@agentrq/agentrq-ws 0.10.0 → 0.10.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 +3 -2
- package/package.json +1 -1
- package/src/cli.js +6 -0
- package/src/commands.js +62 -6
package/README.md
CHANGED
|
@@ -57,8 +57,9 @@ Node 20.6 or newer.
|
|
|
57
57
|
| `skill load <uri>` | Read a skill file (`skill://<name>` reads its `SKILL.md`) |
|
|
58
58
|
| `skill save <uri> --content …` | Replace a file of one of this workspace's skills |
|
|
59
59
|
| `skill delete <uri>` | Take a skill out of this workspace (`skill://<name>`), deleting it when no other workspace uses it, or delete one of its files |
|
|
60
|
-
| `pano save [id] --title … --markdown …` | Create a Pano doc, or replace one, and print its id; `--file` sends a file the markdown links, `--ttl-days` and `--color` set its life and post-it |
|
|
61
|
-
| `pano
|
|
60
|
+
| `pano save [id --version N] --title … --markdown …` | Create a Pano doc, or replace one, and print its id and version; replacing needs the `--version` you read and is refused if the doc changed since; `--file` sends a file the markdown links, `--ttl-days` and `--color` set its life and post-it |
|
|
61
|
+
| `pano edit <id> --version N …` | Change part of a doc without resending it: `--replace TEXT --with TEXT` (the text must occur once), `--append TEXT`, or `--ops` as a JSON array; the ops apply all or none. Prints the id and new version |
|
|
62
|
+
| `pano read <id>` | Read a Pano doc (its `version` included), `--comments`/`--attachments` adding those; `--out DIR` writes its markdown and downloads its files instead, printing its version and their paths |
|
|
62
63
|
| `pano comment <id> <text>` | Comment on a Pano doc |
|
|
63
64
|
| `pano attach <id> --file PATH…` | Attach files to a Pano doc; they need no link |
|
|
64
65
|
| `pano delete <id>` | Delete a Pano doc |
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -38,6 +38,12 @@ export async function run({
|
|
|
38
38
|
const write = (stream, text) => stream.write(`${text}\n`)
|
|
39
39
|
|
|
40
40
|
try {
|
|
41
|
+
// `--help "memory load"` reads as `help memory load`: a leading help flag
|
|
42
|
+
// asks for the help of whatever follows, rather than being an unknown command.
|
|
43
|
+
// A quoted "memory load" is one argument, so split it into words.
|
|
44
|
+
if (argv[0] === '--help' || argv[0] === '-h') {
|
|
45
|
+
argv = ['help', ...argv.slice(1).flatMap((arg) => arg.split(/\s+/).filter(Boolean))]
|
|
46
|
+
}
|
|
41
47
|
if (argv.length === 0 || argv[0] === 'help') {
|
|
42
48
|
const target = argv.slice(1)
|
|
43
49
|
if (target.length > 0) {
|
package/src/commands.js
CHANGED
|
@@ -152,7 +152,8 @@ function panoFiles(paths) {
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* The pano tool answers with the doc as JSON, or with a refusal's text. With
|
|
155
|
-
* idOnly a doc prints as its id, which is all a write needs to
|
|
155
|
+
* idOnly a doc prints as its id and version, which is all a write needs to
|
|
156
|
+
* hand on: the next update must send that version.
|
|
156
157
|
*/
|
|
157
158
|
function printPanoDoc(result, { idOnly = false } = {}) {
|
|
158
159
|
let doc
|
|
@@ -161,7 +162,41 @@ function printPanoDoc(result, { idOnly = false } = {}) {
|
|
|
161
162
|
} catch {
|
|
162
163
|
return result
|
|
163
164
|
}
|
|
164
|
-
return { text: idOnly ? doc.id : result.text, data: doc }
|
|
165
|
+
return { text: idOnly ? [doc.id, doc.version].filter((x) => x !== undefined).join(' ') : result.text, data: doc }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The ops of pano edit: --ops (a JSON array, as the tool takes it), then --replace/--with, then --append. */
|
|
169
|
+
async function panoEditOps(ctx) {
|
|
170
|
+
const { ops, replace, with: newString, append } = ctx.values
|
|
171
|
+
const out = []
|
|
172
|
+
if (ops !== undefined) {
|
|
173
|
+
let parsed
|
|
174
|
+
try {
|
|
175
|
+
parsed = JSON.parse(await resolveText(ops, { stdin: ctx.stdin, what: 'the ops' }))
|
|
176
|
+
} catch (err) {
|
|
177
|
+
if (err instanceof UserError) throw err
|
|
178
|
+
throw new UserError(`--ops is not JSON: ${err.message}`)
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(parsed)) throw new UserError('--ops must be a JSON array of {op, ...}')
|
|
181
|
+
out.push(...parsed)
|
|
182
|
+
}
|
|
183
|
+
if (replace !== undefined) {
|
|
184
|
+
if (newString === undefined) throw new UserError('--replace needs --with, the text it becomes')
|
|
185
|
+
out.push({ op: 'replace', oldString: replace, newString })
|
|
186
|
+
} else if (newString !== undefined) {
|
|
187
|
+
throw new UserError('--with needs --replace, the text to replace')
|
|
188
|
+
}
|
|
189
|
+
if (append !== undefined) out.push({ op: 'append', text: await resolveText(append, { stdin: ctx.stdin, what: 'the text to append' }) })
|
|
190
|
+
if (out.length === 0) throw new UserError('nothing to do: give --ops, --replace and --with, or --append')
|
|
191
|
+
return out
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The doc's version, as a flag: required to change a doc that exists. */
|
|
195
|
+
function panoVersion(value) {
|
|
196
|
+
if (value === undefined) throw new UserError('--version is required to change a doc: the version you read (pano read prints it)')
|
|
197
|
+
const version = Number(value)
|
|
198
|
+
if (!Number.isInteger(version) || version < 1) throw new UserError('--version must be a whole number, 1 or more')
|
|
199
|
+
return version
|
|
165
200
|
}
|
|
166
201
|
|
|
167
202
|
/**
|
|
@@ -184,7 +219,8 @@ async function downloadPanoDoc(ctx, doc, out) {
|
|
|
184
219
|
if (doc.comments) {
|
|
185
220
|
paths.push(writeAttachment(join(dir, 'comments.json'), Buffer.from(JSON.stringify(doc.comments, null, 2))).path)
|
|
186
221
|
}
|
|
187
|
-
|
|
222
|
+
const version = doc.version === undefined ? [] : [`version ${doc.version}`]
|
|
223
|
+
return { text: [...version, ...paths].join('\n'), data: { ...doc, paths } }
|
|
188
224
|
}
|
|
189
225
|
|
|
190
226
|
export const COMMANDS = [
|
|
@@ -388,9 +424,10 @@ export const COMMANDS = [
|
|
|
388
424
|
},
|
|
389
425
|
{
|
|
390
426
|
path: ['pano', 'save'],
|
|
391
|
-
summary: 'Create a Pano doc, or replace one; prints its id',
|
|
392
|
-
usage: 'agentrq-ws pano save [id] --title TEXT --markdown TEXT|@file|- [--file PATH]... [--ttl-days N] [--color NAME]',
|
|
427
|
+
summary: 'Create a Pano doc, or replace one; prints its id and version',
|
|
428
|
+
usage: 'agentrq-ws pano save [id --version N] --title TEXT --markdown TEXT|@file|- [--file PATH]... [--ttl-days N] [--color NAME]',
|
|
393
429
|
options: {
|
|
430
|
+
version: { type: 'string', short: 'v', description: 'The version you read; required with an id, refused if the doc changed since' },
|
|
394
431
|
title: { type: 'string', short: 'T', description: "The doc's title (required)" },
|
|
395
432
|
markdown: { type: 'string', short: 'M', description: "The doc's full markdown (@file or - for stdin; required)" },
|
|
396
433
|
file: { type: 'string', multiple: true, description: 'A linked file, linked from the markdown by its file name (repeatable)' },
|
|
@@ -410,8 +447,10 @@ export const COMMANDS = [
|
|
|
410
447
|
ttlDays = Number(ctx.values['ttl-days'])
|
|
411
448
|
if (!Number.isInteger(ttlDays) || ttlDays < 1) throw new UserError('--ttl-days must be a whole number, 1 or more')
|
|
412
449
|
}
|
|
450
|
+
const id = ctx.positionals[0]
|
|
413
451
|
return printPanoDoc(await pano(ctx, 'save', {
|
|
414
|
-
id
|
|
452
|
+
id,
|
|
453
|
+
version: id === undefined ? undefined : panoVersion(ctx.values.version),
|
|
415
454
|
title: ctx.values.title,
|
|
416
455
|
markdown,
|
|
417
456
|
ttlDays,
|
|
@@ -420,6 +459,23 @@ export const COMMANDS = [
|
|
|
420
459
|
}), { idOnly: true })
|
|
421
460
|
},
|
|
422
461
|
},
|
|
462
|
+
{
|
|
463
|
+
path: ['pano', 'edit'],
|
|
464
|
+
summary: 'Change part of a Pano doc without sending it whole; prints its id and new version',
|
|
465
|
+
usage: 'agentrq-ws pano edit <id> --version N [--ops JSON|@file|-] [--replace TEXT --with TEXT] [--append TEXT|@file|-]',
|
|
466
|
+
options: {
|
|
467
|
+
version: { type: 'string', short: 'v', description: 'The version you read (required); refused if the doc changed since' },
|
|
468
|
+
ops: { type: 'string', description: 'A JSON array of {op: "append", text} and {op: "replace", oldString, newString}' },
|
|
469
|
+
replace: { type: 'string', description: 'Text to replace; it must occur exactly once in the markdown' },
|
|
470
|
+
with: { type: 'string', description: 'What --replace becomes' },
|
|
471
|
+
append: { type: 'string', description: 'Text added at the end, as is (@file or - for stdin)' },
|
|
472
|
+
},
|
|
473
|
+
async run(ctx) {
|
|
474
|
+
const id = requirePositional(ctx.positionals, 0, 'id')
|
|
475
|
+
const version = panoVersion(ctx.values.version)
|
|
476
|
+
return printPanoDoc(await pano(ctx, 'edit', { id, version, ops: await panoEditOps(ctx) }), { idOnly: true })
|
|
477
|
+
},
|
|
478
|
+
},
|
|
423
479
|
{
|
|
424
480
|
path: ['pano', 'read'],
|
|
425
481
|
summary: 'Read a Pano doc, or download it with its files to a directory',
|