@akjamie/agentic-sdlc 1.0.0 → 1.2.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.
@@ -0,0 +1,137 @@
1
+ import path from 'node:path';
2
+ import { exists, readText, walkFiles } from '../lib/fs.js';
3
+ import { changeDir } from '../lib/paths.js';
4
+ import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
5
+ import { runShell } from '../lib/exec.js';
6
+ import { fail } from '../lib/errors.js';
7
+ import { log } from '../lib/log.js';
8
+
9
+ export function parseSpecAcceptanceCriteria(specText) {
10
+ const acs = [];
11
+ const lines = specText.split('\n');
12
+ let currentReq = '';
13
+
14
+ for (const line of lines) {
15
+ const reqMatch = line.match(/^###\s+Requirement:\s*(.+?)\s*$/);
16
+ if (reqMatch) {
17
+ currentReq = reqMatch[1];
18
+ continue;
19
+ }
20
+ const acMatch = line.match(/^\s*-\s*\[[ xX]\]\s*(AC\d+)\s*:\s*(.+)$/);
21
+ if (!acMatch) continue;
22
+ const testMatch = line.match(/\(test:\s*([^)]+?)\s*\)/i);
23
+ acs.push({
24
+ id: acMatch[1],
25
+ requirement: currentReq,
26
+ text: acMatch[2].replace(/\(test:.*$/i, '').trim(),
27
+ testPath: testMatch ? testMatch[1].trim() : null,
28
+ });
29
+ }
30
+ return acs;
31
+ }
32
+
33
+ export function runTests(changeId, opts = {}) {
34
+ const repoRoot = requireRepo(opts);
35
+ const slug = toChangeSlug(changeId);
36
+ const cdir = changeDir(repoRoot, slug);
37
+
38
+ if (!exists(cdir)) {
39
+ fail(`change '${slug}' not found`, { hint: 'check the change id or run `asdlc status`' });
40
+ }
41
+
42
+ const specsDir = path.join(cdir, 'specs');
43
+ if (!exists(specsDir)) {
44
+ fail(`no specs directory found for change '${slug}'`);
45
+ }
46
+
47
+ const specFiles = walkFiles(specsDir).filter((f) => f.endsWith('spec.md'));
48
+ if (specFiles.length === 0) {
49
+ fail(`no spec.md files found under specs/ for change '${slug}'`);
50
+ }
51
+
52
+ const allAcs = [];
53
+ for (const relFile of specFiles) {
54
+ const fullPath = path.join(specsDir, relFile);
55
+ const content = readText(fullPath);
56
+ const acs = parseSpecAcceptanceCriteria(content);
57
+ for (const ac of acs) {
58
+ allAcs.push({ ...ac, specFile: relFile });
59
+ }
60
+ }
61
+
62
+ if (allAcs.length === 0) {
63
+ fail(`no acceptance criteria (AC<n>) found in specs for change '${slug}'`, {
64
+ hint: 'add acceptance criteria with test mappings: - [ ] AC1: ... (test: path/to/test)',
65
+ });
66
+ }
67
+
68
+ const missingMappings = allAcs.filter((ac) => !ac.testPath);
69
+ if (missingMappings.length > 0) {
70
+ fail(`${missingMappings.length} acceptance criteria lack (test: <path>) mappings:\n` +
71
+ missingMappings.map((ac) => ` - ${ac.id}: ${ac.text}`).join('\n'));
72
+ }
73
+
74
+ const uniqueTestPaths = [...new Set(allAcs.map((ac) => ac.testPath))];
75
+ const missingFiles = uniqueTestPaths.filter((tp) => !exists(path.resolve(repoRoot, tp)));
76
+ if (missingFiles.length > 0) {
77
+ fail(`mapped test file(s) do not exist:\n` + missingFiles.map((f) => ` - ${f}`).join('\n'), {
78
+ hint: 'create test stubs or update (test: <path>) in specs',
79
+ });
80
+ }
81
+
82
+ if (!opts.json) {
83
+ log.info(`=== Running Acceptance Tests for ${slug} ===`);
84
+ log.info(`Mapped ACs: ${allAcs.length} across ${uniqueTestPaths.length} test file(s):`);
85
+ for (const ac of allAcs) {
86
+ log.info(` • [${ac.id}] ${ac.text} -> ${ac.testPath}`);
87
+ }
88
+ log.info('');
89
+ }
90
+
91
+ const runnerCmd = opts.runner ?? (process.platform === 'win32'
92
+ ? `node --test ${uniqueTestPaths.map((p) => `"${p}"`).join(' ')}`
93
+ : `node --test ${uniqueTestPaths.join(' ')}`);
94
+
95
+ const res = runShell(runnerCmd, repoRoot, {
96
+ env: { NODE_TEST_CONTEXT: undefined },
97
+ stdio: 'pipe',
98
+ });
99
+ const passed = res.status === 0;
100
+
101
+ if (opts.json) {
102
+ const output = {
103
+ changeId: slug,
104
+ pass: passed,
105
+ status: passed ? 'pass' : 'fail',
106
+ acCount: allAcs.length,
107
+ testFiles: uniqueTestPaths,
108
+ acs: allAcs,
109
+ stdout: res.stdout,
110
+ stderr: res.stderr,
111
+ };
112
+ process.stdout.write(JSON.stringify(output, null, 2) + '\n');
113
+ } else {
114
+ if (res.stdout) process.stdout.write(res.stdout);
115
+ if (res.stderr) process.stderr.write(res.stderr);
116
+
117
+ if (passed) {
118
+ log.ok(`✓ all acceptance tests passed (${allAcs.length} ACs, ${uniqueTestPaths.length} files)`);
119
+ } else {
120
+ log.error(`✗ acceptance test run failed (exit code ${res.status})`);
121
+ }
122
+ }
123
+
124
+ return passed ? 0 : 1;
125
+ }
126
+
127
+ export function register(program) {
128
+ program
129
+ .command('test <changeId>')
130
+ .description('run acceptance tests mapped from change specs (TDD & CI gate)')
131
+ .option('--json', 'output structured JSON report for CI consumption')
132
+ .option('--runner <command>', 'custom test runner command')
133
+ .option('--repo-root <path>')
134
+ .action((changeId, opts) => {
135
+ process.exitCode = runTests(changeId, opts);
136
+ });
137
+ }
package/src/lib/agents.js CHANGED
@@ -17,12 +17,13 @@ const ROUTING_BLOCK = `${ROUTING_MARKER}
17
17
  Everything runs through \`asdlc\` - do NOT call \`openspec ...\` directly. There is no
18
18
  raw escape hatch: the wrappers ARE the guards (graph refresh, approval, checks).
19
19
 
20
- 1. **new** - \`asdlc new "<requirement>"\`: scaffold the change (derives slug from intent) +
20
+ 1. **new** - \`asdlc new "<requirement>" [--batch-grill] [--no-grill]\`: scaffold the change (derives slug from intent) +
21
21
  refresh the knowledge graph + write \`explore.md\` + seed \`clarifications.md\`.
22
22
  ▶ **IMMEDIATE ACTION FOR AGENT**: DO NOT stop or ask permission. In the SAME interaction turn,
23
- immediately run the **batch-grill-me** (or **grilling**) skill using the **batch-grill-me** protocol (evaluate the full frontier
24
- in 1-2 structured batches with recommendations, looking facts up yourself) and record settled decisions
25
- in \`clarifications.md\`.
23
+ ground yourself in \`explore.md\` and codebase facts. Run high-signal conversational **grill-me**
24
+ (or **batch-grill-me** if \`--batch-grill\` was passed) with anti-fatigue guardrails (look facts up yourself,
25
+ focus on material trade-offs, lead with recommendations, early-exit on agreement), and record settled decisions
26
+ in \`clarifications.md\`. (If \`--no-grill\` was passed, self-settle context-inferred assumptions).
26
27
  ▶ **CRITICAL**: ONLY AFTER \`clarifications.md\` is settled may you author **proposal.md -> specs/**\`. (AI Review is handled on PR by CI).
27
28
  2. **grill** - (embedded in Stage 2) settle all design forks in \`clarifications.md\` BEFORE writing specs.
28
29
  3. **lint** - \`asdlc lint <ID>\`: artifacts + BDD/acceptance criteria. Open Spec PR via \`asdlc pr <ID> <targetBranch>\`.
package/src/lib/exec.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
 
3
3
  export function runShell(command, cwd, { env = {}, timeout = 600000, input } = {}) {
4
+ const mergedEnv = { ...process.env, ...env };
5
+ for (const [k, v] of Object.entries(env)) {
6
+ if (v === undefined) delete mergedEnv[k];
7
+ }
4
8
  const res = spawnSync(command, {
5
9
  cwd,
6
10
  encoding: 'utf8',
7
11
  shell: true,
8
12
  timeout,
9
- env: { ...process.env, ...env },
13
+ env: mergedEnv,
10
14
  input, // optional stdin: feeds prompts to a headless verifier agent
11
15
  });
12
16
  return {
package/src/lib/policy.js CHANGED
@@ -12,6 +12,7 @@ export const DEFAULT_POLICY = {
12
12
  reviewers: { spec: null, design: null },
13
13
  ai_review: { trigger: 'on-ready-and-push', debounce_seconds: 120 },
14
14
  rollout_mode: {},
15
+ web_search: 'allow',
15
16
  };
16
17
 
17
18
  function deepMerge(base, over) {
@@ -52,3 +53,8 @@ export function matchesAny(p, globs = []) {
52
53
  export function isAdvisory(policy, checkName) {
53
54
  return policy?.rollout_mode?.[checkName] === 'advisory';
54
55
  }
56
+
57
+ // Web-search policy egress guard: enabled by default ('allow'), blocked only when explicitly 'deny'.
58
+ export function canWebSearch(policy) {
59
+ return policy?.web_search !== 'deny';
60
+ }
@@ -103,6 +103,7 @@ const DEFAULT_SEVERITY = {
103
103
  'R4-then': 'blocker',
104
104
  'R4-given': 'major',
105
105
  'R5-ac': 'blocker',
106
+ 'R5-scenario-coverage': 'blocker',
106
107
  'R6-ac-test': 'blocker',
107
108
  'R7-test-strategy': 'blocker',
108
109
  'R8-removed-reason': 'major',
@@ -146,7 +147,11 @@ export function lintSpecText(text, { requireGiven = true, repoRoot = null, rules
146
147
  }
147
148
 
148
149
  const acs = acceptanceCriteria(r.body);
149
- if (acs.length === 0) add('R5-ac', 'blocker', `"${r.name}" has no Acceptance criteria (AC<n>)`, r.name);
150
+ if (acs.length === 0) {
151
+ add('R5-ac', 'blocker', `"${r.name}" has no Acceptance criteria (AC<n>)`, r.name);
152
+ } else if (scens.length > acs.length) {
153
+ add('R5-scenario-coverage', 'blocker', `"${r.name}" defines ${scens.length} scenario(s) but only ${acs.length} acceptance criteria (each scenario requires AC coverage)`, r.name);
154
+ }
150
155
  for (const ac of acs) {
151
156
  if (!ac.test) {
152
157
  add('R6-ac-test', 'blocker', `"${ac.id}" has no (test: <path>) mapping`, `${r.name} / ${ac.id}`);
@@ -1,80 +0,0 @@
1
- // Jenkinsfile — BU Agentic SDLC gate (OpenSpec engine + asdlc governance).
2
- //
3
- // IMPORTANT: this job does NOT (and must not need to) install asdlc globally on
4
- // the Jenkins agent. There is no `npm i -g` here. asdlc is obtained one of two
5
- // permission-free ways:
6
- //
7
- // 1) project devDependency: declare "agentic-sdlc" in devDependencies, run
8
- // `npm ci` in a stage, then this file uses node_modules/.bin/asdlc; OR
9
- // 2) extra SCM checkout: add a checkout of the asdlc toolkit to this job
10
- // and set ASDLC_TOOLKIT=<workspace>/asdlc-toolkit; then it runs
11
- // `node $ASDLC_TOOLKIT/bin/asdlc.js`.
12
- //
13
- // spec PR (branch asdlc/<id>) -> asdlc lint (spec check)
14
- // impl PR (branch asdlc/impl/<id>) -> asdlc verify (implementation check)
15
-
16
- pipeline {
17
- agent { docker { image 'node:20' label 'docker' } }
18
-
19
- options {
20
- buildDiscarder(logRotator(numToKeepStr: '30'))
21
- disableConcurrentBuilds()
22
- timestamps()
23
- }
24
-
25
- environment {
26
- CHANGE_ID = "${env.CHANGE_BRANCH ?: env.BRANCH_NAME}".tokenize('/').last().toUpperCase()
27
- REPO = "${env.JOB_BASE_NAME}"
28
- IS_IMPL = "${(env.CHANGE_BRANCH ?: env.BRANCH_NAME).contains('impl')}"
29
- }
30
-
31
- stages {
32
- // Optional: only if asdlc is a devDependency. Safe to keep; harmless if absent.
33
- stage('Install project tooling') {
34
- steps {
35
- sh 'if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; elif [ -f package.json ]; then npm install --no-audit --no-fund; else echo "no package.json; relying on ASDLC_TOOLKIT checkout"; fi'
36
- }
37
- }
38
-
39
- stage('Resolve asdlc (NO global install)') {
40
- steps {
41
- script {
42
- def asdlc = sh(returnStdout: true, script: '''
43
- if [ -x node_modules/.bin/asdlc ]; then
44
- echo node_modules/.bin/asdlc
45
- elif [ -n "${ASDLC_TOOLKIT:-}" ] && [ -f "$ASDLC_TOOLKIT/bin/asdlc.js" ]; then
46
- echo "node $ASDLC_TOOLKIT/bin/asdlc.js"
47
- else
48
- echo MISSING
49
- fi
50
- ''').trim()
51
- if (asdlc == 'MISSING') {
52
- error('asdlc not found. Declare it in devDependencies (then npm ci) OR add an SCM checkout and set ASDLC_TOOLKIT.')
53
- }
54
- env.ASDLC = asdlc
55
- }
56
- }
57
- }
58
-
59
- stage('Spec lint & AI Review') {
60
- when { expression { env.IS_IMPL != 'true' } }
61
- steps { sh "${env.ASDLC} lint ${env.CHANGE_ID}" }
62
- }
63
-
64
- stage('Verify & AI Code Review (implementation PR)') {
65
- when { expression { env.IS_IMPL == 'true' } }
66
- steps {
67
- // Player != referee: verify runs every deterministic check PLUS an
68
- // independent agent/model (ASDLC_VERIFY_COMMAND from Jenkins credentials).
69
- withCredentials([string(credentialsId: 'asdlc-verify-api-key', variable: 'VERIFY_API_KEY')]) {
70
- sh "${env.ASDLC} verify ${env.CHANGE_ID} --repo ${env.REPO} --base origin/${env.CHANGE_TARGET} --required"
71
- }
72
- }
73
- }
74
- }
75
-
76
- post {
77
- success { echo "asdlc PASSED for ${env.CHANGE_ID}" }
78
- failure { echo "asdlc FAILED for ${env.CHANGE_ID}" }
79
- }
80
- }