@bluecopa/harness 0.1.0-snapshot.131 → 0.1.0-snapshot.133
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/arc/index.d.ts +969 -0
- package/dist/arc/index.js +2680 -0
- package/dist/arc/index.js.map +1 -0
- package/dist/observability/otel.d.ts +36 -0
- package/dist/observability/otel.js +73 -0
- package/dist/observability/otel.js.map +1 -0
- package/dist/shared-types-C6QKEEsw.d.ts +149 -0
- package/dist/skills/index.d.ts +67 -0
- package/dist/skills/index.js +282 -0
- package/dist/skills/index.js.map +1 -0
- package/package.json +10 -22
- package/dist/arc/app-adapter.d.ts +0 -109
- package/dist/arc/app-adapter.js +0 -408
- package/dist/arc/app-adapter.js.map +0 -1
- package/dist/arc/create-arc-agent.d.ts +0 -51
- package/dist/arc/create-arc-agent.js +0 -4863
- package/dist/arc/create-arc-agent.js.map +0 -1
- package/dist/arc/profile-builder.d.ts +0 -51
- package/dist/arc/profile-builder.js +0 -310
- package/dist/arc/profile-builder.js.map +0 -1
- package/dist/arc/profile-graph.d.ts +0 -36
- package/dist/arc/profile-graph.js +0 -113
- package/dist/arc/profile-graph.js.map +0 -1
- package/dist/arc/transition-table.d.ts +0 -75
- package/dist/arc/transition-table.js +0 -25
- package/dist/arc/transition-table.js.map +0 -1
- package/dist/loop/vercel-agent-loop.d.ts +0 -116
- package/dist/loop/vercel-agent-loop.js +0 -330
- package/dist/loop/vercel-agent-loop.js.map +0 -1
- package/dist/types-B3VY0xnE.d.ts +0 -973
|
@@ -0,0 +1,969 @@
|
|
|
1
|
+
import { A as AnyTool, T as ToolProvider, a as ToolResult, M as ModelFactory, b as ToolResultArtifact, c as ToolChoiceConfig } from '../shared-types-C6QKEEsw.js';
|
|
2
|
+
export { d as ActionType, B as BashOptions, e as BatchOp, f as BatchResult, G as GlobOptions, g as GrepOptions, R as ReadOptions, h as TextEditorRequest, i as ThreadStatus, j as ToolChoiceValue, k as ToolProviderCapabilities, W as WebFetchOptions, r as resolveToolChoice } from '../shared-types-C6QKEEsw.js';
|
|
3
|
+
import * as ai from 'ai';
|
|
4
|
+
|
|
5
|
+
interface ToolCallInfo {
|
|
6
|
+
toolCallId: string;
|
|
7
|
+
toolName: string;
|
|
8
|
+
args: Record<string, unknown>;
|
|
9
|
+
/** Provider-specific metadata preserved across round-trips (e.g., Gemini thought signatures). */
|
|
10
|
+
providerMetadata?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface ToolResultInfo {
|
|
13
|
+
toolCallId: string;
|
|
14
|
+
toolName: string;
|
|
15
|
+
result: string;
|
|
16
|
+
isError?: boolean;
|
|
17
|
+
durationMs?: number;
|
|
18
|
+
}
|
|
19
|
+
type ContentPart = {
|
|
20
|
+
type: "text";
|
|
21
|
+
text: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "image";
|
|
24
|
+
image: Buffer | Uint8Array;
|
|
25
|
+
mimeType: string;
|
|
26
|
+
};
|
|
27
|
+
interface AgentMessage {
|
|
28
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
29
|
+
content: string | ContentPart[];
|
|
30
|
+
toolCalls?: ToolCallInfo[];
|
|
31
|
+
toolResults?: ToolResultInfo[];
|
|
32
|
+
/** Provider-specific metadata preserved across round-trips (e.g., Gemini thought signatures). */
|
|
33
|
+
providerMetadata?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface ToolCallAction {
|
|
36
|
+
type: "tool";
|
|
37
|
+
name: string;
|
|
38
|
+
args: Record<string, unknown>;
|
|
39
|
+
toolCallId?: string;
|
|
40
|
+
/** Provider-specific metadata preserved across round-trips (e.g., Gemini thought signatures). */
|
|
41
|
+
providerMetadata?: Record<string, unknown>;
|
|
42
|
+
/** Short user-visible rationale text emitted before the tool call. */
|
|
43
|
+
publicRationale?: string;
|
|
44
|
+
}
|
|
45
|
+
interface FinalAction {
|
|
46
|
+
type: "final";
|
|
47
|
+
content: string;
|
|
48
|
+
}
|
|
49
|
+
interface ToolBatchAction {
|
|
50
|
+
type: "tool_batch";
|
|
51
|
+
calls: ToolCallAction[];
|
|
52
|
+
/** Short user-visible rationale text emitted before the tool batch. */
|
|
53
|
+
publicRationale?: string;
|
|
54
|
+
}
|
|
55
|
+
type AgentAction = ToolCallAction | FinalAction | ToolBatchAction;
|
|
56
|
+
/** Token usage breakdown for a single LLM step. */
|
|
57
|
+
interface StepUsage {
|
|
58
|
+
inputTokens?: number;
|
|
59
|
+
outputTokens?: number;
|
|
60
|
+
cacheReadTokens?: number;
|
|
61
|
+
cacheWriteTokens?: number;
|
|
62
|
+
reasoningTokens?: number;
|
|
63
|
+
}
|
|
64
|
+
type AgentStreamEvent = {
|
|
65
|
+
type: "text_delta";
|
|
66
|
+
text: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: "tool_start";
|
|
69
|
+
name: string;
|
|
70
|
+
args: Record<string, unknown>;
|
|
71
|
+
toolCallId?: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "tool_end";
|
|
74
|
+
name: string;
|
|
75
|
+
result: {
|
|
76
|
+
success: boolean;
|
|
77
|
+
output: string;
|
|
78
|
+
error?: string;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
};
|
|
81
|
+
} | {
|
|
82
|
+
type: "step_start";
|
|
83
|
+
step: number;
|
|
84
|
+
} | {
|
|
85
|
+
type: "step_end";
|
|
86
|
+
step: number;
|
|
87
|
+
usage?: StepUsage;
|
|
88
|
+
} | {
|
|
89
|
+
type: "done";
|
|
90
|
+
output: string;
|
|
91
|
+
steps: number;
|
|
92
|
+
};
|
|
93
|
+
interface AgentLoop {
|
|
94
|
+
nextAction(messages: AgentMessage[], signal?: AbortSignal): Promise<AgentAction>;
|
|
95
|
+
streamAction?(messages: AgentMessage[]): AsyncIterable<AgentStreamEvent>;
|
|
96
|
+
}
|
|
97
|
+
/** Context passed to `prepareStep` before each LLM call. */
|
|
98
|
+
interface PrepareStepContext {
|
|
99
|
+
stepNumber: number;
|
|
100
|
+
toolCallHistory: string[];
|
|
101
|
+
}
|
|
102
|
+
/** Overrides returned by `prepareStep`. All fields optional — omit to keep defaults. */
|
|
103
|
+
interface PrepareStepResult {
|
|
104
|
+
model?: string;
|
|
105
|
+
activeTools?: string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Tool registry: the Tool contract and schema extraction.
|
|
110
|
+
*
|
|
111
|
+
* Agent tool definitions (Bash, Read, Write, etc.) live in the consumer
|
|
112
|
+
* (truecode). The harness only provides the Tool contract and helpers.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/** A registered tool: schema for the model, execute for the worker */
|
|
116
|
+
interface Tool {
|
|
117
|
+
name: string;
|
|
118
|
+
/** AI SDK tool schema. Optional for ARC-internal tools (ReadEpisode, LCM_*, ScratchPad_*). */
|
|
119
|
+
schema?: AnyTool | undefined;
|
|
120
|
+
/** Execute using the ToolProvider. If not set, tool is handled externally (e.g. ARC tools). */
|
|
121
|
+
execute?: (provider: ToolProvider, args: Record<string, unknown>, workDir: string) => Promise<ToolResult>;
|
|
122
|
+
}
|
|
123
|
+
/** Get only the AI SDK tool schemas from a registry (skips tools without schemas) */
|
|
124
|
+
declare function toolSchemasFromRegistry(registry: Map<string, Tool>): Record<string, AnyTool>;
|
|
125
|
+
|
|
126
|
+
interface StoredMessage {
|
|
127
|
+
id: string;
|
|
128
|
+
conversationId: string;
|
|
129
|
+
index: number;
|
|
130
|
+
role: "user" | "assistant" | "tool";
|
|
131
|
+
content: string;
|
|
132
|
+
toolCalls?: ToolCallInfo[];
|
|
133
|
+
toolResults?: ToolResultInfo[];
|
|
134
|
+
timestamp: number;
|
|
135
|
+
}
|
|
136
|
+
interface GrepResult {
|
|
137
|
+
messageId: string;
|
|
138
|
+
conversationId: string;
|
|
139
|
+
messageIndex: number;
|
|
140
|
+
excerpt: string;
|
|
141
|
+
matchContext: string;
|
|
142
|
+
}
|
|
143
|
+
interface MessageStore {
|
|
144
|
+
append(message: StoredMessage): void;
|
|
145
|
+
getConversation(conversationId: string): StoredMessage[];
|
|
146
|
+
getMessage(conversationId: string, index: number): StoredMessage | null;
|
|
147
|
+
grep(pattern: string, opts?: {
|
|
148
|
+
conversationId?: string;
|
|
149
|
+
maxResults?: number;
|
|
150
|
+
}): GrepResult[];
|
|
151
|
+
}
|
|
152
|
+
declare class MemoryMessageStore implements MessageStore {
|
|
153
|
+
private messages;
|
|
154
|
+
private byConversation;
|
|
155
|
+
append(message: StoredMessage): void;
|
|
156
|
+
getConversation(conversationId: string): StoredMessage[];
|
|
157
|
+
getMessage(conversationId: string, index: number): StoredMessage | null;
|
|
158
|
+
grep(pattern: string, opts?: {
|
|
159
|
+
conversationId?: string;
|
|
160
|
+
maxResults?: number;
|
|
161
|
+
}): GrepResult[];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface SummaryNode {
|
|
165
|
+
id: string;
|
|
166
|
+
depth: number;
|
|
167
|
+
sourceIds: string[];
|
|
168
|
+
sourceConversationIds: string[];
|
|
169
|
+
summary: string;
|
|
170
|
+
artifacts: string[];
|
|
171
|
+
operations: string[];
|
|
172
|
+
outcome: string;
|
|
173
|
+
tokenCount: number;
|
|
174
|
+
createdAt: number;
|
|
175
|
+
}
|
|
176
|
+
interface CompactionOpts {
|
|
177
|
+
/** Minimum number of uncovered children before compaction triggers (default: 4) */
|
|
178
|
+
minChildren?: number;
|
|
179
|
+
/** Soft token budget — compact when total tokens at a depth exceed this (default: 8000) */
|
|
180
|
+
softTokenBudget?: number;
|
|
181
|
+
}
|
|
182
|
+
interface SummaryDAG {
|
|
183
|
+
addLeaf(node: SummaryNode): void;
|
|
184
|
+
compact(opts?: CompactionOpts): SummaryNode[];
|
|
185
|
+
getNode(id: string): SummaryNode | undefined;
|
|
186
|
+
getLineage(id: string, visited?: Set<string>): string[];
|
|
187
|
+
getFrontier(budget: number): SummaryNode[];
|
|
188
|
+
getCoveredIds(frontier: SummaryNode[]): Set<string>;
|
|
189
|
+
getAllNodes(): SummaryNode[];
|
|
190
|
+
}
|
|
191
|
+
declare class MemorySummaryDAG implements SummaryDAG {
|
|
192
|
+
private nodes;
|
|
193
|
+
/** Tracks which source IDs have been covered by a parent node */
|
|
194
|
+
private coveredBy;
|
|
195
|
+
addLeaf(node: SummaryNode): void;
|
|
196
|
+
compact(opts?: CompactionOpts): SummaryNode[];
|
|
197
|
+
getNode(id: string): SummaryNode | undefined;
|
|
198
|
+
getLineage(id: string, visited?: Set<string>): string[];
|
|
199
|
+
getFrontier(budget: number): SummaryNode[];
|
|
200
|
+
/** Returns the coverage set of all node IDs transitively covered by frontier nodes */
|
|
201
|
+
getCoveredIds(frontier: SummaryNode[]): Set<string>;
|
|
202
|
+
getAllNodes(): SummaryNode[];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface GhostCue {
|
|
206
|
+
summaryId: string;
|
|
207
|
+
conversationIds: string[];
|
|
208
|
+
depth: number;
|
|
209
|
+
label: string;
|
|
210
|
+
}
|
|
211
|
+
interface AssembledContext {
|
|
212
|
+
messages: AgentMessage[];
|
|
213
|
+
ghostCues: GhostCue[];
|
|
214
|
+
tokenEstimate: number;
|
|
215
|
+
/** Structured sections for downstream consumers (avoids string matching) */
|
|
216
|
+
frontierText?: string;
|
|
217
|
+
ghostCueText?: string;
|
|
218
|
+
}
|
|
219
|
+
interface AssembleContextOpts {
|
|
220
|
+
conversationId: string;
|
|
221
|
+
store: MessageStore;
|
|
222
|
+
dag: SummaryDAG;
|
|
223
|
+
budget: number;
|
|
224
|
+
freshTailSize: number;
|
|
225
|
+
taskContext: string;
|
|
226
|
+
ooda?: OodaSnapshot;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Budget-driven context assembly from MessageStore + SummaryDAG.
|
|
230
|
+
*
|
|
231
|
+
* Algorithm:
|
|
232
|
+
* 1. Always include: task context (task, workspace, budget info)
|
|
233
|
+
* 2. Fresh tail: last N raw messages from the conversation
|
|
234
|
+
* 3. Frontier: walk DAG from deepest summaries, adding within budget
|
|
235
|
+
* 4. Ghost cues: for any DAG region not expanded, insert a pointer
|
|
236
|
+
* 5. OODA snapshot if provided
|
|
237
|
+
*/
|
|
238
|
+
declare function assembleContext(opts: AssembleContextOpts): AssembledContext;
|
|
239
|
+
interface AssembleWorkerContextOpts {
|
|
240
|
+
store: MessageStore;
|
|
241
|
+
dag: SummaryDAG;
|
|
242
|
+
budget: number;
|
|
243
|
+
taskContext: string;
|
|
244
|
+
instruction: string;
|
|
245
|
+
vectorIndex?: VectorIndex;
|
|
246
|
+
transcriptStore?: TranscriptStore;
|
|
247
|
+
scratchPad?: ScratchPad;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Assemble context specifically for a worker dispatch.
|
|
251
|
+
* Workers get: task context + relevant prior summaries + vector retrieval + scratch notes.
|
|
252
|
+
*/
|
|
253
|
+
declare function assembleWorkerContext(opts: AssembleWorkerContextOpts): Promise<AssembledContext>;
|
|
254
|
+
|
|
255
|
+
type HookEventName = 'PreToolUse' | 'PostToolUse' | 'BeforeWorker' | 'AfterWorker';
|
|
256
|
+
interface HookContext {
|
|
257
|
+
event: HookEventName;
|
|
258
|
+
toolName?: string;
|
|
259
|
+
input?: Record<string, unknown>;
|
|
260
|
+
output?: ToolResult;
|
|
261
|
+
metadata?: Record<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
interface HookDecision {
|
|
264
|
+
allow: boolean;
|
|
265
|
+
reason?: string;
|
|
266
|
+
}
|
|
267
|
+
type HookCallback = (context: HookContext) => Promise<HookDecision | void>;
|
|
268
|
+
|
|
269
|
+
declare class HookRunner {
|
|
270
|
+
private readonly hooks;
|
|
271
|
+
register(event: HookContext['event'], callback: HookCallback): void;
|
|
272
|
+
run(context: HookContext): Promise<HookDecision>;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Raw worker transcript, append-only storage */
|
|
276
|
+
interface Transcript {
|
|
277
|
+
id: string;
|
|
278
|
+
tupleId: string;
|
|
279
|
+
instruction: string;
|
|
280
|
+
messages: AgentMessage[];
|
|
281
|
+
timestamp: number;
|
|
282
|
+
}
|
|
283
|
+
/** Artifact produced by a worker dispatch */
|
|
284
|
+
interface Artifact {
|
|
285
|
+
id: string;
|
|
286
|
+
tupleId: string;
|
|
287
|
+
/** File path or returned value */
|
|
288
|
+
output: string | null;
|
|
289
|
+
/** Full textual worker result, preserved even when expected file artifacts are missing */
|
|
290
|
+
textOutput?: string | undefined;
|
|
291
|
+
status: "complete" | "incomplete" | "failed" | "interrupted";
|
|
292
|
+
/** One-line summary from worker's final message */
|
|
293
|
+
summary: string;
|
|
294
|
+
stepsUsed: number;
|
|
295
|
+
/** Tool calls with results (for orchestrator reasoning) */
|
|
296
|
+
actions?: string[];
|
|
297
|
+
/** The dispatch instruction that produced this artifact */
|
|
298
|
+
instruction?: string;
|
|
299
|
+
}
|
|
300
|
+
interface ExpectedArtifact {
|
|
301
|
+
type: "file" | "directory" | "value" | "unknown";
|
|
302
|
+
path?: string | undefined;
|
|
303
|
+
description?: string | undefined;
|
|
304
|
+
}
|
|
305
|
+
interface ExpectedOutputContract {
|
|
306
|
+
artifacts: ExpectedArtifact[];
|
|
307
|
+
successCriteria?: string[] | undefined;
|
|
308
|
+
verification?: string | undefined;
|
|
309
|
+
description?: string | undefined;
|
|
310
|
+
}
|
|
311
|
+
/** Worker instruction tuple */
|
|
312
|
+
interface Tuple {
|
|
313
|
+
id: string;
|
|
314
|
+
instruction: string;
|
|
315
|
+
/** Artifact IDs to provide as input */
|
|
316
|
+
inputs: string[];
|
|
317
|
+
/** Structured contract for what the worker should produce */
|
|
318
|
+
expectedOutput: ExpectedOutputContract;
|
|
319
|
+
/** Tool names available to worker */
|
|
320
|
+
tools: string[];
|
|
321
|
+
/** Step budget (1-10) */
|
|
322
|
+
steps: number;
|
|
323
|
+
/** Public orchestrator rationale that preceded this dispatch */
|
|
324
|
+
orchestratorContext?: string | undefined;
|
|
325
|
+
}
|
|
326
|
+
interface DispatchRecord {
|
|
327
|
+
tuple: Tuple;
|
|
328
|
+
artifact: Artifact;
|
|
329
|
+
transcript: Transcript;
|
|
330
|
+
progress: WorkerProgressEvent[];
|
|
331
|
+
completedAt: number;
|
|
332
|
+
/** Worker execution result (artifacts, actions, status) */
|
|
333
|
+
workerResult?: WorkerResult | undefined;
|
|
334
|
+
}
|
|
335
|
+
interface OodaSnapshot {
|
|
336
|
+
observations: string[];
|
|
337
|
+
beliefs: string[];
|
|
338
|
+
disprovenApproaches: string[];
|
|
339
|
+
blockers: string[];
|
|
340
|
+
decisionPressure: {
|
|
341
|
+
turn: number;
|
|
342
|
+
maxTurns: number;
|
|
343
|
+
turnsRemaining: number;
|
|
344
|
+
dispatchCount: number;
|
|
345
|
+
allIncomplete: boolean;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
type ReadEpisodeDetail = "summary" | "trace" | "artifacts";
|
|
349
|
+
interface ReadEpisodeArgs {
|
|
350
|
+
id: string;
|
|
351
|
+
detail?: ReadEpisodeDetail | undefined;
|
|
352
|
+
artifactKey?: string | undefined;
|
|
353
|
+
maxTokens?: number | undefined;
|
|
354
|
+
}
|
|
355
|
+
interface TraceToolCall {
|
|
356
|
+
toolName: string;
|
|
357
|
+
toolCallId?: string | undefined;
|
|
358
|
+
args: Record<string, unknown>;
|
|
359
|
+
}
|
|
360
|
+
type ArcTraceEvent = {
|
|
361
|
+
scope: "orchestrator";
|
|
362
|
+
phase: "model_input";
|
|
363
|
+
turn: number;
|
|
364
|
+
model: string;
|
|
365
|
+
system: string;
|
|
366
|
+
/** Full AgentMessage context before SDK conversion. */
|
|
367
|
+
messages: AgentMessage[];
|
|
368
|
+
/** Full SDK-facing messages after conversion. */
|
|
369
|
+
modelMessages: unknown[];
|
|
370
|
+
toolNames: string[];
|
|
371
|
+
} | {
|
|
372
|
+
scope: "orchestrator";
|
|
373
|
+
phase: "model_output";
|
|
374
|
+
turn: number;
|
|
375
|
+
text: string;
|
|
376
|
+
toolCalls: TraceToolCall[];
|
|
377
|
+
} | {
|
|
378
|
+
scope: "orchestrator";
|
|
379
|
+
phase: "public_rationale_missing";
|
|
380
|
+
turn: number;
|
|
381
|
+
toolCalls: TraceToolCall[];
|
|
382
|
+
} | {
|
|
383
|
+
scope: "orchestrator";
|
|
384
|
+
phase: "tool_call";
|
|
385
|
+
turn: number;
|
|
386
|
+
toolName: string;
|
|
387
|
+
args: Record<string, unknown>;
|
|
388
|
+
} | {
|
|
389
|
+
scope: "orchestrator";
|
|
390
|
+
phase: "tool_result";
|
|
391
|
+
turn: number;
|
|
392
|
+
toolName: string;
|
|
393
|
+
args: Record<string, unknown>;
|
|
394
|
+
result: unknown;
|
|
395
|
+
} | {
|
|
396
|
+
scope: "worker";
|
|
397
|
+
phase: "model_input";
|
|
398
|
+
tupleId: string;
|
|
399
|
+
step: number;
|
|
400
|
+
model: string;
|
|
401
|
+
system: string;
|
|
402
|
+
messages: AgentMessage[];
|
|
403
|
+
toolNames: string[];
|
|
404
|
+
} | {
|
|
405
|
+
scope: "worker";
|
|
406
|
+
phase: "model_output";
|
|
407
|
+
tupleId: string;
|
|
408
|
+
step: number;
|
|
409
|
+
action: unknown;
|
|
410
|
+
} | {
|
|
411
|
+
scope: "worker";
|
|
412
|
+
phase: "public_rationale_missing";
|
|
413
|
+
tupleId: string;
|
|
414
|
+
step: number;
|
|
415
|
+
toolNames: string[];
|
|
416
|
+
} | {
|
|
417
|
+
scope: "worker";
|
|
418
|
+
phase: "tool_call";
|
|
419
|
+
tupleId: string;
|
|
420
|
+
step: number;
|
|
421
|
+
toolCallId: string;
|
|
422
|
+
toolName: string;
|
|
423
|
+
args: Record<string, unknown>;
|
|
424
|
+
} | {
|
|
425
|
+
scope: "worker";
|
|
426
|
+
phase: "tool_result";
|
|
427
|
+
tupleId: string;
|
|
428
|
+
step: number;
|
|
429
|
+
toolCallId: string;
|
|
430
|
+
toolName: string;
|
|
431
|
+
result: unknown;
|
|
432
|
+
resultText: string;
|
|
433
|
+
} | {
|
|
434
|
+
scope: "worker";
|
|
435
|
+
phase: "worker_result";
|
|
436
|
+
tupleId: string;
|
|
437
|
+
result: unknown;
|
|
438
|
+
};
|
|
439
|
+
interface TranscriptStore {
|
|
440
|
+
append(transcript: Transcript): Promise<void>;
|
|
441
|
+
getAll(): Promise<Transcript[]>;
|
|
442
|
+
get(id: string): Promise<Transcript | null>;
|
|
443
|
+
}
|
|
444
|
+
interface VectorIndex {
|
|
445
|
+
add(id: string, text: string): Promise<void>;
|
|
446
|
+
search(query: string, k: number): Promise<string[]>;
|
|
447
|
+
load(): Promise<void>;
|
|
448
|
+
save(): Promise<void>;
|
|
449
|
+
}
|
|
450
|
+
interface ArtifactStore {
|
|
451
|
+
set(id: string, artifact: Artifact): Promise<void>;
|
|
452
|
+
get(id: string): Promise<Artifact | null>;
|
|
453
|
+
getAll(): Promise<Record<string, Artifact>>;
|
|
454
|
+
}
|
|
455
|
+
interface ScratchPad {
|
|
456
|
+
write(key: string, content: string): Promise<void>;
|
|
457
|
+
read(key: string): Promise<string | null>;
|
|
458
|
+
list(): Promise<string[]>;
|
|
459
|
+
}
|
|
460
|
+
/** What the orchestrator sees each turn */
|
|
461
|
+
interface OrchestratorContext {
|
|
462
|
+
task: string;
|
|
463
|
+
artifacts: Record<string, Artifact>;
|
|
464
|
+
lastResult: Artifact | null;
|
|
465
|
+
/** Rolling window of recent orchestrator messages */
|
|
466
|
+
recentTurns: AgentMessage[];
|
|
467
|
+
/** Current turn number */
|
|
468
|
+
turn: number;
|
|
469
|
+
/** Max turns allowed */
|
|
470
|
+
maxTurns: number;
|
|
471
|
+
/** Turns remaining after the current turn */
|
|
472
|
+
turnsRemaining: number;
|
|
473
|
+
/** Number of dispatches so far */
|
|
474
|
+
dispatchCount: number;
|
|
475
|
+
/** Number of dispatches since the orchestrator has not emitted done yet */
|
|
476
|
+
dispatchesWithoutFinalAnswer: number;
|
|
477
|
+
/** Artifact status counts across all completed dispatches */
|
|
478
|
+
artifactStatusCounts: Record<Artifact["status"], number>;
|
|
479
|
+
/** True while the orchestrator has not emitted the final done output */
|
|
480
|
+
noFinalAnswerYet: boolean;
|
|
481
|
+
/** True when no dispatch artifact has reached complete status */
|
|
482
|
+
allIncomplete: boolean;
|
|
483
|
+
/** Completed dispatches in chronological order */
|
|
484
|
+
dispatches: DispatchRecord[];
|
|
485
|
+
/** Current observe/orient state rendered into the orchestrator prompt */
|
|
486
|
+
ooda: OodaSnapshot;
|
|
487
|
+
/** LCM message store (all conversations) */
|
|
488
|
+
messageStore?: MessageStore | undefined;
|
|
489
|
+
/** LCM summary DAG */
|
|
490
|
+
summaryDAG?: SummaryDAG | undefined;
|
|
491
|
+
/** Ghost cues for compacted regions */
|
|
492
|
+
ghostCues?: GhostCue[] | undefined;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
interface ArcConfig {
|
|
496
|
+
task: string;
|
|
497
|
+
workDir: string;
|
|
498
|
+
/** Model ID for the orchestrator */
|
|
499
|
+
model: string;
|
|
500
|
+
/** Model ID for workers */
|
|
501
|
+
workerModel: string;
|
|
502
|
+
createModel?: ModelFactory;
|
|
503
|
+
toolProvider: ToolProvider;
|
|
504
|
+
/** Agent-provided tool definitions (Bash, Read, Write, etc.) with schemas, execute, and artifact metadata. Harness adds ARC framework tools internally. */
|
|
505
|
+
tools?: Map<string, Tool> | undefined;
|
|
506
|
+
/** Max orchestrator turns before stopping (default: 12) */
|
|
507
|
+
maxTurns?: number;
|
|
508
|
+
/** Max steps per worker (default: 5, max: 10) */
|
|
509
|
+
maxStepsPerWorker?: number;
|
|
510
|
+
/** Rolling window size for orchestrator context (default: 10) */
|
|
511
|
+
orchestratorWindowSize?: number;
|
|
512
|
+
/** Directory where agent memory lives (default: workDir/.arc) */
|
|
513
|
+
memDir?: string;
|
|
514
|
+
/** Injected vector index (default: in-memory for tests) */
|
|
515
|
+
vectorIndex?: VectorIndex;
|
|
516
|
+
/** Injected scratch pad for inter-worker note sharing (default: in-memory for tests) */
|
|
517
|
+
scratchPad?: ScratchPad;
|
|
518
|
+
/** Injected transcript store (default: in-memory) */
|
|
519
|
+
transcriptStore?: TranscriptStore;
|
|
520
|
+
/** Injected artifact store (default: in-memory) */
|
|
521
|
+
artifactStore?: ArtifactStore;
|
|
522
|
+
/** Custom worker system prompt (appended to default) */
|
|
523
|
+
workerSystemPromptSuffix?: string | undefined;
|
|
524
|
+
/** Custom messages after the core task/budget block */
|
|
525
|
+
formatOrchestratorContext?: ((context: OrchestratorContext) => AgentMessage[]) | undefined;
|
|
526
|
+
/** Provider options passed to generateText (e.g. reasoningEffort for OpenAI). */
|
|
527
|
+
providerOptions?: Record<string, unknown> | undefined;
|
|
528
|
+
/** Optional hook runner for PreToolUse/PostToolUse/BeforeWorker/AfterWorker events */
|
|
529
|
+
hookRunner?: HookRunner | undefined;
|
|
530
|
+
/** Callback for AskUser orchestrator tool. If provided, AskUser is available to the orchestrator. */
|
|
531
|
+
askUser?: ((question: string, options?: string[]) => Promise<string>) | undefined;
|
|
532
|
+
}
|
|
533
|
+
type ArcEvent = {
|
|
534
|
+
type: "orchestrator_turn";
|
|
535
|
+
turn: number;
|
|
536
|
+
contextTokens: number;
|
|
537
|
+
} | {
|
|
538
|
+
type: "trace";
|
|
539
|
+
trace: ArcTraceEvent;
|
|
540
|
+
} | {
|
|
541
|
+
type: "dispatch";
|
|
542
|
+
tupleId: string;
|
|
543
|
+
instruction: string;
|
|
544
|
+
} | {
|
|
545
|
+
type: "dispatch_full";
|
|
546
|
+
tuple: Tuple;
|
|
547
|
+
} | {
|
|
548
|
+
type: "worker_progress";
|
|
549
|
+
tupleId: string;
|
|
550
|
+
progress: WorkerProgressEvent;
|
|
551
|
+
} | {
|
|
552
|
+
type: "worker_complete";
|
|
553
|
+
tupleId: string;
|
|
554
|
+
status: Artifact["status"];
|
|
555
|
+
summary: string;
|
|
556
|
+
stepsUsed: number;
|
|
557
|
+
actions?: string[] | undefined;
|
|
558
|
+
} | {
|
|
559
|
+
type: "recall";
|
|
560
|
+
query: string;
|
|
561
|
+
answer: string;
|
|
562
|
+
} | {
|
|
563
|
+
type: "read_episode";
|
|
564
|
+
id: string;
|
|
565
|
+
detail: ReadEpisodeDetail;
|
|
566
|
+
output: string;
|
|
567
|
+
} | {
|
|
568
|
+
type: "ask_user";
|
|
569
|
+
question: string;
|
|
570
|
+
options?: string[] | undefined;
|
|
571
|
+
} | {
|
|
572
|
+
type: "done";
|
|
573
|
+
output: string;
|
|
574
|
+
} | {
|
|
575
|
+
type: "text_delta";
|
|
576
|
+
text: string;
|
|
577
|
+
};
|
|
578
|
+
type WorkerProgressEvent = {
|
|
579
|
+
kind: "model_start";
|
|
580
|
+
step: number;
|
|
581
|
+
maxSteps: number;
|
|
582
|
+
} | {
|
|
583
|
+
kind: "model_complete";
|
|
584
|
+
step: number;
|
|
585
|
+
actionType: "final" | "tool" | "tool_batch";
|
|
586
|
+
durationMs: number;
|
|
587
|
+
toolNames?: string[] | undefined;
|
|
588
|
+
publicRationale?: string | undefined;
|
|
589
|
+
missingPublicRationale?: boolean | undefined;
|
|
590
|
+
outputSummary?: string | undefined;
|
|
591
|
+
} | {
|
|
592
|
+
kind: "model_error";
|
|
593
|
+
step: number;
|
|
594
|
+
durationMs: number;
|
|
595
|
+
error: string;
|
|
596
|
+
} | {
|
|
597
|
+
kind: "tool_start";
|
|
598
|
+
step: number;
|
|
599
|
+
toolCallId: string;
|
|
600
|
+
toolName: string;
|
|
601
|
+
argsSummary?: string | undefined;
|
|
602
|
+
} | {
|
|
603
|
+
kind: "tool_complete";
|
|
604
|
+
step: number;
|
|
605
|
+
toolCallId: string;
|
|
606
|
+
toolName: string;
|
|
607
|
+
success: boolean;
|
|
608
|
+
durationMs: number;
|
|
609
|
+
outputSummary: string;
|
|
610
|
+
output?: string | undefined;
|
|
611
|
+
exitCode?: unknown;
|
|
612
|
+
} | {
|
|
613
|
+
kind: "tool_error";
|
|
614
|
+
step: number;
|
|
615
|
+
toolCallId: string;
|
|
616
|
+
toolName: string;
|
|
617
|
+
durationMs: number;
|
|
618
|
+
error: string;
|
|
619
|
+
} | {
|
|
620
|
+
kind: "worker_result";
|
|
621
|
+
status: "complete" | "incomplete" | "failed" | "interrupted";
|
|
622
|
+
stepsUsed: number;
|
|
623
|
+
summary: string;
|
|
624
|
+
};
|
|
625
|
+
interface RunWorkerConfig {
|
|
626
|
+
/** Original top-level task */
|
|
627
|
+
task?: string | undefined;
|
|
628
|
+
instruction: string;
|
|
629
|
+
/** Structured contract for this dispatch */
|
|
630
|
+
expectedOutput?: ExpectedOutputContract | undefined;
|
|
631
|
+
/** LCM-assembled context for this worker */
|
|
632
|
+
lcmContext?: AssembledContext | undefined;
|
|
633
|
+
/** Artifact ID -> file content */
|
|
634
|
+
inputArtifacts: Map<string, string>;
|
|
635
|
+
tools: Record<string, AnyTool>;
|
|
636
|
+
/** Tool registry with execute/artifact metadata for dispatch and episode projection */
|
|
637
|
+
toolRegistry: Map<string, Tool>;
|
|
638
|
+
maxSteps: number;
|
|
639
|
+
toolProvider: ToolProvider;
|
|
640
|
+
createModel: ModelFactory;
|
|
641
|
+
model: string;
|
|
642
|
+
workDir: string;
|
|
643
|
+
signal?: AbortSignal | undefined;
|
|
644
|
+
/** Extra text prefixed to worker system prompt */
|
|
645
|
+
systemPromptPrefix?: string | undefined;
|
|
646
|
+
/** Extra text appended to worker system prompt */
|
|
647
|
+
systemPromptSuffix?: string | undefined;
|
|
648
|
+
/** Provider options passed to generateText (e.g. reasoning config). */
|
|
649
|
+
providerOptions?: Record<string, unknown> | undefined;
|
|
650
|
+
/** Public orchestrator rationale that preceded this dispatch */
|
|
651
|
+
orchestratorContext?: string | undefined;
|
|
652
|
+
/** Tuple id for full-fidelity trace events */
|
|
653
|
+
tupleId?: string | undefined;
|
|
654
|
+
/** Optional diagnostic hook for streaming worker internals to the caller */
|
|
655
|
+
onProgress?: ((event: WorkerProgressEvent) => void) | undefined;
|
|
656
|
+
/** Optional full-fidelity trace hook for raw model/tool IO */
|
|
657
|
+
onTrace?: ((event: ArcTraceEvent) => void) | undefined;
|
|
658
|
+
/** Optional hook runner for PreToolUse/PostToolUse events */
|
|
659
|
+
hookRunner?: HookRunner | undefined;
|
|
660
|
+
}
|
|
661
|
+
interface WorkerResult {
|
|
662
|
+
transcript: AgentMessage[];
|
|
663
|
+
output: string | null;
|
|
664
|
+
status: "complete" | "incomplete" | "failed" | "interrupted";
|
|
665
|
+
stepsUsed: number;
|
|
666
|
+
/** Last message content for summary */
|
|
667
|
+
lastMessage: string;
|
|
668
|
+
/** All tool calls with results for orchestrator visibility */
|
|
669
|
+
actions: string[];
|
|
670
|
+
/** Artifacts touched during execution (from ToolResult.artifact) */
|
|
671
|
+
artifacts: ToolResultArtifact[];
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
interface ArcRunResult {
|
|
675
|
+
output: string;
|
|
676
|
+
events: ArcEvent[];
|
|
677
|
+
}
|
|
678
|
+
declare class ArcLoop {
|
|
679
|
+
private readonly config;
|
|
680
|
+
private readonly transcriptStore;
|
|
681
|
+
private readonly vectorIndex;
|
|
682
|
+
private readonly scratchPad;
|
|
683
|
+
private readonly artifactStore;
|
|
684
|
+
private readonly messageStore;
|
|
685
|
+
private readonly summaryDAG;
|
|
686
|
+
private readonly createModel;
|
|
687
|
+
private readonly windowSize;
|
|
688
|
+
private readonly model;
|
|
689
|
+
/** Orchestrator tool schemas (for the model) */
|
|
690
|
+
private readonly orchestratorToolSchemas;
|
|
691
|
+
/** Orchestrator tool registry (for execute) — excludes dispatch/done (control flow) */
|
|
692
|
+
private readonly orchestratorToolRegistry;
|
|
693
|
+
/** Dispatcher deps + mutable state — shared with dispatcher.ts functions */
|
|
694
|
+
private readonly dispatchDeps;
|
|
695
|
+
private readonly dispatchState;
|
|
696
|
+
private orchestratorMessageIndex;
|
|
697
|
+
private turn;
|
|
698
|
+
/** Per-turn abort controller — cancelled by interrupt(), refreshed each turn. */
|
|
699
|
+
private turnController;
|
|
700
|
+
constructor(config: ArcConfig);
|
|
701
|
+
/**
|
|
702
|
+
* Interrupt the current turn — cancels in-flight model calls and workers.
|
|
703
|
+
* The orchestrator loop stays alive and will prompt for user steering.
|
|
704
|
+
*/
|
|
705
|
+
interrupt(): void;
|
|
706
|
+
/**
|
|
707
|
+
* Stream events from the orchestration loop.
|
|
708
|
+
*/
|
|
709
|
+
stream(signal?: AbortSignal): AsyncGenerator<ArcEvent>;
|
|
710
|
+
/**
|
|
711
|
+
* Run the orchestration loop to completion.
|
|
712
|
+
*/
|
|
713
|
+
run(signal?: AbortSignal): Promise<ArcRunResult>;
|
|
714
|
+
/** Append a message to the LCM message store (single source of truth) */
|
|
715
|
+
private appendOrchestratorMessage;
|
|
716
|
+
private findEpisodeRecordBySummaryId;
|
|
717
|
+
private buildContext;
|
|
718
|
+
private buildOrchestratorMessages;
|
|
719
|
+
private buildTaskContextText;
|
|
720
|
+
private readEpisode;
|
|
721
|
+
/**
|
|
722
|
+
* Handle a turn interrupt: prompt user for steering, inject into context.
|
|
723
|
+
*/
|
|
724
|
+
private handleInterrupt;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
type ModelMessage = any;
|
|
728
|
+
/**
|
|
729
|
+
* Convert AgentMessage[] to Vercel AI SDK ModelMessage[].
|
|
730
|
+
* Extracted from VercelAgentLoop — identical logic, standalone pure function.
|
|
731
|
+
*
|
|
732
|
+
* System messages that appear after user/assistant/tool messages are
|
|
733
|
+
* converted to user messages with a [System] prefix. The Anthropic API
|
|
734
|
+
* does not allow interleaved system messages; the actual system prompt
|
|
735
|
+
* is passed separately via the `system` parameter.
|
|
736
|
+
*/
|
|
737
|
+
declare function toModelMessages(messages: AgentMessage[]): ModelMessage[];
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Episode projection: minimal formatting for orchestrator context.
|
|
741
|
+
*
|
|
742
|
+
* The worker collects artifacts and actions during execution.
|
|
743
|
+
* This module just formats DispatchRecords for the orchestrator prompt.
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
/** Format a single dispatch record for the orchestrator prompt */
|
|
747
|
+
declare function formatDispatchForPrompt(record: DispatchRecord, options?: {
|
|
748
|
+
compact?: boolean;
|
|
749
|
+
maxChars?: number;
|
|
750
|
+
}): string;
|
|
751
|
+
/** Build OODA snapshot from dispatch records — reads WorkerResult directly */
|
|
752
|
+
declare function buildOodaSnapshot(input: {
|
|
753
|
+
turn: number;
|
|
754
|
+
maxTurns: number;
|
|
755
|
+
turnsRemaining: number;
|
|
756
|
+
dispatchCount: number;
|
|
757
|
+
allIncomplete: boolean;
|
|
758
|
+
dispatches: DispatchRecord[];
|
|
759
|
+
}): OodaSnapshot;
|
|
760
|
+
declare function formatOodaSnapshotForPrompt(snapshot: OodaSnapshot): string;
|
|
761
|
+
declare function formatReadEpisodeResult(record: DispatchRecord): string;
|
|
762
|
+
declare function formatTranscriptTrace(messages: AgentMessage[], toolResultLimit: number): string;
|
|
763
|
+
|
|
764
|
+
/** Dispatch a worker to accomplish a task */
|
|
765
|
+
declare const dispatch: ai.Tool<{
|
|
766
|
+
instruction: string;
|
|
767
|
+
expectedOutput: string | {
|
|
768
|
+
artifacts?: {
|
|
769
|
+
type: "unknown" | "file" | "directory" | "value";
|
|
770
|
+
path?: string | undefined;
|
|
771
|
+
description?: string | undefined;
|
|
772
|
+
}[] | undefined;
|
|
773
|
+
successCriteria?: string[] | undefined;
|
|
774
|
+
verification?: string | undefined;
|
|
775
|
+
description?: string | undefined;
|
|
776
|
+
kind?: "unknown" | "file" | "value" | "files" | undefined;
|
|
777
|
+
path?: string | undefined;
|
|
778
|
+
paths?: string[] | undefined;
|
|
779
|
+
};
|
|
780
|
+
inputs?: string[] | undefined;
|
|
781
|
+
}, never>;
|
|
782
|
+
/** Mark task complete and return final output */
|
|
783
|
+
declare const done: ai.Tool<{
|
|
784
|
+
output: string;
|
|
785
|
+
}, never>;
|
|
786
|
+
interface ArcToolDeps {
|
|
787
|
+
readEpisode?: (args: ReadEpisodeArgs) => Promise<string>;
|
|
788
|
+
historySearch?: (pattern: string, opts?: {
|
|
789
|
+
conversationId?: string;
|
|
790
|
+
maxResults?: number;
|
|
791
|
+
}) => GrepResult[];
|
|
792
|
+
historyExpand?: (summaryId: string, maxTokens?: number) => string;
|
|
793
|
+
historyOverview?: (summaryId?: string) => string;
|
|
794
|
+
historyRead?: (conversationId: string, messageIndex: number) => string | null;
|
|
795
|
+
scratchPad?: ScratchPad;
|
|
796
|
+
recall?: (query: string) => Promise<string>;
|
|
797
|
+
askUser?: (question: string, options?: string[]) => Promise<string>;
|
|
798
|
+
}
|
|
799
|
+
/** Build worker-facing ARC tools with execute closures */
|
|
800
|
+
declare function buildWorkerToolEntries(deps: ArcToolDeps): Map<string, Tool>;
|
|
801
|
+
/** Build orchestrator-facing ARC tools with execute closures (excludes dispatch/done which are control flow) */
|
|
802
|
+
declare function buildOrchestratorToolEntries(deps: ArcToolDeps): Map<string, Tool>;
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Build a depth-0 (leaf) summary node from a completed dispatch record.
|
|
806
|
+
* Reads artifacts and actions directly from the worker result.
|
|
807
|
+
*/
|
|
808
|
+
declare function buildLeafSummary(record: DispatchRecord): SummaryNode;
|
|
809
|
+
|
|
810
|
+
interface LcmToolDeps {
|
|
811
|
+
messageStore: MessageStore;
|
|
812
|
+
summaryDAG: SummaryDAG;
|
|
813
|
+
vectorIndex: VectorIndex;
|
|
814
|
+
transcriptStore: TranscriptStore;
|
|
815
|
+
/** Needed for expandSummary fallback when message store has no messages for a leaf */
|
|
816
|
+
findDispatchRecord: (summaryId: string) => DispatchRecord | undefined;
|
|
817
|
+
}
|
|
818
|
+
/** Expand a summary node — leaf nodes return source transcript, rollups return child summaries */
|
|
819
|
+
declare function expandSummary(deps: LcmToolDeps, summaryId: string, maxTokens: number): string;
|
|
820
|
+
/** Describe a summary node's metadata, or show DAG overview */
|
|
821
|
+
declare function describeSummary(deps: LcmToolDeps, summaryId?: string): string;
|
|
822
|
+
/** Direct vector search recall — returns matching transcript excerpts */
|
|
823
|
+
declare function recallDirect(deps: LcmToolDeps, query: string): Promise<string>;
|
|
824
|
+
/** Read a specific message from the message store at full fidelity */
|
|
825
|
+
declare function historyRead(deps: LcmToolDeps, conversationId: string, messageIndex: number): string | null;
|
|
826
|
+
/** Search across all stored messages from all conversations */
|
|
827
|
+
declare const history_search: ai.Tool<{
|
|
828
|
+
pattern: string;
|
|
829
|
+
conversationId?: string | undefined;
|
|
830
|
+
maxResults?: number | undefined;
|
|
831
|
+
}, never>;
|
|
832
|
+
/** Expand a summary node back to its source messages or child summaries */
|
|
833
|
+
declare const history_expand: ai.Tool<{
|
|
834
|
+
summaryId: string;
|
|
835
|
+
maxTokens?: number | undefined;
|
|
836
|
+
}, never>;
|
|
837
|
+
/** Show summary node metadata or history overview */
|
|
838
|
+
declare const history_overview: ai.Tool<{
|
|
839
|
+
summaryId?: string | undefined;
|
|
840
|
+
}, never>;
|
|
841
|
+
/** Read a specific message from run history at full fidelity */
|
|
842
|
+
declare const history_read: ai.Tool<{
|
|
843
|
+
conversationId: string;
|
|
844
|
+
messageIndex: number;
|
|
845
|
+
}, never>;
|
|
846
|
+
|
|
847
|
+
declare function cloneForTrace<T>(value: T): T;
|
|
848
|
+
declare function normalizeReadEpisodeArgs(args: Record<string, unknown>): ReadEpisodeArgs;
|
|
849
|
+
|
|
850
|
+
/** In-memory transcript store for testing */
|
|
851
|
+
declare class MemoryTranscriptStore implements TranscriptStore {
|
|
852
|
+
private transcripts;
|
|
853
|
+
private byId;
|
|
854
|
+
append(transcript: Transcript): Promise<void>;
|
|
855
|
+
getAll(): Promise<Transcript[]>;
|
|
856
|
+
get(id: string): Promise<Transcript | null>;
|
|
857
|
+
}
|
|
858
|
+
/** In-memory vector index for testing (no actual embeddings) */
|
|
859
|
+
declare class MemoryVectorIndex implements VectorIndex {
|
|
860
|
+
private entries;
|
|
861
|
+
add(id: string, text: string): Promise<void>;
|
|
862
|
+
search(query: string, k: number): Promise<string[]>;
|
|
863
|
+
load(): Promise<void>;
|
|
864
|
+
save(): Promise<void>;
|
|
865
|
+
}
|
|
866
|
+
/** In-memory scratch pad for testing */
|
|
867
|
+
declare class MemoryScratchPad implements ScratchPad {
|
|
868
|
+
private entries;
|
|
869
|
+
write(key: string, content: string): Promise<void>;
|
|
870
|
+
read(key: string): Promise<string | null>;
|
|
871
|
+
list(): Promise<string[]>;
|
|
872
|
+
}
|
|
873
|
+
/** In-memory artifact store for testing */
|
|
874
|
+
declare class MemoryArtifactStore implements ArtifactStore {
|
|
875
|
+
private artifacts;
|
|
876
|
+
set(id: string, artifact: Artifact): Promise<void>;
|
|
877
|
+
get(id: string): Promise<Artifact | null>;
|
|
878
|
+
getAll(): Promise<Record<string, Artifact>>;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* File-based transcript store.
|
|
883
|
+
* Stores transcripts as individual JSON files in a directory.
|
|
884
|
+
*/
|
|
885
|
+
declare class FsTranscriptStore implements TranscriptStore {
|
|
886
|
+
private readonly dir;
|
|
887
|
+
private readonly indexPath;
|
|
888
|
+
private index;
|
|
889
|
+
private loaded;
|
|
890
|
+
constructor(dir: string);
|
|
891
|
+
append(transcript: Transcript): Promise<void>;
|
|
892
|
+
getAll(): Promise<Transcript[]>;
|
|
893
|
+
get(id: string): Promise<Transcript | null>;
|
|
894
|
+
private ensureLoaded;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* File-based artifact store.
|
|
898
|
+
* Stores artifacts in a single JSON file.
|
|
899
|
+
*/
|
|
900
|
+
declare class FsArtifactStore implements ArtifactStore {
|
|
901
|
+
private readonly filePath;
|
|
902
|
+
private artifacts;
|
|
903
|
+
private loaded;
|
|
904
|
+
constructor(filePath: string);
|
|
905
|
+
set(id: string, artifact: Artifact): Promise<void>;
|
|
906
|
+
get(id: string): Promise<Artifact | null>;
|
|
907
|
+
getAll(): Promise<Record<string, Artifact>>;
|
|
908
|
+
private ensureLoaded;
|
|
909
|
+
private save;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Run a stateless worker with the given configuration.
|
|
914
|
+
* Workers see only: instruction, input artifacts, and tools.
|
|
915
|
+
*/
|
|
916
|
+
declare function runWorker(config: RunWorkerConfig): Promise<WorkerResult>;
|
|
917
|
+
|
|
918
|
+
declare const ORCHESTRATOR_SYSTEM_PROMPT = "You accomplish tasks by dispatching workers and synthesizing results.\n\nDispatch workers for anything requiring tool use. Answer directly with done for questions you can answer from knowledge or prior results.\n\nWorkers are stateless \u2014 they see only their instruction, input artifacts, and tools. They also have access to history and scratch pad tools, so you don't need to repeat everything.\n\nOlder context gets compacted into summaries. Use history_search to find specific prior results, history_read for full content, and history_expand to restore compacted summaries.\n\nBefore dispatching, check what prior workers attempted. Do not repeat failed approaches \u2014 change strategy or decompose differently.\n\nExplain your reasoning before each tool call.\n\nCall done as soon as the task is satisfied. Re-dispatching costs turns \u2014 only follow up if the result is incomplete, failed, or clearly wrong.";
|
|
919
|
+
declare const WORKER_SYSTEM_PROMPT = "Complete the instruction using the available tools. Workers are stateless and cannot interact with the user \u2014 assume reasonable defaults and proceed.\n\nBefore starting, check ScratchPad_List for notes from prior workers and use history_search to find relevant prior attempts.\n\nIf you are running low on steps, stop and write your progress to ScratchPad_Write \u2014 this is more valuable than one more attempt.\n\nBefore finishing, verify your work against the expected output contract. If verification fails, fix it.\n\nExplain your reasoning before each tool call.";
|
|
920
|
+
|
|
921
|
+
/** A system prompt block with optional Anthropic cache control. */
|
|
922
|
+
interface SystemPromptBlock {
|
|
923
|
+
text: string;
|
|
924
|
+
cacheControl?: {
|
|
925
|
+
type: "ephemeral";
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
interface VercelAgentLoopConfig {
|
|
929
|
+
model?: string;
|
|
930
|
+
/** System prompt — string or structured blocks with cache control markers. */
|
|
931
|
+
systemPrompt?: string | SystemPromptBlock[];
|
|
932
|
+
createModel?: ModelFactory;
|
|
933
|
+
/** @deprecated Prefer createModel. */
|
|
934
|
+
apiKey?: string;
|
|
935
|
+
/** Custom tool definitions. If provided, replaces built-in agentTools for LLM calls. */
|
|
936
|
+
tools?: Record<string, AnyTool>;
|
|
937
|
+
/** Tool choice for LLM calls. Supports per-turn callbacks. Default: 'auto'. */
|
|
938
|
+
toolChoice?: ToolChoiceConfig;
|
|
939
|
+
/** Provider options passed to generateText/streamText (e.g. anthropic thinking config). */
|
|
940
|
+
providerOptions?: Record<string, unknown>;
|
|
941
|
+
/** Per-step callback to override model and active tools before each LLM call. */
|
|
942
|
+
prepareStep?: (context: PrepareStepContext) => PrepareStepResult | void;
|
|
943
|
+
}
|
|
944
|
+
declare class VercelAgentLoop implements AgentLoop {
|
|
945
|
+
private readonly model;
|
|
946
|
+
private readonly createModel;
|
|
947
|
+
private readonly systemPrompt;
|
|
948
|
+
private readonly tools;
|
|
949
|
+
private readonly validToolNames;
|
|
950
|
+
private readonly toolChoiceConfig;
|
|
951
|
+
private readonly providerOptions;
|
|
952
|
+
private readonly prepareStep;
|
|
953
|
+
/** Track tool names called across steps for prepareStep context. */
|
|
954
|
+
private toolCallHistory;
|
|
955
|
+
private step;
|
|
956
|
+
/** Last step's token usage — read after nextAction/streamAction completes. */
|
|
957
|
+
lastUsage: StepUsage | undefined;
|
|
958
|
+
constructor(config?: VercelAgentLoopConfig);
|
|
959
|
+
/** Build the `system` parameter for generateText/streamText. */
|
|
960
|
+
private buildSystemParam;
|
|
961
|
+
/** Resolve model + tools for this step via prepareStep callback. */
|
|
962
|
+
private resolveStep;
|
|
963
|
+
/** Extract StepUsage from AI SDK usage object. */
|
|
964
|
+
private static extractUsage;
|
|
965
|
+
nextAction(messages: AgentMessage[], signal?: AbortSignal): Promise<AgentAction>;
|
|
966
|
+
streamAction(messages: AgentMessage[]): AsyncGenerator<AgentStreamEvent>;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
export { AnyTool, type ArcConfig, type ArcEvent, ArcLoop, type ArcRunResult, type ArcToolDeps, type ArcTraceEvent, type Artifact, type ArtifactStore, type AssembleWorkerContextOpts, type AssembledContext, type CompactionOpts, type DispatchRecord, type ExpectedArtifact, type ExpectedOutputContract, FsArtifactStore, FsTranscriptStore, type GhostCue, type GrepResult, type HookCallback, type HookContext, type HookDecision, type HookEventName, HookRunner, type LcmToolDeps, MemoryArtifactStore, MemoryMessageStore, MemoryScratchPad, MemorySummaryDAG, MemoryTranscriptStore, MemoryVectorIndex, type MessageStore, ModelFactory, ORCHESTRATOR_SYSTEM_PROMPT, type OodaSnapshot, type OrchestratorContext, type ReadEpisodeArgs, type ReadEpisodeDetail, type RunWorkerConfig, type ScratchPad, type StoredMessage, type SummaryDAG, type SummaryNode, type SystemPromptBlock, type Tool, ToolChoiceConfig, ToolProvider, ToolResult, ToolResultArtifact, type TraceToolCall, type Transcript, type TranscriptStore, type Tuple, type VectorIndex, VercelAgentLoop, type VercelAgentLoopConfig, WORKER_SYSTEM_PROMPT, type WorkerProgressEvent, type WorkerResult, assembleContext, assembleWorkerContext, buildLeafSummary, buildOodaSnapshot, buildOrchestratorToolEntries, buildWorkerToolEntries, cloneForTrace, describeSummary, dispatch, done, expandSummary, formatDispatchForPrompt, formatOodaSnapshotForPrompt, formatReadEpisodeResult, formatTranscriptTrace, historyRead, history_expand, history_overview, history_read, history_search, normalizeReadEpisodeArgs, recallDirect, runWorker, toModelMessages, toolSchemasFromRegistry };
|