@oneie/cli 5.7.6 → 5.8.1
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 -1
- package/dist/package.json +7 -8
- package/dist/src/age-yefbe8pe.js +1 -0
- package/dist/src/evm-tx-ee2q0e3w.js +1 -0
- package/dist/src/hl-run-tgrkrk69.js +1 -0
- package/dist/src/index-0rj9wdk9.js +4 -0
- package/dist/src/index-91y484c2.js +2052 -0
- package/dist/src/index-940y3rnv.js +12 -0
- package/dist/src/index.js +1047 -121
- package/dist/src/message-key-db1xjdkw.js +1 -0
- package/dist/src/message-lock-5vr8079x.js +5 -0
- package/dist/src/sweep-order-c2p6rk8c.js +1 -0
- package/dist/src/sweep-runner-t68xe7vx.js +1 -0
- package/package.json +7 -8
- 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/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- 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/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 -293
- 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 -263
- 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/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 -360
- package/dist/src/lib/journey.d.ts +0 -148
- package/dist/src/lib/journey.js +0 -245
- 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/network.d.ts +0 -15
- package/dist/src/lib/network.js +0 -41
- 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 -50
- package/dist/src/lib/sui-grpc-send.js +0 -89
- 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/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -88
- package/dist/src/lib/vaultfile.js +0 -222
- 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/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.d.ts +0 -10
- package/dist/src/shop.js +0 -110
- 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 -15
- package/dist/src/start.js +0 -203
- 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/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 -152
- package/dist/src/wallet-money.js +0 -564
- package/dist/src/wallet.d.ts +0 -167
- package/dist/src/wallet.js +0 -855
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -166
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
package/dist/src/secrets.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* secrets.ts — `one secrets seal | run | add-device | give | list`: the sealed .env.
|
|
3
|
-
* (text/secrets.md deliverables 1 and 5; text/secrets-todo.md § C1.)
|
|
4
|
-
*
|
|
5
|
-
* `seal` is the one verb built here. It turns a plaintext .env into `.env.sealed` v1 —
|
|
6
|
-
* names readable, one age file per value — and the readers of every value are ONLY the
|
|
7
|
-
* owner's: the paper lock (the 24 words, HKDF `secrets-x25519-v1`) and the device locks
|
|
8
|
-
* the owner listed in ~/.one/secrets-readers.json (`add-device`, C3, writes it). A lock
|
|
9
|
-
* that is in neither is refused `not_your_reader`: no other person and no agent ever
|
|
10
|
-
* holds a key.
|
|
11
|
-
*
|
|
12
|
-
* Like key-seal.ts it is offline, never prompts, answers `--json`, and exits 0 done /
|
|
13
|
-
* 1 refused. It never prints a value, a line of the .env, or the key words; an error
|
|
14
|
-
* names a variable or a line number. The key is a key file (`--key`) or
|
|
15
|
-
* ONE_WALLET_MNEMONIC — never stdin.
|
|
16
|
-
*
|
|
17
|
-
* `run` and `hash` live in secrets-run.ts (C2). `add-device` (secrets-device.ts, C3) makes this
|
|
18
|
-
* Mac a reader; a Secure Enclave lock among the readers seals through the `age` program
|
|
19
|
-
* (lib/age-plugin.ts). `give` (secrets-give.ts, C8) hands a key to ONE, sealed to the lock ONE's
|
|
20
|
-
* vault names and signed by an agent's own key. `list` (secrets-list.ts, C15) reads the desk —
|
|
21
|
-
* secrets:list, names and meters, never values.
|
|
22
|
-
*/
|
|
23
|
-
import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
24
|
-
import { homedir } from 'node:os';
|
|
25
|
-
import { join, resolve } from 'node:path';
|
|
26
|
-
import { Command } from 'commander';
|
|
27
|
-
import { jsonMode } from './lib/client.js';
|
|
28
|
-
import { isVaultId, parseEnv, parseSealed, renderSealed, sealEntries, verifySealed } from './lib/env-sealed.js';
|
|
29
|
-
import { ageModule, loadSecretsKey, MAX_INPUT_BYTES } from './lib/message-seal.js';
|
|
30
|
-
import { AgePluginError, isPluginLock, PLUGIN_LOCK_RE, requireAge } from './lib/age-plugin.js';
|
|
31
|
-
import { addDeviceAction } from './secrets-device.js';
|
|
32
|
-
import { buildGive } from './secrets-give.js';
|
|
33
|
-
import { buildList } from './secrets-list.js';
|
|
34
|
-
import { buildHash, buildRun } from './secrets-run.js';
|
|
35
|
-
export function fail(cmd, f) {
|
|
36
|
-
if (jsonMode(cmd))
|
|
37
|
-
process.stdout.write(JSON.stringify(f) + '\n');
|
|
38
|
-
else
|
|
39
|
-
process.stderr.write(`error ${f.error}\n`);
|
|
40
|
-
process.exitCode = 1;
|
|
41
|
-
}
|
|
42
|
-
const collect = (v, prev = []) => [...prev, v];
|
|
43
|
-
/** The owner's device-lock list. ONE_SECRETS_READERS moves it (tests); `add-device` (C3) writes it. */
|
|
44
|
-
export function readersFile() {
|
|
45
|
-
return process.env.ONE_SECRETS_READERS?.trim() || join(homedir(), '.one', 'secrets-readers.json');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The owner's device locks: a JSON array of locks, or `{ "readers": [...] }`, each entry a
|
|
49
|
-
* lock string or `{ "lock": "…" }`. No file is no devices — the paper lock is then the only reader.
|
|
50
|
-
*/
|
|
51
|
-
export function deviceLocks(path = readersFile()) {
|
|
52
|
-
if (!existsSync(path))
|
|
53
|
-
return [];
|
|
54
|
-
const badFile = () => ({ ok: false, error: `${path} is not a list of age1… locks`, code: 'bad_readers_file' });
|
|
55
|
-
let parsed;
|
|
56
|
-
try {
|
|
57
|
-
parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return badFile();
|
|
61
|
-
}
|
|
62
|
-
const list = Array.isArray(parsed) ? parsed : parsed?.readers;
|
|
63
|
-
if (!Array.isArray(list))
|
|
64
|
-
return badFile();
|
|
65
|
-
const locks = [];
|
|
66
|
-
for (const e of list) {
|
|
67
|
-
const l = typeof e === 'string' ? e : e?.lock;
|
|
68
|
-
if (typeof l !== 'string' || !l.trim())
|
|
69
|
-
return badFile();
|
|
70
|
-
locks.push(l.trim());
|
|
71
|
-
}
|
|
72
|
-
return locks;
|
|
73
|
-
}
|
|
74
|
-
async function sealAction(file, o, c) {
|
|
75
|
-
const envPath = resolve(file);
|
|
76
|
-
const outPath = resolve(o.out ?? `${file}.sealed`);
|
|
77
|
-
if (outPath === envPath)
|
|
78
|
-
return fail(c, { ok: false, error: 'the sealed file cannot be the .env itself — pass a different --out', code: 'bad_out' });
|
|
79
|
-
if (o.vault !== undefined && !isVaultId(o.vault))
|
|
80
|
-
return fail(c, { ok: false, error: 'that is not a vault id', code: 'bad_vault' });
|
|
81
|
-
let raw;
|
|
82
|
-
try {
|
|
83
|
-
const b = readFileSync(envPath);
|
|
84
|
-
if (b.length > MAX_INPUT_BYTES)
|
|
85
|
-
return fail(c, { ok: false, error: `${file} is more than ${MAX_INPUT_BYTES / (1024 * 1024)} MiB — too big to seal here`, code: 'too_big' });
|
|
86
|
-
raw = b.toString('utf8');
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return fail(c, { ok: false, error: `cannot read ${file}`, code: 'no_input' });
|
|
90
|
-
}
|
|
91
|
-
const k = await loadSecretsKey(o.key);
|
|
92
|
-
if ('ok' in k)
|
|
93
|
-
return fail(c, k);
|
|
94
|
-
try {
|
|
95
|
-
// The readers: the paper lock, the owner's device locks, nobody else.
|
|
96
|
-
const devices = deviceLocks();
|
|
97
|
-
if (!Array.isArray(devices))
|
|
98
|
-
return fail(c, devices);
|
|
99
|
-
const owners = new Set([k.recipient, ...devices]);
|
|
100
|
-
for (const l of o.reader ?? []) {
|
|
101
|
-
if (!owners.has(l.trim())) {
|
|
102
|
-
return fail(c, { ok: false, error: `${l.trim()} is not your lock — a secret is readable only by your paper and your own devices (add one with: one secrets add-device)`, code: 'not_your_reader' });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const readers = [...owners];
|
|
106
|
-
const age = await ageModule();
|
|
107
|
-
for (const l of readers) {
|
|
108
|
-
if (isPluginLock(l)) {
|
|
109
|
-
// A Secure Enclave lock is sealed through the `age` program. A missing program is a refusal, never a dropped device.
|
|
110
|
-
if (!PLUGIN_LOCK_RE.test(l))
|
|
111
|
-
return fail(c, { ok: false, error: `${l} is not an age lock — it starts age1…`, code: 'bad_key' });
|
|
112
|
-
const bins = requireAge();
|
|
113
|
-
if (typeof bins === 'string') {
|
|
114
|
-
return fail(c, { ok: false, error: bins === 'no_plugin' ? 'a Secure Enclave reader needs `age-plugin-se` — brew install age-plugin-se' : 'a Secure Enclave reader needs `age` — brew install age', code: bins });
|
|
115
|
-
}
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
age.decodeRecipient(l);
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
return fail(c, { ok: false, error: `${l} is not an age lock — it starts age1…`, code: 'bad_key' });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const entries = parseEnv(raw);
|
|
126
|
-
if (!Array.isArray(entries))
|
|
127
|
-
return fail(c, entries);
|
|
128
|
-
if (entries.length === 0)
|
|
129
|
-
return fail(c, { ok: false, error: `${file} has no NAME=value lines to seal`, code: 'empty_env' });
|
|
130
|
-
const text = renderSealed({ readers, vault: o.vault, entries: await sealEntries(entries, readers) });
|
|
131
|
-
// Write beside the target, open every value back from the bytes on disk, and only then
|
|
132
|
-
// put it in place. The temp file holds sealed bytes only.
|
|
133
|
-
const tmp = `${outPath}.tmp-${process.pid}`;
|
|
134
|
-
writeFileSync(tmp, text, { mode: 0o644 });
|
|
135
|
-
try {
|
|
136
|
-
const back = parseSealed(readFileSync(tmp, 'utf8'));
|
|
137
|
-
if ('ok' in back)
|
|
138
|
-
return fail(c, { ...back, code: 'readback_failed' });
|
|
139
|
-
const bad = await verifySealed(back, entries, k.secret);
|
|
140
|
-
if (bad)
|
|
141
|
-
return fail(c, bad);
|
|
142
|
-
renameSync(tmp, outPath);
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
if (existsSync(tmp))
|
|
146
|
-
unlinkSync(tmp);
|
|
147
|
-
}
|
|
148
|
-
if (o.remove)
|
|
149
|
-
unlinkSync(envPath);
|
|
150
|
-
const names = entries.map((e) => e.name);
|
|
151
|
-
if (jsonMode(c))
|
|
152
|
-
process.stdout.write(JSON.stringify({ ok: true, file: outPath, names, readers: readers.length, removed: Boolean(o.remove) }) + '\n');
|
|
153
|
-
else {
|
|
154
|
-
process.stdout.write(`sealed ${names.length} value${names.length === 1 ? '' : 's'} → ${outPath} (${readers.length} reader${readers.length === 1 ? '' : 's'})\n`);
|
|
155
|
-
if (o.remove)
|
|
156
|
-
process.stdout.write(`removed ${file}\n`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
// Never `e.message` of a failure that may sit next to a value; the cause is one of a few I/O errors
|
|
161
|
-
// or an age-plugin failure, which carries a code and a fixed message.
|
|
162
|
-
if (e instanceof AgePluginError)
|
|
163
|
-
return fail(c, { ok: false, error: e.message, code: e.code });
|
|
164
|
-
fail(c, { ok: false, error: `could not seal ${file}: ${e.code ?? 'failed'}`, code: 'failed' });
|
|
165
|
-
}
|
|
166
|
-
finally {
|
|
167
|
-
k.secret.fill(0);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const stub = (name, cycle, description) => new Command(name)
|
|
171
|
-
.description(`${description} (not built yet — ${cycle})`)
|
|
172
|
-
.allowUnknownOption()
|
|
173
|
-
.allowExcessArguments()
|
|
174
|
-
.action(() => {
|
|
175
|
-
process.stderr.write(`one secrets ${name}: not built yet (${cycle})\n`);
|
|
176
|
-
process.exitCode = 2;
|
|
177
|
-
});
|
|
178
|
-
export function secretsCmd() {
|
|
179
|
-
const seal = new Command('seal')
|
|
180
|
-
.description('Seal a .env to .env.sealed — names stay readable, every value is sealed to your paper and your own devices')
|
|
181
|
-
.argument('[file]', 'The .env to seal', '.env')
|
|
182
|
-
.option('--out <file>', 'Where to write the sealed file (default: <file>.sealed)')
|
|
183
|
-
.option('--reader <lock>', "Name a reader to include; it must be your paper lock or one in ~/.one/secrets-readers.json (repeat for several)", collect)
|
|
184
|
-
.option('--vault <id>', "Record the owner's vault id in the file header")
|
|
185
|
-
.option('--remove', 'Delete the .env once every value has been opened back from the sealed file and compared byte for byte')
|
|
186
|
-
.option('--key <file>', 'Key file made by `one key new --out` (else ONE_WALLET_MNEMONIC). Never read from stdin')
|
|
187
|
-
.action(sealAction);
|
|
188
|
-
return new Command('secrets')
|
|
189
|
-
.description('Seal a .env so it is safe to commit; only your paper and your own devices can open it')
|
|
190
|
-
.addCommand(seal)
|
|
191
|
-
.addCommand(buildHash())
|
|
192
|
-
.addCommand(buildRun())
|
|
193
|
-
.addCommand(new Command('add-device')
|
|
194
|
-
.description('Make this Mac a reader of your sealed files — a Secure Enclave key opened by Touch ID')
|
|
195
|
-
.option('--name <label>', 'A name for this Mac (default: its hostname)')
|
|
196
|
-
.option('--replace', 'Make a new key even though one exists (the old one stops being a reader)')
|
|
197
|
-
.action(addDeviceAction))
|
|
198
|
-
.addCommand(buildGive())
|
|
199
|
-
.addCommand(buildList());
|
|
200
|
-
}
|
package/dist/src/setup.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
/** No key in env — provision one via the same open call `init` uses, then
|
|
3
|
-
* reconcile the returned slug down into .env.local + workspace.toml. The
|
|
4
|
-
* route mints its own slug; it does not accept a desired one (contract #4). */
|
|
5
|
-
export declare function keylessSetup(dir: string, cfgPath: string | undefined, web: string): Promise<void>;
|
|
6
|
-
export declare function setupCmd(): Command;
|
package/dist/src/setup.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
4
|
-
import { readAgency } from './config.js';
|
|
5
|
-
import { askPath } from './lib/api-path.js';
|
|
6
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
7
|
-
const DEFAULT_WEB = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
8
|
-
async function ask(base, key, receiver, data) {
|
|
9
|
-
const res = await fetch(askPath(base, receiver), {
|
|
10
|
-
method: 'POST',
|
|
11
|
-
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
12
|
-
body: JSON.stringify({ data }),
|
|
13
|
-
});
|
|
14
|
-
if (!res.ok) {
|
|
15
|
-
const body = await res.text().catch(() => '');
|
|
16
|
-
throw new Error(`${receiver} → ${res.status}\n${body}`);
|
|
17
|
-
}
|
|
18
|
-
const json = await res.json();
|
|
19
|
-
if (json.outcome === 'failure') {
|
|
20
|
-
const result = (json.result ?? {});
|
|
21
|
-
const details = Object.entries(result)
|
|
22
|
-
.map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
|
23
|
-
.join(' ');
|
|
24
|
-
throw new Error(`${receiver} → forbidden: ${details}`);
|
|
25
|
-
}
|
|
26
|
-
return json;
|
|
27
|
-
}
|
|
28
|
-
function findConfigPath(dir) {
|
|
29
|
-
for (const name of ['_node.toml', 'agency.toml', 'partner.toml', 'workspace.toml']) {
|
|
30
|
-
if (existsSync(`${dir}/${name}`))
|
|
31
|
-
return `${dir}/${name}`;
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
/** No key in env — provision one via the same open call `init` uses, then
|
|
36
|
-
* reconcile the returned slug down into .env.local + workspace.toml. The
|
|
37
|
-
* route mints its own slug; it does not accept a desired one (contract #4). */
|
|
38
|
-
export async function keylessSetup(dir, cfgPath, web) {
|
|
39
|
-
let name = 'my-workspace';
|
|
40
|
-
if (cfgPath) {
|
|
41
|
-
try {
|
|
42
|
-
name = readAgency(cfgPath).name;
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// toml without slug/name (e.g. a bare workspace.toml) — fall through with the default
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const ownerEmail = mergeEnv(dir).WORKSPACE_OWNER_EMAIL;
|
|
49
|
-
const body = { name };
|
|
50
|
-
if (ownerEmail)
|
|
51
|
-
body.invite = { email: ownerEmail, role: 'owner' };
|
|
52
|
-
const res = await fetch(`${web}/api/provision/agent`, {
|
|
53
|
-
method: 'POST',
|
|
54
|
-
headers: { 'Content-Type': 'application/json' },
|
|
55
|
-
body: JSON.stringify(body),
|
|
56
|
-
});
|
|
57
|
-
const json = (await res.json());
|
|
58
|
-
if (!res.ok) {
|
|
59
|
-
process.stderr.write(`provision/agent → ${res.status}\n${JSON.stringify(json)}\n`);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
const { uid, workspace, apiKey } = json;
|
|
63
|
-
writeEnvLocal(dir, {
|
|
64
|
-
ONE_API_KEY: apiKey,
|
|
65
|
-
WORKSPACE_ID: workspace,
|
|
66
|
-
WORKSPACE_SLUG: workspace,
|
|
67
|
-
AGENCY_WSID: workspace,
|
|
68
|
-
AGENCY_SLUG: workspace,
|
|
69
|
-
CC_ACTOR_ID: uid,
|
|
70
|
-
});
|
|
71
|
-
let reconciled = '';
|
|
72
|
-
const targetToml = cfgPath ?? `${dir}/workspace.toml`;
|
|
73
|
-
if (existsSync(targetToml)) {
|
|
74
|
-
let toml = readFileSync(targetToml, 'utf8');
|
|
75
|
-
if (/^slug\s*=/m.test(toml)) {
|
|
76
|
-
toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${workspace}"`);
|
|
77
|
-
writeFileSync(targetToml, toml);
|
|
78
|
-
reconciled = ` reconciled: ${targetToml} slug → ${workspace}\n`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
process.stdout.write(`Workspace provisioned: ${workspace}\n`);
|
|
82
|
-
process.stdout.write(` key: ${apiKey.slice(0, 8)}… (written to .env.local)\n`);
|
|
83
|
-
process.stdout.write(reconciled);
|
|
84
|
-
}
|
|
85
|
-
export function setupCmd() {
|
|
86
|
-
return new Command('setup')
|
|
87
|
-
.description('Bootstrap a workspace (idempotent) — keyless: provisions with no prior account')
|
|
88
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
89
|
-
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
90
|
-
.action(async (opts) => {
|
|
91
|
-
const dir = process.cwd();
|
|
92
|
-
const env = mergeEnv(dir);
|
|
93
|
-
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
94
|
-
if ((env.AGENCY_WSID && env.CC_ACTOR_ID) || env.ONE_API_KEY) {
|
|
95
|
-
process.stdout.write(`Workspace already set up (${env.AGENCY_WSID ?? env.WORKSPACE_SLUG}). No-op.\n`);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const cfgPath = findConfigPath(dir);
|
|
99
|
-
if (!key) {
|
|
100
|
-
await keylessSetup(dir, cfgPath, DEFAULT_WEB);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (!cfgPath) {
|
|
104
|
-
process.stderr.write(`No _node.toml/agency.toml/partner.toml/workspace.toml found in ${dir}\n`);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
const agency = readAgency(cfgPath);
|
|
108
|
-
const base = opts.api.replace(/\/$/, '');
|
|
109
|
-
const ws = await ask(base, key, 'world:create-workspace', {
|
|
110
|
-
name: agency.name,
|
|
111
|
-
slug: agency.slug,
|
|
112
|
-
plan: agency.plan,
|
|
113
|
-
markup: agency.markup_pct,
|
|
114
|
-
brand: agency.brand ?? false,
|
|
115
|
-
credit: agency.pool ?? 0,
|
|
116
|
-
});
|
|
117
|
-
const wsid = String(ws.wsid ?? agency.slug);
|
|
118
|
-
const actor = await ask(base, key, 'world:create-actor', {
|
|
119
|
-
name: 'claude-code',
|
|
120
|
-
type: 'claude-code',
|
|
121
|
-
group: wsid,
|
|
122
|
-
});
|
|
123
|
-
const aid = String(actor.aid ?? '');
|
|
124
|
-
writeEnvLocal(dir, { AGENCY_WSID: wsid, CC_ACTOR_ID: aid, AGENCY_SLUG: agency.slug });
|
|
125
|
-
process.stdout.write(`Agency: ${wsid} plan=${agency.plan} markup=${agency.markup_pct}% pool=${agency.pool ?? 0} cr\nClaude Code actor: ${aid}\n`);
|
|
126
|
-
});
|
|
127
|
-
}
|
package/dist/src/ship.d.ts
DELETED
package/dist/src/ship.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
export function shipCmd() {
|
|
4
|
-
return new Command('ship')
|
|
5
|
-
.description('git add -A, commit, and push (close the loop)')
|
|
6
|
-
.argument('[message]', 'Commit message', 'ship: update agency workspace')
|
|
7
|
-
.action((message) => {
|
|
8
|
-
const add = spawnSync('git', ['add', '-A'], { stdio: 'inherit' });
|
|
9
|
-
if (add.status !== 0)
|
|
10
|
-
process.exit(add.status ?? 1);
|
|
11
|
-
const commit = spawnSync('git', ['commit', '-m', message], { stdio: 'inherit' });
|
|
12
|
-
if (commit.status !== 0 && commit.status !== 1)
|
|
13
|
-
process.exit(commit.status ?? 1);
|
|
14
|
-
const push = spawnSync('git', ['push'], { stdio: 'inherit' });
|
|
15
|
-
if (push.status !== 0)
|
|
16
|
-
process.exit(push.status ?? 1);
|
|
17
|
-
});
|
|
18
|
-
}
|
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,110 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { authHeaders, jsonMode, out, resolveBase } from './lib/client.js';
|
|
4
|
-
import { askPath } from './lib/api-path.js';
|
|
5
|
-
import { parseFacts, shopInit } from './lib/shop-init.js';
|
|
6
|
-
import { SALE_CHANNEL_IDS, SALE_KIND_IDS, SALE_RAIL_IDS, drawSale, saleChannelOf, saleJson, saleKindOf, saleRailOf, } from './lib/sale-card.js';
|
|
7
|
-
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
8
|
-
/**
|
|
9
|
-
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
10
|
-
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
11
|
-
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
12
|
-
* authority server-side; the API key identifies the caller.
|
|
13
|
-
*
|
|
14
|
-
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
15
|
-
*/
|
|
16
|
-
export function shopCmd() {
|
|
17
|
-
const cmd = new Command('shop').description('Build a shop from the twelve-page pack');
|
|
18
|
-
cmd
|
|
19
|
-
.command('init')
|
|
20
|
-
.description('Seed the shop pack into a workspace, and fill it from a facts file')
|
|
21
|
-
.option('--facts <path>', 'JSON file of ShopBusinessFacts — a fact left out stays a visible placeholder')
|
|
22
|
-
.option('--workspace <slug>', 'Workspace to seed (defaults to ONEIE_WORKSPACE)')
|
|
23
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
24
|
-
.action(async (opts) => {
|
|
25
|
-
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE ?? '';
|
|
26
|
-
if (!workspace) {
|
|
27
|
-
out(cmd, { ok: false, error: 'no workspace — pass --workspace <slug> or set ONEIE_WORKSPACE' });
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
let facts;
|
|
31
|
-
if (opts.facts) {
|
|
32
|
-
if (!existsSync(opts.facts)) {
|
|
33
|
-
out(cmd, { ok: false, error: `facts file not found: ${opts.facts}` });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const parsed = parseFacts(readFileSync(opts.facts, 'utf8'));
|
|
37
|
-
if (!parsed.ok) {
|
|
38
|
-
out(cmd, { ok: false, error: parsed.error });
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
facts = parsed.facts;
|
|
42
|
-
}
|
|
43
|
-
const base = opts.api.replace(/\/$/, '');
|
|
44
|
-
const ask = async (receiver, data) => {
|
|
45
|
-
const res = await fetch(askPath(base, receiver), {
|
|
46
|
-
method: 'POST',
|
|
47
|
-
headers: { 'content-type': 'application/json', ...authHeaders() },
|
|
48
|
-
body: JSON.stringify({ data }),
|
|
49
|
-
});
|
|
50
|
-
// A transport-level failure is its own outcome — never a silent success.
|
|
51
|
-
if (!res.ok)
|
|
52
|
-
return { outcome: `http_${res.status}` };
|
|
53
|
-
return (await res.json());
|
|
54
|
-
};
|
|
55
|
-
const r = await shopInit({ ask }, { workspace, facts });
|
|
56
|
-
if (!r.ok) {
|
|
57
|
-
out(cmd, { ok: false, error: r.error ?? 'shop init failed' });
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
out(cmd, {
|
|
61
|
-
ok: true,
|
|
62
|
-
workspace: r.workspace,
|
|
63
|
-
pages: r.pages,
|
|
64
|
-
open: `/p/${r.pages[0]}`,
|
|
65
|
-
filled: r.filled,
|
|
66
|
-
...(r.fillError ? { fillError: r.fillError } : {}),
|
|
67
|
-
});
|
|
68
|
-
// The pages exist; the facts did not land. Both are true, and the exit
|
|
69
|
-
// code has to carry the half the caller asked for and did not get.
|
|
70
|
-
if (r.fillRequested && !r.filled)
|
|
71
|
-
process.exitCode = 1;
|
|
72
|
-
});
|
|
73
|
-
// A picture of the sale, drawn locally: no key, no network, nothing charged. The drawing lives in
|
|
74
|
-
// lib/sale-card.ts so it is tested without a terminal.
|
|
75
|
-
cmd
|
|
76
|
-
.command('card')
|
|
77
|
-
.description('Draw how your agent sells: the pay card, alone or inside a WhatsApp, SMS or email thread')
|
|
78
|
-
.option('--kind <kind>', `What is sold: ${SALE_KIND_IDS.join('|')}`, 'course')
|
|
79
|
-
.option('--rail <rail>', `How they pay: ${SALE_RAIL_IDS.join('|')}`, 'card')
|
|
80
|
-
.option('--channel <id>', `Where it is sold: ${SALE_CHANNEL_IDS.join('|')}`)
|
|
81
|
-
.option('--all', 'All four offers')
|
|
82
|
-
.option('--paid', 'Draw the card after the tap')
|
|
83
|
-
.action((opts, c) => {
|
|
84
|
-
const kind = saleKindOf(opts.kind);
|
|
85
|
-
const rail = saleRailOf(opts.rail);
|
|
86
|
-
const channel = opts.channel === undefined ? undefined : saleChannelOf(opts.channel);
|
|
87
|
-
// An unknown word is refused, never drawn as the default: a wrong picture reads as a right one.
|
|
88
|
-
if (!kind) {
|
|
89
|
-
out(c, { ok: false, error: `unknown kind "${opts.kind}" — ${SALE_KIND_IDS.join(', ')}` });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (!rail) {
|
|
93
|
-
out(c, { ok: false, error: `unknown rail "${opts.rail}" — ${SALE_RAIL_IDS.join(', ')}` });
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (channel === null) {
|
|
97
|
-
out(c, { ok: false, error: `unknown channel "${opts.channel}" — ${SALE_CHANNEL_IDS.join(', ')}` });
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const kinds = opts.all ? SALE_KIND_IDS : [kind];
|
|
101
|
-
const draw = { rail, channel, phase: opts.paid ? 'paid' : 'idle' };
|
|
102
|
-
if (jsonMode(c)) {
|
|
103
|
-
out(c, saleJson(kinds, draw));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const ascii = !process.stdout.isTTY || 'NO_COLOR' in process.env;
|
|
107
|
-
process.stdout.write(drawSale(kinds, { ...draw, ascii }));
|
|
108
|
-
});
|
|
109
|
-
return cmd;
|
|
110
|
-
}
|
|
@@ -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