@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217
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 +206 -1
- package/README.md +45 -0
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
- package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
- package/dist/command-catalog.generated.d.ts +105 -10
- package/dist/command-catalog.generated.js +127 -10
- package/dist/command-help.js +3 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +11 -52
- package/dist/commands/bot.js +75 -10
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud-demote.d.ts +19 -4
- package/dist/commands/cloud-demote.js +85 -12
- package/dist/commands/cloud-provision.d.ts +5 -1
- package/dist/commands/cloud-provision.js +6 -2
- package/dist/commands/cloud.d.ts +36 -0
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +9 -1
- package/dist/commands/dm.js +7 -0
- package/dist/commands/doctor-usage.d.ts +8 -0
- package/dist/commands/doctor-usage.js +20 -0
- package/dist/commands/doctor.js +7 -1
- package/dist/commands/env.d.ts +18 -0
- package/dist/commands/env.js +82 -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/install-global.js +2 -2
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +102 -26
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-held.js +5 -2
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +15 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +5 -6
- package/dist/lib/anywhere-person-setting.d.ts +2 -0
- package/dist/lib/anywhere-person-setting.js +6 -3
- package/dist/lib/billing/usage-card.d.ts +25 -4
- package/dist/lib/billing/usage-card.js +76 -9
- package/dist/lib/billing/usage-cost.d.ts +3 -3
- package/dist/lib/billing/usage-cost.js +35 -13
- package/dist/lib/billing/usage-only.js +4 -2
- package/dist/lib/billing/usage-rate-card.d.ts +2 -2
- package/dist/lib/billing/usage-rate-card.js +3 -0
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +126 -7
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/inflight.js +10 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
- package/dist/lib/bot/probe.js +7 -1
- 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 +6 -1
- package/dist/lib/bot/runtime/grok-acp.js +32 -14
- package/dist/lib/bot/runtime/grok.js +1 -1
- 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-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- 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/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/flag-monitor.d.ts +8 -0
- package/dist/lib/daemon/flag-monitor.js +17 -6
- package/dist/lib/daemon/flag.d.ts +65 -1
- package/dist/lib/daemon/flag.js +190 -40
- package/dist/lib/daemon/ops/policy.js +62 -5
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- 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 +79 -21
- package/dist/lib/daemon/selfcheck.d.ts +22 -0
- package/dist/lib/daemon/selfcheck.js +40 -1
- package/dist/lib/daemon/server.d.ts +5 -1
- package/dist/lib/daemon/server.js +17 -23
- package/dist/lib/daemon/state-file-switch.d.ts +57 -0
- package/dist/lib/daemon/state-file-switch.js +88 -0
- package/dist/lib/daemon/state-file.d.ts +198 -0
- package/dist/lib/daemon/state-file.js +419 -0
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +7 -1
- package/dist/lib/delivery/artifacts.js +29 -10
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -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 +21 -17
- package/dist/lib/delivery/enrollment.js +83 -5
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -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 +120 -4
- package/dist/lib/delivery/migrations.js +215 -15
- package/dist/lib/delivery/mqtt.d.ts +2 -0
- package/dist/lib/delivery/mqtt.js +7 -0
- package/dist/lib/delivery/reconciler.d.ts +65 -1
- package/dist/lib/delivery/reconciler.js +224 -13
- 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 +2 -0
- package/dist/lib/delivery/store.js +4 -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.d.ts +16 -1
- package/dist/lib/delivery/workers/macos.js +54 -12
- 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 +32 -22
- package/dist/lib/delivery/workers/windows.js +50 -64
- package/dist/lib/doctor/checks/host-core.d.ts +50 -0
- package/dist/lib/doctor/checks/host-core.js +269 -0
- package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
- package/dist/lib/doctor/checks/replay-recorder.js +261 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/environment/profile.d.ts +239 -0
- package/dist/lib/environment/profile.js +251 -0
- package/dist/lib/hook-engine/reconcile.js +39 -13
- package/dist/lib/hook-engine/registration.d.ts +9 -0
- package/dist/lib/hook-engine/registration.js +19 -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/adapters/slack.d.ts +21 -5
- package/dist/lib/hot-channels/adapters/slack.js +64 -21
- package/dist/lib/hot-channels/alert.d.ts +2 -0
- package/dist/lib/hot-channels/alert.js +8 -1
- package/dist/lib/hot-channels/contract.d.ts +12 -0
- package/dist/lib/hot-channels/contract.js +7 -0
- package/dist/lib/hot-channels/loop.js +1 -0
- package/dist/lib/hot-channels/run.d.ts +6 -0
- package/dist/lib/hot-channels/run.js +4 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
- package/dist/lib/hot-channels/signals-pass.js +82 -41
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +57 -5
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +36 -6
- package/dist/lib/install/hook-target.d.ts +3 -0
- package/dist/lib/install/hook-target.js +11 -0
- package/dist/lib/lanes/canonical-host.d.ts +35 -0
- package/dist/lib/lanes/canonical-host.js +65 -0
- package/dist/lib/lanes/host-capacity.d.ts +30 -0
- package/dist/lib/lanes/host-capacity.js +29 -3
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +5 -2
- package/dist/lib/mesh/live/flush.d.ts +5 -1
- package/dist/lib/mesh/live/flush.js +12 -6
- package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
- package/dist/lib/mesh/live/reporting-privacy.js +56 -1
- package/dist/lib/mesh/live/spool.d.ts +7 -0
- package/dist/lib/mesh/live/spool.js +25 -0
- package/dist/lib/person-setting-cache.d.ts +38 -0
- package/dist/lib/person-setting-cache.js +98 -0
- package/dist/lib/safe-store.d.ts +245 -0
- package/dist/lib/safe-store.js +777 -0
- package/dist/lib/signals/engine.d.ts +29 -2
- package/dist/lib/signals/engine.js +103 -4
- package/dist/lib/signals/reply.js +73 -18
- package/dist/lib/signals/steps/adapters.js +7 -2
- package/dist/lib/signals/steps/extract.d.ts +13 -0
- package/dist/lib/signals/steps/extract.js +122 -6
- package/dist/main.js +46 -3
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/cli-telemetry.d.ts +21 -0
- package/dist/utils/cli-telemetry.js +34 -0
- package/dist/utils/command-usage.d.ts +275 -0
- package/dist/utils/command-usage.js +797 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/dist/utils/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +31 -4
- package/dist/utils/host-registration.d.ts +126 -0
- package/dist/utils/host-registration.js +378 -0
- package/dist/utils/resident-package-preload.js +2 -0
- package/package.json +10 -8
- package/scripts/bench-core.mjs +1096 -0
- package/scripts/check-function-manifest.mjs +702 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
- package/dist/lib/delivery/workers/windows-boundary.js +0 -693
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkerAccessPort } from "../rpc/port.js";
|
|
1
2
|
import { helperOutcome, type ContainedLauncher, type ContainedProcess, type ExecutionSpec, type LaunchOutcome, type LaunchRequest, type MatchResult, type Requirements, type StartResult, type TerminalResult, type WindowsWorkerOptions, type WorkerProfile } from "./windows.js";
|
|
2
3
|
/**
|
|
3
4
|
* A macOS job may declare that it can be stopped and restarted elsewhere
|
|
@@ -123,7 +124,18 @@ export declare function macHelperOutcome(h: Parameters<typeof helperOutcome>[0])
|
|
|
123
124
|
* macos-job-helper.ts for the protocol and the limits.
|
|
124
125
|
*/
|
|
125
126
|
export declare function nativeMacosLauncher(opts: NativeMacosLauncherOptions): NativeMacosLauncher;
|
|
126
|
-
export type MacosWorkerOptions = Omit<WindowsWorkerOptions, "launcher"> & {
|
|
127
|
+
export type MacosWorkerOptions = Omit<WindowsWorkerOptions, "launcher" | "access"> & {
|
|
128
|
+
/**
|
|
129
|
+
* The controller, through the worker's access port: the in-process access
|
|
130
|
+
* layer (a DeliveryAccess, or inProcessPort) or the loopback RPC client
|
|
131
|
+
* (US-011 slice 4 B). Every call is awaited.
|
|
132
|
+
*/
|
|
133
|
+
access: WorkerAccessPort;
|
|
134
|
+
/**
|
|
135
|
+
* The attempt id the worker claims with, one per start. The worker keeps it so
|
|
136
|
+
* a claim whose answer was lost can be replayed and returned. Default mw-<uuid>.
|
|
137
|
+
*/
|
|
138
|
+
attemptIds?: () => string;
|
|
127
139
|
launcher: MacContainedLauncher | ContainedLauncher;
|
|
128
140
|
/** Paths no job may read even when a declared read path covers them, such as the delivery store. The work directory is always added. */
|
|
129
141
|
protectedPaths?: string[];
|
|
@@ -144,6 +156,8 @@ export declare class MacosWorker {
|
|
|
144
156
|
private readonly opts;
|
|
145
157
|
private readonly clock;
|
|
146
158
|
private readonly active;
|
|
159
|
+
/** Starts that have not settled yet; optOut waits for them so none strands a claim. */
|
|
160
|
+
private readonly starting;
|
|
147
161
|
private opted;
|
|
148
162
|
private sweepTimer;
|
|
149
163
|
constructor(opts: MacosWorkerOptions);
|
|
@@ -162,6 +176,7 @@ export declare class MacosWorker {
|
|
|
162
176
|
*/
|
|
163
177
|
private finish;
|
|
164
178
|
start(spec: MacExecutionSpec): Promise<StartResult>;
|
|
179
|
+
private startInner;
|
|
165
180
|
/**
|
|
166
181
|
* Stop admitting work. Interruptible active jobs are killed with their whole
|
|
167
182
|
* tree and returned to the ledger; the rest run to completion. Resolves when
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
* runtime so it can be bundled without node_modules.
|
|
56
56
|
*/
|
|
57
57
|
import { execFileSync, spawn } from "node:child_process";
|
|
58
|
-
import {
|
|
58
|
+
import { isSafeAttemptId } from "../attempt-id.js";
|
|
59
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
59
60
|
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
60
61
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
61
62
|
import { HELPER_SOURCE } from "./macos-job-helper.js";
|
|
@@ -656,6 +657,8 @@ function mkdirAndReturn(dir) {
|
|
|
656
657
|
* job directories the helpers left.
|
|
657
658
|
*/
|
|
658
659
|
export const SWEEP_INTERVAL_MS = 5000;
|
|
660
|
+
/** Transport failures after which a claim may have committed without the worker hearing of it. */
|
|
661
|
+
const CLAIM_ANSWER_LOST = new Set(["RPC_TIMEOUT", "RPC_CLOSED", "RPC_UNREACHABLE"]);
|
|
659
662
|
/** A store error carries a string code; checked by shape so no runtime import is needed. */
|
|
660
663
|
function storeCode(err) {
|
|
661
664
|
const code = err?.code;
|
|
@@ -671,6 +674,8 @@ export class MacosWorker {
|
|
|
671
674
|
opts;
|
|
672
675
|
clock;
|
|
673
676
|
active = new Map();
|
|
677
|
+
/** Starts that have not settled yet; optOut waits for them so none strands a claim. */
|
|
678
|
+
starting = new Set();
|
|
674
679
|
opted = false;
|
|
675
680
|
sweepTimer;
|
|
676
681
|
constructor(opts) {
|
|
@@ -734,12 +739,12 @@ export class MacosWorker {
|
|
|
734
739
|
* A failed return is recorded as failed RETURN_NOT_RECORDED and the attempt
|
|
735
740
|
* stays open in the ledger.
|
|
736
741
|
*/
|
|
737
|
-
finish(result, returning = false) {
|
|
742
|
+
async finish(result, returning = false) {
|
|
738
743
|
let final = result;
|
|
739
744
|
if (result.attemptId !== null) {
|
|
740
745
|
if (returning) {
|
|
741
746
|
try {
|
|
742
|
-
this.opts.access.returnAttempt(this.opts.identity, result.attemptId);
|
|
747
|
+
await this.opts.access.returnAttempt(this.opts.identity, result.attemptId);
|
|
743
748
|
}
|
|
744
749
|
catch (err) {
|
|
745
750
|
final = { ...result, kind: "failed", code: "RETURN_NOT_RECORDED", detail: `${result.detail}; ledger return not recorded: ${storeCode(err) ?? message(err)}` };
|
|
@@ -747,7 +752,7 @@ export class MacosWorker {
|
|
|
747
752
|
}
|
|
748
753
|
else {
|
|
749
754
|
try {
|
|
750
|
-
this.opts.access.recordOutcome(this.opts.identity, result.attemptId, result.kind === "succeeded" ? "passed" : "failed");
|
|
755
|
+
await this.opts.access.recordOutcome(this.opts.identity, result.attemptId, result.kind === "succeeded" ? "passed" : "failed");
|
|
751
756
|
}
|
|
752
757
|
catch (err) {
|
|
753
758
|
final = { ...result, detail: `${result.detail}; ledger outcome not recorded: ${storeCode(err) ?? message(err)}` };
|
|
@@ -761,14 +766,21 @@ export class MacosWorker {
|
|
|
761
766
|
return { ...final, kind: "failed", code: "RESULT_NOT_RECORDED", detail: `${final.kind} ${final.code}: ${final.detail}; result not recorded: ${storeCode(err) ?? message(err)}` };
|
|
762
767
|
}
|
|
763
768
|
}
|
|
764
|
-
|
|
769
|
+
start(spec) {
|
|
770
|
+
const p = this.startInner(spec);
|
|
771
|
+
const settled = p.then(() => undefined, () => undefined);
|
|
772
|
+
this.starting.add(settled);
|
|
773
|
+
void settled.finally(() => this.starting.delete(settled));
|
|
774
|
+
return p;
|
|
775
|
+
}
|
|
776
|
+
async startInner(spec) {
|
|
765
777
|
if (this.opted)
|
|
766
778
|
return this.refuse(spec, "OPTED_OUT", "the worker has opted out and admits no new work");
|
|
767
779
|
const valid = validateMacSpec(spec);
|
|
768
780
|
if (!valid.ok)
|
|
769
781
|
return this.refuse(spec, valid.code, valid.detail);
|
|
770
782
|
try {
|
|
771
|
-
const { run, jobs } = this.opts.access.readRun(this.opts.identity, spec.runId);
|
|
783
|
+
const { run, jobs } = await this.opts.access.readRun(this.opts.identity, spec.runId);
|
|
772
784
|
if (run.tenantId !== spec.tenantId)
|
|
773
785
|
return this.refuse(spec, "INVALID_SPEC", `run ${spec.runId} belongs to another tenant`);
|
|
774
786
|
if (!jobs.some((j) => j.job.jobId === spec.jobId))
|
|
@@ -791,16 +803,43 @@ export class MacosWorker {
|
|
|
791
803
|
catch (err) {
|
|
792
804
|
return err instanceof WorkerRefusal ? this.refuse(spec, err.code, err.detail) : this.refuse(spec, "CONTAINMENT_UNAVAILABLE", message(err));
|
|
793
805
|
}
|
|
794
|
-
//
|
|
795
|
-
//
|
|
806
|
+
// The run read above was awaited, so an opt-out may have landed meanwhile.
|
|
807
|
+
// Everything between that await and the claim call is synchronous, so this
|
|
808
|
+
// one check covers it.
|
|
796
809
|
if (this.opted)
|
|
797
810
|
return this.refuse(spec, "OPTED_OUT", "the worker has opted out and admits no new work");
|
|
798
811
|
let attemptId;
|
|
812
|
+
const chosen = (this.opts.attemptIds ?? (() => `mw-${randomUUID()}`))();
|
|
799
813
|
try {
|
|
800
|
-
attemptId = this.opts.access.claim(this.opts.identity, spec.jobId).attempt.attemptId;
|
|
814
|
+
attemptId = (await this.opts.access.claim(this.opts.identity, spec.jobId, { attemptId: chosen })).attempt.attemptId;
|
|
801
815
|
}
|
|
802
816
|
catch (err) {
|
|
803
|
-
|
|
817
|
+
const code = storeCode(err) ?? "CLAIM_FAILED";
|
|
818
|
+
if (!CLAIM_ANSWER_LOST.has(code))
|
|
819
|
+
return this.refuse(spec, code, message(err));
|
|
820
|
+
// The claim may have committed with its answer lost. Replay it with the same id: if it did
|
|
821
|
+
// commit, the replay returns it and the attempt goes straight back to the ledger.
|
|
822
|
+
try {
|
|
823
|
+
const replayed = (await this.opts.access.claim(this.opts.identity, spec.jobId, { attemptId: chosen })).attempt.attemptId;
|
|
824
|
+
if (!isSafeAttemptId(replayed))
|
|
825
|
+
return this.refuse(spec, "CLAIM_INVALID", "the controller answered an attempt id that is not a safe name; nothing was started");
|
|
826
|
+
const detail = `${message(err)}; the claim had committed and was returned unstarted`;
|
|
827
|
+
return { kind: "refused", result: await this.finish(this.result(spec, { kind: "refused", code, detail, attemptId: replayed }), true) };
|
|
828
|
+
}
|
|
829
|
+
catch (again) {
|
|
830
|
+
const detail = `${message(err)}; the replay failed too (${storeCode(again) ?? message(again)}), so a committed claim stays open until its lease expires`;
|
|
831
|
+
return this.refuse(spec, code, detail);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
// The answer names a directory below the work directory: it must be a safe name.
|
|
835
|
+
if (!isSafeAttemptId(attemptId))
|
|
836
|
+
return this.refuse(spec, "CLAIM_INVALID", "the controller answered an attempt id that is not a safe name; nothing was started");
|
|
837
|
+
// The claim was awaited: if the worker opted out while it was in flight, the
|
|
838
|
+
// attempt goes straight back to the ledger and nothing is launched. From
|
|
839
|
+
// here to the launch everything is synchronous.
|
|
840
|
+
if (this.opted) {
|
|
841
|
+
const detail = "the worker opted out while the claim was in flight; the attempt was returned unstarted";
|
|
842
|
+
return { kind: "refused", result: await this.finish(this.result(spec, { kind: "refused", code: "OPTED_OUT", detail, attemptId }), true) };
|
|
804
843
|
}
|
|
805
844
|
const attemptDir = join(this.opts.workDir, attemptId);
|
|
806
845
|
const logPath = join(attemptDir, "output.log");
|
|
@@ -811,7 +850,7 @@ export class MacosWorker {
|
|
|
811
850
|
}
|
|
812
851
|
catch (err) {
|
|
813
852
|
const code = err instanceof WorkerRefusal ? err.code : "INPUT_FAILED";
|
|
814
|
-
return { kind: "failed", result: this.finish(this.result(spec, { kind: "failed", code, detail: message(err), attemptId })) };
|
|
853
|
+
return { kind: "failed", result: await this.finish(this.result(spec, { kind: "failed", code, detail: message(err), attemptId })) };
|
|
815
854
|
}
|
|
816
855
|
const startedAt = this.now();
|
|
817
856
|
let proc;
|
|
@@ -831,7 +870,7 @@ export class MacosWorker {
|
|
|
831
870
|
}
|
|
832
871
|
catch (err) {
|
|
833
872
|
const code = err instanceof WorkerRefusal ? err.code : "SPAWN_FAILED";
|
|
834
|
-
return { kind: "failed", result: this.finish(this.result(spec, { kind: "failed", code, detail: message(err), attemptId, startedAt })) };
|
|
873
|
+
return { kind: "failed", result: await this.finish(this.result(spec, { kind: "failed", code, detail: message(err), attemptId, startedAt })) };
|
|
835
874
|
}
|
|
836
875
|
let rootPid = null;
|
|
837
876
|
const entry = { interruptible: spec.interruptible === true, proc, result: undefined, returning: false, cancelRequested: false };
|
|
@@ -866,6 +905,9 @@ export class MacosWorker {
|
|
|
866
905
|
*/
|
|
867
906
|
async optOut() {
|
|
868
907
|
this.opted = true;
|
|
908
|
+
// A start still waiting for its run read or claim sees the opt-out when the answer
|
|
909
|
+
// arrives and returns its attempt; wait for it, so nothing is stranded.
|
|
910
|
+
await Promise.all([...this.starting]);
|
|
869
911
|
const jobs = [...this.active.values()];
|
|
870
912
|
for (const j of jobs) {
|
|
871
913
|
if (!j.interruptible || j.cancelRequested)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface LiveHost {
|
|
2
|
+
run(file: string, args: string[]): {
|
|
3
|
+
status: number | null;
|
|
4
|
+
stdout: string;
|
|
5
|
+
stderr: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare const realLiveHost: LiveHost;
|
|
9
|
+
export interface LiveOptions {
|
|
10
|
+
root: string;
|
|
11
|
+
service: string;
|
|
12
|
+
host: LiveHost;
|
|
13
|
+
out: (line: string) => void;
|
|
14
|
+
systemRoot?: string;
|
|
15
|
+
/** The node the fixture jobs run under. Defaults to the installed runtime\node.exe. */
|
|
16
|
+
node?: string;
|
|
17
|
+
/** PIDs of live processes whose command line holds the token. Defaults to a Win32_Process query. */
|
|
18
|
+
tokenPids?: (token: string) => number[];
|
|
19
|
+
/** Every PID in an OS process listing. Defaults to tasklist. */
|
|
20
|
+
listedPids?: () => Set<number>;
|
|
21
|
+
/** How long a job may take to reach a terminal outcome. */
|
|
22
|
+
outcomeTimeoutMs?: number;
|
|
23
|
+
/** Tests only: where ServiceProfiles is. Defaults to <SystemRoot>\\ServiceProfiles. */
|
|
24
|
+
serviceProfilesDir?: string;
|
|
25
|
+
/** How long to wait for Windows to create the profile after the first start. Capped at 10 s. */
|
|
26
|
+
postStartWaitMs?: number;
|
|
27
|
+
/** Tests only: the pause between polls. */
|
|
28
|
+
sleepMs?: (ms: number) => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Review C4: Windows creates the service profile at the first start. If ServiceProfiles\<service> (any type) or
|
|
32
|
+
* ProfileList\<SID> exists before that, it was left by an earlier run or planted, and must be cleared by rollback
|
|
33
|
+
* first. "Never started" is the absence of config\first-start.json, which only Administrators can write. The marker
|
|
34
|
+
* is written only after the post-start check passes (checkAfterFirstStart). Returns the refusal, or null.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkBeforeFirstStart(o: LiveOptions): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Review R8: right after the first start, the profile Windows created must pass the same folder checks rollback
|
|
39
|
+
* uses (profileFolderCheck: exact path, no link, owner SYSTEM/Administrators/service SID, protected DACL, no other
|
|
40
|
+
* writer, explicit allow ACE for the service SID, ProfileList path matches). Windows may create it lazily, so it is
|
|
41
|
+
* polled for at most 10 s; still absent is a failure. On any failure the service is stopped and no marker is
|
|
42
|
+
* written, so the next run repeats the pre-start check (and refuses, because the folder now exists). On success
|
|
43
|
+
* config\first-start.json is written. Returns the failure, or null.
|
|
44
|
+
*/
|
|
45
|
+
export declare function checkAfterFirstStart(o: LiveOptions): Promise<string | null>;
|
|
46
|
+
/** The image names these checks start, directly or through the service. Nothing else may be ended on their account. */
|
|
47
|
+
export declare const LIVE_PROCESS_NAMES: readonly ["node.exe", "hqjob.exe", "whoami.exe", "HQNDUS006040.exe", "sc.exe", "reg.exe", "tasklist.exe", "taskkill.exe", "schtasks.exe", "powershell.exe"];
|
|
48
|
+
export interface WhoamiVerdict {
|
|
49
|
+
pass: boolean;
|
|
50
|
+
reasons: string[];
|
|
51
|
+
privileges: string[];
|
|
52
|
+
/** Privileges in the token that are not in ALWAYS_GRANTED_PRIVILEGES. Any entry fails N1. */
|
|
53
|
+
extraPrivileges: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Privileges Windows leaves in a service token whatever the service's
|
|
57
|
+
* required-privileges list says. The installer trims the service to
|
|
58
|
+
* SeChangeNotifyPrivilege, which is also the one privilege the service
|
|
59
|
+
* manager never removes, so that is the whole list. Anything else in a job's
|
|
60
|
+
* token means the trim did not take effect.
|
|
61
|
+
*/
|
|
62
|
+
export declare const ALWAYS_GRANTED_PRIVILEGES: readonly string[];
|
|
63
|
+
/**
|
|
64
|
+
* Judge "whoami /all" output by SID, which does not depend on the display
|
|
65
|
+
* language: the user is the service's virtual account, the token carries the
|
|
66
|
+
* SERVICE logon group, and it carries neither Administrators (in any form,
|
|
67
|
+
* deny-only included) nor an interactive or remote-interactive logon.
|
|
68
|
+
*/
|
|
69
|
+
export declare function evaluateWhoami(text: string, service: string): WhoamiVerdict;
|
|
70
|
+
/** The node script the N2 jobs run: argv is mode pidDir token role; every process writes <role>.pid. */
|
|
71
|
+
export declare const LIVE_FIXTURE_SOURCE: string;
|
|
72
|
+
interface CaseResult {
|
|
73
|
+
name: string;
|
|
74
|
+
pass: boolean;
|
|
75
|
+
detail: string;
|
|
76
|
+
}
|
|
77
|
+
/** Cancel a four-process tree, one of them detached, through the service. */
|
|
78
|
+
export declare function cancelCase(o: LiveOptions, dir: string): Promise<CaseResult>;
|
|
79
|
+
/**
|
|
80
|
+
* True when the text is exactly one "tasklist /V /FO CSV /NH" row for a
|
|
81
|
+
* node.exe with this pid whose User Name column is the service account. Only
|
|
82
|
+
* that column is compared: the window title is set by the process itself.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isRunnerRow(text: string, pid: number, service: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Runs as the job. argv: root decoyQueueEntry decoyStateFile tag. It tries
|
|
87
|
+
* each access once and prints one JSON line. A write that is allowed is
|
|
88
|
+
* undone at once; the two open-for-write probes change no bytes.
|
|
89
|
+
*/
|
|
90
|
+
export declare const ACL_PROBE_SOURCE: string;
|
|
91
|
+
export interface AclProbeRow {
|
|
92
|
+
op: string;
|
|
93
|
+
result: "denied" | "allowed" | "error";
|
|
94
|
+
code: string;
|
|
95
|
+
}
|
|
96
|
+
/** The probe line from a job log, or nothing. */
|
|
97
|
+
export declare function parseAclProbe(log: string): AclProbeRow[];
|
|
98
|
+
export declare function evaluateAclProbe(rows: AclProbeRow[]): {
|
|
99
|
+
pass: boolean;
|
|
100
|
+
lines: string[];
|
|
101
|
+
};
|
|
102
|
+
export declare function n1(o: LiveOptions): Promise<boolean>;
|
|
103
|
+
export declare function n2(o: LiveOptions): Promise<boolean>;
|
|
104
|
+
/** After rollback: every place the pilot could have left something. Read-only. */
|
|
105
|
+
/** True only for N3 PASS. */
|
|
106
|
+
export declare function n3(o: LiveOptions): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* After rollback: every place the pilot could have left something. Read-only. "pending" (exit 3) only when the
|
|
109
|
+
* service profile held by Windows (its folder, ProfileList key and loaded hives) is all that is left and at least
|
|
110
|
+
* one hive is loaded: the two-phase uninstall's state before restart. It is not a pass.
|
|
111
|
+
*/
|
|
112
|
+
export declare function n3Status(o: LiveOptions): "pass" | "pending" | "fail";
|
|
113
|
+
export declare function liveMain(argv: string[], host?: LiveHost, platform?: NodeJS.Platform, out?: (s: string) => void,
|
|
114
|
+
/** The only names the checks may act on. Tests pass a scratch root; the command line cannot. */
|
|
115
|
+
allowed?: {
|
|
116
|
+
service: string;
|
|
117
|
+
root: string;
|
|
118
|
+
serviceProfilesDir?: string;
|
|
119
|
+
}): Promise<number>;
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=windows-service-live.d.ts.map
|