@rucher/cli 0.2.0-beta.7 → 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 +253 -38
- 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, 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
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.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
|
+
}
|
|
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
|
}
|
|
@@ -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",
|
|
@@ -435,7 +506,7 @@ function formatEvents(events, io, kinds = /* @__PURE__ */ new Map()) {
|
|
|
435
506
|
return [
|
|
436
507
|
colors.dim(formatClock(new Date(event.at))),
|
|
437
508
|
colors.bold(event.type.padEnd(9)),
|
|
438
|
-
kind ?
|
|
509
|
+
kind ? colors.dim(kindTag(kind)) : "",
|
|
439
510
|
event.agent ?? "",
|
|
440
511
|
event.link ?? event.note ?? "",
|
|
441
512
|
event.commit ? colors.cyan(event.commit.slice(0, 7)) : ""
|
|
@@ -851,7 +922,8 @@ function serve(io) {
|
|
|
851
922
|
serveCarnet({
|
|
852
923
|
cwd: io.cwd,
|
|
853
924
|
env: io.env,
|
|
854
|
-
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
925
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env),
|
|
926
|
+
afterTool: (carnet, sessionId) => refreshStatusLine(carnet, sessionId, io.env)
|
|
855
927
|
});
|
|
856
928
|
}
|
|
857
929
|
// src/commands/sessions.ts
|
|
@@ -903,13 +975,14 @@ function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
|
903
975
|
const from = findSession(carnet, fromReference);
|
|
904
976
|
const into = findSession(carnet, intoReference);
|
|
905
977
|
const result = carnet.sessions.merge(from.id, into.id);
|
|
978
|
+
for (const session of [from, into]) refreshStatusLine(carnet, session.id, io.env);
|
|
906
979
|
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
907
980
|
const lines = [
|
|
908
981
|
`merged ${label(from)} into ${label(result.session)}`,
|
|
909
982
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
910
983
|
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
911
984
|
` events moved: ${result.movedEvents}`,
|
|
912
|
-
`
|
|
985
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`
|
|
913
986
|
];
|
|
914
987
|
io.stdout(`${lines.join("\n")}\n`);
|
|
915
988
|
}
|
|
@@ -930,7 +1003,7 @@ function sessionsMove(carnet, reference, workspaceReference, io, options = {}) {
|
|
|
930
1003
|
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
931
1004
|
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
932
1005
|
` events moved: ${result.movedEvents}`,
|
|
933
|
-
`
|
|
1006
|
+
` Main line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
934
1007
|
...result.keptNotes ? [` notes kept in ${workspaceLabel(carnet.workspace)}: ${result.keptNotes}`] : []
|
|
935
1008
|
];
|
|
936
1009
|
io.stdout(`${lines.join("\n")}\n`);
|
|
@@ -1001,6 +1074,62 @@ function sessionsClean(carnet, io, options = {}) {
|
|
|
1001
1074
|
if (options.purge) purgeTranscripts(session, io);
|
|
1002
1075
|
}
|
|
1003
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
|
+
}
|
|
1004
1133
|
// src/commands/watch-keys.ts
|
|
1005
1134
|
const INITIAL_WATCH_STATE = {
|
|
1006
1135
|
notesOpen: false,
|
|
@@ -1111,9 +1240,11 @@ function pressKey(state, key, noteCount) {
|
|
|
1111
1240
|
const SECTION_HEADERS = /* @__PURE__ */ new Set([
|
|
1112
1241
|
MAIN_HEADER,
|
|
1113
1242
|
"Waiting on you",
|
|
1243
|
+
BLOCKED_HEADER,
|
|
1114
1244
|
"Running",
|
|
1115
1245
|
NOTES_HEADER
|
|
1116
1246
|
]);
|
|
1247
|
+
const AGENT_LINE = new RegExp(`^ {2}(?:\\d+\\. )?\\S+ ${KIND_TAG_PATTERN.source} `);
|
|
1117
1248
|
function truncate(line, columns) {
|
|
1118
1249
|
const chars = Array.from(line);
|
|
1119
1250
|
return chars.length > columns ? `${chars.slice(0, Math.max(columns - 1, 1)).join("")}…` : line;
|
|
@@ -1125,7 +1256,7 @@ function colorizeLine(line, io) {
|
|
|
1125
1256
|
if (SECTION_HEADERS.has(line)) return colors.bold(cut);
|
|
1126
1257
|
if (line.startsWith(" ⚠")) return colors.red(cut);
|
|
1127
1258
|
if (line.startsWith(" ⚙️") || line.startsWith(" ⏸")) return colors.yellow(cut);
|
|
1128
|
-
if (line === " nothing") return colors.dim(cut);
|
|
1259
|
+
if (line === " nothing" || line === ` ${MAIN_IDLE}`) return colors.dim(cut);
|
|
1129
1260
|
if (cut.startsWith(`${NOTES_HEADER} `)) return `${colors.bold(NOTES_HEADER)}${cut.slice(NOTES_HEADER.length)}`;
|
|
1130
1261
|
const marker = /^ {2}\+ #\d+ +\S+ {2}(similar to [^·]*·)/.exec(cut);
|
|
1131
1262
|
if (marker?.[1]) {
|
|
@@ -1133,6 +1264,7 @@ function colorizeLine(line, io) {
|
|
|
1133
1264
|
const end = start + marker[1].length;
|
|
1134
1265
|
return `${cut.slice(0, start)}${colors.yellow(cut.slice(start, end))}${cut.slice(end)}`;
|
|
1135
1266
|
}
|
|
1267
|
+
if (AGENT_LINE.test(cut)) return cut.replace(KIND_TAG_PATTERN, (tag) => colors.dim(tag));
|
|
1136
1268
|
return cut;
|
|
1137
1269
|
}
|
|
1138
1270
|
function sessionName(session) {
|
|
@@ -1191,7 +1323,42 @@ function hasSomethingToShow(carnet, session) {
|
|
|
1191
1323
|
function sessionBlock(session, view, io) {
|
|
1192
1324
|
return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
|
|
1193
1325
|
}
|
|
1194
|
-
|
|
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) {
|
|
1195
1362
|
const colors = paint(io);
|
|
1196
1363
|
const view = carnet.status.view(session, { kind });
|
|
1197
1364
|
const separator = " - ";
|
|
@@ -1199,19 +1366,21 @@ function singleView(carnet, session, io, kind, state) {
|
|
|
1199
1366
|
const title = `${colors.dim(view.time)}${separator}${colors.cyan(label)}`;
|
|
1200
1367
|
const body = state ? interactiveLines(carnet, session, view, io, state) : sessionLines(session, view, io);
|
|
1201
1368
|
const footer = footerLine(view, io, state);
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
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
|
+
});
|
|
1211
1380
|
}
|
|
1212
1381
|
function renderStatusView(carnet, io, options) {
|
|
1213
1382
|
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);
|
|
1383
|
+
if (sessions.length === 0) return singleView(carnet, resolveSession(carnet, options.session), io, options.kind, options.interaction, options.rows);
|
|
1215
1384
|
let time = "";
|
|
1216
1385
|
const blocks = sessions.map((session) => {
|
|
1217
1386
|
const view = carnet.status.view(session, { kind: options.kind });
|
|
@@ -1221,14 +1390,13 @@ function renderStatusView(carnet, io, options) {
|
|
|
1221
1390
|
const colors = paint(io);
|
|
1222
1391
|
const separator = " - ";
|
|
1223
1392
|
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");
|
|
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
|
+
});
|
|
1232
1400
|
}
|
|
1233
1401
|
function statusOnce(carnet, io, options) {
|
|
1234
1402
|
io.stdout(`${renderStatusView(carnet, io, options)}\n`);
|
|
@@ -1267,23 +1435,26 @@ function statusWatch(carnet, io, options) {
|
|
|
1267
1435
|
try {
|
|
1268
1436
|
text = renderStatusView(carnet, io, {
|
|
1269
1437
|
...options,
|
|
1270
|
-
interaction: interactive ? state : void 0
|
|
1438
|
+
interaction: interactive ? state : void 0,
|
|
1439
|
+
rows: io.rows
|
|
1271
1440
|
});
|
|
1272
1441
|
} catch (error) {
|
|
1273
1442
|
text = paint(io).dim(error instanceof Error ? error.message : String(error));
|
|
1274
1443
|
}
|
|
1275
1444
|
if (text === last) return;
|
|
1276
1445
|
last = text;
|
|
1277
|
-
io.stdout(`${CLEAR}${text}\n`);
|
|
1446
|
+
io.stdout(`${CLEAR}${text}${io.rows === void 0 ? "\n" : ""}`);
|
|
1278
1447
|
};
|
|
1279
1448
|
const timer = setInterval(() => {
|
|
1280
1449
|
if (state.reason === null) repaint();
|
|
1281
1450
|
}, options.intervalMilliseconds);
|
|
1451
|
+
const offResize = options.onResize?.(repaint);
|
|
1282
1452
|
let stopped = false;
|
|
1283
1453
|
const stop = () => {
|
|
1284
1454
|
if (stopped) return;
|
|
1285
1455
|
stopped = true;
|
|
1286
1456
|
clearInterval(timer);
|
|
1457
|
+
offResize?.();
|
|
1287
1458
|
options.keys?.close();
|
|
1288
1459
|
io.stdout(SHOW_CURSOR);
|
|
1289
1460
|
resolve();
|
|
@@ -1303,6 +1474,23 @@ function statusWatch(carnet, io, options) {
|
|
|
1303
1474
|
repaint();
|
|
1304
1475
|
});
|
|
1305
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
|
+
}
|
|
1306
1494
|
// src/workspace-option.ts
|
|
1307
1495
|
const workspaceArgument = { ws: {
|
|
1308
1496
|
type: "string",
|
|
@@ -1556,7 +1744,12 @@ function processIo(options = {}) {
|
|
|
1556
1744
|
cwd: process.cwd(),
|
|
1557
1745
|
env: process.env,
|
|
1558
1746
|
color: tty && colorWanted && !process.env.NO_COLOR,
|
|
1559
|
-
|
|
1747
|
+
get columns() {
|
|
1748
|
+
return process.stdout.columns ?? 80;
|
|
1749
|
+
},
|
|
1750
|
+
get rows() {
|
|
1751
|
+
return tty ? process.stdout.rows : void 0;
|
|
1752
|
+
}
|
|
1560
1753
|
};
|
|
1561
1754
|
}
|
|
1562
1755
|
function readStdin() {
|
|
@@ -1676,7 +1869,11 @@ const statusCommand = defineCommand({
|
|
|
1676
1869
|
...options,
|
|
1677
1870
|
intervalMilliseconds,
|
|
1678
1871
|
signal: controller.signal,
|
|
1679
|
-
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
|
+
}
|
|
1680
1877
|
});
|
|
1681
1878
|
} catch (error) {
|
|
1682
1879
|
fail(io, error);
|
|
@@ -1753,7 +1950,7 @@ const sessionsListCommand = defineCommand({
|
|
|
1753
1950
|
const sessionsMergeCommand = defineCommand({
|
|
1754
1951
|
meta: {
|
|
1755
1952
|
name: "merge",
|
|
1756
|
-
description: "Move the agents,
|
|
1953
|
+
description: "Move the agents, Main line and journal of one session into another, then drop it"
|
|
1757
1954
|
},
|
|
1758
1955
|
args: {
|
|
1759
1956
|
from: {
|
|
@@ -1864,7 +2061,7 @@ const sessionsDropCommand = defineCommand({
|
|
|
1864
2061
|
const sessionsMoveCommand = defineCommand({
|
|
1865
2062
|
meta: {
|
|
1866
2063
|
name: "move",
|
|
1867
|
-
description: "Move a session, its agents,
|
|
2064
|
+
description: "Move a session, its agents, Main line and journal to another workspace"
|
|
1868
2065
|
},
|
|
1869
2066
|
args: {
|
|
1870
2067
|
session: sessionReference,
|
|
@@ -2513,6 +2710,23 @@ const hookCommand = defineCommand({
|
|
|
2513
2710
|
})
|
|
2514
2711
|
}
|
|
2515
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
|
+
});
|
|
2516
2730
|
const serveCommand = defineCommand({
|
|
2517
2731
|
meta: {
|
|
2518
2732
|
name: "serve",
|
|
@@ -2539,6 +2753,7 @@ const main = defineCommand({
|
|
|
2539
2753
|
notes: notesCommand,
|
|
2540
2754
|
ws: wsCommand,
|
|
2541
2755
|
hook: hookCommand,
|
|
2756
|
+
statusline: statusLineCommand,
|
|
2542
2757
|
serve: serveCommand
|
|
2543
2758
|
}
|
|
2544
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": {
|