@akjamie/agentic-sdlc 1.8.0 → 1.9.1

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,141 @@
1
+ import { loadGlobalConfig, saveGlobalConfig, validateWorkflowMode } from '../lib/config.js';
2
+ import { log } from '../lib/log.js';
3
+
4
+ function setNested(obj, keyPath, value) {
5
+ const parts = keyPath.split('.');
6
+ let curr = obj;
7
+ for (let i = 0; i < parts.length - 1; i++) {
8
+ const p = parts[i];
9
+ if (!curr[p] || typeof curr[p] !== 'object') {
10
+ curr[p] = {};
11
+ }
12
+ curr = curr[p];
13
+ }
14
+ curr[parts[parts.length - 1]] = value;
15
+ }
16
+
17
+ function getNested(obj, keyPath) {
18
+ const parts = keyPath.split('.');
19
+ let curr = obj;
20
+ for (const p of parts) {
21
+ if (curr == null || typeof curr !== 'object') return undefined;
22
+ curr = curr[p];
23
+ }
24
+ return curr;
25
+ }
26
+
27
+ function unsetNested(obj, keyPath) {
28
+ const parts = keyPath.split('.');
29
+ let curr = obj;
30
+ for (let i = 0; i < parts.length - 1; i++) {
31
+ const p = parts[i];
32
+ if (curr == null || typeof curr !== 'object') return;
33
+ curr = curr[p];
34
+ }
35
+ delete curr[parts[parts.length - 1]];
36
+ }
37
+
38
+ function maskSensitive(obj, showSecrets) {
39
+ if (showSecrets || !obj || typeof obj !== 'object') return obj;
40
+ const out = Array.isArray(obj) ? [] : {};
41
+ for (const [k, v] of Object.entries(obj)) {
42
+ const isSensitive = /(?:key|token|secret|password)$/i.test(k);
43
+ if (isSensitive && typeof v === 'string') {
44
+ out[k] = '********';
45
+ } else if (v && typeof v === 'object') {
46
+ out[k] = maskSensitive(v, showSecrets);
47
+ } else {
48
+ out[k] = v;
49
+ }
50
+ }
51
+ return out;
52
+ }
53
+
54
+ function flattenConfig(obj, prefix = '') {
55
+ const entries = [];
56
+ if (!obj || typeof obj !== 'object') return entries;
57
+ for (const [k, v] of Object.entries(obj)) {
58
+ const fullKey = prefix ? `${prefix}.${k}` : k;
59
+ if (v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0) {
60
+ entries.push(...flattenConfig(v, fullKey));
61
+ } else {
62
+ entries.push([fullKey, typeof v === 'object' ? JSON.stringify(v) : String(v)]);
63
+ }
64
+ }
65
+ return entries;
66
+ }
67
+
68
+ export function register(program) {
69
+ const configCmd = program
70
+ .command('config')
71
+ .description('manage global ~/.asdlc/config.yaml settings (workflow_mode, git hosts, agent)');
72
+
73
+ configCmd
74
+ .command('set <key> <value>')
75
+ .description('set a global configuration key (e.g. workflow_mode supervised)')
76
+ .action((key, value) => {
77
+ const cfg = loadGlobalConfig();
78
+ if (key === 'workflow_mode') {
79
+ const validated = validateWorkflowMode(value);
80
+ setNested(cfg, key, validated);
81
+ } else {
82
+ setNested(cfg, key, value);
83
+ }
84
+ saveGlobalConfig(cfg);
85
+ log.ok(`set ${key} = ${value}`);
86
+ });
87
+
88
+ configCmd
89
+ .command('get <key>')
90
+ .description('get a global configuration key')
91
+ .option('--show-secrets', 'reveal masked secret value')
92
+ .action((key, opts) => {
93
+ const cfg = loadGlobalConfig();
94
+ const val = getNested(cfg, key);
95
+ if (val === undefined) {
96
+ log.plain('(unset)');
97
+ return;
98
+ }
99
+ const isSensitiveKey = /(?:key|token|secret|password)$/i.test(key);
100
+ if (isSensitiveKey && !opts.showSecrets && typeof val === 'string') {
101
+ log.plain('********');
102
+ } else if (typeof val === 'object' && val !== null) {
103
+ const masked = maskSensitive(val, opts.showSecrets);
104
+ log.plain(JSON.stringify(masked, null, 2));
105
+ } else {
106
+ log.plain(String(val));
107
+ }
108
+ });
109
+
110
+ configCmd
111
+ .command('unset <key>')
112
+ .description('remove a global configuration key')
113
+ .action((key) => {
114
+ const cfg = loadGlobalConfig();
115
+ unsetNested(cfg, key);
116
+ saveGlobalConfig(cfg);
117
+ log.ok(`unset ${key}`);
118
+ });
119
+
120
+ configCmd
121
+ .command('list')
122
+ .description('list all global configuration settings')
123
+ .option('--show-secrets', 'reveal masked secret values')
124
+ .option('--json', 'output in structured JSON')
125
+ .action((opts) => {
126
+ const cfg = loadGlobalConfig();
127
+ const masked = maskSensitive(cfg, opts.showSecrets);
128
+ if (opts.json) {
129
+ log.plain(JSON.stringify(masked, null, 2));
130
+ } else {
131
+ const entries = flattenConfig(masked);
132
+ if (entries.length === 0) {
133
+ log.plain('(no global configuration set)');
134
+ } else {
135
+ for (const [k, v] of entries) {
136
+ log.plain(`${k} = ${v}`);
137
+ }
138
+ }
139
+ }
140
+ });
141
+ }
@@ -4,7 +4,7 @@ import { openspecDir, resolveRepoRoot } from '../lib/paths.js';
4
4
  import { openspecVersion, OPENSPEC_PINNED, findOpenspec } from '../lib/openspec.js';
5
5
  import { graphifyAvailable, graphStatus, GITIGNORE_LINE, ensureGraphify } from '../lib/graphify.js';
6
6
  import { checkSchema, builtinSchemaVersion, localOverride, installSchema } from '../lib/schema.js';
7
- import { refreshAgents } from '../lib/agents.js';
7
+ import { refreshAgents, hasCurrentRouting } from '../lib/agents.js';
8
8
  import { readYaml } from '../lib/yaml.js';
9
9
  import { git } from '../lib/git.js';
10
10
  import { log, dim } from '../lib/log.js';
@@ -70,8 +70,10 @@ export function doctor(opts = {}) {
70
70
  } catch { /* ignore */ }
71
71
 
72
72
  const agents = path.join(repoRoot, 'AGENTS.md');
73
- hasRouting = exists(agents) && readText(agents).includes('<!-- asdlc:routing -->');
74
- add('AGENTS.md routing', hasRouting ? 'pass' : 'warn', hasRouting ? '' : 'missing (run `asdlc init`)');
73
+ const agentsText = exists(agents) ? readText(agents) : '';
74
+ hasRouting = hasCurrentRouting(agentsText);
75
+ add('AGENTS.md routing', hasRouting ? 'pass' : 'warn',
76
+ hasRouting ? '' : (agentsText.includes('<!-- asdlc:routing -->') ? 'outdated (run `asdlc doctor --fix`)' : 'missing (run `asdlc init`)'));
75
77
 
76
78
  const gstatus = graphStatus(repoRoot);
77
79
  add('knowledge graph', gstatus === 'fresh' ? 'pass' : 'warn', gstatus);
@@ -4,6 +4,7 @@ import { changeDir } from '../lib/paths.js';
4
4
  import { requireRepo, toChangeSlug, readLintConfig, jsonOut } from '../lib/cliutil.js';
5
5
  import { lintSpecText, countBlockers } from '../lib/speclint.js';
6
6
  import { assess } from '../assess/index.js';
7
+ import { resolveWorkflowMode } from '../lib/config.js';
7
8
  import { log, dim } from '../lib/log.js';
8
9
 
9
10
  // THE spec check (v10: lint absorbed review). Deterministic:
@@ -110,10 +111,12 @@ export function runLint(changeId, opts = {}) {
110
111
  }
111
112
  const agentAssessPath = path.join(cdir, '.agent-assess.json');
112
113
  if (currLvl || exists(agentAssessPath) || exists(path.join(cdir, 'risk-history.jsonl'))) {
114
+ const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot });
113
115
  const assessment = assess({
114
116
  stage: 'spec',
115
117
  changeId: slug,
116
118
  repoRoot,
119
+ mode: resolvedMode,
117
120
  persist: true
118
121
  });
119
122
  const effectiveLevel = assessment.risk.level;
@@ -157,6 +160,7 @@ export function register(program) {
157
160
  .command('lint <changeId>')
158
161
  .description('check the spec: artifacts + review record + BDD/acceptance criteria')
159
162
  .option('--repo-root <path>')
163
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
160
164
  .option('--json', 'stable JSON output for CI')
161
165
  .action((changeId, opts) => {
162
166
  process.exitCode = runLint(changeId, opts);
@@ -9,6 +9,7 @@ import { fail } from '../lib/errors.js';
9
9
  import { log } from '../lib/log.js';
10
10
  import { Option } from 'commander';
11
11
  import { inferInitialLevel, isSinglePrLevel } from '../lib/level.js';
12
+ import { resolveWorkflowMode } from '../lib/config.js';
12
13
 
13
14
  // STAGE 1 of the spec (v10: explore + propose are ONE step).
14
15
  // 1) scaffold the change through OpenSpec (derives canonical slug from requirement)
@@ -96,24 +97,32 @@ _(unavailable - graph query error)_
96
97
  }
97
98
  }
98
99
 
100
+ // Resolve workflow mode across precedence hierarchy (CLI > Env > Repo > Global > Default)
101
+ const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot });
102
+
99
103
  // Infer governance level (L0, L1, L2, L3) via unified assessment engine (grounded in explore.md)
100
104
  const { level, changeType, workflowMode, reason: levelReason } = inferInitialLevel({
101
105
  requirement,
102
106
  explicitLevel: opts.level,
103
107
  agentContext: opts.agentContext,
104
108
  repoRoot,
105
- changeId: slug
109
+ changeId: slug,
110
+ mode: resolvedMode
106
111
  });
107
112
 
108
113
  // Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
109
114
  const metaPath = path.join(cdir, '.openspec.yaml');
110
115
  if (exists(metaPath)) {
111
116
  const existing = readText(metaPath).trimEnd();
112
- writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
117
+ writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\ngovernanceMode: "${resolvedMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
113
118
  }
114
119
 
115
120
  if (workflowMode === 'single-pr') {
116
- log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR]`);
121
+ if (resolvedMode === 'supervised') {
122
+ log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Supervised Single PR mode: code & specs in one PR, human merge confirmation required]`);
123
+ } else {
124
+ log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR, auto-merge eligible]`);
125
+ }
117
126
  } else {
118
127
  log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
119
128
  }
@@ -243,6 +252,7 @@ export function register(program) {
243
252
  .option('--no-design', 'skip generating technical design (design.md)')
244
253
  .option('--batch-grill', 'use batch-grill-me (present entire decision frontier in structured batches)')
245
254
  .option('--no-grill', 'skip interactive grilling interview (self-settle decisions in clarifications.md)')
255
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
246
256
  .addOption(new Option('--level <level>', 'internal governance level override (hidden)').hideHelp())
247
257
  .option('--repo-root <path>')
248
258
  .action((requirement, opts) => {
@@ -12,6 +12,7 @@ import { fail } from '../lib/errors.js';
12
12
  import { log } from '../lib/log.js';
13
13
  import { assess, renderLabels, renderPRComment } from '../assess/index.js';
14
14
  import { readEffectiveLevel } from '../lib/level.js';
15
+ import { resolveWorkflowMode } from '../lib/config.js';
15
16
 
16
17
  const SAFE_ENV_TEMPLATE_RE = /(^|\/)\.env\.(example|sample|template|defaults|schema)$/i;
17
18
  const SENSITIVE_OR_DUMP_PATTERNS = [
@@ -173,7 +174,8 @@ export async function createPR(changeId, targetBranch, opts = {}) {
173
174
 
174
175
  const lvlMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
175
176
  const changeLevel = lvlMatch ? lvlMatch[1].toUpperCase() : null;
176
- const isSinglePr = changeLevel === 'L0' || changeLevel === 'L1';
177
+ const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: targetBranch });
178
+ const isSinglePr = (changeLevel === 'L0' || changeLevel === 'L1') && resolvedMode !== 'spec-first' && !metaText.match(/^\s*workflowMode:\s*['"]?spec-first['"]?/m);
177
179
 
178
180
  let prType;
179
181
  if (opts.type) {
@@ -234,6 +236,7 @@ export async function createPR(changeId, targetBranch, opts = {}) {
234
236
  base: targetBranch,
235
237
  protectedBranch: targetBranch,
236
238
  openingPr: true,
239
+ mode: resolvedMode,
237
240
  ...opts,
238
241
  });
239
242
  if (verifyExit !== 0) {
@@ -301,6 +304,7 @@ ${proposalText}
301
304
  headSha: 'HEAD',
302
305
  changedFiles: diffFiles,
303
306
  repoRoot,
307
+ mode: resolvedMode,
304
308
  persist: false
305
309
  });
306
310
  const assessLabels = renderLabels(assessment);
@@ -596,6 +600,7 @@ export function register(program) {
596
600
  program
597
601
  .command('pr <changeId> <targetBranch>')
598
602
  .description('automatically open a Spec or Implementation PR: auto-detects stage, pre-flight checks, pushes branch, and attaches labels for CI AI review')
603
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
599
604
  .option('--repo-root <path>')
600
605
  .action(async (changeId, targetBranch, opts) => {
601
606
  await createPR(changeId, targetBranch, opts);
@@ -2,18 +2,18 @@ import path from 'node:path';
2
2
  import { exists, readText, walkFiles, listDir } from '../lib/fs.js';
3
3
  import { changeDir, openspecDir, CHANGES_DIR } from '../lib/paths.js';
4
4
  import { requireRepo, toChangeSlug, jsonOut } from '../lib/cliutil.js';
5
- import { lastCommitTouching } from '../lib/git.js';
5
+ import { lastCommitTouching, resolveDefaultBranch } from '../lib/git.js';
6
6
  import { verdictOf } from './lint.js';
7
7
  import { countUncheckedTasks } from './verify.js';
8
8
  import { log } from '../lib/log.js';
9
- import { isSinglePrLevel } from '../lib/level.js';
9
+ import { resolveTopology } from '../lib/level.js';
10
10
 
11
11
  // "Where am I?" for a change - a read-only view of the 7 stages from the working
12
12
  // tree + git. Useful for humans and for an agent deciding the next command.
13
13
  export function statusChange(changeId, opts = {}) {
14
14
  const repoRoot = requireRepo(opts);
15
15
  const slug = toChangeSlug(changeId);
16
- const branch = opts.protectedBranch ?? 'origin/main';
16
+ const branch = opts.protectedBranch ?? resolveDefaultBranch(repoRoot);
17
17
  const cdir = changeDir(repoRoot, slug);
18
18
 
19
19
  if (!exists(cdir)) {
@@ -42,30 +42,44 @@ export function statusChange(changeId, opts = {}) {
42
42
 
43
43
  const metaPath = path.join(cdir, '.openspec.yaml');
44
44
  let metaText = exists(metaPath) ? readText(metaPath) : '';
45
- const levelMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
46
- const level = levelMatch ? levelMatch[1].toUpperCase() : 'L1';
45
+
46
+ const topology = resolveTopology({ repoRoot, slug, baseRef: branch, cliMode: opts.mode });
47
+ const isSinglePr = topology.isSinglePr;
48
+ const level = topology.effectiveLevel || 'unlevelled';
49
+
50
+ const stage3Label = isSinglePr
51
+ ? '3 spec approval (co-located in single PR; human sign-off at merge)'
52
+ : `3 spec approved on ${branch}`;
47
53
 
48
54
  const stage = [
49
55
  ['1 explore (draft)', has('explore.md')],
50
56
  ['2 proposal.md', has('proposal.md')],
51
57
  ['2 spec delta', specFiles.length > 0],
52
- ['3 spec approved on ' + branch, Boolean(approvedSha)],
58
+ [stage3Label, isSinglePr ? '~' : Boolean(approvedSha)],
53
59
  ['4 tasks complete', unchecked === 0],
54
60
  ];
55
61
 
56
62
  let next;
57
63
  if (!has('explore.md') && !has('proposal.md')) next = `asdlc new ${changeId}`;
58
64
  else if (!has('proposal.md') || specFiles.length === 0) next = 'author proposal.md + specs/**';
59
- else if (!approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (after independent spec review & merge, run: asdlc approve ${changeId})`;
60
- else if (unchecked !== 0) next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
61
- else next = `asdlc verify ${changeId}`;
65
+ else if (isSinglePr) {
66
+ if (!has('tasks.md')) next = `author tasks.md, then run: asdlc apply ${changeId}`;
67
+ else if (unchecked !== 0) next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
68
+ else next = `asdlc verify ${changeId} && asdlc pr ${changeId} ${branch}`;
69
+ } else if (!approvedSha) {
70
+ next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (after independent spec review & merge, run: asdlc approve ${changeId})`;
71
+ } else if (unchecked !== 0) {
72
+ next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
73
+ } else {
74
+ next = `asdlc verify ${changeId}`;
75
+ }
62
76
 
63
77
  if (opts.json) {
64
- jsonOut({
78
+ const payload = {
65
79
  change: slug,
66
80
  exists: true,
67
81
  level,
68
- stage: stage.map(([name, ok]) => ({ name, ok })),
82
+ stage: stage.map(([name, ok]) => ({ name, ok: ok === '~' ? true : Boolean(ok) })),
69
83
  next,
70
84
  checks: {
71
85
  explore: has('explore.md'),
@@ -74,12 +88,20 @@ export function statusChange(changeId, opts = {}) {
74
88
  approvedSha,
75
89
  tasksComplete: unchecked === 0,
76
90
  }
77
- });
91
+ };
92
+ if (isSinglePr) {
93
+ payload.mode = 'single-pr';
94
+ payload.approvalTrack = 'colocated';
95
+ }
96
+ jsonOut(payload);
78
97
  return 0;
79
98
  }
80
99
 
81
100
  log.plain(`change: ${slug}`);
82
- for (const [name, ok] of stage) log.plain(` [${ok ? 'x' : ' '}] ${name}`);
101
+ for (const [name, ok] of stage) {
102
+ const mark = ok === '~' ? '~' : (ok ? 'x' : ' ');
103
+ log.plain(` [${mark}] ${name}`);
104
+ }
83
105
  log.plain('');
84
106
  log.plain(`next: ${next}`);
85
107
  return 0;
@@ -89,7 +111,7 @@ export function statusChange(changeId, opts = {}) {
89
111
  // Deliberately excludes completed/archived changes to keep output compact and scannable.
90
112
  export function statusPortfolio(opts = {}) {
91
113
  const repoRoot = requireRepo(opts);
92
- const branch = opts.protectedBranch ?? 'origin/main';
114
+ const branch = opts.protectedBranch ?? resolveDefaultBranch(repoRoot);
93
115
  const cdirRoot = path.join(openspecDir(repoRoot), CHANGES_DIR);
94
116
 
95
117
  if (!exists(cdirRoot)) {
@@ -118,8 +140,9 @@ export function statusPortfolio(opts = {}) {
118
140
  const specFiles = exists(path.join(cdir, 'specs'))
119
141
  ? walkFiles(path.join(cdir, 'specs')).filter((f) => f.endsWith('spec.md')) : [];
120
142
 
121
- const levelMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
122
- const level = levelMatch ? levelMatch[1].toUpperCase() : 'L1';
143
+ const topology = resolveTopology({ repoRoot, slug, baseRef: branch, cliMode: opts.mode });
144
+ const isSinglePr = topology.isSinglePr;
145
+ const level = topology.effectiveLevel || 'unlevelled';
123
146
 
124
147
  const reqMatch = metaText.match(/^\s*requirement:\s*([^\r\n]+)/m);
125
148
  let requirement = reqMatch ? reqMatch[1].trim() : null;
@@ -130,9 +153,7 @@ export function statusPortfolio(opts = {}) {
130
153
  const locked = [`openspec/changes/${slug}/proposal.md`, `openspec/changes/${slug}/specs`];
131
154
  const approvedSha = lastCommitTouching(repoRoot, branch, locked);
132
155
  const unchecked = has('tasks.md') ? countUncheckedTasks(readText(path.join(cdir, 'tasks.md'))) : null;
133
- const isSinglePr = isSinglePrLevel(level);
134
- const statusMatch = metaText.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
135
- const recordedStatus = statusMatch ? statusMatch[1].toLowerCase() : null;
156
+ const recordedStatus = topology.declaredStatus;
136
157
 
137
158
  let stage = '';
138
159
  let next = '';
@@ -144,7 +165,10 @@ export function statusPortfolio(opts = {}) {
144
165
  stage = 'Drafting Specs';
145
166
  next = `author proposal.md + specs/**`;
146
167
  } else if (isSinglePr) {
147
- if (unchecked === null) {
168
+ if (!has('tasks.md')) {
169
+ stage = 'Ready for Impl';
170
+ next = `author tasks.md, then run: asdlc apply ${slug}`;
171
+ } else if (unchecked === null) {
148
172
  stage = 'Ready for Impl';
149
173
  next = `asdlc apply ${slug}`;
150
174
  } else if (unchecked > 0) {
@@ -224,6 +248,7 @@ export function register(program) {
224
248
  .command('status [changeId]')
225
249
  .description('show where a change is in the 7 stages + the next command (or portfolio overview if omitted)')
226
250
  .option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
251
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
227
252
  .option('--repo-root <path>')
228
253
  .option('--json', 'output machine-readable JSON')
229
254
  .action((changeId, opts) => {
@@ -12,6 +12,7 @@ import { checkSchema } from '../lib/schema.js';
12
12
  import { loadPolicy, isAdvisory, DEFAULT_POLICY, matchesAny } from '../lib/policy.js';
13
13
  import { classifyPR } from '../lib/prtype.js';
14
14
  import { isSinglePrLevel, requiresHumanReview, readChangeLevel, readEffectiveLevel } from '../lib/level.js';
15
+ import { resolveWorkflowMode } from '../lib/config.js';
15
16
  import { assess, renderCheckSummary, loadRiskHistory } from '../assess/index.js';
16
17
  import { checkTestPresence, checkTaskEvidence } from '../lib/tdd.js';
17
18
  import { runTests, parseSpecAcceptanceCriteria } from './test.js';
@@ -30,6 +31,7 @@ function meta(repoRoot, changeId) {
30
31
  specSha: data.specSha ? String(data.specSha) : null,
31
32
  status: data.status ? String(data.status) : null,
32
33
  level: data.level ? String(data.level).toUpperCase() : null,
34
+ workflowMode: data.workflowMode ? String(data.workflowMode).toLowerCase() : null,
33
35
  escalatedInImpl: data.escalatedInImpl === true || String(data.escalatedInImpl).toLowerCase() === 'true',
34
36
  };
35
37
  } catch {
@@ -37,11 +39,13 @@ function meta(repoRoot, changeId) {
37
39
  const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
38
40
  const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
39
41
  const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
42
+ const wm = text.match(/^\s*workflowMode:\s*['"]?([^\s'"]+)['"]?\s*$/m);
40
43
  const esc = text.match(/^\s*escalatedInImpl:\s*['"]?([^\s'"]+)['"]?\s*$/m);
41
44
  return {
42
45
  specSha: sha ? sha[1] : null,
43
46
  status: status ? status[1] : null,
44
47
  level: lvl ? lvl[1].toUpperCase() : null,
48
+ workflowMode: wm ? wm[1].toLowerCase() : null,
45
49
  escalatedInImpl: esc ? esc[1].toLowerCase() === 'true' : false,
46
50
  };
47
51
  }
@@ -239,7 +243,11 @@ export function runVerify(changeId, opts = {}) {
239
243
  preImplRecords.every((r) => isSinglePrLevel(r.risk?.level)) &&
240
244
  history.some((r) => r.stage === 'impl' && !isSinglePrLevel(r.risk?.level)))
241
245
  );
242
- const isSinglePr = Boolean(isSinglePrLevel(changeLevel) || escalatedOnlyInImpl);
246
+ const resolvedMode = resolveWorkflowMode({ cliMode: opts.mode, repoRoot, baseRef: base });
247
+ const isSinglePr = Boolean(
248
+ (isSinglePrLevel(changeLevel) && resolvedMode !== 'spec-first' && metaInfo.workflowMode !== 'spec-first') ||
249
+ escalatedOnlyInImpl
250
+ );
243
251
 
244
252
  const pr = classifyPR({ changedFiles, changeOnMain, policy, emergency: opts.emergency, level: changeLevel, repoRoot, singlePr: isSinglePr });
245
253
  add('pr-type', pr.type === 'invalid' ? 'fail' : 'pass', `type=${pr.type} (${pr.reason})`);
@@ -291,6 +299,7 @@ export function runVerify(changeId, opts = {}) {
291
299
  headSha: head,
292
300
  changedFiles,
293
301
  repoRoot,
302
+ mode: resolvedMode,
294
303
  persist: Boolean(repoRoot && changeId && exists(cdir) && !opts.openingPr && !isCI)
295
304
  });
296
305
 
@@ -441,6 +450,7 @@ export function register(program) {
441
450
  .option('--protected-branch <ref>', 'branch the approved spec must be merged into', 'origin/main')
442
451
  .option('--base <ref>', 'base ref for the PR diff (default: protected branch)')
443
452
  .option('--head <ref>', 'head ref (default: HEAD)')
453
+ .option('--mode <mode>', 'workflow mode: supervised (default) | spec-first | auto')
444
454
  .option('--approved', 'flag indicating human lead approval is verified on PR / platform')
445
455
  .option('--emergency', 'emergency mode bypassing standard branch checks')
446
456
  .option('--required', 'require AI verification gate to pass')
package/src/lib/agents.js CHANGED
@@ -11,27 +11,26 @@ import { graphExists } from './graphify.js';
11
11
  export const ROUTING_MARKER = '<!-- asdlc:routing -->';
12
12
  export const STATUS_MARKER = '<!-- asdlc:system-status -->';
13
13
 
14
+ export function hasCurrentRouting(text = '') {
15
+ return String(text).includes(ROUTING_MARKER) && String(text).includes('Two-Track Execution Flow');
16
+ }
17
+
14
18
  const ROUTING_BLOCK = `${ROUTING_MARKER}
15
- ## Agentic SDLC — the 7 stages (one front door)
19
+ ## Agentic SDLC — Two-Track Execution Flow
20
+
21
+ Everything runs through \`asdlc\` - do NOT call \`openspec ...\` directly. Check current level and mode with \`asdlc status <ID>\`.
16
22
 
17
- Everything runs through \`asdlc\` - do NOT call \`openspec ...\` directly. There is no
18
- raw escape hatch: the wrappers ARE the guards (graph refresh, approval, checks).
23
+ ### 📌 Track A: High-Risk & Core Modules (L2/L3 or spec-first)
24
+ Dual-PR lifecycle with cryptographic intent lock:
25
+ 1. \`asdlc new "<intent>"\` (scaffold + explore + **grill-me interview embedded**, settle \`clarifications.md\`, then author proposal/specs) ->
26
+ 2. \`asdlc lint <ID>\` -> 3. \`asdlc pr <ID> <target>\` (Spec PR) -> 4. Human merge & \`asdlc approve <ID>\` ->
27
+ 5. \`asdlc apply <ID>\` (TDD loop) -> 6. \`asdlc verify <ID>\` -> 7. \`asdlc pr <ID> <target>\` (Impl PR) -> 8. \`asdlc archive <ID>\`.
19
28
 
20
- 1. **new** - \`asdlc new "<requirement>" [--batch-grill] [--no-grill]\`: scaffold the change (derives slug from intent) +
21
- refresh the knowledge graph + write \`explore.md\` + seed \`clarifications.md\`.
22
- ▶ **IMMEDIATE ACTION FOR AGENT**: DO NOT stop or ask permission. In the SAME interaction turn,
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).
27
- ▶ **CRITICAL**: ONLY AFTER \`clarifications.md\` is settled may you author **proposal.md -> specs/**\`. (Independent AI Review is executed in an isolated agent session via \`asdlc-spec-review\` / \`asdlc-impl-review\` skills).
28
- 2. **grill** - (embedded in Stage 2) settle all design forks in \`clarifications.md\` BEFORE writing specs.
29
- 3. **lint** - \`asdlc lint <ID>\`: artifacts + BDD/acceptance criteria. Open Spec PR via \`asdlc pr <ID> <targetBranch>\`.
30
- 4. **approve** - human/TL approves (via PR merge, on PR, or in-place); \`asdlc approve <ID>\` records approved SHA + READY_FOR_IMPL.
31
- 5. **apply** - \`asdlc apply <ID>\` (guard: the spec must be approved), then
32
- \`/opsx-apply\` with task-level TDD + task-level converge.
33
- 6. **verify** - \`asdlc verify <ID>\`: approved SHA, artifacts, tasks complete, tests, AI.
34
- 7. **archive** - \`asdlc archive [<ID> | --merged]\`: post-merge compaction syncing specs to openspec/specs/ (updates AGENTS.md only on \`--agents\` or constitutional changes).
29
+ ### ⚡ Track B: Bounded & Routine Modules (L0/L1 under supervised/auto)
30
+ Fast-path Single-PR lifecycle (Spec & code in one PR, human confirms at merge):
31
+ 1. \`asdlc new "<intent>"\` (grill-me interview embedded) -> 2. Draft \`specs/\` & \`tasks.md\` ->
32
+ 3. \`asdlc apply <ID>\` (directly starts TDD loop; **separate Spec PR and \`asdlc approve\` are waived**) ->
33
+ 4. \`asdlc verify <ID>\` -> 5. \`asdlc pr <ID> <target>\` (Single PR; human Approve at merge is still required under supervised; auto per policy) -> 6. \`asdlc archive <ID>\`.
35
34
 
36
35
  Need orientation? \`asdlc status <ID>\` (where am I / next command) and \`asdlc doctor\`
37
36
  (environment health). A bad spec is never edited: close it and \`asdlc new\` again.`;