@akjamie/agentic-sdlc 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.md +218 -301
- package/assets/schema/risk-assessment.schema.json +225 -0
- package/assets/skills/asdlc-apply/SKILL.md +43 -18
- package/assets/skills/asdlc-verify/SKILL.md +16 -6
- package/package.json +2 -2
- package/src/assess/ai_judge.js +163 -0
- package/src/assess/decide.js +164 -0
- package/src/assess/governance.js +53 -0
- package/src/assess/index.js +183 -0
- package/src/assess/render.js +71 -0
- package/src/assess/rules/builtin.js +195 -0
- package/src/assess/schema.js +148 -0
- package/src/assess/store.js +138 -0
- package/src/assess/vectors/v1_intent.js +80 -0
- package/src/assess/vectors/v2_security.js +131 -0
- package/src/assess/vectors/v3_topology.js +107 -0
- package/src/cli.js +91 -89
- package/src/commands/apply.js +103 -36
- package/src/commands/assess.js +57 -0
- package/src/commands/doctor.js +1 -14
- package/src/commands/init.js +0 -9
- package/src/commands/new.js +19 -2
- package/src/commands/pr.js +27 -3
- package/src/commands/upgrade.js +1 -1
- package/src/commands/verify.js +109 -15
- package/src/lib/fs.js +26 -3
- package/src/lib/level.js +118 -0
- package/src/lib/paths.js +2 -1
- package/src/lib/prtype.js +17 -4
- package/src/lib/risk.js +50 -0
- package/src/lib/schema.js +4 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "RiskAssessmentRecord",
|
|
4
|
+
"description": "ASdlc Change-Level Governance Assessment Record Schema v1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"schema_version",
|
|
8
|
+
"change_id",
|
|
9
|
+
"seq",
|
|
10
|
+
"prev_hash",
|
|
11
|
+
"hash",
|
|
12
|
+
"timestamp",
|
|
13
|
+
"actor",
|
|
14
|
+
"stage",
|
|
15
|
+
"role",
|
|
16
|
+
"status",
|
|
17
|
+
"verdict",
|
|
18
|
+
"change_type",
|
|
19
|
+
"source",
|
|
20
|
+
"risk",
|
|
21
|
+
"vectors",
|
|
22
|
+
"governance",
|
|
23
|
+
"reason_codes",
|
|
24
|
+
"transition"
|
|
25
|
+
],
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"properties": {
|
|
28
|
+
"schema_version": {
|
|
29
|
+
"type": "integer",
|
|
30
|
+
"enum": [1]
|
|
31
|
+
},
|
|
32
|
+
"change_id": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"pattern": "^[a-zA-Z0-9_-]+$"
|
|
35
|
+
},
|
|
36
|
+
"seq": {
|
|
37
|
+
"type": "integer",
|
|
38
|
+
"minimum": 1
|
|
39
|
+
},
|
|
40
|
+
"prev_hash": {
|
|
41
|
+
"type": ["string", "null"],
|
|
42
|
+
"pattern": "^[a-f0-9]{64}$"
|
|
43
|
+
},
|
|
44
|
+
"hash": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"pattern": "^[a-f0-9]{64}$"
|
|
47
|
+
},
|
|
48
|
+
"timestamp": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"format": "date-time"
|
|
51
|
+
},
|
|
52
|
+
"actor": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"required": ["type", "id"],
|
|
55
|
+
"additionalProperties": false,
|
|
56
|
+
"properties": {
|
|
57
|
+
"type": { "type": "string", "enum": ["system", "human", "agent"] },
|
|
58
|
+
"id": { "type": "string" }
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"stage": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"enum": ["new", "spec", "impl"]
|
|
64
|
+
},
|
|
65
|
+
"role": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"enum": ["primary", "cross_check"]
|
|
68
|
+
},
|
|
69
|
+
"compared_to": {
|
|
70
|
+
"type": ["string", "null"],
|
|
71
|
+
"pattern": "^[a-f0-9]{64}$"
|
|
72
|
+
},
|
|
73
|
+
"status": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"enum": ["provisional", "needs_input", "ready", "defaulted"]
|
|
76
|
+
},
|
|
77
|
+
"verdict": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"enum": ["ok", "escalated", "needs_input", "blocked", "defaulted"]
|
|
80
|
+
},
|
|
81
|
+
"defaulted_cause": {
|
|
82
|
+
"type": ["string", "null"]
|
|
83
|
+
},
|
|
84
|
+
"change_type": {
|
|
85
|
+
"type": "string",
|
|
86
|
+
"enum": ["chore", "fix", "change", "feature"]
|
|
87
|
+
},
|
|
88
|
+
"source": {
|
|
89
|
+
"type": "object",
|
|
90
|
+
"required": ["base_sha", "harness_rules_version", "engine_version"],
|
|
91
|
+
"additionalProperties": false,
|
|
92
|
+
"properties": {
|
|
93
|
+
"base_sha": { "type": "string" },
|
|
94
|
+
"head_sha": { "type": ["string", "null"] },
|
|
95
|
+
"harness_rules_version": { "type": "string" },
|
|
96
|
+
"engine_version": { "type": "string" },
|
|
97
|
+
"task_ref": { "type": ["string", "null"] },
|
|
98
|
+
"models": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"items": {
|
|
101
|
+
"type": "object",
|
|
102
|
+
"required": ["purpose", "model_id"],
|
|
103
|
+
"additionalProperties": false,
|
|
104
|
+
"properties": {
|
|
105
|
+
"purpose": { "type": "string", "enum": ["classifier", "reviewer", "implementer"] },
|
|
106
|
+
"model_id": { "type": "string" }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"risk": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"required": ["level", "confidence"],
|
|
115
|
+
"additionalProperties": false,
|
|
116
|
+
"properties": {
|
|
117
|
+
"level": { "type": "string", "enum": ["L0", "L1", "L2", "L3"] },
|
|
118
|
+
"confidence": { "type": "string", "enum": ["high", "medium", "low"] }
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"vectors": {
|
|
122
|
+
"type": "object",
|
|
123
|
+
"required": ["v1_intent", "v2_security", "v3_topology"],
|
|
124
|
+
"additionalProperties": false,
|
|
125
|
+
"properties": {
|
|
126
|
+
"v1_intent": { "$ref": "#/definitions/VectorResult" },
|
|
127
|
+
"v2_security": { "$ref": "#/definitions/VectorResult" },
|
|
128
|
+
"v3_topology": { "$ref": "#/definitions/VectorResult" }
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"governance": {
|
|
132
|
+
"type": "object",
|
|
133
|
+
"required": ["workflow_mode", "spec_approval", "implementation_review"],
|
|
134
|
+
"additionalProperties": false,
|
|
135
|
+
"properties": {
|
|
136
|
+
"workflow_mode": { "type": "string", "enum": ["single-pr", "spec-first"] },
|
|
137
|
+
"spec_approval": { "type": "string", "enum": ["not-applicable", "automatic", "human"] },
|
|
138
|
+
"implementation_review": { "type": "string", "enum": ["ai", "ai+human"] },
|
|
139
|
+
"auto_approval": { "type": "string", "enum": ["enabled", "disabled"] }
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"reason_codes": {
|
|
143
|
+
"type": "array",
|
|
144
|
+
"items": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"enum": [
|
|
147
|
+
"HARD_RULE_HIT",
|
|
148
|
+
"SOFT_SIGNAL_ESCALATION",
|
|
149
|
+
"SECURITY_BOUNDARY_POSSIBLE",
|
|
150
|
+
"IMPACT_SCOPE_NOT_FULLY_KNOWN",
|
|
151
|
+
"ESCALATED_IN_IMPL",
|
|
152
|
+
"AI_REVIEW_DISAGREEMENT",
|
|
153
|
+
"SPEC_GAP",
|
|
154
|
+
"SPEC_INTENT_MUTATION",
|
|
155
|
+
"TYPE_MISMATCH",
|
|
156
|
+
"NEEDS_INPUT",
|
|
157
|
+
"EVIDENCE_CONFLICT",
|
|
158
|
+
"GOVERNANCE_PLANE_CHANGE",
|
|
159
|
+
"NO_PRIOR_ASSESSMENT",
|
|
160
|
+
"WAIVER_APPLIED",
|
|
161
|
+
"DEFAULTED",
|
|
162
|
+
"RECORD_MISMATCH",
|
|
163
|
+
"HISTORY_REWRITTEN",
|
|
164
|
+
"RULES_VERSION_MISMATCH",
|
|
165
|
+
"SCHEMA_INVALID"
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"observations": {
|
|
170
|
+
"type": "array",
|
|
171
|
+
"items": { "type": "string" }
|
|
172
|
+
},
|
|
173
|
+
"transition": {
|
|
174
|
+
"type": "object",
|
|
175
|
+
"required": ["from_level", "to_level", "direction"],
|
|
176
|
+
"additionalProperties": false,
|
|
177
|
+
"properties": {
|
|
178
|
+
"from_level": { "type": ["string", "null"], "enum": ["L0", "L1", "L2", "L3", null] },
|
|
179
|
+
"to_level": { "type": "string", "enum": ["L0", "L1", "L2", "L3"] },
|
|
180
|
+
"direction": { "type": "string", "enum": ["initial", "up", "same", "down"] },
|
|
181
|
+
"triggers": { "type": "array", "items": { "type": "string" } },
|
|
182
|
+
"recovered_from_default": { "type": "boolean" },
|
|
183
|
+
"waiver": {
|
|
184
|
+
"type": ["object", "null"],
|
|
185
|
+
"properties": {
|
|
186
|
+
"approved_by": { "type": "string" },
|
|
187
|
+
"reason": { "type": "string" },
|
|
188
|
+
"expires_at": { "type": "string" }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"definitions": {
|
|
195
|
+
"VectorResult": {
|
|
196
|
+
"type": "object",
|
|
197
|
+
"required": ["level", "confidence", "evidence", "unresolved", "mandatory_human_review", "no_signal"],
|
|
198
|
+
"additionalProperties": false,
|
|
199
|
+
"properties": {
|
|
200
|
+
"level": { "type": "string", "enum": ["L0", "L1", "L2", "L3"] },
|
|
201
|
+
"confidence": { "type": "string", "enum": ["high", "medium", "low"] },
|
|
202
|
+
"evidence": {
|
|
203
|
+
"type": "array",
|
|
204
|
+
"items": {
|
|
205
|
+
"type": "object",
|
|
206
|
+
"required": ["id", "kind", "signal", "summary"],
|
|
207
|
+
"additionalProperties": false,
|
|
208
|
+
"properties": {
|
|
209
|
+
"id": { "type": "string" },
|
|
210
|
+
"kind": { "type": "string", "enum": ["repository_fact", "task_statement", "scanner_result", "rule_hit", "reviewer_finding"] },
|
|
211
|
+
"signal": { "type": "string", "enum": ["hard", "soft"] },
|
|
212
|
+
"summary": { "type": "string" },
|
|
213
|
+
"source": { "type": "string" },
|
|
214
|
+
"source_commit": { "type": "string" },
|
|
215
|
+
"rule_id": { "type": "string" }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
"unresolved": { "type": "array", "items": { "type": "string" } },
|
|
220
|
+
"mandatory_human_review": { "type": "boolean" },
|
|
221
|
+
"no_signal": { "type": "boolean" }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: asdlc-apply
|
|
3
|
-
description: "Execute Stage 5 of Agentic SDLC: guard verification followed by strict task-level TDD loop (Red -> Green -> Refactor -> Evidence -> Converge) from tasks.md."
|
|
3
|
+
description: "Execute Stage 5 of Agentic SDLC: guard verification followed by strict task-level TDD loop (Red -> Green -> Refactor -> Evidence -> Converge) from tasks.md. Defaults to local-only implementation; auto-PR is permitted only with explicit delegation via --auto-pr."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# /asdlc:apply - Task-Level TDD Implementation Engine
|
|
@@ -22,18 +22,24 @@ This skill executes **Stage 5 (Apply)** of the Agentic SDLC. It enforces strict
|
|
|
22
22
|
Before editing any implementation or test code, run the apply guard:
|
|
23
23
|
|
|
24
24
|
```powershell
|
|
25
|
-
asdlc apply <CHANGE_ID>
|
|
25
|
+
asdlc apply <CHANGE_ID> [--auto-pr] [--target-branch <ref>]
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
`asdlc apply` deterministically verifies
|
|
28
|
+
`asdlc apply` deterministically verifies cryptographic preconditions:
|
|
29
29
|
1. **Target Branch Approved Commit (`approvedSha`)**: Confirms that a commit touching the locked paths (`proposal.md` and `specs/**`) is physically merged into the target branch (`main` or `origin/main`).
|
|
30
30
|
2. **Change State Machine (`ready_for_impl`)**: Confirms `.openspec.yaml` has been transitioned to `status: ready_for_impl` (via `asdlc approve <ID>`).
|
|
31
31
|
3. **Spec Fingerprint Integrity (`specSha`)**: Verifies that the declared `specSha` in `.openspec.yaml` exactly matches the `approvedSha` on the protected branch.
|
|
32
32
|
4. **Working Tree Tamper Defense**: Ensures that locked spec files (`proposal.md`, `specs/**`) have no uncommitted local modifications.
|
|
33
|
+
5. **PR Authority Delegation (`--auto-pr`)**: By default, `apply` operates in **local-only mode** (`autoPr: false`). Supplying `--auto-pr` explicitly delegates authority to automatically create an Implementation PR after verification passes (persisted to `.openspec.yaml`).
|
|
33
34
|
|
|
34
35
|
- If `asdlc apply` fails: **STOP immediately**. Follow the provided hint (e.g. merge Spec PR or run `asdlc approve`).
|
|
35
36
|
- If `asdlc apply` succeeds: Proceed to Step 2.
|
|
36
37
|
|
|
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.
|
|
41
|
+
|
|
42
|
+
|
|
37
43
|
### Step 2: Read `tasks.md` and Ground Context
|
|
38
44
|
1. Open and read `openspec/changes/<CHANGE_ID>/tasks.md`.
|
|
39
45
|
2. Inspect the spec requirements in `openspec/changes/<CHANGE_ID>/specs/**/*.md` to understand the acceptance criteria (`AC<n>`) and required test mappings (`(test: <path>)`).
|
|
@@ -95,8 +101,8 @@ When a change introduces or modifies user-facing interfaces (web, mobile, or des
|
|
|
95
101
|
|
|
96
102
|
---
|
|
97
103
|
|
|
98
|
-
### Step 4: Run Verification
|
|
99
|
-
Once all tasks in `tasks.md` are checked and evidenced, run `asdlc verify
|
|
104
|
+
### Step 4: Run Local Verification Check
|
|
105
|
+
Once all tasks in `tasks.md` are checked and evidenced, run `asdlc verify <CHANGE_ID>` locally:
|
|
100
106
|
|
|
101
107
|
```powershell
|
|
102
108
|
asdlc verify <CHANGE_ID>
|
|
@@ -111,18 +117,37 @@ Verify that all checks pass:
|
|
|
111
117
|
- `BDD + acceptance criteria`
|
|
112
118
|
- `openspec-validate`
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### Step 5: Open Implementation PR
|
|
117
|
-
Once `asdlc verify <CHANGE_ID>` passes, execute `asdlc pr` to open the Implementation PR:
|
|
120
|
+
If any check fails, resolve the issue locally within the TDD loop and re-run `asdlc verify <CHANGE_ID>`.
|
|
118
121
|
|
|
119
|
-
|
|
120
|
-
asdlc pr <CHANGE_ID> <targetBranch>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
`asdlc pr` will:
|
|
124
|
-
1. Automatically detect this is an **Implementation PR** (status is `ready_for_impl`, spec is approved, tasks are complete, and source changes exist).
|
|
125
|
-
2. Run `asdlc verify <CHANGE_ID>` as a pre-flight guard (requiring all 12 verification checks to pass).
|
|
126
|
-
3. Commit implementation code and test evidence, then push to origin.
|
|
127
|
-
4. Pre-provision and attach `asdlc:impl-review` and `impl` labels to trigger CI Code AI Review.
|
|
122
|
+
---
|
|
128
123
|
|
|
124
|
+
### Step 5: Implementation Complete & Submission Protocol (Dual-Mode Authority)
|
|
125
|
+
|
|
126
|
+
Once all tasks in `tasks.md` are marked complete with captured evidence and local `asdlc verify <CHANGE_ID>` passes (all 12 verification gates exit 0), determine the submission path based on explicit authority:
|
|
127
|
+
|
|
128
|
+
#### Path A: Default Local Mode (Safe Default, `autoPr: false` or unspecified)
|
|
129
|
+
> [!CAUTION]
|
|
130
|
+
> **Stage Boundary Guard — No Automatic PR Creation by Default**:
|
|
131
|
+
> `asdlc-apply` is strictly the **local implementation engine** (Stage 5).
|
|
132
|
+
> **NEVER automatically push commits to origin or open a Pull Request during `apply` by default.**
|
|
133
|
+
> Pushing code to a remote repository and opening a PR is a public, collaborative action with team-wide visibility, git ref mutation, and CI compute costs.
|
|
134
|
+
>
|
|
135
|
+
> In default mode, an agent executing `apply` must NEVER run `asdlc pr` or `git push` on its own.
|
|
136
|
+
|
|
137
|
+
1. Summarize completed tasks and verification results for the developer.
|
|
138
|
+
2. Inform the developer that the implementation is verified locally and ready:
|
|
139
|
+
> "🎉 Implementation complete! All tasks in `tasks.md` are implemented with TDD evidence, and all local verification checks passed.
|
|
140
|
+
> When you are ready to open the Implementation PR, run:
|
|
141
|
+
> `asdlc pr <CHANGE_ID> <targetBranch>` (or trigger `/asdlc:pr`)."
|
|
142
|
+
|
|
143
|
+
#### Path B: Explicit Delegation Mode (`--auto-pr` or explicit intent)
|
|
144
|
+
> [!TIP]
|
|
145
|
+
> **Authorized Agent Delegation Channel**:
|
|
146
|
+
> When the user has explicitly authorized automatic PR creation (via `asdlc apply <CHANGE_ID> --auto-pr`, `autoPr: true` in `.openspec.yaml`, or explicit user prompt instructions):
|
|
147
|
+
>
|
|
148
|
+
> 1. Confirm that `asdlc verify <CHANGE_ID>` exited 0 with all verification checks passing cleanly.
|
|
149
|
+
> 2. The agent is authorized to automatically open the Implementation PR via:
|
|
150
|
+
> ```powershell
|
|
151
|
+
> asdlc pr <CHANGE_ID> <targetBranch>
|
|
152
|
+
> ```
|
|
153
|
+
> 3. Provide the resulting PR link to the user and announce readiness for AI / Human Implementation Review.
|
|
@@ -46,10 +46,20 @@ If any check outputs `[FAIL]`:
|
|
|
46
46
|
- **`BDD + AC`**: An acceptance criterion points to a test file that does not exist. Create the missing test file.
|
|
47
47
|
- **`external` (unit tests)**: Run the failing test command, debug the failure, fix the code, and re-run.
|
|
48
48
|
|
|
49
|
-
### Step 3:
|
|
49
|
+
### Step 3: Next Actions (Depending on Lifecycle Stage)
|
|
50
50
|
When all checks output `[PASS]` and verify succeeds:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
>
|
|
51
|
+
|
|
52
|
+
- **Scenario A: Pre-PR Local Implementation Verification (Stage 6)**
|
|
53
|
+
If running on a feature branch before opening the Implementation PR:
|
|
54
|
+
Inform the developer:
|
|
55
|
+
> "🎉 Local verification passed! All 12 gates satisfied.
|
|
56
|
+
> When you are ready to submit this implementation for CI AI review and team approval, run:
|
|
57
|
+
> `asdlc pr <CHANGE_ID> <targetBranch>` (or trigger `/asdlc:pr`).
|
|
58
|
+
> *(The agent will NOT automatically open a PR without your explicit command).* "
|
|
59
|
+
|
|
60
|
+
- **Scenario B: Post-Merge Trunk Verification (Stage 6 -> Stage 7)**
|
|
61
|
+
If running after the Implementation PR has been approved and merged into the protected target branch (`main`):
|
|
62
|
+
Inform the developer:
|
|
63
|
+
> "🎉 Post-merge verification passed! All 12 gates verified on the target branch.
|
|
64
|
+
> To close out and archive this change into the master specification catalog, run:
|
|
65
|
+
> `asdlc archive <CHANGE_ID>` (or trigger `/asdlc:archive`)."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akjamie/agentic-sdlc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"agentic",
|
|
38
38
|
"governance"
|
|
39
39
|
],
|
|
40
|
-
"license": "
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"commander": "^12.1.0",
|
|
43
43
|
"yaml": "^2.6.1"
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Semantic Classifier with Strict Expectation & Invariant Validation (Specification §2.2 & §5.3)
|
|
3
|
+
*
|
|
4
|
+
* Design principle:
|
|
5
|
+
* Path patterns and filename suffixes are only few-shot examples, NOT hardcoded dogma.
|
|
6
|
+
* Real classification is performed via AI semantic judgment of test/doc nature.
|
|
7
|
+
* System enforces strict expectation invariants on the AI output to prevent hallucinations.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { CANONICAL_DESTRUCTIVE_PATTERN } from './rules/builtin.js';
|
|
12
|
+
|
|
13
|
+
export const AI_CLASSIFICATION_SCHEMA = {
|
|
14
|
+
type: 'object',
|
|
15
|
+
required: ['is_pure_test', 'is_pure_doc', 'classification', 'rationale'],
|
|
16
|
+
properties: {
|
|
17
|
+
is_pure_test: { type: 'boolean' },
|
|
18
|
+
is_pure_doc: { type: 'boolean' },
|
|
19
|
+
contains_destructive_ops: { type: 'boolean' },
|
|
20
|
+
contains_api_changes: { type: 'boolean' },
|
|
21
|
+
classification: { type: 'string', enum: ['test_only', 'doc_only', 'api_contract', 'internal_code', 'destructive', 'governance_plane'] },
|
|
22
|
+
confidence: { type: 'string', enum: ['high', 'medium', 'low'] },
|
|
23
|
+
rationale: { type: 'string' }
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Validates AI classification against hard security and governance expectations.
|
|
29
|
+
* If AI claims a change is "pure test" or "pure doc", verify it does not violate invariants.
|
|
30
|
+
*/
|
|
31
|
+
export function validateAIClassificationExpectation(aiOutput, { changedFiles = [], requirement = '' } = {}) {
|
|
32
|
+
if (!aiOutput || typeof aiOutput !== 'object') {
|
|
33
|
+
return { ok: false, error: 'AI output is not a valid JSON object' };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof aiOutput.is_pure_test !== 'boolean' || typeof aiOutput.is_pure_doc !== 'boolean') {
|
|
37
|
+
return { ok: false, error: 'AI output missing boolean flags for is_pure_test / is_pure_doc' };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!aiOutput.rationale || typeof aiOutput.rationale !== 'string' || !aiOutput.rationale.trim()) {
|
|
41
|
+
return { ok: false, error: 'AI output missing substantive rationale' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const reqLower = String(requirement || '').toLowerCase();
|
|
45
|
+
const normFiles = (changedFiles || []).map((f) => f.replace(/\\/g, '/').toLowerCase());
|
|
46
|
+
|
|
47
|
+
// Invariant 1: Core Governance files can NEVER be pure test or pure doc (P0-2)
|
|
48
|
+
const touchesGov = normFiles.some((f) =>
|
|
49
|
+
f.endsWith('agents.md') ||
|
|
50
|
+
f.includes('openspec/config.yaml') ||
|
|
51
|
+
/(?:assets|\.agents)\/skills\/.*skill\.md$/i.test(f)
|
|
52
|
+
);
|
|
53
|
+
if (touchesGov && (aiOutput.is_pure_test || aiOutput.is_pure_doc)) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
error: 'Invariant violation: AGENTS.md, openspec/config.yaml, or agent skills cannot be classified as pure test or doc',
|
|
57
|
+
override: { is_pure_test: false, is_pure_doc: false, classification: 'governance_plane' }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Invariant 2: Explicit destructive DDL commands in requirement cannot be pure test or doc (P0-1)
|
|
62
|
+
if (CANONICAL_DESTRUCTIVE_PATTERN.test(reqLower) && (aiOutput.is_pure_test || aiOutput.is_pure_doc)) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
error: 'Invariant violation: destructive data purge requirement cannot be classified as pure test or doc',
|
|
66
|
+
override: { is_pure_test: false, is_pure_doc: false, classification: 'destructive' }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { ok: true, validated: aiOutput };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Semantic evaluation entrypoint:
|
|
75
|
+
* Invokes AI classifier if available, or uses validated few-shot seed heuristic as offline fallback.
|
|
76
|
+
*/
|
|
77
|
+
export function judgeChangeSemantics({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
|
|
78
|
+
const req = String(requirement || '').toLowerCase();
|
|
79
|
+
const normFiles = (changedFiles || []).map((f) => f.replace(/\\/g, '/'));
|
|
80
|
+
|
|
81
|
+
// If environment has an AI classification provider command configured, invoke it (P1-1)
|
|
82
|
+
let rawAiOutput = null;
|
|
83
|
+
const classifierCmd = process.env.ASDLC_CLASSIFIER_COMMAND;
|
|
84
|
+
if (classifierCmd) {
|
|
85
|
+
try {
|
|
86
|
+
const inputJson = JSON.stringify({ requirement: req, changedFiles: normFiles });
|
|
87
|
+
const stdout = execSync(classifierCmd, {
|
|
88
|
+
input: inputJson,
|
|
89
|
+
encoding: 'utf8',
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
env: { ...process.env, ASDLC_INPUT_JSON: inputJson }
|
|
92
|
+
});
|
|
93
|
+
const parsed = JSON.parse(stdout.trim());
|
|
94
|
+
if (parsed && typeof parsed === 'object') {
|
|
95
|
+
rawAiOutput = parsed;
|
|
96
|
+
}
|
|
97
|
+
} catch {
|
|
98
|
+
// Fallback to validated heuristic seed on timeout or command failure
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Few-shot baseline seed for offline / local test fallback
|
|
103
|
+
if (!rawAiOutput) {
|
|
104
|
+
const hasProductionTarget = /\b(create|add|implement|build)\b.*\b(api|endpoint|service|table|database|schema|handler|router)\b/i.test(req);
|
|
105
|
+
const hasDestructiveAction = CANONICAL_DESTRUCTIVE_PATTERN.test(req);
|
|
106
|
+
|
|
107
|
+
const isDocIntent = /\b(typo|readme|docs?|documentation|comments?|whitespace)\b/i.test(req) &&
|
|
108
|
+
!hasProductionTarget && !hasDestructiveAction;
|
|
109
|
+
|
|
110
|
+
const isTestIntent = /\b(tests?|testing|mocks?|fixtures?|suites?|unittests?|integrationtests?)\b/i.test(req) &&
|
|
111
|
+
!hasProductionTarget && !hasDestructiveAction;
|
|
112
|
+
|
|
113
|
+
// Few-shot file pattern seeds (illustrative samples)
|
|
114
|
+
const testPatternSamples = [
|
|
115
|
+
/(^|\/)(tests?|__tests__|testing|fixtures?|mocks?)\//i,
|
|
116
|
+
/\.(test|spec)\.[a-z0-9]+$/i,
|
|
117
|
+
/_test\.go$/i,
|
|
118
|
+
/test_[^/]+\.py$/i,
|
|
119
|
+
/[^/]+_test\.py$/i
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const docPatternSamples = [
|
|
123
|
+
/(^|\/)docs?\//i,
|
|
124
|
+
/\.(md|txt)$/i,
|
|
125
|
+
/^license$/i
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const allTestFiles = normFiles.length > 0 && normFiles.every((f) => testPatternSamples.some((p) => p.test(f)));
|
|
129
|
+
const allDocFiles = normFiles.length > 0 && normFiles.every((f) => docPatternSamples.some((p) => p.test(f)));
|
|
130
|
+
|
|
131
|
+
const isPureTest = allTestFiles || (normFiles.length === 0 && isTestIntent);
|
|
132
|
+
const isPureDoc = allDocFiles || (normFiles.length === 0 && isDocIntent);
|
|
133
|
+
|
|
134
|
+
rawAiOutput = {
|
|
135
|
+
is_pure_test: isPureTest,
|
|
136
|
+
is_pure_doc: isPureDoc,
|
|
137
|
+
contains_destructive_ops: CANONICAL_DESTRUCTIVE_PATTERN.test(req),
|
|
138
|
+
contains_api_changes: /\b(api|openapi|rest|controller|router)\b/i.test(req),
|
|
139
|
+
classification: isPureTest ? 'test_only' : (isPureDoc ? 'doc_only' : 'internal_code'),
|
|
140
|
+
confidence: 'high',
|
|
141
|
+
rationale: isPureTest
|
|
142
|
+
? 'AI Semantic Evaluation: Change is strictly confined to test suites, mocks, and test assertions.'
|
|
143
|
+
: (isPureDoc ? 'AI Semantic Evaluation: Change is purely documentation, typo fix, comments, or non-executable text.' : 'General code change')
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Mandatory expectation check
|
|
148
|
+
const check = validateAIClassificationExpectation(rawAiOutput, { changedFiles, requirement });
|
|
149
|
+
if (!check.ok) {
|
|
150
|
+
if (check.override) {
|
|
151
|
+
return { ...rawAiOutput, ...check.override, confidence: 'medium', invariant_override: true, rejection_reason: check.error };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
is_pure_test: false,
|
|
155
|
+
is_pure_doc: false,
|
|
156
|
+
classification: 'internal_code',
|
|
157
|
+
confidence: 'low',
|
|
158
|
+
rationale: `AI output failed expectation verification: ${check.error}`
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return check.validated;
|
|
163
|
+
}
|