@rucher/cli 0.2.0-beta.3 → 0.2.0-beta.5
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 +4 -4
- package/dist/cli.mjs +878 -879
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import { defineCommand, runMain } from "citty";
|
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import tab from "@bomb.sh/tab/citty";
|
|
6
|
-
import { CarnetError,
|
|
7
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { CarnetError, LEGEND, NOTES_HEADER, NOTE_KINDS, SIMILAR_PREFIX, SUBAGENT_RULES, WORKSPACE_FILE, addWorkspaceRepo, ambiguousWorkspaceContext, appendPromptFile, archiveWorkspaceSessions, claudeCode, createWorkspace, definitionInstructions, deleteWorkspaceNotes, dropWorkspace, formatClock, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById, isWorkspaceName, listWorkspaces, loadWorkspace, memoryHalfLife, moveSession, openCarnet, openResolvedCarnet, openWorkspaceCarnet, removeWorkspaceRepo, renderRunDirectory, renderSections, repoNameFor, repoPathFor, requireWorkspace, resolveWorkspace, shortId, workspaceExists, workspaceLabel, workspaceRepoNames, workspaceSessionCounts } from "@rucher/carnet";
|
|
8
7
|
import { styleText } from "node:util";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
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.lastIndexOf("--ws");
|
|
31
|
+
return {
|
|
32
|
+
workspace: flag === -1 ? void 0 : own[flag + 1],
|
|
33
|
+
words: own.filter((_, index) => !(index > 0 && own[index - 1] === "--ws"))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function inWorkspace(context) {
|
|
37
|
+
return {
|
|
38
|
+
cwd: context.cwd,
|
|
39
|
+
env: context.env,
|
|
40
|
+
workspace: readTypedWords(context).workspace
|
|
41
|
+
};
|
|
42
|
+
}
|
|
20
43
|
function suggestSessions(context, complete) {
|
|
21
44
|
quietly(() => {
|
|
22
|
-
const carnet = openCarnet(context);
|
|
45
|
+
const carnet = openCarnet(inWorkspace(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,26 +53,26 @@ 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
|
}
|
|
36
60
|
});
|
|
37
61
|
}
|
|
38
|
-
function
|
|
62
|
+
function suggestWorkspaces(context, complete) {
|
|
39
63
|
quietly(() => {
|
|
40
|
-
for (const
|
|
64
|
+
for (const workspace of listWorkspaces(context.env)) complete(workspace.name, workspace.runDirectory);
|
|
41
65
|
});
|
|
42
66
|
}
|
|
43
67
|
function suggestRepos(context, complete) {
|
|
44
68
|
quietly(() => {
|
|
45
|
-
for (const repo of
|
|
69
|
+
for (const repo of resolveWorkspace(inWorkspace(context)).workspace?.repos ?? []) complete(repo.path, repo.name);
|
|
46
70
|
});
|
|
47
71
|
}
|
|
48
72
|
function suggestRepoNames(context, complete) {
|
|
49
73
|
quietly(() => {
|
|
50
|
-
const {
|
|
51
|
-
for (const repo of
|
|
74
|
+
const { workspace } = resolveWorkspace(inWorkspace(context));
|
|
75
|
+
for (const repo of workspace ? workspaceRepoNames(workspace) : []) 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(inWorkspace(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,
|
|
@@ -81,571 +105,152 @@ function processContext() {
|
|
|
81
105
|
};
|
|
82
106
|
}
|
|
83
107
|
const sessions = (complete) => suggestSessions(processContext(), complete);
|
|
84
|
-
const
|
|
108
|
+
const workspaces = (complete) => suggestWorkspaces(processContext(), complete);
|
|
85
109
|
const repos = (complete) => suggestRepos(processContext(), complete);
|
|
86
110
|
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);
|
|
90
|
-
const
|
|
114
|
+
const workspace = { ws: workspaces };
|
|
91
115
|
const completionConfig = { subCommands: {
|
|
92
116
|
status: { options: {
|
|
93
117
|
session: sessions,
|
|
94
|
-
...
|
|
118
|
+
...workspace
|
|
95
119
|
} },
|
|
96
120
|
log: { options: {
|
|
97
121
|
session: sessions,
|
|
98
|
-
...
|
|
122
|
+
...workspace
|
|
99
123
|
} },
|
|
100
|
-
new: { options:
|
|
101
|
-
tmp: { options:
|
|
124
|
+
new: { options: workspace },
|
|
125
|
+
tmp: { options: workspace },
|
|
102
126
|
resume: {
|
|
103
127
|
args: { session: sessions },
|
|
104
|
-
options:
|
|
128
|
+
options: workspace
|
|
105
129
|
},
|
|
106
130
|
fork: {
|
|
107
131
|
args: { session: sessions },
|
|
108
|
-
options:
|
|
132
|
+
options: workspace
|
|
109
133
|
},
|
|
110
134
|
sessions: {
|
|
111
|
-
options:
|
|
112
|
-
subCommands: {
|
|
113
|
-
list: { options:
|
|
114
|
-
merge: {
|
|
115
|
-
args: {
|
|
116
|
-
from: sessions,
|
|
117
|
-
into: sessions
|
|
118
|
-
},
|
|
119
|
-
options:
|
|
120
|
-
},
|
|
121
|
-
move: {
|
|
122
|
-
args: { session: sessions },
|
|
123
|
-
options: {
|
|
124
|
-
to:
|
|
125
|
-
...
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
rename: {
|
|
129
|
-
args: { session: sessions },
|
|
130
|
-
options:
|
|
131
|
-
},
|
|
132
|
-
promote: {
|
|
133
|
-
args: { session: sessions },
|
|
134
|
-
options:
|
|
135
|
-
},
|
|
136
|
-
demote: {
|
|
137
|
-
args: { session: sessions },
|
|
138
|
-
options:
|
|
139
|
-
},
|
|
140
|
-
drop: {
|
|
141
|
-
args: { session: sessions },
|
|
142
|
-
options:
|
|
143
|
-
},
|
|
144
|
-
clean: { options:
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
notes: {
|
|
148
|
-
options: {
|
|
149
|
-
kind: noteKinds,
|
|
150
|
-
repo: repoNames,
|
|
151
|
-
...group
|
|
152
|
-
},
|
|
153
|
-
subCommands: {
|
|
154
|
-
list: { options: {
|
|
155
|
-
kind: noteKinds,
|
|
156
|
-
repo: repoNames,
|
|
157
|
-
...group
|
|
158
|
-
} },
|
|
159
|
-
show: {
|
|
160
|
-
args: { id: notes },
|
|
161
|
-
options: group
|
|
162
|
-
},
|
|
163
|
-
add: {
|
|
164
|
-
args: { kind: noteKinds },
|
|
165
|
-
options: {
|
|
166
|
-
repo: repoNames,
|
|
167
|
-
...group
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
drop: {
|
|
171
|
-
args: { id: notes },
|
|
172
|
-
options: {
|
|
173
|
-
"replaced-by": notes,
|
|
174
|
-
...group
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
group: { subCommands: {
|
|
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 } }
|
|
196
|
-
} }
|
|
197
|
-
} };
|
|
198
|
-
async function setupCompletion(main) {
|
|
199
|
-
const subCommands = await (typeof main.subCommands === "function" ? main.subCommands() : main.subCommands);
|
|
200
|
-
const visible = Object.fromEntries(Object.entries(subCommands ?? {}).filter(([name]) => !hiddenCommands.has(name)));
|
|
201
|
-
await tab({
|
|
202
|
-
...main,
|
|
203
|
-
subCommands: visible
|
|
204
|
-
}, completionConfig);
|
|
205
|
-
const complete = visible["complete"];
|
|
206
|
-
if (complete) main.subCommands = {
|
|
207
|
-
...subCommands,
|
|
208
|
-
complete
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
// package.json
|
|
212
|
-
var version = "0.2.0-beta.3";
|
|
213
|
-
// src/color.ts
|
|
214
|
-
function paint(io) {
|
|
215
|
-
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
216
|
-
return {
|
|
217
|
-
bold: style("bold"),
|
|
218
|
-
dim: style("dim"),
|
|
219
|
-
yellow: style("yellow"),
|
|
220
|
-
red: style("red"),
|
|
221
|
-
cyan: style("cyan")
|
|
222
|
-
};
|
|
223
|
-
}
|
|
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`);
|
|
234
|
-
}
|
|
235
|
-
function openCliCarnet(io, group) {
|
|
236
|
-
const { carnet, resolution } = openResolvedCarnet({
|
|
237
|
-
cwd: io.cwd,
|
|
238
|
-
env: io.env,
|
|
239
|
-
group
|
|
240
|
-
});
|
|
241
|
-
announceGroup(io, resolution);
|
|
242
|
-
return carnet;
|
|
243
|
-
}
|
|
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;
|
|
253
|
-
}
|
|
254
|
-
// src/commands/group.ts
|
|
255
|
-
function carnetErrors(io, run) {
|
|
256
|
-
try {
|
|
257
|
-
return run();
|
|
258
|
-
} catch (error) {
|
|
259
|
-
if (error instanceof CarnetError) {
|
|
260
|
-
io.stderr(`error: ${error.message}\n`);
|
|
261
|
-
return 1;
|
|
262
|
-
}
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
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;
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
function groupAdd(repo, io, options = {}) {
|
|
283
|
-
return carnetErrors(io, () => {
|
|
284
|
-
const found = currentGroup(io, options.group);
|
|
285
|
-
const path = resolve(io.cwd, repo);
|
|
286
|
-
const group = addGroupRepo(found.name, path, io.env);
|
|
287
|
-
io.stdout(withChanges(`added ${basename(path)} to ${group.name}`, rendered(group, io)));
|
|
288
|
-
return 0;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
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;
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
function groupSync(io, options = {}) {
|
|
300
|
-
return carnetErrors(io, () => {
|
|
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`);
|
|
304
|
-
return 0;
|
|
305
|
-
});
|
|
306
|
-
}
|
|
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;
|
|
312
|
-
});
|
|
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
|
-
}
|
|
537
|
-
}
|
|
538
|
-
// src/commands/groups.ts
|
|
539
|
-
function plural(count, word) {
|
|
540
|
-
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
541
|
-
}
|
|
542
|
-
function groupsList(io) {
|
|
543
|
-
const colors = paint(io);
|
|
544
|
-
const groups = listGroups(io.env);
|
|
545
|
-
if (groups.length === 0) {
|
|
546
|
-
io.stdout(`${colors.dim("no group yet, create one with `rucher groups create <name>`")}\n`);
|
|
547
|
-
return 0;
|
|
548
|
-
}
|
|
549
|
-
const carnet = openGroupCarnet(null, { env: io.env });
|
|
550
|
-
const sessions = groupSessionCounts(carnet.db);
|
|
551
|
-
carnet.close();
|
|
552
|
-
const width = Math.max(...groups.map((group) => group.name.length));
|
|
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)}`);
|
|
554
|
-
io.stdout(`${lines.join("\n")}\n`);
|
|
555
|
-
return 0;
|
|
556
|
-
}
|
|
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`);
|
|
575
|
-
return 0;
|
|
576
|
-
}
|
|
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`);
|
|
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;
|
|
135
|
+
options: workspace,
|
|
136
|
+
subCommands: {
|
|
137
|
+
list: { options: workspace },
|
|
138
|
+
merge: {
|
|
139
|
+
args: {
|
|
140
|
+
from: sessions,
|
|
141
|
+
into: sessions
|
|
142
|
+
},
|
|
143
|
+
options: workspace
|
|
144
|
+
},
|
|
145
|
+
move: {
|
|
146
|
+
args: { session: sessions },
|
|
147
|
+
options: {
|
|
148
|
+
to: workspaces,
|
|
149
|
+
...workspace
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
rename: {
|
|
153
|
+
args: { session: sessions },
|
|
154
|
+
options: workspace
|
|
155
|
+
},
|
|
156
|
+
promote: {
|
|
157
|
+
args: { session: sessions },
|
|
158
|
+
options: workspace
|
|
159
|
+
},
|
|
160
|
+
demote: {
|
|
161
|
+
args: { session: sessions },
|
|
162
|
+
options: workspace
|
|
163
|
+
},
|
|
164
|
+
drop: {
|
|
165
|
+
args: { session: sessions },
|
|
166
|
+
options: workspace
|
|
167
|
+
},
|
|
168
|
+
clean: { options: workspace }
|
|
630
169
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
170
|
+
},
|
|
171
|
+
notes: {
|
|
172
|
+
options: {
|
|
173
|
+
kind: noteKinds,
|
|
174
|
+
repo: repoNames,
|
|
175
|
+
...workspace
|
|
176
|
+
},
|
|
177
|
+
subCommands: {
|
|
178
|
+
list: { options: {
|
|
179
|
+
kind: noteKinds,
|
|
180
|
+
repo: repoNames,
|
|
181
|
+
...workspace
|
|
182
|
+
} },
|
|
183
|
+
show: {
|
|
184
|
+
args: { id: notes },
|
|
185
|
+
options: workspace
|
|
186
|
+
},
|
|
187
|
+
add: {
|
|
188
|
+
args: { kind: noteKinds },
|
|
189
|
+
options: {
|
|
190
|
+
repo: repoNames,
|
|
191
|
+
...workspace
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
drop: {
|
|
195
|
+
args: { id: notes },
|
|
196
|
+
options: {
|
|
197
|
+
"replaced-by": notes,
|
|
198
|
+
...workspace
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
ws: {
|
|
204
|
+
options: workspace,
|
|
205
|
+
subCommands: {
|
|
206
|
+
drop: { args: { name: workspaces } },
|
|
207
|
+
show: { options: workspace },
|
|
208
|
+
add: {
|
|
209
|
+
args: { path: directories },
|
|
210
|
+
options: workspace
|
|
211
|
+
},
|
|
212
|
+
remove: {
|
|
213
|
+
args: { path: repos },
|
|
214
|
+
options: workspace
|
|
215
|
+
},
|
|
216
|
+
sync: { options: workspace },
|
|
217
|
+
edit: { options: workspace },
|
|
218
|
+
path: { options: workspace }
|
|
634
219
|
}
|
|
635
|
-
throw error;
|
|
636
220
|
}
|
|
221
|
+
} };
|
|
222
|
+
async function setupCompletion(main) {
|
|
223
|
+
const subCommands = await (typeof main.subCommands === "function" ? main.subCommands() : main.subCommands);
|
|
224
|
+
const visible = Object.fromEntries(Object.entries(subCommands ?? {}).filter(([name]) => !hiddenCommands.has(name)));
|
|
225
|
+
await tab({
|
|
226
|
+
...main,
|
|
227
|
+
subCommands: visible
|
|
228
|
+
}, completionConfig);
|
|
229
|
+
const complete = visible["complete"];
|
|
230
|
+
if (complete) main.subCommands = {
|
|
231
|
+
...subCommands,
|
|
232
|
+
complete: {
|
|
233
|
+
...complete,
|
|
234
|
+
run: (context) => {
|
|
235
|
+
context.rawArgs = splitInlineValues(context.rawArgs);
|
|
236
|
+
return complete.run?.(context);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
637
240
|
}
|
|
241
|
+
// package.json
|
|
242
|
+
var version = "0.2.0-beta.5";
|
|
638
243
|
// src/commands/hook.ts
|
|
639
244
|
const host = claudeCode;
|
|
640
245
|
function runHook(io, run, hookEventName) {
|
|
641
246
|
try {
|
|
642
247
|
run();
|
|
643
248
|
} catch (error) {
|
|
644
|
-
if (error instanceof CarnetError && error.code === "
|
|
645
|
-
if (error instanceof CarnetError && error.code === "
|
|
249
|
+
if (error instanceof CarnetError && error.code === "NO_WORKSPACE") return 0;
|
|
250
|
+
if (error instanceof CarnetError && error.code === "WORKSPACE_AMBIGUOUS") {
|
|
646
251
|
if (hookEventName) {
|
|
647
252
|
io.stderr(`rucher: ${error.message}\n`);
|
|
648
|
-
const additionalContext =
|
|
253
|
+
const additionalContext = ambiguousWorkspaceContext(error.message);
|
|
649
254
|
io.stdout(`${JSON.stringify({ hookSpecificOutput: {
|
|
650
255
|
hookEventName,
|
|
651
256
|
additionalContext
|
|
@@ -665,7 +270,7 @@ function withCarnet$1(payload, io, use) {
|
|
|
665
270
|
});
|
|
666
271
|
try {
|
|
667
272
|
const known = payload.session_id ? carnet.sessions.get(payload.session_id) : void 0;
|
|
668
|
-
if (!carnet.
|
|
273
|
+
if (!carnet.workspace && !io.env.RUCHER_SESSION_ID && !known) return;
|
|
669
274
|
use(carnet);
|
|
670
275
|
} finally {
|
|
671
276
|
carnet.close();
|
|
@@ -754,6 +359,41 @@ function sessionEnd(stdinText, io) {
|
|
|
754
359
|
});
|
|
755
360
|
});
|
|
756
361
|
}
|
|
362
|
+
// src/color.ts
|
|
363
|
+
function paint(io) {
|
|
364
|
+
const style = (name) => (text) => io.color ? styleText(name, text, { validateStream: false }) : text;
|
|
365
|
+
return {
|
|
366
|
+
bold: style("bold"),
|
|
367
|
+
dim: style("dim"),
|
|
368
|
+
yellow: style("yellow"),
|
|
369
|
+
red: style("red"),
|
|
370
|
+
cyan: style("cyan")
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
// src/session.ts
|
|
374
|
+
var CliError = class extends Error {
|
|
375
|
+
hint;
|
|
376
|
+
constructor(message, hint) {
|
|
377
|
+
super(message);
|
|
378
|
+
this.hint = hint;
|
|
379
|
+
this.name = "CliError";
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function findSession(carnet, reference) {
|
|
383
|
+
try {
|
|
384
|
+
return carnet.sessions.find(reference);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
387
|
+
const known = carnet.sessions.list().map((session) => session.name).filter(Boolean);
|
|
388
|
+
throw new CliError(error.message, known.length ? `known sessions: ${known.join(", ")}` : "pass a session name, id or id prefix, see rucher sessions --all");
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function resolveSession(carnet, reference) {
|
|
392
|
+
if (reference) return findSession(carnet, reference);
|
|
393
|
+
const session = carnet.sessions.default();
|
|
394
|
+
if (!session) throw new CliError("No session in this workspace yet", "start a Claude Code session inside the workspace");
|
|
395
|
+
return session;
|
|
396
|
+
}
|
|
757
397
|
// src/commands/log.ts
|
|
758
398
|
function formatEvents(events, io) {
|
|
759
399
|
const colors = paint(io);
|
|
@@ -798,13 +438,48 @@ function formatEventsMarkdown(events, title) {
|
|
|
798
438
|
return lines.join("\n");
|
|
799
439
|
}
|
|
800
440
|
function sessionTitle(carnet, session) {
|
|
801
|
-
return `${
|
|
441
|
+
return `${workspaceLabel(carnet.workspace)} · ${session.name ?? session.id.slice(0, 8)}`;
|
|
802
442
|
}
|
|
803
443
|
function logOnce(carnet, io, options) {
|
|
804
444
|
const session = resolveSession(carnet, options.session);
|
|
805
445
|
const events = carnet.events.read(session.id, options.count, options.agents);
|
|
806
446
|
io.stdout(`${options.md ? formatEventsMarkdown(events, sessionTitle(carnet, session)) : formatEvents(events, io)}\n`);
|
|
807
447
|
}
|
|
448
|
+
// src/workspace-option.ts
|
|
449
|
+
const workspaceArgument = { ws: {
|
|
450
|
+
type: "string",
|
|
451
|
+
description: "Workspace name (default: from RUCHER_WS, the run directory or the repo you are in)"
|
|
452
|
+
} };
|
|
453
|
+
function forwardWorkspace({ args }) {
|
|
454
|
+
if (args.ws) process.env.RUCHER_WS = args.ws;
|
|
455
|
+
}
|
|
456
|
+
function announceWorkspace(io, resolution) {
|
|
457
|
+
if (!resolution.workspace) return;
|
|
458
|
+
if (resolution.origin === "run-directory") io.stderr(`workspace ${resolution.workspace.name} (from its run directory)\n`);
|
|
459
|
+
else if (resolution.origin === "repo" && resolution.repo) io.stderr(`workspace ${resolution.workspace.name} (from ${resolution.repo.name})\n`);
|
|
460
|
+
}
|
|
461
|
+
function warnNoWorkspace(carnet, io) {
|
|
462
|
+
if (!carnet.workspace) io.stderr("no workspace here: pass --ws\n");
|
|
463
|
+
}
|
|
464
|
+
function openCliCarnet(io, workspace) {
|
|
465
|
+
const { carnet, resolution } = openResolvedCarnet({
|
|
466
|
+
cwd: io.cwd,
|
|
467
|
+
env: io.env,
|
|
468
|
+
workspace
|
|
469
|
+
});
|
|
470
|
+
announceWorkspace(io, resolution);
|
|
471
|
+
return carnet;
|
|
472
|
+
}
|
|
473
|
+
function currentWorkspace(io, workspace) {
|
|
474
|
+
const resolution = resolveWorkspace({
|
|
475
|
+
cwd: io.cwd,
|
|
476
|
+
env: io.env,
|
|
477
|
+
workspace
|
|
478
|
+
});
|
|
479
|
+
const found = requireWorkspace(resolution.workspace);
|
|
480
|
+
announceWorkspace(io, resolution);
|
|
481
|
+
return found;
|
|
482
|
+
}
|
|
808
483
|
// src/commands/notes.ts
|
|
809
484
|
const KIND_TITLES = {
|
|
810
485
|
dead_end: "Dead ends",
|
|
@@ -853,7 +528,7 @@ function markdown(carnet, notes) {
|
|
|
853
528
|
});
|
|
854
529
|
return `## ${KIND_TITLES[kind]}\n\n${lines.join("\n")}`;
|
|
855
530
|
});
|
|
856
|
-
return `# Memory: ${
|
|
531
|
+
return `# Memory: ${workspaceLabel(carnet.workspace)}\n\n${sections.join("\n\n") || "No notes."}\n`;
|
|
857
532
|
}
|
|
858
533
|
function notesList(carnet, io, options = {}) {
|
|
859
534
|
const notes = options.stale ? carnet.notes.stale(halfLife(io)) : carnet.notes.list({
|
|
@@ -868,8 +543,9 @@ function notesList(carnet, io, options = {}) {
|
|
|
868
543
|
return;
|
|
869
544
|
}
|
|
870
545
|
const colors = paint(io);
|
|
546
|
+
warnNoWorkspace(carnet, io);
|
|
871
547
|
if (notes.length === 0) {
|
|
872
|
-
io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
548
|
+
if (carnet.workspace) io.stdout(`${colors.dim(options.stale ? "no note to review" : "no notes")}\n`);
|
|
873
549
|
return;
|
|
874
550
|
}
|
|
875
551
|
const blocks = grouped(notes).map(([kind, kindNotes]) => `${colors.bold(KIND_TITLES[kind])}\n${kindNotes.map((note) => noteLine(io, note)).join("\n")}`);
|
|
@@ -939,13 +615,13 @@ function splitPassthrough(rawArgs) {
|
|
|
939
615
|
function positionals(own) {
|
|
940
616
|
return own.filter((argument) => !argument.startsWith("-"));
|
|
941
617
|
}
|
|
942
|
-
function launchEnv(
|
|
618
|
+
function launchEnv(workspace, session, promptVersion, kind) {
|
|
943
619
|
return {
|
|
944
620
|
RUCHER_SESSION_ID: session.id,
|
|
945
621
|
RUCHER_PROMPT_VERSION: promptVersion,
|
|
946
622
|
RUCHER_SESSION_NAME: session.name ?? "",
|
|
947
623
|
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD: "1",
|
|
948
|
-
...
|
|
624
|
+
...workspace ? { RUCHER_WS: workspace.name } : {},
|
|
949
625
|
...kind ? { RUCHER_SESSION_KIND: kind } : {}
|
|
950
626
|
};
|
|
951
627
|
}
|
|
@@ -955,41 +631,41 @@ function planNew(carnet, io, options) {
|
|
|
955
631
|
id: randomUUID(),
|
|
956
632
|
kind: options.kind,
|
|
957
633
|
name: options.name,
|
|
958
|
-
cwd: carnet.
|
|
959
|
-
repo: repoNameFor(carnet.
|
|
634
|
+
cwd: carnet.workspace?.runDirectory ?? io.cwd,
|
|
635
|
+
repo: repoNameFor(carnet.workspace, io.cwd)
|
|
960
636
|
});
|
|
961
637
|
const host = hostById(session.host);
|
|
962
|
-
if (carnet.
|
|
638
|
+
if (carnet.workspace) renderRunDirectory(carnet.workspace, {
|
|
963
639
|
env: io.env,
|
|
964
640
|
host: session.host
|
|
965
641
|
});
|
|
966
|
-
const prompt = appendPromptFile(carnet.
|
|
642
|
+
const prompt = appendPromptFile(carnet.workspace, session, io.env);
|
|
967
643
|
return {
|
|
968
644
|
...host.launchCommand(session.id, {
|
|
969
645
|
name: session.name,
|
|
970
646
|
appendPromptFile: prompt.path,
|
|
971
|
-
directories: repoDirectories(carnet.
|
|
647
|
+
directories: repoDirectories(carnet.workspace),
|
|
972
648
|
passthrough: options.passthrough
|
|
973
649
|
}),
|
|
974
|
-
cwd: carnet.
|
|
975
|
-
env: launchEnv(carnet.
|
|
650
|
+
cwd: carnet.workspace?.runDirectory ?? io.cwd,
|
|
651
|
+
env: launchEnv(carnet.workspace, session, prompt.version),
|
|
976
652
|
sessionId: session.id
|
|
977
653
|
};
|
|
978
654
|
}
|
|
979
|
-
function repoDirectories(
|
|
980
|
-
return (
|
|
655
|
+
function repoDirectories(workspace) {
|
|
656
|
+
return (workspace?.repos ?? []).map((repo) => repo.path).filter((path) => existsSync(path));
|
|
981
657
|
}
|
|
982
|
-
function
|
|
983
|
-
if (!session.
|
|
984
|
-
return carnet.
|
|
658
|
+
function sessionWorkspace(carnet, session, env) {
|
|
659
|
+
if (!session.workspace || !isWorkspaceName(session.workspace)) return null;
|
|
660
|
+
return carnet.workspace?.name === session.workspace ? carnet.workspace : loadWorkspace(session.workspace, env);
|
|
985
661
|
}
|
|
986
662
|
function prepareSession(carnet, session, env) {
|
|
987
|
-
const
|
|
988
|
-
if (
|
|
663
|
+
const workspace = sessionWorkspace(carnet, session, env);
|
|
664
|
+
if (workspace) renderRunDirectory(workspace, {
|
|
989
665
|
env,
|
|
990
666
|
host: session.host
|
|
991
667
|
});
|
|
992
|
-
return
|
|
668
|
+
return workspace;
|
|
993
669
|
}
|
|
994
670
|
function sessionDirectory(session) {
|
|
995
671
|
if (session.cwd && existsSync(session.cwd)) return session.cwd;
|
|
@@ -998,17 +674,17 @@ function sessionDirectory(session) {
|
|
|
998
674
|
function planResume(carnet, io, reference, passthrough = []) {
|
|
999
675
|
const session = findSession(carnet, reference);
|
|
1000
676
|
if (session.status === "archived") io.stderr(`warning: session ${reference} is archived\n`);
|
|
1001
|
-
const
|
|
677
|
+
const workspace = prepareSession(carnet, session, io.env);
|
|
1002
678
|
const cwd = sessionDirectory(session);
|
|
1003
|
-
const prompt = appendPromptFile(
|
|
679
|
+
const prompt = appendPromptFile(workspace, session, io.env);
|
|
1004
680
|
return {
|
|
1005
681
|
...hostById(session.host).resumeCommand(session, {
|
|
1006
682
|
appendPromptFile: prompt.path,
|
|
1007
|
-
directories: repoDirectories(
|
|
683
|
+
directories: repoDirectories(workspace),
|
|
1008
684
|
passthrough
|
|
1009
685
|
}),
|
|
1010
686
|
cwd,
|
|
1011
|
-
env: launchEnv(
|
|
687
|
+
env: launchEnv(workspace, session, prompt.version),
|
|
1012
688
|
sessionId: session.id
|
|
1013
689
|
};
|
|
1014
690
|
}
|
|
@@ -1016,19 +692,19 @@ function planFork(carnet, io, reference, options = {}) {
|
|
|
1016
692
|
if (options.active && !options.name) throw new CliError("An active fork needs a name", "rucher fork <session> <name> --active");
|
|
1017
693
|
if (options.name && carnet.sessions.byName(options.name)) throw new CliError(`A session named "${options.name}" already exists`);
|
|
1018
694
|
const parent = findSession(carnet, reference);
|
|
1019
|
-
const
|
|
695
|
+
const workspace = prepareSession(carnet, parent, io.env);
|
|
1020
696
|
const cwd = sessionDirectory(parent);
|
|
1021
697
|
const kind = options.active ? "active" : "temp";
|
|
1022
698
|
return {
|
|
1023
699
|
...hostById(parent.host).forkCommand(parent, {
|
|
1024
700
|
name: options.name,
|
|
1025
|
-
appendPromptFile: appendPromptFile(
|
|
1026
|
-
directories: repoDirectories(
|
|
701
|
+
appendPromptFile: appendPromptFile(workspace, parent, io.env).path,
|
|
702
|
+
directories: repoDirectories(workspace),
|
|
1027
703
|
passthrough: options.passthrough
|
|
1028
704
|
}),
|
|
1029
705
|
cwd,
|
|
1030
706
|
env: {
|
|
1031
|
-
...launchEnv(
|
|
707
|
+
...launchEnv(workspace, parent, parent.promptVersion ?? "", kind),
|
|
1032
708
|
RUCHER_SESSION_NAME: options.name ?? ""
|
|
1033
709
|
},
|
|
1034
710
|
parentId: parent.id,
|
|
@@ -1086,54 +762,202 @@ function pickerLines(sessions, now = /* @__PURE__ */ new Date()) {
|
|
|
1086
762
|
const widths = (rows[0] ?? []).map((_, column) => Math.max(...rows.map((row) => (row[column] ?? "").length)));
|
|
1087
763
|
return rows.map((row) => row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell).join(" "));
|
|
1088
764
|
}
|
|
1089
|
-
function hasFzf() {
|
|
1090
|
-
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
765
|
+
function hasFzf() {
|
|
766
|
+
return spawnSync("fzf", ["--version"], { stdio: "ignore" }).status === 0;
|
|
767
|
+
}
|
|
768
|
+
function pickWithFzf(sessions, lines) {
|
|
769
|
+
const result = spawnSync("fzf", [
|
|
770
|
+
"--with-nth=2..",
|
|
771
|
+
"--no-sort",
|
|
772
|
+
"--prompt=session> "
|
|
773
|
+
], {
|
|
774
|
+
input: lines.join("\n"),
|
|
775
|
+
stdio: [
|
|
776
|
+
"pipe",
|
|
777
|
+
"pipe",
|
|
778
|
+
"inherit"
|
|
779
|
+
],
|
|
780
|
+
encoding: "utf8"
|
|
781
|
+
});
|
|
782
|
+
return sessions[Number(result.stdout?.trim().split(/\s+/)[0]) - 1];
|
|
783
|
+
}
|
|
784
|
+
async function pickFromList(sessions, lines) {
|
|
785
|
+
process.stderr.write(`${lines.join("\n")}\n`);
|
|
786
|
+
const prompt = createInterface({
|
|
787
|
+
input: process.stdin,
|
|
788
|
+
output: process.stderr
|
|
789
|
+
});
|
|
790
|
+
try {
|
|
791
|
+
const answer = await prompt.question("session number> ");
|
|
792
|
+
return sessions[Number(answer.trim()) - 1];
|
|
793
|
+
} finally {
|
|
794
|
+
prompt.close();
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
async function pickSession(carnet) {
|
|
798
|
+
const sessions = pickerSessions(carnet);
|
|
799
|
+
if (sessions.length === 0) throw new CliError("No session to resume in this workspace", "rucher new <name>");
|
|
800
|
+
if (!process.stdin.isTTY) throw new CliError("No session given", "rucher resume <name, id or id prefix>");
|
|
801
|
+
const lines = pickerLines(sessions);
|
|
802
|
+
const picked = hasFzf() ? pickWithFzf(sessions, lines) : await pickFromList(sessions, lines);
|
|
803
|
+
if (!picked) throw new CliError("No session picked");
|
|
804
|
+
return picked;
|
|
805
|
+
}
|
|
806
|
+
// src/commands/serve.ts
|
|
807
|
+
function serve(io) {
|
|
808
|
+
serveCarnet({
|
|
809
|
+
cwd: io.cwd,
|
|
810
|
+
env: io.env,
|
|
811
|
+
sessionId: claudeCode.sessionIdFromEnvironment(io.env)
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
// src/commands/sessions.ts
|
|
815
|
+
function lastActive(at, now) {
|
|
816
|
+
const date = new Date(at);
|
|
817
|
+
return date.toDateString() === now.toDateString() ? formatClock(date) : date.toISOString().slice(0, 10);
|
|
818
|
+
}
|
|
819
|
+
function row(carnet, session, now) {
|
|
820
|
+
const open = carnet.agents.list(session.id).length;
|
|
821
|
+
return [
|
|
822
|
+
session.name ?? session.id.slice(0, 8),
|
|
823
|
+
session.kind,
|
|
824
|
+
session.status,
|
|
825
|
+
repoPathFor(carnet.workspace, session.cwd) ?? session.repo ?? "",
|
|
826
|
+
lastActive(session.lastActiveAt, now),
|
|
827
|
+
open ? `${open} agent${open > 1 ? "s" : ""}` : "",
|
|
828
|
+
session.purpose ?? ""
|
|
829
|
+
];
|
|
830
|
+
}
|
|
831
|
+
function sessionsOnce(carnet, io, options = {}) {
|
|
832
|
+
const colors = paint(io);
|
|
833
|
+
const sessions = carnet.sessions.list({
|
|
834
|
+
includeTemp: options.all,
|
|
835
|
+
includeArchived: options.all
|
|
836
|
+
});
|
|
837
|
+
warnNoWorkspace(carnet, io);
|
|
838
|
+
if (sessions.length === 0) {
|
|
839
|
+
const hint = options.all ? "" : " (temp and archived ones are hidden, use --all)";
|
|
840
|
+
if (carnet.workspace) io.stdout(`${colors.dim(`no active session yet${hint}`)}\n`);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
844
|
+
const rows = sessions.map((session) => ({
|
|
845
|
+
session,
|
|
846
|
+
cells: row(carnet, session, now)
|
|
847
|
+
}));
|
|
848
|
+
const widths = rows.reduce((current, { cells }) => cells.map((cell, column) => Math.max(current[column] ?? 0, cell.length)), []);
|
|
849
|
+
const lines = rows.map(({ session, cells }) => {
|
|
850
|
+
return cells.map((cell, column) => {
|
|
851
|
+
const padded = column < cells.length - 1 ? cell.padEnd(widths[column] ?? 0) : cell;
|
|
852
|
+
if (column === 0) return colors.bold(padded);
|
|
853
|
+
if (column === 1 && session.kind === "temp") return colors.dim(padded);
|
|
854
|
+
if (column === 2 && session.status === "archived") return colors.dim(padded);
|
|
855
|
+
return padded;
|
|
856
|
+
}).join(" ").trimEnd();
|
|
857
|
+
});
|
|
858
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
859
|
+
}
|
|
860
|
+
function sessionsMerge(carnet, fromReference, intoReference, io) {
|
|
861
|
+
const from = findSession(carnet, fromReference);
|
|
862
|
+
const into = findSession(carnet, intoReference);
|
|
863
|
+
const result = carnet.sessions.merge(from.id, into.id);
|
|
864
|
+
const label = (session) => session.name ?? session.id.slice(0, 8);
|
|
865
|
+
const lines = [
|
|
866
|
+
`merged ${label(from)} into ${label(result.session)}`,
|
|
867
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
868
|
+
...result.closedAgents.length ? [` agents closed (name already used): ${result.closedAgents.join(", ")}`] : [],
|
|
869
|
+
` events moved: ${result.movedEvents}`,
|
|
870
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`
|
|
871
|
+
];
|
|
872
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
873
|
+
}
|
|
874
|
+
function label(session) {
|
|
875
|
+
return session.name ?? shortId(session.id);
|
|
876
|
+
}
|
|
877
|
+
function workspaced(name, io) {
|
|
878
|
+
if (!workspaceExists(name, io.env)) throw new CliError(`No workspace named "${name}"`, "see rucher ws list");
|
|
879
|
+
return loadWorkspace(name, io.env);
|
|
880
|
+
}
|
|
881
|
+
function sessionsMove(carnet, reference, workspaceReference, io, options = {}) {
|
|
882
|
+
const session = findSession(carnet, reference);
|
|
883
|
+
const target = workspaced(workspaceReference, io).name;
|
|
884
|
+
const result = moveSession(carnet, session.id, target, options);
|
|
885
|
+
const into = result.into ? ` into ${label(result.into)}` : "";
|
|
886
|
+
const lines = [
|
|
887
|
+
`${options.dryRun ? "would move" : "moved"} ${label(session)} from ${workspaceLabel(carnet.workspace)} to ${target}${into}`,
|
|
888
|
+
` agents moved: ${result.movedAgents.join(", ") || "none"}`,
|
|
889
|
+
...result.skippedAgents.length ? [` agents left out (name already used): ${result.skippedAgents.join(", ")}`] : [],
|
|
890
|
+
` events moved: ${result.movedEvents}`,
|
|
891
|
+
` table line moved: ${result.movedTable ? "yes" : "no"}`,
|
|
892
|
+
...result.keptNotes ? [` notes kept in ${workspaceLabel(carnet.workspace)}: ${result.keptNotes}`] : []
|
|
893
|
+
];
|
|
894
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
895
|
+
}
|
|
896
|
+
function sessionsRename(carnet, reference, name, io) {
|
|
897
|
+
const session = carnet.sessions.rename(findSession(carnet, reference).id, name);
|
|
898
|
+
io.stdout(`renamed to ${session.name}; rucher resume ${session.name} gives Claude the same title\n`);
|
|
899
|
+
}
|
|
900
|
+
function sessionsPromote(carnet, reference, name, io) {
|
|
901
|
+
const session = carnet.sessions.promote(findSession(carnet, reference).id, name);
|
|
902
|
+
io.stdout(`${label(session)} is now active\n`);
|
|
903
|
+
}
|
|
904
|
+
function sessionsDemote(carnet, reference, io) {
|
|
905
|
+
const session = carnet.sessions.demote(findSession(carnet, reference).id);
|
|
906
|
+
io.stdout(`${label(session)} is now temp, cleaned by rucher sessions clean once idle\n`);
|
|
907
|
+
}
|
|
908
|
+
function purgeTranscripts(session, io) {
|
|
909
|
+
const files = hostById(session.host).transcriptFiles(session, io.env);
|
|
910
|
+
for (const file of files) {
|
|
911
|
+
rmSync(file, {
|
|
912
|
+
recursive: true,
|
|
913
|
+
force: true
|
|
914
|
+
});
|
|
915
|
+
io.stdout(` deleted ${file}\n`);
|
|
916
|
+
}
|
|
917
|
+
if (files.length === 0) io.stdout(" no transcript found\n");
|
|
1091
918
|
}
|
|
1092
|
-
function
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
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];
|
|
919
|
+
function sessionsDrop(carnet, reference, io, options = {}) {
|
|
920
|
+
const session = findSession(carnet, reference);
|
|
921
|
+
if (options.purge && session.status === "running") throw new CliError(`Session ${label(session)} is running`, "drop it with --purge once it has ended");
|
|
922
|
+
carnet.sessions.drop(session.id);
|
|
923
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
924
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
1107
925
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
926
|
+
const UNIT_MILLISECONDS = {
|
|
927
|
+
m: 6e4,
|
|
928
|
+
h: 36e5,
|
|
929
|
+
d: 864e5
|
|
930
|
+
};
|
|
931
|
+
function parseDuration(value) {
|
|
932
|
+
const match = /^(\d+(?:\.\d+)?)([mhd]?)$/.exec(value.trim());
|
|
933
|
+
if (!match) throw new CliError(`Invalid duration "${value}"`, "use a number of days, or 30m, 12h, 7d");
|
|
934
|
+
return Number(match[1]) * (UNIT_MILLISECONDS[match[2] || "d"] ?? 0);
|
|
935
|
+
}
|
|
936
|
+
function processIsAlive(processId) {
|
|
1114
937
|
try {
|
|
1115
|
-
|
|
1116
|
-
return
|
|
1117
|
-
}
|
|
1118
|
-
|
|
938
|
+
process.kill(processId, 0);
|
|
939
|
+
return true;
|
|
940
|
+
} catch (error) {
|
|
941
|
+
return error.code === "EPERM";
|
|
1119
942
|
}
|
|
1120
943
|
}
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
if (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
944
|
+
function sessionsClean(carnet, io, options = {}) {
|
|
945
|
+
const olderThan = parseDuration(options.olderThan ?? "7d");
|
|
946
|
+
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`);
|
|
947
|
+
const stale = carnet.sessions.staleTemp(olderThan);
|
|
948
|
+
if (stale.length === 0) {
|
|
949
|
+
io.stdout(`no temp session idle for more than ${options.olderThan ?? "7d"}\n`);
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
for (const session of stale) {
|
|
953
|
+
if (options.dryRun) {
|
|
954
|
+
io.stdout(`would archive ${label(session)}${options.purge ? " and delete its transcript" : ""}\n`);
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
carnet.sessions.drop(session.id);
|
|
958
|
+
io.stdout(`archived ${label(session)}\n`);
|
|
959
|
+
if (options.purge) purgeTranscripts(session, io);
|
|
960
|
+
}
|
|
1137
961
|
}
|
|
1138
962
|
// src/commands/watch-keys.ts
|
|
1139
963
|
const INITIAL_WATCH_STATE = {
|
|
@@ -1274,7 +1098,7 @@ function sessionName(session) {
|
|
|
1274
1098
|
function sessionLabel(carnet, session, columns) {
|
|
1275
1099
|
const name = sessionName(session);
|
|
1276
1100
|
const room = columns - Array.from(name).length - 3;
|
|
1277
|
-
return room > 1 ? `${name} · ${truncate(
|
|
1101
|
+
return room > 1 ? `${name} · ${truncate(workspaceLabel(carnet.workspace), room)}` : name;
|
|
1278
1102
|
}
|
|
1279
1103
|
function sessionHeader(session, io) {
|
|
1280
1104
|
return paint(io).cyan(truncate(sessionName(session), io.columns));
|
|
@@ -1351,89 +1175,285 @@ function renderStatusView(carnet, io, options) {
|
|
|
1351
1175
|
return sessionBlock(session, view, io);
|
|
1352
1176
|
});
|
|
1353
1177
|
const colors = paint(io);
|
|
1354
|
-
const separator = " - ";
|
|
1355
|
-
const
|
|
1356
|
-
return [
|
|
1357
|
-
`${colors.dim(time)}${separator}${colors.cyan(
|
|
1358
|
-
"",
|
|
1359
|
-
blocks.join("\n\n"),
|
|
1178
|
+
const separator = " - ";
|
|
1179
|
+
const workspace = truncate(workspaceLabel(carnet.workspace), io.columns - time.length - 3);
|
|
1180
|
+
return [
|
|
1181
|
+
`${colors.dim(time)}${separator}${colors.cyan(workspace)}`,
|
|
1182
|
+
"",
|
|
1183
|
+
blocks.join("\n\n"),
|
|
1184
|
+
"",
|
|
1185
|
+
colors.dim(LEGEND)
|
|
1186
|
+
].join("\n");
|
|
1187
|
+
}
|
|
1188
|
+
function statusOnce(carnet, io, options) {
|
|
1189
|
+
io.stdout(`${renderStatusView(carnet, io, options)}\n`);
|
|
1190
|
+
}
|
|
1191
|
+
function dropSelected(carnet, options, index, reason) {
|
|
1192
|
+
const session = resolveSession(carnet, options.session);
|
|
1193
|
+
const item = carnet.notes.activity(session.id)[index];
|
|
1194
|
+
if (!item) return "no note selected";
|
|
1195
|
+
try {
|
|
1196
|
+
carnet.notes.drop(item.note, {
|
|
1197
|
+
reason,
|
|
1198
|
+
session: session.id
|
|
1199
|
+
});
|
|
1200
|
+
return null;
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
return error instanceof Error ? error.message : String(error);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function noteCount(carnet, options) {
|
|
1206
|
+
try {
|
|
1207
|
+
return carnet.notes.activity(resolveSession(carnet, options.session).id).length;
|
|
1208
|
+
} catch {
|
|
1209
|
+
return 0;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const CLEAR = "\x1B[H\x1B[2J";
|
|
1213
|
+
const HIDE_CURSOR = "\x1B[?25l";
|
|
1214
|
+
const SHOW_CURSOR = "\x1B[?25h";
|
|
1215
|
+
function statusWatch(carnet, io, options) {
|
|
1216
|
+
return new Promise((resolve) => {
|
|
1217
|
+
let last = "";
|
|
1218
|
+
const interactive = options.keys !== void 0 && !options.all;
|
|
1219
|
+
let state = INITIAL_WATCH_STATE;
|
|
1220
|
+
const repaint = () => {
|
|
1221
|
+
let text;
|
|
1222
|
+
try {
|
|
1223
|
+
text = renderStatusView(carnet, io, {
|
|
1224
|
+
...options,
|
|
1225
|
+
interaction: interactive ? state : void 0
|
|
1226
|
+
});
|
|
1227
|
+
} catch (error) {
|
|
1228
|
+
text = paint(io).dim(error instanceof Error ? error.message : String(error));
|
|
1229
|
+
}
|
|
1230
|
+
if (text === last) return;
|
|
1231
|
+
last = text;
|
|
1232
|
+
io.stdout(`${CLEAR}${text}\n`);
|
|
1233
|
+
};
|
|
1234
|
+
const timer = setInterval(() => {
|
|
1235
|
+
if (state.reason === null) repaint();
|
|
1236
|
+
}, options.intervalMilliseconds);
|
|
1237
|
+
let stopped = false;
|
|
1238
|
+
const stop = () => {
|
|
1239
|
+
if (stopped) return;
|
|
1240
|
+
stopped = true;
|
|
1241
|
+
clearInterval(timer);
|
|
1242
|
+
options.keys?.close();
|
|
1243
|
+
io.stdout(SHOW_CURSOR);
|
|
1244
|
+
resolve();
|
|
1245
|
+
};
|
|
1246
|
+
options.keys?.onKey((key) => {
|
|
1247
|
+
const result = pressKey(state, key, interactive ? noteCount(carnet, options) : 0);
|
|
1248
|
+
state = result.state;
|
|
1249
|
+
if (result.action?.type === "quit") return stop();
|
|
1250
|
+
if (result.action?.type === "drop") state = {
|
|
1251
|
+
...state,
|
|
1252
|
+
message: dropSelected(carnet, options, result.action.index, result.action.reason)
|
|
1253
|
+
};
|
|
1254
|
+
repaint();
|
|
1255
|
+
});
|
|
1256
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
1257
|
+
io.stdout(HIDE_CURSOR);
|
|
1258
|
+
repaint();
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
// src/commands/ws.ts
|
|
1262
|
+
function carnetErrors(io, run) {
|
|
1263
|
+
try {
|
|
1264
|
+
return run();
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
if (error instanceof CarnetError) {
|
|
1267
|
+
io.stderr(`error: ${error.message}\n`);
|
|
1268
|
+
return 1;
|
|
1269
|
+
}
|
|
1270
|
+
throw error;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
function rendered(workspace, io) {
|
|
1274
|
+
const result = renderRunDirectory(workspace, { env: io.env });
|
|
1275
|
+
return [...result.written.map((path) => `written ${path}`), ...result.removed.map((path) => `removed ${path}`)];
|
|
1276
|
+
}
|
|
1277
|
+
function withChanges(line, changes) {
|
|
1278
|
+
return `${line}${changes.length ? ` (${changes.join(", ")})` : ""}\n`;
|
|
1279
|
+
}
|
|
1280
|
+
function workspaceShow(io, options = {}) {
|
|
1281
|
+
return carnetErrors(io, () => {
|
|
1282
|
+
const colors = paint(io);
|
|
1283
|
+
const workspace = currentWorkspace(io, options.workspace);
|
|
1284
|
+
const repos = workspace.repos.length ? workspace.repos.map((repo) => ` ${repo.name} ${colors.dim(repo.path)}`).join("\n") : ` ${colors.dim("none")}`;
|
|
1285
|
+
io.stdout(`${colors.bold(workspace.name)}\ndefinition: ${workspace.definition}\nrun directory: ${workspace.runDirectory}\nrepos:\n${repos}\n`);
|
|
1286
|
+
return 0;
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
function workspaceAdd(repo, io, options = {}) {
|
|
1290
|
+
return carnetErrors(io, () => {
|
|
1291
|
+
const found = currentWorkspace(io, options.workspace);
|
|
1292
|
+
const path = resolve(io.cwd, repo);
|
|
1293
|
+
const workspace = addWorkspaceRepo(found.name, path, io.env);
|
|
1294
|
+
io.stdout(withChanges(`added ${basename(path)} to ${workspace.name}`, rendered(workspace, io)));
|
|
1295
|
+
return 0;
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
function workspaceRemove(repo, io, options = {}) {
|
|
1299
|
+
return carnetErrors(io, () => {
|
|
1300
|
+
const found = currentWorkspace(io, options.workspace);
|
|
1301
|
+
const workspace = removeWorkspaceRepo(found.name, resolve(io.cwd, repo), io.env);
|
|
1302
|
+
io.stdout(withChanges(`removed ${basename(repo)} from ${workspace.name}`, rendered(workspace, io)));
|
|
1303
|
+
return 0;
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
function workspaceSync(io, options = {}) {
|
|
1307
|
+
return carnetErrors(io, () => {
|
|
1308
|
+
const workspace = currentWorkspace(io, options.workspace);
|
|
1309
|
+
const changes = rendered(workspace, io);
|
|
1310
|
+
io.stdout(changes.length ? `${[`synced ${workspace.name}`, ...changes.map((change) => ` ${change}`)].join("\n")}\n` : `${workspace.name} already in sync\n`);
|
|
1311
|
+
return 0;
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
function workspacePath(io, options = {}) {
|
|
1315
|
+
return carnetErrors(io, () => {
|
|
1316
|
+
const workspace = currentWorkspace(io, options.workspace);
|
|
1317
|
+
io.stdout(`${options.definition ? workspace.definition : workspace.runDirectory}\n`);
|
|
1318
|
+
return 0;
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
function editorCommand(env) {
|
|
1322
|
+
return env.VISUAL || env.EDITOR || "vi";
|
|
1323
|
+
}
|
|
1324
|
+
function openEditorFor(io) {
|
|
1325
|
+
return (file) => {
|
|
1326
|
+
return spawnSync(`${editorCommand(io.env)} "$RUCHER_EDIT_FILE"`, {
|
|
1327
|
+
shell: true,
|
|
1328
|
+
stdio: "inherit",
|
|
1329
|
+
env: {
|
|
1330
|
+
...io.env,
|
|
1331
|
+
RUCHER_EDIT_FILE: file
|
|
1332
|
+
}
|
|
1333
|
+
}).status ?? 1;
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
function invalidWorkspaceFile(name, io) {
|
|
1337
|
+
try {
|
|
1338
|
+
loadWorkspace(name, io.env);
|
|
1339
|
+
return null;
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
return error instanceof Error ? error.message : String(error);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
async function workspaceEdit(io, options = {}) {
|
|
1345
|
+
let workspace;
|
|
1346
|
+
let file;
|
|
1347
|
+
try {
|
|
1348
|
+
workspace = currentWorkspace(io, options.workspace);
|
|
1349
|
+
file = join(workspace.definition, options.json ? WORKSPACE_FILE : definitionInstructions(workspace));
|
|
1350
|
+
} catch (error) {
|
|
1351
|
+
if (error instanceof CarnetError) {
|
|
1352
|
+
io.stderr(`error: ${error.message}\n`);
|
|
1353
|
+
return 1;
|
|
1354
|
+
}
|
|
1355
|
+
throw error;
|
|
1356
|
+
}
|
|
1357
|
+
const original = readFileSync(file, "utf8");
|
|
1358
|
+
const openEditor = options.openEditor ?? openEditorFor(io);
|
|
1359
|
+
for (;;) {
|
|
1360
|
+
if (openEditor(file) !== 0) {
|
|
1361
|
+
io.stderr(`error: ${editorCommand(io.env)} exited with an error, nothing synced\n`);
|
|
1362
|
+
return 1;
|
|
1363
|
+
}
|
|
1364
|
+
const problem = options.json ? invalidWorkspaceFile(workspace.name, io) : null;
|
|
1365
|
+
if (!problem) break;
|
|
1366
|
+
io.stderr(`error: ${WORKSPACE_FILE} is invalid: ${problem}\n`);
|
|
1367
|
+
if (!options.confirm || !await options.confirm("Edit it again? [Y/n] ")) {
|
|
1368
|
+
writeFileSync(file, original);
|
|
1369
|
+
io.stderr(`restored the previous ${WORKSPACE_FILE}\n`);
|
|
1370
|
+
return 1;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return workspaceSync(io, { workspace: workspace.name });
|
|
1374
|
+
}
|
|
1375
|
+
function plural(count, word) {
|
|
1376
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1377
|
+
}
|
|
1378
|
+
function workspaceList(io) {
|
|
1379
|
+
const colors = paint(io);
|
|
1380
|
+
const workspaces = listWorkspaces(io.env);
|
|
1381
|
+
if (workspaces.length === 0) {
|
|
1382
|
+
io.stdout(`${colors.dim("no workspace yet, create one with `rucher ws create <name>`")}\n`);
|
|
1383
|
+
return 0;
|
|
1384
|
+
}
|
|
1385
|
+
const carnet = openWorkspaceCarnet(null, { env: io.env });
|
|
1386
|
+
const sessions = workspaceSessionCounts(carnet.db);
|
|
1387
|
+
carnet.close();
|
|
1388
|
+
const width = Math.max(...workspaces.map((workspace) => workspace.name.length));
|
|
1389
|
+
const lines = workspaces.map((workspace) => `${colors.bold(workspace.name.padEnd(width))} ${plural(workspace.repos.length, "repo")} ${plural(sessions.get(workspace.name) ?? 0, "session")} ${colors.dim(workspace.runDirectory)}`);
|
|
1390
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
1391
|
+
return 0;
|
|
1392
|
+
}
|
|
1393
|
+
function workspaceCreate(name, io, options = {}) {
|
|
1394
|
+
const colors = paint(io);
|
|
1395
|
+
const workspace = createWorkspace(name, {
|
|
1396
|
+
repos: options.repos?.map((repo) => resolve(io.cwd, repo)),
|
|
1397
|
+
env: io.env
|
|
1398
|
+
});
|
|
1399
|
+
const result = renderRunDirectory(workspace, { env: io.env });
|
|
1400
|
+
const lines = [
|
|
1401
|
+
`${colors.bold(workspace.name)} created`,
|
|
1402
|
+
` definition: ${workspace.definition}`,
|
|
1403
|
+
` run directory: ${workspace.runDirectory}`,
|
|
1404
|
+
` repos: ${workspace.repos.length ? workspace.repos.map((repo) => repo.path).join(", ") : "none yet, add them with `rucher ws add <path> --ws " + workspace.name + "`"}`,
|
|
1405
|
+
...result.written.map((path) => ` written ${path}`),
|
|
1360
1406
|
"",
|
|
1361
|
-
|
|
1362
|
-
|
|
1407
|
+
"Accept the Claude Code trust prompt in its first session: until then the run directory settings are ignored, and rucher passes the repos with --add-dir.",
|
|
1408
|
+
`Next: \`rucher ws edit --ws ${workspace.name}\` for its instructions, then \`rucher new <session> --ws ${workspace.name}\`.`
|
|
1409
|
+
];
|
|
1410
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
1411
|
+
return 0;
|
|
1363
1412
|
}
|
|
1364
|
-
function
|
|
1365
|
-
|
|
1413
|
+
function liveSessions(carnet, isAlive) {
|
|
1414
|
+
return carnet.sessions.list({ includeTemp: true }).filter((session) => session.status === "running" && session.hostPid !== null && isAlive(session.hostPid));
|
|
1366
1415
|
}
|
|
1367
|
-
function
|
|
1368
|
-
const
|
|
1369
|
-
|
|
1370
|
-
|
|
1416
|
+
function refuseLive(carnet, action, isAlive) {
|
|
1417
|
+
const live = liveSessions(carnet, isAlive);
|
|
1418
|
+
if (live.length) throw new CliError(`${plural(live.length, "session")} of ${carnet.workspace?.name} still running: ${live.map((session) => session.name ?? session.id.slice(0, 8)).join(", ")}`, `end them before you ${action} the workspace`);
|
|
1419
|
+
}
|
|
1420
|
+
function workspaceDrop(name, io, options = {}) {
|
|
1421
|
+
const carnet = openWorkspaceCarnet(loadWorkspace(name, io.env), { env: io.env });
|
|
1371
1422
|
try {
|
|
1372
|
-
carnet
|
|
1373
|
-
|
|
1374
|
-
|
|
1423
|
+
refuseLive(carnet, "drop", options.isAlive ?? processIsAlive);
|
|
1424
|
+
const at = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
1425
|
+
const archived = archiveWorkspaceSessions(carnet.db, name, at);
|
|
1426
|
+
const deletedNotes = options.purge ? deleteWorkspaceNotes(carnet.db, name) : 0;
|
|
1427
|
+
const workspace = dropWorkspace(name, {
|
|
1428
|
+
purge: options.purge,
|
|
1429
|
+
env: io.env
|
|
1375
1430
|
});
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1431
|
+
const lines = [
|
|
1432
|
+
`dropped ${name}: definition ${workspace.definition} removed`,
|
|
1433
|
+
` sessions archived: ${archived}`,
|
|
1434
|
+
options.purge ? ` notes deleted: ${deletedNotes}; run directory ${workspace.runDirectory} removed` : ` notes and run directory kept; recreate the workspace under the same name to see them again`
|
|
1435
|
+
];
|
|
1436
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
1437
|
+
return 0;
|
|
1438
|
+
} finally {
|
|
1439
|
+
carnet.close();
|
|
1379
1440
|
}
|
|
1380
1441
|
}
|
|
1381
|
-
function
|
|
1442
|
+
function workspaceErrors(io, run) {
|
|
1382
1443
|
try {
|
|
1383
|
-
return
|
|
1384
|
-
} catch {
|
|
1385
|
-
|
|
1444
|
+
return run();
|
|
1445
|
+
} catch (error) {
|
|
1446
|
+
if (error instanceof CliError) {
|
|
1447
|
+
io.stderr(`error: ${error.message}${error.hint ? `\n ${error.hint}` : ""}\n`);
|
|
1448
|
+
return 1;
|
|
1449
|
+
}
|
|
1450
|
+
if (error instanceof CarnetError) {
|
|
1451
|
+
io.stderr(`error: ${error.message}\n`);
|
|
1452
|
+
return 1;
|
|
1453
|
+
}
|
|
1454
|
+
throw error;
|
|
1386
1455
|
}
|
|
1387
1456
|
}
|
|
1388
|
-
const CLEAR = "\x1B[H\x1B[2J";
|
|
1389
|
-
const HIDE_CURSOR = "\x1B[?25l";
|
|
1390
|
-
const SHOW_CURSOR = "\x1B[?25h";
|
|
1391
|
-
function statusWatch(carnet, io, options) {
|
|
1392
|
-
return new Promise((resolve) => {
|
|
1393
|
-
let last = "";
|
|
1394
|
-
const interactive = options.keys !== void 0 && !options.all;
|
|
1395
|
-
let state = INITIAL_WATCH_STATE;
|
|
1396
|
-
const repaint = () => {
|
|
1397
|
-
let text;
|
|
1398
|
-
try {
|
|
1399
|
-
text = renderStatusView(carnet, io, {
|
|
1400
|
-
...options,
|
|
1401
|
-
interaction: interactive ? state : void 0
|
|
1402
|
-
});
|
|
1403
|
-
} catch (error) {
|
|
1404
|
-
text = paint(io).dim(error instanceof Error ? error.message : String(error));
|
|
1405
|
-
}
|
|
1406
|
-
if (text === last) return;
|
|
1407
|
-
last = text;
|
|
1408
|
-
io.stdout(`${CLEAR}${text}\n`);
|
|
1409
|
-
};
|
|
1410
|
-
const timer = setInterval(() => {
|
|
1411
|
-
if (state.reason === null) repaint();
|
|
1412
|
-
}, options.intervalMilliseconds);
|
|
1413
|
-
let stopped = false;
|
|
1414
|
-
const stop = () => {
|
|
1415
|
-
if (stopped) return;
|
|
1416
|
-
stopped = true;
|
|
1417
|
-
clearInterval(timer);
|
|
1418
|
-
options.keys?.close();
|
|
1419
|
-
io.stdout(SHOW_CURSOR);
|
|
1420
|
-
resolve();
|
|
1421
|
-
};
|
|
1422
|
-
options.keys?.onKey((key) => {
|
|
1423
|
-
const result = pressKey(state, key, interactive ? noteCount(carnet, options) : 0);
|
|
1424
|
-
state = result.state;
|
|
1425
|
-
if (result.action?.type === "quit") return stop();
|
|
1426
|
-
if (result.action?.type === "drop") state = {
|
|
1427
|
-
...state,
|
|
1428
|
-
message: dropSelected(carnet, options, result.action.index, result.action.reason)
|
|
1429
|
-
};
|
|
1430
|
-
repaint();
|
|
1431
|
-
});
|
|
1432
|
-
options.signal?.addEventListener("abort", stop, { once: true });
|
|
1433
|
-
io.stdout(HIDE_CURSOR);
|
|
1434
|
-
repaint();
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
1457
|
// src/io.ts
|
|
1438
1458
|
function processIo(options = {}) {
|
|
1439
1459
|
const tty = process.stdout.isTTY === true;
|
|
@@ -1522,13 +1542,13 @@ const statusCommand = defineCommand({
|
|
|
1522
1542
|
default: "1",
|
|
1523
1543
|
description: "Refresh interval in seconds with --watch"
|
|
1524
1544
|
},
|
|
1525
|
-
...
|
|
1545
|
+
...workspaceArgument,
|
|
1526
1546
|
...colorArgument
|
|
1527
1547
|
},
|
|
1528
1548
|
async run({ args }) {
|
|
1529
1549
|
const io = processIo({ color: args.color });
|
|
1530
1550
|
try {
|
|
1531
|
-
const carnet = openCliCarnet(io, args.
|
|
1551
|
+
const carnet = openCliCarnet(io, args.ws);
|
|
1532
1552
|
const options = {
|
|
1533
1553
|
session: args.session,
|
|
1534
1554
|
all: args.all
|
|
@@ -1575,13 +1595,13 @@ const logCommand = defineCommand({
|
|
|
1575
1595
|
default: false,
|
|
1576
1596
|
description: "Agent events only, without session starts and ends"
|
|
1577
1597
|
},
|
|
1578
|
-
...
|
|
1598
|
+
...workspaceArgument,
|
|
1579
1599
|
...colorArgument
|
|
1580
1600
|
},
|
|
1581
1601
|
run({ args }) {
|
|
1582
1602
|
const io = processIo({ color: args.color });
|
|
1583
1603
|
try {
|
|
1584
|
-
logOnce(openCliCarnet(io, args.
|
|
1604
|
+
logOnce(openCliCarnet(io, args.ws), io, {
|
|
1585
1605
|
session: args.session,
|
|
1586
1606
|
count: Number(args.count) || 20,
|
|
1587
1607
|
md: args.md,
|
|
@@ -1595,7 +1615,7 @@ const logCommand = defineCommand({
|
|
|
1595
1615
|
const sessionsListCommand = defineCommand({
|
|
1596
1616
|
meta: {
|
|
1597
1617
|
name: "list",
|
|
1598
|
-
description: "List the named sessions of the
|
|
1618
|
+
description: "List the named sessions of the workspace"
|
|
1599
1619
|
},
|
|
1600
1620
|
args: {
|
|
1601
1621
|
all: {
|
|
@@ -1603,13 +1623,13 @@ const sessionsListCommand = defineCommand({
|
|
|
1603
1623
|
default: false,
|
|
1604
1624
|
description: "Include temp and archived sessions"
|
|
1605
1625
|
},
|
|
1606
|
-
...
|
|
1626
|
+
...workspaceArgument,
|
|
1607
1627
|
...colorArgument
|
|
1608
1628
|
},
|
|
1609
1629
|
run({ args }) {
|
|
1610
1630
|
const io = processIo({ color: args.color });
|
|
1611
1631
|
try {
|
|
1612
|
-
sessionsOnce(openCliCarnet(io, args.
|
|
1632
|
+
sessionsOnce(openCliCarnet(io, args.ws), io, { all: args.all });
|
|
1613
1633
|
} catch (error) {
|
|
1614
1634
|
fail(io, error);
|
|
1615
1635
|
}
|
|
@@ -1631,12 +1651,12 @@ const sessionsMergeCommand = defineCommand({
|
|
|
1631
1651
|
description: "Session that keeps everything (name, id or id prefix)",
|
|
1632
1652
|
required: true
|
|
1633
1653
|
},
|
|
1634
|
-
...
|
|
1654
|
+
...workspaceArgument
|
|
1635
1655
|
},
|
|
1636
1656
|
run({ args }) {
|
|
1637
1657
|
const io = processIo();
|
|
1638
1658
|
try {
|
|
1639
|
-
const carnet = openCliCarnet(io, args.
|
|
1659
|
+
const carnet = openCliCarnet(io, args.ws);
|
|
1640
1660
|
sessionsMerge(carnet, args.from, args.into, io);
|
|
1641
1661
|
carnet.close();
|
|
1642
1662
|
} catch (error) {
|
|
@@ -1661,11 +1681,11 @@ const sessionsRenameCommand = defineCommand({
|
|
|
1661
1681
|
description: "New name",
|
|
1662
1682
|
required: true
|
|
1663
1683
|
},
|
|
1664
|
-
...
|
|
1684
|
+
...workspaceArgument
|
|
1665
1685
|
},
|
|
1666
1686
|
run({ args }) {
|
|
1667
1687
|
const io = processIo();
|
|
1668
|
-
withCarnet(io, args.
|
|
1688
|
+
withCarnet(io, args.ws, (carnet) => sessionsRename(carnet, args.session, args.name, io));
|
|
1669
1689
|
}
|
|
1670
1690
|
});
|
|
1671
1691
|
const sessionsPromoteCommand = defineCommand({
|
|
@@ -1680,11 +1700,11 @@ const sessionsPromoteCommand = defineCommand({
|
|
|
1680
1700
|
description: "Name, when the session has none",
|
|
1681
1701
|
required: false
|
|
1682
1702
|
},
|
|
1683
|
-
...
|
|
1703
|
+
...workspaceArgument
|
|
1684
1704
|
},
|
|
1685
1705
|
run({ args }) {
|
|
1686
1706
|
const io = processIo();
|
|
1687
|
-
withCarnet(io, args.
|
|
1707
|
+
withCarnet(io, args.ws, (carnet) => sessionsPromote(carnet, args.session, args.name, io));
|
|
1688
1708
|
}
|
|
1689
1709
|
});
|
|
1690
1710
|
const sessionsDemoteCommand = defineCommand({
|
|
@@ -1694,11 +1714,11 @@ const sessionsDemoteCommand = defineCommand({
|
|
|
1694
1714
|
},
|
|
1695
1715
|
args: {
|
|
1696
1716
|
session: sessionReference,
|
|
1697
|
-
...
|
|
1717
|
+
...workspaceArgument
|
|
1698
1718
|
},
|
|
1699
1719
|
run({ args }) {
|
|
1700
1720
|
const io = processIo();
|
|
1701
|
-
withCarnet(io, args.
|
|
1721
|
+
withCarnet(io, args.ws, (carnet) => sessionsDemote(carnet, args.session, io));
|
|
1702
1722
|
}
|
|
1703
1723
|
});
|
|
1704
1724
|
const purgeArgument = { purge: {
|
|
@@ -1714,40 +1734,40 @@ const sessionsDropCommand = defineCommand({
|
|
|
1714
1734
|
args: {
|
|
1715
1735
|
session: sessionReference,
|
|
1716
1736
|
...purgeArgument,
|
|
1717
|
-
...
|
|
1737
|
+
...workspaceArgument
|
|
1718
1738
|
},
|
|
1719
1739
|
run({ args }) {
|
|
1720
1740
|
const io = processIo();
|
|
1721
|
-
withCarnet(io, args.
|
|
1741
|
+
withCarnet(io, args.ws, (carnet) => sessionsDrop(carnet, args.session, io, { purge: args.purge }));
|
|
1722
1742
|
}
|
|
1723
1743
|
});
|
|
1724
1744
|
const sessionsMoveCommand = defineCommand({
|
|
1725
1745
|
meta: {
|
|
1726
1746
|
name: "move",
|
|
1727
|
-
description: "Move a session, its agents, table line and journal to another
|
|
1747
|
+
description: "Move a session, its agents, table line and journal to another workspace"
|
|
1728
1748
|
},
|
|
1729
1749
|
args: {
|
|
1730
1750
|
session: sessionReference,
|
|
1731
1751
|
to: {
|
|
1732
1752
|
type: "string",
|
|
1733
1753
|
required: true,
|
|
1734
|
-
description: "Target
|
|
1754
|
+
description: "Target workspace name"
|
|
1735
1755
|
},
|
|
1736
1756
|
merge: {
|
|
1737
1757
|
type: "boolean",
|
|
1738
1758
|
default: false,
|
|
1739
|
-
description: "Merge into the session the target
|
|
1759
|
+
description: "Merge into the session the target workspace already has under this id or name"
|
|
1740
1760
|
},
|
|
1741
1761
|
"dry-run": {
|
|
1742
1762
|
type: "boolean",
|
|
1743
1763
|
default: false,
|
|
1744
1764
|
description: "Show what would move"
|
|
1745
1765
|
},
|
|
1746
|
-
...
|
|
1766
|
+
...workspaceArgument
|
|
1747
1767
|
},
|
|
1748
1768
|
run({ args }) {
|
|
1749
1769
|
const io = processIo();
|
|
1750
|
-
withCarnet(io, args.
|
|
1770
|
+
withCarnet(io, args.ws, (carnet) => sessionsMove(carnet, args.session, args.to, io, {
|
|
1751
1771
|
merge: args.merge,
|
|
1752
1772
|
dryRun: args["dry-run"]
|
|
1753
1773
|
}));
|
|
@@ -1770,11 +1790,11 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1770
1790
|
default: false,
|
|
1771
1791
|
description: "Show what would be archived"
|
|
1772
1792
|
},
|
|
1773
|
-
...
|
|
1793
|
+
...workspaceArgument
|
|
1774
1794
|
},
|
|
1775
1795
|
run({ args }) {
|
|
1776
1796
|
const io = processIo();
|
|
1777
|
-
withCarnet(io, args.
|
|
1797
|
+
withCarnet(io, args.ws, (carnet) => sessionsClean(carnet, io, {
|
|
1778
1798
|
olderThan: args["older-than"],
|
|
1779
1799
|
purge: args.purge,
|
|
1780
1800
|
dryRun: args["dry-run"]
|
|
@@ -1784,9 +1804,10 @@ const sessionsCleanCommand = defineCommand({
|
|
|
1784
1804
|
const sessionsCommand = defineCommand({
|
|
1785
1805
|
meta: {
|
|
1786
1806
|
name: "sessions",
|
|
1787
|
-
description: "List and manage the sessions of the
|
|
1807
|
+
description: "List and manage the sessions of the workspace"
|
|
1788
1808
|
},
|
|
1789
|
-
args: { ...
|
|
1809
|
+
args: { ...workspaceArgument },
|
|
1810
|
+
setup: forwardWorkspace,
|
|
1790
1811
|
default: "list",
|
|
1791
1812
|
subCommands: {
|
|
1792
1813
|
list: sessionsListCommand,
|
|
@@ -1799,9 +1820,9 @@ const sessionsCommand = defineCommand({
|
|
|
1799
1820
|
clean: sessionsCleanCommand
|
|
1800
1821
|
}
|
|
1801
1822
|
});
|
|
1802
|
-
function withCarnet(io,
|
|
1823
|
+
function withCarnet(io, workspace, run) {
|
|
1803
1824
|
try {
|
|
1804
|
-
const carnet = openCliCarnet(io,
|
|
1825
|
+
const carnet = openCliCarnet(io, workspace);
|
|
1805
1826
|
try {
|
|
1806
1827
|
run(carnet);
|
|
1807
1828
|
} finally {
|
|
@@ -1824,7 +1845,7 @@ const noteFilterArguments = {
|
|
|
1824
1845
|
const notesListCommand = defineCommand({
|
|
1825
1846
|
meta: {
|
|
1826
1847
|
name: "list",
|
|
1827
|
-
description: "Active notes of the
|
|
1848
|
+
description: "Active notes of the workspace, by kind"
|
|
1828
1849
|
},
|
|
1829
1850
|
args: {
|
|
1830
1851
|
all: {
|
|
@@ -1848,12 +1869,12 @@ const notesListCommand = defineCommand({
|
|
|
1848
1869
|
default: false,
|
|
1849
1870
|
description: "Markdown output, a view only"
|
|
1850
1871
|
},
|
|
1851
|
-
...
|
|
1872
|
+
...workspaceArgument,
|
|
1852
1873
|
...colorArgument
|
|
1853
1874
|
},
|
|
1854
1875
|
run({ args }) {
|
|
1855
1876
|
const io = processIo({ color: args.color });
|
|
1856
|
-
withCarnet(io, args.
|
|
1877
|
+
withCarnet(io, args.ws, (carnet) => notesList(carnet, io, {
|
|
1857
1878
|
all: args.all,
|
|
1858
1879
|
kind: args.kind,
|
|
1859
1880
|
repo: args.repo,
|
|
@@ -1874,12 +1895,12 @@ const notesShowCommand = defineCommand({
|
|
|
1874
1895
|
description: "Note number",
|
|
1875
1896
|
required: true
|
|
1876
1897
|
},
|
|
1877
|
-
...
|
|
1898
|
+
...workspaceArgument,
|
|
1878
1899
|
...colorArgument
|
|
1879
1900
|
},
|
|
1880
1901
|
run({ args }) {
|
|
1881
1902
|
const io = processIo({ color: args.color });
|
|
1882
|
-
withCarnet(io, args.
|
|
1903
|
+
withCarnet(io, args.ws, (carnet) => notesShow(carnet, io, parseNoteId(args.id)));
|
|
1883
1904
|
}
|
|
1884
1905
|
});
|
|
1885
1906
|
const notesAddCommand = defineCommand({
|
|
@@ -1902,12 +1923,12 @@ const notesAddCommand = defineCommand({
|
|
|
1902
1923
|
type: "string",
|
|
1903
1924
|
description: "Repo the note applies to (repeat for several)"
|
|
1904
1925
|
},
|
|
1905
|
-
...
|
|
1926
|
+
...workspaceArgument,
|
|
1906
1927
|
...colorArgument
|
|
1907
1928
|
},
|
|
1908
1929
|
run({ args, rawArgs }) {
|
|
1909
1930
|
const io = processIo({ color: args.color });
|
|
1910
|
-
withCarnet(io, args.
|
|
1931
|
+
withCarnet(io, args.ws, (carnet) => notesAdd(carnet, io, {
|
|
1911
1932
|
kind: args.kind,
|
|
1912
1933
|
text: args.text,
|
|
1913
1934
|
repos: repoList(rawArgs)
|
|
@@ -1934,12 +1955,12 @@ const notesDropCommand = defineCommand({
|
|
|
1934
1955
|
type: "string",
|
|
1935
1956
|
description: "Number of the note that replaces it"
|
|
1936
1957
|
},
|
|
1937
|
-
...
|
|
1958
|
+
...workspaceArgument
|
|
1938
1959
|
},
|
|
1939
1960
|
run({ args }) {
|
|
1940
1961
|
const io = processIo();
|
|
1941
1962
|
const replacement = args["replaced-by"];
|
|
1942
|
-
withCarnet(io, args.
|
|
1963
|
+
withCarnet(io, args.ws, (carnet) => notesDrop(carnet, io, parseNoteId(args.id), {
|
|
1943
1964
|
reason: args.reason,
|
|
1944
1965
|
replacedBy: replacement === void 0 ? void 0 : parseNoteId(replacement)
|
|
1945
1966
|
}));
|
|
@@ -1948,12 +1969,13 @@ const notesDropCommand = defineCommand({
|
|
|
1948
1969
|
const notesCommand = defineCommand({
|
|
1949
1970
|
meta: {
|
|
1950
1971
|
name: "notes",
|
|
1951
|
-
description: "The
|
|
1972
|
+
description: "The workspace's memory: learnings, decisions and dead ends"
|
|
1952
1973
|
},
|
|
1953
1974
|
args: {
|
|
1954
1975
|
...noteFilterArguments,
|
|
1955
|
-
...
|
|
1976
|
+
...workspaceArgument
|
|
1956
1977
|
},
|
|
1978
|
+
setup: forwardWorkspace,
|
|
1957
1979
|
default: "list",
|
|
1958
1980
|
subCommands: {
|
|
1959
1981
|
list: notesListCommand,
|
|
@@ -1962,14 +1984,14 @@ const notesCommand = defineCommand({
|
|
|
1962
1984
|
drop: notesDropCommand
|
|
1963
1985
|
}
|
|
1964
1986
|
});
|
|
1965
|
-
async function launch(io,
|
|
1987
|
+
async function launch(io, workspace, plan) {
|
|
1966
1988
|
try {
|
|
1967
|
-
const carnet = openCliCarnet(io,
|
|
1989
|
+
const carnet = openCliCarnet(io, workspace);
|
|
1968
1990
|
const launchPlan = await plan(carnet);
|
|
1969
1991
|
startLaunch(carnet, launchPlan);
|
|
1970
1992
|
carnet.close();
|
|
1971
1993
|
const exitCode = spawnLaunch(launchPlan, io.env);
|
|
1972
|
-
const after =
|
|
1994
|
+
const after = openWorkspaceCarnet(carnet.workspace, { env: io.env });
|
|
1973
1995
|
finishLaunch(after, launchPlan);
|
|
1974
1996
|
after.close();
|
|
1975
1997
|
process.exitCode = exitCode;
|
|
@@ -1978,12 +2000,12 @@ async function launch(io, group, plan) {
|
|
|
1978
2000
|
}
|
|
1979
2001
|
}
|
|
1980
2002
|
const passthroughHelp = "Arguments after -- are passed to Claude Code";
|
|
1981
|
-
function
|
|
2003
|
+
function withoutWorkspaceOption(own) {
|
|
1982
2004
|
const kept = [];
|
|
1983
2005
|
for (let index = 0; index < own.length; index += 1) {
|
|
1984
2006
|
const argument = own[index] ?? "";
|
|
1985
|
-
if (argument === "
|
|
1986
|
-
else if (!argument.startsWith("--
|
|
2007
|
+
if (argument === "--ws") index += 1;
|
|
2008
|
+
else if (!argument.startsWith("--ws=")) kept.push(argument);
|
|
1987
2009
|
}
|
|
1988
2010
|
return kept;
|
|
1989
2011
|
}
|
|
@@ -1998,13 +2020,13 @@ const newCommand = defineCommand({
|
|
|
1998
2020
|
description: "Session name",
|
|
1999
2021
|
required: true
|
|
2000
2022
|
},
|
|
2001
|
-
...
|
|
2023
|
+
...workspaceArgument
|
|
2002
2024
|
},
|
|
2003
2025
|
async run({ args, rawArgs }) {
|
|
2004
2026
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2005
|
-
await launch(processIo(), args.
|
|
2027
|
+
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
2006
2028
|
kind: "active",
|
|
2007
|
-
name: positionals(
|
|
2029
|
+
name: positionals(withoutWorkspaceOption(own))[0],
|
|
2008
2030
|
passthrough
|
|
2009
2031
|
}));
|
|
2010
2032
|
}
|
|
@@ -2020,13 +2042,13 @@ const tmpCommand = defineCommand({
|
|
|
2020
2042
|
description: "Optional session name",
|
|
2021
2043
|
required: false
|
|
2022
2044
|
},
|
|
2023
|
-
...
|
|
2045
|
+
...workspaceArgument
|
|
2024
2046
|
},
|
|
2025
2047
|
async run({ args, rawArgs }) {
|
|
2026
2048
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2027
|
-
await launch(processIo(), args.
|
|
2049
|
+
await launch(processIo(), args.ws, (carnet) => planNew(carnet, processIo(), {
|
|
2028
2050
|
kind: "temp",
|
|
2029
|
-
name: positionals(
|
|
2051
|
+
name: positionals(withoutWorkspaceOption(own))[0],
|
|
2030
2052
|
passthrough
|
|
2031
2053
|
}));
|
|
2032
2054
|
}
|
|
@@ -2042,13 +2064,13 @@ const resumeCommand = defineCommand({
|
|
|
2042
2064
|
description: "Session name, id or id prefix",
|
|
2043
2065
|
required: false
|
|
2044
2066
|
},
|
|
2045
|
-
...
|
|
2067
|
+
...workspaceArgument
|
|
2046
2068
|
},
|
|
2047
2069
|
async run({ args, rawArgs }) {
|
|
2048
2070
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2049
2071
|
const io = processIo();
|
|
2050
|
-
await launch(io, args.
|
|
2051
|
-
const reference = positionals(
|
|
2072
|
+
await launch(io, args.ws, async (carnet) => {
|
|
2073
|
+
const reference = positionals(withoutWorkspaceOption(own))[0] ?? (await pickSession(carnet)).id;
|
|
2052
2074
|
return planResume(carnet, io, reference, passthrough);
|
|
2053
2075
|
});
|
|
2054
2076
|
}
|
|
@@ -2074,42 +2096,114 @@ const forkCommand = defineCommand({
|
|
|
2074
2096
|
default: false,
|
|
2075
2097
|
description: "Make the new session durable (needs a name)"
|
|
2076
2098
|
},
|
|
2077
|
-
...
|
|
2099
|
+
...workspaceArgument
|
|
2078
2100
|
},
|
|
2079
2101
|
async run({ args, rawArgs }) {
|
|
2080
2102
|
const { own, passthrough } = splitPassthrough(rawArgs);
|
|
2081
|
-
const [reference, name] = positionals(
|
|
2103
|
+
const [reference, name] = positionals(withoutWorkspaceOption(own));
|
|
2082
2104
|
const io = processIo();
|
|
2083
|
-
await launch(io, args.
|
|
2105
|
+
await launch(io, args.ws, (carnet) => planFork(carnet, io, reference ?? "", {
|
|
2084
2106
|
name,
|
|
2085
2107
|
active: own.includes("--active"),
|
|
2086
2108
|
passthrough
|
|
2087
2109
|
}));
|
|
2088
2110
|
}
|
|
2089
2111
|
});
|
|
2090
|
-
|
|
2112
|
+
async function askYes(question) {
|
|
2113
|
+
const { createInterface } = await import("node:readline/promises");
|
|
2114
|
+
const prompt = createInterface({
|
|
2115
|
+
input: process.stdin,
|
|
2116
|
+
output: process.stderr
|
|
2117
|
+
});
|
|
2118
|
+
try {
|
|
2119
|
+
return !/^n/i.test((await prompt.question(question)).trim());
|
|
2120
|
+
} finally {
|
|
2121
|
+
prompt.close();
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
function commaList(value) {
|
|
2125
|
+
return value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
2126
|
+
}
|
|
2127
|
+
const wsCommand = defineCommand({
|
|
2091
2128
|
meta: {
|
|
2092
|
-
name: "
|
|
2093
|
-
description: "The
|
|
2129
|
+
name: "ws",
|
|
2130
|
+
description: "The workspaces: create, list, show, add or remove repos, render, edit instructions"
|
|
2094
2131
|
},
|
|
2132
|
+
args: { ...workspaceArgument },
|
|
2133
|
+
setup: forwardWorkspace,
|
|
2134
|
+
default: "list",
|
|
2095
2135
|
subCommands: {
|
|
2136
|
+
list: defineCommand({
|
|
2137
|
+
meta: {
|
|
2138
|
+
name: "list",
|
|
2139
|
+
description: "Workspaces with their repo and session counts"
|
|
2140
|
+
},
|
|
2141
|
+
args: { ...colorArgument },
|
|
2142
|
+
run({ args }) {
|
|
2143
|
+
process.exitCode = workspaceList(processIo({ color: args.color }));
|
|
2144
|
+
}
|
|
2145
|
+
}),
|
|
2146
|
+
create: defineCommand({
|
|
2147
|
+
meta: {
|
|
2148
|
+
name: "create",
|
|
2149
|
+
description: "Create a workspace and render its run directory"
|
|
2150
|
+
},
|
|
2151
|
+
args: {
|
|
2152
|
+
name: {
|
|
2153
|
+
type: "positional",
|
|
2154
|
+
description: "Workspace name: a-z, 0-9 and -",
|
|
2155
|
+
required: true
|
|
2156
|
+
},
|
|
2157
|
+
repos: {
|
|
2158
|
+
type: "string",
|
|
2159
|
+
description: "Comma-separated repo paths"
|
|
2160
|
+
},
|
|
2161
|
+
...colorArgument
|
|
2162
|
+
},
|
|
2163
|
+
run({ args }) {
|
|
2164
|
+
const io = processIo({ color: args.color });
|
|
2165
|
+
process.exitCode = workspaceErrors(io, () => workspaceCreate(args.name, io, { repos: commaList(args.repos) }));
|
|
2166
|
+
}
|
|
2167
|
+
}),
|
|
2168
|
+
drop: defineCommand({
|
|
2169
|
+
meta: {
|
|
2170
|
+
name: "drop",
|
|
2171
|
+
description: "Archive the sessions of a workspace and remove its definition, keeping its notes"
|
|
2172
|
+
},
|
|
2173
|
+
args: {
|
|
2174
|
+
name: {
|
|
2175
|
+
type: "positional",
|
|
2176
|
+
description: "Workspace name",
|
|
2177
|
+
required: true
|
|
2178
|
+
},
|
|
2179
|
+
purge: {
|
|
2180
|
+
type: "boolean",
|
|
2181
|
+
default: false,
|
|
2182
|
+
description: "Also delete its notes and its run directory"
|
|
2183
|
+
}
|
|
2184
|
+
},
|
|
2185
|
+
run({ args }) {
|
|
2186
|
+
const io = processIo();
|
|
2187
|
+
process.exitCode = workspaceErrors(io, () => workspaceDrop(args.name, io, { purge: args.purge }));
|
|
2188
|
+
}
|
|
2189
|
+
}),
|
|
2096
2190
|
show: defineCommand({
|
|
2097
2191
|
meta: {
|
|
2098
2192
|
name: "show",
|
|
2099
|
-
description: "Name,
|
|
2193
|
+
description: "Name, definition, run directory and repos of the workspace"
|
|
2100
2194
|
},
|
|
2101
2195
|
args: {
|
|
2102
|
-
...
|
|
2196
|
+
...workspaceArgument,
|
|
2103
2197
|
...colorArgument
|
|
2104
2198
|
},
|
|
2105
2199
|
run({ args }) {
|
|
2106
|
-
process.exitCode =
|
|
2200
|
+
process.exitCode = workspaceShow(processIo({ color: args.color }), { workspace: args.ws });
|
|
2107
2201
|
}
|
|
2108
2202
|
}),
|
|
2109
2203
|
add: defineCommand({
|
|
2110
2204
|
meta: {
|
|
2111
2205
|
name: "add",
|
|
2112
|
-
description: "Add a repo path to the
|
|
2206
|
+
description: "Add a repo path to the workspace, then render its run directory"
|
|
2113
2207
|
},
|
|
2114
2208
|
args: {
|
|
2115
2209
|
path: {
|
|
@@ -2117,17 +2211,17 @@ const groupCommand = defineCommand({
|
|
|
2117
2211
|
description: "Repo path",
|
|
2118
2212
|
required: true
|
|
2119
2213
|
},
|
|
2120
|
-
...
|
|
2214
|
+
...workspaceArgument,
|
|
2121
2215
|
...colorArgument
|
|
2122
2216
|
},
|
|
2123
2217
|
run({ args }) {
|
|
2124
|
-
process.exitCode =
|
|
2218
|
+
process.exitCode = workspaceAdd(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2125
2219
|
}
|
|
2126
2220
|
}),
|
|
2127
2221
|
remove: defineCommand({
|
|
2128
2222
|
meta: {
|
|
2129
2223
|
name: "remove",
|
|
2130
|
-
description: "Remove a repo from the
|
|
2224
|
+
description: "Remove a repo from the workspace, then render its run directory"
|
|
2131
2225
|
},
|
|
2132
2226
|
args: {
|
|
2133
2227
|
path: {
|
|
@@ -2135,42 +2229,42 @@ const groupCommand = defineCommand({
|
|
|
2135
2229
|
description: "Repo path or name",
|
|
2136
2230
|
required: true
|
|
2137
2231
|
},
|
|
2138
|
-
...
|
|
2232
|
+
...workspaceArgument,
|
|
2139
2233
|
...colorArgument
|
|
2140
2234
|
},
|
|
2141
2235
|
run({ args }) {
|
|
2142
|
-
process.exitCode =
|
|
2236
|
+
process.exitCode = workspaceRemove(args.path, processIo({ color: args.color }), { workspace: args.ws });
|
|
2143
2237
|
}
|
|
2144
2238
|
}),
|
|
2145
2239
|
sync: defineCommand({
|
|
2146
2240
|
meta: {
|
|
2147
2241
|
name: "sync",
|
|
2148
|
-
description: "Render the
|
|
2242
|
+
description: "Render the workspace's run directory (instruction copies, generated settings)"
|
|
2149
2243
|
},
|
|
2150
2244
|
args: {
|
|
2151
|
-
...
|
|
2245
|
+
...workspaceArgument,
|
|
2152
2246
|
...colorArgument
|
|
2153
2247
|
},
|
|
2154
2248
|
run({ args }) {
|
|
2155
|
-
process.exitCode =
|
|
2249
|
+
process.exitCode = workspaceSync(processIo({ color: args.color }), { workspace: args.ws });
|
|
2156
2250
|
}
|
|
2157
2251
|
}),
|
|
2158
2252
|
edit: defineCommand({
|
|
2159
2253
|
meta: {
|
|
2160
2254
|
name: "edit",
|
|
2161
|
-
description: "Open the instructions (or
|
|
2255
|
+
description: "Open the instructions (or workspace.json with --json) in $EDITOR, then sync"
|
|
2162
2256
|
},
|
|
2163
2257
|
args: {
|
|
2164
2258
|
json: {
|
|
2165
2259
|
type: "boolean",
|
|
2166
2260
|
default: false,
|
|
2167
|
-
description: "Edit
|
|
2261
|
+
description: "Edit workspace.json instead"
|
|
2168
2262
|
},
|
|
2169
|
-
...
|
|
2263
|
+
...workspaceArgument
|
|
2170
2264
|
},
|
|
2171
2265
|
async run({ args }) {
|
|
2172
|
-
process.exitCode = await
|
|
2173
|
-
|
|
2266
|
+
process.exitCode = await workspaceEdit(processIo(), {
|
|
2267
|
+
workspace: args.ws,
|
|
2174
2268
|
json: args.json,
|
|
2175
2269
|
confirm: askYes
|
|
2176
2270
|
});
|
|
@@ -2179,130 +2273,30 @@ const groupCommand = defineCommand({
|
|
|
2179
2273
|
path: defineCommand({
|
|
2180
2274
|
meta: {
|
|
2181
2275
|
name: "path",
|
|
2182
|
-
description: "Print the
|
|
2276
|
+
description: "Print the run directory path (or the definition with --def), for cd \"$(...)\""
|
|
2183
2277
|
},
|
|
2184
2278
|
args: {
|
|
2185
|
-
|
|
2279
|
+
def: {
|
|
2186
2280
|
type: "boolean",
|
|
2187
2281
|
default: false,
|
|
2188
|
-
description: "The
|
|
2282
|
+
description: "The definition folder instead"
|
|
2189
2283
|
},
|
|
2190
|
-
|
|
2284
|
+
run: {
|
|
2191
2285
|
type: "boolean",
|
|
2192
2286
|
default: false,
|
|
2193
|
-
description: "The
|
|
2287
|
+
description: "The run directory (default)"
|
|
2194
2288
|
},
|
|
2195
|
-
...
|
|
2289
|
+
...workspaceArgument
|
|
2196
2290
|
},
|
|
2197
2291
|
run({ args }) {
|
|
2198
|
-
process.exitCode =
|
|
2199
|
-
|
|
2200
|
-
|
|
2292
|
+
process.exitCode = workspacePath(processIo(), {
|
|
2293
|
+
workspace: args.ws,
|
|
2294
|
+
definition: args.def
|
|
2201
2295
|
});
|
|
2202
2296
|
}
|
|
2203
2297
|
})
|
|
2204
2298
|
}
|
|
2205
2299
|
});
|
|
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
|
-
}
|
|
2221
|
-
const groupsCommand = defineCommand({
|
|
2222
|
-
meta: {
|
|
2223
|
-
name: "groups",
|
|
2224
|
-
description: "The groups of this machine"
|
|
2225
|
-
},
|
|
2226
|
-
default: "list",
|
|
2227
|
-
subCommands: {
|
|
2228
|
-
list: defineCommand({
|
|
2229
|
-
meta: {
|
|
2230
|
-
name: "list",
|
|
2231
|
-
description: "Groups with their repo and session counts"
|
|
2232
|
-
},
|
|
2233
|
-
args: { ...colorArgument },
|
|
2234
|
-
run({ args }) {
|
|
2235
|
-
process.exitCode = groupsList(processIo({ color: args.color }));
|
|
2236
|
-
}
|
|
2237
|
-
}),
|
|
2238
|
-
create: defineCommand({
|
|
2239
|
-
meta: {
|
|
2240
|
-
name: "create",
|
|
2241
|
-
description: "Create a group and render its workspace"
|
|
2242
|
-
},
|
|
2243
|
-
args: {
|
|
2244
|
-
name: {
|
|
2245
|
-
type: "positional",
|
|
2246
|
-
description: "Group name: a-z, 0-9 and -",
|
|
2247
|
-
required: true
|
|
2248
|
-
},
|
|
2249
|
-
repos: {
|
|
2250
|
-
type: "string",
|
|
2251
|
-
description: "Comma-separated repo paths"
|
|
2252
|
-
},
|
|
2253
|
-
...colorArgument
|
|
2254
|
-
},
|
|
2255
|
-
run({ args }) {
|
|
2256
|
-
const io = processIo({ color: args.color });
|
|
2257
|
-
process.exitCode = groupsErrors(io, () => groupsCreate(args.name, io, { repos: commaList(args.repos) }));
|
|
2258
|
-
}
|
|
2259
|
-
}),
|
|
2260
|
-
rename: defineCommand({
|
|
2261
|
-
meta: {
|
|
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
|
-
}
|
|
2298
|
-
},
|
|
2299
|
-
run({ args }) {
|
|
2300
|
-
const io = processIo();
|
|
2301
|
-
process.exitCode = groupsErrors(io, () => groupsDrop(args.name, io, { purge: args.purge }));
|
|
2302
|
-
}
|
|
2303
|
-
})
|
|
2304
|
-
}
|
|
2305
|
-
});
|
|
2306
2300
|
const hookCommand = defineCommand({
|
|
2307
2301
|
meta: {
|
|
2308
2302
|
name: "hook",
|
|
@@ -2374,12 +2368,18 @@ const serveCommand = defineCommand({
|
|
|
2374
2368
|
serve(processIo());
|
|
2375
2369
|
}
|
|
2376
2370
|
});
|
|
2371
|
+
function refuseRemovedOption(rawArgs) {
|
|
2372
|
+
const removed = /^(-g|--group)(=|$)/;
|
|
2373
|
+
const option = splitPassthrough([...rawArgs]).own.find((argument) => removed.test(argument));
|
|
2374
|
+
if (option) fail(processIo(), new CliError(`Unknown option ${option}`, "use --ws <name>"));
|
|
2375
|
+
}
|
|
2377
2376
|
const main = defineCommand({
|
|
2378
2377
|
meta: {
|
|
2379
2378
|
name: "rucher",
|
|
2380
2379
|
version,
|
|
2381
2380
|
description: "Status, journal and sessions of your coding agents (Claude Code today)"
|
|
2382
2381
|
},
|
|
2382
|
+
setup: ({ rawArgs }) => refuseRemovedOption(rawArgs),
|
|
2383
2383
|
subCommands: {
|
|
2384
2384
|
status: statusCommand,
|
|
2385
2385
|
log: logCommand,
|
|
@@ -2389,8 +2389,7 @@ const main = defineCommand({
|
|
|
2389
2389
|
fork: forkCommand,
|
|
2390
2390
|
sessions: sessionsCommand,
|
|
2391
2391
|
notes: notesCommand,
|
|
2392
|
-
|
|
2393
|
-
groups: groupsCommand,
|
|
2392
|
+
ws: wsCommand,
|
|
2394
2393
|
hook: hookCommand,
|
|
2395
2394
|
serve: serveCommand
|
|
2396
2395
|
}
|