Skip to content

Commit e025baa

Browse files
committed
Removed redundant code + reduced docker image size
1 parent 8b2b081 commit e025baa

49 files changed

Lines changed: 452 additions & 138 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.dockerignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ zcode-proxy-darwin-*
1111
docs
1212
_reverse
1313
.omo
14+
.codegraph
15+
Android-APP
16+
**/AGENTS.md
17+
**/*.test.ts
18+
src/proxy/captcha-worker-entry.bundle.js

‎Dockerfile‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM oven/bun:1-alpine AS deps
3+
# Keep Bun aligned with CI and desktop builds. Only production dependencies
4+
# are needed even in the builder: both bundles use Bun's built-in bundler.
5+
FROM oven/bun:1.4.0-alpine AS build
46
WORKDIR /app
57
COPY package.json bun.lock ./
6-
RUN bun install --frozen-lockfile
8+
RUN bun install --frozen-lockfile --production
9+
COPY tsconfig.json ./
10+
COPY src ./src
11+
COPY scripts/build-fork-worker.ts ./scripts/build-fork-worker.ts
12+
# Preserve the worker file asset as well as the main bundle. Omitting it
13+
# degrades captcha solving to the main thread (issue #54).
14+
RUN bun run scripts/build-fork-worker.ts \
15+
&& bun build --target=bun --minify --keep-names --define 'require.resolve=undefined' src/index.ts --outdir /app/dist
716

8-
FROM oven/bun:1-alpine
17+
FROM oven/bun:1.4.0-alpine
918
WORKDIR /app
10-
COPY --from=deps /app/node_modules ./node_modules
11-
COPY package.json tsconfig.json config.example.yaml ./
12-
COPY src ./src
13-
COPY scripts ./scripts
14-
# The image runs TS sources — bundle the worker entry here (gitignored build
15-
# input) or the solver silently falls back to main-thread solving.
16-
RUN bun run scripts/build-fork-worker.ts && rm -rf scripts
19+
# Runtime contains the bundled application and worker; no node_modules,
20+
# TypeScript sources, tests, or additional build tools enter this stage.
21+
COPY --from=build /app/dist ./
1722
RUN mkdir -p /data && chown bun:bun /data
1823
ENV ZCODE_PROXY_PORT=8080
1924
ENV ZCODE_PROXY_CONFIG=/data/config.yaml
2025
EXPOSE 8080
2126
USER bun
22-
CMD ["bun", "run", "src/index.ts", "serve"]
27+
CMD ["bun", "index.js", "serve"]

‎PROMPT.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# ZCode 内置提示词
22

3-
从 ZCode 客户端 `app.asar` (`out/host/index.js` + `_reverse/zcode.cjs`) 提取。
3+
> 2026-10-20 维护说明:下文保留带版本日期的历史提取记录,不能把 3.11.2 压缩符号用于当前 3.16.2 bundle。实际出线以 src/proxy/zcode_system.json、system-prompt.ts 与测试为准;源快照见 _reverse/MANIFEST.md。
4+
5+
从 ZCode 客户端 `app.asar` (`out/host/index.js` + `_reverse/glm/zcode.cjs`) 提取。
46

57
ZCode 的 system prompt 由多个模块化 section 组合注入,按 `injectionTarget` 分为 `system` 和 `meta_user` 两类,按 `cacheHint` 分为 `stable` 和 `dynamic`。
68

7-
> **2026-09-11 刷新(对齐 ZCode 3.11.2 CLI bundle)**:本文档已按 `_reverse/zcode.cjs`(3.11.2)
9+
> **2026-09-11 刷新(对齐 ZCode 3.11.2 CLI bundle)**:本文档已按 `_reverse/glm/zcode.cjs`(3.11.2)
810
> 的 `ContextBuilder`(`Hre`)逐符号核对更新。注意两点:
911
> 1. **§4 Task Behavior / §5 Risky Actions / §6 Communication Style 是 2026-06-20 提取时的旧版
1012
> 残留(3.3.x era),现客户端已整体移除** —— 2026-09-11 对本机安装的 3.11.2 全量验证:三个

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ docker run -d --name zcode-proxy -p 8080:8080 \
151151
ghcr.io/tridefender/zcode-proxy:latest
152152
```
153153

154-
镜像多架构(amd64 / arm64),以 `bun` 用户运行。compose 写法:
154+
镜像多架构(amd64 / arm64),以 `bun` 用户运行。多阶段构建后的运行层仅带应用 bundle 和验证码 worker,不带 `node_modules`、源码、测试或额外构建工具,保留完整功能;体积对比和本地构建方法见 [Docker 镜像说明](docs/docker-image.md)。compose 写法:
155155

156156
```yaml
157157
services:
@@ -282,3 +282,7 @@ bun run dev # 开发模式启动面板
282282
## License
283283

284284
MIT
285+
286+
## 协议与维护说明
287+
288+
三端的支持范围、降级行为及不支持的字段见 [兼容矩阵](docs/compatibility.md);源码对拍、修复和未验证项见 [2026-10-20 审计](docs/audit-2026-10-20.md)。Responses hosted 搜索工具不会在服务端执行。

‎README_EN.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ docker run -d --name zcode-proxy -p 8080:8080 \
152152
ghcr.io/tridefender/zcode-proxy:latest
153153
```
154154

155-
The image is multi-arch (amd64 / arm64) and runs as the `bun` user. With compose:
155+
The image is multi-arch (amd64 / arm64) and runs as the `bun` user. Its multi-stage build ships only the application bundle and captcha worker, with all features retained and no `node_modules`, sources, tests, or additional build tools in the runtime layer. See [Docker image notes](docs/docker-image.md) for size measurements and local build commands. With compose:
156156

157157
```yaml
158158
services:
@@ -286,3 +286,7 @@ keys.
286286
## License
287287

288288
MIT
289+
290+
## Protocol and maintenance notes
291+
292+
See the [compatibility matrix](docs/compatibility.md) and [2026-10-20 audit](docs/audit-2026-10-20.md) for supported mappings, deliberate deviations and verification limits. Responses hosted search tools are not executed by this proxy.

‎scripts/audit-reverse.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** Offline evidence extraction. Does not execute the client bundles or contact upstream. */
2+
import { readFileSync } from "node:fs";
3+
import { createHash } from "node:crypto";
4+
5+
const targets = [
6+
{ path: "_reverse/glm/zcode.cjs", anchors: ["function HUs(", "function DGs(", "function s5s(", "WD_CLIENT_SIGN_KDF_SALT", "account_uuid", "disable_parallel_tool_use", "budget_tokens", "oauth/cli/init", "off-peak"] },
7+
{ path: "_reverse/app/out/host/index.js", anchors: ["Bh=class", "function vee(", "function oN(", "foreign-card", "next_draw_at", "/billing/claim"] },
8+
{ path: "_reverse/app/out/host/chunk-XLKRUNM2.js", anchors: ["requestVerificationClaimHeaders", "access_tokens", "off-peak"] },
9+
];
10+
for (const target of targets) {
11+
const source = readFileSync(target.path, "utf8");
12+
console.log(JSON.stringify({ path: target.path, bytes: Buffer.byteLength(source), sha256: createHash("sha256").update(source).digest("hex") }));
13+
for (const anchor of target.anchors) {
14+
const offset = source.indexOf(anchor);
15+
console.log(JSON.stringify({ anchor, offset, excerpt: offset < 0 ? null : source.slice(Math.max(0, offset - 100), offset + 1600) }));
16+
}
17+
}
18+
19+
// Literal presence is a drift signal, not a substitute for reconstructing the
20+
// client's dynamic section selection and joins. Keep failures visible.
21+
const bundle = readFileSync("_reverse/glm/zcode.cjs", "utf8");
22+
const literalView = bundle.replace(/\\u([\da-f]{4})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
23+
.replace(/\\`/g, "`");
24+
const sidecar = JSON.parse(readFileSync("src/proxy/zcode_system.json", "utf8"));
25+
function strings(value: unknown): string[] {
26+
if (typeof value === "string") return [value];
27+
if (value && typeof value === "object") return Object.values(value).flatMap(strings);
28+
return [];
29+
}
30+
const promptLines = [...new Set(strings(sidecar).flatMap(s => s.split("\n")).filter(s => s.length > 30))];
31+
const missing = promptLines.filter(s => !literalView.includes(s) && !literalView.includes(JSON.stringify(s).slice(1, -1)));
32+
console.log(JSON.stringify({ check: "prompt-literal-presence", checked: promptLines.length, missing }));
33+
const poweredBy = literalView.indexOf("You are powered by the model named");
34+
console.log(JSON.stringify({ check: "dynamic-model-line", offset: poweredBy, excerpt: poweredBy < 0 ? null : literalView.slice(Math.max(0, poweredBy - 100), poweredBy + 220) }));

‎src/async/bridge.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Async bridge: core state machine turning sync client stream expectation
3-
* into off-peak async reality. See `.omo/plans/async-off-peak-bridge.md` §3.
3+
* into off-peak async reality. See src/async/AGENTS.md for the state machine contract.
44
*
55
* State machine:
66
* WAIT (queued) → poll every pollIntervalMs (signal-aware); emit keepalives

‎src/async/handler.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* chunked `application/json` response that emits legal leading whitespace during
1818
* wait (defeats client TCP idle) and writes the final aggregated JSON at the end.
1919
*
20-
* @see .omo/plans/async-off-peak-bridge.md §3 for full design.
2120
*/
2221
import type { ProxyConfig } from "../config/types.js";
2322
import type { AuthManager } from "../auth/manager.js";

‎src/auth/manager.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Tests for credential types and auth manager.
3-
* @see .omo/plans/zcode-proxy.md Task 4
43
*/
54
import { describe, it, expect } from "bun:test";
65
import { credentialString, isExpired } from "./types.js";

‎src/auth/manager.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Auth manager — resolves the upstream credential from the OAuth login flow.
3-
* @see .omo/plans/zcode-proxy.md Task 4
43
*/
54
import type { Credential } from "./types.js";
65

0 commit comments

Comments
 (0)