@x-code-cli/core 0.2.0 → 0.2.2
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/api-errors.js +1 -1
- package/dist/agent/api-errors.js.map +1 -1
- package/dist/agent/compression.d.ts +25 -0
- package/dist/agent/compression.d.ts.map +1 -0
- package/dist/agent/compression.js +105 -0
- package/dist/agent/compression.js.map +1 -0
- package/dist/agent/diff.js.map +1 -1
- package/dist/agent/file-ingest.d.ts +14 -0
- package/dist/agent/file-ingest.d.ts.map +1 -1
- package/dist/agent/file-ingest.js +125 -34
- package/dist/agent/file-ingest.js.map +1 -1
- package/dist/agent/light-compact.d.ts.map +1 -1
- package/dist/agent/light-compact.js +0 -19
- package/dist/agent/light-compact.js.map +1 -1
- package/dist/agent/loop-guard.d.ts.map +1 -1
- package/dist/agent/loop-guard.js.map +1 -1
- package/dist/agent/loop-state.d.ts.map +1 -1
- package/dist/agent/loop-state.js +8 -1
- package/dist/agent/loop-state.js.map +1 -1
- package/dist/agent/loop.d.ts +2 -3
- package/dist/agent/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +16 -92
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/messages.d.ts +9 -0
- package/dist/agent/messages.d.ts.map +1 -1
- package/dist/agent/messages.js +15 -0
- package/dist/agent/messages.js.map +1 -1
- package/dist/agent/plan-storage.d.ts.map +1 -1
- package/dist/agent/plan-storage.js +1 -1
- package/dist/agent/plan-storage.js.map +1 -1
- package/dist/agent/plan-tools.d.ts +8 -0
- package/dist/agent/plan-tools.d.ts.map +1 -0
- package/dist/agent/plan-tools.js +150 -0
- package/dist/agent/plan-tools.js.map +1 -0
- package/dist/agent/provider-compat.d.ts.map +1 -1
- package/dist/agent/provider-compat.js.map +1 -1
- package/dist/agent/sub-agents/built-in.d.ts.map +1 -1
- package/dist/agent/sub-agents/built-in.js +41 -15
- package/dist/agent/sub-agents/built-in.js.map +1 -1
- package/dist/agent/sub-agents/loader.d.ts.map +1 -1
- package/dist/agent/sub-agents/loader.js.map +1 -1
- package/dist/agent/sub-agents/runner.d.ts.map +1 -1
- package/dist/agent/sub-agents/runner.js +12 -8
- package/dist/agent/sub-agents/runner.js.map +1 -1
- package/dist/agent/tool-execution.d.ts +34 -2
- package/dist/agent/tool-execution.d.ts.map +1 -1
- package/dist/agent/tool-execution.js +363 -352
- package/dist/agent/tool-execution.js.map +1 -1
- package/dist/agent/tool-result-sanitize.d.ts +21 -7
- package/dist/agent/tool-result-sanitize.d.ts.map +1 -1
- package/dist/agent/tool-result-sanitize.js +56 -30
- package/dist/agent/tool-result-sanitize.js.map +1 -1
- package/dist/agent/vision-fallback.d.ts.map +1 -1
- package/dist/agent/vision-fallback.js +3 -14
- package/dist/agent/vision-fallback.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/permissions/index.d.ts +13 -6
- package/dist/permissions/index.d.ts.map +1 -1
- package/dist/permissions/index.js +57 -6
- package/dist/permissions/index.js.map +1 -1
- package/dist/permissions/session-store.d.ts +74 -0
- package/dist/permissions/session-store.d.ts.map +1 -0
- package/dist/permissions/session-store.js +293 -0
- package/dist/permissions/session-store.js.map +1 -0
- package/dist/providers/cache-control.d.ts.map +1 -1
- package/dist/providers/cache-control.js +0 -29
- package/dist/providers/cache-control.js.map +1 -1
- package/dist/providers/thinking.d.ts.map +1 -1
- package/dist/providers/thinking.js +2 -6
- package/dist/providers/thinking.js.map +1 -1
- package/dist/tools/ask-user.d.ts.map +1 -1
- package/dist/tools/ask-user.js +17 -7
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +8 -1
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +9 -2
- package/dist/tools/glob.js.map +1 -1
- package/dist/tools/grep.d.ts +1 -1
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +29 -6
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/list-dir.d.ts.map +1 -1
- package/dist/tools/list-dir.js.map +1 -1
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +78 -36
- package/dist/tools/read-file.js.map +1 -1
- package/dist/tools/shell-provider.d.ts +1 -0
- package/dist/tools/shell-provider.d.ts.map +1 -1
- package/dist/tools/shell-provider.js +7 -0
- package/dist/tools/shell-provider.js.map +1 -1
- package/dist/tools/shell-utils.d.ts.map +1 -1
- package/dist/tools/shell-utils.js +45 -2
- package/dist/tools/shell-utils.js.map +1 -1
- package/dist/tools/shell.d.ts.map +1 -1
- package/dist/tools/shell.js +15 -1
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/task.d.ts.map +1 -1
- package/dist/tools/task.js +4 -4
- package/dist/tools/task.js.map +1 -1
- package/dist/tools/todo-write.d.ts.map +1 -1
- package/dist/tools/todo-write.js.map +1 -1
- package/dist/tools/web-fetch.d.ts +2 -0
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +92 -27
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/write-file.d.ts.map +1 -1
- package/dist/tools/write-file.js +7 -1
- package/dist/tools/write-file.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/lru-cache.d.ts +17 -0
- package/dist/utils/lru-cache.d.ts.map +1 -0
- package/dist/utils/lru-cache.js +40 -0
- package/dist/utils/lru-cache.js.map +1 -0
- package/dist/utils/media-type.d.ts +5 -0
- package/dist/utils/media-type.d.ts.map +1 -0
- package/dist/utils/media-type.js +19 -0
- package/dist/utils/media-type.js.map +1 -0
- package/dist/utils/message-helpers.d.ts +6 -0
- package/dist/utils/message-helpers.d.ts.map +1 -0
- package/dist/utils/message-helpers.js +14 -0
- package/dist/utils/message-helpers.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// @x-code-cli/core — Permission memory with disk persistence.
|
|
2
|
+
//
|
|
3
|
+
// When a user approves a tool call with "don't ask again", the decision
|
|
4
|
+
// is stored as an AllowRule both in-memory AND on disk at
|
|
5
|
+
// `.x-code/local/permissions.json`. On next startup the persisted rules
|
|
6
|
+
// are loaded so approvals survive across sessions.
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { XCODE_DIR } from '../utils.js';
|
|
10
|
+
// Env-var assignment prefix: VAR=value (unquoted, safe chars only).
|
|
11
|
+
const ENV_VAR_RE = /^[A-Za-z_]\w*=[A-Za-z0-9_./:@-]*\s+/;
|
|
12
|
+
// Detects the `powershell` / `powershell.exe` / `pwsh` invocation prefix.
|
|
13
|
+
// We don't try to match the WHOLE shape here — agents use a lot of flag
|
|
14
|
+
// variations (`-NoProfile`, `-ExecutionPolicy Bypass`, `-File foo.ps1`,
|
|
15
|
+
// bare invocation without `-Command`). Just identify the launcher; the
|
|
16
|
+
// extractor below scans past flags to find the inner command.
|
|
17
|
+
const POWERSHELL_LAUNCHER_RE = /^(?:powershell(?:\.exe)?|pwsh(?:\.exe)?)\b/i;
|
|
18
|
+
// Extracts the first cmdlet or command name from inside quoted PowerShell.
|
|
19
|
+
// Handles Verb-Noun cmdlets (Get-Process) and plain commands (git, npm).
|
|
20
|
+
const PS_INNER_CMD_RE = /["']?\s*(?:&\s*\{?\s*)?([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)+|[a-z][a-z0-9._-]*)/;
|
|
21
|
+
/**
|
|
22
|
+
* Extract a command prefix suitable for prefix-match rules.
|
|
23
|
+
* Returns `null` when no meaningful prefix can be derived.
|
|
24
|
+
*
|
|
25
|
+
* 'git commit -m "fix"' → 'git commit'
|
|
26
|
+
* 'pnpm run build' → 'pnpm run'
|
|
27
|
+
* 'npm install lodash' → 'npm install'
|
|
28
|
+
* 'NODE_ENV=prod npm run dev' → 'npm run'
|
|
29
|
+
* 'powershell -Command "Get-CimInstance ..."' → 'Get-CimInstance'
|
|
30
|
+
* 'powershell -NoProfile -Command "Get-CimInstance ..."' → 'Get-CimInstance'
|
|
31
|
+
* 'powershell -ExecutionPolicy Bypass -c "git status"' → 'git'
|
|
32
|
+
* 'pwsh -Command "& { Get-Process }"' → 'Get-Process'
|
|
33
|
+
* 'powershell -Command Get-Date' → 'Get-Date'
|
|
34
|
+
* 'ls -la' → null
|
|
35
|
+
* '' → null
|
|
36
|
+
*/
|
|
37
|
+
export function extractCommandPrefix(command) {
|
|
38
|
+
let cmd = command.trim();
|
|
39
|
+
while (ENV_VAR_RE.test(cmd)) {
|
|
40
|
+
cmd = cmd.replace(ENV_VAR_RE, '');
|
|
41
|
+
}
|
|
42
|
+
// PowerShell: scan past launcher + flags to find the inner command.
|
|
43
|
+
// Agents emit varied flag combinations (`-NoProfile`, `-ExecutionPolicy
|
|
44
|
+
// Bypass`, `-c` vs `-Command`, etc.) — strip them all, then extract the
|
|
45
|
+
// first cmdlet/command from the remaining string. The earlier regex-based
|
|
46
|
+
// approach only matched a fixed flag layout and produced null for the
|
|
47
|
+
// common `-NoProfile` case, hiding the "don't ask again" option.
|
|
48
|
+
if (POWERSHELL_LAUNCHER_RE.test(cmd)) {
|
|
49
|
+
const tokens = cmd.split(/\s+/).filter(Boolean);
|
|
50
|
+
let i = 1; // skip launcher
|
|
51
|
+
while (i < tokens.length) {
|
|
52
|
+
const tok = tokens[i];
|
|
53
|
+
if (!tok.startsWith('-'))
|
|
54
|
+
break;
|
|
55
|
+
const lower = tok.toLowerCase();
|
|
56
|
+
// -Command / -c ends the flag run — what follows is the actual command
|
|
57
|
+
if (lower === '-command' || lower === '-c') {
|
|
58
|
+
i++;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
// -File <path> — no useful prefix; bail.
|
|
62
|
+
if (lower === '-file')
|
|
63
|
+
return null;
|
|
64
|
+
// Flags that take an argument (consume next token too).
|
|
65
|
+
if (lower === '-executionpolicy' ||
|
|
66
|
+
lower === '-encodedcommand' ||
|
|
67
|
+
lower === '-inputformat' ||
|
|
68
|
+
lower === '-outputformat' ||
|
|
69
|
+
lower === '-version' ||
|
|
70
|
+
lower === '-windowstyle' ||
|
|
71
|
+
lower === '-configurationname' ||
|
|
72
|
+
lower === '-mta' ||
|
|
73
|
+
lower === '-sta') {
|
|
74
|
+
i += 2;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Boolean flags (no argument): -NoProfile, -NoLogo, -NonInteractive, etc.
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
if (i >= tokens.length)
|
|
81
|
+
return null;
|
|
82
|
+
const inner = tokens.slice(i).join(' ');
|
|
83
|
+
const m = PS_INNER_CMD_RE.exec(inner);
|
|
84
|
+
if (m?.[1])
|
|
85
|
+
return m[1];
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const tokens = cmd.split(/\s+/).filter(Boolean);
|
|
89
|
+
if (tokens.length < 2)
|
|
90
|
+
return null;
|
|
91
|
+
const second = tokens[1];
|
|
92
|
+
if (/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(second)) {
|
|
93
|
+
return `${tokens[0]} ${second}`;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Generate the display label for the "don't ask again" option.
|
|
99
|
+
* Returns `null` only for tools where a "don't ask again" affordance
|
|
100
|
+
* makes no sense (enterPlanMode toggles a mode, not a recurring action).
|
|
101
|
+
*
|
|
102
|
+
* Shell with derivable prefix: `git commit:*`
|
|
103
|
+
* Shell without derivable prefix: `this exact command` (exact-match rule —
|
|
104
|
+
* covers Windows-style commands like `findstr /n …`, `cmd /c …`,
|
|
105
|
+
* `dir /b`, where the second token is a `/flag` or path that fails
|
|
106
|
+
* the prefix regex; without this fallback the user gets only Yes/No
|
|
107
|
+
* forever for repeated identical commands).
|
|
108
|
+
* Write tools (writeFile / edit): `all edits this session` (session-only)
|
|
109
|
+
*/
|
|
110
|
+
export function suggestRuleLabel(toolName, input) {
|
|
111
|
+
if (toolName === 'enterPlanMode')
|
|
112
|
+
return null;
|
|
113
|
+
if (toolName === 'shell') {
|
|
114
|
+
const cmd = input.command ?? '';
|
|
115
|
+
const prefix = extractCommandPrefix(cmd);
|
|
116
|
+
if (prefix)
|
|
117
|
+
return `${prefix}:*`;
|
|
118
|
+
return 'this exact command';
|
|
119
|
+
}
|
|
120
|
+
return 'all edits this session';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Build the AllowRule for a "don't ask again" approval.
|
|
124
|
+
*
|
|
125
|
+
* - Shell with derivable prefix (e.g. `git commit`) → prefix rule, persisted
|
|
126
|
+
* - Shell without derivable prefix → exact-match rule,
|
|
127
|
+
* persisted (mirrors Claude Code's `suggestionForExactCommand`
|
|
128
|
+
* fallback in `bashPermissions.ts`). Less reusable than a prefix rule
|
|
129
|
+
* (any arg change breaks the match) but at least suppresses repeated
|
|
130
|
+
* identical invocations — better than "Yes/No forever". The matcher
|
|
131
|
+
* compares against `stripEnvVars(cmd)` so leading `NODE_ENV=…` etc.
|
|
132
|
+
* don't defeat the rule.
|
|
133
|
+
* - writeFile / edit → tool-wide allow,
|
|
134
|
+
* session-only (matches Claude Code).
|
|
135
|
+
*
|
|
136
|
+
* `persist` indicates whether the rule should be saved to disk. Write
|
|
137
|
+
* tools return persist=false; everything else returns persist=true.
|
|
138
|
+
* Returns `null` only for the very few cases where no rule shape applies
|
|
139
|
+
* (currently nothing — kept in the signature so callers stay defensive).
|
|
140
|
+
*/
|
|
141
|
+
export function buildAllowRule(toolName, input) {
|
|
142
|
+
if (toolName === 'shell') {
|
|
143
|
+
const cmd = input.command ?? '';
|
|
144
|
+
const prefix = extractCommandPrefix(cmd);
|
|
145
|
+
if (prefix) {
|
|
146
|
+
return { rule: { tool: toolName, pattern: prefix, type: 'prefix' }, persist: true };
|
|
147
|
+
}
|
|
148
|
+
// Strip env-var prefixes so a `NODE_ENV=prod foo …` approval works
|
|
149
|
+
// for plain `foo …` later — same key the matcher compares against.
|
|
150
|
+
const exact = stripEnvVars(cmd);
|
|
151
|
+
if (!exact)
|
|
152
|
+
return null;
|
|
153
|
+
return { rule: { tool: toolName, pattern: exact, type: 'exact' }, persist: true };
|
|
154
|
+
}
|
|
155
|
+
return { rule: { tool: toolName, pattern: '*', type: 'tool' }, persist: false };
|
|
156
|
+
}
|
|
157
|
+
function stripEnvVars(command) {
|
|
158
|
+
let cmd = command.trim();
|
|
159
|
+
while (ENV_VAR_RE.test(cmd)) {
|
|
160
|
+
cmd = cmd.replace(ENV_VAR_RE, '');
|
|
161
|
+
}
|
|
162
|
+
return cmd.trim();
|
|
163
|
+
}
|
|
164
|
+
// ─── Serialization helpers ───
|
|
165
|
+
function ruleToString(rule) {
|
|
166
|
+
if (rule.type === 'tool')
|
|
167
|
+
return `${rule.tool}:*`;
|
|
168
|
+
if (rule.type === 'prefix')
|
|
169
|
+
return `${rule.tool}:${rule.pattern}:*`;
|
|
170
|
+
return `${rule.tool}:=${rule.pattern}`;
|
|
171
|
+
}
|
|
172
|
+
function parseRuleString(s) {
|
|
173
|
+
// tool:* → tool-wide
|
|
174
|
+
const toolWide = s.match(/^([^:]+):\*$/);
|
|
175
|
+
if (toolWide)
|
|
176
|
+
return { tool: toolWide[1], pattern: '*', type: 'tool' };
|
|
177
|
+
// tool:prefix:* → prefix match
|
|
178
|
+
const prefix = s.match(/^([^:]+):(.+):\*$/);
|
|
179
|
+
if (prefix)
|
|
180
|
+
return { tool: prefix[1], pattern: prefix[2], type: 'prefix' };
|
|
181
|
+
// tool:=exact → exact match
|
|
182
|
+
const exact = s.match(/^([^:]+):=(.+)$/);
|
|
183
|
+
if (exact)
|
|
184
|
+
return { tool: exact[1], pattern: exact[2], type: 'exact' };
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
function getPermissionsPath(cwd) {
|
|
188
|
+
return path.join(cwd, XCODE_DIR, 'local', 'permissions.json');
|
|
189
|
+
}
|
|
190
|
+
// ─── Store ───
|
|
191
|
+
class SessionPermissionStore {
|
|
192
|
+
rules = [];
|
|
193
|
+
addRule(rule) {
|
|
194
|
+
const exists = this.rules.some((r) => r.tool === rule.tool && r.pattern === rule.pattern && r.type === rule.type);
|
|
195
|
+
if (!exists)
|
|
196
|
+
this.rules.push(rule);
|
|
197
|
+
}
|
|
198
|
+
matches(toolName, input) {
|
|
199
|
+
for (const rule of this.rules) {
|
|
200
|
+
if (rule.tool !== toolName)
|
|
201
|
+
continue;
|
|
202
|
+
if (rule.type === 'tool')
|
|
203
|
+
return true;
|
|
204
|
+
if (toolName === 'shell') {
|
|
205
|
+
const cmd = input.command ?? '';
|
|
206
|
+
const prefix = extractCommandPrefix(cmd);
|
|
207
|
+
if (rule.type === 'exact' && stripEnvVars(cmd) === rule.pattern)
|
|
208
|
+
return true;
|
|
209
|
+
if (rule.type === 'prefix' && prefix) {
|
|
210
|
+
if (prefix === rule.pattern)
|
|
211
|
+
return true;
|
|
212
|
+
if (prefix.startsWith(rule.pattern + ' '))
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
clear() {
|
|
220
|
+
this.rules = [];
|
|
221
|
+
}
|
|
222
|
+
get size() {
|
|
223
|
+
return this.rules.length;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const store = new SessionPermissionStore();
|
|
227
|
+
export function addSessionAllowRule(rule) {
|
|
228
|
+
store.addRule(rule);
|
|
229
|
+
}
|
|
230
|
+
export function sessionRulesMatch(toolName, input) {
|
|
231
|
+
return store.matches(toolName, input);
|
|
232
|
+
}
|
|
233
|
+
export function clearSessionRules() {
|
|
234
|
+
store.clear();
|
|
235
|
+
}
|
|
236
|
+
// ─── Disk persistence ───
|
|
237
|
+
/**
|
|
238
|
+
* Load persisted permission rules from `.x-code/local/permissions.json`
|
|
239
|
+
* into the in-memory store. Safe to call multiple times (deduplicates).
|
|
240
|
+
* Silently no-ops if the file doesn't exist or is malformed.
|
|
241
|
+
*/
|
|
242
|
+
export function loadPersistedRules(cwd) {
|
|
243
|
+
const filePath = getPermissionsPath(cwd);
|
|
244
|
+
let raw;
|
|
245
|
+
try {
|
|
246
|
+
raw = fs.readFileSync(filePath, 'utf-8');
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
let data;
|
|
252
|
+
try {
|
|
253
|
+
data = JSON.parse(raw);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (!Array.isArray(data.allow))
|
|
259
|
+
return;
|
|
260
|
+
for (const entry of data.allow) {
|
|
261
|
+
if (typeof entry !== 'string')
|
|
262
|
+
continue;
|
|
263
|
+
const rule = parseRuleString(entry);
|
|
264
|
+
if (rule)
|
|
265
|
+
store.addRule(rule);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Persist a new rule to `.x-code/local/permissions.json`.
|
|
270
|
+
* Creates the file if it doesn't exist. Appends without duplicating.
|
|
271
|
+
*/
|
|
272
|
+
export function persistRule(cwd, rule) {
|
|
273
|
+
const filePath = getPermissionsPath(cwd);
|
|
274
|
+
const ruleStr = ruleToString(rule);
|
|
275
|
+
const data = { allow: [] };
|
|
276
|
+
try {
|
|
277
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
278
|
+
const parsed = JSON.parse(raw);
|
|
279
|
+
if (Array.isArray(parsed.allow)) {
|
|
280
|
+
data.allow = parsed.allow.filter((s) => typeof s === 'string');
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
// File doesn't exist or is malformed — start fresh.
|
|
285
|
+
}
|
|
286
|
+
if (data.allow.includes(ruleStr))
|
|
287
|
+
return;
|
|
288
|
+
data.allow.push(ruleStr);
|
|
289
|
+
const dir = path.dirname(filePath);
|
|
290
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
291
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/permissions/session-store.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,wEAAwE;AACxE,0DAA0D;AAC1D,wEAAwE;AACxE,mDAAmD;AACnD,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAQvC,oEAAoE;AACpE,MAAM,UAAU,GAAG,qCAAqC,CAAA;AAExD,0EAA0E;AAC1E,wEAAwE;AACxE,wEAAwE;AACxE,uEAAuE;AACvE,8DAA8D;AAC9D,MAAM,sBAAsB,GAAG,6CAA6C,CAAA;AAE5E,2EAA2E;AAC3E,yEAAyE;AACzE,MAAM,eAAe,GAAG,mFAAmF,CAAA;AAE3G;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAA;IACxB,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IACnC,CAAC;IAED,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,0EAA0E;IAC1E,sEAAsE;IACtE,iEAAiE;IACjE,IAAI,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,GAAG,CAAC,KAA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,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;IACtD,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAM;IAExC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAExB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACtC,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-control.d.ts","sourceRoot":"","sources":["../../src/providers/cache-control.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache-control.d.ts","sourceRoot":"","sources":["../../src/providers/cache-control.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAWtC,MAAM,WAAW,gBAAgB;IAC/B;uDACmD;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,qCAAqC;IACrC,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf;sDACkD;IAClD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC;;oDAEgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C;AAyBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,kBAAkB,CAkC5E"}
|
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
// @x-code-cli/core — Per-provider prompt caching
|
|
2
|
-
//
|
|
3
|
-
// Prompt caching is the single biggest lever on per-session cost. All current
|
|
4
|
-
// providers offer it, but the activation protocol differs:
|
|
5
|
-
//
|
|
6
|
-
// Anthropic — set `cacheControl: { type: 'ephemeral' }` on the SYSTEM
|
|
7
|
-
// message and the LAST two non-system messages (three
|
|
8
|
-
// breakpoints total, under the API's limit of four). The
|
|
9
|
-
// content at each breakpoint is cached server-side with a
|
|
10
|
-
// 5-minute TTL; subsequent requests that share the exact
|
|
11
|
-
// prefix hit the cache and only pay for the uncached tail.
|
|
12
|
-
//
|
|
13
|
-
// OpenAI — automatic prefix caching, but setting `promptCacheKey`
|
|
14
|
-
// (routes identical keys to the same cache shard) and `store`
|
|
15
|
-
// (retains the call for later fetching) improves hit rates.
|
|
16
|
-
// We send the sessionId as the key so every turn in a
|
|
17
|
-
// conversation maps to the same shard.
|
|
18
|
-
//
|
|
19
|
-
// OpenAI- — the DeepSeek / Moonshot / Alibaba / Zhipu / xAI / custom
|
|
20
|
-
// compatible providers all offer automatic prefix caching with NO
|
|
21
|
-
// explicit flags required. The only prerequisite is a
|
|
22
|
-
// byte-stable prefix across turns: if the system prompt
|
|
23
|
-
// rebuilds with a fresh timestamp every turn, every request
|
|
24
|
-
// misses the cache. We therefore cache the system prompt
|
|
25
|
-
// once per session in LoopState (see loop-state.ts) and use
|
|
26
|
-
// the same string on every subsequent turn.
|
|
27
|
-
//
|
|
28
|
-
// Google — Gemini uses implicit caching; no per-request flags we can
|
|
29
|
-
// usefully set from the SDK. Left as a no-op.
|
|
30
1
|
import { providerOf } from './capabilities.js';
|
|
31
2
|
/** Max messages we attach an Anthropic cache breakpoint to. Anthropic allows
|
|
32
3
|
* up to 4 `cache_control` blocks per request; we spend one on the system
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-control.js","sourceRoot":"","sources":["../../src/providers/cache-control.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache-control.js","sourceRoot":"","sources":["../../src/providers/cache-control.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;+EAI+E;AAC/E,MAAM,yBAAyB,GAAG,CAAC,CAAA;AAyBnC,6EAA6E;AAC7E,SAAS,UAAU,CAAC,GAAiB,EAAE,QAAgB,EAAE,KAA8B;IACrF,MAAM,QAAQ,GAAI,GAAqE,CAAC,eAAe,IAAI,EAAE,CAAA;IAC7G,OAAO;QACL,GAAG,GAAG;QACN,eAAe,EAAE;YACf,GAAG,QAAQ;YACX,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE;SACxD;KACc,CAAA;AACnB,CAAC;AAED,yEAAyE;AACzE,SAAS,sBAAsB,CAAC,MAAc;IAC5C,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,MAAM;QACf,eAAe,EAAE;YACf,SAAS,EAAE,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE;SACnD;KACyB,CAAA;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAsB;IACtD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEzC,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC7B,uEAAuE;QACvE,iEAAiE;QACjE,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,yBAAyB,CAAC,CAAA;QACrE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAA;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACrC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACzF,CAAA;QACD,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC;SAC3D,CAAA;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,yEAAyE;QACzE,sEAAsE;QACtE,iDAAiD;QACjD,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,eAAe,EAAE;gBACf,MAAM,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE;aACzD;SACF,CAAA;IACH,CAAC;IAED,6EAA6E;IAC7E,2EAA2E;IAC3E,uCAAuC;IACvC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAA;AACzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking.d.ts","sourceRoot":"","sources":["../../src/providers/thinking.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"thinking.d.ts","sourceRoot":"","sources":["../../src/providers/thinking.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuDrH;AAED;;;iEAGiE;AACjE,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB"}
|
|
@@ -78,15 +78,11 @@ export function getThinkingProviderOptions(modelId, enabled) {
|
|
|
78
78
|
// and grok-4 ignore it. Sending the option is harmless on the
|
|
79
79
|
// ignoring models — the SDK passes it through and the API silently
|
|
80
80
|
// discards it.
|
|
81
|
-
return enabled
|
|
82
|
-
? { xai: { reasoningEffort: 'high' } }
|
|
83
|
-
: { xai: { reasoningEffort: 'low' } };
|
|
81
|
+
return enabled ? { xai: { reasoningEffort: 'high' } } : { xai: { reasoningEffort: 'low' } };
|
|
84
82
|
case 'openai':
|
|
85
83
|
// Only o-series and gpt-5 reasoning models use `reasoningEffort`;
|
|
86
84
|
// gpt-4.1 ignores it. Same harmless pass-through as xAI.
|
|
87
|
-
return enabled
|
|
88
|
-
? { openai: { reasoningEffort: 'high' } }
|
|
89
|
-
: { openai: { reasoningEffort: 'minimal' } };
|
|
85
|
+
return enabled ? { openai: { reasoningEffort: 'high' } } : { openai: { reasoningEffort: 'minimal' } };
|
|
90
86
|
case 'zhipu':
|
|
91
87
|
case 'custom':
|
|
92
88
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking.js","sourceRoot":"","sources":["../../src/providers/thinking.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,uEAAuE;AACvE,4EAA4E;AAC5E,uEAAuE;AACvE,wEAAwE;AACx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AC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,CAAA;QAE7F,KAAK,QAAQ;YACX,kEAAkE;YAClE,yDAAyD;YACzD,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,CAAA;QAEvG,KAAK,OAAO,CAAC;QACb,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,EAAE,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;iEAGiE;AACjE,MAAM,UAAU,oBAAoB,CAClC,IAAyC,EACzC,QAAiD;IAEjD,MAAM,MAAM,GAA4B,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAA;IAC3D,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzD,MAAM,QAAQ,GAAI,MAAM,CAAC,QAAQ,CAAyC,IAAI,EAAE,CAAA;QAChF,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAA;IAC9C,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO;;;;;;
|
|
1
|
+
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO;;;;;;SAoClB,CAAA"}
|
package/dist/tools/ask-user.js
CHANGED
|
@@ -2,20 +2,30 @@
|
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export const askUser = tool({
|
|
5
|
-
description:
|
|
5
|
+
description: `Ask the user multiple-choice questions to gather information, clarify ambiguity, understand preferences, make decisions, or offer choices.
|
|
6
|
+
|
|
7
|
+
Usage notes:
|
|
8
|
+
- Users will always be able to select "Other" to provide custom text input.
|
|
9
|
+
- If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label.
|
|
10
|
+
|
|
11
|
+
Plan mode note: In plan mode, use this tool to clarify requirements or choose between approaches BEFORE finalizing your plan. Do NOT use this tool to ask "Is my plan ready?" or "Should I proceed?" — use exitPlanMode for plan approval. IMPORTANT: Do not reference "the plan" in your questions (e.g., "Do you have feedback about the plan?", "Does the plan look good?") because the user cannot see the plan in the UI until you call exitPlanMode. If you need plan approval, use exitPlanMode instead.`,
|
|
6
12
|
inputSchema: z.object({
|
|
7
|
-
question: z
|
|
13
|
+
question: z
|
|
14
|
+
.string()
|
|
15
|
+
.describe('The complete question to ask the user. Should be clear, specific, and end with a question mark. Keep it to ONE short sentence — do NOT embed long markdown, lists, headings, or detailed explanations here; put tradeoff details in option descriptions instead. Example: "Which library should we use for date formatting?"'),
|
|
8
16
|
options: z
|
|
9
17
|
.array(z.object({
|
|
10
|
-
label: z
|
|
18
|
+
label: z
|
|
19
|
+
.string()
|
|
20
|
+
.describe('The display text for this option that the user will see and select. Should be concise (1-5 words) and clearly describe the choice.'),
|
|
11
21
|
description: z
|
|
12
22
|
.string()
|
|
13
|
-
.describe('
|
|
23
|
+
.describe('Explanation of what this option means or what will happen if chosen. Useful for providing context about tradeoffs or implications.'),
|
|
14
24
|
}))
|
|
15
25
|
.min(2)
|
|
16
|
-
.max(
|
|
17
|
-
.describe('
|
|
26
|
+
.max(4)
|
|
27
|
+
.describe('The available choices for this question. Must have 2-4 options. Each option should be a distinct, mutually exclusive choice. There should be no "Other" option — the UI auto-appends one as the last row, so adding your own creates a duplicate.'),
|
|
18
28
|
}),
|
|
19
|
-
// No execute — through callback to trigger UI rendering
|
|
29
|
+
// No execute — handled through callback to trigger UI rendering
|
|
20
30
|
});
|
|
21
31
|
//# sourceMappingURL=ask-user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;IAC1B,WAAW,
|
|
1
|
+
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE;;;;;;gfAMie;IAC9e,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,CAAC;aACR,MAAM,EAAE;aACR,QAAQ,CACP,8TAA8T,CAC/T;QACH,OAAO,EAAE,CAAC;aACP,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,CAAC;iBACL,MAAM,EAAE;iBACR,QAAQ,CACP,oIAAoI,CACrI;YACH,WAAW,EAAE,CAAC;iBACX,MAAM,EAAE;iBACR,QAAQ,CACP,oIAAoI,CACrI;SACJ,CAAC,CACH;aACA,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CACP,mPAAmP,CACpP;KACJ,CAAC;IACF,gEAAgE;CACjE,CAAC,CAAA"}
|
package/dist/tools/edit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI;;;;;
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI;;;;;SAgBf,CAAA"}
|
package/dist/tools/edit.js
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export const edit = tool({
|
|
5
|
-
description:
|
|
5
|
+
description: `Perform exact string replacements in files.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
- You must use readFile at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
|
|
9
|
+
- When editing text from readFile output, ensure you preserve the exact indentation (tabs/spaces) as it appears in the file content. Never include line number prefixes in oldString or newString.
|
|
10
|
+
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
|
|
11
|
+
- The edit will FAIL if oldString is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replaceAll to change every instance.
|
|
12
|
+
- Use replaceAll for replacing and renaming strings across the file (e.g. renaming a variable).`,
|
|
6
13
|
inputSchema: z.object({
|
|
7
14
|
filePath: z.string().describe('Absolute path to the file'),
|
|
8
15
|
oldString: z.string().describe('The exact text to find and replace (must be unique in the file)'),
|
package/dist/tools/edit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE;;;;;;;gGAOiF;IAC9F,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QAC1D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iEAAiE,CAAC;QACjG,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;QACtD,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;KACxF,CAAC;IACF,mEAAmE;CACpE,CAAC,CAAA"}
|
package/dist/tools/glob.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,IAAI;;;UA2Bf,CAAA"}
|
package/dist/tools/glob.js
CHANGED
|
@@ -4,8 +4,10 @@ import { tool } from 'ai';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { formatToolError } from '../utils/tool-errors.js';
|
|
6
6
|
import { reportProgress } from './progress.js';
|
|
7
|
+
const MAX_GLOB_RESULTS = 200;
|
|
7
8
|
export const glob = tool({
|
|
8
|
-
description:
|
|
9
|
+
description: `Find files matching a glob pattern. Returns file paths sorted by modification time. ` +
|
|
10
|
+
`Results are capped at ${MAX_GLOB_RESULTS} files — use a more specific pattern if truncated.`,
|
|
9
11
|
inputSchema: z.object({
|
|
10
12
|
pattern: z.string().describe('Glob pattern (e.g. "**/*.ts", "src/**/*.tsx")'),
|
|
11
13
|
cwd: z.string().optional().describe('Directory to search in (defaults to working directory)'),
|
|
@@ -20,7 +22,12 @@ export const glob = tool({
|
|
|
20
22
|
});
|
|
21
23
|
if (files.length === 0)
|
|
22
24
|
return 'No files found matching the pattern.';
|
|
23
|
-
|
|
25
|
+
const truncated = files.length > MAX_GLOB_RESULTS;
|
|
26
|
+
const result = files.slice(0, MAX_GLOB_RESULTS).join('\n');
|
|
27
|
+
if (truncated) {
|
|
28
|
+
return `${result}\n\n... [${files.length - MAX_GLOB_RESULTS} more files not shown — ${files.length} total matches, capped at ${MAX_GLOB_RESULTS}. Use a more specific pattern to narrow results.]`;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
24
31
|
}
|
|
25
32
|
catch (err) {
|
|
26
33
|
return formatToolError('searching files', err);
|
package/dist/tools/glob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAE5B,MA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CAAA"}
|
package/dist/tools/grep.d.ts
CHANGED
package/dist/tools/grep.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,IAAI;;;;;UAqDf,CAAA"}
|
package/dist/tools/grep.js
CHANGED
|
@@ -6,6 +6,9 @@ import { z } from 'zod';
|
|
|
6
6
|
import { formatToolError } from '../utils/tool-errors.js';
|
|
7
7
|
import { reportProgress } from './progress.js';
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
|
+
const DEFAULT_HEAD_LIMIT = 250;
|
|
10
|
+
const MAX_COLUMNS = 500;
|
|
11
|
+
const RG_MAX_BUFFER = 20 * 1024 * 1024;
|
|
9
12
|
let _rgPath = null;
|
|
10
13
|
function getRipgrepPath() {
|
|
11
14
|
if (_rgPath)
|
|
@@ -22,17 +25,33 @@ function getRipgrepPath() {
|
|
|
22
25
|
return _rgPath;
|
|
23
26
|
}
|
|
24
27
|
export const grep = tool({
|
|
25
|
-
description:
|
|
28
|
+
description: `A powerful search tool built on ripgrep.
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
- ALWAYS use this grep tool for content search tasks. NEVER invoke grep or rg as a shell command — this tool has been optimized for correct permissions and access.
|
|
32
|
+
- Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+").
|
|
33
|
+
- Filter files with glob parameter (e.g., "*.ts", "*.{ts,tsx}").
|
|
34
|
+
- Pattern syntax: Uses ripgrep — literal braces need escaping (use interface\\{\\} to find interface{} in Go code).
|
|
35
|
+
- Results are capped at headLimit lines (default ${DEFAULT_HEAD_LIMIT}). Long lines are truncated at ${MAX_COLUMNS} chars.`,
|
|
26
36
|
inputSchema: z.object({
|
|
27
37
|
pattern: z.string().describe('Regex pattern to search for'),
|
|
28
38
|
path: z.string().optional().describe('File or directory to search in (defaults to working directory)'),
|
|
29
39
|
glob: z.string().optional().describe('Glob pattern to filter files (e.g. "*.ts", "*.{ts,tsx}")'),
|
|
30
|
-
|
|
40
|
+
headLimit: z.number().optional().describe(`Max number of output lines (default: ${DEFAULT_HEAD_LIMIT})`),
|
|
31
41
|
}),
|
|
32
|
-
execute: async ({ pattern, path: searchPath, glob: globPattern,
|
|
42
|
+
execute: async ({ pattern, path: searchPath, glob: globPattern, headLimit }, { toolCallId }) => {
|
|
33
43
|
try {
|
|
34
44
|
const rgPath = getRipgrepPath();
|
|
35
|
-
const
|
|
45
|
+
const limit = headLimit ?? DEFAULT_HEAD_LIMIT;
|
|
46
|
+
const args = [
|
|
47
|
+
'--no-heading',
|
|
48
|
+
'--line-number',
|
|
49
|
+
'--color',
|
|
50
|
+
'never',
|
|
51
|
+
'--max-columns',
|
|
52
|
+
String(MAX_COLUMNS),
|
|
53
|
+
'--max-columns-preview',
|
|
54
|
+
];
|
|
36
55
|
if (globPattern) {
|
|
37
56
|
args.push('--glob', globPattern);
|
|
38
57
|
}
|
|
@@ -40,13 +59,17 @@ export const grep = tool({
|
|
|
40
59
|
args.push(searchPath ?? process.cwd());
|
|
41
60
|
reportProgress(toolCallId, `Searching for /${pattern}/`);
|
|
42
61
|
const { stdout } = await execFileAsync(rgPath, args, {
|
|
43
|
-
maxBuffer:
|
|
62
|
+
maxBuffer: RG_MAX_BUFFER,
|
|
44
63
|
timeout: 30000,
|
|
45
64
|
});
|
|
46
65
|
const out = stdout.trim();
|
|
47
66
|
if (!out)
|
|
48
67
|
return 'No matches found.';
|
|
49
|
-
|
|
68
|
+
const lines = out.split('\n');
|
|
69
|
+
if (lines.length <= limit)
|
|
70
|
+
return out;
|
|
71
|
+
const truncated = lines.slice(0, limit).join('\n');
|
|
72
|
+
return `${truncated}\n\n... [${lines.length - limit} more lines not shown — at least ${lines.length} total matches, capped at ${limit}. Narrow your pattern or use glob to reduce results.]`;
|
|
50
73
|
}
|
|
51
74
|
catch (err) {
|
|
52
75
|
if (err && typeof err === 'object' && 'code' in err && err.code === 1) {
|
package/dist/tools/grep.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAEzC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAC9B,MAAM,WAAW,GAAG,GAAG,CAAA;AACvB,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAEtC,IAAI,OAAO,GAAkB,IAAI,CAAA;AAEjC,SAAS,cAAc;IACrB,IAAI,OAAO;QAAE,OAAO,OAAO,CAAA;IAC3B,IAAI,CAAC;QACH,2CAA2C;QAC3C,iEAAiE;QACjE,MAAM,EAAE,GAAG,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