@timekast/factory 0.1.4 → 0.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.
- package/dist/commands/update.js +17 -4
- package/dist/lib/package-json.js +25 -0
- package/package.json +1 -1
package/dist/commands/update.js
CHANGED
|
@@ -37,7 +37,7 @@ import prompts from 'prompts';
|
|
|
37
37
|
import { applyPlan, clearUpdateState, defaultBackupDir, hasUpdateState, readUpdateState, validateStagedManifest, writeUpdateState, } from '../lib/atomic-swap.js';
|
|
38
38
|
import { CLIError } from '../lib/cli-error.js';
|
|
39
39
|
import { diffLockfiles, hasLockfile, normalizeThenHash, planAutoRegister, readLockfile, writeLockfile, } from '../lib/lockfile.js';
|
|
40
|
-
import { insertFactoryUpdateScript } from '../lib/package-json.js';
|
|
40
|
+
import { insertFactoryUpdateScript, setAgentKitVersion } from '../lib/package-json.js';
|
|
41
41
|
import { runPreflight } from '../lib/preflight.js';
|
|
42
42
|
import { downloadProfileTarball, stageProfileTarball } from '../lib/unpack.js';
|
|
43
43
|
/** Parse `update`'s argv slice into flags. Unknown flags are ignored here. */
|
|
@@ -186,7 +186,7 @@ function runResume(rootDir) {
|
|
|
186
186
|
clearUpdateState(rootDir);
|
|
187
187
|
const pkgPath = path.join(rootDir, 'package.json');
|
|
188
188
|
if (existsSync(pkgPath))
|
|
189
|
-
|
|
189
|
+
maintainDerivedPkg(pkgPath, newLock.version);
|
|
190
190
|
rmSync(state.stagedDir, { recursive: true, force: true });
|
|
191
191
|
console.log('✔ `update` retomado y completado.');
|
|
192
192
|
}
|
|
@@ -206,6 +206,19 @@ function warnOnScriptConflict(action, _pkgPath) {
|
|
|
206
206
|
console.warn('Aviso: `factory:update` ya existe en package.json con otro valor; no se sobrescribió.');
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* After a sync, maintain the derived project's package.json: ensure the
|
|
211
|
+
* `factory:update` script (warn on a divergent value) and set `agentKitVersion`
|
|
212
|
+
* to the just-installed brain version, mirroring the lockfile's `version`. Run on
|
|
213
|
+
* every update, so the field tracks each `factory:update` (and a derivative whose
|
|
214
|
+
* field was missing or stale gets reconciled — same shape as the Factory's own
|
|
215
|
+
* package.json). `factoryVersion` (the frozen birth stamp) and `version` (the app
|
|
216
|
+
* semver) are untouched.
|
|
217
|
+
*/
|
|
218
|
+
function maintainDerivedPkg(pkgPath, agentKitVersion) {
|
|
219
|
+
warnOnScriptConflict(insertFactoryUpdateScript(pkgPath).action, pkgPath);
|
|
220
|
+
setAgentKitVersion(pkgPath, agentKitVersion);
|
|
221
|
+
}
|
|
209
222
|
/** Print the deletes + kept-retired (design §7.6 — visible) + a one-line summary. */
|
|
210
223
|
function reportSummary(diff) {
|
|
211
224
|
if (diff.deleteSilent.length > 0) {
|
|
@@ -300,7 +313,7 @@ export async function runUpdate(flags, deps = {}) {
|
|
|
300
313
|
clearUpdateState(rootDir);
|
|
301
314
|
const pkgPath = path.join(rootDir, 'package.json');
|
|
302
315
|
if (existsSync(pkgPath))
|
|
303
|
-
|
|
316
|
+
maintainDerivedPkg(pkgPath, manifest.version);
|
|
304
317
|
reportSummary(diff);
|
|
305
318
|
}
|
|
306
319
|
finally {
|
|
@@ -340,7 +353,7 @@ async function applyLegacy(rootDir, stagedDir, manifest) {
|
|
|
340
353
|
writeLockfile(rootDir, { ...manifest, factoryVersion: manifest.version });
|
|
341
354
|
const pkgPath = path.join(rootDir, 'package.json');
|
|
342
355
|
if (existsSync(pkgPath))
|
|
343
|
-
|
|
356
|
+
maintainDerivedPkg(pkgPath, manifest.version);
|
|
344
357
|
if (plan.ambiguous.length > 0) {
|
|
345
358
|
console.log('\nArchivos en `.claude/` que no están en el manifest (revisar manualmente):');
|
|
346
359
|
for (const p of plan.ambiguous)
|
package/dist/lib/package-json.js
CHANGED
|
@@ -88,3 +88,28 @@ export function insertFactoryUpdateScript(pkgPath) {
|
|
|
88
88
|
}
|
|
89
89
|
return result;
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Surgically set the derived project's `package.json.agentKitVersion` to the
|
|
93
|
+
* installed brain version, mirroring the lockfile's `version`. The Factory's own
|
|
94
|
+
* `package.json` carries `agentKitVersion` and bumps it on every release; a
|
|
95
|
+
* derivative mirrors it so its `package.json` shows the live brain version and
|
|
96
|
+
* stays consistent with the Factory's shape. `update` calls this on every run, so
|
|
97
|
+
* the field tracks each `factory:update` — and a derivative whose field was missing
|
|
98
|
+
* or stale gets reconciled. Reads, sets only that key, re-serializes with the
|
|
99
|
+
* original indentation, and writes only when the value changed. NEVER touches
|
|
100
|
+
* `name`, `version` (the app semver), `factoryVersion` (birth stamp), deps, or scripts.
|
|
101
|
+
*
|
|
102
|
+
* @param pkgPath Absolute path to the derived project's `package.json`.
|
|
103
|
+
* @param version The installed brain version (= the lockfile's `version`).
|
|
104
|
+
* @returns true when the field changed (and the file was rewritten).
|
|
105
|
+
*/
|
|
106
|
+
export function setAgentKitVersion(pkgPath, version) {
|
|
107
|
+
const raw = readFileSync(pkgPath, 'utf8');
|
|
108
|
+
const indent = detectIndent(raw);
|
|
109
|
+
const pkg = parsePackageJson(raw);
|
|
110
|
+
if (pkg.agentKitVersion === version)
|
|
111
|
+
return false;
|
|
112
|
+
pkg.agentKitVersion = version;
|
|
113
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, indent)}\n`, 'utf8');
|
|
114
|
+
return true;
|
|
115
|
+
}
|