@skillit/core 1.5.0 → 2.0.0
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/dist/audit-formatter.d.ts +2 -0
- package/dist/audit-formatter.d.ts.map +1 -1
- package/dist/audit-formatter.js +2 -0
- package/dist/audit-formatter.js.map +1 -1
- package/dist/audit-score.js +82 -4
- package/dist/audit-score.js.map +1 -1
- package/dist/audit-types.d.ts +1 -29
- package/dist/audit-types.d.ts.map +1 -1
- package/dist/audit.d.ts +6 -2
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +39 -32
- package/dist/audit.js.map +1 -1
- package/dist/config-extract.d.ts +48 -0
- package/dist/config-extract.d.ts.map +1 -0
- package/dist/config-extract.js +230 -0
- package/dist/config-extract.js.map +1 -0
- package/dist/docs-scanner.d.ts +3 -0
- package/dist/docs-scanner.d.ts.map +1 -1
- package/dist/docs-scanner.js +3 -0
- package/dist/docs-scanner.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/refine/ast-edit.d.ts +41 -0
- package/dist/refine/ast-edit.d.ts.map +1 -1
- package/dist/refine/ast-edit.js +187 -19
- package/dist/refine/ast-edit.js.map +1 -1
- package/dist/refine/config-source.d.ts +81 -0
- package/dist/refine/config-source.d.ts.map +1 -0
- package/dist/refine/config-source.js +283 -0
- package/dist/refine/config-source.js.map +1 -0
- package/dist/refine/index.d.ts +5 -1
- package/dist/refine/index.d.ts.map +1 -1
- package/dist/refine/index.js +3 -1
- package/dist/refine/index.js.map +1 -1
- package/dist/refine/jsdoc-edit.d.ts +8 -1
- package/dist/refine/jsdoc-edit.d.ts.map +1 -1
- package/dist/refine/jsdoc-edit.js +8 -1
- package/dist/refine/jsdoc-edit.js.map +1 -1
- package/dist/refine/loop.d.ts.map +1 -1
- package/dist/refine/loop.js +26 -5
- package/dist/refine/loop.js.map +1 -1
- package/dist/refine/package-metadata.d.ts +28 -0
- package/dist/refine/package-metadata.d.ts.map +1 -0
- package/dist/refine/package-metadata.js +64 -0
- package/dist/refine/package-metadata.js.map +1 -0
- package/dist/refine/select-targets.d.ts.map +1 -1
- package/dist/refine/select-targets.js +31 -6
- package/dist/refine/select-targets.js.map +1 -1
- package/dist/refine/types.d.ts +29 -2
- package/dist/refine/types.d.ts.map +1 -1
- package/dist/renderer.js +13 -8
- package/dist/renderer.js.map +1 -1
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +2 -0
- package/dist/tokens.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/refine/ast-edit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/core/src/refine/ast-edit.ts
|
|
2
2
|
import { parse, Lang } from '@ast-grep/napi';
|
|
3
|
+
import { escapeJsDocClose, findPropertyByPath, findTypeBody, unescapeJsDocClose } from '../config-extract.js';
|
|
3
4
|
// `satisfies` ensures every listed value is a valid RefineTag. The
|
|
4
5
|
// `MissingTags` assertion below makes the inverse hold too: if a value is added
|
|
5
6
|
// to the RefineTag union but not to this list, compilation fails — so the
|
|
@@ -90,34 +91,179 @@ function leadingJsDoc(anchorNode) {
|
|
|
90
91
|
* - If a JSDoc block exists without the tag, the tag is appended before the
|
|
91
92
|
* closing `*\/`.
|
|
92
93
|
* - If the declaration is not found, the source is returned unchanged.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Parses `source` with ast-grep (core carries no `typescript` dependency) and
|
|
97
|
+
* edits the text in place, so formatting outside the touched JSDoc block is
|
|
98
|
+
* preserved. Tag matching is by name, so re-running with the same tag is a
|
|
99
|
+
* no-op rather than a duplicate.
|
|
93
100
|
*/
|
|
94
101
|
export function upsertJsDocTag(source, declName, tag, content) {
|
|
95
102
|
const root = parse(Lang.TypeScript, source).root();
|
|
96
103
|
const anchorNode = findDeclaration(root, declName);
|
|
97
104
|
if (!anchorNode)
|
|
98
105
|
return source;
|
|
99
|
-
|
|
106
|
+
return upsertTagOnAnchor(source, root, anchorNode, tag, content);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Insert or update a JSDoc tag on a property of a config type.
|
|
110
|
+
*
|
|
111
|
+
* `propertyPath` is a dot path into the interface or object-type alias named
|
|
112
|
+
* `typeName` (e.g. `outDir` or `components.prefix`). Otherwise behaves like
|
|
113
|
+
* {@link upsertJsDocTag}. Returns the source unchanged when the type or
|
|
114
|
+
* property is not found. Used by the config refine source to write routing
|
|
115
|
+
* tags back onto a config type's property declarations.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* Resolves `propertyPath` against the body of `typeName` via ast-grep, recursing
|
|
119
|
+
* into nested object-type members for dotted paths. Like {@link upsertJsDocTag},
|
|
120
|
+
* the edit is text-level and idempotent per tag name.
|
|
121
|
+
*/
|
|
122
|
+
export function upsertPropertyJsDocTag(source, typeName, propertyPath, tag, content) {
|
|
123
|
+
const root = parse(Lang.TypeScript, source).root();
|
|
124
|
+
const body = findTypeBody(root, typeName);
|
|
125
|
+
if (!body)
|
|
126
|
+
return source;
|
|
127
|
+
const property = findPropertyByPath(body, propertyPath);
|
|
128
|
+
if (!property)
|
|
129
|
+
return source;
|
|
130
|
+
return upsertTagOnAnchor(source, root, property, tag, content);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Insert or update `@tag content` on the JSDoc block leading `anchorNode`,
|
|
134
|
+
* creating the block when absent. Idempotent per tag (matches the tag NAME, so
|
|
135
|
+
* multi-line content never produces duplicates) and rebuilds the block as
|
|
136
|
+
* well-formed multi-line (handling single-line `/** text *\/` inputs). Shared by
|
|
137
|
+
* the declaration-level ({@link upsertJsDocTag}) and property-level
|
|
138
|
+
* ({@link upsertPropertyJsDocTag}) upserts.
|
|
139
|
+
*/
|
|
140
|
+
function upsertTagOnAnchor(source, root, anchorNode, tag, content) {
|
|
141
|
+
// Escape any comment-close sequence in the content so a value containing it
|
|
142
|
+
// (e.g. a glob like `**/*.ts` in a config pitfall) can't terminate the block
|
|
143
|
+
// early and corrupt the file. readJsDocTags / config extraction unescape it.
|
|
144
|
+
const tagText = escapeJsDocClose(`@${tag} ${content}`);
|
|
100
145
|
const jsdocNode = leadingJsDoc(anchorNode);
|
|
146
|
+
// Indent from the comment when one exists: it may sit on the SAME line as the
|
|
147
|
+
// declaration (`/** x */ prop`), where the declaration's own column is the
|
|
148
|
+
// text after the comment, not the line indent — using it over-indented every
|
|
149
|
+
// rebuilt continuation line. With no comment, indent from the declaration the
|
|
150
|
+
// new block is prepended to.
|
|
151
|
+
const indent = ' '.repeat((jsdocNode ?? anchorNode).range().start.column);
|
|
101
152
|
if (jsdocNode) {
|
|
102
153
|
const block = jsdocNode.text();
|
|
103
|
-
if (block.
|
|
154
|
+
if (block.match(new RegExp(`(^|\\n)\\s*\\*?\\s*@${tag}\\b`)))
|
|
104
155
|
return source;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
156
|
+
const innerLines = block
|
|
157
|
+
.replace(/^\/\*\*/, '')
|
|
158
|
+
.replace(/\s*\*\/\s*$/, '')
|
|
159
|
+
.split('\n')
|
|
160
|
+
.map((line) => line.replace(/^\s*\*? ?/, '').trimEnd());
|
|
161
|
+
while (innerLines.length > 0 && innerLines[0] === '')
|
|
162
|
+
innerLines.shift();
|
|
163
|
+
while (innerLines.length > 0 && innerLines[innerLines.length - 1] === '')
|
|
164
|
+
innerLines.pop();
|
|
165
|
+
// Prefix every physical line (including multi-line tag content) with ` * `.
|
|
166
|
+
const allLines = [...innerLines, ...tagText.split('\n')];
|
|
167
|
+
const body = allLines
|
|
168
|
+
.map((line) => (line.length > 0 ? `${indent} * ${line}` : `${indent} *`))
|
|
169
|
+
.join('\n');
|
|
170
|
+
const merged = `/**\n${body}\n${indent} */`;
|
|
171
|
+
// Own-line comment: a clean node replace suffices.
|
|
172
|
+
if (jsdocNode.range().end.line !== anchorNode.range().start.line) {
|
|
173
|
+
return root.commitEdits([jsdocNode.replace(merged)]);
|
|
174
|
+
}
|
|
175
|
+
// Same-line `/** x */ prop`: a node replace swaps only the comment text and
|
|
176
|
+
// leaves the declaration packed onto the closing `*/` line. Splice manually
|
|
177
|
+
// — drop the inline gap and start the declaration on its own indented line.
|
|
178
|
+
const start = jsdocNode.range().start.index;
|
|
179
|
+
const end = jsdocNode.range().end.index;
|
|
180
|
+
const tail = source.slice(end).replace(/^[^\S\n]+/, '');
|
|
181
|
+
return `${source.slice(0, start)}${merged}\n${indent}${tail}`;
|
|
113
182
|
}
|
|
114
|
-
// No existing JSDoc — create one before the anchor node.
|
|
115
|
-
|
|
116
|
-
|
|
183
|
+
// No existing JSDoc — create one before the anchor node. Prefix EVERY physical
|
|
184
|
+
// line of the tag (multi-line content too) with ` * `, mirroring the merge
|
|
185
|
+
// branch above. Without this, a multi-line first tag left continuation lines
|
|
186
|
+
// at column 0 — malformed JSDoc that also broke the re-parse for any tag
|
|
187
|
+
// appended to the same declaration in a later pass.
|
|
117
188
|
const at = anchorNode.range().start.index;
|
|
118
|
-
const
|
|
189
|
+
const body = tagText
|
|
190
|
+
.split('\n')
|
|
191
|
+
.map((line) => (line.length > 0 ? `${indent} * ${line}` : `${indent} *`))
|
|
192
|
+
.join('\n');
|
|
193
|
+
const blockText = `/**\n${body}\n${indent} */\n${indent}`;
|
|
119
194
|
return source.slice(0, at) + blockText + source.slice(at);
|
|
120
195
|
}
|
|
196
|
+
// Fast membership set for tag-name lookups (typed as strings so an arbitrary
|
|
197
|
+
// captured `@word` can be tested without a cast). Derived from REFINE_TAGS so
|
|
198
|
+
// it stays in sync with the union automatically.
|
|
199
|
+
const REFINE_TAG_SET = new Set(REFINE_TAGS);
|
|
200
|
+
/**
|
|
201
|
+
* Remove the refine-managed tag spans (`@useWhen`, `@avoidWhen`, `@pitfalls`,
|
|
202
|
+
* `@remarks`, `@example` — see {@link REFINE_TAGS}) from every JSDoc block in
|
|
203
|
+
* `source`, leaving each block's prose description and any non-refine tags
|
|
204
|
+
* intact.
|
|
205
|
+
*
|
|
206
|
+
* Used to feed an annotated config module back to the model as grounding
|
|
207
|
+
* without echoing the routing tags this package itself wrote across earlier
|
|
208
|
+
* refine iterations — those are documentation, not the implementation the model
|
|
209
|
+
* should ground runtime claims in. Unlike a blanket JSDoc strip, this preserves
|
|
210
|
+
* genuine hand-authored docs (e.g. validation notes on a `defineConfig` helper),
|
|
211
|
+
* which are exactly the runtime-behavior grounding we want to keep.
|
|
212
|
+
*
|
|
213
|
+
* Handles single-line (`/** @tag x */`) as well as multi-line blocks: each block
|
|
214
|
+
* is reduced to its inner content (opener/closer and ` * ` gutter dropped) before
|
|
215
|
+
* tags are matched, so an inline opener can't hide a tag. The block-matching
|
|
216
|
+
* regex is non-greedy, and writeback escapes a literal close sequence in content
|
|
217
|
+
* to `*\/`, so an escaped sequence inside a kept line never terminates early.
|
|
218
|
+
*/
|
|
219
|
+
export function stripRefineTags(source) {
|
|
220
|
+
return source.replace(/\/\*\*[\s\S]*?\*\//g, (block, offset) => {
|
|
221
|
+
// Indent of the line the block opens on, for a clean re-wrap when we rebuild.
|
|
222
|
+
const lineStart = source.lastIndexOf('\n', offset) + 1;
|
|
223
|
+
const indent = source.slice(lineStart, offset).match(/^\s*/)?.[0] ?? '';
|
|
224
|
+
return stripRefineTagsFromBlock(block, indent);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Strip refine-tag spans from one JSDoc block. Returns the block unchanged when
|
|
229
|
+
* it holds no refine tag (preserving hand-authored formatting), the empty string
|
|
230
|
+
* when nothing but refine tags remain (the whole block is dropped), or a clean
|
|
231
|
+
* re-wrapped block at `indent` otherwise. A `@tag` line and the lines following
|
|
232
|
+
* it (its continuation) form one span; a non-refine `@tag` closes any open span.
|
|
233
|
+
*/
|
|
234
|
+
function stripRefineTagsFromBlock(block, indent) {
|
|
235
|
+
// Reduce to inner content so tag detection is independent of how the block is
|
|
236
|
+
// wrapped: drop the `/**` opener and `*/` closer (own-line OR inline, as in a
|
|
237
|
+
// single-line `/** @tag x */`), then the per-line ` * ` gutter.
|
|
238
|
+
const inner = block.replace(/^\s*\/\*\*/, '').replace(/\*\/\s*$/, '');
|
|
239
|
+
const lines = inner.split('\n').map((line) => line.replace(/^\s*\*? ?/, '').trimEnd());
|
|
240
|
+
const kept = [];
|
|
241
|
+
let dropping = false;
|
|
242
|
+
let droppedAny = false;
|
|
243
|
+
for (const line of lines) {
|
|
244
|
+
const tagMatch = line.match(/^@(\w+)\b/);
|
|
245
|
+
if (tagMatch) {
|
|
246
|
+
dropping = REFINE_TAG_SET.has(tagMatch[1] ?? '');
|
|
247
|
+
}
|
|
248
|
+
if (dropping) {
|
|
249
|
+
droppedAny = true;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
kept.push(line);
|
|
253
|
+
}
|
|
254
|
+
if (!droppedAny)
|
|
255
|
+
return block; // no refine tag — keep original formatting verbatim
|
|
256
|
+
while (kept.length > 0 && kept[0] === '')
|
|
257
|
+
kept.shift();
|
|
258
|
+
while (kept.length > 0 && kept[kept.length - 1] === '')
|
|
259
|
+
kept.pop();
|
|
260
|
+
if (kept.length === 0)
|
|
261
|
+
return ''; // block was nothing but refine tags
|
|
262
|
+
const body = kept
|
|
263
|
+
.map((line) => (line.length > 0 ? `${indent} * ${line}` : `${indent} *`))
|
|
264
|
+
.join('\n');
|
|
265
|
+
return `/**\n${body}\n${indent} */`;
|
|
266
|
+
}
|
|
121
267
|
/**
|
|
122
268
|
* Parse the leading JSDoc block of a named export declaration and return a
|
|
123
269
|
* map of the RefineTag values found in it.
|
|
@@ -134,13 +280,35 @@ export function readJsDocTags(source, declName) {
|
|
|
134
280
|
if (!jsdocNode)
|
|
135
281
|
return {};
|
|
136
282
|
const block = jsdocNode.text();
|
|
283
|
+
// Strip the block to inner content lines (no `/** */` wrapper, no ` * `
|
|
284
|
+
// prefixes), then walk them: a known `@tag` line opens a capture and the
|
|
285
|
+
// following non-tag lines are its continuation. This keeps multi-line tag
|
|
286
|
+
// content (e.g. bullet lists) intact instead of truncating at the first
|
|
287
|
+
// newline — otherwise a refined `@pitfalls` with several bullets would lose
|
|
288
|
+
// everything past line one when re-extracted into SKILL.md.
|
|
289
|
+
const innerLines = block
|
|
290
|
+
.replace(/^\/\*\*/, '')
|
|
291
|
+
.replace(/\s*\*\/\s*$/, '')
|
|
292
|
+
.split('\n')
|
|
293
|
+
.map((line) => line.replace(/^\s*\*? ?/, '').trimEnd());
|
|
294
|
+
const collected = {};
|
|
295
|
+
let current;
|
|
296
|
+
for (const line of innerLines) {
|
|
297
|
+
const tagMatch = line.match(/^@(\w+)\s?(.*)$/);
|
|
298
|
+
const matchedTag = tagMatch ? REFINE_TAGS.find((t) => t === tagMatch[1]) : undefined;
|
|
299
|
+
if (matchedTag) {
|
|
300
|
+
current = matchedTag;
|
|
301
|
+
collected[current] = [tagMatch[2] ?? ''];
|
|
302
|
+
}
|
|
303
|
+
else if (current) {
|
|
304
|
+
collected[current].push(line);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
137
307
|
const result = {};
|
|
138
308
|
for (const tag of REFINE_TAGS) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
result[tag] = hit[1]?.trim() ?? '';
|
|
143
|
-
}
|
|
309
|
+
const lines = collected[tag];
|
|
310
|
+
if (lines)
|
|
311
|
+
result[tag] = unescapeJsDocClose(lines.join('\n').trim());
|
|
144
312
|
}
|
|
145
313
|
return result;
|
|
146
314
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-edit.js","sourceRoot":"","sources":["../../src/refine/ast-edit.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CA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C,EAAE,CAAC;IACtD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ExtractedSkill } from '../types.js';
|
|
2
|
+
import type { DraftedFix, RefineSource, TargetLocation } from './types.js';
|
|
3
|
+
export interface ConfigRefineSourceOptions {
|
|
4
|
+
/** Path to the TypeScript file declaring the config type. */
|
|
5
|
+
configFile: string;
|
|
6
|
+
/** Name of the exported interface or object-type alias to document. */
|
|
7
|
+
typeName: string;
|
|
8
|
+
/** Skill name (defaults to the package name, then `typeName`). */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** Skill description (defaults to the package.json description). */
|
|
11
|
+
description?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Globs pointing at the code that CONSUMES this config (e.g. the CLI/filter
|
|
14
|
+
* logic). Their contents are fed to the draft model as an implementation
|
|
15
|
+
* reference so it can state CORRECT runtime behavior instead of guessing it
|
|
16
|
+
* from the type alone. Token-capped. Without grounding the model is told not
|
|
17
|
+
* to assert unverifiable runtime semantics.
|
|
18
|
+
*/
|
|
19
|
+
groundingGlobs?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* {@link RefineSource} for a TypeScript configuration surface.
|
|
23
|
+
*
|
|
24
|
+
* Reads the consumer's config type with {@link extractConfigSurface}, exposes it
|
|
25
|
+
* as a single `config` surface in an {@link ExtractedSkill}, and writes routing
|
|
26
|
+
* tags back as JSDoc onto the type's individual property declarations. Unlike
|
|
27
|
+
* the CLI source — whose routing lives at the command (surface) level — a config
|
|
28
|
+
* surface is documented per-OPTION: each fix targets one property by its
|
|
29
|
+
* dot-path `configKey` (e.g. `outDir`, `components.prefix`), routed through
|
|
30
|
+
* {@link upsertPropertyJsDocTag}.
|
|
31
|
+
*
|
|
32
|
+
* It also enriches the skill from the package.json nearest the config file (its
|
|
33
|
+
* description, keywords, repository) and a sibling README, supplying the audit
|
|
34
|
+
* context the metadata checks (F1/F2/F3/E5/W4/W5/W6) score against — without it
|
|
35
|
+
* a config skill forfeits those points even when the package already carries
|
|
36
|
+
* the data.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ConfigRefineSource implements RefineSource {
|
|
39
|
+
private readonly opts;
|
|
40
|
+
/** Cached metadata, populated by {@link extract} (which the loop runs first). */
|
|
41
|
+
private metadata;
|
|
42
|
+
/** Cached surface, populated by {@link extract}; read by {@link guidance}. */
|
|
43
|
+
private surface;
|
|
44
|
+
/** Cached implementation-reference grounding, populated by {@link extract}. */
|
|
45
|
+
private grounding;
|
|
46
|
+
constructor(opts: ConfigRefineSourceOptions);
|
|
47
|
+
extract(): Promise<ExtractedSkill>;
|
|
48
|
+
/**
|
|
49
|
+
* Map an improvement target to its on-disk location. Config targets carry the
|
|
50
|
+
* option's dot-path `configKey` as `name` (kind `config-option`); the config
|
|
51
|
+
* type holds them, so the file is always the config file and the declName is
|
|
52
|
+
* the type. A `config-example` target points at the same file with no path.
|
|
53
|
+
*/
|
|
54
|
+
resolveTargetLocation(target: {
|
|
55
|
+
name: string;
|
|
56
|
+
kind: string;
|
|
57
|
+
file?: string;
|
|
58
|
+
}): TargetLocation | undefined;
|
|
59
|
+
applyFixes(fixes: readonly DraftedFix[]): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Drafting conventions passed to the model each iteration. Scopes every
|
|
62
|
+
* routing tag to the single named option, constrains claims to what the type
|
|
63
|
+
* and provided context can support (the model sees the type, NOT the code that
|
|
64
|
+
* consumes the config, so unconstrained drafting invents wrong runtime
|
|
65
|
+
* semantics), and tells it how to draft the `@example` config file. Built from
|
|
66
|
+
* the cached surface that {@link extract} populates first.
|
|
67
|
+
*/
|
|
68
|
+
guidance(): string;
|
|
69
|
+
private loadMetadata;
|
|
70
|
+
/**
|
|
71
|
+
* Sibling example path for the config file: same directory, the config file's
|
|
72
|
+
* base name with any `.ts`/`.tsx`/`.mts`/`.cts` extension replaced by
|
|
73
|
+
* `.example.ts` (e.g. `z2f.config.ts` → `z2f.config.example.ts`,
|
|
74
|
+
* `config.ts` → `config.example.ts`).
|
|
75
|
+
*/
|
|
76
|
+
private exampleFilePath;
|
|
77
|
+
private loadGrounding;
|
|
78
|
+
/** Nearest ancestor directory of the config file that holds a package.json. */
|
|
79
|
+
private findPackageDir;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=config-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-source.d.ts","sourceRoot":"","sources":["../../src/refine/config-source.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,WAAW,yBAAyB;IACxC,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IAQzC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPjC,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAsB;IACtC,8EAA8E;IAC9E,OAAO,CAAC,OAAO,CAAqC;IACpD,+EAA+E;IAC/E,OAAO,CAAC,SAAS,CAAM;IAEvB,YAA6B,IAAI,EAAE,yBAAyB,EAAI;IAE1D,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,CAgDvC;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,MAAM,EAAE;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,cAAc,GAAG,SAAS,CAS7B;IAEK,UAAU,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA2C5D;IAED;;;;;;;OAOG;IACH,QAAQ,IAAI,MAAM,CAoBjB;YAQa,YAAY;IAiB1B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;YAcT,aAAa;IAyC3B,+EAA+E;IAC/E,OAAO,CAAC,cAAc;CAUvB"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// packages/core/src/refine/config-source.ts
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { glob, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { extractConfigSurface } from '../config-extract.js';
|
|
6
|
+
import { truncateToTokenBudget } from '../tokens.js';
|
|
7
|
+
import { stripRefineTags, upsertPropertyJsDocTag } from './ast-edit.js';
|
|
8
|
+
import { readPackageMetadata } from './package-metadata.js';
|
|
9
|
+
/** Token cap for the implementation-reference grounding fed to the model. */
|
|
10
|
+
const GROUNDING_TOKEN_CAP = 8000;
|
|
11
|
+
const EXCLUDED_GROUNDING_DIRS = new Set(['node_modules', 'dist', 'build', '.git', 'coverage']);
|
|
12
|
+
/** Maximum directories to walk upward from the config file seeking package.json. */
|
|
13
|
+
const MAX_PACKAGE_LOOKUP_DEPTH = 8;
|
|
14
|
+
/**
|
|
15
|
+
* {@link RefineSource} for a TypeScript configuration surface.
|
|
16
|
+
*
|
|
17
|
+
* Reads the consumer's config type with {@link extractConfigSurface}, exposes it
|
|
18
|
+
* as a single `config` surface in an {@link ExtractedSkill}, and writes routing
|
|
19
|
+
* tags back as JSDoc onto the type's individual property declarations. Unlike
|
|
20
|
+
* the CLI source — whose routing lives at the command (surface) level — a config
|
|
21
|
+
* surface is documented per-OPTION: each fix targets one property by its
|
|
22
|
+
* dot-path `configKey` (e.g. `outDir`, `components.prefix`), routed through
|
|
23
|
+
* {@link upsertPropertyJsDocTag}.
|
|
24
|
+
*
|
|
25
|
+
* It also enriches the skill from the package.json nearest the config file (its
|
|
26
|
+
* description, keywords, repository) and a sibling README, supplying the audit
|
|
27
|
+
* context the metadata checks (F1/F2/F3/E5/W4/W5/W6) score against — without it
|
|
28
|
+
* a config skill forfeits those points even when the package already carries
|
|
29
|
+
* the data.
|
|
30
|
+
*/
|
|
31
|
+
export class ConfigRefineSource {
|
|
32
|
+
opts;
|
|
33
|
+
/** Cached metadata, populated by {@link extract} (which the loop runs first). */
|
|
34
|
+
metadata = {};
|
|
35
|
+
/** Cached surface, populated by {@link extract}; read by {@link guidance}. */
|
|
36
|
+
surface;
|
|
37
|
+
/** Cached implementation-reference grounding, populated by {@link extract}. */
|
|
38
|
+
grounding = '';
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
this.opts = opts;
|
|
41
|
+
}
|
|
42
|
+
async extract() {
|
|
43
|
+
const source = await readFile(this.opts.configFile, 'utf8');
|
|
44
|
+
const surface = extractConfigSurface(source, this.opts.typeName);
|
|
45
|
+
if (!surface) {
|
|
46
|
+
throw new Error(`[skillit] config type '${this.opts.typeName}' not found in ${this.opts.configFile}`);
|
|
47
|
+
}
|
|
48
|
+
this.surface = surface;
|
|
49
|
+
this.grounding = await this.loadGrounding();
|
|
50
|
+
const meta = await this.loadMetadata();
|
|
51
|
+
// The render headline (`skill.description`) prefers a caller-supplied
|
|
52
|
+
// config-specific description so the skill body describes the config surface
|
|
53
|
+
// rather than the package. `skill.packageDescription` (set below) is kept as
|
|
54
|
+
// the LITERAL package.json description so the audit's F1 check validates the
|
|
55
|
+
// real published metadata — a config override must not mask a missing or
|
|
56
|
+
// too-short package.json description.
|
|
57
|
+
const description = this.opts.description ?? meta.packageDescription ?? '';
|
|
58
|
+
const skill = {
|
|
59
|
+
name: this.opts.name ?? meta.packageName ?? this.opts.typeName,
|
|
60
|
+
description,
|
|
61
|
+
functions: [],
|
|
62
|
+
classes: [],
|
|
63
|
+
types: [],
|
|
64
|
+
enums: [],
|
|
65
|
+
variables: [],
|
|
66
|
+
examples: [],
|
|
67
|
+
configSurfaces: [surface]
|
|
68
|
+
};
|
|
69
|
+
if (meta.keywords?.length)
|
|
70
|
+
skill.keywords = meta.keywords;
|
|
71
|
+
if (meta.repository)
|
|
72
|
+
skill.repository = meta.repository;
|
|
73
|
+
if (meta.packageDescription)
|
|
74
|
+
skill.packageDescription = meta.packageDescription;
|
|
75
|
+
if (meta.readme !== undefined)
|
|
76
|
+
skill.readme = meta.readme;
|
|
77
|
+
// A sibling `<config>.example.ts` (if present) is the skill's usage example
|
|
78
|
+
// — clears E4 and feeds the rendered Examples section. The refine loop
|
|
79
|
+
// drafts it once when absent; reading it back here surfaces it thereafter.
|
|
80
|
+
// Read directly and tolerate ENOENT (no existsSync precheck — that is a
|
|
81
|
+
// check-then-use race).
|
|
82
|
+
try {
|
|
83
|
+
const example = (await readFile(this.exampleFilePath(), 'utf8')).trim();
|
|
84
|
+
if (example)
|
|
85
|
+
skill.examples = [example];
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// No/unreadable example — leave examples empty (E4 stays a gap).
|
|
89
|
+
}
|
|
90
|
+
return skill;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Map an improvement target to its on-disk location. Config targets carry the
|
|
94
|
+
* option's dot-path `configKey` as `name` (kind `config-option`); the config
|
|
95
|
+
* type holds them, so the file is always the config file and the declName is
|
|
96
|
+
* the type. A `config-example` target points at the same file with no path.
|
|
97
|
+
*/
|
|
98
|
+
resolveTargetLocation(target) {
|
|
99
|
+
if (target.kind === 'config-example') {
|
|
100
|
+
return { file: this.opts.configFile, declName: this.opts.typeName };
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
file: this.opts.configFile,
|
|
104
|
+
declName: this.opts.typeName,
|
|
105
|
+
propertyPath: target.name
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async applyFixes(fixes) {
|
|
109
|
+
// An `@example` fix is the drafted config-example FILE, not a JSDoc tag:
|
|
110
|
+
// write it to the sibling `<config>.example.ts` — but only if one does not
|
|
111
|
+
// already exist, so a hand-authored example is never clobbered.
|
|
112
|
+
const exampleFix = fixes.find((fix) => fix.tag === 'example');
|
|
113
|
+
if (exampleFix) {
|
|
114
|
+
// Write-if-absent atomically with the `wx` flag (create, fail if exists)
|
|
115
|
+
// rather than existsSync-then-write — the latter is a TOCTOU race, and the
|
|
116
|
+
// atomic flag enforces the no-clobber intent at the syscall.
|
|
117
|
+
try {
|
|
118
|
+
await writeFile(this.exampleFilePath(), normalizeExampleFile(exampleFix.value), {
|
|
119
|
+
encoding: 'utf8',
|
|
120
|
+
flag: 'wx'
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
// EEXIST = an example already exists; preserve it. Re-throw anything else.
|
|
125
|
+
if (error.code !== 'EEXIST')
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let source = await readFile(this.opts.configFile, 'utf8');
|
|
130
|
+
let changed = false;
|
|
131
|
+
for (const fix of fixes) {
|
|
132
|
+
if (fix.tag === 'example')
|
|
133
|
+
continue; // handled above (separate file)
|
|
134
|
+
// `fix.toolName` is the option's dot-path configKey (set by the
|
|
135
|
+
// audit-score config-option target). Route it to the matching property.
|
|
136
|
+
const next = upsertPropertyJsDocTag(source, this.opts.typeName, fix.toolName, fix.tag, fix.value);
|
|
137
|
+
if (next !== source) {
|
|
138
|
+
source = next;
|
|
139
|
+
changed = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (changed) {
|
|
143
|
+
await writeFile(this.opts.configFile, source, 'utf8');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Drafting conventions passed to the model each iteration. Scopes every
|
|
148
|
+
* routing tag to the single named option, constrains claims to what the type
|
|
149
|
+
* and provided context can support (the model sees the type, NOT the code that
|
|
150
|
+
* consumes the config, so unconstrained drafting invents wrong runtime
|
|
151
|
+
* semantics), and tells it how to draft the `@example` config file. Built from
|
|
152
|
+
* the cached surface that {@link extract} populates first.
|
|
153
|
+
*/
|
|
154
|
+
guidance() {
|
|
155
|
+
const optionList = (this.surface?.options ?? [])
|
|
156
|
+
.map((o) => `- \`${o.configKey ?? o.name}\`: ${o.type}`)
|
|
157
|
+
.join('\n');
|
|
158
|
+
const typeName = this.opts.typeName;
|
|
159
|
+
return [
|
|
160
|
+
`You are documenting the individual options of the TypeScript configuration object \`${typeName}\`.`,
|
|
161
|
+
`Each work item's "Tool" is ONE option, named by its dot-path key (e.g. \`outDir\`, \`components.prefix\`) — except an @example work item, whose "Tool" is the config type \`${typeName}\` itself.`,
|
|
162
|
+
`For @useWhen / @avoidWhen / @pitfalls: write guidance SPECIFIC to that single option — when to set it (and to what kind of value), when to leave it unset, and footguns unique to its value or interactions. Do NOT describe the configuration type as a whole, the annotate-vs-\`defineConfig()\` choice, or anything that applies to every option; never repeat the same point across options.`,
|
|
163
|
+
this.grounding
|
|
164
|
+
? `GROUND every runtime-behavior claim in the IMPLEMENTATION REFERENCE below (the actual code that consumes this config) and the option's type. State behavior the code actually exhibits — e.g. what an empty array/object means, whether an invalid value throws or is silently ignored, what a flag toggles, how options interact. Do NOT contradict the reference, and do NOT assert behavior absent from both the reference and the type; omit it instead. A confidently wrong "NEVER" is worse than no pitfall.`
|
|
165
|
+
: `GROUND every claim in the option's TYPE and the documentation provided to you. You can see the type, not the code that reads this config — so do NOT assert runtime behavior you cannot verify: whether an empty array/object means "all" or "none", whether an invalid value throws or is silently ignored, what a boolean flag actually toggles, or how two options interact at runtime. If a behavior is not evidenced by the type or the docs, omit it or phrase it as a type-level fact ("\`mode\` accepts 'submit' | 'auto-save'"). A confidently wrong "NEVER" is worse than no pitfall — prefer fewer, verifiable points over speculative ones.`,
|
|
166
|
+
`For @example: output a COMPLETE, type-correct example configuration FILE — import statements plus a default export — saved verbatim as a sibling \`*.config.example.ts\` that must compile. Import \`defineConfig\`/\`${typeName}\` from the package by its published name ONLY if the example lives outside that package; if it sits inside the package's own \`src\`, import from the local source entrypoint (a relative path) so the self-import does not resolve to an unbuilt \`dist\`. Use realistic values for required options and a few common optional ones. Output ONLY the file source: no prose, no markdown, no code fences.`,
|
|
167
|
+
`Options (key: type):\n${optionList}`,
|
|
168
|
+
...(this.grounding
|
|
169
|
+
? [
|
|
170
|
+
`IMPLEMENTATION REFERENCE (the code that consumes this config — ground runtime-behavior claims in it):\n${this.grounding}`
|
|
171
|
+
]
|
|
172
|
+
: [])
|
|
173
|
+
].join('\n\n');
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Discover and parse the package.json nearest the config file (walking up to
|
|
177
|
+
* {@link MAX_PACKAGE_LOOKUP_DEPTH} directories) plus a sibling README. Cached
|
|
178
|
+
* so repeated extract/score passes read the filesystem once. Never throws —
|
|
179
|
+
* unreadable or absent files just yield empty fields.
|
|
180
|
+
*/
|
|
181
|
+
async loadMetadata() {
|
|
182
|
+
const pkgDir = this.findPackageDir();
|
|
183
|
+
if (!pkgDir)
|
|
184
|
+
return this.metadata;
|
|
185
|
+
const meta = await readPackageMetadata(pkgDir);
|
|
186
|
+
this.metadata = {
|
|
187
|
+
...(meta.packageDescription !== undefined
|
|
188
|
+
? { packageDescription: meta.packageDescription }
|
|
189
|
+
: {}),
|
|
190
|
+
...(meta.keywords !== undefined ? { keywords: meta.keywords } : {}),
|
|
191
|
+
...(meta.repository !== undefined ? { repository: meta.repository } : {}),
|
|
192
|
+
...(meta.readme !== undefined ? { readme: meta.readme } : {})
|
|
193
|
+
};
|
|
194
|
+
return meta;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Sibling example path for the config file: same directory, the config file's
|
|
198
|
+
* base name with any `.ts`/`.tsx`/`.mts`/`.cts` extension replaced by
|
|
199
|
+
* `.example.ts` (e.g. `z2f.config.ts` → `z2f.config.example.ts`,
|
|
200
|
+
* `config.ts` → `config.example.ts`).
|
|
201
|
+
*/
|
|
202
|
+
exampleFilePath() {
|
|
203
|
+
const dir = dirname(this.opts.configFile);
|
|
204
|
+
const base = basename(this.opts.configFile).replace(/\.[cm]?tsx?$/, '');
|
|
205
|
+
return join(dir, `${base}.example.ts`);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Read the grounding globs into a single token-capped implementation
|
|
209
|
+
* reference. Prepends the config module's own declarations (refine tags
|
|
210
|
+
* stripped — see {@link stripRefineTags}) so preset tables/defaults/validation
|
|
211
|
+
* ground the model, then appends the matched glob files (skipping `.d.ts`,
|
|
212
|
+
* excluded dirs, and the already-included config file). Returns `''` when no
|
|
213
|
+
* globs are configured or nothing matches — never throws.
|
|
214
|
+
*/
|
|
215
|
+
async loadGrounding() {
|
|
216
|
+
const globs = this.opts.groundingGlobs;
|
|
217
|
+
if (!globs?.length)
|
|
218
|
+
return '';
|
|
219
|
+
const configAbs = resolve(this.opts.configFile);
|
|
220
|
+
const seen = new Set([configAbs]);
|
|
221
|
+
const parts = [];
|
|
222
|
+
// The config module itself often holds non-type declarations the model
|
|
223
|
+
// needs to be accurate — preset tables, defaults, `defineConfig`/validation
|
|
224
|
+
// (e.g. z2f's `SHADCN_OVERRIDES`). Include it, but strip ONLY the routing
|
|
225
|
+
// tags this source writes back across iterations (so our own accumulated
|
|
226
|
+
// annotations aren't fed back as "implementation"); hand-authored prose —
|
|
227
|
+
// the real runtime-behavior grounding — is preserved.
|
|
228
|
+
const configSource = await readFile(this.opts.configFile, 'utf8').catch(() => '');
|
|
229
|
+
const configDecls = stripRefineTags(configSource).trim();
|
|
230
|
+
if (configDecls)
|
|
231
|
+
parts.push(`// ${this.opts.configFile} (config module declarations)\n${configDecls}`);
|
|
232
|
+
for (const pattern of globs) {
|
|
233
|
+
let matches;
|
|
234
|
+
try {
|
|
235
|
+
matches = glob(pattern, {
|
|
236
|
+
exclude: (f) => f.endsWith('.d.ts') || f.split(/[\\/]/).some((seg) => EXCLUDED_GROUNDING_DIRS.has(seg))
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
continue; // bad pattern — skip
|
|
241
|
+
}
|
|
242
|
+
for await (const file of matches) {
|
|
243
|
+
const abs = resolve(file);
|
|
244
|
+
if (seen.has(abs))
|
|
245
|
+
continue; // config file is pre-seeded above
|
|
246
|
+
seen.add(abs);
|
|
247
|
+
const content = await readFile(file, 'utf8').catch(() => '');
|
|
248
|
+
if (content.trim())
|
|
249
|
+
parts.push(`// ${file}\n${content.trim()}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (parts.length === 0)
|
|
253
|
+
return '';
|
|
254
|
+
return truncateToTokenBudget(parts.join('\n\n'), GROUNDING_TOKEN_CAP);
|
|
255
|
+
}
|
|
256
|
+
/** Nearest ancestor directory of the config file that holds a package.json. */
|
|
257
|
+
findPackageDir() {
|
|
258
|
+
let dir = dirname(this.opts.configFile);
|
|
259
|
+
for (let i = 0; i < MAX_PACKAGE_LOOKUP_DEPTH; i++) {
|
|
260
|
+
if (existsSync(join(dir, 'package.json')))
|
|
261
|
+
return dir;
|
|
262
|
+
const parent = dirname(dir);
|
|
263
|
+
if (parent === dir)
|
|
264
|
+
break;
|
|
265
|
+
dir = parent;
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Normalize model-drafted example content into a clean source file: strip a
|
|
272
|
+
* surrounding markdown code fence if the model added one, and ensure a trailing
|
|
273
|
+
* newline. The draft is instructed to omit fences, but a chatty backend may add
|
|
274
|
+
* them anyway.
|
|
275
|
+
*/
|
|
276
|
+
function normalizeExampleFile(raw) {
|
|
277
|
+
let body = raw.trim();
|
|
278
|
+
const fenced = body.match(/^```[a-zA-Z]*\n([\s\S]*?)\n```$/);
|
|
279
|
+
if (fenced?.[1] !== undefined)
|
|
280
|
+
body = fenced[1].trim();
|
|
281
|
+
return `${body}\n`;
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=config-source.js.map
|