mandrel 2.81.0 → 2.82.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/scripts/lib/audit-to-stories/parse-audit-md.js +49 -24
- package/.agents/scripts/lib/baselines/duplication-scanner.js +9 -5
- package/.agents/scripts/lib/bootstrap/manifest.js +128 -159
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/cli.js +31 -27
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/render.js +25 -21
- package/.agents/scripts/lib/orchestration/pr-watch-poll.js +107 -0
- package/.agents/scripts/lib/orchestration/pr-watch.js +168 -235
- package/.agents/scripts/lib/orchestration/reassert-status-column.js +102 -72
- package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +21 -3
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-gate-steps.js +44 -2
- package/.agents/scripts/lib/orchestration/story-close/duplication-close-rescore.js +257 -0
- package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +341 -0
- package/.agents/scripts/lib/orchestration/ticketing.js +0 -9
- package/docs/CHANGELOG.md +19 -0
- package/package.json +1 -1
|
@@ -69,6 +69,50 @@ function deriveDimension(fields, fallbackDimension) {
|
|
|
69
69
|
return fallbackDimension;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Strip wrapping quotes/brackets, trailing punctuation, and a `Location:`
|
|
74
|
+
* anchor (`:line`, `:line:col`, `:start-end`) from a raw token.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} raw
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
function stripTokenDecoration(raw) {
|
|
80
|
+
return raw
|
|
81
|
+
.replace(/^[`'"([]+/, '')
|
|
82
|
+
.replace(/[`'")\].,;]+$/, '')
|
|
83
|
+
.trim()
|
|
84
|
+
.replace(/:\d+(?:-\d+)?(?::\d+)?$/, '');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Drop the `repoRoot` prefix (either separator) from a token, if present.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} token
|
|
91
|
+
* @param {string} [repoRoot]
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
function relativiseToRoot(token, repoRoot) {
|
|
95
|
+
if (typeof repoRoot !== 'string' || repoRoot.length === 0) return token;
|
|
96
|
+
for (const sep of ['/', '\\']) {
|
|
97
|
+
const root = repoRoot.endsWith(sep) ? repoRoot : `${repoRoot}${sep}`;
|
|
98
|
+
if (token.startsWith(root)) return token.slice(root.length);
|
|
99
|
+
}
|
|
100
|
+
return token;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isAbsoluteToken(token) {
|
|
104
|
+
return /^(?:[/\\]|[A-Za-z]:)/.test(token);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A separator-less token passes only as a bare file with a known extension,
|
|
109
|
+
* and only where `requireSeparator` does not forbid it.
|
|
110
|
+
*/
|
|
111
|
+
function isAcceptedShape(token, requireSeparator) {
|
|
112
|
+
if (token.includes('/') || token.includes('\\')) return true;
|
|
113
|
+
return !requireSeparator && FILE_EXT.test(token);
|
|
114
|
+
}
|
|
115
|
+
|
|
72
116
|
/**
|
|
73
117
|
* Repo-relative path, or `null` for an absolute (outside `repoRoot`) or
|
|
74
118
|
* degenerate token. A bare root-level file (`AGENTS.md`) is accepted in
|
|
@@ -82,32 +126,12 @@ function deriveDimension(fields, fallbackDimension) {
|
|
|
82
126
|
*/
|
|
83
127
|
function normalisePathToken(raw, repoRoot, { requireSeparator = false } = {}) {
|
|
84
128
|
if (typeof raw !== 'string') return null;
|
|
85
|
-
const
|
|
86
|
-
.replace(/^[`'"([]+/, '')
|
|
87
|
-
.replace(/[`'")\].,;]+$/, '')
|
|
88
|
-
.trim();
|
|
89
|
-
// `Location:` anchors appear as `:line`, `:line:col`, and `:start-end`.
|
|
90
|
-
const cleaned = stripped.replace(/:\d+(?:-\d+)?(?::\d+)?$/, '');
|
|
129
|
+
const cleaned = stripTokenDecoration(raw);
|
|
91
130
|
if (!cleaned || cleaned === '.' || cleaned === '..') return null;
|
|
92
|
-
|
|
93
|
-
let out = cleaned;
|
|
94
|
-
if (typeof repoRoot === 'string' && repoRoot.length > 0) {
|
|
95
|
-
for (const sep of ['/', '\\']) {
|
|
96
|
-
const root = repoRoot.endsWith(sep) ? repoRoot : `${repoRoot}${sep}`;
|
|
97
|
-
if (out.startsWith(root)) {
|
|
98
|
-
out = out.slice(root.length);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
131
|
+
const out = relativiseToRoot(cleaned, repoRoot);
|
|
103
132
|
// Still absolute ⇒ outside the repo; never a valid group key.
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const hasSeparator = out.includes('/') || out.includes('\\');
|
|
108
|
-
if (requireSeparator && !hasSeparator) return null;
|
|
109
|
-
if (!hasSeparator && !FILE_EXT.test(out)) return null;
|
|
110
|
-
return out;
|
|
133
|
+
if (isAbsoluteToken(out)) return null;
|
|
134
|
+
return isAcceptedShape(out, requireSeparator) ? out : null;
|
|
111
135
|
}
|
|
112
136
|
|
|
113
137
|
/**
|
|
@@ -468,6 +492,7 @@ export const __testing = {
|
|
|
468
492
|
isGroupingHeader,
|
|
469
493
|
foldGroupingHeaders,
|
|
470
494
|
normaliseSeverity,
|
|
495
|
+
normalisePathToken,
|
|
471
496
|
extractFilePaths,
|
|
472
497
|
normaliseTitle,
|
|
473
498
|
deriveDimension,
|
|
@@ -59,16 +59,20 @@ export function relativisePath(sourceId, cwd) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* A side
|
|
63
|
-
*
|
|
62
|
+
* A side ending before it starts, or past its file's counted length, counts
|
|
63
|
+
* nothing: its real span is unrecoverable (jscpd 4 can report the other
|
|
64
|
+
* file's end line), and widening or clamping it records phantom lines.
|
|
64
65
|
*
|
|
65
66
|
* @param {{ start?: { line?: number }, end?: { line?: number } }} dup
|
|
67
|
+
* @param {number} [maxLine] the file's counted length, when known
|
|
66
68
|
* @returns {Array<number>} the 1-based line numbers the clone covers
|
|
67
69
|
*/
|
|
68
|
-
function cloneLineNumbers(dup) {
|
|
70
|
+
function cloneLineNumbers(dup, maxLine) {
|
|
69
71
|
const start = dup?.start?.line;
|
|
70
72
|
const end = dup?.end?.line;
|
|
71
|
-
if (!Number.isInteger(start) || !Number.isInteger(end))
|
|
73
|
+
if (!Number.isInteger(start) || !Number.isInteger(end) || end > maxLine) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
72
76
|
const lines = [];
|
|
73
77
|
for (let n = start; n <= end; n += 1) lines.push(n);
|
|
74
78
|
return lines;
|
|
@@ -100,7 +104,7 @@ export function buildDuplicationRows(
|
|
|
100
104
|
const file = relativisePath(side.sourceId, cwd);
|
|
101
105
|
if (!file) continue;
|
|
102
106
|
const set = dupLinesByFile.get(file) ?? new Set();
|
|
103
|
-
for (const
|
|
107
|
+
for (const n of cloneLineNumbers(side, counts.get(file))) set.add(n);
|
|
104
108
|
dupLinesByFile.set(file, set);
|
|
105
109
|
}
|
|
106
110
|
}
|
|
@@ -21,20 +21,6 @@ export const PHASE_GROUPS = Object.freeze({
|
|
|
21
21
|
QUALITY_GATES: 'quality-gates',
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
/** @type {ReadonlySet<string>} */
|
|
25
|
-
export const PHASE_GROUP_VALUES = Object.freeze(
|
|
26
|
-
new Set(Object.values(PHASE_GROUPS)),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
/** @type {readonly string[]} */
|
|
30
|
-
export const MANIFEST_ENTRY_FIELDS = Object.freeze([
|
|
31
|
-
'phaseGroup',
|
|
32
|
-
'target',
|
|
33
|
-
'action',
|
|
34
|
-
'detail',
|
|
35
|
-
'reversible',
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
24
|
/**
|
|
39
25
|
* @typedef {object} MutationManifestEntry
|
|
40
26
|
* @property {'ide-wiring'|'repo-config'|'github-admin'|'quality-gates'} phaseGroup
|
|
@@ -44,6 +30,128 @@ export const MANIFEST_ENTRY_FIELDS = Object.freeze([
|
|
|
44
30
|
* @property {boolean} reversible — false for remote-admin mutations.
|
|
45
31
|
*/
|
|
46
32
|
|
|
33
|
+
const rel = (...parts) => path.posix.join(...parts);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {MutationManifestEntry['phaseGroup']} phaseGroup
|
|
37
|
+
* @param {boolean} reversible
|
|
38
|
+
* @returns {(target: string, action: string, detail: string) => MutationManifestEntry}
|
|
39
|
+
*/
|
|
40
|
+
function entryFor(phaseGroup, reversible) {
|
|
41
|
+
return (target, action, detail) => ({
|
|
42
|
+
phaseGroup,
|
|
43
|
+
target,
|
|
44
|
+
action,
|
|
45
|
+
detail,
|
|
46
|
+
reversible,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ideWiringEntries() {
|
|
51
|
+
const e = entryFor(PHASE_GROUPS.IDE_WIRING, true);
|
|
52
|
+
return [
|
|
53
|
+
e(
|
|
54
|
+
rel('AGENTS.md'),
|
|
55
|
+
'merge',
|
|
56
|
+
'Wire the @.agents/instructions.md system-prompt import into AGENTS.md (folding any CLAUDE.md into it) so Claude Code hydrates the framework on cold start.',
|
|
57
|
+
),
|
|
58
|
+
e(
|
|
59
|
+
rel('.claude', 'commands'),
|
|
60
|
+
'run',
|
|
61
|
+
'Generate the flat command surface (/<name>) from .agents/workflows/.',
|
|
62
|
+
),
|
|
63
|
+
e(
|
|
64
|
+
rel('.gitignore'),
|
|
65
|
+
'merge',
|
|
66
|
+
'Ignore the .claude/commands/ and .claude/agents/ projections (generated by prepare), .mcp.json + .env (carry secrets), and the per-clone install ledger.',
|
|
67
|
+
),
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function repoConfigEntries() {
|
|
72
|
+
const e = entryFor(PHASE_GROUPS.REPO_CONFIG, true);
|
|
73
|
+
// git-init is the most irreversible local mutation; the ledger must record it.
|
|
74
|
+
const gitInit = entryFor(PHASE_GROUPS.REPO_CONFIG, false)(
|
|
75
|
+
rel('.git'),
|
|
76
|
+
'run',
|
|
77
|
+
'Initialize the local git repository (git init + first commit) when absent. No-op when already a git repo.',
|
|
78
|
+
);
|
|
79
|
+
return [
|
|
80
|
+
gitInit,
|
|
81
|
+
e(
|
|
82
|
+
rel('package.json'),
|
|
83
|
+
'merge',
|
|
84
|
+
'Seed/merge the sync:commands, sync:agents, prepare, and bootstrap npm scripts. `prepare` is guarded: it exits 0 without writing when .agents/scripts/ is absent (a manifest-only container `npm ci`), and otherwise regenerates the .claude/commands/ and .claude/agents/ projections — both gitignored.',
|
|
85
|
+
),
|
|
86
|
+
e(
|
|
87
|
+
rel('.agentrc.json'),
|
|
88
|
+
'create',
|
|
89
|
+
'Seed .agentrc.json from the bundled starter with the operator-supplied owner/repo/handle/base-branch.',
|
|
90
|
+
),
|
|
91
|
+
e(
|
|
92
|
+
rel('.github', 'ISSUE_TEMPLATE'),
|
|
93
|
+
'create',
|
|
94
|
+
'Generate the Story/Epic GitHub Issue Forms from the body SSOT so human-filed tickets round-trip through story-body.parse(). Operator-edited forms are preserved.',
|
|
95
|
+
),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function qualityGateEntries() {
|
|
100
|
+
const e = entryFor(PHASE_GROUPS.QUALITY_GATES, true);
|
|
101
|
+
return [
|
|
102
|
+
e(
|
|
103
|
+
rel('.husky', 'pre-commit'),
|
|
104
|
+
'configure',
|
|
105
|
+
'Install the quality:preview pre-commit hook that blocks MI/CRAP drift at commit time.',
|
|
106
|
+
),
|
|
107
|
+
e(
|
|
108
|
+
rel('package.json'),
|
|
109
|
+
'merge',
|
|
110
|
+
'Add the quality:preview and quality:watch npm scripts.',
|
|
111
|
+
),
|
|
112
|
+
e(
|
|
113
|
+
rel('.agentrc.json'),
|
|
114
|
+
'merge',
|
|
115
|
+
'Seed delivery.quality coding-guardrails and auto-refresh defaults.',
|
|
116
|
+
),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function githubAdminEntries(answers) {
|
|
121
|
+
const repoSlug =
|
|
122
|
+
answers?.owner && answers?.repo
|
|
123
|
+
? `${answers.owner}/${answers.repo}`
|
|
124
|
+
: 'the GitHub repository';
|
|
125
|
+
const e = entryFor(PHASE_GROUPS.GITHUB_ADMIN, false);
|
|
126
|
+
return [
|
|
127
|
+
e(
|
|
128
|
+
`${repoSlug} (repo)`,
|
|
129
|
+
'create',
|
|
130
|
+
'Create the GitHub repository (gh repo create --source=. --push) when absent. No-op when already pushed.',
|
|
131
|
+
),
|
|
132
|
+
e(
|
|
133
|
+
`${repoSlug} labels`,
|
|
134
|
+
'create',
|
|
135
|
+
'Create the framework ticket-lifecycle labels (type::*, agent::*, meta::*, …).',
|
|
136
|
+
),
|
|
137
|
+
e(
|
|
138
|
+
`${repoSlug} Projects V2`,
|
|
139
|
+
'configure',
|
|
140
|
+
'Create/adopt the Projects V2 board, status field, and saved views.',
|
|
141
|
+
),
|
|
142
|
+
e(
|
|
143
|
+
`${repoSlug} branch protection`,
|
|
144
|
+
'configure',
|
|
145
|
+
'Apply the required-status-check branch-protection rule to the base branch.',
|
|
146
|
+
),
|
|
147
|
+
e(
|
|
148
|
+
`${repoSlug} merge methods`,
|
|
149
|
+
'configure',
|
|
150
|
+
'Set the allowed pull-request merge methods to the framework stance (squash-only, auto-merge enabled).',
|
|
151
|
+
),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
|
|
47
155
|
/**
|
|
48
156
|
* File targets are POSIX paths so output is platform-identical; the group
|
|
49
157
|
* set honours the same flags the executing pipeline does.
|
|
@@ -55,149 +163,10 @@ export const MANIFEST_ENTRY_FIELDS = Object.freeze([
|
|
|
55
163
|
* @returns {MutationManifestEntry[]}
|
|
56
164
|
*/
|
|
57
165
|
export function buildMutationManifest(ctx = {}) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
phaseGroup: PHASE_GROUPS.IDE_WIRING,
|
|
65
|
-
target: rel('AGENTS.md'),
|
|
66
|
-
action: 'merge',
|
|
67
|
-
detail:
|
|
68
|
-
'Wire the @.agents/instructions.md system-prompt import into AGENTS.md (folding any CLAUDE.md into it) so Claude Code hydrates the framework on cold start.',
|
|
69
|
-
reversible: true,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
phaseGroup: PHASE_GROUPS.IDE_WIRING,
|
|
73
|
-
target: rel('.claude', 'commands'),
|
|
74
|
-
action: 'run',
|
|
75
|
-
detail:
|
|
76
|
-
'Generate the flat command surface (/<name>) from .agents/workflows/.',
|
|
77
|
-
reversible: true,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
phaseGroup: PHASE_GROUPS.IDE_WIRING,
|
|
81
|
-
target: rel('.gitignore'),
|
|
82
|
-
action: 'merge',
|
|
83
|
-
detail:
|
|
84
|
-
'Ignore the .claude/commands/ and .claude/agents/ projections (generated by prepare), .mcp.json + .env (carry secrets), and the per-clone install ledger.',
|
|
85
|
-
reversible: true,
|
|
86
|
-
},
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
// git-init is the most irreversible local mutation; the ledger must record it.
|
|
90
|
-
entries.push(
|
|
91
|
-
{
|
|
92
|
-
phaseGroup: PHASE_GROUPS.REPO_CONFIG,
|
|
93
|
-
target: rel('.git'),
|
|
94
|
-
action: 'run',
|
|
95
|
-
detail:
|
|
96
|
-
'Initialize the local git repository (git init + first commit) when absent. No-op when already a git repo.',
|
|
97
|
-
reversible: false,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
phaseGroup: PHASE_GROUPS.REPO_CONFIG,
|
|
101
|
-
target: rel('package.json'),
|
|
102
|
-
action: 'merge',
|
|
103
|
-
detail:
|
|
104
|
-
'Seed/merge the sync:commands, sync:agents, prepare, and bootstrap npm scripts. `prepare` is guarded: it exits 0 without writing when .agents/scripts/ is absent (a manifest-only container `npm ci`), and otherwise regenerates the .claude/commands/ and .claude/agents/ projections — both gitignored.',
|
|
105
|
-
reversible: true,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
phaseGroup: PHASE_GROUPS.REPO_CONFIG,
|
|
109
|
-
target: rel('.agentrc.json'),
|
|
110
|
-
action: 'create',
|
|
111
|
-
detail:
|
|
112
|
-
'Seed .agentrc.json from the bundled starter with the operator-supplied owner/repo/handle/base-branch.',
|
|
113
|
-
reversible: true,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
phaseGroup: PHASE_GROUPS.REPO_CONFIG,
|
|
117
|
-
target: rel('.github', 'ISSUE_TEMPLATE'),
|
|
118
|
-
action: 'create',
|
|
119
|
-
detail:
|
|
120
|
-
'Generate the Story/Epic GitHub Issue Forms from the body SSOT so human-filed tickets round-trip through story-body.parse(). Operator-edited forms are preserved.',
|
|
121
|
-
reversible: true,
|
|
122
|
-
},
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (ctx.withQuality) {
|
|
126
|
-
entries.push(
|
|
127
|
-
{
|
|
128
|
-
phaseGroup: PHASE_GROUPS.QUALITY_GATES,
|
|
129
|
-
target: rel('.husky', 'pre-commit'),
|
|
130
|
-
action: 'configure',
|
|
131
|
-
detail:
|
|
132
|
-
'Install the quality:preview pre-commit hook that blocks MI/CRAP drift at commit time.',
|
|
133
|
-
reversible: true,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
phaseGroup: PHASE_GROUPS.QUALITY_GATES,
|
|
137
|
-
target: rel('package.json'),
|
|
138
|
-
action: 'merge',
|
|
139
|
-
detail: 'Add the quality:preview and quality:watch npm scripts.',
|
|
140
|
-
reversible: true,
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
phaseGroup: PHASE_GROUPS.QUALITY_GATES,
|
|
144
|
-
target: rel('.agentrc.json'),
|
|
145
|
-
action: 'merge',
|
|
146
|
-
detail:
|
|
147
|
-
'Seed delivery.quality coding-guardrails and auto-refresh defaults.',
|
|
148
|
-
reversible: true,
|
|
149
|
-
},
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (!ctx.skipGithub) {
|
|
154
|
-
const repoSlug =
|
|
155
|
-
ctx.answers?.owner && ctx.answers?.repo
|
|
156
|
-
? `${ctx.answers.owner}/${ctx.answers.repo}`
|
|
157
|
-
: 'the GitHub repository';
|
|
158
|
-
entries.push(
|
|
159
|
-
{
|
|
160
|
-
phaseGroup: PHASE_GROUPS.GITHUB_ADMIN,
|
|
161
|
-
target: `${repoSlug} (repo)`,
|
|
162
|
-
action: 'create',
|
|
163
|
-
detail:
|
|
164
|
-
'Create the GitHub repository (gh repo create --source=. --push) when absent. No-op when already pushed.',
|
|
165
|
-
reversible: false,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
phaseGroup: PHASE_GROUPS.GITHUB_ADMIN,
|
|
169
|
-
target: `${repoSlug} labels`,
|
|
170
|
-
action: 'create',
|
|
171
|
-
detail:
|
|
172
|
-
'Create the framework ticket-lifecycle labels (type::*, agent::*, meta::*, …).',
|
|
173
|
-
reversible: false,
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
phaseGroup: PHASE_GROUPS.GITHUB_ADMIN,
|
|
177
|
-
target: `${repoSlug} Projects V2`,
|
|
178
|
-
action: 'configure',
|
|
179
|
-
detail:
|
|
180
|
-
'Create/adopt the Projects V2 board, status field, and saved views.',
|
|
181
|
-
reversible: false,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
phaseGroup: PHASE_GROUPS.GITHUB_ADMIN,
|
|
185
|
-
target: `${repoSlug} branch protection`,
|
|
186
|
-
action: 'configure',
|
|
187
|
-
detail:
|
|
188
|
-
'Apply the required-status-check branch-protection rule to the base branch.',
|
|
189
|
-
reversible: false,
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
phaseGroup: PHASE_GROUPS.GITHUB_ADMIN,
|
|
193
|
-
target: `${repoSlug} merge methods`,
|
|
194
|
-
action: 'configure',
|
|
195
|
-
detail:
|
|
196
|
-
'Set the allowed pull-request merge methods to the framework stance (squash-only, auto-merge enabled).',
|
|
197
|
-
reversible: false,
|
|
198
|
-
},
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return entries;
|
|
166
|
+
return [
|
|
167
|
+
...ideWiringEntries(),
|
|
168
|
+
...repoConfigEntries(),
|
|
169
|
+
...(ctx.withQuality ? qualityGateEntries() : []),
|
|
170
|
+
...(ctx.skipGithub ? [] : githubAdminEntries(ctx.answers)),
|
|
171
|
+
];
|
|
203
172
|
}
|
|
@@ -17,19 +17,26 @@ import {
|
|
|
17
17
|
} from './phase-drivers.js';
|
|
18
18
|
import { buildJsonEnvelope, computeExitCode } from './render.js';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const DEFAULT_DEPS = Object.freeze({
|
|
21
|
+
runFastForwardPhase,
|
|
22
|
+
runPrunePhase,
|
|
23
|
+
runBranchPhase,
|
|
24
|
+
runStashPhase,
|
|
25
|
+
resolveConfig,
|
|
26
|
+
write: (text) => process.stdout.write(text),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function resolveBaseBranch(cwd, override, deps) {
|
|
22
30
|
if (override) return override;
|
|
23
31
|
try {
|
|
24
|
-
const cfg = resolveConfig({ cwd });
|
|
32
|
+
const cfg = deps.resolveConfig({ cwd });
|
|
25
33
|
return cfg?.project?.baseBranch || 'main';
|
|
26
34
|
} catch {
|
|
27
35
|
return 'main';
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
async function runActivePhases(opts, cwd, baseBranch) {
|
|
39
|
+
async function runActivePhases(opts, cwd, baseBranch, deps) {
|
|
33
40
|
const out = {
|
|
34
41
|
fastForward: null,
|
|
35
42
|
prune: null,
|
|
@@ -38,24 +45,23 @@ async function runActivePhases(opts, cwd, baseBranch) {
|
|
|
38
45
|
stashes: null,
|
|
39
46
|
};
|
|
40
47
|
if (opts.phases.fastForwardMain) {
|
|
41
|
-
out.fastForward = await runFastForwardPhase(opts, cwd, baseBranch);
|
|
48
|
+
out.fastForward = await deps.runFastForwardPhase(opts, cwd, baseBranch);
|
|
42
49
|
}
|
|
43
50
|
if (opts.phases.pruneRemotes) {
|
|
44
|
-
out.prune = await runPrunePhase(opts, cwd);
|
|
51
|
+
out.prune = await deps.runPrunePhase(opts, cwd);
|
|
45
52
|
}
|
|
46
53
|
if (opts.phases.branches) {
|
|
47
|
-
const r = await runBranchPhase(opts, cwd, baseBranch);
|
|
54
|
+
const r = await deps.runBranchPhase(opts, cwd, baseBranch);
|
|
48
55
|
out.branchesPlan = r.plan;
|
|
49
56
|
out.branchesResult = r.result;
|
|
50
57
|
}
|
|
51
58
|
if (opts.phases.stashes) {
|
|
52
|
-
out.stashes = await runStashPhase(opts, cwd);
|
|
59
|
+
out.stashes = await deps.runStashPhase(opts, cwd);
|
|
53
60
|
}
|
|
54
61
|
return out;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
64
|
+
function maybeEmitJson(opts, baseBranch, phaseResults, deps) {
|
|
59
65
|
if (!opts.json) return;
|
|
60
66
|
const envelope = buildJsonEnvelope({
|
|
61
67
|
dryRun: opts.dryRun,
|
|
@@ -66,7 +72,7 @@ function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
|
66
72
|
prune: phaseResults.prune,
|
|
67
73
|
stashes: phaseResults.stashes,
|
|
68
74
|
});
|
|
69
|
-
|
|
75
|
+
deps.write(`${JSON.stringify(envelope)}\n`);
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/**
|
|
@@ -75,21 +81,19 @@ function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
|
75
81
|
* `runAsCli(...)` and applies `process.exit(envelope.exitCode)` at the
|
|
76
82
|
* harness boundary so library code stays free of direct `process.exit`
|
|
77
83
|
* calls (see `tests/enforcement/process-exit.test.js`).
|
|
84
|
+
*
|
|
85
|
+
* @param {{ argv?: string[], deps?: Partial<typeof DEFAULT_DEPS> }} [args]
|
|
86
|
+
* `deps` overrides the phase drivers, config resolver and stdout writer.
|
|
78
87
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
export async function runCleanup({
|
|
89
|
+
argv = process.argv.slice(2),
|
|
90
|
+
deps = {},
|
|
91
|
+
} = {}) {
|
|
92
|
+
const d = { ...DEFAULT_DEPS, ...deps };
|
|
93
|
+
const opts = parseCleanupArgs(argv);
|
|
82
94
|
const cwd = path.resolve(opts.cwd ?? PROJECT_ROOT);
|
|
83
|
-
const baseBranch = resolveBaseBranch(cwd, opts.base);
|
|
84
|
-
const phaseResults = await runActivePhases(opts, cwd, baseBranch);
|
|
85
|
-
maybeEmitJson(opts, baseBranch, phaseResults);
|
|
86
|
-
return {
|
|
87
|
-
exitCode: computeExitCode({
|
|
88
|
-
branchesPlan: phaseResults.branchesPlan,
|
|
89
|
-
branchesResult: phaseResults.branchesResult,
|
|
90
|
-
fastForward: phaseResults.fastForward,
|
|
91
|
-
prune: phaseResults.prune,
|
|
92
|
-
stashes: phaseResults.stashes,
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
+
const baseBranch = resolveBaseBranch(cwd, opts.base, d);
|
|
96
|
+
const phaseResults = await runActivePhases(opts, cwd, baseBranch, d);
|
|
97
|
+
maybeEmitJson(opts, baseBranch, phaseResults, d);
|
|
98
|
+
return { exitCode: computeExitCode(phaseResults) };
|
|
95
99
|
}
|
|
@@ -281,6 +281,30 @@ function legacyExitCode(plan, result) {
|
|
|
281
281
|
return 0;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
function anyPhaseFailed({ branchesResult, fastForward, prune, stashes }) {
|
|
285
|
+
return [branchesResult, fastForward, prune, stashes].some(
|
|
286
|
+
(phase) => phase && !phase.ok,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function stashDropped(stashes) {
|
|
291
|
+
return (stashes?.actions ?? []).some((a) => a.action === 'drop' && a.dropped);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function anyPhaseWork({ branchesPlan, fastForward, prune, stashes }) {
|
|
295
|
+
return Boolean(
|
|
296
|
+
(branchesPlan?.candidates.length ?? 0) > 0 ||
|
|
297
|
+
fastForward?.applied ||
|
|
298
|
+
(prune?.pruned?.length ?? 0) > 0 ||
|
|
299
|
+
stashDropped(stashes),
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function multiPhaseExitCode(ctx) {
|
|
304
|
+
if (anyPhaseFailed(ctx)) return 1;
|
|
305
|
+
return anyPhaseWork(ctx) ? 0 : 2;
|
|
306
|
+
}
|
|
307
|
+
|
|
284
308
|
/**
|
|
285
309
|
* Accepts `(plan, result)` or a multi-phase context object.
|
|
286
310
|
*
|
|
@@ -292,25 +316,5 @@ export function computeExitCode(ctx, legacyResult) {
|
|
|
292
316
|
if (legacyResult !== undefined || Array.isArray(ctx?.candidates)) {
|
|
293
317
|
return legacyExitCode(ctx, legacyResult);
|
|
294
318
|
}
|
|
295
|
-
|
|
296
|
-
branchesPlan = null,
|
|
297
|
-
branchesResult = null,
|
|
298
|
-
fastForward = null,
|
|
299
|
-
prune = null,
|
|
300
|
-
stashes = null,
|
|
301
|
-
} = ctx ?? {};
|
|
302
|
-
const anyFailure =
|
|
303
|
-
(branchesResult && !branchesResult.ok) ||
|
|
304
|
-
(fastForward && !fastForward.ok) ||
|
|
305
|
-
(prune && !prune.ok) ||
|
|
306
|
-
(stashes && !stashes.ok);
|
|
307
|
-
if (anyFailure) return 1;
|
|
308
|
-
const anyWork =
|
|
309
|
-
(branchesPlan && branchesPlan.candidates.length > 0) ||
|
|
310
|
-
fastForward?.applied ||
|
|
311
|
-
(prune && (prune.pruned?.length ?? 0) > 0) ||
|
|
312
|
-
(stashes &&
|
|
313
|
-
(stashes.actions ?? []).some((a) => a.action === 'drop' && a.dropped));
|
|
314
|
-
if (!anyWork) return 2;
|
|
315
|
-
return 0;
|
|
319
|
+
return multiPhaseExitCode(ctx ?? {});
|
|
316
320
|
}
|