shadok-ai 0.15.12 → 0.15.13

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
@@ -167,11 +167,14 @@ Enter to skip; you can add it later from the web UI).
167
167
  a bot may download at 20 MB; past that you get a clear notice instead of
168
168
  silence.
169
169
  - **Run the command an agent asks you to** — when an agent writes `! cmd` for
170
- you to run (typically because it cannot), a ▶ button under its message runs it
171
- in the agent's shell after a confirmation showing the exact command. It is
172
- refused for anything but your browser, since shell mode sits outside the
173
- agent's guardrails. The command and its output stay in the chat, reload
174
- included — as does one you typed yourself in the terminal view.
170
+ you to run (typically because it cannot), a ▶ run button sits right on that
171
+ command's code block, beside its copy button — so it runs where it was
172
+ written, not in a list below. (An inline `` `! cmd` `` with no block of its
173
+ own still gets a button under the message.) It runs in the agent's shell after
174
+ a confirmation showing the exact command, and is refused for anything but your
175
+ browser, since shell mode sits outside the agent's guardrails. The command and
176
+ its output stay in the chat, reload included — as does one you typed yourself
177
+ in the terminal view.
175
178
  - **Files you hand an agent** — paste or drop a file into the composer (an
176
179
  image, a PDF, a CSV…) and it becomes a **chip** above the text box: a
177
180
  thumbnail for an image, a named tag for anything else, each with a ✕ to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.15.12",
3
+ "version": "0.15.13",
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/bang.js CHANGED
@@ -36,3 +36,20 @@ export function bangCommands(text) {
36
36
  }
37
37
  return out;
38
38
  }
39
+
40
+ /**
41
+ * The single `!` command a fenced code block runs, or null.
42
+ *
43
+ * A code block earns an inline "run" button only when it is EXACTLY one `! cmd`
44
+ * line: shell mode reads one line, so a multi-line block is not one runnable
45
+ * command, and a block of prose is not a command at all. Mirrors the line rule
46
+ * of bangCommands (the `! ` marker, trailing backticks trimmed) so the two can
47
+ * never disagree about what is runnable — the inline button and the fallback
48
+ * row offer the same command, spelled the same way.
49
+ */
50
+ export function blockCommand(codeText) {
51
+ const t = String(codeText == null ? "" : codeText).replace(/\s+$/, "");
52
+ if (!t || /\n/.test(t)) return null;
53
+ const m = /^\s*!\s+(\S.*)$/.exec(t);
54
+ return m ? m[1].replace(/`+$/, "").trim() : null;
55
+ }
package/public/index.html CHANGED
@@ -1051,6 +1051,20 @@
1051
1051
  opacity: 1; color: var(--amber); border-color: var(--amber);
1052
1052
  }
1053
1053
  .bubble.md .md-code-copy.done { opacity: 1; color: var(--ok, #7ac77a); border-color: currentColor; }
1054
+ /* When a fenced block is a `! cmd` the agent asks you to run, a "▶ run" button
1055
+ joins the copy button in a top-right toolbar — so the command is runnable IN
1056
+ the text, beside where the agent wrote it, instead of repeated in a list
1057
+ below. The toolbar is the positioned element; the copy button inside it goes
1058
+ static and keeps its own styling. */
1059
+ .bubble.md .md-code-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 6px; align-items: flex-start; }
1060
+ .bubble.md .md-code-tools .md-code-copy { position: static; top: auto; right: auto; }
1061
+ .bubble.md .md-code-run {
1062
+ padding: 2px 7px; font-family: var(--mono); font-size: 10px; line-height: 1.4;
1063
+ cursor: pointer; background: var(--amber-soft); border: 1px solid var(--amber);
1064
+ border-radius: 6px; color: var(--text); opacity: 0.9;
1065
+ transition: opacity 0.12s;
1066
+ }
1067
+ .bubble.md .md-code-run:hover, .bubble.md .md-code-run:focus-visible { opacity: 1; }
1054
1068
  /* The horizontal scroll for a wide table lives on this wrapper (added in JS
1055
1069
  after sanitising), NOT on the <table>: `display:block` on a table breaks its
1056
1070
  own layout — thead and tbody stop sharing column widths, so the header row
@@ -2490,8 +2504,9 @@
2490
2504
  import { pickChannelSource, dirKey, serverSwapped } from "/channel-store.js?v=__ASSET_V__";
2491
2505
  import { MODEL_CHOICES, composeModel } from "/model-choice.js?v=__ASSET_V__";
2492
2506
  import { EFFORT_CHOICES, effortLabel } from "/effort-choice.js?v=__ASSET_V__";
2493
- import { bangCommands } from "/bang.js?v=__ASSET_V__";
2507
+ import { bangCommands, blockCommand } from "/bang.js?v=__ASSET_V__";
2494
2508
  window.bangCommands = bangCommands;
2509
+ window.blockCommand = blockCommand;
2495
2510
  import { claudeUpdateState } from "/update-ready.js?v=__ASSET_V__";
2496
2511
  window.claudeUpdateState = claudeUpdateState;
2497
2512
  import { uploadFailure } from "/upload.js?v=__ASSET_V__";
@@ -2599,6 +2614,8 @@
2599
2614
  effortLabel: () => "profile default",
2600
2615
  // No module, no buttons: an agent's message renders exactly as before.
2601
2616
  bangCommands: () => [],
2617
+ // No module → no block is runnable, so no inline run button (copy only).
2618
+ blockCommand: () => null,
2602
2619
  // Boot-critical (runs in restore before the module might land): a fulfilled
2603
2620
  // /channels wins even when empty; only a failed fetch uses the cache.
2604
2621
  pickChannelSource: (settled, cached) =>
@@ -4979,32 +4996,66 @@
4979
4996
  return "/download?session=" + encodeURIComponent(tab.sessionId || "") +
4980
4997
  "&path=" + encodeURIComponent(file.path);
4981
4998
  }
4999
+ /** Run a `! cmd` the agent offered: one confirmation, then the command in the
5000
+ * agent's pane shell mode. The confirmation is not ceremony — shell mode is
5001
+ * not the agent's Bash tool, so a profile's guardrails do not apply to it
5002
+ * (measured) — this is the human choosing to run something the agent could
5003
+ * not, and the dialog is where the human sees exactly what that is. */
5004
+ function runBang(tab, cmd) {
5005
+ if (!confirm("Run this command in the agent's shell?\n\n" + cmd +
5006
+ "\n\nIt runs on the machine, outside the agent's guardrails.")) return;
5007
+ sendTo(tab, { type: "run", command: cmd });
5008
+ }
5009
+
4982
5010
  /**
4983
- * Buttons under an agent's message for each `! cmd` it asks YOU to run.
5011
+ * Make the `! cmd` commands an agent asks YOU to run clickable.
4984
5012
  *
4985
- * One click, one confirmation, one command in the agent's pane shell mode.
4986
- * The confirmation is not ceremony: shell mode is not the agent's Bash tool,
4987
- * so a profile's guardrails do not apply to it (measured) — this is the human
4988
- * choosing to run something the agent could not, and the dialog is where the
4989
- * human sees exactly what that is.
5013
+ * Preferred placement is IN the text: a compact "▶ run" button joins the copy
5014
+ * button on every fenced code block that is exactly one `! cmd` line, so the
5015
+ * command stays where the agent wrote it instead of being repeated in a list.
5016
+ * Commands with no block of their own — an inline `` `! cmd` ``, a bare line —
5017
+ * fall back to a row of buttons below, so none is ever lost.
4990
5018
  */
4991
5019
  function decorateBang(tab, bubble, text) {
4992
5020
  const cmds = window.bangCommands(text);
4993
5021
  if (!cmds.length || !bubble) return;
5022
+ const allowed = new Set(cmds);
5023
+ const placed = new Set();
5024
+ // Inline on each runnable code block, beside its copy button.
5025
+ for (const wrap of bubble.querySelectorAll(".md-code")) {
5026
+ const code = wrap.querySelector("code") || wrap.querySelector("pre");
5027
+ const cmd = window.blockCommand(code && code.textContent);
5028
+ if (!cmd || !allowed.has(cmd) || placed.has(cmd)) continue;
5029
+ let tools = wrap.querySelector(".md-code-tools");
5030
+ if (!tools) {
5031
+ tools = document.createElement("div");
5032
+ tools.className = "md-code-tools";
5033
+ const copy = wrap.querySelector(".md-code-copy");
5034
+ if (copy) { copy.replaceWith(tools); tools.appendChild(copy); }
5035
+ else wrap.appendChild(tools);
5036
+ }
5037
+ const run = document.createElement("button");
5038
+ run.type = "button";
5039
+ run.className = "md-code-run";
5040
+ run.textContent = "▶ run";
5041
+ run.title = "Run in this agent's shell: " + cmd;
5042
+ // never onclick=: the CSP nonce does not cover inline handlers
5043
+ run.addEventListener("click", (e) => { e.stopPropagation(); runBang(tab, cmd); });
5044
+ tools.insertBefore(run, tools.firstChild);
5045
+ placed.add(cmd);
5046
+ }
5047
+ // Whatever didn't land on a block still gets a button, below.
5048
+ const rest = cmds.filter((c) => !placed.has(c));
5049
+ if (!rest.length) return;
4994
5050
  const row = document.createElement("div");
4995
5051
  row.className = "bang-row";
4996
- for (const cmd of cmds) {
5052
+ for (const cmd of rest) {
4997
5053
  const b = document.createElement("button");
4998
5054
  b.type = "button";
4999
5055
  b.className = "bang-btn";
5000
5056
  b.textContent = "▶ " + cmd;
5001
5057
  b.title = "Run in this agent's shell: " + cmd;
5002
- // never onclick=: the CSP nonce does not cover inline handlers
5003
- b.addEventListener("click", () => {
5004
- if (!confirm("Run this command in the agent's shell?\n\n" + cmd +
5005
- "\n\nIt runs on the machine, outside the agent's guardrails.")) return;
5006
- sendTo(tab, { type: "run", command: cmd });
5007
- });
5058
+ b.addEventListener("click", () => runBang(tab, cmd));
5008
5059
  row.appendChild(b);
5009
5060
  }
5010
5061
  bubble.appendChild(row);