@rucher/cli 0.2.0-beta.5 → 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 +260 -112
- 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,15 +545,14 @@ 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")}`);
|
|
552
553
|
io.stdout(`${blocks.join("\n\n")}\n`);
|
|
553
554
|
}
|
|
554
|
-
function sessionLabel$
|
|
555
|
+
function sessionLabel$2(carnet, id) {
|
|
555
556
|
if (!id) return "-";
|
|
556
557
|
return carnet.sessions.get(id)?.name ?? shortId(id);
|
|
557
558
|
}
|
|
@@ -566,7 +567,7 @@ function notesShow(carnet, io, id) {
|
|
|
566
567
|
`${colors.bold(`#${note.id}`)} ${note.kind}${note.droppedAt ? colors.dim(" (dropped)") : ""}`,
|
|
567
568
|
note.text,
|
|
568
569
|
`repos: ${note.repos.length ? note.repos.join(", ") : "general"}`,
|
|
569
|
-
`added: ${when(note.createdAt)} in ${sessionLabel$
|
|
570
|
+
`added: ${when(note.createdAt)} in ${sessionLabel$2(carnet, note.session)}${note.agent ? `, from ${note.agent}` : ""}`,
|
|
570
571
|
`weight: ${note.weight.toFixed(2)} · ${note.citationCount} citation${note.citationCount === 1 ? "" : "s"}`
|
|
571
572
|
];
|
|
572
573
|
if (note.similarNotes.length) lines.push(colors.yellow(`similar to: ${note.similarNotes.map((other) => `#${other}`).join(", ")}`));
|
|
@@ -578,7 +579,7 @@ function notesShow(carnet, io, id) {
|
|
|
578
579
|
lines.push("citations:");
|
|
579
580
|
for (const citation of note.citations) {
|
|
580
581
|
const by = citation.agent ? ` ${citation.agent}` : "";
|
|
581
|
-
lines.push(` ${when(citation.at)} ${sessionLabel$
|
|
582
|
+
lines.push(` ${when(citation.at)} ${sessionLabel$2(carnet, citation.session)}${by} ${citation.why}`);
|
|
582
583
|
}
|
|
583
584
|
}
|
|
584
585
|
io.stdout(`${lines.join("\n")}\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) {
|
|
@@ -667,9 +669,12 @@ function prepareSession(carnet, session, env) {
|
|
|
667
669
|
});
|
|
668
670
|
return workspace;
|
|
669
671
|
}
|
|
672
|
+
function sessionLabel$1(session) {
|
|
673
|
+
return session.name ?? session.id.slice(0, 8);
|
|
674
|
+
}
|
|
670
675
|
function sessionDirectory(session) {
|
|
671
676
|
if (session.cwd && existsSync(session.cwd)) return session.cwd;
|
|
672
|
-
throw new CarnetError("SESSION_CWD_MISSING", `The directory of session ${session
|
|
677
|
+
throw new CarnetError("SESSION_CWD_MISSING", `The directory of session ${sessionLabel$1(session)} no longer exists: ${session.cwd ?? "none recorded"}`);
|
|
673
678
|
}
|
|
674
679
|
function planResume(carnet, io, reference, passthrough = []) {
|
|
675
680
|
const session = findSession(carnet, reference);
|
|
@@ -677,21 +682,32 @@ function planResume(carnet, io, reference, passthrough = []) {
|
|
|
677
682
|
const workspace = prepareSession(carnet, session, io.env);
|
|
678
683
|
const cwd = sessionDirectory(session);
|
|
679
684
|
const prompt = appendPromptFile(workspace, session, io.env);
|
|
685
|
+
const host = hostById(session.host);
|
|
686
|
+
const options = {
|
|
687
|
+
appendPromptFile: prompt.path,
|
|
688
|
+
directories: repoDirectories(workspace),
|
|
689
|
+
passthrough
|
|
690
|
+
};
|
|
691
|
+
const fresh = !host.hasConversation(session, io.env);
|
|
692
|
+
if (fresh) io.stderr(`no conversation yet for ${sessionLabel$1(session)}: starting it\n`);
|
|
680
693
|
return {
|
|
681
|
-
...
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}),
|
|
694
|
+
...fresh ? host.launchCommand(session.id, {
|
|
695
|
+
name: session.name,
|
|
696
|
+
...options
|
|
697
|
+
}) : host.resumeCommand(session, options),
|
|
686
698
|
cwd,
|
|
687
699
|
env: launchEnv(workspace, session, prompt.version),
|
|
688
700
|
sessionId: session.id
|
|
689
701
|
};
|
|
690
702
|
}
|
|
691
703
|
function planFork(carnet, io, reference, options = {}) {
|
|
692
|
-
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));
|
|
693
705
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
694
706
|
const parent = findSession(carnet, reference);
|
|
707
|
+
if (!hostById(parent.host).hasConversation(parent, io.env)) {
|
|
708
|
+
const label = sessionLabel$1(parent);
|
|
709
|
+
throw new CliError(`Session ${label} has no conversation yet, nothing to fork`, withWorkspace(`rucher resume ${label}`, parent.workspace));
|
|
710
|
+
}
|
|
695
711
|
const workspace = prepareSession(carnet, parent, io.env);
|
|
696
712
|
const cwd = sessionDirectory(parent);
|
|
697
713
|
const kind = options.active ? "active" : "temp";
|
|
@@ -751,25 +767,27 @@ function lastUse(at, now) {
|
|
|
751
767
|
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
752
768
|
}
|
|
753
769
|
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
754
|
-
|
|
770
|
+
return table(sessions.map((session, index) => [
|
|
755
771
|
String(index + 1),
|
|
756
772
|
session.name ?? shortId(session.id),
|
|
757
773
|
session.kind,
|
|
758
774
|
session.status,
|
|
759
775
|
lastUse(session.lastActiveAt, now),
|
|
760
776
|
shortId(session.id)
|
|
761
|
-
]);
|
|
777
|
+
]));
|
|
778
|
+
}
|
|
779
|
+
function table(rows) {
|
|
762
780
|
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
763
781
|
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
764
782
|
}
|
|
765
783
|
function hasFzf() {
|
|
766
784
|
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
767
785
|
}
|
|
768
|
-
function pickWithFzf(
|
|
786
|
+
function pickWithFzf(items, lines, label) {
|
|
769
787
|
const result = spawnSync("fzf", [
|
|
770
788
|
"--with-nth=2..",
|
|
771
789
|
"--no-sort",
|
|
772
|
-
|
|
790
|
+
`--prompt=${label}> `
|
|
773
791
|
], {
|
|
774
792
|
input: lines.join("\n"),
|
|
775
793
|
stdio: [
|
|
@@ -779,30 +797,55 @@ function pickWithFzf(sessions, lines) {
|
|
|
779
797
|
],
|
|
780
798
|
encoding: "utf8"
|
|
781
799
|
});
|
|
782
|
-
return
|
|
800
|
+
return items[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
783
801
|
}
|
|
784
|
-
async function pickFromList(
|
|
802
|
+
async function pickFromList(items, lines, label) {
|
|
785
803
|
process.stderr.write(`${lines.join("\n")}\n`);
|
|
786
804
|
const prompt = createInterface({
|
|
787
805
|
input: process.stdin,
|
|
788
806
|
output: process.stderr
|
|
789
807
|
});
|
|
790
808
|
try {
|
|
791
|
-
const answer = await prompt.question(
|
|
792
|
-
return
|
|
809
|
+
const answer = await prompt.question(`${label} number> `);
|
|
810
|
+
return items[Number(answer.trim()) - 1];
|
|
793
811
|
} finally {
|
|
794
812
|
prompt.close();
|
|
795
813
|
}
|
|
796
814
|
}
|
|
815
|
+
function pick(items, lines, label) {
|
|
816
|
+
return hasFzf() ? Promise.resolve(pickWithFzf(items, lines, label)) : pickFromList(items, lines, label);
|
|
817
|
+
}
|
|
797
818
|
async function pickSession(carnet) {
|
|
798
819
|
const sessions = pickerSessions(carnet);
|
|
799
|
-
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
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");
|
|
803
824
|
if (!picked) throw new CliError("No session picked");
|
|
804
825
|
return picked;
|
|
805
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
|
+
}
|
|
806
849
|
// src/commands/serve.ts
|
|
807
850
|
function serve(io) {
|
|
808
851
|
serveCarnet({
|
|
@@ -834,10 +877,9 @@ function sessionsOnce(carnet, io, options = {}) {
|
|
|
834
877
|
includeTemp: options.all,
|
|
835
878
|
includeArchived: options.all
|
|
836
879
|
});
|
|
837
|
-
warnNoWorkspace(carnet, io);
|
|
838
880
|
if (sessions.length === 0) {
|
|
839
881
|
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
840
|
-
|
|
882
|
+
io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
841
883
|
return;
|
|
842
884
|
}
|
|
843
885
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
@@ -1067,7 +1109,7 @@ function pressKey(state, key, noteCount) {
|
|
|
1067
1109
|
}
|
|
1068
1110
|
// src/commands/status.ts
|
|
1069
1111
|
const SECTION_HEADERS = /* @__PURE__ */ new Set([
|
|
1070
|
-
|
|
1112
|
+
MAIN_HEADER,
|
|
1071
1113
|
"Waiting on you",
|
|
1072
1114
|
"Running",
|
|
1073
1115
|
NOTES_HEADER
|
|
@@ -1081,7 +1123,8 @@ function colorizeLine(line, io) {
|
|
|
1081
1123
|
if (line === LEGEND) return colors.dim(line);
|
|
1082
1124
|
const cut = truncate(line, io.columns);
|
|
1083
1125
|
if (SECTION_HEADERS.has(line)) return colors.bold(cut);
|
|
1084
|
-
if (line.startsWith("
|
|
1126
|
+
if (line.startsWith(" ⚠")) return colors.red(cut);
|
|
1127
|
+
if (line.startsWith(" ⚙️") || line.startsWith(" ⏸")) return colors.yellow(cut);
|
|
1085
1128
|
if (line === " nothing") return colors.dim(cut);
|
|
1086
1129
|
if (cut.startsWith(`${NOTES_HEADER} `)) return `${colors.bold(NOTES_HEADER)}${cut.slice(NOTES_HEADER.length)}`;
|
|
1087
1130
|
const marker = /^ {2}\+ #\d+ +\S+ {2}(similar to [^·]*·)/.exec(cut);
|
|
@@ -1148,9 +1191,9 @@ function hasSomethingToShow(carnet, session) {
|
|
|
1148
1191
|
function sessionBlock(session, view, io) {
|
|
1149
1192
|
return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
|
|
1150
1193
|
}
|
|
1151
|
-
function singleView(carnet, session, io, state) {
|
|
1194
|
+
function singleView(carnet, session, io, kind, state) {
|
|
1152
1195
|
const colors = paint(io);
|
|
1153
|
-
const view = carnet.status.view(session);
|
|
1196
|
+
const view = carnet.status.view(session, { kind });
|
|
1154
1197
|
const separator = " - ";
|
|
1155
1198
|
const label = sessionLabel(carnet, session, io.columns - view.time.length - 3);
|
|
1156
1199
|
const title = `${colors.dim(view.time)}${separator}${colors.cyan(label)}`;
|
|
@@ -1162,15 +1205,16 @@ function singleView(carnet, session, io, state) {
|
|
|
1162
1205
|
...body,
|
|
1163
1206
|
"",
|
|
1164
1207
|
...footer ? [footer] : [],
|
|
1208
|
+
colors.dim(truncate(KIND_LEGEND, io.columns)),
|
|
1165
1209
|
colors.dim(LEGEND)
|
|
1166
1210
|
].join("\n");
|
|
1167
1211
|
}
|
|
1168
1212
|
function renderStatusView(carnet, io, options) {
|
|
1169
1213
|
const sessions = options.all ? carnet.sessions.list({ includeTemp: true }).filter((session) => hasSomethingToShow(carnet, session)) : [];
|
|
1170
|
-
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);
|
|
1171
1215
|
let time = "";
|
|
1172
1216
|
const blocks = sessions.map((session) => {
|
|
1173
|
-
const view = carnet.status.view(session);
|
|
1217
|
+
const view = carnet.status.view(session, { kind: options.kind });
|
|
1174
1218
|
time ||= view.time;
|
|
1175
1219
|
return sessionBlock(session, view, io);
|
|
1176
1220
|
});
|
|
@@ -1182,6 +1226,7 @@ function renderStatusView(carnet, io, options) {
|
|
|
1182
1226
|
"",
|
|
1183
1227
|
blocks.join("\n\n"),
|
|
1184
1228
|
"",
|
|
1229
|
+
colors.dim(truncate(KIND_LEGEND, io.columns)),
|
|
1185
1230
|
colors.dim(LEGEND)
|
|
1186
1231
|
].join("\n");
|
|
1187
1232
|
}
|
|
@@ -1258,6 +1303,53 @@ function statusWatch(carnet, io, options) {
|
|
|
1258
1303
|
repaint();
|
|
1259
1304
|
});
|
|
1260
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
|
+
}
|
|
1261
1353
|
// src/commands/ws.ts
|
|
1262
1354
|
function carnetErrors(io, run) {
|
|
1263
1355
|
try {
|
|
@@ -1509,6 +1601,22 @@ function fail(io, error) {
|
|
|
1509
1601
|
else io.stderr(`error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1510
1602
|
process.exit(1);
|
|
1511
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
|
+
}
|
|
1512
1620
|
const colorArgument = { color: {
|
|
1513
1621
|
type: "boolean",
|
|
1514
1622
|
default: true,
|
|
@@ -1542,16 +1650,19 @@ const statusCommand = defineCommand({
|
|
|
1542
1650
|
default: "1",
|
|
1543
1651
|
description: "Refresh interval in seconds with --watch"
|
|
1544
1652
|
},
|
|
1653
|
+
...kindArgument,
|
|
1545
1654
|
...workspaceArgument,
|
|
1546
1655
|
...colorArgument
|
|
1547
1656
|
},
|
|
1657
|
+
setup: askWorkspace,
|
|
1548
1658
|
async run({ args }) {
|
|
1549
1659
|
const io = processIo({ color: args.color });
|
|
1550
1660
|
try {
|
|
1551
1661
|
const carnet = openCliCarnet(io, args.ws);
|
|
1552
1662
|
const options = {
|
|
1553
1663
|
session: args.session,
|
|
1554
|
-
all: args.all
|
|
1664
|
+
all: args.all,
|
|
1665
|
+
kind: agentKind(args.kind)
|
|
1555
1666
|
};
|
|
1556
1667
|
if (!args.watch) {
|
|
1557
1668
|
statusOnce(carnet, io, options);
|
|
@@ -1595,9 +1706,11 @@ const logCommand = defineCommand({
|
|
|
1595
1706
|
default: false,
|
|
1596
1707
|
description: "Agent events only, without session starts and ends"
|
|
1597
1708
|
},
|
|
1709
|
+
...kindArgument,
|
|
1598
1710
|
...workspaceArgument,
|
|
1599
1711
|
...colorArgument
|
|
1600
1712
|
},
|
|
1713
|
+
setup: askWorkspace,
|
|
1601
1714
|
run({ args }) {
|
|
1602
1715
|
const io = processIo({ color: args.color });
|
|
1603
1716
|
try {
|
|
@@ -1605,7 +1718,8 @@ const logCommand = defineCommand({
|
|
|
1605
1718
|
session: args.session,
|
|
1606
1719
|
count: Number(args.count) || 20,
|
|
1607
1720
|
md: args.md,
|
|
1608
|
-
agents: args.agents
|
|
1721
|
+
agents: args.agents,
|
|
1722
|
+
kind: agentKind(args.kind)
|
|
1609
1723
|
});
|
|
1610
1724
|
} catch (error) {
|
|
1611
1725
|
fail(io, error);
|
|
@@ -1626,6 +1740,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1626
1740
|
...workspaceArgument,
|
|
1627
1741
|
...colorArgument
|
|
1628
1742
|
},
|
|
1743
|
+
setup: askWorkspace,
|
|
1629
1744
|
run({ args }) {
|
|
1630
1745
|
const io = processIo({ color: args.color });
|
|
1631
1746
|
try {
|
|
@@ -1653,6 +1768,7 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1653
1768
|
},
|
|
1654
1769
|
...workspaceArgument
|
|
1655
1770
|
},
|
|
1771
|
+
setup: askWorkspace,
|
|
1656
1772
|
run({ args }) {
|
|
1657
1773
|
const io = processIo();
|
|
1658
1774
|
try {
|
|
@@ -1683,6 +1799,7 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1683
1799
|
},
|
|
1684
1800
|
...workspaceArgument
|
|
1685
1801
|
},
|
|
1802
|
+
setup: askWorkspace,
|
|
1686
1803
|
run({ args }) {
|
|
1687
1804
|
const io = processIo();
|
|
1688
1805
|
withCarnet(io, args.ws, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
@@ -1702,6 +1819,7 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1702
1819
|
},
|
|
1703
1820
|
...workspaceArgument
|
|
1704
1821
|
},
|
|
1822
|
+
setup: askWorkspace,
|
|
1705
1823
|
run({ args }) {
|
|
1706
1824
|
const io = processIo();
|
|
1707
1825
|
withCarnet(io, args.ws, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
@@ -1716,6 +1834,7 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1716
1834
|
session: sessionReference,
|
|
1717
1835
|
...workspaceArgument
|
|
1718
1836
|
},
|
|
1837
|
+
setup: askWorkspace,
|
|
1719
1838
|
run({ args }) {
|
|
1720
1839
|
const io = processIo();
|
|
1721
1840
|
withCarnet(io, args.ws, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
@@ -1736,6 +1855,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1736
1855
|
...purgeArgument,
|
|
1737
1856
|
...workspaceArgument
|
|
1738
1857
|
},
|
|
1858
|
+
setup: askWorkspace,
|
|
1739
1859
|
run({ args }) {
|
|
1740
1860
|
const io = processIo();
|
|
1741
1861
|
withCarnet(io, args.ws, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
@@ -1765,6 +1885,7 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1765
1885
|
},
|
|
1766
1886
|
...workspaceArgument
|
|
1767
1887
|
},
|
|
1888
|
+
setup: askWorkspace,
|
|
1768
1889
|
run({ args }) {
|
|
1769
1890
|
const io = processIo();
|
|
1770
1891
|
withCarnet(io, args.ws, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
@@ -1792,6 +1913,7 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1792
1913
|
},
|
|
1793
1914
|
...workspaceArgument
|
|
1794
1915
|
},
|
|
1916
|
+
setup: askWorkspace,
|
|
1795
1917
|
run({ args }) {
|
|
1796
1918
|
const io = processIo();
|
|
1797
1919
|
withCarnet(io, args.ws, (carnet) => sessionsClean(carnet, io, {
|
|
@@ -1872,6 +1994,7 @@ const notesListCommand = defineCommand({
|
|
|
1872
1994
|
...workspaceArgument,
|
|
1873
1995
|
...colorArgument
|
|
1874
1996
|
},
|
|
1997
|
+
setup: askWorkspace,
|
|
1875
1998
|
run({ args }) {
|
|
1876
1999
|
const io = processIo({ color: args.color });
|
|
1877
2000
|
withCarnet(io, args.ws, (carnet) => notesList(carnet, io, {
|
|
@@ -1898,6 +2021,7 @@ const notesShowCommand = defineCommand({
|
|
|
1898
2021
|
...workspaceArgument,
|
|
1899
2022
|
...colorArgument
|
|
1900
2023
|
},
|
|
2024
|
+
setup: askWorkspace,
|
|
1901
2025
|
run({ args }) {
|
|
1902
2026
|
const io = processIo({ color: args.color });
|
|
1903
2027
|
withCarnet(io, args.ws, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
@@ -1926,6 +2050,7 @@ const notesAddCommand = defineCommand({
|
|
|
1926
2050
|
...workspaceArgument,
|
|
1927
2051
|
...colorArgument
|
|
1928
2052
|
},
|
|
2053
|
+
setup: askWorkspace,
|
|
1929
2054
|
run({ args, rawArgs }) {
|
|
1930
2055
|
const io = processIo({ color: args.color });
|
|
1931
2056
|
withCarnet(io, args.ws, (carnet) => notesAdd(carnet, io, {
|
|
@@ -1957,6 +2082,7 @@ const notesDropCommand = defineCommand({
|
|
|
1957
2082
|
},
|
|
1958
2083
|
...workspaceArgument
|
|
1959
2084
|
},
|
|
2085
|
+
setup: askWorkspace,
|
|
1960
2086
|
run({ args }) {
|
|
1961
2087
|
const io = processIo();
|
|
1962
2088
|
const replacement = args["replaced-by"];
|
|
@@ -2022,6 +2148,7 @@ const newCommand = defineCommand({
|
|
|
2022
2148
|
},
|
|
2023
2149
|
...workspaceArgument
|
|
2024
2150
|
},
|
|
2151
|
+
setup: askWorkspace,
|
|
2025
2152
|
async run({ args, rawArgs }) {
|
|
2026
2153
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2027
2154
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2044,6 +2171,7 @@ const tmpCommand = defineCommand({
|
|
|
2044
2171
|
},
|
|
2045
2172
|
...workspaceArgument
|
|
2046
2173
|
},
|
|
2174
|
+
setup: askWorkspace,
|
|
2047
2175
|
async run({ args, rawArgs }) {
|
|
2048
2176
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2049
2177
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2066,6 +2194,7 @@ const resumeCommand = defineCommand({
|
|
|
2066
2194
|
},
|
|
2067
2195
|
...workspaceArgument
|
|
2068
2196
|
},
|
|
2197
|
+
setup: askWorkspace,
|
|
2069
2198
|
async run({ args, rawArgs }) {
|
|
2070
2199
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2071
2200
|
const io = processIo();
|
|
@@ -2098,6 +2227,7 @@ const forkCommand = defineCommand({
|
|
|
2098
2227
|
},
|
|
2099
2228
|
...workspaceArgument
|
|
2100
2229
|
},
|
|
2230
|
+
setup: askWorkspace,
|
|
2101
2231
|
async run({ args, rawArgs }) {
|
|
2102
2232
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2103
2233
|
const [reference, name] = positionals(withoutWorkspaceOption(own));
|
|
@@ -2196,6 +2326,7 @@ const wsCommand = defineCommand({
|
|
|
2196
2326
|
...workspaceArgument,
|
|
2197
2327
|
...colorArgument
|
|
2198
2328
|
},
|
|
2329
|
+
setup: askWorkspace,
|
|
2199
2330
|
run({ args }) {
|
|
2200
2331
|
process.exitCode = workspaceShow(processIo({ color: args.color }), { workspace: args.ws });
|
|
2201
2332
|
}
|
|
@@ -2214,6 +2345,7 @@ const wsCommand = defineCommand({
|
|
|
2214
2345
|
...workspaceArgument,
|
|
2215
2346
|
...colorArgument
|
|
2216
2347
|
},
|
|
2348
|
+
setup: askWorkspace,
|
|
2217
2349
|
run({ args }) {
|
|
2218
2350
|
process.exitCode = workspaceAdd(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2219
2351
|
}
|
|
@@ -2232,6 +2364,7 @@ const wsCommand = defineCommand({
|
|
|
2232
2364
|
...workspaceArgument,
|
|
2233
2365
|
...colorArgument
|
|
2234
2366
|
},
|
|
2367
|
+
setup: askWorkspace,
|
|
2235
2368
|
run({ args }) {
|
|
2236
2369
|
process.exitCode = workspaceRemove(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2237
2370
|
}
|
|
@@ -2245,6 +2378,7 @@ const wsCommand = defineCommand({
|
|
|
2245
2378
|
...workspaceArgument,
|
|
2246
2379
|
...colorArgument
|
|
2247
2380
|
},
|
|
2381
|
+
setup: askWorkspace,
|
|
2248
2382
|
run({ args }) {
|
|
2249
2383
|
process.exitCode = workspaceSync(processIo({ color: args.color }), { workspace: args.ws });
|
|
2250
2384
|
}
|
|
@@ -2262,6 +2396,7 @@ const wsCommand = defineCommand({
|
|
|
2262
2396
|
},
|
|
2263
2397
|
...workspaceArgument
|
|
2264
2398
|
},
|
|
2399
|
+
setup: askWorkspace,
|
|
2265
2400
|
async run({ args }) {
|
|
2266
2401
|
process.exitCode = await workspaceEdit(processIo(), {
|
|
2267
2402
|
workspace: args.ws,
|
|
@@ -2288,6 +2423,7 @@ const wsCommand = defineCommand({
|
|
|
2288
2423
|
},
|
|
2289
2424
|
...workspaceArgument
|
|
2290
2425
|
},
|
|
2426
|
+
setup: askWorkspace,
|
|
2291
2427
|
run({ args }) {
|
|
2292
2428
|
process.exitCode = workspacePath(processIo(), {
|
|
2293
2429
|
workspace: args.ws,
|
|
@@ -2321,10 +2457,28 @@ const hookCommand = defineCommand({
|
|
|
2321
2457
|
process.exitCode = sessionEnd(await readStdin(), processIo());
|
|
2322
2458
|
}
|
|
2323
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
|
+
}),
|
|
2324
2478
|
"post-tool-use": defineCommand({
|
|
2325
2479
|
meta: {
|
|
2326
2480
|
name: "post-tool-use",
|
|
2327
|
-
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"
|
|
2328
2482
|
},
|
|
2329
2483
|
async run() {
|
|
2330
2484
|
process.exitCode = postToolUse(await readStdin(), processIo());
|
|
@@ -2333,7 +2487,7 @@ const hookCommand = defineCommand({
|
|
|
2333
2487
|
"user-prompt-submit": defineCommand({
|
|
2334
2488
|
meta: {
|
|
2335
2489
|
name: "user-prompt-submit",
|
|
2336
|
-
description: "UserPromptSubmit hook: names the session after a /rename"
|
|
2490
|
+
description: "UserPromptSubmit hook: starts the main turn, names the session after a /rename"
|
|
2337
2491
|
},
|
|
2338
2492
|
async run() {
|
|
2339
2493
|
process.exitCode = userPromptSubmit(await readStdin(), processIo());
|
|
@@ -2368,18 +2522,12 @@ const serveCommand = defineCommand({
|
|
|
2368
2522
|
serve(processIo());
|
|
2369
2523
|
}
|
|
2370
2524
|
});
|
|
2371
|
-
function refuseRemovedOption(rawArgs) {
|
|
2372
|
-
const removed = /^(-g|--group)(=|$)/;
|
|
2373
|
-
const option = splitPassthrough([...rawArgs]).own.find((argument) => removed.test(argument));
|
|
2374
|
-
if (option) fail(processIo(), new CliError(`Unknown option ${option}`, "use --ws <name>"));
|
|
2375
|
-
}
|
|
2376
2525
|
const main = defineCommand({
|
|
2377
2526
|
meta: {
|
|
2378
2527
|
name: "rucher",
|
|
2379
2528
|
version,
|
|
2380
2529
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2381
2530
|
},
|
|
2382
|
-
setup: ({ rawArgs }) => refuseRemovedOption(rawArgs),
|
|
2383
2531
|
subCommands: {
|
|
2384
2532
|
status: statusCommand,
|
|
2385
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": {
|