@rucher/cli 0.2.0-beta.2 → 0.2.0-beta.4
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 +851 -558
- 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, 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, sourceInstructions } 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";
|
|
@@ -17,10 +17,34 @@ function quietly(suggest) {
|
|
|
17
17
|
suggest();
|
|
18
18
|
} catch {}
|
|
19
19
|
}
|
|
20
|
+
function splitInlineValues(words) {
|
|
21
|
+
return words.flatMap((word, index) => {
|
|
22
|
+
const inline = index < words.length - 1 ? /^(--?[\w-]+)=(.*)$/.exec(word) : null;
|
|
23
|
+
return inline ? [inline[1], inline[2]] : [word];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function readTypedWords({ typedWords }) {
|
|
27
|
+
const typed = typedWords.slice(0, -1);
|
|
28
|
+
const passthrough = typed.indexOf("--");
|
|
29
|
+
const own = passthrough === -1 ? typed : typed.slice(0, passthrough);
|
|
30
|
+
const flag = own.findLastIndex((word) => word === "-g" || word === "--group");
|
|
31
|
+
return {
|
|
32
|
+
group: flag === -1 ? void 0 : own[flag + 1],
|
|
33
|
+
words: own.filter((_, index) => !(index > 0 && (own[index - 1] === "-g" || own[index - 1] === "--group")))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function inGroup(context) {
|
|
37
|
+
return {
|
|
38
|
+
cwd: context.cwd,
|
|
39
|
+
env: context.env,
|
|
40
|
+
group: readTypedWords(context).group
|
|
41
|
+
};
|
|
42
|
+
}
|
|
20
43
|
function suggestSessions(context, complete) {
|
|
21
44
|
quietly(() => {
|
|
22
|
-
const carnet = openCarnet(context);
|
|
45
|
+
const carnet = openCarnet(inGroup(context));
|
|
23
46
|
try {
|
|
47
|
+
const typed = readTypedWords(context).words;
|
|
24
48
|
const sessions = carnet.sessions.list({ includeTemp: true });
|
|
25
49
|
const suggestions = [...sessions.flatMap((session) => session.name ? [{
|
|
26
50
|
value: session.name,
|
|
@@ -29,7 +53,7 @@ function suggestSessions(context, complete) {
|
|
|
29
53
|
value: shortId(session.id),
|
|
30
54
|
description: session.status
|
|
31
55
|
}])];
|
|
32
|
-
for (const suggestion of suggestions) if (!
|
|
56
|
+
for (const suggestion of suggestions) if (!typed.includes(suggestion.value)) complete(suggestion.value, suggestion.description);
|
|
33
57
|
} finally {
|
|
34
58
|
carnet.close();
|
|
35
59
|
}
|
|
@@ -37,18 +61,18 @@ function suggestSessions(context, complete) {
|
|
|
37
61
|
}
|
|
38
62
|
function suggestGroups(context, complete) {
|
|
39
63
|
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);
|
|
64
|
+
for (const group of listGroups(context.env)) complete(group.name, group.workspace);
|
|
42
65
|
});
|
|
43
66
|
}
|
|
44
67
|
function suggestRepos(context, complete) {
|
|
45
68
|
quietly(() => {
|
|
46
|
-
for (const repo of
|
|
69
|
+
for (const repo of resolveGroup(inGroup(context)).group?.repos ?? []) complete(repo.path, repo.name);
|
|
47
70
|
});
|
|
48
71
|
}
|
|
49
72
|
function suggestRepoNames(context, complete) {
|
|
50
73
|
quietly(() => {
|
|
51
|
-
|
|
74
|
+
const { group } = resolveGroup(inGroup(context));
|
|
75
|
+
for (const repo of group ? groupRepoNames(group) : []) complete(repo, "");
|
|
52
76
|
});
|
|
53
77
|
}
|
|
54
78
|
function suggestNoteKinds(complete) {
|
|
@@ -56,7 +80,7 @@ function suggestNoteKinds(complete) {
|
|
|
56
80
|
}
|
|
57
81
|
function suggestNotes(context, complete) {
|
|
58
82
|
quietly(() => {
|
|
59
|
-
const carnet = openCarnet(context);
|
|
83
|
+
const carnet = openCarnet(inGroup(context));
|
|
60
84
|
try {
|
|
61
85
|
for (const note of carnet.notes.list()) complete(String(note.id), note.text.slice(0, 60));
|
|
62
86
|
} finally {
|
|
@@ -73,7 +97,7 @@ function suggestDirectories(context, complete) {
|
|
|
73
97
|
}
|
|
74
98
|
function processContext() {
|
|
75
99
|
const separator = process.argv.indexOf("--");
|
|
76
|
-
const typedWords = separator === -1 ? [] : process.argv.slice(separator + 1);
|
|
100
|
+
const typedWords = separator === -1 ? [] : splitInlineValues(process.argv.slice(separator + 1));
|
|
77
101
|
return {
|
|
78
102
|
cwd: process.cwd(),
|
|
79
103
|
env: process.env,
|
|
@@ -87,51 +111,112 @@ const directories = (complete) => suggestDirectories(processContext(), complete)
|
|
|
87
111
|
const repoNames = (complete) => suggestRepoNames(processContext(), complete);
|
|
88
112
|
const noteKinds = (complete) => suggestNoteKinds(complete);
|
|
89
113
|
const notes = (complete) => suggestNotes(processContext(), complete);
|
|
114
|
+
const group = { group: groups };
|
|
90
115
|
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 } }
|
|
116
|
+
status: { options: {
|
|
117
|
+
session: sessions,
|
|
118
|
+
...group
|
|
119
|
+
} },
|
|
120
|
+
log: { options: {
|
|
121
|
+
session: sessions,
|
|
122
|
+
...group
|
|
109
123
|
} },
|
|
124
|
+
new: { options: group },
|
|
125
|
+
tmp: { options: group },
|
|
126
|
+
resume: {
|
|
127
|
+
args: { session: sessions },
|
|
128
|
+
options: group
|
|
129
|
+
},
|
|
130
|
+
fork: {
|
|
131
|
+
args: { session: sessions },
|
|
132
|
+
options: group
|
|
133
|
+
},
|
|
134
|
+
sessions: {
|
|
135
|
+
options: group,
|
|
136
|
+
subCommands: {
|
|
137
|
+
list: { options: group },
|
|
138
|
+
merge: {
|
|
139
|
+
args: {
|
|
140
|
+
from: sessions,
|
|
141
|
+
into: sessions
|
|
142
|
+
},
|
|
143
|
+
options: group
|
|
144
|
+
},
|
|
145
|
+
move: {
|
|
146
|
+
args: { session: sessions },
|
|
147
|
+
options: {
|
|
148
|
+
to: groups,
|
|
149
|
+
...group
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
rename: {
|
|
153
|
+
args: { session: sessions },
|
|
154
|
+
options: group
|
|
155
|
+
},
|
|
156
|
+
promote: {
|
|
157
|
+
args: { session: sessions },
|
|
158
|
+
options: group
|
|
159
|
+
},
|
|
160
|
+
demote: {
|
|
161
|
+
args: { session: sessions },
|
|
162
|
+
options: group
|
|
163
|
+
},
|
|
164
|
+
drop: {
|
|
165
|
+
args: { session: sessions },
|
|
166
|
+
options: group
|
|
167
|
+
},
|
|
168
|
+
clean: { options: group }
|
|
169
|
+
}
|
|
170
|
+
},
|
|
110
171
|
notes: {
|
|
111
172
|
options: {
|
|
112
173
|
kind: noteKinds,
|
|
113
|
-
repo: repoNames
|
|
174
|
+
repo: repoNames,
|
|
175
|
+
...group
|
|
114
176
|
},
|
|
115
177
|
subCommands: {
|
|
116
178
|
list: { options: {
|
|
117
179
|
kind: noteKinds,
|
|
118
|
-
repo: repoNames
|
|
180
|
+
repo: repoNames,
|
|
181
|
+
...group
|
|
119
182
|
} },
|
|
120
|
-
show: {
|
|
183
|
+
show: {
|
|
184
|
+
args: { id: notes },
|
|
185
|
+
options: group
|
|
186
|
+
},
|
|
121
187
|
add: {
|
|
122
188
|
args: { kind: noteKinds },
|
|
123
|
-
options: {
|
|
189
|
+
options: {
|
|
190
|
+
repo: repoNames,
|
|
191
|
+
...group
|
|
192
|
+
}
|
|
124
193
|
},
|
|
125
194
|
drop: {
|
|
126
195
|
args: { id: notes },
|
|
127
|
-
options: {
|
|
196
|
+
options: {
|
|
197
|
+
"replaced-by": notes,
|
|
198
|
+
...group
|
|
199
|
+
}
|
|
128
200
|
}
|
|
129
201
|
}
|
|
130
202
|
},
|
|
131
|
-
groups: { subCommands: { forget: { args: { reference: groups } } } },
|
|
132
203
|
group: { subCommands: {
|
|
133
|
-
|
|
134
|
-
|
|
204
|
+
show: { options: group },
|
|
205
|
+
add: {
|
|
206
|
+
args: { path: directories },
|
|
207
|
+
options: group
|
|
208
|
+
},
|
|
209
|
+
remove: {
|
|
210
|
+
args: { path: repos },
|
|
211
|
+
options: group
|
|
212
|
+
},
|
|
213
|
+
sync: { options: group },
|
|
214
|
+
edit: { options: group },
|
|
215
|
+
path: { options: group }
|
|
216
|
+
} },
|
|
217
|
+
groups: { subCommands: {
|
|
218
|
+
rename: { args: { from: groups } },
|
|
219
|
+
drop: { args: { name: groups } }
|
|
135
220
|
} }
|
|
136
221
|
} };
|
|
137
222
|
async function setupCompletion(main) {
|
|
@@ -144,11 +229,17 @@ async function setupCompletion(main) {
|
|
|
144
229
|
const complete = visible["complete"];
|
|
145
230
|
if (complete) main.subCommands = {
|
|
146
231
|
...subCommands,
|
|
147
|
-
complete
|
|
232
|
+
complete: {
|
|
233
|
+
...complete,
|
|
234
|
+
run: (context) => {
|
|
235
|
+
context.rawArgs = splitInlineValues(context.rawArgs);
|
|
236
|
+
return complete.run?.(context);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
148
239
|
};
|
|
149
240
|
}
|
|
150
241
|
// package.json
|
|
151
|
-
var version = "0.2.0-beta.
|
|
242
|
+
var version = "0.2.0-beta.4";
|
|
152
243
|
// src/color.ts
|
|
153
244
|
function paint(io) {
|
|
154
245
|
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
@@ -160,61 +251,40 @@ function paint(io) {
|
|
|
160
251
|
cyan: style("cyan")
|
|
161
252
|
};
|
|
162
253
|
}
|
|
163
|
-
// src/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
254
|
+
// src/group-option.ts
|
|
255
|
+
const groupArgument = { group: {
|
|
256
|
+
type: "string",
|
|
257
|
+
alias: "g",
|
|
258
|
+
description: "Group name (default: from RUCHER_GROUP, the workspace or the repo you are in)"
|
|
259
|
+
} };
|
|
260
|
+
function announceGroup(io, resolution) {
|
|
261
|
+
if (!resolution.group) return;
|
|
262
|
+
if (resolution.origin === "workspace") io.stderr(`group ${resolution.group.name} (from its workspace)\n`);
|
|
263
|
+
else if (resolution.origin === "repo" && resolution.repo) io.stderr(`group ${resolution.group.name} (from ${resolution.repo.name})\n`);
|
|
169
264
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
const root = resolve(io.cwd, options.directory ?? ".");
|
|
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;
|
|
265
|
+
function warnNoGroup(carnet, io) {
|
|
266
|
+
if (!carnet.group) io.stderr("no group here: pass -g after the subcommand\n");
|
|
200
267
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const colors = paint(io);
|
|
204
|
-
const group = locateGroup({
|
|
268
|
+
function openCliCarnet(io, group) {
|
|
269
|
+
const { carnet, resolution } = openResolvedCarnet({
|
|
205
270
|
cwd: io.cwd,
|
|
206
|
-
env: io.env
|
|
271
|
+
env: io.env,
|
|
272
|
+
group
|
|
207
273
|
});
|
|
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}`);
|
|
274
|
+
announceGroup(io, resolution);
|
|
275
|
+
return carnet;
|
|
214
276
|
}
|
|
215
|
-
function
|
|
216
|
-
|
|
277
|
+
function currentGroup(io, group) {
|
|
278
|
+
const resolution = resolveGroup({
|
|
279
|
+
cwd: io.cwd,
|
|
280
|
+
env: io.env,
|
|
281
|
+
group
|
|
282
|
+
});
|
|
283
|
+
const found = requireGroup(resolution.group);
|
|
284
|
+
announceGroup(io, resolution);
|
|
285
|
+
return found;
|
|
217
286
|
}
|
|
287
|
+
// src/commands/group.ts
|
|
218
288
|
function carnetErrors(io, run) {
|
|
219
289
|
try {
|
|
220
290
|
return run();
|
|
@@ -226,81 +296,379 @@ function carnetErrors(io, run) {
|
|
|
226
296
|
throw error;
|
|
227
297
|
}
|
|
228
298
|
}
|
|
229
|
-
function
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
299
|
+
function rendered(group, io) {
|
|
300
|
+
const result = renderWorkspace(group, { env: io.env });
|
|
301
|
+
return [...result.written.map((path) => `written ${path}`), ...result.removed.map((path) => `removed ${path}`)];
|
|
302
|
+
}
|
|
303
|
+
function withChanges(line, changes) {
|
|
304
|
+
return `${line}${changes.length ? ` (${changes.join(", ")})` : ""}\n`;
|
|
305
|
+
}
|
|
306
|
+
function groupShow(io, options = {}) {
|
|
307
|
+
return carnetErrors(io, () => {
|
|
308
|
+
const colors = paint(io);
|
|
309
|
+
const group = currentGroup(io, options.group);
|
|
310
|
+
const repos = group.repos.length ? group.repos.map((repo) => ` ${repo.name} ${colors.dim(repo.path)}`).join("\n") : ` ${colors.dim("none")}`;
|
|
311
|
+
io.stdout(`${colors.bold(group.name)}\nsource: ${group.source}\nworkspace: ${group.workspace}\nrepos:\n${repos}\n`);
|
|
312
|
+
return 0;
|
|
233
313
|
});
|
|
314
|
+
}
|
|
315
|
+
function groupAdd(repo, io, options = {}) {
|
|
234
316
|
return carnetErrors(io, () => {
|
|
317
|
+
const found = currentGroup(io, options.group);
|
|
235
318
|
const path = resolve(io.cwd, repo);
|
|
236
|
-
const group = addGroupRepo(found.
|
|
237
|
-
io.stdout(
|
|
319
|
+
const group = addGroupRepo(found.name, path, io.env);
|
|
320
|
+
io.stdout(withChanges(`added ${basename(path)} to ${group.name}`, rendered(group, io)));
|
|
238
321
|
return 0;
|
|
239
322
|
});
|
|
240
323
|
}
|
|
241
|
-
function groupRemove(repo, io) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
324
|
+
function groupRemove(repo, io, options = {}) {
|
|
325
|
+
return carnetErrors(io, () => {
|
|
326
|
+
const found = currentGroup(io, options.group);
|
|
327
|
+
const group = removeGroupRepo(found.name, resolve(io.cwd, repo), io.env);
|
|
328
|
+
io.stdout(withChanges(`removed ${basename(repo)} from ${group.name}`, rendered(group, io)));
|
|
329
|
+
return 0;
|
|
245
330
|
});
|
|
331
|
+
}
|
|
332
|
+
function groupSync(io, options = {}) {
|
|
246
333
|
return carnetErrors(io, () => {
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
io.stdout(
|
|
334
|
+
const group = currentGroup(io, options.group);
|
|
335
|
+
const changes = rendered(group, io);
|
|
336
|
+
io.stdout(changes.length ? `${[`synced ${group.name}`, ...changes.map((change) => ` ${change}`)].join("\n")}\n` : `${group.name} already in sync\n`);
|
|
250
337
|
return 0;
|
|
251
338
|
});
|
|
252
339
|
}
|
|
253
|
-
function
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
340
|
+
function groupPath(io, options = {}) {
|
|
341
|
+
return carnetErrors(io, () => {
|
|
342
|
+
const group = currentGroup(io, options.group);
|
|
343
|
+
io.stdout(`${options.source ? group.source : group.workspace}\n`);
|
|
344
|
+
return 0;
|
|
257
345
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return
|
|
346
|
+
}
|
|
347
|
+
function editorCommand(env) {
|
|
348
|
+
return env.VISUAL || env.EDITOR || "vi";
|
|
349
|
+
}
|
|
350
|
+
function openEditorFor(io) {
|
|
351
|
+
return (file) => {
|
|
352
|
+
return spawnSync(`${editorCommand(io.env)} "$RUCHER_EDIT_FILE"`, {
|
|
353
|
+
shell: true,
|
|
354
|
+
stdio: "inherit",
|
|
355
|
+
env: {
|
|
356
|
+
...io.env,
|
|
357
|
+
RUCHER_EDIT_FILE: file
|
|
358
|
+
}
|
|
359
|
+
}).status ?? 1;
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function invalidGroupFile(name, io) {
|
|
363
|
+
try {
|
|
364
|
+
loadGroup(name, io.env);
|
|
365
|
+
return null;
|
|
366
|
+
} catch (error) {
|
|
367
|
+
return error instanceof Error ? error.message : String(error);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async function groupEdit(io, options = {}) {
|
|
371
|
+
let group;
|
|
372
|
+
let file;
|
|
373
|
+
try {
|
|
374
|
+
group = currentGroup(io, options.group);
|
|
375
|
+
file = join(group.source, options.json ? GROUP_FILE : sourceInstructions(group));
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (error instanceof CarnetError) {
|
|
378
|
+
io.stderr(`error: ${error.message}\n`);
|
|
379
|
+
return 1;
|
|
380
|
+
}
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
const original = readFileSync(file, "utf8");
|
|
384
|
+
const openEditor = options.openEditor ?? openEditorFor(io);
|
|
385
|
+
for (;;) {
|
|
386
|
+
if (openEditor(file) !== 0) {
|
|
387
|
+
io.stderr(`error: ${editorCommand(io.env)} exited with an error, nothing synced\n`);
|
|
388
|
+
return 1;
|
|
389
|
+
}
|
|
390
|
+
const problem = options.json ? invalidGroupFile(group.name, io) : null;
|
|
391
|
+
if (!problem) break;
|
|
392
|
+
io.stderr(`error: ${GROUP_FILE} is invalid: ${problem}\n`);
|
|
393
|
+
if (!options.confirm || !await options.confirm("Edit it again? [Y/n] ")) {
|
|
394
|
+
writeFileSync(file, original);
|
|
395
|
+
io.stderr(`restored the previous ${GROUP_FILE}\n`);
|
|
396
|
+
return 1;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return groupSync(io, { group: group.name });
|
|
400
|
+
}
|
|
401
|
+
// src/session.ts
|
|
402
|
+
var CliError = class extends Error {
|
|
403
|
+
hint;
|
|
404
|
+
constructor(message, hint) {
|
|
405
|
+
super(message);
|
|
406
|
+
this.hint = hint;
|
|
407
|
+
this.name = "CliError";
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
function findSession(carnet, reference) {
|
|
411
|
+
try {
|
|
412
|
+
return carnet.sessions.find(reference);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
415
|
+
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
416
|
+
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` : "pass a session name, id or id prefix, see rucher sessions --all");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function resolveSession(carnet, reference) {
|
|
420
|
+
if (reference) return findSession(carnet, reference);
|
|
421
|
+
const session = carnet.sessions.default();
|
|
422
|
+
if (!session) throw new CliError("No session in this group yet", "start a Claude Code session inside the group");
|
|
423
|
+
return session;
|
|
424
|
+
}
|
|
425
|
+
// src/commands/sessions.ts
|
|
426
|
+
function lastActive(at, now) {
|
|
427
|
+
const date = new Date(at);
|
|
428
|
+
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
429
|
+
}
|
|
430
|
+
function row(carnet, session, now) {
|
|
431
|
+
const open = carnet.agents.list(session.id).length;
|
|
432
|
+
return [
|
|
433
|
+
session.name ?? session.id.slice(0, 8),
|
|
434
|
+
session.kind,
|
|
435
|
+
session.status,
|
|
436
|
+
repoPathFor(carnet.group, session.cwd) ?? session.repo ?? "",
|
|
437
|
+
lastActive(session.lastActiveAt, now),
|
|
438
|
+
open ? `${open} agent${open > 1 ? "s" : ""}` : "",
|
|
439
|
+
session.purpose ?? ""
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
function sessionsOnce(carnet, io, options = {}) {
|
|
443
|
+
const colors = paint(io);
|
|
444
|
+
const sessions = carnet.sessions.list({
|
|
445
|
+
includeTemp: options.all,
|
|
446
|
+
includeArchived: options.all
|
|
447
|
+
});
|
|
448
|
+
warnNoGroup(carnet, io);
|
|
449
|
+
if (sessions.length === 0) {
|
|
450
|
+
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
451
|
+
if (carnet.group) io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
455
|
+
const rows = sessions.map((session) => ({
|
|
456
|
+
session,
|
|
457
|
+
cells: row(carnet, session, now)
|
|
458
|
+
}));
|
|
459
|
+
const widths = rows.reduce((current, { cells }) => cells.map((cell, column) => Math.max(current[column] ?? 0, cell.length)), []);
|
|
460
|
+
const lines = rows.map(({ session, cells }) => {
|
|
461
|
+
return cells.map((cell, column) => {
|
|
462
|
+
const padded = column < cells.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell;
|
|
463
|
+
if (column === 0) return colors.bold(padded);
|
|
464
|
+
if (column === 1 && session.kind === "temp") return colors.dim(padded);
|
|
465
|
+
if (column === 2 && session.status === "archived") return colors.dim(padded);
|
|
466
|
+
return padded;
|
|
467
|
+
}).join(" ").trimEnd();
|
|
468
|
+
});
|
|
469
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
470
|
+
}
|
|
471
|
+
function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
472
|
+
const from = findSession(carnet, fromReference);
|
|
473
|
+
const into = findSession(carnet, intoReference);
|
|
474
|
+
const result = carnet.sessions.merge(from.id, into.id);
|
|
475
|
+
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
476
|
+
const lines = [
|
|
477
|
+
`merged ${label(from)} into ${label(result.session)}`,
|
|
478
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
479
|
+
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
480
|
+
` events moved: ${result.movedEvents}`,
|
|
481
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`
|
|
482
|
+
];
|
|
483
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
484
|
+
}
|
|
485
|
+
function label(session) {
|
|
486
|
+
return session.name ?? shortId(session.id);
|
|
487
|
+
}
|
|
488
|
+
function groupNamed(name, io) {
|
|
489
|
+
if (!groupExists(name, io.env)) throw new CliError(`No group named "${name}"`, "see rucher groups list");
|
|
490
|
+
return loadGroup(name, io.env);
|
|
491
|
+
}
|
|
492
|
+
function sessionsMove(carnet, reference, groupReference, io, options = {}) {
|
|
493
|
+
const session = findSession(carnet, reference);
|
|
494
|
+
const target = groupNamed(groupReference, io).name;
|
|
495
|
+
const result = moveSession(carnet, session.id, target, options);
|
|
496
|
+
const into = result.into ? ` into ${label(result.into)}` : "";
|
|
497
|
+
const lines = [
|
|
498
|
+
`${options.dryRun ? "would move" : "moved"} ${label(session)} from ${groupLabel(carnet.group)} to ${target}${into}`,
|
|
499
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
500
|
+
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
501
|
+
` events moved: ${result.movedEvents}`,
|
|
502
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
503
|
+
...result.keptNotes ? [` notes kept in ${groupLabel(carnet.group)}: ${result.keptNotes}`] : []
|
|
504
|
+
];
|
|
505
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
506
|
+
}
|
|
507
|
+
function sessionsRename(carnet, reference, name, io) {
|
|
508
|
+
const session = carnet.sessions.rename(findSession(carnet, reference).id, name);
|
|
509
|
+
io.stdout(`renamed to ${session.name}; rucher resume ${session.name} gives Claude the same title\n`);
|
|
510
|
+
}
|
|
511
|
+
function sessionsPromote(carnet, reference, name, io) {
|
|
512
|
+
const session = carnet.sessions.promote(findSession(carnet, reference).id, name);
|
|
513
|
+
io.stdout(`${label(session)} is now active\n`);
|
|
514
|
+
}
|
|
515
|
+
function sessionsDemote(carnet, reference, io) {
|
|
516
|
+
const session = carnet.sessions.demote(findSession(carnet, reference).id);
|
|
517
|
+
io.stdout(`${label(session)} is now temp, cleaned by rucher sessions clean once idle\n`);
|
|
518
|
+
}
|
|
519
|
+
function purgeTranscripts(session, io) {
|
|
520
|
+
const files = hostById(session.host).transcriptFiles(session, io.env);
|
|
521
|
+
for (const file of files) {
|
|
522
|
+
rmSync(file, {
|
|
523
|
+
recursive: true,
|
|
524
|
+
force: true
|
|
525
|
+
});
|
|
526
|
+
io.stdout(` deleted ${file}\n`);
|
|
527
|
+
}
|
|
528
|
+
if (files.length === 0) io.stdout(" no transcript found\n");
|
|
529
|
+
}
|
|
530
|
+
function sessionsDrop(carnet, reference, io, options = {}) {
|
|
531
|
+
const session = findSession(carnet, reference);
|
|
532
|
+
if (options.purge && session.status === "running") throw new CliError(`Session ${label(session)} is running`, "drop it with --purge once it has ended");
|
|
533
|
+
carnet.sessions.drop(session.id);
|
|
534
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
535
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
536
|
+
}
|
|
537
|
+
const UNIT_MILLISECONDS = {
|
|
538
|
+
m: 6e4,
|
|
539
|
+
h: 36e5,
|
|
540
|
+
d: 864e5
|
|
541
|
+
};
|
|
542
|
+
function parseDuration(value) {
|
|
543
|
+
const match = /^(\d+(?:\.\d+)?)([mhd]?)$/.exec(value.trim());
|
|
544
|
+
if (!match) throw new CliError(`Invalid duration "${value}"`, "use a number of days, or 30m, 12h, 7d");
|
|
545
|
+
return Number(match[1]) * (UNIT_MILLISECONDS[match[2] || "d"] ?? 0);
|
|
546
|
+
}
|
|
547
|
+
function processIsAlive(processId) {
|
|
548
|
+
try {
|
|
549
|
+
process.kill(processId, 0);
|
|
550
|
+
return true;
|
|
551
|
+
} catch (error) {
|
|
552
|
+
return error.code === "EPERM";
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function sessionsClean(carnet, io, options = {}) {
|
|
556
|
+
const olderThan = parseDuration(options.olderThan ?? "7d");
|
|
557
|
+
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`);
|
|
558
|
+
const stale = carnet.sessions.staleTemp(olderThan);
|
|
559
|
+
if (stale.length === 0) {
|
|
560
|
+
io.stdout(`no temp session idle for more than ${options.olderThan ?? "7d"}\n`);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
for (const session of stale) {
|
|
564
|
+
if (options.dryRun) {
|
|
565
|
+
io.stdout(`would archive ${label(session)}${options.purge ? " and delete its transcript" : ""}\n`);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
carnet.sessions.drop(session.id);
|
|
569
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
570
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
571
|
+
}
|
|
261
572
|
}
|
|
262
573
|
// src/commands/groups.ts
|
|
263
|
-
function
|
|
264
|
-
return
|
|
574
|
+
function plural(count, word) {
|
|
575
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
265
576
|
}
|
|
266
577
|
function groupsList(io) {
|
|
267
578
|
const colors = paint(io);
|
|
268
|
-
const groups =
|
|
579
|
+
const groups = listGroups(io.env);
|
|
269
580
|
if (groups.length === 0) {
|
|
270
|
-
io.stdout(`${colors.dim("no
|
|
581
|
+
io.stdout(`${colors.dim("no group yet, create one with `rucher groups create <name>`")}\n`);
|
|
271
582
|
return 0;
|
|
272
583
|
}
|
|
584
|
+
const carnet = openGroupCarnet(null, { env: io.env });
|
|
585
|
+
const sessions = groupSessionCounts(carnet.db);
|
|
586
|
+
carnet.close();
|
|
273
587
|
const width = Math.max(...groups.map((group) => group.name.length));
|
|
274
|
-
const lines = groups.map((group) => `${colors.bold(group.name.padEnd(width))} ${group.
|
|
588
|
+
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
589
|
io.stdout(`${lines.join("\n")}\n`);
|
|
276
590
|
return 0;
|
|
277
591
|
}
|
|
278
|
-
function
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
592
|
+
function groupsCreate(name, io, options = {}) {
|
|
593
|
+
const colors = paint(io);
|
|
594
|
+
const group = createGroup(name, {
|
|
595
|
+
repos: options.repos?.map((repo) => resolve(io.cwd, repo)),
|
|
596
|
+
env: io.env
|
|
597
|
+
});
|
|
598
|
+
const result = renderWorkspace(group, { env: io.env });
|
|
599
|
+
const lines = [
|
|
600
|
+
`${colors.bold(group.name)} created`,
|
|
601
|
+
` source: ${group.source}`,
|
|
602
|
+
` workspace: ${group.workspace}`,
|
|
603
|
+
` repos: ${group.repos.length ? group.repos.map((repo) => repo.path).join(", ") : "none yet, add them with `rucher group add <path> -g " + group.name + "`"}`,
|
|
604
|
+
...result.written.map((path) => ` written ${path}`),
|
|
605
|
+
"",
|
|
606
|
+
"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.",
|
|
607
|
+
`Next: \`rucher group edit -g ${group.name}\` for its instructions, then \`rucher new <session> -g ${group.name}\`.`
|
|
608
|
+
];
|
|
609
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
293
610
|
return 0;
|
|
294
611
|
}
|
|
295
|
-
function
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
612
|
+
function liveSessions(carnet, isAlive) {
|
|
613
|
+
return carnet.sessions.list({ includeTemp: true }).filter((session) => session.status === "running" && session.hostPid !== null && isAlive(session.hostPid));
|
|
614
|
+
}
|
|
615
|
+
function refuseLive(carnet, action, isAlive) {
|
|
616
|
+
const live = liveSessions(carnet, isAlive);
|
|
617
|
+
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`);
|
|
618
|
+
}
|
|
619
|
+
function groupsRename(from, to, io, options = {}) {
|
|
620
|
+
const carnet = openGroupCarnet(loadGroup(from, io.env), { env: io.env });
|
|
621
|
+
try {
|
|
622
|
+
refuseLive(carnet, "rename", options.isAlive ?? processIsAlive);
|
|
623
|
+
const group = renameGroup(from, to, io.env);
|
|
624
|
+
try {
|
|
625
|
+
renameGroupRows(carnet.db, from, to);
|
|
626
|
+
} catch (error) {
|
|
627
|
+
renameGroup(to, from, io.env);
|
|
628
|
+
throw error;
|
|
629
|
+
}
|
|
630
|
+
io.stdout(`renamed ${from} to ${to}; its workspace stays at ${group.workspace}\n`);
|
|
299
631
|
return 0;
|
|
632
|
+
} finally {
|
|
633
|
+
carnet.close();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function groupsDrop(name, io, options = {}) {
|
|
637
|
+
const carnet = openGroupCarnet(loadGroup(name, io.env), { env: io.env });
|
|
638
|
+
try {
|
|
639
|
+
refuseLive(carnet, "drop", options.isAlive ?? processIsAlive);
|
|
640
|
+
const at = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
641
|
+
const archived = archiveGroupSessions(carnet.db, name, at);
|
|
642
|
+
const deletedNotes = options.purge ? deleteGroupNotes(carnet.db, name) : 0;
|
|
643
|
+
const group = dropGroup(name, {
|
|
644
|
+
purge: options.purge,
|
|
645
|
+
env: io.env
|
|
646
|
+
});
|
|
647
|
+
const lines = [
|
|
648
|
+
`dropped ${name}: source ${group.source} removed`,
|
|
649
|
+
` sessions archived: ${archived}`,
|
|
650
|
+
options.purge ? ` notes deleted: ${deletedNotes}; workspace ${group.workspace} removed` : ` notes and workspace kept; recreate the group under the same name to see them again`
|
|
651
|
+
];
|
|
652
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
653
|
+
return 0;
|
|
654
|
+
} finally {
|
|
655
|
+
carnet.close();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function groupsErrors(io, run) {
|
|
659
|
+
try {
|
|
660
|
+
return run();
|
|
661
|
+
} catch (error) {
|
|
662
|
+
if (error instanceof CliError) {
|
|
663
|
+
io.stderr(`error: ${error.message}${error.hint ? `\n ${error.hint}` : ""}\n`);
|
|
664
|
+
return 1;
|
|
665
|
+
}
|
|
666
|
+
if (error instanceof CarnetError) {
|
|
667
|
+
io.stderr(`error: ${error.message}\n`);
|
|
668
|
+
return 1;
|
|
669
|
+
}
|
|
670
|
+
throw error;
|
|
300
671
|
}
|
|
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
672
|
}
|
|
305
673
|
// src/commands/hook.ts
|
|
306
674
|
const host = claudeCode;
|
|
@@ -331,6 +699,8 @@ function withCarnet$1(payload, io, use) {
|
|
|
331
699
|
sessionId: payload.session_id
|
|
332
700
|
});
|
|
333
701
|
try {
|
|
702
|
+
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
703
|
+
if (!carnet.group && !io.env.RUCHER_SESSION_ID && !known) return;
|
|
334
704
|
use(carnet);
|
|
335
705
|
} finally {
|
|
336
706
|
carnet.close();
|
|
@@ -419,30 +789,6 @@ function sessionEnd(stdinText, io) {
|
|
|
419
789
|
});
|
|
420
790
|
});
|
|
421
791
|
}
|
|
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
792
|
// src/commands/log.ts
|
|
447
793
|
function formatEvents(events, io) {
|
|
448
794
|
const colors = paint(io);
|
|
@@ -487,7 +833,7 @@ function formatEventsMarkdown(events, title) {
|
|
|
487
833
|
return lines.join("\n");
|
|
488
834
|
}
|
|
489
835
|
function sessionTitle(carnet, session) {
|
|
490
|
-
return `${carnet.group
|
|
836
|
+
return `${groupLabel(carnet.group)} · ${session.name ?? session.id.slice(0, 8)}`;
|
|
491
837
|
}
|
|
492
838
|
function logOnce(carnet, io, options) {
|
|
493
839
|
const session = resolveSession(carnet, options.session);
|
|
@@ -542,7 +888,7 @@ function markdown(carnet, notes) {
|
|
|
542
888
|
});
|
|
543
889
|
return `## ${KIND_TITLES[kind]}\n\n${lines.join("\n")}`;
|
|
544
890
|
});
|
|
545
|
-
return `# Memory: ${carnet.group
|
|
891
|
+
return `# Memory: ${groupLabel(carnet.group)}\n\n${sections.join("\n\n") || "No notes."}\n`;
|
|
546
892
|
}
|
|
547
893
|
function notesList(carnet, io, options = {}) {
|
|
548
894
|
const notes = options.stale ? carnet.notes.stale(halfLife(io)) : carnet.notes.list({
|
|
@@ -557,8 +903,9 @@ function notesList(carnet, io, options = {}) {
|
|
|
557
903
|
return;
|
|
558
904
|
}
|
|
559
905
|
const colors = paint(io);
|
|
906
|
+
warnNoGroup(carnet, io);
|
|
560
907
|
if (notes.length === 0) {
|
|
561
|
-
io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
908
|
+
if (carnet.group) io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
562
909
|
return;
|
|
563
910
|
}
|
|
564
911
|
const blocks = grouped(notes).map(([kind, kindNotes]) => `${colors.bold(KIND_TITLES[kind])}\n${kindNotes.map((note) => noteLine(io, note)).join("\n")}`);
|
|
@@ -628,13 +975,13 @@ function splitPassthrough(rawArgs) {
|
|
|
628
975
|
function positionals(own) {
|
|
629
976
|
return own.filter((argument) => !argument.startsWith("-"));
|
|
630
977
|
}
|
|
631
|
-
function launchEnv(
|
|
978
|
+
function launchEnv(group, session, promptVersion, kind) {
|
|
632
979
|
return {
|
|
633
980
|
RUCHER_SESSION_ID: session.id,
|
|
634
981
|
RUCHER_PROMPT_VERSION: promptVersion,
|
|
635
982
|
RUCHER_SESSION_NAME: session.name ?? "",
|
|
636
|
-
|
|
637
|
-
|
|
983
|
+
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD: "1",
|
|
984
|
+
...group ? { RUCHER_GROUP: group.name } : {},
|
|
638
985
|
...kind ? { RUCHER_SESSION_KIND: kind } : {}
|
|
639
986
|
};
|
|
640
987
|
}
|
|
@@ -644,36 +991,60 @@ function planNew(carnet, io, options) {
|
|
|
644
991
|
id: randomUUID(),
|
|
645
992
|
kind: options.kind,
|
|
646
993
|
name: options.name,
|
|
647
|
-
cwd: carnet.group.
|
|
994
|
+
cwd: carnet.group?.workspace ?? io.cwd,
|
|
648
995
|
repo: repoNameFor(carnet.group, io.cwd)
|
|
649
996
|
});
|
|
650
997
|
const host = hostById(session.host);
|
|
998
|
+
if (carnet.group) renderWorkspace(carnet.group, {
|
|
999
|
+
env: io.env,
|
|
1000
|
+
host: session.host
|
|
1001
|
+
});
|
|
651
1002
|
const prompt = appendPromptFile(carnet.group, session, io.env);
|
|
652
1003
|
return {
|
|
653
1004
|
...host.launchCommand(session.id, {
|
|
654
1005
|
name: session.name,
|
|
655
1006
|
appendPromptFile: prompt.path,
|
|
1007
|
+
directories: repoDirectories(carnet.group),
|
|
656
1008
|
passthrough: options.passthrough
|
|
657
1009
|
}),
|
|
658
|
-
cwd: carnet.group.
|
|
659
|
-
env: launchEnv(carnet, session, prompt.version),
|
|
1010
|
+
cwd: carnet.group?.workspace ?? io.cwd,
|
|
1011
|
+
env: launchEnv(carnet.group, session, prompt.version),
|
|
660
1012
|
sessionId: session.id
|
|
661
1013
|
};
|
|
662
1014
|
}
|
|
663
|
-
function
|
|
664
|
-
return
|
|
1015
|
+
function repoDirectories(group) {
|
|
1016
|
+
return (group?.repos ?? []).map((repo) => repo.path).filter((path) => existsSync(path));
|
|
1017
|
+
}
|
|
1018
|
+
function sessionGroup(carnet, session, env) {
|
|
1019
|
+
if (!session.groupName || !isGroupName(session.groupName)) return null;
|
|
1020
|
+
return carnet.group?.name === session.groupName ? carnet.group : loadGroup(session.groupName, env);
|
|
1021
|
+
}
|
|
1022
|
+
function prepareSession(carnet, session, env) {
|
|
1023
|
+
const group = sessionGroup(carnet, session, env);
|
|
1024
|
+
if (group) renderWorkspace(group, {
|
|
1025
|
+
env,
|
|
1026
|
+
host: session.host
|
|
1027
|
+
});
|
|
1028
|
+
return group;
|
|
1029
|
+
}
|
|
1030
|
+
function sessionDirectory(session) {
|
|
1031
|
+
if (session.cwd && existsSync(session.cwd)) return session.cwd;
|
|
1032
|
+
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
1033
|
}
|
|
666
1034
|
function planResume(carnet, io, reference, passthrough = []) {
|
|
667
1035
|
const session = findSession(carnet, reference);
|
|
668
1036
|
if (session.status === "archived") io.stderr(`warning: session ${reference} is archived\n`);
|
|
669
|
-
const
|
|
1037
|
+
const group = prepareSession(carnet, session, io.env);
|
|
1038
|
+
const cwd = sessionDirectory(session);
|
|
1039
|
+
const prompt = appendPromptFile(group, session, io.env);
|
|
670
1040
|
return {
|
|
671
1041
|
...hostById(session.host).resumeCommand(session, {
|
|
672
1042
|
appendPromptFile: prompt.path,
|
|
1043
|
+
directories: repoDirectories(group),
|
|
673
1044
|
passthrough
|
|
674
1045
|
}),
|
|
675
|
-
cwd
|
|
676
|
-
env: launchEnv(
|
|
1046
|
+
cwd,
|
|
1047
|
+
env: launchEnv(group, session, prompt.version),
|
|
677
1048
|
sessionId: session.id
|
|
678
1049
|
};
|
|
679
1050
|
}
|
|
@@ -681,16 +1052,19 @@ function planFork(carnet, io, reference, options = {}) {
|
|
|
681
1052
|
if (options.active && !options.name) throw new CliError("An active fork needs a name", "rucher fork <session> <name> --active");
|
|
682
1053
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
683
1054
|
const parent = findSession(carnet, reference);
|
|
1055
|
+
const group = prepareSession(carnet, parent, io.env);
|
|
1056
|
+
const cwd = sessionDirectory(parent);
|
|
684
1057
|
const kind = options.active ? "active" : "temp";
|
|
685
1058
|
return {
|
|
686
1059
|
...hostById(parent.host).forkCommand(parent, {
|
|
687
1060
|
name: options.name,
|
|
688
|
-
appendPromptFile: appendPromptFile(
|
|
1061
|
+
appendPromptFile: appendPromptFile(group, parent, io.env).path,
|
|
1062
|
+
directories: repoDirectories(group),
|
|
689
1063
|
passthrough: options.passthrough
|
|
690
1064
|
}),
|
|
691
|
-
cwd
|
|
1065
|
+
cwd,
|
|
692
1066
|
env: {
|
|
693
|
-
...launchEnv(
|
|
1067
|
+
...launchEnv(group, parent, parent.promptVersion ?? "", kind),
|
|
694
1068
|
RUCHER_SESSION_NAME: options.name ?? ""
|
|
695
1069
|
},
|
|
696
1070
|
parentId: parent.id,
|
|
@@ -721,237 +1095,81 @@ function spawnLaunch(plan, env) {
|
|
|
721
1095
|
stdio: "inherit",
|
|
722
1096
|
env: {
|
|
723
1097
|
...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`);
|
|
1098
|
+
...plan.env
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
if (result.error) throw result.error;
|
|
1102
|
+
return result.status ?? 1;
|
|
893
1103
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1104
|
+
// src/commands/picker.ts
|
|
1105
|
+
function pickerSessions(carnet) {
|
|
1106
|
+
const sessions = carnet.sessions.list({ includeTemp: true });
|
|
1107
|
+
return [...sessions.filter((session) => session.name), ...sessions.filter((session) => !session.name)];
|
|
897
1108
|
}
|
|
898
|
-
function
|
|
899
|
-
const
|
|
900
|
-
|
|
1109
|
+
function lastUse(at, now) {
|
|
1110
|
+
const date = new Date(at);
|
|
1111
|
+
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
901
1112
|
}
|
|
902
|
-
function
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1113
|
+
function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
1114
|
+
const rows = sessions.map((session, index) => [
|
|
1115
|
+
String(index + 1),
|
|
1116
|
+
session.name ?? shortId(session.id),
|
|
1117
|
+
session.kind,
|
|
1118
|
+
session.status,
|
|
1119
|
+
lastUse(session.lastActiveAt, now),
|
|
1120
|
+
shortId(session.id)
|
|
1121
|
+
]);
|
|
1122
|
+
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
1123
|
+
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
912
1124
|
}
|
|
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);
|
|
1125
|
+
function hasFzf() {
|
|
1126
|
+
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
919
1127
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1128
|
+
function pickWithFzf(sessions, lines) {
|
|
1129
|
+
const result = spawnSync("fzf", [
|
|
1130
|
+
"--with-nth=2..",
|
|
1131
|
+
"--no-sort",
|
|
1132
|
+
"--prompt=session> "
|
|
1133
|
+
], {
|
|
1134
|
+
input: lines.join("\n"),
|
|
1135
|
+
stdio: [
|
|
1136
|
+
"pipe",
|
|
1137
|
+
"pipe",
|
|
1138
|
+
"inherit"
|
|
1139
|
+
],
|
|
1140
|
+
encoding: "utf8"
|
|
1141
|
+
});
|
|
1142
|
+
return sessions[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
929
1143
|
}
|
|
930
|
-
function
|
|
1144
|
+
async function pickFromList(sessions, lines) {
|
|
1145
|
+
process.stderr.write(`${lines.join("\n")}\n`);
|
|
1146
|
+
const prompt = createInterface({
|
|
1147
|
+
input: process.stdin,
|
|
1148
|
+
output: process.stderr
|
|
1149
|
+
});
|
|
931
1150
|
try {
|
|
932
|
-
|
|
933
|
-
return
|
|
934
|
-
}
|
|
935
|
-
|
|
1151
|
+
const answer = await prompt.question("session number> ");
|
|
1152
|
+
return sessions[Number(answer.trim()) - 1];
|
|
1153
|
+
} finally {
|
|
1154
|
+
prompt.close();
|
|
936
1155
|
}
|
|
937
1156
|
}
|
|
938
|
-
function
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
io.
|
|
953
|
-
|
|
954
|
-
}
|
|
1157
|
+
async function pickSession(carnet) {
|
|
1158
|
+
const sessions = pickerSessions(carnet);
|
|
1159
|
+
if (sessions.length === 0) throw new CliError("No session to resume in this group", "rucher new <name>");
|
|
1160
|
+
if (!process.stdin.isTTY) throw new CliError("No session given", "rucher resume <name, id or id prefix>");
|
|
1161
|
+
const lines = pickerLines(sessions);
|
|
1162
|
+
const picked = hasFzf() ? pickWithFzf(sessions, lines) : await pickFromList(sessions, lines);
|
|
1163
|
+
if (!picked) throw new CliError("No session picked");
|
|
1164
|
+
return picked;
|
|
1165
|
+
}
|
|
1166
|
+
// src/commands/serve.ts
|
|
1167
|
+
function serve(io) {
|
|
1168
|
+
serveCarnet({
|
|
1169
|
+
cwd: io.cwd,
|
|
1170
|
+
env: io.env,
|
|
1171
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
1172
|
+
});
|
|
955
1173
|
}
|
|
956
1174
|
// src/commands/watch-keys.ts
|
|
957
1175
|
const INITIAL_WATCH_STATE = {
|
|
@@ -1092,7 +1310,7 @@ function sessionName(session) {
|
|
|
1092
1310
|
function sessionLabel(carnet, session, columns) {
|
|
1093
1311
|
const name = sessionName(session);
|
|
1094
1312
|
const room = columns - Array.from(name).length - 3;
|
|
1095
|
-
return room > 1 ? `${name} · ${truncate(carnet.group
|
|
1313
|
+
return room > 1 ? `${name} · ${truncate(groupLabel(carnet.group), room)}` : name;
|
|
1096
1314
|
}
|
|
1097
1315
|
function sessionHeader(session, io) {
|
|
1098
1316
|
return paint(io).cyan(truncate(sessionName(session), io.columns));
|
|
@@ -1170,7 +1388,7 @@ function renderStatusView(carnet, io, options) {
|
|
|
1170
1388
|
});
|
|
1171
1389
|
const colors = paint(io);
|
|
1172
1390
|
const separator = " - ";
|
|
1173
|
-
const group = truncate(carnet.group
|
|
1391
|
+
const group = truncate(groupLabel(carnet.group), io.columns - time.length - 3);
|
|
1174
1392
|
return [
|
|
1175
1393
|
`${colors.dim(time)}${separator}${colors.cyan(group)}`,
|
|
1176
1394
|
"",
|
|
@@ -1317,37 +1535,6 @@ const sessionArgument = { session: {
|
|
|
1317
1535
|
alias: "s",
|
|
1318
1536
|
description: "Session name, id or id prefix (default: most recently active)"
|
|
1319
1537
|
} };
|
|
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
1538
|
const statusCommand = defineCommand({
|
|
1352
1539
|
meta: {
|
|
1353
1540
|
name: "status",
|
|
@@ -1371,15 +1558,13 @@ const statusCommand = defineCommand({
|
|
|
1371
1558
|
default: "1",
|
|
1372
1559
|
description: "Refresh interval in seconds with --watch"
|
|
1373
1560
|
},
|
|
1561
|
+
...groupArgument,
|
|
1374
1562
|
...colorArgument
|
|
1375
1563
|
},
|
|
1376
1564
|
async run({ args }) {
|
|
1377
1565
|
const io = processIo({ color: args.color });
|
|
1378
1566
|
try {
|
|
1379
|
-
const carnet =
|
|
1380
|
-
cwd: io.cwd,
|
|
1381
|
-
env: io.env
|
|
1382
|
-
});
|
|
1567
|
+
const carnet = openCliCarnet(io, args.group);
|
|
1383
1568
|
const options = {
|
|
1384
1569
|
session: args.session,
|
|
1385
1570
|
all: args.all
|
|
@@ -1426,15 +1611,13 @@ const logCommand = defineCommand({
|
|
|
1426
1611
|
default: false,
|
|
1427
1612
|
description: "Agent events only, without session starts and ends"
|
|
1428
1613
|
},
|
|
1614
|
+
...groupArgument,
|
|
1429
1615
|
...colorArgument
|
|
1430
1616
|
},
|
|
1431
1617
|
run({ args }) {
|
|
1432
1618
|
const io = processIo({ color: args.color });
|
|
1433
1619
|
try {
|
|
1434
|
-
logOnce(
|
|
1435
|
-
cwd: io.cwd,
|
|
1436
|
-
env: io.env
|
|
1437
|
-
}), io, {
|
|
1620
|
+
logOnce(openCliCarnet(io, args.group), io, {
|
|
1438
1621
|
session: args.session,
|
|
1439
1622
|
count: Number(args.count) || 20,
|
|
1440
1623
|
md: args.md,
|
|
@@ -1456,15 +1639,13 @@ const sessionsListCommand = defineCommand({
|
|
|
1456
1639
|
default: false,
|
|
1457
1640
|
description: "Include temp and archived sessions"
|
|
1458
1641
|
},
|
|
1642
|
+
...groupArgument,
|
|
1459
1643
|
...colorArgument
|
|
1460
1644
|
},
|
|
1461
1645
|
run({ args }) {
|
|
1462
1646
|
const io = processIo({ color: args.color });
|
|
1463
1647
|
try {
|
|
1464
|
-
sessionsOnce(
|
|
1465
|
-
cwd: io.cwd,
|
|
1466
|
-
env: io.env
|
|
1467
|
-
}), io, { all: args.all });
|
|
1648
|
+
sessionsOnce(openCliCarnet(io, args.group), io, { all: args.all });
|
|
1468
1649
|
} catch (error) {
|
|
1469
1650
|
fail(io, error);
|
|
1470
1651
|
}
|
|
@@ -1485,15 +1666,13 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1485
1666
|
type: "positional",
|
|
1486
1667
|
description: "Session that keeps everything (name, id or id prefix)",
|
|
1487
1668
|
required: true
|
|
1488
|
-
}
|
|
1669
|
+
},
|
|
1670
|
+
...groupArgument
|
|
1489
1671
|
},
|
|
1490
1672
|
run({ args }) {
|
|
1491
1673
|
const io = processIo();
|
|
1492
1674
|
try {
|
|
1493
|
-
const carnet =
|
|
1494
|
-
cwd: io.cwd,
|
|
1495
|
-
env: io.env
|
|
1496
|
-
});
|
|
1675
|
+
const carnet = openCliCarnet(io, args.group);
|
|
1497
1676
|
sessionsMerge(carnet, args.from, args.into, io);
|
|
1498
1677
|
carnet.close();
|
|
1499
1678
|
} catch (error) {
|
|
@@ -1517,11 +1696,12 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1517
1696
|
type: "positional",
|
|
1518
1697
|
description: "New name",
|
|
1519
1698
|
required: true
|
|
1520
|
-
}
|
|
1699
|
+
},
|
|
1700
|
+
...groupArgument
|
|
1521
1701
|
},
|
|
1522
1702
|
run({ args }) {
|
|
1523
1703
|
const io = processIo();
|
|
1524
|
-
withCarnet(io, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
1704
|
+
withCarnet(io, args.group, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
1525
1705
|
}
|
|
1526
1706
|
});
|
|
1527
1707
|
const sessionsPromoteCommand = defineCommand({
|
|
@@ -1535,11 +1715,12 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1535
1715
|
type: "positional",
|
|
1536
1716
|
description: "Name, when the session has none",
|
|
1537
1717
|
required: false
|
|
1538
|
-
}
|
|
1718
|
+
},
|
|
1719
|
+
...groupArgument
|
|
1539
1720
|
},
|
|
1540
1721
|
run({ args }) {
|
|
1541
1722
|
const io = processIo();
|
|
1542
|
-
withCarnet(io, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
1723
|
+
withCarnet(io, args.group, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
1543
1724
|
}
|
|
1544
1725
|
});
|
|
1545
1726
|
const sessionsDemoteCommand = defineCommand({
|
|
@@ -1547,10 +1728,13 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1547
1728
|
name: "demote",
|
|
1548
1729
|
description: "Make an active session temp, keeping its name"
|
|
1549
1730
|
},
|
|
1550
|
-
args: {
|
|
1731
|
+
args: {
|
|
1732
|
+
session: sessionReference,
|
|
1733
|
+
...groupArgument
|
|
1734
|
+
},
|
|
1551
1735
|
run({ args }) {
|
|
1552
1736
|
const io = processIo();
|
|
1553
|
-
withCarnet(io, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
1737
|
+
withCarnet(io, args.group, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
1554
1738
|
}
|
|
1555
1739
|
});
|
|
1556
1740
|
const purgeArgument = { purge: {
|
|
@@ -1565,11 +1749,12 @@ const sessionsDropCommand = defineCommand({
|
|
|
1565
1749
|
},
|
|
1566
1750
|
args: {
|
|
1567
1751
|
session: sessionReference,
|
|
1568
|
-
...purgeArgument
|
|
1752
|
+
...purgeArgument,
|
|
1753
|
+
...groupArgument
|
|
1569
1754
|
},
|
|
1570
1755
|
run({ args }) {
|
|
1571
1756
|
const io = processIo();
|
|
1572
|
-
withCarnet(io, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
1757
|
+
withCarnet(io, args.group, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
1573
1758
|
}
|
|
1574
1759
|
});
|
|
1575
1760
|
const sessionsMoveCommand = defineCommand({
|
|
@@ -1582,7 +1767,7 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1582
1767
|
to: {
|
|
1583
1768
|
type: "string",
|
|
1584
1769
|
required: true,
|
|
1585
|
-
description: "Target group
|
|
1770
|
+
description: "Target group name"
|
|
1586
1771
|
},
|
|
1587
1772
|
merge: {
|
|
1588
1773
|
type: "boolean",
|
|
@@ -1593,11 +1778,12 @@ const sessionsMoveCommand = defineCommand({
|
|
|
1593
1778
|
type: "boolean",
|
|
1594
1779
|
default: false,
|
|
1595
1780
|
description: "Show what would move"
|
|
1596
|
-
}
|
|
1781
|
+
},
|
|
1782
|
+
...groupArgument
|
|
1597
1783
|
},
|
|
1598
1784
|
run({ args }) {
|
|
1599
1785
|
const io = processIo();
|
|
1600
|
-
withCarnet(io, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
1786
|
+
withCarnet(io, args.group, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
1601
1787
|
merge: args.merge,
|
|
1602
1788
|
dryRun: args["dry-run"]
|
|
1603
1789
|
}));
|
|
@@ -1619,11 +1805,12 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1619
1805
|
type: "boolean",
|
|
1620
1806
|
default: false,
|
|
1621
1807
|
description: "Show what would be archived"
|
|
1622
|
-
}
|
|
1808
|
+
},
|
|
1809
|
+
...groupArgument
|
|
1623
1810
|
},
|
|
1624
1811
|
run({ args }) {
|
|
1625
1812
|
const io = processIo();
|
|
1626
|
-
withCarnet(io, (carnet) => sessionsClean(carnet, io, {
|
|
1813
|
+
withCarnet(io, args.group, (carnet) => sessionsClean(carnet, io, {
|
|
1627
1814
|
olderThan: args["older-than"],
|
|
1628
1815
|
purge: args.purge,
|
|
1629
1816
|
dryRun: args["dry-run"]
|
|
@@ -1635,6 +1822,7 @@ const sessionsCommand = defineCommand({
|
|
|
1635
1822
|
name: "sessions",
|
|
1636
1823
|
description: "List and manage the sessions of the group"
|
|
1637
1824
|
},
|
|
1825
|
+
args: { ...groupArgument },
|
|
1638
1826
|
default: "list",
|
|
1639
1827
|
subCommands: {
|
|
1640
1828
|
list: sessionsListCommand,
|
|
@@ -1647,12 +1835,9 @@ const sessionsCommand = defineCommand({
|
|
|
1647
1835
|
clean: sessionsCleanCommand
|
|
1648
1836
|
}
|
|
1649
1837
|
});
|
|
1650
|
-
function withCarnet(io, run) {
|
|
1838
|
+
function withCarnet(io, group, run) {
|
|
1651
1839
|
try {
|
|
1652
|
-
const carnet =
|
|
1653
|
-
cwd: io.cwd,
|
|
1654
|
-
env: io.env
|
|
1655
|
-
});
|
|
1840
|
+
const carnet = openCliCarnet(io, group);
|
|
1656
1841
|
try {
|
|
1657
1842
|
run(carnet);
|
|
1658
1843
|
} finally {
|
|
@@ -1699,11 +1884,12 @@ const notesListCommand = defineCommand({
|
|
|
1699
1884
|
default: false,
|
|
1700
1885
|
description: "Markdown output, a view only"
|
|
1701
1886
|
},
|
|
1887
|
+
...groupArgument,
|
|
1702
1888
|
...colorArgument
|
|
1703
1889
|
},
|
|
1704
1890
|
run({ args }) {
|
|
1705
1891
|
const io = processIo({ color: args.color });
|
|
1706
|
-
withCarnet(io, (carnet) => notesList(carnet, io, {
|
|
1892
|
+
withCarnet(io, args.group, (carnet) => notesList(carnet, io, {
|
|
1707
1893
|
all: args.all,
|
|
1708
1894
|
kind: args.kind,
|
|
1709
1895
|
repo: args.repo,
|
|
@@ -1721,14 +1907,15 @@ const notesShowCommand = defineCommand({
|
|
|
1721
1907
|
args: {
|
|
1722
1908
|
id: {
|
|
1723
1909
|
type: "positional",
|
|
1724
|
-
description: "Note
|
|
1910
|
+
description: "Note number",
|
|
1725
1911
|
required: true
|
|
1726
1912
|
},
|
|
1913
|
+
...groupArgument,
|
|
1727
1914
|
...colorArgument
|
|
1728
1915
|
},
|
|
1729
1916
|
run({ args }) {
|
|
1730
1917
|
const io = processIo({ color: args.color });
|
|
1731
|
-
withCarnet(io, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
1918
|
+
withCarnet(io, args.group, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
1732
1919
|
}
|
|
1733
1920
|
});
|
|
1734
1921
|
const notesAddCommand = defineCommand({
|
|
@@ -1751,11 +1938,12 @@ const notesAddCommand = defineCommand({
|
|
|
1751
1938
|
type: "string",
|
|
1752
1939
|
description: "Repo the note applies to (repeat for several)"
|
|
1753
1940
|
},
|
|
1941
|
+
...groupArgument,
|
|
1754
1942
|
...colorArgument
|
|
1755
1943
|
},
|
|
1756
1944
|
run({ args, rawArgs }) {
|
|
1757
1945
|
const io = processIo({ color: args.color });
|
|
1758
|
-
withCarnet(io, (carnet) => notesAdd(carnet, io, {
|
|
1946
|
+
withCarnet(io, args.group, (carnet) => notesAdd(carnet, io, {
|
|
1759
1947
|
kind: args.kind,
|
|
1760
1948
|
text: args.text,
|
|
1761
1949
|
repos: repoList(rawArgs)
|
|
@@ -1770,7 +1958,7 @@ const notesDropCommand = defineCommand({
|
|
|
1770
1958
|
args: {
|
|
1771
1959
|
id: {
|
|
1772
1960
|
type: "positional",
|
|
1773
|
-
description: "Note
|
|
1961
|
+
description: "Note number",
|
|
1774
1962
|
required: true
|
|
1775
1963
|
},
|
|
1776
1964
|
reason: {
|
|
@@ -1780,13 +1968,14 @@ const notesDropCommand = defineCommand({
|
|
|
1780
1968
|
},
|
|
1781
1969
|
"replaced-by": {
|
|
1782
1970
|
type: "string",
|
|
1783
|
-
description: "
|
|
1784
|
-
}
|
|
1971
|
+
description: "Number of the note that replaces it"
|
|
1972
|
+
},
|
|
1973
|
+
...groupArgument
|
|
1785
1974
|
},
|
|
1786
1975
|
run({ args }) {
|
|
1787
1976
|
const io = processIo();
|
|
1788
1977
|
const replacement = args["replaced-by"];
|
|
1789
|
-
withCarnet(io, (carnet) => notesDrop(carnet, io, parseNoteId(args.id), {
|
|
1978
|
+
withCarnet(io, args.group, (carnet) => notesDrop(carnet, io, parseNoteId(args.id), {
|
|
1790
1979
|
reason: args.reason,
|
|
1791
1980
|
replacedBy: replacement === void 0 ? void 0 : parseNoteId(replacement)
|
|
1792
1981
|
}));
|
|
@@ -1797,7 +1986,10 @@ const notesCommand = defineCommand({
|
|
|
1797
1986
|
name: "notes",
|
|
1798
1987
|
description: "The group's memory: learnings, decisions and dead ends"
|
|
1799
1988
|
},
|
|
1800
|
-
args:
|
|
1989
|
+
args: {
|
|
1990
|
+
...noteFilterArguments,
|
|
1991
|
+
...groupArgument
|
|
1992
|
+
},
|
|
1801
1993
|
default: "list",
|
|
1802
1994
|
subCommands: {
|
|
1803
1995
|
list: notesListCommand,
|
|
@@ -1806,20 +1998,14 @@ const notesCommand = defineCommand({
|
|
|
1806
1998
|
drop: notesDropCommand
|
|
1807
1999
|
}
|
|
1808
2000
|
});
|
|
1809
|
-
async function launch(io, plan) {
|
|
2001
|
+
async function launch(io, group, plan) {
|
|
1810
2002
|
try {
|
|
1811
|
-
const carnet =
|
|
1812
|
-
cwd: io.cwd,
|
|
1813
|
-
env: io.env
|
|
1814
|
-
});
|
|
2003
|
+
const carnet = openCliCarnet(io, group);
|
|
1815
2004
|
const launchPlan = await plan(carnet);
|
|
1816
2005
|
startLaunch(carnet, launchPlan);
|
|
1817
2006
|
carnet.close();
|
|
1818
2007
|
const exitCode = spawnLaunch(launchPlan, io.env);
|
|
1819
|
-
const after =
|
|
1820
|
-
cwd: io.cwd,
|
|
1821
|
-
env: io.env
|
|
1822
|
-
});
|
|
2008
|
+
const after = openGroupCarnet(carnet.group, { env: io.env });
|
|
1823
2009
|
finishLaunch(after, launchPlan);
|
|
1824
2010
|
after.close();
|
|
1825
2011
|
process.exitCode = exitCode;
|
|
@@ -1828,21 +2014,33 @@ async function launch(io, plan) {
|
|
|
1828
2014
|
}
|
|
1829
2015
|
}
|
|
1830
2016
|
const passthroughHelp = "Arguments after -- are passed to Claude Code";
|
|
2017
|
+
function withoutGroupOption(own) {
|
|
2018
|
+
const kept = [];
|
|
2019
|
+
for (let index = 0; index < own.length; index += 1) {
|
|
2020
|
+
const argument = own[index] ?? "";
|
|
2021
|
+
if (argument === "-g" || argument === "--group") index += 1;
|
|
2022
|
+
else if (!argument.startsWith("--group=") && !argument.startsWith("-g=")) kept.push(argument);
|
|
2023
|
+
}
|
|
2024
|
+
return kept;
|
|
2025
|
+
}
|
|
1831
2026
|
const newCommand = defineCommand({
|
|
1832
2027
|
meta: {
|
|
1833
2028
|
name: "new",
|
|
1834
2029
|
description: `Start a named, durable session. ${passthroughHelp}`
|
|
1835
2030
|
},
|
|
1836
|
-
args: {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
2031
|
+
args: {
|
|
2032
|
+
name: {
|
|
2033
|
+
type: "positional",
|
|
2034
|
+
description: "Session name",
|
|
2035
|
+
required: true
|
|
2036
|
+
},
|
|
2037
|
+
...groupArgument
|
|
2038
|
+
},
|
|
2039
|
+
async run({ args, rawArgs }) {
|
|
1842
2040
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1843
|
-
await launch(processIo(), (carnet) => planNew(carnet, processIo(), {
|
|
2041
|
+
await launch(processIo(), args.group, (carnet) => planNew(carnet, processIo(), {
|
|
1844
2042
|
kind: "active",
|
|
1845
|
-
name: positionals(own)[0],
|
|
2043
|
+
name: positionals(withoutGroupOption(own))[0],
|
|
1846
2044
|
passthrough
|
|
1847
2045
|
}));
|
|
1848
2046
|
}
|
|
@@ -1852,16 +2050,19 @@ const tmpCommand = defineCommand({
|
|
|
1852
2050
|
name: "tmp",
|
|
1853
2051
|
description: `Start a temporary session. ${passthroughHelp}`
|
|
1854
2052
|
},
|
|
1855
|
-
args: {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
2053
|
+
args: {
|
|
2054
|
+
name: {
|
|
2055
|
+
type: "positional",
|
|
2056
|
+
description: "Optional session name",
|
|
2057
|
+
required: false
|
|
2058
|
+
},
|
|
2059
|
+
...groupArgument
|
|
2060
|
+
},
|
|
2061
|
+
async run({ args, rawArgs }) {
|
|
1861
2062
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1862
|
-
await launch(processIo(), (carnet) => planNew(carnet, processIo(), {
|
|
2063
|
+
await launch(processIo(), args.group, (carnet) => planNew(carnet, processIo(), {
|
|
1863
2064
|
kind: "temp",
|
|
1864
|
-
name: positionals(own)[0],
|
|
2065
|
+
name: positionals(withoutGroupOption(own))[0],
|
|
1865
2066
|
passthrough
|
|
1866
2067
|
}));
|
|
1867
2068
|
}
|
|
@@ -1871,16 +2072,19 @@ const resumeCommand = defineCommand({
|
|
|
1871
2072
|
name: "resume",
|
|
1872
2073
|
description: `Resume a session in its host, or pick one when none is given. ${passthroughHelp}`
|
|
1873
2074
|
},
|
|
1874
|
-
args: {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
2075
|
+
args: {
|
|
2076
|
+
session: {
|
|
2077
|
+
type: "positional",
|
|
2078
|
+
description: "Session name, id or id prefix",
|
|
2079
|
+
required: false
|
|
2080
|
+
},
|
|
2081
|
+
...groupArgument
|
|
2082
|
+
},
|
|
2083
|
+
async run({ args, rawArgs }) {
|
|
1880
2084
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1881
2085
|
const io = processIo();
|
|
1882
|
-
await launch(io, async (carnet) => {
|
|
1883
|
-
const reference = positionals(own)[0] ?? (await pickSession(carnet)).id;
|
|
2086
|
+
await launch(io, args.group, async (carnet) => {
|
|
2087
|
+
const reference = positionals(withoutGroupOption(own))[0] ?? (await pickSession(carnet)).id;
|
|
1884
2088
|
return planResume(carnet, io, reference, passthrough);
|
|
1885
2089
|
});
|
|
1886
2090
|
}
|
|
@@ -1905,13 +2109,14 @@ const forkCommand = defineCommand({
|
|
|
1905
2109
|
type: "boolean",
|
|
1906
2110
|
default: false,
|
|
1907
2111
|
description: "Make the new session durable (needs a name)"
|
|
1908
|
-
}
|
|
2112
|
+
},
|
|
2113
|
+
...groupArgument
|
|
1909
2114
|
},
|
|
1910
|
-
async run({ rawArgs }) {
|
|
2115
|
+
async run({ args, rawArgs }) {
|
|
1911
2116
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
1912
|
-
const [reference, name] = positionals(own);
|
|
2117
|
+
const [reference, name] = positionals(withoutGroupOption(own));
|
|
1913
2118
|
const io = processIo();
|
|
1914
|
-
await launch(io, (carnet) => planFork(carnet, io, reference ?? "", {
|
|
2119
|
+
await launch(io, args.group, (carnet) => planFork(carnet, io, reference ?? "", {
|
|
1915
2120
|
name,
|
|
1916
2121
|
active: own.includes("--active"),
|
|
1917
2122
|
passthrough
|
|
@@ -1921,28 +2126,26 @@ const forkCommand = defineCommand({
|
|
|
1921
2126
|
const groupCommand = defineCommand({
|
|
1922
2127
|
meta: {
|
|
1923
2128
|
name: "group",
|
|
1924
|
-
description: "
|
|
2129
|
+
description: "The current group: show it, add or remove repos, render, edit its instructions"
|
|
1925
2130
|
},
|
|
1926
2131
|
subCommands: {
|
|
1927
2132
|
show: defineCommand({
|
|
1928
2133
|
meta: {
|
|
1929
2134
|
name: "show",
|
|
1930
|
-
description: "Name,
|
|
2135
|
+
description: "Name, source, workspace and repos of the group"
|
|
2136
|
+
},
|
|
2137
|
+
args: {
|
|
2138
|
+
...groupArgument,
|
|
2139
|
+
...colorArgument
|
|
1931
2140
|
},
|
|
1932
|
-
args: { ...colorArgument },
|
|
1933
2141
|
run({ args }) {
|
|
1934
|
-
|
|
1935
|
-
try {
|
|
1936
|
-
process.exitCode = groupShow(io);
|
|
1937
|
-
} catch (error) {
|
|
1938
|
-
fail(io, error);
|
|
1939
|
-
}
|
|
2142
|
+
process.exitCode = groupShow(processIo({ color: args.color }), { group: args.group });
|
|
1940
2143
|
}
|
|
1941
2144
|
}),
|
|
1942
2145
|
add: defineCommand({
|
|
1943
2146
|
meta: {
|
|
1944
2147
|
name: "add",
|
|
1945
|
-
description: "Add a repo path to the
|
|
2148
|
+
description: "Add a repo path to the group, then render its workspace"
|
|
1946
2149
|
},
|
|
1947
2150
|
args: {
|
|
1948
2151
|
path: {
|
|
@@ -1950,97 +2153,188 @@ const groupCommand = defineCommand({
|
|
|
1950
2153
|
description: "Repo path",
|
|
1951
2154
|
required: true
|
|
1952
2155
|
},
|
|
2156
|
+
...groupArgument,
|
|
1953
2157
|
...colorArgument
|
|
1954
2158
|
},
|
|
1955
2159
|
run({ args }) {
|
|
1956
|
-
|
|
1957
|
-
try {
|
|
1958
|
-
process.exitCode = groupAdd(args.path, io);
|
|
1959
|
-
} catch (error) {
|
|
1960
|
-
fail(io, error);
|
|
1961
|
-
}
|
|
2160
|
+
process.exitCode = groupAdd(args.path, processIo({ color: args.color }), { group: args.group });
|
|
1962
2161
|
}
|
|
1963
2162
|
}),
|
|
1964
2163
|
remove: defineCommand({
|
|
1965
2164
|
meta: {
|
|
1966
2165
|
name: "remove",
|
|
1967
|
-
description: "Remove a repo
|
|
2166
|
+
description: "Remove a repo from the group, then render its workspace"
|
|
1968
2167
|
},
|
|
1969
2168
|
args: {
|
|
1970
2169
|
path: {
|
|
1971
2170
|
type: "positional",
|
|
1972
|
-
description: "Repo path",
|
|
2171
|
+
description: "Repo path or name",
|
|
1973
2172
|
required: true
|
|
1974
2173
|
},
|
|
2174
|
+
...groupArgument,
|
|
1975
2175
|
...colorArgument
|
|
1976
2176
|
},
|
|
1977
2177
|
run({ args }) {
|
|
1978
|
-
|
|
1979
|
-
try {
|
|
1980
|
-
process.exitCode = groupRemove(args.path, io);
|
|
1981
|
-
} catch (error) {
|
|
1982
|
-
fail(io, error);
|
|
1983
|
-
}
|
|
2178
|
+
process.exitCode = groupRemove(args.path, processIo({ color: args.color }), { group: args.group });
|
|
1984
2179
|
}
|
|
1985
2180
|
}),
|
|
1986
2181
|
sync: defineCommand({
|
|
1987
2182
|
meta: {
|
|
1988
2183
|
name: "sync",
|
|
1989
|
-
description: "
|
|
2184
|
+
description: "Render the group's workspace (instruction copies, generated settings)"
|
|
2185
|
+
},
|
|
2186
|
+
args: {
|
|
2187
|
+
...groupArgument,
|
|
2188
|
+
...colorArgument
|
|
1990
2189
|
},
|
|
1991
|
-
args: { ...colorArgument },
|
|
1992
2190
|
run({ args }) {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2191
|
+
process.exitCode = groupSync(processIo({ color: args.color }), { group: args.group });
|
|
2192
|
+
}
|
|
2193
|
+
}),
|
|
2194
|
+
edit: defineCommand({
|
|
2195
|
+
meta: {
|
|
2196
|
+
name: "edit",
|
|
2197
|
+
description: "Open the instructions (or group.json with --json) in $EDITOR, then sync"
|
|
2198
|
+
},
|
|
2199
|
+
args: {
|
|
2200
|
+
json: {
|
|
2201
|
+
type: "boolean",
|
|
2202
|
+
default: false,
|
|
2203
|
+
description: "Edit group.json instead"
|
|
2204
|
+
},
|
|
2205
|
+
...groupArgument
|
|
2206
|
+
},
|
|
2207
|
+
async run({ args }) {
|
|
2208
|
+
process.exitCode = await groupEdit(processIo(), {
|
|
2209
|
+
group: args.group,
|
|
2210
|
+
json: args.json,
|
|
2211
|
+
confirm: askYes
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
}),
|
|
2215
|
+
path: defineCommand({
|
|
2216
|
+
meta: {
|
|
2217
|
+
name: "path",
|
|
2218
|
+
description: "Print the workspace path (or the source with --source), for cd \"$(...)\""
|
|
2219
|
+
},
|
|
2220
|
+
args: {
|
|
2221
|
+
source: {
|
|
2222
|
+
type: "boolean",
|
|
2223
|
+
default: false,
|
|
2224
|
+
description: "The source folder instead"
|
|
2225
|
+
},
|
|
2226
|
+
workspace: {
|
|
2227
|
+
type: "boolean",
|
|
2228
|
+
default: false,
|
|
2229
|
+
description: "The workspace (default)"
|
|
2230
|
+
},
|
|
2231
|
+
...groupArgument
|
|
2232
|
+
},
|
|
2233
|
+
run({ args }) {
|
|
2234
|
+
process.exitCode = groupPath(processIo(), {
|
|
2235
|
+
group: args.group,
|
|
2236
|
+
source: args.source
|
|
2237
|
+
});
|
|
1999
2238
|
}
|
|
2000
2239
|
})
|
|
2001
2240
|
}
|
|
2002
2241
|
});
|
|
2242
|
+
async function askYes(question) {
|
|
2243
|
+
const { createInterface } = await import("node:readline/promises");
|
|
2244
|
+
const prompt = createInterface({
|
|
2245
|
+
input: process.stdin,
|
|
2246
|
+
output: process.stderr
|
|
2247
|
+
});
|
|
2248
|
+
try {
|
|
2249
|
+
return !/^n/i.test((await prompt.question(question)).trim());
|
|
2250
|
+
} finally {
|
|
2251
|
+
prompt.close();
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
function commaList(value) {
|
|
2255
|
+
return value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
2256
|
+
}
|
|
2003
2257
|
const groupsCommand = defineCommand({
|
|
2004
2258
|
meta: {
|
|
2005
2259
|
name: "groups",
|
|
2006
|
-
description: "
|
|
2260
|
+
description: "The groups of this machine"
|
|
2007
2261
|
},
|
|
2262
|
+
default: "list",
|
|
2008
2263
|
subCommands: {
|
|
2009
2264
|
list: defineCommand({
|
|
2010
2265
|
meta: {
|
|
2011
2266
|
name: "list",
|
|
2012
|
-
description: "
|
|
2267
|
+
description: "Groups with their repo and session counts"
|
|
2013
2268
|
},
|
|
2014
2269
|
args: { ...colorArgument },
|
|
2015
2270
|
run({ args }) {
|
|
2016
2271
|
process.exitCode = groupsList(processIo({ color: args.color }));
|
|
2017
2272
|
}
|
|
2018
2273
|
}),
|
|
2019
|
-
|
|
2274
|
+
create: defineCommand({
|
|
2020
2275
|
meta: {
|
|
2021
|
-
name: "
|
|
2022
|
-
description: "
|
|
2276
|
+
name: "create",
|
|
2277
|
+
description: "Create a group and render its workspace"
|
|
2023
2278
|
},
|
|
2024
2279
|
args: {
|
|
2025
|
-
|
|
2280
|
+
name: {
|
|
2026
2281
|
type: "positional",
|
|
2027
|
-
description: "Group name
|
|
2282
|
+
description: "Group name: a-z, 0-9 and -",
|
|
2028
2283
|
required: true
|
|
2029
2284
|
},
|
|
2285
|
+
repos: {
|
|
2286
|
+
type: "string",
|
|
2287
|
+
description: "Comma-separated repo paths"
|
|
2288
|
+
},
|
|
2030
2289
|
...colorArgument
|
|
2031
2290
|
},
|
|
2032
2291
|
run({ args }) {
|
|
2033
|
-
|
|
2292
|
+
const io = processIo({ color: args.color });
|
|
2293
|
+
process.exitCode = groupsErrors(io, () => groupsCreate(args.name, io, { repos: commaList(args.repos) }));
|
|
2034
2294
|
}
|
|
2035
2295
|
}),
|
|
2036
|
-
|
|
2296
|
+
rename: defineCommand({
|
|
2037
2297
|
meta: {
|
|
2038
|
-
name: "
|
|
2039
|
-
description: "
|
|
2298
|
+
name: "rename",
|
|
2299
|
+
description: "Rename a group with no running session; its workspace stays"
|
|
2300
|
+
},
|
|
2301
|
+
args: {
|
|
2302
|
+
from: {
|
|
2303
|
+
type: "positional",
|
|
2304
|
+
description: "Current name",
|
|
2305
|
+
required: true
|
|
2306
|
+
},
|
|
2307
|
+
to: {
|
|
2308
|
+
type: "positional",
|
|
2309
|
+
description: "New name",
|
|
2310
|
+
required: true
|
|
2311
|
+
}
|
|
2312
|
+
},
|
|
2313
|
+
run({ args }) {
|
|
2314
|
+
const io = processIo();
|
|
2315
|
+
process.exitCode = groupsErrors(io, () => groupsRename(args.from, args.to, io));
|
|
2316
|
+
}
|
|
2317
|
+
}),
|
|
2318
|
+
drop: defineCommand({
|
|
2319
|
+
meta: {
|
|
2320
|
+
name: "drop",
|
|
2321
|
+
description: "Archive the sessions of a group and remove its source, keeping its notes"
|
|
2322
|
+
},
|
|
2323
|
+
args: {
|
|
2324
|
+
name: {
|
|
2325
|
+
type: "positional",
|
|
2326
|
+
description: "Group name",
|
|
2327
|
+
required: true
|
|
2328
|
+
},
|
|
2329
|
+
purge: {
|
|
2330
|
+
type: "boolean",
|
|
2331
|
+
default: false,
|
|
2332
|
+
description: "Also delete its notes and its workspace"
|
|
2333
|
+
}
|
|
2040
2334
|
},
|
|
2041
|
-
args: { ...colorArgument },
|
|
2042
2335
|
run({ args }) {
|
|
2043
|
-
|
|
2336
|
+
const io = processIo();
|
|
2337
|
+
process.exitCode = groupsErrors(io, () => groupsDrop(args.name, io, { purge: args.purge }));
|
|
2044
2338
|
}
|
|
2045
2339
|
})
|
|
2046
2340
|
}
|
|
@@ -2123,7 +2417,6 @@ const main = defineCommand({
|
|
|
2123
2417
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2124
2418
|
},
|
|
2125
2419
|
subCommands: {
|
|
2126
|
-
init: initCommand,
|
|
2127
2420
|
status: statusCommand,
|
|
2128
2421
|
log: logCommand,
|
|
2129
2422
|
new: newCommand,
|