@oneie/cli 5.1.0 → 5.2.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 +18 -0
- package/dist/package.json +1 -1
- package/dist/src/draw.d.ts +18 -0
- package/dist/src/draw.js +156 -0
- package/dist/src/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -192,6 +192,24 @@ JSON body, so the raw door is no worse than a wrapper:
|
|
|
192
192
|
one ask media:generate --data '{"prompt":"a red bicycle"}'
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
+
## Draw — ASCII diagrams, onto the board
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
one draw [name|path] # open lazydraw (the TUI) on a drawing
|
|
199
|
+
one draw list # saved drawings
|
|
200
|
+
one draw export <name> [--basic] [--fenced] [-o out.txt]
|
|
201
|
+
one draw attach <name> --task <tid> [--workspace S] # post it to the task's thread
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`one draw` runs [lazydraw](https://github.com/mpospirit/lazydraw) (MIT, Çağrı
|
|
205
|
+
Gökpunar). It is a Bun app, so it is spawned rather than bundled: `lazydraw` if
|
|
206
|
+
it is on your PATH, else `bun x lazydraw@0.1.1`. Without Bun you get one line
|
|
207
|
+
telling you how to install it. Everything except `attach` is passed straight
|
|
208
|
+
through. `attach` exports plain ASCII in a Markdown fence and posts it through
|
|
209
|
+
`tasks:comment`, so the sketch sits on the row it explains. A diagram over the
|
|
210
|
+
door's 4000-byte comment cap is **refused** with both numbers, never cut, and a
|
|
211
|
+
comment the door trimmed is reported as `truncated`.
|
|
212
|
+
|
|
195
213
|
## Chat — fan in · fan out
|
|
196
214
|
|
|
197
215
|
Send to a space, broadcast to all, or stream incoming messages:
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
|
|
3
|
+
export declare const LAZYDRAW_PKG = "lazydraw@0.1.1";
|
|
4
|
+
/** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
|
|
5
|
+
export declare const COMMENT_MAX_BYTES = 4000;
|
|
6
|
+
/** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
|
|
7
|
+
export declare function resolveRunner(has?: (bin: string) => boolean): string[] | null;
|
|
8
|
+
/** The comment body `attach` posts, or a refusal naming the budget that bit. */
|
|
9
|
+
export declare function attachBody(name: string, diagram: string): {
|
|
10
|
+
ok: true;
|
|
11
|
+
body: string;
|
|
12
|
+
bytes: number;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
error: string;
|
|
16
|
+
bytes: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function drawCmd(): Command;
|
package/dist/src/draw.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { accessSync, constants } from 'node:fs';
|
|
4
|
+
import { delimiter, join } from 'node:path';
|
|
5
|
+
import { authHeaders, resolveBase } from './lib/client.js';
|
|
6
|
+
import { askPath } from './lib/api-path.js';
|
|
7
|
+
// `one draw` — ASCII diagrams in the terminal, via lazydraw
|
|
8
|
+
// (github.com/mpospirit/lazydraw, MIT, © Çağrı Gökpunar).
|
|
9
|
+
//
|
|
10
|
+
// NOT A DEPENDENCY, on purpose. The CLI's runtime deps are exactly commander +
|
|
11
|
+
// @oneie/sdk, and lazydraw is a Bun TUI (its bin is `src/cli.ts`, Bun >= 1.3)
|
|
12
|
+
// while `one` runs on node. So we spawn it: `lazydraw` if it is on PATH, else
|
|
13
|
+
// `bun x lazydraw@<pinned>`. Without Bun there is no editor to open, and the
|
|
14
|
+
// command says so in one line instead of a stack trace.
|
|
15
|
+
//
|
|
16
|
+
// What earns a verb here:
|
|
17
|
+
// draw [args…] PASSTHROUGH — `one draw`, `one draw <name>`, `one draw list`,
|
|
18
|
+
// `one draw export <name> --basic --fenced -o f` are lazydraw's own.
|
|
19
|
+
// attach EARNS IT — exports a drawing and posts it to a task's thread
|
|
20
|
+
// through tasks:comment, so a sketch lands on the board row it
|
|
21
|
+
// explains. The door caps a comment at 4000 bytes; a bigger
|
|
22
|
+
// diagram is REFUSED here with both numbers, never cut mid-line.
|
|
23
|
+
/** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
|
|
24
|
+
export const LAZYDRAW_PKG = 'lazydraw@0.1.1';
|
|
25
|
+
/** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
|
|
26
|
+
export const COMMENT_MAX_BYTES = 4000;
|
|
27
|
+
const DEFAULT_API = 'https://api.one.ie';
|
|
28
|
+
function onPath(bin, path = process.env.PATH ?? '') {
|
|
29
|
+
for (const dir of path.split(delimiter)) {
|
|
30
|
+
if (!dir)
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
accessSync(join(dir, bin), constants.X_OK);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* next dir */
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
|
|
43
|
+
export function resolveRunner(has = (b) => onPath(b)) {
|
|
44
|
+
if (has('lazydraw'))
|
|
45
|
+
return ['lazydraw'];
|
|
46
|
+
if (has('bun'))
|
|
47
|
+
return ['bun', 'x', process.env.ONE_LAZYDRAW || LAZYDRAW_PKG];
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const NO_BUN = 'one draw needs Bun >= 1.3 (lazydraw is a Bun app): curl -fsSL https://bun.sh/install | bash — or `bun install -g lazydraw`';
|
|
51
|
+
/** The comment body `attach` posts, or a refusal naming the budget that bit. */
|
|
52
|
+
export function attachBody(name, diagram) {
|
|
53
|
+
const body = `Diagram \`${name}\` (one draw):\n\n${diagram.trim()}`;
|
|
54
|
+
const bytes = Buffer.byteLength(body, 'utf8');
|
|
55
|
+
if (!diagram.trim())
|
|
56
|
+
return { ok: false, error: `drawing "${name}" exported empty`, bytes };
|
|
57
|
+
if (bytes > COMMENT_MAX_BYTES) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
error: `drawing "${name}" is ${bytes} bytes as a comment; tasks:comment keeps ${COMMENT_MAX_BYTES} — not posted (crop it, or export -o and attach the file)`,
|
|
61
|
+
bytes,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { ok: true, body, bytes };
|
|
65
|
+
}
|
|
66
|
+
function fail(msg) {
|
|
67
|
+
process.stderr.write(`error ${msg}\n`);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
}
|
|
70
|
+
async function askComment(api, data) {
|
|
71
|
+
const res = await fetch(askPath(resolveBase({ api }, DEFAULT_API), 'tasks:comment'), {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: authHeaders(),
|
|
74
|
+
body: JSON.stringify({ data }),
|
|
75
|
+
});
|
|
76
|
+
const text = await res.text();
|
|
77
|
+
let o;
|
|
78
|
+
try {
|
|
79
|
+
o = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
|
|
83
|
+
}
|
|
84
|
+
if (o.outcome && o.outcome !== 'result') {
|
|
85
|
+
const inner = (o.result ?? {});
|
|
86
|
+
// ok:false LAST — an inner body's own `ok` must never overwrite a failed outcome.
|
|
87
|
+
return { ...inner, ok: false, error: inner.error ?? String(o.outcome) };
|
|
88
|
+
}
|
|
89
|
+
if (!res.ok)
|
|
90
|
+
throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
|
|
91
|
+
return (o.result ?? o) ?? {};
|
|
92
|
+
}
|
|
93
|
+
export function drawCmd() {
|
|
94
|
+
const cmd = new Command('draw')
|
|
95
|
+
.description('ASCII diagrams in the terminal (lazydraw) — `one draw [name]`, `list`, `export`, `attach`')
|
|
96
|
+
.argument('[args...]', 'passed to lazydraw: <name|path> · list · export <name> [--basic] [--comment s] [--fenced] [-o f] · --import f')
|
|
97
|
+
.allowUnknownOption()
|
|
98
|
+
.helpOption('-h, --help', 'show this help (lazydraw’s own: one draw -- --help)')
|
|
99
|
+
.action((args) => {
|
|
100
|
+
const runner = resolveRunner();
|
|
101
|
+
if (!runner)
|
|
102
|
+
return fail(NO_BUN);
|
|
103
|
+
const [bin, ...pre] = runner;
|
|
104
|
+
const r = spawnSync(bin, [...pre, ...args], { stdio: 'inherit' });
|
|
105
|
+
if (r.error)
|
|
106
|
+
return fail(`${bin}: ${r.error.message}`);
|
|
107
|
+
process.exitCode = r.status ?? 1;
|
|
108
|
+
});
|
|
109
|
+
cmd
|
|
110
|
+
.command('attach <name>')
|
|
111
|
+
.description('Export a drawing and post it to a task thread (tasks:comment); refuses over the 4000-byte comment cap')
|
|
112
|
+
.requiredOption('--task <tid>', 'Task id, e.g. task:01a0…')
|
|
113
|
+
.option('--workspace <slug>', 'Workspace the task lives in (one you control)')
|
|
114
|
+
.option('--extended', 'Box-drawing characters instead of plain ASCII (+ - |)')
|
|
115
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
116
|
+
.option('--json', 'Print the receipt as JSON')
|
|
117
|
+
.action(async (name, opts) => {
|
|
118
|
+
const runner = resolveRunner();
|
|
119
|
+
if (!runner)
|
|
120
|
+
return fail(NO_BUN);
|
|
121
|
+
const [bin, ...pre] = runner;
|
|
122
|
+
const exportArgs = ['export', name, '--fenced', ...(opts.extended ? [] : ['--basic'])];
|
|
123
|
+
const r = spawnSync(bin, [...pre, ...exportArgs], { encoding: 'utf8' });
|
|
124
|
+
if (r.error)
|
|
125
|
+
return fail(`${bin}: ${r.error.message}`);
|
|
126
|
+
if (r.status !== 0)
|
|
127
|
+
return fail((r.stderr || `lazydraw export exited ${r.status}`).trim());
|
|
128
|
+
const built = attachBody(name, r.stdout);
|
|
129
|
+
if (!built.ok)
|
|
130
|
+
return fail(built.error);
|
|
131
|
+
const res = await askComment(opts.api, {
|
|
132
|
+
tid: opts.task,
|
|
133
|
+
body: built.body,
|
|
134
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
135
|
+
});
|
|
136
|
+
// The door's own receipt decides "cut", never our byte count: it trims before
|
|
137
|
+
// it measures, so comparing against what we sent reads a newline as a loss.
|
|
138
|
+
const submitted = typeof res.submittedBytes === 'number' ? res.submittedBytes : undefined;
|
|
139
|
+
const stored = typeof res.storedBytes === 'number' ? res.storedBytes : undefined;
|
|
140
|
+
const cut = res.truncated === true || (submitted !== undefined && stored !== undefined && stored < submitted);
|
|
141
|
+
const json = opts.json || process.argv.includes('--json');
|
|
142
|
+
const failed = res.ok === false || typeof res.error === 'string';
|
|
143
|
+
const receipt = { ok: !failed && !cut, tid: opts.task, drawing: name, submittedBytes: submitted, storedBytes: stored, ...(cut ? { truncated: true } : {}), ...(res.error ? { error: res.error } : {}) };
|
|
144
|
+
if (json)
|
|
145
|
+
process.stdout.write(JSON.stringify(receipt, null, 2) + '\n');
|
|
146
|
+
if (failed) {
|
|
147
|
+
const landed = typeof res.durability === 'string' ? ` (${res.durability})` : '';
|
|
148
|
+
return fail(`tasks:comment refused: ${String(res.error)}${landed}${res.retryable ? ' — retryable, run it again' : ''}`);
|
|
149
|
+
}
|
|
150
|
+
if (cut)
|
|
151
|
+
return fail(`posted but CUT: ${submitted} bytes submitted, ${stored} stored`);
|
|
152
|
+
if (!json)
|
|
153
|
+
process.stdout.write(`✓ ${name} → ${opts.task} (${built.bytes} bytes)\n`);
|
|
154
|
+
});
|
|
155
|
+
return cmd;
|
|
156
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import { pluginCmd } from './plugin.js';
|
|
|
35
35
|
import { workflowCmd } from './workflow.js';
|
|
36
36
|
import { tasksCmd } from './tasks.js';
|
|
37
37
|
import { mediaCmd } from './media.js';
|
|
38
|
+
import { drawCmd } from './draw.js';
|
|
38
39
|
import { endpointCmd } from './endpoint.js';
|
|
39
40
|
import { shopCmd } from './shop.js';
|
|
40
41
|
import { readFileSync } from 'node:fs';
|
|
@@ -84,6 +85,7 @@ program.addCommand(pluginCmd());
|
|
|
84
85
|
program.addCommand(workflowCmd());
|
|
85
86
|
program.addCommand(tasksCmd());
|
|
86
87
|
program.addCommand(mediaCmd());
|
|
88
|
+
program.addCommand(drawCmd());
|
|
87
89
|
program.addCommand(endpointCmd());
|
|
88
90
|
program.addCommand(shopCmd());
|
|
89
91
|
// Bare `oneie` (no args, no --help/--version): route the audience to its
|