mandrel 2.83.0 → 2.84.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/.agents/README.md +65 -20
- package/.agents/docs/configuration.md +36 -0
- package/.agents/docs/runbooks/mods.md +98 -54
- package/.agents/docs/workflows.md +14 -0
- package/.agents/instructions.md +4 -1
- package/.agents/mods/mandrel-status/hooks/register.tsx +579 -204
- package/.agents/mods/mandrel-status/types/index.d.ts +58 -13
- package/.agents/scripts/boot-sweep.js +42 -13
- package/.agents/scripts/generate-workflows-doc.js +14 -0
- package/.agents/scripts/lib/bootstrap/agents-md-fold.js +99 -16
- package/.agents/scripts/lib/bootstrap/manifest.js +4 -4
- package/.agents/scripts/lib/bootstrap/project-bootstrap.js +16 -1
- package/.agents/scripts/lib/codex/agents-projection.js +284 -0
- package/.agents/scripts/lib/codex/skills-projection.js +291 -0
- package/.agents/scripts/lib/config/agentrc-overlay.js +91 -0
- package/.agents/scripts/lib/config/sync-agentrc.js +39 -19
- package/.agents/scripts/lib/config-resolver.js +5 -42
- package/.agents/scripts/lib/config-settings-schema-quality.js +1 -1
- package/.agents/scripts/lib/observability/source-classifier.js +2 -0
- package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +152 -0
- package/.agents/scripts/lib/orchestration/review-providers/codex.js +33 -105
- package/.agents/scripts/lib/orchestration/review-providers/provider-severity.js +30 -0
- package/.agents/scripts/lib/orchestration/review-providers/security-review.js +3 -17
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +12 -5
- package/.agents/scripts/lib/single-story-sweep/reconcile-closing.js +89 -0
- package/.agents/scripts/single-story-init.js +20 -5
- package/.agents/scripts/sync-agentrc.js +5 -3
- package/.agents/scripts/sync-claude-agents.js +20 -0
- package/.agents/scripts/sync-claude-commands.js +64 -27
- package/.agents/scripts/sync-codex-agents.js +36 -0
- package/.agents/scripts/sync-codex-skills.js +36 -0
- package/.agents/workflows/helpers/mandrel-sync-config.md +16 -9
- package/.agents/workflows/mandrel-update.md +2 -1
- package/docs/CHANGELOG.md +15 -0
- package/lib/cli/guarded-sync.js +3 -2
- package/lib/cli/registry.js +248 -0
- package/lib/cli/sync-agents.js +5 -2
- package/lib/cli/sync-commands.js +5 -2
- package/lib/cli/sync.js +45 -14
- package/lib/cli/uninstall.js +8 -1
- package/lib/migrations/index.js +2 -0
- package/lib/migrations/steps/2.84.0-hoist-system-prompt-block.js +64 -0
- package/package.json +3 -2
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Read-only `.agentrc.json` reconciliation: validate
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Read-only `.agentrc.json` reconciliation: validate the effective config —
|
|
3
|
+
* `.agentrc.local.json` deep-merged over `.agentrc.json`, as the runtime
|
|
4
|
+
* resolver does — against the schema (never silently strip), never auto-fill
|
|
5
|
+
* defaults (the runtime layers them at read time), and flag committed leaves
|
|
6
|
+
* equal to their default as `[REDUNDANT]`.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
import fs from 'node:fs';
|
|
8
10
|
import path from 'node:path';
|
|
9
11
|
import { AGENTRC_SCHEMA, getAgentrcValidator } from '../config-schema.js';
|
|
10
12
|
import { deepEqual } from '../json-utils.js';
|
|
13
|
+
import { applyLocalOverlay, formatAgentrcErrors } from './agentrc-overlay.js';
|
|
11
14
|
import {
|
|
12
15
|
getAgentrcDefaults,
|
|
13
16
|
IDENTITY_PLACEHOLDER_PATHS,
|
|
@@ -29,6 +32,7 @@ import {
|
|
|
29
32
|
* @property {SyncChange[]} changes
|
|
30
33
|
* @property {string[]} errors
|
|
31
34
|
* @property {string} configPath
|
|
35
|
+
* @property {string|null} [localPath] the merged `.agentrc.local.json`, if any
|
|
32
36
|
* @property {boolean} wrote whether `.agentrc.json` was rewritten
|
|
33
37
|
*/
|
|
34
38
|
|
|
@@ -69,20 +73,23 @@ export function syncAgentrc(opts) {
|
|
|
69
73
|
};
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
let overlay;
|
|
77
|
+
try {
|
|
78
|
+
overlay = applyLocalOverlay({ fsImpl, projectRoot, committed: raw });
|
|
79
|
+
} catch (err) {
|
|
80
|
+
return invalidResult(configPath, err.localPath, [err.message]);
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
const validate = getAgentrcValidator();
|
|
73
|
-
if (!validate(
|
|
74
|
-
|
|
75
|
-
(e) => `${e.instancePath || '(root)'} ${e.message}`,
|
|
76
|
-
);
|
|
77
|
-
return {
|
|
78
|
-
status: 'invalid',
|
|
79
|
-
changes: [],
|
|
80
|
-
errors,
|
|
84
|
+
if (!validate(overlay.effective)) {
|
|
85
|
+
return invalidResult(
|
|
81
86
|
configPath,
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
overlay.localPath,
|
|
88
|
+
formatAgentrcErrors(validate.errors),
|
|
89
|
+
);
|
|
84
90
|
}
|
|
85
91
|
|
|
92
|
+
// Advisories target the committed file only: the overlay is per-machine.
|
|
86
93
|
const changes = collectRedundantAdvisories(raw, defaults);
|
|
87
94
|
|
|
88
95
|
return {
|
|
@@ -90,6 +97,18 @@ export function syncAgentrc(opts) {
|
|
|
90
97
|
changes,
|
|
91
98
|
errors: [],
|
|
92
99
|
configPath,
|
|
100
|
+
localPath: overlay.localPath,
|
|
101
|
+
wrote: false,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function invalidResult(configPath, localPath, errors) {
|
|
106
|
+
return {
|
|
107
|
+
status: 'invalid',
|
|
108
|
+
changes: [],
|
|
109
|
+
errors,
|
|
110
|
+
configPath,
|
|
111
|
+
localPath,
|
|
93
112
|
wrote: false,
|
|
94
113
|
};
|
|
95
114
|
}
|
|
@@ -168,16 +187,13 @@ export function formatSyncReport(result) {
|
|
|
168
187
|
return lines.join('\n');
|
|
169
188
|
}
|
|
170
189
|
if (result.status === 'invalid') {
|
|
171
|
-
lines.push(
|
|
190
|
+
lines.push(`[sync-agentrc] ❌ Validation failed${overlayNote(result)}:`);
|
|
172
191
|
for (const err of result.errors) lines.push(` - ${err}`);
|
|
173
192
|
return lines.join('\n');
|
|
174
193
|
}
|
|
175
194
|
const redundant = result.changes.filter((c) => c.op === 'REDUNDANT');
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return lines.join('\n');
|
|
179
|
-
}
|
|
180
|
-
lines.push('[sync-agentrc] ✅ No changes required.');
|
|
195
|
+
lines.push(`[sync-agentrc] ✅ No changes required${overlayNote(result)}.`);
|
|
196
|
+
if (redundant.length === 0) return lines.join('\n');
|
|
181
197
|
lines.push(
|
|
182
198
|
`[sync-agentrc] Advisories: ${redundant.length} project key(s) match framework defaults — informational only.`,
|
|
183
199
|
);
|
|
@@ -190,6 +206,10 @@ export function formatSyncReport(result) {
|
|
|
190
206
|
return lines.join('\n');
|
|
191
207
|
}
|
|
192
208
|
|
|
209
|
+
function overlayNote(result) {
|
|
210
|
+
return result.localPath ? ` (with overlay ${result.localPath})` : '';
|
|
211
|
+
}
|
|
212
|
+
|
|
193
213
|
function previewValue(value) {
|
|
194
214
|
let s;
|
|
195
215
|
try {
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import {
|
|
10
|
+
deepMergeObjects,
|
|
11
|
+
formatAgentrcErrors,
|
|
12
|
+
} from './config/agentrc-overlay.js';
|
|
9
13
|
import { getCiDelivery } from './config/ci.js';
|
|
10
14
|
import { getCommands } from './config/commands.js';
|
|
11
15
|
import { getGitHub } from './config/github.js';
|
|
@@ -90,45 +94,6 @@ function applyDeliveryDefaults(rawDelivery) {
|
|
|
90
94
|
return delivery;
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
/**
|
|
94
|
-
* Deep-merge plain objects for the `.agentrc.local.json` overlay. Arrays and
|
|
95
|
-
* scalars from `override` replace the base value at that key.
|
|
96
|
-
*
|
|
97
|
-
* @param {unknown} base
|
|
98
|
-
* @param {unknown} override
|
|
99
|
-
* @returns {unknown}
|
|
100
|
-
*/
|
|
101
|
-
function deepMergeObjects(base, override) {
|
|
102
|
-
if (
|
|
103
|
-
override === null ||
|
|
104
|
-
typeof override !== 'object' ||
|
|
105
|
-
Array.isArray(override)
|
|
106
|
-
) {
|
|
107
|
-
return override;
|
|
108
|
-
}
|
|
109
|
-
if (base === null || typeof base !== 'object' || Array.isArray(base)) {
|
|
110
|
-
return { ...override };
|
|
111
|
-
}
|
|
112
|
-
const out = { ...base };
|
|
113
|
-
for (const key of Object.keys(override)) {
|
|
114
|
-
const baseVal = base[key];
|
|
115
|
-
const overrideVal = override[key];
|
|
116
|
-
if (
|
|
117
|
-
overrideVal !== null &&
|
|
118
|
-
typeof overrideVal === 'object' &&
|
|
119
|
-
!Array.isArray(overrideVal) &&
|
|
120
|
-
baseVal !== null &&
|
|
121
|
-
typeof baseVal === 'object' &&
|
|
122
|
-
!Array.isArray(baseVal)
|
|
123
|
-
) {
|
|
124
|
-
out[key] = deepMergeObjects(baseVal, overrideVal);
|
|
125
|
-
} else {
|
|
126
|
-
out[key] = overrideVal;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return out;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
97
|
/** @param {import('node:fs')} fsImpl */
|
|
133
98
|
function readJsonConfigFile(fsImpl, filePath, label) {
|
|
134
99
|
try {
|
|
@@ -231,9 +196,7 @@ export function resolveConfig(opts) {
|
|
|
231
196
|
if (validate) {
|
|
232
197
|
const validateAgentrc = getAgentrcValidator();
|
|
233
198
|
if (!validateAgentrc(raw)) {
|
|
234
|
-
const details = (validateAgentrc.errors
|
|
235
|
-
.map((e) => `${e.instancePath || '(root)'} ${e.message}`)
|
|
236
|
-
.join(', ');
|
|
199
|
+
const details = formatAgentrcErrors(validateAgentrc.errors).join(', ');
|
|
237
200
|
throw new Error(`[config] Invalid .agentrc.json: ${details}`);
|
|
238
201
|
}
|
|
239
202
|
}
|
|
@@ -71,7 +71,7 @@ export const CODE_REVIEW_SCHEMA = {
|
|
|
71
71
|
description:
|
|
72
72
|
'Review-provider chain and on-branch remediation threshold for the /mandrel-deliver code-review ceremony.',
|
|
73
73
|
properties: {
|
|
74
|
-
// An adapter whose probe fails (e.g. codex without
|
|
74
|
+
// An adapter whose probe fails (e.g. codex without the Codex CLI)
|
|
75
75
|
// hard-fails at construction — no silent fallback to native.
|
|
76
76
|
providers: {
|
|
77
77
|
type: 'array',
|
|
@@ -81,6 +81,8 @@ const FRAMEWORK_SCRIPT_BASENAMES = Object.freeze([
|
|
|
81
81
|
'sync-agentrc.js',
|
|
82
82
|
'sync-claude-agents.js',
|
|
83
83
|
'sync-claude-commands.js',
|
|
84
|
+
'sync-codex-agents.js',
|
|
85
|
+
'sync-codex-skills.js',
|
|
84
86
|
'test-wrapper.js',
|
|
85
87
|
'update-coverage-baseline.js',
|
|
86
88
|
'update-crap-baseline.js',
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* review-providers/codex-cli.js — the Codex CLI mechanics behind the `codex`
|
|
3
|
+
* provider: the `codex --version` probe and one `codex exec` review run
|
|
4
|
+
* (read-only sandbox, ephemeral, schema-constrained output).
|
|
5
|
+
*
|
|
6
|
+
* `codex exec review` is deliberately not used: its `--base` conflicts with a
|
|
7
|
+
* prompt (no depth directive) and it ignores `--output-schema`.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {import('./types.js').Severity} Severity
|
|
10
|
+
* @typedef {import('./types.js').ReviewDepth} ReviewDepth
|
|
11
|
+
* @typedef {{ status: number, stdout: string, stderr: string }} InvokeResult
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { spawnCaptureAsync, spawnChild } from '../../child-exec.js';
|
|
17
|
+
import { resolvedTempRoot } from '../../config/temp-paths.js';
|
|
18
|
+
import { resolveConfig } from '../../config-resolver.js';
|
|
19
|
+
import { PROJECT_ROOT } from '../../project-root.js';
|
|
20
|
+
import { PROVIDER_SEVERITY_MAP } from './provider-severity.js';
|
|
21
|
+
import { renderDepthDirective } from './review-depth.js';
|
|
22
|
+
|
|
23
|
+
const PROBE_TIMEOUT_MS = 5000;
|
|
24
|
+
const INVOKE_TIMEOUT_MS = 15 * 60 * 1000;
|
|
25
|
+
const IS_WINDOWS = process.platform === 'win32';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Codex severity tokens (case-insensitive) → canonical `Severity`; an
|
|
29
|
+
* unnamed token falls through to `'suggestion'`. The keys are also the
|
|
30
|
+
* schema's severity enum.
|
|
31
|
+
*
|
|
32
|
+
* @type {Readonly<Record<string, Severity>>}
|
|
33
|
+
*/
|
|
34
|
+
export const CODEX_SEVERITY_MAP = PROVIDER_SEVERITY_MAP;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Codex structured output is strict: every property required, no extras,
|
|
38
|
+
* nullable location.
|
|
39
|
+
*/
|
|
40
|
+
const FINDINGS_SCHEMA = Object.freeze({
|
|
41
|
+
type: 'object',
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
required: ['findings'],
|
|
44
|
+
properties: {
|
|
45
|
+
findings: {
|
|
46
|
+
type: 'array',
|
|
47
|
+
items: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
required: ['severity', 'title', 'body', 'file', 'line', 'category'],
|
|
51
|
+
properties: {
|
|
52
|
+
severity: { type: 'string', enum: Object.keys(CODEX_SEVERITY_MAP) },
|
|
53
|
+
title: { type: 'string' },
|
|
54
|
+
body: { type: 'string' },
|
|
55
|
+
file: { type: ['string', 'null'] },
|
|
56
|
+
line: { type: ['integer', 'null'] },
|
|
57
|
+
category: { type: 'string' },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Synchronous so a missing CLI surfaces at construction, not mid-review.
|
|
66
|
+
*
|
|
67
|
+
* @param {{ run?: Function }} [opts] - `(file, args, options)` spawn seam.
|
|
68
|
+
* @returns {boolean} true when `codex --version` exits 0.
|
|
69
|
+
*/
|
|
70
|
+
export function defaultProbeCodexCommand(opts = {}) {
|
|
71
|
+
try {
|
|
72
|
+
const result = spawnChild('codex', ['--version'], {
|
|
73
|
+
shell: IS_WINDOWS,
|
|
74
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
75
|
+
...(opts.run ? { run: opts.run } : {}),
|
|
76
|
+
});
|
|
77
|
+
return (result?.status ?? 1) === 0;
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {{ baseRef: string, headRef: string, depth?: ReviewDepth }} args
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
function buildReviewPrompt({ baseRef, headRef, depth }) {
|
|
88
|
+
return (
|
|
89
|
+
`Review the code changes in the git diff \`${baseRef}...${headRef}\` ` +
|
|
90
|
+
`of this repository (run \`git diff ${baseRef}...${headRef}\` to read ` +
|
|
91
|
+
`it). ${renderDepthDirective(depth)}\n\n` +
|
|
92
|
+
'Report correctness, security, reliability and maintainability problems ' +
|
|
93
|
+
'the change introduces. For each one give the file and line in the new ' +
|
|
94
|
+
'version when attributable (otherwise null), a short title, a markdown ' +
|
|
95
|
+
'body explaining why it is wrong and how to fix it, and a category. ' +
|
|
96
|
+
'Do not modify any file. Report findings ONLY through the required ' +
|
|
97
|
+
'output schema; an empty `findings` array means no problems.\n'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} file
|
|
103
|
+
* @returns {string|null}
|
|
104
|
+
*/
|
|
105
|
+
function readIfPresent(file) {
|
|
106
|
+
try {
|
|
107
|
+
return fs.readFileSync(file, 'utf8');
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Run one `codex exec` review in a per-run directory under the project
|
|
115
|
+
* tempRoot (removed afterwards). The prompt rides stdin; the last-message
|
|
116
|
+
* file becomes `stdout`.
|
|
117
|
+
*
|
|
118
|
+
* @param {{ baseRef: string, headRef: string, depth?: ReviewDepth }} args
|
|
119
|
+
* @param {{ run?: Function, tempRoot?: string, cwd?: string }} [deps]
|
|
120
|
+
* @returns {Promise<InvokeResult>}
|
|
121
|
+
*/
|
|
122
|
+
export async function invokeCodexExec(args, deps = {}) {
|
|
123
|
+
const tempRoot = deps.tempRoot ?? resolvedTempRoot(resolveConfig());
|
|
124
|
+
fs.mkdirSync(tempRoot, { recursive: true });
|
|
125
|
+
const runDir = fs.mkdtempSync(path.join(tempRoot, 'codex-review-'));
|
|
126
|
+
try {
|
|
127
|
+
const schemaPath = path.join(runDir, 'findings.schema.json');
|
|
128
|
+
const lastMessagePath = path.join(runDir, 'last-message.json');
|
|
129
|
+
fs.writeFileSync(schemaPath, JSON.stringify(FINDINGS_SCHEMA));
|
|
130
|
+
const execArgs = ['exec', '--sandbox', 'read-only', '--ephemeral'];
|
|
131
|
+
execArgs.push('--output-schema', schemaPath, '-o', lastMessagePath, '-');
|
|
132
|
+
const result = await spawnCaptureAsync('codex', execArgs, {
|
|
133
|
+
cwd: deps.cwd ?? PROJECT_ROOT,
|
|
134
|
+
input: buildReviewPrompt(args),
|
|
135
|
+
shell: IS_WINDOWS,
|
|
136
|
+
timeout: INVOKE_TIMEOUT_MS,
|
|
137
|
+
...(deps.run ? { run: deps.run } : {}),
|
|
138
|
+
});
|
|
139
|
+
if (result.status !== 0) return result;
|
|
140
|
+
const lastMessage = readIfPresent(lastMessagePath);
|
|
141
|
+
if (lastMessage === null) {
|
|
142
|
+
return {
|
|
143
|
+
status: 1,
|
|
144
|
+
stdout: '',
|
|
145
|
+
stderr: `codex exec wrote no last-message file. ${result.stderr}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return { status: 0, stdout: lastMessage, stderr: result.stderr };
|
|
149
|
+
} finally {
|
|
150
|
+
fs.rmSync(runDir, { recursive: true, force: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* review-providers/codex.js — ReviewProvider over
|
|
3
|
-
*
|
|
2
|
+
* review-providers/codex.js — ReviewProvider over the Codex CLI (`codex
|
|
3
|
+
* exec`, see `codex-cli.js`), so a Codex-only host needs no `claude` binary.
|
|
4
|
+
* A missing CLI hard-fails at construction; never a silent fallback to
|
|
5
|
+
* native.
|
|
4
6
|
*
|
|
5
7
|
* @typedef {import('./types.js').Finding} Finding
|
|
6
8
|
* @typedef {import('./types.js').ReviewInput} ReviewInput
|
|
@@ -8,81 +10,35 @@
|
|
|
8
10
|
* @typedef {import('./types.js').Severity} Severity
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
import {
|
|
14
|
+
CODEX_SEVERITY_MAP,
|
|
15
|
+
defaultProbeCodexCommand,
|
|
16
|
+
invokeCodexExec,
|
|
17
|
+
} from './codex-cli.js';
|
|
15
18
|
import { parseProviderFindings } from './parse-findings.js';
|
|
16
|
-
|
|
19
|
+
|
|
20
|
+
export { CODEX_SEVERITY_MAP, defaultProbeCodexCommand };
|
|
17
21
|
|
|
18
22
|
export const CODEX_REMEDIATIONS = Object.freeze({
|
|
19
23
|
install:
|
|
20
|
-
'Install the Codex
|
|
21
|
-
'
|
|
24
|
+
'Install the Codex CLI (`npm install -g @openai/codex`) and sign in ' +
|
|
25
|
+
'with `codex login` so `codex --version` succeeds on PATH.',
|
|
22
26
|
fallback:
|
|
23
27
|
'Or set `codeReview.providers` to [{ name: "native" }] in .agentrc.json to use the ' +
|
|
24
28
|
'in-process maintainability/lint provider instead.',
|
|
25
29
|
});
|
|
26
30
|
|
|
27
|
-
/** A present `codex-plugin-cc` directory means the slash command is registered. */
|
|
28
|
-
const DEFAULT_PLUGIN_MARKERS = Object.freeze([
|
|
29
|
-
path.join(os.homedir(), '.claude', 'plugins', 'codex-plugin-cc'),
|
|
30
|
-
path.join(os.homedir(), '.claude', 'plugins', 'openai', 'codex-plugin-cc'),
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Synchronous so a missing plugin surfaces at construction, not mid-review.
|
|
35
|
-
*
|
|
36
|
-
* @param {{ markers?: readonly string[], existsFn?: (p: string) => boolean }} [opts]
|
|
37
|
-
* @returns {boolean}
|
|
38
|
-
*/
|
|
39
|
-
export function defaultProbeCodexCommand(opts = {}) {
|
|
40
|
-
const markers = opts.markers ?? DEFAULT_PLUGIN_MARKERS;
|
|
41
|
-
const existsFn = opts.existsFn ?? fs.existsSync;
|
|
42
|
-
for (const marker of markers) {
|
|
43
|
-
try {
|
|
44
|
-
if (existsFn(marker)) return true;
|
|
45
|
-
} catch (_err) {
|
|
46
|
-
// An I/O error reads as absent.
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
31
|
/**
|
|
53
32
|
* @returns {Error}
|
|
54
33
|
*/
|
|
55
34
|
export function buildCodexUnavailableError() {
|
|
56
35
|
return new Error(
|
|
57
36
|
'[ReviewProviderFactory] codeReview.providers includes "codex" but the ' +
|
|
58
|
-
'
|
|
37
|
+
'Codex CLI is not available on this host (`codex --version` failed). ' +
|
|
59
38
|
`${CODEX_REMEDIATIONS.install} ${CODEX_REMEDIATIONS.fallback}`,
|
|
60
39
|
);
|
|
61
40
|
}
|
|
62
41
|
|
|
63
|
-
/**
|
|
64
|
-
* Codex severity tokens (case-insensitive) → canonical `Severity`; an
|
|
65
|
-
* unnamed token falls through to `'suggestion'`.
|
|
66
|
-
*
|
|
67
|
-
* @type {Readonly<Record<string, Severity>>}
|
|
68
|
-
*/
|
|
69
|
-
export const CODEX_SEVERITY_MAP = Object.freeze({
|
|
70
|
-
blocker: 'critical',
|
|
71
|
-
critical: 'critical',
|
|
72
|
-
fatal: 'critical',
|
|
73
|
-
major: 'high',
|
|
74
|
-
high: 'high',
|
|
75
|
-
error: 'high',
|
|
76
|
-
minor: 'medium',
|
|
77
|
-
medium: 'medium',
|
|
78
|
-
warning: 'medium',
|
|
79
|
-
info: 'suggestion',
|
|
80
|
-
nit: 'suggestion',
|
|
81
|
-
style: 'suggestion',
|
|
82
|
-
suggestion: 'suggestion',
|
|
83
|
-
note: 'suggestion',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
42
|
/**
|
|
87
43
|
* @param {unknown} raw
|
|
88
44
|
* @returns {Severity}
|
|
@@ -94,57 +50,23 @@ export function mapCodexSeverity(raw) {
|
|
|
94
50
|
}
|
|
95
51
|
|
|
96
52
|
/**
|
|
97
|
-
*
|
|
53
|
+
* The shared parser omits the schema's `null` file/line.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} rawOutput - The `codex exec` last-message contents.
|
|
98
56
|
* @returns {Finding[]}
|
|
99
|
-
* @throws {Error} when
|
|
57
|
+
* @throws {Error} when the output is not parseable JSON.
|
|
100
58
|
*/
|
|
101
|
-
export function parseCodexFindings(
|
|
102
|
-
return parseProviderFindings(
|
|
103
|
-
errorPrefix: '[codex-review] Failed to parse
|
|
59
|
+
export function parseCodexFindings(rawOutput) {
|
|
60
|
+
return parseProviderFindings(rawOutput, {
|
|
61
|
+
errorPrefix: '[codex-review] Failed to parse codex exec output as JSON',
|
|
104
62
|
mapSeverity: mapCodexSeverity,
|
|
105
63
|
});
|
|
106
64
|
}
|
|
107
65
|
|
|
108
|
-
/**
|
|
109
|
-
* The depth directive rides as trailing prompt prose after the slash command.
|
|
110
|
-
*
|
|
111
|
-
* @param {{ baseRef: string, headRef: string, depth?: import('./types.js').ReviewDepth }} args
|
|
112
|
-
* @returns {string}
|
|
113
|
-
*/
|
|
114
|
-
function buildCodexReviewPrompt({ baseRef, headRef, depth }) {
|
|
115
|
-
return (
|
|
116
|
-
`/codex:review --base ${baseRef} --head ${headRef} --wait ` +
|
|
117
|
-
`${renderDepthDirective(depth)}`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Run `/codex:review` through the host's `claude` CLI; `--wait` makes the
|
|
123
|
-
* plugin print JSON to stdout.
|
|
124
|
-
*
|
|
125
|
-
* @param {{ baseRef: string, headRef: string, depth?: import('./types.js').ReviewDepth }} args
|
|
126
|
-
* @returns {{ status: number, stdout: string, stderr: string }}
|
|
127
|
-
*/
|
|
128
|
-
function defaultInvokeCodexReview({ baseRef, headRef, depth }) {
|
|
129
|
-
const cliArgs = [
|
|
130
|
-
'--print',
|
|
131
|
-
buildCodexReviewPrompt({ baseRef, headRef, depth }),
|
|
132
|
-
];
|
|
133
|
-
const result = spawnSync('claude', cliArgs, {
|
|
134
|
-
encoding: 'utf-8',
|
|
135
|
-
shell: process.platform === 'win32',
|
|
136
|
-
});
|
|
137
|
-
return {
|
|
138
|
-
status: result.status ?? 1,
|
|
139
|
-
stdout: result.stdout ?? '',
|
|
140
|
-
stderr: result.stderr ?? '',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
66
|
/**
|
|
145
67
|
* @param {{
|
|
146
68
|
* probeFn?: () => boolean,
|
|
147
|
-
* invokeFn?: (args: { baseRef: string, headRef: string, scope: string, ticketId: number, depth?: import('./types.js').ReviewDepth }) => { status: number, stdout: string, stderr: string },
|
|
69
|
+
* invokeFn?: (args: { baseRef: string, headRef: string, scope: string, ticketId: number, depth?: import('./types.js').ReviewDepth }) => { status: number, stdout: string, stderr: string } | Promise<{ status: number, stdout: string, stderr: string }>,
|
|
148
70
|
* logger?: { info?: Function, warn?: Function, error?: Function },
|
|
149
71
|
* }} [deps]
|
|
150
72
|
* @returns {ReviewProvider}
|
|
@@ -155,7 +77,7 @@ export function createCodexProvider(deps = {}) {
|
|
|
155
77
|
throw buildCodexUnavailableError();
|
|
156
78
|
}
|
|
157
79
|
|
|
158
|
-
const invokeFn = deps.invokeFn ??
|
|
80
|
+
const invokeFn = deps.invokeFn ?? invokeCodexExec;
|
|
159
81
|
const logger = deps.logger;
|
|
160
82
|
|
|
161
83
|
return {
|
|
@@ -177,14 +99,20 @@ export function createCodexProvider(deps = {}) {
|
|
|
177
99
|
}
|
|
178
100
|
|
|
179
101
|
logger?.info?.(
|
|
180
|
-
`[codex-review] Invoking
|
|
102
|
+
`[codex-review] Invoking codex exec on ${baseRef}...${headRef} ` +
|
|
181
103
|
`for ${scope} #${ticketId}...`,
|
|
182
104
|
);
|
|
183
105
|
|
|
184
|
-
const result = invokeFn({
|
|
106
|
+
const result = await invokeFn({
|
|
107
|
+
baseRef,
|
|
108
|
+
headRef,
|
|
109
|
+
scope,
|
|
110
|
+
ticketId,
|
|
111
|
+
depth,
|
|
112
|
+
});
|
|
185
113
|
if (result.status !== 0) {
|
|
186
114
|
throw new Error(
|
|
187
|
-
`[codex-review]
|
|
115
|
+
`[codex-review] codex exec exited with status ${result.status}: ${
|
|
188
116
|
result.stderr || result.stdout || '<no output>'
|
|
189
117
|
}`,
|
|
190
118
|
);
|
|
@@ -192,7 +120,7 @@ export function createCodexProvider(deps = {}) {
|
|
|
192
120
|
|
|
193
121
|
const findings = parseCodexFindings(result.stdout);
|
|
194
122
|
logger?.info?.(
|
|
195
|
-
`[codex-review] Parsed ${findings.length} finding(s) from
|
|
123
|
+
`[codex-review] Parsed ${findings.length} finding(s) from codex exec.`,
|
|
196
124
|
);
|
|
197
125
|
return findings;
|
|
198
126
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* review-providers/provider-severity.js — the severity vocabulary shared by
|
|
3
|
+
* the LLM-backed providers.
|
|
4
|
+
*
|
|
5
|
+
* @typedef {import('./types.js').Severity} Severity
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Severity vocabulary shared by the LLM-backed providers (case-insensitive
|
|
10
|
+
* token → canonical `Severity`); an unnamed token falls through to
|
|
11
|
+
* `'suggestion'` in each provider's mapper.
|
|
12
|
+
*
|
|
13
|
+
* @type {Readonly<Record<string, Severity>>}
|
|
14
|
+
*/
|
|
15
|
+
export const PROVIDER_SEVERITY_MAP = Object.freeze({
|
|
16
|
+
blocker: 'critical',
|
|
17
|
+
critical: 'critical',
|
|
18
|
+
fatal: 'critical',
|
|
19
|
+
major: 'high',
|
|
20
|
+
high: 'high',
|
|
21
|
+
error: 'high',
|
|
22
|
+
minor: 'medium',
|
|
23
|
+
medium: 'medium',
|
|
24
|
+
warning: 'medium',
|
|
25
|
+
info: 'suggestion',
|
|
26
|
+
nit: 'suggestion',
|
|
27
|
+
style: 'suggestion',
|
|
28
|
+
suggestion: 'suggestion',
|
|
29
|
+
note: 'suggestion',
|
|
30
|
+
});
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { spawnSync } from 'node:child_process';
|
|
13
13
|
import { parseProviderFindings } from './parse-findings.js';
|
|
14
|
+
import { PROVIDER_SEVERITY_MAP } from './provider-severity.js';
|
|
14
15
|
import { renderDepthDirective } from './review-depth.js';
|
|
15
16
|
|
|
16
17
|
export const SECURITY_REVIEW_REMEDIATIONS = Object.freeze({
|
|
@@ -55,26 +56,11 @@ export function buildSecurityReviewUnavailableError() {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
+
* The shared provider vocabulary, kept under this provider's export name.
|
|
59
60
|
*
|
|
60
61
|
* @type {Readonly<Record<string, Severity>>}
|
|
61
62
|
*/
|
|
62
|
-
export const SECURITY_REVIEW_SEVERITY_MAP =
|
|
63
|
-
blocker: 'critical',
|
|
64
|
-
critical: 'critical',
|
|
65
|
-
fatal: 'critical',
|
|
66
|
-
major: 'high',
|
|
67
|
-
high: 'high',
|
|
68
|
-
error: 'high',
|
|
69
|
-
minor: 'medium',
|
|
70
|
-
medium: 'medium',
|
|
71
|
-
warning: 'medium',
|
|
72
|
-
info: 'suggestion',
|
|
73
|
-
nit: 'suggestion',
|
|
74
|
-
style: 'suggestion',
|
|
75
|
-
suggestion: 'suggestion',
|
|
76
|
-
note: 'suggestion',
|
|
77
|
-
});
|
|
63
|
+
export const SECURITY_REVIEW_SEVERITY_MAP = PROVIDER_SEVERITY_MAP;
|
|
78
64
|
|
|
79
65
|
/**
|
|
80
66
|
* @param {unknown} raw
|
|
@@ -24,12 +24,17 @@ const UNLANDED_CLOSE_REASONS = new Set(['not_planned', 'duplicate']);
|
|
|
24
24
|
* @param {{ provider: object, config: object, gh?: object,
|
|
25
25
|
* notify?: Function, sleep?: Function }} deps
|
|
26
26
|
* @param {(tag: string, msg: string) => void} progress
|
|
27
|
-
* @returns {Promise<
|
|
27
|
+
* @returns {Promise<string>} `skipped` | `no-merged-pr` | `error` | the
|
|
28
|
+
* `confirmStoryMerged` action.
|
|
28
29
|
*/
|
|
29
30
|
export async function reconcileDoneLabel(ctx, deps, progress) {
|
|
30
31
|
const { storyId, story, storyBranch } = ctx;
|
|
31
|
-
if (
|
|
32
|
-
|
|
32
|
+
if (
|
|
33
|
+
UNLANDED_CLOSE_REASONS.has(story.stateReason) ||
|
|
34
|
+
story.labels?.includes(STATE_LABELS.DONE)
|
|
35
|
+
) {
|
|
36
|
+
return 'skipped';
|
|
37
|
+
}
|
|
33
38
|
try {
|
|
34
39
|
const rows = await (deps.gh ?? defaultGh).pr.list(
|
|
35
40
|
['--head', storyBranch, '--state', 'all'],
|
|
@@ -41,9 +46,9 @@ export async function reconcileDoneLabel(ctx, deps, progress) {
|
|
|
41
46
|
'NOOP',
|
|
42
47
|
`No merged PR on ${storyBranch} — leaving Story #${storyId}'s labels as they are.`,
|
|
43
48
|
);
|
|
44
|
-
return;
|
|
49
|
+
return 'no-merged-pr';
|
|
45
50
|
}
|
|
46
|
-
await confirmStoryMerged({
|
|
51
|
+
const confirmed = await confirmStoryMerged({
|
|
47
52
|
provider: deps.provider,
|
|
48
53
|
storyId,
|
|
49
54
|
prNumber: parsePrNumber(head.url),
|
|
@@ -55,9 +60,11 @@ export async function reconcileDoneLabel(ctx, deps, progress) {
|
|
|
55
60
|
prState: { state: 'MERGED', mergedAt: null },
|
|
56
61
|
sleepFn: deps.sleep,
|
|
57
62
|
});
|
|
63
|
+
return confirmed.action;
|
|
58
64
|
} catch (err) {
|
|
59
65
|
Logger.warn(
|
|
60
66
|
`[single-story-close] ⚠️ Could not reconcile Story #${storyId} to agent::done: ${err?.message ?? err}`,
|
|
61
67
|
);
|
|
68
|
+
return 'error';
|
|
62
69
|
}
|
|
63
70
|
}
|