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.
- package/dist/commands/plan/core.d.ts +2 -1
- package/dist/commands/plan/core.d.ts.map +1 -1
- package/dist/commands/plan/core.js +6 -26
- package/dist/commands/plan/core.js.map +1 -1
- package/dist/commands/plan/errors.d.ts +6 -2
- package/dist/commands/plan/errors.d.ts.map +1 -1
- package/dist/commands/plan/errors.js +6 -2
- package/dist/commands/plan/errors.js.map +1 -1
- package/dist/commands/plan/next.js +3 -3
- package/dist/commands/plan/next.js.map +1 -1
- package/dist/commands/plan/query.js +3 -3
- package/dist/commands/plan/query.js.map +1 -1
- package/dist/commands/plan/show-status.js +3 -3
- package/dist/commands/plan/show-status.js.map +1 -1
- package/dist/commands/plan/update-status.js +1 -1
- package/dist/commands/plan/update-status.js.map +1 -1
- package/dist/commands/plan/upsert.js +2 -2
- package/dist/commands/plan/upsert.js.map +1 -1
- package/dist/commands/specs/add.d.ts +12 -0
- package/dist/commands/specs/add.d.ts.map +1 -0
- package/dist/commands/specs/add.js +127 -0
- package/dist/commands/specs/add.js.map +1 -0
- package/dist/commands/specs/aggregate.d.ts +12 -0
- package/dist/commands/specs/aggregate.d.ts.map +1 -0
- package/dist/commands/specs/aggregate.js +14 -0
- package/dist/commands/specs/aggregate.js.map +1 -0
- package/dist/commands/specs/approve.d.ts +4 -0
- package/dist/commands/specs/approve.d.ts.map +1 -0
- package/dist/commands/specs/approve.js +69 -0
- package/dist/commands/specs/approve.js.map +1 -0
- package/dist/commands/specs/core.d.ts +123 -0
- package/dist/commands/specs/core.d.ts.map +1 -0
- package/dist/commands/specs/core.js +284 -0
- package/dist/commands/specs/core.js.map +1 -0
- package/dist/commands/specs/delete.d.ts +4 -0
- package/dist/commands/specs/delete.d.ts.map +1 -0
- package/dist/commands/specs/delete.js +36 -0
- package/dist/commands/specs/delete.js.map +1 -0
- package/dist/commands/specs/deprecate.d.ts +4 -0
- package/dist/commands/specs/deprecate.d.ts.map +1 -0
- package/dist/commands/specs/deprecate.js +51 -0
- package/dist/commands/specs/deprecate.js.map +1 -0
- package/dist/commands/specs/errors.d.ts +69 -0
- package/dist/commands/specs/errors.d.ts.map +1 -0
- package/dist/commands/specs/errors.js +114 -0
- package/dist/commands/specs/errors.js.map +1 -0
- package/dist/commands/specs/get.d.ts +4 -0
- package/dist/commands/specs/get.d.ts.map +1 -0
- package/dist/commands/specs/get.js +37 -0
- package/dist/commands/specs/get.js.map +1 -0
- package/dist/commands/specs/graph.d.ts +33 -0
- package/dist/commands/specs/graph.d.ts.map +1 -0
- package/dist/commands/specs/graph.js +179 -0
- package/dist/commands/specs/graph.js.map +1 -0
- package/dist/commands/specs/help-content.d.ts +226 -0
- package/dist/commands/specs/help-content.d.ts.map +1 -0
- package/dist/commands/specs/help-content.js +328 -0
- package/dist/commands/specs/help-content.js.map +1 -0
- package/dist/commands/specs/implemented.d.ts +4 -0
- package/dist/commands/specs/implemented.d.ts.map +1 -0
- package/dist/commands/specs/implemented.js +69 -0
- package/dist/commands/specs/implemented.js.map +1 -0
- package/dist/commands/specs/index.d.ts +4 -0
- package/dist/commands/specs/index.d.ts.map +1 -0
- package/dist/commands/specs/index.js +282 -0
- package/dist/commands/specs/index.js.map +1 -0
- package/dist/commands/specs/info.d.ts +4 -0
- package/dist/commands/specs/info.d.ts.map +1 -0
- package/dist/commands/specs/info.js +78 -0
- package/dist/commands/specs/info.js.map +1 -0
- package/dist/commands/specs/migrate.d.ts +4 -0
- package/dist/commands/specs/migrate.d.ts.map +1 -0
- package/dist/commands/specs/migrate.js +124 -0
- package/dist/commands/specs/migrate.js.map +1 -0
- package/dist/commands/specs/output.d.ts +152 -0
- package/dist/commands/specs/output.d.ts.map +1 -0
- package/dist/commands/specs/output.js +45 -0
- package/dist/commands/specs/output.js.map +1 -0
- package/dist/commands/specs/purge.d.ts +4 -0
- package/dist/commands/specs/purge.d.ts.map +1 -0
- package/dist/commands/specs/purge.js +58 -0
- package/dist/commands/specs/purge.js.map +1 -0
- package/dist/commands/specs/query-filter.d.ts +26 -0
- package/dist/commands/specs/query-filter.d.ts.map +1 -0
- package/dist/commands/specs/query-filter.js +275 -0
- package/dist/commands/specs/query-filter.js.map +1 -0
- package/dist/commands/specs/query.d.ts +4 -0
- package/dist/commands/specs/query.d.ts.map +1 -0
- package/dist/commands/specs/query.js +35 -0
- package/dist/commands/specs/query.js.map +1 -0
- package/dist/commands/specs/render.d.ts +9 -0
- package/dist/commands/specs/render.d.ts.map +1 -0
- package/dist/commands/specs/render.js +129 -0
- package/dist/commands/specs/render.js.map +1 -0
- package/dist/commands/specs/reopen.d.ts +4 -0
- package/dist/commands/specs/reopen.d.ts.map +1 -0
- package/dist/commands/specs/reopen.js +47 -0
- package/dist/commands/specs/reopen.js.map +1 -0
- package/dist/commands/specs/req-parser.d.ts +55 -0
- package/dist/commands/specs/req-parser.d.ts.map +1 -0
- package/dist/commands/specs/req-parser.js +325 -0
- package/dist/commands/specs/req-parser.js.map +1 -0
- package/dist/commands/specs/restore.d.ts +4 -0
- package/dist/commands/specs/restore.d.ts.map +1 -0
- package/dist/commands/specs/restore.js +46 -0
- package/dist/commands/specs/restore.js.map +1 -0
- package/dist/commands/specs/rubric.d.ts +18 -0
- package/dist/commands/specs/rubric.d.ts.map +1 -0
- package/dist/commands/specs/rubric.js +86 -0
- package/dist/commands/specs/rubric.js.map +1 -0
- package/dist/commands/specs/schemas.d.ts +687 -0
- package/dist/commands/specs/schemas.d.ts.map +1 -0
- package/dist/commands/specs/schemas.js +454 -0
- package/dist/commands/specs/schemas.js.map +1 -0
- package/dist/commands/specs/update.d.ts +4 -0
- package/dist/commands/specs/update.d.ts.map +1 -0
- package/dist/commands/specs/update.js +139 -0
- package/dist/commands/specs/update.js.map +1 -0
- package/dist/commands/specs/validate.d.ts +13 -0
- package/dist/commands/specs/validate.d.ts.map +1 -0
- package/dist/commands/specs/validate.js +165 -0
- package/dist/commands/specs/validate.js.map +1 -0
- package/dist/commands/specs/write.d.ts +38 -0
- package/dist/commands/specs/write.d.ts.map +1 -0
- package/dist/commands/specs/write.js +65 -0
- package/dist/commands/specs/write.js.map +1 -0
- package/dist/frontends/cli.d.ts.map +1 -1
- package/dist/frontends/cli.js +186 -0
- package/dist/frontends/cli.js.map +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +2 -0
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/types.d.ts +22 -0
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/shared/actor.d.ts +8 -0
- package/dist/shared/actor.d.ts.map +1 -0
- package/dist/shared/actor.js +65 -0
- package/dist/shared/actor.js.map +1 -0
- package/dist/shared/constants.d.ts +6 -0
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +8 -1
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/dispatch.d.ts.map +1 -1
- package/dist/shared/dispatch.js +2 -0
- package/dist/shared/dispatch.js.map +1 -1
- package/dist/shared/doc-io.d.ts +46 -0
- package/dist/shared/doc-io.d.ts.map +1 -0
- package/dist/shared/{plan-io.js → doc-io.js} +23 -18
- package/dist/shared/doc-io.js.map +1 -0
- package/dist/shared/errors.d.ts +3 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +6 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/graph.d.ts +6 -0
- package/dist/shared/graph.d.ts.map +1 -0
- package/dist/shared/graph.js +34 -0
- package/dist/shared/graph.js.map +1 -0
- package/dist/shared/time.d.ts +9 -0
- package/dist/shared/time.d.ts.map +1 -0
- package/dist/shared/time.js +20 -0
- package/dist/shared/time.js.map +1 -0
- package/package.json +2 -1
- package/dist/shared/plan-io.d.ts +0 -41
- package/dist/shared/plan-io.d.ts.map +0 -1
- package/dist/shared/plan-io.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Implements FR-SPECS-0012 (query subcommand). Read-only attribute search over the whole
|
|
2
|
+
// document via query-filter.ts's grammar; excludes soft-deleted (Removed) specs unless the query
|
|
3
|
+
// string says `include_removed:true`/`status:Removed`, or the caller's own includeRemoved flag
|
|
4
|
+
// (FR-CLI `--include-removed`) is set.
|
|
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 } from "./errors.js";
|
|
9
|
+
import { applyFilter, parseQuery } from "./query-filter.js";
|
|
10
|
+
export async function cmdQuery(specsFile, query, includeRemoved) {
|
|
11
|
+
try {
|
|
12
|
+
let doc;
|
|
13
|
+
try {
|
|
14
|
+
doc = await readDocWithRetry(specsFile);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return err(ERR_SPECS_FILE_CORRUPTED);
|
|
18
|
+
}
|
|
19
|
+
if (!doc)
|
|
20
|
+
return err(ERR_SPECS_NOT_FOUND);
|
|
21
|
+
const filter = parseQuery(query);
|
|
22
|
+
if ("error" in filter)
|
|
23
|
+
return err(filter.error);
|
|
24
|
+
if (includeRemoved)
|
|
25
|
+
filter.includeRemoved = true;
|
|
26
|
+
const specs = applyFilter(doc.specs ?? [], filter);
|
|
27
|
+
logger.info({ specsFile, count: specs.length }, "specs query");
|
|
28
|
+
return ok({ specs, count: specs.length });
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
32
|
+
return err(`internal_error: ${msg}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/commands/specs/query.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,iGAAiG;AACjG,+FAA+F;AAC/F,uCAAuC;AAGvC,OAAO,EA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C,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,9 @@
|
|
|
1
|
+
import type { RunEnvelope } from "../../registry/types.js";
|
|
2
|
+
import { type Spec, type SpecsDocument } from "./core.js";
|
|
3
|
+
import type { SpecRenderResult } from "./output.js";
|
|
4
|
+
/** FR-SPECS-0023 — renders `specs` (already the caller's chosen subset — e.g. query-filtered)
|
|
5
|
+
* grouped by area, in `format`. No file write; timestamps go through formatLocal (FR-SPECS-0042
|
|
6
|
+
* — local display, UTC storage). `format` validity is the caller's (cmdRender's) concern. */
|
|
7
|
+
export declare function renderSpecs(doc: SpecsDocument, specs: Spec[], format: "markdown" | "text"): string;
|
|
8
|
+
export declare function cmdRender(specsFile: string, query?: string, format?: string): Promise<RunEnvelope<SpecRenderResult>>;
|
|
9
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/render.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAK3D,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,aAAa,EAAW,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAwFpD;;6FAE6F;AAC7F,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAGlG;AAQD,wBAAsB,SAAS,CAC7B,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAwBxC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Implements FR-SPECS-0023/0042 (human-readable rendering). renderSpecs is pure (no IO, no file
|
|
2
|
+
// write); cmdRender is the thin envelope wrapper (SPECS §10), completed in this stage per the
|
|
3
|
+
// execution plan (S5) since it needs only readDocWithRetry/envelope/logger (already available)
|
|
4
|
+
// plus query-filter.ts — the plan explicitly names query-filter.ts as "shared by
|
|
5
|
+
// query/validate/render", so this cross-import between S5 files is intentional, not a slip of
|
|
6
|
+
// the "no cross-imports" guideline (which is about avoiding accidental coupling between the five
|
|
7
|
+
// files, not about forbidding the one shared-by-design dependency the plan itself calls out).
|
|
8
|
+
import { ok, err } from "../../shared/envelope.js";
|
|
9
|
+
import { logger } from "../../shared/logger.js";
|
|
10
|
+
import { readDocWithRetry } from "../../shared/doc-io.js";
|
|
11
|
+
import { formatLocal } from "../../shared/time.js";
|
|
12
|
+
import { parseId } from "./core.js";
|
|
13
|
+
import { ERR_INVALID_FORMAT, ERR_SPECS_FILE_CORRUPTED, ERR_SPECS_NOT_FOUND } from "./errors.js";
|
|
14
|
+
import { parseQuery, applyFilter } from "./query-filter.js";
|
|
15
|
+
/** Groups `specs` by area (via parseId), ordered per doc.areas' registration order; any area
|
|
16
|
+
* code present in `specs` but not registered in doc.areas is appended at the end (tolerant —
|
|
17
|
+
* render never fails on an unregistered/unparseable area, it just falls back to the raw code
|
|
18
|
+
* as its own display name). */
|
|
19
|
+
function groupByArea(doc, specs) {
|
|
20
|
+
const byArea = new Map();
|
|
21
|
+
for (const spec of specs) {
|
|
22
|
+
const parsed = parseId(spec.id);
|
|
23
|
+
const code = parsed?.area ?? "UNKNOWN";
|
|
24
|
+
const list = byArea.get(code);
|
|
25
|
+
if (list)
|
|
26
|
+
list.push(spec);
|
|
27
|
+
else
|
|
28
|
+
byArea.set(code, [spec]);
|
|
29
|
+
}
|
|
30
|
+
const groups = [];
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
for (const area of doc.areas ?? []) {
|
|
33
|
+
const list = byArea.get(area.code);
|
|
34
|
+
if (list && list.length > 0) {
|
|
35
|
+
groups.push({ code: area.code, name: area.name, specs: [...list].sort((a, b) => a.id.localeCompare(b.id)) });
|
|
36
|
+
seen.add(area.code);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [code, list] of byArea) {
|
|
40
|
+
if (seen.has(code))
|
|
41
|
+
continue;
|
|
42
|
+
groups.push({ code, name: code, specs: [...list].sort((a, b) => a.id.localeCompare(b.id)) });
|
|
43
|
+
}
|
|
44
|
+
return groups;
|
|
45
|
+
}
|
|
46
|
+
function renderMarkdown(doc, groups) {
|
|
47
|
+
const lines = [`# ${doc.component || "(unnamed)"}`];
|
|
48
|
+
if (doc.description)
|
|
49
|
+
lines.push("", doc.description);
|
|
50
|
+
for (const group of groups) {
|
|
51
|
+
lines.push("", `## ${group.code} — ${group.name}`);
|
|
52
|
+
for (const spec of group.specs) {
|
|
53
|
+
lines.push("", `### ${spec.id} — ${spec.title}`);
|
|
54
|
+
lines.push(`- Priority: ${spec.priority}`);
|
|
55
|
+
lines.push(`- Status: ${spec.status}`);
|
|
56
|
+
lines.push(`- Statement: ${spec.statement}`);
|
|
57
|
+
lines.push("- Acceptance:");
|
|
58
|
+
(spec.acceptance ?? []).forEach((c, i) => {
|
|
59
|
+
lines.push(` ${i + 1}. Given ${c.given} When ${c.when} Then ${c.then}`);
|
|
60
|
+
});
|
|
61
|
+
lines.push(`- Depends on: ${(spec.depends_on ?? []).join(", ") || "(none)"}`);
|
|
62
|
+
lines.push(`- Related: ${(spec.related ?? []).join(", ") || "(none)"}`);
|
|
63
|
+
lines.push(`- Changed: ${formatLocal(spec.changed)} by ${spec.changed_by || "unknown"}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return lines.join("\n");
|
|
67
|
+
}
|
|
68
|
+
function renderText(doc, groups) {
|
|
69
|
+
const lines = [doc.component || "(unnamed)"];
|
|
70
|
+
if (doc.description)
|
|
71
|
+
lines.push(doc.description);
|
|
72
|
+
for (const group of groups) {
|
|
73
|
+
lines.push("", `Area: ${group.code} - ${group.name}`);
|
|
74
|
+
for (const spec of group.specs) {
|
|
75
|
+
lines.push("", `${spec.id} - ${spec.title}`);
|
|
76
|
+
lines.push(` Priority: ${spec.priority}`);
|
|
77
|
+
lines.push(` Status: ${spec.status}`);
|
|
78
|
+
lines.push(` Statement: ${spec.statement}`);
|
|
79
|
+
lines.push(" Acceptance:");
|
|
80
|
+
(spec.acceptance ?? []).forEach((c, i) => {
|
|
81
|
+
lines.push(` ${i + 1}. Given ${c.given} When ${c.when} Then ${c.then}`);
|
|
82
|
+
});
|
|
83
|
+
lines.push(` Depends on: ${(spec.depends_on ?? []).join(", ") || "(none)"}`);
|
|
84
|
+
lines.push(` Related: ${(spec.related ?? []).join(", ") || "(none)"}`);
|
|
85
|
+
lines.push(` Changed: ${formatLocal(spec.changed)} by ${spec.changed_by || "unknown"}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return lines.join("\n");
|
|
89
|
+
}
|
|
90
|
+
/** FR-SPECS-0023 — renders `specs` (already the caller's chosen subset — e.g. query-filtered)
|
|
91
|
+
* grouped by area, in `format`. No file write; timestamps go through formatLocal (FR-SPECS-0042
|
|
92
|
+
* — local display, UTC storage). `format` validity is the caller's (cmdRender's) concern. */
|
|
93
|
+
export function renderSpecs(doc, specs, format) {
|
|
94
|
+
const groups = groupByArea(doc, specs);
|
|
95
|
+
return format === "markdown" ? renderMarkdown(doc, groups) : renderText(doc, groups);
|
|
96
|
+
}
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// cmdRender — FR-SPECS-0023, SPECS §10. Optional query scope (default: all non-Removed specs);
|
|
99
|
+
// format defaults to markdown; a format other than markdown|text -> invalid_format, checked
|
|
100
|
+
// before any read/render work.
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
export async function cmdRender(specsFile, query, format) {
|
|
103
|
+
try {
|
|
104
|
+
const fmt = format ?? "markdown";
|
|
105
|
+
if (fmt !== "markdown" && fmt !== "text")
|
|
106
|
+
return err(ERR_INVALID_FORMAT);
|
|
107
|
+
let doc;
|
|
108
|
+
try {
|
|
109
|
+
doc = await readDocWithRetry(specsFile);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return err(ERR_SPECS_FILE_CORRUPTED);
|
|
113
|
+
}
|
|
114
|
+
if (!doc)
|
|
115
|
+
return err(ERR_SPECS_NOT_FOUND);
|
|
116
|
+
const filter = parseQuery(query);
|
|
117
|
+
if ("error" in filter)
|
|
118
|
+
return err(filter.error);
|
|
119
|
+
const specs = applyFilter(doc.specs ?? [], filter);
|
|
120
|
+
const content = renderSpecs(doc, specs, fmt);
|
|
121
|
+
logger.info({ specsFile, format: fmt, count: specs.length }, "specs render");
|
|
122
|
+
return ok({ format: fmt, content });
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
126
|
+
return err(`internal_error: ${msg}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/commands/specs/render.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,8FAA8F;AAC9F,+FAA+F;AAC/F,iFAAiF;AACjF,8FAA8F;AAC9F,iGAAiG;AACjG,8FAA8F;AAG9F,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;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAiC,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,mBA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AC,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC;QAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IACtC,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 cmdReopen(specsFile: string, ids: string[], actor?: string): Promise<RunEnvelope<SpecLifecycleResult>>;
|
|
4
|
+
//# sourceMappingURL=reopen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reopen.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/reopen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAK3D,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGjF,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAuC3H"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Implements FR-SPECS-0020 (reopen subcommand). Approved -> Draft, clearing approved_by (an
|
|
2
|
+
// explicit way to withdraw approval for rework without first editing content); any other current
|
|
3
|
+
// status -> invalid_transition (not idempotent). A missing id -> target_not_found.
|
|
4
|
+
import { ok, err } from "../../shared/envelope.js";
|
|
5
|
+
import { logger } from "../../shared/logger.js";
|
|
6
|
+
import { applyBatchWrite } from "./write.js";
|
|
7
|
+
import { aggregate } from "./aggregate.js";
|
|
8
|
+
import { buildSpecLifecycleResult } from "./output.js";
|
|
9
|
+
import { ERR_INVALID_TRANSITION, ERR_TARGET_NOT_FOUND } from "./errors.js";
|
|
10
|
+
export async function cmdReopen(specsFile, ids, actor) {
|
|
11
|
+
try {
|
|
12
|
+
const build = (doc) => {
|
|
13
|
+
const rejects = [];
|
|
14
|
+
const affected = [];
|
|
15
|
+
for (const id of ids ?? []) {
|
|
16
|
+
const spec = (doc.specs ?? []).find((s) => s.id === id);
|
|
17
|
+
if (!spec) {
|
|
18
|
+
rejects.push({ ref: id, reason: ERR_TARGET_NOT_FOUND });
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (spec.status !== "Approved") {
|
|
22
|
+
rejects.push({ ref: id, reason: ERR_INVALID_TRANSITION });
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
spec.status = "Draft"; // guarded — set only here, inside the write-path build
|
|
26
|
+
spec.approved_by = "";
|
|
27
|
+
affected.push(id);
|
|
28
|
+
}
|
|
29
|
+
if (rejects.length > 0) {
|
|
30
|
+
return { ok: false, error: aggregate(rejects[0].reason, rejects) };
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, affected, result: buildSpecLifecycleResult(doc, affected) };
|
|
33
|
+
};
|
|
34
|
+
const writeResult = await applyBatchWrite(specsFile, build, { actor });
|
|
35
|
+
if (!writeResult.ok) {
|
|
36
|
+
return { ok: false, result: null, error: writeResult.error, include_help: writeResult.include_help };
|
|
37
|
+
}
|
|
38
|
+
const result = writeResult.result.result;
|
|
39
|
+
logger.info({ specsFile, count: result.updated.length }, "specs reopen");
|
|
40
|
+
return ok(result);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
44
|
+
return err(`internal_error: ${msg}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|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AAC,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AcceptanceCriterion, ImplEnum, Spec } from "./core.js";
|
|
2
|
+
import type { SpecFinding } from "./output.js";
|
|
3
|
+
export interface RawReq {
|
|
4
|
+
attrs: Record<string, string>;
|
|
5
|
+
tags: Record<string, string>;
|
|
6
|
+
sourceLine: number;
|
|
7
|
+
}
|
|
8
|
+
/** Parses `name="value"` (or `name='value'`) pairs out of a raw opening-tag string. */
|
|
9
|
+
export declare function extractAttrs(openTag: string): Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* FR-SPECS-0025 — scans `md` for `<req ...>...</req>` blocks. `<req>` blocks are never nested,
|
|
12
|
+
* so each is found by: locate `<req`, scan to the opening tag's unquoted `>`, then find the
|
|
13
|
+
* next `</req>` — everything between is the opaque body. A malformed opening tag (unterminated
|
|
14
|
+
* quote) or a missing `</req>` for a given `<req` stops scanning that occurrence and moves on
|
|
15
|
+
* (tolerant — one broken block never prevents finding the rest of the file's valid blocks).
|
|
16
|
+
*/
|
|
17
|
+
export declare function scanReqBlocks(md: string): RawReq[];
|
|
18
|
+
/**
|
|
19
|
+
* FR-SPECS-0025 — splits `criteria` into one AcceptanceCriterion per "Given:" marker found. If
|
|
20
|
+
* no "Given:" marker exists anywhere, the whole text is unsplittable and is returned as
|
|
21
|
+
* `{verbatim}` for the caller to place into `then` + flag a warning (report-don't-drop).
|
|
22
|
+
* Within a "Given:"-led chunk, "When:" and "Then:" are each independently optional — real docs
|
|
23
|
+
* (e.g. rosettify/PLAN.md's FR-PLAN-0034) commonly write "Given: ... Then: ..." with no
|
|
24
|
+
* explicit When: clause — so every present marker is used; only a chunk with NEITHER When: nor
|
|
25
|
+
* Then: is truly unsplittable and degrades to `{given:"", when:"", then: <chunk verbatim>}`
|
|
26
|
+
* (mapToSpec's extractAcceptance detects that exact empty-given/when shape and warns).
|
|
27
|
+
*/
|
|
28
|
+
export declare function splitGwt(criteria: string): AcceptanceCriterion[] | {
|
|
29
|
+
verbatim: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* FR-SPECS-0025 — normalizes `tags.implementation`/`tags.implementationNotes` for any of the
|
|
33
|
+
* three real-world shapes: (1) modern split tags; (2) legacy strict bracketed "[Status: X]
|
|
34
|
+
* [Additional Notes: Y]"; (3) legacy loose bracketed "[Status: X] <free text>" with no second
|
|
35
|
+
* bracket (docs/requirements/CHANGES.md's own description of the pre-split format). Never
|
|
36
|
+
* throws and never validates the extracted status against IMPLS — that is migrate.ts's job
|
|
37
|
+
* over the assembled document; this module stays a pure, validation-free mapper.
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeImplementation(tags: Record<string, string>): {
|
|
40
|
+
implementation: ImplEnum;
|
|
41
|
+
implementation_notes: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* FR-SPECS-0025 — maps one scanned `<req>` block to a Partial<Spec> plus warnings. Never
|
|
45
|
+
* throws; a missing id (the one field callers must key writes by) is reported as an
|
|
46
|
+
* error-severity SpecFinding, not a thrown exception, so migrate.ts can report-don't-drop and
|
|
47
|
+
* skip just that item. status/approved_by/changed/implementation are mapped as-is (not
|
|
48
|
+
* stripped the way add/update's stripGuarded would) — migrate imports pre-existing historical
|
|
49
|
+
* state, not a fresh user-authored item.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mapToSpec(raw: RawReq): {
|
|
52
|
+
spec: Partial<Spec>;
|
|
53
|
+
warnings: SpecFinding[];
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=req-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"req-parser.d.ts","sourceRoot":"","sources":["../../../src/commands/specs/req-parser.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAc,IAAI,EAA+C,MAAM,WAAW,CAAC;AAC9H,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AA4CD,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQpE;AAeD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAqClD;AASD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,EAAE,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAgCvF;AASD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,cAAc,EAAE,QAAQ,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,CAoBhI;AA+DD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;CAAE,CA6CvF"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// Implements FR-SPECS-0025's tolerant `<req>` scanner (SPECS §11.4, Decision 4). Pure module —
|
|
2
|
+
// no IO, no envelopes, no error codes: always returns data plus warnings, never throws, and
|
|
3
|
+
// never decides file-level outcomes (source_not_found/migrate_parse_error are migrate.ts's (S6)
|
|
4
|
+
// concern — it calls scanReqBlocks and treats a zero-length result as unparseable).
|
|
5
|
+
//
|
|
6
|
+
// Deliberately hand-rolled, NOT a real XML parser (architecture-notes.md Decision 4): actual
|
|
7
|
+
// `<req>` bodies embed ```code fences```, literal `<PREFIX>-<AREA>` angle brackets, and
|
|
8
|
+
// unescaped `&` — a strict parser would choke on exactly the content this format needs to
|
|
9
|
+
// carry. So every top-level `<tag>...</tag>` body is opaque text, located by its enclosing tag
|
|
10
|
+
// pair only, never re-parsed as markup. The one exception is `<acceptance>`, whose `<criteria>`
|
|
11
|
+
// children are extracted by the same shallow tag-pair technique one level down, since splitting
|
|
12
|
+
// Given/When/Then needs to know where each criterion starts.
|
|
13
|
+
//
|
|
14
|
+
// Real shape, confirmed against docs/requirements/**/*.md and
|
|
15
|
+
// instructions/r3/core/skills/requirements-authoring/assets/ra-requirement-unit.xml:
|
|
16
|
+
// <req id="FR-AREA-0001" type="FR" level="System" ticketId="..." classification="...">
|
|
17
|
+
// <title>..</title> <statement>..</statement> <rationale>..</rationale> <source>..</source>
|
|
18
|
+
// <priority>..</priority> <status>..</status> <approved_by>..</approved_by>
|
|
19
|
+
// <changed>YYYY-MM-DD</changed> <verification>..</verification>
|
|
20
|
+
// <acceptance><criteria>Given: A When: B Then: C.</criteria>..</acceptance>
|
|
21
|
+
// <depends>FR-AREA-0000, NFR-0000</depends> <implementation>..</implementation>
|
|
22
|
+
// <implementationNotes>..</implementationNotes> <notes>..</notes>
|
|
23
|
+
// </req>
|
|
24
|
+
// Every child tag is optional in the wild — every extraction below defaults to "" / [] rather
|
|
25
|
+
// than failing. Two implementation shapes exist: the modern split-tag form above, and the
|
|
26
|
+
// legacy `<implementation>[Status: X] [Additional Notes: Y]</implementation>` single-tag form
|
|
27
|
+
// (docs/requirements/CHANGES.md's migration note; rosettify/PLAN.md still has unmigrated reqs
|
|
28
|
+
// in this form). A single `<criteria>` tag may also hold MULTIPLE concatenated
|
|
29
|
+
// Given:/When:/Then: triples as running prose (FR-SPECS-0012, FR-PLAN-0034 in
|
|
30
|
+
// rosettify/{SPECS,PLAN}.md) rather than one triple per tag — why splitGwt returns an array.
|
|
31
|
+
// scanReqBlocks — locates <req ...>...</req> blocks; bodies are opaque text.
|
|
32
|
+
const KNOWN_TAGS = [
|
|
33
|
+
"title", "statement", "rationale", "source", "ticketId", "priority", "status", "approved_by",
|
|
34
|
+
"changed", "verification", "acceptance", "depends", "related", "implementation",
|
|
35
|
+
"implementationNotes", "notes",
|
|
36
|
+
];
|
|
37
|
+
/** `s[i]` MUST be a quote char (`"` or `'`). Returns the index just past the matching close
|
|
38
|
+
* quote, or -1 if the string ends first (unterminated — the opening-tag scan treats this as a
|
|
39
|
+
* malformed `<req` and stops). No backslash-escape handling here: attribute values in this
|
|
40
|
+
* format never contain the quote character they're wrapped in. */
|
|
41
|
+
function scanAttrQuote(s, i) {
|
|
42
|
+
const quote = s[i];
|
|
43
|
+
let j = i + 1;
|
|
44
|
+
while (j < s.length) {
|
|
45
|
+
if (s[j] === quote)
|
|
46
|
+
return j + 1;
|
|
47
|
+
j++;
|
|
48
|
+
}
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
/** Finds the first unquoted `>` at or after `from`, respecting quoted attribute values so a
|
|
52
|
+
* `>` inside e.g. `classification="a>b"` never ends the opening tag early. */
|
|
53
|
+
function findUnquotedGt(s, from) {
|
|
54
|
+
let i = from;
|
|
55
|
+
while (i < s.length) {
|
|
56
|
+
const c = s[i];
|
|
57
|
+
if (c === '"' || c === "'") {
|
|
58
|
+
const end = scanAttrQuote(s, i);
|
|
59
|
+
if (end === -1)
|
|
60
|
+
return -1;
|
|
61
|
+
i = end;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (c === ">")
|
|
65
|
+
return i;
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
return -1;
|
|
69
|
+
}
|
|
70
|
+
const ATTR_RE = /([a-zA-Z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
71
|
+
/** Parses `name="value"` (or `name='value'`) pairs out of a raw opening-tag string. */
|
|
72
|
+
export function extractAttrs(openTag) {
|
|
73
|
+
const attrs = {};
|
|
74
|
+
ATTR_RE.lastIndex = 0;
|
|
75
|
+
let m;
|
|
76
|
+
while ((m = ATTR_RE.exec(openTag)) !== null) {
|
|
77
|
+
attrs[m[1]] = m[2] !== undefined ? m[2] : m[3] ?? "";
|
|
78
|
+
}
|
|
79
|
+
return attrs;
|
|
80
|
+
}
|
|
81
|
+
/** Extracts the first occurrence of each KNOWN_TAGS top-level tag from `body`, trimmed. Any
|
|
82
|
+
* tag absent from `body` is simply absent from the result (never an error — every caller
|
|
83
|
+
* treats a missing tag as "" / defaulted). */
|
|
84
|
+
function extractKnownTags(body) {
|
|
85
|
+
const tags = {};
|
|
86
|
+
for (const name of KNOWN_TAGS) {
|
|
87
|
+
const re = new RegExp(`<${name}\\b[^>]*>([\\s\\S]*?)<\\/${name}\\s*>`, "i");
|
|
88
|
+
const m = re.exec(body);
|
|
89
|
+
if (m)
|
|
90
|
+
tags[name] = m[1].trim();
|
|
91
|
+
}
|
|
92
|
+
return tags;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* FR-SPECS-0025 — scans `md` for `<req ...>...</req>` blocks. `<req>` blocks are never nested,
|
|
96
|
+
* so each is found by: locate `<req`, scan to the opening tag's unquoted `>`, then find the
|
|
97
|
+
* next `</req>` — everything between is the opaque body. A malformed opening tag (unterminated
|
|
98
|
+
* quote) or a missing `</req>` for a given `<req` stops scanning that occurrence and moves on
|
|
99
|
+
* (tolerant — one broken block never prevents finding the rest of the file's valid blocks).
|
|
100
|
+
*/
|
|
101
|
+
export function scanReqBlocks(md) {
|
|
102
|
+
const blocks = [];
|
|
103
|
+
const openRe = /<req\b/gi;
|
|
104
|
+
let match;
|
|
105
|
+
while ((match = openRe.exec(md)) !== null) {
|
|
106
|
+
const tagStart = match.index;
|
|
107
|
+
const tagEnd = findUnquotedGt(md, tagStart + 4);
|
|
108
|
+
if (tagEnd === -1) {
|
|
109
|
+
// FR-SPECS-0025 — malformed opening tag (unterminated attribute quote): report-don't-drop
|
|
110
|
+
// means this occurrence is skipped, NOT that scanning stops. openRe.lastIndex is left
|
|
111
|
+
// untouched here, so it already sits just past this "<req" match (the engine advances it
|
|
112
|
+
// automatically on every exec()) — the next exec() call resumes strictly forward from
|
|
113
|
+
// there, guaranteeing progress (no infinite loop) while still finding any later
|
|
114
|
+
// well-formed <req> block in the rest of the document.
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const openTag = md.slice(tagStart, tagEnd + 1);
|
|
118
|
+
const closeMatch = /<\/req\s*>/i.exec(md.slice(tagEnd + 1));
|
|
119
|
+
if (!closeMatch) {
|
|
120
|
+
openRe.lastIndex = tagEnd + 1;
|
|
121
|
+
continue; // unterminated block — skip it, keep scanning for later valid blocks
|
|
122
|
+
}
|
|
123
|
+
const bodyStart = tagEnd + 1;
|
|
124
|
+
const bodyEnd = bodyStart + closeMatch.index;
|
|
125
|
+
const body = md.slice(bodyStart, bodyEnd);
|
|
126
|
+
const closeTagEnd = bodyEnd + closeMatch[0].length;
|
|
127
|
+
blocks.push({
|
|
128
|
+
attrs: extractAttrs(openTag),
|
|
129
|
+
tags: extractKnownTags(body),
|
|
130
|
+
sourceLine: md.slice(0, tagStart).split("\n").length,
|
|
131
|
+
});
|
|
132
|
+
openRe.lastIndex = closeTagEnd;
|
|
133
|
+
}
|
|
134
|
+
return blocks;
|
|
135
|
+
}
|
|
136
|
+
// splitGwt — Given:/When:/Then: splitter. A single criteria string may hold multiple
|
|
137
|
+
// concatenated triples (see file header); each is located by its own "Given:" marker.
|
|
138
|
+
const GIVEN_RE = /\bGiven:\s*/gi;
|
|
139
|
+
const WHEN_RE = /\bWhen:\s*/i;
|
|
140
|
+
const THEN_RE = /\bThen:\s*/i;
|
|
141
|
+
/**
|
|
142
|
+
* FR-SPECS-0025 — splits `criteria` into one AcceptanceCriterion per "Given:" marker found. If
|
|
143
|
+
* no "Given:" marker exists anywhere, the whole text is unsplittable and is returned as
|
|
144
|
+
* `{verbatim}` for the caller to place into `then` + flag a warning (report-don't-drop).
|
|
145
|
+
* Within a "Given:"-led chunk, "When:" and "Then:" are each independently optional — real docs
|
|
146
|
+
* (e.g. rosettify/PLAN.md's FR-PLAN-0034) commonly write "Given: ... Then: ..." with no
|
|
147
|
+
* explicit When: clause — so every present marker is used; only a chunk with NEITHER When: nor
|
|
148
|
+
* Then: is truly unsplittable and degrades to `{given:"", when:"", then: <chunk verbatim>}`
|
|
149
|
+
* (mapToSpec's extractAcceptance detects that exact empty-given/when shape and warns).
|
|
150
|
+
*/
|
|
151
|
+
export function splitGwt(criteria) {
|
|
152
|
+
const text = criteria.trim();
|
|
153
|
+
if (!text)
|
|
154
|
+
return { verbatim: "" };
|
|
155
|
+
const givenPositions = [];
|
|
156
|
+
GIVEN_RE.lastIndex = 0;
|
|
157
|
+
let gm;
|
|
158
|
+
while ((gm = GIVEN_RE.exec(text)) !== null)
|
|
159
|
+
givenPositions.push(gm.index);
|
|
160
|
+
if (givenPositions.length === 0)
|
|
161
|
+
return { verbatim: text };
|
|
162
|
+
const chunks = givenPositions.map((start, i) => {
|
|
163
|
+
const end = i + 1 < givenPositions.length ? givenPositions[i + 1] : text.length;
|
|
164
|
+
return text.slice(start, end);
|
|
165
|
+
});
|
|
166
|
+
return chunks.map((chunk) => {
|
|
167
|
+
const trimmedChunk = chunk.trim();
|
|
168
|
+
const afterGiven = trimmedChunk.replace(/^Given:\s*/i, "");
|
|
169
|
+
const whenMatch = WHEN_RE.exec(afterGiven);
|
|
170
|
+
const thenBase = whenMatch ? afterGiven.slice(whenMatch.index + whenMatch[0].length) : afterGiven;
|
|
171
|
+
const thenMatch = THEN_RE.exec(thenBase);
|
|
172
|
+
if (!whenMatch && !thenMatch)
|
|
173
|
+
return { given: "", when: "", then: trimmedChunk };
|
|
174
|
+
if (whenMatch && thenMatch) {
|
|
175
|
+
return {
|
|
176
|
+
given: afterGiven.slice(0, whenMatch.index).trim(),
|
|
177
|
+
when: thenBase.slice(0, thenMatch.index).trim(),
|
|
178
|
+
then: thenBase.slice(thenMatch.index + thenMatch[0].length).trim(),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (whenMatch)
|
|
182
|
+
return { given: afterGiven.slice(0, whenMatch.index).trim(), when: thenBase.trim(), then: "" };
|
|
183
|
+
return { given: thenBase.slice(0, thenMatch.index).trim(), when: "", then: thenBase.slice(thenMatch.index + thenMatch[0].length).trim() };
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// normalizeImplementation — handles both the split-tag and legacy bracketed forms.
|
|
187
|
+
// Strict legacy form: "[Status: X] [Additional Notes: Y]" (Y may itself be empty).
|
|
188
|
+
const LEGACY_STRICT_RE = /^\[Status:\s*([^\]]+)\]\s*\[Additional Notes:\s*([\s\S]*)\]\s*$/i;
|
|
189
|
+
// Looser legacy form: "[Status: X] <trailing text>" — trailing text not itself bracketed.
|
|
190
|
+
const LEGACY_LOOSE_RE = /^\[Status:\s*([^\]]+)\]\s*([\s\S]*)$/i;
|
|
191
|
+
/**
|
|
192
|
+
* FR-SPECS-0025 — normalizes `tags.implementation`/`tags.implementationNotes` for any of the
|
|
193
|
+
* three real-world shapes: (1) modern split tags; (2) legacy strict bracketed "[Status: X]
|
|
194
|
+
* [Additional Notes: Y]"; (3) legacy loose bracketed "[Status: X] <free text>" with no second
|
|
195
|
+
* bracket (docs/requirements/CHANGES.md's own description of the pre-split format). Never
|
|
196
|
+
* throws and never validates the extracted status against IMPLS — that is migrate.ts's job
|
|
197
|
+
* over the assembled document; this module stays a pure, validation-free mapper.
|
|
198
|
+
*/
|
|
199
|
+
export function normalizeImplementation(tags) {
|
|
200
|
+
const raw = (tags["implementation"] ?? "").trim();
|
|
201
|
+
const strict = LEGACY_STRICT_RE.exec(raw);
|
|
202
|
+
if (strict) {
|
|
203
|
+
return { implementation: strict[1].trim(), implementation_notes: strict[2].trim() };
|
|
204
|
+
}
|
|
205
|
+
const loose = LEGACY_LOOSE_RE.exec(raw);
|
|
206
|
+
if (loose) {
|
|
207
|
+
const trailing = (loose[2] ?? "").trim();
|
|
208
|
+
if (trailing.length > 0) {
|
|
209
|
+
return { implementation: loose[1].trim(), implementation_notes: trailing };
|
|
210
|
+
}
|
|
211
|
+
// "[Status: X]" alone — fall back to a separate implementationNotes tag if present.
|
|
212
|
+
return { implementation: loose[1].trim(), implementation_notes: (tags["implementationNotes"] ?? "").trim() };
|
|
213
|
+
}
|
|
214
|
+
// Modern split-tag form (no brackets at all).
|
|
215
|
+
return { implementation: (raw || "NotStarted"), implementation_notes: (tags["implementationNotes"] ?? "").trim() };
|
|
216
|
+
}
|
|
217
|
+
// mapToSpec — assembles a Partial<Spec> + warnings from one RawReq.
|
|
218
|
+
function splitIdList(raw) {
|
|
219
|
+
return raw
|
|
220
|
+
.split(",")
|
|
221
|
+
.map((s) => s.trim())
|
|
222
|
+
.filter((s) => s.length > 0);
|
|
223
|
+
}
|
|
224
|
+
function warn(id, check, message) {
|
|
225
|
+
return { id: id || "(unknown)", check, severity: "warning", message };
|
|
226
|
+
}
|
|
227
|
+
/** Best-effort ISO8601 UTC normalization of a `<changed>` value. The template uses a bare
|
|
228
|
+
* `YYYY-MM-DD` date; real docs sometimes carry a full timestamp already. Unparseable input is
|
|
229
|
+
* preserved verbatim (report-don't-drop) with a warning rather than discarded or defaulted. */
|
|
230
|
+
function normalizeChanged(raw, id, warnings) {
|
|
231
|
+
if (!raw)
|
|
232
|
+
return "";
|
|
233
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(raw)) {
|
|
234
|
+
const asMidnightUtc = new Date(`${raw}T00:00:00.000Z`);
|
|
235
|
+
if (!Number.isNaN(asMidnightUtc.getTime()))
|
|
236
|
+
return asMidnightUtc.toISOString();
|
|
237
|
+
}
|
|
238
|
+
const asIs = new Date(raw);
|
|
239
|
+
if (!Number.isNaN(asIs.getTime()))
|
|
240
|
+
return asIs.toISOString();
|
|
241
|
+
warnings.push(warn(id, "migrate_unparseable_changed", "The changed timestamp could not be parsed and was preserved verbatim."));
|
|
242
|
+
return raw;
|
|
243
|
+
}
|
|
244
|
+
/** Extracts `<criteria>` children from a raw `<acceptance>` body (falling back to treating the
|
|
245
|
+
* whole body as one implicit criteria block if no `<criteria>` tag is found at all), then
|
|
246
|
+
* splits each into given/when/then via splitGwt, warning on every unsplittable result. */
|
|
247
|
+
function extractAcceptance(acceptanceRaw, id, warnings) {
|
|
248
|
+
if (!acceptanceRaw.trim())
|
|
249
|
+
return [];
|
|
250
|
+
const blocks = [];
|
|
251
|
+
const criteriaRe = /<criteria\b[^>]*>([\s\S]*?)<\/criteria\s*>/gi;
|
|
252
|
+
let m;
|
|
253
|
+
while ((m = criteriaRe.exec(acceptanceRaw)) !== null)
|
|
254
|
+
blocks.push(m[1]);
|
|
255
|
+
if (blocks.length === 0)
|
|
256
|
+
blocks.push(acceptanceRaw);
|
|
257
|
+
const unsplittable = () => warn(id, "migrate_unsplittable_criterion", "An acceptance criterion could not be split into given/when/then and was preserved verbatim.");
|
|
258
|
+
const result = [];
|
|
259
|
+
for (const block of blocks) {
|
|
260
|
+
const split = splitGwt(block);
|
|
261
|
+
if ("verbatim" in split) {
|
|
262
|
+
if (split.verbatim) {
|
|
263
|
+
result.push({ given: "", when: "", then: split.verbatim });
|
|
264
|
+
warnings.push(unsplittable());
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
for (const criterion of split) {
|
|
269
|
+
result.push(criterion);
|
|
270
|
+
if (criterion.given === "" && criterion.when === "")
|
|
271
|
+
warnings.push(unsplittable());
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* FR-SPECS-0025 — maps one scanned `<req>` block to a Partial<Spec> plus warnings. Never
|
|
278
|
+
* throws; a missing id (the one field callers must key writes by) is reported as an
|
|
279
|
+
* error-severity SpecFinding, not a thrown exception, so migrate.ts can report-don't-drop and
|
|
280
|
+
* skip just that item. status/approved_by/changed/implementation are mapped as-is (not
|
|
281
|
+
* stripped the way add/update's stripGuarded would) — migrate imports pre-existing historical
|
|
282
|
+
* state, not a fresh user-authored item.
|
|
283
|
+
*/
|
|
284
|
+
export function mapToSpec(raw) {
|
|
285
|
+
const warnings = [];
|
|
286
|
+
const { attrs, tags } = raw;
|
|
287
|
+
const id = (tags["id"] ?? attrs["id"] ?? "").trim();
|
|
288
|
+
if (!id) {
|
|
289
|
+
warnings.push({
|
|
290
|
+
id: `line:${raw.sourceLine}`,
|
|
291
|
+
check: "migrate_missing_id",
|
|
292
|
+
severity: "error",
|
|
293
|
+
message: "A <req> block is missing its id attribute.",
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const spec = {};
|
|
297
|
+
if (id)
|
|
298
|
+
spec.id = id;
|
|
299
|
+
spec.type = (attrs["type"] ?? "");
|
|
300
|
+
spec.level = (attrs["level"] ?? "").trim() || "System";
|
|
301
|
+
const ticketId = (tags["ticketId"] ?? attrs["ticketId"] ?? "").trim();
|
|
302
|
+
if (ticketId)
|
|
303
|
+
spec.ticket_id = ticketId;
|
|
304
|
+
const classification = (attrs["classification"] ?? "").trim();
|
|
305
|
+
if (classification)
|
|
306
|
+
spec.classification = classification;
|
|
307
|
+
spec.title = (tags["title"] ?? "").trim();
|
|
308
|
+
spec.statement = (tags["statement"] ?? "").trim();
|
|
309
|
+
spec.rationale = (tags["rationale"] ?? "").trim();
|
|
310
|
+
spec.source = (tags["source"] ?? "");
|
|
311
|
+
spec.priority = (tags["priority"] ?? "");
|
|
312
|
+
spec.status = (tags["status"] ?? "Draft");
|
|
313
|
+
spec.approved_by = (tags["approved_by"] ?? "").trim();
|
|
314
|
+
spec.changed = normalizeChanged((tags["changed"] ?? "").trim(), id, warnings);
|
|
315
|
+
spec.verification = (tags["verification"] ?? "");
|
|
316
|
+
spec.notes = (tags["notes"] ?? "").trim();
|
|
317
|
+
spec.depends_on = splitIdList(tags["depends"] ?? "");
|
|
318
|
+
spec.related = splitIdList(tags["related"] ?? "");
|
|
319
|
+
const { implementation, implementation_notes } = normalizeImplementation(tags);
|
|
320
|
+
spec.implementation = implementation;
|
|
321
|
+
spec.implementation_notes = implementation_notes;
|
|
322
|
+
spec.acceptance = extractAcceptance(tags["acceptance"] ?? "", id, warnings);
|
|
323
|
+
return { spec, warnings };
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=req-parser.js.map
|