@indigoai-us/hq-cli 5.345.258 → 5.345.261
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 +58 -0
- package/assets/scaffold/core/scripts/handoff-knowledge-commit.sh +163 -5
- package/assets/scaffold/core/scripts/handoff-post.sh +30 -0
- package/assets/scaffold/core/scripts/handoff-sync-prefetch.sh +39 -0
- package/assets/scaffold/core/scripts/handoff-sync-publish.sh +51 -3
- package/contracts/host-canary-release.json +7 -7
- package/dist/commands/cloud.d.ts +2 -7
- package/dist/commands/cloud.js +2 -29
- package/dist/commands/core-bucket-c-handoff-knowledge-native.d.ts +24 -2
- package/dist/commands/core-bucket-c-handoff-knowledge-native.js +170 -19
- package/dist/commands/core-bucket-c-handoff-sync-native.d.ts +4 -2
- package/dist/commands/core-bucket-c-handoff-sync-native.js +153 -34
- package/dist/commands/core-bucket-c-handoff-sync-worker.cjs +201 -0
- package/dist/commands/core-delegate-w1b.js +17 -16
- package/dist/commands/core-delegate.js +5 -4
- package/dist/commands/core-handoff.d.ts +10 -0
- package/dist/commands/core-handoff.js +138 -16
- package/dist/commands/reindex.d.ts +3 -0
- package/dist/commands/reindex.js +11 -5
- package/dist/commands/rescue.js +7 -2
- package/dist/commands/sync-core.js +24 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +3227 -2138
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/canonical-person.d.ts +19 -0
- package/dist/lib/canonical-person.js +30 -0
- package/dist/lib/company-sessions-cli.d.ts +12 -0
- package/dist/lib/company-sessions-cli.js +54 -0
- package/dist/lib/company-sessions.d.ts +31 -0
- package/dist/lib/company-sessions.js +304 -0
- package/dist/lib/doctor/fix/process-identity.d.ts +13 -0
- package/dist/lib/doctor/fix/process-identity.js +63 -7
- 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/hook-engine/coverage.d.ts +44 -1
- package/dist/lib/hook-engine/coverage.js +129 -1
- package/dist/lib/onboarding/orchestrator.js +4 -2
- package/dist/lib/sync-core/engine-home.d.ts +5 -1
- package/dist/lib/sync-core/engine-home.js +6 -2
- package/dist/lib/sync-core/reconcile.d.ts +5 -0
- package/dist/lib/sync-core/reconcile.js +21 -1
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/utils/delegate-lock.d.ts +18 -0
- package/dist/utils/delegate-lock.js +149 -37
- package/dist/utils/sync-operation-lock.d.ts +2 -1
- package/dist/utils/sync-operation-lock.js +13 -2
- package/package.json +8 -8
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { acquireUpdateLock } from './update-lock.js';
|
|
4
|
-
import
|
|
4
|
+
import * as processIdentity from '../lib/doctor/fix/process-identity.js';
|
|
5
|
+
export function formatDelegateLockError(failure) {
|
|
6
|
+
if (failure.reason === 'busy') {
|
|
7
|
+
return 'verification or delivery is active; retry after it finishes';
|
|
8
|
+
}
|
|
9
|
+
if (failure.reason === 'identity-unavailable') {
|
|
10
|
+
if (failure.timedOut) {
|
|
11
|
+
return 'could not acquire delegate lock: process identity check timed out';
|
|
12
|
+
}
|
|
13
|
+
return failure.detail
|
|
14
|
+
? `could not acquire delegate lock: process identity check unavailable (${failure.detail})`
|
|
15
|
+
: 'could not acquire delegate lock: process identity check unavailable';
|
|
16
|
+
}
|
|
17
|
+
return failure.detail
|
|
18
|
+
? `could not acquire delegate lock: ${failure.detail}`
|
|
19
|
+
: 'could not acquire delegate lock';
|
|
20
|
+
}
|
|
5
21
|
/** A complete owner file is linked into place atomically. Legacy mkdir writers
|
|
6
|
-
* see EEXIST; unknown legacy directories stay held.
|
|
7
|
-
|
|
8
|
-
|
|
22
|
+
* see EEXIST; unknown legacy directories stay held. Returns a structured result
|
|
23
|
+
* so callers can tell a held lock apart from a probe timeout or I/O error. */
|
|
24
|
+
export function acquireDelegateLockDetailed(lock, options = {}) {
|
|
25
|
+
const platform = options.platform ?? process.platform;
|
|
26
|
+
const explicitStartOf = options.startOf;
|
|
27
|
+
const startOf = explicitStartOf ?? ((pid) => processIdentity.processStartTime(pid));
|
|
9
28
|
const now = options.now ?? Date.now;
|
|
10
29
|
const alive = options.alive ?? ((pid) => {
|
|
11
30
|
try {
|
|
@@ -16,15 +35,50 @@ export function acquireDelegateLock(lock, options = {}) {
|
|
|
16
35
|
return error.code !== 'ESRCH';
|
|
17
36
|
}
|
|
18
37
|
});
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
const probeStart = (pid) => {
|
|
39
|
+
const start = startOf(pid);
|
|
40
|
+
if (start)
|
|
41
|
+
return { start, timedOut: false, toolUnavailable: false };
|
|
42
|
+
if (!explicitStartOf && typeof processIdentity.lastProcessStartFailure === 'function') {
|
|
43
|
+
const failure = processIdentity.lastProcessStartFailure();
|
|
44
|
+
if (failure && failure.pid === pid) {
|
|
45
|
+
return {
|
|
46
|
+
start: null,
|
|
47
|
+
timedOut: failure.reason === 'timeout',
|
|
48
|
+
detail: failure.detail,
|
|
49
|
+
toolUnavailable: failure.reason === 'timeout' || failure.reason === 'tool-missing',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { start: null, timedOut: false, toolUnavailable: false };
|
|
54
|
+
};
|
|
55
|
+
// On Windows, reading process start times requires spawning PowerShell, which
|
|
56
|
+
// can exceed its timeout under load and fails when blocked by policy. Skip
|
|
57
|
+
// the self start-time probe on win32 unless a caller injected `startOf`, and
|
|
58
|
+
// rely on Node's native OpenProcess liveness check (`process.kill(pid, 0)`)
|
|
59
|
+
// for stale-lock recovery.
|
|
60
|
+
let ownStart;
|
|
61
|
+
if (explicitStartOf !== undefined || platform !== 'win32') {
|
|
62
|
+
const probe = probeStart(process.pid);
|
|
63
|
+
if (!probe.start) {
|
|
64
|
+
return {
|
|
65
|
+
ok: false,
|
|
66
|
+
reason: 'identity-unavailable',
|
|
67
|
+
timedOut: probe.timedOut,
|
|
68
|
+
detail: probe.detail,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
ownStart = probe.start;
|
|
72
|
+
}
|
|
22
73
|
const coordinate = () => acquireUpdateLock({ lockPath: `${lock}.coord`, tool: 'delegate-lock', heartbeatMs: 0, takeoverWaitMs: 0 });
|
|
23
74
|
const mutex = coordinate();
|
|
24
75
|
if (!mutex)
|
|
25
|
-
return
|
|
76
|
+
return { ok: false, reason: 'busy' };
|
|
26
77
|
const token = randomUUID();
|
|
27
|
-
const
|
|
78
|
+
const ownerRecord = ownStart !== undefined
|
|
79
|
+
? { pid: process.pid, start: ownStart, createdAt: now(), token }
|
|
80
|
+
: { pid: process.pid, createdAt: now(), token };
|
|
81
|
+
const body = JSON.stringify(ownerRecord);
|
|
28
82
|
const staged = `${lock}.pending-${token}`;
|
|
29
83
|
let identity;
|
|
30
84
|
try {
|
|
@@ -33,32 +87,81 @@ export function acquireDelegateLock(lock, options = {}) {
|
|
|
33
87
|
fs.linkSync(staged, lock);
|
|
34
88
|
}
|
|
35
89
|
catch (error) {
|
|
36
|
-
|
|
37
|
-
|
|
90
|
+
const code = error.code;
|
|
91
|
+
if (code !== 'EEXIST') {
|
|
92
|
+
return { ok: false, reason: 'error', detail: code || (error instanceof Error ? error.message : String(error)) };
|
|
93
|
+
}
|
|
38
94
|
const before = fs.lstatSync(lock);
|
|
39
95
|
if (before.isSymbolicLink() || !before.isFile())
|
|
40
|
-
return
|
|
96
|
+
return { ok: false, reason: 'busy' };
|
|
41
97
|
const ownerFile = lock;
|
|
42
98
|
const fileStat = fs.lstatSync(ownerFile);
|
|
43
99
|
if (!fileStat.isFile() || fileStat.isSymbolicLink() || fileStat.size > 4096)
|
|
44
|
-
return
|
|
100
|
+
return { ok: false, reason: 'busy' };
|
|
45
101
|
const oldText = fs.readFileSync(ownerFile, 'utf8');
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
102
|
+
let old;
|
|
103
|
+
try {
|
|
104
|
+
old = JSON.parse(oldText);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return { ok: false, reason: 'busy' };
|
|
108
|
+
}
|
|
109
|
+
if (!old ||
|
|
110
|
+
typeof old !== 'object' ||
|
|
111
|
+
!Number.isSafeInteger(old.pid) ||
|
|
112
|
+
old.pid <= 0 ||
|
|
113
|
+
!Number.isFinite(old.createdAt) ||
|
|
114
|
+
(old.start !== undefined &&
|
|
115
|
+
(typeof old.start !== 'string' || !old.start))) {
|
|
116
|
+
return { ok: false, reason: 'busy' };
|
|
117
|
+
}
|
|
118
|
+
const parsed = old;
|
|
119
|
+
const ownerAlive = alive(parsed.pid);
|
|
120
|
+
if (ownerAlive || explicitStartOf !== undefined) {
|
|
121
|
+
if (typeof parsed.start === 'string') {
|
|
122
|
+
const probe = probeStart(parsed.pid);
|
|
123
|
+
if (ownerAlive) {
|
|
124
|
+
if (probe.start === null) {
|
|
125
|
+
if (probe.toolUnavailable) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
reason: 'identity-unavailable',
|
|
129
|
+
timedOut: probe.timedOut,
|
|
130
|
+
detail: probe.detail,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return { ok: false, reason: 'busy' };
|
|
134
|
+
}
|
|
135
|
+
if (probe.start === parsed.start)
|
|
136
|
+
return { ok: false, reason: 'busy' };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (ownerAlive) {
|
|
140
|
+
return { ok: false, reason: 'busy' };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
52
143
|
const after = fs.lstatSync(lock);
|
|
53
|
-
if (before.dev !== after.dev || before.ino !== after.ino || fs.readFileSync(ownerFile, 'utf8') !== oldText)
|
|
54
|
-
return
|
|
144
|
+
if (before.dev !== after.dev || before.ino !== after.ino || fs.readFileSync(ownerFile, 'utf8') !== oldText) {
|
|
145
|
+
return { ok: false, reason: 'busy' };
|
|
146
|
+
}
|
|
55
147
|
fs.unlinkSync(lock);
|
|
56
|
-
|
|
148
|
+
try {
|
|
149
|
+
fs.linkSync(staged, lock);
|
|
150
|
+
}
|
|
151
|
+
catch (relinkError) {
|
|
152
|
+
const relinkCode = relinkError.code;
|
|
153
|
+
if (relinkCode === 'EEXIST')
|
|
154
|
+
return { ok: false, reason: 'busy' };
|
|
155
|
+
return { ok: false, reason: 'error', detail: relinkCode || (relinkError instanceof Error ? relinkError.message : String(relinkError)) };
|
|
156
|
+
}
|
|
57
157
|
}
|
|
58
158
|
identity = fs.lstatSync(lock);
|
|
59
159
|
}
|
|
60
|
-
catch {
|
|
61
|
-
|
|
160
|
+
catch (error) {
|
|
161
|
+
const code = error.code;
|
|
162
|
+
if (code === 'ENOENT')
|
|
163
|
+
return { ok: false, reason: 'busy' };
|
|
164
|
+
return { ok: false, reason: 'error', detail: code || (error instanceof Error ? error.message : String(error)) };
|
|
62
165
|
}
|
|
63
166
|
finally {
|
|
64
167
|
try {
|
|
@@ -68,21 +171,30 @@ export function acquireDelegateLock(lock, options = {}) {
|
|
|
68
171
|
mutex.release();
|
|
69
172
|
}
|
|
70
173
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const current = fs.lstatSync(lock);
|
|
77
|
-
if (!current.isFile() || current.isSymbolicLink() || current.dev !== identity.dev || current.ino !== identity.ino || fs.readFileSync(lock, 'utf8') !== body)
|
|
174
|
+
ok: true,
|
|
175
|
+
lock: {
|
|
176
|
+
release() {
|
|
177
|
+
const releaseMutex = coordinate();
|
|
178
|
+
if (!releaseMutex)
|
|
78
179
|
return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
180
|
+
try {
|
|
181
|
+
const current = fs.lstatSync(lock);
|
|
182
|
+
if (!current.isFile() || current.isSymbolicLink() || current.dev !== identity.dev || current.ino !== identity.ino || fs.readFileSync(lock, 'utf8') !== body)
|
|
183
|
+
return;
|
|
184
|
+
fs.unlinkSync(lock);
|
|
185
|
+
}
|
|
186
|
+
catch { /* Preserve a replacement or an unknown owner. */ }
|
|
187
|
+
finally {
|
|
188
|
+
releaseMutex.release();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
85
191
|
},
|
|
86
192
|
};
|
|
87
193
|
}
|
|
194
|
+
/** A complete owner file is linked into place atomically. Legacy mkdir writers
|
|
195
|
+
* see EEXIST; unknown legacy directories stay held. */
|
|
196
|
+
export function acquireDelegateLock(lock, options = {}) {
|
|
197
|
+
const result = acquireDelegateLockDetailed(lock, options);
|
|
198
|
+
return result.ok ? result.lock : null;
|
|
199
|
+
}
|
|
88
200
|
//# sourceMappingURL=delegate-lock.js.map
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { type SyncOptions, type SyncResult } from "@indigoai-us/hq-cloud";
|
|
19
19
|
import { type LockHandle } from "@indigoai-us/hq-cloud/operation-lock";
|
|
20
|
+
import { type CompanySessionRetentionOptions } from "../lib/company-sessions.js";
|
|
20
21
|
export interface SyncUnderOperationLockDeps<Options, Result> {
|
|
21
22
|
sync: (options: Options & {
|
|
22
23
|
operationLockAlreadyHeld: true;
|
|
@@ -33,5 +34,5 @@ export declare function syncUnderOperationLock<Options extends {
|
|
|
33
34
|
* The production sync leg: hq-cloud's `sync()` under a lock this process takes
|
|
34
35
|
* itself. Every `hq sync` path in `src/commands/cloud.ts` calls this.
|
|
35
36
|
*/
|
|
36
|
-
export declare function syncLeg(options: SyncOptions): Promise<SyncResult>;
|
|
37
|
+
export declare function syncLeg(options: SyncOptions, resolveCompanySessions?: (hqRoot: string) => Promise<CompanySessionRetentionOptions | undefined>): Promise<SyncResult>;
|
|
37
38
|
//# sourceMappingURL=sync-operation-lock.d.ts.map
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
import { sync } from "@indigoai-us/hq-cloud";
|
|
19
19
|
import { acquireOperationLockAsync, } from "@indigoai-us/hq-cloud/operation-lock";
|
|
20
20
|
import { withPackageUseLeaseReleasedDuring } from "./package-use-lease.js";
|
|
21
|
+
import { withCompanySessions } from "../lib/company-sessions.js";
|
|
22
|
+
import { companySessionsForCommand } from "../lib/company-sessions-cli.js";
|
|
21
23
|
export async function syncUnderOperationLock(options, deps) {
|
|
22
24
|
const acquireLock = deps.acquireLock ?? ((hqRoot) => acquireOperationLockAsync(hqRoot, "sync"));
|
|
23
25
|
const withLeaseReleased = deps.withLeaseReleased ??
|
|
@@ -34,7 +36,16 @@ export async function syncUnderOperationLock(options, deps) {
|
|
|
34
36
|
* The production sync leg: hq-cloud's `sync()` under a lock this process takes
|
|
35
37
|
* itself. Every `hq sync` path in `src/commands/cloud.ts` calls this.
|
|
36
38
|
*/
|
|
37
|
-
export function syncLeg(options) {
|
|
38
|
-
|
|
39
|
+
export async function syncLeg(options, resolveCompanySessions = defaultCompanySessions) {
|
|
40
|
+
const companySessions = options.skipReindex === true ? undefined : await resolveCompanySessions(options.hqRoot);
|
|
41
|
+
return syncUnderOperationLock(withCompanySessions(options, companySessions), { sync });
|
|
42
|
+
}
|
|
43
|
+
async function defaultCompanySessions(hqRoot) {
|
|
44
|
+
try {
|
|
45
|
+
return await companySessionsForCommand(hqRoot, true);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
//# sourceMappingURL=sync-operation-lock.js.map
|
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.261",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@aws-sdk/client-iot-data-plane": "^3.1096.0",
|
|
66
66
|
"@aws-sdk/client-s3": "^3.1049.0",
|
|
67
67
|
"@aws-sdk/dsql-signer": "^3.1146.0",
|
|
68
|
-
"@indigoai-us/hq-cloud": "6.18.
|
|
68
|
+
"@indigoai-us/hq-cloud": "6.18.127",
|
|
69
69
|
"@indigoai-us/hq-flags-client": "^0.2.0",
|
|
70
70
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
71
71
|
"@sentry/node": "^10.49.0",
|
|
@@ -128,11 +128,11 @@
|
|
|
128
128
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
129
129
|
},
|
|
130
130
|
"optionalDependencies": {
|
|
131
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
135
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
136
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
131
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.261",
|
|
132
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.261",
|
|
133
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.261",
|
|
134
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.261",
|
|
135
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.261",
|
|
136
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.261"
|
|
137
137
|
}
|
|
138
138
|
}
|