rosettify 2.4.5 → 3.2.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 (169) 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 +191 -1
  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/logger.d.ts +2 -0
  159. package/dist/shared/logger.d.ts.map +1 -1
  160. package/dist/shared/logger.js +12 -3
  161. package/dist/shared/logger.js.map +1 -1
  162. package/dist/shared/time.d.ts +9 -0
  163. package/dist/shared/time.d.ts.map +1 -0
  164. package/dist/shared/time.js +20 -0
  165. package/dist/shared/time.js.map +1 -0
  166. package/package.json +2 -1
  167. package/dist/shared/plan-io.d.ts +0 -41
  168. package/dist/shared/plan-io.d.ts.map +0 -1
  169. package/dist/shared/plan-io.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ // Implements FR-SPECS-0017 (approve subcommand). Draft|Modified -> Approved, setting
2
+ // approved_by to the resolved actor; idempotent on an already-Approved spec; Removed|Deprecated
3
+ // -> invalid_transition; a missing id -> target_not_found. Before approving, runs validate.ts's
4
+ // runValidation over every target (bypassing the query grammar — FILTER_KEYS has no `id` key,
5
+ // so approve resolves ids to Spec[] itself); any error-severity finding refuses the WHOLE batch
6
+ // with one aggregated validation_failed string naming every blocking finding.
7
+ import { ok, err } from "../../shared/envelope.js";
8
+ import { logger } from "../../shared/logger.js";
9
+ import { resolveActor } from "../../shared/actor.js";
10
+ import { applyBatchWrite } from "./write.js";
11
+ import { aggregate } from "./aggregate.js";
12
+ import { buildSpecLifecycleResult } from "./output.js";
13
+ import { ERR_INVALID_TRANSITION, ERR_TARGET_NOT_FOUND, ERR_VALIDATION_FAILED } from "./errors.js";
14
+ import { runValidation } from "./validate.js";
15
+ export async function cmdApprove(specsFile, ids, actor) {
16
+ try {
17
+ // FR-SPECS-0041 — resolved once, then passed as the EXPLICIT actor into applyBatchWrite so
18
+ // approved_by (set inside `build`) and changed_by (stamped by the write path afterward) are
19
+ // guaranteed to be the identical resolved value, not two independent resolutions.
20
+ const resolvedActor = resolveActor(actor);
21
+ const build = (doc) => {
22
+ const rejects = [];
23
+ const targets = [];
24
+ for (const id of ids ?? []) {
25
+ const spec = (doc.specs ?? []).find((s) => s.id === id);
26
+ if (!spec) {
27
+ rejects.push({ ref: id, reason: ERR_TARGET_NOT_FOUND });
28
+ continue;
29
+ }
30
+ if (spec.status === "Removed" || spec.status === "Deprecated") {
31
+ rejects.push({ ref: id, reason: ERR_INVALID_TRANSITION });
32
+ continue;
33
+ }
34
+ targets.push(spec);
35
+ }
36
+ if (rejects.length > 0) {
37
+ return { ok: false, error: aggregate(rejects[0].reason, rejects) };
38
+ }
39
+ // FR-SPECS-0017 — validation gate runs over every target before any status changes; any
40
+ // error-severity finding refuses the whole batch (nothing approved).
41
+ const errorFindings = runValidation(doc, targets).filter((f) => f.severity === "error");
42
+ if (errorFindings.length > 0) {
43
+ const validationRejects = errorFindings.map((f) => ({ ref: f.id, reason: `${f.check}: ${f.message}` }));
44
+ return { ok: false, error: aggregate(ERR_VALIDATION_FAILED, validationRejects) };
45
+ }
46
+ const affected = [];
47
+ for (const spec of targets) {
48
+ if (spec.status !== "Approved") {
49
+ spec.status = "Approved"; // guarded — set only here, inside the write-path build
50
+ spec.approved_by = resolvedActor;
51
+ }
52
+ affected.push(spec.id); // idempotent — already-Approved targets pass through unchanged
53
+ }
54
+ return { ok: true, affected, result: buildSpecLifecycleResult(doc, affected) };
55
+ };
56
+ const writeResult = await applyBatchWrite(specsFile, build, { actor: resolvedActor });
57
+ if (!writeResult.ok) {
58
+ return { ok: false, result: null, error: writeResult.error, include_help: writeResult.include_help };
59
+ }
60
+ const result = writeResult.result.result;
61
+ logger.info({ specsFile, count: result.updated.length }, "specs approve");
62
+ return ok(result);
63
+ }
64
+ catch (e) {
65
+ const msg = e instanceof Error ? e.message : String(e);
66
+ return err(`internal_error: ${msg}`);
67
+ }
68
+ }
69
+ //# sourceMappingURL=approve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approve.js","sourceRoot":"","sources":["../../../src/commands/specs/approve.ts"],"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M,GAAG,UAAU,CAAC,CAAC,uDAAuD;oBACjF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;gBACnC,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,+DAA+D;YACzF,CAAC;YAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,wBAAwB,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC;QACjF,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC;YACpB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC;QACvG,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAO,CAAC,MAAM,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;QAC1E,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpB,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,123 @@
1
+ import type { CommandInput } from "../../registry/types.js";
2
+ export declare const SPEC_TYPES: readonly ["FR", "NFR", "INT", "DATA"];
3
+ export type SpecType = (typeof SPEC_TYPES)[number];
4
+ export declare const STATUSES: readonly ["Draft", "Approved", "Modified", "Deprecated", "Removed"];
5
+ export type StatusEnum = (typeof STATUSES)[number];
6
+ export declare const IMPLS: readonly ["NotStarted", "Implemented", "Planned", "ToBeModified", "ToBeRemoved"];
7
+ export type ImplEnum = (typeof IMPLS)[number];
8
+ export declare const MOSCOW: readonly ["Must", "Should", "Could", "Wont"];
9
+ export type MoscowEnum = (typeof MOSCOW)[number];
10
+ export declare const SOURCES: readonly ["User", "Inferred", "Sources", "Documentation"];
11
+ export type SourceEnum = (typeof SOURCES)[number];
12
+ export declare const VERIFS: readonly ["Test", "Analysis", "Inspection", "Demo"];
13
+ export type VerifEnum = (typeof VERIFS)[number];
14
+ export interface AcceptanceCriterion {
15
+ given: string;
16
+ when: string;
17
+ then: string;
18
+ }
19
+ export interface Spec {
20
+ id: string;
21
+ type: SpecType;
22
+ level: string;
23
+ ticket_id?: string;
24
+ classification?: string;
25
+ title: string;
26
+ statement: string;
27
+ rationale: string;
28
+ source: SourceEnum;
29
+ priority: MoscowEnum;
30
+ status: StatusEnum;
31
+ approved_by: string;
32
+ changed: string;
33
+ changed_by: string;
34
+ verification: VerifEnum;
35
+ acceptance: AcceptanceCriterion[];
36
+ depends_on: string[];
37
+ related: string[];
38
+ implementation: ImplEnum;
39
+ implementation_notes: string;
40
+ notes: string;
41
+ }
42
+ export interface AreaEntry {
43
+ code: string;
44
+ name: string;
45
+ }
46
+ export interface SpecsDocument {
47
+ component: string;
48
+ description: string;
49
+ created_at: string;
50
+ updated_at: string;
51
+ previous_version: string | null;
52
+ areas: AreaEntry[];
53
+ specs: Spec[];
54
+ }
55
+ export interface SpecInput extends CommandInput {
56
+ }
57
+ export declare const GUARDED_FIELDS: readonly ["status", "approved_by", "implementation", "changed_by"];
58
+ export type GuardedField = (typeof GUARDED_FIELDS)[number];
59
+ /** Drops any key in GUARDED_FIELDS from a spec item. Flat check — specs has no nested phases/steps. */
60
+ export declare function stripGuarded(item: Record<string, unknown>): Record<string, unknown>;
61
+ export declare const ID_RE: RegExp;
62
+ /** Parses a spec id into its prefix/area/sequence parts, or null if it does not match ID_RE. */
63
+ export declare function parseId(id: string): {
64
+ prefix: SpecType;
65
+ area: string;
66
+ seq: number;
67
+ } | null;
68
+ /** FR-SPECS-0004 — id must match `<PREFIX>-<AREA>-<NNNN>`. */
69
+ export declare function validateIdFormat(id: string): string | null;
70
+ /**
71
+ * FR-SPECS-0004 — AREA must be registered in doc.areas. Callers that auto-register new areas
72
+ * (add, migrate) MUST call autoRegisterAreas() over the batch's ids before this check, so a
73
+ * new AREA introduced by the same call is not rejected. An id that fails ID_RE is not this
74
+ * function's concern (validateIdFormat covers it) — an unparseable id is treated as passing
75
+ * here so the two errors don't collide on the same item.
76
+ */
77
+ export declare function validateAreaRegistration(spec: Spec, doc: SpecsDocument): string | null;
78
+ /**
79
+ * FR-SPECS-0004 — for each id whose AREA is not yet in doc.areas, registers it with the
80
+ * default name (name = code). add/migrate call this BEFORE validateAreaRegistration so a
81
+ * batch introducing a brand-new area succeeds instead of being rejected unknown_area.
82
+ * update never calls this — it introduces no new ids.
83
+ */
84
+ export declare function autoRegisterAreas(doc: SpecsDocument, ids: string[]): void;
85
+ /** FR-SPECS-0004 — update/patch MUST NOT change a spec's id. Reuses the plan pattern. */
86
+ export declare function validateImmutableId(patchId: string | undefined, targetId: string): string | null;
87
+ /** FR-SPECS-0003 — `type` must be one of SPEC_TYPES. */
88
+ export declare function validateType(t: unknown): string | null;
89
+ /** FR-SPECS-0001 — `source` must be one of SOURCES. Mirrors validateType. */
90
+ export declare function validateSource(s: unknown): string | null;
91
+ /** FR-SPECS-0001 — `priority` must be one of MOSCOW. Mirrors validateType. */
92
+ export declare function validatePriority(p: unknown): string | null;
93
+ /** FR-SPECS-0001 — `verification` must be one of VERIFS. Mirrors validateType. */
94
+ export declare function validateVerification(v: unknown): string | null;
95
+ /** FR-SPECS-0001 — an unknown key on a spec item is rejected. */
96
+ export declare function validateKnownFields(item: Record<string, unknown>): string | null;
97
+ /** FR-SPECS-0001/0006 — every required field (per REQUIRED_STRING_FIELDS) must be non-empty, and `acceptance` non-empty. */
98
+ export declare function validateRequired(spec: Partial<Spec>): string | null;
99
+ /** FR-SPECS-0005 — every spec id in the document must be unique. */
100
+ export declare function validateUniqueIds(doc: SpecsDocument): string | null;
101
+ /**
102
+ * FR-SPECS-0005 — every depends_on/related entry must reference an id present in the document.
103
+ * Soft-deleted (Removed) specs remain valid targets since they are still present in doc.specs.
104
+ */
105
+ export declare function validateReferences(doc: SpecsDocument): string | null;
106
+ /**
107
+ * FR-SPECS-0005 — the depends_on graph must stay acyclic (self-dependency counts as a cycle).
108
+ * `related` is intentionally NOT checked here — it may legitimately form cycles.
109
+ */
110
+ export declare function validateDependsAcyclic(doc: SpecsDocument): string | null;
111
+ /**
112
+ * FR-SPECS-0007 — enforces: max SPECS_MAX_SPECS specs per document; max
113
+ * SPECS_MAX_DEPENDENCIES_PER_SPEC entries in each of depends_on/related; max
114
+ * SPECS_MAX_ACCEPTANCE_PER_SPEC acceptance criteria per spec; max SPECS_MAX_STRING_LENGTH
115
+ * characters per string field; max SPECS_MAX_NAME_LENGTH characters per id/title/name/code.
116
+ * (SPECS_MAX_BATCH_SIZE is enforced by index.ts before processing, not here.)
117
+ */
118
+ export declare function validateSizeLimits(doc: SpecsDocument): string | null;
119
+ export declare function loadSpecs(file: string): SpecsDocument | null;
120
+ export declare function saveSpecs(file: string, doc: SpecsDocument): void;
121
+ /** FR-SPECS-0002 — a fresh, empty specs document. previous_version stays null until the first backup exists. */
122
+ export declare function newDocument(component?: string): SpecsDocument;
123
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/core.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA8B5D,eAAO,MAAM,UAAU,uCAAwC,CAAC;AAChE,MAAM,MAAM,QAA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CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAQpE;AAOD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAO5D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAKhE;AAED,gHAAgH;AAChH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAW7D"}
@@ -0,0 +1,284 @@
1
+ // Implements FR-SPECS-0001..0007, 0040 (core types, enums, validators, and plain document I/O
2
+ // for the specs command). Mirrors the shape of commands/plan/core.ts.
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { detectCycle } from "../../shared/graph.js";
6
+ import { nowUtcZ } from "../../shared/time.js";
7
+ import { SPECS_MAX_SPECS, SPECS_MAX_DEPENDENCIES_PER_SPEC, SPECS_MAX_ACCEPTANCE_PER_SPEC, SPECS_MAX_STRING_LENGTH, SPECS_MAX_NAME_LENGTH, } from "../../shared/constants.js";
8
+ import { ERR_INVALID_ID_FORMAT, ERR_UNKNOWN_AREA, ERR_INVALID_TYPE, ERR_INVALID_SOURCE, ERR_INVALID_PRIORITY, ERR_INVALID_VERIFICATION, ERR_INVALID_SPEC_FIELD, ERR_MISSING_REQUIRED_FIELD, ERR_DUPLICATE_ID, ERR_UNKNOWN_DEPENDENCY, ERR_SIZE_LIMIT_EXCEEDED, ERR_IMMUTABLE_ID, } from "./errors.js";
9
+ // ---------------------------------------------------------------------------
10
+ // Enums (FR-SPECS-0003, 0040, 0015) — const tuples + derived unions, mirrors plan's
11
+ // VALID_STATUSES pattern.
12
+ // ---------------------------------------------------------------------------
13
+ export const SPEC_TYPES = ["FR", "NFR", "INT", "DATA"]; // FR-SPECS-0003
14
+ export const STATUSES = ["Draft", "Approved", "Modified", "Deprecated", "Removed"]; // FR-SPECS-0040
15
+ export const IMPLS = ["NotStarted", "Implemented", "Planned", "ToBeModified", "ToBeRemoved"]; // FR-SPECS-0015
16
+ export const MOSCOW = ["Must", "Should", "Could", "Wont"];
17
+ export const SOURCES = ["User", "Inferred", "Sources", "Documentation"];
18
+ export const VERIFS = ["Test", "Analysis", "Inspection", "Demo"];
19
+ // ---------------------------------------------------------------------------
20
+ // Guarded fields (FR-SPECS-0040) — add/update MUST silently drop any caller-supplied value.
21
+ // ---------------------------------------------------------------------------
22
+ export const GUARDED_FIELDS = ["status", "approved_by", "implementation", "changed_by"];
23
+ /** Drops any key in GUARDED_FIELDS from a spec item. Flat check — specs has no nested phases/steps. */
24
+ export function stripGuarded(item) {
25
+ const guarded = new Set(GUARDED_FIELDS);
26
+ const result = {};
27
+ for (const [key, value] of Object.entries(item)) {
28
+ if (guarded.has(key))
29
+ continue; // FR-SPECS-0040 — silently dropped, not an error
30
+ result[key] = value;
31
+ }
32
+ return result;
33
+ }
34
+ // ---------------------------------------------------------------------------
35
+ // Known/required fields (FR-SPECS-0001)
36
+ // ---------------------------------------------------------------------------
37
+ const KNOWN_SPEC_FIELDS = new Set([
38
+ "id",
39
+ "type",
40
+ "level",
41
+ "ticket_id",
42
+ "classification",
43
+ "title",
44
+ "statement",
45
+ "rationale",
46
+ "source",
47
+ "priority",
48
+ "status",
49
+ "approved_by",
50
+ "changed",
51
+ "changed_by",
52
+ "verification",
53
+ "acceptance",
54
+ "depends_on",
55
+ "related",
56
+ "implementation",
57
+ "implementation_notes",
58
+ "notes",
59
+ ]);
60
+ // FR-SPECS-0001 — required, non-default string fields. `id` is also checked distinctly by
61
+ // callers as `missing_id` (FR-SPECS-0004) before this generic check runs; `level` is required
62
+ // but defaults to "System" when omitted (applied by the caller, not validated here) so it is
63
+ // intentionally excluded from this list. `acceptance` (required, non-empty array) is checked
64
+ // separately below since it is not a string field.
65
+ const REQUIRED_STRING_FIELDS = [
66
+ "id",
67
+ "type",
68
+ "title",
69
+ "statement",
70
+ "source",
71
+ "priority",
72
+ "verification",
73
+ ];
74
+ // ---------------------------------------------------------------------------
75
+ // Validators (FR-SPECS-0001, 0003, 0004, 0005, 0007, 0040)
76
+ // ---------------------------------------------------------------------------
77
+ export const ID_RE = /^(FR|NFR|INT|DATA)-[A-Z0-9]+-\d{4}$/; // FR-SPECS-0004
78
+ // Same pattern as ID_RE but with capturing groups for area/seq, used internally by parseId.
79
+ // Kept as a second regex so ID_RE itself stays byte-identical to the SPECS contract.
80
+ const ID_CAPTURE_RE = /^(FR|NFR|INT|DATA)-([A-Z0-9]+)-(\d{4})$/;
81
+ /** Parses a spec id into its prefix/area/sequence parts, or null if it does not match ID_RE. */
82
+ export function parseId(id) {
83
+ const m = ID_CAPTURE_RE.exec(id);
84
+ if (!m)
85
+ return null;
86
+ return { prefix: m[1], area: m[2], seq: parseInt(m[3], 10) };
87
+ }
88
+ /** FR-SPECS-0004 — id must match `<PREFIX>-<AREA>-<NNNN>`. */
89
+ export function validateIdFormat(id) {
90
+ return ID_RE.test(id) ? null : ERR_INVALID_ID_FORMAT;
91
+ }
92
+ /**
93
+ * FR-SPECS-0004 — AREA must be registered in doc.areas. Callers that auto-register new areas
94
+ * (add, migrate) MUST call autoRegisterAreas() over the batch's ids before this check, so a
95
+ * new AREA introduced by the same call is not rejected. An id that fails ID_RE is not this
96
+ * function's concern (validateIdFormat covers it) — an unparseable id is treated as passing
97
+ * here so the two errors don't collide on the same item.
98
+ */
99
+ export function validateAreaRegistration(spec, doc) {
100
+ const parsed = parseId(spec.id);
101
+ if (!parsed)
102
+ return null;
103
+ const registered = (doc.areas ?? []).some((a) => a.code === parsed.area);
104
+ return registered ? null : ERR_UNKNOWN_AREA;
105
+ }
106
+ /**
107
+ * FR-SPECS-0004 — for each id whose AREA is not yet in doc.areas, registers it with the
108
+ * default name (name = code). add/migrate call this BEFORE validateAreaRegistration so a
109
+ * batch introducing a brand-new area succeeds instead of being rejected unknown_area.
110
+ * update never calls this — it introduces no new ids.
111
+ */
112
+ export function autoRegisterAreas(doc, ids) {
113
+ doc.areas = doc.areas ?? [];
114
+ for (const id of ids) {
115
+ const parsed = parseId(id);
116
+ if (!parsed)
117
+ continue; // invalid ids are rejected elsewhere (validateIdFormat)
118
+ if (!doc.areas.some((a) => a.code === parsed.area)) {
119
+ doc.areas.push({ code: parsed.area, name: parsed.area });
120
+ }
121
+ }
122
+ }
123
+ /** FR-SPECS-0004 — update/patch MUST NOT change a spec's id. Reuses the plan pattern. */
124
+ export function validateImmutableId(patchId, targetId) {
125
+ if (patchId !== undefined && patchId !== targetId)
126
+ return ERR_IMMUTABLE_ID;
127
+ return null;
128
+ }
129
+ /** FR-SPECS-0003 — `type` must be one of SPEC_TYPES. */
130
+ export function validateType(t) {
131
+ return typeof t === "string" && SPEC_TYPES.includes(t) ? null : ERR_INVALID_TYPE;
132
+ }
133
+ /** FR-SPECS-0001 — `source` must be one of SOURCES. Mirrors validateType. */
134
+ export function validateSource(s) {
135
+ return typeof s === "string" && SOURCES.includes(s) ? null : ERR_INVALID_SOURCE;
136
+ }
137
+ /** FR-SPECS-0001 — `priority` must be one of MOSCOW. Mirrors validateType. */
138
+ export function validatePriority(p) {
139
+ return typeof p === "string" && MOSCOW.includes(p) ? null : ERR_INVALID_PRIORITY;
140
+ }
141
+ /** FR-SPECS-0001 — `verification` must be one of VERIFS. Mirrors validateType. */
142
+ export function validateVerification(v) {
143
+ return typeof v === "string" && VERIFS.includes(v) ? null : ERR_INVALID_VERIFICATION;
144
+ }
145
+ /** FR-SPECS-0001 — an unknown key on a spec item is rejected. */
146
+ export function validateKnownFields(item) {
147
+ for (const key of Object.keys(item)) {
148
+ if (!KNOWN_SPEC_FIELDS.has(key))
149
+ return ERR_INVALID_SPEC_FIELD;
150
+ }
151
+ return null;
152
+ }
153
+ /** FR-SPECS-0001/0006 — every required field (per REQUIRED_STRING_FIELDS) must be non-empty, and `acceptance` non-empty. */
154
+ export function validateRequired(spec) {
155
+ for (const field of REQUIRED_STRING_FIELDS) {
156
+ const value = spec[field];
157
+ if (value === undefined || value === null || (typeof value === "string" && value.trim() === "")) {
158
+ return ERR_MISSING_REQUIRED_FIELD;
159
+ }
160
+ }
161
+ if (!Array.isArray(spec.acceptance) || spec.acceptance.length === 0) {
162
+ return ERR_MISSING_REQUIRED_FIELD;
163
+ }
164
+ return null;
165
+ }
166
+ /** FR-SPECS-0005 — every spec id in the document must be unique. */
167
+ export function validateUniqueIds(doc) {
168
+ const seen = new Set();
169
+ for (const spec of doc.specs ?? []) {
170
+ if (!spec.id)
171
+ continue;
172
+ if (seen.has(spec.id))
173
+ return ERR_DUPLICATE_ID;
174
+ seen.add(spec.id);
175
+ }
176
+ return null;
177
+ }
178
+ /**
179
+ * FR-SPECS-0005 — every depends_on/related entry must reference an id present in the document.
180
+ * Soft-deleted (Removed) specs remain valid targets since they are still present in doc.specs.
181
+ */
182
+ export function validateReferences(doc) {
183
+ const ids = new Set((doc.specs ?? []).map((s) => s.id));
184
+ for (const spec of doc.specs ?? []) {
185
+ for (const dep of spec.depends_on ?? []) {
186
+ if (!ids.has(dep))
187
+ return ERR_UNKNOWN_DEPENDENCY;
188
+ }
189
+ for (const rel of spec.related ?? []) {
190
+ if (!ids.has(rel))
191
+ return ERR_UNKNOWN_DEPENDENCY;
192
+ }
193
+ }
194
+ return null;
195
+ }
196
+ /**
197
+ * FR-SPECS-0005 — the depends_on graph must stay acyclic (self-dependency counts as a cycle).
198
+ * `related` is intentionally NOT checked here — it may legitimately form cycles.
199
+ */
200
+ export function validateDependsAcyclic(doc) {
201
+ const graph = new Map();
202
+ for (const spec of doc.specs ?? []) {
203
+ if (spec.id)
204
+ graph.set(spec.id, [...(spec.depends_on ?? [])]);
205
+ }
206
+ return detectCycle(graph); // shared/graph.ts — generic DFS, "dependency_cycle" | null
207
+ }
208
+ /** Recursively enforces string length limits: `id`/`title`/`name`/`code` at SPECS_MAX_NAME_LENGTH, all other strings at SPECS_MAX_STRING_LENGTH. */
209
+ function checkStringLimits(value, keyHint) {
210
+ if (typeof value === "string") {
211
+ const isNameLike = keyHint === "id" || keyHint === "title" || keyHint === "name" || keyHint === "code";
212
+ const limit = isNameLike ? SPECS_MAX_NAME_LENGTH : SPECS_MAX_STRING_LENGTH;
213
+ return value.length > limit ? ERR_SIZE_LIMIT_EXCEEDED : null;
214
+ }
215
+ if (Array.isArray(value)) {
216
+ for (const item of value) {
217
+ const r = checkStringLimits(item, keyHint);
218
+ if (r)
219
+ return r;
220
+ }
221
+ return null;
222
+ }
223
+ if (typeof value === "object" && value !== null) {
224
+ for (const [key, val] of Object.entries(value)) {
225
+ const r = checkStringLimits(val, key);
226
+ if (r)
227
+ return r;
228
+ }
229
+ }
230
+ return null;
231
+ }
232
+ /**
233
+ * FR-SPECS-0007 — enforces: max SPECS_MAX_SPECS specs per document; max
234
+ * SPECS_MAX_DEPENDENCIES_PER_SPEC entries in each of depends_on/related; max
235
+ * SPECS_MAX_ACCEPTANCE_PER_SPEC acceptance criteria per spec; max SPECS_MAX_STRING_LENGTH
236
+ * characters per string field; max SPECS_MAX_NAME_LENGTH characters per id/title/name/code.
237
+ * (SPECS_MAX_BATCH_SIZE is enforced by index.ts before processing, not here.)
238
+ */
239
+ export function validateSizeLimits(doc) {
240
+ if ((doc.specs ?? []).length > SPECS_MAX_SPECS)
241
+ return ERR_SIZE_LIMIT_EXCEEDED;
242
+ for (const spec of doc.specs ?? []) {
243
+ if ((spec.depends_on ?? []).length > SPECS_MAX_DEPENDENCIES_PER_SPEC)
244
+ return ERR_SIZE_LIMIT_EXCEEDED;
245
+ if ((spec.related ?? []).length > SPECS_MAX_DEPENDENCIES_PER_SPEC)
246
+ return ERR_SIZE_LIMIT_EXCEEDED;
247
+ if ((spec.acceptance ?? []).length > SPECS_MAX_ACCEPTANCE_PER_SPEC)
248
+ return ERR_SIZE_LIMIT_EXCEEDED;
249
+ }
250
+ return checkStringLimits(doc);
251
+ }
252
+ // ---------------------------------------------------------------------------
253
+ // Plain document I/O (FR-SPECS-0002, 0071) — used for the first-create bypass and by
254
+ // applyBatchWrite's saveDoc callback. Regular reads go through shared/doc-io.ts readDocWithRetry.
255
+ // ---------------------------------------------------------------------------
256
+ export function loadSpecs(file) {
257
+ if (!fs.existsSync(file))
258
+ return null;
259
+ const raw = JSON.parse(fs.readFileSync(file, "utf8"));
260
+ if (!("previous_version" in raw)) {
261
+ raw["previous_version"] = null;
262
+ }
263
+ return raw;
264
+ }
265
+ export function saveSpecs(file, doc) {
266
+ const dir = path.dirname(file);
267
+ fs.mkdirSync(dir, { recursive: true });
268
+ doc.updated_at = nowUtcZ();
269
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2));
270
+ }
271
+ /** FR-SPECS-0002 — a fresh, empty specs document. previous_version stays null until the first backup exists. */
272
+ export function newDocument(component) {
273
+ const ts = nowUtcZ();
274
+ return {
275
+ component: component ?? "",
276
+ description: "",
277
+ created_at: ts,
278
+ updated_at: ts,
279
+ previous_version: null,
280
+ areas: [],
281
+ specs: [],
282
+ };
283
+ }
284
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/commands/specs/core.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,sEAAsE;AAEtE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,+BAA+B,EAC/B,6BAA6B,EAC7B,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,8EAA8E;AAC9E,o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AS,CAAC,IAAY;IACpC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAkB,CAAC;IACvE,IAAI,CAAC,CAAC,kBAAkB,IAAI,GAAG,CAAC,EAAE,CAAC;QAChC,GAA+B,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,GAAkB;IACxD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,GAAG,CAAC,UAAU,GAAG,OAAO,EAAE,CAAC;IAC3B,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,WAAW,CAAC,SAAkB;IAC5C,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;IACrB,OAAO;QACL,SAAS,EAAE,SAAS,IAAI,EAAE;QAC1B,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,EAAE;QACd,gBAAgB,EAAE,IAAI;QACtB,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RunEnvelope } from "../../registry/types.js";
2
+ import type { SpecDeleteResult } from "./output.js";
3
+ export declare function cmdDelete(specsFile: string, ids: string[], actor?: string): Promise<RunEnvelope<SpecDeleteResult>>;
4
+ //# sourceMappingURL=delete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/delete.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CA+BxH"}
@@ -0,0 +1,36 @@
1
+ // Implements FR-SPECS-0014 (delete subcommand — soft-delete). Sets status=Removed, retains the
2
+ // unit. Idempotent (re-deleting an already-Removed spec succeeds, no-op). A missing id is
3
+ // reported in `missing`, never errors the batch.
4
+ import { ok, err } from "../../shared/envelope.js";
5
+ import { logger } from "../../shared/logger.js";
6
+ import { applyBatchWrite } from "./write.js";
7
+ export async function cmdDelete(specsFile, ids, actor) {
8
+ try {
9
+ const build = (doc) => {
10
+ const removed = [];
11
+ const missing = [];
12
+ for (const id of ids ?? []) {
13
+ const spec = (doc.specs ?? []).find((s) => s.id === id);
14
+ if (!spec) {
15
+ missing.push(id);
16
+ continue;
17
+ }
18
+ spec.status = "Removed"; // guarded — set only here, inside the write-path build (FR-SPECS-0040); idempotent if already Removed
19
+ removed.push(id);
20
+ }
21
+ return { ok: true, affected: removed, result: { removed, missing } };
22
+ };
23
+ const writeResult = await applyBatchWrite(specsFile, build, { actor });
24
+ if (!writeResult.ok) {
25
+ return { ok: false, result: null, error: writeResult.error, include_help: writeResult.include_help };
26
+ }
27
+ const result = writeResult.result.result;
28
+ logger.info({ specsFile, removed: result.removed.length, missing: result.missing.length }, "specs delete");
29
+ return ok(result);
30
+ }
31
+ catch (e) {
32
+ const msg = e instanceof Error ? e.message : String(e);
33
+ return err(`internal_error: ${msg}`);
34
+ }
35
+ }
36
+ //# sourceMappingURL=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CAAC,EAAE,EAAE,CAAC;YACpB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC;QACvG,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAO,CAAC,MAAM,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC;QAC3G,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpB,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,4 @@
1
+ import type { RunEnvelope } from "../../registry/types.js";
2
+ import { type SpecLifecycleResult } from "./output.js";
3
+ export declare function cmdDeprecate(specsFile: string, ids: string[], actor?: string): Promise<RunEnvelope<SpecLifecycleResult>>;
4
+ //# sourceMappingURL=deprecate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecate.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/deprecate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAK3D,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGjF,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CA0C9H"}
@@ -0,0 +1,51 @@
1
+ // Implements FR-SPECS-0018 (deprecate subcommand). Draft|Modified|Approved -> Deprecated;
2
+ // idempotent on an already-Deprecated spec; Removed -> invalid_transition. A missing id ->
3
+ // target_not_found (consistent with approve/restore/reopen, though FR-SPECS-0018's own text does
4
+ // not restate an explicit "Errors:" line the way FR-SPECS-0017 does).
5
+ import { ok, err } from "../../shared/envelope.js";
6
+ import { logger } from "../../shared/logger.js";
7
+ import { applyBatchWrite } from "./write.js";
8
+ import { aggregate } from "./aggregate.js";
9
+ import { buildSpecLifecycleResult } from "./output.js";
10
+ import { ERR_INVALID_TRANSITION, ERR_TARGET_NOT_FOUND } from "./errors.js";
11
+ export async function cmdDeprecate(specsFile, ids, actor) {
12
+ try {
13
+ const build = (doc) => {
14
+ const rejects = [];
15
+ const affected = [];
16
+ for (const id of ids ?? []) {
17
+ const spec = (doc.specs ?? []).find((s) => s.id === id);
18
+ if (!spec) {
19
+ rejects.push({ ref: id, reason: ERR_TARGET_NOT_FOUND });
20
+ continue;
21
+ }
22
+ if (spec.status === "Deprecated") {
23
+ affected.push(id); // idempotent
24
+ continue;
25
+ }
26
+ if (spec.status === "Removed") {
27
+ rejects.push({ ref: id, reason: ERR_INVALID_TRANSITION });
28
+ continue;
29
+ }
30
+ spec.status = "Deprecated"; // guarded — set only here, inside the write-path build
31
+ affected.push(id);
32
+ }
33
+ if (rejects.length > 0) {
34
+ return { ok: false, error: aggregate(rejects[0].reason, rejects) };
35
+ }
36
+ return { ok: true, affected, result: buildSpecLifecycleResult(doc, affected) };
37
+ };
38
+ const writeResult = await applyBatchWrite(specsFile, build, { actor });
39
+ if (!writeResult.ok) {
40
+ return { ok: false, result: null, error: writeResult.error, include_help: writeResult.include_help };
41
+ }
42
+ const result = writeResult.result.result;
43
+ logger.info({ specsFile, count: result.updated.length }, "specs deprecate");
44
+ return ok(result);
45
+ }
46
+ catch (e) {
47
+ const msg = e instanceof Error ? e.message : String(e);
48
+ return err(`internal_error: ${msg}`);
49
+ }
50
+ }
51
+ //# sourceMappingURL=deprecate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecate.js","sourceRoot":"","sources":["../../../src/commands/specs/deprecate.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,2FAA2F;AAC3F,iGAAiG;AACjG,sEAAsE;AAGtE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAmB,eAAe,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAkB,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAA4B,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,GAAa,EAAE,KAAc;IACjF,IAAI,CAAC;QACH,MAAM,KAAK,GAAoC,CAAC,GAAG,EAAE,EAAE;YACrD,MAAM,OAAO,GAAgB,EAAE,CAAC;YAChC,MAAM,QAAQ,GAAa,EAAE,CAAC;YAE9B,KAAK,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACxD,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC;oBACxD,SAAS;gBACX,CAAC;gBACD,IAAI,IAAI,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;oBACjC,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