pi-braid 0.43.6 → 0.43.8
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 +83 -0
- package/TOOLS.md +1 -1
- package/build-info.json +4 -4
- package/dist/extensions/core/prompt-builder/tool-guidelines.js +1 -1
- package/dist/extensions/core/skills-tool/applicability.d.ts +134 -0
- package/dist/extensions/core/skills-tool/applicability.js +161 -0
- package/dist/extensions/core/skills-tool/auto-inject.d.ts +31 -0
- package/dist/extensions/core/skills-tool/auto-inject.js +320 -1
- package/dist/extensions/core/skills-tool/index.js +83 -4
- package/dist/extensions/core/skills-tool/loading-guidance.d.ts +4 -1
- package/dist/extensions/core/skills-tool/loading-guidance.js +6 -2
- package/dist/extensions/core/skills-tool/session-records.d.ts +395 -8
- package/dist/extensions/core/skills-tool/session-records.js +645 -5
- package/dist/extensions/core/skills-tool/skill-families.d.ts +60 -0
- package/dist/extensions/core/skills-tool/skill-families.js +105 -0
- package/dist/extensions/enforcement/handlers/analysis/dreamer-handler.js +5 -1
- package/dist/extensions/enforcement/handlers/register-tool-call.js +5 -2
- package/dist/extensions/enforcement/verification-judge.d.ts +7 -0
- package/dist/extensions/enforcement/verification-judge.js +28 -21
- package/dist/extensions/memory/session-recall/ask.d.ts +95 -0
- package/dist/extensions/memory/session-recall/ask.js +376 -0
- package/dist/extensions/memory/session-recall/corpus-index.d.ts +200 -0
- package/dist/extensions/memory/session-recall/corpus-index.js +480 -0
- package/dist/extensions/memory/session-recall/index.js +173 -21
- package/dist/extensions/memory/session-recall/search.d.ts +29 -0
- package/dist/extensions/memory/session-recall/search.js +42 -9
- package/dist/lib/ai/payload-hygiene.d.ts +3 -0
- package/dist/lib/ai/payload-hygiene.js +34 -2
- package/dist/lib/config/braid-paths.d.ts +4 -0
- package/dist/lib/config/braid-paths.js +6 -0
- package/dist/lib/config/braid-settings.d.ts +22 -0
- package/dist/lib/config/braid-settings.js +15 -0
- package/dist/lib/detection/tool-loop-detector.d.ts +95 -46
- package/dist/lib/detection/tool-loop-detector.js +288 -180
- package/dist/lib/reasoning/dreamer.d.ts +2 -1
- package/dist/lib/reasoning/dreamer.js +12 -7
- package/docs/LOCAL_DEV.md +1 -1
- package/docs/SETUP.md +1 -0
- package/package.json +1 -1
- package/src/extensions/core/AGENTS.md +3 -1
- package/src/extensions/core/prompt-builder/tool-guidelines.ts +1 -1
- package/src/extensions/core/skills-tool/applicability.ts +220 -0
- package/src/extensions/core/skills-tool/auto-inject.ts +391 -0
- package/src/extensions/core/skills-tool/index.ts +96 -3
- package/src/extensions/core/skills-tool/loading-guidance.ts +6 -2
- package/src/extensions/core/skills-tool/session-records.ts +932 -5
- package/src/extensions/core/skills-tool/skill-families.ts +112 -0
- package/src/extensions/enforcement/handlers/analysis/dreamer-handler.ts +5 -1
- package/src/extensions/enforcement/handlers/register-tool-call.ts +5 -2
- package/src/extensions/enforcement/verification-judge.ts +32 -25
- package/src/extensions/memory/AGENTS.md +2 -2
- package/src/extensions/memory/session-recall/AGENTS.md +92 -18
- package/src/extensions/memory/session-recall/ask.ts +435 -0
- package/src/extensions/memory/session-recall/corpus-index.ts +609 -0
- package/src/extensions/memory/session-recall/index.ts +202 -21
- package/src/extensions/memory/session-recall/search.ts +61 -10
- package/src/lib/ai/payload-hygiene.ts +47 -3
- package/src/lib/config/braid-paths.ts +7 -0
- package/src/lib/config/braid-settings.ts +42 -3
- package/src/lib/detection/AGENTS.md +8 -7
- package/src/lib/detection/tool-loop-detector.ts +339 -195
- package/src/lib/reasoning/dreamer.ts +13 -6
|
@@ -95,6 +95,15 @@
|
|
|
95
95
|
* and never within that window of a suggestion or a SKILL.md read). The
|
|
96
96
|
* rule and its bounds live in loading-guidance.ts beside the floor text
|
|
97
97
|
* the line points at; this module only wires them to tool results.
|
|
98
|
+
* 11. At-use inform (`braid.skills.inform`, default off): a COMPLETED call in
|
|
99
|
+
* a family a visible skill's file declares with `governs:` and no read of
|
|
100
|
+
* that body on the session record gets one steer line naming the file and
|
|
101
|
+
* the obligation. Once per session per skill, suppressed by the same
|
|
102
|
+
* obligation record the legs already write (the `informed` leg). It
|
|
103
|
+
* observes a call that already ran and can only add a line: no refusal,
|
|
104
|
+
* no delay, and no rewrite of the result it arrives after. This is the
|
|
105
|
+
* timed alternative to refusing the call, and the difference is the whole
|
|
106
|
+
* point of it.
|
|
98
107
|
*
|
|
99
108
|
* Structure matches the existing steer whisper pattern used by topic-drift,
|
|
100
109
|
* turn-outcome, compaction-retry, context-lifecycle, and others.
|
|
@@ -112,8 +121,11 @@ import { getExtensionState } from "../../../lib/state/extension-state.js";
|
|
|
112
121
|
import { BRAID_INJECTED, BRAID_SOURCE } from "../../../lib/constants/injection-details.js";
|
|
113
122
|
import { getSkillsUsageFilePath } from "../../../lib/config/braid-paths.js";
|
|
114
123
|
import { SESSION_COMPACT, AGENT_SETTLED } from "../../../lib/core/event-names.js";
|
|
115
|
-
import { getSessionProfile, recordSessionSkillLoad, recordSessionStart, } from "./session-records.js";
|
|
124
|
+
import { getSessionProfile, recordApplicabilityCensus, recordApplicabilityVerdict, recordObligationLegs, recordSessionSkillLoad, recordSessionStart, } from "./session-records.js";
|
|
125
|
+
import { evaluateApplicability } from "./applicability.js";
|
|
116
126
|
import { triggerMatches } from "./skill-triggers.js";
|
|
127
|
+
import { toolFamilyToken } from "./skill-families.js";
|
|
128
|
+
import { getSkillsInformMode } from "../../../lib/config/braid-settings.js";
|
|
117
129
|
import { advanceDrift, driftDirectoryFor, driftPayload, initialDrift, noteDriftSurface, recordDriftDrop, recordDriftFire, skillReadRoot, } from "./loading-guidance.js";
|
|
118
130
|
const log = createLogger("skills-auto-inject");
|
|
119
131
|
// Constants
|
|
@@ -238,6 +250,12 @@ const KEYWORD_STOP_WORDS = new Set([
|
|
|
238
250
|
"need",
|
|
239
251
|
"look",
|
|
240
252
|
]);
|
|
253
|
+
function initialObligations() {
|
|
254
|
+
return { legs: new Map(), called: new Set(), written: new Map() };
|
|
255
|
+
}
|
|
256
|
+
function initialApplicability() {
|
|
257
|
+
return { censusWritten: false, verdicts: new Map(), evaluated: 0, undeclared: [], taskChars: 0 };
|
|
258
|
+
}
|
|
241
259
|
const STATE_KEY = "skills-auto-inject";
|
|
242
260
|
function getState(ctx) {
|
|
243
261
|
return getExtensionState(ctx, STATE_KEY, () => ({
|
|
@@ -245,6 +263,8 @@ function getState(ctx) {
|
|
|
245
263
|
currentTurn: 0,
|
|
246
264
|
hintSent: false,
|
|
247
265
|
drift: initialDrift(),
|
|
266
|
+
applicability: initialApplicability(),
|
|
267
|
+
obligations: initialObligations(),
|
|
248
268
|
}));
|
|
249
269
|
}
|
|
250
270
|
// Shared module-level variable rather than a per-module copy: the import
|
|
@@ -910,6 +930,167 @@ export function resolveDiscoveryMode(ctx) {
|
|
|
910
930
|
}
|
|
911
931
|
return state;
|
|
912
932
|
}
|
|
933
|
+
// Applicability verdict (recorded, never enforced)
|
|
934
|
+
/**
|
|
935
|
+
* Classify the catalog against this turn's task text and record what changed.
|
|
936
|
+
*
|
|
937
|
+
* Two writes, both append-only:
|
|
938
|
+
* - the session's census row, once, retried until it lands. It is what makes
|
|
939
|
+
* "not-applicable" derivable (evaluated minus the verdict rows) and what
|
|
940
|
+
* names the skills whose files state no condition at all.
|
|
941
|
+
* - one verdict row per skill whose declared condition held, and never twice
|
|
942
|
+
* for the same (session, skill): the set only grows because the verdict is
|
|
943
|
+
* per-session — a skill whose condition held on any turn applied to the
|
|
944
|
+
* session.
|
|
945
|
+
*
|
|
946
|
+
* The row shape is the joint the sibling compliance record expects: it joins on
|
|
947
|
+
* (sessionId, skill) and adds its own `suggested`/`listed`/`read`/`applied`
|
|
948
|
+
* beside this verdict, so `ignored / (read + ignored)` becomes computable. This
|
|
949
|
+
* module writes no `applied` leg: a tool belong to a skill's family only once
|
|
950
|
+
* the skill declares that family, and no skill does yet.
|
|
951
|
+
*
|
|
952
|
+
* Reads only — it never touches `injected`, a counter or a send. That is the
|
|
953
|
+
* whole point of the ordering in before_agent_start: this step cannot move the
|
|
954
|
+
* suggestion, and the suggestion cannot move the verdict.
|
|
955
|
+
*/
|
|
956
|
+
function stepApplicability(ctx, state, skills, prompt) {
|
|
957
|
+
const evaluation = evaluateApplicability(skills, prompt);
|
|
958
|
+
const app = state.applicability;
|
|
959
|
+
const fresh = evaluation.applicable.filter((verdict) => !app.verdicts.has(verdict.name));
|
|
960
|
+
for (const verdict of fresh)
|
|
961
|
+
app.verdicts.set(verdict.name, verdict);
|
|
962
|
+
app.evaluated = evaluation.evaluated;
|
|
963
|
+
app.undeclared = evaluation.undeclared;
|
|
964
|
+
app.taskChars = prompt.length;
|
|
965
|
+
if (!app.censusWritten) {
|
|
966
|
+
const wrote = recordApplicabilityCensus(ctx, {
|
|
967
|
+
taskChars: app.taskChars,
|
|
968
|
+
evaluated: app.evaluated,
|
|
969
|
+
undeclared: app.undeclared,
|
|
970
|
+
});
|
|
971
|
+
// A session without an id, or a refused store: retry on the next turn.
|
|
972
|
+
if (wrote)
|
|
973
|
+
app.censusWritten = true;
|
|
974
|
+
}
|
|
975
|
+
if (!fresh.length)
|
|
976
|
+
return;
|
|
977
|
+
log.debug(`[skills-auto-inject] applicability: ${fresh.length} newly applicable, ` +
|
|
978
|
+
`${evaluation.evaluated} evaluated, ${evaluation.undeclared.length} undeclared`);
|
|
979
|
+
for (const verdict of fresh) {
|
|
980
|
+
recordApplicabilityVerdict(ctx, {
|
|
981
|
+
skill: verdict.name,
|
|
982
|
+
applicability: verdict.verdict,
|
|
983
|
+
evidence: verdict.evidence,
|
|
984
|
+
});
|
|
985
|
+
// The obligation row lands with the verdict, not with the first leg: a
|
|
986
|
+
// session that is merely told which body it owes, and then does nothing,
|
|
987
|
+
// is the population the rate exists to count. Without this row that
|
|
988
|
+
// session would be mistaken for one the instrument never saw.
|
|
989
|
+
legsFor(state, verdict.name);
|
|
990
|
+
appendObligationRow(ctx, state, verdict.name);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Upgrade an applicable skill to `read` and append its verdict row. A read of a
|
|
995
|
+
* skill whose declared condition never held gets no row: the three classes are
|
|
996
|
+
* about skills that applied, and a read is not a fourth one.
|
|
997
|
+
*/
|
|
998
|
+
function markApplicabilityRead(ctx, state, name) {
|
|
999
|
+
const app = state.applicability;
|
|
1000
|
+
const held = app.verdicts.get(name);
|
|
1001
|
+
if (!held || held.verdict === "read")
|
|
1002
|
+
return;
|
|
1003
|
+
app.verdicts.set(name, { ...held, verdict: "read" });
|
|
1004
|
+
recordApplicabilityVerdict(ctx, {
|
|
1005
|
+
skill: name,
|
|
1006
|
+
applicability: "read",
|
|
1007
|
+
evidence: held.evidence,
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
// Obligation rows (the applied leg)
|
|
1011
|
+
/**
|
|
1012
|
+
* The session's legs for one skill, created on first sight. The object is the
|
|
1013
|
+
* snapshot every row carries, so a row states all five legs as of the moment
|
|
1014
|
+
* the leg changed rather than the single delta that triggered the write.
|
|
1015
|
+
*/
|
|
1016
|
+
function legsFor(state, name) {
|
|
1017
|
+
let legs = state.obligations.legs.get(name);
|
|
1018
|
+
if (!legs) {
|
|
1019
|
+
legs = {
|
|
1020
|
+
skill: name,
|
|
1021
|
+
suggested: false,
|
|
1022
|
+
listed: false,
|
|
1023
|
+
informed: false,
|
|
1024
|
+
read: false,
|
|
1025
|
+
called: false,
|
|
1026
|
+
applied: false,
|
|
1027
|
+
};
|
|
1028
|
+
state.obligations.legs.set(name, legs);
|
|
1029
|
+
}
|
|
1030
|
+
return legs;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Append the skill's legs when they changed since the last row. One row per
|
|
1034
|
+
* distinct state rather than one per event: a session that reads the same body
|
|
1035
|
+
* three times, or lists it on every turn, writes one line. A refused write
|
|
1036
|
+
* leaves the signature unset, so the next leg change retries.
|
|
1037
|
+
*/
|
|
1038
|
+
function appendObligationRow(ctx, state, name) {
|
|
1039
|
+
const legs = state.obligations.legs.get(name);
|
|
1040
|
+
if (!legs)
|
|
1041
|
+
return;
|
|
1042
|
+
const signature = [
|
|
1043
|
+
legs.suggested,
|
|
1044
|
+
legs.listed,
|
|
1045
|
+
legs.informed,
|
|
1046
|
+
legs.read,
|
|
1047
|
+
legs.called,
|
|
1048
|
+
legs.applied,
|
|
1049
|
+
]
|
|
1050
|
+
.map((flag) => (flag ? "1" : "0"))
|
|
1051
|
+
.join("");
|
|
1052
|
+
if (state.obligations.written.get(name) === signature)
|
|
1053
|
+
return;
|
|
1054
|
+
if (!recordObligationLegs(ctx, legs))
|
|
1055
|
+
return;
|
|
1056
|
+
state.obligations.written.set(name, signature);
|
|
1057
|
+
}
|
|
1058
|
+
/** Note one observed leg for a skill and record the row it changed. */
|
|
1059
|
+
function noteObligationLeg(ctx, state, name, leg) {
|
|
1060
|
+
if (!name)
|
|
1061
|
+
return;
|
|
1062
|
+
const legs = legsFor(state, name);
|
|
1063
|
+
if (legs[leg])
|
|
1064
|
+
return;
|
|
1065
|
+
legs[leg] = true;
|
|
1066
|
+
appendObligationRow(ctx, state, name);
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Record the skills a delivered suggestion offered this session. Called only
|
|
1070
|
+
* after the send was accepted, so the row counts arrivals like the `suggested`
|
|
1071
|
+
* counter does. Never throws: a record is not worth a broken turn.
|
|
1072
|
+
*/
|
|
1073
|
+
export function noteObligationSuggested(ctx, names) {
|
|
1074
|
+
try {
|
|
1075
|
+
const state = getState(ctx);
|
|
1076
|
+
for (const name of names)
|
|
1077
|
+
noteObligationLeg(ctx, state, name, "suggested");
|
|
1078
|
+
}
|
|
1079
|
+
catch (err) {
|
|
1080
|
+
log.debug(`[skills-auto-inject] obligation suggested leg failed (best-effort): ${err}`);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
/** Record the skills a catalog page listed (called from the list_skills tool). */
|
|
1084
|
+
export function noteObligationListed(ctx, names) {
|
|
1085
|
+
try {
|
|
1086
|
+
const state = getState(ctx);
|
|
1087
|
+
for (const name of names)
|
|
1088
|
+
noteObligationLeg(ctx, state, name, "listed");
|
|
1089
|
+
}
|
|
1090
|
+
catch (err) {
|
|
1091
|
+
log.debug(`[skills-auto-inject] obligation listed leg failed (best-effort): ${err}`);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
913
1094
|
/**
|
|
914
1095
|
* Count a SKILL.md read (the list→read load path) and mark the matching
|
|
915
1096
|
* injection loaded (releases its slot and extends its cooldown: the skill is
|
|
@@ -932,9 +1113,127 @@ function detectSkillLoad(ev, ctx, state) {
|
|
|
932
1113
|
if (held)
|
|
933
1114
|
held.loadedTurn = state.currentTurn;
|
|
934
1115
|
recordSkillLoad(ctx, name);
|
|
1116
|
+
// The load counters say a read happened; this says whether the session was
|
|
1117
|
+
// one where the skill applied. Independent writes, independent failures.
|
|
1118
|
+
markApplicabilityRead(ctx, state, name);
|
|
1119
|
+
noteObligationLeg(ctx, state, name, "read");
|
|
935
1120
|
log.debug(`[skills-auto-inject] counted actual load of "${name}" via read`);
|
|
936
1121
|
return name;
|
|
937
1122
|
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Record a call into a declared family (the applied leg).
|
|
1125
|
+
*
|
|
1126
|
+
* The FIRST call per (session, skill) decides it: a read already on record
|
|
1127
|
+
* means the body came first and the call applies what it says; no read means
|
|
1128
|
+
* the call came first, and no later read can turn that into satisfaction — the
|
|
1129
|
+
* ordering is a fact about what happened, not a state that improves.
|
|
1130
|
+
*
|
|
1131
|
+
* A failed call still counts: a refusal would fire before the tool ran and
|
|
1132
|
+
* could not know the outcome. Skills that declare no family are never reached
|
|
1133
|
+
* here, which is most of them.
|
|
1134
|
+
*/
|
|
1135
|
+
function stepFamilyCalls(ctx, state, event) {
|
|
1136
|
+
const toolName = event?.toolName;
|
|
1137
|
+
if (!toolName)
|
|
1138
|
+
return;
|
|
1139
|
+
const family = toolFamilyToken(toolName);
|
|
1140
|
+
if (!family)
|
|
1141
|
+
return;
|
|
1142
|
+
for (const skill of _skillsCache) {
|
|
1143
|
+
if (!skill.families?.length || !skill.families.includes(family))
|
|
1144
|
+
continue;
|
|
1145
|
+
if (state.obligations.called.has(skill.name))
|
|
1146
|
+
continue;
|
|
1147
|
+
const legs = legsFor(state, skill.name);
|
|
1148
|
+
state.obligations.called.add(skill.name);
|
|
1149
|
+
legs.called = true;
|
|
1150
|
+
legs.applied = legs.read;
|
|
1151
|
+
appendObligationRow(ctx, state, skill.name);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* The at-use line: the payload names the file and the obligation, and nothing
|
|
1156
|
+
* else.
|
|
1157
|
+
*
|
|
1158
|
+
* Both facts are derivable from the declaration and the catalog entry. The path
|
|
1159
|
+
* is the cached skill's own file path, never constructed; the family is the
|
|
1160
|
+
* token the call's own name yields, which is the same token the declaration is
|
|
1161
|
+
* written in. No skill name is invented in code, no tool argument is echoed,
|
|
1162
|
+
* and there is nothing here for a model to reconcile with the result it just
|
|
1163
|
+
* received. Pure.
|
|
1164
|
+
*/
|
|
1165
|
+
export function formatInformPayload(filePath, family) {
|
|
1166
|
+
return (`[SKILL INFORM] \`${filePath}\` governs the \`${family}\` tool family; ` +
|
|
1167
|
+
`a call in it just ran, and that file has not been read this session. ` +
|
|
1168
|
+
`Read it before the next call in the family.`);
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Inform at use: a COMPLETED call landed in a tool family a visible skill's
|
|
1172
|
+
* file declares with `governs:`, and no read of that body is on the session
|
|
1173
|
+
* record. One steer line, once per session per skill.
|
|
1174
|
+
*
|
|
1175
|
+
* This is the timed alternative to refusing the call. It runs after the result
|
|
1176
|
+
* exists, it touches no result, and the only thing it can do is add a line to
|
|
1177
|
+
* the stream; every gating decision below can only make it quieter. The
|
|
1178
|
+
* suppression is the obligation record itself (the `informed` leg, beside the
|
|
1179
|
+
* `read` leg), not a parallel set, so the record that says what the session did
|
|
1180
|
+
* and the record that stops a second line are one row.
|
|
1181
|
+
*
|
|
1182
|
+
* The applied leg counts a failed call because a refusal would fire before the
|
|
1183
|
+
* tool ran and could not know the outcome; this line does not, because its
|
|
1184
|
+
* premise is a call that ran in a family the body governs.
|
|
1185
|
+
*/
|
|
1186
|
+
function stepInform(pi, ctx, state, ev) {
|
|
1187
|
+
state.informMode ??= getSkillsInformMode();
|
|
1188
|
+
if (state.informMode !== "inform")
|
|
1189
|
+
return;
|
|
1190
|
+
if (!ev?.toolName)
|
|
1191
|
+
return;
|
|
1192
|
+
if (ev.isError)
|
|
1193
|
+
return;
|
|
1194
|
+
const family = toolFamilyToken(ev.toolName);
|
|
1195
|
+
if (!family)
|
|
1196
|
+
return;
|
|
1197
|
+
for (const skill of _skillsCache) {
|
|
1198
|
+
// The at-use line is an advertisement with a path: a body the prompt
|
|
1199
|
+
// deliberately hides from the model must not be named by it either.
|
|
1200
|
+
if (skill.disableModelInvocation)
|
|
1201
|
+
continue;
|
|
1202
|
+
if (!skill.families?.length || !skill.families.includes(family))
|
|
1203
|
+
continue;
|
|
1204
|
+
const held = state.obligations.legs.get(skill.name);
|
|
1205
|
+
if (held?.read)
|
|
1206
|
+
continue; // the body is in context; the obligation is met
|
|
1207
|
+
if (held?.informed)
|
|
1208
|
+
continue; // one line per session per skill
|
|
1209
|
+
const delivered = sendTrackedMessage(pi, {
|
|
1210
|
+
customType: "skills-inform",
|
|
1211
|
+
content: [{ type: "text", text: formatInformPayload(skill.filePath, family) }],
|
|
1212
|
+
display: true,
|
|
1213
|
+
details: {
|
|
1214
|
+
[BRAID_INJECTED]: true,
|
|
1215
|
+
[BRAID_SOURCE]: "skills-auto-inject",
|
|
1216
|
+
skill: skill.name,
|
|
1217
|
+
family,
|
|
1218
|
+
},
|
|
1219
|
+
}, { delivery: "park", deliverAs: "steer" }, { type: "context", source: "skills-auto-inject" },
|
|
1220
|
+
// The module's own budget is the bound: one line per session per skill,
|
|
1221
|
+
// and only on a call in a family the body itself declares. A flood cap
|
|
1222
|
+
// would drop the line in exactly the call it exists for.
|
|
1223
|
+
{ bypassFloodCap: true });
|
|
1224
|
+
if (!delivered) {
|
|
1225
|
+
log.debug("[skills-auto-inject] at-use line suppressed before delivery; not counted");
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
const legs = legsFor(state, skill.name);
|
|
1229
|
+
legs.informed = true;
|
|
1230
|
+
appendObligationRow(ctx, state, skill.name);
|
|
1231
|
+
// The line is a skill surface: the drift trigger stays quiet for its
|
|
1232
|
+
// window, because the pointer it exists to supply has just landed.
|
|
1233
|
+
noteDriftSurface(state.drift);
|
|
1234
|
+
log.info(`[skills-auto-inject] at-use line for "${skill.name}" (family ${family})`);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
938
1237
|
/**
|
|
939
1238
|
* Fire the drift line when the work has moved into a new work area (the rule
|
|
940
1239
|
* and its bounds live in loading-guidance.ts, beside the floor text the line
|
|
@@ -993,6 +1292,13 @@ export function registerAutoInject(pi) {
|
|
|
993
1292
|
const state = getState(ctx);
|
|
994
1293
|
if (detectSkillLoad(ev, ctx, state))
|
|
995
1294
|
noteDriftSurface(state.drift);
|
|
1295
|
+
// A call in a declared family is the applied leg. It runs after the load
|
|
1296
|
+
// detector so a SKILL.md read of the very tool call in flight is already
|
|
1297
|
+
// on record when the family is looked up.
|
|
1298
|
+
stepFamilyCalls(ctx, state, ev);
|
|
1299
|
+
// The at-use line runs after both: it needs the read leg (a read in this
|
|
1300
|
+
// very result silences it) and it does not depend on the applied leg.
|
|
1301
|
+
stepInform(pi, ctx, state, ev);
|
|
996
1302
|
stepDrift(pi, ctx, state, ev);
|
|
997
1303
|
}
|
|
998
1304
|
catch {
|
|
@@ -1044,6 +1350,17 @@ export function registerAutoInject(pi) {
|
|
|
1044
1350
|
if (!prompt.trim()) {
|
|
1045
1351
|
return; // No user input to match against
|
|
1046
1352
|
}
|
|
1353
|
+
// Applicability is recorded BEFORE every scoring early-return below.
|
|
1354
|
+
// Most sessions match no skill, and those are exactly the sessions the
|
|
1355
|
+
// adoption counters cannot explain: the returns would erase them. The
|
|
1356
|
+
// step reads the catalog and the prompt only, so the suggestion decision
|
|
1357
|
+
// below is untouched by it (and its failure cannot cost a suggestion).
|
|
1358
|
+
try {
|
|
1359
|
+
stepApplicability(ctx, state, skills, prompt);
|
|
1360
|
+
}
|
|
1361
|
+
catch (err) {
|
|
1362
|
+
log.debug(`[skills-auto-inject] applicability step failed (best-effort): ${err}`);
|
|
1363
|
+
}
|
|
1047
1364
|
// One-shot profile hint: the first non-empty prompt of a session whose
|
|
1048
1365
|
// configured profile carries a hint gets exactly one steer — the hint
|
|
1049
1366
|
// text itself, byte-for-byte. Profiles without a hint and sessions
|
|
@@ -1125,6 +1442,8 @@ export function registerAutoInject(pi) {
|
|
|
1125
1442
|
(i.loadedTurn !== undefined && state.currentTurn - i.loadedTurn < LOADED_COOLDOWN_TURNS));
|
|
1126
1443
|
// E3: per-skill suggestion counter — counts deliveries, not intent.
|
|
1127
1444
|
recordSkillSuggestion(ctx, skillsToInject.map((s) => s.name));
|
|
1445
|
+
// The same delivery is an obligation leg: the body was offered here.
|
|
1446
|
+
noteObligationSuggested(ctx, skillsToInject.map((s) => s.name));
|
|
1128
1447
|
}
|
|
1129
1448
|
catch (err) {
|
|
1130
1449
|
log.debug(`[skills-auto-inject] Error in before_agent_start: ${err}`);
|
|
@@ -33,11 +33,12 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { Type } from "typebox";
|
|
35
35
|
import { createLogger } from "../../../lib/core/logger.js";
|
|
36
|
-
import { getSkillsRankingMode } from "../../../lib/config/braid-settings.js";
|
|
37
|
-
import { registerAutoInject, updateSkillCache, getSkillStats, getDurableSkillStats, resolveDiscoveryMode, rankSkillsDeterministic, } from "./auto-inject.js";
|
|
36
|
+
import { getSkillsInformMode, getSkillsRankingMode } from "../../../lib/config/braid-settings.js";
|
|
37
|
+
import { registerAutoInject, updateSkillCache, getSkillStats, getDurableSkillStats, noteObligationListed, resolveDiscoveryMode, rankSkillsDeterministic, } from "./auto-inject.js";
|
|
38
38
|
import { readSkillTriggerEntries } from "./skill-triggers.js";
|
|
39
|
+
import { readGovernedFamilies } from "./skill-families.js";
|
|
39
40
|
import { clampSectionsMax, DEFAULT_SECTIONS_MAX, SECTIONS_MAX_LIMIT, readSkillReach, } from "./reach.js";
|
|
40
|
-
import { getMonthlyAdoptionRollup } from "./session-records.js";
|
|
41
|
+
import { getInformRate, getMonthlyAdoptionRollup, getObligationRate, getSessionApplicability, getSessionObligation, judgeSessionObligations, } from "./session-records.js";
|
|
41
42
|
import { checkArgumentValues } from "../../../lib/utils/argument-report.js";
|
|
42
43
|
const log = createLogger("skills-tool");
|
|
43
44
|
let cachedSkills = [];
|
|
@@ -53,7 +54,15 @@ export function setCachedSkills(skills) {
|
|
|
53
54
|
const triggerSources = {};
|
|
54
55
|
for (const entry of entries)
|
|
55
56
|
triggerSources[entry.phrase] = entry.source;
|
|
56
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
...s,
|
|
59
|
+
triggers: entries.map((entry) => entry.phrase),
|
|
60
|
+
triggerSources,
|
|
61
|
+
// The families the file says its advice directs, resolved from the same
|
|
62
|
+
// frontmatter read the phrases come from (one extra parse per file per
|
|
63
|
+
// process). An empty list is a declaration of no family, not a miss.
|
|
64
|
+
families: readGovernedFamilies(s.filePath),
|
|
65
|
+
};
|
|
57
66
|
});
|
|
58
67
|
// Sync with auto-inject subsystem (enriched cache — triggers ride along)
|
|
59
68
|
updateSkillCache(cachedSkills);
|
|
@@ -245,6 +254,10 @@ export default function skillsToolExtension(pi) {
|
|
|
245
254
|
// the empty object carried no information the absence does not.
|
|
246
255
|
...(answer.relevance.has(s.name) ? { relevance: answer.relevance.get(s.name) } : {}),
|
|
247
256
|
}));
|
|
257
|
+
// A listed row is one of the session's obligation legs: the catalog is
|
|
258
|
+
// where a body becomes findable without a whisper. Recorded before the
|
|
259
|
+
// response is built so the row and the page describe the same read.
|
|
260
|
+
noteObligationListed(ctx, skills.map((s) => s.name));
|
|
248
261
|
return {
|
|
249
262
|
content: [
|
|
250
263
|
{
|
|
@@ -310,6 +323,47 @@ export default function skillsToolExtension(pi) {
|
|
|
310
323
|
}
|
|
311
324
|
const monthly = getMonthlyAdoptionRollup();
|
|
312
325
|
const discovery = resolveDiscoveryMode(ctx);
|
|
326
|
+
// The session's skill verdicts (read | ignored, plus the not-applicable
|
|
327
|
+
// remainder of the census) from the durable record, never from memory:
|
|
328
|
+
// the point of the record is that it outlives the turn that saw it.
|
|
329
|
+
// Absent when the session wrote none — an older store, or a session that
|
|
330
|
+
// never reached a task text — so an exhausted reader of the old counters
|
|
331
|
+
// keeps byte-identical output. Only the verdict classes are summarized in
|
|
332
|
+
// details; the full evidence stays in the text payload.
|
|
333
|
+
const recorded = getSessionApplicability(ctx);
|
|
334
|
+
const applicability = recorded
|
|
335
|
+
? {
|
|
336
|
+
taskChars: recorded.taskChars,
|
|
337
|
+
evaluated: recorded.evaluated,
|
|
338
|
+
undeclared: recorded.undeclared,
|
|
339
|
+
classes: recorded.classes,
|
|
340
|
+
verdicts: recorded.verdicts,
|
|
341
|
+
updatedAt: recorded.updatedAt,
|
|
342
|
+
}
|
|
343
|
+
: undefined;
|
|
344
|
+
// The session's obligation legs and its boolean: what the session did
|
|
345
|
+
// with the bodies whose conditions held. Absent when the session has no
|
|
346
|
+
// leg row, so a store this build never wrote to reads byte for byte as
|
|
347
|
+
// it did before (the same rule the applicability block above follows).
|
|
348
|
+
const legRecord = getSessionObligation(ctx);
|
|
349
|
+
const judgement = judgeSessionObligations(recorded, legRecord);
|
|
350
|
+
const obligations = judgement && legRecord && legRecord.skills.length
|
|
351
|
+
? {
|
|
352
|
+
allSatisfied: judgement.allSatisfied,
|
|
353
|
+
obligations: judgement.obligations,
|
|
354
|
+
skills: judgement.skills,
|
|
355
|
+
}
|
|
356
|
+
: undefined;
|
|
357
|
+
// Both rates over one population, or absent while the store carries no
|
|
358
|
+
// obligation row at all: a build that predates the leg reads the same
|
|
359
|
+
// sessions and must see the same payload.
|
|
360
|
+
const obligationRate = getObligationRate();
|
|
361
|
+
// The at-use line's counters, folded from the same store as the channel
|
|
362
|
+
// arm beside them. Absent when the mode is off and no row was ever
|
|
363
|
+
// written, so a reader of a pre-inform store is unchanged.
|
|
364
|
+
const informRate = getInformRate();
|
|
365
|
+
const informMode = getSkillsInformMode();
|
|
366
|
+
const inform = informMode !== "off" || informRate ? { mode: informMode, ...informRate } : undefined;
|
|
313
367
|
return {
|
|
314
368
|
content: [
|
|
315
369
|
{
|
|
@@ -329,6 +383,10 @@ export default function skillsToolExtension(pi) {
|
|
|
329
383
|
suggestedEpoch: suggestedMixed === 0 ? "delivered" : "mixed",
|
|
330
384
|
},
|
|
331
385
|
monthly,
|
|
386
|
+
...(applicability ? { applicability } : {}),
|
|
387
|
+
...(obligations ? { obligations } : {}),
|
|
388
|
+
...(obligationRate ? { obligationRate } : {}),
|
|
389
|
+
...(inform ? { inform } : {}),
|
|
332
390
|
discovery: {
|
|
333
391
|
// Whether the stock skill catalog sits in the persisted
|
|
334
392
|
// transcript (it re-enters via pi's post-compaction
|
|
@@ -347,6 +405,27 @@ export default function skillsToolExtension(pi) {
|
|
|
347
405
|
allTimeSkills: Object.keys(allTime).length,
|
|
348
406
|
allTimeTotals: { ...totals, suggestedDelivered, suggestedMixed },
|
|
349
407
|
monthly,
|
|
408
|
+
...(applicability ? { applicability: applicability.classes } : {}),
|
|
409
|
+
...(obligations
|
|
410
|
+
? {
|
|
411
|
+
obligations: {
|
|
412
|
+
allSatisfied: obligations.allSatisfied,
|
|
413
|
+
count: obligations.obligations,
|
|
414
|
+
},
|
|
415
|
+
}
|
|
416
|
+
: {}),
|
|
417
|
+
...(obligationRate ? { obligationRate } : {}),
|
|
418
|
+
...(inform
|
|
419
|
+
? {
|
|
420
|
+
inform: {
|
|
421
|
+
mode: informMode,
|
|
422
|
+
informs: informRate?.informs ?? 0,
|
|
423
|
+
readFollowed: informRate?.readFollowed ?? 0,
|
|
424
|
+
conversion: informRate?.conversion ?? 0,
|
|
425
|
+
verdict: informRate?.verdict ?? "undecided",
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
: {}),
|
|
350
429
|
},
|
|
351
430
|
};
|
|
352
431
|
},
|
|
@@ -160,7 +160,10 @@ export declare function recordDriftFire(tracker: DriftTracker, directory: string
|
|
|
160
160
|
* a suppressed line is retried only after the session has done more work.
|
|
161
161
|
*/
|
|
162
162
|
export declare function recordDriftDrop(tracker: DriftTracker): void;
|
|
163
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Note that a skill surface (a suggestion, an at-use line, or a SKILL.md read)
|
|
165
|
+
* just landed.
|
|
166
|
+
*/
|
|
164
167
|
export declare function noteDriftSurface(tracker: DriftTracker): void;
|
|
165
168
|
/**
|
|
166
169
|
* The one-line steer: the work area and a pointer back at the catalog in the
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* auto-inject.ts and the reasoning stays testable here.
|
|
37
37
|
*/
|
|
38
38
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
39
|
+
import { toolFamilyToken } from "./skill-families.js";
|
|
39
40
|
/**
|
|
40
41
|
* Paragraph 1: what the catalog is, where the bodies live, and the obligation.
|
|
41
42
|
*
|
|
@@ -136,7 +137,7 @@ export function mechanicalTriggerExamples(toolNames, skillNames) {
|
|
|
136
137
|
// Family token (lowercased) -> lexicographically smallest active tool name.
|
|
137
138
|
const familyTool = new Map();
|
|
138
139
|
for (const tool of toolNames) {
|
|
139
|
-
const family = tool
|
|
140
|
+
const family = toolFamilyToken(tool);
|
|
140
141
|
const incumbent = familyTool.get(family);
|
|
141
142
|
if (incumbent === undefined || tool < incumbent)
|
|
142
143
|
familyTool.set(family, tool);
|
|
@@ -297,7 +298,10 @@ export function recordDriftDrop(tracker) {
|
|
|
297
298
|
tracker.lastFire = tracker.calls;
|
|
298
299
|
tracker.entries = {};
|
|
299
300
|
}
|
|
300
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Note that a skill surface (a suggestion, an at-use line, or a SKILL.md read)
|
|
303
|
+
* just landed.
|
|
304
|
+
*/
|
|
301
305
|
export function noteDriftSurface(tracker) {
|
|
302
306
|
tracker.lastSurface = tracker.calls;
|
|
303
307
|
}
|