rosettify 2.4.5 → 3.1.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 (165) hide show
  1. package/dist/commands/plan/core.d.ts +2 -1
  2. package/dist/commands/plan/core.d.ts.map +1 -1
  3. package/dist/commands/plan/core.js +6 -26
  4. package/dist/commands/plan/core.js.map +1 -1
  5. package/dist/commands/plan/errors.d.ts +6 -2
  6. package/dist/commands/plan/errors.d.ts.map +1 -1
  7. package/dist/commands/plan/errors.js +6 -2
  8. package/dist/commands/plan/errors.js.map +1 -1
  9. package/dist/commands/plan/next.js +3 -3
  10. package/dist/commands/plan/next.js.map +1 -1
  11. package/dist/commands/plan/query.js +3 -3
  12. package/dist/commands/plan/query.js.map +1 -1
  13. package/dist/commands/plan/show-status.js +3 -3
  14. package/dist/commands/plan/show-status.js.map +1 -1
  15. package/dist/commands/plan/update-status.js +1 -1
  16. package/dist/commands/plan/update-status.js.map +1 -1
  17. package/dist/commands/plan/upsert.js +2 -2
  18. package/dist/commands/plan/upsert.js.map +1 -1
  19. package/dist/commands/specs/add.d.ts +12 -0
  20. package/dist/commands/specs/add.d.ts.map +1 -0
  21. package/dist/commands/specs/add.js +127 -0
  22. package/dist/commands/specs/add.js.map +1 -0
  23. package/dist/commands/specs/aggregate.d.ts +12 -0
  24. package/dist/commands/specs/aggregate.d.ts.map +1 -0
  25. package/dist/commands/specs/aggregate.js +14 -0
  26. package/dist/commands/specs/aggregate.js.map +1 -0
  27. package/dist/commands/specs/approve.d.ts +4 -0
  28. package/dist/commands/specs/approve.d.ts.map +1 -0
  29. package/dist/commands/specs/approve.js +69 -0
  30. package/dist/commands/specs/approve.js.map +1 -0
  31. package/dist/commands/specs/core.d.ts +123 -0
  32. package/dist/commands/specs/core.d.ts.map +1 -0
  33. package/dist/commands/specs/core.js +284 -0
  34. package/dist/commands/specs/core.js.map +1 -0
  35. package/dist/commands/specs/delete.d.ts +4 -0
  36. package/dist/commands/specs/delete.d.ts.map +1 -0
  37. package/dist/commands/specs/delete.js +36 -0
  38. package/dist/commands/specs/delete.js.map +1 -0
  39. package/dist/commands/specs/deprecate.d.ts +4 -0
  40. package/dist/commands/specs/deprecate.d.ts.map +1 -0
  41. package/dist/commands/specs/deprecate.js +51 -0
  42. package/dist/commands/specs/deprecate.js.map +1 -0
  43. package/dist/commands/specs/errors.d.ts +69 -0
  44. package/dist/commands/specs/errors.d.ts.map +1 -0
  45. package/dist/commands/specs/errors.js +114 -0
  46. package/dist/commands/specs/errors.js.map +1 -0
  47. package/dist/commands/specs/get.d.ts +4 -0
  48. package/dist/commands/specs/get.d.ts.map +1 -0
  49. package/dist/commands/specs/get.js +37 -0
  50. package/dist/commands/specs/get.js.map +1 -0
  51. package/dist/commands/specs/graph.d.ts +33 -0
  52. package/dist/commands/specs/graph.d.ts.map +1 -0
  53. package/dist/commands/specs/graph.js +179 -0
  54. package/dist/commands/specs/graph.js.map +1 -0
  55. package/dist/commands/specs/help-content.d.ts +226 -0
  56. package/dist/commands/specs/help-content.d.ts.map +1 -0
  57. package/dist/commands/specs/help-content.js +328 -0
  58. package/dist/commands/specs/help-content.js.map +1 -0
  59. package/dist/commands/specs/implemented.d.ts +4 -0
  60. package/dist/commands/specs/implemented.d.ts.map +1 -0
  61. package/dist/commands/specs/implemented.js +69 -0
  62. package/dist/commands/specs/implemented.js.map +1 -0
  63. package/dist/commands/specs/index.d.ts +4 -0
  64. package/dist/commands/specs/index.d.ts.map +1 -0
  65. package/dist/commands/specs/index.js +282 -0
  66. package/dist/commands/specs/index.js.map +1 -0
  67. package/dist/commands/specs/info.d.ts +4 -0
  68. package/dist/commands/specs/info.d.ts.map +1 -0
  69. package/dist/commands/specs/info.js +78 -0
  70. package/dist/commands/specs/info.js.map +1 -0
  71. package/dist/commands/specs/migrate.d.ts +4 -0
  72. package/dist/commands/specs/migrate.d.ts.map +1 -0
  73. package/dist/commands/specs/migrate.js +124 -0
  74. package/dist/commands/specs/migrate.js.map +1 -0
  75. package/dist/commands/specs/output.d.ts +152 -0
  76. package/dist/commands/specs/output.d.ts.map +1 -0
  77. package/dist/commands/specs/output.js +45 -0
  78. package/dist/commands/specs/output.js.map +1 -0
  79. package/dist/commands/specs/purge.d.ts +4 -0
  80. package/dist/commands/specs/purge.d.ts.map +1 -0
  81. package/dist/commands/specs/purge.js +58 -0
  82. package/dist/commands/specs/purge.js.map +1 -0
  83. package/dist/commands/specs/query-filter.d.ts +26 -0
  84. package/dist/commands/specs/query-filter.d.ts.map +1 -0
  85. package/dist/commands/specs/query-filter.js +275 -0
  86. package/dist/commands/specs/query-filter.js.map +1 -0
  87. package/dist/commands/specs/query.d.ts +4 -0
  88. package/dist/commands/specs/query.d.ts.map +1 -0
  89. package/dist/commands/specs/query.js +35 -0
  90. package/dist/commands/specs/query.js.map +1 -0
  91. package/dist/commands/specs/render.d.ts +9 -0
  92. package/dist/commands/specs/render.d.ts.map +1 -0
  93. package/dist/commands/specs/render.js +129 -0
  94. package/dist/commands/specs/render.js.map +1 -0
  95. package/dist/commands/specs/reopen.d.ts +4 -0
  96. package/dist/commands/specs/reopen.d.ts.map +1 -0
  97. package/dist/commands/specs/reopen.js +47 -0
  98. package/dist/commands/specs/reopen.js.map +1 -0
  99. package/dist/commands/specs/req-parser.d.ts +55 -0
  100. package/dist/commands/specs/req-parser.d.ts.map +1 -0
  101. package/dist/commands/specs/req-parser.js +325 -0
  102. package/dist/commands/specs/req-parser.js.map +1 -0
  103. package/dist/commands/specs/restore.d.ts +4 -0
  104. package/dist/commands/specs/restore.d.ts.map +1 -0
  105. package/dist/commands/specs/restore.js +46 -0
  106. package/dist/commands/specs/restore.js.map +1 -0
  107. package/dist/commands/specs/rubric.d.ts +18 -0
  108. package/dist/commands/specs/rubric.d.ts.map +1 -0
  109. package/dist/commands/specs/rubric.js +86 -0
  110. package/dist/commands/specs/rubric.js.map +1 -0
  111. package/dist/commands/specs/schemas.d.ts +687 -0
  112. package/dist/commands/specs/schemas.d.ts.map +1 -0
  113. package/dist/commands/specs/schemas.js +454 -0
  114. package/dist/commands/specs/schemas.js.map +1 -0
  115. package/dist/commands/specs/update.d.ts +4 -0
  116. package/dist/commands/specs/update.d.ts.map +1 -0
  117. package/dist/commands/specs/update.js +139 -0
  118. package/dist/commands/specs/update.js.map +1 -0
  119. package/dist/commands/specs/validate.d.ts +13 -0
  120. package/dist/commands/specs/validate.d.ts.map +1 -0
  121. package/dist/commands/specs/validate.js +165 -0
  122. package/dist/commands/specs/validate.js.map +1 -0
  123. package/dist/commands/specs/write.d.ts +38 -0
  124. package/dist/commands/specs/write.d.ts.map +1 -0
  125. package/dist/commands/specs/write.js +65 -0
  126. package/dist/commands/specs/write.js.map +1 -0
  127. package/dist/frontends/cli.d.ts.map +1 -1
  128. package/dist/frontends/cli.js +186 -0
  129. package/dist/frontends/cli.js.map +1 -1
  130. package/dist/registry/index.d.ts.map +1 -1
  131. package/dist/registry/index.js +2 -0
  132. package/dist/registry/index.js.map +1 -1
  133. package/dist/registry/types.d.ts +22 -0
  134. package/dist/registry/types.d.ts.map +1 -1
  135. package/dist/shared/actor.d.ts +8 -0
  136. package/dist/shared/actor.d.ts.map +1 -0
  137. package/dist/shared/actor.js +65 -0
  138. package/dist/shared/actor.js.map +1 -0
  139. package/dist/shared/constants.d.ts +6 -0
  140. package/dist/shared/constants.d.ts.map +1 -1
  141. package/dist/shared/constants.js +8 -1
  142. package/dist/shared/constants.js.map +1 -1
  143. package/dist/shared/dispatch.d.ts.map +1 -1
  144. package/dist/shared/dispatch.js +2 -0
  145. package/dist/shared/dispatch.js.map +1 -1
  146. package/dist/shared/doc-io.d.ts +46 -0
  147. package/dist/shared/doc-io.d.ts.map +1 -0
  148. package/dist/shared/{plan-io.js → doc-io.js} +23 -18
  149. package/dist/shared/doc-io.js.map +1 -0
  150. package/dist/shared/errors.d.ts +3 -0
  151. package/dist/shared/errors.d.ts.map +1 -0
  152. package/dist/shared/errors.js +6 -0
  153. package/dist/shared/errors.js.map +1 -0
  154. package/dist/shared/graph.d.ts +6 -0
  155. package/dist/shared/graph.d.ts.map +1 -0
  156. package/dist/shared/graph.js +34 -0
  157. package/dist/shared/graph.js.map +1 -0
  158. package/dist/shared/time.d.ts +9 -0
  159. package/dist/shared/time.d.ts.map +1 -0
  160. package/dist/shared/time.js +20 -0
  161. package/dist/shared/time.js.map +1 -0
  162. package/package.json +2 -1
  163. package/dist/shared/plan-io.d.ts +0 -41
  164. package/dist/shared/plan-io.d.ts.map +0 -1
  165. package/dist/shared/plan-io.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ /** FR-SPECS-0071 — document file (and no backup) truly absent. */
2
+ export declare const ERR_SPECS_NOT_FOUND = "specs_not_found";
3
+ /** FR-SPECS-0071 — document file exists but does not parse as the specs schema. */
4
+ export declare const ERR_SPECS_FILE_CORRUPTED = "specs_file_corrupted";
5
+ /** FR-SPECS-0013 — data payload could not be parsed as JSON. */
6
+ export declare const ERR_INVALID_DATA = "invalid_data";
7
+ /** FR-SPECS-0013 — no data payload supplied at all. */
8
+ export declare const ERR_MISSING_DATA = "missing_data";
9
+ /** FR-SPECS-0004 — a spec item is missing its required id on add. */
10
+ export declare const ERR_MISSING_ID = "missing_id";
11
+ /** FR-SPECS-0005 — a spec id is already used by another spec in the document. */
12
+ export declare const ERR_DUPLICATE_ID = "duplicate_id";
13
+ /** FR-SPECS-0004 — a spec id does not match the `<PREFIX>-<AREA>-<NNNN>` format. */
14
+ export declare const ERR_INVALID_ID_FORMAT = "invalid_id_format";
15
+ /** FR-SPECS-0004 — a spec's AREA is not registered in the document and the call does not register it. */
16
+ export declare const ERR_UNKNOWN_AREA = "unknown_area";
17
+ /** FR-SPECS-0003 — a spec's `type` is not one of FR, NFR, INT, DATA. */
18
+ export declare const ERR_INVALID_TYPE = "invalid_type";
19
+ /** FR-SPECS-0001 — a spec's `source` is not one of User, Inferred, Sources, Documentation. */
20
+ export declare const ERR_INVALID_SOURCE = "invalid_source";
21
+ /** FR-SPECS-0001 — a spec's `priority` is not one of Must, Should, Could, Wont. */
22
+ export declare const ERR_INVALID_PRIORITY = "invalid_priority";
23
+ /** FR-SPECS-0001 — a spec's `verification` is not one of Test, Analysis, Inspection, Demo. */
24
+ export declare const ERR_INVALID_VERIFICATION = "invalid_verification";
25
+ /** FR-SPECS-0001 — a spec item carries a field outside the spec schema. */
26
+ export declare const ERR_INVALID_SPEC_FIELD = "invalid_spec_field";
27
+ /** FR-SPECS-0001 — a required field is absent or empty. */
28
+ export declare const ERR_MISSING_REQUIRED_FIELD = "missing_required_field";
29
+ /** FR-SPECS-0005 — a depends_on/related entry references an id absent from the document. */
30
+ export declare const ERR_UNKNOWN_DEPENDENCY = "unknown_dependency";
31
+ /** FR-SPECS-0005 — a depends_on reference would create a cycle (or a spec depends on itself). */
32
+ export declare const ERR_DEPENDENCY_CYCLE = "dependency_cycle";
33
+ /** FR-SPECS-0007 — a configured size limit was exceeded. */
34
+ export declare const ERR_SIZE_LIMIT_EXCEEDED = "size_limit_exceeded";
35
+ /** FR-SPECS-0004 — a patch attempted to change a spec's id. */
36
+ export declare const ERR_IMMUTABLE_ID = "immutable_id";
37
+ /** FR-SPECS-0013 — a target spec id does not exist in the document. */
38
+ export declare const ERR_TARGET_NOT_FOUND = "target_not_found";
39
+ /** FR-SPECS-0015 — implementation value is not one of the allowed enum values. */
40
+ export declare const ERR_INVALID_IMPLEMENTATION = "invalid_implementation";
41
+ /** FR-SPECS-0015 — no implementation value supplied. */
42
+ export declare const ERR_MISSING_IMPLEMENTATION = "missing_implementation";
43
+ /** FR-SPECS-0017..0020 — the requested status change is not a valid transition from the current status. */
44
+ export declare const ERR_INVALID_TRANSITION = "invalid_transition";
45
+ /** FR-SPECS-0017 — one or more approve targets failed validation. */
46
+ export declare const ERR_VALIDATION_FAILED = "validation_failed";
47
+ /** FR-SPECS-0016 — purge requires the --force flag. */
48
+ export declare const ERR_FORCE_REQUIRED = "force_required";
49
+ /** FR-SPECS-0016 — purge target is still referenced by other specs not in the same batch. */
50
+ export declare const ERR_REFERENCED_BY_OTHERS = "referenced_by_others";
51
+ /** FR-SPECS-0012 — query contains an unrecognized filter key. */
52
+ export declare const ERR_INVALID_FILTER = "invalid_filter";
53
+ /** FR-SPECS-0012 — query string is malformed. */
54
+ export declare const ERR_INVALID_QUERY = "invalid_query";
55
+ /** FR-SPECS-0023 — requested render format is not markdown|text. */
56
+ export declare const ERR_INVALID_FORMAT = "invalid_format";
57
+ /** FR-SPECS-0025 — a migrate source path does not exist. */
58
+ export declare const ERR_SOURCE_NOT_FOUND = "source_not_found";
59
+ /** FR-SPECS-0025 — a migrate source contained no parseable spec blocks. */
60
+ export declare const ERR_MIGRATE_PARSE_ERROR = "migrate_parse_error";
61
+ /**
62
+ * FR-SPECS-0070 — rename-as-guard write cycle exhausted retries. Shared with `plan` (not
63
+ * specs-specific); re-exported here so specs call sites have one import surface.
64
+ */
65
+ export { ERR_BACKUP_CREATE_FAILED } from "../../shared/errors.js";
66
+ export declare const TEMPLATES: Readonly<Record<string, string>>;
67
+ /** Returns the generic template for a code, or the code itself if it has no authored template. */
68
+ export declare function describeError(code: string): string;
69
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/errors.ts"],"names":[],"mappings":"AAOA,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,mFAAmF;AACnF,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,qEAAqE;AACrE,eAAO,MAAM,cAAc,eAAe,CAAC;AAC3C,iFAAiF;AACjF,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,yGAAyG;AACzG,eAAO,MAAM,g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O,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D;;;GAGG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AASlE,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BtD,CAAC;AAEF,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
@@ -0,0 +1,114 @@
1
+ // Implements the specs error-code catalog (SPECS §13) and FR-SPECS-0043 (no-internal-leakage
2
+ // for the command's OWN authored surfaces). These templates describe the *kind* of failure in
3
+ // generic terms and never interpolate a Rosetta-internal id, ticket id, or source path. They MAY
4
+ // be composed with caller-supplied data (spec ids, reasons) by aggregate.ts / cmd* callers —
5
+ // that composition is the caller's payload passing through verbatim, which FR-SPECS-0043
6
+ // explicitly exempts from the leakage rule.
7
+ /** FR-SPECS-0071 — document file (and no backup) truly absent. */
8
+ export const ERR_SPECS_NOT_FOUND = "specs_not_found";
9
+ /** FR-SPECS-0071 — document file exists but does not parse as the specs schema. */
10
+ export const ERR_SPECS_FILE_CORRUPTED = "specs_file_corrupted";
11
+ /** FR-SPECS-0013 — data payload could not be parsed as JSON. */
12
+ export const ERR_INVALID_DATA = "invalid_data";
13
+ /** FR-SPECS-0013 — no data payload supplied at all. */
14
+ export const ERR_MISSING_DATA = "missing_data";
15
+ /** FR-SPECS-0004 — a spec item is missing its required id on add. */
16
+ export const ERR_MISSING_ID = "missing_id";
17
+ /** FR-SPECS-0005 — a spec id is already used by another spec in the document. */
18
+ export const ERR_DUPLICATE_ID = "duplicate_id";
19
+ /** FR-SPECS-0004 — a spec id does not match the `<PREFIX>-<AREA>-<NNNN>` format. */
20
+ export const ERR_INVALID_ID_FORMAT = "invalid_id_format";
21
+ /** FR-SPECS-0004 — a spec's AREA is not registered in the document and the call does not register it. */
22
+ export const ERR_UNKNOWN_AREA = "unknown_area";
23
+ /** FR-SPECS-0003 — a spec's `type` is not one of FR, NFR, INT, DATA. */
24
+ export const ERR_INVALID_TYPE = "invalid_type";
25
+ /** FR-SPECS-0001 — a spec's `source` is not one of User, Inferred, Sources, Documentation. */
26
+ export const ERR_INVALID_SOURCE = "invalid_source";
27
+ /** FR-SPECS-0001 — a spec's `priority` is not one of Must, Should, Could, Wont. */
28
+ export const ERR_INVALID_PRIORITY = "invalid_priority";
29
+ /** FR-SPECS-0001 — a spec's `verification` is not one of Test, Analysis, Inspection, Demo. */
30
+ export const ERR_INVALID_VERIFICATION = "invalid_verification";
31
+ /** FR-SPECS-0001 — a spec item carries a field outside the spec schema. */
32
+ export const ERR_INVALID_SPEC_FIELD = "invalid_spec_field";
33
+ /** FR-SPECS-0001 — a required field is absent or empty. */
34
+ export const ERR_MISSING_REQUIRED_FIELD = "missing_required_field";
35
+ /** FR-SPECS-0005 — a depends_on/related entry references an id absent from the document. */
36
+ export const ERR_UNKNOWN_DEPENDENCY = "unknown_dependency";
37
+ /** FR-SPECS-0005 — a depends_on reference would create a cycle (or a spec depends on itself). */
38
+ export const ERR_DEPENDENCY_CYCLE = "dependency_cycle";
39
+ /** FR-SPECS-0007 — a configured size limit was exceeded. */
40
+ export const ERR_SIZE_LIMIT_EXCEEDED = "size_limit_exceeded";
41
+ /** FR-SPECS-0004 — a patch attempted to change a spec's id. */
42
+ export const ERR_IMMUTABLE_ID = "immutable_id";
43
+ /** FR-SPECS-0013 — a target spec id does not exist in the document. */
44
+ export const ERR_TARGET_NOT_FOUND = "target_not_found";
45
+ /** FR-SPECS-0015 — implementation value is not one of the allowed enum values. */
46
+ export const ERR_INVALID_IMPLEMENTATION = "invalid_implementation";
47
+ /** FR-SPECS-0015 — no implementation value supplied. */
48
+ export const ERR_MISSING_IMPLEMENTATION = "missing_implementation";
49
+ /** FR-SPECS-0017..0020 — the requested status change is not a valid transition from the current status. */
50
+ export const ERR_INVALID_TRANSITION = "invalid_transition";
51
+ /** FR-SPECS-0017 — one or more approve targets failed validation. */
52
+ export const ERR_VALIDATION_FAILED = "validation_failed";
53
+ /** FR-SPECS-0016 — purge requires the --force flag. */
54
+ export const ERR_FORCE_REQUIRED = "force_required";
55
+ /** FR-SPECS-0016 — purge target is still referenced by other specs not in the same batch. */
56
+ export const ERR_REFERENCED_BY_OTHERS = "referenced_by_others";
57
+ /** FR-SPECS-0012 — query contains an unrecognized filter key. */
58
+ export const ERR_INVALID_FILTER = "invalid_filter";
59
+ /** FR-SPECS-0012 — query string is malformed. */
60
+ export const ERR_INVALID_QUERY = "invalid_query";
61
+ /** FR-SPECS-0023 — requested render format is not markdown|text. */
62
+ export const ERR_INVALID_FORMAT = "invalid_format";
63
+ /** FR-SPECS-0025 — a migrate source path does not exist. */
64
+ export const ERR_SOURCE_NOT_FOUND = "source_not_found";
65
+ /** FR-SPECS-0025 — a migrate source contained no parseable spec blocks. */
66
+ export const ERR_MIGRATE_PARSE_ERROR = "migrate_parse_error";
67
+ /**
68
+ * FR-SPECS-0070 — rename-as-guard write cycle exhausted retries. Shared with `plan` (not
69
+ * specs-specific); re-exported here so specs call sites have one import surface.
70
+ */
71
+ export { ERR_BACKUP_CREATE_FAILED } from "../../shared/errors.js";
72
+ // ---------------------------------------------------------------------------
73
+ // Message templates (FR-SPECS-0043) — generic, leakage-clean prose per code.
74
+ // No Rosetta id / ticket id / source path / module name ever appears here. Callers (e.g.
75
+ // aggregate.ts) MAY append caller-supplied spec ids / reasons to these — that is the caller's
76
+ // own payload passing through verbatim, which FR-SPECS-0043 explicitly permits.
77
+ // ---------------------------------------------------------------------------
78
+ export const TEMPLATES = {
79
+ [ERR_SPECS_NOT_FOUND]: "The specs document was not found at the given path.",
80
+ [ERR_SPECS_FILE_CORRUPTED]: "The specs document exists but could not be parsed as valid JSON.",
81
+ [ERR_INVALID_DATA]: "The data payload could not be parsed as JSON.",
82
+ [ERR_MISSING_DATA]: "No data payload was supplied.",
83
+ [ERR_MISSING_ID]: "A spec item is missing its required id.",
84
+ [ERR_DUPLICATE_ID]: "A spec id is already used by another spec in this document.",
85
+ [ERR_INVALID_ID_FORMAT]: "A spec id does not match the required <PREFIX>-<AREA>-<NNNN> format.",
86
+ [ERR_UNKNOWN_AREA]: "A spec's area is not registered in this document.",
87
+ [ERR_INVALID_TYPE]: "A spec's type is not one of FR, NFR, INT, DATA.",
88
+ [ERR_INVALID_SOURCE]: "A spec's source is not one of User, Inferred, Sources, Documentation.",
89
+ [ERR_INVALID_PRIORITY]: "A spec's priority is not one of Must, Should, Could, Wont.",
90
+ [ERR_INVALID_VERIFICATION]: "A spec's verification is not one of Test, Analysis, Inspection, Demo.",
91
+ [ERR_INVALID_SPEC_FIELD]: "A spec item carries a field that is not part of the spec schema.",
92
+ [ERR_MISSING_REQUIRED_FIELD]: "A spec item is missing a required field.",
93
+ [ERR_UNKNOWN_DEPENDENCY]: "A depends_on or related reference points to an id that does not exist in this document.",
94
+ [ERR_DEPENDENCY_CYCLE]: "A depends_on reference would create a cycle.",
95
+ [ERR_SIZE_LIMIT_EXCEEDED]: "A configured size limit was exceeded.",
96
+ [ERR_IMMUTABLE_ID]: "A patch attempted to change a spec's id.",
97
+ [ERR_TARGET_NOT_FOUND]: "A target spec id does not exist in this document.",
98
+ [ERR_INVALID_IMPLEMENTATION]: "The implementation value is not one of the allowed values.",
99
+ [ERR_MISSING_IMPLEMENTATION]: "No implementation value was supplied.",
100
+ [ERR_INVALID_TRANSITION]: "The requested status change is not a valid transition from the spec's current status.",
101
+ [ERR_VALIDATION_FAILED]: "One or more targets failed validation and cannot be approved.",
102
+ [ERR_FORCE_REQUIRED]: "Permanent removal is irreversible and requires the force flag.",
103
+ [ERR_REFERENCED_BY_OTHERS]: "One or more targets are still referenced by other specs.",
104
+ [ERR_INVALID_FILTER]: "The query contains an unrecognized filter key.",
105
+ [ERR_INVALID_QUERY]: "The query string is malformed.",
106
+ [ERR_INVALID_FORMAT]: "The requested render format is not supported.",
107
+ [ERR_SOURCE_NOT_FOUND]: "A migration source path does not exist.",
108
+ [ERR_MIGRATE_PARSE_ERROR]: "A migration source contained no parseable spec blocks.",
109
+ };
110
+ /** Returns the generic template for a code, or the code itself if it has no authored template. */
111
+ export function describeError(code) {
112
+ return TEMPLATES[code] ?? code;
113
+ }
114
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/commands/specs/errors.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,8FAA8F;AAC9F,iGAAiG;AACjG,6FAA6F;AAC7F,yFAAyF;AACzF,4CAA4C;AAE5C,kEAAkE;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,mFAAmF;AACnF,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,gEAAgE;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,uDAAuD;AACvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,qEAAqE;AACrE,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,iFAAiF;AACjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,yGAAyG;AACzG,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,8FAA8F;AAC9F,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AACnD,mFAAmF;AACnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AACvD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,2DAA2D;AAC3D,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CAAC,EAAE,+CAA+C;IACrE,CAAC,oBAAoB,CAAC,EAAE,yCAAyC;IACjE,CAAC,uBAAuB,CAAC,EAAE,wDAAwD;CACpF,CAAC;AAEF,kGAAkG;AAClG,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RunEnvelope } from "../../registry/types.js";
2
+ import type { SpecGetResult } from "./output.js";
3
+ export declare function cmdGet(specsFile: string, ids: string[]): Promise<RunEnvelope<SpecGetResult>>;
4
+ //# sourceMappingURL=get.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/get.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAK3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAyBlG"}
@@ -0,0 +1,37 @@
1
+ // Implements FR-SPECS-0011 (get subcommand). By-id retrieval; returns a spec regardless of its
2
+ // status (including Removed, since the caller addressed it explicitly). Never errors on a
3
+ // missing id — it is reported in `missing` instead.
4
+ import { ok, err } from "../../shared/envelope.js";
5
+ import { logger } from "../../shared/logger.js";
6
+ import { readDocWithRetry } from "../../shared/doc-io.js";
7
+ import { ERR_SPECS_FILE_CORRUPTED, ERR_SPECS_NOT_FOUND } from "./errors.js";
8
+ export async function cmdGet(specsFile, ids) {
9
+ try {
10
+ let doc;
11
+ try {
12
+ doc = await readDocWithRetry(specsFile);
13
+ }
14
+ catch {
15
+ return err(ERR_SPECS_FILE_CORRUPTED);
16
+ }
17
+ if (!doc)
18
+ return err(ERR_SPECS_NOT_FOUND);
19
+ const byId = new Map((doc.specs ?? []).map((s) => [s.id, s]));
20
+ const found = [];
21
+ const missing = [];
22
+ for (const id of ids ?? []) {
23
+ const spec = byId.get(id);
24
+ if (spec)
25
+ found.push(spec);
26
+ else
27
+ missing.push(id);
28
+ }
29
+ logger.info({ specsFile, requested: (ids ?? []).length, found: found.length }, "specs get");
30
+ return ok({ found, missing });
31
+ }
32
+ catch (e) {
33
+ const msg = e instanceof Error ? e.message : String(e);
34
+ return err(`internal_error: ${msg}`);
35
+ }
36
+ }
37
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/commands/specs/get.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,0FAA0F;AAC1F,oDAAoD;AAGpD,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,SAAiB,EAAE,GAAa;IAC3D,IAAI,CAAC;QACH,IAAI,GAAyB,CAAC;QAC9B,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,gBAAgB,CAAgB,SAAS,CAAC,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,GAAG;YAAE,OAAO,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE1C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,MAAM,KAAK,GAA2B,EAAE,CAAC;QACzC,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1B,IAAI,IAAI;gBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;gBACtB,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;QAC5F,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { RunEnvelope } from "../../registry/types.js";
2
+ import type { Spec, SpecsDocument } from "./core.js";
3
+ import type { SpecEdge, SpecGraphResult } from "./output.js";
4
+ export interface ResolvedGraph {
5
+ specsById: Map<string, Spec>;
6
+ depends: Map<string, string[]>;
7
+ related: Map<string, string[]>;
8
+ }
9
+ /** Unions the specs of every provided document by id (a later doc's spec wins on id collision —
10
+ * cross-doc resolution is read-only diagnostics, not a merge with defined precedence rules). */
11
+ export declare function buildGraph(docs: SpecsDocument[]): ResolvedGraph;
12
+ /** Transitive forward closure of `start` over `map` (BFS), excluding `start` itself even if a
13
+ * cycle would otherwise bring traversal back to it. */
14
+ export declare function closure(map: Map<string, string[]>, start: string): string[];
15
+ /** The impact set of `start`: every node that transitively depends on it, i.e. `closure` over
16
+ * the reversed adjacency of `map`. */
17
+ export declare function reverseClosure(map: Map<string, string[]>, start: string): string[];
18
+ /**
19
+ * Enumerates every elementary (simple) cycle in `depends` as an edge list. A single-doc
20
+ * depends_on graph is guaranteed acyclic by core.ts's validateDependsAcyclic at write time —
21
+ * this function exists for the cross-document case, where each doc is individually acyclic but
22
+ * their union may not be. Uses the standard "start node is the lexicographically smallest node
23
+ * on the cycle" technique so each cycle is reported exactly once, not once per rotation.
24
+ * Exponential in the worst case (dense cyclic components) — acceptable here since this is a
25
+ * diagnostic/read-only path, never on the write hot path, and real dependency graphs are sparse.
26
+ */
27
+ export declare function enumerateCycles(depends: Map<string, string[]>): SpecEdge[][];
28
+ /** Flattens both adjacency maps into a single edge list (whole-doc graph mode). */
29
+ export declare function edgeList(depends: Map<string, string[]>, related: Map<string, string[]>): SpecEdge[];
30
+ /** Every id referenced by depends_on/related that is absent from the resolved union of docs. */
31
+ export declare function unresolvedRefs(g: ResolvedGraph): string[];
32
+ export declare function cmdGraph(specsFile: string, targetId?: string, additionalPaths?: string[]): Promise<RunEnvelope<SpecGraphResult>>;
33
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/graph.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO7D,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAChC;AAED;gGACgG;AAChG,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,aAAa,CAY/D;AAED;uDACuD;AACvD,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAa3E;AAED;sCACsC;AACtC,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAUlF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,EAAE,EAAE,CA4B5E;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,EAAE,CASnG;AAED,gGAAgG;AAChG,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,EAAE,CASzD;AAUD,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CA8CvC"}
@@ -0,0 +1,179 @@
1
+ // Implements FR-SPECS-0022 (dependency/relation graph analysis). Pure graph primitives per
2
+ // SPECS §11.3, plus the cmdGraph envelope wrapper (SPECS §10) — both completed in this stage
3
+ // per the execution plan (S5), since readDocWithRetry/envelope/logger are all already available
4
+ // from S1/S2 and cmdGraph needs no other S6 subcommand file.
5
+ import { ok, err } from "../../shared/envelope.js";
6
+ import { logger } from "../../shared/logger.js";
7
+ import { readDocWithRetry } from "../../shared/doc-io.js";
8
+ import { ERR_SPECS_FILE_CORRUPTED, ERR_SPECS_NOT_FOUND, ERR_TARGET_NOT_FOUND } from "./errors.js";
9
+ /** Unions the specs of every provided document by id (a later doc's spec wins on id collision —
10
+ * cross-doc resolution is read-only diagnostics, not a merge with defined precedence rules). */
11
+ export function buildGraph(docs) {
12
+ const specsById = new Map();
13
+ const depends = new Map();
14
+ const related = new Map();
15
+ for (const doc of docs) {
16
+ for (const spec of doc.specs ?? []) {
17
+ specsById.set(spec.id, spec);
18
+ depends.set(spec.id, [...(spec.depends_on ?? [])]);
19
+ related.set(spec.id, [...(spec.related ?? [])]);
20
+ }
21
+ }
22
+ return { specsById, depends, related };
23
+ }
24
+ /** Transitive forward closure of `start` over `map` (BFS), excluding `start` itself even if a
25
+ * cycle would otherwise bring traversal back to it. */
26
+ export function closure(map, start) {
27
+ const visited = new Set([start]);
28
+ const result = [];
29
+ const queue = [...(map.get(start) ?? [])];
30
+ let qi = 0;
31
+ while (qi < queue.length) {
32
+ const cur = queue[qi++];
33
+ if (visited.has(cur))
34
+ continue;
35
+ visited.add(cur);
36
+ result.push(cur);
37
+ for (const next of map.get(cur) ?? [])
38
+ queue.push(next);
39
+ }
40
+ return result;
41
+ }
42
+ /** The impact set of `start`: every node that transitively depends on it, i.e. `closure` over
43
+ * the reversed adjacency of `map`. */
44
+ export function reverseClosure(map, start) {
45
+ const reverse = new Map();
46
+ for (const [from, tos] of map) {
47
+ for (const to of tos) {
48
+ const list = reverse.get(to);
49
+ if (list)
50
+ list.push(from);
51
+ else
52
+ reverse.set(to, [from]);
53
+ }
54
+ }
55
+ return closure(reverse, start);
56
+ }
57
+ /**
58
+ * Enumerates every elementary (simple) cycle in `depends` as an edge list. A single-doc
59
+ * depends_on graph is guaranteed acyclic by core.ts's validateDependsAcyclic at write time —
60
+ * this function exists for the cross-document case, where each doc is individually acyclic but
61
+ * their union may not be. Uses the standard "start node is the lexicographically smallest node
62
+ * on the cycle" technique so each cycle is reported exactly once, not once per rotation.
63
+ * Exponential in the worst case (dense cyclic components) — acceptable here since this is a
64
+ * diagnostic/read-only path, never on the write hot path, and real dependency graphs are sparse.
65
+ */
66
+ export function enumerateCycles(depends) {
67
+ const nodes = [...depends.keys()].sort();
68
+ const order = new Map(nodes.map((id, i) => [id, i]));
69
+ const cycles = [];
70
+ const path = [];
71
+ const onPath = new Set();
72
+ function dfs(start, current) {
73
+ path.push(current);
74
+ onPath.add(current);
75
+ for (const next of depends.get(current) ?? []) {
76
+ if (next === start) {
77
+ const edges = path.map((from, i) => ({
78
+ from,
79
+ to: i + 1 < path.length ? path[i + 1] : start,
80
+ kind: "depends_on",
81
+ }));
82
+ cycles.push(edges);
83
+ }
84
+ else if (!onPath.has(next) && (order.get(next) ?? -1) >= (order.get(start) ?? -1)) {
85
+ dfs(start, next);
86
+ }
87
+ }
88
+ path.pop();
89
+ onPath.delete(current);
90
+ }
91
+ for (const start of nodes)
92
+ dfs(start, start);
93
+ return cycles;
94
+ }
95
+ /** Flattens both adjacency maps into a single edge list (whole-doc graph mode). */
96
+ export function edgeList(depends, related) {
97
+ const edges = [];
98
+ for (const [from, tos] of depends) {
99
+ for (const to of tos)
100
+ edges.push({ from, to, kind: "depends_on" });
101
+ }
102
+ for (const [from, tos] of related) {
103
+ for (const to of tos)
104
+ edges.push({ from, to, kind: "related" });
105
+ }
106
+ return edges;
107
+ }
108
+ /** Every id referenced by depends_on/related that is absent from the resolved union of docs. */
109
+ export function unresolvedRefs(g) {
110
+ const unresolved = new Set();
111
+ for (const tos of g.depends.values()) {
112
+ for (const to of tos)
113
+ if (!g.specsById.has(to))
114
+ unresolved.add(to);
115
+ }
116
+ for (const tos of g.related.values()) {
117
+ for (const to of tos)
118
+ if (!g.specsById.has(to))
119
+ unresolved.add(to);
120
+ }
121
+ return [...unresolved];
122
+ }
123
+ // ---------------------------------------------------------------------------
124
+ // cmdGraph — FR-SPECS-0022, SPECS §10. Target mode returns
125
+ // {dependencies, dependents, related, cycles:[], unresolved}; whole-doc mode returns
126
+ // {edges, cycles, unresolved}. Missing target id -> target_not_found. additionalPaths are
127
+ // read best-effort: a missing/corrupted extra doc is skipped (cross-doc resolution is
128
+ // supplementary diagnostics, not a write path with fail-fast integrity requirements).
129
+ // ---------------------------------------------------------------------------
130
+ export async function cmdGraph(specsFile, targetId, additionalPaths) {
131
+ try {
132
+ let doc;
133
+ try {
134
+ doc = await readDocWithRetry(specsFile);
135
+ }
136
+ catch {
137
+ return err(ERR_SPECS_FILE_CORRUPTED);
138
+ }
139
+ if (!doc)
140
+ return err(ERR_SPECS_NOT_FOUND);
141
+ const docs = [doc];
142
+ for (const extraPath of additionalPaths ?? []) {
143
+ try {
144
+ const extra = await readDocWithRetry(extraPath);
145
+ if (extra)
146
+ docs.push(extra);
147
+ }
148
+ catch {
149
+ // best-effort — a corrupted supplementary doc is skipped, not fatal to the primary graph
150
+ }
151
+ }
152
+ const graph = buildGraph(docs);
153
+ if (targetId) {
154
+ if (!graph.specsById.has(targetId))
155
+ return err(ERR_TARGET_NOT_FOUND);
156
+ const result = {
157
+ dependencies: closure(graph.depends, targetId),
158
+ dependents: reverseClosure(graph.depends, targetId),
159
+ related: [...(graph.related.get(targetId) ?? [])],
160
+ cycles: [],
161
+ unresolved: unresolvedRefs(graph),
162
+ };
163
+ logger.info({ specsFile, targetId }, "specs graph: target mode");
164
+ return ok(result);
165
+ }
166
+ const result = {
167
+ edges: edgeList(graph.depends, graph.related),
168
+ cycles: enumerateCycles(graph.depends),
169
+ unresolved: unresolvedRefs(graph),
170
+ };
171
+ logger.info({ specsFile }, "specs graph: whole-doc mode");
172
+ return ok(result);
173
+ }
174
+ catch (e) {
175
+ const msg = e instanceof Error ? e.message : String(e);
176
+ return err(`internal_error: ${msg}`);
177
+ }
178
+ }
179
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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