@akjamie/agentic-sdlc 1.4.0 → 1.6.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 +57 -29
- package/assets/commands/asdlc-approve.md +2 -2
- package/assets/config/config.yaml +1 -1
- package/assets/policy/policy.yaml +6 -0
- package/assets/schema/risk-assessment.schema.json +2 -1
- package/assets/schema/schema.yaml +168 -168
- package/assets/skills/asdlc-apply/SKILL.md +1 -1
- package/assets/skills/asdlc-approve/SKILL.md +2 -2
- package/assets/skills/asdlc-archive/SKILL.md +17 -13
- package/assets/skills/asdlc-doctor/SKILL.md +8 -8
- package/assets/skills/asdlc-impl-review/SKILL.md +15 -25
- package/assets/skills/asdlc-init/SKILL.md +11 -18
- package/assets/skills/asdlc-new/SKILL.md +5 -2
- package/assets/skills/asdlc-pr/SKILL.md +13 -8
- package/assets/skills/asdlc-review/SKILL.md +7 -7
- package/assets/skills/asdlc-spec-review/SKILL.md +10 -20
- package/package.json +2 -1
- package/src/assess/ai_judge.js +106 -36
- package/src/assess/decide.js +8 -6
- package/src/assess/index.js +13 -3
- package/src/assess/rules/builtin.js +7 -2
- package/src/assess/schema.js +6 -1
- package/src/assess/vectors/v1_intent.js +53 -8
- package/src/assess/vectors/v2_security.js +24 -1
- package/src/assess/vectors/v3_topology.js +125 -13
- package/src/commands/apply.js +33 -4
- package/src/commands/approve.js +2 -3
- package/src/commands/archive.js +116 -64
- package/src/commands/doctor.js +22 -19
- package/src/commands/init.js +24 -50
- package/src/commands/lint.js +32 -2
- package/src/commands/new.js +23 -22
- package/src/commands/pr.js +106 -25
- package/src/commands/status.js +1 -1
- package/src/commands/test.js +101 -5
- package/src/commands/update.js +1 -11
- package/src/commands/verify.js +141 -34
- package/src/lib/agents.js +2 -2
- package/src/lib/cliutil.js +57 -7
- package/src/lib/git.js +10 -4
- package/src/lib/graphify.js +89 -14
- package/src/lib/level.js +63 -9
- package/src/lib/openspec.js +61 -31
- package/src/lib/paths.js +0 -2
- package/src/lib/policy.js +4 -0
- package/src/lib/schema.js +32 -11
- package/src/lib/speclint.js +5 -3
- package/src/lib/tdd.js +35 -11
- package/assets/ci/asdlc-ai-review.yml +0 -65
- package/assets/githooks/post-merge +0 -22
- package/assets/githooks/pre-push +0 -17
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,47 +68,110 @@ 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
|
+
|
|
83
|
+
// Invariant 4 (Escalate-Only Ratchet): When no substantive files exist yet (stage new / spec),
|
|
84
|
+
// author-agent self-assessment CANNOT claim pure_doc / pure_test unless the requirement text
|
|
85
|
+
// itself deterministically indicates test or documentation work without code/API/security intent.
|
|
86
|
+
if (substantiveFiles.length === 0 && reqLower.trim() && (aiOutput.is_pure_test || aiOutput.is_pure_doc)) {
|
|
87
|
+
const hasDocSignal = /(?:\b(?:docs?|documentation|readme|typo|typos|comments?|whitespace|changelog|markdown|license)\b|文档|注释|错别字|说明文档)/i.test(reqLower);
|
|
88
|
+
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(reqLower);
|
|
89
|
+
|
|
90
|
+
// Substantive code refactoring or implementation cannot be claimed as pure doc (e.g. "重构订单状态机并补充注释" is code, not doc)
|
|
91
|
+
const hasCodeRefactorOrMutation = /(?:\b(?:refactor|rewrite|redesign|state\s+machine)\b|重构|重写|状态机)/i.test(reqLower) ||
|
|
92
|
+
/\b(?:implement|build|create)\b.*\b(?:api|endpoint|service|controller|router|table|database|schema|handler)\b/i.test(reqLower) ||
|
|
93
|
+
/(?:实现|开发|创建|新增)\b.*(?:接口|服务|路由|数据表|表结构|控制器)/i.test(reqLower) ||
|
|
94
|
+
CANONICAL_DESTRUCTIVE_PATTERN.test(reqLower);
|
|
95
|
+
|
|
96
|
+
// Evaluate doc claim independently (prevents truth table bypass if both is_pure_doc and is_pure_test are set)
|
|
97
|
+
if (aiOutput.is_pure_doc && (!hasDocSignal || hasCodeRefactorOrMutation)) {
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
error: 'Invariant violation: agent assessment cannot downgrade code/architecture requirement to L0 doc_only',
|
|
101
|
+
override: { is_pure_test: false, is_pure_doc: false, classification: 'internal_code' }
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Evaluate test claim independently
|
|
106
|
+
if (aiOutput.is_pure_test && (!hasTestSignal || CANONICAL_DESTRUCTIVE_PATTERN.test(reqLower) || /(?:\b(?:refactor|rewrite|redesign)\b|重构|重写)/i.test(reqLower) || hasCodeRefactorOrMutation)) {
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
error: 'Invariant violation: agent assessment cannot downgrade destructive or refactoring requirement to L0 test_only',
|
|
110
|
+
override: { is_pure_test: false, is_pure_doc: false, classification: 'internal_code' }
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
70
115
|
return { ok: true, validated: aiOutput };
|
|
71
116
|
}
|
|
72
117
|
|
|
73
118
|
/**
|
|
74
119
|
* Semantic evaluation entrypoint:
|
|
75
|
-
*
|
|
120
|
+
* Grounded in Agent session reasoning, environment model hooks, or validated heuristic baseline.
|
|
76
121
|
*/
|
|
77
|
-
export function judgeChangeSemantics({ requirement = '', changedFiles = [], repoRoot = null } = {}) {
|
|
122
|
+
export function judgeChangeSemantics({ requirement = '', changedFiles = [], repoRoot = null, agentContext = null } = {}) {
|
|
78
123
|
const req = String(requirement || '').toLowerCase();
|
|
79
124
|
const normFiles = (changedFiles || []).map((f) => f.replace(/\\/g, '/'));
|
|
80
125
|
|
|
81
|
-
// If environment has an AI classification provider command configured, invoke it (P1-1)
|
|
82
126
|
let rawAiOutput = null;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
127
|
+
|
|
128
|
+
// 1. Direct Agent-Native Evaluation:
|
|
129
|
+
// When running inside an AI coding agent session, accept verified semantic reasoning from the agent
|
|
130
|
+
if (agentContext && typeof agentContext === 'object') {
|
|
131
|
+
rawAiOutput = {
|
|
132
|
+
is_pure_test: Boolean(agentContext.is_pure_test),
|
|
133
|
+
is_pure_doc: Boolean(agentContext.is_pure_doc),
|
|
134
|
+
contains_destructive_ops: Boolean(agentContext.contains_destructive_ops || CANONICAL_DESTRUCTIVE_PATTERN.test(req)),
|
|
135
|
+
contains_api_changes: Boolean(agentContext.contains_api_changes),
|
|
136
|
+
classification: agentContext.classification || (agentContext.is_pure_test ? 'test_only' : (agentContext.is_pure_doc ? 'doc_only' : 'internal_code')),
|
|
137
|
+
confidence: agentContext.confidence || 'high',
|
|
138
|
+
evaluator_mode: 'agent_native',
|
|
139
|
+
rationale: agentContext.rationale || 'Evaluated natively by executing AI Agent in active session'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 2. External Provider Command (if configured via environment hook)
|
|
144
|
+
if (!rawAiOutput) {
|
|
145
|
+
const classifierCmd = process.env.ASDLC_CLASSIFIER_COMMAND;
|
|
146
|
+
if (classifierCmd) {
|
|
147
|
+
try {
|
|
148
|
+
const inputJson = JSON.stringify({ requirement: req, changedFiles: normFiles });
|
|
149
|
+
const stdout = execSync(classifierCmd, {
|
|
150
|
+
input: inputJson,
|
|
151
|
+
encoding: 'utf8',
|
|
152
|
+
timeout: 5000,
|
|
153
|
+
env: { ...process.env, ASDLC_INPUT_JSON: inputJson }
|
|
154
|
+
});
|
|
155
|
+
const parsed = JSON.parse(stdout.trim());
|
|
156
|
+
if (parsed && typeof parsed === 'object') {
|
|
157
|
+
rawAiOutput = { ...parsed, evaluator_mode: 'llm_classifier' };
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// Fallback to baseline heuristic on timeout or execution failure
|
|
96
161
|
}
|
|
97
|
-
} catch {
|
|
98
|
-
// Fallback to validated heuristic seed on timeout or command failure
|
|
99
162
|
}
|
|
100
163
|
}
|
|
101
164
|
|
|
102
|
-
//
|
|
165
|
+
// 3. Validated baseline heuristic seed (deterministic fallback for standalone CLI execution)
|
|
103
166
|
if (!rawAiOutput) {
|
|
104
|
-
const hasProductionTarget = /\b(create|add|implement|build)\b.*\b(api|endpoint|service|table|database|schema|handler|router)\b/i.test(req)
|
|
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);
|
|
105
169
|
const hasDestructiveAction = CANONICAL_DESTRUCTIVE_PATTERN.test(req);
|
|
106
170
|
|
|
107
|
-
const isDocIntent =
|
|
171
|
+
const isDocIntent = /(?:\b(?:typo|typos|readme|docs?|documentation|comments?|whitespace|markdown|license|changelog)\b|错别字|文档|注释|说明文档)/i.test(req) &&
|
|
108
172
|
!hasProductionTarget && !hasDestructiveAction;
|
|
109
173
|
|
|
110
|
-
const isTestIntent =
|
|
174
|
+
const isTestIntent = /(?:\b(?:tests?|testing|mocks?|fixtures?|suites?|unittests?|integrationtests?)\b|单元测试|集成测试|测试用例)/i.test(req) &&
|
|
111
175
|
!hasProductionTarget && !hasDestructiveAction;
|
|
112
176
|
|
|
113
177
|
// Few-shot file pattern seeds (illustrative samples)
|
|
@@ -125,36 +189,42 @@ export function judgeChangeSemantics({ requirement = '', changedFiles = [], repo
|
|
|
125
189
|
/^license$/i
|
|
126
190
|
];
|
|
127
191
|
|
|
128
|
-
const
|
|
129
|
-
const
|
|
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)));
|
|
130
195
|
|
|
131
|
-
const isPureTest = allTestFiles || (
|
|
132
|
-
const isPureDoc = allDocFiles || (
|
|
196
|
+
const isPureTest = allTestFiles || (substantiveFiles.length === 0 && isTestIntent);
|
|
197
|
+
const isPureDoc = allDocFiles || (substantiveFiles.length === 0 && isDocIntent);
|
|
133
198
|
|
|
134
199
|
rawAiOutput = {
|
|
135
200
|
is_pure_test: isPureTest,
|
|
136
201
|
is_pure_doc: isPureDoc,
|
|
137
202
|
contains_destructive_ops: CANONICAL_DESTRUCTIVE_PATTERN.test(req),
|
|
138
|
-
contains_api_changes:
|
|
203
|
+
contains_api_changes: false,
|
|
139
204
|
classification: isPureTest ? 'test_only' : (isPureDoc ? 'doc_only' : 'internal_code'),
|
|
140
205
|
confidence: 'high',
|
|
206
|
+
evaluator_mode: 'heuristic_seed',
|
|
141
207
|
rationale: isPureTest
|
|
142
|
-
? '
|
|
143
|
-
: (isPureDoc ? '
|
|
208
|
+
? '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')
|
|
144
210
|
};
|
|
211
|
+
} else {
|
|
212
|
+
rawAiOutput.evaluator_mode = rawAiOutput.evaluator_mode || 'llm_classifier';
|
|
145
213
|
}
|
|
146
214
|
|
|
147
215
|
// Mandatory expectation check
|
|
148
216
|
const check = validateAIClassificationExpectation(rawAiOutput, { changedFiles, requirement });
|
|
149
217
|
if (!check.ok) {
|
|
218
|
+
const mode = rawAiOutput?.evaluator_mode || 'heuristic_seed';
|
|
150
219
|
if (check.override) {
|
|
151
|
-
return { ...rawAiOutput, ...check.override, confidence: 'medium', invariant_override: true, rejection_reason: check.error };
|
|
220
|
+
return { ...rawAiOutput, ...check.override, evaluator_mode: mode, confidence: 'medium', invariant_override: true, rejection_reason: check.error };
|
|
152
221
|
}
|
|
153
222
|
return {
|
|
154
223
|
is_pure_test: false,
|
|
155
224
|
is_pure_doc: false,
|
|
156
225
|
classification: 'internal_code',
|
|
157
226
|
confidence: 'low',
|
|
227
|
+
evaluator_mode: mode,
|
|
158
228
|
rationale: `AI output failed expectation verification: ${check.error}`
|
|
159
229
|
};
|
|
160
230
|
}
|
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.6.0';
|
|
3
3
|
|
|
4
4
|
export const RISK_LEVELS = {
|
|
5
5
|
L0: 'L0',
|
|
@@ -28,7 +28,7 @@ export const DEFAULT_GOVERNANCE = {
|
|
|
28
28
|
auto_approval: 'disabled'
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const CANONICAL_DESTRUCTIVE_PATTERN =
|
|
31
|
+
export const CANONICAL_DESTRUCTIVE_PATTERN = /(?:\b(?:drop\s+(?:table|column|database|index|schema)|truncate\s+(?:table|database)?|purge\s+(?:data|table|database)|hard\s+delete|clean\s+database|destroy\s+database)\b|删表|删除[^\n,。;]{0,12}(?:表|库|数据库)|清空[^\n,。;]{0,10}表|清理历史[^\n,。;]{0,12}(?:表|数据|账务|记录)|物理删除|销毁[^\n,。;]{0,10}(?:库|数据库|表)|截断[^\n,。;]{0,8}表|抹除[^\n,。;]{0,10}数据)/i;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Hard Signal Rules (§5.2):
|
|
@@ -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
|
+
}
|
|
@@ -52,7 +52,7 @@ export function evaluateV2Security({ requirement = '', changedFiles = [], repoRo
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// 2. Check Requirement Semantics for Security/Financial/Regulatory
|
|
55
|
+
// 2. Check Requirement Semantics for Security/Financial/Regulatory (English + Chinese)
|
|
56
56
|
const highRiskCompounds = [
|
|
57
57
|
'access token', 'refresh token', 'bearer token', 'session token', 'auth token', 'security token',
|
|
58
58
|
'jwt', 'oauth', 'private key', 'secret key', 'password hash', 'password encryption',
|
|
@@ -60,11 +60,21 @@ export function evaluateV2Security({ requirement = '', changedFiles = [], repoRo
|
|
|
60
60
|
'refund ledger', 'clearing settlement', 'credit card'
|
|
61
61
|
];
|
|
62
62
|
|
|
63
|
+
const cjkHighRiskCompounds = [
|
|
64
|
+
'清结算', '资金清算', '账务清算', '资金账本', '核心账务', '对账', '打款', '提现',
|
|
65
|
+
'私钥', '密钥轮换', '密码哈希', '密码加密', '鉴权绕过', '越权', '隐私合规', '实名认证', '数据脱敏'
|
|
66
|
+
];
|
|
67
|
+
|
|
63
68
|
const genericSecWords = [
|
|
64
69
|
'auth', 'authentication', 'password', 'credential', 'crypto',
|
|
65
70
|
'payment', 'payout', 'refund', 'billing', 'ledger', 'wallet', 'clearing'
|
|
66
71
|
];
|
|
67
72
|
|
|
73
|
+
const cjkGenericSecWords = [
|
|
74
|
+
'支付', '结算', '账务', '账本', '钱包', '计费', '账单', '退款',
|
|
75
|
+
'鉴权', '认证', '权限', '密钥', '令牌', '加密', '登录态'
|
|
76
|
+
];
|
|
77
|
+
|
|
68
78
|
let compoundHit = null;
|
|
69
79
|
for (const compound of highRiskCompounds) {
|
|
70
80
|
const re = new RegExp(`\\b${compound.replace(/-/g, '[-\\s]')}\\b`, 'i');
|
|
@@ -73,6 +83,14 @@ export function evaluateV2Security({ requirement = '', changedFiles = [], repoRo
|
|
|
73
83
|
break;
|
|
74
84
|
}
|
|
75
85
|
}
|
|
86
|
+
if (!compoundHit) {
|
|
87
|
+
for (const cjkCompound of cjkHighRiskCompounds) {
|
|
88
|
+
if (req.includes(cjkCompound)) {
|
|
89
|
+
compoundHit = cjkCompound;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
76
94
|
|
|
77
95
|
const matchedGenerics = [];
|
|
78
96
|
for (const word of genericSecWords) {
|
|
@@ -81,6 +99,11 @@ export function evaluateV2Security({ requirement = '', changedFiles = [], repoRo
|
|
|
81
99
|
matchedGenerics.push(word);
|
|
82
100
|
}
|
|
83
101
|
}
|
|
102
|
+
for (const cjkWord of cjkGenericSecWords) {
|
|
103
|
+
if (req.includes(cjkWord)) {
|
|
104
|
+
matchedGenerics.push(cjkWord);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
84
107
|
|
|
85
108
|
const aiJudgment = judgeChangeSemantics({ requirement: req, changedFiles });
|
|
86
109
|
const isDocOrTest = aiJudgment.is_pure_test || aiJudgment.is_pure_doc;
|