operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/agent/agent.d.ts +8 -7
- package/dist/agent/compose-hooks.d.ts +10 -1
- package/dist/agent/compose-hooks.js +61 -6
- package/dist/agent/concurrency.js +1 -1
- package/dist/agent/context-report.d.ts +2 -2
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/run-support.d.ts +1 -1
- package/dist/agent/run-support.js +6 -5
- package/dist/agent/runner.d.ts +25 -22
- package/dist/agent/runner.js +217 -121
- package/dist/agent/session.d.ts +262 -156
- package/dist/agent/session.js +590 -418
- package/dist/agent/subagent-tools.js +3 -3
- package/dist/agent/subagent.js +28 -13
- package/dist/agent/toolset.d.ts +1 -0
- package/dist/agent/toolset.js +13 -7
- package/dist/agent/workflow/journal.d.ts +2 -2
- package/dist/agent/workflow/journal.js +2 -2
- package/dist/agent/workflow/manager.d.ts +1 -1
- package/dist/agent/workflow/manager.js +1 -1
- package/dist/agent/workflow/prompt.js +2 -2
- package/dist/agent/workflow/sandbox.d.ts +1 -1
- package/dist/agent/workflow/sandbox.js +1 -1
- package/dist/agent/workflow/tool.js +30 -43
- package/dist/agent/worktree.d.ts +8 -8
- package/dist/agent/worktree.js +15 -15
- package/dist/capabilities/assembler.d.ts +29 -5
- package/dist/capabilities/assembler.js +85 -9
- package/dist/capabilities/background/code-task.d.ts +43 -0
- package/dist/capabilities/background/code-task.js +75 -0
- package/dist/capabilities/background/command-task.d.ts +9 -2
- package/dist/capabilities/background/command-task.js +22 -6
- package/dist/capabilities/background/index.d.ts +6 -1
- package/dist/capabilities/background/index.js +26 -20
- package/dist/capabilities/background/manager.d.ts +57 -1
- package/dist/capabilities/background/manager.js +210 -45
- package/dist/capabilities/background/persist-disk.d.ts +1 -1
- package/dist/capabilities/background/persist-disk.js +1 -1
- package/dist/capabilities/background/persist.js +4 -2
- package/dist/capabilities/background/projections.d.ts +16 -0
- package/dist/capabilities/background/projections.js +86 -0
- package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
- package/dist/capabilities/background/stall-watchdog.js +85 -0
- package/dist/capabilities/background/task.d.ts +8 -7
- package/dist/capabilities/background/tools.js +33 -7
- package/dist/capabilities/capability-data.d.ts +52 -0
- package/dist/capabilities/capability-data.js +88 -0
- package/dist/capabilities/capability-state.d.ts +2 -4
- package/dist/capabilities/capability-state.js +5 -23
- package/dist/capabilities/capability.d.ts +203 -38
- package/dist/capabilities/compaction/index.js +10 -4
- package/dist/capabilities/compaction/service.d.ts +20 -5
- package/dist/capabilities/compaction/service.js +27 -11
- package/dist/capabilities/goal/goal-store.d.ts +76 -12
- package/dist/capabilities/goal/goal-store.js +137 -53
- package/dist/capabilities/goal/index.d.ts +1 -1
- package/dist/capabilities/goal/index.js +30 -7
- package/dist/capabilities/index.d.ts +9 -6
- package/dist/capabilities/index.js +4 -3
- package/dist/capabilities/plan/index.js +22 -5
- package/dist/capabilities/plan/plan-mode.d.ts +30 -9
- package/dist/capabilities/plan/plan-mode.js +57 -32
- package/dist/capabilities/plan/tools.js +1 -1
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +13 -1
- package/dist/capabilities/skills/index.js +30 -21
- package/dist/capabilities/skills/parser.d.ts +2 -2
- package/dist/capabilities/skills/parser.js +3 -3
- package/dist/capabilities/skills/registry.d.ts +5 -6
- package/dist/capabilities/skills/registry.js +6 -9
- package/dist/capabilities/skills/scanner.d.ts +3 -3
- package/dist/capabilities/skills/scanner.js +14 -14
- package/dist/capabilities/skills/service.d.ts +2 -1
- package/dist/capabilities/skills/service.js +3 -3
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +2 -1
- package/dist/capabilities/task/persist-disk.d.ts +1 -1
- package/dist/capabilities/task/persist-disk.js +1 -1
- package/dist/capabilities/task/persist.js +1 -1
- package/dist/capabilities/todo/index.js +11 -6
- package/dist/capabilities/todo/injector.js +2 -1
- package/dist/capabilities/todo/todo-store.d.ts +28 -7
- package/dist/capabilities/todo/todo-store.js +44 -11
- package/dist/capabilities/todo/tools.js +8 -3
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.js +7 -7
- package/dist/capabilities/user-hooks/index.js +2 -1
- package/dist/capabilities/workflow/index.d.ts +5 -3
- package/dist/capabilities/workflow/index.js +3 -2
- package/dist/commands/index.js +34 -32
- package/dist/config/index.d.ts +1 -1
- package/dist/config/provider-manager.js +0 -28
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/events/events.d.ts +43 -11
- package/dist/events/events.js +1 -0
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/projection.d.ts +49 -1
- package/dist/events/projection.js +144 -19
- package/dist/events/publisher.js +2 -21
- package/dist/home.d.ts +1 -1
- package/dist/home.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/llm/define-model.d.ts +4 -0
- package/dist/llm/define-model.js +63 -25
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/model.d.ts +2 -0
- package/dist/llm/provider.d.ts +17 -0
- package/dist/llm/provider.js +14 -0
- package/dist/llm/retry.js +1 -1
- package/dist/loop/context.d.ts +21 -1
- package/dist/loop/context.js +47 -9
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/index.d.ts +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/interruption.d.ts +9 -4
- package/dist/loop/interruption.js +11 -25
- package/dist/loop/run-turn.d.ts +16 -3
- package/dist/loop/run-turn.js +13 -4
- package/dist/loop/steer.d.ts +78 -12
- package/dist/loop/steer.js +101 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +135 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +29 -7
- package/dist/loop/types.d.ts +6 -0
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/capability.d.ts +13 -0
- package/dist/mcp/capability.js +36 -17
- package/dist/mcp/config-loader.d.ts +5 -5
- package/dist/mcp/config-loader.js +17 -17
- package/dist/mcp/credentials.d.ts +35 -0
- package/dist/mcp/credentials.js +2 -0
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +4 -3
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +108 -6
- package/dist/mcp/manager.js +262 -18
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +82 -16
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +31 -1
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/manager.d.ts +5 -3
- package/dist/permission/manager.js +7 -3
- package/dist/permission/policies.d.ts +2 -2
- package/dist/permission/policies.js +4 -4
- package/dist/plugins/fields.d.ts +14 -0
- package/dist/plugins/fields.js +30 -0
- package/dist/plugins/hooks.d.ts +2 -2
- package/dist/plugins/hooks.js +12 -12
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/manager.d.ts +8 -3
- package/dist/plugins/manager.js +18 -7
- package/dist/plugins/manifest.d.ts +2 -2
- package/dist/plugins/manifest.js +101 -91
- package/dist/plugins/marketplace.js +76 -57
- package/dist/plugins/store.d.ts +3 -3
- package/dist/plugins/store.js +6 -6
- package/dist/protocol/index.d.ts +1 -1
- package/dist/store/catalog-store.d.ts +4 -1
- package/dist/store/catalog-store.js +5 -1
- package/dist/store/checkpointing-store.d.ts +41 -0
- package/dist/store/checkpointing-store.js +86 -0
- package/dist/store/disk-store.d.ts +8 -0
- package/dist/store/disk-store.js +127 -5
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +2 -1
- package/dist/store/log-store.d.ts +9 -1
- package/dist/store/log-store.js +68 -4
- package/dist/store/migrate.d.ts +8 -2
- package/dist/store/migrate.js +9 -2
- package/dist/store/origin.d.ts +31 -6
- package/dist/store/origin.js +0 -14
- package/dist/store/pg.d.ts +1 -0
- package/dist/store/pg.js +37 -2
- package/dist/store/redis.d.ts +1 -0
- package/dist/store/redis.js +30 -0
- package/dist/store/repository.d.ts +13 -1
- package/dist/store/repository.js +45 -2
- package/dist/store/session-catalog.d.ts +4 -0
- package/dist/store/session-catalog.js +6 -0
- package/dist/store/storage.js +3 -0
- package/dist/store/store.d.ts +97 -34
- package/dist/store/store.js +64 -10
- package/dist/telemetry/appender.d.ts +43 -0
- package/dist/telemetry/appender.js +46 -0
- package/dist/telemetry/events.d.ts +142 -0
- package/dist/telemetry/events.js +141 -0
- package/dist/telemetry/index.d.ts +10 -0
- package/dist/telemetry/index.js +6 -0
- package/dist/telemetry/projection.d.ts +23 -0
- package/dist/telemetry/projection.js +185 -0
- package/dist/telemetry/redact.d.ts +20 -0
- package/dist/telemetry/redact.js +40 -0
- package/dist/telemetry/service.d.ts +49 -0
- package/dist/telemetry/service.js +137 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +123 -0
- package/dist/tool/background.d.ts +9 -6
- package/dist/tool/background.js +7 -1
- package/dist/tool/builtin/ask-user-question.js +6 -5
- package/dist/tool/builtin/bash.d.ts +6 -0
- package/dist/tool/builtin/bash.js +79 -42
- package/dist/tool/builtin/edit.js +82 -109
- package/dist/tool/builtin/glob.js +13 -13
- package/dist/tool/builtin/grep.js +13 -13
- package/dist/tool/builtin/read.js +25 -15
- package/dist/tool/builtin/write.js +49 -33
- package/dist/tool/define.d.ts +14 -8
- package/dist/tool/define.js +8 -2
- package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
- package/dist/tool/{machine-base.js → environment-base.js} +45 -119
- package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
- package/dist/tool/{machine-local.js → environment-local.js} +60 -81
- package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
- package/dist/tool/{machine-null.js → environment-null.js} +9 -9
- package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
- package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
- package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
- package/dist/tool/environment.js +2 -0
- package/dist/tool/file-freshness.d.ts +33 -19
- package/dist/tool/file-freshness.js +39 -30
- package/dist/tool/filesystem-tools.d.ts +1 -1
- package/dist/tool/filesystem-tools.js +1 -1
- package/dist/tool/git-context.d.ts +2 -2
- package/dist/tool/git-context.js +8 -8
- package/dist/tool/index.d.ts +12 -12
- package/dist/tool/index.js +12 -10
- package/dist/tool/policies/path-access.d.ts +4 -4
- package/dist/tool/policies/path-access.js +12 -12
- package/dist/tool/questions.d.ts +8 -0
- package/dist/tool/search/catalog.d.ts +37 -0
- package/dist/tool/search/catalog.js +182 -0
- package/dist/tool/search/deferral.d.ts +3 -2
- package/dist/tool/search/loaded.d.ts +32 -0
- package/dist/tool/search/loaded.js +96 -0
- package/dist/tool/search/search-tool.d.ts +2 -6
- package/dist/tool/search/search-tool.js +16 -15
- package/dist/tool/shell-env.js +4 -0
- package/dist/tool/support/bash-paths.js +38 -7
- package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
- package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
- package/dist/tool/support/git-worktree.d.ts +3 -3
- package/dist/tool/support/git-worktree.js +6 -6
- package/dist/tool/support/rg-locator.d.ts +6 -6
- package/dist/tool/support/rg-locator.js +6 -6
- package/dist/tool/support/ripgrep-run.d.ts +5 -5
- package/dist/tool/support/ripgrep-run.js +3 -3
- package/dist/tool/support/tool-path.d.ts +3 -3
- package/dist/tool/support/tool-path.js +7 -7
- package/dist/tool/types.d.ts +54 -10
- package/dist/tool/web/fetch-url.js +1 -1
- package/dist/tool/web/web-search.js +1 -1
- package/dist/tool/workspace-spec.d.ts +3 -3
- package/dist/tool/workspace-spec.js +27 -27
- package/dist/tracing/bridge.d.ts +9 -1
- package/dist/tracing/bridge.js +307 -77
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/otel.d.ts +28 -1
- package/dist/tracing/otel.js +150 -38
- package/dist/tracing/processor.d.ts +22 -0
- package/dist/tracing/processor.js +2 -0
- package/dist/tracing/spans.d.ts +54 -0
- package/dist/tracing/spans.js +5 -0
- package/package.json +6 -2
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
import { InjectionManager } from "./injection.js";
|
|
2
2
|
const STOP_TIMEOUT_MS = 5_000;
|
|
3
3
|
const START_TIMEOUT_MS = 10_000;
|
|
4
|
+
/** Default per-call budget for a `detachable` capability's hooks (see `Capability.hookTimeoutMs`). */
|
|
5
|
+
const HOOK_TIMEOUT_MS = 30_000;
|
|
6
|
+
/** `provider.response` runs before the body streams: a slow observer is latency on every token. */
|
|
7
|
+
const RESPONSE_HOOK_TIMEOUT_MS = 1_000;
|
|
4
8
|
export class AssembledCapabilities {
|
|
5
9
|
diagnostics = [];
|
|
6
10
|
loopHookParts = [];
|
|
7
11
|
boundaryContinuations = [];
|
|
8
12
|
runStarts = [];
|
|
9
13
|
/**
|
|
10
|
-
* Stable arrays handed to `
|
|
14
|
+
* Stable arrays handed to `RunContext.gates`. Capabilities are started and absorbed one
|
|
11
15
|
* at a time, so a consumer that snapshotted at `start()` would miss every gate registered by a
|
|
12
16
|
* capability ordered after it — reading through this live reference avoids depending on order.
|
|
13
17
|
*/
|
|
14
18
|
gates = { compaction: [] };
|
|
15
19
|
injection = new InjectionManager();
|
|
20
|
+
/** Every started capability's provider hooks, in order — already isolated when detachable. */
|
|
21
|
+
providerHooks = [];
|
|
16
22
|
staticTools = [];
|
|
17
23
|
toolProviders = [];
|
|
18
24
|
toolFilters = [];
|
|
19
25
|
started = [];
|
|
20
26
|
ctx;
|
|
21
27
|
stopTimeoutMs;
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
reporter;
|
|
29
|
+
constructor(base, options = {}) {
|
|
30
|
+
this.ctx = { ...base, injection: this.injection, gates: this.gates };
|
|
24
31
|
this.stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;
|
|
32
|
+
this.reporter = options.report;
|
|
33
|
+
}
|
|
34
|
+
/** The run context handed to every capability's `start` and tool provider. */
|
|
35
|
+
get context() {
|
|
36
|
+
return this.ctx;
|
|
25
37
|
}
|
|
26
38
|
async listTools() {
|
|
27
39
|
const tools = [...this.staticTools];
|
|
@@ -41,11 +53,11 @@ export class AssembledCapabilities {
|
|
|
41
53
|
return tools;
|
|
42
54
|
}
|
|
43
55
|
/** Apply every capability's tool filter in registration order. A thrower is skipped. */
|
|
44
|
-
applyToolFilters(tools) {
|
|
56
|
+
applyToolFilters(tools, ctx) {
|
|
45
57
|
let current = tools;
|
|
46
58
|
for (const filter of this.toolFilters) {
|
|
47
59
|
try {
|
|
48
|
-
current = filter(current);
|
|
60
|
+
current = filter(current, ctx);
|
|
49
61
|
}
|
|
50
62
|
catch (error) {
|
|
51
63
|
this.diagnostics.push({
|
|
@@ -70,8 +82,11 @@ export class AssembledCapabilities {
|
|
|
70
82
|
// capability.policies are session-tier contributions — collected once by
|
|
71
83
|
// Session.buildPermissionManager (the manager is session-lived), not per run.
|
|
72
84
|
if (capability.hooks) {
|
|
73
|
-
//
|
|
74
|
-
|
|
85
|
+
// What the contract promises: a `detachable` capability's hook can fail or stall without
|
|
86
|
+
// taking the run with it. An `invariant` one is used as written.
|
|
87
|
+
const hooks = capability.contract === "detachable" ? this.isolate(capability, capability.hooks) : capability.hooks;
|
|
88
|
+
// Run-tier hooks are driven by the Runner itself, not composed into the step environment.
|
|
89
|
+
const { shouldContinueAfterStop, beforeRun, ...loopHooks } = hooks;
|
|
75
90
|
if (Object.keys(loopHooks).length > 0)
|
|
76
91
|
this.loopHookParts.push(loopHooks);
|
|
77
92
|
if (shouldContinueAfterStop)
|
|
@@ -79,8 +94,65 @@ export class AssembledCapabilities {
|
|
|
79
94
|
if (beforeRun)
|
|
80
95
|
this.runStarts.push(beforeRun);
|
|
81
96
|
}
|
|
97
|
+
if (capability.provider) {
|
|
98
|
+
this.providerHooks.push(capability.contract === "detachable" ? this.isolateProvider(capability, capability.provider) : capability.provider);
|
|
99
|
+
}
|
|
82
100
|
this.injection.registerAll(capability.injectors ?? []);
|
|
83
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Wrap every hook of a `detachable` capability: each call gets the capability's budget, and a
|
|
104
|
+
* throw or an overrun becomes a warning plus "no opinion" (`undefined`) — which every hook slot
|
|
105
|
+
* already reads as "carry on unchanged". The overrunning call is not cancelled (a hook has no
|
|
106
|
+
* signal of its own); it is simply no longer waited for, and whatever it returns is dropped.
|
|
107
|
+
*/
|
|
108
|
+
isolate(capability, hooks) {
|
|
109
|
+
const timeoutMs = capability.hookTimeoutMs ?? HOOK_TIMEOUT_MS;
|
|
110
|
+
const wrapped = {};
|
|
111
|
+
for (const [slot, hook] of Object.entries(hooks)) {
|
|
112
|
+
if (hook !== undefined)
|
|
113
|
+
wrapped[slot] = this.guard(capability, slot, hook, timeoutMs);
|
|
114
|
+
}
|
|
115
|
+
return wrapped;
|
|
116
|
+
}
|
|
117
|
+
/** The same guard for the hooks below the loop. `response` never gets more than 1s. */
|
|
118
|
+
isolateProvider(capability, hooks) {
|
|
119
|
+
const timeoutMs = capability.hookTimeoutMs ?? HOOK_TIMEOUT_MS;
|
|
120
|
+
const guard = (slot, hook, ms) => hook === undefined ? undefined : this.guard(capability, slot, hook, ms);
|
|
121
|
+
const headers = guard("provider.headers", hooks.headers?.bind(hooks), timeoutMs);
|
|
122
|
+
const payload = guard("provider.payload", hooks.payload?.bind(hooks), timeoutMs);
|
|
123
|
+
const response = guard("provider.response", hooks.response?.bind(hooks), Math.min(timeoutMs, RESPONSE_HOOK_TIMEOUT_MS));
|
|
124
|
+
return { ...(headers ? { headers } : {}), ...(payload ? { payload } : {}), ...(response ? { response } : {}) };
|
|
125
|
+
}
|
|
126
|
+
/** One call, budgeted: a throw or an overrun is reported and becomes `undefined`. */
|
|
127
|
+
guard(capability, slot, fn, timeoutMs) {
|
|
128
|
+
return async (...args) => {
|
|
129
|
+
try {
|
|
130
|
+
return await withTimeout(Promise.resolve(fn(...args)), timeoutMs);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
this.report({
|
|
134
|
+
capability: capability.name,
|
|
135
|
+
phase: "hook",
|
|
136
|
+
level: "warn",
|
|
137
|
+
message: `${slot} failed/timed out; ignored for this call: ${messageOf(error)}`,
|
|
138
|
+
});
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
report(diagnostic) {
|
|
144
|
+
if (this.reporter === undefined) {
|
|
145
|
+
this.diagnostics.push(diagnostic);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
this.reporter(diagnostic);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// A reporter that throws must not turn an isolated failure back into a run failure.
|
|
153
|
+
this.diagnostics.push(diagnostic);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
84
156
|
markStarted(capability) {
|
|
85
157
|
this.started.push(capability);
|
|
86
158
|
}
|
|
@@ -114,8 +186,9 @@ export async function assembleCapabilities(capabilities, ctx, options = {}) {
|
|
|
114
186
|
const assembled = new AssembledCapabilities(ctx, options);
|
|
115
187
|
const startTimeoutMs = options.startTimeoutMs ?? START_TIMEOUT_MS;
|
|
116
188
|
const seenNames = new Set();
|
|
117
|
-
//
|
|
118
|
-
|
|
189
|
+
// The live injection manager + gate arrays ride along so a capability like compaction can
|
|
190
|
+
// resync injector watermarks after collapsing the prefix.
|
|
191
|
+
const startCtx = assembled.context;
|
|
119
192
|
for (const capability of capabilities) {
|
|
120
193
|
if (seenNames.has(capability.name)) {
|
|
121
194
|
assembled.diagnostics.push({
|
|
@@ -153,6 +226,9 @@ function messageOf(error) {
|
|
|
153
226
|
return error instanceof Error ? error.message : String(error);
|
|
154
227
|
}
|
|
155
228
|
function withTimeout(promise, ms, cancel) {
|
|
229
|
+
// `Infinity` means "no deadline" — handed to setTimeout it would overflow and fire at once.
|
|
230
|
+
if (!Number.isFinite(ms))
|
|
231
|
+
return promise;
|
|
156
232
|
return new Promise((resolve, reject) => {
|
|
157
233
|
const timer = setTimeout(() => {
|
|
158
234
|
const error = new Error(`timed out after ${ms}ms`);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
|
+
import type { BackgroundTask, BackgroundTaskInfoBase, BackgroundTaskSink, TaskOutputLocation } from "./task.ts";
|
|
3
|
+
export interface CodeBackgroundTaskInfo extends BackgroundTaskInfoBase {
|
|
4
|
+
readonly kind: "code";
|
|
5
|
+
/** The model's one-line description of the program. */
|
|
6
|
+
readonly program: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CodeBackgroundTaskOptions {
|
|
9
|
+
readonly timeoutMs?: number;
|
|
10
|
+
readonly abort?: () => void;
|
|
11
|
+
readonly parentAddress?: string;
|
|
12
|
+
readonly toolCallId?: string;
|
|
13
|
+
/** The log file on the environment the program writes its output to. Every background program must have one. */
|
|
14
|
+
readonly logPath: string;
|
|
15
|
+
readonly environment: Environment;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A background task that runs a Code Mode program (`RunCode`) to completion.
|
|
19
|
+
*
|
|
20
|
+
* Holds no output of its own: the program's owner writes its console lines, each nested tool
|
|
21
|
+
* call's outcome and the final result to a log file on the environment as they happen, the same
|
|
22
|
+
* place a background command's bytes go, and this task names that file. `BackgroundOutput`
|
|
23
|
+
* reads it like any other file-backed task; a detached program's progress is the same thing
|
|
24
|
+
* an attached one's was, in the same place.
|
|
25
|
+
*/
|
|
26
|
+
export declare class CodeBackgroundTask implements BackgroundTask {
|
|
27
|
+
readonly kind: "code";
|
|
28
|
+
readonly idPrefix: string;
|
|
29
|
+
readonly description: string;
|
|
30
|
+
readonly timeoutMs?: number;
|
|
31
|
+
readonly parentAddress?: string;
|
|
32
|
+
readonly toolCallId?: string;
|
|
33
|
+
readonly outputLocation: TaskOutputLocation;
|
|
34
|
+
private readonly run;
|
|
35
|
+
private readonly abort?;
|
|
36
|
+
constructor(run: (sink: BackgroundTaskSink) => Promise<{
|
|
37
|
+
ok: boolean;
|
|
38
|
+
stopReason?: string;
|
|
39
|
+
}>, description: string, options: CodeBackgroundTaskOptions);
|
|
40
|
+
start(sink: BackgroundTaskSink): Promise<void>;
|
|
41
|
+
toInfo(base: BackgroundTaskInfoBase): CodeBackgroundTaskInfo;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=code-task.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { errorMessage, isAbortError } from "../../loop/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A background task that runs a Code Mode program (`RunCode`) to completion.
|
|
4
|
+
*
|
|
5
|
+
* Holds no output of its own: the program's owner writes its console lines, each nested tool
|
|
6
|
+
* call's outcome and the final result to a log file on the environment as they happen, the same
|
|
7
|
+
* place a background command's bytes go, and this task names that file. `BackgroundOutput`
|
|
8
|
+
* reads it like any other file-backed task; a detached program's progress is the same thing
|
|
9
|
+
* an attached one's was, in the same place.
|
|
10
|
+
*/
|
|
11
|
+
export class CodeBackgroundTask {
|
|
12
|
+
kind = "code";
|
|
13
|
+
idPrefix = "code";
|
|
14
|
+
description;
|
|
15
|
+
timeoutMs;
|
|
16
|
+
parentAddress;
|
|
17
|
+
toolCallId;
|
|
18
|
+
outputLocation;
|
|
19
|
+
run;
|
|
20
|
+
abort;
|
|
21
|
+
constructor(run, description, options) {
|
|
22
|
+
if (typeof options.logPath !== "string" || options.logPath.length === 0) {
|
|
23
|
+
throw new Error("A background program requires its durable output log.");
|
|
24
|
+
}
|
|
25
|
+
this.run = run;
|
|
26
|
+
this.description = description;
|
|
27
|
+
this.timeoutMs = options.timeoutMs;
|
|
28
|
+
this.abort = options.abort;
|
|
29
|
+
this.parentAddress = options.parentAddress;
|
|
30
|
+
this.toolCallId = options.toolCallId;
|
|
31
|
+
this.outputLocation = { kind: "file", environment: options.environment, path: options.logPath };
|
|
32
|
+
}
|
|
33
|
+
async start(sink) {
|
|
34
|
+
const requestAbort = () => {
|
|
35
|
+
this.abort?.();
|
|
36
|
+
};
|
|
37
|
+
if (sink.signal.aborted)
|
|
38
|
+
requestAbort();
|
|
39
|
+
else
|
|
40
|
+
sink.signal.addEventListener("abort", requestAbort, { once: true });
|
|
41
|
+
const deadline = Symbol("background-code-deadline");
|
|
42
|
+
const races = [this.run(sink)];
|
|
43
|
+
let timer;
|
|
44
|
+
if (this.timeoutMs !== undefined && this.timeoutMs > 0) {
|
|
45
|
+
races.push(new Promise((resolve) => {
|
|
46
|
+
timer = setTimeout(() => resolve(deadline), this.timeoutMs);
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const outcome = await Promise.race(races);
|
|
51
|
+
if (outcome === deadline) {
|
|
52
|
+
this.abort?.();
|
|
53
|
+
await sink.settle({ status: "timed_out" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await sink.settle(outcome.ok ? { status: "completed" } : { status: "failed", ...(outcome.stopReason !== undefined ? { stopReason: outcome.stopReason } : {}) });
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (sink.signal.aborted && isAbortError(error)) {
|
|
60
|
+
await sink.settle({ status: "killed" });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await sink.settle({ status: "failed", stopReason: errorMessage(error) });
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (timer !== undefined)
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
sink.signal.removeEventListener("abort", requestAbort);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
toInfo(base) {
|
|
72
|
+
return { ...base, kind: "code", program: this.description };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=code-task.js.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CommandStarter, ProcessSpawnOptions } from "../../tool/background.ts";
|
|
2
2
|
import type { BackgroundTask, BackgroundTaskInfoBase, BackgroundTaskSink, TaskOutputLocation } from "./task.ts";
|
|
3
|
+
/** Why a command task that was asked to stop settled as failed rather than killed. */
|
|
4
|
+
export declare const COMMAND_NOT_STOPPED_REASON = "a stop was requested, but the command could not be confirmed stopped and may still be running";
|
|
3
5
|
export interface CommandBackgroundTaskInfo extends BackgroundTaskInfoBase {
|
|
4
6
|
/** Wire value kept as "process" — persisted task records use it. */
|
|
5
7
|
readonly kind: "process";
|
|
@@ -16,8 +18,9 @@ export interface CommandBackgroundTaskInfo extends BackgroundTaskInfoBase {
|
|
|
16
18
|
* sandbox transports cannot provide honestly, which is what used to force a fake handle
|
|
17
19
|
* whose `kill()` did nothing.
|
|
18
20
|
*
|
|
19
|
-
* No `forceStop`: SIGTERM → grace → SIGKILL escalation belongs to the
|
|
20
|
-
* is where killing is real. Aborting the signal is the whole stop protocol
|
|
21
|
+
* No `forceStop`: SIGTERM → grace → SIGKILL escalation belongs to the Environment layer, which
|
|
22
|
+
* is where killing is real. Aborting the signal is the whole stop protocol — and the result's
|
|
23
|
+
* `terminated` is the answer: only a confirmed stop settles as `killed`.
|
|
21
24
|
*/
|
|
22
25
|
export declare class CommandBackgroundTask implements BackgroundTask {
|
|
23
26
|
readonly kind: "process";
|
|
@@ -34,9 +37,13 @@ export declare class CommandBackgroundTask implements BackgroundTask {
|
|
|
34
37
|
readonly parentAddress?: string;
|
|
35
38
|
readonly toolCallId?: string;
|
|
36
39
|
private exitCodeValue;
|
|
40
|
+
private stopUnconfirmedValue;
|
|
37
41
|
constructor(start: CommandStarter, command: string, description: string, options?: ProcessSpawnOptions);
|
|
38
42
|
/** Latest known exit status; null until the command settles, or when it reported none. */
|
|
39
43
|
get exitCode(): number | null;
|
|
44
|
+
/** A stop was requested and the backend could not confirm the command ended — it may still
|
|
45
|
+
* be running. Only meaningful once the task has settled. */
|
|
46
|
+
get stopUnconfirmed(): boolean;
|
|
40
47
|
start(sink: BackgroundTaskSink): Promise<void>;
|
|
41
48
|
toInfo(base: BackgroundTaskInfoBase): CommandBackgroundTaskInfo;
|
|
42
49
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from "../../loop/errors.js";
|
|
2
|
+
/** Why a command task that was asked to stop settled as failed rather than killed. */
|
|
3
|
+
export const COMMAND_NOT_STOPPED_REASON = "a stop was requested, but the command could not be confirmed stopped and may still be running";
|
|
2
4
|
/**
|
|
3
5
|
* A shell command running as a background task.
|
|
4
6
|
*
|
|
@@ -9,8 +11,9 @@ import { errorMessage } from "../../loop/errors.js";
|
|
|
9
11
|
* sandbox transports cannot provide honestly, which is what used to force a fake handle
|
|
10
12
|
* whose `kill()` did nothing.
|
|
11
13
|
*
|
|
12
|
-
* No `forceStop`: SIGTERM → grace → SIGKILL escalation belongs to the
|
|
13
|
-
* is where killing is real. Aborting the signal is the whole stop protocol
|
|
14
|
+
* No `forceStop`: SIGTERM → grace → SIGKILL escalation belongs to the Environment layer, which
|
|
15
|
+
* is where killing is real. Aborting the signal is the whole stop protocol — and the result's
|
|
16
|
+
* `terminated` is the answer: only a confirmed stop settles as `killed`.
|
|
14
17
|
*/
|
|
15
18
|
export class CommandBackgroundTask {
|
|
16
19
|
kind = "process";
|
|
@@ -27,20 +30,26 @@ export class CommandBackgroundTask {
|
|
|
27
30
|
parentAddress;
|
|
28
31
|
toolCallId;
|
|
29
32
|
exitCodeValue = null;
|
|
33
|
+
stopUnconfirmedValue = false;
|
|
30
34
|
constructor(start, command, description, options = {}) {
|
|
31
35
|
this.start_ = start;
|
|
32
36
|
this.command = command;
|
|
33
37
|
this.description = description;
|
|
34
38
|
this.parentAddress = options.parentAddress;
|
|
35
39
|
this.toolCallId = options.toolCallId;
|
|
36
|
-
const { logPath,
|
|
37
|
-
if (logPath !== undefined &&
|
|
38
|
-
this.outputLocation = { kind: "file",
|
|
40
|
+
const { logPath, environment } = options;
|
|
41
|
+
if (logPath !== undefined && environment !== undefined)
|
|
42
|
+
this.outputLocation = { kind: "file", environment, path: logPath };
|
|
39
43
|
}
|
|
40
44
|
/** Latest known exit status; null until the command settles, or when it reported none. */
|
|
41
45
|
get exitCode() {
|
|
42
46
|
return this.exitCodeValue;
|
|
43
47
|
}
|
|
48
|
+
/** A stop was requested and the backend could not confirm the command ended — it may still
|
|
49
|
+
* be running. Only meaningful once the task has settled. */
|
|
50
|
+
get stopUnconfirmed() {
|
|
51
|
+
return this.stopUnconfirmedValue;
|
|
52
|
+
}
|
|
44
53
|
async start(sink) {
|
|
45
54
|
// The sink's signal is the manager's stop switch; forward it to the command. Its own
|
|
46
55
|
// controller keeps the two decoupled, so a future internal stop reason stays possible.
|
|
@@ -50,7 +59,7 @@ export class CommandBackgroundTask {
|
|
|
50
59
|
requestStop();
|
|
51
60
|
else
|
|
52
61
|
sink.signal.addEventListener("abort", requestStop, { once: true });
|
|
53
|
-
// The command's output was redirected ON THE
|
|
62
|
+
// The command's output was redirected ON THE ENVIRONMENT before this starts. That file IS the
|
|
54
63
|
// output; readers open a window on it only when somebody asks. No pipe tap or in-memory
|
|
55
64
|
// mirror exists on the background path.
|
|
56
65
|
try {
|
|
@@ -60,6 +69,13 @@ export class CommandBackgroundTask {
|
|
|
60
69
|
signal: controller.signal,
|
|
61
70
|
});
|
|
62
71
|
this.exitCodeValue = result.exitCode ?? null;
|
|
72
|
+
if (sink.signal.aborted && !result.terminated) {
|
|
73
|
+
// The backend walked away rather than stopped it. "killed" would tell the model and the
|
|
74
|
+
// user the command is gone when it may well still be running.
|
|
75
|
+
this.stopUnconfirmedValue = true;
|
|
76
|
+
await sink.settle({ status: "failed", stopReason: COMMAND_NOT_STOPPED_REASON });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
63
79
|
await sink.settle({
|
|
64
80
|
status: sink.signal.aborted ? "killed" : result.exitCode === 0 ? "completed" : "failed",
|
|
65
81
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Capability } from "../capability.ts";
|
|
2
2
|
import { BackgroundManager } from "./manager.ts";
|
|
3
3
|
export { BackgroundManager } from "./manager.ts";
|
|
4
|
-
export type { BackgroundManagerOptions, BackgroundManagerRuntime, BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot, } from "./manager.ts";
|
|
4
|
+
export type { BackgroundManagerOptions, BackgroundManagerRuntime, OutputFollowTiming, BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot, } from "./manager.ts";
|
|
5
|
+
export type { StallWatchdogTiming } from "./stall-watchdog.ts";
|
|
5
6
|
export { CommandBackgroundTask } from "./command-task.ts";
|
|
6
7
|
export type { CommandBackgroundTaskInfo } from "./command-task.ts";
|
|
7
8
|
export { AgentBackgroundTask } from "./agent-task.ts";
|
|
@@ -10,6 +11,10 @@ export { QuestionBackgroundTask } from "./question-task.ts";
|
|
|
10
11
|
export type { QuestionBackgroundTaskInfo, QuestionBackgroundTaskOptions } from "./question-task.ts";
|
|
11
12
|
export { WorkflowBackgroundTask } from "./workflow-task.ts";
|
|
12
13
|
export type { WorkflowBackgroundTaskInfo, WorkflowBackgroundTaskOptions } from "./workflow-task.ts";
|
|
14
|
+
export { CodeBackgroundTask } from "./code-task.ts";
|
|
15
|
+
export type { CodeBackgroundTaskInfo, CodeBackgroundTaskOptions } from "./code-task.ts";
|
|
16
|
+
export { asTaskRegistrar } from "./registrar.ts";
|
|
17
|
+
export type { BackgroundTaskRegistrar } from "./registrar.ts";
|
|
13
18
|
export { StoreBackgroundTaskPersistence, isPersistedTaskTerminal, isValidPersistedTask } from "./persist.ts";
|
|
14
19
|
export type { BackgroundTaskPersistence, PersistedTask } from "./persist.ts";
|
|
15
20
|
export { DiskBackgroundTaskPersistence } from "./persist-disk.ts";
|
|
@@ -7,6 +7,8 @@ export { CommandBackgroundTask } from "./command-task.js";
|
|
|
7
7
|
export { AgentBackgroundTask } from "./agent-task.js";
|
|
8
8
|
export { QuestionBackgroundTask } from "./question-task.js";
|
|
9
9
|
export { WorkflowBackgroundTask } from "./workflow-task.js";
|
|
10
|
+
export { CodeBackgroundTask } from "./code-task.js";
|
|
11
|
+
export { asTaskRegistrar } from "./registrar.js";
|
|
10
12
|
export { StoreBackgroundTaskPersistence, isPersistedTaskTerminal, isValidPersistedTask } from "./persist.js";
|
|
11
13
|
export { DiskBackgroundTaskPersistence } from "./persist-disk.js";
|
|
12
14
|
export { backgroundListTool, backgroundOutputTool, backgroundStopTool } from "./tools.js";
|
|
@@ -14,33 +16,37 @@ export { TERMINAL_STATUSES, isBackgroundTaskTerminal, } from "./task.js";
|
|
|
14
16
|
export function backgroundCapability(manager = new BackgroundManager()) {
|
|
15
17
|
return {
|
|
16
18
|
name: "background",
|
|
19
|
+
contract: "detachable",
|
|
17
20
|
// Enumeration stays a host API (`session.listBackgroundTasks()`). The model already owns
|
|
18
21
|
// every task id it successfully spawned, while cold recovery injects ids whose ack was lost;
|
|
19
22
|
// exposing an unbounded list invites unrelated historical tasks into the reasoning path.
|
|
20
23
|
tools: [backgroundOutputTool(manager), backgroundStopTool(manager)],
|
|
21
24
|
service: manager,
|
|
22
25
|
openSession: async (ctx) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
{
|
|
27
|
+
const { steer, events, store } = ctx;
|
|
28
|
+
// Each task's status is now durably recorded in a dedicated per-task store (disk
|
|
29
|
+
// sessions get the `<sessionDir>/tasks/<id>/` layout; other backends use KV state),
|
|
30
|
+
// so a task orphaned by a dead process can be reconciled to `lost` on reopen. Loading
|
|
31
|
+
// + reconcile happen in the store-cutover step; here we attach the persistence so live
|
|
32
|
+
// spawns start recording. Without a durable store the manager stays purely in memory.
|
|
33
|
+
manager.attach({
|
|
34
|
+
steer,
|
|
35
|
+
events,
|
|
36
|
+
sessionId: ctx.sessionId,
|
|
37
|
+
persistence: makeTaskPersistence(store),
|
|
38
|
+
// Shard-backed output (a sub-agent's conversation) is read back from here rather than
|
|
39
|
+
// copied into the task, so the manager needs the log itself, not just the task store.
|
|
40
|
+
...(store !== undefined ? { store } : {}),
|
|
41
|
+
});
|
|
42
|
+
// Load prior-process task records so reconcile (triggered on first run via
|
|
43
|
+
// session.reconcileSubagents) can reclassify any that were left non-terminal.
|
|
44
|
+
await manager.loadFromDisk();
|
|
45
|
+
}
|
|
40
46
|
},
|
|
41
|
-
// Only releases the event subscription taken
|
|
42
|
-
//
|
|
43
|
-
//
|
|
47
|
+
// Only releases the event subscription taken at open. Running tasks are deliberately NOT
|
|
48
|
+
// stopped here: closing a session releases resources, it does not cancel work, and `attach`
|
|
49
|
+
// is last-writer-wins anyway.
|
|
44
50
|
closeSession: () => {
|
|
45
51
|
manager.detachRuntime();
|
|
46
52
|
},
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
import type { SubagentRecord } from "../../agent/subagent.ts";
|
|
2
|
+
import type { WorkflowSnapshot } from "../../agent/workflow/snapshot.ts";
|
|
1
3
|
import type { EventSink } from "../../events/index.ts";
|
|
2
4
|
import type { SteerBus } from "../../loop/steer.ts";
|
|
3
5
|
import { type SessionStore } from "../../store/index.ts";
|
|
6
|
+
import { type StallWatchdogTiming } from "./stall-watchdog.ts";
|
|
4
7
|
import type { AttachedOutcome, AttachedRunOptions, BackgroundSpawner, CommandStarter, ProcessSpawnOptions, QuestionSpawnOptions } from "../../tool/background.ts";
|
|
5
8
|
import type { ToolResult } from "../../tool/types.ts";
|
|
6
9
|
import { type BackgroundTaskPersistence } from "./persist.ts";
|
|
7
10
|
import { isBackgroundTaskTerminal, type BackgroundTask, type BackgroundTaskInfo, type BackgroundTaskOutputDelta, type BackgroundTaskOutputSnapshot } from "./task.ts";
|
|
8
11
|
export type { BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot } from "./task.ts";
|
|
12
|
+
/** Cadence of the live output tail (see {@link followOutputFile}). */
|
|
13
|
+
export interface OutputFollowTiming {
|
|
14
|
+
/** Between checks while output is flowing. */
|
|
15
|
+
readonly intervalMs?: number;
|
|
16
|
+
/** Ceiling the interval backs off to while output is quiet. */
|
|
17
|
+
readonly quietMaxIntervalMs?: number;
|
|
18
|
+
}
|
|
9
19
|
export interface BackgroundManagerOptions {
|
|
10
20
|
readonly maxRunningTasks?: number;
|
|
11
21
|
readonly now?: () => number;
|
|
22
|
+
/** Timing of the stuck-on-a-prompt check for command tasks (see stall-watchdog.ts). */
|
|
23
|
+
readonly stallDetection?: StallWatchdogTiming;
|
|
24
|
+
/** Cadence of the live output tail while a run is attached (see followOutputFile). */
|
|
25
|
+
readonly outputFollow?: OutputFollowTiming;
|
|
12
26
|
}
|
|
13
27
|
export interface BackgroundManagerRuntime {
|
|
14
28
|
readonly steer?: SteerBus;
|
|
@@ -39,6 +53,8 @@ export declare class BackgroundManager implements BackgroundSpawner {
|
|
|
39
53
|
private unsubscribeConsumption?;
|
|
40
54
|
/** Serialize the whole task store, including the KV backend's shared task index. */
|
|
41
55
|
private persistenceChain;
|
|
56
|
+
private readonly stallDetection;
|
|
57
|
+
private readonly outputFollow;
|
|
42
58
|
constructor(options?: BackgroundManagerOptions);
|
|
43
59
|
attach(runtime: BackgroundManagerRuntime): void;
|
|
44
60
|
/** Undo `attach`'s subscription. (Not `detach` — that one moves a tool call to the
|
|
@@ -81,6 +97,18 @@ export declare class BackgroundManager implements BackgroundSpawner {
|
|
|
81
97
|
*/
|
|
82
98
|
private adoptRunning;
|
|
83
99
|
registerTask(task: BackgroundTask): string;
|
|
100
|
+
/**
|
|
101
|
+
* Background commands only: a foreground one has a timeout and a watching user, and other
|
|
102
|
+
* kinds have no terminal prompt to get stuck on. Started once the task is in the background —
|
|
103
|
+
* a detached run starts watching at the moment it detaches.
|
|
104
|
+
*/
|
|
105
|
+
private watchForStall;
|
|
106
|
+
/**
|
|
107
|
+
* Tell the model a background command looks stuck on a prompt. Not a settle — the task is
|
|
108
|
+
* still running — so it goes out as a plain notice rather than a `background_done`, which the
|
|
109
|
+
* settle-notification ledger and the UI would read as the task having ended.
|
|
110
|
+
*/
|
|
111
|
+
private steerStalled;
|
|
84
112
|
/** The durable projection of a task. The output's address comes from the task itself and is
|
|
85
113
|
* never reconstructed from an id. */
|
|
86
114
|
private toPersisted;
|
|
@@ -99,6 +127,25 @@ export declare class BackgroundManager implements BackgroundSpawner {
|
|
|
99
127
|
* parent conversation address is part of the identity. Used internally by cold recovery;
|
|
100
128
|
* model-facing reads continue to use the stable task id via BackgroundOutput. */
|
|
101
129
|
findByOrigin(parentAddress: string, toolCallId: string): BackgroundTaskInfo | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Past BACKGROUND workflow runs, newest first. A FOREGROUND workflow is a plain `Workflow`
|
|
132
|
+
* tool call — its record is the conversation plus its journal shard — so it is not a task and
|
|
133
|
+
* is not listed here (its shard stays resumable by runId).
|
|
134
|
+
*/
|
|
135
|
+
listWorkflows(): readonly WorkflowSnapshot[];
|
|
136
|
+
/** One background workflow run by runId, or undefined if this ledger has never seen it. */
|
|
137
|
+
getWorkflow(runId: string): WorkflowSnapshot | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* The background subagents in this ledger (live + reconciled ghosts). Foreground subagents are
|
|
140
|
+
* plain `Agent` tool calls, so they are not here — same reason as `listWorkflows`.
|
|
141
|
+
*/
|
|
142
|
+
listSubagents(): readonly SubagentRecord[];
|
|
143
|
+
/**
|
|
144
|
+
* Reconcile orphaned work and report it as subagents: `reconcile()` writes the terminal status
|
|
145
|
+
* back, and each reclassified subagent gets a warning on the session's sink so a host does not
|
|
146
|
+
* have to poll for it. Returns the lost subagents (resume any with `Agent(resume="<id>", …)`).
|
|
147
|
+
*/
|
|
148
|
+
reconcileSubagents(): Promise<readonly SubagentRecord[]>;
|
|
102
149
|
list(activeOnly?: boolean, limit?: number): BackgroundTaskInfo[];
|
|
103
150
|
/**
|
|
104
151
|
* A bounded WINDOW onto a task's output, plus the truth about how much it is a window of.
|
|
@@ -145,7 +192,16 @@ export declare class BackgroundManager implements BackgroundSpawner {
|
|
|
145
192
|
suppressTerminalNotification(taskId: string): Promise<void>;
|
|
146
193
|
stop(taskId: string, reason?: string): Promise<BackgroundTaskInfo | undefined>;
|
|
147
194
|
stopAll(reason?: string): Promise<readonly BackgroundTaskInfo[]>;
|
|
148
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Settle when the task reaches a terminal status, the timeout elapses, or `signal` aborts —
|
|
197
|
+
* whichever comes first. Returns the task's status either way; the caller compares it against
|
|
198
|
+
* the terminal set to tell "it finished" from "I stopped waiting".
|
|
199
|
+
*
|
|
200
|
+
* `signal` matters because the timeout can be up to an hour: without it a blocking waiter
|
|
201
|
+
* outlives the turn that started it, and the loop's post-abort grace window has to shoot the
|
|
202
|
+
* tool down with a synthetic error instead of letting it return cleanly.
|
|
203
|
+
*/
|
|
204
|
+
wait(taskId: string, timeoutMs?: number, signal?: AbortSignal): Promise<BackgroundTaskInfo | undefined>;
|
|
149
205
|
private settleTask;
|
|
150
206
|
private resolveWaiters;
|
|
151
207
|
private fireTerminalEffects;
|