mandrel 2.78.0 → 2.79.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 +6 -1
- package/.agents/audit-checklists/architecture.md +1 -0
- package/.agents/audit-checklists/clean-code.md +1 -0
- package/.agents/audit-checklists/devops.md +4 -1
- package/.agents/audit-checklists/security.md +1 -1
- package/.agents/docs/configuration.md +1 -1
- package/.agents/schemas/agentrc.schema.json +1 -1
- package/.agents/scripts/bootstrap.js +87 -16
- package/.agents/scripts/lib/bootstrap/commit-push.js +3 -2
- package/.agents/scripts/lib/bootstrap/manifest.js +2 -2
- package/.agents/scripts/lib/bootstrap/project-bootstrap.js +51 -15
- package/.agents/scripts/lib/bootstrap/prompt.js +30 -1
- package/.agents/scripts/lib/close-validation/commands.js +33 -0
- package/.agents/scripts/lib/close-validation/gates.js +11 -4
- package/.agents/scripts/lib/config/explain.js +2 -1
- package/.agents/scripts/lib/config-settings-schema.js +2 -1
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/orchestration/story-handoff.js +15 -3
- package/.agents/scripts/lib/orchestration/verify-credit.js +9 -4
- package/.agents/scripts/lib/test-run-credit.js +46 -17
- package/.agents/workflows/audit-architecture.md +20 -4
- package/.agents/workflows/audit-clean-code.md +17 -1
- package/.agents/workflows/audit-devops.md +58 -14
- package/.agents/workflows/audit-performance.md +22 -0
- package/.agents/workflows/audit-quality.md +30 -0
- package/.agents/workflows/audit-security.md +23 -8
- package/.agents/workflows/helpers/audit-lens-core.md +48 -2
- package/README.md +13 -1
- package/docs/CHANGELOG.md +15 -0
- package/lib/cli/registry.js +85 -12
- package/lib/cli/uninstall.js +34 -18
- package/lib/cli/update.js +37 -6
- package/lib/migrations/index.js +2 -0
- package/lib/migrations/steps/2.79.0-container-safe-projections.js +91 -0
- package/package.json +1 -1
package/lib/cli/registry.js
CHANGED
|
@@ -860,9 +860,18 @@ function probeConfiguredDriver(command, runner, projectRoot) {
|
|
|
860
860
|
/** The runner whose green full run deposits the close `test` credit itself. */
|
|
861
861
|
const MANDREL_TEST_RUNNER = 'run-tests.js';
|
|
862
862
|
|
|
863
|
-
/**
|
|
864
|
-
const
|
|
865
|
-
|
|
863
|
+
/** The close `test` gate's command when `project.commands.test` is unset. */
|
|
864
|
+
const DEFAULT_TEST_COMMAND = 'npm test';
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* The deposit command that works on any runner, wrapping `command`.
|
|
868
|
+
*
|
|
869
|
+
* @param {string} command
|
|
870
|
+
* @returns {string}
|
|
871
|
+
*/
|
|
872
|
+
function testCreditDepositCommand(command) {
|
|
873
|
+
return `node .agents/scripts/evidence-gate.js --standalone --scope-id <storyId> --gate test --worktree <workCwd> -- ${command}`;
|
|
874
|
+
}
|
|
866
875
|
|
|
867
876
|
/** The capture close's `coverage-capture` gate finds fresh, per digest § 5. */
|
|
868
877
|
const COVERAGE_CAPTURE_COMMAND =
|
|
@@ -872,7 +881,13 @@ const COVERAGE_CAPTURE_COMMAND =
|
|
|
872
881
|
const STORY_HANDOFF_COMMAND =
|
|
873
882
|
'node .agents/scripts/story-handoff.js --story <storyId> --cwd <workCwd>';
|
|
874
883
|
|
|
875
|
-
|
|
884
|
+
/**
|
|
885
|
+
* @param {string} command
|
|
886
|
+
* @returns {string}
|
|
887
|
+
*/
|
|
888
|
+
function testCreditRemedy(command) {
|
|
889
|
+
return `run the suite through the depositor instead of bare \`${command}\`: ${testCreditDepositCommand(command)}`;
|
|
890
|
+
}
|
|
876
891
|
|
|
877
892
|
const PRE_PUSH_REMEDY =
|
|
878
893
|
'wrap each hook gate in `node .agents/scripts/evidence-gate.js --standalone --scope-id <storyId> --gate <typecheck|lint> -- <command>` so the push deposits the credit close reads';
|
|
@@ -881,8 +896,8 @@ const PRE_PUSH_REMEDY =
|
|
|
881
896
|
const HOOK_GATE_RE = /\b(typecheck|tsc|lint|eslint|biome)\b/;
|
|
882
897
|
|
|
883
898
|
/**
|
|
884
|
-
*
|
|
885
|
-
*
|
|
899
|
+
* Consulted only while `project.commands.test` is unset — then the close
|
|
900
|
+
* gate's argv is `npm test`, which runs `scripts.test`.
|
|
886
901
|
*
|
|
887
902
|
* @param {string} projectRoot
|
|
888
903
|
* @param {typeof fs.readFileSync} readFileImpl
|
|
@@ -930,23 +945,80 @@ function isCrapEnabled(projectRoot, readFileImpl) {
|
|
|
930
945
|
return enabled;
|
|
931
946
|
}
|
|
932
947
|
|
|
948
|
+
/**
|
|
949
|
+
* `project.commands.test` from `.agentrc.json` overlaid by
|
|
950
|
+
* `.agentrc.local.json` — the command close's `test` gate spawns. Read without
|
|
951
|
+
* `resolveConfig()` (built-ins only), like {@link isCrapEnabled}.
|
|
952
|
+
*
|
|
953
|
+
* @param {string} projectRoot
|
|
954
|
+
* @param {typeof fs.readFileSync} readFileImpl
|
|
955
|
+
* @returns {string|null} The configured command, or null when unset/default.
|
|
956
|
+
*/
|
|
957
|
+
function configuredTestCommand(projectRoot, readFileImpl) {
|
|
958
|
+
let command = null;
|
|
959
|
+
for (const file of ['.agentrc.json', '.agentrc.local.json']) {
|
|
960
|
+
const value = readJsonSafe(path.join(projectRoot, file), {
|
|
961
|
+
readFileSync: readFileImpl,
|
|
962
|
+
})?.project?.commands?.test;
|
|
963
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
964
|
+
command = value.trim();
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return command === DEFAULT_TEST_COMMAND ? null : command;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* A configured `project.commands.test` is what close spawns, so the analysis
|
|
972
|
+
* is of that command, never of `scripts.test`.
|
|
973
|
+
*
|
|
974
|
+
* @param {string} command
|
|
975
|
+
* @returns {{ detail: string, remedy?: string }}
|
|
976
|
+
*/
|
|
977
|
+
function describeConfiguredTestCommand(command) {
|
|
978
|
+
const lead = `\`project.commands.test\` sets close's \`test\` gate to \`${command}\``;
|
|
979
|
+
if (command.includes(MANDREL_TEST_RUNNER)) {
|
|
980
|
+
return {
|
|
981
|
+
detail: `${lead}, which reaches mandrel's runner — a green full run on a story branch deposits the close \`test\` credit itself`,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
const remedy = testCreditRemedy(command);
|
|
985
|
+
return {
|
|
986
|
+
detail: `${lead}, which deposits no close \`test\` credit by itself — ${remedy}`,
|
|
987
|
+
remedy,
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
|
|
933
991
|
/**
|
|
934
992
|
* Which depositor digest § 5 selects, stated with its exact command.
|
|
935
993
|
*
|
|
936
|
-
* @param {{ scripts: Record<string, string>, crapEnabled: boolean }} probe
|
|
994
|
+
* @param {{ scripts: Record<string, string>, crapEnabled: boolean, testCommand: string|null }} probe
|
|
937
995
|
* @returns {{ detail: string, remedy?: string }}
|
|
938
996
|
*/
|
|
939
|
-
function describeCreditedRun({ scripts, crapEnabled }) {
|
|
997
|
+
function describeCreditedRun({ scripts, crapEnabled, testCommand }) {
|
|
940
998
|
if (crapEnabled && scriptNamed(scripts, 'test:coverage') !== null) {
|
|
941
999
|
return {
|
|
942
1000
|
detail: `the CRAP gate is enabled and \`test:coverage\` exists, so close registers \`coverage-capture\` and the credited run is the coverage capture: \`${COVERAGE_CAPTURE_COMMAND}\` — its fresh stamp lets close's capture skip the suite`,
|
|
943
1001
|
};
|
|
944
1002
|
}
|
|
1003
|
+
return testCommand !== null
|
|
1004
|
+
? describeConfiguredTestCommand(testCommand)
|
|
1005
|
+
: describeNpmTestScript(scripts);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* With `project.commands.test` unset close spawns `npm test`, so the analysis
|
|
1010
|
+
* is of `scripts.test`.
|
|
1011
|
+
*
|
|
1012
|
+
* @param {Record<string, string>} scripts
|
|
1013
|
+
* @returns {{ detail: string, remedy?: string }}
|
|
1014
|
+
*/
|
|
1015
|
+
function describeNpmTestScript(scripts) {
|
|
1016
|
+
const remedy = testCreditRemedy(DEFAULT_TEST_COMMAND);
|
|
945
1017
|
const script = scriptNamed(scripts, 'test');
|
|
946
1018
|
if (script === null) {
|
|
947
1019
|
return {
|
|
948
|
-
detail: `no \`test\` script in package.json — close still spawns \`npm test\`, so ${
|
|
949
|
-
remedy
|
|
1020
|
+
detail: `no \`test\` script in package.json — close still spawns \`npm test\`, so ${remedy}`,
|
|
1021
|
+
remedy,
|
|
950
1022
|
};
|
|
951
1023
|
}
|
|
952
1024
|
if (script.includes(MANDREL_TEST_RUNNER)) {
|
|
@@ -955,8 +1027,8 @@ function describeCreditedRun({ scripts, crapEnabled }) {
|
|
|
955
1027
|
};
|
|
956
1028
|
}
|
|
957
1029
|
return {
|
|
958
|
-
detail: `\`npm test\` → \`${script}\` is this project's own runner and never reaches \`${MANDREL_TEST_RUNNER}\`, so it deposits no close \`test\` credit and prints nothing — ${
|
|
959
|
-
remedy
|
|
1030
|
+
detail: `\`npm test\` → \`${script}\` is this project's own runner and never reaches \`${MANDREL_TEST_RUNNER}\`, so it deposits no close \`test\` credit and prints nothing — ${remedy}`,
|
|
1031
|
+
remedy,
|
|
960
1032
|
};
|
|
961
1033
|
}
|
|
962
1034
|
|
|
@@ -1020,6 +1092,7 @@ function runTestCreditPath({ projectRoot, readFile = fs.readFileSync } = {}) {
|
|
|
1020
1092
|
describeCreditedRun({
|
|
1021
1093
|
scripts: readProjectScripts(root, readFile),
|
|
1022
1094
|
crapEnabled: isCrapEnabled(root, readFile),
|
|
1095
|
+
testCommand: configuredTestCommand(root, readFile),
|
|
1023
1096
|
}),
|
|
1024
1097
|
describePrePushHook(root, readFile),
|
|
1025
1098
|
];
|
package/lib/cli/uninstall.js
CHANGED
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
BOOTSTRAP_COMMAND,
|
|
22
22
|
GITIGNORE_BLOCKS,
|
|
23
|
+
LEGACY_PREPARE_COMMAND,
|
|
24
|
+
PREPARE_COMMAND,
|
|
23
25
|
SYNC_COMMAND,
|
|
24
26
|
SYSTEM_PROMPT_AGENTS_MD,
|
|
25
27
|
SYSTEM_PROMPT_BLOCK,
|
|
@@ -297,6 +299,33 @@ function revertGitignore(projectRoot, fsImpl) {
|
|
|
297
299
|
return { kind: 'reverted', target: rel, detail };
|
|
298
300
|
}
|
|
299
301
|
|
|
302
|
+
/** Every `prepare` value bootstrap writes whole: guarded, legacy pair, bare sync. */
|
|
303
|
+
const BOOTSTRAP_PREPARE_FORMS = new Set([
|
|
304
|
+
PREPARE_COMMAND,
|
|
305
|
+
LEGACY_PREPARE_COMMAND,
|
|
306
|
+
SYNC_COMMAND,
|
|
307
|
+
]);
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Strip the framework part of a `prepare`: a whole bootstrap-written form
|
|
311
|
+
* goes entirely; an operator command with the sync appended via ` && ` loses
|
|
312
|
+
* just that fragment. `next === ''` means delete the key, never write `""`.
|
|
313
|
+
*
|
|
314
|
+
* @param {unknown} prepare
|
|
315
|
+
* @returns {{ changed: boolean, next: string }}
|
|
316
|
+
*/
|
|
317
|
+
function stripPrepare(prepare) {
|
|
318
|
+
if (typeof prepare !== 'string' || !prepare.includes(SYNC_COMMAND)) {
|
|
319
|
+
return { changed: false, next: '' };
|
|
320
|
+
}
|
|
321
|
+
if (BOOTSTRAP_PREPARE_FORMS.has(prepare)) return { changed: true, next: '' };
|
|
322
|
+
const next = prepare
|
|
323
|
+
.replace(` && ${SYNC_COMMAND}`, '')
|
|
324
|
+
.replace(`${SYNC_COMMAND} && `, '')
|
|
325
|
+
.trim();
|
|
326
|
+
return { changed: next !== prepare, next };
|
|
327
|
+
}
|
|
328
|
+
|
|
300
329
|
/**
|
|
301
330
|
* @param {string} projectRoot
|
|
302
331
|
* @param {typeof fs} fsImpl
|
|
@@ -319,27 +348,14 @@ function revertPackageJson(projectRoot, fsImpl) {
|
|
|
319
348
|
removed.push(name);
|
|
320
349
|
}
|
|
321
350
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (typeof prepare === 'string' && prepare.includes(SYNC_COMMAND)) {
|
|
326
|
-
if (prepare === SYNC_COMMAND) {
|
|
351
|
+
const prepare = stripPrepare(pkg.scripts.prepare);
|
|
352
|
+
if (prepare.changed) {
|
|
353
|
+
if (prepare.next === '') {
|
|
327
354
|
delete pkg.scripts.prepare;
|
|
328
|
-
removed.push('prepare');
|
|
329
355
|
} else {
|
|
330
|
-
|
|
331
|
-
.replace(` && ${SYNC_COMMAND}`, '')
|
|
332
|
-
.replace(`${SYNC_COMMAND} && `, '')
|
|
333
|
-
.trim();
|
|
334
|
-
if (stripped !== prepare) {
|
|
335
|
-
if (stripped === '') {
|
|
336
|
-
delete pkg.scripts.prepare;
|
|
337
|
-
} else {
|
|
338
|
-
pkg.scripts.prepare = stripped;
|
|
339
|
-
}
|
|
340
|
-
removed.push('prepare');
|
|
341
|
-
}
|
|
356
|
+
pkg.scripts.prepare = prepare.next;
|
|
342
357
|
}
|
|
358
|
+
removed.push('prepare');
|
|
343
359
|
}
|
|
344
360
|
if (removed.length === 0) {
|
|
345
361
|
return { kind: 'skipped', target: rel, detail: 'no framework scripts' };
|
package/lib/cli/update.js
CHANGED
|
@@ -22,6 +22,7 @@ import { defaultResolvePackageRoot } from './sync.js';
|
|
|
22
22
|
import { isStale } from './version-check.js';
|
|
23
23
|
import {
|
|
24
24
|
compareVersions,
|
|
25
|
+
resolveConsumerPinSpec,
|
|
25
26
|
resolveConsumerPinVersion,
|
|
26
27
|
} from './version-helpers.js';
|
|
27
28
|
|
|
@@ -196,22 +197,43 @@ function probePackageManager(cwd, fs = nodeFs) {
|
|
|
196
197
|
return detectPackageManagerWithWorkspace(cwd, exists);
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
/**
|
|
201
|
+
* The save flag and spec that keep the consumer's pin style: an exact pin
|
|
202
|
+
* gains the manager's save-exact flag, a tilde rides in the spec (which all
|
|
203
|
+
* three managers record as-is), and caret or unknown keeps the bare spec.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} target
|
|
206
|
+
* @param {'pnpm' | 'yarn' | 'npm'} packageManager
|
|
207
|
+
* @param {'^' | '~' | '' | null} pinOperator
|
|
208
|
+
* @returns {{ exact: string, spec: string }}
|
|
209
|
+
*/
|
|
210
|
+
function pinPreservingSpec(target, packageManager, pinOperator) {
|
|
211
|
+
const exactFlag = packageManager === 'yarn' ? '--exact' : '--save-exact';
|
|
212
|
+
return {
|
|
213
|
+
exact: pinOperator === '' ? ` ${exactFlag}` : '',
|
|
214
|
+
spec: `${PACKAGE_NAME}@${pinOperator === '~' ? '~' : ''}${target}`,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
199
218
|
/**
|
|
200
219
|
* The install command. An `--install-cmd` override is used verbatim except
|
|
201
|
-
* that `{target}` is replaced with the resolved semver.
|
|
220
|
+
* that `{target}` is replaced with the resolved semver. Otherwise the
|
|
221
|
+
* consumer's current pin operator decides the save style: exact keeps an
|
|
222
|
+
* exact pin, tilde keeps a tilde, and caret or unknown keeps today's form.
|
|
202
223
|
*
|
|
203
224
|
* @param {string} target
|
|
204
225
|
* @param {string} [override]
|
|
205
226
|
* @param {{
|
|
206
227
|
* packageManager?: 'pnpm' | 'yarn' | 'npm',
|
|
207
228
|
* workspaceRoot?: boolean,
|
|
229
|
+
* pinOperator?: '^' | '~' | '' | null,
|
|
208
230
|
* }} [detected]
|
|
209
231
|
* @returns {string}
|
|
210
232
|
*/
|
|
211
233
|
export function resolveInstallCmd(
|
|
212
234
|
target,
|
|
213
235
|
override,
|
|
214
|
-
{ packageManager = 'npm', workspaceRoot = false } = {},
|
|
236
|
+
{ packageManager = 'npm', workspaceRoot = false, pinOperator = null } = {},
|
|
215
237
|
) {
|
|
216
238
|
const trimmed = String(override ?? '').trim();
|
|
217
239
|
if (trimmed.length > 0) {
|
|
@@ -219,13 +241,18 @@ export function resolveInstallCmd(
|
|
|
219
241
|
? trimmed.replaceAll('{target}', target)
|
|
220
242
|
: trimmed;
|
|
221
243
|
}
|
|
244
|
+
const { exact, spec } = pinPreservingSpec(
|
|
245
|
+
target,
|
|
246
|
+
packageManager,
|
|
247
|
+
pinOperator,
|
|
248
|
+
);
|
|
222
249
|
if (packageManager === 'pnpm') {
|
|
223
|
-
return `pnpm add -D
|
|
250
|
+
return `pnpm add -D${exact} ${spec}${workspaceRoot ? ' -w' : ''}`;
|
|
224
251
|
}
|
|
225
252
|
if (packageManager === 'yarn') {
|
|
226
|
-
return `yarn add -D
|
|
253
|
+
return `yarn add -D${exact} ${spec}`;
|
|
227
254
|
}
|
|
228
|
-
return `npm install
|
|
255
|
+
return `npm install${exact} ${spec}`;
|
|
229
256
|
}
|
|
230
257
|
|
|
231
258
|
const LOCKFILE_BY_PACKAGE_MANAGER = {
|
|
@@ -461,7 +488,11 @@ export function defaultNpmUpdate(
|
|
|
461
488
|
} = {},
|
|
462
489
|
) {
|
|
463
490
|
const detected = detectPackageManager(cwd, fs);
|
|
464
|
-
const
|
|
491
|
+
const pinOperator = resolveConsumerPinSpec(cwd, fs)?.operator ?? null;
|
|
492
|
+
const cmd = resolveInstallCmd(target, installCmd, {
|
|
493
|
+
...detected,
|
|
494
|
+
pinOperator,
|
|
495
|
+
});
|
|
465
496
|
const repairHint =
|
|
466
497
|
`\n → If node_modules looks wrong, run \`${repairInstallCommand(detected.packageManager)}\`` +
|
|
467
498
|
' to restore it to a consistent state.';
|
package/lib/migrations/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { retireAuditResultsAutoFile } from './steps/2.60.0-retire-audit-results-
|
|
|
18
18
|
import { baselineMergeQueueShape } from './steps/2.63.0-baseline-merge-queue-shape.js';
|
|
19
19
|
import { foldClaudeMdIntoAgentsMdStep } from './steps/2.65.0-fold-claude-md-into-agents-md.js';
|
|
20
20
|
import { retireAuditLedger } from './steps/2.70.0-retire-audit-ledger.js';
|
|
21
|
+
import { containerSafeProjections } from './steps/2.79.0-container-safe-projections.js';
|
|
21
22
|
import { stripRemovedAgentrcKeys } from './steps/strip-removed-agentrc-keys.js';
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -44,6 +45,7 @@ export const migrations = [
|
|
|
44
45
|
baselineMergeQueueShape,
|
|
45
46
|
foldClaudeMdIntoAgentsMdStep,
|
|
46
47
|
retireAuditLedger,
|
|
48
|
+
containerSafeProjections,
|
|
47
49
|
];
|
|
48
50
|
|
|
49
51
|
export { compareVersions };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// lib/migrations/steps/2.79.0-container-safe-projections.js
|
|
2
|
+
/**
|
|
3
|
+
* Bring an existing consumer's bootstrap footprint to the container-safe
|
|
4
|
+
* shape: upgrade the legacy unguarded `prepare` to the guarded
|
|
5
|
+
* form, and add the `.claude/agents/` ignore entry. Reuses the bootstrap's own
|
|
6
|
+
* helpers so a migrated tree matches a fresh bootstrap byte for byte. An
|
|
7
|
+
* operator-customised `prepare` is never touched.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import nodeFs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
ensureGitignore,
|
|
15
|
+
ensurePrepareScript,
|
|
16
|
+
GITIGNORE_BLOCKS,
|
|
17
|
+
LEGACY_PREPARE_COMMAND,
|
|
18
|
+
} from '../../../.agents/scripts/lib/bootstrap/project-bootstrap.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} root
|
|
22
|
+
* @param {typeof nodeFs} fsImpl
|
|
23
|
+
* @returns {{ pkgPath: string, pkg: object | null }}
|
|
24
|
+
*/
|
|
25
|
+
function readPackageJson(root, fsImpl) {
|
|
26
|
+
const pkgPath = path.join(root, 'package.json');
|
|
27
|
+
if (!fsImpl.existsSync(pkgPath)) return { pkgPath, pkg: null };
|
|
28
|
+
try {
|
|
29
|
+
return { pkgPath, pkg: JSON.parse(fsImpl.readFileSync(pkgPath, 'utf8')) };
|
|
30
|
+
} catch {
|
|
31
|
+
return { pkgPath, pkg: null };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} root
|
|
37
|
+
* @param {typeof nodeFs} fsImpl
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function hasLegacyPrepare(root, fsImpl) {
|
|
41
|
+
const { pkg } = readPackageJson(root, fsImpl);
|
|
42
|
+
return pkg?.scripts?.prepare === LEGACY_PREPARE_COMMAND;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} root
|
|
47
|
+
* @param {typeof nodeFs} fsImpl
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
function lacksAgentsIgnore(root, fsImpl) {
|
|
51
|
+
const target = path.join(root, '.gitignore');
|
|
52
|
+
const body = fsImpl.existsSync(target)
|
|
53
|
+
? fsImpl.readFileSync(target, 'utf8')
|
|
54
|
+
: '';
|
|
55
|
+
return !GITIGNORE_BLOCKS.agents.pattern.test(body);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const containerSafeProjections = {
|
|
59
|
+
version: '2.79.0',
|
|
60
|
+
description:
|
|
61
|
+
'guard the bootstrap `prepare` so a manifest-only container `npm ci` ' +
|
|
62
|
+
'skips the projections, and gitignore the generated .claude/agents/ ' +
|
|
63
|
+
'(Story #5581)',
|
|
64
|
+
/**
|
|
65
|
+
* @param {{ projectRoot?: string, fs?: typeof nodeFs }} [ctx]
|
|
66
|
+
* @param {typeof nodeFs} [fsImpl]
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
detect(ctx, fsImpl = ctx?.fs ?? nodeFs) {
|
|
70
|
+
const root = ctx?.projectRoot ?? process.cwd();
|
|
71
|
+
return hasLegacyPrepare(root, fsImpl) || lacksAgentsIgnore(root, fsImpl);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* @param {{ projectRoot?: string, fs?: typeof nodeFs }} [ctx]
|
|
75
|
+
* @param {typeof nodeFs} [fsImpl]
|
|
76
|
+
* @returns {void}
|
|
77
|
+
*/
|
|
78
|
+
apply(ctx, fsImpl = ctx?.fs ?? nodeFs) {
|
|
79
|
+
const root = ctx?.projectRoot ?? process.cwd();
|
|
80
|
+
if (hasLegacyPrepare(root, fsImpl)) {
|
|
81
|
+
const { pkgPath, pkg } = readPackageJson(root, fsImpl);
|
|
82
|
+
ensurePrepareScript(pkg.scripts);
|
|
83
|
+
fsImpl.writeFileSync(
|
|
84
|
+
pkgPath,
|
|
85
|
+
`${JSON.stringify(pkg, null, 2)}\n`,
|
|
86
|
+
'utf8',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
ensureGitignore({ projectRoot: root, fsImpl }, ['agents']);
|
|
90
|
+
},
|
|
91
|
+
};
|
package/package.json
CHANGED