@akjamie/agentic-sdlc 1.8.0 โ†’ 1.9.1

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 CHANGED
@@ -1,9 +1,10 @@
1
1
  # agentic-sdlc
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@akjamie/agentic-sdlc?color=6366f1&label=npm)](https://www.npmjs.com/package/@akjamie/agentic-sdlc)
4
+ [![version: v1.9.1](https://img.shields.io/badge/version-v1.9.1-6366f1.svg)](package.json)
4
5
  [![license: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-10b981.svg)](LICENSE)
5
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D20.19.0-38bdf8.svg)](https://nodejs.org/)
6
- [![tests](https://img.shields.io/badge/tests-168%20passing-10b981.svg)](#development--verification)
7
+ [![tests](https://img.shields.io/badge/tests-212%20passing-10b981.svg)](#development--verification)
7
8
  [![architecture](https://img.shields.io/badge/governance-L0--L3%20Adaptive%20Dual--Track-f59e0b.svg)](#adaptive-risk-tiered-governance-l0l3)
8
9
 
9
10
  > **The Intelligent Governance Engine for Autonomous AI Coding.**
@@ -65,7 +66,7 @@ flowchart TD
65
66
  T_L0 --> SP1["Direct Implementation<br/>(Spec Delta & Code Co-Located)"]
66
67
  T_L1 --> SP1
67
68
  SP1 --> V_AUTO["Local asdlc verify<br/>12 Quality Gates"]
68
- V_AUTO --> PR_AUTO["Single PR to main<br/>(CI + AI Review Auto-Merge)"]
69
+ V_AUTO --> PR_AUTO["Single PR to main<br/>(Supervised Human Sign-Off / Auto-Merge in auto mode)"]
69
70
  end
70
71
 
71
72
  subgraph SPEC_FIRST ["๐Ÿ›ก๏ธ Spec-First Track: Dual-PR Flow"]
@@ -98,14 +99,28 @@ flowchart TD
98
99
  class ESCALATE escStyle;
99
100
  ```
100
101
 
101
- ### Governance Tier Matrix
102
+ ### Three-Tier Workflow Modes (`supervised` | `spec-first` | `auto`)
102
103
 
103
- | Tier | Typical Scope | Workflow Mode | Spec-First Block? | Implementation Review | Auto-Merge |
104
+ `agentic-sdlc` decouples **PR Topology** (`single-pr` vs `spec-first` Dual-PR) from **Merge Authority** (`auto_approval: enabled` vs mandatory human approval):
105
+
106
+ | Dimension | 1. `spec-first` *(Max Compliance)* | 2. `supervised` *(Default ยท Enterprise Transition)* | 3. `auto` *(Full Autonomous)* |
107
+ | :--- | :--- | :--- | :--- |
108
+ | **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 |
109
+ | **L0 / L1 PR Topology** | **Dual-PR** (`spec-first`) | **Single-PR** (`single-pr`) | **Single-PR** (`single-pr`) |
110
+ | **L2 / L3 PR Topology** | **Dual-PR** (`spec-first`) | **Dual-PR** (`spec-first`) | **Dual-PR** (`spec-first`) |
111
+ | **L0 / L1 Spec Approval** | `human` (via Spec PR merge) | `not-applicable` (L0) / `automatic` (L1) | `not-applicable` (L0) / `automatic` (L1) |
112
+ | **L0 / L1 Impl Review & Merge** | `ai+human` (`auto_approval: disabled`) | **`ai+human` (`auto_approval: disabled`)** | **`ai` (`auto_approval: enabled`, Auto-Merge)** |
113
+ | **L2 / L3 Impl Review & Merge** | `ai+human` (`auto_approval: disabled`) | `ai+human` (`auto_approval: disabled`) | `ai+human` (`auto_approval: disabled`) |
114
+ | **Monotonic Security Rank** | **Rank 3 (Strictest)** | **Rank 2 (Default Balanced)** | **Rank 1 (Most Permissive)** |
115
+
116
+ ### Governance Tier Matrix (Default: `supervised`)
117
+
118
+ | Tier | Typical Scope | PR Topology | Spec-First Gate? | Implementation Review | Auto-Merge |
104
119
  | :---: | :--- | :---: | :---: | :---: | :---: |
105
- | **L0** | Test additions, fixtures, docs, typos, comments | **Single PR** | โŒ None | None (Pass) | **Enabled** (once CI passes) |
106
- | **L1** | Internal utils, CI workflows, git hooks, local refactors | **Single PR** | โŒ None | AI Review | **Enabled** (once AI passes) |
107
- | **L2** | Public APIs (FastAPI/Spring/Go), schemas, shared libs | **Dual PR** | **Enforced** | AI + Human Lead | ๐Ÿšซ **Denied** (Lead Approval required) |
108
- | **L3** | Destructive DDL (`DROP`), auth engines, `AGENTS.md` | **Dual PR** | **Enforced** | AI + Human Lead | ๐Ÿšซ **Denied** (Lead Approval required) |
120
+ | **L0** | Test additions, fixtures, docs, typos, comments | **Single PR** | โŒ None | AI Review + Human Confirmation | ๐Ÿ›ก๏ธ **Denied** (Lead Confirmation Required; Auto-Merge in `auto` mode) |
121
+ | **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) |
122
+ | **L2** | Public APIs (FastAPI/Spring/Go), schemas, shared libs | **Dual PR** | ๐Ÿ›‘ **Enforced** | AI + Human Lead | ๐Ÿšซ **Denied** (Lead Approval Required) |
123
+ | **L3** | Destructive DDL (`DROP`), auth engines, `AGENTS.md` | **Dual PR** | ๐Ÿ›‘ **Enforced** | AI + Human Lead | ๐Ÿšซ **Denied** (Lead Approval Required) |
109
124
 
110
125
  ---
111
126
 
@@ -198,7 +213,7 @@ asdlc doctor
198
213
  # 1. Start a routine change (automatically inferred as L1)
199
214
  asdlc new "add memory cache helper with TTL eviction"
200
215
 
201
- # 2. Directly implement using the task-level TDD loop (no Spec PR needed!)
216
+ # 2. Directly implement using the task-level TDD loop (no Spec PR or `asdlc approve` needed!)
202
217
  asdlc apply memory-cache-helper
203
218
 
204
219
  # 3. Verify locally against 12 quality gates
@@ -206,7 +221,8 @@ asdlc verify memory-cache-helper
206
221
 
207
222
  # 4. Open Single PR (co-locates spec delta and code)
208
223
  asdlc pr memory-cache-helper main
209
- # โ†’ Auto-merge eligible once CI & AI checks pass!
224
+ # โ†’ Supervised Single-PR: AI reviews automatically, human confirms merge
225
+ # (or auto-merges unattended when workflow_mode is set to 'auto')
210
226
  ```
211
227
 
212
228
  ### 3. Scenario B: High-Impact API Change (Level L2 ยท Dual-PR Spec-First)
@@ -236,6 +252,30 @@ asdlc pr user-auth main
236
252
  # โ†’ Mandatory Human Tech Lead approval required before trunk merge!
237
253
  ```
238
254
 
255
+ ### 4. Global Configuration (`asdlc config`) & Mode Overrides
256
+
257
+ Manage global defaults in `~/.asdlc/config.yaml` or override them per execution:
258
+
259
+ ```bash
260
+ # Set global default workflow mode (supervised | spec-first | auto)
261
+ asdlc config set workflow_mode supervised
262
+
263
+ # Query global settings (secrets masked automatically)
264
+ asdlc config get workflow_mode
265
+ asdlc config list
266
+ asdlc config list --json
267
+
268
+ # Override mode per change or command
269
+ asdlc new "my change" --mode spec-first
270
+ asdlc apply my-change --mode auto
271
+ ```
272
+
273
+ Precedence hierarchy:
274
+ ```text
275
+ CLI (--mode) > Env (ASDLC_WORKFLOW_MODE) > Repo (.sdlc/policy.yaml) > Global (~/.asdlc/config.yaml) > Default ('supervised')
276
+ ```
277
+ *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.*
278
+
239
279
  ---
240
280
 
241
281
  ## ๐Ÿงฐ Bundled Out-of-the-Box Skills
@@ -248,7 +288,7 @@ asdlc pr user-auth main
248
288
  | [`asdlc-new`](assets/skills/asdlc-new/SKILL.md) | Scaffolds change, queries AST hubs, runs conversational anti-fatigue `grill-me`. |
249
289
  | [`asdlc-lint`](assets/skills/asdlc-lint/SKILL.md) | Enforces deterministic BDD GIVEN/WHEN/THEN and R5 scenario-to-AC coverage. |
250
290
  | [`asdlc-pr`](assets/skills/asdlc-pr/SKILL.md) | Smart PR dispatcher: automatically handles Spec PR vs. Implementation PR. |
251
- | [`asdlc-approve`](assets/skills/asdlc-approve/SKILL.md) | Stamps Git `specSha` lock upon Spec PR merge. |
291
+ | [`asdlc-approve`](assets/skills/asdlc-approve/SKILL.md) | Stamps Git `specSha` lock upon Spec PR merge (Track A Dual-PR; waived for Track B Single-PR). |
252
292
  | [`asdlc-apply`](assets/skills/asdlc-apply/SKILL.md) | Strict task-level TDD engine (`Red -> Green -> Refactor -> Evidence -> Converge`). |
253
293
  | [`asdlc-verify`](assets/skills/asdlc-verify/SKILL.md) | Pre-flight audit across 12 gates (test presence, evidence, tamper guard, schema). |
254
294
  | [`asdlc-spec-review`](assets/skills/asdlc-spec-review/SKILL.md) | Independent review agent: 6-dimensional spec review before human lead approval. |
@@ -310,7 +350,7 @@ asdlc init # Scaffold repository with OpenSpec, Graphify
310
350
  asdlc new "<intent>" # Scaffold change with AST explore + grill-me interview
311
351
  asdlc lint <ID> # Validate BDD scenarios, AC rules, and coverage (docs/spec-format.md)
312
352
  asdlc pr <ID> <target-branch> # Smart PR creator (auto-handles Spec PR vs Impl PR + smart staging)
313
- asdlc approve <ID> # Record approvedSha and transition to ready_for_impl
353
+ asdlc approve <ID> # Record approvedSha & ready_for_impl (Track A; idempotent no-op in Single-PR)
314
354
  asdlc apply <ID> # Guarded implementation launcher (checks approvedSha)
315
355
  asdlc test <ID> [--json] # Execute real test runners mapped to AC annotations
316
356
  asdlc verify <ID> # Audit diff against all 12 quality gates
@@ -331,7 +371,7 @@ git clone https://github.com/akjamie/agentic-sdlc.git
331
371
  cd agentic-sdlc
332
372
  npm install
333
373
 
334
- # Run complete test suite (168 tests passing, 100% pass rate)
374
+ # Run complete test suite (212 tests passing, 100% pass rate)
335
375
  npm test
336
376
 
337
377
  # Run end-to-end multi-language simulation tests
@@ -36,8 +36,8 @@ asdlc apply <CHANGE_ID> [--auto-pr] [--target-branch <ref>]
36
36
  - If `asdlc apply` succeeds: Proceed to Step 2.
37
37
 
38
38
  > [!NOTE]
39
- > **Governance Level & Single PR Flow (L0 / L1)**:
40
- > For changes evaluated as `level: L0` or `level: L1`, prior merging of a Spec PR to the protected branch is waived. `asdlc apply` immediately unblocks local TDD implementation, allowing source code and spec delta to be submitted together in a Single PR.
39
+ > **Governance Level & Single PR Flow (Track B: L0 / L1)**:
40
+ > For changes evaluated as `level: L0` or `level: L1` (under `supervised` or `auto` without `spec-first` override), separate Spec PR and `asdlc approve` are **waived**. `asdlc apply` immediately unblocks local TDD implementation, automatically transitions status to `ready_for_impl` in-place, and allows source code and spec delta to be submitted together in a Single PR. (In `supervised` mode, human Lead sign-off occurs at the single PR merge).
41
41
 
42
42
 
43
43
  ### Step 2: Read `tasks.md` and Ground Context
@@ -7,6 +7,11 @@ description: "Execute Stage 4 of Agentic SDLC: approve spec intent, lock specSha
7
7
 
8
8
  This skill executes **Stage 4 (Approve)** of the Agentic SDLC. It transitions a change from approved intent into the implementation stage (`READY_FOR_IMPL`), locking the spec to a path-limited approved commit SHA (`specSha`).
9
9
 
10
+ > [!IMPORTANT]
11
+ > **Two-Track Lifecycle Routing (Track A vs. Track B)**:
12
+ > - **Track A (Dual-PR / Spec-First โ€” L2/L3 or forced `spec-first`)**: Separate Spec PR + merge + `asdlc approve <ID>` is **strictly required** before implementation (`apply`).
13
+ > - **Track B (Single-PR / Fast-Path โ€” L0/L1 under supervised/auto)**: Standalone Spec PR and `asdlc approve` are **waived**. You may proceed directly to `asdlc apply <ID>` to start TDD. If `asdlc approve <ID>` is run in Single-PR mode, it idempotently marks `status: ready_for_impl` in-place without generating a fake `specSha`, without git tags, and **without modifying `review.md`** (final human sign-off happens on the combined PR).
14
+
10
15
  ---
11
16
 
12
17
  ## Core Concept: The Spec SHA Freeze Gate
@@ -137,6 +137,7 @@ Once `## Open questions` in `clarifications.md` is empty, author the change docu
137
137
  - Independent AI review (`asdlc:spec-review`) is executed by an independent review agent (locally or via PR automation).
138
138
  - Formal approval is given by the human lead via PR merge or `asdlc approve <SLUG>`.
139
139
 
140
- ### Step 5: Transition to Lint
141
- Once artifacts are written, guide the developer:
142
- > "Artifacts drafted! Now run `/asdlc:lint <SLUG>` to verify BDD scenarios, technical design, and acceptance criteria before opening the spec PR."
140
+ ### Step 5: Transition to Implementation / Review (Two-Track Lifecycle)
141
+ Once artifacts are written, guide the developer based on the change's governance level (`asdlc status <SLUG>`):
142
+ - **Track A (L2 / L3 or `spec-first`)**: Run `/asdlc:lint <SLUG>` to verify BDD scenarios and open a Spec PR (`asdlc pr <SLUG>`). After merge, run `asdlc approve <SLUG>`.
143
+ - **Track B (L0 / L1 under supervised/auto)**: Draft `tasks.md` and proceed directly to `/asdlc:apply <SLUG>` to begin the TDD loop (standalone Spec PR and `asdlc approve` are waived; combined PR opened after verify).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akjamie/agentic-sdlc",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "Enterprise Agentic SDLC governance CLI: a 7-stage spec-driven flow on top of OpenSpec + Graphify, enforced by CI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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 = 'enabled';
9
-
10
- switch (level) {
11
- case 'L0':
12
- workflow_mode = 'single-pr';
13
- spec_approval = 'not-applicable';
14
- implementation_review = 'ai';
15
- auto_approval = 'enabled';
16
- break;
17
-
18
- case 'L1':
19
- workflow_mode = 'single-pr';
20
- spec_approval = 'automatic';
21
- implementation_review = 'ai';
22
- auto_approval = 'enabled';
23
- break;
24
-
25
- case 'L2':
26
- workflow_mode = 'spec-first';
27
- spec_approval = 'human';
28
- implementation_review = 'ai+human';
29
- auto_approval = 'disabled';
30
- break;
31
-
32
- case 'L3':
33
- default:
34
- workflow_mode = 'spec-first';
35
- spec_approval = 'human';
36
- implementation_review = 'ai+human';
37
- auto_approval = 'disabled';
38
- break;
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
  }
@@ -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 = {
@@ -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
- actionHighlight = `> ๐Ÿ›‘ **ใ€ๆฒป็†ๅŠจไฝœ๏ผš้ซ˜้ฃŽ้™ฉๆ”นๅŠจ ยท ๅฟ…้กปไบบๅทฅ็ปˆๅฎกใ€‘**\n> ๐ŸŽฏ **ๆœ€็ปˆๆฒป็†็ญ‰็บง**๏ผš\`${lvl}\`\n> ๐Ÿšจ **ๆต่ฝฌๆ‰ง่กŒ**๏ผš**่‡ชๅŠจๅˆๅนถๅทฒๅ…ณ้—ญ (Auto-Merge DENIED)**๏ผŒๅฟ…้กป็”ฑไบบ็ฑป Lead ๅฎกๆ ธๆ‰นๅ‡†ๅŽๆ–นๅฏๅˆๅ…ฅไธปๅนฒใ€‚`;
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
  }
@@ -1,5 +1,5 @@
1
1
  export const HARNESS_RULES_VERSION = '2026.10.0';
2
- export const ENGINE_VERSION = '1.8.0';
2
+ export const ENGINE_VERSION = '1.9.0';
3
3
 
4
4
  export const RISK_LEVELS = {
5
5
  L0: 'L0',
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;
@@ -2,10 +2,11 @@ import path from 'node:path';
2
2
  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
- import { lastCommitTouching, git } from '../lib/git.js';
5
+ import { lastCommitTouching, git, resolveDefaultBranch } 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) {
@@ -89,6 +94,7 @@ export function applyGuard(changeId, opts = {}) {
89
94
  };
90
95
  metaText = upsertKey(metaText, 'status', 'ready_for_impl');
91
96
  writeText(metaPath, metaText);
97
+ log.ok(`${slug}: marked status=ready_for_impl (no separate Spec PR in Single-PR mode; human sign-off happens on the final PR)`);
92
98
  }
93
99
  log.ok(`${slug}: governance level is ${effectiveLevel} (Single PR mode: direct local implementation permitted)`);
94
100
  } else {
@@ -186,21 +192,13 @@ export function applyGuard(changeId, opts = {}) {
186
192
  return 0;
187
193
  }
188
194
 
189
- function resolveDefaultBranch(repoRoot) {
190
- // Check if origin/main, origin/master, main, or master exists
191
- for (const candidate of ['origin/main', 'origin/master', 'main', 'master']) {
192
- const existsRef = git(['rev-parse', '--verify', candidate], repoRoot, { allowFail: true });
193
- if (existsRef) return candidate;
194
- }
195
- return 'main';
196
- }
197
-
198
195
  export function register(program) {
199
196
  program
200
197
  .command('apply <changeId>')
201
198
  .description('guard before implementing: the spec must be approved on the protected branch')
202
199
  .option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
203
200
  .option('--target-branch <ref>', 'target branch to merge into')
201
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
204
202
  .option('--auto-pr', 'explicitly delegate authority to automatically open Implementation PR after verification passes')
205
203
  .option('--no-auto-pr', 'disable automatic Implementation PR creation (default)')
206
204
  .option('--repo-root <path>')
@@ -3,11 +3,12 @@ import { execFileSync } from 'node:child_process';
3
3
  import { exists, readText, writeText } from '../lib/fs.js';
4
4
  import { changeDir } from '../lib/paths.js';
5
5
  import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
6
- import { headSha, git, isGitRepo, lastCommitTouching, changeOnRef, safeCommit } from '../lib/git.js';
6
+ import { headSha, git, isGitRepo, lastCommitTouching, changeOnRef, safeCommit, resolveDefaultBranch } from '../lib/git.js';
7
7
  import { loadPolicy } from '../lib/policy.js';
8
8
  import { classifyPR } from '../lib/prtype.js';
9
9
  import { fail } from '../lib/errors.js';
10
10
  import { log } from '../lib/log.js';
11
+ import { resolveTopology } from '../lib/level.js';
11
12
 
12
13
  function upsertKey(text, key, value) {
13
14
  const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
@@ -83,6 +84,53 @@ export function mergeChange(changeId, opts = {}) {
83
84
  return [];
84
85
  }
85
86
 
87
+ // Single-PR optimization (Stage 4 decoupling):
88
+ // When explicitly invoked for a Single-PR change, spec approval is co-located with the
89
+ // final implementation PR. We idempotently mark status: ready_for_impl without requiring
90
+ // a separate merged Spec PR, without stamping specSha or tagging, and without writing review.md.
91
+ if (changeId) {
92
+ const branch = opts.targetBranch ?? opts.protectedBranch ?? opts.branch ?? resolveDefaultBranch(repoRoot);
93
+ const topology = resolveTopology({ repoRoot, slug, baseRef: branch, cliMode: opts.mode });
94
+
95
+ if (topology.tampered) {
96
+ fail(`cannot approve '${slug}': ${topology.reason}. Manual level downgrading or history tampering is strictly forbidden.`, {
97
+ code: 'LEVEL_TAMPERED',
98
+ hint: 'Revert unauthorized level edits in .openspec.yaml or restore risk-history.jsonl.'
99
+ });
100
+ }
101
+
102
+ if (topology.isSinglePr) {
103
+ const meta = path.join(changeDir(repoRoot, slug), '.openspec.yaml');
104
+ if (!exists(meta)) fail(`${slug}: no .openspec.yaml`);
105
+
106
+ const preImplStatuses = [null, '', 'draft', 'spec_review'];
107
+ if (preImplStatuses.includes(topology.declaredStatus)) {
108
+ let text = readText(meta);
109
+ text = upsertKey(text, 'status', 'ready_for_impl');
110
+ writeText(meta, text);
111
+ log.ok('marked status=ready_for_impl in-place (no separate Spec PR required).');
112
+ } else {
113
+ log.info(`${slug}: status=${topology.declaredStatus} preserved (no status regression).`);
114
+ }
115
+
116
+ log.ok(`${slug}: Single-PR mode (${topology.effectiveLevel}) - spec approval is co-located with implementation PR.`);
117
+ log.info('final approval = human Approve on the single PR (NOT waived).');
118
+ log.info('note: final governance level is re-assessed by `asdlc apply` when implementation context is available.');
119
+ return [slug];
120
+ }
121
+
122
+ // Track A (Dual-PR / Spec-First / unlevelled):
123
+ // Require physical merge evidence on target branch before stamping approval.
124
+ const trackALocked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
125
+ const mergedSha = lastCommitTouching(repoRoot, branch, trackALocked);
126
+ if (!mergedSha) {
127
+ fail(`cannot approve '${slug}': no commit touching ${trackALocked.join(' or ')} is merged into ${branch}. Spec PR must be approved and merged before running asdlc approve.`, {
128
+ code: 'SPEC_NOT_MERGED',
129
+ hint: `Open a Spec PR targeting ${branch}, merge it, then run: asdlc approve ${changeId}`
130
+ });
131
+ }
132
+ }
133
+
86
134
  const changedFiles = (git(['diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD^1', 'HEAD'], repoRoot, { allowFail: true }) ?? '')
87
135
  .split(/\r?\n/).filter(Boolean);
88
136
  // was the change already on main BEFORE this merge?
@@ -156,6 +204,9 @@ export function register(program) {
156
204
  .command('approve [changeId]')
157
205
  .description('record the approved spec after the spec PR merges (tags approved/<ID> + marks READY_FOR_IMPL)')
158
206
  .option('--sha <sha>', 'merge commit (default: HEAD)')
207
+ .option('--protected-branch <ref>', 'branch the approved spec must be merged into')
208
+ .option('--target-branch <ref>', 'target branch to check for spec merge')
209
+ .option('--mode <mode>', 'workflow mode override (supervised, spec-first, auto)')
159
210
  .option('--no-tag', 'skip the approved/<ID> git tag')
160
211
  .option('--no-commit', 'stamp without committing')
161
212
  .option('--repo-root <path>')
@@ -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);