@fenglimg/fabric-cli 2.2.0-rc.1 → 2.2.0-rc.11
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-27HK6H5Y.js +69 -0
- package/dist/{chunk-AOE6AYI7.js → chunk-2KBCTMID.js} +31 -8
- package/dist/chunk-3D7B2UAZ.js +149 -0
- package/dist/{chunk-XC5RUHLK.js → chunk-3IOLS5EK.js} +23 -38
- package/dist/{plan-context-hint-FC6P3WFE.js → chunk-722JU5BP.js} +52 -12
- package/dist/{chunk-2R55HNVD.js → chunk-7ZDXBOOU.js} +234 -206
- package/dist/{doctor-YONYXDX6.js → chunk-E7HJUU34.js} +215 -52
- package/dist/chunk-EOT63RDH.js +36 -0
- package/dist/chunk-FNHDQTPC.js +16 -0
- package/dist/{chunk-2CY4BMTH.js → chunk-HORSMSZL.js} +9 -5
- package/dist/{chunk-BO4XIZWZ.js → chunk-NLNH64A3.js} +5 -18
- package/dist/{chunk-WU6GAPKH.js → chunk-PTGQAZEW.js} +12 -4
- package/dist/chunk-QFIVFZRH.js +13 -0
- package/dist/chunk-QPAW6IYT.js +387 -0
- package/dist/{chunk-COI5VDFU.js → chunk-WA3DYGSY.js} +1 -2
- package/dist/{config-XYRBZJDU.js → config-A3LTECAY.js} +4 -3
- package/dist/context-UJCGYOT6.js +117 -0
- package/dist/doctor-MDTZWKBK.js +24 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +133 -22
- package/dist/info-7FKBTMVO.js +139 -0
- package/dist/install-v2-WLEJ5XHT.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-5TNGH3R4.js +12 -0
- package/dist/{scope-explain-CDIZESP5.js → scope-explain-HLJZ2M33.js} +17 -6
- package/dist/status-4R3TM4FJ.js +37 -0
- package/dist/store-HOCORVL3.js +563 -0
- package/dist/{sync-UJ4BBCZJ.js → sync-DT5UJMMR.js} +197 -30
- package/dist/{uninstall-C3QXKOO6.js → uninstall-IFN2KYBK.js} +97 -140
- package/dist/whoami-ITGEFWH4.js +49 -0
- package/package.json +7 -5
- package/templates/hooks/cite-policy-evict.cjs +412 -160
- package/templates/hooks/configs/README.md +14 -27
- package/templates/hooks/configs/claude-code.json +17 -2
- package/templates/hooks/configs/codex-hooks.json +15 -3
- package/templates/hooks/fabric-hint.cjs +742 -259
- package/templates/hooks/knowledge-hint-broad.cjs +577 -274
- package/templates/hooks/knowledge-hint-narrow.cjs +113 -73
- package/templates/hooks/lib/banner-i18n.cjs +50 -1
- 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 +386 -0
- package/templates/hooks/session-end-marker.cjs +140 -0
- package/templates/skills/fabric/SKILL.md +100 -0
- package/templates/skills/fabric-archive/SKILL.md +47 -24
- 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 +14 -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/chunk-4R2CYEA4.js +0 -116
- package/dist/chunk-L4Q55UC4.js +0 -52
- package/dist/chunk-LFIKMVY7.js +0 -27
- package/dist/chunk-RYAFBNES.js +0 -33
- package/dist/chunk-T5RPGCCM.js +0 -40
- package/dist/install-74ANPCCP.js +0 -2737
- package/dist/status-GLQWLWH6.js +0 -23
- package/dist/store-XB3ADT65.js +0 -144
- package/dist/whoami-2MLO4Y37.js +0 -36
- package/templates/hooks/configs/cursor-hooks.json +0 -18
- package/templates/hooks/lib/cite-contract-reminder.cjs +0 -179
- package/templates/hooks/lib/summary-fallback.cjs +0 -210
package/dist/status-GLQWLWH6.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
projectStatus
|
|
4
|
-
} from "./chunk-T5RPGCCM.js";
|
|
5
|
-
import "./chunk-LFIKMVY7.js";
|
|
6
|
-
import "./chunk-RYAFBNES.js";
|
|
7
|
-
|
|
8
|
-
// src/commands/status.ts
|
|
9
|
-
import { defineCommand } from "citty";
|
|
10
|
-
var status_default = defineCommand({
|
|
11
|
-
meta: { name: "status", description: "Show this project's Fabric store status" },
|
|
12
|
-
run() {
|
|
13
|
-
const status = projectStatus(process.cwd());
|
|
14
|
-
console.log(`uid: ${status.uid ?? "(no global config)"}`);
|
|
15
|
-
console.log(`project_id: ${status.project_id ?? "(not a Fabric project)"}`);
|
|
16
|
-
console.log(`mounted stores: ${status.mounted.length > 0 ? status.mounted.join(", ") : "(none)"}`);
|
|
17
|
-
console.log(`required: ${status.required.length > 0 ? status.required.join(", ") : "(none)"}`);
|
|
18
|
-
console.log(`active write: ${status.active_write_store ?? "(none \u2014 personal scope only)"}`);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
export {
|
|
22
|
-
status_default as default
|
|
23
|
-
};
|
package/dist/store-XB3ADT65.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
assertStoreMountable,
|
|
4
|
-
storeAdd,
|
|
5
|
-
storeBind,
|
|
6
|
-
storeCreate,
|
|
7
|
-
storeExplain,
|
|
8
|
-
storeList,
|
|
9
|
-
storeRemove,
|
|
10
|
-
storeSwitchWrite
|
|
11
|
-
} from "./chunk-4R2CYEA4.js";
|
|
12
|
-
import {
|
|
13
|
-
regenerateBindingsSnapshot
|
|
14
|
-
} from "./chunk-WU6GAPKH.js";
|
|
15
|
-
import "./chunk-L4Q55UC4.js";
|
|
16
|
-
import {
|
|
17
|
-
getProjectTranslator
|
|
18
|
-
} from "./chunk-2CY4BMTH.js";
|
|
19
|
-
import "./chunk-LFIKMVY7.js";
|
|
20
|
-
import "./chunk-RYAFBNES.js";
|
|
21
|
-
|
|
22
|
-
// src/commands/store.ts
|
|
23
|
-
import { defineCommand } from "citty";
|
|
24
|
-
var listCommand = defineCommand({
|
|
25
|
-
meta: { name: "list", description: "List mounted knowledge stores" },
|
|
26
|
-
run() {
|
|
27
|
-
const t = getProjectTranslator();
|
|
28
|
-
const stores = storeList();
|
|
29
|
-
if (stores.length === 0) {
|
|
30
|
-
console.log(t("cli.store.none-mounted"));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const localOnly = t("cli.shared.local-only");
|
|
34
|
-
for (const store of stores) {
|
|
35
|
-
console.log(`${store.alias} ${store.store_uuid} ${store.remote ?? localOnly}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
var addCommand = defineCommand({
|
|
40
|
-
meta: { name: "add", description: "Mount a knowledge store into the global registry" },
|
|
41
|
-
args: {
|
|
42
|
-
uuid: { type: "string", required: true, description: "Intrinsic store UUID" },
|
|
43
|
-
alias: { type: "string", required: true, description: "Local alias for this store" },
|
|
44
|
-
remote: { type: "string", description: "Git remote locator (omit for local-only)" }
|
|
45
|
-
},
|
|
46
|
-
run({ args }) {
|
|
47
|
-
assertStoreMountable(args.uuid);
|
|
48
|
-
const store = args.remote === void 0 ? { store_uuid: args.uuid, alias: args.alias } : { store_uuid: args.uuid, alias: args.alias, remote: args.remote };
|
|
49
|
-
const next = storeAdd(store);
|
|
50
|
-
console.log(
|
|
51
|
-
getProjectTranslator()("cli.store.mounted", {
|
|
52
|
-
alias: args.alias,
|
|
53
|
-
count: String(next.stores.length)
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
var createCommand = defineCommand({
|
|
59
|
-
meta: { name: "create", description: "Create a brand-new local knowledge store and mount it" },
|
|
60
|
-
args: {
|
|
61
|
-
alias: { type: "string", required: true, description: "Local alias for the new store" },
|
|
62
|
-
remote: { type: "string", description: "Git remote to associate (push target; optional)" }
|
|
63
|
-
},
|
|
64
|
-
run({ args }) {
|
|
65
|
-
const result = storeCreate(args.alias, (/* @__PURE__ */ new Date()).toISOString(), {
|
|
66
|
-
...args.remote === void 0 ? {} : { remote: args.remote }
|
|
67
|
-
});
|
|
68
|
-
const t = getProjectTranslator();
|
|
69
|
-
console.log(
|
|
70
|
-
t("cli.store.created", { alias: args.alias, uuid: result.store_uuid, dir: result.storeDir }) + (args.remote === void 0 ? `
|
|
71
|
-
${t("cli.store.created-local-hint")}` : "")
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
var removeCommand = defineCommand({
|
|
76
|
-
meta: { name: "remove", description: "Detach a store from the registry (does NOT delete it)" },
|
|
77
|
-
args: {
|
|
78
|
-
alias: { type: "positional", required: true, description: "Alias to detach" }
|
|
79
|
-
},
|
|
80
|
-
run({ args }) {
|
|
81
|
-
const { detached } = storeRemove(args.alias);
|
|
82
|
-
const t = getProjectTranslator();
|
|
83
|
-
console.log(
|
|
84
|
-
detached === null ? t("cli.store.no-alias", { alias: args.alias }) : t("cli.store.detached", { alias: args.alias })
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
var explainCommand = defineCommand({
|
|
89
|
-
meta: { name: "explain", description: "Explain how a store alias resolves" },
|
|
90
|
-
args: {
|
|
91
|
-
alias: { type: "positional", required: true, description: "Alias to explain" }
|
|
92
|
-
},
|
|
93
|
-
run({ args }) {
|
|
94
|
-
const explanation = storeExplain(args.alias);
|
|
95
|
-
console.log(
|
|
96
|
-
explanation === null ? getProjectTranslator()("cli.store.no-alias", { alias: args.alias }) : JSON.stringify(explanation, null, 2)
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
var bindCommand = defineCommand({
|
|
101
|
-
meta: { name: "bind", description: "Declare a required store on this project's config" },
|
|
102
|
-
args: {
|
|
103
|
-
id: { type: "positional", required: true, description: "Store alias/UUID to require" },
|
|
104
|
-
remote: { type: "string", description: "Suggested remote for clone onboarding" }
|
|
105
|
-
},
|
|
106
|
-
run({ args }) {
|
|
107
|
-
const entry = args.remote === void 0 ? { id: args.id } : { id: args.id, suggested_remote: args.remote };
|
|
108
|
-
const projectRoot = process.cwd();
|
|
109
|
-
const next = storeBind(projectRoot, entry);
|
|
110
|
-
console.log(
|
|
111
|
-
getProjectTranslator(projectRoot)("cli.store.bound", {
|
|
112
|
-
id: args.id,
|
|
113
|
-
count: String(next.required_stores?.length ?? 0)
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
regenerateBindingsSnapshot(projectRoot, { now: (/* @__PURE__ */ new Date()).toISOString() });
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
var switchWriteCommand = defineCommand({
|
|
120
|
-
meta: { name: "switch-write", description: "Set the active write store for non-personal scopes" },
|
|
121
|
-
args: {
|
|
122
|
-
alias: { type: "positional", required: true, description: "Alias of the store to write to" }
|
|
123
|
-
},
|
|
124
|
-
run({ args }) {
|
|
125
|
-
const projectRoot = process.cwd();
|
|
126
|
-
storeSwitchWrite(projectRoot, args.alias);
|
|
127
|
-
console.log(getProjectTranslator(projectRoot)("cli.store.switch-write", { alias: args.alias }));
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
var store_default = defineCommand({
|
|
131
|
-
meta: { name: "store", description: "Manage mounted Fabric knowledge stores" },
|
|
132
|
-
subCommands: {
|
|
133
|
-
list: listCommand,
|
|
134
|
-
create: createCommand,
|
|
135
|
-
add: addCommand,
|
|
136
|
-
remove: removeCommand,
|
|
137
|
-
explain: explainCommand,
|
|
138
|
-
bind: bindCommand,
|
|
139
|
-
"switch-write": switchWriteCommand
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
export {
|
|
143
|
-
store_default as default
|
|
144
|
-
};
|
package/dist/whoami-2MLO4Y37.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
getProjectTranslator
|
|
4
|
-
} from "./chunk-2CY4BMTH.js";
|
|
5
|
-
import {
|
|
6
|
-
whoami
|
|
7
|
-
} from "./chunk-T5RPGCCM.js";
|
|
8
|
-
import "./chunk-LFIKMVY7.js";
|
|
9
|
-
import "./chunk-RYAFBNES.js";
|
|
10
|
-
|
|
11
|
-
// src/commands/whoami.ts
|
|
12
|
-
import { defineCommand } from "citty";
|
|
13
|
-
var whoami_default = defineCommand({
|
|
14
|
-
meta: { name: "whoami", description: "Show this machine's Fabric uid and mounted stores" },
|
|
15
|
-
run() {
|
|
16
|
-
const t = getProjectTranslator();
|
|
17
|
-
const info = whoami();
|
|
18
|
-
if (info === null) {
|
|
19
|
-
console.log(t("cli.cmd.no-global-config"));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
console.log(t("cli.whoami.uid", { uid: info.uid }));
|
|
23
|
-
if (info.stores.length === 0) {
|
|
24
|
-
console.log(t("cli.whoami.stores-none"));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
console.log(t("cli.whoami.stores-label"));
|
|
28
|
-
const localOnly = t("cli.shared.local-only");
|
|
29
|
-
for (const store of info.stores) {
|
|
30
|
-
console.log(` ${store.alias} ${store.store_uuid}${store.local_only ? ` ${localOnly}` : ""}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
export {
|
|
35
|
-
whoami_default as default
|
|
36
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"hooks": {
|
|
4
|
-
"stop": [
|
|
5
|
-
{ "command": ".cursor/hooks/fabric-hint.cjs" }
|
|
6
|
-
],
|
|
7
|
-
"sessionStart": [
|
|
8
|
-
{ "command": ".cursor/hooks/knowledge-hint-broad.cjs" },
|
|
9
|
-
{ "command": ".cursor/hooks/cite-policy-evict.cjs" }
|
|
10
|
-
],
|
|
11
|
-
"preToolUse": [
|
|
12
|
-
{
|
|
13
|
-
"matcher": "Edit|Write|MultiEdit",
|
|
14
|
-
"command": ".cursor/hooks/knowledge-hint-narrow.cjs"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
// v2.0.0-rc.24 TASK-05: L1 Stop hook soft reminder for missing cite contract.
|
|
2
|
-
//
|
|
3
|
-
// Reads `.fabric/agents.meta.json` to build a stable_id → knowledge_type lookup
|
|
4
|
-
// map, then scans summarised assistant turns (cite_ids + cite_tags +
|
|
5
|
-
// cite_commitments parallel arrays produced by lib/cite-line-parser.cjs) for
|
|
6
|
-
// turns that cited a decision-class or pitfall-class id with [applied] tag
|
|
7
|
-
// but no operator commitment and no skip:<reason>. (v2.1.0-rc.1 ADJ-P4-1:
|
|
8
|
-
// legacy [recalled] is remapped to [applied] by the parser upstream.)
|
|
9
|
-
//
|
|
10
|
-
// Emits one reminder line per offending id (deduplicated across the turn
|
|
11
|
-
// summary). Non-blocking — caller writes the lines to stderr; failure to
|
|
12
|
-
// load the meta file or absence of offenders means zero output.
|
|
13
|
-
//
|
|
14
|
-
// Reminder template (rc.24 lock B2 / L1 enforcement layer):
|
|
15
|
-
// ⚠ KB: <id> cited as [applied] but missing contract; add → edit:<glob>
|
|
16
|
-
// or → skip:<reason> next turn
|
|
17
|
-
//
|
|
18
|
-
// Type filter rationale: only `decision` and `pitfall` types are contract-
|
|
19
|
-
// required per rc.24 design lock B6 (idTypeMap routing). `model`,
|
|
20
|
-
// `guideline`, `process` use reference-cite or LLM-judge (deferred to rc.25+)
|
|
21
|
-
// and are intentionally skipped here to avoid false-positive nudges.
|
|
22
|
-
//
|
|
23
|
-
// agents.meta.json schema note: `description.knowledge_type` values are
|
|
24
|
-
// SINGULAR (`decision`, `pitfall`, `model`, `guideline`, `process`) per
|
|
25
|
-
// packages/shared/src/schemas/agents-meta.ts. The reminder filter normalises
|
|
26
|
-
// any plural input defensively but the canonical contract is singular.
|
|
27
|
-
//
|
|
28
|
-
// Reading happens once per hook invocation (caller passes the projectRoot;
|
|
29
|
-
// the lib does the fs read internally). The map is small (<200 entries in
|
|
30
|
-
// typical corpora) so caching beyond the per-invocation scope is unnecessary.
|
|
31
|
-
|
|
32
|
-
const { existsSync, readFileSync } = require("node:fs");
|
|
33
|
-
const { join } = require("node:path");
|
|
34
|
-
|
|
35
|
-
const FABRIC_DIR = ".fabric";
|
|
36
|
-
const AGENTS_META_FILE = "agents.meta.json";
|
|
37
|
-
|
|
38
|
-
// Knowledge types that require contract commitments on [applied] cites.
|
|
39
|
-
// Matches the singular form persisted by `withDerivedAgentsMetaNodeDefaults`
|
|
40
|
-
// in packages/shared/src/schemas/agents-meta.ts. We accept both singular
|
|
41
|
-
// and plural defensively so a future schema change to plurals doesn't
|
|
42
|
-
// silently break the filter.
|
|
43
|
-
const CONTRACT_REQUIRED_TYPES = new Set([
|
|
44
|
-
"decision",
|
|
45
|
-
"decisions",
|
|
46
|
-
"pitfall",
|
|
47
|
-
"pitfalls",
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Build a Map<stable_id, knowledge_type> from <projectRoot>/.fabric/agents.meta.json.
|
|
52
|
-
*
|
|
53
|
-
* Never throws — missing file, malformed JSON, missing nodes key, etc. all
|
|
54
|
-
* yield an empty Map. The caller's downstream filter then becomes a no-op
|
|
55
|
-
* (no id resolves → no reminders).
|
|
56
|
-
*
|
|
57
|
-
* @param {string} projectRoot - workspace root
|
|
58
|
-
* @returns {Map<string, string>} stable_id → knowledge_type (singular)
|
|
59
|
-
*/
|
|
60
|
-
function readKnowledgeTypeMap(projectRoot) {
|
|
61
|
-
const out = new Map();
|
|
62
|
-
if (typeof projectRoot !== "string" || projectRoot.length === 0) return out;
|
|
63
|
-
|
|
64
|
-
const metaPath = join(projectRoot, FABRIC_DIR, AGENTS_META_FILE);
|
|
65
|
-
if (!existsSync(metaPath)) return out;
|
|
66
|
-
|
|
67
|
-
let raw;
|
|
68
|
-
try {
|
|
69
|
-
raw = readFileSync(metaPath, "utf8");
|
|
70
|
-
} catch {
|
|
71
|
-
return out;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let parsed;
|
|
75
|
-
try {
|
|
76
|
-
parsed = JSON.parse(raw);
|
|
77
|
-
} catch {
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (parsed === null || typeof parsed !== "object") return out;
|
|
82
|
-
const nodes = parsed.nodes;
|
|
83
|
-
if (nodes === null || typeof nodes !== "object") return out;
|
|
84
|
-
|
|
85
|
-
for (const [id, node] of Object.entries(nodes)) {
|
|
86
|
-
if (node === null || typeof node !== "object") continue;
|
|
87
|
-
const description = node.description;
|
|
88
|
-
if (description === null || typeof description !== "object") continue;
|
|
89
|
-
const kt = description.knowledge_type;
|
|
90
|
-
if (typeof kt !== "string" || kt.length === 0) continue;
|
|
91
|
-
out.set(id, kt);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return out;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Scan parsed assistant turns for cites that should have a contract but
|
|
99
|
-
* don't, returning the reminder lines to emit.
|
|
100
|
-
*
|
|
101
|
-
* Filter (all must hold for a given index i within a turn):
|
|
102
|
-
* 1. cite_tags includes "applied" (turn-level — applies to the cited id)
|
|
103
|
-
* 2. cite_commitments[i].operators is empty AND cite_commitments[i].skip_reason is null
|
|
104
|
-
* 3. idTypeMap.get(cite_ids[i]) is in {decision, pitfall}
|
|
105
|
-
*
|
|
106
|
-
* v2.1.0-rc.1 (ADJ-P4-1, full remap): the gate is the rc.37 NEW-1 `applied`
|
|
107
|
-
* tag. Legacy [recalled] cites are remapped to [applied] by the parser before
|
|
108
|
-
* they reach here, so gating on "applied" covers both old and new authoring.
|
|
109
|
-
*
|
|
110
|
-
* Tag-level filter clarification: rc.20 cite_tags is parallel to ALL parsed
|
|
111
|
-
* lines (including sentinels), but for the contract-missing reminder we use
|
|
112
|
-
* the turn-level semantic — if the assistant tagged the cite as [applied],
|
|
113
|
-
* the operator-or-skip contract applies. Per TASK-04 invariant, cite_ids and
|
|
114
|
-
* cite_commitments are parallel index-aligned arrays (length-N each).
|
|
115
|
-
*
|
|
116
|
-
* Sentinel turns (cite_ids=[], cite_tags=["none"]) contribute no offenders
|
|
117
|
-
* because the cite_ids loop has zero iterations.
|
|
118
|
-
*
|
|
119
|
-
* Offenders are deduplicated by id across the entire turn array; multiple
|
|
120
|
-
* turns citing the same id yield ONE reminder line.
|
|
121
|
-
*
|
|
122
|
-
* @param {Object} args
|
|
123
|
-
* @param {Array<{cite_ids: string[], cite_tags: string[], cite_commitments: Array<{operators: Array<unknown>, skip_reason: string|null}>}>} args.assistant_turns
|
|
124
|
-
* @param {Map<string, string>} args.idTypeMap
|
|
125
|
-
* @returns {string[]} reminder lines (empty when no offenders)
|
|
126
|
-
*/
|
|
127
|
-
function formatContractMissingReminders({ assistant_turns, idTypeMap }) {
|
|
128
|
-
if (!Array.isArray(assistant_turns) || assistant_turns.length === 0) return [];
|
|
129
|
-
if (!(idTypeMap instanceof Map) || idTypeMap.size === 0) return [];
|
|
130
|
-
|
|
131
|
-
const offenders = new Set();
|
|
132
|
-
|
|
133
|
-
for (const turn of assistant_turns) {
|
|
134
|
-
if (turn === null || typeof turn !== "object") continue;
|
|
135
|
-
const citeIds = Array.isArray(turn.cite_ids) ? turn.cite_ids : [];
|
|
136
|
-
const citeTags = Array.isArray(turn.cite_tags) ? turn.cite_tags : [];
|
|
137
|
-
const commitments = Array.isArray(turn.cite_commitments) ? turn.cite_commitments : [];
|
|
138
|
-
|
|
139
|
-
// Turn-level: the [applied] tag must appear in the turn's tag set
|
|
140
|
-
// (v2.1.0-rc.1 ADJ-P4-1: legacy [recalled] is remapped to [applied]).
|
|
141
|
-
if (!citeTags.includes("applied")) continue;
|
|
142
|
-
|
|
143
|
-
// Iterate by cite_ids.length — sentinel entries don't have ids so they
|
|
144
|
-
// contribute zero iterations even if cite_tags carries "none".
|
|
145
|
-
for (let i = 0; i < citeIds.length; i += 1) {
|
|
146
|
-
const id = citeIds[i];
|
|
147
|
-
if (typeof id !== "string" || id.length === 0) continue;
|
|
148
|
-
|
|
149
|
-
const type = idTypeMap.get(id);
|
|
150
|
-
if (!CONTRACT_REQUIRED_TYPES.has(type)) continue;
|
|
151
|
-
|
|
152
|
-
const commitment = commitments[i];
|
|
153
|
-
if (commitment === null || typeof commitment !== "object") continue;
|
|
154
|
-
const operators = Array.isArray(commitment.operators) ? commitment.operators : [];
|
|
155
|
-
const skipReason = commitment.skip_reason;
|
|
156
|
-
const hasContract = operators.length > 0 || (typeof skipReason === "string" && skipReason.length > 0);
|
|
157
|
-
if (hasContract) continue;
|
|
158
|
-
|
|
159
|
-
offenders.add(id);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (offenders.size === 0) return [];
|
|
164
|
-
|
|
165
|
-
// Stable order: insertion order is the order ids first appeared across turns.
|
|
166
|
-
const reminders = [];
|
|
167
|
-
for (const id of offenders) {
|
|
168
|
-
reminders.push(
|
|
169
|
-
`⚠ KB: ${id} cited as [applied] but missing contract; add \`→ edit:<glob>\` or \`→ skip:<reason>\` next turn`,
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
return reminders;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
module.exports = {
|
|
176
|
-
readKnowledgeTypeMap,
|
|
177
|
-
formatContractMissingReminders,
|
|
178
|
-
CONTRACT_REQUIRED_TYPES,
|
|
179
|
-
};
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* rc.35 TASK-06 (P0-10.b) — summary-fallback library.
|
|
3
|
-
*
|
|
4
|
-
* Resolves opaque hint entries (where `entry.summary === entry.id` so the
|
|
5
|
-
* AI sees no information beyond the id) by reading the entry's markdown
|
|
6
|
-
* file at `.fabric/knowledge/<type>/<id>--<slug>.md`, extracting the first
|
|
7
|
-
* paragraph under `## Summary`, and substituting that text into the entry
|
|
8
|
-
* before the hook renders it.
|
|
9
|
-
*
|
|
10
|
-
* Caching: results are stored in `.fabric/.cache/summary-fallback.json`
|
|
11
|
-
* keyed by the current `revision_hash` returned by plan-context-hint. The
|
|
12
|
-
* cache is wiped wholesale when the revision changes (cheap invariant —
|
|
13
|
-
* any meta rev bump implies entry text MAY have moved). Per-process call
|
|
14
|
-
* also benefits from in-memory dedup since the same opaque id may appear
|
|
15
|
-
* across narrow + broad paths.
|
|
16
|
-
*
|
|
17
|
-
* Design contract:
|
|
18
|
-
* - Never throw. ANY failure (cache read, fs scan, file read) degrades
|
|
19
|
-
* to a no-op — the original opaque summary is left untouched. Hooks
|
|
20
|
-
* must remain best-effort.
|
|
21
|
-
* - Idempotent over identical inputs. Two calls in succession with the
|
|
22
|
-
* same revision_hash + entries set produce zero disk reads on the
|
|
23
|
-
* second call.
|
|
24
|
-
*
|
|
25
|
-
* Public API (module.exports):
|
|
26
|
-
* resolveOpaqueSummaries(entries, projectRoot, revisionHash) — returns
|
|
27
|
-
* a NEW array of entries with `summary` substituted for opaque cases.
|
|
28
|
-
* Original `entry.id` is preserved verbatim.
|
|
29
|
-
*
|
|
30
|
-
* _extractFirstSummaryParagraph(md) — pure helper, exposed for testing.
|
|
31
|
-
*
|
|
32
|
-
* _readCache / _writeCache — exposed for testing.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
const { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } = require("node:fs");
|
|
36
|
-
const { join } = require("node:path");
|
|
37
|
-
|
|
38
|
-
const CACHE_DIR_REL = ".fabric/.cache";
|
|
39
|
-
const CACHE_FILE_REL = ".fabric/.cache/summary-fallback.json";
|
|
40
|
-
const KNOWLEDGE_DIR_REL = ".fabric/knowledge";
|
|
41
|
-
const SUMMARY_MAX_LEN = 80;
|
|
42
|
-
const KNOWLEDGE_TYPE_DIRS = ["decisions", "pitfalls", "guidelines", "models", "processes"];
|
|
43
|
-
|
|
44
|
-
function _isOpaque(entry) {
|
|
45
|
-
if (!entry || typeof entry.id !== "string" || typeof entry.summary !== "string") {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return entry.summary.trim() === entry.id.trim();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Pure helper: extract the first paragraph under a `## Summary` heading.
|
|
53
|
-
*
|
|
54
|
-
* - `## Summary` is case-insensitive but level-sensitive (only H2).
|
|
55
|
-
* - First paragraph = lines until blank line or next heading.
|
|
56
|
-
* - Collapses whitespace + trims; returns `""` if no summary section or
|
|
57
|
-
* the section is empty.
|
|
58
|
-
*/
|
|
59
|
-
function _extractFirstSummaryParagraph(md) {
|
|
60
|
-
if (typeof md !== "string" || md.length === 0) return "";
|
|
61
|
-
const lines = md.split(/\r?\n/);
|
|
62
|
-
let i = 0;
|
|
63
|
-
while (i < lines.length) {
|
|
64
|
-
if (/^##\s+summary\s*$/i.test(lines[i].trim())) {
|
|
65
|
-
i += 1;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
i += 1;
|
|
69
|
-
}
|
|
70
|
-
if (i >= lines.length) return "";
|
|
71
|
-
// Skip blank lines after the heading
|
|
72
|
-
while (i < lines.length && lines[i].trim().length === 0) i += 1;
|
|
73
|
-
// Collect until the next blank line or next heading
|
|
74
|
-
const buf = [];
|
|
75
|
-
while (i < lines.length) {
|
|
76
|
-
const line = lines[i];
|
|
77
|
-
if (line.trim().length === 0) break;
|
|
78
|
-
if (/^#{1,6}\s/.test(line.trim())) break;
|
|
79
|
-
buf.push(line.trim());
|
|
80
|
-
i += 1;
|
|
81
|
-
}
|
|
82
|
-
const flat = buf.join(" ").replace(/\s+/g, " ").trim();
|
|
83
|
-
if (flat.length === 0) return "";
|
|
84
|
-
if (flat.length <= SUMMARY_MAX_LEN) return flat;
|
|
85
|
-
return `${flat.slice(0, SUMMARY_MAX_LEN - 1)}…`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function _readCache(projectRoot) {
|
|
89
|
-
const cachePath = join(projectRoot, CACHE_FILE_REL);
|
|
90
|
-
if (!existsSync(cachePath)) return null;
|
|
91
|
-
try {
|
|
92
|
-
const raw = readFileSync(cachePath, "utf8");
|
|
93
|
-
const parsed = JSON.parse(raw);
|
|
94
|
-
if (parsed && typeof parsed === "object" && typeof parsed.revision === "string" && parsed.summaries && typeof parsed.summaries === "object") {
|
|
95
|
-
return parsed;
|
|
96
|
-
}
|
|
97
|
-
} catch {
|
|
98
|
-
// ignore — caller treats null as no-cache
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function _writeCache(projectRoot, payload) {
|
|
104
|
-
try {
|
|
105
|
-
const cacheDir = join(projectRoot, CACHE_DIR_REL);
|
|
106
|
-
if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
|
|
107
|
-
const cachePath = join(projectRoot, CACHE_FILE_REL);
|
|
108
|
-
writeFileSync(cachePath, JSON.stringify(payload), "utf8");
|
|
109
|
-
} catch {
|
|
110
|
-
// Best-effort — failing to persist cache is not an error
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Scan `.fabric/knowledge/<type>/` for the canonical `<id>--<slug>.md`
|
|
116
|
-
* matching `stableId`. Tries the most likely type-dir first based on the
|
|
117
|
-
* entry's `type` hint, then falls back to scanning all canonical type
|
|
118
|
-
* directories. Returns the absolute path or null.
|
|
119
|
-
*
|
|
120
|
-
* The id→file mapping is unique by construction (stable_id is allocated
|
|
121
|
-
* once per file), so the first match wins.
|
|
122
|
-
*/
|
|
123
|
-
function _findEntryFile(projectRoot, stableId, typeHint) {
|
|
124
|
-
const baseDir = join(projectRoot, KNOWLEDGE_DIR_REL);
|
|
125
|
-
if (!existsSync(baseDir)) return null;
|
|
126
|
-
const tryOrder = [];
|
|
127
|
-
if (typeof typeHint === "string" && typeHint.length > 0) {
|
|
128
|
-
// Accept both singular and plural hints — find the plural form.
|
|
129
|
-
const lower = typeHint.toLowerCase();
|
|
130
|
-
const plural = KNOWLEDGE_TYPE_DIRS.find((d) => d === lower || d.startsWith(lower));
|
|
131
|
-
if (plural) tryOrder.push(plural);
|
|
132
|
-
}
|
|
133
|
-
for (const t of KNOWLEDGE_TYPE_DIRS) {
|
|
134
|
-
if (!tryOrder.includes(t)) tryOrder.push(t);
|
|
135
|
-
}
|
|
136
|
-
const prefix = `${stableId}--`;
|
|
137
|
-
for (const t of tryOrder) {
|
|
138
|
-
const typeDir = join(baseDir, t);
|
|
139
|
-
if (!existsSync(typeDir)) continue;
|
|
140
|
-
let files;
|
|
141
|
-
try {
|
|
142
|
-
files = readdirSync(typeDir);
|
|
143
|
-
} catch {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
for (const f of files) {
|
|
147
|
-
if (f.startsWith(prefix) && f.endsWith(".md")) {
|
|
148
|
-
return join(typeDir, f);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function _resolveOne(projectRoot, entry) {
|
|
156
|
-
const filePath = _findEntryFile(projectRoot, entry.id, entry.type);
|
|
157
|
-
if (filePath === null) return "";
|
|
158
|
-
let md;
|
|
159
|
-
try {
|
|
160
|
-
md = readFileSync(filePath, "utf8");
|
|
161
|
-
} catch {
|
|
162
|
-
return "";
|
|
163
|
-
}
|
|
164
|
-
return _extractFirstSummaryParagraph(md);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Main API. Returns a new array of entries with `summary` swapped for
|
|
169
|
-
* the extracted fallback wherever the original summary was opaque AND
|
|
170
|
-
* the fallback extraction yielded a non-empty string. Non-opaque entries
|
|
171
|
-
* pass through unchanged.
|
|
172
|
-
*/
|
|
173
|
-
function resolveOpaqueSummaries(entries, projectRoot, revisionHash) {
|
|
174
|
-
if (!Array.isArray(entries) || entries.length === 0) return entries;
|
|
175
|
-
const cache = _readCache(projectRoot);
|
|
176
|
-
const cachedSummaries = cache && cache.revision === revisionHash && cache.summaries ? cache.summaries : {};
|
|
177
|
-
const nextCacheSummaries = { ...cachedSummaries };
|
|
178
|
-
let cacheChanged = cache === null || cache.revision !== revisionHash;
|
|
179
|
-
const result = entries.map((entry) => {
|
|
180
|
-
if (!_isOpaque(entry)) return entry;
|
|
181
|
-
const id = entry.id;
|
|
182
|
-
let fallback;
|
|
183
|
-
if (Object.prototype.hasOwnProperty.call(cachedSummaries, id)) {
|
|
184
|
-
fallback = cachedSummaries[id];
|
|
185
|
-
} else {
|
|
186
|
-
fallback = _resolveOne(projectRoot, entry);
|
|
187
|
-
nextCacheSummaries[id] = fallback;
|
|
188
|
-
cacheChanged = true;
|
|
189
|
-
}
|
|
190
|
-
if (typeof fallback === "string" && fallback.length > 0) {
|
|
191
|
-
return { ...entry, summary: fallback };
|
|
192
|
-
}
|
|
193
|
-
return entry;
|
|
194
|
-
});
|
|
195
|
-
if (cacheChanged) {
|
|
196
|
-
_writeCache(projectRoot, { revision: revisionHash, summaries: nextCacheSummaries });
|
|
197
|
-
}
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
module.exports = {
|
|
202
|
-
resolveOpaqueSummaries,
|
|
203
|
-
_extractFirstSummaryParagraph,
|
|
204
|
-
_readCache,
|
|
205
|
-
_writeCache,
|
|
206
|
-
_findEntryFile,
|
|
207
|
-
_isOpaque,
|
|
208
|
-
SUMMARY_MAX_LEN,
|
|
209
|
-
KNOWLEDGE_TYPE_DIRS,
|
|
210
|
-
};
|