@indigoai-us/hq-cli 5.345.214 → 5.345.215
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 +93 -0
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +180 -13
- package/dist/command-catalog.generated.js +221 -13
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +231 -55
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +121 -40
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/daemon.js +5 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-connect.d.ts +10 -3
- package/dist/commands/integrations-connect.js +87 -13
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +28 -11
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-held.js +5 -2
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +35 -3
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/fleet-local.d.ts +33 -1
- package/dist/lib/bot/fleet-local.js +215 -31
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
- package/dist/lib/bot/runtime/grok-acp.js +6 -3
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +54 -1
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +10 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +105 -0
- package/dist/lib/delivery/artifacts.js +567 -0
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +146 -0
- package/dist/lib/delivery/enrollment.js +460 -0
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +255 -0
- package/dist/lib/delivery/migrations.js +823 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +63 -0
- package/dist/lib/delivery/mqtt.js +119 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +215 -0
- package/dist/lib/delivery/reconciler.js +703 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +163 -0
- package/dist/lib/delivery/store.js +944 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +191 -0
- package/dist/lib/delivery/workers/macos.js +943 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +251 -0
- package/dist/lib/delivery/workers/windows.js +594 -0
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
- package/dist/lib/hot-channels/signals-pass.js +71 -2
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/signals/steps/extract.js +40 -4
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire format of the worker-to-controller RPC (US-011 slice 4 B).
|
|
3
|
+
*
|
|
4
|
+
* One TCP connection per call. The worker writes one request line and the
|
|
5
|
+
* controller answers one line, then closes:
|
|
6
|
+
*
|
|
7
|
+
* request {"v":1,"id":"<call id>","method":"<allowlisted>","identity":{...},"args":[...]}
|
|
8
|
+
* answer {"v":1,"id":"<call id>","ok":true,"value":...}
|
|
9
|
+
* {"v":1,"id":"<call id>","ok":false,"error":{"code","found","expected","action"}}
|
|
10
|
+
*
|
|
11
|
+
* The identity travels with every call and the controller hands it to
|
|
12
|
+
* DeliveryAccess, which authenticates it again inside the commit. A refusal
|
|
13
|
+
* keeps the DeliveryStoreError fields and the worker rebuilds it as one.
|
|
14
|
+
* Requests are capped at MAX_REQUEST_BYTES; answers at MAX_ANSWER_BYTES.
|
|
15
|
+
* This is not the MQTT hint channel: the broker is not an authentication
|
|
16
|
+
* boundary, and every call here is answered from the controller's ledger.
|
|
17
|
+
*/
|
|
18
|
+
import { DeliveryStoreError, type DeliveryStoreErrorCode } from "../migrations.js";
|
|
19
|
+
export declare const RPC_WIRE_VERSION = 1;
|
|
20
|
+
/**
|
|
21
|
+
* The only methods a worker may call over the wire. No admin-scoped method
|
|
22
|
+
* (enrollment, revocation, worker listing), no deploy effect (request, publish,
|
|
23
|
+
* reconcile) and nothing on the controller itself.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RPC_METHODS: readonly ["readRun", "readyWork", "verifyNotification", "claim", "dispatch", "recordOutcome", "returnAttempt", "renewLease"];
|
|
26
|
+
export type RpcMethod = (typeof RPC_METHODS)[number];
|
|
27
|
+
export declare function isRpcMethod(m: unknown): m is RpcMethod;
|
|
28
|
+
/** Largest request line, newline included. */
|
|
29
|
+
export declare const MAX_REQUEST_BYTES: number;
|
|
30
|
+
/** Largest answer line the client reads (a readRun of a large run). */
|
|
31
|
+
export declare const MAX_ANSWER_BYTES: number;
|
|
32
|
+
/** The client's deadline for one call, connect to answer. */
|
|
33
|
+
export declare const DEFAULT_RPC_TIMEOUT_MS = 10000;
|
|
34
|
+
/** The server's deadline for receiving a complete request line on a connection. */
|
|
35
|
+
export declare const DEFAULT_SERVER_DEADLINE_MS = 10000;
|
|
36
|
+
/** The longest call id accepted. */
|
|
37
|
+
export declare const MAX_CALL_ID = 128;
|
|
38
|
+
/** Open connections a server holds at once; past this a connection is answered RPC_BUSY and closed. */
|
|
39
|
+
export declare const DEFAULT_MAX_CONNECTIONS = 256;
|
|
40
|
+
export interface RpcRequest {
|
|
41
|
+
v: typeof RPC_WIRE_VERSION;
|
|
42
|
+
id: string;
|
|
43
|
+
method: RpcMethod;
|
|
44
|
+
identity: unknown;
|
|
45
|
+
args: unknown[];
|
|
46
|
+
}
|
|
47
|
+
export interface RpcErrorBody {
|
|
48
|
+
code: string;
|
|
49
|
+
found: string;
|
|
50
|
+
expected: string;
|
|
51
|
+
action: string;
|
|
52
|
+
}
|
|
53
|
+
export type RpcAnswer = {
|
|
54
|
+
v: typeof RPC_WIRE_VERSION;
|
|
55
|
+
id: string;
|
|
56
|
+
ok: true;
|
|
57
|
+
value: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
v: typeof RPC_WIRE_VERSION;
|
|
60
|
+
id: string;
|
|
61
|
+
ok: false;
|
|
62
|
+
error: RpcErrorBody;
|
|
63
|
+
};
|
|
64
|
+
export declare function rpcError(code: DeliveryStoreErrorCode, found: string, expected: string, action: string): DeliveryStoreError;
|
|
65
|
+
/** True when the full error should go to the controller's log because the wire carries less. */
|
|
66
|
+
export declare function redacted(err: unknown): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The wire body of a refusal. A thrown value that is not a DeliveryStoreError
|
|
69
|
+
* is reported without its message or stack, and a store-internal refusal keeps
|
|
70
|
+
* only its code.
|
|
71
|
+
*/
|
|
72
|
+
export declare function errorBody(err: unknown): RpcErrorBody;
|
|
73
|
+
/** Rebuild a refusal from the wire. A malformed body becomes RPC_BAD_ANSWER. */
|
|
74
|
+
export declare function errorFromBody(body: unknown, method: string): DeliveryStoreError;
|
|
75
|
+
/** Parse and check one request line. Throws RPC_BAD_REQUEST or RPC_UNKNOWN_METHOD. */
|
|
76
|
+
export declare function parseRequest(line: string): RpcRequest;
|
|
77
|
+
export declare function encodeLine(value: unknown): string;
|
|
78
|
+
/** Hosts the server binds without allowNonLoopback. "localhost" binds the literals 127.0.0.1 and ::1, never a name lookup. */
|
|
79
|
+
export declare const LOOPBACK_HOSTS: readonly ["127.0.0.1", "::1", "localhost"];
|
|
80
|
+
/** Hosts the client dials without allowNonLoopback: literals only, since "localhost" goes through name resolution. */
|
|
81
|
+
export declare const LOOPBACK_DIAL_HOSTS: readonly ["127.0.0.1", "::1"];
|
|
82
|
+
export declare function isLoopbackHost(host: string): boolean;
|
|
83
|
+
export declare function isLoopbackDialHost(host: string): boolean;
|
|
84
|
+
export declare function notLoopback(host: string, side: "bind" | "dial"): DeliveryStoreError;
|
|
85
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire format of the worker-to-controller RPC (US-011 slice 4 B).
|
|
3
|
+
*
|
|
4
|
+
* One TCP connection per call. The worker writes one request line and the
|
|
5
|
+
* controller answers one line, then closes:
|
|
6
|
+
*
|
|
7
|
+
* request {"v":1,"id":"<call id>","method":"<allowlisted>","identity":{...},"args":[...]}
|
|
8
|
+
* answer {"v":1,"id":"<call id>","ok":true,"value":...}
|
|
9
|
+
* {"v":1,"id":"<call id>","ok":false,"error":{"code","found","expected","action"}}
|
|
10
|
+
*
|
|
11
|
+
* The identity travels with every call and the controller hands it to
|
|
12
|
+
* DeliveryAccess, which authenticates it again inside the commit. A refusal
|
|
13
|
+
* keeps the DeliveryStoreError fields and the worker rebuilds it as one.
|
|
14
|
+
* Requests are capped at MAX_REQUEST_BYTES; answers at MAX_ANSWER_BYTES.
|
|
15
|
+
* This is not the MQTT hint channel: the broker is not an authentication
|
|
16
|
+
* boundary, and every call here is answered from the controller's ledger.
|
|
17
|
+
*/
|
|
18
|
+
import { DeliveryStoreError } from "../migrations.js";
|
|
19
|
+
export const RPC_WIRE_VERSION = 1;
|
|
20
|
+
/**
|
|
21
|
+
* The only methods a worker may call over the wire. No admin-scoped method
|
|
22
|
+
* (enrollment, revocation, worker listing), no deploy effect (request, publish,
|
|
23
|
+
* reconcile) and nothing on the controller itself.
|
|
24
|
+
*/
|
|
25
|
+
export const RPC_METHODS = ["readRun", "readyWork", "verifyNotification", "claim", "dispatch", "recordOutcome", "returnAttempt", "renewLease"];
|
|
26
|
+
export function isRpcMethod(m) {
|
|
27
|
+
return typeof m === "string" && RPC_METHODS.includes(m);
|
|
28
|
+
}
|
|
29
|
+
/** Largest request line, newline included. */
|
|
30
|
+
export const MAX_REQUEST_BYTES = 64 * 1024;
|
|
31
|
+
/** Largest answer line the client reads (a readRun of a large run). */
|
|
32
|
+
export const MAX_ANSWER_BYTES = 8 * 1024 * 1024;
|
|
33
|
+
/** The client's deadline for one call, connect to answer. */
|
|
34
|
+
export const DEFAULT_RPC_TIMEOUT_MS = 10_000;
|
|
35
|
+
/** The server's deadline for receiving a complete request line on a connection. */
|
|
36
|
+
export const DEFAULT_SERVER_DEADLINE_MS = 10_000;
|
|
37
|
+
/** The longest call id accepted. */
|
|
38
|
+
export const MAX_CALL_ID = 128;
|
|
39
|
+
/** Open connections a server holds at once; past this a connection is answered RPC_BUSY and closed. */
|
|
40
|
+
export const DEFAULT_MAX_CONNECTIONS = 256;
|
|
41
|
+
export function rpcError(code, found, expected, action) {
|
|
42
|
+
return new DeliveryStoreError(code, { found, expected, action });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Refusals about the controller's own store. Their text names controller paths
|
|
46
|
+
* and internals, so only the code crosses the wire (the heartbeat and the
|
|
47
|
+
* worker act on the code); the detail stays in the controller's log.
|
|
48
|
+
*/
|
|
49
|
+
const STORE_INTERNAL = new Set([
|
|
50
|
+
"STORE_CORRUPT",
|
|
51
|
+
"STORE_SCHEMA_NEWER",
|
|
52
|
+
"STORE_SCHEMA_UNKNOWN",
|
|
53
|
+
"STORE_INVALID_RECORD",
|
|
54
|
+
"CONTROLLER_OWNED",
|
|
55
|
+
"CONTROLLER_AMBIGUOUS",
|
|
56
|
+
"FENCED",
|
|
57
|
+
"STORE_CLOSED",
|
|
58
|
+
"STORE_IO",
|
|
59
|
+
"BACKUP_INVALID",
|
|
60
|
+
"RESTORE_PENDING",
|
|
61
|
+
"STORE_RETIRED",
|
|
62
|
+
]);
|
|
63
|
+
/** True when the full error should go to the controller's log because the wire carries less. */
|
|
64
|
+
export function redacted(err) {
|
|
65
|
+
return !(err instanceof DeliveryStoreError) || STORE_INTERNAL.has(err.code);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The wire body of a refusal. A thrown value that is not a DeliveryStoreError
|
|
69
|
+
* is reported without its message or stack, and a store-internal refusal keeps
|
|
70
|
+
* only its code.
|
|
71
|
+
*/
|
|
72
|
+
export function errorBody(err) {
|
|
73
|
+
if (err instanceof DeliveryStoreError && STORE_INTERNAL.has(err.code)) {
|
|
74
|
+
return {
|
|
75
|
+
code: err.code,
|
|
76
|
+
found: `the controller could not serve the call (${err.code})`,
|
|
77
|
+
expected: "a controller that owns a working store",
|
|
78
|
+
action: "Retry later. The controller's operator can see the detail in its log.",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (err instanceof DeliveryStoreError)
|
|
82
|
+
return { code: err.code, found: err.found, expected: err.expected, action: err.action };
|
|
83
|
+
return {
|
|
84
|
+
code: "RPC_SERVER_ERROR",
|
|
85
|
+
found: "the controller failed while handling the call",
|
|
86
|
+
expected: "an answer or a delivery refusal",
|
|
87
|
+
action: "Retry; if it persists, check the controller's log. The call may or may not have been applied.",
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const CODE = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
91
|
+
/** Rebuild a refusal from the wire. A malformed body becomes RPC_BAD_ANSWER. */
|
|
92
|
+
export function errorFromBody(body, method) {
|
|
93
|
+
const b = body;
|
|
94
|
+
if (b && typeof b === "object" && typeof b.code === "string" && CODE.test(b.code) && typeof b.found === "string" && typeof b.expected === "string" && typeof b.action === "string") {
|
|
95
|
+
return new DeliveryStoreError(b.code, { found: b.found, expected: b.expected, action: b.action });
|
|
96
|
+
}
|
|
97
|
+
return rpcError("RPC_BAD_ANSWER", `a malformed refusal for ${method}`, "code, found, expected and action as strings", "Check that the controller runs a matching HQ version.");
|
|
98
|
+
}
|
|
99
|
+
/** Parse and check one request line. Throws RPC_BAD_REQUEST or RPC_UNKNOWN_METHOD. */
|
|
100
|
+
export function parseRequest(line) {
|
|
101
|
+
let raw;
|
|
102
|
+
try {
|
|
103
|
+
raw = JSON.parse(line);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw rpcError("RPC_BAD_REQUEST", "a request line that is not JSON", "one JSON object per line", "Send {v, id, method, identity, args}. Nothing was run.");
|
|
107
|
+
}
|
|
108
|
+
const r = raw;
|
|
109
|
+
if (!r || typeof r !== "object" || Array.isArray(r)) {
|
|
110
|
+
throw rpcError("RPC_BAD_REQUEST", "a request that is not a JSON object", "{v, id, method, identity, args}", "Nothing was run.");
|
|
111
|
+
}
|
|
112
|
+
if (r.v !== RPC_WIRE_VERSION)
|
|
113
|
+
throw rpcError("RPC_BAD_REQUEST", `wire version ${JSON.stringify(r.v)}`, `version ${RPC_WIRE_VERSION}`, "Use a worker and controller of the same HQ version. Nothing was run.");
|
|
114
|
+
if (typeof r.id !== "string" || r.id === "" || r.id.length > MAX_CALL_ID)
|
|
115
|
+
throw rpcError("RPC_BAD_REQUEST", "a missing or overlong call id", `a call id of 1 to ${MAX_CALL_ID} characters`, "Nothing was run.");
|
|
116
|
+
if (!Array.isArray(r.args))
|
|
117
|
+
throw rpcError("RPC_BAD_REQUEST", "args that are not a list", "args as a JSON array", "Nothing was run.");
|
|
118
|
+
if (!r.identity || typeof r.identity !== "object" || Array.isArray(r.identity))
|
|
119
|
+
throw rpcError("RPC_BAD_REQUEST", "a missing identity", "the worker's enrollment identity", "Nothing was run.");
|
|
120
|
+
// Checked against the allowlist only; the name is never looked up on an object.
|
|
121
|
+
if (!isRpcMethod(r.method)) {
|
|
122
|
+
throw rpcError("RPC_UNKNOWN_METHOD", "a method that is not on the worker allowlist", RPC_METHODS.join(", "), "Workers may call only these methods over the wire. Nothing was run.");
|
|
123
|
+
}
|
|
124
|
+
return { v: RPC_WIRE_VERSION, id: r.id, method: r.method, identity: r.identity, args: r.args };
|
|
125
|
+
}
|
|
126
|
+
export function encodeLine(value) {
|
|
127
|
+
return `${JSON.stringify(value)}\n`;
|
|
128
|
+
}
|
|
129
|
+
/** Hosts the server binds without allowNonLoopback. "localhost" binds the literals 127.0.0.1 and ::1, never a name lookup. */
|
|
130
|
+
export const LOOPBACK_HOSTS = ["127.0.0.1", "::1", "localhost"];
|
|
131
|
+
/** Hosts the client dials without allowNonLoopback: literals only, since "localhost" goes through name resolution. */
|
|
132
|
+
export const LOOPBACK_DIAL_HOSTS = ["127.0.0.1", "::1"];
|
|
133
|
+
export function isLoopbackHost(host) {
|
|
134
|
+
return LOOPBACK_HOSTS.includes(host);
|
|
135
|
+
}
|
|
136
|
+
export function isLoopbackDialHost(host) {
|
|
137
|
+
return LOOPBACK_DIAL_HOSTS.includes(host);
|
|
138
|
+
}
|
|
139
|
+
export function notLoopback(host, side) {
|
|
140
|
+
const allowed = side === "bind" ? LOOPBACK_HOSTS : LOOPBACK_DIAL_HOSTS;
|
|
141
|
+
return rpcError("RPC_NOT_LOOPBACK", `a request to ${side} ${JSON.stringify(host)}`, `a loopback host (${allowed.join(", ")}), or allowNonLoopback: true`, "The worker RPC carries the enrollment token in clear. Keep it on loopback (use an SSH-forwarded port to reach another machine), or pass allowNonLoopback explicitly. Nothing was opened.");
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=wire.js.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type StoreState, type TakeoverReason } from "./migrations.js";
|
|
2
|
+
export { DeliveryStoreError } from "./migrations.js";
|
|
3
|
+
export type { DeliveryStoreErrorCode } from "./migrations.js";
|
|
4
|
+
export declare const STATE_FILE = "state.json";
|
|
5
|
+
export declare const LOCK_FILE = "owner.lock";
|
|
6
|
+
/**
|
|
7
|
+
* SQLite control database; a write transaction on it is the store's serialization lock.
|
|
8
|
+
* Never open, read or close owner.db in this process except through the better-sqlite3
|
|
9
|
+
* connection in withStoreLock: closing any file descriptor on it drops every fcntl lock
|
|
10
|
+
* this process holds on it, which would silently end the store lock.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CONTROL_DB_FILE = "owner.db";
|
|
13
|
+
/**
|
|
14
|
+
* US-010: written into a store that a restored controller replaced. Its
|
|
15
|
+
* presence refuses every later open, so the old controller cannot regain
|
|
16
|
+
* authority (including by stale-pid takeover).
|
|
17
|
+
*/
|
|
18
|
+
export declare const RETIRED_FILE = "retired.json";
|
|
19
|
+
/** US-010: written by restore; the store refuses to open until activateRestore removes it. */
|
|
20
|
+
export declare const RESTORE_PENDING_FILE = "restore.pending.json";
|
|
21
|
+
/**
|
|
22
|
+
* Points where a test can simulate a crash. Every commit passes temp-partial
|
|
23
|
+
* and temp-written before the rename and renamed after it. Open passes
|
|
24
|
+
* claimed after the lock is installed and before the first commit.
|
|
25
|
+
*/
|
|
26
|
+
export type CommitStep = "claimed" | "temp-partial" | "temp-written" | "renamed";
|
|
27
|
+
export interface OwnerLock {
|
|
28
|
+
controllerId: string;
|
|
29
|
+
host: string;
|
|
30
|
+
pid: number;
|
|
31
|
+
/** Always a number in locks this build writes; null is accepted from older builds. */
|
|
32
|
+
epoch: number | null;
|
|
33
|
+
acquiredAt: string;
|
|
34
|
+
}
|
|
35
|
+
export interface StoreOpenOptions {
|
|
36
|
+
dir: string;
|
|
37
|
+
controllerId: string;
|
|
38
|
+
/** Milliseconds since the Unix epoch. Default Date.now. */
|
|
39
|
+
clock?: () => number;
|
|
40
|
+
/** Default os.hostname(). */
|
|
41
|
+
host?: string;
|
|
42
|
+
/** Default process.pid. */
|
|
43
|
+
pid?: number;
|
|
44
|
+
/** Liveness probe for a lock holder on this host. Default pidIsAlive. */
|
|
45
|
+
isPidAlive?: (pid: number) => boolean;
|
|
46
|
+
/** Explicit operator override: take the lock from a live or ambiguous owner. That owner is fenced. */
|
|
47
|
+
operatorOverride?: {
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
/** Test hook called at each commit step; throwing simulates a crash at that point. */
|
|
51
|
+
crashPoint?: (step: CommitStep) => void;
|
|
52
|
+
/** How long to wait for another controller holding the store lock (owner.db), in real milliseconds. Default 2000. */
|
|
53
|
+
gateWaitMs?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface Takeover {
|
|
56
|
+
reason: TakeoverReason;
|
|
57
|
+
/** The previous lock file text. */
|
|
58
|
+
previousOwner: string;
|
|
59
|
+
supersededLockPath: string;
|
|
60
|
+
}
|
|
61
|
+
export interface OpenReport {
|
|
62
|
+
epoch: number;
|
|
63
|
+
/** Store schema version migrated from on this open, or null. */
|
|
64
|
+
migratedFrom: string | null;
|
|
65
|
+
/** Copy of the pre-migration file, written before the migrated state. */
|
|
66
|
+
backupPath: string | null;
|
|
67
|
+
takeover: Takeover | null;
|
|
68
|
+
/** Uncommitted temp files left by a crash and removed on open. */
|
|
69
|
+
removedTempFiles: string[];
|
|
70
|
+
}
|
|
71
|
+
/** True if a process with this pid exists (EPERM counts as alive). */
|
|
72
|
+
export declare function pidIsAlive(pid: number): boolean;
|
|
73
|
+
/** Parse a lock file. null when it is not exactly an OwnerLock. */
|
|
74
|
+
export declare function parseLock(text: string): OwnerLock | null;
|
|
75
|
+
/**
|
|
76
|
+
* Run `fn` with the committed state.json text while holding the store lock,
|
|
77
|
+
* so no commit lands during `fn` (US-010 backups). Read only; does not need
|
|
78
|
+
* or touch ownership. Refuses a retired store.
|
|
79
|
+
*/
|
|
80
|
+
export declare function withStoreSnapshot<T>(dir: string, waitMs: number, fn: (stateText: string) => T): T;
|
|
81
|
+
export interface RetireRecord {
|
|
82
|
+
successorDir: string;
|
|
83
|
+
backupId: string;
|
|
84
|
+
/** Highest epoch the retired store had reached (its state and its lock). */
|
|
85
|
+
observedEpoch: number;
|
|
86
|
+
retiredAt: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* US-010: retire a store whose authority moves to a restored controller.
|
|
90
|
+
* Under the store lock: record the highest epoch it reached in retired.json
|
|
91
|
+
* (created exclusively), then move owner.lock to a superseded record. The
|
|
92
|
+
* old owner's next commit finds no lock naming it and is FENCED; every later
|
|
93
|
+
* open is refused with STORE_RETIRED. Idempotent for the same successor.
|
|
94
|
+
*/
|
|
95
|
+
export declare function retireStore(dir: string, input: {
|
|
96
|
+
successorDir: string;
|
|
97
|
+
backupId: string;
|
|
98
|
+
now: string;
|
|
99
|
+
waitMs?: number;
|
|
100
|
+
}): RetireRecord;
|
|
101
|
+
/**
|
|
102
|
+
* A single-writer handle on a store directory. Obtain with DeliveryStore.open;
|
|
103
|
+
* most callers want openDeliveryController in reconciler.ts instead.
|
|
104
|
+
*/
|
|
105
|
+
export declare class DeliveryStore {
|
|
106
|
+
readonly dir: string;
|
|
107
|
+
readonly epoch: number;
|
|
108
|
+
readonly report: OpenReport;
|
|
109
|
+
private readonly lock;
|
|
110
|
+
private readonly clock;
|
|
111
|
+
private readonly crashPoint;
|
|
112
|
+
private readonly lockWaitMs;
|
|
113
|
+
private current;
|
|
114
|
+
private status;
|
|
115
|
+
private seq;
|
|
116
|
+
private constructor();
|
|
117
|
+
/**
|
|
118
|
+
* Acquire ownership, load and validate the store (migrating a known older
|
|
119
|
+
* version), and commit the new epoch. A refusal leaves the store unchanged;
|
|
120
|
+
* see the header for what a failure after the claim leaves on disk.
|
|
121
|
+
*/
|
|
122
|
+
static open(opts: StoreOpenOptions): DeliveryStore;
|
|
123
|
+
/** The committed state. Read only: change it through commit(). */
|
|
124
|
+
get state(): StoreState;
|
|
125
|
+
/** Milliseconds from the injected clock: the clock commits are stamped with. */
|
|
126
|
+
nowMs(): number;
|
|
127
|
+
/** ISO timestamp from the injected clock. */
|
|
128
|
+
now(): string;
|
|
129
|
+
/**
|
|
130
|
+
* Apply `mutate` to a copy of the state, validate the result and commit it
|
|
131
|
+
* atomically. `epoch` is the caller's fencing epoch; a write from any epoch
|
|
132
|
+
* other than the current owner's is rejected with FENCED. When mutate
|
|
133
|
+
* throws, nothing is written. Success means the write is in every later
|
|
134
|
+
* owner's base. STORE_IO and CONTROLLER_AMBIGUOUS mean nothing was written
|
|
135
|
+
* and the handle stays usable, so the commit can be retried.
|
|
136
|
+
*/
|
|
137
|
+
commit(epoch: number, mutate: (draft: StoreState) => void): void;
|
|
138
|
+
/**
|
|
139
|
+
* Release ownership. Idempotent. A fenced handle leaves the new owner's
|
|
140
|
+
* lock alone. If the release cannot run (the store lock is busy), the handle stays
|
|
141
|
+
* as it was and close can be retried.
|
|
142
|
+
*/
|
|
143
|
+
close(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Throw unless this handle is open and owner.lock still names it: STORE_CLOSED
|
|
146
|
+
* for a closed or failed handle, FENCED (and the handle is fenced) when
|
|
147
|
+
* another controller owns the store. Read only.
|
|
148
|
+
*/
|
|
149
|
+
assertOwner(): void;
|
|
150
|
+
private fence;
|
|
151
|
+
/** Fence unless owner.lock still names exactly this handle. */
|
|
152
|
+
private assertLockMine;
|
|
153
|
+
private assertWritable;
|
|
154
|
+
/**
|
|
155
|
+
* The temp file is gone, so a takeover removed it. Fence if ownership
|
|
156
|
+
* moved; otherwise something else touched the store.
|
|
157
|
+
*/
|
|
158
|
+
private tempVanished;
|
|
159
|
+
private writeAtomic;
|
|
160
|
+
}
|
|
161
|
+
/** True if `dir` holds a store file. */
|
|
162
|
+
export declare function storeExists(dir: string): boolean;
|
|
163
|
+
//# sourceMappingURL=store.d.ts.map
|