@rucher/cli 0.2.0-beta.0 → 0.2.0-beta.2

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +235 -156
  2. package/package.json +2 -2
package/dist/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineCommand, runMain } from "citty";
3
3
  import { existsSync, readdirSync, rmSync } 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, addGroupRepo, appendPromptFile, claudeCode, formatClock, groupRepoNames, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById, initGroup, isGroupRoot, locateGroup, memoryHalfLife, openCarnet, readRegistry, removeGroupRepo, renderSections, repoNameFor, repoPathFor, shortId, unregisterGroups } from "@rucher/carnet";
6
+ import { CarnetError, LEGEND, NOTES_HEADER, NOTE_KINDS, SIMILAR_PREFIX, SUBAGENT_RULES, addGroupRepo, ambiguousGroupContext, appendPromptFile, claudeCode, formatClock, groupRepoNames, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById, initGroup, isGroupRoot, loadGroup, locateGroup, memoryHalfLife, moveSession, openCarnet, openGroupCarnet, readRegistry, removeGroupRepo, renderSections, repoNameFor, repoPathFor, shortId, unregisterGroups } from "@rucher/carnet";
7
7
  import { styleText } from "node:util";
8
8
  import { spawnSync } from "node:child_process";
9
9
  import { randomUUID } from "node:crypto";
@@ -98,6 +98,10 @@ const completionConfig = { subCommands: {
98
98
  from: sessions,
99
99
  into: sessions
100
100
  } },
101
+ move: {
102
+ args: { session: sessions },
103
+ options: { to: groups }
104
+ },
101
105
  rename: { args: { session: sessions } },
102
106
  promote: { args: { session: sessions } },
103
107
  demote: { args: { session: sessions } },
@@ -144,7 +148,7 @@ async function setupCompletion(main) {
144
148
  };
145
149
  }
146
150
  // package.json
147
- var version = "0.2.0-beta.0";
151
+ var version = "0.2.0-beta.2";
148
152
  // src/color.ts
149
153
  function paint(io) {
150
154
  const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
@@ -300,19 +304,31 @@ function groupsPrune(io) {
300
304
  }
301
305
  // src/commands/hook.ts
302
306
  const host = claudeCode;
303
- function runHook(io, run) {
307
+ function runHook(io, run, hookEventName) {
304
308
  try {
305
309
  run();
306
310
  } catch (error) {
307
311
  if (error instanceof CarnetError && error.code === "NO_GROUP") return 0;
312
+ if (error instanceof CarnetError && error.code === "GROUP_AMBIGUOUS") {
313
+ if (hookEventName) {
314
+ io.stderr(`rucher: ${error.message}\n`);
315
+ const additionalContext = ambiguousGroupContext(error.message);
316
+ io.stdout(`${JSON.stringify({ hookSpecificOutput: {
317
+ hookEventName,
318
+ additionalContext
319
+ } })}\n`);
320
+ }
321
+ return 0;
322
+ }
308
323
  io.stderr(`rucher hook: ${error instanceof Error ? error.message : String(error)}\n`);
309
324
  }
310
325
  return 0;
311
326
  }
312
- function withCarnet$1(cwd, io, use) {
327
+ function withCarnet$1(payload, io, use) {
313
328
  const carnet = openCarnet({
314
- cwd: cwd ?? io.cwd,
315
- env: io.env
329
+ cwd: payload.cwd ?? io.cwd,
330
+ env: io.env,
331
+ sessionId: payload.session_id
316
332
  });
317
333
  try {
318
334
  use(carnet);
@@ -323,7 +339,7 @@ function withCarnet$1(cwd, io, use) {
323
339
  function sessionStart(stdinText, io) {
324
340
  return runHook(io, () => {
325
341
  const payload = host.parseSessionPayload(stdinText);
326
- withCarnet$1(payload.cwd, io, (carnet) => {
342
+ withCarnet$1(payload, io, (carnet) => {
327
343
  const { additionalContext, notices } = handleSessionStart(carnet, payload, {
328
344
  host: host.id,
329
345
  processId: host.processId(io.env),
@@ -345,12 +361,12 @@ function sessionStart(stdinText, io) {
345
361
  io.stdout(`${JSON.stringify({ hookSpecificOutput })}\n`);
346
362
  }
347
363
  });
348
- });
364
+ }, "SessionStart");
349
365
  }
350
366
  function subagentStart(stdinText, io) {
351
367
  return runHook(io, () => {
352
368
  const payload = host.parseSubagentPayload(stdinText);
353
- withCarnet$1(payload.cwd, io, (carnet) => {
369
+ withCarnet$1(payload, io, (carnet) => {
354
370
  carnet.agents.pairSubagent(payload.session_id, payload.agent_id);
355
371
  });
356
372
  if (host.subagentInheritsContext(payload)) return;
@@ -364,7 +380,7 @@ function subagentStart(stdinText, io) {
364
380
  function subagentStop(stdinText, io) {
365
381
  return runHook(io, () => {
366
382
  const payload = host.parseSubagentPayload(stdinText);
367
- withCarnet$1(payload.cwd, io, (carnet) => {
383
+ withCarnet$1(payload, io, (carnet) => {
368
384
  carnet.agents.stopSubagent(payload.session_id, payload.agent_id, host.subagentNames(payload));
369
385
  });
370
386
  });
@@ -372,16 +388,16 @@ function subagentStop(stdinText, io) {
372
388
  function userPromptSubmit(stdinText, io) {
373
389
  return runHook(io, () => {
374
390
  const payload = host.parsePromptPayload(stdinText);
375
- withCarnet$1(payload.cwd, io, (carnet) => {
391
+ withCarnet$1(payload, io, (carnet) => {
376
392
  handleUserPromptSubmit(carnet, host, payload);
377
393
  });
378
- });
394
+ }, "UserPromptSubmit");
379
395
  }
380
396
  function postToolUse(stdinText, io) {
381
397
  return runHook(io, () => {
382
398
  const payload = host.parseToolPayload(stdinText);
383
399
  if (payload.agent_id || !payload.path) return;
384
- withCarnet$1(payload.cwd, io, (carnet) => {
400
+ withCarnet$1(payload, io, (carnet) => {
385
401
  const additionalContext = handleToolUse(carnet, payload, {
386
402
  RUCHER_MEMORY_MAX_CHARACTERS: io.env.RUCHER_MEMORY_MAX_CHARACTERS,
387
403
  RUCHER_MEMORY_HALF_LIFE_DAYS: io.env.RUCHER_MEMORY_HALF_LIFE_DAYS
@@ -398,7 +414,7 @@ function postToolUse(stdinText, io) {
398
414
  function sessionEnd(stdinText, io) {
399
415
  return runHook(io, () => {
400
416
  const payload = host.parseSessionEndPayload(stdinText);
401
- withCarnet$1(payload.cwd, io, (carnet) => {
417
+ withCarnet$1(payload, io, (carnet) => {
402
418
  handleSessionEnd(carnet, payload);
403
419
  });
404
420
  });
@@ -618,6 +634,7 @@ function launchEnv(carnet, session, promptVersion, kind) {
618
634
  RUCHER_PROMPT_VERSION: promptVersion,
619
635
  RUCHER_SESSION_NAME: session.name ?? "",
620
636
  RUCHER_GROUP: carnet.group.name,
637
+ RUCHER_GROUP_ROOT: carnet.group.root,
621
638
  ...kind ? { RUCHER_SESSION_KIND: kind } : {}
622
639
  };
623
640
  }
@@ -776,8 +793,165 @@ async function pickSession(carnet) {
776
793
  function serve(io) {
777
794
  serveCarnet({
778
795
  cwd: io.cwd,
779
- env: io.env
796
+ env: io.env,
797
+ sessionId: claudeCode.sessionIdFromEnvironment(io.env)
798
+ });
799
+ }
800
+ // src/commands/sessions.ts
801
+ function lastActive(at, now) {
802
+ const date = new Date(at);
803
+ return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
804
+ }
805
+ function row(carnet, session, now) {
806
+ const open = carnet.agents.list(session.id).length;
807
+ return [
808
+ session.name ?? session.id.slice(0, 8),
809
+ session.kind,
810
+ session.status,
811
+ repoPathFor(carnet.group, session.cwd) ?? session.repo ?? "",
812
+ lastActive(session.lastActiveAt, now),
813
+ open ? `${open} agent${open > 1 ? "s" : ""}` : "",
814
+ session.purpose ?? ""
815
+ ];
816
+ }
817
+ function sessionsOnce(carnet, io, options = {}) {
818
+ const colors = paint(io);
819
+ const sessions = carnet.sessions.list({
820
+ includeTemp: options.all,
821
+ includeArchived: options.all
822
+ });
823
+ if (sessions.length === 0) {
824
+ const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
825
+ io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
826
+ return;
827
+ }
828
+ const now = options.now ?? /* @__PURE__ */ new Date();
829
+ const rows = sessions.map((session) => ({
830
+ session,
831
+ cells: row(carnet, session, now)
832
+ }));
833
+ const widths = rows.reduce((current, { cells }) => cells.map((cell, column) => Math.max(current[column] ?? 0, cell.length)), []);
834
+ const lines = rows.map(({ session, cells }) => {
835
+ return cells.map((cell, column) => {
836
+ const padded = column < cells.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell;
837
+ if (column === 0) return colors.bold(padded);
838
+ if (column === 1 && session.kind === "temp") return colors.dim(padded);
839
+ if (column === 2 && session.status === "archived") return colors.dim(padded);
840
+ return padded;
841
+ }).join(" ").trimEnd();
780
842
  });
843
+ io.stdout(`${lines.join("\n")}\n`);
844
+ }
845
+ function sessionsMerge(carnet, fromReference, intoReference, io) {
846
+ const from = findSession(carnet, fromReference);
847
+ const into = findSession(carnet, intoReference);
848
+ const result = carnet.sessions.merge(from.id, into.id);
849
+ const label = (session) => session.name ?? session.id.slice(0, 8);
850
+ const lines = [
851
+ `merged ${label(from)} into ${label(result.session)}`,
852
+ ` agents moved: ${result.movedAgents.join(", ") || "none"}`,
853
+ ...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
854
+ ` events moved: ${result.movedEvents}`,
855
+ ` table line moved: ${result.movedTable ? "yes" : "no"}`
856
+ ];
857
+ io.stdout(`${lines.join("\n")}\n`);
858
+ }
859
+ function label(session) {
860
+ return session.name ?? shortId(session.id);
861
+ }
862
+ function groupNamed(reference, io) {
863
+ const groups = readRegistry(io.env).filter((group) => isGroupRoot(group.path));
864
+ const byPath = groups.filter((group) => group.path === resolve(io.cwd, reference));
865
+ const matches = byPath.length ? byPath : groups.filter((group) => group.name === reference);
866
+ const [match] = matches;
867
+ if (!match) throw new CliError(`No registered group named "${reference}"`, "see rucher groups");
868
+ if (matches.length > 1) throw new CliError(`Several groups are named "${reference}"`, "pass the group path");
869
+ return loadGroup(match.path);
870
+ }
871
+ function sessionsMove(carnet, reference, groupReference, io, options = {}) {
872
+ const session = findSession(carnet, reference);
873
+ const target = openGroupCarnet(groupNamed(groupReference, io));
874
+ try {
875
+ const result = moveSession(carnet, session.id, target, options);
876
+ const into = result.into ? ` into ${label(result.into)}` : "";
877
+ const lines = [
878
+ `${options.dryRun ? "would move" : "moved"} ${label(session)} from ${carnet.group.name} to ${target.group.name}${into}`,
879
+ ` agents moved: ${result.movedAgents.join(", ") || "none"}`,
880
+ ...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
881
+ ` events moved: ${result.movedEvents}`,
882
+ ` table line moved: ${result.movedTable ? "yes" : "no"}`,
883
+ ...result.unlinkedNotes ? [` notes kept in ${carnet.group.name}, unlinked from the session: ${result.unlinkedNotes}`] : []
884
+ ];
885
+ io.stdout(`${lines.join("\n")}\n`);
886
+ } finally {
887
+ target.close();
888
+ }
889
+ }
890
+ function sessionsRename(carnet, reference, name, io) {
891
+ const session = carnet.sessions.rename(findSession(carnet, reference).id, name);
892
+ io.stdout(`renamed to ${session.name}; rucher resume ${session.name} gives Claude the same title\n`);
893
+ }
894
+ function sessionsPromote(carnet, reference, name, io) {
895
+ const session = carnet.sessions.promote(findSession(carnet, reference).id, name);
896
+ io.stdout(`${label(session)} is now active\n`);
897
+ }
898
+ function sessionsDemote(carnet, reference, io) {
899
+ const session = carnet.sessions.demote(findSession(carnet, reference).id);
900
+ io.stdout(`${label(session)} is now temp, cleaned by rucher sessions clean once idle\n`);
901
+ }
902
+ function purgeTranscripts(session, io) {
903
+ const files = hostById(session.host).transcriptFiles(session, io.env);
904
+ for (const file of files) {
905
+ rmSync(file, {
906
+ recursive: true,
907
+ force: true
908
+ });
909
+ io.stdout(` deleted ${file}\n`);
910
+ }
911
+ if (files.length === 0) io.stdout(" no transcript found\n");
912
+ }
913
+ function sessionsDrop(carnet, reference, io, options = {}) {
914
+ const session = findSession(carnet, reference);
915
+ if (options.purge && session.status === "running") throw new CliError(`Session ${label(session)} is running`, "drop it with --purge once it has ended");
916
+ carnet.sessions.drop(session.id);
917
+ io.stdout(`archived ${label(session)}\n`);
918
+ if (options.purge) purgeTranscripts(session, io);
919
+ }
920
+ const UNIT_MILLISECONDS = {
921
+ m: 6e4,
922
+ h: 36e5,
923
+ d: 864e5
924
+ };
925
+ function parseDuration(value) {
926
+ const match = /^(\d+(?:\.\d+)?)([mhd]?)$/.exec(value.trim());
927
+ if (!match) throw new CliError(`Invalid duration "${value}"`, "use a number of days, or 30m, 12h, 7d");
928
+ return Number(match[1]) * (UNIT_MILLISECONDS[match[2] || "d"] ?? 0);
929
+ }
930
+ function processIsAlive(processId) {
931
+ try {
932
+ process.kill(processId, 0);
933
+ return true;
934
+ } catch (error) {
935
+ return error.code === "EPERM";
936
+ }
937
+ }
938
+ function sessionsClean(carnet, io, options = {}) {
939
+ const olderThan = parseDuration(options.olderThan ?? "7d");
940
+ if (!options.dryRun) for (const session of carnet.sessions.resetDead(options.isAlive ?? processIsAlive)) io.stdout(`${label(session)} was marked running but its process is gone: now idle\n`);
941
+ const stale = carnet.sessions.staleTemp(olderThan);
942
+ if (stale.length === 0) {
943
+ io.stdout(`no temp session idle for more than ${options.olderThan ?? "7d"}\n`);
944
+ return;
945
+ }
946
+ for (const session of stale) {
947
+ if (options.dryRun) {
948
+ io.stdout(`would archive ${label(session)}${options.purge ? " and delete its transcript" : ""}\n`);
949
+ continue;
950
+ }
951
+ carnet.sessions.drop(session.id);
952
+ io.stdout(`archived ${label(session)}\n`);
953
+ if (options.purge) purgeTranscripts(session, io);
954
+ }
781
955
  }
782
956
  // src/commands/watch-keys.ts
783
957
  const INITIAL_WATCH_STATE = {
@@ -912,18 +1086,16 @@ function colorizeLine(line, io) {
912
1086
  }
913
1087
  return cut;
914
1088
  }
915
- function sessionWhere(carnet, session) {
916
- return repoPathFor(carnet.group, session.cwd) ?? session.repo;
1089
+ function sessionName(session) {
1090
+ return session.name ?? session.id.slice(0, 8);
917
1091
  }
918
1092
  function sessionLabel(carnet, session, columns) {
919
- const name = session.name ?? session.id.slice(0, 8);
920
- const where = sessionWhere(carnet, session);
921
- if (!where) return name;
1093
+ const name = sessionName(session);
922
1094
  const room = columns - Array.from(name).length - 3;
923
- return room > 1 ? `${name} · ${truncate(where, room)}` : name;
1095
+ return room > 1 ? `${name} · ${truncate(carnet.group.name, room)}` : name;
924
1096
  }
925
- function sessionHeader(carnet, session, io) {
926
- return paint(io).cyan(sessionLabel(carnet, session, io.columns));
1097
+ function sessionHeader(session, io) {
1098
+ return paint(io).cyan(truncate(sessionName(session), io.columns));
927
1099
  }
928
1100
  function sessionLines(session, view, io, notes = "full") {
929
1101
  if (session.status === "archived") return [paint(io).dim(" archived, see rucher sessions --all")];
@@ -967,8 +1139,8 @@ function footerLine(view, io, state) {
967
1139
  function hasSomethingToShow(carnet, session) {
968
1140
  return carnet.agents.list(session.id).length > 0 || carnet.table.get(session.id) !== void 0 || carnet.notes.activity(session.id).length > 0;
969
1141
  }
970
- function sessionBlock(carnet, session, view, io) {
971
- return [sessionHeader(carnet, session, io), ...sessionLines(session, view, io, "summary")].join("\n");
1142
+ function sessionBlock(session, view, io) {
1143
+ return [sessionHeader(session, io), ...sessionLines(session, view, io, "summary")].join("\n");
972
1144
  }
973
1145
  function singleView(carnet, session, io, state) {
974
1146
  const colors = paint(io);
@@ -994,14 +1166,17 @@ function renderStatusView(carnet, io, options) {
994
1166
  const blocks = sessions.map((session) => {
995
1167
  const view = carnet.status.view(session);
996
1168
  time ||= view.time;
997
- return sessionBlock(carnet, session, view, io);
1169
+ return sessionBlock(session, view, io);
998
1170
  });
1171
+ const colors = paint(io);
1172
+ const separator = " - ";
1173
+ const group = truncate(carnet.group.name, io.columns - time.length - 3);
999
1174
  return [
1000
- paint(io).dim(time),
1175
+ `${colors.dim(time)}${separator}${colors.cyan(group)}`,
1001
1176
  "",
1002
1177
  blocks.join("\n\n"),
1003
1178
  "",
1004
- paint(io).dim(LEGEND)
1179
+ colors.dim(LEGEND)
1005
1180
  ].join("\n");
1006
1181
  }
1007
1182
  function statusOnce(carnet, io, options) {
@@ -1077,134 +1252,6 @@ function statusWatch(carnet, io, options) {
1077
1252
  repaint();
1078
1253
  });
1079
1254
  }
1080
- // src/commands/sessions.ts
1081
- function lastActive(at, now) {
1082
- const date = new Date(at);
1083
- return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
1084
- }
1085
- function row(carnet, session, now) {
1086
- const open = carnet.agents.list(session.id).length;
1087
- return [
1088
- session.name ?? session.id.slice(0, 8),
1089
- session.kind,
1090
- session.status,
1091
- sessionWhere(carnet, session) ?? "",
1092
- lastActive(session.lastActiveAt, now),
1093
- open ? `${open} agent${open > 1 ? "s" : ""}` : "",
1094
- session.purpose ?? ""
1095
- ];
1096
- }
1097
- function sessionsOnce(carnet, io, options = {}) {
1098
- const colors = paint(io);
1099
- const sessions = carnet.sessions.list({
1100
- includeTemp: options.all,
1101
- includeArchived: options.all
1102
- });
1103
- if (sessions.length === 0) {
1104
- const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
1105
- io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
1106
- return;
1107
- }
1108
- const now = options.now ?? /* @__PURE__ */ new Date();
1109
- const rows = sessions.map((session) => ({
1110
- session,
1111
- cells: row(carnet, session, now)
1112
- }));
1113
- const widths = rows.reduce((current, { cells }) => cells.map((cell, column) => Math.max(current[column] ?? 0, cell.length)), []);
1114
- const lines = rows.map(({ session, cells }) => {
1115
- return cells.map((cell, column) => {
1116
- const padded = column < cells.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell;
1117
- if (column === 0) return colors.bold(padded);
1118
- if (column === 1 && session.kind === "temp") return colors.dim(padded);
1119
- if (column === 2 && session.status === "archived") return colors.dim(padded);
1120
- return padded;
1121
- }).join(" ").trimEnd();
1122
- });
1123
- io.stdout(`${lines.join("\n")}\n`);
1124
- }
1125
- function sessionsMerge(carnet, fromReference, intoReference, io) {
1126
- const from = findSession(carnet, fromReference);
1127
- const into = findSession(carnet, intoReference);
1128
- const result = carnet.sessions.merge(from.id, into.id);
1129
- const label = (session) => session.name ?? session.id.slice(0, 8);
1130
- const lines = [
1131
- `merged ${label(from)} into ${label(result.session)}`,
1132
- ` agents moved: ${result.movedAgents.join(", ") || "none"}`,
1133
- ...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
1134
- ` events moved: ${result.movedEvents}`,
1135
- ` table line moved: ${result.movedTable ? "yes" : "no"}`
1136
- ];
1137
- io.stdout(`${lines.join("\n")}\n`);
1138
- }
1139
- function label(session) {
1140
- return session.name ?? shortId(session.id);
1141
- }
1142
- function sessionsRename(carnet, reference, name, io) {
1143
- const session = carnet.sessions.rename(findSession(carnet, reference).id, name);
1144
- io.stdout(`renamed to ${session.name}; rucher resume ${session.name} gives Claude the same title\n`);
1145
- }
1146
- function sessionsPromote(carnet, reference, name, io) {
1147
- const session = carnet.sessions.promote(findSession(carnet, reference).id, name);
1148
- io.stdout(`${label(session)} is now active\n`);
1149
- }
1150
- function sessionsDemote(carnet, reference, io) {
1151
- const session = carnet.sessions.demote(findSession(carnet, reference).id);
1152
- io.stdout(`${label(session)} is now temp, cleaned by rucher sessions clean once idle\n`);
1153
- }
1154
- function purgeTranscripts(session, io) {
1155
- const files = hostById(session.host).transcriptFiles(session, io.env);
1156
- for (const file of files) {
1157
- rmSync(file, {
1158
- recursive: true,
1159
- force: true
1160
- });
1161
- io.stdout(` deleted ${file}\n`);
1162
- }
1163
- if (files.length === 0) io.stdout(" no transcript found\n");
1164
- }
1165
- function sessionsDrop(carnet, reference, io, options = {}) {
1166
- const session = findSession(carnet, reference);
1167
- if (options.purge && session.status === "running") throw new CliError(`Session ${label(session)} is running`, "drop it with --purge once it has ended");
1168
- carnet.sessions.drop(session.id);
1169
- io.stdout(`archived ${label(session)}\n`);
1170
- if (options.purge) purgeTranscripts(session, io);
1171
- }
1172
- const UNIT_MILLISECONDS = {
1173
- m: 6e4,
1174
- h: 36e5,
1175
- d: 864e5
1176
- };
1177
- function parseDuration(value) {
1178
- const match = /^(\d+(?:\.\d+)?)([mhd]?)$/.exec(value.trim());
1179
- if (!match) throw new CliError(`Invalid duration "${value}"`, "use a number of days, or 30m, 12h, 7d");
1180
- return Number(match[1]) * (UNIT_MILLISECONDS[match[2] || "d"] ?? 0);
1181
- }
1182
- function processIsAlive(processId) {
1183
- try {
1184
- process.kill(processId, 0);
1185
- return true;
1186
- } catch (error) {
1187
- return error.code === "EPERM";
1188
- }
1189
- }
1190
- function sessionsClean(carnet, io, options = {}) {
1191
- const olderThan = parseDuration(options.olderThan ?? "7d");
1192
- if (!options.dryRun) for (const session of carnet.sessions.resetDead(options.isAlive ?? processIsAlive)) io.stdout(`${label(session)} was marked running but its process is gone: now idle\n`);
1193
- const stale = carnet.sessions.staleTemp(olderThan);
1194
- if (stale.length === 0) {
1195
- io.stdout(`no temp session idle for more than ${options.olderThan ?? "7d"}\n`);
1196
- return;
1197
- }
1198
- for (const session of stale) {
1199
- if (options.dryRun) {
1200
- io.stdout(`would archive ${label(session)}${options.purge ? " and delete its transcript" : ""}\n`);
1201
- continue;
1202
- }
1203
- carnet.sessions.drop(session.id);
1204
- io.stdout(`archived ${label(session)}\n`);
1205
- if (options.purge) purgeTranscripts(session, io);
1206
- }
1207
- }
1208
1255
  // src/io.ts
1209
1256
  function processIo(options = {}) {
1210
1257
  const tty = process.stdout.isTTY === true;
@@ -1525,6 +1572,37 @@ const sessionsDropCommand = defineCommand({
1525
1572
  withCarnet(io, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
1526
1573
  }
1527
1574
  });
1575
+ const sessionsMoveCommand = defineCommand({
1576
+ meta: {
1577
+ name: "move",
1578
+ description: "Move a session, its agents, table line and journal to another group"
1579
+ },
1580
+ args: {
1581
+ session: sessionReference,
1582
+ to: {
1583
+ type: "string",
1584
+ required: true,
1585
+ description: "Target group (name or path)"
1586
+ },
1587
+ merge: {
1588
+ type: "boolean",
1589
+ default: false,
1590
+ description: "Merge into the session the target group already has under this id or name"
1591
+ },
1592
+ "dry-run": {
1593
+ type: "boolean",
1594
+ default: false,
1595
+ description: "Show what would move"
1596
+ }
1597
+ },
1598
+ run({ args }) {
1599
+ const io = processIo();
1600
+ withCarnet(io, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
1601
+ merge: args.merge,
1602
+ dryRun: args["dry-run"]
1603
+ }));
1604
+ }
1605
+ });
1528
1606
  const sessionsCleanCommand = defineCommand({
1529
1607
  meta: {
1530
1608
  name: "clean",
@@ -1561,6 +1639,7 @@ const sessionsCommand = defineCommand({
1561
1639
  subCommands: {
1562
1640
  list: sessionsListCommand,
1563
1641
  merge: sessionsMergeCommand,
1642
+ move: sessionsMoveCommand,
1564
1643
  rename: sessionsRenameCommand,
1565
1644
  promote: sessionsPromoteCommand,
1566
1645
  demote: sessionsDemoteCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rucher/cli",
3
- "version": "0.2.0-beta.0",
3
+ "version": "0.2.0-beta.2",
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.0",
38
+ "@rucher/carnet": "0.2.0-beta.2",
39
39
  "citty": "^0.2.2"
40
40
  },
41
41
  "devDependencies": {