talentos 1.4.9 → 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.
@@ -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
@@ -846,7 +862,12 @@ function writeProtected(real, ctx) {
846
862
  // config (a worktree reads the main repository's) or the owner's global config,
847
863
  // and any hook installed in the repository's `hooks` folder.
848
864
  function hookSetup(ctx) {
849
- const setup = { dirs: [], installed: false, linked: [] };
865
+ const setup = {
866
+ dirs: [],
867
+ folders: [],
868
+ installed: false,
869
+ linked: [],
870
+ };
850
871
  for (const root of ctx.writeRoots) {
851
872
  const repo = gitRepoAt(root);
852
873
  if (!repo) {
@@ -871,6 +892,7 @@ function hookSetup(ctx) {
871
892
  }
872
893
  }
873
894
  setup.dirs.push(...folders.slice(1));
895
+ setup.folders.push(...folders);
874
896
  for (const dir of new Set([top, root])) {
875
897
  setup.linked.push(...linkedHookTargets(dir));
876
898
  }
@@ -915,6 +937,17 @@ function hookConfig(real, ctx, content) {
915
937
  PACKAGE_HOOK_KEY.test(content) ||
916
938
  PACKAGE_HOOK_KEY.test(readText(real))));
917
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
+ }
918
951
  // A clone into a folder that holds a hooks folder or a hook config's target
919
952
  // fills it from the clone (#13118).
920
953
  function holdsHooks(target, ctx) {
@@ -973,7 +1006,12 @@ function shellAsk(command, ctx) {
973
1006
  if (sub === "push") {
974
1007
  tier = gitPushTier(git.rest);
975
1008
  }
1009
+ else if (sub === "fetch" || sub === "pull") {
1010
+ tier = gitFetchTier(sub, git.rest);
1011
+ }
976
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))) ||
977
1015
  (sub === "clone" &&
978
1016
  cloneTargets(git, ctx).some((word) => word.glob ||
979
1017
  !ctx.writeRoots.some((root) => isInside(word.text, root)) ||
@@ -981,7 +1019,15 @@ function shellAsk(command, ctx) {
981
1019
  holdsHooks(word.text, ctx)))) {
982
1020
  tier = 1;
983
1021
  }
984
- 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
+ };
985
1031
  }
986
1032
  if (FILE_UTILS.has(program)) {
987
1033
  const inside = args
@@ -1192,10 +1238,13 @@ export function classifyShell(source, ctx) {
1192
1238
  here = moved.moved;
1193
1239
  continue;
1194
1240
  }
1195
- 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);
1196
1245
  // The disk is read before the chain runs, so a repository an earlier part
1197
1246
  // clones or builds is not there yet (#12926).
1198
- const blind = wrote && runsBlind(command, here);
1247
+ const blind = wrote && runsBlind(command, local);
1199
1248
  if (verdict.allow && !blind) {
1200
1249
  mutates ||= verdict.mutates;
1201
1250
  wrote ||= verdict.mutates;
@@ -1204,7 +1253,7 @@ export function classifyShell(source, ctx) {
1204
1253
  if (!verdict.allow && verdict.tier === 0) {
1205
1254
  return verdict;
1206
1255
  }
1207
- const ask = shellAsk(command, here);
1256
+ const ask = shellAsk(command, local);
1208
1257
  asked.push(blind ? { ...ask, tier: 1 } : ask);
1209
1258
  const held = blind ? deny(1) : verdict;
1210
1259
  if (!(held.allow || (worst && !worst.allow && held.tier >= worst.tier))) {
@@ -1217,7 +1266,9 @@ export function classifyShell(source, ctx) {
1217
1266
  }
1218
1267
  // One ask covers the whole command. Its tier is the strictest part's, and its
1219
1268
  // kind names every part, so a rule for one program never covers a chain.
1220
- const kinds = [...new Set(asked.map((entry) => entry.kind))].sort();
1269
+ const kinds = [
1270
+ ...new Set(asked.flatMap((entry) => entry.kind.split(" + "))),
1271
+ ].sort();
1221
1272
  const joined = kinds.join(" + ");
1222
1273
  const kind = joined.length <= 80 ? joined : `${kinds[0]} +${kinds.length - 1}`;
1223
1274
  const tier = Math.min(...asked.map((entry) => entry.tier));
@@ -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)) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talentos",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "type": "module",
5
5
  "description": "TalentOS CLI: push and pull skills, read and write team memory, and delegate work to your Talent from any coding agent.",
6
6
  "repository": {