@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
|
@@ -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/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { registerActivity } from "./activity.ts";
|
|
3
4
|
import { registerAgentPanel } from "./agent-panel.ts";
|
|
4
5
|
import { registerCadenceAgentFeed } from "./agent-panel-cadence.ts";
|
|
5
6
|
import { registerCadenceMode } from "./cadence-mode.ts";
|
|
@@ -12,13 +13,14 @@ import { CONFIG_MISSING, startupCardLines } from "./startup-card.ts";
|
|
|
12
13
|
* actual host binding belongs to the readonly history shell’s session_start. */
|
|
13
14
|
export default function register(pi: ExtensionAPI): void {
|
|
14
15
|
if (process.env.CADENCE_SUBAGENT_CHILD === "1") return;
|
|
16
|
+
registerActivity(pi);
|
|
15
17
|
registerHistoryShell(pi);
|
|
16
18
|
registerCadenceMode(pi);
|
|
17
19
|
// Readonly: notices the browser continuing the session this terminal holds.
|
|
18
20
|
registerSessionSharing(pi);
|
|
19
21
|
// Observes `subagent:*` bus events only; renders nothing until one arrives.
|
|
20
22
|
registerAgentPanel(pi);
|
|
21
|
-
// Publishes
|
|
23
|
+
// Publishes only this conversation's live workflow children; never starts work.
|
|
22
24
|
registerCadenceAgentFeed(pi);
|
|
23
25
|
pi.on("session_start", (_event, ctx) => {
|
|
24
26
|
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc")) return;
|
package/src/native-build.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { type NativeViews, pretty, value } from "./native-history.ts";
|
|
4
4
|
import type { WorkbenchResult } from "./service/contracts/workbench.ts";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
readableDeliveryRun,
|
|
7
|
+
workflowDiagnostics,
|
|
8
|
+
} from "./service/contracts/workflow.ts";
|
|
6
9
|
import type { ServiceClient } from "./service-client.ts";
|
|
7
10
|
import { ContractError } from "./service-contract.ts";
|
|
8
11
|
|
|
@@ -11,9 +14,13 @@ export async function workflowDetails(
|
|
|
11
14
|
ui: NativeViews,
|
|
12
15
|
id: string,
|
|
13
16
|
): Promise<void> {
|
|
17
|
+
let before: number | undefined;
|
|
14
18
|
for (;;) {
|
|
15
19
|
const view = value(
|
|
16
|
-
await client.workbenchRead(
|
|
20
|
+
await client.workbenchRead(
|
|
21
|
+
{ kind: "workflow", id, ...(before === undefined ? {} : { before }) },
|
|
22
|
+
ui.signal,
|
|
23
|
+
),
|
|
17
24
|
);
|
|
18
25
|
ui.current();
|
|
19
26
|
if (
|
|
@@ -24,16 +31,26 @@ export async function workflowDetails(
|
|
|
24
31
|
throw new ContractError("invalid");
|
|
25
32
|
const run = view.response.run;
|
|
26
33
|
await ui.show(
|
|
27
|
-
`${run.goal}\n${run.id} • ${run.status} / ${run.phase}\n${run.notice}\n${workflowDiagnostics(run)}\nMerged commit: ${run.mergedCommit ?? "none"}\nAutomatic Agent review is not human review. Step summaries are previews; select a step for its retained result.\n${pretty(run.steps)}`,
|
|
34
|
+
`${run.goal}\n${run.id} • ${run.status} / ${run.phase}\n${run.notice}\n${workflowDiagnostics(run)}\n${readableDeliveryRun(run.delivery)}\nMerged commit: ${run.mergedCommit ?? "none"}\nAutomatic Agent review is not human review. Step summaries are previews; select a step for its retained result.\n${pretty(run.steps)}`,
|
|
28
35
|
);
|
|
29
36
|
const labels = run.steps.map(
|
|
30
37
|
(s, i) => `${i + 1}. ${s.kind} • ${s.id} • ${s.status}`,
|
|
31
38
|
);
|
|
32
39
|
const selected = await ui.select("Workflow details • readonly", [
|
|
33
40
|
...labels,
|
|
41
|
+
...((run.stepsBefore ?? 0) > 0 ? ["Earlier steps"] : []),
|
|
42
|
+
...(before !== undefined ? ["Latest steps"] : []),
|
|
34
43
|
"Refresh",
|
|
35
44
|
"Return",
|
|
36
45
|
]);
|
|
46
|
+
if (selected === "Earlier steps") {
|
|
47
|
+
before = run.stepsBefore;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (selected === "Latest steps") {
|
|
51
|
+
before = undefined;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
37
54
|
if (selected === "Refresh") continue;
|
|
38
55
|
if (!selected || !labels.includes(selected)) return;
|
|
39
56
|
const step = run.steps[labels.indexOf(selected)];
|
package/src/operator-cli.mjs
CHANGED
|
@@ -97,8 +97,26 @@ function diagnosticText(value, maximum = 4096, secrets = []) {
|
|
|
97
97
|
return bytes.toString("utf8").replace(/\ufffd$/, "") + marker;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
// src/git-environment.mjs
|
|
101
|
+
function gitEnvironment() {
|
|
102
|
+
const root = process.getuid?.() === 0;
|
|
103
|
+
return {
|
|
104
|
+
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"))),
|
|
105
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
106
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
107
|
+
LC_ALL: "C"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function gitArguments(args) {
|
|
111
|
+
return [
|
|
112
|
+
"--no-replace-objects",
|
|
113
|
+
...process.platform !== "win32" && process.getuid?.() === 0 ? ["-c", "safe.directory=", "-c", "core.fsmonitor=false"] : [],
|
|
114
|
+
...args
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
100
118
|
// src/workspace.ts
|
|
101
|
-
import { spawnSync } from "node:child_process";
|
|
119
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
102
120
|
import { createHash } from "node:crypto";
|
|
103
121
|
import {
|
|
104
122
|
closeSync,
|
|
@@ -217,17 +235,6 @@ function readBounded(path, max, packaged = false) {
|
|
|
217
235
|
closeSync(fd);
|
|
218
236
|
}
|
|
219
237
|
}
|
|
220
|
-
function gitEnvironment() {
|
|
221
|
-
const root = process.getuid?.() === 0;
|
|
222
|
-
return {
|
|
223
|
-
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"))),
|
|
224
|
-
GIT_OPTIONAL_LOCKS: "0",
|
|
225
|
-
LC_ALL: "C"
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
function gitArguments(args) {
|
|
229
|
-
return process.platform !== "win32" && process.getuid?.() === 0 ? ["-c", "safe.directory=", "-c", "core.fsmonitor=false", ...args] : args;
|
|
230
|
-
}
|
|
231
238
|
function resolveWorkspace(cwd) {
|
|
232
239
|
const actual = realpathSync(cwd);
|
|
233
240
|
const result = spawnSync("git", gitArguments(["rev-parse", "--show-toplevel"]), {
|
|
@@ -238,6 +245,9 @@ function resolveWorkspace(cwd) {
|
|
|
238
245
|
maxBuffer: 8192,
|
|
239
246
|
windowsHide: true
|
|
240
247
|
});
|
|
248
|
+
return workspaceResult(actual, result);
|
|
249
|
+
}
|
|
250
|
+
function workspaceResult(actual, result) {
|
|
241
251
|
const topLevel = result.stdout?.replace(process.platform === "win32" ? /\r?\n$/ : /\n$/, "");
|
|
242
252
|
if (result.status === 0 && topLevel)
|
|
243
253
|
return { root: realpathSync(topLevel), cwd: actual };
|
package/src/research-scan.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* not a page number or a replay of an earlier scan. No shell or spill files. */
|
|
3
3
|
import { constants } from "node:fs";
|
|
4
4
|
import { lstat, open, opendir, realpath } from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
5
6
|
import { basename, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
6
7
|
import { withinRoot } from "./worker-workspace.mjs";
|
|
7
8
|
|
|
@@ -45,6 +46,7 @@ export class ResearchScan {
|
|
|
45
46
|
this.page = counters();
|
|
46
47
|
this.fileBytes = new Map();
|
|
47
48
|
this.sources = new Set();
|
|
49
|
+
this.bindings = new Map();
|
|
48
50
|
this.stopping = false;
|
|
49
51
|
this.iterator = this.records();
|
|
50
52
|
}
|
|
@@ -88,7 +90,19 @@ export class ResearchScan {
|
|
|
88
90
|
throw new SourceChanged();
|
|
89
91
|
this.check();
|
|
90
92
|
}
|
|
93
|
+
async validateBinding(path, selected) {
|
|
94
|
+
this.check();
|
|
95
|
+
try {
|
|
96
|
+
if ((await realpath(path)) !== selected) throw new SourceChanged();
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (unavailable(e)) throw new SourceChanged();
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
this.check();
|
|
102
|
+
}
|
|
91
103
|
async validate() {
|
|
104
|
+
for (const [path, selected] of this.bindings)
|
|
105
|
+
await this.validateBinding(path, selected);
|
|
92
106
|
for (const source of this.sources) await this.validateSource(source);
|
|
93
107
|
}
|
|
94
108
|
async closeHandle(handle) {
|
|
@@ -100,23 +114,45 @@ export class ResearchScan {
|
|
|
100
114
|
throw new Error("Investigation handle closure failed");
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
|
-
async
|
|
117
|
+
async canonical(path) {
|
|
104
118
|
this.check();
|
|
105
|
-
const selected = await realpath(
|
|
119
|
+
const selected = await realpath(path);
|
|
106
120
|
this.check();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
return selected;
|
|
122
|
+
}
|
|
123
|
+
bind(path, selected) {
|
|
124
|
+
if (path === selected) return () => {};
|
|
125
|
+
const previous = this.bindings.get(path);
|
|
126
|
+
if (previous !== undefined && previous !== selected)
|
|
127
|
+
throw new SourceChanged();
|
|
128
|
+
this.bindings.set(path, selected);
|
|
129
|
+
return () => {
|
|
130
|
+
if (previous === undefined) this.bindings.delete(path);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async target(path) {
|
|
134
|
+
const expanded =
|
|
135
|
+
path === "~"
|
|
136
|
+
? homedir()
|
|
137
|
+
: path?.startsWith("~/")
|
|
138
|
+
? join(homedir(), path.slice(2))
|
|
139
|
+
: path;
|
|
140
|
+
const requested = resolve(this.roots[0], expanded ?? ".");
|
|
141
|
+
const selected = await this.canonical(requested);
|
|
142
|
+
this.bind(requested, selected);
|
|
143
|
+
// Roots choose the default query scope, not permission to read host files.
|
|
144
|
+
const root = this.roots.findIndex((p) => withinRoot(p, requested));
|
|
145
|
+
return { path: selected, display: requested, root: root < 0 ? null : root };
|
|
113
146
|
}
|
|
114
147
|
location(target) {
|
|
148
|
+
const path = target.display ?? target.path;
|
|
115
149
|
return {
|
|
116
150
|
root: target.root,
|
|
117
151
|
path:
|
|
118
|
-
|
|
119
|
-
|
|
152
|
+
target.root === null
|
|
153
|
+
? path
|
|
154
|
+
: relative(this.roots[target.root], path).split(sep).join("/") ||
|
|
155
|
+
basename(path),
|
|
120
156
|
};
|
|
121
157
|
}
|
|
122
158
|
async *records() {
|
|
@@ -174,16 +210,16 @@ export class ResearchScan {
|
|
|
174
210
|
}
|
|
175
211
|
const glob = this.query.glob;
|
|
176
212
|
const name =
|
|
177
|
-
relative(target.
|
|
178
|
-
basename(file.
|
|
213
|
+
relative(target.display, file.display).split(sep).join("/") ||
|
|
214
|
+
basename(file.display);
|
|
179
215
|
if (
|
|
180
216
|
glob &&
|
|
181
|
-
!matchesGlob(glob.includes("/") ? name : basename(file.
|
|
217
|
+
!matchesGlob(glob.includes("/") ? name : basename(file.display), glob)
|
|
182
218
|
) {
|
|
183
219
|
yield null;
|
|
184
220
|
continue;
|
|
185
221
|
}
|
|
186
|
-
if (this.query.kind
|
|
222
|
+
if (["find", "glob"].includes(this.query.kind))
|
|
187
223
|
yield { item: { ...this.location(file), kind: "file" } };
|
|
188
224
|
else {
|
|
189
225
|
try {
|
|
@@ -196,7 +232,12 @@ export class ResearchScan {
|
|
|
196
232
|
}
|
|
197
233
|
}
|
|
198
234
|
}
|
|
199
|
-
async *walk(target, remaining) {
|
|
235
|
+
async *walk(target, remaining, ancestors = new Set()) {
|
|
236
|
+
if (ancestors.has(target.path)) {
|
|
237
|
+
this.omit("symlink cycle omitted");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const branch = new Set(ancestors).add(target.path);
|
|
200
241
|
const source = await this.source(target.path);
|
|
201
242
|
this.check();
|
|
202
243
|
const dir = await opendir(target.path);
|
|
@@ -213,7 +254,11 @@ export class ResearchScan {
|
|
|
213
254
|
this.check();
|
|
214
255
|
if (!entry) return;
|
|
215
256
|
this.count("inspectedEntries");
|
|
216
|
-
const file = {
|
|
257
|
+
const file = {
|
|
258
|
+
path: join(target.path, entry.name),
|
|
259
|
+
display: join(target.display, entry.name),
|
|
260
|
+
root: target.root,
|
|
261
|
+
};
|
|
217
262
|
if (this.query.kind === "ls") {
|
|
218
263
|
yield {
|
|
219
264
|
...file,
|
|
@@ -227,25 +272,54 @@ export class ResearchScan {
|
|
|
227
272
|
};
|
|
228
273
|
continue;
|
|
229
274
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
else {
|
|
236
|
-
// Yield before descent too, so unmatched directories consume a quantum.
|
|
237
|
-
yield null;
|
|
275
|
+
let release = () => {};
|
|
276
|
+
const binding = file.path;
|
|
277
|
+
try {
|
|
278
|
+
let info = entry;
|
|
279
|
+
if (entry.isSymbolicLink()) {
|
|
238
280
|
try {
|
|
239
|
-
|
|
281
|
+
file.path = await this.canonical(file.path);
|
|
282
|
+
release = this.bind(binding, file.path);
|
|
283
|
+
this.check();
|
|
284
|
+
info = await lstat(file.path);
|
|
285
|
+
this.check();
|
|
240
286
|
} catch (e) {
|
|
241
287
|
if (!unavailable(e)) throw e;
|
|
242
|
-
this.omit("unreadable
|
|
288
|
+
this.omit("unreadable symlink omitted");
|
|
289
|
+
yield null;
|
|
290
|
+
continue;
|
|
243
291
|
}
|
|
244
292
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
293
|
+
if (info.isDirectory()) {
|
|
294
|
+
if (entry.name === ".git") this.omit(".git omitted");
|
|
295
|
+
else if (!remaining) this.omit("depth limit");
|
|
296
|
+
else {
|
|
297
|
+
yield null;
|
|
298
|
+
try {
|
|
299
|
+
yield* this.walk(file, remaining - 1, branch);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
if (!unavailable(e)) throw e;
|
|
302
|
+
this.omit("unreadable directory omitted");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} else if (info.isFile()) {
|
|
306
|
+
yield file;
|
|
307
|
+
continue;
|
|
308
|
+
} else this.omit("special file omitted");
|
|
309
|
+
} finally {
|
|
310
|
+
try {
|
|
311
|
+
if (
|
|
312
|
+
entry.isSymbolicLink() &&
|
|
313
|
+
this.bindings.has(binding) &&
|
|
314
|
+
!this.stopping &&
|
|
315
|
+
!this.signal?.aborted
|
|
316
|
+
) {
|
|
317
|
+
await this.validateBinding(binding, file.path);
|
|
318
|
+
}
|
|
319
|
+
} finally {
|
|
320
|
+
release();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
249
323
|
yield null;
|
|
250
324
|
}
|
|
251
325
|
} finally {
|
|
@@ -316,7 +390,13 @@ export class ResearchScan {
|
|
|
316
390
|
if (!ranges) {
|
|
317
391
|
const haystack = this.query.ignoreCase ? text.toLowerCase() : text;
|
|
318
392
|
const matched = this.query.patterns.flatMap((pattern, index) =>
|
|
319
|
-
|
|
393
|
+
(
|
|
394
|
+
this.query.literal
|
|
395
|
+
? haystack.includes(pattern)
|
|
396
|
+
: this.query.regex[index].test(text)
|
|
397
|
+
)
|
|
398
|
+
? [index]
|
|
399
|
+
: [],
|
|
320
400
|
);
|
|
321
401
|
if (!matched.length) return null;
|
|
322
402
|
item.matchedPatterns = matched;
|
package/src/research-tools.mjs
CHANGED
|
@@ -34,12 +34,55 @@ const array = (value, maximum) => {
|
|
|
34
34
|
throw new Error("Invalid investigation batch");
|
|
35
35
|
return value;
|
|
36
36
|
};
|
|
37
|
+
// Bound expansion work, not ordinary glob syntax. Native matchesGlob supports
|
|
38
|
+
// brace alternatives/extglobs; huge ranges/products must not allocate unboundedly.
|
|
39
|
+
const GLOB_EXPANSIONS = 4096;
|
|
37
40
|
const glob = (value) => {
|
|
38
41
|
string(value, 256);
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const stack = [{ alternatives: 0, product: 1, start: 0 }];
|
|
43
|
+
for (let i = 0; i < value.length; i++) {
|
|
44
|
+
if (value[i] === "\\") {
|
|
45
|
+
i++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const current = stack.at(-1);
|
|
49
|
+
if (value[i] === "{")
|
|
50
|
+
stack.push({ alternatives: 0, product: 1, start: i + 1 });
|
|
51
|
+
else if (value[i] === "," && stack.length > 1) {
|
|
52
|
+
current.alternatives += current.product;
|
|
53
|
+
current.product = 1;
|
|
54
|
+
} else if (value[i] === "}" && stack.length > 1) {
|
|
55
|
+
stack.pop();
|
|
56
|
+
let size = current.alternatives + current.product;
|
|
57
|
+
const range =
|
|
58
|
+
/^(-?\d+|[a-zA-Z])\.\.(-?\d+|[a-zA-Z])(?:\.\.(-?\d+))?$/.exec(
|
|
59
|
+
value.slice(current.start, i),
|
|
60
|
+
);
|
|
61
|
+
if (range) {
|
|
62
|
+
const number = (part) =>
|
|
63
|
+
/^-?\d+$/.test(part) ? Number(part) : part.charCodeAt(0);
|
|
64
|
+
const step = Math.abs(Number(range[3] ?? 1)) || 1;
|
|
65
|
+
size =
|
|
66
|
+
Math.floor(Math.abs(number(range[2]) - number(range[1])) / step) + 1;
|
|
67
|
+
}
|
|
68
|
+
stack.at(-1).product *= size;
|
|
69
|
+
}
|
|
70
|
+
if (
|
|
71
|
+
stack.some(
|
|
72
|
+
(entry) =>
|
|
73
|
+
!Number.isFinite(entry.product) ||
|
|
74
|
+
entry.product + entry.alternatives > GLOB_EXPANSIONS,
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
throw new Error(
|
|
78
|
+
"Glob expansion is too large; use * or a smaller set of alternatives",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
41
81
|
return value;
|
|
42
82
|
};
|
|
83
|
+
export const RESEARCH_INSTRUCTIONS =
|
|
84
|
+
"Readonly investigation: use read, grep, find/glob and ls directly, not shell command strings. Explicit absolute paths (including installed packages outside the checkout) and symlinks are readable; roots only choose the default search location. grep accepts regular expressions by default; use literal:true for exact text. find/glob accept brace alternatives and extglobs. There is no bash, write or edit tool in this readonly role: use ls for listing, read for file contents, grep for matching and find/glob for file discovery. Keep credentials and private session content out of reports. A returned cursor continues the same query; an empty page with a cursor is not absence.";
|
|
85
|
+
|
|
43
86
|
function query(kind, args) {
|
|
44
87
|
const common = ["pageSize", "path"];
|
|
45
88
|
object(args, [
|
|
@@ -48,7 +91,7 @@ function query(kind, args) {
|
|
|
48
91
|
? ["files", "offset", "limit"]
|
|
49
92
|
: kind === "grep"
|
|
50
93
|
? ["pattern", "patterns", "glob", "depth", "ignoreCase", "literal"]
|
|
51
|
-
:
|
|
94
|
+
: ["find", "glob"].includes(kind)
|
|
52
95
|
? ["pattern", "depth"]
|
|
53
96
|
: []),
|
|
54
97
|
]);
|
|
@@ -93,11 +136,12 @@ function query(kind, args) {
|
|
|
93
136
|
});
|
|
94
137
|
} else {
|
|
95
138
|
result.path = args.path === undefined ? undefined : string(args.path);
|
|
96
|
-
result.depth = integer(args.depth ?? L.depth,
|
|
97
|
-
if (
|
|
139
|
+
result.depth = integer(args.depth ?? L.depth, Number.MAX_SAFE_INTEGER, 0);
|
|
140
|
+
if (["find", "glob"].includes(kind)) result.glob = glob(args.pattern);
|
|
98
141
|
if (kind === "grep") {
|
|
99
|
-
if (args.literal !== undefined && args.literal !==
|
|
100
|
-
throw new Error("
|
|
142
|
+
if (args.literal !== undefined && typeof args.literal !== "boolean")
|
|
143
|
+
throw new Error("Invalid literal selection");
|
|
144
|
+
result.literal = args.literal === true;
|
|
101
145
|
if (args.ignoreCase !== undefined && typeof args.ignoreCase !== "boolean")
|
|
102
146
|
throw new Error("Invalid case selection");
|
|
103
147
|
if ((args.pattern === undefined) === (args.patterns === undefined))
|
|
@@ -106,9 +150,22 @@ function query(kind, args) {
|
|
|
106
150
|
result.patterns = array(args.patterns ?? [args.pattern], L.patterns).map(
|
|
107
151
|
(pattern) => {
|
|
108
152
|
const text = string(pattern, 256);
|
|
109
|
-
return result.
|
|
153
|
+
return result.literal && result.ignoreCase
|
|
154
|
+
? text.toLowerCase()
|
|
155
|
+
: text;
|
|
110
156
|
},
|
|
111
157
|
);
|
|
158
|
+
if (!result.literal) {
|
|
159
|
+
try {
|
|
160
|
+
result.regex = result.patterns.map(
|
|
161
|
+
(pattern) => new RegExp(pattern, result.ignoreCase ? "iu" : "u"),
|
|
162
|
+
);
|
|
163
|
+
} catch {
|
|
164
|
+
throw new Error(
|
|
165
|
+
"Invalid regular expression; use literal:true for exact text",
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
112
169
|
if (args.glob !== undefined) result.glob = glob(args.glob);
|
|
113
170
|
}
|
|
114
171
|
}
|
|
@@ -120,13 +177,15 @@ const path = Type.Optional(
|
|
|
120
177
|
minLength: 1,
|
|
121
178
|
maxLength: 4096,
|
|
122
179
|
description:
|
|
123
|
-
"
|
|
180
|
+
"An explicit host path, including outside the checkout. Relative paths use the first search root; ~ uses this account's home.",
|
|
124
181
|
}),
|
|
125
182
|
);
|
|
126
183
|
const pageSize = Type.Optional(
|
|
127
184
|
Type.Integer({ minimum: 1, maximum: L.results }),
|
|
128
185
|
);
|
|
129
|
-
const depth = Type.Optional(
|
|
186
|
+
const depth = Type.Optional(
|
|
187
|
+
Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
|
|
188
|
+
);
|
|
130
189
|
const pattern = Type.String({ minLength: 1, maxLength: 256 });
|
|
131
190
|
// Provider function schemas require an object root, not a union of objects.
|
|
132
191
|
// Initial-query versus continuation exclusivity is checked before admission;
|
|
@@ -175,7 +234,7 @@ const definitions = [
|
|
|
175
234
|
{
|
|
176
235
|
name: "grep",
|
|
177
236
|
description:
|
|
178
|
-
"Search
|
|
237
|
+
"Search regular expressions in one file or a tree; literal:true selects exact text. Supply pattern or patterns (OR; matchedPatterns are zero-based input indexes). Each matching logical path is scanned without replaying its consumed prefix. Optional glob, ignoreCase and depth. Explicit host paths, dependencies and symlinks are supported; .git is skipped during tree traversal, and .gitignore is not interpreted. Empty pages with a cursor are progress, NOT absence. Resume with {cursor}, or release with {cursor,close:true}.",
|
|
179
238
|
parameters: parameters({
|
|
180
239
|
path,
|
|
181
240
|
pattern: Type.Optional(pattern),
|
|
@@ -183,18 +242,18 @@ const definitions = [
|
|
|
183
242
|
Type.Array(pattern, { minItems: 1, maxItems: L.patterns }),
|
|
184
243
|
),
|
|
185
244
|
glob: Type.Optional(pattern),
|
|
186
|
-
literal: Type.Optional(Type.
|
|
245
|
+
literal: Type.Optional(Type.Boolean()),
|
|
187
246
|
ignoreCase: Type.Optional(Type.Boolean()),
|
|
188
247
|
depth,
|
|
189
248
|
pageSize,
|
|
190
249
|
}),
|
|
191
250
|
},
|
|
192
|
-
{
|
|
193
|
-
name
|
|
251
|
+
...["find", "glob"].map((name) => ({
|
|
252
|
+
name,
|
|
194
253
|
description:
|
|
195
|
-
"Find file paths
|
|
254
|
+
"Find file paths by glob (*, **, ?, brackets, brace alternatives and extglobs). Explicit host paths, dependencies and symlinks are supported. Traversal defaults to depth 8; set depth explicitly for deeper trees. Symlink cycles and .git traversal are omitted visibly; .gitignore is not interpreted. Resume with this tool's {cursor}; {cursor,close:true} releases it. Coverage/omissions are explicit.",
|
|
196
255
|
parameters: parameters({ path, pattern, depth, pageSize }),
|
|
197
|
-
},
|
|
256
|
+
})),
|
|
198
257
|
{
|
|
199
258
|
name: "ls",
|
|
200
259
|
description:
|
package/src/sdk-worker.mjs
CHANGED
|
@@ -429,7 +429,10 @@ try {
|
|
|
429
429
|
getPrompts: () => ({ prompts: [], diagnostics: [] }),
|
|
430
430
|
getThemes: () => ({ themes: [], diagnostics: [] }),
|
|
431
431
|
getAgentsFiles: () => ({ agentsFiles: [] }),
|
|
432
|
-
getSystemPrompt: () =>
|
|
432
|
+
getSystemPrompt: () =>
|
|
433
|
+
toolkit?.instructions
|
|
434
|
+
? `${instructions}\n\n${toolkit.instructions}`
|
|
435
|
+
: instructions,
|
|
433
436
|
getSystemPromptSource: () => undefined,
|
|
434
437
|
getAppendSystemPrompt: () => [],
|
|
435
438
|
getAppendSystemPromptSources: () => [],
|
|
@@ -467,7 +470,9 @@ try {
|
|
|
467
470
|
toolkit = createWorkerToolkit({
|
|
468
471
|
workspace,
|
|
469
472
|
purpose: publicRequest.purpose,
|
|
473
|
+
changes: publicRequest.changes,
|
|
470
474
|
coordinator,
|
|
475
|
+
reporting: !conversation && publicRequest.purpose === "edit",
|
|
471
476
|
secrets,
|
|
472
477
|
fail: captureFailure,
|
|
473
478
|
createLocalBashOperations,
|