@oneie/cli 5.7.5 → 5.8.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/README.md +19 -0
- package/dist/package.json +5 -2
- package/dist/src/balances.d.ts +89 -0
- package/dist/src/balances.js +202 -0
- package/dist/src/ceiling.d.ts +36 -0
- package/dist/src/ceiling.js +189 -0
- package/dist/src/check.d.ts +11 -0
- package/dist/src/check.js +53 -0
- package/dist/src/credits.d.ts +29 -0
- package/dist/src/credits.js +88 -0
- package/dist/src/hl-run.d.ts +119 -0
- package/dist/src/hl-run.js +480 -0
- package/dist/src/hl.d.ts +17 -0
- package/dist/src/hl.js +148 -0
- package/dist/src/index.js +15 -1
- package/dist/src/join.js +4 -0
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +70 -20
- package/dist/src/lib/check-words.d.ts +57 -0
- package/dist/src/lib/check-words.js +144 -0
- package/dist/src/lib/hl-core/actions.d.ts +99 -0
- package/dist/src/lib/hl-core/actions.js +69 -0
- package/dist/src/lib/hl-core/eip712.d.ts +33 -0
- package/dist/src/lib/hl-core/eip712.js +107 -0
- package/dist/src/lib/hl-core/errors.d.ts +10 -0
- package/dist/src/lib/hl-core/errors.js +15 -0
- package/dist/src/lib/hl-core/exchange.d.ts +24 -0
- package/dist/src/lib/hl-core/exchange.js +47 -0
- package/dist/src/lib/hl-core/index.d.ts +13 -0
- package/dist/src/lib/hl-core/index.js +14 -0
- package/dist/src/lib/hl-core/meta.d.ts +57 -0
- package/dist/src/lib/hl-core/meta.js +110 -0
- package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
- package/dist/src/lib/hl-core/msgpack.js +136 -0
- package/dist/src/lib/hl-core/net.d.ts +2 -0
- package/dist/src/lib/hl-core/net.js +7 -0
- package/dist/src/lib/hl-core/signing.d.ts +103 -0
- package/dist/src/lib/hl-core/signing.js +295 -0
- package/dist/src/lib/hl-core/wire.d.ts +34 -0
- package/dist/src/lib/hl-core/wire.js +81 -0
- package/dist/src/lib/journey-words.d.ts +54 -3
- package/dist/src/lib/journey-words.js +162 -20
- package/dist/src/lib/journey.d.ts +2 -0
- package/dist/src/lib/journey.js +21 -2
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/net-choice.d.ts +28 -0
- package/dist/src/lib/net-choice.js +72 -0
- package/dist/src/lib/network.d.ts +22 -0
- package/dist/src/lib/network.js +50 -0
- package/dist/src/lib/next-words.d.ts +105 -0
- package/dist/src/lib/next-words.js +298 -0
- package/dist/src/lib/qr.d.ts +21 -0
- package/dist/src/lib/qr.js +402 -0
- package/dist/src/lib/sale-card.d.ts +117 -0
- package/dist/src/lib/sale-card.js +261 -0
- package/dist/src/lib/sui-grpc-send.d.ts +90 -0
- package/dist/src/lib/sui-grpc-send.js +128 -0
- package/dist/src/lib/timed-fetch.d.ts +33 -0
- package/dist/src/lib/timed-fetch.js +59 -0
- package/dist/src/lib/vaultfile.d.ts +15 -0
- package/dist/src/lib/vaultfile.js +28 -1
- package/dist/src/lib/wallet-money.d.ts +222 -0
- package/dist/src/lib/wallet-money.js +578 -0
- package/dist/src/lib/wallet-request.d.ts +50 -0
- package/dist/src/lib/wallet-request.js +86 -0
- package/dist/src/move.d.ts +36 -0
- package/dist/src/move.js +152 -0
- package/dist/src/network-cmd.d.ts +17 -0
- package/dist/src/network-cmd.js +74 -0
- package/dist/src/next.d.ts +12 -0
- package/dist/src/next.js +67 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop-buy.d.ts +16 -0
- package/dist/src/shop-buy.js +101 -0
- package/dist/src/shop.js +40 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.d.ts +12 -0
- package/dist/src/start.js +51 -21
- package/dist/src/thread.d.ts +2 -0
- package/dist/src/thread.js +52 -0
- package/dist/src/wallet-money.d.ts +158 -0
- package/dist/src/wallet-money.js +664 -0
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +290 -27
- package/dist/src/workflow.js +4 -1
- package/package.json +5 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { nextFor } from './next-words.js';
|
|
1
2
|
const STEPS = [
|
|
2
|
-
{ step: 'key', title: 'Your key', line: 'Your agent makes its own key on this machine, and its wallets.',
|
|
3
|
+
{ step: 'key', title: 'Your key', line: 'Your agent makes its own key on this machine, and its wallets. On a Mac it locks in the Keychain; at a terminal you type a passphrase.',
|
|
3
4
|
why: 'Whoever holds the key holds the money. Here that is this machine, not ONE.' },
|
|
4
5
|
{ step: 'products', title: 'Your product', line: 'It opens a shop and makes a product with its own checkout page.',
|
|
5
6
|
why: 'A checkout page is how anyone, a person or an agent, pays you.' },
|
|
@@ -25,25 +26,45 @@ export function box(lines) {
|
|
|
25
26
|
const w = Math.max(...lines.map((l) => [...l].length));
|
|
26
27
|
return ['╭' + '─'.repeat(w + 4) + '╮', ...lines.map((l) => `│ ${l}${' '.repeat(w - [...l].length)} │`), '╰' + '─'.repeat(w + 4) + '╯'];
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// Line two is beat 1's line in text/one.md § The VSL: the benefit, before any step.
|
|
30
|
+
const HEADER = box(['ONE · Give your agents financial superpowers', 'Your agent can sell and be paid. Here is how.']);
|
|
31
|
+
/**
|
|
32
|
+
* The eight beats of text/one.md § The VSL, in the script's order and words: the same story the home
|
|
33
|
+
* page, its chat and its film tell. Each carries the one command that does it where the CLI has one
|
|
34
|
+
* (a beat without one is told, not run). Beat 4's send is a screen: the CLI never signs a send.
|
|
35
|
+
* Lines the script holds back until their row is true (Apple Pay, "earnings come back") are not said here.
|
|
36
|
+
* `journey-words.test.ts` reads the beat names from the script, so a reorder there goes red here.
|
|
37
|
+
*/
|
|
38
|
+
const BEATS = [
|
|
39
|
+
{ label: 'The sale', line: 'Your agent sells on your site, in a chat, or by link.' },
|
|
40
|
+
{ label: 'The call', line: 'Tell it what you sell. It makes a link for each.', run: (c) => `${c} --product "Mug=12.50"` },
|
|
41
|
+
{ label: 'Cards', line: 'You pay Stripe\'s cost. ONE adds nothing.' },
|
|
42
|
+
{ label: 'Crypto', line: 'By default USDC goes straight to you. ONE takes 0%.', run: () => 'https://one.ie/wallets, once you own it' },
|
|
43
|
+
{ label: 'The key', line: 'Your machine makes it. Nobody else has it.', run: (c) => `${c} wallet paper` },
|
|
44
|
+
{ label: 'Your agents', line: 'Its own wallet, and a credit limit only you can raise.', run: (c) => `${c} wallet get` },
|
|
45
|
+
{ label: 'Do it now', line: 'Pay your own link with a test card. Watch it land.', run: (c) => c },
|
|
46
|
+
{ label: 'The gift', line: 'It was free. Then Sold, the course.', run: () => 'https://one.ie/sold' },
|
|
47
|
+
];
|
|
48
|
+
/** Shown before a first run: the story in eight lines, then what the run does. Nothing here waits on the network. */
|
|
30
49
|
export function journeyIntro(cli) {
|
|
31
|
-
const
|
|
50
|
+
const w = Math.max(...BEATS.map((s) => s.label.length));
|
|
51
|
+
const pad = ' '.repeat(w + 7);
|
|
32
52
|
return [
|
|
33
53
|
...HEADER,
|
|
34
54
|
'',
|
|
35
|
-
|
|
36
|
-
'',
|
|
37
|
-
...STEPS.map((s, i) => ` ${i + 1}. ${s.title.padEnd(width)} ${s.line}`),
|
|
55
|
+
...BEATS.flatMap((s, i) => [` ${i + 1} ${s.label.padEnd(w)} ${s.line}`, ...(s.run ? [`${pad}${s.run(cli)}`] : [])]),
|
|
38
56
|
'',
|
|
39
|
-
|
|
57
|
+
`Run ${cli}. It walks four checks:`,
|
|
58
|
+
` ${STEPS.map((s) => s.title).join(', ')}.`,
|
|
59
|
+
'You are in control. The sale is a test card, so no real money moves.',
|
|
60
|
+
'Nothing secret is printed.',
|
|
40
61
|
`Stop at any step. Run ${cli} again and it picks up where it left off.`,
|
|
41
62
|
'',
|
|
42
63
|
].join('\n') + '\n';
|
|
43
64
|
}
|
|
44
65
|
/** Shown before a re-run. */
|
|
45
|
-
export function journeyResume(
|
|
46
|
-
return [...HEADER, '', `Picking up where you left off,
|
|
66
|
+
export function journeyResume(group) {
|
|
67
|
+
return [...HEADER, '', `Picking up where you left off, in group ${group}.`, '', ''].join('\n');
|
|
47
68
|
}
|
|
48
69
|
function addressLines(addresses) {
|
|
49
70
|
const seen = new Set();
|
|
@@ -88,7 +109,7 @@ function keyLines(s, cli) {
|
|
|
88
109
|
];
|
|
89
110
|
}
|
|
90
111
|
return [
|
|
91
|
-
'Your agent made its own key, here on this machine. ONE never saw it.',
|
|
112
|
+
'Your agent made its own wallet key, here on this machine. ONE never saw it. ONE issued a separate API key.',
|
|
92
113
|
keychain ? 'It is locked in your Apple Keychain. Touch ID opens it.' : 'It is locked with the passphrase you chose.',
|
|
93
114
|
'',
|
|
94
115
|
n > 0
|
|
@@ -116,16 +137,17 @@ function productLines(s, cli) {
|
|
|
116
137
|
}),
|
|
117
138
|
];
|
|
118
139
|
}
|
|
119
|
-
function saleLines(s, cli) {
|
|
140
|
+
function saleLines(s, cli, net = 'testnet') {
|
|
120
141
|
if (s.status === 'failed')
|
|
121
142
|
return failed(s, cli);
|
|
122
143
|
if (s.status === 'done') {
|
|
123
144
|
const n = Number(s.detail.purchases ?? 1);
|
|
124
|
-
return [`${n === 1 ? 'One sale' : `${n} sales`} counted, read back from your shop. Test money: nothing real moved.`];
|
|
145
|
+
return [`${n === 1 ? 'One sale' : `${n} sales`} counted, read back from your shop. ${net === 'testnet' ? 'Test money' : 'Test sale'}: nothing real moved.`];
|
|
125
146
|
}
|
|
126
147
|
const [number, ...rest] = String(s.detail.card ?? '').split(' · ');
|
|
127
148
|
return [
|
|
128
|
-
|
|
149
|
+
// Two whole lines, not a template: home-journey.test.ts holds the page's mirror of this line to the source text.
|
|
150
|
+
net === 'testnet' ? 'Nothing sold yet. Make the first sale yourself, with test money:' : 'Nothing sold yet. Make the first sale yourself, with a test card:',
|
|
129
151
|
'',
|
|
130
152
|
` 1. Open this page ${String(s.detail.pay ?? '')}`,
|
|
131
153
|
` 2. Pay with test card ${number}`,
|
|
@@ -135,7 +157,7 @@ function saleLines(s, cli) {
|
|
|
135
157
|
'No real card is charged. The sale counts only once your shop reads it back.',
|
|
136
158
|
];
|
|
137
159
|
}
|
|
138
|
-
function handoverLines(s, cli) {
|
|
160
|
+
function handoverLines(s, cli, net = 'testnet') {
|
|
139
161
|
if (s.status === 'failed')
|
|
140
162
|
return failed(s, cli);
|
|
141
163
|
if (s.status === 'waiting')
|
|
@@ -147,14 +169,16 @@ function handoverLines(s, cli) {
|
|
|
147
169
|
...(s.detail.emailed ? [`We also sent it to ${String(s.detail.emailed)}.`] : []),
|
|
148
170
|
'',
|
|
149
171
|
'Keep it private. Anyone with this link can claim the owner seat.',
|
|
150
|
-
|
|
172
|
+
`It works once and lasts 7 days. Sales stay ${net === 'testnet' ? 'on test money' : 'in test mode'} until you take the shop live.`,
|
|
151
173
|
];
|
|
152
174
|
}
|
|
153
175
|
const LINES = {
|
|
154
176
|
key: keyLines, products: productLines, sale: saleLines, handover: handoverLines,
|
|
155
177
|
};
|
|
156
178
|
/** The whole report, in words. */
|
|
179
|
+
/** `opts.net` is the network the API runs on (lib/network.ts); unset reads as testnet, today's words. */
|
|
157
180
|
export function journeyWords(r, cli, opts = {}) {
|
|
181
|
+
const net = opts.net ?? 'testnet';
|
|
158
182
|
const out = [];
|
|
159
183
|
r.steps.forEach((s) => {
|
|
160
184
|
const n = STEPS.findIndex((x) => x.step === s.step);
|
|
@@ -163,19 +187,23 @@ export function journeyWords(r, cli, opts = {}) {
|
|
|
163
187
|
out.push(`${MARK[s.status] ?? '?'} ${n + 1} of ${STEPS.length} ${title}${tag}`);
|
|
164
188
|
if (STEPS[n] && !s.reused && s.status !== 'failed')
|
|
165
189
|
out.push(` Why it matters: ${STEPS[n].why}`, '');
|
|
166
|
-
out.push(...indent((LINES[s.step] ?? ((x) => failed(x, cli)))(s, cli)), '');
|
|
190
|
+
out.push(...indent((LINES[s.step] ?? ((x) => failed(x, cli)))(s, cli, net)), '');
|
|
167
191
|
});
|
|
168
192
|
// Steps never reached (an early stop) still show, so the person sees the whole path.
|
|
169
193
|
for (let i = r.steps.length; i < STEPS.length; i++) {
|
|
170
194
|
out.push(`· ${i + 1} of ${STEPS.length} ${STEPS[i].title}`, ` Not started. ${STEPS[i].line}`, '');
|
|
171
195
|
}
|
|
172
|
-
const
|
|
196
|
+
const have = haveLines(haveNow(r, cli, { net }), cli, r);
|
|
197
|
+
if (have.length)
|
|
198
|
+
out.push(...have, '');
|
|
199
|
+
const panel = superpowers(r, cli, net);
|
|
173
200
|
if (panel.length)
|
|
174
201
|
out.push(...panel, '');
|
|
175
202
|
// The one thing to do now goes last, under everything, where the eye lands.
|
|
176
203
|
const allDone = r.ok && r.steps.length === STEPS.length && r.steps.every((s) => s.status === 'done');
|
|
177
204
|
if (allDone) {
|
|
178
205
|
out.push('Done. Your agent has a key, a shop and a first test sale, and you hold the link that makes it yours.');
|
|
206
|
+
out.push(`Next: ${cli} next (what you are, what you can do, and the one thing to do now)`);
|
|
179
207
|
}
|
|
180
208
|
else if (r.next) {
|
|
181
209
|
const next = spell(r.next, cli).replaceAll('`', '');
|
|
@@ -192,7 +220,7 @@ export function journeyWords(r, cli, opts = {}) {
|
|
|
192
220
|
* key and the group are read from .one/). Sending is the one move the CLI does not
|
|
193
221
|
* sign, so it is told as the screen that does, never as a command.
|
|
194
222
|
*/
|
|
195
|
-
export function superpowers(r, cli) {
|
|
223
|
+
export function superpowers(r, cli, net = 'testnet') {
|
|
196
224
|
const key = r.steps.find((s) => s.step === 'key');
|
|
197
225
|
if (!key || key.status !== 'done')
|
|
198
226
|
return [];
|
|
@@ -200,7 +228,10 @@ export function superpowers(r, cli) {
|
|
|
200
228
|
const sui = addresses.sui ?? '<your Sui address>';
|
|
201
229
|
const moves = [
|
|
202
230
|
{ what: 'See your balances', say: 'show my balances', run: `${cli} wallet get` },
|
|
203
|
-
|
|
231
|
+
// Testnet has a faucet. Mainnet has none: the wallet starts empty, and about 0.005 SUI covers a send.
|
|
232
|
+
net === 'testnet'
|
|
233
|
+
? { what: 'Get free test coins', say: 'fill my wallet with test coins', run: `${cli} wallet faucet ${sui} --chain sui --network testnet` }
|
|
234
|
+
: { what: 'Fund your wallet', say: 'what does my wallet need?', run: `Send SUI to ${sui}` }, // the "starts empty, 0.005 SUI" line is the panel's Network row
|
|
204
235
|
{ what: 'Sell something new', say: 'sell a mug for $12.50', run: `${cli} --product "Mug=12.50"` },
|
|
205
236
|
{ what: 'See what came in', say: 'what payments came in?', run: `${cli} wallet transactions` },
|
|
206
237
|
{ what: 'Ask ONE anything', say: 'how do I get paid in USDC?', run: `${cli} message "how do I get paid in USDC?"` },
|
|
@@ -219,3 +250,114 @@ export function superpowers(r, cli) {
|
|
|
219
250
|
` Every command: ${cli} --help`,
|
|
220
251
|
];
|
|
221
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* The line a person pastes into Claude Code, Codex or any other agent to start it. It opens on the
|
|
255
|
+
* benefit and ends on the page's command (one.ie `START_COMMAND`); the middle is the page's own
|
|
256
|
+
* `launchHandoff().short`: "Read https://one.ie/llms.txt, then run: npx oneie". `npx`, never `one`:
|
|
257
|
+
* the agent it goes to may not have this install.
|
|
258
|
+
*/
|
|
259
|
+
export const AGENT_PROMPT = 'Your agent can sell and be paid. Read https://one.ie/llms.txt, then run: npx oneie';
|
|
260
|
+
const HAVE_CHAINS = [
|
|
261
|
+
['sui', 'Sui', 'sui'], ['evm', 'EVM', 'evm'], ['sol', 'Solana', 'sol'], ['btc', 'Bitcoin', 'btc'], ['asi', 'ASI', 'asi'],
|
|
262
|
+
];
|
|
263
|
+
/** Read from the report and nothing else: a fact the run did not produce is null, never filled in. */
|
|
264
|
+
export function haveNow(r, cli, opts = {}) {
|
|
265
|
+
const get = (step) => r.steps.find((s) => s.step === step);
|
|
266
|
+
const key = get('key');
|
|
267
|
+
const kd = key?.detail ?? {};
|
|
268
|
+
const found = (kd.addresses && typeof kd.addresses === 'object' ? kd.addresses : {});
|
|
269
|
+
const pick = (k) => {
|
|
270
|
+
const names = CHAINS.find((c) => c.keys.includes(k)).keys;
|
|
271
|
+
const hit = names.find((n) => typeof found[n] === 'string' && found[n]);
|
|
272
|
+
return hit ? found[hit] : null;
|
|
273
|
+
};
|
|
274
|
+
const wallet = key?.status === 'done' && typeof kd.wallet === 'string' && kd.wallet ? kd.wallet : null;
|
|
275
|
+
const group = typeof kd.workspace === 'string' && kd.workspace ? kd.workspace : (r.workspace ?? null);
|
|
276
|
+
const products = (Array.isArray(get('products')?.detail.products) ? get('products').detail.products.map(String) : []).flatMap((p) => {
|
|
277
|
+
const m = /^(.*) (\d+\.\d{2}) ([A-Z]{3}) (\S+)$/.exec(p);
|
|
278
|
+
return m ? [{ name: m[1], price: m[2], currency: m[3], url: m[4] }] : [];
|
|
279
|
+
});
|
|
280
|
+
const sale = get('sale');
|
|
281
|
+
// The same answer `one next` gives from the folder: one table of stage → command (next-words.ts).
|
|
282
|
+
const stage = !key || key.status !== 'done' ? 'wallet' : get('products')?.status !== 'done' ? 'shop' : sale?.status === 'done' ? 'sold' : 'sale';
|
|
283
|
+
const next = nextFor(stage, cli).command;
|
|
284
|
+
return {
|
|
285
|
+
key: { file: wallet ? wallet.split(/[\\/]/).slice(-2).join('/') : null, sealed: wallet && typeof kd.sealed === 'string' ? kd.sealed : null },
|
|
286
|
+
addresses: { sui: pick('sui'), evm: pick('evm'), sol: pick('sol'), btc: pick('btc'), asi: pick('asi') },
|
|
287
|
+
group,
|
|
288
|
+
shop: { products },
|
|
289
|
+
limit: { credits: typeof kd.limit === 'number' ? kd.limit : null, command: `${cli} wallet limit ${group ?? '<group>'} <credits>` },
|
|
290
|
+
network: opts.net ?? 'testnet',
|
|
291
|
+
next,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const shorten = (a) => (a.length > 14 ? `${a.slice(0, 6)}\u2026${a.slice(-4)}` : a);
|
|
295
|
+
/** "text" cut into lines of at most `w` columns, on spaces. */
|
|
296
|
+
function wrap(text, w) {
|
|
297
|
+
const out = [];
|
|
298
|
+
for (const word of text.split(' ')) {
|
|
299
|
+
const last = out.at(-1);
|
|
300
|
+
if (last !== undefined && [...last].length + 1 + [...word].length <= w)
|
|
301
|
+
out[out.length - 1] = `${last} ${word}`;
|
|
302
|
+
else
|
|
303
|
+
out.push(word);
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* "What you have now": a compact inventory of what this run made, told again on every later run.
|
|
309
|
+
* One row per fact, short enough for 72 columns; an unknown row says "not yet" and the command that fills it.
|
|
310
|
+
* A run that made no group at all (the first call refused) has nothing to inventory, so nothing prints.
|
|
311
|
+
*/
|
|
312
|
+
export function haveLines(h, cli, r) {
|
|
313
|
+
if (!h.group)
|
|
314
|
+
return [];
|
|
315
|
+
const row = (label, value) => ` ${label.padEnd(9)}${value}`;
|
|
316
|
+
const cont = (value) => ` ${' '.repeat(9)}${value}`;
|
|
317
|
+
const none = (cmd) => `not yet. ${cmd}`;
|
|
318
|
+
const rows = [];
|
|
319
|
+
rows.push(row('Key', h.key.file ? `${h.key.file}, on this machine. Nobody else has it.` : none(cli)));
|
|
320
|
+
const known = HAVE_CHAINS.filter(([k]) => h.addresses[k]);
|
|
321
|
+
if (known.length === 0)
|
|
322
|
+
rows.push(row('Wallets', none(cli)));
|
|
323
|
+
else
|
|
324
|
+
for (const [k, label] of HAVE_CHAINS)
|
|
325
|
+
rows.push(row(label, h.addresses[k] ? shorten(h.addresses[k]) : none(`${cli} wallet get`)));
|
|
326
|
+
rows.push(row('Group', h.group));
|
|
327
|
+
const [first, ...more] = h.shop.products;
|
|
328
|
+
if (!first)
|
|
329
|
+
rows.push(row('Shop', none(`${cli} --product "Mug=12.50"`)));
|
|
330
|
+
else {
|
|
331
|
+
rows.push(row('Shop', `${first.name} ${first.price} ${first.currency}${more.length ? ` and ${more.length} more` : ''}`), cont(first.url));
|
|
332
|
+
}
|
|
333
|
+
rows.push(row('Limit', h.limit.credits !== null ? `${h.limit.credits} credits a month` : none(h.limit.command)));
|
|
334
|
+
rows.push(row('Network', h.network === 'testnet' ? 'testnet. Test coins are free. No real money moves.' : 'mainnet. It starts empty. About 0.005 SUI covers a send.'));
|
|
335
|
+
const salePending = r.steps.find((s) => s.step === 'sale')?.status === 'pending';
|
|
336
|
+
rows.push(row('Next', salePending ? `${h.next} after you pay the test link` : h.next));
|
|
337
|
+
return [
|
|
338
|
+
...box(['What you have now']),
|
|
339
|
+
'',
|
|
340
|
+
...rows,
|
|
341
|
+
'',
|
|
342
|
+
// The wallet a first run makes is empty; this is the way to fill it without the agent ever holding the owner's key.
|
|
343
|
+
` Needs money? ${cli} wallet request 5 USDC`,
|
|
344
|
+
' Your owner gets a link and presses Touch ID.',
|
|
345
|
+
'',
|
|
346
|
+
' Another agent? Paste this into it:',
|
|
347
|
+
...wrap(AGENT_PROMPT, 62).map((l) => ` ${l}`),
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
/** The same words for a terminal that cannot draw boxes or glyphs: a pipe, NO_COLOR, a log. */
|
|
351
|
+
export function asciiOf(text) {
|
|
352
|
+
return text
|
|
353
|
+
.replace(/[\u256d\u256e\u2570\u256f]/g, '+')
|
|
354
|
+
.replace(/\u2500/g, '-')
|
|
355
|
+
.replace(/\u2502/g, '|')
|
|
356
|
+
.replace(/\u2026/g, '...')
|
|
357
|
+
.replace(/\u2713/g, 'ok')
|
|
358
|
+
.replace(/\u2717/g, 'x')
|
|
359
|
+
.replace(/\u00b7/g, '-')
|
|
360
|
+
.replace(/\u2193/g, 'v')
|
|
361
|
+
.replace(/\u2014/g, '-')
|
|
362
|
+
.replace(/[^\x00-\x7f]/g, '?');
|
|
363
|
+
}
|
|
@@ -90,6 +90,8 @@ export interface JourneyDeps {
|
|
|
90
90
|
ask(key: string, receiver: string, data: Record<string, unknown>): Promise<AskEnvelope>;
|
|
91
91
|
sleep(ms: number): Promise<void>;
|
|
92
92
|
now(): number;
|
|
93
|
+
/** A progress line for the person watching (stderr). A wait with no line reads as a hang. */
|
|
94
|
+
say?(line: string): void;
|
|
93
95
|
}
|
|
94
96
|
export interface JourneyOptions {
|
|
95
97
|
api: string;
|
package/dist/src/lib/journey.js
CHANGED
|
@@ -166,8 +166,24 @@ async function saleStep(deps, o, state, key, rerun) {
|
|
|
166
166
|
const waitS = o.waitSeconds !== undefined && Number.isFinite(asked) ? Math.max(0, asked) : rerun ? RERUN_WAIT_S : 0;
|
|
167
167
|
const pollMs = o.pollMs ?? (o.waitSeconds === undefined ? RERUN_POLL_MS : 5000);
|
|
168
168
|
const deadline = deps.now() + waitS * 1000;
|
|
169
|
+
if (waitS > 0)
|
|
170
|
+
deps.say?.(`Checking for the test sale, for up to ${waitS} seconds…`);
|
|
171
|
+
// A poll the server never answered is a miss, not a verdict: keep to the deadline.
|
|
172
|
+
// Only a wait in which NOTHING answered ends as failed, with the reason named.
|
|
173
|
+
let answered = false;
|
|
174
|
+
let silent = '';
|
|
169
175
|
for (;;) {
|
|
170
|
-
const
|
|
176
|
+
const env = await deps.ask(key, 'storefront:stats', { slug: state.workspace });
|
|
177
|
+
if (env.outcome === 'no_answer') {
|
|
178
|
+
silent = env.error ?? 'storefront:stats did not answer';
|
|
179
|
+
if (deps.now() >= deadline)
|
|
180
|
+
break;
|
|
181
|
+
deps.say?.(`one.ie did not answer that check. Trying again…`);
|
|
182
|
+
await deps.sleep(pollMs);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
answered = true;
|
|
186
|
+
const r = readAnswer(env, 'storefront:stats');
|
|
171
187
|
if (!r.ok)
|
|
172
188
|
return { step: 'sale', status: 'failed', detail: { error: r.error } };
|
|
173
189
|
// An answer with no count is not zero purchases: an entitlement or credit gate
|
|
@@ -190,6 +206,9 @@ async function saleStep(deps, o, state, key, rerun) {
|
|
|
190
206
|
break;
|
|
191
207
|
await deps.sleep(pollMs);
|
|
192
208
|
}
|
|
209
|
+
if (!answered) {
|
|
210
|
+
return { step: 'sale', status: 'failed', detail: { error: `${silent}. Your shop is saved in this folder. Run \`npx oneie\` again in a minute` } };
|
|
211
|
+
}
|
|
193
212
|
const first = state.products?.[0];
|
|
194
213
|
return {
|
|
195
214
|
step: 'sale',
|
|
@@ -239,7 +258,7 @@ export async function runJourney(deps, o) {
|
|
|
239
258
|
steps.push(handover);
|
|
240
259
|
const failed = steps.some((s) => s.status === 'failed');
|
|
241
260
|
const next = sale.status === 'pending'
|
|
242
|
-
?
|
|
261
|
+
? `pay with the test card at the link above, then run \`npx oneie\` again. It waits up to ${RERUN_WAIT_S} seconds for the sale to land. Or run \`npx oneie --wait 30\` to wait here while you pay`
|
|
243
262
|
: undefined;
|
|
244
263
|
return { ok: !failed, workspace: state.workspace, steps, ...(next ? { next } : {}) };
|
|
245
264
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface KeySource {
|
|
2
|
+
/** Human words: `--key`, `$ONE_API_KEY`, `~/.config/one/key`, `./.env.local` … — a place, never a value. */
|
|
3
|
+
label: string;
|
|
4
|
+
/** True when the key was found in the current folder (.env.local, .env, .one/key). */
|
|
5
|
+
local: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function keySourceOf(opts: {
|
|
8
|
+
key?: string;
|
|
9
|
+
}, cwd?: string, env?: NodeJS.ProcessEnv): KeySource;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-source.ts — WHERE the key a money command acts with came from, never the key itself.
|
|
3
|
+
*
|
|
4
|
+
* The wallet commands resolve their key in this order (wallet.ts `resolveAuth`): --key, then
|
|
5
|
+
* ONEIE_API_KEY / ONE_API_KEY from the shell, `<cwd>/.env.local`, `<cwd>/.env` (shell wins per
|
|
6
|
+
* variable), then the folder's own `.one/key`, then the machine login. Four of the six are read
|
|
7
|
+
* from the CURRENT FOLDER — so the same command can act as a different actor from a different
|
|
8
|
+
* directory. That order is kept (`one init --write-env` writes `.env.local` on purpose); this file
|
|
9
|
+
* only makes the choice visible: a label for the header, and whether it came from the folder.
|
|
10
|
+
*/
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { readEnvFile } from '../env.js';
|
|
14
|
+
import { readKeyFolder } from './keyfile.js';
|
|
15
|
+
import { firstExisting, KEY_FILE, LEGACY_KEY_FILE } from './paths.js';
|
|
16
|
+
const tilde = (p) => (p.startsWith(homedir()) ? `~${p.slice(homedir().length)}` : p);
|
|
17
|
+
export function keySourceOf(opts, cwd = process.cwd(), env = process.env) {
|
|
18
|
+
if (opts.key)
|
|
19
|
+
return { label: '--key', local: false };
|
|
20
|
+
const files = [join(cwd, '.env.local'), join(cwd, '.env')];
|
|
21
|
+
const parsed = files.map((f) => ({ f, vars: readEnvFile(f) }));
|
|
22
|
+
for (const name of ['ONEIE_API_KEY', 'ONE_API_KEY']) {
|
|
23
|
+
if (env[name])
|
|
24
|
+
return { label: `$${name}`, local: false };
|
|
25
|
+
const hit = parsed.find((p) => p.vars[name]);
|
|
26
|
+
if (hit)
|
|
27
|
+
return { label: `./${hit.f.split('/').pop()}`, local: true };
|
|
28
|
+
}
|
|
29
|
+
if (readKeyFolder(cwd))
|
|
30
|
+
return { label: './.one/key', local: true };
|
|
31
|
+
const machine = firstExisting(KEY_FILE, LEGACY_KEY_FILE);
|
|
32
|
+
return { label: machine ? tilde(machine) : 'no key', local: false };
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Net } from './network.js';
|
|
2
|
+
export type NetFrom = 'flag' | 'env' | 'saved' | 'deploy';
|
|
3
|
+
export type NetChoice = {
|
|
4
|
+
ok: true;
|
|
5
|
+
net: Net;
|
|
6
|
+
from: NetFrom;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: 'bad_net' | 'network_unknown';
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const NET_FILE: string;
|
|
13
|
+
export declare function savedNet(path?: string): Net | null;
|
|
14
|
+
/** Save a choice, or clear it with null (`one network auto`). */
|
|
15
|
+
export declare function saveNet(net: Net | null, path?: string): void;
|
|
16
|
+
/** The page that carries the deploy's meta tag: the web host, never the gateway (api.one.ie serves no page). */
|
|
17
|
+
export declare function webBase(api?: string): string;
|
|
18
|
+
export interface NetDeps {
|
|
19
|
+
env: Record<string, string | undefined>;
|
|
20
|
+
saved: () => Net | null;
|
|
21
|
+
deploy: (base: string) => Promise<Net | null>;
|
|
22
|
+
}
|
|
23
|
+
export declare function resolveNet(flag: string | undefined, api?: string, deps?: NetDeps): Promise<NetChoice>;
|
|
24
|
+
/** The one line every money command prints: the network, and where the choice came from. */
|
|
25
|
+
export declare function netLine(c: {
|
|
26
|
+
net: Net;
|
|
27
|
+
from: NetFrom;
|
|
28
|
+
}): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* net-choice.ts — which network a chain command acts on. ONE rule for every command that touches a chain:
|
|
3
|
+
*
|
|
4
|
+
* 1. --net <mainnet|testnet> this one command
|
|
5
|
+
* 2. ONE_NETWORK=<mainnet|testnet> this shell
|
|
6
|
+
* 3. `one network mainnet|testnet` saved in ~/.config/one/network, until `one network auto`
|
|
7
|
+
* 4. the deploy what one.ie says it runs (<meta name="one:network">)
|
|
8
|
+
*
|
|
9
|
+
* The answer always says where it came from. When nothing above names a network and the deploy cannot be read,
|
|
10
|
+
* the answer is a refusal (`network_unknown`), never a guess — a command that moves money must not assume testnet.
|
|
11
|
+
* Words (a first run's "test money" line) keep their own testnet fallback in lib/network.ts learnNetwork.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { dirname, join } from 'node:path';
|
|
15
|
+
import { CONFIG_DIR } from './paths.js';
|
|
16
|
+
import { readDeployNetwork } from './network.js';
|
|
17
|
+
export const NET_FILE = join(CONFIG_DIR, 'network');
|
|
18
|
+
const isNet = (v) => v === 'mainnet' || v === 'testnet';
|
|
19
|
+
export function savedNet(path = NET_FILE) {
|
|
20
|
+
try {
|
|
21
|
+
const v = readFileSync(path, 'utf8').trim();
|
|
22
|
+
return isNet(v) ? v : null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Save a choice, or clear it with null (`one network auto`). */
|
|
29
|
+
export function saveNet(net, path = NET_FILE) {
|
|
30
|
+
if (net === null) {
|
|
31
|
+
if (existsSync(path))
|
|
32
|
+
rmSync(path);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
36
|
+
writeFileSync(path, net + '\n', { mode: 0o600 });
|
|
37
|
+
}
|
|
38
|
+
/** The page that carries the deploy's meta tag: the web host, never the gateway (api.one.ie serves no page). */
|
|
39
|
+
export function webBase(api) {
|
|
40
|
+
const raw = (api ?? process.env.ONE_API_URL ?? process.env.ONEIE_BASE_URL ?? 'https://one.ie').replace(/\/$/, '');
|
|
41
|
+
try {
|
|
42
|
+
const u = new URL(raw);
|
|
43
|
+
if (u.hostname.startsWith('api.'))
|
|
44
|
+
u.hostname = u.hostname.slice(4);
|
|
45
|
+
return u.origin;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return 'https://one.ie';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const defaultDeps = () => ({ env: process.env, saved: () => savedNet(), deploy: (b) => readDeployNetwork(b) });
|
|
52
|
+
export async function resolveNet(flag, api, deps = defaultDeps()) {
|
|
53
|
+
if (flag !== undefined) {
|
|
54
|
+
return isNet(flag) ? { ok: true, net: flag, from: 'flag' } : { ok: false, error: 'bad_net', message: `--net must be mainnet or testnet, not '${flag}'` };
|
|
55
|
+
}
|
|
56
|
+
const env = deps.env.ONE_NETWORK?.trim();
|
|
57
|
+
if (env)
|
|
58
|
+
return isNet(env) ? { ok: true, net: env, from: 'env' } : { ok: false, error: 'bad_net', message: `ONE_NETWORK must be mainnet or testnet, not '${env}'` };
|
|
59
|
+
const saved = deps.saved();
|
|
60
|
+
if (saved)
|
|
61
|
+
return { ok: true, net: saved, from: 'saved' };
|
|
62
|
+
const base = webBase(api);
|
|
63
|
+
const deployed = await deps.deploy(base);
|
|
64
|
+
if (deployed)
|
|
65
|
+
return { ok: true, net: deployed, from: 'deploy' };
|
|
66
|
+
return { ok: false, error: 'network_unknown', message: `could not read which network ${base} runs, and nothing names one — pass --net mainnet|testnet, set ONE_NETWORK, or run \`one network mainnet|testnet\`` };
|
|
67
|
+
}
|
|
68
|
+
/** The one line every money command prints: the network, and where the choice came from. */
|
|
69
|
+
export function netLine(c) {
|
|
70
|
+
const why = { flag: '--net', env: 'ONE_NETWORK', saved: '`one network`', deploy: 'the deploy' }[c.from];
|
|
71
|
+
return c.net === 'mainnet' ? `network MAINNET — real money (from ${why})` : `network testnet — test money (from ${why})`;
|
|
72
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which Sui network is the API this CLI is talking to on? One's answer is the deploy's own: Layout.astro
|
|
3
|
+
* writes `<meta name="one:network" content="testnet|mainnet">` into every page from the worker's `NETWORK`
|
|
4
|
+
* (one.ie/web/src/lib/sui-network.ts `DEPLOY_NET_META_NAME`), so the CLI asks the home page — the one door
|
|
5
|
+
* that carries it today. There is no status route for it.
|
|
6
|
+
*
|
|
7
|
+
* It only ever shapes the WORDS of a first run (the faucet line, "test money"), never a command's
|
|
8
|
+
* behaviour, and it must never block or fail a run: a slow, failing or unreadable answer is `testnet`
|
|
9
|
+
* (the display rule: show the network where a mistake costs nothing). The home page is large, so the
|
|
10
|
+
* body is read only until the meta tag or `</head>` appears, then dropped.
|
|
11
|
+
*/
|
|
12
|
+
export type Net = 'testnet' | 'mainnet';
|
|
13
|
+
/** Parse the meta tag out of the start of a page. Null when it is not there (yet). */
|
|
14
|
+
export declare function netFromHtml(html: string): Net | null;
|
|
15
|
+
/**
|
|
16
|
+
* The deploy's network, or NULL when it cannot be read (slow, down, no tag). The strict read: a command that
|
|
17
|
+
* moves money refuses on null rather than guessing (lib/net-choice.ts). learnNetwork below is the words-only
|
|
18
|
+
* reading of the same answer, where null becomes `testnet`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readDeployNetwork(api: string, f?: typeof fetch, timeoutMs?: number): Promise<Net | null>;
|
|
21
|
+
/** Words only: the deploy's network, `testnet` when it cannot be read (show the network where a mistake costs nothing). */
|
|
22
|
+
export declare function learnNetwork(api: string, f?: typeof fetch, timeoutMs?: number): Promise<Net>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Parse the meta tag out of the start of a page. Null when it is not there (yet). */
|
|
2
|
+
export function netFromHtml(html) {
|
|
3
|
+
const tag = /<meta\b[^>]*\bname=["']one:network["'][^>]*>/i.exec(html)?.[0];
|
|
4
|
+
const content = tag ? /\bcontent=["']([^"']*)["']/i.exec(tag)?.[1] : undefined;
|
|
5
|
+
if (content === 'mainnet' || content === 'testnet')
|
|
6
|
+
return content;
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The deploy's network, or NULL when it cannot be read (slow, down, no tag). The strict read: a command that
|
|
11
|
+
* moves money refuses on null rather than guessing (lib/net-choice.ts). learnNetwork below is the words-only
|
|
12
|
+
* reading of the same answer, where null becomes `testnet`.
|
|
13
|
+
*/
|
|
14
|
+
export async function readDeployNetwork(api, f = fetch, timeoutMs = 3000) {
|
|
15
|
+
const ctl = new AbortController();
|
|
16
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
17
|
+
try {
|
|
18
|
+
const res = await f(`${api.replace(/\/$/, '')}/`, { signal: ctl.signal, headers: { accept: 'text/html' } });
|
|
19
|
+
if (!res.ok || !res.body)
|
|
20
|
+
return null;
|
|
21
|
+
const reader = res.body.getReader();
|
|
22
|
+
const dec = new TextDecoder();
|
|
23
|
+
let seen = '';
|
|
24
|
+
while (seen.length < 131_072) {
|
|
25
|
+
const { done, value } = await reader.read();
|
|
26
|
+
if (done)
|
|
27
|
+
break;
|
|
28
|
+
seen += dec.decode(value, { stream: true });
|
|
29
|
+
const net = netFromHtml(seen);
|
|
30
|
+
if (net) {
|
|
31
|
+
void reader.cancel().catch(() => { });
|
|
32
|
+
return net;
|
|
33
|
+
}
|
|
34
|
+
if (seen.includes('</head>'))
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
void reader.cancel().catch(() => { });
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Words only: the deploy's network, `testnet` when it cannot be read (show the network where a mistake costs nothing). */
|
|
48
|
+
export async function learnNetwork(api, f = fetch, timeoutMs = 3000) {
|
|
49
|
+
return (await readDeployNetwork(api, f, timeoutMs)) ?? 'testnet';
|
|
50
|
+
}
|