@abelxiaoxing/cadence 2.0.37 → 2.0.40
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 +73 -16
- package/docs/reuse-and-distribution.md +78 -0
- package/package.json +7 -2
- package/src/activity.ts +147 -0
- 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 +3 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +22 -12
- package/src/research-scan.mjs +111 -31
- package/src/research-tools.mjs +75 -16
- package/src/sdk-worker.mjs +6 -1
- package/src/service/activity-files.ts +190 -0
- package/src/service/contracts/workbench.ts +11 -3
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +13 -3
- package/src/service-cli.mjs +392 -93
- package/src/service-host.mjs +7635 -5682
- 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 +55 -2
- package/src/workspace.ts +62 -25
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +19 -18
- package/web/dist/manifest.json +7 -7
package/src/worker-capture.mjs
CHANGED
|
@@ -947,7 +947,9 @@ export class SdkCapture {
|
|
|
947
947
|
const message = own(event, "message");
|
|
948
948
|
const rawRole = own(message, "role");
|
|
949
949
|
const role = rawRole === "toolResult" ? "tool-result" : rawRole;
|
|
950
|
-
requireFact(
|
|
950
|
+
requireFact(
|
|
951
|
+
["system", "user", "assistant", "tool-result"].includes(role),
|
|
952
|
+
);
|
|
951
953
|
const matches =
|
|
952
954
|
role === "tool-result"
|
|
953
955
|
? this.matches(
|
|
@@ -964,6 +966,23 @@ export class SdkCapture {
|
|
|
964
966
|
streams: new Map(),
|
|
965
967
|
declarations: new Map(),
|
|
966
968
|
};
|
|
969
|
+
if (role === "system") {
|
|
970
|
+
// Pi emits prompt/section/tool-loadout changes as paired system
|
|
971
|
+
// messages. The initial effective prompt is already captured as
|
|
972
|
+
// context; these additional SDK control bodies are not chat output.
|
|
973
|
+
// Keep their lifecycle strict and their omitted source explicit,
|
|
974
|
+
// without copying tool definitions or claiming complete capture.
|
|
975
|
+
await this.emit({
|
|
976
|
+
kind: "omitted-block",
|
|
977
|
+
block: {
|
|
978
|
+
owner: { kind: "context", component: "effective-system" },
|
|
979
|
+
sourceType: "unsupported",
|
|
980
|
+
mimeType: null,
|
|
981
|
+
reason: "unsupported",
|
|
982
|
+
},
|
|
983
|
+
});
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
967
986
|
await this.emit({
|
|
968
987
|
kind: "message-start",
|
|
969
988
|
messageId: this.current.id,
|
|
@@ -1054,6 +1073,10 @@ export class SdkCapture {
|
|
|
1054
1073
|
? "tool-result"
|
|
1055
1074
|
: own(message, "role")) === m.role,
|
|
1056
1075
|
);
|
|
1076
|
+
if (m.role === "system") {
|
|
1077
|
+
this.current = null;
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1057
1080
|
for (const stream of m.streams.values())
|
|
1058
1081
|
await this.streamWrite(stream, "", true);
|
|
1059
1082
|
const { texts, count } = await this.blocks(
|
package/src/worker-public.mjs
CHANGED
|
@@ -938,6 +938,7 @@ export function decodeWorkerPublicRequest(v) {
|
|
|
938
938
|
"instructions",
|
|
939
939
|
"prompt",
|
|
940
940
|
...(Object.hasOwn(v ?? {}, "imageCount") ? ["imageCount"] : []),
|
|
941
|
+
...(Object.hasOwn(v ?? {}, "changes") ? ["changes"] : []),
|
|
941
942
|
"handoff",
|
|
942
943
|
]);
|
|
943
944
|
const result = {
|
|
@@ -960,6 +961,23 @@ export function decodeWorkerPublicRequest(v) {
|
|
|
960
961
|
};
|
|
961
962
|
if (result.handoff.inputs.some((i) => i.assignmentId !== result.assignmentId))
|
|
962
963
|
invalid();
|
|
964
|
+
if (o.changes !== undefined) {
|
|
965
|
+
const c = closed(o.changes, ["root", "base", "candidate"]);
|
|
966
|
+
const root = text(c.root, 4096, true);
|
|
967
|
+
if (
|
|
968
|
+
result.purpose !== "review" ||
|
|
969
|
+
!/^(?:\/|[A-Za-z]:[\\/]|\\\\)/u.test(root) ||
|
|
970
|
+
root.includes("\0")
|
|
971
|
+
)
|
|
972
|
+
throw new Error("Invalid review binding");
|
|
973
|
+
const oid = (value) => {
|
|
974
|
+
const s = text(value, 64, true);
|
|
975
|
+
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(s))
|
|
976
|
+
throw new Error("Invalid review object");
|
|
977
|
+
return s;
|
|
978
|
+
};
|
|
979
|
+
result.changes = { root, base: oid(c.base), candidate: oid(c.candidate) };
|
|
980
|
+
}
|
|
963
981
|
if (
|
|
964
982
|
(result.taskKind !== "code" && result.purpose === "edit") ||
|
|
965
983
|
result.role.role !== roleForPurpose(result.purpose)
|
package/src/worker-redaction.mjs
CHANGED
|
@@ -219,6 +219,17 @@ export class TextSanitizer {
|
|
|
219
219
|
this.redacted ||= pos >= 0;
|
|
220
220
|
this.heuristic = this.heuristic.slice(size);
|
|
221
221
|
} else if (match) {
|
|
222
|
+
// A key/delimiter can arrive before its whitespace and value. Starting
|
|
223
|
+
// the skip state now would let that whitespace end it before any value
|
|
224
|
+
// was consumed, leaking a split value or duplicating an old marker.
|
|
225
|
+
// Keep only the bounded prefix until the first value character arrives.
|
|
226
|
+
if (!final && match.index + match[0].length === this.heuristic.length) {
|
|
227
|
+
output += this.heuristic.slice(0, match.index);
|
|
228
|
+
this.heuristic = this.heuristic.slice(match.index);
|
|
229
|
+
if (utf8Bytes(this.heuristic) > 8192)
|
|
230
|
+
throw new ContractError("oversize");
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
222
233
|
output += this.heuristic.slice(0, match.index) + match[0] + marker;
|
|
223
234
|
this.heuristic = this.heuristic.slice(match.index + match[0].length);
|
|
224
235
|
this.skipping = true;
|
package/src/worker-toolkit.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/** Trusted capability composition. No discovery, plugin claims or model-selected
|
|
2
2
|
* permissions. Role prompts do not grant tools; the validated owner request does. */
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { createChangeTools } from "./change-tools.mjs";
|
|
3
5
|
import { createCoordinatorTools } from "./coordinator-tools.mjs";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createResearchTools,
|
|
8
|
+
RESEARCH_INSTRUCTIONS,
|
|
9
|
+
} from "./research-tools.mjs";
|
|
10
|
+
import { sanitizeText } from "./worker-redaction.mjs";
|
|
5
11
|
import { captureBash } from "./worker-tools.mjs";
|
|
6
12
|
|
|
7
13
|
const policies = Object.freeze({
|
|
@@ -30,6 +36,7 @@ const bundles = {
|
|
|
30
36
|
],
|
|
31
37
|
}),
|
|
32
38
|
observation: ({ workspace }) => createResearchTools(workspace),
|
|
39
|
+
changes: ({ changes }) => createChangeTools(changes),
|
|
33
40
|
coordination: () => createCoordinatorTools(),
|
|
34
41
|
};
|
|
35
42
|
|
|
@@ -41,12 +48,55 @@ export function createWorkerToolkit(options) {
|
|
|
41
48
|
(coordinator && purpose !== "research")
|
|
42
49
|
)
|
|
43
50
|
throw new Error("Invalid worker capability selection");
|
|
44
|
-
|
|
51
|
+
if (
|
|
52
|
+
options.changes &&
|
|
53
|
+
(purpose !== "review" ||
|
|
54
|
+
coordinator ||
|
|
55
|
+
options.changes.root !== options.workspace.roots[0])
|
|
56
|
+
)
|
|
57
|
+
throw new Error("Invalid review capability binding");
|
|
58
|
+
const capabilities = options.changes
|
|
59
|
+
? Object.freeze([...policies[purpose], "changes"])
|
|
60
|
+
: policies[coordinator ? "coordination" : purpose];
|
|
45
61
|
const owned = capabilities.map((capability) => bundles[capability](options));
|
|
46
62
|
const customTools = owned.flatMap((bundle) => bundle.tools);
|
|
63
|
+
if (options.reporting && !coordinator && purpose === "edit")
|
|
64
|
+
customTools.push({
|
|
65
|
+
name: "cadence_report",
|
|
66
|
+
label: "Report assignment outcome",
|
|
67
|
+
description:
|
|
68
|
+
"Submit this assignment's structured result after all work. Completed means assigned work is done, not that owner checks or review passed. Use blocked for remaining work. Then give a brief final answer; no JSON formatting is required in that answer. Any later tool call requires a new report.",
|
|
69
|
+
parameters: Type.Object({
|
|
70
|
+
status: Type.Union([
|
|
71
|
+
Type.Literal("completed"),
|
|
72
|
+
Type.Literal("blocked"),
|
|
73
|
+
]),
|
|
74
|
+
summary: Type.String({ minLength: 1, maxLength: 8192 }),
|
|
75
|
+
}),
|
|
76
|
+
async execute(_id, input) {
|
|
77
|
+
if (
|
|
78
|
+
!input ||
|
|
79
|
+
!["completed", "blocked"].includes(input.status) ||
|
|
80
|
+
typeof input.summary !== "string" ||
|
|
81
|
+
!input.summary.trim() ||
|
|
82
|
+
Object.keys(input).some((key) => !["status", "summary"].includes(key))
|
|
83
|
+
)
|
|
84
|
+
throw new Error("Invalid assignment report");
|
|
85
|
+
const report = {
|
|
86
|
+
status: input.status,
|
|
87
|
+
summary: sanitizeText(input.summary, options.secrets ?? []),
|
|
88
|
+
};
|
|
89
|
+
const text = JSON.stringify(report);
|
|
90
|
+
if (!report.summary.trim() || Buffer.byteLength(text) > 16384)
|
|
91
|
+
throw new Error("Assignment report exceeds bound");
|
|
92
|
+
return { content: [{ type: "text", text }], details: undefined };
|
|
93
|
+
},
|
|
94
|
+
});
|
|
47
95
|
const names = owned.flatMap(
|
|
48
96
|
(bundle) => bundle.names ?? bundle.tools.map((tool) => tool.name),
|
|
49
97
|
);
|
|
98
|
+
if (options.reporting && !coordinator && purpose === "edit")
|
|
99
|
+
names.push("cadence_report");
|
|
50
100
|
if (new Set(names).size !== names.length)
|
|
51
101
|
throw new Error("Duplicate worker tool");
|
|
52
102
|
const originals = new Set();
|
|
@@ -54,6 +104,9 @@ export function createWorkerToolkit(options) {
|
|
|
54
104
|
closing;
|
|
55
105
|
return {
|
|
56
106
|
capabilities,
|
|
107
|
+
instructions: capabilities.includes("observation")
|
|
108
|
+
? RESEARCH_INSTRUCTIONS
|
|
109
|
+
: "",
|
|
57
110
|
// Explicit allowlists are required by the installed public Pi SDK. Omitting
|
|
58
111
|
// one would enable its defaults, not mean "only our custom capabilities".
|
|
59
112
|
sessionOptions: {
|
package/src/workspace.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { gitArguments, gitEnvironment } from "./git-environment.mjs";
|
|
2
|
+
|
|
3
|
+
export { gitArguments, gitEnvironment } from "./git-environment.mjs";
|
|
4
|
+
|
|
1
5
|
/** Workspace identity and bounded filesystem operations, independent of task records. */
|
|
2
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
3
7
|
import { createHash } from "node:crypto";
|
|
4
8
|
import {
|
|
5
9
|
closeSync,
|
|
@@ -158,30 +162,6 @@ export function readBounded(
|
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
/** Git observations describe the physical cwd, not inherited alternate
|
|
162
|
-
* index/worktree overrides. Root never borrows sudo's original user's trust. */
|
|
163
|
-
export function gitEnvironment(): NodeJS.ProcessEnv {
|
|
164
|
-
const root = process.getuid?.() === 0;
|
|
165
|
-
return {
|
|
166
|
-
...Object.fromEntries(
|
|
167
|
-
Object.entries(process.env).filter(
|
|
168
|
-
([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"),
|
|
169
|
-
),
|
|
170
|
-
),
|
|
171
|
-
GIT_OPTIONAL_LOCKS: "0",
|
|
172
|
-
LC_ALL: "C",
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
/** Observation is not permission to trust another account's repository.
|
|
176
|
-
* Even with fsmonitor/textconv/ext-diff disabled, status/diff can invoke clean
|
|
177
|
-
* or process filters. Root therefore requires Git's own ownership check, with
|
|
178
|
-
* no safe.directory exceptions (including inherited wildcards). No config is
|
|
179
|
-
* written and ordinary-user trust behavior stays unchanged. */
|
|
180
|
-
export function gitArguments(args: string[]): string[] {
|
|
181
|
-
return process.platform !== "win32" && process.getuid?.() === 0
|
|
182
|
-
? ["-c", "safe.directory=", "-c", "core.fsmonitor=false", ...args]
|
|
183
|
-
: args;
|
|
184
|
-
}
|
|
185
165
|
export function resolveWorkspace(cwd: string): { root: string; cwd: string } {
|
|
186
166
|
const actual = realpathSync(cwd);
|
|
187
167
|
const result = spawnSync(
|
|
@@ -196,6 +176,63 @@ export function resolveWorkspace(cwd: string): { root: string; cwd: string } {
|
|
|
196
176
|
windowsHide: true,
|
|
197
177
|
},
|
|
198
178
|
);
|
|
179
|
+
return workspaceResult(actual, result);
|
|
180
|
+
}
|
|
181
|
+
const WORKSPACE_OBSERVATION_MS = 500;
|
|
182
|
+
/** Discovery must not block the Pi/HTTP event loop on a stalled Git command.
|
|
183
|
+
* Same physical-checkout policy as resolveWorkspace, with a caller-owned wait. */
|
|
184
|
+
export function resolveWorkspaceAsync(
|
|
185
|
+
cwd: string,
|
|
186
|
+
signal?: AbortSignal,
|
|
187
|
+
): Promise<{ root: string; cwd: string }> {
|
|
188
|
+
const actual = realpathSync(cwd);
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
execFile(
|
|
191
|
+
"git",
|
|
192
|
+
gitArguments(["rev-parse", "--show-toplevel"]),
|
|
193
|
+
{
|
|
194
|
+
cwd: actual,
|
|
195
|
+
env: gitEnvironment(),
|
|
196
|
+
encoding: "utf8",
|
|
197
|
+
timeout: WORKSPACE_OBSERVATION_MS,
|
|
198
|
+
maxBuffer: 8192,
|
|
199
|
+
windowsHide: true,
|
|
200
|
+
signal,
|
|
201
|
+
killSignal: "SIGKILL",
|
|
202
|
+
},
|
|
203
|
+
(error, stdout, stderr) => {
|
|
204
|
+
try {
|
|
205
|
+
if (error?.killed || error?.signal || signal?.aborted)
|
|
206
|
+
throw new Error("Workspace lookup interrupted");
|
|
207
|
+
resolve(
|
|
208
|
+
workspaceResult(actual, {
|
|
209
|
+
stdout,
|
|
210
|
+
stderr,
|
|
211
|
+
status: error
|
|
212
|
+
? typeof error.code === "number"
|
|
213
|
+
? error.code
|
|
214
|
+
: null
|
|
215
|
+
: 0,
|
|
216
|
+
error:
|
|
217
|
+
error && typeof error.code !== "number" ? error : undefined,
|
|
218
|
+
}),
|
|
219
|
+
);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
reject(error);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function workspaceResult(
|
|
228
|
+
actual: string,
|
|
229
|
+
result: {
|
|
230
|
+
stdout?: string;
|
|
231
|
+
stderr: string;
|
|
232
|
+
status: number | null;
|
|
233
|
+
error?: Error | null;
|
|
234
|
+
},
|
|
235
|
+
): { root: string; cwd: string } {
|
|
199
236
|
// Remove only Git's record terminator, not valid whitespace in a path.
|
|
200
237
|
const topLevel = result.stdout?.replace(
|
|
201
238
|
process.platform === "win32" ? /\r?\n$/ : /\n$/,
|