oneie 4.0.3 → 4.2.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 +80 -0
- package/dist/package.json +4 -4
- package/dist/src/agent.d.ts +73 -0
- package/dist/src/agent.js +486 -53
- package/dist/src/auth.js +3 -4
- package/dist/src/compiler.js +38 -5
- package/dist/src/doctor.js +61 -6
- package/dist/src/endpoint.d.ts +2 -0
- package/dist/src/endpoint.js +250 -0
- package/dist/src/eval.js +1 -0
- package/dist/src/fn.js +5 -8
- package/dist/src/index.js +8 -0
- package/dist/src/init.js +33 -3
- package/dist/src/lib/agent-env.js +7 -0
- package/dist/src/lib/client.js +16 -7
- package/dist/src/lib/keyfile.d.ts +130 -0
- package/dist/src/lib/keyfile.js +381 -0
- package/dist/src/lib/paths.d.ts +33 -0
- package/dist/src/lib/paths.js +77 -0
- package/dist/src/lib/shop-init.d.ts +62 -0
- package/dist/src/lib/shop-init.js +63 -0
- package/dist/src/lib/tasks-digest.d.ts +66 -0
- package/dist/src/lib/tasks-digest.js +200 -0
- package/dist/src/lib/tasks-graph.d.ts +78 -0
- package/dist/src/lib/tasks-graph.js +425 -0
- package/dist/src/lib/vaultfile.d.ts +73 -0
- package/dist/src/lib/vaultfile.js +184 -0
- package/dist/src/media.d.ts +2 -0
- package/dist/src/media.js +256 -0
- package/dist/src/plugin.js +10 -1
- package/dist/src/shop.d.ts +10 -0
- package/dist/src/shop.js +73 -0
- package/dist/src/skill.js +128 -12
- package/dist/src/tasks.d.ts +2 -0
- package/dist/src/tasks.js +424 -0
- package/dist/src/templates.js +8 -0
- package/dist/src/wallet.d.ts +9 -0
- package/dist/src/wallet.js +259 -1
- package/dist/src/workflow.js +54 -3
- package/package.json +4 -4
- package/dist/src/templates/_node/site/one.config.d.ts +0 -2
- package/dist/src/templates/_node/site/one.config.js +0 -22
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { basename, extname } from 'node:path';
|
|
4
|
+
import { mediaListAllWith } from '@oneie/sdk';
|
|
5
|
+
import { authHeaders, jsonMode, resolveBase } from './lib/client.js';
|
|
6
|
+
import { askPath } from './lib/api-path.js';
|
|
7
|
+
// `one media` — the two media doors a JSON body cannot serve comfortably.
|
|
8
|
+
//
|
|
9
|
+
// WHAT IS DELIBERATELY NOT HERE, and why. The CLI already reaches every receiver:
|
|
10
|
+
// `one ask <receiver> --data '<json>'` (substrate.ts). So a subcommand has to earn
|
|
11
|
+
// its place the way `one tasks board` does — by doing work the raw ask cannot.
|
|
12
|
+
//
|
|
13
|
+
// list EARNS IT — media:list is ONE R2 scan per call with a budget and a
|
|
14
|
+
// cursor, and its `total` is per-page AND a floor whenever `truncated`
|
|
15
|
+
// is present. A raw ask prints scan one and READS AS COMPLETE. That is
|
|
16
|
+
// the 200-row-clamp defect, and it is what this renderer refuses to do.
|
|
17
|
+
// upload EARNS IT — media:upload takes `{ url | base64 }`. You cannot put a
|
|
18
|
+
// local file in a JSON body by hand. This reads it, sizes it against the
|
|
19
|
+
// door's own 5 MiB cap before spending a request, and encodes it.
|
|
20
|
+
// generate DECLINED — it is a prompt string in a JSON body. The answer is
|
|
21
|
+
// `one ask media:generate --data '{"prompt":"a red bicycle"}'`, which is
|
|
22
|
+
// not worse than a wrapper would be. Documented, not built.
|
|
23
|
+
//
|
|
24
|
+
// WORKSPACE. `--workspace` is offered on BOTH verbs because media:upload REFUSES a
|
|
25
|
+
// workspace you may not write ("A refusal is never a downgrade to your own
|
|
26
|
+
// workspace" — its own error describe()). That is the one thing that makes a write
|
|
27
|
+
// flag safe here: the older HTTP doors derive the slug from the session and ignore
|
|
28
|
+
// what they are handed, so an agency's upload landed in the agency's library and
|
|
29
|
+
// looked like it worked. This receiver does not, and the printed `key` proves it —
|
|
30
|
+
// it names the workspace prefix the bytes actually reached.
|
|
31
|
+
const DEFAULT_API = 'https://api.one.ie';
|
|
32
|
+
/** The door's own hard cap (media:upload: "5 MiB hard cap"). Checked here so a
|
|
33
|
+
* doomed 6.7 MiB base64 body is never sent — the refusal is instant and names the number. */
|
|
34
|
+
const UPLOAD_MAX_BYTES = 5 * 1024 * 1024;
|
|
35
|
+
/** media:list's `prefix` is an enum, not a free string — refuse locally rather than
|
|
36
|
+
* spend a request on a value the zod schema will reject. */
|
|
37
|
+
const PREFIXES = ['media', 'chat', 'ads', 'products', 'pages', 'brand', 'courses'];
|
|
38
|
+
const VIDEO_EXT = new Set(['.mp4', '.webm', '.mov', '.m4v', '.avi', '.mkv']);
|
|
39
|
+
const CONTENT_TYPES = {
|
|
40
|
+
'.png': 'image/png',
|
|
41
|
+
'.jpg': 'image/jpeg',
|
|
42
|
+
'.jpeg': 'image/jpeg',
|
|
43
|
+
'.gif': 'image/gif',
|
|
44
|
+
'.webp': 'image/webp',
|
|
45
|
+
'.avif': 'image/avif',
|
|
46
|
+
};
|
|
47
|
+
function fail(msg) {
|
|
48
|
+
process.stderr.write(`error ${msg}\n`);
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
}
|
|
51
|
+
function asker(api) {
|
|
52
|
+
const base = resolveBase({ api }, DEFAULT_API);
|
|
53
|
+
return async (receiver, data, timeoutMs) => {
|
|
54
|
+
const res = await fetch(askPath(base, receiver), {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
headers: authHeaders(),
|
|
57
|
+
body: JSON.stringify(timeoutMs ? { data, timeoutMs } : { data }),
|
|
58
|
+
});
|
|
59
|
+
const text = await res.text();
|
|
60
|
+
let body;
|
|
61
|
+
try {
|
|
62
|
+
body = text ? JSON.parse(text) : undefined;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
// A refusal wears an envelope at HTTP 200 as readily as at 4xx — read the envelope, not the status.
|
|
68
|
+
if (!res.ok && !(body && typeof body === 'object' && 'outcome' in body)) {
|
|
69
|
+
throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
|
|
70
|
+
}
|
|
71
|
+
return unwrap(receiver, body);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Unwrap the ask door's `{ outcome, result }`. A failure whose result is a receiver
|
|
75
|
+
* body (`{ ok:false, error }`) is RETURNED, not thrown — the caller keeps its receipt. */
|
|
76
|
+
function unwrap(receiver, raw) {
|
|
77
|
+
if (!raw || typeof raw !== 'object')
|
|
78
|
+
throw new Error(`${receiver}: empty response`);
|
|
79
|
+
const o = raw;
|
|
80
|
+
if ('outcome' in o) {
|
|
81
|
+
if (o.outcome === 'result')
|
|
82
|
+
return o.result ?? {};
|
|
83
|
+
const inner = o.result;
|
|
84
|
+
if (inner && typeof inner === 'object' && ('ok' in inner || 'error' in inner)) {
|
|
85
|
+
return { ok: false, ...inner, error: inner.error ?? String(o.outcome) };
|
|
86
|
+
}
|
|
87
|
+
const why = typeof o.reason === 'string' ? ` (${o.reason})` : '';
|
|
88
|
+
throw new Error(`${receiver}: ${String(o.outcome)}${why}`);
|
|
89
|
+
}
|
|
90
|
+
if ('result' in o)
|
|
91
|
+
return o.result ?? {};
|
|
92
|
+
return o;
|
|
93
|
+
}
|
|
94
|
+
function human(bytes) {
|
|
95
|
+
if (bytes === null || bytes === undefined)
|
|
96
|
+
return '?';
|
|
97
|
+
if (bytes < 1024)
|
|
98
|
+
return `${bytes}B`;
|
|
99
|
+
if (bytes < 1024 * 1024)
|
|
100
|
+
return `${(bytes / 1024).toFixed(1)}K`;
|
|
101
|
+
return `${(bytes / 1024 / 1024).toFixed(1)}M`;
|
|
102
|
+
}
|
|
103
|
+
function counts(rec) {
|
|
104
|
+
const rows = Object.entries(rec ?? {}).sort((a, b) => b[1] - a[1]);
|
|
105
|
+
return rows.length ? rows.map(([k, v]) => `${k || '(root)'}=${v}`).join(' ') : '-';
|
|
106
|
+
}
|
|
107
|
+
function renderList(res) {
|
|
108
|
+
const items = res.items ?? [];
|
|
109
|
+
const w = process.stdout;
|
|
110
|
+
// ABSENT IS NOT FALSE: a complete answer carries no `truncated` key at all.
|
|
111
|
+
const short = res.truncated !== undefined;
|
|
112
|
+
// THE RULE: a total beside a present `truncated` is a FLOOR, never a count.
|
|
113
|
+
const totalTxt = res.total === undefined ? '?' : short ? `at least ${res.total}` : `${res.total}`;
|
|
114
|
+
w.write(`${items.length} rows, ${totalTxt} media` +
|
|
115
|
+
`${res.scanned !== undefined ? ` scanned=${res.scanned} objects` : ''}` +
|
|
116
|
+
`${res.pages ? ` pages=${res.pages}` : ''}\n`);
|
|
117
|
+
if (short) {
|
|
118
|
+
w.write(`TRUNCATED: the scan budget bit — "${res.total ?? '?'}" is a FLOOR, not a count ` +
|
|
119
|
+
`${JSON.stringify(res.truncated)}\n`);
|
|
120
|
+
}
|
|
121
|
+
if (res.nextCursor) {
|
|
122
|
+
w.write(`MORE: nextCursor=${res.nextCursor} — rerun with --all to walk every page\n`);
|
|
123
|
+
}
|
|
124
|
+
// scanned far above total means most of the bucket is not media — following the
|
|
125
|
+
// cursor is the right move, and concluding "empty workspace" is the wrong one.
|
|
126
|
+
if (!short && res.scanned !== undefined && res.total !== undefined && res.scanned > res.total * 4) {
|
|
127
|
+
w.write(`note most of what was scanned is not media (${res.total} of ${res.scanned})\n`);
|
|
128
|
+
}
|
|
129
|
+
if (res.byPrefix)
|
|
130
|
+
w.write(`byPrefix ${counts(res.byPrefix)}\n`);
|
|
131
|
+
if (items.length)
|
|
132
|
+
w.write('\n');
|
|
133
|
+
for (const it of items) {
|
|
134
|
+
w.write(`${it.key} ${it.kind} ${human(it.size)} ${it.contentType} ${it.uploaded ?? '-'}\n`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export function mediaCmd() {
|
|
138
|
+
const cmd = new Command('media').description('A workspace media library — list the WHOLE of it, upload a local file. ' +
|
|
139
|
+
'(generate has no subcommand on purpose: one ask media:generate --data \'{"prompt":"..."}\')');
|
|
140
|
+
cmd
|
|
141
|
+
.command('list')
|
|
142
|
+
.description('List media (media:list) — rows, an honest total, and a loud word when the scan was cut short')
|
|
143
|
+
.option('--workspace <slug>', 'Group slug to read (default: your own). Honoured only if you may read it.')
|
|
144
|
+
.option('--kind <k>', 'image | video — filters the rows on a page, does not change what is scanned')
|
|
145
|
+
.option('--prefix <p>', `Only this namespace: ${PREFIXES.join(' | ')}`)
|
|
146
|
+
.option('--limit <n>', 'R2 objects to SCAN per page BEFORE filtering — not a row count. Default 500, max 1000.')
|
|
147
|
+
.option('--all', 'Follow nextCursor until every page is read (ceiling 20 pages)')
|
|
148
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
149
|
+
.option('--json', 'Print the raw response')
|
|
150
|
+
.action(async (opts, sub) => {
|
|
151
|
+
if (opts.kind && opts.kind !== 'image' && opts.kind !== 'video') {
|
|
152
|
+
return fail("--kind must be 'image' or 'video'");
|
|
153
|
+
}
|
|
154
|
+
if (opts.prefix && !PREFIXES.includes(opts.prefix)) {
|
|
155
|
+
return fail(`--prefix must be one of: ${PREFIXES.join(', ')}`);
|
|
156
|
+
}
|
|
157
|
+
const limit = opts.limit === undefined ? undefined : Number(opts.limit);
|
|
158
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 1000)) {
|
|
159
|
+
return fail('--limit must be a whole number from 1 to 1000 (R2\'s own ceiling)');
|
|
160
|
+
}
|
|
161
|
+
const req = {
|
|
162
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
163
|
+
...(opts.kind ? { kind: opts.kind } : {}),
|
|
164
|
+
...(opts.prefix ? { prefix: opts.prefix } : {}),
|
|
165
|
+
...(limit !== undefined ? { limit } : {}),
|
|
166
|
+
};
|
|
167
|
+
const ask = asker(opts.api);
|
|
168
|
+
let res;
|
|
169
|
+
try {
|
|
170
|
+
res = opts.all
|
|
171
|
+
? await mediaListAllWith((r, d) => ask(r, d), req)
|
|
172
|
+
: (await ask('media:list', req));
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
176
|
+
}
|
|
177
|
+
if (jsonMode(sub))
|
|
178
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
179
|
+
else if (res.ok !== false)
|
|
180
|
+
renderList(res);
|
|
181
|
+
if (res.ok === false)
|
|
182
|
+
fail(res.error ?? 'media:list failed');
|
|
183
|
+
});
|
|
184
|
+
cmd
|
|
185
|
+
.command('upload <path>')
|
|
186
|
+
.description('Upload a LOCAL image file (media:upload) — read, sized against the 5 MiB cap, base64 encoded. ' +
|
|
187
|
+
'For a remote URL: one ask media:upload --data \'{"url":"https://…"}\'')
|
|
188
|
+
.option('--workspace <slug>', 'Group slug to write (default: your own). A workspace you may not write is REFUSED, never downgraded.')
|
|
189
|
+
.option('--content-type <ct>', 'A HINT only — the stored type is decided by the magic bytes')
|
|
190
|
+
.option('--filename <name>', 'A LABEL for the key, not a path (default: the basename). The extension always comes from the sniffed bytes.')
|
|
191
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
192
|
+
.option('--json', 'Print the raw response')
|
|
193
|
+
.action(async (path, opts, sub) => {
|
|
194
|
+
let size;
|
|
195
|
+
try {
|
|
196
|
+
const st = statSync(path);
|
|
197
|
+
if (!st.isFile())
|
|
198
|
+
return fail(`${path} is not a file`);
|
|
199
|
+
size = st.size;
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
return fail(`${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
203
|
+
}
|
|
204
|
+
if (size === 0)
|
|
205
|
+
return fail(`${path} is empty`);
|
|
206
|
+
const ext = extname(path).toLowerCase();
|
|
207
|
+
if (VIDEO_EXT.has(ext)) {
|
|
208
|
+
// Not a policy this CLI invented — media:upload declares "video is not
|
|
209
|
+
// accepted here" and names the door that does. Refusing locally spends no
|
|
210
|
+
// request and points at the right one.
|
|
211
|
+
return fail(`${path} is video, and media:upload takes raster images only. Nothing was sent. ` +
|
|
212
|
+
'There is no receiver for video yet — the streamed door is PUT /api/media/video-upload (100 MB).');
|
|
213
|
+
}
|
|
214
|
+
if (ext === '.svg') {
|
|
215
|
+
return fail(`${path} is SVG, which media:upload refuses deliberately (the public reader serves the stored type verbatim). Nothing was sent.`);
|
|
216
|
+
}
|
|
217
|
+
if (size > UPLOAD_MAX_BYTES) {
|
|
218
|
+
return fail(`${path} is ${human(size)} — media:upload caps at ${human(UPLOAD_MAX_BYTES)}. Nothing was sent. ` +
|
|
219
|
+
'Host the file and pass a URL instead: one ask media:upload --data \'{"url":"https://…"}\'');
|
|
220
|
+
}
|
|
221
|
+
const contentType = opts.contentType ?? CONTENT_TYPES[ext];
|
|
222
|
+
let base64;
|
|
223
|
+
try {
|
|
224
|
+
base64 = readFileSync(path).toString('base64');
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
return fail(`${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
228
|
+
}
|
|
229
|
+
const data = {
|
|
230
|
+
base64,
|
|
231
|
+
filename: opts.filename ?? basename(path, ext),
|
|
232
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
233
|
+
...(contentType ? { contentType } : {}),
|
|
234
|
+
};
|
|
235
|
+
let res;
|
|
236
|
+
try {
|
|
237
|
+
// 30s is the ask door's own ceiling, and a 5 MiB body measured 6.6s wall to prod.
|
|
238
|
+
res = (await asker(opts.api)('media:upload', data, 30_000));
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
return fail(e instanceof Error ? e.message : String(e));
|
|
242
|
+
}
|
|
243
|
+
if (jsonMode(sub)) {
|
|
244
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
245
|
+
}
|
|
246
|
+
else if (res.ok !== false) {
|
|
247
|
+
// The `key` is the receipt: it names the workspace prefix the bytes ACTUALLY
|
|
248
|
+
// reached. Printed always, so a --workspace upload can never merely look right.
|
|
249
|
+
process.stdout.write(`ok key=${res.key ?? '?'} kind=${res.kind ?? '?'} type=${res.contentType ?? '?'} stored=${human(res.size)} sent=${human(size)}\n` +
|
|
250
|
+
` ${res.url ?? ''}\n`);
|
|
251
|
+
}
|
|
252
|
+
if (res.ok === false)
|
|
253
|
+
fail(res.error ?? 'media:upload failed');
|
|
254
|
+
});
|
|
255
|
+
return cmd;
|
|
256
|
+
}
|
package/dist/src/plugin.js
CHANGED
|
@@ -19,8 +19,17 @@ function apiBase(opts) {
|
|
|
19
19
|
return resolveBase(opts, 'https://one.ie');
|
|
20
20
|
}
|
|
21
21
|
function bearerHeaders(workspace) {
|
|
22
|
+
// THE TOKEN IS THE PLAIN KEY -- the eleventh site of the `${slug}:${key}` bug.
|
|
23
|
+
// `requireAuth` (one.ie/web/src/lib/api-auth.ts:317) resolves a world key by
|
|
24
|
+
// PREFIX (`one-` / `osk_`), so prepending "<workspace>:" produces
|
|
25
|
+
// `one:one-abc...`, which matches no prefix, falls through to session auth and
|
|
26
|
+
// 401s. Ten call sites in agent.ts and skill.ts were fixed for exactly this;
|
|
27
|
+
// this one was missed, which broke `plugin buy` (POST /api/ask/plugins:buy,
|
|
28
|
+
// gated by requireAuth) and `plugin source` for every key-authenticated user.
|
|
29
|
+
// The workspace still gates whether we send auth at all -- it just never
|
|
30
|
+
// belonged inside the credential.
|
|
22
31
|
const key = resolveKey();
|
|
23
|
-
return key && workspace ? { Authorization: `Bearer ${
|
|
32
|
+
return key && workspace ? { Authorization: `Bearer ${key}` } : {};
|
|
24
33
|
}
|
|
25
34
|
// npm pack wraps a package's contents under a "package/" root — strip-components=1 lands
|
|
26
35
|
// the real package.json + src/ directly at ./plugin-<name>/, same as a real npm install would.
|
|
@@ -0,0 +1,10 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { authHeaders, out, resolveBase } from './lib/client.js';
|
|
4
|
+
import { askPath } from './lib/api-path.js';
|
|
5
|
+
import { parseFacts, shopInit } from './lib/shop-init.js';
|
|
6
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
|
+
/**
|
|
8
|
+
* `one shop init` — twelve draft pages, and the seller's own facts written into
|
|
9
|
+
* them, from the terminal. A thin wrapper over two receivers (no new route):
|
|
10
|
+
* `pages:instantiate-shop-pack` then `pages:fill-shop-pack`. The receivers walk
|
|
11
|
+
* authority server-side; the API key identifies the caller.
|
|
12
|
+
*
|
|
13
|
+
* The logic lives in `lib/shop-init.ts` so it is tested without a network.
|
|
14
|
+
*/
|
|
15
|
+
export function shopCmd() {
|
|
16
|
+
const cmd = new Command('shop').description('Build a shop from the twelve-page pack');
|
|
17
|
+
cmd
|
|
18
|
+
.command('init')
|
|
19
|
+
.description('Seed the shop pack into a workspace, and fill it from a facts file')
|
|
20
|
+
.option('--facts <path>', 'JSON file of ShopBusinessFacts — a fact left out stays a visible placeholder')
|
|
21
|
+
.option('--workspace <slug>', 'Workspace to seed (defaults to ONEIE_WORKSPACE)')
|
|
22
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
23
|
+
.action(async (opts) => {
|
|
24
|
+
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE ?? '';
|
|
25
|
+
if (!workspace) {
|
|
26
|
+
out(cmd, { ok: false, error: 'no workspace — pass --workspace <slug> or set ONEIE_WORKSPACE' });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let facts;
|
|
30
|
+
if (opts.facts) {
|
|
31
|
+
if (!existsSync(opts.facts)) {
|
|
32
|
+
out(cmd, { ok: false, error: `facts file not found: ${opts.facts}` });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const parsed = parseFacts(readFileSync(opts.facts, 'utf8'));
|
|
36
|
+
if (!parsed.ok) {
|
|
37
|
+
out(cmd, { ok: false, error: parsed.error });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
facts = parsed.facts;
|
|
41
|
+
}
|
|
42
|
+
const base = opts.api.replace(/\/$/, '');
|
|
43
|
+
const ask = async (receiver, data) => {
|
|
44
|
+
const res = await fetch(askPath(base, receiver), {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'content-type': 'application/json', ...authHeaders() },
|
|
47
|
+
body: JSON.stringify({ data }),
|
|
48
|
+
});
|
|
49
|
+
// A transport-level failure is its own outcome — never a silent success.
|
|
50
|
+
if (!res.ok)
|
|
51
|
+
return { outcome: `http_${res.status}` };
|
|
52
|
+
return (await res.json());
|
|
53
|
+
};
|
|
54
|
+
const r = await shopInit({ ask }, { workspace, facts });
|
|
55
|
+
if (!r.ok) {
|
|
56
|
+
out(cmd, { ok: false, error: r.error ?? 'shop init failed' });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
out(cmd, {
|
|
60
|
+
ok: true,
|
|
61
|
+
workspace: r.workspace,
|
|
62
|
+
pages: r.pages,
|
|
63
|
+
open: `/p/${r.pages[0]}`,
|
|
64
|
+
filled: r.filled,
|
|
65
|
+
...(r.fillError ? { fillError: r.fillError } : {}),
|
|
66
|
+
});
|
|
67
|
+
// The pages exist; the facts did not land. Both are true, and the exit
|
|
68
|
+
// code has to carry the half the caller asked for and did not get.
|
|
69
|
+
if (r.fillRequested && !r.filled)
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
});
|
|
72
|
+
return cmd;
|
|
73
|
+
}
|
package/dist/src/skill.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { KEY_FILE } from './lib/paths.js';
|
|
2
3
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, readdirSync } from 'node:fs';
|
|
3
4
|
import { resolve, basename, join } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
5
|
import { parse as parseSkill } from './skill-parser.js';
|
|
6
|
+
import { askPath } from './lib/api-path.js';
|
|
6
7
|
export function skillCmd() {
|
|
7
8
|
const cmd = new Command('skill').description('Skill management');
|
|
8
9
|
cmd.command('new <name>')
|
|
@@ -77,7 +78,7 @@ export function skillCmd() {
|
|
|
77
78
|
.option('--name <name>', 'Override skill name')
|
|
78
79
|
.option('--yes', 'Skip approval prompt (CI-friendly)')
|
|
79
80
|
.action(async (ref, opts) => {
|
|
80
|
-
const keyFile =
|
|
81
|
+
const keyFile = KEY_FILE;
|
|
81
82
|
const token = process.env.ONEIE_API_KEY ?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
82
83
|
if (!token) {
|
|
83
84
|
out(cmd, { ok: false, error: 'not authenticated — run `oneie auth login`' });
|
|
@@ -112,18 +113,91 @@ export function skillCmd() {
|
|
|
112
113
|
out(cmd, { ok: false, error: err.message, hint: 'try `oneie skill validate <path>` for offline validation' });
|
|
113
114
|
}
|
|
114
115
|
});
|
|
116
|
+
// `skill:save` is the ONLY writer of the store `skill:run` / `skills:list`
|
|
117
|
+
// actually read (`{slug}/skills/{name}/SKILL.md` in R2). It had no CLI verb:
|
|
118
|
+
// `skill publish` writes the agentskills.io directory format to the LOCAL disk
|
|
119
|
+
// and `skill import` pulls someone else's in, so the one thing an author could
|
|
120
|
+
// not do from the CLI was push their own skill to their own workspace. `one push`
|
|
121
|
+
// reaches it, but only by compiling a whole `ai/` tree — there was no way to
|
|
122
|
+
// send a single file.
|
|
123
|
+
cmd.command('push <path>')
|
|
124
|
+
.description("Upload a SKILL.md into a workspace's R2 catalog — the store skill:run and skills:list read")
|
|
125
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
126
|
+
.option('--api <url>', 'API base URL', 'https://one.ie')
|
|
127
|
+
.option('--name <name>', 'Override skill name (defaults to frontmatter name:)')
|
|
128
|
+
.action(async (path, opts) => {
|
|
129
|
+
if (!existsSync(path)) {
|
|
130
|
+
out(cmd, { ok: false, error: `not found: ${path}` });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const content = readFileSync(path, 'utf8');
|
|
134
|
+
// THE NAME IS NEVER GUESSED FROM THE PATH. An earlier draft fell back to the
|
|
135
|
+
// parent directory name, and `skill push /etc/hosts --slug one` therefore
|
|
136
|
+
// published a skill called "etc" containing the host file — accepted, live,
|
|
137
|
+
// and resolvable by `skill:run`. R2 has no skill-delete receiver, so that had
|
|
138
|
+
// to be cleaned up with a direct `wrangler r2 object delete`. A path is not
|
|
139
|
+
// an identity: the frontmatter declares the name, or the caller does.
|
|
140
|
+
if (!/^---\s*$/m.test(content.split('\n')[0] ?? '')) {
|
|
141
|
+
out(cmd, { ok: false, error: `not a skill: ${path} has no YAML frontmatter (a SKILL.md opens with ---)` });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const fmName = /^name:\s*(\S+)\s*$/m.exec(content.split(/^---\s*$/m)[1] ?? '')?.[1];
|
|
145
|
+
const name = opts.name ?? fmName;
|
|
146
|
+
if (!name) {
|
|
147
|
+
out(cmd, { ok: false, error: 'no skill name — add `name:` to the frontmatter, or pass --name <name>' });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
151
|
+
out(cmd, { ok: false, error: `invalid skill name "${name}" — lowercase alphanumeric and hyphens only` });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const keyFile = KEY_FILE;
|
|
155
|
+
const key = process.env.ONE_API_KEY ?? process.env.ONEIE_API_KEY
|
|
156
|
+
?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
157
|
+
if (!key) {
|
|
158
|
+
out(cmd, { ok: false, error: 'no API key — run `oneie auth login` or set ONE_API_KEY' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const res = await fetch(askPath(opts.api.replace(/\/$/, ''), 'skill:save'), {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
165
|
+
body: JSON.stringify({ data: { slug: opts.slug, name, content } }),
|
|
166
|
+
});
|
|
167
|
+
const text = await res.text();
|
|
168
|
+
const envelope = (text ? JSON.parse(text) : {});
|
|
169
|
+
const result = envelope.result ?? {};
|
|
170
|
+
// THE ASK ENVELOPE ANSWERS HTTP 200 ON A REFUSAL — `outcome: "failure"`
|
|
171
|
+
// carries the receiver's error under a 200, so `res.ok` alone would report
|
|
172
|
+
// a refused push as a success.
|
|
173
|
+
if (!res.ok || envelope.outcome === 'failure' || result.ok === false) {
|
|
174
|
+
const base = result.error ?? text ?? 'push failed';
|
|
175
|
+
const hint = result.callerRole === 'anonymous'
|
|
176
|
+
? 'the key was not recognised — run `oneie auth login`, or set ONE_API_KEY to a world key (it starts `one-` or `osk_`)'
|
|
177
|
+
: result.error === 'forbidden'
|
|
178
|
+
? `the key is valid but does not control workspace "${opts.slug}"`
|
|
179
|
+
: undefined;
|
|
180
|
+
out(cmd, { ok: false, status: res.status, error: hint ? `${base} — ${hint}` : base });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
out(cmd, { ok: true, name: result.name ?? name, slug: opts.slug, bytes: result.bytes ?? content.length });
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
out(cmd, { ok: false, error: err.message });
|
|
187
|
+
}
|
|
188
|
+
});
|
|
115
189
|
cmd.command('fork <name>')
|
|
116
190
|
.description('Copy an open skill into a workspace (refuses sealed — invoke-only)')
|
|
117
191
|
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
118
192
|
.option('--api <url>', 'API base URL', 'https://one.ie')
|
|
119
193
|
.action(async (name, opts) => {
|
|
120
|
-
const keyFile =
|
|
194
|
+
const keyFile = KEY_FILE;
|
|
121
195
|
const key = process.env.ONEIE_API_KEY ?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
122
196
|
if (!key) {
|
|
123
197
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
124
198
|
return;
|
|
125
199
|
}
|
|
126
|
-
const token =
|
|
200
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
127
201
|
try {
|
|
128
202
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skills/workspace?slug=${encodeURIComponent(opts.slug)}`, {
|
|
129
203
|
headers: { Authorization: `Bearer ${token}` },
|
|
@@ -153,13 +227,13 @@ export function skillCmd() {
|
|
|
153
227
|
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
154
228
|
.option('--api <url>', 'API base URL', 'https://one.ie')
|
|
155
229
|
.action(async (opts) => {
|
|
156
|
-
const keyFile =
|
|
230
|
+
const keyFile = KEY_FILE;
|
|
157
231
|
const key = process.env.ONEIE_API_KEY ?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
158
232
|
if (!key) {
|
|
159
233
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
160
234
|
return;
|
|
161
235
|
}
|
|
162
|
-
const token =
|
|
236
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
163
237
|
try {
|
|
164
238
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skills/workspace?slug=${encodeURIComponent(opts.slug)}`, {
|
|
165
239
|
headers: { Authorization: `Bearer ${token}` },
|
|
@@ -180,13 +254,13 @@ export function skillCmd() {
|
|
|
180
254
|
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
181
255
|
.option('--api <url>', 'API base URL', 'https://one.ie')
|
|
182
256
|
.action(async (name, opts) => {
|
|
183
|
-
const keyFile =
|
|
257
|
+
const keyFile = KEY_FILE;
|
|
184
258
|
const key = process.env.ONEIE_API_KEY ?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
185
259
|
if (!key) {
|
|
186
260
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
187
261
|
return;
|
|
188
262
|
}
|
|
189
|
-
const token =
|
|
263
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
190
264
|
try {
|
|
191
265
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skill/${encodeURIComponent(name)}?slug=${encodeURIComponent(opts.slug)}`, {
|
|
192
266
|
method: 'DELETE',
|
|
@@ -267,7 +341,7 @@ export function skillCmd() {
|
|
|
267
341
|
out(cmd, { ok: false, error: `not found: ${path}` });
|
|
268
342
|
return;
|
|
269
343
|
}
|
|
270
|
-
const keyFile =
|
|
344
|
+
const keyFile = KEY_FILE;
|
|
271
345
|
const token = process.env.ONEIE_API_KEY ?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
272
346
|
if (!token) {
|
|
273
347
|
out(cmd, { ok: false, error: 'not authenticated — run `oneie auth login`' });
|
|
@@ -276,15 +350,17 @@ export function skillCmd() {
|
|
|
276
350
|
const content = readFileSync(path, 'utf8');
|
|
277
351
|
const parsed = parseSkill(content, { pathStem: basename(path, '.md') });
|
|
278
352
|
const skillName = typeof parsed.meta.name === 'string' ? parsed.meta.name : basename(path, '.md');
|
|
279
|
-
|
|
353
|
+
// Frontmatter is canonical when present; otherwise fall back to the bank.
|
|
354
|
+
const frontmatterEvals = extractEvals(content);
|
|
355
|
+
const evals = frontmatterEvals.length ? frontmatterEvals : readSidecarEvals(path);
|
|
280
356
|
if (!evals.length) {
|
|
281
|
-
out(cmd, { ok: false, error:
|
|
357
|
+
out(cmd, { ok: false, error: `no evals for ${skillName} — add an evals: block to the frontmatter, or an evals/evals.json bank beside it (see \`oneie skill new\`)` });
|
|
282
358
|
return;
|
|
283
359
|
}
|
|
284
360
|
try {
|
|
285
361
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/eval`, {
|
|
286
362
|
method: 'POST',
|
|
287
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${
|
|
363
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
288
364
|
body: JSON.stringify({ slug: opts.slug, skillPath: skillName, iteration: Number(opts.iteration), draftContent: content, draftEvals: evals }),
|
|
289
365
|
});
|
|
290
366
|
const data = await res.json().catch(() => ({}));
|
|
@@ -310,6 +386,46 @@ export function skillCmd() {
|
|
|
310
386
|
});
|
|
311
387
|
return cmd;
|
|
312
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Evals live in two places and only one of them was ever read here:
|
|
391
|
+
* 1. an `evals:` block in SKILL.md frontmatter
|
|
392
|
+
* 2. a sibling `evals/evals.json` bank
|
|
393
|
+
* Every shipped skill uses (2) — measured 51 sidecar banks and 0 frontmatter
|
|
394
|
+
* blocks under one.ie/ai/skills — so `skill eval` refused every real skill with
|
|
395
|
+
* "no evals found in frontmatter". The server already reads both
|
|
396
|
+
* (pages/api/eval.ts), so this only brings the CLI's local read in line.
|
|
397
|
+
*
|
|
398
|
+
* The bank is either a bare array or `{ skill_name, evals: [...] }`, and its
|
|
399
|
+
* cases say `expected_output` where TestCase says `expected`. Normalise both.
|
|
400
|
+
*/
|
|
401
|
+
function readSidecarEvals(skillPath) {
|
|
402
|
+
const dir = skillPath.endsWith('.md') ? resolve(skillPath, '..') : skillPath;
|
|
403
|
+
const bank = join(dir, 'evals', 'evals.json');
|
|
404
|
+
if (!existsSync(bank))
|
|
405
|
+
return [];
|
|
406
|
+
try {
|
|
407
|
+
const raw = JSON.parse(readFileSync(bank, 'utf8'));
|
|
408
|
+
const list = Array.isArray(raw)
|
|
409
|
+
? raw
|
|
410
|
+
: Array.isArray(raw.evals)
|
|
411
|
+
? raw.evals
|
|
412
|
+
: [];
|
|
413
|
+
return list
|
|
414
|
+
.map((c, i) => {
|
|
415
|
+
const o = c;
|
|
416
|
+
return {
|
|
417
|
+
id: o.id === undefined ? `case-${i + 1}` : String(o.id),
|
|
418
|
+
prompt: typeof o.prompt === 'string' ? o.prompt : '',
|
|
419
|
+
expected: String(o.expected ?? o.expected_output ?? ''),
|
|
420
|
+
assertions: Array.isArray(o.assertions) ? o.assertions.map(String) : [],
|
|
421
|
+
};
|
|
422
|
+
})
|
|
423
|
+
.filter(c => c.prompt && c.assertions.length > 0);
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
313
429
|
// Mirrors one.ie/web/src/lib/eval/evals-source.ts and packages/mcp/src/tools/lifecycle.ts
|
|
314
430
|
function extractEvals(content) {
|
|
315
431
|
const fm = content.match(/^---\n([\s\S]*?)\n---/)?.[1];
|