arc402-cli 0.9.19 → 0.10.0
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 +41 -2
- package/dist/abis.d.ts +1 -0
- package/dist/abis.d.ts.map +1 -1
- package/dist/abis.js +45 -14
- package/dist/abis.js.map +1 -1
- package/dist/bundler.d.ts +1 -1
- package/dist/bundler.d.ts.map +1 -1
- package/dist/bundler.js +61 -27
- package/dist/bundler.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -5
- package/dist/client.js.map +1 -1
- package/dist/coinbase-smart-wallet.js +4 -1
- package/dist/coinbase-smart-wallet.js.map +1 -1
- package/dist/commands/accept.js +28 -25
- package/dist/commands/accept.js.map +1 -1
- package/dist/commands/agent-handshake.js +18 -15
- package/dist/commands/agent-handshake.js.map +1 -1
- package/dist/commands/agent.js +104 -98
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/agreements.js +98 -62
- package/dist/commands/agreements.js.map +1 -1
- package/dist/commands/arbitrator.js +81 -45
- package/dist/commands/arbitrator.js.map +1 -1
- package/dist/commands/arena-handshake.d.ts.map +1 -1
- package/dist/commands/arena-handshake.js +35 -53
- package/dist/commands/arena-handshake.js.map +1 -1
- package/dist/commands/arena.js +18 -12
- package/dist/commands/arena.js.map +1 -1
- package/dist/commands/backup.js +36 -30
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/cancel.js +18 -15
- package/dist/commands/cancel.js.map +1 -1
- package/dist/commands/channel.js +81 -45
- package/dist/commands/channel.js.map +1 -1
- package/dist/commands/coldstart.js +34 -31
- package/dist/commands/coldstart.js.map +1 -1
- package/dist/commands/compute.d.ts +14 -0
- package/dist/commands/compute.d.ts.map +1 -0
- package/dist/commands/compute.js +466 -0
- package/dist/commands/compute.js.map +1 -0
- package/dist/commands/config.js +30 -24
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/contract-interaction.js +15 -12
- package/dist/commands/contract-interaction.js.map +1 -1
- package/dist/commands/daemon.d.ts.map +1 -1
- package/dist/commands/daemon.js +135 -98
- package/dist/commands/daemon.js.map +1 -1
- package/dist/commands/deliver.js +76 -37
- package/dist/commands/deliver.js.map +1 -1
- package/dist/commands/discover.js +27 -24
- package/dist/commands/discover.js.map +1 -1
- package/dist/commands/dispute.js +110 -104
- package/dist/commands/dispute.js.map +1 -1
- package/dist/commands/doctor.js +55 -16
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/endpoint.js +95 -56
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/feed.js +18 -11
- package/dist/commands/feed.js.map +1 -1
- package/dist/commands/hire.js +40 -37
- package/dist/commands/hire.js.map +1 -1
- package/dist/commands/migrate.js +33 -30
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/negotiate.d.ts.map +1 -1
- package/dist/commands/negotiate.js +36 -34
- package/dist/commands/negotiate.js.map +1 -1
- package/dist/commands/openshell.js +104 -68
- package/dist/commands/openshell.js.map +1 -1
- package/dist/commands/owner.js +20 -17
- package/dist/commands/owner.js.map +1 -1
- package/dist/commands/policy.js +43 -41
- package/dist/commands/policy.js.map +1 -1
- package/dist/commands/relay.d.ts.map +1 -1
- package/dist/commands/relay.js +51 -18
- package/dist/commands/relay.js.map +1 -1
- package/dist/commands/remediate.js +23 -20
- package/dist/commands/remediate.js.map +1 -1
- package/dist/commands/reputation.js +27 -25
- package/dist/commands/reputation.js.map +1 -1
- package/dist/commands/setup.js +104 -65
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/trust.js +20 -17
- package/dist/commands/trust.js.map +1 -1
- package/dist/commands/verify.js +21 -18
- package/dist/commands/verify.js.map +1 -1
- package/dist/commands/wallet.d.ts.map +1 -1
- package/dist/commands/wallet.js +645 -679
- package/dist/commands/wallet.js.map +1 -1
- package/dist/commands/watch.js +36 -33
- package/dist/commands/watch.js.map +1 -1
- package/dist/commands/watchtower.js +73 -37
- package/dist/commands/watchtower.js.map +1 -1
- package/dist/commands/workroom.d.ts.map +1 -1
- package/dist/commands/workroom.js +282 -143
- package/dist/commands/workroom.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +71 -22
- package/dist/config.js.map +1 -1
- package/dist/daemon/compute-metering.d.ts +61 -0
- package/dist/daemon/compute-metering.d.ts.map +1 -0
- package/dist/daemon/compute-metering.js +299 -0
- package/dist/daemon/compute-metering.js.map +1 -0
- package/dist/daemon/compute-session.d.ts +100 -0
- package/dist/daemon/compute-session.d.ts.map +1 -0
- package/dist/daemon/compute-session.js +231 -0
- package/dist/daemon/compute-session.js.map +1 -0
- package/dist/daemon/config.d.ts +19 -1
- package/dist/daemon/config.d.ts.map +1 -1
- package/dist/daemon/config.js +90 -16
- package/dist/daemon/config.js.map +1 -1
- package/dist/daemon/credentials.d.ts +24 -0
- package/dist/daemon/credentials.d.ts.map +1 -0
- package/dist/daemon/credentials.js +80 -0
- package/dist/daemon/credentials.js.map +1 -0
- package/dist/daemon/delivery-client.d.ts +35 -0
- package/dist/daemon/delivery-client.d.ts.map +1 -0
- package/dist/daemon/delivery-client.js +231 -0
- package/dist/daemon/delivery-client.js.map +1 -0
- package/dist/daemon/file-delivery.d.ts +98 -0
- package/dist/daemon/file-delivery.d.ts.map +1 -0
- package/dist/daemon/file-delivery.js +461 -0
- package/dist/daemon/file-delivery.js.map +1 -0
- package/dist/daemon/hire-listener.d.ts +3 -3
- package/dist/daemon/hire-listener.d.ts.map +1 -1
- package/dist/daemon/hire-listener.js +47 -13
- package/dist/daemon/hire-listener.js.map +1 -1
- package/dist/daemon/index.d.ts +2 -1
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +526 -53
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/job-lifecycle.d.ts +1 -1
- package/dist/daemon/job-lifecycle.d.ts.map +1 -1
- package/dist/daemon/job-lifecycle.js +51 -11
- package/dist/daemon/job-lifecycle.js.map +1 -1
- package/dist/daemon/notify.d.ts +1 -1
- package/dist/daemon/notify.d.ts.map +1 -1
- package/dist/daemon/notify.js +53 -19
- package/dist/daemon/notify.js.map +1 -1
- package/dist/daemon/token-metering.js +47 -8
- package/dist/daemon/token-metering.js.map +1 -1
- package/dist/daemon/userops.d.ts +2 -2
- package/dist/daemon/userops.d.ts.map +1 -1
- package/dist/daemon/userops.js +27 -23
- package/dist/daemon/userops.js.map +1 -1
- package/dist/daemon/wallet-monitor.d.ts +1 -1
- package/dist/daemon/wallet-monitor.d.ts.map +1 -1
- package/dist/daemon/wallet-monitor.js +12 -8
- package/dist/daemon/wallet-monitor.js.map +1 -1
- package/dist/daemon/worker-executor.d.ts +71 -0
- package/dist/daemon/worker-executor.d.ts.map +1 -0
- package/dist/daemon/worker-executor.js +382 -0
- package/dist/daemon/worker-executor.js.map +1 -0
- package/dist/drain-v4.js +64 -26
- package/dist/drain-v4.js.map +1 -1
- package/dist/endpoint-config.js +63 -20
- package/dist/endpoint-config.js.map +1 -1
- package/dist/endpoint-notify.d.ts.map +1 -1
- package/dist/endpoint-notify.js +49 -15
- package/dist/endpoint-notify.js.map +1 -1
- package/dist/index.js +50 -18
- package/dist/index.js.map +1 -1
- package/dist/openshell-runtime.d.ts.map +1 -1
- package/dist/openshell-runtime.js +82 -38
- package/dist/openshell-runtime.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +85 -78
- package/dist/program.js.map +1 -1
- package/dist/repl.js +31 -25
- package/dist/repl.js.map +1 -1
- package/dist/signing.js +6 -3
- package/dist/signing.js.map +1 -1
- package/dist/telegram-notify.js +40 -3
- package/dist/telegram-notify.js.map +1 -1
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +56 -89
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/Footer.js +7 -4
- package/dist/tui/Footer.js.map +1 -1
- package/dist/tui/Header.d.ts +1 -1
- package/dist/tui/Header.d.ts.map +1 -1
- package/dist/tui/Header.js +14 -9
- package/dist/tui/Header.js.map +1 -1
- package/dist/tui/InputLine.d.ts +2 -1
- package/dist/tui/InputLine.d.ts.map +1 -1
- package/dist/tui/InputLine.js +47 -97
- package/dist/tui/InputLine.js.map +1 -1
- package/dist/tui/Viewport.d.ts +1 -2
- package/dist/tui/Viewport.d.ts.map +1 -1
- package/dist/tui/Viewport.js +26 -6
- package/dist/tui/Viewport.js.map +1 -1
- package/dist/tui/WalletConnectPairing.js +19 -16
- package/dist/tui/WalletConnectPairing.js.map +1 -1
- package/dist/tui/components/Button.js +9 -6
- package/dist/tui/components/Button.js.map +1 -1
- package/dist/tui/components/CeremonyView.js +8 -5
- package/dist/tui/components/CeremonyView.js.map +1 -1
- package/dist/tui/components/CompletionDropdown.js +9 -6
- package/dist/tui/components/CompletionDropdown.js.map +1 -1
- package/dist/tui/components/ConfirmPrompt.js +8 -5
- package/dist/tui/components/ConfirmPrompt.js.map +1 -1
- package/dist/tui/components/CustomTextInput.js +14 -11
- package/dist/tui/components/CustomTextInput.js.map +1 -1
- package/dist/tui/components/InteractiveTable.js +12 -9
- package/dist/tui/components/InteractiveTable.js.map +1 -1
- package/dist/tui/components/StepSpinner.js +13 -10
- package/dist/tui/components/StepSpinner.js.map +1 -1
- package/dist/tui/components/Toast.js +12 -8
- package/dist/tui/components/Toast.js.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +21 -28
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/useChat.js +19 -13
- package/dist/tui/useChat.js.map +1 -1
- package/dist/tui/useCommand.d.ts +2 -3
- package/dist/tui/useCommand.d.ts.map +1 -1
- package/dist/tui/useCommand.js +24 -100
- package/dist/tui/useCommand.js.map +1 -1
- package/dist/tui/useNotifications.js +8 -5
- package/dist/tui/useNotifications.js.map +1 -1
- package/dist/tui/useScroll.d.ts.map +1 -1
- package/dist/tui/useScroll.js +12 -15
- package/dist/tui/useScroll.js.map +1 -1
- package/dist/ui/banner.d.ts +0 -12
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +19 -35
- package/dist/ui/banner.js.map +1 -1
- package/dist/ui/colors.js +19 -13
- package/dist/ui/colors.js.map +1 -1
- package/dist/ui/format.js +14 -6
- package/dist/ui/format.js.map +1 -1
- package/dist/ui/qr-render.js +11 -4
- package/dist/ui/qr-render.js.map +1 -1
- package/dist/ui/rpc-fallback.js +11 -6
- package/dist/ui/rpc-fallback.js.map +1 -1
- package/dist/ui/spinner.js +12 -6
- package/dist/ui/spinner.js.map +1 -1
- package/dist/ui/tree.js +6 -3
- package/dist/ui/tree.js.map +1 -1
- package/dist/utils/format.js +41 -27
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/hash.js +42 -4
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/time.js +6 -2
- package/dist/utils/time.js.map +1 -1
- package/dist/wallet-router.d.ts +1 -1
- package/dist/wallet-router.d.ts.map +1 -1
- package/dist/wallet-router.js +19 -12
- package/dist/wallet-router.js.map +1 -1
- package/dist/walletconnect-session.d.ts +1 -1
- package/dist/walletconnect-session.d.ts.map +1 -1
- package/dist/walletconnect-session.js +11 -6
- package/dist/walletconnect-session.js.map +1 -1
- package/dist/walletconnect.d.ts +5 -6
- package/dist/walletconnect.d.ts.map +1 -1
- package/dist/walletconnect.js +35 -32
- package/dist/walletconnect.js.map +1 -1
- package/package.json +11 -10
- package/INK6-UX-SPEC.md +0 -446
- package/MIGRATION-SPEC.md +0 -108
- package/TUI-SPEC.md +0 -214
- package/scripts/authorize-machine-key.ts +0 -43
- package/scripts/drain-wallet.ts +0 -149
- package/scripts/execute-spend-only.ts +0 -81
- package/scripts/register-agent-userop.ts +0 -186
- package/src/abis.ts +0 -187
- package/src/bundler.ts +0 -235
- package/src/client.ts +0 -36
- package/src/coinbase-smart-wallet.ts +0 -51
- package/src/commands/accept.ts +0 -64
- package/src/commands/agent-handshake.ts +0 -72
- package/src/commands/agent.ts +0 -691
- package/src/commands/agreements.ts +0 -350
- package/src/commands/arbitrator.ts +0 -180
- package/src/commands/arena-handshake.ts +0 -274
- package/src/commands/arena.ts +0 -122
- package/src/commands/backup.ts +0 -117
- package/src/commands/cancel.ts +0 -35
- package/src/commands/channel.ts +0 -218
- package/src/commands/coldstart.ts +0 -165
- package/src/commands/config.ts +0 -68
- package/src/commands/contract-interaction.ts +0 -166
- package/src/commands/daemon.ts +0 -1054
- package/src/commands/deliver.ts +0 -148
- package/src/commands/discover.ts +0 -350
- package/src/commands/dispute.ts +0 -375
- package/src/commands/doctor.ts +0 -172
- package/src/commands/endpoint.ts +0 -620
- package/src/commands/feed.ts +0 -229
- package/src/commands/hire.ts +0 -245
- package/src/commands/migrate.ts +0 -177
- package/src/commands/negotiate.ts +0 -272
- package/src/commands/openshell.ts +0 -1055
- package/src/commands/owner.ts +0 -35
- package/src/commands/policy.ts +0 -263
- package/src/commands/relay.ts +0 -277
- package/src/commands/remediate.ts +0 -24
- package/src/commands/reputation.ts +0 -79
- package/src/commands/setup.ts +0 -343
- package/src/commands/trust.ts +0 -27
- package/src/commands/verify.ts +0 -91
- package/src/commands/wallet.ts +0 -3548
- package/src/commands/watch.ts +0 -220
- package/src/commands/watchtower.ts +0 -248
- package/src/commands/workroom.ts +0 -963
- package/src/config.ts +0 -220
- package/src/daemon/config.ts +0 -344
- package/src/daemon/hire-listener.ts +0 -226
- package/src/daemon/index.ts +0 -1089
- package/src/daemon/job-lifecycle.ts +0 -215
- package/src/daemon/notify.ts +0 -297
- package/src/daemon/token-metering.ts +0 -183
- package/src/daemon/userops.ts +0 -119
- package/src/daemon/wallet-monitor.ts +0 -90
- package/src/drain-v4.ts +0 -159
- package/src/endpoint-config.ts +0 -83
- package/src/endpoint-notify.ts +0 -134
- package/src/index.ts +0 -74
- package/src/openshell-runtime.ts +0 -281
- package/src/program.ts +0 -88
- package/src/repl.ts +0 -178
- package/src/signing.ts +0 -28
- package/src/telegram-notify.ts +0 -88
- package/src/tui/App.tsx +0 -263
- package/src/tui/Footer.tsx +0 -18
- package/src/tui/Header.tsx +0 -45
- package/src/tui/InputLine.tsx +0 -243
- package/src/tui/Viewport.tsx +0 -51
- package/src/tui/WalletConnectPairing.tsx +0 -114
- package/src/tui/components/Button.tsx +0 -38
- package/src/tui/components/CeremonyView.tsx +0 -39
- package/src/tui/components/CompletionDropdown.tsx +0 -56
- package/src/tui/components/ConfirmPrompt.tsx +0 -36
- package/src/tui/components/CustomTextInput.tsx +0 -132
- package/src/tui/components/InteractiveTable.tsx +0 -106
- package/src/tui/components/StepSpinner.tsx +0 -84
- package/src/tui/components/Toast.tsx +0 -59
- package/src/tui/index.tsx +0 -90
- package/src/tui/useChat.ts +0 -103
- package/src/tui/useCommand.ts +0 -238
- package/src/tui/useNotifications.ts +0 -28
- package/src/tui/useScroll.ts +0 -69
- package/src/ui/banner.ts +0 -78
- package/src/ui/colors.ts +0 -30
- package/src/ui/format.ts +0 -78
- package/src/ui/qr-render.ts +0 -92
- package/src/ui/rpc-fallback.ts +0 -59
- package/src/ui/spinner.ts +0 -56
- package/src/ui/tree.ts +0 -16
- package/src/utils/format.ts +0 -48
- package/src/utils/hash.ts +0 -5
- package/src/utils/time.ts +0 -15
- package/src/wallet-router.ts +0 -178
- package/src/walletconnect-session.ts +0 -27
- package/src/walletconnect.ts +0 -309
- package/test/time.test.js +0 -11
- package/tsconfig.json +0 -33
package/src/openshell-runtime.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as os from "os";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import { spawnSync } from "child_process";
|
|
5
|
-
import { parse as parseToml } from "smol-toml";
|
|
6
|
-
import { loadConfig } from "./config.js";
|
|
7
|
-
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
|
|
12
|
-
export const ARC402_DIR = path.join(os.homedir(), ".arc402");
|
|
13
|
-
export const OPENSHELL_TOML = path.join(ARC402_DIR, "openshell.toml");
|
|
14
|
-
export const OPENSHELL_RUNTIME_DIR = path.join(ARC402_DIR, "openshell-runtime");
|
|
15
|
-
export const OPENSHELL_RUNTIME_TARBALL = path.join(OPENSHELL_RUNTIME_DIR, "arc402-cli-runtime.tgz");
|
|
16
|
-
export const DEFAULT_RUNTIME_REMOTE_ROOT = "/sandbox/.arc402/runtime/arc402-cli";
|
|
17
|
-
|
|
18
|
-
export interface OpenShellConfig {
|
|
19
|
-
sandbox: { name: string; policy?: string; providers?: string[] };
|
|
20
|
-
runtime?: {
|
|
21
|
-
local_tarball?: string;
|
|
22
|
-
remote_root?: string;
|
|
23
|
-
synced_at?: string;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function runCmd(
|
|
28
|
-
cmd: string,
|
|
29
|
-
args: string[],
|
|
30
|
-
opts: { env?: NodeJS.ProcessEnv; input?: string; timeout?: number } = {}
|
|
31
|
-
): { stdout: string; stderr: string; ok: boolean; status: number | null } {
|
|
32
|
-
const result = spawnSync(cmd, args, {
|
|
33
|
-
encoding: "utf-8",
|
|
34
|
-
env: { ...process.env, ...(opts.env ?? {}) },
|
|
35
|
-
input: opts.input,
|
|
36
|
-
timeout: opts.timeout ?? 60000,
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
stdout: (result.stdout ?? "").trim(),
|
|
40
|
-
stderr: (result.stderr ?? "").trim(),
|
|
41
|
-
ok: result.status === 0 && !result.error,
|
|
42
|
-
status: result.status,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface DockerAccessStatus {
|
|
47
|
-
ok: boolean;
|
|
48
|
-
detail: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function detectDockerAccess(): DockerAccessStatus {
|
|
52
|
-
const result = runCmd("docker", ["info", "--format", "{{.ServerVersion}}"], { timeout: 20000 });
|
|
53
|
-
if (result.ok) {
|
|
54
|
-
return { ok: true, detail: `running (${result.stdout || "version unknown"})` };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const detail = result.stderr || result.stdout || "Docker is unavailable";
|
|
58
|
-
if (/permission denied/i.test(detail)) {
|
|
59
|
-
return { ok: false, detail: "installed but this shell cannot access the Docker daemon" };
|
|
60
|
-
}
|
|
61
|
-
if (/Cannot connect to the Docker daemon/i.test(detail) || /Is the docker daemon running/i.test(detail)) {
|
|
62
|
-
return { ok: false, detail: "installed but the Docker daemon is not running" };
|
|
63
|
-
}
|
|
64
|
-
if (/command not found/i.test(detail) || result.status === 127) {
|
|
65
|
-
return { ok: false, detail: "not installed" };
|
|
66
|
-
}
|
|
67
|
-
return { ok: false, detail };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function resolveOpenShellSecrets(): {
|
|
71
|
-
machineKey?: string;
|
|
72
|
-
telegramBotToken?: string;
|
|
73
|
-
telegramChatId?: string;
|
|
74
|
-
} {
|
|
75
|
-
let machineKey = process.env["ARC402_MACHINE_KEY"];
|
|
76
|
-
let telegramBotToken = process.env["TELEGRAM_BOT_TOKEN"];
|
|
77
|
-
let telegramChatId = process.env["TELEGRAM_CHAT_ID"];
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const config = loadConfig();
|
|
81
|
-
if (!machineKey && config.privateKey) machineKey = config.privateKey;
|
|
82
|
-
if (!telegramBotToken && config.telegramBotToken) telegramBotToken = config.telegramBotToken;
|
|
83
|
-
if (!telegramChatId && config.telegramChatId) telegramChatId = config.telegramChatId;
|
|
84
|
-
} catch {
|
|
85
|
-
// CLI config is optional here; env vars still win when present.
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return { machineKey, telegramBotToken, telegramChatId };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function buildOpenShellSecretExports(requireMachineKey = false): string {
|
|
92
|
-
const secrets = resolveOpenShellSecrets();
|
|
93
|
-
const exports: string[] = [];
|
|
94
|
-
|
|
95
|
-
if (secrets.machineKey) {
|
|
96
|
-
exports.push(`export ARC402_MACHINE_KEY=${shellEscape(secrets.machineKey)}`);
|
|
97
|
-
} else if (requireMachineKey) {
|
|
98
|
-
throw new Error("ARC402 machine key not found in env or arc402 config");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (secrets.telegramBotToken) {
|
|
102
|
-
exports.push(`export TELEGRAM_BOT_TOKEN=${shellEscape(secrets.telegramBotToken)}`);
|
|
103
|
-
}
|
|
104
|
-
if (secrets.telegramChatId) {
|
|
105
|
-
exports.push(`export TELEGRAM_CHAT_ID=${shellEscape(secrets.telegramChatId)}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return exports.join(" && ");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function readOpenShellConfig(): OpenShellConfig | null {
|
|
112
|
-
if (!fs.existsSync(OPENSHELL_TOML)) return null;
|
|
113
|
-
try {
|
|
114
|
-
const raw = fs.readFileSync(OPENSHELL_TOML, "utf-8");
|
|
115
|
-
const parsed = parseToml(raw) as Record<string, unknown>;
|
|
116
|
-
const sb = parsed.sandbox as Record<string, unknown> | undefined;
|
|
117
|
-
if (!sb || typeof sb.name !== "string") return null;
|
|
118
|
-
const runtime = parsed.runtime as Record<string, unknown> | undefined;
|
|
119
|
-
return {
|
|
120
|
-
sandbox: {
|
|
121
|
-
name: sb.name,
|
|
122
|
-
policy: typeof sb.policy === "string" ? sb.policy : undefined,
|
|
123
|
-
providers: Array.isArray(sb.providers) ? (sb.providers as string[]) : undefined,
|
|
124
|
-
},
|
|
125
|
-
runtime: runtime ? {
|
|
126
|
-
local_tarball: typeof runtime.local_tarball === "string" ? runtime.local_tarball : undefined,
|
|
127
|
-
remote_root: typeof runtime.remote_root === "string" ? runtime.remote_root : undefined,
|
|
128
|
-
synced_at: typeof runtime.synced_at === "string" ? runtime.synced_at : undefined,
|
|
129
|
-
} : undefined,
|
|
130
|
-
};
|
|
131
|
-
} catch {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function writeOpenShellConfig(config: OpenShellConfig): void {
|
|
137
|
-
fs.mkdirSync(ARC402_DIR, { recursive: true, mode: 0o700 });
|
|
138
|
-
const providers = (config.sandbox.providers ?? []).map((p) => `"${p}"`).join(", ");
|
|
139
|
-
const lines = [
|
|
140
|
-
"# ARC-402 OpenShell configuration",
|
|
141
|
-
"# Written by: arc402 openshell init / sync-runtime",
|
|
142
|
-
"",
|
|
143
|
-
"[sandbox]",
|
|
144
|
-
`name = "${config.sandbox.name}"`,
|
|
145
|
-
config.sandbox.policy ? `policy = "${config.sandbox.policy}"` : "",
|
|
146
|
-
`providers = [${providers}]`,
|
|
147
|
-
"",
|
|
148
|
-
"[runtime]",
|
|
149
|
-
`local_tarball = "${config.runtime?.local_tarball ?? OPENSHELL_RUNTIME_TARBALL}"`,
|
|
150
|
-
`remote_root = "${config.runtime?.remote_root ?? DEFAULT_RUNTIME_REMOTE_ROOT}"`,
|
|
151
|
-
`synced_at = "${config.runtime?.synced_at ?? new Date().toISOString()}"`,
|
|
152
|
-
"",
|
|
153
|
-
].filter(Boolean);
|
|
154
|
-
fs.writeFileSync(OPENSHELL_TOML, lines.join("\n"), { mode: 0o600 });
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function findCliRoot(startDir: string): string {
|
|
158
|
-
let current = startDir;
|
|
159
|
-
while (true) {
|
|
160
|
-
const pkg = path.join(current, "package.json");
|
|
161
|
-
const dist = path.join(current, "dist", "index.js");
|
|
162
|
-
if (fs.existsSync(pkg) && fs.existsSync(dist)) return current;
|
|
163
|
-
const parent = path.dirname(current);
|
|
164
|
-
if (parent === current) throw new Error("Could not locate ARC-402 CLI root from current install path");
|
|
165
|
-
current = parent;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function buildRuntimeTarball(): { cliRoot: string; tarballPath: string } {
|
|
170
|
-
const cliRoot = findCliRoot(__dirname);
|
|
171
|
-
fs.mkdirSync(OPENSHELL_RUNTIME_DIR, { recursive: true, mode: 0o700 });
|
|
172
|
-
|
|
173
|
-
const tar = runCmd(
|
|
174
|
-
"tar",
|
|
175
|
-
[
|
|
176
|
-
"-czf",
|
|
177
|
-
OPENSHELL_RUNTIME_TARBALL,
|
|
178
|
-
"package.json",
|
|
179
|
-
"package-lock.json",
|
|
180
|
-
"dist",
|
|
181
|
-
"node_modules",
|
|
182
|
-
],
|
|
183
|
-
{ timeout: 300000, env: process.env }
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
if (!tar.ok) {
|
|
187
|
-
// Retry from the cli root via shell so relative paths resolve correctly.
|
|
188
|
-
const shellTar = runCmd(
|
|
189
|
-
"bash",
|
|
190
|
-
[
|
|
191
|
-
"-lc",
|
|
192
|
-
`cd ${shellEscape(cliRoot)} && tar -czf ${shellEscape(OPENSHELL_RUNTIME_TARBALL)} package.json package-lock.json dist node_modules`,
|
|
193
|
-
],
|
|
194
|
-
{ timeout: 300000 }
|
|
195
|
-
);
|
|
196
|
-
if (!shellTar.ok) {
|
|
197
|
-
throw new Error(shellTar.stderr || shellTar.stdout || "Failed to build ARC-402 runtime tarball");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return { cliRoot, tarballPath: OPENSHELL_RUNTIME_TARBALL };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function buildOpenShellSshConfig(sandboxName: string): { configPath: string; host: string } {
|
|
205
|
-
const sshConfig = runCmd("openshell", ["sandbox", "ssh-config", sandboxName], { timeout: 120000 });
|
|
206
|
-
if (!sshConfig.ok || !sshConfig.stdout.trim()) {
|
|
207
|
-
throw new Error(`Failed to get OpenShell SSH config for sandbox ${sandboxName}: ${sshConfig.stderr || sshConfig.stdout || "unknown error"}`);
|
|
208
|
-
}
|
|
209
|
-
const hostMatch = sshConfig.stdout.match(/^Host\s+(\S+)/m);
|
|
210
|
-
if (!hostMatch) {
|
|
211
|
-
throw new Error(`Could not parse OpenShell SSH host alias for sandbox ${sandboxName}`);
|
|
212
|
-
}
|
|
213
|
-
const configPath = path.join(os.tmpdir(), `arc402-openshell-${sandboxName}.ssh`);
|
|
214
|
-
fs.writeFileSync(configPath, sshConfig.stdout, { mode: 0o600 });
|
|
215
|
-
return { configPath, host: hostMatch[1] };
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function provisionFileToSandbox(sandboxName: string, localPath: string, remotePath: string): void {
|
|
219
|
-
if (!fs.existsSync(localPath)) {
|
|
220
|
-
throw new Error(`Local file not found: ${localPath}`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const remoteDir = path.posix.dirname(remotePath);
|
|
224
|
-
const uploadDir = `/tmp/arc402-upload-${Date.now()}`;
|
|
225
|
-
const { configPath, host } = buildOpenShellSshConfig(sandboxName);
|
|
226
|
-
|
|
227
|
-
const prep = runCmd("ssh", ["-F", configPath, host, `rm -rf ${shellEscape(uploadDir)} && mkdir -p ${shellEscape(uploadDir)} && mkdir -p ${shellEscape(remoteDir)}`], { timeout: 120000 });
|
|
228
|
-
if (!prep.ok) {
|
|
229
|
-
throw new Error(`Failed to prepare remote upload directory: ${prep.stderr || prep.stdout}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const upload = runCmd("openshell", ["sandbox", "upload", sandboxName, localPath, uploadDir], { timeout: 300000 });
|
|
233
|
-
if (!upload.ok) {
|
|
234
|
-
throw new Error(`Failed to upload ${path.basename(localPath)}: ${upload.stderr || upload.stdout}`);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const remoteUploaded = path.posix.join(uploadDir, path.basename(localPath));
|
|
238
|
-
const move = runCmd("ssh", ["-F", configPath, host, `cp ${shellEscape(remoteUploaded)} ${shellEscape(remotePath)}`], { timeout: 120000 });
|
|
239
|
-
if (!move.ok) {
|
|
240
|
-
throw new Error(`Failed to place ${path.basename(localPath)} at ${remotePath}: ${move.stderr || move.stdout}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function provisionRuntimeToSandbox(
|
|
245
|
-
sandboxName: string,
|
|
246
|
-
remoteRoot = DEFAULT_RUNTIME_REMOTE_ROOT,
|
|
247
|
-
): { tarballPath: string; remoteRoot: string } {
|
|
248
|
-
const { tarballPath } = buildRuntimeTarball();
|
|
249
|
-
const remoteUploadDir = `/tmp/arc402-runtime-upload-${Date.now()}`;
|
|
250
|
-
const remoteTarball = `${remoteUploadDir}/arc402-cli-runtime.tgz`;
|
|
251
|
-
const { configPath, host } = buildOpenShellSshConfig(sandboxName);
|
|
252
|
-
|
|
253
|
-
const prep = runCmd("ssh", ["-F", configPath, host, `rm -rf ${shellEscape(remoteUploadDir)} && mkdir -p ${shellEscape(remoteUploadDir)}`], { timeout: 120000 });
|
|
254
|
-
if (!prep.ok) {
|
|
255
|
-
throw new Error(`Failed to prepare remote upload directory: ${prep.stderr || prep.stdout}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const upload = runCmd("openshell", ["sandbox", "upload", sandboxName, tarballPath, remoteUploadDir], { timeout: 300000 });
|
|
259
|
-
if (!upload.ok) {
|
|
260
|
-
throw new Error(`Failed to upload ARC-402 runtime bundle: ${upload.stderr || upload.stdout}`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const extract = runCmd(
|
|
264
|
-
"ssh",
|
|
265
|
-
[
|
|
266
|
-
"-F", configPath,
|
|
267
|
-
host,
|
|
268
|
-
`mkdir -p ${shellEscape(remoteRoot)} && tar -xzf ${shellEscape(remoteTarball)} -C ${shellEscape(remoteRoot)} && test -f ${shellEscape(path.posix.join(remoteRoot, "dist/daemon/index.js"))}`,
|
|
269
|
-
],
|
|
270
|
-
{ timeout: 300000 }
|
|
271
|
-
);
|
|
272
|
-
if (!extract.ok) {
|
|
273
|
-
throw new Error(`Failed to provision ARC-402 runtime inside sandbox: ${extract.stderr || extract.stdout}`);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return { tarballPath, remoteRoot };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export function shellEscape(value: string): string {
|
|
280
|
-
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
281
|
-
}
|
package/src/program.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { registerAcceptCommand } from "./commands/accept.js";
|
|
4
|
-
import { registerAgentCommands } from "./commands/agent.js";
|
|
5
|
-
import { registerAgreementsCommands } from "./commands/agreements.js";
|
|
6
|
-
import { registerArbitratorCommand } from "./commands/arbitrator.js";
|
|
7
|
-
import { registerCancelCommand } from "./commands/cancel.js";
|
|
8
|
-
import { registerChannelCommands } from "./commands/channel.js";
|
|
9
|
-
import { registerConfigCommands } from "./commands/config.js";
|
|
10
|
-
import { registerDeliverCommand } from "./commands/deliver.js";
|
|
11
|
-
import { registerDiscoverCommand } from "./commands/discover.js";
|
|
12
|
-
import { registerEndpointCommands } from "./commands/endpoint.js";
|
|
13
|
-
import { registerDisputeCommand } from "./commands/dispute.js";
|
|
14
|
-
import { registerHireCommand } from "./commands/hire.js";
|
|
15
|
-
import { registerHandshakeCommand } from "./commands/agent-handshake.js";
|
|
16
|
-
import { registerNegotiateCommands } from "./commands/negotiate.js";
|
|
17
|
-
import { registerRelayCommands } from "./commands/relay.js";
|
|
18
|
-
import { registerRemediateCommands } from "./commands/remediate.js";
|
|
19
|
-
import { registerDaemonCommands } from "./commands/daemon.js";
|
|
20
|
-
import { registerOpenShellCommands } from "./commands/openshell.js";
|
|
21
|
-
import { registerWorkroomCommands } from "./commands/workroom.js";
|
|
22
|
-
import { registerArenaHandshakeCommands } from "./commands/arena-handshake.js";
|
|
23
|
-
import { registerTrustCommand } from "./commands/trust.js";
|
|
24
|
-
import { registerWalletCommands } from "./commands/wallet.js";
|
|
25
|
-
import { registerOwnerCommands } from "./commands/owner.js";
|
|
26
|
-
import { registerSetupCommands } from "./commands/setup.js";
|
|
27
|
-
import { registerVerifyCommand } from "./commands/verify.js";
|
|
28
|
-
import { registerContractInteractionCommands } from "./commands/contract-interaction.js";
|
|
29
|
-
import { registerWatchtowerCommands } from "./commands/watchtower.js";
|
|
30
|
-
import { registerColdStartCommands } from "./commands/coldstart.js";
|
|
31
|
-
import { registerDoctorCommand } from "./commands/doctor.js";
|
|
32
|
-
import { registerMigrateCommands } from "./commands/migrate.js";
|
|
33
|
-
import { registerFeedCommand } from "./commands/feed.js";
|
|
34
|
-
import { registerArenaCommands } from "./commands/arena.js";
|
|
35
|
-
import { registerWatchCommand } from "./commands/watch.js";
|
|
36
|
-
import { registerBackupCommand } from "./commands/backup.js";
|
|
37
|
-
import reputation from "./commands/reputation.js";
|
|
38
|
-
import policy from "./commands/policy.js";
|
|
39
|
-
|
|
40
|
-
export function createProgram(): Command {
|
|
41
|
-
const program = new Command();
|
|
42
|
-
program
|
|
43
|
-
.name("arc402")
|
|
44
|
-
.description(
|
|
45
|
-
"ARC-402 CLI aligned to canonical-capability discovery → negotiate → hire → remediate → dispute workflow"
|
|
46
|
-
)
|
|
47
|
-
.version((createRequire(import.meta.url)("../package.json") as { version: string }).version)
|
|
48
|
-
.option("--verbose", "Show detailed debug output (RPC calls, contract checks, fallback attempts)");
|
|
49
|
-
|
|
50
|
-
registerConfigCommands(program);
|
|
51
|
-
registerHandshakeCommand(program);
|
|
52
|
-
registerAgentCommands(program);
|
|
53
|
-
registerDiscoverCommand(program);
|
|
54
|
-
registerEndpointCommands(program);
|
|
55
|
-
registerNegotiateCommands(program);
|
|
56
|
-
registerHireCommand(program);
|
|
57
|
-
registerAgreementsCommands(program);
|
|
58
|
-
registerAcceptCommand(program);
|
|
59
|
-
registerDeliverCommand(program);
|
|
60
|
-
registerRemediateCommands(program);
|
|
61
|
-
registerDisputeCommand(program);
|
|
62
|
-
registerArbitratorCommand(program);
|
|
63
|
-
registerCancelCommand(program);
|
|
64
|
-
registerChannelCommands(program);
|
|
65
|
-
registerRelayCommands(program);
|
|
66
|
-
registerDaemonCommands(program);
|
|
67
|
-
registerOpenShellCommands(program);
|
|
68
|
-
registerWorkroomCommands(program);
|
|
69
|
-
registerArenaHandshakeCommands(program);
|
|
70
|
-
registerTrustCommand(program);
|
|
71
|
-
registerWalletCommands(program);
|
|
72
|
-
registerOwnerCommands(program);
|
|
73
|
-
registerSetupCommands(program);
|
|
74
|
-
registerVerifyCommand(program);
|
|
75
|
-
registerContractInteractionCommands(program);
|
|
76
|
-
registerWatchtowerCommands(program);
|
|
77
|
-
registerColdStartCommands(program);
|
|
78
|
-
registerDoctorCommand(program);
|
|
79
|
-
registerMigrateCommands(program);
|
|
80
|
-
registerFeedCommand(program);
|
|
81
|
-
registerArenaCommands(program);
|
|
82
|
-
registerWatchCommand(program);
|
|
83
|
-
registerBackupCommand(program);
|
|
84
|
-
program.addCommand(reputation);
|
|
85
|
-
program.addCommand(policy);
|
|
86
|
-
|
|
87
|
-
return program;
|
|
88
|
-
}
|
package/src/repl.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import readline from "readline";
|
|
6
|
-
import { createProgram } from "./program.js";
|
|
7
|
-
import { getBannerLines, BannerConfig } from "./ui/banner.js";
|
|
8
|
-
import { c } from "./ui/colors.js";
|
|
9
|
-
|
|
10
|
-
// ─── Config helpers ────────────────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
const CONFIG_PATH = path.join(os.homedir(), ".arc402", "config.json");
|
|
13
|
-
|
|
14
|
-
async function loadBannerConfig(): Promise<BannerConfig | undefined> {
|
|
15
|
-
if (!fs.existsSync(CONFIG_PATH)) return undefined;
|
|
16
|
-
try {
|
|
17
|
-
const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")) as {
|
|
18
|
-
network?: string;
|
|
19
|
-
walletContractAddress?: string;
|
|
20
|
-
};
|
|
21
|
-
const cfg: BannerConfig = { network: raw.network };
|
|
22
|
-
if (raw.walletContractAddress) {
|
|
23
|
-
const w = raw.walletContractAddress;
|
|
24
|
-
cfg.wallet = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
25
|
-
}
|
|
26
|
-
return cfg;
|
|
27
|
-
} catch {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ─── Prompt ────────────────────────────────────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
const PROMPT =
|
|
35
|
-
chalk.cyanBright("◈") +
|
|
36
|
-
" " +
|
|
37
|
-
chalk.dim("arc402") +
|
|
38
|
-
" " +
|
|
39
|
-
chalk.white(">") +
|
|
40
|
-
" ";
|
|
41
|
-
|
|
42
|
-
// ─── Shell-style tokenizer ────────────────────────────────────────────────────
|
|
43
|
-
|
|
44
|
-
function parseTokens(input: string): string[] {
|
|
45
|
-
const tokens: string[] = [];
|
|
46
|
-
let current = "";
|
|
47
|
-
let inQuote = false;
|
|
48
|
-
let quoteChar = "";
|
|
49
|
-
let escape = false;
|
|
50
|
-
for (const ch of input) {
|
|
51
|
-
if (escape) {
|
|
52
|
-
current += ch;
|
|
53
|
-
escape = false;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (inQuote) {
|
|
57
|
-
if (quoteChar === '"' && ch === "\\") {
|
|
58
|
-
escape = true;
|
|
59
|
-
} else if (ch === quoteChar) {
|
|
60
|
-
inQuote = false;
|
|
61
|
-
} else {
|
|
62
|
-
current += ch;
|
|
63
|
-
}
|
|
64
|
-
} else if (ch === '"' || ch === "'") {
|
|
65
|
-
inQuote = true;
|
|
66
|
-
quoteChar = ch;
|
|
67
|
-
} else if (ch === " ") {
|
|
68
|
-
if (current) {
|
|
69
|
-
tokens.push(current);
|
|
70
|
-
current = "";
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
current += ch;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (current) tokens.push(current);
|
|
77
|
-
return tokens;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ─── REPL entry point (basic readline fallback) ────────────────────────────────
|
|
81
|
-
|
|
82
|
-
export async function startREPL(): Promise<void> {
|
|
83
|
-
if (!process.stdout.isTTY) {
|
|
84
|
-
const bannerCfg = await loadBannerConfig();
|
|
85
|
-
for (const line of getBannerLines(bannerCfg)) {
|
|
86
|
-
process.stdout.write(line + "\n");
|
|
87
|
-
}
|
|
88
|
-
process.stdout.write(
|
|
89
|
-
"Interactive TUI requires a TTY. Use arc402 <command> directly.\n"
|
|
90
|
-
);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const bannerCfg = await loadBannerConfig();
|
|
95
|
-
for (const line of getBannerLines(bannerCfg)) {
|
|
96
|
-
process.stdout.write(line + "\n");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const rl = readline.createInterface({
|
|
100
|
-
input: process.stdin,
|
|
101
|
-
output: process.stdout,
|
|
102
|
-
prompt: PROMPT,
|
|
103
|
-
terminal: true,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
rl.prompt();
|
|
107
|
-
|
|
108
|
-
rl.on("line", async (input) => {
|
|
109
|
-
const trimmed = input.trim();
|
|
110
|
-
|
|
111
|
-
if (!trimmed) {
|
|
112
|
-
rl.prompt();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (trimmed === "exit" || trimmed === "quit") {
|
|
117
|
-
process.stdout.write(
|
|
118
|
-
" " + chalk.cyanBright("◈") + chalk.dim(" goodbye") + "\n"
|
|
119
|
-
);
|
|
120
|
-
process.exit(0);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (trimmed === "clear") {
|
|
124
|
-
process.stdout.write("\x1b[2J\x1b[H");
|
|
125
|
-
for (const line of getBannerLines(bannerCfg)) {
|
|
126
|
-
process.stdout.write(line + "\n");
|
|
127
|
-
}
|
|
128
|
-
rl.prompt();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Dispatch to commander
|
|
133
|
-
const tokens = parseTokens(trimmed);
|
|
134
|
-
const prog = createProgram();
|
|
135
|
-
prog.exitOverride();
|
|
136
|
-
prog.configureOutput({
|
|
137
|
-
writeOut: (str) => process.stdout.write(str),
|
|
138
|
-
writeErr: (str) => process.stderr.write(str),
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
143
|
-
} catch (err) {
|
|
144
|
-
const e = err as { code?: string; message?: string };
|
|
145
|
-
if (
|
|
146
|
-
e.code === "commander.helpDisplayed" ||
|
|
147
|
-
e.code === "commander.version" ||
|
|
148
|
-
e.code === "commander.executeSubCommandAsync"
|
|
149
|
-
) {
|
|
150
|
-
// already written
|
|
151
|
-
} else if (e.code === "commander.unknownCommand") {
|
|
152
|
-
process.stdout.write(
|
|
153
|
-
`\n ${c.failure} ${chalk.red(`Unknown command: ${chalk.white(tokens[0])}`)} \n`
|
|
154
|
-
);
|
|
155
|
-
process.stdout.write(chalk.dim(" Type 'help' for available commands\n"));
|
|
156
|
-
} else {
|
|
157
|
-
process.stdout.write(
|
|
158
|
-
`\n ${c.failure} ${chalk.red(e.message ?? String(err))}\n`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
process.stdout.write("\n");
|
|
164
|
-
rl.prompt();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
rl.on("close", () => {
|
|
168
|
-
process.stdout.write(
|
|
169
|
-
"\n " + chalk.cyanBright("◈") + chalk.dim(" goodbye") + "\n"
|
|
170
|
-
);
|
|
171
|
-
process.exit(0);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Keep alive
|
|
175
|
-
await new Promise<never>(() => {
|
|
176
|
-
/* readline keeps event loop alive */
|
|
177
|
-
});
|
|
178
|
-
}
|
package/src/signing.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
|
-
|
|
3
|
-
export async function buildSigningUrl(
|
|
4
|
-
action: string,
|
|
5
|
-
params: Record<string, string>,
|
|
6
|
-
agentPrivateKey: string,
|
|
7
|
-
chainId: number
|
|
8
|
-
): Promise<string> {
|
|
9
|
-
const created = Math.floor(Date.now() / 1000).toString();
|
|
10
|
-
const nonce = params.nonce ?? "0";
|
|
11
|
-
const wallet = params.wallet ?? "";
|
|
12
|
-
const message = `${action}:${wallet}:${chainId}:${nonce}:${created}`;
|
|
13
|
-
|
|
14
|
-
const signer = new ethers.Wallet(agentPrivateKey);
|
|
15
|
-
const sig = await signer.signMessage(message);
|
|
16
|
-
|
|
17
|
-
const urlParams = new URLSearchParams({
|
|
18
|
-
action,
|
|
19
|
-
chain: chainId.toString(),
|
|
20
|
-
created,
|
|
21
|
-
nonce,
|
|
22
|
-
sig,
|
|
23
|
-
agentAddress: signer.address,
|
|
24
|
-
...params,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return `https://app.arc402.xyz/sign?${urlParams.toString()}`;
|
|
28
|
-
}
|
package/src/telegram-notify.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import * as https from "https";
|
|
2
|
-
|
|
3
|
-
/** Generic Telegram message sender. Fire-and-forget — swallows errors. */
|
|
4
|
-
export async function sendTelegramMessage(opts: {
|
|
5
|
-
botToken: string;
|
|
6
|
-
chatId: string;
|
|
7
|
-
threadId?: number;
|
|
8
|
-
text: string;
|
|
9
|
-
buttons?: { text: string; url?: string; callback_data?: string }[][];
|
|
10
|
-
}): Promise<void> {
|
|
11
|
-
const body: Record<string, unknown> = {
|
|
12
|
-
chat_id: opts.chatId,
|
|
13
|
-
text: opts.text,
|
|
14
|
-
};
|
|
15
|
-
if (opts.threadId !== undefined) body.message_thread_id = opts.threadId;
|
|
16
|
-
if (opts.buttons && opts.buttons.length > 0) {
|
|
17
|
-
body.reply_markup = { inline_keyboard: opts.buttons };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const payload = JSON.stringify(body);
|
|
21
|
-
await new Promise<void>((resolve) => {
|
|
22
|
-
try {
|
|
23
|
-
const req = https.request(
|
|
24
|
-
{
|
|
25
|
-
hostname: "api.telegram.org",
|
|
26
|
-
path: `/bot${opts.botToken}/sendMessage`,
|
|
27
|
-
method: "POST",
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
"Content-Length": Buffer.byteLength(payload),
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
(res) => { res.resume(); resolve(); }
|
|
34
|
-
);
|
|
35
|
-
req.on("error", () => resolve());
|
|
36
|
-
req.write(payload);
|
|
37
|
-
req.end();
|
|
38
|
-
} catch {
|
|
39
|
-
resolve();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function sendWalletConnectApprovalButton(opts: {
|
|
45
|
-
botToken: string;
|
|
46
|
-
chatId: string;
|
|
47
|
-
threadId?: number;
|
|
48
|
-
prompt: string;
|
|
49
|
-
walletLinks: { label: string; url: string }[];
|
|
50
|
-
}): Promise<void> {
|
|
51
|
-
const body: Record<string, unknown> = {
|
|
52
|
-
chat_id: opts.chatId,
|
|
53
|
-
text: opts.prompt,
|
|
54
|
-
reply_markup: {
|
|
55
|
-
inline_keyboard: [opts.walletLinks.map((link) => ({ text: link.label, url: link.url }))],
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
if (opts.threadId !== undefined) {
|
|
59
|
-
body.message_thread_id = opts.threadId;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const payload = JSON.stringify(body);
|
|
63
|
-
|
|
64
|
-
await new Promise<void>((resolve) => {
|
|
65
|
-
try {
|
|
66
|
-
const req = https.request(
|
|
67
|
-
{
|
|
68
|
-
hostname: "api.telegram.org",
|
|
69
|
-
path: `/bot${opts.botToken}/sendMessage`,
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: {
|
|
72
|
-
"Content-Type": "application/json",
|
|
73
|
-
"Content-Length": Buffer.byteLength(payload),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
(res) => {
|
|
77
|
-
res.resume(); // drain response body
|
|
78
|
-
resolve();
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
req.on("error", () => resolve());
|
|
82
|
-
req.write(payload);
|
|
83
|
-
req.end();
|
|
84
|
-
} catch {
|
|
85
|
-
resolve();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|