talentos 1.4.8 → 1.4.10

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.
@@ -1,7 +1,7 @@
1
- import { existsSync, statSync } from "node:fs";
2
- import { basename, dirname, join } from "node:path";
1
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from "node:fs";
2
+ import { basename, dirname, join, sep } from "node:path";
3
3
  import { ROOM_LOCAL_TOOLS, ROOM_TOOLS } from "../codex-policy.js";
4
- import { canonical, inGitDir, isInside, protectedPaths, protectedReason, reachesProtected, } from "./paths.js";
4
+ import { canonical, inGitDir, isInside, protectedPaths, protectedReason, reachesProtected, WRITE_PROTECTED_SEGMENTS, } from "./paths.js";
5
5
  import { parseShell } from "./shell.js";
6
6
  const NON_ALNUM = /[^A-Za-z\d]+/u;
7
7
  const GREP_R_DIFF = /^-\w*r|^--recursive/u;
@@ -502,7 +502,7 @@ const GIT_GLOBAL_OK = new Set([
502
502
  ]);
503
503
  const GIT_DIR_FLAG = /^(--(?:git-dir|work-tree))=(.+)$/u;
504
504
  // `git [globals] <sub> ...`: only the globals above are understood.
505
- function splitGit(args) {
505
+ export function splitGit(args) {
506
506
  const dirs = [];
507
507
  let index = 0;
508
508
  while (index < args.length && isFlag(args[index])) {
@@ -623,11 +623,18 @@ const CHECKOUT_SAFE_FLAG = /^(?:-b|-t|--track|--no-track|-q|--quiet|--detach)$/u
623
623
  const SWITCH_SAFE_FLAG = /^(?:-d|--detach|-t|--track|--no-track|-q|--quiet|--guess|--no-guess)$/u;
624
624
  // Clone options that set config or hooks, or run a program.
625
625
  const CLONE_BAD_FLAG = /^(?:-\w*[cu]|--config|--template|--upload-pack|--separate-git-dir)/u;
626
+ // Fetch and pull follow the push rules (#12933): `origin` only, plain flags,
627
+ // no `+` refspec. `--force`, `--all`, `--update-head-ok`, `--refmap`,
628
+ // submodules and merge strategies are tier 1.
629
+ const FETCH_SAFE_FLAG = /^(?:-[qvp]+|--quiet|--verbose|--prune|--tags|--no-tags|--progress|--no-progress|--depth=\d+|--unshallow)$/u;
630
+ const PULL_SAFE_FLAG = /^(?:-[qvr]+|--quiet|--verbose|--rebase|--no-rebase|--ff|--ff-only|--no-ff|--no-edit|--autostash|--no-autostash|--progress|--no-progress)$/u;
631
+ // A remote given as a URL: `scheme://…`, `file:` or scp-like `[user@]host:path`.
632
+ const REMOTE_URL = /^[a-z][\w+.-]*:\/\/|^file:|^[^/:\s]+:/iu;
626
633
  const GIT_DIR_PARTS = ["HEAD", "objects", "refs"];
627
- // Git work that touches only `.git` and the network, never the folders around it.
628
634
  const TRAILING_SLASHES = /[/\\]+$/u;
629
635
  const URL_PATH_SEPARATOR = /[/:]/u;
630
636
  const GIT_SUFFIX = /\.git$/u;
637
+ // Git work that touches only `.git` and the network, never the folders around it.
631
638
  const GIT_KEEPS_TREE = new Set(["add", "commit", "fetch", "push"]);
632
639
  const RESTORE_SAFE_FLAG = /^(?:-S|--staged|-q|--quiet|--)$/u;
633
640
  const STASH_KEEPS = new Set([
@@ -655,6 +662,15 @@ function pushesToThread(refspec) {
655
662
  branch.startsWith("talentos/") &&
656
663
  !PROTECTED_BRANCH.test(branch));
657
664
  }
665
+ function gitFetchTier(sub, rest) {
666
+ const [remote, ...refspecs] = rest.filter((word) => !isFlag(word));
667
+ const safe = sub === "fetch" ? FETCH_SAFE_FLAG : PULL_SAFE_FLAG;
668
+ return rest.filter(isFlag).every((flag) => safe.test(flag.text)) &&
669
+ (remote === undefined || remote.text === "origin") &&
670
+ refspecs.every((refspec) => !refspec.text.startsWith("+"))
671
+ ? 2
672
+ : 1;
673
+ }
658
674
  function gitPushTier(rest) {
659
675
  const [remote, ...refspecs] = rest.filter((word) => !isFlag(word));
660
676
  // Only `origin` is the owner's own remote; a URL, a path or another name
@@ -734,7 +750,7 @@ function cloneIntoProtected(args, ctx) {
734
750
  const git = splitGit(args);
735
751
  return (git.sub?.text === "clone" &&
736
752
  cloneTargets(git, ctx).some(({ glob, text }) => !glob &&
737
- Boolean(protectedReason(text, "write", ctx.home, ctx.guard) ||
753
+ (writeProtected(text, ctx) ||
738
754
  gitControlFile(text, ctx) ||
739
755
  inGitDir(text))));
740
756
  }
@@ -750,6 +766,194 @@ function foreignRepo(repo, ctx) {
750
766
  ctx.writeRoots.some((root) => isInside(repo, root)) &&
751
767
  !ctx.writeRoots.some((root) => gitRepoAt(root) === repo));
752
768
  }
769
+ // Files that pick what `git commit` runs (#13110): hook managers' configs, the
770
+ // `package.json` keys they read, and the repo's `core.hooksPath`. A change to
771
+ // one asks every time, so a later commit cannot run model-written hooks with
772
+ // no card. `.husky` and `.githooks` are tier 0 already.
773
+ const HOOK_CONFIG_NAME = /^(?:\.?lefthook(?:-local)?\.(?:ya?ml|json|jsonc|toml)|\.pre-commit-config\.ya?ml|\.lintstagedrc(?:\..+)?|lint-staged\.config\..+|\.?simple-git-hooks(?:\..+)?|\.huskyrc(?:\..+)?|husky\.config\..+|\.overcommit\.ya?ml|\.commitlintrc(?:\..+)?|commitlint\.config\..+)$/iu;
774
+ // A hook manager's config in `package.json` is an object or a list; a version
775
+ // string is only a dependency.
776
+ const PACKAGE_HOOK_KEY = /"(?:husky|simple-git-hooks|lint-staged|pre-commit|commitlint|ghooks|git-hooks)"\s*:\s*[[{]/u;
777
+ // lefthook's script folders; matched without case, like HOOK_CONFIG_NAME.
778
+ const HOOK_DIR_NAME = /^\.lefthook(?:-local)?$/iu;
779
+ const HOOKS_PATH = /^\s*hookspath\s*=\s*"?([^"\n]+?)"?\s*$/gimu;
780
+ const CONFIG_SECTION = /^\s*\[([^\]]+)\]/u;
781
+ const INCLUDE_SECTION = /^include(?:if\s+".*")?$/iu;
782
+ const INCLUDE_PATH = /^\s*path\s*=\s*"?([^"\n]+?)"?\s*$/iu;
783
+ // Git stops following includes at this depth too.
784
+ const MAX_INCLUDE_DEPTH = 10;
785
+ const GITDIR_LINE = /^gitdir:\s*(.+?)\s*$/mu;
786
+ function readText(path) {
787
+ try {
788
+ return readFileSync(path, "utf8");
789
+ }
790
+ catch {
791
+ return "";
792
+ }
793
+ }
794
+ function listDir(path) {
795
+ try {
796
+ return readdirSync(path);
797
+ }
798
+ catch {
799
+ return [];
800
+ }
801
+ }
802
+ // A git config file with every `[include]`/`[includeIf]` file it names
803
+ // appended (each condition counts as met). Paths resolve from the file's folder.
804
+ function configText(path, home, depth = 0) {
805
+ const text = readText(path);
806
+ if (depth >= MAX_INCLUDE_DEPTH) {
807
+ return text;
808
+ }
809
+ const parts = [text];
810
+ let including = false;
811
+ for (const line of text.split("\n")) {
812
+ const section = CONFIG_SECTION.exec(line)?.[1];
813
+ if (section !== undefined) {
814
+ including = INCLUDE_SECTION.test(section.trim());
815
+ continue;
816
+ }
817
+ const included = including ? INCLUDE_PATH.exec(line)?.[1] : undefined;
818
+ if (included) {
819
+ parts.push(configText(canonical(included, dirname(path), home), home, depth + 1));
820
+ }
821
+ }
822
+ return parts.join("\n");
823
+ }
824
+ function realTarget(path) {
825
+ try {
826
+ return realpathSync.native(path);
827
+ }
828
+ catch {
829
+ return;
830
+ }
831
+ }
832
+ // What a hook config or folder at the top of `dir` resolves to: when it is a
833
+ // link, its target is what the hook manager reads.
834
+ function linkedHookTargets(dir) {
835
+ return [dir, join(dir, ".config")].flatMap((folder) => listDir(folder)
836
+ .filter((name) => HOOK_CONFIG_NAME.test(name) || HOOK_DIR_NAME.test(name))
837
+ .flatMap((name) => realTarget(join(folder, name)) ?? []));
838
+ }
839
+ // Each write root and the top of its repository: where the provider, hook and
840
+ // hook-manager folders sit.
841
+ function workspaceTops(ctx) {
842
+ const tops = new Set();
843
+ for (const root of ctx.writeRoots) {
844
+ tops.add(root);
845
+ const repo = gitRepoAt(root);
846
+ if (repo && basename(repo) === ".git") {
847
+ tops.add(dirname(repo));
848
+ }
849
+ }
850
+ return [...tops];
851
+ }
852
+ // The tier 0 write rule, also through a link: `.husky -> tools/husky` makes
853
+ // `tools/husky` as protected as `.husky` (#13118).
854
+ function writeProtected(real, ctx) {
855
+ return (Boolean(protectedReason(real, "write", ctx.home, ctx.guard)) ||
856
+ workspaceTops(ctx).some((top) => WRITE_PROTECTED_SEGMENTS.some((name) => {
857
+ const target = realTarget(join(top, name));
858
+ return target !== undefined && isInside(real, target);
859
+ })));
860
+ }
861
+ // What a commit in each write root runs: `core.hooksPath` from its repository's
862
+ // config (a worktree reads the main repository's) or the owner's global config,
863
+ // and any hook installed in the repository's `hooks` folder.
864
+ function hookSetup(ctx) {
865
+ const setup = {
866
+ dirs: [],
867
+ folders: [],
868
+ installed: false,
869
+ linked: [],
870
+ };
871
+ for (const root of ctx.writeRoots) {
872
+ const repo = gitRepoAt(root);
873
+ if (!repo) {
874
+ continue;
875
+ }
876
+ const top = basename(repo) === ".git" ? dirname(repo) : root;
877
+ const pointer = GITDIR_LINE.exec(readText(repo))?.[1];
878
+ const gitDir = pointer ? canonical(pointer, top, ctx.home) : repo;
879
+ const commonDir = readText(join(gitDir, "commondir")).trim();
880
+ const common = commonDir ? canonical(commonDir, gitDir, ctx.home) : gitDir;
881
+ const folders = [join(common, "hooks")];
882
+ for (const config of [
883
+ join(common, "config"),
884
+ join(gitDir, "config.worktree"),
885
+ join(ctx.home, ".gitconfig"),
886
+ join(ctx.home, ".config", "git", "config"),
887
+ ]) {
888
+ for (const [, value] of configText(config, ctx.home).matchAll(HOOKS_PATH)) {
889
+ if (value) {
890
+ folders.push(canonical(value, top, ctx.home));
891
+ }
892
+ }
893
+ }
894
+ setup.dirs.push(...folders.slice(1));
895
+ setup.folders.push(...folders);
896
+ for (const dir of new Set([top, root])) {
897
+ setup.linked.push(...linkedHookTargets(dir));
898
+ }
899
+ // A hooks folder, or a hook in it, may link to a tracked file or folder:
900
+ // git runs the target.
901
+ for (const folder of folders) {
902
+ for (const path of [
903
+ folder,
904
+ ...listDir(folder)
905
+ .filter((name) => !name.endsWith(".sample"))
906
+ .map((name) => join(folder, name)),
907
+ ]) {
908
+ const target = realTarget(path);
909
+ if (target) {
910
+ setup.linked.push(target);
911
+ }
912
+ }
913
+ }
914
+ setup.installed ||= listDir(join(common, "hooks")).some((name) => !name.endsWith(".sample"));
915
+ }
916
+ return setup;
917
+ }
918
+ /**
919
+ * True when writing `real` changes what a commit runs. While hooks are set up,
920
+ * any `package.json` change counts: a hook may run any npm script. `content`
921
+ * is the new text when known; a shell write is unknown, so it counts.
922
+ */
923
+ function hookConfig(real, ctx, content) {
924
+ const name = basename(real);
925
+ if (HOOK_CONFIG_NAME.test(name) ||
926
+ real.split(sep).some((segment) => HOOK_DIR_NAME.test(segment))) {
927
+ return true;
928
+ }
929
+ const setup = hookSetup(ctx);
930
+ if ([...setup.dirs, ...setup.linked].some((dir) => isInside(real, dir))) {
931
+ return true;
932
+ }
933
+ return (name === "package.json" &&
934
+ (content === undefined ||
935
+ setup.dirs.length > 0 ||
936
+ setup.installed ||
937
+ PACKAGE_HOOK_KEY.test(content) ||
938
+ PACKAGE_HOOK_KEY.test(readText(real))));
939
+ }
940
+ // The hooks `git commit` runs. Husky's `core.hooksPath` holds a stub for every
941
+ // hook, so a husky repository always counts.
942
+ const COMMIT_HOOKS = [
943
+ "pre-commit",
944
+ "prepare-commit-msg",
945
+ "commit-msg",
946
+ "post-commit",
947
+ ];
948
+ function commitRunsHooks(ctx) {
949
+ return hookSetup(ctx).folders.some((folder) => COMMIT_HOOKS.some((name) => existsSync(join(folder, name))));
950
+ }
951
+ // A clone into a folder that holds a hooks folder or a hook config's target
952
+ // fills it from the clone (#13118).
953
+ function holdsHooks(target, ctx) {
954
+ const setup = hookSetup(ctx);
955
+ return [...setup.dirs, ...setup.linked].some((dir) => isInside(dir, target));
956
+ }
753
957
  // `mv`/`cp` onto an existing file replaces it: the old content is gone.
754
958
  function overwrites(args, ctx) {
755
959
  if (args.some((word) => isFlag(word) && TARGET_DIR_FLAG.test(word.text))) {
@@ -773,6 +977,10 @@ function shellAsk(command, ctx) {
773
977
  !ctx.writeRoots.some((root) => isInside(canonical(redirect.target.text, ctx.cwd, ctx.home), root)))) {
774
978
  return { kind: "shell:redirect-outside", tier: 1 };
775
979
  }
980
+ if (command.redirects.some((redirect) => redirect.mode === "write" &&
981
+ hookConfig(canonical(redirect.target.text, ctx.cwd, ctx.home), ctx, undefined))) {
982
+ return { kind: "shell:hook-config", tier: 1 };
983
+ }
776
984
  if (program.includes("/")) {
777
985
  return { kind: "shell:script", tier: 1 };
778
986
  }
@@ -798,22 +1006,42 @@ function shellAsk(command, ctx) {
798
1006
  if (sub === "push") {
799
1007
  tier = gitPushTier(git.rest);
800
1008
  }
1009
+ else if (sub === "fetch" || sub === "pull") {
1010
+ tier = gitFetchTier(sub, git.rest);
1011
+ }
801
1012
  else if (!gitKeepsWork(sub, git.rest, cwd, ctx.home) ||
1013
+ (sub === "clone" &&
1014
+ git.rest.some((word) => !isFlag(word) && REMOTE_URL.test(word.text))) ||
802
1015
  (sub === "clone" &&
803
1016
  cloneTargets(git, ctx).some((word) => word.glob ||
804
- !ctx.writeRoots.some((root) => isInside(word.text, root))))) {
1017
+ !ctx.writeRoots.some((root) => isInside(word.text, root)) ||
1018
+ hookConfig(word.text, ctx, "") ||
1019
+ holdsHooks(word.text, ctx)))) {
805
1020
  tier = 1;
806
1021
  }
807
- return { kind: `git:${sub}`, tier };
1022
+ // R5 for commits (#13115): after an edit, a commit's hooks load configs
1023
+ // and tests the model may have changed, so it also needs the owner's tests
1024
+ // consent. The server reads `run:hooks` as the tests class.
1025
+ return {
1026
+ kind: sub === "commit" && ctx.dirty && commitRunsHooks(ctx)
1027
+ ? "git:commit + run:hooks"
1028
+ : `git:${sub}`,
1029
+ tier,
1030
+ };
808
1031
  }
809
1032
  if (FILE_UTILS.has(program)) {
810
1033
  const inside = args
811
1034
  .filter((word) => !isFlag(word))
812
1035
  .every((word) => !word.glob &&
813
1036
  ctx.writeRoots.some((root) => isInside(canonical(word.text, ctx.cwd, ctx.home), root)) &&
814
- !protectedReason(canonical(word.text, ctx.cwd, ctx.home), "write", ctx.home, ctx.guard));
1037
+ !writeProtected(canonical(word.text, ctx.cwd, ctx.home), ctx));
815
1038
  const replaces = (program === "mv" || program === "cp") && overwrites(args, ctx);
816
- return { kind: `shell:${program}`, tier: inside && !replaces ? 2 : 1 };
1039
+ const hooks = args.some((word) => !isFlag(word) &&
1040
+ hookConfig(canonical(word.text, ctx.cwd, ctx.home), ctx, undefined));
1041
+ return {
1042
+ kind: `shell:${program}`,
1043
+ tier: inside && !replaces && !hooks ? 2 : 1,
1044
+ };
817
1045
  }
818
1046
  const [first, second, third] = command.argv.map((word) => word.text);
819
1047
  if (ctx.dirty &&
@@ -930,14 +1158,16 @@ function classifySimple(command, ctx) {
930
1158
  continue;
931
1159
  }
932
1160
  const real = canonical(redirect.target.text, ctx.cwd, ctx.home);
933
- if (protectedReason(real, "write", ctx.home, ctx.guard) ||
934
- gitControlFile(real, ctx)) {
1161
+ if (writeProtected(real, ctx) || gitControlFile(real, ctx)) {
935
1162
  return deny(0);
936
1163
  }
937
1164
  if (redirect.target.glob ||
938
1165
  !ctx.writeRoots.some((root) => isInside(real, root))) {
939
1166
  return deny(2);
940
1167
  }
1168
+ if (hookConfig(real, ctx, undefined)) {
1169
+ return deny(1);
1170
+ }
941
1171
  mutates = true;
942
1172
  }
943
1173
  return allow(mutates);
@@ -1008,10 +1238,13 @@ export function classifyShell(source, ctx) {
1008
1238
  here = moved.moved;
1009
1239
  continue;
1010
1240
  }
1011
- const verdict = classifySimple(command, here);
1241
+ // An earlier part that writes is an edit for R5 too: `echo x > a.ts && npm
1242
+ // test` runs the changed file (#13115).
1243
+ const local = wrote && !here.dirty ? { ...here, dirty: true } : here;
1244
+ const verdict = classifySimple(command, local);
1012
1245
  // The disk is read before the chain runs, so a repository an earlier part
1013
1246
  // clones or builds is not there yet (#12926).
1014
- const blind = wrote && runsBlind(command, here);
1247
+ const blind = wrote && runsBlind(command, local);
1015
1248
  if (verdict.allow && !blind) {
1016
1249
  mutates ||= verdict.mutates;
1017
1250
  wrote ||= verdict.mutates;
@@ -1020,7 +1253,7 @@ export function classifyShell(source, ctx) {
1020
1253
  if (!verdict.allow && verdict.tier === 0) {
1021
1254
  return verdict;
1022
1255
  }
1023
- const ask = shellAsk(command, here);
1256
+ const ask = shellAsk(command, local);
1024
1257
  asked.push(blind ? { ...ask, tier: 1 } : ask);
1025
1258
  const held = blind ? deny(1) : verdict;
1026
1259
  if (!(held.allow || (worst && !worst.allow && held.tier >= worst.tier))) {
@@ -1033,7 +1266,9 @@ export function classifyShell(source, ctx) {
1033
1266
  }
1034
1267
  // One ask covers the whole command. Its tier is the strictest part's, and its
1035
1268
  // kind names every part, so a rule for one program never covers a chain.
1036
- const kinds = [...new Set(asked.map((entry) => entry.kind))].sort();
1269
+ const kinds = [
1270
+ ...new Set(asked.flatMap((entry) => entry.kind.split(" + "))),
1271
+ ].sort();
1037
1272
  const joined = kinds.join(" + ");
1038
1273
  const kind = joined.length <= 80 ? joined : `${kinds[0]} +${kinds.length - 1}`;
1039
1274
  const tier = Math.min(...asked.map((entry) => entry.tier));
@@ -1058,19 +1293,26 @@ export function applyPatchPaths(command) {
1058
1293
  return paths;
1059
1294
  }
1060
1295
  /** The write rule shared by Edit tools and apply_patch: inside a write root, or ask. */
1061
- function classifyWrite(tool, real, ctx) {
1062
- if (protectedReason(real, "write", ctx.home, ctx.guard) ||
1063
- gitControlFile(real, ctx)) {
1296
+ function classifyWrite(tool, real, ctx, content) {
1297
+ if (writeProtected(real, ctx) || gitControlFile(real, ctx)) {
1064
1298
  return deny(0);
1065
1299
  }
1066
- return ctx.writeRoots.some((root) => isInside(real, root))
1067
- ? allow(true)
1068
- : askDeny("That file is outside this job's workspace. Needs the owner's approval.", {
1300
+ if (!ctx.writeRoots.some((root) => isInside(real, root))) {
1301
+ return askDeny("That file is outside this job's workspace. Needs the owner's approval.", {
1069
1302
  detail: `${tool} ${real}`,
1070
1303
  kind: "write-outside-workspace",
1071
1304
  summary: redactSummary(`${tool} ${real}`),
1072
1305
  tier: 1,
1073
1306
  });
1307
+ }
1308
+ return hookConfig(real, ctx, content)
1309
+ ? askDeny("That file decides what runs when you commit. Needs the owner's approval.", {
1310
+ detail: `${tool} ${real}`,
1311
+ kind: "write-hook-config",
1312
+ summary: redactSummary(`${tool} ${real}`),
1313
+ tier: 1,
1314
+ })
1315
+ : allow(true);
1074
1316
  }
1075
1317
  export function classifyCall(call, context) {
1076
1318
  const guard = context.guard ?? protectedPaths(context.home);
@@ -1091,7 +1333,19 @@ export function classifyCall(call, context) {
1091
1333
  if (!target) {
1092
1334
  return deny(1);
1093
1335
  }
1094
- return classifyWrite(tool, canonical(target, call.cwd, context.home), ctx);
1336
+ // The new text, so a `package.json` edit is judged by what it adds.
1337
+ const edits = Array.isArray(input.edits) ? input.edits : [];
1338
+ const content = [
1339
+ text(input.content),
1340
+ text(input.new_string),
1341
+ text(input.new_source),
1342
+ ...edits.map((edit) => typeof edit === "object" && edit !== null
1343
+ ? text(edit.new_string)
1344
+ : undefined),
1345
+ ]
1346
+ .filter(Boolean)
1347
+ .join("\n");
1348
+ return classifyWrite(tool, canonical(target, call.cwd, context.home), ctx, content);
1095
1349
  }
1096
1350
  // Codex's freeform file-edit tool: the whole patch is in `command`, so every
1097
1351
  // path it adds, updates, moves to or deletes is checked like an Edit, and one
@@ -1103,7 +1357,7 @@ export function classifyCall(call, context) {
1103
1357
  }
1104
1358
  let verdict = allow(true);
1105
1359
  for (const path of paths) {
1106
- const refused = classifyWrite("apply_patch", canonical(path, call.cwd, context.home), ctx);
1360
+ const refused = classifyWrite("apply_patch", canonical(path, call.cwd, context.home), ctx, text(input.command) ?? "");
1107
1361
  if (!refused.allow) {
1108
1362
  if (refused.tier === 0) {
1109
1363
  return refused;
@@ -1,5 +1,6 @@
1
+ import { basename } from "node:path";
1
2
  import { canonical, isInside } from "./paths.js";
2
- import { applyPatchPaths, } from "./policy.js";
3
+ import { applyPatchPaths, splitGit, } from "./policy.js";
3
4
  import { parseShell } from "./shell.js";
4
5
  // "Private-touched" (#10987 PR 2b, R12 R1): did this call reach into the owner's
5
6
  // own setup, so that what it returns may be private? The server records it;
@@ -87,14 +88,33 @@ export function touchesPrivate(call, context, allowedByPolicy) {
87
88
  return true;
88
89
  }
89
90
  const isRun = (part) => part.startsWith("run:");
91
+ // Git commands that bring outside content into the workspace (#13255).
92
+ const GIT_FETCHES = new Set(["clone", "fetch", "pull"]);
93
+ function fetchesOutside(call) {
94
+ const source = call.tool === "Bash" ? text(call.toolInput.command) : undefined;
95
+ const parsed = source ? parseShell(source) : undefined;
96
+ return Boolean(parsed?.ok &&
97
+ parsed.commands.some((command) => {
98
+ const [program, ...args] = command.argv;
99
+ if (basename(program?.text ?? "") !== "git") {
100
+ return false;
101
+ }
102
+ const git = splitGit(args);
103
+ // Globals the reader does not know: any fetch-like word counts.
104
+ return git.ok
105
+ ? GIT_FETCHES.has(git.sub?.text ?? "")
106
+ : args.some((word) => GIT_FETCHES.has(word.text));
107
+ }));
108
+ }
90
109
  /**
91
110
  * Did this call pull untrusted input into the job (Auto mode, R13)? Anything
92
- * the owner's private setup touch covers, plus web search and any serious
93
- * (tier 1) action the owner approved. After the first, tests and builds ask
111
+ * the owner's private setup touch covers, plus web search, a git fetch, pull or
112
+ * clone from any remote, and any serious (tier 1) action the owner approved. After the first, tests and builds ask
94
113
  * again for the rest of the job and the thread.
95
114
  */
96
115
  export function taintsJob(call, context, asked) {
97
116
  return (call.tool === "WebSearch" ||
117
+ fetchesOutside(call) ||
98
118
  // A test or build the owner (or Auto mode) allowed brings in nothing; any
99
119
  // other serious action does.
100
120
  (asked?.tier === 1 && !asked.kind.split(" + ").every(isRun)) ||