specdx 0.3.0-alpha.3 → 0.4.0-alpha.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.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/{pack-PI6V6OR2.js → chunk-4THCEWAK.js} +3 -162
- package/dist/chunk-4THCEWAK.js.map +1 -0
- package/dist/{chunk-WTFWNYJA.js → chunk-HMXUNURD.js} +231 -2
- package/dist/chunk-HMXUNURD.js.map +1 -0
- package/dist/dist-QXLX77XG.js +279 -0
- package/dist/dist-QXLX77XG.js.map +1 -0
- package/dist/index.js +232 -3
- package/dist/index.js.map +1 -1
- package/dist/{lint-6Z2TVWAQ.js → lint-XPAFMLZN.js} +2 -2
- package/dist/main.js +6 -5
- package/dist/main.js.map +1 -1
- package/dist/mcp-6RCSHMXD.js +17 -0
- package/dist/mcp-6RCSHMXD.js.map +1 -0
- package/dist/pack-QCOXMURY.js +167 -0
- package/dist/pack-QCOXMURY.js.map +1 -0
- package/dist/{ready-B7IFPL3S.js → ready-ZXG74W7Y.js} +2 -2
- package/dist/{status-AV5GSWVI.js → status-EKWK47O5.js} +2 -2
- package/package.json +2 -1
- package/dist/chunk-WTFWNYJA.js.map +0 -1
- package/dist/pack-PI6V6OR2.js.map +0 -1
- /package/dist/{lint-6Z2TVWAQ.js.map → lint-XPAFMLZN.js.map} +0 -0
- /package/dist/{ready-B7IFPL3S.js.map → ready-ZXG74W7Y.js.map} +0 -0
- /package/dist/{status-AV5GSWVI.js.map → status-EKWK47O5.js.map} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runCheck
|
|
3
|
+
} from "./chunk-6BWZEAST.js";
|
|
4
|
+
import {
|
|
5
|
+
pack
|
|
6
|
+
} from "./chunk-4THCEWAK.js";
|
|
7
|
+
import {
|
|
8
|
+
createLintEngine,
|
|
9
|
+
getPreset
|
|
10
|
+
} from "./chunk-HMXUNURD.js";
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_DIFF_CONFIG,
|
|
13
|
+
DiffError,
|
|
14
|
+
diffBetweenRefs
|
|
15
|
+
} from "./chunk-DDFLMRPC.js";
|
|
16
|
+
import {
|
|
17
|
+
ConfigError,
|
|
18
|
+
GraphError,
|
|
19
|
+
buildGraph,
|
|
20
|
+
loadConfig,
|
|
21
|
+
parseSpec,
|
|
22
|
+
resolveGlob
|
|
23
|
+
} from "./chunk-PHR7AV6I.js";
|
|
24
|
+
import "./chunk-ZX4HVL5M.js";
|
|
25
|
+
|
|
26
|
+
// ../mcp/dist/server.js
|
|
27
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
|
|
30
|
+
// ../mcp/dist/tools/validate.js
|
|
31
|
+
async function handleValidate(params) {
|
|
32
|
+
try {
|
|
33
|
+
const configDir = params.configPath ?? process.cwd();
|
|
34
|
+
const config = await loadConfig(void 0, configDir);
|
|
35
|
+
return JSON.stringify({
|
|
36
|
+
valid: true,
|
|
37
|
+
specCount: Object.keys(config.specs).length,
|
|
38
|
+
project: config.project?.name ?? "unknown"
|
|
39
|
+
});
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (err instanceof ConfigError) {
|
|
42
|
+
return JSON.stringify({ valid: false, error: err.message, details: err.errors });
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ../mcp/dist/tools/lint.js
|
|
49
|
+
async function handleLint(params) {
|
|
50
|
+
const configDir = process.cwd();
|
|
51
|
+
const config = await loadConfig(void 0, configDir);
|
|
52
|
+
const preset = params.preset ?? config.lint?.extends ?? "recommended";
|
|
53
|
+
const rules = getPreset(preset);
|
|
54
|
+
const specs = [];
|
|
55
|
+
for (const [, entry] of Object.entries(config.specs)) {
|
|
56
|
+
const files = await resolveGlob(entry.path, configDir);
|
|
57
|
+
for (const file of files) {
|
|
58
|
+
if (params.specPath && !file.includes(params.specPath))
|
|
59
|
+
continue;
|
|
60
|
+
specs.push(await parseSpec(file));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let graph;
|
|
64
|
+
try {
|
|
65
|
+
graph = buildGraph(config);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
const engine = createLintEngine({ rules, config, graph });
|
|
69
|
+
const results = engine.lint(specs);
|
|
70
|
+
return JSON.stringify({
|
|
71
|
+
diagnostics: results.diagnostics,
|
|
72
|
+
hasErrors: results.hasErrors,
|
|
73
|
+
hasWarnings: results.hasWarnings,
|
|
74
|
+
specsChecked: specs.length
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ../mcp/dist/tools/pack.js
|
|
79
|
+
async function handlePack(params) {
|
|
80
|
+
const configDir = process.cwd();
|
|
81
|
+
const config = await loadConfig(void 0, configDir);
|
|
82
|
+
const allSpecs = [];
|
|
83
|
+
for (const [, entry] of Object.entries(config.specs)) {
|
|
84
|
+
const files = await resolveGlob(entry.path, configDir);
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
allSpecs.push(await parseSpec(file));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let graph;
|
|
90
|
+
try {
|
|
91
|
+
graph = buildGraph(config);
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
const result = pack(allSpecs, {
|
|
95
|
+
task: params.task,
|
|
96
|
+
budget: params.budget,
|
|
97
|
+
format: params.format ?? void 0
|
|
98
|
+
}, config.pack, graph);
|
|
99
|
+
return result.output;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ../mcp/dist/tools/status.js
|
|
103
|
+
async function handleStatus() {
|
|
104
|
+
const configDir = process.cwd();
|
|
105
|
+
const config = await loadConfig(void 0, configDir);
|
|
106
|
+
const specs = [];
|
|
107
|
+
for (const [, entry] of Object.entries(config.specs)) {
|
|
108
|
+
const paths = await resolveGlob(entry.path, configDir);
|
|
109
|
+
for (const p of paths) {
|
|
110
|
+
const spec = await parseSpec(p);
|
|
111
|
+
specs.push({ spec, entry });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const byStatus = {};
|
|
115
|
+
for (const { spec } of specs) {
|
|
116
|
+
const status = spec.frontmatter.status || "unknown";
|
|
117
|
+
byStatus[status] = (byStatus[status] ?? 0) + 1;
|
|
118
|
+
}
|
|
119
|
+
const presetName = config.lint?.extends ?? "recommended";
|
|
120
|
+
const rules = getPreset(presetName);
|
|
121
|
+
let graph;
|
|
122
|
+
let graphError;
|
|
123
|
+
try {
|
|
124
|
+
graph = buildGraph(config);
|
|
125
|
+
} catch (err) {
|
|
126
|
+
graphError = err.message;
|
|
127
|
+
}
|
|
128
|
+
const engine = createLintEngine({ rules, config, graph });
|
|
129
|
+
const lintResults = engine.lint(specs.map((s) => s.spec));
|
|
130
|
+
const errors = lintResults.diagnostics.filter((d) => d.severity === "error").length;
|
|
131
|
+
const warnings = lintResults.diagnostics.filter((d) => d.severity === "warn").length;
|
|
132
|
+
const thresholdDays = config.diff?.staleness_threshold_days ?? DEFAULT_DIFF_CONFIG.staleness_threshold_days;
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
const staleSpecs = [];
|
|
135
|
+
for (const { spec, entry } of specs) {
|
|
136
|
+
const dateStr = spec.frontmatter.updated || spec.frontmatter.created;
|
|
137
|
+
if (dateStr) {
|
|
138
|
+
const days = Math.floor((now - new Date(dateStr).getTime()) / (1e3 * 60 * 60 * 24));
|
|
139
|
+
if (days > thresholdDays) {
|
|
140
|
+
staleSpecs.push({
|
|
141
|
+
specId: spec.frontmatter.id,
|
|
142
|
+
daysSinceUpdate: days,
|
|
143
|
+
owner: entry.owner
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let verdict = "healthy";
|
|
149
|
+
if (errors > 0 || graphError)
|
|
150
|
+
verdict = "errors";
|
|
151
|
+
else if (warnings > 0 || staleSpecs.length > 0)
|
|
152
|
+
verdict = "warnings";
|
|
153
|
+
return JSON.stringify({
|
|
154
|
+
project: config.project?.name ?? "unknown",
|
|
155
|
+
specCount: specs.length,
|
|
156
|
+
byStatus,
|
|
157
|
+
lintHealth: { errors, warnings, passing: specs.length - errors },
|
|
158
|
+
staleSpecs,
|
|
159
|
+
integrityIssues: graphError ? [graphError] : [],
|
|
160
|
+
verdict
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ../mcp/dist/tools/check.js
|
|
165
|
+
async function handleCheck(params) {
|
|
166
|
+
const configDir = process.cwd();
|
|
167
|
+
const config = await loadConfig(void 0, configDir);
|
|
168
|
+
const specs = [];
|
|
169
|
+
for (const [, entry] of Object.entries(config.specs)) {
|
|
170
|
+
const paths = await resolveGlob(entry.path, configDir);
|
|
171
|
+
for (const p of paths) {
|
|
172
|
+
const spec = await parseSpec(p);
|
|
173
|
+
if (params.specId && spec.frontmatter.id !== params.specId)
|
|
174
|
+
continue;
|
|
175
|
+
specs.push(spec);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const checkConfig = {
|
|
179
|
+
...config.check,
|
|
180
|
+
...params.framework ? { framework: params.framework } : {}
|
|
181
|
+
};
|
|
182
|
+
const result = await runCheck(specs, configDir, checkConfig);
|
|
183
|
+
return JSON.stringify(result);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ../mcp/dist/tools/diff.js
|
|
187
|
+
import { join } from "path";
|
|
188
|
+
async function handleDiff(params) {
|
|
189
|
+
const configDir = process.cwd();
|
|
190
|
+
const config = await loadConfig(void 0, configDir);
|
|
191
|
+
const baseRef = params.base ?? config.diff?.baseline_ref ?? DEFAULT_DIFF_CONFIG.baseline_ref;
|
|
192
|
+
const headRef = params.head ?? "HEAD";
|
|
193
|
+
const configPath = join(configDir, "spec.config.yaml");
|
|
194
|
+
try {
|
|
195
|
+
const result = await diffBetweenRefs(configPath, baseRef, headRef);
|
|
196
|
+
return JSON.stringify(result);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
if (err instanceof DiffError) {
|
|
199
|
+
return JSON.stringify({ error: err.message });
|
|
200
|
+
}
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ../mcp/dist/tools/graph.js
|
|
206
|
+
async function handleGraph(params) {
|
|
207
|
+
const configDir = process.cwd();
|
|
208
|
+
const config = await loadConfig(void 0, configDir);
|
|
209
|
+
try {
|
|
210
|
+
const graph = buildGraph(config);
|
|
211
|
+
const sorted = graph.topologicalSort();
|
|
212
|
+
if (params.format === "dot") {
|
|
213
|
+
const lines = ["digraph specs {"];
|
|
214
|
+
for (const edge of graph.edges)
|
|
215
|
+
lines.push(` "${edge.from}" -> "${edge.to}";`);
|
|
216
|
+
lines.push("}");
|
|
217
|
+
return lines.join("\n");
|
|
218
|
+
}
|
|
219
|
+
return JSON.stringify({
|
|
220
|
+
nodes: sorted,
|
|
221
|
+
edges: graph.edges,
|
|
222
|
+
downstream: Object.fromEntries(sorted.map((n) => [n, graph.getDownstream(n)]))
|
|
223
|
+
});
|
|
224
|
+
} catch (err) {
|
|
225
|
+
if (err instanceof GraphError) {
|
|
226
|
+
return JSON.stringify({ error: err.message });
|
|
227
|
+
}
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ../mcp/dist/server.js
|
|
233
|
+
function createMcpServer() {
|
|
234
|
+
const server = new McpServer({
|
|
235
|
+
name: "specdx",
|
|
236
|
+
version: "0.3.0"
|
|
237
|
+
});
|
|
238
|
+
server.tool("sdx_validate", "Validate the spec.config.yaml configuration file", { configPath: z.string().optional().describe("Path to config directory") }, async (params) => ({
|
|
239
|
+
content: [{ type: "text", text: await handleValidate(params) }]
|
|
240
|
+
}));
|
|
241
|
+
server.tool("sdx_lint", "Run lint rules against the spec suite", {
|
|
242
|
+
preset: z.string().optional().describe("Lint preset: minimal, recommended, strict"),
|
|
243
|
+
specPath: z.string().optional().describe("Lint a specific spec file")
|
|
244
|
+
}, async (params) => ({
|
|
245
|
+
content: [{ type: "text", text: await handleLint(params) }]
|
|
246
|
+
}));
|
|
247
|
+
server.tool("sdx_pack", "Pack spec context for LLM consumption within a token budget", {
|
|
248
|
+
task: z.string().optional().describe("Task description for relevance scoring"),
|
|
249
|
+
format: z.string().optional().describe("Output format: xml, markdown, json"),
|
|
250
|
+
budget: z.number().optional().describe("Token budget (default: 12000)")
|
|
251
|
+
}, async (params) => ({
|
|
252
|
+
content: [{ type: "text", text: await handlePack(params) }]
|
|
253
|
+
}));
|
|
254
|
+
server.tool("sdx_status", "Get spec suite health overview (lint health, staleness, integrity)", {}, async () => ({
|
|
255
|
+
content: [{ type: "text", text: await handleStatus() }]
|
|
256
|
+
}));
|
|
257
|
+
server.tool("sdx_check", "Run spec-to-implementation drift analysis", {
|
|
258
|
+
framework: z.string().optional().describe("Framework: express, hono, nextjs"),
|
|
259
|
+
specId: z.string().optional().describe("Check a specific spec by ID")
|
|
260
|
+
}, async (params) => ({
|
|
261
|
+
content: [{ type: "text", text: await handleCheck(params) }]
|
|
262
|
+
}));
|
|
263
|
+
server.tool("sdx_diff", "Show spec changes and downstream impact between git refs", {
|
|
264
|
+
base: z.string().optional().describe("Base git ref (default: main)"),
|
|
265
|
+
head: z.string().optional().describe("Head git ref (default: HEAD)")
|
|
266
|
+
}, async (params) => ({
|
|
267
|
+
content: [{ type: "text", text: await handleDiff(params) }]
|
|
268
|
+
}));
|
|
269
|
+
server.tool("sdx_graph", "Get the spec dependency graph", {
|
|
270
|
+
format: z.string().optional().describe("Output format: json (default) or dot")
|
|
271
|
+
}, async (params) => ({
|
|
272
|
+
content: [{ type: "text", text: await handleGraph(params) }]
|
|
273
|
+
}));
|
|
274
|
+
return server;
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
createMcpServer
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=dist-QXLX77XG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../mcp/src/server.ts","../../mcp/src/tools/validate.ts","../../mcp/src/tools/lint.ts","../../mcp/src/tools/pack.ts","../../mcp/src/tools/status.ts","../../mcp/src/tools/check.ts","../../mcp/src/tools/diff.ts","../../mcp/src/tools/graph.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { handleValidate } from \"./tools/validate.js\";\nimport { handleLint } from \"./tools/lint.js\";\nimport { handlePack } from \"./tools/pack.js\";\nimport { handleStatus } from \"./tools/status.js\";\nimport { handleCheck } from \"./tools/check.js\";\nimport { handleDiff } from \"./tools/diff.js\";\nimport { handleGraph } from \"./tools/graph.js\";\n\nexport function createMcpServer(): McpServer {\n const server = new McpServer({\n name: \"specdx\",\n version: \"0.3.0\",\n });\n\n server.tool(\n \"sdx_validate\",\n \"Validate the spec.config.yaml configuration file\",\n { configPath: z.string().optional().describe(\"Path to config directory\") },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handleValidate(params) }],\n }),\n );\n\n server.tool(\n \"sdx_lint\",\n \"Run lint rules against the spec suite\",\n {\n preset: z.string().optional().describe(\"Lint preset: minimal, recommended, strict\"),\n specPath: z.string().optional().describe(\"Lint a specific spec file\"),\n },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handleLint(params) }],\n }),\n );\n\n server.tool(\n \"sdx_pack\",\n \"Pack spec context for LLM consumption within a token budget\",\n {\n task: z.string().optional().describe(\"Task description for relevance scoring\"),\n format: z.string().optional().describe(\"Output format: xml, markdown, json\"),\n budget: z.number().optional().describe(\"Token budget (default: 12000)\"),\n },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handlePack(params) }],\n }),\n );\n\n server.tool(\n \"sdx_status\",\n \"Get spec suite health overview (lint health, staleness, integrity)\",\n {},\n async () => ({\n content: [{ type: \"text\" as const, text: await handleStatus() }],\n }),\n );\n\n server.tool(\n \"sdx_check\",\n \"Run spec-to-implementation drift analysis\",\n {\n framework: z.string().optional().describe(\"Framework: express, hono, nextjs\"),\n specId: z.string().optional().describe(\"Check a specific spec by ID\"),\n },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handleCheck(params) }],\n }),\n );\n\n server.tool(\n \"sdx_diff\",\n \"Show spec changes and downstream impact between git refs\",\n {\n base: z.string().optional().describe(\"Base git ref (default: main)\"),\n head: z.string().optional().describe(\"Head git ref (default: HEAD)\"),\n },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handleDiff(params) }],\n }),\n );\n\n server.tool(\n \"sdx_graph\",\n \"Get the spec dependency graph\",\n {\n format: z.string().optional().describe(\"Output format: json (default) or dot\"),\n },\n async (params) => ({\n content: [{ type: \"text\" as const, text: await handleGraph(params) }],\n }),\n );\n\n return server;\n}\n","import { loadConfig, ConfigError } from \"@specdx/core\";\n\nexport async function handleValidate(params: { configPath?: string }): Promise<string> {\n try {\n const configDir = params.configPath ?? process.cwd();\n const config = await loadConfig(undefined, configDir);\n return JSON.stringify({\n valid: true,\n specCount: Object.keys(config.specs).length,\n project: config.project?.name ?? \"unknown\",\n });\n } catch (err) {\n if (err instanceof ConfigError) {\n return JSON.stringify({ valid: false, error: err.message, details: err.errors });\n }\n throw err;\n }\n}\n","import { loadConfig, parseSpec, resolveGlob, buildGraph } from \"@specdx/core\";\nimport { createLintEngine, getPreset } from \"@specdx/lint\";\nimport type { ParsedSpec } from \"@specdx/core\";\n\nexport async function handleLint(params: { preset?: string; specPath?: string }): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n const preset = params.preset ?? config.lint?.extends ?? \"recommended\";\n const rules = getPreset(preset);\n\n const specs: ParsedSpec[] = [];\n for (const [, entry] of Object.entries(config.specs)) {\n const files = await resolveGlob(entry.path, configDir);\n for (const file of files) {\n if (params.specPath && !file.includes(params.specPath)) continue;\n specs.push(await parseSpec(file));\n }\n }\n\n let graph;\n try {\n graph = buildGraph(config);\n } catch {\n // non-fatal\n }\n\n const engine = createLintEngine({ rules, config, graph });\n const results = engine.lint(specs);\n\n return JSON.stringify({\n diagnostics: results.diagnostics,\n hasErrors: results.hasErrors,\n hasWarnings: results.hasWarnings,\n specsChecked: specs.length,\n });\n}\n","import { loadConfig, parseSpec, resolveGlob, buildGraph } from \"@specdx/core\";\nimport { pack } from \"@specdx/pack\";\nimport type { ParsedSpec } from \"@specdx/core\";\n\nexport async function handlePack(params: {\n task?: string;\n format?: string;\n budget?: number;\n}): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n\n const allSpecs: ParsedSpec[] = [];\n for (const [, entry] of Object.entries(config.specs)) {\n const files = await resolveGlob(entry.path, configDir);\n for (const file of files) {\n allSpecs.push(await parseSpec(file));\n }\n }\n\n let graph;\n try {\n graph = buildGraph(config);\n } catch {\n // non-fatal\n }\n\n const result = pack(\n allSpecs,\n {\n task: params.task,\n budget: params.budget,\n format: (params.format as \"xml\" | \"markdown\" | \"json\") ?? undefined,\n },\n config.pack,\n graph,\n );\n\n return result.output;\n}\n","import { loadConfig, parseSpec, resolveGlob, buildGraph } from \"@specdx/core\";\nimport { createLintEngine, getPreset } from \"@specdx/lint\";\nimport { DEFAULT_DIFF_CONFIG } from \"@specdx/diff\";\nimport type { ParsedSpec } from \"@specdx/core\";\n\nexport async function handleStatus(): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n\n const specs: { spec: ParsedSpec; entry: { path: string; owner?: string } }[] = [];\n for (const [, entry] of Object.entries(config.specs)) {\n const paths = await resolveGlob(entry.path, configDir);\n for (const p of paths) {\n const spec = await parseSpec(p);\n specs.push({ spec, entry: entry as { path: string; owner?: string } });\n }\n }\n\n const byStatus: Record<string, number> = {};\n for (const { spec } of specs) {\n const status = (spec.frontmatter.status as string) || \"unknown\";\n byStatus[status] = (byStatus[status] ?? 0) + 1;\n }\n\n const presetName = config.lint?.extends ?? \"recommended\";\n const rules = getPreset(presetName);\n\n let graph;\n let graphError: string | undefined;\n try {\n graph = buildGraph(config);\n } catch (err) {\n graphError = (err as Error).message;\n }\n\n const engine = createLintEngine({ rules, config, graph });\n const lintResults = engine.lint(specs.map((s) => s.spec));\n\n const errors = lintResults.diagnostics.filter((d) => d.severity === \"error\").length;\n const warnings = lintResults.diagnostics.filter((d) => d.severity === \"warn\").length;\n\n const thresholdDays =\n config.diff?.staleness_threshold_days ?? DEFAULT_DIFF_CONFIG.staleness_threshold_days;\n const now = Date.now();\n const staleSpecs: { specId: string; daysSinceUpdate: number; owner?: string }[] = [];\n for (const { spec, entry } of specs) {\n const dateStr =\n (spec.frontmatter.updated as string | undefined) ||\n (spec.frontmatter.created as string | undefined);\n if (dateStr) {\n const days = Math.floor((now - new Date(dateStr).getTime()) / (1000 * 60 * 60 * 24));\n if (days > thresholdDays) {\n staleSpecs.push({\n specId: spec.frontmatter.id as string,\n daysSinceUpdate: days,\n owner: entry.owner,\n });\n }\n }\n }\n\n let verdict: \"healthy\" | \"warnings\" | \"errors\" = \"healthy\";\n if (errors > 0 || graphError) verdict = \"errors\";\n else if (warnings > 0 || staleSpecs.length > 0) verdict = \"warnings\";\n\n return JSON.stringify({\n project: config.project?.name ?? \"unknown\",\n specCount: specs.length,\n byStatus,\n lintHealth: { errors, warnings, passing: specs.length - errors },\n staleSpecs,\n integrityIssues: graphError ? [graphError] : [],\n verdict,\n });\n}\n","import { loadConfig, parseSpec, resolveGlob } from \"@specdx/core\";\nimport { runCheck } from \"@specdx/check\";\nimport type { ParsedSpec } from \"@specdx/core\";\n\nexport async function handleCheck(params: {\n framework?: string;\n specId?: string;\n}): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n\n const specs: ParsedSpec[] = [];\n for (const [, entry] of Object.entries(config.specs)) {\n const paths = await resolveGlob(entry.path, configDir);\n for (const p of paths) {\n const spec = await parseSpec(p);\n if (params.specId && spec.frontmatter.id !== params.specId) continue;\n specs.push(spec);\n }\n }\n\n const checkConfig = {\n ...config.check,\n ...(params.framework\n ? { framework: params.framework as \"express\" | \"hono\" | \"nextjs\" }\n : {}),\n };\n\n const result = await runCheck(specs, configDir, checkConfig);\n return JSON.stringify(result);\n}\n","import { join } from \"node:path\";\nimport { loadConfig } from \"@specdx/core\";\nimport { diffBetweenRefs, DEFAULT_DIFF_CONFIG, DiffError } from \"@specdx/diff\";\n\nexport async function handleDiff(params: { base?: string; head?: string }): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n const baseRef = params.base ?? config.diff?.baseline_ref ?? DEFAULT_DIFF_CONFIG.baseline_ref;\n const headRef = params.head ?? \"HEAD\";\n const configPath = join(configDir, \"spec.config.yaml\");\n\n try {\n const result = await diffBetweenRefs(configPath, baseRef, headRef);\n return JSON.stringify(result);\n } catch (err) {\n if (err instanceof DiffError) {\n return JSON.stringify({ error: err.message });\n }\n throw err;\n }\n}\n","import { loadConfig, buildGraph, GraphError } from \"@specdx/core\";\n\nexport async function handleGraph(params: { format?: string }): Promise<string> {\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n\n try {\n const graph = buildGraph(config);\n const sorted = graph.topologicalSort();\n\n if (params.format === \"dot\") {\n const lines = [\"digraph specs {\"];\n for (const edge of graph.edges) lines.push(` \"${edge.from}\" -> \"${edge.to}\";`);\n lines.push(\"}\");\n return lines.join(\"\\n\");\n }\n\n return JSON.stringify({\n nodes: sorted,\n edges: graph.edges,\n downstream: Object.fromEntries(sorted.map((n) => [n, graph.getDownstream(n)])),\n });\n } catch (err) {\n if (err instanceof GraphError) {\n return JSON.stringify({ error: err.message });\n }\n throw err;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS;;;ACClB,eAAsB,eAAe,QAA+B;AAClE,MAAI;AACF,UAAM,YAAY,OAAO,cAAc,QAAQ,IAAG;AAClD,UAAM,SAAS,MAAM,WAAW,QAAW,SAAS;AACpD,WAAO,KAAK,UAAU;MACpB,OAAO;M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Q,EAAG,SAAS,8BAA8B;IACnE,MAAM,EAAE,OAAM,EAAG,SAAQ,EAAG,SAAS,8BAA8B;KAErE,OAAO,YAAY;IACjB,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,MAAM,WAAW,MAAM,EAAC,CAAE;IACnE;AAGJ,SAAO,KACL,aACA,iCACA;IACE,QAAQ,EAAE,OAAM,EAAG,SAAQ,EAAG,SAAS,sCAAsC;KAE/E,OAAO,YAAY;IACjB,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,MAAM,YAAY,MAAM,EAAC,CAAE;IACpE;AAGJ,SAAO;AACT;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -942,6 +942,230 @@ var singleProjectContextRule = {
|
|
|
942
942
|
}
|
|
943
943
|
};
|
|
944
944
|
|
|
945
|
+
// ../lint/dist/rules/terminology.js
|
|
946
|
+
function normalizeCompound(term) {
|
|
947
|
+
return term.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").toLowerCase().trim();
|
|
948
|
+
}
|
|
949
|
+
function extractCompoundTerms(content) {
|
|
950
|
+
const terms = [];
|
|
951
|
+
const camelCaseRegex = /\b[a-zA-Z]*[a-z][A-Z][a-zA-Z]*\b/g;
|
|
952
|
+
let match;
|
|
953
|
+
while ((match = camelCaseRegex.exec(content)) !== null) {
|
|
954
|
+
terms.push(match[0]);
|
|
955
|
+
}
|
|
956
|
+
const hyphenatedRegex = /\b[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)+\b/g;
|
|
957
|
+
while ((match = hyphenatedRegex.exec(content)) !== null) {
|
|
958
|
+
terms.push(match[0]);
|
|
959
|
+
}
|
|
960
|
+
return terms;
|
|
961
|
+
}
|
|
962
|
+
var terminologyRule = {
|
|
963
|
+
id: "consistency/terminology",
|
|
964
|
+
description: "Detects terminology drift (e.g., user-profile vs UserProfile vs user profile) across specs",
|
|
965
|
+
severity: "warn",
|
|
966
|
+
run(context) {
|
|
967
|
+
if (context.spec !== context.allSpecs[0])
|
|
968
|
+
return [];
|
|
969
|
+
const termMap = /* @__PURE__ */ new Map();
|
|
970
|
+
for (const spec of context.allSpecs) {
|
|
971
|
+
if (!spec.content)
|
|
972
|
+
continue;
|
|
973
|
+
const terms = extractCompoundTerms(spec.content);
|
|
974
|
+
for (const term of terms) {
|
|
975
|
+
const normalized = normalizeCompound(term);
|
|
976
|
+
if (!normalized.includes(" "))
|
|
977
|
+
continue;
|
|
978
|
+
if (!termMap.has(normalized)) {
|
|
979
|
+
termMap.set(normalized, /* @__PURE__ */ new Set());
|
|
980
|
+
}
|
|
981
|
+
termMap.get(normalized).add(term);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
const diagnostics = [];
|
|
985
|
+
for (const [normalized, variants] of termMap) {
|
|
986
|
+
if (variants.size >= 2) {
|
|
987
|
+
const variantList = [...variants].join(", ");
|
|
988
|
+
diagnostics.push({
|
|
989
|
+
ruleId: "consistency/terminology",
|
|
990
|
+
severity: "warn",
|
|
991
|
+
message: `Inconsistent terminology for "${normalized}": found variants [${variantList}]. Standardize terminology across specs.`,
|
|
992
|
+
filePath: context.spec.filePath
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return diagnostics;
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
// ../lint/dist/rules/edge-case-coverage.js
|
|
1001
|
+
var EDGE_CASE_KEYWORDS = [
|
|
1002
|
+
"error",
|
|
1003
|
+
"invalid",
|
|
1004
|
+
"empty",
|
|
1005
|
+
"timeout",
|
|
1006
|
+
"fails",
|
|
1007
|
+
"failure",
|
|
1008
|
+
"boundary",
|
|
1009
|
+
"edge case",
|
|
1010
|
+
"null",
|
|
1011
|
+
"undefined",
|
|
1012
|
+
"reject",
|
|
1013
|
+
"unauthorized",
|
|
1014
|
+
"forbidden",
|
|
1015
|
+
"404",
|
|
1016
|
+
"500",
|
|
1017
|
+
"missing",
|
|
1018
|
+
"malformed",
|
|
1019
|
+
"overflow",
|
|
1020
|
+
"duplicate"
|
|
1021
|
+
];
|
|
1022
|
+
var edgeCaseCoverageRule = {
|
|
1023
|
+
id: "completeness/edge-case-coverage",
|
|
1024
|
+
description: "Flag user stories or test plans that don't mention error states or edge cases",
|
|
1025
|
+
severity: "warn",
|
|
1026
|
+
run(context) {
|
|
1027
|
+
const type = context.spec.frontmatter.type;
|
|
1028
|
+
if (type !== "user-story" && type !== "test-plan")
|
|
1029
|
+
return [];
|
|
1030
|
+
const content = context.spec.content.toLowerCase();
|
|
1031
|
+
const hasEdgeCases = EDGE_CASE_KEYWORDS.some((kw) => content.includes(kw));
|
|
1032
|
+
if (hasEdgeCases)
|
|
1033
|
+
return [];
|
|
1034
|
+
return [
|
|
1035
|
+
{
|
|
1036
|
+
ruleId: "completeness/edge-case-coverage",
|
|
1037
|
+
severity: "warn",
|
|
1038
|
+
message: "No error states or edge cases mentioned. Consider adding error handling, boundary conditions, or failure mode scenarios.",
|
|
1039
|
+
filePath: context.spec.filePath
|
|
1040
|
+
}
|
|
1041
|
+
];
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
// ../lint/dist/rules/naming-conventions.js
|
|
1046
|
+
var namingConventionsRule = {
|
|
1047
|
+
id: "consistency/naming-conventions",
|
|
1048
|
+
description: "Enforce consistent naming conventions across specs",
|
|
1049
|
+
severity: "warn",
|
|
1050
|
+
run(context) {
|
|
1051
|
+
const { spec } = context;
|
|
1052
|
+
const type = spec.frontmatter.type;
|
|
1053
|
+
const diagnostics = [];
|
|
1054
|
+
if (type === "prd") {
|
|
1055
|
+
const sectionParts = spec.content.split(/^(?=## )/m);
|
|
1056
|
+
const featuresSection = sectionParts.find((p) => /^## Features\b/.test(p));
|
|
1057
|
+
if (featuresSection) {
|
|
1058
|
+
const bullets = featuresSection.match(/^- .+$/gm) ?? [];
|
|
1059
|
+
for (const bullet of bullets) {
|
|
1060
|
+
if (bullet.match(/^- \*\*F\d+\*\*:/) === null && bullet.trim().length > 2) {
|
|
1061
|
+
diagnostics.push({
|
|
1062
|
+
ruleId: "consistency/naming-conventions",
|
|
1063
|
+
severity: "warn",
|
|
1064
|
+
message: `PRD feature missing feature ID pattern (**F<N>**:): "${bullet.slice(0, 60)}"`,
|
|
1065
|
+
filePath: spec.filePath
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (type === "user-story") {
|
|
1072
|
+
const id = spec.frontmatter.id;
|
|
1073
|
+
if (!id.startsWith("story-")) {
|
|
1074
|
+
diagnostics.push({
|
|
1075
|
+
ruleId: "consistency/naming-conventions",
|
|
1076
|
+
severity: "warn",
|
|
1077
|
+
message: `User story ID "${id}" should start with "story-" (e.g., "story-${id}")`,
|
|
1078
|
+
filePath: spec.filePath
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (type === "api-contract") {
|
|
1083
|
+
const endpointRe = /^###\s+(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/gm;
|
|
1084
|
+
let match;
|
|
1085
|
+
while ((match = endpointRe.exec(spec.content)) !== null) {
|
|
1086
|
+
const path = match[2];
|
|
1087
|
+
if (/\/[a-z]+[A-Z]/.test(path)) {
|
|
1088
|
+
diagnostics.push({
|
|
1089
|
+
ruleId: "consistency/naming-conventions",
|
|
1090
|
+
severity: "warn",
|
|
1091
|
+
message: `Endpoint path "${path}" uses camelCase \u2014 use kebab-case instead (e.g., "${path.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}")`,
|
|
1092
|
+
filePath: spec.filePath
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
return diagnostics;
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
// ../lint/dist/rules/threat-coverage.js
|
|
1102
|
+
var STOPWORDS = /* @__PURE__ */ new Set(["the", "and", "for", "with", "from", "that", "this", "into", "via"]);
|
|
1103
|
+
function extractThreats(content) {
|
|
1104
|
+
const parts = content.split(/^(?=## )/m);
|
|
1105
|
+
const threats = [];
|
|
1106
|
+
for (const part of parts) {
|
|
1107
|
+
if (!/^##\s+(Threats|Security)\b/i.test(part))
|
|
1108
|
+
continue;
|
|
1109
|
+
const bullets = part.match(/^- .+$/gm) ?? [];
|
|
1110
|
+
threats.push(...bullets.map((b) => b.slice(2).trim()));
|
|
1111
|
+
}
|
|
1112
|
+
return threats;
|
|
1113
|
+
}
|
|
1114
|
+
function extractKeyTerms(text) {
|
|
1115
|
+
return text.toLowerCase().split(/\W+/).filter((w) => w.length > 3).filter((w) => !STOPWORDS.has(w));
|
|
1116
|
+
}
|
|
1117
|
+
var threatCoverageRule = {
|
|
1118
|
+
id: "security/threat-coverage",
|
|
1119
|
+
description: "Technical design specs must address threats identified in other specs",
|
|
1120
|
+
severity: "warn",
|
|
1121
|
+
run(context) {
|
|
1122
|
+
if (context.spec.frontmatter.type !== "technical-design")
|
|
1123
|
+
return [];
|
|
1124
|
+
const allThreats = [];
|
|
1125
|
+
for (const spec of context.allSpecs) {
|
|
1126
|
+
if (spec.filePath === context.spec.filePath)
|
|
1127
|
+
continue;
|
|
1128
|
+
allThreats.push(...extractThreats(spec.content));
|
|
1129
|
+
}
|
|
1130
|
+
if (allThreats.length === 0)
|
|
1131
|
+
return [];
|
|
1132
|
+
const techContent = context.spec.content.toLowerCase();
|
|
1133
|
+
const diagnostics = [];
|
|
1134
|
+
for (const threat of allThreats) {
|
|
1135
|
+
const keyTerms = extractKeyTerms(threat);
|
|
1136
|
+
const covered = keyTerms.some((term) => techContent.includes(term));
|
|
1137
|
+
if (!covered) {
|
|
1138
|
+
diagnostics.push({
|
|
1139
|
+
ruleId: "security/threat-coverage",
|
|
1140
|
+
severity: "warn",
|
|
1141
|
+
message: `Threat not addressed in technical design: "${threat}". Ensure the design covers this threat.`,
|
|
1142
|
+
filePath: context.spec.filePath
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return diagnostics;
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
// ../lint/dist/rules/ambiguity-score-ai.js
|
|
1151
|
+
var ambiguityScoreAiRule = {
|
|
1152
|
+
id: "clarity/ambiguity-score-ai",
|
|
1153
|
+
description: "AI-powered ambiguity detection (requires ANTHROPIC_API_KEY)",
|
|
1154
|
+
severity: "info",
|
|
1155
|
+
run(context) {
|
|
1156
|
+
if (!process.env["ANTHROPIC_API_KEY"])
|
|
1157
|
+
return [];
|
|
1158
|
+
return [
|
|
1159
|
+
{
|
|
1160
|
+
ruleId: "clarity/ambiguity-score-ai",
|
|
1161
|
+
severity: "info",
|
|
1162
|
+
message: "AI ambiguity analysis available \u2014 run `sdx check --ai` for LLM-powered ambiguity detection",
|
|
1163
|
+
filePath: context.spec.filePath
|
|
1164
|
+
}
|
|
1165
|
+
];
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
945
1169
|
// ../lint/dist/rules/index.js
|
|
946
1170
|
var structureRules = [
|
|
947
1171
|
validFrontmatterRule,
|
|
@@ -953,7 +1177,12 @@ var structureRules = [
|
|
|
953
1177
|
var contentRules = [
|
|
954
1178
|
storyCoverageRule,
|
|
955
1179
|
stalenessCheckRule,
|
|
956
|
-
noVagueLanguageRule
|
|
1180
|
+
noVagueLanguageRule,
|
|
1181
|
+
terminologyRule,
|
|
1182
|
+
edgeCaseCoverageRule,
|
|
1183
|
+
namingConventionsRule,
|
|
1184
|
+
threatCoverageRule,
|
|
1185
|
+
ambiguityScoreAiRule
|
|
957
1186
|
];
|
|
958
1187
|
var allBuiltinRules = [...structureRules, ...contentRules];
|
|
959
1188
|
|
|
@@ -1077,7 +1306,7 @@ var lint_default = defineCommand2({
|
|
|
1077
1306
|
import { defineCommand as defineCommand3 } from "citty";
|
|
1078
1307
|
|
|
1079
1308
|
// ../pack/dist/resolver.js
|
|
1080
|
-
var
|
|
1309
|
+
var STOPWORDS2 = /* @__PURE__ */ new Set([
|
|
1081
1310
|
"a",
|
|
1082
1311
|
"an",
|
|
1083
1312
|
"and",
|
|
@@ -1154,7 +1383,7 @@ var STOPWORDS = /* @__PURE__ */ new Set([
|
|
|
1154
1383
|
"your"
|
|
1155
1384
|
]);
|
|
1156
1385
|
function tokenize(task) {
|
|
1157
|
-
return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !
|
|
1386
|
+
return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !STOPWORDS2.has(t));
|
|
1158
1387
|
}
|
|
1159
1388
|
var WEIGHT_TAGS = 3;
|
|
1160
1389
|
var WEIGHT_TITLE = 3;
|