fix error cousing library
Browse files- .agent/memory/session.json +2 -2
- Dockerfile +45 -97
- package.json +1 -1
- server.ts +27 -14
.agent/memory/session.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"version": "1.0.0",
|
| 3 |
-
"session_id": "
|
| 4 |
-
"started_at": "2026-04-
|
| 5 |
"workspace": "D:\\Code\\codeverse",
|
| 6 |
"active_task_id": null,
|
| 7 |
"active_agent": null,
|
|
|
|
| 1 |
{
|
| 2 |
"version": "1.0.0",
|
| 3 |
+
"session_id": "0885d2be",
|
| 4 |
+
"started_at": "2026-04-06T17:16:01.973288+05:30",
|
| 5 |
"workspace": "D:\\Code\\codeverse",
|
| 6 |
"active_task_id": null,
|
| 7 |
"active_agent": null,
|
Dockerfile
CHANGED
|
@@ -1,108 +1,56 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
make \
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
openjdk-17-jdk \
|
| 20 |
-
xvfb \
|
| 21 |
-
fluxbox \
|
| 22 |
-
novnc \
|
| 23 |
-
websockify \
|
| 24 |
-
libnss3 \
|
| 25 |
-
libatk-bridge2.0-0 \
|
| 26 |
-
libcups2 \
|
| 27 |
-
libgtk-3-0 \
|
| 28 |
-
# Docker Client and Daemon (for build-time environment availability)
|
| 29 |
-
docker.io \
|
| 30 |
-
# NIX Support (Declarative Environments)
|
| 31 |
-
xz-utils \
|
| 32 |
-
&& rm -rf /var/lib/apt/lists/* \
|
| 33 |
-
&& curl -fL https://github.com/coder/code-server/releases/download/v4.96.2/code-server-4.96.2-linux-amd64.tar.gz \
|
| 34 |
| tar -C /usr/local/lib -xz \
|
| 35 |
-
&&
|
| 36 |
-
&& ln -s /usr/local/lib/code-server/bin/code-server /usr/local/bin/code-server
|
| 37 |
-
|
| 38 |
-
# Install Nix for Unprivileged Usage
|
| 39 |
-
# Single-user mode without root, configured for /nix
|
| 40 |
-
RUN mkdir -p /nix && chown node:node /nix
|
| 41 |
-
USER node
|
| 42 |
-
RUN curl -L https://nixos.org/nix/install | sh -s -- --no-daemon
|
| 43 |
-
ENV PATH="/home/node/.nix-profile/bin:/home/node/.nix-profile/sbin:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
| 44 |
-
ENV NIX_PATH="nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz"
|
| 45 |
-
|
| 46 |
-
USER root
|
| 47 |
-
# Install Android SDK Command Line Tools
|
| 48 |
-
ENV ANDROID_SDK_ROOT /app/android-sdk
|
| 49 |
-
RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools \
|
| 50 |
-
&& curl -fL https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o cmdline-tools.zip \
|
| 51 |
-
&& unzip cmdline-tools.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools \
|
| 52 |
-
&& mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/latest \
|
| 53 |
-
&& rm cmdline-tools.zip
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
FROM base AS builder
|
| 59 |
WORKDIR /app
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
# Prevent Next.js telemetry
|
| 69 |
-
ENV NEXT_TELEMETRY_DISABLED 1
|
| 70 |
-
# Increase memory for build
|
| 71 |
-
ENV NODE_OPTIONS=--max-old-space-size=8192
|
| 72 |
-
|
| 73 |
-
# Build Next.js and then compile the custom server.ts
|
| 74 |
-
RUN npm run build
|
| 75 |
-
|
| 76 |
-
# Step 2. Production image, copy all the files and start next
|
| 77 |
-
FROM base AS runner
|
| 78 |
WORKDIR /app
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
ENV NEXT_TELEMETRY_DISABLED 1
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
RUN
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
#
|
| 87 |
USER node
|
| 88 |
-
|
| 89 |
-
# Copy needed files with correct ownership to avoid mass chown later
|
| 90 |
-
COPY --chown=node:node --from=builder /app/package.json ./
|
| 91 |
-
COPY --chown=node:node --from=builder /app/package-lock.json* ./
|
| 92 |
-
RUN npm ci --omit=dev && npm cache clean --force
|
| 93 |
-
|
| 94 |
-
# Copy build artifacts with correct ownership
|
| 95 |
-
COPY --chown=node:node --from=builder /app/.next ./.next
|
| 96 |
-
COPY --chown=node:node --from=builder /app/public ./public
|
| 97 |
-
COPY --chown=node:node --from=builder /app/dist ./dist
|
| 98 |
-
|
| 99 |
-
# Create workspaces directory with user node
|
| 100 |
-
RUN mkdir -p /app/workspaces
|
| 101 |
-
|
| 102 |
EXPOSE 7860
|
| 103 |
-
ENV PORT 7860
|
| 104 |
-
ENV HOSTNAME "0.0.0.0"
|
| 105 |
-
ENV AUTH_TRUST_HOST "true"
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM docker.io/library/node:20-bookworm-slim@sha256:1e85773c98c31d4fe5b545e4cb17379e617b348832fb3738b22a08f68dec30f3
|
| 2 |
+
|
| 3 |
+
# 1. System Dependencies & Environment Baseline
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
+
ENV HOME=/home/node
|
| 6 |
+
ENV WORKSPACE_ROOT=/app/workspaces
|
| 7 |
+
ENV ANDROID_SDK_ROOT=/app/android-sdk
|
| 8 |
+
ENV PATH="/home/node/.nix-profile/bin:/usr/local/bin:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${ANDROID_SDK_ROOT}/platform-tools:${PATH}"
|
| 9 |
+
|
| 10 |
+
# 2. Modern Infrastructure Layer (IDX Studio 2026 Baseline)
|
| 11 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 12 |
+
libc6 libstdc++6 python3 make g++ git curl ca-certificates tar unzip \
|
| 13 |
+
openjdk-17-jdk xvfb fluxbox novnc websockify libnss3 libatk-bridge2.0-0 \
|
| 14 |
+
libcups2 libgtk-3-0 xz-utils procps bzip2 iptables \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
# 3. code-server Modernization (v4.114.0 - Latest 2026 Stable)
|
| 18 |
+
RUN curl -fL https://github.com/coder/code-server/releases/download/v4.114.0/code-server-4.114.0-linux-amd64.tar.gz \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
| tar -C /usr/local/lib -xz \
|
| 20 |
+
&& ln -s /usr/local/lib/code-server-4.114.0-linux-amd64/bin/code-server /usr/local/bin/code-server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# 4. Determinate Systems Nix Installer (Unprivileged & Hermetic)
|
| 23 |
+
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux \
|
| 24 |
+
--init none --no-confirm --extra-conf "experimental-features = nix-command flakes" \
|
| 25 |
+
&& chown -R node:node /nix /home/node
|
| 26 |
|
| 27 |
+
# 5. Android SDK (Baseline for Studio Preview)
|
|
|
|
| 28 |
WORKDIR /app
|
| 29 |
+
RUN mkdir -p ${ANDROID_SDK_ROOT} && \
|
| 30 |
+
curl -fL https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip -o cmdline.zip && \
|
| 31 |
+
unzip cmdline.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && \
|
| 32 |
+
mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/latest && \
|
| 33 |
+
rm cmdline.zip && \
|
| 34 |
+
yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-33"
|
| 35 |
+
|
| 36 |
+
# 6. CodeVerse Application Layer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
WORKDIR /app
|
| 38 |
+
COPY package*.json ./
|
| 39 |
+
RUN npm install
|
| 40 |
|
| 41 |
+
COPY . .
|
|
|
|
| 42 |
|
| 43 |
+
# 7. Final Sanity Check & Build (Strict Targets)
|
| 44 |
+
RUN npm run build && \
|
| 45 |
+
mkdir -p ${WORKSPACE_ROOT} && \
|
| 46 |
+
chown -R node:node /app ${WORKSPACE_ROOT}
|
| 47 |
|
| 48 |
+
# User context for Hugging Face Spaces (UID 1000)
|
| 49 |
USER node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
EXPOSE 7860
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# idx-start signal for boot manager
|
| 53 |
+
LABEL org.opencontainers.image.source=https://github.com/shubhjn/codeverse
|
| 54 |
+
LABEL idx.studio.version="2026.04"
|
| 55 |
+
|
| 56 |
+
CMD ["npm", "run", "start"]
|
package.json
CHANGED
|
@@ -40,7 +40,7 @@
|
|
| 40 |
"monaco-editor": "^0.55.1",
|
| 41 |
"monaco-languageclient": "^10.7.0",
|
| 42 |
"next": "16.1.6",
|
| 43 |
-
"next-auth": "
|
| 44 |
"node-pty": "^1.1.0",
|
| 45 |
"playwright": "^1.58.2",
|
| 46 |
"postcss": "^8.5.8",
|
|
|
|
| 40 |
"monaco-editor": "^0.55.1",
|
| 41 |
"monaco-languageclient": "^10.7.0",
|
| 42 |
"next": "16.1.6",
|
| 43 |
+
"next-auth": "5.0.0-beta.31",
|
| 44 |
"node-pty": "^1.1.0",
|
| 45 |
"playwright": "^1.58.2",
|
| 46 |
"postcss": "^8.5.8",
|
server.ts
CHANGED
|
@@ -21,7 +21,6 @@ const dev = process.env.NODE_ENV !== "production";
|
|
| 21 |
const app = next({ dev });
|
| 22 |
const handle = app.getRequestHandler();
|
| 23 |
|
| 24 |
-
// Yjs Doc Management
|
| 25 |
const docs = new Map<string, { doc: Y.Doc; awareness: awarenessProtocol.Awareness }>();
|
| 26 |
const getOrCreateDoc = (docName: string) => {
|
| 27 |
return map.setIfUndefined(docs, docName, () => {
|
|
@@ -30,7 +29,16 @@ const getOrCreateDoc = (docName: string) => {
|
|
| 30 |
return { doc, awareness };
|
| 31 |
});
|
| 32 |
};
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Custom renderer for Proxy Errors and Booting screens.
|
|
@@ -75,8 +83,10 @@ function renderProxyError(res: ServerResponse, error: string, id: string) {
|
|
| 75 |
|
| 76 |
proxy.on("error", (err: Error, req: IncomingMessage, res: ServerResponse | Duplex) => {
|
| 77 |
const host = req.headers.host || "";
|
| 78 |
-
|
| 79 |
-
const
|
|
|
|
|
|
|
| 80 |
const headerId = req.headers['x-codeverse-id'] as string;
|
| 81 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
| 82 |
const id = headerId || (workspaceHostMatch ? workspaceHostMatch[1] : (pathname.split("/")[2] || "unknown"));
|
|
@@ -114,9 +124,10 @@ app.prepare()
|
|
| 114 |
startAutoSleepCron();
|
| 115 |
|
| 116 |
const server = createServer((req: IncomingMessage, res: ServerResponse) => {
|
| 117 |
-
|
| 118 |
-
const
|
| 119 |
-
const
|
|
|
|
| 120 |
|
| 121 |
// Unified ID Detection for cold-start redirection
|
| 122 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
|
@@ -134,7 +145,7 @@ app.prepare()
|
|
| 134 |
req.headers['x-codeverse-id'] = id;
|
| 135 |
req.headers['x-codeverse-type'] = 'workspace';
|
| 136 |
|
| 137 |
-
// Rewrite URL for cleaner IDE interaction
|
| 138 |
if (pathname?.startsWith("/workspace/")) {
|
| 139 |
req.url = "/" + pathname.split("/").slice(3).join("/");
|
| 140 |
}
|
|
@@ -148,16 +159,17 @@ app.prepare()
|
|
| 148 |
return proxy.web(req, res, { target: `http://127.0.0.1:${port}`, changeOrigin: true });
|
| 149 |
}
|
| 150 |
|
| 151 |
-
|
|
|
|
| 152 |
});
|
| 153 |
|
| 154 |
const io = new Server(server, { path: "/api/socketio" });
|
| 155 |
const yjsWss = new WebSocketServer({ noServer: true });
|
| 156 |
|
| 157 |
server.on("upgrade", (req: IncomingMessage, socket: Duplex, head: Buffer) => {
|
| 158 |
-
const
|
| 159 |
-
const
|
| 160 |
-
const
|
| 161 |
|
| 162 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
| 163 |
const id = workspaceHostMatch ? workspaceHostMatch[1] : (pathname?.startsWith("/workspace/") ? pathname.split("/")[2] : null);
|
|
@@ -185,8 +197,9 @@ app.prepare()
|
|
| 185 |
});
|
| 186 |
|
| 187 |
yjsWss.on("connection", (conn: WebSocket, request: IncomingMessage) => {
|
| 188 |
-
const
|
| 189 |
-
const
|
|
|
|
| 190 |
const { doc, awareness } = getOrCreateDoc(docName);
|
| 191 |
conn.binaryType = "arraybuffer";
|
| 192 |
|
|
|
|
| 21 |
const app = next({ dev });
|
| 22 |
const handle = app.getRequestHandler();
|
| 23 |
|
|
|
|
| 24 |
const docs = new Map<string, { doc: Y.Doc; awareness: awarenessProtocol.Awareness }>();
|
| 25 |
const getOrCreateDoc = (docName: string) => {
|
| 26 |
return map.setIfUndefined(docs, docName, () => {
|
|
|
|
| 29 |
return { doc, awareness };
|
| 30 |
});
|
| 31 |
};
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* PRODUCTION PROXY CONFIG (2026 Optimized)
|
| 35 |
+
*/
|
| 36 |
+
const proxy = httpProxy.createProxyServer({
|
| 37 |
+
ws: true,
|
| 38 |
+
xfwd: true,
|
| 39 |
+
timeout: 30000,
|
| 40 |
+
proxyTimeout: 30000
|
| 41 |
+
});
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Custom renderer for Proxy Errors and Booting screens.
|
|
|
|
| 83 |
|
| 84 |
proxy.on("error", (err: Error, req: IncomingMessage, res: ServerResponse | Duplex) => {
|
| 85 |
const host = req.headers.host || "";
|
| 86 |
+
// Modern URL API instead of deprecated url.parse
|
| 87 |
+
const fullUrl = new URL(req.url || "/", `http://${host}`);
|
| 88 |
+
const pathname = fullUrl.pathname;
|
| 89 |
+
|
| 90 |
const headerId = req.headers['x-codeverse-id'] as string;
|
| 91 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
| 92 |
const id = headerId || (workspaceHostMatch ? workspaceHostMatch[1] : (pathname.split("/")[2] || "unknown"));
|
|
|
|
| 124 |
startAutoSleepCron();
|
| 125 |
|
| 126 |
const server = createServer((req: IncomingMessage, res: ServerResponse) => {
|
| 127 |
+
// Modern URL API usage
|
| 128 |
+
const host = req.headers.host || "localhost";
|
| 129 |
+
const fullUrl = new URL(req.url || "/", `http://${host}`);
|
| 130 |
+
const { pathname } = fullUrl;
|
| 131 |
|
| 132 |
// Unified ID Detection for cold-start redirection
|
| 133 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
|
|
|
| 145 |
req.headers['x-codeverse-id'] = id;
|
| 146 |
req.headers['x-codeverse-type'] = 'workspace';
|
| 147 |
|
| 148 |
+
// Rewrite URL for cleaner IDE interaction
|
| 149 |
if (pathname?.startsWith("/workspace/")) {
|
| 150 |
req.url = "/" + pathname.split("/").slice(3).join("/");
|
| 151 |
}
|
|
|
|
| 159 |
return proxy.web(req, res, { target: `http://127.0.0.1:${port}`, changeOrigin: true });
|
| 160 |
}
|
| 161 |
|
| 162 |
+
// Final Next.js handler with modern URL context
|
| 163 |
+
handle(req, res);
|
| 164 |
});
|
| 165 |
|
| 166 |
const io = new Server(server, { path: "/api/socketio" });
|
| 167 |
const yjsWss = new WebSocketServer({ noServer: true });
|
| 168 |
|
| 169 |
server.on("upgrade", (req: IncomingMessage, socket: Duplex, head: Buffer) => {
|
| 170 |
+
const host = req.headers.host || "localhost";
|
| 171 |
+
const fullUrl = new URL(req.url || "/", `http://${host}`);
|
| 172 |
+
const { pathname, searchParams } = fullUrl;
|
| 173 |
|
| 174 |
const workspaceHostMatch = host.match(/^workspace-([a-zA-Z0-9-]+)\./);
|
| 175 |
const id = workspaceHostMatch ? workspaceHostMatch[1] : (pathname?.startsWith("/workspace/") ? pathname.split("/")[2] : null);
|
|
|
|
| 197 |
});
|
| 198 |
|
| 199 |
yjsWss.on("connection", (conn: WebSocket, request: IncomingMessage) => {
|
| 200 |
+
const host = request.headers.host || "localhost";
|
| 201 |
+
const fullUrl = new URL(request.url || "/", `http://${host}`);
|
| 202 |
+
const docName = fullUrl.searchParams.get('doc') || "default";
|
| 203 |
const { doc, awareness } = getOrCreateDoc(docName);
|
| 204 |
conn.binaryType = "arraybuffer";
|
| 205 |
|