@rucher/cli 0.2.0-beta.7 → 0.2.0-beta.9
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 +269 -50
- 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,9 +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 { AGENT_KINDS, CarnetError, GUARDED_TOOLS,
|
|
6
|
+
import { AGENT_KINDS, BLOCKED_HEADER, CarnetError, GUARDED_TOOLS, KIND_LEGEND, KIND_TAG_PATTERN, LAUNCH_TOOLS, 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, guardMainLaunch, guardSubagentCall, handleSessionEnd, handleSessionStart, handleStop, handleToolStart, handleToolUse, handleUserPromptSubmit, hostById, isAgentKind, isWorkspaceName, kindTag, labelStatusLine, 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
7
|
import { tmpdir } from "node:os";
|
|
8
|
-
import { styleText } from "node:util";
|
|
8
|
+
import { stripVTControlCharacters, styleText } from "node:util";
|
|
9
9
|
import { spawnSync } from "node:child_process";
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { createInterface } from "node:readline/promises";
|
|
@@ -246,7 +246,73 @@ async function setupCompletion(main) {
|
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
// package.json
|
|
249
|
-
var version = "0.2.0-beta.
|
|
249
|
+
var version = "0.2.0-beta.9";
|
|
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
|
+
}
|
|
250
316
|
// src/commands/hook.ts
|
|
251
317
|
const host = claudeCode;
|
|
252
318
|
function runHook(io, run) {
|
|
@@ -268,6 +334,7 @@ function withCarnet$1(payload, io, use) {
|
|
|
268
334
|
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
269
335
|
if (!carnet.workspace && !known) return;
|
|
270
336
|
use(carnet);
|
|
337
|
+
if (payload.session_id) refreshStatusLine(carnet, payload.session_id, io.env);
|
|
271
338
|
} finally {
|
|
272
339
|
carnet.close();
|
|
273
340
|
}
|
|
@@ -286,13 +353,17 @@ function sessionStart(stdinText, io) {
|
|
|
286
353
|
RUCHER_SESSION_NAME: io.env.RUCHER_SESSION_NAME,
|
|
287
354
|
RUCHER_PROMPT_VERSION: io.env.RUCHER_PROMPT_VERSION,
|
|
288
355
|
RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
|
|
289
|
-
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
|
|
290
358
|
});
|
|
291
359
|
for (const notice of notices) io.stderr(`${notice}\n`);
|
|
292
|
-
|
|
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) {
|
|
293
364
|
const hookSpecificOutput = {
|
|
294
365
|
hookEventName: "SessionStart",
|
|
295
|
-
additionalContext
|
|
366
|
+
additionalContext: context
|
|
296
367
|
};
|
|
297
368
|
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
298
369
|
}
|
|
@@ -303,7 +374,7 @@ function subagentStart(stdinText, io) {
|
|
|
303
374
|
return runHook(io, () => {
|
|
304
375
|
const payload = host.parseSubagentPayload(stdinText);
|
|
305
376
|
withCarnet$1(payload, io, (carnet) => {
|
|
306
|
-
carnet.agents.pairSubagent(payload.session_id, payload.agent_id);
|
|
377
|
+
carnet.agents.pairSubagent(payload.session_id, payload.agent_id, host.subagentNames(payload));
|
|
307
378
|
});
|
|
308
379
|
if (host.subagentInheritsContext(payload)) return;
|
|
309
380
|
const hookSpecificOutput = {
|
|
@@ -325,7 +396,7 @@ function userPromptSubmit(stdinText, io) {
|
|
|
325
396
|
return runHook(io, () => {
|
|
326
397
|
const payload = host.parsePromptPayload(stdinText);
|
|
327
398
|
withCarnet$1(payload, io, (carnet) => {
|
|
328
|
-
handleUserPromptSubmit(carnet, host, payload);
|
|
399
|
+
handleUserPromptSubmit(carnet, host, payload, { trackTurn: installedPlugin(io.env).endsTurns });
|
|
329
400
|
});
|
|
330
401
|
});
|
|
331
402
|
}
|
|
@@ -337,7 +408,7 @@ function postToolUse(stdinText, io) {
|
|
|
337
408
|
const additionalContext = handleToolUse(carnet, payload, {
|
|
338
409
|
RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
|
|
339
410
|
RUCHER_MEMORY_HALF_LIFE_DAYS: io.env.RUCHER_MEMORY_HALF_LIFE_DAYS
|
|
340
|
-
});
|
|
411
|
+
}, { trackTurn: installedPlugin(io.env).endsTurns });
|
|
341
412
|
if (!additionalContext) return;
|
|
342
413
|
const hookSpecificOutput = {
|
|
343
414
|
hookEventName: "PostToolUse",
|
|
@@ -359,21 +430,24 @@ function scratchRoot(io) {
|
|
|
359
430
|
const uid = process.getuid?.() ?? 0;
|
|
360
431
|
return join(io.env.CLAUDE_CODE_TMPDIR ?? tmpdir(), `claude-${uid}`);
|
|
361
432
|
}
|
|
433
|
+
function denyToolCall(io, reason) {
|
|
434
|
+
const hookSpecificOutput = {
|
|
435
|
+
hookEventName: "PreToolUse",
|
|
436
|
+
permissionDecision: "deny",
|
|
437
|
+
permissionDecisionReason: reason
|
|
438
|
+
};
|
|
439
|
+
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
440
|
+
}
|
|
362
441
|
function preToolUse(stdinText, io) {
|
|
363
442
|
return runHook(io, () => {
|
|
364
443
|
const payload = host.parseToolPayload(stdinText);
|
|
365
|
-
const
|
|
366
|
-
|
|
444
|
+
const tool = payload.tool_name ?? "";
|
|
445
|
+
const guarded = Boolean(payload.agent_id) && GUARDED_TOOLS.has(tool);
|
|
446
|
+
const launch = !payload.agent_id && LAUNCH_TOOLS.has(tool);
|
|
447
|
+
if (!guarded && !launch && (payload.agent_id || tool !== WAITING_TOOL)) return;
|
|
367
448
|
withCarnet$1(payload, io, (carnet) => {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (!reason) return;
|
|
371
|
-
const hookSpecificOutput = {
|
|
372
|
-
hookEventName: "PreToolUse",
|
|
373
|
-
permissionDecision: "deny",
|
|
374
|
-
permissionDecisionReason: reason
|
|
375
|
-
};
|
|
376
|
-
io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
|
|
449
|
+
const reason = guarded ? guardSubagentCall(carnet, payload, scratchRoot(io)) : launch ? guardMainLaunch(carnet, payload) : handleToolStart(carnet, payload);
|
|
450
|
+
if (reason) denyToolCall(io, reason);
|
|
377
451
|
});
|
|
378
452
|
});
|
|
379
453
|
}
|
|
@@ -435,7 +509,7 @@ function formatEvents(events, io, kinds = /* @__PURE__ */ new Map()) {
|
|
|
435
509
|
return [
|
|
436
510
|
colors.dim(formatClock(new Date(event.at))),
|
|
437
511
|
colors.bold(event.type.padEnd(9)),
|
|
438
|
-
kind ?
|
|
512
|
+
kind ? colors.dim(kindTag(kind)) : "",
|
|
439
513
|
event.agent ?? "",
|
|
440
514
|
event.link ?? event.note ?? "",
|
|
441
515
|
event.commit ? colors.cyan(event.commit.slice(0, 7)) : ""
|
|
@@ -851,7 +925,8 @@ function serve(io) {
|
|
|
851
925
|
serveCarnet({
|
|
852
926
|
cwd: io.cwd,
|
|
853
927
|
env: io.env,
|
|
854
|
-
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
928
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env),
|
|
929
|
+
afterTool: (carnet, sessionId) => refreshStatusLine(carnet, sessionId, io.env)
|
|
855
930
|
});
|
|
856
931
|
}
|
|
857
932
|
// src/commands/sessions.ts
|
|
@@ -903,13 +978,14 @@ function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
|
903
978
|
const from = findSession(carnet, fromReference);
|
|
904
979
|
const into = findSession(carnet, intoReference);
|
|
905
980
|
const result = carnet.sessions.merge(from.id, into.id);
|
|
981
|
+
for (const session of [from, into]) refreshStatusLine(carnet, session.id, io.env);
|
|
906
982
|
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
907
983
|
const lines = [
|
|
908
984
|
`merged ${label(from)} into ${label(result.session)}`,
|
|
909
985
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
910
986
|
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
911
987
|
` events moved: ${result.movedEvents}`,
|
|
912
|
-
`
|
|
988
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`
|
|
913
989
|
];
|
|
914
990
|
io.stdout(`${lines.join("\n")}\n`);
|
|
915
991
|
}
|
|
@@ -930,7 +1006,7 @@ function sessionsMove(carnet, reference, workspaceReference, io, options = {}) {
|
|
|
930
1006
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
931
1007
|
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
932
1008
|
` events moved: ${result.movedEvents}`,
|
|
933
|
-
`
|
|
1009
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
934
1010
|
...result.keptNotes ? [` notes kept in ${workspaceLabel(carnet.workspace)}: ${result.keptNotes}`] : []
|
|
935
1011
|
];
|
|
936
1012
|
io.stdout(`${lines.join("\n")}\n`);
|
|
@@ -1001,6 +1077,62 @@ function sessionsClean(carnet, io, options = {}) {
|
|
|
1001
1077
|
if (options.purge) purgeTranscripts(session, io);
|
|
1002
1078
|
}
|
|
1003
1079
|
}
|
|
1080
|
+
// src/commands/fit.ts
|
|
1081
|
+
function charWidth(char) {
|
|
1082
|
+
const code = char.codePointAt(0) ?? 0;
|
|
1083
|
+
if (code === 65039 || code === 8205) return 0;
|
|
1084
|
+
return code >= 126976 || code >= 8960 && code <= 10175 || code >= 11008 && code <= 11263 ? 2 : 1;
|
|
1085
|
+
}
|
|
1086
|
+
function displayWidth(text) {
|
|
1087
|
+
return Array.from(stripVTControlCharacters(text)).reduce((width, char) => width + charWidth(char), 0);
|
|
1088
|
+
}
|
|
1089
|
+
function wrapLegend(legend, columns) {
|
|
1090
|
+
const lines = [];
|
|
1091
|
+
let line = "";
|
|
1092
|
+
for (const item of legend.split(" · ")) {
|
|
1093
|
+
const next = line ? `${line} · ${item}` : item;
|
|
1094
|
+
if (line && displayWidth(next) > columns) {
|
|
1095
|
+
lines.push(line);
|
|
1096
|
+
line = item;
|
|
1097
|
+
} else line = next;
|
|
1098
|
+
}
|
|
1099
|
+
if (line) lines.push(line);
|
|
1100
|
+
return lines;
|
|
1101
|
+
}
|
|
1102
|
+
function sectionName(header) {
|
|
1103
|
+
return stripVTControlCharacters(header).replace(/ {2}.*$/, "");
|
|
1104
|
+
}
|
|
1105
|
+
function splitSections(body) {
|
|
1106
|
+
const sections = [[]];
|
|
1107
|
+
for (const line of body) if (line === "") sections.push([]);
|
|
1108
|
+
else sections.at(-1)?.push(line);
|
|
1109
|
+
return sections.filter((section) => section.length > 0);
|
|
1110
|
+
}
|
|
1111
|
+
function fitToRows({ head, body, bottom, rows, cutOrder, more }) {
|
|
1112
|
+
const room = rows - bottom.length - 1;
|
|
1113
|
+
if (room < 1) return bottom.slice(-rows);
|
|
1114
|
+
const sections = splitSections(body);
|
|
1115
|
+
const content = () => [...head, ...sections.flatMap((section, index) => index ? ["", ...section] : section)];
|
|
1116
|
+
for (const name of cutOrder) {
|
|
1117
|
+
const overflow = content().length - room;
|
|
1118
|
+
if (overflow <= 0) break;
|
|
1119
|
+
const section = sections.find((candidate) => sectionName(candidate[0] ?? "") === name);
|
|
1120
|
+
if (!section || section.length <= 2) continue;
|
|
1121
|
+
const items = section.length - 1;
|
|
1122
|
+
const keep = Math.max(items - overflow - 1, 0);
|
|
1123
|
+
section.splice(1 + keep, items - keep, more(items - keep));
|
|
1124
|
+
}
|
|
1125
|
+
let lines = content();
|
|
1126
|
+
if (lines.length > room) {
|
|
1127
|
+
const kept = lines.slice(0, room - 1);
|
|
1128
|
+
lines = [...kept, more(lines.length - kept.length)];
|
|
1129
|
+
}
|
|
1130
|
+
return [
|
|
1131
|
+
...lines,
|
|
1132
|
+
...Array(rows - bottom.length - lines.length).fill(""),
|
|
1133
|
+
...bottom
|
|
1134
|
+
];
|
|
1135
|
+
}
|
|
1004
1136
|
// src/commands/watch-keys.ts
|
|
1005
1137
|
const INITIAL_WATCH_STATE = {
|
|
1006
1138
|
notesOpen: false,
|
|
@@ -1111,9 +1243,11 @@ function pressKey(state, key, noteCount) {
|
|
|
1111
1243
|
const SECTION_HEADERS = /* @__PURE__ */ new Set([
|
|
1112
1244
|
MAIN_HEADER,
|
|
1113
1245
|
"Waiting on you",
|
|
1246
|
+
BLOCKED_HEADER,
|
|
1114
1247
|
"Running",
|
|
1115
1248
|
NOTES_HEADER
|
|
1116
1249
|
]);
|
|
1250
|
+
const AGENT_LINE = new RegExp(`^ {2}(?:\\d+\\. )?\\S+ ${KIND_TAG_PATTERN.source} `);
|
|
1117
1251
|
function truncate(line, columns) {
|
|
1118
1252
|
const chars = Array.from(line);
|
|
1119
1253
|
return chars.length > columns ? `${chars.slice(0, Math.max(columns - 1, 1)).join("")}…` : line;
|
|
@@ -1125,7 +1259,7 @@ function colorizeLine(line, io) {
|
|
|
1125
1259
|
if (SECTION_HEADERS.has(line)) return colors.bold(cut);
|
|
1126
1260
|
if (line.startsWith(" ⚠")) return colors.red(cut);
|
|
1127
1261
|
if (line.startsWith(" ⚙️") || line.startsWith(" ⏸")) return colors.yellow(cut);
|
|
1128
|
-
if (line === " nothing") return colors.dim(cut);
|
|
1262
|
+
if (line === " nothing" || line === ` ${MAIN_IDLE}`) return colors.dim(cut);
|
|
1129
1263
|
if (cut.startsWith(`${NOTES_HEADER} `)) return `${colors.bold(NOTES_HEADER)}${cut.slice(NOTES_HEADER.length)}`;
|
|
1130
1264
|
const marker = /^ {2}\+ #\d+ +\S+ {2}(similar to [^·]*·)/.exec(cut);
|
|
1131
1265
|
if (marker?.[1]) {
|
|
@@ -1133,6 +1267,7 @@ function colorizeLine(line, io) {
|
|
|
1133
1267
|
const end = start + marker[1].length;
|
|
1134
1268
|
return `${cut.slice(0, start)}${colors.yellow(cut.slice(start, end))}${cut.slice(end)}`;
|
|
1135
1269
|
}
|
|
1270
|
+
if (AGENT_LINE.test(cut)) return cut.replace(KIND_TAG_PATTERN, (tag) => colors.dim(tag));
|
|
1136
1271
|
return cut;
|
|
1137
1272
|
}
|
|
1138
1273
|
function sessionName(session) {
|
|
@@ -1191,7 +1326,42 @@ function hasSomethingToShow(carnet, session) {
|
|
|
1191
1326
|
function sessionBlock(session, view, io) {
|
|
1192
1327
|
return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
|
|
1193
1328
|
}
|
|
1194
|
-
|
|
1329
|
+
const CUT_ORDER = [
|
|
1330
|
+
"Notes",
|
|
1331
|
+
"Running",
|
|
1332
|
+
"Waiting on agents",
|
|
1333
|
+
"Waiting on you"
|
|
1334
|
+
];
|
|
1335
|
+
const NOTES_OPEN_CUT_ORDER = [
|
|
1336
|
+
"Running",
|
|
1337
|
+
"Waiting on agents",
|
|
1338
|
+
"Waiting on you",
|
|
1339
|
+
"Notes"
|
|
1340
|
+
];
|
|
1341
|
+
function legendLines(io, fit) {
|
|
1342
|
+
const colors = paint(io);
|
|
1343
|
+
const legend = fit ? wrapLegend(LEGEND, io.columns) : [LEGEND];
|
|
1344
|
+
return [colors.dim(truncate(KIND_LEGEND, io.columns)), ...legend.map((line) => colors.dim(line))];
|
|
1345
|
+
}
|
|
1346
|
+
function layout(io, rows, parts) {
|
|
1347
|
+
if (rows === void 0) return [
|
|
1348
|
+
...parts.head,
|
|
1349
|
+
...parts.body,
|
|
1350
|
+
"",
|
|
1351
|
+
...parts.footer,
|
|
1352
|
+
...legendLines(io, false)
|
|
1353
|
+
].join("\n");
|
|
1354
|
+
const colors = paint(io);
|
|
1355
|
+
return fitToRows({
|
|
1356
|
+
head: parts.head,
|
|
1357
|
+
body: parts.body,
|
|
1358
|
+
bottom: [...parts.footer, ...legendLines(io, true)],
|
|
1359
|
+
rows,
|
|
1360
|
+
cutOrder: parts.cutOrder,
|
|
1361
|
+
more: (count) => colors.dim(` … ${count} more`)
|
|
1362
|
+
}).join("\n");
|
|
1363
|
+
}
|
|
1364
|
+
function singleView(carnet, session, io, kind, state, rows) {
|
|
1195
1365
|
const colors = paint(io);
|
|
1196
1366
|
const view = carnet.status.view(session, { kind });
|
|
1197
1367
|
const separator = " - ";
|
|
@@ -1199,19 +1369,21 @@ function singleView(carnet, session, io, kind, state) {
|
|
|
1199
1369
|
const title = `${colors.dim(view.time)}${separator}${colors.cyan(label)}`;
|
|
1200
1370
|
const body = state ? interactiveLines(carnet, session, view, io, state) : sessionLines(session, view, io);
|
|
1201
1371
|
const footer = footerLine(view, io, state);
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1372
|
+
const lag = pluginLagNotice(session.pluginVersion);
|
|
1373
|
+
return layout(io, rows, {
|
|
1374
|
+
head: [
|
|
1375
|
+
title,
|
|
1376
|
+
...lag ? [colors.yellow(truncate(lag, io.columns))] : [],
|
|
1377
|
+
""
|
|
1378
|
+
],
|
|
1379
|
+
body,
|
|
1380
|
+
footer: footer ? [footer] : [],
|
|
1381
|
+
cutOrder: state?.notesOpen ? NOTES_OPEN_CUT_ORDER : CUT_ORDER
|
|
1382
|
+
});
|
|
1211
1383
|
}
|
|
1212
1384
|
function renderStatusView(carnet, io, options) {
|
|
1213
1385
|
const sessions = options.all ? carnet.sessions.list({ includeTemp: true }).filter((session) => hasSomethingToShow(carnet, session)) : [];
|
|
1214
|
-
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.kind, options.interaction);
|
|
1386
|
+
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.kind, options.interaction, options.rows);
|
|
1215
1387
|
let time = "";
|
|
1216
1388
|
const blocks = sessions.map((session) => {
|
|
1217
1389
|
const view = carnet.status.view(session, { kind: options.kind });
|
|
@@ -1221,14 +1393,13 @@ function renderStatusView(carnet, io, options) {
|
|
|
1221
1393
|
const colors = paint(io);
|
|
1222
1394
|
const separator = " - ";
|
|
1223
1395
|
const workspace = truncate(workspaceLabel(carnet.workspace), io.columns - time.length - 3);
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
"",
|
|
1227
|
-
blocks.join("\n\n"),
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
].join("\n");
|
|
1396
|
+
const title = `${colors.dim(time)}${separator}${colors.cyan(workspace)}`;
|
|
1397
|
+
return layout(io, options.rows, {
|
|
1398
|
+
head: [title, ""],
|
|
1399
|
+
body: blocks.join("\n\n").split("\n"),
|
|
1400
|
+
footer: [],
|
|
1401
|
+
cutOrder: []
|
|
1402
|
+
});
|
|
1232
1403
|
}
|
|
1233
1404
|
function statusOnce(carnet, io, options) {
|
|
1234
1405
|
io.stdout(`${renderStatusView(carnet, io, options)}\n`);
|
|
@@ -1267,23 +1438,26 @@ function statusWatch(carnet, io, options) {
|
|
|
1267
1438
|
try {
|
|
1268
1439
|
text = renderStatusView(carnet, io, {
|
|
1269
1440
|
...options,
|
|
1270
|
-
interaction: interactive ? state : void 0
|
|
1441
|
+
interaction: interactive ? state : void 0,
|
|
1442
|
+
rows: io.rows
|
|
1271
1443
|
});
|
|
1272
1444
|
} catch (error) {
|
|
1273
1445
|
text = paint(io).dim(error instanceof Error ? error.message : String(error));
|
|
1274
1446
|
}
|
|
1275
1447
|
if (text === last) return;
|
|
1276
1448
|
last = text;
|
|
1277
|
-
io.stdout(`${CLEAR}${text}\n`);
|
|
1449
|
+
io.stdout(`${CLEAR}${text}${io.rows === void 0 ? "\n" : ""}`);
|
|
1278
1450
|
};
|
|
1279
1451
|
const timer = setInterval(() => {
|
|
1280
1452
|
if (state.reason === null) repaint();
|
|
1281
1453
|
}, options.intervalMilliseconds);
|
|
1454
|
+
const offResize = options.onResize?.(repaint);
|
|
1282
1455
|
let stopped = false;
|
|
1283
1456
|
const stop = () => {
|
|
1284
1457
|
if (stopped) return;
|
|
1285
1458
|
stopped = true;
|
|
1286
1459
|
clearInterval(timer);
|
|
1460
|
+
offResize?.();
|
|
1287
1461
|
options.keys?.close();
|
|
1288
1462
|
io.stdout(SHOW_CURSOR);
|
|
1289
1463
|
resolve();
|
|
@@ -1303,6 +1477,23 @@ function statusWatch(carnet, io, options) {
|
|
|
1303
1477
|
repaint();
|
|
1304
1478
|
});
|
|
1305
1479
|
}
|
|
1480
|
+
// src/commands/statusline.ts
|
|
1481
|
+
function statusLineDirectory(io) {
|
|
1482
|
+
io.stdout(`${dirname(statusLinePath("session", io.env))}\n`);
|
|
1483
|
+
return 0;
|
|
1484
|
+
}
|
|
1485
|
+
function statusLine(stdinText, io) {
|
|
1486
|
+
let sessionId;
|
|
1487
|
+
try {
|
|
1488
|
+
sessionId = JSON.parse(stdinText).session_id;
|
|
1489
|
+
} catch {
|
|
1490
|
+
return 0;
|
|
1491
|
+
}
|
|
1492
|
+
if (typeof sessionId !== "string" || !/^[\w-]+$/.test(sessionId)) return 0;
|
|
1493
|
+
const line = labelStatusLine(readStatusLine(sessionId, io.env));
|
|
1494
|
+
if (line) io.stdout(`${line}\n`);
|
|
1495
|
+
return 0;
|
|
1496
|
+
}
|
|
1306
1497
|
// src/workspace-option.ts
|
|
1307
1498
|
const workspaceArgument = { ws: {
|
|
1308
1499
|
type: "string",
|
|
@@ -1515,6 +1706,7 @@ function workspaceDrop(name, io, options = {}) {
|
|
|
1515
1706
|
refuseLive(carnet, "drop", options.isAlive ?? processIsAlive);
|
|
1516
1707
|
const at = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
1517
1708
|
const archived = archiveWorkspaceSessions(carnet.db, name, at);
|
|
1709
|
+
carnet.releaseClosedSandboxes();
|
|
1518
1710
|
const deletedNotes = options.purge ? deleteWorkspaceNotes(carnet.db, name) : 0;
|
|
1519
1711
|
const workspace = dropWorkspace(name, {
|
|
1520
1712
|
purge: options.purge,
|
|
@@ -1556,7 +1748,12 @@ function processIo(options = {}) {
|
|
|
1556
1748
|
cwd: process.cwd(),
|
|
1557
1749
|
env: process.env,
|
|
1558
1750
|
color: tty && colorWanted && !process.env.NO_COLOR,
|
|
1559
|
-
|
|
1751
|
+
get columns() {
|
|
1752
|
+
return process.stdout.columns ?? 80;
|
|
1753
|
+
},
|
|
1754
|
+
get rows() {
|
|
1755
|
+
return tty ? process.stdout.rows : void 0;
|
|
1756
|
+
}
|
|
1560
1757
|
};
|
|
1561
1758
|
}
|
|
1562
1759
|
function readStdin() {
|
|
@@ -1676,7 +1873,11 @@ const statusCommand = defineCommand({
|
|
|
1676
1873
|
...options,
|
|
1677
1874
|
intervalMilliseconds,
|
|
1678
1875
|
signal: controller.signal,
|
|
1679
|
-
keys: terminalKeys(process.stdin, process.stdout)
|
|
1876
|
+
keys: terminalKeys(process.stdin, process.stdout),
|
|
1877
|
+
onResize: (listener) => {
|
|
1878
|
+
process.stdout.on("resize", listener);
|
|
1879
|
+
return () => process.stdout.off("resize", listener);
|
|
1880
|
+
}
|
|
1680
1881
|
});
|
|
1681
1882
|
} catch (error) {
|
|
1682
1883
|
fail(io, error);
|
|
@@ -1753,7 +1954,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1753
1954
|
const sessionsMergeCommand = defineCommand({
|
|
1754
1955
|
meta: {
|
|
1755
1956
|
name: "merge",
|
|
1756
|
-
description: "Move the agents,
|
|
1957
|
+
description: "Move the agents, Main line and journal of one session into another, then drop it"
|
|
1757
1958
|
},
|
|
1758
1959
|
args: {
|
|
1759
1960
|
from: {
|
|
@@ -1864,7 +2065,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1864
2065
|
const sessionsMoveCommand = defineCommand({
|
|
1865
2066
|
meta: {
|
|
1866
2067
|
name: "move",
|
|
1867
|
-
description: "Move a session, its agents,
|
|
2068
|
+
description: "Move a session, its agents, Main line and journal to another workspace"
|
|
1868
2069
|
},
|
|
1869
2070
|
args: {
|
|
1870
2071
|
session: sessionReference,
|
|
@@ -2513,6 +2714,23 @@ const hookCommand = defineCommand({
|
|
|
2513
2714
|
})
|
|
2514
2715
|
}
|
|
2515
2716
|
});
|
|
2717
|
+
const statusLineCommand = defineCommand({
|
|
2718
|
+
meta: {
|
|
2719
|
+
name: "statusline",
|
|
2720
|
+
description: "Print the session's one-line status for a Claude Code statusLine command (JSON on stdin)"
|
|
2721
|
+
},
|
|
2722
|
+
args: { dir: {
|
|
2723
|
+
type: "boolean",
|
|
2724
|
+
description: "Print the folder of the status line files instead (for the plugin mod)"
|
|
2725
|
+
} },
|
|
2726
|
+
async run({ args }) {
|
|
2727
|
+
if (args.dir) {
|
|
2728
|
+
process.exitCode = statusLineDirectory(processIo());
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
process.exitCode = statusLine(await readStdin(), processIo());
|
|
2732
|
+
}
|
|
2733
|
+
});
|
|
2516
2734
|
const serveCommand = defineCommand({
|
|
2517
2735
|
meta: {
|
|
2518
2736
|
name: "serve",
|
|
@@ -2539,6 +2757,7 @@ const main = defineCommand({
|
|
|
2539
2757
|
notes: notesCommand,
|
|
2540
2758
|
ws: wsCommand,
|
|
2541
2759
|
hook: hookCommand,
|
|
2760
|
+
statusline: statusLineCommand,
|
|
2542
2761
|
serve: serveCommand
|
|
2543
2762
|
}
|
|
2544
2763
|
});
|
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.9",
|
|
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.9",
|
|
39
39
|
"citty": "^0.2.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|