@workit-dev/codex 2.27.8 → 2.27.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.
package/dist/launch-mcp.js
CHANGED
|
@@ -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 (
|
|
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
|
|
16772
|
-
var
|
|
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)
|
|
@@ -32756,7 +32787,7 @@ var codexAdapter = {
|
|
|
32756
32787
|
};
|
|
32757
32788
|
},
|
|
32758
32789
|
render,
|
|
32759
|
-
addendum: (input) => `<workit-codex-mutations>Codex MCP is read-only: unattested callers cannot mutate. Run workit verbs with the workit CLI on the shell (node_modules/.bin/workit, or npx -y @workit-dev/cli): check, git branch|commit|push, pr, ci, stack, ledger, handoff; task-family mutations take --json${input.session.id ? ` --actor ${input.session.id}` : ""}. workit acts as this thread (CODEX_THREAD_ID${input.session.id ? `=${input.session.id}` : ""}) unless WORKIT_SESSION_ID is set. A verifier or reviewer records workit ledger verdict under its own session, never the author's: a
|
|
32790
|
+
addendum: (input) => `<workit-codex-mutations>Codex MCP is read-only: unattested callers cannot mutate. Run workit verbs with the workit CLI on the shell (node_modules/.bin/workit, or npx -y @workit-dev/cli): check, git branch|commit|push, pr, ci, stack, ledger, handoff; task-family mutations take --json${input.session.id ? ` --actor ${input.session.id}` : ""}. workit acts as this thread (CODEX_THREAD_ID${input.session.id ? `=${input.session.id}` : ""}) unless WORKIT_SESSION_ID is set. A verifier or reviewer records workit ledger verdict under its own session, never the author's: a Codex subagent's shell is its own thread (CODEX_THREAD_ID), so it passes no --session or --token; <lead>:<agent id> or a made-up <lead>-v1 is refused as forged_session. Merge and release need a workspace grant (workit grant show); a question answer is not host permission.</workit-codex-mutations>`
|
|
32760
32791
|
};
|
|
32761
32792
|
|
|
32762
32793
|
// packages/workit-core/src/hooks/hosts/cursor.ts
|
|
@@ -33075,6 +33106,10 @@ var gap = (part) => ({ workit: null, gap: part });
|
|
|
33075
33106
|
var READ = new Map;
|
|
33076
33107
|
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)");
|
|
33077
33108
|
|
|
33109
|
+
// packages/workit-core/src/hooks/stamp-hint.ts
|
|
33110
|
+
var STATE_NAME = "(?:WORKIT_(?:STATE_DIR|CONFIG)\\w*|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
33111
|
+
var STATE_ENV = new RegExp(`${STATE_NAME}\\s*\\+?=|(?:unset|-u|--unset)[\\s=]+${STATE_NAME}|env:|EnvironmentVariable`, "iu");
|
|
33112
|
+
|
|
33078
33113
|
// packages/workit-core/src/hooks/hook-entry.ts
|
|
33079
33114
|
var RUNNERS2 = new Set([
|
|
33080
33115
|
"node",
|
|
@@ -33125,12 +33160,32 @@ var READERS2 = new Set(("cat less more head tail ls dir stat file wc grep egrep
|
|
|
33125
33160
|
|
|
33126
33161
|
// packages/workit-core/src/hooks/identity-env.ts
|
|
33127
33162
|
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
33163
|
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
33164
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
33130
33165
|
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
33131
|
-
var
|
|
33166
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
33167
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
33168
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
33169
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
33170
|
+
var powershell = (names) => new RegExp([
|
|
33171
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
33172
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
33173
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
33174
|
+
].join("|"), "iu");
|
|
33175
|
+
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
33176
|
var POWERSHELL = powershell(NAMES);
|
|
33177
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
33133
33178
|
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
33179
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
33180
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
33181
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
33182
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
33183
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
33184
|
+
].join("|"), "iu");
|
|
33185
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
33186
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
33187
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
33188
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
33134
33189
|
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
33135
33190
|
var OPAQUE = new Set([
|
|
33136
33191
|
"watch",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
stateDir3
|
|
4
|
+
} from "./workit-hook-sxyjantk.js";
|
|
5
|
+
|
|
6
|
+
// packages/workit-core/src/hooks/stamp-hint.ts
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
var stampHash2 = (text) => createHash("sha256").update(text).digest("hex").slice(0, 32);
|
|
11
|
+
var stampDir2 = (env, session) => path.join(stateDir3(env), "agent-stamps", stampHash2(session));
|
|
12
|
+
var callTag2 = (toolUseId) => stampHash2(toolUseId).slice(0, 8);
|
|
13
|
+
var backgrounds2 = (command) => /(?:^|[^&<>])&(?![&>])/u.test(command);
|
|
14
|
+
var dropCallStamps2 = (env, session, toolUseId) => {
|
|
15
|
+
try {
|
|
16
|
+
const dir = stampDir2(env, session);
|
|
17
|
+
const tag = `.${callTag2(toolUseId)}-`;
|
|
18
|
+
for (const name of fs.readdirSync(dir))
|
|
19
|
+
if (name.includes(tag))
|
|
20
|
+
fs.rmSync(path.join(dir, name), { force: true });
|
|
21
|
+
} catch {}
|
|
22
|
+
};
|
|
23
|
+
var mayRunWorkit2 = (text) => /(?:^|[\s;&|(])(?:\S*[\\/])?workit(?:\s|$)/u.test(text);
|
|
24
|
+
var dropPostToolStamps2 = (env, payload) => {
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse(payload);
|
|
27
|
+
const command = value.tool_input?.command;
|
|
28
|
+
const text = Array.isArray(command) ? command.join(" ") : String(command ?? "");
|
|
29
|
+
const thread = typeof value.agent_id === "string" && value.agent_id.trim() ? value.agent_id : value.session_id;
|
|
30
|
+
if (value.hook_event_name === "PostToolUse" && typeof thread === "string" && thread && typeof value.tool_use_id === "string" && value.tool_use_id && mayRunWorkit2(text) && !backgrounds2(text))
|
|
31
|
+
dropCallStamps2(env, thread, value.tool_use_id);
|
|
32
|
+
} catch {}
|
|
33
|
+
};
|
|
34
|
+
var IDENTITY_ENV = /WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)|\benv\b[^\n;&|]*\s(?:-[a-z]*i|--ignore-environment|-)(?:\s|$)/u;
|
|
35
|
+
var STATE_NAME = "(?:WORKIT_(?:STATE_DIR|CONFIG)\\w*|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
36
|
+
var STATE_ENV = new RegExp(`${STATE_NAME}\\s*\\+?=|(?:unset|-u|--unset)[\\s=]+${STATE_NAME}|env:|EnvironmentVariable`, "iu");
|
|
37
|
+
var mayChangeIdentity2 = (text) => {
|
|
38
|
+
const bare = text.replace(/['"\\]/gu, "");
|
|
39
|
+
return IDENTITY_ENV.test(bare) || STATE_ENV.test(bare);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { stampHash2, stampDir2, callTag2, backgrounds2, dropCallStamps2, mayRunWorkit2, dropPostToolStamps2, mayChangeIdentity2 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
stampHash2,
|
|
4
|
+
stampDir2,
|
|
5
|
+
callTag2,
|
|
6
|
+
backgrounds2,
|
|
7
|
+
dropCallStamps2,
|
|
8
|
+
mayRunWorkit2,
|
|
9
|
+
dropPostToolStamps2,
|
|
10
|
+
mayChangeIdentity2
|
|
11
|
+
} from "./workit-hook-28rqjzbb.js";
|
|
12
|
+
import"./workit-hook-sxyjantk.js";
|
|
13
|
+
export {
|
|
14
|
+
backgrounds2 as backgrounds,
|
|
15
|
+
callTag2 as callTag,
|
|
16
|
+
dropCallStamps2 as dropCallStamps,
|
|
17
|
+
dropPostToolStamps2 as dropPostToolStamps,
|
|
18
|
+
mayChangeIdentity2 as mayChangeIdentity,
|
|
19
|
+
mayRunWorkit2 as mayRunWorkit,
|
|
20
|
+
stampDir2 as stampDir,
|
|
21
|
+
stampHash2 as stampHash
|
|
22
|
+
};
|
|
@@ -33,6 +33,13 @@ import {
|
|
|
33
33
|
import {
|
|
34
34
|
locateWorkitCli2
|
|
35
35
|
} from "./workit-hook-agyvx03a.js";
|
|
36
|
+
import {
|
|
37
|
+
stampHash2,
|
|
38
|
+
stampDir2,
|
|
39
|
+
callTag2,
|
|
40
|
+
backgrounds2,
|
|
41
|
+
dropCallStamps2
|
|
42
|
+
} from "./workit-hook-28rqjzbb.js";
|
|
36
43
|
import {
|
|
37
44
|
recordHookRun2
|
|
38
45
|
} from "./workit-hook-p972vv1e.js";
|
|
@@ -6273,13 +6280,14 @@ var below = (parent, child) => {
|
|
|
6273
6280
|
const rel = path8.relative(parent, child);
|
|
6274
6281
|
return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
|
|
6275
6282
|
};
|
|
6283
|
+
var insideTempDir = (dir, tempDir = os4.tmpdir()) => below(canonical2(tempDir), canonical2(dir));
|
|
6276
6284
|
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
6277
6285
|
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
|
|
6278
6286
|
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
6279
6287
|
return null;
|
|
6280
6288
|
const real = canonical2(folder);
|
|
6281
6289
|
const tmp = canonical2(tempDir);
|
|
6282
|
-
if (
|
|
6290
|
+
if (insideTempDir(folder, tempDir))
|
|
6283
6291
|
return null;
|
|
6284
6292
|
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
6293
|
};
|
|
@@ -10840,8 +10848,58 @@ var STAMPING_HOSTS = new Set([
|
|
|
10840
10848
|
var ISSUED_PER_LEAD = 64;
|
|
10841
10849
|
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
|
|
10842
10850
|
var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
|
|
10843
|
-
var
|
|
10844
|
-
var
|
|
10851
|
+
var PIN_FILE = "issued-registry";
|
|
10852
|
+
var pinFiles = new Map;
|
|
10853
|
+
var pinFile = (cwd) => {
|
|
10854
|
+
if (cwd === undefined)
|
|
10855
|
+
return null;
|
|
10856
|
+
const key = path16.resolve(cwd);
|
|
10857
|
+
const known = pinFiles.get(key);
|
|
10858
|
+
if (known !== undefined)
|
|
10859
|
+
return known;
|
|
10860
|
+
try {
|
|
10861
|
+
const location = resolveStore(key);
|
|
10862
|
+
if (location instanceof Error)
|
|
10863
|
+
return null;
|
|
10864
|
+
const file = location.shared ? path16.join(location.dir, "ledger", PIN_FILE) : null;
|
|
10865
|
+
pinFiles.set(key, file);
|
|
10866
|
+
return file;
|
|
10867
|
+
} catch {
|
|
10868
|
+
return null;
|
|
10869
|
+
}
|
|
10870
|
+
};
|
|
10871
|
+
var pinnedStateDir = (cwd) => {
|
|
10872
|
+
const file = pinFile(cwd);
|
|
10873
|
+
if (file === null)
|
|
10874
|
+
return null;
|
|
10875
|
+
try {
|
|
10876
|
+
const pinned = fs12.readFileSync(file, "utf8").trim();
|
|
10877
|
+
return path16.isAbsolute(pinned) ? pinned : null;
|
|
10878
|
+
} catch {
|
|
10879
|
+
return null;
|
|
10880
|
+
}
|
|
10881
|
+
};
|
|
10882
|
+
var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
|
|
10883
|
+
var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path16.dirname(path16.dirname(path16.dirname(file))));
|
|
10884
|
+
function pinIssuedRegistry(cwd) {
|
|
10885
|
+
const file = pinFile(cwd);
|
|
10886
|
+
if (file === null)
|
|
10887
|
+
return;
|
|
10888
|
+
const state = path16.resolve(resolveStateDir());
|
|
10889
|
+
if (pinnedStateDir(cwd) === state)
|
|
10890
|
+
return;
|
|
10891
|
+
if (testRunSkipsPin(file))
|
|
10892
|
+
return;
|
|
10893
|
+
try {
|
|
10894
|
+
fs12.mkdirSync(path16.dirname(file), { recursive: true });
|
|
10895
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
10896
|
+
fs12.writeFileSync(temp, `${state}
|
|
10897
|
+
`, { mode: 420 });
|
|
10898
|
+
fs12.renameSync(temp, file);
|
|
10899
|
+
} catch {}
|
|
10900
|
+
}
|
|
10901
|
+
var userIssuedRoot = (cwd) => path16.join(registryDir(cwd), "issued");
|
|
10902
|
+
var userTokenRoot = (cwd) => path16.join(registryDir(cwd), "issued-tokens");
|
|
10845
10903
|
function migrateRepoIssued(cwd) {
|
|
10846
10904
|
if (cwd === undefined)
|
|
10847
10905
|
return;
|
|
@@ -10861,7 +10919,7 @@ function migrateRepoIssued(cwd) {
|
|
|
10861
10919
|
const from = path16.join(old, lead);
|
|
10862
10920
|
if (!fs12.statSync(from).isDirectory())
|
|
10863
10921
|
continue;
|
|
10864
|
-
const to = path16.join(userIssuedRoot(), lead);
|
|
10922
|
+
const to = path16.join(userIssuedRoot(cwd), lead);
|
|
10865
10923
|
fs12.mkdirSync(to, { recursive: true, mode: 448 });
|
|
10866
10924
|
for (const id of fs12.readdirSync(from)) {
|
|
10867
10925
|
try {
|
|
@@ -10893,13 +10951,15 @@ var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
|
|
|
10893
10951
|
function recordIssuedSession(cwd, lead, issued) {
|
|
10894
10952
|
const token = randomBytes2(18).toString("hex");
|
|
10895
10953
|
try {
|
|
10954
|
+
pinIssuedRegistry(cwd);
|
|
10896
10955
|
migrateRepoIssued(cwd);
|
|
10897
10956
|
const own = hash(issued);
|
|
10898
|
-
const
|
|
10957
|
+
const state = resolveStateDir();
|
|
10958
|
+
const tokens = path16.join(state, "issued-tokens", hash(lead));
|
|
10899
10959
|
fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
|
|
10900
10960
|
fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
|
|
10901
10961
|
`, { mode: 384, flag: "wx" });
|
|
10902
|
-
const dir = path16.join(
|
|
10962
|
+
const dir = path16.join(state, "issued", hash(lead));
|
|
10903
10963
|
fs12.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
10904
10964
|
fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
|
|
10905
10965
|
`, { mode: 384 });
|
|
@@ -10944,17 +11004,17 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
10944
11004
|
return null;
|
|
10945
11005
|
migrateRepoIssued(cwd);
|
|
10946
11006
|
try {
|
|
10947
|
-
return fs12.readFileSync(path16.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
11007
|
+
return fs12.readFileSync(path16.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
10948
11008
|
} catch {
|
|
10949
11009
|
return null;
|
|
10950
11010
|
}
|
|
10951
11011
|
};
|
|
10952
11012
|
var TOKEN_HASH = /^([0-9a-f]{64})$/mu;
|
|
10953
|
-
var issuedToken = (claimed) => {
|
|
11013
|
+
var issuedToken = (cwd, claimed) => {
|
|
10954
11014
|
const cut = claimed.lastIndexOf(":");
|
|
10955
11015
|
if (cut <= 0)
|
|
10956
11016
|
return { stored: null, leadBound: false };
|
|
10957
|
-
const dir = path16.join(userTokenRoot(), hash(claimed.slice(0, cut)));
|
|
11017
|
+
const dir = path16.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
|
|
10958
11018
|
try {
|
|
10959
11019
|
const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
|
|
10960
11020
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
@@ -10964,7 +11024,7 @@ var issuedToken = (claimed) => {
|
|
|
10964
11024
|
};
|
|
10965
11025
|
function issuedBinding(cwd, claimed) {
|
|
10966
11026
|
const record = issuedRecord(cwd, claimed);
|
|
10967
|
-
const { stored, leadBound } = issuedToken(claimed);
|
|
11027
|
+
const { stored, leadBound } = issuedToken(cwd, claimed);
|
|
10968
11028
|
if (stored)
|
|
10969
11029
|
return "token";
|
|
10970
11030
|
if (record === null)
|
|
@@ -21100,7 +21160,7 @@ var codexAdapter = {
|
|
|
21100
21160
|
};
|
|
21101
21161
|
},
|
|
21102
21162
|
render,
|
|
21103
|
-
addendum: (input) => `<workit-codex-mutations>Codex MCP is read-only: unattested callers cannot mutate. Run workit verbs with the workit CLI on the shell (node_modules/.bin/workit, or npx -y @workit-dev/cli): check, git branch|commit|push, pr, ci, stack, ledger, handoff; task-family mutations take --json${input.session.id ? ` --actor ${input.session.id}` : ""}. workit acts as this thread (CODEX_THREAD_ID${input.session.id ? `=${input.session.id}` : ""}) unless WORKIT_SESSION_ID is set. A verifier or reviewer records workit ledger verdict under its own session, never the author's: a
|
|
21163
|
+
addendum: (input) => `<workit-codex-mutations>Codex MCP is read-only: unattested callers cannot mutate. Run workit verbs with the workit CLI on the shell (node_modules/.bin/workit, or npx -y @workit-dev/cli): check, git branch|commit|push, pr, ci, stack, ledger, handoff; task-family mutations take --json${input.session.id ? ` --actor ${input.session.id}` : ""}. workit acts as this thread (CODEX_THREAD_ID${input.session.id ? `=${input.session.id}` : ""}) unless WORKIT_SESSION_ID is set. A verifier or reviewer records workit ledger verdict under its own session, never the author's: a Codex subagent's shell is its own thread (CODEX_THREAD_ID), so it passes no --session or --token; <lead>:<agent id> or a made-up <lead>-v1 is refused as forged_session. Merge and release need a workspace grant (workit grant show); a question answer is not host permission.</workit-codex-mutations>`
|
|
21104
21164
|
};
|
|
21105
21165
|
|
|
21106
21166
|
// packages/workit-core/src/hooks/hosts/cursor.ts
|
|
@@ -23671,13 +23731,11 @@ Retry as: ${retry}`,
|
|
|
23671
23731
|
}
|
|
23672
23732
|
|
|
23673
23733
|
// packages/workit-core/src/agent-stamp.ts
|
|
23674
|
-
import {
|
|
23734
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
23675
23735
|
import fs26 from "node:fs";
|
|
23676
23736
|
import path40 from "node:path";
|
|
23677
23737
|
var STAMP_TTL_MS = 120000;
|
|
23678
23738
|
var AGENT_ID = /^[\w-]{1,64}$/u;
|
|
23679
|
-
var hash2 = (text) => createHash17("sha256").update(text).digest("hex").slice(0, 32);
|
|
23680
|
-
var stampDir = (env, session) => path40.join(stateDir3(env), "agent-stamps", hash2(session));
|
|
23681
23739
|
var workitCalls2 = (command, dialect = "posix") => {
|
|
23682
23740
|
const calls = [];
|
|
23683
23741
|
try {
|
|
@@ -23696,28 +23754,20 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
|
|
|
23696
23754
|
const calls = workitCalls2(command, options.dialect);
|
|
23697
23755
|
if (!calls.length)
|
|
23698
23756
|
return;
|
|
23699
|
-
const call = options.toolUseId ?
|
|
23757
|
+
const call = options.toolUseId ? callTag2(options.toolUseId) : randomBytes4(4).toString("hex");
|
|
23700
23758
|
try {
|
|
23701
|
-
const dir =
|
|
23759
|
+
const dir = stampDir2(env, session);
|
|
23702
23760
|
fs26.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
23703
23761
|
const now = Date.now();
|
|
23704
23762
|
for (const name of fs26.readdirSync(dir))
|
|
23705
23763
|
if (now - fs26.statSync(path40.join(dir, name)).mtimeMs > STAMP_TTL_MS)
|
|
23706
23764
|
fs26.rmSync(path40.join(dir, name), { force: true });
|
|
23707
|
-
calls.forEach((argv, index) => fs26.writeFileSync(path40.join(dir, `${
|
|
23765
|
+
calls.forEach((argv, index) => fs26.writeFileSync(path40.join(dir, `${stampHash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
|
|
23708
23766
|
} catch {}
|
|
23709
23767
|
};
|
|
23710
|
-
var callTag = (toolUseId) => hash2(toolUseId).slice(0, 8);
|
|
23711
23768
|
var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
23712
|
-
if (
|
|
23713
|
-
|
|
23714
|
-
try {
|
|
23715
|
-
const dir = stampDir(env, session);
|
|
23716
|
-
const tag = `.${callTag(toolUseId)}-`;
|
|
23717
|
-
for (const name of fs26.readdirSync(dir))
|
|
23718
|
-
if (name.includes(tag))
|
|
23719
|
-
fs26.rmSync(path40.join(dir, name), { force: true });
|
|
23720
|
-
} catch {}
|
|
23769
|
+
if (session && toolUseId && command.includes("workit") && !backgrounds2(command))
|
|
23770
|
+
dropCallStamps2(env, session, toolUseId);
|
|
23721
23771
|
};
|
|
23722
23772
|
|
|
23723
23773
|
// packages/workit-core/src/hooks/hook-entry.ts
|
|
@@ -24159,13 +24209,36 @@ var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
|
24159
24209
|
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
24210
|
|
|
24161
24211
|
// packages/workit-core/src/hooks/identity-env.ts
|
|
24212
|
+
import fs27 from "node:fs";
|
|
24213
|
+
import path42 from "node:path";
|
|
24162
24214
|
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
24215
|
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
24216
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
24165
24217
|
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
24166
|
-
var
|
|
24218
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
24219
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
24220
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
24221
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
24222
|
+
var powershell = (names) => new RegExp([
|
|
24223
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
24224
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
24225
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
24226
|
+
].join("|"), "iu");
|
|
24227
|
+
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
24228
|
var POWERSHELL = powershell(NAMES);
|
|
24229
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
24168
24230
|
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
24231
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
24232
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
24233
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
24234
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
24235
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
24236
|
+
].join("|"), "iu");
|
|
24237
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
24238
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
24239
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
24240
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
24241
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
24169
24242
|
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
24170
24243
|
var OPAQUE = new Set([
|
|
24171
24244
|
"watch",
|
|
@@ -24183,22 +24256,41 @@ var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
|
24183
24256
|
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
24184
24257
|
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
24185
24258
|
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
24186
|
-
var
|
|
24187
|
-
var
|
|
24188
|
-
var
|
|
24259
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
24260
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
24261
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
24262
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
24263
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
24264
|
+
var linksToWorkit = (word, cwd) => {
|
|
24265
|
+
const places = /[\\/]/u.test(word) ? [path42.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path42.delimiter).map((dir) => path42.join(dir, word));
|
|
24266
|
+
for (const place of places) {
|
|
24267
|
+
try {
|
|
24268
|
+
const real = fs27.realpathSync(place);
|
|
24269
|
+
return isWorkit(real);
|
|
24270
|
+
} catch {}
|
|
24271
|
+
}
|
|
24272
|
+
return false;
|
|
24273
|
+
};
|
|
24274
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
24189
24275
|
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
24190
|
-
var
|
|
24191
|
-
|
|
24192
|
-
|
|
24193
|
-
|
|
24194
|
-
|
|
24195
|
-
|
|
24196
|
-
}
|
|
24197
|
-
|
|
24276
|
+
var note = (scan, seg, word) => {
|
|
24277
|
+
if (scan.identity && named(word)) {
|
|
24278
|
+
if (seg)
|
|
24279
|
+
seg.identity ??= nameOf(word);
|
|
24280
|
+
else
|
|
24281
|
+
scan.hit ??= nameOf(word);
|
|
24282
|
+
}
|
|
24283
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
24284
|
+
return;
|
|
24285
|
+
if (seg)
|
|
24286
|
+
seg.scoped ??= nameOf(word);
|
|
24287
|
+
else
|
|
24288
|
+
scan.shell ??= nameOf(word);
|
|
24289
|
+
};
|
|
24290
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
24291
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
24198
24292
|
const risky = (what) => void (scan.risky ??= what);
|
|
24199
|
-
const unset = (name) =>
|
|
24200
|
-
mark(scan, name);
|
|
24201
|
-
};
|
|
24293
|
+
const unset = (name) => note(scan, seg, name);
|
|
24202
24294
|
const split = (line, rest, built) => {
|
|
24203
24295
|
if (line === undefined || depth >= 4)
|
|
24204
24296
|
return risky(UNREADABLE);
|
|
@@ -24215,7 +24307,7 @@ var scanEnv = (words, at, expands, scan, depth) => {
|
|
|
24215
24307
|
} catch {
|
|
24216
24308
|
return risky(UNREADABLE);
|
|
24217
24309
|
}
|
|
24218
|
-
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, depth + 1);
|
|
24310
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
24219
24311
|
};
|
|
24220
24312
|
let options = true;
|
|
24221
24313
|
for (let index = at;index < words.length; index += 1) {
|
|
@@ -24273,25 +24365,25 @@ var scanEnv = (words, at, expands, scan, depth) => {
|
|
|
24273
24365
|
}
|
|
24274
24366
|
continue;
|
|
24275
24367
|
}
|
|
24276
|
-
if (
|
|
24368
|
+
if (ASSIGN.test(word)) {
|
|
24277
24369
|
unset(word);
|
|
24278
24370
|
continue;
|
|
24279
24371
|
}
|
|
24280
|
-
return commandAt(words.slice(index), scan);
|
|
24372
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
24281
24373
|
}
|
|
24282
24374
|
};
|
|
24283
|
-
var commandAt = (words, scan, expands = new Set, from = 0) => {
|
|
24375
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
24284
24376
|
let index = from;
|
|
24285
24377
|
while (index < words.length) {
|
|
24286
|
-
while (
|
|
24287
|
-
|
|
24378
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
24379
|
+
note(scan, seg, words[index]);
|
|
24288
24380
|
index += 1;
|
|
24289
24381
|
}
|
|
24290
24382
|
const name = base2(words[index]).toLowerCase();
|
|
24291
24383
|
if (name === "env")
|
|
24292
|
-
return scanEnv(words, index + 1, expands, scan, 0);
|
|
24384
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
24293
24385
|
if (OPAQUE.has(name))
|
|
24294
|
-
return opaque(words.slice(index + 1), scan, true);
|
|
24386
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
24295
24387
|
if (name === "busybox" || name === "toybox") {
|
|
24296
24388
|
index += 1;
|
|
24297
24389
|
continue;
|
|
@@ -24301,21 +24393,37 @@ var commandAt = (words, scan, expands = new Set, from = 0) => {
|
|
|
24301
24393
|
break;
|
|
24302
24394
|
index = pastOptions(words, index + 1, takes);
|
|
24303
24395
|
}
|
|
24304
|
-
|
|
24305
|
-
|
|
24306
|
-
|
|
24307
|
-
|
|
24308
|
-
|
|
24309
|
-
|
|
24396
|
+
const word = words[index];
|
|
24397
|
+
if (word === undefined)
|
|
24398
|
+
return;
|
|
24399
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
24400
|
+
const rest = words.slice(index + 1);
|
|
24401
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
24402
|
+
seg.runs = true;
|
|
24403
|
+
if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
|
|
24404
|
+
opaque(rest, scan, seg, false);
|
|
24405
|
+
const program = base2(word).toLowerCase();
|
|
24406
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
24407
|
+
if (program === "cmd" || shell) {
|
|
24408
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
24409
|
+
if (at >= 0) {
|
|
24410
|
+
const script = rest.slice(at + 1).join(" ");
|
|
24411
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
24412
|
+
if (change)
|
|
24413
|
+
scan.hit ??= change;
|
|
24414
|
+
}
|
|
24415
|
+
}
|
|
24416
|
+
};
|
|
24417
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
24310
24418
|
if (!rest.some(isWorkit))
|
|
24311
24419
|
return;
|
|
24312
|
-
|
|
24313
|
-
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns &&
|
|
24420
|
+
seg.runs = true;
|
|
24421
|
+
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
24314
24422
|
if (rest.some(changes))
|
|
24315
24423
|
scan.risky ??= UNREADABLE;
|
|
24316
|
-
|
|
24317
|
-
|
|
24318
|
-
|
|
24424
|
+
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
24425
|
+
for (const word of rest)
|
|
24426
|
+
note(scan, seg, word);
|
|
24319
24427
|
};
|
|
24320
24428
|
var LOGIN_VALUED = {
|
|
24321
24429
|
su: /[sgGwc]/u,
|
|
@@ -24350,43 +24458,90 @@ var scanCommand2 = (command, dialect, depth, scan) => {
|
|
|
24350
24458
|
}
|
|
24351
24459
|
for (const { words, expands = [] } of segments) {
|
|
24352
24460
|
const expanded = new Set(expands);
|
|
24461
|
+
const seg = newSeg();
|
|
24353
24462
|
let at = 0;
|
|
24354
|
-
while (
|
|
24355
|
-
mark(scan, words[at]);
|
|
24463
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
24356
24464
|
at += 1;
|
|
24357
|
-
|
|
24465
|
+
for (const word of words.slice(0, at))
|
|
24466
|
+
note(scan, at === words.length ? null : seg, word);
|
|
24358
24467
|
let declare = at;
|
|
24359
24468
|
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
24360
24469
|
declare += 1;
|
|
24361
24470
|
if (DECLARES.has(words[declare] ?? "")) {
|
|
24362
24471
|
for (let index = declare + 1;index < words.length; index += 1) {
|
|
24363
|
-
|
|
24472
|
+
note(scan, null, words[index]);
|
|
24364
24473
|
if (expanded.has(index))
|
|
24365
24474
|
scan.risky ??= UNREADABLE;
|
|
24366
24475
|
}
|
|
24367
24476
|
continue;
|
|
24368
24477
|
}
|
|
24369
|
-
commandAt(words, scan, expanded, at);
|
|
24478
|
+
commandAt(words, scan, seg, expanded, at);
|
|
24370
24479
|
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
24371
|
-
if (script)
|
|
24480
|
+
if (script) {
|
|
24481
|
+
const before = scan.runs;
|
|
24482
|
+
scan.runs = false;
|
|
24372
24483
|
scanCommand2(script, dialect, depth + 1, scan);
|
|
24373
|
-
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
24484
|
+
seg.runs ||= scan.runs;
|
|
24485
|
+
scan.runs ||= before;
|
|
24486
|
+
}
|
|
24487
|
+
scan.words.push(...seg.words);
|
|
24488
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
24489
|
+
if (seg.identity && reaches())
|
|
24490
|
+
scan.hit ??= seg.identity;
|
|
24491
|
+
if (seg.scoped && reaches())
|
|
24492
|
+
scan.state ??= seg.scoped;
|
|
24493
|
+
scan.runs ||= seg.runs;
|
|
24494
|
+
}
|
|
24495
|
+
};
|
|
24496
|
+
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);
|
|
24497
|
+
var powershellChange = (command, identity) => {
|
|
24498
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
24499
|
+
if (hit)
|
|
24500
|
+
return hit;
|
|
24501
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
24377
24502
|
return null;
|
|
24503
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
24504
|
+
if (state)
|
|
24505
|
+
return state;
|
|
24506
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
24507
|
+
};
|
|
24508
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
24509
|
+
const identity = options.identity ?? true;
|
|
24378
24510
|
if (dialect === "powershell")
|
|
24379
|
-
return
|
|
24380
|
-
|
|
24511
|
+
return powershellChange(command, identity);
|
|
24512
|
+
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))
|
|
24513
|
+
return null;
|
|
24514
|
+
const scan = {
|
|
24515
|
+
identity,
|
|
24516
|
+
cwd: options.cwd,
|
|
24517
|
+
hit: null,
|
|
24518
|
+
state: null,
|
|
24519
|
+
shell: null,
|
|
24520
|
+
risky: null,
|
|
24521
|
+
runs: false,
|
|
24522
|
+
words: []
|
|
24523
|
+
};
|
|
24381
24524
|
scanCommand2(command, dialect, 0, scan);
|
|
24382
|
-
|
|
24525
|
+
if (scan.hit)
|
|
24526
|
+
return scan.hit;
|
|
24527
|
+
if (scan.state)
|
|
24528
|
+
return scan.state;
|
|
24529
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
24530
|
+
return scan.shell;
|
|
24531
|
+
return scan.runs ? scan.risky : null;
|
|
24532
|
+
};
|
|
24533
|
+
var identityEnvDeny = (change) => {
|
|
24534
|
+
if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
|
|
24535
|
+
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).`;
|
|
24536
|
+
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
24537
|
};
|
|
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
24538
|
|
|
24386
24539
|
// packages/workit-core/src/hooks/handle.ts
|
|
24387
24540
|
var usable2 = (value) => value === "native" || value === "partial";
|
|
24388
24541
|
var stampsAgents = (descriptor) => descriptor.transport === "hook-process" && usable2(descriptor.provenance.agentIdOnTool);
|
|
24389
24542
|
var NONE6 = { kind: "none" };
|
|
24543
|
+
var subagentShellIsOwnSession = (descriptor) => descriptor.host === "codex_cli" || descriptor.host === "codex_desktop";
|
|
24544
|
+
var stampKey = (input, descriptor) => subagentShellIsOwnSession(descriptor) && input.session.agentId ? { session: input.session.agentId, agentId: null } : { session: input.session.id, agentId: input.session.agentId };
|
|
24390
24545
|
var resendsOnChange = (descriptor) => descriptor.context.turnResend === "on-change" && usable2(descriptor.context.perTurn);
|
|
24391
24546
|
var offered = new Set;
|
|
24392
24547
|
var agentRole = (input, descriptor) => input.session.agentId && input.session.agentType !== null ? workitRole(descriptor, input.session.agentType) : null;
|
|
@@ -24432,7 +24587,7 @@ ${subagentStartText({ ...input, cwd: "" }, descriptor, event)}`;
|
|
|
24432
24587
|
const at = currentBranch(cwd) === null ? null : worktreeTop(cwd) ?? null;
|
|
24433
24588
|
const checks = judgeChecksLine(cwd);
|
|
24434
24589
|
const checksText = checks ? ` ${checks}` : "";
|
|
24435
|
-
if (descriptor
|
|
24590
|
+
if (subagentShellIsOwnSession(descriptor))
|
|
24436
24591
|
return `${readOnly} Its shell already acts as its own Workit session, so the ledger tells its verdicts apart from the author's. Record the verdict with exactly this command (pick the result${pick}, name the candidate branch if it differs, say what you ran): \`${verdictCommand({ branch, judge, cwd: at })}\`. Add no session or token option to it, and never set WORKIT_SESSION_ID by hand.${checksText}`;
|
|
24437
24592
|
const token = session ? recordIssuedSession(cwd, session, own) : null;
|
|
24438
24593
|
if (session && !token)
|
|
@@ -24458,6 +24613,7 @@ function decide(input, deps) {
|
|
|
24458
24613
|
switch (event.kind) {
|
|
24459
24614
|
case "session.start": {
|
|
24460
24615
|
reapAtStart(input.cwd);
|
|
24616
|
+
pinIssuedRegistry(input.cwd);
|
|
24461
24617
|
if (!usable2(descriptor.context.sessionStart))
|
|
24462
24618
|
return NONE6;
|
|
24463
24619
|
const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
|
|
@@ -24581,7 +24737,10 @@ function decide(input, deps) {
|
|
|
24581
24737
|
const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
|
|
24582
24738
|
if (gate.kind === "deny")
|
|
24583
24739
|
return gate;
|
|
24584
|
-
const identity = canDeny
|
|
24740
|
+
const identity = canDeny ? identityEnvChange(event.command, event.dialect, {
|
|
24741
|
+
identity: stampsAgents(descriptor),
|
|
24742
|
+
cwd: input.cwd
|
|
24743
|
+
}) : null;
|
|
24585
24744
|
if (identity)
|
|
24586
24745
|
return { kind: "deny", reason: identityEnvDeny(identity), unblock: null };
|
|
24587
24746
|
const plan = heavyGate(input.cwd, event.command, {
|
|
@@ -24601,8 +24760,10 @@ function decide(input, deps) {
|
|
|
24601
24760
|
const aside = plan.kind === "passthrough" ? plan.note : null;
|
|
24602
24761
|
noteRawCommit(input, event.command, postTool ? callKey(event.toolUseId, event.command) : NEXT_COMMAND);
|
|
24603
24762
|
const bypass = !lease && input.host === "claude_code" ? workitBypassFlag(event.command, event.dialect) : null;
|
|
24604
|
-
if (stampsAgents(descriptor))
|
|
24605
|
-
|
|
24763
|
+
if (stampsAgents(descriptor)) {
|
|
24764
|
+
const key = stampKey(input, descriptor);
|
|
24765
|
+
noteAgentStamps(process.env, key.session, key.agentId, lease?.command ?? cwdCommand ?? event.command, { dialect: event.dialect, toolUseId: event.toolUseId });
|
|
24766
|
+
}
|
|
24606
24767
|
if (bypass)
|
|
24607
24768
|
return { kind: "ask", reason: bypass };
|
|
24608
24769
|
const rewrittenTo = lease?.command ?? cwdCommand;
|
|
@@ -24632,7 +24793,7 @@ function decide(input, deps) {
|
|
|
24632
24793
|
if (usable2(descriptor.events["shell.post"].support))
|
|
24633
24794
|
rawGitPost(input, event.command, callKey(event.toolUseId, event.command));
|
|
24634
24795
|
if (stampsAgents(descriptor))
|
|
24635
|
-
dropAgentStamps(process.env, input.session
|
|
24796
|
+
dropAgentStamps(process.env, stampKey(input, descriptor).session, event.toolUseId, event.command);
|
|
24636
24797
|
return NONE6;
|
|
24637
24798
|
case "write.pre": {
|
|
24638
24799
|
if (!usable2(descriptor.events["write.pre"].support))
|
|
@@ -24724,7 +24885,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
|
|
|
24724
24885
|
};
|
|
24725
24886
|
// packages/workit-core/src/hooks/deadline.ts
|
|
24726
24887
|
import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
|
|
24727
|
-
import
|
|
24888
|
+
import path43 from "node:path";
|
|
24728
24889
|
var HOOK_SKIP_TEXT = "workit context skipped: host under load";
|
|
24729
24890
|
var HOOK_DEADLINE_MS = 8000;
|
|
24730
24891
|
var HOST_DEADLINES = {
|
|
@@ -24742,7 +24903,7 @@ var hookDeadlineMs = (env, host = "", native) => {
|
|
|
24742
24903
|
const row = HOST_DEADLINES[host];
|
|
24743
24904
|
return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
|
|
24744
24905
|
};
|
|
24745
|
-
var skipsFile = (stateDir) =>
|
|
24906
|
+
var skipsFile = (stateDir) => path43.join(stateDir, HOOK_SKIPS_FILE);
|
|
24746
24907
|
var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
|
|
24747
24908
|
try {
|
|
24748
24909
|
mkdirSync4(stateDir, { recursive: true });
|
|
@@ -24794,7 +24955,7 @@ var readWithin = async (stdin, budget) => {
|
|
|
24794
24955
|
const text = await within2(read, budget.startedAt + budget.deadlineMs - budget.now());
|
|
24795
24956
|
return isTimedOut(text) ? null : text;
|
|
24796
24957
|
};
|
|
24797
|
-
var
|
|
24958
|
+
var note2 = (adapter, raw, env, budget, outcome, stage) => {
|
|
24798
24959
|
const parsed = raw === undefined ? null : adapter.parse(raw, env);
|
|
24799
24960
|
const event = parsed ? parsed.ok ? parsed.input.event.kind : parsed.event : null;
|
|
24800
24961
|
budget.record({
|
|
@@ -24808,7 +24969,7 @@ var note = (adapter, raw, env, budget, outcome, stage) => {
|
|
|
24808
24969
|
return { native: parsed?.native ?? null, event };
|
|
24809
24970
|
};
|
|
24810
24971
|
var skippedHook = (adapter, raw, env, budget, stage) => {
|
|
24811
|
-
const { native, event } =
|
|
24972
|
+
const { native, event } = note2(adapter, raw, env, budget, "skip", stage);
|
|
24812
24973
|
return {
|
|
24813
24974
|
...adapter.render(skipDecision(event), native),
|
|
24814
24975
|
error: `${HOOK_SKIP_TEXT} (past the ${budget.deadlineMs} ms hook deadline)`,
|
|
@@ -24824,7 +24985,7 @@ var dispatchWithin = async (adapter, raw, env, budget, dispatch = dispatchHook)
|
|
|
24824
24985
|
if (isTimedOut(result))
|
|
24825
24986
|
return skippedHook(adapter, raw, env, budget, "dispatch");
|
|
24826
24987
|
if (remaining() < 0)
|
|
24827
|
-
|
|
24988
|
+
note2(adapter, raw, env, budget, "late", "done");
|
|
24828
24989
|
return { ...result, skipped: false };
|
|
24829
24990
|
};
|
|
24830
24991
|
|
package/dist/workit-hook.js
CHANGED
|
@@ -42,6 +42,7 @@ var { recordHookRun } = await import("./workit-hook-a7qmf2t8.js");
|
|
|
42
42
|
var { observeHookBudget } = await import("./workit-hook-3g6cv3hd.js");
|
|
43
43
|
var { hasTaskStore, mayReach } = await import("./workit-hook-3c7ce65d.js");
|
|
44
44
|
var { mayHitHookGuard } = await import("./workit-hook-hhg5reqd.js");
|
|
45
|
+
var { dropPostToolStamps, mayChangeIdentity, mayRunWorkit } = await import("./workit-hook-v241dvew.js");
|
|
45
46
|
var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
|
|
46
47
|
var namesYtrack = (text) => {
|
|
47
48
|
const bare = text.replace(/['"\\]/g, "");
|
|
@@ -60,7 +61,7 @@ var SHELL_TOOLS = new Set(["bash", "unified-exec"]);
|
|
|
60
61
|
var WRITE_TOOLS = new Set(["applypatch", "edit", "write"]);
|
|
61
62
|
var guarded = (text) => {
|
|
62
63
|
const flat = (s) => s.replaceAll("\\", "/").toLowerCase();
|
|
63
|
-
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)))));
|
|
64
|
+
return [flat(text), text.replace(/['"\\]/g, "").toLowerCase()].some((all) => /issued|approvals|agent-stamps|workspaces\.json|\.config\/workit|state\/workit/.test(all) || [stateDir, configDir].some((dir) => all.includes(flat(dir(process.env)))));
|
|
64
65
|
};
|
|
65
66
|
var quietEvent = () => {
|
|
66
67
|
try {
|
|
@@ -88,12 +89,15 @@ var quietEvent = () => {
|
|
|
88
89
|
return null;
|
|
89
90
|
if (event === "PostToolUse")
|
|
90
91
|
return /\bcommit\b/.test(text) ? null : event;
|
|
92
|
+
if (mayRunWorkit(text) || mayChangeIdentity(text))
|
|
93
|
+
return null;
|
|
91
94
|
const writes = /\b(?:git|gh|glab)\b|>|\b(?:tee|sponge|touch|mkdir|rm|rmdir|mv|cp|truncate|install|ln|patch|dd|sed|perl|set-content|add-content|out-file|new-item|ni|remove-item|del|copy-item|move-item)\b/i.test(text.replace(/\d*>&(?:\d+|-)(?![^\s;&|()<>])|[\d&]*>>?\s*\/dev\/(?:null|stdout|stderr|tty)(?![^\s;&|()<>])/g, " "));
|
|
92
95
|
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) || mayHitHookGuard(text) || namesYtrack(text) || mayRunUserOnly(text) || writes && (process.platform === "win32" || hasTaskStore(value.cwd)) || mayReach(text, value.cwd) || maybeHeavy(text, value.cwd) ? null : event;
|
|
93
96
|
} catch {
|
|
94
97
|
return null;
|
|
95
98
|
}
|
|
96
99
|
};
|
|
100
|
+
dropPostToolStamps(process.env, payload);
|
|
97
101
|
var quiet = observeHookBudget(payload) ? null : quietEvent();
|
|
98
102
|
if (quiet) {
|
|
99
103
|
if (quiet === "PreToolUse")
|
|
@@ -102,7 +106,7 @@ if (quiet) {
|
|
|
102
106
|
`);
|
|
103
107
|
} else {
|
|
104
108
|
try {
|
|
105
|
-
const { runCodexHook } = await import("./workit-hook-
|
|
109
|
+
const { runCodexHook } = await import("./workit-hook-vn2fvwba.js");
|
|
106
110
|
await runCodexHook([payload]);
|
|
107
111
|
} catch (error) {
|
|
108
112
|
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.
|
|
3
|
+
"version": "2.27.10",
|
|
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.
|
|
45
|
-
"@workit-dev/mcp": "^2.27.
|
|
44
|
+
"@workit-dev/core": "^2.27.10",
|
|
45
|
+
"@workit-dev/mcp": "^2.27.10"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=24"
|