@cuylabs/agent-core 0.6.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.
Files changed (74) hide show
  1. package/README.md +5 -1
  2. package/dist/{builder-BKkipazh.d.ts → builder-UpOWQMW3.d.ts} +2 -2
  3. package/dist/{chunk-3C4VKG4P.js → chunk-4BDA7DQY.js} +273 -807
  4. package/dist/chunk-7VKQ4WPB.js +73 -0
  5. package/dist/chunk-BFM2YHNM.js +222 -0
  6. package/dist/chunk-CAA7FHIH.js +280 -0
  7. package/dist/chunk-KUVSERLJ.js +50 -0
  8. package/dist/chunk-N6HWIEEA.js +423 -0
  9. package/dist/chunk-N7P4PN3O.js +84 -0
  10. package/dist/{chunk-QWFMX226.js → chunk-RFEKJKTO.js} +252 -13
  11. package/dist/chunk-RZITT45F.js +202 -0
  12. package/dist/{chunk-X635CM2F.js → chunk-SQU2AJHO.js} +1 -1
  13. package/dist/chunk-VNQBHPCT.js +398 -0
  14. package/dist/{chunk-QAQADS4X.js → chunk-WWYYNWEW.js} +2 -1
  15. package/dist/{chunk-O2ZCFQL6.js → chunk-YSLSEQ6B.js} +105 -220
  16. package/dist/context/index.js +1 -1
  17. package/dist/errors/index.d.ts +11 -0
  18. package/dist/errors/index.js +16 -0
  19. package/dist/events-CE72w8W4.d.ts +149 -0
  20. package/dist/host/index.d.ts +45 -0
  21. package/dist/host/index.js +8 -0
  22. package/dist/{index-DZQJD_hp.d.ts → index-CWSchSql.d.ts} +42 -51
  23. package/dist/index.d.ts +98 -190
  24. package/dist/index.js +476 -939
  25. package/dist/inference/index.d.ts +62 -0
  26. package/dist/inference/index.js +27 -0
  27. package/dist/llm-error-D93FNNLY.d.ts +32 -0
  28. package/dist/middleware/index.d.ts +246 -5
  29. package/dist/middleware/index.js +7 -3
  30. package/dist/models/index.d.ts +226 -3
  31. package/dist/models/index.js +41 -3
  32. package/dist/presets/index.d.ts +53 -0
  33. package/dist/presets/index.js +28 -0
  34. package/dist/prompt/index.d.ts +12 -7
  35. package/dist/reasoning/index.d.ts +53 -8
  36. package/dist/reasoning/index.js +2 -7
  37. package/dist/{registry-CuRWWtcT.d.ts → registry-DwYqsQkX.d.ts} +1 -1
  38. package/dist/{runner-G1wxEgac.d.ts → runner-e2YRcUoX.d.ts} +82 -148
  39. package/dist/runtime/index.d.ts +44 -7
  40. package/dist/runtime/index.js +16 -5
  41. package/dist/safety/index.d.ts +38 -0
  42. package/dist/safety/index.js +12 -0
  43. package/dist/scope/index.d.ts +10 -0
  44. package/dist/scope/index.js +14 -0
  45. package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
  46. package/dist/signal/index.d.ts +28 -0
  47. package/dist/signal/index.js +6 -0
  48. package/dist/skill/index.d.ts +8 -5
  49. package/dist/storage/index.d.ts +2 -2
  50. package/dist/sub-agent/index.d.ts +17 -8
  51. package/dist/tool/index.d.ts +9 -4
  52. package/dist/tool/index.js +4 -3
  53. package/dist/tool-BHbyUAy3.d.ts +150 -0
  54. package/dist/{tool-DYp6-cC3.d.ts → tool-DLXAR9Ce.d.ts} +5 -99
  55. package/dist/tracking/index.d.ts +3 -1
  56. package/dist/{tool-pFAnJc5Y.d.ts → types-BfNpU8NS.d.ts} +1 -150
  57. package/dist/types-BnpEOYV-.d.ts +50 -0
  58. package/dist/types-CHiPh8U2.d.ts +100 -0
  59. package/dist/types-CQL-SvTn.d.ts +29 -0
  60. package/dist/types-CWm-7rvB.d.ts +55 -0
  61. package/dist/types-KKDrdU9Y.d.ts +325 -0
  62. package/dist/{resolver-DOfZ-xuk.d.ts → types-QA4WhEfz.d.ts} +1 -117
  63. package/dist/types-QKHHQLLq.d.ts +336 -0
  64. package/dist/types-YuWV4ag7.d.ts +72 -0
  65. package/package.json +74 -8
  66. package/dist/capabilities/index.d.ts +0 -97
  67. package/dist/capabilities/index.js +0 -46
  68. package/dist/chunk-6TDTQJ4P.js +0 -116
  69. package/dist/chunk-FG4MD5MU.js +0 -54
  70. package/dist/config-D2xeGEHK.d.ts +0 -52
  71. package/dist/identifiers-BLUxFqV_.d.ts +0 -12
  72. package/dist/index-ipP3_ztp.d.ts +0 -198
  73. package/dist/network-D76DS5ot.d.ts +0 -5
  74. package/dist/types-BWo810L_.d.ts +0 -648
@@ -0,0 +1,73 @@
1
+ import {
2
+ extractFilePathsFromArgs,
3
+ shouldCaptureBaseline
4
+ } from "./chunk-VEKUXUVF.js";
5
+ import {
6
+ snapshotScope,
7
+ withinScope
8
+ } from "./chunk-N7P4PN3O.js";
9
+
10
+ // src/tool/executor.ts
11
+ async function executeAgentToolCall(options) {
12
+ return withinScope(
13
+ {
14
+ kind: "tool",
15
+ name: "tool-call",
16
+ sessionId: options.sessionID,
17
+ attributes: {
18
+ toolName: options.toolName,
19
+ messageId: options.messageID,
20
+ agent: options.agent ?? "default"
21
+ }
22
+ },
23
+ async () => {
24
+ const initialized = await options.tool.init({ cwd: options.cwd });
25
+ const ctx = {
26
+ cwd: options.cwd,
27
+ abort: options.abort,
28
+ sessionID: options.sessionID,
29
+ messageID: options.messageID,
30
+ agent: options.agent ?? "default",
31
+ scope: snapshotScope(),
32
+ ...options.host ? { host: options.host } : {},
33
+ ...options.turnTracker ? { turnTracker: options.turnTracker } : {}
34
+ };
35
+ if (options.middleware?.hasMiddleware) {
36
+ const decision = await options.middleware.runBeforeToolCall(
37
+ options.toolName,
38
+ options.params,
39
+ ctx
40
+ );
41
+ if (decision.action === "deny") {
42
+ return {
43
+ output: decision.reason ?? `Tool call denied: ${options.toolName}`
44
+ };
45
+ }
46
+ }
47
+ if (options.turnTracker && initialized.fileOps && shouldCaptureBaseline(initialized.fileOps)) {
48
+ const paths = extractFilePathsFromArgs(
49
+ options.params,
50
+ initialized.fileOps
51
+ );
52
+ for (const path of paths) {
53
+ await options.turnTracker.beforeWrite(path);
54
+ }
55
+ }
56
+ const result = await initialized.execute(options.params, ctx);
57
+ if (options.middleware?.hasMiddleware) {
58
+ const transformed = await options.middleware.runAfterToolCall(
59
+ options.toolName,
60
+ options.params,
61
+ result,
62
+ ctx
63
+ );
64
+ return { output: transformed.output };
65
+ }
66
+ return { output: result.output };
67
+ }
68
+ );
69
+ }
70
+
71
+ export {
72
+ executeAgentToolCall
73
+ };
@@ -0,0 +1,222 @@
1
+ // src/safety/approval/risk.ts
2
+ var DEFAULT_TOOL_RISKS = {
3
+ read: "safe",
4
+ read_file: "safe",
5
+ grep: "safe",
6
+ glob: "safe",
7
+ list_dir: "safe",
8
+ plan: "safe",
9
+ invoke_agent: "safe",
10
+ wait_agent: "safe",
11
+ close_agent: "safe",
12
+ skill: "safe",
13
+ skill_resource: "safe",
14
+ write: "moderate",
15
+ write_file: "moderate",
16
+ edit: "moderate",
17
+ edit_file: "moderate",
18
+ create_file: "moderate",
19
+ bash: "dangerous",
20
+ shell: "dangerous",
21
+ delete_file: "dangerous",
22
+ remove: "dangerous"
23
+ };
24
+ function getToolRisk(tool, customRisks) {
25
+ if (customRisks?.[tool]) {
26
+ return customRisks[tool];
27
+ }
28
+ if (DEFAULT_TOOL_RISKS[tool]) {
29
+ return DEFAULT_TOOL_RISKS[tool];
30
+ }
31
+ return "moderate";
32
+ }
33
+
34
+ // src/safety/approval/errors.ts
35
+ var ApprovalDeniedError = class extends Error {
36
+ constructor(tool, args, message) {
37
+ super(message || `Operation denied: ${tool}`);
38
+ this.tool = tool;
39
+ this.args = args;
40
+ this.name = "ApprovalDeniedError";
41
+ }
42
+ };
43
+ var ApprovalTimeoutError = class extends Error {
44
+ constructor(tool, timeoutMs) {
45
+ super(`Approval timeout after ${timeoutMs}ms for: ${tool}`);
46
+ this.tool = tool;
47
+ this.timeoutMs = timeoutMs;
48
+ this.name = "ApprovalTimeoutError";
49
+ }
50
+ };
51
+
52
+ // src/safety/approval/patterns.ts
53
+ function matchApprovalPattern(pattern, value) {
54
+ const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
55
+ return new RegExp(`^${regex}$`, "i").test(value);
56
+ }
57
+ function extractApprovalPatterns(tool, args) {
58
+ if (!args || typeof args !== "object") {
59
+ return [tool];
60
+ }
61
+ const record = args;
62
+ if ("path" in record && typeof record.path === "string" || "filePath" in record && typeof record.filePath === "string") {
63
+ const path = record.path ?? record.filePath;
64
+ const dir = path.substring(0, path.lastIndexOf("/") + 1);
65
+ return [dir ? `${dir}*` : path];
66
+ }
67
+ if ("command" in record && typeof record.command === "string") {
68
+ const command = record.command.split(/\s+/)[0];
69
+ return [command];
70
+ }
71
+ if ("pattern" in record && typeof record.pattern === "string") {
72
+ return [record.pattern];
73
+ }
74
+ return [tool];
75
+ }
76
+ function describeApprovalOperation(tool, args) {
77
+ if (!args || typeof args !== "object") {
78
+ return `Execute ${tool}`;
79
+ }
80
+ const record = args;
81
+ switch (tool) {
82
+ case "read":
83
+ case "read_file":
84
+ return `Read file: ${record.path ?? record.filePath}`;
85
+ case "write":
86
+ case "write_file":
87
+ case "create_file":
88
+ return `Write file: ${record.path ?? record.filePath}`;
89
+ case "edit":
90
+ case "edit_file":
91
+ return `Edit file: ${record.path ?? record.filePath}`;
92
+ case "delete_file":
93
+ case "remove":
94
+ return `Delete: ${record.path}`;
95
+ case "bash":
96
+ case "shell": {
97
+ const command = String(record.command);
98
+ return `Run command: ${command.slice(0, 100)}${command.length > 100 ? "..." : ""}`;
99
+ }
100
+ case "grep":
101
+ return `Search for: ${record.pattern}`;
102
+ case "glob":
103
+ return `Find files: ${record.pattern}`;
104
+ default:
105
+ return `${tool}(${JSON.stringify(args).slice(0, 50)}...)`;
106
+ }
107
+ }
108
+
109
+ // src/safety/approval/handler.ts
110
+ var requestCounter = 0;
111
+ function findMatchingRule(rules, tool, patterns) {
112
+ for (let index = rules.length - 1; index >= 0; index--) {
113
+ const rule = rules[index];
114
+ const toolMatches = rule.tool === "*" || matchApprovalPattern(rule.tool, tool);
115
+ const patternMatches = patterns.some(
116
+ (pattern) => matchApprovalPattern(rule.pattern, pattern)
117
+ );
118
+ if (toolMatches && patternMatches) {
119
+ return rule;
120
+ }
121
+ }
122
+ return void 0;
123
+ }
124
+ function createApprovalHandler(config = {}) {
125
+ const {
126
+ defaultAction = "ask",
127
+ timeout = 5 * 60 * 1e3,
128
+ onRequest
129
+ } = config;
130
+ const rules = [...config.rules ?? []];
131
+ const pending = /* @__PURE__ */ new Map();
132
+ async function request(sessionId, tool, args, customRisks) {
133
+ const risk = getToolRisk(tool, customRisks);
134
+ const patterns = extractApprovalPatterns(tool, args);
135
+ const matchingRule = findMatchingRule(rules, tool, patterns);
136
+ if (matchingRule) {
137
+ if (matchingRule.action === "allow") {
138
+ return;
139
+ }
140
+ throw new ApprovalDeniedError(
141
+ tool,
142
+ args,
143
+ `Denied by rule: ${matchingRule.pattern}`
144
+ );
145
+ }
146
+ if (risk === "safe" && defaultAction !== "deny") {
147
+ return;
148
+ }
149
+ if (!onRequest) {
150
+ if (defaultAction === "allow") {
151
+ return;
152
+ }
153
+ if (defaultAction === "deny") {
154
+ throw new ApprovalDeniedError(tool, args);
155
+ }
156
+ throw new ApprovalDeniedError(tool, args, "No approval handler configured");
157
+ }
158
+ const id = `approval-${++requestCounter}-${Date.now()}`;
159
+ const requestData = {
160
+ id,
161
+ sessionId,
162
+ tool,
163
+ args,
164
+ description: describeApprovalOperation(tool, args),
165
+ risk,
166
+ patterns,
167
+ timestamp: Date.now()
168
+ };
169
+ const action = await Promise.race([
170
+ new Promise((resolve, reject) => {
171
+ pending.set(id, { resolve, reject });
172
+ onRequest(requestData).then(resolve).catch(reject).finally(() => pending.delete(id));
173
+ }),
174
+ new Promise((_, reject) => {
175
+ setTimeout(() => {
176
+ pending.delete(id);
177
+ reject(new ApprovalTimeoutError(tool, timeout));
178
+ }, timeout);
179
+ })
180
+ ]);
181
+ switch (action) {
182
+ case "allow":
183
+ return;
184
+ case "deny":
185
+ throw new ApprovalDeniedError(tool, args);
186
+ case "remember":
187
+ for (const pattern of patterns) {
188
+ rules.push({ pattern, tool, action: "allow" });
189
+ }
190
+ return;
191
+ }
192
+ }
193
+ function cancelAll(reason) {
194
+ for (const [id, { reject }] of pending) {
195
+ reject(new Error(reason ?? "Cancelled"));
196
+ pending.delete(id);
197
+ }
198
+ }
199
+ function addRule(rule) {
200
+ rules.push(rule);
201
+ }
202
+ function getRules() {
203
+ return rules;
204
+ }
205
+ function clearSessionRules() {
206
+ rules.length = config.rules?.length ?? 0;
207
+ }
208
+ return {
209
+ request,
210
+ cancelAll,
211
+ addRule,
212
+ getRules,
213
+ clearSessionRules
214
+ };
215
+ }
216
+
217
+ export {
218
+ getToolRisk,
219
+ ApprovalDeniedError,
220
+ ApprovalTimeoutError,
221
+ createApprovalHandler
222
+ };
@@ -0,0 +1,280 @@
1
+ // src/presets/patterns.ts
2
+ function globToRegex(pattern) {
3
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
4
+ return new RegExp(`^${escaped}$`, "i");
5
+ }
6
+ function matchesPatterns(id, patterns) {
7
+ return patterns.some((pattern) => globToRegex(pattern).test(id));
8
+ }
9
+ function filterTools(tools, options) {
10
+ const allowPatterns = options.allow ?? [];
11
+ const denyPatterns = options.deny ?? [];
12
+ return tools.filter((tool) => {
13
+ const matchesAllow = allowPatterns.length === 0 || matchesPatterns(tool.id, allowPatterns);
14
+ if (!matchesAllow) {
15
+ return false;
16
+ }
17
+ const matchesDeny = denyPatterns.length > 0 && matchesPatterns(tool.id, denyPatterns);
18
+ if (matchesDeny && allowPatterns.length === 0) {
19
+ return false;
20
+ }
21
+ return true;
22
+ });
23
+ }
24
+
25
+ // src/presets/apply.ts
26
+ function applyPreset(preset, availableTools, baseSystemPrompt) {
27
+ const tools = filterTools(availableTools, {
28
+ allow: preset.allowTools,
29
+ deny: preset.denyTools
30
+ });
31
+ let systemPrompt = preset.systemPrompt;
32
+ if (systemPrompt && baseSystemPrompt) {
33
+ systemPrompt = systemPrompt.replace("{basePrompt}", baseSystemPrompt);
34
+ }
35
+ return {
36
+ name: preset.name,
37
+ systemPrompt,
38
+ tools: tools.length > 0 ? tools : void 0,
39
+ temperature: preset.temperature,
40
+ maxSteps: preset.maxSteps,
41
+ reasoningLevel: preset.reasoningLevel,
42
+ model: preset.model
43
+ };
44
+ }
45
+ function mergePresets(...presets) {
46
+ if (presets.length === 0) {
47
+ throw new Error("mergePresets requires at least one preset");
48
+ }
49
+ if (presets.length === 1) {
50
+ return presets[0];
51
+ }
52
+ const [first, ...rest] = presets;
53
+ const allAllow = [];
54
+ const allDeny = [];
55
+ for (const preset of presets) {
56
+ if (preset.allowTools?.length) {
57
+ allAllow.push(preset.allowTools);
58
+ }
59
+ if (preset.denyTools?.length) {
60
+ allDeny.push(...preset.denyTools);
61
+ }
62
+ }
63
+ const combinedAllow = allAllow.length > 0 ? allAllow.reduce(
64
+ (left, right) => left.length <= right.length ? left : right
65
+ ) : void 0;
66
+ return {
67
+ name: presets.map((preset) => preset.name).join("+"),
68
+ description: presets.map((preset) => preset.description).join(" | "),
69
+ allowTools: combinedAllow,
70
+ denyTools: allDeny.length > 0 ? [...new Set(allDeny)] : void 0,
71
+ systemPrompt: rest.reduce(
72
+ (value, preset) => preset.systemPrompt ?? value,
73
+ first.systemPrompt
74
+ ),
75
+ temperature: rest.reduce(
76
+ (value, preset) => preset.temperature ?? value,
77
+ first.temperature
78
+ ),
79
+ maxSteps: rest.reduce(
80
+ (value, preset) => preset.maxSteps ?? value,
81
+ first.maxSteps
82
+ ),
83
+ reasoningLevel: rest.reduce(
84
+ (value, preset) => preset.reasoningLevel ?? value,
85
+ first.reasoningLevel
86
+ ),
87
+ model: rest.reduce((value, preset) => preset.model ?? value, first.model)
88
+ };
89
+ }
90
+ function createPreset(options) {
91
+ return {
92
+ description: options.description ?? `Custom preset: ${options.name}`,
93
+ ...options
94
+ };
95
+ }
96
+
97
+ // src/presets/builtins.ts
98
+ var explore = {
99
+ name: "explore",
100
+ description: "Read-only exploration mode for understanding content",
101
+ allowTools: ["read*", "search*", "glob*", "grep*", "list*", "find*"],
102
+ denyTools: ["write*", "edit*", "delete*", "bash*", "exec*", "run*"],
103
+ systemPrompt: `{basePrompt}
104
+
105
+ ## EXPLORATION MODE
106
+
107
+ You are in **exploration mode**. Your goal is to thoroughly understand the content.
108
+
109
+ Guidelines:
110
+ - **Always start with glob or grep to discover correct paths** \u2014 never assume directory structure
111
+ - Use search and read tools extensively to build understanding
112
+ - Map out structures, dependencies, and patterns
113
+ - Look for conventions, common patterns, and documentation
114
+ - DO NOT modify anything \u2014 only read and analyse
115
+ - Summarise findings clearly with references to specific locations
116
+
117
+ Error recovery:
118
+ - If a tool returns an error (ENOENT, not found, etc.), try a different path or approach
119
+ - Use glob with broader patterns to discover the correct location
120
+ - Keep going until you have a thorough answer \u2014 do not give up after one failure
121
+ - You have multiple steps available \u2014 use them all if needed`,
122
+ temperature: 0.3,
123
+ maxSteps: 30
124
+ };
125
+ var plan = {
126
+ name: "plan",
127
+ description: "Planning mode for analyzing tasks and creating detailed plans",
128
+ allowTools: ["read*", "search*", "glob*", "grep*", "list*", "find*"],
129
+ denyTools: ["write*", "edit*", "delete*", "bash*", "exec*", "run*"],
130
+ systemPrompt: `{basePrompt}
131
+
132
+ ## PLANNING MODE
133
+
134
+ You are in **planning mode**. Your goal is to analyze and plan before implementation.
135
+
136
+ Guidelines:
137
+ - Analyse the task requirements thoroughly
138
+ - Research existing patterns and conventions
139
+ - Identify potential impacts and dependencies
140
+ - Create a clear, step-by-step implementation plan
141
+ - DO NOT implement anything \u2014 only plan and document
142
+ - Output a numbered list of specific, actionable steps`,
143
+ temperature: 0.2,
144
+ maxSteps: 20
145
+ };
146
+ var review = {
147
+ name: "review",
148
+ description: "Thorough review and analysis mode",
149
+ allowTools: ["read*", "grep*", "search*", "glob*", "list*"],
150
+ denyTools: ["*"],
151
+ systemPrompt: `{basePrompt}
152
+
153
+ ## REVIEW MODE
154
+
155
+ You are in **review mode**. Your goal is to perform a thorough analysis.
156
+
157
+ Review checklist:
158
+ - [ ] Logic errors and edge cases
159
+ - [ ] Security vulnerabilities
160
+ - [ ] Performance issues
161
+ - [ ] Error handling and recovery
162
+ - [ ] Clarity and maintainability
163
+ - [ ] Coverage gaps
164
+
165
+ Guidelines:
166
+ - Be thorough and systematic
167
+ - Cite specific locations and details
168
+ - Explain WHY something is an issue
169
+ - Suggest concrete fixes
170
+ - Rate severity: Critical / High / Medium / Low`,
171
+ temperature: 0.1,
172
+ maxSteps: 25
173
+ };
174
+ var quick = {
175
+ name: "quick",
176
+ description: "Fast mode for simple questions and quick operations",
177
+ systemPrompt: `{basePrompt}
178
+
179
+ ## QUICK MODE
180
+
181
+ You are in **quick mode**. Be fast and focused.
182
+
183
+ Guidelines:
184
+ - Answer directly without lengthy explanations
185
+ - Use minimal tool calls (1-3 max)
186
+ - If you can't answer quickly, say so
187
+ - Prioritize speed over thoroughness`,
188
+ temperature: 0,
189
+ maxSteps: 5
190
+ };
191
+ var careful = {
192
+ name: "careful",
193
+ description: "Extra cautious mode for sensitive operations",
194
+ denyTools: ["bash*", "exec*", "run*", "delete*", "remove*"],
195
+ systemPrompt: `{basePrompt}
196
+
197
+ ## CAREFUL MODE
198
+
199
+ You are in **careful mode**. Every action must be verified.
200
+
201
+ Guidelines:
202
+ - Double-check before any file modifications
203
+ - Explain what you're about to do BEFORE doing it
204
+ - Prefer smaller, incremental changes
205
+ - Always verify changes after making them
206
+ - If uncertain, ask for clarification rather than guessing`,
207
+ temperature: 0,
208
+ maxSteps: 50
209
+ };
210
+ var code = {
211
+ name: "code",
212
+ description: "Full-power implementation mode for writing and modifying code",
213
+ systemPrompt: `{basePrompt}
214
+
215
+ ## IMPLEMENTATION MODE
216
+
217
+ You are a focused **implementation agent**. Your goal is to complete the assigned task fully and correctly.
218
+
219
+ Guidelines:
220
+ - Read existing code first to understand context and conventions before making changes
221
+ - Follow the project's existing patterns, naming conventions, and style
222
+ - Make minimal, targeted changes \u2014 do not refactor unrelated code
223
+ - Verify your work: re-read modified files, run tests or lint if available
224
+ - If the task requires multiple files, handle them systematically one at a time
225
+
226
+ Error recovery:
227
+ - If a command fails, read the error output carefully and fix the root cause
228
+ - If a test fails, read the failure details and iterate until it passes
229
+ - If you cannot find a file, use glob or grep to discover the correct path
230
+ - Keep iterating until the task is DONE \u2014 do not stop at a partial solution
231
+ - You have many steps available \u2014 use them all if needed`,
232
+ temperature: 0,
233
+ maxSteps: 50
234
+ };
235
+ var watch = {
236
+ name: "watch",
237
+ description: "Process monitoring mode for running and watching long commands",
238
+ allowTools: ["bash*", "exec*", "run*", "read*", "grep*", "glob*", "list*", "find*"],
239
+ denyTools: ["write*", "edit*", "delete*", "remove*"],
240
+ systemPrompt: `{basePrompt}
241
+
242
+ ## WATCH MODE
243
+
244
+ You are a **process monitor**. Your goal is to execute a command, observe its output, and report the result.
245
+
246
+ Guidelines:
247
+ - Run the command as given \u2014 do not modify or "improve" it
248
+ - Wait for completion and capture the full output
249
+ - Parse the output for success/failure status, error counts, warnings
250
+ - Report a clear summary: what ran, whether it passed, key details
251
+ - If the process fails, include the relevant error output verbatim
252
+ - Do NOT attempt to fix issues \u2014 only observe and report`,
253
+ temperature: 0,
254
+ maxSteps: 10,
255
+ reasoningLevel: "low"
256
+ };
257
+ var Presets = {
258
+ explore,
259
+ plan,
260
+ review,
261
+ quick,
262
+ careful,
263
+ code,
264
+ watch
265
+ };
266
+
267
+ export {
268
+ filterTools,
269
+ applyPreset,
270
+ mergePresets,
271
+ createPreset,
272
+ explore,
273
+ plan,
274
+ review,
275
+ quick,
276
+ careful,
277
+ code,
278
+ watch,
279
+ Presets
280
+ };
@@ -0,0 +1,50 @@
1
+ // src/signal/local.ts
2
+ var LocalSignal = class {
3
+ /** type → Set<handler> for typed subscriptions */
4
+ typed = /* @__PURE__ */ new Map();
5
+ /** handlers that receive every event */
6
+ wildcard = /* @__PURE__ */ new Set();
7
+ on(type, handler) {
8
+ let set = this.typed.get(type);
9
+ if (!set) {
10
+ set = /* @__PURE__ */ new Set();
11
+ this.typed.set(type, set);
12
+ }
13
+ set.add(handler);
14
+ return () => {
15
+ set.delete(handler);
16
+ if (set.size === 0) this.typed.delete(type);
17
+ };
18
+ }
19
+ onAny(handler) {
20
+ this.wildcard.add(handler);
21
+ return () => {
22
+ this.wildcard.delete(handler);
23
+ };
24
+ }
25
+ emit(event) {
26
+ const set = this.typed.get(event.type);
27
+ if (set) {
28
+ for (const fn of set) {
29
+ try {
30
+ fn(event);
31
+ } catch {
32
+ }
33
+ }
34
+ }
35
+ for (const fn of this.wildcard) {
36
+ try {
37
+ fn(event);
38
+ } catch {
39
+ }
40
+ }
41
+ }
42
+ clear() {
43
+ this.typed.clear();
44
+ this.wildcard.clear();
45
+ }
46
+ };
47
+
48
+ export {
49
+ LocalSignal
50
+ };