@akjamie/agentic-sdlc 1.8.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/governance.js +83 -34
- package/src/assess/index.js +9 -2
- package/src/assess/render.js +6 -1
- package/src/assess/rules/builtin.js +1 -1
- 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/lint.js +4 -0
- package/src/commands/new.js +13 -3
- package/src/commands/pr.js +6 -1
- package/src/commands/status.js +9 -3
- package/src/commands/verify.js +11 -1
- package/src/lib/config.js +145 -0
- package/src/lib/level.js +14 -4
- package/src/lib/risk.js +2 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ flowchart TD
|
|
|
65
65
|
T_L0 --> SP1["Direct Implementation<br/>(Spec Delta & Code Co-Located)"]
|
|
66
66
|
T_L1 --> SP1
|
|
67
67
|
SP1 --> V_AUTO["Local asdlc verify<br/>12 Quality Gates"]
|
|
68
|
-
V_AUTO --> PR_AUTO["Single PR to main<br/>(
|
|
68
|
+
V_AUTO --> PR_AUTO["Single PR to main<br/>(Supervised Human Sign-Off / Auto-Merge in auto mode)"]
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
subgraph SPEC_FIRST ["๐ก๏ธ Spec-First Track: Dual-PR Flow"]
|
|
@@ -98,14 +98,28 @@ flowchart TD
|
|
|
98
98
|
class ESCALATE escStyle;
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
###
|
|
101
|
+
### Three-Tier Workflow Modes (`supervised` | `spec-first` | `auto`)
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
`agentic-sdlc` decouples **PR Topology** (`single-pr` vs `spec-first` Dual-PR) from **Merge Authority** (`auto_approval: enabled` vs mandatory human approval):
|
|
104
|
+
|
|
105
|
+
| Dimension | 1. `spec-first` *(Max Compliance)* | 2. `supervised` *(Default ยท Enterprise Transition)* | 3. `auto` *(Full Autonomous)* |
|
|
106
|
+
| :--- | :--- | :--- | :--- |
|
|
107
|
+
| **Target Persona** | Regulated infra, core banking, high-security repos | **Default for enterprise teams** (Single-PR speed for L0/L1, mandatory human merge) | High-maturity autonomous teams |
|
|
108
|
+
| **L0 / L1 PR Topology** | **Dual-PR** (`spec-first`) | **Single-PR** (`single-pr`) | **Single-PR** (`single-pr`) |
|
|
109
|
+
| **L2 / L3 PR Topology** | **Dual-PR** (`spec-first`) | **Dual-PR** (`spec-first`) | **Dual-PR** (`spec-first`) |
|
|
110
|
+
| **L0 / L1 Spec Approval** | `human` (via Spec PR merge) | `not-applicable` (L0) / `automatic` (L1) | `not-applicable` (L0) / `automatic` (L1) |
|
|
111
|
+
| **L0 / L1 Impl Review & Merge** | `ai+human` (`auto_approval: disabled`) | **`ai+human` (`auto_approval: disabled`)** | **`ai` (`auto_approval: enabled`, Auto-Merge)** |
|
|
112
|
+
| **L2 / L3 Impl Review & Merge** | `ai+human` (`auto_approval: disabled`) | `ai+human` (`auto_approval: disabled`) | `ai+human` (`auto_approval: disabled`) |
|
|
113
|
+
| **Monotonic Security Rank** | **Rank 3 (Strictest)** | **Rank 2 (Default Balanced)** | **Rank 1 (Most Permissive)** |
|
|
114
|
+
|
|
115
|
+
### Governance Tier Matrix (Default: `supervised`)
|
|
116
|
+
|
|
117
|
+
| Tier | Typical Scope | PR Topology | Spec-First Gate? | Implementation Review | Auto-Merge |
|
|
104
118
|
| :---: | :--- | :---: | :---: | :---: | :---: |
|
|
105
|
-
| **L0** | Test additions, fixtures, docs, typos, comments | **Single PR** | โ None |
|
|
106
|
-
| **L1** | Internal utils, CI workflows, git hooks, local refactors | **Single PR** | โ None | AI Review |
|
|
107
|
-
| **L2** | Public APIs (FastAPI/Spring/Go), schemas, shared libs | **Dual PR** |
|
|
108
|
-
| **L3** | Destructive DDL (`DROP`), auth engines, `AGENTS.md` | **Dual PR** |
|
|
119
|
+
| **L0** | Test additions, fixtures, docs, typos, comments | **Single PR** | โ None | AI Review + Human Confirmation | ๐ก๏ธ **Denied** (Lead Confirmation Required; Auto-Merge in `auto` mode) |
|
|
120
|
+
| **L1** | Internal utils, CI workflows, git hooks, local refactors | **Single PR** | โ None | AI Review + Human Confirmation | ๐ก๏ธ **Denied** (Lead Confirmation Required; Auto-Merge in `auto` mode) |
|
|
121
|
+
| **L2** | Public APIs (FastAPI/Spring/Go), schemas, shared libs | **Dual PR** | ๐ **Enforced** | AI + Human Lead | ๐ซ **Denied** (Lead Approval Required) |
|
|
122
|
+
| **L3** | Destructive DDL (`DROP`), auth engines, `AGENTS.md` | **Dual PR** | ๐ **Enforced** | AI + Human Lead | ๐ซ **Denied** (Lead Approval Required) |
|
|
109
123
|
|
|
110
124
|
---
|
|
111
125
|
|
|
@@ -206,7 +220,8 @@ asdlc verify memory-cache-helper
|
|
|
206
220
|
|
|
207
221
|
# 4. Open Single PR (co-locates spec delta and code)
|
|
208
222
|
asdlc pr memory-cache-helper main
|
|
209
|
-
# โ
|
|
223
|
+
# โ Supervised Single-PR: AI reviews automatically, human confirms merge
|
|
224
|
+
# (or auto-merges unattended when workflow_mode is set to 'auto')
|
|
210
225
|
```
|
|
211
226
|
|
|
212
227
|
### 3. Scenario B: High-Impact API Change (Level L2 ยท Dual-PR Spec-First)
|
|
@@ -236,6 +251,30 @@ asdlc pr user-auth main
|
|
|
236
251
|
# โ Mandatory Human Tech Lead approval required before trunk merge!
|
|
237
252
|
```
|
|
238
253
|
|
|
254
|
+
### 4. Global Configuration (`asdlc config`) & Mode Overrides
|
|
255
|
+
|
|
256
|
+
Manage global defaults in `~/.asdlc/config.yaml` or override them per execution:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
# Set global default workflow mode (supervised | spec-first | auto)
|
|
260
|
+
asdlc config set workflow_mode supervised
|
|
261
|
+
|
|
262
|
+
# Query global settings (secrets masked automatically)
|
|
263
|
+
asdlc config get workflow_mode
|
|
264
|
+
asdlc config list
|
|
265
|
+
asdlc config list --json
|
|
266
|
+
|
|
267
|
+
# Override mode per change or command
|
|
268
|
+
asdlc new "my change" --mode spec-first
|
|
269
|
+
asdlc apply my-change --mode auto
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Precedence hierarchy:
|
|
273
|
+
```text
|
|
274
|
+
CLI (--mode) > Env (ASDLC_WORKFLOW_MODE) > Repo (.sdlc/policy.yaml) > Global (~/.asdlc/config.yaml) > Default ('supervised')
|
|
275
|
+
```
|
|
276
|
+
*Note: Monotonic security rank (`spec-first (3) > supervised (2) > auto (1)`) fails closed if a lower-tier configuration attempts to relax a stricter repository policy.*
|
|
277
|
+
|
|
239
278
|
---
|
|
240
279
|
|
|
241
280
|
## ๐งฐ Bundled Out-of-the-Box Skills
|
package/package.json
CHANGED
package/src/assess/governance.js
CHANGED
|
@@ -1,41 +1,89 @@
|
|
|
1
|
+
import { fail } from '../lib/errors.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Derives Governance output parameters based on Level and findings (Specification ยง2.4 & ยง6.1)
|
|
5
|
+
* Supports 3 workflow modes: 'supervised' (default), 'spec-first', 'auto'.
|
|
3
6
|
*/
|
|
4
|
-
export function deriveGovernance({ level, confidence, mandatory_human_review = false } = {}) {
|
|
7
|
+
export function deriveGovernance({ level, confidence, mandatory_human_review = false, mode = 'supervised' } = {}) {
|
|
5
8
|
let workflow_mode = 'single-pr';
|
|
6
9
|
let spec_approval = 'not-applicable';
|
|
7
|
-
let implementation_review = 'ai';
|
|
8
|
-
let auto_approval = '
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
default:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
10
|
+
let implementation_review = 'ai+human';
|
|
11
|
+
let auto_approval = 'disabled';
|
|
12
|
+
|
|
13
|
+
const normMode = String(mode || 'supervised').toLowerCase().trim();
|
|
14
|
+
|
|
15
|
+
if (normMode === 'single-pr') {
|
|
16
|
+
fail("Configured mode cannot be 'single-pr'. Valid modes are: 'supervised', 'spec-first', 'auto'. Single-PR is an internal topology granted to L0/L1 changes.", {
|
|
17
|
+
code: 'INVALID_WORKFLOW_MODE',
|
|
18
|
+
hint: "Use 'supervised' (default), 'spec-first', or 'auto'."
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!['supervised', 'spec-first', 'auto'].includes(normMode)) {
|
|
23
|
+
fail(`Invalid workflow mode '${mode}'. Allowed modes: supervised, spec-first, auto`, {
|
|
24
|
+
code: 'INVALID_WORKFLOW_MODE',
|
|
25
|
+
hint: "Choose one of 'supervised', 'spec-first', 'auto'."
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (normMode === 'spec-first') {
|
|
30
|
+
// Under spec-first, all levels (L0-L3) force Dual-PR, human spec approval, and human implementation review
|
|
31
|
+
workflow_mode = 'spec-first';
|
|
32
|
+
spec_approval = 'human';
|
|
33
|
+
implementation_review = 'ai+human';
|
|
34
|
+
auto_approval = 'disabled';
|
|
35
|
+
} else if (normMode === 'supervised') {
|
|
36
|
+
// Under supervised (default): L0/L1 get Single-PR agility, but auto-merge is disabled (human review required)
|
|
37
|
+
switch (level) {
|
|
38
|
+
case 'L0':
|
|
39
|
+
workflow_mode = 'single-pr';
|
|
40
|
+
spec_approval = 'not-applicable';
|
|
41
|
+
implementation_review = 'ai+human';
|
|
42
|
+
auto_approval = 'disabled';
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case 'L1':
|
|
46
|
+
workflow_mode = 'single-pr';
|
|
47
|
+
spec_approval = 'automatic';
|
|
48
|
+
implementation_review = 'ai+human';
|
|
49
|
+
auto_approval = 'disabled';
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case 'L2':
|
|
53
|
+
case 'L3':
|
|
54
|
+
default:
|
|
55
|
+
workflow_mode = 'spec-first';
|
|
56
|
+
spec_approval = 'human';
|
|
57
|
+
implementation_review = 'ai+human';
|
|
58
|
+
auto_approval = 'disabled';
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
} else if (normMode === 'auto') {
|
|
62
|
+
// Under auto (autonomous): L0/L1 get Single-PR and AI auto-merge; L2/L3 get Dual-PR
|
|
63
|
+
switch (level) {
|
|
64
|
+
case 'L0':
|
|
65
|
+
workflow_mode = 'single-pr';
|
|
66
|
+
spec_approval = 'not-applicable';
|
|
67
|
+
implementation_review = 'ai';
|
|
68
|
+
auto_approval = 'enabled';
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'L1':
|
|
72
|
+
workflow_mode = 'single-pr';
|
|
73
|
+
spec_approval = 'automatic';
|
|
74
|
+
implementation_review = 'ai';
|
|
75
|
+
auto_approval = 'enabled';
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'L2':
|
|
79
|
+
case 'L3':
|
|
80
|
+
default:
|
|
81
|
+
workflow_mode = 'spec-first';
|
|
82
|
+
spec_approval = 'human';
|
|
83
|
+
implementation_review = 'ai+human';
|
|
84
|
+
auto_approval = 'disabled';
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
39
87
|
}
|
|
40
88
|
|
|
41
89
|
// Safety Overrides
|
|
@@ -48,6 +96,7 @@ export function deriveGovernance({ level, confidence, mandatory_human_review = f
|
|
|
48
96
|
workflow_mode,
|
|
49
97
|
spec_approval,
|
|
50
98
|
implementation_review,
|
|
51
|
-
auto_approval
|
|
99
|
+
auto_approval,
|
|
100
|
+
mode: normMode
|
|
52
101
|
};
|
|
53
102
|
}
|
package/src/assess/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { evaluateV3Topology } from './vectors/v3_topology.js';
|
|
|
8
8
|
import { batchAnalyzeFileSemantics } from './semantics.js';
|
|
9
9
|
import { decideAssessment } from './decide.js';
|
|
10
10
|
import { deriveGovernance } from './governance.js';
|
|
11
|
+
import { resolveWorkflowMode } from '../lib/config.js';
|
|
11
12
|
import { appendAssessmentRecord, loadLatestAssessment, loadInitialAssessment } from './store.js';
|
|
12
13
|
import { renderCheckSummary, renderPRComment, renderLabels } from './render.js';
|
|
13
14
|
|
|
@@ -33,9 +34,11 @@ export function assess({
|
|
|
33
34
|
actor = { type: 'system', id: 'asdlc' },
|
|
34
35
|
repoRoot = null,
|
|
35
36
|
persist = true,
|
|
36
|
-
agentContext = null
|
|
37
|
+
agentContext = null,
|
|
38
|
+
mode = null
|
|
37
39
|
} = {}) {
|
|
38
40
|
try {
|
|
41
|
+
const effectiveMode = resolveWorkflowMode({ cliMode: mode, repoRoot, baseRef });
|
|
39
42
|
const prev = previous || (repoRoot && changeId ? loadLatestAssessment(repoRoot, changeId) : null);
|
|
40
43
|
const baseRec = baseline || (repoRoot && changeId ? loadInitialAssessment(repoRoot, changeId) : null);
|
|
41
44
|
|
|
@@ -89,7 +92,8 @@ export function assess({
|
|
|
89
92
|
const governance = decision.governance || deriveGovernance({
|
|
90
93
|
level: decision.level,
|
|
91
94
|
confidence: decision.confidence,
|
|
92
|
-
mandatory_human_review: decision.mandatory_human_review
|
|
95
|
+
mandatory_human_review: decision.mandatory_human_review,
|
|
96
|
+
mode: effectiveMode
|
|
93
97
|
});
|
|
94
98
|
|
|
95
99
|
const recordData = {
|
|
@@ -154,6 +158,9 @@ export function assess({
|
|
|
154
158
|
|
|
155
159
|
return recordData;
|
|
156
160
|
} catch (err) {
|
|
161
|
+
if (err.code === 'ILLEGAL_MODE_DOWNGRADE' || err.code === 'INVALID_WORKFLOW_MODE') {
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
157
164
|
// Fallback to Global Default on unexpected exception (ยง5.5)
|
|
158
165
|
const fallbackDecision = decideAssessment({ stage, error: err, previous });
|
|
159
166
|
const fallbackRecord = {
|
package/src/assess/render.js
CHANGED
|
@@ -13,13 +13,18 @@ export function renderPRComment(record) {
|
|
|
13
13
|
const isEscalated = record.transition.direction === 'up';
|
|
14
14
|
const lvl = record.risk.level;
|
|
15
15
|
const isHumanReview = record.governance.implementation_review === 'ai+human';
|
|
16
|
+
const mode = record.governance.mode || (record.governance.workflow_mode === 'single-pr' ? 'supervised' : 'spec-first');
|
|
16
17
|
|
|
17
18
|
// Prominent Governance Level & Action Highlight Banner
|
|
18
19
|
let actionHighlight = '';
|
|
19
20
|
if (isEscalated) {
|
|
20
21
|
actionHighlight = `> โ ๏ธ **ใๆฒป็ๅจไฝ๏ผๅฎๆฝ้ถๆฎตๅ็บง ยท ๅฟ
้กปไบบๅทฅ็ปๅฎกใ**\n> ๐ฏ **ๆ็ปๆฒป็็ญ็บง**๏ผ\`${lvl}\`๏ผ็ฑ \`${record.transition.from_level || 'L1'}\` ๅๅฐๅ็บง๏ผ\n> ๐จ **ๆต่ฝฌๆง่ก**๏ผไฟๆๅ PR ๆตๆฐด็บฟ๏ผ**่ชๅจๅๅนถๅทฒๅ
ณ้ญ (Auto-Merge DENIED)**๏ผๅฟ
้กป็ฑไบบ็ฑป Lead ๅฎกๆ ธๆนๅๅๆนๅฏๅๅ
ฅใ`;
|
|
21
22
|
} else if (isHumanReview) {
|
|
22
|
-
|
|
23
|
+
if ((lvl === 'L0' || lvl === 'L1') && mode === 'supervised') {
|
|
24
|
+
actionHighlight = `> ๐ก๏ธ **ใๆฒป็ๅจไฝ๏ผๅๆงๅ PR ๆจกๅผ (Supervised) ยท ้ไบบๅทฅ็กฎ่ฎคๅๅ
ฅใ**\n> ๐ฏ **ๆ็ปๆฒป็็ญ็บง**๏ผ\`${lvl}\`\n> ๐ **ๆต่ฝฌๆง่ก**๏ผไฟ็ๅ PR ๆๆทๆต่ฝฌ๏ผ**่ชๅจๅๅนถๅทฒๅ
ณ้ญ (Auto-Merge DENIED)**๏ผAI ่ฏๅฎกๅทฒๅฎๆ๏ผ้็ฑไบบ็ฑปๅทฅ็จๅธ/Lead ็กฎ่ฎคๅๅ
ฅใ`;
|
|
25
|
+
} else {
|
|
26
|
+
actionHighlight = `> ๐ **ใๆฒป็ๅจไฝ๏ผ้ซ้ฃ้ฉๆนๅจ ยท ๅฟ
้กปไบบๅทฅ็ปๅฎกใ**\n> ๐ฏ **ๆ็ปๆฒป็็ญ็บง**๏ผ\`${lvl}\`\n> ๐จ **ๆต่ฝฌๆง่ก**๏ผ**่ชๅจๅๅนถๅทฒๅ
ณ้ญ (Auto-Merge DENIED)**๏ผๅฟ
้กป็ฑไบบ็ฑป Lead ๅฎกๆ ธๆนๅๅๆนๅฏๅๅ
ฅไธปๅนฒใ`;
|
|
27
|
+
}
|
|
23
28
|
} else {
|
|
24
29
|
actionHighlight = `> โก **ใๆฒป็ๅจไฝ๏ผไฝ้ฃ้ฉๆนๅจ ยท AI ่ชๅจๅๅ
ฅ (Auto-Merge Eligible)ใ**\n> ๐ฏ **ๆ็ปๆฒป็็ญ็บง**๏ผ\`${lvl}\`\n> ๐ **ๆต่ฝฌๆง่ก**๏ผCI ้จ็ฆไธ่ชๅจๅๆต่ฏๅ
จ็ปฟๅ๏ผ**็ณป็ปๅฐ่ชๅจ Approve ๅนถๆง่กๅๅนถ**๏ผๆ ้ไบบๅทฅๅฎกๆน้ปๆญใ`;
|
|
25
30
|
}
|
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/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,24 +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,
|
|
103
107
|
agentContext: opts.agentContext,
|
|
104
108
|
repoRoot,
|
|
105
|
-
changeId: slug
|
|
109
|
+
changeId: slug,
|
|
110
|
+
mode: resolvedMode
|
|
106
111
|
});
|
|
107
112
|
|
|
108
113
|
// Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
|
|
109
114
|
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
110
115
|
if (exists(metaPath)) {
|
|
111
116
|
const existing = readText(metaPath).trimEnd();
|
|
112
|
-
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`);
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
if (workflowMode === 'single-pr') {
|
|
116
|
-
|
|
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
|
+
}
|
|
117
126
|
} else {
|
|
118
127
|
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
|
|
119
128
|
}
|
|
@@ -243,6 +252,7 @@ export function register(program) {
|
|
|
243
252
|
.option('--no-design', 'skip generating technical design (design.md)')
|
|
244
253
|
.option('--batch-grill', 'use batch-grill-me (present entire decision frontier in structured batches)')
|
|
245
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')
|
|
246
256
|
.addOption(new Option('--level <level>', 'internal governance level override (hidden)').hideHelp())
|
|
247
257
|
.option('--repo-root <path>')
|
|
248
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
|
@@ -7,6 +7,7 @@ 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.
|
|
@@ -45,18 +46,21 @@ 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
|
|
|
@@ -130,7 +134,8 @@ export function statusPortfolio(opts = {}) {
|
|
|
130
134
|
const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
|
|
131
135
|
const approvedSha = lastCommitTouching(repoRoot, branch, locked);
|
|
132
136
|
const unchecked = has('tasks.md') ? countUncheckedTasks(readText(path.join(cdir, 'tasks.md'))) : null;
|
|
133
|
-
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);
|
|
134
139
|
const statusMatch = metaText.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
135
140
|
const recordedStatus = statusMatch ? statusMatch[1].toLowerCase() : null;
|
|
136
141
|
|
|
@@ -224,6 +229,7 @@ export function register(program) {
|
|
|
224
229
|
.command('status [changeId]')
|
|
225
230
|
.description('show where a change is in the 7 stages + the next command (or portfolio overview if omitted)')
|
|
226
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')
|
|
227
233
|
.option('--repo-root <path>')
|
|
228
234
|
.option('--json', 'output machine-readable JSON')
|
|
229
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')
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { readYaml, stringifyYaml } from './yaml.js';
|
|
5
|
+
import { loadPolicy } from './policy.js';
|
|
6
|
+
import { fail } from './errors.js';
|
|
7
|
+
|
|
8
|
+
export const GLOBAL_CONFIG_DIR = path.join(os.homedir(), '.asdlc');
|
|
9
|
+
export const GLOBAL_CONFIG_FILE = path.join(GLOBAL_CONFIG_DIR, 'config.yaml');
|
|
10
|
+
|
|
11
|
+
export const VALID_WORKFLOW_MODES = ['supervised', 'spec-first', 'auto'];
|
|
12
|
+
export const DEFAULT_WORKFLOW_MODE = 'supervised';
|
|
13
|
+
|
|
14
|
+
export const MODE_RANK = {
|
|
15
|
+
auto: 1,
|
|
16
|
+
supervised: 2,
|
|
17
|
+
'spec-first': 3
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Loads machine-level global config from ~/.asdlc/config.yaml.
|
|
22
|
+
* Returns empty object if file does not exist or fails to parse.
|
|
23
|
+
*/
|
|
24
|
+
export function loadGlobalConfig(configPath = GLOBAL_CONFIG_FILE) {
|
|
25
|
+
try {
|
|
26
|
+
if (fs.existsSync(configPath)) {
|
|
27
|
+
const parsed = readYaml(configPath);
|
|
28
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// Ignore read errors, fall back to empty config
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Writes machine-level global config to ~/.asdlc/config.yaml with 0600 permissions.
|
|
38
|
+
*/
|
|
39
|
+
export function saveGlobalConfig(config, configPath = GLOBAL_CONFIG_FILE) {
|
|
40
|
+
const dir = path.dirname(configPath);
|
|
41
|
+
if (!fs.existsSync(dir)) {
|
|
42
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
43
|
+
}
|
|
44
|
+
const text = stringifyYaml(config);
|
|
45
|
+
fs.writeFileSync(configPath, text, { encoding: 'utf8', mode: 0o600 });
|
|
46
|
+
try {
|
|
47
|
+
fs.chmodSync(configPath, 0o600);
|
|
48
|
+
} catch {
|
|
49
|
+
// Best-effort chmod on Windows platforms
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validates whether a mode string is valid.
|
|
55
|
+
* Fails closed if 'single-pr' (internal topology, not configurable mode) or unknown string.
|
|
56
|
+
*/
|
|
57
|
+
export function validateWorkflowMode(mode) {
|
|
58
|
+
if (!mode) return DEFAULT_WORKFLOW_MODE;
|
|
59
|
+
const norm = String(mode).toLowerCase().trim();
|
|
60
|
+
if (norm === 'single-pr') {
|
|
61
|
+
fail("Configured mode cannot be 'single-pr'. Valid modes are: 'supervised', 'spec-first', 'auto'. Single-PR is an internal topology granted to L0/L1 changes.", {
|
|
62
|
+
code: 'INVALID_WORKFLOW_MODE',
|
|
63
|
+
hint: "Use 'supervised' (default), 'spec-first', or 'auto'."
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!VALID_WORKFLOW_MODES.includes(norm)) {
|
|
67
|
+
fail(`Invalid workflow mode '${mode}'. Allowed modes: supervised, spec-first, auto`, {
|
|
68
|
+
code: 'INVALID_WORKFLOW_MODE',
|
|
69
|
+
hint: "Choose one of 'supervised', 'spec-first', 'auto'."
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return norm;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolves the effective workflow mode across the 5-tier precedence chain:
|
|
77
|
+
* CLI (--mode) > Env (ASDLC_WORKFLOW_MODE) > Repo (.sdlc/policy.yaml) > Global (~/.asdlc/config.yaml) > Default ('supervised')
|
|
78
|
+
*
|
|
79
|
+
* Enforces monotonic policy tightening against repo floor:
|
|
80
|
+
* If repo policy specifies a workflow_mode floor (e.g. 'supervised' or 'spec-first'),
|
|
81
|
+
* any higher-tier setting cannot downgrade security below that floor (fails with ILLEGAL_MODE_DOWNGRADE).
|
|
82
|
+
*/
|
|
83
|
+
export function resolveWorkflowMode({
|
|
84
|
+
cliMode = null,
|
|
85
|
+
envMode = null,
|
|
86
|
+
repoPolicy = null,
|
|
87
|
+
repoRoot = null,
|
|
88
|
+
globalConfig = null,
|
|
89
|
+
baseRef = null,
|
|
90
|
+
customGlobalPath = null
|
|
91
|
+
} = {}) {
|
|
92
|
+
// 1. Resolve Repo Floor
|
|
93
|
+
let repoMode = repoPolicy?.workflow_mode ?? null;
|
|
94
|
+
if (!repoMode && repoRoot) {
|
|
95
|
+
try {
|
|
96
|
+
const pol = loadPolicy(repoRoot, { baseRef });
|
|
97
|
+
if (pol?.workflow_mode) {
|
|
98
|
+
repoMode = pol.workflow_mode;
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
// ignore
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const repoFloor = repoMode ? validateWorkflowMode(repoMode) : null;
|
|
105
|
+
|
|
106
|
+
// 2. Resolve requested mode by precedence:
|
|
107
|
+
// CLI > Env > Repo > Global > Default
|
|
108
|
+
let requestedMode = null;
|
|
109
|
+
let source = null;
|
|
110
|
+
|
|
111
|
+
if (cliMode) {
|
|
112
|
+
requestedMode = validateWorkflowMode(cliMode);
|
|
113
|
+
source = 'CLI';
|
|
114
|
+
} else if (envMode || process.env.ASDLC_WORKFLOW_MODE) {
|
|
115
|
+
requestedMode = validateWorkflowMode(envMode || process.env.ASDLC_WORKFLOW_MODE);
|
|
116
|
+
source = 'Env';
|
|
117
|
+
} else if (repoFloor) {
|
|
118
|
+
requestedMode = repoFloor;
|
|
119
|
+
source = 'Repo';
|
|
120
|
+
} else {
|
|
121
|
+
const globalCfg = globalConfig || loadGlobalConfig(customGlobalPath || GLOBAL_CONFIG_FILE);
|
|
122
|
+
if (globalCfg?.workflow_mode) {
|
|
123
|
+
requestedMode = validateWorkflowMode(globalCfg.workflow_mode);
|
|
124
|
+
source = 'Global';
|
|
125
|
+
} else {
|
|
126
|
+
requestedMode = DEFAULT_WORKFLOW_MODE;
|
|
127
|
+
source = 'Default';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 3. Enforce monotonic policy tightening against Repo Floor:
|
|
132
|
+
// spec-first (3) > supervised (2) > auto (1)
|
|
133
|
+
if (repoFloor && source !== 'Repo') {
|
|
134
|
+
const requestedRank = MODE_RANK[requestedMode] ?? 0;
|
|
135
|
+
const floorRank = MODE_RANK[repoFloor] ?? 0;
|
|
136
|
+
if (requestedRank < floorRank) {
|
|
137
|
+
fail(`cannot downgrade workflow mode to '${requestedMode}': repository policy enforces '${repoFloor}' as minimum security floor`, {
|
|
138
|
+
code: 'ILLEGAL_MODE_DOWNGRADE',
|
|
139
|
+
hint: `Repository policy (.sdlc/policy.yaml) sets a minimum floor of '${repoFloor}'. You may tighten it to stricter modes, but cannot relax it.`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return requestedMode;
|
|
145
|
+
}
|
package/src/lib/level.js
CHANGED
|
@@ -4,12 +4,13 @@ import { changeDir } from './paths.js';
|
|
|
4
4
|
import { toChangeSlug } from './cliutil.js';
|
|
5
5
|
import { git } from './git.js';
|
|
6
6
|
import { assess, loadMaxHistoryLevel, loadRiskHistory } from '../assess/index.js';
|
|
7
|
+
import { deriveGovernance } from '../assess/governance.js';
|
|
7
8
|
import { RISK_LEVELS, LEVEL_RANK } from '../assess/rules/builtin.js';
|
|
8
9
|
import { fail } from './errors.js';
|
|
9
10
|
|
|
10
11
|
export const LEVELS = RISK_LEVELS;
|
|
11
12
|
|
|
12
|
-
export function inferInitialLevel({ requirement = '', explicitLevel, repoRoot, changeId, agentContext = null } = {}) {
|
|
13
|
+
export function inferInitialLevel({ requirement = '', explicitLevel, repoRoot, changeId, agentContext = null, mode = 'supervised' } = {}) {
|
|
13
14
|
// Always run assessment to establish immutable baseline in history
|
|
14
15
|
const result = assess({
|
|
15
16
|
stage: 'new',
|
|
@@ -17,6 +18,7 @@ export function inferInitialLevel({ requirement = '', explicitLevel, repoRoot, c
|
|
|
17
18
|
requirement,
|
|
18
19
|
agentContext,
|
|
19
20
|
repoRoot,
|
|
21
|
+
mode,
|
|
20
22
|
persist: Boolean(repoRoot && changeId)
|
|
21
23
|
});
|
|
22
24
|
|
|
@@ -35,6 +37,8 @@ export function inferInitialLevel({ requirement = '', explicitLevel, repoRoot, c
|
|
|
35
37
|
reason = result.reason_codes[0];
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
let finalGovernance = result.governance;
|
|
41
|
+
|
|
38
42
|
if (explicitLevel) {
|
|
39
43
|
const norm = String(explicitLevel).toUpperCase();
|
|
40
44
|
if (LEVELS[norm]) {
|
|
@@ -48,16 +52,22 @@ export function inferInitialLevel({ requirement = '', explicitLevel, repoRoot, c
|
|
|
48
52
|
}
|
|
49
53
|
finalLevel = norm;
|
|
50
54
|
reason = `explicitly specified via --level ${norm}`;
|
|
55
|
+
finalGovernance = deriveGovernance({
|
|
56
|
+
level: finalLevel,
|
|
57
|
+
confidence: result.risk.confidence,
|
|
58
|
+
mandatory_human_review: result.vectors?.v1_intent?.mandatory_human_review || result.vectors?.v2_security?.mandatory_human_review || result.vectors?.v3_topology?.mandatory_human_review,
|
|
59
|
+
mode
|
|
60
|
+
});
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
const isSpecFirst = finalLevel === 'L2' || finalLevel === 'L3';
|
|
55
64
|
return {
|
|
56
65
|
level: finalLevel,
|
|
57
66
|
changeType: result.change_type,
|
|
58
67
|
reason,
|
|
59
|
-
workflowMode:
|
|
60
|
-
implementationReview:
|
|
68
|
+
workflowMode: finalGovernance.workflow_mode,
|
|
69
|
+
implementationReview: finalGovernance.implementation_review,
|
|
70
|
+
autoApproval: finalGovernance.auto_approval,
|
|
61
71
|
assessment: result
|
|
62
72
|
};
|
|
63
73
|
}
|
package/src/lib/risk.js
CHANGED
|
@@ -6,7 +6,7 @@ export { RISK_LEVELS, LEVEL_RANK };
|
|
|
6
6
|
/**
|
|
7
7
|
* Backward-compatible adapter for legacy callers/tests, delegating to unified assess engine.
|
|
8
8
|
*/
|
|
9
|
-
export function assessRisk({ requirement = '', changedFiles = [], currentLevel = null, repoRoot = null, agentContext = null } = {}) {
|
|
9
|
+
export function assessRisk({ requirement = '', changedFiles = [], currentLevel = null, repoRoot = null, agentContext = null, mode = null } = {}) {
|
|
10
10
|
const result = assess({
|
|
11
11
|
stage: changedFiles.length > 0 ? 'impl' : 'new',
|
|
12
12
|
requirement,
|
|
@@ -15,6 +15,7 @@ export function assessRisk({ requirement = '', changedFiles = [], currentLevel =
|
|
|
15
15
|
baseline: currentLevel ? { risk: { level: currentLevel } } : null,
|
|
16
16
|
repoRoot,
|
|
17
17
|
agentContext,
|
|
18
|
+
mode,
|
|
18
19
|
persist: false
|
|
19
20
|
});
|
|
20
21
|
|