@cuylabs/agent-core 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -372
- package/dist/{builder-RcTZuYnO.d.ts → builder-BRvqCcIk.d.ts} +2 -2
- package/dist/{resolver-DOfZ-xuk.d.ts → capability-resolver-CgRGsWVX.d.ts} +1 -1
- package/dist/{chunk-IMGQOTU2.js → chunk-3HNO5SVI.js} +286 -690
- package/dist/chunk-5K7AQVOU.js +619 -0
- package/dist/{chunk-QAQADS4X.js → chunk-BNSHUWCV.js} +1 -0
- package/dist/{chunk-OTUGSCED.js → chunk-CDTV2UYU.js} +159 -1
- package/dist/chunk-IEFIQENH.js +73 -0
- package/dist/chunk-N7P4PN3O.js +84 -0
- package/dist/{chunk-QWFMX226.js → chunk-QGOGIP7T.js} +148 -15
- package/dist/chunk-VNQBHPCT.js +398 -0
- package/dist/{chunk-X635CM2F.js → chunk-ZPMACVZK.js} +1 -1
- package/dist/context/index.js +1 -1
- package/dist/host/index.d.ts +45 -0
- package/dist/host/index.js +8 -0
- package/dist/{index-p0kOsVsE.d.ts → index-C33hlD6H.d.ts} +12 -7
- package/dist/{index-tmhaADz5.d.ts → index-CfBGYrpd.d.ts} +121 -2
- package/dist/index.d.ts +107 -126
- package/dist/index.js +322 -597
- package/dist/inference/index.d.ts +59 -0
- package/dist/inference/index.js +25 -0
- package/dist/middleware/index.d.ts +8 -4
- package/dist/middleware/index.js +5 -3
- package/dist/models/index.d.ts +104 -2
- package/dist/models/index.js +40 -6
- package/dist/prompt/index.d.ts +10 -6
- package/dist/reasoning/index.d.ts +54 -8
- package/dist/reasoning/index.js +2 -3
- package/dist/{registry-CuRWWtcT.d.ts → registry-BDLIHOQB.d.ts} +1 -1
- package/dist/{runner-C7aMP_x3.d.ts → runner-DSKaEz3z.d.ts} +290 -7
- package/dist/runtime/index.d.ts +41 -7
- package/dist/runtime/index.js +15 -6
- package/dist/scope/index.d.ts +10 -0
- package/dist/scope/index.js +14 -0
- package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
- package/dist/skill/index.d.ts +7 -5
- package/dist/storage/index.d.ts +2 -2
- package/dist/sub-agent/index.d.ts +12 -8
- package/dist/tool/index.d.ts +8 -4
- package/dist/tool/index.js +4 -3
- package/dist/{tool-pFAnJc5Y.d.ts → tool-Db1Ue-1U.d.ts} +1 -1
- package/dist/{tool-DYp6-cC3.d.ts → tool-HUtkiVBx.d.ts} +5 -99
- package/dist/tracking/index.d.ts +3 -1
- package/dist/types-9jGQUjqW.d.ts +29 -0
- package/dist/types-CHiPh8U2.d.ts +100 -0
- package/dist/types-CqDZTh4d.d.ts +335 -0
- package/dist/types-FRpzzg_9.d.ts +355 -0
- package/package.json +19 -8
- package/dist/capabilities/index.d.ts +0 -97
- package/dist/capabilities/index.js +0 -46
- package/dist/chunk-6TDTQJ4P.js +0 -116
- package/dist/chunk-DWYX7ASF.js +0 -26
- package/dist/chunk-FG4MD5MU.js +0 -54
- package/dist/config-D2xeGEHK.d.ts +0 -52
- package/dist/identifiers-BLUxFqV_.d.ts +0 -12
- package/dist/network-D76DS5ot.d.ts +0 -5
- package/dist/types-MM1JoX5T.d.ts +0 -810
package/dist/index.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentTurnEngine,
|
|
3
3
|
ContextOverflowError,
|
|
4
|
-
DEFAULT_RETRY_CONFIG,
|
|
5
4
|
DoomLoopError,
|
|
6
|
-
LLM,
|
|
7
|
-
LLMError,
|
|
8
|
-
OUTPUT_TOKEN_MAX,
|
|
9
5
|
advanceAgentTurnState,
|
|
10
6
|
applyAgentWorkflowCommitResult,
|
|
11
7
|
applyAgentWorkflowModelStepResult,
|
|
12
8
|
applyAgentWorkflowToolBatchResult,
|
|
13
9
|
applyAgentWorkflowToolCallResult,
|
|
14
|
-
calculateDelay,
|
|
15
10
|
cloneAgentWorkflowTurnState,
|
|
16
11
|
commitOutput,
|
|
17
12
|
commitStep,
|
|
@@ -21,29 +16,21 @@ import {
|
|
|
21
16
|
createAgentTurnState,
|
|
22
17
|
createAgentTurnStepCommitBatch,
|
|
23
18
|
createAgentWorkflowTurnState,
|
|
24
|
-
createRetryHandler,
|
|
25
|
-
createRetryState,
|
|
26
19
|
defaultAgentTaskCheckpointStrategy,
|
|
27
20
|
failAgentTurnState,
|
|
28
21
|
failAgentWorkflowTurnState,
|
|
29
|
-
getErrorCategory,
|
|
30
|
-
getRetryDelay,
|
|
31
|
-
isRetryable,
|
|
32
|
-
isRetryableCategory,
|
|
33
22
|
planNextAgentWorkflowOperation,
|
|
34
23
|
prepareModelStep,
|
|
24
|
+
processStepStream,
|
|
35
25
|
processStream,
|
|
36
26
|
recordAgentWorkflowReplayDecision,
|
|
37
27
|
restoreAgentWorkflowMessage,
|
|
38
28
|
restoreAgentWorkflowMessages,
|
|
39
29
|
runModelStep,
|
|
40
30
|
runToolBatch,
|
|
41
|
-
shouldRetry,
|
|
42
|
-
sleep,
|
|
43
31
|
snapshotAgentWorkflowMessage,
|
|
44
|
-
snapshotAgentWorkflowMessages
|
|
45
|
-
|
|
46
|
-
} from "./chunk-IMGQOTU2.js";
|
|
32
|
+
snapshotAgentWorkflowMessages
|
|
33
|
+
} from "./chunk-3HNO5SVI.js";
|
|
47
34
|
import {
|
|
48
35
|
createSkillResourceTool,
|
|
49
36
|
createSkillTool,
|
|
@@ -54,18 +41,25 @@ import {
|
|
|
54
41
|
MemoryStorage,
|
|
55
42
|
STORAGE_VERSION,
|
|
56
43
|
SessionManager,
|
|
44
|
+
buildEntryPath,
|
|
57
45
|
buildMessagesFromEntries,
|
|
58
46
|
configureDefaultSessionManager,
|
|
47
|
+
createMessageEntry,
|
|
48
|
+
createMetadataEntry,
|
|
59
49
|
deserializeMessage,
|
|
50
|
+
extractSessionInfo,
|
|
60
51
|
generateEntryId,
|
|
61
52
|
getDataDir,
|
|
62
53
|
getDefaultSessionManager,
|
|
54
|
+
getGitRootHash,
|
|
63
55
|
getLeafId,
|
|
56
|
+
getProjectId,
|
|
64
57
|
getProjectSessionsDir,
|
|
65
58
|
getSessionsDir,
|
|
66
59
|
parseJSONL,
|
|
67
60
|
serializeMessage,
|
|
68
|
-
toJSONL
|
|
61
|
+
toJSONL,
|
|
62
|
+
toJSONLBatch
|
|
69
63
|
} from "./chunk-BDBZ3SLK.js";
|
|
70
64
|
import {
|
|
71
65
|
DEFAULT_MAX_CONCURRENT,
|
|
@@ -78,9 +72,6 @@ import {
|
|
|
78
72
|
ToolRegistry,
|
|
79
73
|
defaultRegistry
|
|
80
74
|
} from "./chunk-SDSBEQXG.js";
|
|
81
|
-
import {
|
|
82
|
-
executeAgentToolCall
|
|
83
|
-
} from "./chunk-FG4MD5MU.js";
|
|
84
75
|
import {
|
|
85
76
|
MAX_BYTES,
|
|
86
77
|
MAX_LINES,
|
|
@@ -98,14 +89,10 @@ import {
|
|
|
98
89
|
createCheckpointManager,
|
|
99
90
|
createTurnTracker
|
|
100
91
|
} from "./chunk-VBWWUHWI.js";
|
|
101
|
-
import {
|
|
102
|
-
extractFilePathsFromArgs,
|
|
103
|
-
shouldCaptureBaseline,
|
|
104
|
-
withFileTracking
|
|
105
|
-
} from "./chunk-VEKUXUVF.js";
|
|
106
92
|
import {
|
|
107
93
|
ContextManager,
|
|
108
94
|
DEFAULT_CONTEXT_LIMITS,
|
|
95
|
+
PRUNE_PROTECTED_TOOLS,
|
|
109
96
|
estimateConversationTokens,
|
|
110
97
|
estimateMessageTokens,
|
|
111
98
|
estimateTokens,
|
|
@@ -115,14 +102,65 @@ import {
|
|
|
115
102
|
pruneContext,
|
|
116
103
|
pruneToolResults,
|
|
117
104
|
shouldPruneContext
|
|
118
|
-
} from "./chunk-
|
|
105
|
+
} from "./chunk-BNSHUWCV.js";
|
|
119
106
|
import {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
107
|
+
dockerHost,
|
|
108
|
+
localHost
|
|
109
|
+
} from "./chunk-VNQBHPCT.js";
|
|
110
|
+
import {
|
|
111
|
+
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
112
|
+
DEFAULT_RETRY_CONFIG,
|
|
113
|
+
Inference,
|
|
114
|
+
LLM,
|
|
115
|
+
LLMError,
|
|
116
|
+
OUTPUT_TOKEN_MAX,
|
|
117
|
+
buildToolSet,
|
|
118
|
+
calculateDelay,
|
|
119
|
+
createRetryHandler,
|
|
120
|
+
createRetryState,
|
|
121
|
+
getErrorCategory,
|
|
122
|
+
getRetryDelay,
|
|
123
|
+
isRetryable,
|
|
124
|
+
isRetryableCategory,
|
|
125
|
+
parseRetryDelay,
|
|
126
|
+
shouldRetry,
|
|
127
|
+
sleep,
|
|
128
|
+
stream,
|
|
129
|
+
streamOnce,
|
|
130
|
+
streamStep,
|
|
131
|
+
withRetry
|
|
132
|
+
} from "./chunk-5K7AQVOU.js";
|
|
133
|
+
import {
|
|
134
|
+
EXTENDED_LEVELS,
|
|
135
|
+
FIXED_LEVELS,
|
|
136
|
+
STANDARD_LEVELS,
|
|
137
|
+
buildAnthropicOptions,
|
|
138
|
+
buildBedrockOptions,
|
|
139
|
+
buildGoogleOptions,
|
|
140
|
+
buildGroqOptions,
|
|
141
|
+
buildOpenAIOptions,
|
|
142
|
+
buildOpenRouterOptions,
|
|
143
|
+
buildReasoningOptions,
|
|
144
|
+
buildReasoningOptionsSync,
|
|
145
|
+
buildXAIOptions,
|
|
146
|
+
getProviderOptionsKey,
|
|
147
|
+
getReasoningConfig,
|
|
148
|
+
getReasoningConfigSync,
|
|
149
|
+
shouldIncludeReasoningSummary,
|
|
150
|
+
supportsReasoning,
|
|
151
|
+
supportsReasoningSync
|
|
152
|
+
} from "./chunk-ZPMACVZK.js";
|
|
153
|
+
import {
|
|
154
|
+
executeAgentToolCall
|
|
155
|
+
} from "./chunk-IEFIQENH.js";
|
|
156
|
+
import {
|
|
157
|
+
streamWithinScope
|
|
158
|
+
} from "./chunk-N7P4PN3O.js";
|
|
159
|
+
import {
|
|
160
|
+
extractFilePathsFromArgs,
|
|
161
|
+
shouldCaptureBaseline,
|
|
162
|
+
withFileTracking
|
|
163
|
+
} from "./chunk-VEKUXUVF.js";
|
|
126
164
|
import {
|
|
127
165
|
ApprovalDeniedError,
|
|
128
166
|
ApprovalTimeoutError,
|
|
@@ -131,11 +169,39 @@ import {
|
|
|
131
169
|
createApprovalHandler,
|
|
132
170
|
createTelemetryConfig,
|
|
133
171
|
getToolRisk,
|
|
134
|
-
otelMiddleware
|
|
135
|
-
|
|
172
|
+
otelMiddleware,
|
|
173
|
+
promptCacheMiddleware
|
|
174
|
+
} from "./chunk-CDTV2UYU.js";
|
|
136
175
|
import {
|
|
137
|
-
|
|
138
|
-
|
|
176
|
+
CacheCapabilitySource,
|
|
177
|
+
CapabilityCache,
|
|
178
|
+
DEFAULT_RESOLVER_OPTIONS,
|
|
179
|
+
ModelCapabilityResolver,
|
|
180
|
+
PatternCapabilitySource,
|
|
181
|
+
RemoteCapabilityFetcher,
|
|
182
|
+
RemoteCapabilitySource,
|
|
183
|
+
SourcePriority,
|
|
184
|
+
applyCapabilityOverride,
|
|
185
|
+
configureResolver,
|
|
186
|
+
createResolver,
|
|
187
|
+
extractModelId,
|
|
188
|
+
extractProvider,
|
|
189
|
+
findCapabilityOverride,
|
|
190
|
+
getDefaultResolver,
|
|
191
|
+
getModelId,
|
|
192
|
+
getNetworkStatus,
|
|
193
|
+
getProviderCompatibility,
|
|
194
|
+
getProviderId,
|
|
195
|
+
inferProvider,
|
|
196
|
+
likelySupportsReasoning
|
|
197
|
+
} from "./chunk-QGOGIP7T.js";
|
|
198
|
+
import {
|
|
199
|
+
createMCPManager,
|
|
200
|
+
defineServer,
|
|
201
|
+
httpServer,
|
|
202
|
+
sseServer,
|
|
203
|
+
stdioServer
|
|
204
|
+
} from "./chunk-ZXAKHMWH.js";
|
|
139
205
|
import {
|
|
140
206
|
DEFAULT_INSTRUCTION_PATTERNS,
|
|
141
207
|
DEFAULT_MAX_DEPTH,
|
|
@@ -173,24 +239,6 @@ import {
|
|
|
173
239
|
loadSkillMetadata,
|
|
174
240
|
parseFrontmatter
|
|
175
241
|
} from "./chunk-LRHOS4ZN.js";
|
|
176
|
-
import {
|
|
177
|
-
buildReasoningOptions,
|
|
178
|
-
buildReasoningOptionsSync,
|
|
179
|
-
getReasoningConfig,
|
|
180
|
-
getReasoningConfigSync,
|
|
181
|
-
supportsReasoning,
|
|
182
|
-
supportsReasoningSync
|
|
183
|
-
} from "./chunk-X635CM2F.js";
|
|
184
|
-
import {
|
|
185
|
-
ModelCapabilityResolver,
|
|
186
|
-
configureResolver,
|
|
187
|
-
getDefaultResolver,
|
|
188
|
-
getNetworkStatus
|
|
189
|
-
} from "./chunk-QWFMX226.js";
|
|
190
|
-
import {
|
|
191
|
-
getModelId,
|
|
192
|
-
getProviderId
|
|
193
|
-
} from "./chunk-DWYX7ASF.js";
|
|
194
242
|
|
|
195
243
|
// src/agent/chat-loop/commit.ts
|
|
196
244
|
function createChatLoopCommitBatchApplier(params) {
|
|
@@ -279,164 +327,177 @@ function accumulateUsage(current, next) {
|
|
|
279
327
|
|
|
280
328
|
// src/agent/chat-loop/loop.ts
|
|
281
329
|
async function* runChatLoop(deps) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
turnTracker,
|
|
291
|
-
interventionCtrl,
|
|
292
|
-
middlewareRunner,
|
|
293
|
-
contextManager,
|
|
294
|
-
rememberedDoomLoopTools,
|
|
295
|
-
reasoningLevel,
|
|
296
|
-
promptBuilder,
|
|
297
|
-
host,
|
|
298
|
-
mcpTools,
|
|
299
|
-
toModelMessages,
|
|
300
|
-
setIsStreaming
|
|
301
|
-
} = deps;
|
|
302
|
-
const turnEngine = createAgentTurnEngine({
|
|
303
|
-
sessionId,
|
|
304
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
305
|
-
getToolReplayPolicy: (toolName) => toolRecord[toolName] ? normalizeToolReplayPolicy(toolRecord[toolName].replayPolicy) : void 0
|
|
306
|
-
});
|
|
307
|
-
const applyCommitBatch = createChatLoopCommitBatchApplier({
|
|
308
|
-
turnEngine,
|
|
309
|
-
sessions,
|
|
310
|
-
middlewareRunner
|
|
311
|
-
});
|
|
312
|
-
yield* applyCommitBatch(
|
|
313
|
-
turnEngine.createInputCommit({
|
|
314
|
-
content: message,
|
|
315
|
-
system: systemOverride
|
|
316
|
-
}),
|
|
317
|
-
{ emitMessages: true }
|
|
318
|
-
);
|
|
319
|
-
setIsStreaming(true);
|
|
320
|
-
const prevOnApplied = interventionCtrl.onApplied;
|
|
321
|
-
let chatUsage;
|
|
322
|
-
let chatError;
|
|
323
|
-
let chatOutput;
|
|
324
|
-
try {
|
|
325
|
-
if (middlewareRunner.hasMiddleware) {
|
|
326
|
-
await middlewareRunner.runChatStart(sessionId, message);
|
|
327
|
-
}
|
|
328
|
-
const systemPrompts = await buildChatSystemPrompts({
|
|
329
|
-
promptBuilder,
|
|
330
|
-
middlewareRunner,
|
|
331
|
-
systemOverride,
|
|
332
|
-
sessionId,
|
|
333
|
-
config,
|
|
334
|
-
tools: toolRecord
|
|
335
|
-
});
|
|
336
|
-
let step = 1;
|
|
337
|
-
let finalStepText = "";
|
|
338
|
-
let accumulatedUsage;
|
|
339
|
-
while (step <= config.maxSteps) {
|
|
340
|
-
const preparedStep = prepareModelStep({
|
|
330
|
+
yield* streamWithinScope(
|
|
331
|
+
{
|
|
332
|
+
kind: "turn",
|
|
333
|
+
name: "agent-turn",
|
|
334
|
+
sessionId: deps.sessionId
|
|
335
|
+
},
|
|
336
|
+
(async function* () {
|
|
337
|
+
const {
|
|
341
338
|
sessionId,
|
|
342
|
-
|
|
343
|
-
systemPrompts,
|
|
344
|
-
messages: sessions.getMessages(),
|
|
345
|
-
toModelMessages,
|
|
339
|
+
message,
|
|
346
340
|
abort,
|
|
341
|
+
systemOverride,
|
|
342
|
+
sessions,
|
|
347
343
|
tools: toolRecord,
|
|
348
|
-
mcpTools,
|
|
349
344
|
config,
|
|
350
|
-
host,
|
|
351
345
|
turnTracker,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
346
|
+
interventionCtrl,
|
|
347
|
+
middlewareRunner,
|
|
348
|
+
contextManager,
|
|
349
|
+
rememberedDoomLoopTools,
|
|
350
|
+
reasoningLevel,
|
|
351
|
+
promptBuilder,
|
|
352
|
+
host,
|
|
353
|
+
mcpTools,
|
|
354
|
+
toModelMessages,
|
|
355
|
+
setIsStreaming
|
|
356
|
+
} = deps;
|
|
357
|
+
const turnEngine = createAgentTurnEngine({
|
|
358
|
+
sessionId,
|
|
359
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
360
|
+
getToolReplayPolicy: (toolName) => toolRecord[toolName] ? normalizeToolReplayPolicy(toolRecord[toolName].replayPolicy) : void 0
|
|
361
361
|
});
|
|
362
|
-
|
|
363
|
-
if (stepResult.error) {
|
|
364
|
-
chatError = stepResult.error;
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
yield* commitStep({
|
|
368
|
-
step,
|
|
369
|
-
finishReason: stepResult.finishReason,
|
|
362
|
+
const applyCommitBatch = createChatLoopCommitBatchApplier({
|
|
370
363
|
turnEngine,
|
|
371
|
-
|
|
364
|
+
sessions,
|
|
365
|
+
middlewareRunner
|
|
372
366
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
367
|
+
yield* applyCommitBatch(
|
|
368
|
+
turnEngine.createInputCommit({
|
|
369
|
+
content: message,
|
|
370
|
+
system: systemOverride
|
|
371
|
+
}),
|
|
372
|
+
{ emitMessages: true }
|
|
373
|
+
);
|
|
374
|
+
setIsStreaming(true);
|
|
375
|
+
const prevOnApplied = interventionCtrl.onApplied;
|
|
376
|
+
let chatUsage;
|
|
377
|
+
let chatError;
|
|
378
|
+
let chatOutput;
|
|
379
|
+
try {
|
|
380
|
+
if (middlewareRunner.hasMiddleware) {
|
|
381
|
+
await middlewareRunner.runChatStart(sessionId, message);
|
|
382
|
+
}
|
|
383
|
+
const systemPrompts = await buildChatSystemPrompts({
|
|
384
|
+
promptBuilder,
|
|
385
|
+
middlewareRunner,
|
|
386
|
+
systemOverride,
|
|
387
|
+
sessionId,
|
|
388
|
+
config,
|
|
389
|
+
tools: toolRecord
|
|
390
|
+
});
|
|
391
|
+
let step = 1;
|
|
392
|
+
let finalStepText = "";
|
|
393
|
+
let accumulatedUsage;
|
|
394
|
+
while (step <= config.maxSteps) {
|
|
395
|
+
const preparedStep = prepareModelStep({
|
|
396
|
+
sessionId,
|
|
397
|
+
step,
|
|
398
|
+
systemPrompts,
|
|
399
|
+
messages: sessions.getMessages(),
|
|
400
|
+
toModelMessages,
|
|
401
|
+
abort,
|
|
402
|
+
tools: toolRecord,
|
|
403
|
+
mcpTools,
|
|
404
|
+
config,
|
|
405
|
+
host,
|
|
406
|
+
turnTracker,
|
|
407
|
+
intervention: interventionCtrl,
|
|
408
|
+
middleware: middlewareRunner,
|
|
409
|
+
reasoningLevel
|
|
410
|
+
});
|
|
411
|
+
const stepResult = yield* runModelStep({
|
|
412
|
+
preparedStep,
|
|
413
|
+
turnEngine,
|
|
414
|
+
applyCommitBatch,
|
|
415
|
+
rememberedDoomLoopTools
|
|
416
|
+
});
|
|
417
|
+
accumulatedUsage = accumulateUsage(accumulatedUsage, stepResult.usage);
|
|
418
|
+
if (stepResult.error) {
|
|
419
|
+
chatError = stepResult.error;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
yield* commitStep({
|
|
423
|
+
step,
|
|
424
|
+
finishReason: stepResult.finishReason,
|
|
425
|
+
turnEngine,
|
|
426
|
+
applyCommitBatch
|
|
427
|
+
});
|
|
428
|
+
if (stepResult.finishReason === "tool-calls") {
|
|
429
|
+
if (step >= config.maxSteps) {
|
|
430
|
+
const maxStepsError = new Error(
|
|
431
|
+
`Maximum steps (${config.maxSteps}) reached before the turn produced a final response`
|
|
432
|
+
);
|
|
433
|
+
chatError = maxStepsError;
|
|
434
|
+
const statusEvent = { type: "status", status: "error" };
|
|
435
|
+
middlewareRunner.emitEvent(statusEvent);
|
|
436
|
+
yield statusEvent;
|
|
437
|
+
const errorEvent = { type: "error", error: maxStepsError };
|
|
438
|
+
middlewareRunner.emitEvent(errorEvent);
|
|
439
|
+
yield errorEvent;
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
step += 1;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
finalStepText = stepResult.text;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
yield* commitOutput({
|
|
449
|
+
text: finalStepText,
|
|
450
|
+
usage: accumulatedUsage,
|
|
451
|
+
turnEngine,
|
|
452
|
+
applyCommitBatch
|
|
453
|
+
});
|
|
454
|
+
if (config.compaction?.auto !== false) {
|
|
455
|
+
const compactionEvents = await runAutoCompaction({
|
|
456
|
+
contextManager,
|
|
457
|
+
messages: sessions.getMessages()
|
|
458
|
+
});
|
|
459
|
+
for (const event of compactionEvents) {
|
|
460
|
+
yield event;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const turnSummary = await turnTracker.endTurn();
|
|
464
|
+
if (turnSummary.totalTracked > 0) {
|
|
465
|
+
yield {
|
|
466
|
+
type: "turn-summary",
|
|
467
|
+
turnId: turnSummary.turnId,
|
|
468
|
+
files: turnSummary.files.map((file) => ({
|
|
469
|
+
path: file.path,
|
|
470
|
+
type: file.type,
|
|
471
|
+
additions: file.additions,
|
|
472
|
+
deletions: file.deletions
|
|
473
|
+
})),
|
|
474
|
+
additions: turnSummary.additions,
|
|
475
|
+
deletions: turnSummary.deletions
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
chatUsage = accumulatedUsage;
|
|
479
|
+
chatOutput = finalStepText || void 0;
|
|
480
|
+
yield {
|
|
481
|
+
type: "complete",
|
|
482
|
+
usage: accumulatedUsage,
|
|
483
|
+
output: finalStepText || void 0
|
|
484
|
+
};
|
|
485
|
+
} catch (error) {
|
|
486
|
+
chatError = error instanceof Error ? error : new Error(String(error));
|
|
487
|
+
throw error;
|
|
488
|
+
} finally {
|
|
489
|
+
setIsStreaming(false);
|
|
490
|
+
interventionCtrl.onApplied = prevOnApplied;
|
|
491
|
+
if (middlewareRunner.hasMiddleware) {
|
|
492
|
+
await middlewareRunner.runChatEnd(sessionId, {
|
|
493
|
+
usage: chatUsage,
|
|
494
|
+
error: chatError,
|
|
495
|
+
output: chatOutput
|
|
496
|
+
});
|
|
386
497
|
}
|
|
387
|
-
step += 1;
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
finalStepText = stepResult.text;
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
yield* commitOutput({
|
|
394
|
-
text: finalStepText,
|
|
395
|
-
usage: accumulatedUsage,
|
|
396
|
-
turnEngine,
|
|
397
|
-
applyCommitBatch
|
|
398
|
-
});
|
|
399
|
-
if (config.compaction?.auto !== false) {
|
|
400
|
-
const compactionEvents = await runAutoCompaction({
|
|
401
|
-
contextManager,
|
|
402
|
-
messages: sessions.getMessages()
|
|
403
|
-
});
|
|
404
|
-
for (const event of compactionEvents) {
|
|
405
|
-
yield event;
|
|
406
498
|
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (turnSummary.totalTracked > 0) {
|
|
410
|
-
yield {
|
|
411
|
-
type: "turn-summary",
|
|
412
|
-
turnId: turnSummary.turnId,
|
|
413
|
-
files: turnSummary.files.map((file) => ({
|
|
414
|
-
path: file.path,
|
|
415
|
-
type: file.type,
|
|
416
|
-
additions: file.additions,
|
|
417
|
-
deletions: file.deletions
|
|
418
|
-
})),
|
|
419
|
-
additions: turnSummary.additions,
|
|
420
|
-
deletions: turnSummary.deletions
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
chatUsage = accumulatedUsage;
|
|
424
|
-
chatOutput = finalStepText || void 0;
|
|
425
|
-
yield { type: "complete", usage: accumulatedUsage };
|
|
426
|
-
} catch (error) {
|
|
427
|
-
chatError = error instanceof Error ? error : new Error(String(error));
|
|
428
|
-
throw error;
|
|
429
|
-
} finally {
|
|
430
|
-
setIsStreaming(false);
|
|
431
|
-
interventionCtrl.onApplied = prevOnApplied;
|
|
432
|
-
if (middlewareRunner.hasMiddleware) {
|
|
433
|
-
await middlewareRunner.runChatEnd(sessionId, {
|
|
434
|
-
usage: chatUsage,
|
|
435
|
-
error: chatError,
|
|
436
|
-
output: chatOutput
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
499
|
+
})()
|
|
500
|
+
);
|
|
440
501
|
}
|
|
441
502
|
|
|
442
503
|
// src/presets/patterns.ts
|
|
@@ -874,7 +935,7 @@ async function createSubAgentRunSession(options) {
|
|
|
874
935
|
return sessionId;
|
|
875
936
|
}
|
|
876
937
|
|
|
877
|
-
// src/intervention
|
|
938
|
+
// src/agent/intervention.ts
|
|
878
939
|
var InterventionController = class {
|
|
879
940
|
/** Immediate interventions — applied at the next step boundary */
|
|
880
941
|
immediate = [];
|
|
@@ -978,400 +1039,6 @@ var InterventionController = class {
|
|
|
978
1039
|
}
|
|
979
1040
|
};
|
|
980
1041
|
|
|
981
|
-
// src/host/local.ts
|
|
982
|
-
import { spawn } from "child_process";
|
|
983
|
-
import fs from "fs/promises";
|
|
984
|
-
import { existsSync } from "fs";
|
|
985
|
-
import path from "path";
|
|
986
|
-
import process2 from "process";
|
|
987
|
-
function getShell() {
|
|
988
|
-
if (process2.platform === "win32") {
|
|
989
|
-
return { shell: "cmd.exe", args: ["/c"] };
|
|
990
|
-
}
|
|
991
|
-
const userShell = process2.env.SHELL ?? "/bin/bash";
|
|
992
|
-
return { shell: userShell, args: ["-c"] };
|
|
993
|
-
}
|
|
994
|
-
async function killProcessTree(pid) {
|
|
995
|
-
try {
|
|
996
|
-
if (process2.platform !== "win32") {
|
|
997
|
-
process2.kill(-pid, "SIGKILL");
|
|
998
|
-
} else {
|
|
999
|
-
const { exec: execCb } = await import("child_process");
|
|
1000
|
-
execCb(`taskkill /pid ${pid} /t /f`, () => {
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
} catch {
|
|
1004
|
-
try {
|
|
1005
|
-
process2.kill(pid, "SIGKILL");
|
|
1006
|
-
} catch {
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
function localHost(defaultCwd) {
|
|
1011
|
-
const cwd = defaultCwd ?? process2.cwd();
|
|
1012
|
-
return {
|
|
1013
|
-
name: "local",
|
|
1014
|
-
// --------------------------------------------------------------------------
|
|
1015
|
-
// File system
|
|
1016
|
-
// --------------------------------------------------------------------------
|
|
1017
|
-
async readFile(filePath) {
|
|
1018
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1019
|
-
return fs.readFile(abs, "utf-8");
|
|
1020
|
-
},
|
|
1021
|
-
async readBytes(filePath, offset, length) {
|
|
1022
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1023
|
-
const fh = await fs.open(abs, "r");
|
|
1024
|
-
try {
|
|
1025
|
-
const buf = Buffer.alloc(length);
|
|
1026
|
-
await fh.read(buf, 0, length, offset);
|
|
1027
|
-
return buf;
|
|
1028
|
-
} finally {
|
|
1029
|
-
await fh.close();
|
|
1030
|
-
}
|
|
1031
|
-
},
|
|
1032
|
-
async writeFile(filePath, content) {
|
|
1033
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1034
|
-
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
1035
|
-
await fs.writeFile(abs, content, "utf-8");
|
|
1036
|
-
},
|
|
1037
|
-
async exists(filePath) {
|
|
1038
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1039
|
-
return existsSync(abs);
|
|
1040
|
-
},
|
|
1041
|
-
async stat(filePath) {
|
|
1042
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1043
|
-
const s = await fs.stat(abs);
|
|
1044
|
-
return {
|
|
1045
|
-
size: s.size,
|
|
1046
|
-
mtime: s.mtime,
|
|
1047
|
-
isDirectory: s.isDirectory(),
|
|
1048
|
-
isFile: s.isFile()
|
|
1049
|
-
};
|
|
1050
|
-
},
|
|
1051
|
-
async readdir(dirPath) {
|
|
1052
|
-
const abs = path.isAbsolute(dirPath) ? dirPath : path.resolve(cwd, dirPath);
|
|
1053
|
-
const entries = await fs.readdir(abs, { withFileTypes: true });
|
|
1054
|
-
return entries.map((e) => ({
|
|
1055
|
-
name: e.name,
|
|
1056
|
-
isDirectory: e.isDirectory(),
|
|
1057
|
-
isFile: e.isFile()
|
|
1058
|
-
}));
|
|
1059
|
-
},
|
|
1060
|
-
async mkdir(dirPath) {
|
|
1061
|
-
const abs = path.isAbsolute(dirPath) ? dirPath : path.resolve(cwd, dirPath);
|
|
1062
|
-
await fs.mkdir(abs, { recursive: true });
|
|
1063
|
-
},
|
|
1064
|
-
// --------------------------------------------------------------------------
|
|
1065
|
-
// Process execution
|
|
1066
|
-
// --------------------------------------------------------------------------
|
|
1067
|
-
exec(command, options) {
|
|
1068
|
-
const { shell, args } = getShell();
|
|
1069
|
-
const execCwd = options?.cwd ?? cwd;
|
|
1070
|
-
const env = {
|
|
1071
|
-
...process2.env,
|
|
1072
|
-
...options?.env,
|
|
1073
|
-
// Disable pagers — tools collect output, not interactive
|
|
1074
|
-
PAGER: "cat",
|
|
1075
|
-
GIT_PAGER: "cat"
|
|
1076
|
-
};
|
|
1077
|
-
return new Promise((resolve, reject) => {
|
|
1078
|
-
let stdout = "";
|
|
1079
|
-
let stderr = "";
|
|
1080
|
-
let timedOut = false;
|
|
1081
|
-
let settled = false;
|
|
1082
|
-
const child = spawn(shell, [...args, command], {
|
|
1083
|
-
cwd: execCwd,
|
|
1084
|
-
detached: process2.platform !== "win32",
|
|
1085
|
-
env,
|
|
1086
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1087
|
-
});
|
|
1088
|
-
child.stdout?.on("data", (data) => {
|
|
1089
|
-
stdout += data.toString();
|
|
1090
|
-
options?.onStdout?.(data);
|
|
1091
|
-
});
|
|
1092
|
-
child.stderr?.on("data", (data) => {
|
|
1093
|
-
stderr += data.toString();
|
|
1094
|
-
options?.onStderr?.(data);
|
|
1095
|
-
});
|
|
1096
|
-
let timer;
|
|
1097
|
-
if (options?.timeout && options.timeout > 0) {
|
|
1098
|
-
timer = setTimeout(() => {
|
|
1099
|
-
timedOut = true;
|
|
1100
|
-
if (child.pid) killProcessTree(child.pid);
|
|
1101
|
-
}, options.timeout);
|
|
1102
|
-
}
|
|
1103
|
-
const onAbort = () => {
|
|
1104
|
-
if (child.pid) killProcessTree(child.pid);
|
|
1105
|
-
};
|
|
1106
|
-
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1107
|
-
child.on("close", (code2) => {
|
|
1108
|
-
if (settled) return;
|
|
1109
|
-
settled = true;
|
|
1110
|
-
if (timer) clearTimeout(timer);
|
|
1111
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
1112
|
-
resolve({ stdout, stderr, exitCode: code2, timedOut });
|
|
1113
|
-
});
|
|
1114
|
-
child.on("error", (err) => {
|
|
1115
|
-
if (settled) return;
|
|
1116
|
-
settled = true;
|
|
1117
|
-
if (timer) clearTimeout(timer);
|
|
1118
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
1119
|
-
reject(err);
|
|
1120
|
-
});
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
// src/host/docker/exec.ts
|
|
1127
|
-
async function loadDockerode() {
|
|
1128
|
-
try {
|
|
1129
|
-
const module = await import("dockerode");
|
|
1130
|
-
return module.default ?? module;
|
|
1131
|
-
} catch {
|
|
1132
|
-
throw new Error(
|
|
1133
|
-
"dockerHost requires the 'dockerode' package. Install it with: npm install dockerode"
|
|
1134
|
-
);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
async function resolveDockerRuntime(options) {
|
|
1138
|
-
const Dockerode = await loadDockerode();
|
|
1139
|
-
if (typeof options.container === "string") {
|
|
1140
|
-
const docker = new Dockerode(options.dockerOptions);
|
|
1141
|
-
const container2 = docker.getContainer(options.container);
|
|
1142
|
-
return {
|
|
1143
|
-
docker,
|
|
1144
|
-
container: container2,
|
|
1145
|
-
label: options.container
|
|
1146
|
-
};
|
|
1147
|
-
}
|
|
1148
|
-
const container = options.container;
|
|
1149
|
-
return {
|
|
1150
|
-
docker: { modem: container.modem },
|
|
1151
|
-
container,
|
|
1152
|
-
label: container.id?.slice(0, 12) ?? "unknown"
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
async function containerExec(runtime, command, options = {}) {
|
|
1156
|
-
const envEntries = options.env ? Object.entries(options.env).filter((entry) => entry[1] !== void 0).map(([key, value]) => `${key}=${value}`) : void 0;
|
|
1157
|
-
const exec = await runtime.container.exec({
|
|
1158
|
-
Cmd: ["sh", "-c", command],
|
|
1159
|
-
...options.user ? { User: options.user } : {},
|
|
1160
|
-
...options.workdir ? { WorkingDir: options.workdir } : {},
|
|
1161
|
-
...envEntries && envEntries.length > 0 ? { Env: envEntries } : {},
|
|
1162
|
-
AttachStdout: true,
|
|
1163
|
-
AttachStderr: true
|
|
1164
|
-
});
|
|
1165
|
-
const stream = await exec.start({});
|
|
1166
|
-
let timedOut = false;
|
|
1167
|
-
let aborted = false;
|
|
1168
|
-
return await new Promise((resolve, reject) => {
|
|
1169
|
-
const stdoutChunks = [];
|
|
1170
|
-
const stderrChunks = [];
|
|
1171
|
-
runtime.docker.modem.demuxStream(
|
|
1172
|
-
stream,
|
|
1173
|
-
{
|
|
1174
|
-
write: (chunk) => {
|
|
1175
|
-
stdoutChunks.push(chunk);
|
|
1176
|
-
options.onStdout?.(chunk);
|
|
1177
|
-
return true;
|
|
1178
|
-
},
|
|
1179
|
-
end: function() {
|
|
1180
|
-
return this;
|
|
1181
|
-
}
|
|
1182
|
-
},
|
|
1183
|
-
{
|
|
1184
|
-
write: (chunk) => {
|
|
1185
|
-
stderrChunks.push(chunk);
|
|
1186
|
-
options.onStderr?.(chunk);
|
|
1187
|
-
return true;
|
|
1188
|
-
},
|
|
1189
|
-
end: function() {
|
|
1190
|
-
return this;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
);
|
|
1194
|
-
let timer;
|
|
1195
|
-
if (options.timeout && options.timeout > 0) {
|
|
1196
|
-
timer = setTimeout(() => {
|
|
1197
|
-
timedOut = true;
|
|
1198
|
-
stream.destroy?.();
|
|
1199
|
-
}, options.timeout);
|
|
1200
|
-
}
|
|
1201
|
-
const onAbort = () => {
|
|
1202
|
-
aborted = true;
|
|
1203
|
-
stream.destroy?.();
|
|
1204
|
-
};
|
|
1205
|
-
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1206
|
-
stream.on("end", async () => {
|
|
1207
|
-
if (timer) {
|
|
1208
|
-
clearTimeout(timer);
|
|
1209
|
-
}
|
|
1210
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
1211
|
-
try {
|
|
1212
|
-
const info = await exec.inspect();
|
|
1213
|
-
resolve({
|
|
1214
|
-
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
1215
|
-
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
1216
|
-
exitCode: timedOut || aborted ? null : info.ExitCode ?? 0,
|
|
1217
|
-
timedOut
|
|
1218
|
-
});
|
|
1219
|
-
} catch (error) {
|
|
1220
|
-
reject(error);
|
|
1221
|
-
}
|
|
1222
|
-
});
|
|
1223
|
-
stream.on("error", (error) => {
|
|
1224
|
-
if (timer) {
|
|
1225
|
-
clearTimeout(timer);
|
|
1226
|
-
}
|
|
1227
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
1228
|
-
if (timedOut || aborted) {
|
|
1229
|
-
resolve({
|
|
1230
|
-
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
1231
|
-
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
1232
|
-
exitCode: null,
|
|
1233
|
-
timedOut
|
|
1234
|
-
});
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
reject(error);
|
|
1238
|
-
});
|
|
1239
|
-
});
|
|
1240
|
-
}
|
|
1241
|
-
async function runDockerCommand(options) {
|
|
1242
|
-
const { runtime, command, defaultUser, defaultWorkdir, execOptions } = options;
|
|
1243
|
-
return await containerExec(runtime, command, {
|
|
1244
|
-
user: defaultUser,
|
|
1245
|
-
workdir: execOptions?.workdir ?? execOptions?.cwd ?? defaultWorkdir,
|
|
1246
|
-
env: execOptions?.env,
|
|
1247
|
-
timeout: execOptions?.timeout,
|
|
1248
|
-
signal: execOptions?.signal,
|
|
1249
|
-
onStdout: execOptions?.onStdout,
|
|
1250
|
-
onStderr: execOptions?.onStderr
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
// src/host/docker/shell.ts
|
|
1255
|
-
function sq(value) {
|
|
1256
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1257
|
-
}
|
|
1258
|
-
function resolveDockerPath(path2, defaultWorkdir) {
|
|
1259
|
-
if (path2.startsWith("/")) {
|
|
1260
|
-
return path2;
|
|
1261
|
-
}
|
|
1262
|
-
const base = defaultWorkdir.endsWith("/") ? defaultWorkdir : `${defaultWorkdir}/`;
|
|
1263
|
-
return `${base}${path2}`;
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
// src/host/docker/host.ts
|
|
1267
|
-
async function dockerHost(options) {
|
|
1268
|
-
const runtime = await resolveDockerRuntime(options);
|
|
1269
|
-
const defaultUser = options.user;
|
|
1270
|
-
const defaultWorkdir = options.workdir ?? "/";
|
|
1271
|
-
async function run(command, execOptions) {
|
|
1272
|
-
return await runDockerCommand({
|
|
1273
|
-
runtime,
|
|
1274
|
-
command,
|
|
1275
|
-
defaultUser,
|
|
1276
|
-
defaultWorkdir,
|
|
1277
|
-
execOptions
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
return {
|
|
1281
|
-
name: `docker:${runtime.label}`,
|
|
1282
|
-
async readFile(filePath) {
|
|
1283
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1284
|
-
const result = await run(`cat ${sq(absPath)}`);
|
|
1285
|
-
if (result.exitCode !== 0) {
|
|
1286
|
-
throw new Error(`readFile failed (${absPath}): ${result.stderr.trim()}`);
|
|
1287
|
-
}
|
|
1288
|
-
return result.stdout;
|
|
1289
|
-
},
|
|
1290
|
-
async readBytes(filePath, offset, length) {
|
|
1291
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1292
|
-
const result = await run(
|
|
1293
|
-
`dd if=${sq(absPath)} bs=1 skip=${offset} count=${length} 2>/dev/null`
|
|
1294
|
-
);
|
|
1295
|
-
if (result.exitCode !== 0) {
|
|
1296
|
-
throw new Error(
|
|
1297
|
-
`readBytes failed (${absPath}): ${result.stderr.trim()}`
|
|
1298
|
-
);
|
|
1299
|
-
}
|
|
1300
|
-
return Buffer.from(result.stdout, "binary");
|
|
1301
|
-
},
|
|
1302
|
-
async writeFile(filePath, content) {
|
|
1303
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1304
|
-
const dir = absPath.substring(0, absPath.lastIndexOf("/")) || "/";
|
|
1305
|
-
await run(`mkdir -p ${sq(dir)}`);
|
|
1306
|
-
const encoded = Buffer.from(content, "utf-8").toString("base64");
|
|
1307
|
-
const result = await run(`echo ${sq(encoded)} | base64 -d > ${sq(absPath)}`);
|
|
1308
|
-
if (result.exitCode !== 0) {
|
|
1309
|
-
throw new Error(
|
|
1310
|
-
`writeFile failed (${absPath}): ${result.stderr.trim()}`
|
|
1311
|
-
);
|
|
1312
|
-
}
|
|
1313
|
-
},
|
|
1314
|
-
async exists(filePath) {
|
|
1315
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1316
|
-
const result = await run(`test -e ${sq(absPath)}`);
|
|
1317
|
-
return result.exitCode === 0;
|
|
1318
|
-
},
|
|
1319
|
-
async stat(filePath) {
|
|
1320
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1321
|
-
const result = await run(
|
|
1322
|
-
`stat -c '%s %Y %F' ${sq(absPath)} 2>/dev/null || stat -f '%z %m %HT' ${sq(absPath)}`
|
|
1323
|
-
);
|
|
1324
|
-
if (result.exitCode !== 0) {
|
|
1325
|
-
throw new Error(`stat failed (${absPath}): ${result.stderr.trim()}`);
|
|
1326
|
-
}
|
|
1327
|
-
const parts = result.stdout.trim().split(/\s+/);
|
|
1328
|
-
if (parts.length < 3) {
|
|
1329
|
-
throw new Error(
|
|
1330
|
-
`stat: unexpected output format for ${absPath}: ${result.stdout}`
|
|
1331
|
-
);
|
|
1332
|
-
}
|
|
1333
|
-
const size = parseInt(parts[0], 10);
|
|
1334
|
-
const mtimeSec = parseInt(parts[1], 10);
|
|
1335
|
-
const typeStr = parts.slice(2).join(" ").toLowerCase();
|
|
1336
|
-
return {
|
|
1337
|
-
size,
|
|
1338
|
-
mtime: new Date(mtimeSec * 1e3),
|
|
1339
|
-
isDirectory: typeStr.includes("directory"),
|
|
1340
|
-
isFile: typeStr.includes("regular") || typeStr.includes("file")
|
|
1341
|
-
};
|
|
1342
|
-
},
|
|
1343
|
-
async readdir(dirPath) {
|
|
1344
|
-
const absPath = resolveDockerPath(dirPath, defaultWorkdir);
|
|
1345
|
-
const result = await run(
|
|
1346
|
-
`find ${sq(absPath)} -maxdepth 1 -mindepth 1 -printf '%f\\t%y\\n' 2>/dev/null || for f in ${sq(absPath)}/*; do [ -e "$f" ] || continue; n=$(basename "$f"); if [ -d "$f" ]; then printf '%s\\td\\n' "$n"; else printf '%s\\tf\\n' "$n"; fi; done`
|
|
1347
|
-
);
|
|
1348
|
-
if (result.exitCode !== 0) {
|
|
1349
|
-
throw new Error(
|
|
1350
|
-
`readdir failed (${absPath}): ${result.stderr.trim()}`
|
|
1351
|
-
);
|
|
1352
|
-
}
|
|
1353
|
-
return result.stdout.trim().split("\n").filter(Boolean).map((line) => {
|
|
1354
|
-
const [name, type] = line.split(" ");
|
|
1355
|
-
return {
|
|
1356
|
-
name,
|
|
1357
|
-
isDirectory: type === "d",
|
|
1358
|
-
isFile: type === "f"
|
|
1359
|
-
};
|
|
1360
|
-
});
|
|
1361
|
-
},
|
|
1362
|
-
async mkdir(dirPath) {
|
|
1363
|
-
const absPath = resolveDockerPath(dirPath, defaultWorkdir);
|
|
1364
|
-
const result = await run(`mkdir -p ${sq(absPath)}`);
|
|
1365
|
-
if (result.exitCode !== 0) {
|
|
1366
|
-
throw new Error(`mkdir failed (${absPath}): ${result.stderr.trim()}`);
|
|
1367
|
-
}
|
|
1368
|
-
},
|
|
1369
|
-
async exec(command, execOptions) {
|
|
1370
|
-
return await run(command, execOptions);
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
1042
|
// src/agent/model-detection.ts
|
|
1376
1043
|
var DEFAULT_CUSTOM_STREAM_MODELS = [
|
|
1377
1044
|
"computer-use-preview",
|
|
@@ -1819,6 +1486,7 @@ var Agent = class _Agent {
|
|
|
1819
1486
|
break;
|
|
1820
1487
|
case "complete":
|
|
1821
1488
|
if (event.usage) usage = event.usage;
|
|
1489
|
+
if (event.output !== void 0) response = event.output;
|
|
1822
1490
|
break;
|
|
1823
1491
|
case "error":
|
|
1824
1492
|
throw event.error;
|
|
@@ -2365,6 +2033,8 @@ export {
|
|
|
2365
2033
|
AgentTurnEngine,
|
|
2366
2034
|
ApprovalDeniedError,
|
|
2367
2035
|
ApprovalTimeoutError,
|
|
2036
|
+
CacheCapabilitySource,
|
|
2037
|
+
CapabilityCache,
|
|
2368
2038
|
ContextManager,
|
|
2369
2039
|
ContextOverflowError,
|
|
2370
2040
|
DEFAULT_CONTEXT_LIMITS,
|
|
@@ -2373,13 +2043,21 @@ export {
|
|
|
2373
2043
|
DEFAULT_MAX_CONCURRENT,
|
|
2374
2044
|
DEFAULT_MAX_DEPTH,
|
|
2375
2045
|
DEFAULT_MAX_FILE_SIZE,
|
|
2046
|
+
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
2376
2047
|
DEFAULT_MAX_SCAN_DEPTH,
|
|
2377
2048
|
DEFAULT_MAX_SPAWN_DEPTH,
|
|
2049
|
+
DEFAULT_MAX_STEPS,
|
|
2050
|
+
DEFAULT_MAX_TOKENS,
|
|
2051
|
+
DEFAULT_RESOLVER_OPTIONS,
|
|
2378
2052
|
DEFAULT_RETRY_CONFIG,
|
|
2379
2053
|
DEFAULT_SESSION_TITLE_PREFIX,
|
|
2380
2054
|
DEFAULT_SKILL_MAX_SIZE,
|
|
2055
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
2381
2056
|
DoomLoopError,
|
|
2057
|
+
EXTENDED_LEVELS,
|
|
2058
|
+
FIXED_LEVELS,
|
|
2382
2059
|
FileStorage,
|
|
2060
|
+
Inference,
|
|
2383
2061
|
InterventionController,
|
|
2384
2062
|
LLM,
|
|
2385
2063
|
LLMError,
|
|
@@ -2395,12 +2073,18 @@ export {
|
|
|
2395
2073
|
PRIORITY_INSTRUCTIONS,
|
|
2396
2074
|
PRIORITY_OVERRIDE,
|
|
2397
2075
|
PRIORITY_SKILLS,
|
|
2076
|
+
PRUNE_PROTECTED_TOOLS,
|
|
2077
|
+
PatternCapabilitySource,
|
|
2398
2078
|
Presets,
|
|
2399
2079
|
PromptBuilder,
|
|
2080
|
+
RemoteCapabilityFetcher,
|
|
2081
|
+
RemoteCapabilitySource,
|
|
2400
2082
|
SKILL_FILENAME,
|
|
2083
|
+
STANDARD_LEVELS,
|
|
2401
2084
|
STORAGE_VERSION,
|
|
2402
2085
|
SessionManager,
|
|
2403
2086
|
SkillRegistry,
|
|
2087
|
+
SourcePriority,
|
|
2404
2088
|
SubAgentTracker,
|
|
2405
2089
|
TRUNCATE_DIR,
|
|
2406
2090
|
TRUNCATE_GLOB,
|
|
@@ -2412,14 +2096,27 @@ export {
|
|
|
2412
2096
|
applyAgentWorkflowModelStepResult,
|
|
2413
2097
|
applyAgentWorkflowToolBatchResult,
|
|
2414
2098
|
applyAgentWorkflowToolCallResult,
|
|
2099
|
+
applyCapabilityOverride,
|
|
2415
2100
|
applyPreset,
|
|
2416
2101
|
approvalMiddleware,
|
|
2102
|
+
autoDetectStreamProvider,
|
|
2103
|
+
buildAnthropicOptions,
|
|
2104
|
+
buildBedrockOptions,
|
|
2105
|
+
buildEntryPath,
|
|
2106
|
+
buildGoogleOptions,
|
|
2107
|
+
buildGroqOptions,
|
|
2417
2108
|
buildMessagesFromEntries,
|
|
2109
|
+
buildOpenAIOptions,
|
|
2110
|
+
buildOpenRouterOptions,
|
|
2418
2111
|
buildReasoningOptions,
|
|
2419
2112
|
buildReasoningOptionsSync,
|
|
2113
|
+
buildToolSet,
|
|
2114
|
+
buildXAIOptions,
|
|
2420
2115
|
calculateDelay,
|
|
2116
|
+
careful,
|
|
2421
2117
|
clearCheckpoints,
|
|
2422
2118
|
cloneAgentWorkflowTurnState,
|
|
2119
|
+
code,
|
|
2423
2120
|
commitOutput,
|
|
2424
2121
|
commitStep,
|
|
2425
2122
|
configureDefaultSessionManager,
|
|
@@ -2434,6 +2131,8 @@ export {
|
|
|
2434
2131
|
createApprovalHandler,
|
|
2435
2132
|
createCheckpointManager,
|
|
2436
2133
|
createMCPManager,
|
|
2134
|
+
createMessageEntry,
|
|
2135
|
+
createMetadataEntry,
|
|
2437
2136
|
createPreset,
|
|
2438
2137
|
createPromptBuilder,
|
|
2439
2138
|
createResolver,
|
|
@@ -2460,10 +2159,15 @@ export {
|
|
|
2460
2159
|
estimateMessageTokens,
|
|
2461
2160
|
estimateTokens,
|
|
2462
2161
|
executeAgentToolCall,
|
|
2162
|
+
explore,
|
|
2463
2163
|
extractFilePathsFromArgs,
|
|
2164
|
+
extractModelId,
|
|
2165
|
+
extractProvider,
|
|
2166
|
+
extractSessionInfo,
|
|
2464
2167
|
failAgentTurnState,
|
|
2465
2168
|
failAgentWorkflowTurnState,
|
|
2466
2169
|
filterTools,
|
|
2170
|
+
findCapabilityOverride,
|
|
2467
2171
|
findCutPoint,
|
|
2468
2172
|
formatEnvironment,
|
|
2469
2173
|
formatInstructions,
|
|
@@ -2476,45 +2180,61 @@ export {
|
|
|
2476
2180
|
getDefaultResolver,
|
|
2477
2181
|
getDefaultSessionManager,
|
|
2478
2182
|
getErrorCategory,
|
|
2183
|
+
getGitRootHash,
|
|
2479
2184
|
getLeafId,
|
|
2480
2185
|
getModelId,
|
|
2481
2186
|
getNetworkStatus,
|
|
2187
|
+
getProjectId,
|
|
2482
2188
|
getProjectSessionsDir,
|
|
2189
|
+
getProviderCompatibility,
|
|
2483
2190
|
getProviderId,
|
|
2191
|
+
getProviderOptionsKey,
|
|
2484
2192
|
getReasoningConfig,
|
|
2485
2193
|
getReasoningConfigSync,
|
|
2486
2194
|
getRetryDelay,
|
|
2487
2195
|
getSessionsDir,
|
|
2488
2196
|
getTemplate,
|
|
2489
2197
|
getToolRisk,
|
|
2198
|
+
hasStreamProviderFactory,
|
|
2490
2199
|
httpServer,
|
|
2200
|
+
inferProvider,
|
|
2491
2201
|
inferResourceType,
|
|
2492
2202
|
isContextOverflowing,
|
|
2493
2203
|
isRetryable,
|
|
2494
2204
|
isRetryableCategory,
|
|
2205
|
+
likelySupportsReasoning,
|
|
2495
2206
|
loadGlobalInstructions,
|
|
2496
2207
|
loadResourceContent,
|
|
2497
2208
|
loadSkillContent,
|
|
2498
2209
|
loadSkillMetadata,
|
|
2499
2210
|
localHost,
|
|
2500
2211
|
mergePresets,
|
|
2212
|
+
needsCustomStreamProvider,
|
|
2501
2213
|
normalizeToolReplayPolicy,
|
|
2502
2214
|
otelMiddleware,
|
|
2503
2215
|
parseFrontmatter,
|
|
2504
2216
|
parseJSONL,
|
|
2217
|
+
parseRetryDelay,
|
|
2218
|
+
plan,
|
|
2505
2219
|
planNextAgentWorkflowOperation,
|
|
2506
2220
|
prepareModelStep,
|
|
2221
|
+
processStepStream,
|
|
2507
2222
|
processStream,
|
|
2223
|
+
promptCacheMiddleware,
|
|
2508
2224
|
pruneContext,
|
|
2509
2225
|
pruneToolResults,
|
|
2226
|
+
quick,
|
|
2510
2227
|
recordAgentWorkflowReplayDecision,
|
|
2511
2228
|
restoreAgentWorkflowMessage,
|
|
2512
2229
|
restoreAgentWorkflowMessages,
|
|
2230
|
+
review,
|
|
2231
|
+
runChatLoop,
|
|
2513
2232
|
runConcurrent,
|
|
2514
2233
|
runModelStep,
|
|
2515
2234
|
runToolBatch,
|
|
2516
2235
|
serializeMessage,
|
|
2517
2236
|
shouldCaptureBaseline,
|
|
2237
|
+
shouldIncludeReasoningSummary,
|
|
2518
2238
|
shouldPruneContext,
|
|
2519
2239
|
shouldRetry,
|
|
2520
2240
|
sleep,
|
|
@@ -2522,11 +2242,16 @@ export {
|
|
|
2522
2242
|
snapshotAgentWorkflowMessages,
|
|
2523
2243
|
sseServer,
|
|
2524
2244
|
stdioServer,
|
|
2245
|
+
stream,
|
|
2246
|
+
streamOnce,
|
|
2247
|
+
streamStep,
|
|
2525
2248
|
summarizeEnvironment,
|
|
2526
2249
|
supportsReasoning,
|
|
2527
2250
|
supportsReasoningSync,
|
|
2528
2251
|
toJSONL,
|
|
2252
|
+
toJSONLBatch,
|
|
2529
2253
|
truncateOutput,
|
|
2254
|
+
watch,
|
|
2530
2255
|
withFileTracking,
|
|
2531
2256
|
withRetry
|
|
2532
2257
|
};
|