specdx 0.4.0 → 0.6.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.
Files changed (78) hide show
  1. package/.claude-plugin/plugin.json +2 -2
  2. package/README.md +43 -3
  3. package/dist/{check-PHXXA7VY.js → check-5EA2MTNN.js} +121 -27
  4. package/dist/check-5EA2MTNN.js.map +1 -0
  5. package/dist/{chunk-3YXRWQGX.js → chunk-2UUQJ2ER.js} +242 -53
  6. package/dist/chunk-2UUQJ2ER.js.map +1 -0
  7. package/dist/{chunk-NAWYG4VV.js → chunk-5XOWCPP2.js} +2 -2
  8. package/dist/{chunk-2BZIG7OE.js → chunk-BZL2XXMA.js} +14 -14
  9. package/dist/{chunk-SNQNQ2MP.js → chunk-JGD3BOPH.js} +16 -6
  10. package/dist/chunk-JGD3BOPH.js.map +1 -0
  11. package/dist/{chunk-YRQPY5NF.js → chunk-MOYYF7Q6.js} +2 -2
  12. package/dist/{chunk-OVIKIIR4.js → chunk-QAJZCJUJ.js} +4 -3
  13. package/dist/chunk-QAJZCJUJ.js.map +1 -0
  14. package/dist/{chunk-LJTLNXGV.js → chunk-VVZUJ6H4.js} +353 -4
  15. package/dist/chunk-VVZUJ6H4.js.map +1 -0
  16. package/dist/{chunk-HCJDCS26.js → chunk-XRWLPU24.js} +10 -1
  17. package/dist/chunk-XRWLPU24.js.map +1 -0
  18. package/dist/{diff-6C5LJ7SH.js → diff-ZT6HXHK5.js} +4 -4
  19. package/dist/dist-6WDWUOCV.js +26 -0
  20. package/dist/{dist-PK52GA7M.js → dist-A3CWALDC.js} +76 -16
  21. package/dist/dist-A3CWALDC.js.map +1 -0
  22. package/dist/{generate-K72WD455.js → generate-M6YKXUDE.js} +5 -5
  23. package/dist/{generate-story-NUCNYL3I.js → generate-story-BXGNKWC6.js} +4 -4
  24. package/dist/{generate-test-plan-Z46W3N3B.js → generate-test-plan-PZUNCNN3.js} +3 -3
  25. package/dist/{graph-4RNURBNP.js → graph-GKXD2IGW.js} +3 -3
  26. package/dist/index.d.ts +38 -0
  27. package/dist/index.js +463 -26
  28. package/dist/index.js.map +1 -1
  29. package/dist/{lint-2VZPNLE3.js → lint-GZX5C5EQ.js} +93 -14
  30. package/dist/lint-GZX5C5EQ.js.map +1 -0
  31. package/dist/main.js +3 -3
  32. package/dist/{mcp-E6PJWBDQ.js → mcp-VQAYNJQ7.js} +3 -3
  33. package/dist/{migrate-FKFC7UAO.js → migrate-VASWPA3L.js} +3 -3
  34. package/dist/{pack-DE4UBTCC.js → pack-DFUCNWVR.js} +4 -4
  35. package/dist/{ready-K74SLQ24.js → ready-5OFSV2OD.js} +5 -5
  36. package/dist/{status-IAE3BB77.js → status-5MDODW4N.js} +5 -5
  37. package/dist/{update-UFOHZEAK.js → update-NFXC45UT.js} +4 -4
  38. package/dist/{validate-EZHUB5TW.js → validate-LWRLZR3H.js} +3 -3
  39. package/package.json +5 -4
  40. package/skills/core/specdx-author-spec/SKILL.md +33 -0
  41. package/skills/core/specdx-author-spec/references/spec-type-reference.md +57 -0
  42. package/skills/core/specdx-author-spec/references/step-01-frontmatter.md +66 -0
  43. package/skills/core/specdx-author-spec/references/step-02-sections.md +111 -0
  44. package/skills/core/specdx-author-spec/references/step-03-finalize.md +48 -0
  45. package/skills/core/specdx-onboard/SKILL.md +54 -0
  46. package/skills/core/specdx-plan-from-spec/SKILL.md +76 -0
  47. package/skills/core/specdx-pre-commit/SKILL.md +70 -0
  48. package/skills/core/specdx-review-spec/SKILL.md +81 -0
  49. package/skills/core/specdx-router/SKILL.md +67 -0
  50. package/skills/core/specdx-sprint-review/SKILL.md +73 -0
  51. package/skills/core/specdx-start-task/SKILL.md +62 -0
  52. package/skills/experimental/specdx-check-drift/SKILL.md +77 -0
  53. package/skills/experimental/specdx-verify/SKILL.md +85 -0
  54. package/dist/check-PHXXA7VY.js.map +0 -1
  55. package/dist/chunk-3YXRWQGX.js.map +0 -1
  56. package/dist/chunk-HCJDCS26.js.map +0 -1
  57. package/dist/chunk-LJTLNXGV.js.map +0 -1
  58. package/dist/chunk-OVIKIIR4.js.map +0 -1
  59. package/dist/chunk-SNQNQ2MP.js.map +0 -1
  60. package/dist/dist-PK52GA7M.js.map +0 -1
  61. package/dist/dist-ROHCFKYT.js +0 -16
  62. package/dist/lint-2VZPNLE3.js.map +0 -1
  63. /package/dist/{chunk-NAWYG4VV.js.map → chunk-5XOWCPP2.js.map} +0 -0
  64. /package/dist/{chunk-2BZIG7OE.js.map → chunk-BZL2XXMA.js.map} +0 -0
  65. /package/dist/{chunk-YRQPY5NF.js.map → chunk-MOYYF7Q6.js.map} +0 -0
  66. /package/dist/{diff-6C5LJ7SH.js.map → diff-ZT6HXHK5.js.map} +0 -0
  67. /package/dist/{dist-ROHCFKYT.js.map → dist-6WDWUOCV.js.map} +0 -0
  68. /package/dist/{generate-K72WD455.js.map → generate-M6YKXUDE.js.map} +0 -0
  69. /package/dist/{generate-story-NUCNYL3I.js.map → generate-story-BXGNKWC6.js.map} +0 -0
  70. /package/dist/{generate-test-plan-Z46W3N3B.js.map → generate-test-plan-PZUNCNN3.js.map} +0 -0
  71. /package/dist/{graph-4RNURBNP.js.map → graph-GKXD2IGW.js.map} +0 -0
  72. /package/dist/{mcp-E6PJWBDQ.js.map → mcp-VQAYNJQ7.js.map} +0 -0
  73. /package/dist/{migrate-FKFC7UAO.js.map → migrate-VASWPA3L.js.map} +0 -0
  74. /package/dist/{pack-DE4UBTCC.js.map → pack-DFUCNWVR.js.map} +0 -0
  75. /package/dist/{ready-K74SLQ24.js.map → ready-5OFSV2OD.js.map} +0 -0
  76. /package/dist/{status-IAE3BB77.js.map → status-5MDODW4N.js.map} +0 -0
  77. /package/dist/{update-UFOHZEAK.js.map → update-NFXC45UT.js.map} +0 -0
  78. /package/dist/{validate-EZHUB5TW.js.map → validate-LWRLZR3H.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1816,6 +1816,15 @@ var config_default = {
1816
1816
  }
1817
1817
  },
1818
1818
  additionalProperties: false
1819
+ },
1820
+ agents: {
1821
+ type: "object",
1822
+ properties: {
1823
+ paths: { type: "array", items: { type: "string" } },
1824
+ max_tokens: { type: "integer", minimum: 1 },
1825
+ rules: { type: "object" }
1826
+ },
1827
+ additionalProperties: false
1819
1828
  }
1820
1829
  },
1821
1830
  required: ["version", "specs"],
@@ -2104,7 +2113,7 @@ var init_default = defineCommand({
2104
2113
  import { defineCommand as defineCommand2 } from "citty";
2105
2114
 
2106
2115
  // ../core/dist/config.js
2107
- import { readFile } from "fs/promises";
2116
+ import { readFile, stat } from "fs/promises";
2108
2117
  import { join as join2, dirname } from "path";
2109
2118
  import { parse as parseYaml } from "yaml";
2110
2119
  var ConfigError = class extends Error {
@@ -2143,15 +2152,24 @@ async function findConfig(from) {
2143
2152
  let dir = from;
2144
2153
  while (true) {
2145
2154
  const candidate = join2(dir, CONFIG_FILENAME);
2155
+ let stats;
2146
2156
  try {
2147
- await readFile(candidate, "utf-8");
2148
- return candidate;
2149
- } catch {
2157
+ stats = await stat(candidate);
2158
+ } catch (err) {
2159
+ const code = err.code;
2160
+ if (code !== "ENOENT" && code !== "ENOTDIR") {
2161
+ throw new ConfigError(`Cannot read config file: ${candidate} (${code}).`);
2162
+ }
2150
2163
  const parent = dirname(dir);
2151
2164
  if (parent === dir)
2152
2165
  return void 0;
2153
2166
  dir = parent;
2167
+ continue;
2168
+ }
2169
+ if (!stats.isFile()) {
2170
+ throw new ConfigError(`Cannot read config file: ${candidate} is not a regular file.`);
2154
2171
  }
2172
+ return candidate;
2155
2173
  }
2156
2174
  }
2157
2175
 
@@ -3311,6 +3329,352 @@ async function resolveLintConfig({ config, preset, configDir }) {
3311
3329
  return { rules: [...byId.values()], ignore };
3312
3330
  }
3313
3331
 
3332
+ // ../lint/dist/agents/discover.js
3333
+ import { readFile as readFile4 } from "fs/promises";
3334
+ import { relative } from "path";
3335
+ var DEFAULT_AGENT_PATHS = ["AGENTS.md", "CLAUDE.md"];
3336
+ var DEFAULT_MAX_TOKENS = 8e3;
3337
+ async function discoverAgentFiles(patterns, configDir) {
3338
+ const seen = /* @__PURE__ */ new Set();
3339
+ const files = [];
3340
+ for (const pattern of patterns) {
3341
+ for (const filePath of await resolveGlob(pattern, configDir)) {
3342
+ if (seen.has(filePath))
3343
+ continue;
3344
+ seen.add(filePath);
3345
+ const content = await readFile4(filePath, "utf8");
3346
+ files.push({
3347
+ filePath,
3348
+ relativePath: relative(configDir, filePath),
3349
+ content,
3350
+ lines: content.split("\n"),
3351
+ tokens: countTokens(content)
3352
+ });
3353
+ }
3354
+ }
3355
+ return files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
3356
+ }
3357
+
3358
+ // ../lint/dist/agents/rules/structure.js
3359
+ var structureRule = {
3360
+ id: "agents/structure",
3361
+ description: "Agent instruction files should have content and be organised under headings",
3362
+ severity: "warn",
3363
+ run(context) {
3364
+ const { file } = context;
3365
+ const diagnostics = [];
3366
+ if (file.content.trim() === "") {
3367
+ diagnostics.push({
3368
+ ruleId: "agents/structure",
3369
+ severity: "warn",
3370
+ message: `${file.relativePath} is empty. An empty instruction file steers nothing \u2014 delete it or write it.`,
3371
+ filePath: file.filePath
3372
+ });
3373
+ return { diagnostics };
3374
+ }
3375
+ const headings = file.lines.filter((line) => /^#{1,6}\s+\S/.test(line));
3376
+ if (headings.length === 0) {
3377
+ diagnostics.push({
3378
+ ruleId: "agents/structure",
3379
+ severity: "warn",
3380
+ message: `${file.relativePath} has no headings, so it is one undifferentiated block. Nothing can be referenced, revised, or removed in isolation.`,
3381
+ filePath: file.filePath
3382
+ });
3383
+ }
3384
+ return { diagnostics };
3385
+ }
3386
+ };
3387
+
3388
+ // ../lint/dist/agents/rules/stale-references.js
3389
+ var PATH_SHAPED = /^(?:[\w.@-]+\/)+[\w.-]+$|^[\w.-]+\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|ya?ml|toml|sh|py|rb|rs|go|java|css|html)$/;
3390
+ function isNotAFileClaim(candidate) {
3391
+ return candidate.includes("*") || // a glob describes a set, not a file
3392
+ candidate.includes("://") || // a URL
3393
+ candidate.startsWith("http") || candidate.startsWith("@") || // an npm scope: @specdx/core
3394
+ candidate.startsWith("~") || // a home-relative path outside the repo
3395
+ candidate.startsWith("/") || // an absolute path outside the repo
3396
+ /^[A-Z_]+=/.test(candidate);
3397
+ }
3398
+ function normalise(candidate) {
3399
+ return candidate.replace(/^\.\//, "").replace(/[.,;:)]+$/, "");
3400
+ }
3401
+ function fencedLines(lines) {
3402
+ const fenced = /* @__PURE__ */ new Set();
3403
+ let fence;
3404
+ lines.forEach((line, index) => {
3405
+ const match = /^\s*(`{3,}|~{3,})/.exec(line);
3406
+ if (match) {
3407
+ if (fence === void 0) {
3408
+ fence = match[1];
3409
+ fenced.add(index);
3410
+ return;
3411
+ }
3412
+ if (match[1][0] === fence[0])
3413
+ fence = void 0;
3414
+ fenced.add(index);
3415
+ return;
3416
+ }
3417
+ if (fence !== void 0)
3418
+ fenced.add(index);
3419
+ });
3420
+ return fenced;
3421
+ }
3422
+ var REPORTS_ABSENCE = /\b(?:removed?|removal|deleted?|renamed?|moved|dropped|retired|replaced|no longer|does not exist)\b/i;
3423
+ var INTRODUCES_EXAMPLE = /\b(?:e\.g\.|for example|for instance|such as)/i;
3424
+ function extractReferences(lines) {
3425
+ const skip = fencedLines(lines);
3426
+ const found = [];
3427
+ const seen = /* @__PURE__ */ new Set();
3428
+ lines.forEach((line, index) => {
3429
+ if (skip.has(index))
3430
+ return;
3431
+ if (REPORTS_ABSENCE.test(line.replace(/`[^`\n]*`|\]\([^)]*\)/g, "")))
3432
+ return;
3433
+ const exampleFrom = INTRODUCES_EXAMPLE.exec(line)?.index ?? Infinity;
3434
+ const candidates = [];
3435
+ const collect = (pattern) => {
3436
+ for (const match of line.matchAll(pattern)) {
3437
+ if (match.index < exampleFrom)
3438
+ candidates.push(match[1]);
3439
+ }
3440
+ };
3441
+ collect(/`([^`\n]+)`/g);
3442
+ collect(/\]\((?!https?:|#)([^)\s]+)\)/g);
3443
+ for (const raw of candidates) {
3444
+ const candidate = normalise(raw.trim());
3445
+ if (!candidate || isNotAFileClaim(candidate))
3446
+ continue;
3447
+ if (!PATH_SHAPED.test(candidate))
3448
+ continue;
3449
+ if (seen.has(candidate))
3450
+ continue;
3451
+ seen.add(candidate);
3452
+ found.push({ path: candidate, line: index + 1 });
3453
+ }
3454
+ });
3455
+ return found;
3456
+ }
3457
+ var staleReferencesRule = {
3458
+ id: "agents/stale-references",
3459
+ description: "Paths named by an agent instruction file must exist",
3460
+ severity: "warn",
3461
+ run(context) {
3462
+ const { file, exists } = context;
3463
+ const references = extractReferences(file.lines);
3464
+ if (references.length === 0) {
3465
+ return {
3466
+ diagnostics: [],
3467
+ assessed: false,
3468
+ notAssessedReason: `${file.relativePath} names no file paths, so none were checked for staleness.`
3469
+ };
3470
+ }
3471
+ return {
3472
+ diagnostics: references.filter((reference) => !exists(reference.path)).map((reference) => ({
3473
+ ruleId: "agents/stale-references",
3474
+ severity: this.severity,
3475
+ message: `${file.relativePath} refers to "${reference.path}", which does not exist. An agent told to look there will not find it.`,
3476
+ filePath: file.filePath,
3477
+ line: reference.line
3478
+ }))
3479
+ };
3480
+ }
3481
+ };
3482
+
3483
+ // ../lint/dist/agents/rules/size-budget.js
3484
+ var sizeBudgetRule = {
3485
+ id: "agents/size-budget",
3486
+ description: "Agent instruction files should fit a token budget",
3487
+ severity: "warn",
3488
+ run(context) {
3489
+ const { file, maxTokens } = context;
3490
+ if (file.tokens <= maxTokens)
3491
+ return { diagnostics: [] };
3492
+ const over = file.tokens - maxTokens;
3493
+ const percent = Math.round(over / maxTokens * 100);
3494
+ return {
3495
+ diagnostics: [
3496
+ {
3497
+ ruleId: "agents/size-budget",
3498
+ severity: this.severity,
3499
+ message: `${file.relativePath} is ${file.tokens} tokens, ${over} over the ${maxTokens} budget (${percent}% over). It is spending the context window it exists to protect.`,
3500
+ filePath: file.filePath
3501
+ }
3502
+ ]
3503
+ };
3504
+ }
3505
+ };
3506
+
3507
+ // ../lint/dist/agents/resolve-reference.js
3508
+ import { execFileSync } from "child_process";
3509
+ import { readdirSync } from "fs";
3510
+ import { join as join4, sep } from "path";
3511
+ var SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
3512
+ "node_modules",
3513
+ ".git",
3514
+ "dist",
3515
+ "build",
3516
+ "coverage",
3517
+ ".next",
3518
+ ".turbo",
3519
+ ".cache",
3520
+ "out"
3521
+ ]);
3522
+ var MAX_INDEXED_FILES = 2e4;
3523
+ function indexProjectFiles(configDir) {
3524
+ const found = [];
3525
+ const walk2 = (dir, prefix) => {
3526
+ if (found.length >= MAX_INDEXED_FILES)
3527
+ return;
3528
+ let entries;
3529
+ try {
3530
+ entries = readdirSync(dir, { withFileTypes: true });
3531
+ } catch {
3532
+ return;
3533
+ }
3534
+ for (const entry of entries) {
3535
+ if (found.length >= MAX_INDEXED_FILES)
3536
+ return;
3537
+ const relative3 = prefix ? `${prefix}/${entry.name}` : entry.name;
3538
+ if (entry.isDirectory()) {
3539
+ if (SKIP_DIRECTORIES.has(entry.name))
3540
+ continue;
3541
+ found.push(relative3);
3542
+ walk2(join4(dir, entry.name), relative3);
3543
+ } else {
3544
+ found.push(relative3);
3545
+ }
3546
+ }
3547
+ };
3548
+ walk2(configDir, "");
3549
+ return found;
3550
+ }
3551
+ var PLACEHOLDER_STEMS = /* @__PURE__ */ new Set([
3552
+ "foo",
3553
+ "bar",
3554
+ "baz",
3555
+ "qux",
3556
+ "example",
3557
+ "your-app",
3558
+ "my-app",
3559
+ "some-file",
3560
+ "path"
3561
+ ]);
3562
+ function isPlaceholder(reference) {
3563
+ const base = reference.split("/").pop() ?? reference;
3564
+ const stem = base.split(".")[0] ?? base;
3565
+ return PLACEHOLDER_STEMS.has(stem.toLowerCase());
3566
+ }
3567
+ var HAS_EXTENSION = /\.[A-Za-z][A-Za-z0-9]{0,9}$/;
3568
+ function createGitIgnoreCheck(configDir) {
3569
+ return (reference) => {
3570
+ try {
3571
+ execFileSync("git", ["check-ignore", "-q", "--", reference], {
3572
+ cwd: configDir,
3573
+ stdio: "ignore"
3574
+ });
3575
+ return true;
3576
+ } catch {
3577
+ return false;
3578
+ }
3579
+ };
3580
+ }
3581
+ function createReferenceResolver(files, options = {}) {
3582
+ const exact = new Set(files);
3583
+ const byLastSegment = /* @__PURE__ */ new Map();
3584
+ for (const file of files) {
3585
+ const last = file.split("/").pop();
3586
+ const bucket = byLastSegment.get(last);
3587
+ if (bucket)
3588
+ bucket.push(file);
3589
+ else
3590
+ byLastSegment.set(last, [file]);
3591
+ }
3592
+ return (reference) => {
3593
+ const normalised = reference.split(sep).join("/");
3594
+ if (exact.has(normalised))
3595
+ return true;
3596
+ if (isPlaceholder(normalised))
3597
+ return true;
3598
+ const segments = normalised.split("/");
3599
+ const last = segments[segments.length - 1];
3600
+ if (!last)
3601
+ return false;
3602
+ const candidates = byLastSegment.get(last) ?? [];
3603
+ if (candidates.some((c) => c === normalised || c.endsWith(`/${normalised}`)))
3604
+ return true;
3605
+ if (segments.some((segment) => SKIP_DIRECTORIES.has(segment)))
3606
+ return true;
3607
+ if (segments.length > 1 && !HAS_EXTENSION.test(last) && segments[0] !== ".." && !byLastSegment.has(segments[0])) {
3608
+ return true;
3609
+ }
3610
+ return options.isIgnored?.(normalised) ?? false;
3611
+ };
3612
+ }
3613
+
3614
+ // ../lint/dist/agents/index.js
3615
+ var AGENT_RULES = [structureRule, staleReferencesRule, sizeBudgetRule];
3616
+ var VALID_SEVERITIES = /* @__PURE__ */ new Set(["error", "warn", "info"]);
3617
+ var AgentConfigError = class extends Error {
3618
+ };
3619
+ function resolveAgentRules(overrides = {}) {
3620
+ const known = new Map(AGENT_RULES.map((rule) => [rule.id, rule]));
3621
+ for (const id of Object.keys(overrides)) {
3622
+ if (!known.has(id)) {
3623
+ throw new AgentConfigError(`Unknown agent rule "${id}" in agents.rules. Known rules: ${[...known.keys()].join(", ")}.`);
3624
+ }
3625
+ }
3626
+ const resolved = [];
3627
+ for (const rule of AGENT_RULES) {
3628
+ const override = overrides[rule.id];
3629
+ if (override === void 0) {
3630
+ resolved.push(rule);
3631
+ continue;
3632
+ }
3633
+ if (override === false || override === "off")
3634
+ continue;
3635
+ if (typeof override === "string" && VALID_SEVERITIES.has(override)) {
3636
+ resolved.push({ ...rule, severity: override });
3637
+ continue;
3638
+ }
3639
+ throw new AgentConfigError(`Invalid severity ${JSON.stringify(override)} for "${rule.id}". Use "error", "warn", "info", "off", or false.`);
3640
+ }
3641
+ return resolved;
3642
+ }
3643
+ async function lintAgentFiles(options) {
3644
+ const { config, configDir } = options;
3645
+ const agents = config.agents ?? {};
3646
+ const patterns = agents.paths ?? DEFAULT_AGENT_PATHS;
3647
+ const maxTokens = agents.max_tokens ?? DEFAULT_MAX_TOKENS;
3648
+ const rules = resolveAgentRules(agents.rules);
3649
+ const files = await discoverAgentFiles(patterns, configDir);
3650
+ const exists = options.exists ?? (files.length > 0 ? createReferenceResolver(indexProjectFiles(configDir), {
3651
+ isIgnored: createGitIgnoreCheck(configDir)
3652
+ }) : () => true);
3653
+ const diagnostics = [];
3654
+ for (const file of files) {
3655
+ for (const rule of rules) {
3656
+ const result = rule.run({ file, configDir, exists, maxTokens });
3657
+ for (const diagnostic of result.diagnostics) {
3658
+ diagnostics.push({ ...diagnostic, severity: rule.severity });
3659
+ }
3660
+ if (result.assessed === false) {
3661
+ diagnostics.push({
3662
+ ruleId: rule.id,
3663
+ severity: "info",
3664
+ message: result.notAssessedReason ?? `${rule.id} assessed nothing in ${file.relativePath}.`,
3665
+ filePath: file.filePath
3666
+ });
3667
+ }
3668
+ }
3669
+ }
3670
+ return { diagnostics, filesLinted: files.length, assessed: files.length > 0 };
3671
+ }
3672
+ var AGENT_ONLY_CONFIG = { version: "1.0", specs: {}, agents: {} };
3673
+ async function lintAgentFilesWithoutConfig(configDir) {
3674
+ const results = await lintAgentFiles({ config: AGENT_ONLY_CONFIG, configDir });
3675
+ return results.assessed ? results : null;
3676
+ }
3677
+
3314
3678
  // src/shared-args.ts
3315
3679
  var quietArg = {
3316
3680
  type: "boolean",
@@ -3391,7 +3755,28 @@ async function runLint(options) {
3391
3755
  if (!options.configDir) {
3392
3756
  throw new TypeError("runLint requires `configDir` \u2014 the directory holding spec.config.yaml.");
3393
3757
  }
3394
- const config = await loadConfig(void 0, options.configDir);
3758
+ const configPath = await findConfig(options.configDir);
3759
+ if (!configPath) {
3760
+ if (options.specPath) {
3761
+ throw new ConfigError(
3762
+ `No spec.config.yaml at or above this directory, so "${options.specPath}" was not linted as a spec. Run \`specdx lint\` with no path to lint AGENTS.md and CLAUDE.md, or \`specdx init\` to add a spec suite.`
3763
+ );
3764
+ }
3765
+ const agentResults = await lintAgentFilesWithoutConfig(options.configDir);
3766
+ if (!agentResults) {
3767
+ throw new ConfigError("No spec.config.yaml found. Run 'specdx init' to create one.");
3768
+ }
3769
+ return {
3770
+ diagnostics: agentResults.diagnostics,
3771
+ hasErrors: agentResults.diagnostics.some((d) => d.severity === "error"),
3772
+ hasWarnings: agentResults.diagnostics.some((d) => d.severity === "warn"),
3773
+ specFiles: 0,
3774
+ assessed: false,
3775
+ agentFiles: agentResults.filesLinted,
3776
+ specSuite: false
3777
+ };
3778
+ }
3779
+ const config = await loadConfig(configPath, options.configDir);
3395
3780
  const preset = options.preset ?? config.lint?.extends ?? "recommended";
3396
3781
  const { rules, ignore } = await resolveLintConfig({
3397
3782
  config,
@@ -3414,9 +3799,10 @@ async function runLint(options) {
3414
3799
  }
3415
3800
  const engine = createLintEngine({ rules, config, graph, ignore });
3416
3801
  const results = engine.lint(specs);
3417
- if (options.specPath) {
3418
- const specPath = options.specPath;
3419
- results.diagnostics = results.diagnostics.filter((d) => d.filePath.includes(specPath));
3802
+ const { specPath } = options;
3803
+ const selects = (filePath) => specPath === void 0 || filePath.includes(specPath);
3804
+ if (specPath !== void 0) {
3805
+ results.diagnostics = results.diagnostics.filter((d) => selects(d.filePath));
3420
3806
  results.hasErrors = results.diagnostics.some((d) => d.severity === "error");
3421
3807
  results.hasWarnings = results.diagnostics.some((d) => d.severity === "warn");
3422
3808
  }
@@ -3429,9 +3815,56 @@ async function runLint(options) {
3429
3815
  });
3430
3816
  results.hasErrors = true;
3431
3817
  }
3818
+ let agentFiles = 0;
3819
+ if (config.agents) {
3820
+ const agentResults = await lintAgentFiles({ config, configDir: options.configDir });
3821
+ agentFiles = agentResults.filesLinted;
3822
+ if (!agentResults.assessed) {
3823
+ const patterns = config.agents.paths ?? ["AGENTS.md", "CLAUDE.md"];
3824
+ results.diagnostics.push({
3825
+ ruleId: "agents/paths-match-nothing",
3826
+ severity: "error",
3827
+ message: `agents.paths matched no files (${patterns.join(", ")}), so no agent instruction file was linted. Remove the \`agents\` key or fix the paths.`,
3828
+ filePath: "spec.config.yaml"
3829
+ });
3830
+ results.hasErrors = true;
3831
+ }
3832
+ for (const diagnostic of agentResults.diagnostics) {
3833
+ if (!selects(diagnostic.filePath)) continue;
3834
+ results.diagnostics.push(diagnostic);
3835
+ if (diagnostic.severity === "error") results.hasErrors = true;
3836
+ if (diagnostic.severity === "warn") results.hasWarnings = true;
3837
+ }
3838
+ }
3432
3839
  const ignored = new Set(ignore);
3433
- const linted = specs.filter((spec) => !ignored.has(spec.filePath));
3434
- return { ...results, specFiles: linted.length, assessed: linted.length > 0 };
3840
+ const linted = specs.filter((spec) => !ignored.has(spec.filePath) && selects(spec.filePath));
3841
+ return {
3842
+ ...results,
3843
+ specFiles: linted.length,
3844
+ assessed: linted.length > 0,
3845
+ agentFiles,
3846
+ specSuite: true
3847
+ };
3848
+ }
3849
+ function noSpecSuiteNotice(configDir) {
3850
+ return {
3851
+ ruleId: "agents/no-spec-suite",
3852
+ severity: "info",
3853
+ message: "No spec.config.yaml at or above this directory, so no specs were checked \u2014 only agent instruction files. Run `specdx init` to add a spec suite.",
3854
+ filePath: configDir
3855
+ };
3856
+ }
3857
+ function cleanRunMessage(results) {
3858
+ const agentPart = `${results.agentFiles} agent ${results.agentFiles === 1 ? "file" : "files"}`;
3859
+ if (!results.specSuite) {
3860
+ return ` \u2713 ${agentPart} checked, no problems found.
3861
+ No spec.config.yaml here, so no specs were checked. Run \`specdx init\` to add a spec suite.
3862
+ `;
3863
+ }
3864
+ const parts = [`${results.specFiles} ${results.specFiles === 1 ? "spec" : "specs"}`];
3865
+ if (results.agentFiles > 0) parts.push(agentPart);
3866
+ return ` \u2713 ${parts.join(" and ")} checked, no problems found.
3867
+ `;
3435
3868
  }
3436
3869
  var lint_default = defineCommand2({
3437
3870
  meta: { name: "lint", description: "Lint all specs in the suite" },
@@ -3461,15 +3894,19 @@ var lint_default = defineCommand2({
3461
3894
  preset: args.preset
3462
3895
  });
3463
3896
  const formatter = format.format === "json" ? formatJson : format.format === "github" ? formatGithub : formatPretty;
3464
- if (!results.assessed) {
3897
+ if (!results.assessed && results.specSuite) {
3465
3898
  console.error(
3466
- "\n \u26A0 No specs were linted. Check the spec paths in spec.config.yaml, and whether `lint.ignore` excludes them all.\n"
3899
+ args.path ? `
3900
+ \u26A0 No specs matched path "${args.path}", so nothing was linted. Check it against the specs declared in spec.config.yaml.
3901
+ ` : "\n \u26A0 No specs were linted. Check the spec paths in spec.config.yaml, and whether `lint.ignore` excludes them all.\n"
3467
3902
  );
3468
3903
  process.exit(3);
3469
3904
  }
3470
- const rendered = formatter(results.diagnostics);
3905
+ const rendered = formatter(
3906
+ results.specSuite ? results.diagnostics : [noSpecSuiteNotice(process.cwd()), ...results.diagnostics]
3907
+ );
3471
3908
  if (format.format === "pretty" && results.diagnostics.length === 0) {
3472
- output.info(rendered);
3909
+ output.info(cleanRunMessage(results));
3473
3910
  } else {
3474
3911
  output.out(rendered);
3475
3912
  }
@@ -4340,7 +4777,7 @@ var pack_default = defineCommand3({
4340
4777
 
4341
4778
  // src/commands/core/diff.ts
4342
4779
  import { defineCommand as defineCommand4 } from "citty";
4343
- import { join as join5 } from "path";
4780
+ import { join as join6 } from "path";
4344
4781
 
4345
4782
  // ../diff/dist/types.js
4346
4783
  var DEFAULT_DIFF_CONFIG = {
@@ -4528,7 +4965,7 @@ Diff.prototype = {
4528
4965
  tokenize: function tokenize2(value) {
4529
4966
  return Array.from(value);
4530
4967
  },
4531
- join: function join4(chars) {
4968
+ join: function join5(chars) {
4532
4969
  return chars.join("");
4533
4970
  },
4534
4971
  postProcess: function postProcess(changeObjects) {
@@ -5346,7 +5783,7 @@ function checkCrossReferences(allSpecs, removedIds) {
5346
5783
  var import_picomatch = __toESM(require_picomatch2(), 1);
5347
5784
  import { execSync as execSync2 } from "child_process";
5348
5785
  import { readFileSync, realpathSync } from "fs";
5349
- import { dirname as dirname2, relative, resolve as resolve4, sep } from "path";
5786
+ import { dirname as dirname2, relative as relative2, resolve as resolve4, sep as sep2 } from "path";
5350
5787
  function getRepoRoot(cwd) {
5351
5788
  let root;
5352
5789
  try {
@@ -5368,7 +5805,7 @@ function validateRef(ref, cwd) {
5368
5805
  }
5369
5806
  }
5370
5807
  function gitShow(ref, filePath, projectRoot, repoRoot) {
5371
- const relPath = relative(repoRoot, resolve4(projectRoot, filePath));
5808
+ const relPath = relative2(repoRoot, resolve4(projectRoot, filePath));
5372
5809
  try {
5373
5810
  return execSync2(`git show ${ref}:${relPath}`, {
5374
5811
  cwd: repoRoot,
@@ -5380,12 +5817,12 @@ function gitShow(ref, filePath, projectRoot, repoRoot) {
5380
5817
  }
5381
5818
  }
5382
5819
  function toPosix(p) {
5383
- return sep === "/" ? p : p.split(sep).join("/");
5820
+ return sep2 === "/" ? p : p.split(sep2).join("/");
5384
5821
  }
5385
5822
  function buildEntryMatchers(specPathsByKey, projectRoot, repoRoot) {
5386
5823
  return [...specPathsByKey].map(([key, specPath]) => ({
5387
5824
  key,
5388
- isMatch: (0, import_picomatch.default)(toPosix(relative(repoRoot, resolve4(projectRoot, specPath))))
5825
+ isMatch: (0, import_picomatch.default)(toPosix(relative2(repoRoot, resolve4(projectRoot, specPath))))
5389
5826
  }));
5390
5827
  }
5391
5828
  function getChangedSpecFiles(baseRef, headRef, matchers, projectRoot, repoRoot) {
@@ -5412,7 +5849,7 @@ function getChangedSpecFiles(baseRef, headRef, matchers, projectRoot, repoRoot)
5412
5849
  if (!entry)
5413
5850
  continue;
5414
5851
  const changed = {
5415
- path: relative(projectRoot, resolve4(repoRoot, filePath)),
5852
+ path: relative2(projectRoot, resolve4(repoRoot, filePath)),
5416
5853
  entryKey: entry.key
5417
5854
  };
5418
5855
  if (status === "M") {
@@ -5443,7 +5880,7 @@ function listSpecFilesAtRef(ref, matchers, projectRoot, repoRoot) {
5443
5880
  const entry = matchers.find((m) => m.isMatch(filePath));
5444
5881
  if (!entry)
5445
5882
  continue;
5446
- byEntry.get(entry.key)?.push(relative(projectRoot, resolve4(repoRoot, filePath)));
5883
+ byEntry.get(entry.key)?.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
5447
5884
  }
5448
5885
  return byEntry;
5449
5886
  }
@@ -5465,7 +5902,7 @@ function listSpecFilesInWorktree(matchers, projectRoot, repoRoot) {
5465
5902
  const entry = matchers.find((m) => m.isMatch(filePath));
5466
5903
  if (!entry)
5467
5904
  continue;
5468
- byEntry.get(entry.key)?.push(relative(projectRoot, resolve4(repoRoot, filePath)));
5905
+ byEntry.get(entry.key)?.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
5469
5906
  }
5470
5907
  return byEntry;
5471
5908
  }
@@ -5508,7 +5945,7 @@ function getChangedSpecFilesInWorktree(baseRef, matchers, projectRoot, repoRoot)
5508
5945
  return;
5509
5946
  seen.add(filePath);
5510
5947
  const changed = {
5511
- path: relative(projectRoot, resolve4(repoRoot, filePath)),
5948
+ path: relative2(projectRoot, resolve4(repoRoot, filePath)),
5512
5949
  entryKey: entry.key
5513
5950
  };
5514
5951
  if (status === "M")
@@ -5565,7 +6002,7 @@ function listUncommittedSpecFiles(matchers, projectRoot, repoRoot) {
5565
6002
  const filePath = (renamed ?? rawPath).replace(/^"|"$/g, "");
5566
6003
  if (!matchers.some((m) => m.isMatch(filePath)))
5567
6004
  continue;
5568
- files.push(relative(projectRoot, resolve4(repoRoot, filePath)));
6005
+ files.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
5569
6006
  }
5570
6007
  return files;
5571
6008
  }
@@ -5708,7 +6145,7 @@ async function runDiff(options) {
5708
6145
  const config = await loadConfig(void 0, configDir);
5709
6146
  const baseRef = options.base ?? config.diff?.baseline_ref ?? DEFAULT_DIFF_CONFIG.baseline_ref;
5710
6147
  const headRef = options.head ?? "HEAD";
5711
- const configPath = join5(configDir, "spec.config.yaml");
6148
+ const configPath = join6(configDir, "spec.config.yaml");
5712
6149
  const result = await diffBetweenRefs(configPath, baseRef, headRef, {
5713
6150
  working: options.working ?? false
5714
6151
  });