@monoclaw/machine 1.0.4 → 1.0.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/dist/cli.js +70 -12
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -511,9 +511,24 @@ function ensureKeypair(cfg) {
|
|
|
511
511
|
}
|
|
512
512
|
function requireConfig() {
|
|
513
513
|
const c = loadConfig();
|
|
514
|
-
if (!c)
|
|
514
|
+
if (!c) {
|
|
515
|
+
const others = currentProfile() ? [] : enrolledProfiles();
|
|
516
|
+
if (others.length) throw new Error(`This computer's enrolments are under profiles: ${others.map((p) => `"${p.profile}"${p.config.spaceName ? ` (${p.config.spaceName})` : ""}`).join(", ")}. Name one: monoclaw --profile ${others[0].profile} <command>`);
|
|
517
|
+
throw new Error(`Not enrolled. Run: monoclaw enrol <token> --router <url>`);
|
|
518
|
+
}
|
|
515
519
|
return c;
|
|
516
520
|
}
|
|
521
|
+
function enrolledProfiles() {
|
|
522
|
+
return listProfiles().flatMap((p) => p.profile && p.config ? [{ profile: p.profile, config: p.config }] : []);
|
|
523
|
+
}
|
|
524
|
+
function impliedProfile() {
|
|
525
|
+
if (currentProfile() || fs2.existsSync(path2.join(baseDir(), "config.json"))) return null;
|
|
526
|
+
const named = enrolledProfiles();
|
|
527
|
+
return named.length === 1 ? named[0].profile : null;
|
|
528
|
+
}
|
|
529
|
+
function connectResultPath() {
|
|
530
|
+
return path2.join(baseDir(), "connect-result.json");
|
|
531
|
+
}
|
|
517
532
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
518
533
|
function assertRouterUrl(routerUrl, allowInsecure = false) {
|
|
519
534
|
const u = new URL(routerUrl);
|
|
@@ -4223,7 +4238,7 @@ function guessMime(name) {
|
|
|
4223
4238
|
}
|
|
4224
4239
|
|
|
4225
4240
|
// src/version.ts
|
|
4226
|
-
var APP_VERSION = true ? "1.0.
|
|
4241
|
+
var APP_VERSION = true ? "1.0.5" : fromPackage();
|
|
4227
4242
|
|
|
4228
4243
|
// src/client.ts
|
|
4229
4244
|
var HEARTBEAT_MS = 2e4;
|
|
@@ -4872,7 +4887,7 @@ function planEnrol(preview, profiles, routerUrl, opts) {
|
|
|
4872
4887
|
machineName: same.config.name,
|
|
4873
4888
|
message: `This computer is already enrolled in ${preview.space.name} (@${preview.space.handle}) as "${same.config.name}"${where}. Nothing to do: the token was not used.
|
|
4874
4889
|
If the machine shows offline in the app, start it: ${same.profile ? `monoclaw --profile ${same.profile} start` : "monoclaw start"} (or \`${same.profile ? `monoclaw --profile ${same.profile} ` : "monoclaw "}service install\` to run it in the background).
|
|
4875
|
-
To
|
|
4890
|
+
To connect it afresh instead, remove this machine on its page in the app first, then run the command from Add a machine again.`
|
|
4876
4891
|
};
|
|
4877
4892
|
}
|
|
4878
4893
|
if (same && requested !== null && requested !== same.profile) {
|
|
@@ -5174,6 +5189,17 @@ function enrolArgs(o, hasEnrolment, home = os5.homedir()) {
|
|
|
5174
5189
|
if (o.insecure) args2.push("--insecure");
|
|
5175
5190
|
return args2;
|
|
5176
5191
|
}
|
|
5192
|
+
var profileArgs = (profile) => profile ? ["--profile", profile] : [];
|
|
5193
|
+
function enrolledProfile(file = connectResultPath()) {
|
|
5194
|
+
try {
|
|
5195
|
+
const r = JSON.parse(fs18.readFileSync(file, "utf8"));
|
|
5196
|
+
return typeof r.profile === "string" && r.profile ? r.profile : null;
|
|
5197
|
+
} catch {
|
|
5198
|
+
return null;
|
|
5199
|
+
} finally {
|
|
5200
|
+
fs18.rmSync(file, { force: true });
|
|
5201
|
+
}
|
|
5202
|
+
}
|
|
5177
5203
|
function installFailure(message) {
|
|
5178
5204
|
if (/EACCES|permission denied/i.test(message)) return "npm isn't allowed to install here (permission denied). Don't use sudo: install Node with Homebrew or nvm, which keep it in your own folders, then run this again.";
|
|
5179
5205
|
return `npm could not install ${PACKAGE}: ${message.trim().split("\n").slice(-3).join(" ").slice(0, 300)}`;
|
|
@@ -5214,20 +5240,21 @@ async function connect(o, out = { say: (s) => console.log(s), fail: (s) => conso
|
|
|
5214
5240
|
return 1;
|
|
5215
5241
|
}
|
|
5216
5242
|
}
|
|
5217
|
-
const hasEnrolment =
|
|
5243
|
+
const hasEnrolment = listProfiles().some((p) => p.config);
|
|
5244
|
+
fs18.rmSync(connectResultPath(), { force: true });
|
|
5218
5245
|
if (await run2(node, script, enrolArgs(o, hasEnrolment)) !== 0) {
|
|
5219
5246
|
out.fail("This computer was not connected. If the token has run out, copy a new command from Add a machine.");
|
|
5220
5247
|
return 1;
|
|
5221
5248
|
}
|
|
5222
|
-
const profile = o.profile
|
|
5249
|
+
const profile = profileArgs(o.profile ?? enrolledProfile());
|
|
5223
5250
|
if (o.service && await run2(node, script, [...profile, "service", "install"]) !== 0) {
|
|
5224
|
-
out.fail(
|
|
5251
|
+
out.fail(`The background service could not be installed here. Run it in this terminal instead: monoclaw ${[...profile, "start"].join(" ")}`);
|
|
5225
5252
|
return 1;
|
|
5226
5253
|
}
|
|
5227
5254
|
out.say("");
|
|
5228
5255
|
await run2(node, script, [...profile, "doctor"]);
|
|
5229
5256
|
out.say("");
|
|
5230
|
-
out.say(o.service ? "Connected. Go back to MonoClaw in your browser: it has moved on by itself." :
|
|
5257
|
+
out.say(o.service ? "Connected. Go back to MonoClaw in your browser: it has moved on by itself." : `Connected. Now run it: monoclaw ${[...profile, "start"].join(" ")}`);
|
|
5231
5258
|
return 0;
|
|
5232
5259
|
}
|
|
5233
5260
|
|
|
@@ -6368,7 +6395,7 @@ function installService(run3 = runSync) {
|
|
|
6368
6395
|
must("systemctl", ["--user", "daemon-reload"]);
|
|
6369
6396
|
must("systemctl", ["--user", "enable", "--now", names.unit]);
|
|
6370
6397
|
must("systemctl", ["--user", "restart", names.unit]);
|
|
6371
|
-
return { file: r.file, target, notes: [
|
|
6398
|
+
return { file: r.file, target, notes: [lingerNote(run3), `Logs: journalctl --user -u ${names.unit} -f`].filter((n) => !!n) };
|
|
6372
6399
|
}
|
|
6373
6400
|
must("powershell", ["-ExecutionPolicy", "Bypass", "-File", r.file]);
|
|
6374
6401
|
return { file: r.file, target: `Task Scheduler: ${names.task}`, notes: [`Check: Get-ScheduledTask -TaskName "${names.task}"`] };
|
|
@@ -6392,6 +6419,21 @@ function uninstallService(run3 = runSync) {
|
|
|
6392
6419
|
run3("powershell", ["-Command", `Unregister-ScheduledTask -TaskName "${names.task}" -Confirm:$false`]);
|
|
6393
6420
|
return `Task Scheduler: ${names.task}`;
|
|
6394
6421
|
}
|
|
6422
|
+
function lingerEnabled() {
|
|
6423
|
+
if (process.platform !== "linux") return null;
|
|
6424
|
+
const r = spawnSync("loginctl", ["show-user", os7.userInfo().username, "--property=Linger", "--value"], { encoding: "utf8" });
|
|
6425
|
+
if (r.status !== 0) return null;
|
|
6426
|
+
const v = String(r.stdout ?? "").trim();
|
|
6427
|
+
return v === "yes" ? true : v === "no" ? false : null;
|
|
6428
|
+
}
|
|
6429
|
+
var LINGER_FIX = "loginctl enable-linger $USER";
|
|
6430
|
+
function lingerNote(run3) {
|
|
6431
|
+
const on = lingerEnabled();
|
|
6432
|
+
if (on !== false) return null;
|
|
6433
|
+
const r = run3("loginctl", ["enable-linger", os7.userInfo().username]);
|
|
6434
|
+
if (r.status === 0 && lingerEnabled() === true) return "Set to keep running when you log out (linger is on for your user).";
|
|
6435
|
+
return `IMPORTANT: this machine will go offline when you log out of this computer. To keep it running, run: ${LINGER_FIX} (it may ask for your password, or need sudo)`;
|
|
6436
|
+
}
|
|
6395
6437
|
|
|
6396
6438
|
// src/cli.ts
|
|
6397
6439
|
import { spawn as spawn5 } from "node:child_process";
|
|
@@ -6402,9 +6444,16 @@ async function readTokenFromStdin() {
|
|
|
6402
6444
|
return data.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
6403
6445
|
}
|
|
6404
6446
|
var program = new Command();
|
|
6405
|
-
program.name("monoclaw").description("MonoClaw machine: runs your agents, voices, transcription and images on this computer for your MonoClaw projects.").version(APP_VERSION).option("--profile <name>", "Which enrolment on this computer (one per space): `monoclaw --profile guestlab start`. Default: the first enrolment.").hook("preAction", () => {
|
|
6447
|
+
program.name("monoclaw").description("MonoClaw machine: runs your agents, voices, transcription and images on this computer for your MonoClaw projects.").version(APP_VERSION).option("--profile <name>", "Which enrolment on this computer (one per space): `monoclaw --profile guestlab start`. Default: the first enrolment.").hook("preAction", (_this, action) => {
|
|
6406
6448
|
const p = program.opts().profile;
|
|
6407
6449
|
if (p) process.env.MONOCLAW_PROFILE = assertProfileName(p);
|
|
6450
|
+
else if (!["enrol", "connect"].includes(action.name())) {
|
|
6451
|
+
const only2 = impliedProfile();
|
|
6452
|
+
if (only2) {
|
|
6453
|
+
process.env.MONOCLAW_PROFILE = only2;
|
|
6454
|
+
console.error(`(Using the profile "${only2}", this computer's only enrolment.)`);
|
|
6455
|
+
}
|
|
6456
|
+
}
|
|
6408
6457
|
});
|
|
6409
6458
|
var cmd = (rest) => `monoclaw ${currentProfile() ? `--profile ${currentProfile()} ` : ""}${rest}`;
|
|
6410
6459
|
async function confirm(question, fallback) {
|
|
@@ -6431,8 +6480,12 @@ program.command("enrol [token]").description("Connect this machine to your MonoC
|
|
|
6431
6480
|
const profiles = listProfiles();
|
|
6432
6481
|
const preview = await previewToken(opts.router, token, profiles.map((p) => p.config?.hostId ?? "").filter(Boolean), opts.insecure);
|
|
6433
6482
|
const plan = planEnrol(preview, profiles, opts.router, { requestedProfile: currentProfile(), defaultName: os8.hostname() });
|
|
6483
|
+
const report = (profile) => {
|
|
6484
|
+
if (process.env.MONOCLAW_CONNECT) fs22.writeFileSync(connectResultPath(), JSON.stringify({ profile, at: (/* @__PURE__ */ new Date()).toISOString() }), { mode: 384 });
|
|
6485
|
+
};
|
|
6434
6486
|
if (plan.action === "already") {
|
|
6435
6487
|
console.log(plan.message);
|
|
6488
|
+
report(plan.profile);
|
|
6436
6489
|
return;
|
|
6437
6490
|
}
|
|
6438
6491
|
if (plan.confirm) {
|
|
@@ -6467,6 +6520,7 @@ program.command("enrol [token]").description("Connect this machine to your MonoC
|
|
|
6467
6520
|
console.log(`This computer now runs one machine per space; its modules and Claude login are shared. The first enrolment is untouched.`);
|
|
6468
6521
|
}
|
|
6469
6522
|
if (!cfg.roots.length) console.log(`No folders exposed yet. Add one with: ${cmd("roots add ~/command")}`);
|
|
6523
|
+
report(currentProfile());
|
|
6470
6524
|
if (process.env.MONOCLAW_CONNECT) return;
|
|
6471
6525
|
console.log(`
|
|
6472
6526
|
Next, run it (one of):
|
|
@@ -6720,15 +6774,19 @@ program.command("doctor").description("Check and repair what a working host need
|
|
|
6720
6774
|
}
|
|
6721
6775
|
} else lines.push({ ok: false, what: "No Claude Code to run sessions with", fix: "Run `monoclaw doctor` again; if the copy still can't be installed, install Claude Code from https://claude.com/claude-code" });
|
|
6722
6776
|
const cfg = loadConfig();
|
|
6723
|
-
|
|
6777
|
+
const named = currentProfile() ? [] : listProfiles().filter((p) => p.profile && p.config);
|
|
6778
|
+
if (!cfg && named.length) lines.push({ ok: false, info: true, what: `No default enrolment; this computer's enrolments are under profiles: ${named.map((p) => p.profile).join(", ")}`, fix: `monoclaw --profile ${named[0].profile} doctor checks that one` });
|
|
6779
|
+
else if (!cfg) lines.push({ ok: false, info: true, what: "Not enrolled yet", fix: "Copy the command from Add a machine in the app: npx -y @monoclaw/machine@latest connect <token>" });
|
|
6724
6780
|
else {
|
|
6725
6781
|
lines.push({ ok: true, what: `Enrolled as "${cfg.name}" with ${cfg.routerUrl}` });
|
|
6726
6782
|
const missing = cfg.roots.filter((r) => !fs22.existsSync(r));
|
|
6727
6783
|
const exposing = cfg.roots.filter((r) => rootExposesConfig(r, configDir()));
|
|
6728
6784
|
if (exposing.length) lines.push({ ok: false, what: `${exposing.join(", ")} contains this host's config folder, so it is not offered to agents`, fix: `monoclaw roots remove ${exposing[0]}, then monoclaw roots add <a folder inside it>` });
|
|
6729
6785
|
lines.push({ ok: cfg.roots.length > 0 && !missing.length, what: cfg.roots.length ? `Exposed folders: ${cfg.roots.join(", ")}${missing.length ? ` (missing: ${missing.join(", ")})` : ""}` : "No folders exposed", fix: !cfg.roots.length ? "monoclaw roots add ~/command" : missing.length ? "Create them, or remove them with `monoclaw roots remove <path>`" : void 0 });
|
|
6730
|
-
const
|
|
6731
|
-
|
|
6786
|
+
const names = serviceNames();
|
|
6787
|
+
const unit = process.platform === "darwin" ? path22.join(os8.homedir(), "Library", "LaunchAgents", `${names.label}.plist`) : process.platform === "linux" ? path22.join(os8.homedir(), ".config", "systemd", "user", `${names.unit}.service`) : null;
|
|
6788
|
+
if (unit) lines.push({ ok: fs22.existsSync(unit), info: true, what: fs22.existsSync(unit) ? `Background service installed (${unit})` : "Not running as a background service (fine for now)", fix: fs22.existsSync(unit) ? void 0 : `${cmd("service install")} to run at login` });
|
|
6789
|
+
if (unit && fs22.existsSync(unit) && lingerEnabled() === false) lines.push({ ok: false, what: "This machine goes offline when you log out of this computer (linger is off for your user)", fix: LINGER_FIX });
|
|
6732
6790
|
const { registry } = await makeContext(cfg);
|
|
6733
6791
|
await registry.refreshReadiness();
|
|
6734
6792
|
const reports = registry.reports();
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoclaw/machine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@monoclaw/machine",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.5",
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.3.302",
|
package/package.json
CHANGED