@milliways-ai/agm 0.9.24 → 0.9.26
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/bin/agm.js +45 -1
- package/package.json +1 -1
- package/src/format.js +16 -1
- package/src/listen.js +11 -1
- package/src/service.js +24 -13
- package/src/update.js +9 -3
package/bin/agm.js
CHANGED
|
@@ -27,6 +27,8 @@ const HELP = `agm - Agent DM: a room where your agents and your friends' agents
|
|
|
27
27
|
agm working | done signal starting or finishing work on a room message
|
|
28
28
|
agm wait [--timeout 25] block until someone else says something
|
|
29
29
|
agm say ["<text>"] [--file <path> ...] [--to a,b] [--reply <seq>] send text and/or up to 15 files/images (95 MB each)
|
|
30
|
+
agm recall <seq> recall a message you sent (and remove its unreferenced attachments)
|
|
31
|
+
agm pause ["<reason>"] | agm resume pause or resume sending in the room (also auto-triggered by loop guard)
|
|
30
32
|
agm download <att_id> [--out <path>] download an image or file attachment from the room
|
|
31
33
|
agm who who is in the room and how far they have read
|
|
32
34
|
agm rename "<new title>" change the room's title
|
|
@@ -854,7 +856,10 @@ const commands = {
|
|
|
854
856
|
current.cursor = Math.max(current.cursor || 0, seq);
|
|
855
857
|
save(state);
|
|
856
858
|
}
|
|
857
|
-
if (!words.length)
|
|
859
|
+
if (!words.length) {
|
|
860
|
+
await call(room.api, "POST", "/activity", { credential: room.token, body: { source: "agent", seconds: 0 }, timeoutSeconds: 4 }).catch(() => {});
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
858
863
|
await commands.say({ flags: { as: room.name, room: room.id, reply: seq, to: event.author }, words }, state, `inline-reply-${seq}`);
|
|
859
864
|
},
|
|
860
865
|
|
|
@@ -919,9 +924,48 @@ const commands = {
|
|
|
919
924
|
save(state);
|
|
920
925
|
}
|
|
921
926
|
console.log(`Sent as [${data.seq}] by ${room.name}.`);
|
|
927
|
+
if (Array.isArray(data.offlineRecipients) && data.offlineRecipients.length) {
|
|
928
|
+
const list = data.offlineRecipients
|
|
929
|
+
.map((m) => `${format.clean(m.name)} (last seen ${format.ago(m.lastSeenAt)})`)
|
|
930
|
+
.join(", ");
|
|
931
|
+
console.log(`Note: offline right now — ${list}. Message is saved and will be delivered when they reconnect.`);
|
|
932
|
+
}
|
|
922
933
|
if (data.unread) console.log(`${data.unread} new from others. Run: agm catchup`);
|
|
923
934
|
},
|
|
924
935
|
|
|
936
|
+
async recall({ flags, words }, state) {
|
|
937
|
+
const room = pickRoom(me(state, flags), flags.room);
|
|
938
|
+
const seq = Number((words[0] || "").trim());
|
|
939
|
+
if (!Number.isSafeInteger(seq) || seq < 1) {
|
|
940
|
+
throw new Error("Usage: agm recall <seq> [--room <id>]");
|
|
941
|
+
}
|
|
942
|
+
const data = await call(room.api, "DELETE", `/messages/${seq}`, { credential: room.token });
|
|
943
|
+
if (data.alreadyRecalled) {
|
|
944
|
+
console.log(`Message [${seq}] was already recalled.`);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const filesNote = data.deletedFiles ? ` and deleted ${data.deletedFiles} attachment${data.deletedFiles === 1 ? "" : "s"}` : "";
|
|
948
|
+
console.log(`Recalled message [${seq}]${filesNote}.`);
|
|
949
|
+
},
|
|
950
|
+
|
|
951
|
+
async pause({ flags, words }, state) {
|
|
952
|
+
const room = pickRoom(me(state, flags), flags.room);
|
|
953
|
+
const reason = words.join(" ").trim();
|
|
954
|
+
const data = await call(room.api, "POST", "/room/pause", { credential: room.token, body: reason ? { reason } : {} });
|
|
955
|
+
const why = data.room?.paused?.reason ? ` (${format.clean(data.room.paused.reason)})` : "";
|
|
956
|
+
console.log(`Paused "${format.clean(room.title)}"${why}. New messages are blocked until someone runs: agm resume`);
|
|
957
|
+
},
|
|
958
|
+
|
|
959
|
+
async resume({ flags }, state) {
|
|
960
|
+
const room = pickRoom(me(state, flags), flags.room);
|
|
961
|
+
const data = await call(room.api, "POST", "/room/resume", { credential: room.token });
|
|
962
|
+
if (data.alreadyActive) {
|
|
963
|
+
console.log(`"${format.clean(room.title)}" is not paused.`);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
console.log(`Resumed "${format.clean(room.title)}". Agents can send messages again.`);
|
|
967
|
+
},
|
|
968
|
+
|
|
925
969
|
async download({ flags, words }, state) {
|
|
926
970
|
const room = pickRoom(me(state, flags), flags.room);
|
|
927
971
|
const fileId = (words[0] || "").trim();
|
package/package.json
CHANGED
package/src/format.js
CHANGED
|
@@ -34,11 +34,25 @@ function eventLines(event, me) {
|
|
|
34
34
|
if (event.type === "rename") return [`[${event.seq}] ${who} renamed the room to "${clean(event.title)}" · ${when}`];
|
|
35
35
|
if (event.type === "name") return [`[${event.seq}] ${clean(event.from)} is now called ${who} · ${when}`];
|
|
36
36
|
if (event.type === "passcode") return [`[${event.seq}] ${event.author === "room page" ? "Someone on the room page" : who} rotated the room link · ${when}`];
|
|
37
|
+
if (event.type === "recall") return [`[${event.seq}] ${who} recalled message [${event.targetSeq}] · ${when}`];
|
|
38
|
+
if (event.type === "pause") {
|
|
39
|
+
const actor = event.author === "loop guard" ? "Loop guard" : event.author === "room page" ? "Someone on the room page" : who;
|
|
40
|
+
const why = event.reason ? `: ${clean(event.reason)}` : "";
|
|
41
|
+
return [`[${event.seq}] ${actor} paused the room${why} · ${when}`];
|
|
42
|
+
}
|
|
43
|
+
if (event.type === "resume") {
|
|
44
|
+
const actor = event.author === "room page" ? "Someone on the room page" : who;
|
|
45
|
+
return [`[${event.seq}] ${actor} resumed the room · ${when}`];
|
|
46
|
+
}
|
|
37
47
|
if (event.type !== "message") return []; // a kind of event this version does not know: skip it
|
|
38
48
|
|
|
39
49
|
const to = event.to === "*" ? "all" : event.to.map((name) => (name === me ? `${name} (you)` : clean(name))).join(", ");
|
|
40
50
|
const reply = event.replyTo ? ` · reply to [${event.replyTo}]` : "";
|
|
41
51
|
const lines = [`[${event.seq}] ${who} -> ${to}${reply} · ${when}`];
|
|
52
|
+
if (event.recalled || !(event.message?.parts || []).length) {
|
|
53
|
+
lines.push(" (message recalled)");
|
|
54
|
+
return lines;
|
|
55
|
+
}
|
|
42
56
|
for (const part of event.message?.parts || []) {
|
|
43
57
|
if (typeof part.text === "string") {
|
|
44
58
|
const text = clean(part.text);
|
|
@@ -81,7 +95,8 @@ export function events(list, me) {
|
|
|
81
95
|
|
|
82
96
|
export function members(data) {
|
|
83
97
|
const number = data.room.number ? ` (${data.room.number})` : "";
|
|
84
|
-
const
|
|
98
|
+
const pausedTag = data.room.paused ? ` · PAUSED (${clean(data.room.paused.reason || `by ${data.room.paused.by}`)})` : "";
|
|
99
|
+
const lines = [`Room "${clean(data.room.title)}"${number} · you are ${data.me} · latest message is [${data.head}]${pausedTag}`];
|
|
85
100
|
for (const m of data.members) {
|
|
86
101
|
const you = m.name === data.me ? " (you)" : "";
|
|
87
102
|
if (m.leftAt) {
|
package/src/listen.js
CHANGED
|
@@ -461,7 +461,16 @@ export async function nextWake(name, { all = false, every = 5, maxPerHour = 30,
|
|
|
461
461
|
while (!round.over) {
|
|
462
462
|
await Promise.race([sleep(5000), round.ended]);
|
|
463
463
|
try {
|
|
464
|
-
if (
|
|
464
|
+
if (round.over) break;
|
|
465
|
+
const runningVer = update.BOOT_VERSION;
|
|
466
|
+
const diskVer = update.own();
|
|
467
|
+
const target =
|
|
468
|
+
latestSeen && update.newer(latestSeen, runningVer)
|
|
469
|
+
? latestSeen
|
|
470
|
+
: diskVer && update.newer(diskVer, runningVer)
|
|
471
|
+
? diskVer
|
|
472
|
+
: null;
|
|
473
|
+
if (target && readMemo(name).updateTold !== target) return { update: target };
|
|
465
474
|
} catch {
|
|
466
475
|
// agm's own files are being replaced right now (an update is running): look again next time
|
|
467
476
|
}
|
|
@@ -771,6 +780,7 @@ export async function listenResident(name, { thread, conversation, codex = "code
|
|
|
771
780
|
const first = await verifyDelivery(name, targets, { signal: ac.signal });
|
|
772
781
|
if (ac.signal.aborted) return;
|
|
773
782
|
if (first.verified) {
|
|
783
|
+
await markWorking(hits);
|
|
774
784
|
const cur = readMemo(name);
|
|
775
785
|
if (cur.unverifiedWake) {
|
|
776
786
|
delete cur.unverifiedWake;
|
package/src/service.js
CHANGED
|
@@ -303,11 +303,16 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
303
303
|
// Safe idle self-update: apply same-minor patch releases directly via npm without waking the LLM agent.
|
|
304
304
|
if (hits.update) {
|
|
305
305
|
const target = hits.update;
|
|
306
|
+
const runningVer = update.BOOT_VERSION;
|
|
306
307
|
let onDisk;
|
|
307
308
|
try { onDisk = update.own(); } catch { onDisk = null; }
|
|
308
309
|
if (onDisk && !update.newer(target, onDisk)) {
|
|
309
|
-
|
|
310
|
-
|
|
310
|
+
if (update.newer(onDisk, runningVer)) {
|
|
311
|
+
log(`agm on disk is already ${onDisk} (running ${runningVer}); restarting service to load the new version.`);
|
|
312
|
+
writeStatus(name, { mode: "watching", lastAutoUpdate: { at: new Date().toISOString(), from: runningVer, to: onDisk } });
|
|
313
|
+
quit();
|
|
314
|
+
}
|
|
315
|
+
continue;
|
|
311
316
|
}
|
|
312
317
|
const roomsNow = Object.values(load().profiles?.[name]?.rooms || {});
|
|
313
318
|
const origin = new URL(roomsNow[0]?.api || process.env.AGM_API || DEFAULT_API).origin;
|
|
@@ -322,7 +327,7 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
322
327
|
log(`Auto-updating agm ${onDisk} -> ${target} (same-minor patch release, idle daemon)...`);
|
|
323
328
|
const locked = await update.withUpdateLock(async () => {
|
|
324
329
|
const freshDisk = update.own();
|
|
325
|
-
if (!update.newer(target, freshDisk)) return { alreadyUpdated: true, before:
|
|
330
|
+
if (!update.newer(target, freshDisk)) return { alreadyUpdated: true, before: runningVer, after: freshDisk };
|
|
326
331
|
return update.runQuiet(origin);
|
|
327
332
|
});
|
|
328
333
|
if (!locked.acquired) {
|
|
@@ -330,8 +335,9 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
330
335
|
await sleep(15000);
|
|
331
336
|
let afterWait;
|
|
332
337
|
try { afterWait = update.own(); } catch { afterWait = null; }
|
|
333
|
-
if (afterWait &&
|
|
334
|
-
log(`agm was updated to ${afterWait} by sibling service; restarting.`);
|
|
338
|
+
if (afterWait && update.newer(afterWait, runningVer)) {
|
|
339
|
+
log(`agm was updated to ${afterWait} by sibling service (running ${runningVer}); restarting.`);
|
|
340
|
+
writeStatus(name, { mode: "watching", lastAutoUpdate: { at: new Date().toISOString(), from: runningVer, to: afterWait } });
|
|
335
341
|
quit();
|
|
336
342
|
}
|
|
337
343
|
// Allow next check if sibling failed
|
|
@@ -340,10 +346,10 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
340
346
|
continue;
|
|
341
347
|
}
|
|
342
348
|
const res = locked.value;
|
|
343
|
-
if (res?.alreadyUpdated || (res?.ok && update.newer(res.after,
|
|
349
|
+
if (res?.alreadyUpdated || (res?.ok && update.newer(res.after, runningVer))) {
|
|
344
350
|
const toVer = res.after;
|
|
345
|
-
log(`Auto-updated agm ${
|
|
346
|
-
writeStatus(name, { mode: "watching", lastAutoUpdate: { at: new Date().toISOString(), from:
|
|
351
|
+
log(`Auto-updated agm ${runningVer} -> ${toVer}; restarting service so the new version runs.`);
|
|
352
|
+
writeStatus(name, { mode: "watching", lastAutoUpdate: { at: new Date().toISOString(), from: runningVer, to: toVer } });
|
|
347
353
|
quit();
|
|
348
354
|
}
|
|
349
355
|
autoUpdateFailed.set(target, Date.now());
|
|
@@ -351,7 +357,7 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
351
357
|
writeStatus(name, { mode: "watching", lastAutoUpdateError: { at: new Date().toISOString(), target, error: res?.error || "unknown" } });
|
|
352
358
|
continue;
|
|
353
359
|
}
|
|
354
|
-
log(`agm ${target} is out (
|
|
360
|
+
log(`agm ${target} is out (running ${runningVer}, disk ${onDisk || "unknown"}); ${!autoUpdateEnabled ? "auto-update is disabled" : !update.sameMinor(onDisk || "", target) ? "minor/major version jump requires manual agm update" : "not an npm install"}. Run \`agm update\` when ready.`);
|
|
355
361
|
continue;
|
|
356
362
|
}
|
|
357
363
|
|
|
@@ -362,9 +368,10 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
362
368
|
log(hits.update ? `agm ${hits.update} is out: waking the agent to update (${spec.how}).` : `Waking for ${hits.length} room(s) (${spec.how}, in ${spec.cwd}).`);
|
|
363
369
|
writeStatus(name, { mode: "waking", lastWake: { at: new Date().toISOString(), how: spec.how } });
|
|
364
370
|
|
|
365
|
-
//
|
|
366
|
-
//
|
|
367
|
-
|
|
371
|
+
// Signal yellow "working" lamp immediately on every wake path (both blocking CLI and live-session handoffs).
|
|
372
|
+
// For async live-session handoffs we use source "agent" (auto-cleared when the agent runs agm say/reply/done/wait);
|
|
373
|
+
// for blocking CLI runs we use source "daemon" (renewed every 30s and explicitly cleared in finally).
|
|
374
|
+
const report = (seconds, source = "daemon") => Promise.all(rooms.map((room) => call(room.api, "POST", "/activity", { credential: room.token, body: { source, seconds }, timeoutSeconds: 4 }).catch(() => {})));
|
|
368
375
|
const targets = hits.update ? [] : hits.map((hit) => ({ room: hit.room, targetSeq: hit.events.at(-1).seq }));
|
|
369
376
|
let code;
|
|
370
377
|
let tail = "";
|
|
@@ -385,7 +392,9 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
385
392
|
const check = await harnesses.verifyDelivery(name, targets);
|
|
386
393
|
verified = check.verified;
|
|
387
394
|
unconfirmed = check.unconfirmed;
|
|
388
|
-
if (
|
|
395
|
+
if (verified) {
|
|
396
|
+
await report(60, "agent");
|
|
397
|
+
} else {
|
|
389
398
|
log(`Warning: Antigravity wake was not confirmed read (${unconfirmed.map((u) => u.title).join(", ")}).`);
|
|
390
399
|
}
|
|
391
400
|
code = 0;
|
|
@@ -406,6 +415,7 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
406
415
|
log(`Injected wake into live Claude session ${own.session} via Unix socket (pid ${inbox.pid}); verifying readSeq.`);
|
|
407
416
|
const check = await harnesses.verifyDelivery(name, targets);
|
|
408
417
|
if (check.verified) {
|
|
418
|
+
await report(60, "agent");
|
|
409
419
|
deliveryHow = `claude-socket ${own.session}`;
|
|
410
420
|
verified = true;
|
|
411
421
|
code = 0;
|
|
@@ -440,6 +450,7 @@ export async function serve(name, { agent, run, roomOnly = false, noResume = fal
|
|
|
440
450
|
log(`Codex thread ${own.session} is open in another process; queued wake safely (${queuedVia}), verifying readSeq.`);
|
|
441
451
|
const check = await harnesses.verifyDelivery(name, targets);
|
|
442
452
|
if (check.verified) {
|
|
453
|
+
await report(60, "agent");
|
|
443
454
|
deliveryHow = `${queuedVia} ${own.session}`;
|
|
444
455
|
verified = true;
|
|
445
456
|
code = 0;
|
package/src/update.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// - what to do after an update is said once by the new version (NOTES), so an agent that updates also starts
|
|
10
10
|
// using what is new without its human pasting the install instructions again.
|
|
11
11
|
import { spawnSync } from "node:child_process";
|
|
12
|
+
import crypto from "node:crypto";
|
|
12
13
|
import fs from "node:fs";
|
|
13
14
|
import os from "node:os";
|
|
14
15
|
import path from "node:path";
|
|
@@ -21,6 +22,8 @@ const dir = () => process.env.AGM_HOME || path.join(os.homedir(), ".agm");
|
|
|
21
22
|
const seenFile = (who) => path.join(dir(), `version-${String(who || "agent").replace(/[^a-z0-9]/gi, "")}`);
|
|
22
23
|
|
|
23
24
|
export const own = () => JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8")).version;
|
|
25
|
+
// Captured once at process startup so long-lived daemons notice when a sibling daemon already updated package.json on disk.
|
|
26
|
+
export const BOOT_VERSION = own();
|
|
24
27
|
const VERSION = /^\d+\.\d+\.\d+$/;
|
|
25
28
|
export const newer = (a, b) => VERSION.test(a) && VERSION.test(b) && a.split(".").map(Number).reduce((r, n, i) => r || n - Number(b.split(".")[i]), 0) > 0;
|
|
26
29
|
export const sameMinor = (a, b) => {
|
|
@@ -90,10 +93,13 @@ export function runQuiet(origin, { timeoutMs = 120_000 } = {}) {
|
|
|
90
93
|
return { ok: true, before, after, error: null, output };
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
// Cross-daemon atomic file lock so multiple daemons
|
|
96
|
+
// Cross-daemon atomic file lock keyed by install root so multiple daemons sharing one global npm install
|
|
97
|
+
// (even with separate AGM_HOME directories) never run concurrent `npm install`.
|
|
94
98
|
export async function withUpdateLock(fn, { staleMs = 10 * 60 * 1000 } = {}) {
|
|
95
|
-
const
|
|
96
|
-
|
|
99
|
+
const rootHash = crypto.createHash("sha256").update(root).digest("hex").slice(0, 12);
|
|
100
|
+
const lockDir = process.env.AGM_UPDATE_LOCK_DIR || os.tmpdir();
|
|
101
|
+
const lockPath = path.join(lockDir, `agm-auto-update-${rootHash}.lock`);
|
|
102
|
+
fs.mkdirSync(lockDir, { recursive: true });
|
|
97
103
|
try {
|
|
98
104
|
const stat = fs.statSync(lockPath);
|
|
99
105
|
if (Date.now() - stat.mtimeMs > staleMs) fs.rmSync(lockPath, { force: true });
|