shadok-ai 0.19.58 → 0.19.59

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
@@ -392,8 +392,15 @@ Enter to skip; you can add it later from the web UI).
392
392
  - **Provide the variable an agent asks for** — when an agent names a missing
393
393
  credential in code (`` `HUBSPOT_TOKEN missing from the environment` ``), a
394
394
  **+** sits right after it: one click opens the secret vault with the name
395
- filled in and the agent's profile ticked, so you only paste the value (then
396
- reload the agent when offered — a value reaches a process at spawn). Only
395
+ filled in and the agent's profile ticked, so you only paste the value — and
396
+ on *Add* **that agent is reloaded for you**, since a value only reaches a
397
+ process at spawn. Three cases it declines to do silently: an agent **mid-turn**
398
+ is offered instead of cut short (a reload is a respawn: the history is kept,
399
+ a running turn is not), an agent that **no binding feeds** is named so you can
400
+ tick a profile rather than restart it for nothing, and a **stopped** one needs
401
+ nothing — it reads the vault when it next launches. Any other live agent on a
402
+ profile that receives the secret is still offered, with a count of those
403
+ mid-turn. Only
397
404
  names that look like a credential or a connection setting get one (`…_TOKEN`,
398
405
  `…_KEY`, `…_URL`, `…_ID`…), never `NODE_ENV` nor shadok's own `SHADOK_*`.
399
406
  - **`/` commands** — type `/` in the composer and a menu lists the Skill
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.19.58",
3
+ "version": "0.19.59",
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
@@ -4612,7 +4612,7 @@
4612
4612
  defaultAgentName,
4613
4613
  hasReadonlyPreset,
4614
4614
  applyReadonlyPreset, isManagedProfile, profileSaveBody, secretUsers, secretDeleteConfirmText } from "/profile-card.js?v=__ASSET_V__";
4615
- import { secretsPanelMode, secretSections, keyGroups, shareTargets, auditLine, panelGroupOptions, publicWriteTarget, secretChipPick } from "/secrets-panel.js?v=__ASSET_V__";
4615
+ import { secretsPanelMode, secretSections, keyGroups, shareTargets, auditLine, panelGroupOptions, publicWriteTarget, secretChipPick, secretReceivers, plusReloadPlan } from "/secrets-panel.js?v=__ASSET_V__";
4616
4616
  import { notifyState, BLINK_MS } from "/notify.js?v=__ASSET_V__";
4617
4617
  import { echoAuthor, isOwnPrompt } from "/echo-author.js?v=__ASSET_V__";
4618
4618
  import { dialPos, dialColor, dialTitle } from "/gauge-dial.js?v=__ASSET_V__";
@@ -4719,6 +4719,8 @@
4719
4719
  window.keyGroups = keyGroups;
4720
4720
  window.shareTargets = shareTargets;
4721
4721
  window.secretChipPick = secretChipPick;
4722
+ window.secretReceivers = secretReceivers;
4723
+ window.plusReloadPlan = plusReloadPlan;
4722
4724
  window.auditLine = auditLine;
4723
4725
  window.profileSaveBody = profileSaveBody;
4724
4726
  window.isManagedProfile = isManagedProfile;
@@ -4882,6 +4884,12 @@
4882
4884
  // GRANT something: before the module lands, every click resolves to the set
4883
4885
  // already confirmed — the tick springs back and nothing widens.
4884
4886
  secretChipPick: (current) => (Array.isArray(current) ? current : []),
4887
+ // Before the module lands: no known receiver and nothing automatic. The
4888
+ // panel then offers nothing rather than restarting an agent on a guess —
4889
+ // and `reloadCandidates` is only ever reached from a click, by which time
4890
+ // the module is long loaded.
4891
+ secretReceivers: () => ({ profiles: [], any: false }),
4892
+ plusReloadPlan: () => ({ action: "none" }),
4885
4893
  extractLiveText: () => "",
4886
4894
  livePreviewDecision: () => null,
4887
4895
  echoAuthor: () => "",
@@ -12796,6 +12804,10 @@
12796
12804
  let vaultSecrets = []; // the server's tagged list: {name, source, ownerGroup?, audit…}
12797
12805
  let vaultGroups = []; // GET /groups — decides flat vs grouped
12798
12806
  let panelGroup = null; // the group the panel is scoped to (null = the caller's own view)
12807
+ // The agent whose "+" opened the panel, or null (opened by hand). Read ONCE,
12808
+ // by `settleSecretWrite`: it decides whether writing the secret also reloads
12809
+ // that agent, the only way a value reaches a running process.
12810
+ let envAskTab = null;
12799
12811
  async function loadVault() {
12800
12812
  try {
12801
12813
  const [v, g] = await Promise.all([
@@ -12861,10 +12873,19 @@
12861
12873
  }
12862
12874
  // Who receives it. Bridge guard (invariant 10): no module, no mention,
12863
12875
  // rather than an exception that would empty the list.
12864
- const users = !ro && window.secretUsers ? window.secretUsers(profileCache, k) : null;
12865
- if (users && !grouped) {
12876
+ // Both ends of the link (`secretReceivers`), or an "Any profile" binding —
12877
+ // which no profile's own list carries — would read as "no profile uses it"
12878
+ // while every agent receives it.
12879
+ const recv = !ro && window.secretReceivers ? window.secretReceivers(profileCache, vaultSecrets, k) : null;
12880
+ const users = recv ? recv.profiles : null;
12881
+ if (recv && !grouped) {
12866
12882
  const tag = document.createElement("span");
12867
- if (users.length) {
12883
+ if (recv.any) {
12884
+ tag.className = "sec-users";
12885
+ tag.textContent = "→ any profile";
12886
+ tag.title = "Injected as an environment variable into every agent that can read it, whatever its profile"
12887
+ + (users.length ? " (and listed on: " + users.join(", ") + ")" : "");
12888
+ } else if (users.length) {
12868
12889
  tag.className = "sec-users";
12869
12890
  tag.textContent = "→ " + users.join(", ");
12870
12891
  tag.title = users.length === 1
@@ -12943,7 +12964,7 @@
12943
12964
  if (err) { status.className = "sec-status err"; status.textContent = "Not saved: " + err; save.disabled = false; return; }
12944
12965
  showVaultError("");
12945
12966
  await loadVault(); renderSecrets();
12946
- offerReload(sec.name); // the new value reaches an agent only at spawn
12967
+ settleSecretWrite(sec.name); // the new value reaches an agent only at spawn
12947
12968
  };
12948
12969
  save.addEventListener("click", submit);
12949
12970
  cancel.addEventListener("click", close);
@@ -13183,26 +13204,85 @@
13183
13204
  if (changed.length) await loadProfilesInto();
13184
13205
  return changed;
13185
13206
  }
13186
- /** Offer to reload the LIVE agents whose profile now feeds this secret — the
13187
- * value only reaches a process at spawn, so a running one needs a respawn. */
13188
- function offerReload(secretName) {
13189
- const users = new Set(window.secretUsers ? window.secretUsers(profileCache, secretName) : []);
13190
- // Only LIVE agents: a stopped one will get the value when it next launches.
13191
- const agents = tabs.filter((t) => users.has(t.profile) && t.ws && t.ws.readyState === WebSocket.OPEN);
13207
+ /** The live agents that would pick this secret up on a respawn, from both
13208
+ * ends of the link (`secretReceivers`) — a value only reaches a process at
13209
+ * spawn. `skip` leaves out one already being reloaded. */
13210
+ function reloadCandidates(secretName, skip) {
13211
+ const r = window.secretReceivers(profileCache, vaultSecrets, secretName);
13212
+ return tabs.filter((t) =>
13213
+ t !== skip && t.ws && t.ws.readyState === WebSocket.OPEN &&
13214
+ (r.any || (t.profile && r.profiles.includes(t.profile))));
13215
+ }
13216
+ /** The banner under the vault form: what just happened (`note`), and an offer
13217
+ * to reload the agents that now feed on this secret. ONE span, because
13218
+ * `.sec-reload` is a flex row whose span takes the width. */
13219
+ function offerReload(secretName, note, skip) {
13220
+ const agents = reloadCandidates(secretName, skip);
13192
13221
  const box = $("secretsReload");
13193
13222
  box.replaceChildren();
13194
- if (!agents.length) { box.hidden = true; return; }
13195
- const txt = document.createElement("span");
13196
- txt.textContent =
13197
- agents.length === 1
13223
+ const parts = note ? [note] : [];
13224
+ if (agents.length) {
13225
+ const working = agents.filter((t) => t.status === "busy").length;
13226
+ parts.push(agents.length === 1
13198
13227
  ? `1 running agent (${agents[0].nameEl.textContent}) uses “${secretName}”. Reload it to pick up the new value?`
13199
- : `${agents.length} running agents use “${secretName}”. Reload them to pick up the new value?`;
13200
- const go = document.createElement("button");
13201
- go.type = "button"; go.textContent = "Reload " + (agents.length === 1 ? "it" : "all");
13202
- go.addEventListener("click", () => { agents.forEach(reloadTab); box.hidden = true; });
13203
- box.append(txt, go);
13228
+ : `${agents.length} running agents use “${secretName}”. Reload them to pick up the new value?`);
13229
+ // Reloading is a respawn: history is kept, a turn in flight is not. The
13230
+ // profile switch says the same thing rather than forbidding it — catching
13231
+ // an agent mid-track is a use case.
13232
+ if (working) parts.push(working === agents.length
13233
+ ? (working === 1 ? "It is mid-turn: reloading cuts that turn short." : "They are mid-turn: reloading cuts those turns short.")
13234
+ : `${working} of them ${working === 1 ? "is" : "are"} mid-turn: reloading cuts ${working === 1 ? "that turn" : "those turns"} short.`);
13235
+ }
13236
+ if (!parts.length) { box.hidden = true; return; }
13237
+ const txt = document.createElement("span");
13238
+ txt.textContent = parts.join(" ");
13239
+ box.appendChild(txt);
13240
+ if (agents.length) {
13241
+ const go = document.createElement("button");
13242
+ go.type = "button"; go.textContent = "Reload " + (agents.length === 1 ? "it" : "all");
13243
+ go.addEventListener("click", () => { agents.forEach(reloadTab); box.hidden = true; });
13244
+ box.appendChild(go);
13245
+ }
13204
13246
  box.hidden = false;
13205
13247
  }
13248
+ /**
13249
+ * After a secret is written from the form: the agent that asked for it
13250
+ * through a "+" is reloaded on the spot, since that is the only way a value
13251
+ * reaches a running process, and the click already told us which agent and
13252
+ * which name. Everything the plan refuses to do automatically falls back to
13253
+ * the offer — `plusReloadPlan` (pure) carries the why.
13254
+ *
13255
+ * `envAskTab` is consumed here, once: the panel stays open after an Add, and
13256
+ * a second secret typed into it has nothing to do with the agent that asked
13257
+ * for the first.
13258
+ */
13259
+ function settleSecretWrite(secretName) {
13260
+ const tab = envAskTab;
13261
+ envAskTab = null;
13262
+ const receivers = window.secretReceivers(profileCache, vaultSecrets, secretName);
13263
+ const plan = window.plusReloadPlan(
13264
+ tab ? { profile: tab.profile, live: !!(tab.ws && tab.ws.readyState === WebSocket.OPEN), busy: tab.status === "busy" } : null,
13265
+ receivers,
13266
+ );
13267
+ const who = tab && tab.nameEl ? tab.nameEl.textContent : "the agent";
13268
+ if (plan.action === "reload") {
13269
+ reloadTab(tab); // writes its own line in the agent's thread
13270
+ offerReload(secretName, `Reloaded ${who} — it now has “${secretName}” in its environment.`, tab);
13271
+ return;
13272
+ }
13273
+ if (plan.action === "unbound") {
13274
+ // No binding feeds it, so a respawn would change nothing: name the fix
13275
+ // instead of restarting the agent for free. Not "tick the box below":
13276
+ // where that tick lives differs by mode (the form's ticks in flat mode,
13277
+ // the card's chips in grouped), and pointing at the wrong widget is worse
13278
+ // than naming the profile.
13279
+ offerReload(secretName, tab && tab.profile
13280
+ ? `${who} runs “${tab.profile}”, which does not receive “${secretName}” — attach it to that profile, then reload.`
13281
+ : `${who} has no profile, so only “Any profile” would reach it.`, null);
13282
+ return;
13283
+ }
13284
+ offerReload(secretName);
13285
+ }
13206
13286
  // profileCache feeds the "no profile uses it" warning: it must be fresh when
13207
13287
  // the panel opens, or we would show a stale diagnosis.
13208
13288
  // ── Connected accounts (LinkedIn, Google) ──────────────────────────
@@ -13540,6 +13620,7 @@
13540
13620
  document.addEventListener("visibilitychange", refreshCaIfOpen);
13541
13621
 
13542
13622
  async function openSecretsPanel(groupId) {
13623
+ envAskTab = null; // opened by hand: no agent is waiting on this write
13543
13624
  panelGroup = groupId == null ? null : String(groupId);
13544
13625
  showCaError("");
13545
13626
  loadConnectedAccounts();
@@ -13714,6 +13795,7 @@
13714
13795
  * value actually reaches it, the cursor on the value. Saving then goes through
13715
13796
  * the ordinary submit — and its reload offer, since a value lands at spawn. */
13716
13797
  async function openSecretFor(tab, name) {
13798
+ envAskTab = tab || null;
13717
13799
  await Promise.all([loadVault(), loadProfilesInto()]);
13718
13800
  renderSecrets();
13719
13801
  $("secretsReload").hidden = true;
@@ -14878,7 +14960,7 @@
14878
14960
  if (e) showVaultError(name + " was saved, but not attached to its profiles: " + e);
14879
14961
  }
14880
14962
  await loadVault(); renderSecrets();
14881
- offerReload(name); // propose reloading the live agents that now feed on it
14963
+ settleSecretWrite(name); // reload the agent that asked; offer the others
14882
14964
  resetSecretForm();
14883
14965
  $("secretKey").focus();
14884
14966
  });
@@ -163,3 +163,65 @@ export function secretChipPick(current, key, on, exclusive = null) {
163
163
  if (exclusive != null && k === String(exclusive)) return [k];
164
164
  return [...(exclusive != null ? kept.filter((v) => v !== String(exclusive)) : kept), k].sort();
165
165
  }
166
+
167
+ /**
168
+ * The profiles that RECEIVE a secret, read from BOTH ends of the link — plus
169
+ * `any`, the `ANY_PROFILE` wildcard, which reaches an agent whatever its
170
+ * profile (even one with none).
171
+ *
172
+ * The link is writable from either side and stored on the side it was written:
173
+ * a profile's `secrets` list (`PUT /profiles`, what the flat form writes) and a
174
+ * secret's `profiles` list (`PUT /secrets/profiles`, what the panel's chips and
175
+ * the grouped form write). `secretsForProfile` merges both server-side at spawn,
176
+ * so anything that asks "who receives this secret" must merge both too — asking
177
+ * one side alone answers "nobody" for every binding made from the other, and a
178
+ * caller that treats an empty answer as "no one to tell" then says nothing at
179
+ * all. That is exactly how the reload offer went silent on a grouped instance.
180
+ *
181
+ * The vault side is only known for a secret the caller may edit (`GET /secrets`
182
+ * sends `profiles` for an own secret, and for Main's to whoever may write Main);
183
+ * for a shared or read-only tier the profile side is all we have. And an own
184
+ * secret SHADOWS a Main one of the same name per group, which this union
185
+ * ignores: a receiver list is used to OFFER a reload, where naming one agent
186
+ * too many costs a respawn that keeps its history.
187
+ */
188
+ export function secretReceivers(profiles, vaultSecrets, name) {
189
+ const out = new Set();
190
+ let any = false;
191
+ const n = String(name ?? "");
192
+ for (const p of Array.isArray(profiles) ? profiles : [])
193
+ if (p && typeof p.name === "string" && (p.secrets || []).includes(n)) out.add(p.name);
194
+ for (const s of Array.isArray(vaultSecrets) ? vaultSecrets : []) {
195
+ if (!s || s.name !== n || !Array.isArray(s.profiles)) continue;
196
+ for (const p of s.profiles) {
197
+ if (String(p) === ANY_PROFILE) any = true;
198
+ else out.add(String(p));
199
+ }
200
+ }
201
+ return { profiles: [...out].sort(), any };
202
+ }
203
+
204
+ /**
205
+ * What the "+" beside an agent's `MISSING_TOKEN` should do once the secret is
206
+ * written: `reload` the agent that asked, `offer` it instead, `unbound` (it
207
+ * receives nothing, so there is nothing to pick up) or `none`.
208
+ *
209
+ * `agent` is `{ profile, live, busy }` — null when the panel was not opened by
210
+ * a "+", which is why a later Add never restarts a bystander.
211
+ *
212
+ * Order is the point. "Does it receive it?" comes first: a reload cannot help
213
+ * an agent no binding feeds, and saying so is more use than a respawn. A turn
214
+ * in flight is never cut short on the cockpit's own initiative — `restart`
215
+ * kills the process (invariant 23) and no `busy` check stands in its way — so a
216
+ * working agent falls back to the offer, where a person decides. And a dead
217
+ * agent needs nothing: it reads the vault at its next launch.
218
+ */
219
+ export function plusReloadPlan(agent, receivers) {
220
+ if (!agent) return { action: "none" };
221
+ const r = receivers || {};
222
+ const named = Array.isArray(r.profiles) ? r.profiles : [];
223
+ if (!r.any && !(agent.profile && named.includes(agent.profile))) return { action: "unbound" };
224
+ if (!agent.live) return { action: "none" };
225
+ if (agent.busy) return { action: "offer" };
226
+ return { action: "reload" };
227
+ }