@getmateo/cli 0.0.0-stage → 0.19.8
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 +63 -4
- package/README.md +0 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type CommandOptions } from "../../output/index.js";
|
|
3
|
+
export declare function daemonStopCommand(): Command;
|
|
4
|
+
export declare function runStopCommand(options: CommandOptions, _command: Command): Promise<{
|
|
5
|
+
type: "single";
|
|
6
|
+
data: {
|
|
7
|
+
action: string;
|
|
8
|
+
home?: string;
|
|
9
|
+
host?: string;
|
|
10
|
+
pid?: number | null;
|
|
11
|
+
forced?: boolean;
|
|
12
|
+
usedLifecycleRpc?: boolean;
|
|
13
|
+
};
|
|
14
|
+
schema: {
|
|
15
|
+
idField: "action";
|
|
16
|
+
columns: never[];
|
|
17
|
+
renderHuman: () => string;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=stop.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { stopDaemonInstance } from "@getmateo/server/daemon-control";
|
|
3
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
4
|
+
import { withOutput } from "../../output/index.js";
|
|
5
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
6
|
+
import { describeDaemonTarget } from "../../utils/daemon-target.js";
|
|
7
|
+
import { parseTimeoutMs } from "./local-daemon.js";
|
|
8
|
+
export function daemonStopCommand() {
|
|
9
|
+
return addJsonAndDaemonHostOptions(new Command("stop").description("Stop the selected daemon"))
|
|
10
|
+
.option("--timeout <seconds>", "Graceful exit deadline (default: 15)")
|
|
11
|
+
.option("--force", "Permit forced local process cleanup")
|
|
12
|
+
.option("--kill-timeout <seconds>", "Forced exit deadline (default: 3)")
|
|
13
|
+
.action(withOutput(runStopCommand));
|
|
14
|
+
}
|
|
15
|
+
export async function runStopCommand(options, _command) {
|
|
16
|
+
const target = options.daemonTarget;
|
|
17
|
+
const timeoutMs = parseTimeoutMs(options.timeout, 15000);
|
|
18
|
+
const deadline = Date.now() + timeoutMs;
|
|
19
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
20
|
+
const requestShutdown = async (instance) => {
|
|
21
|
+
const client = await connectToDaemon({ target, timeout: remaining(), instance });
|
|
22
|
+
try {
|
|
23
|
+
await client.shutdownServer({ timeout: remaining() });
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await client.close();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (target.kind === "endpoint" && options.force)
|
|
30
|
+
throw {
|
|
31
|
+
code: "INVALID_OPTIONS",
|
|
32
|
+
message: "--force requires a local --home; an endpoint gives no remote process authority.",
|
|
33
|
+
};
|
|
34
|
+
const result = target.kind === "instance"
|
|
35
|
+
? {
|
|
36
|
+
...(await stopDaemonInstance(target.home, {
|
|
37
|
+
force: options.force === true,
|
|
38
|
+
timeoutMs,
|
|
39
|
+
killTimeoutMs: parseTimeoutMs(options.killTimeout, 3000),
|
|
40
|
+
requestShutdown,
|
|
41
|
+
})),
|
|
42
|
+
home: target.home,
|
|
43
|
+
}
|
|
44
|
+
: (await requestShutdown(),
|
|
45
|
+
{ action: "shutdown_requested", host: describeDaemonTarget(target) });
|
|
46
|
+
return {
|
|
47
|
+
type: "single",
|
|
48
|
+
data: result,
|
|
49
|
+
schema: {
|
|
50
|
+
idField: "action",
|
|
51
|
+
columns: [],
|
|
52
|
+
renderHuman: () => target.kind === "endpoint"
|
|
53
|
+
? "Shutdown requested; remote process exit was not verified."
|
|
54
|
+
: `${result.action.replaceAll("_", " ")}: ${target.home}`,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=stop.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { withOutput, } from "../../output/index.js";
|
|
3
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
4
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
5
|
+
const memberSchema = {
|
|
6
|
+
idField: "serverId",
|
|
7
|
+
columns: [
|
|
8
|
+
{ header: "SERVER", field: "serverId" },
|
|
9
|
+
{ header: "LABEL", field: "label" },
|
|
10
|
+
{ header: "LINK", field: "linkType" },
|
|
11
|
+
{ header: "STATUS", field: "status" },
|
|
12
|
+
{
|
|
13
|
+
header: "DISPATCH",
|
|
14
|
+
field: (member) => {
|
|
15
|
+
if (member.acceptsDispatch === null)
|
|
16
|
+
return "unknown";
|
|
17
|
+
return member.acceptsDispatch ? "accepting" : (member.dispatchBlockedReason ?? "refusing");
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{ header: "ERROR", field: (member) => member.error?.code ?? "" },
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
const selfSchema = {
|
|
24
|
+
idField: "serverId",
|
|
25
|
+
columns: [
|
|
26
|
+
{ header: "SERVER", field: "serverId" },
|
|
27
|
+
{ header: "LABEL", field: "label" },
|
|
28
|
+
{ header: "FLEET", field: (self) => self.fleetId ?? "(none)" },
|
|
29
|
+
{ header: "PASSWORD", field: (self) => (self.passwordEnabled ? "set" : "missing") },
|
|
30
|
+
{ header: "ACCEPTS DISPATCH", field: (self) => (self.acceptsDispatch ? "yes" : "no") },
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
async function readStatus(options) {
|
|
34
|
+
const client = await connectToDaemon({ target: options.daemonTarget });
|
|
35
|
+
try {
|
|
36
|
+
return await client.getFleetStatus();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
await client.close().catch(() => undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Read-only fleet diagnostics. Membership is managed by the App. */
|
|
43
|
+
export function createFleetCommand() {
|
|
44
|
+
const fleet = new Command("fleet").description("Inspect this host's fleet membership (managed from the app)");
|
|
45
|
+
addJsonAndDaemonHostOptions(fleet.command("status").description("Show this host's fleet and dispatch state")).action(withOutput(async (options, _command) => ({
|
|
46
|
+
type: "single",
|
|
47
|
+
data: (await readStatus(options)).self,
|
|
48
|
+
schema: selfSchema,
|
|
49
|
+
})));
|
|
50
|
+
addJsonAndDaemonHostOptions(fleet.command("ls").description("List the other fleet members and their link state")).action(withOutput(async (options, _command) => ({
|
|
51
|
+
type: "list",
|
|
52
|
+
data: (await readStatus(options)).members,
|
|
53
|
+
schema: memberSchema,
|
|
54
|
+
})));
|
|
55
|
+
return fleet;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { withOutput } from "../../output/index.js";
|
|
3
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
4
|
+
import { parseDuration } from "../../utils/duration.js";
|
|
5
|
+
import { connectScheduleClient, toScheduleCommandError, toScheduleRow, } from "../schedule/shared.js";
|
|
6
|
+
import { scheduleSchema } from "../schedule/schema.js";
|
|
7
|
+
const heartbeatDeleteSchema = {
|
|
8
|
+
idField: "id",
|
|
9
|
+
columns: [
|
|
10
|
+
{ header: "ID", field: "id" },
|
|
11
|
+
{ header: "STATUS", field: "status" },
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
function requireCallerAgentId() {
|
|
15
|
+
const agentId = process.env.MATEO_AGENT_ID?.trim();
|
|
16
|
+
if (!agentId) {
|
|
17
|
+
throw new Error("Heartbeat commands must run inside a Mateo agent");
|
|
18
|
+
}
|
|
19
|
+
return agentId;
|
|
20
|
+
}
|
|
21
|
+
async function requireOwnedHeartbeat(client, id, agentId) {
|
|
22
|
+
const payload = await client.scheduleInspect({ id });
|
|
23
|
+
if (payload.error || !payload.schedule) {
|
|
24
|
+
throw new Error(payload.error ?? `Heartbeat not found: ${id}`);
|
|
25
|
+
}
|
|
26
|
+
if (payload.schedule.target.type !== "agent" || payload.schedule.target.agentId !== agentId) {
|
|
27
|
+
throw new Error(`Heartbeat ${id} does not belong to agent ${agentId}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function runCreateHeartbeat(prompt, options, _command) {
|
|
31
|
+
const agentId = requireCallerAgentId();
|
|
32
|
+
const cron = options.cron?.trim();
|
|
33
|
+
if (!cron) {
|
|
34
|
+
throw new Error("--cron is required");
|
|
35
|
+
}
|
|
36
|
+
const { client } = await connectScheduleClient(options.daemonTarget);
|
|
37
|
+
try {
|
|
38
|
+
const maxRuns = options.maxRuns ? Number.parseInt(options.maxRuns, 10) : undefined;
|
|
39
|
+
if (maxRuns !== undefined && (!Number.isSafeInteger(maxRuns) || maxRuns <= 0)) {
|
|
40
|
+
throw new Error("--max-runs must be a positive integer");
|
|
41
|
+
}
|
|
42
|
+
const payload = await client.scheduleCreate({
|
|
43
|
+
prompt: prompt.trim(),
|
|
44
|
+
cadence: {
|
|
45
|
+
type: "cron",
|
|
46
|
+
expression: cron,
|
|
47
|
+
...(options.timezone?.trim() ? { timezone: options.timezone.trim() } : {}),
|
|
48
|
+
},
|
|
49
|
+
target: { type: "agent", agentId },
|
|
50
|
+
...(options.name?.trim() ? { name: options.name.trim() } : {}),
|
|
51
|
+
...(maxRuns ? { maxRuns } : {}),
|
|
52
|
+
...(options.expiresIn
|
|
53
|
+
? { expiresAt: new Date(Date.now() + parseDuration(options.expiresIn)).toISOString() }
|
|
54
|
+
: {}),
|
|
55
|
+
});
|
|
56
|
+
if (payload.error || !payload.schedule) {
|
|
57
|
+
throw new Error(payload.error ?? "Heartbeat creation failed");
|
|
58
|
+
}
|
|
59
|
+
return { type: "single", data: toScheduleRow(payload.schedule), schema: scheduleSchema };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw toScheduleCommandError("HEARTBEAT_CREATE_FAILED", "create heartbeat", error);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await client.close().catch(() => undefined);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function runUpdateHeartbeat(id, options, _command) {
|
|
69
|
+
const agentId = requireCallerAgentId();
|
|
70
|
+
const cron = options.cron?.trim();
|
|
71
|
+
if (!cron) {
|
|
72
|
+
throw new Error("--cron is required");
|
|
73
|
+
}
|
|
74
|
+
const { client } = await connectScheduleClient(options.daemonTarget);
|
|
75
|
+
try {
|
|
76
|
+
await requireOwnedHeartbeat(client, id, agentId);
|
|
77
|
+
const payload = await client.scheduleUpdate({
|
|
78
|
+
id,
|
|
79
|
+
cadence: {
|
|
80
|
+
type: "cron",
|
|
81
|
+
expression: cron,
|
|
82
|
+
...(options.timezone?.trim() ? { timezone: options.timezone.trim() } : {}),
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
if (payload.error || !payload.schedule) {
|
|
86
|
+
throw new Error(payload.error ?? `Heartbeat update failed: ${id}`);
|
|
87
|
+
}
|
|
88
|
+
return { type: "single", data: toScheduleRow(payload.schedule), schema: scheduleSchema };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw toScheduleCommandError("HEARTBEAT_UPDATE_FAILED", "update heartbeat", error);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
await client.close().catch(() => undefined);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function runDeleteHeartbeat(id, options, _command) {
|
|
98
|
+
const agentId = requireCallerAgentId();
|
|
99
|
+
const { client } = await connectScheduleClient(options.daemonTarget);
|
|
100
|
+
try {
|
|
101
|
+
await requireOwnedHeartbeat(client, id, agentId);
|
|
102
|
+
const payload = await client.scheduleDelete({ id });
|
|
103
|
+
if (payload.error) {
|
|
104
|
+
throw new Error(payload.error);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
type: "single",
|
|
108
|
+
data: { id: payload.scheduleId, status: "deleted" },
|
|
109
|
+
schema: heartbeatDeleteSchema,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw toScheduleCommandError("HEARTBEAT_DELETE_FAILED", "delete heartbeat", error);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await client.close().catch(() => undefined);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function createHeartbeatCommand() {
|
|
120
|
+
const heartbeat = new Command("heartbeat").description("Manage this agent's heartbeats");
|
|
121
|
+
addJsonAndDaemonHostOptions(heartbeat
|
|
122
|
+
.command("create")
|
|
123
|
+
.description("Create a recurring prompt for this agent")
|
|
124
|
+
.argument("<prompt>", "Prompt to send")
|
|
125
|
+
.requiredOption("--cron <expr>", "Five-field cron cadence")
|
|
126
|
+
.option("--timezone <iana>", "IANA time zone")
|
|
127
|
+
.option("--name <name>", "Heartbeat name")
|
|
128
|
+
.option("--max-runs <n>", "Maximum number of runs")
|
|
129
|
+
.option("--expires-in <duration>", "Time to live")).action(withOutput(runCreateHeartbeat));
|
|
130
|
+
addJsonAndDaemonHostOptions(heartbeat
|
|
131
|
+
.command("update")
|
|
132
|
+
.description("Change a heartbeat cron cadence")
|
|
133
|
+
.argument("<id>", "Heartbeat ID")
|
|
134
|
+
.requiredOption("--cron <expr>", "Five-field cron cadence")
|
|
135
|
+
.option("--timezone <iana>", "IANA time zone")).action(withOutput(runUpdateHeartbeat));
|
|
136
|
+
addJsonAndDaemonHostOptions(heartbeat.command("delete").description("Delete a heartbeat").argument("<id>", "Heartbeat ID")).action(withOutput(runDeleteHeartbeat));
|
|
137
|
+
return heartbeat;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
interface HookEnvironment {
|
|
3
|
+
MATEO_TERMINAL_ID?: string;
|
|
4
|
+
MATEO_ACTIVITY_TOKEN?: string;
|
|
5
|
+
MATEO_TERMINAL_ACTIVITY_URL?: string;
|
|
6
|
+
}
|
|
7
|
+
interface HookInput {
|
|
8
|
+
[Symbol.asyncIterator](): AsyncIterator<string | Buffer>;
|
|
9
|
+
isTTY?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface HooksRuntime {
|
|
12
|
+
env: HookEnvironment;
|
|
13
|
+
input: HookInput;
|
|
14
|
+
fetch: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
export declare function createHooksCommand(): Command;
|
|
17
|
+
export declare function runHooksCommand(agent: string, event: string, runtime?: HooksRuntime): Promise<void>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { resolveHookActivity } from "@getmateo/server/agent-hooks";
|
|
3
|
+
export function createHooksCommand() {
|
|
4
|
+
return new Command("hooks")
|
|
5
|
+
.description("Record agent hook activity")
|
|
6
|
+
.argument("<agent>", "Agent hook source")
|
|
7
|
+
.argument("<event>", "Agent hook event")
|
|
8
|
+
.action((agent, event) => runHooksCommand(agent, event));
|
|
9
|
+
}
|
|
10
|
+
export async function runHooksCommand(agent, event, runtime = {
|
|
11
|
+
env: process.env,
|
|
12
|
+
input: process.stdin,
|
|
13
|
+
fetch,
|
|
14
|
+
}) {
|
|
15
|
+
const target = resolveTarget(runtime.env);
|
|
16
|
+
if (!target)
|
|
17
|
+
return;
|
|
18
|
+
const state = await resolveHookActivity({
|
|
19
|
+
provider: agent,
|
|
20
|
+
event,
|
|
21
|
+
input: {
|
|
22
|
+
isTTY: runtime.input.isTTY,
|
|
23
|
+
read: () => readInput(runtime.input),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!state)
|
|
27
|
+
return;
|
|
28
|
+
await postActivity(target, state, runtime.fetch);
|
|
29
|
+
}
|
|
30
|
+
function resolveTarget(env) {
|
|
31
|
+
const terminalId = env.MATEO_TERMINAL_ID;
|
|
32
|
+
const token = env.MATEO_ACTIVITY_TOKEN;
|
|
33
|
+
const url = env.MATEO_TERMINAL_ACTIVITY_URL;
|
|
34
|
+
if (!terminalId || !token || !url)
|
|
35
|
+
return null;
|
|
36
|
+
return { terminalId, token, url };
|
|
37
|
+
}
|
|
38
|
+
async function readInput(input) {
|
|
39
|
+
const iterator = input[Symbol.asyncIterator]();
|
|
40
|
+
const chunks = [];
|
|
41
|
+
while (true) {
|
|
42
|
+
const next = await withTimeout(iterator.next(), 100);
|
|
43
|
+
if (!next) {
|
|
44
|
+
await iterator.return?.();
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (next.done)
|
|
48
|
+
return chunks.join("");
|
|
49
|
+
chunks.push(String(next.value));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function withTimeout(promise, ms) {
|
|
53
|
+
let timeout;
|
|
54
|
+
try {
|
|
55
|
+
return await Promise.race([
|
|
56
|
+
promise,
|
|
57
|
+
new Promise((resolve) => {
|
|
58
|
+
timeout = setTimeout(() => resolve(null), ms);
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
if (timeout)
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function postActivity(target, state, send) {
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const timeout = setTimeout(() => controller.abort(), 500);
|
|
70
|
+
try {
|
|
71
|
+
await send(target.url, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "content-type": "application/json" },
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
terminalId: target.terminalId,
|
|
76
|
+
token: target.token,
|
|
77
|
+
state,
|
|
78
|
+
}),
|
|
79
|
+
signal: controller.signal,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HubCredentialStore } from "./credentials.js";
|
|
2
|
+
export interface HubAuthorityOptions {
|
|
3
|
+
origin?: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ResolveHubInput {
|
|
7
|
+
options: HubAuthorityOptions;
|
|
8
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
9
|
+
credentials: HubCredentialStore;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_HUB_ORIGIN = "https://hub.paseo.sh";
|
|
12
|
+
export declare function resolveHubOrigin(input: ResolveHubInput): string;
|
|
13
|
+
export declare function resolveHubCredential(input: ResolveHubInput & {
|
|
14
|
+
origin: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=authority.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HubCommandError } from "./error.js";
|
|
2
|
+
import { normalizeHubOrigin } from "./origin.js";
|
|
3
|
+
export const DEFAULT_HUB_ORIGIN = "https://hub.paseo.sh";
|
|
4
|
+
export function resolveHubOrigin(input) {
|
|
5
|
+
const configuredOrigin = input.options.origin ?? input.env.MATEO_HUB_URL;
|
|
6
|
+
const selectedOrigin = configuredOrigin ?? input.credentials.active()?.origin ?? DEFAULT_HUB_ORIGIN;
|
|
7
|
+
return normalizeHubOrigin(selectedOrigin);
|
|
8
|
+
}
|
|
9
|
+
export function resolveHubCredential(input) {
|
|
10
|
+
const explicitCredential = input.options.apiKey ?? input.env.MATEO_HUB_API_KEY;
|
|
11
|
+
if (explicitCredential !== undefined)
|
|
12
|
+
return explicitCredential;
|
|
13
|
+
const stored = input.credentials.get(input.origin);
|
|
14
|
+
if (stored !== null)
|
|
15
|
+
return stored.credential;
|
|
16
|
+
throw new HubCommandError("HUB_API_KEY_REQUIRED", `No stored Hub login matches ${input.origin}. Run \`mateo hub login ${input.origin}\`, pass --api-key <secret>, or set MATEO_HUB_API_KEY.`);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=authority.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { HubHttpClient } from "./hub-client/index.js";
|
|
3
|
+
import type { HubCredentialStore } from "./credentials.js";
|
|
4
|
+
import type { HubDaemonConnection } from "./daemon-client.js";
|
|
5
|
+
import { type HubReporter } from "./reporter.js";
|
|
6
|
+
interface HubConnectOptions {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
host?: string;
|
|
9
|
+
daemonTarget: import("../../utils/daemon-target.js").DaemonTarget;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
permission?: readonly string[];
|
|
12
|
+
permissions?: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
interface HubConnectDependencies {
|
|
15
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
16
|
+
credentials: HubCredentialStore;
|
|
17
|
+
hub: Pick<HubHttpClient, "issueEnrollmentToken">;
|
|
18
|
+
daemon: HubDaemonConnection;
|
|
19
|
+
reporter: HubReporter;
|
|
20
|
+
}
|
|
21
|
+
export declare function runHubConnect(originInput: string | undefined, options: HubConnectOptions, dependencies: HubConnectDependencies): Promise<import("../../output/types.js").ListResult<import("./status-output.js").HubRow>>;
|
|
22
|
+
export declare function addHubConnectCommand(parent: Command, dependencies: HubConnectDependencies): void;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { withOutput } from "../../output/index.js";
|
|
2
|
+
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
|
3
|
+
import { resolveHubCredential, resolveHubOrigin } from "./authority.js";
|
|
4
|
+
import { withHubDaemon } from "./daemon-client.js";
|
|
5
|
+
import { hubStatusResult } from "./status-output.js";
|
|
6
|
+
import { reportHubProgress } from "./reporter.js";
|
|
7
|
+
import { addHubResolutionHelp } from "./help.js";
|
|
8
|
+
export async function runHubConnect(originInput, options, dependencies) {
|
|
9
|
+
const resolution = {
|
|
10
|
+
options: { origin: originInput, apiKey: options.apiKey },
|
|
11
|
+
env: dependencies.env,
|
|
12
|
+
credentials: dependencies.credentials,
|
|
13
|
+
};
|
|
14
|
+
const origin = resolveHubOrigin(resolution);
|
|
15
|
+
reportHubProgress(dependencies.reporter, options, `Connecting this daemon to ${origin}`);
|
|
16
|
+
const credential = resolveHubCredential({ ...resolution, origin });
|
|
17
|
+
const token = await dependencies.hub.issueEnrollmentToken(origin, credential);
|
|
18
|
+
const permissions = options.permissions ?? options.permission ?? [];
|
|
19
|
+
return withHubDaemon(dependencies.daemon, options.daemonTarget, async (daemon) => {
|
|
20
|
+
const response = await daemon.connectHub(origin, token, permissions);
|
|
21
|
+
if (response.status.hubOrigin !== null &&
|
|
22
|
+
!samePermissions(response.status.permissions, permissions)) {
|
|
23
|
+
await daemon.disconnectHub(false).catch(() => undefined);
|
|
24
|
+
throw new Error("The daemon did not honor the requested Hub access. Update Mateo before connecting it.");
|
|
25
|
+
}
|
|
26
|
+
return hubStatusResult(response.status);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function addHubConnectCommand(parent, dependencies) {
|
|
30
|
+
addJsonAndDaemonHostOptions(addHubResolutionHelp(parent
|
|
31
|
+
.command("connect")
|
|
32
|
+
.description("Enroll this daemon with a Mateo Hub")
|
|
33
|
+
.argument("[origin]", "Mateo Hub origin")
|
|
34
|
+
.option("--api-key <secret>", "Organization API key")
|
|
35
|
+
.option("--permission <permission...>", "Grant daemon permission during connection"))).action(withOutput(async (...args) => {
|
|
36
|
+
const origin = args[0];
|
|
37
|
+
const options = args.at(-2);
|
|
38
|
+
return runHubConnect(origin, options, dependencies);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
function samePermissions(actual, expected) {
|
|
42
|
+
return actual.length === expected.length && expected.every((scope) => actual.includes(scope));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface StoredHubCredential {
|
|
2
|
+
origin: string;
|
|
3
|
+
credential: string;
|
|
4
|
+
}
|
|
5
|
+
export interface HubCredentialStore {
|
|
6
|
+
active(): StoredHubCredential | null;
|
|
7
|
+
get(origin: string): StoredHubCredential | null;
|
|
8
|
+
save(credential: StoredHubCredential): void;
|
|
9
|
+
logoutActive(): StoredHubCredential | null;
|
|
10
|
+
}
|
|
11
|
+
export declare class PrivateHubCredentialStore implements HubCredentialStore {
|
|
12
|
+
private readonly filePath;
|
|
13
|
+
constructor(env?: Readonly<Record<string, string | undefined>>);
|
|
14
|
+
active(): StoredHubCredential | null;
|
|
15
|
+
get(origin: string): StoredHubCredential | null;
|
|
16
|
+
save(credential: StoredHubCredential): void;
|
|
17
|
+
logoutActive(): StoredHubCredential | null;
|
|
18
|
+
private read;
|
|
19
|
+
private write;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { HubCommandError } from "./error.js";
|
|
7
|
+
import { normalizeHubOrigin } from "./origin.js";
|
|
8
|
+
const PRIVATE_DIRECTORY_MODE = 0o700;
|
|
9
|
+
const PRIVATE_FILE_MODE = 0o600;
|
|
10
|
+
const credentialRecordSchema = z
|
|
11
|
+
.object({ origin: z.string(), credential: z.string().min(1) })
|
|
12
|
+
.strict();
|
|
13
|
+
const credentialFileSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
version: z.literal(1),
|
|
16
|
+
activeOrigin: z.string().nullable(),
|
|
17
|
+
credentials: z.array(credentialRecordSchema),
|
|
18
|
+
})
|
|
19
|
+
.strict()
|
|
20
|
+
.superRefine((value, context) => {
|
|
21
|
+
const origins = new Set();
|
|
22
|
+
for (const record of value.credentials) {
|
|
23
|
+
let normalized;
|
|
24
|
+
try {
|
|
25
|
+
normalized = normalizeHubOrigin(record.origin);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
context.addIssue({ code: "custom", message: "Credential origin is invalid" });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (normalized !== record.origin || origins.has(record.origin)) {
|
|
32
|
+
context.addIssue({
|
|
33
|
+
code: "custom",
|
|
34
|
+
message: "Credential origins must be unique and normalized",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
origins.add(record.origin);
|
|
38
|
+
}
|
|
39
|
+
if (value.activeOrigin !== null && !origins.has(value.activeOrigin)) {
|
|
40
|
+
context.addIssue({ code: "custom", message: "Active credential is missing" });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export class PrivateHubCredentialStore {
|
|
44
|
+
constructor(env = process.env) {
|
|
45
|
+
this.filePath = path.join(resolveMateoHome(env), "hub-credentials.json");
|
|
46
|
+
}
|
|
47
|
+
active() {
|
|
48
|
+
const data = this.read();
|
|
49
|
+
if (data.activeOrigin === null)
|
|
50
|
+
return null;
|
|
51
|
+
return data.credentials.find((record) => record.origin === data.activeOrigin) ?? null;
|
|
52
|
+
}
|
|
53
|
+
get(origin) {
|
|
54
|
+
const normalizedOrigin = normalizeHubOrigin(origin);
|
|
55
|
+
return this.read().credentials.find((record) => record.origin === normalizedOrigin) ?? null;
|
|
56
|
+
}
|
|
57
|
+
save(credential) {
|
|
58
|
+
const origin = normalizeHubOrigin(credential.origin);
|
|
59
|
+
const current = this.read();
|
|
60
|
+
const remaining = current.credentials.filter((record) => record.origin !== origin);
|
|
61
|
+
this.write({
|
|
62
|
+
version: 1,
|
|
63
|
+
activeOrigin: origin,
|
|
64
|
+
credentials: [...remaining, { origin, credential: credential.credential }],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
logoutActive() {
|
|
68
|
+
const current = this.read();
|
|
69
|
+
if (current.activeOrigin === null)
|
|
70
|
+
return null;
|
|
71
|
+
const removed = current.credentials.find((record) => record.origin === current.activeOrigin);
|
|
72
|
+
if (removed === undefined)
|
|
73
|
+
throw invalidCredentialFile();
|
|
74
|
+
this.write({
|
|
75
|
+
version: 1,
|
|
76
|
+
activeOrigin: null,
|
|
77
|
+
credentials: current.credentials.filter((record) => record.origin !== current.activeOrigin),
|
|
78
|
+
});
|
|
79
|
+
return removed;
|
|
80
|
+
}
|
|
81
|
+
read() {
|
|
82
|
+
let contents;
|
|
83
|
+
try {
|
|
84
|
+
contents = readFileSync(this.filePath, "utf8");
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (isMissingFile(error))
|
|
88
|
+
return { version: 1, activeOrigin: null, credentials: [] };
|
|
89
|
+
throw credentialStorageError();
|
|
90
|
+
}
|
|
91
|
+
chmodPrivate(this.filePath, PRIVATE_FILE_MODE);
|
|
92
|
+
try {
|
|
93
|
+
return credentialFileSchema.parse(JSON.parse(contents));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw invalidCredentialFile();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
write(value) {
|
|
100
|
+
const parsed = credentialFileSchema.parse(value);
|
|
101
|
+
const directory = path.dirname(this.filePath);
|
|
102
|
+
mkdirSync(directory, { recursive: true, mode: PRIVATE_DIRECTORY_MODE });
|
|
103
|
+
chmodPrivate(directory, PRIVATE_DIRECTORY_MODE);
|
|
104
|
+
const temporaryPath = path.join(directory, `.${path.basename(this.filePath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
105
|
+
try {
|
|
106
|
+
writeFileSync(temporaryPath, `${JSON.stringify(parsed, null, 2)}\n`, {
|
|
107
|
+
encoding: "utf8",
|
|
108
|
+
mode: PRIVATE_FILE_MODE,
|
|
109
|
+
});
|
|
110
|
+
renameSync(temporaryPath, this.filePath);
|
|
111
|
+
chmodPrivate(this.filePath, PRIVATE_FILE_MODE);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
rmSync(temporaryPath, { force: true });
|
|
115
|
+
throw credentialStorageError();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function resolveMateoHome(env) {
|
|
120
|
+
const configured = env.MATEO_HOME ?? "~/.mateo";
|
|
121
|
+
const expanded = configured === "~" ? homedir() : configured.replace(/^~\//u, `${homedir()}/`);
|
|
122
|
+
return path.resolve(expanded);
|
|
123
|
+
}
|
|
124
|
+
function chmodPrivate(target, mode) {
|
|
125
|
+
if (process.platform === "win32")
|
|
126
|
+
return;
|
|
127
|
+
try {
|
|
128
|
+
chmodSync(target, mode);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
throw credentialStorageError();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function isMissingFile(error) {
|
|
135
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
136
|
+
}
|
|
137
|
+
function invalidCredentialFile() {
|
|
138
|
+
return new HubCommandError("HUB_CREDENTIALS_INVALID", "Stored Hub login is invalid. Run `mateo hub login <origin>` to replace it.");
|
|
139
|
+
}
|
|
140
|
+
function credentialStorageError() {
|
|
141
|
+
return new HubCommandError("HUB_CREDENTIALS_UNAVAILABLE", "Could not access the private Hub credential store under MATEO_HOME.");
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=credentials.js.map
|