@gorlitzer-labs/seldon 0.14.0 โ 0.15.0
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 +6 -0
- package/bin/seldon.js +68 -12
- package/lib/telegram.mjs +45 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,6 +191,12 @@ your chat and keeps its id in `~/.seldon/telegram.json`). Stored it under anothe
|
|
|
191
191
|
- **The token never shows.** seldon does not store it: without it in the environment,
|
|
192
192
|
`seldon tell` re-runs itself under `comb run --with TELEGRAM_BOT_TOKEN`, so an agent can send
|
|
193
193
|
without ever seeing it. Every machine with comb synced can send.
|
|
194
|
+
- **Your phone โ this machine: `seldon inbox`.** Send the bot a screenshot, video, file, voice
|
|
195
|
+
note or a line of text and it lands in `~/Downloads/seldon-inbox/` (`--dir` for another),
|
|
196
|
+
with a ๐ on your message once it is saved and one line per item in `notes.md`. Plain code,
|
|
197
|
+
no agent in between, no tokens; only your chat is listened to. A bot can fetch up to 20 MB,
|
|
198
|
+
and Telegram compresses photos โ *Send as File* for the original. Telegram itself still
|
|
199
|
+
carries everything (a bot chat is not end-to-end encrypted).
|
|
194
200
|
- **Sending only.** Any number of sessions can send through one bot. Writing *to* an agent from
|
|
195
201
|
Telegram (text, or a screenshot from your phone) is Claude Code's own Telegram channel
|
|
196
202
|
(`claude --channels plugin:telegram@claude-plugins-official`), and the same bot works for
|
package/bin/seldon.js
CHANGED
|
@@ -14,7 +14,7 @@ import { startLane, stopLane, resumeLane, removeLane, findLane } from "../lib/ac
|
|
|
14
14
|
import { listMachines, addMachine, fetchLanes, remoteGroups, sshArgs, lastJsonLine } from "../lib/machines.mjs";
|
|
15
15
|
import { notify } from "../lib/notify.mjs";
|
|
16
16
|
import { serve, serveToken, ownerFromStatus } from "../lib/serve.mjs";
|
|
17
|
-
import { tokenName, readChat, writeChat, chatFromUpdates, getUpdates, sendText, sendFile } from "../lib/telegram.mjs";
|
|
17
|
+
import { tokenName, readChat, writeChat, chatFromUpdates, getUpdates, sendText, sendFile, pollUpdates, fileFromMessage, inboxName, noteLine, downloadFile, react, MAX_DOWNLOAD } from "../lib/telegram.mjs";
|
|
18
18
|
import { reportFromEvent, mergeCodexHooks, removeCodexHooks, opencodePlugin } from "../lib/reports.mjs";
|
|
19
19
|
import { buildRows, headline, ago, laneDetail, unlistedAgents, GLYPH } from "../lib/home.mjs";
|
|
20
20
|
import { parseDuration, describe as describeHold, NAME_RE, DEFAULT_FOR_MS } from "../lib/holds.mjs";
|
|
@@ -1435,6 +1435,7 @@ ${C.bold("seldon")} โ the agent factory: your projects, and the stack that run
|
|
|
1435
1435
|
${C.bold("seldon up --tailnet")} expose the voice over HTTPS (tailscale serve) so the mic works on your phone
|
|
1436
1436
|
${C.bold("seldon serve")} [--tailnet] the panel as a phone web app (--allow-reply to answer agents)
|
|
1437
1437
|
${C.bold("seldon tell")} "โฆ" message yourself on Telegram (--file to send one; --setup once)
|
|
1438
|
+
${C.bold("seldon inbox")} [--dir d] save what you send the bot to a folder here (no agent, no tokens)
|
|
1438
1439
|
${C.bold("seldon up --brain=X")} pick the voice brain: qwen (in-process) | bonsai (local server); remembered
|
|
1439
1440
|
${C.bold("seldon status")} what's running ยท ${C.bold("seldon down")} stop it
|
|
1440
1441
|
${C.bold("seldon adopt")} [dir] put an existing repo on the line: foundation docs (never overwritten),
|
|
@@ -1569,19 +1570,26 @@ function serveCmd(flags) {
|
|
|
1569
1570
|
// `seldon tell "โฆ"` โ message the operator on Telegram, from any agent. The token comes from
|
|
1570
1571
|
// comb in the environment: without it, seldon re-runs itself under `comb run`, so the value
|
|
1571
1572
|
// is never in an argument, a file seldon writes, or the agent's transcript.
|
|
1572
|
-
|
|
1573
|
-
|
|
1573
|
+
// The bot token, from the environment. Without it, re-run this same command under
|
|
1574
|
+
// `comb run` (which puts it there) and return null: the child does the work.
|
|
1575
|
+
function telegramToken(flags) {
|
|
1576
|
+
const fail = (msg) => { console.error(C.red(msg)); process.exitCode = 1; return null; };
|
|
1574
1577
|
const name = typeof flags["token-name"] === "string" ? flags["token-name"] : tokenName();
|
|
1575
1578
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) return fail(`not a secret name: ${name}`);
|
|
1576
|
-
|
|
1577
|
-
if (
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1579
|
+
if (process.env[name]) return { token: process.env[name], name };
|
|
1580
|
+
if (process.env.SELDON_TELL_VIA_COMB) return fail(`comb has no ${name} โ store it once: comb set ${name}`);
|
|
1581
|
+
if (!has("comb")) return fail(`no ${name} in the environment, and comb is not installed (seldon install comb)`);
|
|
1582
|
+
const r = spawnSync("comb", ["run", "--with", name, "--", process.execPath, process.argv[1], ...process.argv.slice(2)],
|
|
1583
|
+
{ stdio: "inherit", env: { ...process.env, SELDON_TELL_VIA_COMB: "1" } });
|
|
1584
|
+
process.exitCode = r.status ?? 1;
|
|
1585
|
+
return null;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
async function tellCmd(words, flags) {
|
|
1589
|
+
const fail = (msg) => { console.error(C.red(msg)); process.exitCode = 1; };
|
|
1590
|
+
const t = telegramToken(flags);
|
|
1591
|
+
if (!t) return;
|
|
1592
|
+
const { token, name } = t;
|
|
1585
1593
|
try {
|
|
1586
1594
|
if (flags.setup) {
|
|
1587
1595
|
const chat = chatFromUpdates(await getUpdates(token));
|
|
@@ -1601,6 +1609,53 @@ async function tellCmd(words, flags) {
|
|
|
1601
1609
|
} catch (e) { fail(e.message); }
|
|
1602
1610
|
}
|
|
1603
1611
|
|
|
1612
|
+
// `seldon inbox` โ what you send the bot from your phone lands in a folder here: photos,
|
|
1613
|
+
// videos, files, voice notes, and text into notes.md. Plain code, no agent in between, no
|
|
1614
|
+
// tokens. Only your chat (from `seldon tell --setup`) is listened to; anyone else is ignored.
|
|
1615
|
+
async function inboxCmd(flags) {
|
|
1616
|
+
const fail = (msg) => { console.error(C.red(msg)); process.exitCode = 1; };
|
|
1617
|
+
const chat = readChat();
|
|
1618
|
+
if (!chat) return fail("not set up yet โ send your bot /start in Telegram, then: seldon tell --setup");
|
|
1619
|
+
const t = telegramToken(flags);
|
|
1620
|
+
if (!t) return;
|
|
1621
|
+
const dir = path.resolve(typeof flags.dir === "string" ? flags.dir : path.join(process.env.HOME, "Downloads", "seldon-inbox"));
|
|
1622
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1623
|
+
const stamp = () => new Date().toTimeString().slice(0, 8);
|
|
1624
|
+
console.log(`${stamp()} seldon inbox โ ${dir}`);
|
|
1625
|
+
let offset;
|
|
1626
|
+
for (;;) {
|
|
1627
|
+
let updates;
|
|
1628
|
+
try { updates = (await pollUpdates(t.token, offset)).result; }
|
|
1629
|
+
catch (e) {
|
|
1630
|
+
console.log(`${stamp()} ${e.message}`);
|
|
1631
|
+
if (/terminated by other getUpdates/i.test(e.message)) return fail("another reader has this bot (a second inbox, or Claude's Telegram channel) โ stop it first");
|
|
1632
|
+
await new Promise((r) => setTimeout(r, 5000)); continue;
|
|
1633
|
+
}
|
|
1634
|
+
for (const u of updates) {
|
|
1635
|
+
offset = u.update_id + 1;
|
|
1636
|
+
const m = u.message;
|
|
1637
|
+
if (!m || m.chat?.id !== chat.id) continue;
|
|
1638
|
+
const when = m.date * 1000, f = fileFromMessage(m), text = m.caption || m.text || "";
|
|
1639
|
+
try {
|
|
1640
|
+
if (f) {
|
|
1641
|
+
if (f.size && f.size > MAX_DOWNLOAD) throw new Error(`${f.name} is over 20 MB โ a bot can't fetch it; share it another way`);
|
|
1642
|
+
const name = inboxName(f.name, when);
|
|
1643
|
+
await downloadFile(t.token, f.fileId, path.join(dir, name));
|
|
1644
|
+
fs.appendFileSync(path.join(dir, "notes.md"), noteLine(when, { file: name, text }), { mode: 0o600 });
|
|
1645
|
+
console.log(`${stamp()} saved ${name}`);
|
|
1646
|
+
} else if (text && !text.startsWith("/")) {
|
|
1647
|
+
fs.appendFileSync(path.join(dir, "notes.md"), noteLine(when, { text }), { mode: 0o600 });
|
|
1648
|
+
console.log(`${stamp()} noted`);
|
|
1649
|
+
} else continue;
|
|
1650
|
+
await react(t.token, chat.id, m.message_id, "๐");
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
console.log(`${stamp()} ${e.message}`);
|
|
1653
|
+
await sendText(t.token, chat.id, `โ not saved: ${e.message}`).catch(() => {});
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1604
1659
|
// `seldon machines` โ the other computers the panel shows (bifrost's realms, one list).
|
|
1605
1660
|
function machinesCmd(verb, name, target) {
|
|
1606
1661
|
if (verb === "add") {
|
|
@@ -1783,6 +1838,7 @@ const ids = tokens.filter((id) => byId[id]); // only the valid module
|
|
|
1783
1838
|
if (cmd === "lane") return laneCmd(tokens[0], tokens[1], flags);
|
|
1784
1839
|
if (cmd === "serve") return serveCmd(flags);
|
|
1785
1840
|
if (cmd === "tell") return tellCmd(tokens, flags);
|
|
1841
|
+
if (cmd === "inbox") return inboxCmd(flags);
|
|
1786
1842
|
if (cmd === "setup") return setupCmd(tokens[0], flags);
|
|
1787
1843
|
if (cmd === "panel" || cmd === "board") return panel();
|
|
1788
1844
|
if (cmd && cmd !== "install") { help(); process.exitCode = 1; return; }
|
package/lib/telegram.mjs
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
// chat id is not a secret (it is useless without the token), so `seldon tell --setup` finds it
|
|
6
6
|
// once and keeps it in ~/.seldon/telegram.json.
|
|
7
7
|
//
|
|
8
|
-
// Sending
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// Sending is open to any number of sessions at once. Reading a bot's messages is one reader
|
|
9
|
+
// only: `seldon inbox` (what you send the bot lands in a folder on this machine โ no agent in
|
|
10
|
+
// between), or Claude Code's own Telegram channel, never both. --setup reads once.
|
|
11
11
|
import { readFileSync, writeFileSync, mkdirSync, statSync } from "node:fs";
|
|
12
12
|
import { join, basename } from "node:path";
|
|
13
13
|
import { SELDON_HOME } from "./agents.mjs";
|
|
@@ -60,6 +60,10 @@ async function call(token, method, body) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export const getUpdates = (token) => call(token, "getUpdates", { allowed_updates: ["message"] });
|
|
63
|
+
// Long polling: Telegram holds the request until something arrives (or `timeout` seconds pass).
|
|
64
|
+
// Asking with `offset` = last update_id + 1 also tells Telegram the earlier ones are handled.
|
|
65
|
+
export const pollUpdates = (token, offset, timeout = 50) =>
|
|
66
|
+
call(token, "getUpdates", { offset, timeout, allowed_updates: ["message"] });
|
|
63
67
|
|
|
64
68
|
export async function sendText(token, chatId, text) {
|
|
65
69
|
for (const part of chunks(text)) await call(token, "sendMessage", { chat_id: chatId, text: part, disable_web_page_preview: true });
|
|
@@ -87,3 +91,41 @@ export async function sendFile(token, chatId, path, caption = "") {
|
|
|
87
91
|
form.set(field, new Blob([readFileSync(path)]), basename(path));
|
|
88
92
|
await call(token, method, form);
|
|
89
93
|
}
|
|
94
|
+
|
|
95
|
+
// ---- the inbox: what you send the bot, saved on this machine ------------------------
|
|
96
|
+
export const MAX_DOWNLOAD = 20 * 1024 * 1024; // a bot may download up to 20 MB
|
|
97
|
+
|
|
98
|
+
// The one file in a message, if it carries one. A photo comes in several sizes: the largest.
|
|
99
|
+
export function fileFromMessage(m) {
|
|
100
|
+
if (!m) return null;
|
|
101
|
+
const pick = (f, fallback) => f && { fileId: f.file_id, size: f.file_size ?? null, name: f.file_name || fallback };
|
|
102
|
+
if (m.photo?.length) return pick(m.photo.at(-1), "photo.jpg");
|
|
103
|
+
return pick(m.document, "file") || pick(m.video, "video.mp4") || pick(m.animation, "animation.mp4")
|
|
104
|
+
|| pick(m.audio, "audio.mp3") || pick(m.voice, "voice.ogg") || pick(m.video_note, "video-note.mp4") || null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// A name that is safe on disk and sorts by time: 20261031-091502-screenshot.png
|
|
108
|
+
export function inboxName(name, date) {
|
|
109
|
+
const base = String(name).split(/[\\/]/).pop().replace(/[^\w.-]+/g, "_").replace(/^\.+/, "").slice(-120) || "file";
|
|
110
|
+
const d = new Date(date), p = (n) => String(n).padStart(2, "0");
|
|
111
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-${base}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// One line in notes.md per thing received, so the folder reads as a log.
|
|
115
|
+
export function noteLine(date, { file, text }) {
|
|
116
|
+
const d = new Date(date), p = (n) => String(n).padStart(2, "0");
|
|
117
|
+
const when = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
|
118
|
+
const body = String(text || "").replace(/\s*\n\s*/g, " โ ").trim();
|
|
119
|
+
return `- ${when} ยท ${file ? `[${file}](${encodeURI(file)})${body ? ` โ ${body}` : ""}` : body}\n`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function downloadFile(token, fileId, dest) {
|
|
123
|
+
const { result } = await call(token, "getFile", { file_id: fileId });
|
|
124
|
+
const r = await fetch(`https://api.telegram.org/file/bot${token}/${result.file_path}`);
|
|
125
|
+
if (!r.ok) throw new Error(`telegram download: ${r.status}`);
|
|
126
|
+
writeFileSync(dest, Buffer.from(await r.arrayBuffer()), { mode: 0o600 });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// A reaction on your message says it is saved, without a reply cluttering the chat.
|
|
130
|
+
export const react = (token, chatId, messageId, emoji) =>
|
|
131
|
+
call(token, "setMessageReaction", { chat_id: chatId, message_id: messageId, reaction: [{ type: "emoji", emoji }] }).catch(() => {});
|