mandrel 2.82.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 +40 -3
- 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/schemas/agentrc.schema.json +1 -1
- package/.agents/scripts/boot-sweep.js +42 -13
- package/.agents/scripts/coverage-capture.js +55 -24
- package/.agents/scripts/evidence-gate.js +7 -1
- package/.agents/scripts/generate-workflows-doc.js +14 -0
- package/.agents/scripts/lib/baselines/duplication-scanner.js +26 -2
- 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/close-lock-events.js +109 -0
- package/.agents/scripts/lib/close-validation/commands.js +12 -0
- package/.agents/scripts/lib/close-validation/gates.js +6 -0
- package/.agents/scripts/lib/close-validation/process.js +5 -2
- package/.agents/scripts/lib/close-validation/runner.js +14 -4
- 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/config-settings-schema.js +1 -1
- package/.agents/scripts/lib/full-suite-lock.js +20 -0
- package/.agents/scripts/lib/full-suite-queue.js +24 -56
- package/.agents/scripts/lib/generated/agentrc-validator.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/close-validation.js +73 -63
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +70 -0
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +3 -0
- package/.agents/scripts/lib/single-story-sweep/reconcile-closing.js +89 -0
- package/.agents/scripts/lib/supervised-suite.js +8 -28
- 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/README.md +167 -216
- package/docs/CHANGELOG.md +25 -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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* phases/reconcile-done.js — a Story closed as completed can still carry a
|
|
3
|
+
* stale lifecycle label: a close that blocked before auto-merge landed its
|
|
4
|
+
* PR leaves `agent::blocked` on the closed issue, and the re-run takes the
|
|
5
|
+
* already-closed early return. With merge evidence on the Story branch, this
|
|
6
|
+
* finishes the flip through the shared `agent::done` confirm. Best-effort —
|
|
7
|
+
* the land already happened, so nothing here may change the `landed`
|
|
8
|
+
* terminal; every failure is logged and swallowed.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { gh as defaultGh } from '../../../gh-exec.js';
|
|
12
|
+
import { Logger } from '../../../Logger.js';
|
|
13
|
+
import { confirmStoryMerged } from '../../../single-story/confirm-merge.js';
|
|
14
|
+
import { STATE_LABELS } from '../../ticketing.js';
|
|
15
|
+
import { parsePrNumber } from './code-review.js';
|
|
16
|
+
import { pickHeadPullRequest } from './pull-request.js';
|
|
17
|
+
|
|
18
|
+
/** Close reasons meaning nothing merged — no label is owed. */
|
|
19
|
+
const UNLANDED_CLOSE_REASONS = new Set(['not_planned', 'duplicate']);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{ storyId: number, storyBranch: string, options: { cwd: string },
|
|
23
|
+
* story: { labels?: string[], stateReason?: string|null } }} ctx
|
|
24
|
+
* @param {{ provider: object, config: object, gh?: object,
|
|
25
|
+
* notify?: Function, sleep?: Function }} deps
|
|
26
|
+
* @param {(tag: string, msg: string) => void} progress
|
|
27
|
+
* @returns {Promise<string>} `skipped` | `no-merged-pr` | `error` | the
|
|
28
|
+
* `confirmStoryMerged` action.
|
|
29
|
+
*/
|
|
30
|
+
export async function reconcileDoneLabel(ctx, deps, progress) {
|
|
31
|
+
const { storyId, story, storyBranch } = ctx;
|
|
32
|
+
if (
|
|
33
|
+
UNLANDED_CLOSE_REASONS.has(story.stateReason) ||
|
|
34
|
+
story.labels?.includes(STATE_LABELS.DONE)
|
|
35
|
+
) {
|
|
36
|
+
return 'skipped';
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const rows = await (deps.gh ?? defaultGh).pr.list(
|
|
40
|
+
['--head', storyBranch, '--state', 'all'],
|
|
41
|
+
['url', 'state', 'mergedAt'],
|
|
42
|
+
);
|
|
43
|
+
const head = pickHeadPullRequest(rows);
|
|
44
|
+
if (head?.state !== 'MERGED') {
|
|
45
|
+
progress(
|
|
46
|
+
'NOOP',
|
|
47
|
+
`No merged PR on ${storyBranch} — leaving Story #${storyId}'s labels as they are.`,
|
|
48
|
+
);
|
|
49
|
+
return 'no-merged-pr';
|
|
50
|
+
}
|
|
51
|
+
const confirmed = await confirmStoryMerged({
|
|
52
|
+
provider: deps.provider,
|
|
53
|
+
storyId,
|
|
54
|
+
prNumber: parsePrNumber(head.url),
|
|
55
|
+
prUrl: head.url,
|
|
56
|
+
cwd: ctx.options.cwd,
|
|
57
|
+
config: deps.config,
|
|
58
|
+
progress,
|
|
59
|
+
injectedNotify: deps.notify,
|
|
60
|
+
prState: { state: 'MERGED', mergedAt: null },
|
|
61
|
+
sleepFn: deps.sleep,
|
|
62
|
+
});
|
|
63
|
+
return confirmed.action;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
Logger.warn(
|
|
66
|
+
`[single-story-close] ⚠️ Could not reconcile Story #${storyId} to agent::done: ${err?.message ?? err}`,
|
|
67
|
+
);
|
|
68
|
+
return 'error';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
pickHeadPullRequest,
|
|
48
48
|
} from './phases/pull-request.js';
|
|
49
49
|
import { pushStoryBranch } from './phases/push.js';
|
|
50
|
+
import { reconcileDoneLabel } from './phases/reconcile-done.js';
|
|
50
51
|
import { handleCriticalReviewBlock } from './phases/review-block.js';
|
|
51
52
|
import { handleOverriddenReviewBlock } from './phases/review-override.js';
|
|
52
53
|
import {
|
|
@@ -588,6 +589,7 @@ function resolveCloseDeps(options, injected) {
|
|
|
588
589
|
gitSpawn: injected.injectedGitSpawn,
|
|
589
590
|
releaseLease: injected.injectedReleaseLease ?? releaseStoryLease,
|
|
590
591
|
graphqlProbe: injected.injectedGraphqlProbe,
|
|
592
|
+
sleep: injected.injectedSleep,
|
|
591
593
|
};
|
|
592
594
|
}
|
|
593
595
|
|
|
@@ -934,6 +936,7 @@ async function loadStoryPhase(ctx, deps) {
|
|
|
934
936
|
progress('INIT', `Closing standalone Story #${ctx.storyId}...`);
|
|
935
937
|
ctx.story = await deps.provider.getTicket(ctx.storyId);
|
|
936
938
|
if (ctx.story.state !== 'closed') return null;
|
|
939
|
+
await reconcileDoneLabel(ctx, deps, progress);
|
|
937
940
|
return await alreadyClosedResult(
|
|
938
941
|
ctx.storyId,
|
|
939
942
|
ctx.story.stateReason,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only a live close flips `agent::done`; a PR that merges after it is gone
|
|
3
|
+
* closes the issue at `agent::closing`. Boot finishes the flip via
|
|
4
|
+
* `reconcileDoneLabel` (MERGED PR required). Bounded; never throws.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getStoryBranch } from '../git-utils.js';
|
|
8
|
+
import { AGENT_LABELS, TYPE_LABELS } from '../label-constants.js';
|
|
9
|
+
import { reconcileDoneLabel as defaultReconcile } from '../orchestration/single-story-close/phases/reconcile-done.js';
|
|
10
|
+
|
|
11
|
+
/** Candidates processed per sweep; a larger backlog drains across boots. */
|
|
12
|
+
export const DEFAULT_RECONCILE_LIMIT = 10;
|
|
13
|
+
|
|
14
|
+
function isStrandedStory(ticket) {
|
|
15
|
+
const labels = Array.isArray(ticket?.labels) ? ticket.labels : [];
|
|
16
|
+
return (
|
|
17
|
+
labels.includes(TYPE_LABELS.STORY) && !labels.includes(AGENT_LABELS.DONE)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function reconcileOne({ story, cwd, deps, logger, reconcileFn }) {
|
|
22
|
+
try {
|
|
23
|
+
return await reconcileFn(
|
|
24
|
+
{
|
|
25
|
+
storyId: story.id,
|
|
26
|
+
storyBranch: getStoryBranch(story.id),
|
|
27
|
+
story,
|
|
28
|
+
options: { cwd },
|
|
29
|
+
},
|
|
30
|
+
deps,
|
|
31
|
+
(_tag, msg) => logger.info?.(msg),
|
|
32
|
+
);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
logger.warn?.(
|
|
35
|
+
`could not reconcile Story #${story.id} (host continues): ${err?.message ?? err}`,
|
|
36
|
+
);
|
|
37
|
+
return 'error';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function reconcileStrandedClosing({
|
|
42
|
+
provider,
|
|
43
|
+
config,
|
|
44
|
+
cwd,
|
|
45
|
+
gh,
|
|
46
|
+
notify,
|
|
47
|
+
sleep,
|
|
48
|
+
logger = {},
|
|
49
|
+
limit = DEFAULT_RECONCILE_LIMIT,
|
|
50
|
+
reconcileFn = defaultReconcile,
|
|
51
|
+
}) {
|
|
52
|
+
const outcome = { ok: true, reconciled: [], skipped: [] };
|
|
53
|
+
if (typeof provider?.listTicketsByLabel !== 'function') return outcome;
|
|
54
|
+
let tickets;
|
|
55
|
+
try {
|
|
56
|
+
tickets = await provider.listTicketsByLabel({
|
|
57
|
+
state: 'closed',
|
|
58
|
+
labels: AGENT_LABELS.CLOSING,
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const msg = err?.message ?? String(err);
|
|
62
|
+
logger.warn?.(
|
|
63
|
+
`closed agent::closing listing failed (host continues): ${msg}`,
|
|
64
|
+
);
|
|
65
|
+
return { ...outcome, ok: false, error: msg };
|
|
66
|
+
}
|
|
67
|
+
const candidates = (Array.isArray(tickets) ? tickets : [])
|
|
68
|
+
.filter(isStrandedStory)
|
|
69
|
+
.slice(0, limit);
|
|
70
|
+
const deps = { provider, config, gh, notify, sleep };
|
|
71
|
+
for (const story of candidates) {
|
|
72
|
+
const storyId = story.id;
|
|
73
|
+
const result = await reconcileOne({
|
|
74
|
+
story,
|
|
75
|
+
cwd,
|
|
76
|
+
deps,
|
|
77
|
+
logger,
|
|
78
|
+
reconcileFn,
|
|
79
|
+
});
|
|
80
|
+
if (result === 'done') outcome.reconciled.push(storyId);
|
|
81
|
+
else outcome.skipped.push({ storyId, reason: result });
|
|
82
|
+
}
|
|
83
|
+
if (outcome.reconciled.length > 0) {
|
|
84
|
+
logger.info?.(
|
|
85
|
+
`🏷️ reconciled ${outcome.reconciled.length} closed Story(ies) stranded at agent::closing → agent::done.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return outcome;
|
|
89
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A full suite supervised as a process group. The suite may write
|
|
3
3
|
* `$MANDREL_SUITE_READY_FILE` when its tests start; the kill timer then
|
|
4
4
|
* re-arms a fresh `timeoutMs`, so a pre-test wait (bounded by `timeoutMs`
|
|
5
|
-
* too) never spends the test budget.
|
|
5
|
+
* too) never spends the test budget.
|
|
6
6
|
*/
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
8
|
import crypto from 'node:crypto';
|
|
@@ -38,23 +38,6 @@ export function formatSuiteTimings({ lockWaitMs, hostWaitMs, testRunMs }) {
|
|
|
38
38
|
return `⏲ suite timings: lockWaitMs=${Math.round(lockWaitMs)} hostWaitMs=${host} testRunMs=${Math.round(testRunMs)}`;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* @param {string} line
|
|
43
|
-
* @returns {SuiteTimings|null}
|
|
44
|
-
*/
|
|
45
|
-
export function parseSuiteTimings(line) {
|
|
46
|
-
const match =
|
|
47
|
-
/suite timings: lockWaitMs=(\d+) hostWaitMs=(\d+|n\/a) testRunMs=(\d+)/u.exec(
|
|
48
|
-
String(line ?? ''),
|
|
49
|
-
);
|
|
50
|
-
if (!match) return null;
|
|
51
|
-
return {
|
|
52
|
-
lockWaitMs: Number(match[1]),
|
|
53
|
-
hostWaitMs: match[2] === NO_HOST_WAIT ? null : Number(match[2]),
|
|
54
|
-
testRunMs: Number(match[3]),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
41
|
function fileExists(fsImpl, file) {
|
|
59
42
|
try {
|
|
60
43
|
return fsImpl.existsSync(file);
|
|
@@ -160,9 +143,9 @@ export function superviseSuite(child, opts) {
|
|
|
160
143
|
/**
|
|
161
144
|
* A bare suite gets SIGKILL on a parent signal; a gate with its own cleanup
|
|
162
145
|
* (a capture holding the lock) SIGTERM. A full-suite gate also gets the
|
|
163
|
-
* handshake and
|
|
146
|
+
* handshake and reports its timings on release.
|
|
164
147
|
*
|
|
165
|
-
* @param {{ fullSuiteLock?: boolean, timeoutMs?: number, signal?: AbortSignal, env?: Record<string, string
|
|
148
|
+
* @param {{ fullSuiteLock?: boolean, timeoutMs?: number, signal?: AbortSignal, env?: Record<string, string>, onLockEvent?: (event: object) => void }} opts
|
|
166
149
|
* @param {{ lockWaitMs?: number }} [lock]
|
|
167
150
|
*/
|
|
168
151
|
export function gateSupervision(opts, lock = {}) {
|
|
@@ -180,14 +163,11 @@ export function gateSupervision(opts, lock = {}) {
|
|
|
180
163
|
supervise: (child, output) =>
|
|
181
164
|
reportOnRelease(
|
|
182
165
|
superviseSuite(child, { ...base, readyFile: handshake.file }),
|
|
183
|
-
(timings) =>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
...timings,
|
|
189
|
-
}),
|
|
190
|
-
),
|
|
166
|
+
(timings) => {
|
|
167
|
+
const full = { lockWaitMs: lock.lockWaitMs ?? 0, ...timings };
|
|
168
|
+
output.emit(output.prefix + formatSuiteTimings(full));
|
|
169
|
+
opts.onLockEvent?.({ kind: 'suite-timings', ...full });
|
|
170
|
+
},
|
|
191
171
|
),
|
|
192
172
|
};
|
|
193
173
|
}
|
|
@@ -279,11 +279,12 @@ export async function reapClosedStoryWorktrees({
|
|
|
279
279
|
|
|
280
280
|
/**
|
|
281
281
|
* Reap merged `story-*` branches (excluding the current one), then the
|
|
282
|
-
* closed-Story worktrees
|
|
283
|
-
* work, dirty worktree, open
|
|
284
|
-
* `boot-sweep.js` via
|
|
282
|
+
* closed-Story worktrees, then stranded `agent::closing` Stories. Never
|
|
283
|
+
* blocks init. Protected candidates (unpushed work, dirty worktree, open
|
|
284
|
+
* Story) are skipped; the lockfile is shared with `boot-sweep.js` via
|
|
285
|
+
* `resolveSweepLockPath` so concurrent reaps cannot race.
|
|
285
286
|
*
|
|
286
|
-
* @returns {Promise<{ worktreeSweep: object }>}
|
|
287
|
+
* @returns {Promise<{ worktreeSweep: object, closingReconcile: object }>}
|
|
287
288
|
*/
|
|
288
289
|
export async function reapMergedStoryBranches({
|
|
289
290
|
cwd,
|
|
@@ -294,6 +295,7 @@ export async function reapMergedStoryBranches({
|
|
|
294
295
|
injectedSweep,
|
|
295
296
|
worktreeSweepFn,
|
|
296
297
|
acquireLockFn,
|
|
298
|
+
closingReconcileFn,
|
|
297
299
|
}) {
|
|
298
300
|
const sweepFn =
|
|
299
301
|
injectedSweep ??
|
|
@@ -320,7 +322,20 @@ export async function reapMergedStoryBranches({
|
|
|
320
322
|
worktreeSweepFn,
|
|
321
323
|
acquireLockFn,
|
|
322
324
|
});
|
|
323
|
-
|
|
325
|
+
const reconcile =
|
|
326
|
+
closingReconcileFn ??
|
|
327
|
+
(await import('./lib/single-story-sweep/reconcile-closing.js'))
|
|
328
|
+
.reconcileStrandedClosing;
|
|
329
|
+
const closingReconcile = await reconcile({
|
|
330
|
+
provider,
|
|
331
|
+
config,
|
|
332
|
+
cwd,
|
|
333
|
+
logger: {
|
|
334
|
+
info: (m) => progress('CLEANUP', m),
|
|
335
|
+
warn: (m) => progress('CLEANUP', `⚠️ ${m}`),
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
return { worktreeSweep, closingReconcile };
|
|
324
339
|
}
|
|
325
340
|
|
|
326
341
|
async function reapMergedBranches({
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Validate `.agentrc.json`
|
|
4
|
+
* Validate `.agentrc.json` (with any `.agentrc.local.json` overlay merged in,
|
|
5
|
+
* as the runtime resolver does) and flag leaves that restate a framework
|
|
6
|
+
* default.
|
|
5
7
|
* Never writes the file: defaults are layered at read time, so absent keys
|
|
6
8
|
* need no filling. Flags and exit codes live in `USAGE`.
|
|
7
9
|
*/
|
|
@@ -14,13 +16,13 @@ import { Logger } from './lib/Logger.js';
|
|
|
14
16
|
const USAGE = {
|
|
15
17
|
invocation: 'node .agents/scripts/sync-agentrc.js [--cwd <path>] [--quiet]',
|
|
16
18
|
summary:
|
|
17
|
-
'Validate `.agentrc.json` against the framework schema and report every
|
|
19
|
+
'Validate `.agentrc.json` — with any gitignored `.agentrc.local.json` deep-merged over it, as the runtime resolver does — against the framework schema, and report every committed leaf that merely restates a framework default. Never writes the config.',
|
|
18
20
|
flags: [
|
|
19
21
|
['--cwd <path>', 'Project root (default: process cwd).'],
|
|
20
22
|
['--quiet', 'Suppress advisory rows; print only the status line.'],
|
|
21
23
|
],
|
|
22
24
|
notes: [
|
|
23
|
-
'Exit codes:\n 0 config is valid (advisories may still appear)\n 1
|
|
25
|
+
'Exit codes:\n 0 config is valid (advisories may still appear)\n 1 `.agentrc.json` is missing, either file is malformed, or the merged config fails schema validation',
|
|
24
26
|
],
|
|
25
27
|
};
|
|
26
28
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
14
|
|
|
15
|
+
import { syncCodexAgents } from './lib/codex/agents-projection.js';
|
|
15
16
|
import { applyHeader } from './lib/command-header.js';
|
|
16
17
|
import { applyAgentModel, getAgentModels } from './lib/config/agent-models.js';
|
|
17
18
|
import { resolveConfig } from './lib/config-resolver.js';
|
|
@@ -148,3 +149,22 @@ await Promise.all(Array.from(byName.values()).map(syncEntry));
|
|
|
148
149
|
Logger.info(
|
|
149
150
|
`\n✔ ${synced} file(s) synced, ${sourceSet.size} total agents in .claude/agents/`,
|
|
150
151
|
);
|
|
152
|
+
|
|
153
|
+
// The Codex half: the same roles as `.codex/agents/mandrel-<role>.toml`. A
|
|
154
|
+
// fixture run (a DEST override) skips it unless SYNC_CODEX_AGENTS_DEST names
|
|
155
|
+
// its own target.
|
|
156
|
+
const codexAgentsDest =
|
|
157
|
+
process.env.SYNC_CODEX_AGENTS_DEST ??
|
|
158
|
+
(process.env.SYNC_CLAUDE_AGENTS_DEST ? null : undefined);
|
|
159
|
+
if (codexAgentsDest !== null) {
|
|
160
|
+
const codex = syncCodexAgents({
|
|
161
|
+
projectRoot: PROJECT_ROOT,
|
|
162
|
+
payloadSrc: PAYLOAD_SRC,
|
|
163
|
+
localSrc: LOCAL_SRC,
|
|
164
|
+
destDir: codexAgentsDest,
|
|
165
|
+
log: (line) => Logger.info(line),
|
|
166
|
+
});
|
|
167
|
+
Logger.info(
|
|
168
|
+
`✔ ${codex.written.length} file(s) synced, ${codex.total} total Codex agents in .codex/agents/`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
|
|
16
|
+
import { syncCodexSkills } from './lib/codex/skills-projection.js';
|
|
16
17
|
import { applyHeader, isCommandExcluded } from './lib/command-header.js';
|
|
17
18
|
import { Logger } from './lib/Logger.js';
|
|
18
19
|
|
|
@@ -117,14 +118,27 @@ function enumerateLoopUnits(dir) {
|
|
|
117
118
|
// Payload first, so it wins a collision.
|
|
118
119
|
const SRC_DIRS = [PAYLOAD_SRC, LOCAL_SRC].filter(dirExists);
|
|
119
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Named, not inline: an anonymous callback in this spawned-only script has no
|
|
123
|
+
* coverage coordinates for the CRAP seat to resolve.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} dir A workflows source root.
|
|
126
|
+
* @returns {Array<{dir: string, name: string, rel: string}>}
|
|
127
|
+
*/
|
|
128
|
+
function workflowEntriesIn(dir) {
|
|
129
|
+
return [
|
|
130
|
+
...fs
|
|
131
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
132
|
+
.filter(isTopLevelWorkflow)
|
|
133
|
+
.map(function toWorkflowEntry(e) {
|
|
134
|
+
return { dir, name: e.name, rel: e.name };
|
|
135
|
+
}),
|
|
136
|
+
...enumerateLoopUnits(dir),
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
|
|
120
140
|
/** @type {Array<{dir: string, name: string, rel: string}>} */
|
|
121
|
-
const entries = SRC_DIRS.flatMap(
|
|
122
|
-
...fs
|
|
123
|
-
.readdirSync(dir, { withFileTypes: true })
|
|
124
|
-
.filter(isTopLevelWorkflow)
|
|
125
|
-
.map((e) => ({ dir, name: e.name, rel: e.name })),
|
|
126
|
-
...enumerateLoopUnits(dir),
|
|
127
|
-
]);
|
|
141
|
+
const entries = SRC_DIRS.flatMap(workflowEntriesIn);
|
|
128
142
|
|
|
129
143
|
// A `command: false` workflow never enters `sourceSet`, so a stale copy is reaped.
|
|
130
144
|
const byRel = new Map();
|
|
@@ -171,30 +185,53 @@ for (const rel of listExistingCommands()) {
|
|
|
171
185
|
// The header goes after any frontmatter, so `---` stays on line 1.
|
|
172
186
|
let synced = 0;
|
|
173
187
|
const resolvedEntries = Array.from(byRel.values());
|
|
174
|
-
await Promise.all(
|
|
175
|
-
resolvedEntries.map(async ({ dir, rel }) => {
|
|
176
|
-
const isLocal = dir === LOCAL_SRC;
|
|
177
|
-
const header = isLocal ? LOCAL_HEADER : HEADER;
|
|
178
|
-
const content = await fs.promises.readFile(path.join(dir, rel), 'utf8');
|
|
179
|
-
const dest = path.join(DEST_DIR, rel);
|
|
180
|
-
const target = applyHeader(content, header);
|
|
181
188
|
|
|
182
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @param {{ dir: string, rel: string }} entry
|
|
191
|
+
* @returns {Promise<void>}
|
|
192
|
+
*/
|
|
193
|
+
async function syncEntry({ dir, rel }) {
|
|
194
|
+
const isLocal = dir === LOCAL_SRC;
|
|
195
|
+
const header = isLocal ? LOCAL_HEADER : HEADER;
|
|
196
|
+
const content = await fs.promises.readFile(path.join(dir, rel), 'utf8');
|
|
197
|
+
const dest = path.join(DEST_DIR, rel);
|
|
198
|
+
const target = applyHeader(content, header);
|
|
183
199
|
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const existingContent = await fs.promises.readFile(dest, 'utf8');
|
|
187
|
-
if (existingContent === target) return;
|
|
188
|
-
} catch (err) {
|
|
189
|
-
if (err.code !== 'ENOENT') throw err;
|
|
190
|
-
}
|
|
200
|
+
await fs.promises.mkdir(path.dirname(dest), { recursive: true });
|
|
191
201
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
)
|
|
202
|
+
// Skip identical content to avoid noisy git diffs.
|
|
203
|
+
try {
|
|
204
|
+
const existingContent = await fs.promises.readFile(dest, 'utf8');
|
|
205
|
+
if (existingContent === target) return;
|
|
206
|
+
} catch (err) {
|
|
207
|
+
if (err.code !== 'ENOENT') throw err;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await fs.promises.writeFile(dest, target, 'utf8');
|
|
211
|
+
synced++;
|
|
212
|
+
Logger.info(` synced ${rel}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
await Promise.all(resolvedEntries.map(syncEntry));
|
|
197
216
|
|
|
198
217
|
Logger.info(
|
|
199
218
|
`\n✔ ${synced} file(s) synced, ${sourceSet.size} total commands in .claude/commands/`,
|
|
200
219
|
);
|
|
220
|
+
|
|
221
|
+
// The Codex half: the same source set as Codex skills. A fixture run (a
|
|
222
|
+
// DEST override) skips it unless SYNC_CODEX_SKILLS_DEST names its own target.
|
|
223
|
+
const codexSkillsDest =
|
|
224
|
+
process.env.SYNC_CODEX_SKILLS_DEST ??
|
|
225
|
+
(process.env.SYNC_CLAUDE_COMMANDS_DEST ? null : undefined);
|
|
226
|
+
if (codexSkillsDest !== null) {
|
|
227
|
+
const codex = syncCodexSkills({
|
|
228
|
+
projectRoot: PROJECT_ROOT,
|
|
229
|
+
payloadSrc: PAYLOAD_SRC,
|
|
230
|
+
localSrc: LOCAL_SRC,
|
|
231
|
+
destDir: codexSkillsDest,
|
|
232
|
+
log: (line) => Logger.info(line),
|
|
233
|
+
});
|
|
234
|
+
Logger.info(
|
|
235
|
+
`✔ ${codex.written.length} file(s) synced, ${codex.total} total Codex skills in .agents/skills/workflows/`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Project the role agents into Codex custom agents under `.codex/agents/`.
|
|
5
|
+
* `sync-claude-agents.js` runs the same projection after the Claude one, so
|
|
6
|
+
* `mandrel sync-agents` and `npm run sync:agents` cover both hosts; this
|
|
7
|
+
* entry point refreshes the Codex half alone.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { runAsCli } from './lib/cli-utils.js';
|
|
11
|
+
import {
|
|
12
|
+
CODEX_AGENTS_DIR,
|
|
13
|
+
syncCodexAgents,
|
|
14
|
+
} from './lib/codex/agents-projection.js';
|
|
15
|
+
import { Logger } from './lib/Logger.js';
|
|
16
|
+
|
|
17
|
+
/** @returns {Promise<void>} */
|
|
18
|
+
async function main() {
|
|
19
|
+
const { written, total } = syncCodexAgents({
|
|
20
|
+
projectRoot: process.cwd(),
|
|
21
|
+
log: (line) => Logger.info(line),
|
|
22
|
+
});
|
|
23
|
+
Logger.info(
|
|
24
|
+
`\n✔ ${written.length} file(s) synced, ${total} total agents in ${CODEX_AGENTS_DIR}/`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
runAsCli(import.meta.url, main, {
|
|
29
|
+
source: 'sync-codex-agents',
|
|
30
|
+
usage: {
|
|
31
|
+
invocation: 'node .agents/scripts/sync-codex-agents.js',
|
|
32
|
+
summary:
|
|
33
|
+
'Regenerate the Codex custom-agent projection of .agents/agents/ (and .agents/local/agents/) as .codex/agents/mandrel-<role>.toml.',
|
|
34
|
+
flags: [],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Project the workflow set into Codex skills under `.agents/skills/workflows/`.
|
|
5
|
+
* `sync-claude-commands.js` runs the same projection after the Claude one, so
|
|
6
|
+
* `mandrel sync-commands` and `npm run sync:commands` cover both hosts; this
|
|
7
|
+
* entry point refreshes the Codex half alone.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { runAsCli } from './lib/cli-utils.js';
|
|
11
|
+
import {
|
|
12
|
+
CODEX_SKILLS_DIR,
|
|
13
|
+
syncCodexSkills,
|
|
14
|
+
} from './lib/codex/skills-projection.js';
|
|
15
|
+
import { Logger } from './lib/Logger.js';
|
|
16
|
+
|
|
17
|
+
/** @returns {Promise<void>} */
|
|
18
|
+
async function main() {
|
|
19
|
+
const { written, total } = syncCodexSkills({
|
|
20
|
+
projectRoot: process.cwd(),
|
|
21
|
+
log: (line) => Logger.info(line),
|
|
22
|
+
});
|
|
23
|
+
Logger.info(
|
|
24
|
+
`\n✔ ${written.length} file(s) synced, ${total} total skills in ${CODEX_SKILLS_DIR}/`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
runAsCli(import.meta.url, main, {
|
|
29
|
+
source: 'sync-codex-skills',
|
|
30
|
+
usage: {
|
|
31
|
+
invocation: 'node .agents/scripts/sync-codex-skills.js',
|
|
32
|
+
summary:
|
|
33
|
+
'Regenerate the Codex skill projection of .agents/workflows/ (and .agents/local/workflows/) under .agents/skills/workflows/.',
|
|
34
|
+
flags: [],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -35,9 +35,10 @@ The reconciliation rules:
|
|
|
35
35
|
|
|
36
36
|
| Scenario | Behavior |
|
|
37
37
|
| --------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
38
|
-
|
|
|
38
|
+
| Merged config (`.agentrc.json` + `.agentrc.local.json`) validates | **Preserve** unconditionally |
|
|
39
39
|
| Project value fails validation | **Abort** with a list of validation errors |
|
|
40
|
-
| Required key missing
|
|
40
|
+
| Required key missing from both files | **Abort via validator** — the schema catches it; the helper does not auto-fill |
|
|
41
|
+
| Required key supplied only by `.agentrc.local.json` | **Valid** — the overlay is merged before validation, as the runtime resolver does |
|
|
41
42
|
| Optional key missing in project | **Leave absent** — the runtime resolves the framework default at read time |
|
|
42
43
|
| Project value deep-equals framework default | **Emit `[REDUNDANT]` advisory** (informational only — the file is never modified) |
|
|
43
44
|
| Identity placeholder paths (`github.owner` / `repo` / …) | **Never flagged** — they carry no usable framework default |
|
|
@@ -72,22 +73,28 @@ The script:
|
|
|
72
73
|
override). When the file is missing, prints an error asking the
|
|
73
74
|
operator to run `mandrel init` (new project) or
|
|
74
75
|
`node .agents/scripts/bootstrap.js` (existing project) and exits 1.
|
|
75
|
-
2.
|
|
76
|
+
2. When a gitignored `.agentrc.local.json` exists, deep-merges it over
|
|
77
|
+
`.agentrc.json` exactly as the runtime resolver does (a malformed overlay
|
|
78
|
+
is reported by name and exits 1). Per-operator identity such as
|
|
79
|
+
`github.operatorHandle` may therefore live in the overlay alone — see
|
|
80
|
+
[Multi-operator repos](../../docs/configuration.md#multi-operator-repos).
|
|
81
|
+
3. Validates the merged config against the framework AJV schema
|
|
76
82
|
(`getAgentrcValidator()`). On any failure, prints a single-line error
|
|
77
83
|
list and exits 1 — the operator must fix the typo / missing required
|
|
78
|
-
key before re-running.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
`
|
|
84
|
+
key before re-running. A missing `github.operatorHandle` names where to
|
|
85
|
+
set it.
|
|
86
|
+
4. Walks every default leaf path. For each path where the committed
|
|
87
|
+
`.agentrc.json` carries a value deep-equal to the framework default,
|
|
88
|
+
prints a `[REDUNDANT]` advisory row (overlay leaves are never flagged). Advisories are informational — the
|
|
82
89
|
project file is never modified.
|
|
83
|
-
|
|
90
|
+
5. Prints the summary line and exits 0.
|
|
84
91
|
|
|
85
92
|
### Exit codes
|
|
86
93
|
|
|
87
94
|
| Code | Meaning |
|
|
88
95
|
| ---- | ----------------------------------------------------------------------------- |
|
|
89
96
|
| 0 | Config is valid (advisories may still appear) |
|
|
90
|
-
| 1 |
|
|
97
|
+
| 1 | `.agentrc.json` is missing, either file is malformed, or the merged config fails schema validation |
|
|
91
98
|
|
|
92
99
|
### Flags
|
|
93
100
|
|
|
@@ -147,7 +147,8 @@ node .agents/scripts/sync-agentrc.js
|
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
The helper is default-aware and **read-only**: it validates
|
|
150
|
-
the consumer config
|
|
150
|
+
the consumer config — `.agentrc.json` with any gitignored
|
|
151
|
+
`.agentrc.local.json` merged over it, as the runtime does — against the new schema (non-zero exit → fix the
|
|
151
152
|
validation error and re-run before proceeding), never auto-fills missing
|
|
152
153
|
optional keys (the runtime layers defaults at read time), and flags
|
|
153
154
|
project values that deep-equal the framework default as `[REDUNDANT]`
|