@akjamie/agentic-sdlc 1.9.2 → 2.0.0-alpha.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.
@@ -1,13 +1,13 @@
1
1
  import path from 'node:path';
2
2
  import os from 'node:os';
3
3
  import fs from 'node:fs';
4
- import { exists, listDir, readText, copyTree, ensureDir } from '../lib/fs.js';
4
+ import { exists, listDir, readText, copyTree, ensureDir, removeDir } from '../lib/fs.js';
5
5
  import { skillsAssetDir, resolveRepoRoot, openspecDir } from '../lib/paths.js';
6
6
  import { detectTools, installSkills } from './init.js';
7
7
  import { fail } from '../lib/errors.js';
8
8
  import { log } from '../lib/log.js';
9
9
 
10
- import { TOOL_REGISTRY, getToolDefinition } from '../lib/tools.js';
10
+ import { TOOL_REGISTRY, getToolDefinition, DEPRECATED_SKILLS } from '../lib/tools.js';
11
11
 
12
12
  /**
13
13
  * Parse YAML frontmatter from a SKILL.md file
@@ -124,6 +124,14 @@ export function installGlobalSkills(opts = {}) {
124
124
  log.ok(`installed skills -> ~/${dir}/skills/`);
125
125
  installedCount++;
126
126
  }
127
+ // Prune deprecated legacy skills from global user agent directory
128
+ for (const dep of DEPRECATED_SKILLS) {
129
+ const depPath = path.join(dest, dep);
130
+ if (exists(depPath)) {
131
+ removeDir(depPath);
132
+ log.ok(`pruned deprecated skill '${dep}' from ~/${dir}/skills/`);
133
+ }
134
+ }
127
135
  }
128
136
 
129
137
  log.info('');
@@ -1,14 +1,48 @@
1
1
  import path from 'node:path';
2
- import { execFileSync, spawnSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { spawnSync } from 'node:child_process';
3
4
  import { exists } from '../lib/fs.js';
4
5
  import { resolveRepoRoot, schemaAssetDir, openspecDir } from '../lib/paths.js';
5
6
  import { installSchema, builtinSchemaVersion } from '../lib/schema.js';
6
7
  import { updateRepo } from './update.js';
7
8
  import { doctor } from './doctor.js';
8
9
  import { log } from '../lib/log.js';
10
+ import { resolveContainerEngine, isEngineAvailable } from '../lib/container.js';
9
11
 
10
12
  import { detectTools, installSkills } from './init.js';
11
13
 
14
+ const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
15
+
16
+ export function resolveRunnerImageTag(opts = {}) {
17
+ return opts.image || process.env.ASDLC_RUNNER_IMAGE || `ghcr.io/akjamie/asdlc-runner:${pkg.version}`;
18
+ }
19
+
20
+ export function upgradeRunnerImage(opts = {}) {
21
+ const image = resolveRunnerImageTag(opts);
22
+ const execFn = opts.execFn || spawnSync;
23
+ let engine = null;
24
+ try {
25
+ engine = resolveContainerEngine(opts, execFn);
26
+ } catch {
27
+ engine = isEngineAvailable('docker', execFn) ? 'docker' : (isEngineAvailable('podman', execFn) ? 'podman' : null);
28
+ }
29
+ if (!engine && opts.execFn) {
30
+ engine = opts.engine || 'docker';
31
+ }
32
+ if (!engine) {
33
+ log.info(`note: container engine (docker/podman) not found; runner image pinned at ${image}`);
34
+ return { pulled: false, skipped: true, image };
35
+ }
36
+ log.step(`syncing runner container image ${image} via ${engine}...`);
37
+ const res = execFn(engine, ['pull', image], { encoding: 'utf8', stdio: opts.execFn ? 'pipe' : 'inherit' });
38
+ if (res && res.status === 0) {
39
+ log.ok(`synced runner image ${image}`);
40
+ return { pulled: true, skipped: false, image, engine };
41
+ }
42
+ log.warn(`runner image pull failed (${image}); container mode will attempt pull on first launch`);
43
+ return { pulled: false, skipped: false, image, engine };
44
+ }
45
+
12
46
  function which(name) {
13
47
  const finder = process.platform === 'win32' ? 'where' : 'which';
14
48
  const r = spawnSync(finder, [name], { encoding: 'utf8' });
@@ -167,6 +201,12 @@ export function runUpgrade(opts = {}) {
167
201
  }
168
202
  }
169
203
 
204
+ if (opts.pullImage) {
205
+ upgradeRunnerImage(opts);
206
+ } else {
207
+ log.info(`runner image aligned to ${resolveRunnerImageTag(opts)} (pass --pull-image to pre-pull)`);
208
+ }
209
+
170
210
  log.info('');
171
211
  log.ok('Toolchain upgrade complete.');
172
212
 
@@ -184,6 +224,8 @@ export function register(program) {
184
224
  .command('upgrade')
185
225
  .description('upgrade the toolchain: asdlc CLI, OpenSpec, Graphify, managed schemas, and repo or global skills')
186
226
  .option('-g, --global', 'upgrade toolchain and refresh global user skills (~/.agents) for CI runners')
227
+ .option('--pull-image', 'pre-pull version-pinned asdlc runner container image')
228
+ .option('--image <tag>', 'override runner container image tag when pulling')
187
229
  .option('--no-asdlc', 'skip upgrading asdlc itself')
188
230
  .option('--no-openspec', 'skip upgrading openspec')
189
231
  .option('--no-graphify', 'skip upgrading graphify')
@@ -192,6 +192,55 @@ export function extractJson(text) {
192
192
  }
193
193
  }
194
194
 
195
+ const TEST_FILE_RE = /(?:^|\/)(?:test|tests|__tests__)\/|\.(?:test|spec)\.[a-z0-9]+$/i;
196
+ const TEST_SKIP_PATTERNS = [
197
+ { label: '.skip(', re: /\b(?:it|test|describe)\.skip\s*\(/ },
198
+ { label: 'xit/xtest/xdescribe', re: /\bx(?:it|test|describe)\s*\(/ },
199
+ { label: '@pytest.mark.skip', re: /@pytest\.mark\.skip\b/ },
200
+ { label: '@Disabled', re: /@Disabled\b/ },
201
+ { label: '#[ignore]', re: /#\[ignore\]/ },
202
+ ];
203
+
204
+ /**
205
+ * Anti-Test-Weakening Gate (§6.4.4):
206
+ * Fails if the implementation diff deletes test files or adds new skip/disable annotations.
207
+ */
208
+ export function checkTestWeakening(repoRoot, base, head, changedFiles = [], opts = {}) {
209
+ const issues = [];
210
+ const nameStatusRaw = typeof opts.nameStatusText === 'string'
211
+ ? opts.nameStatusText
212
+ : (git(['diff', '--name-status', `${base}...${head}`], repoRoot, { allowFail: true }) ?? '');
213
+
214
+ for (const line of nameStatusRaw.split(/\r?\n/)) {
215
+ const m = line.match(/^D\s+(.+)$/);
216
+ if (m && TEST_FILE_RE.test(m[1].trim())) {
217
+ issues.push(`deleted test file: ${m[1].trim()}`);
218
+ }
219
+ }
220
+
221
+ const testFiles = (changedFiles || []).filter((f) => TEST_FILE_RE.test(f));
222
+ if (testFiles.length > 0 || typeof opts.diffText === 'string') {
223
+ const diffText = typeof opts.diffText === 'string'
224
+ ? opts.diffText
225
+ : (git(['diff', '-U0', `${base}...${head}`, '--', ...testFiles], repoRoot, { allowFail: true }) ?? '');
226
+ for (const line of diffText.split(/\r?\n/)) {
227
+ if (!line.startsWith('+') || line.startsWith('+++')) continue;
228
+ for (const pat of TEST_SKIP_PATTERNS) {
229
+ if (pat.re.test(line)) {
230
+ issues.push(`newly skipped/disabled test (${pat.label}): ${line.slice(1).trim().slice(0, 80)}`);
231
+ break;
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ return {
238
+ ok: issues.length === 0,
239
+ issues,
240
+ detail: issues.length === 0 ? 'no deleted or newly skipped tests' : issues.join('; '),
241
+ };
242
+ }
243
+
195
244
  export function runVerify(changeId, opts = {}) {
196
245
  const results = [];
197
246
  const add = (name, status, detail) => results.push({ name, status, detail });
@@ -365,6 +414,9 @@ export function runVerify(changeId, opts = {}) {
365
414
  const testDiff = checkTestPresence(changedFiles);
366
415
  add('test-presence', testDiff.ok ? 'pass' : 'fail', testDiff.detail);
367
416
 
417
+ const weakening = checkTestWeakening(repoRoot, base, head, changedFiles, opts);
418
+ add('anti-test-weakening', weakening.ok ? 'pass' : 'fail', weakening.detail);
419
+
368
420
  if (exists(tasksPath)) {
369
421
  const evidence = checkTaskEvidence(readText(tasksPath));
370
422
  add('tdd-evidence', evidence.ok ? 'pass' : 'fail', evidence.detail);
@@ -0,0 +1,345 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { execFileSync } from 'node:child_process';
6
+ import { exists } from './fs.js';
7
+ import { fail } from './errors.js';
8
+
9
+ function base64UrlEncode(input) {
10
+ const buf = Buffer.isBuffer(input) ? input : Buffer.from(String(input), 'utf8');
11
+ return buf.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
12
+ }
13
+
14
+ /**
15
+ * Mints a signed RS256 JSON Web Token (JWT) for authenticating as a GitHub App.
16
+ */
17
+ export function mintGitHubAppJwt(appId, privateKeyPem, { nowSec = Math.floor(Date.now() / 1000) } = {}) {
18
+ if (!appId || !privateKeyPem) {
19
+ fail('GitHub App JWT requires both appId and privateKeyPem', { code: 'ASDLC_ERR_AUTH_CONFIG' });
20
+ }
21
+ const header = base64UrlEncode(JSON.stringify({ alg: 'RS256', typ: 'JWT' }));
22
+ const payload = base64UrlEncode(JSON.stringify({
23
+ iat: nowSec - 60,
24
+ exp: nowSec + 540,
25
+ iss: String(appId),
26
+ }));
27
+ const signingInput = `${header}.${payload}`;
28
+ const signer = crypto.createSign('RSA-SHA256');
29
+ signer.update(signingInput);
30
+ signer.end();
31
+ const signature = base64UrlEncode(signer.sign(privateKeyPem));
32
+ return `${signingInput}.${signature}`;
33
+ }
34
+
35
+ /**
36
+ * Resolves Git & PR credentials in priority order:
37
+ * 1. GitHub App Installation Token (scoped, triggers downstream CI)
38
+ * 2. GitLab Project Access Token
39
+ * 3. Scoped Fine-Grained PAT
40
+ * 4. Developer CLI Keychain (`gh auth token --hostname <host>`)
41
+ */
42
+ export async function resolveGitCredentials({
43
+ env = process.env,
44
+ globalConfig = null,
45
+ host = 'github.com',
46
+ provider = null,
47
+ execFn = null,
48
+ fetchFn = null,
49
+ } = {}) {
50
+ const effectiveHost = String(host || globalConfig?.git?.default_host || 'github.com').toLowerCase();
51
+ const inferredProvider = provider
52
+ || globalConfig?.git?.provider
53
+ || (effectiveHost.includes('gitlab') ? 'gitlab' : 'github');
54
+
55
+ // 1. GitHub App Installation Token
56
+ const appToken = env?.ASDLC_GITHUB_APP_TOKEN;
57
+ const appId = env?.ASDLC_GITHUB_APP_ID || globalConfig?.git?.app_id;
58
+ const installationId = env?.ASDLC_GITHUB_APP_INSTALLATION_ID || globalConfig?.git?.installation_id;
59
+ const privateKeyRaw = env?.ASDLC_GITHUB_APP_PRIVATE_KEY || globalConfig?.git?.private_key;
60
+ const privateKeyPath = env?.ASDLC_GITHUB_APP_PRIVATE_KEY_PATH || globalConfig?.git?.private_key_path;
61
+ const privateKeyPem = privateKeyRaw || (privateKeyPath && exists(privateKeyPath) ? fs.readFileSync(privateKeyPath, 'utf8') : null);
62
+
63
+ if (appToken || (appId && installationId && privateKeyPem)) {
64
+ let token = appToken || null;
65
+ if (!token && appId && installationId && privateKeyPem) {
66
+ const jwt = mintGitHubAppJwt(appId, privateKeyPem);
67
+ const apiBase = effectiveHost === 'github.com'
68
+ ? 'https://api.github.com'
69
+ : `https://${effectiveHost}/api/v3`;
70
+ const doFetch = fetchFn || globalThis.fetch;
71
+ if (typeof doFetch !== 'function') {
72
+ fail('fetch API unavailable for exchanging GitHub App installation token', { code: 'ASDLC_ERR_AUTH_EXCHANGE' });
73
+ }
74
+ const res = await doFetch(`${apiBase}/app/installations/${installationId}/access_tokens`, {
75
+ method: 'POST',
76
+ headers: {
77
+ Authorization: `Bearer ${jwt}`,
78
+ Accept: 'application/vnd.github+json',
79
+ 'User-Agent': 'agentic-sdlc',
80
+ },
81
+ });
82
+ if (!res.ok) {
83
+ fail(`GitHub App token exchange failed with status ${res.status}`, { code: 'ASDLC_ERR_AUTH_EXCHANGE' });
84
+ }
85
+ const json = await res.json();
86
+ token = json.token;
87
+ }
88
+ return {
89
+ type: 'github-app',
90
+ provider: 'github',
91
+ token,
92
+ host: effectiveHost,
93
+ username: 'x-access-token',
94
+ authorName: 'asdlc-bot[bot]',
95
+ authorEmail: 'asdlc-bot[bot]@users.noreply.github.com',
96
+ triggersCi: true,
97
+ };
98
+ }
99
+
100
+ // 2. GitLab Project Access Token
101
+ const gitlabToken = env?.ASDLC_GITLAB_TOKEN
102
+ || env?.GITLAB_TOKEN
103
+ || (inferredProvider === 'gitlab' ? globalConfig?.git?.token : null);
104
+ if (gitlabToken) {
105
+ return {
106
+ type: 'gitlab-project-token',
107
+ provider: 'gitlab',
108
+ token: gitlabToken,
109
+ host: effectiveHost,
110
+ username: 'oauth2',
111
+ authorName: 'asdlc-bot',
112
+ authorEmail: 'asdlc-bot@noreply.gitlab.com',
113
+ triggersCi: true,
114
+ };
115
+ }
116
+
117
+ // 3. Scoped Fine-Grained PAT
118
+ const scopedPat = env?.ASDLC_GIT_TOKEN || globalConfig?.git?.token || env?.GH_TOKEN || env?.GITHUB_TOKEN;
119
+ if (scopedPat) {
120
+ return {
121
+ type: 'scoped-pat',
122
+ provider: 'github',
123
+ token: scopedPat,
124
+ host: effectiveHost,
125
+ username: 'x-access-token',
126
+ authorName: env?.GIT_AUTHOR_NAME || 'asdlc-bot',
127
+ authorEmail: env?.GIT_AUTHOR_EMAIL || 'asdlc-bot@users.noreply.github.com',
128
+ triggersCi: env?.GITHUB_ACTIONS !== 'true' || Boolean(env?.ASDLC_GIT_TOKEN || globalConfig?.git?.token),
129
+ };
130
+ }
131
+
132
+ // 4. Developer CLI Keychain fallback
133
+ try {
134
+ const runGh = execFn || ((cmd, args) => execFileSync(cmd, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }));
135
+ const out = String(runGh('gh', ['auth', 'token', '--hostname', effectiveHost]) || '').trim();
136
+ if (out) {
137
+ return {
138
+ type: 'developer-keychain',
139
+ provider: 'github',
140
+ token: out,
141
+ host: effectiveHost,
142
+ username: 'x-access-token',
143
+ authorName: env?.GIT_AUTHOR_NAME || 'asdlc-bot',
144
+ authorEmail: env?.GIT_AUTHOR_EMAIL || 'asdlc-bot@users.noreply.github.com',
145
+ triggersCi: true,
146
+ };
147
+ }
148
+ } catch {
149
+ // ignore keychain failure
150
+ }
151
+
152
+ return null;
153
+ }
154
+
155
+ /**
156
+ * Builds an isolated in-memory Git/CLI environment with credential.helper wired dynamically
157
+ * so tokens are never written to disk or .git/config.
158
+ */
159
+ export function buildEphemeralGitEnv(cred, baseEnv = process.env) {
160
+ const out = { ...baseEnv, GIT_TERMINAL_PROMPT: '0' };
161
+ if (!cred || !cred.token) return out;
162
+
163
+ if (cred.provider === 'gitlab') {
164
+ out.GITLAB_TOKEN = cred.token;
165
+ } else {
166
+ out.GH_TOKEN = cred.token;
167
+ out.GITHUB_TOKEN = cred.token;
168
+ }
169
+
170
+ const tokenVar = cred.provider === 'gitlab' ? '$GITLAB_TOKEN' : '$GH_TOKEN';
171
+ const existingCount = Number(out.GIT_CONFIG_COUNT || 0);
172
+ out[`GIT_CONFIG_KEY_${existingCount}`] = 'credential.helper';
173
+ out[`GIT_CONFIG_VALUE_${existingCount}`] = `!f() { echo username=${cred.username || 'x-access-token'}; echo password=${tokenVar}; }; f`;
174
+ out.GIT_CONFIG_COUNT = String(existingCount + 1);
175
+ return out;
176
+ }
177
+
178
+ /**
179
+ * Formats an automated bot commit message with an optional human Co-authored-by trailer.
180
+ */
181
+ export function formatBotCommitMessage(message, { coAuthorName = null, coAuthorEmail = null } = {}) {
182
+ const base = String(message ?? '').trim();
183
+ if (coAuthorName && coAuthorEmail) {
184
+ return `${base}\n\nCo-authored-by: ${coAuthorName} <${coAuthorEmail}>`;
185
+ }
186
+ return base;
187
+ }
188
+
189
+ function maskToken(value) {
190
+ const str = String(value);
191
+ if (str.length <= 8) return '********';
192
+ const prefixMatch = str.match(/^([a-zA-Z]+_)/);
193
+ const prefix = prefixMatch ? prefixMatch[1] : str.slice(0, 3);
194
+ const tail = str.slice(-4);
195
+ return `${prefix}************${tail}`;
196
+ }
197
+
198
+ /**
199
+ * Redacts known credential patterns, URL basic-auth secrets, PEM private keys,
200
+ * and explicit runtime secrets from stdout/stderr/artifact strings.
201
+ */
202
+ export function redactSecrets(text, explicitSecrets = []) {
203
+ let out = String(text ?? '');
204
+ if (!out) return out;
205
+
206
+ // Mask explicit runtime secret strings first
207
+ for (const sec of explicitSecrets) {
208
+ if (sec && typeof sec === 'string' && sec.length >= 4) {
209
+ const masked = maskToken(sec);
210
+ out = out.split(sec).join(masked);
211
+ }
212
+ }
213
+
214
+ // Mask PEM private keys
215
+ out = out.replace(/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g, '[REDACTED_PRIVATE_KEY]');
216
+
217
+ // Mask Bearer / Basic auth headers
218
+ out = out.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, (_, scheme) => `${scheme} ************`);
219
+
220
+ // Mask URL-embedded credentials: https://user:secret@host
221
+ out = out.replace(/(https?:\/\/[^:/\s]+:)([^@\s]+)(@)/gi, (_, pre, _secret, at) => `${pre}************${at}`);
222
+
223
+ // Mask known provider tokens (GitHub, GitLab, Anthropic, OpenAI/Ark)
224
+ out = out.replace(/\b(?:ghp|ghs|ghu|gho|ghr|github_pat|glpat|sk-ant|sk|xoxb|xoxp)[_-][A-Za-z0-9_-]{8,}\b/g, (m) => maskToken(m));
225
+
226
+ return out;
227
+ }
228
+
229
+ /**
230
+ * Resolves AI harness base configuration following the Zero-Schema-Loss whole-file policy:
231
+ * 1. Imported enterprise config at ~/.asdlc/agent/opencode/opencode.json
232
+ * 2. Host native config at ~/.config/opencode/opencode.json (plus auth.json)
233
+ * 3. Generated single-provider fallback from globalConfig.agent
234
+ * Model selection overrides are passed via CLI `-m <provider/model>` flags without mutating host files.
235
+ */
236
+ export function resolveAgentHarnessConfig({
237
+ globalConfig = {},
238
+ cliModel = null,
239
+ cliReviewModel = null,
240
+ homeDir = os.homedir(),
241
+ env = process.env,
242
+ } = {}) {
243
+ const harness = (env?.ASDLC_AGENT_HARNESS || globalConfig?.agent?.harness || 'opencode').toLowerCase();
244
+ const enterpriseConfigPath = path.join(homeDir, '.asdlc', 'agent', 'opencode', 'opencode.json');
245
+ const hostOpenCodeDir = path.join(homeDir, '.config', 'opencode');
246
+ const hostConfigPath = path.join(hostOpenCodeDir, 'opencode.json');
247
+ const hostAuthPath = path.join(homeDir, '.local', 'share', 'opencode', 'auth.json');
248
+
249
+ let configSource = 'generated-minimal';
250
+ let baseConfigPath = null;
251
+ let generatedConfig = null;
252
+
253
+ if (exists(enterpriseConfigPath)) {
254
+ configSource = 'enterprise-template';
255
+ baseConfigPath = enterpriseConfigPath;
256
+ } else if (exists(hostConfigPath)) {
257
+ configSource = 'host-inherited';
258
+ baseConfigPath = hostConfigPath;
259
+ } else {
260
+ const provider = globalConfig?.agent?.provider || 'anthropic';
261
+ const baseUrl = globalConfig?.agent?.base_url || null;
262
+ const customHeaders = globalConfig?.agent?.custom_headers || null;
263
+ const providerOptions = {};
264
+ if (baseUrl) providerOptions.baseURL = baseUrl;
265
+ if (customHeaders && typeof customHeaders === 'object') providerOptions.headers = customHeaders;
266
+ generatedConfig = {
267
+ $schema: 'https://opencode.ai/config.json',
268
+ provider: {
269
+ [provider]: Object.keys(providerOptions).length > 0 ? { options: providerOptions } : {},
270
+ },
271
+ };
272
+ }
273
+
274
+ const authorModel = cliModel || env?.ASDLC_AGENT_MODEL || globalConfig?.agent?.model || null;
275
+ const reviewModel = cliReviewModel || env?.ASDLC_REVIEW_MODEL || globalConfig?.agent?.review_model || authorModel;
276
+ const providerName = globalConfig?.agent?.provider || 'anthropic';
277
+ const apiKey = env?.ASDLC_AGENT_API_KEY || globalConfig?.agent?.api_key || null;
278
+ const authPayload = apiKey
279
+ ? { [providerName]: { type: 'api', key: apiKey } }
280
+ : null;
281
+
282
+ const buildRunArgs = (prompt, modelOverride = null) => {
283
+ if (harness === 'claude') {
284
+ const args = ['-p', '--dangerously-skip-permissions'];
285
+ if (modelOverride) args.push('--model', modelOverride);
286
+ args.push(prompt);
287
+ return args;
288
+ }
289
+ const args = ['run'];
290
+ if (modelOverride) args.push('-m', modelOverride);
291
+ args.push(prompt);
292
+ return args;
293
+ };
294
+
295
+ return {
296
+ harness,
297
+ configSource,
298
+ baseConfigPath,
299
+ authPath: exists(hostAuthPath) ? hostAuthPath : null,
300
+ generatedConfig,
301
+ authPayload,
302
+ model: authorModel,
303
+ authorModel,
304
+ reviewModel,
305
+ heterogeneous: Boolean(authorModel && reviewModel && authorModel !== reviewModel),
306
+ buildAuthorArgs: (prompt) => buildRunArgs(prompt, authorModel),
307
+ buildReviewerArgs: (prompt) => buildRunArgs(prompt, reviewModel),
308
+ };
309
+ }
310
+
311
+ /**
312
+ * Resolves explicit `env.*` variables and `runner.env_passthrough` wildcard globs
313
+ * (e.g. `JIRA_*,CONFLUENCE_*`) into an environment map for intake and container execution.
314
+ */
315
+ export function resolvePassthroughEnv(globalConfig = {}, hostEnv = process.env) {
316
+ const out = {};
317
+ const explicitEnv = globalConfig?.env;
318
+ if (explicitEnv && typeof explicitEnv === 'object') {
319
+ for (const [k, v] of Object.entries(explicitEnv)) {
320
+ if (v !== undefined && v !== null && String(v).length > 0) {
321
+ out[k] = String(v);
322
+ }
323
+ }
324
+ }
325
+
326
+ const rawPatterns = globalConfig?.runner?.env_passthrough || hostEnv?.ASDLC_ENV_PASSTHROUGH || '';
327
+ const patterns = String(rawPatterns)
328
+ .split(',')
329
+ .map((p) => p.trim())
330
+ .filter(Boolean);
331
+
332
+ if (patterns.length > 0 && hostEnv && typeof hostEnv === 'object') {
333
+ for (const pattern of patterns) {
334
+ const regexStr = `^${pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')}$`;
335
+ const re = new RegExp(regexStr);
336
+ for (const [k, v] of Object.entries(hostEnv)) {
337
+ if (v !== undefined && v !== null && String(v).length > 0 && re.test(k)) {
338
+ out[k] = String(v);
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
+ return out;
345
+ }