@cuylabs/agent-core 0.6.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 +5 -1
- package/dist/{builder-BKkipazh.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-3C4VKG4P.js → chunk-3HNO5SVI.js} +273 -807
- package/dist/chunk-5K7AQVOU.js +619 -0
- package/dist/{chunk-QAQADS4X.js → chunk-BNSHUWCV.js} +1 -0
- package/dist/{chunk-O2ZCFQL6.js → chunk-CDTV2UYU.js} +86 -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-DZQJD_hp.d.ts → index-C33hlD6H.d.ts} +12 -7
- package/dist/{index-ipP3_ztp.d.ts → index-CfBGYrpd.d.ts} +121 -2
- package/dist/index.d.ts +107 -126
- package/dist/index.js +321 -601
- package/dist/inference/index.d.ts +59 -0
- package/dist/inference/index.js +25 -0
- package/dist/middleware/index.d.ts +7 -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 +9 -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-G1wxEgac.d.ts → runner-DSKaEz3z.d.ts} +35 -8
- 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 +7 -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-BWo810L_.d.ts +0 -648
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-3C4VKG4P.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,168 +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 {
|
|
426
|
-
type: "complete",
|
|
427
|
-
usage: accumulatedUsage,
|
|
428
|
-
output: finalStepText || void 0
|
|
429
|
-
};
|
|
430
|
-
} catch (error) {
|
|
431
|
-
chatError = error instanceof Error ? error : new Error(String(error));
|
|
432
|
-
throw error;
|
|
433
|
-
} finally {
|
|
434
|
-
setIsStreaming(false);
|
|
435
|
-
interventionCtrl.onApplied = prevOnApplied;
|
|
436
|
-
if (middlewareRunner.hasMiddleware) {
|
|
437
|
-
await middlewareRunner.runChatEnd(sessionId, {
|
|
438
|
-
usage: chatUsage,
|
|
439
|
-
error: chatError,
|
|
440
|
-
output: chatOutput
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
499
|
+
})()
|
|
500
|
+
);
|
|
444
501
|
}
|
|
445
502
|
|
|
446
503
|
// src/presets/patterns.ts
|
|
@@ -878,7 +935,7 @@ async function createSubAgentRunSession(options) {
|
|
|
878
935
|
return sessionId;
|
|
879
936
|
}
|
|
880
937
|
|
|
881
|
-
// src/intervention
|
|
938
|
+
// src/agent/intervention.ts
|
|
882
939
|
var InterventionController = class {
|
|
883
940
|
/** Immediate interventions — applied at the next step boundary */
|
|
884
941
|
immediate = [];
|
|
@@ -982,400 +1039,6 @@ var InterventionController = class {
|
|
|
982
1039
|
}
|
|
983
1040
|
};
|
|
984
1041
|
|
|
985
|
-
// src/host/local.ts
|
|
986
|
-
import { spawn } from "child_process";
|
|
987
|
-
import fs from "fs/promises";
|
|
988
|
-
import { existsSync } from "fs";
|
|
989
|
-
import path from "path";
|
|
990
|
-
import process2 from "process";
|
|
991
|
-
function getShell() {
|
|
992
|
-
if (process2.platform === "win32") {
|
|
993
|
-
return { shell: "cmd.exe", args: ["/c"] };
|
|
994
|
-
}
|
|
995
|
-
const userShell = process2.env.SHELL ?? "/bin/bash";
|
|
996
|
-
return { shell: userShell, args: ["-c"] };
|
|
997
|
-
}
|
|
998
|
-
async function killProcessTree(pid) {
|
|
999
|
-
try {
|
|
1000
|
-
if (process2.platform !== "win32") {
|
|
1001
|
-
process2.kill(-pid, "SIGKILL");
|
|
1002
|
-
} else {
|
|
1003
|
-
const { exec: execCb } = await import("child_process");
|
|
1004
|
-
execCb(`taskkill /pid ${pid} /t /f`, () => {
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
} catch {
|
|
1008
|
-
try {
|
|
1009
|
-
process2.kill(pid, "SIGKILL");
|
|
1010
|
-
} catch {
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
function localHost(defaultCwd) {
|
|
1015
|
-
const cwd = defaultCwd ?? process2.cwd();
|
|
1016
|
-
return {
|
|
1017
|
-
name: "local",
|
|
1018
|
-
// --------------------------------------------------------------------------
|
|
1019
|
-
// File system
|
|
1020
|
-
// --------------------------------------------------------------------------
|
|
1021
|
-
async readFile(filePath) {
|
|
1022
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1023
|
-
return fs.readFile(abs, "utf-8");
|
|
1024
|
-
},
|
|
1025
|
-
async readBytes(filePath, offset, length) {
|
|
1026
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1027
|
-
const fh = await fs.open(abs, "r");
|
|
1028
|
-
try {
|
|
1029
|
-
const buf = Buffer.alloc(length);
|
|
1030
|
-
await fh.read(buf, 0, length, offset);
|
|
1031
|
-
return buf;
|
|
1032
|
-
} finally {
|
|
1033
|
-
await fh.close();
|
|
1034
|
-
}
|
|
1035
|
-
},
|
|
1036
|
-
async writeFile(filePath, content) {
|
|
1037
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1038
|
-
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
1039
|
-
await fs.writeFile(abs, content, "utf-8");
|
|
1040
|
-
},
|
|
1041
|
-
async exists(filePath) {
|
|
1042
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1043
|
-
return existsSync(abs);
|
|
1044
|
-
},
|
|
1045
|
-
async stat(filePath) {
|
|
1046
|
-
const abs = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
1047
|
-
const s = await fs.stat(abs);
|
|
1048
|
-
return {
|
|
1049
|
-
size: s.size,
|
|
1050
|
-
mtime: s.mtime,
|
|
1051
|
-
isDirectory: s.isDirectory(),
|
|
1052
|
-
isFile: s.isFile()
|
|
1053
|
-
};
|
|
1054
|
-
},
|
|
1055
|
-
async readdir(dirPath) {
|
|
1056
|
-
const abs = path.isAbsolute(dirPath) ? dirPath : path.resolve(cwd, dirPath);
|
|
1057
|
-
const entries = await fs.readdir(abs, { withFileTypes: true });
|
|
1058
|
-
return entries.map((e) => ({
|
|
1059
|
-
name: e.name,
|
|
1060
|
-
isDirectory: e.isDirectory(),
|
|
1061
|
-
isFile: e.isFile()
|
|
1062
|
-
}));
|
|
1063
|
-
},
|
|
1064
|
-
async mkdir(dirPath) {
|
|
1065
|
-
const abs = path.isAbsolute(dirPath) ? dirPath : path.resolve(cwd, dirPath);
|
|
1066
|
-
await fs.mkdir(abs, { recursive: true });
|
|
1067
|
-
},
|
|
1068
|
-
// --------------------------------------------------------------------------
|
|
1069
|
-
// Process execution
|
|
1070
|
-
// --------------------------------------------------------------------------
|
|
1071
|
-
exec(command, options) {
|
|
1072
|
-
const { shell, args } = getShell();
|
|
1073
|
-
const execCwd = options?.cwd ?? cwd;
|
|
1074
|
-
const env = {
|
|
1075
|
-
...process2.env,
|
|
1076
|
-
...options?.env,
|
|
1077
|
-
// Disable pagers — tools collect output, not interactive
|
|
1078
|
-
PAGER: "cat",
|
|
1079
|
-
GIT_PAGER: "cat"
|
|
1080
|
-
};
|
|
1081
|
-
return new Promise((resolve, reject) => {
|
|
1082
|
-
let stdout = "";
|
|
1083
|
-
let stderr = "";
|
|
1084
|
-
let timedOut = false;
|
|
1085
|
-
let settled = false;
|
|
1086
|
-
const child = spawn(shell, [...args, command], {
|
|
1087
|
-
cwd: execCwd,
|
|
1088
|
-
detached: process2.platform !== "win32",
|
|
1089
|
-
env,
|
|
1090
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1091
|
-
});
|
|
1092
|
-
child.stdout?.on("data", (data) => {
|
|
1093
|
-
stdout += data.toString();
|
|
1094
|
-
options?.onStdout?.(data);
|
|
1095
|
-
});
|
|
1096
|
-
child.stderr?.on("data", (data) => {
|
|
1097
|
-
stderr += data.toString();
|
|
1098
|
-
options?.onStderr?.(data);
|
|
1099
|
-
});
|
|
1100
|
-
let timer;
|
|
1101
|
-
if (options?.timeout && options.timeout > 0) {
|
|
1102
|
-
timer = setTimeout(() => {
|
|
1103
|
-
timedOut = true;
|
|
1104
|
-
if (child.pid) killProcessTree(child.pid);
|
|
1105
|
-
}, options.timeout);
|
|
1106
|
-
}
|
|
1107
|
-
const onAbort = () => {
|
|
1108
|
-
if (child.pid) killProcessTree(child.pid);
|
|
1109
|
-
};
|
|
1110
|
-
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1111
|
-
child.on("close", (code2) => {
|
|
1112
|
-
if (settled) return;
|
|
1113
|
-
settled = true;
|
|
1114
|
-
if (timer) clearTimeout(timer);
|
|
1115
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
1116
|
-
resolve({ stdout, stderr, exitCode: code2, timedOut });
|
|
1117
|
-
});
|
|
1118
|
-
child.on("error", (err) => {
|
|
1119
|
-
if (settled) return;
|
|
1120
|
-
settled = true;
|
|
1121
|
-
if (timer) clearTimeout(timer);
|
|
1122
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
1123
|
-
reject(err);
|
|
1124
|
-
});
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
// src/host/docker/exec.ts
|
|
1131
|
-
async function loadDockerode() {
|
|
1132
|
-
try {
|
|
1133
|
-
const module = await import("dockerode");
|
|
1134
|
-
return module.default ?? module;
|
|
1135
|
-
} catch {
|
|
1136
|
-
throw new Error(
|
|
1137
|
-
"dockerHost requires the 'dockerode' package. Install it with: npm install dockerode"
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
async function resolveDockerRuntime(options) {
|
|
1142
|
-
const Dockerode = await loadDockerode();
|
|
1143
|
-
if (typeof options.container === "string") {
|
|
1144
|
-
const docker = new Dockerode(options.dockerOptions);
|
|
1145
|
-
const container2 = docker.getContainer(options.container);
|
|
1146
|
-
return {
|
|
1147
|
-
docker,
|
|
1148
|
-
container: container2,
|
|
1149
|
-
label: options.container
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
const container = options.container;
|
|
1153
|
-
return {
|
|
1154
|
-
docker: { modem: container.modem },
|
|
1155
|
-
container,
|
|
1156
|
-
label: container.id?.slice(0, 12) ?? "unknown"
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
async function containerExec(runtime, command, options = {}) {
|
|
1160
|
-
const envEntries = options.env ? Object.entries(options.env).filter((entry) => entry[1] !== void 0).map(([key, value]) => `${key}=${value}`) : void 0;
|
|
1161
|
-
const exec = await runtime.container.exec({
|
|
1162
|
-
Cmd: ["sh", "-c", command],
|
|
1163
|
-
...options.user ? { User: options.user } : {},
|
|
1164
|
-
...options.workdir ? { WorkingDir: options.workdir } : {},
|
|
1165
|
-
...envEntries && envEntries.length > 0 ? { Env: envEntries } : {},
|
|
1166
|
-
AttachStdout: true,
|
|
1167
|
-
AttachStderr: true
|
|
1168
|
-
});
|
|
1169
|
-
const stream = await exec.start({});
|
|
1170
|
-
let timedOut = false;
|
|
1171
|
-
let aborted = false;
|
|
1172
|
-
return await new Promise((resolve, reject) => {
|
|
1173
|
-
const stdoutChunks = [];
|
|
1174
|
-
const stderrChunks = [];
|
|
1175
|
-
runtime.docker.modem.demuxStream(
|
|
1176
|
-
stream,
|
|
1177
|
-
{
|
|
1178
|
-
write: (chunk) => {
|
|
1179
|
-
stdoutChunks.push(chunk);
|
|
1180
|
-
options.onStdout?.(chunk);
|
|
1181
|
-
return true;
|
|
1182
|
-
},
|
|
1183
|
-
end: function() {
|
|
1184
|
-
return this;
|
|
1185
|
-
}
|
|
1186
|
-
},
|
|
1187
|
-
{
|
|
1188
|
-
write: (chunk) => {
|
|
1189
|
-
stderrChunks.push(chunk);
|
|
1190
|
-
options.onStderr?.(chunk);
|
|
1191
|
-
return true;
|
|
1192
|
-
},
|
|
1193
|
-
end: function() {
|
|
1194
|
-
return this;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
);
|
|
1198
|
-
let timer;
|
|
1199
|
-
if (options.timeout && options.timeout > 0) {
|
|
1200
|
-
timer = setTimeout(() => {
|
|
1201
|
-
timedOut = true;
|
|
1202
|
-
stream.destroy?.();
|
|
1203
|
-
}, options.timeout);
|
|
1204
|
-
}
|
|
1205
|
-
const onAbort = () => {
|
|
1206
|
-
aborted = true;
|
|
1207
|
-
stream.destroy?.();
|
|
1208
|
-
};
|
|
1209
|
-
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1210
|
-
stream.on("end", async () => {
|
|
1211
|
-
if (timer) {
|
|
1212
|
-
clearTimeout(timer);
|
|
1213
|
-
}
|
|
1214
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
1215
|
-
try {
|
|
1216
|
-
const info = await exec.inspect();
|
|
1217
|
-
resolve({
|
|
1218
|
-
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
1219
|
-
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
1220
|
-
exitCode: timedOut || aborted ? null : info.ExitCode ?? 0,
|
|
1221
|
-
timedOut
|
|
1222
|
-
});
|
|
1223
|
-
} catch (error) {
|
|
1224
|
-
reject(error);
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
stream.on("error", (error) => {
|
|
1228
|
-
if (timer) {
|
|
1229
|
-
clearTimeout(timer);
|
|
1230
|
-
}
|
|
1231
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
1232
|
-
if (timedOut || aborted) {
|
|
1233
|
-
resolve({
|
|
1234
|
-
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
1235
|
-
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
1236
|
-
exitCode: null,
|
|
1237
|
-
timedOut
|
|
1238
|
-
});
|
|
1239
|
-
return;
|
|
1240
|
-
}
|
|
1241
|
-
reject(error);
|
|
1242
|
-
});
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
async function runDockerCommand(options) {
|
|
1246
|
-
const { runtime, command, defaultUser, defaultWorkdir, execOptions } = options;
|
|
1247
|
-
return await containerExec(runtime, command, {
|
|
1248
|
-
user: defaultUser,
|
|
1249
|
-
workdir: execOptions?.workdir ?? execOptions?.cwd ?? defaultWorkdir,
|
|
1250
|
-
env: execOptions?.env,
|
|
1251
|
-
timeout: execOptions?.timeout,
|
|
1252
|
-
signal: execOptions?.signal,
|
|
1253
|
-
onStdout: execOptions?.onStdout,
|
|
1254
|
-
onStderr: execOptions?.onStderr
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
// src/host/docker/shell.ts
|
|
1259
|
-
function sq(value) {
|
|
1260
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1261
|
-
}
|
|
1262
|
-
function resolveDockerPath(path2, defaultWorkdir) {
|
|
1263
|
-
if (path2.startsWith("/")) {
|
|
1264
|
-
return path2;
|
|
1265
|
-
}
|
|
1266
|
-
const base = defaultWorkdir.endsWith("/") ? defaultWorkdir : `${defaultWorkdir}/`;
|
|
1267
|
-
return `${base}${path2}`;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
// src/host/docker/host.ts
|
|
1271
|
-
async function dockerHost(options) {
|
|
1272
|
-
const runtime = await resolveDockerRuntime(options);
|
|
1273
|
-
const defaultUser = options.user;
|
|
1274
|
-
const defaultWorkdir = options.workdir ?? "/";
|
|
1275
|
-
async function run(command, execOptions) {
|
|
1276
|
-
return await runDockerCommand({
|
|
1277
|
-
runtime,
|
|
1278
|
-
command,
|
|
1279
|
-
defaultUser,
|
|
1280
|
-
defaultWorkdir,
|
|
1281
|
-
execOptions
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
return {
|
|
1285
|
-
name: `docker:${runtime.label}`,
|
|
1286
|
-
async readFile(filePath) {
|
|
1287
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1288
|
-
const result = await run(`cat ${sq(absPath)}`);
|
|
1289
|
-
if (result.exitCode !== 0) {
|
|
1290
|
-
throw new Error(`readFile failed (${absPath}): ${result.stderr.trim()}`);
|
|
1291
|
-
}
|
|
1292
|
-
return result.stdout;
|
|
1293
|
-
},
|
|
1294
|
-
async readBytes(filePath, offset, length) {
|
|
1295
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1296
|
-
const result = await run(
|
|
1297
|
-
`dd if=${sq(absPath)} bs=1 skip=${offset} count=${length} 2>/dev/null`
|
|
1298
|
-
);
|
|
1299
|
-
if (result.exitCode !== 0) {
|
|
1300
|
-
throw new Error(
|
|
1301
|
-
`readBytes failed (${absPath}): ${result.stderr.trim()}`
|
|
1302
|
-
);
|
|
1303
|
-
}
|
|
1304
|
-
return Buffer.from(result.stdout, "binary");
|
|
1305
|
-
},
|
|
1306
|
-
async writeFile(filePath, content) {
|
|
1307
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1308
|
-
const dir = absPath.substring(0, absPath.lastIndexOf("/")) || "/";
|
|
1309
|
-
await run(`mkdir -p ${sq(dir)}`);
|
|
1310
|
-
const encoded = Buffer.from(content, "utf-8").toString("base64");
|
|
1311
|
-
const result = await run(`echo ${sq(encoded)} | base64 -d > ${sq(absPath)}`);
|
|
1312
|
-
if (result.exitCode !== 0) {
|
|
1313
|
-
throw new Error(
|
|
1314
|
-
`writeFile failed (${absPath}): ${result.stderr.trim()}`
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
},
|
|
1318
|
-
async exists(filePath) {
|
|
1319
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1320
|
-
const result = await run(`test -e ${sq(absPath)}`);
|
|
1321
|
-
return result.exitCode === 0;
|
|
1322
|
-
},
|
|
1323
|
-
async stat(filePath) {
|
|
1324
|
-
const absPath = resolveDockerPath(filePath, defaultWorkdir);
|
|
1325
|
-
const result = await run(
|
|
1326
|
-
`stat -c '%s %Y %F' ${sq(absPath)} 2>/dev/null || stat -f '%z %m %HT' ${sq(absPath)}`
|
|
1327
|
-
);
|
|
1328
|
-
if (result.exitCode !== 0) {
|
|
1329
|
-
throw new Error(`stat failed (${absPath}): ${result.stderr.trim()}`);
|
|
1330
|
-
}
|
|
1331
|
-
const parts = result.stdout.trim().split(/\s+/);
|
|
1332
|
-
if (parts.length < 3) {
|
|
1333
|
-
throw new Error(
|
|
1334
|
-
`stat: unexpected output format for ${absPath}: ${result.stdout}`
|
|
1335
|
-
);
|
|
1336
|
-
}
|
|
1337
|
-
const size = parseInt(parts[0], 10);
|
|
1338
|
-
const mtimeSec = parseInt(parts[1], 10);
|
|
1339
|
-
const typeStr = parts.slice(2).join(" ").toLowerCase();
|
|
1340
|
-
return {
|
|
1341
|
-
size,
|
|
1342
|
-
mtime: new Date(mtimeSec * 1e3),
|
|
1343
|
-
isDirectory: typeStr.includes("directory"),
|
|
1344
|
-
isFile: typeStr.includes("regular") || typeStr.includes("file")
|
|
1345
|
-
};
|
|
1346
|
-
},
|
|
1347
|
-
async readdir(dirPath) {
|
|
1348
|
-
const absPath = resolveDockerPath(dirPath, defaultWorkdir);
|
|
1349
|
-
const result = await run(
|
|
1350
|
-
`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`
|
|
1351
|
-
);
|
|
1352
|
-
if (result.exitCode !== 0) {
|
|
1353
|
-
throw new Error(
|
|
1354
|
-
`readdir failed (${absPath}): ${result.stderr.trim()}`
|
|
1355
|
-
);
|
|
1356
|
-
}
|
|
1357
|
-
return result.stdout.trim().split("\n").filter(Boolean).map((line) => {
|
|
1358
|
-
const [name, type] = line.split(" ");
|
|
1359
|
-
return {
|
|
1360
|
-
name,
|
|
1361
|
-
isDirectory: type === "d",
|
|
1362
|
-
isFile: type === "f"
|
|
1363
|
-
};
|
|
1364
|
-
});
|
|
1365
|
-
},
|
|
1366
|
-
async mkdir(dirPath) {
|
|
1367
|
-
const absPath = resolveDockerPath(dirPath, defaultWorkdir);
|
|
1368
|
-
const result = await run(`mkdir -p ${sq(absPath)}`);
|
|
1369
|
-
if (result.exitCode !== 0) {
|
|
1370
|
-
throw new Error(`mkdir failed (${absPath}): ${result.stderr.trim()}`);
|
|
1371
|
-
}
|
|
1372
|
-
},
|
|
1373
|
-
async exec(command, execOptions) {
|
|
1374
|
-
return await run(command, execOptions);
|
|
1375
|
-
}
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
1042
|
// src/agent/model-detection.ts
|
|
1380
1043
|
var DEFAULT_CUSTOM_STREAM_MODELS = [
|
|
1381
1044
|
"computer-use-preview",
|
|
@@ -2370,6 +2033,8 @@ export {
|
|
|
2370
2033
|
AgentTurnEngine,
|
|
2371
2034
|
ApprovalDeniedError,
|
|
2372
2035
|
ApprovalTimeoutError,
|
|
2036
|
+
CacheCapabilitySource,
|
|
2037
|
+
CapabilityCache,
|
|
2373
2038
|
ContextManager,
|
|
2374
2039
|
ContextOverflowError,
|
|
2375
2040
|
DEFAULT_CONTEXT_LIMITS,
|
|
@@ -2378,13 +2043,21 @@ export {
|
|
|
2378
2043
|
DEFAULT_MAX_CONCURRENT,
|
|
2379
2044
|
DEFAULT_MAX_DEPTH,
|
|
2380
2045
|
DEFAULT_MAX_FILE_SIZE,
|
|
2046
|
+
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
2381
2047
|
DEFAULT_MAX_SCAN_DEPTH,
|
|
2382
2048
|
DEFAULT_MAX_SPAWN_DEPTH,
|
|
2049
|
+
DEFAULT_MAX_STEPS,
|
|
2050
|
+
DEFAULT_MAX_TOKENS,
|
|
2051
|
+
DEFAULT_RESOLVER_OPTIONS,
|
|
2383
2052
|
DEFAULT_RETRY_CONFIG,
|
|
2384
2053
|
DEFAULT_SESSION_TITLE_PREFIX,
|
|
2385
2054
|
DEFAULT_SKILL_MAX_SIZE,
|
|
2055
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
2386
2056
|
DoomLoopError,
|
|
2057
|
+
EXTENDED_LEVELS,
|
|
2058
|
+
FIXED_LEVELS,
|
|
2387
2059
|
FileStorage,
|
|
2060
|
+
Inference,
|
|
2388
2061
|
InterventionController,
|
|
2389
2062
|
LLM,
|
|
2390
2063
|
LLMError,
|
|
@@ -2400,12 +2073,18 @@ export {
|
|
|
2400
2073
|
PRIORITY_INSTRUCTIONS,
|
|
2401
2074
|
PRIORITY_OVERRIDE,
|
|
2402
2075
|
PRIORITY_SKILLS,
|
|
2076
|
+
PRUNE_PROTECTED_TOOLS,
|
|
2077
|
+
PatternCapabilitySource,
|
|
2403
2078
|
Presets,
|
|
2404
2079
|
PromptBuilder,
|
|
2080
|
+
RemoteCapabilityFetcher,
|
|
2081
|
+
RemoteCapabilitySource,
|
|
2405
2082
|
SKILL_FILENAME,
|
|
2083
|
+
STANDARD_LEVELS,
|
|
2406
2084
|
STORAGE_VERSION,
|
|
2407
2085
|
SessionManager,
|
|
2408
2086
|
SkillRegistry,
|
|
2087
|
+
SourcePriority,
|
|
2409
2088
|
SubAgentTracker,
|
|
2410
2089
|
TRUNCATE_DIR,
|
|
2411
2090
|
TRUNCATE_GLOB,
|
|
@@ -2417,14 +2096,27 @@ export {
|
|
|
2417
2096
|
applyAgentWorkflowModelStepResult,
|
|
2418
2097
|
applyAgentWorkflowToolBatchResult,
|
|
2419
2098
|
applyAgentWorkflowToolCallResult,
|
|
2099
|
+
applyCapabilityOverride,
|
|
2420
2100
|
applyPreset,
|
|
2421
2101
|
approvalMiddleware,
|
|
2102
|
+
autoDetectStreamProvider,
|
|
2103
|
+
buildAnthropicOptions,
|
|
2104
|
+
buildBedrockOptions,
|
|
2105
|
+
buildEntryPath,
|
|
2106
|
+
buildGoogleOptions,
|
|
2107
|
+
buildGroqOptions,
|
|
2422
2108
|
buildMessagesFromEntries,
|
|
2109
|
+
buildOpenAIOptions,
|
|
2110
|
+
buildOpenRouterOptions,
|
|
2423
2111
|
buildReasoningOptions,
|
|
2424
2112
|
buildReasoningOptionsSync,
|
|
2113
|
+
buildToolSet,
|
|
2114
|
+
buildXAIOptions,
|
|
2425
2115
|
calculateDelay,
|
|
2116
|
+
careful,
|
|
2426
2117
|
clearCheckpoints,
|
|
2427
2118
|
cloneAgentWorkflowTurnState,
|
|
2119
|
+
code,
|
|
2428
2120
|
commitOutput,
|
|
2429
2121
|
commitStep,
|
|
2430
2122
|
configureDefaultSessionManager,
|
|
@@ -2439,6 +2131,8 @@ export {
|
|
|
2439
2131
|
createApprovalHandler,
|
|
2440
2132
|
createCheckpointManager,
|
|
2441
2133
|
createMCPManager,
|
|
2134
|
+
createMessageEntry,
|
|
2135
|
+
createMetadataEntry,
|
|
2442
2136
|
createPreset,
|
|
2443
2137
|
createPromptBuilder,
|
|
2444
2138
|
createResolver,
|
|
@@ -2465,10 +2159,15 @@ export {
|
|
|
2465
2159
|
estimateMessageTokens,
|
|
2466
2160
|
estimateTokens,
|
|
2467
2161
|
executeAgentToolCall,
|
|
2162
|
+
explore,
|
|
2468
2163
|
extractFilePathsFromArgs,
|
|
2164
|
+
extractModelId,
|
|
2165
|
+
extractProvider,
|
|
2166
|
+
extractSessionInfo,
|
|
2469
2167
|
failAgentTurnState,
|
|
2470
2168
|
failAgentWorkflowTurnState,
|
|
2471
2169
|
filterTools,
|
|
2170
|
+
findCapabilityOverride,
|
|
2472
2171
|
findCutPoint,
|
|
2473
2172
|
formatEnvironment,
|
|
2474
2173
|
formatInstructions,
|
|
@@ -2481,45 +2180,61 @@ export {
|
|
|
2481
2180
|
getDefaultResolver,
|
|
2482
2181
|
getDefaultSessionManager,
|
|
2483
2182
|
getErrorCategory,
|
|
2183
|
+
getGitRootHash,
|
|
2484
2184
|
getLeafId,
|
|
2485
2185
|
getModelId,
|
|
2486
2186
|
getNetworkStatus,
|
|
2187
|
+
getProjectId,
|
|
2487
2188
|
getProjectSessionsDir,
|
|
2189
|
+
getProviderCompatibility,
|
|
2488
2190
|
getProviderId,
|
|
2191
|
+
getProviderOptionsKey,
|
|
2489
2192
|
getReasoningConfig,
|
|
2490
2193
|
getReasoningConfigSync,
|
|
2491
2194
|
getRetryDelay,
|
|
2492
2195
|
getSessionsDir,
|
|
2493
2196
|
getTemplate,
|
|
2494
2197
|
getToolRisk,
|
|
2198
|
+
hasStreamProviderFactory,
|
|
2495
2199
|
httpServer,
|
|
2200
|
+
inferProvider,
|
|
2496
2201
|
inferResourceType,
|
|
2497
2202
|
isContextOverflowing,
|
|
2498
2203
|
isRetryable,
|
|
2499
2204
|
isRetryableCategory,
|
|
2205
|
+
likelySupportsReasoning,
|
|
2500
2206
|
loadGlobalInstructions,
|
|
2501
2207
|
loadResourceContent,
|
|
2502
2208
|
loadSkillContent,
|
|
2503
2209
|
loadSkillMetadata,
|
|
2504
2210
|
localHost,
|
|
2505
2211
|
mergePresets,
|
|
2212
|
+
needsCustomStreamProvider,
|
|
2506
2213
|
normalizeToolReplayPolicy,
|
|
2507
2214
|
otelMiddleware,
|
|
2508
2215
|
parseFrontmatter,
|
|
2509
2216
|
parseJSONL,
|
|
2217
|
+
parseRetryDelay,
|
|
2218
|
+
plan,
|
|
2510
2219
|
planNextAgentWorkflowOperation,
|
|
2511
2220
|
prepareModelStep,
|
|
2221
|
+
processStepStream,
|
|
2512
2222
|
processStream,
|
|
2223
|
+
promptCacheMiddleware,
|
|
2513
2224
|
pruneContext,
|
|
2514
2225
|
pruneToolResults,
|
|
2226
|
+
quick,
|
|
2515
2227
|
recordAgentWorkflowReplayDecision,
|
|
2516
2228
|
restoreAgentWorkflowMessage,
|
|
2517
2229
|
restoreAgentWorkflowMessages,
|
|
2230
|
+
review,
|
|
2231
|
+
runChatLoop,
|
|
2518
2232
|
runConcurrent,
|
|
2519
2233
|
runModelStep,
|
|
2520
2234
|
runToolBatch,
|
|
2521
2235
|
serializeMessage,
|
|
2522
2236
|
shouldCaptureBaseline,
|
|
2237
|
+
shouldIncludeReasoningSummary,
|
|
2523
2238
|
shouldPruneContext,
|
|
2524
2239
|
shouldRetry,
|
|
2525
2240
|
sleep,
|
|
@@ -2527,11 +2242,16 @@ export {
|
|
|
2527
2242
|
snapshotAgentWorkflowMessages,
|
|
2528
2243
|
sseServer,
|
|
2529
2244
|
stdioServer,
|
|
2245
|
+
stream,
|
|
2246
|
+
streamOnce,
|
|
2247
|
+
streamStep,
|
|
2530
2248
|
summarizeEnvironment,
|
|
2531
2249
|
supportsReasoning,
|
|
2532
2250
|
supportsReasoningSync,
|
|
2533
2251
|
toJSONL,
|
|
2252
|
+
toJSONLBatch,
|
|
2534
2253
|
truncateOutput,
|
|
2254
|
+
watch,
|
|
2535
2255
|
withFileTracking,
|
|
2536
2256
|
withRetry
|
|
2537
2257
|
};
|