@brainervirus/workit-pi 8.22.1 → 8.22.2

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.
Files changed (2) hide show
  1. package/dist/workit.js +67 -22
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -16744,9 +16744,17 @@ var sessionMarkerFile = (input, session, store) => {
16744
16744
  return path18.join(dir, "hooks", `skills-${name}.json`);
16745
16745
  };
16746
16746
  var list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
16747
- var readSessionMarker = (file) => {
16747
+ var EMPTY = { nudged: [], loaded: [], raw: [], stops: [], judges: [] };
16748
+ var readRaw = (file) => {
16748
16749
  try {
16749
- const value = JSON.parse(fs15.readFileSync(file, "utf8"));
16750
+ return fs15.readFileSync(file, "utf8");
16751
+ } catch {
16752
+ return "";
16753
+ }
16754
+ };
16755
+ var parseMarker = (text) => {
16756
+ try {
16757
+ const value = JSON.parse(text);
16750
16758
  return {
16751
16759
  nudged: list2(value.nudged),
16752
16760
  loaded: list2(value.loaded),
@@ -16755,13 +16763,36 @@ var readSessionMarker = (file) => {
16755
16763
  judges: list2(value.judges)
16756
16764
  };
16757
16765
  } catch {
16758
- return { nudged: [], loaded: [], raw: [], stops: [], judges: [] };
16766
+ return { ...EMPTY };
16767
+ }
16768
+ };
16769
+ var readSessionMarker = (file) => parseMarker(readRaw(file));
16770
+ var writeAtomic = (file, marker) => {
16771
+ fs15.mkdirSync(path18.dirname(file), { recursive: true });
16772
+ const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
16773
+ try {
16774
+ fs15.writeFileSync(temp, JSON.stringify(marker));
16775
+ fs15.renameSync(temp, file);
16776
+ } catch (error) {
16777
+ fs15.rmSync(temp, { force: true });
16778
+ throw error;
16759
16779
  }
16760
16780
  };
16761
16781
  var writeSessionMarker = (file, marker) => {
16762
16782
  try {
16763
- fs15.mkdirSync(path18.dirname(file), { recursive: true });
16764
- fs15.writeFileSync(file, JSON.stringify(marker));
16783
+ writeAtomic(file, marker);
16784
+ } catch {}
16785
+ };
16786
+ var updateSessionMarker = (file, change) => {
16787
+ try {
16788
+ for (let attempt = 0;attempt < 2; attempt++) {
16789
+ const before = readRaw(file);
16790
+ const next = change(parseMarker(before));
16791
+ if (attempt === 0 && readRaw(file) !== before)
16792
+ continue;
16793
+ writeAtomic(file, next);
16794
+ return;
16795
+ }
16765
16796
  } catch {}
16766
16797
  };
16767
16798
  var trackJudge = (input, agentId, running) => {
@@ -16769,9 +16800,10 @@ var trackJudge = (input, agentId, running) => {
16769
16800
  const file = session && agentId ? sessionMarkerFile(input, session) : null;
16770
16801
  if (!file || !agentId)
16771
16802
  return;
16772
- const marker = readSessionMarker(file);
16773
- const rest = marker.judges.filter((id) => id !== agentId);
16774
- writeSessionMarker(file, { ...marker, judges: running ? [...rest, agentId] : rest });
16803
+ updateSessionMarker(file, (marker) => {
16804
+ const rest = marker.judges.filter((id) => id !== agentId);
16805
+ return { ...marker, judges: running ? [...rest, agentId] : rest };
16806
+ });
16775
16807
  };
16776
16808
 
16777
16809
  // packages/workit-core/src/hooks/shell-words.ts
@@ -18420,8 +18452,8 @@ var offPolicyPush = (action, repo, facts, remote) => {
18420
18452
  var nudgeFor = (action, host, session) => {
18421
18453
  switch (action.kind) {
18422
18454
  case "commit": {
18423
- const prefix = host === "cursor" && session ? `WORKIT_SESSION_ID=${session} ` : "";
18424
- return action.amend ? `workit: raw ${quote("git commit --amend")} is recorded for this session; for new commits prefer ${quote(`${prefix}workit git commit -m '<msg>'`)} (adds the Workit-Session trailer and checks branch and commit policy).` : `workit: prefer ${quote(`${prefix}workit git commit -m '<msg>' [--all | -- <paths>]`)}: it adds the Workit-Session trailer and checks branch and commit policy.`;
18455
+ const workit = host === "cursor" && session ? `workit --session ${session}` : "workit";
18456
+ return action.amend ? `workit: raw ${quote("git commit --amend")} is recorded for this session; for new commits prefer ${quote(`${workit} git commit -m '<msg>'`)} (adds the Workit-Session trailer and checks branch and commit policy).` : `workit: prefer ${quote(`${workit} git commit -m '<msg>' [--all | -- <paths>]`)}: it adds the Workit-Session trailer and checks branch and commit policy.`;
18425
18457
  }
18426
18458
  case "push":
18427
18459
  return action.blindForce ? `workit: ${quote("git push --force")} overwrites without a lease; use ${quote("workit git push --force-with-lease")}.` : `workit: prefer ${quote("workit git push")}: it refuses protected branches and verifies the remote tip.`;
@@ -22173,7 +22205,7 @@ var shellPolicy = (cwd, command, dialect = "posix") => {
22173
22205
  import fs20 from "node:fs";
22174
22206
  import os6 from "node:os";
22175
22207
  import path27 from "node:path";
22176
- var EMPTY = () => ({ deny: [], allow: [] });
22208
+ var EMPTY2 = () => ({ deny: [], allow: [] });
22177
22209
  var readText2 = (file) => {
22178
22210
  try {
22179
22211
  return fs20.readFileSync(file, "utf8");
@@ -22250,7 +22282,7 @@ var bashPattern = (entry) => {
22250
22282
  return match ? match[1] ?? "" : null;
22251
22283
  };
22252
22284
  function claudeRules(cwd, env = process.env) {
22253
- const rules = EMPTY();
22285
+ const rules = EMPTY2();
22254
22286
  try {
22255
22287
  for (const file of claudeSettingsFiles(cwd, env)) {
22256
22288
  const text = readText2(file);
@@ -22330,7 +22362,7 @@ var opencodeConfig = (value, rules) => {
22330
22362
  return Object.values(value.agent).every((agent) => isRecord4(agent) && opencodePermission(agent.permission, rules));
22331
22363
  };
22332
22364
  function opencodeRules(cwd, env = process.env) {
22333
- const rules = EMPTY();
22365
+ const rules = EMPTY2();
22334
22366
  try {
22335
22367
  const config = env.XDG_CONFIG_HOME || path27.join(homeOf(env), ".config");
22336
22368
  const files = [
@@ -22377,7 +22409,7 @@ var codexRule = (body) => {
22377
22409
  return { pattern: words.join(" "), decision };
22378
22410
  };
22379
22411
  function codexRules(cwd, env = process.env) {
22380
- const rules = EMPTY();
22412
+ const rules = EMPTY2();
22381
22413
  try {
22382
22414
  const home = env.CODEX_HOME || path27.join(homeOf(env), ".codex");
22383
22415
  const top = gitTop(cwd) ?? cwd;
@@ -22406,7 +22438,7 @@ function codexRules(cwd, env = process.env) {
22406
22438
  return rules;
22407
22439
  }
22408
22440
  function cursorRules(cwd, env = process.env) {
22409
- const rules = EMPTY();
22441
+ const rules = EMPTY2();
22410
22442
  try {
22411
22443
  const top = gitTop(cwd) ?? cwd;
22412
22444
  for (const file of [
@@ -23734,25 +23766,29 @@ var redChecks = (rows, pr, head, endpoint) => {
23734
23766
  reason: `PR #${pr}'s checks were last seen ${state} at ${short(head)}, and this workspace's endpoint is \`${endpoint}\`: run \`workit ci wait --pr ${pr}\`${state === "failing" ? " after fixing the failures `workit pr status` lists (then push)" : ""}.`
23735
23767
  };
23736
23768
  };
23737
- var highRisk = (cwd) => {
23769
+ var taskJudgment = (cwd) => {
23738
23770
  try {
23739
23771
  const store = new TaskStore(cwd);
23740
23772
  const listed = store.listTaskIndex();
23741
23773
  const key = store.currentKey();
23742
23774
  if (!listed.ok || !key.ok)
23743
- return false;
23775
+ return null;
23744
23776
  const entry = listed.data.filter((item) => item.key === key.data.key && item.status !== "closed").toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt))[0];
23745
23777
  const task = entry ? store.readTask(entry.id) : null;
23746
- return task?.ok === true && latestJudgment(task.data)?.riskTier === "high";
23778
+ return task?.ok === true ? latestJudgment(task.data) : null;
23747
23779
  } catch {
23748
- return false;
23780
+ return null;
23749
23781
  }
23750
23782
  };
23751
23783
  var unverified = (cwd, branch, all, descriptor, verification) => {
23752
23784
  const check = checkVerdicts(cwd, branch, all);
23753
23785
  if (check.accepted.accepted || check.accepted.reasons.includes("failing_verdict"))
23754
23786
  return null;
23755
- const independent = verification === "independent" || highRisk(cwd);
23787
+ const judgment = taskJudgment(cwd);
23788
+ const high = judgment?.riskTier === "high";
23789
+ if (judgment && !judgment.behaviorChange && !high)
23790
+ return null;
23791
+ const independent = verification === "independent" || high;
23756
23792
  if (!independent && check.review === "self-reviewed")
23757
23793
  return null;
23758
23794
  const has = check.review === "self-reviewed" ? "only a self verdict" : "no current verdict";
@@ -23823,7 +23859,7 @@ function stopDecision(input, descriptor) {
23823
23859
  if (file && marker) {
23824
23860
  if (marker.stops.includes(key))
23825
23861
  return NONE4;
23826
- writeSessionMarker(file, { ...marker, stops: [...marker.stops, key] });
23862
+ updateSessionMarker(file, (fresh) => ({ ...fresh, stops: [...fresh.stops, key] }));
23827
23863
  }
23828
23864
  return {
23829
23865
  kind: "continue",
@@ -25661,7 +25697,16 @@ ${nudge}` : content) };
25661
25697
  pi.on("session_compact_failed", () => {
25662
25698
  return;
25663
25699
  });
25664
- pi.on("tool_call", (event, ctx) => enforceToolPolicy(event, ctx));
25700
+ pi.on("tool_call", (event, ctx) => {
25701
+ try {
25702
+ return enforceToolPolicy(event, ctx);
25703
+ } catch (error) {
25704
+ const message = `hook failure: ${String(error)}`;
25705
+ process.stderr.write(`[workit] tool_call gate failed: ${message}
25706
+ `);
25707
+ return PI_DESCRIPTOR.shellPolicy.failClosed ? { block: true, reason: message } : undefined;
25708
+ }
25709
+ });
25665
25710
  pi.on("tool_result", (event, ctx) => {
25666
25711
  const observed = observeResult(event, ctx);
25667
25712
  let standing = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-pi",
3
- "version": "8.22.1",
3
+ "version": "8.22.2",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",