@sema-agent/core 1.451.0 → 2.0.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.
Files changed (191) hide show
  1. package/dist/agents/agent-transcript-tool.d.ts +15 -0
  2. package/dist/agents/agent-transcript-tool.js +122 -0
  3. package/dist/agents/cascade.js +5 -8
  4. package/dist/agents/observer.js +3 -0
  5. package/dist/agents/repair-loop.d.ts +1 -1
  6. package/dist/agents/repair-loop.js +1 -1
  7. package/dist/agents/retain-ledger.d.ts +60 -0
  8. package/dist/agents/retain-ledger.js +225 -0
  9. package/dist/agents/roster-store.d.ts +1 -0
  10. package/dist/agents/roster-store.js +9 -0
  11. package/dist/agents/send-message-tool.d.ts +41 -0
  12. package/dist/agents/send-message-tool.js +469 -0
  13. package/dist/agents/subagent.d.ts +33 -108
  14. package/dist/agents/subagent.js +40 -813
  15. package/dist/agents/teacher.d.ts +0 -1
  16. package/dist/agents/teacher.js +0 -9
  17. package/dist/bin/sema-tb.js +3 -3
  18. package/dist/brain/anthropic.js +15 -40
  19. package/dist/brain/openai.js +15 -40
  20. package/dist/brain/reasoning.d.ts +1 -1
  21. package/dist/brain/stream-engine.js +2 -2
  22. package/dist/brain/stream-shared.d.ts +17 -0
  23. package/dist/brain/stream-shared.js +50 -0
  24. package/dist/brain/timeout.d.ts +1 -1
  25. package/dist/brain/timeout.js +1 -1
  26. package/dist/config/catalog.js +1 -3
  27. package/dist/config/defaults.d.ts +6 -0
  28. package/dist/config/defaults.js +6 -0
  29. package/dist/core/ask-question.d.ts +1 -1
  30. package/dist/core/ask-question.js +5 -5
  31. package/dist/core/background-agent-store.d.ts +2 -0
  32. package/dist/core/background-agent-store.js +5 -1
  33. package/dist/core/background-shell.d.ts +1 -1
  34. package/dist/core/checkpoint-store.d.ts +0 -1
  35. package/dist/core/exec-gate.d.ts +1 -1
  36. package/dist/core/exec-output-tail.d.ts +19 -1
  37. package/dist/core/exec-output-tail.js +44 -5
  38. package/dist/core/file-snapshot-store.d.ts +1 -1
  39. package/dist/core/fs-write-gate-policy.d.ts +1 -1
  40. package/dist/core/git-worktree-env.d.ts +1 -1
  41. package/dist/core/hooks.d.ts +1 -1
  42. package/dist/core/image-downsample.d.ts +44 -0
  43. package/dist/core/image-downsample.js +97 -0
  44. package/dist/core/lsp-session.d.ts +1 -0
  45. package/dist/core/lsp-session.js +24 -6
  46. package/dist/core/lsp.d.ts +11 -1
  47. package/dist/core/lsp.js +63 -6
  48. package/dist/core/mailbox-store.d.ts +3 -2
  49. package/dist/core/mailbox-store.js +19 -4
  50. package/dist/core/mcp.d.ts +3 -45
  51. package/dist/core/mcp.js +2 -97
  52. package/dist/core/media-byte-cap.d.ts +1 -1
  53. package/dist/core/memory-recall.d.ts +0 -12
  54. package/dist/core/memory-recall.js +0 -222
  55. package/dist/core/memory.d.ts +0 -6
  56. package/dist/core/memory.js +0 -88
  57. package/dist/core/message-utils.d.ts +1 -1
  58. package/dist/core/oracle-isolation.d.ts +1 -1
  59. package/dist/core/remote-env.d.ts +1 -1
  60. package/dist/core/roles.d.ts +1 -1
  61. package/dist/core/runner/active-skill-scope.d.ts +1 -1
  62. package/dist/core/runner/assemble-result.d.ts +0 -2
  63. package/dist/core/runner/memory-consolidation.d.ts +1 -1
  64. package/dist/core/runner/prepare-memory.d.ts +16 -0
  65. package/dist/core/runner/prepare-memory.js +191 -0
  66. package/dist/core/runner/prepare-task.d.ts +4 -28
  67. package/dist/core/runner/prepare-task.js +29 -208
  68. package/dist/core/runner/prompt-suggestions.d.ts +1 -1
  69. package/dist/core/runner/runtask.d.ts +2 -3
  70. package/dist/core/runner/runtask.js +337 -529
  71. package/dist/core/runner/session-rule-policy.d.ts +1 -1
  72. package/dist/core/runner/synthetic-tools.d.ts +5 -5
  73. package/dist/core/runner/synthetic-tools.js +4 -4
  74. package/dist/core/runner/tool-disclosure.d.ts +3 -3
  75. package/dist/core/runner/tool-disclosure.js +2 -2
  76. package/dist/core/runner/tool-output-projection.d.ts +6 -0
  77. package/dist/core/runner/tool-output-projection.js +81 -0
  78. package/dist/core/runtime.d.ts +1 -1
  79. package/dist/core/scheduler.d.ts +1 -1
  80. package/dist/core/sensitive-path-policy.d.ts +1 -1
  81. package/dist/core/session-reconcile.d.ts +1 -1
  82. package/dist/core/session-reconcile.js +5 -2
  83. package/dist/core/session-store.d.ts +2 -1
  84. package/dist/core/session-store.js +2 -1
  85. package/dist/core/session.d.ts +0 -1
  86. package/dist/core/task-notification.d.ts +1 -0
  87. package/dist/core/task-registry-agent.d.ts +115 -0
  88. package/dist/core/task-registry-agent.js +1163 -0
  89. package/dist/core/task-registry-monitor.d.ts +13 -0
  90. package/dist/core/task-registry-monitor.js +347 -0
  91. package/dist/core/task-registry-shared.d.ts +294 -0
  92. package/dist/core/task-registry-shared.js +271 -0
  93. package/dist/core/task-registry-workflow.d.ts +5 -0
  94. package/dist/core/task-registry-workflow.js +143 -0
  95. package/dist/core/task-registry.d.ts +54 -213
  96. package/dist/core/task-registry.js +190 -1766
  97. package/dist/core/task-tool-shape.d.ts +32 -0
  98. package/dist/core/task-tool-shape.js +83 -0
  99. package/dist/core/tool-policy.d.ts +1 -2
  100. package/dist/core/tool-result-budget.d.ts +1 -1
  101. package/dist/core/tool-result-store.d.ts +2 -2
  102. package/dist/core/tool-result-store.js +3 -3
  103. package/dist/core/tools.d.ts +7 -3
  104. package/dist/core/tools.js +3 -8
  105. package/dist/core/trace.d.ts +2 -2
  106. package/dist/core/types.d.ts +1 -29
  107. package/dist/core/workflow-journal-store.d.ts +2 -0
  108. package/dist/core/workflow-journal-store.js +14 -0
  109. package/dist/core/workflow-run-store-contract.d.ts +1 -1
  110. package/dist/core/workflow-run-store-contract.js +19 -19
  111. package/dist/engine/execution-env/node-execution-env.d.ts +14 -0
  112. package/dist/engine/execution-env/node-execution-env.js +184 -44
  113. package/dist/engine/lsp/frame-decoder.d.ts +1 -1
  114. package/dist/engine/lsp/frame-decoder.js +1 -1
  115. package/dist/engine/lsp/node-lsp-manager.d.ts +4 -2
  116. package/dist/engine/lsp/node-lsp-manager.js +22 -5
  117. package/dist/engine/lsp/stdio-lsp-transport.d.ts +1 -1
  118. package/dist/engine/lsp/stdio-lsp-transport.js +19 -8
  119. package/dist/index.d.ts +18 -16
  120. package/dist/index.js +15 -13
  121. package/dist/internal/harness-types.d.ts +7 -0
  122. package/dist/internal/harness-types.js +1 -0
  123. package/dist/internal/harness.d.ts +1 -7
  124. package/dist/internal/harness.js +1 -0
  125. package/dist/orchestration/goal.js +2 -2
  126. package/dist/orchestration/run-workflow-tool.d.ts +2 -1
  127. package/dist/orchestration/run-workflow-tool.js +29 -6
  128. package/dist/orchestration/workflow-types.d.ts +193 -0
  129. package/dist/orchestration/workflow-types.js +54 -0
  130. package/dist/orchestration/workflow.d.ts +3 -184
  131. package/dist/orchestration/workflow.js +87 -64
  132. package/dist/prompt-assembly/assemble.d.ts +3 -3
  133. package/dist/prompt-assembly/assemble.js +0 -16
  134. package/dist/prompt-assembly/explain.d.ts +1 -1
  135. package/dist/prompt-assembly/tool-catalog.d.ts +1 -1
  136. package/dist/prompts/default.d.ts +1 -6
  137. package/dist/prompts/default.js +3 -11
  138. package/dist/scenarios/env.d.ts +1 -1
  139. package/dist/scenarios/full-body.d.ts +0 -3
  140. package/dist/scenarios/full-body.js +0 -2
  141. package/dist/stores/cc/mailbox-store.js +6 -1
  142. package/dist/stores/file/background-agent-store.d.ts +2 -15
  143. package/dist/stores/file/background-agent-store.js +33 -102
  144. package/dist/stores/file/checkpoint-store.d.ts +1 -14
  145. package/dist/stores/file/checkpoint-store.js +47 -119
  146. package/dist/stores/file/file-snapshot-store.d.ts +1 -1
  147. package/dist/stores/file/mailbox-store.d.ts +1 -1
  148. package/dist/stores/file/mailbox-store.js +9 -7
  149. package/dist/stores/file/shared-ledger.d.ts +35 -0
  150. package/dist/stores/file/shared-ledger.js +94 -0
  151. package/dist/stores/file/workflow-run-store.d.ts +1 -14
  152. package/dist/stores/file/workflow-run-store.js +24 -93
  153. package/dist/tools/fs/bash-readonly-classifier.d.ts +8 -0
  154. package/dist/tools/fs/bash-readonly-classifier.js +166 -0
  155. package/dist/tools/fs/encoding.d.ts +5 -0
  156. package/dist/tools/fs/encoding.js +6 -0
  157. package/dist/tools/fs/fs-bash.d.ts +31 -0
  158. package/dist/tools/fs/fs-bash.js +672 -0
  159. package/dist/tools/fs/fs-pdf.d.ts +22 -0
  160. package/dist/tools/fs/fs-pdf.js +236 -0
  161. package/dist/tools/fs/fs-read.d.ts +8 -0
  162. package/dist/tools/fs/fs-read.js +286 -0
  163. package/dist/tools/fs/fs-search-tools.d.ts +5 -0
  164. package/dist/tools/fs/fs-search-tools.js +173 -0
  165. package/dist/tools/fs/fs-shared.d.ts +55 -0
  166. package/dist/tools/fs/fs-shared.js +144 -0
  167. package/dist/tools/fs/fs-write.d.ts +8 -0
  168. package/dist/tools/fs/fs-write.js +423 -0
  169. package/dist/tools/fs/index.d.ts +12 -65
  170. package/dist/tools/fs/index.js +26 -2026
  171. package/dist/tools/fs/notebook.d.ts +43 -0
  172. package/dist/tools/fs/notebook.js +141 -0
  173. package/dist/tools/fs/pdf.d.ts +1 -1
  174. package/dist/tools/fs/repo-map.d.ts +3 -3
  175. package/dist/tools/fs/repo-map.js +3 -3
  176. package/dist/tools/fs/safety.d.ts +1 -1
  177. package/dist/tools/fs/search.d.ts +1 -1
  178. package/dist/tools/fs/search.js +141 -12
  179. package/dist/tools/gitea-issue.js +4 -2
  180. package/dist/tools/monitor.d.ts +1 -1
  181. package/dist/tools/monitor.js +12 -8
  182. package/dist/tools/scheduler-tools.d.ts +1 -1
  183. package/dist/tools/scheduler-tools.js +16 -16
  184. package/dist/tools/task-list.js +34 -12
  185. package/dist/tools/web.d.ts +4 -2
  186. package/dist/tools/web.js +106 -20
  187. package/dist/tools/worktree.d.ts +1 -1
  188. package/dist/tools/worktree.js +14 -14
  189. package/package.json +1 -1
  190. package/dist/core/dynamic-recall.d.ts +0 -32
  191. package/dist/core/dynamic-recall.js +0 -76
@@ -0,0 +1,32 @@
1
+ import { Type } from "typebox";
2
+ export declare const TASK_OUTPUT_TOOL_NAME = "TaskOutput";
3
+ export declare const TASK_STOP_TOOL_NAME = "TaskStop";
4
+ export declare const TASK_OUTPUT_ALIASES: readonly ["BashOutput", "AgentOutputTool", "BashOutputTool", "AgentOutput", "WorkflowStatus"];
5
+ export declare const TASK_STOP_ALIASES: readonly ["KillShell", "KillBash"];
6
+ export declare const TASK_OUTPUT_CONTRACT: {
7
+ readonly contractId: "core.task_output@1";
8
+ readonly implementationRevision: "1";
9
+ };
10
+ export declare const TASK_STOP_CONTRACT: {
11
+ readonly contractId: "core.task_stop@1";
12
+ readonly implementationRevision: "1";
13
+ };
14
+ export declare const TASK_OUTPUT_MISSING_ID_MESSAGE = "Error (TaskOutput): Missing required parameter: task_id";
15
+ export declare const TASK_STOP_MISSING_ID_MESSAGE = "Missing required parameter: task_id";
16
+ export declare const TASK_STOP_PARAMS: Type.TObject<{
17
+ task_id: Type.TOptional<Type.TString>;
18
+ shell_id: Type.TOptional<Type.TString>;
19
+ }>;
20
+ export declare function resolveTaskIdArg(...values: unknown[]): string | undefined;
21
+ export interface TaskToolCapabilities {
22
+ lanes: boolean;
23
+ outputFile: boolean;
24
+ notification: boolean;
25
+ blockWait: boolean;
26
+ nameAddressing: boolean;
27
+ }
28
+ export declare const REGISTRY_TASK_TOOL_CAPS: TaskToolCapabilities;
29
+ export declare const ENV_DIRECT_TASK_TOOL_CAPS: TaskToolCapabilities;
30
+ export declare function composeTaskOutputDescription(caps: TaskToolCapabilities): string;
31
+ export declare function composeTaskStopDescription(caps: TaskToolCapabilities): string;
32
+ export declare function composeTaskOutputParams(caps: Pick<TaskToolCapabilities, "blockWait" | "lanes">): ReturnType<typeof Type.Object>;
@@ -0,0 +1,83 @@
1
+ import { Type } from "typebox";
2
+ export const TASK_OUTPUT_TOOL_NAME = "TaskOutput";
3
+ export const TASK_STOP_TOOL_NAME = "TaskStop";
4
+ export const TASK_OUTPUT_ALIASES = ["BashOutput", "AgentOutputTool", "BashOutputTool", "AgentOutput", "WorkflowStatus"];
5
+ export const TASK_STOP_ALIASES = ["KillShell", "KillBash"];
6
+ export const TASK_OUTPUT_CONTRACT = { contractId: "core.task_output@1", implementationRevision: "1" };
7
+ export const TASK_STOP_CONTRACT = { contractId: "core.task_stop@1", implementationRevision: "1" };
8
+ export const TASK_OUTPUT_MISSING_ID_MESSAGE = "Error (TaskOutput): Missing required parameter: task_id";
9
+ export const TASK_STOP_MISSING_ID_MESSAGE = "Missing required parameter: task_id";
10
+ export const TASK_STOP_PARAMS = Type.Object({
11
+ task_id: Type.Optional(Type.String({ description: "The ID of the background task to stop" })),
12
+ shell_id: Type.Optional(Type.String({ description: "Deprecated: use task_id instead" })),
13
+ });
14
+ export function resolveTaskIdArg(...values) {
15
+ for (const value of values) {
16
+ if (typeof value === "string" && value.trim() !== "")
17
+ return value.trim();
18
+ }
19
+ return undefined;
20
+ }
21
+ export const REGISTRY_TASK_TOOL_CAPS = {
22
+ lanes: true,
23
+ outputFile: true,
24
+ notification: true,
25
+ blockWait: true,
26
+ nameAddressing: true,
27
+ };
28
+ export const ENV_DIRECT_TASK_TOOL_CAPS = {
29
+ lanes: false,
30
+ outputFile: false,
31
+ notification: false,
32
+ blockWait: false,
33
+ nameAddressing: false,
34
+ };
35
+ export function composeTaskOutputDescription(caps) {
36
+ const parts = [];
37
+ if (caps.outputFile) {
38
+ parts.push("[Deprecated] — for background Bash tasks, prefer Read on the output file path; for agent tasks, use the Agent tool result directly. " +
39
+ "DEPRECATED: Background tasks return their output file path in the tool result" +
40
+ (caps.notification ? ", and you receive a <task-notification> with the same path when the task completes. " : ". "));
41
+ }
42
+ parts.push("Retrieve output or status for a background task by task_id. ");
43
+ parts.push(caps.lanes
44
+ ? "Supports background Bash tasks and workflow tasks returned by RunWorkflow. Returns only the caller's own task scope; unknown and out-of-scope ids are " +
45
+ "reported the same way. "
46
+ : "Reads a background shell started with Bash(run_in_background): returns the run status (running / exited(code) / killed / failed) plus NEW stdout/stderr since your last call. ");
47
+ if (!caps.notification) {
48
+ parts.push('When using a background command as a wait condition, call this repeatedly until status is no longer "running" — completion ' +
49
+ "is signalled by status/exitCode, not by any automatic notification; after you see a terminal status, one more " +
50
+ "poll captures any final output. ");
51
+ }
52
+ if (!caps.lanes)
53
+ parts.push("Optional `filter` is a regex keeping only matching lines. ");
54
+ parts.push("Legacy bash_id and runId arguments are accepted for compatibility.");
55
+ return parts.join("");
56
+ }
57
+ export function composeTaskStopDescription(caps) {
58
+ return [
59
+ "- Stops a running background task by its ID",
60
+ "- Takes a task_id parameter identifying the task to stop",
61
+ ...(caps.nameAddressing ? ["- To stop a background agent spawned with a name, pass that name as task_id"] : []),
62
+ "- Returns a success or failure status",
63
+ "- Use this tool when you need to terminate a long-running task",
64
+ ].join("\n");
65
+ }
66
+ export function composeTaskOutputParams(caps) {
67
+ return Type.Object({
68
+ task_id: Type.Optional(Type.String({
69
+ description: caps.lanes
70
+ ? "The task_id returned by Bash(run_in_background) or RunWorkflow."
71
+ : "The task_id returned by Bash(run_in_background).",
72
+ })),
73
+ ...(caps.blockWait
74
+ ? {
75
+ block: Type.Optional(Type.Boolean({
76
+ description: "Whether to wait for completion (default true — the call waits until the task finishes or `timeout`, saving re-poll turns). Pass false for an instantaneous snapshot.",
77
+ })),
78
+ timeout: Type.Optional(Type.Number({ description: "Optional timeout in milliseconds when block is true (default 30000, max 600000)." })),
79
+ }
80
+ : {}),
81
+ filter: Type.Optional(Type.String({ description: "Optional regex filter for background Bash output (sema extension)." })),
82
+ });
83
+ }
@@ -29,10 +29,9 @@ export type PermissionResult = {
29
29
  reason?: string;
30
30
  decisionReason?: DecisionReason;
31
31
  };
32
- export type ToolDecision = PermissionResult;
33
32
  export declare function decisionText(d: PermissionResult): string | undefined;
34
33
  export interface ToolPolicy {
35
- check(req: ToolCallRequest, signal?: AbortSignal): ToolDecision | Promise<ToolDecision>;
34
+ check(req: ToolCallRequest, signal?: AbortSignal): PermissionResult | Promise<PermissionResult>;
36
35
  }
37
36
  export interface ToolPolicyNameSets {
38
37
  readonly allow?: readonly string[];
@@ -1,4 +1,4 @@
1
- import type { AgentMessage } from "../internal/harness.js";
1
+ import type { AgentMessage } from "../internal/harness-types.js";
2
2
  import { type ToolResultStore } from "./tool-result-store.js";
3
3
  export declare const AGGREGATE_TOOL_RESULT_BUDGET_CHARS = 200000;
4
4
  export interface AggregateBudgetOptions {
@@ -1,4 +1,4 @@
1
- import type { AgentTool } from "../internal/harness.js";
1
+ import type { AgentTool } from "../internal/harness-types.js";
2
2
  export interface ToolResultStore {
3
3
  put(ref: string, content: string): Promise<void> | void;
4
4
  get(ref: string, opts?: {
@@ -54,4 +54,4 @@ export declare function buildPreview(full: string, ref: string, sizes?: {
54
54
  tail: number;
55
55
  }): string;
56
56
  export declare function withToolResultOffload(tool: AgentTool, store: ToolResultStore, thresholdChars: number, sessionId: string): AgentTool;
57
- export declare function makeReadToolResultTool(store: ToolResultStore): AgentTool;
57
+ export declare function createReadToolResultTool(store: ToolResultStore): AgentTool;
@@ -1,5 +1,5 @@
1
1
  import { Type } from "typebox";
2
- import { defineTool } from "./tools.js";
2
+ import { defineTool, errorResult } from "./tools.js";
3
3
  export class InMemoryToolResultStore {
4
4
  opts;
5
5
  map = new Map();
@@ -128,7 +128,7 @@ export function withToolResultOffload(tool, store, thresholdChars, sessionId) {
128
128
  };
129
129
  return { ...tool, execute: wrappedExecute };
130
130
  }
131
- export function makeReadToolResultTool(store) {
131
+ export function createReadToolResultTool(store) {
132
132
  return defineTool({
133
133
  name: OFFLOAD_TOOL_NAME,
134
134
  contract: { contractId: "core.read_tool_result@1", implementationRevision: "1" },
@@ -146,7 +146,7 @@ export function makeReadToolResultTool(store) {
146
146
  const lim = Math.min(READ_MAX_LIMIT, Math.max(1, intOr(limit, READ_DEFAULT_LIMIT)));
147
147
  const slice = await store.get(ref, { offset: off, limit: lim });
148
148
  if (!slice) {
149
- return `No persisted output for ref "${ref}" — it may have expired, or this process has no durable tool-result store (the preview above is all that remains).`;
149
+ return errorResult(`No persisted output for ref "${ref}" — it may have expired, or this process has no durable tool-result store (the preview above is all that remains).`);
150
150
  }
151
151
  const end = slice.offset + slice.content.length;
152
152
  const more = end < slice.totalChars ? `\n…[${slice.totalChars - end} more chars — call again with offset=${end}.]` : "";
@@ -1,5 +1,9 @@
1
1
  import type { TSchema } from "typebox";
2
- import type { AgentTool, Skill } from "../internal/harness.js";
3
- import type { SkillSpec, ToolSpec } from "./types.js";
2
+ import type { AgentTool } from "../internal/harness.js";
3
+ import type { ToolSpec } from "./types.js";
4
+ export declare function errorResult(text: string, details?: unknown): {
5
+ content: string;
6
+ isError: true;
7
+ details?: unknown;
8
+ };
4
9
  export declare function defineTool<TParams extends TSchema = TSchema>(spec: ToolSpec<TParams>): AgentTool<TParams>;
5
- export declare function toSkill(spec: SkillSpec): Skill;
@@ -22,6 +22,9 @@ function isEmptyToolContent(content) {
22
22
  return true;
23
23
  return content.every((b) => b.type === "text" && (typeof b.text !== "string" || b.text.trim() === ""));
24
24
  }
25
+ export function errorResult(text, details) {
26
+ return details === undefined ? { content: text, isError: true } : { content: text, isError: true, details };
27
+ }
25
28
  export function defineTool(spec) {
26
29
  const executionMode = spec.executionMode ?? (spec.effect === "read" ? "parallel" : "sequential");
27
30
  const tool = {
@@ -70,11 +73,3 @@ export function defineTool(spec) {
70
73
  }
71
74
  return tool;
72
75
  }
73
- export function toSkill(spec) {
74
- return {
75
- name: spec.name,
76
- description: spec.description,
77
- content: spec.content,
78
- filePath: `memory://skills/${spec.name}`,
79
- };
80
- }
@@ -1,5 +1,5 @@
1
1
  import type { TaskStatus, ToolEffect } from "./types.js";
2
- import type { ThinkingLevel } from "../internal/harness.js";
2
+ import type { ThinkingLevel } from "../internal/harness-types.js";
3
3
  export interface TraceMechanismsSummary {
4
4
  finalizeInjected?: true;
5
5
  nudgesSent?: number;
@@ -26,7 +26,7 @@ export type TraceEvent = {
26
26
  kind: "prompt.assembled";
27
27
  version: 1;
28
28
  taskId: string;
29
- constitution: "core" | "replaced" | "provider-assembled" | "legacy";
29
+ constitution: "core" | "replaced" | "provider-assembled";
30
30
  blocks: Array<{
31
31
  id: string;
32
32
  chars: number;
@@ -87,7 +87,6 @@ export interface ToolExecuteContext {
87
87
  tokens: number;
88
88
  turns: number;
89
89
  tasks: number;
90
- costUsd?: number;
91
90
  costMicroUsd?: number;
92
91
  }) => void;
93
92
  model?: Model;
@@ -247,7 +246,6 @@ export interface TaskSpec {
247
246
  appendSystemPrompt?: string;
248
247
  promptProvider?: import("../prompts/default.js").PromptProvider;
249
248
  memory?: import("./memory.js").MemorySpecInput;
250
- memoryConsolidation?: MemoryConsolidationConfig;
251
249
  suggestNextPrompts?: boolean | {
252
250
  count?: number;
253
251
  role?: ModelRole;
@@ -398,12 +396,10 @@ export interface TaskResult {
398
396
  outputTokens?: number;
399
397
  cacheWriteTokensLong?: number;
400
398
  costMicroUsd?: number;
401
- costUsd?: number;
402
399
  nested?: {
403
400
  tokens: number;
404
401
  turns: number;
405
402
  tasks: number;
406
- costUsd?: number;
407
403
  costMicroUsd?: number;
408
404
  };
409
405
  memory?: {
@@ -596,7 +592,6 @@ export type TaskEvent = ({
596
592
  export type CompactOutcome = "compacted" | "failed" | "mooted" | "noop" | "blocked" | "disabled";
597
593
  export interface TaskStream extends AsyncIterable<TaskEvent> {
598
594
  result(): Promise<TaskResult>;
599
- consolidation(): Promise<void>;
600
595
  suggestions(): Promise<string[]>;
601
596
  steer(text: string, options?: {
602
597
  trusted?: boolean;
@@ -612,17 +607,6 @@ export interface TaskStream extends AsyncIterable<TaskEvent> {
612
607
  interrupt(): Promise<void>;
613
608
  destroy(): Promise<void>;
614
609
  }
615
- export interface MemoryConsolidationConfig {
616
- enabled: boolean;
617
- role?: ModelRole;
618
- band?: {
619
- lo: number;
620
- hi: number;
621
- };
622
- searchLimit?: number;
623
- maxNotesPerTask?: number;
624
- timeoutSec?: number;
625
- }
626
610
  export interface WorkflowGovernanceBaseline {
627
611
  base: Partial<TaskSpec>;
628
612
  worktreeBase?: Partial<TaskSpec>;
@@ -664,6 +648,7 @@ export interface BackgroundChildEvent {
664
648
  resumable?: boolean;
665
649
  status?: "completed" | "killed" | "failed";
666
650
  seq?: number;
651
+ completionId?: string;
667
652
  stoppedBy?: "user" | "parent" | "system" | (string & {});
668
653
  summary?: string;
669
654
  usage?: {
@@ -728,7 +713,6 @@ export interface RunnerDeps {
728
713
  onWorkflowAgentSpawn?: (handle: import("../orchestration/workflow.js").WorkflowAgentHandle) => void;
729
714
  maxSuspends?: number;
730
715
  now?: () => number;
731
- memoryStore?: import("./memory.js").MemoryStore;
732
716
  memoryBackend?: import("./memory-engine/types.js").MemoryBackend;
733
717
  memoryEngineDir?: string;
734
718
  onMemoryHarvestReport?: (report: import("./memory-engine/types.js").HarvestReport, info: {
@@ -750,17 +734,6 @@ export interface RunnerDeps {
750
734
  path: string;
751
735
  contentHash: string | null;
752
736
  }> | null>;
753
- utilityGate?: import("./memory.js").UtilityGate;
754
- memoryConsolidation?: MemoryConsolidationConfig;
755
- memoryRecall?: {
756
- enabled?: boolean;
757
- thresholdBytes?: number;
758
- select?: import("./memory-recall.js").MemorySelector;
759
- selectorModel?: ModelRef;
760
- maxSelected?: number;
761
- maxLinked?: number;
762
- timeoutMs?: number;
763
- };
764
737
  promptProvider?: import("../prompts/default.js").PromptProvider;
765
738
  onElicit?: OnElicit;
766
739
  mcpImageResizer?: import("./mcp.js").McpImageResizer;
@@ -796,6 +769,5 @@ export interface RunnerDeps {
796
769
  summaryProvider?: import("./auto-compaction.js").MaybeCompactOptions["summaryProvider"];
797
770
  onCompaction?: import("./auto-compaction.js").MaybeCompactOptions["onCompaction"];
798
771
  maxConsecutiveProviderReuse?: number;
799
- dynamicRecall?: import("./dynamic-recall.js").DynamicRecallConfig;
800
772
  }
801
773
  export type { AgentTool, Model, StreamFn, ThinkingLevel };
@@ -11,6 +11,8 @@ export interface WorkflowJournalStore {
11
11
  export declare const MAX_JOURNAL_RESULT_BYTES: number;
12
12
  export declare function oversizeJournalResult(serialized: string): boolean;
13
13
  export declare function callKeyOrdinal(callKey: string): number;
14
+ export declare const JOURNAL_OVERSIZE_ERROR_CODE = "workflow.journal_oversize";
15
+ export declare function journalOversizeTombstone(result: TaskResult, bytes: number): TaskResult;
14
16
  export declare class InMemoryWorkflowJournalStore implements WorkflowJournalStore {
15
17
  private readonly runs;
16
18
  load(runId: string, scope: string): Promise<WorkflowJournalEntry[]>;
@@ -7,6 +7,20 @@ export function callKeyOrdinal(callKey) {
7
7
  const n = Number.parseInt(i >= 0 ? callKey.slice(0, i) : callKey, 10);
8
8
  return Number.isFinite(n) ? n : 0;
9
9
  }
10
+ export const JOURNAL_OVERSIZE_ERROR_CODE = "workflow.journal_oversize";
11
+ export function journalOversizeTombstone(result, bytes) {
12
+ const message = `[journal] result omitted: ${bytes} bytes exceeds the ${MAX_JOURNAL_RESULT_BYTES}-byte per-entry journal cap; ` +
13
+ `the agent's real terminal status was "${result.status}". A resume re-runs this agent (and everything after it) live.`;
14
+ return {
15
+ taskId: result.taskId,
16
+ sessionId: result.sessionId,
17
+ status: "failed",
18
+ result: message,
19
+ errorCode: JOURNAL_OVERSIZE_ERROR_CODE,
20
+ errorMessage: message,
21
+ stats: result.stats,
22
+ };
23
+ }
10
24
  function snapshot(entry) {
11
25
  try {
12
26
  return structuredClone(entry);
@@ -1,5 +1,5 @@
1
1
  import { type WorkflowRunStore } from "./workflow-run-store.js";
2
2
  import type { WorkflowRun, WorkflowRunStatus } from "../orchestration/workflow.js";
3
- export declare function makeWorkflowRun(over?: Partial<WorkflowRun>): WorkflowRun;
3
+ export declare function createWorkflowRun(over?: Partial<WorkflowRun>): WorkflowRun;
4
4
  export declare function workflowRunStoreContract(make: () => WorkflowRunStore, runAssertion?: (name: string, fn: () => Promise<void>) => void): Promise<void>;
5
5
  export type { WorkflowRunStatus };
@@ -1,6 +1,6 @@
1
1
  import { strict as assert } from "node:assert";
2
2
  import { summarizeWorkflowRun } from "./workflow-run-store.js";
3
- export function makeWorkflowRun(over = {}) {
3
+ export function createWorkflowRun(over = {}) {
4
4
  const createdAt = over.createdAt ?? 1_000;
5
5
  return {
6
6
  id: over.id ?? "run-1",
@@ -27,13 +27,13 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
27
27
  };
28
28
  run("put create-once → already_exists", async () => {
29
29
  const store = make();
30
- const r = makeWorkflowRun();
30
+ const r = createWorkflowRun();
31
31
  await store.put(r.id, r);
32
32
  await assert.rejects(store.put(r.id, r), (e) => e.code === "workflow_run.already_exists");
33
33
  });
34
34
  run("get returns a deep copy (mutating the result must not corrupt the store)", async () => {
35
35
  const store = make();
36
- const r = makeWorkflowRun();
36
+ const r = createWorkflowRun();
37
37
  await store.put(r.id, r);
38
38
  const got = await store.get(r.id);
39
39
  assert.ok(got);
@@ -44,7 +44,7 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
44
44
  });
45
45
  run("update CAS: bumps rev, scope-mismatch loses, stale-rev loses, current-rev wins", async () => {
46
46
  const store = make();
47
- const r = makeWorkflowRun({ status: "running" });
47
+ const r = createWorkflowRun({ status: "running" });
48
48
  await store.put(r.id, r);
49
49
  assert.equal(await store.update(r.id, r.scope, { ...r, status: "running", stats: { ...r.stats, tokens: 200 } }), true);
50
50
  assert.equal((await store.get(r.id)).rev, 1);
@@ -54,11 +54,11 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
54
54
  assert.equal(await store.update(r.id, r.scope, { ...r, status: "completed" }, { rev: 1 }), true);
55
55
  assert.equal((await store.get(r.id)).rev, 2);
56
56
  assert.equal((await store.get(r.id)).status, "completed");
57
- assert.equal(await store.update("ghost", r.scope, makeWorkflowRun({ id: "ghost" })), false);
57
+ assert.equal(await store.update("ghost", r.scope, createWorkflowRun({ id: "ghost" })), false);
58
58
  });
59
59
  run("the key id is authoritative — a payload with a mismatched id never poisons the projection (codex BUG4)", async () => {
60
60
  const store = make();
61
- const r = makeWorkflowRun({ id: "real", status: "running" });
61
+ const r = createWorkflowRun({ id: "real", status: "running" });
62
62
  await store.put("real", { ...r, id: "spoofed" });
63
63
  assert.equal((await store.get("real")).id, "real");
64
64
  assert.equal(await store.get("spoofed"), null);
@@ -70,10 +70,10 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
70
70
  run("listByScope: history included (completed + failed + running), createdAt DESC, status filter + limit", async () => {
71
71
  const store = make();
72
72
  assert.deepEqual(await store.listByScope("tenant-a"), []);
73
- const running = makeWorkflowRun({ id: "r-run", status: "running", createdAt: 3_000, endedAt: undefined });
74
- const done = makeWorkflowRun({ id: "r-done", status: "completed", createdAt: 2_000 });
75
- const failed = makeWorkflowRun({ id: "r-fail", status: "failed", createdAt: 1_000 });
76
- const other = makeWorkflowRun({ id: "r-other", scope: "tenant-b", createdAt: 9_000 });
73
+ const running = createWorkflowRun({ id: "r-run", status: "running", createdAt: 3_000, endedAt: undefined });
74
+ const done = createWorkflowRun({ id: "r-done", status: "completed", createdAt: 2_000 });
75
+ const failed = createWorkflowRun({ id: "r-fail", status: "failed", createdAt: 1_000 });
76
+ const other = createWorkflowRun({ id: "r-other", scope: "tenant-b", createdAt: 9_000 });
77
77
  for (const r of [running, done, failed, other])
78
78
  await store.put(r.id, r);
79
79
  const all = await store.listByScope("tenant-a");
@@ -88,7 +88,7 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
88
88
  assert.equal(doneSummary.currentPhase, "build");
89
89
  assert.equal(doneSummary.name, undefined);
90
90
  assert.equal(doneSummary.description, undefined);
91
- const named = makeWorkflowRun({
91
+ const named = createWorkflowRun({
92
92
  id: "r-named", name: "find-flaky", description: "find flaky tests", createdAt: 4_000,
93
93
  phases: [
94
94
  { title: "scan", status: "completed", startedAt: 4_000, endedAt: 4_001 },
@@ -103,10 +103,10 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
103
103
  });
104
104
  run("reap: only terminal runs, NEVER running; maxAgeMs + keep retention; no policy → no-op", async () => {
105
105
  const store = make();
106
- const running = makeWorkflowRun({ id: "k-run", status: "running", createdAt: 100, endedAt: undefined });
107
- const oldDone = makeWorkflowRun({ id: "k-old", status: "completed", createdAt: 100, endedAt: 100 });
108
- const newDone = makeWorkflowRun({ id: "k-new", status: "completed", createdAt: 9_000, endedAt: 9_000 });
109
- const oldFail = makeWorkflowRun({ id: "k-fail", status: "failed", createdAt: 200, endedAt: 200 });
106
+ const running = createWorkflowRun({ id: "k-run", status: "running", createdAt: 100, endedAt: undefined });
107
+ const oldDone = createWorkflowRun({ id: "k-old", status: "completed", createdAt: 100, endedAt: 100 });
108
+ const newDone = createWorkflowRun({ id: "k-new", status: "completed", createdAt: 9_000, endedAt: 9_000 });
109
+ const oldFail = createWorkflowRun({ id: "k-fail", status: "failed", createdAt: 200, endedAt: 200 });
110
110
  for (const r of [running, oldDone, newDone, oldFail])
111
111
  await store.put(r.id, r);
112
112
  assert.equal(await store.reap("tenant-a", 1_000_000), 0);
@@ -120,10 +120,10 @@ export async function workflowRunStoreContract(make, runAssertion = defaultSeque
120
120
  });
121
121
  run("reap keep-newest-N: deletes all but the newest N terminal runs; running excluded from the count", async () => {
122
122
  const store = make();
123
- const running = makeWorkflowRun({ id: "p-run", status: "running", createdAt: 50, endedAt: undefined });
124
- const t1 = makeWorkflowRun({ id: "p-1", status: "completed", createdAt: 1_000 });
125
- const t2 = makeWorkflowRun({ id: "p-2", status: "completed", createdAt: 2_000 });
126
- const t3 = makeWorkflowRun({ id: "p-3", status: "failed", createdAt: 3_000 });
123
+ const running = createWorkflowRun({ id: "p-run", status: "running", createdAt: 50, endedAt: undefined });
124
+ const t1 = createWorkflowRun({ id: "p-1", status: "completed", createdAt: 1_000 });
125
+ const t2 = createWorkflowRun({ id: "p-2", status: "completed", createdAt: 2_000 });
126
+ const t3 = createWorkflowRun({ id: "p-3", status: "failed", createdAt: 3_000 });
127
127
  for (const r of [running, t1, t2, t3])
128
128
  await store.put(r.id, r);
129
129
  assert.equal(await store.reap("tenant-a", 99_999, { keep: 1 }), 2);
@@ -9,6 +9,19 @@ export declare function getShellConfig(customShellPath?: string): Promise<Result
9
9
  shell: string;
10
10
  args: string[];
11
11
  }, ExecutionError>>;
12
+ export declare function decideSpoolReclaim(args: {
13
+ size: number;
14
+ cursor: number;
15
+ writerLive: boolean;
16
+ rotateBytes?: number;
17
+ hardCapBytes?: number;
18
+ }): {
19
+ reclaim: false;
20
+ } | {
21
+ reclaim: true;
22
+ live: boolean;
23
+ skippedBytes: number;
24
+ };
12
25
  export declare function openSpoolPair(base: string): {
13
26
  outPath: string;
14
27
  errPath: string;
@@ -71,6 +84,7 @@ export declare class NodeExecutionEnv implements ExecutionEnv, BackgroundShellCa
71
84
  }): Promise<Result<string[], FileError>>;
72
85
  readBinaryFile(path: string, abortSignal?: AbortSignal): Promise<Result<Uint8Array, FileError>>;
73
86
  writeFile(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
87
+ private writeFileInPlace;
74
88
  writeFileExclusive(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
75
89
  appendFile(path: string, content: string | Uint8Array): Promise<Result<void, FileError>>;
76
90
  fileInfo(path: string): Promise<Result<FileInfo, FileError>>;