@onecraft/wallet 0.0.0-stage → 0.1.145
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/.claude-plugin/marketplace.json +20 -0
- package/.openclaw/AGENTS.md +100 -0
- package/.openclaw/extensions/agent-wallet/README.md +195 -0
- package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
- package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
- package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
- package/.openclaw/extensions/agent-wallet/package.json +49 -0
- package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
- package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
- package/CHANGELOG.md +1232 -0
- package/LICENSE +104 -0
- package/README.md +193 -2
- package/VERSION +1 -0
- package/agent-wallet/.env.example +63 -0
- package/agent-wallet/AGENTS.md +130 -0
- package/agent-wallet/CARD_VAULT.md +640 -0
- package/agent-wallet/README.md +615 -0
- package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
- package/agent-wallet/agent_wallet/__init__.py +16 -0
- package/agent-wallet/agent_wallet/approval.py +165 -0
- package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
- package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
- package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
- package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
- package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
- package/agent-wallet/agent_wallet/bootstrap.py +194 -0
- package/agent-wallet/agent_wallet/card_catalog.py +243 -0
- package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
- package/agent-wallet/agent_wallet/card_vault.py +331 -0
- package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
- package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
- package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
- package/agent-wallet/agent_wallet/config.py +719 -0
- package/agent-wallet/agent_wallet/connector_cli.py +198 -0
- package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
- package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
- package/agent-wallet/agent_wallet/connectors/client.py +308 -0
- package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
- package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
- package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
- package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
- package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
- package/agent-wallet/agent_wallet/exceptions.py +10 -0
- package/agent-wallet/agent_wallet/file_ops.py +34 -0
- package/agent-wallet/agent_wallet/http_client.py +25 -0
- package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
- package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
- package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
- package/agent-wallet/agent_wallet/keystore.py +503 -0
- package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
- package/agent-wallet/agent_wallet/models.py +66 -0
- package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
- package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
- package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
- package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
- package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
- package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
- package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
- package/agent-wallet/agent_wallet/providers/bags.py +202 -0
- package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
- package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
- package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
- package/agent-wallet/agent_wallet/providers/imd.py +720 -0
- package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
- package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
- package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
- package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
- package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
- package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
- package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
- package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
- package/agent-wallet/agent_wallet/solana_stake.py +103 -0
- package/agent-wallet/agent_wallet/solana_tx.py +93 -0
- package/agent-wallet/agent_wallet/spending_limits.py +119 -0
- package/agent-wallet/agent_wallet/telemetry.py +481 -0
- package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
- package/agent-wallet/agent_wallet/update_check.py +190 -0
- package/agent-wallet/agent_wallet/user_wallets.py +573 -0
- package/agent-wallet/agent_wallet/validation.py +31 -0
- package/agent-wallet/agent_wallet/vault_executor.py +456 -0
- package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
- package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
- package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
- package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
- package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
- package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
- package/agent-wallet/examples/bootstrap_wallet.py +21 -0
- package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
- package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
- package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
- package/agent-wallet/openclaw.plugin.json +118 -0
- package/agent-wallet/pyproject.toml +36 -0
- package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
- package/agent-wallet/scripts/build_release_bundle.py +210 -0
- package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
- package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
- package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
- package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
- package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
- package/agent-wallet/scripts/security_utils.py +37 -0
- package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
- package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
- package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
- package/bin/lib/boot-key.mjs +184 -0
- package/bin/lib/evm-daemon.mjs +389 -0
- package/bin/lib/host-detection.mjs +259 -0
- package/bin/lib/integrations.mjs +578 -0
- package/bin/lib/release-python.mjs +9 -0
- package/bin/lib/update-transaction.mjs +235 -0
- package/bin/openclaw-agent-wallet.mjs +3354 -0
- package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
- package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
- package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
- package/claude-code/plugins/agent-wallet/README.md +134 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
- package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
- package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
- package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
- package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
- package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
- package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
- package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
- package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
- package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
- package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
- package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
- package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
- package/codex/plugins/agent-wallet/.mcp.json +15 -0
- package/codex/plugins/agent-wallet/README.md +158 -0
- package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
- package/codex/plugins/agent-wallet/server.py +1797 -0
- package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
- package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
- package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
- package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
- package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
- package/connectors/AGENTS.md +37 -0
- package/connectors/DEVELOPER_GUIDE.md +131 -0
- package/connectors/README.md +139 -0
- package/connectors/READ_ONLY_BETA.md +54 -0
- package/connectors/RELEASING.md +48 -0
- package/connectors/conformance/README.md +31 -0
- package/connectors/conformance/package.json +54 -0
- package/connectors/conformance/scripts/sync-license.mjs +3 -0
- package/connectors/conformance/scripts/sync-spec.mjs +16 -0
- package/connectors/conformance/src/cli.ts +43 -0
- package/connectors/conformance/src/index.ts +7 -0
- package/connectors/conformance/src/runner.ts +314 -0
- package/connectors/conformance/src/types.ts +27 -0
- package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
- package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
- package/connectors/conformance/test/runner.test.mjs +151 -0
- package/connectors/conformance/tsconfig.json +17 -0
- package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
- package/connectors/examples/reference-crypto-data/README.md +51 -0
- package/connectors/examples/reference-crypto-data/conformance.json +11 -0
- package/connectors/examples/reference-crypto-data/connector.json +95 -0
- package/connectors/examples/reference-crypto-data/package.json +21 -0
- package/connectors/examples/reference-crypto-data/railway.toml +9 -0
- package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
- package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
- package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
- package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
- package/connectors/package-lock.json +561 -0
- package/connectors/package.json +19 -0
- package/connectors/scripts/smoke-packed-packages.mjs +121 -0
- package/connectors/sdk-typescript/README.md +47 -0
- package/connectors/sdk-typescript/package.json +49 -0
- package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
- package/connectors/sdk-typescript/src/connector.ts +204 -0
- package/connectors/sdk-typescript/src/errors.ts +11 -0
- package/connectors/sdk-typescript/src/http.ts +116 -0
- package/connectors/sdk-typescript/src/index.ts +26 -0
- package/connectors/sdk-typescript/src/types.ts +101 -0
- package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
- package/connectors/sdk-typescript/tsconfig.json +21 -0
- package/connectors/spec/connector-manifest.schema.json +340 -0
- package/connectors/spec/connector-protocol.md +159 -0
- package/connectors/spec/transaction-intent.schema.json +281 -0
- package/connectors/templates/read-only/.env.example +1 -0
- package/connectors/templates/read-only/Dockerfile +11 -0
- package/connectors/templates/read-only/README.md +33 -0
- package/connectors/templates/read-only/conformance.json +11 -0
- package/connectors/templates/read-only/connector.json +64 -0
- package/connectors/templates/read-only/package.json +21 -0
- package/connectors/templates/read-only/railway.toml +9 -0
- package/connectors/templates/read-only/src/connector.ts +61 -0
- package/connectors/templates/read-only/src/server.ts +14 -0
- package/connectors/templates/read-only/test/connector.test.mjs +62 -0
- package/connectors/templates/read-only/tsconfig.json +17 -0
- package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
- package/cursor/plugins/agent-wallet/README.md +62 -0
- package/cursor/plugins/agent-wallet/mcp.json +16 -0
- package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
- package/cursor/plugins/agent-wallet/server.py +33 -0
- package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
- package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
- package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
- package/hermes/plugins/agent_wallet/README.md +54 -0
- package/hermes/plugins/agent_wallet/__init__.py +55 -0
- package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
- package/hermes/plugins/agent_wallet/schemas.py +211 -0
- package/hermes/plugins/agent_wallet/tools.py +622 -0
- package/install-from-github.sh +139 -0
- package/integrations/hedera/treasury-guard/README.md +92 -0
- package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
- package/integrations/hedera/treasury-guard/package-lock.json +880 -0
- package/integrations/hedera/treasury-guard/package.json +8 -0
- package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
- package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
- package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
- package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
- package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
- package/mcp/README.md +39 -0
- package/mcp/scripts/run_mcp.sh +37 -0
- package/mcp/server.py +33 -0
- package/package.json +106 -4
- package/scripts/check_release_version.mjs +72 -0
- package/scripts/version_targets.mjs +60 -0
- package/setup.sh +87 -0
- package/wdk-evm-wallet/.env.example +38 -0
- package/wdk-evm-wallet/README.md +254 -0
- package/wdk-evm-wallet/bootstrap.sh +8 -0
- package/wdk-evm-wallet/package-lock.json +2359 -0
- package/wdk-evm-wallet/package.json +43 -0
- package/wdk-evm-wallet/run-local.sh +12 -0
- package/wdk-evm-wallet/src/config.js +461 -0
- package/wdk-evm-wallet/src/imd.js +231 -0
- package/wdk-evm-wallet/src/json.js +35 -0
- package/wdk-evm-wallet/src/local_vault.js +407 -0
- package/wdk-evm-wallet/src/network_state.js +96 -0
- package/wdk-evm-wallet/src/pending_transactions.js +148 -0
- package/wdk-evm-wallet/src/server.js +849 -0
- package/wdk-evm-wallet/src/shutdown.js +63 -0
- package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
// Best-effort stop of the wdk-evm-wallet daemon that belongs to the wallet
|
|
2
|
+
// home being updated. The installer never trusts /health alone: the reported
|
|
3
|
+
// PID must also own the local listening socket and run from a wdk-evm-wallet
|
|
4
|
+
// working directory. Every failure is advisory and leaves the process alone.
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import http from "node:http";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const DEFAULT_SERVICE_URL = "http://127.0.0.1:8081";
|
|
13
|
+
const STOP_TIMEOUT_MS = 10000;
|
|
14
|
+
const KILL_TIMEOUT_MS = 5000;
|
|
15
|
+
const LOCAL_HOSTS = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
16
|
+
|
|
17
|
+
function healthUrl(serviceUrl) {
|
|
18
|
+
return `${String(serviceUrl).replace(/\/+$/, "")}/health`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function expandHome(value, env = process.env) {
|
|
22
|
+
const raw = String(value || "").trim();
|
|
23
|
+
const home = String(env.HOME || os.homedir()).trim() || os.homedir();
|
|
24
|
+
if (raw === "~") return home;
|
|
25
|
+
if (raw.startsWith("~/")) return path.join(home, raw.slice(2));
|
|
26
|
+
return raw;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function daemonTakeoverDisabled(env = process.env) {
|
|
30
|
+
return ["1", "true", "yes", "on"].includes(
|
|
31
|
+
String(env.OPENCLAW_EVM_DISABLE_DAEMON_TAKEOVER || "").trim().toLowerCase(),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isLoopbackServiceUrl(serviceUrl) {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = new URL(serviceUrl);
|
|
38
|
+
return parsed.protocol === "http:" && LOCAL_HOSTS.has(parsed.hostname);
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function expectedDataDirFor(env = process.env) {
|
|
45
|
+
const configured = String(env.WDK_EVM_DATA_DIR || "").trim();
|
|
46
|
+
if (configured) return path.resolve(expandHome(configured, env));
|
|
47
|
+
const home = expandHome(env.OPENCLAW_HOME || path.join(env.HOME || os.homedir(), ".openclaw"), env);
|
|
48
|
+
return path.resolve(home, "wdk-evm-wallet");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function samePath(left, right) {
|
|
52
|
+
if (!left || !right) return false;
|
|
53
|
+
try {
|
|
54
|
+
return path.resolve(expandHome(left)) === path.resolve(expandHome(right));
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readJsonFile(pathname) {
|
|
61
|
+
try {
|
|
62
|
+
return { present: true, valid: true, value: JSON.parse(fs.readFileSync(pathname, "utf8")) };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error?.code === "ENOENT") return { present: false, valid: true, value: null };
|
|
65
|
+
return { present: true, valid: false, value: null };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readServiceOwner(dataDir) {
|
|
70
|
+
return readJsonFile(path.join(dataDir, "service-owner.json"));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Daemons stopped writing service-owner.json when the transport moved to a
|
|
74
|
+
// unix socket, so an upgraded home can keep a record naming a process that
|
|
75
|
+
// exited long ago. A record whose pid no longer exists cannot own anything;
|
|
76
|
+
// treating it as present would block the graceful stop forever. Drop it so
|
|
77
|
+
// the strictly verified SIGTERM path applies. A live pid (including a reused
|
|
78
|
+
// one) is kept as-is and still fails closed on mismatch, and SIGKILL still
|
|
79
|
+
// requires a present, matching record.
|
|
80
|
+
export function discardDeadServiceOwner(ownerState, isAlive = processExists) {
|
|
81
|
+
if (!ownerState?.present || !ownerState.valid) return ownerState;
|
|
82
|
+
const pid = Number(ownerState.value?.pid);
|
|
83
|
+
if (!Number.isInteger(pid) || pid <= 0 || isAlive(pid)) return ownerState;
|
|
84
|
+
return { present: false, valid: true, value: null };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function runLsof(args, env = process.env) {
|
|
88
|
+
const result = spawnSync("lsof", args, {
|
|
89
|
+
encoding: "utf8",
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
env,
|
|
92
|
+
});
|
|
93
|
+
if (result.error) return null;
|
|
94
|
+
// lsof uses status 1 when no rows match. That is a valid empty result.
|
|
95
|
+
if (![0, 1].includes(result.status)) return null;
|
|
96
|
+
return String(result.stdout || "");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function parsePids(raw) {
|
|
100
|
+
return [...new Set(
|
|
101
|
+
String(raw || "")
|
|
102
|
+
.split(/\s+/)
|
|
103
|
+
.filter((token) => /^\d+$/.test(token))
|
|
104
|
+
.map((token) => Number(token))
|
|
105
|
+
.filter((pid) => Number.isInteger(pid) && pid > 0),
|
|
106
|
+
)];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function inspectDaemonProcess(pid, port, env = process.env) {
|
|
110
|
+
const listenerOutput = runLsof(
|
|
111
|
+
["-nP", "-t", "-iTCP:" + String(port), "-sTCP:LISTEN"],
|
|
112
|
+
env,
|
|
113
|
+
);
|
|
114
|
+
const cwdOutput = runLsof(["-a", "-p", String(pid), "-d", "cwd", "-Fn"], env);
|
|
115
|
+
if (listenerOutput === null || cwdOutput === null) {
|
|
116
|
+
return { available: false, listenerPids: [], cwd: "" };
|
|
117
|
+
}
|
|
118
|
+
const cwd = cwdOutput
|
|
119
|
+
.split(/\r?\n/)
|
|
120
|
+
.find((line) => line.startsWith("n"))
|
|
121
|
+
?.slice(1)
|
|
122
|
+
.trim() || "";
|
|
123
|
+
return {
|
|
124
|
+
available: true,
|
|
125
|
+
listenerPids: parsePids(listenerOutput),
|
|
126
|
+
cwd,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function cwdLooksLikeEvmDaemon(cwd) {
|
|
131
|
+
if (!cwd) return false;
|
|
132
|
+
try {
|
|
133
|
+
return path.basename(path.resolve(cwd)) === "wdk-evm-wallet";
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function ownerMatches({ ownerState, health, pid, port, expectedDataDir }) {
|
|
140
|
+
if (!ownerState.valid) return false;
|
|
141
|
+
if (!ownerState.present) return true;
|
|
142
|
+
const owner = ownerState.value;
|
|
143
|
+
if (!owner || typeof owner !== "object") return false;
|
|
144
|
+
return (
|
|
145
|
+
Number(owner.pid) === pid &&
|
|
146
|
+
Number(owner.port) === port &&
|
|
147
|
+
samePath(owner.data_dir, expectedDataDir) &&
|
|
148
|
+
String(owner.instance_id || "") === String(health.instanceId || "")
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function classifyDaemonHealth(
|
|
153
|
+
health,
|
|
154
|
+
{
|
|
155
|
+
expectedDataDir,
|
|
156
|
+
port,
|
|
157
|
+
inspection = { available: false, listenerPids: [], cwd: "" },
|
|
158
|
+
ownerState = { present: false, valid: true, value: null },
|
|
159
|
+
} = {},
|
|
160
|
+
) {
|
|
161
|
+
if (!health || typeof health !== "object") {
|
|
162
|
+
return { stoppable: false, reason: "not_running", pid: 0 };
|
|
163
|
+
}
|
|
164
|
+
if (health.service !== "wdk-evm-wallet") {
|
|
165
|
+
return { stoppable: false, reason: "foreign_service", pid: 0 };
|
|
166
|
+
}
|
|
167
|
+
const reportedDataDir = String(health.dataDir || "").trim();
|
|
168
|
+
if (!reportedDataDir || !samePath(reportedDataDir, expectedDataDir)) {
|
|
169
|
+
return { stoppable: false, reason: "foreign_vault", pid: 0 };
|
|
170
|
+
}
|
|
171
|
+
const pid = typeof health.pid === "number" ? health.pid : Number.NaN;
|
|
172
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
173
|
+
return { stoppable: false, reason: "no_pid", pid: 0 };
|
|
174
|
+
}
|
|
175
|
+
if (!inspection.available) {
|
|
176
|
+
return { stoppable: false, reason: "process_inspection_unavailable", pid };
|
|
177
|
+
}
|
|
178
|
+
if (!inspection.listenerPids.includes(pid)) {
|
|
179
|
+
return { stoppable: false, reason: "pid_not_listener", pid };
|
|
180
|
+
}
|
|
181
|
+
if (!cwdLooksLikeEvmDaemon(inspection.cwd)) {
|
|
182
|
+
return { stoppable: false, reason: "foreign_process", pid };
|
|
183
|
+
}
|
|
184
|
+
if (!ownerMatches({ ownerState, health, pid, port, expectedDataDir })) {
|
|
185
|
+
return { stoppable: false, reason: "owner_mismatch", pid };
|
|
186
|
+
}
|
|
187
|
+
return { stoppable: true, reason: "stoppable", pid };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function readDaemonHealth(serviceUrl, timeoutMs = 1500) {
|
|
191
|
+
return new Promise((resolve) => {
|
|
192
|
+
let settled = false;
|
|
193
|
+
const done = (value) => {
|
|
194
|
+
if (!settled) {
|
|
195
|
+
settled = true;
|
|
196
|
+
resolve(value);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const request = http.get(healthUrl(serviceUrl), { timeout: timeoutMs }, (response) => {
|
|
200
|
+
if (response.statusCode !== 200) {
|
|
201
|
+
response.resume();
|
|
202
|
+
done(null);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
let raw = "";
|
|
206
|
+
response.setEncoding("utf8");
|
|
207
|
+
response.on("data", (chunk) => {
|
|
208
|
+
raw += chunk;
|
|
209
|
+
});
|
|
210
|
+
response.on("end", () => {
|
|
211
|
+
try {
|
|
212
|
+
done(JSON.parse(raw));
|
|
213
|
+
} catch {
|
|
214
|
+
done(null);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
request.on("timeout", () => {
|
|
219
|
+
request.destroy();
|
|
220
|
+
done(null);
|
|
221
|
+
});
|
|
222
|
+
request.on("error", () => done(null));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function processExists(pid) {
|
|
227
|
+
try {
|
|
228
|
+
process.kill(pid, 0);
|
|
229
|
+
return true;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return error?.code !== "ESRCH";
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function processIsSignalable(pid) {
|
|
236
|
+
try {
|
|
237
|
+
process.kill(pid, 0);
|
|
238
|
+
return true;
|
|
239
|
+
} catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function processStillMatches(pid, port, expectedDataDir, ownerState, env) {
|
|
245
|
+
const inspection = inspectDaemonProcess(pid, port, env);
|
|
246
|
+
if (
|
|
247
|
+
!inspection.available ||
|
|
248
|
+
!inspection.listenerPids.includes(pid) ||
|
|
249
|
+
!cwdLooksLikeEvmDaemon(inspection.cwd)
|
|
250
|
+
) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (!ownerState.valid || !ownerState.present) return false;
|
|
254
|
+
const owner = ownerState.value;
|
|
255
|
+
return (
|
|
256
|
+
Number(owner?.pid) === pid &&
|
|
257
|
+
Number(owner?.port) === port &&
|
|
258
|
+
samePath(owner?.data_dir, expectedDataDir)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
263
|
+
|
|
264
|
+
async function waitForExit(pid, timeoutMs) {
|
|
265
|
+
const deadline = Date.now() + timeoutMs;
|
|
266
|
+
while (Date.now() < deadline) {
|
|
267
|
+
if (!processExists(pid)) return true;
|
|
268
|
+
await sleep(300);
|
|
269
|
+
}
|
|
270
|
+
return !processExists(pid);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function stopLocalEvmDaemon({ serviceUrl, env = process.env } = {}) {
|
|
274
|
+
if (daemonTakeoverDisabled(env)) {
|
|
275
|
+
return { attempted: false, stopped: false, reason: "takeover_disabled", pid: 0 };
|
|
276
|
+
}
|
|
277
|
+
const url =
|
|
278
|
+
String(env.WDK_EVM_SERVICE_URL || serviceUrl || DEFAULT_SERVICE_URL).trim() ||
|
|
279
|
+
DEFAULT_SERVICE_URL;
|
|
280
|
+
if (!isLoopbackServiceUrl(url)) {
|
|
281
|
+
return { attempted: false, stopped: false, reason: "non_local_service_url", pid: 0 };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const parsed = new URL(url);
|
|
285
|
+
const port = Number(parsed.port || 80);
|
|
286
|
+
const expectedDataDir = expectedDataDirFor(env);
|
|
287
|
+
const health = await readDaemonHealth(url);
|
|
288
|
+
const reportedPid = Number(health?.pid || 0);
|
|
289
|
+
const inspection =
|
|
290
|
+
Number.isInteger(reportedPid) && reportedPid > 0
|
|
291
|
+
? inspectDaemonProcess(reportedPid, port, env)
|
|
292
|
+
: { available: false, listenerPids: [], cwd: "" };
|
|
293
|
+
const ownerState = discardDeadServiceOwner(readServiceOwner(expectedDataDir));
|
|
294
|
+
const verdict = classifyDaemonHealth(health, {
|
|
295
|
+
expectedDataDir,
|
|
296
|
+
port,
|
|
297
|
+
inspection,
|
|
298
|
+
ownerState,
|
|
299
|
+
});
|
|
300
|
+
if (!verdict.stoppable) {
|
|
301
|
+
return { attempted: false, stopped: false, reason: verdict.reason, pid: verdict.pid };
|
|
302
|
+
}
|
|
303
|
+
if (!processIsSignalable(verdict.pid)) {
|
|
304
|
+
return { attempted: false, stopped: false, reason: "pid_not_signalable", pid: verdict.pid };
|
|
305
|
+
}
|
|
306
|
+
// Close the remaining PID-reuse window as much as portable macOS/Linux APIs
|
|
307
|
+
// allow by rechecking the listener immediately before the signal.
|
|
308
|
+
const finalInspection = inspectDaemonProcess(verdict.pid, port, env);
|
|
309
|
+
if (
|
|
310
|
+
!finalInspection.available ||
|
|
311
|
+
!finalInspection.listenerPids.includes(verdict.pid) ||
|
|
312
|
+
!cwdLooksLikeEvmDaemon(finalInspection.cwd)
|
|
313
|
+
) {
|
|
314
|
+
return { attempted: false, stopped: false, reason: "identity_changed", pid: verdict.pid };
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
process.kill(verdict.pid, "SIGTERM");
|
|
318
|
+
} catch (error) {
|
|
319
|
+
return {
|
|
320
|
+
attempted: true,
|
|
321
|
+
stopped: false,
|
|
322
|
+
reason: `signal_failed:${error?.code || "unknown"}`,
|
|
323
|
+
pid: verdict.pid,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
if (await waitForExit(verdict.pid, STOP_TIMEOUT_MS)) {
|
|
327
|
+
return { attempted: true, stopped: true, reason: "stopped", pid: verdict.pid };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// A hard stop is only allowed when the exact same owned process still owns
|
|
331
|
+
// the socket. Missing owner evidence or any identity change fails closed.
|
|
332
|
+
if (!processStillMatches(verdict.pid, port, expectedDataDir, ownerState, env)) {
|
|
333
|
+
return { attempted: true, stopped: false, reason: "still_running_unverified", pid: verdict.pid };
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
process.kill(verdict.pid, "SIGKILL");
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error?.code !== "ESRCH") {
|
|
339
|
+
return {
|
|
340
|
+
attempted: true,
|
|
341
|
+
stopped: false,
|
|
342
|
+
reason: `kill_failed:${error?.code || "unknown"}`,
|
|
343
|
+
pid: verdict.pid,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const stopped = await waitForExit(verdict.pid, KILL_TIMEOUT_MS);
|
|
348
|
+
return {
|
|
349
|
+
attempted: true,
|
|
350
|
+
stopped,
|
|
351
|
+
reason: stopped ? "killed" : "still_running",
|
|
352
|
+
pid: verdict.pid,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// The install and rollback paths are synchronous. Run the bounded async stop
|
|
357
|
+
// worker in a short-lived subprocess rather than making the CLI lifecycle async.
|
|
358
|
+
export function stopLocalEvmDaemonSync({ env = process.env } = {}) {
|
|
359
|
+
const fallback = { attempted: false, stopped: false, reason: "subprocess_failed", pid: 0 };
|
|
360
|
+
try {
|
|
361
|
+
const result = spawnSync(process.execPath, [fileURLToPath(import.meta.url), "--stop"], {
|
|
362
|
+
encoding: "utf8",
|
|
363
|
+
timeout: STOP_TIMEOUT_MS + KILL_TIMEOUT_MS + 5000,
|
|
364
|
+
env,
|
|
365
|
+
});
|
|
366
|
+
if (result.status !== 0 || !result.stdout) return fallback;
|
|
367
|
+
return JSON.parse(result.stdout.trim());
|
|
368
|
+
} catch {
|
|
369
|
+
return fallback;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (
|
|
374
|
+
process.argv[1] &&
|
|
375
|
+
fileURLToPath(import.meta.url) === process.argv[1] &&
|
|
376
|
+
process.argv.includes("--stop")
|
|
377
|
+
) {
|
|
378
|
+
stopLocalEvmDaemon()
|
|
379
|
+
.then((result) => {
|
|
380
|
+
process.stdout.write(JSON.stringify(result));
|
|
381
|
+
process.exit(0);
|
|
382
|
+
})
|
|
383
|
+
.catch(() => {
|
|
384
|
+
process.stdout.write(
|
|
385
|
+
JSON.stringify({ attempted: false, stopped: false, reason: "worker_failed", pid: 0 }),
|
|
386
|
+
);
|
|
387
|
+
process.exit(0);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export const HOST_NAMES = Object.freeze([
|
|
6
|
+
"openclaw",
|
|
7
|
+
"codex",
|
|
8
|
+
"cursor",
|
|
9
|
+
"claude-code",
|
|
10
|
+
"hermes",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const AUTO_ENROLL_ON_EXISTING_RUNTIME = Object.freeze(["cursor"]);
|
|
14
|
+
|
|
15
|
+
const HOST_ALIASES = Object.freeze({
|
|
16
|
+
openclaw: "openclaw",
|
|
17
|
+
codex: "codex",
|
|
18
|
+
cursor: "cursor",
|
|
19
|
+
claude: "claude-code",
|
|
20
|
+
"claude-code": "claude-code",
|
|
21
|
+
claudecode: "claude-code",
|
|
22
|
+
hermes: "hermes",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function expandHome(value, env) {
|
|
26
|
+
const home = env.HOME || os.homedir();
|
|
27
|
+
if (value === "~") return home;
|
|
28
|
+
if (value.startsWith("~/")) return path.join(home, value.slice(2));
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function existingEvidence(candidates, exists = fs.existsSync) {
|
|
33
|
+
return candidates.filter((candidate) => {
|
|
34
|
+
try {
|
|
35
|
+
return exists(candidate);
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function detectedHost(name, displayName, binary, configCandidates, commandPath, exists) {
|
|
43
|
+
const binaryPath = commandPath(binary);
|
|
44
|
+
const configPaths = existingEvidence(configCandidates, exists);
|
|
45
|
+
const evidence = [
|
|
46
|
+
...(binaryPath ? [{ type: "cli", path: binaryPath }] : []),
|
|
47
|
+
...configPaths.map((configPath) => ({ type: "config", path: configPath })),
|
|
48
|
+
];
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
display_name: displayName,
|
|
52
|
+
detected: evidence.length > 0,
|
|
53
|
+
confidence: evidence.length > 0 ? "high" : "none",
|
|
54
|
+
evidence,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function detectHosts({
|
|
59
|
+
env = process.env,
|
|
60
|
+
commandPath,
|
|
61
|
+
exists = fs.existsSync,
|
|
62
|
+
} = {}) {
|
|
63
|
+
if (typeof commandPath !== "function") {
|
|
64
|
+
throw new TypeError("detectHosts requires commandPath(name)");
|
|
65
|
+
}
|
|
66
|
+
const home = env.HOME || os.homedir();
|
|
67
|
+
const openclawHome = path.resolve(expandHome(env.OPENCLAW_HOME || "~/.openclaw", env));
|
|
68
|
+
const codexHome = path.resolve(expandHome(env.CODEX_HOME || "~/.codex", env));
|
|
69
|
+
const cursorHome = path.resolve(expandHome(env.CURSOR_HOME || "~/.cursor", env));
|
|
70
|
+
const hermesHome = path.resolve(expandHome(env.HERMES_HOME || "~/.hermes", env));
|
|
71
|
+
const claudeHome = path.resolve(expandHome(env.CLAUDE_CONFIG_DIR || "~/.claude", env));
|
|
72
|
+
|
|
73
|
+
return [
|
|
74
|
+
detectedHost(
|
|
75
|
+
"openclaw",
|
|
76
|
+
"OpenClaw",
|
|
77
|
+
"openclaw",
|
|
78
|
+
[path.join(openclawHome, "openclaw.json")],
|
|
79
|
+
commandPath,
|
|
80
|
+
exists,
|
|
81
|
+
),
|
|
82
|
+
detectedHost(
|
|
83
|
+
"codex",
|
|
84
|
+
"Codex",
|
|
85
|
+
"codex",
|
|
86
|
+
[path.join(codexHome, "config.toml")],
|
|
87
|
+
commandPath,
|
|
88
|
+
exists,
|
|
89
|
+
),
|
|
90
|
+
detectedHost(
|
|
91
|
+
"cursor",
|
|
92
|
+
"Cursor",
|
|
93
|
+
"cursor",
|
|
94
|
+
[
|
|
95
|
+
path.join(cursorHome, "mcp.json"),
|
|
96
|
+
path.join(cursorHome, "plugins", "local"),
|
|
97
|
+
path.join(home, "Library", "Application Support", "Cursor", "User", "settings.json"),
|
|
98
|
+
path.join(home, "Applications", "Cursor.app"),
|
|
99
|
+
path.join(home, ".local", "share", "applications", "cursor.desktop"),
|
|
100
|
+
...(env.LOCALAPPDATA ? [path.join(env.LOCALAPPDATA, "Programs", "Cursor", "Cursor.exe")] : []),
|
|
101
|
+
],
|
|
102
|
+
commandPath,
|
|
103
|
+
exists,
|
|
104
|
+
),
|
|
105
|
+
detectedHost(
|
|
106
|
+
"claude-code",
|
|
107
|
+
"Claude Code",
|
|
108
|
+
"claude",
|
|
109
|
+
[
|
|
110
|
+
path.join(claudeHome, "settings.json"),
|
|
111
|
+
path.join(home, ".claude.json"),
|
|
112
|
+
],
|
|
113
|
+
commandPath,
|
|
114
|
+
exists,
|
|
115
|
+
),
|
|
116
|
+
detectedHost(
|
|
117
|
+
"hermes",
|
|
118
|
+
"Hermes",
|
|
119
|
+
"hermes",
|
|
120
|
+
[
|
|
121
|
+
path.join(hermesHome, "config.yaml"),
|
|
122
|
+
path.join(hermesHome, "config.yml"),
|
|
123
|
+
path.join(hermesHome, "settings.json"),
|
|
124
|
+
],
|
|
125
|
+
commandPath,
|
|
126
|
+
exists,
|
|
127
|
+
),
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function flagValues(args, name) {
|
|
132
|
+
const values = [];
|
|
133
|
+
const prefix = `${name}=`;
|
|
134
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
135
|
+
const value = args[index];
|
|
136
|
+
if (value === name) {
|
|
137
|
+
const next = args[index + 1] || "";
|
|
138
|
+
if (!next || next.startsWith("--")) {
|
|
139
|
+
throw new Error(`${name} requires a value.`);
|
|
140
|
+
}
|
|
141
|
+
values.push(next);
|
|
142
|
+
index += 1;
|
|
143
|
+
} else if (value.startsWith(prefix)) {
|
|
144
|
+
values.push(value.slice(prefix.length));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return values;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function normalizeHostToken(value) {
|
|
151
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
152
|
+
return HOST_ALIASES[normalized] || normalized;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function parseHostSet(values, { detected, managed }) {
|
|
156
|
+
const selected = new Set();
|
|
157
|
+
for (const rawValue of values) {
|
|
158
|
+
for (const rawToken of String(rawValue).split(",")) {
|
|
159
|
+
const token = normalizeHostToken(rawToken);
|
|
160
|
+
if (!token) continue;
|
|
161
|
+
if (token === "none" || token === "runtime-only") {
|
|
162
|
+
selected.clear();
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (token === "all") {
|
|
166
|
+
HOST_NAMES.forEach((name) => selected.add(name));
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (token === "detected") {
|
|
170
|
+
detected.forEach((name) => selected.add(name));
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (token === "managed") {
|
|
174
|
+
managed.forEach((name) => selected.add(name));
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!HOST_NAMES.includes(token)) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`Unknown host '${rawToken}'. Expected: ${HOST_NAMES.join(", ")}, detected, managed, all, or none.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
selected.add(token);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return selected;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function buildInstallPlan({
|
|
189
|
+
args,
|
|
190
|
+
detections,
|
|
191
|
+
managedHosts = [],
|
|
192
|
+
runtimeInstalled,
|
|
193
|
+
}) {
|
|
194
|
+
const detected = detections.filter((entry) => entry.detected).map((entry) => entry.name);
|
|
195
|
+
const managed = managedHosts.filter((name) => HOST_NAMES.includes(name));
|
|
196
|
+
const hostValues = flagValues(args, "--hosts");
|
|
197
|
+
const explicitHosts = hostValues.length > 0;
|
|
198
|
+
const runtimeOnly = args.includes("--runtime-only");
|
|
199
|
+
const managedOnly = args.includes("--managed-only");
|
|
200
|
+
|
|
201
|
+
let selected;
|
|
202
|
+
let selectionReason;
|
|
203
|
+
if (runtimeOnly) {
|
|
204
|
+
selected = new Set();
|
|
205
|
+
selectionReason = "runtime_only";
|
|
206
|
+
} else if (managedOnly) {
|
|
207
|
+
selected = new Set(managed);
|
|
208
|
+
selectionReason = "managed_only";
|
|
209
|
+
} else if (explicitHosts) {
|
|
210
|
+
selected = parseHostSet(hostValues, { detected, managed });
|
|
211
|
+
selectionReason = "explicit";
|
|
212
|
+
} else if (runtimeInstalled) {
|
|
213
|
+
// Existing installs never enroll newly detected hosts, except ones added
|
|
214
|
+
// after the runtime shipped (e.g. Cursor) so current users pick them up.
|
|
215
|
+
const autoEnrolled = detected.filter((name) => AUTO_ENROLL_ON_EXISTING_RUNTIME.includes(name));
|
|
216
|
+
selected = new Set([...managed, ...autoEnrolled]);
|
|
217
|
+
selectionReason = "existing_runtime_managed_only";
|
|
218
|
+
} else {
|
|
219
|
+
selected = new Set(detected);
|
|
220
|
+
selectionReason = "fresh_install_detected";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const excluded = parseHostSet(flagValues(args, "--exclude"), { detected, managed });
|
|
224
|
+
excluded.forEach((name) => selected.delete(name));
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
schema_version: 1,
|
|
228
|
+
runtime_installed_before: Boolean(runtimeInstalled),
|
|
229
|
+
selection_reason: selectionReason,
|
|
230
|
+
explicit_hosts: explicitHosts,
|
|
231
|
+
detected_hosts: detected,
|
|
232
|
+
managed_hosts: managed,
|
|
233
|
+
selected_hosts: HOST_NAMES.filter((name) => selected.has(name)),
|
|
234
|
+
excluded_hosts: HOST_NAMES.filter((name) => excluded.has(name)),
|
|
235
|
+
detections,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function stripUniversalInstallerArgs(args) {
|
|
240
|
+
const output = [];
|
|
241
|
+
const valueFlags = new Set(["--hosts", "--exclude"]);
|
|
242
|
+
const booleanFlags = new Set([
|
|
243
|
+
"--runtime-only",
|
|
244
|
+
"--managed-only",
|
|
245
|
+
"--no-prompt",
|
|
246
|
+
"--json",
|
|
247
|
+
]);
|
|
248
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
249
|
+
const value = args[index];
|
|
250
|
+
if (booleanFlags.has(value)) continue;
|
|
251
|
+
if (valueFlags.has(value)) {
|
|
252
|
+
index += 1;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if ([...valueFlags].some((name) => value.startsWith(`${name}=`))) continue;
|
|
256
|
+
output.push(value);
|
|
257
|
+
}
|
|
258
|
+
return output;
|
|
259
|
+
}
|