@abelxiaoxing/cadence 2.0.37 → 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 +2 -2
- package/README.es.md +2 -2
- package/README.fr.md +2 -2
- package/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +9 -7
- package/README.pt-BR.md +2 -2
- package/README.ru.md +2 -2
- package/README.zh-CN.md +10 -8
- 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 +43 -16
- package/package.json +4 -1
- package/src/agent-browser/session-navigator.ts +33 -6
- package/src/agent-browser/source.ts +23 -19
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +30 -19
- package/src/agent-panel.ts +12 -16
- 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 +2 -2
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- 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/sdk-worker.mjs +2 -0
- package/src/service/contracts/workbench.ts +11 -3
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +7 -0
- package/src/service-cli.mjs +366 -85
- package/src/service-host.mjs +2450 -983
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +18 -0
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +48 -1
- 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
package/src/agent-panel-model.ts
CHANGED
|
@@ -18,7 +18,12 @@ export const SUBAGENT_VIEW = "subagent:view";
|
|
|
18
18
|
* of the model's context. */
|
|
19
19
|
export const CARD_ENTRY = "cadence-agent-batch";
|
|
20
20
|
|
|
21
|
-
export type SubagentStatus =
|
|
21
|
+
export type SubagentStatus =
|
|
22
|
+
| "running"
|
|
23
|
+
| "done"
|
|
24
|
+
| "rejected"
|
|
25
|
+
| "error"
|
|
26
|
+
| "cancelled";
|
|
22
27
|
type Ended = Exclude<SubagentStatus, "running">;
|
|
23
28
|
|
|
24
29
|
export interface SubagentState {
|
|
@@ -49,12 +54,9 @@ export interface SubagentState {
|
|
|
49
54
|
|
|
50
55
|
/** Retained messages per agent; older ones are counted, not kept. */
|
|
51
56
|
export const MAX_MESSAGES = 2000;
|
|
52
|
-
/** Ended agents kept for review outside the open batch; older ones are
|
|
53
|
-
* dropped with their messages once a batch collapses into its card. */
|
|
54
|
-
export const MAX_ENDED = 24;
|
|
55
57
|
/** Agents written into one card; more are counted, not listed. */
|
|
56
58
|
export const MAX_CARD_AGENTS = 64;
|
|
57
|
-
const ENDED = new Set(["done", "error", "cancelled"]);
|
|
59
|
+
const ENDED = new Set(["done", "rejected", "error", "cancelled"]);
|
|
58
60
|
|
|
59
61
|
const record = (v: unknown): Record<string, unknown> | undefined =>
|
|
60
62
|
v && typeof v === "object" && !Array.isArray(v)
|
|
@@ -120,16 +122,14 @@ export class SubagentStore {
|
|
|
120
122
|
this.batchIds = [];
|
|
121
123
|
return batch;
|
|
122
124
|
}
|
|
123
|
-
/** Drop ended agents
|
|
124
|
-
*
|
|
125
|
-
* not called: the
|
|
126
|
-
prune(
|
|
125
|
+
/** Drop ended agents once their batch has become a display card. An open
|
|
126
|
+
* transcript already holds its own state reference; no history list stays.
|
|
127
|
+
* Listeners are not called: the panel owns the redraw. */
|
|
128
|
+
prune(): string[] {
|
|
127
129
|
const open = new Set(this.batchOpen ? this.batchIds : []);
|
|
128
|
-
const
|
|
129
|
-
(a) =>
|
|
130
|
-
a.status !== "running" && !open.has(a.id) && !retain.includes(a.id),
|
|
130
|
+
const drop = [...this.agents.values()].filter(
|
|
131
|
+
(a) => a.status !== "running" && !open.has(a.id),
|
|
131
132
|
);
|
|
132
|
-
const drop = ended.slice(0, Math.max(0, ended.length - keep));
|
|
133
133
|
for (const a of drop) this.agents.delete(a.id);
|
|
134
134
|
return drop.map((a) => a.id);
|
|
135
135
|
}
|
|
@@ -265,6 +265,7 @@ export const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧",
|
|
|
265
265
|
const SYMBOL: Record<Ended, [string, PaintRole]> = {
|
|
266
266
|
done: ["✔", "success"],
|
|
267
267
|
error: ["✘", "error"],
|
|
268
|
+
rejected: ["⊘", "accent"],
|
|
268
269
|
cancelled: ["○", "muted"],
|
|
269
270
|
};
|
|
270
271
|
export function statusSymbol(
|
|
@@ -431,7 +432,7 @@ export function decodeCard(data: unknown): AgentCard | undefined {
|
|
|
431
432
|
}
|
|
432
433
|
|
|
433
434
|
/** A finished batch: `✔ 3 Research agents finished · 2m 14s`, with outcome
|
|
434
|
-
* counts when any failed or was cancelled. Collapsed, it lists only those;
|
|
435
|
+
* counts when any failed, rejected or was cancelled. Collapsed, it lists only those;
|
|
435
436
|
* expanded, every member with its final text and elapsed time. */
|
|
436
437
|
export function cardLines(
|
|
437
438
|
card: AgentCard,
|
|
@@ -444,13 +445,22 @@ export function cardLines(
|
|
|
444
445
|
const tally = (status: Ended) =>
|
|
445
446
|
card.agents.filter((a) => a.status === status).length;
|
|
446
447
|
const failed = tally("error"),
|
|
448
|
+
rejected = tally("rejected"),
|
|
447
449
|
cancelled = tally("cancelled");
|
|
448
450
|
const [symbol, role] =
|
|
449
|
-
SYMBOL[
|
|
451
|
+
SYMBOL[
|
|
452
|
+
failed
|
|
453
|
+
? "error"
|
|
454
|
+
: rejected
|
|
455
|
+
? "rejected"
|
|
456
|
+
: cancelled
|
|
457
|
+
? "cancelled"
|
|
458
|
+
: "done"
|
|
459
|
+
];
|
|
450
460
|
const kind = sharedKind(card.agents);
|
|
451
461
|
const outcome =
|
|
452
|
-
failed || cancelled
|
|
453
|
-
? ` · ${tally("done")} done${failed ? ` · ${failed} failed` : ""}${
|
|
462
|
+
failed || rejected || cancelled
|
|
463
|
+
? ` · ${tally("done")} done${failed ? ` · ${failed} failed` : ""}${rejected ? ` · ${rejected} rejected` : ""}${
|
|
454
464
|
cancelled ? ` · ${cancelled} cancelled` : ""
|
|
455
465
|
}`
|
|
456
466
|
: "";
|
|
@@ -487,7 +497,7 @@ export interface LiveFrame {
|
|
|
487
497
|
agents: SubagentState[];
|
|
488
498
|
now: number;
|
|
489
499
|
frame: number;
|
|
490
|
-
/** Show the `↓ to
|
|
500
|
+
/** Show the `↓ to view` hint: the input box has focus. */
|
|
491
501
|
hint: boolean;
|
|
492
502
|
}
|
|
493
503
|
/** One summary line; the adapted session browser owns all agent rows. */
|
|
@@ -502,10 +512,11 @@ export function liveLines(f: LiveFrame, width: number, paint: Paint): string[] {
|
|
|
502
512
|
agents.filter((a) => a.status === status).length;
|
|
503
513
|
const done = tally("done"),
|
|
504
514
|
failed = tally("error"),
|
|
515
|
+
rejected = tally("rejected"),
|
|
505
516
|
cancelled = tally("cancelled");
|
|
506
517
|
const counts = `${done ? ` · ${done} done` : ""}${
|
|
507
518
|
failed ? ` · ${failed} failed` : ""
|
|
508
|
-
}${cancelled ? ` · ${cancelled} cancelled` : ""}`;
|
|
519
|
+
}${rejected ? ` · ${rejected} rejected` : ""}${cancelled ? ` · ${cancelled} cancelled` : ""}`;
|
|
509
520
|
const [spin, role] = statusSymbol(running[0], f.frame);
|
|
510
521
|
const header = hinted(
|
|
511
522
|
`${paint(role, spin)} ${running.length} ${noun(kind, running.length)} running${counts}`,
|
package/src/agent-panel.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
cardOf,
|
|
23
23
|
decodeCard,
|
|
24
24
|
liveLines,
|
|
25
|
-
MAX_ENDED,
|
|
26
25
|
type Paint,
|
|
27
26
|
SUBAGENT_EVENTS,
|
|
28
27
|
SUBAGENT_VIEW,
|
|
@@ -48,10 +47,10 @@ export function registerAgentPanel(
|
|
|
48
47
|
pi: ExtensionAPI,
|
|
49
48
|
options: AgentPanelOptions = {},
|
|
50
49
|
): void {
|
|
51
|
-
|
|
50
|
+
let store: SubagentStore | undefined;
|
|
52
51
|
for (const channel of Object.values(SUBAGENT_EVENTS))
|
|
53
52
|
pi.events.on(channel, (data) => {
|
|
54
|
-
store
|
|
53
|
+
store?.apply(channel, data);
|
|
55
54
|
});
|
|
56
55
|
pi.registerEntryRenderer(CARD_ENTRY, (entry, { expanded }, theme) => {
|
|
57
56
|
const card = decodeCard(entry.data);
|
|
@@ -70,6 +69,7 @@ export function registerAgentPanel(
|
|
|
70
69
|
let detach: (() => void) | undefined;
|
|
71
70
|
pi.on("session_start", (_event, ctx) => {
|
|
72
71
|
detach?.();
|
|
72
|
+
store = new SubagentStore(options.now);
|
|
73
73
|
detach =
|
|
74
74
|
ctx.mode === "tui" && ctx.hasUI
|
|
75
75
|
? attachPanel(
|
|
@@ -84,6 +84,7 @@ export function registerAgentPanel(
|
|
|
84
84
|
pi.on("session_shutdown", () => {
|
|
85
85
|
detach?.();
|
|
86
86
|
detach = undefined;
|
|
87
|
+
store = undefined;
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -96,8 +97,6 @@ function attachPanel(
|
|
|
96
97
|
): () => void {
|
|
97
98
|
const now = options.now ?? Date.now;
|
|
98
99
|
const keep = options.keep ?? process.env.CADENCE_AGENT_PANEL === "always";
|
|
99
|
-
if (store.settled()) store.closeBatch();
|
|
100
|
-
store.prune(0);
|
|
101
100
|
let tui: TUI | undefined;
|
|
102
101
|
let frame = 0;
|
|
103
102
|
let spinner: ReturnType<typeof setInterval> | undefined;
|
|
@@ -114,11 +113,10 @@ function attachPanel(
|
|
|
114
113
|
clearInterval(spinner);
|
|
115
114
|
spinner = undefined;
|
|
116
115
|
};
|
|
117
|
-
const source = cadenceBrowserSource(store, announce, now);
|
|
118
116
|
const mount = () => {
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
const show =
|
|
117
|
+
// Keep a handle only for a live batch (or an explicitly kept summary),
|
|
118
|
+
// never just because old agents remain in memory.
|
|
119
|
+
const show = liveAgents().length > 0;
|
|
122
120
|
if (show === mounted) return;
|
|
123
121
|
mounted = show;
|
|
124
122
|
ctx.ui.setWidget(
|
|
@@ -155,14 +153,11 @@ function attachPanel(
|
|
|
155
153
|
/* A replaced runtime cannot append. */
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
|
-
for (const id of store.prune(
|
|
159
|
-
browser?.selected,
|
|
160
|
-
browser?.viewing,
|
|
161
|
-
]))
|
|
162
|
-
positions.delete(id);
|
|
156
|
+
for (const id of store.prune()) positions.delete(id);
|
|
163
157
|
};
|
|
164
158
|
const changed = () => {
|
|
165
159
|
if (detached) return;
|
|
160
|
+
for (const id of store.prune()) positions.delete(id);
|
|
166
161
|
if (kept.length && store.batch().length) kept = [];
|
|
167
162
|
if (!store.settled()) {
|
|
168
163
|
clearTimeout(settling);
|
|
@@ -201,7 +196,8 @@ function attachPanel(
|
|
|
201
196
|
t,
|
|
202
197
|
theme,
|
|
203
198
|
keys,
|
|
204
|
-
|
|
199
|
+
// Transcript caches belong to this interaction, not future batches.
|
|
200
|
+
cadenceBrowserSource(store, announce, now),
|
|
205
201
|
ctx.cwd,
|
|
206
202
|
positions,
|
|
207
203
|
closeBrowser,
|
|
@@ -242,7 +238,7 @@ function attachPanel(
|
|
|
242
238
|
)
|
|
243
239
|
return;
|
|
244
240
|
if (
|
|
245
|
-
|
|
241
|
+
store.running() === 0 ||
|
|
246
242
|
ctx.ui.getEditorText() !== "" ||
|
|
247
243
|
tui?.hasOverlay() ||
|
|
248
244
|
!(
|
|
@@ -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
|
+
}
|
|
@@ -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,7 +26,6 @@ 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"),
|