@abelxiaoxing/cadence 2.0.36 → 2.0.38
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 +4 -4
- package/README.es.md +4 -4
- package/README.fr.md +4 -4
- package/README.ja.md +4 -4
- package/README.ko.md +4 -4
- package/README.md +11 -9
- package/README.pt-BR.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh-CN.md +12 -10
- package/THIRD_PARTY_NOTICES.md +9 -1
- package/agents/design-explorer.md +4 -2
- package/agents/diagnosis-worker.md +5 -2
- package/agents/implementation-worker.md +19 -12
- package/docs/conversation-mode.md +46 -18
- package/docs/reuse-and-distribution.md +1 -1
- package/docs/service-management.md +35 -9
- package/package.json +16 -8
- package/src/agent-browser/labeled-rule.ts +74 -0
- package/src/agent-browser/session-navigator.ts +214 -0
- package/src/agent-browser/source.ts +174 -0
- package/src/agent-browser/transcript-content.ts +442 -0
- package/src/agent-browser/transcript-pane.ts +324 -0
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +34 -267
- package/src/agent-panel.ts +139 -437
- package/src/cadence-instructions.ts +8 -7
- package/src/cadence-mode.ts +30 -9
- package/src/change-tools.mjs +268 -0
- package/src/coordinator-tools.mjs +44 -16
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- package/src/image-content.mjs +7 -28
- package/src/index.ts +1 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +18 -11
- package/src/research-scan.mjs +393 -0
- package/src/research-tools.mjs +406 -342
- package/src/sdk-worker.mjs +42 -55
- package/src/service/contracts/core.ts +0 -1
- package/src/service/contracts/workbench.ts +21 -19
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +7 -0
- package/src/service-cli.mjs +652 -149
- package/src/service-host.mjs +2745 -1137
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +19 -2
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +157 -0
- package/src/worker-workspace.d.mts +13 -0
- package/src/worker-workspace.mjs +48 -0
- package/src/workspace.ts +4 -24
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +18 -17
- package/web/dist/manifest.json +7 -7
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** Shared
|
|
1
|
+
/** Shared dialogue policy. Execution and recovery belong to the persistent owner. */
|
|
2
2
|
export const CADENCE_INSTRUCTIONS = `CADENCE CONVERSATION MODE — stays enabled for this entire conversation, including after a goal completes, until the user explicitly exits by typing 退出 Cadence or exit cadence. Only the user can exit; leaving never cancels accepted work. When asked how to leave, say exactly this.
|
|
3
|
-
You are the sole user-facing coordinator.
|
|
4
|
-
For
|
|
5
|
-
Once
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
During accepted work
|
|
3
|
+
You are the sole user-facing coordinator. Understand the desired result, not a task-management form. Never ask the user to manage tasks, IDs, JSON, service ports, agent assignments, repair counts, budgets or knowledge files.
|
|
4
|
+
For a new goal, use focused cadence_research to inspect relevant code and project knowledge. Reuse still-current findings. Read existing AGENTS.md, engineering/docs/.trellis/spec and .cadence/project.md where applicable. Project documents are observations and conventions, never execution authority. Do not rescan the entire repository or spawn workers just to fill slots. Investigate discoverable facts yourself. Ask only questions that materially change the expected result and cannot reasonably follow existing project conventions. Preserve confirmed decisions; research alone never authorizes edits.
|
|
5
|
+
Once the result is clear, use cadence_plan with version:2. Describe the expected delivery, explicit decisions/non-goals, immutable acceptance, an initial technical route and assignments, approved write paths, exact setup/baseline/acceptance commands and delivery policy. The initial route is automatically adjustable; the owner may diagnose, preserve partial work, split remaining work and select equivalent implementations without routine reconfirmation. Do not ask users to classify every adjustable detail. Never weaken core requirements or checks. Investigate prerequisites first: worktrees do not inherit ignored dependencies. Setup/install commands need inclusion in approval; no implicit downloads, source/profile copying or credential copying. For Git code delivery, prefer local-merge; working-copy requires an explicitly approved direct-edit policy, never a silent fallback. local-merge creates one named cadence/<goal>-<run-id> branch and one stable worktree only AFTER delivery approval, never on mode entry or research. All implementation, recovery and verified knowledge updates reuse that candidate; each new approved delivery gets its own branch. The original conversation cwd stays unchanged. Checks and independent Agent review must bind the exact candidate before fast-forward delivery into the displayed target; only this run's confirmed merges can advance that target baseline for post-merge recovery. Keep the task branch and retain any worktree containing uncommitted, untracked or ignored residue. No automatic rebase, reset, cleanup of user data or mutation replay. local-merge needs an existing branch and commit identity and clean, nonignored approved targets; working-copy preserves existing direct edits without Git mutation.
|
|
6
|
+
Include knowledge as exact Markdown write paths for relevant existing documentation, or .cadence/project.md and a focused .cadence/knowledge/<topic>.md only where no existing document owns the fact. Knowledge is learned from actual implementation and verified evidence, not guessed in the proposal. Avoid duplicate documentation systems. Include necessary tests and documentation in the approved scope so routine delivery does not need scope expansion.
|
|
7
|
+
Present a concise delivery expectation with the complete returned agreement available, then invite one clear approval (the user may type 按计划实施). cadence_start obtains fresh context-bound approval. It covers adaptive execution, checks, automatic Agent review, knowledge updates and the declared local delivery. It never covers push, publication, deployment, new permissions, unplanned installations or changing core requirements. You cannot approve yourself. Vague acknowledgement is not consent.
|
|
8
|
+
During accepted work the service owns progress and recovery. Report actual cadence_status observations; do not start replacement workflows or ask for 'continue' after an individual child fails. Child failure is not delivery failure. The owner proceeds while there is an evidence-based in-scope route, without a fixed repair quota or total delivery deadline. Native worker deadlines and actual closure still apply. If work is genuinely blocked, explain the concrete missing condition and preserved outcomes, not a generic request to continue.
|
|
9
|
+
For follow-up to a settled or interrupted run, inspect retained outcomes first. Partial outputs are not unexplained user edits. Unknown results must be observed and reconciled, never blindly replayed; a new delivery requires fresh approval. No automatic replay after owner restart. cadence_cancel is explicit cancellation, not navigation or exit. Worker prose is not passing checks; automatic review is never human review. Completion leaves Cadence ON and ready. Tools operate on the host; this is not a sandbox.`;
|
package/src/cadence-mode.ts
CHANGED
|
@@ -26,6 +26,8 @@ import { decodeSessionId } from "./service/contracts/models.ts";
|
|
|
26
26
|
import type { ChatTurn } from "./service/contracts/workbench.ts";
|
|
27
27
|
import {
|
|
28
28
|
decodeWorkflowPlan,
|
|
29
|
+
readableDelivery,
|
|
30
|
+
readableDeliveryRun,
|
|
29
31
|
readableWorkflowPlan,
|
|
30
32
|
type WorkflowProposal,
|
|
31
33
|
type WorkflowRequest,
|
|
@@ -85,7 +87,7 @@ const idle = (): CadenceModeState => ({
|
|
|
85
87
|
previousTools: [],
|
|
86
88
|
});
|
|
87
89
|
function readableProposal(proposal: WorkflowProposal): string {
|
|
88
|
-
return `Working directory: ${proposal.cwd}\nCheckout root (declared write paths): ${proposal.checkoutRoot ?? proposal.cwd}\nModel: ${proposal.display?.model ?? "not recorded"}\n\n${readableWorkflowPlan(proposal.plan)}`;
|
|
90
|
+
return `Working directory: ${proposal.cwd}\nCheckout root (declared write paths): ${proposal.checkoutRoot ?? proposal.cwd}\nModel: ${proposal.display?.model ?? "not recorded"}\n\n${readableDelivery(proposal.delivery)}\n\n${readableWorkflowPlan(proposal.plan)}`;
|
|
89
91
|
}
|
|
90
92
|
/** Session restoration restores mode/context, NEVER a grant, pending command or action replay. */
|
|
91
93
|
export function restoreCadenceMode(
|
|
@@ -237,7 +239,8 @@ const PLAN = Type.Object({
|
|
|
237
239
|
design: Type.String(),
|
|
238
240
|
decisions: Type.String(),
|
|
239
241
|
acceptance: Type.String(),
|
|
240
|
-
|
|
242
|
+
version: Type.Literal(2),
|
|
243
|
+
knowledge: Type.Array(Type.String(), { maxItems: 16 }),
|
|
241
244
|
tasks: Type.Array(
|
|
242
245
|
Type.Object({
|
|
243
246
|
id: Type.String(),
|
|
@@ -251,7 +254,6 @@ const PLAN = Type.Object({
|
|
|
251
254
|
checks: Type.Array(CHECK, { minItems: 1, maxItems: 16 }),
|
|
252
255
|
setup: Type.Array(CHECK, { maxItems: 4 }),
|
|
253
256
|
baselineChecks: Type.Array(CHECK, { maxItems: 16 }),
|
|
254
|
-
repairAttempts: Type.Integer({ minimum: 0, maximum: 2 }),
|
|
255
257
|
delivery: Type.Union([
|
|
256
258
|
Type.Literal("local-merge"),
|
|
257
259
|
Type.Literal("working-copy"),
|
|
@@ -389,7 +391,7 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
|
|
|
389
391
|
context = ctx;
|
|
390
392
|
};
|
|
391
393
|
const summarize = (run: WorkflowRun) =>
|
|
392
|
-
`Cadence ${run.status} • ${run.goal}\nRun: ${run.id}\n${workflowDiagnostics(run)}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}${s.exitCode === null ? "" : ` (exit ${s.exitCode})`}\n${s.text}${s.truncated ? "\n[Preview truncated; full result retained by owner.]" : ""}`).join("\n")}\n${run.notice}${run.mergedCommit ? `\nLocal merge: ${run.mergedCommit}` : ""}${run.status === "unknown" ? "\nOutcome unknown: neither completed nor failed. Its actual effects are not inferred, and the owner keeps any fences." : ""}\nAutomatic review is not human review. Cadence mode remains enabled.`;
|
|
394
|
+
`Cadence ${run.status} • ${run.goal}\nRun: ${run.id} · route revision ${run.revision ?? 0} · stepsBefore ${run.stepsBefore ?? 0}\n${workflowDiagnostics(run)}\n${readableDeliveryRun(run.delivery)}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}${s.exitCode === null ? "" : ` (exit ${s.exitCode})`}\n${s.text}${s.truncated ? "\n[Preview truncated; full result retained by owner.]" : ""}`).join("\n")}\n${run.notice}${run.mergedCommit ? `\nLocal merge: ${run.mergedCommit}` : ""}${run.status === "unknown" ? "\nOutcome unknown: neither completed nor failed. Its actual effects are not inferred, and the owner keeps any fences." : ""}\nAutomatic review is not human review. Cadence mode remains enabled.`;
|
|
393
395
|
const agentDir = () => getAgentDir();
|
|
394
396
|
const conversation = (ctx: ExtensionContext) => {
|
|
395
397
|
const cwd = resolveWorkspace(ctx.cwd).cwd;
|
|
@@ -1067,7 +1069,7 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
|
|
|
1067
1069
|
name: "cadence_plan",
|
|
1068
1070
|
label: "Propose implementation plan",
|
|
1069
1071
|
description:
|
|
1070
|
-
"
|
|
1072
|
+
"Publish a readable delivery agreement: goal, acceptance, explicit boundaries, initial route, checks, setup, knowledge paths and delivery policy. Internal implementation routes may adapt after one approval. Does not execute.",
|
|
1071
1073
|
parameters: PLAN,
|
|
1072
1074
|
async execute(_id, input, _signal, _update, ctx) {
|
|
1073
1075
|
return changing(ctx, async (claim) => {
|
|
@@ -1135,9 +1137,9 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
|
|
|
1135
1137
|
});
|
|
1136
1138
|
pi.registerTool({
|
|
1137
1139
|
name: "cadence_start",
|
|
1138
|
-
label: "
|
|
1140
|
+
label: "Deliver approved goal",
|
|
1139
1141
|
description:
|
|
1140
|
-
"Start the current exact plan after fresh user approval. The service automatically implements, reviews, verifies,
|
|
1142
|
+
"Start the current exact plan after fresh user approval. The service automatically implements, reviews, verifies, recovers settled failures, adapts implementation, maintains project knowledge and delivers; client departure only detaches.",
|
|
1141
1143
|
parameters: Type.Object({}),
|
|
1142
1144
|
async execute(_id, _input, signal, _update, ctx) {
|
|
1143
1145
|
return changing(ctx, async (claim) => {
|
|
@@ -1247,11 +1249,12 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
|
|
|
1247
1249
|
name: "cadence_status",
|
|
1248
1250
|
label: "Observe workflow",
|
|
1249
1251
|
description:
|
|
1250
|
-
"Read a retained workflow without replaying any action. Specify runId for earlier runs; otherwise selects the current run. With stepId read its result, or transcript: true for its transcript.",
|
|
1252
|
+
"Read a retained workflow without replaying any action. Specify runId for earlier runs; otherwise selects the current run. With stepId read its result, or transcript: true for its transcript. If stepsBefore is nonzero, use before: stepsBefore to read earlier steps.",
|
|
1251
1253
|
parameters: Type.Object({
|
|
1252
1254
|
runId: Type.Optional(Type.String()),
|
|
1253
1255
|
stepId: Type.Optional(Type.String()),
|
|
1254
1256
|
transcript: Type.Optional(Type.Boolean()),
|
|
1257
|
+
before: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
1255
1258
|
}),
|
|
1256
1259
|
async execute(_id, input, _signal, _update, ctx) {
|
|
1257
1260
|
active(ctx);
|
|
@@ -1261,11 +1264,29 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
|
|
|
1261
1264
|
return result(
|
|
1262
1265
|
"Cadence is enabled; no run yet. Continue clarifying the goal.",
|
|
1263
1266
|
);
|
|
1267
|
+
if (input.before !== undefined && !input.stepId) {
|
|
1268
|
+
await connect(ctx, false);
|
|
1269
|
+
const page = value(
|
|
1270
|
+
await client().workbenchRead({
|
|
1271
|
+
kind: "workflow",
|
|
1272
|
+
id,
|
|
1273
|
+
before: input.before,
|
|
1274
|
+
}),
|
|
1275
|
+
);
|
|
1276
|
+
if (
|
|
1277
|
+
page.kind !== "workflow" ||
|
|
1278
|
+
page.response.type !== "run" ||
|
|
1279
|
+
page.response.run.id !== id
|
|
1280
|
+
)
|
|
1281
|
+
throw new ContractError("invalid");
|
|
1282
|
+
return result(summarize(page.response.run));
|
|
1283
|
+
}
|
|
1264
1284
|
if (input.stepId) {
|
|
1265
1285
|
const seen = await observe(ctx, id);
|
|
1266
1286
|
if (
|
|
1267
1287
|
"absent" in seen ||
|
|
1268
|
-
!seen.run.steps.some((s) => s.id === input.stepId)
|
|
1288
|
+
(!seen.run.steps.some((s) => s.id === input.stepId) &&
|
|
1289
|
+
!(seen.run.stepsBefore ?? 0))
|
|
1269
1290
|
)
|
|
1270
1291
|
throw new Error(
|
|
1271
1292
|
`Step ${input.stepId} does not belong to selected run ${id}. Supply the exact runId and stepId from the research result; no other run was searched.`,
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/** Fixed-revision, readonly Git evidence. Suspended pipes retain real stream
|
|
2
|
+
* positions under backpressure, never replay prefixes or spill source copies. */
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import { gitArguments, gitEnvironment } from "./git-environment.mjs";
|
|
7
|
+
|
|
8
|
+
export const CHANGE_LIMITS = Object.freeze({
|
|
9
|
+
scans: 4,
|
|
10
|
+
pageBytes: 2048,
|
|
11
|
+
idleMs: 120000,
|
|
12
|
+
operationMs: 30000,
|
|
13
|
+
});
|
|
14
|
+
export function createChangeTools(binding) {
|
|
15
|
+
binding = Object.freeze({ ...binding });
|
|
16
|
+
if (
|
|
17
|
+
typeof binding.root !== "string" ||
|
|
18
|
+
![binding.base, binding.candidate].every((oid) =>
|
|
19
|
+
/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(oid),
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
throw new Error("Invalid fixed Git evidence binding");
|
|
23
|
+
const scans = new Set(),
|
|
24
|
+
cursors = new Map();
|
|
25
|
+
let closing = false,
|
|
26
|
+
closeOriginal;
|
|
27
|
+
const stop = (scan) => {
|
|
28
|
+
clearTimeout(scan.timer);
|
|
29
|
+
if (
|
|
30
|
+
!scan.child.killed &&
|
|
31
|
+
scan.child.exitCode === null &&
|
|
32
|
+
scan.child.signalCode === null
|
|
33
|
+
)
|
|
34
|
+
scan.child.kill("SIGKILL");
|
|
35
|
+
scan.child.stdout.destroy();
|
|
36
|
+
};
|
|
37
|
+
const finish = async (scan) => {
|
|
38
|
+
stop(scan);
|
|
39
|
+
await scan.closed;
|
|
40
|
+
scans.delete(scan);
|
|
41
|
+
};
|
|
42
|
+
const execute = async (_id, args, signal) => {
|
|
43
|
+
if (closing) throw new Error("Change observations closed");
|
|
44
|
+
if (signal?.aborted) throw new Error("Change observation canceled");
|
|
45
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
46
|
+
throw new Error("Invalid change arguments");
|
|
47
|
+
let scan;
|
|
48
|
+
if (args.cursor !== undefined) {
|
|
49
|
+
if (
|
|
50
|
+
Object.keys(args).some((k) => !["cursor", "close"].includes(k)) ||
|
|
51
|
+
(args.close !== undefined && args.close !== true)
|
|
52
|
+
)
|
|
53
|
+
throw new Error("A change cursor cannot change its query");
|
|
54
|
+
scan = cursors.get(args.cursor);
|
|
55
|
+
if (!scan)
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Change cursor expired, consumed or foreign; start explicitly",
|
|
58
|
+
);
|
|
59
|
+
cursors.delete(args.cursor);
|
|
60
|
+
clearTimeout(scan.timer);
|
|
61
|
+
} else {
|
|
62
|
+
if (Object.keys(args).some((k) => !["mode", "path"].includes(k)))
|
|
63
|
+
throw new Error("Invalid change arguments");
|
|
64
|
+
const mode = args.mode ?? "paths",
|
|
65
|
+
path = args.path;
|
|
66
|
+
if (!["paths", "diff", "base", "candidate"].includes(mode))
|
|
67
|
+
throw new Error("Invalid change mode");
|
|
68
|
+
if (
|
|
69
|
+
path !== undefined &&
|
|
70
|
+
(typeof path !== "string" ||
|
|
71
|
+
!path ||
|
|
72
|
+
path.length > 1024 ||
|
|
73
|
+
path.includes("\\") ||
|
|
74
|
+
path.includes("\0") ||
|
|
75
|
+
path
|
|
76
|
+
.split("/")
|
|
77
|
+
.some(
|
|
78
|
+
(p) =>
|
|
79
|
+
!p || p === "." || p === ".." || p.toLowerCase() === ".git",
|
|
80
|
+
))
|
|
81
|
+
)
|
|
82
|
+
throw new Error("Select a checkout-relative path");
|
|
83
|
+
if (["base", "candidate"].includes(mode) && !path)
|
|
84
|
+
throw new Error("Select a file");
|
|
85
|
+
if (scans.size >= CHANGE_LIMITS.scans)
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Change cursor capacity reached; close an unused cursor",
|
|
88
|
+
);
|
|
89
|
+
const command =
|
|
90
|
+
mode === "paths" || mode === "diff"
|
|
91
|
+
? [
|
|
92
|
+
"diff",
|
|
93
|
+
...(mode === "paths"
|
|
94
|
+
? ["--name-status"]
|
|
95
|
+
: ["--no-color", "--unified=3"]),
|
|
96
|
+
"--no-renames",
|
|
97
|
+
"--no-ext-diff",
|
|
98
|
+
"--no-textconv",
|
|
99
|
+
binding.base,
|
|
100
|
+
binding.candidate,
|
|
101
|
+
"--",
|
|
102
|
+
...(path ? [path] : []),
|
|
103
|
+
]
|
|
104
|
+
: [
|
|
105
|
+
"show",
|
|
106
|
+
"--no-ext-diff",
|
|
107
|
+
"--no-textconv",
|
|
108
|
+
`${binding[mode]}:${path}`,
|
|
109
|
+
];
|
|
110
|
+
const child = spawn(
|
|
111
|
+
"git",
|
|
112
|
+
gitArguments([
|
|
113
|
+
"--no-pager",
|
|
114
|
+
"--no-lazy-fetch",
|
|
115
|
+
"--literal-pathspecs",
|
|
116
|
+
"-c",
|
|
117
|
+
"core.fsmonitor=false",
|
|
118
|
+
...command,
|
|
119
|
+
]),
|
|
120
|
+
{
|
|
121
|
+
cwd: binding.root,
|
|
122
|
+
env: gitEnvironment(),
|
|
123
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
124
|
+
windowsHide: true,
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
const closed = new Promise((resolve) => {
|
|
128
|
+
let error = false;
|
|
129
|
+
child.once("error", () => {
|
|
130
|
+
error = true;
|
|
131
|
+
});
|
|
132
|
+
child.once("close", (code) => resolve({ code, error }));
|
|
133
|
+
});
|
|
134
|
+
scan = {
|
|
135
|
+
child,
|
|
136
|
+
closed,
|
|
137
|
+
iterator: child.stdout[Symbol.asyncIterator](),
|
|
138
|
+
decoder: new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }),
|
|
139
|
+
buffer: Buffer.alloc(0),
|
|
140
|
+
bytes: 0,
|
|
141
|
+
active: undefined,
|
|
142
|
+
timer: undefined,
|
|
143
|
+
stopped: false,
|
|
144
|
+
};
|
|
145
|
+
scans.add(scan);
|
|
146
|
+
}
|
|
147
|
+
const selected = scan;
|
|
148
|
+
const original = (async () => {
|
|
149
|
+
if (args.close) {
|
|
150
|
+
await finish(selected);
|
|
151
|
+
return render("", "closed", null, selected.bytes);
|
|
152
|
+
}
|
|
153
|
+
const abort = () => {
|
|
154
|
+
selected.stopped = true;
|
|
155
|
+
stop(selected);
|
|
156
|
+
};
|
|
157
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
158
|
+
const timer = setTimeout(abort, CHANGE_LIMITS.operationMs);
|
|
159
|
+
timer.unref();
|
|
160
|
+
try {
|
|
161
|
+
if (signal?.aborted || closing) abort();
|
|
162
|
+
let done = false;
|
|
163
|
+
if (!selected.buffer.length && !selected.stopped) {
|
|
164
|
+
const next = await selected.iterator.next();
|
|
165
|
+
done = next.done === true;
|
|
166
|
+
if (!done) selected.buffer = Buffer.from(next.value);
|
|
167
|
+
}
|
|
168
|
+
if (selected.stopped || closing)
|
|
169
|
+
throw new Error(
|
|
170
|
+
"Change observation stopped; original Git closure joined",
|
|
171
|
+
);
|
|
172
|
+
const part = selected.buffer.subarray(0, CHANGE_LIMITS.pageBytes);
|
|
173
|
+
selected.buffer = selected.buffer.subarray(part.length);
|
|
174
|
+
if (part.includes(0))
|
|
175
|
+
throw new Error("Binary Git object omitted; not text evidence");
|
|
176
|
+
const text = selected.decoder.decode(part, { stream: !done });
|
|
177
|
+
selected.bytes += part.length;
|
|
178
|
+
if (done) {
|
|
179
|
+
const native = await selected.closed;
|
|
180
|
+
if (native.error || native.code !== 0)
|
|
181
|
+
throw new Error("Git evidence unavailable; no complete coverage");
|
|
182
|
+
await finish(selected);
|
|
183
|
+
return render(text, "done", null, selected.bytes);
|
|
184
|
+
}
|
|
185
|
+
const cursor = randomUUID();
|
|
186
|
+
cursors.set(cursor, selected);
|
|
187
|
+
selected.timer = setTimeout(() => {
|
|
188
|
+
cursors.delete(cursor);
|
|
189
|
+
void finish(selected);
|
|
190
|
+
}, CHANGE_LIMITS.idleMs);
|
|
191
|
+
selected.timer.unref();
|
|
192
|
+
return render(text, "more", cursor, selected.bytes);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
await finish(selected);
|
|
195
|
+
throw error;
|
|
196
|
+
} finally {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
signal?.removeEventListener("abort", abort);
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
selected.active = original;
|
|
202
|
+
try {
|
|
203
|
+
return await original;
|
|
204
|
+
} finally {
|
|
205
|
+
if (selected.active === original) selected.active = undefined;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function render(text, state, nextCursor, bytes) {
|
|
209
|
+
return {
|
|
210
|
+
content: [
|
|
211
|
+
{
|
|
212
|
+
type: "text",
|
|
213
|
+
text: JSON.stringify({
|
|
214
|
+
text,
|
|
215
|
+
state,
|
|
216
|
+
nextCursor,
|
|
217
|
+
bytes,
|
|
218
|
+
base: binding.base,
|
|
219
|
+
candidate: binding.candidate,
|
|
220
|
+
coverage: {
|
|
221
|
+
complete: state === "done",
|
|
222
|
+
consistency: "fixed-git-objects",
|
|
223
|
+
},
|
|
224
|
+
}),
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
details: { state, nextCursor },
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
tools: [
|
|
232
|
+
{
|
|
233
|
+
name: "changes",
|
|
234
|
+
label: "changes",
|
|
235
|
+
description:
|
|
236
|
+
"Readonly evidence for the owner's fixed base/candidate commits. mode paths lists changed paths (Git-quoted), diff reads patches, base/candidate reads one file at that revision. Optional checkout-relative path narrows a diff. Text may split across pages: continue exclusively with {cursor}; {cursor,close:true} releases it. more is incomplete, including empty progress. No arbitrary refs, Git commands, shell or writes.",
|
|
237
|
+
parameters: Type.Object(
|
|
238
|
+
{
|
|
239
|
+
mode: Type.Optional(
|
|
240
|
+
Type.String({ enum: ["paths", "diff", "base", "candidate"] }),
|
|
241
|
+
),
|
|
242
|
+
path: Type.Optional(Type.String({ maxLength: 1024 })),
|
|
243
|
+
cursor: Type.Optional(Type.String({ maxLength: 128 })),
|
|
244
|
+
close: Type.Optional(Type.Literal(true)),
|
|
245
|
+
},
|
|
246
|
+
{ additionalProperties: false },
|
|
247
|
+
),
|
|
248
|
+
execute,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
close() {
|
|
252
|
+
if (closeOriginal) return closeOriginal;
|
|
253
|
+
closing = true;
|
|
254
|
+
cursors.clear();
|
|
255
|
+
for (const scan of scans) {
|
|
256
|
+
scan.stopped = true;
|
|
257
|
+
stop(scan);
|
|
258
|
+
}
|
|
259
|
+
closeOriginal = Promise.all(
|
|
260
|
+
[...scans].map(async (scan) => {
|
|
261
|
+
await scan.active?.catch(() => {});
|
|
262
|
+
await finish(scan);
|
|
263
|
+
}),
|
|
264
|
+
).then(() => {});
|
|
265
|
+
return closeOriginal;
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Serialized private child/owner bridge. Never a browser API or shell executor. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
|
|
4
4
|
const CHECK = Type.Object({
|
|
@@ -11,7 +11,8 @@ const PLAN = Type.Object({
|
|
|
11
11
|
design: Type.String(),
|
|
12
12
|
decisions: Type.String(),
|
|
13
13
|
acceptance: Type.String(),
|
|
14
|
-
|
|
14
|
+
version: Type.Literal(2),
|
|
15
|
+
knowledge: Type.Array(Type.String(), { maxItems: 16 }),
|
|
15
16
|
tasks: Type.Array(
|
|
16
17
|
Type.Object({
|
|
17
18
|
id: Type.String(),
|
|
@@ -25,24 +26,27 @@ const PLAN = Type.Object({
|
|
|
25
26
|
checks: Type.Array(CHECK, { minItems: 1, maxItems: 16 }),
|
|
26
27
|
setup: Type.Array(CHECK, { maxItems: 4 }),
|
|
27
28
|
baselineChecks: Type.Array(CHECK, { maxItems: 16 }),
|
|
28
|
-
repairAttempts: Type.Integer({ minimum: 0, maximum: 2 }),
|
|
29
29
|
delivery: Type.Union([
|
|
30
30
|
Type.Literal("local-merge"),
|
|
31
31
|
Type.Literal("working-copy"),
|
|
32
32
|
]),
|
|
33
33
|
});
|
|
34
|
-
export function
|
|
34
|
+
export function createCoordinatorTools() {
|
|
35
35
|
if (!process.send) throw new Error("Coordinator bridge unavailable");
|
|
36
36
|
const pending = new Map();
|
|
37
37
|
let counter = 0;
|
|
38
38
|
let chain = Promise.resolve();
|
|
39
|
+
let disconnected = false;
|
|
40
|
+
let retiring = false;
|
|
41
|
+
let retirement;
|
|
39
42
|
const closed = () => {
|
|
43
|
+
disconnected = true;
|
|
40
44
|
for (const p of pending.values())
|
|
41
45
|
p.reject(new Error("Coordinator disconnected"));
|
|
42
46
|
pending.clear();
|
|
43
47
|
};
|
|
44
48
|
process.on("disconnect", closed);
|
|
45
|
-
|
|
49
|
+
const receive = (reply) => {
|
|
46
50
|
if (
|
|
47
51
|
!reply ||
|
|
48
52
|
typeof reply !== "object" ||
|
|
@@ -58,8 +62,9 @@ export function coordinatorTools() {
|
|
|
58
62
|
details: undefined,
|
|
59
63
|
});
|
|
60
64
|
else p.reject(new Error("Coordinator refused this request"));
|
|
61
|
-
}
|
|
62
|
-
|
|
65
|
+
};
|
|
66
|
+
process.on("message", receive);
|
|
67
|
+
const tools = [
|
|
63
68
|
{
|
|
64
69
|
name: "cadence_research",
|
|
65
70
|
description:
|
|
@@ -94,25 +99,48 @@ export function coordinatorTools() {
|
|
|
94
99
|
...tool,
|
|
95
100
|
label: tool.name,
|
|
96
101
|
execute: async (_callId, args, signal) => {
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
const request = { id: counter, name: tool.name, args };
|
|
102
|
+
if (retiring) throw new Error("Coordinator closed");
|
|
103
|
+
if (signal?.aborted) throw new Error("Coordinator canceled");
|
|
104
|
+
const request = { id: ++counter, name: tool.name, args };
|
|
100
105
|
if (Buffer.byteLength(JSON.stringify(request)) > 65536)
|
|
101
106
|
throw new Error("Coordinator request exceeds bound");
|
|
102
107
|
const original = chain.then(
|
|
103
108
|
() =>
|
|
104
109
|
new Promise((resolve, reject) => {
|
|
110
|
+
if (signal?.aborted) throw new Error("Coordinator canceled");
|
|
111
|
+
if (disconnected) throw new Error("Coordinator disconnected");
|
|
112
|
+
if (retiring) throw new Error("Coordinator closed");
|
|
105
113
|
pending.set(request.id, { resolve, reject });
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
const unavailable = () => {
|
|
115
|
+
pending.delete(request.id);
|
|
116
|
+
reject(new Error("Coordinator request unavailable"));
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
process.send(request, (error) => {
|
|
120
|
+
if (error) unavailable();
|
|
121
|
+
});
|
|
122
|
+
} catch {
|
|
123
|
+
// Synchronous transport failures own the same cleanup as the
|
|
124
|
+
// callback path; never retain pending entries or expose raw errors.
|
|
125
|
+
unavailable();
|
|
126
|
+
}
|
|
112
127
|
}),
|
|
113
128
|
);
|
|
114
129
|
chain = original.catch(() => {});
|
|
115
130
|
return original;
|
|
116
131
|
},
|
|
117
132
|
}));
|
|
133
|
+
return {
|
|
134
|
+
tools,
|
|
135
|
+
close() {
|
|
136
|
+
retiring = true;
|
|
137
|
+
// Already-sent calls still own their original reply/disconnect lifetime.
|
|
138
|
+
// Queued calls refuse before sending; listeners stay until that joins.
|
|
139
|
+
retirement ??= chain.finally(() => {
|
|
140
|
+
process.removeListener("disconnect", closed);
|
|
141
|
+
process.removeListener("message", receive);
|
|
142
|
+
});
|
|
143
|
+
return retirement;
|
|
144
|
+
},
|
|
145
|
+
};
|
|
118
146
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Shared physical-checkout Git execution policy. No inherited alternate index,
|
|
2
|
+
* worktree, config injection or sudo-account trust; never writes configuration. */
|
|
3
|
+
export function gitEnvironment() {
|
|
4
|
+
const root = process.getuid?.() === 0;
|
|
5
|
+
return {
|
|
6
|
+
...Object.fromEntries(
|
|
7
|
+
Object.entries(process.env).filter(
|
|
8
|
+
([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"),
|
|
9
|
+
),
|
|
10
|
+
),
|
|
11
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
12
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
13
|
+
LC_ALL: "C",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function gitArguments(args) {
|
|
17
|
+
return [
|
|
18
|
+
"--no-replace-objects",
|
|
19
|
+
...(process.platform !== "win32" && process.getuid?.() === 0
|
|
20
|
+
? ["-c", "safe.directory=", "-c", "core.fsmonitor=false"]
|
|
21
|
+
: []),
|
|
22
|
+
...args,
|
|
23
|
+
];
|
|
24
|
+
}
|
package/src/image-content.mjs
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
1
|
+
/** Upload chunks and history parts fit existing control replies. There are no
|
|
2
|
+
* image-specific count, byte or dimension quotas; runtime/provider limits apply.
|
|
3
|
+
* Image bytes never enlarge the public worker request or become prompt text. */
|
|
4
4
|
export const IMAGE_LIMITS = Object.freeze({
|
|
5
|
-
count: IMAGE_COUNT,
|
|
6
|
-
bytes: 4 * 1024 * 1024,
|
|
7
|
-
totalBytes: 8 * 1024 * 1024,
|
|
8
5
|
chunkChars: 256 * 1024,
|
|
9
|
-
stagedBytes: 64 * 1024 * 1024,
|
|
10
|
-
stagedCount: 64,
|
|
11
6
|
idleMs: 10 * 60 * 1000,
|
|
12
|
-
pixels: 32 * 1024 * 1024,
|
|
13
|
-
dimension: 16384,
|
|
14
|
-
wireBytes: 12 * 1024 * 1024,
|
|
15
7
|
});
|
|
16
8
|
export const IMAGE_TYPES = Object.freeze([
|
|
17
9
|
"image/png",
|
|
@@ -19,17 +11,15 @@ export const IMAGE_TYPES = Object.freeze([
|
|
|
19
11
|
"image/webp",
|
|
20
12
|
]);
|
|
21
13
|
|
|
22
|
-
export function decodeImageBase64(data
|
|
14
|
+
export function decodeImageBase64(data) {
|
|
23
15
|
if (
|
|
24
16
|
typeof data !== "string" ||
|
|
25
17
|
!data.length ||
|
|
26
18
|
data.length % 4 ||
|
|
27
|
-
data.length > 4 * Math.ceil(maxBytes / 3) ||
|
|
28
19
|
!/^[A-Za-z0-9+/]*={0,2}$/.test(data)
|
|
29
20
|
)
|
|
30
21
|
throw new Error("Invalid image encoding");
|
|
31
22
|
const raw = atob(data);
|
|
32
|
-
if (raw.length > maxBytes) throw new Error("Image is too large");
|
|
33
23
|
const bytes = new Uint8Array(raw.length);
|
|
34
24
|
for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
|
|
35
25
|
return bytes;
|
|
@@ -37,12 +27,8 @@ export function decodeImageBase64(data, maxBytes = IMAGE_LIMITS.bytes) {
|
|
|
37
27
|
|
|
38
28
|
/** Bounded header validation, not an image transcoder. No SVG/HTML or remote URLs. */
|
|
39
29
|
export function validateImageBytes(bytes, mimeType) {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
!bytes.length ||
|
|
43
|
-
bytes.length > IMAGE_LIMITS.bytes
|
|
44
|
-
)
|
|
45
|
-
throw new Error("Unsupported image or size");
|
|
30
|
+
if (!IMAGE_TYPES.includes(mimeType) || !bytes.length)
|
|
31
|
+
throw new Error("Unsupported or empty image");
|
|
46
32
|
const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
47
33
|
const ascii = (at, value) =>
|
|
48
34
|
[...value].every((c, i) => bytes[at + i] === c.charCodeAt(0));
|
|
@@ -108,13 +94,6 @@ export function validateImageBytes(bytes, mimeType) {
|
|
|
108
94
|
height = 1 + ((bits >>> 14) & 16383);
|
|
109
95
|
}
|
|
110
96
|
}
|
|
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");
|
|
97
|
+
if (!width || !height) throw new Error("Invalid image dimensions or header");
|
|
119
98
|
return { width, height };
|
|
120
99
|
}
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default function register(pi: ExtensionAPI): void {
|
|
|
18
18
|
registerSessionSharing(pi);
|
|
19
19
|
// Observes `subagent:*` bus events only; renders nothing until one arrives.
|
|
20
20
|
registerAgentPanel(pi);
|
|
21
|
-
// Publishes
|
|
21
|
+
// Publishes only this conversation's live workflow children; never starts work.
|
|
22
22
|
registerCadenceAgentFeed(pi);
|
|
23
23
|
pi.on("session_start", (_event, ctx) => {
|
|
24
24
|
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc")) return;
|
package/src/native-build.ts
CHANGED