@sema-agent/core 1.294.0 → 1.296.0
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/dist/agents/subagent.d.ts.map +1 -1
- package/dist/agents/subagent.js +24 -3
- package/dist/agents/subagent.js.map +1 -1
- package/dist/bin/sema-tb.d.ts +20 -0
- package/dist/bin/sema-tb.d.ts.map +1 -1
- package/dist/bin/sema-tb.js +71 -23
- package/dist/bin/sema-tb.js.map +1 -1
- package/dist/brain/anthropic.d.ts.map +1 -1
- package/dist/brain/anthropic.js +17 -3
- package/dist/brain/anthropic.js.map +1 -1
- package/dist/brain/openai.d.ts +1 -0
- package/dist/brain/openai.d.ts.map +1 -1
- package/dist/brain/openai.js +328 -298
- package/dist/brain/openai.js.map +1 -1
- package/dist/brain/stream-engine.d.ts +7 -0
- package/dist/brain/stream-engine.d.ts.map +1 -1
- package/dist/brain/stream-engine.js +44 -11
- package/dist/brain/stream-engine.js.map +1 -1
- package/dist/brain/timeout.d.ts +2 -1
- package/dist/brain/timeout.d.ts.map +1 -1
- package/dist/brain/timeout.js +14 -1
- package/dist/brain/timeout.js.map +1 -1
- package/dist/core/ask-question.d.ts.map +1 -1
- package/dist/core/ask-question.js.map +1 -1
- package/dist/core/hooks.d.ts +3 -3
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/hooks.js +11 -4
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/present-plan-tool.d.ts.map +1 -1
- package/dist/core/present-plan-tool.js +12 -13
- package/dist/core/present-plan-tool.js.map +1 -1
- package/dist/core/runner/assemble-result.d.ts +1 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -1
- package/dist/core/runner/assemble-result.js.map +1 -1
- package/dist/core/runner/call-cap.d.ts +4 -1
- package/dist/core/runner/call-cap.d.ts.map +1 -1
- package/dist/core/runner/call-cap.js +4 -1
- package/dist/core/runner/call-cap.js.map +1 -1
- package/dist/core/runner/cut-kill.d.ts +11 -0
- package/dist/core/runner/cut-kill.d.ts.map +1 -0
- package/dist/core/runner/cut-kill.js +38 -0
- package/dist/core/runner/cut-kill.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +5 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -1
- package/dist/core/runner/prepare-task.js +70 -23
- package/dist/core/runner/prepare-task.js.map +1 -1
- package/dist/core/runner/runtask.d.ts.map +1 -1
- package/dist/core/runner/runtask.js +22 -6
- package/dist/core/runner/runtask.js.map +1 -1
- package/dist/core/sensitive-path-policy.d.ts +2 -1
- package/dist/core/sensitive-path-policy.d.ts.map +1 -1
- package/dist/core/sensitive-path-policy.js +22 -0
- package/dist/core/sensitive-path-policy.js.map +1 -1
- package/dist/core/task-registry.d.ts +4 -0
- package/dist/core/task-registry.d.ts.map +1 -1
- package/dist/core/task-registry.js +83 -15
- package/dist/core/task-registry.js.map +1 -1
- package/dist/core/tool-policy.d.ts +5 -2
- package/dist/core/tool-policy.d.ts.map +1 -1
- package/dist/core/tool-policy.js +9 -0
- package/dist/core/tool-policy.js.map +1 -1
- package/dist/core/trace.d.ts +3 -0
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/trace.js.map +1 -1
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/engine/compaction/utils.d.ts.map +1 -1
- package/dist/engine/compaction/utils.js +3 -1
- package/dist/engine/compaction/utils.js.map +1 -1
- package/dist/engine/execution-env/kill-tree.d.ts +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -1
- package/dist/engine/execution-env/kill-tree.js +18 -2
- package/dist/engine/execution-env/kill-tree.js.map +1 -1
- package/dist/engine/execution-env/node-execution-env.d.ts +5 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -1
- package/dist/engine/execution-env/node-execution-env.js +19 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -1
- package/dist/engine/harness/agent-harness.d.ts +1 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -1
- package/dist/engine/harness/agent-harness.js +4 -0
- package/dist/engine/harness/agent-harness.js.map +1 -1
- package/dist/engine/harness/messages.d.ts +2 -0
- package/dist/engine/harness/messages.d.ts.map +1 -1
- package/dist/engine/harness/messages.js +52 -3
- package/dist/engine/harness/messages.js.map +1 -1
- package/dist/engine/harness/types.d.ts +7 -0
- package/dist/engine/harness/types.d.ts.map +1 -1
- package/dist/engine/harness/types.js.map +1 -1
- package/dist/engine/llm/types.d.ts +6 -0
- package/dist/engine/llm/types.d.ts.map +1 -1
- package/dist/engine/loop/agent-loop.js +3 -0
- package/dist/engine/loop/agent-loop.js.map +1 -1
- package/dist/engine/loop/types.d.ts +2 -0
- package/dist/engine/loop/types.d.ts.map +1 -1
- package/dist/engine/session/import-validate.d.ts.map +1 -1
- package/dist/engine/session/import-validate.js +64 -0
- package/dist/engine/session/import-validate.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/llm.d.ts +1 -1
- package/dist/internal/llm.d.ts.map +1 -1
- package/dist/scenarios/full-body.d.ts.map +1 -1
- package/dist/scenarios/full-body.js +3 -2
- package/dist/scenarios/full-body.js.map +1 -1
- package/dist/tools/fs/index.d.ts +8 -1
- package/dist/tools/fs/index.d.ts.map +1 -1
- package/dist/tools/fs/index.js +92 -30
- package/dist/tools/fs/index.js.map +1 -1
- package/dist/tools/fs/safety.d.ts +1 -1
- package/dist/tools/fs/safety.d.ts.map +1 -1
- package/dist/tools/fs/safety.js +3 -1
- package/dist/tools/fs/safety.js.map +1 -1
- package/dist/tools/fs/search.d.ts +7 -2
- package/dist/tools/fs/search.d.ts.map +1 -1
- package/dist/tools/fs/search.js +465 -57
- package/dist/tools/fs/search.js.map +1 -1
- package/dist/tools/monitor.d.ts.map +1 -1
- package/dist/tools/monitor.js +12 -1
- package/dist/tools/monitor.js.map +1 -1
- package/dist/tools/task-list.d.ts.map +1 -1
- package/dist/tools/task-list.js.map +1 -1
- package/dist/tools/worktree.d.ts.map +1 -1
- package/dist/tools/worktree.js +15 -2
- package/dist/tools/worktree.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ExecutionEnv } from "../internal/harness.js";
|
|
2
2
|
import type { ToolPolicy } from "./tool-policy.js";
|
|
3
|
+
export declare const RECOMMENDED_SENSITIVE_PATTERNS: readonly string[];
|
|
3
4
|
export declare function createSensitivePathPolicy(opts: {
|
|
4
5
|
env: ExecutionEnv;
|
|
5
|
-
patterns: string[];
|
|
6
|
+
patterns: readonly string[];
|
|
6
7
|
rootPath?: string;
|
|
7
8
|
tools?: string[];
|
|
8
9
|
}): ToolPolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitive-path-policy.d.ts","sourceRoot":"","sources":["../../src/core/sensitive-path-policy.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAqC,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"sensitive-path-policy.d.ts","sourceRoot":"","sources":["../../src/core/sensitive-path-policy.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAqC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAmBtF,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAqC3D,CAAC;AAuDF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE;IAC9C,GAAG,EAAE,YAAY,CAAC;IAElB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,UAAU,CA2Cb"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { canonicalizeTarget, fileArgPath } from "../tools/fs/safety.js";
|
|
2
2
|
import { canonicalToolName } from "./tool-name-aliases.js";
|
|
3
3
|
const DEFAULT_GUARDED_TOOLS = ["Write", "Edit", "MultiEdit"];
|
|
4
|
+
export const RECOMMENDED_SENSITIVE_PATTERNS = [
|
|
5
|
+
".env",
|
|
6
|
+
".env.*",
|
|
7
|
+
"*.pem",
|
|
8
|
+
"*.key",
|
|
9
|
+
"*.p12",
|
|
10
|
+
"*.pfx",
|
|
11
|
+
"id_rsa*",
|
|
12
|
+
"id_ed25519*",
|
|
13
|
+
"id_ecdsa*",
|
|
14
|
+
".ssh",
|
|
15
|
+
".git/hooks",
|
|
16
|
+
".git/config",
|
|
17
|
+
".aws",
|
|
18
|
+
".config/gcloud",
|
|
19
|
+
".azure",
|
|
20
|
+
".kube/config",
|
|
21
|
+
".npmrc",
|
|
22
|
+
".pypirc",
|
|
23
|
+
".bash_history",
|
|
24
|
+
".zsh_history",
|
|
25
|
+
];
|
|
4
26
|
function segmentGlobToRegExp(segment) {
|
|
5
27
|
const escaped = segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*");
|
|
6
28
|
return new RegExp(`^${escaped}$`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitive-path-policy.js","sourceRoot":"","sources":["../../src/core/sensitive-path-policy.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"sensitive-path-policy.js","sourceRoot":"","sources":["../../src/core/sensitive-path-policy.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,O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AC;YAC9E,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;gBAKd,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;oBAC5B,OAAO;wBACL,MAAM,EAAE,MAAM;wBACd,MAAM,EAAE,aAAa,IAAI,sHAAsH;wBAC/I,cAAc,EAAE,QAAQ;qBACzB,CAAC;gBACJ,CAAC;gBACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC7B,CAAC;YAED,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAChD,IAAI,GAAG,EAAE,CAAC;gBACR,OAAO;oBACL,MAAM,EAAE,MAAM;oBACd,MAAM,EAAE,aAAa,IAAI,2EAA2E,GAAG,GAAG;oBAC1G,cAAc,EAAE,QAAQ;iBACzB,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -55,6 +55,7 @@ export interface RegisterBackgroundBashInput extends TaskAccess {
|
|
|
55
55
|
now?: number;
|
|
56
56
|
sessionScoped?: true;
|
|
57
57
|
onTerminal?: (notification: TaskNotificationPayload) => void;
|
|
58
|
+
outputFile?: string;
|
|
58
59
|
}
|
|
59
60
|
export interface RegisterMonitorInput extends TaskAccess {
|
|
60
61
|
shellId: BackgroundShellId;
|
|
@@ -113,6 +114,7 @@ export declare class TaskRegistry {
|
|
|
113
114
|
private legacyToTaskId;
|
|
114
115
|
mintTaskId(type: SemaTaskType): string;
|
|
115
116
|
registerBackgroundBash(input: RegisterBackgroundBashInput): string;
|
|
117
|
+
isBackgroundOutputFile(canonicalPath: string, access: TaskAccess, env: unknown): boolean;
|
|
116
118
|
registerBackgroundAgent(input: RegisterBackgroundAgentInput): string;
|
|
117
119
|
markStopSource(id: string, source: StopSource): void;
|
|
118
120
|
markStopSourceByShellId(shellId: string, source: StopSource, env?: unknown): void;
|
|
@@ -135,6 +137,7 @@ export declare class TaskRegistry {
|
|
|
135
137
|
source?: StopSource;
|
|
136
138
|
skipSessionScoped?: boolean;
|
|
137
139
|
envDying?: boolean;
|
|
140
|
+
retainProcesses?: boolean;
|
|
138
141
|
}): Promise<number>;
|
|
139
142
|
reapSessionBackground(sessionId: string, scope?: string): number;
|
|
140
143
|
reapAllSessionBackground(): number;
|
|
@@ -147,6 +150,7 @@ export declare class TaskRegistry {
|
|
|
147
150
|
private startBashWatcher;
|
|
148
151
|
sessionResidentShellIds(sessionId: string, env: unknown): BackgroundShellId[];
|
|
149
152
|
timeoutResidentShellIds(env: unknown): BackgroundShellId[];
|
|
153
|
+
retainedShellIds(env: unknown): BackgroundShellId[];
|
|
150
154
|
registerMonitor(input: RegisterMonitorInput): string;
|
|
151
155
|
private startMonitorWatcher;
|
|
152
156
|
registerWorkflow(input: RegisterWorkflowInput): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-registry.d.ts","sourceRoot":"","sources":["../../src/core/task-registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAsB,KAAK,yBAAyB,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACnH,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGtF,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,8BAA8B,CAAC;AAChF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,UAAU,GAAG,kBAAkB,GAAG,SAAS,CAAC;AAQ3F,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;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E,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAsBF,OAAO,CAAC,GAAG,GAAE,MAAmB,GAAG,MAAM;IAMzC,EAAE,CAAC,GAAG,GAAE,MAAmB,EAAE,aAAa,GAAE,MAAuB,GAAG,MAAM;IAmB5E,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IA8CnD,OAAO,CAAC,eAAe;YAQT,kBAAkB;IAuIhC,OAAO,CAAC,kBAAkB;YAWZ,YAAY;YA0DZ,kBAAkB;YA0DlB,WAAW;YA8CX,WAAW;YAsDX,mBAAmB;YA8BnB,mBAAmB;YAwBnB,YAAY;CAmC3B;AAED,eAAO,MAAM,mBAAmB,cAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CA4DrE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CAsCnE"}
|
|
@@ -151,6 +151,18 @@ function statusFromBackground(status, exitCode) {
|
|
|
151
151
|
return exitCode === 0 ? "completed" : "failed";
|
|
152
152
|
return "failed";
|
|
153
153
|
}
|
|
154
|
+
function rollSpoolText(spool, s, cap) {
|
|
155
|
+
if (s.length <= cap)
|
|
156
|
+
return s;
|
|
157
|
+
const half = Math.floor(cap / 2);
|
|
158
|
+
spool.rolledChars += s.length - 2 * half;
|
|
159
|
+
return s.slice(0, half) + s.slice(s.length - half);
|
|
160
|
+
}
|
|
161
|
+
function bashMirrorGapNote(handle) {
|
|
162
|
+
return handle.outputFile !== undefined && handle.spool?.mirrorFailed === true
|
|
163
|
+
? " [!] The output file is INCOMPLETE (one or more writes to it failed) — trust the result text / TaskOutput over the file."
|
|
164
|
+
: "";
|
|
165
|
+
}
|
|
154
166
|
function monitorInTimeoutWindow(handle) {
|
|
155
167
|
return handle.status === "running" && handle.deadlineAt !== undefined && handle.timers.now() < handle.deadlineAt;
|
|
156
168
|
}
|
|
@@ -262,12 +274,26 @@ export class TaskRegistry {
|
|
|
262
274
|
env: input.env,
|
|
263
275
|
shellId: input.shellId,
|
|
264
276
|
...(input.onTerminal !== undefined ? { onTerminal: input.onTerminal } : {}),
|
|
277
|
+
...(input.outputFile !== undefined ? { outputFile: input.outputFile } : {}),
|
|
265
278
|
});
|
|
266
279
|
this.legacyToTaskId.set(String(input.shellId), id);
|
|
267
280
|
if (input.onTerminal)
|
|
268
281
|
this.startBashWatcher(id, input.onTerminal);
|
|
269
282
|
return id;
|
|
270
283
|
}
|
|
284
|
+
isBackgroundOutputFile(canonicalPath, access, env) {
|
|
285
|
+
for (const handle of this.handles.values()) {
|
|
286
|
+
if (handle.type !== "background_bash" || handle.outputFile === undefined)
|
|
287
|
+
continue;
|
|
288
|
+
if (handle.env !== env)
|
|
289
|
+
continue;
|
|
290
|
+
if (handle.outputFile !== canonicalPath)
|
|
291
|
+
continue;
|
|
292
|
+
if (canAccess(handle, access))
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
271
297
|
registerBackgroundAgent(input) {
|
|
272
298
|
assertOwnership(input, "registerBackgroundAgent");
|
|
273
299
|
const id = this.mintTaskId("background_agent");
|
|
@@ -410,6 +436,8 @@ export class TaskRegistry {
|
|
|
410
436
|
continue;
|
|
411
437
|
if (handle.type === "monitor" && monitorInTimeoutWindow(handle))
|
|
412
438
|
continue;
|
|
439
|
+
if ((handle.type === "background_bash" || handle.type === "monitor") && handle.retained === true)
|
|
440
|
+
continue;
|
|
413
441
|
const before = handle.stopSource;
|
|
414
442
|
this.markStopSource(handle.id, source);
|
|
415
443
|
if (before === undefined && handle.stopSource !== undefined)
|
|
@@ -426,9 +454,11 @@ export class TaskRegistry {
|
|
|
426
454
|
continue;
|
|
427
455
|
if (handle.status !== "running" || !canAccess(handle, access))
|
|
428
456
|
continue;
|
|
429
|
-
if (
|
|
457
|
+
if ((handle.retained === true || handle.env.backgroundCapabilities.retainBackgroundProcesses === true || opts?.retainProcesses === true) && !opts?.envDying) {
|
|
458
|
+
handle.retained = true;
|
|
430
459
|
continue;
|
|
431
|
-
|
|
460
|
+
}
|
|
461
|
+
if (opts?.skipSessionScoped && handle.sessionScoped && !(opts?.envDying === true && handle.type === "background_bash"))
|
|
432
462
|
continue;
|
|
433
463
|
if (handle.type === "monitor" && monitorInTimeoutWindow(handle) && !opts?.envDying)
|
|
434
464
|
continue;
|
|
@@ -445,14 +475,31 @@ export class TaskRegistry {
|
|
|
445
475
|
handle.status = "killed";
|
|
446
476
|
handle.stoppedBy = handle.stopSource ?? source;
|
|
447
477
|
handle.updatedAt = Date.now();
|
|
478
|
+
if (handle.outputFile !== undefined) {
|
|
479
|
+
try {
|
|
480
|
+
const drained = await handle.env.pollBackground(handle.shellId);
|
|
481
|
+
if (drained.ok && (drained.value.stdout.length > 0 || drained.value.stderr.length > 0)) {
|
|
482
|
+
const spool = (handle.spool ??= { stdout: "", stderr: "", rolledChars: 0 });
|
|
483
|
+
const cap = 2 * TASK_OUTPUT_MAX_CHARS;
|
|
484
|
+
spool.stdout = rollSpoolText(spool, spool.stdout + drained.value.stdout, cap);
|
|
485
|
+
spool.stderr = rollSpoolText(spool, spool.stderr + drained.value.stderr, cap);
|
|
486
|
+
const ap = await handle.env.appendFile(handle.outputFile, drained.value.stdout + drained.value.stderr);
|
|
487
|
+
if (!ap.ok)
|
|
488
|
+
spool.mirrorFailed = true;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
catch {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
448
494
|
const resultText = handle.spool !== undefined ? bashTerminalResult(handle.spool) : "";
|
|
449
495
|
this.notifyTerminalOnce(handle, () => handle.onTerminal?.({
|
|
450
496
|
task_id: handle.id,
|
|
451
497
|
task_type: "background_bash",
|
|
452
498
|
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
499
|
+
...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
|
|
453
500
|
status: "killed",
|
|
454
501
|
stoppedBy: handle.stoppedBy,
|
|
455
|
-
summary: `${(handle.description ?? "background command").slice(0, 200)} — killed before completion (${clause(handle.stoppedBy)})${killFailed ? ` — kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries` : ""}`,
|
|
502
|
+
summary: `${(handle.description ?? "background command").slice(0, 200)} — killed before completion (${clause(handle.stoppedBy)})${killFailed ? ` — kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries` : ""}${bashMirrorGapNote(handle)}`,
|
|
456
503
|
...(resultText.length > 0 ? { result: resultText } : {}),
|
|
457
504
|
}));
|
|
458
505
|
}
|
|
@@ -488,6 +535,8 @@ export class TaskRegistry {
|
|
|
488
535
|
const access = { owner: sessionId, ...(scope !== undefined ? { scope } : {}) };
|
|
489
536
|
let reaped = 0;
|
|
490
537
|
for (const handle of this.handles.values()) {
|
|
538
|
+
if ((handle.type === "background_bash" || handle.type === "monitor") && handle.retained === true && handle.status === "running")
|
|
539
|
+
continue;
|
|
491
540
|
if (handle.type === "monitor" && handle.status === "running" && handle.sessionScoped && canAccess(handle, access)) {
|
|
492
541
|
this.markStopSource(handle.id, "system");
|
|
493
542
|
if (handle.watcher !== undefined) {
|
|
@@ -562,6 +611,8 @@ export class TaskRegistry {
|
|
|
562
611
|
for (const handle of this.handles.values()) {
|
|
563
612
|
if (handle.type !== "background_bash" && handle.type !== "monitor" && handle.type !== "background_agent")
|
|
564
613
|
continue;
|
|
614
|
+
if (handle.type !== "background_agent" && handle.retained === true)
|
|
615
|
+
continue;
|
|
565
616
|
if (handle.status === "running" && handle.owner === owner)
|
|
566
617
|
n++;
|
|
567
618
|
}
|
|
@@ -634,13 +685,7 @@ export class TaskRegistry {
|
|
|
634
685
|
return;
|
|
635
686
|
handle.spool ??= { stdout: "", stderr: "", rolledChars: 0 };
|
|
636
687
|
const ROLL_CAP = 2 * TASK_OUTPUT_MAX_CHARS;
|
|
637
|
-
const roll = (s) =>
|
|
638
|
-
if (s.length <= ROLL_CAP)
|
|
639
|
-
return s;
|
|
640
|
-
const half = Math.floor(ROLL_CAP / 2);
|
|
641
|
-
handle.spool.rolledChars += s.length - 2 * half;
|
|
642
|
-
return s.slice(0, half) + s.slice(s.length - half);
|
|
643
|
-
};
|
|
688
|
+
const roll = (s) => rollSpoolText(handle.spool, s, ROLL_CAP);
|
|
644
689
|
let ticking = false;
|
|
645
690
|
const MAX_RETRYABLE_POLL_FAILURES = 3;
|
|
646
691
|
let pollFailures = 0;
|
|
@@ -673,8 +718,9 @@ export class TaskRegistry {
|
|
|
673
718
|
task_id: id,
|
|
674
719
|
task_type: "background_bash",
|
|
675
720
|
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
721
|
+
...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
|
|
676
722
|
status: "failed",
|
|
677
|
-
summary: `${(handle.description ?? "background command").slice(0, 200)} — lost its background process (${r.error.message}); no further output will arrive
|
|
723
|
+
summary: `${(handle.description ?? "background command").slice(0, 200)} — lost its background process (${r.error.message}); no further output will arrive.${bashMirrorGapNote(handle)}`,
|
|
678
724
|
...(lostResult.length > 0 ? { result: lostResult } : {}),
|
|
679
725
|
}));
|
|
680
726
|
return;
|
|
@@ -683,6 +729,11 @@ export class TaskRegistry {
|
|
|
683
729
|
const spool = handle.spool;
|
|
684
730
|
spool.stdout = roll(spool.stdout + r.value.stdout);
|
|
685
731
|
spool.stderr = roll(spool.stderr + r.value.stderr);
|
|
732
|
+
if (handle.outputFile !== undefined && (r.value.stdout.length > 0 || r.value.stderr.length > 0)) {
|
|
733
|
+
const ap = await handle.env.appendFile(handle.outputFile, r.value.stdout + r.value.stderr);
|
|
734
|
+
if (!ap.ok)
|
|
735
|
+
spool.mirrorFailed = true;
|
|
736
|
+
}
|
|
686
737
|
handle.status = statusFromBackground(r.value.status, r.value.exitCode);
|
|
687
738
|
if (handle.status === "killed" && handle.stoppedBy === undefined) {
|
|
688
739
|
handle.stoppedBy = handle.stopSource ?? (r.value.timedOut === true ? "timeout" : "system");
|
|
@@ -703,10 +754,11 @@ export class TaskRegistry {
|
|
|
703
754
|
task_id: id,
|
|
704
755
|
task_type: "background_bash",
|
|
705
756
|
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
757
|
+
...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
|
|
706
758
|
status: handle.status === "completed" ? "completed" : handle.status === "killed" ? "killed" : "failed",
|
|
707
759
|
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
708
760
|
...(r.value.status === "exited" && r.value.exitCode !== undefined ? { exitCode: r.value.exitCode } : {}),
|
|
709
|
-
summary: r.value.status === "exited"
|
|
761
|
+
summary: (r.value.status === "exited"
|
|
710
762
|
? r.value.exitCode === 0
|
|
711
763
|
? `Background command "${desc}" completed (exit code 0)`
|
|
712
764
|
: `Background command "${desc}" failed (exit code ${r.value.exitCode})`
|
|
@@ -714,7 +766,7 @@ export class TaskRegistry {
|
|
|
714
766
|
? r.value.timeoutSec !== undefined
|
|
715
767
|
? `${desc} — timed out after ${r.value.timeoutSec}s (its own background time budget); the process was killed`
|
|
716
768
|
: `${desc} — timed out (its own background time budget); the process was killed`
|
|
717
|
-
: `${desc} — ${r.value.status}
|
|
769
|
+
: `${desc} — ${r.value.status}`) + bashMirrorGapNote(handle),
|
|
718
770
|
...(resultText.length > 0 ? { result: resultText } : {}),
|
|
719
771
|
}));
|
|
720
772
|
}
|
|
@@ -732,8 +784,9 @@ export class TaskRegistry {
|
|
|
732
784
|
task_id: id,
|
|
733
785
|
task_type: "background_bash",
|
|
734
786
|
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
787
|
+
...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
|
|
735
788
|
status: "failed",
|
|
736
|
-
summary: `${(handle.description ?? "background command").slice(0, 200)} — lost its background process (poll failed: ${e instanceof Error ? e.message : String(e)}); no further output will arrive
|
|
789
|
+
summary: `${(handle.description ?? "background command").slice(0, 200)} — lost its background process (poll failed: ${e instanceof Error ? e.message : String(e)}); no further output will arrive.${bashMirrorGapNote(handle)}`,
|
|
737
790
|
...(crashedResult.length > 0 ? { result: crashedResult } : {}),
|
|
738
791
|
}));
|
|
739
792
|
}
|
|
@@ -762,6 +815,15 @@ export class TaskRegistry {
|
|
|
762
815
|
}
|
|
763
816
|
return out;
|
|
764
817
|
}
|
|
818
|
+
retainedShellIds(env) {
|
|
819
|
+
const out = [];
|
|
820
|
+
for (const handle of this.handles.values()) {
|
|
821
|
+
if ((handle.type === "background_bash" || handle.type === "monitor") && handle.status === "running" && handle.retained === true && handle.env === env) {
|
|
822
|
+
out.push(handle.shellId);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return out;
|
|
826
|
+
}
|
|
765
827
|
registerMonitor(input) {
|
|
766
828
|
assertOwnership(input, "registerMonitor");
|
|
767
829
|
const id = this.mintTaskId("monitor");
|
|
@@ -1172,6 +1234,8 @@ export class TaskRegistry {
|
|
|
1172
1234
|
if (handle.type === "monitor" && !handle.sessionScoped && canAccess(handle, access)) {
|
|
1173
1235
|
if (monitorInTimeoutWindow(handle))
|
|
1174
1236
|
continue;
|
|
1237
|
+
if (handle.retained === true && handle.status === "running")
|
|
1238
|
+
continue;
|
|
1175
1239
|
this.handles.delete(id);
|
|
1176
1240
|
if (handle.status === "running" && handle.owner !== undefined)
|
|
1177
1241
|
evictedRunningOwners.add(handle.owner);
|
|
@@ -1186,6 +1250,8 @@ export class TaskRegistry {
|
|
|
1186
1250
|
continue;
|
|
1187
1251
|
if (handle.sessionScoped)
|
|
1188
1252
|
continue;
|
|
1253
|
+
if (handle.retained === true && handle.status === "running")
|
|
1254
|
+
continue;
|
|
1189
1255
|
this.handles.delete(id);
|
|
1190
1256
|
if (handle.status === "running" && handle.owner !== undefined)
|
|
1191
1257
|
evictedRunningOwners.add(handle.owner);
|
|
@@ -1590,7 +1656,9 @@ export function createTaskOutputTool(opts) {
|
|
|
1590
1656
|
return defineTool({
|
|
1591
1657
|
name: "TaskOutput",
|
|
1592
1658
|
aliases: [...TASK_OUTPUT_ALIASES],
|
|
1593
|
-
description: "
|
|
1659
|
+
description: "[Deprecated] — for background Bash tasks, prefer Read on the output file path; for agent tasks, use the Agent tool result directly. " +
|
|
1660
|
+
"DEPRECATED: Background tasks return their output file path in the tool result, and you receive a <task-notification> with the same path when the task completes. " +
|
|
1661
|
+
"Retrieve output or status for a background task by task_id. Supports background Bash tasks and workflow " +
|
|
1594
1662
|
"tasks returned by RunWorkflow. Returns only the caller's own task scope; unknown and out-of-scope ids are " +
|
|
1595
1663
|
"reported the same way. Legacy bash_id and runId arguments are accepted for compatibility.",
|
|
1596
1664
|
parameters: Type.Object({
|