arc402-cli 0.7.3 → 0.7.5
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/TUI-SPEC.md +214 -0
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/dist/repl.d.ts.map +1 -1
- package/dist/repl.js +46 -558
- package/dist/repl.js.map +1 -1
- package/dist/tui/App.d.ts +20 -0
- package/dist/tui/App.d.ts.map +1 -0
- package/dist/tui/App.js +166 -0
- package/dist/tui/App.js.map +1 -0
- package/dist/tui/Footer.d.ts +11 -0
- package/dist/tui/Footer.d.ts.map +1 -0
- package/dist/tui/Footer.js +13 -0
- package/dist/tui/Footer.js.map +1 -0
- package/dist/tui/Header.d.ts +15 -0
- package/dist/tui/Header.d.ts.map +1 -0
- package/dist/tui/Header.js +19 -0
- package/dist/tui/Header.js.map +1 -0
- package/dist/tui/InputLine.d.ts +11 -0
- package/dist/tui/InputLine.d.ts.map +1 -0
- package/dist/tui/InputLine.js +145 -0
- package/dist/tui/InputLine.js.map +1 -0
- package/dist/tui/Viewport.d.ts +13 -0
- package/dist/tui/Viewport.d.ts.map +1 -0
- package/dist/tui/Viewport.js +38 -0
- package/dist/tui/Viewport.js.map +1 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +55 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/useChat.d.ts +11 -0
- package/dist/tui/useChat.d.ts.map +1 -0
- package/dist/tui/useChat.js +91 -0
- package/dist/tui/useChat.js.map +1 -0
- package/dist/tui/useCommand.d.ts +17 -0
- package/dist/tui/useCommand.d.ts.map +1 -0
- package/dist/tui/useCommand.js +219 -0
- package/dist/tui/useCommand.js.map +1 -0
- package/dist/tui/useScroll.d.ts +17 -0
- package/dist/tui/useScroll.d.ts.map +1 -0
- package/dist/tui/useScroll.js +46 -0
- package/dist/tui/useScroll.js.map +1 -0
- package/package.json +5 -1
- package/src/index.ts +21 -1
- package/src/repl.ts +50 -663
- package/src/tui/App.tsx +240 -0
- package/src/tui/Footer.tsx +18 -0
- package/src/tui/Header.tsx +37 -0
- package/src/tui/InputLine.tsx +164 -0
- package/src/tui/Viewport.tsx +66 -0
- package/src/tui/index.tsx +72 -0
- package/src/tui/useChat.ts +103 -0
- package/src/tui/useCommand.ts +245 -0
- package/src/tui/useScroll.ts +65 -0
- package/tsconfig.json +6 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.launchTUI = launchTUI;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const ink_1 = require("ink");
|
|
9
|
+
const App_1 = require("./App");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
+
const pkg = require("../../package.json");
|
|
15
|
+
const CONFIG_PATH = path_1.default.join(os_1.default.homedir(), ".arc402", "config.json");
|
|
16
|
+
async function loadConfig() {
|
|
17
|
+
if (!fs_1.default.existsSync(CONFIG_PATH))
|
|
18
|
+
return {};
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(fs_1.default.readFileSync(CONFIG_PATH, "utf-8"));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function getBalance(rpcUrl, address) {
|
|
27
|
+
try {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
29
|
+
const ethersLib = require("ethers");
|
|
30
|
+
const provider = new ethersLib.ethers.JsonRpcProvider(rpcUrl);
|
|
31
|
+
const bal = await Promise.race([
|
|
32
|
+
provider.getBalance(address),
|
|
33
|
+
new Promise((_, r) => setTimeout(() => r(new Error("timeout")), 2000)),
|
|
34
|
+
]);
|
|
35
|
+
return `${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function launchTUI() {
|
|
42
|
+
const config = await loadConfig();
|
|
43
|
+
let walletDisplay;
|
|
44
|
+
if (config.walletContractAddress) {
|
|
45
|
+
const w = config.walletContractAddress;
|
|
46
|
+
walletDisplay = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
47
|
+
}
|
|
48
|
+
let balance;
|
|
49
|
+
if (config.rpcUrl && config.walletContractAddress) {
|
|
50
|
+
balance = await getBalance(config.rpcUrl, config.walletContractAddress);
|
|
51
|
+
}
|
|
52
|
+
const { waitUntilExit } = (0, ink_1.render)((0, jsx_runtime_1.jsx)(App_1.App, { version: pkg.version, network: config.network, wallet: walletDisplay, balance: balance }));
|
|
53
|
+
await waitUntilExit();
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tui/index.tsx"],"names":[],"mappings":";;;;;AA+CA,8BAwBC;;AAtED,6BAA6B;AAC7B,+BAA4B;AAC5B,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AAEpB,8DAA8D;AAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAwB,CAAC;AAEjE,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAQtE,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,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C;IACtD,CAAC;IAED,IAAI,OAA2B,CAAC;IAChC,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;QAClD,OAAO,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,EAAE,aAAa,EAAE,GAAG,IAAA,YAAM,EAC9B,uBAAC,SAAG,IACF,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,OAAO,GAChB,CACH,CAAC;IAEF,MAAM,aAAa,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface UseChatResult {
|
|
2
|
+
send: (message: string, onLine: (line: string) => void) => Promise<void>;
|
|
3
|
+
isSending: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Sends messages to the OpenClaw gateway and streams responses
|
|
7
|
+
* line-by-line into the viewport buffer via onLine callback.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useChat(): UseChatResult;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/tui/useChat.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACrB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,OAAO,IAAI,aAAa,CAyFvC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useChat = useChat;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const colors_1 = require("../ui/colors");
|
|
10
|
+
/**
|
|
11
|
+
* Sends messages to the OpenClaw gateway and streams responses
|
|
12
|
+
* line-by-line into the viewport buffer via onLine callback.
|
|
13
|
+
*/
|
|
14
|
+
function useChat() {
|
|
15
|
+
const [isSending, setIsSending] = (0, react_1.useState)(false);
|
|
16
|
+
const send = (0, react_1.useCallback)(async (message, onLine) => {
|
|
17
|
+
setIsSending(true);
|
|
18
|
+
const trimmed = message.trim().slice(0, 10000);
|
|
19
|
+
// Show thinking placeholder
|
|
20
|
+
onLine(chalk_1.default.dim(" ◈ ") + chalk_1.default.dim("thinking..."));
|
|
21
|
+
let res;
|
|
22
|
+
try {
|
|
23
|
+
res = await fetch("http://localhost:19000/api/agent", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: { "Content-Type": "application/json" },
|
|
26
|
+
body: JSON.stringify({ message: trimmed, session: "arc402-tui" }),
|
|
27
|
+
signal: AbortSignal.timeout(30000),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
32
|
+
const isDown = msg.includes("ECONNREFUSED") ||
|
|
33
|
+
msg.includes("fetch failed") ||
|
|
34
|
+
msg.includes("ENOTFOUND") ||
|
|
35
|
+
msg.includes("UND_ERR_SOCKET");
|
|
36
|
+
if (isDown) {
|
|
37
|
+
onLine(" " +
|
|
38
|
+
chalk_1.default.yellow("⚠") +
|
|
39
|
+
" " +
|
|
40
|
+
chalk_1.default.dim("OpenClaw gateway not running. Start with: ") +
|
|
41
|
+
chalk_1.default.white("openclaw gateway start"));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(msg)}`);
|
|
45
|
+
}
|
|
46
|
+
setIsSending(false);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!res.body) {
|
|
50
|
+
onLine(chalk_1.default.dim(" ◈ ") + chalk_1.default.white("(empty response)"));
|
|
51
|
+
setIsSending(false);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const flushLine = (line) => {
|
|
55
|
+
// Unwrap SSE data lines
|
|
56
|
+
if (line.startsWith("data: ")) {
|
|
57
|
+
line = line.slice(6);
|
|
58
|
+
if (line === "[DONE]")
|
|
59
|
+
return;
|
|
60
|
+
try {
|
|
61
|
+
const j = JSON.parse(line);
|
|
62
|
+
line = j.text ?? j.content ?? j.delta?.text ?? line;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
/* use raw */
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (line.trim()) {
|
|
69
|
+
onLine(chalk_1.default.dim(" ◈ ") + chalk_1.default.white(line));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const reader = res.body.getReader();
|
|
73
|
+
const decoder = new TextDecoder();
|
|
74
|
+
let buffer = "";
|
|
75
|
+
while (true) {
|
|
76
|
+
const { done, value } = await reader.read();
|
|
77
|
+
if (done)
|
|
78
|
+
break;
|
|
79
|
+
buffer += decoder.decode(value, { stream: true });
|
|
80
|
+
const lines = buffer.split("\n");
|
|
81
|
+
buffer = lines.pop() ?? "";
|
|
82
|
+
for (const line of lines)
|
|
83
|
+
flushLine(line);
|
|
84
|
+
}
|
|
85
|
+
if (buffer.trim())
|
|
86
|
+
flushLine(buffer);
|
|
87
|
+
setIsSending(false);
|
|
88
|
+
}, []);
|
|
89
|
+
return { send, isSending };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=useChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.js","sourceRoot":"","s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AChB,MAAM,CAAC,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,eAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAChB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAC3B,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,EAAE;YAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAErC,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface UseCommandResult {
|
|
2
|
+
execute: (input: string, onLine: (line: string) => void) => Promise<void>;
|
|
3
|
+
isRunning: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Dispatches parsed commands to the commander program.
|
|
7
|
+
*
|
|
8
|
+
* NON-INTERACTIVE commands: captures stdout/stderr by monkey-patching
|
|
9
|
+
* process.stdout.write and routes output to the viewport.
|
|
10
|
+
*
|
|
11
|
+
* INTERACTIVE commands (WalletConnect, prompts): spawns a child process
|
|
12
|
+
* running `arc402 <command>` with inherited stdin so that QR codes render
|
|
13
|
+
* and prompts accept input. Output is captured line-by-line into the viewport.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useCommand(): UseCommandResult;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=useCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommand.d.ts","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":"AAyCA,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAmB7C"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useCommand = useCommand;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const program_1 = require("../program");
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const colors_1 = require("../ui/colors");
|
|
12
|
+
/**
|
|
13
|
+
* Commands that use interactive prompts or WalletConnect QR flows.
|
|
14
|
+
* These MUST run in a child process so they can own stdin/stdout directly,
|
|
15
|
+
* because Ink holds stdin in raw mode for its own input handling.
|
|
16
|
+
*/
|
|
17
|
+
const INTERACTIVE_COMMANDS = new Set([
|
|
18
|
+
"wallet deploy",
|
|
19
|
+
"wallet set-guardian",
|
|
20
|
+
"wallet unfreeze",
|
|
21
|
+
"wallet authorize-machine-key",
|
|
22
|
+
"wallet revoke-machine-key",
|
|
23
|
+
"wallet set-passkey",
|
|
24
|
+
"wallet set-interceptor",
|
|
25
|
+
"wallet set-velocity-limit",
|
|
26
|
+
"wallet upgrade-registry",
|
|
27
|
+
"wallet execute-registry-upgrade",
|
|
28
|
+
"wallet cancel-registry-upgrade",
|
|
29
|
+
"wallet register-policy",
|
|
30
|
+
"wallet whitelist-contract",
|
|
31
|
+
"wallet governance setup",
|
|
32
|
+
"wallet policy set-limit",
|
|
33
|
+
"wallet policy set-daily-limit",
|
|
34
|
+
"wallet policy set",
|
|
35
|
+
"wallet import",
|
|
36
|
+
"config init",
|
|
37
|
+
]);
|
|
38
|
+
function isInteractiveCommand(input) {
|
|
39
|
+
const normalized = input.trim();
|
|
40
|
+
for (const cmd of INTERACTIVE_COMMANDS) {
|
|
41
|
+
if (normalized === cmd || normalized.startsWith(cmd + " "))
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Dispatches parsed commands to the commander program.
|
|
48
|
+
*
|
|
49
|
+
* NON-INTERACTIVE commands: captures stdout/stderr by monkey-patching
|
|
50
|
+
* process.stdout.write and routes output to the viewport.
|
|
51
|
+
*
|
|
52
|
+
* INTERACTIVE commands (WalletConnect, prompts): spawns a child process
|
|
53
|
+
* running `arc402 <command>` with inherited stdin so that QR codes render
|
|
54
|
+
* and prompts accept input. Output is captured line-by-line into the viewport.
|
|
55
|
+
*/
|
|
56
|
+
function useCommand() {
|
|
57
|
+
const [isRunning, setIsRunning] = (0, react_1.useState)(false);
|
|
58
|
+
const execute = (0, react_1.useCallback)(async (input, onLine) => {
|
|
59
|
+
setIsRunning(true);
|
|
60
|
+
if (isInteractiveCommand(input)) {
|
|
61
|
+
await executeInteractive(input, onLine);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
await executeInProcess(input, onLine);
|
|
65
|
+
}
|
|
66
|
+
setIsRunning(false);
|
|
67
|
+
}, []);
|
|
68
|
+
return { execute, isRunning };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run an interactive command as a child process with inherited stdin.
|
|
72
|
+
* Ink is temporarily suspended so the child can own the terminal.
|
|
73
|
+
*/
|
|
74
|
+
async function executeInteractive(input, onLine) {
|
|
75
|
+
const tokens = parseTokens(input);
|
|
76
|
+
onLine(chalk_1.default.dim(" ◈ Launching interactive session..."));
|
|
77
|
+
onLine("");
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
// Spawn arc402 as a child process with full terminal access.
|
|
80
|
+
// Use stdio: 'inherit' so the child owns stdin/stdout/stderr directly.
|
|
81
|
+
// This means its output goes straight to the terminal (not captured in viewport)
|
|
82
|
+
// but that's correct — the child needs raw terminal access for QR codes, prompts, etc.
|
|
83
|
+
const child = (0, child_process_1.spawn)(process.execPath, [process.argv[1], ...tokens], {
|
|
84
|
+
stdio: "inherit",
|
|
85
|
+
env: { ...process.env, ARC402_NO_TUI: "1" }, // prevent child from launching its own TUI
|
|
86
|
+
cwd: process.cwd(),
|
|
87
|
+
});
|
|
88
|
+
child.on("close", (code) => {
|
|
89
|
+
onLine("");
|
|
90
|
+
if (code === 0) {
|
|
91
|
+
onLine(` ${colors_1.c.success} ${chalk_1.default.dim("Command completed")}`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Command exited with code ${code}`)}`);
|
|
95
|
+
}
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
child.on("error", (err) => {
|
|
99
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Failed to spawn: ${err.message}`)}`);
|
|
100
|
+
resolve();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Run a non-interactive command in-process with captured output.
|
|
106
|
+
*/
|
|
107
|
+
async function executeInProcess(input, onLine) {
|
|
108
|
+
// Capture stdout/stderr
|
|
109
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
110
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
111
|
+
let captureBuffer = "";
|
|
112
|
+
const flushBuffer = () => {
|
|
113
|
+
if (!captureBuffer)
|
|
114
|
+
return;
|
|
115
|
+
const lines = captureBuffer.split("\n");
|
|
116
|
+
captureBuffer = lines.pop() ?? "";
|
|
117
|
+
for (const line of lines) {
|
|
118
|
+
onLine(line);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const capturedWrite = (chunk, encodingOrCb, cb) => {
|
|
122
|
+
const str = typeof chunk === "string"
|
|
123
|
+
? chunk
|
|
124
|
+
: Buffer.from(chunk).toString("utf8");
|
|
125
|
+
captureBuffer += str;
|
|
126
|
+
flushBuffer();
|
|
127
|
+
const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
128
|
+
if (callback)
|
|
129
|
+
callback();
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
|
+
process.stdout.write = capturedWrite;
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
+
process.stderr.write = capturedWrite;
|
|
136
|
+
try {
|
|
137
|
+
const tokens = parseTokens(input);
|
|
138
|
+
const prog = (0, program_1.createProgram)();
|
|
139
|
+
prog.exitOverride();
|
|
140
|
+
prog.configureOutput({
|
|
141
|
+
writeOut: (str) => process.stdout.write(str),
|
|
142
|
+
writeErr: (str) => process.stderr.write(str),
|
|
143
|
+
});
|
|
144
|
+
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const e = err;
|
|
148
|
+
if (e.code === "commander.helpDisplayed" ||
|
|
149
|
+
e.code === "commander.version" ||
|
|
150
|
+
e.code === "commander.executeSubCommandAsync") {
|
|
151
|
+
// already written or normal exit — no-op
|
|
152
|
+
}
|
|
153
|
+
else if (e.code === "commander.unknownCommand") {
|
|
154
|
+
const tokens = parseTokens(input);
|
|
155
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Unknown command: ${chalk_1.default.white(tokens[0])}`)} `);
|
|
156
|
+
onLine(chalk_1.default.dim(" Type 'help' for available commands"));
|
|
157
|
+
}
|
|
158
|
+
else if (e.code?.startsWith("commander.")) {
|
|
159
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
// Flush remaining buffer
|
|
167
|
+
if (captureBuffer.trim()) {
|
|
168
|
+
onLine(captureBuffer);
|
|
169
|
+
captureBuffer = "";
|
|
170
|
+
}
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
172
|
+
process.stdout.write = originalStdoutWrite;
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
174
|
+
process.stderr.write = originalStderrWrite;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Shell-style tokenizer
|
|
178
|
+
function parseTokens(input) {
|
|
179
|
+
const tokens = [];
|
|
180
|
+
let current = "";
|
|
181
|
+
let inQuote = false;
|
|
182
|
+
let quoteChar = "";
|
|
183
|
+
let escape = false;
|
|
184
|
+
for (const ch of input) {
|
|
185
|
+
if (escape) {
|
|
186
|
+
current += ch;
|
|
187
|
+
escape = false;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (inQuote) {
|
|
191
|
+
if (quoteChar === '"' && ch === "\\") {
|
|
192
|
+
escape = true;
|
|
193
|
+
}
|
|
194
|
+
else if (ch === quoteChar) {
|
|
195
|
+
inQuote = false;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
current += ch;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else if (ch === '"' || ch === "'") {
|
|
202
|
+
inQuote = true;
|
|
203
|
+
quoteChar = ch;
|
|
204
|
+
}
|
|
205
|
+
else if (ch === " ") {
|
|
206
|
+
if (current) {
|
|
207
|
+
tokens.push(current);
|
|
208
|
+
current = "";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
current += ch;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (current)
|
|
216
|
+
tokens.push(current);
|
|
217
|
+
return tokens;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=useCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommand.js","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":";;;;;AAwDA,gCAmBC;AA3ED,iCAA8C;AAC9C,wCAA2C;AAC3C,iDAAsC;AACtC,kDAA0B;AAC1B,yCAAiC;AAEjC;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,eAAe;IACf,qBAAqB;IACrB,iBAAiB;IACjB,8BAA8B;IAC9B,2BAA2B;IAC3B,oBAAoB;IACpB,wBAAwB;IACxB,2BAA2B;IAC3B,yBAAyB;IACzB,iCAAiC;IACjC,gCAAgC;IAChC,wBAAwB;IACxB,2BAA2B;IAC3B,yBAAyB;IACzB,yBAAyB;IACzB,+BAA+B;IAC/B,mBAAmB;IACnB,eAAe;IACf,aAAa;CACd,CAAC,CAAC;AAEH,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,KAAK,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACvC,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,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AC;IACH,CAAC;IACD,IAAI,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface UseScrollResult {
|
|
2
|
+
scrollOffset: number;
|
|
3
|
+
setScrollOffset: (offset: number) => void;
|
|
4
|
+
viewportHeight: number;
|
|
5
|
+
isAutoScroll: boolean;
|
|
6
|
+
scrollUp: (lines?: number) => void;
|
|
7
|
+
scrollDown: (lines?: number) => void;
|
|
8
|
+
snapToBottom: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Manages scroll state for the Viewport.
|
|
12
|
+
* scrollOffset=0 means auto-scroll (pinned to bottom).
|
|
13
|
+
* Positive scrollOffset means scrolled up by that many lines.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useScroll(viewportHeight: number): UseScrollResult;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=useScroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScroll.d.ts","sourceRoot":"","sources":["../../src/tui/useScroll.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,eAAe,CA8CjE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useScroll = useScroll;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ink_1 = require("ink");
|
|
6
|
+
/**
|
|
7
|
+
* Manages scroll state for the Viewport.
|
|
8
|
+
* scrollOffset=0 means auto-scroll (pinned to bottom).
|
|
9
|
+
* Positive scrollOffset means scrolled up by that many lines.
|
|
10
|
+
*/
|
|
11
|
+
function useScroll(viewportHeight) {
|
|
12
|
+
const [scrollOffset, setScrollOffsetState] = (0, react_1.useState)(0);
|
|
13
|
+
const isAutoScroll = scrollOffset === 0;
|
|
14
|
+
const setScrollOffset = (0, react_1.useCallback)((offset) => {
|
|
15
|
+
setScrollOffsetState(Math.max(0, offset));
|
|
16
|
+
}, []);
|
|
17
|
+
const scrollUp = (0, react_1.useCallback)((lines) => {
|
|
18
|
+
const step = lines ?? viewportHeight;
|
|
19
|
+
setScrollOffsetState((prev) => prev + step);
|
|
20
|
+
}, [viewportHeight]);
|
|
21
|
+
const scrollDown = (0, react_1.useCallback)((lines) => {
|
|
22
|
+
const step = lines ?? viewportHeight;
|
|
23
|
+
setScrollOffsetState((prev) => Math.max(0, prev - step));
|
|
24
|
+
}, [viewportHeight]);
|
|
25
|
+
const snapToBottom = (0, react_1.useCallback)(() => {
|
|
26
|
+
setScrollOffsetState(0);
|
|
27
|
+
}, []);
|
|
28
|
+
(0, ink_1.useInput)((_input, key) => {
|
|
29
|
+
if (key.pageUp) {
|
|
30
|
+
scrollUp(viewportHeight);
|
|
31
|
+
}
|
|
32
|
+
else if (key.pageDown) {
|
|
33
|
+
scrollDown(viewportHeight);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
scrollOffset,
|
|
38
|
+
setScrollOffset,
|
|
39
|
+
viewportHeight,
|
|
40
|
+
isAutoScroll,
|
|
41
|
+
scrollUp,
|
|
42
|
+
scrollDown,
|
|
43
|
+
snapToBottom,
|
|
44
|
+
};
|
|
45
|
+
}
|
|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A,cAAQ,EAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACf,QAAQ,CAAC,cAAc,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACxB,UAAU,CAAC,cAAc,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,YAAY;QACZ,eAAe;QACf,cAAc;QACd,YAAY;QACZ,QAAQ;QACR,UAAU;QACV,YAAY;KACb,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arc402-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "ARC-402 CLI for discovery, negotiation payloads, hire/remediation/dispute workflows, and network reads",
|
|
5
5
|
"bin": {
|
|
6
6
|
"arc402": "./dist/index.js"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"@arc402/sdk": "^0.3.1",
|
|
15
15
|
"@coinbase/wallet-sdk": "^4.3.7",
|
|
16
16
|
"@types/better-sqlite3": "^7.6.13",
|
|
17
|
+
"@types/react": "^18.3.28",
|
|
17
18
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
|
18
19
|
"@walletconnect/sign-client": "^2.17.4",
|
|
19
20
|
"better-sqlite3": "^12.8.0",
|
|
@@ -21,10 +22,13 @@
|
|
|
21
22
|
"cli-table3": "^0.6.3",
|
|
22
23
|
"commander": "^12.1.0",
|
|
23
24
|
"ethers": "^6.13.4",
|
|
25
|
+
"ink": "^3.2.0",
|
|
26
|
+
"ink-text-input": "^4.0.3",
|
|
24
27
|
"jose": "^6.2.1",
|
|
25
28
|
"ora": "^8.1.1",
|
|
26
29
|
"prompts": "^2.4.2",
|
|
27
30
|
"qrcode-terminal": "^0.12.0",
|
|
31
|
+
"react": "^18.3.1",
|
|
28
32
|
"smol-toml": "^1.6.0",
|
|
29
33
|
"tweetnacl": "^1.0.3",
|
|
30
34
|
"yaml": "^2.8.2"
|
package/src/index.ts
CHANGED
|
@@ -27,6 +27,18 @@ function checkUpgrade(): void {
|
|
|
27
27
|
|
|
28
28
|
const printMode = process.argv.includes("--print");
|
|
29
29
|
|
|
30
|
+
// Detect if a subcommand was provided (any arg after the binary that doesn't start with -)
|
|
31
|
+
const knownSubcommands = (() => {
|
|
32
|
+
try {
|
|
33
|
+
const prog = createProgram();
|
|
34
|
+
return new Set(prog.commands.map((cmd) => cmd.name()));
|
|
35
|
+
} catch {
|
|
36
|
+
return new Set<string>();
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
const argv = process.argv.slice(2).filter((a) => a !== "--print");
|
|
40
|
+
const hasSubcommand = argv.some((a) => !a.startsWith("-") && knownSubcommands.has(a));
|
|
41
|
+
|
|
30
42
|
if (printMode) {
|
|
31
43
|
// --print mode: skip REPL entirely, suppress ANSI/spinners, run command, exit.
|
|
32
44
|
// Used by OpenClaw agents running arc402 commands via ACP.
|
|
@@ -40,8 +52,16 @@ if (printMode) {
|
|
|
40
52
|
console.error(e instanceof Error ? e.message : String(e));
|
|
41
53
|
process.exit(1);
|
|
42
54
|
});
|
|
55
|
+
} else if (process.stdout.isTTY && !hasSubcommand && process.argv.length <= 2 && !process.env.ARC402_NO_TUI) {
|
|
56
|
+
// TTY with no subcommand — launch Ink TUI (unless spawned by TUI as a child process)
|
|
57
|
+
checkUpgrade();
|
|
58
|
+
void import("./tui/index").then(({ launchTUI }) => launchTUI()).catch((e: unknown) => {
|
|
59
|
+
console.error("TUI failed to start:", e instanceof Error ? e.message : String(e));
|
|
60
|
+
// Fallback to REPL
|
|
61
|
+
void startREPL();
|
|
62
|
+
});
|
|
43
63
|
} else if (process.argv.length <= 2) {
|
|
44
|
-
// No subcommand — enter
|
|
64
|
+
// No subcommand, not TTY — enter basic REPL fallback
|
|
45
65
|
checkUpgrade();
|
|
46
66
|
void startREPL();
|
|
47
67
|
} else {
|