@abelxiaoxing/cadence 2.0.34 → 2.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +2 -2
- package/README.es.md +2 -2
- package/README.fr.md +2 -2
- package/README.ja.md +1 -2
- package/README.ko.md +2 -2
- package/README.md +5 -2
- package/README.pt-BR.md +2 -2
- package/README.ru.md +3 -2
- package/README.zh-CN.md +2 -2
- package/docs/conversation-mode.md +37 -0
- package/package.json +7 -11
- package/src/abort-scope.ts +47 -0
- package/src/cadence-instructions.ts +1 -0
- package/src/image-content.mjs +120 -0
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +52 -0
- package/src/service/contracts/core.ts +1 -0
- package/src/service/contracts/models.ts +3 -0
- package/src/service/contracts/workbench.ts +168 -3
- package/src/service-cli.mjs +6 -1
- package/src/service-host.mjs +686 -96
- package/src/service-http-client.ts +55 -50
- package/src/worker-public.mjs +6 -1
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +19 -17
- package/web/dist/manifest.json +7 -7
package/README.de.md
CHANGED
|
@@ -108,11 +108,11 @@ Cadence erzwingt keinen Pi-Versionsbereich; Entwicklungs-Pins und getestete Lauf
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
Engineering-Anleitungen sind unter [engineering/](engineering/) nach Bereich aufgeteilt; der Projektindex in [AGENTS.md](AGENTS.md) sagt, welche Datei welchen Code abdeckt.
|
|
115
|
-
`verify`
|
|
114
|
+
`verify` ist die einzige Prüfung für Entwicklung und Releases: nur schnelle Checks, ohne Browser.
|
|
115
|
+
Erforderlich sind ein offizieller Node-Build und ein privates temporäres Verzeichnis; siehe [Verifikation](engineering/verification.md).
|
|
116
116
|
|
|
117
117
|
## Lizenz
|
|
118
118
|
|
package/README.es.md
CHANGED
|
@@ -108,11 +108,11 @@ Cadence no impone un rango de versiones de Pi; los pines de desarrollo y los tie
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
La guía de ingeniería se divide por área bajo [engineering/](engineering/); el índice del proyecto en [AGENTS.md](AGENTS.md) indica qué archivo cubre qué código.
|
|
115
|
-
`verify`
|
|
114
|
+
`verify` es la única verificación para desarrollo y publicación: solo comprobaciones rápidas, sin navegador.
|
|
115
|
+
Requiere un build oficial de Node y un directorio temporal privado; ver [verificación](engineering/verification.md).
|
|
116
116
|
|
|
117
117
|
## Licencia
|
|
118
118
|
|
package/README.fr.md
CHANGED
|
@@ -108,11 +108,11 @@ Cadence n'impose pas de plage de versions de Pi ; les versions figées de dével
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
Les conseils d'ingénierie sont répartis par domaine sous [engineering/](engineering/) ; l'index du projet dans [AGENTS.md](AGENTS.md) indique quel fichier couvre quel code.
|
|
115
|
-
`verify`
|
|
114
|
+
`verify` est la seule validation pour le développement et les publications : uniquement des vérifications rapides, sans navigateur.
|
|
115
|
+
Elle nécessite un build Node officiel et un répertoire temporaire privé ; voir [vérification](engineering/verification.md).
|
|
116
116
|
|
|
117
117
|
## Licence
|
|
118
118
|
|
package/README.ja.md
CHANGED
|
@@ -127,13 +127,12 @@ Cadence は Pi のバージョン範囲を強制しない。
|
|
|
127
127
|
```sh
|
|
128
128
|
bun install
|
|
129
129
|
bun run verify
|
|
130
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
131
130
|
```
|
|
132
131
|
|
|
133
132
|
エンジニアリングのガイダンスは [engineering/](engineering/) 下に領域ごとに分割されている。
|
|
134
133
|
[AGENTS.md](AGENTS.md) のプロジェクト索引がどのファイルがどのコードをカバーするかを示す。
|
|
135
134
|
`verify` には公式 Node ビルドとプライベートな一時ディレクトリが必要。
|
|
136
|
-
|
|
135
|
+
`verify` は開発とリリース共通の唯一の検証コマンドで、高速なチェックのみを実行し、ブラウザは不要。
|
|
137
136
|
[検証](engineering/verification.md)を参照。
|
|
138
137
|
|
|
139
138
|
## ライセンス
|
package/README.ko.md
CHANGED
|
@@ -124,12 +124,12 @@ Cadence는 Pi 버전 범위를 강제하지 않습니다.
|
|
|
124
124
|
```sh
|
|
125
125
|
bun install
|
|
126
126
|
bun run verify
|
|
127
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
128
127
|
```
|
|
129
128
|
|
|
130
129
|
엔지니어링 지침은 [engineering/](engineering/) 아래 영역별로 나뉘어 있습니다.
|
|
131
130
|
[AGENTS.md](AGENTS.md)의 프로젝트 인덱스가 어느 파일이 어느 코드를 다루는지 설명합니다.
|
|
132
|
-
`verify
|
|
131
|
+
`verify`는 개발과 릴리스에 사용하는 유일한 검증 명령으로, 빠른 검사만 실행하며 브라우저가 필요하지 않습니다.
|
|
132
|
+
공식 Node 빌드와 개인 임시 디렉터리가 필요합니다.
|
|
133
133
|
[검증](engineering/verification.md)을 참조하세요.
|
|
134
134
|
|
|
135
135
|
## 라이선스
|
package/README.md
CHANGED
|
@@ -51,6 +51,9 @@ The port and token live in `~/.pi/agent/cadence/.env`; anyone with the token can
|
|
|
51
51
|
5. Follow actual progress and local merge results in the conversation; open any subagent's full context from the lower-left **Subagents** dock.
|
|
52
52
|
Refresh and completion keep Cadence on; **Exit Cadence** only exits the mode, while **Cancel workflow — request stop** requests cancellation.
|
|
53
53
|
|
|
54
|
+
The browser also accepts images by file selection, paste or drag-and-drop, with previews and retained history.
|
|
55
|
+
Choose a vision-capable model; see [image input](docs/conversation-mode.md#images-in-the-webui).
|
|
56
|
+
|
|
54
57
|
### In the terminal
|
|
55
58
|
|
|
56
59
|
Enter `/cadence <goal>` once in any trusted project's Pi conversation.
|
|
@@ -110,11 +113,11 @@ Cadence does not impose a Pi version range; development pins and tested runtimes
|
|
|
110
113
|
```sh
|
|
111
114
|
bun install
|
|
112
115
|
bun run verify
|
|
113
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
114
116
|
```
|
|
115
117
|
|
|
116
118
|
Engineering guidance is split by area under [engineering/](engineering/); the project index in [AGENTS.md](AGENTS.md) says which file covers which code.
|
|
117
|
-
`verify`
|
|
119
|
+
`verify` is the single development and release gate: fast checks only, with no browser requirement.
|
|
120
|
+
It needs an official Node build and a private temporary directory; see [verification](engineering/verification.md).
|
|
118
121
|
|
|
119
122
|
## License
|
|
120
123
|
|
package/README.pt-BR.md
CHANGED
|
@@ -108,11 +108,11 @@ O Cadence não impõe uma faixa de versões do Pi; fixações de desenvolvimento
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
As orientações de engenharia são divididas por área sob [engineering/](engineering/); o índice do projeto em [AGENTS.md](AGENTS.md) diz qual arquivo cobre qual código.
|
|
115
|
-
`verify`
|
|
114
|
+
`verify` é a única verificação para desenvolvimento e publicação: apenas verificações rápidas, sem navegador.
|
|
115
|
+
Exige um build oficial do Node e um diretório temporário privado; veja [verificação](engineering/verification.md).
|
|
116
116
|
|
|
117
117
|
## Licença
|
|
118
118
|
|
package/README.ru.md
CHANGED
|
@@ -108,12 +108,13 @@ Cadence не налагает диапазон версий Pi; фиксиров
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
Инженерные указания разделены по областям в [engineering/](engineering/).
|
|
115
114
|
Индекс проекта в [AGENTS.md](AGENTS.md) указывает, какой файл покрывает какой код.
|
|
116
|
-
`verify`
|
|
115
|
+
`verify` — единственная проверка для разработки и публикации: только быстрые проверки, без браузера.
|
|
116
|
+
Нужны официальная сборка Node и приватный временный каталог; см.
|
|
117
|
+
[проверки](engineering/verification.md).
|
|
117
118
|
|
|
118
119
|
## Лицензия
|
|
119
120
|
|
package/README.zh-CN.md
CHANGED
|
@@ -108,11 +108,11 @@ Cadence 不指定 Pi 版本范围;开发用的固定版本和已测试运行
|
|
|
108
108
|
```sh
|
|
109
109
|
bun install
|
|
110
110
|
bun run verify
|
|
111
|
-
CADENCE_BROWSER_PATH=/absolute/existing/chromium bun run verify:full
|
|
112
111
|
```
|
|
113
112
|
|
|
114
113
|
工程指导按领域拆分在 [engineering/](engineering/) 下;[AGENTS.md](AGENTS.md) 中的项目索引说明了哪个文件覆盖哪部分代码。
|
|
115
|
-
`verify`
|
|
114
|
+
`verify` 是开发和发布共用的唯一验证入口:只运行快速检查,不需要浏览器。
|
|
115
|
+
需要官方 Node 构建和私有临时目录;见[验证](engineering/verification.md)。
|
|
116
116
|
|
|
117
117
|
## 许可证
|
|
118
118
|
|
|
@@ -32,6 +32,43 @@ Opening a different conversation does not enable Cadence there.
|
|
|
32
32
|
Restore never replays a command or automatically resumes an interrupted queue.
|
|
33
33
|
When an observation reply is lost, ask for status; do not infer that the action was absent.
|
|
34
34
|
|
|
35
|
+
## Resume a sent conversation on another device
|
|
36
|
+
|
|
37
|
+
Open the same authenticated workbench on the other device with the **complete conversation link**: `/app?project=<project-key>#chat=<session-id>`.
|
|
38
|
+
The project and chat identities in that link select the same server-held conversation even with empty or blocked browser storage.
|
|
39
|
+
Its sent history, Cadence mode, working directory, model preference and linked work come from the service, not from the first device's pending-send display.
|
|
40
|
+
A link grants neither access nor plan approval: authenticate normally and make any new execution confirmation explicitly.
|
|
41
|
+
Without that complete link, the other browser is not promised an automatic return to the first browser's last conversation.
|
|
42
|
+
|
|
43
|
+
Opening the link only observes; browsing never prepares or starts the project's execution service.
|
|
44
|
+
Only an explicit **Send** may prepare it on demand.
|
|
45
|
+
Leaving, closing or disconnecting a viewer does not cancel accepted work; reconnecting does not resend a message, resume an interrupted queue or inherit approval.
|
|
46
|
+
A stale or unavailable observation keeps readable history but cannot establish that work stopped; distinguish connection freshness from the workflow's last observed status.
|
|
47
|
+
|
|
48
|
+
Unsent text and images are not synchronized across devices.
|
|
49
|
+
Text drafts are local to that browser session when storage is available; images remain local to the tab.
|
|
50
|
+
A preparation failure keeps the local draft and explains whether preparation was never dispatched, is unconfirmed, or was confirmed before a later wait failed.
|
|
51
|
+
An uncertain final Send keeps its original command identity for observation only: do not send it again merely because its reply was lost.
|
|
52
|
+
|
|
53
|
+
## Images in the WebUI
|
|
54
|
+
|
|
55
|
+
Use **Add images**, paste a screenshot, or drop image files onto the composer.
|
|
56
|
+
Preview and remove images before Send; a message can contain images without text.
|
|
57
|
+
PNG, JPEG and WebP are supported; the composer shows the current count and size limits.
|
|
58
|
+
Choose a model whose catalog supports image input.
|
|
59
|
+
An incompatible model refuses the message rather than dropping its images.
|
|
60
|
+
Ordinary and Cadence conversations use the same image input.
|
|
61
|
+
Images alongside an approval phrase are a discussion message, not plan approval.
|
|
62
|
+
|
|
63
|
+
Selecting images is local to the tab and does not upload or start execution.
|
|
64
|
+
Only Send uploads them, bound to that exact conversation, branch, model and message; navigating away abandons an unsent continuation, never an admitted turn.
|
|
65
|
+
Unsent pictures are not saved in browser storage and disappear on refresh; the text draft remains.
|
|
66
|
+
After Pi records a sent image, it appears in the conversation history and remains viewable after refresh (including retained reads when the project owner is stopped).
|
|
67
|
+
Click a history thumbnail to open it at full size.
|
|
68
|
+
Unsupported or over-limit media from existing Pi sessions remains omitted; unavailable images show a notice without changing their session files.
|
|
69
|
+
Images are private conversation content, not public download links.
|
|
70
|
+
Text redaction does not sanitize words or secrets inside pixels: inspect screenshots before sending them to a model.
|
|
71
|
+
|
|
35
72
|
## Models and project knowledge
|
|
36
73
|
|
|
37
74
|
The first native use defaults to the current Pi provider/model/API/thinking selection.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abelxiaoxing/cadence",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.36",
|
|
4
4
|
"description": "Conversation-driven Pi workspace: persistent native and WebUI workflows, explicit plan approval, checks and local delivery.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"skills",
|
|
18
18
|
"config",
|
|
19
19
|
"agents",
|
|
20
|
+
"src/abort-scope.ts",
|
|
20
21
|
"src/agent-panel-cadence.ts",
|
|
21
22
|
"src/agent-panel-model.ts",
|
|
22
23
|
"src/agent-panel.ts",
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
"THIRD_PARTY_NOTICES.md",
|
|
70
71
|
"licenses",
|
|
71
72
|
"src/session-entries.mjs",
|
|
73
|
+
"src/image-content.mjs",
|
|
72
74
|
"src/session-sharing.ts",
|
|
73
75
|
"src/conversation-resources.mjs",
|
|
74
76
|
"src/service/contracts/workbench.ts",
|
|
@@ -95,13 +97,10 @@
|
|
|
95
97
|
"pack:check": "node scripts/pack-check.mjs",
|
|
96
98
|
"traceability:check": "node scripts/traceability-check.mjs",
|
|
97
99
|
"verify": "node scripts/verify.mjs",
|
|
98
|
-
"verify:full": "node scripts/verify.mjs --full",
|
|
99
100
|
"check": "node scripts/check-syntax.mjs && bun scripts/build-operator.mjs --check && bun scripts/build-service.mjs --check && tsc --noEmit --incremental --tsBuildInfoFile .cache/tsc/root.tsbuildinfo",
|
|
100
101
|
"lint": "biome check . && rumdl check .",
|
|
101
|
-
"test": "vitest run",
|
|
102
|
-
"test:
|
|
103
|
-
"test:slow": "vitest run --tags-filter=slow",
|
|
104
|
-
"test:target": "vitest run",
|
|
102
|
+
"test": "vitest run --tags-filter=!slow",
|
|
103
|
+
"test:target": "vitest run --tags-filter=!slow",
|
|
105
104
|
"check:agents": "node scripts/check-agents.mjs",
|
|
106
105
|
"doctor": "node src/operator-cli.mjs doctor",
|
|
107
106
|
"runs": "node src/operator-cli.mjs runs",
|
|
@@ -111,10 +110,8 @@
|
|
|
111
110
|
"test:web": "vitest run --config web/vitest.config.ts",
|
|
112
111
|
"build:web": "node scripts/build-web.mjs",
|
|
113
112
|
"build:web:check": "node scripts/build-web.mjs --check",
|
|
114
|
-
"test:web:assets-browser": "bun run test:browser",
|
|
115
113
|
"build:check": "bun scripts/build-operator.mjs --check && bun scripts/build-service.mjs --check && bun run build:web:check",
|
|
116
|
-
"test:service": "vitest run --config test/service.config.ts",
|
|
117
|
-
"test:browser": "vitest run --config web/browser.config.ts",
|
|
114
|
+
"test:service": "vitest run --config test/service.config.ts --tags-filter=!slow",
|
|
118
115
|
"check:notices": "node scripts/audit-notices.mjs"
|
|
119
116
|
},
|
|
120
117
|
"peerDependencies": {
|
|
@@ -153,8 +150,7 @@
|
|
|
153
150
|
"mdast-util-math": "3.0.0",
|
|
154
151
|
"vis-timeline": "8.5.4",
|
|
155
152
|
"vite": "8.3.0",
|
|
156
|
-
"@vitejs/plugin-react": "6.1.1"
|
|
157
|
-
"playwright-core": "1.63.0"
|
|
153
|
+
"@vitejs/plugin-react": "6.1.1"
|
|
158
154
|
},
|
|
159
155
|
"repository": {
|
|
160
156
|
"type": "git",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** A local wait's cancellation lifetime, not ownership of the operation it
|
|
2
|
+
* observes. No static AbortSignal APIs or global polyfill are required. */
|
|
3
|
+
export function abortScope(
|
|
4
|
+
sources: readonly (AbortSignal | undefined)[] = [],
|
|
5
|
+
timeoutMs?: number,
|
|
6
|
+
): { signal: AbortSignal; dispose(): void } {
|
|
7
|
+
if (
|
|
8
|
+
timeoutMs !== undefined &&
|
|
9
|
+
(!Number.isFinite(timeoutMs) || timeoutMs < 0 || timeoutMs > 2_147_483_647)
|
|
10
|
+
)
|
|
11
|
+
throw new RangeError("invalid abort timeout");
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
const listeners = new Map<AbortSignal, () => void>();
|
|
14
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
15
|
+
let disposed = false;
|
|
16
|
+
const dispose = () => {
|
|
17
|
+
if (disposed) return;
|
|
18
|
+
disposed = true;
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
for (const [source, listener] of listeners)
|
|
21
|
+
source.removeEventListener("abort", listener);
|
|
22
|
+
listeners.clear();
|
|
23
|
+
};
|
|
24
|
+
const abort = (reason: unknown) => {
|
|
25
|
+
if (disposed) return;
|
|
26
|
+
dispose();
|
|
27
|
+
controller.abort(reason);
|
|
28
|
+
};
|
|
29
|
+
for (const source of sources) {
|
|
30
|
+
if (!source || listeners.has(source)) continue;
|
|
31
|
+
if (source.aborted) {
|
|
32
|
+
abort(source.reason);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
const listener = () => abort(source.reason);
|
|
36
|
+
listeners.set(source, listener);
|
|
37
|
+
source.addEventListener("abort", listener, { once: true });
|
|
38
|
+
}
|
|
39
|
+
if (!disposed && timeoutMs !== undefined)
|
|
40
|
+
timer = setTimeout(
|
|
41
|
+
() => abort(new DOMException("The wait timed out", "TimeoutError")),
|
|
42
|
+
timeoutMs,
|
|
43
|
+
);
|
|
44
|
+
// Disposal only releases listeners/timers. It never aborts a source, sends
|
|
45
|
+
// Cancel, or changes the admitted work's lifetime.
|
|
46
|
+
return { signal: controller.signal, dispose };
|
|
47
|
+
}
|
|
@@ -4,4 +4,5 @@ You are the sole user-facing coordinator. Continue normal conversation, not a ta
|
|
|
4
4
|
For each new goal: inspect relevant project evidence through cadence_research (up to two independent readonly subagents); read existing AGENTS/docs/.cadence/project.md before proposing conventions. Reuse still-current findings; do not rescan the entire repository or spawn agents merely to fill slots. Aggregate questions yourself. Investigate discoverable facts and ask focused, frequent questions only for unresolved product/technical decisions. Preserve confirmed decisions across turns. Diagnosis/research alone never imply implementation.
|
|
5
5
|
Once material decisions and acceptance criteria are aligned, use cadence_plan with a readable design, explicit non-goals/decisions, exact file scopes, a finite dependency DAG, real verification commands, worktree prerequisites and a bounded repair budget. Independent writes may run concurrently; shared files need a single owner or dependency. Investigate local tool/dependency prerequisites BEFORE finalizing: isolated worktrees do not inherit ignored node_modules. Setup commands require inclusion in the final approval; never silently install/download/copy dependencies or credentials. local-merge needs an existing Git branch and commit identity; working-copy is explicit direct editing without Git mutation and is serialized.
|
|
6
6
|
Present the returned complete plan and invite a single clear execution approval (the user can type 按计划实施). cadence_start binds the exact displayed plan and obtains fresh user consent; never interpret a vague acknowledgement as approval. No further confirmations are needed for the approved bounded pipeline. No push, publication, deployment, recursive delegation or scope expansion. If a material decision changes, revise the plan and seek fresh approval.
|
|
7
|
+
For a follow-up to previously accepted work, inspect cadence_status and retained outcomes before proposing a new run or applying clean-start prerequisites. Known partial outputs from that run are not unexplained user edits. Preserve them and the original failed/unknown result; diagnose the actual failed stage. Never replay the run or claim its checks passed; any new implementation still needs a fresh exact-plan approval.
|
|
7
8
|
During accepted work answer questions, report actual retained progress, and let the service execute. cadence_cancel is explicit cancellation, not navigation/exit. Never claim a worker's prose is a passing check or automatic review is human review. Failed/unknown/blocked outcomes are not success. A completed goal leaves Cadence ON and ready for the next goal; do not require /cadence again. Unrelated discussion is still ordinary conversation within this mode, not implicit permission to start another implementation. Tools operate on the host; this is not a sandbox.`;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IMAGE_COUNT } from "./worker-public.mjs";
|
|
2
|
+
/** Shared image ceilings. Upload chunks and history parts fit existing control replies;
|
|
3
|
+
* image bytes never enlarge the public worker request or become prompt text. */
|
|
4
|
+
export const IMAGE_LIMITS = Object.freeze({
|
|
5
|
+
count: IMAGE_COUNT,
|
|
6
|
+
bytes: 4 * 1024 * 1024,
|
|
7
|
+
totalBytes: 8 * 1024 * 1024,
|
|
8
|
+
chunkChars: 256 * 1024,
|
|
9
|
+
stagedBytes: 64 * 1024 * 1024,
|
|
10
|
+
stagedCount: 64,
|
|
11
|
+
idleMs: 10 * 60 * 1000,
|
|
12
|
+
pixels: 32 * 1024 * 1024,
|
|
13
|
+
dimension: 16384,
|
|
14
|
+
wireBytes: 12 * 1024 * 1024,
|
|
15
|
+
});
|
|
16
|
+
export const IMAGE_TYPES = Object.freeze([
|
|
17
|
+
"image/png",
|
|
18
|
+
"image/jpeg",
|
|
19
|
+
"image/webp",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export function decodeImageBase64(data, maxBytes = IMAGE_LIMITS.bytes) {
|
|
23
|
+
if (
|
|
24
|
+
typeof data !== "string" ||
|
|
25
|
+
!data.length ||
|
|
26
|
+
data.length % 4 ||
|
|
27
|
+
data.length > 4 * Math.ceil(maxBytes / 3) ||
|
|
28
|
+
!/^[A-Za-z0-9+/]*={0,2}$/.test(data)
|
|
29
|
+
)
|
|
30
|
+
throw new Error("Invalid image encoding");
|
|
31
|
+
const raw = atob(data);
|
|
32
|
+
if (raw.length > maxBytes) throw new Error("Image is too large");
|
|
33
|
+
const bytes = new Uint8Array(raw.length);
|
|
34
|
+
for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Bounded header validation, not an image transcoder. No SVG/HTML or remote URLs. */
|
|
39
|
+
export function validateImageBytes(bytes, mimeType) {
|
|
40
|
+
if (
|
|
41
|
+
!IMAGE_TYPES.includes(mimeType) ||
|
|
42
|
+
!bytes.length ||
|
|
43
|
+
bytes.length > IMAGE_LIMITS.bytes
|
|
44
|
+
)
|
|
45
|
+
throw new Error("Unsupported image or size");
|
|
46
|
+
const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
47
|
+
const ascii = (at, value) =>
|
|
48
|
+
[...value].every((c, i) => bytes[at + i] === c.charCodeAt(0));
|
|
49
|
+
let width = 0,
|
|
50
|
+
height = 0;
|
|
51
|
+
if (
|
|
52
|
+
mimeType === "image/png" &&
|
|
53
|
+
bytes.length >= 33 &&
|
|
54
|
+
bytes[0] === 137 &&
|
|
55
|
+
ascii(1, "PNG\r\n\u001a\n") &&
|
|
56
|
+
v.getUint32(8) === 13 &&
|
|
57
|
+
ascii(12, "IHDR")
|
|
58
|
+
) {
|
|
59
|
+
width = v.getUint32(16);
|
|
60
|
+
height = v.getUint32(20);
|
|
61
|
+
} else if (
|
|
62
|
+
mimeType === "image/jpeg" &&
|
|
63
|
+
bytes[0] === 255 &&
|
|
64
|
+
bytes[1] === 216
|
|
65
|
+
) {
|
|
66
|
+
for (let p = 2; p + 3 < bytes.length; ) {
|
|
67
|
+
if (bytes[p++] !== 255) break;
|
|
68
|
+
while (bytes[p] === 255) p++;
|
|
69
|
+
const marker = bytes[p++];
|
|
70
|
+
if (marker === 217 || marker === 218) break;
|
|
71
|
+
if (marker === 1 || (marker >= 208 && marker <= 215)) continue;
|
|
72
|
+
if (p + 2 > bytes.length) break;
|
|
73
|
+
const length = v.getUint16(p);
|
|
74
|
+
if (length < 2 || p + length > bytes.length) break;
|
|
75
|
+
if (
|
|
76
|
+
[
|
|
77
|
+
192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207,
|
|
78
|
+
].includes(marker) &&
|
|
79
|
+
length >= 8
|
|
80
|
+
) {
|
|
81
|
+
height = v.getUint16(p + 3);
|
|
82
|
+
width = v.getUint16(p + 5);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
p += length;
|
|
86
|
+
}
|
|
87
|
+
} else if (
|
|
88
|
+
mimeType === "image/webp" &&
|
|
89
|
+
bytes.length >= 30 &&
|
|
90
|
+
ascii(0, "RIFF") &&
|
|
91
|
+
ascii(8, "WEBP") &&
|
|
92
|
+
v.getUint32(4, true) + 8 === bytes.length
|
|
93
|
+
) {
|
|
94
|
+
if (ascii(12, "VP8X")) {
|
|
95
|
+
width = 1 + bytes[24] + (bytes[25] << 8) + (bytes[26] << 16);
|
|
96
|
+
height = 1 + bytes[27] + (bytes[28] << 8) + (bytes[29] << 16);
|
|
97
|
+
} else if (
|
|
98
|
+
ascii(12, "VP8 ") &&
|
|
99
|
+
bytes[23] === 157 &&
|
|
100
|
+
bytes[24] === 1 &&
|
|
101
|
+
bytes[25] === 42
|
|
102
|
+
) {
|
|
103
|
+
width = v.getUint16(26, true) & 16383;
|
|
104
|
+
height = v.getUint16(28, true) & 16383;
|
|
105
|
+
} else if (ascii(12, "VP8L") && bytes[20] === 47) {
|
|
106
|
+
const bits = v.getUint32(21, true);
|
|
107
|
+
width = 1 + (bits & 16383);
|
|
108
|
+
height = 1 + ((bits >>> 14) & 16383);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
!width ||
|
|
113
|
+
!height ||
|
|
114
|
+
width > IMAGE_LIMITS.dimension ||
|
|
115
|
+
height > IMAGE_LIMITS.dimension ||
|
|
116
|
+
width * height > IMAGE_LIMITS.pixels
|
|
117
|
+
)
|
|
118
|
+
throw new Error("Invalid image dimensions or header");
|
|
119
|
+
return { width, height };
|
|
120
|
+
}
|
package/src/native-build.ts
CHANGED
package/src/sdk-worker.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import {
|
|
5
5
|
closeSync,
|
|
6
6
|
constants,
|
|
7
|
+
createReadStream,
|
|
7
8
|
fstatSync,
|
|
8
9
|
openSync,
|
|
9
10
|
readFileSync,
|
|
@@ -26,6 +27,11 @@ import {
|
|
|
26
27
|
} from "@earendil-works/pi-coding-agent";
|
|
27
28
|
import { conversationResources } from "./conversation-resources.mjs";
|
|
28
29
|
import { coordinatorTools } from "./coordinator-tools.mjs";
|
|
30
|
+
import {
|
|
31
|
+
decodeImageBase64,
|
|
32
|
+
IMAGE_LIMITS,
|
|
33
|
+
validateImageBytes,
|
|
34
|
+
} from "./image-content.mjs";
|
|
29
35
|
import { researchClock, researchTools } from "./research-tools.mjs";
|
|
30
36
|
import {
|
|
31
37
|
BROWSER_COMMAND_ENTRY,
|
|
@@ -271,6 +277,7 @@ try {
|
|
|
271
277
|
: closed(envelope.conversation, [
|
|
272
278
|
"session",
|
|
273
279
|
"agentDir",
|
|
280
|
+
...(Object.hasOwn(envelope.conversation, "images") ? ["images"] : []),
|
|
274
281
|
...(Object.hasOwn(envelope.conversation, "coordinator")
|
|
275
282
|
? ["coordinator"]
|
|
276
283
|
: []),
|
|
@@ -652,6 +659,50 @@ try {
|
|
|
652
659
|
});
|
|
653
660
|
await capture.context(publicRequest, session.systemPrompt);
|
|
654
661
|
stage = "prompt";
|
|
662
|
+
let images;
|
|
663
|
+
if (Boolean(publicRequest.imageCount) !== Boolean(conversation?.images))
|
|
664
|
+
throw new Error("Missing image channel");
|
|
665
|
+
if (conversation?.images !== undefined) {
|
|
666
|
+
const descriptor = closed(conversation.images, ["bytes", "sha256"]);
|
|
667
|
+
if (
|
|
668
|
+
!Number.isSafeInteger(descriptor.bytes) ||
|
|
669
|
+
descriptor.bytes < 1 ||
|
|
670
|
+
descriptor.bytes > IMAGE_LIMITS.wireBytes ||
|
|
671
|
+
!/^[a-f0-9]{64}$/.test(descriptor.sha256) ||
|
|
672
|
+
!model.input?.includes("image")
|
|
673
|
+
)
|
|
674
|
+
throw new Error("Invalid image context");
|
|
675
|
+
const chunks = [];
|
|
676
|
+
let size = 0;
|
|
677
|
+
for await (const chunk of createReadStream(null, { fd: 3 })) {
|
|
678
|
+
size += chunk.length;
|
|
679
|
+
if (size > descriptor.bytes)
|
|
680
|
+
throw new Error("Image payload exceeds bound");
|
|
681
|
+
chunks.push(chunk);
|
|
682
|
+
}
|
|
683
|
+
const bytes = Buffer.concat(chunks);
|
|
684
|
+
if (
|
|
685
|
+
size !== descriptor.bytes ||
|
|
686
|
+
createHash("sha256").update(bytes).digest("hex") !== descriptor.sha256
|
|
687
|
+
)
|
|
688
|
+
throw new Error("Incomplete image payload");
|
|
689
|
+
images = JSON.parse(bytes.toString("utf8"));
|
|
690
|
+
if (
|
|
691
|
+
!Array.isArray(images) ||
|
|
692
|
+
!images.length ||
|
|
693
|
+
images.length !== publicRequest.imageCount
|
|
694
|
+
)
|
|
695
|
+
throw new Error("Invalid images");
|
|
696
|
+
let total = 0;
|
|
697
|
+
for (const image of images) {
|
|
698
|
+
closed(image, ["type", "data", "mimeType"]);
|
|
699
|
+
if (image.type !== "image") throw new Error("Invalid image");
|
|
700
|
+
const decoded = decodeImageBase64(image.data);
|
|
701
|
+
validateImageBytes(decoded, image.mimeType);
|
|
702
|
+
total += decoded.length;
|
|
703
|
+
}
|
|
704
|
+
if (total > IMAGE_LIMITS.totalBytes) throw new Error("Images exceed bound");
|
|
705
|
+
}
|
|
655
706
|
const suppliedPrompt = [
|
|
656
707
|
publicRequest.context,
|
|
657
708
|
...(!conversation && kind !== "code"
|
|
@@ -668,6 +719,7 @@ try {
|
|
|
668
719
|
.filter(Boolean)
|
|
669
720
|
.join("\n\n");
|
|
670
721
|
await session.prompt(suppliedPrompt, {
|
|
722
|
+
...(images ? { images } : {}),
|
|
671
723
|
expandPromptTemplates: false,
|
|
672
724
|
preflightResult: (accepted) => {
|
|
673
725
|
preflight = accepted ? "accepted" : "rejected";
|
|
@@ -77,6 +77,7 @@ export interface ModelChoiceState {
|
|
|
77
77
|
selected: ModelSelection | null;
|
|
78
78
|
}
|
|
79
79
|
export interface ModelCandidate {
|
|
80
|
+
images?: boolean;
|
|
80
81
|
provider: string;
|
|
81
82
|
model: string;
|
|
82
83
|
api: ModelSelection["api"] | null;
|
|
@@ -141,8 +142,10 @@ export function decodeModelCandidate(value: unknown): ModelCandidate {
|
|
|
141
142
|
"api",
|
|
142
143
|
"thinking",
|
|
143
144
|
"eligibility",
|
|
145
|
+
...(Object.hasOwn(value ?? {}, "images") ? ["images"] : []),
|
|
144
146
|
]);
|
|
145
147
|
const candidate: ModelCandidate = {
|
|
148
|
+
...(o.images === undefined ? {} : { images: bool(o.images) }),
|
|
146
149
|
provider: text(o.provider, 128, true),
|
|
147
150
|
model: text(o.model, 256, true),
|
|
148
151
|
api: nullable(o.api, (v) => oneOf(v, modelApis)),
|