@workit-dev/codex 2.14.0 → 2.15.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": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "Adaptive engineering workflow rails for Codex",
5
5
  "author": {
6
6
  "name": "BrainerVirus"
@@ -30941,11 +30941,12 @@ var FLAGS = {
30941
30941
  var CLAUDE_CODE_DESCRIPTOR = {
30942
30942
  host: "claude_code",
30943
30943
  label: "Claude Code",
30944
- verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary)",
30944
+ verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
30945
30945
  docs: ["https://code.claude.com/docs/en/hooks"],
30946
30946
  transport: "hook-process",
30947
30947
  events: {
30948
30948
  "session.start": { support: "native", native: "SessionStart" },
30949
+ "session.end": { support: "native", native: "SessionEnd" },
30949
30950
  "context.turn": { support: "native", native: "UserPromptSubmit" },
30950
30951
  "shell.pre": { support: "native", native: "PreToolUse" },
30951
30952
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -31058,6 +31059,7 @@ var CODEX_DESCRIPTOR = {
31058
31059
  transport: "hook-process",
31059
31060
  events: {
31060
31061
  "session.start": { support: "native", native: "SessionStart" },
31062
+ "session.end": { support: "none", native: null },
31061
31063
  "context.turn": { support: "native", native: "UserPromptSubmit" },
31062
31064
  "shell.pre": { support: "native", native: "PreToolUse" },
31063
31065
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -31329,6 +31331,7 @@ var CURSOR_DESCRIPTOR = {
31329
31331
  transport: "hook-process",
31330
31332
  events: {
31331
31333
  "session.start": { support: "native", native: "sessionStart" },
31334
+ "session.end": { support: "native", native: "sessionEnd" },
31332
31335
  "context.turn": none,
31333
31336
  "shell.pre": { support: "native", native: "beforeShellExecution" },
31334
31337
  "tool.pre": { support: "native", native: "preToolUse" },
@@ -31435,6 +31438,7 @@ var OPENCODE_DESCRIPTOR = {
31435
31438
  transport: "in-process-plugin",
31436
31439
  events: {
31437
31440
  "session.start": { support: "none", native: null },
31441
+ "session.end": { support: "partial", native: 'event("session.deleted")' },
31438
31442
  "context.turn": { support: "native", native: 'session.hook("context")' },
31439
31443
  "shell.pre": { support: "native", native: 'permission.hook("evaluate")' },
31440
31444
  "tool.pre": { support: "native", native: 'tool.hook("execute.before")' },
@@ -31504,6 +31508,7 @@ var PI_DESCRIPTOR = {
31504
31508
  transport: "in-process-plugin",
31505
31509
  events: {
31506
31510
  "session.start": { support: "native", native: "session_start" },
31511
+ "session.end": { support: "native", native: "session_shutdown" },
31507
31512
  "context.turn": { support: "native", native: "before_agent_start" },
31508
31513
  "shell.pre": { support: "native", native: "tool_call" },
31509
31514
  "tool.pre": { support: "native", native: "tool_call" },
@@ -31614,6 +31619,16 @@ var SCAN_MS = 30 * 60000;
31614
31619
  // packages/workit-core/src/hooks/agent-model.ts
31615
31620
  var UNLISTED = new Set(["description", "prompt"]);
31616
31621
 
31622
+ // packages/workit-core/src/hooks/teardown.ts
31623
+ var REAP_INTERVAL_MS = 10 * 60000;
31624
+ var LOG_MAX_BYTES = 1 << 20;
31625
+ var ENDS = {
31626
+ claude_code: new Set(["logout", "prompt_input_exit", "other"]),
31627
+ cursor: new Set(["completed", "aborted", "error", "window_close", "user_close"]),
31628
+ pi: new Set(["quit"]),
31629
+ opencode: new Set(["deleted"])
31630
+ };
31631
+
31617
31632
  // packages/workit-core/src/hooks/ytrack-guard.ts
31618
31633
  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 " + "--attach -H --header").split(" "));
31619
31634
  var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
@@ -30,7 +30,7 @@ var head = (file) => {
30
30
  closeSync(fd);
31
31
  }
32
32
  };
33
- var locateWorkitCli = (options = {}) => {
33
+ var locateWorkitCli2 = (options = {}) => {
34
34
  const env = options.env ?? process.env;
35
35
  const platform = options.platform ?? process.platform;
36
36
  const exists = options.exists ?? existsSync;
@@ -77,12 +77,11 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
77
77
  }
78
78
  return patch;
79
79
  };
80
- var useOwnedWorkitCli = (options = {}) => {
80
+ var useOwnedWorkitCli2 = (options = {}) => {
81
81
  const env = options.env ?? process.env;
82
- const located = locateWorkitCli({ ...options, env });
82
+ const located = locateWorkitCli2({ ...options, env });
83
83
  Object.assign(env, workitCliEnv(located, env, options.platform));
84
84
  return located;
85
85
  };
86
- export {
87
- useOwnedWorkitCli
88
- };
86
+
87
+ export { locateWorkitCli2, useOwnedWorkitCli2 };
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ locateWorkitCli2,
4
+ useOwnedWorkitCli2
5
+ } from "./workit-hook-azjr1ew1.js";
6
+ import"./workit-hook-7jv519ep.js";
7
+ export {
8
+ locateWorkitCli2 as locateWorkitCli,
9
+ useOwnedWorkitCli2 as useOwnedWorkitCli
10
+ };
@@ -27,6 +27,9 @@ import {
27
27
  import {
28
28
  takeProcNotice2
29
29
  } from "./workit-hook-btkg30rw.js";
30
+ import {
31
+ locateWorkitCli2
32
+ } from "./workit-hook-azjr1ew1.js";
30
33
  import {
31
34
  recordHookRun2
32
35
  } from "./workit-hook-w7w0fe4v.js";
@@ -21934,11 +21937,12 @@ var FLAGS = {
21934
21937
  var CLAUDE_CODE_DESCRIPTOR = {
21935
21938
  host: "claude_code",
21936
21939
  label: "Claude Code",
21937
- verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary)",
21940
+ verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
21938
21941
  docs: ["https://code.claude.com/docs/en/hooks"],
21939
21942
  transport: "hook-process",
21940
21943
  events: {
21941
21944
  "session.start": { support: "native", native: "SessionStart" },
21945
+ "session.end": { support: "native", native: "SessionEnd" },
21942
21946
  "context.turn": { support: "native", native: "UserPromptSubmit" },
21943
21947
  "shell.pre": { support: "native", native: "PreToolUse" },
21944
21948
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -22051,6 +22055,7 @@ var CODEX_DESCRIPTOR = {
22051
22055
  transport: "hook-process",
22052
22056
  events: {
22053
22057
  "session.start": { support: "native", native: "SessionStart" },
22058
+ "session.end": { support: "none", native: null },
22054
22059
  "context.turn": { support: "native", native: "UserPromptSubmit" },
22055
22060
  "shell.pre": { support: "native", native: "PreToolUse" },
22056
22061
  "tool.pre": { support: "native", native: "PreToolUse" },
@@ -22322,6 +22327,7 @@ var CURSOR_DESCRIPTOR = {
22322
22327
  transport: "hook-process",
22323
22328
  events: {
22324
22329
  "session.start": { support: "native", native: "sessionStart" },
22330
+ "session.end": { support: "native", native: "sessionEnd" },
22325
22331
  "context.turn": none,
22326
22332
  "shell.pre": { support: "native", native: "beforeShellExecution" },
22327
22333
  "tool.pre": { support: "native", native: "preToolUse" },
@@ -22428,6 +22434,7 @@ var OPENCODE_DESCRIPTOR = {
22428
22434
  transport: "in-process-plugin",
22429
22435
  events: {
22430
22436
  "session.start": { support: "none", native: null },
22437
+ "session.end": { support: "partial", native: 'event("session.deleted")' },
22431
22438
  "context.turn": { support: "native", native: 'session.hook("context")' },
22432
22439
  "shell.pre": { support: "native", native: 'permission.hook("evaluate")' },
22433
22440
  "tool.pre": { support: "native", native: 'tool.hook("execute.before")' },
@@ -22497,6 +22504,7 @@ var PI_DESCRIPTOR = {
22497
22504
  transport: "in-process-plugin",
22498
22505
  events: {
22499
22506
  "session.start": { support: "native", native: "session_start" },
22507
+ "session.end": { support: "native", native: "session_shutdown" },
22500
22508
  "context.turn": { support: "native", native: "before_agent_start" },
22501
22509
  "shell.pre": { support: "native", native: "tool_call" },
22502
22510
  "tool.pre": { support: "native", native: "tool_call" },
@@ -24020,6 +24028,156 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
24020
24028
  return agentModelDecision(cwd, checked.input, { change: checked.change, permissionMode });
24021
24029
  };
24022
24030
 
24031
+ // packages/workit-core/src/hooks/teardown.ts
24032
+ import { spawn } from "node:child_process";
24033
+ import fs23 from "node:fs";
24034
+ import path35 from "node:path";
24035
+ var REAP_INTERVAL_MS = 10 * 60000;
24036
+ var LOG_MAX_BYTES = 1 << 20;
24037
+ var ENDS = {
24038
+ claude_code: new Set(["logout", "prompt_input_exit", "other"]),
24039
+ cursor: new Set(["completed", "aborted", "error", "window_close", "user_close"]),
24040
+ pi: new Set(["quit"]),
24041
+ opencode: new Set(["deleted"])
24042
+ };
24043
+ var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
24044
+ var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
24045
+ var teardownDir = (env) => path35.join(stateDir3(env), "procs");
24046
+ var teardownLog = (env) => path35.join(teardownDir(env), "teardown.log");
24047
+ var reapStamp = (env) => path35.join(teardownDir(env), "reap-at-start.stamp");
24048
+ function spawnDetached(request) {
24049
+ try {
24050
+ const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
24051
+ const line = [`"${request.command}"`, ...request.args].join(" ");
24052
+ const child = spawn(shell ? line : request.command, shell ? [] : request.args, {
24053
+ cwd: request.cwd,
24054
+ env: request.env,
24055
+ detached: true,
24056
+ shell,
24057
+ stdio: ["ignore", request.log ?? "ignore", request.log ?? "ignore"],
24058
+ windowsHide: true
24059
+ });
24060
+ child.on("error", () => {});
24061
+ child.unref();
24062
+ return child.pid !== undefined;
24063
+ } catch {
24064
+ return false;
24065
+ }
24066
+ }
24067
+ var teardownDeps = {
24068
+ spawn: (request) => request.env.WORKIT_TEST_RUN === undefined && spawnDetached(request),
24069
+ now: () => Date.now()
24070
+ };
24071
+ var openLog = (env, args) => {
24072
+ try {
24073
+ const file = teardownLog(env);
24074
+ fs23.mkdirSync(path35.dirname(file), { recursive: true });
24075
+ let size = 0;
24076
+ try {
24077
+ size = fs23.statSync(file).size;
24078
+ } catch {}
24079
+ const fd = fs23.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
24080
+ fs23.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
24081
+ `);
24082
+ return fd;
24083
+ } catch {
24084
+ return null;
24085
+ }
24086
+ };
24087
+ function runCli(args, env, cwd) {
24088
+ let log = null;
24089
+ try {
24090
+ const cli = locateWorkitCli2({ env });
24091
+ log = openLog(env, args);
24092
+ const started = teardownDeps.spawn({
24093
+ command: cli.command,
24094
+ args: [...cli.args, ...args],
24095
+ env,
24096
+ cwd: fs23.existsSync(cwd) ? cwd : teardownDir(env),
24097
+ log
24098
+ });
24099
+ if (!started && log !== null)
24100
+ fs23.writeSync(log, ` not started
24101
+ `);
24102
+ return started;
24103
+ } catch {
24104
+ return false;
24105
+ } finally {
24106
+ if (log !== null)
24107
+ try {
24108
+ fs23.closeSync(log);
24109
+ } catch {}
24110
+ }
24111
+ }
24112
+ function endSession(end, env = process.env) {
24113
+ const session = end.session?.trim() ?? "";
24114
+ if (!SAFE_SESSION.test(session) || !ENDS[end.host]?.has(end.reason ?? ""))
24115
+ return false;
24116
+ const outer = env.WORKIT_SESSION_ID?.trim();
24117
+ if (end.agentId || env.WORKIT_PI_WORKER_SESSION || leadOf(session) !== session || outer && leadOf(outer) !== outer)
24118
+ return false;
24119
+ const child = { ...env, WORKIT_SESSION_ID: session, WORKIT_HOST: end.host };
24120
+ for (const key of HOST_SESSION_VARS)
24121
+ delete child[key];
24122
+ return runCli(["stop", "--session", session, "--reason", "session-end"], child, end.cwd);
24123
+ }
24124
+ var claim2 = (file, now) => {
24125
+ for (let attempt = 0;attempt < 2; attempt += 1)
24126
+ try {
24127
+ fs23.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
24128
+ return true;
24129
+ } catch (error) {
24130
+ if (error.code !== "EEXIST")
24131
+ return false;
24132
+ let held = Number.NaN;
24133
+ try {
24134
+ held = Number(fs23.readFileSync(file, "utf8"));
24135
+ } catch {}
24136
+ if (now - held < REAP_INTERVAL_MS)
24137
+ return false;
24138
+ fs23.rmSync(file, { force: true });
24139
+ }
24140
+ return false;
24141
+ };
24142
+ var fresh = (stamp, now) => {
24143
+ try {
24144
+ const last = Number(fs23.readFileSync(stamp, "utf8"));
24145
+ return now - last < REAP_INTERVAL_MS && last <= now;
24146
+ } catch {
24147
+ return false;
24148
+ }
24149
+ };
24150
+ function reapAtStart(cwd, env = process.env) {
24151
+ const stamp = reapStamp(env);
24152
+ const lock = `${stamp}.claim`;
24153
+ const now = teardownDeps.now();
24154
+ try {
24155
+ if (fresh(stamp, now))
24156
+ return false;
24157
+ fs23.mkdirSync(path35.dirname(stamp), { recursive: true });
24158
+ if (!claim2(lock, now))
24159
+ return false;
24160
+ } catch {
24161
+ return false;
24162
+ }
24163
+ let started = false;
24164
+ try {
24165
+ if (fresh(stamp, now))
24166
+ return false;
24167
+ started = runCli(["stop", "--orphans", "--reason", "session-start"], env, cwd);
24168
+ if (started) {
24169
+ const temp = `${stamp}.${process.pid}`;
24170
+ fs23.writeFileSync(temp, String(now), { mode: 384 });
24171
+ fs23.renameSync(temp, stamp);
24172
+ }
24173
+ } catch {} finally {
24174
+ try {
24175
+ fs23.rmSync(lock, { force: true });
24176
+ } catch {}
24177
+ }
24178
+ return started;
24179
+ }
24180
+
24023
24181
  // packages/workit-core/src/hooks/ytrack-word.ts
24024
24182
  var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
24025
24183
  var namesYtrack = (text) => {
@@ -24582,6 +24740,7 @@ function decide(input, deps) {
24582
24740
  const event = input.event;
24583
24741
  switch (event.kind) {
24584
24742
  case "session.start": {
24743
+ reapAtStart(input.cwd);
24585
24744
  if (!usable2(descriptor.context.sessionStart))
24586
24745
  return NONE6;
24587
24746
  const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
@@ -24596,6 +24755,15 @@ function decide(input, deps) {
24596
24755
  seedTurnContext(input, descriptor);
24597
24756
  return { kind: "context", text };
24598
24757
  }
24758
+ case "session.end":
24759
+ endSession({
24760
+ host: input.host,
24761
+ session: input.session.id,
24762
+ agentId: input.session.agentId,
24763
+ reason: event.reason,
24764
+ cwd: input.cwd
24765
+ });
24766
+ return NONE6;
24599
24767
  case "context.turn": {
24600
24768
  if (!usable2(descriptor.context.perTurn))
24601
24769
  return NONE6;
@@ -24806,7 +24974,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
24806
24974
  };
24807
24975
  // packages/workit-core/src/hooks/deadline.ts
24808
24976
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
24809
- import path35 from "node:path";
24977
+ import path36 from "node:path";
24810
24978
  var HOOK_SKIP_TEXT = "workit context skipped: host under load";
24811
24979
  var HOOK_DEADLINE_MS = 8000;
24812
24980
  var HOST_DEADLINES = {
@@ -24824,7 +24992,7 @@ var hookDeadlineMs = (env, host = "", native) => {
24824
24992
  const row = HOST_DEADLINES[host];
24825
24993
  return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
24826
24994
  };
24827
- var skipsFile = (stateDir) => path35.join(stateDir, HOOK_SKIPS_FILE);
24995
+ var skipsFile = (stateDir) => path36.join(stateDir, HOOK_SKIPS_FILE);
24828
24996
  var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
24829
24997
  try {
24830
24998
  mkdirSync4(stateDir, { recursive: true });
@@ -32,7 +32,7 @@ if (tooOld) {
32
32
  const { belowFloor } = await import("./workit-hook-9k8dtngs.js");
33
33
  process.exit(await belowFloor(codexHost(), { ...tooOld, found: foundNode }, fileURLToPath(import.meta.url)));
34
34
  }
35
- var { useOwnedWorkitCli } = await import("./workit-hook-ve6718aj.js");
35
+ var { useOwnedWorkitCli } = await import("./workit-hook-dzfxvq92.js");
36
36
  useOwnedWorkitCli();
37
37
  var { maybeHeavy, stateDir } = await import("./workit-hook-1xk8mx4h.js");
38
38
  var { configDir } = await import("./workit-hook-z09frbdk.js");
@@ -101,7 +101,7 @@ if (quiet) {
101
101
  `);
102
102
  } else {
103
103
  try {
104
- const { runCodexHook } = await import("./workit-hook-mcerh8x3.js");
104
+ const { runCodexHook } = await import("./workit-hook-x0h085t0.js");
105
105
  await runCodexHook([payload]);
106
106
  } catch (error) {
107
107
  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": "2.14.0",
3
+ "version": "2.15.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": "^2.14.0",
45
- "@workit-dev/mcp": "^2.14.0"
44
+ "@workit-dev/core": "^2.15.0",
45
+ "@workit-dev/mcp": "^2.15.0"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=24"