shadok-ai 0.20.41 → 0.20.42

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
@@ -1555,7 +1555,11 @@ carries a **scope**, chosen when you invite:
1555
1555
  agent is judged on its NAME exactly like a person, and an admin has no override
1556
1556
  there, so it reaches a Private group the way a person does: a member of that
1557
1557
  group adds it from the group's **gear ▸ members** picker, where invited agents
1558
- appear beside the accounts, marked `agent`. Added, it is a full member — it sees
1558
+ appear beside the accounts, marked `agent`. That picker is a DRAFT until you
1559
+ press **Save members**: ticking a tile changes nothing on the server, the tile
1560
+ is outlined and labelled *add* or *remove* while it waits, the footer counts
1561
+ what is pending, and closing the panel with changes left asks before throwing
1562
+ them away. Added, it is a full member — it sees
1559
1563
  and drives that group's agents, starts more **under the group's own Unix user**,
1560
1564
  and reads *and writes* the group's secrets — but it can never change the group or
1561
1565
  who belongs to it (every group write is browser-only). A `restricted`-scope agent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.20.41",
3
+ "version": "0.20.42",
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",
@@ -123,3 +123,44 @@ export function groupMoveRefusal(from, to) {
123
123
  return `An agent can’t be moved into ${label(to)}: that space is walled off (its own system account, its own files). Create the agent from inside it instead.`;
124
124
  return null;
125
125
  }
126
+
127
+ /**
128
+ * What a member grid's current ticks would CHANGE, against the roster the
129
+ * server holds. Pure, so the panel and test/group-nav.test.ts share it.
130
+ *
131
+ * The owner/self tile is never in either list: it is locked and implicit, and
132
+ * returning it would make the panel re-POST an add of the owner on every save.
133
+ * Callers pass a `current` that already excludes them (`readMemberGrid` does
134
+ * the same on the other side).
135
+ */
136
+ export function memberDiff(current, now) {
137
+ const has = (list, n) => (Array.isArray(list) ? list : []).includes(n);
138
+ const a = Array.isArray(now) ? now : [];
139
+ const b = Array.isArray(current) ? current : [];
140
+ return { add: a.filter((n) => !has(b, n)), remove: b.filter((n) => !has(a, n)) };
141
+ }
142
+
143
+ /** True when a member grid holds edits the server has not been told about. */
144
+ export function memberDiffPending(d) {
145
+ return !!d && (d.add.length > 0 || d.remove.length > 0);
146
+ }
147
+
148
+ /**
149
+ * The pending change, in words, for the panel's footer — "" when there is none.
150
+ *
151
+ * It exists because a Save button that merely lights up is easy to miss: an
152
+ * operator ticked tiles, did not see the button at the bottom of a scrolling
153
+ * list, and closed the panel believing membership had changed. Saying WHAT is
154
+ * waiting, next to the button that commits it, is what makes the pending state
155
+ * legible rather than inferable.
156
+ *
157
+ * Counts and not names: a roster can be long, and the names are on the tiles.
158
+ */
159
+ export function memberDiffLabel(d) {
160
+ if (!memberDiffPending(d)) return "";
161
+ const n = (k, one, many) => `${k} ${k === 1 ? one : many}`;
162
+ const parts = [];
163
+ if (d.add.length) parts.push(n(d.add.length, "person to add", "people to add"));
164
+ if (d.remove.length) parts.push(n(d.remove.length, "person to remove", "people to remove"));
165
+ return parts.join(" · ") + " — not saved yet";
166
+ }
package/public/index.html CHANGED
@@ -1306,6 +1306,15 @@
1306
1306
  .member-tile { border: 0; background: none; padding: 6px 2px 4px; border-radius: 10px; cursor: pointer; color: inherit; font: inherit;
1307
1307
  display: flex; flex-direction: column; align-items: center; gap: 7px; transition: background .12s; }
1308
1308
  .member-tile:hover { background: var(--bg-inset); }
1309
+ /* A tile whose tick is NOT yet saved. The pressed state alone says "member",
1310
+ which is exactly what an unsaved change is not — so a pending tile is
1311
+ outlined and labelled, and the footer counts them. */
1312
+ .member-tile[data-pending] { background: var(--bg-inset); box-shadow: inset 0 0 0 1px var(--amber); }
1313
+ .member-tile[data-pending] .member-nm { color: var(--amber); }
1314
+ .member-tile[data-pending]::after {
1315
+ content: attr(data-pending); font-size: 10px; letter-spacing: .04em;
1316
+ text-transform: uppercase; color: var(--amber);
1317
+ }
1309
1318
  .member-av { position: relative; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
1310
1319
  font-weight: 600; font-size: 18px; color: #fff; box-shadow: inset 0 0 0 2px transparent;
1311
1320
  transition: box-shadow .12s, filter .12s; filter: grayscale(.35) brightness(.82); }
@@ -4016,6 +4025,10 @@
4016
4025
  <button id="groupPanelClose" title="Close">✕</button>
4017
4026
  </div>
4018
4027
  <div class="modal-body" id="groupPanelBody"></div>
4028
+ <!-- OUTSIDE the scrolling body on purpose: the Save button used to be
4029
+ appended into the member grid, so on a long roster it scrolled out of
4030
+ sight and the panel looked as if ticking a tile was the whole act. -->
4031
+ <div class="modal-foot" id="groupPanelFoot" hidden></div>
4019
4032
  </div>
4020
4033
  </div>
4021
4034
 
@@ -4942,7 +4955,7 @@
4942
4955
  window.buildRoomMessageLink = buildRoomMessageLink;
4943
4956
  window.parseMessageLink = parseMessageLink;
4944
4957
  window.samePrompt = samePrompt;
4945
- import { GROUP_ICONS, UNGROUPED, randomGroupIcon, resolveGroupView, groupMood, cleanGroupIcon, reconcileTabGroup, groupIsDirty, focusTarget, groupMoveRefusal } from "/group-nav.js?v=__ASSET_V__";
4958
+ import { GROUP_ICONS, UNGROUPED, randomGroupIcon, resolveGroupView, groupMood, cleanGroupIcon, reconcileTabGroup, groupIsDirty, focusTarget, groupMoveRefusal, memberDiff, memberDiffLabel, memberDiffPending } from "/group-nav.js?v=__ASSET_V__";
4946
4959
  window.GROUP_ICONS = GROUP_ICONS;
4947
4960
  window.UNGROUPED = UNGROUPED;
4948
4961
  window.randomGroupIcon = randomGroupIcon;
@@ -4953,6 +4966,9 @@
4953
4966
  window.groupIsDirty = groupIsDirty;
4954
4967
  window.focusTarget = focusTarget;
4955
4968
  window.groupMoveRefusal = groupMoveRefusal;
4969
+ window.memberDiff = memberDiff;
4970
+ window.memberDiffLabel = memberDiffLabel;
4971
+ window.memberDiffPending = memberDiffPending;
4956
4972
  import { searchEmoji, looksLikeEmoji } from "/emoji-search.js?v=__ASSET_V__";
4957
4973
  import { newFolderId, canMoveFolder, folderChildren, effectiveFolder, removeFolder, levelOrder, anchorsFromOrder } from "/agent-folders.js?v=__ASSET_V__";
4958
4974
  window.newFolderId = newFolderId;
@@ -5318,6 +5334,14 @@
5318
5334
  // A drop is a user gesture, long after the module lands; allowing it here
5319
5335
  // costs nothing — the server enforces the same rule (src/groups.ts).
5320
5336
  groupMoveRefusal: () => null,
5337
+ // The group panel is opened by a click, long after the module lands — but
5338
+ // the rule is the rule (invariant 10), and the stub's values are the safe
5339
+ // ones: no pending change, so Save stays disabled and the close guard has
5340
+ // nothing to protect. A dead panel beats a thrown exception that would stop
5341
+ // the grid from drawing at all.
5342
+ memberDiff: () => ({ add: [], remove: [] }),
5343
+ memberDiffPending: () => false,
5344
+ memberDiffLabel: () => "",
5321
5345
  // A group switch is a user click, long after the module lands; the stub
5322
5346
  // mirrors the real "remembered-or-first" so even a race keeps today's
5323
5347
  // top-agent fallback.
@@ -13951,7 +13975,11 @@
13951
13975
  // must change nothing (neither save nor restart).
13952
13976
  if (!$("profConfirmOverlay").hidden) { closeProfConfirm(); e.preventDefault(); return; }
13953
13977
  if (!$("profSwitchOverlay").hidden) { closeProfSwitch(); e.preventDefault(); return; }
13954
- if (!$("groupPanelOverlay").hidden) { $("groupPanelOverlay").hidden = true; e.preventDefault(); return; }
13978
+ // Escape goes through the same guard as the ✕ and the backdrop: it is the
13979
+ // fastest way to lose a roster edit, so it must not be the one door that
13980
+ // does it without asking. `preventDefault` either way — the key was handled,
13981
+ // whether the person then kept the panel open or not.
13982
+ if (!$("groupPanelOverlay").hidden) { closeGroupPanel(); e.preventDefault(); return; }
13955
13983
  if (!$("secretsOverlay").hidden) { $("secretsOverlay").hidden = true; e.preventDefault(); return; }
13956
13984
  if (!$("secAuditOverlay").hidden) { $("secAuditOverlay").hidden = true; e.preventDefault(); return; }
13957
13985
  if (!$("icOverlay").hidden) { $("icOverlay").hidden = true; e.preventDefault(); return; }
@@ -14980,11 +15008,38 @@
14980
15008
  return (me && me.name) || null;
14981
15009
  }
14982
15010
  // BEGIN group-panel
15011
+ /**
15012
+ * Does the open group panel hold member ticks the server has not been told
15013
+ * about? Null when there is nothing to lose (no panel, or not a roster one).
15014
+ *
15015
+ * A roster change is the one edit in this panel that is NOT written as it is
15016
+ * made, so it is the one a close can silently discard — and the ticks look
15017
+ * identical to saved membership while they are pending, which is how someone
15018
+ * walks away believing the roster changed.
15019
+ */
15020
+ let groupPanelPending = null;
15021
+
15022
+ /** Close the group panel, asking first when ticks would be thrown away. */
15023
+ function closeGroupPanel() {
15024
+ if (groupPanelPending && groupPanelPending() &&
15025
+ !confirm("This group's members have unsaved changes.\n\nClose anyway and lose them?")) return false;
15026
+ groupPanelPending = null;
15027
+ $("groupPanelOverlay").hidden = true;
15028
+ return true;
15029
+ }
15030
+
14983
15031
  // Group settings: name + type, and the member list for a Private group only.
14984
15032
  async function openGroupPanel(groupId) {
14985
15033
  const body = $("groupPanelBody");
15034
+ const foot = $("groupPanelFoot");
14986
15035
  const hdr = $("groupPanelTitle");
14987
15036
  $("groupPanelOverlay").hidden = false;
15037
+ // A fresh panel owns nothing yet: cleared here, and only the roster branch
15038
+ // below sets it again. Leaving a stale closure behind would guard a panel
15039
+ // that no longer exists.
15040
+ groupPanelPending = null;
15041
+ foot.textContent = "";
15042
+ foot.hidden = true;
14988
15043
  let g = null;
14989
15044
  try {
14990
15045
  const r = await fetch("/groups");
@@ -15050,15 +15105,34 @@
15050
15105
  const save = document.createElement("button");
15051
15106
  save.type = "button"; save.id = "gpSave"; save.className = "primary";
15052
15107
  save.textContent = "Save members";
15108
+ // The pending count, in words, beside the button that commits it. The
15109
+ // button alone was missable: it sits under the grid, and on a long roster
15110
+ // the body scrolls it away — someone ticked tiles, saw the ticks, closed
15111
+ // the panel and believed the roster had changed. Nothing had been sent.
15112
+ const pending = document.createElement("span");
15113
+ pending.className = "foot-note"; pending.id = "gpPending";
15114
+ pending.setAttribute("role", "status");
15053
15115
  // Self is locked/implicit: never part of the diff.
15054
15116
  const current = members.filter((m) => m !== self);
15055
- const diff = () => {
15056
- const now = readMemberGrid(grid);
15057
- return { add: now.filter((n) => !current.includes(n)), remove: current.filter((n) => !now.includes(n)) };
15117
+ const diff = () => window.memberDiff(current, readMemberGrid(grid));
15118
+ const refresh = () => {
15119
+ const d = diff();
15120
+ save.disabled = !window.memberDiffPending(d);
15121
+ pending.textContent = window.memberDiffLabel(d);
15122
+ // And on the tiles themselves, so the change is visible where it was
15123
+ // made and not only at the bottom of the panel.
15124
+ for (const tile of grid.querySelectorAll(".member-tile")) {
15125
+ const n = tile.dataset.name;
15126
+ if (d.add.includes(n)) tile.dataset.pending = "add";
15127
+ else if (d.remove.includes(n)) tile.dataset.pending = "remove";
15128
+ else delete tile.dataset.pending;
15129
+ }
15058
15130
  };
15059
- const refresh = () => { const d = diff(); save.disabled = !d.add.length && !d.remove.length; };
15060
15131
  renderMemberGrid(grid, { accounts, selected: current, lockedSelf: self, onChange: refresh, agents });
15061
15132
  refresh();
15133
+ // What the close guards read. Set while this panel is the one open, and
15134
+ // cleared by `openGroupPanel` at the top of every call.
15135
+ groupPanelPending = () => window.memberDiffPending(diff());
15062
15136
  save.addEventListener("click", async () => {
15063
15137
  const d = diff();
15064
15138
  save.disabled = true;
@@ -15073,15 +15147,20 @@
15073
15147
  const i = current.indexOf(n);
15074
15148
  if (i >= 0) current.splice(i, 1);
15075
15149
  }
15150
+ // Saved: nothing is pending any more, so the reopen below must not be
15151
+ // stopped by the guard.
15152
+ groupPanelPending = null;
15076
15153
  return openGroupPanel(groupId);
15077
15154
  });
15078
- body.append(grid, save);
15155
+ body.append(grid);
15156
+ foot.append(pending, save);
15157
+ foot.hidden = false;
15079
15158
  return;
15080
15159
  }
15081
15160
  note("Anyone can see this — it is a label.");
15082
15161
  }
15083
- $("groupPanelClose").addEventListener("click", () => { $("groupPanelOverlay").hidden = true; });
15084
- $("groupPanelOverlay").addEventListener("click", (e) => { if (e.target === $("groupPanelOverlay")) $("groupPanelOverlay").hidden = true; });
15162
+ $("groupPanelClose").addEventListener("click", () => { closeGroupPanel(); });
15163
+ $("groupPanelOverlay").addEventListener("click", (e) => { if (e.target === $("groupPanelOverlay")) closeGroupPanel(); });
15085
15164
  // END group-panel
15086
15165
  /** The vault, opened on ONE name an agent asked for: the name filled in (or the
15087
15166
  * existing secret in edit mode), the asking agent's profile pre-ticked so the