@getmateo/cli 0.0.0-stage → 0.19.7
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/LICENSE +211 -0
- package/bin/mateo +3 -0
- package/dist/classify.d.ts +19 -0
- package/dist/classify.js +49 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +143 -0
- package/dist/commands/agent/archive.d.ts +27 -0
- package/dist/commands/agent/archive.js +88 -0
- package/dist/commands/agent/attach.d.ts +8 -0
- package/dist/commands/agent/attach.js +160 -0
- package/dist/commands/agent/delete.d.ts +15 -0
- package/dist/commands/agent/delete.js +104 -0
- package/dist/commands/agent/detach.d.ts +16 -0
- package/dist/commands/agent/detach.js +44 -0
- package/dist/commands/agent/import.d.ts +14 -0
- package/dist/commands/agent/import.js +108 -0
- package/dist/commands/agent/index.d.ts +3 -0
- package/dist/commands/agent/index.js +56 -0
- package/dist/commands/agent/inspect.d.ts +15 -0
- package/dist/commands/agent/inspect.js +196 -0
- package/dist/commands/agent/logs.d.ts +39 -0
- package/dist/commands/agent/logs.js +369 -0
- package/dist/commands/agent/ls.d.ts +61 -0
- package/dist/commands/agent/ls.js +201 -0
- package/dist/commands/agent/mode.d.ts +18 -0
- package/dist/commands/agent/mode.js +100 -0
- package/dist/commands/agent/open.d.ts +11 -0
- package/dist/commands/agent/open.js +74 -0
- package/dist/commands/agent/reload.d.ts +25 -0
- package/dist/commands/agent/reload.js +64 -0
- package/dist/commands/agent/run.d.ts +77 -0
- package/dist/commands/agent/run.js +556 -0
- package/dist/commands/agent/send.d.ts +21 -0
- package/dist/commands/agent/send.js +187 -0
- package/dist/commands/agent/stop.d.ts +17 -0
- package/dist/commands/agent/stop.js +102 -0
- package/dist/commands/agent/update.d.ts +51 -0
- package/dist/commands/agent/update.js +173 -0
- package/dist/commands/agent/wait.d.ts +31 -0
- package/dist/commands/agent/wait.js +161 -0
- package/dist/commands/clone.d.ts +17 -0
- package/dist/commands/clone.js +59 -0
- package/dist/commands/daemon/config.d.ts +3 -0
- package/dist/commands/daemon/config.js +103 -0
- package/dist/commands/daemon/index.d.ts +3 -0
- package/dist/commands/daemon/index.js +28 -0
- package/dist/commands/daemon/local-daemon.d.ts +13 -0
- package/dist/commands/daemon/local-daemon.js +105 -0
- package/dist/commands/daemon/pair.d.ts +30 -0
- package/dist/commands/daemon/pair.js +145 -0
- package/dist/commands/daemon/reload.d.ts +12 -0
- package/dist/commands/daemon/reload.js +44 -0
- package/dist/commands/daemon/restart.d.ts +29 -0
- package/dist/commands/daemon/restart.js +169 -0
- package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
- package/dist/commands/daemon/runtime-toolchain.js +87 -0
- package/dist/commands/daemon/set-password.d.ts +17 -0
- package/dist/commands/daemon/set-password.js +89 -0
- package/dist/commands/daemon/start.d.ts +20 -0
- package/dist/commands/daemon/start.js +52 -0
- package/dist/commands/daemon/status.d.ts +13 -0
- package/dist/commands/daemon/status.js +119 -0
- package/dist/commands/daemon/stop.d.ts +20 -0
- package/dist/commands/daemon/stop.js +58 -0
- package/dist/commands/fleet/index.d.ts +4 -0
- package/dist/commands/fleet/index.js +57 -0
- package/dist/commands/heartbeat/index.d.ts +3 -0
- package/dist/commands/heartbeat/index.js +139 -0
- package/dist/commands/hooks.d.ts +19 -0
- package/dist/commands/hooks.js +89 -0
- package/dist/commands/hub/authority.d.ts +17 -0
- package/dist/commands/hub/authority.js +18 -0
- package/dist/commands/hub/connect.d.ts +24 -0
- package/dist/commands/hub/connect.js +44 -0
- package/dist/commands/hub/credentials.d.ts +21 -0
- package/dist/commands/hub/credentials.js +143 -0
- package/dist/commands/hub/daemon-client.d.ts +41 -0
- package/dist/commands/hub/daemon-client.js +14 -0
- package/dist/commands/hub/deploy-bundle.d.ts +16 -0
- package/dist/commands/hub/deploy-bundle.js +248 -0
- package/dist/commands/hub/deploy-triggers.d.ts +6 -0
- package/dist/commands/hub/deploy-triggers.js +116 -0
- package/dist/commands/hub/deploy.d.ts +50 -0
- package/dist/commands/hub/deploy.js +159 -0
- package/dist/commands/hub/disconnect.d.ts +17 -0
- package/dist/commands/hub/disconnect.js +24 -0
- package/dist/commands/hub/error.d.ts +6 -0
- package/dist/commands/hub/error.js +9 -0
- package/dist/commands/hub/export.d.ts +28 -0
- package/dist/commands/hub/export.js +80 -0
- package/dist/commands/hub/help.d.ts +3 -0
- package/dist/commands/hub/help.js +5 -0
- package/dist/commands/hub/hub-client/index.d.ts +22 -0
- package/dist/commands/hub/hub-client/index.js +135 -0
- package/dist/commands/hub/hub-client/internal/contracts.d.ts +126 -0
- package/dist/commands/hub/hub-client/internal/contracts.js +85 -0
- package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
- package/dist/commands/hub/hub-client/internal/problem.js +85 -0
- package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
- package/dist/commands/hub/hub-client/internal/transport.js +30 -0
- package/dist/commands/hub/index.d.ts +20 -0
- package/dist/commands/hub/index.js +94 -0
- package/dist/commands/hub/init-plan.d.ts +33 -0
- package/dist/commands/hub/init-plan.js +94 -0
- package/dist/commands/hub/init.d.ts +37 -0
- package/dist/commands/hub/init.js +525 -0
- package/dist/commands/hub/login-flow.d.ts +34 -0
- package/dist/commands/hub/login-flow.js +78 -0
- package/dist/commands/hub/login.d.ts +23 -0
- package/dist/commands/hub/login.js +40 -0
- package/dist/commands/hub/logout.d.ts +33 -0
- package/dist/commands/hub/logout.js +71 -0
- package/dist/commands/hub/origin.d.ts +2 -0
- package/dist/commands/hub/origin.js +27 -0
- package/dist/commands/hub/permissions.d.ts +22 -0
- package/dist/commands/hub/permissions.js +61 -0
- package/dist/commands/hub/projects.d.ts +24 -0
- package/dist/commands/hub/projects.js +49 -0
- package/dist/commands/hub/reporter.d.ts +10 -0
- package/dist/commands/hub/reporter.js +11 -0
- package/dist/commands/hub/starter-agent-runtime.d.ts +37 -0
- package/dist/commands/hub/starter-agent-runtime.js +49 -0
- package/dist/commands/hub/starter-trigger.d.ts +10 -0
- package/dist/commands/hub/starter-trigger.js +30 -0
- package/dist/commands/hub/status-output.d.ts +13 -0
- package/dist/commands/hub/status-output.js +30 -0
- package/dist/commands/onboard.d.ts +14 -0
- package/dist/commands/onboard.js +169 -0
- package/dist/commands/open.d.ts +4 -0
- package/dist/commands/open.js +91 -0
- package/dist/commands/permit/allow.d.ts +38 -0
- package/dist/commands/permit/allow.js +138 -0
- package/dist/commands/permit/deny.d.ts +13 -0
- package/dist/commands/permit/deny.js +100 -0
- package/dist/commands/permit/index.d.ts +3 -0
- package/dist/commands/permit/index.js +27 -0
- package/dist/commands/permit/ls.d.ts +21 -0
- package/dist/commands/permit/ls.js +54 -0
- package/dist/commands/plugin/index.d.ts +23 -0
- package/dist/commands/plugin/index.js +174 -0
- package/dist/commands/plugin/scaffold.d.ts +6 -0
- package/dist/commands/plugin/scaffold.js +212 -0
- package/dist/commands/plugin/shared.d.ts +7 -0
- package/dist/commands/plugin/shared.js +34 -0
- package/dist/commands/plugin/update.d.ts +37 -0
- package/dist/commands/plugin/update.js +58 -0
- package/dist/commands/project/create.d.ts +10 -0
- package/dist/commands/project/create.js +43 -0
- package/dist/commands/project/delete.d.ts +9 -0
- package/dist/commands/project/delete.js +35 -0
- package/dist/commands/project/index.d.ts +3 -0
- package/dist/commands/project/index.js +28 -0
- package/dist/commands/project/ls.d.ts +5 -0
- package/dist/commands/project/ls.js +19 -0
- package/dist/commands/project/rename.d.ts +15 -0
- package/dist/commands/project/rename.js +52 -0
- package/dist/commands/project/shared.d.ts +11 -0
- package/dist/commands/project/shared.js +18 -0
- package/dist/commands/provider/diagnostic.d.ts +12 -0
- package/dist/commands/provider/diagnostic.js +31 -0
- package/dist/commands/provider/index.d.ts +3 -0
- package/dist/commands/provider/index.js +21 -0
- package/dist/commands/provider/ls.d.ts +19 -0
- package/dist/commands/provider/ls.js +46 -0
- package/dist/commands/provider/models.d.ts +20 -0
- package/dist/commands/provider/models.js +53 -0
- package/dist/commands/schedule/create.d.ts +19 -0
- package/dist/commands/schedule/create.js +41 -0
- package/dist/commands/schedule/delete.d.ts +10 -0
- package/dist/commands/schedule/delete.js +32 -0
- package/dist/commands/schedule/index.d.ts +3 -0
- package/dist/commands/schedule/index.js +66 -0
- package/dist/commands/schedule/inspect.d.ts +6 -0
- package/dist/commands/schedule/inspect.js +27 -0
- package/dist/commands/schedule/logs.d.ts +6 -0
- package/dist/commands/schedule/logs.js +24 -0
- package/dist/commands/schedule/ls.d.ts +5 -0
- package/dist/commands/schedule/ls.js +25 -0
- package/dist/commands/schedule/pause.d.ts +5 -0
- package/dist/commands/schedule/pause.js +24 -0
- package/dist/commands/schedule/resume.d.ts +5 -0
- package/dist/commands/schedule/resume.js +24 -0
- package/dist/commands/schedule/run-once.d.ts +5 -0
- package/dist/commands/schedule/run-once.js +24 -0
- package/dist/commands/schedule/schema.d.ts +21 -0
- package/dist/commands/schedule/schema.js +67 -0
- package/dist/commands/schedule/shared.d.ts +61 -0
- package/dist/commands/schedule/shared.js +360 -0
- package/dist/commands/schedule/types.d.ts +165 -0
- package/dist/commands/schedule/types.js +2 -0
- package/dist/commands/schedule/update.d.ts +19 -0
- package/dist/commands/schedule/update.js +40 -0
- package/dist/commands/script/index.d.ts +3 -0
- package/dist/commands/script/index.js +19 -0
- package/dist/commands/script/ls.d.ts +6 -0
- package/dist/commands/script/ls.js +20 -0
- package/dist/commands/script/schema.d.ts +5 -0
- package/dist/commands/script/schema.js +13 -0
- package/dist/commands/script/shared.d.ts +12 -0
- package/dist/commands/script/shared.js +59 -0
- package/dist/commands/script/start.d.ts +6 -0
- package/dist/commands/script/start.js +23 -0
- package/dist/commands/script/stop.d.ts +6 -0
- package/dist/commands/script/stop.js +23 -0
- package/dist/commands/terminal/capture.d.ts +10 -0
- package/dist/commands/terminal/capture.js +67 -0
- package/dist/commands/terminal/create.d.ts +11 -0
- package/dist/commands/terminal/create.js +29 -0
- package/dist/commands/terminal/index.d.ts +3 -0
- package/dist/commands/terminal/index.js +51 -0
- package/dist/commands/terminal/kill.d.ts +6 -0
- package/dist/commands/terminal/kill.js +36 -0
- package/dist/commands/terminal/ls.d.ts +11 -0
- package/dist/commands/terminal/ls.js +21 -0
- package/dist/commands/terminal/schema.d.ts +10 -0
- package/dist/commands/terminal/schema.js +17 -0
- package/dist/commands/terminal/send-keys.d.ts +7 -0
- package/dist/commands/terminal/send-keys.js +44 -0
- package/dist/commands/terminal/shared.d.ts +13 -0
- package/dist/commands/terminal/shared.js +64 -0
- package/dist/commands/terminal/upgrade-hosts.d.ts +11 -0
- package/dist/commands/terminal/upgrade-hosts.js +46 -0
- package/dist/commands/usage/index.d.ts +29 -0
- package/dist/commands/usage/index.js +62 -0
- package/dist/commands/usage/presentation.d.ts +4 -0
- package/dist/commands/usage/presentation.js +146 -0
- package/dist/commands/workspace/archive.d.ts +13 -0
- package/dist/commands/workspace/archive.js +43 -0
- package/dist/commands/workspace/create.d.ts +50 -0
- package/dist/commands/workspace/create.js +132 -0
- package/dist/commands/workspace/index.d.ts +3 -0
- package/dist/commands/workspace/index.js +50 -0
- package/dist/commands/workspace/ls.d.ts +11 -0
- package/dist/commands/workspace/ls.js +33 -0
- package/dist/commands/workspace/rename.d.ts +23 -0
- package/dist/commands/workspace/rename.js +63 -0
- package/dist/commands/workspace/setup.d.ts +12 -0
- package/dist/commands/workspace/setup.js +41 -0
- package/dist/commands/workspace/shared.d.ts +15 -0
- package/dist/commands/workspace/shared.js +29 -0
- package/dist/commands/worktree/archive.d.ts +21 -0
- package/dist/commands/worktree/archive.js +108 -0
- package/dist/commands/worktree/create-input.d.ts +15 -0
- package/dist/commands/worktree/create-input.js +56 -0
- package/dist/commands/worktree/create.d.ts +11 -0
- package/dist/commands/worktree/create.js +50 -0
- package/dist/commands/worktree/index.d.ts +3 -0
- package/dist/commands/worktree/index.js +29 -0
- package/dist/commands/worktree/ls.d.ts +18 -0
- package/dist/commands/worktree/ls.js +73 -0
- package/dist/commands/worktree/repository-directory.d.ts +6 -0
- package/dist/commands/worktree/repository-directory.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/output/index.d.ts +45 -0
- package/dist/output/index.js +47 -0
- package/dist/output/json.d.ts +11 -0
- package/dist/output/json.js +37 -0
- package/dist/output/pairing.d.ts +9 -0
- package/dist/output/pairing.js +36 -0
- package/dist/output/quiet.d.ts +9 -0
- package/dist/output/quiet.js +22 -0
- package/dist/output/render.d.ts +15 -0
- package/dist/output/render.js +84 -0
- package/dist/output/table.d.ts +13 -0
- package/dist/output/table.js +135 -0
- package/dist/output/types.d.ts +73 -0
- package/dist/output/types.js +8 -0
- package/dist/output/with-output.d.ts +43 -0
- package/dist/output/with-output.js +85 -0
- package/dist/output/yaml.d.ts +11 -0
- package/dist/output/yaml.js +38 -0
- package/dist/run.d.ts +14 -0
- package/dist/run.js +62 -0
- package/dist/ssh/ssh-tunnel.d.ts +2 -0
- package/dist/ssh/ssh-tunnel.js +3 -0
- package/dist/utils/agent-directory.d.ts +31 -0
- package/dist/utils/agent-directory.js +48 -0
- package/dist/utils/caller-agent.d.ts +14 -0
- package/dist/utils/caller-agent.js +16 -0
- package/dist/utils/client-id.d.ts +2 -0
- package/dist/utils/client-id.js +31 -0
- package/dist/utils/client.d.ts +57 -0
- package/dist/utils/client.js +360 -0
- package/dist/utils/command-options.d.ts +8 -0
- package/dist/utils/command-options.js +49 -0
- package/dist/utils/daemon-target.d.ts +13 -0
- package/dist/utils/daemon-target.js +51 -0
- package/dist/utils/duration.d.ts +7 -0
- package/dist/utils/duration.js +39 -0
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +10 -0
- package/dist/utils/paths.d.ts +12 -0
- package/dist/utils/paths.js +22 -0
- package/dist/utils/provider-model.d.ts +11 -0
- package/dist/utils/provider-model.js +49 -0
- package/dist/utils/timeline.d.ts +12 -0
- package/dist/utils/timeline.js +16 -0
- package/dist/utils/wait-for-stop.d.ts +2 -0
- package/dist/utils/wait-for-stop.js +28 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +24 -0
- package/package.json +58 -4
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { CommandOptions, OutputSchema, SingleResult } from "../../output/index.js";
|
|
3
|
+
export interface DaemonReloadResult {
|
|
4
|
+
restartCommand: string;
|
|
5
|
+
appliedPaths: string[];
|
|
6
|
+
restartRequiredPaths: string[];
|
|
7
|
+
overrideControlledPaths: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const daemonReloadSchema: OutputSchema<DaemonReloadResult>;
|
|
10
|
+
export declare function runDaemonReloadCommand(options: CommandOptions, _command: Command): Promise<SingleResult<DaemonReloadResult>>;
|
|
11
|
+
export declare function daemonReloadCommand(): Command;
|
|
12
|
+
//# sourceMappingURL=reload.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
2
|
+
import { withOutput } from "../../output/index.js";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { describeDaemonTarget } from "../../utils/daemon-target.js";
|
|
5
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
6
|
+
export const daemonReloadSchema = {
|
|
7
|
+
idField: () => "daemon-config",
|
|
8
|
+
columns: [],
|
|
9
|
+
renderHuman(result) {
|
|
10
|
+
if (result.type !== "single")
|
|
11
|
+
return "";
|
|
12
|
+
const lines = ["Configuration reloaded."];
|
|
13
|
+
if (result.data.restartRequiredPaths.length > 0) {
|
|
14
|
+
lines.push("", "Warning: These changes require a daemon restart:", ...result.data.restartRequiredPaths.map((path) => ` ${path}`), "", `Run: ${result.data.restartCommand}`);
|
|
15
|
+
}
|
|
16
|
+
if (result.data.overrideControlledPaths.length > 0) {
|
|
17
|
+
lines.push("", "Warning: These settings are controlled by daemon launch overrides:", ...result.data.overrideControlledPaths.map((path) => ` ${path}`));
|
|
18
|
+
}
|
|
19
|
+
return lines.join("\n");
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export async function runDaemonReloadCommand(options, _command) {
|
|
23
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
24
|
+
try {
|
|
25
|
+
const payload = await client.reloadDaemonConfig();
|
|
26
|
+
return {
|
|
27
|
+
type: "single",
|
|
28
|
+
data: {
|
|
29
|
+
restartCommand: `mateo daemon restart ${options.daemonTarget.kind === "instance" ? `--home ${JSON.stringify(options.daemonTarget.home)}` : `--host ${JSON.stringify(describeDaemonTarget(options.daemonTarget))}`}`,
|
|
30
|
+
appliedPaths: payload.appliedPaths,
|
|
31
|
+
restartRequiredPaths: payload.restartRequiredPaths,
|
|
32
|
+
overrideControlledPaths: payload.overrideControlledPaths,
|
|
33
|
+
},
|
|
34
|
+
schema: daemonReloadSchema,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await client.close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function daemonReloadCommand() {
|
|
42
|
+
return addJsonAndDaemonHostOptions(new Command("reload").description("Reload config.json without restarting")).action(withOutput(runDaemonReloadCommand));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=reload.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type CommandOptions } from "../../output/index.js";
|
|
3
|
+
export declare function daemonRestartCommand(): Command;
|
|
4
|
+
export declare function runRestartCommand(options: CommandOptions, _command: Command): Promise<{
|
|
5
|
+
type: "single";
|
|
6
|
+
data: RestartCommandData;
|
|
7
|
+
schema: {
|
|
8
|
+
idField: "action";
|
|
9
|
+
columns: never[];
|
|
10
|
+
renderHuman: () => string;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
interface RestartCommandData {
|
|
14
|
+
action: "restarted" | "deferred";
|
|
15
|
+
target: string;
|
|
16
|
+
supervisorPid: number | null;
|
|
17
|
+
workerPid: number;
|
|
18
|
+
previousWorkerPid?: number;
|
|
19
|
+
acknowledged?: boolean;
|
|
20
|
+
blockers?: RestartBlocker[];
|
|
21
|
+
}
|
|
22
|
+
interface RestartBlocker {
|
|
23
|
+
kind: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
provider?: string;
|
|
26
|
+
reason: string;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=restart.d.ts.map
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { readDaemonInstance, isSameDaemonInstance, DaemonInstanceError, } from "@getmateo/server/daemon-control";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
5
|
+
import { withOutput } from "../../output/index.js";
|
|
6
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
7
|
+
import { describeDaemonTarget } from "../../utils/daemon-target.js";
|
|
8
|
+
import { parseTimeoutMs, rejectRemovedLaunchFlags } from "./local-daemon.js";
|
|
9
|
+
export function daemonRestartCommand() {
|
|
10
|
+
return rejectRemovedLaunchFlags(addJsonAndDaemonHostOptions(new Command("restart").description("Restart the selected daemon worker, retaining its supervisor launch")))
|
|
11
|
+
.option("--timeout <seconds>", "Replacement readiness deadline (default: 600)")
|
|
12
|
+
.option("--preserve-runtimes", "Restart only if every terminal and agent session survives it; otherwise report blockers and leave the daemon running")
|
|
13
|
+
.action(withOutput(runRestartCommand));
|
|
14
|
+
}
|
|
15
|
+
export async function runRestartCommand(options, _command) {
|
|
16
|
+
const target = options.daemonTarget;
|
|
17
|
+
const deadline = Date.now() + parseTimeoutMs(options.timeout);
|
|
18
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
19
|
+
const instance = target.kind === "instance" ? await readDaemonInstance(target.home) : null;
|
|
20
|
+
async function checkSupervisor() {
|
|
21
|
+
if (target.kind !== "instance")
|
|
22
|
+
return;
|
|
23
|
+
const current = await readDaemonInstance(target.home);
|
|
24
|
+
if (!current || !instance || !isSameDaemonInstance(instance, current))
|
|
25
|
+
throw new DaemonInstanceError("DAEMON_REPLACED", `Supervisor exited or was replaced for ${target.home}.`);
|
|
26
|
+
}
|
|
27
|
+
if (target.kind === "instance" && !instance)
|
|
28
|
+
throw new DaemonInstanceError("DAEMON_NOT_RUNNING", `Daemon is not running for ${target.home}.`);
|
|
29
|
+
const client = await connectToDaemon({
|
|
30
|
+
target,
|
|
31
|
+
instance: instance ?? undefined,
|
|
32
|
+
timeout: remaining(),
|
|
33
|
+
});
|
|
34
|
+
let workerPid;
|
|
35
|
+
const serverInfo = client.getLastServerInfoMessage();
|
|
36
|
+
const serverId = serverInfo?.serverId;
|
|
37
|
+
const supervisorPid = instance?.pid ?? null;
|
|
38
|
+
let outcome;
|
|
39
|
+
try {
|
|
40
|
+
workerPid = (await client.getDaemonStatus({ timeout: remaining() })).pid;
|
|
41
|
+
await checkSupervisor();
|
|
42
|
+
outcome = await requestRestart({
|
|
43
|
+
client,
|
|
44
|
+
preserveRuntimes: options.preserveRuntimes === true,
|
|
45
|
+
serverInfo,
|
|
46
|
+
timeout: remaining(),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await client.close();
|
|
51
|
+
}
|
|
52
|
+
const acknowledged = outcome.kind === "acknowledged";
|
|
53
|
+
if (outcome.kind === "deferred") {
|
|
54
|
+
return deferredRestartResult({
|
|
55
|
+
target: describeDaemonTarget(target),
|
|
56
|
+
supervisorPid,
|
|
57
|
+
workerPid,
|
|
58
|
+
blockers: outcome.blockers,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
let lastError = "No replacement worker observed";
|
|
62
|
+
while (Date.now() < deadline) {
|
|
63
|
+
try {
|
|
64
|
+
const replacement = await connectToDaemon({
|
|
65
|
+
target,
|
|
66
|
+
instance: instance ?? undefined,
|
|
67
|
+
timeout: Math.min(1000, remaining()),
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
if (replacement.getLastServerInfoMessage()?.serverId !== serverId)
|
|
71
|
+
throw new Error("Connected peer identity changed");
|
|
72
|
+
// Status probes every provider, so it can take seconds on a healthy worker.
|
|
73
|
+
const status = await replacement.getDaemonStatus({ timeout: remaining() });
|
|
74
|
+
if (status.pid !== workerPid) {
|
|
75
|
+
await checkSupervisor();
|
|
76
|
+
return {
|
|
77
|
+
type: "single",
|
|
78
|
+
data: {
|
|
79
|
+
action: "restarted",
|
|
80
|
+
target: describeDaemonTarget(target),
|
|
81
|
+
supervisorPid,
|
|
82
|
+
previousWorkerPid: workerPid,
|
|
83
|
+
workerPid: status.pid,
|
|
84
|
+
acknowledged,
|
|
85
|
+
},
|
|
86
|
+
schema: {
|
|
87
|
+
idField: "action",
|
|
88
|
+
columns: [],
|
|
89
|
+
renderHuman: () => `Restarted worker ${workerPid} → ${status.pid} at ${describeDaemonTarget(target)}. Supervisor launch retained.`,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await replacement.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
lastError = error;
|
|
100
|
+
const code = error?.code;
|
|
101
|
+
if (code === "DAEMON_REPLACED" || code === "DAEMON_NOT_RUNNING")
|
|
102
|
+
break;
|
|
103
|
+
if (!isReconnectFailure(error))
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
await delay(Math.min(100, remaining()));
|
|
107
|
+
}
|
|
108
|
+
throw {
|
|
109
|
+
code: "RESTART_NOT_CONFIRMED",
|
|
110
|
+
message: `Replacement was not confirmed for ${describeDaemonTarget(target)}. Restart acknowledged: ${acknowledged}. Last observation: ${String(lastError)}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function describeBlocker(blocker) {
|
|
114
|
+
return ` ${blocker.kind}${blocker.id ? ` ${blocker.id}` : ""}: ${blocker.reason}`;
|
|
115
|
+
}
|
|
116
|
+
function deferredRestartResult(input) {
|
|
117
|
+
return {
|
|
118
|
+
type: "single",
|
|
119
|
+
data: { action: "deferred", ...input },
|
|
120
|
+
schema: {
|
|
121
|
+
idField: "action",
|
|
122
|
+
columns: [],
|
|
123
|
+
renderHuman: () => `Restart deferred at ${input.target}; it would interrupt:\n${input.blockers
|
|
124
|
+
.map(describeBlocker)
|
|
125
|
+
.join("\n")}`,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function requestRestart(input) {
|
|
130
|
+
// A daemon without runtime handoff cannot tell what a restart would lose, so a
|
|
131
|
+
// preserving restart never restarts it.
|
|
132
|
+
if (input.preserveRuntimes && input.serverInfo?.features?.runtimeHandoff !== true) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "deferred",
|
|
135
|
+
blockers: [{ kind: "daemon", reason: "runtime_handoff_unsupported" }],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
if (!input.preserveRuntimes) {
|
|
140
|
+
await input.client.restartServer("cli_restart", undefined, { timeout: input.timeout });
|
|
141
|
+
return { kind: "acknowledged" };
|
|
142
|
+
}
|
|
143
|
+
const result = await input.client.requestRuntimeHandoffRestart({
|
|
144
|
+
reason: "cli_restart",
|
|
145
|
+
timeout: input.timeout,
|
|
146
|
+
});
|
|
147
|
+
return result.status === "accepted"
|
|
148
|
+
? { kind: "acknowledged" }
|
|
149
|
+
: { kind: "deferred", blockers: result.blockers };
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
// The connection can drop as the accepted restart begins.
|
|
153
|
+
if (!isReconnectFailure(error))
|
|
154
|
+
throw error;
|
|
155
|
+
return { kind: "unconfirmed" };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function isReconnectFailure(error) {
|
|
159
|
+
return Boolean(error &&
|
|
160
|
+
typeof error === "object" &&
|
|
161
|
+
"code" in error &&
|
|
162
|
+
[
|
|
163
|
+
"DAEMON_CONNECTION_LOST",
|
|
164
|
+
"DAEMON_REQUEST_TIMEOUT",
|
|
165
|
+
"DAEMON_UNREACHABLE",
|
|
166
|
+
"DAEMON_NOT_READY",
|
|
167
|
+
].includes(String(error.code)));
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=restart.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { platform } from "node:os";
|
|
2
|
+
import { execCommand } from "@getmateo/server/process";
|
|
3
|
+
function normalizeError(error) {
|
|
4
|
+
if (error instanceof Error) {
|
|
5
|
+
return error.message;
|
|
6
|
+
}
|
|
7
|
+
return String(error);
|
|
8
|
+
}
|
|
9
|
+
async function resolveNodePathFromPidUnix(pid) {
|
|
10
|
+
try {
|
|
11
|
+
const { stdout } = await execCommand("ps", ["-o", "comm=", "-p", String(pid)]);
|
|
12
|
+
const resolved = stdout.trim();
|
|
13
|
+
return resolved
|
|
14
|
+
? { nodePath: resolved }
|
|
15
|
+
: { nodePath: null, error: "ps returned an empty command path" };
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return { nodePath: null, error: `ps failed: ${normalizeError(error)}` };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function runProcessProbe(command, args, options) {
|
|
22
|
+
try {
|
|
23
|
+
const { stdout } = await execCommand(command, args, { shell: options?.shell });
|
|
24
|
+
const resolved = stdout.trim();
|
|
25
|
+
return resolved
|
|
26
|
+
? { resolved }
|
|
27
|
+
: { resolved: null, error: `${command} returned no executable path` };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return { resolved: null, error: `${command} failed: ${normalizeError(error)}` };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function resolveNodePathFromPidWindows(pid) {
|
|
34
|
+
const probes = [
|
|
35
|
+
{
|
|
36
|
+
label: "powershell-cim",
|
|
37
|
+
command: "powershell.exe",
|
|
38
|
+
args: [
|
|
39
|
+
"-NoProfile",
|
|
40
|
+
"-Command",
|
|
41
|
+
`(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").ExecutablePath`,
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: "powershell-process",
|
|
46
|
+
command: "powershell.exe",
|
|
47
|
+
args: ["-NoProfile", "-Command", `(Get-Process -Id ${pid}).Path`],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: "wmic",
|
|
51
|
+
command: "wmic",
|
|
52
|
+
args: ["process", "where", `ProcessId=${pid}`, "get", "ExecutablePath", "/VALUE"],
|
|
53
|
+
parseValue: (stdout) => {
|
|
54
|
+
const match = stdout.match(/ExecutablePath=(.+)/);
|
|
55
|
+
return match?.[1]?.trim() ?? null;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
const errors = [];
|
|
60
|
+
async function tryProbe(index) {
|
|
61
|
+
if (index >= probes.length) {
|
|
62
|
+
return {
|
|
63
|
+
nodePath: null,
|
|
64
|
+
error: errors.join("; ") || "could not resolve executable path from PID",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const probe = probes[index];
|
|
68
|
+
const result = await runProcessProbe(probe.command, probe.args, { shell: false });
|
|
69
|
+
if (result.resolved) {
|
|
70
|
+
const resolved = probe.parseValue ? probe.parseValue(result.resolved) : result.resolved;
|
|
71
|
+
if (resolved)
|
|
72
|
+
return { nodePath: resolved };
|
|
73
|
+
errors.push(`${probe.label} returned no executable path`);
|
|
74
|
+
}
|
|
75
|
+
else if (result.error) {
|
|
76
|
+
errors.push(`${probe.label}: ${result.error}`);
|
|
77
|
+
}
|
|
78
|
+
return tryProbe(index + 1);
|
|
79
|
+
}
|
|
80
|
+
return tryProbe(0);
|
|
81
|
+
}
|
|
82
|
+
export async function resolveNodePathFromPid(pid) {
|
|
83
|
+
return platform() === "win32"
|
|
84
|
+
? await resolveNodePathFromPidWindows(pid)
|
|
85
|
+
: await resolveNodePathFromPidUnix(pid);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=runtime-toolchain.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { CommandOptions, SingleResult } from "../../output/index.js";
|
|
3
|
+
interface SetPasswordResult {
|
|
4
|
+
action: "password_set";
|
|
5
|
+
configPath: string;
|
|
6
|
+
restartCommand: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export type PromptPassword = (message: string) => Promise<string | symbol>;
|
|
10
|
+
export interface SetPasswordOptions {
|
|
11
|
+
home?: string;
|
|
12
|
+
promptPassword?: PromptPassword;
|
|
13
|
+
}
|
|
14
|
+
export declare function setDaemonPasswordInConfig(newPassword: string, options?: SetPasswordOptions): Promise<SetPasswordResult>;
|
|
15
|
+
export declare function runSetPasswordCommand(options: CommandOptions, _command: Command): Promise<SingleResult<SetPasswordResult>>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=set-password.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isCancel, password as passwordPrompt } from "@clack/prompts";
|
|
3
|
+
import { hashDaemonPassword } from "@getmateo/server/auth";
|
|
4
|
+
import { readPersistedConfig, savePersistedConfig, } from "@getmateo/server/configuration";
|
|
5
|
+
import { resolveMateoHome } from "@getmateo/server/daemon-control";
|
|
6
|
+
const CONFIG_FILENAME = "config.json";
|
|
7
|
+
const setPasswordResultSchema = {
|
|
8
|
+
idField: "action",
|
|
9
|
+
columns: [
|
|
10
|
+
{ header: "STATUS", field: "action", color: () => "green" },
|
|
11
|
+
{ header: "CONFIG", field: "configPath" },
|
|
12
|
+
{ header: "RESTART", field: "restartCommand" },
|
|
13
|
+
],
|
|
14
|
+
renderHuman: (result, options) => {
|
|
15
|
+
const data = result.data;
|
|
16
|
+
const rows = [
|
|
17
|
+
`Password written to ${data.configPath}`,
|
|
18
|
+
"Restart the daemon for the change to take effect.",
|
|
19
|
+
`Run: ${data.restartCommand}`,
|
|
20
|
+
];
|
|
21
|
+
if (options.format === "table") {
|
|
22
|
+
return rows.join("\n");
|
|
23
|
+
}
|
|
24
|
+
return data.message;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
function createCommandError(code, message, details) {
|
|
28
|
+
return { code, message, ...(details ? { details } : {}) };
|
|
29
|
+
}
|
|
30
|
+
function terminalPasswordPrompt() {
|
|
31
|
+
if (!process.stdin.isTTY) {
|
|
32
|
+
throw createCommandError("PASSWORD_TTY_REQUIRED", "mateo daemon set-password needs a terminal to read the password", "Run it in an interactive terminal, or set MATEO_PASSWORD in the daemon's environment instead.");
|
|
33
|
+
}
|
|
34
|
+
return (message) => passwordPrompt({ message });
|
|
35
|
+
}
|
|
36
|
+
async function promptForPassword(promptPassword) {
|
|
37
|
+
const first = await promptPassword("New daemon password");
|
|
38
|
+
if (isCancel(first)) {
|
|
39
|
+
throw createCommandError("PASSWORD_CANCELLED", "Password update cancelled");
|
|
40
|
+
}
|
|
41
|
+
if (typeof first !== "string" || first.length === 0) {
|
|
42
|
+
throw createCommandError("PASSWORD_REQUIRED", "Password cannot be empty");
|
|
43
|
+
}
|
|
44
|
+
const second = await promptPassword("Confirm daemon password");
|
|
45
|
+
if (isCancel(second)) {
|
|
46
|
+
throw createCommandError("PASSWORD_CANCELLED", "Password update cancelled");
|
|
47
|
+
}
|
|
48
|
+
if (first !== second) {
|
|
49
|
+
throw createCommandError("PASSWORD_MISMATCH", "Passwords do not match");
|
|
50
|
+
}
|
|
51
|
+
return first;
|
|
52
|
+
}
|
|
53
|
+
export async function setDaemonPasswordInConfig(newPassword, options = {}) {
|
|
54
|
+
const mateoHome = resolveMateoHome({ MATEO_HOME: options.home });
|
|
55
|
+
const configPath = path.join(mateoHome, CONFIG_FILENAME);
|
|
56
|
+
const persisted = readPersistedConfig(mateoHome);
|
|
57
|
+
const nextConfig = {
|
|
58
|
+
...persisted,
|
|
59
|
+
daemon: {
|
|
60
|
+
...persisted.daemon,
|
|
61
|
+
auth: {
|
|
62
|
+
...persisted.daemon?.auth,
|
|
63
|
+
password: hashDaemonPassword(newPassword),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
savePersistedConfig(mateoHome, nextConfig);
|
|
68
|
+
return {
|
|
69
|
+
action: "password_set",
|
|
70
|
+
configPath,
|
|
71
|
+
restartCommand: `mateo daemon restart --home ${JSON.stringify(mateoHome)}`,
|
|
72
|
+
message: `Password written to ${configPath}\nRestart the daemon for the change to take effect.\nRun: mateo daemon restart --home ${JSON.stringify(mateoHome)}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export async function runSetPasswordCommand(options, _command) {
|
|
76
|
+
const promptPassword = typeof options.promptPassword === "function"
|
|
77
|
+
? options.promptPassword
|
|
78
|
+
: terminalPasswordPrompt();
|
|
79
|
+
const newPassword = await promptForPassword(promptPassword);
|
|
80
|
+
const result = await setDaemonPasswordInConfig(newPassword, {
|
|
81
|
+
home: options.daemonTarget.kind === "instance" ? options.daemonTarget.home : undefined,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
type: "single",
|
|
85
|
+
data: result,
|
|
86
|
+
schema: setPasswordResultSchema,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=set-password.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type CommandOptions } from "../../output/index.js";
|
|
3
|
+
export declare function startCommand(): Command;
|
|
4
|
+
export declare function runStart(options: CommandOptions, _command: Command): Promise<{
|
|
5
|
+
type: "single";
|
|
6
|
+
data: {
|
|
7
|
+
action: string;
|
|
8
|
+
home: string;
|
|
9
|
+
pid: number;
|
|
10
|
+
listen: string | null;
|
|
11
|
+
logPath: string;
|
|
12
|
+
};
|
|
13
|
+
schema: {
|
|
14
|
+
idField: "pid";
|
|
15
|
+
columns: never[];
|
|
16
|
+
renderHuman: () => string;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
export declare function daemonRunCommand(): Command;
|
|
20
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { addLocalDaemonOptions } from "../../utils/command-options.js";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { daemonLogPath } from "@getmateo/server/daemon-control";
|
|
4
|
+
import { launchLocalDaemon, parseTimeoutMs, rejectRemovedLaunchFlags } from "./local-daemon.js";
|
|
5
|
+
import { withOutput } from "../../output/index.js";
|
|
6
|
+
export function startCommand() {
|
|
7
|
+
return rejectRemovedLaunchFlags(addLocalDaemonOptions(new Command("start")))
|
|
8
|
+
.description("Start the local daemon from persistent configuration (local operation)")
|
|
9
|
+
.option("--timeout <seconds>", "Readiness deadline (default: 600)")
|
|
10
|
+
.action(withOutput(runStart));
|
|
11
|
+
}
|
|
12
|
+
export async function runStart(options, _command) {
|
|
13
|
+
if (options.daemonTarget.kind !== "instance")
|
|
14
|
+
throw new Error("Start requires a local home");
|
|
15
|
+
const home = options.daemonTarget.home;
|
|
16
|
+
const result = await launchLocalDaemon({ home, timeoutMs: parseTimeoutMs(options.timeout) });
|
|
17
|
+
const data = {
|
|
18
|
+
action: result.spawned ? "started" : "already_running",
|
|
19
|
+
home,
|
|
20
|
+
pid: result.instance.pid,
|
|
21
|
+
listen: result.instance.listen,
|
|
22
|
+
logPath: daemonLogPath(home),
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
type: "single",
|
|
26
|
+
data,
|
|
27
|
+
schema: {
|
|
28
|
+
idField: "pid",
|
|
29
|
+
columns: [],
|
|
30
|
+
renderHuman: () => `${result.spawned ? "Started" : "Already running"}: PID ${data.pid}${data.listen ? `, listening on ${data.listen}` : ", not ready"}\nLogs: ${data.logPath}`,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function daemonRunCommand() {
|
|
35
|
+
return rejectRemovedLaunchFlags(addLocalDaemonOptions(new Command("run")))
|
|
36
|
+
.description("Run a local daemon in the foreground with deployment environment overrides")
|
|
37
|
+
.action(withOutput(async (options, _command) => {
|
|
38
|
+
if (options.daemonTarget.kind !== "instance")
|
|
39
|
+
throw new Error("Run requires a local home");
|
|
40
|
+
const result = await launchLocalDaemon({
|
|
41
|
+
home: options.daemonTarget.home,
|
|
42
|
+
foreground: true,
|
|
43
|
+
});
|
|
44
|
+
process.exitCode = result.exitCode ?? 0;
|
|
45
|
+
return {
|
|
46
|
+
type: "single",
|
|
47
|
+
data: { pid: result.instance.pid, action: result.spawned ? "exited" : "already_running" },
|
|
48
|
+
schema: { idField: "pid", columns: [] },
|
|
49
|
+
};
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type CommandOptions } from "../../output/index.js";
|
|
3
|
+
export declare function daemonStatusCommand(): Command;
|
|
4
|
+
export declare function runStatusCommand(options: CommandOptions, _command: Command): Promise<{
|
|
5
|
+
type: "single";
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
schema: {
|
|
8
|
+
idField: () => string;
|
|
9
|
+
columns: never[];
|
|
10
|
+
renderHuman: () => string;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { DaemonConnectionError } from "@getmateo/client/internal/daemon-client";
|
|
3
|
+
import { readDaemonInstance, daemonLogPath, isSameDaemonInstance, DaemonInstanceError, } from "@getmateo/server/daemon-control";
|
|
4
|
+
import { readPersistedConfig, resolveConfigFromPersisted } from "@getmateo/server/configuration";
|
|
5
|
+
import { connectToDaemon, buildDaemonConnectionCommandError } from "../../utils/client.js";
|
|
6
|
+
import { withOutput, toCommandError } from "../../output/index.js";
|
|
7
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
8
|
+
import { describeDaemonTarget } from "../../utils/daemon-target.js";
|
|
9
|
+
export function daemonStatusCommand() {
|
|
10
|
+
return addJsonAndDaemonHostOptions(new Command("status").description("Observe the selected daemon and its published endpoint")).action(withOutput(runStatusCommand));
|
|
11
|
+
}
|
|
12
|
+
export async function runStatusCommand(options, _command) {
|
|
13
|
+
const target = options.daemonTarget;
|
|
14
|
+
const instance = target.kind === "instance" ? await readDaemonInstance(target.home) : null;
|
|
15
|
+
const local = target.kind === "instance"
|
|
16
|
+
? localStatus(target.home, instance)
|
|
17
|
+
: { host: describeDaemonTarget(target) };
|
|
18
|
+
const observed = target.kind === "endpoint" || instance?.listen
|
|
19
|
+
? await probeDaemonStatus(target, instance, local)
|
|
20
|
+
: { connectedDaemon: "not_probed" };
|
|
21
|
+
const data = { ...local, ...observed };
|
|
22
|
+
return {
|
|
23
|
+
type: "single",
|
|
24
|
+
data,
|
|
25
|
+
schema: {
|
|
26
|
+
idField: () => "daemon",
|
|
27
|
+
columns: [],
|
|
28
|
+
renderHuman: () => Object.entries(data)
|
|
29
|
+
.filter(([, value]) => value !== undefined)
|
|
30
|
+
.map(([key, value]) => `${key}: ${typeof value === "object" ? JSON.stringify(value) : value}`)
|
|
31
|
+
.join("\n"),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function probeDaemonStatus(target, instance, local) {
|
|
36
|
+
let connectedDaemon = "unreachable";
|
|
37
|
+
let note;
|
|
38
|
+
let live = {};
|
|
39
|
+
let client;
|
|
40
|
+
try {
|
|
41
|
+
client = await connectToDaemon({ target, instance: instance ?? undefined, timeout: 1500 });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const failure = buildDaemonConnectionCommandError({ target, error });
|
|
45
|
+
if (target.kind === "endpoint")
|
|
46
|
+
throw failure;
|
|
47
|
+
connectedDaemon = "unreachable";
|
|
48
|
+
if (failure.code === "AUTH_REQUIRED")
|
|
49
|
+
connectedDaemon = "auth_required";
|
|
50
|
+
if (failure.code === "AUTH_FAILED")
|
|
51
|
+
connectedDaemon = "auth_failed";
|
|
52
|
+
note = failure.message;
|
|
53
|
+
}
|
|
54
|
+
if (!client)
|
|
55
|
+
return { connectedDaemon, note };
|
|
56
|
+
try {
|
|
57
|
+
let requestError;
|
|
58
|
+
const status = await client.getDaemonStatus({ timeout: 1500 }).catch((error) => {
|
|
59
|
+
requestError = error;
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
// Recheck even when the RPC times out before combining local and live observations.
|
|
63
|
+
const current = target.kind === "instance" ? await readDaemonInstance(target.home) : null;
|
|
64
|
+
if (instance && (!current || !isSameDaemonInstance(instance, current)))
|
|
65
|
+
throw new DaemonInstanceError("DAEMON_REPLACED", "Supervisor exited or was replaced during status observation.");
|
|
66
|
+
const info = client.getLastServerInfoMessage();
|
|
67
|
+
live = daemonIdentity({ info, status });
|
|
68
|
+
connectedDaemon = client.isConnected ? "reachable" : "unreachable";
|
|
69
|
+
if (!status) {
|
|
70
|
+
const failure = toCommandError(requestError);
|
|
71
|
+
note = `Status details unavailable (${failure.code}): ${failure.message}`;
|
|
72
|
+
if (target.kind === "endpoint" ||
|
|
73
|
+
!client.isConnected ||
|
|
74
|
+
!(requestError instanceof DaemonConnectionError) ||
|
|
75
|
+
requestError.code !== "DAEMON_REQUEST_TIMEOUT") {
|
|
76
|
+
throw { ...failure, message: note, details: { ...local, ...live, connectedDaemon } };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
live = {
|
|
81
|
+
...live,
|
|
82
|
+
workerPid: status.pid,
|
|
83
|
+
daemonNode: status.nodePath,
|
|
84
|
+
providers: status.providers,
|
|
85
|
+
relay: status.relay,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await client.close();
|
|
91
|
+
}
|
|
92
|
+
return { ...live, connectedDaemon, note };
|
|
93
|
+
}
|
|
94
|
+
function daemonIdentity(input) {
|
|
95
|
+
return {
|
|
96
|
+
serverId: input.info?.serverId,
|
|
97
|
+
daemonVersion: input.status ? input.status.version : input.info?.version,
|
|
98
|
+
daemonBuild: input.status?.build ?? input.info?.build ?? null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function localStatus(home, instance) {
|
|
102
|
+
const config = resolveConfigFromPersisted(home, readPersistedConfig(home, { defaultsIfMissing: true }), { env: {} });
|
|
103
|
+
let localDaemon = "stopped";
|
|
104
|
+
if (instance)
|
|
105
|
+
localDaemon = instance.listen ? "running" : "not_ready";
|
|
106
|
+
return {
|
|
107
|
+
home,
|
|
108
|
+
pid: instance?.pid ?? null,
|
|
109
|
+
startedAt: instance?.startedAt ?? null,
|
|
110
|
+
listen: instance?.listen ?? null,
|
|
111
|
+
serverId: instance?.serverId ?? undefined,
|
|
112
|
+
hostname: instance?.hostname ?? null,
|
|
113
|
+
configuredListen: config.listen,
|
|
114
|
+
localDaemon,
|
|
115
|
+
desktopManaged: instance?.desktopManaged === true,
|
|
116
|
+
logPath: daemonLogPath(home),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=status.js.map
|