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,342 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// intent-format — command-line tool for Intent Format knowledge bases. Node >= 18, no dependencies.
|
|
3
|
+
// Reads ../../schema.json (relative to this file); the schema drives the behaviour.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { loadSchema } from './lib/schema.mjs';
|
|
8
|
+
import { exists, listDir, slugify, readText, copyDir, toPosix, withLock } from './lib/util.mjs';
|
|
9
|
+
import { parseFrontMatter, fmValue } from './lib/parse.mjs';
|
|
10
|
+
import { loadProject } from './lib/project.mjs';
|
|
11
|
+
import { checkProject } from './lib/check.mjs';
|
|
12
|
+
import { plan, apply } from './lib/regen.mjs';
|
|
13
|
+
import { renderCard } from './lib/templates.mjs';
|
|
14
|
+
import { buildKit } from './lib/kit.mjs';
|
|
15
|
+
import { Usage, Refused, mintCores, createCard, scaffold } from './lib/create.mjs';
|
|
16
|
+
import { STANDARD_DIR } from './lib/schema.mjs';
|
|
17
|
+
import { nextStep, renderNext } from './lib/next.mjs';
|
|
18
|
+
import { frameOf, renderFrame } from './lib/frame.mjs';
|
|
19
|
+
import { ensureAgentFiles } from './lib/agents.mjs';
|
|
20
|
+
import { migrate } from './lib/migrate.mjs';
|
|
21
|
+
import { openList, renderOpen } from './lib/open.mjs';
|
|
22
|
+
|
|
23
|
+
const HELP = `intent-format — Intent Format knowledge-base tool
|
|
24
|
+
|
|
25
|
+
Usage: node <standard>/kit/cli/intent-format.mjs <command> [arguments]
|
|
26
|
+
|
|
27
|
+
Commands
|
|
28
|
+
init <root> --name "<Name>" [--kb <slug>] [--version 1.0] [--lifecycle in-progress] [--modules a,b]
|
|
29
|
+
Create a project root (_index.md, _ids.md, inputs/links.md), the workspace
|
|
30
|
+
V<version>/ with intent-format.md, project.md and module folders; then regen.
|
|
31
|
+
<root> may already exist (e.g. with inputs/); refuses if it holds a manifest.
|
|
32
|
+
new <type> "<Name>" --root <root> [--ws V1.0] [--feature FT…] [--state <State>] [--parent FT…]
|
|
33
|
+
Mint a core and write the card from its template. Prints "<core> <path>".
|
|
34
|
+
scaffold <root> --inventory <file> [--ws V1.0]
|
|
35
|
+
Create a card for every inventory row without a Core (columns: Type, Name,
|
|
36
|
+
Parent / home, …, Core) and write each new core into the row. Idempotent.
|
|
37
|
+
mint <PREFIX> --root <root> [--count n]
|
|
38
|
+
Mint cores (FS, SV, CV, HV for sub-documents). Prints one core per line and
|
|
39
|
+
raises the High-water mark in _ids.md.
|
|
40
|
+
check <root> [--ws V1.0] [--json]
|
|
41
|
+
Diagnostics "<severity> <code> <path>:<line> <message>", then counts and health
|
|
42
|
+
numbers (blind spots by kind · unresolved placeholders · open decisions).
|
|
43
|
+
Exit 1 on errors.
|
|
44
|
+
regen <root>
|
|
45
|
+
Regenerate _index.md, _ids.md, folder rosters, ⚙ sections, status lines and
|
|
46
|
+
CHANGES.md; refresh reference names/paths. Refuses on errors. Idempotent.
|
|
47
|
+
Adds AGENTS.md and CLAUDE.md at the root when missing (never overwrites them).
|
|
48
|
+
migrate <root>
|
|
49
|
+
Bring a KB up to date with the current version: turns the deprecated ### Roles table
|
|
50
|
+
into role cards (one core per role across versions); then regen. Idempotent.
|
|
51
|
+
next [<root>] [--ws V1.0] [--json]
|
|
52
|
+
Read the project folder and print the one next step: during a cold start
|
|
53
|
+
(set up · kickoff · proposal · review · scaffold · fill · check · report) and after.
|
|
54
|
+
open <root> [--ws V1.0] [--json]
|
|
55
|
+
The open list: [ask: …] questions, open decisions, [assumed] and [likely] marks, whys
|
|
56
|
+
missing, other blind spots per card. What to ask the owner next.
|
|
57
|
+
frame <root> <screen core or name> [--ws V1.0] [--json]
|
|
58
|
+
What surrounds a screen at each placement: the resolved shell and its stacked
|
|
59
|
+
variants, parts, navigation and the Places inside contract.
|
|
60
|
+
branch <root> <from> <to>
|
|
61
|
+
Copy workspace V<from> to V<to> (version, lifecycle: in-progress, based-on); regen.
|
|
62
|
+
|
|
63
|
+
Maintainer only
|
|
64
|
+
build-kit
|
|
65
|
+
Regenerates the kit inside the standard (templates/, kit/skills/intent-format/types/,
|
|
66
|
+
kit/skills/intent-format/links.md) from schema.json. Never run it in a KB project.
|
|
67
|
+
|
|
68
|
+
Exit codes: 0 ok · 1 errors in the KB, problems, or command refused · 2 usage error`;
|
|
69
|
+
|
|
70
|
+
const BOOL = new Set(['json', 'help', 'h']);
|
|
71
|
+
|
|
72
|
+
function parseArgs(argv) {
|
|
73
|
+
const pos = [], flags = {};
|
|
74
|
+
for (let i = 0; i < argv.length; i++) {
|
|
75
|
+
const a = argv[i];
|
|
76
|
+
if (a.startsWith('-') && a !== '-') {
|
|
77
|
+
const k = a.replace(/^-+/, '');
|
|
78
|
+
const eq = k.indexOf('=');
|
|
79
|
+
if (eq >= 0) flags[k.slice(0, eq)] = k.slice(eq + 1);
|
|
80
|
+
else if (BOOL.has(k)) flags[k] = true;
|
|
81
|
+
else {
|
|
82
|
+
if (i + 1 >= argv.length) throw new Usage(`--${k} needs a value`);
|
|
83
|
+
flags[k] = argv[++i];
|
|
84
|
+
}
|
|
85
|
+
} else pos.push(a);
|
|
86
|
+
}
|
|
87
|
+
return { pos, flags };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const vNorm = (v) => String(v || '').replace(/^V/, '');
|
|
91
|
+
|
|
92
|
+
function pickWorkspace(P, wsFlag) {
|
|
93
|
+
if (wsFlag) {
|
|
94
|
+
const ws = P.byVersion.get(vNorm(wsFlag));
|
|
95
|
+
if (!ws) throw new Refused(`no workspace V${vNorm(wsFlag)} in ${P.root}`);
|
|
96
|
+
return ws;
|
|
97
|
+
}
|
|
98
|
+
if (P.workspaces.length === 1) return P.workspaces[0];
|
|
99
|
+
const open = P.workspaces.filter((w) => w.lifecycle === 'in-progress');
|
|
100
|
+
if (open.length === 1) return open[0];
|
|
101
|
+
throw new Refused(`several workspaces (${P.workspaces.map((w) => w.folder).join(', ')}) — name one with --ws`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function requireProject(S, root) {
|
|
105
|
+
const P = loadProject(S, root);
|
|
106
|
+
if (!P.workspaces.length) throw new Refused(`no workspace (V<x.y>/) in ${path.resolve(root)} — run intent-format init`);
|
|
107
|
+
return P;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function regenProject(S, root, log = console.log) {
|
|
111
|
+
const P = loadProject(S, root);
|
|
112
|
+
const r = checkProject(S, P, { skipGenerated: true });
|
|
113
|
+
const errors = r.diagnostics.filter((d) => d.severity === 'error');
|
|
114
|
+
if (errors.length) {
|
|
115
|
+
for (const d of errors) log(`${d.severity} ${d.code} ${d.path}:${d.line} ${d.message}`);
|
|
116
|
+
throw new Refused(`regen refused: ${errors.length} error(s) — fix them and run again`);
|
|
117
|
+
}
|
|
118
|
+
const changed = apply(P, plan(S, P));
|
|
119
|
+
const ws = P.workspaces[P.workspaces.length - 1];
|
|
120
|
+
changed.push(...ensureAgentFiles(P.root, ws?.name || path.basename(P.root)));
|
|
121
|
+
log(`regen: ${changed.length} file(s) changed`);
|
|
122
|
+
for (const c of changed) log(` ${c}`);
|
|
123
|
+
return changed;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* ---------------- commands ---------------- */
|
|
127
|
+
|
|
128
|
+
function cmdInit(S, pos, f) {
|
|
129
|
+
const root = pos[0];
|
|
130
|
+
if (!root || !f.name) throw new Usage('init <root> --name "<Name>" [--kb <slug>] [--version 1.0] [--lifecycle in-progress] [--modules a,b]');
|
|
131
|
+
const name = String(f.name).trim();
|
|
132
|
+
if (!name || /[[\]]/.test(name)) throw new Usage('--name must be non-empty and contain no [ or ]');
|
|
133
|
+
const kb = f.kb || slugify(name, 'kb');
|
|
134
|
+
if (!S.R.kbSlug.test(kb)) throw new Usage(`--kb "${kb}" is not a slug (a-z, 0-9, -)`);
|
|
135
|
+
const version = vNorm(f.version || '1.0');
|
|
136
|
+
if (!S.R.version.test(version)) throw new Usage(`--version "${version}" must look like 1.0 or 1.1-label`);
|
|
137
|
+
const lifecycle = f.lifecycle || 'in-progress';
|
|
138
|
+
if (!S.lifecycles.includes(lifecycle)) throw new Usage(`--lifecycle must be one of ${S.lifecycles.join(', ')}`);
|
|
139
|
+
const modules = f.modules ? String(f.modules).split(',').map((x) => x.trim()).filter(Boolean) : [...S.modules];
|
|
140
|
+
for (const m of modules) if (!S.modules.includes(m)) throw new Usage(`unknown module "${m}" (${S.modules.join(', ')})`);
|
|
141
|
+
const abs = path.resolve(root);
|
|
142
|
+
if (exists(path.join(abs, 'intent-format.md'))) throw new Refused(`${abs} already holds a workspace manifest (intent-format.md)`);
|
|
143
|
+
for (const e of listDir(abs)) {
|
|
144
|
+
if (e.isDirectory() && exists(path.join(abs, e.name, 'intent-format.md'))) throw new Refused(`${abs} already holds a workspace manifest (${e.name}/intent-format.md)`);
|
|
145
|
+
}
|
|
146
|
+
fs.mkdirSync(path.join(abs, 'inputs'), { recursive: true });
|
|
147
|
+
const links = path.join(abs, 'inputs', 'links.md');
|
|
148
|
+
if (!exists(links)) fs.writeFileSync(links, `# Links\n\nURLs used as sources for this knowledge base, one per line: - [<title>](<url>) — <what it is>\n`);
|
|
149
|
+
const wsDir = path.join(abs, 'V' + version);
|
|
150
|
+
fs.mkdirSync(wsDir, { recursive: true });
|
|
151
|
+
const ordered = S.modules.filter((m) => modules.includes(m));
|
|
152
|
+
const manifest = ['---', `standard: ${S.standard}`, 'type: manifest', `kb: ${kb}`, `name: ${fmValue(S, 'name', name)}`,
|
|
153
|
+
`version: ${fmValue(S, 'version', version)}`, `lifecycle: ${lifecycle}`, `modules: [${ordered.join(', ')}]`, '---',
|
|
154
|
+
`# ${name}`, '', `Knowledge base of ${name}. Maintainer: —.`, ''].join('\n');
|
|
155
|
+
fs.writeFileSync(path.join(wsDir, 'intent-format.md'), manifest);
|
|
156
|
+
for (const m of ordered) fs.mkdirSync(path.join(wsDir, m), { recursive: true });
|
|
157
|
+
const pfile = path.join(wsDir, 'project.md');
|
|
158
|
+
if (exists(pfile)) console.log(`kept existing ${toPosix(path.relative(abs, pfile))}`);
|
|
159
|
+
else {
|
|
160
|
+
const P = loadProject(S, abs);
|
|
161
|
+
const [core] = mintCores(S, P, S.prefixOfType.project, 1);
|
|
162
|
+
fs.writeFileSync(pfile, renderCard(S, 'project', { id: core, name }));
|
|
163
|
+
}
|
|
164
|
+
console.log(`initialised ${abs} (V${version} ${lifecycle}, kb ${kb}, ${ordered.length} modules)`);
|
|
165
|
+
regenProject(S, abs);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function cmdNew(S, pos, f) {
|
|
169
|
+
const [type, name] = pos;
|
|
170
|
+
if (!type || !name) throw new Usage('new <type> "<Name>" --root <root> [--ws V1.0] [--feature FT…] [--state <s>] [--parent FT…]');
|
|
171
|
+
if (!S.isCardType(type)) throw new Usage(`unknown type "${type}" (${S.roster.join(', ')})`);
|
|
172
|
+
const P = requireProject(S, f.root || '.');
|
|
173
|
+
const ws = pickWorkspace(P, f.ws);
|
|
174
|
+
const { core, rel } = createCard(S, P, ws, type, name, { state: f.state, feature: f.feature, parent: f.parent });
|
|
175
|
+
console.log(`${core} ${rel}`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function cmdScaffold(S, pos, f) {
|
|
179
|
+
const root = pos[0] || f.root;
|
|
180
|
+
if (!root || !f.inventory) throw new Usage('scaffold <root> --inventory <file> [--ws V1.0]');
|
|
181
|
+
if (!exists(f.inventory)) throw new Refused(`inventory ${f.inventory} not found`);
|
|
182
|
+
const P = requireProject(S, root);
|
|
183
|
+
const ws = pickWorkspace(P, f.ws);
|
|
184
|
+
const stats = scaffold(S, P, ws, path.resolve(f.inventory), console.log);
|
|
185
|
+
return stats.problems ? 1 : 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function cmdMint(S, pos, f) {
|
|
189
|
+
const prefix = pos[0];
|
|
190
|
+
if (!prefix) throw new Usage('mint <PREFIX> --root <root> [--count n]');
|
|
191
|
+
const known = !!S.kindOfPrefix[prefix] || S.R.extPrefix.some((r) => r.test(prefix));
|
|
192
|
+
if (!/^[A-Z]{2}$/.test(prefix) || !known) throw new Usage(`unknown prefix "${prefix}" (${Object.keys(S.kindOfPrefix).join(', ')}, or X*/Z*)`);
|
|
193
|
+
const count = f.count === undefined ? 1 : Number(f.count);
|
|
194
|
+
if (!Number.isInteger(count) || count < 1 || count > 1000) throw new Usage('--count must be 1..1000');
|
|
195
|
+
const P = requireProject(S, f.root || '.');
|
|
196
|
+
for (const c of mintCores(S, P, prefix, count)) console.log(c);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const KIND_LABEL = { status: 'status', frontMatter: 'front matter', sections: 'required sections', lists: 'list items', requirements: 'requirement slots', targets: 'relation targets', why: 'why' };
|
|
200
|
+
|
|
201
|
+
function cmdCheck(S, pos, f) {
|
|
202
|
+
let root = path.resolve(pos[0] || f.root || '.');
|
|
203
|
+
let ws = f.ws ? 'V' + vNorm(f.ws) : null;
|
|
204
|
+
if (exists(path.join(root, 'intent-format.md'))) { ws = ws || path.basename(root); root = path.dirname(root); }
|
|
205
|
+
const P = requireProject(S, root);
|
|
206
|
+
if (ws && !P.workspaces.some((w) => w.folder === ws)) throw new Refused(`no workspace ${ws} in ${root}`);
|
|
207
|
+
const r = checkProject(S, P, { ws });
|
|
208
|
+
if (f.json) console.log(JSON.stringify(r, null, 2));
|
|
209
|
+
else {
|
|
210
|
+
for (const d of r.diagnostics) console.log(`${d.severity} ${d.code} ${d.path}:${d.line} ${d.message}`);
|
|
211
|
+
console.log(`Summary: ${r.counts.error} errors · ${r.counts.warning} warnings · ${r.counts.info} infos`);
|
|
212
|
+
for (const h of r.health) {
|
|
213
|
+
const by = Object.entries(h.blindSpotsByKind).map(([k, v]) => `${KIND_LABEL[k] || k} ${v}`).join(' · ');
|
|
214
|
+
console.log(`${h.workspace} (${h.lifecycle || '—'}): ${h.cards} cards · blind spots ${h.blindSpots} (${by}) · unresolved placeholders ${h.unresolvedPlaceholders} · open decisions ${h.openDecisions}`);
|
|
215
|
+
console.log(` why: filled ${h.why.filled} · inherited ${h.why.inherited} · none ${h.why.none} · debt ${h.why.missing} · confidence: assumed ${h.confidence.assumed} · likely ${h.confidence.likely} · asks ${h.asks.open}${h.asks.later ? ` (+${h.asks.later} later${h.asks.due ? `, ${h.asks.due} due` : ''})` : ''}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return r.counts.error ? 1 : 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function cmdRegen(S, pos, f) {
|
|
222
|
+
const root = pos[0] || f.root;
|
|
223
|
+
if (!root) throw new Usage('regen <root>');
|
|
224
|
+
requireProject(S, root);
|
|
225
|
+
regenProject(S, root);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function setManifest(S, file, updates) {
|
|
229
|
+
const lines = readText(file).replace(/\n$/, '').split('\n');
|
|
230
|
+
const fm = parseFrontMatter(lines, S.R);
|
|
231
|
+
if (!fm || fm.errors.length) throw new Refused(`${file}: unparsable front matter`);
|
|
232
|
+
const order = S.raw.manifest.keys.map((k) => k.key);
|
|
233
|
+
const out = ['---'];
|
|
234
|
+
for (const k of order) {
|
|
235
|
+
if (k in updates) { if (updates[k] != null) out.push(`${k}: ${fmValue(S, k, updates[k])}`); continue; }
|
|
236
|
+
const e = fm.map.get(k);
|
|
237
|
+
if (e) out.push(lines[e.idx]);
|
|
238
|
+
}
|
|
239
|
+
for (const e of fm.entries) if (!order.includes(e.key)) out.push(lines[e.idx]);
|
|
240
|
+
out.push(...lines.slice(fm.end));
|
|
241
|
+
fs.writeFileSync(file, out.join('\n') + '\n');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function cmdBranch(S, pos) {
|
|
245
|
+
const [root, from, to] = pos;
|
|
246
|
+
if (!root || !from || !to) throw new Usage('branch <root> <from> <to> e.g. branch kb V1.0 V1.1');
|
|
247
|
+
const P = requireProject(S, root);
|
|
248
|
+
const src = P.byVersion.get(vNorm(from));
|
|
249
|
+
if (!src) throw new Refused(`no workspace V${vNorm(from)} in ${P.root}`);
|
|
250
|
+
const v = vNorm(to);
|
|
251
|
+
if (!S.R.version.test(v)) throw new Usage(`"${to}" must look like V1.1 or V1.1-label`);
|
|
252
|
+
const dst = path.join(P.root, 'V' + v);
|
|
253
|
+
if (exists(dst)) throw new Refused(`${dst} already exists`);
|
|
254
|
+
if (!exists(path.join(src.dir, 'intent-format.md'))) throw new Refused(`V${src.version} has no intent-format.md`);
|
|
255
|
+
copyDir(src.dir, dst);
|
|
256
|
+
fs.rmSync(path.join(dst, 'CHANGES.md'), { force: true });
|
|
257
|
+
setManifest(S, path.join(dst, 'intent-format.md'), { version: v, lifecycle: 'in-progress', 'based-on': src.version });
|
|
258
|
+
console.log(`V${v} created from V${src.version}`);
|
|
259
|
+
regenProject(S, P.root);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const MDS = `node "${toPosix(path.join(STANDARD_DIR, 'kit', 'cli', 'intent-format.mjs'))}"`;
|
|
263
|
+
|
|
264
|
+
function cmdMigrate(S, pos, f) {
|
|
265
|
+
const root = pos[0] || f.root;
|
|
266
|
+
if (!root) throw new Usage('migrate <root>');
|
|
267
|
+
const P = requireProject(S, root);
|
|
268
|
+
const st = migrate(S, P, console.log);
|
|
269
|
+
console.log(`migrate: ${st.renamed} file(s) renamed to ${S.standard} · ${st.created} role card(s) created · ${st.reused} reused across versions · ${st.kept} already there · ${st.workspaces} workspace(s) · ${st.problems} problem(s)`);
|
|
270
|
+
regenProject(S, root);
|
|
271
|
+
return st.problems ? 1 : 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function cmdNext(S, pos, f) {
|
|
275
|
+
const root = path.resolve(pos[0] || f.root || '.');
|
|
276
|
+
const P = exists(root) ? loadProject(S, root) : null;
|
|
277
|
+
const n = nextStep(S, P, root, f.ws ? 'V' + vNorm(f.ws) : null);
|
|
278
|
+
if (f.json) console.log(JSON.stringify(n, null, 2));
|
|
279
|
+
else console.log(renderNext(n, MDS));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function cmdFrame(S, pos, f) {
|
|
283
|
+
const [root, what] = pos;
|
|
284
|
+
if (!root || !what) throw new Usage('frame <root> <screen core or name> [--ws V1.0] [--json]');
|
|
285
|
+
const P = requireProject(S, root);
|
|
286
|
+
const ws = pickWorkspace(P, f.ws);
|
|
287
|
+
const key = what.replace(/^#/, '');
|
|
288
|
+
const screens = ws.cards.filter((c) => c.type === 'screen');
|
|
289
|
+
const hit = screens.find((c) => c.id === key) || screens.filter((c) => c.name.toLowerCase() === what.toLowerCase());
|
|
290
|
+
const screen = Array.isArray(hit) ? (hit.length === 1 ? hit[0] : null) : hit;
|
|
291
|
+
if (!screen) throw new Refused(Array.isArray(hit) && hit.length > 1 ? `several screens are named "${what}" — use the core` : `no screen ${what} in ${ws.folder}`);
|
|
292
|
+
const rows = frameOf(S, ws, screen);
|
|
293
|
+
if (f.json) console.log(JSON.stringify(rows.map((r) => ({ ...r, shell: r.shell ? { id: r.shell.id, name: r.shell.name } : null, variants: r.variants.map((v) => ({ core: v.core, name: v.name })) })), null, 2));
|
|
294
|
+
else console.log(renderFrame(screen, rows));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function cmdOpen(S, pos, f) {
|
|
298
|
+
let root = path.resolve(pos[0] || f.root || '.');
|
|
299
|
+
let ws = f.ws ? 'V' + vNorm(f.ws) : null;
|
|
300
|
+
if (exists(path.join(root, 'intent-format.md'))) { ws = ws || path.basename(root); root = path.dirname(root); }
|
|
301
|
+
const P = requireProject(S, root);
|
|
302
|
+
const w = ws ? P.workspaces.find((x) => x.folder === ws) : pickWorkspace(P, null);
|
|
303
|
+
if (!w) throw new Refused(`no workspace ${ws} in ${root}`);
|
|
304
|
+
checkProject(S, P, { ws: w.folder, skipGenerated: true });
|
|
305
|
+
const o = openList(S, w);
|
|
306
|
+
console.log(f.json ? JSON.stringify(o, null, 2) : renderOpen(o));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function cmdBuildKit(S) {
|
|
310
|
+
const written = buildKit(S);
|
|
311
|
+
console.log(`build-kit: ${written.length} file(s) changed`);
|
|
312
|
+
for (const w of written) console.log(` ${w}`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/* ---------------- main ---------------- */
|
|
316
|
+
|
|
317
|
+
export function main(argv) {
|
|
318
|
+
const S = loadSchema();
|
|
319
|
+
let args;
|
|
320
|
+
try { args = parseArgs(argv); } catch (e) { console.error(e.message); return 2; }
|
|
321
|
+
const [cmd, ...pos] = args.pos;
|
|
322
|
+
if (!cmd || args.flags.help || args.flags.h || cmd === 'help') { console.log(HELP); return cmd || args.flags.help || args.flags.h ? 0 : 2; }
|
|
323
|
+
const table = { init: cmdInit, new: cmdNew, scaffold: cmdScaffold, mint: cmdMint, check: cmdCheck, regen: cmdRegen, branch: cmdBranch, next: cmdNext, frame: cmdFrame, migrate: cmdMigrate, open: cmdOpen, 'build-kit': cmdBuildKit };
|
|
324
|
+
if (!table[cmd]) { console.error(`unknown command "${cmd}"\n\n${HELP}`); return 2; }
|
|
325
|
+
// writing commands hold the project lock: parallel agents on one project take turns
|
|
326
|
+
const writes = { init: pos[0], new: args.flags.root || '.', scaffold: pos[0] || args.flags.root, mint: args.flags.root || '.', regen: pos[0] || args.flags.root, branch: pos[0], migrate: pos[0] || args.flags.root };
|
|
327
|
+
try {
|
|
328
|
+
const run = () => table[cmd](S, pos, args.flags) || 0;
|
|
329
|
+
return writes[cmd] ? withLock(path.resolve(writes[cmd]), run) : run();
|
|
330
|
+
} catch (e) {
|
|
331
|
+
if (e.locked) { console.error(e.message); return 1; }
|
|
332
|
+
if (e instanceof Usage) { console.error(`usage: intent-format ${e.message}`); return 2; }
|
|
333
|
+
if (e instanceof Refused) { console.error(e.message); return 1; }
|
|
334
|
+
throw e;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Run when started as a program — directly, or through a link such as npm's `intent-format` bin — not when imported.
|
|
339
|
+
const realOf = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
|
|
340
|
+
if (process.argv[1] && realOf(process.argv[1]) === realOf(fileURLToPath(import.meta.url))) {
|
|
341
|
+
process.exitCode = main(process.argv.slice(2));
|
|
342
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// AGENTS.md and CLAUDE.md at a project root: how a fresh agent finds the standard and its next
|
|
2
|
+
// step. Written when missing, never overwritten — they belong to the project once created.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { STANDARD_DIR } from './schema.mjs';
|
|
6
|
+
import { exists, toPosix } from './util.mjs';
|
|
7
|
+
|
|
8
|
+
export function agentsText(root, name) {
|
|
9
|
+
const std = toPosix(path.relative(root, STANDARD_DIR)) || '.';
|
|
10
|
+
return `# ${name} — knowledge base
|
|
11
|
+
|
|
12
|
+
This folder is a knowledge base in **Intent Format 1.0**: one markdown card per screen,
|
|
13
|
+
shell, flow, map, rule, API, feature and decision. The standard lives at \`${std}\` (relative to
|
|
14
|
+
this folder).
|
|
15
|
+
|
|
16
|
+
**Start every session here:**
|
|
17
|
+
|
|
18
|
+
node "${std}/kit/cli/intent-format.mjs" next .
|
|
19
|
+
|
|
20
|
+
It reads this folder and prints the one next step — during the cold start and after it.
|
|
21
|
+
|
|
22
|
+
Always:
|
|
23
|
+
- read \`${std}/kit/skills/intent-format/SKILL.md\` before you write cards; then only the sheet for the type you write;
|
|
24
|
+
- before writing or changing a screen: \`intent-format frame . <screen>\` — the shell owns navigation and controls;
|
|
25
|
+
- never mint IDs by hand, never edit \`⚙\` sections; after every batch: \`intent-format regen .\`, then \`intent-format check .\`.
|
|
26
|
+
|
|
27
|
+
If \`${std}\` does not exist on this machine, find the Intent Format folder (it holds \`schema.json\`
|
|
28
|
+
and \`kit/cli/intent-format.mjs\`) and correct the path in this file.
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Create AGENTS.md (and a CLAUDE.md that imports it) when missing. Returns the files written. */
|
|
33
|
+
export function ensureAgentFiles(root, name) {
|
|
34
|
+
const out = [];
|
|
35
|
+
const a = path.join(root, 'AGENTS.md'), c = path.join(root, 'CLAUDE.md');
|
|
36
|
+
if (!exists(a)) { fs.writeFileSync(a, agentsText(root, name)); out.push('AGENTS.md'); }
|
|
37
|
+
if (!exists(c)) { fs.writeFileSync(c, '@AGENTS.md\n'); out.push('CLAUDE.md'); }
|
|
38
|
+
return out;
|
|
39
|
+
}
|