@indigoai-us/hq-cli 5.345.238 → 5.345.241
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 +25 -0
- package/assets/scaffold/core/scripts/hq-delegate-repo.sh +7 -1
- package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +95 -20
- package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +57 -9
- package/dist/command-catalog.generated.d.ts +185 -3
- package/dist/command-catalog.generated.js +228 -3
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/cloud-off-gate.d.ts +2 -1
- package/dist/commands/cloud-off-gate.js +17 -4
- package/dist/commands/cloud.d.ts +17 -2
- package/dist/commands/cloud.js +126 -24
- package/dist/commands/core-delegate-w1b.js +35 -10
- package/dist/commands/core-delegate.d.ts +2 -1
- package/dist/commands/core-delegate.js +207 -48
- package/dist/commands/deploy-comments.js +8 -2
- package/dist/commands/deploy-events.d.ts +40 -0
- package/dist/commands/deploy-events.js +300 -0
- package/dist/commands/doctor.d.ts +4 -4
- package/dist/commands/doctor.js +2 -2
- package/dist/commands/feedback.js +2 -3
- package/dist/commands/keyed-sync-pull.d.ts +12 -0
- package/dist/commands/keyed-sync-pull.js +151 -0
- package/dist/commands/library-add.d.ts +5 -2
- package/dist/commands/library-add.js +22 -9
- package/dist/commands/mcp-registration.d.ts +4 -18
- package/dist/commands/mcp-registration.js +9 -29
- package/dist/commands/mesh.d.ts +4 -0
- package/dist/commands/mesh.js +25 -5
- package/dist/commands/pack-install.d.ts +2 -3
- package/dist/commands/pack-install.js +6 -8
- package/dist/commands/secrets.d.ts +3 -4
- package/dist/commands/secrets.js +3 -20
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +307 -232
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/bot/api.d.ts +2 -1
- package/dist/lib/bot/api.js +2 -15
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +0 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +0 -5
- package/dist/lib/core-utils/delegate-helper-paths.d.ts +26 -0
- package/dist/lib/core-utils/delegate-helper-paths.js +33 -0
- package/dist/lib/daemon/jq-provision.d.ts +63 -0
- package/dist/lib/daemon/jq-provision.js +155 -0
- package/dist/lib/daemon/lanes-reconcile-guard.d.ts +4 -3
- package/dist/lib/daemon/lanes-reconcile-guard.js +4 -4
- package/dist/lib/daemon/mesh-owner.d.ts +4 -0
- package/dist/lib/daemon/mesh-owner.js +20 -0
- package/dist/lib/daemon/ops/policy.d.ts +3 -0
- package/dist/lib/daemon/ops/policy.js +32 -4
- package/dist/lib/daemon/run.js +1 -0
- package/dist/lib/daemon/server.d.ts +6 -0
- package/dist/lib/daemon/server.js +5 -0
- package/dist/lib/daemon/verified-jq.d.ts +96 -0
- package/dist/lib/daemon/verified-jq.js +337 -0
- package/dist/lib/doctor/checks/jq.js +16 -0
- package/dist/lib/doctor/deep/executor.d.ts +7 -0
- package/dist/lib/doctor/deep/executor.js +1 -1
- package/dist/lib/doctor/deep/parity.js +1 -27
- package/dist/lib/doctor/deep/sandbox.d.ts +2 -2
- package/dist/lib/doctor/deep/sandbox.js +3 -19
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +52 -21
- package/dist/lib/doctor/fixtures/discover.d.ts +2 -0
- package/dist/lib/doctor/fixtures/discover.js +1 -1
- package/dist/lib/doctor/json-output.d.ts +1 -1
- package/dist/lib/doctor/registry.d.ts +6 -7
- package/dist/lib/doctor/registry.js +6 -7
- package/dist/lib/doctor/report.d.ts +9 -10
- package/dist/lib/doctor/report.js +4 -4
- 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/jq/install.d.ts +27 -0
- package/dist/lib/jq/install.js +156 -0
- package/dist/lib/lanes/outpost-dispatch.d.ts +1 -1
- package/dist/lib/lanes/outpost-dispatch.js +13 -13
- package/dist/lib/lanes/outpost-pruner-install.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor.js +7 -1
- package/dist/lib/mesh/live/daemon/install.d.ts +4 -0
- package/dist/lib/mesh/live/daemon/install.js +10 -0
- package/dist/lib/mesh/live/daemon/run.js +17 -0
- package/dist/lib/mesh/live/emit-retry.d.ts +20 -2
- package/dist/lib/mesh/live/emit-retry.js +57 -4
- package/dist/lib/mesh/live/emit.js +25 -4
- package/dist/lib/mesh/live/flush.d.ts +2 -0
- package/dist/lib/mesh/live/flush.js +21 -8
- package/dist/lib/mesh/live/spool.d.ts +9 -1
- package/dist/lib/mesh/live/spool.js +41 -29
- package/dist/lib/sync-core/rollout-state.d.ts +9 -1
- package/dist/lib/sync-core/rollout-state.js +34 -4
- package/dist/lib/windows/jq.d.ts +4 -0
- package/dist/lib/windows/jq.js +10 -39
- package/dist/lib/workers-registry/index.js +7 -11
- package/dist/utils/callback-port-busy.d.ts +2 -2
- package/dist/utils/callback-port-busy.js +2 -2
- package/dist/utils/cli-network-lifecycle.js +1 -0
- package/dist/utils/client-health-contract.d.ts +2 -0
- package/dist/utils/client-health-contract.js +1 -1
- package/dist/utils/client-health.js +1 -9
- package/dist/utils/cognito-config.js +5 -0
- package/dist/utils/cognito-session.d.ts +4 -6
- package/dist/utils/cognito-session.js +4 -24
- package/dist/utils/incomplete-install-error.js +1 -11
- package/dist/utils/install-tree-torn.d.ts +11 -0
- package/dist/utils/install-tree-torn.js +1 -1
- package/dist/utils/resident-package-preload.js +2 -1
- package/docs/anywhere-runtime.md +8 -0
- package/package.json +9 -9
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { deployApiRequest } from "../lib/deploy-api.js";
|
|
4
|
+
import { DeployIdentityError, openDeployIdentity } from "../lib/deploy-identity.js";
|
|
5
|
+
class SiteEventsError extends Error {
|
|
6
|
+
}
|
|
7
|
+
const APP_ID = /^(?:[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}|app_[A-Za-z0-9_-]+)$/i;
|
|
8
|
+
const EVENT_ID = /^evt_[0-9a-z]{9}[0-9a-f]{16}$/;
|
|
9
|
+
const COMPANY = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
10
|
+
const MIN_INTERVAL_SECONDS = 30;
|
|
11
|
+
const DEFAULT_HEARTBEAT_MS = 30 * 60_000;
|
|
12
|
+
/** One-line JSON with terminal control and bidi characters escaped. */
|
|
13
|
+
export function jsonLine(value) {
|
|
14
|
+
return JSON.stringify(value).replace(/[\u007f-\u009f\u202a-\u202e\u2066-\u2069]/gu, (character) => `\\u${(character.codePointAt(0) ?? 0).toString(16).padStart(4, "0")}`);
|
|
15
|
+
}
|
|
16
|
+
function display(value) {
|
|
17
|
+
return [...String(value ?? "")].map((character) => {
|
|
18
|
+
const code = character.codePointAt(0) ?? 0;
|
|
19
|
+
const unsafe = code <= 0x1f || (code >= 0x7f && code <= 0x9f)
|
|
20
|
+
|| (code >= 0x202a && code <= 0x202e) || (code >= 0x2066 && code <= 0x2069);
|
|
21
|
+
return unsafe ? `\\u${code.toString(16).padStart(4, "0")}` : character;
|
|
22
|
+
}).join("");
|
|
23
|
+
}
|
|
24
|
+
function checkApp(appId) {
|
|
25
|
+
if (!APP_ID.test(appId))
|
|
26
|
+
throw new SiteEventsError("Use the app ID shown by hq deploy list.");
|
|
27
|
+
}
|
|
28
|
+
function checkScope(options) {
|
|
29
|
+
if ((options.company !== undefined) === (options.personal === true)) {
|
|
30
|
+
throw new SiteEventsError("Choose exactly one of --company <slug> or --personal.");
|
|
31
|
+
}
|
|
32
|
+
if (options.company !== undefined && !COMPANY.test(options.company)) {
|
|
33
|
+
throw new SiteEventsError("Use a valid company slug.");
|
|
34
|
+
}
|
|
35
|
+
return options.personal ? { personal: true } : { company: options.company };
|
|
36
|
+
}
|
|
37
|
+
function checkStatus(status) {
|
|
38
|
+
if (status !== undefined && status !== "new" && status !== "handled") {
|
|
39
|
+
throw new SiteEventsError("--status must be new or handled.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function responseError(status, what) {
|
|
43
|
+
switch (status) {
|
|
44
|
+
case 403:
|
|
45
|
+
return new SiteEventsError(`Could not ${what} (HTTP 403). Only the app owner or an org admin can do this; check the scope.`);
|
|
46
|
+
case 404:
|
|
47
|
+
return new SiteEventsError(`Could not ${what} (HTTP 404). Run hq deploy list to check the app ID and scope.`);
|
|
48
|
+
case 429:
|
|
49
|
+
return new SiteEventsError(`Could not ${what} (HTTP 429). Wait a moment and try again.`);
|
|
50
|
+
default:
|
|
51
|
+
return new SiteEventsError(`Could not ${what} (HTTP ${status}). Try again in a moment.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function send(scope, route, method, body, what) {
|
|
55
|
+
const request = await openDeployIdentity(scope);
|
|
56
|
+
let response;
|
|
57
|
+
try {
|
|
58
|
+
response = await request((token, headers) => deployApiRequest(token, route, method, body, headers, { redirect: "error" }));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof DeployIdentityError)
|
|
62
|
+
throw error;
|
|
63
|
+
throw new SiteEventsError(`Could not reach hq-deploy to ${what}.`);
|
|
64
|
+
}
|
|
65
|
+
if (response.status !== 200)
|
|
66
|
+
throw responseError(response.status, what);
|
|
67
|
+
const parsed = await response.json().catch(() => null);
|
|
68
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
69
|
+
throw new SiteEventsError(`hq-deploy returned an invalid response when asked to ${what}.`);
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
function eventsRoute(appId, query) {
|
|
74
|
+
const params = new URLSearchParams();
|
|
75
|
+
if (query.after)
|
|
76
|
+
params.set("after", query.after);
|
|
77
|
+
if (query.status)
|
|
78
|
+
params.set("status", query.status);
|
|
79
|
+
if (query.limit)
|
|
80
|
+
params.set("limit", query.limit);
|
|
81
|
+
const search = params.toString();
|
|
82
|
+
return `/api/apps/${encodeURIComponent(appId)}/manage/events${search ? `?${search}` : ""}`;
|
|
83
|
+
}
|
|
84
|
+
async function listOnce(appId, scope, query) {
|
|
85
|
+
const body = await send(scope, eventsRoute(appId, query), "GET", undefined, "read site events");
|
|
86
|
+
if (!Array.isArray(body.events))
|
|
87
|
+
throw new SiteEventsError("hq-deploy returned an invalid site events list.");
|
|
88
|
+
return body;
|
|
89
|
+
}
|
|
90
|
+
async function enableAction(appId, options) {
|
|
91
|
+
checkApp(appId);
|
|
92
|
+
const scope = checkScope(options);
|
|
93
|
+
const eventsEnabled = options.off !== true;
|
|
94
|
+
const receipt = await send(scope, `/api/apps/${encodeURIComponent(appId)}`, "PATCH", { eventsEnabled }, "change the site events setting");
|
|
95
|
+
if (receipt.eventsEnabled !== eventsEnabled) {
|
|
96
|
+
throw new SiteEventsError("hq-deploy did not confirm the site events setting. Check it before trying again.");
|
|
97
|
+
}
|
|
98
|
+
const id = typeof receipt.id === "string" ? receipt.id : appId;
|
|
99
|
+
console.log(options.json
|
|
100
|
+
? jsonLine({ ok: true, appId: id, eventsEnabled })
|
|
101
|
+
: `Site events turned ${eventsEnabled ? "on" : "off"} for ${display(id)}.`);
|
|
102
|
+
}
|
|
103
|
+
async function listAction(appId, options) {
|
|
104
|
+
checkApp(appId);
|
|
105
|
+
const scope = checkScope(options);
|
|
106
|
+
checkStatus(options.status);
|
|
107
|
+
if (options.after !== undefined && !EVENT_ID.test(options.after))
|
|
108
|
+
throw new SiteEventsError("--after must be a site event id.");
|
|
109
|
+
if (options.limit !== undefined && !/^[0-9]+$/.test(options.limit))
|
|
110
|
+
throw new SiteEventsError("--limit must be a number.");
|
|
111
|
+
const body = await listOnce(appId, scope, options);
|
|
112
|
+
if (options.json) {
|
|
113
|
+
console.log(jsonLine(body));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (body.events.length === 0) {
|
|
117
|
+
console.log("No site events.");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const event of body.events) {
|
|
121
|
+
const row = (typeof event === "object" && event !== null ? event : {});
|
|
122
|
+
console.log([row.id, row.status, row.name, row.createdAt].map((value) => display(value ?? "-")).join(" | "));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function replyAction(appId, eventId, options) {
|
|
126
|
+
checkApp(appId);
|
|
127
|
+
const scope = checkScope(options);
|
|
128
|
+
if (!EVENT_ID.test(eventId))
|
|
129
|
+
throw new SiteEventsError("Use a site event id (evt_...).");
|
|
130
|
+
checkStatus(options.status);
|
|
131
|
+
if (options.text === undefined && options.status === undefined)
|
|
132
|
+
throw new SiteEventsError("Give --text, --status, or both.");
|
|
133
|
+
if (options.text !== undefined && options.text.trim() === "")
|
|
134
|
+
throw new SiteEventsError("--text must not be empty.");
|
|
135
|
+
const payload = {};
|
|
136
|
+
if (options.text !== undefined)
|
|
137
|
+
payload.reply = options.text;
|
|
138
|
+
if (options.status !== undefined)
|
|
139
|
+
payload.status = options.status;
|
|
140
|
+
const route = `/api/apps/${encodeURIComponent(appId)}/manage/events/${encodeURIComponent(eventId)}`;
|
|
141
|
+
const receipt = await send(scope, route, "PATCH", payload, "reply to the site event");
|
|
142
|
+
if (typeof receipt.id !== "string")
|
|
143
|
+
throw new SiteEventsError("hq-deploy returned an invalid reply receipt.");
|
|
144
|
+
const result = { ok: true, id: receipt.id, status: receipt.status ?? null, reply: receipt.reply ?? null };
|
|
145
|
+
console.log(options.json ? jsonLine(result) : `Replied to ${display(receipt.id)} (status ${display(result.status)}).`);
|
|
146
|
+
}
|
|
147
|
+
function readCursor(cursorFile) {
|
|
148
|
+
try {
|
|
149
|
+
const value = fs.readFileSync(cursorFile, "utf8").trim();
|
|
150
|
+
return EVENT_ID.test(value) ? value : "";
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return "";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function writeCursor(cursorFile, value) {
|
|
157
|
+
const tmp = `${cursorFile}.tmp`;
|
|
158
|
+
try {
|
|
159
|
+
fs.writeFileSync(tmp, `${value}\n`, { mode: 0o600 });
|
|
160
|
+
fs.renameSync(tmp, cursorFile);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
try {
|
|
165
|
+
fs.rmSync(tmp, { force: true });
|
|
166
|
+
}
|
|
167
|
+
catch { /* best effort */ }
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Poll for new events and print one JSON line per result: armed, event,
|
|
173
|
+
* poll_failing (first failure, then every fifth), poll_recovered,
|
|
174
|
+
* cursor_write_failed, heartbeat. The cursor advances only once it is on disk,
|
|
175
|
+
* so after a successful write a restart does not replay those events. When the
|
|
176
|
+
* write fails the cursor stays where it was: the next poll reports the same
|
|
177
|
+
* events again (at least once) together with cursor_write_failed. Each poll opens a
|
|
178
|
+
* fresh sign-in, so a long-running watch survives token refresh. Returns the
|
|
179
|
+
* exit code for --once; otherwise it runs until stopped.
|
|
180
|
+
*/
|
|
181
|
+
export async function watchSiteEvents(appId, options, deps) {
|
|
182
|
+
checkApp(appId);
|
|
183
|
+
const scope = checkScope(options);
|
|
184
|
+
if (!options.cursorFile)
|
|
185
|
+
throw new SiteEventsError("--cursor-file is required so a restart resumes where it stopped.");
|
|
186
|
+
const intervalText = options.interval ?? String(MIN_INTERVAL_SECONDS);
|
|
187
|
+
if (!/^[0-9]+$/.test(intervalText) || Number(intervalText) < MIN_INTERVAL_SECONDS) {
|
|
188
|
+
throw new SiteEventsError(`--interval must be a whole number of seconds, at least ${MIN_INTERVAL_SECONDS}.`);
|
|
189
|
+
}
|
|
190
|
+
// Handled events were already answered; replaying them could repeat a change.
|
|
191
|
+
const status = options.status ?? "new";
|
|
192
|
+
checkStatus(status);
|
|
193
|
+
const cursorFile = options.cursorFile;
|
|
194
|
+
try {
|
|
195
|
+
fs.mkdirSync(path.dirname(cursorFile), { recursive: true });
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
throw new SiteEventsError("Could not create the cursor file's directory.");
|
|
199
|
+
}
|
|
200
|
+
const label = options.label ?? appId;
|
|
201
|
+
let cursor = readCursor(cursorFile);
|
|
202
|
+
deps.emit(jsonLine({ type: "armed", app: label, cursor: cursor || null }));
|
|
203
|
+
let fails = 0;
|
|
204
|
+
let lastBeat = deps.now();
|
|
205
|
+
for (;;) {
|
|
206
|
+
// A failed poll (network, HTTP error, sign-in) is reported below and retried.
|
|
207
|
+
const body = await listOnce(appId, scope, { after: cursor || undefined, status }).catch(() => null);
|
|
208
|
+
if (body === null) {
|
|
209
|
+
fails += 1;
|
|
210
|
+
if (fails % 5 === 1)
|
|
211
|
+
deps.emit(jsonLine({ type: "poll_failing", app: label, count: fails }));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
if (fails > 0)
|
|
215
|
+
deps.emit(jsonLine({ type: "poll_recovered", app: label, after: fails }));
|
|
216
|
+
fails = 0;
|
|
217
|
+
for (const event of body.events) {
|
|
218
|
+
if (typeof event !== "object" || event === null || Array.isArray(event))
|
|
219
|
+
continue;
|
|
220
|
+
const row = event;
|
|
221
|
+
deps.emit(jsonLine({
|
|
222
|
+
type: "event",
|
|
223
|
+
app: label,
|
|
224
|
+
id: row.id ?? null,
|
|
225
|
+
name: row.name ?? null,
|
|
226
|
+
createdAt: row.createdAt ?? null,
|
|
227
|
+
status: row.status ?? null,
|
|
228
|
+
data: row.data ?? null,
|
|
229
|
+
actor: row.actor ?? null,
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
const next = body.nextAfter;
|
|
233
|
+
if (typeof next === "string" && EVENT_ID.test(next) && next !== cursor) {
|
|
234
|
+
if (writeCursor(cursorFile, next)) {
|
|
235
|
+
cursor = next;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
deps.emit(jsonLine({ type: "cursor_write_failed", app: label, path: cursorFile }));
|
|
239
|
+
if (options.once)
|
|
240
|
+
return 1;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (options.once)
|
|
245
|
+
return 0;
|
|
246
|
+
const now = deps.now();
|
|
247
|
+
if (now - lastBeat >= deps.heartbeatMs) {
|
|
248
|
+
deps.emit(jsonLine({ type: "heartbeat", app: label }));
|
|
249
|
+
lastBeat = now;
|
|
250
|
+
}
|
|
251
|
+
await deps.sleep(Number(intervalText) * 1000);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function run(action) {
|
|
255
|
+
try {
|
|
256
|
+
const code = await action();
|
|
257
|
+
if (typeof code === "number" && code !== 0)
|
|
258
|
+
process.exitCode = code;
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.error(error instanceof SiteEventsError || error instanceof DeployIdentityError
|
|
262
|
+
? error.message
|
|
263
|
+
: "Site events command failed.");
|
|
264
|
+
process.exitCode = 1;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function scoped(command) {
|
|
268
|
+
return command.option("--company <slug>", "company owning the app").option("--personal", "use personal scope");
|
|
269
|
+
}
|
|
270
|
+
export function registerDeployEventsCommand(deploy) {
|
|
271
|
+
const events = deploy.command("events").description("Read and answer site events that visitors send from your deployed apps");
|
|
272
|
+
scoped(events.command("enable <app-id>").description("Turn site events on (or off with --off) for an app"))
|
|
273
|
+
.option("--off", "turn site events off; stored events are kept")
|
|
274
|
+
.option("--json", "print {ok, appId, eventsEnabled} as JSON")
|
|
275
|
+
.action((appId, options) => run(() => enableAction(appId, options)));
|
|
276
|
+
scoped(events.command("list <app-id>").description("List site events on an app"))
|
|
277
|
+
.option("--after <event-id>", "only events after this event id")
|
|
278
|
+
.option("--status <status>", "new or handled")
|
|
279
|
+
.option("--limit <n>", "maximum number of events")
|
|
280
|
+
.option("--json", "print the API response ({events, nextAfter}) as JSON")
|
|
281
|
+
.action((appId, options) => run(() => listAction(appId, options)));
|
|
282
|
+
scoped(events.command("reply <app-id> <event-id>").description("Reply to a site event and/or set its status"))
|
|
283
|
+
.option("--text <reply>", "reply text the page shows")
|
|
284
|
+
.option("--status <status>", "new or handled")
|
|
285
|
+
.option("--json", "print {ok, id, status, reply} as JSON")
|
|
286
|
+
.action((appId, eventId, options) => run(() => replyAction(appId, eventId, options)));
|
|
287
|
+
scoped(events.command("watch <app-id>").description("Poll for new site events and print one JSON line per event"))
|
|
288
|
+
.option("--cursor-file <path>", "file that stores the last reported event id")
|
|
289
|
+
.option("--label <name>", "name used in the output lines (default: the app id)")
|
|
290
|
+
.option("--interval <seconds>", `seconds between polls, at least ${MIN_INTERVAL_SECONDS}`, String(MIN_INTERVAL_SECONDS))
|
|
291
|
+
.option("--status <status>", "new or handled (default: new)")
|
|
292
|
+
.option("--once", "poll once and exit")
|
|
293
|
+
.action((appId, options) => run(() => watchSiteEvents(appId, options, {
|
|
294
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
295
|
+
now: () => Date.now(),
|
|
296
|
+
emit: (line) => console.log(line),
|
|
297
|
+
heartbeatMs: DEFAULT_HEARTBEAT_MS,
|
|
298
|
+
})));
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=deploy-events.js.map
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* a TTY. The rendering and contract live in ../lib/doctor/report.ts and
|
|
19
19
|
* ../lib/doctor/json-output.ts; this command wires them to the CLI.
|
|
20
20
|
*
|
|
21
|
-
* The
|
|
22
|
-
*
|
|
21
|
+
* The command detects the host platform once (`detectPlatform`) and passes it
|
|
22
|
+
* through `platform`; UNKNOWN_PLATFORM is the fallback when none is given.
|
|
23
23
|
*/
|
|
24
24
|
import { Command } from "commander";
|
|
25
25
|
import { type DoctorRegistry } from "../lib/doctor/registry.js";
|
|
@@ -70,8 +70,8 @@ export interface RunDoctorOptions {
|
|
|
70
70
|
/** In text mode, emit ANSI colour. Default: false (no escape sequences). */
|
|
71
71
|
color?: boolean;
|
|
72
72
|
/**
|
|
73
|
-
* The detected platform. Defaults to {@link UNKNOWN_PLATFORM};
|
|
74
|
-
*
|
|
73
|
+
* The detected platform. Defaults to {@link UNKNOWN_PLATFORM}; the CLI action
|
|
74
|
+
* passes the result of host platform detection here. It is exposed to every check
|
|
75
75
|
* so host-specific checks (the US-006 runtime probe) can key off it.
|
|
76
76
|
*/
|
|
77
77
|
platform?: DoctorPlatform;
|
package/dist/commands/doctor.js
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* a TTY. The rendering and contract live in ../lib/doctor/report.ts and
|
|
19
19
|
* ../lib/doctor/json-output.ts; this command wires them to the CLI.
|
|
20
20
|
*
|
|
21
|
-
* The
|
|
22
|
-
*
|
|
21
|
+
* The command detects the host platform once (`detectPlatform`) and passes it
|
|
22
|
+
* through `platform`; UNKNOWN_PLATFORM is the fallback when none is given.
|
|
23
23
|
*/
|
|
24
24
|
import { findHqRootAncestor } from "../utils/hq-roots-core.js";
|
|
25
25
|
import * as fs from "node:fs";
|
|
@@ -430,7 +430,6 @@ function describeRowState(row) {
|
|
|
430
430
|
async function currentStateNote(id, token) {
|
|
431
431
|
return describeRowState(await fetchFeedbackRow({ id, token }));
|
|
432
432
|
}
|
|
433
|
-
const OLD_SERVER_HINT = "The server may not support work links yet.";
|
|
434
433
|
/** Delays between read-back attempts: 3 reads over about 1s. */
|
|
435
434
|
export const LINK_READBACK_DELAYS_MS = [300, 700];
|
|
436
435
|
/** Overridable in tests so retries do not wait on real timers. */
|
|
@@ -456,7 +455,7 @@ export async function storeFeedbackWorkLink(opts) {
|
|
|
456
455
|
});
|
|
457
456
|
if (!res.ok) {
|
|
458
457
|
const message = await readFeedbackError(res);
|
|
459
|
-
throw new Error(`The server rejected the work link for ${opts.id}: ${message}. ${
|
|
458
|
+
throw new Error(`The server rejected the work link for ${opts.id}: ${message}. ${await currentStateNote(opts.id, opts.token)}`);
|
|
460
459
|
}
|
|
461
460
|
// The GET resolves through an eventually consistent index, so a read right
|
|
462
461
|
// after the PATCH can return the old row. Retry briefly before deciding.
|
|
@@ -474,7 +473,7 @@ export async function storeFeedbackWorkLink(opts) {
|
|
|
474
473
|
if (!readOk) {
|
|
475
474
|
throw new Error(`Could not read ${opts.id} back to confirm the work link; the link may have been saved. The state was not posted; rerun the same command to retry.`);
|
|
476
475
|
}
|
|
477
|
-
throw new Error(`The server did not store the work link for ${opts.id}. ${
|
|
476
|
+
throw new Error(`The server did not store the work link for ${opts.id}. ${describeRowState(row)}`);
|
|
478
477
|
}
|
|
479
478
|
/** Post a customer-visible update; the server also mirrors it into #hq-feedback. */
|
|
480
479
|
export async function postFeedbackUpdate(opts) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface KeyedPullOptions {
|
|
2
|
+
hqRoot: string;
|
|
3
|
+
company?: string;
|
|
4
|
+
companySlug?: string;
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
/** No session discovery, journal, deletes or tombstones: absence from an
|
|
8
|
+
* ACL-filtered inventory never proves deletion. */
|
|
9
|
+
export declare function keyedSyncPull(options: KeyedPullOptions): Promise<{
|
|
10
|
+
filesDownloaded: number;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=keyed-sync-pull.d.ts.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Transform } from "node:stream";
|
|
4
|
+
import { pipeline } from "node:stream/promises";
|
|
5
|
+
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
6
|
+
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
7
|
+
const fail = (message) => Object.assign(new Error(message), { expected: true });
|
|
8
|
+
function safeKey(value) {
|
|
9
|
+
return typeof value === "string" && value.length > 0 &&
|
|
10
|
+
!/[\\:]/.test(value) && ![...value].some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) &&
|
|
11
|
+
value.split("/").every(part => part.length > 0 && ![".", "..", ".git", ".hq"].includes(part.toLowerCase()) && !/[. ]$/.test(part));
|
|
12
|
+
}
|
|
13
|
+
/** Require a real directory chain. Hydration runs before workload execution,
|
|
14
|
+
* in a launcher-owned tree without concurrent writers. */
|
|
15
|
+
async function directories(dir, create) {
|
|
16
|
+
const parent = path.dirname(dir);
|
|
17
|
+
if (parent !== dir)
|
|
18
|
+
await directories(parent, create);
|
|
19
|
+
let stat;
|
|
20
|
+
try {
|
|
21
|
+
stat = await fs.lstat(dir);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err.code !== "ENOENT")
|
|
25
|
+
throw err;
|
|
26
|
+
if (!create)
|
|
27
|
+
return;
|
|
28
|
+
await fs.mkdir(dir, { mode: 0o700 });
|
|
29
|
+
stat = await fs.lstat(dir);
|
|
30
|
+
}
|
|
31
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
32
|
+
throw fail("Keyed pull refuses linked or non-directory parents");
|
|
33
|
+
}
|
|
34
|
+
async function destination(file) {
|
|
35
|
+
await directories(path.dirname(file), false);
|
|
36
|
+
try {
|
|
37
|
+
const stat = await fs.lstat(file);
|
|
38
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink > 1)
|
|
39
|
+
throw fail("Keyed pull refuses linked or non-file destinations");
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err.code !== "ENOENT")
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** No session discovery, journal, deletes or tombstones: absence from an
|
|
47
|
+
* ACL-filtered inventory never proves deletion. */
|
|
48
|
+
export async function keyedSyncPull(options) {
|
|
49
|
+
const { token, company, companySlug } = options;
|
|
50
|
+
if (!token.startsWith("hqk_") || token.trim() !== token)
|
|
51
|
+
throw fail("Keyed pull requires a valid HQ_API_KEY");
|
|
52
|
+
if (!company || !/^cmp_[A-Za-z0-9]+$/.test(company))
|
|
53
|
+
throw fail("Keyed pull requires --company cmp_…; no session discovery is allowed");
|
|
54
|
+
if (!companySlug || !/^[a-z0-9][a-z0-9_-]*$/.test(companySlug))
|
|
55
|
+
throw fail("Keyed pull requires a safe --company-slug from the trusted launcher");
|
|
56
|
+
const root = path.resolve(options.hqRoot, "companies", companySlug);
|
|
57
|
+
const files = [];
|
|
58
|
+
const names = new Set();
|
|
59
|
+
const cursors = new Set();
|
|
60
|
+
let cursor;
|
|
61
|
+
for (let page = 0;; page++) {
|
|
62
|
+
if (page >= 10_000)
|
|
63
|
+
throw fail("Keyed pull inventory exceeded the page limit");
|
|
64
|
+
let response;
|
|
65
|
+
try {
|
|
66
|
+
response = await vaultApiFetch({ token, path: "/v1/files/list", query: { company, ...(cursor ? { cursor } : {}) } });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
throw fail("Keyed pull inventory request failed");
|
|
70
|
+
}
|
|
71
|
+
if (!response.ok)
|
|
72
|
+
throw fail(`Keyed pull inventory refused (HTTP ${response.status})`);
|
|
73
|
+
let body;
|
|
74
|
+
try {
|
|
75
|
+
body = await response.json();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw fail("Keyed pull inventory was not JSON");
|
|
79
|
+
}
|
|
80
|
+
if (!body || !Array.isArray(body.objects) || typeof body.truncated !== "boolean")
|
|
81
|
+
throw fail("Keyed pull inventory is incomplete or malformed");
|
|
82
|
+
for (const value of body.objects) {
|
|
83
|
+
const row = value;
|
|
84
|
+
if (!row || !safeKey(row.key) || !Number.isSafeInteger(row.size) || row.size < 0)
|
|
85
|
+
throw fail("Keyed pull inventory contains an unsafe file");
|
|
86
|
+
const name = row.key.normalize("NFC").toLowerCase();
|
|
87
|
+
if (names.has(name))
|
|
88
|
+
throw fail("Keyed pull inventory contains colliding files");
|
|
89
|
+
names.add(name);
|
|
90
|
+
files.push({ key: row.key, size: row.size });
|
|
91
|
+
}
|
|
92
|
+
if (!body.truncated) {
|
|
93
|
+
if (body.cursor !== undefined && body.cursor !== null && body.cursor !== "")
|
|
94
|
+
throw fail("Keyed pull inventory has an inconsistent cursor");
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
if (typeof body.cursor !== "string" || !body.cursor || cursors.has(body.cursor))
|
|
98
|
+
throw fail("Keyed pull inventory has no advancing cursor");
|
|
99
|
+
cursor = body.cursor;
|
|
100
|
+
cursors.add(cursor);
|
|
101
|
+
}
|
|
102
|
+
for (const name of names) {
|
|
103
|
+
const parts = name.split("/");
|
|
104
|
+
for (let i = 1; i < parts.length; i++) {
|
|
105
|
+
if (names.has(parts.slice(0, i).join("/")))
|
|
106
|
+
throw fail("Keyed pull inventory has a file/directory collision");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const file of files)
|
|
110
|
+
await destination(path.join(root, file.key));
|
|
111
|
+
if (files.length === 0)
|
|
112
|
+
return { filesDownloaded: 0 };
|
|
113
|
+
await directories(root, true);
|
|
114
|
+
const stage = await fs.mkdtemp(path.join(root, ".keyed-pull-"));
|
|
115
|
+
try {
|
|
116
|
+
// This existing resident-preloaded module imports cloud.ts for personal
|
|
117
|
+
// identity resolution; defer it here to avoid a static command cycle.
|
|
118
|
+
const { createCompanyPresignClient } = await import("./files-browse.js");
|
|
119
|
+
const client = createCompanyPresignClient({ token, companyUid: company, companySlug });
|
|
120
|
+
for (const [index, file] of files.entries()) {
|
|
121
|
+
try {
|
|
122
|
+
const result = await client.send(new GetObjectCommand({ Bucket: "resolved-server-side", Key: file.key }));
|
|
123
|
+
if (!result.Body)
|
|
124
|
+
throw fail("Missing body");
|
|
125
|
+
let size = 0;
|
|
126
|
+
const counter = new Transform({ transform(chunk, _encoding, callback) {
|
|
127
|
+
size += chunk.length;
|
|
128
|
+
callback(size > file.size ? fail("Download exceeded listed size") : null, chunk);
|
|
129
|
+
} });
|
|
130
|
+
const handle = await fs.open(path.join(stage, String(index)), "wx", 0o600);
|
|
131
|
+
await pipeline(result.Body, counter, handle.createWriteStream());
|
|
132
|
+
if (size !== file.size)
|
|
133
|
+
throw fail("Download did not match listed size");
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw fail("Keyed pull download failed; no staged files were applied");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const [index, file] of files.entries()) {
|
|
140
|
+
const target = path.join(root, file.key);
|
|
141
|
+
await destination(target);
|
|
142
|
+
await directories(path.dirname(target), true);
|
|
143
|
+
await fs.rename(path.join(stage, String(index)), target);
|
|
144
|
+
}
|
|
145
|
+
return { filesDownloaded: files.length };
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
await fs.rm(stage, { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=keyed-sync-pull.js.map
|
|
@@ -128,8 +128,11 @@ export declare function runLibraryAdd(inputs: readonly string[], options: Librar
|
|
|
128
128
|
*/
|
|
129
129
|
export declare function ensureLibraryInSyncScope(company: LibraryCompany, dirRel: string, placeholderPaths: readonly string[], deps: Pick<LibraryAddDeps, "hqRoot" | "syncScope" | "addPin">): Promise<LibrarySyncScopeNote | undefined>;
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
131
|
+
* Resolve the company's sync scope for the library pin note. A failed call
|
|
132
|
+
* is reported as that call's own error, so the note names the real cause.
|
|
133
|
+
* Since hq-cloud 6.18.117 {@link resolvePullScope} fails closed itself; it
|
|
134
|
+
* throws a SyncScopeLookupError whose message is a sync skip line, which
|
|
135
|
+
* would read wrongly in a pin note.
|
|
133
136
|
*/
|
|
134
137
|
export declare function resolveLibrarySyncScope(client: Required<PullScopeClient>, company: LibraryCompany, hqRoot: string): Promise<PullScope>;
|
|
135
138
|
export interface LibraryTagResult {
|
|
@@ -419,8 +419,11 @@ export async function ensureLibraryInSyncScope(company, dirRel, placeholderPaths
|
|
|
419
419
|
return { status: "pinned", pins: missing };
|
|
420
420
|
}
|
|
421
421
|
/**
|
|
422
|
-
*
|
|
423
|
-
*
|
|
422
|
+
* Resolve the company's sync scope for the library pin note. A failed call
|
|
423
|
+
* is reported as that call's own error, so the note names the real cause.
|
|
424
|
+
* Since hq-cloud 6.18.117 {@link resolvePullScope} fails closed itself; it
|
|
425
|
+
* throws a SyncScopeLookupError whose message is a sync skip line, which
|
|
426
|
+
* would read wrongly in a pin note.
|
|
424
427
|
*/
|
|
425
428
|
export async function resolveLibrarySyncScope(client, company, hqRoot) {
|
|
426
429
|
let failure;
|
|
@@ -428,13 +431,23 @@ export async function resolveLibrarySyncScope(client, company, hqRoot) {
|
|
|
428
431
|
failure ??= err;
|
|
429
432
|
throw err;
|
|
430
433
|
});
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
434
|
+
const rethrowFailure = () => {
|
|
435
|
+
if (failure !== undefined)
|
|
436
|
+
throw failure instanceof Error ? failure : new Error(String(failure));
|
|
437
|
+
};
|
|
438
|
+
let scope;
|
|
439
|
+
try {
|
|
440
|
+
scope = await resolvePullScope({
|
|
441
|
+
listMyMemberships: () => watch(client.listMyMemberships()),
|
|
442
|
+
getMembershipSyncConfig: (id) => watch(client.getMembershipSyncConfig(id)),
|
|
443
|
+
listMyExplicitGrants: (uid) => watch(client.listMyExplicitGrants(uid)),
|
|
444
|
+
}, company.uid, company.slug, hqRoot);
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
rethrowFailure();
|
|
448
|
+
throw err;
|
|
449
|
+
}
|
|
450
|
+
rethrowFailure();
|
|
438
451
|
return scope;
|
|
439
452
|
}
|
|
440
453
|
async function writeAssetPlaceholder(p, options, deps, dirAbs) {
|
|
@@ -121,20 +121,6 @@ export declare class PartialRegistrationError extends McpRegistrationError {
|
|
|
121
121
|
readonly backupDir: string | undefined;
|
|
122
122
|
constructor(message: string, backupDir?: string);
|
|
123
123
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Thrown by not-yet-implemented seams (the US-007/US-008 Claude/Codex emitters).
|
|
126
|
-
* Carries a stable `code` so callers/tests can identify it without string-
|
|
127
|
-
* matching the message, and a `story` for at-a-glance attribution. KEPT from the
|
|
128
|
-
* US-005 seam: the merge EMITTERS are still pending after US-006 (which ships the
|
|
129
|
-
* safe-write substrate beneath them).
|
|
130
|
-
*/
|
|
131
|
-
export declare class NotImplementedError extends Error {
|
|
132
|
-
/** Stable, machine-checkable discriminator. */
|
|
133
|
-
readonly code: "NotImplemented";
|
|
134
|
-
/** The PRD story that lands the real implementation. */
|
|
135
|
-
readonly story: string;
|
|
136
|
-
constructor(message: string, story?: string);
|
|
137
|
-
}
|
|
138
124
|
/** Roots the substrate's view of the filesystem; everything is derived from `home`. */
|
|
139
125
|
export interface SafeWriteEnv {
|
|
140
126
|
/** The user home directory. Tests MUST pass a tmpdir here. */
|
|
@@ -677,10 +663,10 @@ export declare function isMcpRegistrationEnabled(env?: Readonly<Record<string, s
|
|
|
677
663
|
* `pack-install` routes `wire:'merge'` keys to). For each declared server name it
|
|
678
664
|
* loads + shape-checks the manifest, then fans out via {@link registerServer}.
|
|
679
665
|
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* supplied loader so this stays decoupled from
|
|
683
|
-
* fully testable in isolation.
|
|
666
|
+
* It wires the Claude/JSON surface (US-007) and the Codex/TOML surface (US-008);
|
|
667
|
+
* on a host without Codex the Codex surface is a first-class skip. Manifests are
|
|
668
|
+
* loaded with a caller-supplied loader so this stays decoupled from
|
|
669
|
+
* `pack-install`'s payload layout and fully testable in isolation.
|
|
684
670
|
*
|
|
685
671
|
* @param pkg the pack name (e.g. `hq-pack-vyg-shopify`) — stamped as provenance
|
|
686
672
|
* @param names the bare server names from `contributes.mcp`
|