@principal-ai/subsystems-core 0.52.0 → 0.53.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 (214) hide show
  1. package/README.md +30 -2
  2. package/dist/audit/boundary.d.ts +104 -0
  3. package/dist/audit/boundary.d.ts.map +1 -0
  4. package/dist/audit/boundary.js +363 -0
  5. package/dist/audit/boundary.js.map +1 -0
  6. package/dist/audit/c4.d.ts +41 -0
  7. package/dist/audit/c4.d.ts.map +1 -0
  8. package/dist/audit/c4.js +41 -0
  9. package/dist/audit/c4.js.map +1 -0
  10. package/dist/audit/engine.d.ts +135 -0
  11. package/dist/audit/engine.d.ts.map +1 -0
  12. package/dist/audit/engine.js +865 -0
  13. package/dist/audit/engine.js.map +1 -0
  14. package/dist/audit/fixes.d.ts +80 -0
  15. package/dist/audit/fixes.d.ts.map +1 -0
  16. package/dist/audit/fixes.js +162 -0
  17. package/dist/audit/fixes.js.map +1 -0
  18. package/dist/audit/graphify-provider.d.ts +51 -0
  19. package/dist/audit/graphify-provider.d.ts.map +1 -0
  20. package/dist/audit/graphify-provider.js +36 -0
  21. package/dist/audit/graphify-provider.js.map +1 -0
  22. package/dist/audit/hash.d.ts +25 -0
  23. package/dist/audit/hash.d.ts.map +1 -0
  24. package/dist/audit/hash.js +53 -0
  25. package/dist/audit/hash.js.map +1 -0
  26. package/dist/audit/index.d.ts +12 -0
  27. package/dist/audit/index.d.ts.map +1 -0
  28. package/dist/audit/index.js +40 -0
  29. package/dist/audit/index.js.map +1 -0
  30. package/dist/audit/local-graphify.d.ts +75 -0
  31. package/dist/audit/local-graphify.d.ts.map +1 -0
  32. package/dist/audit/local-graphify.js +283 -0
  33. package/dist/audit/local-graphify.js.map +1 -0
  34. package/dist/audit/paths.d.ts +16 -0
  35. package/dist/audit/paths.d.ts.map +1 -0
  36. package/dist/audit/paths.js +31 -0
  37. package/dist/audit/paths.js.map +1 -0
  38. package/dist/audit/pure.d.ts +18 -0
  39. package/dist/audit/pure.d.ts.map +1 -0
  40. package/dist/audit/pure.js +50 -0
  41. package/dist/audit/pure.js.map +1 -0
  42. package/dist/audit/report-logic.d.ts +17 -0
  43. package/dist/audit/report-logic.d.ts.map +1 -0
  44. package/dist/audit/report-logic.js +206 -0
  45. package/dist/audit/report-logic.js.map +1 -0
  46. package/dist/audit/report.d.ts +140 -0
  47. package/dist/audit/report.d.ts.map +1 -0
  48. package/dist/audit/report.js +3 -0
  49. package/dist/audit/report.js.map +1 -0
  50. package/dist/audit/trail.d.ts +29 -0
  51. package/dist/audit/trail.d.ts.map +1 -0
  52. package/dist/audit/trail.js +59 -0
  53. package/dist/audit/trail.js.map +1 -0
  54. package/dist/audit/verification.d.ts +98 -0
  55. package/dist/audit/verification.d.ts.map +1 -0
  56. package/dist/audit/verification.js +11 -0
  57. package/dist/audit/verification.js.map +1 -0
  58. package/dist/audit/verify/component.d.ts +68 -0
  59. package/dist/audit/verify/component.d.ts.map +1 -0
  60. package/dist/audit/verify/component.js +500 -0
  61. package/dist/audit/verify/component.js.map +1 -0
  62. package/dist/audit/verify/declarations.d.ts +58 -0
  63. package/dist/audit/verify/declarations.d.ts.map +1 -0
  64. package/dist/audit/verify/declarations.js +227 -0
  65. package/dist/audit/verify/declarations.js.map +1 -0
  66. package/dist/audit/verify/grammar.d.ts +12 -0
  67. package/dist/audit/verify/grammar.d.ts.map +1 -0
  68. package/dist/audit/verify/grammar.js +57 -0
  69. package/dist/audit/verify/grammar.js.map +1 -0
  70. package/dist/audit/verify/index.d.ts +12 -0
  71. package/dist/audit/verify/index.d.ts.map +1 -0
  72. package/dist/audit/verify/index.js +31 -0
  73. package/dist/audit/verify/index.js.map +1 -0
  74. package/dist/audit/verify/parser.d.ts +19 -0
  75. package/dist/audit/verify/parser.d.ts.map +1 -0
  76. package/dist/audit/verify/parser.js +122 -0
  77. package/dist/audit/verify/parser.js.map +1 -0
  78. package/dist/audit/verify/span.d.ts +49 -0
  79. package/dist/audit/verify/span.d.ts.map +1 -0
  80. package/dist/audit/verify/span.js +377 -0
  81. package/dist/audit/verify/span.js.map +1 -0
  82. package/dist/graphify/anchor.d.ts +45 -0
  83. package/dist/graphify/anchor.d.ts.map +1 -0
  84. package/dist/graphify/anchor.js +179 -0
  85. package/dist/graphify/anchor.js.map +1 -0
  86. package/dist/graphify/consolidated.d.ts +259 -0
  87. package/dist/graphify/consolidated.d.ts.map +1 -0
  88. package/dist/graphify/consolidated.js +12 -0
  89. package/dist/graphify/consolidated.js.map +1 -0
  90. package/dist/graphify/construct.d.ts +41 -0
  91. package/dist/graphify/construct.d.ts.map +1 -0
  92. package/dist/graphify/construct.js +106 -0
  93. package/dist/graphify/construct.js.map +1 -0
  94. package/dist/graphify/ids.d.ts +19 -0
  95. package/dist/graphify/ids.d.ts.map +1 -0
  96. package/dist/graphify/ids.js +53 -0
  97. package/dist/graphify/ids.js.map +1 -0
  98. package/dist/graphify/index.d.ts +16 -0
  99. package/dist/graphify/index.d.ts.map +1 -0
  100. package/dist/graphify/index.js +32 -0
  101. package/dist/graphify/index.js.map +1 -0
  102. package/dist/graphify/resolve.d.ts +48 -0
  103. package/dist/graphify/resolve.d.ts.map +1 -0
  104. package/dist/graphify/resolve.js +89 -0
  105. package/dist/graphify/resolve.js.map +1 -0
  106. package/dist/graphify/signature.d.ts +87 -0
  107. package/dist/graphify/signature.d.ts.map +1 -0
  108. package/dist/graphify/signature.js +282 -0
  109. package/dist/graphify/signature.js.map +1 -0
  110. package/dist/graphify/types.d.ts +141 -0
  111. package/dist/graphify/types.d.ts.map +1 -0
  112. package/dist/graphify/types.js +9 -0
  113. package/dist/graphify/types.js.map +1 -0
  114. package/dist/index.d.ts +4 -0
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +9 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/infra/c4.d.ts +59 -0
  119. package/dist/infra/c4.d.ts.map +1 -0
  120. package/dist/infra/c4.js +106 -0
  121. package/dist/infra/c4.js.map +1 -0
  122. package/dist/infra/index.d.ts +13 -0
  123. package/dist/infra/index.d.ts.map +1 -0
  124. package/dist/infra/index.js +22 -0
  125. package/dist/infra/index.js.map +1 -0
  126. package/dist/infra/jsonc.d.ts +10 -0
  127. package/dist/infra/jsonc.d.ts.map +1 -0
  128. package/dist/infra/jsonc.js +77 -0
  129. package/dist/infra/jsonc.js.map +1 -0
  130. package/dist/infra/terraform.d.ts +41 -0
  131. package/dist/infra/terraform.d.ts.map +1 -0
  132. package/dist/infra/terraform.js +208 -0
  133. package/dist/infra/terraform.js.map +1 -0
  134. package/dist/infra/types.d.ts +107 -0
  135. package/dist/infra/types.d.ts.map +1 -0
  136. package/dist/infra/types.js +47 -0
  137. package/dist/infra/types.js.map +1 -0
  138. package/dist/infra/wrangler.d.ts +32 -0
  139. package/dist/infra/wrangler.d.ts.map +1 -0
  140. package/dist/infra/wrangler.js +177 -0
  141. package/dist/infra/wrangler.js.map +1 -0
  142. package/dist/node.d.ts +3 -0
  143. package/dist/node.d.ts.map +1 -1
  144. package/dist/node.js +4 -1
  145. package/dist/node.js.map +1 -1
  146. package/dist/storage/topic-reference-links.d.ts +3 -3
  147. package/dist/storage/topic-reference-links.d.ts.map +1 -1
  148. package/dist/storage/topic-reference-links.js +23 -8
  149. package/dist/storage/topic-reference-links.js.map +1 -1
  150. package/dist/storage/topic-share.d.ts +69 -0
  151. package/dist/storage/topic-share.d.ts.map +1 -0
  152. package/dist/storage/topic-share.js +67 -0
  153. package/dist/storage/topic-share.js.map +1 -0
  154. package/dist/storage/topic-types.d.ts +5 -1
  155. package/dist/storage/topic-types.d.ts.map +1 -1
  156. package/dist/types/subsystem-model.d.ts +59 -0
  157. package/dist/types/subsystem-model.d.ts.map +1 -1
  158. package/dist/types/subsystem-model.js +50 -1
  159. package/dist/types/subsystem-model.js.map +1 -1
  160. package/dist/validation.d.ts.map +1 -1
  161. package/dist/validation.js +25 -2
  162. package/dist/validation.js.map +1 -1
  163. package/package.json +22 -2
  164. package/schemas/subsystem-model.schema.json +35 -19
  165. package/src/audit/boundary.ts +447 -0
  166. package/src/audit/c4.ts +70 -0
  167. package/src/audit/engine.ts +1099 -0
  168. package/src/audit/fixes.ts +192 -0
  169. package/src/audit/graphify-provider.test.ts +58 -0
  170. package/src/audit/graphify-provider.ts +77 -0
  171. package/src/audit/hash.ts +58 -0
  172. package/src/audit/index.ts +34 -0
  173. package/src/audit/local-graphify.test.ts +163 -0
  174. package/src/audit/local-graphify.ts +354 -0
  175. package/src/audit/paths.ts +25 -0
  176. package/src/audit/pure.ts +91 -0
  177. package/src/audit/report-logic.test.ts +145 -0
  178. package/src/audit/report-logic.ts +245 -0
  179. package/src/audit/report.ts +207 -0
  180. package/src/audit/trail.ts +77 -0
  181. package/src/audit/verification.ts +104 -0
  182. package/src/audit/verify/component.ts +760 -0
  183. package/src/audit/verify/declarations.ts +284 -0
  184. package/src/audit/verify/grammar.ts +57 -0
  185. package/src/audit/verify/index.ts +41 -0
  186. package/src/audit/verify/parser.ts +124 -0
  187. package/src/audit/verify/span.ts +478 -0
  188. package/src/graphify/anchor.ts +206 -0
  189. package/src/graphify/consolidated.ts +298 -0
  190. package/src/graphify/construct.ts +153 -0
  191. package/src/graphify/ids.ts +48 -0
  192. package/src/graphify/index.ts +16 -0
  193. package/src/graphify/resolve.ts +115 -0
  194. package/src/graphify/signature.ts +354 -0
  195. package/src/graphify/types.ts +164 -0
  196. package/src/index.ts +10 -0
  197. package/src/infra/c4.ts +146 -0
  198. package/src/infra/index.ts +21 -0
  199. package/src/infra/infra.test.ts +360 -0
  200. package/src/infra/jsonc.ts +70 -0
  201. package/src/infra/terraform.ts +251 -0
  202. package/src/infra/types.ts +136 -0
  203. package/src/infra/wrangler.ts +203 -0
  204. package/src/node.ts +3 -0
  205. package/src/storage/topic-reference-links.test.ts +7 -1
  206. package/src/storage/topic-reference-links.ts +24 -8
  207. package/src/storage/topic-share.test.ts +91 -0
  208. package/src/storage/topic-share.ts +118 -0
  209. package/src/storage/topic-types.ts +3 -1
  210. package/src/storage/topicStore.test.ts +1 -0
  211. package/src/types/subsystem-model.test.ts +52 -2
  212. package/src/types/subsystem-model.ts +104 -0
  213. package/src/validation.test.ts +71 -7
  214. package/src/validation.ts +27 -2
package/README.md CHANGED
@@ -9,6 +9,27 @@ Subsystem model types/schema and agent-session tooling for Principal AI.
9
9
  | `@principal-ai/subsystems-core` | Browser-safe subsystem model/topic types, reference links + `isSubsystemModelDocument` |
10
10
  | `@principal-ai/subsystems-core/node` | OpenCode store, agent-session list/fetch/normalize, topic store, fixtures |
11
11
  | `@principal-ai/subsystems-core/pipeline` | Bun-safe session normalize/accumulate (no `better-sqlite3`) |
12
+ | `@principal-ai/subsystems-core/audit` | Node audit engine, component verifier (tree-sitter), Graphify ports, report types, local cache reader |
13
+ | `@principal-ai/subsystems-core/graphify` | Pure Graphify graph types + anchor/construct/signature resolution helpers |
14
+
15
+ `./audit` is the shared implementation behind both the `principal-ai
16
+ subsystem-model audit <id>` CLI command and Subsystems Studio. Hosts supply
17
+ adapters for the model store, Graphify transport, augmentations, C4 evidence,
18
+ source reads, report persistence, and commit provenance; the engine owns the
19
+ verification policy, report assembly, and fingerprint. `./graphify` and
20
+ `./audit`'s pure policy are browser-safe; `./audit` itself is Node-only
21
+ (`node:crypto`, `node:fs`, `web-tree-sitter`).
22
+
23
+ The Graphify dependency is a port, not a transport: `graphify-provider` defines
24
+ the contract, and `createLocalGraphifyAuditProvider` reads the same
25
+ `~/.principal/graphify-graphs` HEAD(+dirty) cache layout Studio writes. A host
26
+ can substitute a build-capable provider or a future MCP daemon without changing
27
+ the engine. Pure verdict/fix/verification rules stay browser-safe via
28
+ `./audit/pure` (re-exported from the main entry).
29
+
30
+ Studio and the CLI therefore run one audit implementation. Studio keeps its own
31
+ Graphify adapter (it can build caches); the CLI reads caches read-only and
32
+ reports missing checkouts/caches as explicit unavailable results.
12
33
 
13
34
  ## Schema
14
35
 
@@ -16,7 +37,7 @@ Portable document schema: `schemas/subsystem-model.schema.json`
16
37
 
17
38
  ## Topic references
18
39
 
19
- `DraftTopic.references` attaches local topics and C4 sketches by ID:
40
+ `DraftTopic.references` attaches local topics, C4 sketches, and drawings by ID:
20
41
 
21
42
  ```ts
22
43
  import {
@@ -29,14 +50,21 @@ const reference: TopicReference = { kind: 'c4-sketch', sketchId: 'c4s-123-abc' }
29
50
  formatTopicReferenceLink(reference); // principal://c4-sketch/c4s-123-abc
30
51
  parseTopicReferenceLink('principal://topic/topic-123-abc');
31
52
  // { kind: 'topic', topicId: 'topic-123-abc' }
53
+ parseTopicReferenceLink('principal://drawing/0b6f7c1e');
54
+ // { kind: 'drawing', drawingId: '0b6f7c1e' }
32
55
  ```
33
56
 
57
+ A drawing ID is the file name, without extension, of a `.excalidraw` file in the
58
+ host's drawings folder (the desktop app uses `~/.alexandria/drawings/`). Titles
59
+ come from the drawing file's `appState.name` and are resolved by the host.
60
+
34
61
  Create/update accepts `references`; updates replace the whole array (`[]` clears
35
62
  it). Existing topics may omit the field. References are directional and local-only.
36
63
  Targets stay separate artifacts; deleting a target leaves a missing reference,
37
64
  not a cascading deletion. Existing `subsystemModels` associations are unchanged.
38
65
 
39
- Markdown links such as `[Architecture](principal://c4-sketch/c4s-123-abc)` and
66
+ Markdown links such as `[Architecture](principal://c4-sketch/c4s-123-abc)`,
67
+ `[Whiteboard](principal://drawing/0b6f7c1e)`, and
40
68
  `[Related](principal://topic/topic-123-abc)` use the same target shapes but are
41
69
  independent of attachments. Helpers only format/parse hrefs; hosts must allow the
42
70
  `principal` protocol in Markdown sanitizers and handle resolution, navigation,
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Boundary (process / module) audit helpers — membership for frames.
3
+ * Mechanical checks only; no Graphify.
4
+ *
5
+ * Soft rule: module≠file and process-nest disagreement are gaps (never hard
6
+ * fails). Module without a file anchor on a grounded component is an issue.
7
+ */
8
+ import type { SubsystemComponent } from '../types/subsystem-model';
9
+ import type { C4AuditElement } from './c4';
10
+ export type BoundaryCheckKind = 'module_file' | 'process_nest' | 'process_claim' | 'process_container' | 'skipped';
11
+ export type BoundaryCheckVerdict = 'ok' | 'issue' | 'gap' | 'skipped';
12
+ export interface BoundaryComponentCheck {
13
+ componentAlias: string;
14
+ componentName?: string;
15
+ kind: BoundaryCheckKind;
16
+ module?: string;
17
+ file?: string;
18
+ process?: string;
19
+ verdict: BoundaryCheckVerdict;
20
+ note?: string;
21
+ }
22
+ export interface BoundaryAuditFinding {
23
+ kind: 'boundary_module_file_mismatch' | 'boundary_process_nest_disagree' | 'boundary_process_missing' | 'boundary_process_unassigned' | 'boundary_process_proposed' | 'boundary_process_rejected' | 'boundary_process_unbacked';
24
+ severity: 'error' | 'info';
25
+ componentAlias?: string;
26
+ componentName?: string;
27
+ /** Module key when the finding is about a multi-member module group. */
28
+ moduleKey?: string;
29
+ /** Process key when the finding is about a process boundary as a whole. */
30
+ processKey?: string;
31
+ message: string;
32
+ }
33
+ export interface BoundaryAuditResult {
34
+ checks: BoundaryComponentCheck[];
35
+ findings: BoundaryAuditFinding[];
36
+ summary: {
37
+ /** Components with a non-empty module claim. */
38
+ modulesClaimed: number;
39
+ moduleFileOk: number;
40
+ moduleFileMismatch: number;
41
+ /** Multi-member module groups inspected for process nest. */
42
+ processNestsChecked: number;
43
+ processNestOk: number;
44
+ processNestDisagree: number;
45
+ /** Runtime-executing components that must state a deployment unit. */
46
+ processRequired: number;
47
+ processClaimed: number;
48
+ processMissing: number;
49
+ };
50
+ }
51
+ /** Normalize path-ish strings for module/file comparison. */
52
+ export declare function normalizeBoundaryPath(p: string): string;
53
+ /**
54
+ * True when `module` is the file itself or a directory prefix of it
55
+ * (sensible parent path for a frame).
56
+ */
57
+ export declare function moduleAgreesWithFile(module: string, file: string): boolean;
58
+ /** True when this component must carry a `process` claim. */
59
+ export declare function requiresProcess(c: SubsystemComponent): boolean;
60
+ /**
61
+ * Audit process/module membership fields on components.
62
+ *
63
+ * `augmentedModuleAliases` — component aliases with an accepted
64
+ * module-boundary augmentation confirming an intentional module≠file
65
+ * grouping.
66
+ */
67
+ export declare function auditBoundaryFields(components: readonly SubsystemComponent[], opts?: {
68
+ augmentedModuleAliases?: ReadonlySet<string>;
69
+ }): BoundaryAuditResult;
70
+ /**
71
+ * Which runtime components have NO verified key to assign a process from —
72
+ * a required process claim whose repo's element set holds no accepted
73
+ * container. Pure over its inputs.
74
+ */
75
+ export declare function auditProcessBacking(components: readonly SubsystemComponent[], sets: ReadonlyMap<string, readonly C4AuditElement[]>): BoundaryAuditFinding[];
76
+ /**
77
+ * One finding per claim-less component. The verification pass reports every
78
+ * claim-less runtime component as `boundary_process_missing`; the backing pass
79
+ * reports the subset with no accepted container as `boundary_process_unbacked`.
80
+ * This drops the missing finding for any component the backing pass already
81
+ * named as unbacked — missing survives only for backed gaps.
82
+ *
83
+ * Pure over its inputs; returns a new array.
84
+ */
85
+ export declare function dropUnbackedMissing<F extends {
86
+ kind: string;
87
+ componentAlias?: string | null;
88
+ }>(findings: readonly F[]): F[];
89
+ /**
90
+ * Process-boundary verification against the C4 element store — the same read
91
+ * the renderer's issues list does. One finding per boundary that is NOT
92
+ * verified; `verified` reports nothing.
93
+ *
94
+ * Each finding carries a backing `process_container` check per member alias
95
+ * (verdict `gap` when unverified), so the lane tallies see the same state the
96
+ * issues list shows.
97
+ *
98
+ * Pure over its inputs; the caller reads the element set(s) from disk.
99
+ */
100
+ export declare function auditProcessVerification(components: readonly SubsystemComponent[], elements: readonly C4AuditElement[]): {
101
+ checks: BoundaryComponentCheck[];
102
+ findings: BoundaryAuditFinding[];
103
+ };
104
+ //# sourceMappingURL=boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/audit/boundary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAI1C,MAAM,MAAM,iBAAiB,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ify.
5
+ *
6
+ * Soft rule: module≠file and process-nest disagreement are gaps (never hard
7
+ * fails). Module without a file anchor on a grounded component is an issue.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.auditProcessVerification = exports.dropUnbackedMissing = exports.auditProcessBacking = exports.auditBoundaryFields = exports.requiresProcess = exports.moduleAgreesWithFile = exports.normalizeBoundaryPath = void 0;
11
+ const subsystem_model_1 = require("../types/subsystem-model");
12
+ const c4_1 = require("./c4");
13
+ const paths_1 = require("./paths");
14
+ /** Normalize path-ish strings for module/file comparison. */
15
+ function normalizeBoundaryPath(p) {
16
+ return p.trim().replace(/\\/g, '/').replace(/^\.\//, '');
17
+ }
18
+ exports.normalizeBoundaryPath = normalizeBoundaryPath;
19
+ /**
20
+ * True when `module` is the file itself or a directory prefix of it
21
+ * (sensible parent path for a frame).
22
+ */
23
+ function moduleAgreesWithFile(module, file) {
24
+ const m = normalizeBoundaryPath(module);
25
+ const f = normalizeBoundaryPath(file);
26
+ if (!m || !f)
27
+ return false;
28
+ if (m === f)
29
+ return true;
30
+ const prefix = m.endsWith('/') ? m : `${m}/`;
31
+ return f.startsWith(prefix);
32
+ }
33
+ exports.moduleAgreesWithFile = moduleAgreesWithFile;
34
+ function isUngrounded(c) {
35
+ return c.construct === 'external';
36
+ }
37
+ /**
38
+ * Constructs that must state a deployment unit (`process`).
39
+ *
40
+ * Required — runtime-executing declarations. A reader needs `process` to know
41
+ * where the code actually runs: function, class, custom_entity.
42
+ *
43
+ * Allowed but not required — type-only declarations are erased at compile
44
+ * time, and a shared type is often legitimately reachable from several
45
+ * processes at once.
46
+ *
47
+ * Not enforced — `external` is third-party (no owner in this repo); `store`
48
+ * is a state container rather than a deployment unit.
49
+ */
50
+ const PROCESS_REQUIRED_CONSTRUCTS = new Set([
51
+ 'function',
52
+ 'class',
53
+ 'custom_entity',
54
+ ]);
55
+ /** True when this component must carry a `process` claim. */
56
+ function requiresProcess(c) {
57
+ if (isUngrounded(c))
58
+ return false;
59
+ return PROCESS_REQUIRED_CONSTRUCTS.has(c.construct ?? '');
60
+ }
61
+ exports.requiresProcess = requiresProcess;
62
+ /**
63
+ * Audit process/module membership fields on components.
64
+ *
65
+ * `augmentedModuleAliases` — component aliases with an accepted
66
+ * module-boundary augmentation confirming an intentional module≠file
67
+ * grouping.
68
+ */
69
+ function auditBoundaryFields(components, opts) {
70
+ const checks = [];
71
+ const findings = [];
72
+ const augmented = opts?.augmentedModuleAliases;
73
+ let modulesClaimed = 0;
74
+ let moduleFileOk = 0;
75
+ let moduleFileMismatch = 0;
76
+ let processNestsChecked = 0;
77
+ let processNestOk = 0;
78
+ let processNestDisagree = 0;
79
+ let processRequired = 0;
80
+ let processClaimed = 0;
81
+ let processMissing = 0;
82
+ const byModule = new Map();
83
+ for (const c of components) {
84
+ const moduleRaw = c.module?.trim() ?? '';
85
+ const fileRaw = c.file?.trim() ?? '';
86
+ const processRaw = c.process?.trim() ?? '';
87
+ /*
88
+ * Dynamic topology, independent of module. A runtime-executing component
89
+ * must name its deployment unit whether or not it sits in a module group.
90
+ * Types are exempt but may still claim one.
91
+ */
92
+ if (requiresProcess(c)) {
93
+ processRequired++;
94
+ if (processRaw) {
95
+ processClaimed++;
96
+ checks.push({
97
+ componentAlias: c.alias,
98
+ componentName: c.name,
99
+ kind: 'process_claim',
100
+ process: processRaw,
101
+ verdict: 'ok',
102
+ note: `process claimed (${processRaw})`,
103
+ });
104
+ }
105
+ else {
106
+ processMissing++;
107
+ const note = `${c.construct ?? 'component'} claims no process — no deployment unit stated`;
108
+ checks.push({
109
+ componentAlias: c.alias,
110
+ componentName: c.name,
111
+ kind: 'process_claim',
112
+ verdict: 'gap',
113
+ note,
114
+ });
115
+ findings.push({
116
+ kind: 'boundary_process_missing',
117
+ severity: 'info',
118
+ componentAlias: c.alias,
119
+ componentName: c.name,
120
+ message: note,
121
+ });
122
+ }
123
+ }
124
+ if (!moduleRaw)
125
+ continue;
126
+ modulesClaimed++;
127
+ const modNorm = normalizeBoundaryPath(moduleRaw);
128
+ const members = byModule.get(modNorm) ?? [];
129
+ members.push(c);
130
+ byModule.set(modNorm, members);
131
+ if (!fileRaw) {
132
+ // A grounded component with a module but no file is rejected at input.
133
+ // Externals carry no file by design, so they are skipped rather than
134
+ // flagged.
135
+ if (isUngrounded(c)) {
136
+ checks.push({
137
+ componentAlias: c.alias,
138
+ componentName: c.name,
139
+ kind: 'module_file',
140
+ module: moduleRaw,
141
+ file: '',
142
+ process: processRaw || undefined,
143
+ verdict: 'skipped',
144
+ note: 'module on external — no file required',
145
+ });
146
+ }
147
+ continue;
148
+ }
149
+ if (moduleAgreesWithFile(moduleRaw, fileRaw)) {
150
+ moduleFileOk++;
151
+ checks.push({
152
+ componentAlias: c.alias,
153
+ componentName: c.name,
154
+ kind: 'module_file',
155
+ module: moduleRaw,
156
+ file: fileRaw,
157
+ process: processRaw || undefined,
158
+ verdict: 'ok',
159
+ note: 'module matches file (or is a path prefix)',
160
+ });
161
+ continue;
162
+ }
163
+ if (augmented?.has(c.alias)) {
164
+ moduleFileOk++;
165
+ checks.push({
166
+ componentAlias: c.alias,
167
+ componentName: c.name,
168
+ kind: 'module_file',
169
+ module: moduleRaw,
170
+ file: fileRaw,
171
+ process: processRaw || undefined,
172
+ verdict: 'ok',
173
+ note: 'module≠file confirmed (augmented)',
174
+ });
175
+ continue;
176
+ }
177
+ moduleFileMismatch++;
178
+ const note = `module ${JSON.stringify(moduleRaw)} does not match file ${JSON.stringify(fileRaw)} (and is not a path prefix)`;
179
+ checks.push({
180
+ componentAlias: c.alias,
181
+ componentName: c.name,
182
+ kind: 'module_file',
183
+ module: moduleRaw,
184
+ file: fileRaw,
185
+ process: processRaw || undefined,
186
+ verdict: 'gap',
187
+ note,
188
+ });
189
+ findings.push({
190
+ kind: 'boundary_module_file_mismatch',
191
+ severity: 'info',
192
+ componentAlias: c.alias,
193
+ componentName: c.name,
194
+ moduleKey: modNorm,
195
+ message: note,
196
+ });
197
+ }
198
+ for (const [moduleKey, members] of byModule) {
199
+ if (members.length < 2)
200
+ continue;
201
+ processNestsChecked++;
202
+ const processes = new Set();
203
+ for (const m of members) {
204
+ const p = m.process?.trim();
205
+ if (p)
206
+ processes.add(p);
207
+ }
208
+ // Empty process on some members is fine for nest; disagreement is
209
+ // two+ distinct non-empty process values among members.
210
+ if (processes.size <= 1) {
211
+ processNestOk++;
212
+ for (const m of members) {
213
+ checks.push({
214
+ componentAlias: m.alias,
215
+ componentName: m.name,
216
+ kind: 'process_nest',
217
+ module: moduleKey,
218
+ process: m.process?.trim() || undefined,
219
+ verdict: 'ok',
220
+ note: processes.size === 1
221
+ ? `module nest agrees under process ${JSON.stringify([...processes][0])}`
222
+ : 'multi-member module with no process claims — nest n/a',
223
+ });
224
+ }
225
+ continue;
226
+ }
227
+ processNestDisagree++;
228
+ const list = [...processes].sort().map((p) => JSON.stringify(p)).join(', ');
229
+ const note = `module ${JSON.stringify(moduleKey)} members claim different processes: ${list}`;
230
+ for (const m of members) {
231
+ checks.push({
232
+ componentAlias: m.alias,
233
+ componentName: m.name,
234
+ kind: 'process_nest',
235
+ module: moduleKey,
236
+ process: m.process?.trim() || undefined,
237
+ verdict: 'gap',
238
+ note,
239
+ });
240
+ findings.push({
241
+ kind: 'boundary_process_nest_disagree',
242
+ severity: 'info',
243
+ componentAlias: m.alias,
244
+ componentName: m.name,
245
+ moduleKey,
246
+ message: note,
247
+ });
248
+ }
249
+ }
250
+ return {
251
+ checks,
252
+ findings,
253
+ summary: {
254
+ modulesClaimed,
255
+ moduleFileOk,
256
+ moduleFileMismatch,
257
+ processNestsChecked,
258
+ processNestOk,
259
+ processNestDisagree,
260
+ processRequired,
261
+ processClaimed,
262
+ processMissing,
263
+ },
264
+ };
265
+ }
266
+ exports.auditBoundaryFields = auditBoundaryFields;
267
+ /**
268
+ * Which runtime components have NO verified key to assign a process from —
269
+ * a required process claim whose repo's element set holds no accepted
270
+ * container. Pure over its inputs.
271
+ */
272
+ function auditProcessBacking(components, sets) {
273
+ const findings = [];
274
+ for (const c of components) {
275
+ if (!requiresProcess(c))
276
+ continue;
277
+ if (c.process?.trim())
278
+ continue;
279
+ const repoKey = (0, paths_1.purlRepoKey)(c.purl);
280
+ const set = repoKey ? sets.get(repoKey) : undefined;
281
+ const hasBackableKey = (set ?? []).some((e) => e.kind === 'container' && e.state === 'accepted' && e.process?.trim());
282
+ if (hasBackableKey)
283
+ continue;
284
+ findings.push({
285
+ kind: 'boundary_process_unbacked',
286
+ severity: 'info',
287
+ componentAlias: c.alias,
288
+ componentName: c.name,
289
+ message: `${c.construct ?? 'component'} ${JSON.stringify(c.alias)} claims no process and no accepted container exists to assign it from — accept a container for this boundary first (container-verifier).`,
290
+ });
291
+ }
292
+ return findings;
293
+ }
294
+ exports.auditProcessBacking = auditProcessBacking;
295
+ /**
296
+ * One finding per claim-less component. The verification pass reports every
297
+ * claim-less runtime component as `boundary_process_missing`; the backing pass
298
+ * reports the subset with no accepted container as `boundary_process_unbacked`.
299
+ * This drops the missing finding for any component the backing pass already
300
+ * named as unbacked — missing survives only for backed gaps.
301
+ *
302
+ * Pure over its inputs; returns a new array.
303
+ */
304
+ function dropUnbackedMissing(findings) {
305
+ const unbackedAliases = new Set(findings
306
+ .filter((f) => f.kind === 'boundary_process_unbacked' && f.componentAlias != null)
307
+ .map((f) => f.componentAlias));
308
+ if (unbackedAliases.size === 0)
309
+ return [...findings];
310
+ return findings.filter((f) => !(f.kind === 'boundary_process_missing' &&
311
+ f.componentAlias != null &&
312
+ unbackedAliases.has(f.componentAlias)));
313
+ }
314
+ exports.dropUnbackedMissing = dropUnbackedMissing;
315
+ /**
316
+ * Process-boundary verification against the C4 element store — the same read
317
+ * the renderer's issues list does. One finding per boundary that is NOT
318
+ * verified; `verified` reports nothing.
319
+ *
320
+ * Each finding carries a backing `process_container` check per member alias
321
+ * (verdict `gap` when unverified), so the lane tallies see the same state the
322
+ * issues list shows.
323
+ *
324
+ * Pure over its inputs; the caller reads the element set(s) from disk.
325
+ */
326
+ function auditProcessVerification(components, elements) {
327
+ const rollup = (0, subsystem_model_1.getSubsystemProcessRegions)({ components });
328
+ const statuses = (0, c4_1.verifyProcessBoundaries)({ rollup, elements });
329
+ const nameByAlias = new Map(components.map((c) => [c.alias, c.name]));
330
+ const checks = [];
331
+ const findings = [];
332
+ for (const { key, status, memberAliases, element } of statuses) {
333
+ const verified = status === 'verified';
334
+ for (const alias of memberAliases) {
335
+ checks.push({
336
+ componentAlias: alias,
337
+ componentName: nameByAlias.get(alias),
338
+ kind: 'process_container',
339
+ process: key,
340
+ verdict: verified ? 'ok' : 'gap',
341
+ note: verified
342
+ ? `boundary ${JSON.stringify(key)} verified by container ${JSON.stringify(element?.label ?? element?.id ?? key)}`
343
+ : `boundary ${JSON.stringify(key)} has no accepted container (${status})`,
344
+ });
345
+ }
346
+ if (verified)
347
+ continue;
348
+ const label = element?.label ?? key;
349
+ findings.push({
350
+ kind: `boundary_process_${status}`,
351
+ severity: 'info',
352
+ processKey: key,
353
+ message: status === 'unassigned'
354
+ ? `No C4 container claims the process boundary ${JSON.stringify(key)} yet — a container-verifier run would assess it.`
355
+ : status === 'proposed'
356
+ ? `Container ${JSON.stringify(label)} claims the process boundary ${JSON.stringify(key)} and awaits a decision.`
357
+ : `Container ${JSON.stringify(label)} was rejected for the process boundary ${JSON.stringify(key)} — it stays unclaimed until a container is accepted.`,
358
+ });
359
+ }
360
+ return { checks, findings };
361
+ }
362
+ exports.auditProcessVerification = auditProcessVerification;
363
+ //# sourceMappingURL=boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../src/audit/boundary.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,8DAAqE;AAErE,6BAA8C;AAC9C,mCAAqC;AA4DrC,6DAA6D;AAC7D,SAAgB,qBAAqB,CAAC,CAAS;IAC7C,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAA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K,GAAG,OAAO,EAAE,KAAK,IAAI,GAAG,CAAA;QACnC,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,oBAAoB,MAAM,EAAE;YAClC,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,GAAG;YACf,OAAO,EACL,MAAM,KAAK,YAAY;gBACrB,CAAC,CAAC,+CAA+C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kDAAkD;gBACtH,CAAC,CAAC,MAAM,KAAK,UAAU;oBACrB,CAAC,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,yBAAyB;oBAChH,CAAC,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,0CAA0C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,sDAAsD;SAC9J,CAAC,CAAA;KACH;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC7B,CAAC;AAtCD,4DAsCC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Minimal C4 read-side used by the audit engine.
3
+ *
4
+ * The full C4 model lives in the viewer package. The audit only needs to read
5
+ * a container's `process` claim and review state, so it takes a structural
6
+ * element shape here instead of depending on the renderer.
7
+ */
8
+ export type C4AuditElementState = 'proposed' | 'accepted' | 'rejected';
9
+ export interface C4AuditElement {
10
+ id: string;
11
+ kind: string;
12
+ state: C4AuditElementState;
13
+ process?: string;
14
+ label?: string;
15
+ }
16
+ export type C4ProcessVerification = 'unassigned' | 'proposed' | 'rejected' | 'verified';
17
+ export interface C4ProcessBoundaryStatus {
18
+ /** The `process` key, e.g. `principal-studio/host`. */
19
+ key: string;
20
+ /** Aliases carrying this key in the model, when the caller supplied them. */
21
+ memberAliases: string[];
22
+ status: C4ProcessVerification;
23
+ /** The container whose state decided the status. Absent when `unassigned`. */
24
+ element?: C4AuditElement;
25
+ }
26
+ /**
27
+ * Read a process boundary's verification off its container assignment.
28
+ *
29
+ * The claimant is the container whose `process` equals the boundary's key —
30
+ * a plain string match. When several containers claim one key, the decided one
31
+ * wins: accepted over rejected over proposed, so one reviewer's yes outranks
32
+ * another's no. Pure.
33
+ */
34
+ export declare function verifyProcessBoundaries(options: {
35
+ rollup: ReadonlyArray<{
36
+ key: string;
37
+ memberAliases?: readonly string[];
38
+ }>;
39
+ elements: readonly C4AuditElement[];
40
+ }): C4ProcessBoundaryStatus[];
41
+ //# sourceMappingURL=c4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.d.ts","sourceRoot":"","sources":["../../src/audit/c4.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAA;AAEtE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,mBAAmB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,UAAU,GACV,UAAU,GACV,UAAU,CAAA;AAEd,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,GAAG,EAAE,MAAM,CAAA;IACX,6EAA6E;IAC7E,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,MAAM,EAAE,qBAAqB,CAAA;IAC7B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,MAAM,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;IACzE,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAA;CACpC,GAAG,uBAAuB,EAAE,CAwB5B"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal C4 read-side used by the audit engine.
4
+ *
5
+ * The full C4 model lives in the viewer package. The audit only needs to read
6
+ * a container's `process` claim and review state, so it takes a structural
7
+ * element shape here instead of depending on the renderer.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.verifyProcessBoundaries = void 0;
11
+ /**
12
+ * Read a process boundary's verification off its container assignment.
13
+ *
14
+ * The claimant is the container whose `process` equals the boundary's key —
15
+ * a plain string match. When several containers claim one key, the decided one
16
+ * wins: accepted over rejected over proposed, so one reviewer's yes outranks
17
+ * another's no. Pure.
18
+ */
19
+ function verifyProcessBoundaries(options) {
20
+ const byKey = new Map();
21
+ for (const element of options.elements) {
22
+ if (element.kind !== 'container' || !element.process)
23
+ continue;
24
+ const list = byKey.get(element.process) ?? [];
25
+ list.push(element);
26
+ byKey.set(element.process, list);
27
+ }
28
+ const precedence = { accepted: 0, rejected: 1, proposed: 2 };
29
+ return options.rollup.map(({ key, memberAliases }) => {
30
+ const aliases = [...(memberAliases ?? [])];
31
+ const claimants = byKey.get(key) ?? [];
32
+ if (claimants.length === 0) {
33
+ return { key, memberAliases: aliases, status: 'unassigned' };
34
+ }
35
+ const decided = [...claimants].sort((a, b) => precedence[a.state] - precedence[b.state] || a.id.localeCompare(b.id))[0];
36
+ const status = decided.state === 'accepted' ? 'verified' : decided.state;
37
+ return { key, memberAliases: aliases, status, element: decided };
38
+ });
39
+ }
40
+ exports.verifyProcessBoundaries = verifyProcessBoundaries;
41
+ //# sourceMappingURL=c4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.js","sourceRoot":"","sources":["../../src/audit/c4.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA4BH;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAC,OAGvC;IACC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAA;IACjD,KAAK,MAAM,OAAO,IAAI,OAAO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