shadok-ai 0.17.72 → 0.17.74

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
@@ -190,8 +190,11 @@ Enter to skip; you can add it later from the web UI).
190
190
  children and nothing else, so a busy channel never wakes it. What arrives is
191
191
  the child's own summary plus pointers (branch, diff link) — never the diff
192
192
  itself, which on a large session costs far more than it is worth. The link is
193
- set automatically at spawn; you can also attach or detach an agent by hand
194
- from its ⋯ menu.
193
+ set automatically at spawn; you can also change it by hand. A 🔗 on the tab
194
+ marks any agent that has a link, and its menu cuts it from **either** end — the
195
+ child's own "Detach from…", or, on the parent, "Children reporting here…" to
196
+ drop an agent whose reports you no longer want. An agent can do the same over
197
+ the CLI with `pilotctl set-parent <id> <parent|none>`.
195
198
  - **Quota gauges + pace guard** — 5h and 7d subscription usage, with an
196
199
  optional block when you're burning faster than the window elapses (any
197
200
  message can force through).
@@ -556,6 +559,12 @@ shell.
556
559
 
557
560
  ### Running in Docker
558
561
 
562
+ > Putting one instance online for someone else, on its own machine, behind a
563
+ > domain? Follow
564
+ > [`docs/deploying-an-instance.md`](docs/deploying-an-instance.md) instead — the
565
+ > same thing in order, with a `docker-compose.yml` to copy, and it links back
566
+ > here for the explanations.
567
+
559
568
  The repo ships an official `Dockerfile`:
560
569
 
561
570
  ```bash
@@ -1117,6 +1126,7 @@ wrong**, not in a catch-up pass afterwards:
1117
1126
  | `CLAUDE.md` | the file→responsibility map, the build/run recipe, the invariants | you add a module, or you lose an afternoon to something the next person would lose it to as well |
1118
1127
  | `docs/architecture.md` | how a subsystem actually works and why it was built that way | you add or reshape a subsystem, or you make a design trade-off worth remembering |
1119
1128
  | `docs/superpowers/specs/` | one design per feature, dated | before building anything non-trivial |
1129
+ | `docs/deploying-an-instance.md` | the order of operations to put ONE instance online on its own machine | a deployment step changes: the image, the volume list, the proxy requirements, the upgrade path |
1120
1130
 
1121
1131
  This is not bookkeeping. A doc that lags is worse than no doc: it is confidently
1122
1132
  wrong, and it is read as current. `docs/architecture.md` once went **48 commits**
@@ -29,6 +29,7 @@ and automatically starts the shadok-ai server when it is not running (port
29
29
  | `list [--cwd DIR]` | driven agents (local state + alive/dead) and resumable sessions. With `--peer X`: the agents running ON X (from X itself, tagged `peer`), plus X's resumable sessions only for a `--cwd` you name — a path on X |
30
30
  | `diff <id>` | the agent's changes (git status + diff against the worktree's base) |
31
31
  | `stop <id>` | ends the session (for ALL its clients) |
32
+ | `set-parent <id> <parent-id\|none>` | re-link an agent to a parent, or **detach** it with `none` (it then reports to nobody). The link is what makes the parent hear when the agent finishes, blocks or dies — set automatically at spawn, flipped here when a side task is done and you want it off a lead's back |
32
33
  | `screen <id>` | raw TUI screen (debug) |
33
34
  | `profile-prompt "<text>" [--name NAME] [--readonly]` | rewrites a profile's **system prompt**: your own by default; any of them (and creation with `--name`) under the lead profile |
34
35
  | `talk-handle` | prints **your own** handle — the "here is a handle to me" you share so another agent can send you a letter → `{handle}` |
@@ -113,7 +114,12 @@ Practical consequence: **do not loop to watch an agent any more.** Launch the
113
114
  time, and the information comes to you.
114
115
 
115
116
  `--parent none` spawns an agent deliberately unattached; `--parent <id>`
116
- attaches it elsewhere.
117
+ attaches it elsewhere. To change the link on an agent that is **already
118
+ running** — detach one whose notifications you no longer want, or move it under
119
+ a different lead — use `set-parent <id> <parent-id|none>`. In the cockpit the
120
+ same thing is a click: an agent's tab menu offers "Detach from…" (child side)
121
+ and, on the parent, "Children reporting here…", and a 🔗 on the tab marks any
122
+ agent that has a link.
117
123
 
118
124
  ## Talking across groups: a letter, not a remote control (`talk`)
119
125
 
@@ -161,6 +161,13 @@ export function parseArgs(argv) {
161
161
  return { cmd, pos, flags };
162
162
  }
163
163
 
164
+ // Normalise the `set-parent` target: `none`/`null`/empty mean DETACH (report to
165
+ // nobody), anything else is the parent session id. Pure, so the rule is
166
+ // testable without a server.
167
+ export function parseParentArg(arg) {
168
+ return arg && arg !== "none" && arg !== "null" ? arg : null;
169
+ }
170
+
164
171
  function connect() {
165
172
  return new Promise((resolve, reject) => {
166
173
  const ws = makeWS(wsUrl(), { headers: authHeaders() });
@@ -532,6 +539,32 @@ async function cmdDiff(id) {
532
539
  };
533
540
  }
534
541
 
542
+ // Attach an agent under another, or detach it with `none`. The link is what
543
+ // makes the parent hear when this agent finishes, blocks or dies — set
544
+ // automatically at spawn, flipped by hand here (e.g. to stop reporting to a
545
+ // lead once a side task is done). `parent` is SERVER_OWNED on the channel, so
546
+ // this WS message is the only legitimate path, exactly like the web menu's
547
+ // "Detach from…". The server validates the link (cycle/depth/fan-out) and
548
+ // refuses out loud; detaching (`none`) is always allowed.
549
+ async function cmdSetParent(id, parentArg, flags) {
550
+ if (!id) throw new Error("usage: pilotctl set-parent <id> <parent-id|none>");
551
+ await ensureServer();
552
+ const st = readState(id);
553
+ // cwd may be unknown for a session we did not spawn; the server resolves the
554
+ // target from its own registry (it is the authority on where a session lives).
555
+ const cwd = flags.cwd ?? st?.cwd ?? undefined;
556
+ const parent = parseParentArg(parentArg);
557
+ const client = await openSession({ resume: id, cwd });
558
+ client.send({ type: "set-parent", parent });
559
+ // The server echoes the new link with a `parent` broadcast; a refused link
560
+ // comes back as `error` (code "link-refused").
561
+ const r = await client.waitFor(["parent", "error"], 15_000);
562
+ client.ws.close();
563
+ if (r.type === "error") throw new Error(r.message || "set-parent refused");
564
+ if (r.type === "timeout") throw new Error("set-parent not confirmed within 15s");
565
+ return { sessionId: id, parent: r.parent ?? null };
566
+ }
567
+
535
568
  async function cmdStop(id) {
536
569
  await ensureServer();
537
570
  const st = readState(id);
@@ -657,7 +690,8 @@ async function cmdScreen(id, flags) {
657
690
  }
658
691
 
659
692
  const HELP =
660
- "usage: pilotctl <spawn|prompt|dialog|choose|toggle|confirm|freetext|list|diff|stop|screen|profile-prompt|talk|talk-handle|peer> …\n" +
693
+ "usage: pilotctl <spawn|prompt|dialog|choose|toggle|confirm|freetext|list|diff|stop|set-parent|screen|profile-prompt|talk|talk-handle|peer> …\n" +
694
+ " pilotctl set-parent <id> <parent-id|none> # re-link or detach an agent from its parent\n" +
661
695
  " add --peer <alias> to any command to run it against another instance's agents\n" +
662
696
  " pilotctl peer <add <alias> <url> <ticket> [--token]|list|rm <alias>>";
663
697
 
@@ -764,6 +798,8 @@ export async function run(argv) {
764
798
  return cmdDiff(pos[0]);
765
799
  case "stop":
766
800
  return cmdStop(pos[0]);
801
+ case "set-parent":
802
+ return cmdSetParent(pos[0], pos[1], flags);
767
803
  case "screen":
768
804
  return cmdScreen(pos[0], flags);
769
805
  case "profile-prompt":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.17.72",
3
+ "version": "0.17.74",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",
package/public/index.html CHANGED
@@ -310,6 +310,9 @@
310
310
  /* Same for the opposite: an agent with scheduled prompts can speak without
311
311
  anyone having asked it anything. */
312
312
  .tab .cron, .tab .tg { font-size: 9px; opacity: 0.75; flex: 0 0 auto; }
313
+ /* A parent/child link exists on this agent (it reports to another, or others
314
+ report to it). Clicking opens the tab menu, where the link can be cut. */
315
+ .tab .link { font-size: 9px; opacity: 0.75; flex: 0 0 auto; cursor: pointer; }
313
316
  /* Background shells the agent left running. Last of the row on purpose: it is
314
317
  the most transient thing a tab says, so it must not shift the icons that sit
315
318
  still. It TURNS because a stopped hourglass and a running one look the same,
@@ -4935,6 +4938,18 @@
4935
4938
  update.className = "update";
4936
4939
  update.hidden = true;
4937
4940
  update.addEventListener("click", (e) => { e.stopPropagation(); handleClaudeUpdate(tab); });
4941
+ // Parent/child link indicator. Shown when this agent reports to another OR
4942
+ // others report to it; clicking opens the tab menu, where either link can be
4943
+ // cut (both the child-side "Detach from…" and the parent-side children list).
4944
+ const link = document.createElement("span");
4945
+ link.className = "link";
4946
+ link.hidden = true;
4947
+ link.textContent = "🔗";
4948
+ link.addEventListener("click", (e) => {
4949
+ e.stopPropagation();
4950
+ const r = link.getBoundingClientRect();
4951
+ openTabMenu(tab, r.left, r.bottom + 4);
4952
+ });
4938
4953
  // Name + time stacked (the time UNDER the title, so as not to truncate it).
4939
4954
  // Two rows: row 1 = led + name + icons; row 2 FULL WIDTH = "xxx ago" on the
4940
4955
  // left, context % hard right (no longer hidden behind the icons).
@@ -4949,7 +4964,7 @@
4949
4964
  paintAvatar();
4950
4965
  const row1 = document.createElement("div");
4951
4966
  row1.className = "tab-row1";
4952
- row1.append(name, timer, mute, cron, tg, shells, monitors, update, close);
4967
+ row1.append(name, timer, mute, cron, tg, shells, monitors, update, link, close);
4953
4968
  const row2 = document.createElement("div");
4954
4969
  row2.className = "tab-row2";
4955
4970
  row2.append(lastAt, ctxNum);
@@ -4986,7 +5001,7 @@
4986
5001
  updateState: null, // Claude Code update: "restart" (reload to apply) | "failed" (install then reload) | null
4987
5002
  staleReasons: [], // server-side "reload to apply" reasons: prompt/guardrails/skills/secrets changed, auth token expired, claude binary updated
4988
5003
  btnEl: btn, ledEl: led, nameEl: name, timerEl: timer,
4989
- ctxNumEl: ctxNum, ctxFillEl: ctxFill, muteEl: mute, cronEl: cron, tgEl: tg, shellsEl: shells, monitorsEl: monitors, updateEl: update,
5004
+ ctxNumEl: ctxNum, ctxFillEl: ctxFill, muteEl: mute, cronEl: cron, tgEl: tg, shellsEl: shells, monitorsEl: monitors, updateEl: update, linkEl: link,
4990
5005
  mirror: false, // mirrored into Telegram? (the ✈️ on the tab)
4991
5006
  lastAtEl: lastAt,
4992
5007
  };
@@ -5486,6 +5501,31 @@
5486
5501
  return t && t.nameEl ? t.nameEl.textContent : String(sessionId).slice(0, 8);
5487
5502
  }
5488
5503
 
5504
+ /** The agents that report to this one (its children in the kinship tree). */
5505
+ function childTabsOf(tab) {
5506
+ return tab.sessionId ? tabs.filter((t) => t.sessionId && t.parent === tab.sessionId) : [];
5507
+ }
5508
+
5509
+ /**
5510
+ * Light the 🔗 on a tab when it has a parent OR any children, and say which in
5511
+ * the tooltip. A parent change moves the badge on BOTH ends (the child gains a
5512
+ * parent, the parent gains a child), so callers refresh every tab — cheap, and
5513
+ * it never leaves one side stale.
5514
+ */
5515
+ function refreshLinkBadge(tab) {
5516
+ if (!tab.linkEl) return;
5517
+ const kids = childTabsOf(tab);
5518
+ const hasParent = !!tab.parent;
5519
+ tab.linkEl.hidden = !hasParent && kids.length === 0;
5520
+ const bits = [];
5521
+ if (hasParent) bits.push("Reports to " + parentLabel(tab.parent));
5522
+ if (kids.length) bits.push(kids.length + (kids.length > 1 ? " agents report here" : " agent reports here"));
5523
+ tab.linkEl.title = bits.join(" · ");
5524
+ }
5525
+ function refreshAllLinkBadges() {
5526
+ for (const t of tabs) refreshLinkBadge(t);
5527
+ }
5528
+
5489
5529
  /**
5490
5530
  * Second page of the tab menu: which agent this one reports to.
5491
5531
  *
@@ -5518,6 +5558,48 @@
5518
5558
  tabMenuOpenedAt = Date.now();
5519
5559
  }
5520
5560
 
5561
+ /**
5562
+ * Second page of the tab menu, from the PARENT's side: the agents reporting to
5563
+ * this one, each detachable in one click. The symmetric twin of the child-side
5564
+ * "Detach from…" — it is how you cut a link while looking at the parent, which
5565
+ * is the natural place when a lead wants an agent off its back. Detaching is
5566
+ * always legal (no cycle to check), so unlike the picker there is nothing to
5567
+ * refuse. Sending `set-parent {parent:null}` on the CHILD's socket is what the
5568
+ * server expects (the message acts on the attached session).
5569
+ */
5570
+ function openChildrenDetacher(tab) {
5571
+ const kids = childTabsOf(tab);
5572
+ tabMenu.replaceChildren();
5573
+ const head = document.createElement("div");
5574
+ head.className = "tm-head";
5575
+ head.textContent = kids.length ? "Detach which agent?" : "No agent reports here";
5576
+ tabMenu.appendChild(head);
5577
+ if (kids.length > 1) {
5578
+ const all = document.createElement("button");
5579
+ all.className = "tm-item";
5580
+ all.textContent = "✕ Detach all (" + kids.length + ")";
5581
+ all.addEventListener("click", (e) => {
5582
+ e.stopPropagation();
5583
+ closeTabMenu();
5584
+ for (const kid of kids) sendTo(kid, { type: "set-parent", parent: null });
5585
+ });
5586
+ tabMenu.appendChild(all);
5587
+ }
5588
+ for (const kid of kids) {
5589
+ const b = document.createElement("button");
5590
+ b.className = "tm-item";
5591
+ b.textContent = "✕ " + (kid.nameEl ? kid.nameEl.textContent : kid.sessionId.slice(0, 8));
5592
+ b.addEventListener("click", (e) => { // never onclick=: the CSP nonce
5593
+ e.stopPropagation(); // does not cover inline handlers
5594
+ closeTabMenu();
5595
+ sendTo(kid, { type: "set-parent", parent: null });
5596
+ });
5597
+ tabMenu.appendChild(b);
5598
+ }
5599
+ tabMenu.hidden = false;
5600
+ tabMenuOpenedAt = Date.now();
5601
+ }
5602
+
5521
5603
  function openTabMenu(tab, x, y) {
5522
5604
  tabMenu.replaceChildren();
5523
5605
  // Header: WHO this agent is. The profile is what qualifies it (role,
@@ -5586,6 +5668,13 @@
5586
5668
  tab.parent ? "🔗 Detach from " + parentLabel(tab.parent) : "🔗 Report to…",
5587
5669
  () => (tab.parent ? sendTo(tab, { type: "set-parent", parent: null }) : openParentPicker(tab)),
5588
5670
  ]);
5671
+ // The parent-side half: the agents reporting to THIS one, detachable from
5672
+ // here — so you can cut a link without hunting down the child's own tab.
5673
+ const kids = childTabsOf(tab);
5674
+ if (kids.length) items.push([
5675
+ "🔗 Children reporting here (" + kids.length + ")…",
5676
+ () => openChildrenDetacher(tab),
5677
+ ]);
5589
5678
  }
5590
5679
  // The main channel is the environment's home base — it can't be closed.
5591
5680
  if (!tab.isMain) items.push(["✕ Close agent", () => closeTab(tab)]);
@@ -6915,6 +7004,9 @@
6915
7004
  }
6916
7005
  }
6917
7006
  lastChannelIds = current;
7007
+ // Parents are re-applied above from the registry; refresh every 🔗 once the
7008
+ // pass has settled, so a link made on another device lights up here too.
7009
+ refreshAllLinkBadges();
6918
7010
  }
6919
7011
 
6920
7012
  // Is the server currently starting this instance's lead agent? Never inferred
@@ -10084,6 +10176,7 @@
10084
10176
  // Broadcast to every client, like `profile`: attaching from one tab
10085
10177
  // must update the others without a reload.
10086
10178
  t.parent = msg.parent;
10179
+ refreshAllLinkBadges(); // moves the 🔗 on both ends of the link
10087
10180
  break;
10088
10181
  case "tokens":
10089
10182
  t.tokens = msg.tokens;