@indigoai-us/hq-cli 5.345.251 → 5.345.253
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 +153 -0
- package/assets/scaffold/core/scripts/hq-session.sh +9 -0
- package/contracts/host-canary-release.json +9 -3
- package/dist/command-catalog.generated.d.ts +269 -1
- package/dist/command-catalog.generated.js +330 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/bot.js +7 -2
- package/dist/commands/ci-intake.d.ts +15 -0
- package/dist/commands/ci-intake.js +252 -0
- package/dist/commands/ci-metrics.d.ts +8 -0
- package/dist/commands/ci-metrics.js +55 -0
- package/dist/commands/ci.d.ts +13 -0
- package/dist/commands/ci.js +10 -0
- package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
- package/dist/commands/core-hq-session-binding.d.ts +140 -0
- package/dist/commands/core-hq-session-binding.js +363 -0
- package/dist/commands/core-hq-session-native.d.ts +23 -0
- package/dist/commands/core-hq-session-native.js +59 -9
- package/dist/commands/core-stop-autosave.js +1 -1
- package/dist/commands/core.js +10 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +42 -5
- package/dist/commands/files.d.ts +62 -0
- package/dist/commands/files.js +250 -9
- package/dist/commands/install-global.js +4 -2
- package/dist/commands/logout.js +4 -0
- package/dist/commands/ontology-graph.d.ts +2 -0
- package/dist/commands/ontology-graph.js +33 -0
- package/dist/commands/report.js +35 -2
- package/dist/commands/storage-gate.js +1 -1
- package/dist/commands/vault-retention-flag.js +2 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +48 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +50 -0
- package/dist/lib/bot/fleet-cron.js +173 -32
- package/dist/lib/bot/fleet-local.d.ts +18 -0
- package/dist/lib/bot/fleet-local.js +51 -5
- package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
- package/dist/lib/bot/signals-engine-flag.js +1 -1
- package/dist/lib/cli-invite-nudge.js +1 -1
- package/dist/lib/client-version.d.ts +2 -0
- package/dist/lib/client-version.js +24 -0
- package/dist/lib/company-flag-gate.d.ts +30 -0
- package/dist/lib/company-flag-gate.js +104 -0
- package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
- package/dist/lib/daemon/flag.js +2 -1
- package/dist/lib/daemon/legacy-journal-gate.js +3 -1
- package/dist/lib/daemon/run.js +4 -3
- package/dist/lib/daemon/shared-flag-reads.js +1 -1
- package/dist/lib/delivery/migrations.d.ts +32 -1
- package/dist/lib/delivery/migrations.js +69 -8
- package/dist/lib/doctor/checks/host-core.js +22 -4
- package/dist/lib/doctor/checks/jq.d.ts +27 -6
- package/dist/lib/doctor/checks/jq.js +46 -8
- package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
- package/dist/lib/flag-client-gate-headers.d.ts +38 -0
- package/dist/lib/flag-client-gate-headers.js +62 -0
- package/dist/lib/flag-client-headers.d.ts +15 -0
- package/dist/lib/flag-client-headers.js +25 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +35 -0
- package/dist/lib/flag-registry.d.ts +1 -20
- package/dist/lib/flag-registry.js +5 -81
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +30 -0
- package/dist/lib/hook-engine/adapter-core-pin.js +30 -0
- package/dist/lib/hook-engine/coverage.d.ts +65 -1
- package/dist/lib/hook-engine/coverage.js +173 -8
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
- package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
- package/dist/lib/hot-channels/signal-changes.js +683 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
- package/dist/lib/hot-channels/signals-pass.js +232 -12
- package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
- package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
- package/dist/lib/lanes/registry-flag.js +2 -1
- package/dist/lib/lanes/spawn.js +11 -1
- package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
- package/dist/lib/mesh/live/binding-intent.js +201 -0
- package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
- package/dist/lib/mesh/live/binding-receipt.js +365 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
- package/dist/lib/mesh/live/daemon/install.js +2 -1
- package/dist/lib/mesh/live/daemon/presence.js +9 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
- package/dist/lib/mesh/live/daemon/run.js +33 -1
- package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
- package/dist/lib/ontology-graph/lineage/index.js +1027 -0
- package/dist/lib/ontology-graph/model/index.d.ts +54 -0
- package/dist/lib/ontology-graph/model/index.js +112 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
- package/dist/lib/ontology-graph/model/pass.js +9 -2
- package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
- package/dist/lib/ontology-graph/model/pending-items.js +24 -1
- package/dist/lib/ontology-graph/model/step.d.ts +1 -1
- package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
- package/dist/lib/ontology-graph/model/tasks.js +20 -7
- package/dist/lib/ontology-graph/read/brief.js +41 -6
- package/dist/lib/ontology-graph/read/index.d.ts +4 -0
- package/dist/lib/ontology-graph/read/index.js +173 -29
- package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
- package/dist/lib/ontology-graph/read/lineage.js +262 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
- package/dist/lib/ontology-graph/replay/engine.js +213 -8
- package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
- package/dist/lib/ontology-graph/replay/extractors.js +25 -1
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
- package/dist/lib/ontology-graph/replay/index.js +9 -3
- package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
- package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
- package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
- package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
- package/dist/lib/ontology-graph/schema/index.js +1 -0
- package/dist/lib/ontology-graph/setup/index.js +13 -3
- package/dist/lib/search-index/index.d.ts +33 -1
- package/dist/lib/search-index/index.js +180 -25
- package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
- package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
- package/dist/lib/signals/adapters-catalog.js +1 -1
- package/dist/lib/smart-ci/cost.d.ts +72 -0
- package/dist/lib/smart-ci/cost.js +120 -0
- package/dist/lib/smart-ci/github.d.ts +112 -0
- package/dist/lib/smart-ci/github.js +267 -0
- package/dist/lib/smart-ci/intake.d.ts +288 -0
- package/dist/lib/smart-ci/intake.js +1078 -0
- package/dist/lib/smart-ci/ledger.d.ts +218 -0
- package/dist/lib/smart-ci/ledger.js +527 -0
- package/dist/lib/smart-ci/metrics.d.ts +137 -0
- package/dist/lib/smart-ci/metrics.js +249 -0
- package/dist/lib/smart-ci/records.d.ts +265 -0
- package/dist/lib/smart-ci/records.js +281 -0
- package/dist/lib/smart-ci/reducer.d.ts +67 -0
- package/dist/lib/smart-ci/reducer.js +261 -0
- package/dist/lib/sync-core/engine-holds.d.ts +15 -0
- package/dist/lib/sync-core/engine-holds.js +104 -11
- package/dist/lib/sync-core/engine-home.d.ts +3 -0
- package/dist/lib/sync-core/engine-home.js +41 -1
- package/dist/lib/sync-core/flag.js +2 -1
- package/dist/lib/sync-core/hand-back.d.ts +1 -0
- package/dist/lib/sync-core/hand-back.js +7 -2
- package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
- package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
- package/dist/lib/sync-core/legacy-journal-export.js +120 -55
- package/dist/lib/sync-core/reconcile.d.ts +2 -1
- package/dist/lib/sync-core/reconcile.js +40 -7
- package/dist/lib/sync-invalid-entity-warning.js +2 -1
- package/dist/lib/windows/install-followup.d.ts +41 -0
- package/dist/lib/windows/install-followup.js +87 -0
- package/dist/lib/windows/jq.d.ts +59 -0
- package/dist/lib/windows/jq.js +154 -3
- package/dist/lib/windows/user-path.d.ts +5 -0
- package/dist/lib/windows/user-path.js +1 -1
- package/dist/lib/work-context/auto-bind.d.ts +12 -0
- package/dist/lib/work-context/auto-bind.js +49 -3
- package/dist/lib/work-context/organize.d.ts +4 -2
- package/dist/lib/work-context/organize.js +18 -8
- package/dist/lib/work-context/reconcile.js +16 -1
- package/dist/main.js +12 -1
- package/dist/utils/client-health-contract.d.ts +30 -0
- package/dist/utils/client-health-contract.js +111 -0
- package/dist/utils/client-health.d.ts +5 -2
- package/dist/utils/client-health.js +74 -5
- package/dist/utils/exclusive-lock.d.ts +5 -1
- package/dist/utils/exclusive-lock.js +9 -2
- package/dist/utils/host-registration.d.ts +7 -0
- package/dist/utils/host-registration.js +10 -1
- package/dist/utils/pid.d.ts +31 -0
- package/dist/utils/pid.js +65 -0
- package/dist/utils/resident-package-preload.js +12 -4
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/package.json +10 -8
- package/scripts/install-hook-engine.mjs +5 -3
|
@@ -78,7 +78,43 @@ function readTextOrNull(file) {
|
|
|
78
78
|
export function engineHoldFile(engineHome, vaultUid) {
|
|
79
79
|
return path.join(engineHome, ".hq", "sync-core", "holds", `${vaultUid}.json`);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
const HOLD_KINDS_FILE_MAX_BYTES = 1024 * 1024;
|
|
82
|
+
export function readEngineHoldKinds(engineHome, vaultUid) {
|
|
83
|
+
try {
|
|
84
|
+
const file = engineHoldFile(engineHome, vaultUid);
|
|
85
|
+
const stat = fs.lstatSync(file);
|
|
86
|
+
if (!stat.isFile() || stat.size > HOLD_KINDS_FILE_MAX_BYTES)
|
|
87
|
+
return [];
|
|
88
|
+
const groups = record(JSON.parse(fs.readFileSync(file, "utf8")))?.groups;
|
|
89
|
+
if (!Array.isArray(groups))
|
|
90
|
+
return [];
|
|
91
|
+
const kinds = new Set();
|
|
92
|
+
for (const value of groups) {
|
|
93
|
+
const group = record(value);
|
|
94
|
+
if (typeof group?.direction !== "string")
|
|
95
|
+
continue;
|
|
96
|
+
const paths = Array.isArray(group.paths) ? group.paths.length : 0;
|
|
97
|
+
const declared = typeof group.count === "number" && Number.isSafeInteger(group.count) ? group.count : 0;
|
|
98
|
+
if (paths > 0 || declared > 0)
|
|
99
|
+
kinds.add(group.direction);
|
|
100
|
+
}
|
|
101
|
+
return [...kinds].sort();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export const ENGINE_HOLD_DIRECTIONS = [
|
|
108
|
+
"delete_local",
|
|
109
|
+
"delete_remote",
|
|
110
|
+
"overwrite_local",
|
|
111
|
+
"overwrite_remote",
|
|
112
|
+
"merge",
|
|
113
|
+
"undecided",
|
|
114
|
+
"not_approvable",
|
|
115
|
+
];
|
|
116
|
+
const LOCAL_BODY_DIRECTIONS = new Set(["overwrite_remote", "merge", "undecided", "not_approvable"]);
|
|
117
|
+
function readEngineHold(engineHome, vaultUid) {
|
|
82
118
|
let text;
|
|
83
119
|
try {
|
|
84
120
|
const file = engineHoldFile(engineHome, vaultUid);
|
|
@@ -88,7 +124,7 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
88
124
|
text = fs.readFileSync(file, "utf8");
|
|
89
125
|
}
|
|
90
126
|
catch (error) {
|
|
91
|
-
return error.code === "ENOENT" ? null : "
|
|
127
|
+
return error.code === "ENOENT" ? null : "read-failed";
|
|
92
128
|
}
|
|
93
129
|
let hold;
|
|
94
130
|
try {
|
|
@@ -99,6 +135,21 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
99
135
|
}
|
|
100
136
|
if (!hold || !Array.isArray(hold.groups))
|
|
101
137
|
return "unreadable";
|
|
138
|
+
return hold;
|
|
139
|
+
}
|
|
140
|
+
function groupPaths(group) {
|
|
141
|
+
return Array.isArray(group.paths) ? group.paths.filter((p) => typeof p === "string") : [];
|
|
142
|
+
}
|
|
143
|
+
function groupCount(group, paths) {
|
|
144
|
+
const declared = typeof group.count === "number" && Number.isSafeInteger(group.count) && group.count >= 0 ? group.count : 0;
|
|
145
|
+
return Math.max(paths.length, declared);
|
|
146
|
+
}
|
|
147
|
+
export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
148
|
+
const hold = readEngineHold(engineHome, vaultUid);
|
|
149
|
+
if (hold === null)
|
|
150
|
+
return null;
|
|
151
|
+
if (hold === "unreadable" || hold === "read-failed")
|
|
152
|
+
return "unreadable";
|
|
102
153
|
const deletes = [];
|
|
103
154
|
const unknown = new Set();
|
|
104
155
|
let count = 0;
|
|
@@ -106,25 +157,67 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
106
157
|
const group = record(value);
|
|
107
158
|
if (!group || typeof group.direction !== "string")
|
|
108
159
|
return "unreadable";
|
|
109
|
-
|
|
160
|
+
const direction = group.direction;
|
|
161
|
+
if (direction === "overwrite_local" || LOCAL_BODY_DIRECTIONS.has(direction))
|
|
110
162
|
continue;
|
|
111
|
-
if (
|
|
112
|
-
if (!unknown.has(
|
|
113
|
-
unknown.add(
|
|
114
|
-
warn(`${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} has a kind of hold this hq does not know (direction ${
|
|
163
|
+
if (direction !== "delete_local" && direction !== "delete_remote") {
|
|
164
|
+
if (!unknown.has(direction) && groupCount(group, groupPaths(group)) > 0) {
|
|
165
|
+
unknown.add(direction);
|
|
166
|
+
warn(`${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} has a kind of hold this hq does not know (direction ${printable(direction.slice(0, 64))}); the vault is not handed to the current sync while it is held, so its local copies stay as they are`);
|
|
115
167
|
}
|
|
116
168
|
continue;
|
|
117
169
|
}
|
|
118
|
-
const paths =
|
|
119
|
-
|
|
120
|
-
count += Math.max(paths.length, declared);
|
|
170
|
+
const paths = groupPaths(group);
|
|
171
|
+
count += groupCount(group, paths);
|
|
121
172
|
for (const p of paths)
|
|
122
|
-
deletes.push({ path: p, direction
|
|
173
|
+
deletes.push({ path: p, direction });
|
|
123
174
|
}
|
|
124
175
|
if (count === 0)
|
|
125
176
|
return null;
|
|
126
177
|
return { ...(typeof hold.holdId === "string" && hold.holdId ? { holdId: hold.holdId } : {}), count, deletes };
|
|
127
178
|
}
|
|
179
|
+
export function readEngineHeldLocalBodies(engineHome, vaultUid) {
|
|
180
|
+
const hold = readEngineHold(engineHome, vaultUid);
|
|
181
|
+
if (hold === null || hold === "unreadable")
|
|
182
|
+
return null;
|
|
183
|
+
if (hold === "read-failed")
|
|
184
|
+
return { count: 0, paths: [], directions: [], readFailed: true };
|
|
185
|
+
const paths = [];
|
|
186
|
+
const directions = new Set();
|
|
187
|
+
let count = 0;
|
|
188
|
+
for (const value of hold.groups) {
|
|
189
|
+
const group = record(value) ?? {};
|
|
190
|
+
const direction = typeof group.direction === "string" ? group.direction : "unknown";
|
|
191
|
+
if (direction === "delete_local" || direction === "delete_remote" || direction === "overwrite_local")
|
|
192
|
+
continue;
|
|
193
|
+
const held = groupPaths(group);
|
|
194
|
+
const n = typeof group.direction === "string" ? groupCount(group, held) : Math.max(1, groupCount(group, held));
|
|
195
|
+
if (n === 0)
|
|
196
|
+
continue;
|
|
197
|
+
count += n;
|
|
198
|
+
directions.add(direction);
|
|
199
|
+
for (const p of held)
|
|
200
|
+
paths.push({ path: p, direction });
|
|
201
|
+
}
|
|
202
|
+
if (count === 0)
|
|
203
|
+
return null;
|
|
204
|
+
return {
|
|
205
|
+
...(typeof hold.holdId === "string" && hold.holdId ? { holdId: hold.holdId } : {}),
|
|
206
|
+
count,
|
|
207
|
+
paths,
|
|
208
|
+
directions: [...directions].sort(),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export function heldLocalBodiesHandoverLine(vaultUid, held) {
|
|
212
|
+
if (held.readFailed) {
|
|
213
|
+
return `${vaultUid}: not handed back to the current sync yet: the new sync engine's hold file could not be read just now, so it may hold local copies the current sync would replace; the vault stays off both syncs until the file can be read`;
|
|
214
|
+
}
|
|
215
|
+
const shown = held.paths.slice(0, HELD_DELETE_LOG_LIMIT).map((entry) => printable(entry.path));
|
|
216
|
+
const more = held.count > shown.length ? `; and ${held.count - shown.length} more` : "";
|
|
217
|
+
const id = held.holdId ? ` (hold ${/^[A-Za-z0-9_-]{1,64}$/.test(held.holdId) ? held.holdId : printable(held.holdId)})` : "";
|
|
218
|
+
const kinds = held.directions.map((direction) => printable(direction.slice(0, 64))).join(", ");
|
|
219
|
+
return `${vaultUid}: not handed back to the current sync yet: the new sync engine held ${held.count} change${held.count === 1 ? "" : "s"} that keep this device's copy (${kinds})${id}, and the current sync would replace those local copies with the vault's; the local copies stay as they are and the vault stays off both syncs until the new sync engine can run this vault again and the hold is decided: ${shown.join(", ")}${more}`;
|
|
220
|
+
}
|
|
128
221
|
function printable(value) {
|
|
129
222
|
return JSON.stringify(value);
|
|
130
223
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SyncCoreVaultSettings } from "./vault-settings.js";
|
|
2
|
+
import { type ClientHealthSyncEngineSafety } from "../../utils/client-health-contract.js";
|
|
2
3
|
export type SyncCoreVaultKind = "personal" | "company";
|
|
3
4
|
export type SyncCoreVaultPhase = "warming" | "full";
|
|
4
5
|
export interface SyncCoreVault {
|
|
@@ -54,6 +55,7 @@ export interface SyncCoreFirstCycle {
|
|
|
54
55
|
truncated: boolean;
|
|
55
56
|
}
|
|
56
57
|
export declare const SYNC_CORE_STATUS_WORK_LIMIT = 20;
|
|
58
|
+
export declare const SYNC_CORE_STATUS_FILE_MAX_BYTES: number;
|
|
57
59
|
export declare function engineFirstCycle(engineHome: string, vaultUid: string, since: string): SyncCoreFirstCycle | null;
|
|
58
60
|
export interface SyncCoreLastCycle extends SyncCoreFirstCycle {
|
|
59
61
|
fullVault: boolean;
|
|
@@ -92,6 +94,7 @@ export interface SyncCoreEngineStatus {
|
|
|
92
94
|
wakeChannel?: SyncCoreWakeChannel;
|
|
93
95
|
cycle?: SyncCoreRunningCycle;
|
|
94
96
|
lastCycle?: SyncCoreLastCycle;
|
|
97
|
+
safety?: ClientHealthSyncEngineSafety;
|
|
95
98
|
}
|
|
96
99
|
export declare const SYNC_CORE_CYCLE_STALE_MS = 120000;
|
|
97
100
|
export declare function readEngineStatus(engineHome: string, vaultUid: string, now?: Date): SyncCoreEngineStatus | null;
|
|
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { parse as parseToml } from "smol-toml";
|
|
4
4
|
import { compareSyncCoreReleases } from "./release-compare.js";
|
|
5
|
+
import { CLIENT_HEALTH_MAX_SYNC_ENGINE_COUNT, } from "../../utils/client-health-contract.js";
|
|
5
6
|
export const SYNC_CORE_REQUESTS_PER_DAY = 20_000;
|
|
6
7
|
// The first engine release with no daily request count; it ignores `requests_per_day`.
|
|
7
8
|
export const SYNC_CORE_REQUEST_COUNT_REMOVED_IN = "v0.1.29";
|
|
@@ -94,9 +95,14 @@ export const SYNC_CORE_STATUS_WORK_LIMIT = 20;
|
|
|
94
95
|
function count(value) {
|
|
95
96
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
96
97
|
}
|
|
98
|
+
export const SYNC_CORE_STATUS_FILE_MAX_BYTES = 1024 * 1024;
|
|
97
99
|
function readStatusFile(engineHome) {
|
|
98
100
|
try {
|
|
99
|
-
|
|
101
|
+
const file = path.join(engineHome, ".hq", "sync-core", "status.json");
|
|
102
|
+
const stat = fs.lstatSync(file);
|
|
103
|
+
if (!stat.isFile() || stat.size > SYNC_CORE_STATUS_FILE_MAX_BYTES)
|
|
104
|
+
return undefined;
|
|
105
|
+
return record(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
100
106
|
}
|
|
101
107
|
catch {
|
|
102
108
|
return undefined;
|
|
@@ -204,6 +210,38 @@ function vaultWakeChannel(value, vaultUid) {
|
|
|
204
210
|
const since = isoTime(channel.since_ms);
|
|
205
211
|
return { connected: channel.connected, ...(since ? { since } : {}) };
|
|
206
212
|
}
|
|
213
|
+
const SAFETY_COUNTER_NAMES = [
|
|
214
|
+
["vault_deletes", "vaultDeletes"],
|
|
215
|
+
["local_deletes", "localDeletes"],
|
|
216
|
+
["download_trashed", "downloadTrashed"],
|
|
217
|
+
["conflict_backups", "conflictBackups"],
|
|
218
|
+
["local_replaced", "localReplaced"],
|
|
219
|
+
["uploads_over", "uploadsOver"],
|
|
220
|
+
["refused_deletes", "refusedDeletes"],
|
|
221
|
+
["refused_uploads", "refusedUploads"],
|
|
222
|
+
["adoptions", "adoptions"],
|
|
223
|
+
];
|
|
224
|
+
function vaultSafety(value, vaultUid) {
|
|
225
|
+
if (!Array.isArray(value))
|
|
226
|
+
return undefined;
|
|
227
|
+
const counters = record(value.map(record).find((item) => item?.vault === vaultUid)?.counters);
|
|
228
|
+
if (!counters)
|
|
229
|
+
return undefined;
|
|
230
|
+
const safety = {};
|
|
231
|
+
for (const [engineName, name] of SAFETY_COUNTER_NAMES) {
|
|
232
|
+
const counter = record(counters[engineName]);
|
|
233
|
+
const total = Math.min(wholeCount(counter?.total), CLIENT_HEALTH_MAX_SYNC_ENGINE_COUNT);
|
|
234
|
+
if (!counter || total === 0)
|
|
235
|
+
continue;
|
|
236
|
+
const lastAtMs = Math.floor(timestampMs(counter.last_at_ms) ?? 0);
|
|
237
|
+
safety[name] = {
|
|
238
|
+
total,
|
|
239
|
+
last24h: Math.min(wholeCount(counter.last_24h), CLIENT_HEALTH_MAX_SYNC_ENGINE_COUNT),
|
|
240
|
+
...(lastAtMs > 0 ? { lastAtMs } : {}),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return safety;
|
|
244
|
+
}
|
|
207
245
|
export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
208
246
|
const status = readStatusFile(engineHome);
|
|
209
247
|
if (!status)
|
|
@@ -218,6 +256,7 @@ export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
|
218
256
|
const transfersQueued = cycle ? wholeCount(cycle.transfers_queued) : 0;
|
|
219
257
|
const running = runningCycle(status.cycle, vaultUid, now);
|
|
220
258
|
const wakeChannel = vaultWakeChannel(status.wakes, vaultUid);
|
|
259
|
+
const safety = vaultSafety(status.safety, vaultUid);
|
|
221
260
|
return {
|
|
222
261
|
...(typeof status.engine_version === "string" && status.engine_version ? { engineVersion: status.engine_version } : {}),
|
|
223
262
|
...(startedAt ? { startedAt } : {}),
|
|
@@ -226,6 +265,7 @@ export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
|
|
|
226
265
|
: {}),
|
|
227
266
|
...(running ? { cycle: running } : {}),
|
|
228
267
|
...(wakeChannel ? { wakeChannel } : {}),
|
|
268
|
+
...(safety ? { safety } : {}),
|
|
229
269
|
...(cycle && atMs !== undefined
|
|
230
270
|
? {
|
|
231
271
|
lastCycle: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readLocalOverride } from "@indigoai-us/hq-flags-client";
|
|
2
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
2
3
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
3
4
|
export const SYNC_RUST_ENGINE_ROLLOUT_FLAG = "sync.rust-engine-rollout-v3";
|
|
4
5
|
const READ_TIMEOUT_MS = 5_000;
|
|
@@ -7,6 +7,7 @@ export interface HandBackVault {
|
|
|
7
7
|
legacyAlreadyOff?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare function engineOwnsVault(home: string, uid: string): boolean;
|
|
10
|
+
export declare function engineHoldBlocksHandBack(home: string, uid: string): boolean;
|
|
10
11
|
/**
|
|
11
12
|
* Returns vaults whose engine has stopped to the current sync: turns the
|
|
12
13
|
* old-sync switch back on (not for a vault the user had off before the move),
|
|
@@ -2,11 +2,15 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { legacySwitchRestorePatch, writeVaultSyncSwitches } from "../vault-sync-switches.js";
|
|
4
4
|
import { removeEngineOwnership, syncCoreEngineHome } from "./engine-home.js";
|
|
5
|
+
import { readEngineHeldLocalBodies } from "./engine-holds.js";
|
|
5
6
|
import { removeLegacyJournalExport } from "./legacy-journal-export.js";
|
|
6
7
|
const reportedRemovalFailures = new Set();
|
|
7
8
|
export function engineOwnsVault(home, uid) {
|
|
8
9
|
return fs.existsSync(path.join(syncCoreEngineHome(home, uid), ".hq", "sync-core", "owned", `${uid}.json`));
|
|
9
10
|
}
|
|
11
|
+
export function engineHoldBlocksHandBack(home, uid) {
|
|
12
|
+
return readEngineHeldLocalBodies(syncCoreEngineHome(home, uid), uid) !== null;
|
|
13
|
+
}
|
|
10
14
|
/**
|
|
11
15
|
* Returns vaults whose engine has stopped to the current sync: turns the
|
|
12
16
|
* old-sync switch back on (not for a vault the user had off before the move),
|
|
@@ -15,10 +19,11 @@ export function engineOwnsVault(home, uid) {
|
|
|
15
19
|
* before removing any record when menubar.json cannot be written.
|
|
16
20
|
*/
|
|
17
21
|
export function finishLegacyHandBack(home, vaults, switches, warn = (line) => void process.stderr.write(`${line}\n`), removeExport = removeLegacyJournalExport) {
|
|
18
|
-
const
|
|
22
|
+
const ready = vaults.filter((vault) => !engineHoldBlocksHandBack(home, vault.uid));
|
|
23
|
+
const patch = legacySwitchRestorePatch(ready, switches);
|
|
19
24
|
if (patch.personal || Object.keys(patch.companies).length > 0)
|
|
20
25
|
writeVaultSyncSwitches(home, patch);
|
|
21
|
-
for (const vault of
|
|
26
|
+
for (const vault of ready) {
|
|
22
27
|
const key = `${home}\0${vault.uid}`;
|
|
23
28
|
try {
|
|
24
29
|
removeExport(home, vault);
|
|
@@ -4,8 +4,10 @@ import { writeLegacyJournalExport } from "./legacy-journal-export.js";
|
|
|
4
4
|
import { loadLegacyJournalReader } from "./legacy-journal-reader.js";
|
|
5
5
|
const [home, uid, slug, offSince] = process.argv.slice(2);
|
|
6
6
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const cutoff = offSince ? Date.parse(offSince) : Number.NaN;
|
|
8
|
+
if (!home || !uid || !slug || !Number.isFinite(cutoff)) {
|
|
9
|
+
throw new Error("usage: legacy-journal-export-child <home> <vault uid> <slug> <time the current sync's switch was turned off>");
|
|
10
|
+
}
|
|
9
11
|
const loaded = await loadLegacyJournalReader([currentHqCloud(daemonPaths(home, process.env).root), bundledHqCloud()]);
|
|
10
12
|
if (!loaded.reader)
|
|
11
13
|
throw new Error(loaded.reason);
|
|
@@ -13,7 +15,7 @@ try {
|
|
|
13
15
|
home,
|
|
14
16
|
vault: { uid, kind: "company", slug },
|
|
15
17
|
readJournal: loaded.reader,
|
|
16
|
-
|
|
18
|
+
offSince: cutoff,
|
|
17
19
|
});
|
|
18
20
|
process.exit(0);
|
|
19
21
|
}
|
|
@@ -13,18 +13,30 @@ export type LegacyJournalExportResult = {
|
|
|
13
13
|
file: string;
|
|
14
14
|
replaced: boolean;
|
|
15
15
|
} | {
|
|
16
|
-
status: "present" | "consumed" | "not-company" | "no-journal";
|
|
16
|
+
status: "present" | "consumed" | "stale" | "not-company" | "no-journal" | "no-cutoff" | "nothing-to-export";
|
|
17
|
+
};
|
|
18
|
+
export type LegacyJournalExportState = "present" | "unusable" | "consumed" | "stale" | "missing" | "not-company";
|
|
19
|
+
export type StaleLegacyJournalDrop = {
|
|
20
|
+
status: "none" | "removed";
|
|
21
|
+
} | {
|
|
22
|
+
status: "failed";
|
|
23
|
+
reason: string;
|
|
17
24
|
};
|
|
18
|
-
export type LegacyJournalExportState = "present" | "unusable" | "consumed" | "missing" | "not-company";
|
|
19
25
|
export declare const LEGACY_JOURNAL_EXPORT_MAX_BYTES: number;
|
|
20
26
|
export declare const LEGACY_JOURNAL_EXPORT_MAX_AHEAD_MS: number;
|
|
21
27
|
export declare function legacyJournalExportPath(home: string, uid: string, slug: string): string;
|
|
22
28
|
export declare function legacyJournalConsumedPath(home: string, uid: string, slug: string): string;
|
|
23
29
|
export declare function legacyJournalUnprovenPath(home: string, uid: string, slug: string): string;
|
|
30
|
+
export declare function legacyJournalStalePath(home: string, uid: string, slug: string): string;
|
|
24
31
|
export declare function legacyJournalExportState(home: string, vault: LegacyJournalExportVault, now?: number): LegacyJournalExportState;
|
|
25
|
-
export declare function legacyStateDir(home: string, env: NodeJS.ProcessEnv): string;
|
|
26
32
|
export declare function legacyStateDirs(home: string, env: NodeJS.ProcessEnv): string[];
|
|
27
33
|
export declare function legacyJournalDirs(home: string, env: NodeJS.ProcessEnv, slug: string): string[];
|
|
34
|
+
export interface MergeLegacyJournalOptions {
|
|
35
|
+
offSince: number | undefined;
|
|
36
|
+
now: number;
|
|
37
|
+
platform?: NodeJS.Platform;
|
|
38
|
+
}
|
|
39
|
+
export declare function mergeLegacyJournalFiles(journals: readonly Record<string, unknown>[], opts: MergeLegacyJournalOptions): Record<string, unknown>;
|
|
28
40
|
export declare function removeLegacyJournalTemps(home: string, vault: LegacyJournalExportVault): void;
|
|
29
41
|
export interface WriteLegacyJournalExportOptions {
|
|
30
42
|
home: string;
|
|
@@ -33,7 +45,14 @@ export interface WriteLegacyJournalExportOptions {
|
|
|
33
45
|
env?: NodeJS.ProcessEnv;
|
|
34
46
|
now?: () => number;
|
|
35
47
|
offSince?: number;
|
|
48
|
+
platform?: NodeJS.Platform;
|
|
36
49
|
}
|
|
37
50
|
export declare function writeLegacyJournalExport(opts: WriteLegacyJournalExportOptions): LegacyJournalExportResult;
|
|
38
|
-
export declare function removeLegacyJournalExport(home: string, vault: LegacyJournalExportVault
|
|
51
|
+
export declare function removeLegacyJournalExport(home: string, vault: LegacyJournalExportVault, removeFiles?: (home: string, vault: LegacyJournalExportVault & {
|
|
52
|
+
slug: string;
|
|
53
|
+
}) => void): void;
|
|
54
|
+
export declare function markLegacyJournalExportStale(home: string, vault: LegacyJournalExportVault): void;
|
|
55
|
+
export declare function dropStaleLegacyJournalExport(home: string, vault: LegacyJournalExportVault, removeFiles?: (home: string, vault: LegacyJournalExportVault & {
|
|
56
|
+
slug: string;
|
|
57
|
+
}) => void): StaleLegacyJournalDrop;
|
|
39
58
|
//# sourceMappingURL=legacy-journal-export.d.ts.map
|
|
@@ -20,6 +20,9 @@ export function legacyJournalConsumedPath(home, uid, slug) {
|
|
|
20
20
|
export function legacyJournalUnprovenPath(home, uid, slug) {
|
|
21
21
|
return `${legacyJournalExportPath(home, uid, slug)}.unproven`;
|
|
22
22
|
}
|
|
23
|
+
export function legacyJournalStalePath(home, uid, slug) {
|
|
24
|
+
return `${legacyJournalExportPath(home, uid, slug)}.stale`;
|
|
25
|
+
}
|
|
23
26
|
function exportable(vault) {
|
|
24
27
|
return vault.kind === "company" && vault.uid.startsWith("cmp_") && typeof vault.slug === "string" && SLUG.test(vault.slug);
|
|
25
28
|
}
|
|
@@ -29,7 +32,8 @@ function exists(file) {
|
|
|
29
32
|
return true;
|
|
30
33
|
}
|
|
31
34
|
catch (error) {
|
|
32
|
-
|
|
35
|
+
const code = error.code;
|
|
36
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
33
37
|
return false;
|
|
34
38
|
throw error;
|
|
35
39
|
}
|
|
@@ -56,6 +60,8 @@ function usableExport(file, now) {
|
|
|
56
60
|
export function legacyJournalExportState(home, vault, now = Date.now()) {
|
|
57
61
|
if (!exportable(vault))
|
|
58
62
|
return "not-company";
|
|
63
|
+
if (exists(legacyJournalStalePath(home, vault.uid, vault.slug)))
|
|
64
|
+
return "stale";
|
|
59
65
|
if (exists(legacyJournalConsumedPath(home, vault.uid, vault.slug)))
|
|
60
66
|
return "consumed";
|
|
61
67
|
const file = legacyJournalExportPath(home, vault.uid, vault.slug);
|
|
@@ -63,76 +69,104 @@ export function legacyJournalExportState(home, vault, now = Date.now()) {
|
|
|
63
69
|
return "missing";
|
|
64
70
|
return usableExport(file, now) ? "present" : "unusable";
|
|
65
71
|
}
|
|
66
|
-
export function legacyStateDir(home, env) {
|
|
67
|
-
return env.HQ_STATE_DIR ?? path.join(home, ".hq");
|
|
68
|
-
}
|
|
69
72
|
export function legacyStateDirs(home, env) {
|
|
70
|
-
|
|
73
|
+
const machine = machineTokenStateDir(home, env);
|
|
74
|
+
const set = env.HQ_STATE_DIR;
|
|
75
|
+
if (set && path.resolve(set) !== path.resolve(machine))
|
|
76
|
+
return [set];
|
|
77
|
+
return [path.join(home, ".hq"), machine];
|
|
71
78
|
}
|
|
72
79
|
export function legacyJournalDirs(home, env, slug) {
|
|
73
80
|
return legacyStateDirs(home, env).filter((dir) => fs.existsSync(path.join(dir, `sync-journal.${slug}.json`)));
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return Number.isFinite(ms) ? ms : 0;
|
|
82
|
+
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
|
|
83
|
+
function timeMs(value, now) {
|
|
84
|
+
if (typeof value !== "string" || !ISO_TIME.test(value))
|
|
85
|
+
return Number.NaN;
|
|
86
|
+
const at = Date.parse(value);
|
|
87
|
+
return at <= now ? at : Number.NaN;
|
|
82
88
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
89
|
+
function rankMs(entry, now) {
|
|
90
|
+
const synced = timeMs(entry.syncedAt, now);
|
|
91
|
+
if (!Number.isFinite(synced))
|
|
92
|
+
return Number.NaN;
|
|
93
|
+
if (entry.removedAt === undefined || entry.removedAt === null)
|
|
94
|
+
return synced;
|
|
95
|
+
const removed = timeMs(entry.removedAt, now);
|
|
96
|
+
return Number.isFinite(removed) ? Math.max(synced, removed) : Number.NaN;
|
|
91
97
|
}
|
|
92
|
-
function
|
|
93
|
-
return
|
|
98
|
+
function sameValue(a, b) {
|
|
99
|
+
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
94
100
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
101
|
+
function foldedPath(key) {
|
|
102
|
+
return key.normalize("NFC").toLowerCase();
|
|
97
103
|
}
|
|
98
|
-
function lastSyncedEntries(slug, dirs, readJournal,
|
|
104
|
+
function lastSyncedEntries(slug, dirs, readJournal, opts) {
|
|
99
105
|
const read = dirs
|
|
100
|
-
.map((dir) =>
|
|
101
|
-
|
|
102
|
-
return { dir, files, count: files && typeof files === "object" ? Object.keys(files).length : 0 };
|
|
103
|
-
})
|
|
104
|
-
.filter((journal) => journal.count > 0);
|
|
106
|
+
.map((dir) => readJournal(slug, dir).files)
|
|
107
|
+
.filter((files) => files && typeof files === "object" && Object.keys(files).length > 0);
|
|
105
108
|
if (read.length === 0)
|
|
106
109
|
throw new Error(`the current sync has a journal for ${slug} but it read as empty`);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
return mergeLegacyJournalFiles(read, opts);
|
|
111
|
+
}
|
|
112
|
+
export function mergeLegacyJournalFiles(journals, opts) {
|
|
113
|
+
const out = Object.create(null);
|
|
114
|
+
const cutoff = opts.offSince;
|
|
115
|
+
if (cutoff === undefined || !Number.isFinite(cutoff))
|
|
116
|
+
return out;
|
|
117
|
+
const platform = opts.platform ?? process.platform;
|
|
118
|
+
const folds = platform === "darwin" || platform === "win32";
|
|
112
119
|
const merged = Object.create(null);
|
|
120
|
+
const leftOut = new Set();
|
|
113
121
|
const disputed = new Set();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
const spelled = new Map();
|
|
123
|
+
const collided = new Set();
|
|
124
|
+
for (const files of journals) {
|
|
125
|
+
for (const key of Object.keys(files)) {
|
|
126
|
+
if (folds) {
|
|
127
|
+
const folded = foldedPath(key);
|
|
128
|
+
const first = spelled.get(folded);
|
|
129
|
+
if (first === undefined)
|
|
130
|
+
spelled.set(folded, key);
|
|
131
|
+
else if (first !== key)
|
|
132
|
+
collided.add(folded);
|
|
133
|
+
}
|
|
134
|
+
const value = files[key];
|
|
135
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
136
|
+
continue;
|
|
137
|
+
const entry = value;
|
|
138
|
+
const at = rankMs(entry, opts.now);
|
|
139
|
+
if (!Number.isFinite(at)) {
|
|
140
|
+
leftOut.add(key);
|
|
119
141
|
continue;
|
|
120
142
|
}
|
|
121
143
|
const kept = merged[key];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (at > keptAt) {
|
|
125
|
-
merged[key] = entry;
|
|
144
|
+
if (!kept || at > kept.at) {
|
|
145
|
+
merged[key] = { entry, at };
|
|
126
146
|
disputed.delete(key);
|
|
127
147
|
}
|
|
128
|
-
else if (at ===
|
|
129
|
-
|
|
148
|
+
else if (at === kept.at) {
|
|
149
|
+
if (entry.hash === kept.entry.hash
|
|
150
|
+
&& sameValue(entry.removedAt, kept.entry.removedAt)
|
|
151
|
+
&& sameValue(entry.localDeleteIntent, kept.entry.localDeleteIntent)) {
|
|
152
|
+
if (entry.localDiverges === true && kept.entry.localDiverges !== true)
|
|
153
|
+
merged[key] = { entry: { ...kept.entry, localDiverges: true }, at };
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
disputed.add(key);
|
|
157
|
+
}
|
|
130
158
|
}
|
|
131
159
|
}
|
|
132
160
|
}
|
|
133
|
-
for (const key of
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
for (const key of Object.keys(merged)) {
|
|
162
|
+
const { entry, at } = merged[key];
|
|
163
|
+
if (leftOut.has(key) || disputed.has(key) || at > cutoff)
|
|
164
|
+
continue;
|
|
165
|
+
if (folds && collided.has(foldedPath(key)))
|
|
166
|
+
continue;
|
|
167
|
+
out[key] = entry;
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
136
170
|
}
|
|
137
171
|
export function removeLegacyJournalTemps(home, vault) {
|
|
138
172
|
if (!exportable(vault))
|
|
@@ -170,12 +204,16 @@ export function writeLegacyJournalExport(opts) {
|
|
|
170
204
|
const state = legacyJournalExportState(home, vault, now());
|
|
171
205
|
if (state !== "missing" && state !== "unusable")
|
|
172
206
|
return { status: state };
|
|
207
|
+
if (opts.offSince === undefined || !Number.isFinite(opts.offSince))
|
|
208
|
+
return { status: "no-cutoff" };
|
|
173
209
|
const slug = vault.slug;
|
|
174
210
|
const dirs = legacyJournalDirs(home, opts.env ?? process.env, slug);
|
|
175
211
|
if (dirs.length === 0)
|
|
176
212
|
return { status: "no-journal" };
|
|
177
|
-
const files = lastSyncedEntries(slug, dirs, opts.readJournal, opts.offSince);
|
|
213
|
+
const files = lastSyncedEntries(slug, dirs, opts.readJournal, { offSince: opts.offSince, now: now(), platform: opts.platform });
|
|
178
214
|
const keys = Object.keys(files);
|
|
215
|
+
if (keys.length === 0)
|
|
216
|
+
return { status: "nothing-to-export" };
|
|
179
217
|
const file = legacyJournalExportPath(home, vault.uid, slug);
|
|
180
218
|
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
181
219
|
removeLegacyJournalTemps(home, vault);
|
|
@@ -198,8 +236,6 @@ export function writeLegacyJournalExport(opts) {
|
|
|
198
236
|
}
|
|
199
237
|
}
|
|
200
238
|
fs.writeSync(fd, `${chunk.join("")}}}\n`);
|
|
201
|
-
if (entries === 0)
|
|
202
|
-
throw new Error(`the current sync's journal for ${slug} has no usable entries`);
|
|
203
239
|
if (fs.fstatSync(fd).size > LEGACY_JOURNAL_EXPORT_MAX_BYTES) {
|
|
204
240
|
throw new Error(`the copy of the current sync's journal for ${slug} is over ${LEGACY_JOURNAL_EXPORT_MAX_BYTES / (1024 * 1024)} MB, more than the new sync engine reads`);
|
|
205
241
|
}
|
|
@@ -229,13 +265,42 @@ export function writeLegacyJournalExport(opts) {
|
|
|
229
265
|
throw error;
|
|
230
266
|
}
|
|
231
267
|
}
|
|
232
|
-
|
|
233
|
-
if (!exportable(vault))
|
|
234
|
-
return;
|
|
268
|
+
function removeExportFiles(home, vault) {
|
|
235
269
|
const file = legacyJournalExportPath(home, vault.uid, vault.slug);
|
|
236
270
|
for (const target of [file, `${file}.consumed`, `${file}.unproven`, `${file}.unproven.bad`]) {
|
|
237
271
|
fs.rmSync(target, { recursive: true, force: true });
|
|
238
272
|
}
|
|
239
273
|
removeLegacyJournalTemps(home, vault);
|
|
240
274
|
}
|
|
275
|
+
export function removeLegacyJournalExport(home, vault, removeFiles = removeExportFiles) {
|
|
276
|
+
if (!exportable(vault))
|
|
277
|
+
return;
|
|
278
|
+
markLegacyJournalExportStale(home, vault);
|
|
279
|
+
removeFiles(home, vault);
|
|
280
|
+
fs.rmSync(legacyJournalStalePath(home, vault.uid, vault.slug), { force: true });
|
|
281
|
+
}
|
|
282
|
+
export function markLegacyJournalExportStale(home, vault) {
|
|
283
|
+
if (!exportable(vault))
|
|
284
|
+
return;
|
|
285
|
+
const file = legacyJournalExportPath(home, vault.uid, vault.slug);
|
|
286
|
+
const marker = legacyJournalStalePath(home, vault.uid, vault.slug);
|
|
287
|
+
if (exists(marker) || ![file, `${file}.consumed`, `${file}.unproven`].some(exists))
|
|
288
|
+
return;
|
|
289
|
+
fs.writeFileSync(marker, "{}\n", { mode: 0o600 });
|
|
290
|
+
}
|
|
291
|
+
export function dropStaleLegacyJournalExport(home, vault, removeFiles = removeExportFiles) {
|
|
292
|
+
if (!exportable(vault))
|
|
293
|
+
return { status: "none" };
|
|
294
|
+
const marker = legacyJournalStalePath(home, vault.uid, vault.slug);
|
|
295
|
+
if (!exists(marker))
|
|
296
|
+
return { status: "none" };
|
|
297
|
+
try {
|
|
298
|
+
removeFiles(home, vault);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
return { status: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
302
|
+
}
|
|
303
|
+
fs.rmSync(marker, { force: true });
|
|
304
|
+
return { status: "removed" };
|
|
305
|
+
}
|
|
241
306
|
//# sourceMappingURL=legacy-journal-export.js.map
|
|
@@ -2,7 +2,7 @@ import { type SyncCoreVault } from "./engine-home.js";
|
|
|
2
2
|
import { type SyncCoreBinaryInstall, type SyncCorePin } from "./release.js";
|
|
3
3
|
import type { MachineType } from "../daemon/machine-type.js";
|
|
4
4
|
import { type SyncCoreCompanyEntity } from "./company-adoption.js";
|
|
5
|
-
import { type LegacyJournalReader } from "./legacy-journal-export.js";
|
|
5
|
+
import { dropStaleLegacyJournalExport, type LegacyJournalReader } from "./legacy-journal-export.js";
|
|
6
6
|
import { type SyncCoreRolloutState } from "./rollout-state.js";
|
|
7
7
|
export interface SyncCoreMembership {
|
|
8
8
|
companyUid: string;
|
|
@@ -30,6 +30,7 @@ export interface SyncCoreReconcileDeps {
|
|
|
30
30
|
resolveCompany?: (companyUid: string) => Promise<SyncCoreCompanyEntity | null>;
|
|
31
31
|
readLegacyJournal?: LegacyJournalReader;
|
|
32
32
|
legacyJournalUnavailable?: string;
|
|
33
|
+
removeStaleLegacyJournalFiles?: Parameters<typeof dropStaleLegacyJournalExport>[2];
|
|
33
34
|
/** Only desktop and self-hosted machines set up a joined company. */
|
|
34
35
|
machineType?: MachineType;
|
|
35
36
|
ensureBinary: (release: string) => Promise<SyncCoreBinaryInstall>;
|