@oneie/cli 5.7.2 → 5.7.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.7.2",
3
+ "version": "5.7.3",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,2 +1,12 @@
1
1
  import { Command } from 'commander';
2
+ interface CatalogItem {
3
+ receiver: string;
4
+ summary?: string;
5
+ effect?: string;
6
+ cost?: unknown;
7
+ reversible?: boolean;
8
+ settles?: string;
9
+ }
10
+ export declare function catalogItems(data: Record<string, unknown>): CatalogItem[];
2
11
  export declare function catalogCommands(program: Command): void;
12
+ export {};
@@ -1,18 +1,9 @@
1
1
  import { askPath } from './lib/api-path.js';
2
+ import { authHeaders } from './lib/client.js';
2
3
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
3
- function apiKey() {
4
- return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
5
- }
6
4
  function base(opts) {
7
5
  return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
8
6
  }
9
- function authHeaders() {
10
- const h = { 'Content-Type': 'application/json' };
11
- const k = apiKey();
12
- if (k)
13
- h['Authorization'] = `Bearer ${k}`;
14
- return h;
15
- }
16
7
  const RECIPE_BLURB = {
17
8
  spine: 'onboard — become an actor, mint a key, declare capability',
18
9
  build: 'build a world — workspace, group, actor, thing',
@@ -50,6 +41,13 @@ function formatCatalog(items, goal) {
50
41
  }
51
42
  return out.join('\n');
52
43
  }
44
+ // The door answers { outcome, result: CatalogItem[] }; older shapes put the list at
45
+ // items / receivers. Reading only those two printed an empty catalog.
46
+ export function catalogItems(data) {
47
+ const r = data.result;
48
+ const list = Array.isArray(r) ? r : r?.items ?? data.items ?? data.receivers ?? [];
49
+ return Array.isArray(list) ? list : [];
50
+ }
53
51
  export function catalogCommands(program) {
54
52
  program
55
53
  .command('catalog')
@@ -72,7 +70,7 @@ export function catalogCommands(program) {
72
70
  process.stdout.write(JSON.stringify(data, null, 2) + '\n');
73
71
  return;
74
72
  }
75
- const items = (data.items ?? data.receivers ?? []);
73
+ const items = catalogItems(data);
76
74
  process.stdout.write(formatCatalog(items, opts.goal) + '\n');
77
75
  });
78
76
  }
@@ -2,7 +2,7 @@ import { Command } from 'commander';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { mergeEnv } from './env.js';
4
4
  import { resolveBase, resolveKey, authHeaders } from './lib/client.js';
5
- import { readKeyFolder, keyFolderStatus } from './lib/keyfile.js';
5
+ import { readKeyFolder, keyFolderStatus, workspaceFor, KEY_DIR_NAME, LEGACY_KEY_DIR_NAME } from './lib/keyfile.js';
6
6
  import { KEY_FILE } from './lib/paths.js';
7
7
  import { askPath } from './lib/api-path.js';
8
8
  /** api.one.ie (the gateway) answers `GET /health`; one.ie/web has no /health
@@ -57,7 +57,7 @@ export async function runDoctor(dir, opts = {}) {
57
57
  name: 'config',
58
58
  ok: hasConfig,
59
59
  detail: folder
60
- ? `${dir}/.oneie/agent.key (0600, project)`
60
+ ? `${dir}/${existsSync(`${dir}/${KEY_DIR_NAME}/agent.key`) ? KEY_DIR_NAME : LEGACY_KEY_DIR_NAME}/agent.key (0600, project)`
61
61
  : hasConfig
62
62
  ? `${keyFile} (0600)`
63
63
  : `${keyFile} missing — run \`one setup\` or \`one login\``,
@@ -124,7 +124,7 @@ export function whoamiCmd() {
124
124
  body: JSON.stringify({ data: {} }),
125
125
  });
126
126
  const live = res.ok;
127
- process.stdout.write(`workspace ${env.WORKSPACE_SLUG ?? env.AGENCY_SLUG ?? '(unset)'}\n`);
127
+ process.stdout.write(`workspace ${env.WORKSPACE_SLUG ?? workspaceFor(undefined, dir, env) ?? '(unset)'}\n`);
128
128
  process.stdout.write(`key ${key.slice(0, 4)}***… ${live ? '(live)' : `(unreachable — ${base})`}\n`);
129
129
  process.stdout.write(`base ${base}\n`);
130
130
  if (!live)
@@ -1 +1,2 @@
1
1
  export declare function askPath(base: string, receiver: string): string;
2
+ export declare function substrateUrl(url: string): string;
@@ -7,3 +7,34 @@ export function askPath(base, receiver) {
7
7
  const isGateway = new URL(base).hostname === 'api.one.ie';
8
8
  return `${base}${isGateway ? '/ask' : '/api/ask'}/${encodeURIComponent(receiver)}`;
9
9
  }
10
+ // The other substrate doors. They were written as one.ie/web's long form (/api/mark/…),
11
+ // which api.one.ie — the default base — answers 404; only /ask knew the host. The map is the
12
+ // inverse of api/src/substrate-binding.ts PATH_MAP, so a path the gateway serves is spelled the
13
+ // way the gateway serves it and every other host keeps the long form.
14
+ const GATEWAY_SHORT = [
15
+ ['/api/export/groups', '/groups'],
16
+ ['/api/export/actors', '/actors'],
17
+ ['/api/export/paths', '/paths'],
18
+ ['/api/signal', '/signal'],
19
+ ['/api/mark', '/mark'],
20
+ ['/api/warn', '/warn'],
21
+ ['/api/fade', '/fade'],
22
+ ['/api/sub', '/sub'],
23
+ ['/api/follow', '/follow'],
24
+ ['/api/select', '/select'],
25
+ ['/api/things', '/things'],
26
+ ['/api/events', '/events'],
27
+ ['/api/learning', '/learning'],
28
+ ];
29
+ export function substrateUrl(url) {
30
+ const u = new URL(url);
31
+ if (u.hostname !== 'api.one.ie')
32
+ return url;
33
+ for (const [long, short] of GATEWAY_SHORT) {
34
+ if (u.pathname === long || u.pathname.startsWith(`${long}/`)) {
35
+ u.pathname = short + u.pathname.slice(long.length);
36
+ return u.toString();
37
+ }
38
+ }
39
+ return url;
40
+ }
@@ -128,3 +128,9 @@ export declare function readKeyFolder(dir: string): {
128
128
  * a silent null is right for `resolveKey` and useless for `doctor`.
129
129
  */
130
130
  export declare function keyFolderStatus(dir: string): 'none' | 'ok' | 'foreign' | 'unsafe' | 'unreadable';
131
+ /**
132
+ * Which workspace a command acts in: flag > AGENCY_SLUG > the workspace `npx oneie`
133
+ * saved beside this folder's key. The journey already knows the agent's workspace;
134
+ * asking for it again was a dead end (`wallet get`, `whoami`).
135
+ */
136
+ export declare function workspaceFor(explicit: string | undefined, dir: string, env: Record<string, string>): string | undefined;
@@ -382,3 +382,16 @@ export function keyFolderStatus(dir) {
382
382
  return 'unreadable';
383
383
  }
384
384
  }
385
+ /**
386
+ * Which workspace a command acts in: flag > AGENCY_SLUG > the workspace `npx oneie`
387
+ * saved beside this folder's key. The journey already knows the agent's workspace;
388
+ * asking for it again was a dead end (`wallet get`, `whoami`).
389
+ */
390
+ export function workspaceFor(explicit, dir, env) {
391
+ if (explicit)
392
+ return explicit;
393
+ if (env.AGENCY_SLUG)
394
+ return env.AGENCY_SLUG;
395
+ const saved = readKeyFolder(dir)?.meta.workspace;
396
+ return typeof saved === 'string' && saved ? saved : undefined;
397
+ }
@@ -1,12 +1,12 @@
1
1
  import { authHeaders, resolveBase, resolveKey } from './lib/client.js';
2
- import { askPath } from './lib/api-path.js';
2
+ import { askPath, substrateUrl } from './lib/api-path.js';
3
3
  import { sendMessage } from './message.js';
4
4
  const DEFAULT_API = resolveBase({}, 'https://api.one.ie');
5
5
  function base(opts) {
6
6
  return resolveBase(opts, 'https://api.one.ie');
7
7
  }
8
8
  async function api(url, init) {
9
- const res = await fetch(url, { headers: authHeaders(), ...init });
9
+ const res = await fetch(substrateUrl(url), { headers: authHeaders(), ...init });
10
10
  if (!res.ok) {
11
11
  const body = await res.text().catch(() => '');
12
12
  process.stderr.write(`${init?.method ?? 'GET'} ${url} → ${res.status}\n${body}\n`);
package/dist/src/trade.js CHANGED
@@ -1,18 +1,9 @@
1
1
  import { askPath } from './lib/api-path.js';
2
+ import { authHeaders } from './lib/client.js';
2
3
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
3
- function apiKey() {
4
- return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
5
- }
6
4
  function base(opts) {
7
5
  return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
8
6
  }
9
- function authHeaders() {
10
- const h = { 'Content-Type': 'application/json' };
11
- const k = apiKey();
12
- if (k)
13
- h['Authorization'] = `Bearer ${k}`;
14
- return h;
15
- }
16
7
  async function ask(b, receiver, data) {
17
8
  const res = await fetch(askPath(b, receiver), {
18
9
  method: 'POST',
@@ -76,12 +67,17 @@ export function tradeCommands(program) {
76
67
  });
77
68
  program
78
69
  .command('earn')
79
- .description('Show credit earned summary (pay:weight)')
70
+ .description('What this workspace has earned — card money waiting, crypto owed, credit balance')
80
71
  .option('--api <url>', 'API base URL', DEFAULT_API)
81
72
  .option('--json', 'Output raw JSON')
82
73
  .action(async (opts) => {
83
- const data = await ask(base(opts), 'pay:weight', {});
84
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
74
+ // pay:weight PAYS for a task (needs to/task/amount); it was never a summary.
75
+ // These two are what an agent key can read, and they answer for its own workspace.
76
+ const [store, credits] = await Promise.all([
77
+ ask(base(opts), 'storefront:balance', {}),
78
+ ask(base(opts), 'credits:balance', {}),
79
+ ]);
80
+ process.stdout.write(JSON.stringify({ storefront: store, credits }, null, 2) + '\n');
85
81
  });
86
82
  program
87
83
  .command('usage')
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
  import { type Derivation, type GeneratedWallet } from '@oneie/sdk/wallet';
3
3
  import { type VaultBlob, type SealOpts } from '@oneie/sdk/vault-file';
4
4
  import { askPath } from './lib/api-path.js';
5
+ import { workspaceFor } from './lib/keyfile.js';
5
6
  export { askPath };
6
7
  type AskEnvelope = {
7
8
  outcome?: string;
@@ -48,6 +49,7 @@ export declare function sealWallet(mnemonic: string, passphrase: string, opts: {
48
49
  }): Promise<VaultBlob>;
49
50
  /** The addresses a sealed vault holds, read under ITS marker — absent is v1. */
50
51
  export declare function openedWallet(blob: VaultBlob, mnemonic: string): Promise<GeneratedWallet>;
52
+ export { workspaceFor };
51
53
  export declare function faucetOk(results: Array<{
52
54
  success: boolean;
53
55
  }>): boolean;
@@ -6,6 +6,8 @@ import { generateWallet, recoverWallet, readDerivation } from '@oneie/sdk/wallet
6
6
  import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
7
7
  import { proveAddresses } from '@oneie/sdk/address-proof';
8
8
  import { askPath } from './lib/api-path.js';
9
+ import { workspaceFor } from './lib/keyfile.js';
10
+ import { resolveKey } from './lib/client.js';
9
11
  import { wordsStdoutRefusal } from './lib/agent-env.js';
10
12
  import { cliPrefix } from './lib/invoked-as.js';
11
13
  import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
@@ -98,14 +100,14 @@ export async function openedWallet(blob, mnemonic) {
98
100
  }
99
101
  function resolveAuth(opts) {
100
102
  const env = mergeEnv(process.cwd());
101
- const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
103
+ const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? resolveKey();
102
104
  return { base: opts.api.replace(/\/$/, ''), key };
103
105
  }
106
+ export { workspaceFor };
104
107
  function resolveWorkspace(explicit) {
105
- const env = mergeEnv(process.cwd());
106
- const workspace = explicit ?? env.AGENCY_SLUG;
108
+ const workspace = workspaceFor(explicit, process.cwd(), mergeEnv(process.cwd()));
107
109
  if (!workspace) {
108
- process.stderr.write('--workspace required (or set AGENCY_SLUG)\n');
110
+ process.stderr.write('--workspace required (or set AGENCY_SLUG, or run from the folder `npx oneie` made)\n');
109
111
  process.exit(1);
110
112
  }
111
113
  return workspace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.7.2",
3
+ "version": "5.7.3",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {