@akjamie/agentic-sdlc 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +219 -2
- package/assets/ci/asdlc-ai-review.yml +65 -0
- package/assets/config/config.yaml +76 -0
- package/assets/githooks/post-merge +22 -0
- package/assets/githooks/pre-push +17 -0
- package/assets/policy/policy.yaml +46 -0
- package/assets/schema/schema.yaml +168 -0
- package/assets/schema/templates/design.md +134 -0
- package/assets/schema/templates/proposal.md +25 -0
- package/assets/schema/templates/review.md +24 -0
- package/assets/schema/templates/spec.md +37 -0
- package/assets/schema/templates/tasks.md +10 -0
- package/assets/skills/asdlc-apply/SKILL.md +128 -0
- package/assets/skills/asdlc-approve/SKILL.md +107 -0
- package/assets/skills/asdlc-archive/SKILL.md +49 -0
- package/assets/skills/asdlc-doctor/SKILL.md +82 -0
- package/assets/skills/asdlc-impl-review/SKILL.md +219 -0
- package/assets/skills/asdlc-init/SKILL.md +68 -0
- package/assets/skills/asdlc-lint/SKILL.md +59 -0
- package/assets/skills/asdlc-new/SKILL.md +107 -0
- package/assets/skills/asdlc-pr/SKILL.md +59 -0
- package/assets/skills/asdlc-review/SKILL.md +80 -0
- package/assets/skills/asdlc-spec-review/SKILL.md +206 -0
- package/assets/skills/asdlc-status/SKILL.md +49 -0
- package/assets/skills/asdlc-upgrade/SKILL.md +34 -0
- package/assets/skills/asdlc-verify/SKILL.md +55 -0
- package/assets/skills/batch-grill-me/SKILL.md +136 -0
- package/assets/skills/grilling/SKILL.md +136 -0
- package/bin/asdlc.js +6 -0
- package/package.json +43 -4
- package/src/cli.js +89 -0
- package/src/commands/apply.js +114 -0
- package/src/commands/approve.js +166 -0
- package/src/commands/archive.js +143 -0
- package/src/commands/doctor.js +163 -0
- package/src/commands/init.js +201 -0
- package/src/commands/lint.js +127 -0
- package/src/commands/new.js +171 -0
- package/src/commands/pr.js +495 -0
- package/src/commands/skills.js +184 -0
- package/src/commands/status.js +65 -0
- package/src/commands/test.js +137 -0
- package/src/commands/update.js +103 -0
- package/src/commands/upgrade.js +175 -0
- package/src/commands/verify.js +229 -0
- package/src/index.js +3 -0
- package/src/lib/agents.js +73 -0
- package/src/lib/cliutil.js +99 -0
- package/src/lib/errors.js +18 -0
- package/src/lib/exec.js +23 -0
- package/src/lib/fs.js +83 -0
- package/src/lib/git.js +76 -0
- package/src/lib/graphify.js +106 -0
- package/src/lib/log.js +15 -0
- package/src/lib/openspec.js +91 -0
- package/src/lib/paths.js +43 -0
- package/src/lib/policy.js +60 -0
- package/src/lib/prtype.js +41 -0
- package/src/lib/schema.js +86 -0
- package/src/lib/speclint.js +173 -0
- package/src/lib/tdd.js +71 -0
- package/src/lib/yaml.js +18 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, ensureDir, copyTree, readText, writeText, listDir } from '../lib/fs.js';
|
|
3
|
+
import { openspecDir, configAssetFile, ciAssetDir, githooksAssetDir, schemaAssetDir, policyAssetFile, skillsAssetDir, SCHEMA_NAME } from '../lib/paths.js';
|
|
4
|
+
import { installSchema, builtinSchemaVersion, localOverride } from '../lib/schema.js';
|
|
5
|
+
import { log } from '../lib/log.js';
|
|
6
|
+
import { runOpenspec, openspecVersion, ensureOpenspec } from '../lib/openspec.js';
|
|
7
|
+
import { git } from '../lib/git.js';
|
|
8
|
+
import { ensureGraphify, buildGraph, ensureGitignore } from '../lib/graphify.js';
|
|
9
|
+
import { refreshAgents } from '../lib/agents.js';
|
|
10
|
+
import { ensureRemoteLabels } from './pr.js';
|
|
11
|
+
|
|
12
|
+
// Directory -> OpenSpec tool id. We detect what the repo already uses so we can
|
|
13
|
+
// wire OpenSpec's own agent commands/skills (we do NOT invent our own).
|
|
14
|
+
const TOOL_DIRS = {
|
|
15
|
+
'.opencode': 'opencode',
|
|
16
|
+
'.claude': 'claude',
|
|
17
|
+
'.codex': 'codex',
|
|
18
|
+
'.pi': 'pi',
|
|
19
|
+
'.dsh': 'dsh',
|
|
20
|
+
'.cursor': 'cursor',
|
|
21
|
+
'.gemini': 'gemini',
|
|
22
|
+
'.qwen': 'qwen',
|
|
23
|
+
'.trae': 'trae',
|
|
24
|
+
'.zed': 'zed',
|
|
25
|
+
'.windsurf': 'windsurf',
|
|
26
|
+
'.devin': 'devin',
|
|
27
|
+
'.agents': 'agents',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function detectTools(repoRoot) {
|
|
31
|
+
return Object.entries(TOOL_DIRS)
|
|
32
|
+
.filter(([dir]) => exists(path.join(repoRoot, dir)))
|
|
33
|
+
.map(([, id]) => id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function initRepo(opts = {}) {
|
|
37
|
+
const repoRoot = path.resolve(opts.repoRoot ?? process.cwd());
|
|
38
|
+
const osDir = openspecDir(repoRoot);
|
|
39
|
+
|
|
40
|
+
// 1) Ensure the OpenSpec ENGINE is installed (pinned devDependency), then
|
|
41
|
+
// REUSE it for setup: init the project + wire agent tooling. Re-running
|
|
42
|
+
// is idempotent and never resets our governance config.
|
|
43
|
+
const osInstall = opts.openspec === false
|
|
44
|
+
? { installed: openspecVersion(repoRoot) != null, action: 'skipped' }
|
|
45
|
+
: ensureOpenspec(repoRoot);
|
|
46
|
+
if (!osInstall.installed) {
|
|
47
|
+
log.warn('openspec CLI unavailable and could not be installed (need npm)');
|
|
48
|
+
} else {
|
|
49
|
+
if (osInstall.action === 'npm-install') log.ok(`installed openspec@${'1.13.2'} (devDependency)`);
|
|
50
|
+
const tools = opts.tools ?? (detectTools(repoRoot).join(',') || 'none');
|
|
51
|
+
const res = runOpenspec(['init', '--tools', tools, '--no-animation'], repoRoot);
|
|
52
|
+
if (res.status === 0) log.ok(`openspec init --tools ${tools}`);
|
|
53
|
+
else log.warn(`openspec init returned ${res.status} (non-fatal)`);
|
|
54
|
+
}
|
|
55
|
+
ensureDir(path.join(osDir, 'changes'));
|
|
56
|
+
ensureDir(path.join(osDir, 'specs'));
|
|
57
|
+
|
|
58
|
+
// 1.5) BU-managed OpenSpec schema: install ONCE per machine (central), never
|
|
59
|
+
// copied into the repo. This IS the OpenSpec customization layer - the
|
|
60
|
+
// enterprise change flow (proposal -> specs -> review -> tasks).
|
|
61
|
+
const override = localOverride(repoRoot);
|
|
62
|
+
if (override.tracked) {
|
|
63
|
+
log.warn(`committed local schema copy found: ${override.path}`);
|
|
64
|
+
log.warn('the BU standard forbids per-repo schema overrides; remove it (the schema is installed centrally by `asdlc init`)');
|
|
65
|
+
}
|
|
66
|
+
const schemaDest = installSchema();
|
|
67
|
+
log.ok(`installed managed schema v${builtinSchemaVersion()} -> ${path.relative(repoRoot, schemaDest) || schemaDest}`);
|
|
68
|
+
if (opts.vendor) {
|
|
69
|
+
const vendored = path.join(osDir, 'schemas', SCHEMA_NAME);
|
|
70
|
+
copyTree(schemaAssetDir, vendored);
|
|
71
|
+
log.ok(`vendored schema -> openspec/schemas/${SCHEMA_NAME} (CI-only; do not commit)`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 2) Governance overlay: schema name + context + rules + lint + verify policy.
|
|
75
|
+
const configDest = path.join(osDir, 'config.yaml');
|
|
76
|
+
const MARKER = 'asdlc governance overlay';
|
|
77
|
+
const hasOurs = exists(configDest) && readText(configDest).includes(MARKER);
|
|
78
|
+
if (hasOurs && !opts.force) {
|
|
79
|
+
log.step('governance config already present (use --force to overlay)');
|
|
80
|
+
} else {
|
|
81
|
+
let content = readText(configAssetFile);
|
|
82
|
+
if (!/^schemaVersion:/m.test(content) && builtinSchemaVersion()) {
|
|
83
|
+
content = `${content.trimEnd()}\nschemaVersion: "${builtinSchemaVersion()}"\n`;
|
|
84
|
+
}
|
|
85
|
+
writeText(configDest, content);
|
|
86
|
+
log.ok('wrote governance config (openspec/config.yaml)');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 3) CI + git hooks (governance glue, not OpenSpec's job).
|
|
90
|
+
if (opts.ci === 'jenkins') {
|
|
91
|
+
const dest = path.join(repoRoot, 'Jenkinsfile');
|
|
92
|
+
if (exists(dest) && !opts.force) log.step('Jenkinsfile exists (use --force)');
|
|
93
|
+
else { writeText(dest, readText(path.join(ciAssetDir, 'Jenkinsfile'))); log.ok('wrote Jenkinsfile'); }
|
|
94
|
+
}
|
|
95
|
+
if (opts.hooks !== false) installHooks(repoRoot);
|
|
96
|
+
|
|
97
|
+
// 3.5) Platform policy (v6 §7.3): committed, CODEOWNERS-protected. Default only.
|
|
98
|
+
const policyDest = path.join(repoRoot, '.sdlc', 'policy.yaml');
|
|
99
|
+
if (exists(policyDest) && !opts.force) {
|
|
100
|
+
log.step('.sdlc/policy.yaml exists (use --force to reset)');
|
|
101
|
+
} else {
|
|
102
|
+
writeText(policyDest, readText(policyAssetFile));
|
|
103
|
+
log.ok('wrote .sdlc/policy.yaml (platform-owned; protect with CODEOWNERS)');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 3.6) Pre-provision remote governance labels if git remote & gh are available
|
|
107
|
+
try {
|
|
108
|
+
ensureRemoteLabels(repoRoot);
|
|
109
|
+
} catch { /* ignore */ }
|
|
110
|
+
|
|
111
|
+
// 4) graphify (BU standard): a code-derived navigation graph for spec drafting.
|
|
112
|
+
// Deterministic code-only AST (no LLM key), bound to HEAD, derived cache.
|
|
113
|
+
if (opts.graph !== false) {
|
|
114
|
+
const g = ensureGraphify();
|
|
115
|
+
if (!g.installed) {
|
|
116
|
+
log.warn('graphify not installed and could not be installed');
|
|
117
|
+
log.info(' install it (uv tool install graphifyy, or pip install graphifyy via your internal mirror)');
|
|
118
|
+
} else {
|
|
119
|
+
if (g.action !== 'present') log.ok(`installed graphify (${g.action})`);
|
|
120
|
+
const b = buildGraph(repoRoot);
|
|
121
|
+
if (b.status === 0) log.ok('built graphify code graph -> graphify-out/ (bound to HEAD)');
|
|
122
|
+
else log.warn('graphify build failed (non-fatal)');
|
|
123
|
+
if (ensureGitignore(repoRoot)) log.ok('added graphify-out/ to .gitignore');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 4.5) Bundled Agent Skills: install out-of-the-box skills (grilling, asdlc-apply)
|
|
128
|
+
// into the project's agent tools directory (.agents/skills, .claude/skills, etc.)
|
|
129
|
+
const explicitTools = opts.tools ? opts.tools.split(',').map((s) => s.trim().toLowerCase()) : [];
|
|
130
|
+
const allTools = [...new Set([...detectTools(repoRoot), ...explicitTools])];
|
|
131
|
+
installSkills(repoRoot, allTools);
|
|
132
|
+
|
|
133
|
+
// 5) AGENTS.md: the routing layer the agentic IDE reads (workflow + system
|
|
134
|
+
// status derived from the graph). Written after the graph so status has nodes.
|
|
135
|
+
refreshAgents(repoRoot);
|
|
136
|
+
log.ok('refreshed AGENTS.md (asdlc workflow + system status)');
|
|
137
|
+
|
|
138
|
+
log.info('');
|
|
139
|
+
log.info('Next:');
|
|
140
|
+
log.info(' 1. start a spec: asdlc new "<requirement>"');
|
|
141
|
+
log.info(' 2. check the spec: asdlc lint <CHANGE-ID>');
|
|
142
|
+
log.info(' 3. after the spec PR merges: asdlc approve <CHANGE-ID>');
|
|
143
|
+
log.info(' 4. implementation PR: asdlc verify <CHANGE-ID> --repo <name>');
|
|
144
|
+
return repoRoot;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// All supported tools and their skills directory name (tools that use a 'skills/' subdir convention)
|
|
148
|
+
const TOOL_SKILLS_DIRS = {
|
|
149
|
+
claude: '.claude',
|
|
150
|
+
opencode: '.opencode',
|
|
151
|
+
pi: '.pi',
|
|
152
|
+
dsh: '.dsh',
|
|
153
|
+
cursor: '.cursor',
|
|
154
|
+
gemini: '.gemini',
|
|
155
|
+
windsurf: '.windsurf',
|
|
156
|
+
trae: '.trae',
|
|
157
|
+
codex: '.codex',
|
|
158
|
+
zed: '.zed',
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export function installSkills(repoRoot, tools = []) {
|
|
162
|
+
if (!exists(skillsAssetDir)) return;
|
|
163
|
+
const targetDirs = ['.agents'];
|
|
164
|
+
for (const t of tools) {
|
|
165
|
+
const key = String(t).toLowerCase().replace(/^\./, '');
|
|
166
|
+
if (TOOL_SKILLS_DIRS[key]) targetDirs.push(TOOL_SKILLS_DIRS[key]);
|
|
167
|
+
else if (key) targetDirs.push(`.${key}`);
|
|
168
|
+
}
|
|
169
|
+
const count = listDir(skillsAssetDir).filter((d) => d.isDirectory()).length;
|
|
170
|
+
for (const dir of new Set(targetDirs)) {
|
|
171
|
+
const dest = path.join(repoRoot, dir, 'skills');
|
|
172
|
+
copyTree(skillsAssetDir, dest);
|
|
173
|
+
log.ok(`installed bundled skills (${count} skills) -> ${dir}/skills/`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function installHooks(repoRoot) {
|
|
178
|
+
if (!exists(githooksAssetDir)) return;
|
|
179
|
+
const dest = path.join(repoRoot, '.githooks');
|
|
180
|
+
copyTree(githooksAssetDir, dest);
|
|
181
|
+
try {
|
|
182
|
+
git(['config', 'core.hooksPath', '.githooks'], repoRoot);
|
|
183
|
+
log.ok('installed .githooks (pre-push, post-merge) + core.hooksPath');
|
|
184
|
+
} catch {
|
|
185
|
+
log.warn('could not set core.hooksPath (not a git repo?)');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function register(program) {
|
|
190
|
+
program
|
|
191
|
+
.command('init')
|
|
192
|
+
.description('set up a repo: reuse `openspec init` + governance overlay + CI/hooks')
|
|
193
|
+
.option('--repo-root <path>', 'repository root (default: cwd)')
|
|
194
|
+
.option('--tools <list>', 'OpenSpec agent tools (default: auto-detect)')
|
|
195
|
+
.option('--ci <name>', 'scaffold a CI pipeline (supported: jenkins)')
|
|
196
|
+
.option('--no-hooks', 'skip installing .githooks')
|
|
197
|
+
.option('--no-graph', 'skip graphify install/build')
|
|
198
|
+
.option('--no-openspec', 'skip the openspec CLI step')
|
|
199
|
+
.option('--force', 'overwrite existing config / Jenkinsfile')
|
|
200
|
+
.action((opts) => initRepo(opts));
|
|
201
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, readText, walkFiles } from '../lib/fs.js';
|
|
3
|
+
import { changeDir } from '../lib/paths.js';
|
|
4
|
+
import { requireRepo, toChangeSlug, readLintConfig, jsonOut } from '../lib/cliutil.js';
|
|
5
|
+
import { lintSpecText, countBlockers } from '../lib/speclint.js';
|
|
6
|
+
import { log, dim } from '../lib/log.js';
|
|
7
|
+
|
|
8
|
+
// THE spec check (v10: lint absorbed review). Deterministic:
|
|
9
|
+
// - required artifacts (explore.md + proposal.md + >=1 spec delta)
|
|
10
|
+
// - the review record (review.md) exists, verdict APPROVE, no blocking findings
|
|
11
|
+
// - BDD + Acceptance-Criteria quality
|
|
12
|
+
export function verdictOf(text) {
|
|
13
|
+
const m = text.match(/##\s*Verdict[^\n]*\n+\s*([A-Za-z_]+)/);
|
|
14
|
+
return m ? m[1].toUpperCase() : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function hasBlockingFindings(text) {
|
|
18
|
+
const m = text.match(/##\s*Blocking Findings[^\n]*\n([\s\S]*?)(?:\n##\s|\s*$)/i);
|
|
19
|
+
if (!m) return false;
|
|
20
|
+
const body = m[1].replace(/<!--[\s\S]*?-->/g, '').trim();
|
|
21
|
+
return Boolean(body) && !/^\(?\s*none\s*\)?\.?$/i.test(body);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function finish(results, { json, changeId }) {
|
|
25
|
+
const blockers = results.filter((r) => r.status === 'fail');
|
|
26
|
+
if (json) {
|
|
27
|
+
jsonOut({ changeId, pass: blockers.length === 0, results });
|
|
28
|
+
return blockers.length ? 1 : 0;
|
|
29
|
+
}
|
|
30
|
+
log.info('');
|
|
31
|
+
for (const r of results) {
|
|
32
|
+
const badge = { pass: 'PASS', fail: 'FAIL', skip: 'SKIP' }[r.status];
|
|
33
|
+
log.plain(` [${badge}] ${r.name}`);
|
|
34
|
+
if (r.detail) log.plain(` ${dim(r.detail)}`);
|
|
35
|
+
}
|
|
36
|
+
log.info('');
|
|
37
|
+
if (blockers.length) {
|
|
38
|
+
log.plain(`lint failed: ${blockers.length} check(s)`);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
log.plain('lint passed');
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function runLint(changeId, opts = {}) {
|
|
46
|
+
const repoRoot = requireRepo(opts);
|
|
47
|
+
const slug = toChangeSlug(changeId);
|
|
48
|
+
const cdir = changeDir(repoRoot, slug);
|
|
49
|
+
const results = [];
|
|
50
|
+
const add = (name, status, detail) => results.push({ name, status, detail });
|
|
51
|
+
|
|
52
|
+
if (!exists(cdir)) {
|
|
53
|
+
add('change', 'fail', `change '${slug}' not found`);
|
|
54
|
+
return finish(results, { json: opts.json, changeId });
|
|
55
|
+
}
|
|
56
|
+
add('change', 'pass', slug);
|
|
57
|
+
add('explore.md (stage 1)', exists(path.join(cdir, 'explore.md')) ? 'pass' : 'fail',
|
|
58
|
+
exists(path.join(cdir, 'explore.md')) ? '' : 'run `asdlc new <ID>` (explore is the first stage)');
|
|
59
|
+
const proposalPath = path.join(cdir, 'proposal.md');
|
|
60
|
+
const proposalText = exists(proposalPath) ? readText(proposalPath) : '';
|
|
61
|
+
add('proposal.md', exists(proposalPath) ? 'pass' : 'fail',
|
|
62
|
+
exists(proposalPath) ? '' : 'proposal.md missing');
|
|
63
|
+
|
|
64
|
+
const specFiles = exists(path.join(cdir, 'specs'))
|
|
65
|
+
? walkFiles(path.join(cdir, 'specs')).filter((f) => f.endsWith('spec.md'))
|
|
66
|
+
: [];
|
|
67
|
+
add('spec delta', specFiles.length > 0 ? 'pass' : 'fail', specFiles.length > 0 ? `${specFiles.length} file(s)` : 'no spec delta present');
|
|
68
|
+
|
|
69
|
+
const combinedSpecText = specFiles.map((f) => readText(path.join(cdir, 'specs', f))).join('\n');
|
|
70
|
+
const fullIntentText = `${proposalText}\n${combinedSpecText}`;
|
|
71
|
+
|
|
72
|
+
// Deterministic detection for UI and 3rd-party/external API scope
|
|
73
|
+
const UI_OR_EXTERNAL_API = /\b(ui|ux|frontend|web|screen|page|view|component|css|style|html|layout|dialog|modal|button|table|card|form|itinerary|3rd-party|third-party|external api|vendor api|geocode|amap|weather api|maps api|payment gateway|stripe|oauth|webhook)\b/i;
|
|
74
|
+
const requiresDesign = UI_OR_EXTERNAL_API.test(fullIntentText);
|
|
75
|
+
|
|
76
|
+
const designPath = path.join(cdir, 'design.md');
|
|
77
|
+
if (!exists(designPath)) {
|
|
78
|
+
if (requiresDesign) {
|
|
79
|
+
add('design.md', 'fail', 'design.md is mandatory for UI and external API changes (run `asdlc new --design` or author design.md)');
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
const text = readText(designPath);
|
|
83
|
+
const nonComment = text.replace(/<!--[\s\S]*?-->/g, '').trim();
|
|
84
|
+
if (nonComment.length < 150) {
|
|
85
|
+
add('design.md', 'fail', 'design.md contains only unedited template placeholders; fill in technical design');
|
|
86
|
+
} else {
|
|
87
|
+
add('design.md', 'pass', 'technical design documented');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const reviewPath = path.join(cdir, 'review.md');
|
|
92
|
+
if (!exists(reviewPath)) {
|
|
93
|
+
add('review.md', 'pass', 'delegated to CI bot (review comments & summary posted on PR)');
|
|
94
|
+
add('review verdict', 'pass', 'pending human PR review on GitHub/GitLab');
|
|
95
|
+
} else {
|
|
96
|
+
const text = readText(reviewPath);
|
|
97
|
+
add('review.md', 'pass', '');
|
|
98
|
+
const verdict = verdictOf(text);
|
|
99
|
+
add('review verdict', verdict === 'APPROVE' ? 'pass' : 'fail', verdict ? `verdict: ${verdict}` : 'no verdict found');
|
|
100
|
+
add('blocking findings', hasBlockingFindings(text) ? 'fail' : 'pass', hasBlockingFindings(text) ? 'blocking findings present' : '');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { rules } = readLintConfig(repoRoot);
|
|
104
|
+
const findings = [];
|
|
105
|
+
for (const file of specFiles) {
|
|
106
|
+
// Spec stage: check the AC->test MAPPING exists, but not that the test file
|
|
107
|
+
// exists yet (the test is written during implementation; `asdlc verify`
|
|
108
|
+
// enforces existence).
|
|
109
|
+
for (const fnd of lintSpecText(readText(path.join(cdir, 'specs', file)), { rules })) findings.push({ ...fnd, file });
|
|
110
|
+
}
|
|
111
|
+
const blockers = countBlockers(findings);
|
|
112
|
+
add('BDD + acceptance criteria', blockers === 0 ? 'pass' : 'fail',
|
|
113
|
+
blockers === 0 ? `${findings.length} advisory finding(s)` : `${blockers} blocker(s)`);
|
|
114
|
+
|
|
115
|
+
return finish(results, { json: opts.json, changeId });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function register(program) {
|
|
119
|
+
program
|
|
120
|
+
.command('lint <changeId>')
|
|
121
|
+
.description('check the spec: artifacts + review record + BDD/acceptance criteria')
|
|
122
|
+
.option('--repo-root <path>')
|
|
123
|
+
.option('--json', 'stable JSON output for CI')
|
|
124
|
+
.action((changeId, opts) => {
|
|
125
|
+
process.exitCode = runLint(changeId, opts);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, readText, writeText, ensureDir } from '../lib/fs.js';
|
|
3
|
+
import { changeDir, schemaAssetDir } from '../lib/paths.js';
|
|
4
|
+
import { requireRepo, deriveChangeSlug, extractRequirementTerms } from '../lib/cliutil.js';
|
|
5
|
+
import { ensureGraphify, ensureFreshGraph, graphifyQuery } from '../lib/graphify.js';
|
|
6
|
+
import { runOpenspec } from '../lib/openspec.js';
|
|
7
|
+
import { runShell } from '../lib/exec.js';
|
|
8
|
+
import { fail } from '../lib/errors.js';
|
|
9
|
+
import { log } from '../lib/log.js';
|
|
10
|
+
|
|
11
|
+
// STAGE 1 of the spec (v10: explore + propose are ONE step).
|
|
12
|
+
// 1) scaffold the change through OpenSpec (derives canonical slug from requirement)
|
|
13
|
+
// 2) refresh the knowledge graph (graphify, behind the scenes)
|
|
14
|
+
// 3) write explore.md so the proposal is grounded in the real system
|
|
15
|
+
export function newChange(requirement, opts = {}) {
|
|
16
|
+
const repoRoot = requireRepo(opts);
|
|
17
|
+
const slug = deriveChangeSlug(requirement, opts);
|
|
18
|
+
const cdir = changeDir(repoRoot, slug);
|
|
19
|
+
if (exists(cdir)) fail(`change '${slug}' already exists`, { hint: 'use a new requirement/id, or iterate the existing change' });
|
|
20
|
+
|
|
21
|
+
if (opts.openspec !== false) {
|
|
22
|
+
const res = runOpenspec(['new', 'change', slug], repoRoot);
|
|
23
|
+
if (res.missing) fail('OpenSpec CLI not found', { hint: 'run `asdlc init`' });
|
|
24
|
+
if (res.status !== 0) fail(`openspec new change failed: ${(res.stderr || res.stdout || '').slice(0, 300)}`);
|
|
25
|
+
log.ok(`created change '${slug}' (derived from: "${requirement}")`);
|
|
26
|
+
} else {
|
|
27
|
+
ensureDir(cdir);
|
|
28
|
+
writeText(path.join(cdir, '.openspec.yaml'), 'schema: agentic-repo-change\n');
|
|
29
|
+
log.ok(`created change '${slug}' (derived from: "${requirement}")`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Record requirement in change metadata (.openspec.yaml)
|
|
33
|
+
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
34
|
+
if (exists(metaPath)) {
|
|
35
|
+
const existing = readText(metaPath).trimEnd();
|
|
36
|
+
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\n`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const g = ensureGraphify();
|
|
40
|
+
if (!g.installed) {
|
|
41
|
+
log.warn('[WARN] explore.md generated without graph context (Graphify not installed). Run `asdlc init --graph` to enable architectural AST index.');
|
|
42
|
+
const fallbackMd = `# Explore: ${slug}
|
|
43
|
+
|
|
44
|
+
> Requirement: "${requirement}"
|
|
45
|
+
> [WARN] explore.md generated without graph context because Graphify is not installed or enabled.
|
|
46
|
+
> Run \`asdlc init --graph\` to build the repository knowledge graph.
|
|
47
|
+
> generatedAt: ${new Date().toISOString()}
|
|
48
|
+
|
|
49
|
+
## Architectural hubs (god nodes)
|
|
50
|
+
_(unavailable - graphify not initialized)_
|
|
51
|
+
|
|
52
|
+
## Query: ${slug}
|
|
53
|
+
_(unavailable - graphify not initialized)_
|
|
54
|
+
`;
|
|
55
|
+
writeText(path.join(cdir, 'explore.md'), fallbackMd);
|
|
56
|
+
log.ok(`wrote explore.md (fallback without graph context)`);
|
|
57
|
+
} else {
|
|
58
|
+
try {
|
|
59
|
+
const fresh = ensureFreshGraph(repoRoot);
|
|
60
|
+
const terms = extractRequirementTerms(requirement);
|
|
61
|
+
const q = opts.query ?? (terms || slug);
|
|
62
|
+
const hubs = (runShell('graphify god-nodes', repoRoot).stdout || '').trim();
|
|
63
|
+
const query = graphifyQuery(repoRoot, q);
|
|
64
|
+
const md = `# Explore: ${slug}
|
|
65
|
+
|
|
66
|
+
> Requirement: "${requirement}"
|
|
67
|
+
> Generated by \`asdlc new\` from the knowledge graph - structured queries, not
|
|
68
|
+
> code reading. Ground the proposal in this. generatedAt: ${new Date().toISOString()}
|
|
69
|
+
|
|
70
|
+
## Architectural hubs (god nodes)
|
|
71
|
+
|
|
72
|
+
${hubs || '_(none)_'}
|
|
73
|
+
|
|
74
|
+
## Query: ${q}
|
|
75
|
+
|
|
76
|
+
${(query.stdout || '').trim() || '_(no matches)_'}
|
|
77
|
+
`;
|
|
78
|
+
writeText(path.join(cdir, 'explore.md'), md);
|
|
79
|
+
log.ok(`wrote explore.md (graph ${fresh.status}, query: "${q}")`);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
log.warn(`[WARN] explore.md generated with partial context (graph error: ${err.message}). Run \`asdlc init --graph\` to reindex.`);
|
|
82
|
+
const fallbackMd = `# Explore: ${slug}
|
|
83
|
+
|
|
84
|
+
> Requirement: "${requirement}"
|
|
85
|
+
> [WARN] Graph query encountered an error: ${err.message}
|
|
86
|
+
> Run \`asdlc init --graph\` to reindex repository knowledge graph.
|
|
87
|
+
> generatedAt: ${new Date().toISOString()}
|
|
88
|
+
|
|
89
|
+
## Architectural hubs (god nodes)
|
|
90
|
+
_(unavailable - graph query error)_
|
|
91
|
+
|
|
92
|
+
## Query: ${slug}
|
|
93
|
+
_(unavailable - graph query error)_
|
|
94
|
+
`;
|
|
95
|
+
writeText(path.join(cdir, 'explore.md'), fallbackMd);
|
|
96
|
+
log.ok(`wrote explore.md (fallback with error note)`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Seed the grilling interview (skill: grilling / batch-grill-me). The agent runs it
|
|
101
|
+
// with the author in batch mode to resolve the decision frontier in 1-2 turns.
|
|
102
|
+
const clar = path.join(cdir, 'clarifications.md');
|
|
103
|
+
if (!exists(clar)) {
|
|
104
|
+
writeText(clar, `# Clarifications: ${slug}
|
|
105
|
+
|
|
106
|
+
> Requirement: "${requirement}"
|
|
107
|
+
> Before writing proposal.md / specs, the agent MUST run a **batch-grill-me** interview
|
|
108
|
+
> with the author (skill: \`grilling\`) and record the settled decisions here.
|
|
109
|
+
> Use batch-grill-me for maximum efficiency: evaluate the design tree, present the ENTIRE
|
|
110
|
+
> frontier in one structured batch (numbered Q1..Qn with concrete recommended defaults),
|
|
111
|
+
> allowing the author to approve or selectively adjust decisions in 1-2 rounds.
|
|
112
|
+
> Facts are the agent's job to look up; decisions are the author's to make.
|
|
113
|
+
|
|
114
|
+
## Requirement
|
|
115
|
+
"${requirement}"
|
|
116
|
+
|
|
117
|
+
## Settled decisions
|
|
118
|
+
<!-- one entry per settled decision: decision -> answer, with the reason -->
|
|
119
|
+
<!-- Consider key architectural dimensions: -->
|
|
120
|
+
<!-- 1. Functional Scope & Seams (user journeys, error states, domain models) -->
|
|
121
|
+
<!-- 2. Security & Threat Mitigation (auth, parameter validation, secrets, data privacy) -->
|
|
122
|
+
<!-- 3. Operational NFRs & Performance Budgets (latency SLAs, cache TTL, rate limits) -->
|
|
123
|
+
|
|
124
|
+
## Open questions
|
|
125
|
+
<!-- must be empty before the spec is written -->
|
|
126
|
+
`);
|
|
127
|
+
log.ok('seeded clarifications.md (run batch-grill-me interview)');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Technical design (design.md) scaffolding:
|
|
131
|
+
// Auto-seed if requirement implies UI, frontend, API integration, security, NFR, or technical complexity,
|
|
132
|
+
// or if explicitly requested via opts.design === true.
|
|
133
|
+
const UI_OR_TECH_KEYWORDS = /\b(ui|ux|frontend|web|screen|page|view|component|css|style|api|endpoint|service|client|integration|database|db|schema|model|architecture|refactor|migration|auth|payment|cache|gateway|protocol|security|threat|nfr|performance|rate.?limit|sanitize|encryption)\b/i;
|
|
134
|
+
const shouldSeedDesign = opts.design === true || (opts.design !== false && UI_OR_TECH_KEYWORDS.test(requirement));
|
|
135
|
+
const designPath = path.join(cdir, 'design.md');
|
|
136
|
+
if (shouldSeedDesign && !exists(designPath)) {
|
|
137
|
+
const tmplPath = path.join(schemaAssetDir, 'templates', 'design.md');
|
|
138
|
+
let tmpl = exists(tmplPath) ? readText(tmplPath) : `# Technical Design: ${slug}\n\n`;
|
|
139
|
+
tmpl = tmpl.replace('<!-- change id -->', slug);
|
|
140
|
+
tmpl = tmpl.replace('<!-- requirement summary -->', requirement.replace(/"/g, '\\"'));
|
|
141
|
+
writeText(designPath, tmpl);
|
|
142
|
+
log.ok('seeded design.md (technical design for architecture/UI/API/security/NFR)');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
log.info('');
|
|
146
|
+
log.info('[ASDLC PROTOCOL: IMMEDIATE ACTION REQUIRED FOR AGENT]');
|
|
147
|
+
log.info(' ▶ DO NOT pause or ask the author if you should begin grilling.');
|
|
148
|
+
log.info(' ▶ Ground yourself in `explore.md` and research codebase facts first.');
|
|
149
|
+
log.info(' ▶ Perform external search for 3rd-party APIs, vendor SDKs, and UI design patterns (enabled by default).');
|
|
150
|
+
log.info(' (If search fails or offline: emit \'[WARN] External search failed or offline: <reason>. Continuing with defined steps.\' and continue without blocking).');
|
|
151
|
+
log.info(' ▶ Formulate decision frontier covering Functional scope, Security threat vectors, and Operational NFRs.');
|
|
152
|
+
log.info(' ▶ Invoke `batch-grill-me` (or `grilling`) to present structured Batch 1 questions with recommended defaults.');
|
|
153
|
+
log.info(' ▶ Record agreed decisions into `clarifications.md`.');
|
|
154
|
+
log.info(' ▶ ONLY AFTER clarifications are settled: author `proposal.md`, `specs/**`, and `design.md` (if seeded/needed).');
|
|
155
|
+
log.info(` ▶ Run \`asdlc lint ${slug}\`.`);
|
|
156
|
+
return slug;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function register(program) {
|
|
160
|
+
program
|
|
161
|
+
.command('new <requirement>')
|
|
162
|
+
.description('start a spec: scaffold + refresh the graph + explore.md + clarifications.md (for grilling)')
|
|
163
|
+
.option('--id <slug>', 'explicit change slug (override auto-derivation)')
|
|
164
|
+
.option('--query <q>', 'graph query terms (default: extracted requirement terms)')
|
|
165
|
+
.option('--design', 'explicitly generate technical design (design.md)')
|
|
166
|
+
.option('--no-design', 'skip generating technical design (design.md)')
|
|
167
|
+
.option('--repo-root <path>')
|
|
168
|
+
.action((requirement, opts) => {
|
|
169
|
+
newChange(requirement, opts);
|
|
170
|
+
});
|
|
171
|
+
}
|