@colin999n9/gworld-agent 0.1.0-alpha.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.
Files changed (86) hide show
  1. package/README.md +127 -0
  2. package/dist/cli.d.ts +12 -0
  3. package/dist/cli.js +256 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/client-installer.d.ts +20 -0
  6. package/dist/client-installer.js +48 -0
  7. package/dist/client-installer.js.map +1 -0
  8. package/dist/config.d.ts +37 -0
  9. package/dist/config.js +184 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/data/indexer-client.d.ts +34 -0
  12. package/dist/data/indexer-client.js +172 -0
  13. package/dist/data/indexer-client.js.map +1 -0
  14. package/dist/data/rpc-reader.d.ts +69 -0
  15. package/dist/data/rpc-reader.js +163 -0
  16. package/dist/data/rpc-reader.js.map +1 -0
  17. package/dist/domain.d.ts +204 -0
  18. package/dist/domain.js +2 -0
  19. package/dist/domain.js.map +1 -0
  20. package/dist/errors.d.ts +10 -0
  21. package/dist/errors.js +16 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/factory.d.ts +4 -0
  24. package/dist/factory.js +25 -0
  25. package/dist/factory.js.map +1 -0
  26. package/dist/fs.d.ts +3 -0
  27. package/dist/fs.js +35 -0
  28. package/dist/fs.js.map +1 -0
  29. package/dist/generated/abis.d.ts +7446 -0
  30. package/dist/generated/abis.js +4861 -0
  31. package/dist/generated/abis.js.map +1 -0
  32. package/dist/generated/deployments.d.ts +145 -0
  33. package/dist/generated/deployments.js +150 -0
  34. package/dist/generated/deployments.js.map +1 -0
  35. package/dist/generated/protocol.d.ts +165 -0
  36. package/dist/generated/protocol.js +132 -0
  37. package/dist/generated/protocol.js.map +1 -0
  38. package/dist/geometry.d.ts +24 -0
  39. package/dist/geometry.js +31 -0
  40. package/dist/geometry.js.map +1 -0
  41. package/dist/json.d.ts +3 -0
  42. package/dist/json.js +14 -0
  43. package/dist/json.js.map +1 -0
  44. package/dist/mcp/server.d.ts +4 -0
  45. package/dist/mcp/server.js +134 -0
  46. package/dist/mcp/server.js.map +1 -0
  47. package/dist/mcp/stdio.d.ts +2 -0
  48. package/dist/mcp/stdio.js +23 -0
  49. package/dist/mcp/stdio.js.map +1 -0
  50. package/dist/runner/audit-store.d.ts +27 -0
  51. package/dist/runner/audit-store.js +61 -0
  52. package/dist/runner/audit-store.js.map +1 -0
  53. package/dist/runner/file-state.d.ts +7 -0
  54. package/dist/runner/file-state.js +23 -0
  55. package/dist/runner/file-state.js.map +1 -0
  56. package/dist/runner/legal-actions.d.ts +22 -0
  57. package/dist/runner/legal-actions.js +171 -0
  58. package/dist/runner/legal-actions.js.map +1 -0
  59. package/dist/runner/observation.d.ts +12 -0
  60. package/dist/runner/observation.js +47 -0
  61. package/dist/runner/observation.js.map +1 -0
  62. package/dist/runner/policy.d.ts +10 -0
  63. package/dist/runner/policy.js +68 -0
  64. package/dist/runner/policy.js.map +1 -0
  65. package/dist/runner/runtime.d.ts +73 -0
  66. package/dist/runner/runtime.js +236 -0
  67. package/dist/runner/runtime.js.map +1 -0
  68. package/dist/runner/strategy.d.ts +2 -0
  69. package/dist/runner/strategy.js +19 -0
  70. package/dist/runner/strategy.js.map +1 -0
  71. package/dist/runner/transaction-executor.d.ts +58 -0
  72. package/dist/runner/transaction-executor.js +114 -0
  73. package/dist/runner/transaction-executor.js.map +1 -0
  74. package/dist/runner/writer-lock.d.ts +14 -0
  75. package/dist/runner/writer-lock.js +81 -0
  76. package/dist/runner/writer-lock.js.map +1 -0
  77. package/dist/wallet/keystore.d.ts +18 -0
  78. package/dist/wallet/keystore.js +111 -0
  79. package/dist/wallet/keystore.js.map +1 -0
  80. package/dist/wallet/password-store.d.ts +27 -0
  81. package/dist/wallet/password-store.js +118 -0
  82. package/dist/wallet/password-store.js.map +1 -0
  83. package/package.json +41 -0
  84. package/skill/gworld/SKILL.md +58 -0
  85. package/skill/gworld/references/rules.md +33 -0
  86. package/skill/gworld/references/troubleshooting.md +22 -0
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @colin999n9/gworld-agent
2
+
3
+ > Preview package: this personal-scope package is the temporary testing entrypoint. It is not the final Galxe-owned package. The production release will be published separately as `@galxe/gworld-agent`; npm cannot transfer a scoped package between scopes. After that release, this package will be deprecated with a migration notice.
4
+
5
+ Local-first GWorld Agent Runner, stdio MCP server, and installable Agent Skill. It is the only first-party browser-independent component that signs game transactions; the Web remains read-only.
6
+
7
+ ## What it protects
8
+
9
+ - A dedicated wallet is stored as a `scrypt` + AES-256-GCM keystore with `0600` permissions.
10
+ - Interactive users choose a recovery password they know. macOS Keychain can cache it for normal Runner unlocks; headless hosts can use a `0600` password file.
11
+ - MCP never receives a private key, password, arbitrary calldata, raw transaction, contract function, or unrestricted RPC method.
12
+ - Private-key import/export is deliberately local CLI-only. Export requires an interactive confirmation bound to the wallet address and is audit-recorded.
13
+ - Writes require a fresh short-lived legal `actionId`, policy validation, `eth_call` simulation, signing, receipt confirmation, Indexer confirmation, and an audit event.
14
+ - A per-profile OS file lock prevents separate CLI/MCP processes from signing concurrently; a crashed process lock is recovered only after its PID is no longer alive.
15
+ - World writes fail closed while the Indexer is rebuilding, more than one block behind, or reports a persisted cursor ahead of the current chain head. Autonomous failures use bounded exponential backoff and sanitized audit messages.
16
+ - Default policy permits only low-risk, zero-G-spend actions and at most three transactions per round.
17
+
18
+ Use a new low-balance wallet for GWorld. Never import a primary wallet.
19
+
20
+ ## One-command onboarding
21
+
22
+ After the package is published:
23
+
24
+ ```bash
25
+ npx @colin999n9/gworld-agent@0.1.0-alpha.0 join --network testnet --client auto
26
+ ```
27
+
28
+ The command creates/unlocks the local encrypted wallet, completes the Agent spawn lifecycle, installs the GWorld Skill, and registers the pinned MCP command with detected Codex and/or Claude clients.
29
+
30
+ `--client` selects where the local integration is installed; it does not select a wallet, AI model, browser, or in-game Agent:
31
+
32
+ - `--client auto`: detect Codex CLI and Claude CLI on `PATH`, install the shared Skill, and register the pinned `gworld` MCP command with every detected client.
33
+ - `--client codex`: configure Codex only.
34
+ - `--client claude`: configure Claude only.
35
+ - omit `--client`: join GWorld only; do not install the Skill or register MCP.
36
+
37
+ `auto` fails with a clear error when neither supported client is detected.
38
+
39
+ The Gravity Testnet preset is generated from the checked-in deployment and includes the official RPC, Router, confirmations, and hosted Indexer at `https://gworld-indexer.gravity.xyz`. Normal users must not provide `--indexer-url`; the flag remains available only as an explicit developer/self-hosted override.
40
+
41
+ For a completely custom network, provide the full boundary:
42
+
43
+ ```bash
44
+ gworld-agent join --network custom \
45
+ --chain-id 12345 \
46
+ --rpc-url https://rpc.example \
47
+ --indexer-url https://indexer.example \
48
+ --router-address 0x0000000000000000000000000000000000000001 \
49
+ --confirmations 2 \
50
+ --client auto
51
+ ```
52
+
53
+ Unknown network names fail closed unless every field above is supplied. The Runner uses the trusted testnet preset by default while retaining individual flags only as explicit developer/self-hosted overrides.
54
+
55
+ ## Develop from this repository
56
+
57
+ ```bash
58
+ npm --prefix agent ci
59
+ npm --prefix agent run build
60
+
61
+ # Start local Anvil + contracts + Indexer in another terminal.
62
+ GWORLD_KEYSTORE_PASSWORD_FILE=/secure/path/password \
63
+ node agent/dist/cli.js wallet create --profile local
64
+ node agent/dist/cli.js join --profile local --client auto
65
+ ```
66
+
67
+ `GWORLD_KEYSTORE_PASSWORD_FILE` must be mode `0600`. Interactive macOS use normally needs no password environment because the password is generated into Keychain.
68
+
69
+ To import a dedicated wallet, use the hidden prompt:
70
+
71
+ ```bash
72
+ gworld-agent wallet import --profile default
73
+ ```
74
+
75
+ Automation may pipe the key to `wallet import --stdin`; there is deliberately no `--private-key` option.
76
+
77
+ To recover or migrate a wallet, export its private key only from a trusted local terminal:
78
+
79
+ ```bash
80
+ gworld-agent wallet export --profile default
81
+ ```
82
+
83
+ The CLI prints a warning, requires the exact confirmation `EXPORT <wallet-address>`, and then forces the user to re-enter the recovery password instead of reading Keychain or environment credentials. On macOS/Linux it can instead create a new mode-`0600` file and refuses to overwrite an existing target:
84
+
85
+ ```bash
86
+ gworld-agent wallet export --profile default --output ./gworld-private-key.txt
87
+ ```
88
+
89
+ Treat either form as highly sensitive. The export command is never registered with MCP and must never be run through an Agent or pasted into chat.
90
+
91
+ Windows users can reveal the key in the trusted interactive terminal. Raw `--output` file export is disabled on Windows until owner-only ACL enforcement is implemented; this avoids treating POSIX `0600` as if it protected an NTFS file.
92
+
93
+ ## CLI
94
+
95
+ ```text
96
+ wallet create|import|export create, import, or explicitly recover a dedicated wallet
97
+ join create/resume/spawn Agent and optionally install clients
98
+ status inspect wallet, Agent, chain, Runner, and sync state
99
+ observe read current indexed world plus strong RPC Agent state
100
+ actions create short-lived legal action tickets
101
+ act --kind ACTION select and execute one currently legal action kind
102
+ activity read sanitized local audit events
103
+ run start the conservative autonomous loop
104
+ pause stop autonomous execution without deleting state
105
+ mcp serve the stdio MCP protocol
106
+ ```
107
+
108
+ Profiles live under `~/.gworld/profiles/<profile>/` unless `GWORLD_HOME` is set. Config, state, wallet, and audit files are private atomic writes.
109
+
110
+ ## MCP contract
111
+
112
+ Read tools: `gworld_status`, `gworld_observe`, `gworld_get_legal_actions`, `gworld_get_activity`, and `gworld_get_policy`.
113
+
114
+ Controlled writes: `gworld_join`, `gworld_simulate_action`, `gworld_execute_action`, `gworld_set_policy`, `gworld_start`, and `gworld_pause`.
115
+
116
+ External agents must call status → policy → observe → legal actions. Execution accepts only the returned UUID `actionId`; after any state change or stale/expired error, request a new action list.
117
+
118
+ ## Verification
119
+
120
+ ```bash
121
+ npm --prefix agent run typecheck
122
+ npm --prefix agent test
123
+ npm --prefix agent run build
124
+ npm --prefix agent run test:e2e
125
+ ```
126
+
127
+ The E2E starts a temporary Anvil and Ponder Indexer, deploys contracts, imports an Anvil-only test key through stdin, creates/spawns an Agent, checks in, claims a tile, and verifies receipt, indexing, and audit data.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { type AgentConfig } from './config.js';
3
+ import type { Address, PrivateKey } from './domain.js';
4
+ import { PasswordManager } from './wallet/password-store.js';
5
+ export declare function applyNetworkOverrides(config: AgentConfig, values: Record<string, unknown>): AgentConfig;
6
+ type ExportPasswordUnlocker = Pick<PasswordManager, 'unlockForExport'>;
7
+ export declare function exportWalletPrivateKey(config: AgentConfig, confirmation: string, passwordManager?: ExportPasswordUnlocker): Promise<{
8
+ address: Address;
9
+ privateKey: PrivateKey;
10
+ }>;
11
+ export declare function assertPrivateKeyExportOutputSupported(output: string | undefined, platform?: NodeJS.Platform): void;
12
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,256 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from 'node:util';
3
+ import { access } from 'node:fs/promises';
4
+ import { resolve } from 'node:path';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { getAddress } from 'viem';
7
+ import { generatePrivateKey } from 'viem/accounts';
8
+ import { ALL_ACTIONS, loadConfig, networkPreset, saveConfig } from './config.js';
9
+ import { AgentError, sanitizedError } from './errors.js';
10
+ import { createAgentRuntime } from './factory.js';
11
+ import { stringifyJson } from './json.js';
12
+ import { ClientInstaller } from './client-installer.js';
13
+ import { FileAuditLog } from './runner/audit-store.js';
14
+ import { FileRuntimeState } from './runner/file-state.js';
15
+ import { decryptPrivateKey, encryptPrivateKey, loadKeyStore, saveKeyStore, savePrivateKeyExport } from './wallet/keystore.js';
16
+ import { PasswordManager, promptHidden, promptText } from './wallet/password-store.js';
17
+ import { serveMcp } from './mcp/stdio.js';
18
+ const HELP = `GWorld Agent Kit
19
+
20
+ Usage:
21
+ gworld-agent wallet create|import|export [--profile NAME] [--output PATH]
22
+ gworld-agent join [--profile NAME] [--client auto|codex|claude]
23
+ gworld-agent status [--profile NAME]
24
+ gworld-agent observe [--profile NAME]
25
+ gworld-agent actions [--profile NAME]
26
+ gworld-agent act --kind ACTION [--profile NAME]
27
+ gworld-agent activity [--profile NAME] [--limit COUNT]
28
+ gworld-agent run [--profile NAME]
29
+ gworld-agent pause [--profile NAME]
30
+ gworld-agent mcp [--profile NAME]
31
+
32
+ Custom network (all fields required when changing networks):
33
+ --network NAME --chain-id ID --rpc-url URL --indexer-url URL --router-address ADDRESS --confirmations COUNT
34
+
35
+ Private keys are accepted only through the hidden wallet import prompt or --stdin, never command arguments.
36
+ Private-key export is local CLI-only, requires an interactive address-bound confirmation, and is never exposed through MCP.
37
+ `;
38
+ function print(value) {
39
+ process.stdout.write(`${stringifyJson(value, 2)}\n`);
40
+ }
41
+ export function applyNetworkOverrides(config, values) {
42
+ const requestedName = values.network == null ? config.network.name : String(values.network);
43
+ const selected = requestedName === config.network.name ? config.network : networkPreset(requestedName);
44
+ const required = [
45
+ ['chain-id', 'chainId'],
46
+ ['rpc-url', 'rpcUrl'],
47
+ ['indexer-url', 'indexerUrl'],
48
+ ['router-address', 'routerAddress'],
49
+ ['confirmations', 'confirmations'],
50
+ ];
51
+ const missing = required
52
+ .filter(([option, property]) => values[option] == null && (selected == null || selected[property] == null))
53
+ .map(([option]) => option);
54
+ if (missing.length > 0) {
55
+ const reason = selected == null
56
+ ? `Unknown network ${requestedName}; provide all network fields`
57
+ : `Network preset ${requestedName} is incomplete`;
58
+ throw new AgentError('config_invalid', `${reason} (missing: ${missing.join(', ')})`);
59
+ }
60
+ const network = {
61
+ ...config.network,
62
+ ...(selected ?? {}),
63
+ name: requestedName,
64
+ ...(values['chain-id'] ? { chainId: Number(values['chain-id']) } : {}),
65
+ ...(values['rpc-url'] ? { rpcUrl: String(values['rpc-url']) } : {}),
66
+ ...(values['indexer-url'] ? { indexerUrl: String(values['indexer-url']) } : {}),
67
+ ...(values['router-address'] ? { routerAddress: getAddress(String(values['router-address'])).toLowerCase() } : {}),
68
+ ...(values.confirmations != null ? { confirmations: Number(values.confirmations) } : {}),
69
+ };
70
+ return { ...config, network };
71
+ }
72
+ async function withOverrides(config, values) {
73
+ const next = applyNetworkOverrides(config, values);
74
+ await saveConfig(next);
75
+ return next;
76
+ }
77
+ async function exists(path) {
78
+ try {
79
+ await access(path);
80
+ return true;
81
+ }
82
+ catch {
83
+ return false;
84
+ }
85
+ }
86
+ async function createWallet(config, profile, imported) {
87
+ if (await exists(config.wallet.keystorePath))
88
+ throw new AgentError('wallet_corrupt', 'Wallet already exists; refusing to overwrite it');
89
+ const password = await new PasswordManager().create(profile);
90
+ const privateKey = imported ?? generatePrivateKey();
91
+ const store = await encryptPrivateKey(privateKey, password);
92
+ await saveKeyStore(config.wallet.keystorePath, store);
93
+ await saveConfig(config);
94
+ return store.address;
95
+ }
96
+ async function unlocked(config, profile, interactive = true) {
97
+ const password = await new PasswordManager().unlock(profile, interactive);
98
+ const privateKey = await decryptPrivateKey(await loadKeyStore(config.wallet.keystorePath), password);
99
+ return createAgentRuntime(config, privateKey);
100
+ }
101
+ async function ensureWallet(config, profile) {
102
+ if (!(await exists(config.wallet.keystorePath)))
103
+ await createWallet(config, profile);
104
+ }
105
+ async function readPrivateKeyFromStdin() {
106
+ let value = '';
107
+ for await (const chunk of process.stdin)
108
+ value += chunk.toString();
109
+ value = value.trim();
110
+ if (!/^0x[0-9a-fA-F]{64}$/.test(value))
111
+ throw new AgentError('wallet_corrupt', 'Private key must be 32-byte hex');
112
+ return value;
113
+ }
114
+ export async function exportWalletPrivateKey(config, confirmation, passwordManager = new PasswordManager()) {
115
+ const store = await loadKeyStore(config.wallet.keystorePath);
116
+ const expected = `EXPORT ${store.address}`;
117
+ if (confirmation !== expected) {
118
+ throw new AgentError('policy_denied', `Private-key export confirmation must exactly match: ${expected}`);
119
+ }
120
+ const password = await passwordManager.unlockForExport();
121
+ return { address: store.address, privateKey: await decryptPrivateKey(store, password) };
122
+ }
123
+ export function assertPrivateKeyExportOutputSupported(output, platform = process.platform) {
124
+ if (output && platform === 'win32') {
125
+ throw new AgentError('unsupported', 'Raw file export is disabled on Windows until owner-only ACL support is available; omit --output to reveal it in a trusted terminal');
126
+ }
127
+ }
128
+ async function main() {
129
+ const { values, positionals } = parseArgs({
130
+ allowPositionals: true,
131
+ strict: true,
132
+ options: {
133
+ profile: { type: 'string', default: 'default' },
134
+ client: { type: 'string' },
135
+ network: { type: 'string' },
136
+ 'chain-id': { type: 'string' },
137
+ 'rpc-url': { type: 'string' },
138
+ 'indexer-url': { type: 'string' },
139
+ 'router-address': { type: 'string' },
140
+ confirmations: { type: 'string' },
141
+ stdin: { type: 'boolean' },
142
+ output: { type: 'string' },
143
+ kind: { type: 'string' },
144
+ limit: { type: 'string' },
145
+ help: { type: 'boolean', short: 'h' },
146
+ },
147
+ });
148
+ if (values.help || positionals.length === 0) {
149
+ process.stdout.write(HELP);
150
+ return;
151
+ }
152
+ const profile = values.profile;
153
+ let config = await loadConfig(profile);
154
+ config = await withOverrides(config, values);
155
+ const command = positionals[0];
156
+ if (command === 'wallet') {
157
+ const operation = positionals[1];
158
+ if (operation === 'create')
159
+ return print({ wallet: await createWallet(config, profile), profile });
160
+ if (operation === 'import') {
161
+ const privateKey = values.stdin ? await readPrivateKeyFromStdin() : await readPrivateKeyFromStdinIfTty();
162
+ return print({ wallet: await createWallet(config, profile, privateKey), profile });
163
+ }
164
+ if (operation === 'export') {
165
+ assertPrivateKeyExportOutputSupported(values.output);
166
+ if (!values.output && !process.stdout.isTTY) {
167
+ throw new AgentError('unsupported', 'Terminal private-key export requires an interactive stdout; use a real terminal or --output PATH');
168
+ }
169
+ const store = await loadKeyStore(config.wallet.keystorePath);
170
+ process.stderr.write('WARNING: Anyone with this private key controls the GWorld wallet. Never paste it into an Agent or chat.\n');
171
+ const confirmation = await promptText(`Type EXPORT ${store.address} to continue: `);
172
+ const exported = await exportWalletPrivateKey(config, confirmation);
173
+ if (values.output) {
174
+ const outputPath = resolve(values.output);
175
+ await savePrivateKeyExport(outputPath, exported.privateKey);
176
+ await new FileAuditLog(config.auditPath).record({
177
+ type: 'lifecycle',
178
+ status: 'wallet_private_key_exported',
179
+ detail: { address: exported.address, destination: 'file' },
180
+ });
181
+ return print({ wallet: exported.address, exportedTo: outputPath, profile });
182
+ }
183
+ process.stdout.write(`${exported.privateKey}\n`);
184
+ await new FileAuditLog(config.auditPath).record({
185
+ type: 'lifecycle',
186
+ status: 'wallet_private_key_exported',
187
+ detail: { address: exported.address, destination: 'terminal' },
188
+ });
189
+ return;
190
+ }
191
+ throw new AgentError('config_invalid', 'wallet command requires create, import, or export');
192
+ }
193
+ if (command === 'mcp')
194
+ return serveMcp(profile);
195
+ if (command === 'pause') {
196
+ await new FileRuntimeState(config.statePath).setPaused(true);
197
+ return print({ state: 'paused', profile });
198
+ }
199
+ await ensureWallet(config, profile);
200
+ const runtime = await unlocked(config, profile);
201
+ if (command === 'join') {
202
+ const result = await runtime.join();
203
+ let installation;
204
+ if (values.client) {
205
+ if (!['auto', 'codex', 'claude'].includes(values.client))
206
+ throw new AgentError('config_invalid', '--client must be auto, codex, or claude');
207
+ installation = await new ClientInstaller().install(values.client, profile);
208
+ }
209
+ return print({ ...result, installation });
210
+ }
211
+ if (command === 'status')
212
+ return print(await runtime.status());
213
+ if (command === 'observe')
214
+ return print(await runtime.observe());
215
+ if (command === 'actions')
216
+ return print({ actions: await runtime.getLegalActions() });
217
+ if (command === 'act') {
218
+ if (!values.kind || !ALL_ACTIONS.includes(values.kind)) {
219
+ throw new AgentError('config_invalid', `--kind must be one of: ${ALL_ACTIONS.join(', ')}`);
220
+ }
221
+ const action = (await runtime.getLegalActions()).find((candidate) => candidate.action.kind === values.kind);
222
+ if (!action)
223
+ throw new AgentError('action_not_found', `No currently legal ${values.kind} action`);
224
+ return print(await runtime.executeAction(action.actionId));
225
+ }
226
+ if (command === 'activity') {
227
+ const limit = values.limit == null ? 50 : Number(values.limit);
228
+ if (!Number.isInteger(limit) || limit < 1 || limit > 500)
229
+ throw new AgentError('config_invalid', '--limit must be 1..500');
230
+ return print({ activity: await runtime.activity(limit) });
231
+ }
232
+ if (command === 'run') {
233
+ print(await runtime.start());
234
+ await new Promise((resolve) => {
235
+ const stop = async () => { await runtime.pause(); resolve(); };
236
+ process.once('SIGINT', stop);
237
+ process.once('SIGTERM', stop);
238
+ });
239
+ return;
240
+ }
241
+ throw new AgentError('config_invalid', `Unknown command: ${command}`);
242
+ }
243
+ async function readPrivateKeyFromStdinIfTty() {
244
+ const value = await promptHidden('Import dedicated GWorld private key: ');
245
+ if (!/^0x[0-9a-fA-F]{64}$/.test(value))
246
+ throw new AgentError('wallet_corrupt', 'Private key must be 32-byte hex');
247
+ return value;
248
+ }
249
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
250
+ main().catch((error) => {
251
+ const safe = sanitizedError(error);
252
+ process.stderr.write(`gworld-agent [${safe.code}]: ${safe.message}\n`);
253
+ process.exitCode = 1;
254
+ });
255
+ }
256
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAEnG,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAoB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO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,CAAC,CAAC;QACvE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type AgentClient = 'codex' | 'claude';
2
+ type Run = (command: string, args: string[], inherit?: boolean) => {
3
+ status: number | null;
4
+ };
5
+ export declare class ClientInstaller {
6
+ private readonly run;
7
+ private readonly skillsHome;
8
+ private readonly skillSource;
9
+ constructor(run?: Run, skillsHome?: string, skillSource?: string);
10
+ detected(): AgentClient[];
11
+ installSkill(): Promise<string>;
12
+ installMcp(client: AgentClient, profile: string): 'installed' | 'already_configured';
13
+ install(client: AgentClient | 'auto', profile: string): Promise<{
14
+ skillPath: string;
15
+ clients: {
16
+ [k: string]: "already_configured" | "installed";
17
+ };
18
+ }>;
19
+ }
20
+ export {};
@@ -0,0 +1,48 @@
1
+ import { cp, mkdir } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { spawnSync } from 'node:child_process';
6
+ import { AgentError } from './errors.js';
7
+ function defaultRun(command, args, inherit = false) {
8
+ return spawnSync(command, args, { stdio: inherit ? 'inherit' : 'ignore' });
9
+ }
10
+ export class ClientInstaller {
11
+ run;
12
+ skillsHome;
13
+ skillSource;
14
+ constructor(run = defaultRun, skillsHome = join(homedir(), '.agents', 'skills'), skillSource = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'skill', 'gworld')) {
15
+ this.run = run;
16
+ this.skillsHome = skillsHome;
17
+ this.skillSource = skillSource;
18
+ }
19
+ detected() {
20
+ return ['codex', 'claude'].filter((client) => this.run(client, ['--version']).status === 0);
21
+ }
22
+ async installSkill() {
23
+ const target = join(this.skillsHome, 'gworld');
24
+ await mkdir(this.skillsHome, { recursive: true });
25
+ await cp(this.skillSource, target, { recursive: true, force: true });
26
+ return target;
27
+ }
28
+ installMcp(client, profile) {
29
+ if (this.run(client, ['mcp', 'get', 'gworld']).status === 0)
30
+ return 'already_configured';
31
+ const launch = ['npx', '--yes', '@colin999n9/gworld-agent@0.1.0-alpha.0', 'mcp', '--profile', profile];
32
+ const args = client === 'codex'
33
+ ? ['mcp', 'add', 'gworld', '--', ...launch]
34
+ : ['mcp', 'add', '--scope', 'user', 'gworld', '--', ...launch];
35
+ const result = this.run(client, args, true);
36
+ if (result.status !== 0)
37
+ throw new AgentError('unsupported', `Unable to register GWorld MCP with ${client}`);
38
+ return 'installed';
39
+ }
40
+ async install(client, profile) {
41
+ const skillPath = await this.installSkill();
42
+ const clients = client === 'auto' ? this.detected() : [client];
43
+ if (clients.length === 0)
44
+ throw new AgentError('unsupported', 'No supported Codex or Claude client was detected');
45
+ return { skillPath, clients: Object.fromEntries(clients.map((name) => [name, this.installMcp(name, profile)])) };
46
+ }
47
+ }
48
+ //# sourceMappingURL=client-installer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-installer.js","sourceRoot":"","sources":["../src/client-installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,SAAS,UAAU,CAAC,OAAe,EAAE,IAAc,EAAE,OAAO,GAAG,KAAK;IAClE,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,OAAO,eAAe;IAEP,GAAG;IACH,UAAU;IACV,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AAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;YAC3C,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,sCAAsC,MAAM,EAAE,CAAC,CAAC;QAC7G,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAA4B,EAAE,OAAe;QACzD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,kDAAkD,CAAC,CAAC;QAClH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnH,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import type { ActionKind, Address, RunnerPolicy } from './domain.js';
2
+ export type NetworkConfig = {
3
+ name: string;
4
+ chainId: number;
5
+ rpcUrl: string;
6
+ indexerUrl: string;
7
+ routerAddress: Address;
8
+ confirmations: number;
9
+ };
10
+ export type NetworkPresetConfig = Pick<NetworkConfig, 'name' | 'chainId' | 'rpcUrl' | 'routerAddress' | 'confirmations'> & Partial<Pick<NetworkConfig, 'indexerUrl'>>;
11
+ export type AgentConfig = {
12
+ version: 1;
13
+ profile: string;
14
+ network: NetworkConfig;
15
+ wallet: {
16
+ keystorePath: string;
17
+ };
18
+ runner: {
19
+ agentId: bigint | null;
20
+ mapRadius: number;
21
+ pollIntervalMs: number;
22
+ actionTtlMs: number;
23
+ indexingTimeoutMs: number;
24
+ };
25
+ policy: RunnerPolicy;
26
+ auditPath: string;
27
+ statePath: string;
28
+ };
29
+ export declare const ALL_ACTIONS: ActionKind[];
30
+ export declare const DEFAULT_ALLOWED_ACTIONS: ActionKind[];
31
+ export declare function gworldHome(): string;
32
+ export declare function configPath(profile?: string): string;
33
+ export declare function networkPreset(name: string): NetworkPresetConfig | null;
34
+ export declare function defaultConfig(profile?: string): AgentConfig;
35
+ export declare function parseConfig(value: unknown): AgentConfig;
36
+ export declare function loadConfig(profile?: string): Promise<AgentConfig>;
37
+ export declare function saveConfig(config: AgentConfig): Promise<void>;