shadok-ai 0.20.55 → 0.20.58

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 CHANGED
@@ -1098,6 +1098,59 @@ from the phone's *Linked devices* list too.
1098
1098
  reconnects. The same happens when a stored session finds no library at boot,
1099
1099
  because nothing is ever installed without an admin's click.
1100
1100
 
1101
+ ### Web widget (optional): a chat box on your site, one agent per visitor
1102
+
1103
+ A website adds one script tag; a chat box appears; a visitor who writes in it
1104
+ gets an agent of their own in an **External** group of this instance — the
1105
+ WhatsApp door's idea, for the plain web. Customer support on a public site, or
1106
+ an assistant inside a product.
1107
+
1108
+ **Set it up** from the External group's settings (the gear beside the group):
1109
+ *Add a web widget*, pick the profile visitors' agents run on, list the sites
1110
+ allowed to show the box, switch it on, and paste the snippet on the site:
1111
+
1112
+ ```html
1113
+ <script async src="https://your-cockpit.example/widget.js?id=wg_…"></script>
1114
+ ```
1115
+
1116
+ An instance holds as many widgets as you create. Several may open into one
1117
+ group, and then share its ceiling.
1118
+
1119
+ **Who a visitor is.** Anonymous, and recognised by their browser: the
1120
+ conversation continues on that browser and that site, nowhere else. The site
1121
+ may pass a little context before the box opens —
1122
+
1123
+ ```js
1124
+ window.shadokWidget = { context: { email: "ada@example.org", name: "Ada", plan: "team" } };
1125
+ ```
1126
+
1127
+ — which is handed to the agent as what the site **claims**, never as an
1128
+ identity: a value in a page's JavaScript proves nothing.
1129
+
1130
+ **What it costs, and its limits.** Nothing is created until the visitor sends
1131
+ a first message; then their conversation gets its own system account, like any
1132
+ conversation of an External group. Each widget has a ceiling — conversations
1133
+ held at once (200), new ones per hour (30), new ones per hour from one address
1134
+ (3) — and a refused visitor is told to come back later. Listing a site stops
1135
+ other sites from showing the box; it does not stop a program from writing to
1136
+ it, which is what the ceiling is for. There is no captcha: a program that
1137
+ changes address can fill an hour's allowance.
1138
+
1139
+ **What a visitor sees and can do.** The agent's answers, and a question the
1140
+ agent asks on purpose (as buttons). Never a tool call, never what a member
1141
+ types to the agent from the cockpit, and never a permission prompt — those are
1142
+ declined for them. A message that starts with a command name reaches the agent
1143
+ as text. No attachments yet.
1144
+
1145
+ **What the box cannot reach.** It is served by the cockpit's own host, so its
1146
+ page is sandboxed into an origin of its own: no cockpit cookie, no cockpit
1147
+ storage, and a socket that is not the cockpit's. The visitor's token is kept
1148
+ by the site's page — so a script running on that site can read that visitor's
1149
+ conversation, the same trust the site already has over what they type there.
1150
+
1151
+ Needs the multi-tenant deployment (External groups do), and HTTPS on the sites
1152
+ that embed it.
1153
+
1101
1154
  ### Running in Docker
1102
1155
 
1103
1156
  > Putting one instance online for someone else, on its own machine, behind a
@@ -20,7 +20,7 @@ and automatically starts the shadok-ai server when it is not running (port
20
20
 
21
21
  | Command | Effect |
22
22
  |---|---|
23
- | `spawn [--cwd DIR] [--worktree] [--profile NAME] [--name LABEL] [--resume ID] [--continue]` | creates an agent → `{sessionId, cwd, branch}`. Skill Factory skills are not passed here: the agent runs every factory skill shared with its group (or with everyone, or private to its creator), at the latest release accepted for that group. `--worktree` isolates the agent in a git worktree (`~/.shadok-ai/worktrees/`, branch `shadok-ai/<tag>`). `--profile` gives it a role + its guardrails + its secrets (see below). `--name` sets the agent's tab name in the cockpit (spawn only; a later rename in the UI is kept) — without it the name is derived from the profile/directory, so several agents look alike |
23
+ | `spawn [--cwd DIR] [--worktree] [--profile NAME] [--name LABEL] [--group ID] [--resume ID] [--continue]` | creates an agent → `{sessionId, cwd, branch}`. `--group` names the group (by id) it is born in, honoured only if you can see that group — else it lands in your own; `list` shows each agent's `group`/`groupName`. In an **external** group the agent gets a conversation of its own: its own Unix user and folder, the group's door secrets, and the same box as a guest (it sees nothing else of that group), no worktree. Skill Factory skills are not passed here: the agent runs every factory skill shared with its group (or with everyone, or private to its creator), at the latest release accepted for that group. `--worktree` isolates the agent in a git worktree (`~/.shadok-ai/worktrees/`, branch `shadok-ai/<tag>`). `--profile` gives it a role + its guardrails + its secrets (see below). `--name` sets the agent's tab name in the cockpit (spawn only; a later rename in the UI is kept) — without it the name is derived from the profile/directory, so several agents look alike |
24
24
  | `prompt <id> "text" [--timeout s]` | sends a prompt, waits for the end of the turn → `{status:"answer", text, tools}` or `{status:"dialog", question, options, multi}` or `{status:"timeout", screen}` or `{status:"pace-blocked", reason}` |
25
25
  | `dialog <id>` | queries the state → `{status:"idle"}` or the pending dialog |
26
26
  | `choose <id> <n>` | single-select dialog: picks and commits option n |
@@ -152,7 +152,7 @@ export function parseArgs(argv) {
152
152
  if (a === "--worktree" || a === "--continue" || a === "--readonly" || a === "--force" || a === "--dry-run") flags[a.slice(2)] = true;
153
153
  else if (
154
154
  a === "--cwd" || a === "--resume" || a === "--timeout" || a === "--profile" || a === "--parent" ||
155
- a === "--name" || a === "--peer" || a === "--peer-url" || a === "--peer-token" || a === "--idle"
155
+ a === "--name" || a === "--peer" || a === "--peer-url" || a === "--peer-token" || a === "--idle" || a === "--group"
156
156
  ) flags[a.slice(2)] = rest[++i];
157
157
  // Repeatable: a Skill Factory skill the new agent is born with, `name` or `name@N`.
158
158
  else if (a === "--skill") (flags.skill ||= []).push(rest[++i]);
@@ -384,6 +384,11 @@ export function buildStartMsg(flags, env = process.env) {
384
384
  // later resume never overwrites a rename made in the cockpit. Omitted → the
385
385
  // cockpit derives a default from the profile/directory.
386
386
  if (flags.name) startMsg.name = flags.name;
387
+ // The group (its id) to be born in. The server honours it only when the
388
+ // caller can see that group, and otherwise files the agent in the caller's
389
+ // own — `list` says where each agent landed. In an EXTERNAL group the agent
390
+ // gets a conversation of its own, walled off like a guest's.
391
+ if (flags.group) startMsg.group = flags.group;
387
392
  // A factory skill is not given to an agent: every agent its sharing covers
388
393
  // runs it. The flag is still parsed so an old command line does not fail.
389
394
  if (flags.skill?.length)
@@ -0,0 +1,252 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="robots" content="noindex">
7
+ <title>Chat</title>
8
+ <style nonce="__CSP_NONCE__">
9
+ :root { --accent: #2b6cb0; --ink: #1a202c; --soft: #f1f3f5; --line: #dfe3e8; --mute: #6b7280; }
10
+ * { box-sizing: border-box; }
11
+ html, body { height: 100%; margin: 0; }
12
+ body { display: flex; flex-direction: column; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: #fff; }
13
+ header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; background: var(--accent); color: #fff; font-weight: 600; }
14
+ header span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
15
+ header button { border: 0; background: transparent; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
16
+ #log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
17
+ .msg { max-width: 86%; padding: 8px 12px; border-radius: 14px; overflow-wrap: anywhere; }
18
+ .msg.me { align-self: flex-end; background: var(--accent); color: #fff; white-space: pre-wrap; border-bottom-right-radius: 4px; }
19
+ .msg.them { align-self: flex-start; background: var(--soft); border-bottom-left-radius: 4px; }
20
+ .msg.them > :first-child { margin-top: 0; }
21
+ .msg.them > :last-child { margin-bottom: 0; }
22
+ .msg.them pre { overflow-x: auto; background: #e6e9ed; padding: 8px; border-radius: 8px; }
23
+ .msg.them code { font-size: 13px; }
24
+ .msg.them a { color: var(--accent); }
25
+ .note { align-self: center; max-width: 90%; text-align: center; color: var(--mute); font-size: 13px; }
26
+ .dots { align-self: flex-start; color: var(--mute); letter-spacing: 3px; }
27
+ .ask { align-self: stretch; border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
28
+ .ask p { margin: 0 0 4px; font-weight: 600; white-space: pre-wrap; }
29
+ .ask button, .ask label { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; font: inherit; cursor: pointer; }
30
+ .ask button:hover { border-color: var(--accent); }
31
+ .ask .go { align-self: flex-end; background: var(--accent); color: #fff; border-color: var(--accent); }
32
+ .ask input[type=text] { width: 100%; margin-top: 6px; }
33
+ #composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
34
+ textarea, input[type=text] { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font: inherit; font-size: 16px; }
35
+ textarea:focus, input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
36
+ #composer button { border: 0; border-radius: 10px; padding: 0 14px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
37
+ #composer button:disabled { opacity: .5; cursor: default; }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <header><span id="title">Chat</span><button type="button" id="close" aria-label="Close">&times;</button></header>
42
+ <div id="log" role="log" aria-live="polite"></div>
43
+ <div id="composer"><textarea id="box" rows="1" maxlength="4000" placeholder="Type a message…" aria-label="Message"></textarea><button type="button" id="send">Send</button></div>
44
+ <script nonce="__CSP_NONCE__" src="/widget/vendor/purify.js?v=__ASSET_V__"></script>
45
+ <script nonce="__CSP_NONCE__" src="/widget/vendor/marked.js?v=__ASSET_V__"></script>
46
+ <script nonce="__CSP_NONCE__">
47
+ (function () {
48
+ "use strict";
49
+ var WIDGET = "__WIDGET_ID__";
50
+ var TICKET = "__WIDGET_TICKET__";
51
+ var SOCKET = "__WIDGET_WS__";
52
+ var ORIGINS = __WIDGET_ORIGINS__;
53
+ var $ = function (id) { return document.getElementById(id); };
54
+ var log = $("log"), box = $("box"), send = $("send");
55
+ var parentOrigin = null, token = null, context = null, page = null;
56
+ var ws = null, ready = false, busy = false, dots = null, ask = null, retry = 0, over = false, started = false;
57
+
58
+ function toParent(msg) {
59
+ msg.shadokWidget = 1;
60
+ // Before the handshake the parent's origin is unknown and an opaque frame
61
+ // cannot name itself either: only a contentless hello goes out to "*".
62
+ window.parent.postMessage(msg, parentOrigin || "*");
63
+ }
64
+ function scroll() { log.scrollTop = log.scrollHeight; }
65
+ function add(cls, fill) {
66
+ var el = document.createElement("div");
67
+ el.className = cls;
68
+ fill(el);
69
+ log.insertBefore(el, dots && dots.parentNode === log ? dots : null);
70
+ scroll();
71
+ return el;
72
+ }
73
+ function mine(text) { add("msg me", function (el) { el.textContent = text; }); }
74
+ function theirs(markdown) {
75
+ add("msg them", function (el) {
76
+ // The agent's Markdown derives from whatever it read: sanitised, or shown
77
+ // as plain text when the sanitiser did not load. Never raw HTML.
78
+ if (window.DOMPurify && window.marked) {
79
+ el.innerHTML = window.DOMPurify.sanitize(window.marked.parse(markdown), { FORBID_TAGS: ["style", "form", "input", "button", "iframe"], FORBID_ATTR: ["style"] });
80
+ var links = el.querySelectorAll("a[href]");
81
+ for (var i = 0; i < links.length; i++) { links[i].target = "_blank"; links[i].rel = "noopener noreferrer"; }
82
+ } else el.textContent = markdown;
83
+ });
84
+ }
85
+ function note(text) { add("note", function (el) { el.textContent = text; }); }
86
+ function working(on) {
87
+ busy = on;
88
+ send.disabled = on || !ready || over;
89
+ if (on && !dots) { dots = document.createElement("div"); dots.className = "dots"; dots.textContent = "•••"; log.appendChild(dots); scroll(); }
90
+ if (!on && dots) { dots.remove(); dots = null; }
91
+ }
92
+ function clearAsk() { if (ask) { ask.remove(); ask = null; } }
93
+ function answer(payload) { payload.type = "answer"; ws.send(JSON.stringify(payload)); clearAsk(); working(true); }
94
+ function showAsk(m) {
95
+ clearAsk();
96
+ working(false);
97
+ send.disabled = true;
98
+ ask = add("ask", function (el) {
99
+ var q = document.createElement("p");
100
+ q.textContent = m.question || "";
101
+ el.appendChild(q);
102
+ var picked = {};
103
+ (m.options || []).forEach(function (o) {
104
+ if (o.text) {
105
+ var wrap = document.createElement("label");
106
+ wrap.textContent = o.label;
107
+ var input = document.createElement("input");
108
+ input.type = "text";
109
+ input.maxLength = 1000;
110
+ input.addEventListener("keydown", function (e) {
111
+ if (e.key === "Enter" && input.value.trim()) { e.preventDefault(); answer({ n: o.n, text: input.value.trim() }); }
112
+ });
113
+ wrap.appendChild(input);
114
+ el.appendChild(wrap);
115
+ return;
116
+ }
117
+ if (m.multi) {
118
+ var lab = document.createElement("label");
119
+ var cb = document.createElement("input");
120
+ cb.type = "checkbox";
121
+ cb.addEventListener("change", function () { picked[o.n] = cb.checked; });
122
+ lab.appendChild(cb);
123
+ lab.appendChild(document.createTextNode(" " + o.label));
124
+ el.appendChild(lab);
125
+ return;
126
+ }
127
+ var b = document.createElement("button");
128
+ b.type = "button";
129
+ b.textContent = o.label;
130
+ b.addEventListener("click", function () { answer({ n: o.n }); });
131
+ el.appendChild(b);
132
+ });
133
+ if (m.multi) {
134
+ var go = document.createElement("button");
135
+ go.type = "button";
136
+ go.className = "go";
137
+ go.textContent = "Send";
138
+ go.addEventListener("click", function () {
139
+ answer({ ns: Object.keys(picked).filter(function (k) { return picked[k]; }).map(Number) });
140
+ });
141
+ el.appendChild(go);
142
+ }
143
+ });
144
+ }
145
+ function closedForGood(text) {
146
+ over = true;
147
+ ready = false;
148
+ send.disabled = true;
149
+ box.disabled = true;
150
+ if (text) note(text);
151
+ }
152
+
153
+ function connect() {
154
+ if (over) return;
155
+ ws = new WebSocket(SOCKET);
156
+ ws.addEventListener("open", function () {
157
+ ws.send(JSON.stringify({ type: "hello", widget: WIDGET, ticket: TICKET, token: token || undefined }));
158
+ });
159
+ ws.addEventListener("message", function (e) {
160
+ var m;
161
+ try { m = JSON.parse(e.data); } catch (x) { return; }
162
+ switch (m.type) {
163
+ case "ready":
164
+ ready = true;
165
+ retry = 0;
166
+ send.disabled = busy;
167
+ if (m.title) { $("title").textContent = m.title; document.title = m.title; }
168
+ if (m.placeholder) box.placeholder = m.placeholder;
169
+ if (m.accent) document.documentElement.style.setProperty("--accent", m.accent);
170
+ if (!started) { started = true; if (m.welcome) theirs(m.welcome); }
171
+ break;
172
+ case "token":
173
+ token = m.token;
174
+ toParent({ type: "token", token: m.token });
175
+ break;
176
+ case "history":
177
+ // A reconnect replays what is already on screen: drawn once.
178
+ if (log.querySelector(".msg.me")) break;
179
+ (m.turns || []).forEach(function (t) { if (t.role === "visitor") mine(t.text); else theirs(t.text); });
180
+ break;
181
+ case "working": working(true); break;
182
+ case "text": theirs(m.markdown || ""); toParent({ type: "unread" }); break;
183
+ case "echo": mine(m.text || ""); break;
184
+ case "done": working(false); clearAsk(); break;
185
+ case "dialog": showAsk(m); toParent({ type: "unread" }); break;
186
+ case "notice": note(m.text || ""); break;
187
+ case "reload": reloadOnce(); break;
188
+ case "closed": closedForGood("This chat is not available right now."); break;
189
+ }
190
+ });
191
+ ws.addEventListener("close", function () {
192
+ ready = false;
193
+ working(false);
194
+ send.disabled = true;
195
+ if (over) return;
196
+ retry = Math.min(retry + 1, 6);
197
+ setTimeout(connect, 1000 * Math.pow(2, retry - 1));
198
+ });
199
+ }
200
+ // The ticket this page carries expired or was issued to another address: a
201
+ // reload gets a fresh one. Counted in the fragment (no storage here), so a
202
+ // server that keeps refusing cannot spin the frame for ever.
203
+ function reloadOnce() {
204
+ var n = parseInt((location.hash.match(/r=(\d+)/) || [])[1] || "0", 10);
205
+ if (n >= 3) return closedForGood("This chat is not available right now.");
206
+ over = true;
207
+ location.hash = "r=" + (n + 1);
208
+ location.reload();
209
+ }
210
+
211
+ // Not a form element: the sandbox has no `allow-forms`, and a sandboxed frame does
212
+ // not even dispatch `submit` — the message would silently never leave.
213
+ function submitMessage() {
214
+ var text = box.value.trim();
215
+ if (!text || !ready || busy || over) return;
216
+ var msg = { type: "message", text: text };
217
+ if (context || page) {
218
+ msg.context = {};
219
+ for (var k in context || {}) msg.context[k] = context[k];
220
+ if (page) msg.context.page = page;
221
+ }
222
+ ws.send(JSON.stringify(msg));
223
+ mine(text);
224
+ box.value = "";
225
+ working(true);
226
+ }
227
+ send.addEventListener("click", submitMessage);
228
+ box.addEventListener("keydown", function (e) {
229
+ if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); submitMessage(); }
230
+ });
231
+ $("close").addEventListener("click", function () { toParent({ type: "close" }); });
232
+
233
+ window.addEventListener("message", function (e) {
234
+ // Only the page that embeds us, and only if it is one of the widget's sites.
235
+ if (e.source !== window.parent || ORIGINS.indexOf(e.origin) < 0) return;
236
+ var m = e.data;
237
+ if (!m || m.shadokWidget !== 1) return;
238
+ if (m.type === "init") {
239
+ parentOrigin = e.origin;
240
+ if (typeof m.token === "string") token = m.token;
241
+ if (m.context && typeof m.context === "object") context = m.context;
242
+ if (typeof m.page === "string") page = m.page;
243
+ if (!ws) connect();
244
+ } else if (m.type === "context" && m.context && typeof m.context === "object") context = m.context;
245
+ else if (m.type === "shown") box.focus();
246
+ });
247
+ send.disabled = true;
248
+ toParent({ type: "hello" });
249
+ })();
250
+ </script>
251
+ </body>
252
+ </html>
@@ -0,0 +1,100 @@
1
+ /* shadok-ai web widget loader. Served by the instance as /widget.js?id=<widget>.
2
+ * Draws a launcher button and, on first open, the chat frame. Keeps the
3
+ * visitor's token in THIS page's storage (the frame has no storage of its own)
4
+ * and hands it to the frame once, in answer to its hello. */
5
+ (function () {
6
+ "use strict";
7
+ var ID = "__WIDGET_ID__";
8
+ var BASE = "__WIDGET_BASE__";
9
+ var ACCENT = "__WIDGET_ACCENT__";
10
+ var TITLE = "__WIDGET_TITLE__";
11
+ if (window.__shadokWidgetLoaded) return;
12
+ window.__shadokWidgetLoaded = true;
13
+ var KEY = "shadok-widget:" + ID;
14
+ var api = (window.shadokWidget = window.shadokWidget || {});
15
+ var context = clean(api.context);
16
+ var frame = null, panel = null, open = false, badge = null;
17
+
18
+ function clean(c) {
19
+ var out = {}, n = 0;
20
+ if (!c || typeof c !== "object") return null;
21
+ for (var k in c) if (typeof c[k] === "string" && /^[a-zA-Z0-9_]{1,32}$/.test(k) && n++ < 10) out[k] = c[k].slice(0, 200);
22
+ return n ? out : null;
23
+ }
24
+ function stored() { try { return window.localStorage.getItem(KEY); } catch (e) { return null; } }
25
+ function store(t) { try { window.localStorage.setItem(KEY, t); } catch (e) { /* private mode: this visit only */ } }
26
+ function post(msg) {
27
+ if (!frame || !frame.contentWindow) return;
28
+ msg.shadokWidget = 1;
29
+ // The frame's origin is opaque by design and cannot be named.
30
+ frame.contentWindow.postMessage(msg, "*");
31
+ }
32
+ function css(el, rules) { for (var k in rules) el.style[k] = rules[k]; return el; }
33
+ function narrow() { return window.innerWidth < 480; }
34
+ function place() {
35
+ if (!panel) return;
36
+ if (narrow()) css(panel, { right: "0", bottom: "0", width: "100%", height: "100%", borderRadius: "0" });
37
+ else css(panel, { right: "20px", bottom: "88px", width: "380px", height: "min(600px, calc(100% - 110px))", borderRadius: "14px" });
38
+ }
39
+ function build() {
40
+ panel = css(document.createElement("div"), {
41
+ position: "fixed", zIndex: "2147483000", background: "#fff", overflow: "hidden",
42
+ boxShadow: "0 12px 40px rgba(0,0,0,.25)", display: "none",
43
+ });
44
+ frame = css(document.createElement("iframe"), { width: "100%", height: "100%", border: "0" });
45
+ frame.title = TITLE;
46
+ frame.src = BASE + "/widget/frame?w=" + encodeURIComponent(ID);
47
+ panel.appendChild(frame);
48
+ document.body.appendChild(panel);
49
+ place();
50
+ }
51
+ function show(on) {
52
+ open = on;
53
+ if (on && !panel) build();
54
+ if (panel) panel.style.display = on ? "block" : "none";
55
+ if (on) { badge.style.display = "none"; post({ type: "shown" }); }
56
+ }
57
+ api.open = function () { show(true); };
58
+ api.close = function () { show(false); };
59
+ api.setContext = function (c) { context = clean(c); post({ type: "context", context: context || {} }); };
60
+
61
+ window.addEventListener("message", function (e) {
62
+ if (!frame || e.source !== frame.contentWindow) return;
63
+ var m = e.data;
64
+ if (!m || m.shadokWidget !== 1) return;
65
+ if (m.type === "hello") post({ type: "init", token: stored(), context: context, page: location.href.slice(0, 200) });
66
+ else if (m.type === "token" && typeof m.token === "string") store(m.token);
67
+ else if (m.type === "close") show(false);
68
+ else if (m.type === "unread" && !open) badge.style.display = "block";
69
+ });
70
+ window.addEventListener("resize", place);
71
+
72
+ function start() {
73
+ var button = css(document.createElement("button"), {
74
+ position: "fixed", right: "20px", bottom: "20px", zIndex: "2147483000", width: "56px", height: "56px",
75
+ borderRadius: "50%", border: "0", background: ACCENT, color: "#fff", cursor: "pointer",
76
+ boxShadow: "0 6px 20px rgba(0,0,0,.25)", padding: "0",
77
+ });
78
+ button.type = "button";
79
+ button.setAttribute("aria-label", TITLE);
80
+ var ns = "http://www.w3.org/2000/svg";
81
+ var svg = document.createElementNS(ns, "svg");
82
+ svg.setAttribute("viewBox", "0 0 24 24");
83
+ svg.setAttribute("width", "26");
84
+ svg.setAttribute("height", "26");
85
+ var path = document.createElementNS(ns, "path");
86
+ path.setAttribute("fill", "currentColor");
87
+ path.setAttribute("d", "M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z");
88
+ svg.appendChild(path);
89
+ button.appendChild(svg);
90
+ badge = css(document.createElement("span"), {
91
+ position: "absolute", top: "2px", right: "2px", width: "14px", height: "14px", borderRadius: "50%",
92
+ background: "#e53e3e", border: "2px solid #fff", display: "none",
93
+ });
94
+ button.appendChild(badge);
95
+ button.addEventListener("click", function () { show(!open); });
96
+ document.body.appendChild(button);
97
+ }
98
+ if (document.body) start();
99
+ else document.addEventListener("DOMContentLoaded", start);
100
+ })();
@@ -70,6 +70,8 @@ export declare function agentAccountName(sessionId: string): string;
70
70
  * door's configuration: an admin who re-points a door at another group must not
71
71
  * silently un-box the conversations that are already running.
72
72
  *
73
+ * - a web binding (a website visitor, through a widget) is always a guest's,
74
+ * for the reason a WhatsApp one is.
73
75
  * - a WhatsApp binding is always a guest's. That transport has no owner and no
74
76
  * operator side: "every DM is a guest's, including the admin's own".
75
77
  * - a Telegram binding is a guest's when it is a DM (`threadId` absent and a
@@ -77,6 +79,9 @@ export declare function agentAccountName(sessionId: string): string;
77
79
  * the DM owner. `dmOwner` unknown means every DM is a guest's, which is the
78
80
  * fail-closed direction: boxing the owner's own agent costs it the sight of
79
81
  * its siblings, while un-boxing a stranger's costs the instance a wall.
82
+ * - an agent spawned INTO an external group (`Channel.conversation`) is boxed
83
+ * like a guest: it is a member of the strangers' group, and without the box
84
+ * that membership would show it every other conversation there.
80
85
  * - anything else — a board topic, a group chat, a plain web agent — is not a
81
86
  * guest's and is not boxed.
82
87
  *
@@ -93,6 +98,11 @@ export declare function guestConversationOf(ch: {
93
98
  account: string;
94
99
  id: string;
95
100
  } | null;
101
+ web?: {
102
+ widget: string;
103
+ visitor: string;
104
+ } | null;
105
+ conversation?: string | null;
96
106
  } | null | undefined, dmOwner: number | null): string | null;
97
107
  /**
98
108
  * Resolve the principal behind a VERIFIED session id (the caller has already
@@ -120,6 +130,7 @@ export declare function resolveAgentPrincipal(sessionId: string, channels: reado
120
130
  account: string;
121
131
  id: string;
122
132
  } | null;
133
+ conversation?: string | null;
123
134
  }[], peerScope: (name: string) => "admin" | "member" | "restricted" | null, liveProfile?: string | null,
124
135
  /** The Telegram DM owner, for `guestConversationOf`. Omitted = unknown, which
125
136
  * boxes every DM — the fail-closed direction. */
@@ -15,6 +15,7 @@
15
15
  * name, and its group membership is exactly its channel's group — nothing a
16
16
  * frame or a body says. Pure, so the rules are tested without a server.
17
17
  */
18
+ import { isAgentConversation } from "./isolation-unit.js";
18
19
  /** Prefix of an agent's account name. Reserved: `userWriteVerdict` refuses a
19
20
  * person account named with it. Nothing authorizes on the NAME anyway — an
20
21
  * agent is recognised by the `agent` field, which only the key resolution sets. */
@@ -42,6 +43,8 @@ export function agentAccountName(sessionId) {
42
43
  * door's configuration: an admin who re-points a door at another group must not
43
44
  * silently un-box the conversations that are already running.
44
45
  *
46
+ * - a web binding (a website visitor, through a widget) is always a guest's,
47
+ * for the reason a WhatsApp one is.
45
48
  * - a WhatsApp binding is always a guest's. That transport has no owner and no
46
49
  * operator side: "every DM is a guest's, including the admin's own".
47
50
  * - a Telegram binding is a guest's when it is a DM (`threadId` absent and a
@@ -49,6 +52,9 @@ export function agentAccountName(sessionId) {
49
52
  * the DM owner. `dmOwner` unknown means every DM is a guest's, which is the
50
53
  * fail-closed direction: boxing the owner's own agent costs it the sight of
51
54
  * its siblings, while un-boxing a stranger's costs the instance a wall.
55
+ * - an agent spawned INTO an external group (`Channel.conversation`) is boxed
56
+ * like a guest: it is a member of the strangers' group, and without the box
57
+ * that membership would show it every other conversation there.
52
58
  * - anything else — a board topic, a group chat, a plain web agent — is not a
53
59
  * guest's and is not boxed.
54
60
  *
@@ -59,8 +65,15 @@ export function agentAccountName(sessionId) {
59
65
  export function guestConversationOf(ch, dmOwner) {
60
66
  if (!ch)
61
67
  return null;
68
+ if (isAgentConversation(ch.conversation))
69
+ return `ag:${ch.conversation}`;
62
70
  if (ch.whatsapp)
63
71
  return `wa:${ch.whatsapp.account}:${ch.whatsapp.id}`;
72
+ // A web binding is always a guest's, like a WhatsApp one: the widget has no
73
+ // owner and no operator side. Any binding at all boxes — a malformed one
74
+ // included, since un-boxing a stranger is the direction that costs a wall.
75
+ if (ch.web)
76
+ return `web:${ch.web.widget}:${ch.web.visitor}`;
64
77
  const tg = ch.telegram;
65
78
  if (!tg || tg.threadId != null || !(tg.chatId > 0))
66
79
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"agent-principal.js","sourceRoot":"","sources":["../src/agent-principal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAmCH;;oFAEoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAE7C,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,OAAO,GAAG,oBAAoB,GAAG,SAAS,EAAE,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,mBAAmB,CACjC,EAGoB,EACpB,OAAsB;IAEtB,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,IAAI,EAAE,CAAC,QAAQ;QAAE,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,EAA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,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,uBAAuB,CAA+C,GAAM;IAC1F,MAAM,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,IAAI,qBAAqB;QAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAC,CAM/B;IACC,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IACnD,OAAO,CAAC,CAAC,UAAU,CAAC;AACtB,CAAC;AAED;sEACsE;AACtE,MAAM,UAAU,aAAa,CAAC,CAAU;IACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClF,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC/C,CAAC"}
@@ -40,6 +40,13 @@ export interface Channel {
40
40
  * web widget — its own field, for the reason `whatsapp` has one.
41
41
  * Server-owned; written by the widget bridge only (src/web-guests.ts). */
42
42
  web?: WebBinding | null;
43
+ /** The conversation of an agent spawned INTO an external group rather than
44
+ * admitted through a door (`agentConversationName`: `ag-<its session id>`).
45
+ * In such a group the conversation is the isolation unit — its Unix user,
46
+ * its HOME, its vault slice — so it is stored at birth and read back on
47
+ * every resume (`guestConversationKey`), never derived from the caller.
48
+ * Server-owned; written once, by the start handler. */
49
+ conversation?: string | null;
43
50
  /** What the user WANTS: should this channel also live in Telegram?
44
51
  * Distinct from `telegram` — without an explicit intent, "not mirrored yet"
45
52
  * and "deliberately not mirrored" are indistinguishable, and the reconcile
package/dist/channels.js CHANGED
@@ -21,6 +21,10 @@ export function isMirrored(c) {
21
21
  // Nor a website visitor's.
22
22
  if (c.web)
23
23
  return false;
24
+ // Nor an agent living among them: it is boxed like a guest, so a board topic
25
+ // would be the one place its conversation reached beyond its own group.
26
+ if (c.conversation)
27
+ return false;
24
28
  return c.mirror ?? !!c.telegram;
25
29
  }
26
30
  /** Fields the server owns; a browser PUT must never overwrite or drop them.
@@ -30,7 +34,7 @@ export function isMirrored(c) {
30
34
  * only resume its own agents" — which broke any multi-step remote exchange
31
35
  * (the holder's first resume ran; the browser's next sync wiped the owner). Same
32
36
  * loss as `profile`/`parent` before they were listed here. */
33
- const SERVER_OWNED = ["cwd", "branch", "repo", "telegram", "whatsapp", "web", "profile", "model", "effort", "parent", "home", "group", "createdByPeer", "spawnFp", "spawnAt", "spawnClaudeVer", "skills", "createdBy"];
37
+ const SERVER_OWNED = ["cwd", "branch", "repo", "telegram", "whatsapp", "web", "conversation", "profile", "model", "effort", "parent", "home", "group", "createdByPeer", "spawnFp", "spawnAt", "spawnClaudeVer", "skills", "createdBy"];
34
38
  /**
35
39
  * Pure: is this channel the environment's home base — pinned and never closable?
36
40
  *
@@ -282,6 +286,8 @@ mayMove) {
282
286
  // And for the web binding: a planted one would hand a browser someone
283
287
  // else's conversation name, i.e. their Unix user on the next resume.
284
288
  delete born.web;
289
+ // And for an agent-made conversation: a planted name is a Unix user.
290
+ delete born.conversation;
285
291
  result.push(born);
286
292
  continue;
287
293
  }
@@ -299,6 +305,8 @@ mayMove) {
299
305
  delete merged.whatsapp;
300
306
  if (prev.web === undefined)
301
307
  delete merged.web;
308
+ if (prev.conversation === undefined)
309
+ delete merged.conversation;
302
310
  if (!("group" in c) && prev.group !== undefined)
303
311
  merged.group = prev.group;
304
312
  // Same for `folder`: a tab pushes it only when it filed the agent itself, so