@mindexed/cfact 1.1.4 → 1.1.6

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.
Files changed (2) hide show
  1. package/bin/cfact.js +97 -28
  2. package/package.json +9 -2
package/bin/cfact.js CHANGED
@@ -1265,6 +1265,100 @@ 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
+ const CLOSE_AND_RERUN = 'Close Claude Code, Antigravity and any terminal or editor open inside .claude/engine, then re-run this command.';
1271
+ const LOCK_ERROR_CODES = new Set(['EPERM', 'EBUSY', 'EACCES']);
1272
+
1273
+ /**
1274
+ * True when `e` is the "another program holds this directory open" family of errors (CHG-288, FF-389).
1275
+ * Exported so the classification is testable without a Windows machine.
1276
+ */
1277
+ function isLockError(e) {
1278
+ return Boolean(e) && LOCK_ERROR_CODES.has(e.code);
1279
+ }
1280
+
1281
+ /**
1282
+ * Install a staged engine tree at `enginePath` WITHOUT ever leaving the consumer with no engine, and without leaving
1283
+ * residue behind on any failure path (CHG-288, FF-389).
1284
+ *
1285
+ * The cross-device copy (stageDir lives in os.tmpdir(), usually a different filesystem) is the failure-prone part —
1286
+ * disk-full, permissions — so it happens to a sibling of enginePath BEFORE the old engine is touched. After that the
1287
+ * swap is same-filesystem renames (atomic, no partial state), and a failed final rename restores the backup. Deleting
1288
+ * the old engine first (as an earlier version did) risked a mid-copy failure leaving nothing behind.
1289
+ *
1290
+ * The first rename moves the CURRENT engine aside. On Windows it throws EPERM while a Claude Code or Antigravity session
1291
+ * holds a handle inside `.claude/engine`; it was unguarded, so the consumer got a raw stack and a stray untracked
1292
+ * `.claude/.engine.incoming`. It is now translated into the one instruction that fixes it, and the failure leaves the
1293
+ * old engine untouched (the rename never happened) and the staging directories removed. A translated catch rather than
1294
+ * a dry rename-and-restore probe, deliberately: a probe can succeed and the real rename still fail (a handle opened in
1295
+ * between), and a probe whose restore half fails is exactly the "no engine" state this function exists to avoid.
1296
+ *
1297
+ * `fsImpl` is injectable so the failure paths are testable without a locked directory.
1298
+ */
1299
+ function installStagedEngine({ enginePath, stageDir, tmpDir, fsImpl = fs }) {
1300
+ const engineParent = path.dirname(enginePath);
1301
+ const incoming = path.join(engineParent, '.engine.incoming');
1302
+ const backup = path.join(engineParent, '.engine.backup');
1303
+ const quietRm = (target) => {
1304
+ try { fsImpl.rmSync(target, { recursive: true, force: true }); } catch { /* best effort: never mask the real error */ }
1305
+ };
1306
+ const abort = (message) => {
1307
+ quietRm(incoming);
1308
+ quietRm(tmpDir);
1309
+ die(message);
1310
+ };
1311
+
1312
+ try {
1313
+ fsImpl.rmSync(incoming, { recursive: true, force: true });
1314
+ fsImpl.rmSync(backup, { recursive: true, force: true });
1315
+ } catch (e) {
1316
+ abort(isLockError(e)
1317
+ ? `cannot clear the leftovers of an earlier update next to ${enginePath} (${e.code}): another program holds them open. ${CLOSE_AND_RERUN}`
1318
+ : `cannot clear the leftovers of an earlier update next to ${enginePath} — ${e.message}`);
1319
+ }
1320
+ try {
1321
+ fsImpl.renameSync(stageDir, incoming); // same-fs fast path
1322
+ } catch {
1323
+ try {
1324
+ fsImpl.cpSync(stageDir, incoming, { recursive: true }); // cross-device fallback
1325
+ } catch (e) {
1326
+ abort(`could not stage the new engine next to ${enginePath} — ${e.message}. Your current engine was not touched.`);
1327
+ }
1328
+ }
1329
+ const hadOld = fsImpl.existsSync(enginePath);
1330
+ if (hadOld) {
1331
+ try {
1332
+ fsImpl.renameSync(enginePath, backup);
1333
+ } catch (e) {
1334
+ abort(isLockError(e)
1335
+ ? `cannot replace ${enginePath} (${e.code}): another program is holding it open, most often a running Claude Code or Antigravity session. ${CLOSE_AND_RERUN}${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.`
1336
+ : `cannot move the current engine aside — ${e.message}. Your current engine was not touched.`);
1337
+ }
1338
+ }
1339
+ try {
1340
+ fsImpl.renameSync(incoming, enginePath);
1341
+ } catch (e) {
1342
+ if (hadOld) {
1343
+ try {
1344
+ fsImpl.renameSync(backup, enginePath); // restore the old engine
1345
+ } catch (restoreErr) {
1346
+ quietRm(incoming);
1347
+ 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.`);
1348
+ }
1349
+ }
1350
+ abort(`failed to install the new engine (old engine restored) — ${e.message}`);
1351
+ }
1352
+ try {
1353
+ fsImpl.rmSync(backup, { recursive: true, force: true });
1354
+ } catch (e) {
1355
+ // The new engine is already in place; failing the run over a leftover would lie about what happened.
1356
+ 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.`);
1357
+ }
1358
+ quietRm(tmpDir);
1359
+ }
1360
+
1361
+
1268
1362
  async function materialise(opts) {
1269
1363
  const consumerRoot = path.resolve(opts.consumer || process.cwd());
1270
1364
  if (!fs.existsSync(path.join(consumerRoot, '.claude'))) {
@@ -1396,34 +1490,7 @@ async function materialise(opts) {
1396
1490
  die('extracted tarball has no matrix.json at its root — it is not a valid engine tarball.');
1397
1491
  }
1398
1492
 
1399
- // Swap in the new engine WITHOUT ever leaving the consumer with no engine.
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 });
1493
+ installStagedEngine({ enginePath, stageDir, tmpDir });
1427
1494
 
1428
1495
  // THE PIN RECORDS THE RELEASE THAT WAS FETCHED, NOT THE ENGINE'S MATRIX
1429
1496
  // VERSION (ADR-0128). These used to be the same string, so reading the
@@ -1714,4 +1781,6 @@ module.exports = {
1714
1781
  engineMatrixVersion,
1715
1782
  describeUpdateOutcome,
1716
1783
  requiredNextSteps,
1784
+ isLockError,
1785
+ installStagedEngine,
1717
1786
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexed/cfact",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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",
@@ -110,12 +112,17 @@
110
112
  "test:npm-deprecation": "node scripts/test-npm-deprecation.js",
111
113
  "test:generate-erd": "node scripts/test-generate-erd.js",
112
114
  "test:surfaces-layerpaths": "node scripts/test-surfaces-layerpaths.js",
115
+ "test:surfaces-hostmodules": "node scripts/test-surfaces-hostmodules.js",
113
116
  "test:list-feature-files": "node scripts/test-list-feature-files.js",
114
117
  "test:generate-project-analysis": "node scripts/test-generate-project-analysis.js",
115
118
  "test:generate-feature-card": "node scripts/test-generate-feature-card.js",
116
119
  "test:generate-codex-agents": "node scripts/test-generate-codex-agents.js",
117
120
  "test:context-subject": "node scripts/test-context-subject.js",
118
- "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: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: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: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-erd && npm run test:surfaces-layerpaths && 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",
121
+ "test:design-levels": "node scripts/test-design-levels.js",
122
+ "test:pre-push-unit-ref": "node scripts/test-pre-push-unit-ref.js",
123
+ "test:design-audit": "node scripts/test-design-audit.js",
124
+ "test:grants-definer-declaration": "node scripts/test-grants-definer-declaration.js",
125
+ "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: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-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",
119
126
  "test:test-command-gate": "node scripts/test-test-command-gate.js",
120
127
  "test:changelog-adr-refs": "node scripts/test-changelog-adr-refs.js",
121
128
  "test:known-frictions-staleness": "node scripts/test-known-frictions-staleness.js",