@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 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/>(CI + AI Review Auto-Merge)"]
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
- ### Governance Tier Matrix
101
+ ### Three-Tier Workflow Modes (`supervised` | `spec-first` | `auto`)
102
102
 
103
- | Tier | Typical Scope | Workflow Mode | Spec-First Block? | Implementation Review | Auto-Merge |
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 | 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) |
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
- # → Auto-merge eligible once CI & AI checks pass!
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akjamie/agentic-sdlc",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
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": {
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { execSync } from 'node:child_process';
11
- import { CANONICAL_DESTRUCTIVE_PATTERN, isTestOrDocFile, isChangeMetadataFile } from './rules/builtin.js';
11
+ import { CANONICAL_DESTRUCTIVE_PATTERN, isTestOrDocFile, isChangeMetadataFile, isPureTestFile, isPureL0File } from './rules/builtin.js';
12
12
 
13
13
  export const AI_CLASSIFICATION_SCHEMA = {
14
14
  type: 'object',
@@ -163,50 +163,51 @@ export function judgeChangeSemantics({ requirement = '', changedFiles = [], repo
163
163
  }
164
164
 
165
165
  // 3. Validated baseline heuristic seed (deterministic fallback for standalone CLI execution)
166
+ // Per Hardening Spec C3/C4 & R2 Review: CLI maintains ZERO human natural language dictionaries for risk escalation.
167
+ // Pre-code risk escalation relies strictly on CANONICAL_DESTRUCTIVE_PATTERN, target files (explore.md), or host agentContext.
168
+ // Explicit documented exception: Safe L0-only doc/test intent tokens are retained exclusively for pre-code routine
169
+ // classification (guarded by Invariant 4 against refactoring/code masking), and can NEVER escalate risk or bypass gates.
166
170
  if (!rawAiOutput) {
167
- const hasProductionTarget = /\b(create|add|implement|build)\b.*\b(api|endpoint|service|table|database|schema|handler|router)\b/i.test(req) ||
168
- /(?:创建|新增|实现|开发)\b.*(?:接口|服务|路由|数据表|表结构|控制器)/i.test(req);
169
171
  const hasDestructiveAction = CANONICAL_DESTRUCTIVE_PATTERN.test(req);
170
172
 
171
- const isDocIntent = /(?:\b(?:typo|typos|readme|docs?|documentation|comments?|whitespace|markdown|license|changelog)\b|错别字|文档|注释|说明文档)/i.test(req) &&
172
- !hasProductionTarget && !hasDestructiveAction;
173
-
174
- const isTestIntent = /(?:\b(?:tests?|testing|mocks?|fixtures?|suites?|unittests?|integrationtests?)\b|单元测试|集成测试|测试用例)/i.test(req) &&
175
- !hasProductionTarget && !hasDestructiveAction;
173
+ const substantiveFiles = normFiles.filter((f) => !isChangeMetadataFile(f));
174
+ const allTestFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => isPureTestFile(f));
175
+ const allDocFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => isPureL0File(f));
176
176
 
177
- // Few-shot file pattern seeds (illustrative samples)
178
- const testPatternSamples = [
179
- /(^|\/)(tests?|__tests__|testing|fixtures?|mocks?)\//i,
180
- /\.(test|spec)\.[a-z0-9]+$/i,
181
- /_test\.go$/i,
182
- /test_[^/]+\.py$/i,
183
- /[^/]+_test\.py$/i
184
- ];
177
+ let isPureTest = allTestFiles;
178
+ let isPureDoc = allDocFiles;
185
179
 
186
- const docPatternSamples = [
187
- /(^|\/)docs?\//i,
188
- /\.(md|txt)$/i,
189
- /^license$/i
190
- ];
180
+ if (substantiveFiles.length === 0 && !hasDestructiveAction) {
181
+ const hasDocSignal = /(?:\b(?:docs?|documentation|readme|typo|typos|comments?|whitespace|changelog|markdown|license)\b|文档|注释|错别字|说明文档)/i.test(req);
182
+ const hasTestSignal = /(?:\b(?:unit\s+tests?|integration\s+tests?|e2e\s+tests?|test\s+suites?|test\s+cases?|tests?|testing|mocks?|fixtures?)\b|单元测试|集成测试|测试用例)/i.test(req);
183
+ const hasCodeRefactorOrMutation = /(?:\b(?:refactor|rewrite|redesign|state\s+machine)\b|重构|重写|状态机)/i.test(req) ||
184
+ /\b(?:implement|build|create)\b.*\b(?:api|endpoint|service|controller|router|table|database|schema|handler)\b/i.test(req) ||
185
+ /(?:实现|开发|创建|新增)\b.*(?:接口|服务|路由|数据表|表结构|控制器)/i.test(req);
191
186
 
192
- const substantiveFiles = normFiles.filter((f) => !isChangeMetadataFile(f));
193
- const allTestFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => testPatternSamples.some((p) => p.test(f)));
194
- const allDocFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => docPatternSamples.some((p) => p.test(f)));
187
+ if (hasDocSignal && !hasCodeRefactorOrMutation) {
188
+ isPureDoc = true;
189
+ }
190
+ if (hasTestSignal && !hasCodeRefactorOrMutation) {
191
+ isPureTest = true;
192
+ }
193
+ }
195
194
 
196
- const isPureTest = allTestFiles || (substantiveFiles.length === 0 && isTestIntent);
197
- const isPureDoc = allDocFiles || (substantiveFiles.length === 0 && isDocIntent);
195
+ let heuristicClass = 'internal_code';
196
+ if (isPureTest) heuristicClass = 'test_only';
197
+ else if (isPureDoc) heuristicClass = 'doc_only';
198
+ else if (hasDestructiveAction) heuristicClass = 'destructive';
198
199
 
199
200
  rawAiOutput = {
200
201
  is_pure_test: isPureTest,
201
202
  is_pure_doc: isPureDoc,
202
- contains_destructive_ops: CANONICAL_DESTRUCTIVE_PATTERN.test(req),
203
+ contains_destructive_ops: hasDestructiveAction,
203
204
  contains_api_changes: false,
204
- classification: isPureTest ? 'test_only' : (isPureDoc ? 'doc_only' : 'internal_code'),
205
+ classification: heuristicClass,
205
206
  confidence: 'high',
206
207
  evaluator_mode: 'heuristic_seed',
207
208
  rationale: isPureTest
208
209
  ? 'Deterministic Heuristic Baseline: Change is strictly confined to test suites, mocks, and test assertions.'
209
- : (isPureDoc ? 'Deterministic Heuristic Baseline: Change is purely documentation, typo fix, comments, or non-executable text.' : 'Deterministic Heuristic Baseline: General code change')
210
+ : (isPureDoc ? 'Deterministic Heuristic Baseline: Change is purely documentation, typo fix, comments, or non-executable text.' : (hasDestructiveAction ? 'Deterministic Heuristic Baseline: Irreversible destructive data operations detected in task statement.' : 'Deterministic Heuristic Baseline: General code change (evaluated via static code semantics)'))
210
211
  };
211
212
  } else {
212
213
  rawAiOutput.evaluator_mode = rawAiOutput.evaluator_mode || 'llm_classifier';
@@ -73,6 +73,24 @@ export function decideAssessment({
73
73
  }
74
74
  }
75
75
 
76
+ // 3b. Bounded L1 Positive Safety Envelope (§10.2 7b):
77
+ // When calculatedLevel is L1, verify it remains within bounded local code envelope:
78
+ // - Substantive production source files <= 5
79
+ // - Did not modify root export entrypoints (index.ts/js, lib.rs)
80
+ // If unbounded (> 5 source files or touching root entrypoints), escalate to L2
81
+ if (calculatedLevel === 'L1' && !hasMandatoryHumanReview) {
82
+ const substantiveFiles = changedFiles
83
+ .map((f) => f.replace(/\\/g, '/'))
84
+ .filter((f) => !isChangeMetadataFile(f));
85
+ const productionFiles = substantiveFiles.filter((f) => !isPureL0File(f) && !isPureTestFile(f));
86
+
87
+ if (productionFiles.length > 5) {
88
+ calculatedLevel = 'L2';
89
+ } else if (productionFiles.some((f) => /^(?:(?:packages\/[^/]+\/)?(?:src\/|lib\/)?)?(?:index\.(?:ts|js|mjs)|lib\.rs)$/i.test(f))) {
90
+ calculatedLevel = 'L2';
91
+ }
92
+ }
93
+
76
94
  // 4. Determine Confidence & Unresolved
77
95
  const allUnresolved = [
78
96
  ...(v1.unresolved || []),
@@ -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
  }
@@ -5,8 +5,10 @@ import { HARNESS_RULES_VERSION, ENGINE_VERSION } from './rules/builtin.js';
5
5
  import { evaluateV1Intent } from './vectors/v1_intent.js';
6
6
  import { evaluateV2Security } from './vectors/v2_security.js';
7
7
  import { evaluateV3Topology } from './vectors/v3_topology.js';
8
+ import { batchAnalyzeFileSemantics } from './semantics.js';
8
9
  import { decideAssessment } from './decide.js';
9
10
  import { deriveGovernance } from './governance.js';
11
+ import { resolveWorkflowMode } from '../lib/config.js';
10
12
  import { appendAssessmentRecord, loadLatestAssessment, loadInitialAssessment } from './store.js';
11
13
  import { renderCheckSummary, renderPRComment, renderLabels } from './render.js';
12
14
 
@@ -31,15 +33,18 @@ export function assess({
31
33
  baseline = null,
32
34
  actor = { type: 'system', id: 'asdlc' },
33
35
  repoRoot = null,
34
- persist = true
36
+ persist = true,
37
+ agentContext = null,
38
+ mode = null
35
39
  } = {}) {
36
40
  try {
41
+ const effectiveMode = resolveWorkflowMode({ cliMode: mode, repoRoot, baseRef });
37
42
  const prev = previous || (repoRoot && changeId ? loadLatestAssessment(repoRoot, changeId) : null);
38
43
  const baseRec = baseline || (repoRoot && changeId ? loadInitialAssessment(repoRoot, changeId) : null);
39
44
 
40
45
  // If requirement is empty or for spec stage, load proposal.md and design.md from change dir
41
46
  let effectiveReq = requirement || '';
42
- let agentContext = null;
47
+ let effectiveAgentContext = agentContext;
43
48
  if (repoRoot && changeId) {
44
49
  try {
45
50
  const cdir = changeDir(repoRoot, changeId);
@@ -50,19 +55,24 @@ export function assess({
50
55
  }
51
56
 
52
57
  // Check if change contains agent assessment context (.agent-assess.json or .openspec.yaml assessment)
53
- const agentCtxPath = path.join(cdir, '.agent-assess.json');
54
- if (fs.existsSync(agentCtxPath)) {
55
- try {
56
- agentContext = JSON.parse(fs.readFileSync(agentCtxPath, 'utf8'));
57
- } catch { /* ignore parse error */ }
58
+ if (!effectiveAgentContext) {
59
+ const agentCtxPath = path.join(cdir, '.agent-assess.json');
60
+ if (fs.existsSync(agentCtxPath)) {
61
+ try {
62
+ effectiveAgentContext = JSON.parse(fs.readFileSync(agentCtxPath, 'utf8'));
63
+ } catch { /* ignore parse error */ }
64
+ }
58
65
  }
59
66
  } catch { /* ignore read failure */ }
60
67
  }
61
68
 
69
+ const effectiveBase = baseRef || baseSha;
70
+ const fileSemantics = batchAnalyzeFileSemantics(changedFiles, { repoRoot, baseRef: effectiveBase });
71
+
62
72
  // 1. Evaluate Three Risk Vectors
63
- const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType, agentContext });
64
- const v2 = evaluateV2Security({ requirement: effectiveReq, changedFiles, repoRoot, baseRef: baseRef || baseSha });
65
- const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot, changeId });
73
+ const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType, agentContext: effectiveAgentContext });
74
+ const v2 = evaluateV2Security({ requirement: effectiveReq, changedFiles, repoRoot, baseRef: effectiveBase, fileSemantics });
75
+ const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot, changeId, baseRef: effectiveBase, fileSemantics });
66
76
 
67
77
  // Inferred or provided Change Type
68
78
  const effectiveType = changeType || v1.inferredType || 'change';
@@ -82,7 +92,8 @@ export function assess({
82
92
  const governance = decision.governance || deriveGovernance({
83
93
  level: decision.level,
84
94
  confidence: decision.confidence,
85
- mandatory_human_review: decision.mandatory_human_review
95
+ mandatory_human_review: decision.mandatory_human_review,
96
+ mode: effectiveMode
86
97
  });
87
98
 
88
99
  const recordData = {
@@ -147,6 +158,9 @@ export function assess({
147
158
 
148
159
  return recordData;
149
160
  } catch (err) {
161
+ if (err.code === 'ILLEGAL_MODE_DOWNGRADE' || err.code === 'INVALID_WORKFLOW_MODE') {
162
+ throw err;
163
+ }
150
164
  // Fallback to Global Default on unexpected exception (§5.5)
151
165
  const fallbackDecision = decideAssessment({ stage, error: err, previous });
152
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.7.0';
2
+ export const ENGINE_VERSION = '1.9.0';
3
3
 
4
4
  export const RISK_LEVELS = {
5
5
  L0: 'L0',