operon-agents-core 0.1.0-alpha.3 → 0.1.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- 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/context-report.js +3 -1
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +3 -2
- package/dist/agent/index.js +2 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/lifecycle-recovery.d.ts +15 -0
- package/dist/agent/lifecycle-recovery.js +44 -0
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/profiles.d.ts +3 -0
- package/dist/agent/profiles.js +1 -0
- package/dist/agent/recovery.js +2 -2
- package/dist/agent/run-support.d.ts +3 -3
- package/dist/agent/run-support.js +11 -13
- package/dist/agent/runner.d.ts +33 -22
- package/dist/agent/runner.js +229 -125
- package/dist/agent/session.d.ts +269 -162
- package/dist/agent/session.js +611 -426
- 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 +14 -8
- package/dist/agent/workflow/index.d.ts +1 -1
- package/dist/agent/workflow/index.js +1 -1
- 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/structured.d.ts +2 -0
- package/dist/agent/workflow/structured.js +4 -0
- package/dist/agent/workflow/tool.js +34 -46
- 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/full.js +4 -3
- 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 +2 -6
- package/dist/config/index.js +1 -3
- package/dist/config/merge.js +0 -6
- package/dist/config/resolver.d.ts +0 -3
- package/dist/config/resolver.js +0 -3
- package/dist/config/schema.d.ts +55 -104
- package/dist/config/schema.js +61 -46
- package/dist/events/events.d.ts +43 -12
- 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/decision-model.d.ts +23 -0
- package/dist/llm/decision-model.js +26 -0
- package/dist/llm/define-model.d.ts +28 -26
- package/dist/llm/define-model.js +106 -63
- package/dist/llm/errors.d.ts +0 -3
- package/dist/llm/errors.js +0 -80
- package/dist/llm/index.d.ts +10 -6
- package/dist/llm/index.js +7 -4
- package/dist/llm/model-manager.d.ts +95 -0
- package/dist/llm/model-manager.js +233 -0
- package/dist/llm/model.d.ts +20 -19
- package/dist/llm/provider.d.ts +20 -0
- package/dist/llm/provider.js +17 -0
- package/dist/llm/request-retry.d.ts +18 -0
- package/dist/llm/request-retry.js +93 -0
- package/dist/llm/retry.d.ts +14 -0
- package/dist/llm/retry.js +85 -21
- 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 -14
- package/dist/loop/steer.js +96 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +150 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +30 -8
- 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 +115 -7
- package/dist/mcp/manager.js +298 -30
- 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/provider.js +5 -1
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/mcp/types.d.ts +4 -0
- package/dist/permission/auto-approver/decision-auto-approver.d.ts +45 -0
- package/dist/permission/auto-approver/decision-auto-approver.js +111 -0
- package/dist/permission/auto-approver/index.d.ts +1 -0
- package/dist/permission/auto-approver/index.js +1 -0
- package/dist/permission/auto-approver/llm-auto-approver.d.ts +1 -1
- package/dist/permission/auto-approver/llm-auto-approver.js +10 -6
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/index.d.ts +1 -1
- package/dist/permission/index.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/protocol/tool-schema.d.ts +6 -0
- 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 +30 -14
- 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 -38
- 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 +43 -22
- 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 +59 -9
- 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/config/model-catalog.d.ts +0 -17
- package/dist/config/model-catalog.js +0 -37
- package/dist/config/provider-manager.d.ts +0 -57
- package/dist/config/provider-manager.js +0 -344
- package/dist/llm/runtime.d.ts +0 -25
- package/dist/llm/runtime.js +0 -38
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
package/README.md
CHANGED
|
@@ -5,3 +5,16 @@ Internal engine for `operon-agents`.
|
|
|
5
5
|
Application code should import from `operon-agents`. This package intentionally
|
|
6
6
|
contains lower-level runtime, loop, permission, storage, and capability modules
|
|
7
7
|
that may change as the engine evolves.
|
|
8
|
+
|
|
9
|
+
## Execution recovery
|
|
10
|
+
|
|
11
|
+
`Runner.run` and `runStream` reconcile abandoned lifecycle frames before a Session's
|
|
12
|
+
first fresh run, under its run lock and any configured `SessionLock`. Durable
|
|
13
|
+
approval/input pauses remain resumable through `Runner.resume`. `Session.open`
|
|
14
|
+
alone never closes unfinished turns: opening is not proof that another executor died.
|
|
15
|
+
|
|
16
|
+
Hosts can call `recoverOrphanedTurns` without opening a Session, or
|
|
17
|
+
`closeOrphanedTurns` to receive the committed repair events for broadcasting.
|
|
18
|
+
Both require exclusive execution ownership. For stores shared across processes,
|
|
19
|
+
provide a distributed lock to Runner or acquire a host-managed lease before takeover.
|
|
20
|
+
Recovery closes orphan frames; it does not retry tools with unknown side effects.
|
package/dist/agent/agent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChatModel } from "../llm/define-model.ts";
|
|
2
2
|
import type { ModelSettings } from "../llm/model.ts";
|
|
3
3
|
import type { Tool } from "../tool/types.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Environment } from "../tool/environment.ts";
|
|
5
5
|
import type { Handoff } from "./handoff.ts";
|
|
6
6
|
import type { InputGuardrail, OutputGuardrail, ToolInputGuardrail, ToolOutputGuardrail } from "./guardrail.ts";
|
|
7
7
|
import type { SystemPromptContext } from "./instruction-context.ts";
|
|
@@ -10,8 +10,8 @@ export interface AgentRunContext<TContext = unknown> {
|
|
|
10
10
|
readonly address: string;
|
|
11
11
|
readonly signal: AbortSignal;
|
|
12
12
|
readonly context?: TContext;
|
|
13
|
-
/**
|
|
14
|
-
readonly
|
|
13
|
+
/** Environment of the current runtime frame (root/subagent/worktree), never captured by Agent. */
|
|
14
|
+
readonly environment?: Environment;
|
|
15
15
|
/** Lazily resolves Session-cached environment + AGENTS.md data for this runtime frame. */
|
|
16
16
|
readonly resolveSystemPromptContext?: () => Promise<SystemPromptContext>;
|
|
17
17
|
}
|
|
@@ -38,10 +38,11 @@ export interface AgentConfig<TContext = unknown> {
|
|
|
38
38
|
readonly outputType?: unknown;
|
|
39
39
|
readonly maxStepsPerTurn?: number;
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
41
|
+
* Capability/MCP tools are discovered on demand through SearchTool; only loaded ones are
|
|
42
|
+
* sent to the model, so the catalog can change mid-conversation without touching the
|
|
43
|
+
* request prefix. On models with native deferred-tool support (Anthropic tool_reference,
|
|
44
|
+
* Kimi, OpenAI tool search) pi also keeps a loaded definition out of the prefix. Default:
|
|
45
|
+
* on for those models, off elsewhere. `false` loads capability tools up front.
|
|
45
46
|
*/
|
|
46
47
|
readonly deferTools?: boolean;
|
|
47
48
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { LoopHooks } from "../loop/types.ts";
|
|
2
2
|
import type { Tool } from "../tool/types.ts";
|
|
3
|
+
import type { LlmRequest } from "../llm/model.ts";
|
|
4
|
+
import type { CapabilityProviderHooks, ProviderHookContext } from "../capabilities/capability.ts";
|
|
3
5
|
import type { ConversationContext } from "../loop/context.ts";
|
|
4
6
|
import type { Agent } from "./agent.ts";
|
|
5
7
|
import type { RunState } from "./runner.ts";
|
|
@@ -8,6 +10,13 @@ import type { RunState } from "./runner.ts";
|
|
|
8
10
|
* (compaction beforeStep/afterStep …) → permission authorizer (single) → tool guardrails.
|
|
9
11
|
* Extracted from the Engine; only TYPES are imported from `runner.ts`.
|
|
10
12
|
*/
|
|
11
|
-
export declare function buildRunHooks<TContext>(active: Agent<TContext>, state: RunState<TContext>, context: ConversationContext, tools: readonly Tool[]): LoopHooks;
|
|
13
|
+
export declare function buildRunHooks<TContext>(active: Agent<TContext>, state: RunState<TContext>, context: ConversationContext, tools: readonly Tool[] | (() => readonly Tool[])): LoopHooks;
|
|
14
|
+
/**
|
|
15
|
+
* Fold every capability's provider hooks into the request's `providerOptions` callbacks — the
|
|
16
|
+
* only way to reach them, since the provider layer invokes them from inside its HTTP path. A
|
|
17
|
+
* callback already on the request (set by a `beforeModelRequest` hook) runs FIRST and is kept,
|
|
18
|
+
* so nothing that wrote `providerOptions` directly is silently replaced.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withProviderHooks(request: LlmRequest, hooks: readonly CapabilityProviderHooks[], ctx: ProviderHookContext): LlmRequest;
|
|
12
21
|
export declare function composeLoopHooks(parts: ReadonlyArray<Partial<LoopHooks> | undefined>): LoopHooks;
|
|
13
22
|
//# sourceMappingURL=compose-hooks.d.ts.map
|
|
@@ -9,6 +9,14 @@ import { withToolCallRecoveryContext } from "./recovery.js";
|
|
|
9
9
|
export function buildRunHooks(active, state, context, tools) {
|
|
10
10
|
const ctx = runCtxFor(state);
|
|
11
11
|
const parts = [...state.capabilities.loopHookParts];
|
|
12
|
+
const providerHooks = state.capabilities.providerHooks;
|
|
13
|
+
if (providerHooks.length > 0) {
|
|
14
|
+
parts.push({
|
|
15
|
+
beforeModelRequest: async ({ request, turnId, stepNumber, address }) => ({
|
|
16
|
+
request: withProviderHooks(request, providerHooks, { turnId, stepNumber, ...(address !== undefined ? { address } : {}) }),
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
12
20
|
parts.push({ authorizeToolExecution: buildAuthorizer(state, context, tools) });
|
|
13
21
|
if (active.guardrails.toolInput && active.guardrails.toolInput.length > 0) {
|
|
14
22
|
parts.push({ prepareToolExecution: toolInputGuardrailHook(active, ctx, active.guardrails.toolInput) });
|
|
@@ -26,21 +34,68 @@ export function buildRunHooks(active, state, context, tools) {
|
|
|
26
34
|
});
|
|
27
35
|
return composeLoopHooks(parts);
|
|
28
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Fold every capability's provider hooks into the request's `providerOptions` callbacks — the
|
|
39
|
+
* only way to reach them, since the provider layer invokes them from inside its HTTP path. A
|
|
40
|
+
* callback already on the request (set by a `beforeModelRequest` hook) runs FIRST and is kept,
|
|
41
|
+
* so nothing that wrote `providerOptions` directly is silently replaced.
|
|
42
|
+
*/
|
|
43
|
+
export function withProviderHooks(request, hooks, ctx) {
|
|
44
|
+
const options = { ...request.providerOptions };
|
|
45
|
+
const headerHooks = hooks.map((h) => h.headers).filter(isDefined);
|
|
46
|
+
const payloadHooks = hooks.map((h) => h.payload).filter(isDefined);
|
|
47
|
+
const responseHooks = hooks.map((h) => h.response).filter(isDefined);
|
|
48
|
+
if (headerHooks.length > 0) {
|
|
49
|
+
const prior = options.transformHeaders;
|
|
50
|
+
options.transformHeaders = async (headers) => {
|
|
51
|
+
let current = prior !== undefined ? await prior(headers) : headers;
|
|
52
|
+
for (const hook of headerHooks)
|
|
53
|
+
current = (await hook(current, ctx)) ?? current;
|
|
54
|
+
return current;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (payloadHooks.length > 0) {
|
|
58
|
+
const prior = options.onPayload;
|
|
59
|
+
options.onPayload = async (payload) => {
|
|
60
|
+
let current = prior !== undefined ? await prior(payload) : payload;
|
|
61
|
+
for (const hook of payloadHooks) {
|
|
62
|
+
const result = await hook(current, ctx);
|
|
63
|
+
if (result !== undefined && result !== null)
|
|
64
|
+
current = result.payload;
|
|
65
|
+
}
|
|
66
|
+
return current;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (responseHooks.length > 0) {
|
|
70
|
+
const prior = options.onResponse;
|
|
71
|
+
options.onResponse = async (response) => {
|
|
72
|
+
if (prior !== undefined)
|
|
73
|
+
await prior(response);
|
|
74
|
+
for (const hook of responseHooks)
|
|
75
|
+
await hook(response, ctx);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { ...request, providerOptions: options };
|
|
79
|
+
}
|
|
29
80
|
function buildAuthorizer(state, context, tools) {
|
|
30
81
|
// The `auto`-mode judge needs THIS frame's live transcript + tool registry (the authorize
|
|
31
82
|
// ctx carries neither). Bind them per turn as closure state — the manager is a session
|
|
32
83
|
// singleton shared by concurrent frames, so they must never be stored on it.
|
|
33
|
-
const base = state.permission.authorizerFor({ getTranscript: () => context.messages, getTools: () => tools });
|
|
34
|
-
const answers = state.answers;
|
|
35
|
-
if (!answers)
|
|
36
|
-
return base;
|
|
84
|
+
const base = state.permission.authorizerFor({ getTranscript: () => context.messages, getTools: typeof tools === "function" ? tools : () => tools });
|
|
37
85
|
return async (ctx) => {
|
|
38
|
-
|
|
86
|
+
// Read at call time, not captured: a nested call (`ToolRunContext.dispatch`) may add an
|
|
87
|
+
// answer while the batch runs.
|
|
88
|
+
const answer = state.answers?.[ctx.toolCall.id];
|
|
39
89
|
if (answer) {
|
|
40
90
|
// Audit record: this is the single chokepoint both live and durable approvals
|
|
41
91
|
// flow through (the responder/resume answer is applied here).
|
|
42
|
-
context.
|
|
92
|
+
context.audit({ type: "permission.record_approval", toolCallId: ctx.toolCall.id, toolName: ctx.toolCall.name, decision: answer.decision, feedback: answer.feedback, approvalRule: ctx.plan.approvalRule, scope: answer.scope });
|
|
93
|
+
// That record is this frame's audit trail. A session grant is the SESSION's state, so the
|
|
94
|
+
// session persists it — what a reopen restores from — whichever frame earned it.
|
|
95
|
+
const grants = answer.decision === "approved" && answer.scope === "session" && !state.permission.sessionGrants.includes(ctx.plan.approvalRule);
|
|
43
96
|
const ok = state.permission.applyApproval(ctx.plan.approvalRule, answer);
|
|
97
|
+
if (grants)
|
|
98
|
+
state.session.persistPermissionState();
|
|
44
99
|
if (ok)
|
|
45
100
|
return undefined;
|
|
46
101
|
return { block: true, reason: answer.feedback ?? `Tool ${ctx.toolCall.name} was ${answer.decision}.` };
|
|
@@ -40,7 +40,7 @@ export function defaultSpawnConcurrency() {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* One limiter per session. Keyed off the session port (not the frame) because a run's frames come
|
|
43
|
-
* and go while the session is what actually owns the
|
|
43
|
+
* and go while the session is what actually owns the environment's capacity; a session holds its run
|
|
44
44
|
* lock, so this bounds the whole tree beneath one prompt.
|
|
45
45
|
*/
|
|
46
46
|
const perSession = new WeakMap();
|
|
@@ -42,13 +42,13 @@ export interface ContextBreakdown {
|
|
|
42
42
|
readonly compactBuffer: ContextSlice;
|
|
43
43
|
/** contextWindow − used − compactBuffer, clamped at 0. */
|
|
44
44
|
readonly free: ContextSlice;
|
|
45
|
-
/** Epoch ms the snapshot was taken (turn boundary). */
|
|
45
|
+
/** Epoch ms the snapshot was taken (turn boundary, then each step's request). */
|
|
46
46
|
readonly capturedAt: number;
|
|
47
47
|
}
|
|
48
48
|
export interface ComputeContextBreakdownInput {
|
|
49
49
|
readonly model: ChatModel;
|
|
50
50
|
readonly system: string | undefined;
|
|
51
|
-
readonly tools: readonly Tool[];
|
|
51
|
+
readonly tools: readonly Pick<Tool, "schema">[];
|
|
52
52
|
readonly messages: readonly Message[];
|
|
53
53
|
/** Per-injector token estimates captured while injecting at the turn boundary. */
|
|
54
54
|
readonly injectionTokens: ReadonlyMap<string, number>;
|
|
@@ -8,7 +8,9 @@ export function computeContextBreakdown(input) {
|
|
|
8
8
|
let builtinTools = 0;
|
|
9
9
|
let mcpTools = 0;
|
|
10
10
|
for (const tool of input.tools) {
|
|
11
|
-
|
|
11
|
+
// What goes on the wire: `outputSchema` is for programs calling the tool, never sent to the model.
|
|
12
|
+
const { outputSchema: _programOnly, ...sent } = tool.schema;
|
|
13
|
+
const tokens = estimateTokens(JSON.stringify(sent));
|
|
12
14
|
if (isMcpToolName(tool.schema.name))
|
|
13
15
|
mcpTools += tokens;
|
|
14
16
|
else
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Logger } from "../logging/index.ts";
|
|
2
|
+
import type { SessionStore, StateKey } from "../store/index.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Writes current-state values to the store's key/value side, one key at a time.
|
|
5
|
+
*
|
|
6
|
+
* A write reads its value (`read()`) when it RUNS, not when it is asked for, so asking again
|
|
7
|
+
* while a write is waiting to start changes nothing — that write will carry the newer value —
|
|
8
|
+
* and writes for one key land in the order they were asked for. Nothing here touches the log.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DurableStateWriter {
|
|
11
|
+
private readonly slots;
|
|
12
|
+
private readonly store;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
constructor(store: SessionStore | undefined, logger: Logger);
|
|
15
|
+
/** Store `read()` under `key` (null/undefined removes it). See the class doc for ordering. */
|
|
16
|
+
write(key: StateKey, read: () => unknown): Promise<void>;
|
|
17
|
+
/** Settles once every write asked for `key` so far has finished (succeeded or failed). */
|
|
18
|
+
settled(key: StateKey): Promise<void>;
|
|
19
|
+
/** Settles once every write asked for so far has finished (succeeded or failed). */
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=durable-state.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes current-state values to the store's key/value side, one key at a time.
|
|
3
|
+
*
|
|
4
|
+
* A write reads its value (`read()`) when it RUNS, not when it is asked for, so asking again
|
|
5
|
+
* while a write is waiting to start changes nothing — that write will carry the newer value —
|
|
6
|
+
* and writes for one key land in the order they were asked for. Nothing here touches the log.
|
|
7
|
+
*/
|
|
8
|
+
export class DurableStateWriter {
|
|
9
|
+
slots = new Map();
|
|
10
|
+
store;
|
|
11
|
+
logger;
|
|
12
|
+
constructor(store, logger) {
|
|
13
|
+
this.store = store;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
/** Store `read()` under `key` (null/undefined removes it). See the class doc for ordering. */
|
|
17
|
+
write(key, read) {
|
|
18
|
+
const store = this.store;
|
|
19
|
+
if (store === undefined)
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
let slot = this.slots.get(key);
|
|
22
|
+
if (slot === undefined) {
|
|
23
|
+
slot = { tail: Promise.resolve(), waiting: undefined };
|
|
24
|
+
this.slots.set(key, slot);
|
|
25
|
+
}
|
|
26
|
+
if (slot.waiting !== undefined)
|
|
27
|
+
return slot.waiting;
|
|
28
|
+
const current = slot;
|
|
29
|
+
const write = current.tail.then(async () => {
|
|
30
|
+
// Running now: a change from here on must be carried by a write after this one.
|
|
31
|
+
current.waiting = undefined;
|
|
32
|
+
const value = read();
|
|
33
|
+
if (value === undefined || value === null)
|
|
34
|
+
await store.deleteState(key);
|
|
35
|
+
else
|
|
36
|
+
await store.putState(key, value);
|
|
37
|
+
});
|
|
38
|
+
current.waiting = write;
|
|
39
|
+
current.tail = write.catch(() => undefined);
|
|
40
|
+
write.catch((error) => {
|
|
41
|
+
this.logger.log("warn", `failed to persist state "${key}"`, { error: error instanceof Error ? error.message : String(error) });
|
|
42
|
+
});
|
|
43
|
+
return write;
|
|
44
|
+
}
|
|
45
|
+
/** Settles once every write asked for `key` so far has finished (succeeded or failed). */
|
|
46
|
+
settled(key) {
|
|
47
|
+
return this.slots.get(key)?.tail ?? Promise.resolve();
|
|
48
|
+
}
|
|
49
|
+
/** Settles once every write asked for so far has finished (succeeded or failed). */
|
|
50
|
+
async flush() {
|
|
51
|
+
await Promise.all([...this.slots.values()].map((slot) => slot.tail));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=durable-state.js.map
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export { composeLoopHooks } from "./compose-hooks.ts";
|
|
|
8
8
|
/** Agent profile + session runtime → the params one request carries. Exported so embedders
|
|
9
9
|
* that drive `runTurn` directly resolve precedence the same way the Runner does. */
|
|
10
10
|
export { resolveModelParams } from "./run-support.ts";
|
|
11
|
-
export {
|
|
12
|
-
export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions,
|
|
11
|
+
export { Session, newSessionId } from "./session.ts";
|
|
12
|
+
export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions, SessionOpenOptions, SessionPort, } from "./session.ts";
|
|
13
13
|
export { newAgentId } from "./subagent.ts";
|
|
14
14
|
export type { SubagentRecord, SubagentStatus, AgentSpawnDetails } from "./subagent.ts";
|
|
15
15
|
export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.ts";
|
|
@@ -22,4 +22,5 @@ export type { ContextBreakdown, ContextSlice, ContextInjectionSlice, ComputeCont
|
|
|
22
22
|
export { Runner } from "./runner.ts";
|
|
23
23
|
export type { AgentInput, ResumeInput, RunInterruption, RunnerConfig, RunOptions, RunResult, RunStatus, } from "./runner.ts";
|
|
24
24
|
export * from "./workflow/index.ts";
|
|
25
|
+
export { closeOrphanedTurns, recoverOrphanedTurns } from "./lifecycle-recovery.ts";
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/agent/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { composeLoopHooks } from "./compose-hooks.js";
|
|
|
5
5
|
/** Agent profile + session runtime → the params one request carries. Exported so embedders
|
|
6
6
|
* that drive `runTurn` directly resolve precedence the same way the Runner does. */
|
|
7
7
|
export { resolveModelParams } from "./run-support.js";
|
|
8
|
-
export {
|
|
8
|
+
export { Session, newSessionId } from "./session.js";
|
|
9
9
|
export { newAgentId } from "./subagent.js";
|
|
10
10
|
export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.js";
|
|
11
11
|
export { DEFAULT_AGENT_PROFILES, DEFAULT_AGENT_PROFILE_NAME, DEFAULT_SUBAGENT_NAMES } from "./profile-builtins.js";
|
|
@@ -16,4 +16,5 @@ export { Runner } from "./runner.js";
|
|
|
16
16
|
// Workflow engine (the deterministic subagent-orchestration runtime) + its manager
|
|
17
17
|
// and snapshot/journal layers, exposed so upper layers can integrate programmatically.
|
|
18
18
|
export * from "./workflow/index.js";
|
|
19
|
+
export { closeOrphanedTurns, recoverOrphanedTurns } from "./lifecycle-recovery.js";
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../tool/environment.ts";
|
|
2
2
|
/** Runtime-only values used to render a profile system prompt. */
|
|
3
3
|
export interface SystemPromptContext {
|
|
4
4
|
readonly osKind: string;
|
|
@@ -13,20 +13,20 @@ export interface SystemPromptContext {
|
|
|
13
13
|
}
|
|
14
14
|
/** Format a date without adding a timezone conversion that could move it to another day. */
|
|
15
15
|
export declare function formatSystemPromptDate(date: Date): string;
|
|
16
|
-
/** Build the environment portion of a profile prompt from the active runtime
|
|
17
|
-
export declare function prepareSystemPromptContext(
|
|
16
|
+
/** Build the environment portion of a profile prompt from the active runtime environment. */
|
|
17
|
+
export declare function prepareSystemPromptContext(environment: Environment, now?: string, cwd?: string): Promise<SystemPromptContext>;
|
|
18
18
|
/**
|
|
19
19
|
* Live-Session cache for system-prompt environment data.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
* separates differently rooted frames backed by the same
|
|
21
|
+
* Environment object identity separates independent local/remote/worktree runtimes; normalized cwd
|
|
22
|
+
* separates differently rooted frames backed by the same environment. Promise values also coalesce
|
|
23
23
|
* concurrent root/subagent reads. Nothing here is persisted, timed, or checked every turn.
|
|
24
24
|
*/
|
|
25
25
|
export declare class SystemPromptContextCache {
|
|
26
26
|
private readonly sessionDate;
|
|
27
27
|
private readonly entries;
|
|
28
28
|
constructor(createdAt?: Date);
|
|
29
|
-
resolve(
|
|
29
|
+
resolve(environment: Environment, revision?: number): Promise<SystemPromptContext>;
|
|
30
30
|
/** Release runtime references when the owning Session closes. */
|
|
31
31
|
clear(): void;
|
|
32
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, join } from "pathe";
|
|
2
|
-
import { readTextFile } from "../tool/support/
|
|
2
|
+
import { readTextFile } from "../tool/support/environment-ops.js";
|
|
3
3
|
const AGENTS_MD_MAX_CHARS = 32 * 1024;
|
|
4
4
|
/** Format a date without adding a timezone conversion that could move it to another day. */
|
|
5
5
|
export function formatSystemPromptDate(date) {
|
|
@@ -8,23 +8,23 @@ export function formatSystemPromptDate(date) {
|
|
|
8
8
|
const day = String(date.getDate()).padStart(2, "0");
|
|
9
9
|
return `${year}-${month}-${day}`;
|
|
10
10
|
}
|
|
11
|
-
/** Build the environment portion of a profile prompt from the active runtime
|
|
12
|
-
export async function prepareSystemPromptContext(
|
|
11
|
+
/** Build the environment portion of a profile prompt from the active runtime environment. */
|
|
12
|
+
export async function prepareSystemPromptContext(environment, now = formatSystemPromptDate(new Date()), cwd = environment.normpath(environment.getcwd())) {
|
|
13
13
|
return {
|
|
14
|
-
osKind:
|
|
15
|
-
osArch:
|
|
16
|
-
osVersion:
|
|
17
|
-
shell: `${
|
|
14
|
+
osKind: environment.osInfo.osKind,
|
|
15
|
+
osArch: environment.osInfo.osArch,
|
|
16
|
+
osVersion: environment.osInfo.osVersion,
|
|
17
|
+
shell: `${environment.osInfo.shellName} (${environment.osInfo.shellPath})`,
|
|
18
18
|
now,
|
|
19
19
|
cwd,
|
|
20
|
-
agentsMd: await loadAgentsMd(
|
|
20
|
+
agentsMd: await loadAgentsMd(environment, cwd),
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Live-Session cache for system-prompt environment data.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
* separates differently rooted frames backed by the same
|
|
26
|
+
* Environment object identity separates independent local/remote/worktree runtimes; normalized cwd
|
|
27
|
+
* separates differently rooted frames backed by the same environment. Promise values also coalesce
|
|
28
28
|
* concurrent root/subagent reads. Nothing here is persisted, timed, or checked every turn.
|
|
29
29
|
*/
|
|
30
30
|
export class SystemPromptContextCache {
|
|
@@ -33,17 +33,17 @@ export class SystemPromptContextCache {
|
|
|
33
33
|
constructor(createdAt = new Date()) {
|
|
34
34
|
this.sessionDate = formatSystemPromptDate(createdAt);
|
|
35
35
|
}
|
|
36
|
-
resolve(
|
|
37
|
-
const cwd =
|
|
38
|
-
let byCwd = this.entries.get(
|
|
36
|
+
resolve(environment, revision = 0) {
|
|
37
|
+
const cwd = environment.normpath(environment.getcwd());
|
|
38
|
+
let byCwd = this.entries.get(environment);
|
|
39
39
|
if (byCwd === undefined) {
|
|
40
40
|
byCwd = new Map();
|
|
41
|
-
this.entries.set(
|
|
41
|
+
this.entries.set(environment, byCwd);
|
|
42
42
|
}
|
|
43
43
|
const cached = byCwd.get(cwd);
|
|
44
44
|
if (cached?.revision === revision)
|
|
45
45
|
return cached.value;
|
|
46
|
-
const value = prepareSystemPromptContext(
|
|
46
|
+
const value = prepareSystemPromptContext(environment, this.sessionDate, cwd).catch((error) => {
|
|
47
47
|
if (byCwd?.get(cwd)?.value === value)
|
|
48
48
|
byCwd.delete(cwd);
|
|
49
49
|
throw error;
|
|
@@ -57,13 +57,13 @@ export class SystemPromptContextCache {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
/** Collect AGENTS.md from the user dir then filesystem root→cwd (nearest appended last). */
|
|
60
|
-
async function loadAgentsMd(
|
|
61
|
-
const paths = agentsMdPaths(
|
|
60
|
+
async function loadAgentsMd(environment, cwd) {
|
|
61
|
+
const paths = agentsMdPaths(environment, cwd);
|
|
62
62
|
// Reads are independent. Keep result order deterministic while avoiding a serial RPC walk on
|
|
63
|
-
// remote
|
|
63
|
+
// remote environments.
|
|
64
64
|
const files = await Promise.all(paths.map(async (path) => {
|
|
65
65
|
try {
|
|
66
|
-
const text = (await readTextFile(
|
|
66
|
+
const text = (await readTextFile(environment, path)).slice(0, AGENTS_MD_MAX_CHARS).trim();
|
|
67
67
|
return text.length > 0 ? { path, text } : undefined;
|
|
68
68
|
}
|
|
69
69
|
catch {
|
|
@@ -75,10 +75,10 @@ async function loadAgentsMd(machine, cwd) {
|
|
|
75
75
|
.map((file) => `# ${file.path}\n${file.text}`)
|
|
76
76
|
.join("\n\n");
|
|
77
77
|
}
|
|
78
|
-
function agentsMdPaths(
|
|
79
|
-
const candidates = [join(
|
|
78
|
+
function agentsMdPaths(environment, cwd) {
|
|
79
|
+
const candidates = [join(environment.gethome(), ".agents", "AGENTS.md")];
|
|
80
80
|
const dirs = [];
|
|
81
|
-
let current =
|
|
81
|
+
let current = environment.normpath(cwd);
|
|
82
82
|
for (;;) {
|
|
83
83
|
dirs.unshift(current);
|
|
84
84
|
const parent = dirname(current);
|
|
@@ -90,7 +90,7 @@ function agentsMdPaths(machine, cwd) {
|
|
|
90
90
|
candidates.push(join(dir, "AGENTS.md"));
|
|
91
91
|
const seen = new Set();
|
|
92
92
|
return candidates.filter((path) => {
|
|
93
|
-
const key =
|
|
93
|
+
const key = environment.normpath(path);
|
|
94
94
|
if (seen.has(key))
|
|
95
95
|
return false;
|
|
96
96
|
seen.add(key);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AgentEvent } from "../events/index.ts";
|
|
2
|
+
import type { AgentRecord, SessionStore } from "../store/index.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Close lifecycle frames abandoned by a previous executor, preserving durable pauses.
|
|
5
|
+
* The host MUST establish exclusive execution ownership before calling this function.
|
|
6
|
+
* It does not acquire a lease: an open turn alone is never evidence of a dead executor.
|
|
7
|
+
* Repeated calls under that ownership are idempotent, including after a partial write.
|
|
8
|
+
* A supplied log must be read under the same ownership and include every shard's tail.
|
|
9
|
+
* Returns committed records; a raw store does not broadcast them to live observers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function recoverOrphanedTurns(sessionId: string, store: SessionStore, records?: readonly AgentRecord[]): Promise<AgentRecord[]>;
|
|
12
|
+
/** Host-facing recovery with projected events to broadcast after durable writes. Same
|
|
13
|
+
* exclusive-ownership requirement as recoverOrphanedTurns; no Session needs to be opened. */
|
|
14
|
+
export declare function closeOrphanedTurns(sessionId: string, store: SessionStore): Promise<readonly AgentEvent[]>;
|
|
15
|
+
//# sourceMappingURL=lifecycle-recovery.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SessionProjection, readSessionTails } from "../events/projection.js";
|
|
2
|
+
import { agentEventFromRecord, newAgentEventId } from "../events/index.js";
|
|
3
|
+
import { INTERRUPTION_STATE_KEY } from "../loop/interruption.js";
|
|
4
|
+
/**
|
|
5
|
+
* Close lifecycle frames abandoned by a previous executor, preserving durable pauses.
|
|
6
|
+
* The host MUST establish exclusive execution ownership before calling this function.
|
|
7
|
+
* It does not acquire a lease: an open turn alone is never evidence of a dead executor.
|
|
8
|
+
* Repeated calls under that ownership are idempotent, including after a partial write.
|
|
9
|
+
* A supplied log must be read under the same ownership and include every shard's tail.
|
|
10
|
+
* Returns committed records; a raw store does not broadcast them to live observers.
|
|
11
|
+
*/
|
|
12
|
+
export async function recoverOrphanedTurns(sessionId, store, records) {
|
|
13
|
+
if (await store.getState(INTERRUPTION_STATE_KEY) !== null)
|
|
14
|
+
return [];
|
|
15
|
+
// Reuse the core checkpoint/lifecycle reducer, without history or live subscriptions.
|
|
16
|
+
const frames = new SessionProjection(sessionId, { history: false });
|
|
17
|
+
for (const record of records ?? await readSessionTails(store))
|
|
18
|
+
frames.applyRecord(record);
|
|
19
|
+
const recovered = [];
|
|
20
|
+
for (const agent of frames.snapshot({ maxMessages: 0 }).agents) {
|
|
21
|
+
if (agent.turn !== undefined) {
|
|
22
|
+
await append(agent.address, { type: "turn.ended", turnId: agent.turn.turnId, reason: "failed" });
|
|
23
|
+
}
|
|
24
|
+
if (agent.live && agent.agent !== undefined) {
|
|
25
|
+
await append(agent.address, { type: "agent.ended", agent: agent.agent });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return recovered;
|
|
29
|
+
async function append(address, event) {
|
|
30
|
+
const record = { type: "event.lifecycle", eventId: newAgentEventId(), time: Date.now(), address, event };
|
|
31
|
+
await store.appendRecord(record);
|
|
32
|
+
recovered.push(record);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Host-facing recovery with projected events to broadcast after durable writes. Same
|
|
36
|
+
* exclusive-ownership requirement as recoverOrphanedTurns; no Session needs to be opened. */
|
|
37
|
+
export async function closeOrphanedTurns(sessionId, store) {
|
|
38
|
+
const records = await recoverOrphanedTurns(sessionId, store);
|
|
39
|
+
return records.flatMap((record) => {
|
|
40
|
+
const event = agentEventFromRecord(record, sessionId);
|
|
41
|
+
return event === undefined ? [] : [event];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=lifecycle-recovery.js.map
|
|
@@ -73,7 +73,7 @@ whenToUse: |
|
|
|
73
73
|
Delegate non-trivial software-engineering work (reading files, editing code, running commands) that should return a compact but technically complete summary to the parent agent.
|
|
74
74
|
promptVars:
|
|
75
75
|
roleAdditional: |
|
|
76
|
-
You are running as a subagent. Every user message comes from the parent agent, which sees only your final message — not your intermediate context. Treat the parent as your caller: do not ask the end user questions;
|
|
76
|
+
You are running as a subagent. Every user message comes from the parent agent, which sees only your final message — not your intermediate context. Treat the parent as your caller: do not ask the end user questions; environment any ambiguity in your final summary instead.
|
|
77
77
|
tools:
|
|
78
78
|
- Read
|
|
79
79
|
- Write
|
package/dist/agent/profiles.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { ChatModel } from "../llm/define-model.ts";
|
|
3
|
+
import type { ModelSettings } from "../llm/model.ts";
|
|
3
4
|
import type { Tool } from "../tool/types.ts";
|
|
4
5
|
import { Agent } from "./agent.ts";
|
|
5
6
|
import type { SystemPromptContext } from "./instruction-context.ts";
|
|
@@ -61,6 +62,8 @@ export interface BuildAgentOptions {
|
|
|
61
62
|
* `Agent.maxStepsPerTurn`. Lets a host vary the cap per agent (and so per session) without
|
|
62
63
|
* standing up a second Runner. */
|
|
63
64
|
readonly maxStepsPerTurn?: number;
|
|
65
|
+
/** How the built agent's model should behave. See `Agent.modelSettings`. */
|
|
66
|
+
readonly modelSettings?: ModelSettings;
|
|
64
67
|
}
|
|
65
68
|
/** Turn a resolved profile into a runnable Agent whose system prompt renders from live context. */
|
|
66
69
|
export declare function buildAgentFromProfile<TContext = unknown>(profile: ResolvedAgentProfile, options?: BuildAgentOptions): Promise<Agent<TContext>>;
|
package/dist/agent/profiles.js
CHANGED
|
@@ -166,6 +166,7 @@ export async function buildAgentFromProfile(profile, options = {}) {
|
|
|
166
166
|
model,
|
|
167
167
|
tools: toolset,
|
|
168
168
|
...(options.maxStepsPerTurn !== undefined ? { maxStepsPerTurn: options.maxStepsPerTurn } : {}),
|
|
169
|
+
...(options.modelSettings !== undefined ? { modelSettings: options.modelSettings } : {}),
|
|
169
170
|
handoffDescription: profile.whenToUse ?? profile.description,
|
|
170
171
|
});
|
|
171
172
|
}
|
package/dist/agent/recovery.js
CHANGED
|
@@ -46,9 +46,9 @@ export async function withToolCallRecoveryContext(state, request) {
|
|
|
46
46
|
const reminder = lines.join("\n");
|
|
47
47
|
return {
|
|
48
48
|
...request,
|
|
49
|
-
|
|
49
|
+
systemPrompt: request.systemPrompt === undefined || request.systemPrompt.length === 0
|
|
50
50
|
? reminder
|
|
51
|
-
: `${request.
|
|
51
|
+
: `${request.systemPrompt}\n\n${reminder}`,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
function findBackgroundByOrigin(value, parentAddress, toolCallId) {
|
|
@@ -9,7 +9,7 @@ import type { AssistantMessage, Message } from "../protocol/index.ts";
|
|
|
9
9
|
import type { ModelSettings, ThinkingLevel } from "../llm/model.ts";
|
|
10
10
|
import type { AgentEventBody, EventSink } from "../events/index.ts";
|
|
11
11
|
import type { ConversationContext, HistoryChangeListener } from "../loop/context.ts";
|
|
12
|
-
import type { AgentRunContext } from "./agent.ts";
|
|
12
|
+
import type { Agent, AgentRunContext } from "./agent.ts";
|
|
13
13
|
import type { DeriveOptions, RunState, RunStatus } from "./runner.ts";
|
|
14
14
|
import type { TurnStopReason } from "../loop/types.ts";
|
|
15
15
|
/**
|
|
@@ -55,11 +55,11 @@ export declare function resolveModelParams(settings: ModelSettings | undefined,
|
|
|
55
55
|
export declare function runCtxFor<TContext>(state: RunState<TContext>): AgentRunContext<TContext>;
|
|
56
56
|
/**
|
|
57
57
|
* Fork a child runtime for a spawned sub-agent: fresh usage/turns ledger and a new
|
|
58
|
-
* `address` shard, inheriting the parent's shared
|
|
58
|
+
* `address` shard, inheriting the parent's shared environment (session/store/permission/…)
|
|
59
59
|
* unless an override is given. This is the single place child frames are minted — the
|
|
60
60
|
* subagent, Agent, and Workflow tools all go through it.
|
|
61
61
|
*/
|
|
62
|
-
export declare function deriveChild<TContext>(parent: RunState<TContext>, opts: DeriveOptions): RunState<TContext>;
|
|
62
|
+
export declare function deriveChild<TContext>(parent: RunState<TContext>, opts: DeriveOptions, spawner: Pick<Agent<TContext>, "model">): RunState<TContext>;
|
|
63
63
|
/** Runs the turn-boundary injectors, appending their reminders to `context`, and returns each
|
|
64
64
|
* injector's token estimate so the context breakdown can break the framing out of `messages`. */
|
|
65
65
|
export declare function injectAtTurnBoundary<TContext>(state: RunState<TContext>, context: ConversationContext): Map<string, number>;
|