@cydm/happy-elves 0.1.0-beta.5 → 0.1.0-beta.51
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/README.md +2 -0
- package/apps/cli/dist/commands/account.d.ts +2 -0
- package/apps/cli/dist/commands/account.js +51 -0
- package/apps/cli/dist/commands/app.d.ts +3 -0
- package/apps/cli/dist/commands/app.js +103 -0
- package/apps/cli/dist/commands/collect.d.ts +2 -0
- package/apps/cli/dist/commands/collect.js +30 -0
- package/apps/cli/dist/commands/command.d.ts +6 -0
- package/apps/cli/dist/commands/command.js +1 -0
- package/apps/cli/dist/commands/config.d.ts +2 -0
- package/apps/cli/dist/commands/config.js +30 -0
- package/apps/cli/dist/commands/daemon.d.ts +2 -0
- package/apps/cli/dist/commands/daemon.js +218 -0
- package/apps/cli/dist/commands/lib/args.d.ts +4 -0
- package/apps/cli/dist/commands/lib/args.js +88 -0
- package/apps/cli/dist/commands/lib/audit.d.ts +1 -0
- package/apps/cli/dist/commands/lib/audit.js +25 -0
- package/apps/cli/dist/commands/lib/bootstrap-config.d.ts +28 -0
- package/apps/cli/dist/commands/lib/bootstrap-config.js +149 -0
- package/apps/cli/dist/commands/lib/bootstrap-daemon.d.ts +15 -0
- package/apps/cli/dist/commands/lib/bootstrap-daemon.js +45 -0
- package/apps/cli/dist/commands/lib/bootstrap-output.d.ts +18 -0
- package/apps/cli/dist/commands/lib/bootstrap-output.js +39 -0
- package/apps/cli/dist/commands/lib/bootstrap.d.ts +1 -0
- package/apps/cli/dist/commands/lib/bootstrap.js +95 -0
- package/apps/cli/dist/commands/lib/config.d.ts +19 -0
- package/apps/cli/dist/commands/lib/config.js +161 -0
- package/apps/cli/dist/commands/lib/doctor.d.ts +1 -0
- package/apps/cli/dist/commands/lib/doctor.js +48 -0
- package/apps/cli/dist/commands/lib/exit.d.ts +1 -0
- package/apps/cli/dist/commands/lib/exit.js +132 -0
- package/apps/cli/dist/commands/lib/index.d.ts +25 -0
- package/apps/cli/dist/commands/lib/index.js +25 -0
- package/apps/cli/dist/commands/lib/json.d.ts +5 -0
- package/apps/cli/dist/commands/lib/json.js +16 -0
- package/apps/cli/dist/commands/lib/local-daemon.d.ts +13 -0
- package/apps/cli/dist/commands/lib/local-daemon.js +132 -0
- package/apps/cli/dist/commands/lib/loop-store.d.ts +5 -0
- package/apps/cli/dist/commands/lib/loop-store.js +77 -0
- package/apps/cli/dist/commands/lib/orchestrator.d.ts +30 -0
- package/apps/cli/dist/commands/lib/orchestrator.js +146 -0
- package/apps/cli/dist/commands/lib/paths.d.ts +9 -0
- package/apps/cli/dist/commands/lib/paths.js +13 -0
- package/apps/cli/dist/commands/lib/relay-http.d.ts +18 -0
- package/apps/cli/dist/commands/lib/relay-http.js +112 -0
- package/apps/cli/dist/commands/lib/scope.d.ts +16 -0
- package/apps/cli/dist/commands/lib/scope.js +103 -0
- package/apps/cli/dist/commands/lib/session-output.d.ts +62 -0
- package/apps/cli/dist/commands/lib/session-output.js +413 -0
- package/apps/cli/dist/commands/lib/session-view.d.ts +80 -0
- package/apps/cli/dist/commands/lib/session-view.js +196 -0
- package/apps/cli/dist/commands/lib/status.d.ts +1 -0
- package/apps/cli/dist/commands/lib/status.js +62 -0
- package/apps/cli/dist/commands/lib/types.d.ts +86 -0
- package/apps/cli/dist/commands/lib/types.js +1 -0
- package/apps/cli/dist/commands/lib/usage.d.ts +5 -0
- package/apps/cli/dist/commands/lib/usage.js +284 -0
- package/apps/cli/dist/commands/lib/workspace.d.ts +25 -0
- package/apps/cli/dist/commands/lib/workspace.js +70 -0
- package/apps/cli/dist/commands/loop.d.ts +2 -0
- package/apps/cli/dist/commands/loop.js +212 -0
- package/apps/cli/dist/commands/machine.d.ts +2 -0
- package/apps/cli/dist/commands/machine.js +260 -0
- package/apps/cli/dist/commands/orchestrator.d.ts +2 -0
- package/apps/cli/dist/commands/orchestrator.js +411 -0
- package/apps/cli/dist/commands/relay.d.ts +2 -0
- package/apps/cli/dist/commands/relay.js +79 -0
- package/apps/cli/dist/commands/remote.d.ts +2 -0
- package/apps/cli/dist/commands/remote.js +142 -0
- package/apps/cli/dist/commands/session.d.ts +2 -0
- package/apps/cli/dist/commands/session.js +749 -0
- package/apps/cli/dist/commands/skill.d.ts +2 -0
- package/apps/cli/dist/commands/skill.js +214 -0
- package/apps/cli/dist/commands/token.d.ts +2 -0
- package/apps/cli/dist/commands/token.js +50 -0
- package/apps/cli/dist/commands/turn.d.ts +2 -0
- package/apps/cli/dist/commands/turn.js +249 -0
- package/apps/cli/dist/errors.d.ts +4 -0
- package/apps/cli/dist/errors.js +8 -0
- package/apps/cli/dist/index.js +2 -2374
- package/apps/daemon/dist/app.d.ts +2 -0
- package/apps/daemon/dist/app.js +117 -0
- package/apps/daemon/dist/args.d.ts +2 -0
- package/apps/daemon/dist/args.js +14 -0
- package/apps/daemon/dist/audit.d.ts +9 -0
- package/apps/daemon/dist/audit.js +50 -0
- package/apps/daemon/dist/cli.js +2 -1833
- package/apps/daemon/dist/config.d.ts +8 -0
- package/apps/daemon/dist/config.js +90 -0
- package/apps/daemon/dist/errors.d.ts +6 -0
- package/apps/daemon/dist/errors.js +21 -0
- package/apps/daemon/dist/loop/runner.d.ts +2 -0
- package/apps/daemon/dist/loop/runner.js +284 -0
- package/apps/daemon/dist/loop/store.d.ts +3 -0
- package/apps/daemon/dist/loop/store.js +63 -0
- package/apps/daemon/dist/pair.d.ts +1 -0
- package/apps/daemon/dist/pair.js +45 -0
- package/apps/daemon/dist/paths.d.ts +11 -0
- package/apps/daemon/dist/paths.js +16 -0
- package/apps/daemon/dist/process.d.ts +14 -0
- package/apps/daemon/dist/process.js +99 -0
- package/apps/daemon/dist/relay/connection.d.ts +2 -0
- package/apps/daemon/dist/relay/connection.js +146 -0
- package/apps/daemon/dist/relay/devtools.d.ts +4 -0
- package/apps/daemon/dist/relay/devtools.js +359 -0
- package/apps/daemon/dist/relay/register.d.ts +2 -0
- package/apps/daemon/dist/relay/register.js +60 -0
- package/apps/daemon/dist/relay/send.d.ts +16 -0
- package/apps/daemon/dist/relay/send.js +216 -0
- package/apps/daemon/dist/relay-http.d.ts +8 -0
- package/apps/daemon/dist/relay-http.js +70 -0
- package/apps/daemon/dist/runtime/external-provider.d.ts +20 -0
- package/apps/daemon/dist/runtime/external-provider.js +937 -0
- package/apps/daemon/dist/runtime.d.ts +12 -0
- package/apps/daemon/dist/runtime.js +78 -0
- package/apps/daemon/dist/session/create-session.d.ts +23 -0
- package/apps/daemon/dist/session/create-session.js +28 -0
- package/apps/daemon/dist/session/directory.d.ts +8 -0
- package/apps/daemon/dist/session/directory.js +162 -0
- package/apps/daemon/dist/session/events.d.ts +33 -0
- package/apps/daemon/dist/session/events.js +184 -0
- package/apps/daemon/dist/session/file-preview.d.ts +4 -0
- package/apps/daemon/dist/session/file-preview.js +169 -0
- package/apps/daemon/dist/session/lifecycle.d.ts +30 -0
- package/apps/daemon/dist/session/lifecycle.js +880 -0
- package/apps/daemon/dist/session/metadata.d.ts +7 -0
- package/apps/daemon/dist/session/metadata.js +117 -0
- package/apps/daemon/dist/session/primitives.d.ts +5 -0
- package/apps/daemon/dist/session/primitives.js +416 -0
- package/apps/daemon/dist/session/prompt.d.ts +4 -0
- package/apps/daemon/dist/session/prompt.js +316 -0
- package/apps/daemon/dist/session/runtime-handle.d.ts +7 -0
- package/apps/daemon/dist/session/runtime-handle.js +47 -0
- package/apps/daemon/dist/session/workspace-paths.d.ts +3 -0
- package/apps/daemon/dist/session/workspace-paths.js +30 -0
- package/apps/daemon/dist/start.d.ts +1 -0
- package/apps/daemon/dist/start.js +71 -0
- package/apps/daemon/dist/state.d.ts +21 -0
- package/apps/daemon/dist/state.js +10 -0
- package/apps/daemon/dist/turn-coordinator.d.ts +1 -0
- package/apps/daemon/dist/turn-coordinator.js +3 -1
- package/apps/daemon/dist/types.d.ts +143 -0
- package/apps/daemon/dist/types.js +1 -0
- package/apps/daemon/dist/utils.d.ts +1 -0
- package/apps/daemon/dist/utils.js +3 -0
- package/apps/daemon/package.json +3 -23
- package/apps/relay/dist/auth.js +13 -3
- package/apps/relay/dist/connections.d.ts +25 -5
- package/apps/relay/dist/connections.js +0 -1
- package/apps/relay/dist/controller-handlers.d.ts +20 -6
- package/apps/relay/dist/controller-handlers.js +665 -35
- package/apps/relay/dist/db.js +257 -5
- package/apps/relay/dist/errors.d.ts +5 -0
- package/apps/relay/dist/errors.js +9 -0
- package/apps/relay/dist/event-visibility.d.ts +7 -0
- package/apps/relay/dist/event-visibility.js +46 -0
- package/apps/relay/dist/http-routes.d.ts +3 -0
- package/apps/relay/dist/http-routes.js +584 -0
- package/apps/relay/dist/http-schemas.d.ts +42 -1
- package/apps/relay/dist/http-schemas.js +29 -3
- package/apps/relay/dist/index.js +43 -817
- package/apps/relay/dist/machine-command-result-handlers.d.ts +4 -0
- package/apps/relay/dist/machine-command-result-handlers.js +532 -0
- package/apps/relay/dist/machine-handler-context.d.ts +79 -0
- package/apps/relay/dist/machine-handler-context.js +1 -0
- package/apps/relay/dist/machine-handlers.d.ts +3 -29
- package/apps/relay/dist/machine-handlers.js +13 -168
- package/apps/relay/dist/machine-reliability.d.ts +7 -0
- package/apps/relay/dist/machine-reliability.js +12 -0
- package/apps/relay/dist/projection-repository.d.ts +87 -0
- package/apps/relay/dist/projection-repository.js +220 -0
- package/apps/relay/dist/projections.d.ts +3 -2
- package/apps/relay/dist/projections.js +110 -4
- package/apps/relay/dist/relay-context.d.ts +159 -0
- package/apps/relay/dist/relay-context.js +830 -0
- package/apps/relay/dist/repositories.d.ts +2 -2
- package/apps/relay/dist/repositories.js +20 -9
- package/apps/relay/dist/retention.d.ts +9 -0
- package/apps/relay/dist/retention.js +25 -0
- package/apps/relay/dist/scope.d.ts +33 -0
- package/apps/relay/dist/scope.js +187 -0
- package/apps/relay/dist/security.js +0 -1
- package/apps/relay/dist/session-projection-reducer.d.ts +4 -0
- package/apps/relay/dist/session-projection-reducer.js +448 -0
- package/apps/relay/dist/types.d.ts +31 -1
- package/apps/relay/dist/types.js +0 -1
- package/apps/relay/dist/websocket.d.ts +3 -0
- package/apps/relay/dist/websocket.js +178 -0
- package/npm-shrinkwrap.json +1615 -0
- package/package.json +27 -14
- package/packages/agent-sdk/dist/index.d.ts +130 -0
- package/packages/agent-sdk/dist/index.js +198 -0
- package/packages/client/dist/account.d.ts +23 -0
- package/packages/client/dist/account.js +77 -0
- package/packages/client/dist/client.d.ts +69 -0
- package/packages/client/dist/client.js +581 -0
- package/packages/client/dist/errors.d.ts +19 -0
- package/packages/client/dist/errors.js +27 -0
- package/packages/client/dist/http.d.ts +10 -0
- package/packages/client/dist/http.js +93 -0
- package/packages/client/dist/index.d.ts +6 -248
- package/packages/client/dist/index.js +4 -1014
- package/packages/client/dist/live-session-state.d.ts +15 -0
- package/packages/client/dist/live-session-state.js +60 -0
- package/packages/client/dist/live-state.d.ts +8 -0
- package/packages/client/dist/live-state.js +33 -0
- package/packages/client/dist/live-types.d.ts +115 -0
- package/packages/client/dist/live-types.js +1 -0
- package/packages/client/dist/live.d.ts +85 -0
- package/packages/client/dist/live.js +1058 -0
- package/packages/client/dist/parsers.d.ts +25 -0
- package/packages/client/dist/parsers.js +199 -0
- package/packages/client/dist/session-event-order.d.ts +16 -0
- package/packages/client/dist/session-event-order.js +83 -0
- package/packages/client/dist/session-event-window.d.ts +5 -0
- package/packages/client/dist/session-event-window.js +54 -0
- package/packages/client/dist/transport.d.ts +39 -0
- package/packages/client/dist/transport.js +325 -0
- package/packages/client/dist/types.d.ts +295 -0
- package/packages/client/dist/types.js +1 -0
- package/packages/client/dist/validation.d.ts +15 -0
- package/packages/client/dist/validation.js +97 -0
- package/packages/pie-provider/dist/index.d.ts +2 -0
- package/packages/pie-provider/dist/index.js +1098 -0
- package/packages/provider-protocol/dist/index.d.ts +910 -0
- package/packages/provider-protocol/dist/index.js +348 -0
- package/packages/runtime/dist/index.d.ts +58 -97
- package/packages/runtime/dist/index.js +0 -1
- package/packages/runtime-acpx/dist/index.d.ts +2 -2
- package/packages/runtime-acpx/dist/index.js +71 -2
- package/packages/runtime-cli/dist/async-queue.d.ts +0 -1
- package/packages/runtime-cli/dist/async-queue.js +0 -1
- package/packages/runtime-cli/dist/claude-history.d.ts +6 -0
- package/packages/runtime-cli/dist/claude-history.js +343 -0
- package/packages/runtime-cli/dist/claude-json.d.ts +28 -0
- package/packages/runtime-cli/dist/claude-json.js +28 -0
- package/packages/runtime-cli/dist/claude-rename.d.ts +5 -0
- package/packages/runtime-cli/dist/claude-rename.js +14 -0
- package/packages/runtime-cli/dist/claude-session-store.d.ts +3 -2
- package/packages/runtime-cli/dist/claude-session-store.js +51 -15
- package/packages/runtime-cli/dist/claude-turn.d.ts +14 -0
- package/packages/runtime-cli/dist/claude-turn.js +149 -0
- package/packages/runtime-cli/dist/codex-app-server.d.ts +43 -19
- package/packages/runtime-cli/dist/codex-app-server.js +423 -444
- package/packages/runtime-cli/dist/codex-approvals.d.ts +7 -0
- package/packages/runtime-cli/dist/codex-approvals.js +32 -0
- package/packages/runtime-cli/dist/codex-history.d.ts +16 -0
- package/packages/runtime-cli/dist/codex-history.js +748 -0
- package/packages/runtime-cli/dist/codex-json-rpc.d.ts +29 -0
- package/packages/runtime-cli/dist/codex-json-rpc.js +198 -0
- package/packages/runtime-cli/dist/codex-lifecycle.d.ts +24 -0
- package/packages/runtime-cli/dist/codex-lifecycle.js +71 -0
- package/packages/runtime-cli/dist/codex-protocol.d.ts +7 -0
- package/packages/runtime-cli/dist/codex-protocol.js +71 -0
- package/packages/runtime-cli/dist/command-resolver.d.ts +23 -0
- package/packages/runtime-cli/dist/command-resolver.js +100 -0
- package/packages/runtime-cli/dist/history-merge.d.ts +17 -0
- package/packages/runtime-cli/dist/history-merge.js +286 -0
- package/packages/runtime-cli/dist/index.d.ts +3 -2
- package/packages/runtime-cli/dist/index.js +190 -365
- package/packages/runtime-cli/dist/permissions.d.ts +5 -0
- package/packages/runtime-cli/dist/permissions.js +21 -0
- package/packages/runtime-cli/dist/session-store.d.ts +35 -0
- package/packages/runtime-cli/dist/session-store.js +100 -0
- package/packages/shared/dist/args.d.ts +9 -0
- package/packages/shared/dist/args.js +34 -0
- package/packages/shared/dist/crypto.d.ts +0 -1
- package/packages/shared/dist/crypto.js +0 -1
- package/packages/shared/dist/ids.d.ts +0 -1
- package/packages/shared/dist/ids.js +0 -1
- package/packages/shared/dist/index.d.ts +3 -1
- package/packages/shared/dist/index.js +3 -1
- package/packages/shared/dist/protocol-schemas.d.ts +413 -0
- package/packages/shared/dist/protocol-schemas.js +197 -0
- package/packages/shared/dist/protocol-types.d.ts +251 -0
- package/packages/shared/dist/protocol-types.js +1 -0
- package/packages/shared/dist/protocol.d.ts +195 -145
- package/packages/shared/dist/protocol.js +224 -86
- package/packages/shared/dist/session-name.d.ts +3 -0
- package/packages/shared/dist/session-name.js +25 -0
- package/packages/shared/dist/session-state.d.ts +15 -0
- package/packages/shared/dist/session-state.js +47 -0
- package/apps/cli/dist/index.js.map +0 -1
- package/apps/daemon/dist/cli.js.map +0 -1
- package/apps/daemon/dist/turn-coordinator.js.map +0 -1
- package/apps/relay/dist/auth.js.map +0 -1
- package/apps/relay/dist/connections.js.map +0 -1
- package/apps/relay/dist/controller-handlers.js.map +0 -1
- package/apps/relay/dist/db.js.map +0 -1
- package/apps/relay/dist/http-schemas.js.map +0 -1
- package/apps/relay/dist/index.js.map +0 -1
- package/apps/relay/dist/machine-handlers.js.map +0 -1
- package/apps/relay/dist/projections.js.map +0 -1
- package/apps/relay/dist/repositories.js.map +0 -1
- package/apps/relay/dist/security.js.map +0 -1
- package/apps/relay/dist/types.js.map +0 -1
- package/apps/relay/package.json +0 -29
- package/packages/client/dist/index.d.ts.map +0 -1
- package/packages/client/dist/index.js.map +0 -1
- package/packages/client/package.json +0 -22
- package/packages/runtime/dist/index.d.ts.map +0 -1
- package/packages/runtime/dist/index.js.map +0 -1
- package/packages/runtime/package.json +0 -19
- package/packages/runtime-acpx/dist/index.d.ts.map +0 -1
- package/packages/runtime-acpx/dist/index.js.map +0 -1
- package/packages/runtime-acpx/package.json +0 -23
- package/packages/runtime-cli/dist/async-queue.d.ts.map +0 -1
- package/packages/runtime-cli/dist/async-queue.js.map +0 -1
- package/packages/runtime-cli/dist/claude-session-store.d.ts.map +0 -1
- package/packages/runtime-cli/dist/claude-session-store.js.map +0 -1
- package/packages/runtime-cli/dist/codex-app-server.d.ts.map +0 -1
- package/packages/runtime-cli/dist/codex-app-server.js.map +0 -1
- package/packages/runtime-cli/dist/index.d.ts.map +0 -1
- package/packages/runtime-cli/dist/index.js.map +0 -1
- package/packages/runtime-cli/package.json +0 -22
- package/packages/shared/dist/crypto.d.ts.map +0 -1
- package/packages/shared/dist/crypto.js.map +0 -1
- package/packages/shared/dist/ids.d.ts.map +0 -1
- package/packages/shared/dist/ids.js.map +0 -1
- package/packages/shared/dist/index.d.ts.map +0 -1
- package/packages/shared/dist/index.js.map +0 -1
- package/packages/shared/dist/protocol.d.ts.map +0 -1
- package/packages/shared/dist/protocol.js.map +0 -1
- package/packages/shared/package.json +0 -24
package/README.md
CHANGED
|
@@ -11,5 +11,7 @@ happy-elves account create --relay https://relay.happyelves.ai --device-name "CL
|
|
|
11
11
|
## Self-host relay
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
+
HAPPY_ELVES_ENV=production \
|
|
15
|
+
HAPPY_ELVES_ALLOWED_ORIGINS=https://your-controller.example \
|
|
14
16
|
happy-elves relay serve --host 0.0.0.0 --port 8787 --json
|
|
15
17
|
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { configDir, configPath, generateAccountSecret, ok, parsePairingStartResponse, randomId, readRelayJson, requireRelayUrl, stopLocalDaemon, throwRelayHttpError, writeConfig } from "./lib/index.js";
|
|
5
|
+
export async function handleAccount({ domain, action, flags }) {
|
|
6
|
+
if (domain === "account" && action === "create") {
|
|
7
|
+
const relayUrl = requireRelayUrl(flags);
|
|
8
|
+
const deviceId = typeof flags["device-id"] === "string" ? flags["device-id"] : randomId("dev");
|
|
9
|
+
const deviceName = typeof flags["device-name"] === "string" ? flags["device-name"] : os.hostname();
|
|
10
|
+
const accountSecret = generateAccountSecret();
|
|
11
|
+
const response = await fetch(`${relayUrl}/api/pairing/start`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: { "content-type": "application/json" },
|
|
14
|
+
body: JSON.stringify({ deviceId, deviceName }),
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
await throwRelayHttpError(response, "Account creation failed");
|
|
18
|
+
}
|
|
19
|
+
const paired = parsePairingStartResponse(await readRelayJson(response, "Account creation response is not valid JSON"));
|
|
20
|
+
const config = {
|
|
21
|
+
relayUrl,
|
|
22
|
+
controllerToken: paired.controllerToken,
|
|
23
|
+
accountSecret,
|
|
24
|
+
};
|
|
25
|
+
await writeConfig(config);
|
|
26
|
+
ok("account.create", {
|
|
27
|
+
accountId: paired.accountId,
|
|
28
|
+
configPath,
|
|
29
|
+
relayUrl,
|
|
30
|
+
deviceId,
|
|
31
|
+
controllerToken: paired.controllerToken,
|
|
32
|
+
accountSecret,
|
|
33
|
+
pairingCode: paired.pairingCode,
|
|
34
|
+
expiresAt: paired.expiresAt,
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (domain === "account" && action === "reset") {
|
|
39
|
+
const stop = await stopLocalDaemon().catch((error) => ({
|
|
40
|
+
error: error instanceof Error ? error.message : String(error),
|
|
41
|
+
}));
|
|
42
|
+
await fs.rm(configPath, { force: true });
|
|
43
|
+
await fs.rm(path.join(configDir, "daemon.json"), { force: true });
|
|
44
|
+
ok("account.reset", {
|
|
45
|
+
removed: [configPath, path.join(configDir, "daemon.json")],
|
|
46
|
+
stop,
|
|
47
|
+
});
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { handleAccount } from "./account.js";
|
|
4
|
+
import { handleCollect } from "./collect.js";
|
|
5
|
+
import { handleConfig } from "./config.js";
|
|
6
|
+
import { handleDaemon } from "./daemon.js";
|
|
7
|
+
import { handleLoop } from "./loop.js";
|
|
8
|
+
import { handleMachine } from "./machine.js";
|
|
9
|
+
import { handleOrchestrator } from "./orchestrator.js";
|
|
10
|
+
import { handleRelay } from "./relay.js";
|
|
11
|
+
import { handleRemote } from "./remote.js";
|
|
12
|
+
import { handleSession } from "./session.js";
|
|
13
|
+
import { handleSkill } from "./skill.js";
|
|
14
|
+
import { handleToken } from "./token.js";
|
|
15
|
+
import { handleTurn } from "./turn.js";
|
|
16
|
+
import { commandUsage, commandUsageText, handleCliError, parseCliFlags, skillText, startBootstrap, topLevelDoctor, topLevelStatus, usage, usageText } from "./lib/index.js";
|
|
17
|
+
export { handleCliError };
|
|
18
|
+
const domainHandlers = [
|
|
19
|
+
handleAccount,
|
|
20
|
+
handleConfig,
|
|
21
|
+
handleRemote,
|
|
22
|
+
handleToken,
|
|
23
|
+
handleLoop,
|
|
24
|
+
handleDaemon,
|
|
25
|
+
handleRelay,
|
|
26
|
+
handleMachine,
|
|
27
|
+
handleOrchestrator,
|
|
28
|
+
handleSession,
|
|
29
|
+
handleSkill,
|
|
30
|
+
handleTurn,
|
|
31
|
+
handleCollect,
|
|
32
|
+
];
|
|
33
|
+
export async function main() {
|
|
34
|
+
const argv = process.argv.slice(2);
|
|
35
|
+
const [domain] = argv;
|
|
36
|
+
if (!domain)
|
|
37
|
+
usage();
|
|
38
|
+
if (domain === "--skill") {
|
|
39
|
+
console.log(skillText());
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (domain === "--help" || domain === "-h" || domain === "help") {
|
|
43
|
+
console.log(usageText());
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (domain === "--version" || domain === "-v" || domain === "version") {
|
|
47
|
+
console.log(cliVersion());
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const topLevelHelpRequested = argv[1] === "help" || argv.slice(1).some((arg) => arg === "--help" || arg === "-h");
|
|
51
|
+
if (topLevelHelpRequested && commandUsageText(domain)) {
|
|
52
|
+
console.log(commandUsageText(domain));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (domain === "start") {
|
|
56
|
+
const { flags } = parseCliFlags(argv.slice(1));
|
|
57
|
+
await startBootstrap(flags);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (domain === "doctor") {
|
|
61
|
+
const { flags } = parseCliFlags(argv.slice(1));
|
|
62
|
+
await topLevelDoctor(flags);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (domain === "status") {
|
|
66
|
+
const { flags } = parseCliFlags(argv.slice(1));
|
|
67
|
+
await topLevelStatus(flags);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const action = argv[1];
|
|
71
|
+
const rest = argv.slice(2);
|
|
72
|
+
if ((!action || action.startsWith("-")) && commandUsageText(domain)) {
|
|
73
|
+
commandUsage(domain);
|
|
74
|
+
}
|
|
75
|
+
const { positional, flags } = parseCliFlags(rest);
|
|
76
|
+
if (action === "--help" || action === "-h" || action === "help" || flags.help === true || flags.h === true) {
|
|
77
|
+
console.log(commandUsageText(domain) ?? usageText());
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const input = { domain, action, positional, flags };
|
|
81
|
+
for (const handle of domainHandlers) {
|
|
82
|
+
if (await handle(input))
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
usage();
|
|
86
|
+
}
|
|
87
|
+
function cliVersion() {
|
|
88
|
+
for (const candidate of [
|
|
89
|
+
path.resolve(import.meta.dirname, "..", "..", "..", "..", "package.json"),
|
|
90
|
+
path.resolve(import.meta.dirname, "..", "..", "..", "package.json"),
|
|
91
|
+
path.resolve(import.meta.dirname, "..", "..", "package.json"),
|
|
92
|
+
]) {
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(fs.readFileSync(candidate, "utf8"));
|
|
95
|
+
if (typeof parsed.version === "string" && parsed.version.trim())
|
|
96
|
+
return parsed.version.trim();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Try the next packaged/source layout.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return "0.1.0";
|
|
103
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CliError, ControllerClient, conciseEvents, ok, parseEventCursor, printConciseEvents, readConfig, requirePositional, wantsJson, wantsVerbose } from "./lib/index.js";
|
|
2
|
+
export async function handleCollect({ domain, action, flags }) {
|
|
3
|
+
if (domain !== "collect")
|
|
4
|
+
return false;
|
|
5
|
+
const config = await readConfig(flags);
|
|
6
|
+
const client = new ControllerClient(config);
|
|
7
|
+
const sessionId = requirePositional(action, "sessionId");
|
|
8
|
+
const since = parseEventCursor(flags.since);
|
|
9
|
+
const limit = typeof flags.limit === "string" ? Number(flags.limit) : undefined;
|
|
10
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit <= 0)) {
|
|
11
|
+
throw new CliError(`Invalid --limit: ${flags.limit}`, "INVALID_ARGUMENT");
|
|
12
|
+
}
|
|
13
|
+
const events = await client.collect(sessionId, { since, limit });
|
|
14
|
+
const lastEventId = events.at(-1)?.id;
|
|
15
|
+
const nextSince = lastEventId === undefined ? (since ?? null) : `cursor_${lastEventId}`;
|
|
16
|
+
if (wantsJson(flags) || wantsVerbose(flags)) {
|
|
17
|
+
ok("session.collect", {
|
|
18
|
+
sessionId,
|
|
19
|
+
debugOnly: true,
|
|
20
|
+
cursor: nextSince,
|
|
21
|
+
nextSince,
|
|
22
|
+
...(wantsVerbose(flags) ? { events } : { events: conciseEvents(events) }),
|
|
23
|
+
}, { sessionId });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
printConciseEvents(events);
|
|
27
|
+
console.log(`nextSince: ${nextSince ?? "none"}`);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { configPath, ok, readConfig, redactedControllerConfig, redactedRelayUrl, requireRelayUrl, requireString, wantsJson, writeConfig } from "./lib/index.js";
|
|
2
|
+
export async function handleConfig({ domain, action, flags }) {
|
|
3
|
+
if (domain === "config" && action === "init") {
|
|
4
|
+
const config = {
|
|
5
|
+
relayUrl: requireRelayUrl(flags),
|
|
6
|
+
controllerToken: requireString(flags, "token"),
|
|
7
|
+
accountSecret: requireString(flags, "secret"),
|
|
8
|
+
};
|
|
9
|
+
await writeConfig(config);
|
|
10
|
+
ok("config.init", { path: configPath, relayUrl: redactedRelayUrl(config.relayUrl) });
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (domain === "config" && action === "show") {
|
|
14
|
+
const config = await readConfig(flags);
|
|
15
|
+
if (!wantsJson(flags)) {
|
|
16
|
+
const redacted = redactedControllerConfig(config);
|
|
17
|
+
console.log(`Config: ${configPath}`);
|
|
18
|
+
console.log(`Relay: ${redacted.relayUrl}`);
|
|
19
|
+
console.log(`Controller token: ${redacted.hasControllerToken ? "configured" : "missing"}`);
|
|
20
|
+
console.log(`Account secret: ${redacted.hasAccountSecret ? "configured" : "missing"}`);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
ok("config.show", {
|
|
24
|
+
path: configPath,
|
|
25
|
+
config: redactedControllerConfig(config),
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { CliError, compactText, ControllerClient, configDir, configPath, daemonPidPath, deriveOrchestration, idleSessionStatuses, localDaemonStatus, ok, parsePairingClaimResponse, randomId, readConfig, readDaemonConfig, readLocalAuditLog, readRelayJson, redactedDaemonConfig, requirePositional, requireRelayUrl, requireString, showMachine, spawnDaemonStart, stopLocalDaemon, throwRelayHttpError, wantsJson, writeDaemonConfig } from "./lib/index.js";
|
|
4
|
+
export async function handleDaemon({ domain, action, flags }) {
|
|
5
|
+
if (domain === "daemon" && action === "pair") {
|
|
6
|
+
const relayUrl = requireRelayUrl(flags);
|
|
7
|
+
const code = requireString(flags, "code");
|
|
8
|
+
const accountSecret = requireString(flags, "secret");
|
|
9
|
+
const machineName = typeof flags.name === "string" && flags.name.trim() ? flags.name.trim() : os.hostname();
|
|
10
|
+
const machineId = typeof flags["machine-id"] === "string" ? flags["machine-id"] : randomId("mach");
|
|
11
|
+
const response = await fetch(`${relayUrl}/api/pairing/claim`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: { "content-type": "application/json" },
|
|
14
|
+
body: JSON.stringify({ code, machineId }),
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
await throwRelayHttpError(response, "Pairing failed");
|
|
18
|
+
}
|
|
19
|
+
const claimed = parsePairingClaimResponse(await readRelayJson(response, "Pairing response is not valid JSON"));
|
|
20
|
+
const daemonConfig = {
|
|
21
|
+
relayUrl,
|
|
22
|
+
accountId: claimed.accountId,
|
|
23
|
+
machineId: claimed.machineId,
|
|
24
|
+
machineName,
|
|
25
|
+
machineToken: claimed.machineToken,
|
|
26
|
+
accountSecret,
|
|
27
|
+
};
|
|
28
|
+
const daemonConfigPath = await writeDaemonConfig(daemonConfig);
|
|
29
|
+
ok("daemon.pair", {
|
|
30
|
+
path: daemonConfigPath,
|
|
31
|
+
config: redactedDaemonConfig(daemonConfig),
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (domain === "daemon" && action === "doctor") {
|
|
36
|
+
const checks = [];
|
|
37
|
+
let config;
|
|
38
|
+
try {
|
|
39
|
+
config = await readConfig(flags);
|
|
40
|
+
checks.push({ name: "config", ok: true, message: configPath });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
checks.push({ name: "config", ok: false, message: error instanceof Error ? error.message : String(error) });
|
|
44
|
+
}
|
|
45
|
+
if (config) {
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(`${config.relayUrl}/health`);
|
|
48
|
+
checks.push({ name: "relay", ok: response.ok, message: response.ok ? "reachable" : await response.text() });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
checks.push({ name: "relay", ok: false, message: error instanceof Error ? error.message : String(error) });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const data = { ok: checks.every((check) => check.ok), checks };
|
|
55
|
+
if (!wantsJson(flags)) {
|
|
56
|
+
console.log(`Daemon doctor: ${data.ok ? "ok" : "issues found"}`);
|
|
57
|
+
for (const check of checks) {
|
|
58
|
+
console.log(`${check.ok ? "ok" : "fail"} ${check.name}: ${check.message}`);
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
ok("daemon.doctor", data);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (domain === "daemon" && action === "config") {
|
|
66
|
+
const daemonConfig = await readDaemonConfig();
|
|
67
|
+
const redacted = redactedDaemonConfig(daemonConfig);
|
|
68
|
+
if (!wantsJson(flags)) {
|
|
69
|
+
console.log(`Config: ${path.join(configDir, "daemon.json")}`);
|
|
70
|
+
console.log(`Relay: ${redacted.relayUrl}`);
|
|
71
|
+
console.log(`Account: ${redacted.accountId}`);
|
|
72
|
+
console.log(`Machine: ${redacted.machineName} (${redacted.machineId})`);
|
|
73
|
+
console.log(`Machine token: ${redacted.hasMachineToken ? "configured" : "missing"}`);
|
|
74
|
+
console.log(`Account secret: ${redacted.hasAccountSecret ? "configured" : "missing"}`);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
ok("daemon.config", {
|
|
78
|
+
path: path.join(configDir, "daemon.json"),
|
|
79
|
+
config: redacted,
|
|
80
|
+
});
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (domain === "daemon" && action === "logs") {
|
|
84
|
+
const tail = typeof flags.tail === "string" ? Number(flags.tail) : 100;
|
|
85
|
+
if (!Number.isInteger(tail) || tail <= 0) {
|
|
86
|
+
throw new CliError(`Invalid --tail: ${flags.tail}`, "INVALID_ARGUMENT");
|
|
87
|
+
}
|
|
88
|
+
const entries = await readLocalAuditLog(tail);
|
|
89
|
+
if (!wantsJson(flags)) {
|
|
90
|
+
if (entries.length === 0) {
|
|
91
|
+
console.log("No daemon audit log entries.");
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
const record = entry;
|
|
96
|
+
const createdAt = typeof record.createdAt === "string" ? record.createdAt : "-";
|
|
97
|
+
const action = typeof record.action === "string" ? record.action : "unknown";
|
|
98
|
+
const actor = typeof record.actor === "string" ? record.actor : "unknown";
|
|
99
|
+
const sessionId = typeof record.sessionId === "string" ? record.sessionId : undefined;
|
|
100
|
+
const summary = typeof record.summary === "string" ? record.summary : JSON.stringify(record);
|
|
101
|
+
console.log(`${createdAt} ${action} ${actor}`);
|
|
102
|
+
if (sessionId)
|
|
103
|
+
console.log(` session: ${sessionId}`);
|
|
104
|
+
console.log(` ${compactText(summary, 160)}`);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
ok("daemon.logs", {
|
|
109
|
+
path: path.join(configDir, "audit.jsonl"),
|
|
110
|
+
entries,
|
|
111
|
+
});
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
if (domain === "daemon" && action === "start") {
|
|
115
|
+
const status = await localDaemonStatus();
|
|
116
|
+
if (status.running) {
|
|
117
|
+
ok("daemon.start", { ...status, started: false });
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
await readDaemonConfig();
|
|
121
|
+
const startArgs = typeof flags.relay === "string" ? ["--relay", flags.relay] : [];
|
|
122
|
+
const pid = spawnDaemonStart(startArgs);
|
|
123
|
+
ok("daemon.start", { pid, pidPath: daemonPidPath, started: true });
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (domain === "daemon" && action === "stop") {
|
|
127
|
+
ok("daemon.stop", await stopLocalDaemon());
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (domain === "daemon" && action === "restart") {
|
|
131
|
+
await readDaemonConfig();
|
|
132
|
+
const stop = await stopLocalDaemon();
|
|
133
|
+
const startArgs = typeof flags.relay === "string" ? ["--relay", flags.relay] : [];
|
|
134
|
+
const pid = spawnDaemonStart(startArgs);
|
|
135
|
+
ok("daemon.restart", { stop, startedPid: pid, pidPath: daemonPidPath });
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (domain === "daemon" && action === "status" && flags.local === true) {
|
|
139
|
+
const local = await localDaemonStatus();
|
|
140
|
+
if (!wantsJson(flags)) {
|
|
141
|
+
console.log(local.running ? `Daemon: running${local.pid ? ` pid ${local.pid}` : ""}` : "Daemon: stopped");
|
|
142
|
+
console.log(`Pid file: ${local.pidPath}`);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
ok("daemon.status", { local });
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (domain === "daemon" && action === "status") {
|
|
149
|
+
const config = await readConfig(flags);
|
|
150
|
+
const client = new ControllerClient(config);
|
|
151
|
+
const local = await localDaemonStatus();
|
|
152
|
+
const response = await fetch(`${config.relayUrl}/health`);
|
|
153
|
+
const snapshot = await client.snapshot();
|
|
154
|
+
const machineFilter = flags.machine === true ? requirePositional(undefined, "machineId") : typeof flags.machine === "string" ? flags.machine : undefined;
|
|
155
|
+
const machines = machineFilter
|
|
156
|
+
? snapshot.machines.filter((machine) => machine.id === machineFilter)
|
|
157
|
+
: snapshot.machines;
|
|
158
|
+
if (machineFilter && machines.length === 0)
|
|
159
|
+
throw new CliError("Machine not found", "MACHINE_NOT_FOUND");
|
|
160
|
+
const machineIds = new Set(machines.map((machine) => machine.id));
|
|
161
|
+
const sessions = snapshot.sessions.filter((session) => machineIds.has(session.machineId));
|
|
162
|
+
const projectedMachines = await Promise.all(machines.map((machine) => showMachine(client, machine)));
|
|
163
|
+
const projectedSessions = await Promise.all(sessions.map(async (session) => ({
|
|
164
|
+
sessionId: session.id,
|
|
165
|
+
machineId: session.machineId,
|
|
166
|
+
agent: session.agent,
|
|
167
|
+
status: session.status,
|
|
168
|
+
orchestration: deriveOrchestration(session, await client.history(session.id, 20)),
|
|
169
|
+
updatedAt: session.updatedAt,
|
|
170
|
+
capabilities: session.capabilities,
|
|
171
|
+
})));
|
|
172
|
+
const data = {
|
|
173
|
+
configPath,
|
|
174
|
+
local,
|
|
175
|
+
relayUrl: config.relayUrl,
|
|
176
|
+
relayReachable: response.ok,
|
|
177
|
+
relay: response.ok ? await response.json() : await response.text(),
|
|
178
|
+
machines: projectedMachines.map((machine) => ({
|
|
179
|
+
machineId: machine.id,
|
|
180
|
+
name: machine.metadata.name ?? machine.name,
|
|
181
|
+
online: machine.online,
|
|
182
|
+
lastSeen: machine.lastSeen,
|
|
183
|
+
defaultCwd: machine.defaultCwd,
|
|
184
|
+
daemonVersion: machine.capabilities.daemonVersion,
|
|
185
|
+
acpxVersion: machine.capabilities.acpxVersion,
|
|
186
|
+
sessionPrimitives: machine.capabilities.sessionPrimitives,
|
|
187
|
+
agents: machine.capabilities.agents,
|
|
188
|
+
metadata: machine.metadata,
|
|
189
|
+
})),
|
|
190
|
+
sessions: projectedSessions,
|
|
191
|
+
summary: {
|
|
192
|
+
machineCount: machines.length,
|
|
193
|
+
onlineMachineCount: machines.filter((machine) => machine.online).length,
|
|
194
|
+
sessionCount: projectedSessions.length,
|
|
195
|
+
runningSessionCount: projectedSessions.filter((session) => session.status === "running").length,
|
|
196
|
+
idleSessionCount: projectedSessions.filter((session) => idleSessionStatuses.includes(session.status)).length,
|
|
197
|
+
blockedSessionCount: projectedSessions.filter((session) => session.orchestration.blocked).length,
|
|
198
|
+
activeSessionCount: projectedSessions.filter((session) => session.orchestration.state === "active").length,
|
|
199
|
+
completedSessionCount: projectedSessions.filter((session) => session.orchestration.completed).length,
|
|
200
|
+
needsUserSessionCount: projectedSessions.filter((session) => session.orchestration.needsUser).length,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
if (!wantsJson(flags)) {
|
|
204
|
+
console.log(`Relay: ${data.relayUrl} ${data.relayReachable ? "ok" : "unreachable"}`);
|
|
205
|
+
console.log(data.local.running ? `Local daemon: running${data.local.pid ? ` pid ${data.local.pid}` : ""}` : "Local daemon: stopped");
|
|
206
|
+
console.log(`Machines: ${data.summary.onlineMachineCount}/${data.summary.machineCount} online`);
|
|
207
|
+
console.log(`Sessions: ${data.summary.sessionCount} total, ${data.summary.runningSessionCount} running, ${data.summary.needsUserSessionCount} needs user`);
|
|
208
|
+
for (const machine of data.machines) {
|
|
209
|
+
console.log(`- ${machine.name} (${machine.machineId}) ${machine.online ? "online" : "offline"}`);
|
|
210
|
+
console.log(` cwd: ${machine.defaultCwd ?? "-"}`);
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
ok("daemon.status", data, machineFilter ? { machineId: machineFilter } : {});
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { parseFlags as parseSharedFlags } from "../../../../../packages/shared/dist/index.js";
|
|
2
|
+
import { CliError } from "../../errors.js";
|
|
3
|
+
const valueFlags = new Set([
|
|
4
|
+
"agent",
|
|
5
|
+
"code",
|
|
6
|
+
"controller",
|
|
7
|
+
"cwd",
|
|
8
|
+
"device-id",
|
|
9
|
+
"device-name",
|
|
10
|
+
"from",
|
|
11
|
+
"host",
|
|
12
|
+
"invite-secret",
|
|
13
|
+
"join-url-base",
|
|
14
|
+
"limit",
|
|
15
|
+
"machine",
|
|
16
|
+
"machine-id",
|
|
17
|
+
"name",
|
|
18
|
+
"mode",
|
|
19
|
+
"output",
|
|
20
|
+
"path",
|
|
21
|
+
"port",
|
|
22
|
+
"permission",
|
|
23
|
+
"permission-mode",
|
|
24
|
+
"prompt",
|
|
25
|
+
"prompt-file",
|
|
26
|
+
"query",
|
|
27
|
+
"request-id",
|
|
28
|
+
"every",
|
|
29
|
+
"reason",
|
|
30
|
+
"relay",
|
|
31
|
+
"root",
|
|
32
|
+
"runtime-limit",
|
|
33
|
+
"runtime-session",
|
|
34
|
+
"shell",
|
|
35
|
+
"actions",
|
|
36
|
+
"expires-in",
|
|
37
|
+
"format",
|
|
38
|
+
"loops",
|
|
39
|
+
"machines",
|
|
40
|
+
"messages",
|
|
41
|
+
"sessions",
|
|
42
|
+
"secret",
|
|
43
|
+
"since",
|
|
44
|
+
"stop-on",
|
|
45
|
+
"tail",
|
|
46
|
+
"tag",
|
|
47
|
+
"tags",
|
|
48
|
+
"text",
|
|
49
|
+
"text-file",
|
|
50
|
+
"timeout",
|
|
51
|
+
"timeout-ms",
|
|
52
|
+
"wait-timeout-ms",
|
|
53
|
+
"runtime-timeout",
|
|
54
|
+
"to",
|
|
55
|
+
"token",
|
|
56
|
+
"ttl",
|
|
57
|
+
"url",
|
|
58
|
+
"turn",
|
|
59
|
+
"until",
|
|
60
|
+
]);
|
|
61
|
+
const booleanFlags = new Set([
|
|
62
|
+
"all",
|
|
63
|
+
"detach",
|
|
64
|
+
"force",
|
|
65
|
+
"help",
|
|
66
|
+
"h",
|
|
67
|
+
"include-output",
|
|
68
|
+
"include-archived",
|
|
69
|
+
"json",
|
|
70
|
+
"keep-source",
|
|
71
|
+
"local",
|
|
72
|
+
"no-open",
|
|
73
|
+
"no-wait",
|
|
74
|
+
"repair-head",
|
|
75
|
+
"summary",
|
|
76
|
+
"verbose",
|
|
77
|
+
"wait",
|
|
78
|
+
]);
|
|
79
|
+
const knownFlags = new Set([...valueFlags, ...booleanFlags]);
|
|
80
|
+
const dashPrefixedValueFlags = new Set(["secret"]);
|
|
81
|
+
export function parseCliFlags(argv) {
|
|
82
|
+
const parsed = parseSharedFlags(argv, { valueFlags, dashPrefixedValueFlags });
|
|
83
|
+
const unknown = Object.keys(parsed.flags).filter((flag) => !knownFlags.has(flag));
|
|
84
|
+
if (unknown.length > 0) {
|
|
85
|
+
throw new CliError(`Unknown flag: --${unknown[0]}`, "UNKNOWN_FLAG");
|
|
86
|
+
}
|
|
87
|
+
return parsed;
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readLocalAuditLog(tail?: number): Promise<unknown[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { CliError } from "../../errors.js";
|
|
4
|
+
import { configDir } from "./paths.js";
|
|
5
|
+
export async function readLocalAuditLog(tail = 100) {
|
|
6
|
+
const auditPath = path.join(configDir, "audit.jsonl");
|
|
7
|
+
let content = "";
|
|
8
|
+
try {
|
|
9
|
+
content = await fs.readFile(auditPath, "utf8");
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === "ENOENT")
|
|
13
|
+
return [];
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
return content.trim().split("\n").filter(Boolean).slice(-tail).map((line) => JSON.parse(line));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof SyntaxError) {
|
|
21
|
+
throw new CliError("Local audit log contains invalid JSON.", "AUDIT_LOG_INVALID");
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CliConfig, DaemonConfig } from "./types.js";
|
|
2
|
+
export type ConfigBackup = {
|
|
3
|
+
path: string;
|
|
4
|
+
backupPath: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function ensureControllerConfig(params: {
|
|
8
|
+
relayUrl: string;
|
|
9
|
+
explicitRelay: boolean;
|
|
10
|
+
deviceName: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
config: CliConfig;
|
|
13
|
+
created: boolean;
|
|
14
|
+
accountId?: string;
|
|
15
|
+
backup?: ConfigBackup;
|
|
16
|
+
reconfigured: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function ensureDaemonPaired(config: CliConfig, machineName: string): Promise<{
|
|
19
|
+
config: DaemonConfig;
|
|
20
|
+
created: boolean;
|
|
21
|
+
backup?: ConfigBackup;
|
|
22
|
+
reconfigured: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function controllerBaseUrl(flags: Record<string, string | boolean>): string;
|
|
25
|
+
export declare function startRelayUrl(flags: Record<string, string | boolean>, existing?: CliConfig): {
|
|
26
|
+
relayUrl: string;
|
|
27
|
+
explicit: boolean;
|
|
28
|
+
};
|