pi-braid 0.44.4 → 0.44.5
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 +29 -0
- package/build-info.json +4 -4
- package/dist/extensions/enforcement/handlers/register-adherence-meter.d.ts +24 -1
- package/dist/extensions/enforcement/handlers/register-adherence-meter.js +86 -30
- package/package.json +1 -1
- package/src/extensions/enforcement/handlers/register-adherence-meter.ts +92 -32
package/CHANGELOG.md
CHANGED
|
@@ -254,6 +254,35 @@ same fixture's last arm, which asserted the operator's home instead of what ever
|
|
|
254
254
|
now states the property it was meant to hold, that the shipped tree passes wherever the roots are. The tags
|
|
255
255
|
for 0.44.1 and 0.44.3 stay where they are, each with its failed run beside it.
|
|
256
256
|
|
|
257
|
+
## Core 0.44.5, Telegram 0.2.1: a label names the session, and the digest reads as a sentence (2026-11-15)
|
|
258
|
+
|
|
259
|
+
The identity line said `session unknown` on every message a seat sent. pi DELETES `PI_SESSION_ID`
|
|
260
|
+
from the environment it hands an extension and re-injects it only into bash children, so the label's
|
|
261
|
+
`process.env` read could never succeed, while the adherence digest beside it printed the real id from
|
|
262
|
+
the extension context. The session now comes from that context: the Telegram factory registers a
|
|
263
|
+
getter (`setIdentitySessionSource`) bound to the live `ExtensionContext` it already keeps for
|
|
264
|
+
`isIdle`, and the label prefers it to the environment, which stays the fallback the standalone
|
|
265
|
+
`node src/lib/identity.ts` command still has. The memo is keyed on the id the getter answers with, so
|
|
266
|
+
one session reads one line, a label rendered before the first `session_start` corrects itself, and a
|
|
267
|
+
reload inside one process relabels to the session that now sends.
|
|
268
|
+
|
|
269
|
+
The adherence digest was nine labelled lines, and the owner read it as a field dump. It is now one
|
|
270
|
+
thing that happened: a bold subject naming the rung and how many rules are in it, one sentence
|
|
271
|
+
carrying the counts and quoting the rule in full with the internal source token after it in
|
|
272
|
+
parentheses rather than in front, and one time stamp. Two fields are gone. The truncated session id,
|
|
273
|
+
because the message already opens with a label that names the session. The report path, because the
|
|
274
|
+
reader receives this on a chat client and the report is where the counts live, not somewhere to
|
|
275
|
+
navigate to. A digest that folded several crossings now says so and names how many, and a rule is no
|
|
276
|
+
longer clipped to 64 characters: a fragment of a regex told the owner nothing, and above the plain
|
|
277
|
+
cap the body carries the format the outbound gate asks for.
|
|
278
|
+
|
|
279
|
+
Both changes are fixes to what the owner sees, so both move a patch: core 0.44.5 and Telegram 0.2.1.
|
|
280
|
+
The new function is internal wiring between the package's own modules, not a documented command. The
|
|
281
|
+
three digest shapes are frozen in `packages/telegram/test/fixtures/adherence-digest-bodies.json`
|
|
282
|
+
because the two packages cannot import each other: the producer's fixture asserts the renderer emits
|
|
283
|
+
those lines, and the Telegram fixture pushes the same bytes through the gate and Telegram's own
|
|
284
|
+
parser.
|
|
285
|
+
|
|
257
286
|
## Core 0.44.0, Contrib 0.2.0, Providers 1.0.8 — the ruler gains eyes, and refusals learn to speak (2026-11-12)
|
|
258
287
|
|
|
259
288
|
`design_audit` could measure a rendered page and say nothing about whether it looked cheap. The same
|
package/build-info.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-braid",
|
|
3
|
-
"version": "0.44.
|
|
4
|
-
"sha": "
|
|
5
|
-
"shaShort": "
|
|
3
|
+
"version": "0.44.5",
|
|
4
|
+
"sha": "130129cea9f9bb2c6adad598f0bdc456b778cdd5",
|
|
5
|
+
"shaShort": "130129ce",
|
|
6
6
|
"branch": "detached",
|
|
7
7
|
"dirty": false,
|
|
8
|
-
"packedAt": "2026-11-
|
|
8
|
+
"packedAt": "2026-11-15T22:30:42.163Z"
|
|
9
9
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* report is read by nothing that composes the prompt.
|
|
22
22
|
*/
|
|
23
23
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
24
|
-
import { type AdherenceWriteResult } from "../../../lib/enforcement/adherence-meter.js";
|
|
24
|
+
import { type AdherenceWriteResult, type PendingEscalation } from "../../../lib/enforcement/adherence-meter.js";
|
|
25
25
|
/** What a crossing may ask the owner channel for. */
|
|
26
26
|
export interface AdherenceOwnerSender {
|
|
27
27
|
(text: string, opts?: {
|
|
@@ -50,6 +50,29 @@ export interface AdherenceWiringDeps {
|
|
|
50
50
|
reportDir?: string;
|
|
51
51
|
k?: number;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The hourly digest: one thing that happened, not a field dump. A bold subject
|
|
55
|
+
* names the rung and how many rules the message is about; one sentence carries
|
|
56
|
+
* the counts and the rule it quotes; one stamp says when.
|
|
57
|
+
*
|
|
58
|
+
* Two fields the labelled body carried are deliberately gone:
|
|
59
|
+
* - the truncated session id, because the message already opens with the
|
|
60
|
+
* identity label, and the label names the session the send belongs to
|
|
61
|
+
* (`lib/identity.ts`, telegram);
|
|
62
|
+
* - the report path. The report is where the counts live, not somewhere a
|
|
63
|
+
* reader navigates to from a chat client, so an operator path on the last
|
|
64
|
+
* line was one of the labelled fields the owner read as a dump.
|
|
65
|
+
*
|
|
66
|
+
* The rule is quoted in FULL, never clipped: a fragment of a regex told the
|
|
67
|
+
* owner nothing, and the outbound gate carries a formatted body rather than
|
|
68
|
+
* asking a sender to pre-chew its subject. The quietest honest count of the
|
|
69
|
+
* crossings it folded is stated in its own sentence, so a digest that carries
|
|
70
|
+
* several never reads like a single one.
|
|
71
|
+
*/
|
|
72
|
+
export declare function renderAdherenceDigest(digest: {
|
|
73
|
+
pending: PendingEscalation[];
|
|
74
|
+
suppressed: number;
|
|
75
|
+
}, nowMs: number): string;
|
|
53
76
|
/**
|
|
54
77
|
* Aggregate the current branch and fold every crossing into the owner's
|
|
55
78
|
* hourly digest.
|
|
@@ -29,7 +29,7 @@ import { getExtensionState, getSessionIdSafe, safeSessionManagerTyped, } from ".
|
|
|
29
29
|
import { getWatchdogTgSignalSender } from "../../../lib/state/global-state.js";
|
|
30
30
|
import { readTelegramPollerLiveness } from "../../../lib/state/telegram-poller-liveness.js";
|
|
31
31
|
import { formatLocalTime } from "../../../lib/utils/local-time.js";
|
|
32
|
-
import { activeBranchEntries,
|
|
32
|
+
import { activeBranchEntries, aggregateRuleAdherence, commitDigest, createEscalationState, planDigest, planEscalation, readSessionEntriesFromFile, recordEscalation, writeAdherenceReport, } from "../../../lib/enforcement/adherence-meter.js";
|
|
33
33
|
const log = createLogger("adherence-meter");
|
|
34
34
|
/** Extension-state bucket key for the per-session meter state. */
|
|
35
35
|
const ADHERENCE_STATE_KEY = "adherence-meter";
|
|
@@ -59,40 +59,96 @@ function branchEntries(ctx) {
|
|
|
59
59
|
function escapeHtml(text) {
|
|
60
60
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
/** The rule's matched text (the key's `source::pattern` tail), shortened. */
|
|
67
|
-
function ruleLabel(entry) {
|
|
68
|
-
const tail = entry.ruleKey.includes("::")
|
|
62
|
+
/** The rule's own text: the key is `source::body`, and the body is the rule. */
|
|
63
|
+
function ruleText(entry) {
|
|
64
|
+
const body = entry.ruleKey.includes("::")
|
|
69
65
|
? entry.ruleKey.split("::").slice(1).join("::")
|
|
70
66
|
: entry.ruleKey;
|
|
71
|
-
return
|
|
67
|
+
return body.trim();
|
|
68
|
+
}
|
|
69
|
+
/** Counts up to twenty in words; past that the numeral is the honest form. */
|
|
70
|
+
const COUNT_WORDS = [
|
|
71
|
+
"zero",
|
|
72
|
+
"one",
|
|
73
|
+
"two",
|
|
74
|
+
"three",
|
|
75
|
+
"four",
|
|
76
|
+
"five",
|
|
77
|
+
"six",
|
|
78
|
+
"seven",
|
|
79
|
+
"eight",
|
|
80
|
+
"nine",
|
|
81
|
+
"ten",
|
|
82
|
+
"eleven",
|
|
83
|
+
"twelve",
|
|
84
|
+
"thirteen",
|
|
85
|
+
"fourteen",
|
|
86
|
+
"fifteen",
|
|
87
|
+
"sixteen",
|
|
88
|
+
"seventeen",
|
|
89
|
+
"eighteen",
|
|
90
|
+
"nineteen",
|
|
91
|
+
"twenty",
|
|
92
|
+
];
|
|
93
|
+
function countWord(n) {
|
|
94
|
+
return Number.isInteger(n) && n >= 0 && n < COUNT_WORDS.length ? COUNT_WORDS[n] : String(n);
|
|
95
|
+
}
|
|
96
|
+
/** The same word, as the opening of a sentence. */
|
|
97
|
+
function sentenceCase(text) {
|
|
98
|
+
return text.length > 0 ? `${text[0].toUpperCase()}${text.slice(1)}` : text;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A rule body that already carries its own quoting is not quoted twice: the
|
|
102
|
+
* whisper bodies the meter counts open and close with quotation marks of their
|
|
103
|
+
* own.
|
|
104
|
+
*/
|
|
105
|
+
function quoted(text) {
|
|
106
|
+
const opens = /^["'“«]/.test(text);
|
|
107
|
+
const closes = /["'”»]$/.test(text);
|
|
108
|
+
return opens && closes ? text : `"${text}"`;
|
|
72
109
|
}
|
|
73
110
|
/**
|
|
74
|
-
* The hourly digest:
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
111
|
+
* The hourly digest: one thing that happened, not a field dump. A bold subject
|
|
112
|
+
* names the rung and how many rules the message is about; one sentence carries
|
|
113
|
+
* the counts and the rule it quotes; one stamp says when.
|
|
114
|
+
*
|
|
115
|
+
* Two fields the labelled body carried are deliberately gone:
|
|
116
|
+
* - the truncated session id, because the message already opens with the
|
|
117
|
+
* identity label, and the label names the session the send belongs to
|
|
118
|
+
* (`lib/identity.ts`, telegram);
|
|
119
|
+
* - the report path. The report is where the counts live, not somewhere a
|
|
120
|
+
* reader navigates to from a chat client, so an operator path on the last
|
|
121
|
+
* line was one of the labelled fields the owner read as a dump.
|
|
122
|
+
*
|
|
123
|
+
* The rule is quoted in FULL, never clipped: a fragment of a regex told the
|
|
124
|
+
* owner nothing, and the outbound gate carries a formatted body rather than
|
|
125
|
+
* asking a sender to pre-chew its subject. The quietest honest count of the
|
|
126
|
+
* crossings it folded is stated in its own sentence, so a digest that carries
|
|
127
|
+
* several never reads like a single one.
|
|
78
128
|
*/
|
|
79
|
-
function
|
|
80
|
-
// The subject is the highest rung in the digest
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
129
|
+
export function renderAdherenceDigest(digest, nowMs) {
|
|
130
|
+
// The subject is the rule at the highest rung in the digest. Among rules the
|
|
131
|
+
// ladder put on the same rung (it advances one rung per pass, so a tie is the
|
|
132
|
+
// ordinary case for a folded digest), the one with the most deliveries is the
|
|
133
|
+
// informative quote.
|
|
134
|
+
const subject = digest.pending.reduce((best, entry) => entry.milestone > best.milestone ||
|
|
135
|
+
(entry.milestone === best.milestone && entry.deliveries >= best.deliveries)
|
|
136
|
+
? entry
|
|
137
|
+
: best);
|
|
138
|
+
const crossings = digest.pending.length;
|
|
139
|
+
const ruleCount = new Set(digest.pending.map((entry) => entry.ruleKey)).size;
|
|
140
|
+
const rules = ruleCount === 1 ? "rule" : "rules";
|
|
141
|
+
const folded = crossings > 1
|
|
142
|
+
? sentenceCase(`${countWord(crossings)} crossings, from ${countWord(ruleCount)} ${rules}, ` +
|
|
143
|
+
`are reported together in this message. `)
|
|
144
|
+
: "";
|
|
145
|
+
return [
|
|
146
|
+
`<b>Adherence · rung ${subject.milestone} · ${countWord(ruleCount)} ${rules}</b>`,
|
|
147
|
+
`${folded}The rule ${escapeHtml(quoted(ruleText(subject)))} ` +
|
|
148
|
+
`(${escapeHtml(subject.source)}) has repeated ${subject.repeats} ` +
|
|
149
|
+
`times across ${subject.deliveries} deliveries.`,
|
|
90
150
|
`at ${formatLocalTime(new Date(nowMs))}`,
|
|
91
|
-
|
|
92
|
-
// per-rule counts live in the session report.
|
|
93
|
-
`where ${escapeHtml(shorten(adherenceReportPath(), 72))}`,
|
|
94
|
-
];
|
|
95
|
-
return lines.join("\n");
|
|
151
|
+
].join("\n");
|
|
96
152
|
}
|
|
97
153
|
/**
|
|
98
154
|
* Aggregate the current branch and fold every crossing into the owner's
|
|
@@ -151,7 +207,7 @@ export async function checkAdherence(ctx, deps = {}) {
|
|
|
151
207
|
let ok = false;
|
|
152
208
|
try {
|
|
153
209
|
ok =
|
|
154
|
-
(await Promise.resolve(sender(
|
|
210
|
+
(await Promise.resolve(sender(renderAdherenceDigest(digest, nowMs), {
|
|
155
211
|
parseMode: "HTML",
|
|
156
212
|
source: "adherence-digest",
|
|
157
213
|
suppressed: digest.suppressed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-braid",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.5",
|
|
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",
|
|
@@ -40,7 +40,6 @@ import { readTelegramPollerLiveness } from "../../../lib/state/telegram-poller-l
|
|
|
40
40
|
import { formatLocalTime } from "../../../lib/utils/local-time.js";
|
|
41
41
|
import {
|
|
42
42
|
activeBranchEntries,
|
|
43
|
-
adherenceReportPath,
|
|
44
43
|
aggregateRuleAdherence,
|
|
45
44
|
commitDigest,
|
|
46
45
|
createEscalationState,
|
|
@@ -121,48 +120,109 @@ function escapeHtml(text: string): string {
|
|
|
121
120
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** The rule's matched text (the key's `source::pattern` tail), shortened. */
|
|
130
|
-
function ruleLabel(entry: PendingEscalation): string {
|
|
131
|
-
const tail = entry.ruleKey.includes("::")
|
|
123
|
+
/** The rule's own text: the key is `source::body`, and the body is the rule. */
|
|
124
|
+
function ruleText(entry: PendingEscalation): string {
|
|
125
|
+
const body = entry.ruleKey.includes("::")
|
|
132
126
|
? entry.ruleKey.split("::").slice(1).join("::")
|
|
133
127
|
: entry.ruleKey;
|
|
134
|
-
return
|
|
128
|
+
return body.trim();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Counts up to twenty in words; past that the numeral is the honest form. */
|
|
132
|
+
const COUNT_WORDS = [
|
|
133
|
+
"zero",
|
|
134
|
+
"one",
|
|
135
|
+
"two",
|
|
136
|
+
"three",
|
|
137
|
+
"four",
|
|
138
|
+
"five",
|
|
139
|
+
"six",
|
|
140
|
+
"seven",
|
|
141
|
+
"eight",
|
|
142
|
+
"nine",
|
|
143
|
+
"ten",
|
|
144
|
+
"eleven",
|
|
145
|
+
"twelve",
|
|
146
|
+
"thirteen",
|
|
147
|
+
"fourteen",
|
|
148
|
+
"fifteen",
|
|
149
|
+
"sixteen",
|
|
150
|
+
"seventeen",
|
|
151
|
+
"eighteen",
|
|
152
|
+
"nineteen",
|
|
153
|
+
"twenty",
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
function countWord(n: number): string {
|
|
157
|
+
return Number.isInteger(n) && n >= 0 && n < COUNT_WORDS.length ? COUNT_WORDS[n] : String(n);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The same word, as the opening of a sentence. */
|
|
161
|
+
function sentenceCase(text: string): string {
|
|
162
|
+
return text.length > 0 ? `${text[0].toUpperCase()}${text.slice(1)}` : text;
|
|
135
163
|
}
|
|
136
164
|
|
|
137
165
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* gate validates it before any send).
|
|
166
|
+
* A rule body that already carries its own quoting is not quoted twice: the
|
|
167
|
+
* whisper bodies the meter counts open and close with quotation marks of their
|
|
168
|
+
* own.
|
|
142
169
|
*/
|
|
143
|
-
function
|
|
170
|
+
function quoted(text: string): string {
|
|
171
|
+
const opens = /^["'“«]/.test(text);
|
|
172
|
+
const closes = /["'”»]$/.test(text);
|
|
173
|
+
return opens && closes ? text : `"${text}"`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The hourly digest: one thing that happened, not a field dump. A bold subject
|
|
178
|
+
* names the rung and how many rules the message is about; one sentence carries
|
|
179
|
+
* the counts and the rule it quotes; one stamp says when.
|
|
180
|
+
*
|
|
181
|
+
* Two fields the labelled body carried are deliberately gone:
|
|
182
|
+
* - the truncated session id, because the message already opens with the
|
|
183
|
+
* identity label, and the label names the session the send belongs to
|
|
184
|
+
* (`lib/identity.ts`, telegram);
|
|
185
|
+
* - the report path. The report is where the counts live, not somewhere a
|
|
186
|
+
* reader navigates to from a chat client, so an operator path on the last
|
|
187
|
+
* line was one of the labelled fields the owner read as a dump.
|
|
188
|
+
*
|
|
189
|
+
* The rule is quoted in FULL, never clipped: a fragment of a regex told the
|
|
190
|
+
* owner nothing, and the outbound gate carries a formatted body rather than
|
|
191
|
+
* asking a sender to pre-chew its subject. The quietest honest count of the
|
|
192
|
+
* crossings it folded is stated in its own sentence, so a digest that carries
|
|
193
|
+
* several never reads like a single one.
|
|
194
|
+
*/
|
|
195
|
+
export function renderAdherenceDigest(
|
|
144
196
|
digest: { pending: PendingEscalation[]; suppressed: number },
|
|
145
|
-
ctx: ExtensionContext,
|
|
146
197
|
nowMs: number,
|
|
147
198
|
): string {
|
|
148
|
-
// The subject is the highest rung in the digest
|
|
199
|
+
// The subject is the rule at the highest rung in the digest. Among rules the
|
|
200
|
+
// ladder put on the same rung (it advances one rung per pass, so a tie is the
|
|
201
|
+
// ordinary case for a folded digest), the one with the most deliveries is the
|
|
202
|
+
// informative quote.
|
|
149
203
|
const subject = digest.pending.reduce((best, entry) =>
|
|
150
|
-
entry.milestone
|
|
204
|
+
entry.milestone > best.milestone ||
|
|
205
|
+
(entry.milestone === best.milestone && entry.deliveries >= best.deliveries)
|
|
206
|
+
? entry
|
|
207
|
+
: best,
|
|
151
208
|
);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
209
|
+
const crossings = digest.pending.length;
|
|
210
|
+
const ruleCount = new Set(digest.pending.map((entry) => entry.ruleKey)).size;
|
|
211
|
+
const rules = ruleCount === 1 ? "rule" : "rules";
|
|
212
|
+
const folded =
|
|
213
|
+
crossings > 1
|
|
214
|
+
? sentenceCase(
|
|
215
|
+
`${countWord(crossings)} crossings, from ${countWord(ruleCount)} ${rules}, ` +
|
|
216
|
+
`are reported together in this message. `,
|
|
217
|
+
)
|
|
218
|
+
: "";
|
|
219
|
+
return [
|
|
220
|
+
`<b>Adherence · rung ${subject.milestone} · ${countWord(ruleCount)} ${rules}</b>`,
|
|
221
|
+
`${folded}The rule ${escapeHtml(quoted(ruleText(subject)))} ` +
|
|
222
|
+
`(${escapeHtml(subject.source)}) has repeated ${subject.repeats} ` +
|
|
223
|
+
`times across ${subject.deliveries} deliveries.`,
|
|
160
224
|
`at ${formatLocalTime(new Date(nowMs))}`,
|
|
161
|
-
|
|
162
|
-
// per-rule counts live in the session report.
|
|
163
|
-
`where ${escapeHtml(shorten(adherenceReportPath(), 72))}`,
|
|
164
|
-
];
|
|
165
|
-
return lines.join("\n");
|
|
225
|
+
].join("\n");
|
|
166
226
|
}
|
|
167
227
|
|
|
168
228
|
/**
|
|
@@ -231,7 +291,7 @@ export async function checkAdherence(
|
|
|
231
291
|
try {
|
|
232
292
|
ok =
|
|
233
293
|
(await Promise.resolve(
|
|
234
|
-
sender(
|
|
294
|
+
sender(renderAdherenceDigest(digest, nowMs), {
|
|
235
295
|
parseMode: "HTML",
|
|
236
296
|
source: "adherence-digest",
|
|
237
297
|
suppressed: digest.suppressed,
|