@indigoai-us/hq-cli 5.345.243 → 5.345.245
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/dist/command-catalog.generated.d.ts +3 -3
- package/dist/command-catalog.generated.js +3 -3
- package/dist/commands/bot.d.ts +12 -0
- package/dist/commands/bot.js +126 -44
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +2087 -1830
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/bot/config.d.ts +10 -0
- package/dist/lib/bot/config.js +15 -0
- package/dist/lib/bot/continuity.js +2 -2
- package/dist/lib/bot/promote-sign-in.d.ts +78 -0
- package/dist/lib/bot/promote-sign-in.js +152 -0
- package/dist/lib/bot/promote.d.ts +19 -1
- package/dist/lib/bot/promote.js +25 -5
- package/dist/lib/bot/scaffold.d.ts +20 -3
- package/dist/lib/bot/scaffold.js +18 -8
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +10 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +86 -42
- package/dist/lib/daemon/hook-requests.d.ts +2 -2
- package/dist/lib/daemon/hook-requests.js +13 -3
- 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/lanes/liveness.js +46 -16
- package/dist/lib/sync-core/engine-holds.d.ts +17 -1
- package/dist/lib/sync-core/engine-holds.js +73 -3
- package/dist/lib/sync-core/reconcile.js +10 -2
- package/package.json +8 -8
|
@@ -189,10 +189,20 @@ export function ingestSpoolLine(line, sessions, lineNo) {
|
|
|
189
189
|
entry.lastSeq = seq;
|
|
190
190
|
sessions[sessionId] = entry;
|
|
191
191
|
}
|
|
192
|
-
/** 64 KiB.
|
|
192
|
+
/** 64 KiB. The spool is read in chunks of this size, never as one string. */
|
|
193
193
|
const SPOOL_READ_CHUNK = 64 * 1024;
|
|
194
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* A spool line longer than this is skipped whole with a warning. Liveness
|
|
196
|
+
* events are small JSON (well under 1 KiB), so this only bounds memory when a
|
|
197
|
+
* line is corrupt or has no newline.
|
|
198
|
+
*/
|
|
195
199
|
const SPOOL_MAX_LINE = 1_048_576;
|
|
200
|
+
/**
|
|
201
|
+
* Visit each spool line, reading the file in fixed-size chunks. Lines are
|
|
202
|
+
* split on the raw newline byte and decoded only once complete, so a
|
|
203
|
+
* multi-byte UTF-8 character cut by a chunk boundary stays intact. Line
|
|
204
|
+
* numbers match a whole-file `split("\n")`.
|
|
205
|
+
*/
|
|
196
206
|
function ingestSpoolFile(spoolPath, sessions, deps) {
|
|
197
207
|
const openSync = deps.openSync ?? fs.openSync;
|
|
198
208
|
const readSync = deps.readSync ?? fs.readSync;
|
|
@@ -200,27 +210,47 @@ function ingestSpoolFile(spoolPath, sessions, deps) {
|
|
|
200
210
|
const fd = openSync(spoolPath, "r");
|
|
201
211
|
try {
|
|
202
212
|
const buf = Buffer.alloc(SPOOL_READ_CHUNK);
|
|
203
|
-
let
|
|
213
|
+
let pending = [];
|
|
214
|
+
let pendingBytes = 0;
|
|
215
|
+
let oversized = false;
|
|
204
216
|
let lineNo = 0;
|
|
217
|
+
const finishLine = (tail) => {
|
|
218
|
+
lineNo += 1;
|
|
219
|
+
if (oversized) {
|
|
220
|
+
process.stderr.write(`lanes liveness: skipping oversized spool line ${lineNo}\n`);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
const bytes = pending.length > 0 ? Buffer.concat([...pending, tail]) : tail;
|
|
224
|
+
ingestSpoolLine(bytes.toString("utf8"), sessions, lineNo);
|
|
225
|
+
}
|
|
226
|
+
pending = [];
|
|
227
|
+
pendingBytes = 0;
|
|
228
|
+
oversized = false;
|
|
229
|
+
};
|
|
205
230
|
for (;;) {
|
|
206
231
|
const n = readSync(fd, buf, 0, buf.length, null);
|
|
207
232
|
if (n === 0)
|
|
208
233
|
break;
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
234
|
+
const chunk = buf.subarray(0, n);
|
|
235
|
+
let start = 0;
|
|
236
|
+
for (let nl = chunk.indexOf(0x0a, start); nl !== -1; nl = chunk.indexOf(0x0a, start)) {
|
|
237
|
+
finishLine(chunk.subarray(start, nl));
|
|
238
|
+
start = nl + 1;
|
|
239
|
+
}
|
|
240
|
+
if (start < n && !oversized) {
|
|
241
|
+
pendingBytes += n - start;
|
|
242
|
+
if (pendingBytes > SPOOL_MAX_LINE) {
|
|
243
|
+
oversized = true;
|
|
244
|
+
pending = [];
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
// Copy: buf is reused by the next read.
|
|
248
|
+
pending.push(Buffer.from(chunk.subarray(start)));
|
|
249
|
+
}
|
|
216
250
|
}
|
|
217
|
-
if (leftover.length > SPOOL_MAX_LINE)
|
|
218
|
-
leftover = "";
|
|
219
|
-
}
|
|
220
|
-
if (leftover) {
|
|
221
|
-
lineNo += 1;
|
|
222
|
-
ingestSpoolLine(leftover, sessions, lineNo);
|
|
223
251
|
}
|
|
252
|
+
if (oversized || pendingBytes > 0)
|
|
253
|
+
finishLine(Buffer.alloc(0));
|
|
224
254
|
}
|
|
225
255
|
finally {
|
|
226
256
|
closeSync(fd);
|
|
@@ -8,7 +8,23 @@ export interface EngineHeldDeletes {
|
|
|
8
8
|
count: number;
|
|
9
9
|
deletes: EngineHeldDelete[];
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* hq-cloud's runner reads this file and never applies a delete it lists: the
|
|
13
|
+
* server copy stays (and downloads again when the local file is missing) and
|
|
14
|
+
* the local copy stays. The runner drops a path after a later positive signal.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handbackKeepFile(home: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Adds a vault's held deletes to the hand-back keep list, merged with any
|
|
19
|
+
* paths already listed for it. Throws when the file cannot be written.
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeHandbackKeep(home: string, vault: {
|
|
22
|
+
uid: string;
|
|
23
|
+
slug?: string;
|
|
24
|
+
}, held: EngineHeldDeletes, at: string,
|
|
25
|
+
/** Test seam: runs after the temp file is written, before the re-read that guards the rename. */
|
|
26
|
+
beforeRename?: (attempt: number) => void): void;
|
|
11
27
|
export declare function engineHoldFile(engineHome: string, vaultUid: string): string;
|
|
12
28
|
export declare function readEngineHeldDeletes(engineHome: string, vaultUid: string): EngineHeldDeletes | "unreadable" | null;
|
|
13
|
-
export declare function heldDeletesHandoverLine(vaultUid: string, held: EngineHeldDeletes | "unreadable", engineHome: string): string;
|
|
29
|
+
export declare function heldDeletesHandoverLine(vaultUid: string, held: EngineHeldDeletes | "unreadable", engineHome: string, home: string): string;
|
|
14
30
|
//# sourceMappingURL=engine-holds.d.ts.map
|
|
@@ -5,6 +5,76 @@ const HOLD_FILE_MAX_BYTES = 16 * 1024 * 1024;
|
|
|
5
5
|
function record(value) {
|
|
6
6
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* hq-cloud's runner reads this file and never applies a delete it lists: the
|
|
10
|
+
* server copy stays (and downloads again when the local file is missing) and
|
|
11
|
+
* the local copy stays. The runner drops a path after a later positive signal.
|
|
12
|
+
*/
|
|
13
|
+
export function handbackKeepFile(home) {
|
|
14
|
+
return path.join(home, ".hq", "sync-core", "handback-keep.json");
|
|
15
|
+
}
|
|
16
|
+
const HANDBACK_KEEP_VERSION = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Adds a vault's held deletes to the hand-back keep list, merged with any
|
|
19
|
+
* paths already listed for it. Throws when the file cannot be written.
|
|
20
|
+
*/
|
|
21
|
+
export function writeHandbackKeep(home, vault, held, at,
|
|
22
|
+
/** Test seam: runs after the temp file is written, before the re-read that guards the rename. */
|
|
23
|
+
beforeRename) {
|
|
24
|
+
const file = handbackKeepFile(home);
|
|
25
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
26
|
+
for (let attempt = 0; attempt < HANDBACK_KEEP_WRITE_ATTEMPTS; attempt++) {
|
|
27
|
+
const text = readTextOrNull(file);
|
|
28
|
+
let current;
|
|
29
|
+
try {
|
|
30
|
+
current = text === null ? {} : record(JSON.parse(text)) ?? {};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
current = {};
|
|
34
|
+
}
|
|
35
|
+
const vaults = { ...(record(current.vaults) ?? {}) };
|
|
36
|
+
const before = record(vaults[vault.uid]);
|
|
37
|
+
const paths = new Map();
|
|
38
|
+
for (const value of Array.isArray(before?.paths) ? before.paths : []) {
|
|
39
|
+
const entry = record(value);
|
|
40
|
+
if (entry && typeof entry.path === "string")
|
|
41
|
+
paths.set(entry.path, entry);
|
|
42
|
+
}
|
|
43
|
+
for (const entry of held.deletes) {
|
|
44
|
+
const known = paths.get(entry.path);
|
|
45
|
+
paths.set(entry.path, known?.direction === entry.direction ? known : { path: entry.path, direction: entry.direction });
|
|
46
|
+
}
|
|
47
|
+
vaults[vault.uid] = {
|
|
48
|
+
...(vault.slug ? { slug: vault.slug } : {}),
|
|
49
|
+
...(held.holdId ? { holdId: held.holdId } : {}),
|
|
50
|
+
writtenAt: at,
|
|
51
|
+
paths: [...paths.values()],
|
|
52
|
+
};
|
|
53
|
+
const version = typeof current.version === "number" && current.version > HANDBACK_KEEP_VERSION ? current.version : HANDBACK_KEEP_VERSION;
|
|
54
|
+
const temp = `${file}.${process.pid}.${attempt}.tmp`;
|
|
55
|
+
fs.writeFileSync(temp, `${JSON.stringify({ ...current, version, vaults }, null, 2)}\n`, { mode: 0o600 });
|
|
56
|
+
// The runner also rewrites this file: rename only over the version just read.
|
|
57
|
+
beforeRename?.(attempt);
|
|
58
|
+
if (readTextOrNull(file) !== text) {
|
|
59
|
+
fs.rmSync(temp, { force: true });
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
fs.renameSync(temp, file);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`${file} kept changing while it was written`);
|
|
66
|
+
}
|
|
67
|
+
const HANDBACK_KEEP_WRITE_ATTEMPTS = 5;
|
|
68
|
+
function readTextOrNull(file) {
|
|
69
|
+
try {
|
|
70
|
+
return fs.readFileSync(file, "utf8");
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code === "ENOENT")
|
|
74
|
+
return null;
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
8
78
|
export function engineHoldFile(engineHome, vaultUid) {
|
|
9
79
|
return path.join(engineHome, ".hq", "sync-core", "holds", `${vaultUid}.json`);
|
|
10
80
|
}
|
|
@@ -48,13 +118,13 @@ export function readEngineHeldDeletes(engineHome, vaultUid) {
|
|
|
48
118
|
function printable(value) {
|
|
49
119
|
return JSON.stringify(value);
|
|
50
120
|
}
|
|
51
|
-
export function heldDeletesHandoverLine(vaultUid, held, engineHome) {
|
|
121
|
+
export function heldDeletesHandoverLine(vaultUid, held, engineHome, home) {
|
|
52
122
|
if (held === "unreadable") {
|
|
53
|
-
return `${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} could not be read;
|
|
123
|
+
return `${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} could not be read; nothing it held is passed to the current sync, which decides each path again from its own journal and delete checks`;
|
|
54
124
|
}
|
|
55
125
|
const shown = held.deletes.slice(0, HELD_DELETE_LOG_LIMIT).map((entry) => `${entry.direction === "delete_local" ? "local copy of" : "server copy of"} ${printable(entry.path)}`);
|
|
56
126
|
const more = held.count > shown.length ? `; and ${held.count - shown.length} more` : "";
|
|
57
127
|
const id = held.holdId ? ` (hold ${/^[A-Za-z0-9_-]{1,64}$/.test(held.holdId) ? held.holdId : printable(held.holdId)})` : "";
|
|
58
|
-
return `${vaultUid}: switching back with ${held.count} delete${held.count === 1 ? "" : "s"} the new sync engine held${id}; the current sync
|
|
128
|
+
return `${vaultUid}: switching back with ${held.count} delete${held.count === 1 ? "" : "s"} the new sync engine held${id}; the current sync keeps these files and does not apply those deletes (listed in ${handbackKeepFile(home)}): ${shown.join(", ")}${more}`;
|
|
59
129
|
}
|
|
60
130
|
//# sourceMappingURL=engine-holds.js.map
|
|
@@ -7,7 +7,7 @@ import { clearEngineStatus, engineFirstCycle, isSyncCoreVaultUid, removeEngineOw
|
|
|
7
7
|
import { SYNC_CORE_FULL_RELEASE, SYNC_CORE_RELEASE, compareSyncCoreReleases, fullModeAllowed, installedSyncCoreRelease, syncCoreBinaryPath, windowsFullRelease, } from "./release.js";
|
|
8
8
|
import { readSyncCoreSkips } from "./skip.js";
|
|
9
9
|
import { isLiveCompanyEntity, joinedCompanySlug, setUpJoinedCompany } from "./company-adoption.js";
|
|
10
|
-
import { heldDeletesHandoverLine, readEngineHeldDeletes } from "./engine-holds.js";
|
|
10
|
+
import { heldDeletesHandoverLine, readEngineHeldDeletes, writeHandbackKeep } from "./engine-holds.js";
|
|
11
11
|
import { SYNC_RUST_ENGINE_ROLLOUT_FLAG } from "./flag.js";
|
|
12
12
|
import { readSyncCoreRolloutState, syncCoreRolloutStatePath, writeSyncCoreRolloutState, } from "./rollout-state.js";
|
|
13
13
|
function message(error) {
|
|
@@ -336,8 +336,16 @@ export async function reconcileSyncCore(deps) {
|
|
|
336
336
|
continue;
|
|
337
337
|
const engineHome = syncCoreEngineHome(deps.home, vault.uid);
|
|
338
338
|
const heldDeletes = readEngineHeldDeletes(engineHome, vault.uid);
|
|
339
|
+
if (heldDeletes && heldDeletes !== "unreadable") {
|
|
340
|
+
try {
|
|
341
|
+
writeHandbackKeep(deps.home, vault, heldDeletes, at);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
warnings.push(`could not record the ${heldDeletes.count} deletes the new sync engine held for ${vault.uid}; the current sync may apply them: ${message(error)}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
339
347
|
if (heldDeletes)
|
|
340
|
-
handover.push(heldDeletesHandoverLine(vault.uid, heldDeletes, engineHome));
|
|
348
|
+
handover.push(heldDeletesHandoverLine(vault.uid, heldDeletes, engineHome, deps.home));
|
|
341
349
|
handedBack.push(vault);
|
|
342
350
|
}
|
|
343
351
|
const handingBack = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.245",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@aws-sdk/client-iot-data-plane": "^3.1096.0",
|
|
64
64
|
"@aws-sdk/client-s3": "^3.1049.0",
|
|
65
65
|
"@aws-sdk/dsql-signer": "^3.1146.0",
|
|
66
|
-
"@indigoai-us/hq-cloud": "6.18.
|
|
66
|
+
"@indigoai-us/hq-cloud": "6.18.120",
|
|
67
67
|
"@indigoai-us/hq-flags-client": "^0.2.0",
|
|
68
68
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
69
69
|
"@sentry/node": "^10.49.0",
|
|
@@ -126,11 +126,11 @@
|
|
|
126
126
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
127
127
|
},
|
|
128
128
|
"optionalDependencies": {
|
|
129
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
129
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.245",
|
|
130
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.245",
|
|
131
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.245",
|
|
132
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.245",
|
|
133
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.245",
|
|
134
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.245"
|
|
135
135
|
}
|
|
136
136
|
}
|