pi-braid 0.43.23 → 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
@@ -80,6 +80,42 @@ record; the tag scheme above applies unchanged.
80
80
  contract; a new fixture covers both trees, the scoping and the absent-versus-empty
81
81
  populations.
82
82
 
83
+ ## Telegram — 0.1.8 (2026-11-04: a pre-identity lock is judged by its pid, so a dead holder cannot wedge the channel)
84
+
85
+ - **The legacy arm has three outcomes instead of a permanent refusal.** A lock
86
+ written before identity existed carries only a pid; the rule read its absent
87
+ heartbeat as "cannot judge" and refused forever, even when the holder had died.
88
+ A dead pid now acquires as `stale-legacy` and the takeover rewrites the record in
89
+ the identity shape, so the next seat never meets a legacy file.
90
+ - **A recycled pid is not the holder.** A live pid whose process started after the
91
+ record was written acquires as `stale-legacy-recycled`; the comparison is why the
92
+ channel cannot be wedged twice by the same defect, once when the holder dies and
93
+ once when the operating system hands its number to someone else.
94
+ - **The refusal that remains names the file and the way out.** `held-legacy` covers
95
+ a dated live pid and an undatable one, and the message carries the path and the
96
+ note that a clean disable releases it, because a refusal an operator cannot act on
97
+ is a support ticket.
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
+
113
+ ## Core — 0.43.24 (2026-11-04: carries the poller lock's legacy arm)
114
+
115
+ - **No core code changed.** The version moves so the tree's derived development
116
+ version sorts above `v0.43.23`, and the release that installs the Telegram fix also
117
+ carries the core packages at one version.
118
+
83
119
  ## Core — 0.43.23 (2026-11-04: 21 core skills declare their phrases where the matcher reads them)
84
120
 
85
121
  - **The core skill tree follows the contract it documents.** Of 23 skills, 21 moved
package/build-info.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pi-braid",
3
- "version": "0.43.23",
4
- "sha": "e63d33701040689c94aab6c50ebb067d5ef94df3",
5
- "shaShort": "e63d3370",
3
+ "version": "0.43.25",
4
+ "sha": "7aeba3aae0e1eee74da2330661e89f78161f0b66",
5
+ "shaShort": "7aeba3aa",
6
6
  "branch": "detached",
7
7
  "dirty": false,
8
- "packedAt": "2026-11-03T23:20:23.106Z"
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.23",
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;