@akjamie/agentic-sdlc 1.2.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.
- package/LICENSE +201 -21
- package/README.md +218 -301
- package/assets/schema/risk-assessment.schema.json +225 -0
- package/assets/skills/asdlc-apply/SKILL.md +43 -18
- package/assets/skills/asdlc-verify/SKILL.md +16 -6
- package/package.json +2 -2
- package/src/assess/ai_judge.js +163 -0
- package/src/assess/decide.js +164 -0
- package/src/assess/governance.js +53 -0
- package/src/assess/index.js +183 -0
- package/src/assess/render.js +71 -0
- package/src/assess/rules/builtin.js +195 -0
- package/src/assess/schema.js +148 -0
- package/src/assess/store.js +138 -0
- package/src/assess/vectors/v1_intent.js +80 -0
- package/src/assess/vectors/v2_security.js +131 -0
- package/src/assess/vectors/v3_topology.js +107 -0
- package/src/cli.js +91 -89
- package/src/commands/apply.js +103 -36
- package/src/commands/assess.js +57 -0
- package/src/commands/doctor.js +1 -14
- package/src/commands/init.js +0 -9
- package/src/commands/new.js +19 -2
- package/src/commands/pr.js +27 -3
- package/src/commands/upgrade.js +1 -1
- package/src/commands/verify.js +109 -15
- package/src/lib/fs.js +26 -3
- package/src/lib/level.js +118 -0
- package/src/lib/paths.js +2 -1
- package/src/lib/prtype.js +17 -4
- package/src/lib/risk.js +50 -0
- package/src/lib/schema.js +4 -0
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 {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
program
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
program
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
asdlc
|
|
52
|
-
asdlc
|
|
53
|
-
asdlc
|
|
54
|
-
asdlc
|
|
55
|
-
asdlc
|
|
56
|
-
asdlc
|
|
57
|
-
asdlc
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
asdlc
|
|
63
|
-
asdlc
|
|
64
|
-
asdlc skills
|
|
65
|
-
asdlc
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
}
|
package/src/commands/apply.js
CHANGED
|
@@ -3,9 +3,9 @@ import { exists, readText, writeText } from '../lib/fs.js';
|
|
|
3
3
|
import { changeDir } from '../lib/paths.js';
|
|
4
4
|
import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
|
|
5
5
|
import { lastCommitTouching, git } from '../lib/git.js';
|
|
6
|
-
import { readYaml } from '../lib/yaml.js';
|
|
7
6
|
import { fail } from '../lib/errors.js';
|
|
8
7
|
import { log } from '../lib/log.js';
|
|
8
|
+
import { isSinglePrLevel, readEffectiveLevel } from '../lib/level.js';
|
|
9
9
|
|
|
10
10
|
// Guard before implementing: the spec must be APPROVED on the target branch
|
|
11
11
|
// (i.e. the Spec PR has been merged into targetBranch, locking proposal.md & specs/**).
|
|
@@ -23,7 +23,15 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
23
23
|
const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
24
24
|
const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
25
25
|
const tb = text.match(/^\s*targetBranch:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
26
|
-
|
|
26
|
+
const apr = text.match(/^\s*autoPr:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
27
|
+
const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
28
|
+
meta = {
|
|
29
|
+
specSha: sha ? sha[1] : null,
|
|
30
|
+
status: status ? status[1] : null,
|
|
31
|
+
targetBranch: tb ? tb[1] : null,
|
|
32
|
+
autoPr: apr ? apr[1] : null,
|
|
33
|
+
level: lvl ? lvl[1].toUpperCase() : null,
|
|
34
|
+
};
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
const branch = opts.targetBranch
|
|
@@ -33,53 +41,102 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
33
41
|
|
|
34
42
|
const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
fail(`'${slug}' is not approved yet (no Spec PR for this change merged into ${branch})`, {
|
|
42
|
-
code: 'NOT_APPROVED',
|
|
43
|
-
hint: `open a Spec PR via \`asdlc pr ${changeId} ${branch}\` and merge it before implementing`,
|
|
44
|
+
const levelInfo = readEffectiveLevel(repoRoot, slug);
|
|
45
|
+
if (levelInfo?.tampered) {
|
|
46
|
+
fail(`cannot apply '${slug}': declared level in .openspec.yaml (${levelInfo.declaredLevel}) is lower than recorded history (${levelInfo.maxHistoryLevel}). Manual level downgrading is strictly forbidden.`, {
|
|
47
|
+
code: 'LEVEL_TAMPERED',
|
|
48
|
+
hint: 'Revert unauthorized level edits in .openspec.yaml or raise a system rule fix.'
|
|
44
49
|
});
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
fail(`cannot apply '${slug}': locked spec paths have uncommitted local modifications:\n${dirty}`, {
|
|
51
|
-
code: 'SPEC_DIRTY',
|
|
52
|
-
hint: 'commit or stash your spec modifications before proceeding with implementation',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 4. Content-level cryptographic zero-diff invariant:
|
|
57
|
-
// The local spec content MUST match the approved version on the target branch
|
|
58
|
-
const diff = (git(['diff', approvedSha, '--', ...locked], repoRoot, { allowFail: true }) ?? '').trim();
|
|
59
|
-
if (diff) {
|
|
60
|
-
fail(`'${slug}' spec differs from the approved version on ${branch} (${approvedSha.slice(0, 8)}):\n${diff.slice(0, 300)}`, {
|
|
61
|
-
code: 'SPEC_DIFFERS_FROM_APPROVED',
|
|
62
|
-
hint: `spec was modified after approval. Merge latest ${branch} or revert unauthorized spec changes.`,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
52
|
+
const effectiveLevel = levelInfo?.effectiveLevel || meta.level || null;
|
|
53
|
+
const isSinglePr = isSinglePrLevel(effectiveLevel);
|
|
54
|
+
let approvedSha = null;
|
|
65
55
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (exists(metaPath)) {
|
|
56
|
+
if (isSinglePr) {
|
|
57
|
+
// For L0 / L1, Single PR mode allows direct local implementation.
|
|
58
|
+
// Transition to ready_for_impl automatically if drafting.
|
|
59
|
+
if (meta.status !== 'ready_for_impl' && exists(metaPath)) {
|
|
70
60
|
let metaText = readText(metaPath);
|
|
71
61
|
const upsertKey = (text, key, val) => {
|
|
72
62
|
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
73
63
|
return re.test(text) ? text.replace(re, `${key}: "${val}"`) : `${text.trimEnd()}\n${key}: "${val}"\n`;
|
|
74
64
|
};
|
|
75
|
-
metaText = upsertKey(metaText, 'specSha', approvedSha);
|
|
76
65
|
metaText = upsertKey(metaText, 'status', 'ready_for_impl');
|
|
77
66
|
writeText(metaPath, metaText);
|
|
78
67
|
}
|
|
79
|
-
log.ok(`${slug}:
|
|
68
|
+
log.ok(`${slug}: governance level is ${effectiveLevel} (Single PR mode: direct local implementation permitted)`);
|
|
69
|
+
} else {
|
|
70
|
+
// L2 / L3 Two-phase Spec-first flow
|
|
71
|
+
// 2. Multi-tenant path-isolated approval detection
|
|
72
|
+
// Query ONLY commits touching this change's own directory on target branch
|
|
73
|
+
approvedSha = lastCommitTouching(repoRoot, branch, locked);
|
|
74
|
+
|
|
75
|
+
if (!approvedSha) {
|
|
76
|
+
fail(`'${slug}' is not approved yet (no Spec PR for this change merged into ${branch})`, {
|
|
77
|
+
code: 'NOT_APPROVED',
|
|
78
|
+
hint: `open a Spec PR via \`asdlc pr ${changeId} ${branch}\` and merge it before implementing`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Local working tree tamper check: locked paths must not have uncommitted edits
|
|
83
|
+
const dirty = (git(['status', '--porcelain', '--', ...locked], repoRoot, { allowFail: true }) ?? '').trim();
|
|
84
|
+
if (dirty) {
|
|
85
|
+
fail(`cannot apply '${slug}': locked spec paths have uncommitted local modifications:\n${dirty}`, {
|
|
86
|
+
code: 'SPEC_DIRTY',
|
|
87
|
+
hint: 'commit or stash your spec modifications before proceeding with implementation',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 4. Content-level cryptographic zero-diff invariant:
|
|
92
|
+
// The local spec content MUST match the approved version on the target branch
|
|
93
|
+
const diff = (git(['diff', approvedSha, '--', ...locked], repoRoot, { allowFail: true }) ?? '').trim();
|
|
94
|
+
if (diff) {
|
|
95
|
+
fail(`'${slug}' spec differs from the approved version on ${branch} (${approvedSha.slice(0, 8)}):\n${diff.slice(0, 300)}`, {
|
|
96
|
+
code: 'SPEC_DIFFERS_FROM_APPROVED',
|
|
97
|
+
hint: `spec was modified after approval. Merge latest ${branch} or revert unauthorized spec changes.`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 5. Automatic state transition: PR Merge is the single source of truth for approval!
|
|
102
|
+
// If the spec is physically merged on the target branch with 0 diff, automatically transition to ready_for_impl
|
|
103
|
+
if (meta.status !== 'ready_for_impl' || meta.specSha !== approvedSha) {
|
|
104
|
+
if (exists(metaPath)) {
|
|
105
|
+
let metaText = readText(metaPath);
|
|
106
|
+
const upsertKey = (text, key, val) => {
|
|
107
|
+
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
108
|
+
return re.test(text) ? text.replace(re, `${key}: "${val}"`) : `${text.trimEnd()}\n${key}: "${val}"\n`;
|
|
109
|
+
};
|
|
110
|
+
metaText = upsertKey(metaText, 'specSha', approvedSha);
|
|
111
|
+
metaText = upsertKey(metaText, 'status', 'ready_for_impl');
|
|
112
|
+
writeText(metaPath, metaText);
|
|
113
|
+
}
|
|
114
|
+
log.ok(`${slug}: recognized PR approval on ${branch} (synced state to ready_for_impl @ ${approvedSha.slice(0, 8)})`);
|
|
115
|
+
}
|
|
80
116
|
}
|
|
81
117
|
|
|
82
|
-
// 6.
|
|
118
|
+
// 6. Explicit Auto-PR Delegation Handling
|
|
119
|
+
if (opts.autoPr !== undefined && exists(metaPath)) {
|
|
120
|
+
let metaText = readText(metaPath);
|
|
121
|
+
const upsertKey = (text, key, val) => {
|
|
122
|
+
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
123
|
+
return re.test(text) ? text.replace(re, `${key}: ${val}`) : `${text.trimEnd()}\n${key}: ${val}\n`;
|
|
124
|
+
};
|
|
125
|
+
metaText = upsertKey(metaText, 'autoPr', opts.autoPr ? 'true' : 'false');
|
|
126
|
+
writeText(metaPath, metaText);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (opts.targetBranch && exists(metaPath)) {
|
|
130
|
+
let metaText = readText(metaPath);
|
|
131
|
+
const upsertKey = (text, key, val) => {
|
|
132
|
+
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
133
|
+
return re.test(text) ? text.replace(re, `${key}: "${val}"`) : `${text.trimEnd()}\n${key}: "${val}"\n`;
|
|
134
|
+
};
|
|
135
|
+
metaText = upsertKey(metaText, 'targetBranch', opts.targetBranch);
|
|
136
|
+
writeText(metaPath, metaText);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 7. Tasks checklist presence
|
|
83
140
|
const tasksPath = path.join(cdir, 'tasks.md');
|
|
84
141
|
if (!exists(tasksPath)) {
|
|
85
142
|
fail(`'${slug}' missing tasks.md`, {
|
|
@@ -88,7 +145,14 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
88
145
|
});
|
|
89
146
|
}
|
|
90
147
|
|
|
91
|
-
|
|
148
|
+
const isAutoPr = opts.autoPr === true || (opts.autoPr === undefined && meta.autoPr === 'true');
|
|
149
|
+
const shaDisplay = approvedSha ? ` (specSha: ${approvedSha.slice(0, 8)}, state: ready_for_impl)` : ` (state: ready_for_impl)`;
|
|
150
|
+
log.ok(`${slug} is READY FOR IMPLEMENTATION on ${branch}${shaDisplay}`);
|
|
151
|
+
if (isAutoPr) {
|
|
152
|
+
log.info(`Auto-PR delegation: ENABLED (agent is authorized to open Implementation PR once tasks & verify pass).`);
|
|
153
|
+
} else {
|
|
154
|
+
log.info(`Auto-PR delegation: DISABLED (local-only mode; run \`asdlc pr\` when ready to submit).`);
|
|
155
|
+
}
|
|
92
156
|
log.info(`Ready for implementation. Follow task-level TDD loop in tasks.md.`);
|
|
93
157
|
return 0;
|
|
94
158
|
}
|
|
@@ -107,6 +171,9 @@ export function register(program) {
|
|
|
107
171
|
.command('apply <changeId>')
|
|
108
172
|
.description('guard before implementing: the spec must be approved on the protected branch')
|
|
109
173
|
.option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
|
|
174
|
+
.option('--target-branch <ref>', 'target branch to merge into')
|
|
175
|
+
.option('--auto-pr', 'explicitly delegate authority to automatically open Implementation PR after verification passes')
|
|
176
|
+
.option('--no-auto-pr', 'disable automatic Implementation PR creation (default)')
|
|
110
177
|
.option('--repo-root <path>')
|
|
111
178
|
.action((changeId, opts) => {
|
|
112
179
|
process.exitCode = applyGuard(changeId, opts);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
|
|
2
|
+
import { git } from '../lib/git.js';
|
|
3
|
+
import { assess, renderCheckSummary, renderPRComment } from '../assess/index.js';
|
|
4
|
+
import { log } from '../lib/log.js';
|
|
5
|
+
|
|
6
|
+
export function runAssessCommand(changeId, opts = {}) {
|
|
7
|
+
const repoRoot = requireRepo(opts);
|
|
8
|
+
const slug = changeId ? toChangeSlug(changeId) : null;
|
|
9
|
+
const stage = opts.stage || 'new';
|
|
10
|
+
|
|
11
|
+
let changedFiles = [];
|
|
12
|
+
if (stage === 'impl') {
|
|
13
|
+
const base = opts.base || 'origin/main';
|
|
14
|
+
const head = opts.head || 'HEAD';
|
|
15
|
+
const diffFiles = git(['diff', '--name-only', `${base}...${head}`], repoRoot, { allowFail: true }) ?? '';
|
|
16
|
+
changedFiles = diffFiles.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result = assess({
|
|
20
|
+
stage,
|
|
21
|
+
changeId: slug,
|
|
22
|
+
requirement: opts.requirement || '',
|
|
23
|
+
changedFiles,
|
|
24
|
+
baseSha: opts.base || 'HEAD',
|
|
25
|
+
headSha: opts.head || null,
|
|
26
|
+
repoRoot,
|
|
27
|
+
persist: Boolean(slug)
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (opts.json) {
|
|
31
|
+
console.log(JSON.stringify(result, null, 2));
|
|
32
|
+
return result.verdict === 'ok' ? 0 : 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
log.info(renderCheckSummary(result));
|
|
36
|
+
if (result.transition && result.transition.direction === 'up') {
|
|
37
|
+
log.warn(`[ESCALATED] Level increased from ${result.transition.from_level} to ${result.risk.level}`);
|
|
38
|
+
}
|
|
39
|
+
return result.verdict === 'ok' ? 0 : 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function register(program) {
|
|
43
|
+
program
|
|
44
|
+
.command('assess [changeId]')
|
|
45
|
+
.description('evaluate change risk and governance requirements via unified assess engine')
|
|
46
|
+
.option('--stage <stage>', 'assessment stage: new | spec | impl', 'new')
|
|
47
|
+
.option('--requirement <text>', 'requirement description (for stage: new)')
|
|
48
|
+
.option('--base <ref>', 'base ref for diff (for stage: impl)', 'origin/main')
|
|
49
|
+
.option('--head <ref>', 'head ref for diff (for stage: impl)', 'HEAD')
|
|
50
|
+
.option('--json', 'output raw assessment JSON')
|
|
51
|
+
.action((changeId, opts) => {
|
|
52
|
+
const code = runAssessCommand(changeId, opts);
|
|
53
|
+
if (code !== 0 && !process.exitCode) {
|
|
54
|
+
process.exitCode = code;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
package/src/commands/doctor.js
CHANGED
|
@@ -52,9 +52,6 @@ export function doctor(opts = {}) {
|
|
|
52
52
|
if (exists(cfgPath)) { try { cfgSchema = (readYaml(cfgPath) ?? {}).schema ?? null; } catch { /* ignore */ } }
|
|
53
53
|
add('repo config schema', cfgSchema === 'agentic-repo-change' ? 'pass' : 'warn', cfgSchema ?? 'unset');
|
|
54
54
|
|
|
55
|
-
const policy = exists(path.join(repoRoot, '.sdlc', 'policy.yaml'));
|
|
56
|
-
add('.sdlc/policy.yaml', policy ? 'pass' : 'warn', policy ? '' : 'missing (run `asdlc init`)');
|
|
57
|
-
|
|
58
55
|
let hooksPath = null;
|
|
59
56
|
try { hooksPath = git(['config', '--get', 'core.hooksPath'], repoRoot, { allowFail: true }); } catch { /* ignore */ }
|
|
60
57
|
add('.githooks', hooksPath === '.githooks' ? 'pass' : 'warn', hooksPath === '.githooks' ? 'core.hooksPath=.githooks' : `core.hooksPath=${hooksPath ?? 'unset'}`);
|
|
@@ -98,17 +95,7 @@ export function doctor(opts = {}) {
|
|
|
98
95
|
} catch (e) { log.warn(`fix failed for .gitignore: ${e.message}`); }
|
|
99
96
|
}
|
|
100
97
|
|
|
101
|
-
// 3. .
|
|
102
|
-
if (!policy && exists(policyAssetFile)) {
|
|
103
|
-
try {
|
|
104
|
-
const pdir = path.join(repoRoot, '.sdlc');
|
|
105
|
-
ensureDir(pdir);
|
|
106
|
-
copyTree(policyAssetFile, path.join(pdir, 'policy.yaml'));
|
|
107
|
-
log.ok('fixed: created .sdlc/policy.yaml from template');
|
|
108
|
-
} catch (e) { log.warn(`fix failed for policy: ${e.message}`); }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// 4. .githooks
|
|
98
|
+
// 3. .githooks
|
|
112
99
|
if (hooksPath !== '.githooks') {
|
|
113
100
|
try {
|
|
114
101
|
if (exists(githooksAssetDir)) {
|
package/src/commands/init.js
CHANGED
|
@@ -94,15 +94,6 @@ export function initRepo(opts = {}) {
|
|
|
94
94
|
}
|
|
95
95
|
if (opts.hooks !== false) installHooks(repoRoot);
|
|
96
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
97
|
// 3.6) Pre-provision remote governance labels if git remote & gh are available
|
|
107
98
|
try {
|
|
108
99
|
ensureRemoteLabels(repoRoot);
|
package/src/commands/new.js
CHANGED
|
@@ -7,6 +7,8 @@ import { runOpenspec } from '../lib/openspec.js';
|
|
|
7
7
|
import { runShell } from '../lib/exec.js';
|
|
8
8
|
import { fail } from '../lib/errors.js';
|
|
9
9
|
import { log } from '../lib/log.js';
|
|
10
|
+
import { Option } from 'commander';
|
|
11
|
+
import { inferInitialLevel, isSinglePrLevel } from '../lib/level.js';
|
|
10
12
|
|
|
11
13
|
// STAGE 1 of the spec (v10: explore + propose are ONE step).
|
|
12
14
|
// 1) scaffold the change through OpenSpec (derives canonical slug from requirement)
|
|
@@ -32,11 +34,25 @@ export function newChange(requirement, opts = {}) {
|
|
|
32
34
|
// Determine grill mode: 'none' (--no-grill), 'batch' (--batch-grill), or 'interactive' (default grill-me)
|
|
33
35
|
const grillMode = opts.grill === false ? 'none' : (opts.batchGrill ? 'batch' : 'interactive');
|
|
34
36
|
|
|
35
|
-
//
|
|
37
|
+
// Infer governance level (L0, L1, L2, L3) via unified assessment engine
|
|
38
|
+
const { level, changeType, workflowMode, reason: levelReason } = inferInitialLevel({
|
|
39
|
+
requirement,
|
|
40
|
+
explicitLevel: opts.level,
|
|
41
|
+
repoRoot,
|
|
42
|
+
changeId: slug
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
|
|
36
46
|
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
37
47
|
if (exists(metaPath)) {
|
|
38
48
|
const existing = readText(metaPath).trimEnd();
|
|
39
|
-
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\n`);
|
|
49
|
+
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (workflowMode === 'single-pr') {
|
|
53
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR]`);
|
|
54
|
+
} else {
|
|
55
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
const g = ensureGraphify();
|
|
@@ -225,6 +241,7 @@ export function register(program) {
|
|
|
225
241
|
.option('--no-design', 'skip generating technical design (design.md)')
|
|
226
242
|
.option('--batch-grill', 'use batch-grill-me (present entire decision frontier in structured batches)')
|
|
227
243
|
.option('--no-grill', 'skip interactive grilling interview (self-settle decisions in clarifications.md)')
|
|
244
|
+
.addOption(new Option('--level <level>', 'internal governance level override (hidden)').hideHelp())
|
|
228
245
|
.option('--repo-root <path>')
|
|
229
246
|
.action((requirement, opts) => {
|
|
230
247
|
newChange(requirement, opts);
|
package/src/commands/pr.js
CHANGED
|
@@ -8,6 +8,8 @@ import { runLint } from './lint.js';
|
|
|
8
8
|
import { runVerify } from './verify.js';
|
|
9
9
|
import { fail } from '../lib/errors.js';
|
|
10
10
|
import { log } from '../lib/log.js';
|
|
11
|
+
import { assess, renderLabels, renderPRComment } from '../assess/index.js';
|
|
12
|
+
import { readEffectiveLevel } from '../lib/level.js';
|
|
11
13
|
|
|
12
14
|
export const ASDLC_LABELS = {
|
|
13
15
|
'asdlc:spec-review': {
|
|
@@ -88,6 +90,10 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
88
90
|
.split(/\r?\n/).filter(Boolean);
|
|
89
91
|
const hasSourceChanges = diffFiles.some((f) => !f.startsWith(`openspec/changes/${slug}/`));
|
|
90
92
|
|
|
93
|
+
const lvlMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
94
|
+
const changeLevel = lvlMatch ? lvlMatch[1].toUpperCase() : null;
|
|
95
|
+
const isSinglePr = changeLevel === 'L0' || changeLevel === 'L1';
|
|
96
|
+
|
|
91
97
|
let prType;
|
|
92
98
|
if (opts.type) {
|
|
93
99
|
prType = opts.type.toLowerCase();
|
|
@@ -96,6 +102,7 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
96
102
|
changeStatus === 'ready_for_impl' ||
|
|
97
103
|
Boolean(specSha) ||
|
|
98
104
|
currentBranch.startsWith('impl/') ||
|
|
105
|
+
(isSinglePr && hasSourceChanges) ||
|
|
99
106
|
(hasSourceChanges && (checkedCount > 0 || uncheckedCount === 0))
|
|
100
107
|
) {
|
|
101
108
|
prType = 'impl';
|
|
@@ -122,6 +129,7 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
122
129
|
repoRoot,
|
|
123
130
|
base: targetBranch,
|
|
124
131
|
protectedBranch: targetBranch,
|
|
132
|
+
openingPr: true,
|
|
125
133
|
...opts,
|
|
126
134
|
});
|
|
127
135
|
if (verifyExit !== 0) {
|
|
@@ -200,7 +208,23 @@ ${proposalText}
|
|
|
200
208
|
`;
|
|
201
209
|
}
|
|
202
210
|
|
|
203
|
-
// 6.
|
|
211
|
+
// 6. Assessment Governance & PR Metadata
|
|
212
|
+
const assessment = assess({
|
|
213
|
+
stage: isSpec ? 'spec' : 'impl',
|
|
214
|
+
changeId: slug,
|
|
215
|
+
baseSha: targetBranch,
|
|
216
|
+
headSha: 'HEAD',
|
|
217
|
+
changedFiles: diffFiles,
|
|
218
|
+
repoRoot,
|
|
219
|
+
persist: false
|
|
220
|
+
});
|
|
221
|
+
const assessLabels = renderLabels(assessment);
|
|
222
|
+
const assessComment = renderPRComment(assessment);
|
|
223
|
+
const labelsToApply = Array.from(new Set([labelPrefix, secondaryLabel, ...assessLabels]));
|
|
224
|
+
|
|
225
|
+
body = `${body}\n\n---\n\n${assessComment}\n`;
|
|
226
|
+
|
|
227
|
+
// 7. Multi-tier PR creation strategy:
|
|
204
228
|
// Tier 1: Platform CLI (gh / glab)
|
|
205
229
|
// Tier 2: Direct REST API (GITHUB_TOKEN / GITLAB_TOKEN)
|
|
206
230
|
// Tier 3: 1-click Web compare URL fallback
|
|
@@ -213,7 +237,7 @@ ${proposalText}
|
|
|
213
237
|
|
|
214
238
|
// Pre-provision governance labels on remote before PR creation (so gh pr create doesn't reject unknown labels)
|
|
215
239
|
if (remoteInfo?.isGitHub) {
|
|
216
|
-
ensureRemoteLabels(repoRoot,
|
|
240
|
+
ensureRemoteLabels(repoRoot, labelsToApply);
|
|
217
241
|
}
|
|
218
242
|
|
|
219
243
|
// Attempt Tier 1: CLI (gh)
|
|
@@ -224,7 +248,7 @@ ${proposalText}
|
|
|
224
248
|
'--body', body,
|
|
225
249
|
'--base', targetBranch,
|
|
226
250
|
'--head', currentBranch,
|
|
227
|
-
'--label',
|
|
251
|
+
'--label', labelsToApply.join(','),
|
|
228
252
|
], { cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
229
253
|
prCreated = true;
|
|
230
254
|
prUrl = out.trim();
|
package/src/commands/upgrade.js
CHANGED
|
@@ -111,7 +111,7 @@ export function upgradeSchema() {
|
|
|
111
111
|
log.warn(`schema asset directory missing at ${schemaAssetDir}`);
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
|
-
const dest = installSchema();
|
|
114
|
+
const dest = installSchema({ force: true });
|
|
115
115
|
log.ok(`refreshed schema v${builtinSchemaVersion()} -> ${dest}`);
|
|
116
116
|
return true;
|
|
117
117
|
} catch (err) {
|