intent-format 0.0.0-stage → 1.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.
- package/.github/ISSUE_TEMPLATE/1-something-wrong.yml +18 -0
- package/.github/ISSUE_TEMPLATE/2-idea.yml +11 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/AGENTS.md +11 -0
- package/CHANGELOG.md +287 -0
- package/CLAUDE.md +1 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +19 -0
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/SECURITY.md +10 -0
- package/VERSION +1 -0
- package/examples/example-app/AGENTS.md +19 -0
- package/examples/example-app/CLAUDE.md +1 -0
- package/examples/example-app/V1.0/apis/_index.md +14 -0
- package/examples/example-app/V1.0/apis/ap000001-list-items.md +20 -0
- package/examples/example-app/V1.0/apis/ap000002-save-item.md +28 -0
- package/examples/example-app/V1.0/backend/_index.md +15 -0
- package/examples/example-app/V1.0/backend/bn000001-app-server.md +24 -0
- package/examples/example-app/V1.0/backend/bn000002-main-database.md +22 -0
- package/examples/example-app/V1.0/backend/bn000003-file-storage.md +22 -0
- package/examples/example-app/V1.0/comments/_index.md +13 -0
- package/examples/example-app/V1.0/comments/cm000001-empty-list-message.md +15 -0
- package/examples/example-app/V1.0/components/_index.md +16 -0
- package/examples/example-app/V1.0/components/cp000001-button.md +32 -0
- package/examples/example-app/V1.0/components/cp000002-text-field.md +31 -0
- package/examples/example-app/V1.0/components/cp000003-item-row.md +34 -0
- package/examples/example-app/V1.0/components/cp000004-top-bar.md +26 -0
- package/examples/example-app/V1.0/decisions/_index.md +13 -0
- package/examples/example-app/V1.0/decisions/dc000001-where-do-item-images-live.md +26 -0
- package/examples/example-app/V1.0/edge-cases/_index.md +13 -0
- package/examples/example-app/V1.0/edge-cases/ec000001-save-fails.md +24 -0
- package/examples/example-app/V1.0/features/_index.md +17 -0
- package/examples/example-app/V1.0/features/ft000001-items.md +22 -0
- package/examples/example-app/V1.0/features/ft000002-account.md +21 -0
- package/examples/example-app/V1.0/features/ft000003-browse-items.md +26 -0
- package/examples/example-app/V1.0/features/ft000004-edit-an-item.md +33 -0
- package/examples/example-app/V1.0/features/ft000005-change-settings.md +21 -0
- package/examples/example-app/V1.0/ia/_index.md +13 -0
- package/examples/example-app/V1.0/ia/ia000001-main-map.md +23 -0
- package/examples/example-app/V1.0/intent-format.md +12 -0
- package/examples/example-app/V1.0/project.md +51 -0
- package/examples/example-app/V1.0/roles/_index.md +14 -0
- package/examples/example-app/V1.0/roles/ro000001-member.md +22 -0
- package/examples/example-app/V1.0/roles/ro000002-admin.md +19 -0
- package/examples/example-app/V1.0/rules/_index.md +13 -0
- package/examples/example-app/V1.0/rules/rl000001-item-name-is-required.md +20 -0
- package/examples/example-app/V1.0/screens/_index.md +17 -0
- package/examples/example-app/V1.0/screens/sc000001-home.md +18 -0
- package/examples/example-app/V1.0/screens/sc000002-item-list.md +43 -0
- package/examples/example-app/V1.0/screens/sc000003-item-detail.md +24 -0
- package/examples/example-app/V1.0/screens/sc000004-edit-item.md +35 -0
- package/examples/example-app/V1.0/screens/sc000005-settings.md +19 -0
- package/examples/example-app/V1.0/shells/_index.md +8 -0
- package/examples/example-app/V1.0/tech/_index.md +14 -0
- package/examples/example-app/V1.0/tech/tc000001-ui-framework.md +23 -0
- package/examples/example-app/V1.0/tech/tc000002-relational-database.md +25 -0
- package/examples/example-app/V1.0/userflows/_index.md +14 -0
- package/examples/example-app/V1.0/userflows/uf000001-create-an-item.md +66 -0
- package/examples/example-app/V1.0/userflows/uf000002-edit-an-item.md +47 -0
- package/examples/example-app/V1.1/CHANGES.md +12 -0
- package/examples/example-app/V1.1/apis/_index.md +14 -0
- package/examples/example-app/V1.1/apis/ap000001-list-items.md +20 -0
- package/examples/example-app/V1.1/apis/ap000002-save-item.md +28 -0
- package/examples/example-app/V1.1/backend/_index.md +15 -0
- package/examples/example-app/V1.1/backend/bn000001-app-server.md +24 -0
- package/examples/example-app/V1.1/backend/bn000002-main-database.md +22 -0
- package/examples/example-app/V1.1/backend/bn000003-file-storage.md +22 -0
- package/examples/example-app/V1.1/comments/_index.md +14 -0
- package/examples/example-app/V1.1/comments/cm000001-empty-list-message.md +15 -0
- package/examples/example-app/V1.1/comments/cm000002-filter-placement.md +12 -0
- package/examples/example-app/V1.1/components/_index.md +16 -0
- package/examples/example-app/V1.1/components/cp000001-button.md +32 -0
- package/examples/example-app/V1.1/components/cp000002-text-field.md +32 -0
- package/examples/example-app/V1.1/components/cp000003-item-row.md +34 -0
- package/examples/example-app/V1.1/components/cp000004-top-bar.md +26 -0
- package/examples/example-app/V1.1/decisions/_index.md +13 -0
- package/examples/example-app/V1.1/decisions/dc000001-where-do-item-images-live.md +26 -0
- package/examples/example-app/V1.1/edge-cases/_index.md +13 -0
- package/examples/example-app/V1.1/edge-cases/ec000001-save-fails.md +24 -0
- package/examples/example-app/V1.1/features/_index.md +17 -0
- package/examples/example-app/V1.1/features/ft000001-items.md +22 -0
- package/examples/example-app/V1.1/features/ft000002-account.md +21 -0
- package/examples/example-app/V1.1/features/ft000003-browse-items.md +26 -0
- package/examples/example-app/V1.1/features/ft000004-edit-an-item.md +33 -0
- package/examples/example-app/V1.1/features/ft000005-change-settings.md +21 -0
- package/examples/example-app/V1.1/ia/_index.md +13 -0
- package/examples/example-app/V1.1/ia/ia000001-main-map.md +23 -0
- package/examples/example-app/V1.1/intent-format.md +13 -0
- package/examples/example-app/V1.1/project.md +51 -0
- package/examples/example-app/V1.1/roles/_index.md +14 -0
- package/examples/example-app/V1.1/roles/ro000001-member.md +22 -0
- package/examples/example-app/V1.1/roles/ro000002-admin.md +19 -0
- package/examples/example-app/V1.1/rules/_index.md +13 -0
- package/examples/example-app/V1.1/rules/rl000001-item-name-is-required.md +20 -0
- package/examples/example-app/V1.1/screens/_index.md +17 -0
- package/examples/example-app/V1.1/screens/sc000001-home.md +18 -0
- package/examples/example-app/V1.1/screens/sc000002-item-list.md +44 -0
- package/examples/example-app/V1.1/screens/sc000003-item-detail.md +24 -0
- package/examples/example-app/V1.1/screens/sc000004-edit-item.md +35 -0
- package/examples/example-app/V1.1/screens/sc000005-settings.md +19 -0
- package/examples/example-app/V1.1/shells/_index.md +8 -0
- package/examples/example-app/V1.1/tech/_index.md +14 -0
- package/examples/example-app/V1.1/tech/tc000001-ui-framework.md +23 -0
- package/examples/example-app/V1.1/tech/tc000002-relational-database.md +25 -0
- package/examples/example-app/V1.1/userflows/_index.md +14 -0
- package/examples/example-app/V1.1/userflows/uf000001-create-an-item.md +66 -0
- package/examples/example-app/V1.1/userflows/uf000002-edit-an-item.md +47 -0
- package/examples/example-app/_ids.md +78 -0
- package/examples/example-app/_index.md +14 -0
- package/examples/example-app/inputs/brief.md +3 -0
- package/examples/example-app/inputs/links.md +3 -0
- package/kit/cli/README.md +128 -0
- package/kit/cli/intent-format.mjs +342 -0
- package/kit/cli/lib/agents.mjs +39 -0
- package/kit/cli/lib/check.mjs +412 -0
- package/kit/cli/lib/create.mjs +190 -0
- package/kit/cli/lib/frame.mjs +182 -0
- package/kit/cli/lib/generate.mjs +418 -0
- package/kit/cli/lib/kit.mjs +203 -0
- package/kit/cli/lib/migrate.mjs +97 -0
- package/kit/cli/lib/model.mjs +409 -0
- package/kit/cli/lib/next.mjs +134 -0
- package/kit/cli/lib/open.mjs +34 -0
- package/kit/cli/lib/parse.mjs +260 -0
- package/kit/cli/lib/project.mjs +120 -0
- package/kit/cli/lib/regen.mjs +112 -0
- package/kit/cli/lib/relations.mjs +380 -0
- package/kit/cli/lib/rename.mjs +23 -0
- package/kit/cli/lib/schema.mjs +185 -0
- package/kit/cli/lib/templates.mjs +41 -0
- package/kit/cli/lib/util.mjs +165 -0
- package/kit/cli/test/nav.mjs +145 -0
- package/kit/cli/test/roles.mjs +85 -0
- package/kit/cli/test/smoke.mjs +716 -0
- package/kit/skills/intent-format/SKILL.md +91 -0
- package/kit/skills/intent-format/links.md +142 -0
- package/kit/skills/intent-format/types/_overview.md +73 -0
- package/kit/skills/intent-format/types/api.md +111 -0
- package/kit/skills/intent-format/types/backend.md +110 -0
- package/kit/skills/intent-format/types/comment.md +66 -0
- package/kit/skills/intent-format/types/component.md +139 -0
- package/kit/skills/intent-format/types/decision.md +91 -0
- package/kit/skills/intent-format/types/edge-case.md +107 -0
- package/kit/skills/intent-format/types/feature.md +154 -0
- package/kit/skills/intent-format/types/ia.md +106 -0
- package/kit/skills/intent-format/types/project.md +131 -0
- package/kit/skills/intent-format/types/role.md +98 -0
- package/kit/skills/intent-format/types/rule.md +100 -0
- package/kit/skills/intent-format/types/screen.md +153 -0
- package/kit/skills/intent-format/types/shell.md +156 -0
- package/kit/skills/intent-format/types/tech.md +109 -0
- package/kit/skills/intent-format/types/userflow.md +197 -0
- package/kit/skills/kb-cold-start/SKILL.md +124 -0
- package/kit/skills/kb-cold-start/kickoff-questionnaire.md +42 -0
- package/kit/skills/kb-cold-start/templates.md +108 -0
- package/package.json +30 -4
- package/rationale.md +180 -0
- package/schema.json +5895 -0
- package/spec.md +1173 -0
- package/templates/api.md +16 -0
- package/templates/backend.md +15 -0
- package/templates/comment.md +11 -0
- package/templates/component.md +15 -0
- package/templates/decision.md +23 -0
- package/templates/edge-case.md +14 -0
- package/templates/feature.md +14 -0
- package/templates/ia.md +14 -0
- package/templates/project.md +34 -0
- package/templates/role.md +14 -0
- package/templates/rule.md +14 -0
- package/templates/screen.md +14 -0
- package/templates/shell.md +24 -0
- package/templates/tech.md +18 -0
- package/templates/userflow.md +20 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Small helpers shared by the mds modules. No dependencies.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const toPosix = (p) => p.split(path.sep).join('/');
|
|
6
|
+
|
|
7
|
+
export function readText(file) {
|
|
8
|
+
return fs.readFileSync(file, 'utf8').replace(/\r\n?/g, '\n');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function exists(p) {
|
|
12
|
+
try { fs.accessSync(p); return true; } catch { return false; }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isDir(p) {
|
|
16
|
+
try { return fs.statSync(p).isDirectory(); } catch { return false; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const byName = (a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
20
|
+
|
|
21
|
+
export function listDir(dir) {
|
|
22
|
+
try { return fs.readdirSync(dir, { withFileTypes: true }).sort(byName); } catch { return []; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Every .md file under dir (recursive, dot-folders skipped), sorted. */
|
|
26
|
+
export function walkMd(dir) {
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const e of listDir(dir)) {
|
|
29
|
+
if (e.name.startsWith('.')) continue;
|
|
30
|
+
const p = path.join(dir, e.name);
|
|
31
|
+
if (e.isDirectory()) out.push(...walkMd(p));
|
|
32
|
+
else if (e.isFile() && e.name.endsWith('.md')) out.push(p);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Write only when the bytes differ. Returns true when the file was written. */
|
|
38
|
+
export function writeIfChanged(file, text) {
|
|
39
|
+
let old = null;
|
|
40
|
+
try { old = fs.readFileSync(file, 'utf8'); } catch { /* new file */ }
|
|
41
|
+
if (old === text) return false;
|
|
42
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
43
|
+
fs.writeFileSync(file, text);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function copyDir(src, dst) {
|
|
48
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
49
|
+
for (const e of listDir(src)) {
|
|
50
|
+
const s = path.join(src, e.name), d = path.join(dst, e.name);
|
|
51
|
+
if (e.isDirectory()) copyDir(s, d);
|
|
52
|
+
else if (e.isFile()) fs.copyFileSync(s, d);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** ids.slug: NFKD fold, drop marks, lowercase, runs outside a-z0-9 → -, trim, cut 60. */
|
|
57
|
+
export function slugify(name, fallback) {
|
|
58
|
+
let s = String(name).normalize('NFKD').replace(/\p{M}+/gu, '').toLowerCase()
|
|
59
|
+
.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
60
|
+
if (s.length > 60) s = s.slice(0, 60).replace(/-+$/, '');
|
|
61
|
+
return s || fallback;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function parseVersion(v) {
|
|
65
|
+
const m = /^(\d+)\.(\d+)(?:-([a-z0-9-]+))?$/.exec(v || '');
|
|
66
|
+
return m ? { major: +m[1], minor: +m[2], label: m[3] || '' } : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** versions sort: major, minor numerically; a labelled exploration after its unlabelled version. */
|
|
70
|
+
export function compareVersions(a, b) {
|
|
71
|
+
const x = parseVersion(a), y = parseVersion(b);
|
|
72
|
+
if (!x || !y) return a < b ? -1 : a > b ? 1 : 0;
|
|
73
|
+
if (x.major !== y.major) return x.major - y.major;
|
|
74
|
+
if (x.minor !== y.minor) return x.minor - y.minor;
|
|
75
|
+
if (x.label === y.label) return 0;
|
|
76
|
+
if (x.label === '') return -1;
|
|
77
|
+
if (y.label === '') return 1;
|
|
78
|
+
return x.label < y.label ? -1 : 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Split str at every top-level occurrence of sep (outside [], () and "…").
|
|
83
|
+
* Returns [{ text, start }] with start offsets into str. max = maximum number of splits.
|
|
84
|
+
*/
|
|
85
|
+
export function splitTop(str, sep, max = Infinity) {
|
|
86
|
+
const out = [];
|
|
87
|
+
let sq = 0, par = 0, inQ = false, last = 0, splits = 0;
|
|
88
|
+
for (let i = 0; i < str.length; i++) {
|
|
89
|
+
const c = str[i];
|
|
90
|
+
if (inQ) {
|
|
91
|
+
if (c === '\\') { i++; continue; }
|
|
92
|
+
if (c === '"') inQ = false;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (c === '"') { inQ = true; continue; }
|
|
96
|
+
if (c === '[') sq++;
|
|
97
|
+
else if (c === ']') sq = Math.max(0, sq - 1);
|
|
98
|
+
else if (c === '(') par++;
|
|
99
|
+
else if (c === ')') par = Math.max(0, par - 1);
|
|
100
|
+
else if (sq === 0 && par === 0 && splits < max && str.startsWith(sep, i)) {
|
|
101
|
+
out.push({ text: str.slice(last, i), start: last });
|
|
102
|
+
i += sep.length - 1;
|
|
103
|
+
last = i + 1;
|
|
104
|
+
splits++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
out.push({ text: str.slice(last), start: last });
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function unquote(v) {
|
|
112
|
+
return v.replace(/\\(.)/g, '$1');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function quote(v) {
|
|
116
|
+
return '"' + v.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const escapeCell = (s) => String(s).replace(/\|/g, '\\|');
|
|
120
|
+
|
|
121
|
+
/** Relative link path from one file to another ('' when it is the same file). */
|
|
122
|
+
export function relLink(fromFile, toFile) {
|
|
123
|
+
if (path.resolve(fromFile) === path.resolve(toFile)) return '';
|
|
124
|
+
return toPosix(path.relative(path.dirname(fromFile), toFile));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function cut(text, max) {
|
|
128
|
+
const chars = Array.from(text);
|
|
129
|
+
if (chars.length <= max) return text;
|
|
130
|
+
return chars.slice(0, max - 1).join('').trimEnd() + '…';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const pad6 = (n) => String(n).padStart(6, '0');
|
|
134
|
+
|
|
135
|
+
export function sortBy(arr, ...keys) {
|
|
136
|
+
return arr.sort((a, b) => {
|
|
137
|
+
for (const k of keys) {
|
|
138
|
+
const x = k(a), y = k(b);
|
|
139
|
+
if (x < y) return -1;
|
|
140
|
+
if (x > y) return 1;
|
|
141
|
+
}
|
|
142
|
+
return 0;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Run fn holding <root>/.mds.lock, so two agents writing one project in parallel do not clobber
|
|
148
|
+
* _ids.md or generated files. Waits up to 30 s; a lock older than 2 min is stale and removed.
|
|
149
|
+
*/
|
|
150
|
+
export function withLock(root, fn) {
|
|
151
|
+
const lock = path.join(root, '.mds.lock');
|
|
152
|
+
fs.mkdirSync(root, { recursive: true });
|
|
153
|
+
const until = Date.now() + 30000;
|
|
154
|
+
for (;;) {
|
|
155
|
+
try { fs.mkdirSync(lock); break; } catch (e) {
|
|
156
|
+
if (e.code !== 'EEXIST') throw e;
|
|
157
|
+
let age = 0;
|
|
158
|
+
try { age = Date.now() - fs.statSync(lock).mtimeMs; } catch { continue; }
|
|
159
|
+
if (age > 120000) { fs.rmSync(lock, { recursive: true, force: true }); continue; }
|
|
160
|
+
if (Date.now() > until) throw Object.assign(new Error(`another mds command is writing ${root} (.mds.lock) — retry, or delete .mds.lock if no mds is running`), { locked: true });
|
|
161
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
try { return fn(); } finally { fs.rmSync(lock, { recursive: true, force: true }); }
|
|
165
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Shell navigation and cold-start steering: stacked variants, one navigation list, the checks
|
|
3
|
+
// W017 / W048 / I027 / I028, intent-format frame, intent-format next through every phase, the lock, AGENTS.md.
|
|
4
|
+
// node kit/cli/test/nav.mjs [--keep]
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { spawnSync, spawn } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const MDS = path.join(here, '..', 'intent-format.mjs');
|
|
13
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mds-nav-'));
|
|
14
|
+
const R = path.join(tmp, 'shop');
|
|
15
|
+
const results = [];
|
|
16
|
+
let failed = 0;
|
|
17
|
+
const step = (name, pass, detail = '') => { results.push(`${pass ? '✓' : '✗'} ${name}${detail && !pass ? ' — ' + detail : ''}`); if (!pass) failed++; };
|
|
18
|
+
const mds = (...a) => { const r = spawnSync(process.execPath, [MDS, ...a], { encoding: 'utf8' }); return { code: r.status, out: r.stdout, err: r.stderr }; };
|
|
19
|
+
const put = (rel, t) => { fs.mkdirSync(path.dirname(path.join(R, rel)), { recursive: true }); fs.writeFileSync(path.join(R, rel), t); };
|
|
20
|
+
const get = (rel) => fs.readFileSync(path.join(R, rel), 'utf8');
|
|
21
|
+
const next = () => JSON.parse(mds('next', R, '--json').out);
|
|
22
|
+
const codes = () => JSON.parse(mds('check', R, '--json').out).diagnostics.map((d) => d.code);
|
|
23
|
+
|
|
24
|
+
/* ---------- cold start, phase by phase ---------- */
|
|
25
|
+
let n = next();
|
|
26
|
+
step('next: no project → set up', n.step === 1, JSON.stringify(n));
|
|
27
|
+
fs.mkdirSync(path.join(R, 'inputs'), { recursive: true });
|
|
28
|
+
put('inputs/brief.md', '# Brief\n\nA shop: guests browse, members buy.\n');
|
|
29
|
+
mds('init', R, '--name', 'Shop');
|
|
30
|
+
step('init writes AGENTS.md and CLAUDE.md', /intent-format\.mjs" next \./.test(get('AGENTS.md')) && get('CLAUDE.md') === '@AGENTS.md\n');
|
|
31
|
+
put('AGENTS.md', '# mine\n');
|
|
32
|
+
mds('regen', R);
|
|
33
|
+
step('regen never overwrites AGENTS.md', get('AGENTS.md') === '# mine\n');
|
|
34
|
+
n = next();
|
|
35
|
+
step('next: kickoff', n.step === 2 && !n.unattended);
|
|
36
|
+
put('inputs/kickoff-answers.md', 'Mode: unattended\n\n1. Unknown\n');
|
|
37
|
+
n = next();
|
|
38
|
+
step('next: proposal, unattended noticed', n.step === 3 && n.unattended);
|
|
39
|
+
const inv = ['# Inventory', '', '| # | Type | Name | Parent / home | Evidence | Confidence | Notes | Core |', '|---|---|---|---|---|---|---|---|',
|
|
40
|
+
'| 1 | shell | Web shell | | brief | high | | |', '| 2 | screen | Home | | brief | high | | |', '| 3 | screen | Account | | brief | high | | |',
|
|
41
|
+
'| 4 | screen | Sign in | | brief | high | | |', '| 5 | component | Header | | brief | high | | |', '| 6 | component | Account menu | | brief | high | | |',
|
|
42
|
+
'| 7 | component | Burger | | brief | high | | |', '| 8 | ia | Main map | | brief | high | | |', ''].join('\n');
|
|
43
|
+
put('proposal/inventory.md', inv);
|
|
44
|
+
put('proposal/decisions.md', '| # | Question | Options | Recommendation | Why |\n|---|---|---|---|---|\n| D1 | One shell or two? | a) b) | a | same nav |\n');
|
|
45
|
+
n = next();
|
|
46
|
+
step('next: unattended review is written, not skipped', n.step === 4 && /Unattended/.test(n.do[0]));
|
|
47
|
+
put('proposal/review.md', 'Unattended — recommendations applied.\n');
|
|
48
|
+
n = next();
|
|
49
|
+
step('next: scaffold', n.step === 5 && /intent-format scaffold/.test(n.do[0]));
|
|
50
|
+
mds('scaffold', R, '--inventory', path.join(R, 'proposal/inventory.md'));
|
|
51
|
+
n = next();
|
|
52
|
+
step('next: fill project first', n.step === 6 && /project card/.test(n.do[0]), n.do?.[0]);
|
|
53
|
+
|
|
54
|
+
/* ---------- fill: vocabularies, shell, map, screens ---------- */
|
|
55
|
+
const ids = Object.fromEntries([...get('proposal/inventory.md').matchAll(/\| \d+ \| [a-z]+ \| ([^|]+?) \|.*\| ([A-Z]{2}\d{6}) \|/g)].map((m) => [m[1], m[2]]));
|
|
56
|
+
const ref = (name, folder) => `[#${ids[name]} ${name}](../${folder}/${ids[name].toLowerCase()}-${name.toLowerCase().replace(/ /g, '-')}.md)`;
|
|
57
|
+
const proj = get('V1.0/project.md');
|
|
58
|
+
put('V1.0/project.md', proj.replace(/## Description\n—/, '## Description\nA shop.')
|
|
59
|
+
.replace(/### States\n[\s\S]*?(?=### Platforms)/, '### States\n| State | Code | Note |\n|---|---|---|\n| Guest | SGU | not signed in |\n| Member | SM | signed in |\n\n')
|
|
60
|
+
.replace(/### Platforms\n[^#]*/, '### Platforms\n- Desktop web\n- Mobile web\n\n')
|
|
61
|
+
.replace(/### Opens-as\n[^#]*/, '### Opens-as\n- Dropdown\n- Side panel\n\n'));
|
|
62
|
+
const shellFile = `V1.0/shells/${ids['Web shell'].toLowerCase()}-web-shell.md`;
|
|
63
|
+
put(shellFile, get(shellFile).replace('shell-type: —', 'shell-type: app').replace(/## Description\n—/, '## Description\nThe web frame.')
|
|
64
|
+
.replace(/## Components\n—/, `## Components\n1. ${ref('Header', 'components')}`)
|
|
65
|
+
.replace(/## Navigation\n—/, `## Navigation\n1. ${ref('Home', 'screens')} · kind: tab · in: Header\n2. ${ref('Sign in', 'screens')} · in: Header · state: Guest\n3. ${ref('Account', 'screens')} · kind: menu · in: Account menu · state: Member\n4. ${ref('Account', 'screens')} · in: Header`)
|
|
66
|
+
.replace(/## Places inside\n—/, '## Places inside\n🚫 Never show navigation of your own.')
|
|
67
|
+
+ `\n## Variants\n### Mobile web · #HV000001\n<a id="hv000001"></a>\nplatform: Mobile web\n\n1. ${ref('Burger', 'components')}\n- Leads to: ${ref('Home', 'screens')}\n\n### Member · #HV000002\n<a id="hv000002"></a>\nstate: Member\n\n1. ${ref('Account menu', 'components')} · opens-as: Dropdown\n`);
|
|
68
|
+
mds('mint', 'HV', '--root', R, '--count', '2');
|
|
69
|
+
const homeFile = `V1.0/screens/${ids.Home.toLowerCase()}-home.md`;
|
|
70
|
+
put(homeFile, get(homeFile).replace(/## Description\n—/, '## Description\nThe start.').replace(/## Components\n—/, `## Components\n1. ${ref('Header', 'components')}`));
|
|
71
|
+
const accFile = `V1.0/screens/${ids.Account.toLowerCase()}-account.md`;
|
|
72
|
+
put(accFile, get(accFile).replace(/^status: —\n/m, 'status: —\nstate: Member\n'));
|
|
73
|
+
const mapFile = `V1.0/ia/${ids['Main map'].toLowerCase()}-main-map.md`;
|
|
74
|
+
put(mapFile, get(mapFile).replace(/## Parts\n—/, `## Parts\n- ${ref('Home', 'screens')}\n - ${ref('Account', 'screens')}`));
|
|
75
|
+
const c = codes();
|
|
76
|
+
step('W017: navigation in a variant', c.includes('W017'));
|
|
77
|
+
step('I027: a shell part on a screen', c.includes('I027'));
|
|
78
|
+
step('I028: a line shown where its screen does not exist', c.filter((x) => x === 'I028').length === 1, c.join(' '));
|
|
79
|
+
step('W048 absent while every in: is a part', !c.includes('W048'));
|
|
80
|
+
put(shellFile, get(shellFile).replace('· in: Header\n', '· in: Footer\n').replace(/\n- Leads to: .*\n/, '\n'));
|
|
81
|
+
step('W048: in: names no part of the shell', codes().includes('W048'));
|
|
82
|
+
put(shellFile, get(shellFile).replace('· in: Footer\n', '· in: Header\n').replace(/\n4\. .* · in: Header\n/, '\n'));
|
|
83
|
+
put(homeFile, get(homeFile).replace(/## Components\n1\. .*\n/, '## Components\nnone\n'));
|
|
84
|
+
mds('regen', R);
|
|
85
|
+
|
|
86
|
+
/* ---------- frame: stacking and one list ---------- */
|
|
87
|
+
const fr = JSON.parse(mds('frame', R, 'Account', '--json').out);
|
|
88
|
+
const at = (p) => fr.find((r) => r.platform === p);
|
|
89
|
+
const mob = at('Mobile web');
|
|
90
|
+
step('frame: variants stack (Mobile web + Member)', mob && mob.variants.map((v) => v.name).join('+') === 'Mobile web+Member', JSON.stringify(mob?.variants));
|
|
91
|
+
step('frame: parts merge across variants', mob && mob.parts.map((p) => p.name).join(',') === 'Header,Burger,Account menu', JSON.stringify(mob?.parts));
|
|
92
|
+
step('frame: navigation filtered by state, entry placed by in:', mob && mob.navigation.map((x) => `${x.name}@${x.in}`).join(',') === 'Home@Header,Account@Account menu', JSON.stringify(mob?.navigation));
|
|
93
|
+
const txt = mds('frame', R, 'Account').out;
|
|
94
|
+
step('frame: identical frames print once, contract once', (txt.match(/Places inside —/g) || []).length === 1 && /at {5}Main map › Home › Account · Member — Desktop web/.test(txt), txt);
|
|
95
|
+
|
|
96
|
+
/* ---------- resolution: platform skip, stepper of a flow, flow platform ---------- */
|
|
97
|
+
const area = mds('new', 'shell', 'Account area', '--root', R).out.trim().split(' ');
|
|
98
|
+
put(area[1], get(area[1]).replace('shell-type: —', 'shell-type: section\nplatform: Desktop web'));
|
|
99
|
+
put(mapFile, get(mapFile).replace(/( - \[#SC\d+ Account\]\([^)]*\))/, `$1 · shell: #${area[0]}`));
|
|
100
|
+
let fa = JSON.parse(mds('frame', R, 'Account', '--json').out);
|
|
101
|
+
step('a node binding applies where the shell fits the platform', fa.find((r) => r.platform === 'Desktop web' && r.where.startsWith('Main map'))?.shell?.id === area[0]);
|
|
102
|
+
step('a node binding to a desktop-only shell is skipped on mobile', fa.find((r) => r.platform === 'Mobile web' && r.where.startsWith('Main map'))?.shell?.id === ids['Web shell']);
|
|
103
|
+
const st = mds('new', 'shell', 'Sign-in stepper', '--root', R).out.trim().split(' ');
|
|
104
|
+
put(st[1], get(st[1]).replace('shell-type: —', 'shell-type: stepper\nflow: UF000777'));
|
|
105
|
+
const { loadSchema } = await import('../lib/schema.mjs');
|
|
106
|
+
const { loadProject } = await import('../lib/project.mjs');
|
|
107
|
+
const { resolvePlacement } = await import('../lib/frame.mjs');
|
|
108
|
+
const S2 = loadSchema(), P2 = loadProject(S2, R), ws2 = P2.workspaces[0];
|
|
109
|
+
const signIn = ws2.cards.find((c) => c.name === 'Sign in');
|
|
110
|
+
const rp = resolvePlacement(S2, ws2, { screen: signIn, platform: 'Desktop web', state: 'Guest', depth: null, flow: { id: 'UF000777', name: 'Sign in' } });
|
|
111
|
+
step('a step of a flow gets that flow’s stepper by default', rp.shell?.id === st[0] && /stepper/.test(rp.via), rp.via);
|
|
112
|
+
const rp2 = resolvePlacement(S2, ws2, { screen: signIn, platform: 'Desktop web', state: 'Guest', depth: 1 });
|
|
113
|
+
step('the same screen on the map keeps the app shell', rp2.shell?.id === ids['Web shell']);
|
|
114
|
+
const st2 = mds('new', 'shell', 'Second stepper', '--root', R).out.trim().split(' ');
|
|
115
|
+
put(st2[1], get(st2[1]).replace('shell-type: —', 'shell-type: stepper\nflow: UF000777'));
|
|
116
|
+
step('W045: two steppers for one flow', codes().filter((x) => x === 'W045').length >= 1);
|
|
117
|
+
for (const f of [st[1], st2[1], area[1]]) fs.rmSync(path.join(R, f));
|
|
118
|
+
put(mapFile, get(mapFile).replace(/ · shell: #SH\d+/, ''));
|
|
119
|
+
mds('regen', R);
|
|
120
|
+
|
|
121
|
+
/* ---------- next during fill, then the end ---------- */
|
|
122
|
+
n = next();
|
|
123
|
+
step('next: fill order (shell before screen, decisions counted)', n.step === 6 && !/shell card/.test(n.do[0]), n.do?.join(' | '));
|
|
124
|
+
put('report.md', '# Report\n');
|
|
125
|
+
n = next();
|
|
126
|
+
step('next: report present → ongoing', n.mode === 'ongoing');
|
|
127
|
+
|
|
128
|
+
/* ---------- lock ---------- */
|
|
129
|
+
fs.mkdirSync(path.join(R, '.mds.lock'));
|
|
130
|
+
const t0 = Date.now();
|
|
131
|
+
const locked = spawn(process.execPath, [MDS, 'mint', 'FS', '--root', R]);
|
|
132
|
+
let lockedOut = '';
|
|
133
|
+
locked.stdout.on('data', (d) => (lockedOut += d));
|
|
134
|
+
setTimeout(() => fs.rmSync(path.join(R, '.mds.lock'), { recursive: true, force: true }), 600);
|
|
135
|
+
await new Promise((res) => locked.on('close', res));
|
|
136
|
+
step('lock: a writer waits for the lock, then runs', /^FS\d{6}$/m.test(lockedOut) && Date.now() - t0 >= 500 && !fs.existsSync(path.join(R, '.mds.lock')));
|
|
137
|
+
const par = await Promise.all([0, 1, 2, 3].map(() => new Promise((res) => { let o = ''; const p = spawn(process.execPath, [MDS, 'mint', 'CV', '--root', R, '--count', '5']); p.stdout.on('data', (d) => (o += d)); p.on('close', () => res(o.trim().split('\n'))); })));
|
|
138
|
+
const all = par.flat();
|
|
139
|
+
step('lock: parallel mints never collide', all.length === 20 && new Set(all).size === 20, all.join(' '));
|
|
140
|
+
|
|
141
|
+
console.log('mds navigation + next test');
|
|
142
|
+
for (const l of results) console.log(' ' + l);
|
|
143
|
+
console.log(failed ? `FAILED (${failed})` : 'PASSED');
|
|
144
|
+
if (process.argv.includes('--keep')) console.log(`kept ${tmp}`); else fs.rmSync(tmp, { recursive: true, force: true });
|
|
145
|
+
process.exitCode = failed ? 1 : 0;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Role cards: stories resolve by name, ⚙ Stories, W049 / W050 / I029, intent-format migrate across
|
|
3
|
+
// versions (one core per role, archived skipped, idempotent), next sends old KBs to migrate.
|
|
4
|
+
// node kit/cli/test/roles.mjs [--keep]
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const MDS = path.join(here, '..', 'intent-format.mjs');
|
|
13
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mds-roles-'));
|
|
14
|
+
const R = path.join(tmp, 'kb');
|
|
15
|
+
const results = [];
|
|
16
|
+
let failed = 0;
|
|
17
|
+
const step = (name, pass, detail = '') => { results.push(`${pass ? '✓' : '✗'} ${name}${detail && !pass ? ' — ' + detail : ''}`); if (!pass) failed++; };
|
|
18
|
+
const mds = (...a) => { const r = spawnSync(process.execPath, [MDS, ...a], { encoding: 'utf8' }); return { code: r.status, out: r.stdout, err: r.stderr }; };
|
|
19
|
+
const get = (rel) => fs.readFileSync(path.join(R, rel), 'utf8');
|
|
20
|
+
const put = (rel, t) => { fs.mkdirSync(path.dirname(path.join(R, rel)), { recursive: true }); fs.writeFileSync(path.join(R, rel), t); };
|
|
21
|
+
const diags = () => JSON.parse(mds('check', R, '--json').out).diagnostics;
|
|
22
|
+
const has = (code) => diags().some((d) => d.code === code);
|
|
23
|
+
|
|
24
|
+
/* ---------- an old-style KB: Roles table, two versions, one archived ---------- */
|
|
25
|
+
mds('init', R, '--name', 'Kb');
|
|
26
|
+
const old = (p) => p.replace(/## User stories\n—/, '## User stories\n- As a Guest, I want to look around, so that I can decide.\n- As a Member, I want to buy, so that I get the thing.')
|
|
27
|
+
.replace('## Vocabularies\n', '## Vocabularies\n### Roles\n| Role | Description | States |\n|---|---|---|\n| Guest | Looks around | Signed out |\n| Member | Buys things | Signed in |\n| Staff | Back office, not in this KB | |\n\n')
|
|
28
|
+
.replace(/### States\n\| State \| Code \| Note \|\n\|---\|---\|---\|\n/, '### States\n| State | Code | Note |\n|---|---|---|\n| Signed out | SSO | |\n| Signed in | SSI | |\n');
|
|
29
|
+
put('V1.0/project.md', old(get('V1.0/project.md')));
|
|
30
|
+
step('old table still resolves stories (no W037)', !has('W037') && has('W050'));
|
|
31
|
+
mds('branch', R, 'V1.0', 'V1.1');
|
|
32
|
+
mds('branch', R, 'V1.1', 'V1.2');
|
|
33
|
+
put('V1.0/intent-format.md', get('V1.0/intent-format.md').replace(/lifecycle: .*/, 'lifecycle: archived'));
|
|
34
|
+
step('W050 silent in a read-only version', !diags().some((d) => d.code === 'W050' && d.path.startsWith('V1.0/')));
|
|
35
|
+
let n = JSON.parse(mds('next', R, '--json').out);
|
|
36
|
+
step('next sends an old KB to migrate', n.mode === 'migrate' && /intent-format migrate/.test(n.do[0]));
|
|
37
|
+
|
|
38
|
+
/* ---------- migrate ---------- */
|
|
39
|
+
let r = mds('migrate', R);
|
|
40
|
+
step('migrate runs', r.code === 0, r.out + r.err);
|
|
41
|
+
const cores = (ws) => fs.readdirSync(path.join(R, ws, 'roles')).filter((f) => f !== '_index.md').sort();
|
|
42
|
+
step('archived version untouched', (!fs.existsSync(path.join(R, 'V1.0', 'roles')) || !cores('V1.0').length) && /### Roles/.test(get('V1.0/project.md')));
|
|
43
|
+
step('one core per role across versions', JSON.stringify(cores('V1.1')) === JSON.stringify(cores('V1.2')) && cores('V1.1').length === 3, cores('V1.1').join(','));
|
|
44
|
+
step('table removed, module enabled', !/### Roles/.test(get('V1.1/project.md')) && /modules: \[roles,/.test(get('V1.1/intent-format.md')));
|
|
45
|
+
const member = get('V1.2/roles/' + cores('V1.2').find((f) => f.includes('member')));
|
|
46
|
+
step('States column → state:, description kept', /^state: Signed in$/m.test(member) && /Buys things/.test(member));
|
|
47
|
+
step('⚙ Stories filled', /## ⚙ Stories\n- \[#PR000001 Kb\]\(\.\.\/project\.md\) · story: User stories/.test(member), member);
|
|
48
|
+
step('V1.2 role unchanged against V1.1', /· unchanged/.test(member));
|
|
49
|
+
r = mds('migrate', R);
|
|
50
|
+
step('migrate is idempotent', /0 role card\(s\) created · 0 reused/.test(r.out) && /regen: 0 file/.test(r.out), r.out);
|
|
51
|
+
const c = diags();
|
|
52
|
+
step('I029 for a role no story names (Staff)', c.filter((d) => d.code === 'I029').length === 2 && c.every((d) => d.code !== 'W049' && d.severity !== 'warning'), JSON.stringify(c.filter((d) => d.severity !== 'info')));
|
|
53
|
+
|
|
54
|
+
/* ---------- names resolve against cards now ---------- */
|
|
55
|
+
put('V1.2/project.md', get('V1.2/project.md').replace('- As a Member, I want to buy', '- As a Buyer, I want to buy'));
|
|
56
|
+
step('W037 when a story names no role card', has('W037'));
|
|
57
|
+
put('V1.2/project.md', get('V1.2/project.md').replace('- As a Buyer, I want to buy', '- As a Member, I want to buy'));
|
|
58
|
+
const dup = cores('V1.2').find((f) => f.includes('guest'));
|
|
59
|
+
put('V1.2/roles/ro000099-guest.md', get('V1.2/roles/' + dup).replace(/^id: RO\d+$/m, 'id: RO000099').replace(/· #RO\d+/, '· #RO000099'));
|
|
60
|
+
step('W049 for two roles with one name', has('W049'));
|
|
61
|
+
fs.rmSync(path.join(R, 'V1.2/roles/ro000099-guest.md'));
|
|
62
|
+
|
|
63
|
+
/* ---------- a role takes Links, Comments and decisions like any card ---------- */
|
|
64
|
+
const mfile = 'V1.2/roles/' + cores('V1.2').find((f) => f.includes('member'));
|
|
65
|
+
put(mfile, get(mfile).replace(/\n## ⚙ Stories/, '\n## Links\n- [Interview notes](https://example.com/notes) · type: Source\n\n## ⚙ Stories'));
|
|
66
|
+
const dc = mds('new', 'decision', 'Do members need a separate app?', '--root', R, '--ws', 'V1.2').out.trim().split(' ');
|
|
67
|
+
const mcore = /^id: (RO\d+)$/m.exec(get(mfile))[1];
|
|
68
|
+
put(dc[1], get(dc[1]).replace(/## Affects\n—/, `## Affects\n- #${mcore}`));
|
|
69
|
+
mds('regen', R);
|
|
70
|
+
const bad = diags().filter((d) => ['W017', 'W018'].includes(d.code));
|
|
71
|
+
step('Links on a role and decisions affecting it are legal', !bad.length, JSON.stringify(bad));
|
|
72
|
+
step('⚙ Decisions on the role', /## ⚙ Decisions\n- \[#DC/.test(get(mfile)), get(mfile));
|
|
73
|
+
|
|
74
|
+
/* ---------- scaffold puts roles first ---------- */
|
|
75
|
+
const inv = path.join(tmp, 'inv.md');
|
|
76
|
+
fs.writeFileSync(inv, '| # | Type | Name | Parent / home | Core |\n|---|---|---|---|---|\n| 1 | feature | Shop | | |\n| 2 | role | Courier | | |\n');
|
|
77
|
+
r = mds('scaffold', R, '--inventory', inv, '--ws', 'V1.2');
|
|
78
|
+
const lines = r.out.split('\n').filter((l) => /^(RO|FT)\d/.test(l));
|
|
79
|
+
step('scaffold creates roles before features', lines[0]?.startsWith('RO') && lines[1]?.startsWith('FT'), r.out);
|
|
80
|
+
|
|
81
|
+
console.log('mds roles test');
|
|
82
|
+
for (const l of results) console.log(' ' + l);
|
|
83
|
+
console.log(failed ? `FAILED (${failed})` : 'PASSED');
|
|
84
|
+
if (process.argv.includes('--keep')) console.log(`kept ${tmp}`); else fs.rmSync(tmp, { recursive: true, force: true });
|
|
85
|
+
process.exitCode = failed ? 1 : 0;
|