@sema-agent/core 5.19.0 → 5.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -4
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-transcript-tool.d.ts +30 -0
- package/dist/agents/builtin-agents.d.ts +60 -0
- package/dist/agents/cascade.d.ts +107 -0
- package/dist/agents/cumulative-stats.d.ts +56 -0
- package/dist/agents/observer.d.ts +162 -0
- package/dist/agents/peer-admission.d.ts +95 -0
- package/dist/agents/repair-loop.d.ts +226 -0
- package/dist/agents/retain-ledger.d.ts +141 -0
- package/dist/agents/roster-store.d.ts +105 -0
- package/dist/agents/roster-store.js +3 -0
- package/dist/agents/send-message-tool.d.ts +92 -0
- package/dist/agents/session-util.d.ts +5 -0
- package/dist/agents/subagent-steps.d.ts +66 -0
- package/dist/agents/subagent.d.ts +600 -0
- package/dist/agents/suspend-guard.d.ts +29 -0
- package/dist/agents/teacher.d.ts +75 -0
- package/dist/agents/team.d.ts +120 -1
- package/dist/agents/tool-filter.d.ts +34 -0
- package/dist/agents/verify.d.ts +198 -0
- package/dist/bench/metrics.d.ts +455 -0
- package/dist/brain/anthropic.d.ts +30 -0
- package/dist/brain/circuit-breaker.d.ts +33 -0
- package/dist/brain/circuit-breaker.js +14 -3
- package/dist/brain/context-overflow.d.ts +60 -3
- package/dist/brain/degrading.d.ts +67 -0
- package/dist/brain/errors.d.ts +42 -0
- package/dist/brain/failover.d.ts +15 -0
- package/dist/brain/media-degrade.d.ts +39 -0
- package/dist/brain/model-presets.d.ts +31 -0
- package/dist/brain/open-responses.d.ts +19 -0
- package/dist/brain/openai.d.ts +46 -0
- package/dist/brain/reasoning.d.ts +106 -1
- package/dist/brain/repetition.d.ts +83 -0
- package/dist/brain/request-params.d.ts +56 -0
- package/dist/brain/retry.d.ts +46 -0
- package/dist/brain/routing.d.ts +12 -0
- package/dist/brain/status-sink.d.ts +30 -1
- package/dist/brain/stream-engine.d.ts +147 -0
- package/dist/brain/stream-shared.d.ts +34 -0
- package/dist/brain/terminal-cause.d.ts +31 -0
- package/dist/brain/timeout.d.ts +108 -0
- package/dist/brain/timeout.js +11 -0
- package/dist/brain/tool-call-id.d.ts +20 -0
- package/dist/brain/tool-call-repair.d.ts +13 -0
- package/dist/config/catalog.d.ts +47 -0
- package/dist/config/defaults.d.ts +33 -0
- package/dist/core/a2a-task-state.d.ts +53 -0
- package/dist/core/a2a.d.ts +51 -0
- package/dist/core/arg-summary.d.ts +62 -0
- package/dist/core/ask-question.d.ts +272 -2
- package/dist/core/auto-compaction.d.ts +467 -0
- package/dist/core/auto-compaction.js +20 -6
- package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
- package/dist/core/auto-mode-prompt.d.ts +27 -0
- package/dist/core/auto-mode.d.ts +54 -3
- package/dist/core/auto-promote.d.ts +100 -0
- package/dist/core/background-agent-store.d.ts +293 -0
- package/dist/core/background-agent-store.js +5 -0
- package/dist/core/background-shell.d.ts +110 -0
- package/dist/core/cache-break-detector.d.ts +34 -0
- package/dist/core/canonical-json.d.ts +57 -0
- package/dist/core/checkpoint-store.d.ts +1574 -16
- package/dist/core/compliance.d.ts +30 -0
- package/dist/core/consolidate-scope.d.ts +75 -0
- package/dist/core/context-edit.d.ts +99 -0
- package/dist/core/context-guard.d.ts +46 -0
- package/dist/core/exec-gate.d.ts +44 -0
- package/dist/core/exec-output-tail.d.ts +61 -0
- package/dist/core/file-snapshot-store.d.ts +104 -0
- package/dist/core/fs-write-gate-policy.d.ts +36 -0
- package/dist/core/git-worktree-env.d.ts +31 -0
- package/dist/core/governance-codes.d.ts +19 -0
- package/dist/core/hooks.d.ts +609 -1
- package/dist/core/human-input-projection.d.ts +37 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/image-downsample.d.ts +74 -0
- package/dist/core/locked-config.d.ts +37 -0
- package/dist/core/lsp-diagnostics.d.ts +77 -0
- package/dist/core/lsp-protocol.d.ts +29 -0
- package/dist/core/lsp-session.d.ts +60 -1
- package/dist/core/lsp.d.ts +150 -1
- package/dist/core/mailbox-store.d.ts +57 -0
- package/dist/core/mailbox-store.js +2 -0
- package/dist/core/mcp.d.ts +385 -0
- package/dist/core/mcp.js +58 -11
- package/dist/core/media-byte-cap.d.ts +21 -0
- package/dist/core/memory-admission.d.ts +71 -0
- package/dist/core/memory-engine/content-origin.d.ts +64 -0
- package/dist/core/memory-engine/data-plane.d.ts +43 -0
- package/dist/core/memory-engine/dual-root.d.ts +24 -0
- package/dist/core/memory-engine/engine.d.ts +230 -0
- package/dist/core/memory-engine/engine.js +103 -35
- package/dist/core/memory-engine/file-backend.d.ts +155 -0
- package/dist/core/memory-engine/frontmatter.d.ts +16 -0
- package/dist/core/memory-engine/layout.d.ts +217 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
- package/dist/core/memory-engine/migrate.d.ts +9 -0
- package/dist/core/memory-engine/scan.d.ts +12 -0
- package/dist/core/memory-engine/scope-contract.d.ts +61 -1
- package/dist/core/memory-engine/sync-client.d.ts +87 -0
- package/dist/core/memory-engine/sync.d.ts +60 -0
- package/dist/core/memory-engine/tools.d.ts +41 -0
- package/dist/core/memory-engine/types.d.ts +188 -0
- package/dist/core/memory-recall.d.ts +141 -0
- package/dist/core/memory-vector.d.ts +20 -0
- package/dist/core/memory.d.ts +458 -0
- package/dist/core/message-utils.d.ts +6 -0
- package/dist/core/oracle-isolation.d.ts +69 -0
- package/dist/core/permission-rule-consent.d.ts +138 -0
- package/dist/core/permission-rule-model.d.ts +122 -0
- package/dist/core/permission-rule-store.d.ts +119 -3
- package/dist/core/permission-rules.d.ts +87 -1
- package/dist/core/present-plan-tool.d.ts +20 -0
- package/dist/core/pricing.d.ts +26 -0
- package/dist/core/property-harness.d.ts +86 -0
- package/dist/core/protocol-naming.d.ts +38 -0
- package/dist/core/protocol-table.d.ts +61 -0
- package/dist/core/push-queue.d.ts +1 -0
- package/dist/core/remote-env.d.ts +383 -1
- package/dist/core/retention-policy.d.ts +40 -0
- package/dist/core/retention-policy.js +21 -0
- package/dist/core/retention.d.ts +51 -0
- package/dist/core/roles.d.ts +59 -0
- package/dist/core/runner/active-skill-scope.d.ts +34 -0
- package/dist/core/runner/assemble-result.d.ts +134 -0
- package/dist/core/runner/compaction-call-options.d.ts +97 -1
- package/dist/core/runner/grounding-signal.d.ts +10 -0
- package/dist/core/runner/image.d.ts +17 -0
- package/dist/core/runner/image.js +29 -15
- package/dist/core/runner/memory-consolidation.d.ts +60 -0
- package/dist/core/runner/prepare-memory.d.ts +59 -0
- package/dist/core/runner/prepare-task.d.ts +1011 -2
- package/dist/core/runner/prepare-task.js +51 -14
- package/dist/core/runner/prompt-suggestions.d.ts +7 -0
- package/dist/core/runner/runtask.d.ts +304 -3
- package/dist/core/runner/runtask.js +17 -2
- package/dist/core/runner/session-file-state-replay.d.ts +49 -0
- package/dist/core/runner/session-rule-policy.d.ts +58 -0
- package/dist/core/runner/strict-output-schema.d.ts +18 -3
- package/dist/core/runner/synthetic-tools.d.ts +113 -0
- package/dist/core/runner/teardown-bounded.d.ts +34 -0
- package/dist/core/runner/tool-disclosure.d.ts +227 -0
- package/dist/core/runner/tool-output-projection.d.ts +6 -0
- package/dist/core/runner/turn-attachments.d.ts +634 -0
- package/dist/core/runner/usage-accounting.d.ts +32 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/safe-notify.d.ts +64 -0
- package/dist/core/safety-axis-vocab.d.ts +23 -0
- package/dist/core/safety-merge-corpus.d.ts +37 -0
- package/dist/core/scheduler.d.ts +121 -0
- package/dist/core/secret-env.d.ts +32 -0
- package/dist/core/select-model.d.ts +15 -0
- package/dist/core/sensitive-path-policy.d.ts +42 -0
- package/dist/core/session-policy-store.d.ts +94 -0
- package/dist/core/session-reconcile.d.ts +80 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session.d.ts +153 -0
- package/dist/core/shared-memory/contract.d.ts +22 -0
- package/dist/core/shared-memory/normalize.d.ts +123 -2
- package/dist/core/shared-memory/tools.d.ts +14 -0
- package/dist/core/shared-memory/types.d.ts +105 -0
- package/dist/core/shutdown-debug.d.ts +6 -0
- package/dist/core/side-query.d.ts +38 -0
- package/dist/core/side-query.js +6 -1
- package/dist/core/skill-tool-specifier.d.ts +72 -0
- package/dist/core/skills-directory.d.ts +100 -1
- package/dist/core/spec-contract.d.ts +89 -0
- package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
- package/dist/core/store-contracts/contract-harness.d.ts +20 -0
- package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
- package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
- package/dist/core/strategy-store.d.ts +37 -0
- package/dist/core/stub-env.d.ts +7 -0
- package/dist/core/surrogate-safe-slice.d.ts +35 -0
- package/dist/core/task-notification.d.ts +202 -0
- package/dist/core/task-outcome.d.ts +53 -0
- package/dist/core/task-registry-agent.d.ts +337 -1
- package/dist/core/task-registry-agent.js +2 -0
- package/dist/core/task-registry-monitor.d.ts +12 -0
- package/dist/core/task-registry-shared.d.ts +540 -0
- package/dist/core/task-registry.d.ts +343 -0
- package/dist/core/task-registry.js +13 -2
- package/dist/core/task-tool-shape.d.ts +44 -0
- package/dist/core/tighten-task-spec.d.ts +21 -0
- package/dist/core/tool-detach.d.ts +21 -0
- package/dist/core/tool-errors.d.ts +131 -0
- package/dist/core/tool-errors.js +4 -0
- package/dist/core/tool-name-aliases.d.ts +27 -0
- package/dist/core/tool-policy.d.ts +555 -0
- package/dist/core/tool-policy.js +3 -0
- package/dist/core/tool-result-budget.d.ts +32 -0
- package/dist/core/tool-result-store.d.ts +174 -1
- package/dist/core/tools.d.ts +45 -0
- package/dist/core/trace.d.ts +323 -0
- package/dist/core/types.d.ts +3859 -2
- package/dist/core/untrusted-egress.d.ts +8 -0
- package/dist/core/untrusted-text.d.ts +156 -0
- package/dist/core/usage-window-store.d.ts +95 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/warm-resume.d.ts +17 -0
- package/dist/core/wiring-manifest.d.ts +169 -0
- package/dist/core/with-retry.d.ts +24 -0
- package/dist/core/workflow-journal-store.d.ts +160 -0
- package/dist/core/workflow-run-store-contract.d.ts +25 -0
- package/dist/core/workflow-run-store.d.ts +119 -0
- package/dist/core/workflow-run-store.js +2 -0
- package/dist/engine/compaction/compaction.d.ts +256 -1
- package/dist/engine/compaction/utils.d.ts +94 -0
- package/dist/engine/execution-env/kill-tree.d.ts +29 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
- package/dist/engine/harness/agent-harness.d.ts +116 -0
- package/dist/engine/harness/agent-harness.js +3 -14
- package/dist/engine/harness/messages.d.ts +15 -0
- package/dist/engine/harness/types.d.ts +464 -2
- package/dist/engine/llm/diagnostics.d.ts +4 -0
- package/dist/engine/llm/event-stream.d.ts +3 -0
- package/dist/engine/llm/index.d.ts +7 -0
- package/dist/engine/llm/types.d.ts +500 -3
- package/dist/engine/llm/validation.d.ts +3 -0
- package/dist/engine/loop/agent-loop.d.ts +87 -2
- package/dist/engine/loop/runtime-deps.d.ts +7 -0
- package/dist/engine/loop/types.d.ts +424 -0
- package/dist/engine/lsp/frame-decoder.d.ts +13 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
- package/dist/engine/session/import-validate.d.ts +27 -0
- package/dist/engine/session/log-digest.d.ts +93 -0
- package/dist/engine/session/memory-repo.d.ts +6 -0
- package/dist/engine/session/memory-storage.d.ts +2 -0
- package/dist/engine/session/session.d.ts +75 -0
- package/dist/engine/session/storage-base.d.ts +8 -0
- package/dist/fixtures/index.d.ts +36 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +1 -2
- package/dist/internal/harness-types.d.ts +6 -0
- package/dist/internal/harness.d.ts +11 -0
- package/dist/internal/llm.d.ts +6 -0
- package/dist/orchestration/builtin-workflows.d.ts +53 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
- package/dist/orchestration/goal.d.ts +57 -0
- package/dist/orchestration/goal.js +3 -0
- package/dist/orchestration/run-spec.d.ts +42 -0
- package/dist/orchestration/run-spec.js +4 -0
- package/dist/orchestration/run-workflow-tool.d.ts +169 -0
- package/dist/orchestration/workflow-governance.d.ts +61 -0
- package/dist/orchestration/workflow-meta.d.ts +28 -0
- package/dist/orchestration/workflow-observe.d.ts +60 -0
- package/dist/orchestration/workflow-primitives.d.ts +23 -1
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
- package/dist/orchestration/workflow-script-runner.d.ts +88 -0
- package/dist/orchestration/workflow-script-store.d.ts +98 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
- package/dist/orchestration/workflow-types.d.ts +169 -2
- package/dist/orchestration/workflow.d.ts +358 -0
- package/dist/orchestration/workflow.js +13 -2
- package/dist/prompt-assembly/artifact-store.d.ts +33 -0
- package/dist/prompt-assembly/artifact.d.ts +25 -0
- package/dist/prompt-assembly/assemble.d.ts +20 -0
- package/dist/prompt-assembly/composer.d.ts +29 -0
- package/dist/prompt-assembly/epoch.d.ts +55 -1
- package/dist/prompt-assembly/event-registry.d.ts +35 -0
- package/dist/prompt-assembly/explain.d.ts +12 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
- package/dist/prompt-assembly/types.d.ts +115 -0
- package/dist/prompts/coordinator.d.ts +27 -0
- package/dist/prompts/default.d.ts +539 -0
- package/dist/prompts/simple-sections.d.ts +45 -0
- package/dist/prompts/supervisor.d.ts +66 -0
- package/dist/scenarios/env.d.ts +28 -0
- package/dist/scenarios/full-body.d.ts +50 -0
- package/dist/scenarios/scenario-registry.d.ts +60 -0
- package/dist/scenarios/teacher-quickstart.d.ts +27 -0
- package/dist/server/http.d.ts +17 -0
- package/dist/stores/cc/lockfile.d.ts +6 -0
- package/dist/stores/cc/mailbox-store.d.ts +8 -0
- package/dist/stores/cc/roster-adapter.d.ts +4 -0
- package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
- package/dist/stores/file/background-agent-store.d.ts +24 -0
- package/dist/stores/file/background-agent-store.js +2 -1
- package/dist/stores/file/checkpoint-store.d.ts +38 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/fs-atomic.d.ts +155 -0
- package/dist/stores/file/index.d.ts +89 -0
- package/dist/stores/file/mailbox-store.d.ts +36 -0
- package/dist/stores/file/mailbox-store.js +2 -0
- package/dist/stores/file/memory-store.d.ts +82 -0
- package/dist/stores/file/permission-rule-store.d.ts +79 -0
- package/dist/stores/file/session-policy-store.d.ts +28 -0
- package/dist/stores/file/session-store.d.ts +40 -0
- package/dist/stores/file/shared-ledger.d.ts +83 -0
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/usage-window-store.d.ts +18 -0
- package/dist/stores/file/workflow-journal-store.d.ts +100 -0
- package/dist/stores/file/workflow-run-store.d.ts +11 -0
- package/dist/stores/file/workflow-run-store.js +2 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
- package/dist/tools/fs/encoding.d.ts +60 -0
- package/dist/tools/fs/fs-bash.d.ts +133 -0
- package/dist/tools/fs/fs-pdf.d.ts +28 -0
- package/dist/tools/fs/fs-search-tools.d.ts +5 -0
- package/dist/tools/fs/fs-shared.d.ts +360 -0
- package/dist/tools/fs/fs-write.d.ts +16 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
- package/dist/tools/fs/index.d.ts +79 -0
- package/dist/tools/fs/notebook.d.ts +56 -0
- package/dist/tools/fs/pdf.d.ts +70 -0
- package/dist/tools/fs/pdf.js +8 -2
- package/dist/tools/fs/repo-map.d.ts +10 -0
- package/dist/tools/fs/safety.d.ts +376 -0
- package/dist/tools/fs/search.d.ts +131 -0
- package/dist/tools/loop-tick.d.ts +24 -0
- package/dist/tools/monitor.d.ts +55 -0
- package/dist/tools/scheduler-tools.d.ts +51 -0
- package/dist/tools/sql-adapters.d.ts +18 -0
- package/dist/tools/sql.d.ts +25 -0
- package/dist/tools/task-list.d.ts +77 -0
- package/dist/tools/todo.d.ts +8 -0
- package/dist/tools/web.d.ts +184 -0
- package/dist/tools/web.js +32 -5
- package/dist/tools/worktree.d.ts +81 -0
- package/package.json +2 -2
- package/dist/tools/gitea-issue.d.ts +0 -13
- package/dist/tools/gitea-issue.js +0 -75
|
@@ -2,6 +2,7 @@ import type { PromptEpochDescriptor } from "../../prompt-assembly/epoch.js";
|
|
|
2
2
|
import type { DocumentContent, ImageContent, Model, SimpleStreamOptions, TextContent, Transport } from "../llm/index.js";
|
|
3
3
|
import type { AfterToolCallResult, AgentEvent, AgentMessage, AgentTool, BeforeToolCallResult, QueueMode, ThinkingLevel } from "../loop/types.js";
|
|
4
4
|
import type { AgentCoreRuntimeDeps } from "../loop/runtime-deps.js";
|
|
5
|
+
/** Result of a fallible operation. Expected failures are returned as `ok: false` instead of thrown. */
|
|
5
6
|
export type Result<TValue, TError> = {
|
|
6
7
|
ok: true;
|
|
7
8
|
value: TValue;
|
|
@@ -9,48 +10,138 @@ export type Result<TValue, TError> = {
|
|
|
9
10
|
ok: false;
|
|
10
11
|
error: TError;
|
|
11
12
|
};
|
|
13
|
+
/** Create a successful {@link Result}. */
|
|
12
14
|
export declare function ok<TValue, TError>(value: TValue): Result<TValue, TError>;
|
|
15
|
+
/** Create a failed {@link Result}. */
|
|
13
16
|
export declare function err<TValue, TError>(error: TError): Result<TValue, TError>;
|
|
17
|
+
/** Normalize unknown thrown values into Error instances before using them as typed error causes. */
|
|
14
18
|
export declare function toError(error: unknown): Error;
|
|
19
|
+
/**
|
|
20
|
+
* Skill loaded from a `SKILL.md` file or provided by an application.
|
|
21
|
+
*
|
|
22
|
+
* [c209-C] R2 C8 delivery reality: in this repo skill disclosure does NOT enter the system prompt —
|
|
23
|
+
* `name`+`description` ride the first user turn as a `<system-reminder>` `<skills>` listing frame
|
|
24
|
+
* (+ boundary drift deltas), and bodies come back through the `Skill` tool. This harness-level
|
|
25
|
+
* resource type is the vendored seam the runner maps `TaskSpec.skills` onto.
|
|
26
|
+
*/
|
|
15
27
|
export interface Skill {
|
|
28
|
+
/** Stable skill name used for lookup and model-visible listings. */
|
|
16
29
|
name: string;
|
|
30
|
+
/** Short model-visible description of when to use the skill. */
|
|
17
31
|
description: string;
|
|
32
|
+
/** Full skill instructions. */
|
|
18
33
|
content: string;
|
|
34
|
+
/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */
|
|
19
35
|
filePath: string;
|
|
36
|
+
/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */
|
|
20
37
|
disableModelInvocation?: boolean;
|
|
21
38
|
}
|
|
39
|
+
/** Prompt template that can be formatted into a prompt for explicit invocation. */
|
|
22
40
|
export interface PromptTemplate {
|
|
41
|
+
/** Stable template name used for lookup or application command routing. */
|
|
23
42
|
name: string;
|
|
43
|
+
/** Optional description for command lists or autocomplete. */
|
|
24
44
|
description?: string;
|
|
45
|
+
/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */
|
|
25
46
|
content: string;
|
|
26
47
|
}
|
|
48
|
+
/** Resources made available to explicit invocation methods and system-prompt callbacks. */
|
|
27
49
|
export interface AgentHarnessResources<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> {
|
|
50
|
+
/** Prompt templates available for explicit invocation. */
|
|
28
51
|
promptTemplates?: TPromptTemplate[];
|
|
52
|
+
/** Skills available to the model and explicit skill invocation. */
|
|
29
53
|
skills?: TSkill[];
|
|
30
54
|
}
|
|
55
|
+
/** Curated provider request options owned by the harness and snapshotted per turn. */
|
|
31
56
|
export interface AgentHarnessStreamOptions {
|
|
57
|
+
/** Preferred transport forwarded to the stream function. */
|
|
32
58
|
transport?: Transport;
|
|
59
|
+
/** Provider request timeout in milliseconds. */
|
|
33
60
|
timeoutMs?: number;
|
|
61
|
+
/** Maximum provider retry attempts. */
|
|
34
62
|
maxRetries?: number;
|
|
63
|
+
/** Optional cap for provider-requested retry delays. */
|
|
35
64
|
maxRetryDelayMs?: number;
|
|
65
|
+
/** Additional request headers merged with auth and lifecycle headers. */
|
|
36
66
|
headers?: Record<string, string>;
|
|
67
|
+
/** Provider metadata forwarded with requests. */
|
|
37
68
|
metadata?: SimpleStreamOptions["metadata"];
|
|
69
|
+
/** Provider cache retention hint. */
|
|
38
70
|
cacheRetention?: SimpleStreamOptions["cacheRetention"];
|
|
39
71
|
}
|
|
72
|
+
/** Per-request stream option patch returned by provider hooks. */
|
|
40
73
|
export interface AgentHarnessStreamOptionsPatch extends Omit<Partial<AgentHarnessStreamOptions>, "headers" | "metadata"> {
|
|
74
|
+
/** Header patch. `undefined` values delete keys; explicit `headers: undefined` clears all headers. */
|
|
41
75
|
headers?: Record<string, string | undefined>;
|
|
76
|
+
/** Metadata patch. `undefined` values delete keys; explicit `metadata: undefined` clears all metadata. */
|
|
42
77
|
metadata?: Record<string, unknown>;
|
|
43
78
|
}
|
|
79
|
+
/** Kind of filesystem object as addressed by a {@link FileSystem}. Symlinks are not followed automatically. */
|
|
44
80
|
export type FileKind = "file" | "directory" | "symlink";
|
|
45
|
-
|
|
81
|
+
/** Stable, backend-independent file error codes returned by {@link FileSystem} file operations. */
|
|
82
|
+
export type FileErrorCode = "aborted" | "not_found" | "permission_denied" | "not_directory" | "is_directory" | "invalid" | "not_supported"
|
|
83
|
+
/** Exclusive create refused because the path already exists ({@link FileSystem.writeFileExclusive},
|
|
84
|
+
* POSIX `O_EXCL` shape). Discriminable so a caller can distinguish "lost the create race" from a
|
|
85
|
+
* write failure and give honest guidance instead of overwriting. */
|
|
86
|
+
| "already_exists"
|
|
87
|
+
/** A remote fs RPC exceeded its liveness/idle bound (a hung provider call) — retryable by the caller per
|
|
88
|
+
* the op's idempotency. Mirrors `RemoteExecutionError` code `"timeout"` so a remote `FileSystem` op can
|
|
89
|
+
* surface a hang as a typed, retryable error instead of `"unknown"` (core src/core/remote-env.ts contract;
|
|
90
|
+
* VENDOR.md mod #6 / service[45]/[49] class-fix). */
|
|
91
|
+
| "timeout"
|
|
92
|
+
/** The transport carrying a remote fs op dropped mid-session (SSH channel death, ADB device offline) —
|
|
93
|
+
* retryable after reconnect. Mirrors `RemoteExecutionErrorCode` `"transport_lost"`, same precedent as
|
|
94
|
+
* `"timeout"` above (VENDOR.md mod #9 / service[63] SSH/ADB adapters), so a retry whitelist can see it
|
|
95
|
+
* instead of an opaque `"unknown"`. */
|
|
96
|
+
| "transport_lost" | "unknown";
|
|
97
|
+
/** Error returned by {@link FileSystem} file operations. */
|
|
46
98
|
export declare class FileError extends Error {
|
|
99
|
+
/** Backend-independent error code. */
|
|
47
100
|
code: FileErrorCode;
|
|
101
|
+
/** Absolute addressed path associated with the failure, when available. */
|
|
48
102
|
path?: string;
|
|
49
103
|
constructor(code: FileErrorCode, message: string, path?: string, cause?: Error);
|
|
50
104
|
}
|
|
51
|
-
|
|
105
|
+
/** Stable, backend-independent execution error codes returned by {@link ExecutionEnv.exec}. */
|
|
106
|
+
export type ExecutionErrorCode = "aborted" | "timeout"
|
|
107
|
+
/** The shell binary/config could not be resolved BEFORE spawning — the command never started. */
|
|
108
|
+
| "shell_unavailable"
|
|
109
|
+
/** CONTRACT (2026-07-13, TB cwd-poison batch): spawn_error MUST mean the command NEVER STARTED (the
|
|
110
|
+
* OS-level spawn itself failed: dead cwd, missing binary, EMFILE/ENOMEM…). The Bash tool reroutes
|
|
111
|
+
* spawn_error + shell_unavailable to a STRUCTURAL error (throw → isError:true) and runs a dead-cwd
|
|
112
|
+
* diagnosis on them; an env that maps "command ran and failed" onto spawn_error breaks that
|
|
113
|
+
* semantics. Remote env implementers: map post-start failures to exit codes / transport_lost. */
|
|
114
|
+
| "spawn_error" | "callback_error"
|
|
115
|
+
/** The transport carrying a remote exec dropped mid-session (SSH channel death without exit-status, ADB
|
|
116
|
+
* device offline) — the command's outcome is UNKNOWN (it may have kept running); retry only per the op's
|
|
117
|
+
* idempotency, after reconnect. Mirrors `RemoteExecutionErrorCode` `"transport_lost"` (VENDOR.md mod #9 /
|
|
118
|
+
* service[63] SSH/ADB adapters). */
|
|
119
|
+
| "transport_lost"
|
|
120
|
+
/** The workspace is (or became) SUSPENDED — its VM is paused, so the command NEVER STARTED and never
|
|
121
|
+
* will until the task is resumed. Mirrors `RemoteExecutionErrorCode` `"suspended"`, same precedent as
|
|
122
|
+
* `"timeout"`/`"transport_lost"` (RB-439-a): without it a paused-workspace refusal collapsed into
|
|
123
|
+
* `"unknown"`, and the model was told the same generic sentence it gets for an unclassified provider
|
|
124
|
+
* fault — so it re-issued the command instead of asking for a resume. Not retryable in place. */
|
|
125
|
+
| "suspended"
|
|
126
|
+
/** Authentication to the remote target was PERMANENTLY rejected (revoked token, refused key) — the
|
|
127
|
+
* command never started, and every retry will fail the same way (and may lock the account). Mirrors
|
|
128
|
+
* `RemoteExecutionErrorCode` `"auth_failed"`; deliberately NOT a mirror of `auth_transient`, which an
|
|
129
|
+
* adapter retries internally per its own bounded policy rather than surfacing as an exec outcome. */
|
|
130
|
+
| "auth_failed" | "unknown";
|
|
131
|
+
/** Error returned by {@link ExecutionEnv.exec}. */
|
|
52
132
|
export declare class ExecutionError extends Error {
|
|
133
|
+
/** Backend-independent error code. */
|
|
53
134
|
code: ExecutionErrorCode;
|
|
135
|
+
/**
|
|
136
|
+
* TB triple-fake-green report (2026-07-13) — output produced BEFORE the failure, for the
|
|
137
|
+
* ran-then-cut codes (`timeout` / `aborted` / `callback_error`; the last is a command that
|
|
138
|
+
* started and was then killed because a host-side output callback failed — its completion was
|
|
139
|
+
* never observed, but its captured output is real work). CC anchor (2.1.206 BashTask settle): a
|
|
140
|
+
* timed-out command keeps ALL captured stdout/stderr and only APPENDS a "Command timed out after
|
|
141
|
+
* X" line — discarding 600s of build logs forces the model to rerun blind. Optional: envs that
|
|
142
|
+
* cannot capture partial output simply omit these; never-started codes
|
|
143
|
+
* (spawn_error/shell_unavailable) have no output by definition.
|
|
144
|
+
*/
|
|
54
145
|
partialStdout?: string;
|
|
55
146
|
partialStderr?: string;
|
|
56
147
|
constructor(code: ExecutionErrorCode, message: string, cause?: Error, partial?: {
|
|
@@ -58,73 +149,158 @@ export declare class ExecutionError extends Error {
|
|
|
58
149
|
stderr?: string;
|
|
59
150
|
});
|
|
60
151
|
}
|
|
152
|
+
/** Stable compaction error codes returned by compaction helpers. */
|
|
61
153
|
export type CompactionErrorCode = "aborted" | "summarization_failed" | "invalid_session" | "unknown";
|
|
154
|
+
/** Error returned by compaction helpers. */
|
|
62
155
|
export declare class CompactionError extends Error {
|
|
156
|
+
/** Backend-independent error code. */
|
|
63
157
|
code: CompactionErrorCode;
|
|
64
158
|
constructor(code: CompactionErrorCode, message: string, cause?: Error);
|
|
65
159
|
}
|
|
66
160
|
export type SessionErrorCode = "not_found" | "invalid_session" | "invalid_entry" | "invalid_fork_target" | "storage" | "conflict" | "unknown";
|
|
161
|
+
/** Error thrown by session storage, repositories, and session tree operations. */
|
|
67
162
|
export declare class SessionError extends Error {
|
|
163
|
+
/** Session subsystem error code. */
|
|
68
164
|
code: SessionErrorCode;
|
|
69
165
|
constructor(code: SessionErrorCode, message: string, cause?: Error);
|
|
70
166
|
}
|
|
71
167
|
export type AgentHarnessErrorCode = "busy" | "invalid_state" | "invalid_argument" | "session" | "hook" | "auth" | "compaction" | "unknown";
|
|
168
|
+
/** Public AgentHarness failure with a stable top-level classification. */
|
|
72
169
|
export declare class AgentHarnessError extends Error {
|
|
73
170
|
code: AgentHarnessErrorCode;
|
|
74
171
|
constructor(code: AgentHarnessErrorCode, message: string, cause?: Error);
|
|
75
172
|
}
|
|
173
|
+
/** Metadata for one filesystem object in a {@link FileSystem}. */
|
|
76
174
|
export interface FileInfo {
|
|
175
|
+
/** Basename of {@link path}. */
|
|
77
176
|
name: string;
|
|
177
|
+
/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */
|
|
78
178
|
path: string;
|
|
179
|
+
/** Object kind. Symlink targets are not followed; use {@link FileSystem.canonicalPath} explicitly. */
|
|
79
180
|
kind: FileKind;
|
|
181
|
+
/** Size in bytes for the addressed filesystem object. */
|
|
80
182
|
size: number;
|
|
183
|
+
/** Modification time as milliseconds since Unix epoch. */
|
|
81
184
|
mtimeMs: number;
|
|
82
185
|
}
|
|
186
|
+
/** Options for {@link Shell.exec}. */
|
|
83
187
|
export interface ExecutionEnvExecOptions {
|
|
188
|
+
/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. Defaults to {@link ExecutionEnv.cwd}. */
|
|
84
189
|
cwd?: string;
|
|
190
|
+
/** Additional environment variables for the command. Values override the environment defaults. Defaults to no overrides. */
|
|
85
191
|
env?: Record<string, string>;
|
|
192
|
+
/** Timeout in seconds. Implementations should return a timeout error when the command exceeds this duration. Defaults to no timeout. */
|
|
86
193
|
timeout?: number;
|
|
194
|
+
/** Abort signal used to terminate the command. Defaults to no abort signal. */
|
|
87
195
|
abortSignal?: AbortSignal;
|
|
196
|
+
/** Called with stdout chunks as they are produced. */
|
|
88
197
|
onStdout?: (chunk: string) => void;
|
|
198
|
+
/** Called with stderr chunks as they are produced. */
|
|
89
199
|
onStderr?: (chunk: string) => void;
|
|
200
|
+
/**
|
|
201
|
+
* VENDORED EDIT (design/116 detach, 飞轮 [C]): when fired mid-run, an env that supports detach ADOPTS the
|
|
202
|
+
* running child as a background process (its handle never leaves the env) and settles the exec with a
|
|
203
|
+
* `detached` marker instead of killing it. Envs without detach support ignore this (the exec runs on).
|
|
204
|
+
*/
|
|
90
205
|
detachSignal?: AbortSignal;
|
|
206
|
+
/**
|
|
207
|
+
* RB-198 F1 (form-one audit, CC 220 `Zry`/`WZi.#m` parity) — when this command's OWN timeout
|
|
208
|
+
* fires, an env that supports detach ADOPTS the running child as a background process (the same
|
|
209
|
+
* mechanism `detachSignal` uses) instead of killing it, settling the exec with
|
|
210
|
+
* `detached: {shellId, cause:"timeout"}` — a non-idempotent long command survives its own timeout
|
|
211
|
+
* instead of being SIGKILLed mid-flight and forcing a blind re-run. The CALLER decides eligibility
|
|
212
|
+
* (bash-specific command-shape knowledge the env itself does not have — same division of labor as
|
|
213
|
+
* `detachSignal` being caller-fired); a `false`/absent value keeps the pre-existing kill-on-timeout
|
|
214
|
+
* behavior. Envs without detach support ignore this (opt-in, backward compatible).
|
|
215
|
+
*/
|
|
91
216
|
autoBackgroundOnTimeout?: boolean;
|
|
92
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Filesystem capability used by the harness.
|
|
220
|
+
*
|
|
221
|
+
* Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by file operations are addressed paths
|
|
222
|
+
* in the filesystem namespace, but are not canonicalized through symlinks unless returned by {@link canonicalPath}.
|
|
223
|
+
*
|
|
224
|
+
* Operation methods must never throw or reject. All filesystem failures, including unexpected backend failures, must be
|
|
225
|
+
* encoded in the returned {@link Result}. Implementations must preserve this invariant.
|
|
226
|
+
*/
|
|
93
227
|
export interface FileSystem {
|
|
228
|
+
/** Current working directory for relative paths. */
|
|
94
229
|
cwd: string;
|
|
230
|
+
/** Return an absolute addressed path without requiring it to exist and without resolving symlinks. */
|
|
95
231
|
absolutePath(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
232
|
+
/** Join path segments in the filesystem namespace without requiring the result to exist. */
|
|
96
233
|
joinPath(parts: string[], abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
234
|
+
/** Read a UTF-8 text file. */
|
|
97
235
|
readTextFile(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
236
|
+
/** Read UTF-8 text lines. Implementations should stop once `maxLines` lines have been read. */
|
|
98
237
|
readTextLines(path: string, options?: {
|
|
99
238
|
maxLines?: number;
|
|
100
239
|
abortSignal?: AbortSignal;
|
|
101
240
|
}): Promise<Result<string[], FileError>>;
|
|
241
|
+
/** Read a binary file. */
|
|
102
242
|
readBinaryFile(path: string, abortSignal?: AbortSignal): Promise<Result<Uint8Array, FileError>>;
|
|
243
|
+
/** Create or overwrite a file, creating parent directories when supported. Implementation note
|
|
244
|
+
* (RB-221 [1937]): the Node env replaces the file as a WHOLE (same-directory staging + fsync +
|
|
245
|
+
* rename; `aborted` ⇒ target untouched), falling back to an in-place rewrite where rename cannot
|
|
246
|
+
* apply (cross-device, symlink chains, non-regular targets, read-only parent dir). Atomicity is an
|
|
247
|
+
* implementation quality, NOT an interface-level contract — a remote/transport env may only have a
|
|
248
|
+
* plain in-place write. */
|
|
103
249
|
writeFile(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
|
|
250
|
+
/**
|
|
251
|
+
* OPTIONAL atomic exclusive create (KNOWN-ISSUES Edit-as-create TOCTOU close-out): create `path` with
|
|
252
|
+
* `content` ONLY when nothing exists there, in ONE atomic backend step (POSIX `O_CREAT|O_EXCL` / Node
|
|
253
|
+
* `wx` flag shape). An existing file fails with {@link FileError} code `"already_exists"` and is never
|
|
254
|
+
* truncated or overwritten. Parent directories are created when supported, same as {@link writeFile}.
|
|
255
|
+
*
|
|
256
|
+
* Degradation contract: an env whose backend has NO exclusive-create primitive (e.g. a remote transport
|
|
257
|
+
* that can only exists+write in two round-trips) MUST leave this `undefined` rather than emulate it —
|
|
258
|
+
* a two-step emulation re-opens the very TOCTOU window this method exists to close, behind an
|
|
259
|
+
* atomic-looking face. Callers that find it `undefined` fall back to their own explicit non-atomic
|
|
260
|
+
* emulation and own the residual race.
|
|
261
|
+
*/
|
|
104
262
|
writeFileExclusive?(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
|
|
263
|
+
/** Create or append to a file, creating parent directories when supported. */
|
|
105
264
|
appendFile(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
|
|
265
|
+
/** Return metadata for the addressed path without following symlinks. */
|
|
106
266
|
fileInfo(path: string, abortSignal?: AbortSignal): Promise<Result<FileInfo, FileError>>;
|
|
267
|
+
/** List direct children of a directory without following symlinks. */
|
|
107
268
|
listDir(path: string, abortSignal?: AbortSignal): Promise<Result<FileInfo[], FileError>>;
|
|
269
|
+
/** Return the canonical path for an existing path, resolving symlinks where supported. */
|
|
108
270
|
canonicalPath(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
271
|
+
/**
|
|
272
|
+
* VENDORED EDIT (design/72 §2.1, additive/backward-compatible): read a symlink's raw target (one
|
|
273
|
+
* hop, NOT followed). Optional — an env that omits it falls back to best-effort canonicalization
|
|
274
|
+
* for a DANGLING leaf symlink (a symlink whose target doesn't exist yet, which `canonicalPath`'s
|
|
275
|
+
* `realpath` can't resolve). Needed so a sensitive-path guard / containment check sees the real
|
|
276
|
+
* target of `write_file innocent.txt` where `innocent.txt -> .git/hooks/payload`.
|
|
277
|
+
*/
|
|
109
278
|
readLink?(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
279
|
+
/** Return false for missing paths. Other errors, such as permission failures, return a {@link FileError}. */
|
|
110
280
|
exists(path: string, abortSignal?: AbortSignal): Promise<Result<boolean, FileError>>;
|
|
281
|
+
/** Create a directory. Defaults: `recursive: true`, no abort signal. */
|
|
111
282
|
createDir(path: string, options?: {
|
|
112
283
|
recursive?: boolean;
|
|
113
284
|
abortSignal?: AbortSignal;
|
|
114
285
|
}): Promise<Result<void, FileError>>;
|
|
286
|
+
/** Remove a file or directory. Defaults: `recursive: false`, `force: false`, no abort signal. */
|
|
115
287
|
remove(path: string, options?: {
|
|
116
288
|
recursive?: boolean;
|
|
117
289
|
force?: boolean;
|
|
118
290
|
abortSignal?: AbortSignal;
|
|
119
291
|
}): Promise<Result<void, FileError>>;
|
|
292
|
+
/** Create a temporary directory and return its absolute path. Defaults: `prefix: "tmp-"`, no abort signal. */
|
|
120
293
|
createTempDir(prefix?: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
294
|
+
/** Create a temporary file and return its absolute path. Defaults: `prefix: ""`, `suffix: ""`, no abort signal. */
|
|
121
295
|
createTempFile(options?: {
|
|
122
296
|
prefix?: string;
|
|
123
297
|
suffix?: string;
|
|
124
298
|
abortSignal?: AbortSignal;
|
|
125
299
|
}): Promise<Result<string, FileError>>;
|
|
300
|
+
/** Release filesystem resources. Must be best-effort and must not throw or reject. */
|
|
126
301
|
cleanup(): Promise<void>;
|
|
127
302
|
}
|
|
303
|
+
/** Result payload for {@link Shell.exec}. */
|
|
128
304
|
export interface ExecResult {
|
|
129
305
|
stdout: string;
|
|
130
306
|
stderr: string;
|
|
@@ -134,33 +310,74 @@ export interface ExecResult {
|
|
|
134
310
|
cause?: "timeout";
|
|
135
311
|
};
|
|
136
312
|
}
|
|
313
|
+
/** Shell execution capability used by the harness. */
|
|
137
314
|
export interface Shell {
|
|
315
|
+
/** Execute a shell command in {@link FileSystem.cwd} unless `options.cwd` is provided. */
|
|
138
316
|
exec(command: string, options?: ExecutionEnvExecOptions): Promise<Result<ExecResult, ExecutionError>>;
|
|
317
|
+
/** Release shell resources. Must be best-effort and must not throw or reject. */
|
|
139
318
|
cleanup(): Promise<void>;
|
|
140
319
|
}
|
|
320
|
+
/** Filesystem and process execution environment used by the harness. */
|
|
141
321
|
export interface ExecutionEnv extends FileSystem, Shell {
|
|
322
|
+
/**
|
|
323
|
+
* design/164 件四 — the environment's PLATFORM LIFETIME in milliseconds: how long this sandbox/VM is
|
|
324
|
+
* allowed to exist before the platform reclaims it, counted from {@link lifetimeStartedAt}. Declared by
|
|
325
|
+
* the ADAPTER, never by the task: sandbox lifetimes are a platform fact (minutes to a day, depending on
|
|
326
|
+
* the backend and tier), so the engine holds no number of its own and a local Node environment simply
|
|
327
|
+
* omits the field (⇒ unbounded, the pre-164 behavior).
|
|
328
|
+
*
|
|
329
|
+
* The engine reads it at every clean turn boundary: once `anchor + lifetimeMs − ENV_LIFETIME_SUSPEND_MARGIN_MS`
|
|
330
|
+
* has passed, the run either suspends into a durable checkpoint (`reason: "env_lifetime"`) or, when the
|
|
331
|
+
* deployment cannot suspend durably, stops LOUDLY with `env.lifetime_expired` — instead of being killed
|
|
332
|
+
* mid-turn by the platform with no record of where it got to.
|
|
333
|
+
*
|
|
334
|
+
* Must be a finite, positive number of ms; anything else is refused at the door (`config.env_lifetime_invalid`)
|
|
335
|
+
* rather than folded to a default, because an unevaluable lifetime is not a lifetime.
|
|
336
|
+
*/
|
|
142
337
|
readonly lifetimeMs?: number;
|
|
338
|
+
/**
|
|
339
|
+
* design/164 件四 — epoch ms at which this environment's {@link lifetimeMs} started running: the moment
|
|
340
|
+
* the PLATFORM created the sandbox, which is the only honest anchor. Self-reported because the engine
|
|
341
|
+
* cannot observe it: an env handed to the Runner may have been created long before this task (a shared
|
|
342
|
+
* static env), and a resumed sandbox carries the age of its original creation.
|
|
343
|
+
*
|
|
344
|
+
* Omitted ⇒ the engine falls back to the instant its own `executionEnvFactory` returned the env, which is
|
|
345
|
+
* accurate only for an env minted FOR this run. An env that declares `lifetimeMs` WITHOUT this anchor and
|
|
346
|
+
* was NOT minted by the factory (a caller-owned static env) leaves the engine no way to age it — the
|
|
347
|
+
* lifetime is then reported as unarmable through `onError` and NOT enforced, because the only guess
|
|
348
|
+
* available (task start) overestimates the remaining lifetime, i.e. errs toward the failure this whole
|
|
349
|
+
* mechanism exists to prevent.
|
|
350
|
+
*/
|
|
143
351
|
readonly lifetimeStartedAt?: number;
|
|
144
352
|
}
|
|
353
|
+
/** Base fields shared by append-only session tree entries. */
|
|
145
354
|
export interface SessionTreeEntryBase {
|
|
355
|
+
/** Entry discriminator used for JSONL persistence and typed narrowing. */
|
|
146
356
|
type: string;
|
|
357
|
+
/** Stable entry id unique within a session file. */
|
|
147
358
|
id: string;
|
|
359
|
+
/** Parent entry id, or null for a root entry. */
|
|
148
360
|
parentId: string | null;
|
|
361
|
+
/** ISO timestamp string used for persistence and sorting. */
|
|
149
362
|
timestamp: string;
|
|
150
363
|
}
|
|
364
|
+
/** Persisted transcript message entry. */
|
|
151
365
|
export interface MessageEntry extends SessionTreeEntryBase {
|
|
152
366
|
type: "message";
|
|
153
367
|
message: AgentMessage;
|
|
154
368
|
}
|
|
369
|
+
/** Persisted thinking-level selection marker. */
|
|
155
370
|
export interface ThinkingLevelChangeEntry extends SessionTreeEntryBase {
|
|
156
371
|
type: "thinking_level_change";
|
|
157
372
|
thinkingLevel: string;
|
|
158
373
|
}
|
|
374
|
+
/** Persisted model selection marker. */
|
|
159
375
|
export interface ModelChangeEntry extends SessionTreeEntryBase {
|
|
160
376
|
type: "model_change";
|
|
161
377
|
provider: string;
|
|
162
378
|
modelId: string;
|
|
163
379
|
}
|
|
380
|
+
/** Persisted summary that replaces older transcript history in context. */
|
|
164
381
|
export interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {
|
|
165
382
|
type: "compaction";
|
|
166
383
|
summary: string;
|
|
@@ -169,11 +386,13 @@ export interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {
|
|
|
169
386
|
details?: T;
|
|
170
387
|
fromHook?: boolean;
|
|
171
388
|
}
|
|
389
|
+
/** Persisted harness/application marker that is not replayed into model context. */
|
|
172
390
|
export interface CustomEntry<T = unknown> extends SessionTreeEntryBase {
|
|
173
391
|
type: "custom";
|
|
174
392
|
customType: string;
|
|
175
393
|
data?: T;
|
|
176
394
|
}
|
|
395
|
+
/** Persisted harness/application message that can be replayed into model context. */
|
|
177
396
|
export interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {
|
|
178
397
|
type: "custom_message";
|
|
179
398
|
customType: string;
|
|
@@ -181,44 +400,105 @@ export interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {
|
|
|
181
400
|
details?: T;
|
|
182
401
|
display: boolean;
|
|
183
402
|
}
|
|
403
|
+
/** Append-only label update for another session entry. */
|
|
184
404
|
export interface LabelEntry extends SessionTreeEntryBase {
|
|
185
405
|
type: "label";
|
|
186
406
|
targetId: string;
|
|
187
407
|
label: string | undefined;
|
|
188
408
|
}
|
|
409
|
+
/** Persisted session metadata marker. */
|
|
189
410
|
export interface SessionInfoEntry extends SessionTreeEntryBase {
|
|
190
411
|
type: "session_info";
|
|
191
412
|
name?: string;
|
|
192
413
|
}
|
|
414
|
+
/** Append-only marker that changes the active visible leaf. */
|
|
193
415
|
export interface LeafEntry extends SessionTreeEntryBase {
|
|
194
416
|
type: "leaf";
|
|
195
417
|
targetId: string | null;
|
|
196
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Prompt-epoch pin (campaign S3, prompt-assembly protocol §9.2) — a FIRST-CLASS typed entry (not a
|
|
421
|
+
* forgeable generic `custom` entry): which prompt-pack artifact this session is pinned to. Written
|
|
422
|
+
* at session start (before the first conversation entry) and on legacy migration; every compaction
|
|
423
|
+
* RESTATES the then-current descriptor inside its own `details.promptEpoch` (same-CAS atomicity,
|
|
424
|
+
* bounded-tail recoverable). Fields mirror `PromptEpochDescriptor` (src/prompt-assembly/epoch.ts).
|
|
425
|
+
*/
|
|
197
426
|
export interface PromptEpochEntry extends SessionTreeEntryBase, PromptEpochDescriptor {
|
|
198
427
|
type: "prompt_epoch";
|
|
199
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* design/150 (RB-25 终态): the listing ANNOUNCED name-sets as a FIRST-CLASS typed entry — which
|
|
431
|
+
* agent roster / skills / model catalog the model has actually been told about on this branch.
|
|
432
|
+
* SNAPSHOT semantics (not deltas): the nearest entry on the branch IS the announced state — rosters
|
|
433
|
+
* are bounded, so replay is a single read, never text parsing of engine-minted transcript frames.
|
|
434
|
+
* Written best-effort at every listing COMMIT point (first-frame delivery / intact boundary
|
|
435
|
+
* survival); the checkpoint mirror (`CheckpointState.announcedListings`) and the transcript-probe
|
|
436
|
+
* replay remain as the second/third rungs of the resume-seed ladder for pre-entry sessions.
|
|
437
|
+
* Present-only arms — an absent arm means "no announcement recorded for that face", same Q5
|
|
438
|
+
* discipline as the checkpoint mirror.
|
|
439
|
+
*/
|
|
200
440
|
export interface AnnouncedListingEntry extends SessionTreeEntryBase {
|
|
201
441
|
type: "announced_listing";
|
|
202
442
|
agents?: string[];
|
|
203
443
|
skills?: string[];
|
|
204
444
|
models?: string[];
|
|
205
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* REF-D3/D4 merge target: the active EnterWorktree session (M22 live-CC anchor, codex 终审 1.255 F2 —
|
|
448
|
+
* plain strings only, no closures, so it survives a durable suspend into `CheckpointState.activeWorktree`
|
|
449
|
+
* verbatim). Canonical definition — `tools/worktree.ts` (the tool pair that owns this durably) re-exports
|
|
450
|
+
* this type rather than declaring its own copy: the harness layer must never import FROM `tools/`
|
|
451
|
+
* (that would invert the layering), so the shared shape lives here and the tool-level module points back
|
|
452
|
+
* at it.
|
|
453
|
+
*
|
|
454
|
+
* `entered`: true when the session ENTERED a pre-existing worktree via `path` instead of creating one —
|
|
455
|
+
* ExitWorktree then never removes it ("ExitWorktree will not remove a worktree entered this way").
|
|
456
|
+
* Absent/false = created by EnterWorktree (removable per the normal rules).
|
|
457
|
+
*/
|
|
206
458
|
export interface ActiveWorktreeSession {
|
|
207
459
|
worktreeDir: string;
|
|
208
460
|
originalCwd: string;
|
|
209
461
|
baseSha: string;
|
|
210
462
|
entered?: boolean;
|
|
211
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* REF-D3/D4 merge target: the session's WORKSPACE STATE container (nests {@link ActiveWorktreeSession}) —
|
|
466
|
+
* see {@link WorkspaceStateEntry} for the durable-entry narrative this type also backs.
|
|
467
|
+
*/
|
|
212
468
|
export interface WorkspaceState {
|
|
469
|
+
/** The canonical task root these paths were recorded against (the rebase base). */
|
|
213
470
|
taskRoot: string;
|
|
471
|
+
/** The tracked logical cwd at settle; ABSENT ⇒ the task root (no tracked `cd` outstanding). */
|
|
214
472
|
handsCwd?: string;
|
|
473
|
+
/** The active EnterWorktree session at settle; ABSENT ⇒ none. */
|
|
215
474
|
activeWorktree?: ActiveWorktreeSession;
|
|
216
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* design/155 (cli [1580]): the session's WORKSPACE STATE at a task settle — the tracked logical cwd
|
|
478
|
+
* and the active EnterWorktree session. Ordinary continuation turns (a new task on the same
|
|
479
|
+
* `spec.sessionId`) have NO checkpoint seed, so without this entry both refs silently reset to the
|
|
480
|
+
* task root every turn (cd doesn't stick, ExitWorktree no-ops, the worktree leaks). Restore ladder
|
|
481
|
+
* (same rung doctrine as the announced-listing, design/150 RB-25): the checkpoint seed stays FIRST on
|
|
482
|
+
* a durable resume (cut atomically with the leaf); the branch-nearest entry of this type is the
|
|
483
|
+
* SECOND rung (plain continuations); fresh defaults last. SNAPSHOT semantics — nearest wins; a
|
|
484
|
+
* settle that returned to the default state writes a CLEAR entry (`handsCwd`/`activeWorktree` both
|
|
485
|
+
* absent) so a stale earlier snapshot cannot shadow it. Paths are recorded against `taskRoot` and
|
|
486
|
+
* rebased on read when the continuing task runs under a different root.
|
|
487
|
+
*/
|
|
217
488
|
export interface WorkspaceStateEntry extends SessionTreeEntryBase, WorkspaceState {
|
|
218
489
|
type: "workspace_state";
|
|
219
490
|
}
|
|
491
|
+
/** Bounded cap for {@link normalizeWorkspaceState} paths (a sha is capped by its hex shape check). */
|
|
220
492
|
export declare const WORKSPACE_STATE_MAX_PATH_CHARS = 4096;
|
|
493
|
+
/**
|
|
494
|
+
* design/155: strict shape gate for the workspace-state snapshot — the SINGLE normalization the
|
|
495
|
+
* read walk, the public append, and the import-validate door all use (same posture as
|
|
496
|
+
* {@link normalizeAnnouncedListing}). Returns a shaped copy carrying ONLY the known keys, or
|
|
497
|
+
* undefined when the value is not structurally valid.
|
|
498
|
+
*/
|
|
221
499
|
export declare function normalizeWorkspaceState(value: unknown): WorkspaceState | undefined;
|
|
500
|
+
/** Bounded caps for {@link normalizeAnnouncedListing} — a roster is dozens of names, never thousands;
|
|
501
|
+
* a "name" is a short identifier, never a document. Oversize ⇒ structurally invalid (forgery signal). */
|
|
222
502
|
export declare const ANNOUNCED_LISTING_MAX_NAMES = 500;
|
|
223
503
|
export declare const ANNOUNCED_LISTING_MAX_NAME_CHARS = 200;
|
|
224
504
|
export declare function normalizeCompactionStateCarrier(v: unknown): {
|
|
@@ -228,6 +508,14 @@ export declare function normalizeCompactionStateCarrier(v: unknown): {
|
|
|
228
508
|
modelId: string;
|
|
229
509
|
} | null;
|
|
230
510
|
};
|
|
511
|
+
/**
|
|
512
|
+
* RB-128 (2026-07-25, defect probe): the SAME two values also arrive as first-class entries, and those
|
|
513
|
+
* had no door at all — so RB-121 gated the weaker of two channels. `buildSessionContext` runs the carrier
|
|
514
|
+
* seed BEFORE the entry scan, which means an ungated `thinking_level_change` / `model_change` OVERRIDES the
|
|
515
|
+
* gated carrier: the property RB-121's own doc claims ("an imported entry could name any string as the
|
|
516
|
+
* branch's thinking level and any provider/model as its active model") stayed true through the other door.
|
|
517
|
+
* Same shapes, one predicate, both channels.
|
|
518
|
+
*/
|
|
231
519
|
export declare function isValidThinkingLevelChange(e: {
|
|
232
520
|
thinkingLevel?: unknown;
|
|
233
521
|
}): boolean;
|
|
@@ -235,12 +523,17 @@ export declare function isValidModelChange(e: {
|
|
|
235
523
|
provider?: unknown;
|
|
236
524
|
modelId?: unknown;
|
|
237
525
|
}): boolean;
|
|
526
|
+
/** RB-128: a `label` / `session_info.name` that is not a string reaches `.trim()` inside
|
|
527
|
+
* `BaseSessionStorage`'s CONSTRUCTOR — and the file backend validates BEFORE constructing any storage, so
|
|
528
|
+
* the poison lands on disk and every later `open()` throws a raw `TypeError` (not even a `SessionError`).
|
|
529
|
+
* Unrecoverable through the API, which is why this belongs at the import door. */
|
|
238
530
|
export declare function isOptionalDisplayString(v: unknown, max?: number): boolean;
|
|
239
531
|
export declare function normalizeAnnouncedListing(v: unknown): {
|
|
240
532
|
agents?: string[];
|
|
241
533
|
skills?: string[];
|
|
242
534
|
models?: string[];
|
|
243
535
|
} | undefined;
|
|
536
|
+
/** All persisted session tree entry variants. */
|
|
244
537
|
export type SessionTreeEntry = MessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | CompactionEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry | LeafEntry | PromptEpochEntry | AnnouncedListingEntry | WorkspaceStateEntry;
|
|
245
538
|
export interface SessionContext {
|
|
246
539
|
messages: AgentMessage[];
|
|
@@ -253,6 +546,11 @@ export interface SessionContext {
|
|
|
253
546
|
export interface SessionMetadata {
|
|
254
547
|
id: string;
|
|
255
548
|
createdAt: string;
|
|
549
|
+
/** F7 fork-GC seam (1.175 known-limitation closed 2026-07-11): the PARENT session this one was forked
|
|
550
|
+
* from, stamped by every `SessionRepo.fork` implementation. Durable fork sessions have no core GC
|
|
551
|
+
* path by design — a deployment's retention/reap (service, design/109 family) reads this to identify
|
|
552
|
+
* fork lineage (e.g. reap forks whose parent is gone/expired). Absent on a non-forked session and on
|
|
553
|
+
* forked sessions persisted before this field shipped. */
|
|
256
554
|
forkedFrom?: string;
|
|
257
555
|
}
|
|
258
556
|
export interface JsonlSessionMetadata extends SessionMetadata {
|
|
@@ -260,12 +558,24 @@ export interface JsonlSessionMetadata extends SessionMetadata {
|
|
|
260
558
|
path: string;
|
|
261
559
|
parentSessionPath?: string;
|
|
262
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* Optimistic-lock options for session writes (F2). A durable backend uses `expectedLeafId` to make
|
|
563
|
+
* the write conditional — preventing cross-instance split-brain, where two stateless runners that
|
|
564
|
+
* both woke the same session append to the same parent and one branch is silently abandoned.
|
|
565
|
+
*/
|
|
263
566
|
export interface SessionWriteOptions {
|
|
567
|
+
/**
|
|
568
|
+
* Apply only if the current branch leaf still equals this value; on mismatch the storage throws
|
|
569
|
+
* `SessionError("conflict")`. Omit (the default) to write unconditionally. `null` means "expect an
|
|
570
|
+
* empty session". A durable backend turns this into a compare-and-set (e.g. a `(session_id, seq)`
|
|
571
|
+
* unique-key insert); the in-process base storage checks it against its in-memory leaf.
|
|
572
|
+
*/
|
|
264
573
|
expectedLeafId?: string | null;
|
|
265
574
|
}
|
|
266
575
|
export interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {
|
|
267
576
|
getMetadata(): Promise<TMetadata>;
|
|
268
577
|
getLeafId(): Promise<string | null>;
|
|
578
|
+
/** Persist a leaf entry that records the active session-tree leaf. */
|
|
269
579
|
setLeafId(leafId: string | null, opts?: SessionWriteOptions): Promise<void>;
|
|
270
580
|
createEntryId(): Promise<string>;
|
|
271
581
|
appendEntry(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
|
|
@@ -276,6 +586,21 @@ export interface SessionStorage<TMetadata extends SessionMetadata = SessionMetad
|
|
|
276
586
|
getLabel(id: string): Promise<string | undefined>;
|
|
277
587
|
getPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;
|
|
278
588
|
getEntries(): Promise<SessionTreeEntry[]>;
|
|
589
|
+
/**
|
|
590
|
+
* Campaign S3 / RB-14 seam (blackboard [975] joint verdict): OPTIONAL epoch anchor for
|
|
591
|
+
* bounded-tail backends. A durable backend that loads only `firstKeptEntryId..leaf` cannot show
|
|
592
|
+
* the branch walk an epoch carrier when a rewind cuts BEFORE the latest compaction's restatement
|
|
593
|
+
* (window: firstKept ≤ cut < compactionEntry) — `Session.getPromptEpoch()` falls back to this
|
|
594
|
+
* method when the loaded branch has no carrier. Implementations return the descriptor from the
|
|
595
|
+
* nearest carrier BELOW the load floor (a `prompt_epoch` entry or a compaction restatement), or
|
|
596
|
+
* undefined when none exists (a genuinely pre-epoch session). File/in-memory backends need not
|
|
597
|
+
* implement it (their walks see the full tree).
|
|
598
|
+
*/
|
|
599
|
+
/** RB-104 (2026-07-25, defect probe): the bounded-window root this storage was woken with (F3), or
|
|
600
|
+
* null/absent for a full-tree load. Optional — a backend that never bounds its wake omits it. Callers
|
|
601
|
+
* use it to tell a LEGITIMATE headless window (its head's parent lives below the declared floor) apart
|
|
602
|
+
* from a CORRUPT log (a head whose parent is simply missing); the two look identical byte-wise and
|
|
603
|
+
* must not be treated alike. `BaseSessionStorage` implements it for the bundled backends. */
|
|
279
604
|
getFloorId?(): string | null;
|
|
280
605
|
getEpochAnchor?(): Promise<{
|
|
281
606
|
epoch: number;
|
|
@@ -285,10 +610,26 @@ export interface SessionStorage<TMetadata extends SessionMetadata = SessionMetad
|
|
|
285
610
|
activatedBy: "session_start" | "compaction" | "legacy_migration";
|
|
286
611
|
} | undefined>;
|
|
287
612
|
}
|
|
613
|
+
/**
|
|
614
|
+
* Options for `buildContext`/`buildSessionContext` — the read-side window awareness seam.
|
|
615
|
+
* `windowTokens` arms a DEFENSIVE re-clamp of the compaction summary's retained invoked-skills
|
|
616
|
+
* area against the CURRENT model's window (the area was budgeted at compaction time against the
|
|
617
|
+
* model active THEN; a later, smaller-window model must not inherit an area that alone overflows
|
|
618
|
+
* its window). `charsPerToken` is the structural coefficient for that clamp (default 4). Absent ⇒
|
|
619
|
+
* legacy behavior, byte-identical context.
|
|
620
|
+
*/
|
|
288
621
|
export interface BuildContextOptions {
|
|
289
622
|
windowTokens?: number;
|
|
290
623
|
charsPerToken?: number;
|
|
291
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* The session CONTRACT the harness consumes (`Session`) — dependency inversion: the substrate defines the
|
|
627
|
+
* interface it needs; the application provides the implementation. Replaces a vendored→first-party
|
|
628
|
+
* `import type { Session }` coupling — the vendored harness no longer reaches into `engine/session/session.ts`
|
|
629
|
+
* for a concrete type, so the substrate is self-contained for the planned de-vendoring. The first-party
|
|
630
|
+
* `class Session` `implements Session`. (Named `Session`, not `Session`, so it coexists with the public,
|
|
631
|
+
* constructable `class Session` without a breaking public-API change.)
|
|
632
|
+
*/
|
|
292
633
|
export interface Session<TMetadata extends SessionMetadata = SessionMetadata> {
|
|
293
634
|
getMetadata(): Promise<TMetadata>;
|
|
294
635
|
getStorage(): SessionStorage<TMetadata>;
|
|
@@ -307,18 +648,31 @@ export interface Session<TMetadata extends SessionMetadata = SessionMetadata> {
|
|
|
307
648
|
appendCustomMessageEntry(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details?: unknown): Promise<string>;
|
|
308
649
|
appendLabel(targetId: string, label: string | undefined): Promise<string>;
|
|
309
650
|
appendSessionName(name: string): Promise<string>;
|
|
651
|
+
/** design/150 (RB-25): persist the listing announced name-sets as a first-class
|
|
652
|
+
* {@link AnnouncedListingEntry} (snapshot semantics; see `Session.appendAnnouncedListing`). */
|
|
310
653
|
appendAnnouncedListing(snapshot: {
|
|
311
654
|
agents?: readonly string[];
|
|
312
655
|
skills?: readonly string[];
|
|
313
656
|
models?: readonly string[];
|
|
314
657
|
}): Promise<string>;
|
|
658
|
+
/** design/150 (RB-25): nearest announced-listing snapshot on the active branch (first rung of the
|
|
659
|
+
* resume-seed ladder); undefined ⇒ pre-entry session. */
|
|
315
660
|
getAnnouncedListing(): Promise<{
|
|
316
661
|
agents?: string[];
|
|
317
662
|
skills?: string[];
|
|
318
663
|
models?: string[];
|
|
319
664
|
} | undefined>;
|
|
665
|
+
/** design/155: persist the settle-time workspace state (tracked cwd + active worktree) as a
|
|
666
|
+
* first-class {@link WorkspaceStateEntry} (snapshot semantics; see `Session.appendWorkspaceState`). */
|
|
320
667
|
appendWorkspaceState(state: WorkspaceState): Promise<string>;
|
|
668
|
+
/** design/155: nearest workspace-state snapshot on the active branch (the continuation rung of the
|
|
669
|
+
* cwd/worktree restore ladder — the checkpoint seed stays first); undefined ⇒ no snapshot visible. */
|
|
321
670
|
getWorkspaceState(): Promise<WorkspaceState | undefined>;
|
|
671
|
+
/** The branch's current prompt-epoch descriptor (semantics: `Session.getPromptEpoch`). OPTIONAL on
|
|
672
|
+
* the interface (typecheck 车 2026-07-24): the built-in `Session` class always implements it;
|
|
673
|
+
* optionality keeps external `Session` implementers compatible. The consumer (`maybeCompact`'s
|
|
674
|
+
* epoch restatement) calls it with `?.()` — an implementer without it degrades to the pre-epoch
|
|
675
|
+
* path (no restatement), never a crash. */
|
|
322
676
|
getPromptEpoch?(): Promise<import("../../prompt-assembly/epoch.js").PromptEpochDescriptor | undefined>;
|
|
323
677
|
}
|
|
324
678
|
export interface SessionCreateOptions {
|
|
@@ -335,7 +689,27 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
|
|
|
335
689
|
list(options?: TListOptions): Promise<TMetadata[]>;
|
|
336
690
|
delete(metadata: TMetadata): Promise<void>;
|
|
337
691
|
fork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;
|
|
692
|
+
/**
|
|
693
|
+
* 2c session-sync (service [266]②): the FULL durable entry log for `sessionId`, oldest-first, with
|
|
694
|
+
* `id`/`parentId` VERBATIM and BYPASSING any compaction floor — NOT `getEntries()`, which on a durable
|
|
695
|
+
* backend that woke with a bounded F3 window returns only the tail (silently truncating pre-floor history).
|
|
696
|
+
* Optional — a backend that supports cross-backend session export/migration implements it.
|
|
697
|
+
*/
|
|
338
698
|
exportEntries?(sessionId: string): Promise<SessionTreeEntry[]>;
|
|
699
|
+
/**
|
|
700
|
+
* 2c session-sync: write a verbatim entry log (produced by {@link exportEntries} on another backend) into
|
|
701
|
+
* `sessionId`, re-stamping ownership to `owner` (from the caller's authenticated principal — never trusted
|
|
702
|
+
* from the bundle). The log MUST be passed through `validateEntriesForImport` first (the single fail-closed
|
|
703
|
+
* invariant gate); a durable backend persists THAT function's output, it does not re-implement the checks.
|
|
704
|
+
* Optional.
|
|
705
|
+
*
|
|
706
|
+
* design/171 §6.4 — `options.preserveActorAssertions` is the OPERATOR-level trusted-import
|
|
707
|
+
* declaration, threaded verbatim into the validator: default (absent/false) strips `actor`
|
|
708
|
+
* attribution from imported history (an importer is not an ingress); `true` = the operator vouches
|
|
709
|
+
* for the source (same-deployment migration) and well-formed assertions survive. A backend that
|
|
710
|
+
* implements this method forwards the flag to its `validateEntriesForImport` call — the gate that
|
|
711
|
+
* actually persists decides, so a pre-validated array cannot be silently re-stripped.
|
|
712
|
+
*/
|
|
339
713
|
importEntries?(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
|
|
340
714
|
preserveActorAssertions?: boolean;
|
|
341
715
|
}): Promise<void>;
|
|
@@ -380,7 +754,9 @@ export interface ContextEvent {
|
|
|
380
754
|
messages: AgentMessage[];
|
|
381
755
|
}
|
|
382
756
|
export interface TurnBoundaryEvent {
|
|
757
|
+
/** Fires between model-request boundaries, after session flush, before the context rebuild. */
|
|
383
758
|
type: "turn_boundary";
|
|
759
|
+
/** The model that will run the next turn (authoritative under a mid-task model switch). */
|
|
384
760
|
model: Model;
|
|
385
761
|
}
|
|
386
762
|
export interface BeforeProviderRequestEvent {
|
|
@@ -444,25 +820,52 @@ export interface ResourcesUpdateEvent<TSkill extends Skill = Skill, TPromptTempl
|
|
|
444
820
|
}
|
|
445
821
|
export type AgentHarnessOwnEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> = QueueUpdateEvent | SavePointEvent | AbortEvent | SettledEvent | BeforeAgentStartEvent<TSkill, TPromptTemplate> | ContextEvent | TurnBoundaryEvent | BeforeProviderRequestEvent | BeforeProviderPayloadEvent | AfterProviderResponseEvent | ToolCallEvent | ToolResultEvent | SessionBeforeCompactEvent | SessionCompactEvent | ModelSelectEvent | ThinkingLevelSelectEvent | ResourcesUpdateEvent<TSkill, TPromptTemplate>;
|
|
446
822
|
export type AgentHarnessEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> = AgentEvent | AgentHarnessOwnEvent<TSkill, TPromptTemplate>;
|
|
823
|
+
/** Hook result for mutating the initial prompt run before the agent starts. */
|
|
447
824
|
export interface BeforeAgentStartResult {
|
|
825
|
+
/** Replacement messages for the prompt run. */
|
|
448
826
|
messages?: AgentMessage[];
|
|
827
|
+
/** Replacement system prompt for the prompt run. */
|
|
449
828
|
systemPrompt?: string;
|
|
450
829
|
}
|
|
830
|
+
/** Hook result for replacing the full context message list before provider conversion. */
|
|
451
831
|
export interface ContextResult {
|
|
452
832
|
messages: AgentMessage[];
|
|
453
833
|
}
|
|
834
|
+
/** Hook result for patching provider request options before payload construction. */
|
|
454
835
|
export interface BeforeProviderRequestResult {
|
|
455
836
|
streamOptions?: AgentHarnessStreamOptionsPatch;
|
|
456
837
|
}
|
|
838
|
+
/** Hook result for replacing the provider payload after construction. */
|
|
457
839
|
export interface BeforeProviderPayloadResult {
|
|
458
840
|
payload: unknown;
|
|
459
841
|
}
|
|
842
|
+
/**
|
|
843
|
+
* Hook result for blocking a tool call before execution, or rewriting its arguments.
|
|
844
|
+
*
|
|
845
|
+
* `block: true` blocks the call (`reason` becomes the error text). `updatedInput` (without `block`)
|
|
846
|
+
* rewrites the args the tool executes with — re-validated against the tool schema by the loop before
|
|
847
|
+
* execution (design/37). `block` wins over `updatedInput`.
|
|
848
|
+
*
|
|
849
|
+
* REF-D23 — this IS the loop's `BeforeToolCallResult`, not a hand-kept structural match of it. The
|
|
850
|
+
* `beforeToolCall` callback in agent-harness.ts returns the hook result verbatim, so the two shapes
|
|
851
|
+
* were never allowed to differ; the earlier "keep in sync" note asked a human to maintain by hand
|
|
852
|
+
* what the type system can state.
|
|
853
|
+
*/
|
|
460
854
|
export type ToolCallResult = BeforeToolCallResult;
|
|
855
|
+
/**
|
|
856
|
+
* Hook patch for a completed tool result before it is persisted/emitted.
|
|
857
|
+
*
|
|
858
|
+
* REF-D23 — same relationship as {@link ToolCallResult}: this IS the loop's `AfterToolCallResult`.
|
|
859
|
+
* The `afterToolCall` callback forwards the hook result verbatim, so a field added on the loop side
|
|
860
|
+
* reaches the harness hook surface without a second edit here.
|
|
861
|
+
*/
|
|
461
862
|
export type ToolResultPatch = AfterToolCallResult;
|
|
863
|
+
/** Hook result for cancelling or replacing a planned compaction. */
|
|
462
864
|
export interface SessionBeforeCompactResult {
|
|
463
865
|
cancel?: boolean;
|
|
464
866
|
compaction?: CompactResult;
|
|
465
867
|
}
|
|
868
|
+
/** Typed return values expected from AgentHarness hook handlers by event type. */
|
|
466
869
|
export type AgentHarnessEventResultMap = {
|
|
467
870
|
before_agent_start: BeforeAgentStartResult | undefined;
|
|
468
871
|
context: ContextResult | undefined;
|
|
@@ -482,22 +885,31 @@ export type AgentHarnessEventResultMap = {
|
|
|
482
885
|
abort: undefined;
|
|
483
886
|
settled: undefined;
|
|
484
887
|
};
|
|
888
|
+
/** Queued messages removed by an abort operation. */
|
|
485
889
|
export interface AbortResult {
|
|
486
890
|
clearedSteer: AgentMessage[];
|
|
487
891
|
clearedFollowUp: AgentMessage[];
|
|
488
892
|
}
|
|
893
|
+
/** Compaction data supplied by hooks or returned from compaction preparation. */
|
|
489
894
|
export interface CompactResult {
|
|
490
895
|
summary: string;
|
|
491
896
|
firstKeptEntryId: string;
|
|
492
897
|
tokensBefore: number;
|
|
493
898
|
details?: unknown;
|
|
494
899
|
}
|
|
900
|
+
/** Settings that control automatic context compaction. */
|
|
495
901
|
export interface CompactionSettings {
|
|
496
902
|
enabled: boolean;
|
|
497
903
|
reserveTokens: number;
|
|
498
904
|
keepRecentTokens: number;
|
|
905
|
+
/** design/145 §1 — window-safety clamp tolerance for an independent (smaller-window) compaction
|
|
906
|
+
* model: when the summarization input would be clamp-truncated by MORE than this ratio, the
|
|
907
|
+
* summary call becomes a candidate to fall back to the MAIN model (which is always window-safe).
|
|
908
|
+
* 0 = any truncation is a fallback candidate; 1 = never fall back (the pre-145 clamp-only
|
|
909
|
+
* behavior). Default 0.10. */
|
|
499
910
|
clampTolerance?: number;
|
|
500
911
|
}
|
|
912
|
+
/** Prepared compaction inputs exposed to hooks before a summary is generated. */
|
|
501
913
|
export interface CompactionPreparation {
|
|
502
914
|
firstKeptEntryId: string;
|
|
503
915
|
messagesToSummarize: AgentMessage[];
|
|
@@ -508,15 +920,21 @@ export interface CompactionPreparation {
|
|
|
508
920
|
fileOps: FileOperations;
|
|
509
921
|
settings: CompactionSettings;
|
|
510
922
|
}
|
|
923
|
+
/** File operations accumulated from summarized transcript ranges. */
|
|
511
924
|
export interface FileOperations {
|
|
512
925
|
read: Set<string>;
|
|
513
926
|
written: Set<string>;
|
|
514
927
|
edited: Set<string>;
|
|
515
928
|
}
|
|
929
|
+
/** Construction options for AgentHarness. */
|
|
516
930
|
export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate, TTool extends AgentTool = AgentTool> {
|
|
517
931
|
env: ExecutionEnv;
|
|
518
932
|
session: Session;
|
|
519
933
|
tools?: TTool[];
|
|
934
|
+
/**
|
|
935
|
+
* Concrete resources available to explicit invocation methods and system-prompt callbacks.
|
|
936
|
+
* Applications own loading/reloading resources and should call `setResources()` with new values.
|
|
937
|
+
*/
|
|
520
938
|
resources?: AgentHarnessResources<TSkill, TPromptTemplate>;
|
|
521
939
|
systemPrompt?: string | ((context: {
|
|
522
940
|
env: ExecutionEnv;
|
|
@@ -526,6 +944,12 @@ export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTempla
|
|
|
526
944
|
activeTools: TTool[];
|
|
527
945
|
resources: AgentHarnessResources<TSkill, TPromptTemplate>;
|
|
528
946
|
}) => string | Promise<string>);
|
|
947
|
+
/**
|
|
948
|
+
* Campaign S4 (ADDITIVE): physical system blocks for block-aware Brains. Static per leg (same
|
|
949
|
+
* freeze semantics as a string `systemPrompt`). When present it MUST correspond to the same
|
|
950
|
+
* bytes as `systemPrompt` (the M13 projection duty is on the producer — prepare-task). Brains
|
|
951
|
+
* that ignore it read `systemPrompt` and lose nothing.
|
|
952
|
+
*/
|
|
529
953
|
systemBlocks?: Array<{
|
|
530
954
|
text: string;
|
|
531
955
|
cacheControlBoundary: boolean;
|
|
@@ -535,19 +959,57 @@ export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTempla
|
|
|
535
959
|
headers?: Record<string, string>;
|
|
536
960
|
} | undefined>;
|
|
537
961
|
runtime?: AgentCoreRuntimeDeps;
|
|
962
|
+
/** Curated stream/provider request options. Snapshotted at turn start. */
|
|
538
963
|
streamOptions?: AgentHarnessStreamOptions;
|
|
539
964
|
model: Model;
|
|
540
965
|
thinkingLevel?: ThinkingLevel;
|
|
541
966
|
activeToolNames?: string[];
|
|
542
967
|
steeringMode?: QueueMode;
|
|
543
968
|
followUpMode?: QueueMode;
|
|
969
|
+
/** design/119 #2: per-request output-token cap forwarded to the provider (`options.maxTokens`). */
|
|
544
970
|
maxOutputTokens?: number;
|
|
971
|
+
/**
|
|
972
|
+
* design/130 P1: per-CALL dynamic output cap, evaluated by the loop immediately before EACH
|
|
973
|
+
* provider call. A number return overrides `maxOutputTokens` for that call only; undefined
|
|
974
|
+
* leaves the static chain untouched. Must be cheap (hot path).
|
|
975
|
+
*/
|
|
545
976
|
maxOutputTokensPerCall?: () => number | undefined;
|
|
977
|
+
/**
|
|
978
|
+
* 1.296 件A: per-CALL advisory stall watchdogs, evaluated by the loop immediately before EACH
|
|
979
|
+
* provider call and forwarded as `StreamOptions.stallTimeouts` (brain construction-time config
|
|
980
|
+
* wins when present — advisory, not an override). undefined return ⇒ nothing supplied.
|
|
981
|
+
*/
|
|
546
982
|
stallTimeoutsPerCall?: () => import("../llm/types.js").StallTimeouts | undefined;
|
|
983
|
+
/**
|
|
984
|
+
* Abort-classification seam for the loop's abort short-circuit tool results, forwarded verbatim
|
|
985
|
+
* to the loop config (`AgentLoopConfig.abortResultDetails`, see its JSDoc for the contract): a
|
|
986
|
+
* non-undefined return value becomes the minted result's `details` (e.g. `{ code: "gate.parked" }`
|
|
987
|
+
* when the host's durable approval gate parked the batch). Evaluated at mint time; the abort
|
|
988
|
+
* texts themselves never change.
|
|
989
|
+
*/
|
|
547
990
|
abortResultDetails?: () => Record<string, unknown> | undefined;
|
|
991
|
+
/**
|
|
992
|
+
* service [398] C2: the loop's recovery/terminal trace sink, forwarded to `runAgentLoop`'s trace
|
|
993
|
+
* parameter (previously test-only — never passed in production, so the loop's six self-heal
|
|
994
|
+
* recoveries were invisible outside display:false nudge messages). Must not throw; hot path.
|
|
995
|
+
*/
|
|
548
996
|
loopTrace?: (step: import("../loop/agent-loop.js").LoopStep) => void;
|
|
997
|
+
/**
|
|
998
|
+
* design/131 (service [404] 拍): per-task resilience intent flags, forwarded to every provider
|
|
999
|
+
* call (`StreamOptions.resilience`) so the deployment's decorator stack (degrading / failover /
|
|
1000
|
+
* breaker) can stand aside for this task. Absent ⇒ today's behavior.
|
|
1001
|
+
*/
|
|
549
1002
|
resilience?: import("../llm/types.js").ResilienceOptions;
|
|
1003
|
+
/** design/120 P1: parallel-batch tool concurrency cap forwarded to the loop (default 10). */
|
|
550
1004
|
maxToolConcurrency?: number;
|
|
1005
|
+
/**
|
|
1006
|
+
* design/120 P2: opt in to in-stream tool execution (safe tool calls start while the model is
|
|
1007
|
+
* still streaming). Default OFF. The harness forwards this to the loop ONLY when no `tool_call`
|
|
1008
|
+
* hook handler is registered at run start (snapshot per prompt()) — a policy/approval gate on
|
|
1009
|
+
* that hook could durably suspend, which has no stable leaf mid-stream. Hosts that register a
|
|
1010
|
+
* suspending `tool_call` handler mid-run after opting in get undefined behavior (documented
|
|
1011
|
+
* contract, see AgentLoopConfig.streamingToolExecution).
|
|
1012
|
+
*/
|
|
551
1013
|
streamingToolExecution?: boolean;
|
|
552
1014
|
}
|
|
553
1015
|
export type { AgentHarness } from "./agent-harness.js";
|