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
package/CHANGELOG.md CHANGED
@@ -33,16 +33,104 @@ stay core history and no longer occupy a sibling's release name: past a bare
33
33
 
34
34
  ## Repository history
35
35
 
36
- `main` carries a single consolidated commit as of the 2026-10-12 consolidation.
37
- The per-iteration series it replaces (380 commits) is kept outside this
38
- repository, in a local-only ref (`refs/archive/main-pre-squash`) plus an
39
- all-refs bundle; a public clone has the consolidated commit only, so a checkout
40
- that needs line history needs access to that local archive. This file and
41
- [`packages/core/docs/HISTORY.md`](packages/core/docs/HISTORY.md) are the
42
- reader-facing record; the tag scheme above applies unchanged.
36
+ `main` is a linear history above the tag line described above; `git rev-list --count main` states how
37
+ many commits it holds.
38
+
39
+ Two rewrites are visible to anyone holding an older clone, and both preserved content byte for byte:
40
+
41
+ - the 2026-10-12 consolidation replaced the per-iteration series (380 commits) with one consolidated
42
+ commit; that series is kept outside this repository, in a local-only ref
43
+ (`refs/archive/main-pre-squash`) plus an all-refs bundle, so a public clone has the consolidated line
44
+ only;
45
+ - the 2026-10-29 subject rewrite changed 16 commit messages and nothing else: the generated
46
+ `Merge branch '<internal branch name>'` subjects became the subject of the commit that landed, and two
47
+ older hand-written subjects lost a prefix. Every tree hash is unchanged and the tags were re-pointed,
48
+ so fetching this history can report a forced update. Packed artifacts from releases before it name a
49
+ `build-info` commit from the old history, and that commit no longer resolves here.
50
+
51
+ This file and [`packages/core/docs/HISTORY.md`](packages/core/docs/HISTORY.md) are the reader-facing
52
+ record; the tag scheme above applies unchanged.
43
53
 
44
54
  ---
45
55
 
56
+ ## Core — 0.43.7 (2026-10-30: an ignored skill is visible, and two rates say whether the obligation held)
57
+
58
+ - **A skill that applied and was ignored is now distinguishable from one that never applied.** The
59
+ subsystem could tell whether an agent read a skill and could not tell whether it should have. It now
60
+ records, per session and per skill, a verdict with the phrase that decided it and where the skill
61
+ declares it: `read`, `ignored`, or `not-applicable`, plus a census row naming the installed skills whose
62
+ files declare no condition at all. The record is additive by construction: a new record kind on the
63
+ existing store, refused by the adoption reader so the two cannot silently merge, and an existing
64
+ reader's output is byte-identical when the record is absent. `ignored` over `read + ignored` is the
65
+ rate nobody could compute before, and it is computable from the record alone.
66
+ - **The condition is the author's own declaration, not a coincidence.** Applicability reads the trigger
67
+ phrases the injector already matches, with the injector's own word-boundary rule, so the verdict can
68
+ never disagree with the whisper about whether a phrase is present; 1,098 phrase/text pairs over both
69
+ installed packs were checked for that agreement. The addition is polarity: "do not research this" is a
70
+ session where research did not apply. The negation rule is one cue, not a composed one, so a double
71
+ negative reads as negation and the ignored rate is a lower bound; that is pinned by a test with its
72
+ reason rather than left as a surprise.
73
+ - **A skill declares the tool family its body directs, and the session records what it did with it.** Three
74
+ of the shipped skills declare a family, five declare none because a body that governs no tool family
75
+ genuinely has none, and the contract reports both numbers rather than padding the count. The per-session
76
+ leg records `suggested`, `listed`, `read`, `called`, `applied`, where `applied` is ordered: a call made
77
+ before the read cannot be credited, and a read with no call still satisfies. An applicable skill with no
78
+ leg row is counted unsatisfied rather than dropped, which keeps the ignored population inside the
79
+ denominator.
80
+ - **The obligation rate ships with its own falsifier.** `allSatisfied` over the sessions that carry both a
81
+ verdict and a leg row, reported beside the read rate with that denominator stated rather than implied,
82
+ and a gap below five points marks the metric as non-discriminating. On a constructed population the two
83
+ rates separate three satisfied sessions from four that all read, so the number distinguishes what it
84
+ claims to.
85
+ - **The label vocabulary refuses both spellings on both surfaces.** The source gate's vocabulary was
86
+ uppercase while the spelling seats actually typed was lowercase, so 73 handles sat in 22 fixture files
87
+ the gate never saw, plus 23 glued spellings inside them and 11 more in two files the sweep could not
88
+ name. They are renamed to the fixtures' own subjects, the shared set now matches either case, and the
89
+ history gate's two redundant patterns are gone so one subject yields one problem line. A planted token
90
+ reddens the gate at a named line and column; a word character before a handle, two digits, four digits,
91
+ and an ISO calendar week are none of them hits.
92
+ - **A refusal was designed, measured, and killed by its own test.** The candidate enforcement was to refuse
93
+ the first call in a declared family once when the body was never read. Simulated over 703 sessions and
94
+ 107,463 tool calls with the production functions imported, 2 of 30 refused calls changed course (6.7%,
95
+ interval 1.8 to 21.3%), 0 of 30 on a stricter reading, and the gate could reach at most 8% of the calls
96
+ it governs. The best case in the data refutes the shape: the model read the body when the body mattered,
97
+ after the work it needed, without a gate. What ships is the measurement that makes that answer
98
+ possible; what does not ship is the gate.
99
+
100
+ ## Core — 0.43.6 (2026-10-29: the rule says one thing, and a merge states what landed)
101
+
102
+ - **The identity block contradicted itself, and the contradiction is gone.** One sentence forbade
103
+ internal labels in commit messages while the next sanctioned the commit subject as a seat for them, so
104
+ the rule could be quoted in either direction and nothing could be gated against it. It now says one
105
+ thing: a branch name may carry an internal handle for the operator, a commit subject must not. The
106
+ file gate's own comment, the design research behind the rule, and the open-source readiness audit all
107
+ already said subjects stay clean; the block was the outlier.
108
+ - **A merge states what landed.** Git derives `Merge branch '<name>'` from the branch name, so every
109
+ merge out of a worker branch published a handle nobody chose to write: 14 of the 24 merge commits then
110
+ in this repository carried that shape, and no gate read commit messages. The merge path now passes the
111
+ landed commit's own subject, and refuses the merge when it cannot read one, because the fallback is
112
+ precisely the derived subject. A probe through the real tool on a two-parent merge shows the landed
113
+ subject before and after; against a build with the change reverted it prints the derived one.
114
+ - **History has a gate now.** `check:commit-subjects` reads every commit since the newest tag reachable
115
+ from HEAD, merges included, and refuses internal-label tokens and the branch namespace a merge subject
116
+ inherits. Its range re-anchors at each release, and the summary line carries the range, the baseline tag
117
+ and the head, so a recorded population names the revision it certifies. Both workflows now fetch full
118
+ history, because a shallow clone has no tag to anchor the range, and the gate fails closed rather than
119
+ certifying nothing.
120
+ - **One vocabulary, two surfaces.** The label patterns the source gate used moved into a module both
121
+ gates read, so a token added once is refused in files and in history. The source gate's behaviour is
122
+ unchanged, proven by the same planted token caught at the same line and column either side of the
123
+ extraction.
124
+ - **The spelling seats actually typed is refused.** The shared vocabulary is uppercase, and the lowercase
125
+ form slid through: it is refused in history now, where the population has no fixture strings to
126
+ confuse it, with three near-miss cases in the fixture proving a word character before the handle, two
127
+ digits, and a four-digit run are not hits. The source surface keeps the uppercase vocabulary until the
128
+ lowercase strings inside fixture names are swept, which is tracked rather than assumed.
129
+ - **The fixture builds its own repositories.** A tag and a clean range, a planted label reported with its
130
+ sha, token and subject while a clean commit beside it stays unreported, a tagless tree refused with a
131
+ reason, the subject git itself derives from a worker branch, and the lowercase spelling with its
132
+ near-misses. The label tokens are composed at runtime, so the fixture does not plant what it tests.
133
+
46
134
  ## Core — 0.43.5 (2026-10-28: the runtime suite runs eight files at once, and a planted hang still dies at its cap)
47
135
 
48
136
  - **The core suite stopped waiting on one file at a time.** Its 320 files ran serially in 640s; eight in flight measured
package/build-info.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pi-braid",
3
- "version": "0.43.5",
4
- "sha": "e4d4f633f2707551090ffe407362b0266788dee9",
5
- "shaShort": "e4d4f633",
3
+ "version": "0.43.7",
4
+ "sha": "202c7b26bdcfe036b330cde4d98470951553502f",
5
+ "shaShort": "202c7b26",
6
6
  "branch": "detached",
7
7
  "dirty": false,
8
- "packedAt": "2026-10-29T11:33:28.249Z"
8
+ "packedAt": "2026-10-30T08:48:55.796Z"
9
9
  }
@@ -8,7 +8,7 @@ import { type PromptSection } from "./section.js";
8
8
  * instead of a prohibition list. The text is pinned verbatim by the lockstep
9
9
  * test — no paraphrasing here either.
10
10
  */
11
- export declare const SURFACE_DISCIPLINE = "Signal discipline binds every surface you produce: code comments, commit messages, tests, docs, reports, logs. A comment earns its place only by explaining why \u2014 code that needs a what-narration is rewritten, not annotated. Never commit internal task IDs, wave or phase labels, or session-ephemeral figures: a future reader has no context for them. Internal labels present in task text or briefs are never copied into code, tests, comments, docs, or commit messages \u2014 the only sanctioned seats for wave context are a report's filename and title and the commit subject. Write any spec or brief so a teammate with zero context can act on it.";
11
+ export declare const SURFACE_DISCIPLINE = "Signal discipline binds every surface you produce: code comments, commit messages, tests, docs, reports, logs. A comment earns its place only by explaining why \u2014 code that needs a what-narration is rewritten, not annotated. Never commit internal task IDs, wave or phase labels, or session-ephemeral figures: a future reader has no context for them. Internal labels present in task text or briefs are never copied into code, tests, comments, docs, or commit messages. A report's filename and title are the only sanctioned seats for wave context: a branch name may carry an internal handle for the operator, but the commit subject must not, because git derives it from the branch name and a reader keeps the subject. Write any spec or brief so a teammate with zero context can act on it.";
12
12
  /**
13
13
  * Its own section: the handler places it between the identity block and the
14
14
  * identity-core block — render order: COMMUNICATION ��� SURFACE_DISCIPLINE
@@ -8,7 +8,7 @@ import { simpleSection } from "./section.js";
8
8
  * instead of a prohibition list. The text is pinned verbatim by the lockstep
9
9
  * test — no paraphrasing here either.
10
10
  */
11
- export const SURFACE_DISCIPLINE = `Signal discipline binds every surface you produce: code comments, commit messages, tests, docs, reports, logs. A comment earns its place only by explaining why — code that needs a what-narration is rewritten, not annotated. Never commit internal task IDs, wave or phase labels, or session-ephemeral figures: a future reader has no context for them. Internal labels present in task text or briefs are never copied into code, tests, comments, docs, or commit messages — the only sanctioned seats for wave context are a report's filename and title and the commit subject. Write any spec or brief so a teammate with zero context can act on it.`;
11
+ export const SURFACE_DISCIPLINE = `Signal discipline binds every surface you produce: code comments, commit messages, tests, docs, reports, logs. A comment earns its place only by explaining why — code that needs a what-narration is rewritten, not annotated. Never commit internal task IDs, wave or phase labels, or session-ephemeral figures: a future reader has no context for them. Internal labels present in task text or briefs are never copied into code, tests, comments, docs, or commit messages. A report's filename and title are the only sanctioned seats for wave context: a branch name may carry an internal handle for the operator, but the commit subject must not, because git derives it from the branch name and a reader keeps the subject. Write any spec or brief so a teammate with zero context can act on it.`;
12
12
  /**
13
13
  * Its own section: the handler places it between the identity block and the
14
14
  * identity-core block — render order: COMMUNICATION ��� SURFACE_DISCIPLINE
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Skill applicability — did a skill's own declared condition hold for the task?
3
+ *
4
+ * The suggestion whisper, the catalog ranking and the adoption counters all
5
+ * answer "might this skill help?". None answers the question the counters
6
+ * cannot: of the sessions that read nothing, which of them had a skill whose
7
+ * stated condition the task text actually met? A suggestion that was ignored
8
+ * and a skill that never applied looked identical in `suggested`/`loaded`.
9
+ * This module decides that difference and keeps its evidence.
10
+ *
11
+ * The condition is the skill's OWN declaration, never a heuristic invented
12
+ * here: the trigger phrases its file declares — frontmatter `trigger:` /
13
+ * `triggers:`, a `## trigger:` body heading, the description's `Triggers:`
14
+ * tail — the same entries `skill-triggers.ts` reads and the same provenance
15
+ * labels it records. The shipped pack's contract already treats that list as
16
+ * the machine-readable form of applicability ("a description that cannot fire
17
+ * is indistinguishable from one that fires"), so a skill file needs no new
18
+ * field for this module to see it. A file that declares no phrase yields no
19
+ * verdict at all; the caller reports it as undeclared rather than asserting
20
+ * "does not apply" on no evidence.
21
+ *
22
+ * Matching mirrors the injector on purpose. The occurrence boundary is the one
23
+ * `triggerMatches` uses (a phrase occurs where neither neighbour is a letter or
24
+ * digit, so "pane" is not an occurrence in "paneled"), because a verdict that
25
+ * disagreed with the whisper would be worse than no verdict: the suite pins
26
+ * the two answers equal over the installed catalog. What this module adds is
27
+ * polarity — a phrase inside a negated clause ("do not research this") is not
28
+ * the author's condition holding, so the clause is read and the phrase is
29
+ * dropped as evidence.
30
+ *
31
+ * What this module does NOT do: it decides nothing about delivery, slots,
32
+ * cooldowns, counters or ranking. It returns a classification and the caller
33
+ * records it. Nothing here reads the session, writes a file or sends a
34
+ * message.
35
+ *
36
+ * Cost: one pass over the task text per phrase of the cached catalog, with the
37
+ * native substring scan as the cheap reject before any boundary work. The
38
+ * caller holds the prompt in memory already (the injector matches against the
39
+ * same string), so no I/O is added per turn.
40
+ */
41
+ import type { TriggerSource } from "./skill-triggers.js";
42
+ /**
43
+ * A skill as the applicability read consumes it: its name and the phrase list
44
+ * the cache resolved from its file. `triggers` and `triggerSources` are the
45
+ * fields `setCachedSkills` fills, so this read never touches the disk — the
46
+ * phrases and their provenance are the ones the injector matched against.
47
+ */
48
+ export interface ConditionalSkill {
49
+ name: string;
50
+ /** Authored phrases (lowercased, deduped, capped) — empty when the file declares none. */
51
+ triggers?: string[];
52
+ /** Which authored source declared each phrase. */
53
+ triggerSources?: Record<string, TriggerSource>;
54
+ }
55
+ /** One authored phrase that matched, with the place in the file that declares it. */
56
+ export interface ApplicabilityEvidence {
57
+ /** The authored phrase, as the reader normalized it. */
58
+ phrase: string;
59
+ /**
60
+ * frontmatter | heading | description — absent only when the cached skill
61
+ * carried no provenance map (an unenriched cache, never a production one).
62
+ */
63
+ source?: TriggerSource;
64
+ }
65
+ /**
66
+ * One skill's verdict for a session.
67
+ *
68
+ * `ignored` is the evaluation's answer: the declared condition held and no
69
+ * detected read followed. `read` is the read-detector's upgrade of the same
70
+ * row. The third class, not-applicable, is never a row — it is a skill that
71
+ * declared a condition and did not meet the task text, so a reader derives it
72
+ * from the record's census (`evaluated` minus the verdict rows).
73
+ */
74
+ export interface SkillApplicabilityVerdict {
75
+ name: string;
76
+ verdict: "read" | "ignored";
77
+ evidence: ApplicabilityEvidence[];
78
+ }
79
+ /** Max evidence rows carried per skill: enough to review, bounded like every other surface. */
80
+ export declare const MAX_APPLICABILITY_EVIDENCE = 4;
81
+ /**
82
+ * Word tokens a negation cue may sit before the phrase and still negate it.
83
+ * "do not research this" (0) and "no need to research" (2) are negated;
84
+ * "do not stop, then research it later" puts the cue past the clauseless
85
+ * distance and reads as the assertion it is. Four is the smallest window that
86
+ * covers the "no need to"/"there is no reason to" shapes without reaching
87
+ * across a clause.
88
+ */
89
+ export declare const NEGATION_GAP_TOKENS = 4;
90
+ /**
91
+ * Every index in `lowered` where `phrase` occurs as a whole phrase, using the
92
+ * matcher's boundary rule: neither neighbour may be a letter or digit. Phrase
93
+ * must already be lowercase. Pure.
94
+ */
95
+ export declare function phraseOccurrences(phrase: string, lowered: string): number[];
96
+ /**
97
+ * Index where the clause containing `at` begins: after the nearest sentence
98
+ * terminator. A clause boundary is what stops a negation in one statement from
99
+ * reaching a phrase in the next ("do not use the catalog; research the topic"
100
+ * asserts research). Pure.
101
+ */
102
+ export declare function clauseStart(lowered: string, at: number): number;
103
+ /**
104
+ * True when the clause text preceding a phrase carries a negation cue close
105
+ * enough to negate it. The LAST cue decides, so "not only did we not ask" is
106
+ * read by its nearest cue rather than its first. Pure.
107
+ */
108
+ export declare function isNegatedPrefix(prefix: string): boolean;
109
+ /**
110
+ * The evidence for one skill's declared condition holding on `taskText`.
111
+ *
112
+ * A phrase is evidence when at least one of its occurrences is asserted:
113
+ * negating one occurrence does not erase another ("do not skip research" and
114
+ * "research this" in the same text both count). Phrases are evidence at most
115
+ * MAX_APPLICABILITY_EVIDENCE times per skill, in authored order. An empty
116
+ * return means the condition did not hold. Pure.
117
+ */
118
+ export declare function skillApplicability(skill: ConditionalSkill, taskText: string): ApplicabilityEvidence[];
119
+ /** The whole catalog's answer for one task text. */
120
+ export interface ApplicabilityEvaluation {
121
+ /** Skills whose declared condition held, each still an `ignored` verdict. */
122
+ applicable: SkillApplicabilityVerdict[];
123
+ /** Installed skills that declare at least one condition phrase. */
124
+ evaluated: number;
125
+ /** Installed skills that declare none — no condition, so no verdict either way. */
126
+ undeclared: string[];
127
+ }
128
+ /**
129
+ * Classify every installed skill against one task text. Pure: the catalog
130
+ * arrives as the cache already resolved it, and the text is the prompt the
131
+ * injector matched against.
132
+ */
133
+ export declare function evaluateApplicability(skills: ConditionalSkill[], taskText: string): ApplicabilityEvaluation;
134
+ //# sourceMappingURL=applicability.d.ts.map
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Skill applicability — did a skill's own declared condition hold for the task?
3
+ *
4
+ * The suggestion whisper, the catalog ranking and the adoption counters all
5
+ * answer "might this skill help?". None answers the question the counters
6
+ * cannot: of the sessions that read nothing, which of them had a skill whose
7
+ * stated condition the task text actually met? A suggestion that was ignored
8
+ * and a skill that never applied looked identical in `suggested`/`loaded`.
9
+ * This module decides that difference and keeps its evidence.
10
+ *
11
+ * The condition is the skill's OWN declaration, never a heuristic invented
12
+ * here: the trigger phrases its file declares — frontmatter `trigger:` /
13
+ * `triggers:`, a `## trigger:` body heading, the description's `Triggers:`
14
+ * tail — the same entries `skill-triggers.ts` reads and the same provenance
15
+ * labels it records. The shipped pack's contract already treats that list as
16
+ * the machine-readable form of applicability ("a description that cannot fire
17
+ * is indistinguishable from one that fires"), so a skill file needs no new
18
+ * field for this module to see it. A file that declares no phrase yields no
19
+ * verdict at all; the caller reports it as undeclared rather than asserting
20
+ * "does not apply" on no evidence.
21
+ *
22
+ * Matching mirrors the injector on purpose. The occurrence boundary is the one
23
+ * `triggerMatches` uses (a phrase occurs where neither neighbour is a letter or
24
+ * digit, so "pane" is not an occurrence in "paneled"), because a verdict that
25
+ * disagreed with the whisper would be worse than no verdict: the suite pins
26
+ * the two answers equal over the installed catalog. What this module adds is
27
+ * polarity — a phrase inside a negated clause ("do not research this") is not
28
+ * the author's condition holding, so the clause is read and the phrase is
29
+ * dropped as evidence.
30
+ *
31
+ * What this module does NOT do: it decides nothing about delivery, slots,
32
+ * cooldowns, counters or ranking. It returns a classification and the caller
33
+ * records it. Nothing here reads the session, writes a file or sends a
34
+ * message.
35
+ *
36
+ * Cost: one pass over the task text per phrase of the cached catalog, with the
37
+ * native substring scan as the cheap reject before any boundary work. The
38
+ * caller holds the prompt in memory already (the injector matches against the
39
+ * same string), so no I/O is added per turn.
40
+ */
41
+ /** Max evidence rows carried per skill: enough to review, bounded like every other surface. */
42
+ export const MAX_APPLICABILITY_EVIDENCE = 4;
43
+ /**
44
+ * Word tokens a negation cue may sit before the phrase and still negate it.
45
+ * "do not research this" (0) and "no need to research" (2) are negated;
46
+ * "do not stop, then research it later" puts the cue past the clauseless
47
+ * distance and reads as the assertion it is. Four is the smallest window that
48
+ * covers the "no need to"/"there is no reason to" shapes without reaching
49
+ * across a clause.
50
+ */
51
+ export const NEGATION_GAP_TOKENS = 4;
52
+ /**
53
+ * Negation cues, matched in the clause text BEFORE a phrase. The `-n't`
54
+ * alternative is spelled out rather than listed per verb so a contraction the
55
+ * list forgot ("won't", "shouldn't") still counts.
56
+ */
57
+ const NEGATION_CUE = /\b(?:not|never|no|nor|without|avoid|avoiding|skip|skipping)\b|\b[a-z]+n['\u2019]t\b/gi;
58
+ /** True when `char` continues a word (the boundary rule `triggerMatches` uses). */
59
+ function isWordChar(char) {
60
+ return char !== undefined && /[a-z0-9]/.test(char);
61
+ }
62
+ /**
63
+ * Every index in `lowered` where `phrase` occurs as a whole phrase, using the
64
+ * matcher's boundary rule: neither neighbour may be a letter or digit. Phrase
65
+ * must already be lowercase. Pure.
66
+ */
67
+ export function phraseOccurrences(phrase, lowered) {
68
+ if (!phrase)
69
+ return [];
70
+ const out = [];
71
+ let from = 0;
72
+ for (;;) {
73
+ const at = lowered.indexOf(phrase, from);
74
+ if (at < 0)
75
+ break;
76
+ if (!isWordChar(lowered[at - 1]) && !isWordChar(lowered[at + phrase.length]))
77
+ out.push(at);
78
+ from = at + 1;
79
+ }
80
+ return out;
81
+ }
82
+ /**
83
+ * Index where the clause containing `at` begins: after the nearest sentence
84
+ * terminator. A clause boundary is what stops a negation in one statement from
85
+ * reaching a phrase in the next ("do not use the catalog; research the topic"
86
+ * asserts research). Pure.
87
+ */
88
+ export function clauseStart(lowered, at) {
89
+ for (let i = at - 1; i >= 0; i--) {
90
+ const char = lowered[i];
91
+ if (char === "." || char === "!" || char === "?" || char === ";" || char === "\n")
92
+ return i + 1;
93
+ }
94
+ return 0;
95
+ }
96
+ /**
97
+ * True when the clause text preceding a phrase carries a negation cue close
98
+ * enough to negate it. The LAST cue decides, so "not only did we not ask" is
99
+ * read by its nearest cue rather than its first. Pure.
100
+ */
101
+ export function isNegatedPrefix(prefix) {
102
+ const cue = new RegExp(NEGATION_CUE.source, "gi");
103
+ let last = null;
104
+ let match;
105
+ while ((match = cue.exec(prefix)))
106
+ last = match;
107
+ if (!last)
108
+ return false;
109
+ const gap = prefix.slice(last.index + last[0].length);
110
+ return (gap.match(/[a-z0-9]+/g) ?? []).length <= NEGATION_GAP_TOKENS;
111
+ }
112
+ /**
113
+ * The evidence for one skill's declared condition holding on `taskText`.
114
+ *
115
+ * A phrase is evidence when at least one of its occurrences is asserted:
116
+ * negating one occurrence does not erase another ("do not skip research" and
117
+ * "research this" in the same text both count). Phrases are evidence at most
118
+ * MAX_APPLICABILITY_EVIDENCE times per skill, in authored order. An empty
119
+ * return means the condition did not hold. Pure.
120
+ */
121
+ export function skillApplicability(skill, taskText) {
122
+ const lowered = taskText.toLowerCase();
123
+ const evidence = [];
124
+ for (const authored of skill.triggers ?? []) {
125
+ if (evidence.length >= MAX_APPLICABILITY_EVIDENCE)
126
+ break;
127
+ const phrase = authored.toLowerCase();
128
+ // Cheap reject first: most phrases are absent from most prompts.
129
+ if (!phrase || !lowered.includes(phrase))
130
+ continue;
131
+ const asserted = phraseOccurrences(phrase, lowered).some((at) => !isNegatedPrefix(lowered.slice(clauseStart(lowered, at), at)));
132
+ if (!asserted)
133
+ continue;
134
+ const source = skill.triggerSources?.[authored] ?? skill.triggerSources?.[phrase];
135
+ evidence.push(source ? { phrase, source } : { phrase });
136
+ }
137
+ return evidence;
138
+ }
139
+ /**
140
+ * Classify every installed skill against one task text. Pure: the catalog
141
+ * arrives as the cache already resolved it, and the text is the prompt the
142
+ * injector matched against.
143
+ */
144
+ export function evaluateApplicability(skills, taskText) {
145
+ const applicable = [];
146
+ const undeclared = [];
147
+ let evaluated = 0;
148
+ const text = taskText ?? "";
149
+ for (const skill of skills) {
150
+ if (!skill.triggers?.length) {
151
+ undeclared.push(skill.name);
152
+ continue;
153
+ }
154
+ evaluated++;
155
+ const evidence = skillApplicability(skill, text);
156
+ if (evidence.length)
157
+ applicable.push({ name: skill.name, verdict: "ignored", evidence });
158
+ }
159
+ return { applicable, evaluated, undeclared };
160
+ }
161
+ //# sourceMappingURL=applicability.js.map
@@ -189,6 +189,8 @@ export interface CachedSkill {
189
189
  triggers?: string[];
190
190
  /** Which source authored each phrase (the row's evidence label). */
191
191
  triggerSources?: Record<string, TriggerSource>;
192
+ /** Tool families the file's `governs:` declaration claims (skill-families.ts). */
193
+ families?: string[];
192
194
  }
193
195
  /** Called by index.ts's setCachedSkills to keep the auto-inject cache in sync. */
194
196
  export declare function updateSkillCache(skills: CachedSkill[]): void;
@@ -497,6 +499,14 @@ interface DiscoveryState {
497
499
  * discovery mode. Returns the current record for skill_stats.
498
500
  */
499
501
  export declare function resolveDiscoveryMode(ctx: ExtensionContext): DiscoveryState;
502
+ /**
503
+ * Record the skills a delivered suggestion offered this session. Called only
504
+ * after the send was accepted, so the row counts arrivals like the `suggested`
505
+ * counter does. Never throws: a record is not worth a broken turn.
506
+ */
507
+ export declare function noteObligationSuggested(ctx: ExtensionContext, names: string[]): void;
508
+ /** Record the skills a catalog page listed (called from the list_skills tool). */
509
+ export declare function noteObligationListed(ctx: ExtensionContext, names: string[]): void;
500
510
  /**
501
511
  * Register the auto-inject handler on before_agent_start, the read-tool load
502
512
  * detector and the drift trigger on tool_result.