@workit-dev/codex 1.8.1 → 1.9.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workit",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "Adaptive engineering workflow rails for Codex",
5
5
  "author": {
6
6
  "name": "BrainerVirus"
@@ -31377,6 +31377,13 @@ var SCAN_MS = 30 * 60000;
31377
31377
  // packages/workit-core/src/hooks/agent-model.ts
31378
31378
  var UNLISTED = new Set(["description", "prompt"]);
31379
31379
 
31380
+ // packages/workit-core/src/hooks/ytrack-guard.ts
31381
+ var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
31382
+ var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
31383
+ var gap = (part) => ({ workit: null, gap: part });
31384
+ var READ = new Map;
31385
+ var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
31386
+
31380
31387
  // packages/workit-core/src/hooks/handle.ts
31381
31388
  var offered = new Set;
31382
31389
  var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
@@ -16225,7 +16225,9 @@ var tokenize = (command, dialect) => {
16225
16225
  heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
16226
16226
  else if (pending === "herestring")
16227
16227
  (current.stdin ??= []).push(text);
16228
- else if (pending !== "input") {
16228
+ else if (pending === "input")
16229
+ (current.inputs ??= []).push(text);
16230
+ else {
16229
16231
  const at = current.words.length;
16230
16232
  current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
16231
16233
  if (expanding || !posix && word.startsWith("@"))
@@ -19162,7 +19164,7 @@ var splitDenial = (plan) => ({
19162
19164
  unblock: plan.unblock
19163
19165
  });
19164
19166
  // packages/workit-core/src/hooks/write-gate.ts
19165
- import { existsSync as existsSync10, realpathSync as realpathSync7, statSync as statSync3 } from "node:fs";
19167
+ import { existsSync as existsSync10, readdirSync as readdirSync3, readFileSync as readFileSync9, realpathSync as realpathSync7, statSync as statSync3 } from "node:fs";
19166
19168
  import os8 from "node:os";
19167
19169
  import path28 from "node:path";
19168
19170
 
@@ -19428,9 +19430,9 @@ var editsOf = (input) => {
19428
19430
  case "cp":
19429
19431
  case "ln":
19430
19432
  case "install": {
19431
- const target = args.indexOf("-t");
19432
- if (target >= 0)
19433
- return args[target + 1] ? [args[target + 1]] : null;
19433
+ const into = valueOf(args, /^(?:-t|--target-directory=?)(.*)$/s);
19434
+ if (into !== undefined)
19435
+ return [into];
19434
19436
  const last = operands(args).at(-1);
19435
19437
  return last ? [last] : null;
19436
19438
  }
@@ -19484,6 +19486,84 @@ var editsOf = (input) => {
19484
19486
  return [];
19485
19487
  }
19486
19488
  };
19489
+ var WRAPPERS2 = {
19490
+ sudo: "ugCDhpRrTtU",
19491
+ doas: "uC",
19492
+ env: "uCS",
19493
+ nice: "n",
19494
+ ionice: "cnp",
19495
+ timeout: "sk",
19496
+ stdbuf: "ioe",
19497
+ time: "fo",
19498
+ nohup: "",
19499
+ command: "",
19500
+ exec: "a",
19501
+ setsid: "",
19502
+ builtin: "",
19503
+ "!": "",
19504
+ npx: "p",
19505
+ bunx: "p"
19506
+ };
19507
+ var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
19508
+ var isConfigDir = (file) => configDirs().some((dir) => canonical3(dir) === canonical3(file));
19509
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path28.relative(canonical3(resolveStateDir()), canonical3(file)));
19510
+ var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
19511
+ var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move|copy(?:2|file|tree|File)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
19512
+ var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
19513
+ var readsRoot = (text, at) => {
19514
+ let call;
19515
+ for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
19516
+ const char = text[index - 1];
19517
+ if (char === ")")
19518
+ depth++;
19519
+ else if (char === "(" && depth-- === 0)
19520
+ call = /([\w$]+)\s*$/.exec(text.slice(0, index - 1))?.[1] ?? "";
19521
+ else if (depth <= 0 && /[;\n]/.test(char))
19522
+ break;
19523
+ }
19524
+ if (call !== undefined && READ_CALLS.test(call))
19525
+ return true;
19526
+ if (call !== undefined && !PATH_CALLS.test(call))
19527
+ return false;
19528
+ return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
19529
+ };
19530
+ var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
19531
+ var SCRIPT_OPTIONS = [
19532
+ [/^(?:(?:ba|z|k|da)?sh|source|\.)$/, /^(?:[-+][oO]|--(?:rcfile|init-file))$/],
19533
+ [/^python/, /^-[WXQ]$/],
19534
+ [
19535
+ /./,
19536
+ /^(?:-[rCI]|--(?:require|import|(?:experimental-)?loader|preload|input-type|conditions|title|cwd|tsconfig|project|env-file|config))$/
19537
+ ]
19538
+ ];
19539
+ var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
19540
+ var scriptArgs = (verb, args) => {
19541
+ const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
19542
+ const preloads = [];
19543
+ for (let at = 0;at < args.length; at++) {
19544
+ const [option, value] = args[at].split(/=(.*)/s);
19545
+ if (value !== undefined && PRELOAD.test(option))
19546
+ preloads.push(value);
19547
+ else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
19548
+ break;
19549
+ else if (takes.test(option)) {
19550
+ if (PRELOAD.test(option))
19551
+ preloads.push(args[at + 1] ?? "");
19552
+ at++;
19553
+ } else if (!/^[-+]/.test(option) && option !== "run")
19554
+ return { named: args[at], preloads };
19555
+ }
19556
+ return { preloads };
19557
+ };
19558
+ var unwrapped = (words) => {
19559
+ let at = 0;
19560
+ for (let takes;(takes = WRAPPERS2[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
19561
+ at++;
19562
+ while (at < words.length && /^-|^\w+=|^\d[\w.]*$/.test(words[at]))
19563
+ at += words[at].length === 2 && words[at][0] === "-" && takes.includes(words[at][1]) ? 2 : 1;
19564
+ }
19565
+ return at ? words.slice(at) : null;
19566
+ };
19487
19567
  var shellScript2 = (words) => {
19488
19568
  if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
19489
19569
  return null;
@@ -19728,9 +19808,8 @@ var gitOutputs = (args) => {
19728
19808
  const under = (file) => file === "." ? `${base}/${OPAQUE_TARGET}git` : /^[/~$]|^[A-Za-z]:[\\/]/.test(file) ? file : `${base}/${file}`;
19729
19809
  return files.length ? files.map(under) : null;
19730
19810
  };
19731
- var pathsIn = (text) => [
19732
- ...text.matchAll(/(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g)
19733
- ].map((match) => match[0]);
19811
+ var PATHS = /(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g;
19812
+ var pathsIn = (text) => [...text.matchAll(PATHS)].map((match) => match[0]);
19734
19813
  var linkSources = (args, at) => {
19735
19814
  const names = operands([...args]);
19736
19815
  const into = args.indexOf("-t");
@@ -19857,12 +19936,12 @@ var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
19857
19936
  var PUSHD2 = new Set(["pushd", "push-location"]);
19858
19937
  var POPD2 = new Set(["popd", "pop-location"]);
19859
19938
  var UNKNOWN_DIR = path28.resolve(path28.parse(process.cwd()).root, ".workit-unknown-dir");
19860
- var cdInto = (dir, words, strict = false, vars = new Map) => {
19939
+ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
19861
19940
  const lost = strict ? UNKNOWN_DIR : undefined;
19862
19941
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
19863
19942
  const named = found === undefined ? undefined : expandVars(found, vars);
19864
19943
  const target = named === undefined ? undefined : homeExpanded(named);
19865
- if (target === "-" || target && /^~|[$`*?]/.test(target))
19944
+ if (target === "-" || target && (globs ? /^~|[$`]/ : /^~|[$`*?]/).test(target))
19866
19945
  return lost;
19867
19946
  if (dir === undefined)
19868
19947
  return lost;
@@ -19885,7 +19964,8 @@ var assignmentsOf = (words) => {
19885
19964
  var commandWords = (words) => {
19886
19965
  let start = 0;
19887
19966
  while (start < words.length && COMPOUND.has(words[start]))
19888
- start++;
19967
+ if (words[start++] === "function")
19968
+ start++;
19889
19969
  return words.slice(start);
19890
19970
  };
19891
19971
  var REBINDS_ANY = new Set([
@@ -20037,7 +20117,8 @@ var expansions = (text, vars, loops) => {
20037
20117
  last = match.index + match[0].length;
20038
20118
  const value = vars.get(name);
20039
20119
  const values = loops.get(name) ?? (value === undefined ? null : [value]);
20040
- const applied = values?.map((item) => applyOperator(item, match[2] ?? ""));
20120
+ const fallback = /^:?[-=](.*)$/s.exec(match[2] ?? "")?.[1];
20121
+ const applied = values?.flatMap((item) => fallback === undefined ? [applyOperator(item, match[2] ?? "")] : item === "" ? expansions(fallback, vars, loops) : [item]);
20041
20122
  const fits = applied && results.length * applied.length <= MAX_EXPANSIONS2;
20042
20123
  results = fits && applied.every((item) => item !== null) ? results.flatMap((prefix) => applied.map((item) => prefix + literal + item)) : results.map((prefix) => prefix + literal + match[0]);
20043
20124
  }
@@ -20083,6 +20164,7 @@ var homeExpanded = (file) => {
20083
20164
  };
20084
20165
  var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
20085
20166
  const targets = [];
20167
+ const written = new Map;
20086
20168
  let dir = cwd;
20087
20169
  let stack = [];
20088
20170
  const segments = segmentsOf(command, dialect);
@@ -20145,6 +20227,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
20145
20227
  continue;
20146
20228
  }
20147
20229
  const body = commandWords(segment.words);
20230
+ const before = segments[segments.indexOf(segment) - 1];
20231
+ const feeder = before?.pipe ? before : undefined;
20148
20232
  const keywords = segment.words.length - body.length;
20149
20233
  for (const keyword of segment.words.slice(0, keywords))
20150
20234
  if (OPENS.has(keyword))
@@ -20198,7 +20282,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
20198
20282
  }
20199
20283
  const plain = !segment.conditional;
20200
20284
  if (CD2.has(name)) {
20201
- dir = cdInto(dir, words, strict, vars);
20285
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
20202
20286
  moved(plain);
20203
20287
  continue;
20204
20288
  }
@@ -20209,7 +20293,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
20209
20293
  }
20210
20294
  if (PUSHD2.has(name)) {
20211
20295
  stack.push(dir);
20212
- dir = cdInto(dir, words, strict, vars);
20296
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
20213
20297
  moved(plain);
20214
20298
  continue;
20215
20299
  }
@@ -20218,15 +20302,94 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
20218
20302
  moved(plain);
20219
20303
  continue;
20220
20304
  }
20221
- const inner = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
20305
+ const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
20306
+ const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
20307
+ const inner = held.length === 1 ? held[0] : literal;
20222
20308
  const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
20223
20309
  if (inner !== null && dir !== undefined)
20224
20310
  for (const runIn of workitRunDir(dir, words, atAll))
20225
20311
  targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
20312
+ const bare = strict === "registry" && depth < 4 ? unwrapped(words) : null;
20313
+ if (bare?.length && dir !== undefined)
20314
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
20315
+ if (strict === "registry" && dir !== undefined && depth < 4) {
20316
+ const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
20317
+ const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
20318
+ const fed = segment.stdin?.join(`
20319
+ `);
20320
+ if (fed !== undefined)
20321
+ for (const file of segment.redirects)
20322
+ for (const into of atAll(file))
20323
+ written.set(into, fed);
20324
+ const read = (file) => atAll(file).flatMap((script) => {
20325
+ const made = written.get(script);
20326
+ if (made !== undefined)
20327
+ return [made];
20328
+ try {
20329
+ const stat = statSync3(script);
20330
+ const text = stat.isFile() && stat.size <= 262144 ? readFileSync9(script, "utf8") : "\x00";
20331
+ return text.includes("\x00") ? [] : [text];
20332
+ } catch {
20333
+ return [];
20334
+ }
20335
+ });
20336
+ const { named: operand, preloads } = scriptArgs(verb, args);
20337
+ const named = operand === "/dev/stdin" ? undefined : operand;
20338
+ const maker = feeder ? commandWords(feeder.words) : [];
20339
+ const [format = "", ...values] = maker.slice(1);
20340
+ let filled = 0;
20341
+ const printed = format.replace(/%[sbq]/g, () => values[filled++] ?? "");
20342
+ const piped = /^(?:echo|printf)$/.test(maker[0] ?? "") ? [[maker[0] === "printf" ? printed : format, ...values].join(`
20343
+ `).replaceAll("\\n", `
20344
+ `)] : maker[0] === "cat" ? [...feeder?.stdin ?? [], ...operands(maker.slice(1)).flatMap(read)] : [];
20345
+ const inputs = (segment.inputs ?? []).filter((file) => file !== "/dev/null");
20346
+ const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
20347
+ const others = [];
20348
+ if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
20349
+ if (named === undefined && shellScript2(run) === null)
20350
+ shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
20351
+ else if (named !== undefined && shellScript2(run) === null)
20352
+ shells.push(...read(named));
20353
+ shells.push(...preloads.flatMap(read));
20354
+ } else if (INTERPRETERS.test(verb)) {
20355
+ const code = args.findIndex((arg) => /^-[a-zA-Z]*[ce]$|^--eval$/.test(arg));
20356
+ if (code >= 0)
20357
+ others.push(...expansions(args[code + 1] ?? "", vars, loops));
20358
+ others.push(...named === undefined ? [...segment.stdin ?? [], ...inputs.flatMap(read), ...piped] : read(named), ...preloads.flatMap(read));
20359
+ } else if (/[\\/]/.test(run[0] ?? ""))
20360
+ for (const text of read(run[0]))
20361
+ (/^#!.*\b(?:python|node|bun|deno|ruby|perl|php)/.test(text) ? others : shells).push(text);
20362
+ for (const script of shells)
20363
+ targets.push(...segmentTargets(dir, script, "posix", depth + 1, strict, vars));
20364
+ for (const raw of others) {
20365
+ const text = raw.replace(/^\s*(?:#(?!!)|\/\/|\/?\*).*$/gm, "");
20366
+ const joined = [
20367
+ ...text.matchAll(/(?:["'][^"'\s,*?[]+["']\s*[,/+]\s*)+["'][^"'\s,*?[]+["']/g)
20368
+ ].map(({ 0: literals, index }) => ({
20369
+ word: literals.replace(/["']\s*[,/+]\s*["']/g, "/").replace(/["']/g, ""),
20370
+ index
20371
+ }));
20372
+ const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
20373
+ const under = (word) => homes ? [path28.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
20374
+ const found = [
20375
+ ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
20376
+ ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
20377
+ ];
20378
+ for (const { file, index } of found)
20379
+ if (!isRoot(file) || !readsRoot(text, index))
20380
+ targets.push(file);
20381
+ }
20382
+ if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
20383
+ for (const file of operands(args))
20384
+ targets.push(...atAll(file));
20385
+ if (verb === "cp" && args.some((arg) => /^-[a-zA-Z]*l|^--link$/.test(arg)))
20386
+ for (const file of operands(args).slice(0, -1))
20387
+ targets.push(...atAll(file));
20388
+ }
20226
20389
  if (strict && dir !== undefined) {
20227
20390
  const runIn = dir;
20228
20391
  for (const sub of depth < 4 ? segment.subs ?? [] : [])
20229
- targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, true, vars));
20392
+ targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, strict, vars));
20230
20393
  const expanding = new Set(segment.expands ?? []);
20231
20394
  const scriptOf = (index) => {
20232
20395
  const word = body[index];
@@ -20242,12 +20405,15 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
20242
20405
  if (runner !== undefined && expanding.has(keywords + lead + ran) && unresolvedRefs(homeExpanded(runner)).length > 0)
20243
20406
  targets.push(unknownVarTarget(runner));
20244
20407
  const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
20408
+ const quiet = strict === "registry" && INTERPRETERS.test(runner?.split(/[\\/]/).at(-1) ?? "");
20245
20409
  for (const file of opaque ?? [])
20246
20410
  for (const resolved of atAll(file))
20247
- targets.push(file === "." ? path28.join(resolved, here) : resolved);
20411
+ if (!quiet || !isRoot(resolved))
20412
+ targets.push(file === "." ? path28.join(resolved, here) : resolved);
20248
20413
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
20249
- if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
20250
- targets.push(...linkSources(words.slice(ln + 1), at));
20414
+ const lnArgs = words.slice(ln + 1);
20415
+ if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
20416
+ targets.push(...linkSources(lnArgs, at));
20251
20417
  }
20252
20418
  for (const file of segment.redirects)
20253
20419
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file))
@@ -20282,11 +20448,14 @@ var workitCwd = (dir, args, resolve) => {
20282
20448
  };
20283
20449
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
20284
20450
  try {
20451
+ const env = new Map(strict === "registry" ? [...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]) : []);
20285
20452
  return [
20286
- ...segmentTargets(cwd, command, dialect, 0, strict),
20453
+ ...segmentTargets(cwd, command, dialect, 0, strict, env),
20287
20454
  ...gitMutationDirs(cwd, command, dialect).map((dir) => path28.join(dir, DIR_TARGET))
20288
20455
  ];
20289
- } catch {
20456
+ } catch (error) {
20457
+ if (strict === "registry")
20458
+ throw error;
20290
20459
  return [];
20291
20460
  }
20292
20461
  };
@@ -20344,12 +20513,79 @@ var claimAll = (owner, targets, deps) => {
20344
20513
  };
20345
20514
  var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path28.resolve(cwd, file)) : [path28.join(cwd, DIR_TARGET)];
20346
20515
  var configDirs = () => [resolveConfigDir(), grantsDir()];
20516
+ var globbed = (cwd, target, state, configs) => {
20517
+ if (!/[*?[]/.test(target))
20518
+ return [];
20519
+ const raw = path28.resolve(cwd, target).split(path28.sep);
20520
+ const literal = raw.findIndex((part) => /[*?[]/.test(part));
20521
+ const pattern = [
20522
+ ...canonical3(raw.slice(0, literal).join(path28.sep) || path28.sep).replace(/[\\/]+$/, "").split(path28.sep),
20523
+ ...raw.slice(literal)
20524
+ ];
20525
+ const segment = (glob, name) => {
20526
+ try {
20527
+ return new RegExp(`^${glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/g, "\\$&").replace(/\[!/g, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, CASE_INSENSITIVE ? "i" : "").test(name);
20528
+ } catch {
20529
+ return false;
20530
+ }
20531
+ };
20532
+ const hit = (file, below) => {
20533
+ const parts = canonical3(file).split(path28.sep);
20534
+ return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
20535
+ };
20536
+ let roots = [];
20537
+ try {
20538
+ roots = readdirSync3(state).filter((name) => /^(?:issued|approvals$)/.test(name));
20539
+ } catch {}
20540
+ return [
20541
+ ...roots.map((name) => path28.join(state, name)).filter((root) => hit(root, true)),
20542
+ ...configs.flatMap((dir) => [dir, path28.join(dir, "workspaces.json")]).filter((file) => hit(file, false))
20543
+ ];
20544
+ };
20545
+ var guardedInodes = (state, configs) => {
20546
+ const seen = new Map;
20547
+ let budget = 2000;
20548
+ const add = (file, registry) => {
20549
+ if (budget-- <= 0)
20550
+ return;
20551
+ const stat = statSync3(file, { throwIfNoEntry: false });
20552
+ if (stat?.isFile())
20553
+ seen.set(`${stat.dev}:${stat.ino}`, registry);
20554
+ else if (stat?.isDirectory())
20555
+ for (const name of readdirSync3(file))
20556
+ add(path28.join(file, name), registry);
20557
+ };
20558
+ try {
20559
+ for (const dir of configs)
20560
+ add(path28.join(dir, "workspaces.json"), "grants");
20561
+ for (const name of readdirSync3(state))
20562
+ if (/^(?:issued|approvals$)/.test(name))
20563
+ add(path28.join(state, name), name === "approvals" ? "approvals" : "issued");
20564
+ } catch {}
20565
+ return seen;
20566
+ };
20567
+ var hardLinked = (file, state, configs, inodes) => {
20568
+ try {
20569
+ const stat = statSync3(file, { throwIfNoEntry: false });
20570
+ if (!stat?.isFile() || stat.nlink < 2 || !stat.ino)
20571
+ return;
20572
+ inodes.map ??= guardedInodes(state, configs);
20573
+ return inodes.map.get(`${stat.dev}:${stat.ino}`);
20574
+ } catch {
20575
+ return;
20576
+ }
20577
+ };
20347
20578
  var registryTarget = (cwd, targets) => {
20348
20579
  const state = resolveStateDir();
20349
20580
  const configs = configDirs();
20581
+ const inodes = {};
20350
20582
  for (const target of targets) {
20351
20583
  const file = homeExpanded(target);
20352
- const registry = underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
20584
+ const glob = globbed(cwd, file, state, configs)[0];
20585
+ const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
20586
+ if (viaGlob)
20587
+ return { file: target, registry: viaGlob.registry };
20588
+ const registry = hardLinked(path28.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
20353
20589
  if (registry)
20354
20590
  return { file: target, registry };
20355
20591
  }
@@ -20371,7 +20607,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
20371
20607
  };
20372
20608
  var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
20373
20609
  const parts = partsUnder(dir, cwd, target, platform, real);
20374
- return parts?.length === 1 && (parts[0] === "" || parts[0] === "workspaces.json");
20610
+ return parts?.length === 1 && ["", "workspaces.json", DIR_TARGET].includes(parts[0]);
20375
20611
  };
20376
20612
  var unquotedWindowsRegistry = (command, platform = process.platform) => {
20377
20613
  if (platform !== "win32" || !command.includes("\\"))
@@ -20379,8 +20615,21 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
20379
20615
  const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
20380
20616
  const text = flat(command);
20381
20617
  const state = flat(resolveStateDir());
20382
- const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configDirs().some((dir) => text.includes(`${flat(dir)}/workspaces.json`)) ? "grants" : null;
20383
- return registry && shellWrites(command).writes ? registry : null;
20618
+ const configs = configDirs().map(flat);
20619
+ const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configs.some((dir) => text.includes(dir)) ? "grants" : null;
20620
+ if (!registry)
20621
+ return null;
20622
+ const spans = command.replace(/[^\s'"|;&<>()]*\\[^\s'"|;&<>()]*/g, (word) => word.replaceAll("\\", "/"));
20623
+ const writes = shellWrites(spans);
20624
+ const moved = [
20625
+ "",
20626
+ ...[...spans.matchAll(/(?:^|[;&|(]\s*)(?:cd|pushd|chdir)\s+([^\s;&|)]+)/g)].map((match) => `${match[1]}/`)
20627
+ ];
20628
+ const named = (target) => moved.some((dir) => {
20629
+ const at = flat(/^(?:[a-z]:)?\//i.test(target) ? target : dir + target).replace(/\/\.?\//g, "/");
20630
+ return registry === "grants" ? configs.some((cfg) => [cfg, `${cfg}/`, `${cfg}/workspaces.json`].includes(at)) : at.includes(`${state}/${registry}`);
20631
+ });
20632
+ return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
20384
20633
  };
20385
20634
  var REGISTRY_DENY = {
20386
20635
  issued: {
@@ -20401,9 +20650,10 @@ var REGISTRY_DENY = {
20401
20650
  };
20402
20651
  var registryDeny = ({ file, registry }) => {
20403
20652
  const { label, what, unblock } = REGISTRY_DENY[registry];
20653
+ const named = path28.basename(file).startsWith(".workit-") ? path28.dirname(file) : file;
20404
20654
  return {
20405
20655
  kind: "deny",
20406
- reason: `workit ${label}: ${file} is under ${what}. ${unblock}`,
20656
+ reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
20407
20657
  unblock
20408
20658
  };
20409
20659
  };
@@ -20425,10 +20675,20 @@ function writeGate(cwd, paths, owner, deps) {
20425
20675
  function shellGate(cwd, command, owner, dialect = "posix", deps) {
20426
20676
  try {
20427
20677
  const windows = unquotedWindowsRegistry(command);
20428
- const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
20678
+ const forged = registryTarget(cwd, shellMutationTargets(cwd, command, dialect, "registry")) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
20429
20679
  if (forged)
20430
20680
  return registryDeny(forged);
20431
- } catch {}
20681
+ } catch {
20682
+ const text = command.replaceAll("\\", "/").replace(/['"]/g, "").toLowerCase();
20683
+ if (/issued|approvals|workspaces\.json|\.config\/workit|state\/workit/.test(text) || [resolveStateDir(), ...configDirs()].some((dir) => text.includes(dir.replaceAll("\\", "/").toLowerCase()))) {
20684
+ const { unblock } = REGISTRY_DENY.grants;
20685
+ return {
20686
+ kind: "deny",
20687
+ reason: `workit registry guard: Workit could not analyse this command, which names a guarded path; split it into plain commands. ${unblock}`,
20688
+ unblock
20689
+ };
20690
+ }
20691
+ }
20432
20692
  const writes = shellWrites(command);
20433
20693
  let targets = [];
20434
20694
  if (owner)
@@ -22035,7 +22295,7 @@ function confineImplementerShell(input, command, dialect = "posix") {
22035
22295
  }
22036
22296
  var SCRATCH = ".workit-scratch";
22037
22297
  var SHELL_NAMES = /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/;
22038
- var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
22298
+ var INTERPRETERS2 = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
22039
22299
  var FED = /^(?:-|\/dev\/stdin|\/dev\/fd\/0|\/proc\/self\/fd\/0)$|^<\(/;
22040
22300
  var LEADS = /^(?:sudo|doas|env|command|builtin|exec|nohup|time|nice|timeout|stdbuf|xargs|busybox|!|\{|if|then|else|elif|do|while|until|\w+=.*|[-\d].*)$/s;
22041
22301
  var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
@@ -22152,7 +22412,7 @@ var judgeRefusal = (command, fed, depth = 0) => {
22152
22412
  }
22153
22413
  }
22154
22414
  }
22155
- if (INTERPRETERS.test(name) && !args.some((arg) => INLINE.test(arg))) {
22415
+ if (INTERPRETERS2.test(name) && !args.some((arg) => INLINE.test(arg))) {
22156
22416
  const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED.test(args[index - 1] ?? ""));
22157
22417
  if (FED.test(operand ?? "") || operand === undefined && !/^(?:bun|deno)$/.test(name))
22158
22418
  return unseen;
@@ -22504,7 +22764,7 @@ var cdWorkitSplit = (command) => {
22504
22764
  };
22505
22765
 
22506
22766
  // packages/workit-core/src/hooks/model-limit.ts
22507
- import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync3, readSync, statSync as statSync5 } from "node:fs";
22767
+ import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync4, readSync, statSync as statSync5 } from "node:fs";
22508
22768
  import os9 from "node:os";
22509
22769
  import path33 from "node:path";
22510
22770
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
@@ -22704,7 +22964,7 @@ var firstPrompt = (file) => {
22704
22964
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
22705
22965
  var listDir = (dir) => {
22706
22966
  try {
22707
- return readdirSync3(dir).map((name) => path33.join(dir, name));
22967
+ return readdirSync4(dir).map((name) => path33.join(dir, name));
22708
22968
  } catch {
22709
22969
  return [];
22710
22970
  }
@@ -22853,6 +23113,313 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
22853
23113
  return agentModelDecision(cwd, checked.input, { change: checked.change, permissionMode });
22854
23114
  };
22855
23115
 
23116
+ // packages/workit-core/src/hooks/ytrack-word.ts
23117
+ var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
23118
+ var namesYtrack = (text) => {
23119
+ const bare = text.replace(/['"\\]/g, "");
23120
+ return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
23121
+ };
23122
+
23123
+ // packages/workit-core/src/hooks/ytrack-guard.ts
23124
+ var name2 = (word = "") => (word.split(/[\\/]/).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd)$|@.*$/g, "");
23125
+ var quote2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
23126
+ var minutesOf = (text = "") => {
23127
+ if (/^\d+$/.test(text.trim()))
23128
+ return Number(text) > 0 ? Number(text) : null;
23129
+ let total = 0;
23130
+ const rest = text.replace(/(\d+(?:\.\d+)?)\s*(h|hours?|m|mins?|minutes?)(?![a-z])/gi, (_, n, unit) => {
23131
+ total += Number(n) * (/^h/i.test(unit) ? 60 : 1);
23132
+ return "";
23133
+ });
23134
+ return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
23135
+ };
23136
+ var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
23137
+ var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
23138
+ var standsAlone = (args, at) => {
23139
+ const before = args[at - 1] ?? "";
23140
+ const end = args.indexOf("--");
23141
+ return (end < 0 || at < end) && (!before.startsWith("-") || before.includes("=") || BARE.has(before));
23142
+ };
23143
+ var flagged = (args, flag) => args.some((arg, at) => flag.test(arg) && standsAlone(args, at));
23144
+ var asksHelp2 = (args) => flagged(args, /^(?:--help|-h)$/);
23145
+ var GROUPS = {
23146
+ issue: "issue",
23147
+ "work-item": "work-item",
23148
+ workitem: "work-item",
23149
+ api: "api"
23150
+ };
23151
+ var ASKS = /^(?:post|put|patch|delete)$/i;
23152
+ var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
23153
+ var QUIET = /^--(?:debug|no-color|json|jq)$/;
23154
+ var CARRIES = {
23155
+ note: { "--body": "body", "-b": "body", "--body-file": "file" },
23156
+ time: { "--duration": "duration", "--text": "text", "--date": "date" },
23157
+ create: {
23158
+ "--project": "project",
23159
+ "-p": "project",
23160
+ "--summary": "summary",
23161
+ "-s": "summary",
23162
+ "--description": "description",
23163
+ "--description-file": "file"
23164
+ }
23165
+ };
23166
+ var gap = (part) => ({ workit: null, gap: part });
23167
+ var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
23168
+ var mapWrite = (verb, args) => {
23169
+ const values = {};
23170
+ const operands = [];
23171
+ for (let at = 0;at < args.length; at++) {
23172
+ const arg = args[at];
23173
+ if (!arg.startsWith("-") || arg === "-") {
23174
+ operands.push(arg);
23175
+ continue;
23176
+ }
23177
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
23178
+ const flag = eq > 0 ? arg.slice(0, eq) : arg;
23179
+ const value = eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
23180
+ if (QUIET.test(flag))
23181
+ continue;
23182
+ const key = CARRIES[verb][flag];
23183
+ if (!key || value === undefined || key in values)
23184
+ return gap(`\`${flag}\``);
23185
+ if (/[$`]|^~/.test(value))
23186
+ return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
23187
+ values[key] = value;
23188
+ }
23189
+ const [issue, ...more] = operands.slice(2);
23190
+ const v = values;
23191
+ if (verb === "create") {
23192
+ if (issue !== undefined)
23193
+ return gap(`the operand \`${issue}\``);
23194
+ if (v.project === undefined || v.summary === undefined)
23195
+ return gap("a missing --project or --summary");
23196
+ if (v.description !== undefined && v.file !== undefined)
23197
+ return gap("both --description and --description-file");
23198
+ if (v.file === "-")
23199
+ return gap("text read from standard input");
23200
+ return {
23201
+ workit: [
23202
+ "workit youtrack create",
23203
+ pair("--project", v.project),
23204
+ pair("--summary", v.summary),
23205
+ v.description === undefined ? "" : pair("--description", v.description),
23206
+ v.file === undefined ? "" : pair("--file", v.file)
23207
+ ].filter(Boolean).join(" ")
23208
+ };
23209
+ }
23210
+ if (issue === undefined || more.length || !/^[A-Z]+-\d+$/.test(issue))
23211
+ return gap("the issue, which must be one id like ABC-123");
23212
+ if (verb === "note") {
23213
+ if (v.body === undefined === (v.file === undefined))
23214
+ return gap("a comment that needs exactly one of --body or --body-file");
23215
+ if (v.file === "-")
23216
+ return gap("text read from standard input");
23217
+ if (v.body !== undefined && !v.body.trim())
23218
+ return gap("an empty --body");
23219
+ return {
23220
+ workit: `workit youtrack note ${issue} ${v.body === undefined ? pair("--file", v.file) : pair("--markdown", v.body)}`
23221
+ };
23222
+ }
23223
+ const minutes = minutesOf(v.duration);
23224
+ if (minutes === null)
23225
+ return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
23226
+ if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
23227
+ return gap(`\`--date ${v.date}\``);
23228
+ return {
23229
+ workit: [
23230
+ `workit youtrack time ${issue} --minutes ${minutes}`,
23231
+ v.text === undefined ? "" : pair("--text", v.text),
23232
+ v.date === undefined ? "" : pair("--date", v.date)
23233
+ ].filter(Boolean).join(" ")
23234
+ };
23235
+ };
23236
+ var UNCOVERED = { workit: null, gap: "" };
23237
+ var classify = (args) => {
23238
+ if (asksHelp2(args))
23239
+ return null;
23240
+ const lenient = args.filter((arg, at) => !arg.startsWith("-") && !VALUE.has(args[at - 1] ?? ""));
23241
+ const strict = args.filter((arg, at) => !arg.startsWith("-") && standsAlone(args, at));
23242
+ return judge(args, lenient) ?? judge(args, strict);
23243
+ };
23244
+ var judge = (args, words) => {
23245
+ const group = GROUPS[words[0] ?? ""];
23246
+ const verb = words[1] ?? "";
23247
+ if (group === "api") {
23248
+ const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
23249
+ if (methods.some((method) => ASKS.test(method.value)))
23250
+ return UNCOVERED;
23251
+ if (methods.some((method) => method.alone))
23252
+ return null;
23253
+ return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
23254
+ }
23255
+ if (group === "work-item" && /^(?:add|create)$/.test(verb))
23256
+ return mapWrite("time", args);
23257
+ if (group === "work-item")
23258
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
23259
+ if (group !== "issue")
23260
+ return null;
23261
+ if (verb === "comment")
23262
+ return mapWrite("note", args);
23263
+ if (verb === "create")
23264
+ return mapWrite("create", args);
23265
+ if (verb === "command")
23266
+ return flagged(args, /^--dry-run$/) ? null : UNCOVERED;
23267
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
23268
+ };
23269
+ var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
23270
+ var MAX_DEPTH2 = 4;
23271
+ var READ = new Map;
23272
+ var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
23273
+ var ungrant = (write) => write.workit ? { command: write.command, ...NOT_PLAIN } : write;
23274
+ var ytrackArgs = (line, found, depth, names, plain) => {
23275
+ const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
23276
+ const tail = workitCheckTail(line);
23277
+ if (tail) {
23278
+ inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
23279
+ return true;
23280
+ }
23281
+ const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
23282
+ const script = flag > 0 ? line[flag + 1] : name2(line[0]) === "eval" ? line.slice(1).join(" ") : undefined;
23283
+ if (script !== undefined) {
23284
+ inner(script);
23285
+ return true;
23286
+ }
23287
+ let at = 0;
23288
+ let called = false;
23289
+ const runner = name2(line[0]);
23290
+ if (/^(?:npx|bunx|pnpx)$/.test(runner) || /^(?:p?npm|yarn)$/.test(runner) && /^(?:dlx|exec|x)$/.test(line[1] ?? "")) {
23291
+ at = runner.endsWith("x") ? 1 : 2;
23292
+ for (;line[at]?.startsWith("-"); at++) {
23293
+ if (/^(?:-c|--call)$/.test(line[at])) {
23294
+ inner(line[at + 1] ?? "");
23295
+ called = true;
23296
+ }
23297
+ if (/^(?:-[pc]|--package|--call)$/.test(line[at]))
23298
+ at++;
23299
+ }
23300
+ }
23301
+ const resolved = /^(?:\$\(|`)\s*(?:which|command\s+-v|type\s+-[pP])\s+ytrack\s*[)`]$/.test(line[at] ?? "");
23302
+ const alias = names.get(line[at] ?? "");
23303
+ if (name2(line[at]) !== "ytrack" && !resolved && !alias)
23304
+ return called;
23305
+ const argv = [...alias ?? [], ...line.slice(at + 1)];
23306
+ const write = classify(argv);
23307
+ if (write) {
23308
+ const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
23309
+ found.push(plain ? one : ungrant(one));
23310
+ }
23311
+ return true;
23312
+ };
23313
+ var aliases = (command) => {
23314
+ const found = new Map;
23315
+ for (const [, alias, a, b, c] of command.matchAll(/\balias\s+([\w.-]+)=(?:'([^']*)'|"([^"]*)"|([^\s;&|)]+))/g)) {
23316
+ const value = a ?? b ?? c ?? "";
23317
+ if (/^(?:\S*\/)?ytrack(?:\s|$)/.test(value))
23318
+ found.set(alias, value.split(/\s+/).slice(1));
23319
+ }
23320
+ for (const [, a, b, body] of command.matchAll(/(?:\bfunction\s+([\w.-]+)(?:\s*\(\s*\))?|\b([\w.-]+)\s*\(\s*\))\s*\{([^}]*)\}/g))
23321
+ if (/(?:^|[\s;&|])(?:\S*\/)?ytrack\s/.test(body ?? ""))
23322
+ found.set(a ?? b ?? "", []);
23323
+ return found;
23324
+ };
23325
+ var PASS = /^(?:command|exec|nohup|setsid|time|nice|ionice|stdbuf|chronic|unbuffer|timeout)$/;
23326
+ var COMPOUND3 = /^(?:for|select|while|until|repeat|do|done|function|case|foreach|coproc)$/;
23327
+ var passed = (words) => {
23328
+ let at = 0;
23329
+ for (;at < words.length; at++) {
23330
+ const word = words[at];
23331
+ if (/^[A-Za-z_]\w*=/.test(word))
23332
+ return [];
23333
+ if (!PASS.test(word))
23334
+ break;
23335
+ if (/^(?:exec|command)$/.test(word) && words[at + 1]?.startsWith("-"))
23336
+ return [];
23337
+ while (/^(?:-|\d)/.test(words[at + 1] ?? ""))
23338
+ at++;
23339
+ }
23340
+ return words.slice(at);
23341
+ };
23342
+ var plainLines = (command, dialect) => {
23343
+ let first = null;
23344
+ const later = [];
23345
+ for (const segment of segmentsOf(command, dialect)) {
23346
+ if (segment.group || segment.unanalyzable || segment.subs?.length)
23347
+ return null;
23348
+ if (COMPOUND3.test(segment.words[0] ?? ""))
23349
+ return null;
23350
+ if (segment.words.some((word) => /^YTRACK_\w*=/.test(word)))
23351
+ return null;
23352
+ const names = namesYtrack([...segment.words, ...segment.stdin ?? []].join(" "));
23353
+ if (first === null) {
23354
+ if (!names || segment.expands?.length)
23355
+ return null;
23356
+ first = passed(segment.words);
23357
+ } else if (names)
23358
+ later.push(segment.words);
23359
+ }
23360
+ return first ? { first, later } : null;
23361
+ };
23362
+ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
23363
+ if (!namesYtrack(command))
23364
+ return [];
23365
+ if (depth > MAX_DEPTH2)
23366
+ throw new Error("ytrack nested too deep");
23367
+ const key = `${plain}\x00${dialect}\x00${command}`;
23368
+ const known = READ.get(key);
23369
+ if (known)
23370
+ return known;
23371
+ let found = [];
23372
+ const lines = plain ? plainLines(command, dialect) : null;
23373
+ const none = new Map;
23374
+ if (!lines || !ytrackArgs(lines.first, found, depth, none, true) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
23375
+ found = [];
23376
+ for (const line of commandLines(command, dialect))
23377
+ ytrackArgs(line, found, depth, aliases(command), false);
23378
+ }
23379
+ READ.set(key, found);
23380
+ if (READ.size > 64)
23381
+ READ.delete(READ.keys().next().value);
23382
+ return found;
23383
+ };
23384
+ var writesMode = (cwd) => resolveRuntimeWorkspaceVcs(cwd)?.youtrack?.writes;
23385
+ var ytrackGate = (cwd, command, dialect, ask) => {
23386
+ let writes;
23387
+ try {
23388
+ const merged = new Map;
23389
+ for (const write of ytrackWrites(command, dialect)) {
23390
+ const seen = merged.get(write.command);
23391
+ merged.set(write.command, !seen || !write.workit ? write : !seen.workit ? seen : ungrant(write));
23392
+ }
23393
+ writes = [...merged.values()];
23394
+ } catch {
23395
+ if (writesMode(cwd) === "auto")
23396
+ return null;
23397
+ return {
23398
+ kind: "deny",
23399
+ reason: `Workit could not analyse this command, which names ytrack: run each ytrack call as its own plain command so a YouTrack write can ask the user first (#780).`,
23400
+ unblock: null
23401
+ };
23402
+ }
23403
+ if (!writes.length || writesMode(cwd) === "auto")
23404
+ return null;
23405
+ const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
23406
+ const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
23407
+ if (!calls.length && ask)
23408
+ return {
23409
+ kind: "ask",
23410
+ reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
23411
+ };
23412
+ const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
23413
+ const run = calls.length ? ` Run ${calls.join(", then ")} instead: it asks the user first. When it answers approval_needed, run exactly the \`workit approve <id>\` it names, now, with nothing around it (no 2>&1, pipe or echo), so the host asks the user; then rerun the workit call once.` : "";
23414
+ const user = bare.length ? ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
23415
+ const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
23416
+ return {
23417
+ kind: "deny",
23418
+ reason: `${why}${run}${user}${rerun}`,
23419
+ unblock: writes[0]?.workit ?? null
23420
+ };
23421
+ };
23422
+
22856
23423
  // packages/workit-core/src/hooks/handle.ts
22857
23424
  var usable2 = (value) => value === "native" || value === "partial";
22858
23425
  var NONE6 = { kind: "none" };
@@ -22978,6 +23545,9 @@ function decide(input, deps) {
22978
23545
  const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) : NONE6;
22979
23546
  if (policy.kind !== "none")
22980
23547
  return policy;
23548
+ const ytrack = canDeny ? ytrackGate(input.cwd, event.command, event.dialect ?? "posix", input.host === "claude_code") : null;
23549
+ if (ytrack)
23550
+ return ytrack;
22981
23551
  const split = canDeny ? cdWorkitSplit(event.command) : null;
22982
23552
  if (split)
22983
23553
  return {
@@ -23170,7 +23740,7 @@ var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
23170
23740
  `);
23171
23741
  } catch {}
23172
23742
  };
23173
- var QUIET = new Set([
23743
+ var QUIET2 = new Set([
23174
23744
  "stop",
23175
23745
  "subagent.stop",
23176
23746
  "shell.post",
@@ -23178,7 +23748,7 @@ var QUIET = new Set([
23178
23748
  "prompt.submit",
23179
23749
  null
23180
23750
  ]);
23181
- var skipDecision = (event) => QUIET.has(event) ? { kind: "none" } : { kind: "context", text: HOOK_SKIP_TEXT };
23751
+ var skipDecision = (event) => QUIET2.has(event) ? { kind: "none" } : { kind: "context", text: HOOK_SKIP_TEXT };
23182
23752
  var TIMED_OUT = Symbol("timed out");
23183
23753
  var within2 = async (work, ms) => {
23184
23754
  let timer;
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // packages/workit-codex/hooks/launcher.ts
4
- import { readFileSync } from "node:fs";
4
+ import { readFileSync, realpathSync, statSync } from "node:fs";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  var foundNode = process.env.WORKIT_HOOK_NODE_VERSION || process.versions.node;
@@ -39,6 +39,11 @@ var { configDir } = await import("./workit-hook-z09frbdk.js");
39
39
  var { standingPending } = await import("./workit-hook-mk64s4fk.js");
40
40
  var { recordHookRun } = await import("./workit-hook-zyj0kzc5.js");
41
41
  var { observeHookBudget } = await import("./workit-hook-3g6cv3hd.js");
42
+ var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
43
+ var namesYtrack = (text) => {
44
+ const bare = text.replace(/['"\\]/g, "");
45
+ return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
46
+ };
42
47
  var payload = "";
43
48
  for await (const chunk of process.stdin)
44
49
  payload += String(chunk);
@@ -46,8 +51,7 @@ var SHELL_TOOLS = new Set(["bash", "unified-exec"]);
46
51
  var WRITE_TOOLS = new Set(["applypatch", "edit", "write"]);
47
52
  var guarded = (text) => {
48
53
  const flat = (s) => s.replaceAll("\\", "/").toLowerCase();
49
- const all = flat(text);
50
- return /issued|workspaces\.json|\.config\/workit/.test(all) || [stateDir, configDir].some((dir) => all.includes(flat(dir(process.env))));
54
+ return [flat(text), text.replace(/['"\\]/g, "").toLowerCase()].some((all) => /issued|approvals|workspaces\.json|\.config\/workit|state\/workit/.test(all) || [stateDir, configDir].some((dir) => all.includes(flat(dir(process.env)))));
51
55
  };
52
56
  var quietEvent = () => {
53
57
  try {
@@ -73,7 +77,19 @@ var quietEvent = () => {
73
77
  return null;
74
78
  if (event === "PostToolUse")
75
79
  return /\bcommit\b/.test(text) ? null : event;
76
- return /\b(?:git|gh|glab)\b/.test(text) || guarded(text) || maybeHeavy(text, value.cwd) ? null : event;
80
+ const writes = /[>]|\b(?:cp|mv|rm|rmdir|mkdir|tee|ln|install|rsync|touch|sed|perl|dd|curl|wget|tar|unzip|truncate|patch|chmod|chown|chgrp|chattr|find|xargs|unlink|g?awk|shred|mkfifo)\b/.test(text) && (/(?:^|[\s=<>|;&("'])(?:~|\/|\$|\.\.)[^\s'"]*[*?[]|\$\{?(?:WORKIT_|XDG_|APPDATA|HOME)/.test(text) || text.split(/[\s;&|()<>`'"]+/).some((word) => {
81
+ const file = path.resolve(String(value.cwd), word);
82
+ try {
83
+ const stat = statSync(file, { throwIfNoEntry: false });
84
+ if (stat?.isFile() && stat.nlink > 1)
85
+ return true;
86
+ const real = stat ? realpathSync(file) : path.join(realpathSync(path.dirname(file)), path.basename(file));
87
+ return real !== file && guarded(real);
88
+ } catch {
89
+ return false;
90
+ }
91
+ }));
92
+ return /\b(?:git|gh|glab|node|tsx|ts-node|bash|sh|zsh|dash|ksh|ruby|perl|php|source)\b|(?:^|[;&|(\n])\s*(?:\w+=\S*\s+)*(?:(?:time|exec|sudo|nice|nohup|env|command|builtin|timeout|stdbuf|if|then|do|while|until|!)\s+(?:-\S+\s+|\d\S*\s+)*)*(?:\.\s+\S|\.{0,2}\/)/.test(text) || guarded(text) || namesYtrack(text) || writes || maybeHeavy(text, value.cwd) ? null : event;
77
93
  } catch {
78
94
  return null;
79
95
  }
@@ -86,7 +102,7 @@ if (quiet) {
86
102
  `);
87
103
  } else {
88
104
  try {
89
- const { runCodexHook } = await import("./workit-hook-31tr5j4k.js");
105
+ const { runCodexHook } = await import("./workit-hook-ct8jhghw.js");
90
106
  await runCodexHook([payload]);
91
107
  } catch (error) {
92
108
  const { answerRuntimeFailure } = await import("./workit-hook-9k8dtngs.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/codex",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "private": false,
5
5
  "description": "Workit Codex CLI/desktop plugin — shared MCP transport, hooks, method skills, and verifier/reviewer/implementer agents",
6
6
  "keywords": [
@@ -41,8 +41,8 @@
41
41
  "build": "bun scripts/build.ts"
42
42
  },
43
43
  "devDependencies": {
44
- "@workit-dev/core": "^1.8.1",
45
- "@workit-dev/mcp": "^1.8.1"
44
+ "@workit-dev/core": "^1.9.0",
45
+ "@workit-dev/mcp": "^1.9.0"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=24"