pi-braid 0.43.24 → 0.43.25

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/CHANGELOG.md CHANGED
@@ -96,6 +96,20 @@ record; the tag scheme above applies unchanged.
96
96
  note that a clean disable releases it, because a refusal an operator cannot act on
97
97
  is a support ticket.
98
98
 
99
+ ## Core — 0.43.25 (2026-11-04: the context backstop leaves a countable trace)
100
+
101
+ - **The 0.90W backstop records that it fired.** The site called the drain and
102
+ wrote nothing, so "how often does it fire in real sessions" had no instrument
103
+ and could not be answered at all. Each fire now appends one line to
104
+ `metrics/context-backstop.jsonl` with the token count, the window, the derived
105
+ ratio and the session.
106
+ - **The write cannot break a turn.** A counter that throws inside the turn_end
107
+ pipeline would trade a measurable claim for a torn request, so the append is
108
+ wrapped and an uncounted fire is the failure mode.
109
+ - **The fixture asserts the trace, not the intent.** The existing backstop case
110
+ now requires exactly one line per fire and checks the ratio against the
111
+ recorded tokens; removing the call reddens it.
112
+
99
113
  ## Core — 0.43.24 (2026-11-04: carries the poller lock's legacy arm)
100
114
 
101
115
  - **No core code changed.** The version moves so the tree's derived development
package/build-info.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pi-braid",
3
- "version": "0.43.24",
4
- "sha": "e1d647e5b1e0c9367bd49bcde72e3a316c908250",
5
- "shaShort": "e1d647e5",
3
+ "version": "0.43.25",
4
+ "sha": "7aeba3aae0e1eee74da2330661e89f78161f0b66",
5
+ "shaShort": "7aeba3aa",
6
6
  "branch": "detached",
7
7
  "dirty": false,
8
- "packedAt": "2026-11-04T17:19:52.861Z"
8
+ "packedAt": "2026-11-05T05:46:15.761Z"
9
9
  }
@@ -12,6 +12,8 @@
12
12
  * - "deep_clean" meta-action: tag + archive + compact in one call
13
13
  */
14
14
  import { Type } from "typebox";
15
+ import { appendFileSync, mkdirSync } from "node:fs";
16
+ import { join } from "node:path";
15
17
  import { getExtensionState, readExtensionState } from "../../../../../lib/state/extension-state.js";
16
18
  import { onEvent } from "../../../../../lib/events/event-types.js";
17
19
  import { TOOL_EXECUTION_START, TOOL_EXECUTION_END, AGENT_SETTLED, TURN_END, } from "../../../../../lib/core/event-names.js";
@@ -19,6 +21,7 @@ import { analyzeSession } from "../../analysis.js";
19
21
  import * as timerMod from "../../../../scheduling/timer/index.js";
20
22
  import { getState } from "../../../../enforcement/state.js";
21
23
  import { CONTEXT_COMPACT_REFUSE_PERCENT } from "../../../../../lib/detection/context-thresholds.js";
24
+ import { metricsDir } from "../../../../../lib/config/braid-paths.js";
22
25
  import { getCmState, isCompactionActive, log, recordNavigationAction } from "../shared.js";
23
26
  import { snapBoundaryOutsideToolBatch } from "../tool-batch-boundary.js";
24
27
  import { formatTokensK, tokenArms } from "../../../../../lib/detection/context-usage.js";
@@ -58,6 +61,32 @@ function captureUsage(ctx) {
58
61
  return null;
59
62
  }
60
63
  }
64
+ /**
65
+ * One line per backstop fire.
66
+ *
67
+ * The backstop fired silently, so "how often does it fire in real sessions" was
68
+ * not answerable from any log: the site only called the drain. A JSON line makes
69
+ * the question countable (wc -l on the file, or any reader over it), and the
70
+ * write is wrapped because a counter that can break a turn is worse than an
71
+ * uncounted fire.
72
+ */
73
+ function recordBackstopFire(usage) {
74
+ try {
75
+ const dir = metricsDir();
76
+ mkdirSync(dir, { recursive: true });
77
+ appendFileSync(join(dir, "context-backstop.jsonl"), `${JSON.stringify({
78
+ at: new Date().toISOString(),
79
+ event: "backstop-fire",
80
+ tokens: usage.tokens,
81
+ contextWindow: usage.contextWindow,
82
+ ratio: Number((usage.tokens / usage.contextWindow).toFixed(4)),
83
+ session: process.env.PI_SESSION_ID ?? null,
84
+ })}\n`);
85
+ }
86
+ catch {
87
+ // Uncounted is better than a torn turn.
88
+ }
89
+ }
61
90
  // Blank optional selectors.
62
91
  //
63
92
  // Some clients emit every schema property and send "" for the ones they do
@@ -550,6 +579,7 @@ export function registerContextCompress(pi) {
550
579
  const usage = captureUsage(ctx);
551
580
  if (!usage || usage.tokens < tokenArms(usage.contextWindow).backstop)
552
581
  return;
582
+ recordBackstopFire(usage);
553
583
  firePendingCompactionsIfSettled(ctx, st);
554
584
  }
555
585
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-braid",
3
- "version": "0.43.24",
3
+ "version": "0.43.25",
4
4
  "description": "🥨 Braid - Metacognitive extension suite for pi coding agent: Adds memory, plan tracking, structured cognitive signals and completion checks on top of pi core loop, so long sessions keep their context and stop claiming unfinished work.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,6 +13,8 @@
13
13
  */
14
14
 
15
15
  import { Type } from "typebox";
16
+ import { appendFileSync, mkdirSync } from "node:fs";
17
+ import { join } from "node:path";
16
18
  import type { CompactOptions, ExtensionAPI } from "@earendil-works/pi-coding-agent";
17
19
  import { getExtensionState, readExtensionState } from "../../../../../lib/state/extension-state.js";
18
20
  import { onEvent } from "../../../../../lib/events/event-types.js";
@@ -26,6 +28,7 @@ import { analyzeSession } from "../../analysis.js";
26
28
  import * as timerMod from "../../../../scheduling/timer/index.js";
27
29
  import { getState } from "../../../../enforcement/state.js";
28
30
  import { CONTEXT_COMPACT_REFUSE_PERCENT } from "../../../../../lib/detection/context-thresholds.js";
31
+ import { metricsDir } from "../../../../../lib/config/braid-paths.js";
29
32
  import { getCmState, isCompactionActive, log, recordNavigationAction } from "../shared.js";
30
33
  import { snapBoundaryOutsideToolBatch } from "../tool-batch-boundary.js";
31
34
  import { formatTokensK, tokenArms } from "../../../../../lib/detection/context-usage.js";
@@ -68,6 +71,35 @@ function captureUsage(ctx: any): { percent: number; tokens: number; contextWindo
68
71
  }
69
72
  }
70
73
 
74
+ /**
75
+ * One line per backstop fire.
76
+ *
77
+ * The backstop fired silently, so "how often does it fire in real sessions" was
78
+ * not answerable from any log: the site only called the drain. A JSON line makes
79
+ * the question countable (wc -l on the file, or any reader over it), and the
80
+ * write is wrapped because a counter that can break a turn is worse than an
81
+ * uncounted fire.
82
+ */
83
+ function recordBackstopFire(usage: { tokens: number; contextWindow: number }): void {
84
+ try {
85
+ const dir = metricsDir();
86
+ mkdirSync(dir, { recursive: true });
87
+ appendFileSync(
88
+ join(dir, "context-backstop.jsonl"),
89
+ `${JSON.stringify({
90
+ at: new Date().toISOString(),
91
+ event: "backstop-fire",
92
+ tokens: usage.tokens,
93
+ contextWindow: usage.contextWindow,
94
+ ratio: Number((usage.tokens / usage.contextWindow).toFixed(4)),
95
+ session: process.env.PI_SESSION_ID ?? null,
96
+ })}\n`,
97
+ );
98
+ } catch {
99
+ // Uncounted is better than a torn turn.
100
+ }
101
+ }
102
+
71
103
  // Blank optional selectors.
72
104
  //
73
105
  // Some clients emit every schema property and send "" for the ones they do
@@ -676,6 +708,7 @@ export function registerContextCompress(pi: ExtensionAPI): void {
676
708
  if (isCompactionActive(ctx)) return;
677
709
  const usage = captureUsage(ctx);
678
710
  if (!usage || usage.tokens < tokenArms(usage.contextWindow).backstop) return;
711
+ recordBackstopFire(usage);
679
712
  firePendingCompactionsIfSettled(ctx, st);
680
713
  } catch {
681
714
  // A failed backstop check must not tear the turn_end event pipeline;