@akjamie/agentic-sdlc 1.3.0 → 1.5.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 +48 -24
- package/assets/commands/asdlc-apply.md +24 -0
- package/assets/commands/asdlc-approve.md +21 -0
- package/assets/commands/asdlc-archive.md +21 -0
- package/assets/commands/asdlc-doctor.md +24 -0
- package/assets/commands/asdlc-lint.md +30 -0
- package/assets/commands/asdlc-new.md +29 -0
- package/assets/commands/asdlc-pr.md +25 -0
- package/assets/commands/asdlc-status.md +23 -0
- package/assets/commands/asdlc-test.md +20 -0
- package/assets/commands/asdlc-verify.md +29 -0
- package/assets/schema/risk-assessment.schema.json +2 -1
- package/assets/skills/asdlc-apply/SKILL.md +1 -1
- package/assets/skills/asdlc-approve/SKILL.md +1 -1
- package/assets/skills/asdlc-impl-review/SKILL.md +13 -11
- package/assets/skills/asdlc-new/SKILL.md +20 -3
- package/assets/skills/asdlc-spec-review/SKILL.md +8 -6
- package/package.json +1 -1
- package/src/assess/ai_judge.js +70 -33
- package/src/assess/decide.js +8 -6
- package/src/assess/index.js +13 -3
- package/src/assess/rules/builtin.js +6 -1
- package/src/assess/schema.js +6 -1
- package/src/assess/vectors/v1_intent.js +53 -8
- package/src/assess/vectors/v3_topology.js +97 -3
- package/src/cli.js +1 -1
- package/src/commands/apply.js +32 -3
- package/src/commands/doctor.js +32 -4
- package/src/commands/init.js +5 -55
- package/src/commands/lint.js +41 -4
- package/src/commands/new.js +23 -22
- package/src/commands/skills.js +7 -19
- package/src/commands/status.js +170 -9
- package/src/commands/test.js +31 -4
- package/src/commands/update.js +4 -3
- package/src/commands/verify.js +47 -20
- package/src/lib/graphify.js +67 -3
- package/src/lib/paths.js +1 -0
- package/src/lib/speclint.js +5 -3
- package/src/lib/tdd.js +6 -2
- package/src/lib/tools.js +313 -0
package/src/assess/ai_judge.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Agent-Native Semantic Evaluation with Strict Expectation & Invariant Validation (Specification §2.2 & §5.3)
|
|
3
3
|
*
|
|
4
4
|
* Design principle:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Classification is performed natively by the executing AI Agent within its live reasoning session,
|
|
6
|
+
* supplemented by environment hooks and validated baseline heuristics.
|
|
7
|
+
* The system enforces strict expectation invariants on the semantic output to prevent hallucinations.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { execSync } from 'node:child_process';
|
|
11
|
-
import { CANONICAL_DESTRUCTIVE_PATTERN } from './rules/builtin.js';
|
|
11
|
+
import { CANONICAL_DESTRUCTIVE_PATTERN, isTestOrDocFile, isChangeMetadataFile } from './rules/builtin.js';
|
|
12
12
|
|
|
13
13
|
export const AI_CLASSIFICATION_SCHEMA = {
|
|
14
14
|
type: 'object',
|
|
15
|
-
required: ['is_pure_test', 'is_pure_doc', 'classification', 'rationale'],
|
|
15
|
+
required: ['is_pure_test', 'is_pure_doc', 'classification', 'rationale', 'evaluator_mode'],
|
|
16
16
|
properties: {
|
|
17
17
|
is_pure_test: { type: 'boolean' },
|
|
18
18
|
is_pure_doc: { type: 'boolean' },
|
|
@@ -20,6 +20,7 @@ export const AI_CLASSIFICATION_SCHEMA = {
|
|
|
20
20
|
contains_api_changes: { type: 'boolean' },
|
|
21
21
|
classification: { type: 'string', enum: ['test_only', 'doc_only', 'api_contract', 'internal_code', 'destructive', 'governance_plane'] },
|
|
22
22
|
confidence: { type: 'string', enum: ['high', 'medium', 'low'] },
|
|
23
|
+
evaluator_mode: { type: 'string', enum: ['agent_native', 'llm_classifier', 'heuristic_seed'] },
|
|
23
24
|
rationale: { type: 'string' }
|
|
24
25
|
}
|
|
25
26
|
};
|
|
@@ -67,39 +68,69 @@ export function validateAIClassificationExpectation(aiOutput, { changedFiles = [
|
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
// Invariant 3: Production source code files cannot be disguised as pure test or doc
|
|
72
|
+
// Exclude per-change SDLC metadata artifacts (openspec/changes/<id>/*) which accompany every branch
|
|
73
|
+
const substantiveFiles = normFiles.filter((f) => !isChangeMetadataFile(f));
|
|
74
|
+
const touchesProductionCode = substantiveFiles.some((f) => !isTestOrDocFile(f));
|
|
75
|
+
if (touchesProductionCode && (aiOutput.is_pure_test || aiOutput.is_pure_doc)) {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
error: 'Invariant violation: changes touching production source files cannot be classified as pure test or doc',
|
|
79
|
+
override: { is_pure_test: false, is_pure_doc: false, classification: 'internal_code' }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
70
83
|
return { ok: true, validated: aiOutput };
|
|
71
84
|
}
|
|
72
85
|
|
|
73
86
|
/**
|
|
74
87
|
* Semantic evaluation entrypoint:
|
|
75
|
-
*
|
|
88
|
+
* Grounded in Agent session reasoning, environment model hooks, or validated heuristic baseline.
|
|
76
89
|
*/
|
|
77
|
-
export function judgeChangeSemantics({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
|
|
90
|
+
export function judgeChangeSemantics({ requirement = '', changedFiles = [], repoRoot = null, agentContext = null } = {}) {
|
|
78
91
|
const req = String(requirement || '').toLowerCase();
|
|
79
92
|
const normFiles = (changedFiles || []).map((f) => f.replace(/\\/g, '/'));
|
|
80
93
|
|
|
81
|
-
// If environment has an AI classification provider command configured, invoke it (P1-1)
|
|
82
94
|
let rawAiOutput = null;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
|
|
96
|
+
// 1. Direct Agent-Native Evaluation:
|
|
97
|
+
// When running inside an AI coding agent session, accept verified semantic reasoning from the agent
|
|
98
|
+
if (agentContext && typeof agentContext === 'object') {
|
|
99
|
+
rawAiOutput = {
|
|
100
|
+
is_pure_test: Boolean(agentContext.is_pure_test),
|
|
101
|
+
is_pure_doc: Boolean(agentContext.is_pure_doc),
|
|
102
|
+
contains_destructive_ops: Boolean(agentContext.contains_destructive_ops || CANONICAL_DESTRUCTIVE_PATTERN.test(req)),
|
|
103
|
+
contains_api_changes: Boolean(agentContext.contains_api_changes),
|
|
104
|
+
classification: agentContext.classification || (agentContext.is_pure_test ? 'test_only' : (agentContext.is_pure_doc ? 'doc_only' : 'internal_code')),
|
|
105
|
+
confidence: agentContext.confidence || 'high',
|
|
106
|
+
evaluator_mode: 'agent_native',
|
|
107
|
+
rationale: agentContext.rationale || 'Evaluated natively by executing AI Agent in active session'
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 2. External Provider Command (if configured via environment hook)
|
|
112
|
+
if (!rawAiOutput) {
|
|
113
|
+
const classifierCmd = process.env.ASDLC_CLASSIFIER_COMMAND;
|
|
114
|
+
if (classifierCmd) {
|
|
115
|
+
try {
|
|
116
|
+
const inputJson = JSON.stringify({ requirement: req, changedFiles: normFiles });
|
|
117
|
+
const stdout = execSync(classifierCmd, {
|
|
118
|
+
input: inputJson,
|
|
119
|
+
encoding: 'utf8',
|
|
120
|
+
timeout: 5000,
|
|
121
|
+
env: { ...process.env, ASDLC_INPUT_JSON: inputJson }
|
|
122
|
+
});
|
|
123
|
+
const parsed = JSON.parse(stdout.trim());
|
|
124
|
+
if (parsed && typeof parsed === 'object') {
|
|
125
|
+
rawAiOutput = { ...parsed, evaluator_mode: 'llm_classifier' };
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
// Fallback to baseline heuristic on timeout or execution failure
|
|
96
129
|
}
|
|
97
|
-
} catch {
|
|
98
|
-
// Fallback to validated heuristic seed on timeout or command failure
|
|
99
130
|
}
|
|
100
131
|
}
|
|
101
132
|
|
|
102
|
-
//
|
|
133
|
+
// 3. Validated baseline heuristic seed (deterministic fallback for standalone CLI execution)
|
|
103
134
|
if (!rawAiOutput) {
|
|
104
135
|
const hasProductionTarget = /\b(create|add|implement|build)\b.*\b(api|endpoint|service|table|database|schema|handler|router)\b/i.test(req);
|
|
105
136
|
const hasDestructiveAction = CANONICAL_DESTRUCTIVE_PATTERN.test(req);
|
|
@@ -125,36 +156,42 @@ export function judgeChangeSemantics({ requirement = '', changedFiles = [], repo
|
|
|
125
156
|
/^license$/i
|
|
126
157
|
];
|
|
127
158
|
|
|
128
|
-
const
|
|
129
|
-
const
|
|
159
|
+
const substantiveFiles = normFiles.filter((f) => !isChangeMetadataFile(f));
|
|
160
|
+
const allTestFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => testPatternSamples.some((p) => p.test(f)));
|
|
161
|
+
const allDocFiles = substantiveFiles.length > 0 && substantiveFiles.every((f) => docPatternSamples.some((p) => p.test(f)));
|
|
130
162
|
|
|
131
|
-
const isPureTest = allTestFiles || (
|
|
132
|
-
const isPureDoc = allDocFiles || (
|
|
163
|
+
const isPureTest = allTestFiles || (substantiveFiles.length === 0 && isTestIntent);
|
|
164
|
+
const isPureDoc = allDocFiles || (substantiveFiles.length === 0 && isDocIntent);
|
|
133
165
|
|
|
134
166
|
rawAiOutput = {
|
|
135
167
|
is_pure_test: isPureTest,
|
|
136
168
|
is_pure_doc: isPureDoc,
|
|
137
169
|
contains_destructive_ops: CANONICAL_DESTRUCTIVE_PATTERN.test(req),
|
|
138
|
-
contains_api_changes:
|
|
170
|
+
contains_api_changes: false,
|
|
139
171
|
classification: isPureTest ? 'test_only' : (isPureDoc ? 'doc_only' : 'internal_code'),
|
|
140
172
|
confidence: 'high',
|
|
173
|
+
evaluator_mode: 'heuristic_seed',
|
|
141
174
|
rationale: isPureTest
|
|
142
|
-
? '
|
|
143
|
-
: (isPureDoc ? '
|
|
175
|
+
? 'Deterministic Heuristic Baseline: Change is strictly confined to test suites, mocks, and test assertions.'
|
|
176
|
+
: (isPureDoc ? 'Deterministic Heuristic Baseline: Change is purely documentation, typo fix, comments, or non-executable text.' : 'Deterministic Heuristic Baseline: General code change')
|
|
144
177
|
};
|
|
178
|
+
} else {
|
|
179
|
+
rawAiOutput.evaluator_mode = rawAiOutput.evaluator_mode || 'llm_classifier';
|
|
145
180
|
}
|
|
146
181
|
|
|
147
182
|
// Mandatory expectation check
|
|
148
183
|
const check = validateAIClassificationExpectation(rawAiOutput, { changedFiles, requirement });
|
|
149
184
|
if (!check.ok) {
|
|
185
|
+
const mode = rawAiOutput?.evaluator_mode || 'heuristic_seed';
|
|
150
186
|
if (check.override) {
|
|
151
|
-
return { ...rawAiOutput, ...check.override, confidence: 'medium', invariant_override: true, rejection_reason: check.error };
|
|
187
|
+
return { ...rawAiOutput, ...check.override, evaluator_mode: mode, confidence: 'medium', invariant_override: true, rejection_reason: check.error };
|
|
152
188
|
}
|
|
153
189
|
return {
|
|
154
190
|
is_pure_test: false,
|
|
155
191
|
is_pure_doc: false,
|
|
156
192
|
classification: 'internal_code',
|
|
157
193
|
confidence: 'low',
|
|
194
|
+
evaluator_mode: mode,
|
|
158
195
|
rationale: `AI output failed expectation verification: ${check.error}`
|
|
159
196
|
};
|
|
160
197
|
}
|
package/src/assess/decide.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LEVEL_RANK, DEFAULT_GOVERNANCE, L0_DETERMINISTIC_PATTERNS } from './rules/builtin.js';
|
|
1
|
+
import { LEVEL_RANK, DEFAULT_GOVERNANCE, L0_DETERMINISTIC_PATTERNS, isChangeMetadataFile } from './rules/builtin.js';
|
|
2
2
|
import { judgeChangeSemantics } from './ai_judge.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -57,12 +57,14 @@ export function decideAssessment({
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
const req = v1.requirement || '';
|
|
60
|
-
const aiJudgment = judgeChangeSemantics({ requirement: req, changedFiles });
|
|
60
|
+
const aiJudgment = v1.aiJudgment || judgeChangeSemantics({ requirement: req, changedFiles });
|
|
61
61
|
|
|
62
62
|
if (!hasMandatoryHumanReview && maxRank <= 1) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const substantiveFiles = changedFiles
|
|
64
|
+
.map((f) => f.replace(/\\/g, '/'))
|
|
65
|
+
.filter((f) => !isChangeMetadataFile(f));
|
|
66
|
+
if (substantiveFiles.length > 0) {
|
|
67
|
+
const allDoc = substantiveFiles.every((f) => L0_DETERMINISTIC_PATTERNS.some((p) => p.test(f)));
|
|
66
68
|
if (allDoc || aiJudgment.is_pure_doc || aiJudgment.is_pure_test) {
|
|
67
69
|
calculatedLevel = 'L0';
|
|
68
70
|
}
|
|
@@ -114,7 +116,7 @@ export function decideAssessment({
|
|
|
114
116
|
} else if (highestRank > baseRank) {
|
|
115
117
|
direction = 'same';
|
|
116
118
|
triggers.push(`Level remains escalated at ${finalLevel} above baseline ${baselineLevel}`);
|
|
117
|
-
if (stage === 'impl') {
|
|
119
|
+
if (stage === 'impl' && (previous?.reason_codes || []).includes('ESCALATED_IN_IMPL')) {
|
|
118
120
|
reason_codes.push('ESCALATED_IN_IMPL');
|
|
119
121
|
}
|
|
120
122
|
} else {
|
package/src/assess/index.js
CHANGED
|
@@ -38,6 +38,7 @@ export function assess({
|
|
|
38
38
|
|
|
39
39
|
// If requirement is empty or for spec stage, load proposal.md and design.md from change dir
|
|
40
40
|
let effectiveReq = requirement || '';
|
|
41
|
+
let agentContext = null;
|
|
41
42
|
if (repoRoot && changeId) {
|
|
42
43
|
try {
|
|
43
44
|
const cdir = changeDir(repoRoot, changeId);
|
|
@@ -46,13 +47,21 @@ export function assess({
|
|
|
46
47
|
const propText = fs.readFileSync(propPath, 'utf8');
|
|
47
48
|
effectiveReq = `${effectiveReq}\n${propText}`.trim();
|
|
48
49
|
}
|
|
50
|
+
|
|
51
|
+
// Check if change contains agent assessment context (.agent-assess.json or .openspec.yaml assessment)
|
|
52
|
+
const agentCtxPath = path.join(cdir, '.agent-assess.json');
|
|
53
|
+
if (fs.existsSync(agentCtxPath)) {
|
|
54
|
+
try {
|
|
55
|
+
agentContext = JSON.parse(fs.readFileSync(agentCtxPath, 'utf8'));
|
|
56
|
+
} catch { /* ignore parse error */ }
|
|
57
|
+
}
|
|
49
58
|
} catch { /* ignore read failure */ }
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
// 1. Evaluate Three Risk Vectors
|
|
53
|
-
const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType });
|
|
62
|
+
const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType, agentContext });
|
|
54
63
|
const v2 = evaluateV2Security({ requirement: effectiveReq, changedFiles, repoRoot });
|
|
55
|
-
const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot });
|
|
64
|
+
const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot, changeId });
|
|
56
65
|
|
|
57
66
|
// Inferred or provided Change Type
|
|
58
67
|
const effectiveType = changeType || v1.inferredType || 'change';
|
|
@@ -101,6 +110,7 @@ export function assess({
|
|
|
101
110
|
v1_intent: {
|
|
102
111
|
level: v1.level,
|
|
103
112
|
confidence: v1.confidence,
|
|
113
|
+
evaluator_mode: v1.evaluator_mode || 'heuristic_seed',
|
|
104
114
|
evidence: v1.evidence,
|
|
105
115
|
unresolved: v1.unresolved,
|
|
106
116
|
mandatory_human_review: v1.mandatory_human_review,
|
|
@@ -161,7 +171,7 @@ export function assess({
|
|
|
161
171
|
confidence: 'low'
|
|
162
172
|
},
|
|
163
173
|
vectors: {
|
|
164
|
-
v1_intent: { level: 'L2', confidence: 'low', evidence: [], unresolved: [err.message], mandatory_human_review: true, no_signal: false },
|
|
174
|
+
v1_intent: { level: 'L2', confidence: 'low', evaluator_mode: 'heuristic_seed', evidence: [], unresolved: [err.message], mandatory_human_review: true, no_signal: false },
|
|
165
175
|
v2_security: { level: 'L2', confidence: 'low', evidence: [], unresolved: [err.message], mandatory_human_review: true, no_signal: false },
|
|
166
176
|
v3_topology: { level: 'L2', confidence: 'low', evidence: [], unresolved: [err.message], mandatory_human_review: true, no_signal: false }
|
|
167
177
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const HARNESS_RULES_VERSION = '2026.10.0';
|
|
2
|
-
export const ENGINE_VERSION = '1.
|
|
2
|
+
export const ENGINE_VERSION = '1.5.0';
|
|
3
3
|
|
|
4
4
|
export const RISK_LEVELS = {
|
|
5
5
|
L0: 'L0',
|
|
@@ -181,6 +181,11 @@ export const TEST_AND_DOC_PATTERNS = [
|
|
|
181
181
|
/(^|\/)assets\/(?:images|media|icons|fonts)\//i
|
|
182
182
|
];
|
|
183
183
|
|
|
184
|
+
export function isChangeMetadataFile(filePath = '') {
|
|
185
|
+
const norm = String(filePath).replace(/\\/g, '/');
|
|
186
|
+
return /(^|\/)openspec\/changes\/[^/]+\//i.test(norm);
|
|
187
|
+
}
|
|
188
|
+
|
|
184
189
|
export function isTestOrDocFile(filePath = '') {
|
|
185
190
|
const norm = String(filePath).replace(/\\/g, '/');
|
|
186
191
|
if (
|
package/src/assess/schema.js
CHANGED
|
@@ -84,6 +84,11 @@ export function validateRecordSchema(record) {
|
|
|
84
84
|
errors.push('status defaulted requires non-null defaulted_cause');
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
const evalMode = record.vectors?.v1_intent?.evaluator_mode;
|
|
88
|
+
if (evalMode !== undefined && !['agent_native', 'llm_classifier', 'heuristic_seed'].includes(evalMode)) {
|
|
89
|
+
errors.push(`Invalid v1_intent.evaluator_mode: ${evalMode}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
87
92
|
if (record.hash && computeRecordHash(record) !== record.hash) {
|
|
88
93
|
errors.push(`Hash mismatch: computed ${computeRecordHash(record)} vs declared ${record.hash}`);
|
|
89
94
|
}
|
|
@@ -115,7 +120,7 @@ export function validateChainInvariants(records = []) {
|
|
|
115
120
|
errors.push(`Record at index ${i} has seq ${rec.seq}, expected ${expectedSeq}`);
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
//
|
|
123
|
+
// SHA-256 content hash chain integrity (P1-3)
|
|
119
124
|
const computed = computeRecordHash(rec);
|
|
120
125
|
if (rec.hash && computed !== rec.hash) {
|
|
121
126
|
errors.push(`Record ${rec.seq} hash mismatch: computed ${computed} vs declared ${rec.hash}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LEVEL_RANK, CANONICAL_DESTRUCTIVE_PATTERN } from '../rules/builtin.js';
|
|
2
2
|
import { judgeChangeSemantics } from '../ai_judge.js';
|
|
3
3
|
|
|
4
|
-
export function evaluateV1Intent({ requirement = '', specDelta = '', changedFiles = [], changeType = null } = {}) {
|
|
4
|
+
export function evaluateV1Intent({ requirement = '', specDelta = '', changedFiles = [], changeType = null, agentContext = null } = {}) {
|
|
5
5
|
const req = String(requirement || '').toLowerCase();
|
|
6
6
|
const evidence = [];
|
|
7
7
|
const unresolved = [];
|
|
@@ -36,10 +36,48 @@ export function evaluateV1Intent({ requirement = '', specDelta = '', changedFile
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// 2.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
// 2. Semantic Evaluation: Agent Native Evaluation, External LLM Classifier, or Heuristic Baseline
|
|
40
|
+
const aiJudgment = judgeChangeSemantics({ requirement: req, changedFiles, agentContext });
|
|
41
|
+
const evalMode = aiJudgment.evaluator_mode || 'heuristic_seed';
|
|
42
|
+
const isAiMode = evalMode !== 'heuristic_seed';
|
|
43
|
+
|
|
44
|
+
// 2a. Agent / LLM Semantic Escalation (Bidirectional — never triggered by offline regex heuristic_seed):
|
|
45
|
+
if (isAiMode) {
|
|
46
|
+
if (aiJudgment.classification === 'api_contract' || aiJudgment.contains_api_changes) {
|
|
47
|
+
if (level === 'L1') {
|
|
48
|
+
level = 'L2';
|
|
49
|
+
inferredType = inferredType === 'chore' ? 'change' : inferredType;
|
|
50
|
+
evidence.push({
|
|
51
|
+
id: 'V1_AI_API_CONTRACT_INTENT',
|
|
52
|
+
kind: 'semantic_intent',
|
|
53
|
+
signal: 'hard',
|
|
54
|
+
summary: aiJudgment.rationale || 'Agent Semantic Evaluation: Change modifies cross-boundary API contracts'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
} else if (aiJudgment.classification === 'destructive' || aiJudgment.contains_destructive_ops) {
|
|
58
|
+
level = 'L3';
|
|
59
|
+
mandatory_human_review = true;
|
|
60
|
+
evidence.push({
|
|
61
|
+
id: 'V1_AI_DESTRUCTIVE_INTENT',
|
|
62
|
+
kind: 'semantic_intent',
|
|
63
|
+
signal: 'hard',
|
|
64
|
+
summary: aiJudgment.rationale || 'Agent Semantic Evaluation: Task involves destructive data purge or drop'
|
|
65
|
+
});
|
|
66
|
+
} else if (aiJudgment.classification === 'governance_plane') {
|
|
67
|
+
level = 'L3';
|
|
68
|
+
mandatory_human_review = true;
|
|
69
|
+
evidence.push({
|
|
70
|
+
id: 'V1_AI_GOVERNANCE_INTENT',
|
|
71
|
+
kind: 'semantic_intent',
|
|
72
|
+
signal: 'hard',
|
|
73
|
+
summary: aiJudgment.rationale || 'Agent Semantic Evaluation: Task modifies core repository governance'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 2b. L0 Trivial Evaluation (only if no hard signals triggered)
|
|
79
|
+
if (!mandatory_human_review && level === 'L1') {
|
|
80
|
+
const modePrefix = isAiMode ? 'Agent Semantic Evaluation' : 'Deterministic Heuristic Baseline';
|
|
43
81
|
if (aiJudgment.is_pure_test) {
|
|
44
82
|
level = 'L0';
|
|
45
83
|
inferredType = 'chore';
|
|
@@ -47,7 +85,7 @@ export function evaluateV1Intent({ requirement = '', specDelta = '', changedFile
|
|
|
47
85
|
id: 'V1_AI_TEST_EVALUATION',
|
|
48
86
|
kind: 'scanner_result',
|
|
49
87
|
signal: 'soft',
|
|
50
|
-
summary: aiJudgment.rationale ||
|
|
88
|
+
summary: aiJudgment.rationale || `${modePrefix}: Change is strictly test suites/mocks (evaluated as L0 trivial/routine)`
|
|
51
89
|
});
|
|
52
90
|
} else if (aiJudgment.is_pure_doc) {
|
|
53
91
|
level = 'L0';
|
|
@@ -56,7 +94,7 @@ export function evaluateV1Intent({ requirement = '', specDelta = '', changedFile
|
|
|
56
94
|
id: 'V1_AI_DOC_EVALUATION',
|
|
57
95
|
kind: 'scanner_result',
|
|
58
96
|
signal: 'soft',
|
|
59
|
-
summary: aiJudgment.rationale ||
|
|
97
|
+
summary: aiJudgment.rationale || `${modePrefix}: Intent is purely documentation, typo, or comment editing`
|
|
60
98
|
});
|
|
61
99
|
}
|
|
62
100
|
}
|
|
@@ -71,10 +109,17 @@ export function evaluateV1Intent({ requirement = '', specDelta = '', changedFile
|
|
|
71
109
|
return {
|
|
72
110
|
level,
|
|
73
111
|
confidence,
|
|
112
|
+
evaluator_mode: evalMode,
|
|
74
113
|
inferredType,
|
|
75
114
|
evidence,
|
|
76
115
|
unresolved,
|
|
77
116
|
mandatory_human_review,
|
|
78
|
-
no_signal
|
|
117
|
+
no_signal,
|
|
118
|
+
requirement: effectiveReqSafe(req),
|
|
119
|
+
aiJudgment
|
|
79
120
|
};
|
|
80
121
|
}
|
|
122
|
+
|
|
123
|
+
function effectiveReqSafe(req) {
|
|
124
|
+
return req || '';
|
|
125
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { HARD_RULES, isTestOrDocFile } from '../rules/builtin.js';
|
|
3
|
+
import { HARD_RULES, isTestOrDocFile, isChangeMetadataFile } from '../rules/builtin.js';
|
|
4
|
+
import { getGraphTopologyMetrics } from '../../lib/graphify.js';
|
|
4
5
|
|
|
5
|
-
export function evaluateV3Topology({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
|
|
6
|
+
export function evaluateV3Topology({ requirement = '', changedFiles = [], repoRoot = null, changeId = null } = {}) {
|
|
6
7
|
const req = String(requirement || '').toLowerCase();
|
|
7
8
|
const evidence = [];
|
|
8
9
|
const unresolved = [];
|
|
@@ -72,7 +73,100 @@ export function evaluateV3Topology({ requirement = '', changedFiles = [], repoRo
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
// 2.
|
|
76
|
+
// 2. Graphify AST Knowledge Graph Centrality & God Nodes Check
|
|
77
|
+
// Escalates to L2 if changed files touch architectural hubs with high cross-file fan-in
|
|
78
|
+
if (repoRoot) {
|
|
79
|
+
try {
|
|
80
|
+
const topoMetrics = getGraphTopologyMetrics(repoRoot);
|
|
81
|
+
if (topoMetrics.available && topoMetrics.fileInDegree) {
|
|
82
|
+
// High centrality threshold: >= 20 cross-file inbound dependencies
|
|
83
|
+
// Exclude purely peripheral utility loggers or formats
|
|
84
|
+
const GOD_NODE_THRESHOLD = 20;
|
|
85
|
+
const hitHubs = [];
|
|
86
|
+
|
|
87
|
+
const substantiveFiles = changedFiles.filter((f) => !isChangeMetadataFile(f));
|
|
88
|
+
|
|
89
|
+
// Check 1: Physical changed files
|
|
90
|
+
for (const f of substantiveFiles) {
|
|
91
|
+
if (isTestOrDocFile(f)) continue;
|
|
92
|
+
const norm = f.replace(/\\/g, '/');
|
|
93
|
+
if (/(^|\/)(log|logger|logging|cliutil)\.[a-z0-9]+$/i.test(norm)) continue; // ignore pure logger / cli wrappers
|
|
94
|
+
const inDegree = topoMetrics.fileInDegree[norm] || 0;
|
|
95
|
+
if (inDegree >= GOD_NODE_THRESHOLD) {
|
|
96
|
+
hitHubs.push({ file: norm, inDegree });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Check 2: Pre-implementation stages (no substantive changedFiles yet) — ground in explore.md query
|
|
101
|
+
// IMPORTANT:
|
|
102
|
+
// a) Only inspect the ## Query: section (never the global ## Architectural hubs header).
|
|
103
|
+
// b) When Graphify outputs a BFS depth=2 traversal with `Start: [...]`, restrict matches to
|
|
104
|
+
// 0-hop Start nodes so 2-hop neighbor hubs (e.g. leaf -> caller -> fs.js) do not trigger false positives.
|
|
105
|
+
if (substantiveFiles.length === 0 && hitHubs.length === 0 && changeId) {
|
|
106
|
+
try {
|
|
107
|
+
const expPath = path.join(repoRoot, 'openspec', 'changes', changeId, 'explore.md');
|
|
108
|
+
if (fs.existsSync(expPath)) {
|
|
109
|
+
const expContent = fs.readFileSync(expPath, 'utf8');
|
|
110
|
+
const queryMatch = expContent.match(/##\s*Query:[^\n]*\n([\s\S]*?)(?:\n##\s|$)/i);
|
|
111
|
+
const queryContent = queryMatch ? queryMatch[1] : '';
|
|
112
|
+
if (queryContent && !queryContent.includes('_(no matches)_') && !queryContent.includes('_(unavailable')) {
|
|
113
|
+
const startHeaderMatch = queryContent.match(/\bStart:\s*\[([^\]]*)\]/);
|
|
114
|
+
let directHitFiles = null;
|
|
115
|
+
let startLabels = null;
|
|
116
|
+
|
|
117
|
+
if (startHeaderMatch) {
|
|
118
|
+
startLabels = new Set();
|
|
119
|
+
const rawList = startHeaderMatch[1];
|
|
120
|
+
for (const m of rawList.matchAll(/['"]([^'"]+)['"]/g)) {
|
|
121
|
+
startLabels.add(m[1].trim());
|
|
122
|
+
}
|
|
123
|
+
directHitFiles = new Set();
|
|
124
|
+
for (const m of queryContent.matchAll(/^NODE\s+(.+?)\s+\[src=([^\s\]]+)/gm)) {
|
|
125
|
+
const nodeLabel = m[1].trim();
|
|
126
|
+
const nodeSrc = m[2].replace(/\\/g, '/');
|
|
127
|
+
if (startLabels.has(nodeLabel) && !isTestOrDocFile(nodeSrc)) {
|
|
128
|
+
directHitFiles.add(nodeSrc);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const [hubFile, inDeg] of (topoMetrics.topHubs || [])) {
|
|
134
|
+
if (inDeg >= GOD_NODE_THRESHOLD && !/(^|\/)(log|logger|logging|cliutil)\.[a-z0-9]+$/i.test(hubFile)) {
|
|
135
|
+
const baseName = path.basename(hubFile);
|
|
136
|
+
const matched = directHitFiles !== null
|
|
137
|
+
? (directHitFiles.has(hubFile) || startLabels.has(hubFile) || startLabels.has(baseName))
|
|
138
|
+
: (queryContent.includes(hubFile) || queryContent.includes(baseName));
|
|
139
|
+
if (matched) {
|
|
140
|
+
hitHubs.push({ file: hubFile, inDegree: inDeg });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch { /* ignore explore read */ }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (hitHubs.length > 0) {
|
|
150
|
+
no_signal = false;
|
|
151
|
+
if (level === 'L1') {
|
|
152
|
+
level = 'L2';
|
|
153
|
+
}
|
|
154
|
+
const hubDesc = hitHubs.slice(0, 3).map((h) => `${h.file} (${h.inDegree} inbound refs)`).join(', ');
|
|
155
|
+
evidence.push({
|
|
156
|
+
id: 'V3_GRAPHIFY_GOD_NODE',
|
|
157
|
+
kind: 'topology_centrality',
|
|
158
|
+
signal: 'hard',
|
|
159
|
+
summary: `Touches Graphify AST architectural hub: ${hubDesc}`,
|
|
160
|
+
source: hitHubs[0].file
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
/* ignore graph metrics reading failure */
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 3. Check Requirement Semantics for Architecture / Schema / Infra
|
|
76
170
|
const topoKeywords = [
|
|
77
171
|
'api', 'endpoint', 'openapi', 'swagger', 'grpc', 'protobuf', 'graphql', 'webhook',
|
|
78
172
|
'fastapi', 'springboot', 'spring boot', 'controller', 'rest api', 'router',
|
package/src/cli.js
CHANGED
|
@@ -59,7 +59,7 @@ The flow:
|
|
|
59
59
|
asdlc archive <ID> finish: archive change + sync living specs to openspec/specs/
|
|
60
60
|
|
|
61
61
|
Navigation, health & maintenance:
|
|
62
|
-
asdlc status
|
|
62
|
+
asdlc status [ID] where a change is in the 7 stages (or portfolio overview if omitted)
|
|
63
63
|
asdlc doctor environment + repo setup health
|
|
64
64
|
asdlc update update repo state: skills, AST knowledge graph (KB) & AGENTS.md
|
|
65
65
|
asdlc upgrade [--global] upgrade asdlc CLI, openspec, graphify & managed schema
|
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 { assess } from '../assess/index.js';
|
|
9
10
|
|
|
10
11
|
// Guard before implementing: the spec must be APPROVED on the target branch
|
|
11
12
|
// (i.e. the Spec PR has been merged into targetBranch, locking proposal.md & specs/**).
|
|
@@ -15,7 +16,6 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
15
16
|
const cdir = changeDir(repoRoot, slug);
|
|
16
17
|
if (!exists(cdir)) fail(`change '${slug}' not found`);
|
|
17
18
|
|
|
18
|
-
// 1. Resolve target branch dynamically: CLI option -> .openspec.yaml -> git tracking -> main/master
|
|
19
19
|
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
20
20
|
let meta = {};
|
|
21
21
|
if (exists(metaPath)) {
|
|
@@ -49,7 +49,32 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
let effectiveLevel = levelInfo?.effectiveLevel || meta.level || null;
|
|
53
|
+
const agentAssessPath = path.join(cdir, '.agent-assess.json');
|
|
54
|
+
if (meta.level && (exists(agentAssessPath) || levelInfo?.maxHistoryLevel)) {
|
|
55
|
+
const assessment = assess({
|
|
56
|
+
stage: 'spec',
|
|
57
|
+
changeId: slug,
|
|
58
|
+
repoRoot,
|
|
59
|
+
persist: true
|
|
60
|
+
});
|
|
61
|
+
const assessedLevel = assessment.risk.level;
|
|
62
|
+
const rank = { L0: 0, L1: 1, L2: 2, L3: 3 };
|
|
63
|
+
if ((rank[assessedLevel] ?? 0) > (rank[effectiveLevel] ?? 0)) {
|
|
64
|
+
effectiveLevel = assessedLevel;
|
|
65
|
+
if (exists(metaPath)) {
|
|
66
|
+
let metaText = readText(metaPath);
|
|
67
|
+
const upsertKey = (text, key, val) => {
|
|
68
|
+
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
69
|
+
return re.test(text) ? text.replace(re, `${key}: "${val}"`) : `${text.trimEnd()}\n${key}: "${val}"\n`;
|
|
70
|
+
};
|
|
71
|
+
metaText = upsertKey(metaText, 'level', effectiveLevel);
|
|
72
|
+
metaText = upsertKey(metaText, 'workflowMode', assessment.governance.workflow_mode);
|
|
73
|
+
writeText(metaPath, metaText);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
53
78
|
const isSinglePr = isSinglePrLevel(effectiveLevel);
|
|
54
79
|
let approvedSha = null;
|
|
55
80
|
|
|
@@ -88,7 +113,7 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
88
113
|
});
|
|
89
114
|
}
|
|
90
115
|
|
|
91
|
-
// 4. Content-level
|
|
116
|
+
// 4. Content-level Git-anchored zero-diff invariant:
|
|
92
117
|
// The local spec content MUST match the approved version on the target branch
|
|
93
118
|
const diff = (git(['diff', approvedSha, '--', ...locked], repoRoot, { allowFail: true }) ?? '').trim();
|
|
94
119
|
if (diff) {
|
|
@@ -109,6 +134,10 @@ export function applyGuard(changeId, opts = {}) {
|
|
|
109
134
|
};
|
|
110
135
|
metaText = upsertKey(metaText, 'specSha', approvedSha);
|
|
111
136
|
metaText = upsertKey(metaText, 'status', 'ready_for_impl');
|
|
137
|
+
if (effectiveLevel && effectiveLevel !== meta.level) {
|
|
138
|
+
metaText = upsertKey(metaText, 'level', effectiveLevel);
|
|
139
|
+
metaText = upsertKey(metaText, 'workflowMode', 'spec-first');
|
|
140
|
+
}
|
|
112
141
|
writeText(metaPath, metaText);
|
|
113
142
|
}
|
|
114
143
|
log.ok(`${slug}: recognized PR approval on ${branch} (synced state to ready_for_impl @ ${approvedSha.slice(0, 8)})`);
|