shadok-ai 0.17.73 → 0.17.75

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).
@@ -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.73",
3
+ "version": "0.17.75",
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,
@@ -1124,7 +1127,13 @@
1124
1127
  #secretsList li.sec-ro code { opacity: .85; }
1125
1128
  #secretsList li.sec-row { flex-wrap: wrap; }
1126
1129
  .sec-meta { flex-basis: 100%; font-size: 11px; color: var(--text-dim); margin-top: 2px; }
1127
- #secretAttach[data-grouped="1"] { display: none; }
1130
+ #secretAttach[data-grouped="1"][data-editing="1"] { display: none; }
1131
+ #secretsAdd { margin-bottom: 12px; }
1132
+ .sec-val { flex-basis: 100%; display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; }
1133
+ .sec-val .sec-mask { font-family: var(--mono); letter-spacing: .1em; color: var(--text-dim); }
1134
+ .sec-val input { flex: 1; min-width: 0; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--amber); background: rgba(0,0,0,.25); color: inherit; font-size: 16px; }
1135
+ .sec-val button { flex: none; font-size: 12px; padding: 4px 12px; border-radius: 6px; border: 1px solid var(--line); background: none; color: inherit; cursor: pointer; }
1136
+ .sec-val button.sec-val-save { border-color: var(--amber); color: var(--amber); }
1128
1137
  .sec-from { margin-left: 8px; font-size: 11px; color: var(--text-dim); font-family: var(--sans, inherit); }
1129
1138
  /* Grouped mode: each own secret is a card — name + actions, one meta line, then
1130
1139
  the "Shared with" / "Injected into" chip rows and ONE Save. */
@@ -3405,7 +3414,6 @@
3405
3414
  </section>
3406
3415
  <div id="secretsScope" class="sec-scope" hidden><span>Group</span><select id="secretsGroup" aria-label="Group whose secrets are shown"></select></div>
3407
3416
  <p id="secretsErr" class="sec-err" role="alert" hidden></p>
3408
- <ul id="secretsList"></ul>
3409
3417
  <form id="secretsAdd">
3410
3418
  <div class="sec-add-row">
3411
3419
  <input id="secretKey" placeholder="NAME" autocomplete="off" spellcheck="false" />
@@ -3418,6 +3426,7 @@
3418
3426
  <div id="secretProfiles" class="sec-profiles"></div>
3419
3427
  </div>
3420
3428
  </form>
3429
+ <ul id="secretsList"></ul>
3421
3430
  <div id="secretsReload" class="sec-reload" hidden></div>
3422
3431
  <details class="sec-relay">
3423
3432
  <summary>Finish a sign-in for an agent (OAuth)</summary>
@@ -4935,6 +4944,18 @@
4935
4944
  update.className = "update";
4936
4945
  update.hidden = true;
4937
4946
  update.addEventListener("click", (e) => { e.stopPropagation(); handleClaudeUpdate(tab); });
4947
+ // Parent/child link indicator. Shown when this agent reports to another OR
4948
+ // others report to it; clicking opens the tab menu, where either link can be
4949
+ // cut (both the child-side "Detach from…" and the parent-side children list).
4950
+ const link = document.createElement("span");
4951
+ link.className = "link";
4952
+ link.hidden = true;
4953
+ link.textContent = "🔗";
4954
+ link.addEventListener("click", (e) => {
4955
+ e.stopPropagation();
4956
+ const r = link.getBoundingClientRect();
4957
+ openTabMenu(tab, r.left, r.bottom + 4);
4958
+ });
4938
4959
  // Name + time stacked (the time UNDER the title, so as not to truncate it).
4939
4960
  // Two rows: row 1 = led + name + icons; row 2 FULL WIDTH = "xxx ago" on the
4940
4961
  // left, context % hard right (no longer hidden behind the icons).
@@ -4949,7 +4970,7 @@
4949
4970
  paintAvatar();
4950
4971
  const row1 = document.createElement("div");
4951
4972
  row1.className = "tab-row1";
4952
- row1.append(name, timer, mute, cron, tg, shells, monitors, update, close);
4973
+ row1.append(name, timer, mute, cron, tg, shells, monitors, update, link, close);
4953
4974
  const row2 = document.createElement("div");
4954
4975
  row2.className = "tab-row2";
4955
4976
  row2.append(lastAt, ctxNum);
@@ -4986,7 +5007,7 @@
4986
5007
  updateState: null, // Claude Code update: "restart" (reload to apply) | "failed" (install then reload) | null
4987
5008
  staleReasons: [], // server-side "reload to apply" reasons: prompt/guardrails/skills/secrets changed, auth token expired, claude binary updated
4988
5009
  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,
5010
+ ctxNumEl: ctxNum, ctxFillEl: ctxFill, muteEl: mute, cronEl: cron, tgEl: tg, shellsEl: shells, monitorsEl: monitors, updateEl: update, linkEl: link,
4990
5011
  mirror: false, // mirrored into Telegram? (the ✈️ on the tab)
4991
5012
  lastAtEl: lastAt,
4992
5013
  };
@@ -5486,6 +5507,31 @@
5486
5507
  return t && t.nameEl ? t.nameEl.textContent : String(sessionId).slice(0, 8);
5487
5508
  }
5488
5509
 
5510
+ /** The agents that report to this one (its children in the kinship tree). */
5511
+ function childTabsOf(tab) {
5512
+ return tab.sessionId ? tabs.filter((t) => t.sessionId && t.parent === tab.sessionId) : [];
5513
+ }
5514
+
5515
+ /**
5516
+ * Light the 🔗 on a tab when it has a parent OR any children, and say which in
5517
+ * the tooltip. A parent change moves the badge on BOTH ends (the child gains a
5518
+ * parent, the parent gains a child), so callers refresh every tab — cheap, and
5519
+ * it never leaves one side stale.
5520
+ */
5521
+ function refreshLinkBadge(tab) {
5522
+ if (!tab.linkEl) return;
5523
+ const kids = childTabsOf(tab);
5524
+ const hasParent = !!tab.parent;
5525
+ tab.linkEl.hidden = !hasParent && kids.length === 0;
5526
+ const bits = [];
5527
+ if (hasParent) bits.push("Reports to " + parentLabel(tab.parent));
5528
+ if (kids.length) bits.push(kids.length + (kids.length > 1 ? " agents report here" : " agent reports here"));
5529
+ tab.linkEl.title = bits.join(" · ");
5530
+ }
5531
+ function refreshAllLinkBadges() {
5532
+ for (const t of tabs) refreshLinkBadge(t);
5533
+ }
5534
+
5489
5535
  /**
5490
5536
  * Second page of the tab menu: which agent this one reports to.
5491
5537
  *
@@ -5518,6 +5564,48 @@
5518
5564
  tabMenuOpenedAt = Date.now();
5519
5565
  }
5520
5566
 
5567
+ /**
5568
+ * Second page of the tab menu, from the PARENT's side: the agents reporting to
5569
+ * this one, each detachable in one click. The symmetric twin of the child-side
5570
+ * "Detach from…" — it is how you cut a link while looking at the parent, which
5571
+ * is the natural place when a lead wants an agent off its back. Detaching is
5572
+ * always legal (no cycle to check), so unlike the picker there is nothing to
5573
+ * refuse. Sending `set-parent {parent:null}` on the CHILD's socket is what the
5574
+ * server expects (the message acts on the attached session).
5575
+ */
5576
+ function openChildrenDetacher(tab) {
5577
+ const kids = childTabsOf(tab);
5578
+ tabMenu.replaceChildren();
5579
+ const head = document.createElement("div");
5580
+ head.className = "tm-head";
5581
+ head.textContent = kids.length ? "Detach which agent?" : "No agent reports here";
5582
+ tabMenu.appendChild(head);
5583
+ if (kids.length > 1) {
5584
+ const all = document.createElement("button");
5585
+ all.className = "tm-item";
5586
+ all.textContent = "✕ Detach all (" + kids.length + ")";
5587
+ all.addEventListener("click", (e) => {
5588
+ e.stopPropagation();
5589
+ closeTabMenu();
5590
+ for (const kid of kids) sendTo(kid, { type: "set-parent", parent: null });
5591
+ });
5592
+ tabMenu.appendChild(all);
5593
+ }
5594
+ for (const kid of kids) {
5595
+ const b = document.createElement("button");
5596
+ b.className = "tm-item";
5597
+ b.textContent = "✕ " + (kid.nameEl ? kid.nameEl.textContent : kid.sessionId.slice(0, 8));
5598
+ b.addEventListener("click", (e) => { // never onclick=: the CSP nonce
5599
+ e.stopPropagation(); // does not cover inline handlers
5600
+ closeTabMenu();
5601
+ sendTo(kid, { type: "set-parent", parent: null });
5602
+ });
5603
+ tabMenu.appendChild(b);
5604
+ }
5605
+ tabMenu.hidden = false;
5606
+ tabMenuOpenedAt = Date.now();
5607
+ }
5608
+
5521
5609
  function openTabMenu(tab, x, y) {
5522
5610
  tabMenu.replaceChildren();
5523
5611
  // Header: WHO this agent is. The profile is what qualifies it (role,
@@ -5586,6 +5674,13 @@
5586
5674
  tab.parent ? "🔗 Detach from " + parentLabel(tab.parent) : "🔗 Report to…",
5587
5675
  () => (tab.parent ? sendTo(tab, { type: "set-parent", parent: null }) : openParentPicker(tab)),
5588
5676
  ]);
5677
+ // The parent-side half: the agents reporting to THIS one, detachable from
5678
+ // here — so you can cut a link without hunting down the child's own tab.
5679
+ const kids = childTabsOf(tab);
5680
+ if (kids.length) items.push([
5681
+ "🔗 Children reporting here (" + kids.length + ")…",
5682
+ () => openChildrenDetacher(tab),
5683
+ ]);
5589
5684
  }
5590
5685
  // The main channel is the environment's home base — it can't be closed.
5591
5686
  if (!tab.isMain) items.push(["✕ Close agent", () => closeTab(tab)]);
@@ -6915,6 +7010,9 @@
6915
7010
  }
6916
7011
  }
6917
7012
  lastChannelIds = current;
7013
+ // Parents are re-applied above from the registry; refresh every 🔗 once the
7014
+ // pass has settled, so a link made on another device lights up here too.
7015
+ refreshAllLinkBadges();
6918
7016
  }
6919
7017
 
6920
7018
  // Is the server currently starting this instance's lead agent? Never inferred
@@ -10084,6 +10182,7 @@
10084
10182
  // Broadcast to every client, like `profile`: attaching from one tab
10085
10183
  // must update the others without a reload.
10086
10184
  t.parent = msg.parent;
10185
+ refreshAllLinkBadges(); // moves the 🔗 on both ends of the link
10087
10186
  break;
10088
10187
  case "tokens":
10089
10188
  t.tokens = msg.tokens;
@@ -11565,7 +11664,8 @@
11565
11664
  actions.append(actionBtn("s-edit", "🕘", "Audit log for this secret — who wrote it and which agents received it", () => openSecretAudit(k)));
11566
11665
  if (!ro) {
11567
11666
  actions.append(
11568
- actionBtn("s-edit", "✎", "Update this secret's value / the profiles it feeds", () => startEditSecret(k, grouped && sec.ownerGroup != null ? String(sec.ownerGroup) : null)),
11667
+ actionBtn("s-edit", "✎", "Update this secret's value / the profiles it feeds", () =>
11668
+ grouped ? startInlineEdit(li, sec) : startEditSecret(k, null)),
11569
11669
  actionBtn("s-del", "✕", "Remove from vault", async () => {
11570
11670
  // The row's OWNER group, not the panel's write target (see secretControls).
11571
11671
  const g = grouped && sec.ownerGroup != null ? String(sec.ownerGroup) : secretWriteGroup();
@@ -11581,10 +11681,60 @@
11581
11681
  if (grouped) {
11582
11682
  const line = window.auditLine ? window.auditLine(sec) : "";
11583
11683
  if (line) { const m = document.createElement("div"); m.className = "sec-meta"; m.textContent = line; li.appendChild(m); }
11684
+ if (!ro) li.appendChild(secretValueLine(li, sec));
11584
11685
  if (!ro) li.appendChild(secretControls(sec));
11585
11686
  }
11586
11687
  return li;
11587
11688
  }
11689
+ /** The value line of an own secret's card. The vault is write-only — the page
11690
+ * never receives a value, not even its length — so this is a FIXED mask, the
11691
+ * same for every secret: a length-shaped one would need the server to send
11692
+ * the length, which tells an onlooker how long a credential is. */
11693
+ function secretValueLine(li, sec) {
11694
+ const row = document.createElement("div"); row.className = "sec-val";
11695
+ const mask = document.createElement("span"); mask.className = "sec-mask"; mask.textContent = "••••••••";
11696
+ mask.title = "Value hidden — the vault is write-only. ✎ to replace it.";
11697
+ row.appendChild(mask);
11698
+ return row;
11699
+ }
11700
+ /** ✎ on a card: replace the value right there, instead of loading the form at
11701
+ * the other end of the panel. Writes to the secret's OWNER group (see
11702
+ * startEditSecret for why not the panel's target). Profiles and sharing stay
11703
+ * on the card's own chips. */
11704
+ function startInlineEdit(li, sec) {
11705
+ const row = li.querySelector(".sec-val");
11706
+ if (!row || row.querySelector("input")) return;
11707
+ const input = document.createElement("input");
11708
+ input.type = "password"; input.placeholder = "new value";
11709
+ input.autocomplete = "new-password"; input.spellcheck = false;
11710
+ input.setAttribute("aria-label", "New value for " + sec.name);
11711
+ const save = document.createElement("button"); save.type = "button"; save.className = "sec-val-save"; save.textContent = "Update";
11712
+ const cancel = document.createElement("button"); cancel.type = "button"; cancel.textContent = "Cancel";
11713
+ const status = document.createElement("span"); status.className = "sec-status"; status.setAttribute("role", "status");
11714
+ const close = () => row.replaceWith(secretValueLine(li, sec));
11715
+ const submit = async () => {
11716
+ const value = input.value;
11717
+ if (!value) { input.focus(); return; }
11718
+ save.disabled = true; status.className = "sec-status"; status.textContent = "Saving…";
11719
+ const body = { name: sec.name, value, overwrite: true, ...(sec.ownerGroup != null ? { group: String(sec.ownerGroup) } : {}) };
11720
+ let err;
11721
+ try {
11722
+ err = await vaultError(await fetch("/secrets", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
11723
+ } catch (e) { err = "network error: " + (e && e.message || e); }
11724
+ if (err) { status.className = "sec-status err"; status.textContent = "Not saved: " + err; save.disabled = false; return; }
11725
+ showVaultError("");
11726
+ await loadVault(); renderSecrets();
11727
+ offerReload(sec.name); // the new value reaches an agent only at spawn
11728
+ };
11729
+ save.addEventListener("click", submit);
11730
+ cancel.addEventListener("click", close);
11731
+ input.addEventListener("keydown", (e) => {
11732
+ if (e.key === "Enter") { e.preventDefault(); submit(); }
11733
+ else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); close(); }
11734
+ });
11735
+ row.replaceChildren(input, save, cancel, status);
11736
+ input.focus();
11737
+ }
11588
11738
  /** Read a refused vault write's message: the server answers `{error}` JSON;
11589
11739
  * a proxy may answer HTML, so fall back to the status line. */
11590
11740
  async function vaultError(r) {
@@ -11761,6 +11911,7 @@
11761
11911
  $("secretVal").value = ""; $("secretVal").placeholder = "value";
11762
11912
  $("secretSubmit").textContent = "Add";
11763
11913
  $("secretEditCancel").hidden = true;
11914
+ $("secretAttach").dataset.editing = "";
11764
11915
  renderSecretProfiles(new Set());
11765
11916
  }
11766
11917
  function startEditSecret(name, ownerGroup = null) {
@@ -11773,6 +11924,9 @@
11773
11924
  $("secretVal").value = ""; $("secretVal").placeholder = "new value (blank = keep)";
11774
11925
  $("secretSubmit").textContent = "Update";
11775
11926
  $("secretEditCancel").hidden = false;
11927
+ // Grouped mode: an existing secret's profiles live on its card's chips, so
11928
+ // the form hides its own ticks rather than offer a second, divergent copy.
11929
+ $("secretAttach").dataset.editing = "1";
11776
11930
  const users = window.secretUsers ? window.secretUsers(profileCache, name) : [];
11777
11931
  renderSecretProfiles(new Set(users));
11778
11932
  $("secretVal").focus();
@@ -12062,7 +12216,16 @@
12062
12216
  $("secretsOverlay").hidden = false;
12063
12217
  $("secretKey").focus();
12064
12218
  }
12065
- $("secretsBtn").addEventListener("click", () => openSecretsPanel(null));
12219
+ // Opened on the group on screen: Personal or a private group as itself, any
12220
+ // public group — the Main view included — as the "Public" bucket (renderSecrets'
12221
+ // `toOption` folds a public id into it). A phone (no rail) has no view and keeps
12222
+ // the panel's own default.
12223
+ const secretsGroupOnScreen = () => {
12224
+ if (!railShown()) return null;
12225
+ const v = viewGroupId();
12226
+ return v == null || v === COMMONS_GROUP_ID ? PUBLIC_BUCKET : String(v);
12227
+ };
12228
+ $("secretsBtn").addEventListener("click", () => openSecretsPanel(secretsGroupOnScreen()));
12066
12229
  // ── Member picker: avatar toggle grid ───────────────────────────────
12067
12230
  // Shared by the create-group form and the group panel. Names go through
12068
12231
  // textContent (invariant 13); the only innerHTML is the constant check SVG.
@@ -13351,8 +13514,11 @@
13351
13514
  // because a human at the vault is acting deliberately; the flag only stops an
13352
13515
  // AGENT replacing a credential silently).
13353
13516
  const keepValue = editingSecret && value === "";
13517
+ const isNew = !editingSecret;
13518
+ let writtenGroup = null;
13354
13519
  if (!keepValue) {
13355
13520
  const body = editingSecret && editingSecretGroup ? { name, value, overwrite: true, group: editingSecretGroup } : withSecretGroup({ name, value, overwrite: true });
13521
+ writtenGroup = body.group ?? null;
13356
13522
  const r = await fetch("/secrets", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
13357
13523
  const err = await vaultError(r);
13358
13524
  // Refused: say so and keep the form filled, rather than clearing it as if saved.
@@ -13362,6 +13528,14 @@
13362
13528
  // Grouped mode binds profiles per row (PUT /secrets/profiles) and hides the
13363
13529
  // ticks: syncing here would read an empty selection and detach everything.
13364
13530
  if (window.secretsPanelMode(vaultGroups) === "flat") await syncSecretToProfiles(name, wanted); // refreshes profileCache
13531
+ else if (isNew && wanted.length) {
13532
+ // Grouped mode: a new secret is bound to the ticked profiles in its group
13533
+ // right away (the same route as the card's chips), so creating one no
13534
+ // longer means "add, then find its card, tick, Save".
13535
+ const e = await vaultError(await fetch("/secrets/profiles", { method: "PUT", headers: { "Content-Type": "application/json" },
13536
+ body: JSON.stringify({ name, profiles: wanted, ...(writtenGroup ? { group: writtenGroup } : {}) }) }));
13537
+ if (e) showVaultError(name + " was saved, but not attached to its profiles: " + e);
13538
+ }
13365
13539
  await loadVault(); renderSecrets();
13366
13540
  offerReload(name); // propose reloading the live agents that now feed on it
13367
13541
  resetSecretForm();
@@ -14000,7 +14174,7 @@
14000
14174
  }
14001
14175
  $("profToSecrets").addEventListener("click", () => {
14002
14176
  $("profilesOverlay").hidden = true;
14003
- openSecretsPanel(null);
14177
+ openSecretsPanel(secretsGroupOnScreen());
14004
14178
  });
14005
14179
  const READONLY_DENY = ["Bash(git commit:*)","Bash(git push:*)","Bash(git add:*)","Bash(git reset:*)","Bash(git rebase:*)","Bash(git merge:*)","Bash(git checkout:*)"];
14006
14180
  /** The typed patterns, one per line, without the empty ones. */