eversince 0.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.
@@ -0,0 +1,80 @@
1
+ import { mkdir, stat } from 'node:fs/promises';
2
+ import { createWriteStream } from 'node:fs';
3
+ import { pipeline } from 'node:stream/promises';
4
+ import { Readable } from 'node:stream';
5
+ import { basename, join, extname } from 'node:path';
6
+ import { Client } from '../client.js';
7
+ import { line, note, printResult } from '../output.js';
8
+ import { USER_AGENT } from '../version.js';
9
+ const EXTENSIONS = {
10
+ image: '.png',
11
+ video: '.mp4',
12
+ audio: '.mp3',
13
+ document: '.txt',
14
+ };
15
+ export function fileNameFor(item) {
16
+ const ref = basename(item.ref || item.item_id || 'item').replace(/[^\w.-]+/g, '-').replace(/^\.+/, '') || 'item';
17
+ let fromUrl = '';
18
+ try {
19
+ fromUrl = item.url ? extname(new URL(item.url).pathname) : '';
20
+ }
21
+ catch {
22
+ fromUrl = '';
23
+ }
24
+ const ext = /^\.[\w]{1,8}$/.test(fromUrl) ? fromUrl : EXTENSIONS[item.type ?? ''] || '';
25
+ const title = item.title?.replace(/[^\w.-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60);
26
+ return title ? `${ref}-${title}${ext}` : `${ref}${ext}`;
27
+ }
28
+ export async function download(argv, connection, mode) {
29
+ if (argv.refs.length === 0)
30
+ throw new Error('Which items? `eversince download ab12cd`');
31
+ const dir = argv.out ?? process.cwd();
32
+ await mkdir(dir, { recursive: true });
33
+ const client = await Client.create(connection);
34
+ const { items } = (await client.tool('get_items', { refs: argv.refs }));
35
+ const written = [];
36
+ const failed = [];
37
+ const found = new Set(items.flatMap((i) => [i.ref, i.item_id].filter(Boolean)));
38
+ for (const ref of argv.refs) {
39
+ if (!found.has(ref))
40
+ failed.push({ ref, error: 'No such item in this workspace' });
41
+ }
42
+ for (const item of items) {
43
+ const ref = item.ref || item.item_id || 'item';
44
+ if (!item.url) {
45
+ failed.push({ ref, error: 'Item has no file — it may still be generating' });
46
+ continue;
47
+ }
48
+ if (!mode.json)
49
+ note(`${ref} …`);
50
+ let res;
51
+ try {
52
+ res = await fetch(item.url, { headers: { 'user-agent': USER_AGENT } });
53
+ }
54
+ catch (error) {
55
+ failed.push({ ref, error: error instanceof Error ? error.message : String(error) });
56
+ continue;
57
+ }
58
+ if (!res.ok || !res.body) {
59
+ failed.push({ ref, error: res.status === 403 ? 'Link expired — run the command again' : `Could not fetch (${res.status})` });
60
+ continue;
61
+ }
62
+ const path = join(dir, fileNameFor(item));
63
+ try {
64
+ await pipeline(Readable.fromWeb(res.body), createWriteStream(path));
65
+ }
66
+ catch (error) {
67
+ failed.push({ ref, error: error instanceof Error ? error.message : String(error) });
68
+ continue;
69
+ }
70
+ written.push({ ref, path, bytes: (await stat(path)).size });
71
+ }
72
+ printResult(mode, { written, failed }, () => {
73
+ for (const w of written)
74
+ line(w.path);
75
+ for (const f of failed)
76
+ line(`failed ${f.ref} — ${f.error}`);
77
+ });
78
+ if (failed.length)
79
+ process.exitCode = 1;
80
+ }
@@ -0,0 +1,337 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile, writeFile, mkdir, copyFile, access, rename } from 'node:fs/promises';
3
+ import { join, dirname } from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ import { discoverAuthorizationServer } from '../auth/oauth.js';
6
+ import { Client } from '../client.js';
7
+ import { resolveBaseUrl, hostOf } from '../config.js';
8
+ import { line, note, printResult } from '../output.js';
9
+ import { cliLauncher, connectThroughApp, desktopInstalled, launchedFromTemporaryCopy, openApp } from '../local.js';
10
+ export const APP_AGENTS = ['claude-code', 'codex', 'cursor', 'vscode', 'claude-desktop', 'other'];
11
+ function checkAgent(given) {
12
+ if (given === undefined)
13
+ return undefined;
14
+ if (!APP_AGENTS.includes(given))
15
+ throw new Error(`--agent is one of ${APP_AGENTS.join(', ')}.`);
16
+ return given;
17
+ }
18
+ const GET_THE_APP = 'With the Eversince desktop app on this computer, the same work runs free. Get it at https://eversince.ai, then run eversince init again.';
19
+ const SERVER_KEY = 'eversince';
20
+ function vscodeUserDir() {
21
+ const home = homedir();
22
+ if (process.platform === 'darwin')
23
+ return join(home, 'Library', 'Application Support', 'Code', 'User');
24
+ if (process.platform === 'win32')
25
+ return join(process.env.APPDATA || join(home, 'AppData', 'Roaming'), 'Code', 'User');
26
+ return join(process.env.XDG_CONFIG_HOME || join(home, '.config'), 'Code', 'User');
27
+ }
28
+ function jsonTargets(scope, agent) {
29
+ const cwd = process.cwd();
30
+ const home = homedir();
31
+ const all = scope === 'project'
32
+ ? {
33
+ 'claude-code': { agent: 'Claude Code', path: join(cwd, '.mcp.json'), key: 'mcpServers' },
34
+ cursor: { agent: 'Cursor', path: join(cwd, '.cursor', 'mcp.json'), key: 'mcpServers' },
35
+ vscode: { agent: 'VS Code', path: join(cwd, '.vscode', 'mcp.json'), key: 'servers' },
36
+ }
37
+ : {
38
+ 'claude-code': { agent: 'Claude Code', path: join(home, '.claude.json'), key: 'mcpServers' },
39
+ cursor: { agent: 'Cursor', path: join(home, '.cursor', 'mcp.json'), key: 'mcpServers' },
40
+ vscode: { agent: 'VS Code', path: join(vscodeUserDir(), 'mcp.json'), key: 'servers' },
41
+ };
42
+ if (!agent)
43
+ return [all['claude-code'], all.cursor];
44
+ return agent === 'claude-code' || agent === 'cursor' || agent === 'vscode' ? [all[agent]] : [];
45
+ }
46
+ function manualFor(agent, mcpUrl) {
47
+ const codex = { agent: 'Codex', reason: `add to ~/.codex/config.toml:\n\n[mcp_servers.${SERVER_KEY}]\nurl = "${mcpUrl}"\n` };
48
+ if (!agent || agent === 'codex')
49
+ return [codex];
50
+ if (agent === 'claude-desktop') {
51
+ return [{ agent: 'Claude Desktop', reason: `add a custom connector in its settings, named Eversince, with the address ${mcpUrl}` }];
52
+ }
53
+ if (agent === 'other')
54
+ return [{ agent: 'Your agent', reason: `add an HTTP MCP server named ${SERVER_KEY} with the address ${mcpUrl}` }];
55
+ return [];
56
+ }
57
+ async function writeAtomic(path, text) {
58
+ await mkdir(dirname(path), { recursive: true });
59
+ const temp = `${path}.eversince-${process.pid}.tmp`;
60
+ await writeFile(temp, text);
61
+ await rename(temp, path);
62
+ }
63
+ function skillTargets(scope) {
64
+ const root = scope === 'project' ? process.cwd() : homedir();
65
+ return [{ agent: 'Claude Code', path: join(root, '.claude', 'skills', 'eversince-cli', 'SKILL.md') }];
66
+ }
67
+ function skillBody(mcpWhere) {
68
+ return `---
69
+ name: eversince-cli
70
+ description: Reach an Eversince workspace from the shell — upload local files into the library, download items onto disk, call any workspace tool, and follow generation and render to completion. Use whenever the media is on this machine, the same operation runs over many items, or the work has to continue without an agent session.
71
+ ---
72
+
73
+ # Eversince from the command line
74
+
75
+ A media workspace this account can reach two ways. Prefer whichever fits the step.
76
+
77
+ ## The CLI — local files, bulk work, no session needed
78
+
79
+ \`\`\`bash
80
+ eversince tools # everything this workspace can do, live
81
+ eversince tools <name> # one tool's input schema
82
+ eversince run <tool> '<json>' # call any tool; add --wait for async work
83
+ eversince upload <files|folder> # local files into the library
84
+ eversince download <refs> --out ./dir # library items onto disk
85
+ eversince jobs <id> --wait # follow generation, render
86
+ \`\`\`
87
+
88
+ Add \`--json\` for machine-readable output — \`{"ok":true,"data":…}\` on success,
89
+ \`{"ok":false,"error":…}\` on failure, so one field says which arrived.
90
+
91
+ ## MCP — inside the session
92
+
93
+ The same tools are available over MCP ${mcpWhere}. Use those when the work is
94
+ conversational and the files are already in the workspace; use the CLI when the
95
+ files are on this machine or the work has to outlive the session.
96
+
97
+ ## Worth knowing
98
+
99
+ - Every generation lands in the library on its own; nothing needs saving.
100
+ - Async tools return a job. \`--wait\` follows it; without it you get an id back.
101
+ - Downloaded filenames carry the item's short reference. Keep it in the name when
102
+ publishing, so results can be matched back to the item later.
103
+ - \`eversince tools <name>\` is authoritative for arguments. Read it rather than
104
+ guessing at a schema.
105
+ - \`--workspace <id>\` picks the workspace for one command and changes nothing
106
+ for anyone else, so several agents can run at once against different ones.
107
+ Left off, it is the workspace this connection was signed in to.
108
+ `;
109
+ }
110
+ async function exists(path) {
111
+ try {
112
+ await access(path);
113
+ return true;
114
+ }
115
+ catch {
116
+ return false;
117
+ }
118
+ }
119
+ async function backup(path) {
120
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
121
+ const target = `${path}.backup-${stamp}`;
122
+ await copyFile(path, target);
123
+ return target;
124
+ }
125
+ async function writeMcpEntry(target, mcpUrl, dryRun) {
126
+ const entry = { type: 'http', url: mcpUrl };
127
+ let current = {};
128
+ const had = await exists(target.path);
129
+ if (had) {
130
+ const raw = await readFile(target.path, 'utf8');
131
+ try {
132
+ current = raw.trim() ? JSON.parse(raw) : {};
133
+ }
134
+ catch {
135
+ throw new Error(`${target.path} is not valid JSON — fix or move it, then run init again.`);
136
+ }
137
+ }
138
+ const servers = { ...(current[target.key] ?? {}) };
139
+ const existing = servers[SERVER_KEY];
140
+ if (existing && typeof existing === 'object' && 'command' in existing) {
141
+ return { agent: target.agent, path: target.path, action: 'unchanged' };
142
+ }
143
+ const merged = existing && typeof existing === 'object'
144
+ ? { ...entry, ...existing }
145
+ : entry;
146
+ if (existing && JSON.stringify(existing) === JSON.stringify(merged)) {
147
+ return { agent: target.agent, path: target.path, action: 'unchanged' };
148
+ }
149
+ if (dryRun) {
150
+ return { agent: target.agent, path: target.path, action: had ? 'updated' : 'created' };
151
+ }
152
+ const saved = had ? await backup(target.path) : undefined;
153
+ servers[SERVER_KEY] = merged;
154
+ await writeAtomic(target.path, `${JSON.stringify({ ...current, [target.key]: servers }, null, 2)}\n`);
155
+ return { agent: target.agent, path: target.path, action: had ? 'updated' : 'created', backup: saved };
156
+ }
157
+ async function writeSkill(target, body, force, dryRun) {
158
+ if (await exists(target.path)) {
159
+ const current = await readFile(target.path, 'utf8');
160
+ if (current === body)
161
+ return { agent: target.agent, path: target.path, action: 'unchanged' };
162
+ if (!force) {
163
+ throw new Error(`${target.path} already exists and differs. Re-run with --force to replace it.`);
164
+ }
165
+ if (dryRun)
166
+ return { agent: target.agent, path: target.path, action: 'updated' };
167
+ const saved = await backup(target.path);
168
+ await writeFile(target.path, body);
169
+ return { agent: target.agent, path: target.path, action: 'updated', backup: saved };
170
+ }
171
+ if (dryRun)
172
+ return { agent: target.agent, path: target.path, action: 'created' };
173
+ await mkdir(dirname(target.path), { recursive: true });
174
+ await writeFile(target.path, body);
175
+ return { agent: target.agent, path: target.path, action: 'created' };
176
+ }
177
+ function agentsToConnect(given) {
178
+ if (given)
179
+ return [given];
180
+ if (process.env.CLAUDECODE)
181
+ return ['claude-code'];
182
+ if (Object.keys(process.env).some((key) => key.startsWith('CODEX_') && key !== 'CODEX_HOME'))
183
+ return ['codex'];
184
+ const home = homedir();
185
+ const found = [];
186
+ if (existsSync(join(home, '.claude.json')) || existsSync(join(home, '.claude')))
187
+ found.push('claude-code');
188
+ if (existsSync(join(home, '.codex')))
189
+ found.push('codex');
190
+ return found;
191
+ }
192
+ async function projectEntryShadows() {
193
+ const file = join(process.cwd(), '.mcp.json');
194
+ try {
195
+ const parsed = JSON.parse(await readFile(file, 'utf8'));
196
+ const entry = parsed.mcpServers?.[SERVER_KEY];
197
+ return entry && !entry.command ? file : null;
198
+ }
199
+ catch {
200
+ return null;
201
+ }
202
+ }
203
+ async function initThroughApp(argv, scope, mode) {
204
+ const agents = agentsToConnect(argv.agent);
205
+ if (agents.length === 0) {
206
+ throw new Error(`Name the agent to connect with --agent: ${APP_AGENTS.join(', ')}.`);
207
+ }
208
+ if (agents.some((a) => a !== 'claude-desktop') && launchedFromTemporaryCopy()) {
209
+ throw new Error('This CLI is a temporary copy. Install it with `npm install -g eversince`, then run `eversince init` again.');
210
+ }
211
+ const dryRun = argv.dryRun === true;
212
+ const connections = [];
213
+ if (!dryRun) {
214
+ await openApp(() => { if (!mode.json)
215
+ note('Opening the Eversince app on this computer.'); });
216
+ const cli = cliLauncher();
217
+ for (const agent of agents)
218
+ connections.push(await connectThroughApp(agent, { cli }));
219
+ }
220
+ const changes = [];
221
+ if (argv.skills !== false) {
222
+ const body = skillBody('through the Eversince desktop app on this computer');
223
+ for (const target of skillTargets(scope)) {
224
+ changes.push(await writeSkill(target, body, argv.force === true, dryRun));
225
+ }
226
+ }
227
+ const shadowed = agents.includes('claude-code') ? await projectEntryShadows() : null;
228
+ printResult(mode, {
229
+ venue: 'desktop',
230
+ dry_run: dryRun,
231
+ agents,
232
+ connections: connections.map(({ token: _token, ...rest }) => { void _token; return rest; }),
233
+ changes,
234
+ ...(shadowed ? { shadowed_by: shadowed } : {}),
235
+ }, () => {
236
+ if (dryRun) {
237
+ line(`Would connect ${agents.join(', ')} through the Eversince app on this computer.`);
238
+ }
239
+ for (const c of connections) {
240
+ line(`Connected ${c.label} through the Eversince app on this computer. Work it does there is free.`);
241
+ if (c.done)
242
+ note(` ${c.done}`);
243
+ if (c.agent === 'other' && c.command)
244
+ note(` Command: ${[c.command, ...(c.args ?? [])].map((a) => JSON.stringify(a)).join(' ')}`);
245
+ }
246
+ for (const change of changes) {
247
+ line(`${change.action.padEnd(10)}${change.path}`);
248
+ if (change.backup)
249
+ note(` previous copy: ${change.backup}`);
250
+ }
251
+ if (shadowed) {
252
+ note(`${shadowed} has its own eversince entry, which Claude Code uses in this folder instead. Remove it there to use the app.`);
253
+ }
254
+ if (dryRun)
255
+ line('Dry run. Nothing was written.');
256
+ });
257
+ }
258
+ export async function init(argv, connection, mode) {
259
+ if (argv.scope && argv.scope !== 'user' && argv.scope !== 'project') {
260
+ throw new Error('--scope is either project or user.');
261
+ }
262
+ const agent = checkAgent(argv.agent);
263
+ const scope = argv.scope === 'user' ? 'user' : 'project';
264
+ const doMcp = argv.mcp !== false;
265
+ const doSkills = argv.skills !== false;
266
+ const dryRun = argv.dryRun === true;
267
+ const cloudChosen = connection.cloud || connection.baseUrl || process.env.ES_BASE_URL?.trim();
268
+ const app = desktopInstalled();
269
+ if (doMcp && !cloudChosen && app.canConnect)
270
+ return initThroughApp({ ...argv, agent }, scope, mode);
271
+ if (doMcp && !cloudChosen && app.installed && !mode.json) {
272
+ note('The Eversince app on this computer is too old to connect agents. Update it and run eversince init again to work free through it.');
273
+ }
274
+ const baseUrl = await resolveBaseUrl(connection.baseUrl);
275
+ const { resource: mcpUrl } = await discoverAuthorizationServer(baseUrl);
276
+ const offerApp = !app.installed;
277
+ const changes = [];
278
+ const skipped = [];
279
+ if (doMcp) {
280
+ for (const target of jsonTargets(scope, agent)) {
281
+ changes.push(await writeMcpEntry(target, mcpUrl, dryRun));
282
+ }
283
+ skipped.push(...manualFor(agent, mcpUrl));
284
+ }
285
+ if (doSkills) {
286
+ const body = skillBody(`at ${mcpUrl}`);
287
+ for (const target of skillTargets(scope)) {
288
+ changes.push(await writeSkill(target, body, argv.force === true, dryRun));
289
+ }
290
+ }
291
+ if (!dryRun) {
292
+ const wrote = changes.filter((c) => c.action !== 'unchanged').map((c) => c.agent);
293
+ const named = agent
294
+ ? agent === 'claude-code' || agent === 'cursor' || agent === 'codex'
295
+ ? { agent }
296
+ : agent === 'vscode'
297
+ ? { name: 'VS Code' }
298
+ : agent === 'claude-desktop'
299
+ ? { name: 'Claude Desktop' }
300
+ : null
301
+ : wrote.includes('Claude Code')
302
+ ? { agent: 'claude-code' }
303
+ : wrote.includes('Cursor')
304
+ ? { agent: 'cursor' }
305
+ : skipped.some((item) => item.agent === 'Codex')
306
+ ? { agent: 'codex' }
307
+ : null;
308
+ if (named) {
309
+ try {
310
+ const client = await Client.create({ ...connection, baseUrl, cloud: true });
311
+ await client.post('/api/v1/connections/agent', named);
312
+ }
313
+ catch {
314
+ }
315
+ }
316
+ }
317
+ printResult(mode, { venue: 'cloud', scope, mcp_url: mcpUrl, dry_run: dryRun, changes, manual: skipped, ...(offerApp ? { desktop_app: GET_THE_APP } : {}) }, () => {
318
+ for (const change of changes) {
319
+ line(`${change.action.padEnd(10)}${change.path}`);
320
+ if (change.backup)
321
+ note(` previous copy: ${change.backup}`);
322
+ }
323
+ for (const item of skipped) {
324
+ line();
325
+ line(`${item.agent} — ${item.reason}`);
326
+ }
327
+ line();
328
+ if (dryRun) {
329
+ line('Dry run — nothing was written.');
330
+ return;
331
+ }
332
+ line(`Connected to ${hostOf(baseUrl)}. Restart any running agent to pick it up.`);
333
+ note('The agent authorises its own MCP connection; it does not use the CLI credential.');
334
+ if (offerApp)
335
+ line(GET_THE_APP);
336
+ });
337
+ }
@@ -0,0 +1,68 @@
1
+ import { Client } from '../client.js';
2
+ import { line, note, pad, printResult } from '../output.js';
3
+ const TERMINAL = new Set(['succeeded', 'failed', 'cancelled']);
4
+ const POLL_SECONDS = 45;
5
+ export async function waitForJobs(client, ids, opts) {
6
+ const deadline = Date.now() + opts.timeoutMs;
7
+ for (;;) {
8
+ const remaining = Math.max(0, deadline - Date.now());
9
+ const wait = Math.min(POLL_SECONDS, Math.floor(remaining / 1000));
10
+ const data = (await client.tool('get_jobs', { ids, wait_seconds: wait }, {
11
+ timeoutMs: (wait + 30) * 1000,
12
+ }));
13
+ opts.onTick?.(data.jobs);
14
+ if (data.jobs.length === 0)
15
+ return [];
16
+ if (data.jobs.every((j) => TERMINAL.has(j.status)))
17
+ return data.jobs;
18
+ if (Date.now() >= deadline)
19
+ return data.jobs;
20
+ }
21
+ }
22
+ function describe(job) {
23
+ const progress = typeof job.progress === 'number' ? ` ${Math.round(job.progress * 100)}%` : '';
24
+ return `${pad(job.id, 26)}${pad(job.kind ?? '', 12)}${job.status}${progress}${job.error ? ` — ${job.error}` : ''}`;
25
+ }
26
+ export async function jobs(argv, connection, mode) {
27
+ const client = await Client.create(connection);
28
+ if (argv.action === 'cancel') {
29
+ if (argv.ids.length === 0)
30
+ throw new Error('Which jobs? `eversince jobs cancel <id…>`');
31
+ const data = (await client.tool('cancel_jobs', { ids: argv.ids }));
32
+ printResult(mode, data, () => {
33
+ for (const job of data.jobs)
34
+ line(describe(job));
35
+ });
36
+ return;
37
+ }
38
+ if (argv.ids.length === 0)
39
+ throw new Error('Which jobs? `eversince jobs <id…>` or `eversince jobs cancel <id…>`');
40
+ if (!argv.wait) {
41
+ const data = (await client.tool('get_jobs', { ids: argv.ids }));
42
+ printResult(mode, data, () => {
43
+ for (const job of data.jobs)
44
+ line(describe(job));
45
+ });
46
+ return;
47
+ }
48
+ let lastLine = '';
49
+ const finished = await waitForJobs(client, argv.ids, {
50
+ timeoutMs: (argv.timeout ?? 1800) * 1000,
51
+ onTick: (current) => {
52
+ if (mode.json)
53
+ return;
54
+ const summary = current.map((j) => `${j.id.slice(0, 8)} ${j.status}`).join(' ');
55
+ if (summary !== lastLine) {
56
+ note(summary);
57
+ lastLine = summary;
58
+ }
59
+ },
60
+ });
61
+ const failed = finished.filter((j) => j.status === 'failed');
62
+ printResult(mode, { jobs: finished }, () => {
63
+ for (const job of finished)
64
+ line(describe(job));
65
+ });
66
+ if (failed.length)
67
+ process.exitCode = 1;
68
+ }
@@ -0,0 +1,71 @@
1
+ import { Client } from '../client.js';
2
+ import { waitForJobs } from './jobs.js';
3
+ import { printResult, line, note } from '../output.js';
4
+ async function readStdin() {
5
+ const chunks = [];
6
+ for await (const chunk of process.stdin)
7
+ chunks.push(Buffer.from(chunk));
8
+ return Buffer.concat(chunks).toString('utf8').trim();
9
+ }
10
+ export function jobIdsIn(result) {
11
+ if (!result || typeof result !== 'object')
12
+ return [];
13
+ const r = result;
14
+ const ids = [];
15
+ for (const key of ['job_id', 'jobId', 'item_id', 'id']) {
16
+ const value = r[key];
17
+ if (typeof value === 'string')
18
+ ids.push(value);
19
+ }
20
+ for (const key of ['jobs', 'items']) {
21
+ const value = r[key];
22
+ if (Array.isArray(value)) {
23
+ for (const entry of value)
24
+ ids.push(...jobIdsIn(entry));
25
+ }
26
+ }
27
+ return [...new Set(ids)];
28
+ }
29
+ export async function run(argv, connection, mode) {
30
+ if (!argv.name)
31
+ throw new Error('Which tool? `eversince run <tool> \'{"json":"args"}\'`');
32
+ const given = argv.input?.trim();
33
+ const raw = given === '-' ? await readStdin() : given;
34
+ let input = {};
35
+ if (raw) {
36
+ try {
37
+ input = JSON.parse(raw);
38
+ }
39
+ catch (cause) {
40
+ throw new Error(`Arguments must be JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
41
+ }
42
+ }
43
+ const client = await Client.create(connection);
44
+ const result = await client.tool(argv.name, input, { idempotencyKey: argv.idempotencyKey });
45
+ if (!argv.wait) {
46
+ printResult(mode, result, () => line(JSON.stringify(result, null, 2)));
47
+ return;
48
+ }
49
+ const ids = jobIdsIn(result);
50
+ const finished = ids.length
51
+ ? await waitForJobs(client, ids, {
52
+ timeoutMs: (argv.timeout ?? 1800) * 1000,
53
+ onTick: (jobs) => {
54
+ if (!mode.json)
55
+ note(jobs.map((j) => `${j.id.slice(0, 8)} ${j.status}`).join(' '));
56
+ },
57
+ })
58
+ : [];
59
+ if (finished.length === 0) {
60
+ if (!mode.json)
61
+ note('Nothing to wait for — this call returned its result directly.');
62
+ printResult(mode, result, () => line(JSON.stringify(result, null, 2)));
63
+ return;
64
+ }
65
+ const failed = finished.filter((j) => j.status === 'failed');
66
+ printResult(mode, { result, jobs: finished }, () => {
67
+ line(JSON.stringify({ result, jobs: finished }, null, 2));
68
+ });
69
+ if (failed.length)
70
+ process.exitCode = 1;
71
+ }
@@ -0,0 +1,36 @@
1
+ import { Client } from '../client.js';
2
+ import { line, pad, printResult } from '../output.js';
3
+ export async function tools(argv, connection, mode) {
4
+ const client = await Client.create(connection);
5
+ const wantSchemas = argv.schemas === true || Boolean(argv.name) || mode.json;
6
+ const data = (await client.get('/api/v1/tools', {
7
+ schemas: wantSchemas ? undefined : 'false',
8
+ annotation: argv.annotation,
9
+ }));
10
+ const list = argv.name ? data.tools.filter((t) => t.name === argv.name) : data.tools;
11
+ if (argv.name && list.length === 0) {
12
+ const near = data.tools.filter((t) => t.name.includes(argv.name)).slice(0, 5);
13
+ throw new Error(`No tool named "${argv.name}".${near.length ? ` Did you mean: ${near.map((t) => t.name).join(', ')}?` : ' Run `eversince tools` for the list.'}`);
14
+ }
15
+ printResult(mode, argv.name ? list[0] : { tools: list }, () => {
16
+ if (argv.name) {
17
+ const tool = list[0];
18
+ line(tool.name);
19
+ line(tool.description);
20
+ line();
21
+ line(`class: ${tool.annotation} cost: ${tool.cost} method: ${tool.method}`);
22
+ if (tool.input_schema) {
23
+ line();
24
+ line(JSON.stringify(tool.input_schema, null, 2));
25
+ }
26
+ line();
27
+ line(`eversince run ${tool.name} '{ … }'`);
28
+ return;
29
+ }
30
+ const width = Math.max(...list.map((t) => t.name.length)) + 2;
31
+ for (const tool of list)
32
+ line(`${pad(tool.name, width)}${tool.description}`);
33
+ line();
34
+ line(`${list.length} tools. \`eversince tools <name>\` for one in full.`);
35
+ });
36
+ }