pi-braid 0.43.5 → 0.43.7

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 (26) hide show
  1. package/CHANGELOG.md +95 -7
  2. package/build-info.json +4 -4
  3. package/dist/extensions/core/prompt-builder/surface-discipline-section.d.ts +1 -1
  4. package/dist/extensions/core/prompt-builder/surface-discipline-section.js +1 -1
  5. package/dist/extensions/core/skills-tool/applicability.d.ts +134 -0
  6. package/dist/extensions/core/skills-tool/applicability.js +161 -0
  7. package/dist/extensions/core/skills-tool/auto-inject.d.ts +10 -0
  8. package/dist/extensions/core/skills-tool/auto-inject.js +216 -1
  9. package/dist/extensions/core/skills-tool/index.js +64 -3
  10. package/dist/extensions/core/skills-tool/loading-guidance.js +2 -1
  11. package/dist/extensions/core/skills-tool/session-records.d.ts +297 -8
  12. package/dist/extensions/core/skills-tool/session-records.js +509 -5
  13. package/dist/extensions/core/skills-tool/skill-families.d.ts +60 -0
  14. package/dist/extensions/core/skills-tool/skill-families.js +105 -0
  15. package/dist/extensions/orchestrator/index.js +11 -1
  16. package/docs/LOCAL_DEV.md +1 -1
  17. package/package.json +1 -1
  18. package/src/extensions/core/AGENTS.md +1 -0
  19. package/src/extensions/core/prompt-builder/surface-discipline-section.ts +1 -1
  20. package/src/extensions/core/skills-tool/applicability.ts +220 -0
  21. package/src/extensions/core/skills-tool/auto-inject.ts +274 -0
  22. package/src/extensions/core/skills-tool/index.ts +75 -2
  23. package/src/extensions/core/skills-tool/loading-guidance.ts +2 -1
  24. package/src/extensions/core/skills-tool/session-records.ts +740 -5
  25. package/src/extensions/core/skills-tool/skill-families.ts +112 -0
  26. package/src/extensions/orchestrator/index.ts +13 -1
@@ -1,8 +1,18 @@
1
1
  /**
2
- * Durable per-session skill-adoption records + monthly adoption rollup.
2
+ * Durable per-session skill records + the monthly adoption rollup.
3
3
  *
4
- * Every session that reaches an agent turn gets ONE logical record:
5
- * { sessionId, role, month, hadSkillLoad, updatedAt }
4
+ * The store is one append-only JSONL file with three record kinds, told apart
5
+ * by `kind`:
6
+ *
7
+ * (absent) an ADOPTION record, the older shape:
8
+ * { sessionId, role, month, hadSkillLoad, updatedAt }
9
+ * "applicability" an APPLICABILITY record: the session's skill verdicts
10
+ * (see ApplicabilityRecord)
11
+ * "obligation" an OBLIGATION record: one skill's legs in one session
12
+ * (see ObligationLegRecord)
13
+ *
14
+ * An adoption record exists for every session that reaches an agent turn, so
15
+ * every such session gets ONE logical record (the rollup denominator);
6
16
  * `role` carries the session's profile name from the braid config (see
7
17
  * lib/config/session-profiles.ts), or the neutral default when no profile
8
18
  * matches; `month` is the local-time "YYYY-MM" of the write, and
@@ -22,6 +32,13 @@
22
32
  * filesystems; the tolerant reader skips unparseable lines, the window is
23
33
  * a single small write, and this is accepted as best-effort telemetry.
24
34
  *
35
+ * Each reader reads its own kind and ignores the others. The adoption reader
36
+ * is fail-closed on an unknown `kind`, so a record type added later cannot
37
+ * enter the adoption numbers by looking enough like one; and a build that
38
+ * predates the applicability kind reads those lines as adoption records of
39
+ * the same session, which folds to the same numbers because it carries no
40
+ * new sessions and never sets `hadSkillLoad`.
41
+ *
25
42
  * Back-compat: records written before profiles existed carry a role from
26
43
  * the retired fixed set; those values pass the profile-name gate
27
44
  * unchanged, so older buckets keep folding under their original names.
@@ -30,6 +47,7 @@
30
47
  */
31
48
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
32
49
  import { type ResolvedSessionProfile } from "../../../lib/config/session-profiles.js";
50
+ import type { ApplicabilityEvidence, SkillApplicabilityVerdict } from "./applicability.js";
33
51
  /** One durable per-session adoption record (a single JSONL line on disk). */
34
52
  export interface SkillSessionRecord {
35
53
  /** pi session id (from ctx.sessionManager.getSessionId()). */
@@ -59,11 +77,7 @@ export declare function foldSessionRecords(records: SkillSessionRecord[]): Skill
59
77
  * throws); corrupt lines are skipped.
60
78
  */
61
79
  export declare function readSessionRecords(storePath: string): SkillSessionRecord[];
62
- /**
63
- * Append one record. Best-effort: every error is swallowed (this runs on
64
- * the agent-loop and tool-result paths — a telemetry failure must never
65
- * break a turn). Returns true when the line landed on disk.
66
- */
80
+ /** Append one adoption record (see appendLine for the failure contract). */
67
81
  export declare function appendSessionRecord(record: SkillSessionRecord, storePath: string): boolean;
68
82
  /**
69
83
  * The session's effective profile, resolved from the braid config on first
@@ -82,6 +96,281 @@ export declare function recordSessionStart(ctx: ExtensionContext, storePath?: st
82
96
  * numerator of the adoption rate). Claims must NOT route here.
83
97
  */
84
98
  export declare function recordSessionSkillLoad(ctx: ExtensionContext, storePath?: string): void;
99
+ /**
100
+ * One skill's applicability verdict for one session.
101
+ *
102
+ * The three classes, as this instrument names them:
103
+ *
104
+ * not-applicable the skill's own declared condition did not meet the
105
+ * session's task text. Derived, never a row: the census's
106
+ * `evaluated` minus the verdict rows. A row per non-match
107
+ * would multiply every session's record by the installed
108
+ * catalog to say "nothing here".
109
+ * ignored the condition held and no detected read followed. This is
110
+ * the class the adoption counters cannot express.
111
+ * read the condition held and a detected SKILL.md read followed.
112
+ *
113
+ * `undeclared` sits outside all three: those skill files state no condition, so
114
+ * no verdict about them is honest (see applicability.ts).
115
+ */
116
+ /** One verdict row: the skill, its class, and the phrases that decided it. */
117
+ export interface ApplicabilityVerdictRecord {
118
+ kind: "applicability";
119
+ sessionId: string;
120
+ role: string;
121
+ month: string;
122
+ updatedAt: string;
123
+ /** The skill this row answers for. */
124
+ skill: string;
125
+ /** read | ignored — a row exists only where a condition held. */
126
+ applicability: "read" | "ignored";
127
+ evidence: ApplicabilityEvidence[];
128
+ }
129
+ /**
130
+ * One session's census row: how much task text was read, how many skills
131
+ * declared a condition, and which ones declared none. Written once per
132
+ * session, so `not-applicable` is derivable without a row per non-match.
133
+ */
134
+ export interface ApplicabilityCensusRecord {
135
+ kind: "applicability";
136
+ sessionId: string;
137
+ role: string;
138
+ month: string;
139
+ updatedAt: string;
140
+ /** Characters of task text the first evaluation read. */
141
+ taskChars: number;
142
+ /** Installed skills declaring at least one condition phrase. */
143
+ evaluated: number;
144
+ /** Installed skills whose files declare no condition phrase. */
145
+ undeclared: string[];
146
+ }
147
+ /**
148
+ * An applicability record. The two shapes share the kind and the session
149
+ * identity, and a reader tells them apart by `skill`: a row with one answers
150
+ * for that skill, a row without one is the session's census. The split is what
151
+ * lets a per-skill record join the sibling compliance record on
152
+ * (sessionId, skill) without either store learning the other's fields.
153
+ */
154
+ export type ApplicabilityRecord = ApplicabilityVerdictRecord | ApplicabilityCensusRecord;
155
+ /** A session's applicability after folding every record written for it. */
156
+ export interface SessionApplicability {
157
+ sessionId: string;
158
+ role: string;
159
+ month: string;
160
+ updatedAt: string;
161
+ /** Characters of task text the census read. */
162
+ taskChars: number;
163
+ /** Skills that declared a condition. */
164
+ evaluated: number;
165
+ /** Skills that declared none — the blind spot, named. */
166
+ undeclared: string[];
167
+ /** One entry per applicable skill, `read` beating `ignored`. */
168
+ verdicts: SkillApplicabilityVerdict[];
169
+ /** The three classes as counts: read + ignored = applicable. */
170
+ classes: {
171
+ read: number;
172
+ ignored: number;
173
+ notApplicable: number;
174
+ };
175
+ }
176
+ /**
177
+ * Read the applicability records from the store. Missing or unreadable file →
178
+ * empty (never throws); non-applicability and corrupt lines are skipped.
179
+ */
180
+ export declare function readApplicabilityRecords(storePath: string): ApplicabilityRecord[];
181
+ /**
182
+ * Fold the store into one logical record per sessionId: the newest census wins
183
+ * the session facts, verdict rows union across writes with `read` beating
184
+ * `ignored`. Pure. The fold is what makes a torn, duplicated or out-of-order
185
+ * append harmless: the record set, not the line order, decides a verdict.
186
+ */
187
+ export declare function foldApplicabilityRecords(records: ApplicabilityRecord[]): SessionApplicability[];
188
+ /** Fields a caller supplies for the session's census row. */
189
+ export interface ApplicabilityCensusInput {
190
+ taskChars: number;
191
+ evaluated: number;
192
+ undeclared: string[];
193
+ }
194
+ /**
195
+ * Append the session's census row. Best-effort like every other writer here: a
196
+ * false return means the line did not land, never a thrown turn.
197
+ */
198
+ export declare function recordApplicabilityCensus(ctx: ExtensionContext, census: ApplicabilityCensusInput, storePath?: string): boolean;
199
+ /**
200
+ * Append one skill's verdict row. The same function writes the `read` upgrade:
201
+ * the fold decides, so no line is ever rewritten.
202
+ */
203
+ export declare function recordApplicabilityVerdict(ctx: ExtensionContext, verdict: {
204
+ skill: string;
205
+ applicability: "read" | "ignored";
206
+ evidence: ApplicabilityEvidence[];
207
+ }, storePath?: string): boolean;
208
+ /**
209
+ * The folded applicability record for the context's own session, or undefined
210
+ * when the session wrote none. Reader: a refused path or a torn store is a
211
+ * miss, not a throw.
212
+ */
213
+ export declare function getSessionApplicability(ctx: ExtensionContext, options?: {
214
+ storePath?: string;
215
+ }): SessionApplicability | undefined;
216
+ /**
217
+ * One skill's legs in one session: what the instrument saw happen to the body
218
+ * an obligation names.
219
+ *
220
+ * These are facts about reads and calls, not verdicts. `read` here means a
221
+ * DETECTED SKILL.md read, and it is deliberately not the applicability record's
222
+ * `applicability: "read"` class — that one is a verdict about a skill whose
223
+ * declared condition held, and the applicability record refuses to classify a
224
+ * read whose condition never held. This record states the read and leaves the
225
+ * verdict where it belongs.
226
+ *
227
+ * `called` and `applied` are the applied leg, and they are the reason the
228
+ * record exists:
229
+ * called a tool call in a family this skill declares happened this
230
+ * session, whatever the call's outcome — a refusal fires before the
231
+ * call and cannot know the result.
232
+ * applied the FIRST such call came after a detected read of this body.
233
+ *
234
+ * The pair is decided once, at the first call, because that is the only moment
235
+ * the ordering exists: a later read followed by a later call must not turn an
236
+ * earlier violation into satisfaction. Both stay false when the skill declares
237
+ * no family; most declare none, and an obligation that names no family is
238
+ * satisfied by the read alone.
239
+ *
240
+ * `suggested` and `listed` are the surfaces that made the body findable in
241
+ * this session (a delivered suggestion, a list_skills row); they carry the
242
+ * "was it offered" half of adoption, which the call facts cannot.
243
+ */
244
+ export interface ObligationLegRecord {
245
+ kind: "obligation";
246
+ sessionId: string;
247
+ role: string;
248
+ month: string;
249
+ updatedAt: string;
250
+ skill: string;
251
+ suggested: boolean;
252
+ listed: boolean;
253
+ read: boolean;
254
+ called: boolean;
255
+ applied: boolean;
256
+ }
257
+ /** A record's five legs, read back as one row per skill. */
258
+ export interface ObligationLegs {
259
+ skill: string;
260
+ suggested: boolean;
261
+ listed: boolean;
262
+ read: boolean;
263
+ called: boolean;
264
+ applied: boolean;
265
+ }
266
+ /** One session's obligation rows, folded. */
267
+ export interface SessionObligation {
268
+ sessionId: string;
269
+ role: string;
270
+ month: string;
271
+ updatedAt: string;
272
+ /** One row per skill seen, in first-seen order. */
273
+ skills: ObligationLegs[];
274
+ }
275
+ /** Normalize a parsed JSON line into an obligation record, or null. */
276
+ export declare function normalizeObligationRecord(raw: unknown): ObligationLegRecord | null;
277
+ /**
278
+ * Read the obligation records from the store. Missing or unreadable file →
279
+ * empty (never throws); other kinds and corrupt lines are skipped.
280
+ */
281
+ export declare function readObligationRecords(storePath?: string): ObligationLegRecord[];
282
+ /**
283
+ * Fold a session's obligation rows into one record: the five legs OR across
284
+ * every row, so a row that saw one leg never erases a leg a later row did not
285
+ * have. `called`/`applied` are written once per skill, so the OR is exact
286
+ * rather than convenient. A torn or duplicated row folds; a malformed one is
287
+ * dropped at normalize, before this sees it.
288
+ */
289
+ export declare function foldObligationRecords(records: ObligationLegRecord[]): SessionObligation[];
290
+ /**
291
+ * Append one skill's legs. Best-effort like the sibling writer: a refused or
292
+ * missing store returns false so the caller can retry on a later turn.
293
+ */
294
+ export declare function recordObligationLegs(ctx: ExtensionContext, legs: ObligationLegs, storePath?: string): boolean;
295
+ /** The current session's obligation rows, folded. Missing store → undefined. */
296
+ export declare function getSessionObligation(ctx: ExtensionContext, options?: {
297
+ storePath?: string;
298
+ }): SessionObligation | undefined;
299
+ /**
300
+ * An obligation is satisfied when the body was read AND, if the session ever
301
+ * called into a family the skill declares, that the first call came after the
302
+ * read. Without a declared family the second clause is vacuous: reading the
303
+ * body is the whole obligation.
304
+ */
305
+ export declare function obligationSatisfied(legs: ObligationLegs): boolean;
306
+ /** One judged skill: its legs, plus whether it was even an obligation. */
307
+ export interface JudgedSkill extends ObligationLegs {
308
+ /** null when the skill's declared condition never held: no obligation. */
309
+ satisfied: boolean | null;
310
+ }
311
+ /** A session's judgement: every leg it recorded, and the session boolean. */
312
+ export interface SessionJudgement {
313
+ skills: JudgedSkill[];
314
+ allSatisfied: boolean;
315
+ /** Obligations that applied (leg rows whose condition held). */
316
+ obligations: number;
317
+ }
318
+ /**
319
+ * Judge one session against its obligation rows. Pure.
320
+ *
321
+ * A skill is an obligation when the applicability fold carries a verdict for
322
+ * it: the previous record's question was whether the skill applied, and this
323
+ * one takes that answer as given. An obligation is decided by this record's
324
+ * legs alone, which is why the two kinds can be folded independently and
325
+ * joined on (sessionId, skill) without either re-reading the other.
326
+ */
327
+ export declare function judgeSessionObligations(applicable: SessionApplicability | undefined, obligation: SessionObligation | undefined): SessionJudgement | undefined;
328
+ /**
329
+ * The design's own decision rule: a gap this small makes the rate a duplicate
330
+ * of the read rate, and a duplicate should be deleted rather than shipped.
331
+ */
332
+ export declare const FALSIFIER_GAP_POINTS = 5;
333
+ /**
334
+ * The two rates and their shared denominator.
335
+ *
336
+ * `sessions` is the population both rates are divided by: sessions with at
337
+ * least one obligation that applied AND at least one obligation row, i.e. the
338
+ * sessions this build's instrument saw. A session whose applicable verdicts
339
+ * predate the instrument is counted in `uninstrumented` instead of scored as
340
+ * unsatisfied — a zero the instrument did not observe is not a zero it found.
341
+ *
342
+ * `readRate` is the older measurement restricted to this population: a session
343
+ * counts when ANY detected read landed in it, which is the adoption counter's
344
+ * own definition (`actual > 0`), so the difference between the two numbers is
345
+ * the satisfaction criterion and nothing else.
346
+ */
347
+ export interface ObligationRate {
348
+ sessions: number;
349
+ allSatisfied: number;
350
+ /** 0-1, rounded to 4 decimals (a percentage point is 2 of these). */
351
+ allSatisfiedRate: number;
352
+ withRead: number;
353
+ readRate: number;
354
+ /** allSatisfiedRate - readRate, in percentage points, 2 decimals. */
355
+ gapPoints: number;
356
+ /** Obligations that applied, across the population. */
357
+ obligations: number;
358
+ unsatisfied: number;
359
+ /** False when the gap is under FALSIFIER_GAP_POINTS: the metric is a copy. */
360
+ discriminating: boolean;
361
+ /** Sessions with an applicable skill but no obligation row: not scored. */
362
+ uninstrumented: number;
363
+ }
364
+ /** Compute both rates over one store's folds. Pure. */
365
+ export declare function computeObligationRate(sessions: SessionApplicability[], obligations: SessionObligation[]): ObligationRate;
366
+ /**
367
+ * The store-wide rate, or undefined when the store carries no obligation row
368
+ * at all. Undefined is the absent record: a reader of a store this build has
369
+ * not written to sees the payload it always saw, byte for byte.
370
+ */
371
+ export declare function getObligationRate(options?: {
372
+ storePath?: string;
373
+ }): ObligationRate | undefined;
85
374
  /** Adoption numbers for one profile in one month. */
86
375
  export interface ProfileAdoption {
87
376
  /** Sessions active in the month (records with a turn). */