@akjamie/agentic-sdlc 1.7.0 → 1.9.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/README.md +47 -8
- package/package.json +1 -1
- package/src/assess/ai_judge.js +30 -29
- package/src/assess/decide.js +18 -0
- package/src/assess/governance.js +83 -34
- package/src/assess/index.js +25 -11
- package/src/assess/render.js +6 -1
- package/src/assess/rules/builtin.js +1 -1
- package/src/assess/semantics.js +369 -0
- package/src/assess/vectors/v1_intent.js +13 -13
- package/src/assess/vectors/v2_security.js +19 -87
- package/src/assess/vectors/v3_topology.js +29 -44
- package/src/cli.js +3 -0
- package/src/commands/apply.js +7 -1
- package/src/commands/assess.js +2 -0
- package/src/commands/config.js +141 -0
- package/src/commands/doctor.js +15 -1
- package/src/commands/lint.js +4 -0
- package/src/commands/new.js +14 -3
- package/src/commands/pr.js +6 -1
- package/src/commands/status.js +24 -11
- package/src/commands/verify.js +11 -1
- package/src/lib/cliutil.js +3 -51
- package/src/lib/config.js +145 -0
- package/src/lib/git.js +42 -0
- package/src/lib/level.js +15 -4
- package/src/lib/risk.js +3 -1
package/src/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ import { register as registerUpgrade } from './commands/upgrade.js';
|
|
|
15
15
|
import { register as registerUpdate } from './commands/update.js';
|
|
16
16
|
import { register as registerSkills } from './commands/skills.js';
|
|
17
17
|
import { register as registerAssess } from './commands/assess.js';
|
|
18
|
+
import { register as registerConfig } from './commands/config.js';
|
|
18
19
|
import { AsdlcError } from './lib/errors.js';
|
|
19
20
|
import { log } from './lib/log.js';
|
|
20
21
|
|
|
@@ -45,6 +46,7 @@ export function buildCli() {
|
|
|
45
46
|
registerUpgrade(program); // upgrade toolchain (asdlc, openspec, graphify, schema)
|
|
46
47
|
registerSkills(program); // manage & install bundled agent skills (repo or global CI)
|
|
47
48
|
registerAssess(program); // evaluate risk & governance requirements (CI & local tool)
|
|
49
|
+
registerConfig(program); // manage machine global configuration (~/.asdlc/config.yaml)
|
|
48
50
|
|
|
49
51
|
program.addHelpText('after', `
|
|
50
52
|
The flow:
|
|
@@ -65,6 +67,7 @@ Navigation, health & maintenance:
|
|
|
65
67
|
asdlc upgrade [--global] upgrade asdlc CLI, openspec, graphify & managed schema
|
|
66
68
|
asdlc skills list list all available bundled agent skills
|
|
67
69
|
asdlc skills install --global install skills globally for CI/headless agents (opencode, pi, dsh)
|
|
70
|
+
asdlc config <set|get|list> manage global settings (~/.asdlc/config.yaml, workflow_mode)
|
|
68
71
|
|
|
69
72
|
A bad spec is not edited: close it and run \`asdlc new\` again.`);
|
|
70
73
|
return program;
|
package/src/commands/apply.js
CHANGED
|
@@ -6,6 +6,7 @@ import { lastCommitTouching, git } from '../lib/git.js';
|
|
|
6
6
|
import { fail } from '../lib/errors.js';
|
|
7
7
|
import { log } from '../lib/log.js';
|
|
8
8
|
import { isSinglePrLevel, readEffectiveLevel } from '../lib/level.js';
|
|
9
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
9
10
|
import { assess } from '../assess/index.js';
|
|
10
11
|
|
|
11
12
|
// Guard before implementing: the spec must be APPROVED on the target branch
|
|
@@ -25,12 +26,14 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
25
26
|
const tb = text.match(/^\s*targetBranch:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
26
27
|
const apr = text.match(/^\s*autoPr:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
27
28
|
const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
29
|
+
const wm = text.match(/^\s*workflowMode:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
28
30
|
meta = {
|
|
29
31
|
specSha: sha ? sha[1] : null,
|
|
30
32
|
status: status ? status[1] : null,
|
|
31
33
|
targetBranch: tb ? tb[1] : null,
|
|
32
34
|
autoPr: apr ? apr[1] : null,
|
|
33
35
|
level: lvl ? lvl[1].toUpperCase() : null,
|
|
36
|
+
workflowMode: wm ? wm[1].toLowerCase() : null,
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -39,6 +42,7 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
39
42
|
?? meta.targetBranch
|
|
40
43
|
?? resolveDefaultBranch(repoRoot);
|
|
41
44
|
|
|
45
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: branch });
|
|
42
46
|
const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
|
|
43
47
|
|
|
44
48
|
const levelInfo = readEffectiveLevel(repoRoot, slug, { baseRef: branch });
|
|
@@ -56,6 +60,7 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
56
60
|
stage: 'spec',
|
|
57
61
|
changeId: slug,
|
|
58
62
|
repoRoot,
|
|
63
|
+
mode: resolvedMode,
|
|
59
64
|
persist: true
|
|
60
65
|
});
|
|
61
66
|
const assessedLevel = assessment.risk.level;
|
|
@@ -75,7 +80,7 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
const isSinglePr = isSinglePrLevel(effectiveLevel);
|
|
83
|
+
const isSinglePr = isSinglePrLevel(effectiveLevel) && resolvedMode !== 'spec-first' && meta.workflowMode !== 'spec-first';
|
|
79
84
|
let approvedSha = null;
|
|
80
85
|
|
|
81
86
|
if (isSinglePr) {
|
|
@@ -201,6 +206,7 @@ export function register(program) {
|
|
|
201
206
|
.description('guard before implementing: the spec must be approved on the protected branch')
|
|
202
207
|
.option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
|
|
203
208
|
.option('--target-branch <ref>', 'target branch to merge into')
|
|
209
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
204
210
|
.option('--auto-pr', 'explicitly delegate authority to automatically open Implementation PR after verification passes')
|
|
205
211
|
.option('--no-auto-pr', 'disable automatic Implementation PR creation (default)')
|
|
206
212
|
.option('--repo-root <path>')
|
package/src/commands/assess.js
CHANGED
|
@@ -24,6 +24,7 @@ export function runAssessCommand(changeId, opts = {}) {
|
|
|
24
24
|
baseSha: opts.base || 'HEAD',
|
|
25
25
|
headSha: opts.head || null,
|
|
26
26
|
repoRoot,
|
|
27
|
+
mode: opts.mode,
|
|
27
28
|
persist: Boolean(slug)
|
|
28
29
|
});
|
|
29
30
|
|
|
@@ -47,6 +48,7 @@ export function register(program) {
|
|
|
47
48
|
.option('--requirement <text>', 'requirement description (for stage: new)')
|
|
48
49
|
.option('--base <ref>', 'base ref for diff (for stage: impl)', 'origin/main')
|
|
49
50
|
.option('--head <ref>', 'head ref for diff (for stage: impl)', 'HEAD')
|
|
51
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
50
52
|
.option('--json', 'output raw assessment JSON')
|
|
51
53
|
.action((changeId, opts) => {
|
|
52
54
|
const code = runAssessCommand(changeId, opts);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { loadGlobalConfig, saveGlobalConfig, validateWorkflowMode } from '../lib/config.js';
|
|
2
|
+
import { log } from '../lib/log.js';
|
|
3
|
+
|
|
4
|
+
function setNested(obj, keyPath, value) {
|
|
5
|
+
const parts = keyPath.split('.');
|
|
6
|
+
let curr = obj;
|
|
7
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
8
|
+
const p = parts[i];
|
|
9
|
+
if (!curr[p] || typeof curr[p] !== 'object') {
|
|
10
|
+
curr[p] = {};
|
|
11
|
+
}
|
|
12
|
+
curr = curr[p];
|
|
13
|
+
}
|
|
14
|
+
curr[parts[parts.length - 1]] = value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getNested(obj, keyPath) {
|
|
18
|
+
const parts = keyPath.split('.');
|
|
19
|
+
let curr = obj;
|
|
20
|
+
for (const p of parts) {
|
|
21
|
+
if (curr == null || typeof curr !== 'object') return undefined;
|
|
22
|
+
curr = curr[p];
|
|
23
|
+
}
|
|
24
|
+
return curr;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function unsetNested(obj, keyPath) {
|
|
28
|
+
const parts = keyPath.split('.');
|
|
29
|
+
let curr = obj;
|
|
30
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
31
|
+
const p = parts[i];
|
|
32
|
+
if (curr == null || typeof curr !== 'object') return;
|
|
33
|
+
curr = curr[p];
|
|
34
|
+
}
|
|
35
|
+
delete curr[parts[parts.length - 1]];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function maskSensitive(obj, showSecrets) {
|
|
39
|
+
if (showSecrets || !obj || typeof obj !== 'object') return obj;
|
|
40
|
+
const out = Array.isArray(obj) ? [] : {};
|
|
41
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
42
|
+
const isSensitive = /(?:key|token|secret|password)$/i.test(k);
|
|
43
|
+
if (isSensitive && typeof v === 'string') {
|
|
44
|
+
out[k] = '********';
|
|
45
|
+
} else if (v && typeof v === 'object') {
|
|
46
|
+
out[k] = maskSensitive(v, showSecrets);
|
|
47
|
+
} else {
|
|
48
|
+
out[k] = v;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function flattenConfig(obj, prefix = '') {
|
|
55
|
+
const entries = [];
|
|
56
|
+
if (!obj || typeof obj !== 'object') return entries;
|
|
57
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
58
|
+
const fullKey = prefix ? `${prefix}.${k}` : k;
|
|
59
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0) {
|
|
60
|
+
entries.push(...flattenConfig(v, fullKey));
|
|
61
|
+
} else {
|
|
62
|
+
entries.push([fullKey, typeof v === 'object' ? JSON.stringify(v) : String(v)]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function register(program) {
|
|
69
|
+
const configCmd = program
|
|
70
|
+
.command('config')
|
|
71
|
+
.description('manage global ~/.asdlc/config.yaml settings (workflow_mode, git hosts, agent)');
|
|
72
|
+
|
|
73
|
+
configCmd
|
|
74
|
+
.command('set <key> <value>')
|
|
75
|
+
.description('set a global configuration key (e.g. workflow_mode supervised)')
|
|
76
|
+
.action((key, value) => {
|
|
77
|
+
const cfg = loadGlobalConfig();
|
|
78
|
+
if (key === 'workflow_mode') {
|
|
79
|
+
const validated = validateWorkflowMode(value);
|
|
80
|
+
setNested(cfg, key, validated);
|
|
81
|
+
} else {
|
|
82
|
+
setNested(cfg, key, value);
|
|
83
|
+
}
|
|
84
|
+
saveGlobalConfig(cfg);
|
|
85
|
+
log.ok(`set ${key} = ${value}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
configCmd
|
|
89
|
+
.command('get <key>')
|
|
90
|
+
.description('get a global configuration key')
|
|
91
|
+
.option('--show-secrets', 'reveal masked secret value')
|
|
92
|
+
.action((key, opts) => {
|
|
93
|
+
const cfg = loadGlobalConfig();
|
|
94
|
+
const val = getNested(cfg, key);
|
|
95
|
+
if (val === undefined) {
|
|
96
|
+
log.plain('(unset)');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const isSensitiveKey = /(?:key|token|secret|password)$/i.test(key);
|
|
100
|
+
if (isSensitiveKey && !opts.showSecrets && typeof val === 'string') {
|
|
101
|
+
log.plain('********');
|
|
102
|
+
} else if (typeof val === 'object' && val !== null) {
|
|
103
|
+
const masked = maskSensitive(val, opts.showSecrets);
|
|
104
|
+
log.plain(JSON.stringify(masked, null, 2));
|
|
105
|
+
} else {
|
|
106
|
+
log.plain(String(val));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
configCmd
|
|
111
|
+
.command('unset <key>')
|
|
112
|
+
.description('remove a global configuration key')
|
|
113
|
+
.action((key) => {
|
|
114
|
+
const cfg = loadGlobalConfig();
|
|
115
|
+
unsetNested(cfg, key);
|
|
116
|
+
saveGlobalConfig(cfg);
|
|
117
|
+
log.ok(`unset ${key}`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
configCmd
|
|
121
|
+
.command('list')
|
|
122
|
+
.description('list all global configuration settings')
|
|
123
|
+
.option('--show-secrets', 'reveal masked secret values')
|
|
124
|
+
.option('--json', 'output in structured JSON')
|
|
125
|
+
.action((opts) => {
|
|
126
|
+
const cfg = loadGlobalConfig();
|
|
127
|
+
const masked = maskSensitive(cfg, opts.showSecrets);
|
|
128
|
+
if (opts.json) {
|
|
129
|
+
log.plain(JSON.stringify(masked, null, 2));
|
|
130
|
+
} else {
|
|
131
|
+
const entries = flattenConfig(masked);
|
|
132
|
+
if (entries.length === 0) {
|
|
133
|
+
log.plain('(no global configuration set)');
|
|
134
|
+
} else {
|
|
135
|
+
for (const [k, v] of entries) {
|
|
136
|
+
log.plain(`${k} = ${v}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
package/src/commands/doctor.js
CHANGED
|
@@ -9,6 +9,7 @@ import { readYaml } from '../lib/yaml.js';
|
|
|
9
9
|
import { git } from '../lib/git.js';
|
|
10
10
|
import { log, dim } from '../lib/log.js';
|
|
11
11
|
import { detectTools, checkToolHealth, installSkills, installCommands } from '../lib/tools.js';
|
|
12
|
+
import { jsonOut } from '../lib/cliutil.js';
|
|
12
13
|
|
|
13
14
|
// Environment + setup health. Exit non-zero only on a critical failure
|
|
14
15
|
// (no OpenSpec project, or the managed schema is not installed / is overridden).
|
|
@@ -94,10 +95,22 @@ export function doctor(opts = {}) {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
let failed = 0;
|
|
98
|
+
for (const r of rows) {
|
|
99
|
+
if (r.status === 'fail') failed += 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (opts.json) {
|
|
103
|
+
jsonOut({
|
|
104
|
+
ok: failed === 0,
|
|
105
|
+
failed,
|
|
106
|
+
checks: rows,
|
|
107
|
+
});
|
|
108
|
+
return failed ? 1 : 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
log.info('');
|
|
98
112
|
for (const r of rows) {
|
|
99
113
|
const badge = { pass: 'PASS', warn: 'WARN', fail: 'FAIL' }[r.status];
|
|
100
|
-
if (r.status === 'fail') failed += 1;
|
|
101
114
|
log.plain(` [${badge}] ${r.name}`);
|
|
102
115
|
if (r.detail) log.plain(` ${dim(r.detail)}`);
|
|
103
116
|
}
|
|
@@ -174,6 +187,7 @@ export function register(program) {
|
|
|
174
187
|
.description('check the environment + repo setup health (with optional --fix)')
|
|
175
188
|
.option('-g, --global', 'check global toolchain and agent skills only (for CI/headless environments)')
|
|
176
189
|
.option('--fix', 'automatically remediate fixable environment and configuration drift')
|
|
190
|
+
.option('--json', 'output machine-readable JSON')
|
|
177
191
|
.option('--repo-root <path>')
|
|
178
192
|
.action((opts) => {
|
|
179
193
|
process.exitCode = doctor(opts);
|
package/src/commands/lint.js
CHANGED
|
@@ -4,6 +4,7 @@ import { changeDir } from '../lib/paths.js';
|
|
|
4
4
|
import { requireRepo, toChangeSlug, readLintConfig, jsonOut } from '../lib/cliutil.js';
|
|
5
5
|
import { lintSpecText, countBlockers } from '../lib/speclint.js';
|
|
6
6
|
import { assess } from '../assess/index.js';
|
|
7
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
7
8
|
import { log, dim } from '../lib/log.js';
|
|
8
9
|
|
|
9
10
|
// THE spec check (v10: lint absorbed review). Deterministic:
|
|
@@ -110,10 +111,12 @@ export function runLint(changeId, opts = {}) {
|
|
|
110
111
|
}
|
|
111
112
|
const agentAssessPath = path.join(cdir, '.agent-assess.json');
|
|
112
113
|
if (currLvl || exists(agentAssessPath) || exists(path.join(cdir, 'risk-history.jsonl'))) {
|
|
114
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot });
|
|
113
115
|
const assessment = assess({
|
|
114
116
|
stage: 'spec',
|
|
115
117
|
changeId: slug,
|
|
116
118
|
repoRoot,
|
|
119
|
+
mode: resolvedMode,
|
|
117
120
|
persist: true
|
|
118
121
|
});
|
|
119
122
|
const effectiveLevel = assessment.risk.level;
|
|
@@ -157,6 +160,7 @@ export function register(program) {
|
|
|
157
160
|
.command('lint <changeId>')
|
|
158
161
|
.description('check the spec: artifacts + review record + BDD/acceptance criteria')
|
|
159
162
|
.option('--repo-root <path>')
|
|
163
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
160
164
|
.option('--json', 'stable JSON output for CI')
|
|
161
165
|
.action((changeId, opts) => {
|
|
162
166
|
process.exitCode = runLint(changeId, opts);
|
package/src/commands/new.js
CHANGED
|
@@ -9,6 +9,7 @@ import { fail } from '../lib/errors.js';
|
|
|
9
9
|
import { log } from '../lib/log.js';
|
|
10
10
|
import { Option } from 'commander';
|
|
11
11
|
import { inferInitialLevel, isSinglePrLevel } from '../lib/level.js';
|
|
12
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
12
13
|
|
|
13
14
|
// STAGE 1 of the spec (v10: explore + propose are ONE step).
|
|
14
15
|
// 1) scaffold the change through OpenSpec (derives canonical slug from requirement)
|
|
@@ -96,23 +97,32 @@ _(unavailable - graph query error)_
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
// Resolve workflow mode across precedence hierarchy (CLI > Env > Repo > Global > Default)
|
|
101
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot });
|
|
102
|
+
|
|
99
103
|
// Infer governance level (L0, L1, L2, L3) via unified assessment engine (grounded in explore.md)
|
|
100
104
|
const { level, changeType, workflowMode, reason: levelReason } = inferInitialLevel({
|
|
101
105
|
requirement,
|
|
102
106
|
explicitLevel: opts.level,
|
|
107
|
+
agentContext: opts.agentContext,
|
|
103
108
|
repoRoot,
|
|
104
|
-
changeId: slug
|
|
109
|
+
changeId: slug,
|
|
110
|
+
mode: resolvedMode
|
|
105
111
|
});
|
|
106
112
|
|
|
107
113
|
// Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
|
|
108
114
|
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
109
115
|
if (exists(metaPath)) {
|
|
110
116
|
const existing = readText(metaPath).trimEnd();
|
|
111
|
-
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
|
|
117
|
+
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\ngovernanceMode: "${resolvedMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
if (workflowMode === 'single-pr') {
|
|
115
|
-
|
|
121
|
+
if (resolvedMode === 'supervised') {
|
|
122
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Supervised Single PR mode: code & specs in one PR, human merge confirmation required]`);
|
|
123
|
+
} else {
|
|
124
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR, auto-merge eligible]`);
|
|
125
|
+
}
|
|
116
126
|
} else {
|
|
117
127
|
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
|
|
118
128
|
}
|
|
@@ -242,6 +252,7 @@ export function register(program) {
|
|
|
242
252
|
.option('--no-design', 'skip generating technical design (design.md)')
|
|
243
253
|
.option('--batch-grill', 'use batch-grill-me (present entire decision frontier in structured batches)')
|
|
244
254
|
.option('--no-grill', 'skip interactive grilling interview (self-settle decisions in clarifications.md)')
|
|
255
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
245
256
|
.addOption(new Option('--level <level>', 'internal governance level override (hidden)').hideHelp())
|
|
246
257
|
.option('--repo-root <path>')
|
|
247
258
|
.action((requirement, opts) => {
|
package/src/commands/pr.js
CHANGED
|
@@ -12,6 +12,7 @@ import { fail } from '../lib/errors.js';
|
|
|
12
12
|
import { log } from '../lib/log.js';
|
|
13
13
|
import { assess, renderLabels, renderPRComment } from '../assess/index.js';
|
|
14
14
|
import { readEffectiveLevel } from '../lib/level.js';
|
|
15
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
15
16
|
|
|
16
17
|
const SAFE_ENV_TEMPLATE_RE = /(^|\/)\.env\.(example|sample|template|defaults|schema)$/i;
|
|
17
18
|
const SENSITIVE_OR_DUMP_PATTERNS = [
|
|
@@ -173,7 +174,8 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
173
174
|
|
|
174
175
|
const lvlMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
175
176
|
const changeLevel = lvlMatch ? lvlMatch[1].toUpperCase() : null;
|
|
176
|
-
const
|
|
177
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: targetBranch });
|
|
178
|
+
const isSinglePr = (changeLevel === 'L0' || changeLevel === 'L1') && resolvedMode !== 'spec-first' && !metaText.match(/^\s*workflowMode:\s*['"]?spec-first['"]?/m);
|
|
177
179
|
|
|
178
180
|
let prType;
|
|
179
181
|
if (opts.type) {
|
|
@@ -234,6 +236,7 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
234
236
|
base: targetBranch,
|
|
235
237
|
protectedBranch: targetBranch,
|
|
236
238
|
openingPr: true,
|
|
239
|
+
mode: resolvedMode,
|
|
237
240
|
...opts,
|
|
238
241
|
});
|
|
239
242
|
if (verifyExit !== 0) {
|
|
@@ -301,6 +304,7 @@ ${proposalText}
|
|
|
301
304
|
headSha: 'HEAD',
|
|
302
305
|
changedFiles: diffFiles,
|
|
303
306
|
repoRoot,
|
|
307
|
+
mode: resolvedMode,
|
|
304
308
|
persist: false
|
|
305
309
|
});
|
|
306
310
|
const assessLabels = renderLabels(assessment);
|
|
@@ -596,6 +600,7 @@ export function register(program) {
|
|
|
596
600
|
program
|
|
597
601
|
.command('pr <changeId> <targetBranch>')
|
|
598
602
|
.description('automatically open a Spec or Implementation PR: auto-detects stage, pre-flight checks, pushes branch, and attaches labels for CI AI review')
|
|
603
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
599
604
|
.option('--repo-root <path>')
|
|
600
605
|
.action(async (changeId, targetBranch, opts) => {
|
|
601
606
|
await createPR(changeId, targetBranch, opts);
|
package/src/commands/status.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { exists, readText, walkFiles, listDir } from '../lib/fs.js';
|
|
3
3
|
import { changeDir, openspecDir, CHANGES_DIR } from '../lib/paths.js';
|
|
4
|
-
import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
|
|
4
|
+
import { requireRepo, toChangeSlug, jsonOut } from '../lib/cliutil.js';
|
|
5
5
|
import { lastCommitTouching } from '../lib/git.js';
|
|
6
6
|
import { verdictOf } from './lint.js';
|
|
7
7
|
import { countUncheckedTasks } from './verify.js';
|
|
8
8
|
import { log } from '../lib/log.js';
|
|
9
9
|
import { isSinglePrLevel } from '../lib/level.js';
|
|
10
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
10
11
|
|
|
11
12
|
// "Where am I?" for a change - a read-only view of the 7 stages from the working
|
|
12
13
|
// tree + git. Useful for humans and for an agent deciding the next command.
|
|
@@ -18,11 +19,11 @@ export function statusChange(changeId, opts = {}) {
|
|
|
18
19
|
|
|
19
20
|
if (!exists(cdir)) {
|
|
20
21
|
if (opts.json) {
|
|
21
|
-
|
|
22
|
+
jsonOut({
|
|
22
23
|
change: slug,
|
|
23
24
|
exists: false,
|
|
24
25
|
next: `asdlc new ${changeId}`
|
|
25
|
-
}
|
|
26
|
+
});
|
|
26
27
|
return 0;
|
|
27
28
|
}
|
|
28
29
|
log.plain(`change: ${slug}`);
|
|
@@ -45,29 +46,39 @@ export function statusChange(changeId, opts = {}) {
|
|
|
45
46
|
const levelMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
46
47
|
const level = levelMatch ? levelMatch[1].toUpperCase() : 'L1';
|
|
47
48
|
|
|
49
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: branch });
|
|
50
|
+
const isSinglePr = isSinglePrLevel(level) && resolvedMode !== 'spec-first' && !metaText.match(/^\s*workflowMode:\s*['"]?spec-first['"]?/m);
|
|
51
|
+
|
|
48
52
|
const stage = [
|
|
49
53
|
['1 explore (draft)', has('explore.md')],
|
|
50
54
|
['2 proposal.md', has('proposal.md')],
|
|
51
55
|
['2 spec delta', specFiles.length > 0],
|
|
52
|
-
['3 spec approved on ' + branch, Boolean(approvedSha)],
|
|
56
|
+
['3 spec approved on ' + branch, isSinglePr ? true : Boolean(approvedSha)],
|
|
53
57
|
['4 tasks complete', unchecked === 0],
|
|
54
58
|
];
|
|
55
59
|
|
|
56
60
|
let next;
|
|
57
61
|
if (!has('explore.md') && !has('proposal.md')) next = `asdlc new ${changeId}`;
|
|
58
62
|
else if (!has('proposal.md') || specFiles.length === 0) next = 'author proposal.md + specs/**';
|
|
59
|
-
else if (!approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (after independent spec review & merge, run: asdlc approve ${changeId})`;
|
|
63
|
+
else if (!isSinglePr && !approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (after independent spec review & merge, run: asdlc approve ${changeId})`;
|
|
60
64
|
else if (unchecked !== 0) next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
|
|
61
65
|
else next = `asdlc verify ${changeId}`;
|
|
62
66
|
|
|
63
67
|
if (opts.json) {
|
|
64
|
-
|
|
68
|
+
jsonOut({
|
|
65
69
|
change: slug,
|
|
66
70
|
exists: true,
|
|
67
71
|
level,
|
|
68
72
|
stage: stage.map(([name, ok]) => ({ name, ok })),
|
|
69
|
-
next
|
|
70
|
-
|
|
73
|
+
next,
|
|
74
|
+
checks: {
|
|
75
|
+
explore: has('explore.md'),
|
|
76
|
+
proposal: has('proposal.md'),
|
|
77
|
+
specs: specFiles.length,
|
|
78
|
+
approvedSha,
|
|
79
|
+
tasksComplete: unchecked === 0,
|
|
80
|
+
}
|
|
81
|
+
});
|
|
71
82
|
return 0;
|
|
72
83
|
}
|
|
73
84
|
|
|
@@ -123,7 +134,8 @@ export function statusPortfolio(opts = {}) {
|
|
|
123
134
|
const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
|
|
124
135
|
const approvedSha = lastCommitTouching(repoRoot, branch, locked);
|
|
125
136
|
const unchecked = has('tasks.md') ? countUncheckedTasks(readText(path.join(cdir, 'tasks.md'))) : null;
|
|
126
|
-
const
|
|
137
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: branch });
|
|
138
|
+
const isSinglePr = isSinglePrLevel(level) && resolvedMode !== 'spec-first' && !metaText.match(/^\s*workflowMode:\s*['"]?spec-first['"]?/m);
|
|
127
139
|
const statusMatch = metaText.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
128
140
|
const recordedStatus = statusMatch ? statusMatch[1].toLowerCase() : null;
|
|
129
141
|
|
|
@@ -186,10 +198,10 @@ export function statusPortfolio(opts = {}) {
|
|
|
186
198
|
}
|
|
187
199
|
|
|
188
200
|
if (opts.json) {
|
|
189
|
-
|
|
201
|
+
jsonOut({
|
|
190
202
|
total: active.length,
|
|
191
203
|
active
|
|
192
|
-
}
|
|
204
|
+
});
|
|
193
205
|
return 0;
|
|
194
206
|
}
|
|
195
207
|
|
|
@@ -217,6 +229,7 @@ export function register(program) {
|
|
|
217
229
|
.command('status [changeId]')
|
|
218
230
|
.description('show where a change is in the 7 stages + the next command (or portfolio overview if omitted)')
|
|
219
231
|
.option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
|
|
232
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
220
233
|
.option('--repo-root <path>')
|
|
221
234
|
.option('--json', 'output machine-readable JSON')
|
|
222
235
|
.action((changeId, opts) => {
|
package/src/commands/verify.js
CHANGED
|
@@ -12,6 +12,7 @@ import { checkSchema } from '../lib/schema.js';
|
|
|
12
12
|
import { loadPolicy, isAdvisory, DEFAULT_POLICY, matchesAny } from '../lib/policy.js';
|
|
13
13
|
import { classifyPR } from '../lib/prtype.js';
|
|
14
14
|
import { isSinglePrLevel, requiresHumanReview, readChangeLevel, readEffectiveLevel } from '../lib/level.js';
|
|
15
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
15
16
|
import { assess, renderCheckSummary, loadRiskHistory } from '../assess/index.js';
|
|
16
17
|
import { checkTestPresence, checkTaskEvidence } from '../lib/tdd.js';
|
|
17
18
|
import { runTests, parseSpecAcceptanceCriteria } from './test.js';
|
|
@@ -30,6 +31,7 @@ function meta(repoRoot, changeId) {
|
|
|
30
31
|
specSha: data.specSha ? String(data.specSha) : null,
|
|
31
32
|
status: data.status ? String(data.status) : null,
|
|
32
33
|
level: data.level ? String(data.level).toUpperCase() : null,
|
|
34
|
+
workflowMode: data.workflowMode ? String(data.workflowMode).toLowerCase() : null,
|
|
33
35
|
escalatedInImpl: data.escalatedInImpl === true || String(data.escalatedInImpl).toLowerCase() === 'true',
|
|
34
36
|
};
|
|
35
37
|
} catch {
|
|
@@ -37,11 +39,13 @@ function meta(repoRoot, changeId) {
|
|
|
37
39
|
const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
38
40
|
const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
39
41
|
const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
42
|
+
const wm = text.match(/^\s*workflowMode:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
40
43
|
const esc = text.match(/^\s*escalatedInImpl:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
41
44
|
return {
|
|
42
45
|
specSha: sha ? sha[1] : null,
|
|
43
46
|
status: status ? status[1] : null,
|
|
44
47
|
level: lvl ? lvl[1].toUpperCase() : null,
|
|
48
|
+
workflowMode: wm ? wm[1].toLowerCase() : null,
|
|
45
49
|
escalatedInImpl: esc ? esc[1].toLowerCase() === 'true' : false,
|
|
46
50
|
};
|
|
47
51
|
}
|
|
@@ -239,7 +243,11 @@ export function runVerify(changeId, opts = {}) {
|
|
|
239
243
|
preImplRecords.every((r) => isSinglePrLevel(r.risk?.level)) &&
|
|
240
244
|
history.some((r) => r.stage === 'impl' && !isSinglePrLevel(r.risk?.level)))
|
|
241
245
|
);
|
|
242
|
-
const
|
|
246
|
+
const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: base });
|
|
247
|
+
const isSinglePr = Boolean(
|
|
248
|
+
(isSinglePrLevel(changeLevel) && resolvedMode !== 'spec-first' && metaInfo.workflowMode !== 'spec-first') ||
|
|
249
|
+
escalatedOnlyInImpl
|
|
250
|
+
);
|
|
243
251
|
|
|
244
252
|
const pr = classifyPR({ changedFiles, changeOnMain, policy, emergency: opts.emergency, level: changeLevel, repoRoot, singlePr: isSinglePr });
|
|
245
253
|
add('pr-type', pr.type === 'invalid' ? 'fail' : 'pass', `type=${pr.type} (${pr.reason})`);
|
|
@@ -291,6 +299,7 @@ export function runVerify(changeId, opts = {}) {
|
|
|
291
299
|
headSha: head,
|
|
292
300
|
changedFiles,
|
|
293
301
|
repoRoot,
|
|
302
|
+
mode: resolvedMode,
|
|
294
303
|
persist: Boolean(repoRoot && changeId && exists(cdir) && !opts.openingPr && !isCI)
|
|
295
304
|
});
|
|
296
305
|
|
|
@@ -441,6 +450,7 @@ export function register(program) {
|
|
|
441
450
|
.option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
|
|
442
451
|
.option('--base <ref>', 'base ref for the PR diff (default: protected branch)')
|
|
443
452
|
.option('--head <ref>', 'head ref (default: HEAD)')
|
|
453
|
+
.option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
|
|
444
454
|
.option('--approved', 'flag indicating human lead approval is verified on PR / platform')
|
|
445
455
|
.option('--emergency', 'emergency mode bypassing standard branch checks')
|
|
446
456
|
.option('--required', 'require AI verification gate to pass')
|
package/src/lib/cliutil.js
CHANGED
|
@@ -11,51 +11,6 @@ export function toChangeSlug(changeId) {
|
|
|
11
11
|
.replace(/^-+|-+$/g, '');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Bilingual domain lexicon bridging Chinese engineering requirements to canonical English
|
|
15
|
-
// codebase symbols and readable change slugs (enabling Graphify AST queries on CJK inputs).
|
|
16
|
-
const CJK_DOMAIN_LEXICON = [
|
|
17
|
-
[/重构/, 'refactor'],
|
|
18
|
-
[/修复|排障|缺陷/, 'fix'],
|
|
19
|
-
[/清结算|清算/, 'clearing-settlement'],
|
|
20
|
-
[/支付|打款|收单/, 'payment'],
|
|
21
|
-
[/结算/, 'settlement'],
|
|
22
|
-
[/退款/, 'refund'],
|
|
23
|
-
[/账务|账本|记账|对账/, 'ledger'],
|
|
24
|
-
[/计费|账单/, 'billing'],
|
|
25
|
-
[/钱包|资金/, 'wallet'],
|
|
26
|
-
[/删表|删除.*表|清空.*表|清理历史|物理删除/, 'purge-table'],
|
|
27
|
-
[/鉴权|认证|登录态|单点登录/, 'auth'],
|
|
28
|
-
[/权限|越权|角色/, 'rbac'],
|
|
29
|
-
[/密钥|私钥|令牌|加密|脱敏/, 'secret-crypto'],
|
|
30
|
-
[/接口|出入参|协议/, 'api'],
|
|
31
|
-
[/路由|网关|控制器/, 'router'],
|
|
32
|
-
[/数据库|数据表|表结构|迁移|索引/, 'schema-db'],
|
|
33
|
-
[/订单/, 'order'],
|
|
34
|
-
[/缓存/, 'cache'],
|
|
35
|
-
[/队列|消息/, 'queue'],
|
|
36
|
-
[/配置/, 'config'],
|
|
37
|
-
[/单元测试|集成测试|测试用例/, 'test'],
|
|
38
|
-
[/文档|注释/, 'docs'],
|
|
39
|
-
[/微信/, 'wechat'],
|
|
40
|
-
[/回调|通知/, 'callback'],
|
|
41
|
-
[/状态机/, 'state-machine'],
|
|
42
|
-
[/错别字/, 'typo'],
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
function extractCjkMappedTokens(text) {
|
|
46
|
-
const raw = String(text ?? '');
|
|
47
|
-
if (!/[\u4e00-\u9fff]/.test(raw)) return [];
|
|
48
|
-
const tokens = [];
|
|
49
|
-
for (const [pattern, mapped] of CJK_DOMAIN_LEXICON) {
|
|
50
|
-
if (pattern.test(raw)) {
|
|
51
|
-
for (const part of mapped.split('-')) {
|
|
52
|
-
if (!tokens.includes(part)) tokens.push(part);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return tokens;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
14
|
export function extractRequirementTerms(text) {
|
|
60
15
|
const raw = String(text ?? '');
|
|
61
16
|
const s = raw
|
|
@@ -66,9 +21,7 @@ export function extractRequirementTerms(text) {
|
|
|
66
21
|
.replace(/[^a-z0-9\s]/g, ' ')
|
|
67
22
|
.trim();
|
|
68
23
|
const asciiWords = s.split(/\s+/).filter(Boolean);
|
|
69
|
-
|
|
70
|
-
const merged = [...new Set([...asciiWords, ...cjkWords])];
|
|
71
|
-
return merged.slice(0, 6).join(' ');
|
|
24
|
+
return [...new Set(asciiWords)].slice(0, 6).join(' ');
|
|
72
25
|
}
|
|
73
26
|
|
|
74
27
|
export function deriveChangeSlug(input, opts = {}) {
|
|
@@ -100,8 +53,7 @@ export function deriveChangeSlug(input, opts = {}) {
|
|
|
100
53
|
.split(/\s+/)
|
|
101
54
|
.filter(Boolean);
|
|
102
55
|
|
|
103
|
-
const
|
|
104
|
-
const words = [...new Set([...cjkTokens, ...asciiWords])].slice(0, 5);
|
|
56
|
+
const words = [...new Set(asciiWords)].slice(0, 5);
|
|
105
57
|
|
|
106
58
|
const keywords = words.join('-');
|
|
107
59
|
if (ticket && keywords) return `${ticket}-${keywords}`.slice(0, 40).replace(/-+$/, '');
|
|
@@ -110,7 +62,7 @@ export function deriveChangeSlug(input, opts = {}) {
|
|
|
110
62
|
const fallback = toChangeSlug(text).slice(0, 40);
|
|
111
63
|
if (fallback) return fallback;
|
|
112
64
|
|
|
113
|
-
// Non-ASCII fallback when no
|
|
65
|
+
// Non-ASCII fallback when no ASCII terms matched: generate deterministic slug from content hash
|
|
114
66
|
const hash = Math.abs(text.split('').reduce((acc, c) => ((acc << 5) - acc) + c.charCodeAt(0), 0)).toString(36);
|
|
115
67
|
return `change-${hash || Date.now().toString(36)}`;
|
|
116
68
|
}
|