@cuylabs/agent-core 0.7.0 → 0.8.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/dist/{builder-BRvqCcIk.d.ts → builder-UpOWQMW3.d.ts} +2 -2
- package/dist/{chunk-3HNO5SVI.js → chunk-4BDA7DQY.js} +3 -3
- package/dist/chunk-BFM2YHNM.js +222 -0
- package/dist/chunk-CAA7FHIH.js +280 -0
- package/dist/chunk-DWYX7ASF.js +26 -0
- package/dist/chunk-KUVSERLJ.js +50 -0
- package/dist/{chunk-5K7AQVOU.js → chunk-N6HWIEEA.js} +8 -204
- package/dist/{chunk-QGOGIP7T.js → chunk-RFEKJKTO.js} +131 -25
- package/dist/chunk-RZITT45F.js +202 -0
- package/dist/{chunk-ZPMACVZK.js → chunk-SQU2AJHO.js} +1 -1
- package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
- package/dist/{chunk-CDTV2UYU.js → chunk-YSLSEQ6B.js} +52 -252
- package/dist/context/index.js +1 -1
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +16 -0
- package/dist/events-CE72w8W4.d.ts +149 -0
- package/dist/{index-C33hlD6H.d.ts → index-CWSchSql.d.ts} +36 -50
- package/dist/index.d.ts +36 -109
- package/dist/index.js +213 -396
- package/dist/inference/index.d.ts +10 -7
- package/dist/inference/index.js +7 -5
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +245 -7
- package/dist/middleware/index.js +3 -1
- package/dist/models/index.d.ts +125 -4
- package/dist/models/index.js +7 -3
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +28 -0
- package/dist/prompt/index.d.ts +10 -8
- package/dist/reasoning/index.d.ts +1 -2
- package/dist/reasoning/index.js +3 -7
- package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/{runner-DSKaEz3z.d.ts → runner-e2YRcUoX.d.ts} +58 -151
- package/dist/runtime/index.d.ts +11 -8
- package/dist/runtime/index.js +9 -7
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +2 -2
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +7 -6
- package/dist/sub-agent/index.d.ts +14 -9
- package/dist/tool/index.d.ts +7 -5
- package/dist/tool/index.js +2 -2
- package/dist/tool-BHbyUAy3.d.ts +150 -0
- package/dist/{tool-HUtkiVBx.d.ts → tool-DLXAR9Ce.d.ts} +1 -1
- package/dist/tracking/index.d.ts +2 -2
- package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/types-BnpEOYV-.d.ts +50 -0
- package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/{types-FRpzzg_9.d.ts → types-KKDrdU9Y.d.ts} +5 -35
- package/dist/{capability-resolver-CgRGsWVX.d.ts → types-QA4WhEfz.d.ts} +1 -117
- package/dist/{types-CqDZTh4d.d.ts → types-QKHHQLLq.d.ts} +5 -4
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +58 -3
- package/dist/index-CfBGYrpd.d.ts +0 -317
- package/dist/{chunk-IEFIQENH.js → chunk-7VKQ4WPB.js} +4 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FileStorage,
|
|
3
|
+
MemoryStorage,
|
|
4
|
+
STORAGE_VERSION,
|
|
5
|
+
SessionManager,
|
|
6
|
+
buildEntryPath,
|
|
7
|
+
buildMessagesFromEntries,
|
|
8
|
+
configureDefaultSessionManager,
|
|
9
|
+
createMessageEntry,
|
|
10
|
+
createMetadataEntry,
|
|
11
|
+
deserializeMessage,
|
|
12
|
+
extractSessionInfo,
|
|
13
|
+
generateEntryId,
|
|
14
|
+
getDataDir,
|
|
15
|
+
getDefaultSessionManager,
|
|
16
|
+
getGitRootHash,
|
|
17
|
+
getLeafId,
|
|
18
|
+
getProjectId,
|
|
19
|
+
getProjectSessionsDir,
|
|
20
|
+
getSessionsDir,
|
|
21
|
+
parseJSONL,
|
|
22
|
+
serializeMessage,
|
|
23
|
+
toJSONL,
|
|
24
|
+
toJSONLBatch
|
|
25
|
+
} from "./chunk-BDBZ3SLK.js";
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_MAX_CONCURRENT,
|
|
28
|
+
DEFAULT_MAX_SPAWN_DEPTH,
|
|
29
|
+
DEFAULT_SESSION_TITLE_PREFIX,
|
|
30
|
+
SubAgentTracker,
|
|
31
|
+
createSubAgentTools
|
|
32
|
+
} from "./chunk-7MUFEN4K.js";
|
|
33
|
+
import {
|
|
34
|
+
ToolRegistry,
|
|
35
|
+
defaultRegistry
|
|
36
|
+
} from "./chunk-SDSBEQXG.js";
|
|
37
|
+
import {
|
|
38
|
+
TurnChangeTracker,
|
|
39
|
+
clearCheckpoints,
|
|
40
|
+
createCheckpointManager,
|
|
41
|
+
createTurnTracker
|
|
42
|
+
} from "./chunk-VBWWUHWI.js";
|
|
43
|
+
import {
|
|
44
|
+
Presets,
|
|
45
|
+
applyPreset,
|
|
46
|
+
careful,
|
|
47
|
+
code,
|
|
48
|
+
createPreset,
|
|
49
|
+
explore,
|
|
50
|
+
filterTools,
|
|
51
|
+
mergePresets,
|
|
52
|
+
plan,
|
|
53
|
+
quick,
|
|
54
|
+
review,
|
|
55
|
+
watch
|
|
56
|
+
} from "./chunk-CAA7FHIH.js";
|
|
57
|
+
import {
|
|
58
|
+
DEFAULT_INSTRUCTION_PATTERNS,
|
|
59
|
+
DEFAULT_MAX_DEPTH,
|
|
60
|
+
DEFAULT_MAX_FILE_SIZE,
|
|
61
|
+
PRIORITY_BASE,
|
|
62
|
+
PRIORITY_CUSTOM,
|
|
63
|
+
PRIORITY_ENVIRONMENT,
|
|
64
|
+
PRIORITY_INSTRUCTIONS,
|
|
65
|
+
PRIORITY_OVERRIDE,
|
|
66
|
+
PRIORITY_SKILLS,
|
|
67
|
+
PromptBuilder,
|
|
68
|
+
createPromptBuilder,
|
|
69
|
+
detectModelFamily,
|
|
70
|
+
discoverInstructions,
|
|
71
|
+
formatEnvironment,
|
|
72
|
+
formatInstructions,
|
|
73
|
+
gatherEnvironment,
|
|
74
|
+
getAvailableFamilies,
|
|
75
|
+
getTemplate,
|
|
76
|
+
loadGlobalInstructions,
|
|
77
|
+
summarizeEnvironment
|
|
78
|
+
} from "./chunk-IVUJDISU.js";
|
|
1
79
|
import {
|
|
2
80
|
AgentTurnEngine,
|
|
3
81
|
ContextOverflowError,
|
|
@@ -30,48 +108,15 @@ import {
|
|
|
30
108
|
runToolBatch,
|
|
31
109
|
snapshotAgentWorkflowMessage,
|
|
32
110
|
snapshotAgentWorkflowMessages
|
|
33
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-4BDA7DQY.js";
|
|
112
|
+
import {
|
|
113
|
+
LocalSignal
|
|
114
|
+
} from "./chunk-KUVSERLJ.js";
|
|
34
115
|
import {
|
|
35
116
|
createSkillResourceTool,
|
|
36
117
|
createSkillTool,
|
|
37
118
|
createSkillTools
|
|
38
119
|
} from "./chunk-YUUJK53A.js";
|
|
39
|
-
import {
|
|
40
|
-
FileStorage,
|
|
41
|
-
MemoryStorage,
|
|
42
|
-
STORAGE_VERSION,
|
|
43
|
-
SessionManager,
|
|
44
|
-
buildEntryPath,
|
|
45
|
-
buildMessagesFromEntries,
|
|
46
|
-
configureDefaultSessionManager,
|
|
47
|
-
createMessageEntry,
|
|
48
|
-
createMetadataEntry,
|
|
49
|
-
deserializeMessage,
|
|
50
|
-
extractSessionInfo,
|
|
51
|
-
generateEntryId,
|
|
52
|
-
getDataDir,
|
|
53
|
-
getDefaultSessionManager,
|
|
54
|
-
getGitRootHash,
|
|
55
|
-
getLeafId,
|
|
56
|
-
getProjectId,
|
|
57
|
-
getProjectSessionsDir,
|
|
58
|
-
getSessionsDir,
|
|
59
|
-
parseJSONL,
|
|
60
|
-
serializeMessage,
|
|
61
|
-
toJSONL,
|
|
62
|
-
toJSONLBatch
|
|
63
|
-
} from "./chunk-BDBZ3SLK.js";
|
|
64
|
-
import {
|
|
65
|
-
DEFAULT_MAX_CONCURRENT,
|
|
66
|
-
DEFAULT_MAX_SPAWN_DEPTH,
|
|
67
|
-
DEFAULT_SESSION_TITLE_PREFIX,
|
|
68
|
-
SubAgentTracker,
|
|
69
|
-
createSubAgentTools
|
|
70
|
-
} from "./chunk-7MUFEN4K.js";
|
|
71
|
-
import {
|
|
72
|
-
ToolRegistry,
|
|
73
|
-
defaultRegistry
|
|
74
|
-
} from "./chunk-SDSBEQXG.js";
|
|
75
120
|
import {
|
|
76
121
|
MAX_BYTES,
|
|
77
122
|
MAX_LINES,
|
|
@@ -84,11 +129,20 @@ import {
|
|
|
84
129
|
truncateOutput
|
|
85
130
|
} from "./chunk-P6YF7USR.js";
|
|
86
131
|
import {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
132
|
+
DEFAULT_EXTERNAL_DIRS,
|
|
133
|
+
DEFAULT_MAX_SCAN_DEPTH,
|
|
134
|
+
DEFAULT_SKILL_MAX_SIZE,
|
|
135
|
+
SKILL_FILENAME,
|
|
136
|
+
SkillRegistry,
|
|
137
|
+
createSkillRegistry,
|
|
138
|
+
discoverSkills,
|
|
139
|
+
emptySkillRegistry,
|
|
140
|
+
inferResourceType,
|
|
141
|
+
loadResourceContent,
|
|
142
|
+
loadSkillContent,
|
|
143
|
+
loadSkillMetadata,
|
|
144
|
+
parseFrontmatter
|
|
145
|
+
} from "./chunk-LRHOS4ZN.js";
|
|
92
146
|
import {
|
|
93
147
|
ContextManager,
|
|
94
148
|
DEFAULT_CONTEXT_LIMITS,
|
|
@@ -102,7 +156,7 @@ import {
|
|
|
102
156
|
pruneContext,
|
|
103
157
|
pruneToolResults,
|
|
104
158
|
shouldPruneContext
|
|
105
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-WWYYNWEW.js";
|
|
106
160
|
import {
|
|
107
161
|
dockerHost,
|
|
108
162
|
localHost
|
|
@@ -112,24 +166,26 @@ import {
|
|
|
112
166
|
DEFAULT_RETRY_CONFIG,
|
|
113
167
|
Inference,
|
|
114
168
|
LLM,
|
|
115
|
-
LLMError,
|
|
116
169
|
OUTPUT_TOKEN_MAX,
|
|
117
170
|
buildToolSet,
|
|
118
171
|
calculateDelay,
|
|
119
172
|
createRetryHandler,
|
|
120
173
|
createRetryState,
|
|
121
|
-
getErrorCategory,
|
|
122
|
-
getRetryDelay,
|
|
123
|
-
isRetryable,
|
|
124
|
-
isRetryableCategory,
|
|
125
|
-
parseRetryDelay,
|
|
126
174
|
shouldRetry,
|
|
127
175
|
sleep,
|
|
128
176
|
stream,
|
|
129
177
|
streamOnce,
|
|
130
178
|
streamStep,
|
|
131
179
|
withRetry
|
|
132
|
-
} from "./chunk-
|
|
180
|
+
} from "./chunk-N6HWIEEA.js";
|
|
181
|
+
import {
|
|
182
|
+
executeAgentToolCall
|
|
183
|
+
} from "./chunk-7VKQ4WPB.js";
|
|
184
|
+
import {
|
|
185
|
+
extractFilePathsFromArgs,
|
|
186
|
+
shouldCaptureBaseline,
|
|
187
|
+
withFileTracking
|
|
188
|
+
} from "./chunk-VEKUXUVF.js";
|
|
133
189
|
import {
|
|
134
190
|
EXTENDED_LEVELS,
|
|
135
191
|
FIXED_LEVELS,
|
|
@@ -149,29 +205,43 @@ import {
|
|
|
149
205
|
shouldIncludeReasoningSummary,
|
|
150
206
|
supportsReasoning,
|
|
151
207
|
supportsReasoningSync
|
|
152
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-SQU2AJHO.js";
|
|
153
209
|
import {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
210
|
+
createScope,
|
|
211
|
+
currentScope,
|
|
212
|
+
restoreScope,
|
|
213
|
+
snapshotScope,
|
|
214
|
+
streamWithinScope,
|
|
215
|
+
withinScope
|
|
158
216
|
} from "./chunk-N7P4PN3O.js";
|
|
159
217
|
import {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
218
|
+
LLMError,
|
|
219
|
+
getErrorCategory,
|
|
220
|
+
getRetryDelay,
|
|
221
|
+
isRetryable,
|
|
222
|
+
isRetryableCategory,
|
|
223
|
+
parseRetryDelay
|
|
224
|
+
} from "./chunk-RZITT45F.js";
|
|
225
|
+
import {
|
|
226
|
+
createMCPManager,
|
|
227
|
+
defineServer,
|
|
228
|
+
httpServer,
|
|
229
|
+
sseServer,
|
|
230
|
+
stdioServer
|
|
231
|
+
} from "./chunk-ZXAKHMWH.js";
|
|
164
232
|
import {
|
|
165
|
-
ApprovalDeniedError,
|
|
166
|
-
ApprovalTimeoutError,
|
|
167
233
|
MiddlewareRunner,
|
|
168
234
|
approvalMiddleware,
|
|
169
|
-
createApprovalHandler,
|
|
170
235
|
createTelemetryConfig,
|
|
171
|
-
getToolRisk,
|
|
172
236
|
otelMiddleware,
|
|
173
237
|
promptCacheMiddleware
|
|
174
|
-
} from "./chunk-
|
|
238
|
+
} from "./chunk-YSLSEQ6B.js";
|
|
239
|
+
import {
|
|
240
|
+
ApprovalDeniedError,
|
|
241
|
+
ApprovalTimeoutError,
|
|
242
|
+
createApprovalHandler,
|
|
243
|
+
getToolRisk
|
|
244
|
+
} from "./chunk-BFM2YHNM.js";
|
|
175
245
|
import {
|
|
176
246
|
CacheCapabilitySource,
|
|
177
247
|
CapabilityCache,
|
|
@@ -188,57 +258,16 @@ import {
|
|
|
188
258
|
extractProvider,
|
|
189
259
|
findCapabilityOverride,
|
|
190
260
|
getDefaultResolver,
|
|
191
|
-
getModelId,
|
|
192
261
|
getNetworkStatus,
|
|
193
262
|
getProviderCompatibility,
|
|
194
|
-
|
|
263
|
+
inferContextWindow,
|
|
195
264
|
inferProvider,
|
|
196
265
|
likelySupportsReasoning
|
|
197
|
-
} from "./chunk-
|
|
266
|
+
} from "./chunk-RFEKJKTO.js";
|
|
198
267
|
import {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
sseServer,
|
|
203
|
-
stdioServer
|
|
204
|
-
} from "./chunk-ZXAKHMWH.js";
|
|
205
|
-
import {
|
|
206
|
-
DEFAULT_INSTRUCTION_PATTERNS,
|
|
207
|
-
DEFAULT_MAX_DEPTH,
|
|
208
|
-
DEFAULT_MAX_FILE_SIZE,
|
|
209
|
-
PRIORITY_BASE,
|
|
210
|
-
PRIORITY_CUSTOM,
|
|
211
|
-
PRIORITY_ENVIRONMENT,
|
|
212
|
-
PRIORITY_INSTRUCTIONS,
|
|
213
|
-
PRIORITY_OVERRIDE,
|
|
214
|
-
PRIORITY_SKILLS,
|
|
215
|
-
PromptBuilder,
|
|
216
|
-
createPromptBuilder,
|
|
217
|
-
detectModelFamily,
|
|
218
|
-
discoverInstructions,
|
|
219
|
-
formatEnvironment,
|
|
220
|
-
formatInstructions,
|
|
221
|
-
gatherEnvironment,
|
|
222
|
-
getAvailableFamilies,
|
|
223
|
-
getTemplate,
|
|
224
|
-
loadGlobalInstructions,
|
|
225
|
-
summarizeEnvironment
|
|
226
|
-
} from "./chunk-IVUJDISU.js";
|
|
227
|
-
import {
|
|
228
|
-
DEFAULT_EXTERNAL_DIRS,
|
|
229
|
-
DEFAULT_MAX_SCAN_DEPTH,
|
|
230
|
-
DEFAULT_SKILL_MAX_SIZE,
|
|
231
|
-
SKILL_FILENAME,
|
|
232
|
-
SkillRegistry,
|
|
233
|
-
createSkillRegistry,
|
|
234
|
-
discoverSkills,
|
|
235
|
-
emptySkillRegistry,
|
|
236
|
-
inferResourceType,
|
|
237
|
-
loadResourceContent,
|
|
238
|
-
loadSkillContent,
|
|
239
|
-
loadSkillMetadata,
|
|
240
|
-
parseFrontmatter
|
|
241
|
-
} from "./chunk-LRHOS4ZN.js";
|
|
268
|
+
getModelId,
|
|
269
|
+
getProviderId
|
|
270
|
+
} from "./chunk-DWYX7ASF.js";
|
|
242
271
|
|
|
243
272
|
// src/agent/chat-loop/commit.ts
|
|
244
273
|
function createChatLoopCommitBatchApplier(params) {
|
|
@@ -500,272 +529,6 @@ async function* runChatLoop(deps) {
|
|
|
500
529
|
);
|
|
501
530
|
}
|
|
502
531
|
|
|
503
|
-
// src/presets/patterns.ts
|
|
504
|
-
function globToRegex(pattern) {
|
|
505
|
-
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
506
|
-
return new RegExp(`^${escaped}$`, "i");
|
|
507
|
-
}
|
|
508
|
-
function matchesPatterns(id, patterns) {
|
|
509
|
-
return patterns.some((pattern) => globToRegex(pattern).test(id));
|
|
510
|
-
}
|
|
511
|
-
function filterTools(tools, options) {
|
|
512
|
-
const allowPatterns = options.allow ?? [];
|
|
513
|
-
const denyPatterns = options.deny ?? [];
|
|
514
|
-
return tools.filter((tool) => {
|
|
515
|
-
const matchesAllow = allowPatterns.length === 0 || matchesPatterns(tool.id, allowPatterns);
|
|
516
|
-
if (!matchesAllow) {
|
|
517
|
-
return false;
|
|
518
|
-
}
|
|
519
|
-
const matchesDeny = denyPatterns.length > 0 && matchesPatterns(tool.id, denyPatterns);
|
|
520
|
-
if (matchesDeny && allowPatterns.length === 0) {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
return true;
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// src/presets/apply.ts
|
|
528
|
-
function applyPreset(preset, availableTools, baseSystemPrompt) {
|
|
529
|
-
const tools = filterTools(availableTools, {
|
|
530
|
-
allow: preset.allowTools,
|
|
531
|
-
deny: preset.denyTools
|
|
532
|
-
});
|
|
533
|
-
let systemPrompt = preset.systemPrompt;
|
|
534
|
-
if (systemPrompt && baseSystemPrompt) {
|
|
535
|
-
systemPrompt = systemPrompt.replace("{basePrompt}", baseSystemPrompt);
|
|
536
|
-
}
|
|
537
|
-
return {
|
|
538
|
-
name: preset.name,
|
|
539
|
-
systemPrompt,
|
|
540
|
-
tools: tools.length > 0 ? tools : void 0,
|
|
541
|
-
temperature: preset.temperature,
|
|
542
|
-
maxSteps: preset.maxSteps,
|
|
543
|
-
reasoningLevel: preset.reasoningLevel,
|
|
544
|
-
model: preset.model
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
function mergePresets(...presets) {
|
|
548
|
-
if (presets.length === 0) {
|
|
549
|
-
throw new Error("mergePresets requires at least one preset");
|
|
550
|
-
}
|
|
551
|
-
if (presets.length === 1) {
|
|
552
|
-
return presets[0];
|
|
553
|
-
}
|
|
554
|
-
const [first, ...rest] = presets;
|
|
555
|
-
const allAllow = [];
|
|
556
|
-
const allDeny = [];
|
|
557
|
-
for (const preset of presets) {
|
|
558
|
-
if (preset.allowTools?.length) {
|
|
559
|
-
allAllow.push(preset.allowTools);
|
|
560
|
-
}
|
|
561
|
-
if (preset.denyTools?.length) {
|
|
562
|
-
allDeny.push(...preset.denyTools);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
const combinedAllow = allAllow.length > 0 ? allAllow.reduce(
|
|
566
|
-
(left, right) => left.length <= right.length ? left : right
|
|
567
|
-
) : void 0;
|
|
568
|
-
return {
|
|
569
|
-
name: presets.map((preset) => preset.name).join("+"),
|
|
570
|
-
description: presets.map((preset) => preset.description).join(" | "),
|
|
571
|
-
allowTools: combinedAllow,
|
|
572
|
-
denyTools: allDeny.length > 0 ? [...new Set(allDeny)] : void 0,
|
|
573
|
-
systemPrompt: rest.reduce(
|
|
574
|
-
(value, preset) => preset.systemPrompt ?? value,
|
|
575
|
-
first.systemPrompt
|
|
576
|
-
),
|
|
577
|
-
temperature: rest.reduce(
|
|
578
|
-
(value, preset) => preset.temperature ?? value,
|
|
579
|
-
first.temperature
|
|
580
|
-
),
|
|
581
|
-
maxSteps: rest.reduce(
|
|
582
|
-
(value, preset) => preset.maxSteps ?? value,
|
|
583
|
-
first.maxSteps
|
|
584
|
-
),
|
|
585
|
-
reasoningLevel: rest.reduce(
|
|
586
|
-
(value, preset) => preset.reasoningLevel ?? value,
|
|
587
|
-
first.reasoningLevel
|
|
588
|
-
),
|
|
589
|
-
model: rest.reduce((value, preset) => preset.model ?? value, first.model)
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
function createPreset(options) {
|
|
593
|
-
return {
|
|
594
|
-
description: options.description ?? `Custom preset: ${options.name}`,
|
|
595
|
-
...options
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// src/presets/builtins.ts
|
|
600
|
-
var explore = {
|
|
601
|
-
name: "explore",
|
|
602
|
-
description: "Read-only exploration mode for understanding content",
|
|
603
|
-
allowTools: ["read*", "search*", "glob*", "grep*", "list*", "find*"],
|
|
604
|
-
denyTools: ["write*", "edit*", "delete*", "bash*", "exec*", "run*"],
|
|
605
|
-
systemPrompt: `{basePrompt}
|
|
606
|
-
|
|
607
|
-
## EXPLORATION MODE
|
|
608
|
-
|
|
609
|
-
You are in **exploration mode**. Your goal is to thoroughly understand the content.
|
|
610
|
-
|
|
611
|
-
Guidelines:
|
|
612
|
-
- **Always start with glob or grep to discover correct paths** \u2014 never assume directory structure
|
|
613
|
-
- Use search and read tools extensively to build understanding
|
|
614
|
-
- Map out structures, dependencies, and patterns
|
|
615
|
-
- Look for conventions, common patterns, and documentation
|
|
616
|
-
- DO NOT modify anything \u2014 only read and analyse
|
|
617
|
-
- Summarise findings clearly with references to specific locations
|
|
618
|
-
|
|
619
|
-
Error recovery:
|
|
620
|
-
- If a tool returns an error (ENOENT, not found, etc.), try a different path or approach
|
|
621
|
-
- Use glob with broader patterns to discover the correct location
|
|
622
|
-
- Keep going until you have a thorough answer \u2014 do not give up after one failure
|
|
623
|
-
- You have multiple steps available \u2014 use them all if needed`,
|
|
624
|
-
temperature: 0.3,
|
|
625
|
-
maxSteps: 30
|
|
626
|
-
};
|
|
627
|
-
var plan = {
|
|
628
|
-
name: "plan",
|
|
629
|
-
description: "Planning mode for analyzing tasks and creating detailed plans",
|
|
630
|
-
allowTools: ["read*", "search*", "glob*", "grep*", "list*", "find*"],
|
|
631
|
-
denyTools: ["write*", "edit*", "delete*", "bash*", "exec*", "run*"],
|
|
632
|
-
systemPrompt: `{basePrompt}
|
|
633
|
-
|
|
634
|
-
## PLANNING MODE
|
|
635
|
-
|
|
636
|
-
You are in **planning mode**. Your goal is to analyze and plan before implementation.
|
|
637
|
-
|
|
638
|
-
Guidelines:
|
|
639
|
-
- Analyse the task requirements thoroughly
|
|
640
|
-
- Research existing patterns and conventions
|
|
641
|
-
- Identify potential impacts and dependencies
|
|
642
|
-
- Create a clear, step-by-step implementation plan
|
|
643
|
-
- DO NOT implement anything \u2014 only plan and document
|
|
644
|
-
- Output a numbered list of specific, actionable steps`,
|
|
645
|
-
temperature: 0.2,
|
|
646
|
-
maxSteps: 20
|
|
647
|
-
};
|
|
648
|
-
var review = {
|
|
649
|
-
name: "review",
|
|
650
|
-
description: "Thorough review and analysis mode",
|
|
651
|
-
allowTools: ["read*", "grep*", "search*", "glob*", "list*"],
|
|
652
|
-
denyTools: ["*"],
|
|
653
|
-
systemPrompt: `{basePrompt}
|
|
654
|
-
|
|
655
|
-
## REVIEW MODE
|
|
656
|
-
|
|
657
|
-
You are in **review mode**. Your goal is to perform a thorough analysis.
|
|
658
|
-
|
|
659
|
-
Review checklist:
|
|
660
|
-
- [ ] Logic errors and edge cases
|
|
661
|
-
- [ ] Security vulnerabilities
|
|
662
|
-
- [ ] Performance issues
|
|
663
|
-
- [ ] Error handling and recovery
|
|
664
|
-
- [ ] Clarity and maintainability
|
|
665
|
-
- [ ] Coverage gaps
|
|
666
|
-
|
|
667
|
-
Guidelines:
|
|
668
|
-
- Be thorough and systematic
|
|
669
|
-
- Cite specific locations and details
|
|
670
|
-
- Explain WHY something is an issue
|
|
671
|
-
- Suggest concrete fixes
|
|
672
|
-
- Rate severity: Critical / High / Medium / Low`,
|
|
673
|
-
temperature: 0.1,
|
|
674
|
-
maxSteps: 25
|
|
675
|
-
};
|
|
676
|
-
var quick = {
|
|
677
|
-
name: "quick",
|
|
678
|
-
description: "Fast mode for simple questions and quick operations",
|
|
679
|
-
systemPrompt: `{basePrompt}
|
|
680
|
-
|
|
681
|
-
## QUICK MODE
|
|
682
|
-
|
|
683
|
-
You are in **quick mode**. Be fast and focused.
|
|
684
|
-
|
|
685
|
-
Guidelines:
|
|
686
|
-
- Answer directly without lengthy explanations
|
|
687
|
-
- Use minimal tool calls (1-3 max)
|
|
688
|
-
- If you can't answer quickly, say so
|
|
689
|
-
- Prioritize speed over thoroughness`,
|
|
690
|
-
temperature: 0,
|
|
691
|
-
maxSteps: 5
|
|
692
|
-
};
|
|
693
|
-
var careful = {
|
|
694
|
-
name: "careful",
|
|
695
|
-
description: "Extra cautious mode for sensitive operations",
|
|
696
|
-
denyTools: ["bash*", "exec*", "run*", "delete*", "remove*"],
|
|
697
|
-
systemPrompt: `{basePrompt}
|
|
698
|
-
|
|
699
|
-
## CAREFUL MODE
|
|
700
|
-
|
|
701
|
-
You are in **careful mode**. Every action must be verified.
|
|
702
|
-
|
|
703
|
-
Guidelines:
|
|
704
|
-
- Double-check before any file modifications
|
|
705
|
-
- Explain what you're about to do BEFORE doing it
|
|
706
|
-
- Prefer smaller, incremental changes
|
|
707
|
-
- Always verify changes after making them
|
|
708
|
-
- If uncertain, ask for clarification rather than guessing`,
|
|
709
|
-
temperature: 0,
|
|
710
|
-
maxSteps: 50
|
|
711
|
-
};
|
|
712
|
-
var code = {
|
|
713
|
-
name: "code",
|
|
714
|
-
description: "Full-power implementation mode for writing and modifying code",
|
|
715
|
-
systemPrompt: `{basePrompt}
|
|
716
|
-
|
|
717
|
-
## IMPLEMENTATION MODE
|
|
718
|
-
|
|
719
|
-
You are a focused **implementation agent**. Your goal is to complete the assigned task fully and correctly.
|
|
720
|
-
|
|
721
|
-
Guidelines:
|
|
722
|
-
- Read existing code first to understand context and conventions before making changes
|
|
723
|
-
- Follow the project's existing patterns, naming conventions, and style
|
|
724
|
-
- Make minimal, targeted changes \u2014 do not refactor unrelated code
|
|
725
|
-
- Verify your work: re-read modified files, run tests or lint if available
|
|
726
|
-
- If the task requires multiple files, handle them systematically one at a time
|
|
727
|
-
|
|
728
|
-
Error recovery:
|
|
729
|
-
- If a command fails, read the error output carefully and fix the root cause
|
|
730
|
-
- If a test fails, read the failure details and iterate until it passes
|
|
731
|
-
- If you cannot find a file, use glob or grep to discover the correct path
|
|
732
|
-
- Keep iterating until the task is DONE \u2014 do not stop at a partial solution
|
|
733
|
-
- You have many steps available \u2014 use them all if needed`,
|
|
734
|
-
temperature: 0,
|
|
735
|
-
maxSteps: 50
|
|
736
|
-
};
|
|
737
|
-
var watch = {
|
|
738
|
-
name: "watch",
|
|
739
|
-
description: "Process monitoring mode for running and watching long commands",
|
|
740
|
-
allowTools: ["bash*", "exec*", "run*", "read*", "grep*", "glob*", "list*", "find*"],
|
|
741
|
-
denyTools: ["write*", "edit*", "delete*", "remove*"],
|
|
742
|
-
systemPrompt: `{basePrompt}
|
|
743
|
-
|
|
744
|
-
## WATCH MODE
|
|
745
|
-
|
|
746
|
-
You are a **process monitor**. Your goal is to execute a command, observe its output, and report the result.
|
|
747
|
-
|
|
748
|
-
Guidelines:
|
|
749
|
-
- Run the command as given \u2014 do not modify or "improve" it
|
|
750
|
-
- Wait for completion and capture the full output
|
|
751
|
-
- Parse the output for success/failure status, error counts, warnings
|
|
752
|
-
- Report a clear summary: what ran, whether it passed, key details
|
|
753
|
-
- If the process fails, include the relevant error output verbatim
|
|
754
|
-
- Do NOT attempt to fix issues \u2014 only observe and report`,
|
|
755
|
-
temperature: 0,
|
|
756
|
-
maxSteps: 10,
|
|
757
|
-
reasoningLevel: "low"
|
|
758
|
-
};
|
|
759
|
-
var Presets = {
|
|
760
|
-
explore,
|
|
761
|
-
plan,
|
|
762
|
-
review,
|
|
763
|
-
quick,
|
|
764
|
-
careful,
|
|
765
|
-
code,
|
|
766
|
-
watch
|
|
767
|
-
};
|
|
768
|
-
|
|
769
532
|
// src/agent/fork.ts
|
|
770
533
|
function resolveForkOptions(options, parentTools, systemPrompt) {
|
|
771
534
|
if (!options.preset) {
|
|
@@ -844,7 +607,7 @@ function createForkedAgentConfig(options) {
|
|
|
844
607
|
};
|
|
845
608
|
}
|
|
846
609
|
|
|
847
|
-
// src/agent/mcp.ts
|
|
610
|
+
// src/agent/mcp-bridge.ts
|
|
848
611
|
async function ensureMcpTools(state) {
|
|
849
612
|
if (!state.manager) {
|
|
850
613
|
return { connected: false, cachedTools: void 0 };
|
|
@@ -1039,23 +802,14 @@ var InterventionController = class {
|
|
|
1039
802
|
}
|
|
1040
803
|
};
|
|
1041
804
|
|
|
1042
|
-
// src/agent/
|
|
805
|
+
// src/agent/stream-provider.ts
|
|
1043
806
|
var DEFAULT_CUSTOM_STREAM_MODELS = [
|
|
1044
807
|
"computer-use-preview",
|
|
1045
808
|
"computer-use-preview-2025-03-11"
|
|
1046
809
|
];
|
|
1047
|
-
function getModelId2(model) {
|
|
1048
|
-
if (typeof model === "string") {
|
|
1049
|
-
return model;
|
|
1050
|
-
}
|
|
1051
|
-
if (typeof model === "object" && model !== null && "modelId" in model) {
|
|
1052
|
-
return String(model.modelId);
|
|
1053
|
-
}
|
|
1054
|
-
return void 0;
|
|
1055
|
-
}
|
|
1056
810
|
function needsCustomStreamProvider(model, customPatterns) {
|
|
1057
|
-
const modelId =
|
|
1058
|
-
if (!modelId) return false;
|
|
811
|
+
const modelId = getModelId(model);
|
|
812
|
+
if (!modelId || modelId === "[object Object]") return false;
|
|
1059
813
|
const patterns = customPatterns ?? DEFAULT_CUSTOM_STREAM_MODELS;
|
|
1060
814
|
return patterns.some((pattern) => modelId.includes(pattern));
|
|
1061
815
|
}
|
|
@@ -1070,7 +824,7 @@ function autoDetectStreamProvider(model, tools, explicitProvider) {
|
|
|
1070
824
|
const enhancedTools = tools;
|
|
1071
825
|
const customPatterns = enhancedTools.__customStreamModels;
|
|
1072
826
|
if (needsCustomStreamProvider(model, customPatterns) && hasStreamProviderFactory(enhancedTools)) {
|
|
1073
|
-
const modelId =
|
|
827
|
+
const modelId = getModelId(model);
|
|
1074
828
|
if (modelId) {
|
|
1075
829
|
const streamConfig = {
|
|
1076
830
|
apiKey: process.env.OPENAI_API_KEY,
|
|
@@ -1115,10 +869,11 @@ function createEffectiveAgentConfig(config) {
|
|
|
1115
869
|
return {
|
|
1116
870
|
systemPrompt: DEFAULT_SYSTEM_PROMPT,
|
|
1117
871
|
cwd: process.cwd(),
|
|
1118
|
-
maxOutputTokens: DEFAULT_MAX_TOKENS,
|
|
1119
|
-
maxSteps: DEFAULT_MAX_STEPS,
|
|
1120
872
|
reasoningLevel: "off",
|
|
1121
873
|
...config,
|
|
874
|
+
// Re-apply defaults after spread so explicit `undefined` from callers doesn't win.
|
|
875
|
+
maxSteps: config.maxSteps ?? DEFAULT_MAX_STEPS,
|
|
876
|
+
maxOutputTokens: config.maxOutputTokens ?? DEFAULT_MAX_TOKENS,
|
|
1122
877
|
streamProvider: effectiveStreamProvider
|
|
1123
878
|
};
|
|
1124
879
|
}
|
|
@@ -1145,10 +900,17 @@ function createAgentState(config) {
|
|
|
1145
900
|
}
|
|
1146
901
|
function createAgentContextManager(config) {
|
|
1147
902
|
const compactionConfig = config.compaction ?? {};
|
|
903
|
+
const modelId = getModelId(config.model);
|
|
904
|
+
const inferredWindow = inferContextWindow(modelId);
|
|
905
|
+
const contextWindow = config.contextWindow ?? inferredWindow ?? DEFAULT_CONTEXT_LIMITS.contextWindow;
|
|
906
|
+
const reserveTokens = Math.min(
|
|
907
|
+
32e3,
|
|
908
|
+
Math.max(8e3, Math.round(contextWindow * 0.12))
|
|
909
|
+
);
|
|
1148
910
|
return new ContextManager({
|
|
1149
911
|
limits: {
|
|
1150
|
-
contextWindow
|
|
1151
|
-
reserveTokens
|
|
912
|
+
contextWindow,
|
|
913
|
+
reserveTokens,
|
|
1152
914
|
protectedTokens: compactionConfig.protectedTokens ?? DEFAULT_CONTEXT_LIMITS.protectedTokens,
|
|
1153
915
|
pruneMinimum: compactionConfig.pruneMinimum ?? DEFAULT_CONTEXT_LIMITS.pruneMinimum
|
|
1154
916
|
},
|
|
@@ -1294,6 +1056,8 @@ var Agent = class _Agent {
|
|
|
1294
1056
|
mcpManager;
|
|
1295
1057
|
/** Whether MCP has been connected (lazy init) */
|
|
1296
1058
|
mcpConnected = false;
|
|
1059
|
+
/** Whether skill tools have been resolved (lazy init) */
|
|
1060
|
+
skillToolsResolved = false;
|
|
1297
1061
|
/** Cached MCP tools (refreshed on connect) */
|
|
1298
1062
|
mcpToolsCache;
|
|
1299
1063
|
/** Prompt pipeline builder (when using layered prompt mode) */
|
|
@@ -1308,6 +1072,8 @@ var Agent = class _Agent {
|
|
|
1308
1072
|
telemetrySettings;
|
|
1309
1073
|
/** Tracing shutdown function (from `tracing` config auto-setup) */
|
|
1310
1074
|
tracingShutdown;
|
|
1075
|
+
/** Multi-consumer event dispatch */
|
|
1076
|
+
_signal;
|
|
1311
1077
|
constructor(config) {
|
|
1312
1078
|
const setup = createAgentSetup(config);
|
|
1313
1079
|
this.config = setup.config;
|
|
@@ -1323,6 +1089,17 @@ var Agent = class _Agent {
|
|
|
1323
1089
|
this.middlewareRunner = setup.middlewareRunner;
|
|
1324
1090
|
this.telemetrySettings = setup.telemetrySettings;
|
|
1325
1091
|
this.tracingShutdown = setup.tracingShutdown;
|
|
1092
|
+
this._signal = config.signal ?? new LocalSignal();
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Event signal — subscribe to events without consuming the generator.
|
|
1096
|
+
*
|
|
1097
|
+
* Every event yielded by `chat()` is also dispatched here, allowing
|
|
1098
|
+
* multiple passive observers (SSE routes, TUI, plugins) to listen
|
|
1099
|
+
* concurrently.
|
|
1100
|
+
*/
|
|
1101
|
+
get signal() {
|
|
1102
|
+
return this._signal;
|
|
1326
1103
|
}
|
|
1327
1104
|
/** Agent name (identity for spans, Dapr workflows, etc.) */
|
|
1328
1105
|
get name() {
|
|
@@ -1369,6 +1146,22 @@ var Agent = class _Agent {
|
|
|
1369
1146
|
supportsReasoning() {
|
|
1370
1147
|
return supportsReasoningSync(this.state.model);
|
|
1371
1148
|
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Ensure skill tools are registered when `prompt.skills` is configured.
|
|
1151
|
+
* Lazy initialization — resolves the registry and adds tools on first use.
|
|
1152
|
+
*/
|
|
1153
|
+
async ensureSkillTools() {
|
|
1154
|
+
if (this.skillToolsResolved || !this.promptBuilder) return;
|
|
1155
|
+
this.skillToolsResolved = true;
|
|
1156
|
+
const registry = await this.promptBuilder.getSkillRegistry(this.config.cwd);
|
|
1157
|
+
if (registry.size > 0) {
|
|
1158
|
+
for (const tool of createSkillTools(registry)) {
|
|
1159
|
+
if (!this.tools.has(tool.id)) {
|
|
1160
|
+
this.tools.set(tool.id, tool);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1372
1165
|
/**
|
|
1373
1166
|
* Ensure MCP is connected and return tools
|
|
1374
1167
|
* Lazy initialization - only connects on first use
|
|
@@ -1420,12 +1213,13 @@ var Agent = class _Agent {
|
|
|
1420
1213
|
*/
|
|
1421
1214
|
async *chat(sessionId, message, options) {
|
|
1422
1215
|
await this.ensureSession(sessionId);
|
|
1216
|
+
await this.ensureSkillTools();
|
|
1423
1217
|
const abort = options?.abort ?? new AbortController().signal;
|
|
1424
1218
|
const turnId = `${sessionId}-turn-${++this.turnCounter}`;
|
|
1425
1219
|
this.turnTracker.startTurn(turnId);
|
|
1426
1220
|
await this.repairOrphanedToolCalls();
|
|
1427
1221
|
const mcpTools = await this.ensureMCPConnected();
|
|
1428
|
-
|
|
1222
|
+
const loop = runChatLoop({
|
|
1429
1223
|
sessionId,
|
|
1430
1224
|
message,
|
|
1431
1225
|
abort,
|
|
@@ -1448,6 +1242,10 @@ var Agent = class _Agent {
|
|
|
1448
1242
|
this.state.isStreaming = v;
|
|
1449
1243
|
}
|
|
1450
1244
|
});
|
|
1245
|
+
for await (const event of loop) {
|
|
1246
|
+
this._signal.emit(event);
|
|
1247
|
+
yield event;
|
|
1248
|
+
}
|
|
1451
1249
|
}
|
|
1452
1250
|
/**
|
|
1453
1251
|
* Ensure a session is loaded or created
|
|
@@ -1778,6 +1576,17 @@ var Agent = class _Agent {
|
|
|
1778
1576
|
setModel(model) {
|
|
1779
1577
|
this.config.model = model;
|
|
1780
1578
|
this.state.model = model;
|
|
1579
|
+
if (this.config.contextWindow === void 0) {
|
|
1580
|
+
const modelId = getModelId(model);
|
|
1581
|
+
const inferred = inferContextWindow(modelId);
|
|
1582
|
+
if (inferred) {
|
|
1583
|
+
const reserveTokens = Math.min(
|
|
1584
|
+
32e3,
|
|
1585
|
+
Math.max(8e3, Math.round(inferred * 0.12))
|
|
1586
|
+
);
|
|
1587
|
+
this.contextManager.setLimits({ contextWindow: inferred, reserveTokens });
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1781
1590
|
}
|
|
1782
1591
|
/**
|
|
1783
1592
|
* Get the prompt builder (when using pipeline mode).
|
|
@@ -1995,6 +1804,7 @@ var Agent = class _Agent {
|
|
|
1995
1804
|
* After calling close(), the agent should not be used.
|
|
1996
1805
|
*/
|
|
1997
1806
|
async close() {
|
|
1807
|
+
this._signal.clear();
|
|
1998
1808
|
if (this.tracingShutdown) {
|
|
1999
1809
|
await this.tracingShutdown();
|
|
2000
1810
|
}
|
|
@@ -2061,6 +1871,7 @@ export {
|
|
|
2061
1871
|
InterventionController,
|
|
2062
1872
|
LLM,
|
|
2063
1873
|
LLMError,
|
|
1874
|
+
LocalSignal,
|
|
2064
1875
|
MAX_BYTES,
|
|
2065
1876
|
MAX_LINES,
|
|
2066
1877
|
MemoryStorage,
|
|
@@ -2138,6 +1949,7 @@ export {
|
|
|
2138
1949
|
createResolver,
|
|
2139
1950
|
createRetryHandler,
|
|
2140
1951
|
createRetryState,
|
|
1952
|
+
createScope,
|
|
2141
1953
|
createSkillRegistry,
|
|
2142
1954
|
createSkillResourceTool,
|
|
2143
1955
|
createSkillTool,
|
|
@@ -2145,6 +1957,7 @@ export {
|
|
|
2145
1957
|
createSubAgentTools,
|
|
2146
1958
|
createTelemetryConfig,
|
|
2147
1959
|
createTurnTracker,
|
|
1960
|
+
currentScope,
|
|
2148
1961
|
defaultAgentTaskCheckpointStrategy,
|
|
2149
1962
|
defaultRegistry,
|
|
2150
1963
|
defineServer,
|
|
@@ -2197,6 +2010,7 @@ export {
|
|
|
2197
2010
|
getToolRisk,
|
|
2198
2011
|
hasStreamProviderFactory,
|
|
2199
2012
|
httpServer,
|
|
2013
|
+
inferContextWindow,
|
|
2200
2014
|
inferProvider,
|
|
2201
2015
|
inferResourceType,
|
|
2202
2016
|
isContextOverflowing,
|
|
@@ -2227,6 +2041,7 @@ export {
|
|
|
2227
2041
|
recordAgentWorkflowReplayDecision,
|
|
2228
2042
|
restoreAgentWorkflowMessage,
|
|
2229
2043
|
restoreAgentWorkflowMessages,
|
|
2044
|
+
restoreScope,
|
|
2230
2045
|
review,
|
|
2231
2046
|
runChatLoop,
|
|
2232
2047
|
runConcurrent,
|
|
@@ -2240,6 +2055,7 @@ export {
|
|
|
2240
2055
|
sleep,
|
|
2241
2056
|
snapshotAgentWorkflowMessage,
|
|
2242
2057
|
snapshotAgentWorkflowMessages,
|
|
2058
|
+
snapshotScope,
|
|
2243
2059
|
sseServer,
|
|
2244
2060
|
stdioServer,
|
|
2245
2061
|
stream,
|
|
@@ -2253,5 +2069,6 @@ export {
|
|
|
2253
2069
|
truncateOutput,
|
|
2254
2070
|
watch,
|
|
2255
2071
|
withFileTracking,
|
|
2256
|
-
withRetry
|
|
2072
|
+
withRetry,
|
|
2073
|
+
withinScope
|
|
2257
2074
|
};
|