@mindexed/cfact 1.1.4 → 1.1.7
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/bin/cfact.js +111 -28
- package/package.json +13 -2
package/bin/cfact.js
CHANGED
|
@@ -1265,6 +1265,113 @@ function extractTarball(tarball, destDir) {
|
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
1267
1267
|
// --- the two commands -------------------------------------------------------
|
|
1268
|
+
// Windows (and any host that locks an open directory) refuses to rename a tree another process holds a handle in.
|
|
1269
|
+
// Node surfaces it as one of these codes depending on the API and the lock; all three mean "something has it open".
|
|
1270
|
+
// The holder is NOT a fixed program (CHG-296, FF-392): the measured one was a running dev server and its desktop app, both
|
|
1271
|
+
// reading the project's engine, while the earlier wording blamed Claude Code and cost several failed runs and a needless
|
|
1272
|
+
// session restart. The installer cannot name the holder, so it lists the likely kinds and, on Windows, says how to find it.
|
|
1273
|
+
const CLOSE_AND_RERUN = 'Likely holders: a dev server or desktop app that reads .claude/engine, an editor with a file from it open, or a terminal whose current directory is inside it. Stop or close whichever applies, then re-run this command.';
|
|
1274
|
+
const LOCK_ERROR_CODES = new Set(['EPERM', 'EBUSY', 'EACCES']);
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* Extra guidance for finding the holder, platform-specific. Windows only: Resource Monitor is the tool that can name the
|
|
1278
|
+
* process, and npx.ps1 being refused by the default PowerShell execution policy stops the documented one-liner before the
|
|
1279
|
+
* installer starts, so the re-run advice offers npx.cmd. `platform` is a parameter so it is testable off Windows.
|
|
1280
|
+
*/
|
|
1281
|
+
function lockHolderGuidance(platform = process.platform) {
|
|
1282
|
+
if (platform !== 'win32') return '';
|
|
1283
|
+
return ' To find the holder: Resource Monitor > CPU > Associated Handles, search for "engine". If PowerShell refuses to run npx (npx.ps1 blocked by the execution policy), run the same command with npx.cmd instead.';
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* True when `e` is the "another program holds this directory open" family of errors (CHG-288, FF-389).
|
|
1288
|
+
* Exported so the classification is testable without a Windows machine.
|
|
1289
|
+
*/
|
|
1290
|
+
function isLockError(e) {
|
|
1291
|
+
return Boolean(e) && LOCK_ERROR_CODES.has(e.code);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Install a staged engine tree at `enginePath` WITHOUT ever leaving the consumer with no engine, and without leaving
|
|
1296
|
+
* residue behind on any failure path (CHG-288, FF-389).
|
|
1297
|
+
*
|
|
1298
|
+
* The cross-device copy (stageDir lives in os.tmpdir(), usually a different filesystem) is the failure-prone part —
|
|
1299
|
+
* disk-full, permissions — so it happens to a sibling of enginePath BEFORE the old engine is touched. After that the
|
|
1300
|
+
* swap is same-filesystem renames (atomic, no partial state), and a failed final rename restores the backup. Deleting
|
|
1301
|
+
* the old engine first (as an earlier version did) risked a mid-copy failure leaving nothing behind.
|
|
1302
|
+
*
|
|
1303
|
+
* The first rename moves the CURRENT engine aside. On Windows it throws EPERM while any program (a dev server, a desktop
|
|
1304
|
+
* app, an editor, a terminal) holds a handle inside `.claude/engine`; it was unguarded, so the consumer got a raw stack and a stray untracked
|
|
1305
|
+
* `.claude/.engine.incoming`. It is now translated into the one instruction that fixes it, and the failure leaves the
|
|
1306
|
+
* old engine untouched (the rename never happened) and the staging directories removed. A translated catch rather than
|
|
1307
|
+
* a dry rename-and-restore probe, deliberately: a probe can succeed and the real rename still fail (a handle opened in
|
|
1308
|
+
* between), and a probe whose restore half fails is exactly the "no engine" state this function exists to avoid.
|
|
1309
|
+
*
|
|
1310
|
+
* `fsImpl` is injectable so the failure paths are testable without a locked directory.
|
|
1311
|
+
*/
|
|
1312
|
+
function installStagedEngine({ enginePath, stageDir, tmpDir, fsImpl = fs, platform = process.platform }) {
|
|
1313
|
+
const engineParent = path.dirname(enginePath);
|
|
1314
|
+
const incoming = path.join(engineParent, '.engine.incoming');
|
|
1315
|
+
const backup = path.join(engineParent, '.engine.backup');
|
|
1316
|
+
const quietRm = (target) => {
|
|
1317
|
+
try { fsImpl.rmSync(target, { recursive: true, force: true }); } catch { /* best effort: never mask the real error */ }
|
|
1318
|
+
};
|
|
1319
|
+
const abort = (message) => {
|
|
1320
|
+
quietRm(incoming);
|
|
1321
|
+
quietRm(tmpDir);
|
|
1322
|
+
die(message);
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
try {
|
|
1326
|
+
fsImpl.rmSync(incoming, { recursive: true, force: true });
|
|
1327
|
+
fsImpl.rmSync(backup, { recursive: true, force: true });
|
|
1328
|
+
} catch (e) {
|
|
1329
|
+
abort(isLockError(e)
|
|
1330
|
+
? `cannot clear the leftovers of an earlier update next to ${enginePath} (${e.code}): another program holds them open. ${CLOSE_AND_RERUN}${lockHolderGuidance(platform)}`
|
|
1331
|
+
: `cannot clear the leftovers of an earlier update next to ${enginePath} — ${e.message}`);
|
|
1332
|
+
}
|
|
1333
|
+
try {
|
|
1334
|
+
fsImpl.renameSync(stageDir, incoming); // same-fs fast path
|
|
1335
|
+
} catch {
|
|
1336
|
+
try {
|
|
1337
|
+
fsImpl.cpSync(stageDir, incoming, { recursive: true }); // cross-device fallback
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
abort(`could not stage the new engine next to ${enginePath} — ${e.message}. Your current engine was not touched.`);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
const hadOld = fsImpl.existsSync(enginePath);
|
|
1343
|
+
if (hadOld) {
|
|
1344
|
+
try {
|
|
1345
|
+
fsImpl.renameSync(enginePath, backup);
|
|
1346
|
+
} catch (e) {
|
|
1347
|
+
abort(isLockError(e)
|
|
1348
|
+
? `cannot replace ${enginePath} (${e.code}): another program is holding it open. ${CLOSE_AND_RERUN}${lockHolderGuidance(platform)}${e.code === 'EACCES' ? ' (EACCES can also mean you lack write permission on .claude/; if closing them changes nothing, check that.)' : ''} Your current engine was not touched.`
|
|
1349
|
+
: `cannot move the current engine aside — ${e.message}. Your current engine was not touched.`);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
try {
|
|
1353
|
+
fsImpl.renameSync(incoming, enginePath);
|
|
1354
|
+
} catch (e) {
|
|
1355
|
+
if (hadOld) {
|
|
1356
|
+
try {
|
|
1357
|
+
fsImpl.renameSync(backup, enginePath); // restore the old engine
|
|
1358
|
+
} catch (restoreErr) {
|
|
1359
|
+
quietRm(incoming);
|
|
1360
|
+
die(`failed to install the new engine AND could not restore the old one (${restoreErr.message}). Your previous engine is at ${backup} — rename it back to ${enginePath} before doing anything else.`);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
abort(`failed to install the new engine (old engine restored) — ${e.message}`);
|
|
1364
|
+
}
|
|
1365
|
+
try {
|
|
1366
|
+
fsImpl.rmSync(backup, { recursive: true, force: true });
|
|
1367
|
+
} catch (e) {
|
|
1368
|
+
// The new engine is already in place; failing the run over a leftover would lie about what happened.
|
|
1369
|
+
console.warn(`⚠️ claude-factory: the update succeeded, but ${backup} could not be removed (${e.code || e.message}). Delete it by hand once nothing holds it open.`);
|
|
1370
|
+
}
|
|
1371
|
+
quietRm(tmpDir);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
|
|
1268
1375
|
async function materialise(opts) {
|
|
1269
1376
|
const consumerRoot = path.resolve(opts.consumer || process.cwd());
|
|
1270
1377
|
if (!fs.existsSync(path.join(consumerRoot, '.claude'))) {
|
|
@@ -1396,34 +1503,7 @@ async function materialise(opts) {
|
|
|
1396
1503
|
die('extracted tarball has no matrix.json at its root — it is not a valid engine tarball.');
|
|
1397
1504
|
}
|
|
1398
1505
|
|
|
1399
|
-
|
|
1400
|
-
// The cross-device copy (stageDir lives in os.tmpdir(), usually a different
|
|
1401
|
-
// filesystem) is the failure-prone part — disk-full, permissions — so it must
|
|
1402
|
-
// happen to a sibling of enginePath BEFORE the old engine is touched. After
|
|
1403
|
-
// that, the swap is same-filesystem renames (atomic, no partial state), and a
|
|
1404
|
-
// failed final rename restores the backup. Deleting the old engine first (as
|
|
1405
|
-
// an earlier version did) risked a mid-copy failure leaving nothing behind.
|
|
1406
|
-
const engineParent = path.dirname(enginePath);
|
|
1407
|
-
const incoming = path.join(engineParent, '.engine.incoming');
|
|
1408
|
-
const backup = path.join(engineParent, '.engine.backup');
|
|
1409
|
-
fs.rmSync(incoming, { recursive: true, force: true });
|
|
1410
|
-
fs.rmSync(backup, { recursive: true, force: true });
|
|
1411
|
-
try {
|
|
1412
|
-
fs.renameSync(stageDir, incoming); // same-fs fast path
|
|
1413
|
-
} catch {
|
|
1414
|
-
fs.cpSync(stageDir, incoming, { recursive: true }); // cross-device fallback
|
|
1415
|
-
}
|
|
1416
|
-
const hadOld = fs.existsSync(enginePath);
|
|
1417
|
-
if (hadOld) fs.renameSync(enginePath, backup);
|
|
1418
|
-
try {
|
|
1419
|
-
fs.renameSync(incoming, enginePath);
|
|
1420
|
-
} catch (e) {
|
|
1421
|
-
if (hadOld) fs.renameSync(backup, enginePath); // restore the old engine
|
|
1422
|
-
fs.rmSync(incoming, { recursive: true, force: true });
|
|
1423
|
-
die(`failed to install the new engine (old engine restored) — ${e.message}`);
|
|
1424
|
-
}
|
|
1425
|
-
fs.rmSync(backup, { recursive: true, force: true });
|
|
1426
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
1506
|
+
installStagedEngine({ enginePath, stageDir, tmpDir });
|
|
1427
1507
|
|
|
1428
1508
|
// THE PIN RECORDS THE RELEASE THAT WAS FETCHED, NOT THE ENGINE'S MATRIX
|
|
1429
1509
|
// VERSION (ADR-0128). These used to be the same string, so reading the
|
|
@@ -1714,4 +1794,7 @@ module.exports = {
|
|
|
1714
1794
|
engineMatrixVersion,
|
|
1715
1795
|
describeUpdateOutcome,
|
|
1716
1796
|
requiredNextSteps,
|
|
1797
|
+
isLockError,
|
|
1798
|
+
lockHolderGuidance,
|
|
1799
|
+
installStagedEngine,
|
|
1717
1800
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindexed/cfact",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Clean Orthogonal Architecture Software Factory Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"claude-factory": "bin/cfact.js",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"test:parse-ast": "node skills/ast-parser/scripts/test-parse-ast.js",
|
|
53
53
|
"test:git-tree-sweep": "node scripts/test-git-tree-sweep.js",
|
|
54
54
|
"test:secrets-two-stage": "node scripts/test-secrets-two-stage.js",
|
|
55
|
+
"test:migration-grants-check": "node scripts/test-migration-grants-check.js",
|
|
55
56
|
"test:profile-paths": "node scripts/verify-profiles.js",
|
|
56
57
|
"test:registry-gate": "node scripts/test-registry-gate.js",
|
|
57
58
|
"test:rule-resolver": "node scripts/test-rule-resolver.js",
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
"test:engine-host": "node scripts/test-engine-host.js",
|
|
70
71
|
"test:zone-coverage": "node scripts/test-zone-coverage.js",
|
|
71
72
|
"test:workflow-spine": "node scripts/test-workflow-spine.js",
|
|
73
|
+
"test:architecture-size-gate": "node scripts/test-architecture-size-gate.js",
|
|
72
74
|
"test:command-shape": "node scripts/test-command-shape.js",
|
|
73
75
|
"test:change-record": "node scripts/test-change-record.js",
|
|
74
76
|
"test:artifact-timestamps": "node scripts/test-artifact-timestamps.js",
|
|
@@ -84,6 +86,7 @@
|
|
|
84
86
|
"test:feature-v2-switch": "node scripts/test-feature-v2-switch.js",
|
|
85
87
|
"test:feature-completeness": "node scripts/test-feature-completeness.js",
|
|
86
88
|
"test:feature-history": "node scripts/test-feature-history.js",
|
|
89
|
+
"test:feature-rekey": "node scripts/test-feature-rekey.js",
|
|
87
90
|
"test:agent-note-dispatch": "node scripts/test-agent-note-dispatch.js",
|
|
88
91
|
"test:check-record-text": "node scripts/test-check-record-text.js",
|
|
89
92
|
"test:feature-write-guard": "node scripts/test-feature-write-guard.js",
|
|
@@ -110,18 +113,26 @@
|
|
|
110
113
|
"test:npm-deprecation": "node scripts/test-npm-deprecation.js",
|
|
111
114
|
"test:generate-erd": "node scripts/test-generate-erd.js",
|
|
112
115
|
"test:surfaces-layerpaths": "node scripts/test-surfaces-layerpaths.js",
|
|
116
|
+
"test:surfaces-hostmodules": "node scripts/test-surfaces-hostmodules.js",
|
|
113
117
|
"test:list-feature-files": "node scripts/test-list-feature-files.js",
|
|
114
118
|
"test:generate-project-analysis": "node scripts/test-generate-project-analysis.js",
|
|
115
119
|
"test:generate-feature-card": "node scripts/test-generate-feature-card.js",
|
|
116
120
|
"test:generate-codex-agents": "node scripts/test-generate-codex-agents.js",
|
|
117
121
|
"test:context-subject": "node scripts/test-context-subject.js",
|
|
118
|
-
"test": "
|
|
122
|
+
"test:design-levels": "node scripts/test-design-levels.js",
|
|
123
|
+
"test:pre-push-unit-ref": "node scripts/test-pre-push-unit-ref.js",
|
|
124
|
+
"test:design-audit": "node scripts/test-design-audit.js",
|
|
125
|
+
"test:grants-definer-declaration": "node scripts/test-grants-definer-declaration.js",
|
|
126
|
+
"test:default-ship-pipeline": "node scripts/test-default-ship-pipeline.js",
|
|
127
|
+
"test:credential-slots": "node scripts/test-credential-slots.js",
|
|
128
|
+
"test": "npm run test:dc-generator && npm run test:substance-generator && npm run test:json-flush && npm run test:installer-exit && npm run test:installer-channel && npm run test:installer-update-messaging && npm run test:installer-wiring && npm run test:tar-invocation && npm run test:framework-agents-mcp && npm run test:controller-gates && npm run test:controller-single-file-attribution && npm run test:parse-ast && npm run test:git-tree-sweep && npm run test:secrets-two-stage && npm run test:migration-grants-check && npm run test:profile-paths && npm run test:registry-gate && npm run test:rule-resolver && npm run test:adr-template-edges && npm run test:adr-path-constants && npm run test:resolver-topology && npm run test:graph-strip && npm run test:graph-registry && npm run test:graph-memory-substrate && npm run test:document-freshness && npm run test:frontmatter-readers && npm run test:tarball-reproducible && npm run test:release-version && npm run test:consumer-checklist && npm run test:engine-host && npm run test:zone-coverage && npm run test:workflow-spine && npm run test:architecture-size-gate && npm run test:command-shape && npm run test:change-record && npm run test:engine-write-lock && npm run test:installer-publish-drift && npm run test:grants-authored && npm run test:test-capability && npm run test:installer-lifecycle && npm run test:gate-three-state && npm run test:refresh-compliance && npm run test:gate-coverage && npm run test:policy-lib && npm run test:validate-zone-denylist-bypass && npm run test:validate-zone-ledger-score && npm run test:rules-carrier-schema && npm run test:rule-record-schema && npm run test:rule-record-concerns-check && npm run test:external-standard-drift && npm run test:session-branch && npm run test:installer-shadowing && npm run test:feature-record && npm run test:feature-store && npm run test:feature-record-v2 && npm run test:feature-v2-switch && npm run test:feature-completeness && npm run test:feature-history && npm run test:feature-rekey && npm run test:agent-note-dispatch && npm run test:check-record-text && npm run test:consumer-docs-migration && npm run test:npm-deprecation && npm run test:sot-templates-pointer && npm run test:test-command-gate && npm run test:changelog-adr-refs && npm run test:generate-ci && npm run test:known-frictions-staleness && npm run test:artifact-timestamps && npm run test:generate-flow-map && npm run test:generate-zone-map && npm run test:generate-infra-map && npm run test:generate-legal-map && npm run test:generate-erd && npm run test:surfaces-layerpaths && npm run test:surfaces-hostmodules && npm run test:list-feature-files && npm run test:feature-write-guard && npm run test:context-subject && npm run test:generate-project-analysis && npm run test:generate-feature-card && npm run test:generate-codex-agents && npm run test:generate-agent-cards && npm run test:generate-framework-graph && npm run test:unrecorded-scope && npm run test:profile-reinstated-zones && npm run test:contract-claims && npm run test:plan-crosscheck && npm run test:consumer-alignment && npm run test:check-consumer-alignment && npm run test:design-levels && npm run test:pre-push-unit-ref && npm run test:design-audit && npm run test:grants-definer-declaration && npm run test:default-ship-pipeline && npm run test:credential-slots",
|
|
119
129
|
"test:test-command-gate": "node scripts/test-test-command-gate.js",
|
|
120
130
|
"test:changelog-adr-refs": "node scripts/test-changelog-adr-refs.js",
|
|
121
131
|
"test:known-frictions-staleness": "node scripts/test-known-frictions-staleness.js",
|
|
122
132
|
"test:generate-flow-map": "node scripts/test-generate-flow-map.js",
|
|
123
133
|
"test:generate-zone-map": "node scripts/test-generate-zone-map.js",
|
|
124
134
|
"test:generate-infra-map": "node scripts/test-generate-infra-map.js",
|
|
135
|
+
"test:generate-legal-map": "node scripts/test-generate-legal-map.js",
|
|
125
136
|
"test:generate-agent-cards": "node scripts/test-generate-agent-cards.js",
|
|
126
137
|
"test:generate-framework-graph": "node scripts/test-generate-framework-graph.js",
|
|
127
138
|
"test:unrecorded-scope": "node scripts/test-unrecorded-scope.js",
|