@alexwkleung/reika 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD_PARTY_LICENSES.txt +1271 -0
- package/dist/chunk-AX767B3T.js +22724 -0
- package/dist/chunk-JVOYWUGK.js +279 -0
- package/dist/chunk-KI5CTLSX.js +59 -0
- package/dist/chunk-SBBXMTSX.js +4050 -0
- package/dist/cli.js +153 -53
- package/dist/devtools-FYXXYYMR.js +2 -0
- package/dist/esm-SND35LIM.js +8494 -0
- package/dist/headless-Y2V6WPLB.js +592 -0
- package/dist/node-7FRVMBZF.js +69479 -0
- package/dist/tui-KWAD5BDE.js +34366 -0
- package/package.json +16 -17
- package/dist/agent/attachments.js +0 -63
- package/dist/agent/bashread.js +0 -177
- package/dist/agent/compaction.js +0 -922
- package/dist/agent/compactionreport.js +0 -248
- package/dist/agent/continuation.js +0 -153
- package/dist/agent/decoderate.js +0 -132
- package/dist/agent/entropytrace.js +0 -169
- package/dist/agent/genreserve.js +0 -75
- package/dist/agent/groundcheck.js +0 -195
- package/dist/agent/logitrecovery.js +0 -171
- package/dist/agent/loop.js +0 -3676
- package/dist/agent/mentions.js +0 -118
- package/dist/agent/noteslotmonitor.js +0 -82
- package/dist/agent/pastedurls.js +0 -203
- package/dist/agent/planpressure.js +0 -87
- package/dist/agent/plantrack.js +0 -503
- package/dist/agent/prefillcost.js +0 -95
- package/dist/agent/prefixtrace.js +0 -90
- package/dist/agent/prompt.js +0 -349
- package/dist/agent/readfirst.js +0 -190
- package/dist/agent/readtrace.js +0 -191
- package/dist/agent/reasoningtrace.js +0 -242
- package/dist/agent/shellruns.js +0 -81
- package/dist/agent/subagentpressure.js +0 -70
- package/dist/agent/subagentreport.js +0 -117
- package/dist/agent/warm.js +0 -163
- package/dist/approval.js +0 -59
- package/dist/check/typecheck.js +0 -345
- package/dist/config.js +0 -509
- package/dist/context/bootstrap.js +0 -122
- package/dist/context/bundlesize.js +0 -74
- package/dist/context/files.js +0 -67
- package/dist/context/gitignore.js +0 -102
- package/dist/context/repomap.js +0 -304
- package/dist/debug.js +0 -197
- package/dist/headless/headless.js +0 -440
- package/dist/headless/headlessargs.js +0 -108
- package/dist/headless/headlessprompt.js +0 -132
- package/dist/laststate.js +0 -71
- package/dist/limit.js +0 -27
- package/dist/mcp/client.js +0 -630
- package/dist/mcp/config.js +0 -187
- package/dist/mcp/manager.js +0 -158
- package/dist/mcp/tools.js +0 -323
- package/dist/ocr/select.js +0 -29
- package/dist/ocr/system.js +0 -162
- package/dist/ocr/types.js +0 -1
- package/dist/ocr/vision.js +0 -139
- package/dist/provider/budget.js +0 -56
- package/dist/provider/cachehints.js +0 -30
- package/dist/provider/client.js +0 -573
- package/dist/provider/contextwindow.js +0 -78
- package/dist/provider/dispatcher.js +0 -126
- package/dist/provider/latches.js +0 -31
- package/dist/provider/modellimits.js +0 -186
- package/dist/provider/noteslot.js +0 -239
- package/dist/provider/templatekwargs.js +0 -31
- package/dist/provider/tokens.js +0 -32
- package/dist/provider/toolcall.js +0 -1088
- package/dist/provider/transport.js +0 -264
- package/dist/search/_chrome.js +0 -422
- package/dist/search/cdp.js +0 -223
- package/dist/search/searxng.js +0 -86
- package/dist/search/types.js +0 -17
- package/dist/session.js +0 -411
- package/dist/skills/skillmatch.js +0 -143
- package/dist/skills/skills.js +0 -349
- package/dist/store/payloads.js +0 -21
- package/dist/store/sessions.js +0 -180
- package/dist/store/transcript.js +0 -390
- package/dist/tools/_carriers.js +0 -119
- package/dist/tools/_danger.js +0 -1848
- package/dist/tools/_deps.js +0 -203
- package/dist/tools/_diff.js +0 -64
- package/dist/tools/_exfil.js +0 -168
- package/dist/tools/_heredoc.js +0 -419
- package/dist/tools/_hosts.js +0 -224
- package/dist/tools/_markdown.js +0 -288
- package/dist/tools/_net.js +0 -65
- package/dist/tools/_paths.js +0 -171
- package/dist/tools/_readonly.js +0 -545
- package/dist/tools/_sandbox.js +0 -953
- package/dist/tools/_spill.js +0 -216
- package/dist/tools/_spillstats.js +0 -45
- package/dist/tools/_treediff.js +0 -350
- package/dist/tools/_urls.js +0 -335
- package/dist/tools/_walk.js +0 -24
- package/dist/tools/_writetargets.js +0 -96
- package/dist/tools/ask.js +0 -194
- package/dist/tools/bash.js +0 -638
- package/dist/tools/edit.js +0 -439
- package/dist/tools/fetch.js +0 -415
- package/dist/tools/glob.js +0 -142
- package/dist/tools/grep.js +0 -263
- package/dist/tools/index.js +0 -171
- package/dist/tools/list.js +0 -96
- package/dist/tools/read.js +0 -74
- package/dist/tools/search.js +0 -134
- package/dist/tools/subagent.js +0 -23
- package/dist/tools/write.js +0 -107
- package/dist/types.js +0 -1
- package/dist/ui/App.js +0 -2874
- package/dist/ui/Approval.js +0 -148
- package/dist/ui/Confirm.js +0 -51
- package/dist/ui/DiffView.js +0 -401
- package/dist/ui/Input.js +0 -461
- package/dist/ui/ModelSelect.js +0 -32
- package/dist/ui/PlanProgress.js +0 -50
- package/dist/ui/Question.js +0 -238
- package/dist/ui/QueuedList.js +0 -17
- package/dist/ui/ResumeSelect.js +0 -61
- package/dist/ui/Scrollback.js +0 -715
- package/dist/ui/Splash.js +0 -42
- package/dist/ui/Status.js +0 -207
- package/dist/ui/Suggestions.js +0 -50
- package/dist/ui/Working.js +0 -242
- package/dist/ui/clipboard.js +0 -77
- package/dist/ui/commands.js +0 -205
- package/dist/ui/dialogspecs.js +0 -38
- package/dist/ui/focus.js +0 -56
- package/dist/ui/format.js +0 -180
- package/dist/ui/framedrops.js +0 -34
- package/dist/ui/glyphs.js +0 -48
- package/dist/ui/harnessecho.js +0 -24
- package/dist/ui/highlight.js +0 -191
- package/dist/ui/identity.js +0 -211
- package/dist/ui/layout.js +0 -224
- package/dist/ui/markdown.js +0 -357
- package/dist/ui/models.js +0 -32
- package/dist/ui/pastes.js +0 -59
- package/dist/ui/paths.js +0 -19
- package/dist/ui/pr.js +0 -78
- package/dist/ui/queue.js +0 -25
- package/dist/ui/reactbuild.js +0 -15
- package/dist/ui/reasoningfold.js +0 -63
- package/dist/ui/redact.js +0 -51
- package/dist/ui/scrub.js +0 -49
- package/dist/ui/suggest.js +0 -92
- package/dist/ui/summary.js +0 -60
- package/dist/ui/syncframe.js +0 -97
- package/dist/ui/termtext.js +0 -117
- package/dist/ui/theme.js +0 -100
- package/dist/ui/tui.js +0 -9
- package/dist/ui/warmtrigger.js +0 -37
- package/dist/version.js +0 -27
package/dist/tools/_markdown.js
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
// Text on a command line that ends up in Markdown, and therefore never runs. The danger scan
|
|
2
|
-
// (`_danger.ts`) matches the literal command text, which is exactly what makes it hard to fool —
|
|
3
|
-
// and exactly why it fires on prose: `gh pr create --body "$(cat <<'EOF' … we run rm -rf / … EOF)"`
|
|
4
|
-
// reports "Recursive force delete" for a sentence, and `cat > CHANGELOG.md <<'EOF'` prompts under
|
|
5
|
-
// `safe` for a changelog entry that merely *mentions* a destructive command. The user then reads a
|
|
6
|
-
// dialog recommending they consider an rm they are not being asked to run, which is the reflexive
|
|
7
|
-
// approval this gate cannot afford (see AGENTS.md, "Approval gate").
|
|
8
|
-
//
|
|
9
|
-
// So this file answers one question — which stretches of a command are Markdown DATA — and blanks
|
|
10
|
-
// them, length-preserving, before the patterns run. Two producers, and only the ones a model
|
|
11
|
-
// actually reaches for:
|
|
12
|
-
//
|
|
13
|
-
// - a shell text writer (`cat`, `tee`, `printf`, `echo`) whose redirect target or operand is a
|
|
14
|
-
// Markdown path: `cat > CHANGELOG.md <<'EOF'`. The extension is the whole claim — `cat > run.sh`
|
|
15
|
-
// is a script and stays flagged, which is the undershoot that keeps this honest.
|
|
16
|
-
// - a `gh` segment carrying one of the flags whose value GitHub renders as Markdown (`--body`,
|
|
17
|
-
// `--title`, `--notes`, and the `-file` forms), including the heredoc a `--body-file -` reads.
|
|
18
|
-
//
|
|
19
|
-
// What it deliberately does NOT blank is anything the shell still EXECUTES inside that text: a
|
|
20
|
-
// substitution runs in a body whose delimiter was unquoted (`<<EOF`) and in any double-quoted or
|
|
21
|
-
// bare argument, so `$(…)`, backticks and process substitution (`<(…)`/`>(…)`) inside those are kept
|
|
22
|
-
// verbatim and the ordinary scan still answers for them. That is the same rule `_sandbox.ts` applies
|
|
23
|
-
// to heredoc bodies (data for the verb question, re-read for the substitution one), narrowed here to
|
|
24
|
-
// text we can name as Markdown.
|
|
25
|
-
import { scanHeredocs } from './_heredoc.js';
|
|
26
|
-
import { maskQuoted } from './_readonly.js';
|
|
27
|
-
// The extensions that make a written file Markdown. `mdx` rides along because it is read as
|
|
28
|
-
// Markdown with JSX in it; a component file is not what this is for, and a false negative there
|
|
29
|
-
// costs one missed label on an uncommon shape.
|
|
30
|
-
const MARKDOWN_PATH_RE = /\.(?:md|markdown|mdx)$/i;
|
|
31
|
-
// Words whose arguments are the text being written rather than a program being run. Short on
|
|
32
|
-
// purpose: `sed`, `awk` and `perl` take a PROGRAM as an argument, so their text is not data, and
|
|
33
|
-
// `git log > notes.md` writes a file whose arguments are flags — neither is this rule's case.
|
|
34
|
-
const TEXT_WRITERS = new Set(['cat', 'tee', 'printf', 'echo']);
|
|
35
|
-
// `gh`'s prose flags. Enumerated by flag rather than by noun/verb because it is the flag that says
|
|
36
|
-
// "this is text GitHub renders" — the same words on every verb that has them (`issue`/`pr`/`release`
|
|
37
|
-
// create|edit|comment|review, `gist create`), and a noun/verb table would need a new entry for each.
|
|
38
|
-
const GH_TEXT_FLAGS = new Set([
|
|
39
|
-
'-b',
|
|
40
|
-
'--body',
|
|
41
|
-
'-F',
|
|
42
|
-
'--body-file',
|
|
43
|
-
'-t',
|
|
44
|
-
'--title',
|
|
45
|
-
'-n',
|
|
46
|
-
'--notes',
|
|
47
|
-
'--notes-file',
|
|
48
|
-
'-d',
|
|
49
|
-
'--desc',
|
|
50
|
-
'--description',
|
|
51
|
-
]);
|
|
52
|
-
// A segment boundary: what starts a new command. Only the plain separators — never `(` or `$(`,
|
|
53
|
-
// because the segment holding a heredoc operator is the one whose WORDS name the Markdown producer,
|
|
54
|
-
// and `gh pr create --body "$(cat <<'EOF'` must read as one `gh` segment rather than as a bare `cat`.
|
|
55
|
-
const SEPARATOR_RE = /[;&|\r\n]+/g;
|
|
56
|
-
// `>f`, `>> f`, `2>f`, `&>f` — the same shape `_writetargets.ts` reads targets off.
|
|
57
|
-
const REDIRECT_WORD_RE = /^(?:\d+|&)?>>?(.*)$/;
|
|
58
|
-
// Blank every Markdown-data region of `command`, preserving offsets and newlines. Length-preserving
|
|
59
|
-
// so a caller can keep indexing the original string, newline-preserving so every line-based parser
|
|
60
|
-
// downstream (`stripHeredocs`, `segmentsWithDir`, the segment splits) still sees the same shape.
|
|
61
|
-
export function maskMarkdownData(command) {
|
|
62
|
-
const regions = [...heredocRegions(command), ...argumentRegions(command)];
|
|
63
|
-
// Outer first, and this ordering is load-bearing only because blanking is monotone: a later pass
|
|
64
|
-
// can blank more but never restore, so regions must not over-claim. `--body "$(cat <<'EOF' …
|
|
65
|
-
// EOF)"` is a value region (expands) whose kept `$(…)` still contains the quoted heredoc's body —
|
|
66
|
-
// the body region lands after it and blanks exactly that.
|
|
67
|
-
regions.sort((a, b) => a.start - b.start || b.end - a.end);
|
|
68
|
-
let masked = command;
|
|
69
|
-
for (const r of regions) {
|
|
70
|
-
const blanked = blankData(masked.slice(r.start, r.end), r.expands);
|
|
71
|
-
masked = masked.slice(0, r.start) + blanked + masked.slice(r.end);
|
|
72
|
-
}
|
|
73
|
-
return masked;
|
|
74
|
-
}
|
|
75
|
-
// Heredoc bodies whose segment writes Markdown. The operator's own segment is what decides, not the
|
|
76
|
-
// line: two heredocs on one line are two different commands more often than they are one.
|
|
77
|
-
function heredocRegions(command) {
|
|
78
|
-
// The operators come off the RAW command and the segments off the quote mask, because
|
|
79
|
-
// `gh pr create --body "$(cat <<'EOF' … EOF)"` puts the operator INSIDE the double-quoted value the
|
|
80
|
-
// mask blanks. Which `<<` is live — never one in quoted prose (`--title 'use <<EOF'`), always one
|
|
81
|
-
// inside a `$(…)` — is `scanHeredocs`' answer, the same one the sandbox and the danger scan get.
|
|
82
|
-
// A scan it cannot read exactly blanks nothing: the danger labels then over-report, never hide.
|
|
83
|
-
const scan = scanHeredocs(command);
|
|
84
|
-
if (scan.uncertain)
|
|
85
|
-
return [];
|
|
86
|
-
const view = maskQuoted(command);
|
|
87
|
-
const out = [];
|
|
88
|
-
for (const h of scan.heredocs) {
|
|
89
|
-
const seg = segmentAt(command, view, h.opAt);
|
|
90
|
-
if (!seg || !isMarkdownSegment(seg.text))
|
|
91
|
-
continue;
|
|
92
|
-
out.push({ start: h.bodyStart, end: h.bodyEnd, expands: !h.literal });
|
|
93
|
-
}
|
|
94
|
-
return out;
|
|
95
|
-
}
|
|
96
|
-
// Shell words whose text is Markdown by the flag it rides or the file it lands in.
|
|
97
|
-
function argumentRegions(command) {
|
|
98
|
-
const out = [];
|
|
99
|
-
const view = maskQuoted(command);
|
|
100
|
-
// Every segment, including the last one — the common shape (`gh pr create --body "…"` with nothing
|
|
101
|
-
// after it) ends at the end of the command rather than at a separator.
|
|
102
|
-
const bounds = [];
|
|
103
|
-
let from = 0;
|
|
104
|
-
SEPARATOR_RE.lastIndex = 0;
|
|
105
|
-
for (let m = SEPARATOR_RE.exec(view); m; m = SEPARATOR_RE.exec(view)) {
|
|
106
|
-
bounds.push({ start: from, end: m.index });
|
|
107
|
-
from = m.index + m[0].length;
|
|
108
|
-
}
|
|
109
|
-
bounds.push({ start: from, end: view.length });
|
|
110
|
-
for (const { start, end: segEnd } of bounds) {
|
|
111
|
-
// Raw words, not the masked view's: the value of `--body "…"` and a quoted redirect target are
|
|
112
|
-
// blanked in the view (that is the point of it), and their OFFSETS are what this pass needs.
|
|
113
|
-
const seg = command.slice(start, segEnd);
|
|
114
|
-
const words = shellWords(seg);
|
|
115
|
-
const name = unquote(words[0]?.text ?? '');
|
|
116
|
-
if (!name)
|
|
117
|
-
continue;
|
|
118
|
-
if (name === 'gh') {
|
|
119
|
-
for (let i = 0; i < words.length; i++) {
|
|
120
|
-
// The flag is what sits before the `=`, when there is one: `--body="…"` is `--body` with a
|
|
121
|
-
// value, and comparing the whole word against the set missed exactly that spelling.
|
|
122
|
-
const eq = words[i].text.indexOf('=');
|
|
123
|
-
const flag = unquote(eq === -1 ? words[i].text : words[i].text.slice(0, eq));
|
|
124
|
-
if (!GH_TEXT_FLAGS.has(flag))
|
|
125
|
-
continue;
|
|
126
|
-
// The region is the VALUE word and nothing else. It used to run to the end of the segment,
|
|
127
|
-
// and an earlier single-quoted flag (`--title 'Fix'`) then blanked a later double-quoted
|
|
128
|
-
// flag's value wholesale — including an executed `$(…)` the scan must still answer for
|
|
129
|
-
// (measured). `expands` comes from the value's own quoting, so `--body '…'` and
|
|
130
|
-
// `--body='…'` — one shell word each — get the same verdict.
|
|
131
|
-
const value = eq === -1 ? words[i + 1] : words[i];
|
|
132
|
-
const valueAt = eq === -1 ? 0 : eq + 1;
|
|
133
|
-
if (!value)
|
|
134
|
-
continue;
|
|
135
|
-
out.push({
|
|
136
|
-
start: start + value.at + valueAt,
|
|
137
|
-
end: start + value.at + value.text.length,
|
|
138
|
-
expands: value.text[valueAt] !== "'",
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (!TEXT_WRITERS.has(name))
|
|
144
|
-
continue;
|
|
145
|
-
if (!writesMarkdown(words, name))
|
|
146
|
-
continue;
|
|
147
|
-
// Everything after the command word is text it is writing: operands and the redirect clause
|
|
148
|
-
// alike. `cat README.md` with no redirect is a read and is not this case.
|
|
149
|
-
out.push({ start: start + words[0].at + words[0].text.length, end: segEnd, expands: true });
|
|
150
|
-
}
|
|
151
|
-
return out;
|
|
152
|
-
}
|
|
153
|
-
// Words split the way the shell splits them: a quoted run is ONE word (`--body="a b"` is a single
|
|
154
|
-
// argument, and splitting it on the space made the flag unreadable — measured, on the `--body=` form
|
|
155
|
-
// specifically). Offsets are preserved so a caller can cut the value back out of the original.
|
|
156
|
-
function shellWords(seg) {
|
|
157
|
-
const out = [];
|
|
158
|
-
let i = 0;
|
|
159
|
-
while (i < seg.length) {
|
|
160
|
-
if (/\s/.test(seg[i])) {
|
|
161
|
-
i++;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const at = i;
|
|
165
|
-
let text = '';
|
|
166
|
-
while (i < seg.length && !/\s/.test(seg[i])) {
|
|
167
|
-
const ch = seg[i];
|
|
168
|
-
if (ch === '"' || ch === "'") {
|
|
169
|
-
const close = seg.indexOf(ch, i + 1);
|
|
170
|
-
if (close === -1) {
|
|
171
|
-
text += seg.slice(i);
|
|
172
|
-
i = seg.length;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
text += seg.slice(i, close + 1);
|
|
176
|
-
i = close + 1;
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
text += ch;
|
|
180
|
-
i++;
|
|
181
|
-
}
|
|
182
|
-
out.push({ text, at });
|
|
183
|
-
}
|
|
184
|
-
return out;
|
|
185
|
-
}
|
|
186
|
-
function writesMarkdown(words, name) {
|
|
187
|
-
for (let i = 0; i < words.length; i++) {
|
|
188
|
-
const w = unquote(words[i].text);
|
|
189
|
-
const redirect = REDIRECT_WORD_RE.exec(w);
|
|
190
|
-
if (redirect) {
|
|
191
|
-
// `>f` carries the target in the same word; `> f` in the next one.
|
|
192
|
-
const target = redirect[1] || unquote(words[i + 1]?.text ?? '');
|
|
193
|
-
if (target && !target.startsWith('&') && MARKDOWN_PATH_RE.test(target))
|
|
194
|
-
return true;
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
if (name === 'tee' && i > 0 && !w.startsWith('-') && MARKDOWN_PATH_RE.test(w))
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
// The segment an offset sits in: back to the previous separator, forward to the next one. The
|
|
203
|
-
// BOUNDARIES come from the quote-masked view, so a separator inside a quoted string is not one; the
|
|
204
|
-
// words come from the raw text, so a quoted target (`cat > "CHANGELOG.md"`) is still readable as the
|
|
205
|
-
// path it names — masking it away would silently turn this rule off for every quoted operand.
|
|
206
|
-
function segmentAt(command, view, at) {
|
|
207
|
-
const before = view.slice(0, at);
|
|
208
|
-
const after = view.slice(at);
|
|
209
|
-
let start = 0;
|
|
210
|
-
for (const m of before.matchAll(SEPARATOR_RE))
|
|
211
|
-
start = (m.index ?? 0) + m[0].length;
|
|
212
|
-
let last = 0;
|
|
213
|
-
for (const m of after.matchAll(SEPARATOR_RE))
|
|
214
|
-
last = (m.index ?? 0) + m[0].length;
|
|
215
|
-
const end = at + last;
|
|
216
|
-
if (end <= start)
|
|
217
|
-
return undefined;
|
|
218
|
-
return { text: command.slice(start, end) };
|
|
219
|
-
}
|
|
220
|
-
function isMarkdownSegment(seg) {
|
|
221
|
-
const words = shellWords(seg);
|
|
222
|
-
const name = unquote(words[0]?.text ?? '');
|
|
223
|
-
// Same up-to-the-`=` reading as the argument pass: `--body="…"` has to count as a text flag or the
|
|
224
|
-
// heredoc it carries is never recognised as Markdown.
|
|
225
|
-
if (name === 'gh') {
|
|
226
|
-
return words.some(w => {
|
|
227
|
-
const eq = w.text.indexOf('=');
|
|
228
|
-
return GH_TEXT_FLAGS.has(unquote(eq === -1 ? w.text : w.text.slice(0, eq)));
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (!TEXT_WRITERS.has(name))
|
|
232
|
-
return false;
|
|
233
|
-
return writesMarkdown(words, name);
|
|
234
|
-
}
|
|
235
|
-
function unquote(word) {
|
|
236
|
-
return word.replace(/['"]/g, '');
|
|
237
|
-
}
|
|
238
|
-
// Blank a stretch of data, keeping the newlines (so line-based parsers downstream see the same
|
|
239
|
-
// shape) and — only where the shell still expands them — the substitutions inside it.
|
|
240
|
-
function blankData(text, expands) {
|
|
241
|
-
const blank = text.replace(/[^\n]/g, ' ');
|
|
242
|
-
if (!expands)
|
|
243
|
-
return blank;
|
|
244
|
-
const chars = [...blank];
|
|
245
|
-
for (let i = 0; i < text.length; i++) {
|
|
246
|
-
const ch = text[i];
|
|
247
|
-
// The three constructs the shell still runs inside otherwise-literal text: command
|
|
248
|
-
// substitution (`$(…)`), backticks, and process substitution (`<(…)`/`>(…)`, which runs its
|
|
249
|
-
// command no matter where `cat`'s output goes). Everything else is data. Process substitution
|
|
250
|
-
// only runs UNQUOTED, which is exactly where this `expands` branch lands — a `<(` inside a
|
|
251
|
-
// double-quoted `--body` is literal text and was blanked by the quote handling already.
|
|
252
|
-
let end = -1;
|
|
253
|
-
if (ch === '`')
|
|
254
|
-
end = text.indexOf('`', i + 1);
|
|
255
|
-
else if ((ch === '$' || ch === '<' || ch === '>') && text[i + 1] === '(')
|
|
256
|
-
end = matchParen(text, i + 1);
|
|
257
|
-
else
|
|
258
|
-
continue;
|
|
259
|
-
if (end === -1)
|
|
260
|
-
continue;
|
|
261
|
-
// Keep the substitution, spaces elsewhere: it is the part of this text that runs.
|
|
262
|
-
for (let k = i; k <= end; k++)
|
|
263
|
-
chars[k] = text[k];
|
|
264
|
-
i = end;
|
|
265
|
-
}
|
|
266
|
-
return chars.join('');
|
|
267
|
-
}
|
|
268
|
-
// The `)` that closes the paren at `open`, or -1 when the text never closes it. Single- and
|
|
269
|
-
// double-quoted runs inside are skipped whole so a `)` in a string cannot close the span early —
|
|
270
|
-
// the early close is the direction that would restore text the shell does not run.
|
|
271
|
-
function matchParen(text, open) {
|
|
272
|
-
let depth = 0;
|
|
273
|
-
for (let i = open; i < text.length; i++) {
|
|
274
|
-
const ch = text[i];
|
|
275
|
-
if (ch === "'" || ch === '"') {
|
|
276
|
-
const close = text.indexOf(ch, i + 1);
|
|
277
|
-
if (close === -1)
|
|
278
|
-
return -1;
|
|
279
|
-
i = close;
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
if (ch === '(')
|
|
283
|
-
depth++;
|
|
284
|
-
else if (ch === ')' && --depth === 0)
|
|
285
|
-
return i;
|
|
286
|
-
}
|
|
287
|
-
return -1;
|
|
288
|
-
}
|
package/dist/tools/_net.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { networkInterfaces } from 'node:os';
|
|
2
|
-
// Error codes that mean the NETWORK is down, not the host: name resolution failed outright, or no
|
|
3
|
-
// route exists. A refused connection, a timeout, a TLS failure all name one server's condition and
|
|
4
|
-
// stay per-call — one slow host is not an outage, and a model told "offline" over a single bad
|
|
5
|
-
// server would give up on the next perfectly good URL. This set is what the fetch tool latches a
|
|
6
|
-
// turn on (#392): every further web call would fail the same way, so none of them is worth the
|
|
7
|
-
// round it costs.
|
|
8
|
-
const OFFLINE_CODES = new Set([
|
|
9
|
-
'ENOTFOUND',
|
|
10
|
-
'EAI_AGAIN',
|
|
11
|
-
'ENETUNREACH',
|
|
12
|
-
'EHOSTUNREACH',
|
|
13
|
-
'ENETDOWN',
|
|
14
|
-
]);
|
|
15
|
-
// The `code` on an error or any of its causes. undici wraps a socket failure as
|
|
16
|
-
// `TypeError: fetch failed` with the real error on `cause`, so the top-level message alone says
|
|
17
|
-
// nothing a model can act on; the code is one level down.
|
|
18
|
-
export function errorCode(e) {
|
|
19
|
-
let cur = e;
|
|
20
|
-
for (let depth = 0; depth < 5 && cur && typeof cur === 'object'; depth++) {
|
|
21
|
-
const code = cur.code;
|
|
22
|
-
if (typeof code === 'string')
|
|
23
|
-
return code;
|
|
24
|
-
cur = cur.cause;
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
// The offline code out of an error, or undefined when the failure is host-specific.
|
|
29
|
-
export function offlineCode(e) {
|
|
30
|
-
const code = errorCode(e);
|
|
31
|
-
return code && OFFLINE_CODES.has(code) ? code : undefined;
|
|
32
|
-
}
|
|
33
|
-
// The innermost message of an error chain, for a failure text that names the cause rather than
|
|
34
|
-
// undici's outer "fetch failed".
|
|
35
|
-
export function rootMessage(e) {
|
|
36
|
-
let cur = e;
|
|
37
|
-
let msg = '';
|
|
38
|
-
for (let depth = 0; depth < 5 && cur && typeof cur === 'object'; depth++) {
|
|
39
|
-
const m = cur.message;
|
|
40
|
-
if (typeof m === 'string' && m)
|
|
41
|
-
msg = m;
|
|
42
|
-
cur = cur.cause;
|
|
43
|
-
}
|
|
44
|
-
return msg || String(e);
|
|
45
|
-
}
|
|
46
|
-
// Whether this machine has any route out at all: an interface with a non-loopback, non-link-local
|
|
47
|
-
// address. Zero egress — no probe request — so it costs nothing on an airgapped machine and leaks
|
|
48
|
-
// nothing to anyone. It answers the common case (wifi off, airplane mode) and nothing subtler: a
|
|
49
|
-
// connected router with no upstream reads as online, and the per-turn latch above catches that
|
|
50
|
-
// one on the first failed call. Link-local is excluded on purpose — macOS keeps fe80:: on utun and
|
|
51
|
-
// awdl interfaces with the radio off, so counting it would never say offline.
|
|
52
|
-
export function isOffline(interfaces = networkInterfaces()) {
|
|
53
|
-
for (const addrs of Object.values(interfaces)) {
|
|
54
|
-
for (const a of addrs ?? []) {
|
|
55
|
-
if (a.internal)
|
|
56
|
-
continue;
|
|
57
|
-
if (a.family === 'IPv4' && a.address.startsWith('169.254.'))
|
|
58
|
-
continue;
|
|
59
|
-
if (a.family === 'IPv6' && /^fe[89ab]/i.test(a.address))
|
|
60
|
-
continue;
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
package/dist/tools/_paths.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { lstatSync, readlinkSync, realpathSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
-
import { execFileSync } from 'node:child_process';
|
|
5
|
-
// Resolve a model-supplied path against cwd. Models routinely emit `~/...`
|
|
6
|
-
// paths, which node's resolve() treats as a literal directory named "~".
|
|
7
|
-
export function resolveUserPath(cwd, path) {
|
|
8
|
-
if (path === '~')
|
|
9
|
-
return homedir();
|
|
10
|
-
if (path.startsWith('~/'))
|
|
11
|
-
return resolve(homedir(), path.slice(2));
|
|
12
|
-
return resolve(cwd, path);
|
|
13
|
-
}
|
|
14
|
-
// Pure string form of the test. `relative` returns a `..`-prefixed path for an escape and an
|
|
15
|
-
// absolute one when the two share no root at all (another Windows drive).
|
|
16
|
-
//
|
|
17
|
-
// The `..` check is on a whole segment, not a prefix: `relative('/repo', '/repo/..config/x')` is
|
|
18
|
-
// `'..config/x'`, which a bare startsWith('..') reads as an escape and would refuse a legitimate
|
|
19
|
-
// in-project file whose name begins with two dots.
|
|
20
|
-
function escapesByString(cwd, full) {
|
|
21
|
-
const rel = relative(cwd, full);
|
|
22
|
-
if (rel === '')
|
|
23
|
-
return false;
|
|
24
|
-
return rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel);
|
|
25
|
-
}
|
|
26
|
-
// Realpath the nearest existing ancestor and re-append the tail. A write target usually does not
|
|
27
|
-
// exist yet, so realpath on the whole path would just throw; the parent almost always does.
|
|
28
|
-
function realResolve(p) {
|
|
29
|
-
let head = p;
|
|
30
|
-
const tail = [];
|
|
31
|
-
for (;;) {
|
|
32
|
-
try {
|
|
33
|
-
return resolve(realpathSync.native(head), ...[...tail].reverse());
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
const parent = dirname(head);
|
|
37
|
-
if (parent === head)
|
|
38
|
-
return p; // reached the root without finding anything real
|
|
39
|
-
tail.push(basename(head));
|
|
40
|
-
head = parent;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Whether a resolved path lands outside the project.
|
|
45
|
-
//
|
|
46
|
-
// A string comparison first, and a symlink-resolved one only to ACQUIT. That asymmetry is the
|
|
47
|
-
// point: `process.cwd()` is already symlink-resolved, so on macOS a project reached through
|
|
48
|
-
// `/tmp` (a symlink to `/private/tmp`) has `cwd = /private/tmp/proj`, and a model-supplied
|
|
49
|
-
// `/tmp/proj/x.ts` reads as an escape by string alone — under `bypass` that is a hard refusal of
|
|
50
|
-
// a write into the project itself. Re-testing through real paths clears it.
|
|
51
|
-
//
|
|
52
|
-
// It never runs the other way: a path the string test already calls inside is returned as inside
|
|
53
|
-
// without touching the filesystem. So a symlink INSIDE cwd pointing outward still passes, exactly
|
|
54
|
-
// as before — that is the right trade for a confused model, which is what this guards against. It
|
|
55
|
-
// is not a defense against a determined one, and nothing should be built on top of it as though it
|
|
56
|
-
// were. Kernel-enforced confinement is #163.
|
|
57
|
-
export function escapesProject(cwd, full) {
|
|
58
|
-
if (!escapesByString(cwd, full))
|
|
59
|
-
return false;
|
|
60
|
-
return escapesByString(realResolve(cwd), realResolve(full));
|
|
61
|
-
}
|
|
62
|
-
// The approval warning for a write that lands outside the project, shared so `write` and `edit`
|
|
63
|
-
// raise the identical flag. `warnings` is what makes an approval bypass session-auto-approve
|
|
64
|
-
// (App.tsx hasWarnings), so this is the whole mechanism by which such a write reaches the user at
|
|
65
|
-
// all — under `safe` neither tool passed one, and every write auto-approved to any path.
|
|
66
|
-
//
|
|
67
|
-
// No path in the text: the modal prints the subject directly above it, and repeating it there only
|
|
68
|
-
// pushed the line past the dialog width and wrapped it.
|
|
69
|
-
export const OUTSIDE_PROJECT_WARNING = 'Writes outside the project directory';
|
|
70
|
-
// The approval warning for a write that lands in git's metadata. Same shape and mechanism as
|
|
71
|
-
// `OUTSIDE_PROJECT_WARNING`: under `safe` the warning pierces auto-approve and the user sees a
|
|
72
|
-
// modal; under `bypass` (no `requestApproval`) the write is refused outright. The sandbox half of
|
|
73
|
-
// this class refuses the same paths for every sandboxed command (#706); here a deliberately
|
|
74
|
-
// approved write is allowed, exactly as a user-approved bash command runs unsandboxed — the "user
|
|
75
|
-
// asks the agent to repair a hook" case the sandbox's hard deny would otherwise force into bash.
|
|
76
|
-
export const GIT_METADATA_WARNING = 'Writes to git config or hooks (runs code at your next git command)';
|
|
77
|
-
// The names the sandbox profile refuses (src/tools/_sandbox.ts): any entry named `.git`, the
|
|
78
|
-
// metadata files at its top level and under `modules/`/`worktrees/<x>/`, and the `hooks` subtree.
|
|
79
|
-
// Unanchored, so a repo nested anywhere in the project is covered. Paths are normalized to `/` so
|
|
80
|
-
// a Windows separator cannot dodge the `/`-spelled rules. Case-insensitive because macOS's default
|
|
81
|
-
// volume is: `.git/Config` and `.GIT/hooks/x` write the real files, and on a case-sensitive volume
|
|
82
|
-
// the extra matches are only a prompt.
|
|
83
|
-
const GIT_METADATA_NAME_RE = /\/\.git$|\.git\/((modules\/.+\/|worktrees\/[^/]+\/)?(config|config\.worktree|commondir|gitdir))$|\.git\/(modules\/.+\/)?hooks(\/|$)/i;
|
|
84
|
-
// A common git dir NOT named `.git` (`git init --separate-git-dir`, a dotfiles bare repo) escapes
|
|
85
|
-
// the name rules, the same hole the sandbox's GITDIR param exists for. Protected places are the
|
|
86
|
-
// profile's `GITDIR` deny lines, written against the resolved common dir of the session cwd. This
|
|
87
|
-
// is the cwd's repo only — a git dir a target's OWN tree would resolve to is a separate repo whose
|
|
88
|
-
// paths the name rules still cover when it is a plain `.git` entry. The path is regex-escaped: a
|
|
89
|
-
// cwd may itself contain `.`, `+` or `(` (a dotted project name), and an unescaped one would match
|
|
90
|
-
// broader than the git dir.
|
|
91
|
-
const GIT_DIR_DENY_RE = (g) => {
|
|
92
|
-
const dir = g.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
93
|
-
return new RegExp(`^${dir}$|^${dir}/(config|config\\.worktree|commondir|gitdir)$|^${dir}/hooks(/|$)|^${dir}/worktrees/[^/]+/(config|config\\.worktree|commondir|gitdir)$|^${dir}/modules/.+/(config|config\\.worktree|commondir|gitdir)$|^${dir}/modules/.+/hooks(/|$)`, 'i');
|
|
94
|
-
};
|
|
95
|
-
const commonGitDirs = new Map();
|
|
96
|
-
// The session cwd's common git dir, normalized, or null when there is none. Mirrors the sandbox's
|
|
97
|
-
// `gitDirToBind` (src/tools/_sandbox.ts) minus its "cwd's own `.git`" skip:
|
|
98
|
-
// for the file tools the name rules already cover a `.git`-named dir, and protecting it again here
|
|
99
|
-
// changes nothing, so the skip is a comparison that cannot differ in outcome. A found dir is cached
|
|
100
|
-
// per cwd; a null is not, so a `--separate-git-dir`/bare repo the user creates mid-session is still
|
|
101
|
-
// probed for on the next write.
|
|
102
|
-
function commonGitDir(cwd) {
|
|
103
|
-
const cached = commonGitDirs.get(cwd);
|
|
104
|
-
if (cached !== undefined)
|
|
105
|
-
return cached;
|
|
106
|
-
let dir = null;
|
|
107
|
-
try {
|
|
108
|
-
const out = execFileSync('git', ['rev-parse', '--git-common-dir'], {
|
|
109
|
-
cwd,
|
|
110
|
-
encoding: 'utf8',
|
|
111
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
112
|
-
timeout: 5_000,
|
|
113
|
-
}).trim();
|
|
114
|
-
if (out) {
|
|
115
|
-
// Real path, as the sandbox binds it: git prints a separate git dir already resolved, so a
|
|
116
|
-
// cwd behind a symlink (`/tmp`, `os.tmpdir()`) would otherwise never match it.
|
|
117
|
-
dir = realTarget(resolve(isAbsolute(out) ? out : resolve(cwd, out)));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
// not a repo, or no git — nothing to protect beyond the name rules
|
|
122
|
-
}
|
|
123
|
-
if (dir !== null)
|
|
124
|
-
commonGitDirs.set(cwd, dir);
|
|
125
|
-
return dir;
|
|
126
|
-
}
|
|
127
|
-
// Where a write to `full` actually lands: the real path of its deepest existing ancestor plus the
|
|
128
|
-
// rest, with a dangling symlink followed by hand (writeFile creates its target). The sandbox gets
|
|
129
|
-
// this from the kernel; a string check does not, and a sandboxed `ln -s .git/hooks h` is an
|
|
130
|
-
// ordinary in-project write that would turn `write h/pre-commit` into a hook.
|
|
131
|
-
function realTarget(full) {
|
|
132
|
-
let head = full;
|
|
133
|
-
const tail = [];
|
|
134
|
-
for (let hops = 0; hops < 40; hops++) {
|
|
135
|
-
try {
|
|
136
|
-
return join(realpathSync.native(head), ...tail);
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
// does not exist (yet), or a dangling link — handled below
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
if (lstatSync(head).isSymbolicLink()) {
|
|
143
|
-
head = resolve(dirname(head), readlinkSync(head));
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
// nothing there
|
|
149
|
-
}
|
|
150
|
-
const parent = dirname(head);
|
|
151
|
-
if (parent === head)
|
|
152
|
-
return full;
|
|
153
|
-
tail.unshift(basename(head));
|
|
154
|
-
head = parent;
|
|
155
|
-
}
|
|
156
|
-
return full;
|
|
157
|
-
}
|
|
158
|
-
// Whether a resolved path is git metadata that names a program, and the warning to raise when it
|
|
159
|
-
// is. Undefined for anything else, so the tools' `warnings` arrays stay absent for a normal write.
|
|
160
|
-
// Both the path as written and where it really lands are checked: either one naming git metadata
|
|
161
|
-
// is enough.
|
|
162
|
-
export function gitMetadataWarning(cwd, full) {
|
|
163
|
-
const targets = [...new Set([full, realTarget(full)])].map(p => p.replaceAll('\\', '/'));
|
|
164
|
-
if (targets.some(f => GIT_METADATA_NAME_RE.test(f)))
|
|
165
|
-
return GIT_METADATA_WARNING;
|
|
166
|
-
const g = commonGitDir(cwd);
|
|
167
|
-
if (!g)
|
|
168
|
-
return undefined;
|
|
169
|
-
const deny = GIT_DIR_DENY_RE(g.replaceAll('\\', '/'));
|
|
170
|
-
return targets.some(f => deny.test(f)) ? GIT_METADATA_WARNING : undefined;
|
|
171
|
-
}
|