@rucher/cli 0.2.0-beta.1 → 0.2.0-beta.3
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 +3 -2
- package/dist/cli.mjs +810 -553
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
|
-
import { existsSync, readdirSync, rmSync } from "node:fs";
|
|
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, addGroupRepo, ambiguousGroupContext, appendPromptFile, claudeCode, formatClock, groupRepoNames, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById,
|
|
7
|
-
import { styleText } from "node:util";
|
|
6
|
+
import { CarnetError, GROUP_FILE, INSTRUCTIONS_FILE, LEGEND, NOTES_HEADER, NOTE_KINDS, SIMILAR_PREFIX, SUBAGENT_RULES, addGroupRepo, ambiguousGroupContext, appendPromptFile, archiveGroupSessions, claudeCode, createGroup, deleteGroupNotes, dropGroup, formatClock, groupExists, groupLabel, groupRepoNames, groupSessionCounts, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById, isGroupName, listGroups, loadGroup, memoryHalfLife, moveSession, openCarnet, openGroupCarnet, openResolvedCarnet, removeGroupRepo, renameGroup, renameGroupRows, renderSections, renderWorkspace, repoNameFor, repoPathFor, requireGroup, resolveGroup, shortId } from "@rucher/carnet";
|
|
8
7
|
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { styleText } from "node:util";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { createInterface } from "node:readline/promises";
|
|
11
11
|
import { serveCarnet } from "@rucher/carnet/mcp";
|
|
@@ -37,18 +37,18 @@ function suggestSessions(context, complete) {
|
|
|
37
37
|
}
|
|
38
38
|
function suggestGroups(context, complete) {
|
|
39
39
|
quietly(() => {
|
|
40
|
-
const
|
|
41
|
-
for (const group of groups) complete(groups.filter((other) => other.name === group.name).length > 1 ? group.path : group.name, group.path);
|
|
40
|
+
for (const group of listGroups(context.env)) complete(group.name, group.workspace);
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
function suggestRepos(context, complete) {
|
|
45
44
|
quietly(() => {
|
|
46
|
-
for (const repo of
|
|
45
|
+
for (const repo of resolveGroup(context).group?.repos ?? []) complete(repo.path, repo.name);
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
function suggestRepoNames(context, complete) {
|
|
50
49
|
quietly(() => {
|
|
51
|
-
|
|
50
|
+
const { group } = resolveGroup(context);
|
|
51
|
+
for (const repo of group ? groupRepoNames(group) : []) complete(repo, "");
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
function suggestNoteKinds(complete) {
|
|
@@ -87,51 +87,112 @@ const directories = (complete) => suggestDirectories(processContext(), complete)
|
|
|
87
87
|
const repoNames = (complete) => suggestRepoNames(processContext(), complete);
|
|
88
88
|
const noteKinds = (complete) => suggestNoteKinds(complete);
|
|
89
89
|
const notes = (complete) => suggestNotes(processContext(), complete);
|
|
90
|
+
const group = { group: groups };
|
|
90
91
|
const completionConfig = { subCommands: {
|
|
91
|
-
status: { options: {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
from: sessions,
|
|
99
|
-
into: sessions
|
|
100
|
-
} },
|
|
101
|
-
move: {
|
|
102
|
-
args: { session: sessions },
|
|
103
|
-
options: { to: groups }
|
|
104
|
-
},
|
|
105
|
-
rename: { args: { session: sessions } },
|
|
106
|
-
promote: { args: { session: sessions } },
|
|
107
|
-
demote: { args: { session: sessions } },
|
|
108
|
-
drop: { args: { session: sessions } }
|
|
92
|
+
status: { options: {
|
|
93
|
+
session: sessions,
|
|
94
|
+
...group
|
|
95
|
+
} },
|
|
96
|
+
log: { options: {
|
|
97
|
+
session: sessions,
|
|
98
|
+
...group
|
|
109
99
|
} },
|
|
100
|
+
new: { options: group },
|
|
101
|
+
tmp: { options: group },
|
|
102
|
+
resume: {
|
|
103
|
+
args: { session: sessions },
|
|
104
|
+
options: group
|
|
105
|
+
},
|
|
106
|
+
fork: {
|
|
107
|
+
args: { session: sessions },
|
|
108
|
+
options: group
|
|
109
|
+
},
|
|
110
|
+
sessions: {
|
|
111
|
+
options: group,
|
|
112
|
+
subCommands: {
|
|
113
|
+
list: { options: group },
|
|
114
|
+
merge: {
|
|
115
|
+
args: {
|
|
116
|
+
from: sessions,
|
|
117
|
+
into: sessions
|
|
118
|
+
},
|
|
119
|
+
options: group
|
|
120
|
+
},
|
|
121
|
+
move: {
|
|
122
|
+
args: { session: sessions },
|
|
123
|
+
options: {
|
|
124
|
+
to: groups,
|
|
125
|
+
...group
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
rename: {
|
|
129
|
+
args: { session: sessions },
|
|
130
|
+
options: group
|
|
131
|
+
},
|
|
132
|
+
promote: {
|
|
133
|
+
args: { session: sessions },
|
|
134
|
+
options: group
|
|
135
|
+
},
|
|
136
|
+
demote: {
|
|
137
|
+
args: { session: sessions },
|
|
138
|
+
options: group
|
|
139
|
+
},
|
|
140
|
+
drop: {
|
|
141
|
+
args: { session: sessions },
|
|
142
|
+
options: group
|
|
143
|
+
},
|
|
144
|
+
clean: { options: group }
|
|
145
|
+
}
|
|
146
|
+
},
|
|
110
147
|
notes: {
|
|
111
148
|
options: {
|
|
112
149
|
kind: noteKinds,
|
|
113
|
-
repo: repoNames
|
|
150
|
+
repo: repoNames,
|
|
151
|
+
...group
|
|
114
152
|
},
|
|
115
153
|
subCommands: {
|
|
116
154
|
list: { options: {
|
|
117
155
|
kind: noteKinds,
|
|
118
|
-
repo: repoNames
|
|
156
|
+
repo: repoNames,
|
|
157
|
+
...group
|
|
119
158
|
} },
|
|
120
|
-
show: {
|
|
159
|
+
show: {
|
|
160
|
+
args: { id: notes },
|
|
161
|
+
options: group
|
|
162
|
+
},
|
|
121
163
|
add: {
|
|
122
164
|
args: { kind: noteKinds },
|
|
123
|
-
options: {
|
|
165
|
+
options: {
|
|
166
|
+
repo: repoNames,
|
|
167
|
+
...group
|
|
168
|
+
}
|
|
124
169
|
},
|
|
125
170
|
drop: {
|
|
126
171
|
args: { id: notes },
|
|
127
|
-
options: {
|
|
172
|
+
options: {
|
|
173
|
+
"replaced-by": notes,
|
|
174
|
+
...group
|
|
175
|
+
}
|
|
128
176
|
}
|
|
129
177
|
}
|
|
130
178
|
},
|
|
131
|
-
groups: { subCommands: { forget: { args: { reference: groups } } } },
|
|
132
179
|
group: { subCommands: {
|
|
133
|
-
|
|
134
|
-
|
|
180
|
+
show: { options: group },
|
|
181
|
+
add: {
|
|
182
|
+
args: { path: directories },
|
|
183
|
+
options: group
|
|
184
|
+
},
|
|
185
|
+
remove: {
|
|
186
|
+
args: { path: repos },
|
|
187
|
+
options: group
|
|
188
|
+
},
|
|
189
|
+
sync: { options: group },
|
|
190
|
+
edit: { options: group },
|
|
191
|
+
path: { options: group }
|
|
192
|
+
} },
|
|
193
|
+
groups: { subCommands: {
|
|
194
|
+
rename: { args: { from: groups } },
|
|
195
|
+
drop: { args: { name: groups } }
|
|
135
196
|
} }
|
|
136
197
|
} };
|
|
137
198
|
async function setupCompletion(main) {
|
|
@@ -148,7 +209,7 @@ async function setupCompletion(main) {
|
|
|
148
209
|
};
|
|
149
210
|
}
|
|
150
211
|
// package.json
|
|
151
|
-
var version = "0.2.0-beta.
|
|
212
|
+
var version = "0.2.0-beta.3";
|
|
152
213
|
// src/color.ts
|
|
153
214
|
function paint(io) {
|
|
154
215
|
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
@@ -160,61 +221,37 @@ function paint(io) {
|
|
|
160
221
|
cyan: style("cyan")
|
|
161
222
|
};
|
|
162
223
|
}
|
|
163
|
-
// src/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
let group;
|
|
174
|
-
try {
|
|
175
|
-
group = initGroup(root, {
|
|
176
|
-
name: options.name,
|
|
177
|
-
repos: options.repos?.map((repo) => resolve(io.cwd, repo)),
|
|
178
|
-
env: io.env
|
|
179
|
-
});
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (error instanceof CarnetError) {
|
|
182
|
-
io.stderr(`error: ${error.message}\n`);
|
|
183
|
-
return 1;
|
|
184
|
-
}
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
const lines = [
|
|
188
|
-
`${colors.bold(group.name)} initialised in ${group.root}`,
|
|
189
|
-
` repos: ${group.repos.length ? group.repos.join(", ") : "none yet, add them with `rucher group add <path>`"}`,
|
|
190
|
-
` database: ${group.dbPath}`
|
|
191
|
-
];
|
|
192
|
-
for (const { path, result } of syncContextFiles(group, "merge")) {
|
|
193
|
-
if (result === "unchanged") continue;
|
|
194
|
-
lines.push(result === "no-markers" ? ` kept existing ${path} ${colors.dim("(add the rucher:repos markers to keep its repo list in sync, and a line: multi-agent work uses the rucher tools)")}` : ` ${result} ${path}`);
|
|
195
|
-
}
|
|
196
|
-
const hosts = group.hosts.map((id) => hostById(id).displayName).join(" or ");
|
|
197
|
-
lines.push("", `Next: start ${hosts} in this directory, then \`rucher status --watch\` in a side pane.`);
|
|
198
|
-
io.stdout(`${lines.join("\n")}\n`);
|
|
199
|
-
return 0;
|
|
224
|
+
// src/group-option.ts
|
|
225
|
+
const groupArgument = { group: {
|
|
226
|
+
type: "string",
|
|
227
|
+
alias: "g",
|
|
228
|
+
description: "Group name (default: from RUCHER_GROUP, the workspace or the repo you are in)"
|
|
229
|
+
} };
|
|
230
|
+
function announceGroup(io, resolution) {
|
|
231
|
+
if (!resolution.group) return;
|
|
232
|
+
if (resolution.origin === "workspace") io.stderr(`group ${resolution.group.name} (from its workspace)\n`);
|
|
233
|
+
else if (resolution.origin === "repo" && resolution.repo) io.stderr(`group ${resolution.group.name} (from ${resolution.repo.name})\n`);
|
|
200
234
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const colors = paint(io);
|
|
204
|
-
const group = locateGroup({
|
|
235
|
+
function openCliCarnet(io, group) {
|
|
236
|
+
const { carnet, resolution } = openResolvedCarnet({
|
|
205
237
|
cwd: io.cwd,
|
|
206
|
-
env: io.env
|
|
238
|
+
env: io.env,
|
|
239
|
+
group
|
|
207
240
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return 0;
|
|
211
|
-
}
|
|
212
|
-
function syncNotes(group, mode) {
|
|
213
|
-
return syncContextFiles(group, mode).filter(({ result }) => result !== "unchanged").map(({ path, result }) => result === "no-markers" ? `${path} has no rucher:repos markers, update its repo list yourself` : `${result} ${path}`);
|
|
241
|
+
announceGroup(io, resolution);
|
|
242
|
+
return carnet;
|
|
214
243
|
}
|
|
215
|
-
function
|
|
216
|
-
|
|
244
|
+
function currentGroup(io, group) {
|
|
245
|
+
const resolution = resolveGroup({
|
|
246
|
+
cwd: io.cwd,
|
|
247
|
+
env: io.env,
|
|
248
|
+
group
|
|
249
|
+
});
|
|
250
|
+
const found = requireGroup(resolution.group);
|
|
251
|
+
announceGroup(io, resolution);
|
|
252
|
+
return found;
|
|
217
253
|
}
|
|
254
|
+
// src/commands/group.ts
|
|
218
255
|
function carnetErrors(io, run) {
|
|
219
256
|
try {
|
|
220
257
|
return run();
|
|
@@ -226,81 +263,377 @@ function carnetErrors(io, run) {
|
|
|
226
263
|
throw error;
|
|
227
264
|
}
|
|
228
265
|
}
|
|
229
|
-
function
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
266
|
+
function rendered(group, io) {
|
|
267
|
+
const result = renderWorkspace(group, { env: io.env });
|
|
268
|
+
return [...result.written.map((path) => `written ${path}`), ...result.removed.map((path) => `removed ${path}`)];
|
|
269
|
+
}
|
|
270
|
+
function withChanges(line, changes) {
|
|
271
|
+
return `${line}${changes.length ? ` (${changes.join(", ")})` : ""}\n`;
|
|
272
|
+
}
|
|
273
|
+
function groupShow(io, options = {}) {
|
|
274
|
+
return carnetErrors(io, () => {
|
|
275
|
+
const colors = paint(io);
|
|
276
|
+
const group = currentGroup(io, options.group);
|
|
277
|
+
const repos = group.repos.length ? group.repos.map((repo) => ` ${repo.name} ${colors.dim(repo.path)}`).join("\n") : ` ${colors.dim("none")}`;
|
|
278
|
+
io.stdout(`${colors.bold(group.name)}\nsource: ${group.source}\nworkspace: ${group.workspace}\nrepos:\n${repos}\n`);
|
|
279
|
+
return 0;
|
|
233
280
|
});
|
|
281
|
+
}
|
|
282
|
+
function groupAdd(repo, io, options = {}) {
|
|
234
283
|
return carnetErrors(io, () => {
|
|
284
|
+
const found = currentGroup(io, options.group);
|
|
235
285
|
const path = resolve(io.cwd, repo);
|
|
236
|
-
const group = addGroupRepo(found.
|
|
237
|
-
io.stdout(
|
|
286
|
+
const group = addGroupRepo(found.name, path, io.env);
|
|
287
|
+
io.stdout(withChanges(`added ${basename(path)} to ${group.name}`, rendered(group, io)));
|
|
238
288
|
return 0;
|
|
239
289
|
});
|
|
240
290
|
}
|
|
241
|
-
function groupRemove(repo, io) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
291
|
+
function groupRemove(repo, io, options = {}) {
|
|
292
|
+
return carnetErrors(io, () => {
|
|
293
|
+
const found = currentGroup(io, options.group);
|
|
294
|
+
const group = removeGroupRepo(found.name, resolve(io.cwd, repo), io.env);
|
|
295
|
+
io.stdout(withChanges(`removed ${basename(repo)} from ${group.name}`, rendered(group, io)));
|
|
296
|
+
return 0;
|
|
245
297
|
});
|
|
298
|
+
}
|
|
299
|
+
function groupSync(io, options = {}) {
|
|
246
300
|
return carnetErrors(io, () => {
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
io.stdout(
|
|
301
|
+
const group = currentGroup(io, options.group);
|
|
302
|
+
const changes = rendered(group, io);
|
|
303
|
+
io.stdout(changes.length ? `${[`synced ${group.name}`, ...changes.map((change) => ` ${change}`)].join("\n")}\n` : `${group.name} already in sync\n`);
|
|
250
304
|
return 0;
|
|
251
305
|
});
|
|
252
306
|
}
|
|
253
|
-
function
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
307
|
+
function groupPath(io, options = {}) {
|
|
308
|
+
return carnetErrors(io, () => {
|
|
309
|
+
const group = currentGroup(io, options.group);
|
|
310
|
+
io.stdout(`${options.source ? group.source : group.workspace}\n`);
|
|
311
|
+
return 0;
|
|
257
312
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return
|
|
313
|
+
}
|
|
314
|
+
function editorCommand(env) {
|
|
315
|
+
return env.VISUAL || env.EDITOR || "vi";
|
|
316
|
+
}
|
|
317
|
+
function openEditorFor(io) {
|
|
318
|
+
return (file) => {
|
|
319
|
+
return spawnSync(`${editorCommand(io.env)} "$RUCHER_EDIT_FILE"`, {
|
|
320
|
+
shell: true,
|
|
321
|
+
stdio: "inherit",
|
|
322
|
+
env: {
|
|
323
|
+
...io.env,
|
|
324
|
+
RUCHER_EDIT_FILE: file
|
|
325
|
+
}
|
|
326
|
+
}).status ?? 1;
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function invalidGroupFile(name, io) {
|
|
330
|
+
try {
|
|
331
|
+
loadGroup(name, io.env);
|
|
332
|
+
return null;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return error instanceof Error ? error.message : String(error);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async function groupEdit(io, options = {}) {
|
|
338
|
+
let group;
|
|
339
|
+
try {
|
|
340
|
+
group = currentGroup(io, options.group);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error instanceof CarnetError) {
|
|
343
|
+
io.stderr(`error: ${error.message}\n`);
|
|
344
|
+
return 1;
|
|
345
|
+
}
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
const file = join(group.source, options.json ? GROUP_FILE : INSTRUCTIONS_FILE);
|
|
349
|
+
const original = readFileSync(file, "utf8");
|
|
350
|
+
const openEditor = options.openEditor ?? openEditorFor(io);
|
|
351
|
+
for (;;) {
|
|
352
|
+
if (openEditor(file) !== 0) {
|
|
353
|
+
io.stderr(`error: ${editorCommand(io.env)} exited with an error, nothing synced\n`);
|
|
354
|
+
return 1;
|
|
355
|
+
}
|
|
356
|
+
const problem = options.json ? invalidGroupFile(group.name, io) : null;
|
|
357
|
+
if (!problem) break;
|
|
358
|
+
io.stderr(`error: ${GROUP_FILE} is invalid: ${problem}\n`);
|
|
359
|
+
if (!options.confirm || !await options.confirm("Edit it again? [Y/n] ")) {
|
|
360
|
+
writeFileSync(file, original);
|
|
361
|
+
io.stderr(`restored the previous ${GROUP_FILE}\n`);
|
|
362
|
+
return 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return groupSync(io, { group: group.name });
|
|
366
|
+
}
|
|
367
|
+
// src/session.ts
|
|
368
|
+
var CliError = class extends Error {
|
|
369
|
+
hint;
|
|
370
|
+
constructor(message, hint) {
|
|
371
|
+
super(message);
|
|
372
|
+
this.hint = hint;
|
|
373
|
+
this.name = "CliError";
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
function findSession(carnet, reference) {
|
|
377
|
+
try {
|
|
378
|
+
return carnet.sessions.find(reference);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
381
|
+
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
382
|
+
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` : "pass a session name, id or id prefix, see rucher sessions --all");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function resolveSession(carnet, reference) {
|
|
386
|
+
if (reference) return findSession(carnet, reference);
|
|
387
|
+
const session = carnet.sessions.default();
|
|
388
|
+
if (!session) throw new CliError("No session in this group yet", "start a Claude Code session inside the group");
|
|
389
|
+
return session;
|
|
390
|
+
}
|
|
391
|
+
// src/commands/sessions.ts
|
|
392
|
+
function lastActive(at, now) {
|
|
393
|
+
const date = new Date(at);
|
|
394
|
+
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
395
|
+
}
|
|
396
|
+
function row(carnet, session, now) {
|
|
397
|
+
const open = carnet.agents.list(session.id).length;
|
|
398
|
+
return [
|
|
399
|
+
session.name ?? session.id.slice(0, 8),
|
|
400
|
+
session.kind,
|
|
401
|
+
session.status,
|
|
402
|
+
repoPathFor(carnet.group, session.cwd) ?? session.repo ?? "",
|
|
403
|
+
lastActive(session.lastActiveAt, now),
|
|
404
|
+
open ? `${open} agent${open > 1 ? "s" : ""}` : "",
|
|
405
|
+
session.purpose ?? ""
|
|
406
|
+
];
|
|
407
|
+
}
|
|
408
|
+
function sessionsOnce(carnet, io, options = {}) {
|
|
409
|
+
const colors = paint(io);
|
|
410
|
+
const sessions = carnet.sessions.list({
|
|
411
|
+
includeTemp: options.all,
|
|
412
|
+
includeArchived: options.all
|
|
413
|
+
});
|
|
414
|
+
if (sessions.length === 0) {
|
|
415
|
+
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
416
|
+
io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
420
|
+
const rows = sessions.map((session) => ({
|
|
421
|
+
session,
|
|
422
|
+
cells: row(carnet, session, now)
|
|
423
|
+
}));
|
|
424
|
+
const widths = rows.reduce((current, { cells }) => cells.map((cell, column) => Math.max(current[column] ?? 0, cell.length)), []);
|
|
425
|
+
const lines = rows.map(({ session, cells }) => {
|
|
426
|
+
return cells.map((cell, column) => {
|
|
427
|
+
const padded = column < cells.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell;
|
|
428
|
+
if (column === 0) return colors.bold(padded);
|
|
429
|
+
if (column === 1 && session.kind === "temp") return colors.dim(padded);
|
|
430
|
+
if (column === 2 && session.status === "archived") return colors.dim(padded);
|
|
431
|
+
return padded;
|
|
432
|
+
}).join(" ").trimEnd();
|
|
433
|
+
});
|
|
434
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
435
|
+
}
|
|
436
|
+
function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
437
|
+
const from = findSession(carnet, fromReference);
|
|
438
|
+
const into = findSession(carnet, intoReference);
|
|
439
|
+
const result = carnet.sessions.merge(from.id, into.id);
|
|
440
|
+
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
441
|
+
const lines = [
|
|
442
|
+
`merged ${label(from)} into ${label(result.session)}`,
|
|
443
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
444
|
+
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
445
|
+
` events moved: ${result.movedEvents}`,
|
|
446
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`
|
|
447
|
+
];
|
|
448
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
449
|
+
}
|
|
450
|
+
function label(session) {
|
|
451
|
+
return session.name ?? shortId(session.id);
|
|
452
|
+
}
|
|
453
|
+
function groupNamed(name, io) {
|
|
454
|
+
if (!groupExists(name, io.env)) throw new CliError(`No group named "${name}"`, "see rucher groups list");
|
|
455
|
+
return loadGroup(name, io.env);
|
|
456
|
+
}
|
|
457
|
+
function sessionsMove(carnet, reference, groupReference, io, options = {}) {
|
|
458
|
+
const session = findSession(carnet, reference);
|
|
459
|
+
const target = groupNamed(groupReference, io).name;
|
|
460
|
+
const result = moveSession(carnet, session.id, target, options);
|
|
461
|
+
const into = result.into ? ` into ${label(result.into)}` : "";
|
|
462
|
+
const lines = [
|
|
463
|
+
`${options.dryRun ? "would move" : "moved"} ${label(session)} from ${groupLabel(carnet.group)} to ${target}${into}`,
|
|
464
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
465
|
+
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
466
|
+
` events moved: ${result.movedEvents}`,
|
|
467
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
468
|
+
...result.keptNotes ? [` notes kept in ${groupLabel(carnet.group)}: ${result.keptNotes}`] : []
|
|
469
|
+
];
|
|
470
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
471
|
+
}
|
|
472
|
+
function sessionsRename(carnet, reference, name, io) {
|
|
473
|
+
const session = carnet.sessions.rename(findSession(carnet, reference).id, name);
|
|
474
|
+
io.stdout(`renamed to ${session.name}; rucher resume ${session.name} gives Claude the same title\n`);
|
|
475
|
+
}
|
|
476
|
+
function sessionsPromote(carnet, reference, name, io) {
|
|
477
|
+
const session = carnet.sessions.promote(findSession(carnet, reference).id, name);
|
|
478
|
+
io.stdout(`${label(session)} is now active\n`);
|
|
479
|
+
}
|
|
480
|
+
function sessionsDemote(carnet, reference, io) {
|
|
481
|
+
const session = carnet.sessions.demote(findSession(carnet, reference).id);
|
|
482
|
+
io.stdout(`${label(session)} is now temp, cleaned by rucher sessions clean once idle\n`);
|
|
483
|
+
}
|
|
484
|
+
function purgeTranscripts(session, io) {
|
|
485
|
+
const files = hostById(session.host).transcriptFiles(session, io.env);
|
|
486
|
+
for (const file of files) {
|
|
487
|
+
rmSync(file, {
|
|
488
|
+
recursive: true,
|
|
489
|
+
force: true
|
|
490
|
+
});
|
|
491
|
+
io.stdout(` deleted ${file}\n`);
|
|
492
|
+
}
|
|
493
|
+
if (files.length === 0) io.stdout(" no transcript found\n");
|
|
494
|
+
}
|
|
495
|
+
function sessionsDrop(carnet, reference, io, options = {}) {
|
|
496
|
+
const session = findSession(carnet, reference);
|
|
497
|
+
if (options.purge && session.status === "running") throw new CliError(`Session ${label(session)} is running`, "drop it with --purge once it has ended");
|
|
498
|
+
carnet.sessions.drop(session.id);
|
|
499
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
500
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
501
|
+
}
|
|
502
|
+
const UNIT_MILLISECONDS = {
|
|
503
|
+
m: 6e4,
|
|
504
|
+
h: 36e5,
|
|
505
|
+
d: 864e5
|
|
506
|
+
};
|
|
507
|
+
function parseDuration(value) {
|
|
508
|
+
const match = /^(\d+(?:\.\d+)?)([mhd]?)$/.exec(value.trim());
|
|
509
|
+
if (!match) throw new CliError(`Invalid duration "${value}"`, "use a number of days, or 30m, 12h, 7d");
|
|
510
|
+
return Number(match[1]) * (UNIT_MILLISECONDS[match[2] || "d"] ?? 0);
|
|
511
|
+
}
|
|
512
|
+
function processIsAlive(processId) {
|
|
513
|
+
try {
|
|
514
|
+
process.kill(processId, 0);
|
|
515
|
+
return true;
|
|
516
|
+
} catch (error) {
|
|
517
|
+
return error.code === "EPERM";
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function sessionsClean(carnet, io, options = {}) {
|
|
521
|
+
const olderThan = parseDuration(options.olderThan ?? "7d");
|
|
522
|
+
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`);
|
|
523
|
+
const stale = carnet.sessions.staleTemp(olderThan);
|
|
524
|
+
if (stale.length === 0) {
|
|
525
|
+
io.stdout(`no temp session idle for more than ${options.olderThan ?? "7d"}\n`);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
for (const session of stale) {
|
|
529
|
+
if (options.dryRun) {
|
|
530
|
+
io.stdout(`would archive ${label(session)}${options.purge ? " and delete its transcript" : ""}\n`);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
carnet.sessions.drop(session.id);
|
|
534
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
535
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
536
|
+
}
|
|
261
537
|
}
|
|
262
538
|
// src/commands/groups.ts
|
|
263
|
-
function
|
|
264
|
-
return
|
|
539
|
+
function plural(count, word) {
|
|
540
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
265
541
|
}
|
|
266
542
|
function groupsList(io) {
|
|
267
543
|
const colors = paint(io);
|
|
268
|
-
const groups =
|
|
544
|
+
const groups = listGroups(io.env);
|
|
269
545
|
if (groups.length === 0) {
|
|
270
|
-
io.stdout(`${colors.dim("no
|
|
546
|
+
io.stdout(`${colors.dim("no group yet, create one with `rucher groups create <name>`")}\n`);
|
|
271
547
|
return 0;
|
|
272
548
|
}
|
|
549
|
+
const carnet = openGroupCarnet(null, { env: io.env });
|
|
550
|
+
const sessions = groupSessionCounts(carnet.db);
|
|
551
|
+
carnet.close();
|
|
273
552
|
const width = Math.max(...groups.map((group) => group.name.length));
|
|
274
|
-
const lines = groups.map((group) => `${colors.bold(group.name.padEnd(width))} ${group.
|
|
553
|
+
const lines = groups.map((group) => `${colors.bold(group.name.padEnd(width))} ${plural(group.repos.length, "repo")} ${plural(sessions.get(group.name) ?? 0, "session")} ${colors.dim(group.workspace)}`);
|
|
275
554
|
io.stdout(`${lines.join("\n")}\n`);
|
|
276
555
|
return 0;
|
|
277
556
|
}
|
|
278
|
-
function
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
557
|
+
function groupsCreate(name, io, options = {}) {
|
|
558
|
+
const colors = paint(io);
|
|
559
|
+
const group = createGroup(name, {
|
|
560
|
+
repos: options.repos?.map((repo) => resolve(io.cwd, repo)),
|
|
561
|
+
env: io.env
|
|
562
|
+
});
|
|
563
|
+
const result = renderWorkspace(group, { env: io.env });
|
|
564
|
+
const lines = [
|
|
565
|
+
`${colors.bold(group.name)} created`,
|
|
566
|
+
` source: ${group.source}`,
|
|
567
|
+
` workspace: ${group.workspace}`,
|
|
568
|
+
` repos: ${group.repos.length ? group.repos.map((repo) => repo.path).join(", ") : "none yet, add them with `rucher group add <path> -g " + group.name + "`"}`,
|
|
569
|
+
...result.written.map((path) => ` written ${path}`),
|
|
570
|
+
"",
|
|
571
|
+
"Accept the Claude Code trust prompt in its first session: until then the workspace settings are ignored, and rucher passes the repos with --add-dir.",
|
|
572
|
+
`Next: \`rucher group edit -g ${group.name}\` for its instructions, then \`rucher new <session> -g ${group.name}\`.`
|
|
573
|
+
];
|
|
574
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
293
575
|
return 0;
|
|
294
576
|
}
|
|
295
|
-
function
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
577
|
+
function liveSessions(carnet, isAlive) {
|
|
578
|
+
return carnet.sessions.list({ includeTemp: true }).filter((session) => session.status === "running" && session.hostPid !== null && isAlive(session.hostPid));
|
|
579
|
+
}
|
|
580
|
+
function refuseLive(carnet, action, isAlive) {
|
|
581
|
+
const live = liveSessions(carnet, isAlive);
|
|
582
|
+
if (live.length) throw new CliError(`${plural(live.length, "session")} of ${carnet.group?.name} still running: ${live.map((session) => session.name ?? session.id.slice(0, 8)).join(", ")}`, `end them before you ${action} the group`);
|
|
583
|
+
}
|
|
584
|
+
function groupsRename(from, to, io, options = {}) {
|
|
585
|
+
const carnet = openGroupCarnet(loadGroup(from, io.env), { env: io.env });
|
|
586
|
+
try {
|
|
587
|
+
refuseLive(carnet, "rename", options.isAlive ?? processIsAlive);
|
|
588
|
+
const group = renameGroup(from, to, io.env);
|
|
589
|
+
try {
|
|
590
|
+
renameGroupRows(carnet.db, from, to);
|
|
591
|
+
} catch (error) {
|
|
592
|
+
renameGroup(to, from, io.env);
|
|
593
|
+
throw error;
|
|
594
|
+
}
|
|
595
|
+
io.stdout(`renamed ${from} to ${to}; its workspace stays at ${group.workspace}\n`);
|
|
299
596
|
return 0;
|
|
597
|
+
} finally {
|
|
598
|
+
carnet.close();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function groupsDrop(name, io, options = {}) {
|
|
602
|
+
const carnet = openGroupCarnet(loadGroup(name, io.env), { env: io.env });
|
|
603
|
+
try {
|
|
604
|
+
refuseLive(carnet, "drop", options.isAlive ?? processIsAlive);
|
|
605
|
+
const at = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
606
|
+
const archived = archiveGroupSessions(carnet.db, name, at);
|
|
607
|
+
const deletedNotes = options.purge ? deleteGroupNotes(carnet.db, name) : 0;
|
|
608
|
+
const group = dropGroup(name, {
|
|
609
|
+
purge: options.purge,
|
|
610
|
+
env: io.env
|
|
611
|
+
});
|
|
612
|
+
const lines = [
|
|
613
|
+
`dropped ${name}: source ${group.source} removed`,
|
|
614
|
+
` sessions archived: ${archived}`,
|
|
615
|
+
options.purge ? ` notes deleted: ${deletedNotes}; workspace ${group.workspace} removed` : ` notes and workspace kept; recreate the group under the same name to see them again`
|
|
616
|
+
];
|
|
617
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
618
|
+
return 0;
|
|
619
|
+
} finally {
|
|
620
|
+
carnet.close();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function groupsErrors(io, run) {
|
|
624
|
+
try {
|
|
625
|
+
return run();
|
|
626
|
+
} catch (error) {
|
|
627
|
+
if (error instanceof CliError) {
|
|
628
|
+
io.stderr(`error: ${error.message}${error.hint ? `\n ${error.hint}` : ""}\n`);
|
|
629
|
+
return 1;
|
|
630
|
+
}
|
|
631
|
+
if (error instanceof CarnetError) {
|
|
632
|
+
io.stderr(`error: ${error.message}\n`);
|
|
633
|
+
return 1;
|
|
634
|
+
}
|
|
635
|
+
throw error;
|
|
300
636
|
}
|
|
301
|
-
unregisterGroups(gone.map((group) => group.path), io.env);
|
|
302
|
-
io.stdout(`pruned ${gone.length}:\n${gone.map((g) => ` ${g.name} ${g.path}`).join("\n")}\n`);
|
|
303
|
-
return 0;
|
|
304
637
|
}
|
|
305
638
|
// src/commands/hook.ts
|
|
306
639
|
const host = claudeCode;
|
|
@@ -331,6 +664,8 @@ function withCarnet$1(payload, io, use) {
|
|
|
331
664
|
sessionId: payload.session_id
|
|
332
665
|
});
|
|
333
666
|
try {
|
|
667
|
+
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
668
|
+
if (!carnet.group && !io.env.RUCHER_SESSION_ID && !known) return;
|
|
334
669
|
use(carnet);
|
|
335
670
|
} finally {
|
|
336
671
|
carnet.close();
|
|
@@ -419,30 +754,6 @@ function sessionEnd(stdinText, io) {
|
|
|
419
754
|
});
|
|
420
755
|
});
|
|
421
756
|
}
|
|
422
|
-
// src/session.ts
|
|
423
|
-
var CliError = class extends Error {
|
|
424
|
-
hint;
|
|
425
|
-
constructor(message, hint) {
|
|
426
|
-
super(message);
|
|
427
|
-
this.hint = hint;
|
|
428
|
-
this.name = "CliError";
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
function findSession(carnet, reference) {
|
|
432
|
-
try {
|
|
433
|
-
return carnet.sessions.find(reference);
|
|
434
|
-
} catch (error) {
|
|
435
|
-
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
436
|
-
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
437
|
-
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` : "pass a session name, id or id prefix, see rucher sessions --all");
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function resolveSession(carnet, reference) {
|
|
441
|
-
if (reference) return findSession(carnet, reference);
|
|
442
|
-
const session = carnet.sessions.default();
|
|
443
|
-
if (!session) throw new CliError("No session in this group yet", "start a Claude Code session inside the group");
|
|
444
|
-
return session;
|
|
445
|
-
}
|
|
446
757
|
// src/commands/log.ts
|
|
447
758
|
function formatEvents(events, io) {
|
|
448
759
|
const colors = paint(io);
|
|
@@ -487,7 +798,7 @@ function formatEventsMarkdown(events, title) {
|
|
|
487
798
|
return lines.join("\n");
|
|
488
799
|
}
|
|
489
800
|
function sessionTitle(carnet, session) {
|
|
490
|
-
return `${carnet.group
|
|
801
|
+
return `${groupLabel(carnet.group)} · ${session.name ?? session.id.slice(0, 8)}`;
|
|
491
802
|
}
|
|
492
803
|
function logOnce(carnet, io, options) {
|
|
493
804
|
const session = resolveSession(carnet, options.session);
|
|
@@ -542,7 +853,7 @@ function markdown(carnet, notes) {
|
|
|
542
853
|
});
|
|
543
854
|
return `## ${KIND_TITLES[kind]}\n\n${lines.join("\n")}`;
|
|
544
855
|
});
|
|
545
|
-
return `# Memory: ${carnet.group
|
|
856
|
+
return `# Memory: ${groupLabel(carnet.group)}\n\n${sections.join("\n\n") || "No notes."}\n`;
|
|
546
857
|
}
|
|
547
858
|
function notesList(carnet, io, options = {}) {
|
|
548
859
|
const notes = options.stale ? carnet.notes.stale(halfLife(io)) : carnet.notes.list({
|
|
@@ -628,13 +939,13 @@ function splitPassthrough(rawArgs) {
|
|
|
628
939
|
function positionals(own) {
|
|
629
940
|
return own.filter((argument) => !argument.startsWith("-"));
|
|
630
941
|
}
|
|
631
|
-
function launchEnv(
|
|
942
|
+
function launchEnv(group, session, promptVersion, kind) {
|
|
632
943
|
return {
|
|
633
944
|
RUCHER_SESSION_ID: session.id,
|
|
634
945
|
RUCHER_PROMPT_VERSION: promptVersion,
|
|
635
946
|
RUCHER_SESSION_NAME: session.name ?? "",
|
|
636
|
-
|
|
637
|
-
|
|
947
|
+
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD: "1",
|
|
948
|
+
...group ? { RUCHER_GROUP: group.name } : {},
|
|
638
949
|
...kind ? { RUCHER_SESSION_KIND: kind } : {}
|
|
639
950
|
};
|
|
640
951
|
}
|
|
@@ -644,36 +955,60 @@ function planNew(carnet, io, options) {
|
|
|
644
955
|
id: randomUUID(),
|
|
645
956
|
kind: options.kind,
|
|
646
957
|
name: options.name,
|
|
647
|
-
cwd: carnet.group.
|
|
958
|
+
cwd: carnet.group?.workspace ?? io.cwd,
|
|
648
959
|
repo: repoNameFor(carnet.group, io.cwd)
|
|
649
960
|
});
|
|
650
961
|
const host = hostById(session.host);
|
|
962
|
+
if (carnet.group) renderWorkspace(carnet.group, {
|
|
963
|
+
env: io.env,
|
|
964
|
+
host: session.host
|
|
965
|
+
});
|
|
651
966
|
const prompt = appendPromptFile(carnet.group, session, io.env);
|
|
652
967
|
return {
|
|
653
968
|
...host.launchCommand(session.id, {
|
|
654
969
|
name: session.name,
|
|
655
970
|
appendPromptFile: prompt.path,
|
|
971
|
+
directories: repoDirectories(carnet.group),
|
|
656
972
|
passthrough: options.passthrough
|
|
657
973
|
}),
|
|
658
|
-
cwd: carnet.group.
|
|
659
|
-
env: launchEnv(carnet, session, prompt.version),
|
|
974
|
+
cwd: carnet.group?.workspace ?? io.cwd,
|
|
975
|
+
env: launchEnv(carnet.group, session, prompt.version),
|
|
660
976
|
sessionId: session.id
|
|
661
977
|
};
|
|
662
978
|
}
|
|
663
|
-
function
|
|
664
|
-
return
|
|
979
|
+
function repoDirectories(group) {
|
|
980
|
+
return (group?.repos ?? []).map((repo) => repo.path).filter((path) => existsSync(path));
|
|
981
|
+
}
|
|
982
|
+
function sessionGroup(carnet, session, env) {
|
|
983
|
+
if (!session.groupName || !isGroupName(session.groupName)) return null;
|
|
984
|
+
return carnet.group?.name === session.groupName ? carnet.group : loadGroup(session.groupName, env);
|
|
985
|
+
}
|
|
986
|
+
function prepareSession(carnet, session, env) {
|
|
987
|
+
const group = sessionGroup(carnet, session, env);
|
|
988
|
+
if (group) renderWorkspace(group, {
|
|
989
|
+
env,
|
|
990
|
+
host: session.host
|
|
991
|
+
});
|
|
992
|
+
return group;
|
|
993
|
+
}
|
|
994
|
+
function sessionDirectory(session) {
|
|
995
|
+
if (session.cwd && existsSync(session.cwd)) return session.cwd;
|
|
996
|
+
throw new CarnetError("SESSION_CWD_MISSING", `The directory of session ${session.name ?? session.id.slice(0, 8)} no longer exists: ${session.cwd ?? "none recorded"}`);
|
|
665
997
|
}
|
|
666
998
|
function planResume(carnet, io, reference, passthrough = []) {
|
|
667
999
|
const session = findSession(carnet, reference);
|
|
668
1000
|
if (session.status === "archived") io.stderr(`warning: session ${reference} is archived\n`);
|
|
669
|
-
const
|
|
1001
|
+
const group = prepareSession(carnet, session, io.env);
|
|
1002
|
+
const cwd = sessionDirectory(session);
|
|
1003
|
+
const prompt = appendPromptFile(group, session, io.env);
|
|
670
1004
|
return {
|
|
671
1005
|
...hostById(session.host).resumeCommand(session, {
|
|
672
1006
|
appendPromptFile: prompt.path,
|
|
1007
|
+
directories: repoDirectories(group),
|
|
673
1008
|
passthrough
|
|
674
1009
|
}),
|
|
675
|
-
cwd
|
|
676
|
-
env: launchEnv(
|
|
1010
|
+
cwd,
|
|
1011
|
+
env: launchEnv(group, session, prompt.version),
|
|
677
1012
|
sessionId: session.id
|
|
678
1013
|
};
|
|
679
1014
|
}
|
|
@@ -681,16 +1016,19 @@ function planFork(carnet, io, reference, options = {}) {
|
|
|
681
1016
|
if (options.active && !options.name) throw new CliError("An active fork needs a name", "rucher fork <session> <name> --active");
|
|
682
1017
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
683
1018
|
const parent = findSession(carnet, reference);
|
|
1019
|
+
const group = prepareSession(carnet, parent, io.env);
|
|
1020
|
+
const cwd = sessionDirectory(parent);
|
|
684
1021
|
const kind = options.active ? "active" : "temp";
|
|
685
1022
|
return {
|
|
686
1023
|
...hostById(parent.host).forkCommand(parent, {
|
|
687
1024
|
name: options.name,
|
|
688
|
-
appendPromptFile: appendPromptFile(
|
|
1025
|
+
appendPromptFile: appendPromptFile(group, parent, io.env).path,
|
|
1026
|
+
directories: repoDirectories(group),
|
|
689
1027
|
passthrough: options.passthrough
|
|
690
1028
|
}),
|
|
691
|
-
cwd
|
|
1029
|
+
cwd,
|
|
692
1030
|
env: {
|
|
693
|
-
...launchEnv(
|
|
1031
|
+
...launchEnv(group, parent, parent.promptVersion ?? "", kind),
|
|
694
1032
|
RUCHER_SESSION_NAME: options.name ?? ""
|
|
695
1033
|
},
|
|
696
1034
|
parentId: parent.id,
|
|
@@ -721,237 +1059,81 @@ function spawnLaunch(plan, env) {
|
|
|
721
1059
|
stdio: "inherit",
|
|
722
1060
|
env: {
|
|
723
1061
|
...env,
|
|
724
|
-
...plan.env
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
if (result.error) throw result.error;
|
|
728
|
-
return result.status ?? 1;
|
|
729
|
-
}
|
|
730
|
-
// src/commands/picker.ts
|
|
731
|
-
function pickerSessions(carnet) {
|
|
732
|
-
const sessions = carnet.sessions.list({ includeTemp: true });
|
|
733
|
-
return [...sessions.filter((session) => session.name), ...sessions.filter((session) => !session.name)];
|
|
734
|
-
}
|
|
735
|
-
function lastUse(at, now) {
|
|
736
|
-
const date = new Date(at);
|
|
737
|
-
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
738
|
-
}
|
|
739
|
-
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
740
|
-
const rows = sessions.map((session, index) => [
|
|
741
|
-
String(index + 1),
|
|
742
|
-
session.name ?? shortId(session.id),
|
|
743
|
-
session.kind,
|
|
744
|
-
session.status,
|
|
745
|
-
lastUse(session.lastActiveAt, now),
|
|
746
|
-
shortId(session.id)
|
|
747
|
-
]);
|
|
748
|
-
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
749
|
-
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
750
|
-
}
|
|
751
|
-
function hasFzf() {
|
|
752
|
-
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
753
|
-
}
|
|
754
|
-
function pickWithFzf(sessions, lines) {
|
|
755
|
-
const result = spawnSync("fzf", [
|
|
756
|
-
"--with-nth=2..",
|
|
757
|
-
"--no-sort",
|
|
758
|
-
"--prompt=session> "
|
|
759
|
-
], {
|
|
760
|
-
input: lines.join("\n"),
|
|
761
|
-
stdio: [
|
|
762
|
-
"pipe",
|
|
763
|
-
"pipe",
|
|
764
|
-
"inherit"
|
|
765
|
-
],
|
|
766
|
-
encoding: "utf8"
|
|
767
|
-
});
|
|
768
|
-
return sessions[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
769
|
-
}
|
|
770
|
-
async function pickFromList(sessions, lines) {
|
|
771
|
-
process.stderr.write(`${lines.join("\n")}\n`);
|
|
772
|
-
const prompt = createInterface({
|
|
773
|
-
input: process.stdin,
|
|
774
|
-
output: process.stderr
|
|
775
|
-
});
|
|
776
|
-
try {
|
|
777
|
-
const answer = await prompt.question("session number> ");
|
|
778
|
-
return sessions[Number(answer.trim()) - 1];
|
|
779
|
-
} finally {
|
|
780
|
-
prompt.close();
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
async function pickSession(carnet) {
|
|
784
|
-
const sessions = pickerSessions(carnet);
|
|
785
|
-
if (sessions.length === 0) throw new CliError("No session to resume in this group", "rucher new <name>");
|
|
786
|
-
if (!process.stdin.isTTY) throw new CliError("No session given", "rucher resume <name, id or id prefix>");
|
|
787
|
-
const lines = pickerLines(sessions);
|
|
788
|
-
const picked = hasFzf() ? pickWithFzf(sessions, lines) : await pickFromList(sessions, lines);
|
|
789
|
-
if (!picked) throw new CliError("No session picked");
|
|
790
|
-
return picked;
|
|
791
|
-
}
|
|
792
|
-
// src/commands/serve.ts
|
|
793
|
-
function serve(io) {
|
|
794
|
-
serveCarnet({
|
|
795
|
-
cwd: io.cwd,
|
|
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();
|
|
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`);
|
|
1062
|
+
...plan.env
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
if (result.error) throw result.error;
|
|
1066
|
+
return result.status ?? 1;
|
|
893
1067
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1068
|
+
// src/commands/picker.ts
|
|
1069
|
+
function pickerSessions(carnet) {
|
|
1070
|
+
const sessions = carnet.sessions.list({ includeTemp: true });
|
|
1071
|
+
return [...sessions.filter((session) => session.name), ...sessions.filter((session) => !session.name)];
|
|
897
1072
|
}
|
|
898
|
-
function
|
|
899
|
-
const
|
|
900
|
-
|
|
1073
|
+
function lastUse(at, now) {
|
|
1074
|
+
const date = new Date(at);
|
|
1075
|
+
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
901
1076
|
}
|
|
902
|
-
function
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1077
|
+
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
1078
|
+
const rows = sessions.map((session, index) => [
|
|
1079
|
+
String(index + 1),
|
|
1080
|
+
session.name ?? shortId(session.id),
|
|
1081
|
+
session.kind,
|
|
1082
|
+
session.status,
|
|
1083
|
+
lastUse(session.lastActiveAt, now),
|
|
1084
|
+
shortId(session.id)
|
|
1085
|
+
]);
|
|
1086
|
+
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
1087
|
+
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
912
1088
|
}
|
|
913
|
-
function
|
|
914
|
-
|
|
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);
|
|
1089
|
+
function hasFzf() {
|
|
1090
|
+
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
919
1091
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1092
|
+
function pickWithFzf(sessions, lines) {
|
|
1093
|
+
const result = spawnSync("fzf", [
|
|
1094
|
+
"--with-nth=2..",
|
|
1095
|
+
"--no-sort",
|
|
1096
|
+
"--prompt=session> "
|
|
1097
|
+
], {
|
|
1098
|
+
input: lines.join("\n"),
|
|
1099
|
+
stdio: [
|
|
1100
|
+
"pipe",
|
|
1101
|
+
"pipe",
|
|
1102
|
+
"inherit"
|
|
1103
|
+
],
|
|
1104
|
+
encoding: "utf8"
|
|
1105
|
+
});
|
|
1106
|
+
return sessions[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
929
1107
|
}
|
|
930
|
-
function
|
|
1108
|
+
async function pickFromList(sessions, lines) {
|
|
1109
|
+
process.stderr.write(`${lines.join("\n")}\n`);
|
|
1110
|
+
const prompt = createInterface({
|
|
1111
|
+
input: process.stdin,
|
|
1112
|
+
output: process.stderr
|
|
1113
|
+
});
|
|
931
1114
|
try {
|
|
932
|
-
|
|
933
|
-
return
|
|
934
|
-
}
|
|
935
|
-
|
|
1115
|
+
const answer = await prompt.question("session number> ");
|
|
1116
|
+
return sessions[Number(answer.trim()) - 1];
|
|
1117
|
+
} finally {
|
|
1118
|
+
prompt.close();
|
|
936
1119
|
}
|
|
937
1120
|
}
|
|
938
|
-
function
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
io.
|
|
953
|
-
|
|
954
|
-
}
|
|
1121
|
+
async function pickSession(carnet) {
|
|
1122
|
+
const sessions = pickerSessions(carnet);
|
|
1123
|
+
if (sessions.length === 0) throw new CliError("No session to resume in this group", "rucher new <name>");
|
|
1124
|
+
if (!process.stdin.isTTY) throw new CliError("No session given", "rucher resume <name, id or id prefix>");
|
|
1125
|
+
const lines = pickerLines(sessions);
|
|
1126
|
+
const picked = hasFzf() ? pickWithFzf(sessions, lines) : await pickFromList(sessions, lines);
|
|
1127
|
+
if (!picked) throw new CliError("No session picked");
|
|
1128
|
+
return picked;
|
|
1129
|
+
}
|
|
1130
|
+
// src/commands/serve.ts
|
|
1131
|
+
function serve(io) {
|
|
1132
|
+
serveCarnet({
|
|
1133
|
+
cwd: io.cwd,
|
|
1134
|
+
env: io.env,
|
|
1135
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
1136
|
+
});
|
|
955
1137
|
}
|
|
956
1138
|
// src/commands/watch-keys.ts
|
|
957
1139
|
const INITIAL_WATCH_STATE = {
|
|
@@ -1092,7 +1274,7 @@ function sessionName(session) {
|
|
|
1092
1274
|
function sessionLabel(carnet, session, columns) {
|
|
1093
1275
|
const name = sessionName(session);
|
|
1094
1276
|
const room = columns - Array.from(name).length - 3;
|
|
1095
|
-
return room > 1 ? `${name} · ${truncate(carnet.group
|
|
1277
|
+
return room > 1 ? `${name} · ${truncate(groupLabel(carnet.group), room)}` : name;
|
|
1096
1278
|
}
|
|
1097
1279
|
function sessionHeader(session, io) {
|
|
1098
1280
|
return paint(io).cyan(truncate(sessionName(session), io.columns));
|
|
@@ -1170,7 +1352,7 @@ function renderStatusView(carnet, io, options) {
|
|
|
1170
1352
|
});
|
|
1171
1353
|
const colors = paint(io);
|
|
1172
1354
|
const separator = " - ";
|
|
1173
|
-
const group = truncate(carnet.group
|
|
1355
|
+
const group = truncate(groupLabel(carnet.group), io.columns - time.length - 3);
|
|
1174
1356
|
return [
|
|
1175
1357
|
`${colors.dim(time)}${separator}${colors.cyan(group)}`,
|
|
1176
1358
|
"",
|
|
@@ -1317,37 +1499,6 @@ const sessionArgument = { session: {
|
|
|
1317
1499
|
alias: "s",
|
|
1318
1500
|
description: "Session name, id or id prefix (default: most recently active)"
|
|
1319
1501
|
} };
|
|
1320
|
-
const initCommand = defineCommand({
|
|
1321
|
-
meta: {
|
|
1322
|
-
name: "init",
|
|
1323
|
-
description: "Make the current directory a Rucher group (meta directory)"
|
|
1324
|
-
},
|
|
1325
|
-
args: {
|
|
1326
|
-
directory: {
|
|
1327
|
-
type: "positional",
|
|
1328
|
-
description: "Meta directory (default: current directory)",
|
|
1329
|
-
required: false
|
|
1330
|
-
},
|
|
1331
|
-
name: {
|
|
1332
|
-
type: "string",
|
|
1333
|
-
description: "Group name (default: directory name)"
|
|
1334
|
-
},
|
|
1335
|
-
repos: {
|
|
1336
|
-
type: "string",
|
|
1337
|
-
description: "Comma-separated repo paths (more later with `rucher group add`)"
|
|
1338
|
-
},
|
|
1339
|
-
...colorArgument
|
|
1340
|
-
},
|
|
1341
|
-
run({ args }) {
|
|
1342
|
-
const io = processIo({ color: args.color });
|
|
1343
|
-
const repos = args.repos ? args.repos.split(",").map((repo) => repo.trim()).filter(Boolean) : void 0;
|
|
1344
|
-
process.exitCode = init({
|
|
1345
|
-
directory: args.directory,
|
|
1346
|
-
name: args.name,
|
|
1347
|
-
repos
|
|
1348
|
-
}, io);
|
|
1349
|
-
}
|
|
1350
|
-
});
|
|
1351
1502
|
const statusCommand = defineCommand({
|
|
1352
1503
|
meta: {
|
|
1353
1504
|
name: "status",
|
|
@@ -1371,15 +1522,13 @@ const statusCommand = defineCommand({
|
|
|
1371
1522
|
default: "1",
|
|
1372
1523
|
description: "Refresh interval in seconds with --watch"
|
|
1373
1524
|
},
|
|
1525
|
+
...groupArgument,
|
|
1374
1526
|
...colorArgument
|
|
1375
1527
|
},
|
|
1376
1528
|
async run({ args }) {
|
|
1377
1529
|
const io = processIo({ color: args.color });
|
|
1378
1530
|
try {
|
|
1379
|
-
const carnet =
|
|
1380
|
-
cwd: io.cwd,
|
|
1381
|
-
env: io.env
|
|
1382
|
-
});
|
|
1531
|
+
const carnet = openCliCarnet(io, args.group);
|
|
1383
1532
|
const options = {
|
|
1384
1533
|
session: args.session,
|
|
1385
1534
|
all: args.all
|
|
@@ -1426,15 +1575,13 @@ const logCommand = defineCommand({
|
|
|
1426
1575
|
default: false,
|
|
1427
1576
|
description: "Agent events only, without session starts and ends"
|
|
1428
1577
|
},
|
|
1578
|
+
...groupArgument,
|
|
1429
1579
|
...colorArgument
|
|
1430
1580
|
},
|
|
1431
1581
|
run({ args }) {
|
|
1432
1582
|
const io = processIo({ color: args.color });
|
|
1433
1583
|
try {
|
|
1434
|
-
logOnce(
|
|
1435
|
-
cwd: io.cwd,
|
|
1436
|
-
env: io.env
|
|
1437
|
-
}), io, {
|
|
1584
|
+
logOnce(openCliCarnet(io, args.group), io, {
|
|
1438
1585
|
session: args.session,
|
|
1439
1586
|
count: Number(args.count) || 20,
|
|
1440
1587
|
md: args.md,
|
|
@@ -1456,15 +1603,13 @@ const sessionsListCommand = defineCommand({
|
|
|
1456
1603
|
default: false,
|
|
1457
1604
|
description: "Include temp and archived sessions"
|
|
1458
1605
|
},
|
|
1606
|
+
...groupArgument,
|
|
1459
1607
|
...colorArgument
|
|
1460
1608
|
},
|
|
1461
1609
|
run({ args }) {
|
|
1462
1610
|
const io = processIo({ color: args.color });
|
|
1463
1611
|
try {
|
|
1464
|
-
sessionsOnce(
|
|
1465
|
-
cwd: io.cwd,
|
|
1466
|
-
env: io.env
|
|
1467
|
-
}), io, { all: args.all });
|
|
1612
|
+
sessionsOnce(openCliCarnet(io, args.group), io, { all: args.all });
|
|
1468
1613
|
} catch (error) {
|
|
1469
1614
|
fail(io, error);
|
|
1470
1615
|
}
|
|
@@ -1485,15 +1630,13 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1485
1630
|
type: "positional",
|
|
1486
1631
|
description: "Session that keeps everything (name, id or id prefix)",
|
|
1487
1632
|
required: true
|
|
1488
|
-
}
|
|
1633
|
+
},
|
|
1634
|
+
...groupArgument
|
|
1489
1635
|
},
|
|
1490
1636
|
run({ args }) {
|
|
1491
1637
|
const io = processIo();
|
|
1492
1638
|
try {
|
|
1493
|
-
const carnet =
|
|
1494
|
-
cwd: io.cwd,
|
|
1495
|
-
env: io.env
|
|
1496
|
-
});
|
|
1639
|
+
const carnet = openCliCarnet(io, args.group);
|
|
1497
1640
|
sessionsMerge(carnet, args.from, args.into, io);
|
|
1498
1641
|
carnet.close();
|
|
1499
1642
|
} catch (error) {
|
|
@@ -1517,11 +1660,12 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1517
1660
|
type: "positional",
|
|
1518
1661
|
description: "New name",
|
|
1519
1662
|
required: true
|
|
1520
|
-
}
|
|
1663
|
+
},
|
|
1664
|
+
...groupArgument
|
|
1521
1665
|
},
|
|
1522
1666
|
run({ args }) {
|
|
1523
1667
|
const io = processIo();
|
|
1524
|
-
withCarnet(io, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
1668
|
+
withCarnet(io, args.group, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
1525
1669
|
}
|
|
1526
1670
|
});
|
|
1527
1671
|
const sessionsPromoteCommand = defineCommand({
|
|
@@ -1535,11 +1679,12 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1535
1679
|
type: "positional",
|
|
1536
1680
|
description: "Name, when the session has none",
|
|
1537
1681
|
required: false
|
|
1538
|
-
}
|
|
1682
|
+
},
|
|
1683
|
+
...groupArgument
|
|
1539
1684
|
},
|
|
1540
1685
|
run({ args }) {
|
|
1541
1686
|
const io = processIo();
|
|
1542
|
-
withCarnet(io, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
1687
|
+
withCarnet(io, args.group, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
1543
1688
|
}
|
|
1544
1689
|
});
|
|
1545
1690
|
const sessionsDemoteCommand = defineCommand({
|
|
@@ -1547,10 +1692,13 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1547
1692
|
name: "demote",
|
|
1548
1693
|
description: "Make an active session temp, keeping its name"
|
|
1549
1694
|
},
|
|
1550
|
-
args: {
|
|
1695
|
+
args: {
|
|
1696
|
+
session: sessionReference,
|
|
1697
|
+
...groupArgument
|
|
1698
|
+
},
|
|
1551
1699
|
run({ args }) {
|
|
1552
1700
|
const io = processIo();
|
|
1553
|
-
withCarnet(io, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
1701
|
+
withCarnet(io, args.group, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
1554
1702
|
}
|
|
1555
1703
|
});
|
|
1556
1704
|
const purgeArgument = { purge: {
|
|
@@ -1565,11 +1713,12 @@ const sessionsDropCommand = defineCommand({
|
|
|
1565
1713
|
},
|
|
1566
1714
|
args: {
|
|
1567
1715
|
session: sessionReference,
|
|
1568
|
-
...purgeArgument
|
|
1716
|
+
...purgeArgument,
|
|
1717
|
+
...groupArgument
|
|
1569
1718
|
},
|
|
1570
1719
|
run({ args }) {
|
|
1571
1720
|
const io = processIo();
|
|
1572
|
-
withCarnet(io, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
1721
|
+
withCarnet(io, args.group, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
1573
1722
|
}
|
|
1574
1723
|
});
|
|
1575
1724
|
const sessionsMoveCommand = defineCommand({
|
|
@@ -1582,7 +1731,7 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1582
1731
|
to: {
|
|
1583
1732
|
type: "string",
|
|
1584
1733
|
required: true,
|
|
1585
|
-
description: "Target group
|
|
1734
|
+
description: "Target group name"
|
|
1586
1735
|
},
|
|
1587
1736
|
merge: {
|
|
1588
1737
|
type: "boolean",
|
|
@@ -1593,11 +1742,12 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1593
1742
|
type: "boolean",
|
|
1594
1743
|
default: false,
|
|
1595
1744
|
description: "Show what would move"
|
|
1596
|
-
}
|
|
1745
|
+
},
|
|
1746
|
+
...groupArgument
|
|
1597
1747
|
},
|
|
1598
1748
|
run({ args }) {
|
|
1599
1749
|
const io = processIo();
|
|
1600
|
-
withCarnet(io, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
1750
|
+
withCarnet(io, args.group, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
1601
1751
|
merge: args.merge,
|
|
1602
1752
|
dryRun: args["dry-run"]
|
|
1603
1753
|
}));
|
|
@@ -1619,11 +1769,12 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1619
1769
|
type: "boolean",
|
|
1620
1770
|
default: false,
|
|
1621
1771
|
description: "Show what would be archived"
|
|
1622
|
-
}
|
|
1772
|
+
},
|
|
1773
|
+
...groupArgument
|
|
1623
1774
|
},
|
|
1624
1775
|
run({ args }) {
|
|
1625
1776
|
const io = processIo();
|
|
1626
|
-
withCarnet(io, (carnet) => sessionsClean(carnet, io, {
|
|
1777
|
+
withCarnet(io, args.group, (carnet) => sessionsClean(carnet, io, {
|
|
1627
1778
|
olderThan: args["older-than"],
|
|
1628
1779
|
purge: args.purge,
|
|
1629
1780
|
dryRun: args["dry-run"]
|
|
@@ -1635,6 +1786,7 @@ const sessionsCommand = defineCommand({
|
|
|
1635
1786
|
name: "sessions",
|
|
1636
1787
|
description: "List and manage the sessions of the group"
|
|
1637
1788
|
},
|
|
1789
|
+
args: { ...groupArgument },
|
|
1638
1790
|
default: "list",
|
|
1639
1791
|
subCommands: {
|
|
1640
1792
|
list: sessionsListCommand,
|
|
@@ -1647,12 +1799,9 @@ const sessionsCommand = defineCommand({
|
|
|
1647
1799
|
clean: sessionsCleanCommand
|
|
1648
1800
|
}
|
|
1649
1801
|
});
|
|
1650
|
-
function withCarnet(io, run) {
|
|
1802
|
+
function withCarnet(io, group, run) {
|
|
1651
1803
|
try {
|
|
1652
|
-
const carnet =
|
|
1653
|
-
cwd: io.cwd,
|
|
1654
|
-
env: io.env
|
|
1655
|
-
});
|
|
1804
|
+
const carnet = openCliCarnet(io, group);
|
|
1656
1805
|
try {
|
|
1657
1806
|
run(carnet);
|
|
1658
1807
|
} finally {
|
|
@@ -1699,11 +1848,12 @@ const notesListCommand = defineCommand({
|
|
|
1699
1848
|
default: false,
|
|
1700
1849
|
description: "Markdown output, a view only"
|
|
1701
1850
|
},
|
|
1851
|
+
...groupArgument,
|
|
1702
1852
|
...colorArgument
|
|
1703
1853
|
},
|
|
1704
1854
|
run({ args }) {
|
|
1705
1855
|
const io = processIo({ color: args.color });
|
|
1706
|
-
withCarnet(io, (carnet) => notesList(carnet, io, {
|
|
1856
|
+
withCarnet(io, args.group, (carnet) => notesList(carnet, io, {
|
|
1707
1857
|
all: args.all,
|
|
1708
1858
|
kind: args.kind,
|
|
1709
1859
|
repo: args.repo,
|
|
@@ -1721,14 +1871,15 @@ const notesShowCommand = defineCommand({
|
|
|
1721
1871
|
args: {
|
|
1722
1872
|
id: {
|
|
1723
1873
|
type: "positional",
|
|
1724
|
-
description: "Note
|
|
1874
|
+
description: "Note number",
|
|
1725
1875
|
required: true
|
|
1726
1876
|
},
|
|
1877
|
+
...groupArgument,
|
|
1727
1878
|
...colorArgument
|
|
1728
1879
|
},
|
|
1729
1880
|
run({ args }) {
|
|
1730
1881
|
const io = processIo({ color: args.color });
|
|
1731
|
-
withCarnet(io, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
1882
|
+
withCarnet(io, args.group, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
1732
1883
|
}
|
|
1733
1884
|
});
|
|
1734
1885
|
const notesAddCommand = defineCommand({
|
|
@@ -1751,11 +1902,12 @@ const notesAddCommand = defineCommand({
|
|
|
1751
1902
|
type: "string",
|
|
1752
1903
|
description: "Repo the note applies to (repeat for several)"
|
|
1753
1904
|
},
|
|
1905
|
+
...groupArgument,
|
|
1754
1906
|
...colorArgument
|
|
1755
1907
|
},
|
|
1756
1908
|
run({ args, rawArgs }) {
|
|
1757
1909
|
const io = processIo({ color: args.color });
|
|
1758
|
-
withCarnet(io, (carnet) => notesAdd(carnet, io, {
|
|
1910
|
+
withCarnet(io, args.group, (carnet) => notesAdd(carnet, io, {
|
|
1759
1911
|
kind: args.kind,
|
|
1760
1912
|
text: args.text,
|
|
1761
1913
|
repos: repoList(rawArgs)
|
|
@@ -1770,7 +1922,7 @@ const notesDropCommand = defineCommand({
|
|
|
1770
1922
|
args: {
|
|
1771
1923
|
id: {
|
|
1772
1924
|
type: "positional",
|
|
1773
|
-
description: "Note
|
|
1925
|
+
description: "Note number",
|
|
1774
1926
|
required: true
|
|
1775
1927
|
},
|
|
1776
1928
|
reason: {
|
|
@@ -1780,13 +1932,14 @@ const notesDropCommand = defineCommand({
|
|
|
1780
1932
|
},
|
|
1781
1933
|
"replaced-by": {
|
|
1782
1934
|
type: "string",
|
|
1783
|
-
description: "
|
|
1784
|
-
}
|
|
1935
|
+
description: "Number of the note that replaces it"
|
|
1936
|
+
},
|
|
1937
|
+
...groupArgument
|
|
1785
1938
|
},
|
|
1786
1939
|
run({ args }) {
|
|
1787
1940
|
const io = processIo();
|
|
1788
1941
|
const replacement = args["replaced-by"];
|
|
1789
|
-
withCarnet(io, (carnet) => notesDrop(carnet, io, parseNoteId(args.id), {
|
|
1942
|
+
withCarnet(io, args.group, (carnet) => notesDrop(carnet, io, parseNoteId(args.id), {
|
|
1790
1943
|
reason: args.reason,
|
|
1791
1944
|
replacedBy: replacement === void 0 ? void 0 : parseNoteId(replacement)
|
|
1792
1945
|
}));
|
|
@@ -1797,7 +1950,10 @@ const notesCommand = defineCommand({
|
|
|
1797
1950
|
name: "notes",
|
|
1798
1951
|
description: "The group's memory: learnings, decisions and dead ends"
|
|
1799
1952
|
},
|
|
1800
|
-
args:
|
|
1953
|
+
args: {
|
|
1954
|
+
...noteFilterArguments,
|
|
1955
|
+
...groupArgument
|
|
1956
|
+
},
|
|
1801
1957
|
default: "list",
|
|
1802
1958
|
subCommands: {
|
|
1803
1959
|
list: notesListCommand,
|
|
@@ -1806,20 +1962,14 @@ const notesCommand = defineCommand({
|
|
|
1806
1962
|
drop: notesDropCommand
|
|
1807
1963
|
}
|
|
1808
1964
|
});
|
|
1809
|
-
async function launch(io, plan) {
|
|
1965
|
+
async function launch(io, group, plan) {
|
|
1810
1966
|
try {
|
|
1811
|
-
const carnet =
|
|
1812
|
-
cwd: io.cwd,
|
|
1813
|
-
env: io.env
|
|
1814
|
-
});
|
|
1967
|
+
const carnet = openCliCarnet(io, group);
|
|
1815
1968
|
const launchPlan = await plan(carnet);
|
|
1816
1969
|
startLaunch(carnet, launchPlan);
|
|
1817
1970
|
carnet.close();
|
|
1818
1971
|
const exitCode = spawnLaunch(launchPlan, io.env);
|
|
1819
|
-
const after =
|
|
1820
|
-
cwd: io.cwd,
|
|
1821
|
-
env: io.env
|
|
1822
|
-
});
|
|
1972
|
+
const after = openGroupCarnet(carnet.group, { env: io.env });
|
|
1823
1973
|
finishLaunch(after, launchPlan);
|
|
1824
1974
|
after.close();
|
|
1825
1975
|
process.exitCode = exitCode;
|
|
@@ -1828,21 +1978,33 @@ async function launch(io, plan) {
|
|
|
1828
1978
|
}
|
|
1829
1979
|
}
|
|
1830
1980
|
const passthroughHelp = "Arguments after -- are passed to Claude Code";
|
|
1981
|
+
function withoutGroupOption(own) {
|
|
1982
|
+
const kept = [];
|
|
1983
|
+
for (let index = 0; index < own.length; index += 1) {
|
|
1984
|
+
const argument = own[index] ?? "";
|
|
1985
|
+
if (argument === "-g" || argument === "--group") index += 1;
|
|
1986
|
+
else if (!argument.startsWith("--group=") && !argument.startsWith("-g=")) kept.push(argument);
|
|
1987
|
+
}
|
|
1988
|
+
return kept;
|
|
1989
|
+
}
|
|
1831
1990
|
const newCommand = defineCommand({
|
|
1832
1991
|
meta: {
|
|
1833
1992
|
name: "new",
|
|
1834
1993
|
description: `Start a named, durable session. ${passthroughHelp}`
|
|
1835
1994
|
},
|
|
1836
|
-
args: {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1995
|
+
args: {
|
|
1996
|
+
name: {
|
|
1997
|
+
type: "positional",
|
|
1998
|
+
description: "Session name",
|
|
1999
|
+
required: true
|
|
2000
|
+
},
|
|
2001
|
+
...groupArgument
|
|
2002
|
+
},
|
|
2003
|
+
async run({ args, rawArgs }) {
|
|
1842
2004
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1843
|
-
await launch(processIo(), (carnet) => planNew(carnet, processIo(), {
|
|
2005
|
+
await launch(processIo(), args.group, (carnet) => planNew(carnet, processIo(), {
|
|
1844
2006
|
kind: "active",
|
|
1845
|
-
name: positionals(own)[0],
|
|
2007
|
+
name: positionals(withoutGroupOption(own))[0],
|
|
1846
2008
|
passthrough
|
|
1847
2009
|
}));
|
|
1848
2010
|
}
|
|
@@ -1852,16 +2014,19 @@ const tmpCommand = defineCommand({
|
|
|
1852
2014
|
name: "tmp",
|
|
1853
2015
|
description: `Start a temporary session. ${passthroughHelp}`
|
|
1854
2016
|
},
|
|
1855
|
-
args: {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
2017
|
+
args: {
|
|
2018
|
+
name: {
|
|
2019
|
+
type: "positional",
|
|
2020
|
+
description: "Optional session name",
|
|
2021
|
+
required: false
|
|
2022
|
+
},
|
|
2023
|
+
...groupArgument
|
|
2024
|
+
},
|
|
2025
|
+
async run({ args, rawArgs }) {
|
|
1861
2026
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1862
|
-
await launch(processIo(), (carnet) => planNew(carnet, processIo(), {
|
|
2027
|
+
await launch(processIo(), args.group, (carnet) => planNew(carnet, processIo(), {
|
|
1863
2028
|
kind: "temp",
|
|
1864
|
-
name: positionals(own)[0],
|
|
2029
|
+
name: positionals(withoutGroupOption(own))[0],
|
|
1865
2030
|
passthrough
|
|
1866
2031
|
}));
|
|
1867
2032
|
}
|
|
@@ -1871,16 +2036,19 @@ const resumeCommand = defineCommand({
|
|
|
1871
2036
|
name: "resume",
|
|
1872
2037
|
description: `Resume a session in its host, or pick one when none is given. ${passthroughHelp}`
|
|
1873
2038
|
},
|
|
1874
|
-
args: {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
2039
|
+
args: {
|
|
2040
|
+
session: {
|
|
2041
|
+
type: "positional",
|
|
2042
|
+
description: "Session name, id or id prefix",
|
|
2043
|
+
required: false
|
|
2044
|
+
},
|
|
2045
|
+
...groupArgument
|
|
2046
|
+
},
|
|
2047
|
+
async run({ args, rawArgs }) {
|
|
1880
2048
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1881
2049
|
const io = processIo();
|
|
1882
|
-
await launch(io, async (carnet) => {
|
|
1883
|
-
const reference = positionals(own)[0] ?? (await pickSession(carnet)).id;
|
|
2050
|
+
await launch(io, args.group, async (carnet) => {
|
|
2051
|
+
const reference = positionals(withoutGroupOption(own))[0] ?? (await pickSession(carnet)).id;
|
|
1884
2052
|
return planResume(carnet, io, reference, passthrough);
|
|
1885
2053
|
});
|
|
1886
2054
|
}
|
|
@@ -1905,13 +2073,14 @@ const forkCommand = defineCommand({
|
|
|
1905
2073
|
type: "boolean",
|
|
1906
2074
|
default: false,
|
|
1907
2075
|
description: "Make the new session durable (needs a name)"
|
|
1908
|
-
}
|
|
2076
|
+
},
|
|
2077
|
+
...groupArgument
|
|
1909
2078
|
},
|
|
1910
|
-
async run({ rawArgs }) {
|
|
2079
|
+
async run({ args, rawArgs }) {
|
|
1911
2080
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1912
|
-
const [reference, name] = positionals(own);
|
|
2081
|
+
const [reference, name] = positionals(withoutGroupOption(own));
|
|
1913
2082
|
const io = processIo();
|
|
1914
|
-
await launch(io, (carnet) => planFork(carnet, io, reference ?? "", {
|
|
2083
|
+
await launch(io, args.group, (carnet) => planFork(carnet, io, reference ?? "", {
|
|
1915
2084
|
name,
|
|
1916
2085
|
active: own.includes("--active"),
|
|
1917
2086
|
passthrough
|
|
@@ -1921,28 +2090,26 @@ const forkCommand = defineCommand({
|
|
|
1921
2090
|
const groupCommand = defineCommand({
|
|
1922
2091
|
meta: {
|
|
1923
2092
|
name: "group",
|
|
1924
|
-
description: "
|
|
2093
|
+
description: "The current group: show it, add or remove repos, render, edit its instructions"
|
|
1925
2094
|
},
|
|
1926
2095
|
subCommands: {
|
|
1927
2096
|
show: defineCommand({
|
|
1928
2097
|
meta: {
|
|
1929
2098
|
name: "show",
|
|
1930
|
-
description: "Name,
|
|
2099
|
+
description: "Name, source, workspace and repos of the group"
|
|
2100
|
+
},
|
|
2101
|
+
args: {
|
|
2102
|
+
...groupArgument,
|
|
2103
|
+
...colorArgument
|
|
1931
2104
|
},
|
|
1932
|
-
args: { ...colorArgument },
|
|
1933
2105
|
run({ args }) {
|
|
1934
|
-
|
|
1935
|
-
try {
|
|
1936
|
-
process.exitCode = groupShow(io);
|
|
1937
|
-
} catch (error) {
|
|
1938
|
-
fail(io, error);
|
|
1939
|
-
}
|
|
2106
|
+
process.exitCode = groupShow(processIo({ color: args.color }), { group: args.group });
|
|
1940
2107
|
}
|
|
1941
2108
|
}),
|
|
1942
2109
|
add: defineCommand({
|
|
1943
2110
|
meta: {
|
|
1944
2111
|
name: "add",
|
|
1945
|
-
description: "Add a repo path to the
|
|
2112
|
+
description: "Add a repo path to the group, then render its workspace"
|
|
1946
2113
|
},
|
|
1947
2114
|
args: {
|
|
1948
2115
|
path: {
|
|
@@ -1950,97 +2117,188 @@ const groupCommand = defineCommand({
|
|
|
1950
2117
|
description: "Repo path",
|
|
1951
2118
|
required: true
|
|
1952
2119
|
},
|
|
2120
|
+
...groupArgument,
|
|
1953
2121
|
...colorArgument
|
|
1954
2122
|
},
|
|
1955
2123
|
run({ args }) {
|
|
1956
|
-
|
|
1957
|
-
try {
|
|
1958
|
-
process.exitCode = groupAdd(args.path, io);
|
|
1959
|
-
} catch (error) {
|
|
1960
|
-
fail(io, error);
|
|
1961
|
-
}
|
|
2124
|
+
process.exitCode = groupAdd(args.path, processIo({ color: args.color }), { group: args.group });
|
|
1962
2125
|
}
|
|
1963
2126
|
}),
|
|
1964
2127
|
remove: defineCommand({
|
|
1965
2128
|
meta: {
|
|
1966
2129
|
name: "remove",
|
|
1967
|
-
description: "Remove a repo
|
|
2130
|
+
description: "Remove a repo from the group, then render its workspace"
|
|
1968
2131
|
},
|
|
1969
2132
|
args: {
|
|
1970
2133
|
path: {
|
|
1971
2134
|
type: "positional",
|
|
1972
|
-
description: "Repo path",
|
|
2135
|
+
description: "Repo path or name",
|
|
1973
2136
|
required: true
|
|
1974
2137
|
},
|
|
2138
|
+
...groupArgument,
|
|
1975
2139
|
...colorArgument
|
|
1976
2140
|
},
|
|
1977
2141
|
run({ args }) {
|
|
1978
|
-
|
|
1979
|
-
try {
|
|
1980
|
-
process.exitCode = groupRemove(args.path, io);
|
|
1981
|
-
} catch (error) {
|
|
1982
|
-
fail(io, error);
|
|
1983
|
-
}
|
|
2142
|
+
process.exitCode = groupRemove(args.path, processIo({ color: args.color }), { group: args.group });
|
|
1984
2143
|
}
|
|
1985
2144
|
}),
|
|
1986
2145
|
sync: defineCommand({
|
|
1987
2146
|
meta: {
|
|
1988
2147
|
name: "sync",
|
|
1989
|
-
description: "
|
|
2148
|
+
description: "Render the group's workspace (instructions link, generated settings)"
|
|
2149
|
+
},
|
|
2150
|
+
args: {
|
|
2151
|
+
...groupArgument,
|
|
2152
|
+
...colorArgument
|
|
1990
2153
|
},
|
|
1991
|
-
args: { ...colorArgument },
|
|
1992
2154
|
run({ args }) {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2155
|
+
process.exitCode = groupSync(processIo({ color: args.color }), { group: args.group });
|
|
2156
|
+
}
|
|
2157
|
+
}),
|
|
2158
|
+
edit: defineCommand({
|
|
2159
|
+
meta: {
|
|
2160
|
+
name: "edit",
|
|
2161
|
+
description: "Open the instructions (or group.json with --json) in $EDITOR, then sync"
|
|
2162
|
+
},
|
|
2163
|
+
args: {
|
|
2164
|
+
json: {
|
|
2165
|
+
type: "boolean",
|
|
2166
|
+
default: false,
|
|
2167
|
+
description: "Edit group.json instead"
|
|
2168
|
+
},
|
|
2169
|
+
...groupArgument
|
|
2170
|
+
},
|
|
2171
|
+
async run({ args }) {
|
|
2172
|
+
process.exitCode = await groupEdit(processIo(), {
|
|
2173
|
+
group: args.group,
|
|
2174
|
+
json: args.json,
|
|
2175
|
+
confirm: askYes
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
}),
|
|
2179
|
+
path: defineCommand({
|
|
2180
|
+
meta: {
|
|
2181
|
+
name: "path",
|
|
2182
|
+
description: "Print the workspace path (or the source with --source), for cd \"$(...)\""
|
|
2183
|
+
},
|
|
2184
|
+
args: {
|
|
2185
|
+
source: {
|
|
2186
|
+
type: "boolean",
|
|
2187
|
+
default: false,
|
|
2188
|
+
description: "The source folder instead"
|
|
2189
|
+
},
|
|
2190
|
+
workspace: {
|
|
2191
|
+
type: "boolean",
|
|
2192
|
+
default: false,
|
|
2193
|
+
description: "The workspace (default)"
|
|
2194
|
+
},
|
|
2195
|
+
...groupArgument
|
|
2196
|
+
},
|
|
2197
|
+
run({ args }) {
|
|
2198
|
+
process.exitCode = groupPath(processIo(), {
|
|
2199
|
+
group: args.group,
|
|
2200
|
+
source: args.source
|
|
2201
|
+
});
|
|
1999
2202
|
}
|
|
2000
2203
|
})
|
|
2001
2204
|
}
|
|
2002
2205
|
});
|
|
2206
|
+
async function askYes(question) {
|
|
2207
|
+
const { createInterface } = await import("node:readline/promises");
|
|
2208
|
+
const prompt = createInterface({
|
|
2209
|
+
input: process.stdin,
|
|
2210
|
+
output: process.stderr
|
|
2211
|
+
});
|
|
2212
|
+
try {
|
|
2213
|
+
return !/^n/i.test((await prompt.question(question)).trim());
|
|
2214
|
+
} finally {
|
|
2215
|
+
prompt.close();
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
function commaList(value) {
|
|
2219
|
+
return value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
2220
|
+
}
|
|
2003
2221
|
const groupsCommand = defineCommand({
|
|
2004
2222
|
meta: {
|
|
2005
2223
|
name: "groups",
|
|
2006
|
-
description: "
|
|
2224
|
+
description: "The groups of this machine"
|
|
2007
2225
|
},
|
|
2226
|
+
default: "list",
|
|
2008
2227
|
subCommands: {
|
|
2009
2228
|
list: defineCommand({
|
|
2010
2229
|
meta: {
|
|
2011
2230
|
name: "list",
|
|
2012
|
-
description: "
|
|
2231
|
+
description: "Groups with their repo and session counts"
|
|
2013
2232
|
},
|
|
2014
2233
|
args: { ...colorArgument },
|
|
2015
2234
|
run({ args }) {
|
|
2016
2235
|
process.exitCode = groupsList(processIo({ color: args.color }));
|
|
2017
2236
|
}
|
|
2018
2237
|
}),
|
|
2019
|
-
|
|
2238
|
+
create: defineCommand({
|
|
2020
2239
|
meta: {
|
|
2021
|
-
name: "
|
|
2022
|
-
description: "
|
|
2240
|
+
name: "create",
|
|
2241
|
+
description: "Create a group and render its workspace"
|
|
2023
2242
|
},
|
|
2024
2243
|
args: {
|
|
2025
|
-
|
|
2244
|
+
name: {
|
|
2026
2245
|
type: "positional",
|
|
2027
|
-
description: "Group name
|
|
2246
|
+
description: "Group name: a-z, 0-9 and -",
|
|
2028
2247
|
required: true
|
|
2029
2248
|
},
|
|
2249
|
+
repos: {
|
|
2250
|
+
type: "string",
|
|
2251
|
+
description: "Comma-separated repo paths"
|
|
2252
|
+
},
|
|
2030
2253
|
...colorArgument
|
|
2031
2254
|
},
|
|
2032
2255
|
run({ args }) {
|
|
2033
|
-
|
|
2256
|
+
const io = processIo({ color: args.color });
|
|
2257
|
+
process.exitCode = groupsErrors(io, () => groupsCreate(args.name, io, { repos: commaList(args.repos) }));
|
|
2034
2258
|
}
|
|
2035
2259
|
}),
|
|
2036
|
-
|
|
2260
|
+
rename: defineCommand({
|
|
2037
2261
|
meta: {
|
|
2038
|
-
name: "
|
|
2039
|
-
description: "
|
|
2262
|
+
name: "rename",
|
|
2263
|
+
description: "Rename a group with no running session; its workspace stays"
|
|
2264
|
+
},
|
|
2265
|
+
args: {
|
|
2266
|
+
from: {
|
|
2267
|
+
type: "positional",
|
|
2268
|
+
description: "Current name",
|
|
2269
|
+
required: true
|
|
2270
|
+
},
|
|
2271
|
+
to: {
|
|
2272
|
+
type: "positional",
|
|
2273
|
+
description: "New name",
|
|
2274
|
+
required: true
|
|
2275
|
+
}
|
|
2276
|
+
},
|
|
2277
|
+
run({ args }) {
|
|
2278
|
+
const io = processIo();
|
|
2279
|
+
process.exitCode = groupsErrors(io, () => groupsRename(args.from, args.to, io));
|
|
2280
|
+
}
|
|
2281
|
+
}),
|
|
2282
|
+
drop: defineCommand({
|
|
2283
|
+
meta: {
|
|
2284
|
+
name: "drop",
|
|
2285
|
+
description: "Archive the sessions of a group and remove its source, keeping its notes"
|
|
2286
|
+
},
|
|
2287
|
+
args: {
|
|
2288
|
+
name: {
|
|
2289
|
+
type: "positional",
|
|
2290
|
+
description: "Group name",
|
|
2291
|
+
required: true
|
|
2292
|
+
},
|
|
2293
|
+
purge: {
|
|
2294
|
+
type: "boolean",
|
|
2295
|
+
default: false,
|
|
2296
|
+
description: "Also delete its notes and its workspace"
|
|
2297
|
+
}
|
|
2040
2298
|
},
|
|
2041
|
-
args: { ...colorArgument },
|
|
2042
2299
|
run({ args }) {
|
|
2043
|
-
|
|
2300
|
+
const io = processIo();
|
|
2301
|
+
process.exitCode = groupsErrors(io, () => groupsDrop(args.name, io, { purge: args.purge }));
|
|
2044
2302
|
}
|
|
2045
2303
|
})
|
|
2046
2304
|
}
|
|
@@ -2123,7 +2381,6 @@ const main = defineCommand({
|
|
|
2123
2381
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2124
2382
|
},
|
|
2125
2383
|
subCommands: {
|
|
2126
|
-
init: initCommand,
|
|
2127
2384
|
status: statusCommand,
|
|
2128
2385
|
log: logCommand,
|
|
2129
2386
|
new: newCommand,
|