specdx 0.4.0-alpha.9 → 0.4.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/.claude-plugin/plugin.json +7 -2
- package/README.md +259 -0
- package/dist/{check-4FSSC6HN.js → check-PHXXA7VY.js} +68 -30
- package/dist/check-PHXXA7VY.js.map +1 -0
- package/dist/chunk-2BZIG7OE.js +185 -0
- package/dist/chunk-2BZIG7OE.js.map +1 -0
- package/dist/{chunk-N77RNV7J.js → chunk-3YXRWQGX.js} +217 -42
- package/dist/chunk-3YXRWQGX.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-DMGABJ6T.js +41 -0
- package/dist/chunk-DMGABJ6T.js.map +1 -0
- package/dist/{chunk-7JXW2GTJ.js → chunk-HCJDCS26.js} +9 -2
- package/dist/chunk-HCJDCS26.js.map +1 -0
- package/dist/chunk-LJTLNXGV.js +835 -0
- package/dist/chunk-LJTLNXGV.js.map +1 -0
- package/dist/chunk-NAWYG4VV.js +2846 -0
- package/dist/chunk-NAWYG4VV.js.map +1 -0
- package/dist/chunk-NHD44ZYN.js +20 -0
- package/dist/chunk-NHD44ZYN.js.map +1 -0
- package/dist/chunk-OVIKIIR4.js +103 -0
- package/dist/chunk-OVIKIIR4.js.map +1 -0
- package/dist/{chunk-IHTYAW7C.js → chunk-SNQNQ2MP.js} +111 -7
- package/dist/chunk-SNQNQ2MP.js.map +1 -0
- package/dist/{chunk-AKNPCB37.js → chunk-YRQPY5NF.js} +32 -12
- package/dist/chunk-YRQPY5NF.js.map +1 -0
- package/dist/diff-6C5LJ7SH.js +200 -0
- package/dist/diff-6C5LJ7SH.js.map +1 -0
- package/dist/{dist-4DIRTBJH.js → dist-PK52GA7M.js} +43 -20
- package/dist/dist-PK52GA7M.js.map +1 -0
- package/dist/{dist-RL2DT3ZE.js → dist-ROHCFKYT.js} +3 -2
- package/dist/dist-ROHCFKYT.js.map +1 -0
- package/dist/generate-K72WD455.js +21 -0
- package/dist/generate-K72WD455.js.map +1 -0
- package/dist/{generate-story-EFHGINHA.js → generate-story-NUCNYL3I.js} +43 -19
- package/dist/generate-story-NUCNYL3I.js.map +1 -0
- package/dist/{generate-test-plan-BO7444RG.js → generate-test-plan-Z46W3N3B.js} +61 -11
- package/dist/generate-test-plan-Z46W3N3B.js.map +1 -0
- package/dist/{graph-5XINV7PT.js → graph-4RNURBNP.js} +49 -11
- package/dist/graph-4RNURBNP.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +2660 -371
- package/dist/index.js.map +1 -1
- package/dist/{lint-PTMWMLDQ.js → lint-2VZPNLE3.js} +46 -18
- package/dist/lint-2VZPNLE3.js.map +1 -0
- package/dist/main.js +10 -229
- package/dist/main.js.map +1 -1
- package/dist/mcp-E6PJWBDQ.js +35 -0
- package/dist/mcp-E6PJWBDQ.js.map +1 -0
- package/dist/{migrate-4KF6GHLO.js → migrate-FKFC7UAO.js} +21 -9
- package/dist/migrate-FKFC7UAO.js.map +1 -0
- package/dist/{pack-DSOODXAN.js → pack-DE4UBTCC.js} +41 -13
- package/dist/pack-DE4UBTCC.js.map +1 -0
- package/dist/{ready-6DNKIHP6.js → ready-K74SLQ24.js} +55 -14
- package/dist/ready-K74SLQ24.js.map +1 -0
- package/dist/skills/{specdx-author-spec.md → core/specdx-author-spec/SKILL.md} +10 -6
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-01-frontmatter.md +1 -1
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-02-sections.md +41 -0
- package/dist/skills/{specdx-onboard.md → core/specdx-onboard/SKILL.md} +8 -3
- package/dist/skills/{specdx-plan-from-spec.md → core/specdx-plan-from-spec/SKILL.md} +5 -1
- package/dist/skills/{specdx-pre-commit.md → core/specdx-pre-commit/SKILL.md} +16 -2
- package/dist/skills/{specdx-review-spec.md → core/specdx-review-spec/SKILL.md} +5 -1
- package/dist/skills/core/specdx-router/SKILL.md +67 -0
- package/dist/skills/{specdx-sprint-review.md → core/specdx-sprint-review/SKILL.md} +6 -2
- package/dist/skills/{specdx-start-task.md → core/specdx-start-task/SKILL.md} +5 -1
- package/dist/skills/{specdx-check-drift.md → experimental/specdx-check-drift/SKILL.md} +10 -4
- package/dist/skills/{specdx-verify.md → experimental/specdx-verify/SKILL.md} +6 -2
- package/dist/skills-36SRUEMR.js +121 -0
- package/dist/skills-36SRUEMR.js.map +1 -0
- package/dist/{status-WZK247CI.js → status-IAE3BB77.js} +63 -32
- package/dist/status-IAE3BB77.js.map +1 -0
- package/dist/{update-JTNSYX3B.js → update-UFOHZEAK.js} +22 -12
- package/dist/update-UFOHZEAK.js.map +1 -0
- package/dist/{validate-LBDYWUDX.js → validate-EZHUB5TW.js} +36 -17
- package/dist/validate-EZHUB5TW.js.map +1 -0
- package/hooks/hooks.json +12 -6
- package/hooks/session-start +35 -3
- package/package.json +28 -13
- package/dist/changelog-XUVHY3QK.js +0 -93
- package/dist/changelog-XUVHY3QK.js.map +0 -1
- package/dist/check-4FSSC6HN.js.map +0 -1
- package/dist/chunk-7JXW2GTJ.js.map +0 -1
- package/dist/chunk-AKNPCB37.js.map +0 -1
- package/dist/chunk-DAZCOUVK.js +0 -496
- package/dist/chunk-DAZCOUVK.js.map +0 -1
- package/dist/chunk-GAM4MXPC.js +0 -15
- package/dist/chunk-GAM4MXPC.js.map +0 -1
- package/dist/chunk-IHTYAW7C.js.map +0 -1
- package/dist/chunk-N77RNV7J.js.map +0 -1
- package/dist/chunk-SRZ33RJP.js +0 -1147
- package/dist/chunk-SRZ33RJP.js.map +0 -1
- package/dist/diff-OXZ34NU4.js +0 -107
- package/dist/diff-OXZ34NU4.js.map +0 -1
- package/dist/dist-4DIRTBJH.js.map +0 -1
- package/dist/explain-QBV3AESQ.js +0 -109
- package/dist/explain-QBV3AESQ.js.map +0 -1
- package/dist/generate-7GNPT2WJ.js +0 -13
- package/dist/generate-7GNPT2WJ.js.map +0 -1
- package/dist/generate-story-EFHGINHA.js.map +0 -1
- package/dist/generate-test-plan-BO7444RG.js.map +0 -1
- package/dist/graph-5XINV7PT.js.map +0 -1
- package/dist/lint-PTMWMLDQ.js.map +0 -1
- package/dist/mcp-BGFAPM6G.js +0 -17
- package/dist/mcp-BGFAPM6G.js.map +0 -1
- package/dist/migrate-4KF6GHLO.js.map +0 -1
- package/dist/pack-DSOODXAN.js.map +0 -1
- package/dist/ready-6DNKIHP6.js.map +0 -1
- package/dist/skills-3GBBWZW2.js +0 -93
- package/dist/skills-3GBBWZW2.js.map +0 -1
- package/dist/status-WZK247CI.js.map +0 -1
- package/dist/update-JTNSYX3B.js.map +0 -1
- package/dist/validate-LBDYWUDX.js.map +0 -1
- /package/dist/{dist-RL2DT3ZE.js.map → chunk-5WRI5ZAA.js.map} +0 -0
- /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
- /package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-03-finalize.md +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/core/init.ts","../src/commands/registry.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join, basename, resolve } from \"node:path\";\nimport { REQUIRED_SECTIONS } from \"@specdx/schema\";\n\nexport type Template = \"lightweight\" | \"bmad\" | \"api-first\" | \"quick\" | \"context\";\n\nexport interface ScaffoldOptions {\n projectName: string;\n template: Template;\n targetDir: string;\n}\n\nconst TEMPLATE_SPECS: Record<\n Template,\n Array<{ filename: string; type: keyof typeof REQUIRED_SECTIONS }>\n> = {\n lightweight: [\n { filename: \"prd.md\", type: \"prd\" },\n { filename: \"technical-design.md\", type: \"technical-design\" },\n ],\n bmad: [\n { filename: \"prd.md\", type: \"prd\" },\n { filename: \"technical-design.md\", type: \"technical-design\" },\n { filename: \"test-plan.md\", type: \"test-plan\" },\n ],\n \"api-first\": [\n { filename: \"technical-design.md\", type: \"technical-design\" },\n { filename: \"api-contract.md\", type: \"api-contract\" },\n { filename: \"test-plan.md\", type: \"test-plan\" },\n ],\n quick: [{ filename: \"quick-spec.md\", type: \"quick-spec\" }],\n context: [{ filename: \"project-context.md\", type: \"project-context\" }],\n};\n\nconst TEMPLATE_EXTRA_DIRS: Record<Template, string[]> = {\n lightweight: [],\n bmad: [\"specs/stories\", \"specs/adr\"],\n \"api-first\": [],\n quick: [],\n context: [],\n};\n\nfunction specIdFromFilename(filename: string): string {\n return filename.replace(/\\.md$/, \"\");\n}\n\nfunction specTitleFromType(type: string): string {\n return type\n .split(\"-\")\n .map((w) => w.charAt(0).toUpperCase() + w.slice(1))\n .join(\" \");\n}\n\nfunction buildSpecFile(\n filename: string,\n type: keyof typeof REQUIRED_SECTIONS,\n projectName: string,\n today: string,\n): string {\n const id = specIdFromFilename(filename);\n const title = `${specTitleFromType(type)} — ${projectName}`;\n const sections = REQUIRED_SECTIONS[type];\n\n const frontmatter = [\n \"---\",\n `id: ${id}`,\n `type: ${type}`,\n `title: \"${title}\"`,\n `status: draft`,\n `version: \"0.1\"`,\n `created: \"${today}\"`,\n `authors: [\"author\"]`,\n \"---\",\n ].join(\"\\n\");\n\n const body = sections.map((section) => `\\n## ${section}\\n\\n<!-- placeholder -->`).join(\"\\n\");\n\n return `${frontmatter}\\n${body}\\n`;\n}\n\nfunction buildConfigYaml(\n projectName: string,\n specs: Array<{ filename: string; type: string }>,\n): string {\n const specEntries = specs\n .map(({ filename, type }) => {\n const key = specIdFromFilename(filename);\n return ` ${key}:\\n path: specs/${filename}\\n type: ${type}`;\n })\n .join(\"\\n\");\n\n return (\n [`version: \"1.0\"`, `project:`, ` name: \"${projectName}\"`, `specs:`, specEntries].join(\"\\n\") +\n \"\\n\"\n );\n}\n\nexport async function scaffoldProject({\n projectName,\n template,\n targetDir,\n}: ScaffoldOptions): Promise<void> {\n if (!targetDir) {\n throw new TypeError(\"scaffoldProject requires `targetDir` — where to create the project.\");\n }\n const today = new Date().toISOString().slice(0, 10);\n const specsDir = join(targetDir, \"specs\");\n\n // Create specs/ directory\n await mkdir(specsDir, { recursive: true });\n\n // Create extra template dirs (e.g., bmad needs stories/ and adr/)\n for (const extraDir of TEMPLATE_EXTRA_DIRS[template]) {\n await mkdir(join(targetDir, extraDir), { recursive: true });\n }\n\n const specs = TEMPLATE_SPECS[template];\n\n // Write spec files\n for (const { filename, type } of specs) {\n const content = buildSpecFile(filename, type, projectName, today);\n await writeFile(join(specsDir, filename), content, \"utf-8\");\n }\n\n // Write spec.config.yaml\n const configContent = buildConfigYaml(projectName, specs);\n await writeFile(join(targetDir, \"spec.config.yaml\"), configContent, \"utf-8\");\n}\n\n/**\n * The project name to use when `--name` is absent: the target directory's own\n * name, resolved so that `.` becomes the current directory rather than a dot.\n */\nexport function defaultProjectName(dir: string): string {\n return basename(resolve(dir)) || \"my-project\";\n}\n\n/**\n * The templates `init` accepts. The `--template` help text is derived from this\n * list rather than restated, so the two cannot disagree — the help advertised\n * three while the validator accepted five.\n */\nconst VALID_TEMPLATES: Template[] = [\"lightweight\", \"bmad\", \"api-first\", \"quick\", \"context\"];\n\nexport default defineCommand({\n meta: {\n name: \"init\",\n description: \"Initialize a new specdx project with spec scaffolding\",\n },\n args: {\n name: {\n type: \"string\",\n description: \"Project name (default: the target directory's name)\",\n },\n template: {\n type: \"string\",\n description: `Template to use (${VALID_TEMPLATES.join(\", \")})`,\n default: \"lightweight\",\n },\n dir: {\n type: \"string\",\n description: \"Target directory\",\n default: \".\",\n },\n },\n async run({ args }) {\n const { template, dir } = args;\n if (!VALID_TEMPLATES.includes(template as Template)) {\n console.error(`Unknown template: ${template}. Choose from: ${VALID_TEMPLATES.join(\", \")}`);\n process.exit(1);\n }\n\n // The first command anyone runs should not fail on a missing flag when the\n // answer is sitting in the path. `--name` still wins where they differ.\n const name = args.name || defaultProjectName(dir);\n\n console.log(`Scaffolding \"${name}\" with template \"${template}\" in ${dir}...`);\n await scaffoldProject({ projectName: name, template: template as Template, targetDir: dir });\n console.log(`Done! Project \"${name}\" scaffolded successfully.`);\n },\n});\n","import type { ArgsDef, CommandDef, SubCommandsDef } from \"citty\";\nimport initCommand from \"./core/init.js\";\n\n/**\n * Promoted commands — the set `--help` presents without a caveat.\n *\n * Promotion is the directory a command lives in, not an adjective someone\n * remembered to type into its description. `explain` and `changelog` both\n * drifted into the core surface precisely because the marker was a string.\n * Sub-commands are spelled the way a user types them.\n */\nexport const CORE_COMMANDS = [\n \"init\",\n \"lint\",\n \"validate\",\n \"graph\",\n \"skills\",\n \"pack\",\n \"diff\",\n \"status\",\n \"ready\",\n \"generate\",\n \"generate story\",\n \"mcp\",\n] as const;\n\n/** Commands whose output is not yet trusted enough to promote. */\nexport const EXPERIMENTAL_COMMANDS = [\"check\", \"update\", \"migrate\", \"generate test-plan\"] as const;\n\n/** Every command that ships, promoted or not. */\nexport const COMMAND_NAMES = [...CORE_COMMANDS, ...EXPERIMENTAL_COMMANDS];\n\nexport type CommandName = (typeof COMMAND_NAMES)[number];\n\n/** Bucket directory a command lives in, under `commands/`. */\nexport function bucketOf(name: string): \"core\" | \"experimental\" {\n return (EXPERIMENTAL_COMMANDS as readonly string[]).includes(name) ? \"experimental\" : \"core\";\n}\n\n/** Module path for a command, relative to `commands/`. */\nexport function moduleOf(name: string): string {\n return `${bucketOf(name)}/${name.replace(/ /g, \"-\")}.ts`;\n}\n\n/**\n * Prefix an experimental command's description with its caveat.\n *\n * Derived from the bucket, so no description in the tree spells `[experimental]`\n * itself and the two can never disagree.\n */\nexport function labelled<T extends ArgsDef>(name: string, cmd: CommandDef<T>): CommandDef<T> {\n if (bucketOf(name) === \"core\") return cmd;\n const meta = cmd.meta;\n // citty allows meta to be a function or promise. Ours are all plain objects,\n // and the conformance test asserts every experimental command renders the\n // caveat -- so a command that adopts lazy meta fails loudly rather than\n // shipping unlabelled.\n if (typeof meta !== \"object\" || meta === null || \"then\" in meta) return cmd;\n return {\n ...cmd,\n meta: { ...meta, description: `[experimental] ${meta.description ?? \"\"}`.trim() },\n };\n}\n\n/** Lazily load a command module and label it according to its bucket. */\nfunction bucketed<T extends ArgsDef>(\n name: string,\n load: () => Promise<CommandDef<T>>,\n): () => Promise<CommandDef<T>> {\n return () => load().then((cmd) => labelled(name, cmd));\n}\n\n/**\n * The `subCommands` map citty registers, keyed by the top-level names above.\n *\n * Typed as citty's own `SubCommandsDef` rather than a `Record<CommandName, ...>`:\n * `CommandDef` is invariant in its args, so a narrower annotation rejects every\n * command that declares args. The conformance test asserts the keys instead.\n */\nexport const subCommands: SubCommandsDef = {\n init: initCommand,\n lint: bucketed(\"lint\", () => import(\"./core/lint.js\").then((m) => m.default)),\n validate: bucketed(\"validate\", () => import(\"./core/validate.js\").then((m) => m.default)),\n graph: bucketed(\"graph\", () => import(\"./core/graph.js\").then((m) => m.default)),\n skills: bucketed(\"skills\", () => import(\"./core/skills.js\").then((m) => m.default)),\n pack: bucketed(\"pack\", () => import(\"./core/pack.js\").then((m) => m.default)),\n diff: bucketed(\"diff\", () => import(\"./core/diff.js\").then((m) => m.default)),\n status: bucketed(\"status\", () => import(\"./core/status.js\").then((m) => m.default)),\n check: bucketed(\"check\", () => import(\"./experimental/check.js\").then((m) => m.default)),\n ready: bucketed(\"ready\", () => import(\"./core/ready.js\").then((m) => m.default)),\n update: bucketed(\"update\", () => import(\"./experimental/update.js\").then((m) => m.default)),\n generate: bucketed(\"generate\", () => import(\"./core/generate.js\").then((m) => m.default)),\n migrate: bucketed(\"migrate\", () => import(\"./experimental/migrate.js\").then((m) => m.default)),\n mcp: bucketed(\"mcp\", () => import(\"./core/mcp.js\").then((m) => m.default)),\n};\n"],"mappings":";;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,OAAO,iBAAiB;AACjC,SAAS,MAAM,UAAU,eAAe;AAWxC,IAAM,iBAGF;AAAA,EACF,aAAa;AAAA,IACX,EAAE,UAAU,UAAU,MAAM,MAAM;AAAA,IAClC,EAAE,UAAU,uBAAuB,MAAM,mBAAmB;AAAA,EAC9D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AAAA,EACvF,OAAO,SAAS,SAAS,MAAM,OAAO,qBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;AAAA,EAC/E,QAAQ,SAAS,UAAU,MAAM,OAAO,sBAA0B,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;AAAA,EAC1F,UAAU,SAAS,YAAY,MAAM,OAAO,wBAAoB,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;AAAA,EACxF,SAAS,SAAS,WAAW,MAAM,OAAO,uBAA2B,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;AAAA,EAC7F,KAAK,SAAS,OAAO,MAAM,OAAO,mBAAe,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;AAC3E;","names":[]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// ../check/dist/check.js
|
|
2
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
3
|
+
import { join as join10 } from "path";
|
|
4
|
+
|
|
1
5
|
// ../check/dist/spec-parsers.js
|
|
2
6
|
function extractSection(content, heading) {
|
|
3
7
|
const headingPattern = new RegExp(`^##\\s+${escapeRegex(heading)}\\s*$`, "im");
|
|
@@ -13,34 +17,55 @@ function escapeRegex(str) {
|
|
|
13
17
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
18
|
}
|
|
15
19
|
var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
20
|
+
function pathParams(path) {
|
|
21
|
+
return (path.match(/:([A-Za-z_][A-Za-z0-9_]*)/g) ?? []).map((p) => p.slice(1));
|
|
22
|
+
}
|
|
23
|
+
function hasEndpointsSection(content) {
|
|
24
|
+
return extractSection(content, "Endpoints") !== null;
|
|
25
|
+
}
|
|
16
26
|
function parseEndpoints(content) {
|
|
17
27
|
const section = extractSection(content, "Endpoints");
|
|
18
28
|
if (!section)
|
|
19
29
|
return [];
|
|
20
30
|
const results = [];
|
|
31
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32
|
+
const push = (rawMethod, path, description) => {
|
|
33
|
+
const method = rawMethod.toUpperCase();
|
|
34
|
+
if (!HTTP_METHODS.has(method))
|
|
35
|
+
return;
|
|
36
|
+
const key = `${method} ${path}`;
|
|
37
|
+
if (seen.has(key))
|
|
38
|
+
return;
|
|
39
|
+
seen.add(key);
|
|
40
|
+
results.push({
|
|
41
|
+
method,
|
|
42
|
+
path,
|
|
43
|
+
params: pathParams(path),
|
|
44
|
+
description: description && description.length > 0 ? description : void 0
|
|
45
|
+
});
|
|
46
|
+
};
|
|
21
47
|
const headingPattern = /^###\s+(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/im;
|
|
22
|
-
const
|
|
23
|
-
for (const block of blocks) {
|
|
48
|
+
for (const block of section.split(/^(?=###\s)/m)) {
|
|
24
49
|
const headingMatch = headingPattern.exec(block);
|
|
25
50
|
if (!headingMatch)
|
|
26
51
|
continue;
|
|
27
|
-
const rawMethod = headingMatch[1].toUpperCase();
|
|
28
|
-
if (!HTTP_METHODS.has(rawMethod))
|
|
29
|
-
continue;
|
|
30
|
-
const method = rawMethod;
|
|
31
|
-
const path = headingMatch[2];
|
|
32
|
-
const params = (path.match(/:([A-Za-z_][A-Za-z0-9_]*)/g) ?? []).map((p) => p.slice(1));
|
|
33
52
|
const afterHeading = block.slice(headingMatch.index + headingMatch[0].length);
|
|
34
53
|
const descriptionLine = afterHeading.split("\n").map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith("#") && !l.startsWith("-"));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
push(headingMatch[1], headingMatch[2], descriptionLine);
|
|
55
|
+
}
|
|
56
|
+
const bulletPattern = new RegExp(
|
|
57
|
+
"^\\s*[-*+]\\s+[`*_]*\\s*(GET|POST|PUT|PATCH|DELETE)[`*_]*\\s+[`*_]*(/[^\\s`*_]*)[`*_]*\\s*(?:[\u2014\u2013:-]\\s*(.*))?$",
|
|
58
|
+
// optional description
|
|
59
|
+
"gim"
|
|
60
|
+
);
|
|
61
|
+
let bulletMatch;
|
|
62
|
+
while ((bulletMatch = bulletPattern.exec(section)) !== null) {
|
|
63
|
+
push(bulletMatch[1], bulletMatch[2], bulletMatch[3]?.trim());
|
|
41
64
|
}
|
|
42
65
|
return results;
|
|
43
66
|
}
|
|
67
|
+
var TYPE_SHAPE = /^[A-Za-z_$][\w$.<>[\]]*(?:\s*[|&]\s*[A-Za-z_$][\w$.<>[\]]*)*$/;
|
|
68
|
+
var TYPE_NAME_SHAPE = /^[A-Za-z_$][\w$]*(?:<[\w$,\s[\]]+>)?$/;
|
|
44
69
|
function parseTypeDefinitions(content) {
|
|
45
70
|
const section = extractSection(content, "Data Model");
|
|
46
71
|
if (!section)
|
|
@@ -48,25 +73,94 @@ function parseTypeDefinitions(content) {
|
|
|
48
73
|
const results = [];
|
|
49
74
|
const blocks = section.split(/^(?=###\s)/m);
|
|
50
75
|
for (const block of blocks) {
|
|
51
|
-
const headingMatch = /^###\s+(\
|
|
76
|
+
const headingMatch = /^###\s+(.+?)\s*$/m.exec(block);
|
|
52
77
|
if (!headingMatch)
|
|
53
78
|
continue;
|
|
54
|
-
const name = headingMatch[1];
|
|
79
|
+
const name = headingMatch[1].trim().replace(/^`|`$/g, "");
|
|
80
|
+
if (!TYPE_NAME_SHAPE.test(name))
|
|
81
|
+
continue;
|
|
55
82
|
const fields = [];
|
|
56
|
-
const fieldPattern = /^-\s
|
|
83
|
+
const fieldPattern = /^-\s+(?:`([^`]+)`|([A-Za-z_$][\w$]*\??))\s*:\s*(.+)/gm;
|
|
57
84
|
let fieldMatch;
|
|
58
85
|
while ((fieldMatch = fieldPattern.exec(block)) !== null) {
|
|
59
|
-
const
|
|
86
|
+
const backticked = fieldMatch[1] !== void 0;
|
|
87
|
+
const rawName = fieldMatch[1] ?? fieldMatch[2];
|
|
60
88
|
const optional = rawName.endsWith("?");
|
|
61
89
|
const fieldName = optional ? rawName.slice(0, -1) : rawName;
|
|
62
|
-
const rawType = fieldMatch[
|
|
90
|
+
const rawType = fieldMatch[3].trim();
|
|
63
91
|
const type = rawType.replace(/\s*\(.*?\)\s*$/, "").trim();
|
|
92
|
+
if (!backticked && !TYPE_SHAPE.test(type))
|
|
93
|
+
continue;
|
|
64
94
|
fields.push({ name: fieldName, type, optional });
|
|
65
95
|
}
|
|
96
|
+
if (fields.length === 0)
|
|
97
|
+
fields.push(...parseFieldTable(block));
|
|
98
|
+
if (fields.length === 0)
|
|
99
|
+
continue;
|
|
66
100
|
results.push({ name, fields });
|
|
67
101
|
}
|
|
68
102
|
return results;
|
|
69
103
|
}
|
|
104
|
+
function tableCells(line) {
|
|
105
|
+
const trimmed = line.trim();
|
|
106
|
+
if (!trimmed.startsWith("|"))
|
|
107
|
+
return null;
|
|
108
|
+
return trimmed.replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim().replace(/^`|`$/g, ""));
|
|
109
|
+
}
|
|
110
|
+
function isTableRule(cells) {
|
|
111
|
+
return cells.every((cell) => /^:?-{2,}:?$/.test(cell));
|
|
112
|
+
}
|
|
113
|
+
function parseFieldTable(block) {
|
|
114
|
+
const rows = block.split("\n").map(tableCells);
|
|
115
|
+
const headerIndex = rows.findIndex((r) => r !== null);
|
|
116
|
+
if (headerIndex === -1)
|
|
117
|
+
return [];
|
|
118
|
+
const header = rows[headerIndex];
|
|
119
|
+
const nameColumn = header.findIndex((h) => /^(field|name|property|attribute|key)s?$/i.test(h));
|
|
120
|
+
const typeColumn = header.findIndex((h) => /^types?$/i.test(h));
|
|
121
|
+
if (nameColumn === -1 || typeColumn === -1)
|
|
122
|
+
return [];
|
|
123
|
+
const fields = [];
|
|
124
|
+
for (const cells of rows.slice(headerIndex + 1)) {
|
|
125
|
+
if (cells === null)
|
|
126
|
+
continue;
|
|
127
|
+
if (isTableRule(cells))
|
|
128
|
+
continue;
|
|
129
|
+
const rawName = cells[nameColumn];
|
|
130
|
+
const rawType = cells[typeColumn];
|
|
131
|
+
if (!rawName || !rawType)
|
|
132
|
+
continue;
|
|
133
|
+
const optional = rawName.endsWith("?");
|
|
134
|
+
const name = optional ? rawName.slice(0, -1) : rawName;
|
|
135
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name))
|
|
136
|
+
continue;
|
|
137
|
+
fields.push({ name, type: rawType.replace(/\s*\(.*?\)\s*$/, "").trim(), optional });
|
|
138
|
+
}
|
|
139
|
+
return fields;
|
|
140
|
+
}
|
|
141
|
+
function unreadableTypeBlocks(content) {
|
|
142
|
+
const section = extractSection(content, "Data Model");
|
|
143
|
+
if (!section)
|
|
144
|
+
return [];
|
|
145
|
+
const unreadable = [];
|
|
146
|
+
for (const block of section.split(/^(?=###\s)/m)) {
|
|
147
|
+
const headingMatch = /^###\s+(.+?)\s*$/m.exec(block);
|
|
148
|
+
if (!headingMatch)
|
|
149
|
+
continue;
|
|
150
|
+
const name = headingMatch[1].trim().replace(/^`|`$/g, "");
|
|
151
|
+
if (!TYPE_NAME_SHAPE.test(name))
|
|
152
|
+
continue;
|
|
153
|
+
const hasTable = block.split("\n").some((line) => tableCells(line) !== null);
|
|
154
|
+
if (!hasTable)
|
|
155
|
+
continue;
|
|
156
|
+
const parsed = parseTypeDefinitions(`## Data Model
|
|
157
|
+
|
|
158
|
+
${block}`);
|
|
159
|
+
if (parsed.length === 0)
|
|
160
|
+
unreadable.push(name);
|
|
161
|
+
}
|
|
162
|
+
return unreadable;
|
|
163
|
+
}
|
|
70
164
|
function parseTestCases(content) {
|
|
71
165
|
const section = extractSection(content, "Test Cases");
|
|
72
166
|
if (!section)
|
|
@@ -83,7 +177,15 @@ function parseTestCases(content) {
|
|
|
83
177
|
const bulletMatch = /^-\s+(.+)/.exec(line);
|
|
84
178
|
if (!bulletMatch)
|
|
85
179
|
continue;
|
|
86
|
-
|
|
180
|
+
let bulletText = bulletMatch[1].trim();
|
|
181
|
+
let caseId;
|
|
182
|
+
const idMatch = /^\*{0,2}(TC\d+)\*{0,2}\s*[:.-]\s*/i.exec(bulletText);
|
|
183
|
+
if (idMatch) {
|
|
184
|
+
caseId = idMatch[1].toUpperCase();
|
|
185
|
+
bulletText = bulletText.slice(idMatch[0].length).trim();
|
|
186
|
+
if (!bulletText)
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
87
189
|
const colonIdx = bulletText.indexOf(":");
|
|
88
190
|
if (colonIdx !== -1) {
|
|
89
191
|
const label = bulletText.slice(0, colonIdx).trim();
|
|
@@ -92,11 +194,15 @@ function parseTestCases(content) {
|
|
|
92
194
|
for (const item of items) {
|
|
93
195
|
const trimmed = item.trim();
|
|
94
196
|
if (trimmed) {
|
|
95
|
-
results.push({
|
|
197
|
+
results.push({
|
|
198
|
+
description: `${label}: ${trimmed}`,
|
|
199
|
+
section: currentSection,
|
|
200
|
+
id: caseId
|
|
201
|
+
});
|
|
96
202
|
}
|
|
97
203
|
}
|
|
98
204
|
} else {
|
|
99
|
-
results.push({ description: bulletText, section: currentSection });
|
|
205
|
+
results.push({ description: bulletText, section: currentSection, id: caseId });
|
|
100
206
|
}
|
|
101
207
|
}
|
|
102
208
|
return results;
|
|
@@ -339,9 +445,10 @@ async function walkAppDir(dir, pathPrefix, results) {
|
|
|
339
445
|
}
|
|
340
446
|
}
|
|
341
447
|
}
|
|
342
|
-
async function extractNextjsRoutes(projectDir, appDir
|
|
343
|
-
const
|
|
344
|
-
|
|
448
|
+
async function extractNextjsRoutes(projectDir, appDir) {
|
|
449
|
+
const candidates = appDir !== void 0 ? [appDir] : ["app", "src/app"];
|
|
450
|
+
const scanDir = candidates.map((dir) => join3(projectDir, dir)).find((dir) => existsSync3(dir));
|
|
451
|
+
if (!scanDir) {
|
|
345
452
|
return [];
|
|
346
453
|
}
|
|
347
454
|
let tsMorph;
|
|
@@ -618,7 +725,7 @@ function inferZodType(node, SyntaxKind) {
|
|
|
618
725
|
}
|
|
619
726
|
|
|
620
727
|
// ../check/dist/extractors/prisma.js
|
|
621
|
-
import { readFile } from "fs/promises";
|
|
728
|
+
import { readFile, readdir as readdir2 } from "fs/promises";
|
|
622
729
|
import { join as join6 } from "path";
|
|
623
730
|
var PRISMA_TYPE_MAP = {
|
|
624
731
|
String: "string",
|
|
@@ -631,14 +738,37 @@ var PRISMA_TYPE_MAP = {
|
|
|
631
738
|
Json: "unknown",
|
|
632
739
|
Bytes: "Buffer"
|
|
633
740
|
};
|
|
634
|
-
async function
|
|
635
|
-
const
|
|
636
|
-
|
|
741
|
+
async function findPrismaSchemas(projectDir) {
|
|
742
|
+
const found = [];
|
|
743
|
+
for (const relative of ["prisma/schema.prisma", "schema.prisma"]) {
|
|
744
|
+
const path = join6(projectDir, relative);
|
|
745
|
+
try {
|
|
746
|
+
await readFile(path, "utf-8");
|
|
747
|
+
found.push(path);
|
|
748
|
+
} catch {
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
const schemaDir = join6(projectDir, "prisma", "schema");
|
|
637
752
|
try {
|
|
638
|
-
|
|
753
|
+
for (const entry of await readdir2(schemaDir)) {
|
|
754
|
+
if (entry.endsWith(".prisma"))
|
|
755
|
+
found.push(join6(schemaDir, entry));
|
|
756
|
+
}
|
|
639
757
|
} catch {
|
|
758
|
+
}
|
|
759
|
+
return found;
|
|
760
|
+
}
|
|
761
|
+
async function extractPrismaModels(projectDir) {
|
|
762
|
+
const schemaPaths = await findPrismaSchemas(projectDir);
|
|
763
|
+
if (schemaPaths.length === 0)
|
|
640
764
|
return [];
|
|
765
|
+
const models = [];
|
|
766
|
+
for (const schemaPath of schemaPaths) {
|
|
767
|
+
models.push(...parseSchema(await readFile(schemaPath, "utf-8"), schemaPath));
|
|
641
768
|
}
|
|
769
|
+
return models;
|
|
770
|
+
}
|
|
771
|
+
function parseSchema(content, schemaPath) {
|
|
642
772
|
const models = [];
|
|
643
773
|
const modelRe = /^model\s+(\w+)\s*\{([^}]+)\}/gm;
|
|
644
774
|
let modelMatch;
|
|
@@ -789,7 +919,11 @@ function matchTypes(specTypes, codeTypes, specId) {
|
|
|
789
919
|
specSection: "Data Models",
|
|
790
920
|
expected: `Type: ${specType.name}`,
|
|
791
921
|
severity: "error",
|
|
792
|
-
suggestion: `Implement type "${specType.name}" in code
|
|
922
|
+
suggestion: `Implement type "${specType.name}" in code`,
|
|
923
|
+
// The score's types denominator counts fields; an absent type must
|
|
924
|
+
// subtract all of its fields, not 1, or a project that implements
|
|
925
|
+
// nothing of an N-field model scores (N-1)/N.
|
|
926
|
+
weight: specType.fields.length
|
|
793
927
|
});
|
|
794
928
|
continue;
|
|
795
929
|
}
|
|
@@ -857,7 +991,10 @@ function matchTests(specCases, codeTests, specId) {
|
|
|
857
991
|
category: "test",
|
|
858
992
|
specId,
|
|
859
993
|
specSection: specCase.section,
|
|
860
|
-
expected
|
|
994
|
+
// `expected` keeps the case ID so the finding can be traced back to a
|
|
995
|
+
// line in the test plan; the suggestion is the test name to write, and
|
|
996
|
+
// the spec's own label is no part of that.
|
|
997
|
+
expected: specCase.id ? `${specCase.id}: ${specCase.description}` : specCase.description,
|
|
861
998
|
severity: "warn",
|
|
862
999
|
suggestion: `Add a test matching: "${specCase.description}"`
|
|
863
1000
|
});
|
|
@@ -951,8 +1088,12 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
951
1088
|
continue;
|
|
952
1089
|
}
|
|
953
1090
|
for (const name of artifact.exports) {
|
|
954
|
-
|
|
955
|
-
|
|
1091
|
+
if (exported.has(name)) {
|
|
1092
|
+
total += 1;
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
if (enforced) {
|
|
1096
|
+
total += 1;
|
|
956
1097
|
findings.push({
|
|
957
1098
|
type: "missing",
|
|
958
1099
|
category: "artifact",
|
|
@@ -962,6 +1103,17 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
962
1103
|
severity: "error",
|
|
963
1104
|
suggestion: `Export ${name} from ${artifact.path} or update the artifacts list in ${specId}.`
|
|
964
1105
|
});
|
|
1106
|
+
} else {
|
|
1107
|
+
pending += 1;
|
|
1108
|
+
findings.push({
|
|
1109
|
+
type: "pending",
|
|
1110
|
+
category: "artifact",
|
|
1111
|
+
specId,
|
|
1112
|
+
codeLocation: { file: artifact.path, line: 1 },
|
|
1113
|
+
expected: `export "${name}" from ${artifact.path}`,
|
|
1114
|
+
severity: "info",
|
|
1115
|
+
suggestion: `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`
|
|
1116
|
+
});
|
|
965
1117
|
}
|
|
966
1118
|
}
|
|
967
1119
|
}
|
|
@@ -970,7 +1122,7 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
970
1122
|
notes.push(`artifact export checks skipped for ${skippedExports} export(s): ts-morph is not available or the file could not be parsed.`);
|
|
971
1123
|
}
|
|
972
1124
|
if (pending > 0) {
|
|
973
|
-
notes.push(`${pending} declared artifact(s) pending: planned by specs that are not yet approved. They are excluded from the score and become enforceable when the spec status changes to approved.`);
|
|
1125
|
+
notes.push(`${pending} declared artifact assertion(s) pending: files or exports planned by specs that are not yet approved. They are excluded from the score and become enforceable when the spec status changes to approved.`);
|
|
974
1126
|
}
|
|
975
1127
|
return { findings, total, checked: total, pending, notes };
|
|
976
1128
|
}
|
|
@@ -980,7 +1132,7 @@ function computeScore(findings, totals) {
|
|
|
980
1132
|
const missingByCategory = { route: 0, type: 0, test: 0, artifact: 0 };
|
|
981
1133
|
for (const f of findings) {
|
|
982
1134
|
if (f.type === "missing" || f.type === "mismatch") {
|
|
983
|
-
missingByCategory[f.category] = (missingByCategory[f.category] ?? 0) + 1;
|
|
1135
|
+
missingByCategory[f.category] = (missingByCategory[f.category] ?? 0) + (f.weight ?? 1);
|
|
984
1136
|
}
|
|
985
1137
|
}
|
|
986
1138
|
const categoryMap = {
|
|
@@ -1032,6 +1184,15 @@ async function detectFramework(projectDir) {
|
|
|
1032
1184
|
}
|
|
1033
1185
|
|
|
1034
1186
|
// ../check/dist/check.js
|
|
1187
|
+
async function usesPrisma(projectDir) {
|
|
1188
|
+
try {
|
|
1189
|
+
const pkg = JSON.parse(await readFile3(join10(projectDir, "package.json"), "utf-8"));
|
|
1190
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
1191
|
+
return "prisma" in deps || "@prisma/client" in deps;
|
|
1192
|
+
} catch {
|
|
1193
|
+
return false;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1035
1196
|
async function runCheck(specs, projectDir, config = {}) {
|
|
1036
1197
|
const findings = [];
|
|
1037
1198
|
const notes = [];
|
|
@@ -1043,7 +1204,7 @@ async function runCheck(specs, projectDir, config = {}) {
|
|
|
1043
1204
|
let codeTestCount = null;
|
|
1044
1205
|
const tsMorphAvailable = await import("ts-morph").then(() => true, () => false);
|
|
1045
1206
|
if (!tsMorphAvailable) {
|
|
1046
|
-
notes.push("route and
|
|
1207
|
+
notes.push("route, type and test extraction skipped: ts-morph is not installed. Install specdx and ts-morph as devDependencies (pnpm add -D specdx ts-morph) \u2014 an ephemeral runner like pnpm dlx cannot provide it.");
|
|
1047
1208
|
}
|
|
1048
1209
|
const framework = config.framework && config.framework !== "auto" ? config.framework : await detectFramework(projectDir);
|
|
1049
1210
|
const apiContractSpecs = specs.filter((s) => s.frontmatter.type === "api-contract");
|
|
@@ -1054,27 +1215,41 @@ async function runCheck(specs, projectDir, config = {}) {
|
|
|
1054
1215
|
const specEndpoints = parseEndpoints(spec.content);
|
|
1055
1216
|
routeTotal += specEndpoints.length;
|
|
1056
1217
|
findings.push(...matchRoutes(specEndpoints, codeRoutes, spec.frontmatter.id));
|
|
1218
|
+
if (specEndpoints.length === 0 && hasEndpointsSection(spec.content)) {
|
|
1219
|
+
notes.push(`${spec.frontmatter.id}: no endpoints recognised in its Endpoints section, so routes were not assessed. Write each endpoint as \`- GET /path \u2014 description\` or as a \`### GET /path\` heading.`);
|
|
1220
|
+
}
|
|
1057
1221
|
}
|
|
1058
1222
|
if (framework === null) {
|
|
1059
1223
|
notes.push("no supported framework detected (express, hono, nextjs) \u2014 route extraction ran in fallback mode across all extractors.");
|
|
1060
1224
|
}
|
|
1061
1225
|
}
|
|
1062
1226
|
const designSpecs = specs.filter((s) => s.frontmatter.type === "technical-design");
|
|
1063
|
-
|
|
1227
|
+
const prismaSchemaFound = (await findPrismaSchemas(projectDir)).length > 0;
|
|
1228
|
+
if (designSpecs.length > 0 && (tsMorphAvailable || prismaSchemaFound)) {
|
|
1064
1229
|
const codeTypes = [
|
|
1065
1230
|
...tsMorphAvailable ? await extractTypeScriptTypes(projectDir, config.types_dir) : [],
|
|
1066
1231
|
...tsMorphAvailable ? await extractZodSchemas(projectDir, config.types_dir) : [],
|
|
1067
1232
|
...await extractPrismaModels(projectDir)
|
|
1068
1233
|
];
|
|
1069
1234
|
codeTypeCount = codeTypes.length;
|
|
1235
|
+
if (await usesPrisma(projectDir) && !prismaSchemaFound) {
|
|
1236
|
+
notes.push("a prisma dependency is declared but no schema was found at prisma/schema.prisma, schema.prisma or prisma/schema/*.prisma \u2014 Prisma models were not assessed.");
|
|
1237
|
+
}
|
|
1070
1238
|
for (const spec of designSpecs) {
|
|
1071
1239
|
const specTypes = parseTypeDefinitions(spec.content);
|
|
1072
|
-
|
|
1240
|
+
const fieldCount = specTypes.reduce((sum, t) => sum + t.fields.length, 0);
|
|
1241
|
+
typeTotal += fieldCount;
|
|
1073
1242
|
findings.push(...matchTypes(specTypes, codeTypes, spec.frontmatter.id));
|
|
1243
|
+
if (fieldCount === 0 && /^##\s+Data Model\s*$/im.test(spec.content)) {
|
|
1244
|
+
notes.push(`${spec.frontmatter.id}: no fields recognised in its Data Model, so types were not assessed. Write fields as \`- name: type\` (one per line, under a \`### TypeName\` heading).`);
|
|
1245
|
+
}
|
|
1246
|
+
for (const name of unreadableTypeBlocks(spec.content)) {
|
|
1247
|
+
notes.push(`${spec.frontmatter.id}: no fields recognised under \`### ${name}\`, so that type was not assessed. A table needs a field column and a type column, or write fields as \`- name: type\`.`);
|
|
1248
|
+
}
|
|
1074
1249
|
}
|
|
1075
1250
|
}
|
|
1076
1251
|
const testPlanSpecs = specs.filter((s) => s.frontmatter.type === "test-plan");
|
|
1077
|
-
if (testPlanSpecs.length > 0) {
|
|
1252
|
+
if (testPlanSpecs.length > 0 && tsMorphAvailable) {
|
|
1078
1253
|
const codeTests = await extractTestDescriptions(projectDir, config.tests_dir);
|
|
1079
1254
|
codeTestCount = codeTests.length;
|
|
1080
1255
|
for (const spec of testPlanSpecs) {
|
|
@@ -1127,7 +1302,7 @@ async function extractRoutes(projectDir, config, framework) {
|
|
|
1127
1302
|
async function analyzeWithAi(findings, context) {
|
|
1128
1303
|
const apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
1129
1304
|
if (!apiKey) {
|
|
1130
|
-
throw new Error("ANTHROPIC_API_KEY environment variable is required for --ai mode. Set it or use the
|
|
1305
|
+
throw new Error("ANTHROPIC_API_KEY environment variable is required for --ai mode. Set it or use the specdx-verify skill instead (no API key needed).");
|
|
1131
1306
|
}
|
|
1132
1307
|
if (findings.length === 0) {
|
|
1133
1308
|
return { findings, assessments: [], summary: "No findings to analyze." };
|
|
@@ -1183,4 +1358,4 @@ export {
|
|
|
1183
1358
|
runCheck,
|
|
1184
1359
|
analyzeWithAi
|
|
1185
1360
|
};
|
|
1186
|
-
//# sourceMappingURL=chunk-
|
|
1361
|
+
//# sourceMappingURL=chunk-3YXRWQGX.js.map
|