harnessed 5.0.15 → 5.0.16
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/CHANGELOG.md +13 -0
- package/bin/harnessed-update-reminder-worker.mjs +18 -14
- package/bin/harnessed-update-reminder.mjs +1 -1
- package/dist/cli.mjs +323 -19
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [5.0.16] - 2026-12-05
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Compiled binaries now build with `bun build --compile --minify`. A controlled same-source Windows measurement against the CI-pinned Bun 1.3.14 shows a 1,307,648-byte (~1.26%) size reduction; the embedded runtime still dominates the ~100MB binary, so this is a modest reduction rather than a size fix. No startup-time claims are made.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- The legacy `~/.harnessed` → host-native `harnessed` state-root migration (`~/.claude/harnessed` or `~/.codex/harnessed`) no longer runs when `HARNESSED_ROOT_OVERRIDE` is set. The override redirects the caller's state root but not the migration's user-home targets, so even a `--version` invocation under an isolated root could move or rename the real legacy directory; ambient migration is now skipped entirely while the override is set. Unset or empty override values keep the existing migration behavior.
|
|
17
|
+
- `harnessed rollback` backups for JSON settings files now record only the keys the install actually changed. Every mutated file used to be byte-copied into `~/.claude/harnessed/backups/`, which swept unrelated `env` credentials out of `settings.json` into the backup dir and let a rollback clobber keys the install never touched — including edits made after install. When a plan's old and new images both parse as JSON objects, the backup now stores a scoped diff of the old values only (`kind: "json-subtree"`), and rollback reverts exactly those paths while preserving every other current key. Compatibility: scoped snapshots carry a `json-subtree-v1` format discriminator in place of the file checksum, so released rollbacks always refuse them with a checksum mismatch instead of writing diff JSON into the target file — restore scoped snapshots with this version or newer. Scoped backups and restores also refuse JSON containing numbers `JSON.stringify` cannot round-trip (non-finite values, integers beyond 2^53-1) rather than silently corrupting them; byte backups for non-JSON files are unchanged.
|
|
18
|
+
- The "you were updated" notice is now written on a real auto-update. The owned-state refresh that runs in the new binary launched the notice write without awaiting it, and the entry point exits the process the moment the refresh entry returns — so on every real update the notice write was killed mid-flight and the status file kept the half-written skeleton the worker records before the handover. The refresh itself always completed (it is awaited); only the notice was lost, which is why the defect was invisible to every test that keeps the process alive. The next session after an auto-update now prints the version change, the changelog excerpt and the restart hint exactly once, as designed.
|
|
19
|
+
- `harnessed update --rollback` can now find what an update banked. A self-update copied the replaced binary into `bin-backup/<version>/` under the exec's own filename (`harnessed`, `harnessed.exe`), while the rollback scan looked for the release asset name (`harnessed-windows-x64.exe`, …) — on a real install the two never match, so rollback reported "no rollback candidates" against a full `bin-backup/`. Every test world named the exec file exactly like the asset, which is why the mismatch never showed up. New banks are written under the asset name the contract documents, and the scan also accepts the exec basename so every backup banked since 4.32.20 stays reachable.
|
|
20
|
+
|
|
8
21
|
## [5.0.15] - 2026-11-09
|
|
9
22
|
|
|
10
23
|
### Fixed
|
|
@@ -65,7 +65,7 @@ var init_package = __esm({
|
|
|
65
65
|
'package.json'() {
|
|
66
66
|
package_default = {
|
|
67
67
|
name: 'harnessed',
|
|
68
|
-
version: '5.0.
|
|
68
|
+
version: '5.0.16',
|
|
69
69
|
description: 'AI coding harness package manager + composition orchestrator',
|
|
70
70
|
type: 'module',
|
|
71
71
|
license: 'Apache-2.0',
|
|
@@ -3519,7 +3519,7 @@ async function runBinarySelfUpdate(deps, opts) {
|
|
|
3519
3519
|
try {
|
|
3520
3520
|
const dir = join6(deps.stateRoot(), 'bin-backup', deps.currentVersion)
|
|
3521
3521
|
await mkdir(dir, { recursive: true })
|
|
3522
|
-
await copyFile(bakPath, join6(dir,
|
|
3522
|
+
await copyFile(bakPath, join6(dir, asset))
|
|
3523
3523
|
backupDir = dir
|
|
3524
3524
|
copied = true
|
|
3525
3525
|
} catch (e) {
|
|
@@ -3563,20 +3563,25 @@ async function runBinaryRollback(deps, opts) {
|
|
|
3563
3563
|
}
|
|
3564
3564
|
const asset = assetNameFor(deps.platform, deps.arch)
|
|
3565
3565
|
const backupsRoot = join6(deps.stateRoot(), 'bin-backup')
|
|
3566
|
-
|
|
3566
|
+
const execBase = basename(deps.execPath)
|
|
3567
|
+
const banked = /* @__PURE__ */ new Map()
|
|
3567
3568
|
try {
|
|
3568
3569
|
const entries = await readdir(backupsRoot, { withFileTypes: true })
|
|
3569
3570
|
for (const e of entries) {
|
|
3570
3571
|
if (!e.isDirectory()) continue
|
|
3571
|
-
const
|
|
3572
|
-
(
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3572
|
+
for (const name of asset === execBase ? [asset] : [asset, execBase]) {
|
|
3573
|
+
const has = await access(join6(backupsRoot, e.name, name)).then(
|
|
3574
|
+
() => true,
|
|
3575
|
+
() => false,
|
|
3576
|
+
)
|
|
3577
|
+
if (has) {
|
|
3578
|
+
banked.set(e.name, name)
|
|
3579
|
+
break
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3576
3582
|
}
|
|
3577
|
-
} catch {
|
|
3578
|
-
|
|
3579
|
-
}
|
|
3583
|
+
} catch {}
|
|
3584
|
+
const versions = [...banked.keys()]
|
|
3580
3585
|
if (versions.length === 0) {
|
|
3581
3586
|
return {
|
|
3582
3587
|
status: 'error',
|
|
@@ -3595,9 +3600,8 @@ async function runBinaryRollback(deps, opts) {
|
|
|
3595
3600
|
} else {
|
|
3596
3601
|
target = versions.reduce((a, b) => (compareVersions(a, b) === 'behind' ? b : a))
|
|
3597
3602
|
}
|
|
3598
|
-
const backupBin = join6(backupsRoot, target, asset)
|
|
3603
|
+
const backupBin = join6(backupsRoot, target, banked.get(target) ?? asset)
|
|
3599
3604
|
const execDir = dirname4(deps.execPath)
|
|
3600
|
-
const execBase = basename(deps.execPath)
|
|
3601
3605
|
const ext = deps.platform === 'win32' ? '.exe' : ''
|
|
3602
3606
|
const tempPath = join6(execDir, `.harnessed-rollback-${deps.pid}${ext}`)
|
|
3603
3607
|
const bakPath = join6(execDir, `${execBase}.bak-${deps.currentVersion}`)
|
|
@@ -3644,7 +3648,7 @@ async function runBinaryRollback(deps, opts) {
|
|
|
3644
3648
|
try {
|
|
3645
3649
|
const dir = join6(backupsRoot, deps.currentVersion)
|
|
3646
3650
|
await mkdir(dir, { recursive: true })
|
|
3647
|
-
await copyFile(bakPath, join6(dir,
|
|
3651
|
+
await copyFile(bakPath, join6(dir, asset))
|
|
3648
3652
|
copied = true
|
|
3649
3653
|
} catch (e) {
|
|
3650
3654
|
deps.log(`warning: could not bank the replaced binary (${e.message}) \u2014 keeping ${bakPath}`)
|
|
@@ -14,7 +14,7 @@ var init_package = __esm({
|
|
|
14
14
|
'package.json'() {
|
|
15
15
|
package_default = {
|
|
16
16
|
name: 'harnessed',
|
|
17
|
-
version: '5.0.
|
|
17
|
+
version: '5.0.16',
|
|
18
18
|
description: 'AI coding harness package manager + composition orchestrator',
|
|
19
19
|
type: 'module',
|
|
20
20
|
license: 'Apache-2.0',
|
package/dist/cli.mjs
CHANGED
|
@@ -42,7 +42,7 @@ var init_package = __esm({
|
|
|
42
42
|
"package.json"() {
|
|
43
43
|
package_default = {
|
|
44
44
|
name: "harnessed",
|
|
45
|
-
version: "5.0.
|
|
45
|
+
version: "5.0.16",
|
|
46
46
|
description: "AI coding harness package manager + composition orchestrator",
|
|
47
47
|
type: "module",
|
|
48
48
|
license: "Apache-2.0",
|
|
@@ -432,6 +432,8 @@ function renameLegacyRoot(source, target) {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
function migrateLegacyHarnessedRoot(context = captureHostInstallContext()) {
|
|
435
|
+
const override = process.env.HARNESSED_ROOT_OVERRIDE;
|
|
436
|
+
if (override !== void 0 && override !== "") return;
|
|
435
437
|
const legacyRoot = join(context.userHome, ".harnessed");
|
|
436
438
|
const newRoot = context.platform.stateRoot;
|
|
437
439
|
const targetParent = dirname(newRoot);
|
|
@@ -4099,6 +4101,149 @@ var init_autoUpdateCmd = __esm({
|
|
|
4099
4101
|
init_updateReminderPreferences();
|
|
4100
4102
|
}
|
|
4101
4103
|
});
|
|
4104
|
+
|
|
4105
|
+
// src/installers/lib/jsonSubtree.ts
|
|
4106
|
+
function isJsonObject(v) {
|
|
4107
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4108
|
+
}
|
|
4109
|
+
function tryParseJsonObject(text) {
|
|
4110
|
+
try {
|
|
4111
|
+
const v = JSON.parse(text);
|
|
4112
|
+
return isJsonObject(v) ? v : null;
|
|
4113
|
+
} catch {
|
|
4114
|
+
return null;
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
function hasOwn(obj, key) {
|
|
4118
|
+
return Object.hasOwn(obj, key);
|
|
4119
|
+
}
|
|
4120
|
+
function setOwn(obj, key, value) {
|
|
4121
|
+
Object.defineProperty(obj, key, {
|
|
4122
|
+
value,
|
|
4123
|
+
writable: true,
|
|
4124
|
+
enumerable: true,
|
|
4125
|
+
configurable: true
|
|
4126
|
+
});
|
|
4127
|
+
}
|
|
4128
|
+
function deepEqualJson(a, b) {
|
|
4129
|
+
if (a === b) return true;
|
|
4130
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
4131
|
+
return a.length === b.length && a.every((v, i) => deepEqualJson(v, b[i]));
|
|
4132
|
+
}
|
|
4133
|
+
if (isJsonObject(a) && isJsonObject(b)) {
|
|
4134
|
+
const aKeys = Object.keys(a);
|
|
4135
|
+
const bKeys = Object.keys(b);
|
|
4136
|
+
return aKeys.length === bKeys.length && aKeys.every((k) => hasOwn(b, k) && deepEqualJson(a[k], b[k]));
|
|
4137
|
+
}
|
|
4138
|
+
return false;
|
|
4139
|
+
}
|
|
4140
|
+
function diffJsonObjects(oldObj, newObj) {
|
|
4141
|
+
const changes = [];
|
|
4142
|
+
const walk = (o, n, base) => {
|
|
4143
|
+
for (const key of Object.keys(o)) {
|
|
4144
|
+
const path = [...base, key];
|
|
4145
|
+
if (!hasOwn(n, key)) {
|
|
4146
|
+
changes.push({ path, existed: true, value: o[key] });
|
|
4147
|
+
} else {
|
|
4148
|
+
compare(o[key], n[key], path);
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
for (const key of Object.keys(n)) {
|
|
4152
|
+
if (!hasOwn(o, key)) changes.push({ path: [...base, key], existed: false });
|
|
4153
|
+
}
|
|
4154
|
+
};
|
|
4155
|
+
const compare = (a, b, path) => {
|
|
4156
|
+
if (isJsonObject(a) && isJsonObject(b)) {
|
|
4157
|
+
walk(a, b, path);
|
|
4158
|
+
} else if (!deepEqualJson(a, b)) {
|
|
4159
|
+
changes.push({ path, existed: true, value: a });
|
|
4160
|
+
}
|
|
4161
|
+
};
|
|
4162
|
+
walk(oldObj, newObj, []);
|
|
4163
|
+
return changes;
|
|
4164
|
+
}
|
|
4165
|
+
function containsUnsafeJsonNumber(value) {
|
|
4166
|
+
if (typeof value === "number") {
|
|
4167
|
+
return !Number.isFinite(value) || Number.isInteger(value) && !Number.isSafeInteger(value);
|
|
4168
|
+
}
|
|
4169
|
+
if (Array.isArray(value)) return value.some(containsUnsafeJsonNumber);
|
|
4170
|
+
if (isJsonObject(value)) {
|
|
4171
|
+
return Object.keys(value).some((k) => containsUnsafeJsonNumber(value[k]));
|
|
4172
|
+
}
|
|
4173
|
+
return false;
|
|
4174
|
+
}
|
|
4175
|
+
function pathsOverlap(a, b) {
|
|
4176
|
+
const n = Math.min(a.length, b.length);
|
|
4177
|
+
return a.slice(0, n).every((seg, i) => seg === b[i]);
|
|
4178
|
+
}
|
|
4179
|
+
function validateSubtreePayload(parsed) {
|
|
4180
|
+
if (!isJsonObject(parsed)) return { ok: false, reason: "payload is not a JSON object" };
|
|
4181
|
+
if (parsed.version !== SUBTREE_PAYLOAD_VERSION) {
|
|
4182
|
+
return { ok: false, reason: `unsupported payload version ${String(parsed.version)}` };
|
|
4183
|
+
}
|
|
4184
|
+
const raw = parsed.changes;
|
|
4185
|
+
if (!Array.isArray(raw)) return { ok: false, reason: "changes is not an array" };
|
|
4186
|
+
const changes = [];
|
|
4187
|
+
for (const item of raw) {
|
|
4188
|
+
if (!isJsonObject(item)) return { ok: false, reason: "change entry is not an object" };
|
|
4189
|
+
const { path, existed } = item;
|
|
4190
|
+
if (!Array.isArray(path) || path.length === 0 || !path.every((seg) => typeof seg === "string")) {
|
|
4191
|
+
return { ok: false, reason: "change path must be a non-empty string array" };
|
|
4192
|
+
}
|
|
4193
|
+
if (typeof existed !== "boolean") {
|
|
4194
|
+
return { ok: false, reason: "change existed must be boolean" };
|
|
4195
|
+
}
|
|
4196
|
+
const hasValue = hasOwn(item, "value");
|
|
4197
|
+
if (existed && !hasValue) {
|
|
4198
|
+
return { ok: false, reason: "existed change missing old value" };
|
|
4199
|
+
}
|
|
4200
|
+
if (!existed && hasValue) {
|
|
4201
|
+
return { ok: false, reason: "added-path change must not carry a value" };
|
|
4202
|
+
}
|
|
4203
|
+
const p8 = path;
|
|
4204
|
+
for (const prev of changes) {
|
|
4205
|
+
if (pathsOverlap(prev.path, p8)) {
|
|
4206
|
+
return {
|
|
4207
|
+
ok: false,
|
|
4208
|
+
reason: `duplicate or overlapping change path ${JSON.stringify(p8)}`
|
|
4209
|
+
};
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
const change = { path: p8, existed };
|
|
4213
|
+
if (hasValue) change.value = item.value;
|
|
4214
|
+
changes.push(change);
|
|
4215
|
+
}
|
|
4216
|
+
return { ok: true, changes };
|
|
4217
|
+
}
|
|
4218
|
+
function applySubtreeChanges(current, changes) {
|
|
4219
|
+
for (const change of changes) {
|
|
4220
|
+
let node = current;
|
|
4221
|
+
for (const seg of change.path.slice(0, -1)) {
|
|
4222
|
+
const next = hasOwn(node, seg) ? node[seg] : void 0;
|
|
4223
|
+
if (!isJsonObject(next)) {
|
|
4224
|
+
return {
|
|
4225
|
+
ok: false,
|
|
4226
|
+
reason: `conflict at ${JSON.stringify(change.path)}: parent ${JSON.stringify(seg)} is missing or not an object`
|
|
4227
|
+
};
|
|
4228
|
+
}
|
|
4229
|
+
node = next;
|
|
4230
|
+
}
|
|
4231
|
+
const leaf = change.path[change.path.length - 1];
|
|
4232
|
+
if (change.existed) {
|
|
4233
|
+
setOwn(node, leaf, change.value);
|
|
4234
|
+
} else if (hasOwn(node, leaf)) {
|
|
4235
|
+
delete node[leaf];
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
return { ok: true };
|
|
4239
|
+
}
|
|
4240
|
+
var SUBTREE_PAYLOAD_VERSION, SUBTREE_ENTRY_SHA1;
|
|
4241
|
+
var init_jsonSubtree = __esm({
|
|
4242
|
+
"src/installers/lib/jsonSubtree.ts"() {
|
|
4243
|
+
SUBTREE_PAYLOAD_VERSION = 1;
|
|
4244
|
+
SUBTREE_ENTRY_SHA1 = "json-subtree-v1";
|
|
4245
|
+
}
|
|
4246
|
+
});
|
|
4102
4247
|
function getBackupRoot(hostContext) {
|
|
4103
4248
|
return hostContext ? join(hostContext.platform.stateRoot, "backups") : harnessedSubdir("backups");
|
|
4104
4249
|
}
|
|
@@ -4174,12 +4319,56 @@ async function backup(plan, ctx) {
|
|
|
4174
4319
|
}
|
|
4175
4320
|
};
|
|
4176
4321
|
}
|
|
4177
|
-
const sha1 = createHash("sha1").update(buf).digest("hex");
|
|
4178
4322
|
const eol = detectEol(buf);
|
|
4179
4323
|
const dest = mirrorPath(file.target, file.scope, backupDir, ctx.hostContext);
|
|
4324
|
+
const entry = {
|
|
4325
|
+
target: file.target,
|
|
4326
|
+
backup: dest,
|
|
4327
|
+
sha1: createHash("sha1").update(buf).digest("hex"),
|
|
4328
|
+
eol
|
|
4329
|
+
};
|
|
4330
|
+
let stored = buf;
|
|
4331
|
+
const oldJson = tryParseJsonObject(file.oldText);
|
|
4332
|
+
const newJson = tryParseJsonObject(file.newText);
|
|
4333
|
+
if (oldJson !== null && newJson !== null) {
|
|
4334
|
+
if (buf.toString("utf8") !== file.oldText) {
|
|
4335
|
+
return {
|
|
4336
|
+
ok: false,
|
|
4337
|
+
error: {
|
|
4338
|
+
file: filename,
|
|
4339
|
+
path: file.target,
|
|
4340
|
+
message: "on-disk content differs from plan oldText (stale plan); re-run the install to regenerate the plan",
|
|
4341
|
+
line: null,
|
|
4342
|
+
column: null,
|
|
4343
|
+
keyword: "backup-stale-plan"
|
|
4344
|
+
}
|
|
4345
|
+
};
|
|
4346
|
+
}
|
|
4347
|
+
if (containsUnsafeJsonNumber(oldJson) || containsUnsafeJsonNumber(newJson)) {
|
|
4348
|
+
return {
|
|
4349
|
+
ok: false,
|
|
4350
|
+
error: {
|
|
4351
|
+
file: filename,
|
|
4352
|
+
path: file.target,
|
|
4353
|
+
message: "JSON contains a number that cannot round-trip through JSON.stringify (non-finite or unsafe integer); scoped backup refused \u2014 edit the file manually",
|
|
4354
|
+
line: null,
|
|
4355
|
+
column: null,
|
|
4356
|
+
keyword: "backup-json-unsafe-number"
|
|
4357
|
+
}
|
|
4358
|
+
};
|
|
4359
|
+
}
|
|
4360
|
+
stored = Buffer.from(
|
|
4361
|
+
`${JSON.stringify({ version: 1, changes: diffJsonObjects(oldJson, newJson) }, null, 2)}
|
|
4362
|
+
`,
|
|
4363
|
+
"utf8"
|
|
4364
|
+
);
|
|
4365
|
+
entry.kind = "json-subtree";
|
|
4366
|
+
entry.sha1 = SUBTREE_ENTRY_SHA1;
|
|
4367
|
+
entry.payloadSha1 = createHash("sha1").update(stored).digest("hex");
|
|
4368
|
+
}
|
|
4180
4369
|
try {
|
|
4181
4370
|
await mkdir(dirname(dest), { recursive: true });
|
|
4182
|
-
await writeFile(dest,
|
|
4371
|
+
await writeFile(dest, stored);
|
|
4183
4372
|
} catch (err2) {
|
|
4184
4373
|
return {
|
|
4185
4374
|
ok: false,
|
|
@@ -4193,7 +4382,7 @@ async function backup(plan, ctx) {
|
|
|
4193
4382
|
}
|
|
4194
4383
|
};
|
|
4195
4384
|
}
|
|
4196
|
-
entries.push(
|
|
4385
|
+
entries.push(entry);
|
|
4197
4386
|
}
|
|
4198
4387
|
const metadata = {
|
|
4199
4388
|
installer: filename,
|
|
@@ -4224,6 +4413,7 @@ var HOME_DIR;
|
|
|
4224
4413
|
var init_backup = __esm({
|
|
4225
4414
|
"src/installers/lib/backup.ts"() {
|
|
4226
4415
|
init_harnessedRoot();
|
|
4416
|
+
init_jsonSubtree();
|
|
4227
4417
|
HOME_DIR = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
4228
4418
|
}
|
|
4229
4419
|
});
|
|
@@ -22245,7 +22435,7 @@ async function runBinarySelfUpdate(deps, opts) {
|
|
|
22245
22435
|
try {
|
|
22246
22436
|
const dir = join(deps.stateRoot(), "bin-backup", deps.currentVersion);
|
|
22247
22437
|
await mkdir(dir, { recursive: true });
|
|
22248
|
-
await copyFile$1(bakPath, join(dir,
|
|
22438
|
+
await copyFile$1(bakPath, join(dir, asset));
|
|
22249
22439
|
backupDir = dir;
|
|
22250
22440
|
copied = true;
|
|
22251
22441
|
} catch (e) {
|
|
@@ -22290,20 +22480,26 @@ async function runBinaryRollback(deps, opts) {
|
|
|
22290
22480
|
}
|
|
22291
22481
|
const asset = assetNameFor(deps.platform, deps.arch);
|
|
22292
22482
|
const backupsRoot = join(deps.stateRoot(), "bin-backup");
|
|
22293
|
-
|
|
22483
|
+
const execBase = basename(deps.execPath);
|
|
22484
|
+
const banked = /* @__PURE__ */ new Map();
|
|
22294
22485
|
try {
|
|
22295
22486
|
const entries = await readdir(backupsRoot, { withFileTypes: true });
|
|
22296
22487
|
for (const e of entries) {
|
|
22297
22488
|
if (!e.isDirectory()) continue;
|
|
22298
|
-
const
|
|
22299
|
-
(
|
|
22300
|
-
|
|
22301
|
-
|
|
22302
|
-
|
|
22489
|
+
for (const name of asset === execBase ? [asset] : [asset, execBase]) {
|
|
22490
|
+
const has = await access(join(backupsRoot, e.name, name)).then(
|
|
22491
|
+
() => true,
|
|
22492
|
+
() => false
|
|
22493
|
+
);
|
|
22494
|
+
if (has) {
|
|
22495
|
+
banked.set(e.name, name);
|
|
22496
|
+
break;
|
|
22497
|
+
}
|
|
22498
|
+
}
|
|
22303
22499
|
}
|
|
22304
22500
|
} catch {
|
|
22305
|
-
versions = [];
|
|
22306
22501
|
}
|
|
22502
|
+
const versions = [...banked.keys()];
|
|
22307
22503
|
if (versions.length === 0) {
|
|
22308
22504
|
return {
|
|
22309
22505
|
status: "error",
|
|
@@ -22322,9 +22518,8 @@ async function runBinaryRollback(deps, opts) {
|
|
|
22322
22518
|
} else {
|
|
22323
22519
|
target = versions.reduce((a, b) => compareVersions(a, b) === "behind" ? b : a);
|
|
22324
22520
|
}
|
|
22325
|
-
const backupBin = join(backupsRoot, target, asset);
|
|
22521
|
+
const backupBin = join(backupsRoot, target, banked.get(target) ?? asset);
|
|
22326
22522
|
const execDir = dirname(deps.execPath);
|
|
22327
|
-
const execBase = basename(deps.execPath);
|
|
22328
22523
|
const ext = deps.platform === "win32" ? ".exe" : "";
|
|
22329
22524
|
const tempPath = join(execDir, `.harnessed-rollback-${deps.pid}${ext}`);
|
|
22330
22525
|
const bakPath = join(execDir, `${execBase}.bak-${deps.currentVersion}`);
|
|
@@ -22373,7 +22568,7 @@ async function runBinaryRollback(deps, opts) {
|
|
|
22373
22568
|
try {
|
|
22374
22569
|
const dir = join(backupsRoot, deps.currentVersion);
|
|
22375
22570
|
await mkdir(dir, { recursive: true });
|
|
22376
|
-
await copyFile$1(bakPath, join(dir,
|
|
22571
|
+
await copyFile$1(bakPath, join(dir, asset));
|
|
22377
22572
|
copied = true;
|
|
22378
22573
|
} catch (e) {
|
|
22379
22574
|
deps.log(
|
|
@@ -25383,9 +25578,49 @@ ${t("rollback.metadata_unreadable.fix")}`
|
|
|
25383
25578
|
process.exit(1);
|
|
25384
25579
|
return;
|
|
25385
25580
|
}
|
|
25581
|
+
{
|
|
25582
|
+
const counts = /* @__PURE__ */ new Map();
|
|
25583
|
+
for (const entry of meta.files) {
|
|
25584
|
+
counts.set(entry.target, (counts.get(entry.target) ?? 0) + 1);
|
|
25585
|
+
}
|
|
25586
|
+
const dupInvolvingSubtree = meta.files.some(
|
|
25587
|
+
(entry) => entry.kind === "json-subtree" && (counts.get(entry.target) ?? 0) > 1
|
|
25588
|
+
);
|
|
25589
|
+
if (dupInvolvingSubtree) {
|
|
25590
|
+
console.error(
|
|
25591
|
+
"error: backup metadata has duplicate entries for a json-subtree target; refusing to guess composition order"
|
|
25592
|
+
);
|
|
25593
|
+
process.exit(1);
|
|
25594
|
+
return;
|
|
25595
|
+
}
|
|
25596
|
+
}
|
|
25386
25597
|
const ordered = [...meta.files].reverse();
|
|
25387
25598
|
const planned = [];
|
|
25388
25599
|
for (const entry of ordered) {
|
|
25600
|
+
if (entry.kind === "json-subtree") {
|
|
25601
|
+
if (entry.sha1 !== SUBTREE_ENTRY_SHA1 || typeof entry.payloadSha1 !== "string" || !/^[a-f0-9]{40}$/.test(entry.payloadSha1) || entry.backup === "" || entry.sentinel !== void 0) {
|
|
25602
|
+
console.error(
|
|
25603
|
+
`error: malformed json-subtree backup entry for ${entry.target}; scoped snapshots require a compatible harnessed reader \u2014 restore manually`
|
|
25604
|
+
);
|
|
25605
|
+
process.exit(1);
|
|
25606
|
+
return;
|
|
25607
|
+
}
|
|
25608
|
+
} else {
|
|
25609
|
+
if (entry.kind !== void 0 && entry.kind !== "bytes") {
|
|
25610
|
+
console.error(
|
|
25611
|
+
`error: backup entry for ${entry.target} has unknown kind ${String(entry.kind)}; upgrade harnessed or restore manually`
|
|
25612
|
+
);
|
|
25613
|
+
process.exit(1);
|
|
25614
|
+
return;
|
|
25615
|
+
}
|
|
25616
|
+
if (entry.payloadSha1 !== void 0) {
|
|
25617
|
+
console.error(
|
|
25618
|
+
`error: backup entry for ${entry.target} carries payloadSha1 without json-subtree kind; refusing to guess its format`
|
|
25619
|
+
);
|
|
25620
|
+
process.exit(1);
|
|
25621
|
+
return;
|
|
25622
|
+
}
|
|
25623
|
+
}
|
|
25389
25624
|
if (entry.backup === "") {
|
|
25390
25625
|
if (entry.sentinel === "created") {
|
|
25391
25626
|
planned.push({ target: entry.target, action: "remove-created" });
|
|
@@ -25419,13 +25654,81 @@ ${t("rollback.metadata_unreadable.fix")}`
|
|
|
25419
25654
|
process.exit(1);
|
|
25420
25655
|
return;
|
|
25421
25656
|
}
|
|
25422
|
-
const
|
|
25423
|
-
if (
|
|
25657
|
+
const digest = createHash("sha1").update(buf).digest("hex");
|
|
25658
|
+
if (entry.kind === "json-subtree") {
|
|
25659
|
+
if (digest !== entry.payloadSha1) {
|
|
25660
|
+
console.error(
|
|
25661
|
+
t("rollback.checksum_mismatch", {
|
|
25662
|
+
target: entry.target,
|
|
25663
|
+
expected: (entry.payloadSha1 ?? "").slice(0, 12),
|
|
25664
|
+
actual: digest.slice(0, 12)
|
|
25665
|
+
})
|
|
25666
|
+
);
|
|
25667
|
+
process.exit(1);
|
|
25668
|
+
return;
|
|
25669
|
+
}
|
|
25670
|
+
let parsedPayload;
|
|
25671
|
+
try {
|
|
25672
|
+
parsedPayload = JSON.parse(buf.toString("utf8"));
|
|
25673
|
+
} catch {
|
|
25674
|
+
console.error(`error: backup payload for ${entry.target} is not valid JSON`);
|
|
25675
|
+
process.exit(1);
|
|
25676
|
+
return;
|
|
25677
|
+
}
|
|
25678
|
+
const payload = validateSubtreePayload(parsedPayload);
|
|
25679
|
+
if (!payload.ok) {
|
|
25680
|
+
console.error(
|
|
25681
|
+
`error: invalid json-subtree payload for ${entry.target}: ${payload.reason}`
|
|
25682
|
+
);
|
|
25683
|
+
process.exit(1);
|
|
25684
|
+
return;
|
|
25685
|
+
}
|
|
25686
|
+
const currentText = await (async () => {
|
|
25687
|
+
try {
|
|
25688
|
+
return await readFile(entry.target, "utf8");
|
|
25689
|
+
} catch {
|
|
25690
|
+
return null;
|
|
25691
|
+
}
|
|
25692
|
+
})();
|
|
25693
|
+
const current = currentText === null ? null : tryParseJsonObject(currentText);
|
|
25694
|
+
if (current === null) {
|
|
25695
|
+
console.error(
|
|
25696
|
+
`error: cannot restore ${entry.target}: current content is not a readable JSON object (refusing to overwrite user edits)`
|
|
25697
|
+
);
|
|
25698
|
+
process.exit(1);
|
|
25699
|
+
return;
|
|
25700
|
+
}
|
|
25701
|
+
const unsafe = containsUnsafeJsonNumber(current) || payload.changes.some((c) => c.existed && containsUnsafeJsonNumber(c.value));
|
|
25702
|
+
if (unsafe) {
|
|
25703
|
+
console.error(
|
|
25704
|
+
`error: cannot restore ${entry.target}: JSON contains a number that cannot round-trip through JSON.stringify (non-finite or unsafe integer) \u2014 restore manually`
|
|
25705
|
+
);
|
|
25706
|
+
process.exit(1);
|
|
25707
|
+
return;
|
|
25708
|
+
}
|
|
25709
|
+
const applied = applySubtreeChanges(current, payload.changes);
|
|
25710
|
+
if (!applied.ok) {
|
|
25711
|
+
console.error(`error: cannot restore ${entry.target}: ${applied.reason}`);
|
|
25712
|
+
process.exit(1);
|
|
25713
|
+
return;
|
|
25714
|
+
}
|
|
25715
|
+
planned.push({
|
|
25716
|
+
target: entry.target,
|
|
25717
|
+
action: "write",
|
|
25718
|
+
data: normalizeEol(
|
|
25719
|
+
Buffer.from(`${JSON.stringify(current, null, 2)}
|
|
25720
|
+
`, "utf8"),
|
|
25721
|
+
entry.eol
|
|
25722
|
+
)
|
|
25723
|
+
});
|
|
25724
|
+
continue;
|
|
25725
|
+
}
|
|
25726
|
+
if (digest !== entry.sha1) {
|
|
25424
25727
|
console.error(
|
|
25425
25728
|
t("rollback.checksum_mismatch", {
|
|
25426
25729
|
target: entry.target,
|
|
25427
25730
|
expected: entry.sha1.slice(0, 12),
|
|
25428
|
-
actual:
|
|
25731
|
+
actual: digest.slice(0, 12)
|
|
25429
25732
|
})
|
|
25430
25733
|
);
|
|
25431
25734
|
process.exit(1);
|
|
@@ -25464,6 +25767,7 @@ var init_rollback = __esm({
|
|
|
25464
25767
|
"src/cli/rollback.ts"() {
|
|
25465
25768
|
init_i18n();
|
|
25466
25769
|
init_backup();
|
|
25770
|
+
init_jsonSubtree();
|
|
25467
25771
|
init_path_guard();
|
|
25468
25772
|
}
|
|
25469
25773
|
});
|
|
@@ -28674,7 +28978,7 @@ async function runOwnedRefreshEntry() {
|
|
|
28674
28978
|
const { captureHostInstallContext: captureHostInstallContext3 } = await Promise.resolve().then(() => (init_hostInstallContext(), hostInstallContext_exports));
|
|
28675
28979
|
const context = captureHostInstallContext3();
|
|
28676
28980
|
const outcome = await refreshOwnedState(context);
|
|
28677
|
-
writeAutoUpdateNoticeForNewBinary(context);
|
|
28981
|
+
await writeAutoUpdateNoticeForNewBinary(context);
|
|
28678
28982
|
if (outcome.ok) {
|
|
28679
28983
|
console.log(
|
|
28680
28984
|
`[harnessed] owned state refreshed (${outcome.updated.length} component(s): ${outcome.updated.join(", ")})`
|