@monoclaw/machine 1.0.4 → 1.0.6
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 +92 -15
- package/npm-shrinkwrap.json +11 -11
- 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.6" : 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
|
|
|
@@ -5694,6 +5721,12 @@ ${s.agentBrief.trim().slice(0, 4e3)}` : "",
|
|
|
5694
5721
|
parts.push(notes.join("\n"));
|
|
5695
5722
|
return parts.join("\n\n");
|
|
5696
5723
|
}
|
|
5724
|
+
function runEnding(subtype, errors, stopRequested) {
|
|
5725
|
+
const errs = errors.length ? errors.join("; ") : subtype;
|
|
5726
|
+
const said = /interrupt/i.test(`${subtype} ${errs}`);
|
|
5727
|
+
if (stopRequested || subtype === "error_during_execution" && /interrupt/i.test(errs)) return { error: null, interrupted: true };
|
|
5728
|
+
return { error: `Run ended: ${errs}`.slice(0, 500), interrupted: said };
|
|
5729
|
+
}
|
|
5697
5730
|
var ClaudeSession = class {
|
|
5698
5731
|
constructor(opts) {
|
|
5699
5732
|
this.opts = opts;
|
|
@@ -5918,10 +5951,14 @@ var ClaudeSession = class {
|
|
|
5918
5951
|
if (msg.subtype === "success") {
|
|
5919
5952
|
this.q.push({ kind: "usage", inputTokens: msg.usage?.input_tokens, outputTokens: msg.usage?.output_tokens, costUsd: msg.total_cost_usd, durationMs: msg.duration_ms, turns: msg.num_turns });
|
|
5920
5953
|
} else {
|
|
5921
|
-
const
|
|
5922
|
-
if (
|
|
5954
|
+
const end = runEnding(msg.subtype, "errors" in msg && Array.isArray(msg.errors) ? msg.errors : [], this.stopJustRequested());
|
|
5955
|
+
if (end.error) this.q.push({ kind: "error", message: end.error, fatal: false });
|
|
5956
|
+
this.q.push({ kind: "done", interrupted: end.interrupted });
|
|
5957
|
+
this.stopRequestedAt = 0;
|
|
5958
|
+
return;
|
|
5923
5959
|
}
|
|
5924
|
-
this.q.push({ kind: "done", interrupted:
|
|
5960
|
+
this.q.push({ kind: "done", interrupted: false });
|
|
5961
|
+
this.stopRequestedAt = 0;
|
|
5925
5962
|
return;
|
|
5926
5963
|
}
|
|
5927
5964
|
default:
|
|
@@ -5971,7 +6008,16 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
|
|
|
5971
6008
|
toolResult(id, result) {
|
|
5972
6009
|
this.tools.result(id, result);
|
|
5973
6010
|
}
|
|
6011
|
+
/**
|
|
6012
|
+
* When we last asked the run to stop. The result that follows within a minute is a stop, whatever it calls itself
|
|
6013
|
+
* (a stop asked for while nothing ran must not hide a later run's real error, hence the limit).
|
|
6014
|
+
*/
|
|
6015
|
+
stopRequestedAt = 0;
|
|
6016
|
+
stopJustRequested() {
|
|
6017
|
+
return this.stopRequestedAt > 0 && Date.now() - this.stopRequestedAt < 6e4;
|
|
6018
|
+
}
|
|
5974
6019
|
async interrupt() {
|
|
6020
|
+
this.stopRequestedAt = Date.now();
|
|
5975
6021
|
await this.query?.interrupt().catch(() => {
|
|
5976
6022
|
});
|
|
5977
6023
|
}
|
|
@@ -6368,7 +6414,7 @@ function installService(run3 = runSync) {
|
|
|
6368
6414
|
must("systemctl", ["--user", "daemon-reload"]);
|
|
6369
6415
|
must("systemctl", ["--user", "enable", "--now", names.unit]);
|
|
6370
6416
|
must("systemctl", ["--user", "restart", names.unit]);
|
|
6371
|
-
return { file: r.file, target, notes: [
|
|
6417
|
+
return { file: r.file, target, notes: [lingerNote(run3), `Logs: journalctl --user -u ${names.unit} -f`].filter((n) => !!n) };
|
|
6372
6418
|
}
|
|
6373
6419
|
must("powershell", ["-ExecutionPolicy", "Bypass", "-File", r.file]);
|
|
6374
6420
|
return { file: r.file, target: `Task Scheduler: ${names.task}`, notes: [`Check: Get-ScheduledTask -TaskName "${names.task}"`] };
|
|
@@ -6392,6 +6438,21 @@ function uninstallService(run3 = runSync) {
|
|
|
6392
6438
|
run3("powershell", ["-Command", `Unregister-ScheduledTask -TaskName "${names.task}" -Confirm:$false`]);
|
|
6393
6439
|
return `Task Scheduler: ${names.task}`;
|
|
6394
6440
|
}
|
|
6441
|
+
function lingerEnabled() {
|
|
6442
|
+
if (process.platform !== "linux") return null;
|
|
6443
|
+
const r = spawnSync("loginctl", ["show-user", os7.userInfo().username, "--property=Linger", "--value"], { encoding: "utf8" });
|
|
6444
|
+
if (r.status !== 0) return null;
|
|
6445
|
+
const v = String(r.stdout ?? "").trim();
|
|
6446
|
+
return v === "yes" ? true : v === "no" ? false : null;
|
|
6447
|
+
}
|
|
6448
|
+
var LINGER_FIX = "loginctl enable-linger $USER";
|
|
6449
|
+
function lingerNote(run3) {
|
|
6450
|
+
const on = lingerEnabled();
|
|
6451
|
+
if (on !== false) return null;
|
|
6452
|
+
const r = run3("loginctl", ["enable-linger", os7.userInfo().username]);
|
|
6453
|
+
if (r.status === 0 && lingerEnabled() === true) return "Set to keep running when you log out (linger is on for your user).";
|
|
6454
|
+
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)`;
|
|
6455
|
+
}
|
|
6395
6456
|
|
|
6396
6457
|
// src/cli.ts
|
|
6397
6458
|
import { spawn as spawn5 } from "node:child_process";
|
|
@@ -6402,9 +6463,16 @@ async function readTokenFromStdin() {
|
|
|
6402
6463
|
return data.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
6403
6464
|
}
|
|
6404
6465
|
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", () => {
|
|
6466
|
+
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
6467
|
const p = program.opts().profile;
|
|
6407
6468
|
if (p) process.env.MONOCLAW_PROFILE = assertProfileName(p);
|
|
6469
|
+
else if (!["enrol", "connect"].includes(action.name())) {
|
|
6470
|
+
const only2 = impliedProfile();
|
|
6471
|
+
if (only2) {
|
|
6472
|
+
process.env.MONOCLAW_PROFILE = only2;
|
|
6473
|
+
console.error(`(Using the profile "${only2}", this computer's only enrolment.)`);
|
|
6474
|
+
}
|
|
6475
|
+
}
|
|
6408
6476
|
});
|
|
6409
6477
|
var cmd = (rest) => `monoclaw ${currentProfile() ? `--profile ${currentProfile()} ` : ""}${rest}`;
|
|
6410
6478
|
async function confirm(question, fallback) {
|
|
@@ -6431,8 +6499,12 @@ program.command("enrol [token]").description("Connect this machine to your MonoC
|
|
|
6431
6499
|
const profiles = listProfiles();
|
|
6432
6500
|
const preview = await previewToken(opts.router, token, profiles.map((p) => p.config?.hostId ?? "").filter(Boolean), opts.insecure);
|
|
6433
6501
|
const plan = planEnrol(preview, profiles, opts.router, { requestedProfile: currentProfile(), defaultName: os8.hostname() });
|
|
6502
|
+
const report = (profile) => {
|
|
6503
|
+
if (process.env.MONOCLAW_CONNECT) fs22.writeFileSync(connectResultPath(), JSON.stringify({ profile, at: (/* @__PURE__ */ new Date()).toISOString() }), { mode: 384 });
|
|
6504
|
+
};
|
|
6434
6505
|
if (plan.action === "already") {
|
|
6435
6506
|
console.log(plan.message);
|
|
6507
|
+
report(plan.profile);
|
|
6436
6508
|
return;
|
|
6437
6509
|
}
|
|
6438
6510
|
if (plan.confirm) {
|
|
@@ -6467,6 +6539,7 @@ program.command("enrol [token]").description("Connect this machine to your MonoC
|
|
|
6467
6539
|
console.log(`This computer now runs one machine per space; its modules and Claude login are shared. The first enrolment is untouched.`);
|
|
6468
6540
|
}
|
|
6469
6541
|
if (!cfg.roots.length) console.log(`No folders exposed yet. Add one with: ${cmd("roots add ~/command")}`);
|
|
6542
|
+
report(currentProfile());
|
|
6470
6543
|
if (process.env.MONOCLAW_CONNECT) return;
|
|
6471
6544
|
console.log(`
|
|
6472
6545
|
Next, run it (one of):
|
|
@@ -6720,15 +6793,19 @@ program.command("doctor").description("Check and repair what a working host need
|
|
|
6720
6793
|
}
|
|
6721
6794
|
} 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
6795
|
const cfg = loadConfig();
|
|
6723
|
-
|
|
6796
|
+
const named = currentProfile() ? [] : listProfiles().filter((p) => p.profile && p.config);
|
|
6797
|
+
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` });
|
|
6798
|
+
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
6799
|
else {
|
|
6725
6800
|
lines.push({ ok: true, what: `Enrolled as "${cfg.name}" with ${cfg.routerUrl}` });
|
|
6726
6801
|
const missing = cfg.roots.filter((r) => !fs22.existsSync(r));
|
|
6727
6802
|
const exposing = cfg.roots.filter((r) => rootExposesConfig(r, configDir()));
|
|
6728
6803
|
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
6804
|
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
|
-
|
|
6805
|
+
const names = serviceNames();
|
|
6806
|
+
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;
|
|
6807
|
+
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` });
|
|
6808
|
+
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
6809
|
const { registry } = await makeContext(cfg);
|
|
6733
6810
|
await registry.refreshReadiness();
|
|
6734
6811
|
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.6",
|
|
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.6",
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.3.302",
|
|
@@ -614,9 +614,9 @@
|
|
|
614
614
|
}
|
|
615
615
|
},
|
|
616
616
|
"node_modules/express-rate-limit": {
|
|
617
|
-
"version": "8.7.
|
|
618
|
-
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.
|
|
619
|
-
"integrity": "sha512-
|
|
617
|
+
"version": "8.7.5",
|
|
618
|
+
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.5.tgz",
|
|
619
|
+
"integrity": "sha512-wi+v38cx2EqD0JnhE/e74o5tFqKWUOAPFJIgyEiqJ8v2MNpoOAA3kI2hXYOI+YM+HE5yqbdAlVxm2GqOIeYOgA==",
|
|
620
620
|
"license": "MIT",
|
|
621
621
|
"dependencies": {
|
|
622
622
|
"debug": "^4.4.3",
|
|
@@ -870,9 +870,9 @@
|
|
|
870
870
|
"license": "ISC"
|
|
871
871
|
},
|
|
872
872
|
"node_modules/jose": {
|
|
873
|
-
"version": "6.2.
|
|
874
|
-
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.
|
|
875
|
-
"integrity": "sha512-
|
|
873
|
+
"version": "6.2.18",
|
|
874
|
+
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.18.tgz",
|
|
875
|
+
"integrity": "sha512-doV4thUwgkrycJH4yLeqwTGIIZphHl+pk7CPReuMIhYhncmgzdko85MaCG4YQFTxqMFr1/oEH32tZuKKovcDEg==",
|
|
876
876
|
"license": "MIT",
|
|
877
877
|
"funding": {
|
|
878
878
|
"url": "https://github.com/sponsors/panva"
|
|
@@ -1007,9 +1007,9 @@
|
|
|
1007
1007
|
}
|
|
1008
1008
|
},
|
|
1009
1009
|
"node_modules/object-inspect": {
|
|
1010
|
-
"version": "1.
|
|
1011
|
-
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.
|
|
1012
|
-
"integrity": "sha512-
|
|
1010
|
+
"version": "1.14.0",
|
|
1011
|
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
|
|
1012
|
+
"integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
|
|
1013
1013
|
"license": "MIT",
|
|
1014
1014
|
"engines": {
|
|
1015
1015
|
"node": ">= 0.4"
|
package/package.json
CHANGED