@rucher/cli 0.2.0-beta.6 → 0.2.0-beta.7
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/dist/cli.mjs +238 -104
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -3,7 +3,8 @@ import { defineCommand, runMain } from "citty";
|
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import tab from "@bomb.sh/tab/citty";
|
|
6
|
-
import { CarnetError, LEGEND, NOTES_HEADER, NOTE_KINDS, SIMILAR_PREFIX, SUBAGENT_RULES, WORKSPACE_FILE, addWorkspaceRepo,
|
|
6
|
+
import { AGENT_KINDS, CarnetError, GUARDED_TOOLS, KIND_ABBREVIATIONS, KIND_LEGEND, LEGEND, MAIN_HEADER, NOTES_HEADER, NOTE_KINDS, SIMILAR_PREFIX, SUBAGENT_RULES, WAITING_TOOL, WORKSPACE_FILE, addWorkspaceRepo, appendPromptFile, archiveWorkspaceSessions, claudeCode, createWorkspace, definitionInstructions, deleteWorkspaceNotes, dropWorkspace, formatClock, guardSubagentCall, handleSessionEnd, handleSessionStart, handleStop, handleToolStart, handleToolUse, handleUserPromptSubmit, hostById, isAgentKind, isWorkspaceName, listWorkspaces, loadWorkspace, memoryHalfLife, moveSession, openCarnet, openResolvedCarnet, openWorkspaceCarnet, removeWorkspaceRepo, renderRunDirectory, renderSections, repoNameFor, repoPathFor, requireWorkspace, resolveWorkspace, shortId, workspaceExists, workspaceLabel, workspaceLastActive, workspaceRepoNames, workspaceSessionCounts } from "@rucher/carnet";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
7
8
|
import { styleText } from "node:util";
|
|
8
9
|
import { spawnSync } from "node:child_process";
|
|
9
10
|
import { randomUUID } from "node:crypto";
|
|
@@ -78,6 +79,9 @@ function suggestRepoNames(context, complete) {
|
|
|
78
79
|
function suggestNoteKinds(complete) {
|
|
79
80
|
for (const kind of NOTE_KINDS) complete(kind, "");
|
|
80
81
|
}
|
|
82
|
+
function suggestAgentKinds(complete) {
|
|
83
|
+
for (const kind of AGENT_KINDS) complete(kind, "");
|
|
84
|
+
}
|
|
81
85
|
function suggestNotes(context, complete) {
|
|
82
86
|
quietly(() => {
|
|
83
87
|
const carnet = openCarnet(inWorkspace(context));
|
|
@@ -110,15 +114,18 @@ const repos = (complete) => suggestRepos(processContext(), complete);
|
|
|
110
114
|
const directories = (complete) => suggestDirectories(processContext(), complete);
|
|
111
115
|
const repoNames = (complete) => suggestRepoNames(processContext(), complete);
|
|
112
116
|
const noteKinds = (complete) => suggestNoteKinds(complete);
|
|
117
|
+
const agentKinds = (complete) => suggestAgentKinds(complete);
|
|
113
118
|
const notes = (complete) => suggestNotes(processContext(), complete);
|
|
114
119
|
const workspace = { ws: workspaces };
|
|
115
120
|
const completionConfig = { subCommands: {
|
|
116
121
|
status: { options: {
|
|
117
122
|
session: sessions,
|
|
123
|
+
kind: agentKinds,
|
|
118
124
|
...workspace
|
|
119
125
|
} },
|
|
120
126
|
log: { options: {
|
|
121
127
|
session: sessions,
|
|
128
|
+
kind: agentKinds,
|
|
122
129
|
...workspace
|
|
123
130
|
} },
|
|
124
131
|
new: { options: workspace },
|
|
@@ -239,25 +246,14 @@ async function setupCompletion(main) {
|
|
|
239
246
|
};
|
|
240
247
|
}
|
|
241
248
|
// package.json
|
|
242
|
-
var version = "0.2.0-beta.
|
|
249
|
+
var version = "0.2.0-beta.7";
|
|
243
250
|
// src/commands/hook.ts
|
|
244
251
|
const host = claudeCode;
|
|
245
|
-
function runHook(io, run
|
|
252
|
+
function runHook(io, run) {
|
|
246
253
|
try {
|
|
247
254
|
run();
|
|
248
255
|
} catch (error) {
|
|
249
256
|
if (error instanceof CarnetError && error.code === "NO_WORKSPACE") return 0;
|
|
250
|
-
if (error instanceof CarnetError && error.code === "WORKSPACE_AMBIGUOUS") {
|
|
251
|
-
if (hookEventName) {
|
|
252
|
-
io.stderr(`rucher: ${error.message}\n`);
|
|
253
|
-
const additionalContext = ambiguousWorkspaceContext(error.message);
|
|
254
|
-
io.stdout(`${JSON.stringify({ hookSpecificOutput: {
|
|
255
|
-
hookEventName,
|
|
256
|
-
additionalContext
|
|
257
|
-
} })}\n`);
|
|
258
|
-
}
|
|
259
|
-
return 0;
|
|
260
|
-
}
|
|
261
257
|
io.stderr(`rucher hook: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
262
258
|
}
|
|
263
259
|
return 0;
|
|
@@ -270,7 +266,7 @@ function withCarnet$1(payload, io, use) {
|
|
|
270
266
|
});
|
|
271
267
|
try {
|
|
272
268
|
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
273
|
-
if (!carnet.workspace && !
|
|
269
|
+
if (!carnet.workspace && !known) return;
|
|
274
270
|
use(carnet);
|
|
275
271
|
} finally {
|
|
276
272
|
carnet.close();
|
|
@@ -301,7 +297,7 @@ function sessionStart(stdinText, io) {
|
|
|
301
297
|
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
302
298
|
}
|
|
303
299
|
});
|
|
304
|
-
}
|
|
300
|
+
});
|
|
305
301
|
}
|
|
306
302
|
function subagentStart(stdinText, io) {
|
|
307
303
|
return runHook(io, () => {
|
|
@@ -331,12 +327,12 @@ function userPromptSubmit(stdinText, io) {
|
|
|
331
327
|
withCarnet$1(payload, io, (carnet) => {
|
|
332
328
|
handleUserPromptSubmit(carnet, host, payload);
|
|
333
329
|
});
|
|
334
|
-
}
|
|
330
|
+
});
|
|
335
331
|
}
|
|
336
332
|
function postToolUse(stdinText, io) {
|
|
337
333
|
return runHook(io, () => {
|
|
338
334
|
const payload = host.parseToolPayload(stdinText);
|
|
339
|
-
if (payload.agent_id
|
|
335
|
+
if (payload.agent_id) return;
|
|
340
336
|
withCarnet$1(payload, io, (carnet) => {
|
|
341
337
|
const additionalContext = handleToolUse(carnet, payload, {
|
|
342
338
|
RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
|
|
@@ -359,6 +355,36 @@ function sessionEnd(stdinText, io) {
|
|
|
359
355
|
});
|
|
360
356
|
});
|
|
361
357
|
}
|
|
358
|
+
function scratchRoot(io) {
|
|
359
|
+
const uid = process.getuid?.() ?? 0;
|
|
360
|
+
return join(io.env.CLAUDE_CODE_TMPDIR ?? tmpdir(), `claude-${uid}`);
|
|
361
|
+
}
|
|
362
|
+
function preToolUse(stdinText, io) {
|
|
363
|
+
return runHook(io, () => {
|
|
364
|
+
const payload = host.parseToolPayload(stdinText);
|
|
365
|
+
const guarded = Boolean(payload.agent_id) && GUARDED_TOOLS.has(payload.tool_name ?? "");
|
|
366
|
+
if (!guarded && (payload.agent_id || payload.tool_name !== WAITING_TOOL)) return;
|
|
367
|
+
withCarnet$1(payload, io, (carnet) => {
|
|
368
|
+
if (!guarded) return handleToolStart(carnet, payload);
|
|
369
|
+
const reason = guardSubagentCall(carnet, payload, scratchRoot(io));
|
|
370
|
+
if (!reason) return;
|
|
371
|
+
const hookSpecificOutput = {
|
|
372
|
+
hookEventName: "PreToolUse",
|
|
373
|
+
permissionDecision: "deny",
|
|
374
|
+
permissionDecisionReason: reason
|
|
375
|
+
};
|
|
376
|
+
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function stopHook(stdinText, io) {
|
|
381
|
+
return runHook(io, () => {
|
|
382
|
+
const payload = host.parseStopPayload(stdinText);
|
|
383
|
+
withCarnet$1(payload, io, (carnet) => {
|
|
384
|
+
handleStop(carnet, payload);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}
|
|
362
388
|
// src/color.ts
|
|
363
389
|
function paint(io) {
|
|
364
390
|
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
@@ -379,29 +405,37 @@ var CliError = class extends Error {
|
|
|
379
405
|
this.name = "CliError";
|
|
380
406
|
}
|
|
381
407
|
};
|
|
408
|
+
function withWorkspace(command, workspace) {
|
|
409
|
+
return workspace ? `${command} --ws ${workspace}` : command;
|
|
410
|
+
}
|
|
382
411
|
function findSession(carnet, reference) {
|
|
383
412
|
try {
|
|
384
413
|
return carnet.sessions.find(reference);
|
|
385
414
|
} catch (error) {
|
|
386
415
|
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
387
416
|
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
388
|
-
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` :
|
|
417
|
+
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` : `pass a session name, id or id prefix, see ${withWorkspace("rucher sessions --all", carnet.workspace?.name)}`);
|
|
389
418
|
}
|
|
390
419
|
}
|
|
391
420
|
function resolveSession(carnet, reference) {
|
|
392
421
|
if (reference) return findSession(carnet, reference);
|
|
393
422
|
const session = carnet.sessions.default();
|
|
394
|
-
if (!session) throw new CliError("No session in this workspace yet", "start
|
|
423
|
+
if (!session) throw new CliError("No session in this workspace yet", withWorkspace("start one with rucher new <name>", carnet.workspace?.name));
|
|
395
424
|
return session;
|
|
396
425
|
}
|
|
397
426
|
// src/commands/log.ts
|
|
398
|
-
function
|
|
427
|
+
function kindOf(event, kinds) {
|
|
428
|
+
return event.agent ? kinds.get(event.agent) : void 0;
|
|
429
|
+
}
|
|
430
|
+
function formatEvents(events, io, kinds = /* @__PURE__ */ new Map()) {
|
|
399
431
|
const colors = paint(io);
|
|
400
432
|
if (events.length === 0) return colors.dim("no events yet");
|
|
401
433
|
return events.map((event) => {
|
|
434
|
+
const kind = kindOf(event, kinds);
|
|
402
435
|
return [
|
|
403
436
|
colors.dim(formatClock(new Date(event.at))),
|
|
404
437
|
colors.bold(event.type.padEnd(9)),
|
|
438
|
+
kind ? KIND_ABBREVIATIONS[kind] : "",
|
|
405
439
|
event.agent ?? "",
|
|
406
440
|
event.link ?? event.note ?? "",
|
|
407
441
|
event.commit ? colors.cyan(event.commit.slice(0, 7)) : ""
|
|
@@ -413,8 +447,10 @@ function formatDay(date) {
|
|
|
413
447
|
const day = String(date.getDate()).padStart(2, "0");
|
|
414
448
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
415
449
|
}
|
|
416
|
-
function markdownEvent(event) {
|
|
450
|
+
function markdownEvent(event, kinds) {
|
|
417
451
|
const parts = [`${formatClock(new Date(event.at))} **${event.type}**`];
|
|
452
|
+
const kind = kindOf(event, kinds);
|
|
453
|
+
if (kind) parts.push(kind);
|
|
418
454
|
if (event.agent) parts.push(`\`${event.agent}\``);
|
|
419
455
|
const detail = [
|
|
420
456
|
event.note,
|
|
@@ -423,7 +459,7 @@ function markdownEvent(event) {
|
|
|
423
459
|
].filter(Boolean).join(" · ");
|
|
424
460
|
return `- ${parts.join(" ")}${detail ? `: ${detail}` : ""}`;
|
|
425
461
|
}
|
|
426
|
-
function formatEventsMarkdown(events, title) {
|
|
462
|
+
function formatEventsMarkdown(events, title, kinds = /* @__PURE__ */ new Map()) {
|
|
427
463
|
const lines = [`# Journal: ${title}`];
|
|
428
464
|
if (events.length === 0) return `${lines[0]}\n\nNo events yet.`;
|
|
429
465
|
let day = "";
|
|
@@ -433,7 +469,7 @@ function formatEventsMarkdown(events, title) {
|
|
|
433
469
|
day = current;
|
|
434
470
|
lines.push("", `## ${day}`, "");
|
|
435
471
|
}
|
|
436
|
-
lines.push(markdownEvent(event));
|
|
472
|
+
lines.push(markdownEvent(event, kinds));
|
|
437
473
|
}
|
|
438
474
|
return lines.join("\n");
|
|
439
475
|
}
|
|
@@ -442,43 +478,9 @@ function sessionTitle(carnet, session) {
|
|
|
442
478
|
}
|
|
443
479
|
function logOnce(carnet, io, options) {
|
|
444
480
|
const session = resolveSession(carnet, options.session);
|
|
445
|
-
const events = carnet.events.read(session.id, options.count, options.agents);
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
// src/workspace-option.ts
|
|
449
|
-
const workspaceArgument = { ws: {
|
|
450
|
-
type: "string",
|
|
451
|
-
description: "Workspace name (default: from RUCHER_WS, the run directory or the repo you are in)"
|
|
452
|
-
} };
|
|
453
|
-
function forwardWorkspace({ args }) {
|
|
454
|
-
if (args.ws) process.env.RUCHER_WS = args.ws;
|
|
455
|
-
}
|
|
456
|
-
function announceWorkspace(io, resolution) {
|
|
457
|
-
if (!resolution.workspace) return;
|
|
458
|
-
if (resolution.origin === "run-directory") io.stderr(`workspace ${resolution.workspace.name} (from its run directory)\n`);
|
|
459
|
-
else if (resolution.origin === "repo" && resolution.repo) io.stderr(`workspace ${resolution.workspace.name} (from ${resolution.repo.name})\n`);
|
|
460
|
-
}
|
|
461
|
-
function warnNoWorkspace(carnet, io) {
|
|
462
|
-
if (!carnet.workspace) io.stderr("no workspace here: pass --ws\n");
|
|
463
|
-
}
|
|
464
|
-
function openCliCarnet(io, workspace) {
|
|
465
|
-
const { carnet, resolution } = openResolvedCarnet({
|
|
466
|
-
cwd: io.cwd,
|
|
467
|
-
env: io.env,
|
|
468
|
-
workspace
|
|
469
|
-
});
|
|
470
|
-
announceWorkspace(io, resolution);
|
|
471
|
-
return carnet;
|
|
472
|
-
}
|
|
473
|
-
function currentWorkspace(io, workspace) {
|
|
474
|
-
const resolution = resolveWorkspace({
|
|
475
|
-
cwd: io.cwd,
|
|
476
|
-
env: io.env,
|
|
477
|
-
workspace
|
|
478
|
-
});
|
|
479
|
-
const found = requireWorkspace(resolution.workspace);
|
|
480
|
-
announceWorkspace(io, resolution);
|
|
481
|
-
return found;
|
|
481
|
+
const events = carnet.events.read(session.id, options.count, options.agents, options.kind);
|
|
482
|
+
const kinds = new Map(carnet.agents.list(session.id, { includeClosed: true }).map((agent) => [agent.name, agent.kind]));
|
|
483
|
+
io.stdout(`${options.md ? formatEventsMarkdown(events, sessionTitle(carnet, session), kinds) : formatEvents(events, io, kinds)}\n`);
|
|
482
484
|
}
|
|
483
485
|
// src/commands/notes.ts
|
|
484
486
|
const KIND_TITLES = {
|
|
@@ -543,9 +545,8 @@ function notesList(carnet, io, options = {}) {
|
|
|
543
545
|
return;
|
|
544
546
|
}
|
|
545
547
|
const colors = paint(io);
|
|
546
|
-
warnNoWorkspace(carnet, io);
|
|
547
548
|
if (notes.length === 0) {
|
|
548
|
-
|
|
549
|
+
io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
549
550
|
return;
|
|
550
551
|
}
|
|
551
552
|
const blocks = grouped(notes).map(([kind, kindNotes]) => `${colors.bold(KIND_TITLES[kind])}\n${kindNotes.map((note) => noteLine(io, note)).join("\n")}`);
|
|
@@ -626,29 +627,30 @@ function launchEnv(workspace, session, promptVersion, kind) {
|
|
|
626
627
|
};
|
|
627
628
|
}
|
|
628
629
|
function planNew(carnet, io, options) {
|
|
629
|
-
if (options.kind === "active" && !options.name) throw new CliError("An active session needs a name", "rucher new <name>");
|
|
630
|
+
if (options.kind === "active" && !options.name) throw new CliError("An active session needs a name", withWorkspace("rucher new <name>", carnet.workspace?.name));
|
|
631
|
+
const workspace = carnet.requireWorkspace();
|
|
630
632
|
const session = carnet.sessions.create({
|
|
631
633
|
id: randomUUID(),
|
|
632
634
|
kind: options.kind,
|
|
633
635
|
name: options.name,
|
|
634
|
-
cwd:
|
|
635
|
-
repo: repoNameFor(
|
|
636
|
+
cwd: workspace.runDirectory,
|
|
637
|
+
repo: repoNameFor(workspace, io.cwd)
|
|
636
638
|
});
|
|
637
639
|
const host = hostById(session.host);
|
|
638
|
-
|
|
640
|
+
renderRunDirectory(workspace, {
|
|
639
641
|
env: io.env,
|
|
640
642
|
host: session.host
|
|
641
643
|
});
|
|
642
|
-
const prompt = appendPromptFile(
|
|
644
|
+
const prompt = appendPromptFile(workspace, session, io.env);
|
|
643
645
|
return {
|
|
644
646
|
...host.launchCommand(session.id, {
|
|
645
647
|
name: session.name,
|
|
646
648
|
appendPromptFile: prompt.path,
|
|
647
|
-
directories: repoDirectories(
|
|
649
|
+
directories: repoDirectories(workspace),
|
|
648
650
|
passthrough: options.passthrough
|
|
649
651
|
}),
|
|
650
|
-
cwd:
|
|
651
|
-
env: launchEnv(
|
|
652
|
+
cwd: workspace.runDirectory,
|
|
653
|
+
env: launchEnv(workspace, session, prompt.version),
|
|
652
654
|
sessionId: session.id
|
|
653
655
|
};
|
|
654
656
|
}
|
|
@@ -656,7 +658,7 @@ function repoDirectories(workspace) {
|
|
|
656
658
|
return (workspace?.repos ?? []).map((repo) => repo.path).filter((path) => existsSync(path));
|
|
657
659
|
}
|
|
658
660
|
function sessionWorkspace(carnet, session, env) {
|
|
659
|
-
if (!
|
|
661
|
+
if (!isWorkspaceName(session.workspace)) return null;
|
|
660
662
|
return carnet.workspace?.name === session.workspace ? carnet.workspace : loadWorkspace(session.workspace, env);
|
|
661
663
|
}
|
|
662
664
|
function prepareSession(carnet, session, env) {
|
|
@@ -699,12 +701,12 @@ function planResume(carnet, io, reference, passthrough = []) {
|
|
|
699
701
|
};
|
|
700
702
|
}
|
|
701
703
|
function planFork(carnet, io, reference, options = {}) {
|
|
702
|
-
if (options.active && !options.name) throw new CliError("An active fork needs a name", "rucher fork <session> <name> --active");
|
|
704
|
+
if (options.active && !options.name) throw new CliError("An active fork needs a name", withWorkspace("rucher fork <session> <name> --active", carnet.workspace?.name));
|
|
703
705
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
704
706
|
const parent = findSession(carnet, reference);
|
|
705
707
|
if (!hostById(parent.host).hasConversation(parent, io.env)) {
|
|
706
708
|
const label = sessionLabel$1(parent);
|
|
707
|
-
throw new CliError(`Session ${label} has no conversation yet, nothing to fork`, `rucher resume ${label}
|
|
709
|
+
throw new CliError(`Session ${label} has no conversation yet, nothing to fork`, withWorkspace(`rucher resume ${label}`, parent.workspace));
|
|
708
710
|
}
|
|
709
711
|
const workspace = prepareSession(carnet, parent, io.env);
|
|
710
712
|
const cwd = sessionDirectory(parent);
|
|
@@ -765,25 +767,27 @@ function lastUse(at, now) {
|
|
|
765
767
|
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
766
768
|
}
|
|
767
769
|
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
768
|
-
|
|
770
|
+
return table(sessions.map((session, index) => [
|
|
769
771
|
String(index + 1),
|
|
770
772
|
session.name ?? shortId(session.id),
|
|
771
773
|
session.kind,
|
|
772
774
|
session.status,
|
|
773
775
|
lastUse(session.lastActiveAt, now),
|
|
774
776
|
shortId(session.id)
|
|
775
|
-
]);
|
|
777
|
+
]));
|
|
778
|
+
}
|
|
779
|
+
function table(rows) {
|
|
776
780
|
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
777
781
|
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
778
782
|
}
|
|
779
783
|
function hasFzf() {
|
|
780
784
|
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
781
785
|
}
|
|
782
|
-
function pickWithFzf(
|
|
786
|
+
function pickWithFzf(items, lines, label) {
|
|
783
787
|
const result = spawnSync("fzf", [
|
|
784
788
|
"--with-nth=2..",
|
|
785
789
|
"--no-sort",
|
|
786
|
-
|
|
790
|
+
`--prompt=${label}> `
|
|
787
791
|
], {
|
|
788
792
|
input: lines.join("\n"),
|
|
789
793
|
stdio: [
|
|
@@ -793,30 +797,55 @@ function pickWithFzf(sessions, lines) {
|
|
|
793
797
|
],
|
|
794
798
|
encoding: "utf8"
|
|
795
799
|
});
|
|
796
|
-
return
|
|
800
|
+
return items[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
797
801
|
}
|
|
798
|
-
async function pickFromList(
|
|
802
|
+
async function pickFromList(items, lines, label) {
|
|
799
803
|
process.stderr.write(`${lines.join("\n")}\n`);
|
|
800
804
|
const prompt = createInterface({
|
|
801
805
|
input: process.stdin,
|
|
802
806
|
output: process.stderr
|
|
803
807
|
});
|
|
804
808
|
try {
|
|
805
|
-
const answer = await prompt.question(
|
|
806
|
-
return
|
|
809
|
+
const answer = await prompt.question(`${label} number> `);
|
|
810
|
+
return items[Number(answer.trim()) - 1];
|
|
807
811
|
} finally {
|
|
808
812
|
prompt.close();
|
|
809
813
|
}
|
|
810
814
|
}
|
|
815
|
+
function pick(items, lines, label) {
|
|
816
|
+
return hasFzf() ? Promise.resolve(pickWithFzf(items, lines, label)) : pickFromList(items, lines, label);
|
|
817
|
+
}
|
|
811
818
|
async function pickSession(carnet) {
|
|
812
819
|
const sessions = pickerSessions(carnet);
|
|
813
|
-
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
const picked =
|
|
820
|
+
const workspace = carnet.workspace?.name;
|
|
821
|
+
if (sessions.length === 0) throw new CliError("No session to resume in this workspace", withWorkspace("rucher new <name>", workspace));
|
|
822
|
+
if (!process.stdin.isTTY) throw new CliError("No session given", withWorkspace("rucher resume <name, id or id prefix>", workspace));
|
|
823
|
+
const picked = await pick(sessions, pickerLines(sessions), "session");
|
|
817
824
|
if (!picked) throw new CliError("No session picked");
|
|
818
825
|
return picked;
|
|
819
826
|
}
|
|
827
|
+
function workspaceChoices(env) {
|
|
828
|
+
const carnet = openWorkspaceCarnet(null, { env });
|
|
829
|
+
try {
|
|
830
|
+
const lastActive = workspaceLastActive(carnet.db);
|
|
831
|
+
return listWorkspaces(env).map((workspace) => ({
|
|
832
|
+
name: workspace.name,
|
|
833
|
+
lastActiveAt: lastActive.get(workspace.name)
|
|
834
|
+
})).sort((a, b) => (b.lastActiveAt ?? "").localeCompare(a.lastActiveAt ?? "") || a.name.localeCompare(b.name));
|
|
835
|
+
} finally {
|
|
836
|
+
carnet.close();
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function workspaceLines(choices, now = /* @__PURE__ */ new Date()) {
|
|
840
|
+
return table(choices.map((choice, index) => [
|
|
841
|
+
String(index + 1),
|
|
842
|
+
choice.name,
|
|
843
|
+
choice.lastActiveAt ? lastUse(choice.lastActiveAt, now) : "never"
|
|
844
|
+
]));
|
|
845
|
+
}
|
|
846
|
+
async function pickWorkspace(choices) {
|
|
847
|
+
return (await pick(choices, workspaceLines(choices), "workspace"))?.name;
|
|
848
|
+
}
|
|
820
849
|
// src/commands/serve.ts
|
|
821
850
|
function serve(io) {
|
|
822
851
|
serveCarnet({
|
|
@@ -848,10 +877,9 @@ function sessionsOnce(carnet, io, options = {}) {
|
|
|
848
877
|
includeTemp: options.all,
|
|
849
878
|
includeArchived: options.all
|
|
850
879
|
});
|
|
851
|
-
warnNoWorkspace(carnet, io);
|
|
852
880
|
if (sessions.length === 0) {
|
|
853
881
|
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
854
|
-
|
|
882
|
+
io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
855
883
|
return;
|
|
856
884
|
}
|
|
857
885
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
@@ -1081,7 +1109,7 @@ function pressKey(state, key, noteCount) {
|
|
|
1081
1109
|
}
|
|
1082
1110
|
// src/commands/status.ts
|
|
1083
1111
|
const SECTION_HEADERS = /* @__PURE__ */ new Set([
|
|
1084
|
-
|
|
1112
|
+
MAIN_HEADER,
|
|
1085
1113
|
"Waiting on you",
|
|
1086
1114
|
"Running",
|
|
1087
1115
|
NOTES_HEADER
|
|
@@ -1095,7 +1123,8 @@ function colorizeLine(line, io) {
|
|
|
1095
1123
|
if (line === LEGEND) return colors.dim(line);
|
|
1096
1124
|
const cut = truncate(line, io.columns);
|
|
1097
1125
|
if (SECTION_HEADERS.has(line)) return colors.bold(cut);
|
|
1098
|
-
if (line.startsWith("
|
|
1126
|
+
if (line.startsWith(" ⚠")) return colors.red(cut);
|
|
1127
|
+
if (line.startsWith(" ⚙️") || line.startsWith(" ⏸")) return colors.yellow(cut);
|
|
1099
1128
|
if (line === " nothing") return colors.dim(cut);
|
|
1100
1129
|
if (cut.startsWith(`${NOTES_HEADER} `)) return `${colors.bold(NOTES_HEADER)}${cut.slice(NOTES_HEADER.length)}`;
|
|
1101
1130
|
const marker = /^ {2}\+ #\d+ +\S+ {2}(similar to [^·]*·)/.exec(cut);
|
|
@@ -1162,9 +1191,9 @@ function hasSomethingToShow(carnet, session) {
|
|
|
1162
1191
|
function sessionBlock(session, view, io) {
|
|
1163
1192
|
return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
|
|
1164
1193
|
}
|
|
1165
|
-
function singleView(carnet, session, io, state) {
|
|
1194
|
+
function singleView(carnet, session, io, kind, state) {
|
|
1166
1195
|
const colors = paint(io);
|
|
1167
|
-
const view = carnet.status.view(session);
|
|
1196
|
+
const view = carnet.status.view(session, { kind });
|
|
1168
1197
|
const separator = " - ";
|
|
1169
1198
|
const label = sessionLabel(carnet, session, io.columns - view.time.length - 3);
|
|
1170
1199
|
const title = `${colors.dim(view.time)}${separator}${colors.cyan(label)}`;
|
|
@@ -1176,15 +1205,16 @@ function singleView(carnet, session, io, state) {
|
|
|
1176
1205
|
...body,
|
|
1177
1206
|
"",
|
|
1178
1207
|
...footer ? [footer] : [],
|
|
1208
|
+
colors.dim(truncate(KIND_LEGEND, io.columns)),
|
|
1179
1209
|
colors.dim(LEGEND)
|
|
1180
1210
|
].join("\n");
|
|
1181
1211
|
}
|
|
1182
1212
|
function renderStatusView(carnet, io, options) {
|
|
1183
1213
|
const sessions = options.all ? carnet.sessions.list({ includeTemp: true }).filter((session) => hasSomethingToShow(carnet, session)) : [];
|
|
1184
|
-
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.interaction);
|
|
1214
|
+
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.kind, options.interaction);
|
|
1185
1215
|
let time = "";
|
|
1186
1216
|
const blocks = sessions.map((session) => {
|
|
1187
|
-
const view = carnet.status.view(session);
|
|
1217
|
+
const view = carnet.status.view(session, { kind: options.kind });
|
|
1188
1218
|
time ||= view.time;
|
|
1189
1219
|
return sessionBlock(session, view, io);
|
|
1190
1220
|
});
|
|
@@ -1196,6 +1226,7 @@ function renderStatusView(carnet, io, options) {
|
|
|
1196
1226
|
"",
|
|
1197
1227
|
blocks.join("\n\n"),
|
|
1198
1228
|
"",
|
|
1229
|
+
colors.dim(truncate(KIND_LEGEND, io.columns)),
|
|
1199
1230
|
colors.dim(LEGEND)
|
|
1200
1231
|
].join("\n");
|
|
1201
1232
|
}
|
|
@@ -1272,6 +1303,53 @@ function statusWatch(carnet, io, options) {
|
|
|
1272
1303
|
repaint();
|
|
1273
1304
|
});
|
|
1274
1305
|
}
|
|
1306
|
+
// src/workspace-option.ts
|
|
1307
|
+
const workspaceArgument = { ws: {
|
|
1308
|
+
type: "string",
|
|
1309
|
+
description: "Workspace name (default: from RUCHER_WS or the run directory, else asked)"
|
|
1310
|
+
} };
|
|
1311
|
+
function forwardWorkspace({ args }) {
|
|
1312
|
+
if (args.ws) process.env.RUCHER_WS = args.ws;
|
|
1313
|
+
}
|
|
1314
|
+
async function chooseWorkspace(io, workspace, { interactive = process.stdin.isTTY === true && process.stderr.isTTY === true, choose = pickWorkspace } = {}) {
|
|
1315
|
+
if (workspace || !interactive) return;
|
|
1316
|
+
if (resolveWorkspace({
|
|
1317
|
+
cwd: io.cwd,
|
|
1318
|
+
env: io.env
|
|
1319
|
+
}).workspace) return;
|
|
1320
|
+
const choices = workspaceChoices(io.env);
|
|
1321
|
+
if (choices.length === 0) return;
|
|
1322
|
+
const chosen = await choose(choices);
|
|
1323
|
+
if (chosen) io.env.RUCHER_WS = chosen;
|
|
1324
|
+
}
|
|
1325
|
+
function announceWorkspace(io, resolution) {
|
|
1326
|
+
if (resolution.workspace && resolution.origin === "run-directory") io.stderr(`workspace ${resolution.workspace.name} (from its run directory)\n`);
|
|
1327
|
+
}
|
|
1328
|
+
function openCliCarnet(io, workspace) {
|
|
1329
|
+
const { carnet, resolution } = openResolvedCarnet({
|
|
1330
|
+
cwd: io.cwd,
|
|
1331
|
+
env: io.env,
|
|
1332
|
+
workspace
|
|
1333
|
+
});
|
|
1334
|
+
try {
|
|
1335
|
+
requireWorkspace(resolution.workspace);
|
|
1336
|
+
} catch (error) {
|
|
1337
|
+
carnet.close();
|
|
1338
|
+
throw error;
|
|
1339
|
+
}
|
|
1340
|
+
announceWorkspace(io, resolution);
|
|
1341
|
+
return carnet;
|
|
1342
|
+
}
|
|
1343
|
+
function currentWorkspace(io, workspace) {
|
|
1344
|
+
const resolution = resolveWorkspace({
|
|
1345
|
+
cwd: io.cwd,
|
|
1346
|
+
env: io.env,
|
|
1347
|
+
workspace
|
|
1348
|
+
});
|
|
1349
|
+
const found = requireWorkspace(resolution.workspace);
|
|
1350
|
+
announceWorkspace(io, resolution);
|
|
1351
|
+
return found;
|
|
1352
|
+
}
|
|
1275
1353
|
// src/commands/ws.ts
|
|
1276
1354
|
function carnetErrors(io, run) {
|
|
1277
1355
|
try {
|
|
@@ -1523,6 +1601,22 @@ function fail(io, error) {
|
|
|
1523
1601
|
else io.stderr(`error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1524
1602
|
process.exit(1);
|
|
1525
1603
|
}
|
|
1604
|
+
async function askWorkspace({ args }) {
|
|
1605
|
+
const io = processIo();
|
|
1606
|
+
try {
|
|
1607
|
+
await chooseWorkspace(io, args.ws);
|
|
1608
|
+
} catch (error) {
|
|
1609
|
+
fail(io, error);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
const kindArgument = { kind: {
|
|
1613
|
+
type: "string",
|
|
1614
|
+
description: AGENT_KINDS.join(", ")
|
|
1615
|
+
} };
|
|
1616
|
+
function agentKind(value) {
|
|
1617
|
+
if (value === void 0 || isAgentKind(value)) return value;
|
|
1618
|
+
throw new CliError(`Unknown agent kind ${value}`, `use one of ${AGENT_KINDS.join(", ")}`);
|
|
1619
|
+
}
|
|
1526
1620
|
const colorArgument = { color: {
|
|
1527
1621
|
type: "boolean",
|
|
1528
1622
|
default: true,
|
|
@@ -1556,16 +1650,19 @@ const statusCommand = defineCommand({
|
|
|
1556
1650
|
default: "1",
|
|
1557
1651
|
description: "Refresh interval in seconds with --watch"
|
|
1558
1652
|
},
|
|
1653
|
+
...kindArgument,
|
|
1559
1654
|
...workspaceArgument,
|
|
1560
1655
|
...colorArgument
|
|
1561
1656
|
},
|
|
1657
|
+
setup: askWorkspace,
|
|
1562
1658
|
async run({ args }) {
|
|
1563
1659
|
const io = processIo({ color: args.color });
|
|
1564
1660
|
try {
|
|
1565
1661
|
const carnet = openCliCarnet(io, args.ws);
|
|
1566
1662
|
const options = {
|
|
1567
1663
|
session: args.session,
|
|
1568
|
-
all: args.all
|
|
1664
|
+
all: args.all,
|
|
1665
|
+
kind: agentKind(args.kind)
|
|
1569
1666
|
};
|
|
1570
1667
|
if (!args.watch) {
|
|
1571
1668
|
statusOnce(carnet, io, options);
|
|
@@ -1609,9 +1706,11 @@ const logCommand = defineCommand({
|
|
|
1609
1706
|
default: false,
|
|
1610
1707
|
description: "Agent events only, without session starts and ends"
|
|
1611
1708
|
},
|
|
1709
|
+
...kindArgument,
|
|
1612
1710
|
...workspaceArgument,
|
|
1613
1711
|
...colorArgument
|
|
1614
1712
|
},
|
|
1713
|
+
setup: askWorkspace,
|
|
1615
1714
|
run({ args }) {
|
|
1616
1715
|
const io = processIo({ color: args.color });
|
|
1617
1716
|
try {
|
|
@@ -1619,7 +1718,8 @@ const logCommand = defineCommand({
|
|
|
1619
1718
|
session: args.session,
|
|
1620
1719
|
count: Number(args.count) || 20,
|
|
1621
1720
|
md: args.md,
|
|
1622
|
-
agents: args.agents
|
|
1721
|
+
agents: args.agents,
|
|
1722
|
+
kind: agentKind(args.kind)
|
|
1623
1723
|
});
|
|
1624
1724
|
} catch (error) {
|
|
1625
1725
|
fail(io, error);
|
|
@@ -1640,6 +1740,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1640
1740
|
...workspaceArgument,
|
|
1641
1741
|
...colorArgument
|
|
1642
1742
|
},
|
|
1743
|
+
setup: askWorkspace,
|
|
1643
1744
|
run({ args }) {
|
|
1644
1745
|
const io = processIo({ color: args.color });
|
|
1645
1746
|
try {
|
|
@@ -1667,6 +1768,7 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1667
1768
|
},
|
|
1668
1769
|
...workspaceArgument
|
|
1669
1770
|
},
|
|
1771
|
+
setup: askWorkspace,
|
|
1670
1772
|
run({ args }) {
|
|
1671
1773
|
const io = processIo();
|
|
1672
1774
|
try {
|
|
@@ -1697,6 +1799,7 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1697
1799
|
},
|
|
1698
1800
|
...workspaceArgument
|
|
1699
1801
|
},
|
|
1802
|
+
setup: askWorkspace,
|
|
1700
1803
|
run({ args }) {
|
|
1701
1804
|
const io = processIo();
|
|
1702
1805
|
withCarnet(io, args.ws, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
@@ -1716,6 +1819,7 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1716
1819
|
},
|
|
1717
1820
|
...workspaceArgument
|
|
1718
1821
|
},
|
|
1822
|
+
setup: askWorkspace,
|
|
1719
1823
|
run({ args }) {
|
|
1720
1824
|
const io = processIo();
|
|
1721
1825
|
withCarnet(io, args.ws, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
@@ -1730,6 +1834,7 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1730
1834
|
session: sessionReference,
|
|
1731
1835
|
...workspaceArgument
|
|
1732
1836
|
},
|
|
1837
|
+
setup: askWorkspace,
|
|
1733
1838
|
run({ args }) {
|
|
1734
1839
|
const io = processIo();
|
|
1735
1840
|
withCarnet(io, args.ws, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
@@ -1750,6 +1855,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1750
1855
|
...purgeArgument,
|
|
1751
1856
|
...workspaceArgument
|
|
1752
1857
|
},
|
|
1858
|
+
setup: askWorkspace,
|
|
1753
1859
|
run({ args }) {
|
|
1754
1860
|
const io = processIo();
|
|
1755
1861
|
withCarnet(io, args.ws, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
@@ -1779,6 +1885,7 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1779
1885
|
},
|
|
1780
1886
|
...workspaceArgument
|
|
1781
1887
|
},
|
|
1888
|
+
setup: askWorkspace,
|
|
1782
1889
|
run({ args }) {
|
|
1783
1890
|
const io = processIo();
|
|
1784
1891
|
withCarnet(io, args.ws, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
@@ -1806,6 +1913,7 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1806
1913
|
},
|
|
1807
1914
|
...workspaceArgument
|
|
1808
1915
|
},
|
|
1916
|
+
setup: askWorkspace,
|
|
1809
1917
|
run({ args }) {
|
|
1810
1918
|
const io = processIo();
|
|
1811
1919
|
withCarnet(io, args.ws, (carnet) => sessionsClean(carnet, io, {
|
|
@@ -1886,6 +1994,7 @@ const notesListCommand = defineCommand({
|
|
|
1886
1994
|
...workspaceArgument,
|
|
1887
1995
|
...colorArgument
|
|
1888
1996
|
},
|
|
1997
|
+
setup: askWorkspace,
|
|
1889
1998
|
run({ args }) {
|
|
1890
1999
|
const io = processIo({ color: args.color });
|
|
1891
2000
|
withCarnet(io, args.ws, (carnet) => notesList(carnet, io, {
|
|
@@ -1912,6 +2021,7 @@ const notesShowCommand = defineCommand({
|
|
|
1912
2021
|
...workspaceArgument,
|
|
1913
2022
|
...colorArgument
|
|
1914
2023
|
},
|
|
2024
|
+
setup: askWorkspace,
|
|
1915
2025
|
run({ args }) {
|
|
1916
2026
|
const io = processIo({ color: args.color });
|
|
1917
2027
|
withCarnet(io, args.ws, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
@@ -1940,6 +2050,7 @@ const notesAddCommand = defineCommand({
|
|
|
1940
2050
|
...workspaceArgument,
|
|
1941
2051
|
...colorArgument
|
|
1942
2052
|
},
|
|
2053
|
+
setup: askWorkspace,
|
|
1943
2054
|
run({ args, rawArgs }) {
|
|
1944
2055
|
const io = processIo({ color: args.color });
|
|
1945
2056
|
withCarnet(io, args.ws, (carnet) => notesAdd(carnet, io, {
|
|
@@ -1971,6 +2082,7 @@ const notesDropCommand = defineCommand({
|
|
|
1971
2082
|
},
|
|
1972
2083
|
...workspaceArgument
|
|
1973
2084
|
},
|
|
2085
|
+
setup: askWorkspace,
|
|
1974
2086
|
run({ args }) {
|
|
1975
2087
|
const io = processIo();
|
|
1976
2088
|
const replacement = args["replaced-by"];
|
|
@@ -2036,6 +2148,7 @@ const newCommand = defineCommand({
|
|
|
2036
2148
|
},
|
|
2037
2149
|
...workspaceArgument
|
|
2038
2150
|
},
|
|
2151
|
+
setup: askWorkspace,
|
|
2039
2152
|
async run({ args, rawArgs }) {
|
|
2040
2153
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2041
2154
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2058,6 +2171,7 @@ const tmpCommand = defineCommand({
|
|
|
2058
2171
|
},
|
|
2059
2172
|
...workspaceArgument
|
|
2060
2173
|
},
|
|
2174
|
+
setup: askWorkspace,
|
|
2061
2175
|
async run({ args, rawArgs }) {
|
|
2062
2176
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2063
2177
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2080,6 +2194,7 @@ const resumeCommand = defineCommand({
|
|
|
2080
2194
|
},
|
|
2081
2195
|
...workspaceArgument
|
|
2082
2196
|
},
|
|
2197
|
+
setup: askWorkspace,
|
|
2083
2198
|
async run({ args, rawArgs }) {
|
|
2084
2199
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2085
2200
|
const io = processIo();
|
|
@@ -2112,6 +2227,7 @@ const forkCommand = defineCommand({
|
|
|
2112
2227
|
},
|
|
2113
2228
|
...workspaceArgument
|
|
2114
2229
|
},
|
|
2230
|
+
setup: askWorkspace,
|
|
2115
2231
|
async run({ args, rawArgs }) {
|
|
2116
2232
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2117
2233
|
const [reference, name] = positionals(withoutWorkspaceOption(own));
|
|
@@ -2210,6 +2326,7 @@ const wsCommand = defineCommand({
|
|
|
2210
2326
|
...workspaceArgument,
|
|
2211
2327
|
...colorArgument
|
|
2212
2328
|
},
|
|
2329
|
+
setup: askWorkspace,
|
|
2213
2330
|
run({ args }) {
|
|
2214
2331
|
process.exitCode = workspaceShow(processIo({ color: args.color }), { workspace: args.ws });
|
|
2215
2332
|
}
|
|
@@ -2228,6 +2345,7 @@ const wsCommand = defineCommand({
|
|
|
2228
2345
|
...workspaceArgument,
|
|
2229
2346
|
...colorArgument
|
|
2230
2347
|
},
|
|
2348
|
+
setup: askWorkspace,
|
|
2231
2349
|
run({ args }) {
|
|
2232
2350
|
process.exitCode = workspaceAdd(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2233
2351
|
}
|
|
@@ -2246,6 +2364,7 @@ const wsCommand = defineCommand({
|
|
|
2246
2364
|
...workspaceArgument,
|
|
2247
2365
|
...colorArgument
|
|
2248
2366
|
},
|
|
2367
|
+
setup: askWorkspace,
|
|
2249
2368
|
run({ args }) {
|
|
2250
2369
|
process.exitCode = workspaceRemove(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2251
2370
|
}
|
|
@@ -2259,6 +2378,7 @@ const wsCommand = defineCommand({
|
|
|
2259
2378
|
...workspaceArgument,
|
|
2260
2379
|
...colorArgument
|
|
2261
2380
|
},
|
|
2381
|
+
setup: askWorkspace,
|
|
2262
2382
|
run({ args }) {
|
|
2263
2383
|
process.exitCode = workspaceSync(processIo({ color: args.color }), { workspace: args.ws });
|
|
2264
2384
|
}
|
|
@@ -2276,6 +2396,7 @@ const wsCommand = defineCommand({
|
|
|
2276
2396
|
},
|
|
2277
2397
|
...workspaceArgument
|
|
2278
2398
|
},
|
|
2399
|
+
setup: askWorkspace,
|
|
2279
2400
|
async run({ args }) {
|
|
2280
2401
|
process.exitCode = await workspaceEdit(processIo(), {
|
|
2281
2402
|
workspace: args.ws,
|
|
@@ -2302,6 +2423,7 @@ const wsCommand = defineCommand({
|
|
|
2302
2423
|
},
|
|
2303
2424
|
...workspaceArgument
|
|
2304
2425
|
},
|
|
2426
|
+
setup: askWorkspace,
|
|
2305
2427
|
run({ args }) {
|
|
2306
2428
|
process.exitCode = workspacePath(processIo(), {
|
|
2307
2429
|
workspace: args.ws,
|
|
@@ -2335,10 +2457,28 @@ const hookCommand = defineCommand({
|
|
|
2335
2457
|
process.exitCode = sessionEnd(await readStdin(), processIo());
|
|
2336
2458
|
}
|
|
2337
2459
|
}),
|
|
2460
|
+
"pre-tool-use": defineCommand({
|
|
2461
|
+
meta: {
|
|
2462
|
+
name: "pre-tool-use",
|
|
2463
|
+
description: "PreToolUse hook: marks the main turn as waiting on the human"
|
|
2464
|
+
},
|
|
2465
|
+
async run() {
|
|
2466
|
+
process.exitCode = preToolUse(await readStdin(), processIo());
|
|
2467
|
+
}
|
|
2468
|
+
}),
|
|
2469
|
+
stop: defineCommand({
|
|
2470
|
+
meta: {
|
|
2471
|
+
name: "stop",
|
|
2472
|
+
description: "Stop hook: ends the main agent's turn"
|
|
2473
|
+
},
|
|
2474
|
+
async run() {
|
|
2475
|
+
process.exitCode = stopHook(await readStdin(), processIo());
|
|
2476
|
+
}
|
|
2477
|
+
}),
|
|
2338
2478
|
"post-tool-use": defineCommand({
|
|
2339
2479
|
meta: {
|
|
2340
2480
|
name: "post-tool-use",
|
|
2341
|
-
description: "PostToolUse hook: adds a repo's notes the first time a tool touches it"
|
|
2481
|
+
description: "PostToolUse hook: marks the main turn working, adds a repo's notes the first time a tool touches it"
|
|
2342
2482
|
},
|
|
2343
2483
|
async run() {
|
|
2344
2484
|
process.exitCode = postToolUse(await readStdin(), processIo());
|
|
@@ -2347,7 +2487,7 @@ const hookCommand = defineCommand({
|
|
|
2347
2487
|
"user-prompt-submit": defineCommand({
|
|
2348
2488
|
meta: {
|
|
2349
2489
|
name: "user-prompt-submit",
|
|
2350
|
-
description: "UserPromptSubmit hook: names the session after a /rename"
|
|
2490
|
+
description: "UserPromptSubmit hook: starts the main turn, names the session after a /rename"
|
|
2351
2491
|
},
|
|
2352
2492
|
async run() {
|
|
2353
2493
|
process.exitCode = userPromptSubmit(await readStdin(), processIo());
|
|
@@ -2382,18 +2522,12 @@ const serveCommand = defineCommand({
|
|
|
2382
2522
|
serve(processIo());
|
|
2383
2523
|
}
|
|
2384
2524
|
});
|
|
2385
|
-
function refuseRemovedOption(rawArgs) {
|
|
2386
|
-
const removed = /^(-g|--group)(=|$)/;
|
|
2387
|
-
const option = splitPassthrough([...rawArgs]).own.find((argument) => removed.test(argument));
|
|
2388
|
-
if (option) fail(processIo(), new CliError(`Unknown option ${option}`, "use --ws <name>"));
|
|
2389
|
-
}
|
|
2390
2525
|
const main = defineCommand({
|
|
2391
2526
|
meta: {
|
|
2392
2527
|
name: "rucher",
|
|
2393
2528
|
version,
|
|
2394
2529
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2395
2530
|
},
|
|
2396
|
-
setup: ({ rawArgs }) => refuseRemovedOption(rawArgs),
|
|
2397
2531
|
subCommands: {
|
|
2398
2532
|
status: statusCommand,
|
|
2399
2533
|
log: logCommand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rucher/cli",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.7",
|
|
4
4
|
"description": "rucher: status, journal and sessions of your Claude Code sub-agents, from the terminal",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@bomb.sh/tab": "0.0.22",
|
|
38
|
-
"@rucher/carnet": "0.2.0-beta.
|
|
38
|
+
"@rucher/carnet": "0.2.0-beta.7",
|
|
39
39
|
"citty": "^0.2.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|