whale-igniter 1.2.3 → 1.3.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/README.md +19 -2
- package/dist/analyzer/insights.js +144 -0
- package/dist/commands/adopt.js +20 -0
- package/dist/commands/changes.js +127 -0
- package/dist/commands/ignite.js +142 -76
- package/dist/commands/insights.js +146 -9
- package/dist/commands/references.js +193 -0
- package/dist/commands/sync.js +8 -0
- package/dist/generators/wikiGenerator.js +8 -304
- package/dist/index.js +33 -2
- package/dist/mcp/server.js +29 -0
- package/dist/scanner/extractors/css.js +95 -0
- package/dist/scanner/extractors/inline.js +131 -0
- package/dist/scanner/extractors/styleBlocks.js +37 -0
- package/dist/scanner/normalizer.js +59 -0
- package/dist/scanner/tailwindScanner.js +39 -0
- package/dist/templates/claude.js +93 -0
- package/dist/templates/components.js +45 -0
- package/dist/templates/conventions.js +45 -0
- package/dist/templates/decisions.js +34 -0
- package/dist/templates/foundations.js +34 -0
- package/dist/templates/project.js +82 -0
- package/dist/utils/aiAvailability.js +25 -0
- package/dist/utils/wizardMapping.js +54 -0
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -5,6 +5,12 @@ import { loadRefinements } from "../utils/refinements.js";
|
|
|
5
5
|
import { loadDecisions } from "../utils/decisions.js";
|
|
6
6
|
import { loadComponents } from "../utils/components.js";
|
|
7
7
|
import { validateCss } from "../validators/cssValidator.js";
|
|
8
|
+
import { renderFoundations } from "../templates/foundations.js";
|
|
9
|
+
import { renderConventions } from "../templates/conventions.js";
|
|
10
|
+
import { renderDecisions } from "../templates/decisions.js";
|
|
11
|
+
import { renderComponents } from "../templates/components.js";
|
|
12
|
+
import { renderProject, renderWikiReadme, renderWorkflows } from "../templates/project.js";
|
|
13
|
+
import { renderRootIndex } from "../templates/claude.js";
|
|
8
14
|
export async function generateWiki(target) {
|
|
9
15
|
const config = await loadConfig(target);
|
|
10
16
|
const refinements = await loadRefinements(target);
|
|
@@ -15,11 +21,10 @@ export async function generateWiki(target) {
|
|
|
15
21
|
const warnings = issues.filter((i) => i.severity === "warning").length;
|
|
16
22
|
const wikiDir = path.join(target, "llm-wiki");
|
|
17
23
|
await fs.ensureDir(wikiDir);
|
|
18
|
-
// ---- llm-wiki/ themed files ------------------------------------------------
|
|
19
24
|
const themedFiles = {
|
|
20
25
|
"README.md": renderWikiReadme(config),
|
|
21
26
|
"PROJECT.md": renderProject(config, errors, warnings, refinements.length, decisions.length),
|
|
22
|
-
"FOUNDATIONS.md": renderFoundations(config),
|
|
27
|
+
"FOUNDATIONS.md": renderFoundations(config, decisions),
|
|
23
28
|
"CONVENTIONS.md": renderConventions(config, refinements),
|
|
24
29
|
"DECISIONS.md": renderDecisions(decisions),
|
|
25
30
|
"COMPONENTS.md": renderComponents(components),
|
|
@@ -31,7 +36,6 @@ export async function generateWiki(target) {
|
|
|
31
36
|
await fs.writeFile(filePath, content);
|
|
32
37
|
wikiFiles.push(filePath);
|
|
33
38
|
}
|
|
34
|
-
// ---- root-level AI entry points -------------------------------------------
|
|
35
39
|
const rootIndex = renderRootIndex(config, {
|
|
36
40
|
errors,
|
|
37
41
|
warnings,
|
|
@@ -41,14 +45,12 @@ export async function generateWiki(target) {
|
|
|
41
45
|
});
|
|
42
46
|
const rootFiles = [];
|
|
43
47
|
const targets = config.aiTargets ?? ["claude"];
|
|
44
|
-
// CLAUDE.md is always written (default reader). Other agent files mirror it.
|
|
45
48
|
const filenamesByTarget = {
|
|
46
49
|
claude: "CLAUDE.md",
|
|
47
|
-
codex: "AGENTS.md",
|
|
50
|
+
codex: "AGENTS.md",
|
|
48
51
|
cursor: ".cursorrules",
|
|
49
52
|
copilot: ".github/copilot-instructions.md"
|
|
50
53
|
};
|
|
51
|
-
// Always emit CLAUDE.md as the canonical file, even if claude isn't listed.
|
|
52
54
|
const written = new Set();
|
|
53
55
|
const emit = async (filename) => {
|
|
54
56
|
if (written.has(filename))
|
|
@@ -65,301 +67,3 @@ export async function generateWiki(target) {
|
|
|
65
67
|
}
|
|
66
68
|
return { rootFiles, wikiFiles };
|
|
67
69
|
}
|
|
68
|
-
// ----------------------------------------------------------------------------
|
|
69
|
-
// Renderers
|
|
70
|
-
// ----------------------------------------------------------------------------
|
|
71
|
-
function renderRootIndex(config, stats) {
|
|
72
|
-
const name = config.projectName ?? "this project";
|
|
73
|
-
const grid = config.foundations?.grid ?? 8;
|
|
74
|
-
const ctrl = config.foundations?.radius?.control ?? 2;
|
|
75
|
-
const cont = config.foundations?.radius?.container ?? 4;
|
|
76
|
-
const stack = config.stack ?? "css";
|
|
77
|
-
const packs = (config.packs ?? []).join(", ") || "(none)";
|
|
78
|
-
return `# AI Agent Context — ${name}
|
|
79
|
-
|
|
80
|
-
> This file is auto-generated by [Whale Igniter](https://github.com/whale-igniter).
|
|
81
|
-
> Do not edit by hand. Run \`whale sync\` after changes to regenerate.
|
|
82
|
-
|
|
83
|
-
You are working in a project managed by Whale Igniter. Whale maintains
|
|
84
|
-
machine-readable operational context so AI agents understand the design
|
|
85
|
-
system, conventions and decisions without re-explaining them every session.
|
|
86
|
-
|
|
87
|
-
## Quick facts
|
|
88
|
-
|
|
89
|
-
- **Project type:** ${config.projectType ?? "unspecified"}
|
|
90
|
-
- **Stack:** ${stack}
|
|
91
|
-
- **Grid:** ${grid}px (all spacing must be a multiple)
|
|
92
|
-
- **Border radius:** ${ctrl}px (controls), ${cont}px (containers)
|
|
93
|
-
- **Active packs:** ${packs}
|
|
94
|
-
- **Validation status:** ${stats.errors} error(s), ${stats.warnings} warning(s)
|
|
95
|
-
- **Decisions logged:** ${stats.decisionCount}
|
|
96
|
-
- **Refinements active:** ${stats.refinementCount}
|
|
97
|
-
- **Components catalogued:** ${stats.componentCount}
|
|
98
|
-
|
|
99
|
-
## How to read this project
|
|
100
|
-
|
|
101
|
-
Whale stores structured context in two locations:
|
|
102
|
-
|
|
103
|
-
1. **\`intelligence/\`** — source of truth (JSON). Read these when you need precise data:
|
|
104
|
-
- \`intelligence/refinements.json\` — validator overrides the team has accepted
|
|
105
|
-
- \`intelligence/decisions.json\` — architectural and product decisions
|
|
106
|
-
- \`intelligence/components.json\` — catalog of components in the project
|
|
107
|
-
|
|
108
|
-
2. **\`llm-wiki/\`** — human + AI readable markdown rendered from the JSON:
|
|
109
|
-
- \`llm-wiki/FOUNDATIONS.md\` — design tokens and grid rules
|
|
110
|
-
- \`llm-wiki/CONVENTIONS.md\` — coding and design conventions
|
|
111
|
-
- \`llm-wiki/DECISIONS.md\` — decision log in narrative form
|
|
112
|
-
- \`llm-wiki/COMPONENTS.md\` — component catalog
|
|
113
|
-
- \`llm-wiki/WORKFLOWS.md\` — how the team uses Whale day to day
|
|
114
|
-
|
|
115
|
-
If a question can be answered from \`intelligence/*.json\`, prefer that file —
|
|
116
|
-
it's the source. The wiki is a rendered view.
|
|
117
|
-
|
|
118
|
-
## Rules you must follow
|
|
119
|
-
|
|
120
|
-
1. **Spacing.** Every padding, margin and gap must be a multiple of \`${grid}px\`.
|
|
121
|
-
2. **Radius.** Buttons, inputs, selects use \`${ctrl}px\`. Cards, modals, sheets use \`${cont}px\`.
|
|
122
|
-
3. **Color.** Prefer semantic tokens over raw hex. If you must add a hex,
|
|
123
|
-
record a refinement explaining why.
|
|
124
|
-
4. **Focus.** Every interactive element needs a visible \`:focus-visible\` state.
|
|
125
|
-
5. **Decisions.** When you make a non-obvious choice, propose recording it via
|
|
126
|
-
\`whale decision\` so future sessions inherit the reasoning.
|
|
127
|
-
6. **Refinements.** Honor entries in \`intelligence/refinements.json\` —
|
|
128
|
-
they encode intentional exceptions the team approved.
|
|
129
|
-
|
|
130
|
-
## When the user asks you to add a component
|
|
131
|
-
|
|
132
|
-
Before writing code:
|
|
133
|
-
- Check \`intelligence/components.json\` to see if it already exists.
|
|
134
|
-
- Check \`llm-wiki/FOUNDATIONS.md\` for the tokens to use.
|
|
135
|
-
- After creating it, suggest the user run \`whale component add <name>\`
|
|
136
|
-
so future agents know it exists.
|
|
137
|
-
|
|
138
|
-
## Commands available
|
|
139
|
-
|
|
140
|
-
- \`whale validate\` — runs the validators, exits non-zero on errors
|
|
141
|
-
- \`whale refine "<note>"\` — record a validator override
|
|
142
|
-
- \`whale decision\` — record an architectural decision (interactive)
|
|
143
|
-
- \`whale component add <name>\` — register a component
|
|
144
|
-
- \`whale sync\` — regenerate this file and the wiki
|
|
145
|
-
- \`whale docs\` — generate human-facing reports
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
_Last sync: ${new Date().toISOString()}_
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
|
-
function renderWikiReadme(config) {
|
|
152
|
-
return `# LLM Wiki
|
|
153
|
-
|
|
154
|
-
This directory is generated by Whale Igniter. It contains a human-and-AI
|
|
155
|
-
readable view of the project's operational context.
|
|
156
|
-
|
|
157
|
-
**Do not edit these files directly** — they are regenerated from
|
|
158
|
-
\`intelligence/*.json\` and \`whale.config.json\` whenever you run
|
|
159
|
-
\`whale sync\`.
|
|
160
|
-
|
|
161
|
-
## Files
|
|
162
|
-
|
|
163
|
-
- \`PROJECT.md\` — high-level project facts
|
|
164
|
-
- \`FOUNDATIONS.md\` — grid, radius, tokens
|
|
165
|
-
- \`CONVENTIONS.md\` — active conventions and refinements
|
|
166
|
-
- \`DECISIONS.md\` — decision log
|
|
167
|
-
- \`COMPONENTS.md\` — component catalog
|
|
168
|
-
- \`WORKFLOWS.md\` — recommended usage flow
|
|
169
|
-
|
|
170
|
-
## For AI agents
|
|
171
|
-
|
|
172
|
-
The canonical entry point for AI agents is \`/CLAUDE.md\` at the project root.
|
|
173
|
-
This wiki is the detailed view — start with the root file, drill in here.
|
|
174
|
-
|
|
175
|
-
_Generated by Whale Igniter v0.7._
|
|
176
|
-
`;
|
|
177
|
-
}
|
|
178
|
-
function renderProject(config, errors, warnings, refinementCount, decisionCount) {
|
|
179
|
-
return `# Project Context
|
|
180
|
-
|
|
181
|
-
- **Project name:** ${config.projectName ?? "(unset)"}
|
|
182
|
-
- **Project type:** ${config.projectType ?? "unspecified"}
|
|
183
|
-
- **Stack:** ${config.stack ?? "css"}
|
|
184
|
-
- **AI targets:** ${(config.aiTargets ?? []).join(", ") || "(none)"}
|
|
185
|
-
- **Active packs:** ${(config.packs ?? []).join(", ") || "(none)"}
|
|
186
|
-
- **Ignited:** ${config.ignited?.at ?? "(not yet)"} (${config.ignited?.mode ?? "—"})
|
|
187
|
-
|
|
188
|
-
## Current status
|
|
189
|
-
|
|
190
|
-
- Validation errors: ${errors}
|
|
191
|
-
- Validation warnings: ${warnings}
|
|
192
|
-
- Decisions logged: ${decisionCount}
|
|
193
|
-
- Active refinements: ${refinementCount}
|
|
194
|
-
|
|
195
|
-
_Generated by Whale Igniter._
|
|
196
|
-
`;
|
|
197
|
-
}
|
|
198
|
-
function renderFoundations(config) {
|
|
199
|
-
const grid = config.foundations?.grid ?? 8;
|
|
200
|
-
const ctrl = config.foundations?.radius?.control ?? 2;
|
|
201
|
-
const cont = config.foundations?.radius?.container ?? 4;
|
|
202
|
-
return `# Foundations
|
|
203
|
-
|
|
204
|
-
The invariants of this project. All UI must conform unless explicitly refined.
|
|
205
|
-
|
|
206
|
-
## Spacing
|
|
207
|
-
|
|
208
|
-
Grid unit: **${grid}px**.
|
|
209
|
-
|
|
210
|
-
Every padding, margin and gap should be a multiple of ${grid}px. The allowed
|
|
211
|
-
scale is:
|
|
212
|
-
|
|
213
|
-
\`\`\`
|
|
214
|
-
${[1, 2, 3, 4, 5, 6, 8, 10, 12].map((n) => `${n * grid}px`).join(" ")}
|
|
215
|
-
\`\`\`
|
|
216
|
-
|
|
217
|
-
## Radius
|
|
218
|
-
|
|
219
|
-
| Use | Value |
|
|
220
|
-
| -------------- | ------- |
|
|
221
|
-
| Controls | ${ctrl}px |
|
|
222
|
-
| Containers | ${cont}px |
|
|
223
|
-
|
|
224
|
-
Controls = buttons, inputs, selects, toggles. Containers = cards, modals,
|
|
225
|
-
sheets, popovers.
|
|
226
|
-
|
|
227
|
-
## Tone & accent
|
|
228
|
-
|
|
229
|
-
- Tone: ${config.branding?.tone ?? "(unset)"}
|
|
230
|
-
- Accent: ${config.branding?.accent ?? "(unset)"}
|
|
231
|
-
|
|
232
|
-
_Generated by Whale Igniter._
|
|
233
|
-
`;
|
|
234
|
-
}
|
|
235
|
-
function renderConventions(config, refinements) {
|
|
236
|
-
const lines = [
|
|
237
|
-
"# Conventions",
|
|
238
|
-
"",
|
|
239
|
-
"## Rules",
|
|
240
|
-
"",
|
|
241
|
-
`- Spacing is a multiple of ${config.foundations?.grid ?? 8}px.`,
|
|
242
|
-
"- Controls and containers use distinct radius values (see FOUNDATIONS.md).",
|
|
243
|
-
"- Every interactive element has a visible \`:focus-visible\` state.",
|
|
244
|
-
"- Prefer semantic tokens over raw color values.",
|
|
245
|
-
"",
|
|
246
|
-
"## Active refinements",
|
|
247
|
-
""
|
|
248
|
-
];
|
|
249
|
-
if (refinements.length === 0) {
|
|
250
|
-
lines.push("_No refinements recorded yet._");
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
lines.push("These are exceptions the team has explicitly approved. The validator", "suppresses matching issues.", "");
|
|
254
|
-
for (const r of refinements) {
|
|
255
|
-
const scopeParts = [];
|
|
256
|
-
if (r.scope?.issueType)
|
|
257
|
-
scopeParts.push(`type=\`${r.scope.issueType}\``);
|
|
258
|
-
if (r.scope?.selector)
|
|
259
|
-
scopeParts.push(`selector=\`${r.scope.selector}\``);
|
|
260
|
-
if (r.scope?.file)
|
|
261
|
-
scopeParts.push(`file=\`${r.scope.file}\``);
|
|
262
|
-
const scope = scopeParts.length ? ` _(${scopeParts.join(", ")})_` : "";
|
|
263
|
-
lines.push(`- **${r.timestamp.slice(0, 10)}** — ${r.note}${scope}`);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
lines.push("", "_Generated by Whale Igniter._");
|
|
267
|
-
return lines.join("\n");
|
|
268
|
-
}
|
|
269
|
-
function renderDecisions(decisions) {
|
|
270
|
-
const lines = [
|
|
271
|
-
"# Decision Log",
|
|
272
|
-
"",
|
|
273
|
-
"Architectural, product and tooling decisions, in reverse chronological order.",
|
|
274
|
-
""
|
|
275
|
-
];
|
|
276
|
-
if (decisions.length === 0) {
|
|
277
|
-
lines.push("_No decisions logged yet. Use `whale decision` to record one._");
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
const sorted = [...decisions].sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
281
|
-
for (const d of sorted) {
|
|
282
|
-
lines.push(`## ${d.title}`);
|
|
283
|
-
lines.push("");
|
|
284
|
-
lines.push(`- **Date:** ${d.timestamp.slice(0, 10)}`);
|
|
285
|
-
lines.push(`- **Category:** ${d.category}`);
|
|
286
|
-
lines.push(`- **Status:** ${d.status}`);
|
|
287
|
-
if (d.context) {
|
|
288
|
-
lines.push("", "**Context**", "", d.context);
|
|
289
|
-
}
|
|
290
|
-
lines.push("", "**Decision**", "", d.decision);
|
|
291
|
-
if (d.consequences) {
|
|
292
|
-
lines.push("", "**Consequences**", "", d.consequences);
|
|
293
|
-
}
|
|
294
|
-
lines.push("", "---", "");
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
lines.push("_Generated by Whale Igniter._");
|
|
298
|
-
return lines.join("\n");
|
|
299
|
-
}
|
|
300
|
-
function renderComponents(components) {
|
|
301
|
-
const lines = ["# Component Catalog", ""];
|
|
302
|
-
if (components.length === 0) {
|
|
303
|
-
lines.push("_No components catalogued yet. Use `whale component add <name>` to register one._");
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
const sorted = [...components].sort((a, b) => a.name.localeCompare(b.name));
|
|
307
|
-
for (const c of sorted) {
|
|
308
|
-
lines.push(`## ${c.name}`);
|
|
309
|
-
lines.push("");
|
|
310
|
-
if (c.description)
|
|
311
|
-
lines.push(c.description, "");
|
|
312
|
-
const meta = [];
|
|
313
|
-
if (c.category)
|
|
314
|
-
meta.push(`Category: ${c.category}`);
|
|
315
|
-
if (c.variants?.length)
|
|
316
|
-
meta.push(`Variants: ${c.variants.join(", ")}`);
|
|
317
|
-
if (c.states?.length)
|
|
318
|
-
meta.push(`States: ${c.states.join(", ")}`);
|
|
319
|
-
if (meta.length)
|
|
320
|
-
lines.push(meta.map((m) => `- ${m}`).join("\n"), "");
|
|
321
|
-
if (c.files?.length) {
|
|
322
|
-
lines.push("**Files:**");
|
|
323
|
-
for (const f of c.files)
|
|
324
|
-
lines.push(`- \`${f}\``);
|
|
325
|
-
lines.push("");
|
|
326
|
-
}
|
|
327
|
-
lines.push("---", "");
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
lines.push("_Generated by Whale Igniter._");
|
|
331
|
-
return lines.join("\n");
|
|
332
|
-
}
|
|
333
|
-
function renderWorkflows(_config) {
|
|
334
|
-
return `# Workflows
|
|
335
|
-
|
|
336
|
-
## Daily flow
|
|
337
|
-
|
|
338
|
-
\`\`\`
|
|
339
|
-
whale validate # see what's drifting
|
|
340
|
-
whale refine "<note>" # accept an intentional exception
|
|
341
|
-
whale decision # record a non-obvious choice
|
|
342
|
-
whale component add <name> # register a new component
|
|
343
|
-
whale sync # regenerate AI context
|
|
344
|
-
\`\`\`
|
|
345
|
-
|
|
346
|
-
## When to use what
|
|
347
|
-
|
|
348
|
-
| You want to... | Command |
|
|
349
|
-
| --------------------------------------------- | ----------------------------- |
|
|
350
|
-
| See what's broken | \`whale validate\` |
|
|
351
|
-
| Accept an exception ("we use radius 0 here") | \`whale refine "..."\` |
|
|
352
|
-
| Log an architecture/product choice | \`whale decision\` |
|
|
353
|
-
| Track a new component | \`whale component add\` |
|
|
354
|
-
| Refresh AI context after manual edits | \`whale sync\` |
|
|
355
|
-
| Produce human reports | \`whale docs\` |
|
|
356
|
-
|
|
357
|
-
## Recommended cadence
|
|
358
|
-
|
|
359
|
-
- **Per change:** run \`validate\` before commit.
|
|
360
|
-
- **Per significant choice:** record a \`decision\` or \`refinement\`.
|
|
361
|
-
- **Per session:** run \`sync\` before handing off to an AI agent.
|
|
362
|
-
|
|
363
|
-
_Generated by Whale Igniter._
|
|
364
|
-
`;
|
|
365
|
-
}
|
package/dist/index.js
CHANGED
|
@@ -12,13 +12,15 @@ import { decisionCommand } from "./commands/decision.js";
|
|
|
12
12
|
import { componentAddCommand, componentListCommand } from "./commands/component.js";
|
|
13
13
|
import { adoptCommand } from "./commands/adopt.js";
|
|
14
14
|
import { adoptReviewCommand, adoptStatusCommand } from "./commands/adoptReview.js";
|
|
15
|
-
import { insightsCommand } from "./commands/insights.js";
|
|
15
|
+
import { insightsCommand, insightsDriftReviewCommand } from "./commands/insights.js";
|
|
16
16
|
import { createComponentCommand } from "./commands/createComponent.js";
|
|
17
17
|
import { seleneDescribeCommand, seleneAuditCommand, seleneSuggestCommand, seleneApplyCommand, seleneStatusCommand, seleneCacheClearCommand } from "./commands/selene.js";
|
|
18
18
|
import { mcpServeCommand, mcpConfigCommand } from "./commands/mcp.js";
|
|
19
19
|
import { watchCommand } from "./commands/watch.js";
|
|
20
20
|
import { rememberCommand, checkCommand, improveCommand, explainCommand } from "./commands/friendly.js";
|
|
21
21
|
import { teamAddCommand, teamListCommand } from "./commands/team.js";
|
|
22
|
+
import { referencesListCommand, referencesAddCommand, referencesUpdateCommand } from "./commands/references.js";
|
|
23
|
+
import { changesCommand } from "./commands/changes.js";
|
|
22
24
|
import { PACKAGE_VERSION } from "./version.js";
|
|
23
25
|
const program = new Command();
|
|
24
26
|
program
|
|
@@ -142,7 +144,7 @@ cache
|
|
|
142
144
|
.command("clear")
|
|
143
145
|
.description("Delete all cached Selene responses.")
|
|
144
146
|
.action(() => seleneCacheClearCommand());
|
|
145
|
-
program
|
|
147
|
+
const insightsCmd = program
|
|
146
148
|
.command("insights [target]")
|
|
147
149
|
.description("Run local analyzers over the intelligence stores and surface accountable recommendations.")
|
|
148
150
|
.option("--json", "Emit insights as JSON (for scripting / CI)")
|
|
@@ -150,6 +152,12 @@ program
|
|
|
150
152
|
.option("--min-severity <level>", "Show only insights at this severity or higher (info | warning | critical)")
|
|
151
153
|
.option("--skip-scan", "Skip the source scan (faster, but disables orphan/drift insights)")
|
|
152
154
|
.action((target, opts) => insightsCommand(target, opts));
|
|
155
|
+
insightsCmd
|
|
156
|
+
.command("drift <category>")
|
|
157
|
+
.description("Show or review drift in spacing | color | radii.")
|
|
158
|
+
.option("--review", "Enter interactive review loop: accept as refinement, flag for refactor, or skip")
|
|
159
|
+
.option("--target <path>", "Workspace path (default: cwd)")
|
|
160
|
+
.action((category, opts) => insightsDriftReviewCommand(category, opts));
|
|
153
161
|
const create = program
|
|
154
162
|
.command("create")
|
|
155
163
|
.description("Generate new code that respects the project's foundations.");
|
|
@@ -234,6 +242,24 @@ mcp
|
|
|
234
242
|
.option("--client <name>", "claude-code | cursor | zed | raw", "claude-code")
|
|
235
243
|
.option("--project <path>", "Workspace path (default: cwd)")
|
|
236
244
|
.action((opts) => mcpConfigCommand(opts));
|
|
245
|
+
const references = program
|
|
246
|
+
.command("references")
|
|
247
|
+
.description("Manage the UI component reference library for this project.");
|
|
248
|
+
references
|
|
249
|
+
.command("list [target]")
|
|
250
|
+
.description("Show available reference categories and which are present in this project.")
|
|
251
|
+
.action((target) => referencesListCommand(target));
|
|
252
|
+
references
|
|
253
|
+
.command("add [category]")
|
|
254
|
+
.description("Copy a reference category from the Whale library into references/<category>.md.")
|
|
255
|
+
.option("--all", "Copy all categories (INDEX + all six category files)")
|
|
256
|
+
.option("--target <path>", "Workspace path (default: cwd)")
|
|
257
|
+
.action((category, opts) => referencesAddCommand(category, opts));
|
|
258
|
+
references
|
|
259
|
+
.command("update [target]")
|
|
260
|
+
.description("Re-copy references from Whale, prompting to keep/overwrite locally modified files.")
|
|
261
|
+
.action((target) => referencesUpdateCommand(target));
|
|
262
|
+
references.action((opts) => referencesListCommand(opts.target));
|
|
237
263
|
program
|
|
238
264
|
.command("watch [target]")
|
|
239
265
|
.description("Watch foundations and intelligence stores; regenerate CLAUDE.md and wiki on change.")
|
|
@@ -241,4 +267,9 @@ program
|
|
|
241
267
|
.option("--verbose", "Print every change event and regeneration detail")
|
|
242
268
|
.option("--once", "Run a single regeneration and exit (useful for CI)")
|
|
243
269
|
.action((target, opts) => watchCommand(target, opts));
|
|
270
|
+
program
|
|
271
|
+
.command("changes [target]")
|
|
272
|
+
.description("Show what changed in intelligence stores since a git ref.")
|
|
273
|
+
.option("--since <ref>", "Git ref to compare against (default: HEAD~1)", "HEAD~1")
|
|
274
|
+
.action((target, opts) => changesCommand({ since: opts.since, target }));
|
|
244
275
|
program.parse();
|
package/dist/mcp/server.js
CHANGED
|
@@ -381,6 +381,35 @@ export function buildMcpServer() {
|
|
|
381
381
|
return ok(`Regenerated ${rootFiles.length} root file(s) and ${wikiFiles.length} wiki file(s).\n` +
|
|
382
382
|
`Root: ${rootFiles.map((f) => path.relative(ws, f)).join(", ")}`);
|
|
383
383
|
});
|
|
384
|
+
server.registerTool("whale_ui_reference", {
|
|
385
|
+
title: "Read a UI references category file",
|
|
386
|
+
description: "Returns the contents of a curated UI component reference file from this " +
|
|
387
|
+
"project's references/ directory. These files document the quality bar and " +
|
|
388
|
+
"best implementations for each component category. Call this BEFORE building " +
|
|
389
|
+
"any UI component — consult the relevant category to understand what states " +
|
|
390
|
+
"and behaviors are required. Use 'INDEX' as the category to get the index file.",
|
|
391
|
+
inputSchema: {
|
|
392
|
+
category: z
|
|
393
|
+
.string()
|
|
394
|
+
.describe("Category slug: forms | navigation | feedback | surface | layout | data-display | INDEX"),
|
|
395
|
+
target: z.string().optional().describe("Workspace path. Defaults to WHALE_PROJECT or cwd.")
|
|
396
|
+
}
|
|
397
|
+
}, async ({ category, target }) => {
|
|
398
|
+
const ws = resolveWorkspace(target);
|
|
399
|
+
const filename = category.toUpperCase() === "INDEX" ? "INDEX.md" : `${category}.md`;
|
|
400
|
+
const referencePath = path.join(ws, "references", filename);
|
|
401
|
+
if (!(await fs.pathExists(referencePath))) {
|
|
402
|
+
const configPath = path.join(ws, "whale.config.json");
|
|
403
|
+
const hasProject = await fs.pathExists(configPath);
|
|
404
|
+
if (!hasProject) {
|
|
405
|
+
return err(`No whale.config.json found at ${ws}. Run \`whale ignite\` or \`whale adopt\` first.`);
|
|
406
|
+
}
|
|
407
|
+
return err(`references/${filename} not found in this project. ` +
|
|
408
|
+
`Run \`whale references add ${category}\` to copy it from the Whale library.`);
|
|
409
|
+
}
|
|
410
|
+
const content = await fs.readFile(referencePath, "utf-8");
|
|
411
|
+
return ok(content);
|
|
412
|
+
});
|
|
384
413
|
return server;
|
|
385
414
|
}
|
|
386
415
|
/**
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import postcss from "postcss";
|
|
4
|
+
import { parsePxValue, TRACKED_PROPERTIES } from "../normalizer.js";
|
|
5
|
+
const IGNORE = ["node_modules/**", "dist/**", ".next/**", "build/**", "coverage/**"];
|
|
6
|
+
// Resolve a CSS variable reference against :root declarations in the same file.
|
|
7
|
+
// Follows one level only: var(--x) → value. Does not recurse.
|
|
8
|
+
function buildVarMap(root) {
|
|
9
|
+
const vars = new Map();
|
|
10
|
+
root.walkRules((rule) => {
|
|
11
|
+
if (rule.selector === ":root" || rule.selector === ":root,\n:root") {
|
|
12
|
+
rule.walkDecls((decl) => {
|
|
13
|
+
if (decl.prop.startsWith("--")) {
|
|
14
|
+
vars.set(decl.prop, decl.value);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return vars;
|
|
20
|
+
}
|
|
21
|
+
function resolveValue(value, vars) {
|
|
22
|
+
const match = value.match(/^var\((--[^),\s]+)\)/);
|
|
23
|
+
if (!match)
|
|
24
|
+
return value;
|
|
25
|
+
const resolved = vars.get(match[1]);
|
|
26
|
+
return resolved && !resolved.startsWith("var(") ? resolved : value;
|
|
27
|
+
}
|
|
28
|
+
async function extractFromFile(filePath, source, lineOffset = 0) {
|
|
29
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
30
|
+
let root;
|
|
31
|
+
try {
|
|
32
|
+
root = postcss.parse(content);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const vars = buildVarMap(root);
|
|
38
|
+
const observations = [];
|
|
39
|
+
root.walkDecls((decl) => {
|
|
40
|
+
const prop = decl.prop.toLowerCase();
|
|
41
|
+
if (!TRACKED_PROPERTIES.has(prop))
|
|
42
|
+
return;
|
|
43
|
+
const rawValue = decl.value;
|
|
44
|
+
const resolvedValue = resolveValue(rawValue, vars);
|
|
45
|
+
observations.push({
|
|
46
|
+
property: prop,
|
|
47
|
+
value: resolvedValue,
|
|
48
|
+
pxValue: parsePxValue(resolvedValue),
|
|
49
|
+
file: filePath,
|
|
50
|
+
line: (decl.source?.start?.line ?? 1) + lineOffset,
|
|
51
|
+
column: decl.source?.start?.column,
|
|
52
|
+
source
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return observations;
|
|
56
|
+
}
|
|
57
|
+
// Walk @media and @supports blocks too — postcss.walkDecls handles them already.
|
|
58
|
+
// Exported separately so styleBlocks extractor can reuse the logic.
|
|
59
|
+
export async function extractFromContent(content, filePath, lineOffset, source) {
|
|
60
|
+
let root;
|
|
61
|
+
try {
|
|
62
|
+
root = postcss.parse(content);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const vars = buildVarMap(root);
|
|
68
|
+
const observations = [];
|
|
69
|
+
root.walkDecls((decl) => {
|
|
70
|
+
const prop = decl.prop.toLowerCase();
|
|
71
|
+
if (!TRACKED_PROPERTIES.has(prop))
|
|
72
|
+
return;
|
|
73
|
+
const rawValue = decl.value;
|
|
74
|
+
const resolvedValue = resolveValue(rawValue, vars);
|
|
75
|
+
observations.push({
|
|
76
|
+
property: prop,
|
|
77
|
+
value: resolvedValue,
|
|
78
|
+
pxValue: parsePxValue(resolvedValue),
|
|
79
|
+
file: filePath,
|
|
80
|
+
line: (decl.source?.start?.line ?? 1) + lineOffset,
|
|
81
|
+
column: decl.source?.start?.column,
|
|
82
|
+
source
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return observations;
|
|
86
|
+
}
|
|
87
|
+
export async function extractFromCssFiles(root) {
|
|
88
|
+
const files = await glob("**/*.{css,scss,sass,less}", {
|
|
89
|
+
cwd: root,
|
|
90
|
+
ignore: IGNORE,
|
|
91
|
+
absolute: true
|
|
92
|
+
});
|
|
93
|
+
const results = await Promise.all(files.map((f) => extractFromFile(f, "css")));
|
|
94
|
+
return results.flat();
|
|
95
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import { parse as babelParse } from "@babel/parser";
|
|
4
|
+
import * as t from "@babel/types";
|
|
5
|
+
import { parsePxValue, TRACKED_PROPERTIES, camelToCssProperty } from "../normalizer.js";
|
|
6
|
+
const IGNORE = ["node_modules/**", "dist/**", ".next/**", "build/**", "coverage/**"];
|
|
7
|
+
function countNewlines(str, upTo) {
|
|
8
|
+
let count = 1;
|
|
9
|
+
for (let i = 0; i < upTo && i < str.length; i++) {
|
|
10
|
+
if (str[i] === "\n")
|
|
11
|
+
count++;
|
|
12
|
+
}
|
|
13
|
+
return count;
|
|
14
|
+
}
|
|
15
|
+
// Manual AST walk — avoids @babel/traverse callable-default ESM issues
|
|
16
|
+
function walkAst(node, visitor) {
|
|
17
|
+
if (!node || typeof node !== "object")
|
|
18
|
+
return;
|
|
19
|
+
visitor(node);
|
|
20
|
+
for (const key of Object.keys(node)) {
|
|
21
|
+
const child = node[key];
|
|
22
|
+
if (!child || typeof child !== "object")
|
|
23
|
+
continue;
|
|
24
|
+
if (Array.isArray(child)) {
|
|
25
|
+
for (const item of child) {
|
|
26
|
+
if (item && typeof item === "object" && "type" in item) {
|
|
27
|
+
walkAst(item, visitor);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if ("type" in child) {
|
|
32
|
+
walkAst(child, visitor);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Parse HTML style="..." attributes with a regex
|
|
37
|
+
async function extractFromHtml(filePath) {
|
|
38
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
39
|
+
const observations = [];
|
|
40
|
+
const attrRegex = /style="([^"]+)"/gi;
|
|
41
|
+
let match;
|
|
42
|
+
while ((match = attrRegex.exec(content)) !== null) {
|
|
43
|
+
const line = countNewlines(content, match.index);
|
|
44
|
+
const declarations = match[1].split(";").map((s) => s.trim()).filter(Boolean);
|
|
45
|
+
for (const decl of declarations) {
|
|
46
|
+
const colonIdx = decl.indexOf(":");
|
|
47
|
+
if (colonIdx === -1)
|
|
48
|
+
continue;
|
|
49
|
+
const prop = decl.slice(0, colonIdx).trim().toLowerCase();
|
|
50
|
+
const value = decl.slice(colonIdx + 1).trim();
|
|
51
|
+
if (!TRACKED_PROPERTIES.has(prop))
|
|
52
|
+
continue;
|
|
53
|
+
observations.push({
|
|
54
|
+
property: prop,
|
|
55
|
+
value,
|
|
56
|
+
pxValue: parsePxValue(value),
|
|
57
|
+
file: filePath,
|
|
58
|
+
line,
|
|
59
|
+
source: "inline"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return observations;
|
|
64
|
+
}
|
|
65
|
+
// Parse JSX style={{ }} using manual AST walk
|
|
66
|
+
async function extractFromJsx(filePath) {
|
|
67
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
68
|
+
let ast;
|
|
69
|
+
try {
|
|
70
|
+
ast = babelParse(content, {
|
|
71
|
+
sourceType: "module",
|
|
72
|
+
plugins: ["typescript", "jsx"],
|
|
73
|
+
errorRecovery: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const observations = [];
|
|
80
|
+
walkAst(ast, (node) => {
|
|
81
|
+
if (!t.isJSXAttribute(node))
|
|
82
|
+
return;
|
|
83
|
+
if (!t.isJSXIdentifier(node.name, { name: "style" }))
|
|
84
|
+
return;
|
|
85
|
+
if (!t.isJSXExpressionContainer(node.value))
|
|
86
|
+
return;
|
|
87
|
+
const expr = node.value.expression;
|
|
88
|
+
if (!t.isObjectExpression(expr))
|
|
89
|
+
return;
|
|
90
|
+
for (const prop of expr.properties) {
|
|
91
|
+
if (!t.isObjectProperty(prop))
|
|
92
|
+
continue;
|
|
93
|
+
if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
|
|
94
|
+
continue;
|
|
95
|
+
const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
96
|
+
const cssProp = camelToCssProperty(keyName);
|
|
97
|
+
if (!cssProp)
|
|
98
|
+
continue;
|
|
99
|
+
let value;
|
|
100
|
+
if (t.isStringLiteral(prop.value)) {
|
|
101
|
+
value = prop.value.value;
|
|
102
|
+
}
|
|
103
|
+
else if (t.isNumericLiteral(prop.value)) {
|
|
104
|
+
value = `${prop.value.value}px`;
|
|
105
|
+
}
|
|
106
|
+
if (!value)
|
|
107
|
+
continue;
|
|
108
|
+
const line = prop.loc?.start.line ?? 0;
|
|
109
|
+
observations.push({
|
|
110
|
+
property: cssProp,
|
|
111
|
+
value,
|
|
112
|
+
pxValue: parsePxValue(value),
|
|
113
|
+
file: filePath,
|
|
114
|
+
line,
|
|
115
|
+
source: "inline"
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return observations;
|
|
120
|
+
}
|
|
121
|
+
export async function extractFromInlineStyles(root) {
|
|
122
|
+
const [htmlFiles, jsxFiles] = await Promise.all([
|
|
123
|
+
glob("**/*.{html,htm}", { cwd: root, ignore: IGNORE, absolute: true }),
|
|
124
|
+
glob("**/*.{tsx,jsx}", { cwd: root, ignore: IGNORE, absolute: true })
|
|
125
|
+
]);
|
|
126
|
+
const results = await Promise.all([
|
|
127
|
+
...htmlFiles.map(extractFromHtml),
|
|
128
|
+
...jsxFiles.map(extractFromJsx)
|
|
129
|
+
]);
|
|
130
|
+
return results.flat();
|
|
131
|
+
}
|