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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How often a watched log is checked for growth.
|
|
3
|
+
*
|
|
4
|
+
* A background task is otherwise notification-driven — nobody reads its output until it ends or
|
|
5
|
+
* is asked for — so this is the one recurring cost it carries, on every running task, for the
|
|
6
|
+
* whole of its life. A check is one `fileInfo`: a metadata call on the backends that have one,
|
|
7
|
+
* but still a `stat(1)` command on those that do not. Sampling at a third of the threshold keeps
|
|
8
|
+
* that rare while still noticing a stuck prompt within {@link STALL_THRESHOLD_MS} of it
|
|
9
|
+
* appearing, at worst one interval later.
|
|
10
|
+
*/
|
|
11
|
+
export const STALL_CHECK_INTERVAL_MS = 15_000;
|
|
12
|
+
/** How long output must stay unchanged before the tail is inspected. */
|
|
13
|
+
export const STALL_THRESHOLD_MS = 45_000;
|
|
14
|
+
/** How much of the log's end is read to find its last line. */
|
|
15
|
+
const STALL_TAIL_BYTES = 1024;
|
|
16
|
+
/** Last-line shapes of a prompt waiting for keyboard input. */
|
|
17
|
+
const PROMPT_PATTERNS = [
|
|
18
|
+
/\(y\/n\)/i, // (Y/n), (y/N)
|
|
19
|
+
/\[y\/n\]/i, // [Y/n], [y/N]
|
|
20
|
+
/\(yes\/no\)/i,
|
|
21
|
+
/\? *\([yn]\) *$/i, // npx/npm create: "Ok to proceed? (y)" — not in Claude Code's list
|
|
22
|
+
/\b(?:Do you|Would you|Shall I|Are you sure|Ready to)\b.*\? *$/i,
|
|
23
|
+
/Press (any key|Enter)/i,
|
|
24
|
+
/Continue\?/i,
|
|
25
|
+
/Overwrite\?/i,
|
|
26
|
+
];
|
|
27
|
+
export function looksLikePrompt(tail) {
|
|
28
|
+
const lastLine = tail.trimEnd().split("\n").pop() ?? "";
|
|
29
|
+
return PROMPT_PATTERNS.some((pattern) => pattern.test(lastLine));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Watch a task's log file; call `onStall` once, with the log's tail, when it looks stuck on a
|
|
33
|
+
* prompt. Returns the function that stops watching. Every check costs one `fileInfo`; the tail
|
|
34
|
+
* is read only after the threshold passes, and only once per quiet period.
|
|
35
|
+
*/
|
|
36
|
+
export function startStallWatchdog(file, onStall, timing = {}) {
|
|
37
|
+
const checkIntervalMs = timing.checkIntervalMs ?? STALL_CHECK_INTERVAL_MS;
|
|
38
|
+
const thresholdMs = timing.thresholdMs ?? STALL_THRESHOLD_MS;
|
|
39
|
+
let lastSize = -1;
|
|
40
|
+
let lastGrowth = Date.now();
|
|
41
|
+
let stopped = false;
|
|
42
|
+
let checking = false;
|
|
43
|
+
const check = async () => {
|
|
44
|
+
const { size } = await file.environment.fileInfo(file.path);
|
|
45
|
+
if (size !== lastSize) {
|
|
46
|
+
lastSize = size;
|
|
47
|
+
lastGrowth = Date.now();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (Date.now() - lastGrowth < thresholdMs || size === 0)
|
|
51
|
+
return;
|
|
52
|
+
const offset = Math.max(0, size - STALL_TAIL_BYTES);
|
|
53
|
+
const tail = (await file.environment.readBytes(file.path, { offset, length: size - offset })).toString("utf8");
|
|
54
|
+
if (stopped)
|
|
55
|
+
return;
|
|
56
|
+
if (!looksLikePrompt(tail)) {
|
|
57
|
+
// Quiet but not asking anything: look again after another full threshold, not every tick.
|
|
58
|
+
lastGrowth = Date.now();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
stop();
|
|
62
|
+
onStall(tail.trimEnd());
|
|
63
|
+
};
|
|
64
|
+
const timer = setInterval(() => {
|
|
65
|
+
// Serialize: a slow remote stat must not let the next tick start a second check.
|
|
66
|
+
if (checking || stopped)
|
|
67
|
+
return;
|
|
68
|
+
checking = true;
|
|
69
|
+
check()
|
|
70
|
+
.catch(() => {
|
|
71
|
+
/* the log not created yet, or its environment briefly unreachable — try again next tick */
|
|
72
|
+
})
|
|
73
|
+
.finally(() => {
|
|
74
|
+
checking = false;
|
|
75
|
+
});
|
|
76
|
+
}, checkIntervalMs);
|
|
77
|
+
// Never the reason a host process stays alive.
|
|
78
|
+
timer.unref?.();
|
|
79
|
+
function stop() {
|
|
80
|
+
stopped = true;
|
|
81
|
+
clearInterval(timer);
|
|
82
|
+
}
|
|
83
|
+
return stop;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=stall-watchdog.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
2
|
import type { AgentBackgroundTaskInfo } from "./agent-task.ts";
|
|
3
3
|
import type { CommandBackgroundTaskInfo } from "./command-task.ts";
|
|
4
4
|
import type { QuestionBackgroundTaskInfo } from "./question-task.ts";
|
|
5
5
|
import type { WorkflowBackgroundTaskInfo } from "./workflow-task.ts";
|
|
6
|
+
import type { CodeBackgroundTaskInfo } from "./code-task.ts";
|
|
6
7
|
export type BackgroundTaskStatus = "running" | "completed" | "failed" | "paused" | "timed_out" | "killed" | "lost";
|
|
7
8
|
export declare const TERMINAL_STATUSES: ReadonlySet<BackgroundTaskStatus>;
|
|
8
9
|
export type BackgroundTaskSettlementStatus = "completed" | "failed" | "paused" | "timed_out" | "killed";
|
|
@@ -25,10 +26,10 @@ export interface BackgroundTaskInfoBase {
|
|
|
25
26
|
readonly terminalNotificationSuppressed?: boolean;
|
|
26
27
|
readonly timeoutMs?: number;
|
|
27
28
|
/** Stable pointer to the task's complete output. This is the wire/store shape: unlike
|
|
28
|
-
* {@link TaskOutputLocation}, it contains no live
|
|
29
|
+
* {@link TaskOutputLocation}, it contains no live Environment handle and survives restart. */
|
|
29
30
|
readonly outputRef?: TaskOutputRef;
|
|
30
31
|
}
|
|
31
|
-
export type BackgroundTaskInfo = CommandBackgroundTaskInfo | AgentBackgroundTaskInfo | QuestionBackgroundTaskInfo | WorkflowBackgroundTaskInfo;
|
|
32
|
+
export type BackgroundTaskInfo = CommandBackgroundTaskInfo | AgentBackgroundTaskInfo | QuestionBackgroundTaskInfo | WorkflowBackgroundTaskInfo | CodeBackgroundTaskInfo;
|
|
32
33
|
export interface BackgroundTaskSink {
|
|
33
34
|
readonly signal: AbortSignal;
|
|
34
35
|
settle(settlement: BackgroundTaskSettlement): Promise<boolean>;
|
|
@@ -37,7 +38,7 @@ export interface BackgroundTaskSink {
|
|
|
37
38
|
* Where a task's output already lives — a FACT the task states, never a copy it holds.
|
|
38
39
|
*
|
|
39
40
|
* The variants exist because output has several native homes and none is this process. A
|
|
40
|
-
* command's bytes are written by the OS into a file on the
|
|
41
|
+
* command's bytes are written by the OS into a file on the environment; a sub-agent's messages are
|
|
41
42
|
* appended by its conversation into a shard of the session store. In both cases the substance
|
|
42
43
|
* is already somewhere durable, addressable, and (for the shard) shared with every other view
|
|
43
44
|
* of the same data — the projection a UI subscribes to reads that identical record.
|
|
@@ -60,10 +61,10 @@ export type TaskOutputRef = {
|
|
|
60
61
|
readonly address: string;
|
|
61
62
|
};
|
|
62
63
|
export type TaskOutputLocation =
|
|
63
|
-
/** Redirected on the
|
|
64
|
+
/** Redirected on the environment: `<home>/.operon/tasks/<id>.log` and the like. */
|
|
64
65
|
{
|
|
65
66
|
readonly kind: "file";
|
|
66
|
-
readonly
|
|
67
|
+
readonly environment: Environment;
|
|
67
68
|
readonly path: string;
|
|
68
69
|
}
|
|
69
70
|
/** A sub-agent's own conversation shard, read back and reduced to its latest answer. */
|
|
@@ -102,7 +103,7 @@ export interface BackgroundTask {
|
|
|
102
103
|
readonly toolCallId?: string;
|
|
103
104
|
readonly timeoutMs?: number;
|
|
104
105
|
/** Aborting `sink.signal` is the whole stop protocol — there is no second, harder step.
|
|
105
|
-
* A task that drives a command forwards the signal to `
|
|
106
|
+
* A task that drives a command forwards the signal to `environment.run`, where SIGTERM →
|
|
106
107
|
* grace → SIGKILL escalation lives. */
|
|
107
108
|
start(sink: BackgroundTaskSink): void | Promise<void>;
|
|
108
109
|
toInfo(base: BackgroundTaskInfoBase): BackgroundTaskInfo;
|
|
@@ -79,28 +79,54 @@ export function backgroundOutputTool(manager) {
|
|
|
79
79
|
name: "BackgroundOutput",
|
|
80
80
|
description: [
|
|
81
81
|
"Read a background AGENT's or WORKFLOW's result, taken from where it already lives — a sub-agent's own conversation, a workflow run's journal. Works while it is still running: you get whatever it has produced so far.",
|
|
82
|
-
"- You do NOT need to poll. Every background task
|
|
83
|
-
"- For a background BASH command this returns status only, plus output_path. The command's output is a file on the
|
|
82
|
+
"- You do NOT need to poll, and you do NOT need to stay in the turn. Every background task notifies on its own when it settles — including minutes after the turn that started it has ended, which wakes a new turn by itself. So ending your turn is never how you lose a result: it is the normal way to wait for one. Call this when you want the answer before that notification arrives, or after one tells you the task is done.",
|
|
83
|
+
"- For a background BASH command this returns status only, plus output_path. The command's output is a file on the environment — Read that path instead, which also gives you offset/limit paging over a large log.",
|
|
84
84
|
"- For a background WORKFLOW this returns the run's story from its journal: each phase, each agent's result, any failure, and the final outcome — for a running one, everything so far.",
|
|
85
85
|
"- For a background question this returns the user's answer in full — the place to read the rest when the completion notification truncated it.",
|
|
86
86
|
"- For a terminal task the metadata explains why it ended: status=timed_out when aborted by its deadline, and reason when it was explicitly stopped; terminal_reason is a categorical label (timed_out | stopped | failed). A task that ended on its own emits none of these.",
|
|
87
|
-
"- block=true waits for completion (optional timeout in seconds).
|
|
87
|
+
"- block=true waits for completion (optional timeout in seconds). It costs you the whole turn — the user cannot say anything to you until the task settles or the timeout expires, so a long block locks them out. Justified only when all three hold: the task settles in seconds, nothing and nobody else has to act first, and you have no other work to do. Otherwise read with block=false, say what you are waiting on, and end the turn.",
|
|
88
|
+
"- NEVER block on a task that is waiting for the user — a login/OAuth flow in a browser, a confirmation, anything whose next step is a human action. Blocking there deadlocks the two of you: the user is waiting to see what you say, and you are waiting for the thing only they can finish. End your turn instead, tell them what to do, and read the task when they say they are done.",
|
|
88
89
|
].join("\n"),
|
|
89
90
|
params: z.object({
|
|
90
91
|
task_id: z.string().describe("The background task ID to inspect."),
|
|
91
|
-
block: z
|
|
92
|
-
|
|
92
|
+
block: z
|
|
93
|
+
.boolean()
|
|
94
|
+
.default(false)
|
|
95
|
+
.describe("Hold the turn until the task finishes. Leave false unless you have nothing else to do — never true for a task awaiting user action.")
|
|
96
|
+
.optional(),
|
|
97
|
+
timeout: z
|
|
98
|
+
.number()
|
|
99
|
+
.int()
|
|
100
|
+
.min(0)
|
|
101
|
+
.max(3600)
|
|
102
|
+
.default(30)
|
|
103
|
+
.describe("Max seconds to wait when block=true. The ceiling is high for the rare task worth standing guard over; it is not a suggestion. Past a few seconds the completion notification is the better instrument, so raise this deliberately, not by default.")
|
|
104
|
+
.optional(),
|
|
93
105
|
}),
|
|
94
106
|
resolve: (args) => ({
|
|
95
107
|
...globApproval("BackgroundOutput", args.task_id),
|
|
96
108
|
accesses: ToolAccesses.none(),
|
|
97
109
|
display: { title: `Read output of task ${args.task_id}` },
|
|
98
|
-
run: async () => {
|
|
110
|
+
run: async ({ signal }) => {
|
|
99
111
|
const info = manager.getTask(args.task_id);
|
|
100
112
|
if (!info)
|
|
101
113
|
return text(`Task not found: ${args.task_id}`, true);
|
|
114
|
+
// A question is answered by the user, in the conversation this turn is holding open.
|
|
115
|
+
// Blocking on it is a guaranteed deadlock — the answer cannot arrive until the turn
|
|
116
|
+
// ends, and the turn cannot end while this waits. Refuse rather than burn the timeout.
|
|
117
|
+
if (args.block && info.kind === "question" && !isBackgroundTaskTerminal(info.status)) {
|
|
118
|
+
return text([
|
|
119
|
+
formatTaskInfo(info),
|
|
120
|
+
"",
|
|
121
|
+
"block=true is refused for a pending question: it waits for the user, who cannot answer while this turn is held open.",
|
|
122
|
+
"End your turn instead — the answer arrives as a completion notification.",
|
|
123
|
+
].join("\n"), true);
|
|
124
|
+
}
|
|
125
|
+
// Hand the signal down: a blocking wait can be an hour long, and without it an
|
|
126
|
+
// interrupted turn cannot reclaim this tool — the loop's grace window kills it with a
|
|
127
|
+
// synthetic error instead. With it, an abort returns the task's real status normally.
|
|
102
128
|
if (args.block && !isBackgroundTaskTerminal(info.status)) {
|
|
103
|
-
await manager.wait(args.task_id, (args.timeout ?? 30) * 1000);
|
|
129
|
+
await manager.wait(args.task_id, (args.timeout ?? 30) * 1000, signal);
|
|
104
130
|
}
|
|
105
131
|
const current = manager.getTask(args.task_id);
|
|
106
132
|
if (!current)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A capability's own durable data: a key/value `state` and a stream of named `records` (kept in
|
|
3
|
+
* the session's audit shard, never the conversation), each partitioned by the capability's name. What `SessionContext.state` / `records` / `record` are
|
|
4
|
+
* built from — one `CapabilityData` per session, one view per capability.
|
|
5
|
+
*
|
|
6
|
+
* The partition prefix is `extension:<owner>:`, not `capability:`, on purpose: extensions wrote
|
|
7
|
+
* their state and records under that prefix before they became capabilities, and keeping it is
|
|
8
|
+
* what lets a session written by an extension read back after the extension is a capability.
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentRecord, AgentRecordBody, SessionStore } from "../store/index.ts";
|
|
11
|
+
/** Durable per-capability key/value state (SessionStore-backed; in memory for a storeless session). */
|
|
12
|
+
export interface CapabilityState {
|
|
13
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
14
|
+
set(key: string, value: unknown): Promise<void>;
|
|
15
|
+
delete(key: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** One record a capability wrote with `record(name, data)`, as `records()` hands it back. */
|
|
18
|
+
export interface CapabilityRecord {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly data?: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface CapabilityDataOptions {
|
|
23
|
+
readonly store?: SessionStore;
|
|
24
|
+
/** The session's audit shard, where capability records are kept (see `AUDIT_ADDRESS`). */
|
|
25
|
+
readonly readAudit: () => Promise<readonly AgentRecord[]>;
|
|
26
|
+
/** Write a record to the session's audit shard. */
|
|
27
|
+
readonly append: (body: AgentRecordBody) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare class CapabilityData {
|
|
30
|
+
private readonly store;
|
|
31
|
+
private readonly readAudit;
|
|
32
|
+
private readonly append;
|
|
33
|
+
/** Storeless sessions keep state here, for the session's lifetime. */
|
|
34
|
+
private readonly memoryState;
|
|
35
|
+
/** Records written in THIS session, per owner, in write order. */
|
|
36
|
+
private readonly writes;
|
|
37
|
+
/** Records from earlier processes, per owner — bucketed once, on the first `records()` call. */
|
|
38
|
+
private snapshot;
|
|
39
|
+
/**
|
|
40
|
+
* The line between "earlier" and "this session". A log read taken AFTER a write has been
|
|
41
|
+
* persisted would otherwise return that write a second time, alongside its copy in `writes`.
|
|
42
|
+
*/
|
|
43
|
+
private readonly openedAt;
|
|
44
|
+
constructor(options: CapabilityDataOptions);
|
|
45
|
+
stateFor(owner: string): CapabilityState;
|
|
46
|
+
recordsFor(owner: string): () => Promise<readonly CapabilityRecord[]>;
|
|
47
|
+
recorderFor(owner: string): (name: string, data?: unknown) => void;
|
|
48
|
+
/** One pass over the audit shard buckets every owner's records; owners are colon-free slugs,
|
|
49
|
+
* so the prefix parse is unambiguous. Never a read of the conversation log. */
|
|
50
|
+
private earlier;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=capability-data.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const PREFIX = "extension:";
|
|
2
|
+
export class CapabilityData {
|
|
3
|
+
store;
|
|
4
|
+
readAudit;
|
|
5
|
+
append;
|
|
6
|
+
/** Storeless sessions keep state here, for the session's lifetime. */
|
|
7
|
+
memoryState = new Map();
|
|
8
|
+
/** Records written in THIS session, per owner, in write order. */
|
|
9
|
+
writes = new Map();
|
|
10
|
+
/** Records from earlier processes, per owner — bucketed once, on the first `records()` call. */
|
|
11
|
+
snapshot;
|
|
12
|
+
/**
|
|
13
|
+
* The line between "earlier" and "this session". A log read taken AFTER a write has been
|
|
14
|
+
* persisted would otherwise return that write a second time, alongside its copy in `writes`.
|
|
15
|
+
*/
|
|
16
|
+
openedAt = Date.now();
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.store = options.store;
|
|
19
|
+
this.readAudit = options.readAudit;
|
|
20
|
+
this.append = options.append;
|
|
21
|
+
}
|
|
22
|
+
stateFor(owner) {
|
|
23
|
+
const prefix = `${PREFIX}${owner}:`;
|
|
24
|
+
const store = this.store;
|
|
25
|
+
return {
|
|
26
|
+
get: async (key) => {
|
|
27
|
+
const full = prefix + key;
|
|
28
|
+
return ((store !== undefined ? await store.getState(full) : this.memoryState.get(full)) ?? null);
|
|
29
|
+
},
|
|
30
|
+
set: async (key, value) => {
|
|
31
|
+
const full = prefix + key;
|
|
32
|
+
if (store !== undefined)
|
|
33
|
+
await store.putState(full, value);
|
|
34
|
+
else
|
|
35
|
+
this.memoryState.set(full, value);
|
|
36
|
+
},
|
|
37
|
+
delete: async (key) => {
|
|
38
|
+
const full = prefix + key;
|
|
39
|
+
if (store !== undefined)
|
|
40
|
+
await store.deleteState(full);
|
|
41
|
+
else
|
|
42
|
+
this.memoryState.delete(full);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
recordsFor(owner) {
|
|
47
|
+
return async () => {
|
|
48
|
+
const earlier = (await this.earlier()).get(owner) ?? [];
|
|
49
|
+
return [...earlier, ...(this.writes.get(owner) ?? [])];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
recorderFor(owner) {
|
|
53
|
+
return (name, data) => {
|
|
54
|
+
this.append({ type: "custom", name: `${PREFIX}${owner}:${name}`, data });
|
|
55
|
+
const bucket = this.writes.get(owner) ?? [];
|
|
56
|
+
if (!this.writes.has(owner))
|
|
57
|
+
this.writes.set(owner, bucket);
|
|
58
|
+
bucket.push({ name, ...(data !== undefined ? { data } : {}) });
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** One pass over the audit shard buckets every owner's records; owners are colon-free slugs,
|
|
62
|
+
* so the prefix parse is unambiguous. Never a read of the conversation log. */
|
|
63
|
+
earlier() {
|
|
64
|
+
this.snapshot ??= this.readAudit().then((log) => {
|
|
65
|
+
const buckets = new Map();
|
|
66
|
+
for (const record of log) {
|
|
67
|
+
if (record.type !== "custom" || (record.time ?? 0) >= this.openedAt)
|
|
68
|
+
continue;
|
|
69
|
+
const full = record.name;
|
|
70
|
+
if (typeof full !== "string" || !full.startsWith(PREFIX))
|
|
71
|
+
continue;
|
|
72
|
+
const rest = full.slice(PREFIX.length);
|
|
73
|
+
const sep = rest.indexOf(":");
|
|
74
|
+
if (sep <= 0)
|
|
75
|
+
continue;
|
|
76
|
+
const owner = rest.slice(0, sep);
|
|
77
|
+
const data = record.data;
|
|
78
|
+
const bucket = buckets.get(owner) ?? [];
|
|
79
|
+
if (!buckets.has(owner))
|
|
80
|
+
buckets.set(owner, bucket);
|
|
81
|
+
bucket.push({ name: rest.slice(sep + 1), ...(data !== undefined ? { data } : {}) });
|
|
82
|
+
}
|
|
83
|
+
return buckets;
|
|
84
|
+
});
|
|
85
|
+
return this.snapshot;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=capability-data.js.map
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { AgentRecord, SessionStore } from "../store/index.ts";
|
|
2
2
|
/** The whole linear log in append order, or [] when there is no store / empty session. */
|
|
3
3
|
export declare function readLog(store: SessionStore | undefined): Promise<AgentRecord[]>;
|
|
4
|
-
/** The session's
|
|
5
|
-
* the session shares across capabilities
|
|
4
|
+
/** The session's whole log for a capability that needs history from before the newest
|
|
5
|
+
* checkpoint: prefers the memoized `logRecords` the session shares across capabilities,
|
|
6
6
|
* falling back to a direct `readLog` when it is absent (e.g. a test-constructed context). */
|
|
7
7
|
export declare function readSessionLog(ctx: {
|
|
8
8
|
readonly store?: SessionStore;
|
|
9
9
|
readonly logRecords?: () => Promise<readonly AgentRecord[]>;
|
|
10
10
|
}): Promise<readonly AgentRecord[]>;
|
|
11
|
-
/** The `details` of the latest tool result for `toolName` in the log, or undefined. */
|
|
12
|
-
export declare function latestToolDetails(records: readonly AgentRecord[], toolName: string): unknown;
|
|
13
11
|
//# sourceMappingURL=capability-state.d.ts.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// Capability state
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// durable across resume and, because a fork copies the log, correct after a fork.
|
|
1
|
+
// Capability state is NOT read from the log: a stateful capability keeps its current value in the
|
|
2
|
+
// store's key/value side and restores from it (see `CapabilityDurableState`). The log holds what
|
|
3
|
+
// the model saw. These readers are for a capability that genuinely wants that history.
|
|
5
4
|
/** The whole linear log in append order, or [] when there is no store / empty session. */
|
|
6
5
|
export async function readLog(store) {
|
|
7
6
|
if (store === undefined)
|
|
@@ -11,27 +10,10 @@ export async function readLog(store) {
|
|
|
11
10
|
records.push(record);
|
|
12
11
|
return records;
|
|
13
12
|
}
|
|
14
|
-
/** The session's
|
|
15
|
-
* the session shares across capabilities
|
|
13
|
+
/** The session's whole log for a capability that needs history from before the newest
|
|
14
|
+
* checkpoint: prefers the memoized `logRecords` the session shares across capabilities,
|
|
16
15
|
* falling back to a direct `readLog` when it is absent (e.g. a test-constructed context). */
|
|
17
16
|
export function readSessionLog(ctx) {
|
|
18
17
|
return ctx.logRecords !== undefined ? ctx.logRecords() : readLog(ctx.store);
|
|
19
18
|
}
|
|
20
|
-
/** Tool-result messages for `toolName` in the log, in append order. */
|
|
21
|
-
function toolResultsInLog(records, toolName) {
|
|
22
|
-
const out = [];
|
|
23
|
-
for (const record of records) {
|
|
24
|
-
if (record.type !== "context.append_message")
|
|
25
|
-
continue;
|
|
26
|
-
const msg = record.message;
|
|
27
|
-
if (msg.role === "toolResult" && msg.toolName === toolName)
|
|
28
|
-
out.push(msg);
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
/** The `details` of the latest tool result for `toolName` in the log, or undefined. */
|
|
33
|
-
export function latestToolDetails(records, toolName) {
|
|
34
|
-
const results = toolResultsInLog(records, toolName);
|
|
35
|
-
return results.length === 0 ? undefined : results[results.length - 1].details;
|
|
36
|
-
}
|
|
37
19
|
//# sourceMappingURL=capability-state.js.map
|