@akjamie/agentic-sdlc 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -2
  3. package/assets/ci/Jenkinsfile +80 -0
  4. package/assets/ci/asdlc-ai-review.yml +65 -0
  5. package/assets/config/config.yaml +76 -0
  6. package/assets/githooks/post-merge +22 -0
  7. package/assets/githooks/pre-push +17 -0
  8. package/assets/policy/policy.yaml +46 -0
  9. package/assets/schema/schema.yaml +162 -0
  10. package/assets/schema/templates/design.md +16 -0
  11. package/assets/schema/templates/proposal.md +25 -0
  12. package/assets/schema/templates/review.md +24 -0
  13. package/assets/schema/templates/spec.md +37 -0
  14. package/assets/schema/templates/tasks.md +10 -0
  15. package/assets/skills/asdlc-apply/SKILL.md +128 -0
  16. package/assets/skills/asdlc-approve/SKILL.md +107 -0
  17. package/assets/skills/asdlc-archive/SKILL.md +48 -0
  18. package/assets/skills/asdlc-doctor/SKILL.md +82 -0
  19. package/assets/skills/asdlc-impl-review/SKILL.md +214 -0
  20. package/assets/skills/asdlc-init/SKILL.md +68 -0
  21. package/assets/skills/asdlc-lint/SKILL.md +56 -0
  22. package/assets/skills/asdlc-new/SKILL.md +74 -0
  23. package/assets/skills/asdlc-pr/SKILL.md +59 -0
  24. package/assets/skills/asdlc-review/SKILL.md +80 -0
  25. package/assets/skills/asdlc-spec-review/SKILL.md +194 -0
  26. package/assets/skills/asdlc-status/SKILL.md +49 -0
  27. package/assets/skills/asdlc-upgrade/SKILL.md +34 -0
  28. package/assets/skills/asdlc-verify/SKILL.md +55 -0
  29. package/assets/skills/batch-grill-me/SKILL.md +136 -0
  30. package/assets/skills/grilling/SKILL.md +136 -0
  31. package/bin/asdlc.js +6 -0
  32. package/package.json +43 -4
  33. package/src/cli.js +86 -0
  34. package/src/commands/apply.js +114 -0
  35. package/src/commands/approve.js +166 -0
  36. package/src/commands/archive.js +115 -0
  37. package/src/commands/doctor.js +163 -0
  38. package/src/commands/init.js +201 -0
  39. package/src/commands/lint.js +103 -0
  40. package/src/commands/new.js +142 -0
  41. package/src/commands/pr.js +495 -0
  42. package/src/commands/skills.js +184 -0
  43. package/src/commands/status.js +65 -0
  44. package/src/commands/update.js +103 -0
  45. package/src/commands/upgrade.js +175 -0
  46. package/src/commands/verify.js +229 -0
  47. package/src/index.js +3 -0
  48. package/src/lib/agents.js +73 -0
  49. package/src/lib/cliutil.js +99 -0
  50. package/src/lib/errors.js +18 -0
  51. package/src/lib/exec.js +19 -0
  52. package/src/lib/fs.js +83 -0
  53. package/src/lib/git.js +76 -0
  54. package/src/lib/graphify.js +106 -0
  55. package/src/lib/log.js +15 -0
  56. package/src/lib/openspec.js +91 -0
  57. package/src/lib/paths.js +43 -0
  58. package/src/lib/policy.js +54 -0
  59. package/src/lib/prtype.js +41 -0
  60. package/src/lib/schema.js +86 -0
  61. package/src/lib/speclint.js +168 -0
  62. package/src/lib/tdd.js +71 -0
  63. package/src/lib/yaml.js +18 -0
@@ -0,0 +1,65 @@
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 } from '../lib/cliutil.js';
5
+ import { lastCommitTouching } from '../lib/git.js';
6
+ import { verdictOf } from './lint.js';
7
+ import { countUncheckedTasks } from './verify.js';
8
+ import { log } from '../lib/log.js';
9
+
10
+ // "Where am I?" for a change - a read-only view of the 7 stages from the working
11
+ // tree + git. Useful for humans and for an agent deciding the next command.
12
+ export function statusChange(changeId, opts = {}) {
13
+ const repoRoot = requireRepo(opts);
14
+ const slug = toChangeSlug(changeId);
15
+ const branch = opts.protectedBranch ?? 'origin/main';
16
+ const cdir = changeDir(repoRoot, slug);
17
+
18
+ if (!exists(cdir)) {
19
+ log.plain(`change: ${slug}`);
20
+ log.plain(' (not created)');
21
+ log.plain(`next: asdlc new ${changeId}`);
22
+ return 0;
23
+ }
24
+
25
+ const has = (f) => exists(path.join(cdir, f));
26
+ const specFiles = exists(path.join(cdir, 'specs'))
27
+ ? walkFiles(path.join(cdir, 'specs')).filter((f) => f.endsWith('spec.md')) : [];
28
+ const review = has('review.md') ? readText(path.join(cdir, 'review.md')) : null;
29
+ const verdict = review ? verdictOf(review) : null;
30
+ const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
31
+ const approvedSha = lastCommitTouching(repoRoot, branch, locked);
32
+ const unchecked = has('tasks.md') ? countUncheckedTasks(readText(path.join(cdir, 'tasks.md'))) : null;
33
+
34
+ const stage = [
35
+ ['1 explore (draft)', has('explore.md')],
36
+ ['2 proposal.md', has('proposal.md')],
37
+ ['2 spec delta', specFiles.length > 0],
38
+ ['3 spec approved on ' + branch, Boolean(approvedSha)],
39
+ ['4 tasks complete', unchecked === 0],
40
+ ];
41
+
42
+ log.plain(`change: ${slug}`);
43
+ for (const [name, ok] of stage) log.plain(` [${ok ? 'x' : ' '}] ${name}`);
44
+
45
+ let next;
46
+ if (!has('explore.md') && !has('proposal.md')) next = `asdlc new ${changeId}`;
47
+ else if (!has('proposal.md') || specFiles.length === 0) next = 'author proposal.md + specs/**';
48
+ else if (!approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (CI handles AI review on PR; once merged run: asdlc approve ${changeId})`;
49
+ else if (unchecked !== 0) next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
50
+ else next = `asdlc verify ${changeId}`;
51
+ log.plain('');
52
+ log.plain(`next: ${next}`);
53
+ return 0;
54
+ }
55
+
56
+ export function register(program) {
57
+ program
58
+ .command('status <changeId>')
59
+ .description('show where a change is in the 7 stages + the next command')
60
+ .option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
61
+ .option('--repo-root <path>')
62
+ .action((changeId, opts) => {
63
+ process.exitCode = statusChange(changeId, opts);
64
+ });
65
+ }
@@ -0,0 +1,103 @@
1
+ import path from 'node:path';
2
+ import { exists } from '../lib/fs.js';
3
+ import { resolveRepoRoot, openspecDir, OPENSPEC_DIR } from '../lib/paths.js';
4
+ import { log } from '../lib/log.js';
5
+ import { detectTools, installSkills, installHooks } from './init.js';
6
+ import { ensureGraphify, buildGraph, ensureGitignore } from '../lib/graphify.js';
7
+ import { refreshAgents } from '../lib/agents.js';
8
+
9
+ export function updateRepo(opts = {}) {
10
+ const repoRoot = resolveRepoRoot(opts);
11
+ const isGit = exists(path.join(repoRoot, '.git'));
12
+ const isSdlc = exists(openspecDir(repoRoot));
13
+
14
+ if (!isGit) {
15
+ log.error('Not a Git repository: \'asdlc update\' must be run inside a Git repository.');
16
+ log.info('');
17
+ log.info('💡 To initialize this project for Agentic SDLC, run:');
18
+ log.info(' git init');
19
+ log.info(' asdlc init');
20
+ log.info('');
21
+ log.info('💡 To upgrade your global CLI toolchain instead, run:');
22
+ log.info(' asdlc upgrade --global');
23
+ return 1;
24
+ }
25
+
26
+ if (!isSdlc) {
27
+ log.error(`Repository not initialized for Agentic SDLC (missing '${OPENSPEC_DIR}/' directory).`);
28
+ log.info('');
29
+ log.info('💡 To set up Agentic SDLC in this repository (OpenSpec, knowledge graph, and agent skills):');
30
+ log.info(' asdlc init');
31
+ log.info('');
32
+ log.info('💡 To upgrade your global CLI toolchain instead:');
33
+ log.info(' asdlc upgrade');
34
+ return 1;
35
+ }
36
+
37
+ log.info('=== Updating Repository SDLC State ===');
38
+ log.info(`Repository: ${repoRoot}`);
39
+ log.info('');
40
+
41
+ // 1) Skills refresh
42
+ if (opts.skills !== false) {
43
+ log.step('refreshing bundled agent skills in repository...');
44
+ const tools = detectTools(repoRoot);
45
+ installSkills(repoRoot, tools);
46
+ }
47
+
48
+ // 2) Codebase AST knowledge graph (KB / graphify)
49
+ if (opts.graph !== false) {
50
+ log.step('rebuilding codebase AST knowledge graph (graphify)...');
51
+ try {
52
+ const g = ensureGraphify();
53
+ if (g.installed) {
54
+ const b = buildGraph(repoRoot);
55
+ if (b.status === 0) {
56
+ log.ok('rebuilt code knowledge graph -> graphify-out/ (bound to HEAD)');
57
+ ensureGitignore(repoRoot);
58
+ } else {
59
+ log.warn('graphify build returned non-zero status (non-fatal)');
60
+ }
61
+ } else {
62
+ log.warn('graphify not installed; skipping knowledge graph rebuild');
63
+ }
64
+ } catch (err) {
65
+ log.warn(`graphify update failed: ${err.message}`);
66
+ }
67
+ }
68
+
69
+ // 3) Agent routing layer (AGENTS.md)
70
+ log.step('refreshing AGENTS.md system status & architectural hubs...');
71
+ try {
72
+ refreshAgents(repoRoot);
73
+ log.ok('refreshed AGENTS.md system status (derived from knowledge graph)');
74
+ } catch (err) {
75
+ log.warn(`AGENTS.md refresh failed: ${err.message}`);
76
+ }
77
+
78
+ // 4) Git governance hooks
79
+ if (opts.hooks !== false) {
80
+ try {
81
+ installHooks(repoRoot);
82
+ } catch (err) {
83
+ log.warn(`git hooks refresh failed: ${err.message}`);
84
+ }
85
+ }
86
+
87
+ log.info('');
88
+ log.ok('Repository SDLC state is fully up to date.');
89
+ return 0;
90
+ }
91
+
92
+ export function register(program) {
93
+ program
94
+ .command('update')
95
+ .description('update current repository SDLC state: refresh agent skills, rebuild AST knowledge graph (KB), and sync AGENTS.md')
96
+ .option('--repo-root <path>', 'repository root (default: current repository)')
97
+ .option('--no-skills', 'skip refreshing agent skills')
98
+ .option('--no-graph', 'skip rebuilding codebase knowledge graph')
99
+ .option('--no-hooks', 'skip refreshing git hooks')
100
+ .action((opts) => {
101
+ process.exitCode = updateRepo(opts);
102
+ });
103
+ }
@@ -0,0 +1,175 @@
1
+ import path from 'node:path';
2
+ import { execFileSync, spawnSync } from 'node:child_process';
3
+ import { exists } from '../lib/fs.js';
4
+ import { resolveRepoRoot, schemaAssetDir, openspecDir } from '../lib/paths.js';
5
+ import { installSchema, builtinSchemaVersion } from '../lib/schema.js';
6
+ import { updateRepo } from './update.js';
7
+ import { doctor } from './doctor.js';
8
+ import { log } from '../lib/log.js';
9
+
10
+ import { detectTools, installSkills } from './init.js';
11
+
12
+ function which(name) {
13
+ const finder = process.platform === 'win32' ? 'where' : 'which';
14
+ const r = spawnSync(finder, [name], { encoding: 'utf8' });
15
+ if (r.status !== 0) return null;
16
+ return r.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0] ?? null;
17
+ }
18
+
19
+ export function upgradeAsdlc() {
20
+ log.step('upgrading asdlc CLI...');
21
+ try {
22
+ const pkgSpec = process.env.ASDLC_PKG_SPEC || '@akjamie/agentic-sdlc@latest';
23
+ execFileSync('npm', ['install', '-g', pkgSpec], { stdio: 'inherit' });
24
+ log.ok('asdlc CLI upgraded to latest');
25
+ return true;
26
+ } catch (err) {
27
+ log.warn(`asdlc upgrade via npm failed: ${err.message}`);
28
+ log.info('💡 [FALLBACK] If automatic upgrade failed, run manually:');
29
+ log.info(' npm install -g --allow-git=all --force git+https://github.com/akjamie/agentic-sdlc.git');
30
+ return false;
31
+ }
32
+ }
33
+
34
+ export function upgradeSkills(repoRoot) {
35
+ log.step('refreshing bundled agent skills in repository...');
36
+ try {
37
+ const tools = detectTools(repoRoot);
38
+ installSkills(repoRoot, tools);
39
+ log.ok('refreshed bundled agent skills in repository');
40
+ return true;
41
+ } catch (err) {
42
+ log.warn(`skills refresh failed: ${err.message}`);
43
+ return false;
44
+ }
45
+ }
46
+
47
+ export function upgradeOpenspec() {
48
+ log.step('upgrading openspec...');
49
+ try {
50
+ execFileSync('npm', ['install', '-g', '@fission-ai/openspec@latest'], { stdio: 'inherit' });
51
+ log.ok('openspec upgraded to latest');
52
+ return true;
53
+ } catch (err) {
54
+ log.warn(`openspec upgrade failed: ${err.message}`);
55
+ return false;
56
+ }
57
+ }
58
+
59
+ export function upgradeGraphify() {
60
+ log.step('upgrading graphify...');
61
+ const viaUv = Boolean(which('uv'));
62
+ const viaPipx = Boolean(which('pipx'));
63
+ const viaPip = Boolean(which('pip'));
64
+
65
+ if (viaUv) {
66
+ try {
67
+ execFileSync('uv', ['tool', 'install', '--upgrade', 'graphifyy'], { stdio: 'inherit' });
68
+ log.ok('graphify upgraded via uv');
69
+ return true;
70
+ } catch {
71
+ // fallback
72
+ }
73
+ }
74
+
75
+ if (viaPipx) {
76
+ try {
77
+ execFileSync('pipx', ['install', '--upgrade', 'graphifyy'], { stdio: 'inherit' });
78
+ log.ok('graphify upgraded via pipx');
79
+ return true;
80
+ } catch {
81
+ // fallback
82
+ }
83
+ }
84
+
85
+ if (viaPip) {
86
+ try {
87
+ execFileSync('pip', ['install', '--upgrade', 'graphifyy'], { stdio: 'inherit' });
88
+ log.ok('graphify upgraded via pip');
89
+ return true;
90
+ } catch (err) {
91
+ // PEP 668 on Debian/Ubuntu externally-managed-environment: retry with --break-system-packages
92
+ try {
93
+ execFileSync('pip', ['install', '--upgrade', 'graphifyy', '--break-system-packages'], { stdio: 'inherit' });
94
+ log.ok('graphify upgraded via pip (--break-system-packages)');
95
+ return true;
96
+ } catch (err2) {
97
+ log.warn(`graphify upgrade via pip failed: ${err2.message}`);
98
+ return false;
99
+ }
100
+ }
101
+ }
102
+
103
+ log.warn('neither uv, pipx, nor pip found; please install/upgrade graphify manually');
104
+ return false;
105
+ }
106
+
107
+ export function upgradeSchema() {
108
+ log.step('refreshing BU-managed OpenSpec schema...');
109
+ try {
110
+ if (!exists(schemaAssetDir)) {
111
+ log.warn(`schema asset directory missing at ${schemaAssetDir}`);
112
+ return false;
113
+ }
114
+ const dest = installSchema();
115
+ log.ok(`refreshed schema v${builtinSchemaVersion()} -> ${dest}`);
116
+ return true;
117
+ } catch (err) {
118
+ log.warn(`schema refresh failed: ${err.message}`);
119
+ return false;
120
+ }
121
+ }
122
+
123
+ import { installGlobalSkills } from './skills.js';
124
+
125
+ export function runUpgrade(opts = {}) {
126
+ log.info('=== Upgrading Agentic SDLC Toolchain ===');
127
+ log.info('');
128
+
129
+ const repoRoot = opts.global ? null : resolveRepoRoot(opts);
130
+
131
+ if (opts.asdlc !== false) upgradeAsdlc();
132
+ if (opts.openspec !== false) upgradeOpenspec();
133
+ if (opts.graphify !== false) upgradeGraphify();
134
+ if (opts.schema !== false) upgradeSchema();
135
+
136
+ if (opts.skills !== false) {
137
+ if (opts.global) {
138
+ installGlobalSkills(opts);
139
+ } else if (repoRoot) {
140
+ if (exists(openspecDir(repoRoot))) {
141
+ updateRepo({ repoRoot, ...opts });
142
+ } else {
143
+ upgradeSkills(repoRoot);
144
+ }
145
+ }
146
+ }
147
+
148
+ log.info('');
149
+ log.ok('Toolchain upgrade complete.');
150
+
151
+ if (opts.doctor !== false) {
152
+ log.info('');
153
+ log.info('=== Post-upgrade Health Check (doctor) ===');
154
+ return doctor(repoRoot ? { repoRoot } : {});
155
+ }
156
+
157
+ return 0;
158
+ }
159
+
160
+ export function register(program) {
161
+ program
162
+ .command('upgrade')
163
+ .description('upgrade the toolchain: asdlc CLI, OpenSpec, Graphify, managed schemas, and repo or global skills')
164
+ .option('-g, --global', 'upgrade toolchain and refresh global user skills (~/.agents) for CI runners')
165
+ .option('--no-asdlc', 'skip upgrading asdlc itself')
166
+ .option('--no-openspec', 'skip upgrading openspec')
167
+ .option('--no-graphify', 'skip upgrading graphify')
168
+ .option('--no-schema', 'skip refreshing BU-managed schema')
169
+ .option('--no-skills', 'skip refreshing skills')
170
+ .option('--no-doctor', 'skip running post-upgrade doctor check')
171
+ .option('--repo-root <path>')
172
+ .action((opts) => {
173
+ process.exitCode = runUpgrade(opts);
174
+ });
175
+ }
@@ -0,0 +1,229 @@
1
+ import path from 'node:path';
2
+ import { exists, readText, walkFiles } from '../lib/fs.js';
3
+ import { readYaml } from '../lib/yaml.js';
4
+ import { openspecDir, changeDir } from '../lib/paths.js';
5
+ import { requireRepo, toChangeSlug, readLintConfig } from '../lib/cliutil.js';
6
+ import { validateChange } from '../lib/openspec.js';
7
+ import { runShell } from '../lib/exec.js';
8
+ import { lastCommitTouching, changeOnRef, git } from '../lib/git.js';
9
+ import { lintSpecText, countBlockers } from '../lib/speclint.js';
10
+ import { checkSchema } from '../lib/schema.js';
11
+ import { loadPolicy, isAdvisory, DEFAULT_POLICY, matchesAny } from '../lib/policy.js';
12
+ import { classifyPR } from '../lib/prtype.js';
13
+ import { checkTestPresence, checkTaskEvidence } from '../lib/tdd.js';
14
+ import { log, dim } from '../lib/log.js';
15
+
16
+ // THE implementation check (v10: gate absorbed verify). Deterministic checks
17
+ // first, then - if a verifier is configured - independent AI verification
18
+ // (player != referee).
19
+
20
+ function meta(repoRoot, changeId) {
21
+ const p = path.join(changeDir(repoRoot, toChangeSlug(changeId)), '.openspec.yaml');
22
+ if (!exists(p)) return {};
23
+ const text = readText(p);
24
+ const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
25
+ const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
26
+ return { specSha: sha ? sha[1] : null, status: status ? status[1] : null };
27
+ }
28
+
29
+ function readYamlConfig(repoRoot) {
30
+ const cfg = path.join(openspecDir(repoRoot), 'config.yaml');
31
+ if (!exists(cfg)) return {};
32
+ try { return readYaml(cfg) ?? {}; } catch { return {}; }
33
+ }
34
+
35
+ export function countUncheckedTasks(text) {
36
+ return (text.match(/^\s*-\s+\[\s\]/gm) ?? []).length;
37
+ }
38
+
39
+ function readExternalChecks(repoRoot) {
40
+ const ext = (readYamlConfig(repoRoot).gates ?? {}).external;
41
+ if (!Array.isArray(ext)) return [];
42
+ return ext.filter((e) => e && typeof e.command === 'string').map((e) => ({ name: e.name ?? e.command, command: e.command }));
43
+ }
44
+
45
+ function finish(results, policy) {
46
+ let failed = 0;
47
+ log.info('');
48
+ for (const r of results) {
49
+ const status = r.status === 'fail' && isAdvisory(policy, r.name) ? 'warn' : r.status;
50
+ const badge = { pass: 'PASS', fail: 'FAIL', warn: 'WARN', skip: 'SKIP' }[status];
51
+ if (status === 'fail') failed += 1;
52
+ log.plain(` [${badge}] ${r.name}`);
53
+ if (r.detail) log.plain(` ${dim(r.detail)}`);
54
+ }
55
+ log.info('');
56
+ if (failed) { log.plain(`verify failed: ${failed} check(s)`); return 1; }
57
+ log.plain('verify passed');
58
+ return 0;
59
+ }
60
+
61
+ function intent(cdir) {
62
+ const parts = [];
63
+ for (const f of ['proposal.md', 'review.md', 'tasks.md']) {
64
+ const p = path.join(cdir, f);
65
+ if (exists(p)) parts.push(`===== ${f} =====\n${readText(p)}`);
66
+ }
67
+ const specsDir = path.join(cdir, 'specs');
68
+ if (exists(specsDir)) {
69
+ for (const f of walkFiles(specsDir).filter((x) => x.endsWith('spec.md'))) {
70
+ parts.push(`===== specs/${f} =====\n${readText(path.join(specsDir, f))}`);
71
+ }
72
+ }
73
+ return parts.join('\n\n');
74
+ }
75
+
76
+ function buildPrompt(changeId, intentText, diff, base) {
77
+ return `You are an INDEPENDENT VERIFIER for change ${changeId}. You did NOT author it.
78
+ Verify the IMPLEMENTATION satisfies the APPROVED INTENT. Be skeptical.
79
+ - Decide PASS/FAIL for every requirement / acceptance criterion and every task.
80
+ - FAIL if a requirement is unmet, a task is unchecked/unimplemented, or test evidence is missing.
81
+ Output ONLY strict JSON: {"verdict":"PASS|FAIL","summary":"...","requirements":[{"id":"...","verdict":"PASS|FAIL","evidence":"...","gaps":"..."}]}
82
+
83
+ ===== APPROVED INTENT =====
84
+ ${intentText}
85
+
86
+ ===== IMPLEMENTATION DIFF (base ${base}) =====
87
+ ${diff || '(empty diff)'}
88
+ `;
89
+ }
90
+
91
+ function extractJson(text) {
92
+ const start = text.indexOf('{');
93
+ const end = text.lastIndexOf('}');
94
+ if (start < 0 || end <= start) return null;
95
+ try { return JSON.parse(text.slice(start, end + 1)); } catch { return null; }
96
+ }
97
+
98
+ export function runVerify(changeId, opts = {}) {
99
+ const results = [];
100
+ const add = (name, status, detail) => results.push({ name, status, detail });
101
+ const branch = opts.protectedBranch ?? 'origin/main';
102
+
103
+ let repoRoot;
104
+ try {
105
+ repoRoot = requireRepo(opts);
106
+ add('repo', 'pass', repoRoot);
107
+ } catch (err) {
108
+ add('repo', 'fail', err.message);
109
+ return finish(results, DEFAULT_POLICY);
110
+ }
111
+
112
+ const policy = loadPolicy(repoRoot);
113
+ const slug = toChangeSlug(changeId);
114
+ const base = opts.base ?? branch;
115
+ const head = opts.head ?? 'HEAD';
116
+
117
+ const changedFiles = (git(['diff', '--name-only', `${base}...${head}`], repoRoot, { allowFail: true }) ?? '')
118
+ .split(/\r?\n/).filter(Boolean);
119
+ const changeOnMain = changeOnRef(repoRoot, branch, slug);
120
+ const pr = classifyPR({ changedFiles, changeOnMain, policy, emergency: opts.emergency });
121
+ add('pr-type', pr.type === 'invalid' ? 'fail' : 'pass', `type=${pr.type} (${pr.reason})`);
122
+
123
+ const cdir = changeDir(repoRoot, slug);
124
+ if (!exists(cdir)) {
125
+ add('change', 'fail', `change '${slug}' not found`);
126
+ return finish(results, policy);
127
+ }
128
+ add('change', 'pass', slug);
129
+ const { specSha, status } = meta(repoRoot, changeId);
130
+
131
+ const required = ['proposal.md', 'tasks.md'];
132
+ const missing = required.filter((f) => !exists(path.join(cdir, f)));
133
+ const specFiles = exists(path.join(cdir, 'specs'))
134
+ ? walkFiles(path.join(cdir, 'specs')).filter((f) => f.endsWith('spec.md')) : [];
135
+ if (missing.length === 0 && specFiles.length > 0) add('artifacts', 'pass', 'proposal, tasks, spec delta present');
136
+ else add('artifacts', 'fail', [...missing.map((f) => `${f} missing`), ...(specFiles.length === 0 ? ['no spec delta'] : [])].join('; '));
137
+
138
+ const lockedPaths = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
139
+ const approvedSha = lastCommitTouching(repoRoot, branch, lockedPaths);
140
+ if (!approvedSha) add('approved-spec', 'fail', `no commit on locked paths is merged into ${branch} (not approved)`);
141
+ else if (specSha && specSha !== approvedSha) add('approved-spec', 'fail', `declared specSha ${specSha.slice(0, 8)} != approved commit ${approvedSha.slice(0, 8)}`);
142
+ else add('approved-spec', 'pass', `approved commit ${approvedSha.slice(0, 8)} on ${branch}`);
143
+
144
+ // Lightweight tamper guard: in an implementation PR, locked spec files MUST NOT be modified
145
+ const lockedModified = changedFiles.filter((f) => matchesAny(f, policy?.locked_paths ?? DEFAULT_POLICY.locked_paths));
146
+ if (pr.type === 'impl' && lockedModified.length > 0) {
147
+ add('spec-tamper', 'fail', `${lockedModified.length} locked spec file(s) modified in implementation PR (${lockedModified.join(', ')})`);
148
+ } else {
149
+ add('spec-tamper', 'pass', 'locked spec paths unmodified');
150
+ }
151
+
152
+ add('flow-state', status === 'ready_for_impl' ? 'pass' : 'fail',
153
+ status === 'ready_for_impl' ? 'READY_FOR_IMPL' : `status is ${status ?? 'unset'} (run: asdlc approve ${changeId})`);
154
+
155
+ const tasksPath = path.join(cdir, 'tasks.md');
156
+ const unchecked = exists(tasksPath) ? countUncheckedTasks(readText(tasksPath)) : Infinity;
157
+ add('tasks-complete', unchecked === 0 ? 'pass' : 'fail',
158
+ unchecked === 0 ? 'all tasks checked' : (Number.isFinite(unchecked) ? `${unchecked} unchecked task(s)` : 'tasks.md missing'));
159
+
160
+ const testDiff = checkTestPresence(changedFiles);
161
+ add('test-presence', testDiff.ok ? 'pass' : 'fail', testDiff.detail);
162
+
163
+ if (exists(tasksPath)) {
164
+ const evidence = checkTaskEvidence(readText(tasksPath));
165
+ add('tdd-evidence', evidence.ok ? 'pass' : 'fail', evidence.detail);
166
+ }
167
+
168
+ const { rules } = readLintConfig(repoRoot);
169
+ const findings = [];
170
+ for (const file of specFiles) {
171
+ for (const fnd of lintSpecText(readText(path.join(cdir, 'specs', file)), { repoRoot, rules })) findings.push({ ...fnd, file });
172
+ }
173
+ const blockers = countBlockers(findings);
174
+ add('BDD + acceptance criteria', blockers === 0 ? 'pass' : 'fail', blockers === 0 ? `${findings.length} advisory finding(s)` : `${blockers} blocker(s)`);
175
+
176
+ if (opts.skipOpenspec) {
177
+ add('openspec-validate', 'skip', '--skip-openspec');
178
+ } else {
179
+ const res = validateChange(repoRoot, { strict: true, all: true });
180
+ if (res.missing) add('openspec-validate', 'fail', 'openspec CLI not found');
181
+ else if (res.status === 0) add('openspec-validate', 'pass', 'strict validation passed');
182
+ else add('openspec-validate', 'fail', `${res.stdout}${res.stderr}`.trim().slice(0, 600));
183
+ }
184
+
185
+ const schema = checkSchema(repoRoot, { expectedVersion: readYamlConfig(repoRoot)?.schemaVersion ?? null });
186
+ add('schema-managed', schema.ok ? 'pass' : 'fail',
187
+ schema.ok ? `managed schema v${schema.installed}` : `${schema.reason}${schema.hint ? ` (${schema.hint})` : ''}`);
188
+
189
+ if (!opts.skipExternal) {
190
+ const SECRET = /TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|PRIVATE_?KEY|CREDENTIAL/i;
191
+ const cleanEnv = Object.fromEntries(Object.entries(process.env).filter(([k]) => !SECRET.test(k)));
192
+ const env = { ...cleanEnv, ASDLC_CHANGE_ID: changeId, ASDLC_REPO: opts.repo ?? '', ASDLC_SPEC_SHA: specSha ?? '' };
193
+ for (const check of readExternalChecks(repoRoot)) {
194
+ const res = runShell(check.command, repoRoot, { env });
195
+ if (res.status === 0) add(check.name, 'pass', '');
196
+ else add(check.name, 'fail', `${res.stdout}${res.stderr}`.trim().slice(0, 600) || `exit ${res.status}`);
197
+ }
198
+ }
199
+
200
+ const vcfg = readYamlConfig(repoRoot).verify ?? {};
201
+ const command = process.env.ASDLC_VERIFY_COMMAND ?? vcfg.command;
202
+ const required2 = Boolean(opts.required ?? vcfg.required ?? false);
203
+ if (!command) {
204
+ add('AI verification', required2 ? 'fail' : 'skip', required2 ? 'no verifier configured (set ASDLC_VERIFY_COMMAND)' : 'no verifier configured');
205
+ } else {
206
+ const diff = git(['diff', `${base}...${head}`], repoRoot, { allowFail: true }) ?? '';
207
+ const res = runShell(command, repoRoot, { input: buildPrompt(changeId, intent(cdir), diff, base), timeout: 900000 });
208
+ const report = extractJson(res.stdout) ?? { verdict: 'FAIL', summary: 'verifier produced no parseable JSON' };
209
+ const ok = String(report.verdict).toUpperCase() === 'PASS' && res.status === 0;
210
+ add('AI verification', ok ? 'pass' : 'fail', String(report.summary ?? '').slice(0, 300));
211
+ }
212
+
213
+ return finish(results, policy);
214
+ }
215
+
216
+ export function register(program) {
217
+ program
218
+ .command('verify <changeId>')
219
+ .description('check the implementation: artifacts + approved SHA + tasks complete + lint + validate + AI verification')
220
+ .option('--repo <name>', 'repository name')
221
+ .option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
222
+ .option('--base <ref>', 'base ref for the PR diff (default: protected branch)')
223
+ .option('--head <ref>', 'head ref (default: HEAD)')
224
+ .option('--skip-openspec', 'skip openspec validation')
225
+ .option('--skip-external', 'skip external checks from config')
226
+ .action((changeId, opts) => {
227
+ process.exitCode = runVerify(changeId, opts);
228
+ });
229
+ }
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { run, buildCli } from './cli.js';
2
+ export * from './lib/speclint.js';
3
+ export * from './lib/errors.js';
@@ -0,0 +1,73 @@
1
+ import path from 'node:path';
2
+ import { exists, readText, writeText } from './fs.js';
3
+ import { runShell } from './exec.js';
4
+ import { graphExists } from './graphify.js';
5
+
6
+ // AGENTS.md is the routing layer the agentic IDE reads. Two machine-managed
7
+ // blocks (markers): the asdlc workflow, and the system status derived from the
8
+ // graphify graph (deterministic query, not an LLM summary). Hand-written
9
+ // content elsewhere in AGENTS.md is preserved.
10
+
11
+ export const ROUTING_MARKER = '<!-- asdlc:routing -->';
12
+ export const STATUS_MARKER = '<!-- asdlc:system-status -->';
13
+
14
+ const ROUTING_BLOCK = `${ROUTING_MARKER}
15
+ ## Agentic SDLC — the 7 stages (one front door)
16
+
17
+ Everything runs through \`asdlc\` - do NOT call \`openspec ...\` directly. There is no
18
+ raw escape hatch: the wrappers ARE the guards (graph refresh, approval, checks).
19
+
20
+ 1. **new** - \`asdlc new "<requirement>"\`: scaffold the change (derives slug from intent) +
21
+ refresh the knowledge graph + write \`explore.md\` + seed \`clarifications.md\`.
22
+ ▶ **IMMEDIATE ACTION FOR AGENT**: DO NOT stop or ask permission. In the SAME interaction turn,
23
+ immediately run the **batch-grill-me** (or **grilling**) skill using the **batch-grill-me** protocol (evaluate the full frontier
24
+ in 1-2 structured batches with recommendations, looking facts up yourself) and record settled decisions
25
+ in \`clarifications.md\`.
26
+ ▶ **CRITICAL**: ONLY AFTER \`clarifications.md\` is settled may you author **proposal.md -> specs/**\`. (AI Review is handled on PR by CI).
27
+ 2. **grill** - (embedded in Stage 2) settle all design forks in \`clarifications.md\` BEFORE writing specs.
28
+ 3. **lint** - \`asdlc lint <ID>\`: artifacts + BDD/acceptance criteria. Open Spec PR via \`asdlc pr <ID> <targetBranch>\`.
29
+ 4. **approve** - human/TL approves (via PR merge, on PR, or in-place); \`asdlc approve <ID>\` records approved SHA + READY_FOR_IMPL.
30
+ 5. **apply** - \`asdlc apply <ID>\` (guard: the spec must be approved), then
31
+ \`/opsx-apply\` with task-level TDD + task-level converge.
32
+ 6. **verify** - \`asdlc verify <ID>\`: approved SHA, artifacts, tasks complete, tests, AI.
33
+ 7. **archive** - \`asdlc archive <ID>\`: sync specs to openspec/specs/ + update README.md (updates AGENTS.md only for constitutional changes).
34
+
35
+ Need orientation? \`asdlc status <ID>\` (where am I / next command) and \`asdlc doctor\`
36
+ (environment health). A bad spec is never edited: close it and \`asdlc new\` again.`;
37
+
38
+ function upsertBlock(text, marker, block) {
39
+ const idx = text.indexOf(marker);
40
+ if (idx < 0) {
41
+ const sep = text && !text.endsWith('\n') ? '\n' : '';
42
+ return `${text}${sep}${sep}${block}\n`;
43
+ }
44
+ const rest = text.slice(idx + marker.length);
45
+ const next = rest.match(/\n<!-- asdlc:/);
46
+ const end = next ? idx + marker.length + next.index : text.length;
47
+ return `${text.slice(0, idx)}${block}\n${text.slice(end)}`;
48
+ }
49
+
50
+ function systemStatusBlock(repoRoot) {
51
+ if (!graphExists(repoRoot)) return `${STATUS_MARKER}
52
+ ## System status (from the knowledge graph)
53
+
54
+ _(graph not built yet - run \`asdlc init\` or \`asdlc new <change>\`)_`;
55
+ const res = runShell('graphify god-nodes', repoRoot);
56
+ const body = (res.stdout || '').trim().split(/\r?\n/).slice(0, 15).join('\n');
57
+ return `${STATUS_MARKER}
58
+ ## System status (from the knowledge graph, generated - do not hand-edit)
59
+
60
+ ${body || '_(no nodes)_'}
61
+
62
+ _Architectural hubs = the most-connected modules. Run \`asdlc new <change>\`
63
+ to query the graph for detail._`;
64
+ }
65
+
66
+ export function refreshAgents(repoRoot, { systemStatus = true } = {}) {
67
+ const p = path.join(repoRoot, 'AGENTS.md');
68
+ let text = exists(p) ? readText(p) : '';
69
+ text = upsertBlock(text, ROUTING_MARKER, ROUTING_BLOCK);
70
+ if (systemStatus) text = upsertBlock(text, STATUS_MARKER, systemStatusBlock(repoRoot));
71
+ writeText(p, text);
72
+ return p;
73
+ }