@workit-dev/codex 2.27.8 → 2.27.9

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": "2.27.8",
3
+ "version": "2.27.9",
4
4
  "description": "Adaptive engineering workflow rails for Codex",
5
5
  "author": {
6
6
  "name": "BrainerVirus"
@@ -16144,12 +16144,6 @@ var applyPatterns = (value) => {
16144
16144
  };
16145
16145
  var redactSecrets = (value) => applyPatterns(value);
16146
16146
 
16147
- // packages/workit-core/src/store/paths.ts
16148
- import { spawnSync as spawnSync9 } from "node:child_process";
16149
- import { createHash as createHash6 } from "node:crypto";
16150
- import fs6 from "node:fs";
16151
- import path10 from "node:path";
16152
-
16153
16147
  // packages/workit-core/src/store/folder-store.ts
16154
16148
  import fs5 from "node:fs";
16155
16149
  import os5 from "node:os";
@@ -16366,13 +16360,14 @@ var below = (parent, child) => {
16366
16360
  const rel = path9.relative(parent, child);
16367
16361
  return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
16368
16362
  };
16363
+ var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical3(tempDir), canonical3(dir));
16369
16364
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
16370
16365
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
16371
16366
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
16372
16367
  return null;
16373
16368
  const real = canonical3(folder);
16374
16369
  const tmp = canonical3(tempDir);
16375
- if (below(tmp, real))
16370
+ if (insideTempDir(folder, tempDir))
16376
16371
  return null;
16377
16372
  return `workit test run (WORKIT_TEST_RUN): refusing to move ${path9.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
16378
16373
  };
@@ -16458,6 +16453,10 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
16458
16453
  }
16459
16454
 
16460
16455
  // packages/workit-core/src/store/paths.ts
16456
+ import { spawnSync as spawnSync9 } from "node:child_process";
16457
+ import { createHash as createHash6 } from "node:crypto";
16458
+ import fs6 from "node:fs";
16459
+ import path10 from "node:path";
16461
16460
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
16462
16461
  var gitRun = (cwd, args) => {
16463
16462
  const run = spawnSync9("git", args, {
@@ -16768,8 +16767,40 @@ function hostSessionFromEnv(env) {
16768
16767
  return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
16769
16768
  }
16770
16769
  var hash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 32);
16771
- var userIssuedRoot = () => path11.join(resolveStateDir(), "issued");
16772
- var userTokenRoot = () => path11.join(resolveStateDir(), "issued-tokens");
16770
+ var PIN_FILE = "issued-registry";
16771
+ var pinFiles = new Map;
16772
+ var pinFile = (cwd) => {
16773
+ if (cwd === undefined)
16774
+ return null;
16775
+ const key = path11.resolve(cwd);
16776
+ const known = pinFiles.get(key);
16777
+ if (known !== undefined)
16778
+ return known;
16779
+ try {
16780
+ const location = resolveStore(key);
16781
+ if (location instanceof Error)
16782
+ return null;
16783
+ const file = location.shared ? path11.join(location.dir, "ledger", PIN_FILE) : null;
16784
+ pinFiles.set(key, file);
16785
+ return file;
16786
+ } catch {
16787
+ return null;
16788
+ }
16789
+ };
16790
+ var pinnedStateDir = (cwd) => {
16791
+ const file = pinFile(cwd);
16792
+ if (file === null)
16793
+ return null;
16794
+ try {
16795
+ const pinned = fs7.readFileSync(file, "utf8").trim();
16796
+ return path11.isAbsolute(pinned) ? pinned : null;
16797
+ } catch {
16798
+ return null;
16799
+ }
16800
+ };
16801
+ var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
16802
+ var userIssuedRoot = (cwd) => path11.join(registryDir(cwd), "issued");
16803
+ var userTokenRoot = (cwd) => path11.join(registryDir(cwd), "issued-tokens");
16773
16804
  function migrateRepoIssued(cwd) {
16774
16805
  if (cwd === undefined)
16775
16806
  return;
@@ -16789,7 +16820,7 @@ function migrateRepoIssued(cwd) {
16789
16820
  const from = path11.join(old, lead);
16790
16821
  if (!fs7.statSync(from).isDirectory())
16791
16822
  continue;
16792
- const to = path11.join(userIssuedRoot(), lead);
16823
+ const to = path11.join(userIssuedRoot(cwd), lead);
16793
16824
  fs7.mkdirSync(to, { recursive: true, mode: 448 });
16794
16825
  for (const id of fs7.readdirSync(from)) {
16795
16826
  try {
@@ -16823,17 +16854,17 @@ var issuedRecord = (cwd, claimed) => {
16823
16854
  return null;
16824
16855
  migrateRepoIssued(cwd);
16825
16856
  try {
16826
- return fs7.readFileSync(path11.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
16857
+ return fs7.readFileSync(path11.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
16827
16858
  } catch {
16828
16859
  return null;
16829
16860
  }
16830
16861
  };
16831
16862
  var TOKEN_HASH = /^([0-9a-f]{64})$/mu;
16832
- var issuedToken = (claimed) => {
16863
+ var issuedToken = (cwd, claimed) => {
16833
16864
  const cut = claimed.lastIndexOf(":");
16834
16865
  if (cut <= 0)
16835
16866
  return { stored: null, leadBound: false };
16836
- const dir = path11.join(userTokenRoot(), hash(claimed.slice(0, cut)));
16867
+ const dir = path11.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
16837
16868
  try {
16838
16869
  const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
16839
16870
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
@@ -16843,7 +16874,7 @@ var issuedToken = (claimed) => {
16843
16874
  };
16844
16875
  function issuedBinding(cwd, claimed) {
16845
16876
  const record = issuedRecord(cwd, claimed);
16846
- const { stored, leadBound } = issuedToken(claimed);
16877
+ const { stored, leadBound } = issuedToken(cwd, claimed);
16847
16878
  if (stored)
16848
16879
  return "token";
16849
16880
  if (record === null)
@@ -33125,12 +33156,32 @@ var READERS2 = new Set(("cat less more head tail ls dir stat file wc grep egrep
33125
33156
 
33126
33157
  // packages/workit-core/src/hooks/identity-env.ts
33127
33158
  var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
33128
- var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
33129
33159
  var IDENTITY = new RegExp(`^${NAMES}$`, "u");
33160
+ var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
33130
33161
  var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
33131
- var powershell = (names) => new RegExp(`\\$env:${names}\\b|env:[\\\\/]?${names}\\b|EnvironmentVariable\\(\\s*['"]${names}\\b`, "iu");
33162
+ var IDENTITY_ANY = new RegExp(NAMES, "iu");
33163
+ var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
33164
+ var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
33165
+ var STATE_ANY = new RegExp(STATE_NAMES, "iu");
33166
+ var powershell = (names) => new RegExp([
33167
+ `\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
33168
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
33169
+ `SetEnvironmentVariable\\(\\s*['"]${names}\\b`
33170
+ ].join("|"), "iu");
33171
+ var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
33132
33172
  var POWERSHELL = powershell(NAMES);
33173
+ var POWERSHELL_STATE = powershell(STATE_NAMES);
33133
33174
  var POWERSHELL_HOST = powershell(HOST_NAMES);
33175
+ var POWERSHELL_OPAQUE = new RegExp([
33176
+ `SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
33177
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
33178
+ `(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
33179
+ `\\b(?:iex|Invoke-Expression)\\b`
33180
+ ].join("|"), "iu");
33181
+ var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
33182
+ var CMD_IDENTITY = cmdSet(NAMES);
33183
+ var CMD_STATE = cmdSet(STATE_NAMES);
33184
+ var CMD_HOST = cmdSet(HOST_NAMES);
33134
33185
  var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
33135
33186
  var OPAQUE = new Set([
33136
33187
  "watch",
@@ -6273,13 +6273,14 @@ var below = (parent, child) => {
6273
6273
  const rel = path8.relative(parent, child);
6274
6274
  return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
6275
6275
  };
6276
+ var insideTempDir = (dir, tempDir = os4.tmpdir()) => below(canonical2(tempDir), canonical2(dir));
6276
6277
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
6277
6278
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
6278
6279
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
6279
6280
  return null;
6280
6281
  const real = canonical2(folder);
6281
6282
  const tmp = canonical2(tempDir);
6282
- if (below(tmp, real))
6283
+ if (insideTempDir(folder, tempDir))
6283
6284
  return null;
6284
6285
  return `workit test run (WORKIT_TEST_RUN): refusing to move ${path8.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
6285
6286
  };
@@ -10840,8 +10841,58 @@ var STAMPING_HOSTS = new Set([
10840
10841
  var ISSUED_PER_LEAD = 64;
10841
10842
  var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
10842
10843
  var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
10843
- var userIssuedRoot = () => path16.join(resolveStateDir(), "issued");
10844
- var userTokenRoot = () => path16.join(resolveStateDir(), "issued-tokens");
10844
+ var PIN_FILE = "issued-registry";
10845
+ var pinFiles = new Map;
10846
+ var pinFile = (cwd) => {
10847
+ if (cwd === undefined)
10848
+ return null;
10849
+ const key = path16.resolve(cwd);
10850
+ const known = pinFiles.get(key);
10851
+ if (known !== undefined)
10852
+ return known;
10853
+ try {
10854
+ const location = resolveStore(key);
10855
+ if (location instanceof Error)
10856
+ return null;
10857
+ const file = location.shared ? path16.join(location.dir, "ledger", PIN_FILE) : null;
10858
+ pinFiles.set(key, file);
10859
+ return file;
10860
+ } catch {
10861
+ return null;
10862
+ }
10863
+ };
10864
+ var pinnedStateDir = (cwd) => {
10865
+ const file = pinFile(cwd);
10866
+ if (file === null)
10867
+ return null;
10868
+ try {
10869
+ const pinned = fs12.readFileSync(file, "utf8").trim();
10870
+ return path16.isAbsolute(pinned) ? pinned : null;
10871
+ } catch {
10872
+ return null;
10873
+ }
10874
+ };
10875
+ var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
10876
+ var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path16.dirname(path16.dirname(path16.dirname(file))));
10877
+ function pinIssuedRegistry(cwd) {
10878
+ const file = pinFile(cwd);
10879
+ if (file === null)
10880
+ return;
10881
+ const state = path16.resolve(resolveStateDir());
10882
+ if (pinnedStateDir(cwd) === state)
10883
+ return;
10884
+ if (testRunSkipsPin(file))
10885
+ return;
10886
+ try {
10887
+ fs12.mkdirSync(path16.dirname(file), { recursive: true });
10888
+ const temp = `${file}.${process.pid}.tmp`;
10889
+ fs12.writeFileSync(temp, `${state}
10890
+ `, { mode: 420 });
10891
+ fs12.renameSync(temp, file);
10892
+ } catch {}
10893
+ }
10894
+ var userIssuedRoot = (cwd) => path16.join(registryDir(cwd), "issued");
10895
+ var userTokenRoot = (cwd) => path16.join(registryDir(cwd), "issued-tokens");
10845
10896
  function migrateRepoIssued(cwd) {
10846
10897
  if (cwd === undefined)
10847
10898
  return;
@@ -10861,7 +10912,7 @@ function migrateRepoIssued(cwd) {
10861
10912
  const from = path16.join(old, lead);
10862
10913
  if (!fs12.statSync(from).isDirectory())
10863
10914
  continue;
10864
- const to = path16.join(userIssuedRoot(), lead);
10915
+ const to = path16.join(userIssuedRoot(cwd), lead);
10865
10916
  fs12.mkdirSync(to, { recursive: true, mode: 448 });
10866
10917
  for (const id of fs12.readdirSync(from)) {
10867
10918
  try {
@@ -10893,13 +10944,15 @@ var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
10893
10944
  function recordIssuedSession(cwd, lead, issued) {
10894
10945
  const token = randomBytes2(18).toString("hex");
10895
10946
  try {
10947
+ pinIssuedRegistry(cwd);
10896
10948
  migrateRepoIssued(cwd);
10897
10949
  const own = hash(issued);
10898
- const tokens = path16.join(userTokenRoot(), hash(lead));
10950
+ const state = resolveStateDir();
10951
+ const tokens = path16.join(state, "issued-tokens", hash(lead));
10899
10952
  fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
10900
10953
  fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
10901
10954
  `, { mode: 384, flag: "wx" });
10902
- const dir = path16.join(userIssuedRoot(), hash(lead));
10955
+ const dir = path16.join(state, "issued", hash(lead));
10903
10956
  fs12.mkdirSync(dir, { recursive: true, mode: 448 });
10904
10957
  fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
10905
10958
  `, { mode: 384 });
@@ -10944,17 +10997,17 @@ var issuedRecord = (cwd, claimed) => {
10944
10997
  return null;
10945
10998
  migrateRepoIssued(cwd);
10946
10999
  try {
10947
- return fs12.readFileSync(path16.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
11000
+ return fs12.readFileSync(path16.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
10948
11001
  } catch {
10949
11002
  return null;
10950
11003
  }
10951
11004
  };
10952
11005
  var TOKEN_HASH = /^([0-9a-f]{64})$/mu;
10953
- var issuedToken = (claimed) => {
11006
+ var issuedToken = (cwd, claimed) => {
10954
11007
  const cut = claimed.lastIndexOf(":");
10955
11008
  if (cut <= 0)
10956
11009
  return { stored: null, leadBound: false };
10957
- const dir = path16.join(userTokenRoot(), hash(claimed.slice(0, cut)));
11010
+ const dir = path16.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
10958
11011
  try {
10959
11012
  const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
10960
11013
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
@@ -10964,7 +11017,7 @@ var issuedToken = (claimed) => {
10964
11017
  };
10965
11018
  function issuedBinding(cwd, claimed) {
10966
11019
  const record = issuedRecord(cwd, claimed);
10967
- const { stored, leadBound } = issuedToken(claimed);
11020
+ const { stored, leadBound } = issuedToken(cwd, claimed);
10968
11021
  if (stored)
10969
11022
  return "token";
10970
11023
  if (record === null)
@@ -24159,13 +24212,36 @@ var hookEntryRun = (cwd, command, dialect = "posix") => {
24159
24212
  var hookEntryDeny = (entry) => `workit hook guard: this command runs Workit's hook entry ${entry}. Only the host runs Workit's hooks, with the payload it builds; a payload written in a shell would act as a session, subagent or agent that never existed. Use the workit CLI for what you need (\`workit doctor\` probes the installed hooks).`;
24160
24213
 
24161
24214
  // packages/workit-core/src/hooks/identity-env.ts
24215
+ import fs27 from "node:fs";
24216
+ import path42 from "node:path";
24162
24217
  var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
24163
- var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
24164
24218
  var IDENTITY = new RegExp(`^${NAMES}$`, "u");
24219
+ var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
24165
24220
  var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
24166
- var powershell = (names) => new RegExp(`\\$env:${names}\\b|env:[\\\\/]?${names}\\b|EnvironmentVariable\\(\\s*['"]${names}\\b`, "iu");
24221
+ var IDENTITY_ANY = new RegExp(NAMES, "iu");
24222
+ var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
24223
+ var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
24224
+ var STATE_ANY = new RegExp(STATE_NAMES, "iu");
24225
+ var powershell = (names) => new RegExp([
24226
+ `\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
24227
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
24228
+ `SetEnvironmentVariable\\(\\s*['"]${names}\\b`
24229
+ ].join("|"), "iu");
24230
+ var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
24167
24231
  var POWERSHELL = powershell(NAMES);
24232
+ var POWERSHELL_STATE = powershell(STATE_NAMES);
24168
24233
  var POWERSHELL_HOST = powershell(HOST_NAMES);
24234
+ var POWERSHELL_OPAQUE = new RegExp([
24235
+ `SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
24236
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
24237
+ `(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
24238
+ `\\b(?:iex|Invoke-Expression)\\b`
24239
+ ].join("|"), "iu");
24240
+ var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
24241
+ var CMD_IDENTITY = cmdSet(NAMES);
24242
+ var CMD_STATE = cmdSet(STATE_NAMES);
24243
+ var CMD_HOST = cmdSet(HOST_NAMES);
24244
+ var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
24169
24245
  var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
24170
24246
  var OPAQUE = new Set([
24171
24247
  "watch",
@@ -24183,22 +24259,41 @@ var ENV_FLAGS = new Set(["i", "0", "v"]);
24183
24259
  var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
24184
24260
  var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
24185
24261
  var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
24186
- var nameOf = (word) => word?.split("=")[0] ?? "";
24187
- var named = (word) => IDENTITY.test(nameOf(word)) || HOST_VARIABLE.test(nameOf(word));
24188
- var isWorkit = (word) => /^workit(?:-cli)?$/u.test(base2(word));
24262
+ var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
24263
+ var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
24264
+ var named = (word) => IDENTITY.test(nameOf(word));
24265
+ var stateNamed = (word) => STATE2.test(nameOf(word));
24266
+ var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
24267
+ var linksToWorkit = (word, cwd) => {
24268
+ const places = /[\\/]/u.test(word) ? [path42.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path42.delimiter).map((dir) => path42.join(dir, word));
24269
+ for (const place of places) {
24270
+ try {
24271
+ const real = fs27.realpathSync(place);
24272
+ return isWorkit(real);
24273
+ } catch {}
24274
+ }
24275
+ return false;
24276
+ };
24277
+ var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
24189
24278
  var UNREADABLE = "env/unset arguments Workit cannot read";
24190
- var mark = (scan, word) => {
24191
- const name = nameOf(word);
24192
- if (IDENTITY.test(name))
24193
- scan.hit ??= name;
24194
- else if (HOST_VARIABLE.test(name))
24195
- scan.hostHit ??= name;
24196
- };
24197
- var scanEnv = (words, at, expands, scan, depth) => {
24279
+ var note = (scan, seg, word) => {
24280
+ if (scan.identity && named(word)) {
24281
+ if (seg)
24282
+ seg.identity ??= nameOf(word);
24283
+ else
24284
+ scan.hit ??= nameOf(word);
24285
+ }
24286
+ if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
24287
+ return;
24288
+ if (seg)
24289
+ seg.scoped ??= nameOf(word);
24290
+ else
24291
+ scan.shell ??= nameOf(word);
24292
+ };
24293
+ var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
24294
+ var scanEnv = (words, at, expands, scan, seg, depth) => {
24198
24295
  const risky = (what) => void (scan.risky ??= what);
24199
- const unset = (name) => {
24200
- mark(scan, name);
24201
- };
24296
+ const unset = (name) => note(scan, seg, name);
24202
24297
  const split = (line, rest, built) => {
24203
24298
  if (line === undefined || depth >= 4)
24204
24299
  return risky(UNREADABLE);
@@ -24215,7 +24310,7 @@ var scanEnv = (words, at, expands, scan, depth) => {
24215
24310
  } catch {
24216
24311
  return risky(UNREADABLE);
24217
24312
  }
24218
- scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, depth + 1);
24313
+ scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
24219
24314
  };
24220
24315
  let options = true;
24221
24316
  for (let index = at;index < words.length; index += 1) {
@@ -24273,25 +24368,25 @@ var scanEnv = (words, at, expands, scan, depth) => {
24273
24368
  }
24274
24369
  continue;
24275
24370
  }
24276
- if (/^[A-Za-z_]\w*=/u.test(word)) {
24371
+ if (ASSIGN.test(word)) {
24277
24372
  unset(word);
24278
24373
  continue;
24279
24374
  }
24280
- return commandAt(words.slice(index), scan);
24375
+ return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
24281
24376
  }
24282
24377
  };
24283
- var commandAt = (words, scan, expands = new Set, from = 0) => {
24378
+ var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
24284
24379
  let index = from;
24285
24380
  while (index < words.length) {
24286
- while (/^[A-Za-z_]\w*=/u.test(words[index] ?? "")) {
24287
- mark(scan, words[index]);
24381
+ while (ASSIGN.test(words[index] ?? "")) {
24382
+ note(scan, seg, words[index]);
24288
24383
  index += 1;
24289
24384
  }
24290
24385
  const name = base2(words[index]).toLowerCase();
24291
24386
  if (name === "env")
24292
- return scanEnv(words, index + 1, expands, scan, 0);
24387
+ return scanEnv(words, index + 1, expands, scan, seg, 0);
24293
24388
  if (OPAQUE.has(name))
24294
- return opaque(words.slice(index + 1), scan, true);
24389
+ return opaque(words.slice(index + 1), scan, seg, true);
24295
24390
  if (name === "busybox" || name === "toybox") {
24296
24391
  index += 1;
24297
24392
  continue;
@@ -24301,21 +24396,37 @@ var commandAt = (words, scan, expands = new Set, from = 0) => {
24301
24396
  break;
24302
24397
  index = pastOptions(words, index + 1, takes);
24303
24398
  }
24304
- if (isWorkit(words[index]))
24305
- scan.runs = true;
24306
- else if (words.slice(index + 1).some((word) => base2(word).toLowerCase() === "env"))
24307
- opaque(words.slice(index + 1), scan, false);
24308
- };
24309
- var opaque = (rest, scan, assigns) => {
24399
+ const word = words[index];
24400
+ if (word === undefined)
24401
+ return;
24402
+ seg.words.push({ word, built: expands.has(index) });
24403
+ const rest = words.slice(index + 1);
24404
+ if (isWorkit(word) || rest.some(isWorkit))
24405
+ seg.runs = true;
24406
+ if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
24407
+ opaque(rest, scan, seg, false);
24408
+ const program = base2(word).toLowerCase();
24409
+ const shell = program === "pwsh" || program === "powershell";
24410
+ if (program === "cmd" || shell) {
24411
+ const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
24412
+ if (at >= 0) {
24413
+ const script = rest.slice(at + 1).join(" ");
24414
+ const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
24415
+ if (change)
24416
+ scan.hit ??= change;
24417
+ }
24418
+ }
24419
+ };
24420
+ var opaque = (rest, scan, seg, assigns) => {
24310
24421
  if (!rest.some(isWorkit))
24311
24422
  return;
24312
- scan.runs = true;
24313
- const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && /^[A-Za-z_]\w*=/u.test(word);
24423
+ seg.runs = true;
24424
+ const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
24314
24425
  if (rest.some(changes))
24315
24426
  scan.risky ??= UNREADABLE;
24316
- const hit = rest.find(named);
24317
- if (hit && rest.some((word) => base2(word).toLowerCase() === "env"))
24318
- mark(scan, hit);
24427
+ if (rest.some((word) => base2(word).toLowerCase() === "env"))
24428
+ for (const word of rest)
24429
+ note(scan, seg, word);
24319
24430
  };
24320
24431
  var LOGIN_VALUED = {
24321
24432
  su: /[sgGwc]/u,
@@ -24350,38 +24461,83 @@ var scanCommand2 = (command, dialect, depth, scan) => {
24350
24461
  }
24351
24462
  for (const { words, expands = [] } of segments) {
24352
24463
  const expanded = new Set(expands);
24464
+ const seg = newSeg();
24353
24465
  let at = 0;
24354
- while (/^[A-Za-z_]\w*=/u.test(words[at] ?? "")) {
24355
- mark(scan, words[at]);
24466
+ while (ASSIGN.test(words[at] ?? ""))
24356
24467
  at += 1;
24357
- }
24468
+ for (const word of words.slice(0, at))
24469
+ note(scan, at === words.length ? null : seg, word);
24358
24470
  let declare = at;
24359
24471
  if (["builtin", "command"].includes(words[declare] ?? ""))
24360
24472
  declare += 1;
24361
24473
  if (DECLARES.has(words[declare] ?? "")) {
24362
24474
  for (let index = declare + 1;index < words.length; index += 1) {
24363
- mark(scan, words[index]);
24475
+ note(scan, null, words[index]);
24364
24476
  if (expanded.has(index))
24365
24477
  scan.risky ??= UNREADABLE;
24366
24478
  }
24367
24479
  continue;
24368
24480
  }
24369
- commandAt(words, scan, expanded, at);
24481
+ commandAt(words, scan, seg, expanded, at);
24370
24482
  const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
24371
- if (script)
24483
+ if (script) {
24484
+ const before = scan.runs;
24485
+ scan.runs = false;
24372
24486
  scanCommand2(script, dialect, depth + 1, scan);
24373
- }
24374
- };
24375
- var identityEnvChange = (command, dialect = "posix") => {
24376
- if (!/WORKIT_|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|\b(?:env|unset|export|declare|typeset|local|readonly)\b/u.test(command))
24487
+ seg.runs ||= scan.runs;
24488
+ scan.runs ||= before;
24489
+ }
24490
+ scan.words.push(...seg.words);
24491
+ const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
24492
+ if (seg.identity && reaches())
24493
+ scan.hit ??= seg.identity;
24494
+ if (seg.scoped && reaches())
24495
+ scan.state ??= seg.scoped;
24496
+ scan.runs ||= seg.runs;
24497
+ }
24498
+ };
24499
+ var cmdChange = (script, scan) => (scan.identity ? CMD_IDENTITY.exec(script)?.[1] : null) ?? (RUNS_TEXT.test(script) ? CMD_STATE.exec(script)?.[1] ?? (scan.identity ? CMD_HOST.exec(script)?.[1] : null) ?? null : null);
24500
+ var powershellChange = (command, identity) => {
24501
+ const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
24502
+ if (hit)
24503
+ return hit;
24504
+ if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
24377
24505
  return null;
24506
+ const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
24507
+ if (state)
24508
+ return state;
24509
+ return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
24510
+ };
24511
+ var identityEnvChange = (command, dialect = "posix", options = {}) => {
24512
+ const identity = options.identity ?? true;
24378
24513
  if (dialect === "powershell")
24379
- return POWERSHELL.exec(command)?.[0] ?? (/\bworkit\b/iu.test(command) ? POWERSHELL_HOST.exec(command)?.[0] ?? null : null);
24380
- const scan = { hit: null, hostHit: null, risky: null, runs: false };
24514
+ return powershellChange(command, identity);
24515
+ if (!/WORKIT_|XDG_|HOME|USERPROFILE|APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|EnvironmentVariable|\b(?:env|unset|export|declare|typeset|local|readonly)\b/iu.test(command))
24516
+ return null;
24517
+ const scan = {
24518
+ identity,
24519
+ cwd: options.cwd,
24520
+ hit: null,
24521
+ state: null,
24522
+ shell: null,
24523
+ risky: null,
24524
+ runs: false,
24525
+ words: []
24526
+ };
24381
24527
  scanCommand2(command, dialect, 0, scan);
24382
- return scan.hit ?? (scan.runs ? scan.hostHit ?? scan.risky : null);
24528
+ if (scan.hit)
24529
+ return scan.hit;
24530
+ if (scan.state)
24531
+ return scan.state;
24532
+ if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
24533
+ return scan.shell;
24534
+ return scan.runs ? scan.risky : null;
24535
+ };
24536
+ var identityEnvDeny = (change) => {
24537
+ if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
24538
+ return `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
24539
+ return `workit identity: this command runs workit with ${change} changed. Workit reads issued sessions, grants and its ledger trust from the state and config dirs the host's environment names, so a workit call may not move them (#980); run it without setting, unsetting or emptying ${change}.`;
24383
24540
  };
24384
- var identityEnvDeny = (change) => `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
24385
24541
 
24386
24542
  // packages/workit-core/src/hooks/handle.ts
24387
24543
  var usable2 = (value) => value === "native" || value === "partial";
@@ -24458,6 +24614,7 @@ function decide(input, deps) {
24458
24614
  switch (event.kind) {
24459
24615
  case "session.start": {
24460
24616
  reapAtStart(input.cwd);
24617
+ pinIssuedRegistry(input.cwd);
24461
24618
  if (!usable2(descriptor.context.sessionStart))
24462
24619
  return NONE6;
24463
24620
  const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
@@ -24581,7 +24738,10 @@ function decide(input, deps) {
24581
24738
  const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
24582
24739
  if (gate.kind === "deny")
24583
24740
  return gate;
24584
- const identity = canDeny && stampsAgents(descriptor) ? identityEnvChange(event.command, event.dialect) : null;
24741
+ const identity = canDeny ? identityEnvChange(event.command, event.dialect, {
24742
+ identity: stampsAgents(descriptor),
24743
+ cwd: input.cwd
24744
+ }) : null;
24585
24745
  if (identity)
24586
24746
  return { kind: "deny", reason: identityEnvDeny(identity), unblock: null };
24587
24747
  const plan = heavyGate(input.cwd, event.command, {
@@ -24724,7 +24884,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
24724
24884
  };
24725
24885
  // packages/workit-core/src/hooks/deadline.ts
24726
24886
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
24727
- import path42 from "node:path";
24887
+ import path43 from "node:path";
24728
24888
  var HOOK_SKIP_TEXT = "workit context skipped: host under load";
24729
24889
  var HOOK_DEADLINE_MS = 8000;
24730
24890
  var HOST_DEADLINES = {
@@ -24742,7 +24902,7 @@ var hookDeadlineMs = (env, host = "", native) => {
24742
24902
  const row = HOST_DEADLINES[host];
24743
24903
  return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
24744
24904
  };
24745
- var skipsFile = (stateDir) => path42.join(stateDir, HOOK_SKIPS_FILE);
24905
+ var skipsFile = (stateDir) => path43.join(stateDir, HOOK_SKIPS_FILE);
24746
24906
  var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
24747
24907
  try {
24748
24908
  mkdirSync4(stateDir, { recursive: true });
@@ -24794,7 +24954,7 @@ var readWithin = async (stdin, budget) => {
24794
24954
  const text = await within2(read, budget.startedAt + budget.deadlineMs - budget.now());
24795
24955
  return isTimedOut(text) ? null : text;
24796
24956
  };
24797
- var note = (adapter, raw, env, budget, outcome, stage) => {
24957
+ var note2 = (adapter, raw, env, budget, outcome, stage) => {
24798
24958
  const parsed = raw === undefined ? null : adapter.parse(raw, env);
24799
24959
  const event = parsed ? parsed.ok ? parsed.input.event.kind : parsed.event : null;
24800
24960
  budget.record({
@@ -24808,7 +24968,7 @@ var note = (adapter, raw, env, budget, outcome, stage) => {
24808
24968
  return { native: parsed?.native ?? null, event };
24809
24969
  };
24810
24970
  var skippedHook = (adapter, raw, env, budget, stage) => {
24811
- const { native, event } = note(adapter, raw, env, budget, "skip", stage);
24971
+ const { native, event } = note2(adapter, raw, env, budget, "skip", stage);
24812
24972
  return {
24813
24973
  ...adapter.render(skipDecision(event), native),
24814
24974
  error: `${HOOK_SKIP_TEXT} (past the ${budget.deadlineMs} ms hook deadline)`,
@@ -24824,7 +24984,7 @@ var dispatchWithin = async (adapter, raw, env, budget, dispatch = dispatchHook)
24824
24984
  if (isTimedOut(result))
24825
24985
  return skippedHook(adapter, raw, env, budget, "dispatch");
24826
24986
  if (remaining() < 0)
24827
- note(adapter, raw, env, budget, "late", "done");
24987
+ note2(adapter, raw, env, budget, "late", "done");
24828
24988
  return { ...result, skipped: false };
24829
24989
  };
24830
24990
 
@@ -102,7 +102,7 @@ if (quiet) {
102
102
  `);
103
103
  } else {
104
104
  try {
105
- const { runCodexHook } = await import("./workit-hook-jbtcvq84.js");
105
+ const { runCodexHook } = await import("./workit-hook-vrrn5d90.js");
106
106
  await runCodexHook([payload]);
107
107
  } catch (error) {
108
108
  const { answerRuntimeFailure } = await import("./workit-hook-2j7nwxvz.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/codex",
3
- "version": "2.27.8",
3
+ "version": "2.27.9",
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": "^2.27.8",
45
- "@workit-dev/mcp": "^2.27.8"
44
+ "@workit-dev/core": "^2.27.9",
45
+ "@workit-dev/mcp": "^2.27.9"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=24"