shadok-ai 0.19.66 → 0.19.67

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
@@ -273,6 +273,13 @@ Enter to skip; you can add it later from the web UI).
273
273
  child's own "Detach from…", or, on the parent, "Children reporting here…" to
274
274
  drop an agent whose reports you no longer want. An agent can do the same over
275
275
  the CLI with `pilotctl set-parent <id> <parent|none>`.
276
+ The agents column **draws the link as a tree**: the agents an agent launched
277
+ sit indented under it, and the ▾ count on its tab folds them away (folded, it
278
+ carries the mood of what it hides — a child waiting for an answer still
279
+ shows). Nothing is arranged by hand and nothing is stored: the tree follows
280
+ the link. It never overrides where you filed an agent, though — a child you
281
+ put in another folder or group stays there, and when a parent is closed its
282
+ children simply move up a level.
276
283
  - **Quota gauges + pace guard** — 5h and 7d subscription usage, with an
277
284
  optional block when you're burning faster than the window elapses (any
278
285
  message can force through).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.19.66",
3
+ "version": "0.19.67",
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",
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Agent families — the pure core behind the parent/child tree of the agents
3
+ * column. The link itself is the server's (`parent` on the channel, validated
4
+ * by src/kinship.ts); this only decides how to DRAW it. Nothing is stored: the
5
+ * tree is recomputed from the links on every layout, so it follows an agent
6
+ * that spawns another without anyone arranging anything. ESM, browser + tests.
7
+ */
8
+
9
+ /**
10
+ * Who each agent is drawn under. `items` are `{ id, parent, slot }` in column
11
+ * order: `id` the agent's session id (null for a tab that has none yet — it is
12
+ * always a root), `parent` the session it reports to, `slot` the place it was
13
+ * filed in (its group and folder).
14
+ *
15
+ * A child nests under its parent ONLY when both sit in the same slot. Filing is
16
+ * a deliberate act — a folder, a group with its own members — and a derived
17
+ * tree must never move an agent out of where someone put it. So a child filed
18
+ * elsewhere, or whose parent is closed, is simply a root where it stands.
19
+ *
20
+ * Returns `Map<id, parentId>` holding the nested agents only.
21
+ */
22
+ export function familyParents(items) {
23
+ const byId = new Map();
24
+ for (const it of items || []) if (it && it.id != null) byId.set(String(it.id), it);
25
+ const shown = new Map();
26
+ for (const it of byId.values()) {
27
+ if (it.parent == null) continue;
28
+ const p = byId.get(String(it.parent));
29
+ if (!p || p === it || (p.slot ?? null) !== (it.slot ?? null)) continue;
30
+ shown.set(String(it.id), String(p.id));
31
+ }
32
+ // The server refuses a cycle, but a list caught mid-update could carry one,
33
+ // and a cycle has no root: every member would be drawn under another and the
34
+ // whole loop would vanish from the column. Cut it — its members become roots.
35
+ for (const start of [...shown.keys()]) {
36
+ const seen = new Set([start]);
37
+ let cur = shown.get(start);
38
+ while (cur != null && !seen.has(cur)) {
39
+ seen.add(cur);
40
+ cur = shown.get(cur);
41
+ }
42
+ // Only when the walk comes back to where it started: an agent hanging OFF
43
+ // the loop is not part of it and keeps its parent.
44
+ if (cur === start) for (const id of seen) shown.delete(id);
45
+ }
46
+ return shown;
47
+ }
48
+
49
+ /**
50
+ * The same links, read downwards: `kids(id)` → the ids drawn directly under
51
+ * `id`, in column order. `kids(null)` is not the roots — callers know theirs.
52
+ */
53
+ export function familyChildren(items, shown) {
54
+ const out = new Map();
55
+ for (const it of items || []) {
56
+ if (!it || it.id == null) continue;
57
+ const p = shown.get(String(it.id));
58
+ if (p == null) continue;
59
+ if (!out.has(p)) out.set(p, []);
60
+ out.get(p).push(String(it.id));
61
+ }
62
+ return (id) => out.get(String(id)) || [];
63
+ }
64
+
65
+ /** Every agent drawn under `id`, at any depth — what a folded parent hides. */
66
+ export function familyDescendants(kids, id) {
67
+ const all = [];
68
+ const walk = (cur) => {
69
+ for (const k of kids(cur)) {
70
+ all.push(k);
71
+ walk(k);
72
+ }
73
+ };
74
+ walk(id);
75
+ return all;
76
+ }
package/public/index.html CHANGED
@@ -841,6 +841,20 @@
841
841
  .folder-body { display: flex; flex-direction: column; gap: 2px; margin-left: 12px; padding-left: 6px; border-left: 1px solid var(--line); }
842
842
  .agent-folder.folded > .folder-body { display: none; }
843
843
  body.dragging-tab .folder-body:empty { min-height: 22px; border: 1px dashed var(--line); border-radius: 4px; }
844
+ /* Agent families: the agents a parent launched sit indented under it. DERIVED
845
+ from the parent link on every layout, never stored — so nothing here can be
846
+ dragged into being; the tab menu's "Report to…" is what changes it. */
847
+ .kin-body { display: flex; flex-direction: column; gap: 2px; margin-left: 10px; padding-left: 5px; border-left: 1px solid var(--line); }
848
+ .kin-body.folded { display: none; }
849
+ /* The fold toggle on a parent's tab: caret + how many agents sit under it.
850
+ Folded, it carries the mood of what it hides (same three as a folder). */
851
+ .tab .kin { flex: 0 0 auto; cursor: pointer; font-size: 10px; line-height: 1; padding: 2px 4px; border-radius: 4px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
852
+ .tab .kin:hover { color: var(--amber); background: var(--amber-soft); }
853
+ .tab .kin.needs-answer { background: color-mix(in srgb, var(--amber) 28%, transparent); color: var(--text); font-weight: 700; animation: breathe 1.2s ease-in-out infinite; }
854
+ .tab .kin.unread { color: var(--phosphor); font-weight: 700; }
855
+ .tab .kin.working { animation: breathe 1.8s ease-in-out infinite; }
856
+ @media (prefers-reduced-motion: reduce) { .tab .kin { animation: none !important; } }
857
+ .tab.kin-holds-active { box-shadow: inset 0 0 0 1px var(--line); }
844
858
  /* While dragging a tab, empty drop zones become visible targets. */
845
859
  body.dragging-tab #ungrouped:empty,
846
860
  body.dragging-tab .group-body:empty {
@@ -4668,6 +4682,10 @@
4668
4682
  window.folderChildren = folderChildren;
4669
4683
  window.effectiveFolder = effectiveFolder;
4670
4684
  window.removeFolder = removeFolder;
4685
+ import { familyParents, familyChildren, familyDescendants } from "/agent-family.js?v=__ASSET_V__";
4686
+ window.familyParents = familyParents;
4687
+ window.familyChildren = familyChildren;
4688
+ window.familyDescendants = familyDescendants;
4671
4689
  window.searchEmoji = searchEmoji;
4672
4690
  window.looksLikeEmoji = looksLikeEmoji;
4673
4691
  import { pumpLine, mascotSay, pickMaxim } from "/shadok-soul.js?v=__ASSET_V__";
@@ -5001,6 +5019,10 @@
5001
5019
  folderChildren: () => () => [],
5002
5020
  effectiveFolder: () => null,
5003
5021
  removeFolder: (folders) => ({ folders, refile: new Map() }),
5022
+ // Families before the module lands: a flat column, every agent a root.
5023
+ familyParents: () => new Map(),
5024
+ familyChildren: () => () => [],
5025
+ familyDescendants: () => [],
5004
5026
  looksLikeEmoji: () => false,
5005
5027
  uploadFailure: (status, contentType) =>
5006
5028
  /json/i.test(contentType || "") ? null : status === 413 ? "too large (over the server's upload limit)" : `upload failed (HTTP ${status || "?"})`,
@@ -5440,6 +5462,18 @@
5440
5462
  const r = link.getBoundingClientRect();
5441
5463
  openTabMenu(tab, r.left, r.bottom + 4);
5442
5464
  });
5465
+ // Fold toggle for the agents this one launched (drawn indented under it).
5466
+ // Hidden until it has any; painted by paintKin.
5467
+ const kin = document.createElement("span");
5468
+ kin.className = "kin";
5469
+ kin.hidden = true;
5470
+ kin.addEventListener("click", (e) => {
5471
+ e.stopPropagation();
5472
+ if (!tab.sessionId) return;
5473
+ if (!foldedKin.delete(tab.sessionId)) foldedKin.add(tab.sessionId);
5474
+ saveFoldedKin();
5475
+ paintKin();
5476
+ });
5443
5477
  // Name + time stacked (the time UNDER the title, so as not to truncate it).
5444
5478
  // Two rows: row 1 = led + name + icons; row 2 FULL WIDTH = "xxx ago" on the
5445
5479
  // left, context % hard right (no longer hidden behind the icons).
@@ -5454,7 +5488,7 @@
5454
5488
  paintAvatar();
5455
5489
  const row1 = document.createElement("div");
5456
5490
  row1.className = "tab-row1";
5457
- row1.append(name, timer, mute, cron, tg, shells, monitors, update, link, close);
5491
+ row1.append(name, timer, mute, cron, tg, shells, monitors, update, link, kin, close);
5458
5492
  const row2 = document.createElement("div");
5459
5493
  row2.className = "tab-row2";
5460
5494
  row2.append(lastAt, ctxNum);
@@ -5486,7 +5520,7 @@
5486
5520
  updateState: null, // Claude Code update: "restart" (reload to apply) | "failed" (install then reload) | null
5487
5521
  staleReasons: [], // server-side "reload to apply" reasons: prompt/guardrails/skills/secrets changed, auth token expired, claude binary updated
5488
5522
  btnEl: btn, ledEl: led, nameEl: name, timerEl: timer,
5489
- ctxNumEl: ctxNum, muteEl: mute, cronEl: cron, tgEl: tg, shellsEl: shells, monitorsEl: monitors, updateEl: update, linkEl: link,
5523
+ ctxNumEl: ctxNum, muteEl: mute, cronEl: cron, tgEl: tg, shellsEl: shells, monitorsEl: monitors, updateEl: update, linkEl: link, kinEl: kin,
5490
5524
  mirror: false, // mirrored into Telegram? (the ✈️ on the tab)
5491
5525
  lastAtEl: lastAt,
5492
5526
  };
@@ -6658,6 +6692,14 @@
6658
6692
  function saveFolded() {
6659
6693
  try { localStorage.setItem(FOLD_KEY(), JSON.stringify([...foldedFolders])); } catch {}
6660
6694
  }
6695
+ // Families fold the same way: this browser's choice, keyed by the PARENT's
6696
+ // session id (the tree itself is derived and has no id of its own).
6697
+ const KIN_FOLD_KEY = () => dirKey("cp.kinCollapsed", instanceKey);
6698
+ let foldedKin = new Set();
6699
+ try { foldedKin = new Set(JSON.parse(localStorage.getItem(KIN_FOLD_KEY()) || "[]")); } catch { foldedKin = new Set(); }
6700
+ function saveFoldedKin() {
6701
+ try { localStorage.setItem(KIN_FOLD_KEY(), JSON.stringify([...foldedKin])); } catch {}
6702
+ }
6661
6703
  // A local edit not yet confirmed by the server: a poll in between must not
6662
6704
  // put the old tree back under the user's hands.
6663
6705
  let folderPushTimer = null;
@@ -6788,29 +6830,56 @@
6788
6830
  folderEls.delete(id);
6789
6831
  }
6790
6832
  paintFolderHeads();
6833
+ paintKin();
6791
6834
  }
6792
6835
  function layoutScope(key, scope) {
6793
6836
  if (scope.querySelector("input.rename")) return; // a re-nest would eat the typing
6794
- const own = folders.some((f) => (f.group ?? null) === key);
6795
- if (!own && !scope.querySelector(".agent-folder")) return;
6796
6837
  const kids = window.folderChildren(folders, key);
6797
6838
  const tabEls = [...scope.querySelectorAll(".tab")];
6798
6839
  const place = (b) => window.effectiveFolder(folders, b._tab?.folder ?? null, key);
6840
+ // Families nest INSIDE a level: a child sits under its parent only when both
6841
+ // were filed in the same place (public/agent-family.js) — the tree is
6842
+ // derived, so it must never pull an agent out of the folder it was put in.
6843
+ const sid = (b) => b._tab?.sessionId ?? null;
6844
+ const items = tabEls.map((b) => ({ id: sid(b), parent: b._tab?.parent ?? null, slot: place(b) }));
6845
+ const shown = window.familyParents(items);
6846
+ const own = folders.some((f) => (f.group ?? null) === key);
6847
+ if (!own && !shown.size && !scope.querySelector(".agent-folder, .kin-body")) return;
6848
+ const kidIds = window.familyChildren(items, shown);
6849
+ const elBySid = new Map(tabEls.filter(sid).map((b) => [String(sid(b)), b]));
6850
+ const isRoot = (b) => !sid(b) || !shown.has(String(sid(b)));
6851
+ const kidEls = (b) => (sid(b) ? kidIds(sid(b)).map((id) => elBySid.get(id)).filter(Boolean) : []);
6852
+ const tabSig = (b) => {
6853
+ const k = kidEls(b);
6854
+ return "t" + (b._tab?.id ?? "") + (k.length ? ",[" + k.map(tabSig).join(",") + "]" : "");
6855
+ };
6799
6856
  const desired = (parent) =>
6800
6857
  [...kids(parent).map((f) => "f" + f.id + "(" + desired(f.id) + ")"),
6801
- ...tabEls.filter((b) => place(b) === parent).map((b) => "t" + (b._tab?.id ?? ""))].join(",");
6858
+ ...tabEls.filter((b) => place(b) === parent && isRoot(b)).map(tabSig)].join(",");
6802
6859
  const actual = (box) =>
6803
6860
  [...box.children].map((ch) =>
6804
6861
  ch.classList.contains("agent-folder") ? "f" + ch.dataset.folder + "(" + actual(ch._folderBody) + ")"
6862
+ : ch.classList.contains("kin-body") ? "[" + actual(ch) + "]"
6805
6863
  : ch.classList.contains("tab") ? "t" + (ch._tab?.id ?? "") : "?").join(",");
6806
6864
  if (desired(null) === actual(scope)) return;
6865
+ // One body per parent, kept on its tab across layouts.
6866
+ const usedKin = new Set();
6867
+ const putTab = (box, b) => {
6868
+ box.appendChild(b);
6869
+ const k = kidEls(b);
6870
+ if (!k.length) return;
6871
+ const body = b._tab.kinBodyEl || (b._tab.kinBodyEl = Object.assign(document.createElement("div"), { className: "kin-body" }));
6872
+ usedKin.add(body);
6873
+ box.appendChild(body);
6874
+ for (const c of k) putTab(body, c);
6875
+ };
6807
6876
  const build = (box, parent) => {
6808
6877
  for (const f of kids(parent)) {
6809
6878
  const rec = folderEl(f);
6810
6879
  box.appendChild(rec.el);
6811
6880
  build(rec.body, f.id);
6812
6881
  }
6813
- for (const b of tabEls) if (place(b) === parent) box.appendChild(b);
6882
+ for (const b of tabEls) if (place(b) === parent && isRoot(b)) putTab(box, b);
6814
6883
  };
6815
6884
  const keep = new Set();
6816
6885
  const mark = (parent) => { for (const f of kids(parent)) { keep.add(f.id); mark(f.id); } };
@@ -6819,6 +6888,30 @@
6819
6888
  // A folder of another group that ended up here (its group was dissolved):
6820
6889
  // it is empty by now, every tab having been placed above.
6821
6890
  for (const el of [...scope.querySelectorAll(".agent-folder")]) if (!keep.has(el.dataset.folder)) el.remove();
6891
+ // Same for a family body whose parent closed or lost its last child.
6892
+ for (const el of [...scope.querySelectorAll(".kin-body")]) if (!usedKin.has(el)) el.remove();
6893
+ }
6894
+
6895
+ /** The fold toggle of every parent: caret + count, and — folded — the mood of
6896
+ * the agents it hides. Guarded writes, for the same reason as the folders'. */
6897
+ function paintKin() {
6898
+ for (const t of tabs) {
6899
+ if (!t.kinEl) continue;
6900
+ const body = t.kinBodyEl;
6901
+ const inside = body && body.isConnected ? [...body.querySelectorAll(".tab")] : [];
6902
+ const folded = inside.length > 0 && foldedKin.has(t.sessionId);
6903
+ if (body) body.classList.toggle("folded", folded);
6904
+ if (t.kinEl.hidden !== !inside.length) t.kinEl.hidden = !inside.length;
6905
+ const label = inside.length ? (folded ? "▸" : "▾") + inside.length : "";
6906
+ if (t.kinEl.textContent !== label) t.kinEl.textContent = label;
6907
+ const title = inside.length
6908
+ ? (folded ? "Show" : "Hide") + " the " + inside.length + (inside.length > 1 ? " agents" : " agent") + " under this one"
6909
+ : "";
6910
+ if (t.kinEl.title !== title) t.kinEl.title = title;
6911
+ const mood = folded ? window.groupMood(inside.map((b) => b._tab).filter(Boolean).map(moodOf)) : null;
6912
+ for (const m of ["needs-answer", "unread", "working"]) t.kinEl.classList.toggle(m, m === mood);
6913
+ t.btnEl.classList.toggle("kin-holds-active", folded && inside.some((b) => b.classList.contains("active")));
6914
+ }
6822
6915
  }
6823
6916
 
6824
6917
  /** Count, fold caret, icon and mood of every folder header. Guarded writes: