@akjamie/agentic-sdlc 1.1.0 → 1.3.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 (40) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +264 -154
  3. package/assets/schema/risk-assessment.schema.json +225 -0
  4. package/assets/schema/templates/design.md +94 -31
  5. package/assets/skills/api-design/SKILL.md +204 -0
  6. package/assets/skills/asdlc-apply/SKILL.md +43 -18
  7. package/assets/skills/asdlc-impl-review/SKILL.md +153 -47
  8. package/assets/skills/asdlc-new/SKILL.md +42 -24
  9. package/assets/skills/asdlc-verify/SKILL.md +16 -6
  10. package/assets/skills/batch-grill-me/SKILL.md +11 -7
  11. package/assets/skills/frontend-design/SKILL.md +84 -0
  12. package/assets/skills/grilling/SKILL.md +43 -17
  13. package/package.json +2 -2
  14. package/src/assess/ai_judge.js +163 -0
  15. package/src/assess/decide.js +164 -0
  16. package/src/assess/governance.js +53 -0
  17. package/src/assess/index.js +183 -0
  18. package/src/assess/render.js +71 -0
  19. package/src/assess/rules/builtin.js +195 -0
  20. package/src/assess/schema.js +148 -0
  21. package/src/assess/store.js +138 -0
  22. package/src/assess/vectors/v1_intent.js +80 -0
  23. package/src/assess/vectors/v2_security.js +131 -0
  24. package/src/assess/vectors/v3_topology.js +107 -0
  25. package/src/cli.js +91 -89
  26. package/src/commands/apply.js +103 -36
  27. package/src/commands/assess.js +57 -0
  28. package/src/commands/doctor.js +1 -14
  29. package/src/commands/init.js +0 -9
  30. package/src/commands/new.js +97 -19
  31. package/src/commands/pr.js +27 -3
  32. package/src/commands/upgrade.js +1 -1
  33. package/src/commands/verify.js +109 -15
  34. package/src/lib/agents.js +5 -4
  35. package/src/lib/fs.js +26 -3
  36. package/src/lib/level.js +118 -0
  37. package/src/lib/paths.js +2 -1
  38. package/src/lib/prtype.js +17 -4
  39. package/src/lib/risk.js +50 -0
  40. package/src/lib/schema.js +4 -0
@@ -0,0 +1,138 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import YAML from 'yaml';
4
+ import { exists, readText, writeText, ensureDir } from '../lib/fs.js';
5
+ import { changeDir } from '../lib/paths.js';
6
+ import { computeRecordHash, validateRecordSchema, validateChainInvariants } from './schema.js';
7
+
8
+ export const HISTORY_FILE = 'risk-history.jsonl';
9
+ export const SNAPSHOT_FILE = 'risk-assessment.yaml';
10
+
11
+ /**
12
+ * Loads all historical assessment records for a change.
13
+ * Enforces fail-closed chain validation on read (P1-3).
14
+ */
15
+ export function loadRiskHistory(repoRoot, changeId) {
16
+ if (!repoRoot || !changeId) return [];
17
+ const cdir = changeDir(repoRoot, changeId);
18
+ const p = path.join(cdir, HISTORY_FILE);
19
+ if (!exists(p)) return [];
20
+
21
+ const lines = readText(p).split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
22
+ const records = [];
23
+ for (const line of lines) {
24
+ try {
25
+ records.push(JSON.parse(line));
26
+ } catch {
27
+ const err = new Error(`Corrupted JSON in risk history line for ${changeId}`);
28
+ err.code = 'TAMPER_DETECTED';
29
+ throw err;
30
+ }
31
+ }
32
+
33
+ if (records.length > 0) {
34
+ const chainCheck = validateChainInvariants(records);
35
+ if (!chainCheck.valid) {
36
+ const err = new Error(`Risk history tamper detected for ${changeId}: ${chainCheck.errors.join('; ')}`);
37
+ err.code = 'TAMPER_DETECTED';
38
+ throw err;
39
+ }
40
+ }
41
+
42
+ return records;
43
+ }
44
+
45
+ /**
46
+ * Loads the latest assessment record for a change.
47
+ */
48
+ export function loadLatestAssessment(repoRoot, changeId) {
49
+ const history = loadRiskHistory(repoRoot, changeId);
50
+ return history.length > 0 ? history[history.length - 1] : null;
51
+ }
52
+
53
+ /**
54
+ * Loads the initial baseline assessment record for a change (seq: 1).
55
+ */
56
+ export function loadInitialAssessment(repoRoot, changeId) {
57
+ const history = loadRiskHistory(repoRoot, changeId);
58
+ return history.length > 0 ? history[0] : null;
59
+ }
60
+
61
+ /**
62
+ * Loads the maximum risk level recorded in history.
63
+ */
64
+ export function loadMaxHistoryLevel(repoRoot, changeId) {
65
+ const history = loadRiskHistory(repoRoot, changeId);
66
+ if (history.length === 0) return null;
67
+ const rank = { L0: 0, L1: 1, L2: 2, L3: 3 };
68
+ let maxLvl = history[0].risk?.level || 'L1';
69
+ for (const h of history) {
70
+ const lvl = h.risk?.level;
71
+ if (lvl && (rank[lvl] ?? 1) > (rank[maxLvl] ?? 1)) {
72
+ maxLvl = lvl;
73
+ }
74
+ }
75
+ return maxLvl;
76
+ }
77
+
78
+ /**
79
+ * Appends an assessment record to risk-history.jsonl and overwrites risk-assessment.yaml snapshot.
80
+ */
81
+ export function appendAssessmentRecord(repoRoot, changeId, recordData) {
82
+ const cdir = changeDir(repoRoot, changeId);
83
+ ensureDir(cdir);
84
+
85
+ const history = loadRiskHistory(repoRoot, changeId);
86
+
87
+ // Deduplicate consecutive identical stage evaluations to prevent log bloat
88
+ if (history.length > 0) {
89
+ const prev = history[history.length - 1];
90
+ if (
91
+ prev.stage === recordData.stage &&
92
+ prev.risk?.level === recordData.risk?.level &&
93
+ prev.verdict === recordData.verdict &&
94
+ JSON.stringify(prev.reason_codes || []) === JSON.stringify(recordData.reason_codes || [])
95
+ ) {
96
+ return prev;
97
+ }
98
+ }
99
+
100
+ const seq = history.length + 1;
101
+ const prev_hash = history.length > 0 ? history[history.length - 1].hash : null;
102
+
103
+ const record = {
104
+ schema_version: 1,
105
+ change_id: changeId,
106
+ seq,
107
+ prev_hash,
108
+ ...recordData
109
+ };
110
+
111
+ // Compute immutable sha256 hash
112
+ record.hash = computeRecordHash(record);
113
+
114
+ // Validate single record schema
115
+ const schemaCheck = validateRecordSchema(record);
116
+ if (!schemaCheck.valid) {
117
+ throw new Error(`Schema validation failed: ${schemaCheck.errors.join('; ')}`);
118
+ }
119
+
120
+ // Validate chain invariant
121
+ const newChain = [...history, record];
122
+ const chainCheck = validateChainInvariants(newChain);
123
+ if (!chainCheck.valid) {
124
+ throw new Error(`Chain invariant validation failed: ${chainCheck.errors.join('; ')}`);
125
+ }
126
+
127
+ // 1. Append to JSONL history atomically (P2-3)
128
+ const histPath = path.join(cdir, HISTORY_FILE);
129
+ const line = JSON.stringify(record) + '\n';
130
+ fs.appendFileSync(histPath, line, 'utf8');
131
+
132
+ // 2. Overwrite human-readable YAML snapshot
133
+ const snapPath = path.join(cdir, SNAPSHOT_FILE);
134
+ const yamlText = `# ASdlc Latest Risk Assessment Snapshot\n# Generated at: ${record.timestamp}\n# Change: ${changeId} (seq: ${record.seq})\n\n` + YAML.stringify(record);
135
+ writeText(snapPath, yamlText);
136
+
137
+ return record;
138
+ }
@@ -0,0 +1,80 @@
1
+ import { LEVEL_RANK, CANONICAL_DESTRUCTIVE_PATTERN } from '../rules/builtin.js';
2
+ import { judgeChangeSemantics } from '../ai_judge.js';
3
+
4
+ export function evaluateV1Intent({ requirement = '', specDelta = '', changedFiles = [], changeType = null } = {}) {
5
+ const req = String(requirement || '').toLowerCase();
6
+ const evidence = [];
7
+ const unresolved = [];
8
+ let level = 'L1';
9
+ let confidence = 'high';
10
+ let mandatory_human_review = false;
11
+ let no_signal = false;
12
+
13
+ // Infer Change Type if not provided
14
+ let inferredType = changeType;
15
+ if (!inferredType) {
16
+ if (/\b(doc|docs|readme|typo|format|clean|ci|workflow|action|hook|dependency|upgrade|refactor)\b/i.test(req)) {
17
+ inferredType = 'chore';
18
+ } else if (/\b(fix|bug|defect|issue|error|patch|resolve)\b/i.test(req)) {
19
+ inferredType = 'fix';
20
+ } else if (/\b(add|new|feature|capability|create)\b/i.test(req)) {
21
+ inferredType = 'feature';
22
+ } else {
23
+ inferredType = 'change';
24
+ }
25
+ }
26
+
27
+ // 1. Destructive Operations & Irreversibility (P0-1)
28
+ if (CANONICAL_DESTRUCTIVE_PATTERN.test(req)) {
29
+ level = 'L3';
30
+ mandatory_human_review = true;
31
+ evidence.push({
32
+ id: 'V1_DESTRUCTIVE_INTENT',
33
+ kind: 'task_statement',
34
+ signal: 'hard',
35
+ summary: 'Task intent indicates irreversible data destruction or purge'
36
+ });
37
+ }
38
+
39
+ // 2. AI Semantic Classification: Pure Test or Pure Doc Evaluation (L0)
40
+ // CRITICAL: A soft classifier must NEVER downgrade an already-triggered hard security signal! (P0-1)
41
+ if (!mandatory_human_review) {
42
+ const aiJudgment = judgeChangeSemantics({ requirement: req, changedFiles });
43
+ if (aiJudgment.is_pure_test) {
44
+ level = 'L0';
45
+ inferredType = 'chore';
46
+ evidence.push({
47
+ id: 'V1_AI_TEST_EVALUATION',
48
+ kind: 'scanner_result',
49
+ signal: 'soft',
50
+ summary: aiJudgment.rationale || 'AI Semantic Evaluation: Change is strictly test suites/mocks (evaluated as L0 trivial/routine)'
51
+ });
52
+ } else if (aiJudgment.is_pure_doc) {
53
+ level = 'L0';
54
+ inferredType = 'chore';
55
+ evidence.push({
56
+ id: 'V1_AI_DOC_EVALUATION',
57
+ kind: 'scanner_result',
58
+ signal: 'soft',
59
+ summary: aiJudgment.rationale || 'AI Semantic Evaluation: Intent is purely documentation, typo, or comment editing'
60
+ });
61
+ }
62
+ }
63
+
64
+ // If empty input
65
+ if (!req.trim() && changedFiles.length === 0) {
66
+ no_signal = true;
67
+ confidence = 'low';
68
+ unresolved.push('Requirement text is empty or missing');
69
+ }
70
+
71
+ return {
72
+ level,
73
+ confidence,
74
+ inferredType,
75
+ evidence,
76
+ unresolved,
77
+ mandatory_human_review,
78
+ no_signal
79
+ };
80
+ }
@@ -0,0 +1,131 @@
1
+ import path from 'node:path';
2
+ import { exists, readText } from '../../lib/fs.js';
3
+ import { HARD_RULES, isTestOrDocFile, CANONICAL_DESTRUCTIVE_PATTERN } from '../rules/builtin.js';
4
+ import { judgeChangeSemantics } from '../ai_judge.js';
5
+
6
+ export function evaluateV2Security({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
7
+ const req = String(requirement || '').toLowerCase();
8
+ const evidence = [];
9
+ const unresolved = [];
10
+ let level = 'L1';
11
+ let confidence = 'high';
12
+ let mandatory_human_review = false;
13
+ let no_signal = true;
14
+
15
+ // 1. Check Hard Rules against physical files
16
+ const securityRules = HARD_RULES.filter((r) =>
17
+ ['HARD_GOV_PLANE', 'HARD_SECURITY_CREDENTIALS', 'HARD_FINANCIAL_ASSETS', 'HARD_DESTRUCTIVE_DDL'].includes(r.id)
18
+ );
19
+
20
+ for (const rule of securityRules) {
21
+ const hits = changedFiles.filter((f) => {
22
+ // Exclude test and documentation files from security/credentials (never exclude governance plane or destructive DDL) (P1-4)
23
+ if (rule.id !== 'HARD_GOV_PLANE' && rule.id !== 'HARD_DESTRUCTIVE_DDL' && isTestOrDocFile(f)) return false;
24
+ const norm = f.replace(/\\/g, '/');
25
+ if (rule.patterns.some((p) => p.test(norm))) return true;
26
+ // Content-level or name-level DDL check for SQL files (P1-2)
27
+ if (rule.id === 'HARD_DESTRUCTIVE_DDL' && /\.(sql)$/i.test(norm)) {
28
+ if (/drop|truncate|purge|destructive/i.test(norm)) return true;
29
+ if (repoRoot) {
30
+ const fullPath = path.isAbsolute(f) ? f : path.join(repoRoot, f);
31
+ if (exists(fullPath)) {
32
+ const sqlContent = readText(fullPath);
33
+ if (CANONICAL_DESTRUCTIVE_PATTERN.test(sqlContent)) return true;
34
+ }
35
+ }
36
+ }
37
+ return false;
38
+ });
39
+
40
+ if (hits.length > 0) {
41
+ level = 'L3';
42
+ no_signal = false;
43
+ mandatory_human_review = rule.mandatory_human_review;
44
+ evidence.push({
45
+ id: `V2_${rule.id}`,
46
+ kind: 'rule_hit',
47
+ rule_id: rule.id,
48
+ signal: 'hard',
49
+ summary: `${rule.summary} (${hits.slice(0, 3).join(', ')})`,
50
+ source: hits[0]
51
+ });
52
+ }
53
+ }
54
+
55
+ // 2. Check Requirement Semantics for Security/Financial/Regulatory
56
+ const highRiskCompounds = [
57
+ 'access token', 'refresh token', 'bearer token', 'session token', 'auth token', 'security token',
58
+ 'jwt', 'oauth', 'private key', 'secret key', 'password hash', 'password encryption',
59
+ 'mfa', 'rbac', 'kms', 'pii', 'gdpr', 'tax id', 'ssn', 'payment refund', 'payment ledger',
60
+ 'refund ledger', 'clearing settlement', 'credit card'
61
+ ];
62
+
63
+ const genericSecWords = [
64
+ 'auth', 'authentication', 'password', 'credential', 'crypto',
65
+ 'payment', 'payout', 'refund', 'billing', 'ledger', 'wallet', 'clearing'
66
+ ];
67
+
68
+ let compoundHit = null;
69
+ for (const compound of highRiskCompounds) {
70
+ const re = new RegExp(`\\b${compound.replace(/-/g, '[-\\s]')}\\b`, 'i');
71
+ if (re.test(req)) {
72
+ compoundHit = compound;
73
+ break;
74
+ }
75
+ }
76
+
77
+ const matchedGenerics = [];
78
+ for (const word of genericSecWords) {
79
+ const re = new RegExp(`\\b${word}\\b`, 'i');
80
+ if (re.test(req)) {
81
+ matchedGenerics.push(word);
82
+ }
83
+ }
84
+
85
+ const aiJudgment = judgeChangeSemantics({ requirement: req, changedFiles });
86
+ const isDocOrTest = aiJudgment.is_pure_test || aiJudgment.is_pure_doc;
87
+
88
+ if (!isDocOrTest) {
89
+ if (compoundHit) {
90
+ no_signal = false;
91
+ level = 'L3';
92
+ mandatory_human_review = true;
93
+ evidence.push({
94
+ id: 'V2_SECURITY_COMPOUND_KEYWORD',
95
+ kind: 'task_statement',
96
+ signal: 'hard',
97
+ summary: `Task requirement touches critical security/regulatory compound phrase: '${compoundHit}'`
98
+ });
99
+ } else if (matchedGenerics.length >= 2) {
100
+ no_signal = false;
101
+ level = 'L3';
102
+ mandatory_human_review = true;
103
+ evidence.push({
104
+ id: 'V2_SECURITY_MULTI_KEYWORD',
105
+ kind: 'task_statement',
106
+ signal: 'soft',
107
+ summary: `Task requirement touches multiple security/financial domains: '${matchedGenerics.join(', ')}'`
108
+ });
109
+ } else if (matchedGenerics.length === 1) {
110
+ no_signal = false;
111
+ if (level === 'L1') {
112
+ level = 'L2'; // Capped at L2 for single soft generic keyword
113
+ }
114
+ evidence.push({
115
+ id: 'V2_SECURITY_SINGLE_KEYWORD',
116
+ kind: 'task_statement',
117
+ signal: 'soft',
118
+ summary: `Task requirement touches security/financial domain keyword: '${matchedGenerics[0]}'`
119
+ });
120
+ }
121
+ }
122
+
123
+ return {
124
+ level,
125
+ confidence,
126
+ evidence,
127
+ unresolved,
128
+ mandatory_human_review,
129
+ no_signal
130
+ };
131
+ }
@@ -0,0 +1,107 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { HARD_RULES, isTestOrDocFile } from '../rules/builtin.js';
4
+
5
+ export function evaluateV3Topology({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
6
+ const req = String(requirement || '').toLowerCase();
7
+ const evidence = [];
8
+ const unresolved = [];
9
+ let level = 'L1';
10
+ let confidence = 'high';
11
+ let mandatory_human_review = false;
12
+ let no_signal = true;
13
+
14
+ // 1. Check Hard Rules for Topology / Contracts / Infra
15
+ const topoRules = HARD_RULES.filter((r) =>
16
+ ['HARD_API_CONTRACT', 'HARD_DB_MIGRATION', 'HARD_SUPPLY_CHAIN'].includes(r.id)
17
+ );
18
+
19
+ const API_CONTENT_PATTERNS = [
20
+ /@(RestController|Controller|RequestMapping|GetMapping|PostMapping|PutMapping|DeleteMapping|PatchMapping)\b/,
21
+ /@(app|router)\.(get|post|put|delete|patch)\b/,
22
+ /\b(APIRouter|gin\.Default|router\.HandleFunc)\b/
23
+ ];
24
+
25
+ for (const rule of topoRules) {
26
+ const hits = changedFiles.filter((f) => {
27
+ if (isTestOrDocFile(f)) return false;
28
+ const norm = f.replace(/\\/g, '/');
29
+ if (rule.patterns.some((p) => p.test(norm))) return true;
30
+
31
+ // Content-based heuristic for API handlers in source files
32
+ if (rule.id === 'HARD_API_CONTRACT' && repoRoot && /\.(java|kt|py|go|ts|js)$/i.test(norm)) {
33
+ try {
34
+ const fullPath = path.isAbsolute(f) ? f : path.join(repoRoot, f);
35
+ if (fs.existsSync(fullPath)) {
36
+ const content = fs.readFileSync(fullPath, 'utf8');
37
+ if (API_CONTENT_PATTERNS.some((p) => p.test(content))) return true;
38
+ }
39
+ } catch { /* ignore read failure */ }
40
+ }
41
+ return false;
42
+ });
43
+
44
+ if (hits.length > 0) {
45
+ level = 'L2';
46
+ no_signal = false;
47
+ evidence.push({
48
+ id: `V3_${rule.id}`,
49
+ kind: 'rule_hit',
50
+ rule_id: rule.id,
51
+ signal: 'hard',
52
+ summary: `${rule.summary} (${hits.slice(0, 3).join(', ')})`,
53
+ source: hits[0]
54
+ });
55
+ }
56
+ }
57
+
58
+ // Check CI Tooling Rule
59
+ const ciRule = HARD_RULES.find((r) => r.id === 'HARD_CI_TOOLING');
60
+ if (ciRule) {
61
+ const ciHits = changedFiles.filter((f) => ciRule.patterns.some((p) => p.test(f.replace(/\\/g, '/'))));
62
+ if (ciHits.length > 0) {
63
+ no_signal = false;
64
+ evidence.push({
65
+ id: 'V3_HARD_CI_TOOLING',
66
+ kind: 'rule_hit',
67
+ rule_id: ciRule.id,
68
+ signal: 'hard',
69
+ summary: `${ciRule.summary} (${ciHits.slice(0, 3).join(', ')})`,
70
+ source: ciHits[0]
71
+ });
72
+ }
73
+ }
74
+
75
+ // 2. Check Requirement Semantics for Architecture / Schema / Infra
76
+ const topoKeywords = [
77
+ 'api', 'endpoint', 'openapi', 'swagger', 'grpc', 'protobuf', 'graphql', 'webhook',
78
+ 'fastapi', 'springboot', 'spring boot', 'controller', 'rest api', 'router',
79
+ 'database', 'migration', 'schema', 'db table', 'database table', 'sql table', 'ddl', 'model', 'docker', 'k8s', 'helm'
80
+ ];
81
+
82
+ for (const kw of topoKeywords) {
83
+ const re = new RegExp(`\\b${kw.replace(/-/g, '[-\\s]')}\\b`, 'i');
84
+ if (re.test(req)) {
85
+ no_signal = false;
86
+ if (level === 'L1') {
87
+ level = 'L2';
88
+ }
89
+ evidence.push({
90
+ id: 'V3_TOPOLOGY_KEYWORD',
91
+ kind: 'task_statement',
92
+ signal: 'soft',
93
+ summary: `Requirement touches cross-boundary architectural keyword: '${kw}'`
94
+ });
95
+ break;
96
+ }
97
+ }
98
+
99
+ return {
100
+ level,
101
+ confidence,
102
+ evidence,
103
+ unresolved,
104
+ mandatory_human_review,
105
+ no_signal
106
+ };
107
+ }
package/src/cli.js CHANGED
@@ -1,89 +1,91 @@
1
- import { readFileSync } from 'node:fs';
2
- import { Command } from 'commander';
3
- import { register as registerInit } from './commands/init.js';
4
- import { register as registerNew } from './commands/new.js';
5
- import { register as registerLint } from './commands/lint.js';
6
- import { register as registerPr } from './commands/pr.js';
7
- import { register as registerApprove } from './commands/approve.js';
8
- import { register as registerApply } from './commands/apply.js';
9
- import { register as registerTest } from './commands/test.js';
10
- import { register as registerVerify } from './commands/verify.js';
11
- import { register as registerArchive } from './commands/archive.js';
12
- import { register as registerStatus } from './commands/status.js';
13
- import { register as registerDoctor } from './commands/doctor.js';
14
- import { register as registerUpgrade } from './commands/upgrade.js';
15
- import { register as registerUpdate } from './commands/update.js';
16
- import { register as registerSkills } from './commands/skills.js';
17
- import { AsdlcError } from './lib/errors.js';
18
- import { log } from './lib/log.js';
19
-
20
- const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
21
-
22
- export function buildCli() {
23
- const program = new Command();
24
- program
25
- .name('asdlc')
26
- .description('Agentic SDLC - an OpenSpec + Graphify flow behind one command.')
27
- .version(pkg.version);
28
-
29
- // The 7 stages, in order.
30
- registerInit(program); // 1. set up the repo
31
- registerNew(program); // 2. start a spec (scaffold + graph refresh + explore.md)
32
- registerLint(program); // 3. check the spec
33
- registerPr(program); // 3.5 open the Spec PR automatically
34
- registerApprove(program); // 4. record approval (after the spec PR merges or in-place)
35
- registerApply(program); // 5. start implementing
36
- registerTest(program); // 5.5 run acceptance tests mapped from change specs (TDD & CI gate)
37
- registerVerify(program); // 6. check the implementation
38
- registerArchive(program); // 7. finish (sync living specs to openspec/specs/)
39
-
40
- // Navigation + health + maintenance (not stages).
41
- registerStatus(program); // where am I / what's next
42
- registerDoctor(program); // environment + setup health
43
- registerUpdate(program); // update repo state: skills, AST graph (KB) & AGENTS.md
44
- registerUpgrade(program); // upgrade toolchain (asdlc, openspec, graphify, schema)
45
- registerSkills(program); // manage & install bundled agent skills (repo or global CI)
46
-
47
- program.addHelpText('after', `
48
- The flow:
49
- asdlc init set up the repo (installs OpenSpec + Graphify, wires CI)
50
- asdlc new "<requirement>" start a spec: scaffold + refresh graph + explore.md + grilling
51
- asdlc lint <ID> check the spec (artifacts + BDD + acceptance criteria)
52
- asdlc pr <ID> <targetBranch> open the Spec PR (pushes branch + auto-creates PR via CLI or API)
53
- asdlc approve <ID> record approval (on PR / merge / in-place) + mark READY_FOR_IMPL
54
- asdlc apply <ID> guard, then /opsx-apply (task-level TDD loop)
55
- asdlc test <ID> run acceptance tests mapped from change specs (TDD & CI gate)
56
- asdlc verify <ID> check the implementation (artifacts, tasks, tests, AI)
57
- asdlc archive <ID> finish: archive change + sync living specs to openspec/specs/
58
-
59
- Navigation, health & maintenance:
60
- asdlc status <ID> where a change is in the 7 stages + the next command
61
- asdlc doctor environment + repo setup health
62
- asdlc update update repo state: skills, AST knowledge graph (KB) & AGENTS.md
63
- asdlc upgrade [--global] upgrade asdlc CLI, openspec, graphify & managed schema
64
- asdlc skills list list all available bundled agent skills
65
- asdlc skills install --global install skills globally for CI/headless agents (opencode, pi, dsh)
66
-
67
- A bad spec is not edited: close it and run \`asdlc new\` again.`);
68
- return program;
69
- }
70
-
71
- export async function run(argv = process.argv) {
72
- const program = buildCli();
73
- program.exitOverride();
74
- try {
75
- await program.parseAsync(argv);
76
- return process.exitCode ?? 0;
77
- } catch (err) {
78
- if (err?.code?.startsWith('commander.')) return err.exitCode ?? 0;
79
- if (err instanceof AsdlcError) {
80
- log.error(err.message);
81
- if (err.hint) log.info(` hint: ${err.hint}`);
82
- if (err.detail) log.info(` ${err.detail}`);
83
- return err.exitCode;
84
- }
85
- log.error(err?.message ?? String(err));
86
- if (process.env.ASDLC_DEBUG) log.error(err?.stack ?? '');
87
- return 1;
88
- }
89
- }
1
+ import { readFileSync } from 'node:fs';
2
+ import { Command } from 'commander';
3
+ import { register as registerInit } from './commands/init.js';
4
+ import { register as registerNew } from './commands/new.js';
5
+ import { register as registerLint } from './commands/lint.js';
6
+ import { register as registerPr } from './commands/pr.js';
7
+ import { register as registerApprove } from './commands/approve.js';
8
+ import { register as registerApply } from './commands/apply.js';
9
+ import { register as registerTest } from './commands/test.js';
10
+ import { register as registerVerify } from './commands/verify.js';
11
+ import { register as registerArchive } from './commands/archive.js';
12
+ import { register as registerStatus } from './commands/status.js';
13
+ import { register as registerDoctor } from './commands/doctor.js';
14
+ import { register as registerUpgrade } from './commands/upgrade.js';
15
+ import { register as registerUpdate } from './commands/update.js';
16
+ import { register as registerSkills } from './commands/skills.js';
17
+ import { register as registerAssess } from './commands/assess.js';
18
+ import { AsdlcError } from './lib/errors.js';
19
+ import { log } from './lib/log.js';
20
+
21
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
22
+
23
+ export function buildCli() {
24
+ const program = new Command();
25
+ program
26
+ .name('asdlc')
27
+ .description('Agentic SDLC - an OpenSpec + Graphify flow behind one command.')
28
+ .version(pkg.version);
29
+
30
+ // The 7 stages, in order.
31
+ registerInit(program); // 1. set up the repo
32
+ registerNew(program); // 2. start a spec (scaffold + graph refresh + explore.md)
33
+ registerLint(program); // 3. check the spec
34
+ registerPr(program); // 3.5 open the Spec PR automatically
35
+ registerApprove(program); // 4. record approval (after the spec PR merges or in-place)
36
+ registerApply(program); // 5. start implementing
37
+ registerTest(program); // 5.5 run acceptance tests mapped from change specs (TDD & CI gate)
38
+ registerVerify(program); // 6. check the implementation
39
+ registerArchive(program); // 7. finish (sync living specs to openspec/specs/)
40
+
41
+ // Navigation + health + maintenance (not stages).
42
+ registerStatus(program); // where am I / what's next
43
+ registerDoctor(program); // environment + setup health
44
+ registerUpdate(program); // update repo state: skills, AST graph (KB) & AGENTS.md
45
+ registerUpgrade(program); // upgrade toolchain (asdlc, openspec, graphify, schema)
46
+ registerSkills(program); // manage & install bundled agent skills (repo or global CI)
47
+ registerAssess(program); // evaluate risk & governance requirements (CI & local tool)
48
+
49
+ program.addHelpText('after', `
50
+ The flow:
51
+ asdlc init set up the repo (installs OpenSpec + Graphify, wires CI)
52
+ asdlc new "<requirement>" start a spec: scaffold + refresh graph + explore.md + grilling
53
+ asdlc lint <ID> check the spec (artifacts + BDD + acceptance criteria)
54
+ asdlc pr <ID> <targetBranch> open the Spec PR (pushes branch + auto-creates PR via CLI or API)
55
+ asdlc approve <ID> record approval (on PR / merge / in-place) + mark READY_FOR_IMPL
56
+ asdlc apply <ID> guard, then /opsx-apply (task-level TDD loop)
57
+ asdlc test <ID> run acceptance tests mapped from change specs (TDD & CI gate)
58
+ asdlc verify <ID> check the implementation (artifacts, tasks, tests, AI)
59
+ asdlc archive <ID> finish: archive change + sync living specs to openspec/specs/
60
+
61
+ Navigation, health & maintenance:
62
+ asdlc status <ID> where a change is in the 7 stages + the next command
63
+ asdlc doctor environment + repo setup health
64
+ asdlc update update repo state: skills, AST knowledge graph (KB) & AGENTS.md
65
+ asdlc upgrade [--global] upgrade asdlc CLI, openspec, graphify & managed schema
66
+ asdlc skills list list all available bundled agent skills
67
+ asdlc skills install --global install skills globally for CI/headless agents (opencode, pi, dsh)
68
+
69
+ A bad spec is not edited: close it and run \`asdlc new\` again.`);
70
+ return program;
71
+ }
72
+
73
+ export async function run(argv = process.argv) {
74
+ const program = buildCli();
75
+ program.exitOverride();
76
+ try {
77
+ await program.parseAsync(argv);
78
+ return process.exitCode ?? 0;
79
+ } catch (err) {
80
+ if (err?.code?.startsWith('commander.')) return err.exitCode ?? 0;
81
+ if (err instanceof AsdlcError) {
82
+ log.error(err.message);
83
+ if (err.hint) log.info(` hint: ${err.hint}`);
84
+ if (err.detail) log.info(` ${err.detail}`);
85
+ return err.exitCode;
86
+ }
87
+ log.error(err?.message ?? String(err));
88
+ if (process.env.ASDLC_DEBUG) log.error(err?.stack ?? '');
89
+ return 1;
90
+ }
91
+ }