@alexwkleung/reika 0.2.0 → 0.4.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/agent/loop.js +1 -0
- package/dist/check/typecheck.js +115 -7
- package/dist/cli.js +3 -0
- package/dist/config.js +4 -3
- package/dist/headless.js +27 -2
- package/dist/headlessargs.js +12 -0
- package/dist/provider/modellimits.js +31 -0
- package/dist/session.js +24 -8
- package/dist/tools/_paths.js +105 -2
- package/dist/tools/_sandbox.js +299 -36
- package/dist/tools/_treediff.js +56 -11
- package/dist/tools/bash.js +38 -33
- package/dist/tools/edit.js +19 -6
- package/dist/tools/write.js +21 -6
- package/package.json +1 -1
- package/skills/review.md +8 -2
package/dist/tools/bash.js
CHANGED
|
@@ -4,7 +4,7 @@ import { detectDangerousPatterns } from './_danger.js';
|
|
|
4
4
|
import { scanHeredocs } from './_heredoc.js';
|
|
5
5
|
import { remoteUrlRisk } from './_exfil.js';
|
|
6
6
|
import { declineSummary } from '../approval.js';
|
|
7
|
-
import {
|
|
7
|
+
import { broadWorkdirNotice, isBroadWorkdir, networkAllowedFor, sandboxArgv, sandboxFooter, sandboxNotice, sandboxPlan, refusedWriteLine, } from './_sandbox.js';
|
|
8
8
|
import { recordCapped } from './_spillstats.js';
|
|
9
9
|
import { GH_PLAN_READ_LIST, READ_ONLY_COMMAND_LIST, isProvablyReadOnly } from './_readonly.js';
|
|
10
10
|
import { changesSince, snapshotTree } from './_treediff.js';
|
|
@@ -260,8 +260,8 @@ export const sandboxNoticed = new Set();
|
|
|
260
260
|
// fight it"; this line is where the user learns the flag exists — once, since a Go or Gradle build
|
|
261
261
|
// that needs a home-dir path will refuse on every command until they act on it.
|
|
262
262
|
const sandboxDenialNoticed = new Set();
|
|
263
|
-
const SANDBOX_DENIAL_NOTICE = 'The sandbox refused a write
|
|
264
|
-
'
|
|
263
|
+
const SANDBOX_DENIAL_NOTICE = 'The sandbox refused a write to a path it does not allow (see the command output). If this ' +
|
|
264
|
+
'project needs it, REIKA_SANDBOX=0 turns the sandbox off.';
|
|
265
265
|
export function execStream(command, ctx, sandbox) {
|
|
266
266
|
const timeoutMs = ctx.bashTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
267
267
|
const idleMs = ctx.bashIdleMs ?? DEFAULT_IDLE_MS;
|
|
@@ -276,10 +276,14 @@ export function execStream(command, ctx, sandbox) {
|
|
|
276
276
|
// A UI receipt, never in the model's context (the agent prompt carries the model's copy). Nothing
|
|
277
277
|
// otherwise announces the sandbox, so without this the user's only evidence would be a command
|
|
278
278
|
// that mysteriously failed. Once per cwd, both for the receipt and for the machine-fault warning.
|
|
279
|
-
// Marked shown only when a run completes with it attached (below): an aborted first command
|
|
280
|
-
//
|
|
279
|
+
// Marked shown only when a run completes with it attached (below): an aborted first command must
|
|
280
|
+
// not consume the one receipt this cwd gets.
|
|
281
|
+
//
|
|
282
|
+
// Keyed by the reason as well when there is one: the two network settings are separate profiles,
|
|
283
|
+
// and a receipt the other one already showed must not hide that this one runs unconfined.
|
|
284
|
+
const noticeKey = plan && 'reason' in plan ? `${ctx.cwd}\0${plan.reason}` : ctx.cwd;
|
|
281
285
|
let notice;
|
|
282
|
-
if (plan && !sandboxNoticed.has(
|
|
286
|
+
if (plan && !sandboxNoticed.has(noticeKey)) {
|
|
283
287
|
notice = argv
|
|
284
288
|
? {
|
|
285
289
|
tone: 'info',
|
|
@@ -396,7 +400,24 @@ export function execStream(command, ctx, sandbox) {
|
|
|
396
400
|
proc.on('close', (code, signal) => {
|
|
397
401
|
cleanup();
|
|
398
402
|
const rawOutput = buffer.join('');
|
|
399
|
-
const
|
|
403
|
+
const capped = totalBytes >= MAX_PAYLOAD_BYTES;
|
|
404
|
+
const truncated = capped ? '\n…(truncated)' : '';
|
|
405
|
+
// #723: a denial printed after the 64KB head is still a denial. The spill window holds the last
|
|
406
|
+
// 4MB, so a refusal in one package of a `pnpm -r build` followed by 20KB of the others' logs is
|
|
407
|
+
// still seen; with spill off only the 4KB `uiTail` is retained. Only the refused-write check
|
|
408
|
+
// reads past the head: the ps and network notes stay on the output the model was shown, since
|
|
409
|
+
// loose words like `ENOTFOUND` in 4MB of a red test suite would blame the sandbox for a
|
|
410
|
+
// genuine failure. Joined once and reused by the spill below.
|
|
411
|
+
const retained = spilling ? tail : uiTail;
|
|
412
|
+
const tailText = capped ? retained.text() : '';
|
|
413
|
+
// The window is chunk-granular, so its first line may be the back half of one: cut off, a prose
|
|
414
|
+
// line (`we tried to open /x/y: operation not permitted`) reads as a refusal.
|
|
415
|
+
const scanned = !capped
|
|
416
|
+
? rawOutput
|
|
417
|
+
: retained.bytes >= rawBytes
|
|
418
|
+
? tailText
|
|
419
|
+
: `${rawOutput}\n${tailText.slice(tailText.indexOf('\n') + 1)}`;
|
|
420
|
+
const refusedWrite = argv ? refusedWriteLine(scanned) : null;
|
|
400
421
|
// The sandbox-aware half (#163). Seatbelt's network denials never say "permission" — curl
|
|
401
422
|
// reports a DNS failure, git/npm report credentials or proxy problems — so a headerless failure
|
|
402
423
|
// reads to a model as a bug in its own command and sets up the classic spiral. Keyed on the
|
|
@@ -406,16 +427,20 @@ export function execStream(command, ctx, sandbox) {
|
|
|
406
427
|
searchHint(command, rawOutput) +
|
|
407
428
|
heredocSubstitutionHint(command, code, rawOutput) +
|
|
408
429
|
(argv && sandbox
|
|
409
|
-
? sandboxFooter(command, code, rawOutput, {
|
|
430
|
+
? sandboxFooter(command, code, rawOutput, {
|
|
431
|
+
...sandbox,
|
|
432
|
+
toolNames: ctx.toolNames,
|
|
433
|
+
refusedWrite,
|
|
434
|
+
})
|
|
410
435
|
: '');
|
|
411
436
|
// Built from the retained tail, not the payload head: the chip is the user's answer to "how
|
|
412
437
|
// did it end?", which the head cannot give once a run passes the cap.
|
|
413
438
|
const display = buildCommandDisplay(command, uiTail.text(), rawBytes > uiTail.bytes);
|
|
414
439
|
if (notice && plan)
|
|
415
|
-
sandboxNoticed.add(
|
|
440
|
+
sandboxNoticed.add(noticeKey);
|
|
416
441
|
// On the output's shape, not the exit status: `mkdir ~/x; echo ok` exits 0 with the denial in
|
|
417
442
|
// its output, and the user would otherwise never learn the flag exists.
|
|
418
|
-
if (
|
|
443
|
+
if (refusedWrite !== null && !sandboxDenialNoticed.has(ctx.cwd)) {
|
|
419
444
|
sandboxDenialNoticed.add(ctx.cwd);
|
|
420
445
|
notice = {
|
|
421
446
|
tone: 'warn',
|
|
@@ -460,28 +485,8 @@ export function execStream(command, ctx, sandbox) {
|
|
|
460
485
|
});
|
|
461
486
|
}
|
|
462
487
|
};
|
|
463
|
-
//
|
|
464
|
-
//
|
|
465
|
-
// every command into an uninterpretable failure. Retried unsandboxed, exactly once — and said,
|
|
466
|
-
// as a warn: a command that ran unconfined after the sandbox refused to load is the one event
|
|
467
|
-
// here the user must see, and the one that points at a generator bug.
|
|
468
|
-
if (argv &&
|
|
469
|
-
code === SANDBOX_PROFILE_ERROR_CODE &&
|
|
470
|
-
rawOutput.includes(SANDBOX_EXEC_ERROR_PREFIX)) {
|
|
471
|
-
execStream(command, ctx).then(r => resolve({
|
|
472
|
-
...r,
|
|
473
|
-
notice: {
|
|
474
|
-
tone: 'warn',
|
|
475
|
-
content: [
|
|
476
|
-
r.notice?.content,
|
|
477
|
-
`Not sandboxed: the sandbox profile failed to load (sandbox-exec exit ${code}); re-ran unsandboxed: ${command}`,
|
|
478
|
-
]
|
|
479
|
-
.filter(Boolean)
|
|
480
|
-
.join('\n'),
|
|
481
|
-
},
|
|
482
|
-
}));
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
488
|
+
// No retry on exit 65: `sandboxPlan` has already proved this profile loads (#738), so a 65
|
|
489
|
+
// here is the command's own, and re-running it unsandboxed is what a fake refusal was after.
|
|
485
490
|
// Recorded whether or not spilling is on: the question this answers is how often bash
|
|
486
491
|
// output exceeds the cap at all, which is a property of the workload, not of the flag. The
|
|
487
492
|
// spilling arm records below instead, after the write, so `spilled` reports whether an
|
|
@@ -497,7 +502,7 @@ export function execStream(command, ctx, sandbox) {
|
|
|
497
502
|
}
|
|
498
503
|
void (async () => {
|
|
499
504
|
const complete = tail.bytes >= rawBytes;
|
|
500
|
-
const ref = await spillResult('bash',
|
|
505
|
+
const ref = await spillResult('bash', tailText);
|
|
501
506
|
recordCapped({
|
|
502
507
|
tool: 'bash',
|
|
503
508
|
total: rawBytes,
|
package/dist/tools/edit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { relative } from 'node:path';
|
|
3
|
-
import { escapesProject, OUTSIDE_PROJECT_WARNING, resolveUserPath } from './_paths.js';
|
|
3
|
+
import { escapesProject, gitMetadataWarning, OUTSIDE_PROJECT_WARNING, resolveUserPath, } from './_paths.js';
|
|
4
4
|
import { buildEditDiff, editDiffStartLine } from './_diff.js';
|
|
5
5
|
import { surfaceImportedDeps } from './_deps.js';
|
|
6
6
|
import { groundUrls } from './_urls.js';
|
|
@@ -26,6 +26,12 @@ export const editTool = {
|
|
|
26
26
|
const newStr = String(args.new_string ?? '');
|
|
27
27
|
const full = resolveUserPath(ctx.cwd, path);
|
|
28
28
|
const outside = escapesProject(ctx.cwd, full);
|
|
29
|
+
// Git config and hooks name programs something else runs, so they carry a warning the same way
|
|
30
|
+
// an out-of-project path does (#719). Combined into one `warnings` list so a path that is both
|
|
31
|
+
// (an outside repo's `.git/config`) raises each flag once, in one modal.
|
|
32
|
+
const gitMeta = gitMetadataWarning(ctx.cwd, full);
|
|
33
|
+
const gated = outside || gitMeta !== undefined;
|
|
34
|
+
const warnings = [...(outside ? [OUTSIDE_PROJECT_WARNING] : []), ...(gitMeta ? [gitMeta] : [])];
|
|
29
35
|
// See write.ts for why these are two names. `rel` stays project-relative because it rides
|
|
30
36
|
// `diff.path`, which App.tsx hands to addFileToIndex -> ignore (a RangeError on an absolute
|
|
31
37
|
// path); `display` is what the user and the model see.
|
|
@@ -33,10 +39,17 @@ export const editTool = {
|
|
|
33
39
|
const display = outside ? full : rel;
|
|
34
40
|
// See write.ts — the same gap, the same gate. Checked before the file is read so the boundary is
|
|
35
41
|
// reported instead of an incidental read error on a path we would refuse anyway.
|
|
36
|
-
if (
|
|
42
|
+
if (gated && !ctx.requestApproval) {
|
|
43
|
+
if (outside) {
|
|
44
|
+
return {
|
|
45
|
+
summary: `Edit refused: ${full} is outside the project directory (${ctx.cwd}), and approvals ` +
|
|
46
|
+
'are bypassed so it cannot be confirmed with the user. Edit inside the project instead.',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
37
49
|
return {
|
|
38
|
-
summary: `Edit refused: ${
|
|
39
|
-
'are bypassed so it cannot be confirmed with the user
|
|
50
|
+
summary: `Edit refused: ${display} is git config or a hook, which runs code at the user's next ` +
|
|
51
|
+
'git command. Approvals are bypassed so it cannot be confirmed with the user; edit a ' +
|
|
52
|
+
'project file instead, or leave the change for the user.',
|
|
40
53
|
};
|
|
41
54
|
}
|
|
42
55
|
if (oldStr === '') {
|
|
@@ -58,12 +71,12 @@ export const editTool = {
|
|
|
58
71
|
// below, which no longer re-raises the warning — the boundary was consented to here, so under
|
|
59
72
|
// `safe` that second one auto-approves and this stays a single modal.
|
|
60
73
|
let approvedOutside = false;
|
|
61
|
-
if (
|
|
74
|
+
if (gated && ctx.requestApproval) {
|
|
62
75
|
const ok = await ctx.requestApproval({
|
|
63
76
|
tool: 'edit',
|
|
64
77
|
subject: display,
|
|
65
78
|
preview: intentDiff(oldStr, newStr),
|
|
66
|
-
warnings
|
|
79
|
+
warnings,
|
|
67
80
|
});
|
|
68
81
|
if (!ok)
|
|
69
82
|
return { summary: declineSummary('Edit', ` for ${display}`, ctx) };
|
package/dist/tools/write.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, stat, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, relative } from 'node:path';
|
|
3
|
-
import { escapesProject, OUTSIDE_PROJECT_WARNING, resolveUserPath } from './_paths.js';
|
|
3
|
+
import { escapesProject, gitMetadataWarning, OUTSIDE_PROJECT_WARNING, resolveUserPath, } from './_paths.js';
|
|
4
4
|
import { buildWriteDiff } from './_diff.js';
|
|
5
5
|
import { surfaceImportedDeps } from './_deps.js';
|
|
6
6
|
import { groundUrls } from './_urls.js';
|
|
@@ -21,6 +21,12 @@ export const writeTool = {
|
|
|
21
21
|
const content = String(args.content ?? '');
|
|
22
22
|
const full = resolveUserPath(ctx.cwd, path);
|
|
23
23
|
const outside = escapesProject(ctx.cwd, full);
|
|
24
|
+
// Git config and hooks name programs something else runs, so they carry a warning the same way
|
|
25
|
+
// an out-of-project path does (#719). Combined into one `warnings` list so a path that is both
|
|
26
|
+
// (an outside repo's `.git/config`) raises each flag once, in one modal.
|
|
27
|
+
const gitMeta = gitMetadataWarning(ctx.cwd, full);
|
|
28
|
+
const gated = outside || gitMeta !== undefined;
|
|
29
|
+
const warnings = [...(outside ? [OUTSIDE_PROJECT_WARNING] : []), ...(gitMeta ? [gitMeta] : [])];
|
|
24
30
|
// Two names for the same file, deliberately. `rel` stays project-relative because it is what
|
|
25
31
|
// rides `diff.path`, and App.tsx feeds that straight to addFileToIndex -> ignore, which throws
|
|
26
32
|
// a RangeError on an absolute path. `display` is the human- and model-facing string: an
|
|
@@ -32,10 +38,19 @@ export const writeTool = {
|
|
|
32
38
|
// passed `warnings`, so under `safe` every write auto-approved to any path `resolveUserPath`
|
|
33
39
|
// would produce — `~/.zshrc` included. Under `bypass` there is no modal to fall through to, so
|
|
34
40
|
// the only honest answer is no; the model is told why, and that the project is where to write.
|
|
35
|
-
|
|
41
|
+
// Git metadata gets the same treatment: bypassed, there is nobody to clear a hook write, so it
|
|
42
|
+
// is refused rather than landed (#719).
|
|
43
|
+
if (gated && !ctx.requestApproval) {
|
|
44
|
+
if (outside) {
|
|
45
|
+
return {
|
|
46
|
+
summary: `Write refused: ${full} is outside the project directory (${ctx.cwd}), and approvals ` +
|
|
47
|
+
'are bypassed so it cannot be confirmed with the user. Write inside the project instead.',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
36
50
|
return {
|
|
37
|
-
summary: `Write refused: ${
|
|
38
|
-
'are bypassed so it cannot be confirmed with the user
|
|
51
|
+
summary: `Write refused: ${display} is git config or a hook, which runs code at the user's next ` +
|
|
52
|
+
'git command. Approvals are bypassed so it cannot be confirmed with the user; write a ' +
|
|
53
|
+
'project file instead, or leave the change for the user.',
|
|
39
54
|
};
|
|
40
55
|
}
|
|
41
56
|
const diffText = buildWriteDiff(content);
|
|
@@ -45,13 +60,13 @@ export const writeTool = {
|
|
|
45
60
|
// model's own content, not the file's, so gating early loses no information. Inside the
|
|
46
61
|
// project the order is unchanged.
|
|
47
62
|
let approved = false;
|
|
48
|
-
if (
|
|
63
|
+
if (gated && ctx.requestApproval) {
|
|
49
64
|
const ok = await ctx.requestApproval({
|
|
50
65
|
tool: 'write',
|
|
51
66
|
subject: display,
|
|
52
67
|
preview: diffText,
|
|
53
68
|
startLine: 1,
|
|
54
|
-
warnings
|
|
69
|
+
warnings,
|
|
55
70
|
});
|
|
56
71
|
if (!ok)
|
|
57
72
|
return { summary: declineSummary('Write', ` for ${display}`, ctx) };
|
package/package.json
CHANGED
package/skills/review.md
CHANGED
|
@@ -23,8 +23,14 @@ straight on to the diff.
|
|
|
23
23
|
|
|
24
24
|
If output comes back it is the linked issue, in the same JSON shape as before:
|
|
25
25
|
`body` may be empty, and then the content is in `comments`. The issue may itself
|
|
26
|
-
reference other numbers (`#179`, `#185`).
|
|
27
|
-
|
|
26
|
+
reference other numbers (`#179`, `#185`). Most are background — leave them. Read
|
|
27
|
+
one only when this issue does not state the requirement itself: its body sends
|
|
28
|
+
you elsewhere for it ("see #179", "as described in #185", "follow-up to #179"),
|
|
29
|
+
or is too short to say what is wanted. Then run, once, for that one number:
|
|
30
|
+
|
|
31
|
+
gh issue view <that number> --json title,body
|
|
32
|
+
|
|
33
|
+
and go on. Do not follow any number that second issue mentions.
|
|
28
34
|
|
|
29
35
|
Then, before any other call, write one or two sentences in your reply saying what
|
|
30
36
|
the issue asks for — not what the PR does, the requirement. Later tool output can
|