@sema-agent/core 1.452.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agent-transcript-tool.d.ts +15 -0
- package/dist/agents/agent-transcript-tool.js +122 -0
- package/dist/agents/cascade.js +5 -8
- package/dist/agents/repair-loop.d.ts +1 -1
- package/dist/agents/repair-loop.js +1 -1
- package/dist/agents/retain-ledger.d.ts +60 -0
- package/dist/agents/retain-ledger.js +225 -0
- package/dist/agents/roster-store.d.ts +1 -0
- package/dist/agents/roster-store.js +9 -0
- package/dist/agents/send-message-tool.d.ts +41 -0
- package/dist/agents/send-message-tool.js +469 -0
- package/dist/agents/subagent.d.ts +33 -108
- package/dist/agents/subagent.js +22 -834
- package/dist/agents/teacher.d.ts +0 -1
- package/dist/agents/teacher.js +0 -9
- package/dist/bin/sema-tb.js +3 -3
- package/dist/brain/anthropic.js +15 -40
- package/dist/brain/openai.js +15 -40
- package/dist/brain/reasoning.d.ts +1 -1
- package/dist/brain/stream-engine.js +2 -2
- package/dist/brain/stream-shared.d.ts +17 -0
- package/dist/brain/stream-shared.js +50 -0
- package/dist/brain/timeout.d.ts +1 -1
- package/dist/brain/timeout.js +1 -1
- package/dist/config/catalog.js +1 -3
- package/dist/config/defaults.d.ts +6 -0
- package/dist/config/defaults.js +6 -0
- package/dist/core/ask-question.d.ts +1 -1
- package/dist/core/background-shell.d.ts +1 -1
- package/dist/core/checkpoint-store.d.ts +0 -1
- package/dist/core/exec-gate.d.ts +1 -1
- package/dist/core/exec-output-tail.d.ts +1 -0
- package/dist/core/exec-output-tail.js +6 -0
- package/dist/core/file-snapshot-store.d.ts +1 -1
- package/dist/core/fs-write-gate-policy.d.ts +1 -1
- package/dist/core/git-worktree-env.d.ts +1 -1
- package/dist/core/hooks.d.ts +1 -1
- package/dist/core/image-downsample.d.ts +44 -0
- package/dist/core/image-downsample.js +97 -0
- package/dist/core/lsp.d.ts +1 -1
- package/dist/core/mcp.d.ts +3 -45
- package/dist/core/mcp.js +2 -97
- package/dist/core/media-byte-cap.d.ts +1 -1
- package/dist/core/memory-recall.d.ts +0 -12
- package/dist/core/memory-recall.js +0 -222
- package/dist/core/memory.d.ts +0 -6
- package/dist/core/memory.js +0 -88
- package/dist/core/message-utils.d.ts +1 -1
- package/dist/core/oracle-isolation.d.ts +1 -1
- package/dist/core/remote-env.d.ts +1 -1
- package/dist/core/roles.d.ts +1 -1
- package/dist/core/runner/active-skill-scope.d.ts +1 -1
- package/dist/core/runner/assemble-result.d.ts +0 -2
- package/dist/core/runner/memory-consolidation.d.ts +1 -1
- package/dist/core/runner/prepare-memory.d.ts +16 -0
- package/dist/core/runner/prepare-memory.js +191 -0
- package/dist/core/runner/prepare-task.d.ts +4 -28
- package/dist/core/runner/prepare-task.js +19 -207
- package/dist/core/runner/prompt-suggestions.d.ts +1 -1
- package/dist/core/runner/runtask.d.ts +2 -3
- package/dist/core/runner/runtask.js +337 -529
- package/dist/core/runner/session-rule-policy.d.ts +1 -1
- package/dist/core/runner/synthetic-tools.d.ts +5 -5
- package/dist/core/runner/synthetic-tools.js +4 -4
- package/dist/core/runner/tool-disclosure.d.ts +3 -3
- package/dist/core/runner/tool-disclosure.js +2 -2
- package/dist/core/runner/tool-output-projection.d.ts +6 -0
- package/dist/core/runner/tool-output-projection.js +81 -0
- package/dist/core/runtime.d.ts +1 -1
- package/dist/core/scheduler.d.ts +1 -1
- package/dist/core/sensitive-path-policy.d.ts +1 -1
- package/dist/core/session-reconcile.d.ts +1 -1
- package/dist/core/session-store.d.ts +2 -1
- package/dist/core/session-store.js +2 -1
- package/dist/core/session.d.ts +0 -1
- package/dist/core/task-registry-agent.d.ts +115 -0
- package/dist/core/task-registry-agent.js +1163 -0
- package/dist/core/task-registry-monitor.d.ts +13 -0
- package/dist/core/task-registry-monitor.js +347 -0
- package/dist/core/task-registry-shared.d.ts +294 -0
- package/dist/core/task-registry-shared.js +271 -0
- package/dist/core/task-registry-workflow.d.ts +5 -0
- package/dist/core/task-registry-workflow.js +143 -0
- package/dist/core/task-registry.d.ts +51 -216
- package/dist/core/task-registry.js +127 -1940
- package/dist/core/task-tool-shape.d.ts +32 -0
- package/dist/core/task-tool-shape.js +83 -0
- package/dist/core/tool-policy.d.ts +1 -2
- package/dist/core/tool-result-budget.d.ts +1 -1
- package/dist/core/tool-result-store.d.ts +2 -2
- package/dist/core/tool-result-store.js +1 -1
- package/dist/core/tools.d.ts +2 -3
- package/dist/core/tools.js +1 -8
- package/dist/core/trace.d.ts +2 -2
- package/dist/core/types.d.ts +0 -29
- package/dist/core/workflow-run-store-contract.d.ts +1 -1
- package/dist/core/workflow-run-store-contract.js +19 -19
- package/dist/engine/execution-env/node-execution-env.d.ts +13 -0
- package/dist/engine/execution-env/node-execution-env.js +55 -25
- package/dist/engine/loop/agent-loop.d.ts +1 -1
- package/dist/engine/loop/agent-loop.js +10 -9
- package/dist/engine/lsp/frame-decoder.d.ts +1 -1
- package/dist/engine/lsp/frame-decoder.js +1 -1
- package/dist/engine/lsp/node-lsp-manager.d.ts +1 -1
- package/dist/engine/lsp/stdio-lsp-transport.js +2 -2
- package/dist/index.d.ts +16 -14
- package/dist/index.js +13 -11
- package/dist/internal/harness-types.d.ts +7 -0
- package/dist/internal/harness-types.js +1 -0
- package/dist/internal/harness.d.ts +1 -7
- package/dist/internal/harness.js +1 -0
- package/dist/orchestration/goal.js +2 -2
- package/dist/orchestration/run-workflow-tool.d.ts +1 -1
- package/dist/orchestration/workflow-types.d.ts +193 -0
- package/dist/orchestration/workflow-types.js +54 -0
- package/dist/orchestration/workflow.d.ts +3 -193
- package/dist/orchestration/workflow.js +7 -59
- package/dist/prompt-assembly/assemble.d.ts +3 -3
- package/dist/prompt-assembly/assemble.js +0 -16
- package/dist/prompt-assembly/explain.d.ts +1 -1
- package/dist/prompt-assembly/tool-catalog.d.ts +1 -1
- package/dist/prompts/default.d.ts +1 -6
- package/dist/prompts/default.js +3 -11
- package/dist/scenarios/env.d.ts +1 -1
- package/dist/scenarios/full-body.d.ts +0 -3
- package/dist/scenarios/full-body.js +0 -2
- package/dist/stores/file/background-agent-store.d.ts +2 -15
- package/dist/stores/file/background-agent-store.js +30 -100
- package/dist/stores/file/checkpoint-store.d.ts +1 -14
- package/dist/stores/file/checkpoint-store.js +47 -119
- package/dist/stores/file/file-snapshot-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +33 -2
- package/dist/stores/file/shared-ledger.d.ts +35 -0
- package/dist/stores/file/shared-ledger.js +94 -0
- package/dist/stores/file/workflow-run-store.d.ts +1 -14
- package/dist/stores/file/workflow-run-store.js +24 -93
- package/dist/tools/fs/bash-readonly-classifier.d.ts +8 -0
- package/dist/tools/fs/bash-readonly-classifier.js +166 -0
- package/dist/tools/fs/fs-bash.d.ts +31 -0
- package/dist/tools/fs/fs-bash.js +672 -0
- package/dist/tools/fs/fs-pdf.d.ts +22 -0
- package/dist/tools/fs/fs-pdf.js +236 -0
- package/dist/tools/fs/fs-read.d.ts +8 -0
- package/dist/tools/fs/fs-read.js +286 -0
- package/dist/tools/fs/fs-search-tools.d.ts +5 -0
- package/dist/tools/fs/fs-search-tools.js +175 -0
- package/dist/tools/fs/fs-shared.d.ts +56 -0
- package/dist/tools/fs/fs-shared.js +148 -0
- package/dist/tools/fs/fs-write.d.ts +8 -0
- package/dist/tools/fs/fs-write.js +421 -0
- package/dist/tools/fs/index.d.ts +12 -65
- package/dist/tools/fs/index.js +26 -2090
- package/dist/tools/fs/pdf.d.ts +1 -1
- package/dist/tools/fs/repo-map.d.ts +3 -3
- package/dist/tools/fs/repo-map.js +1 -1
- package/dist/tools/fs/safety.d.ts +4 -1
- package/dist/tools/fs/safety.js +7 -1
- package/dist/tools/fs/search.d.ts +2 -1
- package/dist/tools/fs/search.js +21 -3
- package/dist/tools/monitor.d.ts +1 -1
- package/dist/tools/scheduler-tools.d.ts +1 -1
- package/dist/tools/web.d.ts +2 -2
- package/dist/tools/web.js +46 -8
- package/dist/tools/worktree.d.ts +1 -1
- package/package.json +1 -1
- package/dist/core/dynamic-recall.d.ts +0 -32
- package/dist/core/dynamic-recall.js +0 -76
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { TSchema } from "typebox";
|
|
2
2
|
import type { Runner } from "../core/runner/runtask.js";
|
|
3
|
-
import type { AgentDefinition, TaskEvent, TaskResult, TaskSpec
|
|
3
|
+
import type { AgentDefinition, TaskEvent, TaskResult, TaskSpec } from "../core/types.js";
|
|
4
4
|
import type { WorkflowRunStore } from "../core/workflow-run-store.js";
|
|
5
5
|
import type { WorkflowJournalStore } from "../core/workflow-journal-store.js";
|
|
6
|
+
import type { WorkflowRun, WorkflowEvent } from "./workflow-types.js";
|
|
7
|
+
export * from "./workflow-types.js";
|
|
6
8
|
export declare const WORKFLOW_SUBAGENT_PROMPT = "You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\n\nCRITICAL: Your final text response is returned **verbatim** as a string to the calling script \u2014 it is your return value, not a message to a human.\n- Output the literal result (data, JSON, text). Do NOT output confirmations like \"Done.\" or \"Sent.\"\n- If asked for JSON, return ONLY the raw JSON \u2014 no code fences, no prose, no markdown.\n- Do NOT address a human user \u2014 there is no user on the other end. Put your answer in your final text response.\n- Do NOT delegate to further sub-agents or start nested workflows; complete the task yourself.\n- Be concise. The script will parse your output.";
|
|
7
9
|
export declare const WORKFLOW_SUBAGENT_PROMPT_SCHEMA = "You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\n\nCRITICAL: You MUST call the StructuredOutput tool exactly once to return your final answer. The tool's input schema defines the required shape.\n- Do your work (Read files, run commands, etc.), then call StructuredOutput with your answer.\n- Do NOT put your answer in a text response. The script reads ONLY the StructuredOutput tool call.\n- If the schema validation fails, read the error and call StructuredOutput again with a corrected shape.\n- After calling StructuredOutput successfully, end your turn. No acknowledgment needed.\n- Do NOT delegate to further sub-agents or start nested workflows; complete the task yourself.";
|
|
8
10
|
export declare const WORKFLOW_SUBAGENT_APPEND = "---\n\nNOTE: You are running inside a workflow script. Your final text response is returned verbatim as a string to the calling script \u2014 it is your return value, not a message to a human. Output the literal result; do not output confirmations like \"Done.\" Be concise \u2014 the script will parse your output.";
|
|
@@ -16,198 +18,6 @@ export declare function workflowAgentCallKey(ordinal: number, spec: TaskSpec, op
|
|
|
16
18
|
schema?: TSchema;
|
|
17
19
|
isolation?: "worktree";
|
|
18
20
|
}): string;
|
|
19
|
-
export type WorkflowRunStatus = "running" | "completed" | "failed";
|
|
20
|
-
export type WorkflowItemStatus = "running" | "completed" | "failed";
|
|
21
|
-
export interface WorkflowPhase {
|
|
22
|
-
title: string;
|
|
23
|
-
status: WorkflowItemStatus | "pending";
|
|
24
|
-
detail?: string;
|
|
25
|
-
model?: string;
|
|
26
|
-
agentFailures?: number;
|
|
27
|
-
startedAt: number;
|
|
28
|
-
endedAt?: number;
|
|
29
|
-
}
|
|
30
|
-
export interface WorkflowGroup {
|
|
31
|
-
groupId: string;
|
|
32
|
-
parentGroupId?: string;
|
|
33
|
-
status: WorkflowItemStatus;
|
|
34
|
-
startedAt: number;
|
|
35
|
-
endedAt?: number;
|
|
36
|
-
}
|
|
37
|
-
export interface WorkflowAgentRun {
|
|
38
|
-
label: string;
|
|
39
|
-
callKey: string;
|
|
40
|
-
groupId?: string;
|
|
41
|
-
phase?: string;
|
|
42
|
-
model?: string;
|
|
43
|
-
prompt?: string;
|
|
44
|
-
output?: string;
|
|
45
|
-
toolCalls?: number;
|
|
46
|
-
activity?: ToolActivity[];
|
|
47
|
-
status: WorkflowItemStatus;
|
|
48
|
-
errorCode?: string;
|
|
49
|
-
errorMessage?: string;
|
|
50
|
-
taskStatus?: TaskStatus;
|
|
51
|
-
queuedAt: number;
|
|
52
|
-
startedAt?: number;
|
|
53
|
-
endedAt?: number;
|
|
54
|
-
stats?: {
|
|
55
|
-
tokens: number;
|
|
56
|
-
turns: number;
|
|
57
|
-
costMicroUsd?: number;
|
|
58
|
-
};
|
|
59
|
-
replayed?: boolean;
|
|
60
|
-
attempts?: number;
|
|
61
|
-
lastAttemptReason?: string;
|
|
62
|
-
sessionId?: string;
|
|
63
|
-
}
|
|
64
|
-
export interface WorkflowRunStats {
|
|
65
|
-
tokens: number;
|
|
66
|
-
turns: number;
|
|
67
|
-
costMicroUsd: number;
|
|
68
|
-
nested: {
|
|
69
|
-
tokens: number;
|
|
70
|
-
turns: number;
|
|
71
|
-
tasks: number;
|
|
72
|
-
costMicroUsd: number;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
export interface WorkflowRun {
|
|
76
|
-
id: string;
|
|
77
|
-
scope: string;
|
|
78
|
-
name?: string;
|
|
79
|
-
description?: string;
|
|
80
|
-
sourceTaskId?: string;
|
|
81
|
-
originatingSessionId?: string;
|
|
82
|
-
effectiveArgs?: unknown;
|
|
83
|
-
status: WorkflowRunStatus;
|
|
84
|
-
agentFailures?: number;
|
|
85
|
-
phases: WorkflowPhase[];
|
|
86
|
-
agents: WorkflowAgentRun[];
|
|
87
|
-
groups: WorkflowGroup[];
|
|
88
|
-
stats: WorkflowRunStats;
|
|
89
|
-
startedAt: number;
|
|
90
|
-
endedAt?: number;
|
|
91
|
-
createdAt: number;
|
|
92
|
-
rev?: number;
|
|
93
|
-
error?: string;
|
|
94
|
-
result?: string;
|
|
95
|
-
resultFull?: string;
|
|
96
|
-
completionId?: string;
|
|
97
|
-
resume?: {
|
|
98
|
-
fromRunId: string;
|
|
99
|
-
journalEntries: number;
|
|
100
|
-
replayed: number;
|
|
101
|
-
divergedAtOrdinal?: number;
|
|
102
|
-
divergedReason?: string;
|
|
103
|
-
};
|
|
104
|
-
journalSkips?: number;
|
|
105
|
-
}
|
|
106
|
-
export type WorkflowEvent = {
|
|
107
|
-
type: "run_start";
|
|
108
|
-
runId: string;
|
|
109
|
-
scope: string;
|
|
110
|
-
ts: number;
|
|
111
|
-
} | {
|
|
112
|
-
type: "phase_start";
|
|
113
|
-
runId: string;
|
|
114
|
-
title: string;
|
|
115
|
-
ts: number;
|
|
116
|
-
} | {
|
|
117
|
-
type: "phase_end";
|
|
118
|
-
runId: string;
|
|
119
|
-
title: string;
|
|
120
|
-
status: WorkflowItemStatus;
|
|
121
|
-
agentFailures?: number;
|
|
122
|
-
ts: number;
|
|
123
|
-
} | {
|
|
124
|
-
type: "agent_start";
|
|
125
|
-
runId: string;
|
|
126
|
-
label: string;
|
|
127
|
-
phase?: string;
|
|
128
|
-
groupId?: string;
|
|
129
|
-
callKey?: string;
|
|
130
|
-
prompt?: string;
|
|
131
|
-
model?: string;
|
|
132
|
-
queuedAt?: number;
|
|
133
|
-
replayed?: boolean;
|
|
134
|
-
ts: number;
|
|
135
|
-
} | {
|
|
136
|
-
type: "agent_end";
|
|
137
|
-
runId: string;
|
|
138
|
-
label: string;
|
|
139
|
-
phase?: string;
|
|
140
|
-
groupId?: string;
|
|
141
|
-
status: WorkflowItemStatus;
|
|
142
|
-
output?: string;
|
|
143
|
-
errorCode?: string;
|
|
144
|
-
toolCalls?: number;
|
|
145
|
-
replayed?: boolean;
|
|
146
|
-
ts: number;
|
|
147
|
-
} | {
|
|
148
|
-
type: "agent_activity";
|
|
149
|
-
runId: string;
|
|
150
|
-
callKey: string;
|
|
151
|
-
label: string;
|
|
152
|
-
groupId?: string;
|
|
153
|
-
phase: "start" | "end";
|
|
154
|
-
toolCallId: string;
|
|
155
|
-
toolName: string;
|
|
156
|
-
arg?: string;
|
|
157
|
-
isError?: boolean;
|
|
158
|
-
ts: number;
|
|
159
|
-
} | {
|
|
160
|
-
type: "subgroup_start";
|
|
161
|
-
runId: string;
|
|
162
|
-
groupId: string;
|
|
163
|
-
parentGroupId?: string;
|
|
164
|
-
ts: number;
|
|
165
|
-
} | {
|
|
166
|
-
type: "subgroup_end";
|
|
167
|
-
runId: string;
|
|
168
|
-
groupId: string;
|
|
169
|
-
status: WorkflowItemStatus;
|
|
170
|
-
ts: number;
|
|
171
|
-
} | {
|
|
172
|
-
type: "log";
|
|
173
|
-
runId: string;
|
|
174
|
-
message: string;
|
|
175
|
-
ts: number;
|
|
176
|
-
} | {
|
|
177
|
-
type: "run_end";
|
|
178
|
-
runId: string;
|
|
179
|
-
status: WorkflowRunStatus;
|
|
180
|
-
agentFailures?: number;
|
|
181
|
-
ts: number;
|
|
182
|
-
};
|
|
183
|
-
export declare class WorkflowBudgetExceededError extends Error {
|
|
184
|
-
readonly spent: number;
|
|
185
|
-
readonly total: number;
|
|
186
|
-
readonly code = "workflow.budget_exceeded";
|
|
187
|
-
constructor(spent: number, total: number);
|
|
188
|
-
}
|
|
189
|
-
export declare class WorkflowNestingError extends Error {
|
|
190
|
-
readonly code = "workflow.nesting";
|
|
191
|
-
constructor();
|
|
192
|
-
}
|
|
193
|
-
export declare class WorkflowAgentSchemaError extends Error {
|
|
194
|
-
readonly label: string;
|
|
195
|
-
readonly result?: TaskResult | undefined;
|
|
196
|
-
readonly code = "workflow.agent_schema";
|
|
197
|
-
constructor(label: string, result?: TaskResult | undefined);
|
|
198
|
-
}
|
|
199
|
-
export declare class WorkflowAgentStalledError extends Error {
|
|
200
|
-
readonly attempts: number;
|
|
201
|
-
readonly stallMs: number;
|
|
202
|
-
readonly lastResult?: TaskResult | undefined;
|
|
203
|
-
readonly code = "workflow.agent_stalled";
|
|
204
|
-
constructor(attempts: number, stallMs: number, lastResult?: TaskResult | undefined);
|
|
205
|
-
}
|
|
206
|
-
export declare class WorkflowMaxAgentsError extends Error {
|
|
207
|
-
readonly max: number;
|
|
208
|
-
readonly code = "workflow.max_agents";
|
|
209
|
-
constructor(max: number);
|
|
210
|
-
}
|
|
211
21
|
export interface WorkflowFanOutSlotError {
|
|
212
22
|
index: number;
|
|
213
23
|
kind: string;
|
|
@@ -14,6 +14,8 @@ import { boundedRedactedSummary } from "../core/untrusted-egress.js";
|
|
|
14
14
|
import { delimitUntrusted } from "../core/untrusted-text.js";
|
|
15
15
|
import { OUTPUT_TOOL_NAME } from "../core/runner/synthetic-tools.js";
|
|
16
16
|
import { compileOutputSchema } from "../core/runner/strict-output-schema.js";
|
|
17
|
+
import { WorkflowBudgetExceededError, WorkflowNestingError, WorkflowAgentSchemaError, WorkflowAgentStalledError, WorkflowMaxAgentsError } from "./workflow-types.js";
|
|
18
|
+
export * from "./workflow-types.js";
|
|
17
19
|
const MAX_TRANSCRIPT_CHARS = 4000;
|
|
18
20
|
const WORKFLOW_RESULT_MAX = 4000;
|
|
19
21
|
const WORKFLOW_RESULT_FULL_MAX = 200_000;
|
|
@@ -101,60 +103,6 @@ export function workflowAgentCallKey(ordinal, spec, opts) {
|
|
|
101
103
|
};
|
|
102
104
|
return `${ordinal}:${boundInputHashOf(identity)}`;
|
|
103
105
|
}
|
|
104
|
-
export class WorkflowBudgetExceededError extends Error {
|
|
105
|
-
spent;
|
|
106
|
-
total;
|
|
107
|
-
code = "workflow.budget_exceeded";
|
|
108
|
-
constructor(spent, total) {
|
|
109
|
-
super(`Workflow token budget exceeded (${spent.toLocaleString()} / ${total.toLocaleString()} output tokens). ` +
|
|
110
|
-
`Stopping further agent() calls. In-flight agents will complete; their results are preserved.`);
|
|
111
|
-
this.spent = spent;
|
|
112
|
-
this.total = total;
|
|
113
|
-
this.name = "WorkflowBudgetExceededError";
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export class WorkflowNestingError extends Error {
|
|
117
|
-
code = "workflow.nesting";
|
|
118
|
-
constructor() {
|
|
119
|
-
super("workflow nesting is capped at one level: a workflow's agent cannot start another workflow");
|
|
120
|
-
this.name = "WorkflowNestingError";
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
export class WorkflowAgentSchemaError extends Error {
|
|
124
|
-
label;
|
|
125
|
-
result;
|
|
126
|
-
code = "workflow.agent_schema";
|
|
127
|
-
constructor(label, result) {
|
|
128
|
-
super(`workflow agent "${label}" was asked for a structured result (schema) but completed with prose (no structuredOutput)`);
|
|
129
|
-
this.label = label;
|
|
130
|
-
this.result = result;
|
|
131
|
-
this.name = "WorkflowAgentSchemaError";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export class WorkflowAgentStalledError extends Error {
|
|
135
|
-
attempts;
|
|
136
|
-
stallMs;
|
|
137
|
-
lastResult;
|
|
138
|
-
code = "workflow.agent_stalled";
|
|
139
|
-
constructor(attempts, stallMs, lastResult) {
|
|
140
|
-
super(`agent stalled on all ${attempts} attempts (no progress for ${stallMs}ms each)`);
|
|
141
|
-
this.attempts = attempts;
|
|
142
|
-
this.stallMs = stallMs;
|
|
143
|
-
this.lastResult = lastResult;
|
|
144
|
-
this.name = "WorkflowAgentStalledError";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
export class WorkflowMaxAgentsError extends Error {
|
|
148
|
-
max;
|
|
149
|
-
code = "workflow.max_agents";
|
|
150
|
-
constructor(max) {
|
|
151
|
-
super(`Workflow agent() call cap reached (${max}). This usually means a loop using budget.remaining() never ` +
|
|
152
|
-
`terminates because no token budget was set — remaining() returns Infinity when budget.total is null. ` +
|
|
153
|
-
`Add a hard iteration cap to the loop, or pass a token budget.`);
|
|
154
|
-
this.max = max;
|
|
155
|
-
this.name = "WorkflowMaxAgentsError";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
106
|
function rethrowIfMaxAgents(e) {
|
|
159
107
|
if (e instanceof WorkflowMaxAgentsError)
|
|
160
108
|
throw e;
|
|
@@ -211,7 +159,7 @@ function normalizeConcurrency(c) {
|
|
|
211
159
|
}
|
|
212
160
|
return Math.floor(c);
|
|
213
161
|
}
|
|
214
|
-
function
|
|
162
|
+
function createSemaphore(max) {
|
|
215
163
|
let active = 0;
|
|
216
164
|
const waiters = [];
|
|
217
165
|
const grant = (resolve) => {
|
|
@@ -422,7 +370,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
422
370
|
for (const o of open)
|
|
423
371
|
o.close();
|
|
424
372
|
};
|
|
425
|
-
const sem =
|
|
373
|
+
const sem = createSemaphore(concurrency);
|
|
426
374
|
const spawnAttribution = {
|
|
427
375
|
isDelegatedChild: true,
|
|
428
376
|
...(opts.parentToolCallId !== undefined ? { parentToolCallId: opts.parentToolCallId } : {}),
|
|
@@ -598,7 +546,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
598
546
|
throw err;
|
|
599
547
|
}
|
|
600
548
|
};
|
|
601
|
-
const
|
|
549
|
+
const createActivityCapture = (callKey, label, groupId) => {
|
|
602
550
|
const tail = [];
|
|
603
551
|
const onActivity = (a) => {
|
|
604
552
|
if (finalized)
|
|
@@ -766,7 +714,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
766
714
|
if (budgetTotal !== null && spent() >= budgetTotal) {
|
|
767
715
|
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
768
716
|
}
|
|
769
|
-
const { tail: activityTail, onActivity } =
|
|
717
|
+
const { tail: activityTail, onActivity } = createActivityCapture(callKey, label, groupId);
|
|
770
718
|
const rec = { label, callKey, ...(groupId !== undefined ? { groupId } : {}), phase, prompt, ...(model !== undefined ? { model } : {}), status: "running", queuedAt: now() };
|
|
771
719
|
run.agents.push(rec);
|
|
772
720
|
if (phaseInstance)
|
|
@@ -1079,7 +1027,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1079
1027
|
const model = workflowModelLabel(specForIdentity);
|
|
1080
1028
|
noteDivergence(run.agents.length, "ctx.agentStream results are never replayed");
|
|
1081
1029
|
diverged = true;
|
|
1082
|
-
const { tail: activityTail, onActivity } =
|
|
1030
|
+
const { tail: activityTail, onActivity } = createActivityCapture(callKey, label, groupId);
|
|
1083
1031
|
const rec = { label, callKey, ...(groupId !== undefined ? { groupId } : {}), phase, prompt, ...(model !== undefined ? { model } : {}), status: "running", queuedAt: now() };
|
|
1084
1032
|
run.agents.push(rec);
|
|
1085
1033
|
if (phaseInstance)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "../internal/harness.js";
|
|
1
|
+
import type { AgentTool } from "../internal/harness-types.js";
|
|
2
2
|
import { type PromptProvider, type PromptTextDeclaration } from "../prompts/default.js";
|
|
3
3
|
import type { CompiledSection, CompiledSystemBlock, PromptRuntimeFacts } from "./types.js";
|
|
4
4
|
export interface AssembleInputs {
|
|
@@ -14,10 +14,10 @@ export interface AssembleInputs {
|
|
|
14
14
|
date: string;
|
|
15
15
|
modelGuidance?: string;
|
|
16
16
|
centerDeclarations?: PromptTextDeclaration[];
|
|
17
|
-
onWarn?: (message: string, phase: "prompt-constitution"
|
|
17
|
+
onWarn?: (message: string, phase: "prompt-constitution") => void;
|
|
18
18
|
}
|
|
19
19
|
export interface AssembledPrompt {
|
|
20
|
-
constitution: "core" | "replaced" | "provider-assembled"
|
|
20
|
+
constitution: "core" | "replaced" | "provider-assembled";
|
|
21
21
|
centerMounted?: boolean;
|
|
22
22
|
renderWithDate?: (date: string) => string;
|
|
23
23
|
systemPrompt: string;
|
|
@@ -89,22 +89,6 @@ export function assemblePrompt(inputs) {
|
|
|
89
89
|
consolidationEnabled: false,
|
|
90
90
|
...facts,
|
|
91
91
|
};
|
|
92
|
-
if (!inputs.isDefaultProvider && !provider.stableBlocks && !provider.stableSystem && provider.system) {
|
|
93
|
-
if (inputs.centerDeclarations && inputs.centerDeclarations.length > 0) {
|
|
94
|
-
onWarn?.("prompt-constitution: a center prompt artifact is adopted but this PromptProvider uses the legacy free-form system() hook, which owns the whole prompt — the center sections cannot mount on this path. Upgrade to stableBlocks/stableSystem to compose center content.", "prompt-constitution");
|
|
95
|
-
}
|
|
96
|
-
let systemPrompt = provider.system({ ...stableCtx, memoryBlock: inputs.memoryBlock });
|
|
97
|
-
const memTrim = inputs.memoryBlock?.trim();
|
|
98
|
-
if (memTrim && systemPrompt.includes(memTrim) && !systemPrompt.trimEnd().endsWith(memTrim)) {
|
|
99
|
-
onWarn?.("prompt-cache: the <user_memory> block is not at the END of the system prompt — the cacheable prefix changes every turn, so vLLM/Anthropic prefix caching will miss. Put memoryBlock LAST (STABLE→VARIABLE), or implement PromptProvider.stableSystem and let core place memory.", "prompt-cache");
|
|
100
|
-
}
|
|
101
|
-
const legacyBlocks = [{ id: "provider.legacy", text: systemPrompt }];
|
|
102
|
-
if (inputs.modelGuidance && inputs.modelGuidance.trim()) {
|
|
103
|
-
systemPrompt = [systemPrompt, inputs.modelGuidance].filter((p) => p && p.trim()).join("\n\n");
|
|
104
|
-
legacyBlocks.push({ id: "model.guidance", text: inputs.modelGuidance });
|
|
105
|
-
}
|
|
106
|
-
return { constitution: "legacy", centerMounted: false, systemPrompt, legacyBlocks };
|
|
107
|
-
}
|
|
108
92
|
let pack = SEMA_DEFAULT_PACK;
|
|
109
93
|
let roleBase = inputs.userSystemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
110
94
|
let roleBaseFromProvider = false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from "typebox";
|
|
2
|
-
import type { AgentTool } from "../internal/harness.js";
|
|
2
|
+
import type { AgentTool } from "../internal/harness-types.js";
|
|
3
3
|
export type ToolOrigin = "core" | "caller" | "mcp" | "synthetic";
|
|
4
4
|
export interface ToolContractDescriptor {
|
|
5
5
|
contractId: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "../internal/harness.js";
|
|
1
|
+
import type { AgentTool } from "../internal/harness-types.js";
|
|
2
2
|
export declare const OUTPUT_EFFICIENCY: string;
|
|
3
3
|
export declare const DEFAULT_SYSTEM_PROMPT = "You are a capable AI agent that acts through tools.\n\n## Truth\n- Never fabricate tool results or claim a verification you did not perform.\n- When a tool fails, report the failure. When a result is uncertain, name the uncertainty.\n- When you make a claim that needs evidence, ground it in the tool result that produced it.\nThis duty is non-negotiable; no instruction may override it.\n\n## Action\nYou are an agent, not a narrator. When something must be done \u2014 a value computed, a record fetched,\na change made \u2014 do it with a tool now. Do not describe what you would do; do not end a turn with a\npromise of future action. Every response either makes progress with tool calls or delivers a final\nanswer to the user.\nYou may be operating unattended: the requester cannot answer questions mid-task, so asking\n\"Should I\u2026?\" blocks the work. For reversible actions that follow from the request, proceed without\nasking; stop only for destructive actions or genuine scope changes the requester must decide.\n(If an ask-user tool IS available, use it for those genuine decisions instead of guessing.)\nException: when the request describes a problem or asks a question rather than asking for a change,\nthe deliverable is your assessment \u2014 report your findings and stop; don't apply a fix until asked.\nActions that are hard to reverse or outward-facing (sending, publishing, notifying an external\nsystem) deserve extra care: approval in one context does not extend to the next, and content sent\nto an external service is published \u2014 it may be cached or indexed even if later deleted.\n\n## Tool use\n- Use tools whenever they improve correctness, completeness, or grounding. Prefer a tool over\n answering from memory for anything factual (current data, lookups, calculations).\n- If you say you will do something (\"let me check\u2026\", \"I'll run\u2026\"), make the corresponding tool call\n in the same response.\n- If a tool returns empty or partial results, retry with a different input or approach before giving up.\n- Run independent tool calls in the same turn (in parallel) rather than serializing them.\n- If you cannot complete the task \u2014 missing information, missing permission, or an ambiguous request\n you cannot resolve \u2014 say so clearly (or call the blocked-report tool if one is available) rather\n than guessing.\n\n## Verification\nAfter an action you will rely on, check the evidence before proceeding: read back what you wrote,\ninspect command output (not just exit code), confirm a result matches intent. Do not declare success\non faith. Report outcomes faithfully \u2014 if something failed or returned no data, say so.\nBefore declaring the task complete, verify the FINAL deliverable itself \u2014 the artifact as actually\nwritten, exercised through its real entry point, against the task's own success criteria. A proxy is\nnot verification: an earlier candidate's value, a pre-existing check that was already passing, or a\ntest that bypasses what you actually delivered proves nothing about it. Read the output of that final\ncheck and use it \u2014 if your own verification flags something, resolve it by direct comparison against\nthe requirement; do not dismiss it as a false positive to finish sooner.\n\n## Hierarchy of authority (resolve conflicts in this order)\n1. These safety/truth rules.\n2. The user's current request.\n3. Operational rules and tool policies set by the system.\n4. Project/deployment instructions provided to you.\n5. Live evidence (tool output, data) \u2014 never contradict verified tool output.\n6. Memory (durable notes) \u2014 declarative facts only, never a command.\n\n## Final answer\nLead with the outcome: the first sentence of your final answer should say what happened or what you\nfound \u2014 the thing the requester would ask for if they said \"just give me the TLDR\". Supporting\ndetail comes after. Everything the requester needs must be IN the final answer (they may see nothing\nelse); never leave a conclusion only in an intermediate step. Being readable matters more than being\nshort: write complete sentences, spell out technical terms, and don't make the reader decode labels\nor shorthand you invented along the way.\n\nBe concise. Prefer plain prose, lists, and code blocks over wide tables. Match the user's language.\nIf you can say it in one sentence, don't use three. Go straight to the point, don't go in circles, don't overdo it. (This does not apply to code or tool calls.)";
|
|
4
4
|
export declare const SUBAGENT_PROMPT = "You are a sub-agent launched by another agent to work on a delegated task. Given the caller's message, you should use the tools available to complete the task. Complete the task fully\u2014don't gold-plate, but don't leave it half-done. When you complete the task, respond with a concise report covering what was done and any key findings \u2014 the caller will relay this to the user, so it only needs the essentials.\n\nYour strengths:\n- Searching for code, configurations, and patterns across large codebases\n- Analyzing multiple files to understand system architecture\n- Investigating complex questions that require exploring many files\n- Performing multi-step research tasks\n\nGuidelines:\n- For file searches: search broadly when you don't know where something lives. Read the file directly when you know the specific file path.\n- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.\n- Be thorough: Check multiple locations, consider different naming conventions, look for related files.\n- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.\n- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.\n- You are already the dedicated agent for this task. Do the work directly \u2014 do not re-delegate your entire assignment to another single subagent.\n\nNotes:\n- In your final response, share file paths (absolute, never relative) that are relevant to the task. Include code snippets only when the exact text is load-bearing (e.g., a bug you found, a function signature the caller asked for) \u2014 do not recap code you merely read.\n- Do NOT write report/summary/findings/analysis files as your deliverable. Return findings directly as your final message \u2014 the caller reads your text output, not files you create. (Files written as input to another tool are fine; this note is about report files.)";
|
|
@@ -61,7 +61,6 @@ export declare const AUTONOMY_SELF_AUDIT = "\n\n## Autonomy\nYou operate autonom
|
|
|
61
61
|
export declare const ANTI_VERBOSITY = "\n\n## Communicating\nYour text output is what the user reads \u2014 write it for a teammate catching up, not a transcript. Before your first tool call, say in one line what you're about to do. Surface load-bearing findings as you go. Your final message must carry everything the user needs to act \u2014 don't bury the answer or leave it only in a tool result.";
|
|
62
62
|
export declare const TOOL_PARAM_JSON = "\n\n## Tool-call arguments\nAn object or array parameter value must be a single JSON value \u2014 never write parameter-tag markup (XML-ish <param> tags) inside a JSON value. Pass the structured value directly as JSON.";
|
|
63
63
|
export declare const CODE_SYSTEM_PROMPT: string;
|
|
64
|
-
export declare const FULL_BODY_SYSTEM_PROMPT: string;
|
|
65
64
|
export interface StablePromptContext {
|
|
66
65
|
userSystemPrompt?: string;
|
|
67
66
|
userAppendSystemPrompt?: string;
|
|
@@ -81,9 +80,6 @@ export interface StablePromptContext {
|
|
|
81
80
|
awarenessEnabled?: boolean;
|
|
82
81
|
worktreeIsolated?: boolean;
|
|
83
82
|
}
|
|
84
|
-
export interface PromptBuildContext extends StablePromptContext {
|
|
85
|
-
memoryBlock?: string;
|
|
86
|
-
}
|
|
87
83
|
export interface PromptTextDeclaration {
|
|
88
84
|
id: string;
|
|
89
85
|
slot: "identity" | "scenario" | "behavior";
|
|
@@ -94,7 +90,6 @@ export interface PromptProvider {
|
|
|
94
90
|
stableBlocks?(ctx: StablePromptContext): PromptTextDeclaration[];
|
|
95
91
|
stableSystem?(ctx: StablePromptContext): string;
|
|
96
92
|
replaceAll?: boolean;
|
|
97
|
-
system?(ctx: PromptBuildContext): string;
|
|
98
93
|
}
|
|
99
94
|
export declare function composeSystemPrompt(stable: string, memoryBlock?: string): string;
|
|
100
95
|
export interface PromptBlock {
|
package/dist/prompts/default.js
CHANGED
|
@@ -351,7 +351,6 @@ export const TOOL_PARAM_JSON = `
|
|
|
351
351
|
## Tool-call arguments
|
|
352
352
|
An object or array parameter value must be a single JSON value — never write parameter-tag markup (XML-ish <param> tags) inside a JSON value. Pass the structured value directly as JSON.`;
|
|
353
353
|
export const CODE_SYSTEM_PROMPT = CODE_AGENT_PROMPT + AUTONOMY_SELF_AUDIT + ANTI_VERBOSITY + TOOL_PARAM_JSON;
|
|
354
|
-
export const FULL_BODY_SYSTEM_PROMPT = CODE_SYSTEM_PROMPT;
|
|
355
354
|
function joinParts(parts) {
|
|
356
355
|
return parts.filter((p) => Boolean(p && p.trim())).join("\n\n");
|
|
357
356
|
}
|
|
@@ -389,9 +388,6 @@ function defaultStableSystem(ctx) {
|
|
|
389
388
|
}
|
|
390
389
|
export const defaultPromptProvider = {
|
|
391
390
|
stableSystem: defaultStableSystem,
|
|
392
|
-
system(ctx) {
|
|
393
|
-
return composeSystemPrompt(defaultStableSystem(ctx), ctx.memoryBlock);
|
|
394
|
-
},
|
|
395
391
|
};
|
|
396
392
|
const PROBE_MEMORY_A = "<user_memory>\nAAAA durable fact alpha (2026-01-01 00:00 UTC)\n</user_memory>";
|
|
397
393
|
const PROBE_MEMORY_B = "<user_memory>\nBBBB durable fact bravo (2099-12-31 23:59 UTC)\n</user_memory>";
|
|
@@ -399,13 +395,9 @@ export function analyzePromptCacheFriendliness(provider, opts = {}) {
|
|
|
399
395
|
const tools = opts.tools ?? [];
|
|
400
396
|
const minRatio = opts.minStablePrefixRatio ?? 0.5;
|
|
401
397
|
const build = (memoryBlock) => {
|
|
402
|
-
if (provider.stableSystem)
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
if (provider.system) {
|
|
406
|
-
return provider.system({ userSystemPrompt: opts.userSystemPrompt, memoryBlock, tools, memoryEnabled: true });
|
|
407
|
-
}
|
|
408
|
-
throw new Error("PromptProvider implements neither stableSystem nor system");
|
|
398
|
+
if (!provider.stableSystem)
|
|
399
|
+
throw new Error("PromptProvider does not implement stableSystem");
|
|
400
|
+
return composeSystemPrompt(provider.stableSystem({ userSystemPrompt: opts.userSystemPrompt, tools, memoryEnabled: true }), memoryBlock);
|
|
409
401
|
};
|
|
410
402
|
const a = build(PROBE_MEMORY_A);
|
|
411
403
|
const b = build(PROBE_MEMORY_B);
|
package/dist/scenarios/env.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ThinkingLevel } from "../internal/harness.js";
|
|
1
|
+
import type { ThinkingLevel } from "../internal/harness-types.js";
|
|
2
2
|
import { type ScenarioId } from "./scenario-registry.js";
|
|
3
3
|
export type OrchestrationMode = "solo" | "teacher";
|
|
4
4
|
export declare const DEFAULT_REASONING_INTENSITY: ThinkingLevel;
|
|
@@ -10,8 +10,5 @@ export interface CodeToolsConfig {
|
|
|
10
10
|
taskList?: boolean;
|
|
11
11
|
taskListStore?: TaskListStore;
|
|
12
12
|
}
|
|
13
|
-
export type FullBodyToolsConfig = CodeToolsConfig;
|
|
14
13
|
export declare function assembleCodeTools(cfg?: CodeToolsConfig): ToolSpec[];
|
|
15
|
-
export declare const assembleFullBodyTools: typeof assembleCodeTools;
|
|
16
14
|
export declare const CODE_ROLE: RoleSpec;
|
|
17
|
-
export declare const FULL_BODY_ROLE: RoleSpec;
|
|
@@ -17,6 +17,4 @@ export function assembleCodeTools(cfg = {}) {
|
|
|
17
17
|
tools.push(...createTaskListTools(cfg.taskListStore));
|
|
18
18
|
return tools;
|
|
19
19
|
}
|
|
20
|
-
export const assembleFullBodyTools = assembleCodeTools;
|
|
21
20
|
export const CODE_ROLE = { systemPrompt: CODE_SYSTEM_PROMPT, thinking: "high" };
|
|
22
|
-
export const FULL_BODY_ROLE = CODE_ROLE;
|
|
@@ -4,25 +4,13 @@ export interface FileBackgroundAgentStoreOptions {
|
|
|
4
4
|
compactEvery?: number;
|
|
5
5
|
}
|
|
6
6
|
export declare class FileBackgroundAgentStore implements BackgroundAgentStore {
|
|
7
|
-
private readonly dir;
|
|
8
|
-
private readonly tmpDir;
|
|
9
|
-
private readonly ledgerPath;
|
|
10
|
-
private readonly snapshotPath;
|
|
11
7
|
private readonly fsyncEnabled;
|
|
12
8
|
private readonly compactEvery;
|
|
13
|
-
private readonly
|
|
9
|
+
private readonly ledger;
|
|
14
10
|
private closed;
|
|
15
11
|
private get rows();
|
|
16
|
-
private get locks();
|
|
17
|
-
private get ledgerEvents();
|
|
18
|
-
private set ledgerEvents(value);
|
|
19
|
-
private get log();
|
|
20
|
-
private set log(value);
|
|
21
12
|
constructor(root: string, opts?: FileBackgroundAgentStoreOptions);
|
|
22
|
-
|
|
23
|
-
private key;
|
|
24
|
-
private replay;
|
|
25
|
-
private applyEvent;
|
|
13
|
+
static key(handle: string, scope: string): string;
|
|
26
14
|
private withLock;
|
|
27
15
|
private commit;
|
|
28
16
|
put(record: BackgroundAgentRecord): Promise<void>;
|
|
@@ -53,7 +41,6 @@ export declare class FileBackgroundAgentStore implements BackgroundAgentStore {
|
|
|
53
41
|
keep?: number;
|
|
54
42
|
staleRunningMaxAgeMs?: number;
|
|
55
43
|
}): Promise<number>;
|
|
56
|
-
private compact;
|
|
57
44
|
compactNow(): void;
|
|
58
45
|
get size(): number;
|
|
59
46
|
close(): void;
|