@abelxiaoxing/cadence 2.0.38 → 2.0.41
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/docs/conversation-mode.md +31 -0
- package/docs/reuse-and-distribution.md +92 -0
- package/package.json +4 -3
- package/src/activity.ts +147 -0
- package/src/change-tools.mjs +45 -17
- package/src/index.ts +2 -0
- package/src/native-build.ts +1 -1
- package/src/operator-cli.mjs +4 -1
- package/src/research-tools.mjs +45 -419
- package/src/sdk-worker.mjs +5 -2
- package/src/service/activity-files.ts +190 -0
- package/src/service/coordination.ts +6 -3
- package/src/service-cli.mjs +26 -8
- package/src/service-host.mjs +5314 -4828
- package/src/worker-toolkit.mjs +31 -4
- package/src/workspace.ts +58 -1
- package/web/dist/assets/cadence.js +18 -18
- package/web/dist/manifest.json +5 -5
- package/src/research-scan.mjs +0 -393
package/src/worker-toolkit.mjs
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { createChangeTools } from "./change-tools.mjs";
|
|
5
5
|
import { createCoordinatorTools } from "./coordinator-tools.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createResearchTools,
|
|
8
|
+
RESEARCH_INSTRUCTIONS,
|
|
9
|
+
} from "./research-tools.mjs";
|
|
7
10
|
import { sanitizeText } from "./worker-redaction.mjs";
|
|
8
11
|
import { captureBash } from "./worker-tools.mjs";
|
|
9
12
|
|
|
@@ -101,6 +104,9 @@ export function createWorkerToolkit(options) {
|
|
|
101
104
|
closing;
|
|
102
105
|
return {
|
|
103
106
|
capabilities,
|
|
107
|
+
instructions: capabilities.includes("observation")
|
|
108
|
+
? RESEARCH_INSTRUCTIONS
|
|
109
|
+
: "",
|
|
104
110
|
// Explicit allowlists are required by the installed public Pi SDK. Omitting
|
|
105
111
|
// one would enable its defaults, not mean "only our custom capabilities".
|
|
106
112
|
sessionOptions: {
|
|
@@ -117,10 +123,31 @@ export function createWorkerToolkit(options) {
|
|
|
117
123
|
...tool,
|
|
118
124
|
execute: (...args) => {
|
|
119
125
|
if (closed) return Promise.reject(new Error("Worker tools closed"));
|
|
120
|
-
const original = Promise.resolve().then(() => {
|
|
126
|
+
const original = Promise.resolve().then(async () => {
|
|
121
127
|
if (closed) throw new Error("Worker tools closed");
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
const signal = args[2];
|
|
129
|
+
if (signal?.aborted) throw new Error("Worker tool canceled");
|
|
130
|
+
const fileTool = [
|
|
131
|
+
"read",
|
|
132
|
+
"grep",
|
|
133
|
+
"find",
|
|
134
|
+
"ls",
|
|
135
|
+
"write",
|
|
136
|
+
"edit",
|
|
137
|
+
].includes(tool.name);
|
|
138
|
+
// Stock file tools may reject an abort observer before their real
|
|
139
|
+
// I/O finishes. Join this admitted call under the worker deadline,
|
|
140
|
+
// then suppress its result if canceled. Pi grep already waits for
|
|
141
|
+
// child close on abort, so preserve its stop signal like shell and
|
|
142
|
+
// changes; no mutation is replayed.
|
|
143
|
+
const forwarded = [...args];
|
|
144
|
+
if (fileTool && tool.name !== "grep") forwarded[2] = undefined;
|
|
145
|
+
const result = await tool.execute(...forwarded);
|
|
146
|
+
if (fileTool && signal?.aborted)
|
|
147
|
+
throw new Error(
|
|
148
|
+
"Worker tool canceled; its original operation settled and may have completed",
|
|
149
|
+
);
|
|
150
|
+
return result;
|
|
124
151
|
});
|
|
125
152
|
const tracked = original.finally(() => originals.delete(tracked));
|
|
126
153
|
originals.add(tracked);
|
package/src/workspace.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { gitArguments, gitEnvironment } from "./git-environment.mjs";
|
|
|
3
3
|
export { gitArguments, gitEnvironment } from "./git-environment.mjs";
|
|
4
4
|
|
|
5
5
|
/** Workspace identity and bounded filesystem operations, independent of task records. */
|
|
6
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import {
|
|
9
9
|
closeSync,
|
|
@@ -176,6 +176,63 @@ export function resolveWorkspace(cwd: string): { root: string; cwd: string } {
|
|
|
176
176
|
windowsHide: true,
|
|
177
177
|
},
|
|
178
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 } {
|
|
179
236
|
// Remove only Git's record terminator, not valid whitespace in a path.
|
|
180
237
|
const topLevel = result.stdout?.replace(
|
|
181
238
|
process.platform === "win32" ? /\r?\n$/ : /\n$/,
|