@wrongstack/tools 0.295.0 → 0.295.1

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 (48) hide show
  1. package/dist/auto-proceed-loop-guard.d.ts +31 -0
  2. package/dist/auto-proceed-loop-guard.d.ts.map +1 -1
  3. package/dist/auto-proceed-loop-guard.js +24 -1
  4. package/dist/auto-proceed-loop-guard.js.map +2 -2
  5. package/dist/bash.js +39 -23
  6. package/dist/bash.js.map +2 -2
  7. package/dist/builtin.js +278 -109
  8. package/dist/builtin.js.map +4 -4
  9. package/dist/codebase-index/generic-parser.d.ts.map +1 -1
  10. package/dist/codebase-index/index.js +48 -47
  11. package/dist/codebase-index/index.js.map +2 -2
  12. package/dist/codebase-index/indexer.d.ts.map +1 -1
  13. package/dist/codebase-index/worker.js +48 -47
  14. package/dist/codebase-index/worker.js.map +2 -2
  15. package/dist/codebase-index/writer.d.ts.map +1 -1
  16. package/dist/exec.js +39 -23
  17. package/dist/exec.js.map +2 -2
  18. package/dist/glob.d.ts.map +1 -1
  19. package/dist/glob.js +80 -30
  20. package/dist/glob.js.map +4 -4
  21. package/dist/grep.d.ts.map +1 -1
  22. package/dist/grep.js +87 -20
  23. package/dist/grep.js.map +4 -4
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +281 -109
  27. package/dist/index.js.map +4 -4
  28. package/dist/kanban-evidence-bridge.d.ts +21 -0
  29. package/dist/kanban-evidence-bridge.d.ts.map +1 -0
  30. package/dist/kanban.d.ts +17 -1
  31. package/dist/kanban.d.ts.map +1 -1
  32. package/dist/kanban.js +164 -7
  33. package/dist/kanban.js.map +3 -3
  34. package/dist/pack.js +278 -109
  35. package/dist/pack.js.map +4 -4
  36. package/dist/process-registry-persistent.d.ts.map +1 -1
  37. package/dist/ps-slash.js +39 -23
  38. package/dist/ps-slash.js.map +2 -2
  39. package/dist/tool-tier.js +278 -109
  40. package/dist/tool-tier.js.map +4 -4
  41. package/dist/tree.d.ts.map +1 -1
  42. package/dist/tree.js +2 -14
  43. package/dist/tree.js.map +2 -2
  44. package/dist/win32.d.ts +10 -0
  45. package/dist/win32.d.ts.map +1 -0
  46. package/dist/win32.js +67 -0
  47. package/dist/win32.js.map +7 -0
  48. package/package.json +7 -3
@@ -86,6 +86,27 @@ export interface RepetitionSignal {
86
86
  */
87
87
  shouldHalt: boolean;
88
88
  }
89
+ /**
90
+ * Steer text appended (once) to a grounded todo continuation when the board
91
+ * has not moved between two consecutive automatic turns. Grounded prompts are
92
+ * synthesized from durable todo state, so an identical re-feed means the whole
93
+ * previous turn produced zero board movement — usually the model worked but
94
+ * forgot to update the board. One explicit steer fixes that far more often
95
+ * than halting; the halt only fires if the board stays frozen AFTER the steer.
96
+ */
97
+ export declare const GROUNDED_NO_PROGRESS_STEER: string;
98
+ export type GroundedRepetitionAction = 'feed' | 'steer' | 'halt';
99
+ export interface GroundedRepetitionSignal extends RepetitionSignal {
100
+ /**
101
+ * What the caller should do with this grounded (todo-sourced) prompt:
102
+ * - `feed` — no repetition; feed the prompt as-is.
103
+ * - `steer` — first repetition; feed the prompt with
104
+ * {@link GROUNDED_NO_PROGRESS_STEER} appended instead of halting.
105
+ * - `halt` — the board stayed frozen even after a steer; break the loop
106
+ * exactly like a `shouldHalt` from {@link AutoProceedLoopGuard.record}.
107
+ */
108
+ action: GroundedRepetitionAction;
109
+ }
89
110
  export interface AutoProceedLoopGuard {
90
111
  /**
91
112
  * Record a prompt that is about to be auto-fed. Returns the repetition
@@ -94,6 +115,16 @@ export interface AutoProceedLoopGuard {
94
115
  * the loop must be broken instead.
95
116
  */
96
117
  record(prompt: string): RepetitionSignal;
118
+ /**
119
+ * Record a GROUNDED prompt — one synthesized from durable state (the todo
120
+ * board) rather than echoed from model output. Repetition of a grounded
121
+ * prompt is a "no board progress" signal, not necessarily an echo loop, so
122
+ * the first repetition asks the caller to steer (append
123
+ * {@link GROUNDED_NO_PROGRESS_STEER} to the fed text) and only a repetition
124
+ * that survives the steer halts. The steer state resets whenever a
125
+ * different prompt is recorded (board moved) or on {@link reset}.
126
+ */
127
+ recordGrounded(prompt: string): GroundedRepetitionSignal;
97
128
  /**
98
129
  * Drop the history. Call this on any manual user input so a fresh run
99
130
  * starts with no memory of the prior cycle.
@@ -1 +1 @@
1
- {"version":3,"file":"auto-proceed-loop-guard.d.ts","sourceRoot":"","sources":["../src/auto-proceed-loop-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACzC;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;;;OAIG;IACH,OAAO,IAAI,SAAS,MAAM,EAAE,CAAC;IAC7B;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,gBAAqB,GAAG,oBAAoB,CAmD/F"}
1
+ {"version":3,"file":"auto-proceed-loop-guard.d.ts","sourceRoot":"","sources":["../src/auto-proceed-loop-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,QAO3B,CAAC;AAEb,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjE,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE;;;;;;;OAOG;IACH,MAAM,EAAE,wBAAwB,CAAC;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACzC;;;;;;;;OAQG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAAC;IACzD;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;;;OAIG;IACH,OAAO,IAAI,SAAS,MAAM,EAAE,CAAC;IAC7B;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,gBAAqB,GAAG,oBAAoB,CAqE/F"}
@@ -2,6 +2,14 @@
2
2
  function normalizeForRepetition(prompt) {
3
3
  return prompt.replace(/\s+/g, " ").trim().toLowerCase();
4
4
  }
5
+ var GROUNDED_NO_PROGRESS_STEER = [
6
+ "NOTE: The todo board has not changed since the previous automatic continuation \u2014 this exact instruction is being repeated.",
7
+ "Before anything else, bring the board up to date so the loop stays grounded:",
8
+ "- mark work that is actually finished as completed,",
9
+ "- split the current item into smaller concrete sub-items if it needs more than one turn,",
10
+ "- remove or reword items that no longer apply.",
11
+ "Then continue the work. If you are blocked, state exactly what is blocking you instead of repeating the same turn."
12
+ ].join("\n");
5
13
  function createAutoProceedLoopGuard(options = {}) {
6
14
  const safeIntegerOption = (value, fallback) => {
7
15
  if (value === void 0) return fallback;
@@ -11,6 +19,7 @@ function createAutoProceedLoopGuard(options = {}) {
11
19
  const repeatThreshold = Math.max(2, safeIntegerOption(options.repeatThreshold, 2));
12
20
  const windowSize = Math.max(repeatThreshold, safeIntegerOption(options.windowSize, 3));
13
21
  let buffer = [];
22
+ let steeredFor = null;
14
23
  function record(prompt) {
15
24
  const normalized = normalizeForRepetition(prompt);
16
25
  buffer.push(normalized);
@@ -28,8 +37,21 @@ function createAutoProceedLoopGuard(options = {}) {
28
37
  shouldHalt: runLength >= repeatThreshold
29
38
  };
30
39
  }
40
+ function recordGrounded(prompt) {
41
+ const signal = record(prompt);
42
+ if (!signal.shouldHalt) {
43
+ steeredFor = null;
44
+ return { ...signal, shouldHalt: false, action: "feed" };
45
+ }
46
+ if (steeredFor === signal.normalized) {
47
+ return { ...signal, action: "halt" };
48
+ }
49
+ steeredFor = signal.normalized;
50
+ return { ...signal, shouldHalt: false, action: "steer" };
51
+ }
31
52
  function reset() {
32
53
  buffer = [];
54
+ steeredFor = null;
33
55
  }
34
56
  function history() {
35
57
  return buffer.slice();
@@ -37,9 +59,10 @@ function createAutoProceedLoopGuard(options = {}) {
37
59
  function size() {
38
60
  return buffer.length;
39
61
  }
40
- return { record, reset, history, size };
62
+ return { record, recordGrounded, reset, history, size };
41
63
  }
42
64
  export {
65
+ GROUNDED_NO_PROGRESS_STEER,
43
66
  createAutoProceedLoopGuard,
44
67
  normalizeForRepetition
45
68
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/auto-proceed-loop-guard.ts"],
4
- "sourcesContent": ["/**\n * Auto-proceed loop guard.\n *\n * ## Problem\n *\n * The REPL and TUI both implement an \"auto\" autonomy mode that, after every\n * completed agent turn, feeds the next suggestion (or top auto=\"true\" item)\n * back as a fresh prompt. When the agent emits the same `<nextsteps>` block\n * on every reply \u2014 which happens whenever the model's output is stable but\n * autonomy treats the next step as \"still actionable\" \u2014 the loop self-feeds\n * the same instruction 2\u20133 times in a row before the longer\n * `autoProceedMaxIterations` cap (default 50) trips.\n *\n * The user reports the visible symptom: the same response, including the same\n * `<nextsteps>` block, repeats. Manual input from the user is the only thing\n * that breaks out. They suspect the next-steps mechanism is the source.\n *\n * The 50-iteration cap is intentionally loose \u2014 it is a runaway safety net,\n * not a UX signal. By the time it trips, the user has already watched the\n * same response 50 times.\n *\n * ## Approach\n *\n * A small, pure, browser-safe stateful helper that records the last few\n * prompts fed through the auto-proceed / auto-submit path. It normalizes\n * prompts (whitespace, casing) so trivial rewordings are not collapsed, but\n * identical re-feeds are. When the same normalized prompt is fed\n * `repeatThreshold` (default 2) times in a row, the guard returns\n * `{ shouldHalt: true }`.\n *\n * Callers are expected to:\n * 1. Call `record(prompt)` immediately before each auto-feed.\n * 2. If `shouldHalt` is true, clear the suggestion + auto-suggestion store,\n * cancel any pending countdown, and surface a \"we detected a loop\"\n * message asking the user what's happening. Do NOT feed the prompt.\n * 3. Call `reset()` whenever the user types anything manually (REPL manual\n * input or any user-driven submit) so the next auto-feed starts clean.\n *\n * The default `repeatThreshold` is 2 \u2014 i.e. the second consecutive identical\n * feed (the first re-feed of an already-seen prompt) halts the loop. That\n * matches the user's report (\"receiving the same prompt 2-3 times in a row\n * causes the system to enter a loop\"). Setting it to 2 catches the loop on\n * the first identical re-feed rather than after the 50-iteration runaway cap trips.\n *\n * The window size is intentionally small (default 3). The loop we care about\n * is the immediate repetition \u2014 a longer history would misfire on legitimate\n * \"do X, then do Y, then do X\" sequences the model occasionally returns to.\n *\n * This module is BROWSER-SAFE \u2014 no Node-only imports \u2014 so it can be imported\n * from Vite-bundled WebUI as well as Node-based CLI/TUI.\n */\n\n/**\n * Normalize a prompt for repetition comparison. Whitespace is collapsed and\n * trimmed; case is folded to lowercase. Nothing semantic is removed, so two\n * prompts that differ in any meaningful way (extra word, different code,\n * different file path) compare as distinct. Two prompts that differ only by\n * leading/trailing whitespace and casing are treated as identical.\n */\nexport function normalizeForRepetition(prompt: string): string {\n return prompt.replace(/\\s+/g, ' ').trim().toLowerCase();\n}\n\nexport interface LoopGuardOptions {\n /**\n * How many consecutive identical prompts (after normalization) trigger a\n * halt. Default 2 \u2014 i.e. the second consecutive identical feed (the first\n * re-feed of an already-seen prompt) halts the loop. Clamped to >= 2.\n */\n repeatThreshold?: number;\n /**\n * How many of the most recent feeds to retain for comparison. The window\n * is searched from newest to oldest; the guard cares about the run of\n * identical entries ending at the most recent one, not about identical\n * entries anywhere in history. Default 3.\n */\n windowSize?: number;\n}\n\nexport interface RepetitionSignal {\n /** The normalized prompt that just got recorded. */\n normalized: string;\n /**\n * Number of consecutive identical feeds ending at the most recent feed,\n * including this one. Always >= 1.\n */\n runLength: number;\n /**\n * True when the run length has crossed `repeatThreshold`. Callers must\n * stop feeding and surface a user prompt instead.\n */\n shouldHalt: boolean;\n}\n\nexport interface AutoProceedLoopGuard {\n /**\n * Record a prompt that is about to be auto-fed. Returns the repetition\n * signal for that prompt. When `shouldHalt` is true the caller MUST NOT\n * feed the prompt \u2014 it has been recorded for post-mortem inspection, but\n * the loop must be broken instead.\n */\n record(prompt: string): RepetitionSignal;\n /**\n * Drop the history. Call this on any manual user input so a fresh run\n * starts with no memory of the prior cycle.\n */\n reset(): void;\n /**\n * Read-only view of the most recent normalized prompts (newest last).\n * Useful for diagnostics and for the message shown to the user when the\n * guard halts the loop.\n */\n history(): readonly string[];\n /**\n * How many entries the guard is currently retaining.\n */\n size(): number;\n}\n\n/**\n * Build a fresh loop guard. Defaults: `repeatThreshold = 2`, `windowSize = 3`.\n *\n * @example\n * const guard = createAutoProceedLoopGuard();\n * for (const prompt of candidates) {\n * const signal = guard.record(prompt);\n * if (signal.shouldHalt) {\n * haltAutoProceedAndAskUser(signal);\n * break;\n * }\n * feedPrompt(prompt);\n * }\n */\nexport function createAutoProceedLoopGuard(options: LoopGuardOptions = {}): AutoProceedLoopGuard {\n // Validate options defensively. Non-finite values (NaN, Infinity) MUST\n // fall back to the documented default \u2014 a guard that silently disables\n // itself is worse than no guard at all. Specifically:\n // - `repeatThreshold: NaN` would cause `Math.floor(NaN) = NaN`,\n // `Math.max(2, NaN) = NaN`, and `runLength >= NaN` is always false,\n // making the guard permanent no-op.\n // - `windowSize: NaN` / `Infinity` would skip the trim branch entirely\n // (`buffer.length > NaN` and `buffer.length > Infinity` are both\n // false), so the buffer would grow without bound.\n const safeIntegerOption = (value: number | undefined, fallback: number): number => {\n if (value === undefined) return fallback;\n if (!Number.isFinite(value)) return fallback;\n return Math.floor(value);\n };\n const repeatThreshold = Math.max(2, safeIntegerOption(options.repeatThreshold, 2));\n const windowSize = Math.max(repeatThreshold, safeIntegerOption(options.windowSize, 3));\n let buffer: string[] = [];\n\n function record(prompt: string): RepetitionSignal {\n const normalized = normalizeForRepetition(prompt);\n buffer.push(normalized);\n if (buffer.length > windowSize) {\n buffer = buffer.slice(buffer.length - windowSize);\n }\n // Count the trailing run of identical normalized prompts.\n let runLength = 0;\n for (let i = buffer.length - 1; i >= 0; i--) {\n if (buffer[i] === normalized) runLength++;\n else break;\n }\n return {\n normalized,\n runLength,\n shouldHalt: runLength >= repeatThreshold,\n };\n }\n\n function reset(): void {\n buffer = [];\n }\n\n function history(): readonly string[] {\n return buffer.slice();\n }\n\n function size(): number {\n return buffer.length;\n }\n\n return { record, reset, history, size };\n}\n"],
5
- "mappings": ";AA2DO,SAAS,uBAAuB,QAAwB;AAC7D,SAAO,OAAO,QAAQ,QAAQ,GAAG,EAAE,KAAK,EAAE,YAAY;AACxD;AAwEO,SAAS,2BAA2B,UAA4B,CAAC,GAAyB;AAU/F,QAAM,oBAAoB,CAAC,OAA2B,aAA6B;AACjF,QAAI,UAAU,OAAW,QAAO;AAChC,QAAI,CAAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AACA,QAAM,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,QAAQ,iBAAiB,CAAC,CAAC;AACjF,QAAM,aAAa,KAAK,IAAI,iBAAiB,kBAAkB,QAAQ,YAAY,CAAC,CAAC;AACrF,MAAI,SAAmB,CAAC;AAExB,WAAS,OAAO,QAAkC;AAChD,UAAM,aAAa,uBAAuB,MAAM;AAChD,WAAO,KAAK,UAAU;AACtB,QAAI,OAAO,SAAS,YAAY;AAC9B,eAAS,OAAO,MAAM,OAAO,SAAS,UAAU;AAAA,IAClD;AAEA,QAAI,YAAY;AAChB,aAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,UAAI,OAAO,CAAC,MAAM,WAAY;AAAA,UACzB;AAAA,IACP;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,YAAY,aAAa;AAAA,IAC3B;AAAA,EACF;AAEA,WAAS,QAAc;AACrB,aAAS,CAAC;AAAA,EACZ;AAEA,WAAS,UAA6B;AACpC,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,WAAS,OAAe;AACtB,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,EAAE,QAAQ,OAAO,SAAS,KAAK;AACxC;",
4
+ "sourcesContent": ["/**\n * Auto-proceed loop guard.\n *\n * ## Problem\n *\n * The REPL and TUI both implement an \"auto\" autonomy mode that, after every\n * completed agent turn, feeds the next suggestion (or top auto=\"true\" item)\n * back as a fresh prompt. When the agent emits the same `<nextsteps>` block\n * on every reply \u2014 which happens whenever the model's output is stable but\n * autonomy treats the next step as \"still actionable\" \u2014 the loop self-feeds\n * the same instruction 2\u20133 times in a row before the longer\n * `autoProceedMaxIterations` cap (default 50) trips.\n *\n * The user reports the visible symptom: the same response, including the same\n * `<nextsteps>` block, repeats. Manual input from the user is the only thing\n * that breaks out. They suspect the next-steps mechanism is the source.\n *\n * The 50-iteration cap is intentionally loose \u2014 it is a runaway safety net,\n * not a UX signal. By the time it trips, the user has already watched the\n * same response 50 times.\n *\n * ## Approach\n *\n * A small, pure, browser-safe stateful helper that records the last few\n * prompts fed through the auto-proceed / auto-submit path. It normalizes\n * prompts (whitespace, casing) so trivial rewordings are not collapsed, but\n * identical re-feeds are. When the same normalized prompt is fed\n * `repeatThreshold` (default 2) times in a row, the guard returns\n * `{ shouldHalt: true }`.\n *\n * Callers are expected to:\n * 1. Call `record(prompt)` immediately before each auto-feed.\n * 2. If `shouldHalt` is true, clear the suggestion + auto-suggestion store,\n * cancel any pending countdown, and surface a \"we detected a loop\"\n * message asking the user what's happening. Do NOT feed the prompt.\n * 3. Call `reset()` whenever the user types anything manually (REPL manual\n * input or any user-driven submit) so the next auto-feed starts clean.\n *\n * The default `repeatThreshold` is 2 \u2014 i.e. the second consecutive identical\n * feed (the first re-feed of an already-seen prompt) halts the loop. That\n * matches the user's report (\"receiving the same prompt 2-3 times in a row\n * causes the system to enter a loop\"). Setting it to 2 catches the loop on\n * the first identical re-feed rather than after the 50-iteration runaway cap trips.\n *\n * The window size is intentionally small (default 3). The loop we care about\n * is the immediate repetition \u2014 a longer history would misfire on legitimate\n * \"do X, then do Y, then do X\" sequences the model occasionally returns to.\n *\n * This module is BROWSER-SAFE \u2014 no Node-only imports \u2014 so it can be imported\n * from Vite-bundled WebUI as well as Node-based CLI/TUI.\n */\n\n/**\n * Normalize a prompt for repetition comparison. Whitespace is collapsed and\n * trimmed; case is folded to lowercase. Nothing semantic is removed, so two\n * prompts that differ in any meaningful way (extra word, different code,\n * different file path) compare as distinct. Two prompts that differ only by\n * leading/trailing whitespace and casing are treated as identical.\n */\nexport function normalizeForRepetition(prompt: string): string {\n return prompt.replace(/\\s+/g, ' ').trim().toLowerCase();\n}\n\nexport interface LoopGuardOptions {\n /**\n * How many consecutive identical prompts (after normalization) trigger a\n * halt. Default 2 \u2014 i.e. the second consecutive identical feed (the first\n * re-feed of an already-seen prompt) halts the loop. Clamped to >= 2.\n */\n repeatThreshold?: number;\n /**\n * How many of the most recent feeds to retain for comparison. The window\n * is searched from newest to oldest; the guard cares about the run of\n * identical entries ending at the most recent one, not about identical\n * entries anywhere in history. Default 3.\n */\n windowSize?: number;\n}\n\nexport interface RepetitionSignal {\n /** The normalized prompt that just got recorded. */\n normalized: string;\n /**\n * Number of consecutive identical feeds ending at the most recent feed,\n * including this one. Always >= 1.\n */\n runLength: number;\n /**\n * True when the run length has crossed `repeatThreshold`. Callers must\n * stop feeding and surface a user prompt instead.\n */\n shouldHalt: boolean;\n}\n\n/**\n * Steer text appended (once) to a grounded todo continuation when the board\n * has not moved between two consecutive automatic turns. Grounded prompts are\n * synthesized from durable todo state, so an identical re-feed means the whole\n * previous turn produced zero board movement \u2014 usually the model worked but\n * forgot to update the board. One explicit steer fixes that far more often\n * than halting; the halt only fires if the board stays frozen AFTER the steer.\n */\nexport const GROUNDED_NO_PROGRESS_STEER = [\n 'NOTE: The todo board has not changed since the previous automatic continuation \u2014 this exact instruction is being repeated.',\n 'Before anything else, bring the board up to date so the loop stays grounded:',\n '- mark work that is actually finished as completed,',\n '- split the current item into smaller concrete sub-items if it needs more than one turn,',\n '- remove or reword items that no longer apply.',\n 'Then continue the work. If you are blocked, state exactly what is blocking you instead of repeating the same turn.',\n].join('\\n');\n\nexport type GroundedRepetitionAction = 'feed' | 'steer' | 'halt';\n\nexport interface GroundedRepetitionSignal extends RepetitionSignal {\n /**\n * What the caller should do with this grounded (todo-sourced) prompt:\n * - `feed` \u2014 no repetition; feed the prompt as-is.\n * - `steer` \u2014 first repetition; feed the prompt with\n * {@link GROUNDED_NO_PROGRESS_STEER} appended instead of halting.\n * - `halt` \u2014 the board stayed frozen even after a steer; break the loop\n * exactly like a `shouldHalt` from {@link AutoProceedLoopGuard.record}.\n */\n action: GroundedRepetitionAction;\n}\n\nexport interface AutoProceedLoopGuard {\n /**\n * Record a prompt that is about to be auto-fed. Returns the repetition\n * signal for that prompt. When `shouldHalt` is true the caller MUST NOT\n * feed the prompt \u2014 it has been recorded for post-mortem inspection, but\n * the loop must be broken instead.\n */\n record(prompt: string): RepetitionSignal;\n /**\n * Record a GROUNDED prompt \u2014 one synthesized from durable state (the todo\n * board) rather than echoed from model output. Repetition of a grounded\n * prompt is a \"no board progress\" signal, not necessarily an echo loop, so\n * the first repetition asks the caller to steer (append\n * {@link GROUNDED_NO_PROGRESS_STEER} to the fed text) and only a repetition\n * that survives the steer halts. The steer state resets whenever a\n * different prompt is recorded (board moved) or on {@link reset}.\n */\n recordGrounded(prompt: string): GroundedRepetitionSignal;\n /**\n * Drop the history. Call this on any manual user input so a fresh run\n * starts with no memory of the prior cycle.\n */\n reset(): void;\n /**\n * Read-only view of the most recent normalized prompts (newest last).\n * Useful for diagnostics and for the message shown to the user when the\n * guard halts the loop.\n */\n history(): readonly string[];\n /**\n * How many entries the guard is currently retaining.\n */\n size(): number;\n}\n\n/**\n * Build a fresh loop guard. Defaults: `repeatThreshold = 2`, `windowSize = 3`.\n *\n * @example\n * const guard = createAutoProceedLoopGuard();\n * for (const prompt of candidates) {\n * const signal = guard.record(prompt);\n * if (signal.shouldHalt) {\n * haltAutoProceedAndAskUser(signal);\n * break;\n * }\n * feedPrompt(prompt);\n * }\n */\nexport function createAutoProceedLoopGuard(options: LoopGuardOptions = {}): AutoProceedLoopGuard {\n // Validate options defensively. Non-finite values (NaN, Infinity) MUST\n // fall back to the documented default \u2014 a guard that silently disables\n // itself is worse than no guard at all. Specifically:\n // - `repeatThreshold: NaN` would cause `Math.floor(NaN) = NaN`,\n // `Math.max(2, NaN) = NaN`, and `runLength >= NaN` is always false,\n // making the guard permanent no-op.\n // - `windowSize: NaN` / `Infinity` would skip the trim branch entirely\n // (`buffer.length > NaN` and `buffer.length > Infinity` are both\n // false), so the buffer would grow without bound.\n const safeIntegerOption = (value: number | undefined, fallback: number): number => {\n if (value === undefined) return fallback;\n if (!Number.isFinite(value)) return fallback;\n return Math.floor(value);\n };\n const repeatThreshold = Math.max(2, safeIntegerOption(options.repeatThreshold, 2));\n const windowSize = Math.max(repeatThreshold, safeIntegerOption(options.windowSize, 3));\n let buffer: string[] = [];\n // Normalized grounded prompt we already steered for; a halt only fires for\n // a grounded prompt that repeats again AFTER its steer.\n let steeredFor: string | null = null;\n\n function record(prompt: string): RepetitionSignal {\n const normalized = normalizeForRepetition(prompt);\n buffer.push(normalized);\n if (buffer.length > windowSize) {\n buffer = buffer.slice(buffer.length - windowSize);\n }\n // Count the trailing run of identical normalized prompts.\n let runLength = 0;\n for (let i = buffer.length - 1; i >= 0; i--) {\n if (buffer[i] === normalized) runLength++;\n else break;\n }\n return {\n normalized,\n runLength,\n shouldHalt: runLength >= repeatThreshold,\n };\n }\n\n function recordGrounded(prompt: string): GroundedRepetitionSignal {\n const signal = record(prompt);\n if (!signal.shouldHalt) {\n // The board moved (different prompt) \u2014 clear any pending steer state.\n steeredFor = null;\n return { ...signal, shouldHalt: false, action: 'feed' };\n }\n if (steeredFor === signal.normalized) {\n return { ...signal, action: 'halt' };\n }\n steeredFor = signal.normalized;\n return { ...signal, shouldHalt: false, action: 'steer' };\n }\n\n function reset(): void {\n buffer = [];\n steeredFor = null;\n }\n\n function history(): readonly string[] {\n return buffer.slice();\n }\n\n function size(): number {\n return buffer.length;\n }\n\n return { record, recordGrounded, reset, history, size };\n}\n"],
5
+ "mappings": ";AA2DO,SAAS,uBAAuB,QAAwB;AAC7D,SAAO,OAAO,QAAQ,QAAQ,GAAG,EAAE,KAAK,EAAE,YAAY;AACxD;AAyCO,IAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,IAAI;AAiEJ,SAAS,2BAA2B,UAA4B,CAAC,GAAyB;AAU/F,QAAM,oBAAoB,CAAC,OAA2B,aAA6B;AACjF,QAAI,UAAU,OAAW,QAAO;AAChC,QAAI,CAAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AACA,QAAM,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,QAAQ,iBAAiB,CAAC,CAAC;AACjF,QAAM,aAAa,KAAK,IAAI,iBAAiB,kBAAkB,QAAQ,YAAY,CAAC,CAAC;AACrF,MAAI,SAAmB,CAAC;AAGxB,MAAI,aAA4B;AAEhC,WAAS,OAAO,QAAkC;AAChD,UAAM,aAAa,uBAAuB,MAAM;AAChD,WAAO,KAAK,UAAU;AACtB,QAAI,OAAO,SAAS,YAAY;AAC9B,eAAS,OAAO,MAAM,OAAO,SAAS,UAAU;AAAA,IAClD;AAEA,QAAI,YAAY;AAChB,aAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,UAAI,OAAO,CAAC,MAAM,WAAY;AAAA,UACzB;AAAA,IACP;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,YAAY,aAAa;AAAA,IAC3B;AAAA,EACF;AAEA,WAAS,eAAe,QAA0C;AAChE,UAAM,SAAS,OAAO,MAAM;AAC5B,QAAI,CAAC,OAAO,YAAY;AAEtB,mBAAa;AACb,aAAO,EAAE,GAAG,QAAQ,YAAY,OAAO,QAAQ,OAAO;AAAA,IACxD;AACA,QAAI,eAAe,OAAO,YAAY;AACpC,aAAO,EAAE,GAAG,QAAQ,QAAQ,OAAO;AAAA,IACrC;AACA,iBAAa,OAAO;AACpB,WAAO,EAAE,GAAG,QAAQ,YAAY,OAAO,QAAQ,QAAQ;AAAA,EACzD;AAEA,WAAS,QAAc;AACrB,aAAS,CAAC;AACV,iBAAa;AAAA,EACf;AAEA,WAAS,UAA6B;AACpC,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,WAAS,OAAe;AACtB,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,EAAE,QAAQ,gBAAgB,OAAO,SAAS,KAAK;AACxD;",
6
6
  "names": []
7
7
  }
package/dist/bash.js CHANGED
@@ -825,6 +825,7 @@ function emitStructuredLog(level, event, message, error) {
825
825
  }
826
826
  var HEARTBEAT_INTERVAL_MS = 5e3;
827
827
  var STALE_THRESHOLD_MS = 3e4;
828
+ var LOCK_STALE_MS = 3e4;
828
829
  var LOCKFILE = ".process-registry.lock";
829
830
  function generateInstanceId() {
830
831
  const hostname2 = os2.hostname();
@@ -853,21 +854,26 @@ async function acquireLock(lockfilePath, timeoutMs = 5e3) {
853
854
  try {
854
855
  const content = await fs.readFile(lockfilePath, "utf-8");
855
856
  const parts = content.split(":");
856
- const lockPidStr = parts[0] ?? "0";
857
- const lockPid = parseInt(lockPidStr, 10);
858
- if (process.platform !== "win32") {
857
+ const lockPid = parseInt(parts[0] ?? "0", 10);
858
+ const lockTs = Number(parts[parts.length - 1]);
859
+ const staleByAge = Number.isFinite(lockTs) && Date.now() - lockTs > LOCK_STALE_MS;
860
+ let holderDead = false;
861
+ if (process.platform !== "win32" && Number.isFinite(lockPid) && lockPid > 0) {
859
862
  try {
860
863
  process.kill(lockPid, 0);
861
864
  } catch {
862
- await fs.unlink(lockfilePath);
863
- continue;
865
+ holderDead = true;
864
866
  }
865
867
  }
866
- } catch {
867
- try {
868
- await fs.unlink(lockfilePath);
869
- } catch {
868
+ if (holderDead || staleByAge) {
869
+ await fs.unlink(lockfilePath).catch(() => {
870
+ });
871
+ continue;
870
872
  }
873
+ } catch {
874
+ await fs.unlink(lockfilePath).catch(() => {
875
+ });
876
+ continue;
871
877
  }
872
878
  await new Promise((r) => setTimeout(r, 100));
873
879
  continue;
@@ -877,25 +883,35 @@ async function acquireLock(lockfilePath, timeoutMs = 5e3) {
877
883
  }
878
884
  throw new Error(`Failed to acquire lock after ${timeoutMs}ms`);
879
885
  }
886
+ function freshRegistryData() {
887
+ return {
888
+ version: 1,
889
+ instances: /* @__PURE__ */ new Map(),
890
+ protectedPatterns: ["wrongstack", "node"],
891
+ lastCleanup: Date.now()
892
+ };
893
+ }
880
894
  async function readRegistryFile(filePath) {
895
+ let content;
881
896
  try {
882
- const content = await fs.readFile(filePath, "utf-8");
883
- const parsed = JSON.parse(content);
884
- if (parsed.instances && Array.isArray(parsed.instances)) {
885
- parsed.instances = new Map(parsed.instances);
886
- }
887
- return parsed;
897
+ content = await fs.readFile(filePath, "utf-8");
888
898
  } catch (err) {
889
- if (isNodeError(err) && err.code === "ENOENT") {
890
- return {
891
- version: 1,
892
- instances: /* @__PURE__ */ new Map(),
893
- protectedPatterns: ["wrongstack", "node"],
894
- lastCleanup: Date.now()
895
- };
896
- }
899
+ if (isNodeError(err) && err.code === "ENOENT") return freshRegistryData();
897
900
  throw err;
898
901
  }
902
+ try {
903
+ const parsed = JSON.parse(content);
904
+ if (!parsed || typeof parsed !== "object") return freshRegistryData();
905
+ const base = freshRegistryData();
906
+ return {
907
+ version: 1,
908
+ instances: Array.isArray(parsed.instances) ? new Map(parsed.instances) : base.instances,
909
+ protectedPatterns: Array.isArray(parsed.protectedPatterns) ? parsed.protectedPatterns : base.protectedPatterns,
910
+ lastCleanup: typeof parsed.lastCleanup === "number" ? parsed.lastCleanup : base.lastCleanup
911
+ };
912
+ } catch {
913
+ return freshRegistryData();
914
+ }
899
915
  }
900
916
  async function writeRegistryFile(filePath, data) {
901
917
  const tmpPath = `${filePath}.tmp.${process.pid}`;