talentos 1.2.0 → 1.3.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/adapters.js +8 -0
- package/dist/agent/gateway.js +7 -1
- package/dist/agent/native/approvals.js +53 -1
- package/dist/agent/native/codex-owner-probe.js +389 -0
- package/dist/agent/native/codex-owner.js +160 -0
- package/dist/agent/native/context.js +92 -0
- package/dist/agent/native/gate.js +11 -1
- package/dist/agent/native/hook-entry.js +65 -3
- package/dist/agent/native/launch.js +10 -1
- package/dist/agent/native/policy.js +283 -20
- package/dist/agent/native/probe.js +18 -15
- package/dist/agent/native/receipts.js +47 -0
- package/dist/agent/native/touch.js +143 -0
- package/dist/agent/serve.js +47 -2
- package/dist/agent-service.js +14 -1
- package/dist/commands/agent-native.js +2 -2
- package/dist/gateway-install.js +15 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ const GREP_R = /^-\w*[rR]|^--recursive|^--dereference-recursive/u;
|
|
|
7
7
|
const LS_R = /^-\w*R|^--recursive/u;
|
|
8
8
|
const PATTERN_FLAG = /^-\w*e|^--regexp|^-\w*f|^--file/u;
|
|
9
9
|
const GLOB_CHARS = /[*?[{]/u;
|
|
10
|
+
const PATH_IN_FLAG = /[/~]/u;
|
|
10
11
|
const ASK = "This needs the owner's approval, which isn't available yet. Tell the owner in your reply what you wanted to do and why. Do not retry or work around it.";
|
|
11
12
|
const BLOCKED = "Blocked: this touches credentials or the settings that protect this session. Do not retry or work around it.";
|
|
12
13
|
const allow = (mutates = false) => ({ allow: true, mutates });
|
|
@@ -210,8 +211,11 @@ const SECRET_PROGRAMS = new Set([
|
|
|
210
211
|
"ssh-keygen",
|
|
211
212
|
]);
|
|
212
213
|
const READ_ONLY = {
|
|
214
|
+
awk: { paths: "after-pattern", valid: awkIsPrint },
|
|
213
215
|
basename: { paths: "none" },
|
|
214
216
|
cat: { paths: "all" },
|
|
217
|
+
column: { paths: "all" },
|
|
218
|
+
comm: { paths: "all" },
|
|
215
219
|
cut: { paths: "all" },
|
|
216
220
|
date: { badFlags: /^-s|^--set/u, paths: "none" },
|
|
217
221
|
df: { paths: "all" },
|
|
@@ -224,6 +228,7 @@ const READ_ONLY = {
|
|
|
224
228
|
echo: { paths: "none" },
|
|
225
229
|
false: { paths: "none" },
|
|
226
230
|
file: { badFlags: /^-C|^-m|^--magic/u, paths: "all" },
|
|
231
|
+
fold: { paths: "all" },
|
|
227
232
|
find: {
|
|
228
233
|
badFlags: /^-(exec|execdir|ok|okdir|delete|fprint0?|fprintf|fls)$/u,
|
|
229
234
|
paths: "find",
|
|
@@ -234,10 +239,18 @@ const READ_ONLY = {
|
|
|
234
239
|
recursive: (a) => a.some((x) => GREP_R.test(x)),
|
|
235
240
|
},
|
|
236
241
|
head: { paths: "all" },
|
|
242
|
+
hexdump: { paths: "all" },
|
|
243
|
+
hostname: { paths: "none" },
|
|
244
|
+
id: { paths: "none" },
|
|
245
|
+
jq: { paths: "after-pattern", valid: jqIsRead },
|
|
237
246
|
ls: {
|
|
238
247
|
paths: "all",
|
|
239
248
|
recursive: (a) => a.some((x) => LS_R.test(x)),
|
|
240
249
|
},
|
|
250
|
+
md5sum: { paths: "all" },
|
|
251
|
+
nl: { paths: "all" },
|
|
252
|
+
od: { paths: "all" },
|
|
253
|
+
paste: { paths: "all" },
|
|
241
254
|
printf: { paths: "none" },
|
|
242
255
|
pwd: { paths: "none" },
|
|
243
256
|
readlink: { paths: "all" },
|
|
@@ -247,21 +260,95 @@ const READ_ONLY = {
|
|
|
247
260
|
paths: "after-pattern",
|
|
248
261
|
recursive: () => true,
|
|
249
262
|
},
|
|
263
|
+
rev: { paths: "all" },
|
|
264
|
+
sed: { paths: "after-pattern", valid: sedIsPrint },
|
|
265
|
+
sha1sum: { paths: "all" },
|
|
266
|
+
sha256sum: { paths: "all" },
|
|
267
|
+
shasum: { paths: "all" },
|
|
268
|
+
sleep: { paths: "none" },
|
|
250
269
|
sort: { badFlags: /^-o|^--output|^--compress-program/u, paths: "all" },
|
|
251
270
|
stat: { paths: "all" },
|
|
271
|
+
tac: { paths: "all" },
|
|
252
272
|
tail: { badFlags: /^-\w*f|^--follow/u, paths: "all" },
|
|
273
|
+
test: { paths: "all" },
|
|
253
274
|
tr: { paths: "none" },
|
|
254
275
|
tree: { badFlags: /^-o$/u, paths: "all", recursive: () => true },
|
|
255
276
|
true: { paths: "none" },
|
|
277
|
+
uname: { paths: "none" },
|
|
256
278
|
uniq: { paths: "all" },
|
|
257
279
|
wc: { paths: "all" },
|
|
258
280
|
which: { paths: "none" },
|
|
281
|
+
whoami: { paths: "none" },
|
|
282
|
+
xxd: { paths: "all" },
|
|
259
283
|
};
|
|
284
|
+
// sed, awk and jq can run code or write files, so only plain "print what matches"
|
|
285
|
+
// scripts pass; anything else is an ordinary ask. The script is the first
|
|
286
|
+
// positional word; the rest are files.
|
|
287
|
+
const SED_FLAGS = new Set(["-E", "-n", "-r", "-s", "--quiet", "--silent"]);
|
|
288
|
+
const SED_SCRIPT = /^(?:\d+|\$)(?:,(?:\d+|\$))?p$|^\/[^/]+\/p$|^s([^\\\n])(?:(?!\1)[^\\]|\\.)*\1(?:(?!\1)[^\\]|\\.)*\1[gIip]*$/u;
|
|
289
|
+
const AWK_SCRIPT = /^\{\s*print(?:\s+\$(?:\d+|NF))?(?:\s*,\s*\$(?:\d+|NF))*\s*\}$/u;
|
|
290
|
+
const AWK_FLAG = /^-F[^\w\s'"\\]$|^-F\\t$/u;
|
|
291
|
+
const JQ_FLAGS = new Set([
|
|
292
|
+
"-C",
|
|
293
|
+
"-M",
|
|
294
|
+
"-S",
|
|
295
|
+
"-a",
|
|
296
|
+
"-c",
|
|
297
|
+
"-e",
|
|
298
|
+
"-j",
|
|
299
|
+
"-n",
|
|
300
|
+
"-r",
|
|
301
|
+
"-s",
|
|
302
|
+
"--compact-output",
|
|
303
|
+
"--exit-status",
|
|
304
|
+
"--join-output",
|
|
305
|
+
"--null-input",
|
|
306
|
+
"--raw-output",
|
|
307
|
+
"--slurp",
|
|
308
|
+
"--sort-keys",
|
|
309
|
+
]);
|
|
310
|
+
// env/$ENV print secrets; input* and import read other files; debug/stderr leak.
|
|
311
|
+
const JQ_BAD_WORD = /\b(?:ENV|env|import|include|input|inputs|input_filename|debug|stderr|halt_error)\b/u;
|
|
312
|
+
function firstPositional(args) {
|
|
313
|
+
return args.find((word) => !isFlag(word));
|
|
314
|
+
}
|
|
315
|
+
function sedIsPrint(args) {
|
|
316
|
+
const script = firstPositional(args);
|
|
317
|
+
return (args.filter(isFlag).every((flag) => SED_FLAGS.has(flag.text)) &&
|
|
318
|
+
script !== undefined &&
|
|
319
|
+
!script.glob &&
|
|
320
|
+
SED_SCRIPT.test(script.text));
|
|
321
|
+
}
|
|
322
|
+
function awkIsPrint(args) {
|
|
323
|
+
const script = firstPositional(args);
|
|
324
|
+
return (args.filter(isFlag).every((flag) => AWK_FLAG.test(flag.text)) &&
|
|
325
|
+
script !== undefined &&
|
|
326
|
+
AWK_SCRIPT.test(script.text));
|
|
327
|
+
}
|
|
328
|
+
function jqIsRead(args) {
|
|
329
|
+
const script = firstPositional(args);
|
|
330
|
+
return (args.filter(isFlag).every((flag) => JQ_FLAGS.has(flag.text)) &&
|
|
331
|
+
script !== undefined &&
|
|
332
|
+
!JQ_BAD_WORD.test(script.text));
|
|
333
|
+
}
|
|
260
334
|
const RUNNER_SCRIPTS = new Set(["build", "check", "lint", "test", "typecheck"]);
|
|
261
335
|
const SAFE_ARG = /^--?[A-Za-z][\w-]*(=[\w./:@-]+)?$|^--$/u;
|
|
262
336
|
function isFlag(word) {
|
|
263
337
|
return word.text.startsWith("-") && word.text !== "-";
|
|
264
338
|
}
|
|
339
|
+
// A flag can carry a path: `--files0-from=/x`, `--file=/x`, `-f/x`. Each one is
|
|
340
|
+
// read like a positional path, so a protected file cannot hide in a flag value.
|
|
341
|
+
function flagPathWords(args) {
|
|
342
|
+
const words = [];
|
|
343
|
+
for (const word of args.filter(isFlag)) {
|
|
344
|
+
const equals = word.text.indexOf("=");
|
|
345
|
+
const start = equals > 0 ? equals + 1 : word.text.slice(2).search(PATH_IN_FLAG) + 2;
|
|
346
|
+
if (start > (equals > 0 ? 0 : 1) && start < word.text.length) {
|
|
347
|
+
words.push({ glob: word.glob, text: word.text.slice(start) });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return words;
|
|
351
|
+
}
|
|
265
352
|
function pathCheck(word, ctx, recursive) {
|
|
266
353
|
if (word.glob) {
|
|
267
354
|
// A glob can only be judged by its literal directory; keep it inside cwd.
|
|
@@ -286,6 +373,15 @@ function classifyReadOnly(spec, args, ctx) {
|
|
|
286
373
|
if (spec.badFlags && flags.some((flag) => spec.badFlags?.test(flag))) {
|
|
287
374
|
return deny(2);
|
|
288
375
|
}
|
|
376
|
+
if (spec.valid && !spec.valid(args)) {
|
|
377
|
+
return deny(2);
|
|
378
|
+
}
|
|
379
|
+
for (const word of flagPathWords(args)) {
|
|
380
|
+
const refused = pathCheck(word, ctx, false);
|
|
381
|
+
if (refused) {
|
|
382
|
+
return refused;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
289
385
|
const recursive = spec.recursive?.(flags) ?? false;
|
|
290
386
|
let targets = [];
|
|
291
387
|
if (spec.paths === "all") {
|
|
@@ -364,39 +460,125 @@ function classifyRunner(args, ctx) {
|
|
|
364
460
|
const GIT_READ = new Set([
|
|
365
461
|
"blame",
|
|
366
462
|
"branch",
|
|
463
|
+
"cat-file",
|
|
367
464
|
"describe",
|
|
368
465
|
"diff",
|
|
466
|
+
"diff-tree",
|
|
467
|
+
"for-each-ref",
|
|
468
|
+
"grep",
|
|
369
469
|
"log",
|
|
370
470
|
"ls-files",
|
|
471
|
+
"ls-tree",
|
|
472
|
+
"merge-base",
|
|
473
|
+
"name-rev",
|
|
474
|
+
"reflog",
|
|
475
|
+
"remote",
|
|
476
|
+
"rev-list",
|
|
371
477
|
"rev-parse",
|
|
372
478
|
"shortlog",
|
|
373
479
|
"show",
|
|
480
|
+
"show-ref",
|
|
481
|
+
"stash",
|
|
374
482
|
"status",
|
|
483
|
+
"tag",
|
|
484
|
+
"worktree",
|
|
375
485
|
]);
|
|
376
|
-
const GIT_BAD_FLAG = /^(--output|-c$|-C$|--exec-path|--upload-pack|--git-dir|--work-tree|--no-index|--ext-diff|--textconv|--open-files-in-pager|-O)/u;
|
|
486
|
+
const GIT_BAD_FLAG = /^(--output|-c$|-C$|--config-env|--exec-path|--upload-pack|--git-dir|--work-tree|--no-index|--ext-diff|--textconv|--filters|--open-files-in-pager|-O)/u;
|
|
377
487
|
const GIT_LIST_FLAG = /^(-a|-r|-v|-vv|--all|--remotes|--list|--show-current)$/u;
|
|
488
|
+
// Global options that cannot run anything. -c, --config-env, --exec-path and
|
|
489
|
+
// aliases can, so they stay asks; GIT_* env assignments never parse.
|
|
490
|
+
const GIT_GLOBAL_OK = new Set([
|
|
491
|
+
"--literal-pathspecs",
|
|
492
|
+
"--no-optional-locks",
|
|
493
|
+
"--no-pager",
|
|
494
|
+
"-P",
|
|
495
|
+
]);
|
|
496
|
+
const GIT_DIR_FLAG = /^--(?:git-dir|work-tree)=(.+)$/u;
|
|
497
|
+
// `git [globals] <sub> ...`: only the globals above are understood.
|
|
498
|
+
function splitGit(args) {
|
|
499
|
+
const dirs = [];
|
|
500
|
+
let index = 0;
|
|
501
|
+
while (index < args.length && isFlag(args[index])) {
|
|
502
|
+
const word = args[index];
|
|
503
|
+
const next = args[index + 1];
|
|
504
|
+
const attached = GIT_DIR_FLAG.exec(word.text);
|
|
505
|
+
if (GIT_GLOBAL_OK.has(word.text)) {
|
|
506
|
+
index += 1;
|
|
507
|
+
}
|
|
508
|
+
else if (attached?.[1]) {
|
|
509
|
+
dirs.push({ chdir: false, word: { glob: word.glob, text: attached[1] } });
|
|
510
|
+
index += 1;
|
|
511
|
+
}
|
|
512
|
+
else if (["-C", "--git-dir", "--work-tree"].includes(word.text) &&
|
|
513
|
+
next &&
|
|
514
|
+
!isFlag(next)) {
|
|
515
|
+
dirs.push({ chdir: word.text === "-C", word: next });
|
|
516
|
+
index += 2;
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
return { dirs, ok: false, rest: [] };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return { dirs, ok: true, rest: args.slice(index + 1), sub: args[index] };
|
|
523
|
+
}
|
|
524
|
+
// Subcommands that also write take a read-only form: check it.
|
|
525
|
+
function gitSubIsRead(sub, rest) {
|
|
526
|
+
const flags = rest.filter(isFlag).map((word) => word.text);
|
|
527
|
+
const positional = rest.filter((word) => !isFlag(word)).map((w) => w.text);
|
|
528
|
+
switch (sub) {
|
|
529
|
+
case "branch":
|
|
530
|
+
// `git branch NAME` creates a branch; only the listing forms pass.
|
|
531
|
+
return (positional.length === 0 && flags.every((f) => GIT_LIST_FLAG.test(f)));
|
|
532
|
+
case "tag":
|
|
533
|
+
return flags.some((f) => f === "-l" || f === "--list");
|
|
534
|
+
case "remote":
|
|
535
|
+
return (flags.every((f) => f === "-v" || f === "--verbose") &&
|
|
536
|
+
(positional.length === 0 || positional[0] === "get-url"));
|
|
537
|
+
case "stash":
|
|
538
|
+
return positional[0] === "list" || positional[0] === "show";
|
|
539
|
+
case "worktree":
|
|
540
|
+
return positional[0] === "list";
|
|
541
|
+
case "reflog":
|
|
542
|
+
return positional.length === 0 || positional[0] === "show";
|
|
543
|
+
default:
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
378
547
|
function classifyGit(args, ctx) {
|
|
379
|
-
const
|
|
380
|
-
|
|
548
|
+
const git = splitGit(args);
|
|
549
|
+
const { sub, rest } = git;
|
|
550
|
+
if (!(git.ok && sub && GIT_READ.has(sub.text))) {
|
|
381
551
|
return deny(2);
|
|
382
552
|
}
|
|
383
553
|
const flags = rest.filter(isFlag);
|
|
384
|
-
|
|
385
|
-
|
|
554
|
+
if (flags.some((flag) => GIT_BAD_FLAG.test(flag.text)) ||
|
|
555
|
+
!gitSubIsRead(sub.text, rest)) {
|
|
386
556
|
return deny(2);
|
|
387
557
|
}
|
|
388
|
-
|
|
389
|
-
if (sub.text === "branch" &&
|
|
390
|
-
(positional.length > 0 ||
|
|
391
|
-
flags.some((flag) => !GIT_LIST_FLAG.test(flag.text)))) {
|
|
392
|
-
return deny(2);
|
|
393
|
-
}
|
|
394
|
-
for (const word of positional) {
|
|
558
|
+
for (const word of flagPathWords(rest)) {
|
|
395
559
|
const refused = pathCheck(word, ctx, false);
|
|
396
560
|
if (refused) {
|
|
397
561
|
return refused;
|
|
398
562
|
}
|
|
399
563
|
}
|
|
564
|
+
// `-C dir` and friends read that path: the same check as `cat dir/x`. Later
|
|
565
|
+
// paths resolve against the directory `-C` moved into.
|
|
566
|
+
let local = ctx;
|
|
567
|
+
for (const { chdir, word } of git.dirs) {
|
|
568
|
+
const refused = pathCheck(word, local, false);
|
|
569
|
+
if (refused) {
|
|
570
|
+
return refused;
|
|
571
|
+
}
|
|
572
|
+
if (chdir) {
|
|
573
|
+
local = { ...local, cwd: canonical(word.text, local.cwd, local.home) };
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
for (const word of rest.filter((word) => !isFlag(word))) {
|
|
577
|
+
const refused = pathCheck(word, local, false);
|
|
578
|
+
if (refused) {
|
|
579
|
+
return refused;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
400
582
|
return allow();
|
|
401
583
|
}
|
|
402
584
|
// What an always-allow rule can name: local repository work the owner expects
|
|
@@ -451,12 +633,19 @@ function shellAsk(command, ctx) {
|
|
|
451
633
|
return { kind: "shell:script", tier: 1 };
|
|
452
634
|
}
|
|
453
635
|
if (program === "git") {
|
|
454
|
-
const
|
|
455
|
-
const
|
|
456
|
-
|
|
636
|
+
const git = splitGit(args);
|
|
637
|
+
const sub = git.ok ? (git.sub?.text ?? "") : "";
|
|
638
|
+
const badFlag = git.rest.some((word) => isFlag(word) && GIT_BAD_FLAG.test(word.text));
|
|
639
|
+
// A change to another repository is not the workspace's own work.
|
|
640
|
+
const elsewhere = git.dirs.some(({ word }) => word.glob ||
|
|
641
|
+
!ctx.writeRoots.some((root) => isInside(canonical(word.text, ctx.cwd, ctx.home), root)));
|
|
642
|
+
if (!(git.ok && GIT_TIER2.has(sub)) || badFlag || elsewhere) {
|
|
457
643
|
return { kind: `git:${sub || "?"}`, tier: 1 };
|
|
458
644
|
}
|
|
459
|
-
return {
|
|
645
|
+
return {
|
|
646
|
+
kind: `git:${sub}`,
|
|
647
|
+
tier: sub === "push" ? gitPushTier([git.sub, ...git.rest]) : 2,
|
|
648
|
+
};
|
|
460
649
|
}
|
|
461
650
|
if (FILE_UTILS.has(program)) {
|
|
462
651
|
const inside = args
|
|
@@ -486,6 +675,40 @@ function shellAsk(command, ctx) {
|
|
|
486
675
|
}
|
|
487
676
|
return { kind: `shell:${program}`, tier: 1 };
|
|
488
677
|
}
|
|
678
|
+
const VERSION_PROGRAMS = new Set([
|
|
679
|
+
"bun",
|
|
680
|
+
"cargo",
|
|
681
|
+
"claude",
|
|
682
|
+
"deno",
|
|
683
|
+
"git",
|
|
684
|
+
"node",
|
|
685
|
+
"npm",
|
|
686
|
+
"pip",
|
|
687
|
+
"pip3",
|
|
688
|
+
"pnpm",
|
|
689
|
+
"python",
|
|
690
|
+
"python3",
|
|
691
|
+
"rustc",
|
|
692
|
+
"yarn",
|
|
693
|
+
]);
|
|
694
|
+
// `node --version`, `go version`: asking a tool who it is runs nothing else.
|
|
695
|
+
function isVersionQuery(program, args) {
|
|
696
|
+
if (args.length !== 1) {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
const only = args[0]?.text;
|
|
700
|
+
return ((VERSION_PROGRAMS.has(program) &&
|
|
701
|
+
(only === "--version" || only === "-v" || only === "-V")) ||
|
|
702
|
+
(program === "go" && only === "version"));
|
|
703
|
+
}
|
|
704
|
+
// Another repository's attributes, config and submodule map pick the programs
|
|
705
|
+
// git runs for a diff, a filter or a fetch. Outside this job's workspace they
|
|
706
|
+
// are never written (R13); inside it they are the owner's own repo.
|
|
707
|
+
const GIT_CONTROL_FILE = /(?:^|\/)(?:\.gitattributes|\.gitmodules|\.git\/config|\.git\/info\/attributes)$/iu;
|
|
708
|
+
function gitControlFile(real, ctx) {
|
|
709
|
+
return (GIT_CONTROL_FILE.test(real) &&
|
|
710
|
+
!ctx.writeRoots.some((root) => isInside(real, root)));
|
|
711
|
+
}
|
|
489
712
|
function classifySimple(command, ctx) {
|
|
490
713
|
const [programWord, ...args] = command.argv;
|
|
491
714
|
if (!programWord) {
|
|
@@ -499,6 +722,14 @@ function classifySimple(command, ctx) {
|
|
|
499
722
|
if (SECRET_PROGRAMS.has(program)) {
|
|
500
723
|
verdict = deny(0);
|
|
501
724
|
}
|
|
725
|
+
else if (isVersionQuery(program, args)) {
|
|
726
|
+
verdict = allow();
|
|
727
|
+
}
|
|
728
|
+
else if (FILE_UTILS.has(program) &&
|
|
729
|
+
args.some((word) => !(isFlag(word) || word.glob) &&
|
|
730
|
+
gitControlFile(canonical(word.text, ctx.cwd, ctx.home), ctx))) {
|
|
731
|
+
verdict = deny(0);
|
|
732
|
+
}
|
|
502
733
|
else {
|
|
503
734
|
const spec = READ_ONLY[program];
|
|
504
735
|
if (program === "git") {
|
|
@@ -526,7 +757,8 @@ function classifySimple(command, ctx) {
|
|
|
526
757
|
continue;
|
|
527
758
|
}
|
|
528
759
|
const real = canonical(redirect.target.text, ctx.cwd, ctx.home);
|
|
529
|
-
if (protectedReason(real, "write", ctx.home, ctx.guard)
|
|
760
|
+
if (protectedReason(real, "write", ctx.home, ctx.guard) ||
|
|
761
|
+
gitControlFile(real, ctx)) {
|
|
530
762
|
return deny(0);
|
|
531
763
|
}
|
|
532
764
|
if (redirect.target.glob ||
|
|
@@ -537,6 +769,25 @@ function classifySimple(command, ctx) {
|
|
|
537
769
|
}
|
|
538
770
|
return allow(mutates);
|
|
539
771
|
}
|
|
772
|
+
function changeDirectory(command, ctx) {
|
|
773
|
+
const [program, target, ...extra] = command.argv;
|
|
774
|
+
if (program?.text !== "cd" ||
|
|
775
|
+
extra.length > 0 ||
|
|
776
|
+
command.redirects.length > 0 ||
|
|
777
|
+
!target ||
|
|
778
|
+
target.glob ||
|
|
779
|
+
target.text === "-" ||
|
|
780
|
+
isFlag(target)) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const refused = pathCheck(target, ctx, false);
|
|
784
|
+
if (refused) {
|
|
785
|
+
return refused.allow || refused.tier !== 0 ? undefined : refused;
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
moved: { ...ctx, cwd: canonical(target.text, ctx.cwd, ctx.home) },
|
|
789
|
+
};
|
|
790
|
+
}
|
|
540
791
|
export function classifyShell(source, ctx) {
|
|
541
792
|
const parsed = parseShell(source);
|
|
542
793
|
const summary = redactSummary(source);
|
|
@@ -546,8 +797,19 @@ export function classifyShell(source, ctx) {
|
|
|
546
797
|
let mutates = false;
|
|
547
798
|
let worst;
|
|
548
799
|
const asked = [];
|
|
800
|
+
let here = ctx;
|
|
549
801
|
for (const command of parsed.commands) {
|
|
550
|
-
|
|
802
|
+
// `cd dir && ...`: later paths resolve from there. A target the reader
|
|
803
|
+
// cannot judge falls through to the ordinary ask for `cd`.
|
|
804
|
+
const moved = changeDirectory(command, here);
|
|
805
|
+
if (moved) {
|
|
806
|
+
if (!("moved" in moved)) {
|
|
807
|
+
return moved;
|
|
808
|
+
}
|
|
809
|
+
here = moved.moved;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
const verdict = classifySimple(command, here);
|
|
551
813
|
if (verdict.allow) {
|
|
552
814
|
mutates ||= verdict.mutates;
|
|
553
815
|
continue;
|
|
@@ -555,7 +817,7 @@ export function classifyShell(source, ctx) {
|
|
|
555
817
|
if (verdict.tier === 0) {
|
|
556
818
|
return verdict;
|
|
557
819
|
}
|
|
558
|
-
asked.push(shellAsk(command,
|
|
820
|
+
asked.push(shellAsk(command, here));
|
|
559
821
|
if (!worst || (!worst.allow && verdict.tier < worst.tier)) {
|
|
560
822
|
worst = verdict;
|
|
561
823
|
}
|
|
@@ -595,7 +857,8 @@ export function classifyCall(call, context) {
|
|
|
595
857
|
return deny(1);
|
|
596
858
|
}
|
|
597
859
|
const real = canonical(target, call.cwd, context.home);
|
|
598
|
-
if (protectedReason(real, "write", context.home, guard)
|
|
860
|
+
if (protectedReason(real, "write", context.home, guard) ||
|
|
861
|
+
gitControlFile(real, context)) {
|
|
599
862
|
return deny(0);
|
|
600
863
|
}
|
|
601
864
|
return context.writeRoots.some((root) => isInside(real, root))
|
|
@@ -130,22 +130,25 @@ export async function runScenario(binary, scenario, hookEntry) {
|
|
|
130
130
|
// A stand-in owner behind the real supervisor bridge: the ask is pending for
|
|
131
131
|
// `answerAfterMs`, then the server "says" the scenario's answer.
|
|
132
132
|
const startedAt = Date.now();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
133
|
+
// Every scenario runs behind the real supervisor: the hook reports calls
|
|
134
|
+
// that reach the owner's setup (a subagent, an MCP tool) through it before
|
|
135
|
+
// the call runs, and refuses the call if it cannot. A scenario with no
|
|
136
|
+
// `answer` has an owner who declines at once.
|
|
137
|
+
const owner = await new ApprovalBridge({
|
|
138
|
+
gateway: {
|
|
139
|
+
touch: async () => undefined,
|
|
140
|
+
request: () => Promise.resolve({ status: scenario.answer ? "pending" : "denied" }),
|
|
141
|
+
status: (keys) => Promise.resolve(keys.map((actionKey) => ({
|
|
142
|
+
actionKey,
|
|
143
|
+
status: Date.now() - startedAt < (scenario.answerAfterMs ?? 0)
|
|
144
|
+
? "pending"
|
|
145
|
+
: (scenario.answer ?? "denied"),
|
|
146
|
+
}))),
|
|
147
|
+
},
|
|
148
|
+
statusEveryMs: 50,
|
|
149
|
+
}).start();
|
|
147
150
|
await writeFile(join(jobDir, "context.json"), JSON.stringify({
|
|
148
|
-
|
|
151
|
+
askSocket: owner.socketPath,
|
|
149
152
|
home,
|
|
150
153
|
writeRoots: [realpathSync.native(work)],
|
|
151
154
|
}));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { redactSummary } from "./policy.js";
|
|
4
|
+
export const RECEIPT_ROWS_MAX = 500;
|
|
5
|
+
const TARGET_MAX = 120;
|
|
6
|
+
const TOOL_MAX = 80;
|
|
7
|
+
const ASKED = new Set(["approved", "denied", "expired"]);
|
|
8
|
+
export async function readReceipts(jobDir) {
|
|
9
|
+
let raw;
|
|
10
|
+
try {
|
|
11
|
+
raw = await readFile(join(jobDir, "calls.jsonl"), "utf8");
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const rows = [];
|
|
17
|
+
for (const line of raw.split("\n")) {
|
|
18
|
+
if (rows.length >= RECEIPT_ROWS_MAX) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const value = JSON.parse(line);
|
|
23
|
+
const decision = value.decision;
|
|
24
|
+
if (typeof value.tool === "string" &&
|
|
25
|
+
typeof value.at === "number" &&
|
|
26
|
+
typeof value.tier === "number" &&
|
|
27
|
+
(decision === "allow" || decision === "deny")) {
|
|
28
|
+
rows.push({
|
|
29
|
+
...(typeof value.asked === "string" && ASKED.has(value.asked)
|
|
30
|
+
? { asked: value.asked }
|
|
31
|
+
: {}),
|
|
32
|
+
at: value.at,
|
|
33
|
+
decision,
|
|
34
|
+
seq: rows.length,
|
|
35
|
+
subagent: value.subagent === true,
|
|
36
|
+
target: redactSummary(typeof value.target === "string" ? value.target : "").slice(0, TARGET_MAX),
|
|
37
|
+
tier: value.tier,
|
|
38
|
+
tool: value.tool.slice(0, TOOL_MAX),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// A torn last line from a killed hook is not a receipt.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return rows;
|
|
47
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { canonical, isInside } from "./paths.js";
|
|
2
|
+
import { parseShell } from "./shell.js";
|
|
3
|
+
// "Private-touched" (#10987 PR 2b, R12 R1): did this call reach into the owner's
|
|
4
|
+
// own setup, so that what it returns may be private? The server holds back what
|
|
5
|
+
// such a job writes into a room with other people until the owner reviews it.
|
|
6
|
+
//
|
|
7
|
+
// Allowlist-shaped like the policy: a call is NOT private only when it is
|
|
8
|
+
// recognised as staying inside the job's workspace or using the room's own
|
|
9
|
+
// tools. Anything else (any other MCP tool, a web fetch, a read outside the
|
|
10
|
+
// workspace, a command the policy had to ask about, a tool we do not know)
|
|
11
|
+
// counts as touched. A false "touched" costs the owner one tap; a false
|
|
12
|
+
// "untouched" would post private data, so every doubt resolves to touched.
|
|
13
|
+
const ROOM_SERVER_PREFIX = "mcp__talentos_room__";
|
|
14
|
+
// Tools that read files by path; the path decides.
|
|
15
|
+
const PATH_TOOLS = new Set(["Glob", "Grep", "LS", "NotebookRead", "Read"]);
|
|
16
|
+
const EDIT_TOOLS = new Set(["Edit", "MultiEdit", "NotebookEdit", "Write"]);
|
|
17
|
+
// Tools that touch nothing of the owner's: bookkeeping and public web search.
|
|
18
|
+
// Skill and Agent are NOT here: a skill or subagent is owner-level context the
|
|
19
|
+
// hook cannot see into, so calling one counts as touched (R13 P2-d).
|
|
20
|
+
const NEUTRAL_TOOLS = new Set([
|
|
21
|
+
"AskUserQuestion",
|
|
22
|
+
"BashOutput",
|
|
23
|
+
"ExitPlanMode",
|
|
24
|
+
"KillShell",
|
|
25
|
+
"TaskCreate",
|
|
26
|
+
"TaskGet",
|
|
27
|
+
"TaskList",
|
|
28
|
+
"TaskStop",
|
|
29
|
+
"TaskUpdate",
|
|
30
|
+
"TodoWrite",
|
|
31
|
+
"ToolSearch",
|
|
32
|
+
"WebSearch",
|
|
33
|
+
]);
|
|
34
|
+
const GLOB_CHARS = /[*?[{]/u;
|
|
35
|
+
const PATH_START = /[/~]/u;
|
|
36
|
+
function text(value) {
|
|
37
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
38
|
+
}
|
|
39
|
+
export function touchesPrivate(call, context, allowedByPolicy) {
|
|
40
|
+
// The policy had to ask the owner: it is outward, irreversible or unknown, and
|
|
41
|
+
// once approved it may read anything.
|
|
42
|
+
if (!allowedByPolicy) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const { tool, toolInput: input } = call;
|
|
46
|
+
const inside = (path, base = call.cwd) => {
|
|
47
|
+
if (path.startsWith("~") && path !== "~" && !path.startsWith("~/")) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const real = canonical(path, base, context.home);
|
|
51
|
+
return context.writeRoots.some((root) => isInside(real, root));
|
|
52
|
+
};
|
|
53
|
+
if (tool.startsWith("mcp__")) {
|
|
54
|
+
return !tool.startsWith(ROOM_SERVER_PREFIX);
|
|
55
|
+
}
|
|
56
|
+
if (NEUTRAL_TOOLS.has(tool)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (PATH_TOOLS.has(tool) || EDIT_TOOLS.has(tool)) {
|
|
60
|
+
const paths = [
|
|
61
|
+
text(input.file_path),
|
|
62
|
+
text(input.notebook_path),
|
|
63
|
+
text(input.path),
|
|
64
|
+
// A glob pattern is judged by its literal directory prefix.
|
|
65
|
+
tool === "Glob"
|
|
66
|
+
? (text(input.pattern)?.split(GLOB_CHARS)[0] ?? undefined)
|
|
67
|
+
: undefined,
|
|
68
|
+
].filter((path) => path !== undefined);
|
|
69
|
+
if (paths.length === 0) {
|
|
70
|
+
return !inside(".");
|
|
71
|
+
}
|
|
72
|
+
return paths.some((path) => !inside(path));
|
|
73
|
+
}
|
|
74
|
+
if (tool === "Bash") {
|
|
75
|
+
return shellTouchesPrivate(text(input.command), inside, call.cwd, context.home);
|
|
76
|
+
}
|
|
77
|
+
// WebFetch and every tool this list does not know.
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const isRun = (part) => part.startsWith("run:");
|
|
81
|
+
/**
|
|
82
|
+
* Did this call pull untrusted input into the job (Auto mode, R13)? Anything
|
|
83
|
+
* the owner's private setup touch covers, plus web search and any serious
|
|
84
|
+
* (tier 1) action the owner approved. After the first, tests and builds ask
|
|
85
|
+
* again for the rest of the job and the thread.
|
|
86
|
+
*/
|
|
87
|
+
export function taintsJob(call, context, asked) {
|
|
88
|
+
return (call.tool === "WebSearch" ||
|
|
89
|
+
// A test or build the owner (or Auto mode) allowed brings in nothing; any
|
|
90
|
+
// other serious action does.
|
|
91
|
+
(asked?.tier === 1 && !asked.kind.split(" + ").every(isRun)) ||
|
|
92
|
+
touchesPrivate(call, context, true));
|
|
93
|
+
}
|
|
94
|
+
function shellTouchesPrivate(source, inside, cwd, home) {
|
|
95
|
+
const parsed = source ? parseShell(source) : undefined;
|
|
96
|
+
if (!(parsed?.ok && inside("."))) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// `cd dir && ...`: later paths resolve from where the command moved to.
|
|
100
|
+
let base = cwd;
|
|
101
|
+
for (const command of parsed.commands) {
|
|
102
|
+
const words = command.argv.slice(1);
|
|
103
|
+
if (command.argv[0]?.text === "cd") {
|
|
104
|
+
const target = words[0];
|
|
105
|
+
if (!target ||
|
|
106
|
+
words.length > 1 ||
|
|
107
|
+
target.glob ||
|
|
108
|
+
!inside(target.text, base)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
base = canonical(target.text, base, home);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
for (const word of words) {
|
|
115
|
+
if (word.text.startsWith("-")) {
|
|
116
|
+
// `--git-dir=/x` and `-C/x` carry a path inside the flag.
|
|
117
|
+
const start = word.text.search(PATH_START);
|
|
118
|
+
if (start > 0 && !inside(word.text.slice(start), base)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (word.glob) {
|
|
124
|
+
// A relative glob stays in the working directory; anything else cannot
|
|
125
|
+
// be judged from its literal prefix.
|
|
126
|
+
if (PATH_START.test(word.text.charAt(0)) || word.text.includes("..")) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!inside(word.text, base)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const redirect of command.redirects) {
|
|
136
|
+
if (redirect.target.text !== "/dev/null" &&
|
|
137
|
+
!inside(redirect.target.text, base)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|