apow-cli 0.11.18 → 0.12.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/.env.example +23 -5
- package/README.md +117 -67
- package/dist/brand-intro.js +160 -0
- package/dist/bridge/solana.js +27 -45
- package/dist/config.js +90 -5
- package/dist/dashboard-html.js +36 -43
- package/dist/dashboard.js +22 -151
- package/dist/errors.js +22 -3
- package/dist/grinder-http.js +3 -5
- package/dist/grinder-native.js +6 -5
- package/dist/index.js +540 -343
- package/dist/llm-setup.js +42 -0
- package/dist/lp-gate.js +28 -0
- package/dist/miner.js +24 -10
- package/dist/mint.js +6 -7
- package/dist/policy/audit-log.js +57 -0
- package/dist/policy/context.js +11 -0
- package/dist/policy/decode.js +84 -0
- package/dist/policy/paths.js +41 -0
- package/dist/policy/policy.js +224 -0
- package/dist/policy/spend-ledger.js +43 -0
- package/dist/preflight.js +138 -50
- package/dist/secure-env.js +65 -0
- package/dist/signer/guarded-account.js +78 -0
- package/dist/signer/local-keystore.js +40 -0
- package/dist/signer/session.js +11 -0
- package/dist/signer/types.js +2 -0
- package/dist/smhl.js +83 -10
- package/dist/stats.js +13 -1
- package/dist/sweep.js +181 -0
- package/dist/ui.js +140 -16
- package/dist/wallet-store.js +127 -31
- package/dist/wallet.js +18 -22
- package/dist/x402.js +4 -4
- package/package.json +8 -5
- package/skill.md +57 -833
package/dist/preflight.js
CHANGED
|
@@ -43,7 +43,11 @@ const chains_1 = require("viem/chains");
|
|
|
43
43
|
const AgentCoin_json_1 = __importDefault(require("./abi/AgentCoin.json"));
|
|
44
44
|
const MiningAgent_json_1 = __importDefault(require("./abi/MiningAgent.json"));
|
|
45
45
|
const config_1 = require("./config");
|
|
46
|
+
const errors_1 = require("./errors");
|
|
46
47
|
const grinder_http_1 = require("./grinder-http");
|
|
48
|
+
const policy_1 = require("./policy/policy");
|
|
49
|
+
const spend_ledger_1 = require("./policy/spend-ledger");
|
|
50
|
+
const secure_env_1 = require("./secure-env");
|
|
47
51
|
const wallet_1 = require("./wallet");
|
|
48
52
|
const ui = __importStar(require("./ui"));
|
|
49
53
|
const agentCoinAbi = AgentCoin_json_1.default;
|
|
@@ -60,13 +64,60 @@ const erc20BalanceAbi = [
|
|
|
60
64
|
stateMutability: "view",
|
|
61
65
|
},
|
|
62
66
|
];
|
|
63
|
-
function
|
|
67
|
+
function runLocalCliCheck(command, args, env) {
|
|
68
|
+
const result = (0, node_child_process_1.spawnSync)(command, args, {
|
|
69
|
+
encoding: "utf8",
|
|
70
|
+
env,
|
|
71
|
+
timeout: 5_000,
|
|
72
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
passed: result.status === 0,
|
|
76
|
+
output: `${result.stdout ?? ""}\n${result.stderr ?? ""}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function hasLocalCli(command, env) {
|
|
80
|
+
return runLocalCliCheck(command, ["--version"], env).passed;
|
|
81
|
+
}
|
|
82
|
+
function hasClaudeSubscriptionAuth() {
|
|
83
|
+
const result = runLocalCliCheck("claude", ["auth", "status"], (0, secure_env_1.claudeSubscriptionEnv)());
|
|
84
|
+
return result.passed && /claude\.ai|subscription/i.test(result.output);
|
|
85
|
+
}
|
|
86
|
+
function hasCodexSubscriptionAuth() {
|
|
87
|
+
const result = runLocalCliCheck("codex", ["login", "status"], (0, secure_env_1.codexSubscriptionEnv)());
|
|
88
|
+
return result.passed && /chatgpt/i.test(result.output);
|
|
89
|
+
}
|
|
90
|
+
async function checkOllamaReadiness() {
|
|
91
|
+
const endpoint = `${config_1.config.ollamaUrl.replace(/\/+$/, "")}/api/tags`;
|
|
64
92
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
const response = await fetch(endpoint, { signal: AbortSignal.timeout(3_000) });
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`HTTP ${response.status}`);
|
|
96
|
+
}
|
|
97
|
+
const data = (await response.json());
|
|
98
|
+
const expected = config_1.config.llmModel.split(":")[0];
|
|
99
|
+
const installed = (data.models ?? []).some(({ name, model }) => {
|
|
100
|
+
const candidate = name ?? model ?? "";
|
|
101
|
+
return candidate === config_1.config.llmModel || candidate.split(":")[0] === expected;
|
|
102
|
+
});
|
|
103
|
+
if (!installed) {
|
|
104
|
+
return {
|
|
105
|
+
label: `LLM provider: ollama is missing ${config_1.config.llmModel}`,
|
|
106
|
+
passed: false,
|
|
107
|
+
fix: `Run \`ollama pull ${config_1.config.llmModel}\`, then retry`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
label: `LLM provider: ollama (${config_1.config.llmModel}, local inference)`,
|
|
112
|
+
passed: true,
|
|
113
|
+
};
|
|
67
114
|
}
|
|
68
115
|
catch {
|
|
69
|
-
return
|
|
116
|
+
return {
|
|
117
|
+
label: `LLM provider: ollama is unreachable at ${(0, errors_1.redactUrls)(config_1.config.ollamaUrl)}`,
|
|
118
|
+
passed: false,
|
|
119
|
+
fix: "Install and start Ollama, then retry",
|
|
120
|
+
};
|
|
70
121
|
}
|
|
71
122
|
}
|
|
72
123
|
async function runPreflight(level) {
|
|
@@ -94,40 +145,46 @@ async function runPreflight(level) {
|
|
|
94
145
|
// Check x402: USDC balance BEFORE RPC check (can't use x402 without USDC)
|
|
95
146
|
let x402Funded = false;
|
|
96
147
|
if (config_1.config.useX402 && wallet_1.account) {
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
args: [wallet_1.account.address],
|
|
109
|
-
}));
|
|
110
|
-
if (usdcBalance === 0n) {
|
|
111
|
-
results.push({
|
|
112
|
-
label: "No USDC balance — QuickNode x402 requires USDC on Base",
|
|
113
|
-
passed: false,
|
|
114
|
-
fix: `Send at least 2.00 USDC to ${wallet_1.account.address} on Base for x402 starting balance; add more if you want extra headroom. Run \`apow fund\` to bridge from Solana or Ethereum.`,
|
|
148
|
+
if (!config_1.config.rpcUrl) {
|
|
149
|
+
x402Funded = true; // optimistic — the x402 RPC check below will verify reachability.
|
|
150
|
+
ui.warn("Skipping x402 USDC precheck because RPC_URL is not set; refusing to use public Base RPC endpoints");
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
try {
|
|
154
|
+
// Use a separate lightweight client to avoid chicken-and-egg
|
|
155
|
+
// (can't use x402 to check if we can pay for x402)
|
|
156
|
+
const checkClient = (0, viem_1.createPublicClient)({
|
|
157
|
+
chain: chains_1.base,
|
|
158
|
+
transport: (0, viem_1.http)(config_1.config.rpcUrl),
|
|
115
159
|
});
|
|
160
|
+
const usdcBalance = (await checkClient.readContract({
|
|
161
|
+
address: USDC_ADDRESS,
|
|
162
|
+
abi: erc20BalanceAbi,
|
|
163
|
+
functionName: "balanceOf",
|
|
164
|
+
args: [wallet_1.account.address],
|
|
165
|
+
}));
|
|
166
|
+
if (usdcBalance === 0n) {
|
|
167
|
+
results.push({
|
|
168
|
+
label: "No USDC balance — QuickNode x402 requires USDC on Base",
|
|
169
|
+
passed: false,
|
|
170
|
+
fix: `Send at least 2.00 USDC to ${wallet_1.account.address} on Base for x402 starting balance; add more if you want extra headroom. Run \`apow fund\` to bridge from Solana or Ethereum.`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
x402Funded = true;
|
|
175
|
+
const formatted = (0, viem_1.formatUnits)(usdcBalance, USDC_DECIMALS);
|
|
176
|
+
results.push({
|
|
177
|
+
label: `RPC: QuickNode x402 (${formatted} USDC available)`,
|
|
178
|
+
passed: true,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
116
181
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
label: `RPC: QuickNode x402 (${formatted} USDC available)`,
|
|
122
|
-
passed: true,
|
|
123
|
-
});
|
|
182
|
+
catch {
|
|
183
|
+
// USDC check failed — can't verify, warn but don't block
|
|
184
|
+
x402Funded = true; // optimistic — let the RPC check determine reachability
|
|
185
|
+
ui.warn("Could not check USDC balance — QuickNode x402 may fail if wallet has no USDC");
|
|
124
186
|
}
|
|
125
187
|
}
|
|
126
|
-
catch {
|
|
127
|
-
// USDC check failed — can't verify, warn but don't block
|
|
128
|
-
x402Funded = true; // optimistic — let the RPC check determine reachability
|
|
129
|
-
ui.warn("Could not check USDC balance — QuickNode x402 may fail if wallet has no USDC");
|
|
130
|
-
}
|
|
131
188
|
}
|
|
132
189
|
// Check 2: RPC reachable + chain ID
|
|
133
190
|
// Skip when: no RPC configured at all, or x402 active but unfunded
|
|
@@ -151,7 +208,7 @@ async function runPreflight(level) {
|
|
|
151
208
|
}
|
|
152
209
|
catch {
|
|
153
210
|
results.push({
|
|
154
|
-
label: `RPC unreachable — could not connect to ${config_1.config.useX402 ? "QuickNode x402" : config_1.config.rpcUrl}`,
|
|
211
|
+
label: `RPC unreachable — could not connect to ${config_1.config.useX402 ? "QuickNode x402" : (0, errors_1.redactUrls)(config_1.config.rpcUrl)}`,
|
|
155
212
|
passed: false,
|
|
156
213
|
fix: config_1.config.useX402
|
|
157
214
|
? "Check internet connection and USDC balance, or set RPC_URL in .env for a custom RPC"
|
|
@@ -160,18 +217,33 @@ async function runPreflight(level) {
|
|
|
160
217
|
}
|
|
161
218
|
}
|
|
162
219
|
if (level === "wallet" || level === "mining") {
|
|
220
|
+
const policy = (0, policy_1.loadPolicy)();
|
|
221
|
+
const spent = wallet_1.account ? (0, spend_ledger_1.spentTodayUsdc)(wallet_1.account.address) : 0;
|
|
222
|
+
const remaining = Math.max(0, policy.x402.dailyUsdc - spent);
|
|
223
|
+
results.push({
|
|
224
|
+
label: `Policy: ${policy.mode} (${remaining.toFixed(2)} USDC x402 budget remaining today)`,
|
|
225
|
+
passed: true,
|
|
226
|
+
});
|
|
163
227
|
// Check 3: Private key valid
|
|
164
228
|
if (wallet_1.account) {
|
|
229
|
+
const source = config_1.config.walletSource === "keystore" ? "encrypted keystore" : "legacy PRIVATE_KEY";
|
|
165
230
|
results.push({
|
|
166
|
-
label: `
|
|
231
|
+
label: `Wallet signer unlocked via ${source} (${wallet_1.account.address.slice(0, 6)}...${wallet_1.account.address.slice(-4)})`,
|
|
167
232
|
passed: true,
|
|
168
233
|
});
|
|
169
234
|
}
|
|
235
|
+
else if (config_1.config.keystorePath && config_1.config.walletLoadError) {
|
|
236
|
+
results.push({
|
|
237
|
+
label: "Encrypted keystore locked",
|
|
238
|
+
passed: false,
|
|
239
|
+
fix: config_1.config.walletLoadError,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
170
242
|
else {
|
|
171
243
|
results.push({
|
|
172
244
|
label: "Private key not configured",
|
|
173
245
|
passed: false,
|
|
174
|
-
fix: "Run `apow setup` and choose Easy Mode, or set
|
|
246
|
+
fix: "Run `apow setup` and choose Easy Mode, or set KEYSTORE_PATH to an encrypted keystore",
|
|
175
247
|
});
|
|
176
248
|
}
|
|
177
249
|
// Check 4: Wallet has ETH (skip if RPC already failed — avoids duplicate errors)
|
|
@@ -224,48 +296,64 @@ async function runPreflight(level) {
|
|
|
224
296
|
if (config_1.config.llmProvider === "clawrouter") {
|
|
225
297
|
if (!wallet_1.account) {
|
|
226
298
|
results.push({
|
|
227
|
-
label: "
|
|
299
|
+
label: "The x402 LLM service requires an unlocked wallet signer",
|
|
228
300
|
passed: false,
|
|
229
|
-
fix: "
|
|
301
|
+
fix: "Unlock KEYSTORE_PATH with KEYSTORE_PASSWORD",
|
|
230
302
|
});
|
|
231
303
|
}
|
|
232
304
|
else {
|
|
233
305
|
results.push({
|
|
234
|
-
label: "LLM provider:
|
|
306
|
+
label: "LLM provider: automatic x402 model selection",
|
|
235
307
|
passed: true,
|
|
236
308
|
});
|
|
237
309
|
}
|
|
238
310
|
}
|
|
239
311
|
else if (config_1.config.llmProvider === "ollama") {
|
|
240
|
-
results.push(
|
|
312
|
+
results.push(await checkOllamaReadiness());
|
|
241
313
|
}
|
|
242
314
|
else if (config_1.config.llmProvider === "claude-code") {
|
|
243
|
-
|
|
315
|
+
const env = (0, secure_env_1.claudeSubscriptionEnv)();
|
|
316
|
+
if (!hasLocalCli("claude", env)) {
|
|
244
317
|
results.push({
|
|
245
|
-
label: "LLM provider
|
|
318
|
+
label: "LLM provider claude-code not installed",
|
|
319
|
+
passed: false,
|
|
320
|
+
fix: "Install Claude Code or switch to LLM_PROVIDER=clawrouter",
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
else if (hasClaudeSubscriptionAuth()) {
|
|
324
|
+
results.push({
|
|
325
|
+
label: "LLM provider: Claude Code (Claude subscription authenticated)",
|
|
246
326
|
passed: true,
|
|
247
327
|
});
|
|
248
328
|
}
|
|
249
329
|
else {
|
|
250
330
|
results.push({
|
|
251
|
-
label: "
|
|
331
|
+
label: "Claude Code is not signed in with a Claude subscription",
|
|
252
332
|
passed: false,
|
|
253
|
-
fix: "
|
|
333
|
+
fix: "Run `claude login`, choose your Claude.ai subscription, then retry",
|
|
254
334
|
});
|
|
255
335
|
}
|
|
256
336
|
}
|
|
257
337
|
else if (config_1.config.llmProvider === "codex") {
|
|
258
|
-
|
|
338
|
+
const env = (0, secure_env_1.codexSubscriptionEnv)();
|
|
339
|
+
if (!hasLocalCli("codex", env)) {
|
|
259
340
|
results.push({
|
|
260
|
-
label: "LLM provider
|
|
341
|
+
label: "LLM provider codex not installed",
|
|
342
|
+
passed: false,
|
|
343
|
+
fix: "Install Codex CLI or switch to LLM_PROVIDER=clawrouter",
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (hasCodexSubscriptionAuth()) {
|
|
347
|
+
results.push({
|
|
348
|
+
label: "LLM provider: Codex (ChatGPT subscription authenticated)",
|
|
261
349
|
passed: true,
|
|
262
350
|
});
|
|
263
351
|
}
|
|
264
352
|
else {
|
|
265
353
|
results.push({
|
|
266
|
-
label: "
|
|
354
|
+
label: "Codex is not signed in with ChatGPT",
|
|
267
355
|
passed: false,
|
|
268
|
-
fix: "
|
|
356
|
+
fix: "Run `codex login`, choose ChatGPT subscription access, then retry",
|
|
269
357
|
});
|
|
270
358
|
}
|
|
271
359
|
}
|
|
@@ -276,7 +364,7 @@ async function runPreflight(level) {
|
|
|
276
364
|
results.push({
|
|
277
365
|
label: `LLM API key not set for ${config_1.config.llmProvider}`,
|
|
278
366
|
passed: false,
|
|
279
|
-
fix: "Set LLM_API_KEY in .env, or switch to LLM_PROVIDER=clawrouter (
|
|
367
|
+
fix: "Set LLM_API_KEY in .env, or switch to LLM_PROVIDER=clawrouter (no API key; wallet-paid in USDC)",
|
|
280
368
|
});
|
|
281
369
|
}
|
|
282
370
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.childEnv = childEnv;
|
|
4
|
+
exports.claudeSubscriptionEnv = claudeSubscriptionEnv;
|
|
5
|
+
exports.codexSubscriptionEnv = codexSubscriptionEnv;
|
|
6
|
+
const SECRET_ENV_KEYS = new Set([
|
|
7
|
+
"KEYSTORE_PASSWORD",
|
|
8
|
+
"APOW_KEYSTORE_PASSWORD",
|
|
9
|
+
"PRIVATE_KEY",
|
|
10
|
+
]);
|
|
11
|
+
const SUBSCRIPTION_CLI_ENV_KEYS = new Set([
|
|
12
|
+
"PATH",
|
|
13
|
+
"HOME",
|
|
14
|
+
"USER",
|
|
15
|
+
"LOGNAME",
|
|
16
|
+
"SHELL",
|
|
17
|
+
"TMPDIR",
|
|
18
|
+
"TMP",
|
|
19
|
+
"TEMP",
|
|
20
|
+
"LANG",
|
|
21
|
+
"LC_ALL",
|
|
22
|
+
"LC_CTYPE",
|
|
23
|
+
"TERM",
|
|
24
|
+
"NO_COLOR",
|
|
25
|
+
"FORCE_COLOR",
|
|
26
|
+
"SSL_CERT_FILE",
|
|
27
|
+
"SSL_CERT_DIR",
|
|
28
|
+
"NODE_EXTRA_CA_CERTS",
|
|
29
|
+
"CODEX_HOME",
|
|
30
|
+
"CLAUDE_CONFIG_DIR",
|
|
31
|
+
"XDG_CONFIG_HOME",
|
|
32
|
+
"XDG_DATA_HOME",
|
|
33
|
+
"XDG_CACHE_HOME",
|
|
34
|
+
"PATHEXT",
|
|
35
|
+
"SystemRoot",
|
|
36
|
+
"ComSpec",
|
|
37
|
+
"WINDIR",
|
|
38
|
+
"USERPROFILE",
|
|
39
|
+
"LOCALAPPDATA",
|
|
40
|
+
"APPDATA",
|
|
41
|
+
]);
|
|
42
|
+
function childEnv(base = process.env) {
|
|
43
|
+
const next = {};
|
|
44
|
+
for (const [key, value] of Object.entries(base)) {
|
|
45
|
+
if (!SECRET_ENV_KEYS.has(key)) {
|
|
46
|
+
next[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
function subscriptionCliEnv(base) {
|
|
52
|
+
const next = {};
|
|
53
|
+
for (const [key, value] of Object.entries(base)) {
|
|
54
|
+
if (SUBSCRIPTION_CLI_ENV_KEYS.has(key)) {
|
|
55
|
+
next[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return next;
|
|
59
|
+
}
|
|
60
|
+
function claudeSubscriptionEnv(base = process.env) {
|
|
61
|
+
return subscriptionCliEnv(base);
|
|
62
|
+
}
|
|
63
|
+
function codexSubscriptionEnv(base = process.env) {
|
|
64
|
+
return subscriptionCliEnv(base);
|
|
65
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGuardedAccount = createGuardedAccount;
|
|
4
|
+
const audit_log_1 = require("../policy/audit-log");
|
|
5
|
+
const context_1 = require("../policy/context");
|
|
6
|
+
const policy_1 = require("../policy/policy");
|
|
7
|
+
const spend_ledger_1 = require("../policy/spend-ledger");
|
|
8
|
+
const decode_1 = require("../policy/decode");
|
|
9
|
+
function createGuardedAccount(base) {
|
|
10
|
+
return {
|
|
11
|
+
...base,
|
|
12
|
+
async signTransaction(transaction, options) {
|
|
13
|
+
const context = (0, context_1.getSignerContext)();
|
|
14
|
+
const verdict = (0, policy_1.evaluateTx)({
|
|
15
|
+
account: base.address,
|
|
16
|
+
to: transaction.to,
|
|
17
|
+
value: transaction.value,
|
|
18
|
+
data: transaction.data,
|
|
19
|
+
context,
|
|
20
|
+
});
|
|
21
|
+
(0, audit_log_1.appendAudit)({
|
|
22
|
+
address: base.address,
|
|
23
|
+
kind: verdict.kind,
|
|
24
|
+
target: transaction.to ?? undefined,
|
|
25
|
+
selector: (0, decode_1.calldataSelector)(transaction.data),
|
|
26
|
+
valueWei: transaction.value?.toString(),
|
|
27
|
+
verdict: verdict.verdict,
|
|
28
|
+
policyRule: verdict.rule,
|
|
29
|
+
context,
|
|
30
|
+
});
|
|
31
|
+
(0, policy_1.assertAllowed)(verdict);
|
|
32
|
+
return base.signTransaction(transaction, options);
|
|
33
|
+
},
|
|
34
|
+
async signTypedData(parameters) {
|
|
35
|
+
const context = (0, context_1.getSignerContext)();
|
|
36
|
+
const verdict = (0, policy_1.evaluateTypedData)({ account: base.address, parameters, context });
|
|
37
|
+
(0, audit_log_1.appendAudit)({
|
|
38
|
+
address: base.address,
|
|
39
|
+
kind: verdict.kind,
|
|
40
|
+
target: "typed-data",
|
|
41
|
+
usdc: verdict.usdc?.toString(),
|
|
42
|
+
payee: verdict.payee,
|
|
43
|
+
verdict: verdict.verdict,
|
|
44
|
+
policyRule: verdict.rule,
|
|
45
|
+
context,
|
|
46
|
+
});
|
|
47
|
+
(0, policy_1.assertAllowed)(verdict);
|
|
48
|
+
if (verdict.kind === "x402" && verdict.usdc !== undefined) {
|
|
49
|
+
(0, spend_ledger_1.recordSpend)({ address: base.address, kind: "x402", usdc: verdict.usdc, payee: verdict.payee });
|
|
50
|
+
}
|
|
51
|
+
return base.signTypedData(parameters);
|
|
52
|
+
},
|
|
53
|
+
async signMessage({ message }) {
|
|
54
|
+
(0, audit_log_1.appendAudit)({
|
|
55
|
+
address: base.address,
|
|
56
|
+
kind: "other",
|
|
57
|
+
target: "signMessage",
|
|
58
|
+
verdict: "deny",
|
|
59
|
+
policyRule: "sign-message-denied",
|
|
60
|
+
context: (0, context_1.getSignerContext)(),
|
|
61
|
+
});
|
|
62
|
+
throw new Error("Policy denied: sign-message-denied. APoW CLI does not sign arbitrary messages.");
|
|
63
|
+
},
|
|
64
|
+
sign: base.sign
|
|
65
|
+
? async ({ hash }) => {
|
|
66
|
+
(0, audit_log_1.appendAudit)({
|
|
67
|
+
address: base.address,
|
|
68
|
+
kind: "other",
|
|
69
|
+
target: "raw-sign",
|
|
70
|
+
verdict: "deny",
|
|
71
|
+
policyRule: "raw-sign-denied",
|
|
72
|
+
context: (0, context_1.getSignerContext)(),
|
|
73
|
+
});
|
|
74
|
+
throw new Error(`Policy denied: raw-sign-denied. Refusing to sign raw hash ${hash.slice(0, 10)}...`);
|
|
75
|
+
}
|
|
76
|
+
: undefined,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetSigner = resetSigner;
|
|
4
|
+
exports.getSigner = getSigner;
|
|
5
|
+
const accounts_1 = require("viem/accounts");
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
const audit_log_1 = require("../policy/audit-log");
|
|
8
|
+
const guarded_account_1 = require("./guarded-account");
|
|
9
|
+
let cachedKey;
|
|
10
|
+
let cachedSigner = null;
|
|
11
|
+
function resetSigner() {
|
|
12
|
+
cachedKey = undefined;
|
|
13
|
+
cachedSigner = null;
|
|
14
|
+
}
|
|
15
|
+
function getSigner() {
|
|
16
|
+
if (!config_1.config.privateKey)
|
|
17
|
+
return null;
|
|
18
|
+
if (cachedSigner && cachedKey === config_1.config.privateKey)
|
|
19
|
+
return cachedSigner;
|
|
20
|
+
const rawKey = config_1.config.privateKey;
|
|
21
|
+
const base = (0, accounts_1.privateKeyToAccount)(rawKey);
|
|
22
|
+
const guarded = (0, guarded_account_1.createGuardedAccount)(base);
|
|
23
|
+
cachedKey = rawKey;
|
|
24
|
+
cachedSigner = {
|
|
25
|
+
address: base.address,
|
|
26
|
+
kind: config_1.config.walletSource === "keystore" ? "keystore" : "env-key",
|
|
27
|
+
account: guarded,
|
|
28
|
+
unsafeRawKeyFor(consumer) {
|
|
29
|
+
(0, audit_log_1.appendAudit)({
|
|
30
|
+
address: base.address,
|
|
31
|
+
kind: "raw-key-handout",
|
|
32
|
+
target: consumer,
|
|
33
|
+
verdict: "allow",
|
|
34
|
+
policyRule: "raw-key-handout",
|
|
35
|
+
});
|
|
36
|
+
return rawKey;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return cachedSigner;
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setSessionPassword = setSessionPassword;
|
|
4
|
+
exports.getSessionPassword = getSessionPassword;
|
|
5
|
+
let sessionPassword = "";
|
|
6
|
+
function setSessionPassword(password) {
|
|
7
|
+
sessionPassword = password;
|
|
8
|
+
}
|
|
9
|
+
function getSessionPassword() {
|
|
10
|
+
return sessionPassword;
|
|
11
|
+
}
|
package/dist/smhl.js
CHANGED
|
@@ -42,8 +42,15 @@ exports.validateSmhlSolution = validateSmhlSolution;
|
|
|
42
42
|
exports.solveSmhlAlgorithmic = solveSmhlAlgorithmic;
|
|
43
43
|
exports.solveSmhlChallenge = solveSmhlChallenge;
|
|
44
44
|
const node_child_process_1 = require("node:child_process");
|
|
45
|
+
const node_fs_1 = require("node:fs");
|
|
46
|
+
const node_os_1 = require("node:os");
|
|
47
|
+
const node_path_1 = require("node:path");
|
|
45
48
|
const openai_1 = __importDefault(require("openai"));
|
|
46
49
|
const config_1 = require("./config");
|
|
50
|
+
const secure_env_1 = require("./secure-env");
|
|
51
|
+
const local_keystore_1 = require("./signer/local-keystore");
|
|
52
|
+
const SMHL_SYSTEM_PROMPT = "You generate short lowercase word sequences that match exact constraints. "
|
|
53
|
+
+ "Return only the words separated by spaces. Do not use tools. Nothing else.";
|
|
47
54
|
function normalizeSmhlChallenge(raw) {
|
|
48
55
|
if (Array.isArray(raw)) {
|
|
49
56
|
const [targetAsciiSum, firstNChars, wordCount, charPosition, charValue, totalLength] = raw;
|
|
@@ -320,8 +327,11 @@ async function requestQwenSolutionForModel(prompt, model) {
|
|
|
320
327
|
}
|
|
321
328
|
async function requestClawRouterSolution(prompt, model) {
|
|
322
329
|
const { ensureClawRouter, getClawRouterBaseUrl } = await Promise.resolve().then(() => __importStar(require("./clawrouter")));
|
|
323
|
-
const
|
|
324
|
-
|
|
330
|
+
const signer = (0, local_keystore_1.getSigner)();
|
|
331
|
+
if (!signer) {
|
|
332
|
+
throw new Error("ClawRouter requires an unlocked wallet signer.");
|
|
333
|
+
}
|
|
334
|
+
await ensureClawRouter(signer.unsafeRawKeyFor("clawrouter"));
|
|
325
335
|
const client = new openai_1.default({
|
|
326
336
|
apiKey: "x402",
|
|
327
337
|
baseURL: `${getClawRouterBaseUrl()}/v1`,
|
|
@@ -339,10 +349,41 @@ async function requestClawRouterSolution(prompt, model) {
|
|
|
339
349
|
}, { timeout: 15_000 });
|
|
340
350
|
return response.choices[0]?.message.content ?? "";
|
|
341
351
|
}
|
|
342
|
-
|
|
352
|
+
function createIsolatedCliDirectory(prefix) {
|
|
353
|
+
return (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), prefix));
|
|
354
|
+
}
|
|
355
|
+
function removeIsolatedCliDirectory(path) {
|
|
356
|
+
try {
|
|
357
|
+
(0, node_fs_1.rmSync)(path, { recursive: true, force: true });
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// Best-effort cleanup after a short-lived, non-persistent inference run.
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async function requestClaudeCodeSolution(prompt, model) {
|
|
343
364
|
return new Promise((resolve, reject) => {
|
|
344
|
-
const
|
|
345
|
-
(0, node_child_process_1.
|
|
365
|
+
const cwd = createIsolatedCliDirectory("apow-claude-smhl-");
|
|
366
|
+
(0, node_child_process_1.execFile)("claude", [
|
|
367
|
+
"-p",
|
|
368
|
+
prompt,
|
|
369
|
+
"--no-session-persistence",
|
|
370
|
+
"--safe-mode",
|
|
371
|
+
"--disable-slash-commands",
|
|
372
|
+
"--tools",
|
|
373
|
+
"",
|
|
374
|
+
"--model",
|
|
375
|
+
model,
|
|
376
|
+
"--effort",
|
|
377
|
+
"low",
|
|
378
|
+
"--system-prompt",
|
|
379
|
+
SMHL_SYSTEM_PROMPT,
|
|
380
|
+
], {
|
|
381
|
+
cwd,
|
|
382
|
+
timeout: 15_000,
|
|
383
|
+
maxBuffer: 64 * 1024,
|
|
384
|
+
env: (0, secure_env_1.claudeSubscriptionEnv)(),
|
|
385
|
+
}, (error, stdout, stderr) => {
|
|
386
|
+
removeIsolatedCliDirectory(cwd);
|
|
346
387
|
if (error) {
|
|
347
388
|
reject(new Error(`Claude Code error: ${error.message}${stderr ? `\nstderr: ${stderr}` : ""}${stdout ? `\nstdout: ${stdout}` : ""}`));
|
|
348
389
|
return;
|
|
@@ -351,15 +392,41 @@ async function requestClaudeCodeSolution(prompt) {
|
|
|
351
392
|
});
|
|
352
393
|
});
|
|
353
394
|
}
|
|
354
|
-
async function requestCodexSolution(prompt) {
|
|
395
|
+
async function requestCodexSolution(prompt, model) {
|
|
355
396
|
return new Promise((resolve, reject) => {
|
|
356
|
-
|
|
397
|
+
const cwd = createIsolatedCliDirectory("apow-codex-smhl-");
|
|
398
|
+
const child = (0, node_child_process_1.execFile)("codex", [
|
|
399
|
+
"exec",
|
|
400
|
+
"--ephemeral",
|
|
401
|
+
"--ignore-user-config",
|
|
402
|
+
"--ignore-rules",
|
|
403
|
+
"--sandbox",
|
|
404
|
+
"read-only",
|
|
405
|
+
"--skip-git-repo-check",
|
|
406
|
+
"--color",
|
|
407
|
+
"never",
|
|
408
|
+
"--model",
|
|
409
|
+
model,
|
|
410
|
+
"--config",
|
|
411
|
+
'model_reasoning_effort="low"',
|
|
412
|
+
"--config",
|
|
413
|
+
'shell_environment_policy.inherit="none"',
|
|
414
|
+
"-",
|
|
415
|
+
], {
|
|
416
|
+
cwd,
|
|
417
|
+
timeout: 15_000,
|
|
418
|
+
maxBuffer: 64 * 1024,
|
|
419
|
+
env: (0, secure_env_1.codexSubscriptionEnv)(),
|
|
420
|
+
}, (error, stdout, stderr) => {
|
|
421
|
+
removeIsolatedCliDirectory(cwd);
|
|
357
422
|
if (error) {
|
|
358
423
|
reject(new Error(`Codex error: ${error.message}${stderr ? `\nstderr: ${stderr}` : ""}${stdout ? `\nstdout: ${stdout}` : ""}`));
|
|
359
424
|
return;
|
|
360
425
|
}
|
|
361
426
|
resolve(stdout.trim());
|
|
362
427
|
});
|
|
428
|
+
child.stdin?.on("error", () => { });
|
|
429
|
+
child.stdin?.end(`${SMHL_SYSTEM_PROMPT}\n\n${prompt}`);
|
|
363
430
|
});
|
|
364
431
|
}
|
|
365
432
|
function resolveModelForProvider(provider) {
|
|
@@ -373,7 +440,13 @@ function resolveProviderOrder() {
|
|
|
373
440
|
return providers;
|
|
374
441
|
}
|
|
375
442
|
function describeProvider(provider) {
|
|
376
|
-
return provider === "claude-code"
|
|
443
|
+
return provider === "claude-code"
|
|
444
|
+
? "Claude Code"
|
|
445
|
+
: provider === "codex"
|
|
446
|
+
? "Codex"
|
|
447
|
+
: provider === "clawrouter"
|
|
448
|
+
? "ClawRouter"
|
|
449
|
+
: provider;
|
|
377
450
|
}
|
|
378
451
|
function isPermanentProviderError(message) {
|
|
379
452
|
const normalized = message.toLowerCase();
|
|
@@ -399,9 +472,9 @@ async function requestProviderSolution(provider, prompt) {
|
|
|
399
472
|
case "ollama":
|
|
400
473
|
return requestOllamaSolutionForModel(prompt, model);
|
|
401
474
|
case "claude-code":
|
|
402
|
-
return requestClaudeCodeSolution(prompt);
|
|
475
|
+
return requestClaudeCodeSolution(prompt, model);
|
|
403
476
|
case "codex":
|
|
404
|
-
return requestCodexSolution(prompt);
|
|
477
|
+
return requestCodexSolution(prompt, model);
|
|
405
478
|
case "deepseek":
|
|
406
479
|
return requestDeepSeekSolutionForModel(prompt, model);
|
|
407
480
|
case "qwen":
|