@indigoai-us/hq-cli 5.345.222 → 5.345.223
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 +23 -0
- package/dist/command-catalog.generated.d.ts +1 -1
- package/dist/command-catalog.generated.js +1 -1
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- package/dist/commands/core-delegate-w1b.js +207 -187
- package/dist/commands/packs.js +13 -2
- package/dist/commands/sync-core.js +31 -12
- package/dist/lib/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- package/dist/lib/daemon/machine-checks.d.ts +45 -0
- package/dist/lib/daemon/machine-checks.js +95 -11
- package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
- package/dist/lib/daemon/native-notice-ledger.js +43 -0
- package/dist/lib/daemon/run.js +3 -2
- package/dist/lib/daemon/supervisor.d.ts +10 -0
- package/dist/lib/daemon/supervisor.js +86 -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 +33 -3
- package/dist/lib/flag-registry.js +13 -0
- package/dist/lib/scan-packages/index.js +8 -9
- package/dist/lib/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- package/dist/lib/sync-core/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +15 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +12 -1
- package/dist/lib/sync-core/vault-settings.js +23 -7
- package/dist/utils/pack-contributions.d.ts +14 -2
- package/dist/utils/pack-contributions.js +31 -5
- package/package.json +7 -7
- package/scripts/bench-core.mjs +34 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { parentPort, workerData } from "node:worker_threads";
|
|
3
3
|
import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
4
4
|
import { createFlagClient } from "@indigoai-us/hq-flags-client";
|
|
5
|
+
import { decodeJwtClaims } from "./daemon/machine-token-identity.js";
|
|
5
6
|
const data = workerData;
|
|
6
7
|
const endpoint = data.endpoint;
|
|
7
8
|
const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
|
|
@@ -10,6 +11,8 @@ async function refresh() {
|
|
|
10
11
|
if (!parentPort || typeof endpoint !== "string" || endpoint.trim() === "")
|
|
11
12
|
return;
|
|
12
13
|
try {
|
|
14
|
+
const idToken = typeof data.idToken === "string" && data.idToken.length > 0
|
|
15
|
+
? data.idToken : loadCachedTokens()?.idToken ?? "";
|
|
13
16
|
const companyUid = typeof data.companyUid === "string" && COMPANY_UID_RE.test(data.companyUid)
|
|
14
17
|
? data.companyUid
|
|
15
18
|
: undefined;
|
|
@@ -20,14 +23,41 @@ async function refresh() {
|
|
|
20
23
|
endpoint,
|
|
21
24
|
...(companyUid ? { companyUid } : {}),
|
|
22
25
|
...(companyIdentifiers.length ? { companyIdentifiers } : {}),
|
|
23
|
-
getToken: () =>
|
|
24
|
-
? data.idToken
|
|
25
|
-
: loadCachedTokens()?.idToken ?? "",
|
|
26
|
+
getToken: () => idToken,
|
|
26
27
|
refreshIntervalMs: 0,
|
|
27
28
|
onError: () => { },
|
|
28
29
|
});
|
|
29
30
|
await client.ready();
|
|
30
31
|
const snapshot = client.snapshot();
|
|
32
|
+
// These are the claims of the token used for the request, not environment
|
|
33
|
+
// identity hints. The service authenticates it again on the scoped resolve.
|
|
34
|
+
const claims = decodeJwtClaims(idToken);
|
|
35
|
+
if ((companyUid || companyIdentifiers.length) && claims?.["custom:entityType"] === "agent" &&
|
|
36
|
+
typeof claims["custom:entityUid"] === "string" && /^agt_[A-Za-z0-9]+$/.test(claims["custom:entityUid"])) {
|
|
37
|
+
// Resolve without company selectors: the service maps this authenticated
|
|
38
|
+
// caller to personUid=agentUid. Never relabel company-scoped decisions.
|
|
39
|
+
const personClient = createFlagClient({
|
|
40
|
+
endpoint,
|
|
41
|
+
getToken: () => idToken,
|
|
42
|
+
refreshIntervalMs: 0,
|
|
43
|
+
onError: () => { },
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
await personClient.ready();
|
|
47
|
+
const personSnapshot = personClient.snapshot();
|
|
48
|
+
if (personSnapshot)
|
|
49
|
+
parentPort.postMessage({ personSnapshot });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Preserve the independent company refresh when person scope is offline.
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
try {
|
|
56
|
+
personClient.close();
|
|
57
|
+
}
|
|
58
|
+
catch { /* Same isolated failure boundary. */ }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
31
61
|
if (snapshot)
|
|
32
62
|
parentPort.postMessage(snapshot);
|
|
33
63
|
else
|
|
@@ -238,6 +238,19 @@ export function kickFlagRegistryReadiness(dependencies = {}) {
|
|
|
238
238
|
worker.unref();
|
|
239
239
|
};
|
|
240
240
|
worker.on("message", (value) => {
|
|
241
|
+
if (value && typeof value === "object" && "personSnapshot" in value &&
|
|
242
|
+
isFlagSnapshot(value.personSnapshot)) {
|
|
243
|
+
try {
|
|
244
|
+
writePersonFlagSnapshotFile(value.personSnapshot.flags);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
captureFlagRegistryException(error instanceof Error ? error : new Error(String(error)), {
|
|
248
|
+
component: "flag-snapshot-cache-write", company_uid_present: "false",
|
|
249
|
+
...flagSnapshotWriteFailureTags(error),
|
|
250
|
+
}, sentry);
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
241
254
|
if (isFlagSnapshot(value)) {
|
|
242
255
|
heldSnapshot = value;
|
|
243
256
|
heldSnapshotFetchedAt = Date.now();
|
|
@@ -171,27 +171,26 @@ function targetLookup(target) {
|
|
|
171
171
|
/**
|
|
172
172
|
* Reindex keeps pack skills at `.claude/skills/<pack>:<item>`. Recreating the
|
|
173
173
|
* unprefixed table dest next to that wrapper duplicates names like `hooks`.
|
|
174
|
+
* Only this pack's own `<pack>:<item>` counts: another pack's or a company's
|
|
175
|
+
* `*:<item>` says nothing about whether this pack's skill is reachable.
|
|
174
176
|
*/
|
|
175
|
-
function namespacedSkillHostExists(hqRoot, item) {
|
|
176
|
-
const dir = path.join(hqRoot, '.claude', 'skills');
|
|
177
|
-
let names;
|
|
177
|
+
function namespacedSkillHostExists(hqRoot, packName, item) {
|
|
178
178
|
try {
|
|
179
|
-
|
|
179
|
+
fs.lstatSync(path.join(hqRoot, '.claude', 'skills', `${packName}:${item}`));
|
|
180
|
+
return true;
|
|
180
181
|
}
|
|
181
182
|
catch {
|
|
182
183
|
return false;
|
|
183
184
|
}
|
|
184
|
-
const suffix = `:${item}`;
|
|
185
|
-
return names.some((name) => name.endsWith(suffix));
|
|
186
185
|
}
|
|
187
|
-
function ensureSymlink(link, hqRoot, info, warn) {
|
|
186
|
+
function ensureSymlink(link, hqRoot, packName, info, warn) {
|
|
188
187
|
if (!existsOrSymlink(link.src)) {
|
|
189
188
|
warn(`payload missing: ${link.src} (declared but not shipped)`);
|
|
190
189
|
return;
|
|
191
190
|
}
|
|
192
191
|
if (link.key === 'skills' &&
|
|
193
192
|
path.basename(link.dst) === link.item &&
|
|
194
|
-
namespacedSkillHostExists(hqRoot, link.item)) {
|
|
193
|
+
namespacedSkillHostExists(hqRoot, packName, link.item)) {
|
|
195
194
|
info(`skipped ${link.dst} (namespaced skill wrapper already present)`);
|
|
196
195
|
return;
|
|
197
196
|
}
|
|
@@ -394,7 +393,7 @@ export function scanPackages(hqRoot, options = {}) {
|
|
|
394
393
|
continue;
|
|
395
394
|
}
|
|
396
395
|
}
|
|
397
|
-
ensureSymlink(link, hqRoot, info, warn);
|
|
396
|
+
ensureSymlink(link, hqRoot, name, info, warn);
|
|
398
397
|
}
|
|
399
398
|
}
|
|
400
399
|
}
|
|
@@ -220,6 +220,14 @@ export declare function summaryRel(date: string): string;
|
|
|
220
220
|
export declare function listCompanies(hqRoot: string): string[];
|
|
221
221
|
/** Reads one knowledge preference. Throws SignalsConfigError when the script is missing or fails. */
|
|
222
222
|
export declare function readPref(hqRoot: string, company: string, field: string, spawn: SpawnSyncFn): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* The prefs-off rule: whether a run skips `company` because signals_capture and
|
|
225
|
+
* ontology_capture are both off on this computer. `runSignals` decides its
|
|
226
|
+
* `prefs-off` skip with this, and the bot's hot-signal-sync job asks it before
|
|
227
|
+
* choosing the engine (lib/bot/signals-engine-flag.ts), so the two cannot
|
|
228
|
+
* disagree. Throws SignalsConfigError when the settings cannot be read.
|
|
229
|
+
*/
|
|
230
|
+
export declare function capturePrefsOff(hqRoot: string, company: string, spawn?: SpawnSyncFn): boolean;
|
|
223
231
|
/** Coarse v2 kind for a step's detailed kind. */
|
|
224
232
|
export declare function toRunErrorKind(kind: ErrorKind | undefined): RunErrorKind;
|
|
225
233
|
/** Fills the v2 outcome fields of a finished record from its steps. */
|
|
@@ -167,6 +167,18 @@ export function readPref(hqRoot, company, field, spawn) {
|
|
|
167
167
|
}
|
|
168
168
|
return TRUE_VALUES.has(r.stdout.trim().toLowerCase());
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The prefs-off rule: whether a run skips `company` because signals_capture and
|
|
172
|
+
* ontology_capture are both off on this computer. `runSignals` decides its
|
|
173
|
+
* `prefs-off` skip with this, and the bot's hot-signal-sync job asks it before
|
|
174
|
+
* choosing the engine (lib/bot/signals-engine-flag.ts), so the two cannot
|
|
175
|
+
* disagree. Throws SignalsConfigError when the settings cannot be read.
|
|
176
|
+
*/
|
|
177
|
+
export function capturePrefsOff(hqRoot, company, spawn = defaultSpawn) {
|
|
178
|
+
const signalsOn = readPref(hqRoot, company, "signals_capture", spawn);
|
|
179
|
+
const ontologyOn = readPref(hqRoot, company, "ontology_capture", spawn);
|
|
180
|
+
return !signalsOn && !ontologyOn;
|
|
181
|
+
}
|
|
170
182
|
function readJson(hqRoot, rel) {
|
|
171
183
|
const abs = path.join(hqRoot, rel);
|
|
172
184
|
if (!fs.existsSync(abs))
|
|
@@ -452,11 +464,9 @@ export async function runSignals(opts) {
|
|
|
452
464
|
record.jobRanAt = priorJobRanAt;
|
|
453
465
|
// 3. Mark the run as running before any step.
|
|
454
466
|
persist();
|
|
455
|
-
let
|
|
456
|
-
let ontologyOn;
|
|
467
|
+
let prefsOff;
|
|
457
468
|
try {
|
|
458
|
-
|
|
459
|
-
ontologyOn = readPref(hqRoot, company, "ontology_capture", spawn);
|
|
469
|
+
prefsOff = capturePrefsOff(hqRoot, company, spawn);
|
|
460
470
|
}
|
|
461
471
|
catch (err) {
|
|
462
472
|
if (!(err instanceof SignalsConfigError))
|
|
@@ -475,7 +485,7 @@ export async function runSignals(opts) {
|
|
|
475
485
|
records.push(record);
|
|
476
486
|
continue;
|
|
477
487
|
}
|
|
478
|
-
if (
|
|
488
|
+
if (prefsOff) {
|
|
479
489
|
record.skipReason = "prefs-off";
|
|
480
490
|
finish();
|
|
481
491
|
records.push(record);
|
|
@@ -14,4 +14,22 @@ export interface ReadCompanyRolloutFlagOptions {
|
|
|
14
14
|
export declare class RolloutFlagReadError extends Error {
|
|
15
15
|
}
|
|
16
16
|
export declare function readCompanyRolloutFlag(companyUid: string, token: string, options?: ReadCompanyRolloutFlagOptions): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Company-wide parallel downloads for the new sync engine. Registry flags are
|
|
19
|
+
* booleans, so two keys form a ladder: `sync.parallel-downloads` alone means
|
|
20
|
+
* 8 streams, `sync.parallel-downloads-16` means 16 and wins over the first.
|
|
21
|
+
* Neither on means no company value (the engine default, off).
|
|
22
|
+
*/
|
|
23
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_FLAG = "sync.parallel-downloads";
|
|
24
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_16_FLAG = "sync.parallel-downloads-16";
|
|
25
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS = 8;
|
|
26
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS = 16;
|
|
27
|
+
export declare class DownloadStreamsFlagReadError extends Error {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The company's download stream count from the flag registry, or undefined when
|
|
31
|
+
* neither key is on. Throws DownloadStreamsFlagReadError when the registry
|
|
32
|
+
* cannot be read, so the caller can keep the value it had.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readCompanyDownloadStreams(companyUid: string, token: string, options?: ReadCompanyRolloutFlagOptions): Promise<number | undefined>;
|
|
17
35
|
//# sourceMappingURL=flag.d.ts.map
|
|
@@ -44,4 +44,70 @@ export async function readCompanyRolloutFlag(companyUid, token, options = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Company-wide parallel downloads for the new sync engine. Registry flags are
|
|
49
|
+
* booleans, so two keys form a ladder: `sync.parallel-downloads` alone means
|
|
50
|
+
* 8 streams, `sync.parallel-downloads-16` means 16 and wins over the first.
|
|
51
|
+
* Neither on means no company value (the engine default, off).
|
|
52
|
+
*/
|
|
53
|
+
export const SYNC_PARALLEL_DOWNLOADS_FLAG = "sync.parallel-downloads";
|
|
54
|
+
export const SYNC_PARALLEL_DOWNLOADS_16_FLAG = "sync.parallel-downloads-16";
|
|
55
|
+
export const SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS = 8;
|
|
56
|
+
export const SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS = 16;
|
|
57
|
+
export class DownloadStreamsFlagReadError extends Error {
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The company's download stream count from the flag registry, or undefined when
|
|
61
|
+
* neither key is on. Throws DownloadStreamsFlagReadError when the registry
|
|
62
|
+
* cannot be read, so the caller can keep the value it had.
|
|
63
|
+
*/
|
|
64
|
+
export async function readCompanyDownloadStreams(companyUid, token, options = {}) {
|
|
65
|
+
const env = options.env ?? process.env;
|
|
66
|
+
const override16 = readLocalOverride(SYNC_PARALLEL_DOWNLOADS_16_FLAG, env);
|
|
67
|
+
const override8 = readLocalOverride(SYNC_PARALLEL_DOWNLOADS_FLAG, env);
|
|
68
|
+
const fromValues = (on16, on8) => on16 ? SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS : on8 ? SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS : undefined;
|
|
69
|
+
if (override16 !== null && override8 !== null)
|
|
70
|
+
return fromValues(override16, override8);
|
|
71
|
+
let failure;
|
|
72
|
+
const onError = (error) => {
|
|
73
|
+
failure ??= error;
|
|
74
|
+
};
|
|
75
|
+
const fail = (error) => new DownloadStreamsFlagReadError(`could not read ${SYNC_PARALLEL_DOWNLOADS_FLAG} for ${companyUid}: ${error instanceof Error ? error.message : String(error)}`);
|
|
76
|
+
const client = (options.createClient ?? createFlagClient)({
|
|
77
|
+
endpoint: resolveFlagRegistryEndpoint(undefined, env),
|
|
78
|
+
getToken: () => token,
|
|
79
|
+
env: {},
|
|
80
|
+
refreshIntervalMs: 0,
|
|
81
|
+
requestTimeoutMs: READ_TIMEOUT_MS,
|
|
82
|
+
companyUid,
|
|
83
|
+
onError,
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
await client.ready();
|
|
87
|
+
const on = (key, override) => {
|
|
88
|
+
if (override !== null)
|
|
89
|
+
return override;
|
|
90
|
+
const resolution = client.explain(key, { fallback: false });
|
|
91
|
+
return resolution.source === "snapshot" && resolution.value === true;
|
|
92
|
+
};
|
|
93
|
+
const on16 = on(SYNC_PARALLEL_DOWNLOADS_16_FLAG, override16);
|
|
94
|
+
const on8 = on(SYNC_PARALLEL_DOWNLOADS_FLAG, override8);
|
|
95
|
+
if (failure !== undefined)
|
|
96
|
+
throw fail(failure);
|
|
97
|
+
return fromValues(on16, on8);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error instanceof DownloadStreamsFlagReadError)
|
|
101
|
+
throw error;
|
|
102
|
+
throw fail(error);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
try {
|
|
106
|
+
client.close();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
failure ??= undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
47
113
|
//# sourceMappingURL=flag.js.map
|
|
@@ -13,6 +13,12 @@ export interface SyncCoreReconcileDeps {
|
|
|
13
13
|
listMemberships: () => Promise<SyncCoreMembership[]>;
|
|
14
14
|
resolvePersonUid: () => Promise<string | null>;
|
|
15
15
|
readRolloutFlag: (companyUid: string) => Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* The company's parallel download stream count from the flag registry, or
|
|
18
|
+
* undefined when the company has none. Throws when the registry cannot be
|
|
19
|
+
* read; the vault then keeps the value it had. Omitted: no company value.
|
|
20
|
+
*/
|
|
21
|
+
readDownloadStreams?: (companyUid: string) => Promise<number | undefined>;
|
|
16
22
|
ensureBinary: (release: string) => Promise<SyncCoreBinaryInstall>;
|
|
17
23
|
/** A fixed release (tests). Otherwise readPin decides, then SYNC_CORE_RELEASE. */
|
|
18
24
|
release?: string;
|
|
@@ -187,6 +187,20 @@ export async function reconcileSyncCore(deps) {
|
|
|
187
187
|
: switchesBefore.offCompanies.has(vault.slug ?? "");
|
|
188
188
|
const legacyAlreadyOff = wasFull ? before.legacyAlreadyOff === true : alreadyOff;
|
|
189
189
|
const legacyOffSince = (wasFull && alreadyOff ? before.legacyOffSince : undefined) ?? at;
|
|
190
|
+
let downloadStreams;
|
|
191
|
+
if (vault.kind === "company" && deps.readDownloadStreams) {
|
|
192
|
+
try {
|
|
193
|
+
downloadStreams = await deps.readDownloadStreams(vault.uid);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
downloadStreams = before?.downloadStreams;
|
|
197
|
+
const keptValue = downloadStreams === undefined ? "no company download streams" : `${downloadStreams} download streams`;
|
|
198
|
+
warnings.push(`${message(error)}; keeping ${vault.slug ?? vault.uid} at ${keptValue}`);
|
|
199
|
+
}
|
|
200
|
+
if (downloadStreams !== before?.downloadStreams) {
|
|
201
|
+
log(`${vault.uid}: company download streams ${before?.downloadStreams ?? "none"} -> ${downloadStreams ?? "none"}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
190
204
|
const recorded = wasFull ? before.firstCycle : undefined;
|
|
191
205
|
const firstCycle = recorded && recorded.planned > 0
|
|
192
206
|
? recorded
|
|
@@ -200,6 +214,7 @@ export async function reconcileSyncCore(deps) {
|
|
|
200
214
|
legacyOffSince,
|
|
201
215
|
...(legacyAlreadyOff ? { legacyAlreadyOff: true } : {}),
|
|
202
216
|
...(firstCycle ? { firstCycle } : {}),
|
|
217
|
+
...(downloadStreams !== undefined ? { downloadStreams } : {}),
|
|
203
218
|
});
|
|
204
219
|
if (firstCycle && firstCycle !== recorded && (!recorded || firstCycle.planned > 0))
|
|
205
220
|
log(`${vault.uid}: first full cycle ${firstCycle.at}: ${firstCycle.planned} planned, ${firstCycle.completed} completed, ${firstCycle.held} held`);
|
|
@@ -8,6 +8,8 @@ export interface RolloutVault {
|
|
|
8
8
|
legacyOffSince?: string;
|
|
9
9
|
legacyAlreadyOff?: true;
|
|
10
10
|
firstCycle?: SyncCoreFirstCycle;
|
|
11
|
+
/** Download streams from the company flag (sync.parallel-downloads[-16]); absent means no company value. */
|
|
12
|
+
downloadStreams?: number;
|
|
11
13
|
}
|
|
12
14
|
export interface SyncCoreRolloutState {
|
|
13
15
|
version: 1;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { isSyncCoreVaultUid } from "./vault-uid.js";
|
|
4
|
+
import { SYNC_CORE_DOWNLOAD_STREAMS_MAX } from "./vault-settings.js";
|
|
4
5
|
const FIRST_CYCLE_COUNTS = [
|
|
5
6
|
"planned",
|
|
6
7
|
"completed",
|
|
@@ -63,6 +64,11 @@ function vault(value) {
|
|
|
63
64
|
const cycle = v.firstCycle === undefined ? undefined : firstCycle(v.firstCycle);
|
|
64
65
|
if (cycle === null)
|
|
65
66
|
return null;
|
|
67
|
+
// An invalid company value is dropped rather than failing the whole state.
|
|
68
|
+
const streams = typeof v.downloadStreams === "number" && Number.isInteger(v.downloadStreams)
|
|
69
|
+
&& v.downloadStreams >= 1 && v.downloadStreams <= SYNC_CORE_DOWNLOAD_STREAMS_MAX
|
|
70
|
+
? v.downloadStreams
|
|
71
|
+
: undefined;
|
|
66
72
|
return {
|
|
67
73
|
uid: v.uid,
|
|
68
74
|
kind: v.kind,
|
|
@@ -72,6 +78,7 @@ function vault(value) {
|
|
|
72
78
|
...(typeof v.legacyOffSince === "string" ? { legacyOffSince: v.legacyOffSince } : {}),
|
|
73
79
|
...(v.legacyAlreadyOff === true ? { legacyAlreadyOff: true } : {}),
|
|
74
80
|
...(cycle ? { firstCycle: cycle } : {}),
|
|
81
|
+
...(streams !== undefined ? { downloadStreams: streams } : {}),
|
|
75
82
|
};
|
|
76
83
|
}
|
|
77
84
|
export function readSyncCoreRolloutState(home) {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One computer's setting for one vault. `parallelDownloads: false` is an
|
|
3
|
+
* explicit off on this computer, which outranks the company flag; no entry at
|
|
4
|
+
* all follows the company (see effectiveEngineSettings).
|
|
5
|
+
*/
|
|
1
6
|
export interface SyncCoreVaultSettings {
|
|
2
7
|
parallelDownloads?: boolean;
|
|
3
8
|
downloadStreams?: number;
|
|
@@ -12,10 +17,16 @@ export declare function readSyncCoreVaultSettings(home: string, opts?: {
|
|
|
12
17
|
strict?: boolean;
|
|
13
18
|
}): Map<string, SyncCoreVaultSettings>;
|
|
14
19
|
export declare function parseSyncCoreVaultSetting(key: string, value: string): {
|
|
15
|
-
parallelDownloads: boolean;
|
|
20
|
+
parallelDownloads: boolean | undefined;
|
|
16
21
|
} | {
|
|
17
22
|
downloadStreams: number | undefined;
|
|
18
23
|
};
|
|
19
24
|
export declare function setSyncCoreVaultSetting(home: string, vaultUid: string, key: string, value: string): SyncCoreVaultSettings | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* What one vault's engine runs with: this computer's setting when it has one
|
|
27
|
+
* (on or an explicit off), otherwise the company's stream count from the flag
|
|
28
|
+
* registry, otherwise nothing (the engine default, off).
|
|
29
|
+
*/
|
|
30
|
+
export declare function effectiveEngineSettings(local: SyncCoreVaultSettings | undefined, companyStreams: number | undefined): SyncCoreVaultSettings | undefined;
|
|
20
31
|
export declare function engineSettingsEnv(settings: SyncCoreVaultSettings | undefined): Record<string, string>;
|
|
21
32
|
//# sourceMappingURL=vault-settings.d.ts.map
|
|
@@ -15,6 +15,8 @@ function cleanSettings(raw) {
|
|
|
15
15
|
return undefined;
|
|
16
16
|
const record = raw;
|
|
17
17
|
const settings = {};
|
|
18
|
+
if (record.parallel_downloads === false)
|
|
19
|
+
return { parallelDownloads: false };
|
|
18
20
|
if (record.parallel_downloads !== true)
|
|
19
21
|
return undefined;
|
|
20
22
|
settings.parallelDownloads = true;
|
|
@@ -64,7 +66,7 @@ function writeAll(home, all) {
|
|
|
64
66
|
const vaults = {};
|
|
65
67
|
for (const [uid, settings] of [...all.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
66
68
|
vaults[uid] = {
|
|
67
|
-
|
|
69
|
+
parallel_downloads: settings.parallelDownloads === true,
|
|
68
70
|
...(settings.downloadStreams !== undefined ? { download_streams: settings.downloadStreams } : {}),
|
|
69
71
|
};
|
|
70
72
|
}
|
|
@@ -79,7 +81,9 @@ export function parseSyncCoreVaultSetting(key, value) {
|
|
|
79
81
|
return { parallelDownloads: true };
|
|
80
82
|
if (value === "off")
|
|
81
83
|
return { parallelDownloads: false };
|
|
82
|
-
|
|
84
|
+
if (value === "default")
|
|
85
|
+
return { parallelDownloads: undefined };
|
|
86
|
+
throw new SyncCoreVaultSettingError(`parallel-downloads takes on or off, or default to follow the company setting, not ${JSON.stringify(value)}`);
|
|
83
87
|
}
|
|
84
88
|
if (key === "download-streams") {
|
|
85
89
|
if (value === "default")
|
|
@@ -95,12 +99,12 @@ export function parseSyncCoreVaultSetting(key, value) {
|
|
|
95
99
|
export function setSyncCoreVaultSetting(home, vaultUid, key, value) {
|
|
96
100
|
const change = parseSyncCoreVaultSetting(key, value);
|
|
97
101
|
const all = readSyncCoreVaultSettings(home, { strict: true });
|
|
98
|
-
|
|
102
|
+
let next = { ...all.get(vaultUid) };
|
|
99
103
|
if ("parallelDownloads" in change) {
|
|
100
|
-
if (change.parallelDownloads)
|
|
101
|
-
next
|
|
104
|
+
if (change.parallelDownloads === undefined)
|
|
105
|
+
next = {};
|
|
102
106
|
else
|
|
103
|
-
|
|
107
|
+
next.parallelDownloads = change.parallelDownloads;
|
|
104
108
|
}
|
|
105
109
|
else if (change.downloadStreams === undefined) {
|
|
106
110
|
delete next.downloadStreams;
|
|
@@ -113,13 +117,25 @@ export function setSyncCoreVaultSetting(home, vaultUid, key, value) {
|
|
|
113
117
|
}
|
|
114
118
|
if (!next.parallelDownloads)
|
|
115
119
|
delete next.downloadStreams;
|
|
116
|
-
if (
|
|
120
|
+
if (next.parallelDownloads === undefined)
|
|
117
121
|
all.delete(vaultUid);
|
|
118
122
|
else
|
|
119
123
|
all.set(vaultUid, next);
|
|
120
124
|
writeAll(home, all);
|
|
121
125
|
return all.get(vaultUid);
|
|
122
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* What one vault's engine runs with: this computer's setting when it has one
|
|
129
|
+
* (on or an explicit off), otherwise the company's stream count from the flag
|
|
130
|
+
* registry, otherwise nothing (the engine default, off).
|
|
131
|
+
*/
|
|
132
|
+
export function effectiveEngineSettings(local, companyStreams) {
|
|
133
|
+
if (local?.parallelDownloads !== undefined)
|
|
134
|
+
return local;
|
|
135
|
+
if (companyStreams === undefined)
|
|
136
|
+
return undefined;
|
|
137
|
+
return { parallelDownloads: true, downloadStreams: companyStreams };
|
|
138
|
+
}
|
|
123
139
|
export function engineSettingsEnv(settings) {
|
|
124
140
|
if (!settings?.parallelDownloads)
|
|
125
141
|
return {};
|
|
@@ -117,9 +117,21 @@ export interface UnwireResult {
|
|
|
117
117
|
* uninstall from leaving dangling symlinks behind.
|
|
118
118
|
*
|
|
119
119
|
* Also removes the namespaced skill host (`<pack>:<item>`) reindex writes
|
|
120
|
-
* next to the unprefixed table dest.
|
|
120
|
+
* next to the unprefixed table dest, unless `keepNamespacedSkills` is set.
|
|
121
|
+
* `hq packs update` sets it: the pack directory is replaced in place, so the
|
|
122
|
+
* namespaced links stay valid, and removing them would hide `/<pack>:<skill>`
|
|
123
|
+
* until the next reindex. Update removes the hosts of skills the new version
|
|
124
|
+
* dropped with `unwireNamespacedSkills` once the new manifest is on disk.
|
|
121
125
|
*/
|
|
122
|
-
export declare function unwirePack(hqRoot: string, packDir: string, contributes: Partial<Record<PackContributeKey, string[]
|
|
126
|
+
export declare function unwirePack(hqRoot: string, packDir: string, contributes: Partial<Record<PackContributeKey, string[]>>, options?: {
|
|
127
|
+
keepNamespacedSkills?: boolean;
|
|
128
|
+
}): UnwireResult;
|
|
129
|
+
/**
|
|
130
|
+
* Remove the namespaced skill hosts (`<pack>:<item>`) for `items`, with the
|
|
131
|
+
* same ownership rules as `unwirePack`: only links into this pack's directory,
|
|
132
|
+
* and wrapper directories only once removing those links leaves them empty.
|
|
133
|
+
*/
|
|
134
|
+
export declare function unwireNamespacedSkills(hqRoot: string, packDir: string, items: readonly unknown[]): UnwireResult;
|
|
123
135
|
/** The result of {@link unwirePackMcp}: the per-server un-registration outcomes (empty when no `mcp` keys). */
|
|
124
136
|
export interface UnwireMcpResult {
|
|
125
137
|
/** One {@link UnregisterServerResult} per declared `contributes.mcp` server, in declaration order. */
|
|
@@ -85,11 +85,18 @@ export function mergeKeys(contributes) {
|
|
|
85
85
|
* macOS `/var` ↔ `/private/var` so equivalent paths compare equal.
|
|
86
86
|
*/
|
|
87
87
|
function canonicalPath(p) {
|
|
88
|
+
const absolute = path.resolve(p);
|
|
88
89
|
try {
|
|
89
|
-
return fs.realpathSync.native(
|
|
90
|
+
return fs.realpathSync.native(absolute);
|
|
90
91
|
}
|
|
91
92
|
catch {
|
|
92
|
-
|
|
93
|
+
// The path itself is gone (a broken link's target). Canonicalize its
|
|
94
|
+
// nearest existing ancestor so `/var` vs `/private/var` style aliases still
|
|
95
|
+
// compare equal against an existing pack directory.
|
|
96
|
+
const parent = path.dirname(absolute);
|
|
97
|
+
if (parent === absolute)
|
|
98
|
+
return absolute;
|
|
99
|
+
return path.join(canonicalPath(parent), path.basename(absolute));
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
/** True when `candidate` resolves under `packDir` (pack directory containment). */
|
|
@@ -333,19 +340,38 @@ function unwireNamespacedSkillHost(dst, packDir, item, result) {
|
|
|
333
340
|
* uninstall from leaving dangling symlinks behind.
|
|
334
341
|
*
|
|
335
342
|
* Also removes the namespaced skill host (`<pack>:<item>`) reindex writes
|
|
336
|
-
* next to the unprefixed table dest.
|
|
343
|
+
* next to the unprefixed table dest, unless `keepNamespacedSkills` is set.
|
|
344
|
+
* `hq packs update` sets it: the pack directory is replaced in place, so the
|
|
345
|
+
* namespaced links stay valid, and removing them would hide `/<pack>:<skill>`
|
|
346
|
+
* until the next reindex. Update removes the hosts of skills the new version
|
|
347
|
+
* dropped with `unwireNamespacedSkills` once the new manifest is on disk.
|
|
337
348
|
*/
|
|
338
|
-
export function unwirePack(hqRoot, packDir, contributes) {
|
|
349
|
+
export function unwirePack(hqRoot, packDir, contributes, options = {}) {
|
|
339
350
|
const result = { unlinked: [], skipped: [] };
|
|
340
351
|
for (const link of contributionLinks(hqRoot, packDir, contributes)) {
|
|
341
352
|
unlinkContribution(result, link, packDir);
|
|
342
353
|
}
|
|
354
|
+
if (!options.keepNamespacedSkills) {
|
|
355
|
+
unwireNamespacedSkillsInto(result, hqRoot, packDir, contributes.skills ?? []);
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
function unwireNamespacedSkillsInto(result, hqRoot, packDir, items) {
|
|
343
360
|
const packName = path.basename(packDir);
|
|
344
|
-
for (const item of
|
|
361
|
+
for (const item of items) {
|
|
345
362
|
if (typeof item !== 'string' || item.length === 0)
|
|
346
363
|
continue;
|
|
347
364
|
unwireNamespacedSkillHost(path.join(hqRoot, '.claude', 'skills', `${packName}:${item}`), packDir, item, result);
|
|
348
365
|
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Remove the namespaced skill hosts (`<pack>:<item>`) for `items`, with the
|
|
369
|
+
* same ownership rules as `unwirePack`: only links into this pack's directory,
|
|
370
|
+
* and wrapper directories only once removing those links leaves them empty.
|
|
371
|
+
*/
|
|
372
|
+
export function unwireNamespacedSkills(hqRoot, packDir, items) {
|
|
373
|
+
const result = { unlinked: [], skipped: [] };
|
|
374
|
+
unwireNamespacedSkillsInto(result, hqRoot, packDir, items);
|
|
349
375
|
return result;
|
|
350
376
|
}
|
|
351
377
|
/**
|
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.223",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -124,11 +124,11 @@
|
|
|
124
124
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
125
125
|
},
|
|
126
126
|
"optionalDependencies": {
|
|
127
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
128
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
129
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
127
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.223",
|
|
128
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.223",
|
|
129
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.223",
|
|
130
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.223",
|
|
131
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.223",
|
|
132
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.223"
|
|
133
133
|
}
|
|
134
134
|
}
|
package/scripts/bench-core.mjs
CHANGED
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
// (master-hook.sh or the host's adapter script).
|
|
40
40
|
// A bot host's adapter is not in this
|
|
41
41
|
// repository: give it with --core-cmd old=...
|
|
42
|
-
// new hq-hook run --host <host> <Event
|
|
42
|
+
// new hq-hook run --host <host> <Event>
|
|
43
|
+
// --hq-root <root>, as host registration
|
|
44
|
+
// writes it; a bot host
|
|
43
45
|
// gets its own event name (pre_tool_call,
|
|
44
46
|
// post_tool_call, pre_llm_call)
|
|
45
47
|
// selected whatever the host's registration under
|
|
@@ -849,6 +851,34 @@ function botSelected({ host, event, options, rootEnv }) {
|
|
|
849
851
|
return { steps, detected: describeCore(steps.map((step) => step.named)), profile: candidates[0].profile.file };
|
|
850
852
|
}
|
|
851
853
|
|
|
854
|
+
// The spelling of a script path that Git Bash can run and resolve its own
|
|
855
|
+
// folder from: on Windows, forward slashes and /c/... for a drive path (the
|
|
856
|
+
// same conversion src/utils/run-bundled-script.ts uses). master-hook.sh finds
|
|
857
|
+
// its sibling scripts from BASH_SOURCE, and a backslash path makes that the
|
|
858
|
+
// working directory instead. Other platforms get the path unchanged.
|
|
859
|
+
export function bashScriptPath(value, platform = process.platform) {
|
|
860
|
+
if (platform !== "win32") return value;
|
|
861
|
+
const normalized = value.replaceAll("\\", "/");
|
|
862
|
+
const drive = /^([A-Za-z]):\/(.*)$/u.exec(normalized);
|
|
863
|
+
return drive ? `/${drive[1].toLowerCase()}/${drive[2]}` : normalized;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// The HQ root as a host registration writes it after --hq-root: trailing
|
|
867
|
+
// separators removed, except for a bare drive or the filesystem root (the
|
|
868
|
+
// same rule as launcherRoot in src/lib/hook-engine/registration-identity.ts).
|
|
869
|
+
export function registrationRoot(root) {
|
|
870
|
+
const trimmed = root.replace(/[\\/]+$/u, "");
|
|
871
|
+
return trimmed === "" || /^[A-Za-z]:$/u.test(trimmed) ? root : trimmed;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Arguments for --core new: what host registration writes for a project
|
|
875
|
+
// entry, `run --host <host> <Event> --hq-root <root>`. The root is given
|
|
876
|
+
// explicitly, as registration does on every platform, so the engine does not
|
|
877
|
+
// fall back to CLAUDE_PROJECT_DIR (which it does not read on Windows).
|
|
878
|
+
export function newCoreArgs(host, word, root) {
|
|
879
|
+
return ["run", "--host", host, word, "--hq-root", registrationRoot(root)];
|
|
880
|
+
}
|
|
881
|
+
|
|
852
882
|
function defaultBash(platform) {
|
|
853
883
|
if (platform !== "win32") return "bash";
|
|
854
884
|
for (const base of [process.env.ProgramFiles, process.env["ProgramFiles(x86)"], process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, "Programs")]) {
|
|
@@ -880,14 +910,15 @@ export function resolveInvocation({ host, core, event, tool, options, platform =
|
|
|
880
910
|
}
|
|
881
911
|
|
|
882
912
|
if (core === "new") {
|
|
883
|
-
const args =
|
|
913
|
+
const args = newCoreArgs(host, word, root);
|
|
884
914
|
return { steps: [{ file: options.hqHook, args, env: rootEnv, cwd: root, display: `${options.hqHook} ${args.join(" ")}` }], detected: "new" };
|
|
885
915
|
}
|
|
886
916
|
|
|
887
917
|
if (core === "old") {
|
|
888
918
|
const script = path.join(root, ...OLD_ENTRY[host]);
|
|
889
919
|
if (!fs.existsSync(script)) return { steps: [], detected: "old", missing: `the old core is not under --root (${script} is missing)` };
|
|
890
|
-
const
|
|
920
|
+
const scriptArg = bashScriptPath(script, platform);
|
|
921
|
+
const args = host === "claude" ? [scriptArg, event] : [scriptArg];
|
|
891
922
|
const env = { ...rootEnv, BASH_ENV: os.devNull };
|
|
892
923
|
if (host === "grok") Object.assign(env, { GROK_WORKSPACE_ROOT: root, GROK_HOOK_EVENT: event });
|
|
893
924
|
return { steps: [{ file: bash, args, env, cwd: root, display: `bash ${args.join(" ")}` }], detected: "old" };
|