@rucher/cli 0.2.0-beta.6 → 0.2.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.mjs +484 -135
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,4 +12,4 @@ rucher resume shop-auth # back into a named session
|
|
|
12
12
|
rucher serve # the Carnet MCP server, started by the Claude Code plugin
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Install: `npm install -g @rucher/cli`. See the repository [README](https://github.com/Florian-Varrin/Rucher#readme) for the Claude Code plugin and workspaces, and [
|
|
15
|
+
Install: `npm install -g @rucher/cli`. See the repository [README](https://github.com/Florian-Varrin/Rucher#readme) for the Claude Code plugin and workspaces, and the [CLI reference](https://github.com/Florian-Varrin/Rucher/blob/master/docs/reference/cli.md) for every command.
|
package/dist/cli.mjs
CHANGED
|
@@ -3,8 +3,9 @@ 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,
|
|
7
|
-
import {
|
|
6
|
+
import { AGENT_KINDS, BLOCKED_HEADER, CarnetError, GUARDED_TOOLS, KIND_LEGEND, KIND_TAG_PATTERN, LEGEND, MAIN_HEADER, MAIN_IDLE, 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, kindTag, listWorkspaces, loadWorkspace, memoryHalfLife, moveSession, openCarnet, openResolvedCarnet, openWorkspaceCarnet, removeWorkspaceRepo, renderRunDirectory, renderSections, repoNameFor, repoPathFor, requireWorkspace, resolveWorkspace, shortId, statusLinePath, workspaceExists, workspaceLabel, workspaceLastActive, workspaceRepoNames, workspaceSessionCounts, writeStatusLine } from "@rucher/carnet";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { stripVTControlCharacters, styleText } from "node:util";
|
|
8
9
|
import { spawnSync } from "node:child_process";
|
|
9
10
|
import { randomUUID } from "node:crypto";
|
|
10
11
|
import { createInterface } from "node:readline/promises";
|
|
@@ -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,80 @@ 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.8";
|
|
250
|
+
// src/plugin.ts
|
|
251
|
+
const CLI_VERSION = version;
|
|
252
|
+
function readJson(path) {
|
|
253
|
+
try {
|
|
254
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
255
|
+
} catch {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function installedPlugin(env) {
|
|
260
|
+
const root = env.CLAUDE_PLUGIN_ROOT;
|
|
261
|
+
if (!root) return {
|
|
262
|
+
version: null,
|
|
263
|
+
endsTurns: true
|
|
264
|
+
};
|
|
265
|
+
const manifest = readJson(join(root, ".claude-plugin", "plugin.json"));
|
|
266
|
+
const hooks = readJson(join(root, "hooks", "hooks.json"));
|
|
267
|
+
return {
|
|
268
|
+
version: typeof manifest?.version === "string" ? manifest.version : null,
|
|
269
|
+
endsTurns: Boolean(hooks?.hooks && "Stop" in hooks.hooks)
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function parse(version) {
|
|
273
|
+
const [core = "", ...pre] = version.split("-");
|
|
274
|
+
return {
|
|
275
|
+
core: core.split(".").map(Number),
|
|
276
|
+
pre: pre.length > 0 ? pre.join("-") : null
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function isOlderVersion(version, than) {
|
|
280
|
+
const a = parse(version);
|
|
281
|
+
const b = parse(than);
|
|
282
|
+
for (let index = 0; index < 3; index += 1) {
|
|
283
|
+
const diff = (a.core[index] ?? 0) - (b.core[index] ?? 0);
|
|
284
|
+
if (diff !== 0) return diff < 0;
|
|
285
|
+
}
|
|
286
|
+
if (a.pre === b.pre) return false;
|
|
287
|
+
if (a.pre === null) return false;
|
|
288
|
+
if (b.pre === null) return true;
|
|
289
|
+
return a.pre.localeCompare(b.pre, void 0, { numeric: true }) < 0;
|
|
290
|
+
}
|
|
291
|
+
function pluginLagNotice(version) {
|
|
292
|
+
if (!version || !isOlderVersion(version, CLI_VERSION)) return null;
|
|
293
|
+
return `rucher plugin ${version} is behind the CLI ${CLI_VERSION}: update the plugin, then restart the session`;
|
|
294
|
+
}
|
|
295
|
+
// src/status-line.ts
|
|
296
|
+
const LAG_LINE = "plugin behind the CLI: update it";
|
|
297
|
+
function refreshStatusLine(carnet, sessionId, env) {
|
|
298
|
+
try {
|
|
299
|
+
const version = carnet.sessions.get(sessionId)?.pluginVersion ?? null;
|
|
300
|
+
const lag = version && isOlderVersion(version, CLI_VERSION) ? LAG_LINE : null;
|
|
301
|
+
writeStatusLine(carnet, sessionId, {
|
|
302
|
+
env,
|
|
303
|
+
lag
|
|
304
|
+
});
|
|
305
|
+
} catch {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function readStatusLine(sessionId, env) {
|
|
310
|
+
try {
|
|
311
|
+
return readFileSync(statusLinePath(sessionId, env), "utf8").trimEnd();
|
|
312
|
+
} catch {
|
|
313
|
+
return "";
|
|
314
|
+
}
|
|
315
|
+
}
|
|
243
316
|
// src/commands/hook.ts
|
|
244
317
|
const host = claudeCode;
|
|
245
|
-
function runHook(io, run
|
|
318
|
+
function runHook(io, run) {
|
|
246
319
|
try {
|
|
247
320
|
run();
|
|
248
321
|
} catch (error) {
|
|
249
322
|
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
323
|
io.stderr(`rucher hook: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
262
324
|
}
|
|
263
325
|
return 0;
|
|
@@ -270,8 +332,9 @@ function withCarnet$1(payload, io, use) {
|
|
|
270
332
|
});
|
|
271
333
|
try {
|
|
272
334
|
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
273
|
-
if (!carnet.workspace && !
|
|
335
|
+
if (!carnet.workspace && !known) return;
|
|
274
336
|
use(carnet);
|
|
337
|
+
if (payload.session_id) refreshStatusLine(carnet, payload.session_id, io.env);
|
|
275
338
|
} finally {
|
|
276
339
|
carnet.close();
|
|
277
340
|
}
|
|
@@ -290,18 +353,22 @@ function sessionStart(stdinText, io) {
|
|
|
290
353
|
RUCHER_SESSION_NAME: io.env.RUCHER_SESSION_NAME,
|
|
291
354
|
RUCHER_PROMPT_VERSION: io.env.RUCHER_PROMPT_VERSION,
|
|
292
355
|
RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
|
|
293
|
-
RUCHER_MEMORY_HALF_LIFE_DAYS: io.env.RUCHER_MEMORY_HALF_LIFE_DAYS
|
|
356
|
+
RUCHER_MEMORY_HALF_LIFE_DAYS: io.env.RUCHER_MEMORY_HALF_LIFE_DAYS,
|
|
357
|
+
CLAUDE_CONFIG_DIR: io.env.CLAUDE_CONFIG_DIR
|
|
294
358
|
});
|
|
295
359
|
for (const notice of notices) io.stderr(`${notice}\n`);
|
|
296
|
-
|
|
360
|
+
const { version } = installedPlugin(io.env);
|
|
361
|
+
carnet.sessions.recordPluginVersion(payload.session_id, version);
|
|
362
|
+
const context = [additionalContext, pluginLagNotice(version)].filter(Boolean).join("\n\n");
|
|
363
|
+
if (context) {
|
|
297
364
|
const hookSpecificOutput = {
|
|
298
365
|
hookEventName: "SessionStart",
|
|
299
|
-
additionalContext
|
|
366
|
+
additionalContext: context
|
|
300
367
|
};
|
|
301
368
|
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
302
369
|
}
|
|
303
370
|
});
|
|
304
|
-
}
|
|
371
|
+
});
|
|
305
372
|
}
|
|
306
373
|
function subagentStart(stdinText, io) {
|
|
307
374
|
return runHook(io, () => {
|
|
@@ -329,19 +396,19 @@ function userPromptSubmit(stdinText, io) {
|
|
|
329
396
|
return runHook(io, () => {
|
|
330
397
|
const payload = host.parsePromptPayload(stdinText);
|
|
331
398
|
withCarnet$1(payload, io, (carnet) => {
|
|
332
|
-
handleUserPromptSubmit(carnet, host, payload);
|
|
399
|
+
handleUserPromptSubmit(carnet, host, payload, { trackTurn: installedPlugin(io.env).endsTurns });
|
|
333
400
|
});
|
|
334
|
-
}
|
|
401
|
+
});
|
|
335
402
|
}
|
|
336
403
|
function postToolUse(stdinText, io) {
|
|
337
404
|
return runHook(io, () => {
|
|
338
405
|
const payload = host.parseToolPayload(stdinText);
|
|
339
|
-
if (payload.agent_id
|
|
406
|
+
if (payload.agent_id) return;
|
|
340
407
|
withCarnet$1(payload, io, (carnet) => {
|
|
341
408
|
const additionalContext = handleToolUse(carnet, payload, {
|
|
342
409
|
RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
|
|
343
410
|
RUCHER_MEMORY_HALF_LIFE_DAYS: io.env.RUCHER_MEMORY_HALF_LIFE_DAYS
|
|
344
|
-
});
|
|
411
|
+
}, { trackTurn: installedPlugin(io.env).endsTurns });
|
|
345
412
|
if (!additionalContext) return;
|
|
346
413
|
const hookSpecificOutput = {
|
|
347
414
|
hookEventName: "PostToolUse",
|
|
@@ -359,6 +426,36 @@ function sessionEnd(stdinText, io) {
|
|
|
359
426
|
});
|
|
360
427
|
});
|
|
361
428
|
}
|
|
429
|
+
function scratchRoot(io) {
|
|
430
|
+
const uid = process.getuid?.() ?? 0;
|
|
431
|
+
return join(io.env.CLAUDE_CODE_TMPDIR ?? tmpdir(), `claude-${uid}`);
|
|
432
|
+
}
|
|
433
|
+
function preToolUse(stdinText, io) {
|
|
434
|
+
return runHook(io, () => {
|
|
435
|
+
const payload = host.parseToolPayload(stdinText);
|
|
436
|
+
const guarded = Boolean(payload.agent_id) && GUARDED_TOOLS.has(payload.tool_name ?? "");
|
|
437
|
+
if (!guarded && (payload.agent_id || payload.tool_name !== WAITING_TOOL)) return;
|
|
438
|
+
withCarnet$1(payload, io, (carnet) => {
|
|
439
|
+
if (!guarded) return handleToolStart(carnet, payload);
|
|
440
|
+
const reason = guardSubagentCall(carnet, payload, scratchRoot(io));
|
|
441
|
+
if (!reason) return;
|
|
442
|
+
const hookSpecificOutput = {
|
|
443
|
+
hookEventName: "PreToolUse",
|
|
444
|
+
permissionDecision: "deny",
|
|
445
|
+
permissionDecisionReason: reason
|
|
446
|
+
};
|
|
447
|
+
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
function stopHook(stdinText, io) {
|
|
452
|
+
return runHook(io, () => {
|
|
453
|
+
const payload = host.parseStopPayload(stdinText);
|
|
454
|
+
withCarnet$1(payload, io, (carnet) => {
|
|
455
|
+
handleStop(carnet, payload);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
}
|
|
362
459
|
// src/color.ts
|
|
363
460
|
function paint(io) {
|
|
364
461
|
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
@@ -379,29 +476,37 @@ var CliError = class extends Error {
|
|
|
379
476
|
this.name = "CliError";
|
|
380
477
|
}
|
|
381
478
|
};
|
|
479
|
+
function withWorkspace(command, workspace) {
|
|
480
|
+
return workspace ? `${command} --ws ${workspace}` : command;
|
|
481
|
+
}
|
|
382
482
|
function findSession(carnet, reference) {
|
|
383
483
|
try {
|
|
384
484
|
return carnet.sessions.find(reference);
|
|
385
485
|
} catch (error) {
|
|
386
486
|
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
387
487
|
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
388
|
-
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` :
|
|
488
|
+
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
489
|
}
|
|
390
490
|
}
|
|
391
491
|
function resolveSession(carnet, reference) {
|
|
392
492
|
if (reference) return findSession(carnet, reference);
|
|
393
493
|
const session = carnet.sessions.default();
|
|
394
|
-
if (!session) throw new CliError("No session in this workspace yet", "start
|
|
494
|
+
if (!session) throw new CliError("No session in this workspace yet", withWorkspace("start one with rucher new <name>", carnet.workspace?.name));
|
|
395
495
|
return session;
|
|
396
496
|
}
|
|
397
497
|
// src/commands/log.ts
|
|
398
|
-
function
|
|
498
|
+
function kindOf(event, kinds) {
|
|
499
|
+
return event.agent ? kinds.get(event.agent) : void 0;
|
|
500
|
+
}
|
|
501
|
+
function formatEvents(events, io, kinds = /* @__PURE__ */ new Map()) {
|
|
399
502
|
const colors = paint(io);
|
|
400
503
|
if (events.length === 0) return colors.dim("no events yet");
|
|
401
504
|
return events.map((event) => {
|
|
505
|
+
const kind = kindOf(event, kinds);
|
|
402
506
|
return [
|
|
403
507
|
colors.dim(formatClock(new Date(event.at))),
|
|
404
508
|
colors.bold(event.type.padEnd(9)),
|
|
509
|
+
kind ? colors.dim(kindTag(kind)) : "",
|
|
405
510
|
event.agent ?? "",
|
|
406
511
|
event.link ?? event.note ?? "",
|
|
407
512
|
event.commit ? colors.cyan(event.commit.slice(0, 7)) : ""
|
|
@@ -413,8 +518,10 @@ function formatDay(date) {
|
|
|
413
518
|
const day = String(date.getDate()).padStart(2, "0");
|
|
414
519
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
415
520
|
}
|
|
416
|
-
function markdownEvent(event) {
|
|
521
|
+
function markdownEvent(event, kinds) {
|
|
417
522
|
const parts = [`${formatClock(new Date(event.at))} **${event.type}**`];
|
|
523
|
+
const kind = kindOf(event, kinds);
|
|
524
|
+
if (kind) parts.push(kind);
|
|
418
525
|
if (event.agent) parts.push(`\`${event.agent}\``);
|
|
419
526
|
const detail = [
|
|
420
527
|
event.note,
|
|
@@ -423,7 +530,7 @@ function markdownEvent(event) {
|
|
|
423
530
|
].filter(Boolean).join(" · ");
|
|
424
531
|
return `- ${parts.join(" ")}${detail ? `: ${detail}` : ""}`;
|
|
425
532
|
}
|
|
426
|
-
function formatEventsMarkdown(events, title) {
|
|
533
|
+
function formatEventsMarkdown(events, title, kinds = /* @__PURE__ */ new Map()) {
|
|
427
534
|
const lines = [`# Journal: ${title}`];
|
|
428
535
|
if (events.length === 0) return `${lines[0]}\n\nNo events yet.`;
|
|
429
536
|
let day = "";
|
|
@@ -433,7 +540,7 @@ function formatEventsMarkdown(events, title) {
|
|
|
433
540
|
day = current;
|
|
434
541
|
lines.push("", `## ${day}`, "");
|
|
435
542
|
}
|
|
436
|
-
lines.push(markdownEvent(event));
|
|
543
|
+
lines.push(markdownEvent(event, kinds));
|
|
437
544
|
}
|
|
438
545
|
return lines.join("\n");
|
|
439
546
|
}
|
|
@@ -442,43 +549,9 @@ function sessionTitle(carnet, session) {
|
|
|
442
549
|
}
|
|
443
550
|
function logOnce(carnet, io, options) {
|
|
444
551
|
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;
|
|
552
|
+
const events = carnet.events.read(session.id, options.count, options.agents, options.kind);
|
|
553
|
+
const kinds = new Map(carnet.agents.list(session.id, { includeClosed: true }).map((agent) => [agent.name, agent.kind]));
|
|
554
|
+
io.stdout(`${options.md ? formatEventsMarkdown(events, sessionTitle(carnet, session), kinds) : formatEvents(events, io, kinds)}\n`);
|
|
482
555
|
}
|
|
483
556
|
// src/commands/notes.ts
|
|
484
557
|
const KIND_TITLES = {
|
|
@@ -543,9 +616,8 @@ function notesList(carnet, io, options = {}) {
|
|
|
543
616
|
return;
|
|
544
617
|
}
|
|
545
618
|
const colors = paint(io);
|
|
546
|
-
warnNoWorkspace(carnet, io);
|
|
547
619
|
if (notes.length === 0) {
|
|
548
|
-
|
|
620
|
+
io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
549
621
|
return;
|
|
550
622
|
}
|
|
551
623
|
const blocks = grouped(notes).map(([kind, kindNotes]) => `${colors.bold(KIND_TITLES[kind])}\n${kindNotes.map((note) => noteLine(io, note)).join("\n")}`);
|
|
@@ -626,29 +698,30 @@ function launchEnv(workspace, session, promptVersion, kind) {
|
|
|
626
698
|
};
|
|
627
699
|
}
|
|
628
700
|
function planNew(carnet, io, options) {
|
|
629
|
-
if (options.kind === "active" && !options.name) throw new CliError("An active session needs a name", "rucher new <name>");
|
|
701
|
+
if (options.kind === "active" && !options.name) throw new CliError("An active session needs a name", withWorkspace("rucher new <name>", carnet.workspace?.name));
|
|
702
|
+
const workspace = carnet.requireWorkspace();
|
|
630
703
|
const session = carnet.sessions.create({
|
|
631
704
|
id: randomUUID(),
|
|
632
705
|
kind: options.kind,
|
|
633
706
|
name: options.name,
|
|
634
|
-
cwd:
|
|
635
|
-
repo: repoNameFor(
|
|
707
|
+
cwd: workspace.runDirectory,
|
|
708
|
+
repo: repoNameFor(workspace, io.cwd)
|
|
636
709
|
});
|
|
637
710
|
const host = hostById(session.host);
|
|
638
|
-
|
|
711
|
+
renderRunDirectory(workspace, {
|
|
639
712
|
env: io.env,
|
|
640
713
|
host: session.host
|
|
641
714
|
});
|
|
642
|
-
const prompt = appendPromptFile(
|
|
715
|
+
const prompt = appendPromptFile(workspace, session, io.env);
|
|
643
716
|
return {
|
|
644
717
|
...host.launchCommand(session.id, {
|
|
645
718
|
name: session.name,
|
|
646
719
|
appendPromptFile: prompt.path,
|
|
647
|
-
directories: repoDirectories(
|
|
720
|
+
directories: repoDirectories(workspace),
|
|
648
721
|
passthrough: options.passthrough
|
|
649
722
|
}),
|
|
650
|
-
cwd:
|
|
651
|
-
env: launchEnv(
|
|
723
|
+
cwd: workspace.runDirectory,
|
|
724
|
+
env: launchEnv(workspace, session, prompt.version),
|
|
652
725
|
sessionId: session.id
|
|
653
726
|
};
|
|
654
727
|
}
|
|
@@ -656,7 +729,7 @@ function repoDirectories(workspace) {
|
|
|
656
729
|
return (workspace?.repos ?? []).map((repo) => repo.path).filter((path) => existsSync(path));
|
|
657
730
|
}
|
|
658
731
|
function sessionWorkspace(carnet, session, env) {
|
|
659
|
-
if (!
|
|
732
|
+
if (!isWorkspaceName(session.workspace)) return null;
|
|
660
733
|
return carnet.workspace?.name === session.workspace ? carnet.workspace : loadWorkspace(session.workspace, env);
|
|
661
734
|
}
|
|
662
735
|
function prepareSession(carnet, session, env) {
|
|
@@ -699,12 +772,12 @@ function planResume(carnet, io, reference, passthrough = []) {
|
|
|
699
772
|
};
|
|
700
773
|
}
|
|
701
774
|
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");
|
|
775
|
+
if (options.active && !options.name) throw new CliError("An active fork needs a name", withWorkspace("rucher fork <session> <name> --active", carnet.workspace?.name));
|
|
703
776
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
704
777
|
const parent = findSession(carnet, reference);
|
|
705
778
|
if (!hostById(parent.host).hasConversation(parent, io.env)) {
|
|
706
779
|
const label = sessionLabel$1(parent);
|
|
707
|
-
throw new CliError(`Session ${label} has no conversation yet, nothing to fork`, `rucher resume ${label}
|
|
780
|
+
throw new CliError(`Session ${label} has no conversation yet, nothing to fork`, withWorkspace(`rucher resume ${label}`, parent.workspace));
|
|
708
781
|
}
|
|
709
782
|
const workspace = prepareSession(carnet, parent, io.env);
|
|
710
783
|
const cwd = sessionDirectory(parent);
|
|
@@ -765,25 +838,27 @@ function lastUse(at, now) {
|
|
|
765
838
|
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
766
839
|
}
|
|
767
840
|
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
768
|
-
|
|
841
|
+
return table(sessions.map((session, index) => [
|
|
769
842
|
String(index + 1),
|
|
770
843
|
session.name ?? shortId(session.id),
|
|
771
844
|
session.kind,
|
|
772
845
|
session.status,
|
|
773
846
|
lastUse(session.lastActiveAt, now),
|
|
774
847
|
shortId(session.id)
|
|
775
|
-
]);
|
|
848
|
+
]));
|
|
849
|
+
}
|
|
850
|
+
function table(rows) {
|
|
776
851
|
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
777
852
|
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
778
853
|
}
|
|
779
854
|
function hasFzf() {
|
|
780
855
|
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
781
856
|
}
|
|
782
|
-
function pickWithFzf(
|
|
857
|
+
function pickWithFzf(items, lines, label) {
|
|
783
858
|
const result = spawnSync("fzf", [
|
|
784
859
|
"--with-nth=2..",
|
|
785
860
|
"--no-sort",
|
|
786
|
-
|
|
861
|
+
`--prompt=${label}> `
|
|
787
862
|
], {
|
|
788
863
|
input: lines.join("\n"),
|
|
789
864
|
stdio: [
|
|
@@ -793,36 +868,62 @@ function pickWithFzf(sessions, lines) {
|
|
|
793
868
|
],
|
|
794
869
|
encoding: "utf8"
|
|
795
870
|
});
|
|
796
|
-
return
|
|
871
|
+
return items[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
797
872
|
}
|
|
798
|
-
async function pickFromList(
|
|
873
|
+
async function pickFromList(items, lines, label) {
|
|
799
874
|
process.stderr.write(`${lines.join("\n")}\n`);
|
|
800
875
|
const prompt = createInterface({
|
|
801
876
|
input: process.stdin,
|
|
802
877
|
output: process.stderr
|
|
803
878
|
});
|
|
804
879
|
try {
|
|
805
|
-
const answer = await prompt.question(
|
|
806
|
-
return
|
|
880
|
+
const answer = await prompt.question(`${label} number> `);
|
|
881
|
+
return items[Number(answer.trim()) - 1];
|
|
807
882
|
} finally {
|
|
808
883
|
prompt.close();
|
|
809
884
|
}
|
|
810
885
|
}
|
|
886
|
+
function pick(items, lines, label) {
|
|
887
|
+
return hasFzf() ? Promise.resolve(pickWithFzf(items, lines, label)) : pickFromList(items, lines, label);
|
|
888
|
+
}
|
|
811
889
|
async function pickSession(carnet) {
|
|
812
890
|
const sessions = pickerSessions(carnet);
|
|
813
|
-
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
const picked =
|
|
891
|
+
const workspace = carnet.workspace?.name;
|
|
892
|
+
if (sessions.length === 0) throw new CliError("No session to resume in this workspace", withWorkspace("rucher new <name>", workspace));
|
|
893
|
+
if (!process.stdin.isTTY) throw new CliError("No session given", withWorkspace("rucher resume <name, id or id prefix>", workspace));
|
|
894
|
+
const picked = await pick(sessions, pickerLines(sessions), "session");
|
|
817
895
|
if (!picked) throw new CliError("No session picked");
|
|
818
896
|
return picked;
|
|
819
897
|
}
|
|
898
|
+
function workspaceChoices(env) {
|
|
899
|
+
const carnet = openWorkspaceCarnet(null, { env });
|
|
900
|
+
try {
|
|
901
|
+
const lastActive = workspaceLastActive(carnet.db);
|
|
902
|
+
return listWorkspaces(env).map((workspace) => ({
|
|
903
|
+
name: workspace.name,
|
|
904
|
+
lastActiveAt: lastActive.get(workspace.name)
|
|
905
|
+
})).sort((a, b) => (b.lastActiveAt ?? "").localeCompare(a.lastActiveAt ?? "") || a.name.localeCompare(b.name));
|
|
906
|
+
} finally {
|
|
907
|
+
carnet.close();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
function workspaceLines(choices, now = /* @__PURE__ */ new Date()) {
|
|
911
|
+
return table(choices.map((choice, index) => [
|
|
912
|
+
String(index + 1),
|
|
913
|
+
choice.name,
|
|
914
|
+
choice.lastActiveAt ? lastUse(choice.lastActiveAt, now) : "never"
|
|
915
|
+
]));
|
|
916
|
+
}
|
|
917
|
+
async function pickWorkspace(choices) {
|
|
918
|
+
return (await pick(choices, workspaceLines(choices), "workspace"))?.name;
|
|
919
|
+
}
|
|
820
920
|
// src/commands/serve.ts
|
|
821
921
|
function serve(io) {
|
|
822
922
|
serveCarnet({
|
|
823
923
|
cwd: io.cwd,
|
|
824
924
|
env: io.env,
|
|
825
|
-
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
925
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env),
|
|
926
|
+
afterTool: (carnet, sessionId) => refreshStatusLine(carnet, sessionId, io.env)
|
|
826
927
|
});
|
|
827
928
|
}
|
|
828
929
|
// src/commands/sessions.ts
|
|
@@ -848,10 +949,9 @@ function sessionsOnce(carnet, io, options = {}) {
|
|
|
848
949
|
includeTemp: options.all,
|
|
849
950
|
includeArchived: options.all
|
|
850
951
|
});
|
|
851
|
-
warnNoWorkspace(carnet, io);
|
|
852
952
|
if (sessions.length === 0) {
|
|
853
953
|
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
854
|
-
|
|
954
|
+
io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
855
955
|
return;
|
|
856
956
|
}
|
|
857
957
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
@@ -875,13 +975,14 @@ function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
|
875
975
|
const from = findSession(carnet, fromReference);
|
|
876
976
|
const into = findSession(carnet, intoReference);
|
|
877
977
|
const result = carnet.sessions.merge(from.id, into.id);
|
|
978
|
+
for (const session of [from, into]) refreshStatusLine(carnet, session.id, io.env);
|
|
878
979
|
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
879
980
|
const lines = [
|
|
880
981
|
`merged ${label(from)} into ${label(result.session)}`,
|
|
881
982
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
882
983
|
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
883
984
|
` events moved: ${result.movedEvents}`,
|
|
884
|
-
`
|
|
985
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`
|
|
885
986
|
];
|
|
886
987
|
io.stdout(`${lines.join("\n")}\n`);
|
|
887
988
|
}
|
|
@@ -902,7 +1003,7 @@ function sessionsMove(carnet, reference, workspaceReference, io, options = {}) {
|
|
|
902
1003
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
903
1004
|
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
904
1005
|
` events moved: ${result.movedEvents}`,
|
|
905
|
-
`
|
|
1006
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
906
1007
|
...result.keptNotes ? [` notes kept in ${workspaceLabel(carnet.workspace)}: ${result.keptNotes}`] : []
|
|
907
1008
|
];
|
|
908
1009
|
io.stdout(`${lines.join("\n")}\n`);
|
|
@@ -973,6 +1074,62 @@ function sessionsClean(carnet, io, options = {}) {
|
|
|
973
1074
|
if (options.purge) purgeTranscripts(session, io);
|
|
974
1075
|
}
|
|
975
1076
|
}
|
|
1077
|
+
// src/commands/fit.ts
|
|
1078
|
+
function charWidth(char) {
|
|
1079
|
+
const code = char.codePointAt(0) ?? 0;
|
|
1080
|
+
if (code === 65039 || code === 8205) return 0;
|
|
1081
|
+
return code >= 126976 || code >= 8960 && code <= 10175 || code >= 11008 && code <= 11263 ? 2 : 1;
|
|
1082
|
+
}
|
|
1083
|
+
function displayWidth(text) {
|
|
1084
|
+
return Array.from(stripVTControlCharacters(text)).reduce((width, char) => width + charWidth(char), 0);
|
|
1085
|
+
}
|
|
1086
|
+
function wrapLegend(legend, columns) {
|
|
1087
|
+
const lines = [];
|
|
1088
|
+
let line = "";
|
|
1089
|
+
for (const item of legend.split(" · ")) {
|
|
1090
|
+
const next = line ? `${line} · ${item}` : item;
|
|
1091
|
+
if (line && displayWidth(next) > columns) {
|
|
1092
|
+
lines.push(line);
|
|
1093
|
+
line = item;
|
|
1094
|
+
} else line = next;
|
|
1095
|
+
}
|
|
1096
|
+
if (line) lines.push(line);
|
|
1097
|
+
return lines;
|
|
1098
|
+
}
|
|
1099
|
+
function sectionName(header) {
|
|
1100
|
+
return stripVTControlCharacters(header).replace(/ {2}.*$/, "");
|
|
1101
|
+
}
|
|
1102
|
+
function splitSections(body) {
|
|
1103
|
+
const sections = [[]];
|
|
1104
|
+
for (const line of body) if (line === "") sections.push([]);
|
|
1105
|
+
else sections.at(-1)?.push(line);
|
|
1106
|
+
return sections.filter((section) => section.length > 0);
|
|
1107
|
+
}
|
|
1108
|
+
function fitToRows({ head, body, bottom, rows, cutOrder, more }) {
|
|
1109
|
+
const room = rows - bottom.length - 1;
|
|
1110
|
+
if (room < 1) return bottom.slice(-rows);
|
|
1111
|
+
const sections = splitSections(body);
|
|
1112
|
+
const content = () => [...head, ...sections.flatMap((section, index) => index ? ["", ...section] : section)];
|
|
1113
|
+
for (const name of cutOrder) {
|
|
1114
|
+
const overflow = content().length - room;
|
|
1115
|
+
if (overflow <= 0) break;
|
|
1116
|
+
const section = sections.find((candidate) => sectionName(candidate[0] ?? "") === name);
|
|
1117
|
+
if (!section || section.length <= 2) continue;
|
|
1118
|
+
const items = section.length - 1;
|
|
1119
|
+
const keep = Math.max(items - overflow - 1, 0);
|
|
1120
|
+
section.splice(1 + keep, items - keep, more(items - keep));
|
|
1121
|
+
}
|
|
1122
|
+
let lines = content();
|
|
1123
|
+
if (lines.length > room) {
|
|
1124
|
+
const kept = lines.slice(0, room - 1);
|
|
1125
|
+
lines = [...kept, more(lines.length - kept.length)];
|
|
1126
|
+
}
|
|
1127
|
+
return [
|
|
1128
|
+
...lines,
|
|
1129
|
+
...Array(rows - bottom.length - lines.length).fill(""),
|
|
1130
|
+
...bottom
|
|
1131
|
+
];
|
|
1132
|
+
}
|
|
976
1133
|
// src/commands/watch-keys.ts
|
|
977
1134
|
const INITIAL_WATCH_STATE = {
|
|
978
1135
|
notesOpen: false,
|
|
@@ -1081,11 +1238,13 @@ function pressKey(state, key, noteCount) {
|
|
|
1081
1238
|
}
|
|
1082
1239
|
// src/commands/status.ts
|
|
1083
1240
|
const SECTION_HEADERS = /* @__PURE__ */ new Set([
|
|
1084
|
-
|
|
1241
|
+
MAIN_HEADER,
|
|
1085
1242
|
"Waiting on you",
|
|
1243
|
+
BLOCKED_HEADER,
|
|
1086
1244
|
"Running",
|
|
1087
1245
|
NOTES_HEADER
|
|
1088
1246
|
]);
|
|
1247
|
+
const AGENT_LINE = new RegExp(`^ {2}(?:\\d+\\. )?\\S+ ${KIND_TAG_PATTERN.source} `);
|
|
1089
1248
|
function truncate(line, columns) {
|
|
1090
1249
|
const chars = Array.from(line);
|
|
1091
1250
|
return chars.length > columns ? `${chars.slice(0, Math.max(columns - 1, 1)).join("")}…` : line;
|
|
@@ -1095,8 +1254,9 @@ function colorizeLine(line, io) {
|
|
|
1095
1254
|
if (line === LEGEND) return colors.dim(line);
|
|
1096
1255
|
const cut = truncate(line, io.columns);
|
|
1097
1256
|
if (SECTION_HEADERS.has(line)) return colors.bold(cut);
|
|
1098
|
-
if (line.startsWith("
|
|
1099
|
-
if (line
|
|
1257
|
+
if (line.startsWith(" ⚠")) return colors.red(cut);
|
|
1258
|
+
if (line.startsWith(" ⚙️") || line.startsWith(" ⏸")) return colors.yellow(cut);
|
|
1259
|
+
if (line === " nothing" || line === ` ${MAIN_IDLE}`) return colors.dim(cut);
|
|
1100
1260
|
if (cut.startsWith(`${NOTES_HEADER} `)) return `${colors.bold(NOTES_HEADER)}${cut.slice(NOTES_HEADER.length)}`;
|
|
1101
1261
|
const marker = /^ {2}\+ #\d+ +\S+ {2}(similar to [^·]*·)/.exec(cut);
|
|
1102
1262
|
if (marker?.[1]) {
|
|
@@ -1104,6 +1264,7 @@ function colorizeLine(line, io) {
|
|
|
1104
1264
|
const end = start + marker[1].length;
|
|
1105
1265
|
return `${cut.slice(0, start)}${colors.yellow(cut.slice(start, end))}${cut.slice(end)}`;
|
|
1106
1266
|
}
|
|
1267
|
+
if (AGENT_LINE.test(cut)) return cut.replace(KIND_TAG_PATTERN, (tag) => colors.dim(tag));
|
|
1107
1268
|
return cut;
|
|
1108
1269
|
}
|
|
1109
1270
|
function sessionName(session) {
|
|
@@ -1162,42 +1323,80 @@ function hasSomethingToShow(carnet, session) {
|
|
|
1162
1323
|
function sessionBlock(session, view, io) {
|
|
1163
1324
|
return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
|
|
1164
1325
|
}
|
|
1165
|
-
|
|
1326
|
+
const CUT_ORDER = [
|
|
1327
|
+
"Notes",
|
|
1328
|
+
"Running",
|
|
1329
|
+
"Waiting on agents",
|
|
1330
|
+
"Waiting on you"
|
|
1331
|
+
];
|
|
1332
|
+
const NOTES_OPEN_CUT_ORDER = [
|
|
1333
|
+
"Running",
|
|
1334
|
+
"Waiting on agents",
|
|
1335
|
+
"Waiting on you",
|
|
1336
|
+
"Notes"
|
|
1337
|
+
];
|
|
1338
|
+
function legendLines(io, fit) {
|
|
1339
|
+
const colors = paint(io);
|
|
1340
|
+
const legend = fit ? wrapLegend(LEGEND, io.columns) : [LEGEND];
|
|
1341
|
+
return [colors.dim(truncate(KIND_LEGEND, io.columns)), ...legend.map((line) => colors.dim(line))];
|
|
1342
|
+
}
|
|
1343
|
+
function layout(io, rows, parts) {
|
|
1344
|
+
if (rows === void 0) return [
|
|
1345
|
+
...parts.head,
|
|
1346
|
+
...parts.body,
|
|
1347
|
+
"",
|
|
1348
|
+
...parts.footer,
|
|
1349
|
+
...legendLines(io, false)
|
|
1350
|
+
].join("\n");
|
|
1351
|
+
const colors = paint(io);
|
|
1352
|
+
return fitToRows({
|
|
1353
|
+
head: parts.head,
|
|
1354
|
+
body: parts.body,
|
|
1355
|
+
bottom: [...parts.footer, ...legendLines(io, true)],
|
|
1356
|
+
rows,
|
|
1357
|
+
cutOrder: parts.cutOrder,
|
|
1358
|
+
more: (count) => colors.dim(` … ${count} more`)
|
|
1359
|
+
}).join("\n");
|
|
1360
|
+
}
|
|
1361
|
+
function singleView(carnet, session, io, kind, state, rows) {
|
|
1166
1362
|
const colors = paint(io);
|
|
1167
|
-
const view = carnet.status.view(session);
|
|
1363
|
+
const view = carnet.status.view(session, { kind });
|
|
1168
1364
|
const separator = " - ";
|
|
1169
1365
|
const label = sessionLabel(carnet, session, io.columns - view.time.length - 3);
|
|
1170
1366
|
const title = `${colors.dim(view.time)}${separator}${colors.cyan(label)}`;
|
|
1171
1367
|
const body = state ? interactiveLines(carnet, session, view, io, state) : sessionLines(session, view, io);
|
|
1172
1368
|
const footer = footerLine(view, io, state);
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1369
|
+
const lag = pluginLagNotice(session.pluginVersion);
|
|
1370
|
+
return layout(io, rows, {
|
|
1371
|
+
head: [
|
|
1372
|
+
title,
|
|
1373
|
+
...lag ? [colors.yellow(truncate(lag, io.columns))] : [],
|
|
1374
|
+
""
|
|
1375
|
+
],
|
|
1376
|
+
body,
|
|
1377
|
+
footer: footer ? [footer] : [],
|
|
1378
|
+
cutOrder: state?.notesOpen ? NOTES_OPEN_CUT_ORDER : CUT_ORDER
|
|
1379
|
+
});
|
|
1181
1380
|
}
|
|
1182
1381
|
function renderStatusView(carnet, io, options) {
|
|
1183
1382
|
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);
|
|
1383
|
+
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.kind, options.interaction, options.rows);
|
|
1185
1384
|
let time = "";
|
|
1186
1385
|
const blocks = sessions.map((session) => {
|
|
1187
|
-
const view = carnet.status.view(session);
|
|
1386
|
+
const view = carnet.status.view(session, { kind: options.kind });
|
|
1188
1387
|
time ||= view.time;
|
|
1189
1388
|
return sessionBlock(session, view, io);
|
|
1190
1389
|
});
|
|
1191
1390
|
const colors = paint(io);
|
|
1192
1391
|
const separator = " - ";
|
|
1193
1392
|
const workspace = truncate(workspaceLabel(carnet.workspace), io.columns - time.length - 3);
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
"",
|
|
1197
|
-
blocks.join("\n\n"),
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1393
|
+
const title = `${colors.dim(time)}${separator}${colors.cyan(workspace)}`;
|
|
1394
|
+
return layout(io, options.rows, {
|
|
1395
|
+
head: [title, ""],
|
|
1396
|
+
body: blocks.join("\n\n").split("\n"),
|
|
1397
|
+
footer: [],
|
|
1398
|
+
cutOrder: []
|
|
1399
|
+
});
|
|
1201
1400
|
}
|
|
1202
1401
|
function statusOnce(carnet, io, options) {
|
|
1203
1402
|
io.stdout(`${renderStatusView(carnet, io, options)}\n`);
|
|
@@ -1236,23 +1435,26 @@ function statusWatch(carnet, io, options) {
|
|
|
1236
1435
|
try {
|
|
1237
1436
|
text = renderStatusView(carnet, io, {
|
|
1238
1437
|
...options,
|
|
1239
|
-
interaction: interactive ? state : void 0
|
|
1438
|
+
interaction: interactive ? state : void 0,
|
|
1439
|
+
rows: io.rows
|
|
1240
1440
|
});
|
|
1241
1441
|
} catch (error) {
|
|
1242
1442
|
text = paint(io).dim(error instanceof Error ? error.message : String(error));
|
|
1243
1443
|
}
|
|
1244
1444
|
if (text === last) return;
|
|
1245
1445
|
last = text;
|
|
1246
|
-
io.stdout(`${CLEAR}${text}\n`);
|
|
1446
|
+
io.stdout(`${CLEAR}${text}${io.rows === void 0 ? "\n" : ""}`);
|
|
1247
1447
|
};
|
|
1248
1448
|
const timer = setInterval(() => {
|
|
1249
1449
|
if (state.reason === null) repaint();
|
|
1250
1450
|
}, options.intervalMilliseconds);
|
|
1451
|
+
const offResize = options.onResize?.(repaint);
|
|
1251
1452
|
let stopped = false;
|
|
1252
1453
|
const stop = () => {
|
|
1253
1454
|
if (stopped) return;
|
|
1254
1455
|
stopped = true;
|
|
1255
1456
|
clearInterval(timer);
|
|
1457
|
+
offResize?.();
|
|
1256
1458
|
options.keys?.close();
|
|
1257
1459
|
io.stdout(SHOW_CURSOR);
|
|
1258
1460
|
resolve();
|
|
@@ -1272,6 +1474,70 @@ function statusWatch(carnet, io, options) {
|
|
|
1272
1474
|
repaint();
|
|
1273
1475
|
});
|
|
1274
1476
|
}
|
|
1477
|
+
// src/commands/statusline.ts
|
|
1478
|
+
function statusLineDirectory(io) {
|
|
1479
|
+
io.stdout(`${dirname(statusLinePath("session", io.env))}\n`);
|
|
1480
|
+
return 0;
|
|
1481
|
+
}
|
|
1482
|
+
function statusLine(stdinText, io) {
|
|
1483
|
+
let sessionId;
|
|
1484
|
+
try {
|
|
1485
|
+
sessionId = JSON.parse(stdinText).session_id;
|
|
1486
|
+
} catch {
|
|
1487
|
+
return 0;
|
|
1488
|
+
}
|
|
1489
|
+
if (typeof sessionId !== "string" || !/^[\w-]+$/.test(sessionId)) return 0;
|
|
1490
|
+
const line = readStatusLine(sessionId, io.env);
|
|
1491
|
+
if (line) io.stdout(`${line}\n`);
|
|
1492
|
+
return 0;
|
|
1493
|
+
}
|
|
1494
|
+
// src/workspace-option.ts
|
|
1495
|
+
const workspaceArgument = { ws: {
|
|
1496
|
+
type: "string",
|
|
1497
|
+
description: "Workspace name (default: from RUCHER_WS or the run directory, else asked)"
|
|
1498
|
+
} };
|
|
1499
|
+
function forwardWorkspace({ args }) {
|
|
1500
|
+
if (args.ws) process.env.RUCHER_WS = args.ws;
|
|
1501
|
+
}
|
|
1502
|
+
async function chooseWorkspace(io, workspace, { interactive = process.stdin.isTTY === true && process.stderr.isTTY === true, choose = pickWorkspace } = {}) {
|
|
1503
|
+
if (workspace || !interactive) return;
|
|
1504
|
+
if (resolveWorkspace({
|
|
1505
|
+
cwd: io.cwd,
|
|
1506
|
+
env: io.env
|
|
1507
|
+
}).workspace) return;
|
|
1508
|
+
const choices = workspaceChoices(io.env);
|
|
1509
|
+
if (choices.length === 0) return;
|
|
1510
|
+
const chosen = await choose(choices);
|
|
1511
|
+
if (chosen) io.env.RUCHER_WS = chosen;
|
|
1512
|
+
}
|
|
1513
|
+
function announceWorkspace(io, resolution) {
|
|
1514
|
+
if (resolution.workspace && resolution.origin === "run-directory") io.stderr(`workspace ${resolution.workspace.name} (from its run directory)\n`);
|
|
1515
|
+
}
|
|
1516
|
+
function openCliCarnet(io, workspace) {
|
|
1517
|
+
const { carnet, resolution } = openResolvedCarnet({
|
|
1518
|
+
cwd: io.cwd,
|
|
1519
|
+
env: io.env,
|
|
1520
|
+
workspace
|
|
1521
|
+
});
|
|
1522
|
+
try {
|
|
1523
|
+
requireWorkspace(resolution.workspace);
|
|
1524
|
+
} catch (error) {
|
|
1525
|
+
carnet.close();
|
|
1526
|
+
throw error;
|
|
1527
|
+
}
|
|
1528
|
+
announceWorkspace(io, resolution);
|
|
1529
|
+
return carnet;
|
|
1530
|
+
}
|
|
1531
|
+
function currentWorkspace(io, workspace) {
|
|
1532
|
+
const resolution = resolveWorkspace({
|
|
1533
|
+
cwd: io.cwd,
|
|
1534
|
+
env: io.env,
|
|
1535
|
+
workspace
|
|
1536
|
+
});
|
|
1537
|
+
const found = requireWorkspace(resolution.workspace);
|
|
1538
|
+
announceWorkspace(io, resolution);
|
|
1539
|
+
return found;
|
|
1540
|
+
}
|
|
1275
1541
|
// src/commands/ws.ts
|
|
1276
1542
|
function carnetErrors(io, run) {
|
|
1277
1543
|
try {
|
|
@@ -1478,7 +1744,12 @@ function processIo(options = {}) {
|
|
|
1478
1744
|
cwd: process.cwd(),
|
|
1479
1745
|
env: process.env,
|
|
1480
1746
|
color: tty && colorWanted && !process.env.NO_COLOR,
|
|
1481
|
-
|
|
1747
|
+
get columns() {
|
|
1748
|
+
return process.stdout.columns ?? 80;
|
|
1749
|
+
},
|
|
1750
|
+
get rows() {
|
|
1751
|
+
return tty ? process.stdout.rows : void 0;
|
|
1752
|
+
}
|
|
1482
1753
|
};
|
|
1483
1754
|
}
|
|
1484
1755
|
function readStdin() {
|
|
@@ -1523,6 +1794,22 @@ function fail(io, error) {
|
|
|
1523
1794
|
else io.stderr(`error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1524
1795
|
process.exit(1);
|
|
1525
1796
|
}
|
|
1797
|
+
async function askWorkspace({ args }) {
|
|
1798
|
+
const io = processIo();
|
|
1799
|
+
try {
|
|
1800
|
+
await chooseWorkspace(io, args.ws);
|
|
1801
|
+
} catch (error) {
|
|
1802
|
+
fail(io, error);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const kindArgument = { kind: {
|
|
1806
|
+
type: "string",
|
|
1807
|
+
description: AGENT_KINDS.join(", ")
|
|
1808
|
+
} };
|
|
1809
|
+
function agentKind(value) {
|
|
1810
|
+
if (value === void 0 || isAgentKind(value)) return value;
|
|
1811
|
+
throw new CliError(`Unknown agent kind ${value}`, `use one of ${AGENT_KINDS.join(", ")}`);
|
|
1812
|
+
}
|
|
1526
1813
|
const colorArgument = { color: {
|
|
1527
1814
|
type: "boolean",
|
|
1528
1815
|
default: true,
|
|
@@ -1556,16 +1843,19 @@ const statusCommand = defineCommand({
|
|
|
1556
1843
|
default: "1",
|
|
1557
1844
|
description: "Refresh interval in seconds with --watch"
|
|
1558
1845
|
},
|
|
1846
|
+
...kindArgument,
|
|
1559
1847
|
...workspaceArgument,
|
|
1560
1848
|
...colorArgument
|
|
1561
1849
|
},
|
|
1850
|
+
setup: askWorkspace,
|
|
1562
1851
|
async run({ args }) {
|
|
1563
1852
|
const io = processIo({ color: args.color });
|
|
1564
1853
|
try {
|
|
1565
1854
|
const carnet = openCliCarnet(io, args.ws);
|
|
1566
1855
|
const options = {
|
|
1567
1856
|
session: args.session,
|
|
1568
|
-
all: args.all
|
|
1857
|
+
all: args.all,
|
|
1858
|
+
kind: agentKind(args.kind)
|
|
1569
1859
|
};
|
|
1570
1860
|
if (!args.watch) {
|
|
1571
1861
|
statusOnce(carnet, io, options);
|
|
@@ -1579,7 +1869,11 @@ const statusCommand = defineCommand({
|
|
|
1579
1869
|
...options,
|
|
1580
1870
|
intervalMilliseconds,
|
|
1581
1871
|
signal: controller.signal,
|
|
1582
|
-
keys: terminalKeys(process.stdin, process.stdout)
|
|
1872
|
+
keys: terminalKeys(process.stdin, process.stdout),
|
|
1873
|
+
onResize: (listener) => {
|
|
1874
|
+
process.stdout.on("resize", listener);
|
|
1875
|
+
return () => process.stdout.off("resize", listener);
|
|
1876
|
+
}
|
|
1583
1877
|
});
|
|
1584
1878
|
} catch (error) {
|
|
1585
1879
|
fail(io, error);
|
|
@@ -1609,9 +1903,11 @@ const logCommand = defineCommand({
|
|
|
1609
1903
|
default: false,
|
|
1610
1904
|
description: "Agent events only, without session starts and ends"
|
|
1611
1905
|
},
|
|
1906
|
+
...kindArgument,
|
|
1612
1907
|
...workspaceArgument,
|
|
1613
1908
|
...colorArgument
|
|
1614
1909
|
},
|
|
1910
|
+
setup: askWorkspace,
|
|
1615
1911
|
run({ args }) {
|
|
1616
1912
|
const io = processIo({ color: args.color });
|
|
1617
1913
|
try {
|
|
@@ -1619,7 +1915,8 @@ const logCommand = defineCommand({
|
|
|
1619
1915
|
session: args.session,
|
|
1620
1916
|
count: Number(args.count) || 20,
|
|
1621
1917
|
md: args.md,
|
|
1622
|
-
agents: args.agents
|
|
1918
|
+
agents: args.agents,
|
|
1919
|
+
kind: agentKind(args.kind)
|
|
1623
1920
|
});
|
|
1624
1921
|
} catch (error) {
|
|
1625
1922
|
fail(io, error);
|
|
@@ -1640,6 +1937,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1640
1937
|
...workspaceArgument,
|
|
1641
1938
|
...colorArgument
|
|
1642
1939
|
},
|
|
1940
|
+
setup: askWorkspace,
|
|
1643
1941
|
run({ args }) {
|
|
1644
1942
|
const io = processIo({ color: args.color });
|
|
1645
1943
|
try {
|
|
@@ -1652,7 +1950,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1652
1950
|
const sessionsMergeCommand = defineCommand({
|
|
1653
1951
|
meta: {
|
|
1654
1952
|
name: "merge",
|
|
1655
|
-
description: "Move the agents,
|
|
1953
|
+
description: "Move the agents, Main line and journal of one session into another, then drop it"
|
|
1656
1954
|
},
|
|
1657
1955
|
args: {
|
|
1658
1956
|
from: {
|
|
@@ -1667,6 +1965,7 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1667
1965
|
},
|
|
1668
1966
|
...workspaceArgument
|
|
1669
1967
|
},
|
|
1968
|
+
setup: askWorkspace,
|
|
1670
1969
|
run({ args }) {
|
|
1671
1970
|
const io = processIo();
|
|
1672
1971
|
try {
|
|
@@ -1697,6 +1996,7 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1697
1996
|
},
|
|
1698
1997
|
...workspaceArgument
|
|
1699
1998
|
},
|
|
1999
|
+
setup: askWorkspace,
|
|
1700
2000
|
run({ args }) {
|
|
1701
2001
|
const io = processIo();
|
|
1702
2002
|
withCarnet(io, args.ws, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
@@ -1716,6 +2016,7 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1716
2016
|
},
|
|
1717
2017
|
...workspaceArgument
|
|
1718
2018
|
},
|
|
2019
|
+
setup: askWorkspace,
|
|
1719
2020
|
run({ args }) {
|
|
1720
2021
|
const io = processIo();
|
|
1721
2022
|
withCarnet(io, args.ws, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
@@ -1730,6 +2031,7 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1730
2031
|
session: sessionReference,
|
|
1731
2032
|
...workspaceArgument
|
|
1732
2033
|
},
|
|
2034
|
+
setup: askWorkspace,
|
|
1733
2035
|
run({ args }) {
|
|
1734
2036
|
const io = processIo();
|
|
1735
2037
|
withCarnet(io, args.ws, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
@@ -1750,6 +2052,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1750
2052
|
...purgeArgument,
|
|
1751
2053
|
...workspaceArgument
|
|
1752
2054
|
},
|
|
2055
|
+
setup: askWorkspace,
|
|
1753
2056
|
run({ args }) {
|
|
1754
2057
|
const io = processIo();
|
|
1755
2058
|
withCarnet(io, args.ws, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
@@ -1758,7 +2061,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1758
2061
|
const sessionsMoveCommand = defineCommand({
|
|
1759
2062
|
meta: {
|
|
1760
2063
|
name: "move",
|
|
1761
|
-
description: "Move a session, its agents,
|
|
2064
|
+
description: "Move a session, its agents, Main line and journal to another workspace"
|
|
1762
2065
|
},
|
|
1763
2066
|
args: {
|
|
1764
2067
|
session: sessionReference,
|
|
@@ -1779,6 +2082,7 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1779
2082
|
},
|
|
1780
2083
|
...workspaceArgument
|
|
1781
2084
|
},
|
|
2085
|
+
setup: askWorkspace,
|
|
1782
2086
|
run({ args }) {
|
|
1783
2087
|
const io = processIo();
|
|
1784
2088
|
withCarnet(io, args.ws, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
@@ -1806,6 +2110,7 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1806
2110
|
},
|
|
1807
2111
|
...workspaceArgument
|
|
1808
2112
|
},
|
|
2113
|
+
setup: askWorkspace,
|
|
1809
2114
|
run({ args }) {
|
|
1810
2115
|
const io = processIo();
|
|
1811
2116
|
withCarnet(io, args.ws, (carnet) => sessionsClean(carnet, io, {
|
|
@@ -1886,6 +2191,7 @@ const notesListCommand = defineCommand({
|
|
|
1886
2191
|
...workspaceArgument,
|
|
1887
2192
|
...colorArgument
|
|
1888
2193
|
},
|
|
2194
|
+
setup: askWorkspace,
|
|
1889
2195
|
run({ args }) {
|
|
1890
2196
|
const io = processIo({ color: args.color });
|
|
1891
2197
|
withCarnet(io, args.ws, (carnet) => notesList(carnet, io, {
|
|
@@ -1912,6 +2218,7 @@ const notesShowCommand = defineCommand({
|
|
|
1912
2218
|
...workspaceArgument,
|
|
1913
2219
|
...colorArgument
|
|
1914
2220
|
},
|
|
2221
|
+
setup: askWorkspace,
|
|
1915
2222
|
run({ args }) {
|
|
1916
2223
|
const io = processIo({ color: args.color });
|
|
1917
2224
|
withCarnet(io, args.ws, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
@@ -1940,6 +2247,7 @@ const notesAddCommand = defineCommand({
|
|
|
1940
2247
|
...workspaceArgument,
|
|
1941
2248
|
...colorArgument
|
|
1942
2249
|
},
|
|
2250
|
+
setup: askWorkspace,
|
|
1943
2251
|
run({ args, rawArgs }) {
|
|
1944
2252
|
const io = processIo({ color: args.color });
|
|
1945
2253
|
withCarnet(io, args.ws, (carnet) => notesAdd(carnet, io, {
|
|
@@ -1971,6 +2279,7 @@ const notesDropCommand = defineCommand({
|
|
|
1971
2279
|
},
|
|
1972
2280
|
...workspaceArgument
|
|
1973
2281
|
},
|
|
2282
|
+
setup: askWorkspace,
|
|
1974
2283
|
run({ args }) {
|
|
1975
2284
|
const io = processIo();
|
|
1976
2285
|
const replacement = args["replaced-by"];
|
|
@@ -2036,6 +2345,7 @@ const newCommand = defineCommand({
|
|
|
2036
2345
|
},
|
|
2037
2346
|
...workspaceArgument
|
|
2038
2347
|
},
|
|
2348
|
+
setup: askWorkspace,
|
|
2039
2349
|
async run({ args, rawArgs }) {
|
|
2040
2350
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2041
2351
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2058,6 +2368,7 @@ const tmpCommand = defineCommand({
|
|
|
2058
2368
|
},
|
|
2059
2369
|
...workspaceArgument
|
|
2060
2370
|
},
|
|
2371
|
+
setup: askWorkspace,
|
|
2061
2372
|
async run({ args, rawArgs }) {
|
|
2062
2373
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2063
2374
|
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
@@ -2080,6 +2391,7 @@ const resumeCommand = defineCommand({
|
|
|
2080
2391
|
},
|
|
2081
2392
|
...workspaceArgument
|
|
2082
2393
|
},
|
|
2394
|
+
setup: askWorkspace,
|
|
2083
2395
|
async run({ args, rawArgs }) {
|
|
2084
2396
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2085
2397
|
const io = processIo();
|
|
@@ -2112,6 +2424,7 @@ const forkCommand = defineCommand({
|
|
|
2112
2424
|
},
|
|
2113
2425
|
...workspaceArgument
|
|
2114
2426
|
},
|
|
2427
|
+
setup: askWorkspace,
|
|
2115
2428
|
async run({ args, rawArgs }) {
|
|
2116
2429
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2117
2430
|
const [reference, name] = positionals(withoutWorkspaceOption(own));
|
|
@@ -2210,6 +2523,7 @@ const wsCommand = defineCommand({
|
|
|
2210
2523
|
...workspaceArgument,
|
|
2211
2524
|
...colorArgument
|
|
2212
2525
|
},
|
|
2526
|
+
setup: askWorkspace,
|
|
2213
2527
|
run({ args }) {
|
|
2214
2528
|
process.exitCode = workspaceShow(processIo({ color: args.color }), { workspace: args.ws });
|
|
2215
2529
|
}
|
|
@@ -2228,6 +2542,7 @@ const wsCommand = defineCommand({
|
|
|
2228
2542
|
...workspaceArgument,
|
|
2229
2543
|
...colorArgument
|
|
2230
2544
|
},
|
|
2545
|
+
setup: askWorkspace,
|
|
2231
2546
|
run({ args }) {
|
|
2232
2547
|
process.exitCode = workspaceAdd(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2233
2548
|
}
|
|
@@ -2246,6 +2561,7 @@ const wsCommand = defineCommand({
|
|
|
2246
2561
|
...workspaceArgument,
|
|
2247
2562
|
...colorArgument
|
|
2248
2563
|
},
|
|
2564
|
+
setup: askWorkspace,
|
|
2249
2565
|
run({ args }) {
|
|
2250
2566
|
process.exitCode = workspaceRemove(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2251
2567
|
}
|
|
@@ -2259,6 +2575,7 @@ const wsCommand = defineCommand({
|
|
|
2259
2575
|
...workspaceArgument,
|
|
2260
2576
|
...colorArgument
|
|
2261
2577
|
},
|
|
2578
|
+
setup: askWorkspace,
|
|
2262
2579
|
run({ args }) {
|
|
2263
2580
|
process.exitCode = workspaceSync(processIo({ color: args.color }), { workspace: args.ws });
|
|
2264
2581
|
}
|
|
@@ -2276,6 +2593,7 @@ const wsCommand = defineCommand({
|
|
|
2276
2593
|
},
|
|
2277
2594
|
...workspaceArgument
|
|
2278
2595
|
},
|
|
2596
|
+
setup: askWorkspace,
|
|
2279
2597
|
async run({ args }) {
|
|
2280
2598
|
process.exitCode = await workspaceEdit(processIo(), {
|
|
2281
2599
|
workspace: args.ws,
|
|
@@ -2302,6 +2620,7 @@ const wsCommand = defineCommand({
|
|
|
2302
2620
|
},
|
|
2303
2621
|
...workspaceArgument
|
|
2304
2622
|
},
|
|
2623
|
+
setup: askWorkspace,
|
|
2305
2624
|
run({ args }) {
|
|
2306
2625
|
process.exitCode = workspacePath(processIo(), {
|
|
2307
2626
|
workspace: args.ws,
|
|
@@ -2335,10 +2654,28 @@ const hookCommand = defineCommand({
|
|
|
2335
2654
|
process.exitCode = sessionEnd(await readStdin(), processIo());
|
|
2336
2655
|
}
|
|
2337
2656
|
}),
|
|
2657
|
+
"pre-tool-use": defineCommand({
|
|
2658
|
+
meta: {
|
|
2659
|
+
name: "pre-tool-use",
|
|
2660
|
+
description: "PreToolUse hook: marks the main turn as waiting on the human"
|
|
2661
|
+
},
|
|
2662
|
+
async run() {
|
|
2663
|
+
process.exitCode = preToolUse(await readStdin(), processIo());
|
|
2664
|
+
}
|
|
2665
|
+
}),
|
|
2666
|
+
stop: defineCommand({
|
|
2667
|
+
meta: {
|
|
2668
|
+
name: "stop",
|
|
2669
|
+
description: "Stop hook: ends the main agent's turn"
|
|
2670
|
+
},
|
|
2671
|
+
async run() {
|
|
2672
|
+
process.exitCode = stopHook(await readStdin(), processIo());
|
|
2673
|
+
}
|
|
2674
|
+
}),
|
|
2338
2675
|
"post-tool-use": defineCommand({
|
|
2339
2676
|
meta: {
|
|
2340
2677
|
name: "post-tool-use",
|
|
2341
|
-
description: "PostToolUse hook: adds a repo's notes the first time a tool touches it"
|
|
2678
|
+
description: "PostToolUse hook: marks the main turn working, adds a repo's notes the first time a tool touches it"
|
|
2342
2679
|
},
|
|
2343
2680
|
async run() {
|
|
2344
2681
|
process.exitCode = postToolUse(await readStdin(), processIo());
|
|
@@ -2347,7 +2684,7 @@ const hookCommand = defineCommand({
|
|
|
2347
2684
|
"user-prompt-submit": defineCommand({
|
|
2348
2685
|
meta: {
|
|
2349
2686
|
name: "user-prompt-submit",
|
|
2350
|
-
description: "UserPromptSubmit hook: names the session after a /rename"
|
|
2687
|
+
description: "UserPromptSubmit hook: starts the main turn, names the session after a /rename"
|
|
2351
2688
|
},
|
|
2352
2689
|
async run() {
|
|
2353
2690
|
process.exitCode = userPromptSubmit(await readStdin(), processIo());
|
|
@@ -2373,6 +2710,23 @@ const hookCommand = defineCommand({
|
|
|
2373
2710
|
})
|
|
2374
2711
|
}
|
|
2375
2712
|
});
|
|
2713
|
+
const statusLineCommand = defineCommand({
|
|
2714
|
+
meta: {
|
|
2715
|
+
name: "statusline",
|
|
2716
|
+
description: "Print the session's one-line status for a Claude Code statusLine command (JSON on stdin)"
|
|
2717
|
+
},
|
|
2718
|
+
args: { dir: {
|
|
2719
|
+
type: "boolean",
|
|
2720
|
+
description: "Print the folder of the status line files instead (for the plugin mod)"
|
|
2721
|
+
} },
|
|
2722
|
+
async run({ args }) {
|
|
2723
|
+
if (args.dir) {
|
|
2724
|
+
process.exitCode = statusLineDirectory(processIo());
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
2727
|
+
process.exitCode = statusLine(await readStdin(), processIo());
|
|
2728
|
+
}
|
|
2729
|
+
});
|
|
2376
2730
|
const serveCommand = defineCommand({
|
|
2377
2731
|
meta: {
|
|
2378
2732
|
name: "serve",
|
|
@@ -2382,18 +2736,12 @@ const serveCommand = defineCommand({
|
|
|
2382
2736
|
serve(processIo());
|
|
2383
2737
|
}
|
|
2384
2738
|
});
|
|
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
2739
|
const main = defineCommand({
|
|
2391
2740
|
meta: {
|
|
2392
2741
|
name: "rucher",
|
|
2393
2742
|
version,
|
|
2394
2743
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2395
2744
|
},
|
|
2396
|
-
setup: ({ rawArgs }) => refuseRemovedOption(rawArgs),
|
|
2397
2745
|
subCommands: {
|
|
2398
2746
|
status: statusCommand,
|
|
2399
2747
|
log: logCommand,
|
|
@@ -2405,6 +2753,7 @@ const main = defineCommand({
|
|
|
2405
2753
|
notes: notesCommand,
|
|
2406
2754
|
ws: wsCommand,
|
|
2407
2755
|
hook: hookCommand,
|
|
2756
|
+
statusline: statusLineCommand,
|
|
2408
2757
|
serve: serveCommand
|
|
2409
2758
|
}
|
|
2410
2759
|
});
|
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.8",
|
|
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.8",
|
|
39
39
|
"citty": "^0.2.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|