@akjamie/agentic-sdlc 1.6.1 → 1.8.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
@@ -362,7 +362,6 @@ We welcome contributions from developers, architects, and researchers advancing
362
362
  - **Specification & Linting Reference**: Read [docs/spec-format.md](docs/spec-format.md) for R0–R8 pass/fail examples, BDD rules, and troubleshooting remedies.
363
363
  - **IDE Slash-Command Parity**: First-class slash commands (`/asdlc-*`) across Claude Code, OpenCode, Pi, Antigravity, GitHub Copilot, Cursor, Trae, and Windsurf (see [docs/usage.md](docs/usage.md)).
364
364
  - **Architectural Specs**: Read [docs/architecture.md](docs/architecture.md) for deep dives on the 3-plane model.
365
- - **Enterprise Blueprint**: Browse [docs/blueprint.md](docs/blueprint.md) (or [Chinese version](docs/blueprint.zh.md)) for enterprise deployment patterns.
366
365
  - **Documentation Index**: See [docs/README.md](docs/README.md) for the active documentation catalog.
367
366
 
368
367
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akjamie/agentic-sdlc",
3
- "version": "1.6.1",
3
+ "version": "1.8.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';
@@ -1,4 +1,4 @@
1
- import { LEVEL_RANK, DEFAULT_GOVERNANCE, L0_DETERMINISTIC_PATTERNS, isChangeMetadataFile } from './rules/builtin.js';
1
+ import { LEVEL_RANK, DEFAULT_GOVERNANCE, L0_DETERMINISTIC_PATTERNS, isPureL0File, isPureTestFile, isChangeMetadataFile } from './rules/builtin.js';
2
2
  import { judgeChangeSemantics } from './ai_judge.js';
3
3
 
4
4
  /**
@@ -64,8 +64,8 @@ export function decideAssessment({
64
64
  .map((f) => f.replace(/\\/g, '/'))
65
65
  .filter((f) => !isChangeMetadataFile(f));
66
66
  if (substantiveFiles.length > 0) {
67
- const allDoc = substantiveFiles.every((f) => L0_DETERMINISTIC_PATTERNS.some((p) => p.test(f)));
68
- if (allDoc || aiJudgment.is_pure_doc || aiJudgment.is_pure_test) {
67
+ const allDocOrTest = substantiveFiles.every((f) => isPureL0File(f) || isPureTestFile(f));
68
+ if (allDocOrTest && (aiJudgment.is_pure_doc || aiJudgment.is_pure_test || substantiveFiles.every((f) => isPureL0File(f)))) {
69
69
  calculatedLevel = 'L0';
70
70
  }
71
71
  } else if (aiJudgment.is_pure_test || aiJudgment.is_pure_doc || (v1.level === 'L0' && v2.no_signal && v3.no_signal)) {
@@ -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 || []),
@@ -5,6 +5,7 @@ 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';
10
11
  import { appendAssessmentRecord, loadLatestAssessment, loadInitialAssessment } from './store.js';
@@ -21,6 +22,7 @@ export { HARNESS_RULES_VERSION, ENGINE_VERSION, DEFAULT_GOVERNANCE } from './rul
21
22
  export function assess({
22
23
  stage = 'new',
23
24
  changeId,
25
+ baseRef = null,
24
26
  baseSha = 'HEAD',
25
27
  headSha = null,
26
28
  requirement = '',
@@ -30,7 +32,8 @@ export function assess({
30
32
  baseline = null,
31
33
  actor = { type: 'system', id: 'asdlc' },
32
34
  repoRoot = null,
33
- persist = true
35
+ persist = true,
36
+ agentContext = null
34
37
  } = {}) {
35
38
  try {
36
39
  const prev = previous || (repoRoot && changeId ? loadLatestAssessment(repoRoot, changeId) : null);
@@ -38,7 +41,7 @@ export function assess({
38
41
 
39
42
  // If requirement is empty or for spec stage, load proposal.md and design.md from change dir
40
43
  let effectiveReq = requirement || '';
41
- let agentContext = null;
44
+ let effectiveAgentContext = agentContext;
42
45
  if (repoRoot && changeId) {
43
46
  try {
44
47
  const cdir = changeDir(repoRoot, changeId);
@@ -49,19 +52,24 @@ export function assess({
49
52
  }
50
53
 
51
54
  // 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 */ }
55
+ if (!effectiveAgentContext) {
56
+ const agentCtxPath = path.join(cdir, '.agent-assess.json');
57
+ if (fs.existsSync(agentCtxPath)) {
58
+ try {
59
+ effectiveAgentContext = JSON.parse(fs.readFileSync(agentCtxPath, 'utf8'));
60
+ } catch { /* ignore parse error */ }
61
+ }
57
62
  }
58
63
  } catch { /* ignore read failure */ }
59
64
  }
60
65
 
66
+ const effectiveBase = baseRef || baseSha;
67
+ const fileSemantics = batchAnalyzeFileSemantics(changedFiles, { repoRoot, baseRef: effectiveBase });
68
+
61
69
  // 1. Evaluate Three Risk Vectors
62
- const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType, agentContext });
63
- const v2 = evaluateV2Security({ requirement: effectiveReq, changedFiles, repoRoot });
64
- const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot, changeId });
70
+ const v1 = evaluateV1Intent({ requirement: effectiveReq, changedFiles, changeType, agentContext: effectiveAgentContext });
71
+ const v2 = evaluateV2Security({ requirement: effectiveReq, changedFiles, repoRoot, baseRef: effectiveBase, fileSemantics });
72
+ const v3 = evaluateV3Topology({ requirement: effectiveReq, changedFiles, repoRoot, changeId, baseRef: effectiveBase, fileSemantics });
65
73
 
66
74
  // Inferred or provided Change Type
67
75
  const effectiveType = changeType || v1.inferredType || 'change';
@@ -1,5 +1,5 @@
1
1
  export const HARNESS_RULES_VERSION = '2026.10.0';
2
- export const ENGINE_VERSION = '1.6.1';
2
+ export const ENGINE_VERSION = '1.8.0';
3
3
 
4
4
  export const RISK_LEVELS = {
5
5
  L0: 'L0',
@@ -44,10 +44,14 @@ export const HARD_RULES = [
44
44
  mandatory_human_review: true,
45
45
  patterns: [
46
46
  /(^|\/)AGENTS\.md$/i,
47
+ /(^|\/)(CLAUDE|GEMINI)\.md$/i,
48
+ /(^|\/)\.github\/(copilot-instructions|prompts)\//i,
49
+ /(^|\/)assets\/commands\//i,
50
+ /(^|\/)\.sdlc\//i,
47
51
  /(^|\/)openspec\/config\.yaml$/i,
48
52
  /(^|\/)(assets|\.agents)\/skills\/.*SKILL\.md$/i
49
53
  ],
50
- summary: 'Modifies core Agent governance constitution (AGENTS.md, openspec/config.yaml, or agent skills)'
54
+ summary: 'Modifies core Agent governance constitution or agent instructions'
51
55
  },
52
56
  // 2. High-Risk Security, Credentials & Cryptography (L3)
53
57
  {
@@ -181,6 +185,33 @@ export const TEST_AND_DOC_PATTERNS = [
181
185
  /(^|\/)assets\/(?:images|media|icons|fonts)\//i
182
186
  ];
183
187
 
188
+ export const L0_EXCLUSION_PATTERNS = [
189
+ /(^|\/)requirements.*\.txt$/i,
190
+ /(^|\/)CMakeLists\.txt$/i,
191
+ /(^|\/)(src|app|pkg|internal|lib)\/.*\.md$/i,
192
+ /(^|\/)prompts\/.*\.md$/i,
193
+ /(^|\/)(CLAUDE|GEMINI|AGENTS)\.md$/i,
194
+ /(^|\/)\.github\//i,
195
+ /(^|\/)\.sdlc\//i,
196
+ /(^|\/)assets\/commands\//i
197
+ ];
198
+
199
+ export function isPureL0File(filePath = '') {
200
+ const norm = String(filePath).replace(/\\/g, '/');
201
+ if (L0_EXCLUSION_PATTERNS.some((p) => p.test(norm))) return false;
202
+ return L0_DETERMINISTIC_PATTERNS.some((p) => p.test(norm));
203
+ }
204
+
205
+ export function isPureTestFile(filePath = '') {
206
+ const norm = String(filePath).replace(/\\/g, '/');
207
+ if (L0_EXCLUSION_PATTERNS.some((p) => p.test(norm))) return false;
208
+ return /(^|\/)(tests?|__tests__|testing)\//i.test(norm) ||
209
+ /\.(test|spec)\.[a-z0-9]+$/i.test(norm) ||
210
+ /_test\.go$/i.test(norm) ||
211
+ /test_[^/]+\.py$/i.test(norm) ||
212
+ /[^/]+_test\.py$/i.test(norm);
213
+ }
214
+
184
215
  export function isChangeMetadataFile(filePath = '') {
185
216
  const norm = String(filePath).replace(/\\/g, '/');
186
217
  return /(^|\/)openspec\/changes\/[^/]+\//i.test(norm);
@@ -0,0 +1,41 @@
1
+ export const SECRET_PATTERNS = [
2
+ // Cloud AKs
3
+ { name: 'ALIBABA_AK', pattern: /\bLTAI[0-9A-Za-z]{12,20}\b/, redact: (s) => `${s.slice(0, 4)}****` },
4
+ { name: 'AWS_AK', pattern: /\bAKIA[0-9A-Z]{16}\b/, redact: (s) => `${s.slice(0, 4)}****` },
5
+ { name: 'TENCENT_AK', pattern: /\bAKID[0-9A-Za-z]{13,20}\b/, redact: (s) => `${s.slice(0, 4)}****` },
6
+ // Private keys
7
+ { name: 'PRIVATE_KEY', pattern: /-----BEGIN (?:RSA|EC|OPENSSH|DSA|PRIVATE) .*PRIVATE KEY-----/, redact: () => '-----BEGIN PRIVATE KEY-----****' },
8
+ // Platform tokens
9
+ { name: 'GITHUB_PAT', pattern: /\b(?:ghp_[0-9A-Za-z]{36}|github_pat_[0-9A-Za-z_]{50,})\b/, redact: (s) => `${s.slice(0, 4)}****` },
10
+ { name: 'SLACK_TOKEN', pattern: /\bxox[baprs]-[0-9A-Za-z-]{20,}\b/, redact: (s) => `${s.slice(0, 5)}****` },
11
+ { name: 'OPENAI_TOKEN', pattern: /\bsk-[A-Za-z0-9]{20,}\b/, redact: (s) => `${s.slice(0, 3)}****` },
12
+ // Secret assignments & connection strings with plaintext passwords
13
+ { name: 'SECRET_ASSIGNMENT', pattern: /(?:access[-_]?key[-_]?secret|secret[-_]?key|private[-_]?key)\s*[:=]\s*['"]?([A-Za-z0-9+/=_-]{16,})['"]?/i, redact: () => 'secret_key=****' },
14
+ { name: 'JDBC_PASSWORD', pattern: /jdbc:.*password=([^\s;&'"]+)/i, redact: () => 'jdbc:...password=****' },
15
+ { name: 'MONGO_PASSWORD', pattern: /mongodb(?:\+srv)?:\/\/[^:]+:([^@\s]+)@/i, redact: () => 'mongodb://...:****@' },
16
+ ];
17
+
18
+ export const IGNORE_SECRET_INTERPOLATION = /\$\{[^}]+\}|\{\{[^}]+\}|\$[A-Z0-9_]+|ENC\([^)]+\)|vault:|kms:|<YOUR_|<CHANGE_ME>|\b(?:dummy|mock)\b/i;
19
+
20
+ export function scanDiffForSecrets(diffOrText) {
21
+ if (!diffOrText || typeof diffOrText !== 'string') return [];
22
+ const findings = [];
23
+ const lines = diffOrText.split('\n');
24
+ for (let idx = 0; idx < lines.length; idx += 1) {
25
+ const rawLine = lines[idx];
26
+ // In diff mode, only scan added '+' lines (not +++ headers)
27
+ const content = rawLine.startsWith('+') && !rawLine.startsWith('+++') ? rawLine.slice(1) : rawLine;
28
+ if (IGNORE_SECRET_INTERPOLATION.test(content)) continue;
29
+ for (const rule of SECRET_PATTERNS) {
30
+ const m = content.match(rule.pattern);
31
+ if (m) {
32
+ findings.push({
33
+ rule: rule.name,
34
+ redacted: rule.redact(m[0]),
35
+ line: idx + 1,
36
+ });
37
+ }
38
+ }
39
+ }
40
+ return findings;
41
+ }