@clay-design-system/kb 0.0.0-stage → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/contract.d.ts +227 -0
  2. package/dist/contract.d.ts.map +1 -0
  3. package/dist/contract.js +134 -0
  4. package/dist/contract.js.map +1 -0
  5. package/dist/core/memory.d.ts +20 -0
  6. package/dist/core/memory.d.ts.map +1 -0
  7. package/dist/core/memory.js +23 -0
  8. package/dist/core/memory.js.map +1 -0
  9. package/dist/core/model.d.ts +47 -0
  10. package/dist/core/model.d.ts.map +1 -0
  11. package/dist/core/model.js +21 -0
  12. package/dist/core/model.js.map +1 -0
  13. package/dist/core/prose.d.ts +40 -0
  14. package/dist/core/prose.d.ts.map +1 -0
  15. package/dist/core/prose.js +106 -0
  16. package/dist/core/prose.js.map +1 -0
  17. package/dist/core/query.d.ts +87 -0
  18. package/dist/core/query.d.ts.map +1 -0
  19. package/dist/core/query.js +637 -0
  20. package/dist/core/query.js.map +1 -0
  21. package/dist/core/rank.d.ts +123 -0
  22. package/dist/core/rank.d.ts.map +1 -0
  23. package/dist/core/rank.js +429 -0
  24. package/dist/core/rank.js.map +1 -0
  25. package/dist/core/route-email.d.ts +48 -0
  26. package/dist/core/route-email.d.ts.map +1 -0
  27. package/dist/core/route-email.js +172 -0
  28. package/dist/core/route-email.js.map +1 -0
  29. package/dist/core/route.d.ts +431 -0
  30. package/dist/core/route.d.ts.map +1 -0
  31. package/dist/core/route.js +1769 -0
  32. package/dist/core/route.js.map +1 -0
  33. package/dist/core/search.d.ts +64 -0
  34. package/dist/core/search.d.ts.map +1 -0
  35. package/dist/core/search.js +123 -0
  36. package/dist/core/search.js.map +1 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/snapshot-email.json +1 -0
  42. package/dist/snapshot-foundations.json +1 -0
  43. package/dist/snapshot-web.json +1 -0
  44. package/package.json +28 -3
  45. package/README.md +0 -3
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Public query contract for `@clay-design-system/kb`.
3
+ *
4
+ * One query layer (Registry D4): the Clay CLI and `kb:mcp` call `createClayKb`, and Marko calls the
5
+ * same methods. Argument names and types match `scripts/kb/mcp.ts` (`clay_search`, `clay_get`,
6
+ * `clay_section`, `clay_rules`, `clay_route`). `route` takes the brief inline. There is no
7
+ * `briefPath` on this package — callers that have a file read it themselves and pass `brief`.
8
+ *
9
+ * `text` is the compact Markdown an agent reads. `data` is the same answer as structured fields
10
+ * (Registry "detail"). `clay_check_copy` stays on the CLI; it reads a page file.
11
+ *
12
+ * The published package ships three snapshots (Registry D11, public npm): `snapshot-web.json`,
13
+ * `snapshot-foundations.json` (tokens, icons, logos), and `snapshot-email.json`. Marko loads web
14
+ * and foundations together via `createClayKbFromSlices`. These argument shapes still accept
15
+ * `email`, `ds`, and `includeBackground`. A slice that does not contain those units returns no hits.
16
+ */
17
+ export declare const CLAY_KB_SCHEMA_VERSION: 1;
18
+ export declare const CLAY_STAGES: readonly ["structure", "mapping", "design", "assets", "copy", "page-file", "ux", "qa", "static", "fidelity"];
19
+ export type ClayStage = (typeof CLAY_STAGES)[number];
20
+ export declare const CLAY_MODES: readonly ["A", "B"];
21
+ export type ClayMode = (typeof CLAY_MODES)[number];
22
+ /** Values `clay_search` accepts for `scope`. Default when omitted: web + ds + shared. */
23
+ export declare const CLAY_SEARCH_SCOPES: readonly ["web", "ds", "shared", "email", "all"];
24
+ export type ClaySearchScope = (typeof CLAY_SEARCH_SCOPES)[number];
25
+ export declare const CLAY_RULE_SCOPES: readonly ["web", "email"];
26
+ export type ClayRuleScope = (typeof CLAY_RULE_SCOPES)[number];
27
+ export interface ClayKbResult<TData> {
28
+ text: string;
29
+ data: TData;
30
+ }
31
+ /** In-memory dedupe state. The package never reads or writes a session file. Marko omits this. */
32
+ export interface ClayKbSession {
33
+ served: Record<string, string>;
34
+ lines: Record<string, string>;
35
+ layouts: string[];
36
+ sections: string[];
37
+ stages: string[];
38
+ }
39
+ export interface ClayKbOptions {
40
+ session?: ClayKbSession;
41
+ }
42
+ export interface ClaySearchArgs {
43
+ query: string;
44
+ /** How many hits. Default 10. */
45
+ k?: number;
46
+ kind?: string[];
47
+ /** Entity ids, e.g. `section:FeaturesSection`. */
48
+ entity?: string[];
49
+ stage?: ClayStage[];
50
+ mode?: ClayMode;
51
+ scope?: ClaySearchScope[];
52
+ includeBackground?: boolean;
53
+ }
54
+ export interface ClaySearchHit {
55
+ id: string;
56
+ /** BM25F score, rounded to 3 decimal places. */
57
+ score: number;
58
+ kind: string;
59
+ authority: string;
60
+ summary: string;
61
+ /** File-level asset twins folded into this registry hit (one hit per logo), when there are any. */
62
+ aliases?: string[];
63
+ }
64
+ export interface ClaySearchData {
65
+ hits: ClaySearchHit[];
66
+ }
67
+ export interface ClayGetArgs {
68
+ /** An id ending in `*` expands to that prefix (at most 25). */
69
+ ids: string[];
70
+ }
71
+ export interface ClayKbUnitRelations {
72
+ supersedes?: string[];
73
+ conflictsWith?: string[];
74
+ seeAlso?: string[];
75
+ precedence?: string[];
76
+ }
77
+ export interface ClayKbUnit {
78
+ id: string;
79
+ kind: string;
80
+ scope: 'web' | 'email' | 'ds' | 'shared';
81
+ topic: string;
82
+ authority: 'canonical' | 'derived' | 'guidance' | 'background';
83
+ stages: ClayStage[];
84
+ modes?: ClayMode[];
85
+ entities: string[];
86
+ summary: string;
87
+ body: string;
88
+ when?: string;
89
+ notWhen?: string;
90
+ severity?: 'Critical' | 'Major' | 'Minor';
91
+ enforcement?: ('lint' | 'script' | 'test' | 'qa' | 'review' | 'types')[];
92
+ relations?: ClayKbUnitRelations;
93
+ source?: {
94
+ path: string;
95
+ anchor?: string;
96
+ generatedBy?: string;
97
+ };
98
+ status: 'active' | 'deprecated';
99
+ verifiedAt?: string;
100
+ handbookId?: string;
101
+ data?: unknown;
102
+ facts?: unknown;
103
+ }
104
+ export interface ClayGetData {
105
+ units: ClayKbUnit[];
106
+ missing: string[];
107
+ /** Ids already served on `options.session`. Always empty when no session was passed. */
108
+ repeated: string[];
109
+ }
110
+ export interface ClaySectionArgs {
111
+ /** e.g. `FeaturesSection`. */
112
+ name: string;
113
+ /** e.g. `tab-cards-carousel`. Several layouts may be comma-separated. */
114
+ layout?: string;
115
+ }
116
+ export interface ClaySectionData {
117
+ section: string;
118
+ layout?: string;
119
+ units: string[];
120
+ }
121
+ export interface ClayRulesArgs {
122
+ stage?: ClayStage;
123
+ mode?: ClayMode;
124
+ /** `email` lists email rules. `web` and omitted both list the non-email rules. */
125
+ scope?: ClayRuleScope;
126
+ }
127
+ export interface ClayRulesData {
128
+ units: string[];
129
+ }
130
+ export interface ClayRouteArgs {
131
+ /** Skill running the stage, e.g. `web-compose`. */
132
+ skill: string;
133
+ stage: ClayStage;
134
+ /** web-compose mode: A = page brief, B = PMM brief. */
135
+ mode?: ClayMode;
136
+ /** Brief text (Markdown), inline. This package has no `briefPath`. */
137
+ brief?: string;
138
+ /** Token budget. Default 2500. */
139
+ budget?: number;
140
+ }
141
+ export interface ClayBriefSection {
142
+ n: number;
143
+ title: string;
144
+ text: string;
145
+ items: number | null;
146
+ }
147
+ export interface ClayBriefRow {
148
+ section: ClayBriefSection;
149
+ candidates: {
150
+ id: string;
151
+ line: string;
152
+ fit: 'fits' | 'over' | 'under' | 'unknown';
153
+ }[];
154
+ }
155
+ export interface ClayRouteData {
156
+ tokens: number;
157
+ budget: number;
158
+ units: {
159
+ id: string;
160
+ tier: string;
161
+ inlined: 'body' | 'summary' | 'id';
162
+ }[];
163
+ brief: ClayBriefRow[];
164
+ }
165
+ export type ClayIndexField = 'id' | 'summary' | 'entities' | 'topic' | 'when' | 'body';
166
+ export type ClayIndexAvg = Record<ClayIndexField, number>;
167
+ export interface ClaySerializedSearchIndex {
168
+ fingerprint: string;
169
+ n: number;
170
+ avg: ClayIndexAvg;
171
+ channels?: Record<'web' | 'email' | 'all', {
172
+ n: number;
173
+ avg: ClayIndexAvg;
174
+ }>;
175
+ docs: {
176
+ id: string;
177
+ len: ClayIndexAvg;
178
+ email?: 1;
179
+ }[];
180
+ /** term → [docIndex, field term-frequencies in ClayIndexField order] */
181
+ postings: [string, [number, number[]][]][];
182
+ /** lower-case entity name → entity ids */
183
+ entityNames: [string, string[]][];
184
+ }
185
+ export interface ClayKbCounts {
186
+ units: number;
187
+ hand?: number;
188
+ derived?: number;
189
+ byKind?: Record<string, number>;
190
+ byAuthority?: Record<string, number>;
191
+ byScope?: Record<string, number>;
192
+ }
193
+ /**
194
+ * Prebuilt knowledge passed to `createClayKb`. Plain JSON (`packages/kb` export `./snapshot.json`).
195
+ * `generatedFromSha` is the git sha the snapshot was built from, or null for a local build.
196
+ */
197
+ export type ClayKbSlice = 'web' | 'foundations' | 'email';
198
+ export interface ClayKbSnapshot {
199
+ schemaVersion: typeof CLAY_KB_SCHEMA_VERSION;
200
+ packageVersion: string;
201
+ generatedFromSha: string | null;
202
+ /** Which file this snapshot is. Absent on a snapshot merged by `createClayKbFromSlices`. */
203
+ slice?: ClayKbSlice;
204
+ fingerprint: string;
205
+ counts: ClayKbCounts;
206
+ units: ClayKbUnit[];
207
+ index: ClaySerializedSearchIndex;
208
+ }
209
+ export interface ClayKb {
210
+ search(args: ClaySearchArgs): ClayKbResult<ClaySearchData>;
211
+ get(args: ClayGetArgs): ClayKbResult<ClayGetData>;
212
+ section(args: ClaySectionArgs): ClayKbResult<ClaySectionData>;
213
+ rules(args: ClayRulesArgs): ClayKbResult<ClayRulesData>;
214
+ route(args: ClayRouteArgs): ClayKbResult<ClayRouteData>;
215
+ }
216
+ /**
217
+ * Query layer over an in-memory snapshot. No filesystem and no `process.cwd`.
218
+ * Invalid arguments and an unknown section or stage throw `Error`.
219
+ * Search with no hits, and get with missing ids, return `{ text, data }` and do not throw.
220
+ */
221
+ /**
222
+ * One query layer over several snapshots. Marko passes web + foundations. The index is rebuilt
223
+ * from the stored unit text so scores cover every slice, not one file at a time.
224
+ */
225
+ export declare function createClayKbFromSlices(snapshots: ClayKbSnapshot[], options?: ClayKbOptions): ClayKb;
226
+ export declare function createClayKb(snapshot: ClayKbSnapshot, options?: ClayKbOptions): ClayKb;
227
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAA;AAEhD,eAAO,MAAM,WAAW,8GAWd,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpD,eAAO,MAAM,UAAU,qBAAsB,CAAA;AAC7C,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AAElD,yFAAyF;AACzF,eAAO,MAAM,kBAAkB,kDAAmD,CAAA;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjE,eAAO,MAAM,gBAAgB,2BAA4B,CAAA;AACzD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,kGAAkG;AAClG,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,MAAM,WAAW,aAA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AA4F;IAC5F,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,KAAK,EAAE,yBAAyB,CAAA;CACjC;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC,CAAA;IAC1D,GAAG,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACjD,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAA;IAC7D,KAAK,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;IACvD,KAAK,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;CACxD;AAQD;;;;GAIG;AACH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CA4BnG;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CA2DtF"}
@@ -0,0 +1,134 @@
1
+ import { get, route, rules, search, section } from './core/query.js';
2
+ import { buildIndex, hydrateIndex, serializeIndex } from './core/search.js';
3
+ /**
4
+ * Public query contract for `@clay-design-system/kb`.
5
+ *
6
+ * One query layer (Registry D4): the Clay CLI and `kb:mcp` call `createClayKb`, and Marko calls the
7
+ * same methods. Argument names and types match `scripts/kb/mcp.ts` (`clay_search`, `clay_get`,
8
+ * `clay_section`, `clay_rules`, `clay_route`). `route` takes the brief inline. There is no
9
+ * `briefPath` on this package — callers that have a file read it themselves and pass `brief`.
10
+ *
11
+ * `text` is the compact Markdown an agent reads. `data` is the same answer as structured fields
12
+ * (Registry "detail"). `clay_check_copy` stays on the CLI; it reads a page file.
13
+ *
14
+ * The published package ships three snapshots (Registry D11, public npm): `snapshot-web.json`,
15
+ * `snapshot-foundations.json` (tokens, icons, logos), and `snapshot-email.json`. Marko loads web
16
+ * and foundations together via `createClayKbFromSlices`. These argument shapes still accept
17
+ * `email`, `ds`, and `includeBackground`. A slice that does not contain those units returns no hits.
18
+ */
19
+ export const CLAY_KB_SCHEMA_VERSION = 1;
20
+ export const CLAY_STAGES = [
21
+ 'structure',
22
+ 'mapping',
23
+ 'design',
24
+ 'assets',
25
+ 'copy',
26
+ 'page-file',
27
+ 'ux',
28
+ 'qa',
29
+ 'static',
30
+ 'fidelity',
31
+ ];
32
+ export const CLAY_MODES = ['A', 'B'];
33
+ /** Values `clay_search` accepts for `scope`. Default when omitted: web + ds + shared. */
34
+ export const CLAY_SEARCH_SCOPES = ['web', 'ds', 'shared', 'email', 'all'];
35
+ export const CLAY_RULE_SCOPES = ['web', 'email'];
36
+ function required(tool, key, value) {
37
+ if (value === undefined || value === null || value === '') {
38
+ throw new Error(`${tool}: missing required argument "${key}"`);
39
+ }
40
+ }
41
+ /**
42
+ * Query layer over an in-memory snapshot. No filesystem and no `process.cwd`.
43
+ * Invalid arguments and an unknown section or stage throw `Error`.
44
+ * Search with no hits, and get with missing ids, return `{ text, data }` and do not throw.
45
+ */
46
+ /**
47
+ * One query layer over several snapshots. Marko passes web + foundations. The index is rebuilt
48
+ * from the stored unit text so scores cover every slice, not one file at a time.
49
+ */
50
+ export function createClayKbFromSlices(snapshots, options) {
51
+ if (snapshots.length === 0)
52
+ throw new Error('createClayKbFromSlices: pass at least one snapshot');
53
+ const units = snapshots.flatMap((snapshot) => snapshot.units);
54
+ const fingerprint = snapshots.map((snapshot) => snapshot.fingerprint).join('+');
55
+ const built = buildIndex({ fingerprint, units: units });
56
+ const index = JSON.parse(serializeIndex(built));
57
+ delete index.$comment;
58
+ delete index.fields;
59
+ return createClayKb({
60
+ schemaVersion: CLAY_KB_SCHEMA_VERSION,
61
+ packageVersion: snapshots[0].packageVersion,
62
+ generatedFromSha: snapshots[0].generatedFromSha,
63
+ fingerprint,
64
+ counts: {
65
+ units: units.length,
66
+ byScope: snapshots.reduce((acc, snapshot) => {
67
+ for (const [scope, count] of Object.entries(snapshot.counts.byScope ?? {})) {
68
+ acc[scope] = (acc[scope] ?? 0) + count;
69
+ }
70
+ return acc;
71
+ }, {}),
72
+ },
73
+ units,
74
+ index,
75
+ }, options);
76
+ }
77
+ export function createClayKb(snapshot, options) {
78
+ if (snapshot.schemaVersion !== CLAY_KB_SCHEMA_VERSION) {
79
+ throw new Error(`createClayKb: snapshot schemaVersion must be ${CLAY_KB_SCHEMA_VERSION}, got ${String(snapshot.schemaVersion)}`);
80
+ }
81
+ if (!Array.isArray(snapshot.units) ||
82
+ snapshot.index == null ||
83
+ typeof snapshot.fingerprint !== 'string') {
84
+ throw new Error('createClayKb: snapshot needs units, index, and fingerprint');
85
+ }
86
+ const units = snapshot.units;
87
+ const ctx = {
88
+ kb: { fingerprint: snapshot.fingerprint, units },
89
+ index: hydrateIndex(snapshot.index),
90
+ byId: new Map(units.map((unit) => [unit.id, unit])),
91
+ };
92
+ const session = options?.session;
93
+ return {
94
+ search(args) {
95
+ required('clay_search', 'query', args.query);
96
+ return search(ctx, args.query, {
97
+ k: args.k,
98
+ kind: args.kind,
99
+ entity: args.entity,
100
+ stage: args.stage,
101
+ mode: args.mode,
102
+ scope: args.scope,
103
+ includeBackground: args.includeBackground,
104
+ });
105
+ },
106
+ get(args) {
107
+ if (!Array.isArray(args.ids) || args.ids.length === 0)
108
+ required('clay_get', 'ids', undefined);
109
+ return get(ctx, args.ids, { session });
110
+ },
111
+ section(args) {
112
+ required('clay_section', 'name', args.name);
113
+ return section(ctx, args.name, args.layout, { session });
114
+ },
115
+ rules(args = {}) {
116
+ return rules(ctx, { stage: args.stage, mode: args.mode, scope: args.scope });
117
+ },
118
+ route(args) {
119
+ required('clay_route', 'skill', args.skill);
120
+ required('clay_route', 'stage', args.stage);
121
+ const result = route(ctx, {
122
+ skill: args.skill,
123
+ stage: args.stage,
124
+ mode: args.mode,
125
+ brief: args.brief,
126
+ budget: args.budget,
127
+ session,
128
+ });
129
+ const { text: _routeText, ...data } = result.data;
130
+ return { text: result.text, data };
131
+ },
132
+ };
133
+ }
134
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAU,CAAA;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,WAAW;IACX,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,WAAW;IACX,IAAI;IACJ,IAAI;IACJ,QAAQ;IACR,UAAU;CACF,CAAA;AAIV,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,CAAU,CAAA;AAG7C,yFAAyF;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAU,CAAA;AAGlF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,CAAU,CAAA;AAsMzD,SAAS,QAAQ,CAAC,IAAY,EAAE,GAAW,EAAE,KAAc;IACzD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,gCAAgC,GAAG,GAAG,CAAC,CAAA;IAChE,CAAC;AACH,CAAC;AAED;;;;GAI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,KAAK;gBACjB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,OAAO;aACR,CAAC,CAAA;YACF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;YACjD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,CAAA;QACpC,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * In-memory dedupe for one build. The Clay CLI loads and saves this object;
3
+ * the core only mutates the object it is given.
4
+ */
5
+ export interface MemorySession {
6
+ served: Record<string, string>;
7
+ lines: Record<string, string>;
8
+ layouts: string[];
9
+ sections: string[];
10
+ stages: string[];
11
+ }
12
+ /** Record a unit as served in full (first place wins). */
13
+ export declare function markServed(s: MemorySession | undefined, id: string, where: string): void;
14
+ /** Record a unit's one-line summary as served. */
15
+ export declare function markLine(s: MemorySession | undefined, id: string, where: string): void;
16
+ /** Already seen at least as a line (or a body). */
17
+ export declare const seenLine: (s: MemorySession | undefined, id: string) => boolean;
18
+ export declare const seenBody: (s: MemorySession | undefined, id: string) => boolean;
19
+ export declare function noteSection(s: MemorySession | undefined, name: string, layout?: string): void;
20
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/core/memory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAExF;AAED,kDAAkD;AAClD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEtF;AAED,mDAAmD;AACnD,eAAO,MAAM,QAAQ,GAAI,GAAG,aAAa,GAAG,SAAS,EAAE,IAAI,MAAM,YACvB,CAAA;AAC1C,eAAO,MAAM,QAAQ,GAAI,GAAG,aAAa,GAAG,SAAS,EAAE,IAAI,MAAM,YAA0B,CAAA;AAE3F,wBAAgB,WAAW,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAK7F"}
@@ -0,0 +1,23 @@
1
+ /** Record a unit as served in full (first place wins). */
2
+ export function markServed(s, id, where) {
3
+ if (s && !s.served[id])
4
+ s.served[id] = where;
5
+ }
6
+ /** Record a unit's one-line summary as served. */
7
+ export function markLine(s, id, where) {
8
+ if (s && !s.lines[id])
9
+ s.lines[id] = where;
10
+ }
11
+ /** Already seen at least as a line (or a body). */
12
+ export const seenLine = (s, id) => !!s && (!!s.lines[id] || !!s.served[id]);
13
+ export const seenBody = (s, id) => !!s && !!s.served[id];
14
+ export function noteSection(s, name, layout) {
15
+ if (!s || !name)
16
+ return;
17
+ if (!s.sections.includes(name))
18
+ s.sections.push(name);
19
+ const key = layout ? `${name}.${layout}` : '';
20
+ if (key && !s.layouts.includes(key))
21
+ s.layouts.push(key);
22
+ }
23
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/core/memory.ts"],"names":[],"mappings":"AAYA,0DAA0D;AAC1D,MAAM,UAAU,UA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AAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1D,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * In-memory knowledge the query core reads. No filesystem.
3
+ * Field set is the subset search, route, and the answer formatters use.
4
+ * `STAGES` matches `kb/schema.ts` and `CLAY_STAGES` in `../contract.ts`.
5
+ */
6
+ export declare const STAGES: readonly ["structure", "mapping", "design", "assets", "copy", "page-file", "ux", "qa", "static", "fidelity"];
7
+ export type Stage = (typeof STAGES)[number];
8
+ export declare function estimateTokens(text: string): number;
9
+ export interface Unit {
10
+ id: string;
11
+ kind: string;
12
+ scope: string;
13
+ topic: string;
14
+ authority: string;
15
+ stages: string[];
16
+ modes?: ('A' | 'B')[];
17
+ entities: string[];
18
+ summary: string;
19
+ body: string;
20
+ when?: string;
21
+ notWhen?: string;
22
+ severity?: string;
23
+ enforcement?: string[];
24
+ relations?: {
25
+ supersedes?: string[];
26
+ conflictsWith?: string[];
27
+ seeAlso?: string[];
28
+ precedence?: string[];
29
+ };
30
+ source: {
31
+ path: string;
32
+ anchor?: string;
33
+ generatedBy?: string;
34
+ };
35
+ status: string;
36
+ verifiedAt?: string;
37
+ handbookId?: string;
38
+ data?: unknown;
39
+ facts?: unknown;
40
+ file?: string;
41
+ }
42
+ export type KbUnit = Unit;
43
+ export interface Kb {
44
+ fingerprint: string;
45
+ units: KbUnit[];
46
+ }
47
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,MAAM,8GAWT,CAAA;AAEV,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,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set search, route, and the answer formatters use.
4
+ * `STAGES` matches `kb/schema.ts` and `CLAY_STAGES` in `../contract.ts`.
5
+ */
6
+ export const STAGES = [
7
+ 'structure',
8
+ 'mapping',
9
+ 'design',
10
+ 'assets',
11
+ 'copy',
12
+ 'page-file',
13
+ 'ux',
14
+ 'qa',
15
+ 'static',
16
+ 'fidelity',
17
+ ];
18
+ export function estimateTokens(text) {
19
+ return Math.ceil(text.length / 4);
20
+ }
21
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,WAAW;IACX,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,WAAW;IACX,IAAI;IACJ,IAAI;IACJ,QAAQ;IACR,UAAU;CACF,CAAA;AAIV,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Prose utilities for the general `kb:lint` claim checks (K3 retry 2): split a unit into sentences,
3
+ * reduce a sentence to its significant tokens, and weigh tokens by rarity (IDF) over the corpus.
4
+ *
5
+ * Normalisation is deliberately simple and symmetric (both sides of every comparison go through it):
6
+ * - unit-id citations (`policy.x.y`) are removed (a citation is a link, not content);
7
+ * - Markdown punctuation is dropped; `gray` → `grey`; "back to back" / "next to each other" /
8
+ * "adjacent" / "consecutive" / "in a row" → `adjacent`;
9
+ * - numbers keep their unit (`64 px` → `64px`) and ranges become one token (`4–6` → `4to6`);
10
+ * - identifiers are split on `-` / `_` / camelCase is kept whole (`tabs-background` → tabs, background;
11
+ * `FeaturesSection` → featuressection);
12
+ * - English stop words and normative words (never/always/must/only/…) are not significant: the
13
+ * normative words mark a *rule* sentence but never count as shared content;
14
+ * - a light stemmer folds plurals and -ing/-ed.
15
+ */
16
+ import { stem } from './rank.js';
17
+ export declare const UNIT_ID_RE: RegExp;
18
+ /** A sentence carries a rule when it says what to always / never / only do. */
19
+ export declare const NORMATIVE_RE: RegExp;
20
+ /**
21
+ * A sentence gives an instruction without a normative word: it opens with a base verb, optionally after a leading
22
+ * "When/Whenever/If …," clause ("Whenever a MediaSlot is a placeholder, give it a placeholderLabel …"). K4: candidate
23
+ * restatements are normative OR imperative sentences.
24
+ */
25
+ export declare const IMPERATIVE_RE: RegExp;
26
+ /** The light stemmer (folds plurals, -ing/-ed) lives with the search analyzer so lint and search stem alike. */
27
+ export { stem };
28
+ /** Text with citations, Markdown and phrasing variants normalised (still human-readable). */
29
+ export declare function normaliseText(s: string): string;
30
+ /** Significant, stemmed tokens of a sentence (a set). */
31
+ export declare function sigTokens(s: string): Set<string>;
32
+ export declare const isNumericToken: (t: string) => boolean;
33
+ /** Sentences of a Markdown body: one per table row / list item / line, lines split on `. ` + capital and (unless `keepSemicolons`) on `; `. Code fences are skipped. */
34
+ export declare function sentences(text: string, opts?: {
35
+ keepSemicolons?: boolean;
36
+ }): string[];
37
+ /** Inverse document frequency over a corpus of token sets: rare tokens weigh more. */
38
+ export declare function idfOf(docs: Iterable<Set<string>>): (t: string) => number;
39
+ export declare function intersect(a: Set<string>, b: Set<string>): string[];
40
+ //# sourceMappingURL=prose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prose.d.ts","sourceRoot":"","sources":["../../src/core/prose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,eAAO,MAAM,UAAU,QAC+J,CAAA;AAEtL,+EAA+E;AAC/E,eAAO,MAAM,YAAY,QACkJ,CAAA;AAE3K;;;;GAIG;AACH,eAAO,MAAM,aAAa,QACmO,CAAA;AAgB7P,gHAAgH;AAChH,OAAO,EAAE,IAAI,EAAE,CAAA;AAEf,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU/C;AAED,yDAAyD;AACzD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAYhD;AAED,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,YAAkB,CAAA;AAE1D,wKAAwK;AACxK,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,EAAE,CAqBzF;AAED,sFAAsF;AACtF,wBAAgB,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAQxE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAKlE"}