@oneie/cli 5.8.0 → 5.9.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 +114 -6
- package/dist/package.json +37 -11
- package/dist/src/age-1k8hs4ec.js +1 -0
- package/dist/src/client-n6fpnd9f.js +1 -0
- package/dist/src/evm-tx-cqhm9rtt.js +1 -0
- package/dist/src/hl-run-0pv1e0p2.js +1 -0
- package/dist/src/index-f5vhzspa.js +12 -0
- package/dist/src/index-h3nrt8bx.js +4 -0
- package/dist/src/index-st6k9vhc.js +2062 -0
- package/dist/src/index.js +1122 -134
- package/dist/src/message-key-yczrxszr.js +1 -0
- package/dist/src/message-lock-thr851d5.js +5 -0
- package/dist/src/sweep-order-jrq2hkye.js +1 -0
- package/dist/src/sweep-runner-jftw9em7.js +1 -0
- package/package.json +37 -11
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/ceiling.d.ts +0 -36
- package/dist/src/ceiling.js +0 -189
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/check.d.ts +0 -11
- package/dist/src/check.js +0 -53
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/credits.d.ts +0 -29
- package/dist/src/credits.js +0 -88
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -297
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -270
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/check-words.d.ts +0 -57
- package/dist/src/lib/check-words.js +0 -144
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -363
- package/dist/src/lib/journey.d.ts +0 -150
- package/dist/src/lib/journey.js +0 -264
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/net-choice.d.ts +0 -28
- package/dist/src/lib/net-choice.js +0 -72
- package/dist/src/lib/network.d.ts +0 -22
- package/dist/src/lib/network.js +0 -50
- package/dist/src/lib/next-words.d.ts +0 -105
- package/dist/src/lib/next-words.js +0 -298
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -90
- package/dist/src/lib/sui-grpc-send.js +0 -128
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/timed-fetch.d.ts +0 -33
- package/dist/src/lib/timed-fetch.js +0 -59
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -103
- package/dist/src/lib/vaultfile.js +0 -249
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/move.d.ts +0 -36
- package/dist/src/move.js +0 -152
- package/dist/src/network-cmd.d.ts +0 -17
- package/dist/src/network-cmd.js +0 -74
- package/dist/src/next.d.ts +0 -12
- package/dist/src/next.js +0 -67
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop-buy.d.ts +0 -16
- package/dist/src/shop-buy.js +0 -101
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -112
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -27
- package/dist/src/start.js +0 -225
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/thread.d.ts +0 -2
- package/dist/src/thread.js +0 -52
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -158
- package/dist/src/wallet-money.js +0 -664
- package/dist/src/wallet.d.ts +0 -169
- package/dist/src/wallet.js +0 -973
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -169
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
package/dist/src/shop-buy.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* shop-buy.ts — `one shop buy <workspace> <ppid>`: an agent buys a store's product with USDC on Sui from its own
|
|
3
|
-
* vault, through the same route the checkout page uses (/api/storefront/crypto):
|
|
4
|
-
*
|
|
5
|
-
* 1. quote action:'quote' — the store's price, its Sui option, usdcEligible
|
|
6
|
-
* 2. escrow action:'escrow' — a deposit address for THIS sale and the exact USDC amount pay recorded
|
|
7
|
-
* 3. pay the vault in --dir sends exactly that USDC to the deposit address (suiSendGrpc, the one Sui signer)
|
|
8
|
-
* 4. status action:'status' — polled until pay sees the money (completed); forwardTxHash once the sweep moves it on
|
|
9
|
-
*
|
|
10
|
-
* No address or amount is ever typed: both come back from the route, which reads them server-side. Dry by default:
|
|
11
|
-
* without --live it quotes and stops — the escrow address is minted only by a live run, because minting one is a write.
|
|
12
|
-
*/
|
|
13
|
-
import { Command } from 'commander';
|
|
14
|
-
import { authHeaders, out, resolveBase } from './lib/client.js';
|
|
15
|
-
import { suiSendGrpc } from './lib/sui-grpc-send.js';
|
|
16
|
-
import { SUI } from './lib/wallet-money.js';
|
|
17
|
-
import { unlock } from './wallet.js';
|
|
18
|
-
import { netLine, resolveNet } from './lib/net-choice.js';
|
|
19
|
-
const SUI_ADDR = /^0x[0-9a-f]{64}$/i;
|
|
20
|
-
/** "1.000000" USDC → 1000000 base units (6 decimals); anything else → null. */
|
|
21
|
-
export function usdcUnits(v) {
|
|
22
|
-
if (typeof v !== 'string' || !/^\d{1,9}(\.\d{1,6})?$/.test(v.trim()))
|
|
23
|
-
return null;
|
|
24
|
-
const [w, f = ''] = v.trim().split('.');
|
|
25
|
-
const n = BigInt(w) * 1000000n + BigInt(f.padEnd(6, '0'));
|
|
26
|
-
return n > 0n ? n : null;
|
|
27
|
-
}
|
|
28
|
-
async function crypto(base, body) {
|
|
29
|
-
const res = await fetch(`${base.replace(/\/$/, '')}/api/storefront/crypto`, { method: 'POST', headers: { ...authHeaders(), 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
30
|
-
return { status: res.status, json: (await res.json().catch(() => ({}))) };
|
|
31
|
-
}
|
|
32
|
-
export function shopBuyCmd() {
|
|
33
|
-
return new Command('buy')
|
|
34
|
-
.description("Buy a store's product with USDC on Sui from the vault in --dir: quote, escrow address for this sale, pay the exact USDC, poll until pay sees it. Dry (quote only) unless --live")
|
|
35
|
-
.argument('<workspace>', 'The store, e.g. one')
|
|
36
|
-
.argument('<ppid>', 'The price id, e.g. price_58bgh7w7y97ickj6')
|
|
37
|
-
.option('--dir <vault>', 'The sealed vault that pays', '.')
|
|
38
|
-
.option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)')
|
|
39
|
-
.option('--api <url>', 'one.ie base URL')
|
|
40
|
-
.option('--rpc <url>', 'Sui gRPC base URL override')
|
|
41
|
-
.option('--wait <seconds>', 'How long to poll status after paying', '120')
|
|
42
|
-
.option('--live', 'Mint the escrow address, pay it and poll. Without it: the quote only')
|
|
43
|
-
.action(async (workspace, ppid, o, sub) => {
|
|
44
|
-
const t0 = Date.now();
|
|
45
|
-
const nc = await resolveNet(o.net, o.api);
|
|
46
|
-
if (!nc.ok)
|
|
47
|
-
return out(sub, nc);
|
|
48
|
-
const net = nc.net;
|
|
49
|
-
const base = resolveBase({ api: o.api }, 'https://one.ie');
|
|
50
|
-
const q = await crypto(base, { action: 'quote', workspace, ppid, chains: ['SUI'] });
|
|
51
|
-
const sui = (q.json.options ?? []).find((x) => x.chain === 'SUI');
|
|
52
|
-
if (q.status !== 200 || !sui)
|
|
53
|
-
return out(sub, { ok: false, error: String(q.json.error ?? 'no_sui_option'), status: q.status });
|
|
54
|
-
if (sui.usdcEligible !== true)
|
|
55
|
-
return out(sub, { ok: false, error: 'usdc_not_offered', detail: 'this store does not take USDC on Sui for this price' });
|
|
56
|
-
const quote = { workspace, ppid, usd: q.json.amountUsd, escrow: q.json.escrow, custody: q.json.custody, net, networkFrom: nc.from, says: netLine(nc) };
|
|
57
|
-
if (!o.live)
|
|
58
|
-
return out(sub, { ok: true, dry: true, quote, next: 'add --live to mint this sale\'s deposit address and pay it in USDC from --dir' });
|
|
59
|
-
const opened = await unlock(o.dir);
|
|
60
|
-
if ('error' in opened)
|
|
61
|
-
return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
|
|
62
|
-
const key = opened.keys.find((k) => k.chain === 'sui');
|
|
63
|
-
if (!key)
|
|
64
|
-
return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
|
|
65
|
-
const e = await crypto(base, { action: 'escrow', workspace, ppid, chain: 'SUI' });
|
|
66
|
-
const paymentId = String(e.json.paymentId ?? '');
|
|
67
|
-
const escrowAddress = String(e.json.escrowAddress ?? '');
|
|
68
|
-
const units = usdcUnits(e.json.usdc);
|
|
69
|
-
if (e.status !== 200 || !paymentId || !SUI_ADDR.test(escrowAddress))
|
|
70
|
-
return out(sub, { ok: false, error: String(e.json.error ?? 'escrow_failed'), status: e.status });
|
|
71
|
-
if (units === null)
|
|
72
|
-
return out(sub, { ok: false, error: 'usdc_not_offered_on_this_escrow', paymentId, detail: 'pay did not echo a USDC amount for this deposit address — nothing was sent' });
|
|
73
|
-
if (e.json.network === 'testnet' && net === 'mainnet')
|
|
74
|
-
return out(sub, { ok: false, error: 'network_mismatch', paymentId });
|
|
75
|
-
let digest;
|
|
76
|
-
let finalMs;
|
|
77
|
-
try {
|
|
78
|
-
const sent = await suiSendGrpc({ asset: 'USDC', coinType: SUI[net].usdc, from: key.address, to: escrowAddress, amountUnits: units, privateKeyHex: key.privateKeyHex, rpc: o.rpc, net });
|
|
79
|
-
digest = sent.digest;
|
|
80
|
-
finalMs = sent.finalMs;
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
const se = err;
|
|
84
|
-
return out(sub, { ok: false, error: se.code ?? 'send_failed', detail: se.message, ...(se.digest ? { digest: se.digest } : {}), paymentId, escrowAddress });
|
|
85
|
-
}
|
|
86
|
-
const deadline = Date.now() + Math.max(10, Number(o.wait) || 120) * 1000;
|
|
87
|
-
let s = {};
|
|
88
|
-
while (Date.now() < deadline) {
|
|
89
|
-
s = (await crypto(base, { action: 'status', workspace, paymentId, chain: 'SUI', amount: String(e.json.amount ?? '') })).json;
|
|
90
|
-
if (s.status === 'completed' || s.status === 'forwarded' || s.forwardTxHash)
|
|
91
|
-
break;
|
|
92
|
-
await new Promise((r) => setTimeout(r, 4000));
|
|
93
|
-
}
|
|
94
|
-
const seen = s.status === 'completed' || s.status === 'forwarded' || Boolean(s.forwardTxHash);
|
|
95
|
-
return out(sub, {
|
|
96
|
-
ok: seen, ...(seen ? {} : { error: 'not_seen_yet', next: 'poll again: the money is at the deposit address' }),
|
|
97
|
-
paid: `${e.json.usdc} USDC`, paymentId, escrowAddress, digest, explorer: `${SUI[net].explorer}/tx/${digest}`, payer: key.address,
|
|
98
|
-
status: s.status ?? null, forwardTxHash: s.forwardTxHash ?? null, finalMs, wallMs: Date.now() - t0,
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
package/dist/src/shop.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
/**
|
|
3
|
-
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
4
|
-
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
5
|
-
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
6
|
-
* authority server-side; the API key identifies the caller.
|
|
7
|
-
*
|
|
8
|
-
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
9
|
-
*/
|
|
10
|
-
export declare function shopCmd(): Command;
|
package/dist/src/shop.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { shopBuyCmd } from './shop-buy.js';
|
|
3
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
-
import { authHeaders, jsonMode, out, resolveBase } from './lib/client.js';
|
|
5
|
-
import { askPath } from './lib/api-path.js';
|
|
6
|
-
import { parseFacts, shopInit } from './lib/shop-init.js';
|
|
7
|
-
import { SALE_CHANNEL_IDS, SALE_KIND_IDS, SALE_RAIL_IDS, drawSale, saleChannelOf, saleJson, saleKindOf, saleRailOf, } from './lib/sale-card.js';
|
|
8
|
-
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
9
|
-
/**
|
|
10
|
-
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
11
|
-
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
12
|
-
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
13
|
-
* authority server-side; the API key identifies the caller.
|
|
14
|
-
*
|
|
15
|
-
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
16
|
-
*/
|
|
17
|
-
export function shopCmd() {
|
|
18
|
-
const cmd = new Command('shop').description('Build a shop from the twelve-page pack');
|
|
19
|
-
cmd
|
|
20
|
-
.command('init')
|
|
21
|
-
.description('Seed the shop pack into a workspace, and fill it from a facts file')
|
|
22
|
-
.option('--facts <path>', 'JSON file of ShopBusinessFacts — a fact left out stays a visible placeholder')
|
|
23
|
-
.option('--workspace <slug>', 'Workspace to seed (defaults to ONEIE_WORKSPACE)')
|
|
24
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
25
|
-
.action(async (opts) => {
|
|
26
|
-
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE ?? '';
|
|
27
|
-
if (!workspace) {
|
|
28
|
-
out(cmd, { ok: false, error: 'no workspace — pass --workspace <slug> or set ONEIE_WORKSPACE' });
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
let facts;
|
|
32
|
-
if (opts.facts) {
|
|
33
|
-
if (!existsSync(opts.facts)) {
|
|
34
|
-
out(cmd, { ok: false, error: `facts file not found: ${opts.facts}` });
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const parsed = parseFacts(readFileSync(opts.facts, 'utf8'));
|
|
38
|
-
if (!parsed.ok) {
|
|
39
|
-
out(cmd, { ok: false, error: parsed.error });
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
facts = parsed.facts;
|
|
43
|
-
}
|
|
44
|
-
const base = opts.api.replace(/\/$/, '');
|
|
45
|
-
const ask = async (receiver, data) => {
|
|
46
|
-
const res = await fetch(askPath(base, receiver), {
|
|
47
|
-
method: 'POST',
|
|
48
|
-
headers: { 'content-type': 'application/json', ...authHeaders() },
|
|
49
|
-
body: JSON.stringify({ data }),
|
|
50
|
-
});
|
|
51
|
-
// A transport-level failure is its own outcome — never a silent success.
|
|
52
|
-
if (!res.ok)
|
|
53
|
-
return { outcome: `http_${res.status}` };
|
|
54
|
-
return (await res.json());
|
|
55
|
-
};
|
|
56
|
-
const r = await shopInit({ ask }, { workspace, facts });
|
|
57
|
-
if (!r.ok) {
|
|
58
|
-
out(cmd, { ok: false, error: r.error ?? 'shop init failed' });
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
out(cmd, {
|
|
62
|
-
ok: true,
|
|
63
|
-
workspace: r.workspace,
|
|
64
|
-
pages: r.pages,
|
|
65
|
-
open: `/p/${r.pages[0]}`,
|
|
66
|
-
filled: r.filled,
|
|
67
|
-
...(r.fillError ? { fillError: r.fillError } : {}),
|
|
68
|
-
});
|
|
69
|
-
// The pages exist; the facts did not land. Both are true, and the exit
|
|
70
|
-
// code has to carry the half the caller asked for and did not get.
|
|
71
|
-
if (r.fillRequested && !r.filled)
|
|
72
|
-
process.exitCode = 1;
|
|
73
|
-
});
|
|
74
|
-
// A picture of the sale, drawn locally: no key, no network, nothing charged. The drawing lives in
|
|
75
|
-
// lib/sale-card.ts so it is tested without a terminal.
|
|
76
|
-
cmd
|
|
77
|
-
.command('card')
|
|
78
|
-
.description('Draw how your agent sells: the pay card, alone or inside a WhatsApp, SMS or email thread')
|
|
79
|
-
.option('--kind <kind>', `What is sold: ${SALE_KIND_IDS.join('|')}`, 'course')
|
|
80
|
-
.option('--rail <rail>', `How they pay: ${SALE_RAIL_IDS.join('|')}`, 'card')
|
|
81
|
-
.option('--channel <id>', `Where it is sold: ${SALE_CHANNEL_IDS.join('|')}`)
|
|
82
|
-
.option('--all', 'All four offers')
|
|
83
|
-
.option('--paid', 'Draw the card after the tap')
|
|
84
|
-
.action((opts, c) => {
|
|
85
|
-
const kind = saleKindOf(opts.kind);
|
|
86
|
-
const rail = saleRailOf(opts.rail);
|
|
87
|
-
const channel = opts.channel === undefined ? undefined : saleChannelOf(opts.channel);
|
|
88
|
-
// An unknown word is refused, never drawn as the default: a wrong picture reads as a right one.
|
|
89
|
-
if (!kind) {
|
|
90
|
-
out(c, { ok: false, error: `unknown kind "${opts.kind}" — ${SALE_KIND_IDS.join(', ')}` });
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (!rail) {
|
|
94
|
-
out(c, { ok: false, error: `unknown rail "${opts.rail}" — ${SALE_RAIL_IDS.join(', ')}` });
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (channel === null) {
|
|
98
|
-
out(c, { ok: false, error: `unknown channel "${opts.channel}" — ${SALE_CHANNEL_IDS.join(', ')}` });
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const kinds = opts.all ? SALE_KIND_IDS : [kind];
|
|
102
|
-
const draw = { rail, channel, phase: opts.paid ? 'paid' : 'idle' };
|
|
103
|
-
if (jsonMode(c)) {
|
|
104
|
-
out(c, saleJson(kinds, draw));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const ascii = !process.stdout.isTTY || 'NO_COLOR' in process.env;
|
|
108
|
-
process.stdout.write(drawSale(kinds, { ...draw, ascii }));
|
|
109
|
-
});
|
|
110
|
-
cmd.addCommand(shopBuyCmd());
|
|
111
|
-
return cmd;
|
|
112
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface Diagnostic {
|
|
2
|
-
level: 'warn' | 'info';
|
|
3
|
-
code: string;
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
|
-
export interface ParsedSkill {
|
|
7
|
-
meta: Record<string, unknown>;
|
|
8
|
-
body: string;
|
|
9
|
-
diagnostics: Diagnostic[];
|
|
10
|
-
}
|
|
11
|
-
export interface ParseOptions {
|
|
12
|
-
pathStem?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function parse(md: string, opts?: ParseOptions): ParsedSkill;
|
package/dist/src/skill-parser.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Mirror of web/src/lib/skill/parser.ts — keep in sync.
|
|
2
|
-
// TODO: dedupe via @oneie/sdk export once SDK ships skill helpers.
|
|
3
|
-
function parseFrontmatter(yaml) {
|
|
4
|
-
const meta = {};
|
|
5
|
-
const lines = yaml.split('\n');
|
|
6
|
-
let i = 0;
|
|
7
|
-
while (i < lines.length) {
|
|
8
|
-
const line = lines[i];
|
|
9
|
-
if (!line.trim() || line.trim().startsWith('#')) {
|
|
10
|
-
i++;
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
let col = line.indexOf(': ');
|
|
14
|
-
let inlineStart = col === -1 ? -1 : col + 2;
|
|
15
|
-
if (col === -1 && /^[A-Za-z0-9_-]+:\s*$/.test(line)) {
|
|
16
|
-
col = line.indexOf(':');
|
|
17
|
-
inlineStart = line.length;
|
|
18
|
-
}
|
|
19
|
-
if (col === -1) {
|
|
20
|
-
i++;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const key = line.slice(0, col).trim();
|
|
24
|
-
if (!key) {
|
|
25
|
-
i++;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const inline = line.slice(inlineStart).trim();
|
|
29
|
-
const arr = [];
|
|
30
|
-
let j = i + 1;
|
|
31
|
-
while (j < lines.length && lines[j].trim().startsWith('- ')) {
|
|
32
|
-
arr.push(lines[j].trim().slice(2));
|
|
33
|
-
j++;
|
|
34
|
-
}
|
|
35
|
-
if (arr.length > 0) {
|
|
36
|
-
meta[key] = arr;
|
|
37
|
-
i = j;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
meta[key] = inline === '' ? true : inline;
|
|
41
|
-
i++;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return meta;
|
|
45
|
-
}
|
|
46
|
-
const FENCE = /^---\s*$/m;
|
|
47
|
-
function firstParagraph(body) {
|
|
48
|
-
const trimmed = body.trim();
|
|
49
|
-
if (!trimmed)
|
|
50
|
-
return undefined;
|
|
51
|
-
for (const chunk of trimmed.split(/\n\s*\n/)) {
|
|
52
|
-
const para = chunk.split('\n').filter(l => !l.startsWith('#')).join(' ').trim();
|
|
53
|
-
if (para)
|
|
54
|
-
return para;
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
export function parse(md, opts = {}) {
|
|
59
|
-
const diagnostics = [];
|
|
60
|
-
const parts = md.split(FENCE);
|
|
61
|
-
let meta = {};
|
|
62
|
-
let body;
|
|
63
|
-
if (parts.length < 3) {
|
|
64
|
-
body = md.trim();
|
|
65
|
-
if (opts.pathStem) {
|
|
66
|
-
meta.name = opts.pathStem;
|
|
67
|
-
diagnostics.push({ level: 'warn', code: 'no-frontmatter', message: `No frontmatter; deriving name='${opts.pathStem}' from path` });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
diagnostics.push({ level: 'warn', code: 'no-frontmatter', message: 'No frontmatter and no pathStem provided' });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const yaml = parts[1];
|
|
75
|
-
body = parts.slice(2).join('---').trim();
|
|
76
|
-
try {
|
|
77
|
-
meta = parseFrontmatter(yaml);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
const cleaned = yaml.split('\n').filter(l => !l.match(/^[^:#][^:]*:[^:]*:[^:]*/)).join('\n');
|
|
81
|
-
meta = parseFrontmatter(cleaned);
|
|
82
|
-
diagnostics.push({ level: 'warn', code: 'lenient-yaml', message: 'Frontmatter required lenient retry (unquoted colons)' });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!meta.name && opts.pathStem) {
|
|
86
|
-
meta.name = opts.pathStem;
|
|
87
|
-
diagnostics.push({ level: 'warn', code: 'missing-name', message: `Missing name; using path stem '${opts.pathStem}'` });
|
|
88
|
-
}
|
|
89
|
-
if (opts.pathStem && meta.name && meta.name !== opts.pathStem) {
|
|
90
|
-
diagnostics.push({ level: 'warn', code: 'name-mismatch', message: `name='${String(meta.name)}' does not match path stem '${opts.pathStem}'` });
|
|
91
|
-
}
|
|
92
|
-
if (typeof meta.name === 'string' && meta.name.length > 64) {
|
|
93
|
-
diagnostics.push({ level: 'warn', code: 'name-too-long', message: `name length ${meta.name.length} exceeds 64 chars` });
|
|
94
|
-
}
|
|
95
|
-
if (!meta.description) {
|
|
96
|
-
const para = firstParagraph(body);
|
|
97
|
-
if (para) {
|
|
98
|
-
meta.description = para;
|
|
99
|
-
diagnostics.push({ level: 'info', code: 'description-from-body', message: 'Derived description from first body paragraph' });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const triggersStr = typeof meta.triggers === 'string'
|
|
103
|
-
? meta.triggers
|
|
104
|
-
: Array.isArray(meta.triggers)
|
|
105
|
-
? meta.triggers.map(String).join(', ')
|
|
106
|
-
: '';
|
|
107
|
-
if (triggersStr) {
|
|
108
|
-
const base = typeof meta.description === 'string' ? meta.description : '';
|
|
109
|
-
meta.description = base ? `${base} Triggers: ${triggersStr}` : `Triggers: ${triggersStr}`;
|
|
110
|
-
diagnostics.push({ level: 'info', code: 'triggers-merged', message: "'triggers' field merged into description" });
|
|
111
|
-
}
|
|
112
|
-
return { meta, body, diagnostics };
|
|
113
|
-
}
|
package/dist/src/skill.d.ts
DELETED