@leverageaiapps/locus 2.2.1 → 2.2.3
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/agent/agent-loop.d.ts +19 -0
- package/dist/agent/agent-loop.d.ts.map +1 -0
- package/dist/agent/agent-loop.js +936 -0
- package/dist/agent/agent-loop.js.map +1 -0
- package/dist/agent/claude-client.d.ts +48 -0
- package/dist/agent/claude-client.d.ts.map +1 -0
- package/dist/agent/claude-client.js +341 -0
- package/dist/agent/claude-client.js.map +1 -0
- package/dist/agent/compaction.d.ts +31 -0
- package/dist/agent/compaction.d.ts.map +1 -0
- package/dist/agent/compaction.js +295 -0
- package/dist/agent/compaction.js.map +1 -0
- package/dist/agent/local-tools.d.ts +21 -0
- package/dist/agent/local-tools.d.ts.map +1 -0
- package/dist/agent/local-tools.js +130 -0
- package/dist/agent/local-tools.js.map +1 -0
- package/dist/agent/tool-defs.d.ts +17 -0
- package/dist/agent/tool-defs.d.ts.map +1 -0
- package/dist/agent/tool-defs.js +217 -0
- package/dist/agent/tool-defs.js.map +1 -0
- package/dist/agent/types.d.ts +80 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +9 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent/worker-proxy.d.ts +39 -0
- package/dist/agent/worker-proxy.d.ts.map +1 -0
- package/dist/agent/worker-proxy.js +135 -0
- package/dist/agent/worker-proxy.js.map +1 -0
- package/dist/vortex-tunnel.d.ts.map +1 -1
- package/dist/vortex-tunnel.js +119 -18
- package/dist/vortex-tunnel.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Context compaction — token estimation, truncation, and context window management.
|
|
4
|
+
* Uses a provided chat function for summary generation.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.estimateTokens = estimateTokens;
|
|
8
|
+
exports.estimateMessagesTokens = estimateMessagesTokens;
|
|
9
|
+
exports.checkContextWindow = checkContextWindow;
|
|
10
|
+
exports.truncateOversizedToolResults = truncateOversizedToolResults;
|
|
11
|
+
exports.compactBrowserContext = compactBrowserContext;
|
|
12
|
+
exports.repairToolUseResultPairing = repairToolUseResultPairing;
|
|
13
|
+
exports.maybeCompactMessages = maybeCompactMessages;
|
|
14
|
+
exports.emergencyCompactMessages = emergencyCompactMessages;
|
|
15
|
+
// ─── Constants ───────────────────────────────────────────────────
|
|
16
|
+
const MODEL_CONTEXT_WINDOW = 200000;
|
|
17
|
+
const RESERVE_TOKENS = 12000;
|
|
18
|
+
const MIN_USABLE_CONTEXT = 8000;
|
|
19
|
+
const COMPACTION_THRESHOLD = 150000;
|
|
20
|
+
const MAX_TOOL_RESULT_CHARS = 30000;
|
|
21
|
+
const SAFETY_MARGIN = 1.2; // char/3 estimate can undercount; 20% buffer prevents overflow
|
|
22
|
+
// ─── Token Estimation ────────────────────────────────────────────
|
|
23
|
+
function estimateTokens(text) {
|
|
24
|
+
return Math.ceil(text.length / 3);
|
|
25
|
+
}
|
|
26
|
+
function estimateMessagesTokens(messages) {
|
|
27
|
+
return messages.reduce((sum, m) => {
|
|
28
|
+
if (typeof m.content === 'string') {
|
|
29
|
+
return sum + estimateTokens(m.content) + 4;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(m.content)) {
|
|
32
|
+
return sum + estimateTokens(JSON.stringify(m.content)) + 4;
|
|
33
|
+
}
|
|
34
|
+
let msgTokens = 4;
|
|
35
|
+
for (const block of m.content) {
|
|
36
|
+
const b = block;
|
|
37
|
+
if (b.type === 'image' && b.source?.data) {
|
|
38
|
+
msgTokens += Math.min(Math.ceil(b.source.data.length / 1), 1600);
|
|
39
|
+
}
|
|
40
|
+
else if (b.type === 'text') {
|
|
41
|
+
msgTokens += estimateTokens(b.text || '');
|
|
42
|
+
}
|
|
43
|
+
else if (b.type === 'tool_use') {
|
|
44
|
+
msgTokens += estimateTokens(JSON.stringify(b.input || {})) + 20;
|
|
45
|
+
}
|
|
46
|
+
else if (b.type === 'tool_result') {
|
|
47
|
+
if (typeof b.content === 'string') {
|
|
48
|
+
msgTokens += estimateTokens(b.content);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
msgTokens += estimateTokens(JSON.stringify(b.content || ''));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
msgTokens += estimateTokens(JSON.stringify(b));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return sum + msgTokens;
|
|
59
|
+
}, 0);
|
|
60
|
+
}
|
|
61
|
+
// ─── Context Window Check ────────────────────────────────────────
|
|
62
|
+
function checkContextWindow(messages, systemPromptTokens = 0) {
|
|
63
|
+
const rawTokens = estimateMessagesTokens(messages);
|
|
64
|
+
const totalTokens = Math.ceil((rawTokens + systemPromptTokens) * SAFETY_MARGIN);
|
|
65
|
+
const available = MODEL_CONTEXT_WINDOW - totalTokens - RESERVE_TOKENS;
|
|
66
|
+
if (available < MIN_USABLE_CONTEXT) {
|
|
67
|
+
return { ok: false, warn: true, availableTokens: available, totalTokens };
|
|
68
|
+
}
|
|
69
|
+
if (available < 32000) {
|
|
70
|
+
return { ok: true, warn: true, availableTokens: available, totalTokens };
|
|
71
|
+
}
|
|
72
|
+
return { ok: true, warn: false, availableTokens: available, totalTokens };
|
|
73
|
+
}
|
|
74
|
+
// ─── Truncate Oversized Tool Results ─────────────────────────────
|
|
75
|
+
function truncateOversizedToolResults(messages, maxChars = MAX_TOOL_RESULT_CHARS) {
|
|
76
|
+
let truncated = 0;
|
|
77
|
+
for (const msg of messages) {
|
|
78
|
+
if (!Array.isArray(msg.content))
|
|
79
|
+
continue;
|
|
80
|
+
for (const block of msg.content) {
|
|
81
|
+
const b = block;
|
|
82
|
+
if (b.type !== 'tool_result')
|
|
83
|
+
continue;
|
|
84
|
+
if (typeof b.content === 'string' && b.content.length > maxChars) {
|
|
85
|
+
const headChars = Math.floor(maxChars * 0.7);
|
|
86
|
+
const tailChars = Math.floor(maxChars * 0.2);
|
|
87
|
+
const head = b.content.substring(0, headChars);
|
|
88
|
+
const tail = b.content.substring(b.content.length - tailChars);
|
|
89
|
+
const omitted = b.content.length - headChars - tailChars;
|
|
90
|
+
b.content = `${head}\n\n[... ${omitted} chars omitted ...]\n\n${tail}`;
|
|
91
|
+
truncated++;
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(b.content)) {
|
|
94
|
+
for (const nested of b.content) {
|
|
95
|
+
const n = nested;
|
|
96
|
+
if (n.type === 'text' && typeof n.text === 'string' && n.text.length > maxChars) {
|
|
97
|
+
const headChars = Math.floor(maxChars * 0.7);
|
|
98
|
+
const tailChars = Math.floor(maxChars * 0.2);
|
|
99
|
+
const head = n.text.substring(0, headChars);
|
|
100
|
+
const tail = n.text.substring(n.text.length - tailChars);
|
|
101
|
+
const omitted = n.text.length - headChars - tailChars;
|
|
102
|
+
n.text = `${head}\n\n[... ${omitted} chars omitted ...]\n\n${tail}`;
|
|
103
|
+
truncated++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return truncated;
|
|
110
|
+
}
|
|
111
|
+
// ─── Compact Browser Context ─────────────────────────────────────
|
|
112
|
+
function compactBrowserContext(messages, keepRecent = 2) {
|
|
113
|
+
let removed = 0;
|
|
114
|
+
const totalMsgs = messages.length;
|
|
115
|
+
const cutoff = Math.max(0, totalMsgs - keepRecent * 2);
|
|
116
|
+
for (let i = 0; i < cutoff; i++) {
|
|
117
|
+
const msg = messages[i];
|
|
118
|
+
if (!Array.isArray(msg.content))
|
|
119
|
+
continue;
|
|
120
|
+
for (let j = 0; j < msg.content.length; j++) {
|
|
121
|
+
const block = msg.content[j];
|
|
122
|
+
// Strip old image blocks
|
|
123
|
+
if (block.type === 'image') {
|
|
124
|
+
msg.content[j] = { type: 'text', text: '[image removed for context savings]' };
|
|
125
|
+
removed++;
|
|
126
|
+
}
|
|
127
|
+
// Strip old accessibility snapshots from tool results
|
|
128
|
+
if (block.type === 'tool_result' && typeof block.content === 'string') {
|
|
129
|
+
if (block.content.includes('## Accessibility Tree') && block.content.length > 2000) {
|
|
130
|
+
const lines = block.content.split('\n');
|
|
131
|
+
const axIdx = lines.findIndex((l) => l.includes('## Accessibility Tree'));
|
|
132
|
+
if (axIdx >= 0) {
|
|
133
|
+
block.content = lines.slice(0, axIdx).join('\n') + '\n[accessibility snapshot removed for context savings]';
|
|
134
|
+
removed++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return removed;
|
|
141
|
+
}
|
|
142
|
+
// ─── Repair Tool Use / Result Pairing ────────────────────────────
|
|
143
|
+
/**
|
|
144
|
+
* Fix orphaned tool_use or tool_result blocks after compaction.
|
|
145
|
+
* - Removes tool_result blocks whose tool_use_id has no matching tool_use.
|
|
146
|
+
* - Inserts dummy tool_result for tool_use blocks with no matching result.
|
|
147
|
+
* Returns the number of repairs made.
|
|
148
|
+
*/
|
|
149
|
+
function repairToolUseResultPairing(messages) {
|
|
150
|
+
let repaired = 0;
|
|
151
|
+
// Pass 1: Collect all tool_use IDs and tool_result IDs
|
|
152
|
+
const toolUseIds = new Set();
|
|
153
|
+
const toolResultIds = new Set();
|
|
154
|
+
for (const msg of messages) {
|
|
155
|
+
if (!Array.isArray(msg.content))
|
|
156
|
+
continue;
|
|
157
|
+
for (const block of msg.content) {
|
|
158
|
+
const b = block;
|
|
159
|
+
if (b.type === 'tool_use' && b.id)
|
|
160
|
+
toolUseIds.add(b.id);
|
|
161
|
+
if (b.type === 'tool_result' && b.tool_use_id)
|
|
162
|
+
toolResultIds.add(b.tool_use_id);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Pass 2: Remove orphaned tool_result blocks (no matching tool_use)
|
|
166
|
+
for (const msg of messages) {
|
|
167
|
+
if (msg.role !== 'user' || !Array.isArray(msg.content))
|
|
168
|
+
continue;
|
|
169
|
+
const before = msg.content.length;
|
|
170
|
+
msg.content = msg.content.filter((b) => {
|
|
171
|
+
if (b.type === 'tool_result' && b.tool_use_id && !toolUseIds.has(b.tool_use_id)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
});
|
|
176
|
+
repaired += before - msg.content.length;
|
|
177
|
+
// If user message is now empty, add placeholder text
|
|
178
|
+
if (msg.content.length === 0) {
|
|
179
|
+
msg.content.push({ type: 'text', text: '[context compacted]' });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Pass 3: Add dummy results for orphaned tool_use blocks
|
|
183
|
+
for (let i = 0; i < messages.length; i++) {
|
|
184
|
+
const msg = messages[i];
|
|
185
|
+
if (msg.role !== 'assistant' || !Array.isArray(msg.content))
|
|
186
|
+
continue;
|
|
187
|
+
const orphanedIds = [];
|
|
188
|
+
for (const block of msg.content) {
|
|
189
|
+
if (block.type === 'tool_use' && block.id && !toolResultIds.has(block.id)) {
|
|
190
|
+
orphanedIds.push(block.id);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (orphanedIds.length === 0)
|
|
194
|
+
continue;
|
|
195
|
+
// Ensure the next message is a user message with tool_results
|
|
196
|
+
if (i + 1 < messages.length && messages[i + 1].role === 'user') {
|
|
197
|
+
const nextMsg = messages[i + 1];
|
|
198
|
+
if (!Array.isArray(nextMsg.content)) {
|
|
199
|
+
nextMsg.content = [{ type: 'text', text: typeof nextMsg.content === 'string' ? nextMsg.content : '' }];
|
|
200
|
+
}
|
|
201
|
+
for (const id of orphanedIds) {
|
|
202
|
+
nextMsg.content.push({
|
|
203
|
+
type: 'tool_result',
|
|
204
|
+
tool_use_id: id,
|
|
205
|
+
content: '[result unavailable — context was compacted]',
|
|
206
|
+
});
|
|
207
|
+
repaired++;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Insert a new user message with the missing tool_results
|
|
212
|
+
const dummyResults = orphanedIds.map(id => ({
|
|
213
|
+
type: 'tool_result',
|
|
214
|
+
tool_use_id: id,
|
|
215
|
+
content: '[result unavailable — context was compacted]',
|
|
216
|
+
}));
|
|
217
|
+
messages.splice(i + 1, 0, { role: 'user', content: dummyResults });
|
|
218
|
+
repaired += orphanedIds.length;
|
|
219
|
+
i++; // Skip the newly inserted message
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return repaired;
|
|
223
|
+
}
|
|
224
|
+
// ─── Maybe Compact Messages ──────────────────────────────────────
|
|
225
|
+
async function maybeCompactMessages(messages, chatFn, systemPrompt) {
|
|
226
|
+
const rawTokens = estimateMessagesTokens(messages);
|
|
227
|
+
const safeTokens = Math.ceil(rawTokens * SAFETY_MARGIN);
|
|
228
|
+
if (safeTokens < COMPACTION_THRESHOLD)
|
|
229
|
+
return messages;
|
|
230
|
+
console.log(`[Compaction] Token estimate ${rawTokens} (safe: ${safeTokens}) exceeds threshold ${COMPACTION_THRESHOLD}, compacting...`);
|
|
231
|
+
// Keep the last 4 messages (2 turns) intact
|
|
232
|
+
const keepCount = Math.min(4, messages.length);
|
|
233
|
+
const oldMessages = messages.slice(0, messages.length - keepCount);
|
|
234
|
+
const recentMessages = messages.slice(messages.length - keepCount);
|
|
235
|
+
if (oldMessages.length === 0)
|
|
236
|
+
return messages;
|
|
237
|
+
// Build summary of old messages
|
|
238
|
+
const summaryParts = [];
|
|
239
|
+
for (const msg of oldMessages) {
|
|
240
|
+
const content = typeof msg.content === 'string'
|
|
241
|
+
? msg.content
|
|
242
|
+
: msg.content.map((b) => {
|
|
243
|
+
if (b.type === 'text')
|
|
244
|
+
return b.text;
|
|
245
|
+
if (b.type === 'tool_use')
|
|
246
|
+
return `[Used ${b.name}]`;
|
|
247
|
+
if (b.type === 'tool_result')
|
|
248
|
+
return `[Result: ${(typeof b.content === 'string' ? b.content : '').substring(0, 200)}]`;
|
|
249
|
+
return '';
|
|
250
|
+
}).filter(Boolean).join(' ');
|
|
251
|
+
if (content)
|
|
252
|
+
summaryParts.push(`${msg.role}: ${content.substring(0, 500)}`);
|
|
253
|
+
}
|
|
254
|
+
// Ask Claude to summarize via provided chat function
|
|
255
|
+
try {
|
|
256
|
+
const summaryResp = await chatFn([{ role: 'user', content: `Summarize this conversation history concisely (key decisions, results, current state):\n\n${summaryParts.join('\n\n')}` }], {
|
|
257
|
+
systemPrompt: 'You are a concise summarizer. Output only the summary, no preamble.',
|
|
258
|
+
tools: [],
|
|
259
|
+
maxTokens: 2000,
|
|
260
|
+
});
|
|
261
|
+
const summaryText = summaryResp.content
|
|
262
|
+
.filter((b) => b.type === 'text')
|
|
263
|
+
.map((b) => b.text)
|
|
264
|
+
.join('');
|
|
265
|
+
if (summaryText) {
|
|
266
|
+
console.log(`[Compaction] Summarized ${oldMessages.length} messages into ${summaryText.length} chars`);
|
|
267
|
+
return [
|
|
268
|
+
{ role: 'user', content: `[Previous conversation summary]\n${summaryText}` },
|
|
269
|
+
{ role: 'assistant', content: 'Understood, I have the context from our previous conversation. How can I continue helping?' },
|
|
270
|
+
...recentMessages,
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
console.error(`[Compaction] Summary failed: ${err.message}`);
|
|
276
|
+
}
|
|
277
|
+
// Fallback: just truncate old messages
|
|
278
|
+
return recentMessages;
|
|
279
|
+
}
|
|
280
|
+
// ─── Emergency Compact ───────────────────────────────────────────
|
|
281
|
+
function emergencyCompactMessages(messages) {
|
|
282
|
+
if (messages.length <= 4)
|
|
283
|
+
return messages;
|
|
284
|
+
// Keep first message + last 4 messages
|
|
285
|
+
const first = messages[0];
|
|
286
|
+
const recent = messages.slice(-4);
|
|
287
|
+
console.log(`[Compaction] Emergency: dropped ${messages.length - 5} middle messages`);
|
|
288
|
+
return [
|
|
289
|
+
first,
|
|
290
|
+
{ role: 'user', content: '[Earlier conversation messages were removed due to context limits. Continue from the most recent context.]' },
|
|
291
|
+
{ role: 'assistant', content: 'Understood. Continuing from the recent context.' },
|
|
292
|
+
...recent,
|
|
293
|
+
];
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=compaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/agent/compaction.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAqBH,wCAEC;AAED,wDA6BC;AAID,gDAeC;AAID,oEAuCC;AAID,sDA8BC;AAUD,gEA0EC;AAID,oDA8DC;AAID,4DAaC;AAnTD,oEAAoE;AAEpE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,aAAa,GAAG,GAAG,CAAC,CAAC,+DAA+D;AAE1F,oEAAoE;AAEpE,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,sBAAsB,CAAC,QAAmB;IACxD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAChC,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YAClC,OAAO,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,OAAO,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,S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AG,MAAM;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local tool execution — bash, file operations, search.
|
|
3
|
+
* These run directly on the user's Mac filesystem with zero network latency.
|
|
4
|
+
*
|
|
5
|
+
* Adapted from container-agent/src/local-tools.ts:
|
|
6
|
+
* - cwd: workingDirectory || HOME (not /root)
|
|
7
|
+
* - No DISPLAY env (no X11/Docker)
|
|
8
|
+
* - Removed: ensureDesktop, refreshDesktopIfNeeded (no X11/VNC)
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolExecResult } from './types';
|
|
11
|
+
export declare function setWorkingDirectory(dir: string): void;
|
|
12
|
+
export declare function executeBash(command: string): Promise<ToolExecResult>;
|
|
13
|
+
export declare function executeWriteFile(filePath: string, content: string): Promise<ToolExecResult>;
|
|
14
|
+
export declare function executeReadFile(filePath: string): Promise<ToolExecResult>;
|
|
15
|
+
export declare function executeShowFile(filePath: string): Promise<ToolExecResult>;
|
|
16
|
+
export declare function executeSearchFiles(pattern: string, directory?: string): Promise<ToolExecResult>;
|
|
17
|
+
export declare function readFileBase64(filePath: string): Promise<{
|
|
18
|
+
base64: string;
|
|
19
|
+
size: number;
|
|
20
|
+
} | null>;
|
|
21
|
+
//# sourceMappingURL=local-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-tools.d.ts","sourceRoot":"","sources":["../../src/agent/local-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAQ9C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAErD;AAMD,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA6C1E;AAID,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,cAAc,CAAC,CASzB;AAID,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAO/E;AAID,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAO/E;AAID,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,cAAc,CAAC,CAYzB;AAID,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAOvG"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Local tool execution — bash, file operations, search.
|
|
4
|
+
* These run directly on the user's Mac filesystem with zero network latency.
|
|
5
|
+
*
|
|
6
|
+
* Adapted from container-agent/src/local-tools.ts:
|
|
7
|
+
* - cwd: workingDirectory || HOME (not /root)
|
|
8
|
+
* - No DISPLAY env (no X11/Docker)
|
|
9
|
+
* - Removed: ensureDesktop, refreshDesktopIfNeeded (no X11/VNC)
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setWorkingDirectory = setWorkingDirectory;
|
|
13
|
+
exports.executeBash = executeBash;
|
|
14
|
+
exports.executeWriteFile = executeWriteFile;
|
|
15
|
+
exports.executeReadFile = executeReadFile;
|
|
16
|
+
exports.executeShowFile = executeShowFile;
|
|
17
|
+
exports.executeSearchFiles = executeSearchFiles;
|
|
18
|
+
exports.readFileBase64 = readFileBase64;
|
|
19
|
+
const node_child_process_1 = require("node:child_process");
|
|
20
|
+
const promises_1 = require("node:fs/promises");
|
|
21
|
+
const node_path_1 = require("node:path");
|
|
22
|
+
const node_util_1 = require("node:util");
|
|
23
|
+
const exec = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
24
|
+
// ─── Module-level working directory (set by agent loop) ──────────
|
|
25
|
+
let currentWorkingDirectory = process.env.HOME || '/tmp';
|
|
26
|
+
function setWorkingDirectory(dir) {
|
|
27
|
+
currentWorkingDirectory = dir;
|
|
28
|
+
}
|
|
29
|
+
// ─── Bash ────────────────────────────────────────────────────────
|
|
30
|
+
const LONG_RUNNING_RE = /apt|pip|npm|yarn|pdflatex|xelatex|lualatex|latex|make|cargo|gcc|g\+\+|docker|wget|curl.*-[oO]|git clone|bundle|composer|mvn|gradle/i;
|
|
31
|
+
async function executeBash(command) {
|
|
32
|
+
const isLong = LONG_RUNNING_RE.test(command);
|
|
33
|
+
const timeoutMs = isLong ? 300000 : 120000;
|
|
34
|
+
const cwd = currentWorkingDirectory;
|
|
35
|
+
try {
|
|
36
|
+
let stdout, stderr;
|
|
37
|
+
if (command.includes('<<')) {
|
|
38
|
+
// Heredoc: write to temp script file
|
|
39
|
+
const scriptPath = `/tmp/_cmd_${Date.now()}.sh`;
|
|
40
|
+
await (0, promises_1.writeFile)(scriptPath, `#!/bin/bash\ncd "${cwd}"\n${command}\n`);
|
|
41
|
+
const result = await exec(`bash ${scriptPath} && rm -f ${scriptPath}`, {
|
|
42
|
+
cwd,
|
|
43
|
+
timeout: timeoutMs,
|
|
44
|
+
env: process.env,
|
|
45
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
46
|
+
});
|
|
47
|
+
stdout = result.stdout;
|
|
48
|
+
stderr = result.stderr;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const result = await exec(command, {
|
|
52
|
+
cwd,
|
|
53
|
+
timeout: timeoutMs,
|
|
54
|
+
env: process.env,
|
|
55
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
56
|
+
});
|
|
57
|
+
stdout = result.stdout;
|
|
58
|
+
stderr = result.stderr;
|
|
59
|
+
}
|
|
60
|
+
const output = (stdout || '') + (stderr ? '\n' + stderr : '');
|
|
61
|
+
return { output, isError: false };
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
// exec returns error with stdout/stderr when exit code != 0
|
|
65
|
+
const stdout = err.stdout || '';
|
|
66
|
+
const stderr = err.stderr || '';
|
|
67
|
+
let output = (stdout + (stderr ? '\n' + stderr : '')).trim();
|
|
68
|
+
if (!output) {
|
|
69
|
+
output = err.killed
|
|
70
|
+
? `Command timed out after ${timeoutMs / 1000} seconds`
|
|
71
|
+
: `Command exited with code ${err.code || 1}: ${err.message}`;
|
|
72
|
+
}
|
|
73
|
+
return { output, isError: true };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// ─── Write File ──────────────────────────────────────────────────
|
|
77
|
+
async function executeWriteFile(filePath, content) {
|
|
78
|
+
try {
|
|
79
|
+
// Ensure parent directory exists
|
|
80
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(filePath), { recursive: true });
|
|
81
|
+
await (0, promises_1.writeFile)(filePath, content, 'utf-8');
|
|
82
|
+
return { output: `File written: ${filePath}`, isError: false };
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
return { output: `Failed to write file: ${err.message}`, isError: true };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// ─── Read File ───────────────────────────────────────────────────
|
|
89
|
+
async function executeReadFile(filePath) {
|
|
90
|
+
try {
|
|
91
|
+
const content = await (0, promises_1.readFile)(filePath, 'utf-8');
|
|
92
|
+
return { output: content, isError: false };
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return { output: `Failed to read file: ${err.message}`, isError: true };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// ─── Show File (sends file to user for download via R2) ──────────
|
|
99
|
+
async function executeShowFile(filePath) {
|
|
100
|
+
try {
|
|
101
|
+
await (0, promises_1.stat)(filePath); // Check file exists
|
|
102
|
+
return { output: `File ready to download: ${filePath}`, isError: false };
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return { output: `File not found: ${err.message}`, isError: true };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// ─── Search Files ────────────────────────────────────────────────
|
|
109
|
+
async function executeSearchFiles(pattern, directory) {
|
|
110
|
+
const searchDir = directory || currentWorkingDirectory;
|
|
111
|
+
try {
|
|
112
|
+
const { stdout } = await exec(`find ${searchDir} -maxdepth 5 -name "${pattern}" -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null | head -50`, { cwd: searchDir, timeout: 30000 });
|
|
113
|
+
const output = stdout.trim() || 'No files found.';
|
|
114
|
+
return { output, isError: false };
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return { output: `Search failed: ${err.message}`, isError: true };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// ─── Read file as base64 (for R2 upload) ─────────────────────────
|
|
121
|
+
async function readFileBase64(filePath) {
|
|
122
|
+
try {
|
|
123
|
+
const buf = await (0, promises_1.readFile)(filePath);
|
|
124
|
+
return { base64: buf.toString('base64'), size: buf.length };
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=local-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-tools.js","sourceRoot":"","sources":["../../src/agent/local-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAcH,kDAEC;AAMD,kCA6CC;AAID,4CAYC;AAID,0CAOC;AAID,0CAOC;AAID,gDAeC;AAID,wCAOC;AArID,2DAAoD;AACpD,+CAAoE;AACpE,yCAAoC;AACpC,yCAAsC;AAGtC,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,yBAAM,CAAC,CAAC;AAE/B,oEAAoE;AAEpE,IAAI,uBAAuB,GAAW,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC;AAEjE,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,u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F,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,IAAI,iBAAiB,CAAC;QAClD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,kBAAkB,GAAG,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACpE,CAAC;AACH,CAAC;AAED,oEAAoE;AAE7D,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,CAAC,CAAC;QACrC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Definitions for PC Agent — adapted from container-agent/src/tool-defs.ts
|
|
3
|
+
*
|
|
4
|
+
* Differences from sandbox tools:
|
|
5
|
+
* - Removed: browser_action (no browser automation on Mac)
|
|
6
|
+
* - Removed: request_human_help (no VNC desktop)
|
|
7
|
+
* - Updated descriptions: "user's computer" instead of "sandbox"
|
|
8
|
+
*/
|
|
9
|
+
import type { Tool } from './claude-client';
|
|
10
|
+
export declare const PC_TOOLS: Tool[];
|
|
11
|
+
export declare const WEB_SEARCH_SERVER_TOOL: Tool;
|
|
12
|
+
export declare const WEB_FETCH_SERVER_TOOL: Tool;
|
|
13
|
+
/**
|
|
14
|
+
* Build the full tools array, excluding specified tool names.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildToolList(excludeTools?: string[]): Tool[];
|
|
17
|
+
//# sourceMappingURL=tool-defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-defs.d.ts","sourceRoot":"","sources":["../../src/agent/tool-defs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,eAAO,MAAM,QAAQ,EAAE,IAAI,EAmL1B,CAAC;AAIF,eAAO,MAAM,sBAAsB,EAAE,IAIpC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,IAInC,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,GAAE,MAAM,EAAO,GAAG,IAAI,EAAE,CAQjE"}
|