arc402-cli 0.4.3 → 0.5.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/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/index.js +7 -110
- package/dist/index.js.map +1 -1
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +85 -0
- package/dist/program.js.map +1 -0
- package/dist/repl.d.ts +2 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +277 -0
- package/dist/repl.js.map +1 -0
- package/package.json +1 -1
- package/src/client.ts +3 -1
- package/src/index.ts +8 -115
- package/src/program.ts +83 -0
- package/src/repl.ts +328 -0
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAY3E;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAUvF"}
|
package/dist/client.js
CHANGED
|
@@ -10,7 +10,9 @@ async function getClient(config) {
|
|
|
10
10
|
const address = await signer.getAddress();
|
|
11
11
|
return { provider, signer, address };
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
// No private key — use walletContractAddress for read-only operations
|
|
14
|
+
const address = config.walletContractAddress ?? null;
|
|
15
|
+
return { provider, signer: null, address };
|
|
14
16
|
}
|
|
15
17
|
async function requireSigner(config) {
|
|
16
18
|
const { provider, signer } = await getClient(config);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AASA,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AASA,8BAYC;AAED,sCAYC;AAnCD,mCAAgC;AASzB,KAAK,UAAU,SAAS,CAAC,MAAoB;IAClD,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE3D,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACvC,CAAC;IAED,sEAAsE;IACtE,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,IAAI,IAAI,CAAC;IACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC7C,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,MAAoB;IAEpB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACX,gFAAgF,CACjF,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,118 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const os_1 = __importDefault(require("os"));
|
|
11
|
-
const accept_1 = require("./commands/accept");
|
|
12
|
-
const agent_1 = require("./commands/agent");
|
|
13
|
-
const agreements_1 = require("./commands/agreements");
|
|
14
|
-
const arbitrator_1 = require("./commands/arbitrator");
|
|
15
|
-
const cancel_1 = require("./commands/cancel");
|
|
16
|
-
const channel_1 = require("./commands/channel");
|
|
17
|
-
const config_1 = require("./commands/config");
|
|
18
|
-
const deliver_1 = require("./commands/deliver");
|
|
19
|
-
const discover_1 = require("./commands/discover");
|
|
20
|
-
const endpoint_1 = require("./commands/endpoint");
|
|
21
|
-
const dispute_1 = require("./commands/dispute");
|
|
22
|
-
const hire_1 = require("./commands/hire");
|
|
23
|
-
const agent_handshake_1 = require("./commands/agent-handshake");
|
|
24
|
-
const negotiate_1 = require("./commands/negotiate");
|
|
25
|
-
const relay_1 = require("./commands/relay");
|
|
26
|
-
const remediate_1 = require("./commands/remediate");
|
|
27
|
-
const daemon_1 = require("./commands/daemon");
|
|
28
|
-
const openshell_1 = require("./commands/openshell");
|
|
29
|
-
const workroom_1 = require("./commands/workroom");
|
|
30
|
-
const arena_handshake_1 = require("./commands/arena-handshake");
|
|
31
|
-
const trust_1 = require("./commands/trust");
|
|
32
|
-
const wallet_1 = require("./commands/wallet");
|
|
33
|
-
const banner_1 = require("./ui/banner");
|
|
34
|
-
const owner_1 = require("./commands/owner");
|
|
35
|
-
const setup_1 = require("./commands/setup");
|
|
36
|
-
const verify_1 = require("./commands/verify");
|
|
37
|
-
const contract_interaction_1 = require("./commands/contract-interaction");
|
|
38
|
-
const watchtower_1 = require("./commands/watchtower");
|
|
39
|
-
const coldstart_1 = require("./commands/coldstart");
|
|
40
|
-
const migrate_1 = require("./commands/migrate");
|
|
41
|
-
const feed_1 = require("./commands/feed");
|
|
42
|
-
const arena_1 = require("./commands/arena");
|
|
43
|
-
const watch_1 = require("./commands/watch");
|
|
44
|
-
const reputation_js_1 = __importDefault(require("./commands/reputation.js"));
|
|
45
|
-
const policy_js_1 = __importDefault(require("./commands/policy.js"));
|
|
46
|
-
// Show banner when invoked with no arguments
|
|
4
|
+
const program_1 = require("./program");
|
|
5
|
+
const repl_1 = require("./repl");
|
|
47
6
|
if (process.argv.length <= 2) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let bannerCfg;
|
|
51
|
-
if (fs_1.default.existsSync(CONFIG_PATH)) {
|
|
52
|
-
try {
|
|
53
|
-
const raw = JSON.parse(fs_1.default.readFileSync(CONFIG_PATH, "utf-8"));
|
|
54
|
-
bannerCfg = { network: raw.network };
|
|
55
|
-
if (raw.walletContractAddress) {
|
|
56
|
-
const w = raw.walletContractAddress;
|
|
57
|
-
bannerCfg.wallet = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
58
|
-
}
|
|
59
|
-
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
60
|
-
try {
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
62
|
-
const ethersLib = require("ethers");
|
|
63
|
-
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
64
|
-
const bal = await Promise.race([
|
|
65
|
-
provider.getBalance(raw.walletContractAddress),
|
|
66
|
-
new Promise((_, r) => setTimeout(() => r(new Error("timeout")), 2000)),
|
|
67
|
-
]);
|
|
68
|
-
bannerCfg.balance = `${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`;
|
|
69
|
-
}
|
|
70
|
-
catch { /* skip balance on error/timeout */ }
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch { /* skip config info on parse error */ }
|
|
74
|
-
}
|
|
75
|
-
(0, banner_1.renderBanner)(bannerCfg);
|
|
76
|
-
process.exit(0);
|
|
77
|
-
})();
|
|
7
|
+
// No subcommand — enter interactive REPL
|
|
8
|
+
void (0, repl_1.startREPL)();
|
|
78
9
|
}
|
|
79
10
|
else {
|
|
80
|
-
|
|
81
|
-
program
|
|
82
|
-
(0, config_1.registerConfigCommands)(program);
|
|
83
|
-
(0, agent_handshake_1.registerHandshakeCommand)(program);
|
|
84
|
-
(0, agent_1.registerAgentCommands)(program);
|
|
85
|
-
(0, discover_1.registerDiscoverCommand)(program);
|
|
86
|
-
(0, endpoint_1.registerEndpointCommands)(program);
|
|
87
|
-
(0, negotiate_1.registerNegotiateCommands)(program);
|
|
88
|
-
(0, hire_1.registerHireCommand)(program);
|
|
89
|
-
(0, agreements_1.registerAgreementsCommands)(program);
|
|
90
|
-
(0, accept_1.registerAcceptCommand)(program);
|
|
91
|
-
(0, deliver_1.registerDeliverCommand)(program);
|
|
92
|
-
(0, remediate_1.registerRemediateCommands)(program);
|
|
93
|
-
(0, dispute_1.registerDisputeCommand)(program);
|
|
94
|
-
(0, arbitrator_1.registerArbitratorCommand)(program);
|
|
95
|
-
(0, cancel_1.registerCancelCommand)(program);
|
|
96
|
-
(0, channel_1.registerChannelCommands)(program);
|
|
97
|
-
(0, relay_1.registerRelayCommands)(program);
|
|
98
|
-
(0, daemon_1.registerDaemonCommands)(program);
|
|
99
|
-
(0, openshell_1.registerOpenShellCommands)(program);
|
|
100
|
-
(0, workroom_1.registerWorkroomCommands)(program);
|
|
101
|
-
(0, arena_handshake_1.registerArenaHandshakeCommands)(program);
|
|
102
|
-
(0, trust_1.registerTrustCommand)(program);
|
|
103
|
-
(0, wallet_1.registerWalletCommands)(program);
|
|
104
|
-
(0, owner_1.registerOwnerCommands)(program);
|
|
105
|
-
(0, setup_1.registerSetupCommands)(program);
|
|
106
|
-
(0, verify_1.registerVerifyCommand)(program);
|
|
107
|
-
(0, contract_interaction_1.registerContractInteractionCommands)(program);
|
|
108
|
-
(0, watchtower_1.registerWatchtowerCommands)(program);
|
|
109
|
-
(0, coldstart_1.registerColdStartCommands)(program);
|
|
110
|
-
(0, migrate_1.registerMigrateCommands)(program);
|
|
111
|
-
(0, feed_1.registerFeedCommand)(program);
|
|
112
|
-
(0, arena_1.registerArenaCommands)(program);
|
|
113
|
-
(0, watch_1.registerWatchCommand)(program);
|
|
114
|
-
program.addCommand(reputation_js_1.default);
|
|
115
|
-
program.addCommand(policy_js_1.default);
|
|
11
|
+
// One-shot mode — arc402 wallet deploy still works as usual
|
|
12
|
+
const program = (0, program_1.createProgram)();
|
|
116
13
|
program.parse(process.argv);
|
|
117
|
-
}
|
|
14
|
+
}
|
|
118
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAC1C,iCAAmC;AAEnC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAC7B,yCAAyC;IACzC,KAAK,IAAA,gBAAS,GAAE,CAAC;AACnB,CAAC;KAAM,CAAC;IACN,4DAA4D;IAC5D,MAAM,OAAO,GAAG,IAAA,uBAAa,GAAE,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoCpC,wBAAgB,aAAa,IAAI,OAAO,CA8CvC"}
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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.createProgram = createProgram;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const accept_1 = require("./commands/accept");
|
|
9
|
+
const agent_1 = require("./commands/agent");
|
|
10
|
+
const agreements_1 = require("./commands/agreements");
|
|
11
|
+
const arbitrator_1 = require("./commands/arbitrator");
|
|
12
|
+
const cancel_1 = require("./commands/cancel");
|
|
13
|
+
const channel_1 = require("./commands/channel");
|
|
14
|
+
const config_1 = require("./commands/config");
|
|
15
|
+
const deliver_1 = require("./commands/deliver");
|
|
16
|
+
const discover_1 = require("./commands/discover");
|
|
17
|
+
const endpoint_1 = require("./commands/endpoint");
|
|
18
|
+
const dispute_1 = require("./commands/dispute");
|
|
19
|
+
const hire_1 = require("./commands/hire");
|
|
20
|
+
const agent_handshake_1 = require("./commands/agent-handshake");
|
|
21
|
+
const negotiate_1 = require("./commands/negotiate");
|
|
22
|
+
const relay_1 = require("./commands/relay");
|
|
23
|
+
const remediate_1 = require("./commands/remediate");
|
|
24
|
+
const daemon_1 = require("./commands/daemon");
|
|
25
|
+
const openshell_1 = require("./commands/openshell");
|
|
26
|
+
const workroom_1 = require("./commands/workroom");
|
|
27
|
+
const arena_handshake_1 = require("./commands/arena-handshake");
|
|
28
|
+
const trust_1 = require("./commands/trust");
|
|
29
|
+
const wallet_1 = require("./commands/wallet");
|
|
30
|
+
const owner_1 = require("./commands/owner");
|
|
31
|
+
const setup_1 = require("./commands/setup");
|
|
32
|
+
const verify_1 = require("./commands/verify");
|
|
33
|
+
const contract_interaction_1 = require("./commands/contract-interaction");
|
|
34
|
+
const watchtower_1 = require("./commands/watchtower");
|
|
35
|
+
const coldstart_1 = require("./commands/coldstart");
|
|
36
|
+
const migrate_1 = require("./commands/migrate");
|
|
37
|
+
const feed_1 = require("./commands/feed");
|
|
38
|
+
const arena_1 = require("./commands/arena");
|
|
39
|
+
const watch_1 = require("./commands/watch");
|
|
40
|
+
const reputation_js_1 = __importDefault(require("./commands/reputation.js"));
|
|
41
|
+
const policy_js_1 = __importDefault(require("./commands/policy.js"));
|
|
42
|
+
function createProgram() {
|
|
43
|
+
const program = new commander_1.Command();
|
|
44
|
+
program
|
|
45
|
+
.name("arc402")
|
|
46
|
+
.description("ARC-402 CLI aligned to canonical-capability discovery → negotiate → hire → remediate → dispute workflow")
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
|
+
.version(require("../package.json").version);
|
|
49
|
+
(0, config_1.registerConfigCommands)(program);
|
|
50
|
+
(0, agent_handshake_1.registerHandshakeCommand)(program);
|
|
51
|
+
(0, agent_1.registerAgentCommands)(program);
|
|
52
|
+
(0, discover_1.registerDiscoverCommand)(program);
|
|
53
|
+
(0, endpoint_1.registerEndpointCommands)(program);
|
|
54
|
+
(0, negotiate_1.registerNegotiateCommands)(program);
|
|
55
|
+
(0, hire_1.registerHireCommand)(program);
|
|
56
|
+
(0, agreements_1.registerAgreementsCommands)(program);
|
|
57
|
+
(0, accept_1.registerAcceptCommand)(program);
|
|
58
|
+
(0, deliver_1.registerDeliverCommand)(program);
|
|
59
|
+
(0, remediate_1.registerRemediateCommands)(program);
|
|
60
|
+
(0, dispute_1.registerDisputeCommand)(program);
|
|
61
|
+
(0, arbitrator_1.registerArbitratorCommand)(program);
|
|
62
|
+
(0, cancel_1.registerCancelCommand)(program);
|
|
63
|
+
(0, channel_1.registerChannelCommands)(program);
|
|
64
|
+
(0, relay_1.registerRelayCommands)(program);
|
|
65
|
+
(0, daemon_1.registerDaemonCommands)(program);
|
|
66
|
+
(0, openshell_1.registerOpenShellCommands)(program);
|
|
67
|
+
(0, workroom_1.registerWorkroomCommands)(program);
|
|
68
|
+
(0, arena_handshake_1.registerArenaHandshakeCommands)(program);
|
|
69
|
+
(0, trust_1.registerTrustCommand)(program);
|
|
70
|
+
(0, wallet_1.registerWalletCommands)(program);
|
|
71
|
+
(0, owner_1.registerOwnerCommands)(program);
|
|
72
|
+
(0, setup_1.registerSetupCommands)(program);
|
|
73
|
+
(0, verify_1.registerVerifyCommand)(program);
|
|
74
|
+
(0, contract_interaction_1.registerContractInteractionCommands)(program);
|
|
75
|
+
(0, watchtower_1.registerWatchtowerCommands)(program);
|
|
76
|
+
(0, coldstart_1.registerColdStartCommands)(program);
|
|
77
|
+
(0, migrate_1.registerMigrateCommands)(program);
|
|
78
|
+
(0, feed_1.registerFeedCommand)(program);
|
|
79
|
+
(0, arena_1.registerArenaCommands)(program);
|
|
80
|
+
(0, watch_1.registerWatchCommand)(program);
|
|
81
|
+
program.addCommand(reputation_js_1.default);
|
|
82
|
+
program.addCommand(policy_js_1.default);
|
|
83
|
+
return program;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1 @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+1 @@
|
|
|
1
|
+
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../src/repl.ts"],"names":[],"mappings":"AA0LA,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CA6I/C"}
|
package/dist/repl.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
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.startREPL = startREPL;
|
|
7
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const program_1 = require("./program");
|
|
13
|
+
const banner_1 = require("./ui/banner");
|
|
14
|
+
const colors_1 = require("./ui/colors");
|
|
15
|
+
// ─── Prompt ───────────────────────────────────────────────────────────────────
|
|
16
|
+
const PROMPT = chalk_1.default.cyanBright("◈") +
|
|
17
|
+
" " +
|
|
18
|
+
chalk_1.default.dim("arc402") +
|
|
19
|
+
" " +
|
|
20
|
+
chalk_1.default.white(">") +
|
|
21
|
+
" ";
|
|
22
|
+
// ─── Sentinel thrown to intercept process.exit() from commands ───────────────
|
|
23
|
+
class REPLExitSignal extends Error {
|
|
24
|
+
constructor(code = 0) {
|
|
25
|
+
super("repl-exit-signal");
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// ─── Config / banner helpers ──────────────────────────────────────────────────
|
|
30
|
+
const CONFIG_PATH = path_1.default.join(os_1.default.homedir(), ".arc402", "config.json");
|
|
31
|
+
async function loadBannerConfig() {
|
|
32
|
+
if (!fs_1.default.existsSync(CONFIG_PATH))
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const raw = JSON.parse(fs_1.default.readFileSync(CONFIG_PATH, "utf-8"));
|
|
36
|
+
const cfg = { network: raw.network };
|
|
37
|
+
if (raw.walletContractAddress) {
|
|
38
|
+
const w = raw.walletContractAddress;
|
|
39
|
+
cfg.wallet = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
40
|
+
}
|
|
41
|
+
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
42
|
+
try {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
44
|
+
const ethersLib = require("ethers");
|
|
45
|
+
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
46
|
+
const bal = await Promise.race([
|
|
47
|
+
provider.getBalance(raw.walletContractAddress),
|
|
48
|
+
new Promise((_, r) => setTimeout(() => r(new Error("timeout")), 2000)),
|
|
49
|
+
]);
|
|
50
|
+
cfg.balance = `${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
/* skip balance on timeout */
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return cfg;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// ─── Status dashboard ─────────────────────────────────────────────────────────
|
|
63
|
+
async function showStatus() {
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(" " + chalk_1.default.cyanBright("◈") + " " + chalk_1.default.dim("─".repeat(45)));
|
|
66
|
+
if (!fs_1.default.existsSync(CONFIG_PATH)) {
|
|
67
|
+
console.log(chalk_1.default.dim(" No config found. Run 'config init' to get started."));
|
|
68
|
+
console.log();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const raw = JSON.parse(fs_1.default.readFileSync(CONFIG_PATH, "utf-8"));
|
|
73
|
+
if (raw.network)
|
|
74
|
+
console.log(` ${chalk_1.default.dim("Network")} ${chalk_1.default.white(raw.network)}`);
|
|
75
|
+
if (raw.walletContractAddress) {
|
|
76
|
+
const w = raw.walletContractAddress;
|
|
77
|
+
console.log(` ${chalk_1.default.dim("Wallet")} ${chalk_1.default.white(`${w.slice(0, 6)}...${w.slice(-4)}`)}`);
|
|
78
|
+
}
|
|
79
|
+
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
80
|
+
try {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
82
|
+
const ethersLib = require("ethers");
|
|
83
|
+
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
84
|
+
const bal = await Promise.race([
|
|
85
|
+
provider.getBalance(raw.walletContractAddress),
|
|
86
|
+
new Promise((_, r) => setTimeout(() => r(new Error("timeout")), 2000)),
|
|
87
|
+
]);
|
|
88
|
+
console.log(` ${chalk_1.default.dim("Balance")} ${chalk_1.default.white(`${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`)}`);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
/* skip */
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
/* skip */
|
|
97
|
+
}
|
|
98
|
+
console.log();
|
|
99
|
+
}
|
|
100
|
+
// ─── Shell-style tokenizer (handles "quoted strings") ────────────────────────
|
|
101
|
+
function parseTokens(input) {
|
|
102
|
+
const tokens = [];
|
|
103
|
+
let current = "";
|
|
104
|
+
let inQuote = false;
|
|
105
|
+
let quoteChar = "";
|
|
106
|
+
for (const ch of input) {
|
|
107
|
+
if (inQuote) {
|
|
108
|
+
if (ch === quoteChar) {
|
|
109
|
+
inQuote = false;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
current += ch;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (ch === '"' || ch === "'") {
|
|
116
|
+
inQuote = true;
|
|
117
|
+
quoteChar = ch;
|
|
118
|
+
}
|
|
119
|
+
else if (ch === " ") {
|
|
120
|
+
if (current) {
|
|
121
|
+
tokens.push(current);
|
|
122
|
+
current = "";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
current += ch;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (current)
|
|
130
|
+
tokens.push(current);
|
|
131
|
+
return tokens;
|
|
132
|
+
}
|
|
133
|
+
// ─── Tab completer ────────────────────────────────────────────────────────────
|
|
134
|
+
function buildCompleter(topCmds, subCmds) {
|
|
135
|
+
const specialCmds = ["help", "exit", "quit", "clear", "status"];
|
|
136
|
+
const allTop = [...specialCmds, ...topCmds];
|
|
137
|
+
return function completer(line) {
|
|
138
|
+
const trimmed = line.trimStart();
|
|
139
|
+
const spaceIdx = trimmed.indexOf(" ");
|
|
140
|
+
if (spaceIdx === -1) {
|
|
141
|
+
// Completing the first word (top-level command)
|
|
142
|
+
const hits = allTop.filter((cmd) => cmd.startsWith(trimmed));
|
|
143
|
+
return [hits.length ? hits : allTop, trimmed];
|
|
144
|
+
}
|
|
145
|
+
// Completing a subcommand
|
|
146
|
+
const parent = trimmed.slice(0, spaceIdx);
|
|
147
|
+
const rest = trimmed.slice(spaceIdx + 1);
|
|
148
|
+
const subs = subCmds.get(parent) ?? [];
|
|
149
|
+
const hits = subs.filter((s) => s.startsWith(rest));
|
|
150
|
+
return [
|
|
151
|
+
hits.map((s) => `${parent} ${s}`),
|
|
152
|
+
trimmed,
|
|
153
|
+
];
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// ─── REPL entry point ─────────────────────────────────────────────────────────
|
|
157
|
+
async function startREPL() {
|
|
158
|
+
// Show the banner
|
|
159
|
+
const bannerCfg = await loadBannerConfig();
|
|
160
|
+
(0, banner_1.renderBanner)(bannerCfg);
|
|
161
|
+
// Build a template program once just to extract command metadata for completions
|
|
162
|
+
const template = (0, program_1.createProgram)();
|
|
163
|
+
const topCmds = template.commands.map((cmd) => cmd.name());
|
|
164
|
+
const subCmds = new Map();
|
|
165
|
+
for (const cmd of template.commands) {
|
|
166
|
+
if (cmd.commands.length > 0) {
|
|
167
|
+
subCmds.set(cmd.name(), cmd.commands.map((s) => s.name()));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const rl = node_readline_1.default.createInterface({
|
|
171
|
+
input: process.stdin,
|
|
172
|
+
output: process.stdout,
|
|
173
|
+
prompt: PROMPT,
|
|
174
|
+
completer: buildCompleter(topCmds, subCmds),
|
|
175
|
+
terminal: true,
|
|
176
|
+
historySize: 200,
|
|
177
|
+
});
|
|
178
|
+
function goodbye() {
|
|
179
|
+
console.log("\n " + chalk_1.default.cyanBright("◈") + chalk_1.default.dim(" goodbye"));
|
|
180
|
+
}
|
|
181
|
+
rl.on("SIGINT", () => {
|
|
182
|
+
goodbye();
|
|
183
|
+
rl.close();
|
|
184
|
+
process.exit(0);
|
|
185
|
+
});
|
|
186
|
+
rl.on("close", () => {
|
|
187
|
+
goodbye();
|
|
188
|
+
process.exit(0);
|
|
189
|
+
});
|
|
190
|
+
rl.prompt();
|
|
191
|
+
// Process lines one at a time
|
|
192
|
+
for await (const line of rl) {
|
|
193
|
+
const input = line.trim();
|
|
194
|
+
if (!input) {
|
|
195
|
+
rl.prompt();
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
// ── Special built-in commands ──────────────────────────────────────────
|
|
199
|
+
if (input === "exit" || input === "quit") {
|
|
200
|
+
goodbye();
|
|
201
|
+
rl.close();
|
|
202
|
+
process.exit(0);
|
|
203
|
+
}
|
|
204
|
+
if (input === "clear") {
|
|
205
|
+
console.clear();
|
|
206
|
+
const cfg = await loadBannerConfig();
|
|
207
|
+
(0, banner_1.renderBanner)(cfg);
|
|
208
|
+
rl.prompt();
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (input === "status") {
|
|
212
|
+
await showStatus();
|
|
213
|
+
rl.prompt();
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (input === "help" || input === "help ") {
|
|
217
|
+
// Show the full commander help via the program
|
|
218
|
+
const prog = (0, program_1.createProgram)();
|
|
219
|
+
prog.exitOverride();
|
|
220
|
+
prog.configureOutput({
|
|
221
|
+
writeOut: (str) => process.stdout.write(str),
|
|
222
|
+
writeErr: (str) => process.stderr.write(str),
|
|
223
|
+
});
|
|
224
|
+
try {
|
|
225
|
+
await prog.parseAsync(["node", "arc402", "--help"]);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
/* commander throws after printing help — ignore */
|
|
229
|
+
}
|
|
230
|
+
rl.prompt();
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
// ── Dispatch to commander ──────────────────────────────────────────────
|
|
234
|
+
const tokens = parseTokens(input);
|
|
235
|
+
const prog = (0, program_1.createProgram)();
|
|
236
|
+
prog.exitOverride();
|
|
237
|
+
prog.configureOutput({
|
|
238
|
+
writeOut: (str) => process.stdout.write(str),
|
|
239
|
+
writeErr: (str) => process.stderr.write(str),
|
|
240
|
+
});
|
|
241
|
+
// Intercept process.exit() so a command exiting doesn't kill the REPL
|
|
242
|
+
const origExit = process.exit;
|
|
243
|
+
process.exit = ((code) => {
|
|
244
|
+
throw new REPLExitSignal(code ?? 0);
|
|
245
|
+
});
|
|
246
|
+
try {
|
|
247
|
+
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
if (err instanceof REPLExitSignal) {
|
|
251
|
+
// Command called process.exit() — normal, just continue the REPL
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const e = err;
|
|
255
|
+
if (e.code === "commander.helpDisplayed" ||
|
|
256
|
+
e.code === "commander.version") {
|
|
257
|
+
// Help / version output was already written — nothing to do
|
|
258
|
+
}
|
|
259
|
+
else if (e.code === "commander.unknownCommand") {
|
|
260
|
+
console.log(`\n ${colors_1.c.failure} ${chalk_1.default.red(`Unknown command: ${chalk_1.default.white(tokens[0])}`)}`);
|
|
261
|
+
console.log(chalk_1.default.dim(" Type 'help' for available commands\n"));
|
|
262
|
+
}
|
|
263
|
+
else if (e.code?.startsWith("commander.")) {
|
|
264
|
+
console.log(`\n ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}\n`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
console.log(`\n ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}\n`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
process.exit = origExit;
|
|
273
|
+
}
|
|
274
|
+
rl.prompt();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=repl.js.map
|
package/dist/repl.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repl.js","sourceRoot":"","sources":["../src/repl.ts"],"names":[],"mappings":";;;;;AA0LA,8BA6IC;AAvUD,kEAAqC;AACrC,kDAA0B;AAC1B,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,uCAA0C;AAC1C,wCAAyD;AACzD,wCAAgC;AAEhC,iFAAiF;AAEjF,MAAM,MAAM,GACV,eAAK,CAAC,UAAU,CAAC,GAAG,CAAC;IACrB,GAAG;IACH,eAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;IACnB,GAAG;IACH,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC;IAChB,GAAG,CAAC;AAEN,gFAAgF;AAEhF,MAAM,cAAe,SAAQ,KAAK;IAChC,YAA4B,OAAe,CAAC;QAC1C,KAAK,CAAC,kBAAkB,CAAC,CAAC;QADA,SAAI,GAAJ,IAAI,CAAY;IAE5C,CAAC;CACF;AAED,iFAAiF;AAEjF,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAEtE,KAAK,UAAU,gBAA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AC,CAAC,CAAC;gBACnE,CAAC;qBAAM,IAAI,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;oBAC5C,OAAO,CAAC,GAAG,CAAC,MAAM,UAAC,CAAC,OAAO,IAAI,eAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC1E,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CACT,MAAM,UAAC,CAAC,OAAO,IAAI,eAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAC3D,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACR,OAA0B,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC9C,CAAC;QAED,EAAE,CAAC,MAAM,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -16,7 +16,9 @@ export async function getClient(config: Arc402Config): Promise<Arc402Client> {
|
|
|
16
16
|
return { provider, signer, address };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// No private key — use walletContractAddress for read-only operations
|
|
20
|
+
const address = config.walletContractAddress ?? null;
|
|
21
|
+
return { provider, signer: null, address };
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export async function requireSigner(
|
package/src/index.ts
CHANGED
|
@@ -1,119 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import path from "path";
|
|
5
|
-
import os from "os";
|
|
6
|
-
import { registerAcceptCommand } from "./commands/accept";
|
|
7
|
-
import { registerAgentCommands } from "./commands/agent";
|
|
8
|
-
import { registerAgreementsCommands } from "./commands/agreements";
|
|
9
|
-
import { registerArbitratorCommand } from "./commands/arbitrator";
|
|
10
|
-
import { registerCancelCommand } from "./commands/cancel";
|
|
11
|
-
import { registerChannelCommands } from "./commands/channel";
|
|
12
|
-
import { registerConfigCommands } from "./commands/config";
|
|
13
|
-
import { registerDeliverCommand } from "./commands/deliver";
|
|
14
|
-
import { registerDiscoverCommand } from "./commands/discover";
|
|
15
|
-
import { registerEndpointCommands } from "./commands/endpoint";
|
|
16
|
-
import { registerDisputeCommand } from "./commands/dispute";
|
|
17
|
-
import { registerHireCommand } from "./commands/hire";
|
|
18
|
-
import { registerHandshakeCommand } from "./commands/agent-handshake";
|
|
19
|
-
import { registerNegotiateCommands } from "./commands/negotiate";
|
|
20
|
-
import { registerRelayCommands } from "./commands/relay";
|
|
21
|
-
import { registerRemediateCommands } from "./commands/remediate";
|
|
22
|
-
import { registerDaemonCommands } from "./commands/daemon";
|
|
23
|
-
import { registerOpenShellCommands } from "./commands/openshell";
|
|
24
|
-
import { registerWorkroomCommands } from "./commands/workroom";
|
|
25
|
-
import { registerArenaHandshakeCommands } from "./commands/arena-handshake";
|
|
26
|
-
import { registerTrustCommand } from "./commands/trust";
|
|
27
|
-
import { registerWalletCommands } from "./commands/wallet";
|
|
28
|
-
import { renderBanner } from "./ui/banner";
|
|
29
|
-
import { registerOwnerCommands } from "./commands/owner";
|
|
30
|
-
import { registerSetupCommands } from "./commands/setup";
|
|
31
|
-
import { registerVerifyCommand } from "./commands/verify";
|
|
32
|
-
import { registerContractInteractionCommands } from "./commands/contract-interaction";
|
|
33
|
-
import { registerWatchtowerCommands } from "./commands/watchtower";
|
|
34
|
-
import { registerColdStartCommands } from "./commands/coldstart";
|
|
35
|
-
import { registerMigrateCommands } from "./commands/migrate";
|
|
36
|
-
import { registerFeedCommand } from "./commands/feed";
|
|
37
|
-
import { registerArenaCommands } from "./commands/arena";
|
|
38
|
-
import { registerWatchCommand } from "./commands/watch";
|
|
39
|
-
import reputation from "./commands/reputation.js";
|
|
40
|
-
import policy from "./commands/policy.js";
|
|
41
|
-
import { BannerConfig } from "./ui/banner";
|
|
2
|
+
import { createProgram } from "./program";
|
|
3
|
+
import { startREPL } from "./repl";
|
|
42
4
|
|
|
43
|
-
// Show banner when invoked with no arguments
|
|
44
5
|
if (process.argv.length <= 2) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let bannerCfg: BannerConfig | undefined;
|
|
48
|
-
|
|
49
|
-
if (fs.existsSync(CONFIG_PATH)) {
|
|
50
|
-
try {
|
|
51
|
-
const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")) as {
|
|
52
|
-
network?: string;
|
|
53
|
-
walletContractAddress?: string;
|
|
54
|
-
rpcUrl?: string;
|
|
55
|
-
};
|
|
56
|
-
bannerCfg = { network: raw.network };
|
|
57
|
-
if (raw.walletContractAddress) {
|
|
58
|
-
const w = raw.walletContractAddress;
|
|
59
|
-
bannerCfg.wallet = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
60
|
-
}
|
|
61
|
-
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
62
|
-
try {
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
64
|
-
const ethersLib = require("ethers") as typeof import("ethers");
|
|
65
|
-
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
66
|
-
const bal = await Promise.race([
|
|
67
|
-
provider.getBalance(raw.walletContractAddress),
|
|
68
|
-
new Promise<never>((_, r) => setTimeout(() => r(new Error("timeout")), 2000)),
|
|
69
|
-
]);
|
|
70
|
-
bannerCfg.balance = `${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`;
|
|
71
|
-
} catch { /* skip balance on error/timeout */ }
|
|
72
|
-
}
|
|
73
|
-
} catch { /* skip config info on parse error */ }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
renderBanner(bannerCfg);
|
|
77
|
-
process.exit(0);
|
|
78
|
-
})();
|
|
6
|
+
// No subcommand — enter interactive REPL
|
|
7
|
+
void startREPL();
|
|
79
8
|
} else {
|
|
80
|
-
|
|
81
|
-
const program =
|
|
82
|
-
program.
|
|
83
|
-
|
|
84
|
-
registerHandshakeCommand(program);
|
|
85
|
-
registerAgentCommands(program);
|
|
86
|
-
registerDiscoverCommand(program);
|
|
87
|
-
registerEndpointCommands(program);
|
|
88
|
-
registerNegotiateCommands(program);
|
|
89
|
-
registerHireCommand(program);
|
|
90
|
-
registerAgreementsCommands(program);
|
|
91
|
-
registerAcceptCommand(program);
|
|
92
|
-
registerDeliverCommand(program);
|
|
93
|
-
registerRemediateCommands(program);
|
|
94
|
-
registerDisputeCommand(program);
|
|
95
|
-
registerArbitratorCommand(program);
|
|
96
|
-
registerCancelCommand(program);
|
|
97
|
-
registerChannelCommands(program);
|
|
98
|
-
registerRelayCommands(program);
|
|
99
|
-
registerDaemonCommands(program);
|
|
100
|
-
registerOpenShellCommands(program);
|
|
101
|
-
registerWorkroomCommands(program);
|
|
102
|
-
registerArenaHandshakeCommands(program);
|
|
103
|
-
registerTrustCommand(program);
|
|
104
|
-
registerWalletCommands(program);
|
|
105
|
-
registerOwnerCommands(program);
|
|
106
|
-
registerSetupCommands(program);
|
|
107
|
-
registerVerifyCommand(program);
|
|
108
|
-
registerContractInteractionCommands(program);
|
|
109
|
-
registerWatchtowerCommands(program);
|
|
110
|
-
registerColdStartCommands(program);
|
|
111
|
-
registerMigrateCommands(program);
|
|
112
|
-
registerFeedCommand(program);
|
|
113
|
-
registerArenaCommands(program);
|
|
114
|
-
registerWatchCommand(program);
|
|
115
|
-
program.addCommand(reputation);
|
|
116
|
-
program.addCommand(policy);
|
|
117
|
-
program.parse(process.argv);
|
|
118
|
-
|
|
119
|
-
} // end else (has arguments)
|
|
9
|
+
// One-shot mode — arc402 wallet deploy still works as usual
|
|
10
|
+
const program = createProgram();
|
|
11
|
+
program.parse(process.argv);
|
|
12
|
+
}
|
package/src/program.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { registerAcceptCommand } from "./commands/accept";
|
|
3
|
+
import { registerAgentCommands } from "./commands/agent";
|
|
4
|
+
import { registerAgreementsCommands } from "./commands/agreements";
|
|
5
|
+
import { registerArbitratorCommand } from "./commands/arbitrator";
|
|
6
|
+
import { registerCancelCommand } from "./commands/cancel";
|
|
7
|
+
import { registerChannelCommands } from "./commands/channel";
|
|
8
|
+
import { registerConfigCommands } from "./commands/config";
|
|
9
|
+
import { registerDeliverCommand } from "./commands/deliver";
|
|
10
|
+
import { registerDiscoverCommand } from "./commands/discover";
|
|
11
|
+
import { registerEndpointCommands } from "./commands/endpoint";
|
|
12
|
+
import { registerDisputeCommand } from "./commands/dispute";
|
|
13
|
+
import { registerHireCommand } from "./commands/hire";
|
|
14
|
+
import { registerHandshakeCommand } from "./commands/agent-handshake";
|
|
15
|
+
import { registerNegotiateCommands } from "./commands/negotiate";
|
|
16
|
+
import { registerRelayCommands } from "./commands/relay";
|
|
17
|
+
import { registerRemediateCommands } from "./commands/remediate";
|
|
18
|
+
import { registerDaemonCommands } from "./commands/daemon";
|
|
19
|
+
import { registerOpenShellCommands } from "./commands/openshell";
|
|
20
|
+
import { registerWorkroomCommands } from "./commands/workroom";
|
|
21
|
+
import { registerArenaHandshakeCommands } from "./commands/arena-handshake";
|
|
22
|
+
import { registerTrustCommand } from "./commands/trust";
|
|
23
|
+
import { registerWalletCommands } from "./commands/wallet";
|
|
24
|
+
import { registerOwnerCommands } from "./commands/owner";
|
|
25
|
+
import { registerSetupCommands } from "./commands/setup";
|
|
26
|
+
import { registerVerifyCommand } from "./commands/verify";
|
|
27
|
+
import { registerContractInteractionCommands } from "./commands/contract-interaction";
|
|
28
|
+
import { registerWatchtowerCommands } from "./commands/watchtower";
|
|
29
|
+
import { registerColdStartCommands } from "./commands/coldstart";
|
|
30
|
+
import { registerMigrateCommands } from "./commands/migrate";
|
|
31
|
+
import { registerFeedCommand } from "./commands/feed";
|
|
32
|
+
import { registerArenaCommands } from "./commands/arena";
|
|
33
|
+
import { registerWatchCommand } from "./commands/watch";
|
|
34
|
+
import reputation from "./commands/reputation.js";
|
|
35
|
+
import policy from "./commands/policy.js";
|
|
36
|
+
|
|
37
|
+
export function createProgram(): Command {
|
|
38
|
+
const program = new Command();
|
|
39
|
+
program
|
|
40
|
+
.name("arc402")
|
|
41
|
+
.description(
|
|
42
|
+
"ARC-402 CLI aligned to canonical-capability discovery → negotiate → hire → remediate → dispute workflow"
|
|
43
|
+
)
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
45
|
+
.version((require("../package.json") as { version: string }).version);
|
|
46
|
+
|
|
47
|
+
registerConfigCommands(program);
|
|
48
|
+
registerHandshakeCommand(program);
|
|
49
|
+
registerAgentCommands(program);
|
|
50
|
+
registerDiscoverCommand(program);
|
|
51
|
+
registerEndpointCommands(program);
|
|
52
|
+
registerNegotiateCommands(program);
|
|
53
|
+
registerHireCommand(program);
|
|
54
|
+
registerAgreementsCommands(program);
|
|
55
|
+
registerAcceptCommand(program);
|
|
56
|
+
registerDeliverCommand(program);
|
|
57
|
+
registerRemediateCommands(program);
|
|
58
|
+
registerDisputeCommand(program);
|
|
59
|
+
registerArbitratorCommand(program);
|
|
60
|
+
registerCancelCommand(program);
|
|
61
|
+
registerChannelCommands(program);
|
|
62
|
+
registerRelayCommands(program);
|
|
63
|
+
registerDaemonCommands(program);
|
|
64
|
+
registerOpenShellCommands(program);
|
|
65
|
+
registerWorkroomCommands(program);
|
|
66
|
+
registerArenaHandshakeCommands(program);
|
|
67
|
+
registerTrustCommand(program);
|
|
68
|
+
registerWalletCommands(program);
|
|
69
|
+
registerOwnerCommands(program);
|
|
70
|
+
registerSetupCommands(program);
|
|
71
|
+
registerVerifyCommand(program);
|
|
72
|
+
registerContractInteractionCommands(program);
|
|
73
|
+
registerWatchtowerCommands(program);
|
|
74
|
+
registerColdStartCommands(program);
|
|
75
|
+
registerMigrateCommands(program);
|
|
76
|
+
registerFeedCommand(program);
|
|
77
|
+
registerArenaCommands(program);
|
|
78
|
+
registerWatchCommand(program);
|
|
79
|
+
program.addCommand(reputation);
|
|
80
|
+
program.addCommand(policy);
|
|
81
|
+
|
|
82
|
+
return program;
|
|
83
|
+
}
|
package/src/repl.ts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import { createProgram } from "./program";
|
|
7
|
+
import { renderBanner, BannerConfig } from "./ui/banner";
|
|
8
|
+
import { c } from "./ui/colors";
|
|
9
|
+
|
|
10
|
+
// ─── Prompt ───────────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
const PROMPT =
|
|
13
|
+
chalk.cyanBright("◈") +
|
|
14
|
+
" " +
|
|
15
|
+
chalk.dim("arc402") +
|
|
16
|
+
" " +
|
|
17
|
+
chalk.white(">") +
|
|
18
|
+
" ";
|
|
19
|
+
|
|
20
|
+
// ─── Sentinel thrown to intercept process.exit() from commands ───────────────
|
|
21
|
+
|
|
22
|
+
class REPLExitSignal extends Error {
|
|
23
|
+
constructor(public readonly code: number = 0) {
|
|
24
|
+
super("repl-exit-signal");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ─── Config / banner helpers ──────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
const CONFIG_PATH = path.join(os.homedir(), ".arc402", "config.json");
|
|
31
|
+
|
|
32
|
+
async function loadBannerConfig(): Promise<BannerConfig | undefined> {
|
|
33
|
+
if (!fs.existsSync(CONFIG_PATH)) return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")) as {
|
|
36
|
+
network?: string;
|
|
37
|
+
walletContractAddress?: string;
|
|
38
|
+
rpcUrl?: string;
|
|
39
|
+
};
|
|
40
|
+
const cfg: BannerConfig = { network: raw.network };
|
|
41
|
+
if (raw.walletContractAddress) {
|
|
42
|
+
const w = raw.walletContractAddress;
|
|
43
|
+
cfg.wallet = `${w.slice(0, 6)}...${w.slice(-4)}`;
|
|
44
|
+
}
|
|
45
|
+
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
46
|
+
try {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
|
+
const ethersLib = require("ethers") as typeof import("ethers");
|
|
49
|
+
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
50
|
+
const bal = await Promise.race([
|
|
51
|
+
provider.getBalance(raw.walletContractAddress),
|
|
52
|
+
new Promise<never>((_, r) =>
|
|
53
|
+
setTimeout(() => r(new Error("timeout")), 2000)
|
|
54
|
+
),
|
|
55
|
+
]);
|
|
56
|
+
cfg.balance = `${parseFloat(
|
|
57
|
+
ethersLib.ethers.formatEther(bal)
|
|
58
|
+
).toFixed(4)} ETH`;
|
|
59
|
+
} catch {
|
|
60
|
+
/* skip balance on timeout */
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return cfg;
|
|
64
|
+
} catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ─── Status dashboard ─────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
async function showStatus(): Promise<void> {
|
|
72
|
+
console.log();
|
|
73
|
+
console.log(
|
|
74
|
+
" " + chalk.cyanBright("◈") + " " + chalk.dim("─".repeat(45))
|
|
75
|
+
);
|
|
76
|
+
if (!fs.existsSync(CONFIG_PATH)) {
|
|
77
|
+
console.log(
|
|
78
|
+
chalk.dim(" No config found. Run 'config init' to get started.")
|
|
79
|
+
);
|
|
80
|
+
console.log();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")) as {
|
|
85
|
+
network?: string;
|
|
86
|
+
walletContractAddress?: string;
|
|
87
|
+
rpcUrl?: string;
|
|
88
|
+
};
|
|
89
|
+
if (raw.network)
|
|
90
|
+
console.log(` ${chalk.dim("Network")} ${chalk.white(raw.network)}`);
|
|
91
|
+
if (raw.walletContractAddress) {
|
|
92
|
+
const w = raw.walletContractAddress;
|
|
93
|
+
console.log(
|
|
94
|
+
` ${chalk.dim("Wallet")} ${chalk.white(`${w.slice(0, 6)}...${w.slice(-4)}`)}`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (raw.rpcUrl && raw.walletContractAddress) {
|
|
98
|
+
try {
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
100
|
+
const ethersLib = require("ethers") as typeof import("ethers");
|
|
101
|
+
const provider = new ethersLib.ethers.JsonRpcProvider(raw.rpcUrl);
|
|
102
|
+
const bal = await Promise.race([
|
|
103
|
+
provider.getBalance(raw.walletContractAddress),
|
|
104
|
+
new Promise<never>((_, r) =>
|
|
105
|
+
setTimeout(() => r(new Error("timeout")), 2000)
|
|
106
|
+
),
|
|
107
|
+
]);
|
|
108
|
+
console.log(
|
|
109
|
+
` ${chalk.dim("Balance")} ${chalk.white(
|
|
110
|
+
`${parseFloat(ethersLib.ethers.formatEther(bal)).toFixed(4)} ETH`
|
|
111
|
+
)}`
|
|
112
|
+
);
|
|
113
|
+
} catch {
|
|
114
|
+
/* skip */
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
/* skip */
|
|
119
|
+
}
|
|
120
|
+
console.log();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ─── Shell-style tokenizer (handles "quoted strings") ────────────────────────
|
|
124
|
+
|
|
125
|
+
function parseTokens(input: string): string[] {
|
|
126
|
+
const tokens: string[] = [];
|
|
127
|
+
let current = "";
|
|
128
|
+
let inQuote = false;
|
|
129
|
+
let quoteChar = "";
|
|
130
|
+
|
|
131
|
+
for (const ch of input) {
|
|
132
|
+
if (inQuote) {
|
|
133
|
+
if (ch === quoteChar) {
|
|
134
|
+
inQuote = false;
|
|
135
|
+
} else {
|
|
136
|
+
current += ch;
|
|
137
|
+
}
|
|
138
|
+
} else if (ch === '"' || ch === "'") {
|
|
139
|
+
inQuote = true;
|
|
140
|
+
quoteChar = ch;
|
|
141
|
+
} else if (ch === " ") {
|
|
142
|
+
if (current) {
|
|
143
|
+
tokens.push(current);
|
|
144
|
+
current = "";
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
current += ch;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (current) tokens.push(current);
|
|
151
|
+
return tokens;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ─── Tab completer ────────────────────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
function buildCompleter(
|
|
157
|
+
topCmds: string[],
|
|
158
|
+
subCmds: Map<string, string[]>
|
|
159
|
+
): readline.Completer {
|
|
160
|
+
const specialCmds = ["help", "exit", "quit", "clear", "status"];
|
|
161
|
+
const allTop = [...specialCmds, ...topCmds];
|
|
162
|
+
|
|
163
|
+
return function completer(line: string): [string[], string] {
|
|
164
|
+
const trimmed = line.trimStart();
|
|
165
|
+
const spaceIdx = trimmed.indexOf(" ");
|
|
166
|
+
|
|
167
|
+
if (spaceIdx === -1) {
|
|
168
|
+
// Completing the first word (top-level command)
|
|
169
|
+
const hits = allTop.filter((cmd) => cmd.startsWith(trimmed));
|
|
170
|
+
return [hits.length ? hits : allTop, trimmed];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Completing a subcommand
|
|
174
|
+
const parent = trimmed.slice(0, spaceIdx);
|
|
175
|
+
const rest = trimmed.slice(spaceIdx + 1);
|
|
176
|
+
const subs = subCmds.get(parent) ?? [];
|
|
177
|
+
const hits = subs.filter((s) => s.startsWith(rest));
|
|
178
|
+
return [
|
|
179
|
+
hits.map((s) => `${parent} ${s}`),
|
|
180
|
+
trimmed,
|
|
181
|
+
];
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ─── REPL entry point ─────────────────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
export async function startREPL(): Promise<void> {
|
|
188
|
+
// Show the banner
|
|
189
|
+
const bannerCfg = await loadBannerConfig();
|
|
190
|
+
renderBanner(bannerCfg);
|
|
191
|
+
|
|
192
|
+
// Build a template program once just to extract command metadata for completions
|
|
193
|
+
const template = createProgram();
|
|
194
|
+
const topCmds = template.commands.map((cmd) => cmd.name());
|
|
195
|
+
const subCmds = new Map<string, string[]>();
|
|
196
|
+
for (const cmd of template.commands) {
|
|
197
|
+
if (cmd.commands.length > 0) {
|
|
198
|
+
subCmds.set(
|
|
199
|
+
cmd.name(),
|
|
200
|
+
cmd.commands.map((s) => s.name())
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const rl = readline.createInterface({
|
|
206
|
+
input: process.stdin,
|
|
207
|
+
output: process.stdout,
|
|
208
|
+
prompt: PROMPT,
|
|
209
|
+
completer: buildCompleter(topCmds, subCmds),
|
|
210
|
+
terminal: true,
|
|
211
|
+
historySize: 200,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
function goodbye(): void {
|
|
215
|
+
console.log(
|
|
216
|
+
"\n " + chalk.cyanBright("◈") + chalk.dim(" goodbye")
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
rl.on("SIGINT", () => {
|
|
221
|
+
goodbye();
|
|
222
|
+
rl.close();
|
|
223
|
+
process.exit(0);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
rl.on("close", () => {
|
|
227
|
+
goodbye();
|
|
228
|
+
process.exit(0);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
rl.prompt();
|
|
232
|
+
|
|
233
|
+
// Process lines one at a time
|
|
234
|
+
for await (const line of rl) {
|
|
235
|
+
const input = line.trim();
|
|
236
|
+
|
|
237
|
+
if (!input) {
|
|
238
|
+
rl.prompt();
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ── Special built-in commands ──────────────────────────────────────────
|
|
243
|
+
|
|
244
|
+
if (input === "exit" || input === "quit") {
|
|
245
|
+
goodbye();
|
|
246
|
+
rl.close();
|
|
247
|
+
process.exit(0);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (input === "clear") {
|
|
251
|
+
console.clear();
|
|
252
|
+
const cfg = await loadBannerConfig();
|
|
253
|
+
renderBanner(cfg);
|
|
254
|
+
rl.prompt();
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (input === "status") {
|
|
259
|
+
await showStatus();
|
|
260
|
+
rl.prompt();
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (input === "help" || input === "help ") {
|
|
265
|
+
// Show the full commander help via the program
|
|
266
|
+
const prog = createProgram();
|
|
267
|
+
prog.exitOverride();
|
|
268
|
+
prog.configureOutput({
|
|
269
|
+
writeOut: (str) => process.stdout.write(str),
|
|
270
|
+
writeErr: (str) => process.stderr.write(str),
|
|
271
|
+
});
|
|
272
|
+
try {
|
|
273
|
+
await prog.parseAsync(["node", "arc402", "--help"]);
|
|
274
|
+
} catch {
|
|
275
|
+
/* commander throws after printing help — ignore */
|
|
276
|
+
}
|
|
277
|
+
rl.prompt();
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ── Dispatch to commander ──────────────────────────────────────────────
|
|
282
|
+
|
|
283
|
+
const tokens = parseTokens(input);
|
|
284
|
+
const prog = createProgram();
|
|
285
|
+
prog.exitOverride();
|
|
286
|
+
prog.configureOutput({
|
|
287
|
+
writeOut: (str) => process.stdout.write(str),
|
|
288
|
+
writeErr: (str) => process.stderr.write(str),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// Intercept process.exit() so a command exiting doesn't kill the REPL
|
|
292
|
+
const origExit = process.exit;
|
|
293
|
+
(process as NodeJS.Process).exit = ((code?: number) => {
|
|
294
|
+
throw new REPLExitSignal(code ?? 0);
|
|
295
|
+
}) as typeof process.exit;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
299
|
+
} catch (err) {
|
|
300
|
+
if (err instanceof REPLExitSignal) {
|
|
301
|
+
// Command called process.exit() — normal, just continue the REPL
|
|
302
|
+
} else {
|
|
303
|
+
const e = err as { code?: string; message?: string };
|
|
304
|
+
if (
|
|
305
|
+
e.code === "commander.helpDisplayed" ||
|
|
306
|
+
e.code === "commander.version"
|
|
307
|
+
) {
|
|
308
|
+
// Help / version output was already written — nothing to do
|
|
309
|
+
} else if (e.code === "commander.unknownCommand") {
|
|
310
|
+
console.log(
|
|
311
|
+
`\n ${c.failure} ${chalk.red(`Unknown command: ${chalk.white(tokens[0])}`)}`
|
|
312
|
+
);
|
|
313
|
+
console.log(chalk.dim(" Type 'help' for available commands\n"));
|
|
314
|
+
} else if (e.code?.startsWith("commander.")) {
|
|
315
|
+
console.log(`\n ${c.failure} ${chalk.red(e.message ?? String(err))}\n`);
|
|
316
|
+
} else {
|
|
317
|
+
console.log(
|
|
318
|
+
`\n ${c.failure} ${chalk.red(e.message ?? String(err))}\n`
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} finally {
|
|
323
|
+
(process as NodeJS.Process).exit = origExit;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
rl.prompt();
|
|
327
|
+
}
|
|
328
|
+
}
|