@fenglimg/fabric-cli 2.2.0-rc.4 → 2.2.0-rc.9
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/README.md +8 -5
- package/dist/{chunk-5JG4QJLO.js → chunk-27HK6H5Y.js} +10 -5
- package/dist/{chunk-F6ITRM7T.js → chunk-2KBCTMID.js} +29 -6
- package/dist/chunk-3D7B2UAZ.js +149 -0
- package/dist/{chunk-XC5RUHLK.js → chunk-3IOLS5EK.js} +23 -38
- package/dist/{chunk-XHHCRDIR.js → chunk-7ZDXBOOU.js} +174 -211
- package/dist/{doctor-U5W4CX5I.js → chunk-E7HJUU34.js} +103 -51
- package/dist/{chunk-XCBVSGCS.js → chunk-FNHDQTPC.js} +1 -10
- package/dist/{chunk-2CY4BMTH.js → chunk-HORSMSZL.js} +9 -5
- package/dist/{chunk-BO4XIZWZ.js → chunk-NLNH64A3.js} +5 -18
- package/dist/{chunk-H3FE6VIK.js → chunk-PTGQAZEW.js} +13 -3
- package/dist/chunk-QFIVFZRH.js +13 -0
- package/dist/{chunk-5SSNE5GM.js → chunk-QPAW6IYT.js} +125 -39
- package/dist/{chunk-COI5VDFU.js → chunk-WA3DYGSY.js} +1 -2
- package/dist/{plan-context-hint-CHVZGOZ5.js → chunk-YM4XATJF.js} +29 -4
- package/dist/{config-VJMXCLXW.js → config-A3LTECAY.js} +4 -3
- package/dist/context-7NUKXDB6.js +117 -0
- package/dist/doctor-MDTZWKBK.js +24 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +131 -21
- package/dist/info-7FKBTMVO.js +139 -0
- package/dist/install-v2-I6PJ6IFT.js +3279 -0
- package/dist/{metrics-RER6NLFC.js → metrics-HMFH4YHK.js} +1 -1
- package/dist/{onboard-coverage-JWQWDZW7.js → onboard-coverage-XSG77LL3.js} +48 -27
- package/dist/plan-context-hint-G75R4P4J.js +12 -0
- package/dist/{scope-explain-BWRWBCCP.js → scope-explain-HLJZ2M33.js} +3 -2
- package/dist/{status-7UFLWRX7.js → status-4R3TM4FJ.js} +8 -5
- package/dist/{store-ZEZMQVG7.js → store-HOCORVL3.js} +96 -350
- package/dist/{sync-EA5HZMXM.js → sync-DT5UJMMR.js} +36 -13
- package/dist/{uninstall-F75MPKQC.js → uninstall-IFN2KYBK.js} +71 -140
- package/dist/{whoami-3FRWYGML.js → whoami-ITGEFWH4.js} +9 -7
- package/package.json +7 -5
- package/templates/hooks/cite-policy-evict.cjs +5 -5
- package/templates/hooks/configs/README.md +14 -27
- package/templates/hooks/configs/claude-code.json +1 -1
- package/templates/hooks/configs/codex-hooks.json +3 -3
- package/templates/hooks/fabric-hint.cjs +326 -161
- package/templates/hooks/knowledge-hint-broad.cjs +431 -271
- package/templates/hooks/knowledge-hint-narrow.cjs +64 -77
- package/templates/hooks/lib/banner-i18n.cjs +31 -0
- package/templates/hooks/lib/bindings-snapshot-reader.cjs +118 -7
- package/templates/hooks/lib/cite-line-parser.cjs +12 -20
- package/templates/hooks/lib/client-adapter.cjs +66 -7
- package/templates/hooks/lib/nudge-policy.cjs +117 -0
- package/templates/hooks/lib/state-store.cjs +60 -0
- package/templates/hooks/post-tooluse-mutation.cjs +112 -11
- package/templates/skills/fabric/SKILL.md +100 -0
- package/templates/skills/fabric-archive/SKILL.md +29 -26
- package/templates/skills/fabric-archive/ref/dry-run-scope.md +1 -1
- package/templates/skills/fabric-archive/ref/i18n-policy.md +2 -3
- package/templates/skills/fabric-archive/ref/phase-1-5-onboard.md +2 -3
- package/templates/skills/fabric-archive/ref/phase-1-cross-session.md +1 -1
- package/templates/skills/fabric-archive/ref/phase-2-5-viability.md +1 -1
- package/templates/skills/fabric-archive/ref/phase-3-6-related-edges.md +18 -0
- package/templates/skills/fabric-archive/ref/phase-3-7-semantic-scope.md +47 -0
- package/templates/skills/fabric-audit/SKILL.md +13 -3
- package/templates/skills/fabric-connect/SKILL.md +3 -3
- package/templates/skills/fabric-import/SKILL.md +7 -7
- package/templates/skills/fabric-import/ref/i18n-policy.md +2 -3
- package/templates/skills/fabric-import/ref/state-recovery.md +1 -2
- package/templates/skills/fabric-review/SKILL.md +5 -5
- package/templates/skills/fabric-review/ref/cite-contract.md +1 -1
- package/templates/skills/fabric-review/ref/i18n-policy.md +2 -3
- package/templates/skills/fabric-review/ref/output-contract.md +1 -1
- package/templates/skills/fabric-review/ref/per-mode-flows.md +2 -2
- package/templates/skills/fabric-review/ref/worked-examples.md +1 -1
- package/templates/skills/fabric-store/SKILL.md +1 -1
- package/templates/skills/fabric-sync/SKILL.md +1 -1
- package/templates/skills/lib/shared-policy.md +2 -2
- package/dist/install-7XJ64WSC.js +0 -2743
- package/templates/hooks/configs/cursor-hooks.json +0 -30
- package/templates/hooks/lib/cite-contract-reminder.cjs +0 -179
- package/templates/hooks/lib/summary-fallback.cjs +0 -210
|
@@ -44,23 +44,6 @@ try {
|
|
|
44
44
|
citeLineParser = null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// v2.0.0-rc.24 TASK-05: L1 enforcement layer — soft Stop hook reminder for
|
|
48
|
-
// [recalled] cites of decision/pitfall types that arrived without operator
|
|
49
|
-
// contract or skip:<reason>. Reads .fabric/agents.meta.json (via
|
|
50
|
-
// lib/cite-contract-reminder.cjs#readKnowledgeTypeMap) to type-route cite
|
|
51
|
-
// ids per B6 lock; emits one
|
|
52
|
-
// ⚠ KB: <id> cited as [recalled] but missing contract; add → edit:<glob>
|
|
53
|
-
// or → skip:<reason> next turn
|
|
54
|
-
// line to stderr per offending id. Non-blocking, never throws.
|
|
55
|
-
let citeContractReminder = null;
|
|
56
|
-
try {
|
|
57
|
-
citeContractReminder = require("./lib/cite-contract-reminder.cjs");
|
|
58
|
-
} catch {
|
|
59
|
-
// Helper module missing — soft reminder simply doesn't fire. Audit-side
|
|
60
|
-
// doctor (TASK-08) still catches contract violations at the next run.
|
|
61
|
-
citeContractReminder = null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
47
|
// v2.0.0-rc.37 NEW-30: shared client-protocol adapter. Guarded require (this
|
|
65
48
|
// hook runs in arbitrary user repos); detectClient delegates the 3-tier
|
|
66
49
|
// detection to the lib, falling back to env-only when the lib is absent.
|
|
@@ -71,6 +54,17 @@ try {
|
|
|
71
54
|
clientAdapter = null;
|
|
72
55
|
}
|
|
73
56
|
|
|
57
|
+
// v2.2 dual-sink (Goal A / D4): human-output gate for the archive nudge. The Stop
|
|
58
|
+
// archive nudge is SOFT (additionalContext, never decision:block — D3) and the
|
|
59
|
+
// human systemMessage is gated by nudge_mode. Optional require — absent → human
|
|
60
|
+
// always emits (legacy posture).
|
|
61
|
+
let nudgePolicy = null;
|
|
62
|
+
try {
|
|
63
|
+
nudgePolicy = require("./lib/nudge-policy.cjs");
|
|
64
|
+
} catch {
|
|
65
|
+
nudgePolicy = null;
|
|
66
|
+
}
|
|
67
|
+
|
|
74
68
|
// v2.0.0-rc.37 NEW-16: shared config + sidecar I/O for the per-signal dismiss
|
|
75
69
|
// feature (config-level durable opt-out + session-scoped sidecar). Guarded
|
|
76
70
|
// require (house style); dismiss simply doesn't fire if the lib is absent.
|
|
@@ -98,16 +92,115 @@ try {
|
|
|
98
92
|
bindingsSnapshotReader = null;
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
// Read the
|
|
102
|
-
|
|
95
|
+
// Read the workspace binding id (snapshot key) from project config. Standard
|
|
96
|
+
// repos default to project_id; worktrees can set workspace_binding_id to isolate
|
|
97
|
+
// hook/runtime state without changing project identity.
|
|
98
|
+
function readWorkspaceBindingId(cwd) {
|
|
103
99
|
try {
|
|
104
100
|
const parsed = JSON.parse(readFileSync(join(cwd, ".fabric", "fabric-config.json"), "utf8"));
|
|
101
|
+
if (typeof parsed.workspace_binding_id === "string") return parsed.workspace_binding_id;
|
|
105
102
|
return typeof parsed.project_id === "string" ? parsed.project_id : null;
|
|
106
103
|
} catch {
|
|
107
104
|
return null;
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
107
|
|
|
108
|
+
function readSnapshotKnowledgeStats(projectRoot, now) {
|
|
109
|
+
const nowMs = now instanceof Date ? now.getTime() : Number(now) || Date.now();
|
|
110
|
+
const empty = { pendingCount: 0, oldestPendingAgeMs: null, canonicalCount: 0 };
|
|
111
|
+
if (bindingsSnapshotReader === null) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const bindingId = readWorkspaceBindingId(projectRoot);
|
|
115
|
+
if (bindingId === null) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const snapshot = bindingsSnapshotReader.readBindingsSnapshot(bindingId);
|
|
120
|
+
// No snapshot file → empty corpus (KT-DEC-0007), preserving prior behavior.
|
|
121
|
+
if (!snapshot) {
|
|
122
|
+
return empty;
|
|
123
|
+
}
|
|
124
|
+
// LIVE recount off the snapshot's resolved store dirs. The cached
|
|
125
|
+
// knowledge_stats projection is frozen at snapshot-write time, so once the
|
|
126
|
+
// pending queue is reviewed (or store content syncs out-of-band) it goes
|
|
127
|
+
// stale — that is the phantom review-backlog this hook used to report
|
|
128
|
+
// (KT-PIT-0017). The authoritative count is the live *.md walk under the
|
|
129
|
+
// resolved store dirs.
|
|
130
|
+
const live = bindingsSnapshotReader.liveKnowledgeStats(snapshot);
|
|
131
|
+
// #3: a snapshot predating knowledge_store_dirs makes liveKnowledgeStats
|
|
132
|
+
// return null — counts are undeterminable and the cached projection is
|
|
133
|
+
// unreliable. Return `undefined` (a marker distinct from the `null` that
|
|
134
|
+
// lib/binding-absent returns, which readPendingStats uses as its legacy-
|
|
135
|
+
// fallback signal) so countCanonicalNodes maps it to "unknown" and the
|
|
136
|
+
// underseed signal SKIPS rather than false-firing on a stale corpus (snapshot
|
|
137
|
+
// self-heals on the next install/sync). Distinguished from the missing-
|
|
138
|
+
// snapshot case above, which stays `empty` (genuine fresh-project zero).
|
|
139
|
+
if (live === null) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
const pendingCount =
|
|
143
|
+
Number.isFinite(live.pendingCount) && live.pendingCount > 0 ? Math.floor(live.pendingCount) : 0;
|
|
144
|
+
const canonicalCount =
|
|
145
|
+
Number.isFinite(live.canonicalCount) && live.canonicalCount > 0
|
|
146
|
+
? Math.floor(live.canonicalCount)
|
|
147
|
+
: 0;
|
|
148
|
+
const oldestPendingAgeMs =
|
|
149
|
+
pendingCount > 0 &&
|
|
150
|
+
Number.isFinite(live.oldestPendingMtimeMs) &&
|
|
151
|
+
live.oldestPendingMtimeMs > 0
|
|
152
|
+
? Math.max(0, nowMs - live.oldestPendingMtimeMs)
|
|
153
|
+
: null;
|
|
154
|
+
return { pendingCount, oldestPendingAgeMs, canonicalCount };
|
|
155
|
+
} catch {
|
|
156
|
+
return empty;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function readLegacyPendingStats(projectRoot, now) {
|
|
161
|
+
const nowMs = now instanceof Date ? now.getTime() : Number(now) || Date.now();
|
|
162
|
+
const baseDir = join(projectRoot, FABRIC_DIR, PENDING_DIR);
|
|
163
|
+
|
|
164
|
+
let count = 0;
|
|
165
|
+
let oldestMtime = null;
|
|
166
|
+
|
|
167
|
+
if (!existsSync(baseDir)) {
|
|
168
|
+
return { count: 0, oldestAgeMs: null };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const type of PENDING_TYPES) {
|
|
172
|
+
const typeDir = join(baseDir, type);
|
|
173
|
+
if (!existsSync(typeDir)) continue;
|
|
174
|
+
|
|
175
|
+
let entries;
|
|
176
|
+
try {
|
|
177
|
+
entries = readdirSync(typeDir);
|
|
178
|
+
} catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
if (!entry.endsWith(".md")) continue;
|
|
184
|
+
const filePath = join(typeDir, entry);
|
|
185
|
+
let mtime;
|
|
186
|
+
try {
|
|
187
|
+
mtime = statSync(filePath).mtimeMs;
|
|
188
|
+
} catch {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
count += 1;
|
|
192
|
+
if (oldestMtime === null || mtime < oldestMtime) {
|
|
193
|
+
oldestMtime = mtime;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
count,
|
|
200
|
+
oldestAgeMs: count > 0 && oldestMtime !== null ? nowMs - oldestMtime : null,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
111
204
|
// CONSTANTS — duplicated from packages/server/src/services/_shared.ts.
|
|
112
205
|
// DRY violation accepted: this hook script runs in user repos WITHOUT
|
|
113
206
|
// node_modules access, so it cannot import from @fenglimg/fabric-server.
|
|
@@ -125,6 +218,59 @@ const EVENT_LEDGER_FILE = "events.jsonl";
|
|
|
125
218
|
const METRICS_LEDGER_FILE = "metrics.jsonl";
|
|
126
219
|
const EVENT_TYPE_PROPOSED = "knowledge_proposed";
|
|
127
220
|
const EVENT_TYPE_INIT_SCAN_COMPLETED = "init_scan_completed";
|
|
221
|
+
|
|
222
|
+
// v2.2 dual-sink (Goal A / D6): deterministic high-value probe for the archive
|
|
223
|
+
// nudge value-gate. Mirrors packages/server/src/services/archive-scan.ts
|
|
224
|
+
// (hasHighValueSignal) — the hook replicates the SAME deterministic ledger probe
|
|
225
|
+
// rather than running the semantic archive-scan, staying within the Hook⊥MCP
|
|
226
|
+
// boundary (the hook reads events.jsonl mechanically; it never judges relevance).
|
|
227
|
+
// Keep these two literal sets in sync with archive-scan.ts.
|
|
228
|
+
const ARCHIVE_HIGH_VALUE_EVENT_TYPES = new Set([
|
|
229
|
+
"knowledge_context_planned",
|
|
230
|
+
"edit_paths_recorded",
|
|
231
|
+
"edit_intent_checked",
|
|
232
|
+
]);
|
|
233
|
+
const ARCHIVE_NORMATIVE_KEYWORDS = [
|
|
234
|
+
"以后",
|
|
235
|
+
"always",
|
|
236
|
+
"never",
|
|
237
|
+
"from now on",
|
|
238
|
+
"下次",
|
|
239
|
+
"记一下",
|
|
240
|
+
"永远不要",
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
// v2.2 dual-sink (Goal A / D6): does the ledger carry a high-value archive signal
|
|
244
|
+
// since the watermark (last knowledge_proposed)? True iff any HIGH_VALUE event
|
|
245
|
+
// fired past the watermark, OR the latest assistant_turn carries a normative
|
|
246
|
+
// keyword. Deterministic — no semantic judgement. Used to VALUE-GATE the archive
|
|
247
|
+
// nudge so the check cadence (edits/hours) is decoupled from the nudge cadence
|
|
248
|
+
// (D6): a workspace that crossed the edit threshold but produced no high-value
|
|
249
|
+
// signal stays quiet. watermarkTs null (never archived) → treat all events as
|
|
250
|
+
// past-watermark (a never-archived repo with any edit signal is worth nudging).
|
|
251
|
+
function hasHighValueArchiveSignal(events, watermarkTs) {
|
|
252
|
+
if (!Array.isArray(events)) return false;
|
|
253
|
+
const wm = typeof watermarkTs === "number" ? watermarkTs : 0;
|
|
254
|
+
let latestTurn = null;
|
|
255
|
+
for (const e of events) {
|
|
256
|
+
if (!e || typeof e.ts !== "number" || e.ts <= wm) continue;
|
|
257
|
+
if (typeof e.event_type === "string" && ARCHIVE_HIGH_VALUE_EVENT_TYPES.has(e.event_type)) {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
if (e.event_type === "assistant_turn_observed") {
|
|
261
|
+
if (latestTurn === null || (typeof latestTurn.ts === "number" && e.ts > latestTurn.ts)) {
|
|
262
|
+
latestTurn = e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (latestTurn !== null) {
|
|
267
|
+
const haystack = JSON.stringify(latestTurn).toLowerCase();
|
|
268
|
+
for (const kw of ARCHIVE_NORMATIVE_KEYWORDS) {
|
|
269
|
+
if (haystack.includes(kw.toLowerCase())) return true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
128
274
|
// v2.0.0-rc.7 T10: doctor_run event drives Signal D (maintenance hint).
|
|
129
275
|
const EVENT_TYPE_DOCTOR_RUN = "doctor_run";
|
|
130
276
|
// v2.0.0-rc.20 TASK-03: per-turn cite-policy observation event. Emitted by
|
|
@@ -267,92 +413,40 @@ function readLedger(projectRoot) {
|
|
|
267
413
|
}
|
|
268
414
|
|
|
269
415
|
/**
|
|
270
|
-
*
|
|
271
|
-
* PENDING_TYPES subdirs, collecting count and oldest mtime.
|
|
416
|
+
* Read pending counts from the CLI-generated resolved-bindings snapshot.
|
|
272
417
|
*
|
|
273
418
|
* Returns { count, oldestAgeMs } where:
|
|
274
419
|
* - count: total .md file count across all type subdirs
|
|
275
420
|
* - oldestAgeMs: (nowMs - oldestMtimeMs) when count>0, else null
|
|
276
421
|
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
422
|
+
* Store-only cutover: hooks never walk project-local knowledge or store
|
|
423
|
+
* trees. Missing snapshot stats degrade to zero (KT-DEC-0007).
|
|
279
424
|
*/
|
|
280
425
|
function readPendingStats(projectRoot, now) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (!existsSync(baseDir)) {
|
|
288
|
-
return { count: 0, oldestAgeMs: null };
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
for (const type of PENDING_TYPES) {
|
|
292
|
-
const typeDir = join(baseDir, type);
|
|
293
|
-
if (!existsSync(typeDir)) continue;
|
|
294
|
-
|
|
295
|
-
let entries;
|
|
296
|
-
try {
|
|
297
|
-
entries = readdirSync(typeDir);
|
|
298
|
-
} catch {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
for (const entry of entries) {
|
|
303
|
-
if (!entry.endsWith(".md")) continue;
|
|
304
|
-
const filePath = join(typeDir, entry);
|
|
305
|
-
let mtime;
|
|
306
|
-
try {
|
|
307
|
-
mtime = statSync(filePath).mtimeMs;
|
|
308
|
-
} catch {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
count += 1;
|
|
312
|
-
if (oldestMtime === null || mtime < oldestMtime) {
|
|
313
|
-
oldestMtime = mtime;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
426
|
+
const stats = readSnapshotKnowledgeStats(projectRoot, now);
|
|
427
|
+
// `!= null` (loose) also catches the `undefined` old-snapshot marker (#3) →
|
|
428
|
+
// fall through to the legacy reader (which degrades to 0 → no phantom review
|
|
429
|
+
// nudge), rather than dereferencing pendingCount on a non-object.
|
|
430
|
+
if (stats != null) {
|
|
431
|
+
return { count: stats.pendingCount, oldestAgeMs: stats.oldestPendingAgeMs };
|
|
316
432
|
}
|
|
317
|
-
|
|
318
|
-
return {
|
|
319
|
-
count,
|
|
320
|
-
oldestAgeMs: count > 0 && oldestMtime !== null ? nowMs - oldestMtime : null,
|
|
321
|
-
};
|
|
433
|
+
return readLegacyPendingStats(projectRoot, now);
|
|
322
434
|
}
|
|
323
435
|
|
|
324
436
|
/**
|
|
325
|
-
* Count canonical knowledge entries
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* Returns the integer count. ENOENT / unreadable subdir → silently treated as
|
|
330
|
-
* zero (preserves never-block-on-failure invariant). Filters on `.md` suffix
|
|
331
|
-
* only; the more-precise canonical filename pattern check is owned by
|
|
332
|
-
* doctor.ts (the hook is a coarse signal, not a lint).
|
|
437
|
+
* Count canonical knowledge entries from the CLI-generated resolved-bindings
|
|
438
|
+
* snapshot. Store-only: hooks never walk project-local knowledge or store
|
|
439
|
+
* trees — a missing snapshot degrades to zero (KT-DEC-0007).
|
|
333
440
|
*/
|
|
334
441
|
function countCanonicalNodes(projectRoot) {
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
for
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
let entries;
|
|
344
|
-
try {
|
|
345
|
-
entries = readdirSync(typeDir);
|
|
346
|
-
} catch {
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
for (const entry of entries) {
|
|
350
|
-
if (entry.endsWith(".md")) {
|
|
351
|
-
count += 1;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return count;
|
|
442
|
+
const stats = readSnapshotKnowledgeStats(projectRoot);
|
|
443
|
+
// #3: `undefined` = snapshot EXISTS but predates knowledge_store_dirs →
|
|
444
|
+
// undeterminable → return null so decide()'s underseed signal SKIPS rather than
|
|
445
|
+
// false-firing on a stale corpus. `null` = no reader / not bound → degrade to 0
|
|
446
|
+
// (KT-DEC-0007, preserved). The `empty` object (missing snapshot) → canonical 0,
|
|
447
|
+
// still firing correctly for a genuinely fresh corpus.
|
|
448
|
+
if (stats === undefined) return null;
|
|
449
|
+
return stats === null ? 0 : stats.canonicalCount;
|
|
356
450
|
}
|
|
357
451
|
|
|
358
452
|
/**
|
|
@@ -411,6 +505,81 @@ function countEditsSince(projectRoot, anchorTs) {
|
|
|
411
505
|
return count;
|
|
412
506
|
}
|
|
413
507
|
|
|
508
|
+
// ---------------------------------------------------------------------------
|
|
509
|
+
// Observability grill (a + Q4): session-activity status breadcrumb.
|
|
510
|
+
//
|
|
511
|
+
// A no-signal Stop used to return SILENT — the human only ever heard from
|
|
512
|
+
// Fabric when there was a nudge to act on, never a "here is what I did" recap,
|
|
513
|
+
// which reads as "Fabric does nothing in the background". These two helpers add
|
|
514
|
+
// a HUMAN-ONLY trust anchor (the AI gets no activity recap — flow ⊥ observation,
|
|
515
|
+
// D5) plus the nudge_mode tier-guidance line (so the human-channel volume knob
|
|
516
|
+
// is discoverable). Cadence is gated by nudge_mode at emit time.
|
|
517
|
+
// ---------------------------------------------------------------------------
|
|
518
|
+
|
|
519
|
+
// Session-scoped tally. Counts ONLY events that carry session_id, filtered to
|
|
520
|
+
// the current session — knowledge_context_planned / knowledge_proposed lack
|
|
521
|
+
// session_id and are intentionally excluded (a cross-session count would
|
|
522
|
+
// mislead). Exported for unit tests.
|
|
523
|
+
function tallySessionActivity(events, sessionId) {
|
|
524
|
+
let edits = 0;
|
|
525
|
+
let consumed = 0;
|
|
526
|
+
if (!Array.isArray(events) || typeof sessionId !== "string" || sessionId.length === 0) {
|
|
527
|
+
return { edits, consumed };
|
|
528
|
+
}
|
|
529
|
+
for (const ev of events) {
|
|
530
|
+
if (!ev || ev.session_id !== sessionId) continue;
|
|
531
|
+
if (ev.event_type === "file_mutated") edits += 1;
|
|
532
|
+
else if (ev.event_type === "knowledge_consumed") consumed += 1;
|
|
533
|
+
}
|
|
534
|
+
return { edits, consumed };
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Emit the human-facing session status breadcrumb when no actionable signal
|
|
538
|
+
// fired. Human sink ONLY. Cadence by nudge_mode: silent → never; minimal/normal
|
|
539
|
+
// → once per session; verbose → every turn. Folds in the tier-guidance line on
|
|
540
|
+
// the first status of the session so the volume knob is discoverable. Never
|
|
541
|
+
// throws — the caller wraps it, but every branch degrades silently anyway.
|
|
542
|
+
function emitSessionStatus(cwd, events, stdinPayload, nowMs, pendingStats, out) {
|
|
543
|
+
if (nudgePolicy === null || clientAdapter === null) return;
|
|
544
|
+
if (typeof clientAdapter.emitDualSink !== "function") return;
|
|
545
|
+
const sessionId = resolveHookSessionId(stdinPayload);
|
|
546
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) return;
|
|
547
|
+
|
|
548
|
+
const mode =
|
|
549
|
+
typeof nudgePolicy.readNudgeMode === "function" ? nudgePolicy.readNudgeMode(cwd) : "normal";
|
|
550
|
+
if (mode === "silent") return; // human channel globally muted
|
|
551
|
+
|
|
552
|
+
const tally = tallySessionActivity(events, sessionId);
|
|
553
|
+
const pending = pendingStats && typeof pendingStats.total === "number" ? pendingStats.total : 0;
|
|
554
|
+
// Nothing happened yet this session AND no backlog → no trust anchor to show.
|
|
555
|
+
if (tally.edits === 0 && tally.consumed === 0 && pending === 0) return;
|
|
556
|
+
|
|
557
|
+
// Cadence gate: normal/minimal show once per session; verbose every turn.
|
|
558
|
+
const cache = readShownCache(cwd, sessionId);
|
|
559
|
+
const firstThisSession = cache._status === undefined;
|
|
560
|
+
if (mode !== "verbose" && !firstThisSession) return;
|
|
561
|
+
|
|
562
|
+
const variant = readFabricLanguage(cwd);
|
|
563
|
+
const line1 = renderBanner("statusLine", variant, {
|
|
564
|
+
edits: tally.edits,
|
|
565
|
+
consumed: tally.consumed,
|
|
566
|
+
pending,
|
|
567
|
+
});
|
|
568
|
+
// Tier guidance only on the first status of the session (don't repeat it on
|
|
569
|
+
// every verbose turn).
|
|
570
|
+
const human = firstThisSession
|
|
571
|
+
? `${line1}\n${renderBanner("statusTier", variant, { mode })}`
|
|
572
|
+
: line1;
|
|
573
|
+
|
|
574
|
+
clientAdapter.emitDualSink(
|
|
575
|
+
{ human, ai: null },
|
|
576
|
+
{ client: clientAdapter.detectClient(__dirname), eventName: "Stop", streams: { stdout: out } },
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
cache._status = nowMs;
|
|
580
|
+
writeShownCache(cwd, cache, sessionId);
|
|
581
|
+
}
|
|
582
|
+
|
|
414
583
|
/**
|
|
415
584
|
* v2.0.0-rc.8 (TASK-002): detect whether a fabric-import skill run is
|
|
416
585
|
* currently in flight, used to gate Signal B (review hint) so the Stop
|
|
@@ -862,6 +1031,10 @@ function decide(events, now, pendingStats, underseedStats, editCounterStats, thr
|
|
|
862
1031
|
lastInitScanTs === null ? null : (nowMs - lastInitScanTs) / MS_PER_HOUR;
|
|
863
1032
|
const hoursSinceProposed = hoursElapsed; // reuse archive-signal calc above
|
|
864
1033
|
const triggerUnderseed =
|
|
1034
|
+
// #3: null = undeterminable canonical count (old snapshot) → skip. Guard
|
|
1035
|
+
// first because `null < threshold` coerces to true in JS and would else
|
|
1036
|
+
// false-fire the underseed nudge on a stale corpus.
|
|
1037
|
+
underseed.nodeCount != null &&
|
|
865
1038
|
underseed.nodeCount < underseed.threshold &&
|
|
866
1039
|
hoursSinceInit !== null &&
|
|
867
1040
|
hoursSinceInit >= UNDERSEED_POST_INIT_QUIET_HOURS &&
|
|
@@ -1510,14 +1683,13 @@ function parseKbLine(raw) {
|
|
|
1510
1683
|
* "codex". Covers the dominant deployment shape (hook script lives
|
|
1511
1684
|
* under the client's per-repo dir).
|
|
1512
1685
|
*
|
|
1513
|
-
* Returns `undefined` when neither signal fires (
|
|
1514
|
-
*
|
|
1515
|
-
* so omitting it leaves the event valid.
|
|
1686
|
+
* Returns `undefined` when neither signal fires (a custom deployment). The
|
|
1687
|
+
* Zod schema marks `client` optional, so omitting it leaves the event valid.
|
|
1516
1688
|
*/
|
|
1517
1689
|
function detectClient() {
|
|
1518
1690
|
// Delegate the full 3-tier detection (env → CLAUDE_PROJECT_DIR → path
|
|
1519
|
-
// heuristic
|
|
1520
|
-
//
|
|
1691
|
+
// heuristic) to the shared adapter. __dirname is passed so the path
|
|
1692
|
+
// heuristic reflects THIS hook's location.
|
|
1521
1693
|
if (clientAdapter && typeof clientAdapter.detectClient === "function") {
|
|
1522
1694
|
return clientAdapter.detectClient(__dirname);
|
|
1523
1695
|
}
|
|
@@ -1525,7 +1697,7 @@ function detectClient() {
|
|
|
1525
1697
|
const envClient = process.env.FABRIC_HINT_CLIENT;
|
|
1526
1698
|
if (typeof envClient === "string" && envClient.length > 0) {
|
|
1527
1699
|
const normalised = envClient.trim().toLowerCase();
|
|
1528
|
-
if (normalised === "cc" || normalised === "codex"
|
|
1700
|
+
if (normalised === "cc" || normalised === "codex") {
|
|
1529
1701
|
return normalised;
|
|
1530
1702
|
}
|
|
1531
1703
|
}
|
|
@@ -1864,50 +2036,6 @@ function summarizeTranscript(transcriptPath) {
|
|
|
1864
2036
|
return out;
|
|
1865
2037
|
}
|
|
1866
2038
|
|
|
1867
|
-
/**
|
|
1868
|
-
* v2.0.0-rc.24 TASK-05: emit soft L1 reminder to stderr when assistant turns
|
|
1869
|
-
* cited a decision/pitfall id with [recalled] but no operator contract and no
|
|
1870
|
-
* skip:<reason>. Reads agents.meta.json once per invocation; aggregated per
|
|
1871
|
-
* turn (one line per offending id). Non-blocking — never throws, always
|
|
1872
|
-
* returns the array of emitted reminder strings (for unit tests + callers
|
|
1873
|
-
* that want to observe what was written).
|
|
1874
|
-
*
|
|
1875
|
-
* The reminder writes go to stderr (the hook contract: stdout is structured
|
|
1876
|
-
* banner JSON consumed by the harness; stderr is free-text system message
|
|
1877
|
-
* that surfaces back to the model on the next turn in cc / codex / cursor).
|
|
1878
|
-
*/
|
|
1879
|
-
function emitCiteContractRemindersBestEffort(cwd, stdinPayload, stderr) {
|
|
1880
|
-
if (citeContractReminder === null) return [];
|
|
1881
|
-
if (stdinPayload === null || typeof stdinPayload !== "object") return [];
|
|
1882
|
-
try {
|
|
1883
|
-
const transcript = summarizeTranscript(stdinPayload.transcript_path);
|
|
1884
|
-
const turns = transcript.assistant_turns;
|
|
1885
|
-
if (!Array.isArray(turns) || turns.length === 0) return [];
|
|
1886
|
-
|
|
1887
|
-
const idTypeMap = citeContractReminder.readKnowledgeTypeMap(cwd);
|
|
1888
|
-
if (!(idTypeMap instanceof Map) || idTypeMap.size === 0) return [];
|
|
1889
|
-
|
|
1890
|
-
const reminders = citeContractReminder.formatContractMissingReminders({
|
|
1891
|
-
assistant_turns: turns,
|
|
1892
|
-
idTypeMap,
|
|
1893
|
-
});
|
|
1894
|
-
if (!Array.isArray(reminders) || reminders.length === 0) return [];
|
|
1895
|
-
|
|
1896
|
-
const sink = stderr || process.stderr;
|
|
1897
|
-
for (const line of reminders) {
|
|
1898
|
-
try {
|
|
1899
|
-
sink.write(line + "\n");
|
|
1900
|
-
} catch {
|
|
1901
|
-
// Sink write failure must not abort emission of remaining reminders.
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
return reminders;
|
|
1905
|
-
} catch {
|
|
1906
|
-
// Outer guard — never throw. Hook continues silently.
|
|
1907
|
-
return [];
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
2039
|
/**
|
|
1912
2040
|
* v2.0.0-rc.7 T5: writeSessionDigestBestEffort — non-blocking digest fan-out.
|
|
1913
2041
|
* Called from main() before the existing decide() flow. Failure is silently
|
|
@@ -1961,16 +2089,6 @@ function main(env, stdio) {
|
|
|
1961
2089
|
// the hook's other I/O).
|
|
1962
2090
|
extractAndWriteAssistantTurnsBestEffort(cwd, stdinPayload);
|
|
1963
2091
|
|
|
1964
|
-
// v2.0.0-rc.24 TASK-05: L1 soft reminder layer. Surfaces ⚠ KB:<id> lines
|
|
1965
|
-
// to stderr when decision/pitfall cites arrived with [recalled] tag but
|
|
1966
|
-
// empty contract. Non-blocking, never throws; doctor (TASK-08) catches
|
|
1967
|
-
// any contract violation the model ignored.
|
|
1968
|
-
emitCiteContractRemindersBestEffort(
|
|
1969
|
-
cwd,
|
|
1970
|
-
stdinPayload,
|
|
1971
|
-
stdio && stdio.stderr,
|
|
1972
|
-
);
|
|
1973
|
-
|
|
1974
2092
|
const events = readLedger(cwd);
|
|
1975
2093
|
|
|
1976
2094
|
// lifecycle-refactor W3-A2 (§7): request graph-edge extraction for a freshly
|
|
@@ -2128,7 +2246,38 @@ function main(env, stdio) {
|
|
|
2128
2246
|
}
|
|
2129
2247
|
}
|
|
2130
2248
|
|
|
2131
|
-
if (result === null)
|
|
2249
|
+
if (result === null) {
|
|
2250
|
+
// Observability grill (a): no actionable signal — instead of returning
|
|
2251
|
+
// silently (which made Fabric feel inert in the background), surface a
|
|
2252
|
+
// session-activity status breadcrumb to the human sink (gated by
|
|
2253
|
+
// nudge_mode). Best-effort: never block the Stop hook on it.
|
|
2254
|
+
try {
|
|
2255
|
+
emitSessionStatus(cwd, events, stdinPayload, nowMs, pendingStats, out);
|
|
2256
|
+
} catch {
|
|
2257
|
+
// status breadcrumb is decorative — never throw
|
|
2258
|
+
}
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
// v2.2 dual-sink (Goal A / D6): VALUE-GATE the archive nudge. Signal A's
|
|
2263
|
+
// edit/hours trigger is the CHECK cadence; the nudge only fires when a
|
|
2264
|
+
// deterministic high-value signal accrued since the last archive (decouples
|
|
2265
|
+
// check frequency from disturb frequency). Boundary-correct: replicates
|
|
2266
|
+
// archive-scan's ledger probe (no semantic judgement). Other signals
|
|
2267
|
+
// (review/import/maintenance) are unaffected.
|
|
2268
|
+
if (result.signal === "archive") {
|
|
2269
|
+
let watermarkTs = null;
|
|
2270
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
2271
|
+
const ev = events[i];
|
|
2272
|
+
if (ev && ev.event_type === EVENT_TYPE_PROPOSED && typeof ev.ts === "number") {
|
|
2273
|
+
watermarkTs = ev.ts;
|
|
2274
|
+
break;
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
if (!hasHighValueArchiveSignal(events, watermarkTs)) {
|
|
2278
|
+
return; // no high-value candidate → stay quiet (D6 value-gate)
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2132
2281
|
|
|
2133
2282
|
// v2.0.0-rc.37 NEW-16: per-signal dismiss. A chosen signal whose type the
|
|
2134
2283
|
// user dismissed (config-durable or session sidecar) exits silently —
|
|
@@ -2150,10 +2299,10 @@ function main(env, stdio) {
|
|
|
2150
2299
|
// pile. Best-effort; missing snapshot / single-store omits the line.
|
|
2151
2300
|
if (bindingsSnapshotReader !== null && typeof result.reason === "string") {
|
|
2152
2301
|
try {
|
|
2153
|
-
const
|
|
2154
|
-
if (
|
|
2302
|
+
const bindingId = readWorkspaceBindingId(cwd);
|
|
2303
|
+
if (bindingId) {
|
|
2155
2304
|
const label = bindingsSnapshotReader.formatStoreLabels(
|
|
2156
|
-
bindingsSnapshotReader.readBindingsSnapshot(
|
|
2305
|
+
bindingsSnapshotReader.readBindingsSnapshot(bindingId),
|
|
2157
2306
|
);
|
|
2158
2307
|
if (label) {
|
|
2159
2308
|
result.reason = `${result.reason}\n${label}`;
|
|
@@ -2193,9 +2342,27 @@ function main(env, stdio) {
|
|
|
2193
2342
|
}
|
|
2194
2343
|
|
|
2195
2344
|
emitSignalFiredEvent(cwd, sessionId, result);
|
|
2345
|
+
const reasonText = typeof result.reason === "string" ? result.reason : "";
|
|
2196
2346
|
delete result.threshold;
|
|
2197
2347
|
delete result.actual_value;
|
|
2198
|
-
|
|
2348
|
+
// v2.2 dual-sink (Goal A / D3): the archive nudge is SOFT — emitted as
|
|
2349
|
+
// additionalContext(AI) + systemMessage(human), NEVER decision:block. The
|
|
2350
|
+
// human channel is gated by nudge_mode (D4/D5); the AI channel always carries
|
|
2351
|
+
// it (flow ⊥ observation). Missing it is backstopped by the SessionEnd marker
|
|
2352
|
+
// + cross-session debt (D3). Review/import keep the decision:block contract
|
|
2353
|
+
// (out of Goal A scope; KT-DEC-0007 nudge semantics unchanged for them).
|
|
2354
|
+
if (result.signal === "archive" && clientAdapter && typeof clientAdapter.emitDualSink === "function") {
|
|
2355
|
+
const humanGate =
|
|
2356
|
+
nudgePolicy !== null
|
|
2357
|
+
? nudgePolicy.resolveHumanSink(cwd, "stop", { highValue: true })
|
|
2358
|
+
: { emitHuman: true };
|
|
2359
|
+
clientAdapter.emitDualSink(
|
|
2360
|
+
{ human: humanGate.emitHuman ? reasonText : null, ai: reasonText },
|
|
2361
|
+
{ client: clientAdapter.detectClient(__dirname), eventName: "Stop", streams: { stdout: out } },
|
|
2362
|
+
);
|
|
2363
|
+
} else {
|
|
2364
|
+
out.write(JSON.stringify(result));
|
|
2365
|
+
}
|
|
2199
2366
|
cache[result.signal] = nowMs;
|
|
2200
2367
|
writeShownCache(cwd, cache, resolveHookSessionId(stdinPayload));
|
|
2201
2368
|
} catch {
|
|
@@ -2209,6 +2376,8 @@ module.exports = {
|
|
|
2209
2376
|
readPendingStats,
|
|
2210
2377
|
countCanonicalNodes,
|
|
2211
2378
|
countEditsSince,
|
|
2379
|
+
// observability grill (a): session-activity tally for the human status line.
|
|
2380
|
+
tallySessionActivity,
|
|
2212
2381
|
// rc.7 T4: top-edited-directories aggregator + banner overview formatter.
|
|
2213
2382
|
getTopEditedDirectories,
|
|
2214
2383
|
formatActivityOverview,
|
|
@@ -2248,10 +2417,6 @@ module.exports = {
|
|
|
2248
2417
|
parseKbLine,
|
|
2249
2418
|
detectClient,
|
|
2250
2419
|
extractAndWriteAssistantTurnsBestEffort,
|
|
2251
|
-
// v2.0.0-rc.24 TASK-05: L1 soft reminder helpers (exported for unit testing
|
|
2252
|
-
// of the contract-missing emission contract). The lib module itself is
|
|
2253
|
-
// also exported indirectly via the reminder helper.
|
|
2254
|
-
emitCiteContractRemindersBestEffort,
|
|
2255
2420
|
// lifecycle-refactor W3-A2 (§7): graph-edge-candidate request emitter
|
|
2256
2421
|
// (exported for unit testing of the honest stable_id-gating + de-dup).
|
|
2257
2422
|
emitGraphEdgeCandidateBestEffort,
|