@ybotok/loam 0.2.0-alpha.1 → 0.2.0-alpha.4

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 (92) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/README.md +6 -6
  3. package/ROADMAP.md +155 -18
  4. package/SCHEMA.md +33 -1
  5. package/dist/commands/archive/plan/gate.js +18 -12
  6. package/dist/commands/archive/plan/gate.js.map +1 -1
  7. package/dist/commands/archive/plan/landscape.js +19 -0
  8. package/dist/commands/archive/plan/landscape.js.map +1 -1
  9. package/dist/commands/archive/run.js +48 -3
  10. package/dist/commands/archive/run.js.map +1 -1
  11. package/dist/commands/seed/plan.js +1 -1
  12. package/dist/commands/seed/plan.js.map +1 -1
  13. package/dist/commands/subsystem/sync.js +1 -1
  14. package/dist/commands/subsystem/sync.js.map +1 -1
  15. package/dist/commands/subsystem/txn/txn.js +1 -1
  16. package/dist/commands/subsystem/txn/txn.js.map +1 -1
  17. package/dist/commands/subsystem/txn/views.js +23 -11
  18. package/dist/commands/subsystem/txn/views.js.map +1 -1
  19. package/dist/commands/validate/arch-coverage.js +11 -1
  20. package/dist/commands/validate/arch-coverage.js.map +1 -1
  21. package/dist/commands/validate/fleet/obligations.js +43 -9
  22. package/dist/commands/validate/fleet/obligations.js.map +1 -1
  23. package/dist/commands/validate/fleet/usecases/steps.js +3 -3
  24. package/dist/commands/validate/fleet/usecases/steps.js.map +1 -1
  25. package/dist/commands/validate/fleet/views/ids.js +6 -1
  26. package/dist/commands/validate/fleet/views/ids.js.map +1 -1
  27. package/dist/commands/validate/fleet/views/stale.js +15 -39
  28. package/dist/commands/validate/fleet/views/stale.js.map +1 -1
  29. package/dist/commands/validate/service/service.js +1 -0
  30. package/dist/commands/validate/service/service.js.map +1 -1
  31. package/dist/commands/validate/service/specs.js +33 -1
  32. package/dist/commands/validate/service/specs.js.map +1 -1
  33. package/dist/core/agent/agents-md/map/subsystem.js +8 -1
  34. package/dist/core/agent/agents-md/map/subsystem.js.map +1 -1
  35. package/dist/core/agent/agents-md.js +4 -0
  36. package/dist/core/agent/agents-md.js.map +1 -1
  37. package/dist/core/agent/workflows/check.js +3 -0
  38. package/dist/core/agent/workflows/check.js.map +1 -1
  39. package/dist/core/brief/unchecked.js +1 -0
  40. package/dist/core/brief/unchecked.js.map +1 -1
  41. package/dist/core/c4/arch.js +72 -180
  42. package/dist/core/c4/arch.js.map +1 -1
  43. package/dist/core/c4/likec4.js +2 -0
  44. package/dist/core/c4/likec4.js.map +1 -1
  45. package/dist/core/c4/parsed/deployment.js +158 -0
  46. package/dist/core/c4/parsed/deployment.js.map +1 -0
  47. package/dist/core/c4/project/load.js +4 -0
  48. package/dist/core/c4/project/load.js.map +1 -1
  49. package/dist/core/c4/project/staged.js +220 -0
  50. package/dist/core/c4/project/staged.js.map +1 -0
  51. package/dist/core/c4/resolve/service.js +46 -0
  52. package/dist/core/c4/resolve/service.js.map +1 -1
  53. package/dist/core/c4/resolve/steps.js +144 -0
  54. package/dist/core/c4/resolve/steps.js.map +1 -0
  55. package/dist/core/c4/splice/delta-blocks.js +15 -2
  56. package/dist/core/c4/splice/delta-blocks.js.map +1 -1
  57. package/dist/core/c4/workspace.js +2 -0
  58. package/dist/core/c4/workspace.js.map +1 -1
  59. package/dist/core/coherence/coherence.js +36 -0
  60. package/dist/core/coherence/coherence.js.map +1 -1
  61. package/dist/core/deployment/delta.js +188 -0
  62. package/dist/core/deployment/delta.js.map +1 -0
  63. package/dist/core/deployment/objects.js +145 -0
  64. package/dist/core/deployment/objects.js.map +1 -0
  65. package/dist/core/pack/living.js +19 -0
  66. package/dist/core/pack/living.js.map +1 -1
  67. package/dist/core/repo/authored/paths.js +18 -0
  68. package/dist/core/repo/authored/paths.js.map +1 -1
  69. package/dist/core/repo/paths.js +44 -3
  70. package/dist/core/repo/paths.js.map +1 -1
  71. package/dist/core/repo/tree/render/body.js +219 -0
  72. package/dist/core/repo/tree/render/body.js.map +1 -0
  73. package/dist/core/repo/tree/render/stale.js +26 -0
  74. package/dist/core/repo/tree/render/stale.js.map +1 -0
  75. package/dist/core/repo/tree/render/text.js +84 -0
  76. package/dist/core/repo/tree/render/text.js.map +1 -0
  77. package/dist/core/repo/tree/{views.js → render/views.js} +38 -34
  78. package/dist/core/repo/tree/render/views.js.map +1 -0
  79. package/dist/core/status/feature/artifacts.js +29 -4
  80. package/dist/core/status/feature/artifacts.js.map +1 -1
  81. package/dist/core/status/fleet/fleet.js +11 -1
  82. package/dist/core/status/fleet/fleet.js.map +1 -1
  83. package/dist/core/usecases/delta/overlay.js +28 -191
  84. package/dist/core/usecases/delta/overlay.js.map +1 -1
  85. package/dist/core/usecases/fleet.js.map +1 -1
  86. package/dist/core/usecases/operations.js +2 -2
  87. package/dist/core/usecases/operations.js.map +1 -1
  88. package/dist/core/vocabulary/issue.js +3 -0
  89. package/dist/core/vocabulary/issue.js.map +1 -1
  90. package/examples/docs/architecture/subsystems.likec4 +4 -0
  91. package/package.json +1 -1
  92. package/dist/core/repo/tree/views.js.map +0 -1
@@ -12,6 +12,13 @@
12
12
  * the LikeC4 renderer, which merges the whole `architecture/` project per
13
13
  * likec4.config.json, resolves it.
14
14
  *
15
+ * Each view opens with the LABEL a human reads — `title`, and `description`
16
+ * when the marker carries one — because this file exists only to be rendered
17
+ * and an unlabelled view is shown by its id, which is hex-escaped for
18
+ * injectivity and reads as `subsystem_platform__order_2dflow`. Both
19
+ * strings are somebody else's words and go through `likec4String`, which
20
+ * records what a raw one does.
21
+ *
15
22
  * The output is deterministic and line-oriented, and both halves are the
16
23
  * contract: subsystems sorted by path, members sorted by id, ONE `include`
17
24
  * per line — so two concurrent moves into different groups touch different
@@ -40,9 +47,9 @@
40
47
  * the committed landscape resolves keeps the output a function of committed
41
48
  * bytes alone.
42
49
  */
43
- import {} from "../../c4/likec4.js";
44
- import { serviceResolver } from "../../c4/resolve/service.js";
45
- import { servicesUnder } from "./find.js";
50
+ import {} from "../../../c4/likec4.js";
51
+ import { renderContext, viewBody } from "./body.js";
52
+ import { likec4String, viewTitle } from "./text.js";
46
53
  /**
47
54
  * The header every generated file opens with — stable bytes, part of the
48
55
  * byte-compare contract, naming the regenerator so a reader who found the
@@ -50,7 +57,8 @@ import { servicesUnder } from "./find.js";
50
57
  */
51
58
  const HEADER = "// generated by loam — the subsystem tree under services/, one view per subsystem.\n" +
52
59
  "// Do not edit: `loam subsystem sync` regenerates this file from the directories,\n" +
53
- "// and `loam validate --all` reports `subsystem.views-stale` when it drifts.\n";
60
+ "// and `loam validate --all` reports `subsystem.views-stale` when it drifts.\n" +
61
+ "// A scoping aid, not the fleet's architecture: author your own diagrams elsewhere.\n";
54
62
  /**
55
63
  * Render the views file for a walked tree, or null when the tree has no
56
64
  * subsystems — the file must then be ABSENT, so a flat fleet never carries a
@@ -59,50 +67,46 @@ const HEADER = "// generated by loam — the subsystem tree under services/, one
59
67
  export function renderSubsystemViews(tree, elements) {
60
68
  if (tree.subsystems.length === 0)
61
69
  return null;
62
- const elementOf = elementByService(tree, elements);
70
+ const ctx = renderContext(tree, elements);
63
71
  const lines = [HEADER, "views {"];
64
72
  const subsystems = [...tree.subsystems].sort((a, b) => (pathKey(a) < pathKey(b) ? -1 : 1));
65
73
  for (const [i, sub] of subsystems.entries()) {
66
74
  if (i > 0)
67
75
  lines.push("");
68
76
  lines.push(` // services/${pathKey(sub)}`);
77
+ const body = viewBody(ctx, sub);
78
+ if (body.disclosure !== null)
79
+ lines.push(` // ${body.disclosure}`);
69
80
  lines.push(` view ${subsystemViewId(sub)} {`);
70
- for (const member of membersOf(tree, sub)) {
71
- const element = elementOf.get(member.id);
72
- if (element !== undefined)
73
- lines.push(` include ${element}`);
74
- }
81
+ // Metadata FIRST, and that ordering is a hard constraint rather than a
82
+ // taste: measured, an `include` OR a `group { … }` line followed by
83
+ // `title` is a parse error ("Expecting token of type '}' but found
84
+ // `title`"), and one parse error in this file blanks the whole
85
+ // `architecture/` project in the renderer.
86
+ lines.push(` title '${viewTitle(titleChain(tree, sub))}'`);
87
+ const description = likec4String(sub.meta.description ?? "");
88
+ if (description !== "")
89
+ lines.push(` description '${description}'`);
90
+ lines.push(...body.lines);
75
91
  lines.push(" }");
76
92
  }
77
93
  lines.push("}");
78
94
  return lines.join("\n") + "\n";
79
95
  }
80
96
  /**
81
- * The landscape element standing for each service id: for every element,
82
- * resolve it through the shared join, and let the SHALLOWEST element win
83
- * (document order breaking ties). Shallowest, because `serviceResolver`
84
- * resolves a service's own containers to the service too, and a view should
85
- * include the service-level box, not whichever nested container happened to
86
- * be declared first.
97
+ * This subsystem and every MARKED ancestor above it, outermost first — the
98
+ * chain `viewTitle` composes a path out of.
99
+ *
100
+ * Marked, because an intermediate directory holding no `subsystem.yaml` is
101
+ * `subsystem.unmarked`, an error the walk already names: it is not a group,
102
+ * so it contributes no folder level here either. Read off the walked tree
103
+ * rather than off the path segments, so what the title says and what the
104
+ * finding says about the same directory cannot disagree.
87
105
  */
88
- function elementByService(tree, elements) {
89
- const known = new Set(tree.services.map((s) => s.id));
90
- const resolve = serviceResolver(elements, known);
91
- const depth = (id) => id.split(".").length;
92
- const out = new Map();
93
- for (const e of elements) {
94
- const service = resolve(e.id);
95
- if (!known.has(service))
96
- continue;
97
- const held = out.get(service);
98
- if (held === undefined || depth(e.id) < depth(held))
99
- out.set(service, e.id);
100
- }
101
- return out;
102
- }
103
- /** Services beneath this subsystem at any depth, ordered by id — the transitive membership. */
104
- function membersOf(tree, sub) {
105
- return [...servicesUnder(tree, sub)].sort((a, b) => (a.id < b.id ? -1 : 1));
106
+ function titleChain(tree, sub) {
107
+ return tree.subsystems
108
+ .filter((s) => s.path.length <= sub.path.length && s.path.every((name, i) => sub.path[i] === name))
109
+ .sort((a, b) => a.path.length - b.path.length);
106
110
  }
107
111
  /** The sort key and the comment spelling: the subsystem's path from services/, joined. */
108
112
  function pathKey(sub) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.js","sourceRoot":"","sources":["../../../../../src/core/repo/tree/render/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CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,0FAA0F;AAC1F,SAAS,OAAO,CAAC,GAAmB;IAClC,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAElD,MAAM,UAAU,eAAe,CAAC,GAAmB;IACjD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACvC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzH,OAAO,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,UAAU,CAAC,MAAqB,EAAE,QAAuB;IACvE,MAAM,EAAE,GAAG,CAAC,IAAmB,EAAiB,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3G,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/**\n * The generated views file: `architecture/subsystems.likec4`, one LikeC4 view\n * per subsystem enumerating the services beneath it. GENERATED, never\n * authored — authored bytes stay authored (archive's verbatim-splice promise),\n * so the tree is mirrored into a file of its own that `loam subsystem sync`\n * owns outright, and staleness against the tree is a byte compare\n * (`subsystem.views-stale` in `validate --all`), never a parse: a spike\n * confirmed a views-only document does NOT parse standalone (its `include`\n * lines reference elements the landscape defines), so nothing in loam ever\n * loads this file (and rule 26 does not change that: this file is GENERATED and\n * holds STATIC views, whose contents loam may not read in any document) — only\n * the LikeC4 renderer, which merges the whole `architecture/` project per\n * likec4.config.json, resolves it.\n *\n * Each view opens with the LABEL a human reads — `title`, and `description`\n * when the marker carries one — because this file exists only to be rendered\n * and an unlabelled view is shown by its id, which is hex-escaped for\n * injectivity and reads as `subsystem_platform__order_2dflow`. Both\n * strings are somebody else's words and go through `likec4String`, which\n * records what a raw one does.\n *\n * The output is deterministic and line-oriented, and both halves are the\n * contract: subsystems sorted by path, members sorted by id, ONE `include`\n * per line — so two concurrent moves into different groups touch different\n * lines and git merges the file without intervention, exactly as the\n * service-grouped landscape splice already achieves. Byte-reproducible on any\n * machine: no timestamps, no absolute paths, no readdir-order dependence (the\n * walk sorts, and every list is re-sorted here). Plain lexicographic sorts on\n * purpose — the ids' own grammar is ASCII, an INVALID name is still ordered\n * deterministically, and `compareIds`' numeric tokenizing lives in `repo/`,\n * which this package must not import (`walk.ts` says why the edge only points\n * the other way).\n *\n * Membership is TRANSITIVE: a subsystem's view includes every service beneath\n * it at any depth, so a parent's view is the whole group's map rather than an\n * empty frame around its children. An empty view body is legal LikeC4 (same\n * spike), so an empty subsystem renders as one — `subsystem new` must be\n * usable before anything moves in.\n *\n * Include lines name the landscape ELEMENT id, resolved through the same\n * element→service join `validate` uses (`serviceResolver`: explicit\n * `metadata { service }` binding first, then a title naming a real service) —\n * because element ids in real landscapes are not service ids, and a view of\n * raw service ids would silently render empty for every such fleet. A member\n * with no landscape element is omitted from the includes: the omission is\n * already an error (`landscape.service-unmodelled`), and rendering only what\n * the committed landscape resolves keeps the output a function of committed\n * bytes alone.\n */\nimport { type Elem } from \"../../../c4/likec4.js\";\nimport { renderContext, viewBody } from \"./body.js\";\nimport { likec4String, viewTitle } from \"./text.js\";\nimport type { FleetTree, SubsystemEntry } from \"../walk.js\";\n\n/**\n * The header every generated file opens with — stable bytes, part of the\n * byte-compare contract, naming the regenerator so a reader who found the\n * file first knows what owns it.\n */\nconst HEADER =\n \"// generated by loam — the subsystem tree under services/, one view per subsystem.\\n\" +\n \"// Do not edit: `loam subsystem sync` regenerates this file from the directories,\\n\" +\n \"// and `loam validate --all` reports `subsystem.views-stale` when it drifts.\\n\" +\n \"// A scoping aid, not the fleet's architecture: author your own diagrams elsewhere.\\n\";\n\n/**\n * Render the views file for a walked tree, or null when the tree has no\n * subsystems — the file must then be ABSENT, so a flat fleet never carries a\n * generated artifact that says nothing.\n */\nexport function renderSubsystemViews(tree: FleetTree, elements: Elem[]): string | null {\n if (tree.subsystems.length === 0) return null;\n const ctx = renderContext(tree, elements);\n const lines: string[] = [HEADER, \"views {\"];\n const subsystems = [...tree.subsystems].sort((a, b) => (pathKey(a) < pathKey(b) ? -1 : 1));\n for (const [i, sub] of subsystems.entries()) {\n if (i > 0) lines.push(\"\");\n lines.push(` // services/${pathKey(sub)}`);\n const body = viewBody(ctx, sub);\n if (body.disclosure !== null) lines.push(` // ${body.disclosure}`);\n lines.push(` view ${subsystemViewId(sub)} {`);\n // Metadata FIRST, and that ordering is a hard constraint rather than a\n // taste: measured, an `include` OR a `group { … }` line followed by\n // `title` is a parse error (\"Expecting token of type '}' but found\n // `title`\"), and one parse error in this file blanks the whole\n // `architecture/` project in the renderer.\n lines.push(` title '${viewTitle(titleChain(tree, sub))}'`);\n const description = likec4String(sub.meta.description ?? \"\");\n if (description !== \"\") lines.push(` description '${description}'`);\n lines.push(...body.lines);\n lines.push(\" }\");\n }\n lines.push(\"}\");\n return lines.join(\"\\n\") + \"\\n\";\n}\n\n/**\n * This subsystem and every MARKED ancestor above it, outermost first — the\n * chain `viewTitle` composes a path out of.\n *\n * Marked, because an intermediate directory holding no `subsystem.yaml` is\n * `subsystem.unmarked`, an error the walk already names: it is not a group,\n * so it contributes no folder level here either. Read off the walked tree\n * rather than off the path segments, so what the title says and what the\n * finding says about the same directory cannot disagree.\n */\nfunction titleChain(tree: FleetTree, sub: SubsystemEntry): SubsystemEntry[] {\n return tree.subsystems\n .filter((s) => s.path.length <= sub.path.length && s.path.every((name, i) => sub.path[i] === name))\n .sort((a, b) => a.path.length - b.path.length);\n}\n\n/** The sort key and the comment spelling: the subsystem's path from services/, joined. */\nfunction pathKey(sub: SubsystemEntry): string {\n return sub.path.join(\"/\");\n}\n\n/**\n * A LikeC4 identifier for the view, derived from the subsystem's path so\n * nesting reads in the name — and INJECTIVE over every path the name grammar\n * admits, because the renderer refuses the whole `architecture/` project over\n * a duplicate view id. The naive folding (every non-identifier byte and the\n * join separator alike becoming `_`) collided three DISTINCT healthy names\n * onto one identifier — `a_b`, and `b` under `a`, both rendered\n * `subsystem_a_b` — so `validate --all` was green while the renderer refused\n * the fleet map; `subsystem.name-collision` never fires because the flat\n * namespace really is intact. Hence the encoding: an identifier byte\n * (`[A-Za-z0-9]`) passes through, any other byte becomes `_` + two lowercase\n * hex digits (`.` → `_2e`, `-` → `_2d`, `_` itself → `_5f` — the underscore\n * must be escaped precisely because it is BOTH legal in a name and the\n * separator), and segments join on `__`. Underscore runs then decode\n * uniquely — one is an escape, two a separator, three a separator followed\n * by an escape — so no two distinct legal paths share an identifier. A name\n * `subsystem.name-invalid` already flagged may hold a code point above 0xff\n * whose longer hex could in principle re-collide; it is deterministic still,\n * and that directory is already an error finding by name.\n *\n * EXPORTED, with its prefix, because `subsystem.view-id-collision` has to ask\n * the generator what it mints rather than re-deriving it. A check carrying its\n * own copy of the escaping above would go quiet the day the encoding changed,\n * and going quiet is the failure this whole family exists to prevent.\n */\nexport const SUBSYSTEM_VIEW_PREFIX = \"subsystem_\";\n\nexport function subsystemViewId(sub: SubsystemEntry): string {\n const segment = (name: string): string =>\n [...name].map((ch) => (/[A-Za-z0-9]/.test(ch) ? ch : `_${ch.codePointAt(0)!.toString(16).padStart(2, \"0\")}`)).join(\"\");\n return `subsystem_${sub.path.map(segment).join(\"__\")}`;\n}\n\n/**\n * Does the file on disk already SAY what `renderSubsystemViews` renders?\n *\n * The generator above only ever emits LF. `core.autocrlf=true` is Git for\n * Windows' installer default and a docs repo ships no `.gitattributes`, so an\n * ordinary Windows clone hands the file back with CRLF and not one fact\n * changed. Four call sites asked this question with a byte equality and all\n * four answered \"stale\" on such a clone: `loam validate` reported an error,\n * `loam subsystem sync` reported `updated` and rewrote with LF, git then showed\n * the file permanently modified, and the next checkout restored the CRLF. That\n * is a loop rather than a diagnosis, which is why the comparison lives here\n * now — the module that mints the bytes is the one that owes an answer about\n * them, and three near-copies of this rule would go stale one at a time.\n *\n * Still never a parse: a views-only document does not parse standalone, and no\n * check anywhere reads this file's content. The narrowing is from BYTES to\n * CONTENT, which is what `subsystem.views-stale`'s own message (\"does not match\n * the tree\") already claims. The symmetric cost is accepted and is the one\n * `core/verify/pins/pin.ts` documents for `pinnedDigest`: a pure line-ending\n * change is invisible, correctly, because it is not a change to what the file\n * says.\n *\n * `null` is carried through as itself rather than collapsing into `\"\"`: absent,\n * must-be-absent and present-but-different are three distinct states with three\n * distinct messages, and a fleet whose views file does not exist is not a fleet\n * whose views file is blank.\n */\nexport function viewsAgree(actual: string | null, expected: string | null): boolean {\n const lf = (text: string | null): string | null => (text === null ? null : text.replace(/\\r\\n|\\r/g, \"\\n\"));\n return lf(actual) === lf(expected);\n}\n"]}
@@ -127,8 +127,25 @@ export function featureArtifacts(docsDir, feature, services, grading) {
127
127
  for (const svc of services) {
128
128
  const p = featureSpecPaths(feature.dir, svc);
129
129
  const specFault = faulted("spec", svc);
130
- out.push(fileState("spec", { service: svc, path: rel(p.spec), exists: existsSync(p.spec) }, true, specFault));
131
- out.push(fileState("arch-spec", { service: svc, path: rel(p.archSpec), exists: existsSync(p.archSpec) }, false, specFault));
130
+ // What a service delta owes is a REQUIREMENT DELTA, not specifically the
131
+ // business one. `arch.spec.md` is the other corpus, with the same grammar
132
+ // and the same delta algebra, and `featureChecklist` derives claims from
133
+ // it — so a directory holding only the architectural document is a
134
+ // complete delta, and every gate already reads it as one: `coherence`'s
135
+ // `service.no-requirement-delta` counts the DIRECTORY, and
136
+ // `validate --feature` grades an arch-only delta clean at exit 0.
137
+ //
138
+ // Requiring `spec.md` unconditionally made this module the one document
139
+ // that disagreed. An architecture-only feature — an outbox added, a retry
140
+ // policy, an alert; the changes `arch.spec.md` exists for because no
141
+ // business scenario was ever going to carry them — reported `missing` and
142
+ // emitted `next.author-spec`, sending the author to write business
143
+ // requirements the change does not have, about a feature the gate accepts.
144
+ // status may be redder than the gates on a question they also ask; it may
145
+ // not invent an obligation they do not.
146
+ const archExists = existsSync(p.archSpec);
147
+ out.push(fileState("spec", { service: svc, path: rel(p.spec), exists: existsSync(p.spec) }, !archExists, specFault));
148
+ out.push(fileState("arch-spec", { service: svc, path: rel(p.archSpec), exists: archExists }, false, specFault));
132
149
  out.push(fileState("openapi", { service: svc, path: rel(p.openapi), exists: existsSync(p.openapi) }, owesContract(living.get(svc), contracted.has(svc), governs.has(svc)), faulted("openapi", svc)));
133
150
  // Never required: an event contract is genuinely optional — the axis's own
134
151
  // absence-grading rests on that — so absence is `done`, exactly like
@@ -145,7 +162,15 @@ export function featureArtifacts(docsDir, feature, services, grading) {
145
162
  // promise is realized by service requirements, and those are what the record
146
163
  // answers — so counting one as a feeder would report a capability-only
147
164
  // feature as ready to verify against a checklist with nothing in it.
148
- const feeders = out.filter((a) => a.id !== "intent" && a.id !== "arch-spec" && a.id !== "capabilities" && a.exists);
165
+ //
166
+ // `arch-spec` used to be excluded beside it, and that failed the same test
167
+ // the comment above states: `featureChecklist` DOES read `arch.spec.md`
168
+ // (`core/verify/checklist.ts`), and `loam verify` on an architecture-only
169
+ // feature returns a real checklist. The row said `blocked … needs delta,
170
+ // spec, openapi, asyncapi` and `next.verify` said there was nothing to derive
171
+ // a checklist from, about a command that derives one — which is the failure
172
+ // `blocked` is supposed to prevent, pointed the wrong way.
173
+ const feeders = out.filter((a) => a.id !== "intent" && a.id !== "capabilities" && a.exists);
149
174
  out.push({
150
175
  id: "verification",
151
176
  service: null,
@@ -153,7 +178,7 @@ export function featureArtifacts(docsDir, feature, services, grading) {
153
178
  exists: verification.state !== "absent",
154
179
  required: true,
155
180
  status: feeders.length === 0 ? "blocked" : verificationStatus(verification),
156
- blockedBy: feeders.length === 0 ? ["delta", "spec", "openapi", "asyncapi"] : [],
181
+ blockedBy: feeders.length === 0 ? ["delta", "spec", "arch-spec", "openapi", "asyncapi"] : [],
157
182
  });
158
183
  return out;
159
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../../../src/core/status/feature/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIlD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IACxC,qCAAqC;IACrC,uCAAuC;IACvC,mCAAmC;IACnC,sBAAsB;IACtB,wCAAwC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,OAAgB;IACrD,IAAI,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,sBAAsB;QAAE,OAAO,OAAO,CAAC;IAChF,IAAI,IAAI,CAAC,UAAU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,OAAO,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,EAAE,YAAY,CAAC,KAAK,KAAK,QAAQ;QACvC,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC;QAC3E,SAAS,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;KAChF,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AASD,SAAS,SAAS,CAAC,EAAc,EAAE,IAAe,EAAE,QAAiB,EAAE,OAAgB;IACrF,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,MAAM,MAAM,GAAmB,CAAC,MAAM;QACpC,CAAC,CAAC,QAAQ;YACR,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM;QACV,CAAC,CAAC,OAAO;YACP,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,MAAM,CAAC;IACb,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AACxE,CAAC","sourcesContent":["/**\n * The artifact table: which files a feature owes, whether each is on disk, and\n * which finding turns a row `draft`. Nothing is graded here — the shared\n * checks already ran, and this module only attributes what they reported to\n * the file a reader should edit.\n */\nimport { existsSync } from \"node:fs\";\nimport { repoPath } from \"../../envelope/json.js\";\nimport type { CapabilityDoc } from \"../../capabilities/tree.js\";\nimport type { PathableService } from \"../../kernel/ids/service.js\";\nimport type { FeatureEntry } from \"../../repo/entries.js\";\nimport { featurePaths, featureSpecPaths } from \"../../repo/paths.js\";\nimport { verificationPath } from \"../../verify/record.js\";\nimport type { Finding } from \"../../vocabulary/report.js\";\nimport { owesContract } from \"../contracts.js\";\nimport type { ServiceEntry } from \"../../repo/entries.js\";\nimport type { ArtifactId, ArtifactState, ArtifactStatus, VerificationState } from \"../report.js\";\nimport { verificationStatus } from \"../verification.js\";\nimport type { DocsDir } from \"../../kernel/ids/dirs.js\";\n\n/**\n * The `capability.*` codes filed against a capability DOCUMENT rather than\n * against a service requirement's join line. Spelled out rather than matched by\n * prefix because the family straddles both corpora, and the whole point of this\n * table is to name one file.\n */\nconst CAPABILITY_DOCUMENT_CODES = new Set([\n \"capability.requirement-unidentified\",\n \"capability.requirement-service-scoped\",\n \"capability.requirement-inert-join\",\n \"capability.uncovered\",\n \"capability.remove-requirement-realized\",\n]);\n\n/**\n * Which artifact an error names.\n *\n * Attribution is by code family, because that is the only machine-readable\n * pointer an `Issue` carries: `subject` narrows to a NAME, never to a file.\n * The families are unambiguous — `c4-api.*`/`c4-event.*`/`c4.*` and the two\n * `delta.*` codes about the LikeC4 document itself grade the architecture\n * axis, `openapi.*` grades the API contract, `asyncapi.*` the event contract,\n * and the remaining `delta.*` codes plus `spec-api.*`/`spec-event.*` are the\n * delta-shape checks, every one of which is about a requirement in a spec\n * delta.\n *\n * An error that maps to nothing (or whose subject is unknown) still lands in\n * `checks.issues` and still drives `next.fix-coherence` — it just does not turn\n * any single artifact `draft`, because guessing which file to blame is how a\n * reader gets sent to edit the wrong one.\n *\n * THE BUSINESS CORPUS IS THE ONE PLACE THE CODE FAMILY IS NOT ENOUGH. A\n * `delta.*` issue's `subject` is a service id OR a capability id\n * (`core/delta/scope.ts`), and so is a `scaffold.placeholder`'s\n * (`core/coherence/authoring/scaffold.ts` files one per unedited capability\n * delta), and nothing in either code says which — so this\n * function answers `spec` for both and `featureArtifacts` below resolves it by\n * MEMBERSHIP, against the two lists it already holds. Where a name is only a\n * capability the capability row is turned `draft` and no service row is; where\n * a fleet holds a service AND a capability of the same name, BOTH are, which is\n * the pessimistic answer this module is required to give and strictly better\n * than the old one (it named the service's spec delta and was silently wrong).\n * The capability-document codes below need no such resolution: they are only\n * ever filed against a capability.\n */\nfunction faultedArtifact(code: string, subject?: string): ArtifactId | null {\n if (code === \"delta.invalid\" || code === \"delta.nothing-tagged\") return \"delta\";\n if (code.startsWith(\"c4-api.\") || code.startsWith(\"c4-event.\") || code.startsWith(\"c4.\")) return \"delta\";\n if (code.startsWith(\"openapi.\")) return \"openapi\";\n if (code.startsWith(\"asyncapi.\")) return \"asyncapi\";\n // The capability document's own grades, and the two halves of the `Realizes:`\n // join a feature can break — every one of them names a\n // `features/<FEAT>/capabilities/<id>/spec.md`, never a service delta. The two\n // `capability.*` codes deliberately absent are `capability.unknown` and\n // `capability.realizes-unknown`: those grade a SERVICE requirement's join\n // lines and carry a service id, so the prefix alone would send their reader\n // to the wrong file.\n if (CAPABILITY_DOCUMENT_CODES.has(code)) return \"capabilities\";\n if (code.startsWith(\"delta.\") || code.startsWith(\"spec-api.\") || code.startsWith(\"spec-event.\")) return \"spec\";\n // The two families validate contributes: the frontmatter checks read only\n // intent.md, and a requirement with no scenario is a requirement in a spec\n // delta. Both name exactly one file, so both may turn a row `draft`.\n if (code.startsWith(\"frontmatter.\")) return \"intent\";\n if (code === \"requirements.missing-scenarios\") return \"spec\";\n // The authoring gate names exactly one file per finding too — leaving these\n // unmapped had the table calling intent.md `done` (\"nothing is owed here\")\n // while the archive exited 1 because it says nothing. A placeholder finding\n // carries no subject when it is the C4 delta's scaffolded description; with a\n // subject it is a SPEC DELTA IN EITHER CORPUS — a service id when the text\n // sits in `specs/<svc>/`, a capability id when it sits in\n // `capabilities/<id>/` — which is why `spec` here is resolved by membership\n // below and must not be narrowed to the service list.\n if (code === \"intent.empty\") return \"intent\";\n if (code === \"scaffold.placeholder\") return subject === undefined ? \"delta\" : \"spec\";\n return null;\n}\n\n/**\n * The artifact table. Every entry is graded by two questions in order — is it\n * there, and does anything the shared checks reported name it — so a file that\n * exists and is wrong can never be reported the way one that was never written\n * is.\n */\n/** What the grading of one feature's files needs beyond the files themselves. */\nexport interface Grading {\n /** The findings that make an artifact `draft` rather than `done`. */\n blocking: Finding[];\n verification: VerificationState;\n /** Operations some OTHER feature's contract already holds. */\n contracted: ReadonlySet<string>;\n /** Operations this feature's own requirements govern. */\n governs: ReadonlySet<string>;\n /** The enumeration's entries by id — where each living service is and what it has (owesContract reads both). */\n living: ReadonlyMap<string, ServiceEntry>;\n /**\n * The capability documents this feature's delta carries. Empty for every\n * feature in a fleet that has not adopted the business axis, which is what\n * keeps the rows out of those payloads entirely.\n */\n capabilities: readonly CapabilityDoc[];\n}\n\nexport function featureArtifacts(\n docsDir: DocsDir,\n feature: FeatureEntry,\n services: readonly PathableService[],\n grading: Grading,\n): ArtifactState[] {\n const { blocking, verification, contracted, governs, living, capabilities } = grading;\n const paths = featurePaths(feature.dir);\n const rel = (abs: string): string => repoPath(docsDir, abs);\n const faults = blocking.map((f) => ({ artifact: faultedArtifact(f.code, f.subject), subject: f.subject }));\n const faulted = (id: ArtifactId, service: string | null): boolean =>\n faults.some((f) => f.artifact === id && (service === null || f.subject === service));\n\n const out: ArtifactState[] = [\n fileState(\"intent\", { service: null, path: rel(paths.intent), exists: existsSync(paths.intent) }, true, faulted(\"intent\", null)),\n fileState(\"delta\", { service: null, path: rel(paths.delta), exists: existsSync(paths.delta) }, false, faulted(\"delta\", null)),\n ];\n\n // One row per capability document the feature carries, and none at all when\n // it carries none: the row is the answer to \"which file do I edit\", and a\n // fleet that has not adopted the axis has no such file to name. Never\n // `required` — no feature owes a business change — so absence never shows up\n // as work owed, and only a fault turns one `draft`. A `delta.*` fault carries\n // the capability id in `subject` with nothing saying it is not a service, so\n // the membership test is the resolution the code family cannot give.\n for (const doc of capabilities) {\n out.push({\n id: \"capabilities\",\n service: null,\n capability: doc.id,\n path: rel(doc.spec),\n exists: existsSync(doc.spec),\n required: false,\n status: faulted(\"capabilities\", doc.id) || faulted(\"spec\", doc.id) ? \"draft\" : \"done\",\n blockedBy: [],\n });\n }\n\n for (const svc of services) {\n const p = featureSpecPaths(feature.dir, svc);\n const specFault = faulted(\"spec\", svc);\n out.push(fileState(\"spec\", { service: svc, path: rel(p.spec), exists: existsSync(p.spec) }, true, specFault));\n out.push(fileState(\"arch-spec\", { service: svc, path: rel(p.archSpec), exists: existsSync(p.archSpec) }, false, specFault));\n out.push(\n fileState(\n \"openapi\",\n { service: svc, path: rel(p.openapi), exists: existsSync(p.openapi) },\n owesContract(living.get(svc), contracted.has(svc), governs.has(svc)),\n faulted(\"openapi\", svc),\n ),\n );\n // Never required: an event contract is genuinely optional — the axis's own\n // absence-grading rests on that — so absence is `done`, exactly like\n // arch.spec.md. Present and faulted still turns the row `draft`.\n out.push(\n fileState(\n \"asyncapi\",\n { service: svc, path: rel(p.asyncapi), exists: existsSync(p.asyncapi) },\n false,\n faulted(\"asyncapi\", svc),\n ),\n );\n }\n\n // The record is the one artifact with a real prerequisite: its checklist is\n // derived from the delta and the per-service deltas, so with none of them\n // written there is nothing to answer — authoring one is impossible rather\n // than merely premature, which is the whole distinction `blocked` carries.\n //\n // `capabilities` is excluded for exactly that reason and not by oversight:\n // `featureChecklist` derives no claim from a capability document — a business\n // promise is realized by service requirements, and those are what the record\n // answers — so counting one as a feeder would report a capability-only\n // feature as ready to verify against a checklist with nothing in it.\n const feeders = out.filter(\n (a) => a.id !== \"intent\" && a.id !== \"arch-spec\" && a.id !== \"capabilities\" && a.exists,\n );\n out.push({\n id: \"verification\",\n service: null,\n path: rel(verificationPath(feature.dir)),\n exists: verification.state !== \"absent\",\n required: true,\n status: feeders.length === 0 ? \"blocked\" : verificationStatus(verification),\n blockedBy: feeders.length === 0 ? [\"delta\", \"spec\", \"openapi\", \"asyncapi\"] : [],\n });\n return out;\n}\n\n/** Where an artifact is and whether it is there — the three facts a grade reads. */\ninterface FileFacts {\n service: string | null;\n path: string;\n exists: boolean;\n}\n\nfunction fileState(id: ArtifactId, file: FileFacts, required: boolean, faulted: boolean): ArtifactState {\n const { service, path, exists } = file;\n const status: ArtifactStatus = !exists\n ? required\n ? \"missing\"\n : \"done\"\n : faulted\n ? \"draft\"\n : \"done\";\n return { id, service, path, exists, required, status, blockedBy: [] };\n}\n"]}
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../../../src/core/status/feature/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIlD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IACxC,qCAAqC;IACrC,uCAAuC;IACvC,mCAAmC;IACnC,sBAAsB;IACtB,wCAAwC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,OAAgB;IACrD,IAAI,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,sBAAsB;QAAE,OAAO,OAAO,CAAC;IAChF,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,SAAS,CAAC;IAClD,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QAAE,OAAO,UAAU,CAAC;IACpD,8EAA8E;IAC9E,uDAAuD;IACvD,8EAA8E;IAC9E,wEAAwE;IACxE,0EAA0E;IAC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AgB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,EAAE,YAAY,CAAC,KAAK,KAAK,QAAQ;QACvC,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC;QAC3E,SAAS,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;KAC7F,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AASD,SAAS,SAAS,CAAC,EAAc,EAAE,IAAe,EAAE,QAAiB,EAAE,OAAgB;IACrF,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,MAAM,MAAM,GAAmB,CAAC,MAAM;QACpC,CAAC,CAAC,QAAQ;YACR,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM;QACV,CAAC,CAAC,OAAO;YACP,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,MAAM,CAAC;IACb,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AACxE,CAAC","sourcesContent":["/**\n * The artifact table: which files a feature owes, whether each is on disk, and\n * which finding turns a row `draft`. Nothing is graded here — the shared\n * checks already ran, and this module only attributes what they reported to\n * the file a reader should edit.\n */\nimport { existsSync } from \"node:fs\";\nimport { repoPath } from \"../../envelope/json.js\";\nimport type { CapabilityDoc } from \"../../capabilities/tree.js\";\nimport type { PathableService } from \"../../kernel/ids/service.js\";\nimport type { FeatureEntry } from \"../../repo/entries.js\";\nimport { featurePaths, featureSpecPaths } from \"../../repo/paths.js\";\nimport { verificationPath } from \"../../verify/record.js\";\nimport type { Finding } from \"../../vocabulary/report.js\";\nimport { owesContract } from \"../contracts.js\";\nimport type { ServiceEntry } from \"../../repo/entries.js\";\nimport type { ArtifactId, ArtifactState, ArtifactStatus, VerificationState } from \"../report.js\";\nimport { verificationStatus } from \"../verification.js\";\nimport type { DocsDir } from \"../../kernel/ids/dirs.js\";\n\n/**\n * The `capability.*` codes filed against a capability DOCUMENT rather than\n * against a service requirement's join line. Spelled out rather than matched by\n * prefix because the family straddles both corpora, and the whole point of this\n * table is to name one file.\n */\nconst CAPABILITY_DOCUMENT_CODES = new Set([\n \"capability.requirement-unidentified\",\n \"capability.requirement-service-scoped\",\n \"capability.requirement-inert-join\",\n \"capability.uncovered\",\n \"capability.remove-requirement-realized\",\n]);\n\n/**\n * Which artifact an error names.\n *\n * Attribution is by code family, because that is the only machine-readable\n * pointer an `Issue` carries: `subject` narrows to a NAME, never to a file.\n * The families are unambiguous — `c4-api.*`/`c4-event.*`/`c4.*` and the two\n * `delta.*` codes about the LikeC4 document itself grade the architecture\n * axis, `openapi.*` grades the API contract, `asyncapi.*` the event contract,\n * and the remaining `delta.*` codes plus `spec-api.*`/`spec-event.*` are the\n * delta-shape checks, every one of which is about a requirement in a spec\n * delta.\n *\n * An error that maps to nothing (or whose subject is unknown) still lands in\n * `checks.issues` and still drives `next.fix-coherence` — it just does not turn\n * any single artifact `draft`, because guessing which file to blame is how a\n * reader gets sent to edit the wrong one.\n *\n * THE BUSINESS CORPUS IS THE ONE PLACE THE CODE FAMILY IS NOT ENOUGH. A\n * `delta.*` issue's `subject` is a service id OR a capability id\n * (`core/delta/scope.ts`), and so is a `scaffold.placeholder`'s\n * (`core/coherence/authoring/scaffold.ts` files one per unedited capability\n * delta), and nothing in either code says which — so this\n * function answers `spec` for both and `featureArtifacts` below resolves it by\n * MEMBERSHIP, against the two lists it already holds. Where a name is only a\n * capability the capability row is turned `draft` and no service row is; where\n * a fleet holds a service AND a capability of the same name, BOTH are, which is\n * the pessimistic answer this module is required to give and strictly better\n * than the old one (it named the service's spec delta and was silently wrong).\n * The capability-document codes below need no such resolution: they are only\n * ever filed against a capability.\n */\nfunction faultedArtifact(code: string, subject?: string): ArtifactId | null {\n if (code === \"delta.invalid\" || code === \"delta.nothing-tagged\") return \"delta\";\n if (code.startsWith(\"c4-api.\") || code.startsWith(\"c4-event.\") || code.startsWith(\"c4.\")) return \"delta\";\n if (code.startsWith(\"openapi.\")) return \"openapi\";\n if (code.startsWith(\"asyncapi.\")) return \"asyncapi\";\n // The capability document's own grades, and the two halves of the `Realizes:`\n // join a feature can break — every one of them names a\n // `features/<FEAT>/capabilities/<id>/spec.md`, never a service delta. The two\n // `capability.*` codes deliberately absent are `capability.unknown` and\n // `capability.realizes-unknown`: those grade a SERVICE requirement's join\n // lines and carry a service id, so the prefix alone would send their reader\n // to the wrong file.\n if (CAPABILITY_DOCUMENT_CODES.has(code)) return \"capabilities\";\n if (code.startsWith(\"delta.\") || code.startsWith(\"spec-api.\") || code.startsWith(\"spec-event.\")) return \"spec\";\n // The two families validate contributes: the frontmatter checks read only\n // intent.md, and a requirement with no scenario is a requirement in a spec\n // delta. Both name exactly one file, so both may turn a row `draft`.\n if (code.startsWith(\"frontmatter.\")) return \"intent\";\n if (code === \"requirements.missing-scenarios\") return \"spec\";\n // The authoring gate names exactly one file per finding too — leaving these\n // unmapped had the table calling intent.md `done` (\"nothing is owed here\")\n // while the archive exited 1 because it says nothing. A placeholder finding\n // carries no subject when it is the C4 delta's scaffolded description; with a\n // subject it is a SPEC DELTA IN EITHER CORPUS — a service id when the text\n // sits in `specs/<svc>/`, a capability id when it sits in\n // `capabilities/<id>/` — which is why `spec` here is resolved by membership\n // below and must not be narrowed to the service list.\n if (code === \"intent.empty\") return \"intent\";\n if (code === \"scaffold.placeholder\") return subject === undefined ? \"delta\" : \"spec\";\n return null;\n}\n\n/**\n * The artifact table. Every entry is graded by two questions in order — is it\n * there, and does anything the shared checks reported name it — so a file that\n * exists and is wrong can never be reported the way one that was never written\n * is.\n */\n/** What the grading of one feature's files needs beyond the files themselves. */\nexport interface Grading {\n /** The findings that make an artifact `draft` rather than `done`. */\n blocking: Finding[];\n verification: VerificationState;\n /** Operations some OTHER feature's contract already holds. */\n contracted: ReadonlySet<string>;\n /** Operations this feature's own requirements govern. */\n governs: ReadonlySet<string>;\n /** The enumeration's entries by id — where each living service is and what it has (owesContract reads both). */\n living: ReadonlyMap<string, ServiceEntry>;\n /**\n * The capability documents this feature's delta carries. Empty for every\n * feature in a fleet that has not adopted the business axis, which is what\n * keeps the rows out of those payloads entirely.\n */\n capabilities: readonly CapabilityDoc[];\n}\n\nexport function featureArtifacts(\n docsDir: DocsDir,\n feature: FeatureEntry,\n services: readonly PathableService[],\n grading: Grading,\n): ArtifactState[] {\n const { blocking, verification, contracted, governs, living, capabilities } = grading;\n const paths = featurePaths(feature.dir);\n const rel = (abs: string): string => repoPath(docsDir, abs);\n const faults = blocking.map((f) => ({ artifact: faultedArtifact(f.code, f.subject), subject: f.subject }));\n const faulted = (id: ArtifactId, service: string | null): boolean =>\n faults.some((f) => f.artifact === id && (service === null || f.subject === service));\n\n const out: ArtifactState[] = [\n fileState(\"intent\", { service: null, path: rel(paths.intent), exists: existsSync(paths.intent) }, true, faulted(\"intent\", null)),\n fileState(\"delta\", { service: null, path: rel(paths.delta), exists: existsSync(paths.delta) }, false, faulted(\"delta\", null)),\n ];\n\n // One row per capability document the feature carries, and none at all when\n // it carries none: the row is the answer to \"which file do I edit\", and a\n // fleet that has not adopted the axis has no such file to name. Never\n // `required` — no feature owes a business change — so absence never shows up\n // as work owed, and only a fault turns one `draft`. A `delta.*` fault carries\n // the capability id in `subject` with nothing saying it is not a service, so\n // the membership test is the resolution the code family cannot give.\n for (const doc of capabilities) {\n out.push({\n id: \"capabilities\",\n service: null,\n capability: doc.id,\n path: rel(doc.spec),\n exists: existsSync(doc.spec),\n required: false,\n status: faulted(\"capabilities\", doc.id) || faulted(\"spec\", doc.id) ? \"draft\" : \"done\",\n blockedBy: [],\n });\n }\n\n for (const svc of services) {\n const p = featureSpecPaths(feature.dir, svc);\n const specFault = faulted(\"spec\", svc);\n // What a service delta owes is a REQUIREMENT DELTA, not specifically the\n // business one. `arch.spec.md` is the other corpus, with the same grammar\n // and the same delta algebra, and `featureChecklist` derives claims from\n // it — so a directory holding only the architectural document is a\n // complete delta, and every gate already reads it as one: `coherence`'s\n // `service.no-requirement-delta` counts the DIRECTORY, and\n // `validate --feature` grades an arch-only delta clean at exit 0.\n //\n // Requiring `spec.md` unconditionally made this module the one document\n // that disagreed. An architecture-only feature — an outbox added, a retry\n // policy, an alert; the changes `arch.spec.md` exists for because no\n // business scenario was ever going to carry them — reported `missing` and\n // emitted `next.author-spec`, sending the author to write business\n // requirements the change does not have, about a feature the gate accepts.\n // status may be redder than the gates on a question they also ask; it may\n // not invent an obligation they do not.\n const archExists = existsSync(p.archSpec);\n out.push(fileState(\"spec\", { service: svc, path: rel(p.spec), exists: existsSync(p.spec) }, !archExists, specFault));\n out.push(fileState(\"arch-spec\", { service: svc, path: rel(p.archSpec), exists: archExists }, false, specFault));\n out.push(\n fileState(\n \"openapi\",\n { service: svc, path: rel(p.openapi), exists: existsSync(p.openapi) },\n owesContract(living.get(svc), contracted.has(svc), governs.has(svc)),\n faulted(\"openapi\", svc),\n ),\n );\n // Never required: an event contract is genuinely optional — the axis's own\n // absence-grading rests on that — so absence is `done`, exactly like\n // arch.spec.md. Present and faulted still turns the row `draft`.\n out.push(\n fileState(\n \"asyncapi\",\n { service: svc, path: rel(p.asyncapi), exists: existsSync(p.asyncapi) },\n false,\n faulted(\"asyncapi\", svc),\n ),\n );\n }\n\n // The record is the one artifact with a real prerequisite: its checklist is\n // derived from the delta and the per-service deltas, so with none of them\n // written there is nothing to answer — authoring one is impossible rather\n // than merely premature, which is the whole distinction `blocked` carries.\n //\n // `capabilities` is excluded for exactly that reason and not by oversight:\n // `featureChecklist` derives no claim from a capability document — a business\n // promise is realized by service requirements, and those are what the record\n // answers — so counting one as a feeder would report a capability-only\n // feature as ready to verify against a checklist with nothing in it.\n //\n // `arch-spec` used to be excluded beside it, and that failed the same test\n // the comment above states: `featureChecklist` DOES read `arch.spec.md`\n // (`core/verify/checklist.ts`), and `loam verify` on an architecture-only\n // feature returns a real checklist. The row said `blocked … needs delta,\n // spec, openapi, asyncapi` and `next.verify` said there was nothing to derive\n // a checklist from, about a command that derives one — which is the failure\n // `blocked` is supposed to prevent, pointed the wrong way.\n const feeders = out.filter((a) => a.id !== \"intent\" && a.id !== \"capabilities\" && a.exists);\n out.push({\n id: \"verification\",\n service: null,\n path: rel(verificationPath(feature.dir)),\n exists: verification.state !== \"absent\",\n required: true,\n status: feeders.length === 0 ? \"blocked\" : verificationStatus(verification),\n blockedBy: feeders.length === 0 ? [\"delta\", \"spec\", \"arch-spec\", \"openapi\", \"asyncapi\"] : [],\n });\n return out;\n}\n\n/** Where an artifact is and whether it is there — the three facts a grade reads. */\ninterface FileFacts {\n service: string | null;\n path: string;\n exists: boolean;\n}\n\nfunction fileState(id: ArtifactId, file: FileFacts, required: boolean, faulted: boolean): ArtifactState {\n const { service, path, exists } = file;\n const status: ArtifactStatus = !exists\n ? required\n ? \"missing\"\n : \"done\"\n : faulted\n ? \"draft\"\n : \"done\";\n return { id, service, path, exists, required, status, blockedBy: [] };\n}\n"]}
@@ -143,7 +143,17 @@ async function fleetFeature(docsDir, feature, view) {
143
143
  const governs = governedServices(await scanDeltas(docsDir, feature, feature.services, context));
144
144
  for (const svc of feature.services) {
145
145
  const p = featureSpecPaths(feature.dir, svc);
146
- if (!existsSync(p.spec))
146
+ // EITHER corpus satisfies it. What a service delta owes is a requirement
147
+ // delta, and `arch.spec.md` is the other one — same grammar, same delta
148
+ // algebra, read by `featureChecklist` — so an architecture-only feature is
149
+ // complete and every gate already says so. This form asked for `spec.md`
150
+ // specifically, which broke the rule the comment two lines down states
151
+ // about the contract question: the two forms disagreed, `loam status`
152
+ // reporting `missing <svc>/spec` over a feature `loam status <FEAT>` and
153
+ // `loam validate --feature` both called complete. The name stays
154
+ // `<svc>/spec` when NEITHER exists, because the business delta is the one
155
+ // an author writes by default.
156
+ if (!existsSync(p.spec) && !existsSync(p.archSpec))
147
157
  missing.push(`${svc}/spec`);
148
158
  // The same question featureArtifacts asks, through the same function: the
149
159
  // two forms must never disagree about whether a feature owes a contract.
@@ -1 +1 @@
1
- {"version":3,"file":"fleet.js","sourceRoot":"","sources":["../../../../src/core/status/fleet/fleet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAwB,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAwC,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,YAAY,EACZ,OAAO,GAKR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AA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EAAE,OAAO,CAAC,GAAG,CAAC;QACpC,KAAK;QACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,SAAS;QACT,OAAO;QACP,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The whole repository — why the fleet form is cheaper than the feature form.\n *\n * `loam status` with no feature runs over every active feature, and deriving a\n * coherence report or a verification checklist per feature means spinning a\n * fresh LikeC4 workspace per feature. On a fleet-sized repository that is the\n * cost that gets a command switched off — `list` made the same call about its\n * verification column. So the fleet form grades nothing: it reports artifact\n * PRESENCE, the dependency order, and a verification record only where one\n * already exists, and its `next[]` hands off to `loam status <FEAT>`, which is\n * where the checks actually run.\n */\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { analyzeDependencies } from \"../../dependencies/dependencies.js\";\nimport { type DependencyGraph } from \"../../dependencies/facts.js\";\nimport { isLandscapeStub } from \"../../scaffold/landscape.js\";\nimport { repoPath } from \"../../envelope/json.js\";\nimport { FleetContext } from \"../../fleet-context.js\";\nimport { compareIds, type FeatureEntry, type ServiceEntry } from \"../../repo/entries.js\";\nimport { featurePaths, featureSpecPaths, landscapePath } from \"../../repo/paths.js\";\nimport { listFeatures, listServices } from \"../../repo/repo.js\";\nimport { contractOwners, contractsHeldElsewhere, owesContract } from \"../contracts.js\";\nimport { readInterruptedCommit } from \"../interrupted.js\";\nimport {\n undocumented,\n vouched,\n type ArtifactStatus,\n type FleetFeatureState,\n type FleetStatusReport,\n type InterruptedCommit,\n} from \"../report.js\";\nimport { governedServices, scanDeltas } from \"../scan.js\";\nimport { fullyVerified, verificationState } from \"../verification.js\";\nimport { fleetNext, type Binding } from \"./next.js\";\nimport type { DocsDir } from \"../../kernel/ids/dirs.js\";\n\n/**\n * The fleet view: how much of `services/` anyone has written down, every\n * feature in flight with the stage it has reached, and the order they have to\n * land in. Nothing here is graded — the module header says why — so the stages\n * are drawn from artifact presence and from a record that already exists, and\n * `next[]` hands off to `loam status <FEAT>` for everything else.\n */\nexport async function fleetStatus(\n docsDir: DocsDir,\n opts: { service?: string; bound?: string; context?: FleetContext } = {},\n): Promise<FleetStatusReport> {\n const context = opts.context ?? new FleetContext();\n const interrupted = await readInterruptedCommit(docsDir);\n const narrowed = opts.service;\n const all = await listServices(docsDir, context);\n const services = narrowed === undefined ? all : all.filter((s) => s.id === narrowed);\n // The service this repository says it IS, and whether the fleet has heard of\n // it. Asked against the UNNARROWED list, because \"is it adopted\" is a question\n // about the fleet and not about the view.\n //\n // Both facts travel, where only the unadopted case used to. This value was a\n // `string | null` that went null exactly when the service directory EXISTED,\n // so the walk could see the repository it stands in only while that\n // repository was undocumented — and a developer in an adopted service repo\n // got the whole fleet's worklist with their own boundary buried in it.\n const binding: Binding | null =\n opts.bound === undefined ? null : { id: opts.bound, adopted: all.some((s) => s.id === opts.bound) };\n const graph = await analyzeDependencies(docsDir, undefined, context);\n const entries = await listFeatures(docsDir, {}, context);\n const inScope = narrowed === undefined ? entries : entries.filter((f) => f.services.some((s) => s === narrowed));\n // Once for the fleet, not once per feature: which features hold a contract\n // for which service is one fact about the repository, and every feature below\n // reads its own row out of it. Built over the UNNARROWED list on purpose — a\n // `--service` view still has to know that a feature outside it discharges the\n // contract, or the narrowing would invent an obligation.\n const owners = await contractOwners(docsDir, context);\n\n const features = await Promise.all(\n inScope.map((f) =>\n fleetFeature(docsDir, f, {\n graph,\n contracted: contractsHeldElsewhere(owners, f.id),\n living: new Map(all.map((s) => [s.id, s])),\n context,\n interrupted,\n }),\n ),\n );\n features.sort((a, b) => compareIds(a.id, b.id));\n\n // The first-hour ladder's fact, computed exactly when the ladder can apply\n // — an unnarrowed run over a fleet with zero services and zero features —\n // so the read disappears from every repository that has anything in it.\n // Withheld on narrowed runs for the same reason the binding is withheld\n // below: `--service X` is an explicit question about X, and the\n // repository's onboarding ladder would be a different question's answer.\n const teaching =\n narrowed === undefined && services.length === 0 && features.length === 0\n ? { landscape: await landscapeTeaching(docsDir) }\n : null;\n\n return {\n interrupted,\n services: {\n total: services.length,\n undocumented: services.filter(undocumented).length,\n draft: services.filter((s) => !undocumented(s) && !vouched(s)).length,\n vouched: services.filter(vouched).length,\n // A subset of `vouched`, never a fourth bucket: those services ARE\n // vouched, and the three counts still sum to `total`. It rides beside\n // the count it qualifies because this line is the fleet's trust\n // headline, and \"118 vouched\" over a fleet where 90 of them were read\n // from a sample is the misreading the scope exists to prevent.\n sampledVouched: services.filter((s) => vouched(s) && s.vouchScope === \"sampled\").length,\n },\n features,\n order: graph.order.filter((id) => features.some((f) => f.id === id)),\n service: narrowed ?? null,\n // The binding is passed only when this run was NOT narrowed, and that guard\n // is unchanged now that the binding also decides ORDER. `--service X` is an\n // explicit question about X, and answering it with a step about whichever\n // service loam.json happens to name would be a different question's answer\n // at the top of the list — which is as true of a rung promoted to the front\n // as it was of `next.adopt-bound` emitted out of nowhere. A narrowed run\n // sees at most the one service it asked about anyway, so withholding the\n // binding here costs the reader nothing and keeps `--service X` answering\n // only about X.\n next: fleetNext(\n { services, features, graph, interrupted, teaching },\n narrowed === undefined ? binding : null,\n ),\n };\n}\n\n/**\n * Which first-hour state the fleet map is in: absent, still the scaffold's own\n * untouched bytes, or authored. One file read and a byte comparison — the\n * module header's cost rule stands, no LikeC4 workspace is spun here.\n */\nasync function landscapeTeaching(docsDir: DocsDir): Promise<\"missing\" | \"stub\" | \"authored\"> {\n const lp = landscapePath(docsDir);\n if (!existsSync(lp)) return \"missing\";\n try {\n return isLandscapeStub(await readFile(lp, \"utf8\")) ? \"stub\" : \"authored\";\n } catch {\n // Unreadable is not untouched. A map that cannot be read — a directory in\n // the file's place, a permission — must not be called the scaffold's stub\n // (\"missing\" and \"stub\" would each put a false statement in next[]), so it\n // reads as \"authored\", which only drops the one teaching step: the gate\n // entry still names `loam validate --all`, where an unreadable landscape\n // is actually graded, and letting this read throw would hand the whole\n // orientation surface — a command that reports and never gates — to the\n // repository-unavailable refusal over a file status does not even parse.\n return \"authored\";\n }\n}\n\n/** What a feature's fleet row needs about the fleet AROUND it. */\ninterface FleetView {\n graph: DependencyGraph;\n /** Operations some other feature's contract already holds. */\n contracted: ReadonlySet<string>;\n /** The enumeration's entries by id — where each living service is and what it has (owesContract reads both). */\n living: ReadonlyMap<string, ServiceEntry>;\n context: FleetContext;\n interrupted: InterruptedCommit | null;\n}\n\nasync function fleetFeature(\n docsDir: DocsDir,\n feature: FeatureEntry,\n view: FleetView,\n): Promise<FleetFeatureState> {\n const { graph, contracted, living, context, interrupted } = view;\n const paths = featurePaths(feature.dir);\n const missing: string[] = [];\n if (!existsSync(paths.intent)) missing.push(\"intent\");\n if (feature.services.length === 0) missing.push(\"spec\");\n // Requirement text, not a coherence run: `Operations:` lines are read off the\n // same cached parse `list` already pays for, and the contract question needs\n // them (owesContract). No LikeC4 workspace is spun here, which is the cost\n // this form actually refuses.\n const governs = governedServices(await scanDeltas(docsDir, feature, feature.services, context));\n for (const svc of feature.services) {\n const p = featureSpecPaths(feature.dir, svc);\n if (!existsSync(p.spec)) missing.push(`${svc}/spec`);\n // The same question featureArtifacts asks, through the same function: the\n // two forms must never disagree about whether a feature owes a contract.\n if (owesContract(living.get(svc), contracted.has(svc), governs.has(svc)) && !existsSync(p.openapi)) {\n missing.push(`${svc}/openapi`);\n }\n }\n const verification = (await verificationState(docsDir, feature)).state;\n const blockedBy = graph.nodes.find((n) => n.id === feature.id)?.dependsOn ?? [];\n\n // No `draft` here, ever: that verdict needs the coherence run this form\n // refuses to pay for, and inferring it from presence alone would be a second\n // opinion about validity — the one thing status must never invent.\n //\n // The interrupted commit leads, exactly as it does in the feature form: every\n // presence test below is a question about files a killed `archive` may have\n // half-written, so answering `done` from them is a claim about bytes nobody\n // has established. Without this the two forms contradicted each other over\n // one repository — `loam status --json` said `done` and offered \"ship it\"\n // while `loam status <FEAT>` said `blocked` — and the rule in report.ts's\n // header is that this projection is never greener than the gates.\n const stage: ArtifactStatus =\n interrupted !== null\n ? \"blocked\"\n : missing.length > 0\n ? \"missing\"\n : blockedBy.length > 0\n ? \"blocked\"\n : fullyVerified(verification)\n ? \"done\"\n : \"ready\";\n\n return {\n id: feature.id,\n dirName: feature.dirName,\n path: repoPath(docsDir, feature.dir),\n stage,\n services: feature.services,\n blockedBy,\n missing,\n verification,\n };\n}\n"]}
1
+ {"version":3,"file":"fleet.js","sourceRoot":"","sources":["../../../../src/core/status/fleet/fleet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAwB,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAwC,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,YAAY,EACZ,OAAO,GAKR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC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AC,CAAC,OAAO,CAAC;IAEpB,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;QACpC,KAAK;QACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,SAAS;QACT,OAAO;QACP,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The whole repository — why the fleet form is cheaper than the feature form.\n *\n * `loam status` with no feature runs over every active feature, and deriving a\n * coherence report or a verification checklist per feature means spinning a\n * fresh LikeC4 workspace per feature. On a fleet-sized repository that is the\n * cost that gets a command switched off — `list` made the same call about its\n * verification column. So the fleet form grades nothing: it reports artifact\n * PRESENCE, the dependency order, and a verification record only where one\n * already exists, and its `next[]` hands off to `loam status <FEAT>`, which is\n * where the checks actually run.\n */\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { analyzeDependencies } from \"../../dependencies/dependencies.js\";\nimport { type DependencyGraph } from \"../../dependencies/facts.js\";\nimport { isLandscapeStub } from \"../../scaffold/landscape.js\";\nimport { repoPath } from \"../../envelope/json.js\";\nimport { FleetContext } from \"../../fleet-context.js\";\nimport { compareIds, type FeatureEntry, type ServiceEntry } from \"../../repo/entries.js\";\nimport { featurePaths, featureSpecPaths, landscapePath } from \"../../repo/paths.js\";\nimport { listFeatures, listServices } from \"../../repo/repo.js\";\nimport { contractOwners, contractsHeldElsewhere, owesContract } from \"../contracts.js\";\nimport { readInterruptedCommit } from \"../interrupted.js\";\nimport {\n undocumented,\n vouched,\n type ArtifactStatus,\n type FleetFeatureState,\n type FleetStatusReport,\n type InterruptedCommit,\n} from \"../report.js\";\nimport { governedServices, scanDeltas } from \"../scan.js\";\nimport { fullyVerified, verificationState } from \"../verification.js\";\nimport { fleetNext, type Binding } from \"./next.js\";\nimport type { DocsDir } from \"../../kernel/ids/dirs.js\";\n\n/**\n * The fleet view: how much of `services/` anyone has written down, every\n * feature in flight with the stage it has reached, and the order they have to\n * land in. Nothing here is graded — the module header says why — so the stages\n * are drawn from artifact presence and from a record that already exists, and\n * `next[]` hands off to `loam status <FEAT>` for everything else.\n */\nexport async function fleetStatus(\n docsDir: DocsDir,\n opts: { service?: string; bound?: string; context?: FleetContext } = {},\n): Promise<FleetStatusReport> {\n const context = opts.context ?? new FleetContext();\n const interrupted = await readInterruptedCommit(docsDir);\n const narrowed = opts.service;\n const all = await listServices(docsDir, context);\n const services = narrowed === undefined ? all : all.filter((s) => s.id === narrowed);\n // The service this repository says it IS, and whether the fleet has heard of\n // it. Asked against the UNNARROWED list, because \"is it adopted\" is a question\n // about the fleet and not about the view.\n //\n // Both facts travel, where only the unadopted case used to. This value was a\n // `string | null` that went null exactly when the service directory EXISTED,\n // so the walk could see the repository it stands in only while that\n // repository was undocumented — and a developer in an adopted service repo\n // got the whole fleet's worklist with their own boundary buried in it.\n const binding: Binding | null =\n opts.bound === undefined ? null : { id: opts.bound, adopted: all.some((s) => s.id === opts.bound) };\n const graph = await analyzeDependencies(docsDir, undefined, context);\n const entries = await listFeatures(docsDir, {}, context);\n const inScope = narrowed === undefined ? entries : entries.filter((f) => f.services.some((s) => s === narrowed));\n // Once for the fleet, not once per feature: which features hold a contract\n // for which service is one fact about the repository, and every feature below\n // reads its own row out of it. Built over the UNNARROWED list on purpose — a\n // `--service` view still has to know that a feature outside it discharges the\n // contract, or the narrowing would invent an obligation.\n const owners = await contractOwners(docsDir, context);\n\n const features = await Promise.all(\n inScope.map((f) =>\n fleetFeature(docsDir, f, {\n graph,\n contracted: contractsHeldElsewhere(owners, f.id),\n living: new Map(all.map((s) => [s.id, s])),\n context,\n interrupted,\n }),\n ),\n );\n features.sort((a, b) => compareIds(a.id, b.id));\n\n // The first-hour ladder's fact, computed exactly when the ladder can apply\n // — an unnarrowed run over a fleet with zero services and zero features —\n // so the read disappears from every repository that has anything in it.\n // Withheld on narrowed runs for the same reason the binding is withheld\n // below: `--service X` is an explicit question about X, and the\n // repository's onboarding ladder would be a different question's answer.\n const teaching =\n narrowed === undefined && services.length === 0 && features.length === 0\n ? { landscape: await landscapeTeaching(docsDir) }\n : null;\n\n return {\n interrupted,\n services: {\n total: services.length,\n undocumented: services.filter(undocumented).length,\n draft: services.filter((s) => !undocumented(s) && !vouched(s)).length,\n vouched: services.filter(vouched).length,\n // A subset of `vouched`, never a fourth bucket: those services ARE\n // vouched, and the three counts still sum to `total`. It rides beside\n // the count it qualifies because this line is the fleet's trust\n // headline, and \"118 vouched\" over a fleet where 90 of them were read\n // from a sample is the misreading the scope exists to prevent.\n sampledVouched: services.filter((s) => vouched(s) && s.vouchScope === \"sampled\").length,\n },\n features,\n order: graph.order.filter((id) => features.some((f) => f.id === id)),\n service: narrowed ?? null,\n // The binding is passed only when this run was NOT narrowed, and that guard\n // is unchanged now that the binding also decides ORDER. `--service X` is an\n // explicit question about X, and answering it with a step about whichever\n // service loam.json happens to name would be a different question's answer\n // at the top of the list — which is as true of a rung promoted to the front\n // as it was of `next.adopt-bound` emitted out of nowhere. A narrowed run\n // sees at most the one service it asked about anyway, so withholding the\n // binding here costs the reader nothing and keeps `--service X` answering\n // only about X.\n next: fleetNext(\n { services, features, graph, interrupted, teaching },\n narrowed === undefined ? binding : null,\n ),\n };\n}\n\n/**\n * Which first-hour state the fleet map is in: absent, still the scaffold's own\n * untouched bytes, or authored. One file read and a byte comparison — the\n * module header's cost rule stands, no LikeC4 workspace is spun here.\n */\nasync function landscapeTeaching(docsDir: DocsDir): Promise<\"missing\" | \"stub\" | \"authored\"> {\n const lp = landscapePath(docsDir);\n if (!existsSync(lp)) return \"missing\";\n try {\n return isLandscapeStub(await readFile(lp, \"utf8\")) ? \"stub\" : \"authored\";\n } catch {\n // Unreadable is not untouched. A map that cannot be read — a directory in\n // the file's place, a permission — must not be called the scaffold's stub\n // (\"missing\" and \"stub\" would each put a false statement in next[]), so it\n // reads as \"authored\", which only drops the one teaching step: the gate\n // entry still names `loam validate --all`, where an unreadable landscape\n // is actually graded, and letting this read throw would hand the whole\n // orientation surface — a command that reports and never gates — to the\n // repository-unavailable refusal over a file status does not even parse.\n return \"authored\";\n }\n}\n\n/** What a feature's fleet row needs about the fleet AROUND it. */\ninterface FleetView {\n graph: DependencyGraph;\n /** Operations some other feature's contract already holds. */\n contracted: ReadonlySet<string>;\n /** The enumeration's entries by id — where each living service is and what it has (owesContract reads both). */\n living: ReadonlyMap<string, ServiceEntry>;\n context: FleetContext;\n interrupted: InterruptedCommit | null;\n}\n\nasync function fleetFeature(\n docsDir: DocsDir,\n feature: FeatureEntry,\n view: FleetView,\n): Promise<FleetFeatureState> {\n const { graph, contracted, living, context, interrupted } = view;\n const paths = featurePaths(feature.dir);\n const missing: string[] = [];\n if (!existsSync(paths.intent)) missing.push(\"intent\");\n if (feature.services.length === 0) missing.push(\"spec\");\n // Requirement text, not a coherence run: `Operations:` lines are read off the\n // same cached parse `list` already pays for, and the contract question needs\n // them (owesContract). No LikeC4 workspace is spun here, which is the cost\n // this form actually refuses.\n const governs = governedServices(await scanDeltas(docsDir, feature, feature.services, context));\n for (const svc of feature.services) {\n const p = featureSpecPaths(feature.dir, svc);\n // EITHER corpus satisfies it. What a service delta owes is a requirement\n // delta, and `arch.spec.md` is the other one — same grammar, same delta\n // algebra, read by `featureChecklist` — so an architecture-only feature is\n // complete and every gate already says so. This form asked for `spec.md`\n // specifically, which broke the rule the comment two lines down states\n // about the contract question: the two forms disagreed, `loam status`\n // reporting `missing <svc>/spec` over a feature `loam status <FEAT>` and\n // `loam validate --feature` both called complete. The name stays\n // `<svc>/spec` when NEITHER exists, because the business delta is the one\n // an author writes by default.\n if (!existsSync(p.spec) && !existsSync(p.archSpec)) missing.push(`${svc}/spec`);\n // The same question featureArtifacts asks, through the same function: the\n // two forms must never disagree about whether a feature owes a contract.\n if (owesContract(living.get(svc), contracted.has(svc), governs.has(svc)) && !existsSync(p.openapi)) {\n missing.push(`${svc}/openapi`);\n }\n }\n const verification = (await verificationState(docsDir, feature)).state;\n const blockedBy = graph.nodes.find((n) => n.id === feature.id)?.dependsOn ?? [];\n\n // No `draft` here, ever: that verdict needs the coherence run this form\n // refuses to pay for, and inferring it from presence alone would be a second\n // opinion about validity — the one thing status must never invent.\n //\n // The interrupted commit leads, exactly as it does in the feature form: every\n // presence test below is a question about files a killed `archive` may have\n // half-written, so answering `done` from them is a claim about bytes nobody\n // has established. Without this the two forms contradicted each other over\n // one repository — `loam status --json` said `done` and offered \"ship it\"\n // while `loam status <FEAT>` said `blocked` — and the rule in report.ts's\n // header is that this projection is never greener than the gates.\n const stage: ArtifactStatus =\n interrupted !== null\n ? \"blocked\"\n : missing.length > 0\n ? \"missing\"\n : blockedBy.length > 0\n ? \"blocked\"\n : fullyVerified(verification)\n ? \"done\"\n : \"ready\";\n\n return {\n id: feature.id,\n dirName: feature.dirName,\n path: repoPath(docsDir, feature.dir),\n stage,\n services: feature.services,\n blockedBy,\n missing,\n verification,\n };\n}\n"]}