muuuuse 1.3.2 → 1.4.1
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 +33 -66
- package/package.json +2 -3
- package/src/agents.js +76 -224
- package/src/cli.js +47 -119
- package/src/runtime.js +625 -373
- package/src/util.js +43 -123
- package/src/tmux.js +0 -170
package/src/cli.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
commandExists,
|
|
4
|
-
parseFlags,
|
|
5
|
-
readCommandVersion,
|
|
6
|
-
usage,
|
|
7
|
-
} = require("./util");
|
|
8
|
-
const {
|
|
9
|
-
SeatProcess,
|
|
10
|
-
readAllSessionStatuses,
|
|
11
|
-
readSessionStatus,
|
|
12
|
-
resolveProgramTokens,
|
|
13
|
-
resolveSessionName,
|
|
14
|
-
stopSessions,
|
|
15
|
-
} = require("./runtime");
|
|
1
|
+
const { BRAND, usage } = require("./util");
|
|
2
|
+
const { ArmedSeat, getStatusReport, stopAllSessions } = require("./runtime");
|
|
16
3
|
|
|
17
4
|
async function main(argv = process.argv.slice(2)) {
|
|
18
5
|
if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
|
|
@@ -20,154 +7,95 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
20
7
|
return;
|
|
21
8
|
}
|
|
22
9
|
|
|
23
|
-
const command = argv[0];
|
|
24
|
-
|
|
25
|
-
if (command === "doctor") {
|
|
26
|
-
runDoctor();
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
10
|
+
const command = String(argv[0] || "").trim().toLowerCase();
|
|
29
11
|
|
|
30
12
|
if (command === "stop") {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (result.sessions.length === 0) {
|
|
34
|
-
process.stdout.write(`${BRAND} no live sessions found.\n`);
|
|
35
|
-
return;
|
|
13
|
+
if (argv.length > 1) {
|
|
14
|
+
throw new Error("`muuuuse stop` takes no extra arguments.");
|
|
36
15
|
}
|
|
37
16
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
const result = stopAllSessions();
|
|
18
|
+
if (result.sessions.length === 0) {
|
|
19
|
+
process.stdout.write(`${BRAND} no armed seats found.\n`);
|
|
20
|
+
return;
|
|
42
21
|
}
|
|
43
22
|
|
|
23
|
+
process.stdout.write(`${BRAND} stop requested.\n`);
|
|
44
24
|
for (const session of result.sessions) {
|
|
45
25
|
process.stdout.write(`${session.sessionName}\n`);
|
|
46
26
|
for (const seat of session.seats) {
|
|
47
|
-
process.stdout.write(
|
|
48
|
-
`seat ${seat.seatId}: wrapper ${describeStopResult(seat.wrapperStopped, seat.wrapperForced)}`
|
|
49
|
-
+ `, child ${describeStopResult(seat.childStopped, seat.childForced)}\n`
|
|
50
|
-
);
|
|
27
|
+
process.stdout.write(`seat ${seat.seatId}: ${seat.state} · agent ${seat.agent || "idle"} · relays ${seat.relayCount}\n`);
|
|
51
28
|
}
|
|
52
29
|
}
|
|
53
30
|
return;
|
|
54
31
|
}
|
|
55
32
|
|
|
56
33
|
if (command === "status") {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
printSessionStatus(readSessionStatus(flags.session));
|
|
60
|
-
return;
|
|
34
|
+
if (argv.length > 1) {
|
|
35
|
+
throw new Error("`muuuuse status` takes no extra arguments.");
|
|
61
36
|
}
|
|
62
37
|
|
|
63
|
-
const
|
|
64
|
-
if (sessions.length === 0) {
|
|
65
|
-
process.stdout.write(`${BRAND} no
|
|
38
|
+
const report = getStatusReport();
|
|
39
|
+
if (report.sessions.length === 0) {
|
|
40
|
+
process.stdout.write(`${BRAND} no armed seats found.\n`);
|
|
66
41
|
return;
|
|
67
42
|
}
|
|
68
43
|
|
|
69
|
-
|
|
70
|
-
|
|
44
|
+
process.stdout.write(`${BRAND} status\n`);
|
|
45
|
+
for (const session of report.sessions) {
|
|
46
|
+
process.stdout.write(`\n${session.sessionName}\n`);
|
|
47
|
+
if (session.stopRequestedAt) {
|
|
48
|
+
process.stdout.write(`stop requested: ${session.stopRequestedAt}\n`);
|
|
49
|
+
}
|
|
50
|
+
for (const seat of session.seats) {
|
|
51
|
+
process.stdout.write(renderSeatStatus(seat));
|
|
52
|
+
}
|
|
71
53
|
}
|
|
72
54
|
return;
|
|
73
55
|
}
|
|
74
56
|
|
|
75
57
|
if (command === "1" || command === "2") {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
if (argv.length > 1) {
|
|
59
|
+
throw new Error(`\`muuuuse ${command}\` takes no extra arguments. Run it directly in the terminal you want to arm.`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const seat = new ArmedSeat({
|
|
81
63
|
cwd: process.cwd(),
|
|
82
|
-
maxRelays: flags.maxRelays,
|
|
83
64
|
seatId: Number(command),
|
|
84
|
-
sessionName,
|
|
85
65
|
});
|
|
86
66
|
const code = await seat.run();
|
|
87
67
|
process.exit(code);
|
|
88
68
|
}
|
|
89
69
|
|
|
90
|
-
if (command === "3") {
|
|
91
|
-
const { positionals, flags } = parseFlags(argv.slice(1));
|
|
92
|
-
const action = String(positionals[0] || "status").toLowerCase();
|
|
93
|
-
|
|
94
|
-
if (action === "stop") {
|
|
95
|
-
const forwarded = ["stop", ...argv.slice(1).filter((token) => token !== "stop")];
|
|
96
|
-
await main(forwarded);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (action === "status") {
|
|
101
|
-
const forwarded = ["status", ...argv.slice(1).filter((token) => token !== "status")];
|
|
102
|
-
await main(forwarded);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
throw new Error(`Unknown seat 3 action '${action}'. Try \`muuuuse stop\` or \`muuuuse status\`.`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
70
|
throw new Error(`Unknown command '${command}'.`);
|
|
110
71
|
}
|
|
111
72
|
|
|
112
|
-
function
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
73
|
+
function renderSeatStatus(seat) {
|
|
74
|
+
const bits = [
|
|
75
|
+
`seat ${seat.seatId}: ${seat.state}`,
|
|
76
|
+
`agent ${seat.agent || "idle"}`,
|
|
77
|
+
`relays ${seat.relayCount}`,
|
|
78
|
+
`wrapper ${seat.wrapperPid || "-"}`,
|
|
79
|
+
`child ${seat.childPid || "-"}`,
|
|
119
80
|
];
|
|
120
81
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
process.stdout.write(`${item.ok ? "OK " : "MISS"} ${item.label}${item.detail ? `: ${item.detail}` : ""}\n`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
process.stdout.write("\nKnown presets\n");
|
|
127
|
-
process.stdout.write("- codex\n");
|
|
128
|
-
process.stdout.write("- claude\n");
|
|
129
|
-
process.stdout.write("- gemini\n");
|
|
130
|
-
process.stdout.write("\nAny other local program can be wrapped directly with `muuuuse 1 <program...>` or `muuuuse 2 <program...>`.\n");
|
|
131
|
-
|
|
132
|
-
const missingRequired = checks.some((item) => item.required && !item.ok);
|
|
133
|
-
if (missingRequired) {
|
|
134
|
-
process.exitCode = 1;
|
|
82
|
+
if (seat.partnerLive) {
|
|
83
|
+
bits.push("peer live");
|
|
135
84
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
function checkBinary(command, versionArgs, required) {
|
|
139
|
-
if (!commandExists(command)) {
|
|
140
|
-
return { label: command, ok: false, detail: "not installed", required };
|
|
85
|
+
if (seat.lastAnswerAt) {
|
|
86
|
+
bits.push(`last answer ${seat.lastAnswerAt}`);
|
|
141
87
|
}
|
|
142
|
-
const version = readCommandVersion(command, versionArgs) || "installed";
|
|
143
|
-
return { label: command, ok: true, detail: version, required };
|
|
144
|
-
}
|
|
145
88
|
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
if (signaled) {
|
|
151
|
-
return "signaled";
|
|
89
|
+
let output = `${bits.join(" · ")}\n`;
|
|
90
|
+
if (seat.cwd) {
|
|
91
|
+
output += `cwd: ${seat.cwd}\n`;
|
|
152
92
|
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function printSessionStatus(status) {
|
|
157
|
-
process.stdout.write(`${BRAND} session ${status.sessionName}\n`);
|
|
158
|
-
for (const seat of status.seats) {
|
|
159
|
-
if (!seat.status) {
|
|
160
|
-
process.stdout.write(`seat ${seat.seatId}: idle\n`);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const state = seat.status.state || "unknown";
|
|
165
|
-
const program = Array.isArray(seat.status.command) ? seat.status.command.join(" ") : "";
|
|
166
|
-
process.stdout.write(`seat ${seat.seatId}: ${state}${program ? ` (${program})` : ""}\n`);
|
|
93
|
+
if (seat.log) {
|
|
94
|
+
output += `log: ${seat.log}\n`;
|
|
167
95
|
}
|
|
96
|
+
return output;
|
|
168
97
|
}
|
|
169
98
|
|
|
170
99
|
module.exports = {
|
|
171
100
|
main,
|
|
172
|
-
runDoctor,
|
|
173
101
|
};
|