@alexwkleung/reika 0.11.0 → 0.12.0

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.
@@ -3885,6 +3885,10 @@ function startProfiles(config, mode, state, launched = setAtLaunch) {
3885
3885
  }
3886
3886
 
3887
3887
  // src/ui/format.ts
3888
+ var HIDDEN_TOOL_ARGS = {
3889
+ edit: /* @__PURE__ */ new Set(["old_string", "new_string"]),
3890
+ write: /* @__PURE__ */ new Set(["content"])
3891
+ };
3888
3892
  function formatElapsed(seconds) {
3889
3893
  const h = Math.floor(seconds / 3600);
3890
3894
  const m = Math.floor(seconds % 3600 / 60);
@@ -3897,6 +3901,13 @@ function formatElapsed(seconds) {
3897
3901
  function formatDurationMs(ms) {
3898
3902
  return formatElapsed(Math.round(ms / 1e3));
3899
3903
  }
3904
+ function turnEndLabel(durationMs, interrupted) {
3905
+ return interrupted ? `Interrupted after ${formatDurationMs(durationMs)}` : `Worked for ${formatDurationMs(durationMs)}`;
3906
+ }
3907
+ var ABORTED_MARKER_RE = /(?:\n\n)?\(aborted\)$/;
3908
+ function displayProse(content, interrupted) {
3909
+ return interrupted ? content.replace(ABORTED_MARKER_RE, "") : content;
3910
+ }
3900
3911
  var PREFILL_LABEL_MIN_TOKENS = 2048;
3901
3912
  var PREFILL_LABEL_MIN_MS = 2e3;
3902
3913
  function prefillLabel(progress) {
@@ -6704,13 +6715,6 @@ function redactSecrets(s) {
6704
6715
 
6705
6716
  // src/ui/paths.ts
6706
6717
  import { homedir as homedir5 } from "node:os";
6707
- var HOME = homedir5();
6708
- function scrubPaths(s, cwd = process.cwd()) {
6709
- let out = s;
6710
- if (cwd) out = out.split(cwd + "/").join("");
6711
- if (HOME) out = out.split(HOME + "/").join("~/");
6712
- return out;
6713
- }
6714
6718
 
6715
6719
  // src/ui/identity.ts
6716
6720
  import { execFile } from "node:child_process";
@@ -6727,6 +6731,9 @@ var generation = 0;
6727
6731
  function scrubGeneration() {
6728
6732
  return generation;
6729
6733
  }
6734
+ function bumpScrubGeneration() {
6735
+ generation++;
6736
+ }
6730
6737
  function setIdentity(id) {
6731
6738
  rules = buildRules(id);
6732
6739
  enabled = true;
@@ -6832,6 +6839,24 @@ function git(args, cwd, timeoutMs) {
6832
6839
  });
6833
6840
  }
6834
6841
 
6842
+ // src/ui/paths.ts
6843
+ var HOME = homedir5();
6844
+ var sessionRoot = null;
6845
+ function setDisplayRoot(cwd) {
6846
+ if (cwd === sessionRoot) return;
6847
+ sessionRoot = cwd;
6848
+ bumpScrubGeneration();
6849
+ }
6850
+ function displayRoot() {
6851
+ return sessionRoot ?? process.cwd();
6852
+ }
6853
+ function scrubPaths(s, cwd = displayRoot()) {
6854
+ let out = s;
6855
+ if (cwd) out = out.split(cwd + "/").join("");
6856
+ if (HOME) out = out.split(HOME + "/").join("~/");
6857
+ return out;
6858
+ }
6859
+
6835
6860
  // src/ui/scrub.ts
6836
6861
  function scrubDisplay(s, cwd) {
6837
6862
  return scrubIdentity(scrubPaths(redactSecrets(s), cwd));
@@ -6844,6 +6869,23 @@ function displayCwd(cwd) {
6844
6869
  function scrubOutput(s, cwd) {
6845
6870
  return scrubDisplay(sanitizeTerminalText(s), cwd);
6846
6871
  }
6872
+ var HELD_TAIL_SCAN = 512;
6873
+ function holdPartialPath(s) {
6874
+ const roots = [homedir6() + "/", displayRoot() + "/"];
6875
+ const from = Math.max(0, s.length - HELD_TAIL_SCAN);
6876
+ for (let i = s.indexOf("/", from); i !== -1; i = s.indexOf("/", i + 1)) {
6877
+ const tail = s.slice(i);
6878
+ if (/\s/.test(tail)) continue;
6879
+ if (roots.some((r) => r.length > tail.length && r.startsWith(tail))) return s.slice(0, i);
6880
+ }
6881
+ return s;
6882
+ }
6883
+ function scrubPreview(s) {
6884
+ return s.split("\n").map((line) => scrubIdentity(scrubPaths(line))).join("\n");
6885
+ }
6886
+ function scrubLines(s) {
6887
+ return s.split("\n").map((line) => scrubDisplay(line)).join("\n");
6888
+ }
6847
6889
 
6848
6890
  // src/ui/harnessecho.ts
6849
6891
  var HARNESS_ECHO_LINE = /^\s*(?:\[reika:[^\]\n]*\]|\(reika:[^)\n]*\)|\[tool (?:result|output)[^\]\n]*\])\s*$/;
@@ -7836,6 +7878,170 @@ function isRecord2(v) {
7836
7878
  return typeof v === "object" && v !== null && !Array.isArray(v);
7837
7879
  }
7838
7880
 
7881
+ // src/ui/pastes.ts
7882
+ var PASTE_LINE_THRESHOLD = 12;
7883
+ var PASTE_CHAR_THRESHOLD = 1500;
7884
+ var MAX_PASTE_STORE_CHARS = 4e6;
7885
+ var MARKER_RE = /\[Pasted text #\d+ \+[^\]\n]+\]/g;
7886
+ function isLargePaste(text) {
7887
+ return countLines(text) >= PASTE_LINE_THRESHOLD || text.length >= PASTE_CHAR_THRESHOLD;
7888
+ }
7889
+ function rememberPaste(pastes, text) {
7890
+ const kept = [...pastes, { marker: nextMarker(pastes, text), text }];
7891
+ let total = kept.reduce((n, p) => n + p.text.length, 0);
7892
+ while (kept.length > 1 && total > MAX_PASTE_STORE_CHARS) {
7893
+ total -= kept.shift().text.length;
7894
+ }
7895
+ return { pastes: kept, marker: kept[kept.length - 1].marker };
7896
+ }
7897
+ function expandPastes(input, pastes) {
7898
+ if (pastes.length === 0) return input;
7899
+ const byMarker = new Map(pastes.map((p) => [p.marker, p.text]));
7900
+ return input.replace(MARKER_RE, (m) => byMarker.get(m) ?? m);
7901
+ }
7902
+ function hasPasteMarker(input) {
7903
+ MARKER_RE.lastIndex = 0;
7904
+ return MARKER_RE.test(input);
7905
+ }
7906
+ function nextMarker(pastes, text) {
7907
+ const used = pastes.map((p) => Number(/#(\d+)/.exec(p.marker)?.[1] ?? 0));
7908
+ const id = Math.max(0, ...used) + 1;
7909
+ const lines = countLines(text);
7910
+ const size = lines > 1 ? `${lines} lines` : `${text.length} chars`;
7911
+ return `[Pasted text #${id} +${size}]`;
7912
+ }
7913
+ function countLines(text) {
7914
+ const n = text.split("\n").length;
7915
+ return text.endsWith("\n") ? n - 1 : n;
7916
+ }
7917
+
7918
+ // src/agent/turncommands.ts
7919
+ function parseCommand(raw) {
7920
+ const rest = raw.slice(1);
7921
+ const space = rest.indexOf(" ");
7922
+ return {
7923
+ name: (space === -1 ? rest : rest.slice(0, space)).toLowerCase(),
7924
+ args: space === -1 ? "" : rest.slice(space + 1)
7925
+ };
7926
+ }
7927
+ function resolveTurnCommand(name, args, ctx) {
7928
+ const { mode } = ctx;
7929
+ if (name === "implement") {
7930
+ if (mode === "shell" || mode === "chat") {
7931
+ return {
7932
+ kind: "refuse",
7933
+ content: `/implement isn't available in ${mode} mode \u2014 use it from plan mode (or agent mode) to execute a plan.`
7934
+ };
7935
+ }
7936
+ const target = mode === "plan" ? ctx.implementMode ?? "agent" : mode === "minimal" || mode === "grind" ? mode : "agent";
7937
+ const label = target.charAt(0).toUpperCase() + target.slice(1);
7938
+ return {
7939
+ kind: "submit",
7940
+ modelText: buildImplementPrompt(args),
7941
+ // Always explicit: a front end's own mode may not have caught up with `switchTo` yet.
7942
+ mode: target,
7943
+ ...mode === "plan" ? { switchTo: target } : {},
7944
+ before: mode === "plan" ? [{ content: `${label} mode \u2014 implementing the plan above.` }] : [],
7945
+ after: [],
7946
+ echo: false
7947
+ };
7948
+ }
7949
+ if (name === "compact") {
7950
+ if (mode === "chat" || mode === "shell") {
7951
+ return { kind: "refuse", content: `/compact isn't available in ${mode} mode.` };
7952
+ }
7953
+ return {
7954
+ kind: "submit",
7955
+ // Never reaches the loop: a manual compaction drops the user message.
7956
+ modelText: "compact",
7957
+ ...mode === "vibe" ? { mode: "agent" } : {},
7958
+ before: [{ content: "Compacting context\u2026", tone: "info", emphasis: "line" }],
7959
+ after: [],
7960
+ echo: true,
7961
+ manualCompact: true
7962
+ };
7963
+ }
7964
+ if (name === "search") {
7965
+ const query = args.trim();
7966
+ if (!query) {
7967
+ return {
7968
+ kind: "refuse",
7969
+ content: "Usage: /search <query> \u2014 the model runs one web search and answers from the results."
7970
+ };
7971
+ }
7972
+ const refusal = searchModeRefusal(mode);
7973
+ if (refusal) return { kind: "refuse", content: refusal };
7974
+ const target = mode === "vibe" ? "agent" : mode;
7975
+ if (!ctx.searchAvailable(target)) {
7976
+ return { kind: "refuse", content: searchUnavailableNotice(ctx.offline()) };
7977
+ }
7978
+ return {
7979
+ kind: "submit",
7980
+ modelText: buildSearchPrompt(query),
7981
+ ...target === mode ? {} : { mode: target },
7982
+ before: [],
7983
+ after: [],
7984
+ echo: false
7985
+ };
7986
+ }
7987
+ return null;
7988
+ }
7989
+ function resolveSkillCommand(name, args, ctx) {
7990
+ const skill = ctx.skills.find((s) => s.name === name);
7991
+ if (!skill) return null;
7992
+ const extra = ctx.pastes ? expandPastes(args.trim(), ctx.pastes) : args.trim();
7993
+ return {
7994
+ kind: "submit",
7995
+ modelText: extra ? `${skill.body}
7996
+
7997
+ ${extra}` : skill.body,
7998
+ ...ctx.mode === "vibe" ? { mode: "vibe" } : {},
7999
+ before: [],
8000
+ // The bubble echoes what was typed; only this line says the body is what the model got (#398).
8001
+ after: [
8002
+ {
8003
+ content: `Skill /${skill.name} applied \u2014 its body was sent as this prompt${extra ? ", with your text after it" : ""}.`,
8004
+ tone: "info"
8005
+ }
8006
+ ],
8007
+ echo: false,
8008
+ skill: skill.name
8009
+ };
8010
+ }
8011
+ var IMPLEMENT_MODES = ["agent", "minimal", "grind"];
8012
+ function buildImplementPrompt(extra) {
8013
+ const base = "Implement the plan above. Work through it step by step, making the edits to the files it names.";
8014
+ const trimmed = extra.trim();
8015
+ return trimmed ? `${base}
8016
+
8017
+ Additional guidance: ${trimmed}` : base;
8018
+ }
8019
+ function buildSearchPrompt(query) {
8020
+ return [
8021
+ `Search the web for: ${query.trim()}`,
8022
+ "",
8023
+ "Your first action is a `search` tool call with that query. Answer from its results, not from memory.",
8024
+ "",
8025
+ "- Give each claim the URL the results returned, verbatim.",
8026
+ "- Open the one or two most promising results with `fetch_url` before leaning on a snippet.",
8027
+ "- If the results are off-topic, say so and stop \u2014 do not re-run the query in other words.",
8028
+ "- If the search fails or is unavailable, say that in one line instead of answering from memory."
8029
+ ].join("\n");
8030
+ }
8031
+ function searchModeRefusal(mode) {
8032
+ const elsewhere = "/agent, /plan, /chat or /grind to search.";
8033
+ if (mode === "shell") return `/search needs a model turn, and shell mode has none \u2014 ${elsewhere}`;
8034
+ if (mode === "minimal")
8035
+ return `/search needs the web tools, and minimal mode carries none \u2014 ${elsewhere}`;
8036
+ return void 0;
8037
+ }
8038
+ function searchUnavailableNotice(offline) {
8039
+ return offline ? "/search is off for this session: it started with no route out, so the web tools were not loaded (#392)." : "No search provider is configured, so this session has no `search` tool. Set REIKA_SEARXNG_URL to a SearXNG instance, or REIKA_CDP_SEARCH=1 to search through Chrome.";
8040
+ }
8041
+ function isImplementCommand(input) {
8042
+ return /^\/implement(?:\s|$)/i.test(input.trim());
8043
+ }
8044
+
7839
8045
  // src/provider/noteslot.ts
7840
8046
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
7841
8047
  import { homedir as homedir8 } from "node:os";
@@ -14731,6 +14937,7 @@ import { homedir as homedir14, tmpdir } from "node:os";
14731
14937
  import { dirname as dirname9, isAbsolute as isAbsolute4, join as join17, resolve as resolve6 } from "node:path";
14732
14938
  import { execFileSync as execFileSync3, spawnSync } from "node:child_process";
14733
14939
  var SANDBOX_EXEC_ERROR_PREFIX = "sandbox-exec:";
14940
+ var protectedPorts = /* @__PURE__ */ new Set();
14734
14941
  function sandboxProfile(opts) {
14735
14942
  const lines = [
14736
14943
  "(version 1)",
@@ -14823,6 +15030,9 @@ function sandboxProfile(opts) {
14823
15030
  "(allow network-inbound (local unix))"
14824
15031
  );
14825
15032
  }
15033
+ for (const port of [...protectedPorts].sort((a, b) => a - b)) {
15034
+ lines.push(`(deny network-outbound (remote ip "localhost:${port}"))`);
15035
+ }
14826
15036
  return lines.join("\n");
14827
15037
  }
14828
15038
  var NET_VERBS = /* @__PURE__ */ new Set(["gh", "git", "glab", "hf"]);
@@ -21343,6 +21553,7 @@ function commitAborted(opts, partial, partialReasoning, turnStart, fetchedUrls)
21343
21553
  const m = {
21344
21554
  role: "assistant",
21345
21555
  content,
21556
+ interrupted: true,
21346
21557
  ...reasoning ? { reasoning } : {},
21347
21558
  durationMs: Date.now() - turnStart,
21348
21559
  ...fetchedUrls.size > 0 ? { sources: [...fetchedUrls] } : {}
@@ -21490,34 +21701,6 @@ ${coverage}` : "")
21490
21701
  }
21491
21702
 
21492
21703
  // src/ui/commands.ts
21493
- var MODE_CYCLE = ["agent", "plan", "minimal", "vibe", "grind", "chat", "shell"];
21494
- function nextMode(current) {
21495
- return MODE_CYCLE[(MODE_CYCLE.indexOf(current) + 1) % MODE_CYCLE.length];
21496
- }
21497
- function turnMode(current, active) {
21498
- return current === "vibe" ? "vibe" : active;
21499
- }
21500
- function turnTools(mode, lists) {
21501
- if (mode === "chat") return lists.chat;
21502
- if (mode === "plan" || mode === "vibe") return lists.plan;
21503
- if (mode === "minimal") return lists.minimal;
21504
- if (mode === "grind") return lists.grind;
21505
- return lists.agent;
21506
- }
21507
- function turnPromptMode(mode) {
21508
- if (mode === "chat") return "chat";
21509
- if (mode === "plan" || mode === "vibe") return "plan";
21510
- return "agent";
21511
- }
21512
- function isMinimalPrompt(mode) {
21513
- return mode === "minimal";
21514
- }
21515
- function isGrindPrompt(mode) {
21516
- return mode === "grind";
21517
- }
21518
- function turnRefines(mode) {
21519
- return mode !== "vibe";
21520
- }
21521
21704
  var COMMANDS = [
21522
21705
  { name: "help", desc: "show this list" },
21523
21706
  { name: "new", desc: "reset conversation, tokens, mode" },
@@ -21583,48 +21766,66 @@ var COMMANDS = [
21583
21766
  { name: "exit", desc: "exit Reika" },
21584
21767
  { name: "quit", desc: "alias of /exit" }
21585
21768
  ];
21586
- var IMPLEMENT_MODES = ["agent", "minimal", "grind"];
21587
- function buildImplementPrompt(extra) {
21588
- const base = "Implement the plan above. Work through it step by step, making the edits to the files it names.";
21589
- const trimmed = extra.trim();
21590
- return trimmed ? `${base}
21591
-
21592
- Additional guidance: ${trimmed}` : base;
21593
- }
21594
- function buildSearchPrompt(query) {
21595
- return [
21596
- `Search the web for: ${query.trim()}`,
21597
- "",
21598
- "Your first action is a `search` tool call with that query. Answer from its results, not from memory.",
21599
- "",
21600
- "- Give each claim the URL the results returned, verbatim.",
21601
- "- Open the one or two most promising results with `fetch_url` before leaning on a snippet.",
21602
- "- If the results are off-topic, say so and stop \u2014 do not re-run the query in other words.",
21603
- "- If the search fails or is unavailable, say that in one line instead of answering from memory."
21604
- ].join("\n");
21605
- }
21606
- function searchModeRefusal(mode) {
21607
- const elsewhere = "/agent, /plan, /chat or /grind to search.";
21608
- if (mode === "shell") return `/search needs a model turn, and shell mode has none \u2014 ${elsewhere}`;
21609
- if (mode === "minimal")
21610
- return `/search needs the web tools, and minimal mode carries none \u2014 ${elsewhere}`;
21611
- return void 0;
21612
- }
21613
- function searchUnavailableNotice(offline) {
21614
- return offline ? "/search is off for this session: it started with no route out, so the web tools were not loaded (#392)." : "No search provider is configured, so this session has no `search` tool. Set REIKA_SEARXNG_URL to a SearXNG instance, or REIKA_CDP_SEARCH=1 to search through Chrome.";
21615
- }
21616
21769
  function planWritten(messages) {
21617
21770
  return messages.some(
21618
21771
  (m) => m.role === "assistant" && !!m.planFinal && parsePlanSteps(m.content ?? "").length > 0
21619
21772
  );
21620
21773
  }
21621
- function isImplementCommand(input) {
21622
- return /^\/implement(?:\s|$)/i.test(input.trim());
21623
- }
21624
21774
  function isSaveCommand(input) {
21625
21775
  return /^\/save(?:\s|$)/i.test(input.trim());
21626
21776
  }
21627
21777
 
21778
+ // src/agent/modes.ts
21779
+ var MODE_CYCLE = ["agent", "plan", "minimal", "vibe", "grind", "chat", "shell"];
21780
+ function nextMode(current) {
21781
+ return MODE_CYCLE[(MODE_CYCLE.indexOf(current) + 1) % MODE_CYCLE.length];
21782
+ }
21783
+ function turnMode(current, active) {
21784
+ return current === "vibe" ? "vibe" : active;
21785
+ }
21786
+ function turnTools(mode, lists) {
21787
+ if (mode === "chat") return lists.chat;
21788
+ if (mode === "plan" || mode === "vibe") return lists.plan;
21789
+ if (mode === "minimal") return lists.minimal;
21790
+ if (mode === "grind") return lists.grind;
21791
+ return lists.agent;
21792
+ }
21793
+ function turnPromptMode(mode) {
21794
+ if (mode === "chat") return "chat";
21795
+ if (mode === "plan" || mode === "vibe") return "plan";
21796
+ return "agent";
21797
+ }
21798
+ function isMinimalPrompt(mode) {
21799
+ return mode === "minimal";
21800
+ }
21801
+ function isGrindPrompt(mode) {
21802
+ return mode === "grind";
21803
+ }
21804
+ function turnRefines(mode) {
21805
+ return mode !== "vibe";
21806
+ }
21807
+ function modeSide(mode) {
21808
+ return mode === "chat" ? "chat" : "agent";
21809
+ }
21810
+ var MODE_BANNERS = {
21811
+ agent: "Agent mode.",
21812
+ shell: "Shell mode. Commands run directly in cwd. /agent to return.",
21813
+ chat: "Chat mode. Filesystem and shell tools disabled. Conversation isolated from agent. /agent to return.",
21814
+ plan: "Plan mode \u2014 read-only exploration; will end with a written plan. Send another message to refine that plan, or /implement (agent, minimal or grind) to execute it.",
21815
+ vibe: "Vibe mode \u2014 each prompt is planned first (read-only), then the plan is implemented automatically. Approvals apply as usual. /agent to return.",
21816
+ minimal: "Minimal mode \u2014 shell only, and no repo map, project summary, or AGENTS.md in the prompt. The model works from what commands show it. /agent to return.",
21817
+ grind: "Grind mode \u2014 the model works through a fixed procedure: pin down the task, explore, choose, change, prove it by running checks, review the diff, report what was verified. Tools: bash, read, edit. /agent to return."
21818
+ };
21819
+ function resolveModeCommand(name, ctx) {
21820
+ const to = MODE_CYCLE.find((m) => m === name);
21821
+ if (!to) return null;
21822
+ if (to === ctx.mode) return { kind: "refuse", content: `Already in ${to} mode.` };
21823
+ if (ctx.busy) {
21824
+ return { kind: "refuse", content: "Cannot switch modes while busy. Wait or ctrl-c to abort." };
21825
+ }
21826
+ return { kind: "switch", to, banner: MODE_BANNERS[to] };
21827
+ }
21828
+
21628
21829
  // src/session.ts
21629
21830
  async function createSession(opts) {
21630
21831
  if (opts.config) assertRawConfig(opts.config, "createSession");
@@ -21647,6 +21848,7 @@ async function createSession(opts) {
21647
21848
  repoMapBudgetFor(resolveProfile(cfg, profile).contextWindow, cfg.repoMapBudget)
21648
21849
  );
21649
21850
  let bundle = fitRepoMap(booted);
21851
+ setDisplayRoot(bundle.cwd);
21650
21852
  const retryWindow = /* @__PURE__ */ new Set();
21651
21853
  if (probed && !probed.reached) retryWindow.add(profile);
21652
21854
  void ensureNoteSlot(resolveProfile(cfg, profile));
@@ -21909,6 +22111,7 @@ async function createSession(opts) {
21909
22111
  const next = update(bundle);
21910
22112
  if (next === bundle) return;
21911
22113
  bundle = next;
22114
+ setDisplayRoot(bundle.cwd);
21912
22115
  changed();
21913
22116
  },
21914
22117
  switchSide: (next) => {
@@ -21962,6 +22165,102 @@ function noWindowNotice(probe, before, name = "default") {
21962
22165
  return parts.join(" ");
21963
22166
  }
21964
22167
 
22168
+ // src/skills/skillmatch.ts
22169
+ var SUGGEST_MIN_SCORE = 1;
22170
+ var AUTO_MIN_SCORE = 2;
22171
+ var AUTO_MAX_WORDS = 12;
22172
+ var COURTESY_LEADS = [
22173
+ "can you please",
22174
+ "could you please",
22175
+ "can you",
22176
+ "could you",
22177
+ "would you",
22178
+ "please",
22179
+ "pls",
22180
+ "now",
22181
+ "next",
22182
+ "okay",
22183
+ "ok",
22184
+ "hey",
22185
+ "let s",
22186
+ "lets"
22187
+ ];
22188
+ var AUTO_BODY_WINDOW_FRACTION = 0.15;
22189
+ var DENSE_CHARS_PER_TOKEN = 2.5;
22190
+ var AUTO_BODY_CHARS_FALLBACK = 6e3;
22191
+ var CONTINUATIONS = /* @__PURE__ */ new Set([
22192
+ "y",
22193
+ "n",
22194
+ "yes",
22195
+ "yeah",
22196
+ "yep",
22197
+ "no",
22198
+ "ok",
22199
+ "okay",
22200
+ "sure",
22201
+ "go",
22202
+ "go ahead",
22203
+ "go on",
22204
+ "continue",
22205
+ "keep going",
22206
+ "proceed",
22207
+ "do it",
22208
+ "next",
22209
+ "again",
22210
+ "retry",
22211
+ "fix it",
22212
+ "thanks"
22213
+ ]);
22214
+ function matchSkill(prompt, skills) {
22215
+ const haystack = normalize4(prompt);
22216
+ if (!haystack || CONTINUATIONS.has(haystack.trim())) return null;
22217
+ const lead = stripCourtesyLead(haystack);
22218
+ const words2 = haystack.trim().split(" ").length;
22219
+ const ranked = [];
22220
+ for (const skill of skills) {
22221
+ const hits = candidatePhrases(skill).filter((p) => haystack.includes(` ${p} `));
22222
+ if (hits.length === 0) continue;
22223
+ const matched = hits.filter((p) => !hits.some((q) => q !== p && ` ${q} `.includes(` ${p} `)));
22224
+ const score = matched.reduce((sum, p) => sum + p.split(" ").length, 0);
22225
+ const leading = matched.some((p) => lead.startsWith(` ${p} `));
22226
+ ranked.push({ skill, score, matched, leading, words: words2 });
22227
+ }
22228
+ if (ranked.length === 0) return null;
22229
+ ranked.sort((a, b) => b.score - a.score);
22230
+ if (ranked.length > 1 && ranked[1].score === ranked[0].score) return null;
22231
+ return ranked[0].score >= SUGGEST_MIN_SCORE ? ranked[0] : null;
22232
+ }
22233
+ function shouldAutoInject(match, contextWindowTokens) {
22234
+ return shouldConfirmInject(match, contextWindowTokens) && match.words <= AUTO_MAX_WORDS;
22235
+ }
22236
+ function shouldConfirmInject(match, contextWindowTokens) {
22237
+ if (match.score < AUTO_MIN_SCORE) return false;
22238
+ if (!match.leading) return false;
22239
+ const maxChars = contextWindowTokens ? contextWindowTokens * DENSE_CHARS_PER_TOKEN * AUTO_BODY_WINDOW_FRACTION : AUTO_BODY_CHARS_FALLBACK;
22240
+ return match.skill.body.length <= maxChars;
22241
+ }
22242
+ function candidatePhrases(skill) {
22243
+ const fromName = skill.name.replace(/[-_]+/g, " ");
22244
+ const phrases = [fromName, ...skill.triggers].map((p) => normalize4(p).trim()).filter((p) => p.length >= 3);
22245
+ return [...new Set(phrases)];
22246
+ }
22247
+ function stripCourtesyLead(haystack) {
22248
+ let rest = haystack;
22249
+ for (let stripped = true; stripped; ) {
22250
+ stripped = false;
22251
+ for (const lead of COURTESY_LEADS) {
22252
+ if (rest.startsWith(` ${lead} `)) {
22253
+ rest = ` ${rest.slice(lead.length + 2)}`;
22254
+ stripped = true;
22255
+ }
22256
+ }
22257
+ }
22258
+ return rest;
22259
+ }
22260
+ function normalize4(text) {
22261
+ return ` ${text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
22262
+ }
22263
+
21965
22264
  // src/agent/mentions.ts
21966
22265
  import { readFile as readFile15 } from "node:fs/promises";
21967
22266
  import { homedir as homedir16 } from "node:os";
@@ -21970,7 +22269,7 @@ import { basename as basename4, extname as extname3, isAbsolute as isAbsolute8,
21970
22269
  // src/agent/attachments.ts
21971
22270
  var MAX_IMAGE_TEXT = 2e4;
21972
22271
  var NATIVE_IMAGE_NOTE = "(not transcribed \u2014 you were shown this image directly, once. Ask for a re-paste if you need to look at it again.)";
21973
- var MARKER_RE = /\[Image (\d+)\]/g;
22272
+ var MARKER_RE2 = /\[Image (\d+)\]/g;
21974
22273
  function nextImageMarker(existing) {
21975
22274
  const used = existing.map((a) => Number(/\d+/.exec(a.marker)?.[0] ?? 0));
21976
22275
  return `[Image ${Math.max(0, ...used) + 1}]`;
@@ -22002,7 +22301,10 @@ async function readNativeAttachments(attachments, ocr) {
22002
22301
  attachments.map(async (a) => {
22003
22302
  if (!a.native) return a;
22004
22303
  const result = await ocr(a.native.bytes);
22005
- if (result.ok) return { marker: a.marker, text: result.text, source: a.source };
22304
+ if (result.ok) {
22305
+ const receipt = a.receipt ? { receipt: `${a.marker} \u2014 ${result.text.length} chars read from the image.` } : {};
22306
+ return { marker: a.marker, text: result.text, source: a.source, ...receipt };
22307
+ }
22006
22308
  failed.push(a.marker);
22007
22309
  return { marker: a.marker, text: "(image could not be read)", source: a.source };
22008
22310
  })
@@ -22010,8 +22312,8 @@ async function readNativeAttachments(attachments, ocr) {
22010
22312
  return { attachments: read, failed };
22011
22313
  }
22012
22314
  function hasImageMarker(input) {
22013
- MARKER_RE.lastIndex = 0;
22014
- return MARKER_RE.test(input);
22315
+ MARKER_RE2.lastIndex = 0;
22316
+ return MARKER_RE2.test(input);
22015
22317
  }
22016
22318
 
22017
22319
  // src/agent/mentions.ts
@@ -22260,102 +22562,6 @@ ${content || "(no extractable content)"}${truncated ? "\n\u2026(truncated \u2014
22260
22562
  return { blocks, notices, fetched };
22261
22563
  }
22262
22564
 
22263
- // src/skills/skillmatch.ts
22264
- var SUGGEST_MIN_SCORE = 1;
22265
- var AUTO_MIN_SCORE = 2;
22266
- var AUTO_MAX_WORDS = 12;
22267
- var COURTESY_LEADS = [
22268
- "can you please",
22269
- "could you please",
22270
- "can you",
22271
- "could you",
22272
- "would you",
22273
- "please",
22274
- "pls",
22275
- "now",
22276
- "next",
22277
- "okay",
22278
- "ok",
22279
- "hey",
22280
- "let s",
22281
- "lets"
22282
- ];
22283
- var AUTO_BODY_WINDOW_FRACTION = 0.15;
22284
- var DENSE_CHARS_PER_TOKEN = 2.5;
22285
- var AUTO_BODY_CHARS_FALLBACK = 6e3;
22286
- var CONTINUATIONS = /* @__PURE__ */ new Set([
22287
- "y",
22288
- "n",
22289
- "yes",
22290
- "yeah",
22291
- "yep",
22292
- "no",
22293
- "ok",
22294
- "okay",
22295
- "sure",
22296
- "go",
22297
- "go ahead",
22298
- "go on",
22299
- "continue",
22300
- "keep going",
22301
- "proceed",
22302
- "do it",
22303
- "next",
22304
- "again",
22305
- "retry",
22306
- "fix it",
22307
- "thanks"
22308
- ]);
22309
- function matchSkill(prompt, skills) {
22310
- const haystack = normalize4(prompt);
22311
- if (!haystack || CONTINUATIONS.has(haystack.trim())) return null;
22312
- const lead = stripCourtesyLead(haystack);
22313
- const words2 = haystack.trim().split(" ").length;
22314
- const ranked = [];
22315
- for (const skill of skills) {
22316
- const hits = candidatePhrases(skill).filter((p) => haystack.includes(` ${p} `));
22317
- if (hits.length === 0) continue;
22318
- const matched = hits.filter((p) => !hits.some((q) => q !== p && ` ${q} `.includes(` ${p} `)));
22319
- const score = matched.reduce((sum, p) => sum + p.split(" ").length, 0);
22320
- const leading = matched.some((p) => lead.startsWith(` ${p} `));
22321
- ranked.push({ skill, score, matched, leading, words: words2 });
22322
- }
22323
- if (ranked.length === 0) return null;
22324
- ranked.sort((a, b) => b.score - a.score);
22325
- if (ranked.length > 1 && ranked[1].score === ranked[0].score) return null;
22326
- return ranked[0].score >= SUGGEST_MIN_SCORE ? ranked[0] : null;
22327
- }
22328
- function shouldAutoInject(match, contextWindowTokens) {
22329
- return shouldConfirmInject(match, contextWindowTokens) && match.words <= AUTO_MAX_WORDS;
22330
- }
22331
- function shouldConfirmInject(match, contextWindowTokens) {
22332
- if (match.score < AUTO_MIN_SCORE) return false;
22333
- if (!match.leading) return false;
22334
- const maxChars = contextWindowTokens ? contextWindowTokens * DENSE_CHARS_PER_TOKEN * AUTO_BODY_WINDOW_FRACTION : AUTO_BODY_CHARS_FALLBACK;
22335
- return match.skill.body.length <= maxChars;
22336
- }
22337
- function candidatePhrases(skill) {
22338
- const fromName = skill.name.replace(/[-_]+/g, " ");
22339
- const phrases = [fromName, ...skill.triggers].map((p) => normalize4(p).trim()).filter((p) => p.length >= 3);
22340
- return [...new Set(phrases)];
22341
- }
22342
- function stripCourtesyLead(haystack) {
22343
- let rest = haystack;
22344
- for (let stripped = true; stripped; ) {
22345
- stripped = false;
22346
- for (const lead of COURTESY_LEADS) {
22347
- if (rest.startsWith(` ${lead} `)) {
22348
- rest = ` ${rest.slice(lead.length + 2)}`;
22349
- stripped = true;
22350
- }
22351
- }
22352
- }
22353
- return rest;
22354
- }
22355
- function normalize4(text) {
22356
- return ` ${text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
22357
- }
22358
-
22359
22565
  // src/ocr/system.ts
22360
22566
  import { spawn as spawn5 } from "node:child_process";
22361
22567
  import { createRequire as createRequire2 } from "node:module";
@@ -22474,6 +22680,9 @@ function parseWorkerResult(envelope, code, signal) {
22474
22680
  var VISION_TIMEOUT_MS = 3e5;
22475
22681
  var VISION_PROMPT = "Describe this image for a coding assistant that cannot see it. First transcribe all visible text exactly \u2014 code, error messages, logs, terminal output, UI labels \u2014 preserving line breaks and indentation. Then, only if it matters, briefly describe what is shown (layout, diagram, highlighted region). Plain text only, no preamble.";
22476
22682
  function sniffImageMime(bytes) {
22683
+ return sniffKnownImageMime(bytes) ?? "image/png";
22684
+ }
22685
+ function sniffKnownImageMime(bytes) {
22477
22686
  const b = bytes;
22478
22687
  if (b.length >= 8 && b[0] === 137 && b[1] === 80 && b[2] === 78 && b[3] === 71)
22479
22688
  return "image/png";
@@ -22485,7 +22694,7 @@ function sniffImageMime(bytes) {
22485
22694
  if (b.length >= 2 && b[0] === 66 && b[1] === 77) return "image/bmp";
22486
22695
  if (b.length >= 4 && (b[0] === 73 && b[1] === 73 && b[2] === 42 && b[3] === 0 || b[0] === 77 && b[1] === 77 && b[2] === 0 && b[3] === 42))
22487
22696
  return "image/tiff";
22488
- return "image/png";
22697
+ return null;
22489
22698
  }
22490
22699
  function visionRequest(model, image) {
22491
22700
  const dataUrl = `data:${sniffImageMime(image)};base64,${Buffer.from(image).toString("base64")}`;
@@ -22574,6 +22783,90 @@ function pasteIsNative(config) {
22574
22783
  return config.vision === "native";
22575
22784
  }
22576
22785
 
22786
+ // src/agent/submitinput.ts
22787
+ function skillToConfirm(prompt, ctx) {
22788
+ if (ctx.skillAuto === "off" || prompt.startsWith("/")) return null;
22789
+ if (ctx.mode === "shell" || ctx.mode === "chat") return null;
22790
+ const match = matchSkill(prompt, ctx.skills);
22791
+ return match && shouldConfirmInject(match, ctx.contextWindow) ? match : null;
22792
+ }
22793
+ function urlsToConfirm(prompt, ctx) {
22794
+ if (ctx.pasteFetch === "off" || prompt.startsWith("/") || ctx.mode === "shell") return null;
22795
+ const plan = planPastedUrls(prompt);
22796
+ return plan.urls.length === 0 || plan.request ? null : plan.urls;
22797
+ }
22798
+ function submitStageLabel(stage) {
22799
+ if (stage.kind === "describe-image") return `Describing image with ${stage.model}`;
22800
+ return `Fetching ${stage.count} pasted link${stage.count > 1 ? "s" : ""}`;
22801
+ }
22802
+ async function buildSubmitInput(prompt, opts) {
22803
+ const notices = [];
22804
+ const reader = imageReader(opts.config);
22805
+ const vision = opts.config.visionModel;
22806
+ const ocr = vision ? (bytes) => {
22807
+ opts.onStage?.({ kind: "describe-image", model: vision });
22808
+ return reader(bytes);
22809
+ } : reader;
22810
+ const expansion = await expandMentions(prompt, opts.cwd, { ocr });
22811
+ notices.push(...expansion.notices.map((content) => ({ content, tone: "warn" })));
22812
+ const urls = await expandPastedUrls(prompt, {
22813
+ mode: opts.config.pasteFetch,
22814
+ incidental: opts.fetchUrls,
22815
+ onStart: (count) => opts.onStage?.({ kind: "fetch-urls", count })
22816
+ });
22817
+ notices.push(...urls.notices.map((n) => ({ content: n.text, tone: n.tone })));
22818
+ let images = opts.images ?? [];
22819
+ if (!pasteIsNative(opts.config) && images.some((a) => a.native)) {
22820
+ const read = await readNativeAttachments(images, ocr);
22821
+ images = read.attachments;
22822
+ for (const marker of read.failed) {
22823
+ notices.push({
22824
+ content: `Couldn't read ${marker} for ${opts.config.model}, which can't see images \u2014 it was pasted under a profile that could.`,
22825
+ tone: "warn"
22826
+ });
22827
+ }
22828
+ }
22829
+ let modelText = attachImageBlocks(expansion.augmented, images);
22830
+ for (const a of images) {
22831
+ if (a.receipt && modelText.includes(a.marker))
22832
+ notices.push({ content: a.receipt, tone: "info" });
22833
+ }
22834
+ const nativeImages = images.filter(
22835
+ (a) => Boolean(a.native && modelText.includes(a.marker))
22836
+ ).map((a) => ({ marker: a.marker, ...a.native }));
22837
+ if (urls.blocks.length > 0) modelText = `${urls.blocks.join("\n\n")}
22838
+
22839
+ ${modelText}`;
22840
+ let skill;
22841
+ const match = matchSkill(prompt, opts.skills);
22842
+ if (match && opts.skillRoute === match.skill.name) {
22843
+ notices.push({
22844
+ content: `Skill /${match.skill.name} applied \u2014 its body was prepended to this prompt (matched: ${match.matched.join(", ")}).`,
22845
+ tone: "info"
22846
+ });
22847
+ skill = match.skill.name;
22848
+ modelText = `${match.skill.body}
22849
+
22850
+ ${modelText}`;
22851
+ } else if (match && opts.skillHints && !opts.skillHints.has(match.skill.name)) {
22852
+ opts.skillHints.add(match.skill.name);
22853
+ if (opts.skillRoute !== null) {
22854
+ notices.push({
22855
+ content: `Skill hint: /${match.skill.name} \u2014 ${match.skill.description}. Prompt sent unchanged; start with /${match.skill.name} to apply it.`,
22856
+ tone: "info"
22857
+ });
22858
+ }
22859
+ }
22860
+ modelText = expandPastes(modelText, opts.pastes ?? []);
22861
+ return {
22862
+ modelText,
22863
+ display: expansion.display,
22864
+ ...skill ? { skill } : {},
22865
+ ...nativeImages.length > 0 ? { nativeImages } : {},
22866
+ notices
22867
+ };
22868
+ }
22869
+
22577
22870
  // src/ui/dialogspecs.ts
22578
22871
  var APPROVAL_OPTIONS = [
22579
22872
  "Approve",
@@ -22606,6 +22899,30 @@ function pastedUrlConfirmSpec(urls) {
22606
22899
  accept: "fetch"
22607
22900
  };
22608
22901
  }
22902
+ var IMPLEMENT_MODE_LABELS = {
22903
+ agent: "Agent \u2014 full tool set",
22904
+ minimal: "Minimal \u2014 shell only, no repo map or AGENTS.md",
22905
+ grind: "Grind \u2014 fixed procedure, proves the change by running checks"
22906
+ };
22907
+ function implementModeConfirmSpec() {
22908
+ return {
22909
+ title: "Implement",
22910
+ subtitle: "which mode should carry out the plan?",
22911
+ details: [],
22912
+ options: IMPLEMENT_MODES.map((m) => IMPLEMENT_MODE_LABELS[m])
22913
+ };
22914
+ }
22915
+ var TOGGLE_ON = 0;
22916
+ var TOGGLE_OFF = 1;
22917
+ var TOGGLE_CANCEL = 2;
22918
+ function toggleConfirmSpec(opts) {
22919
+ return {
22920
+ title: opts.title,
22921
+ subtitle: opts.subtitle,
22922
+ details: [],
22923
+ options: ["on", "off", "Cancel"]
22924
+ };
22925
+ }
22609
22926
 
22610
22927
  export {
22611
22928
  isOffline,
@@ -22619,8 +22936,10 @@ export {
22619
22936
  saveLastState,
22620
22937
  startMode,
22621
22938
  startProfiles,
22939
+ HIDDEN_TOOL_ARGS,
22622
22940
  formatElapsed,
22623
- formatDurationMs,
22941
+ turnEndLabel,
22942
+ displayProse,
22624
22943
  prefillLabel,
22625
22944
  kFormat,
22626
22945
  formatTokensPerSecond,
@@ -22637,11 +22956,11 @@ export {
22637
22956
  formatUnattendedDeclines,
22638
22957
  compactThreshold,
22639
22958
  shouldCompact,
22640
- scrubPaths,
22641
22959
  scrubGeneration,
22642
22960
  clearIdentity,
22643
22961
  isAnon,
22644
22962
  enableAnon,
22963
+ scrubPaths,
22645
22964
  stripAnsi,
22646
22965
  isFullwidth,
22647
22966
  isWide,
@@ -22652,6 +22971,9 @@ export {
22652
22971
  scrubDisplay,
22653
22972
  displayCwd,
22654
22973
  scrubOutput,
22974
+ holdPartialPath,
22975
+ scrubPreview,
22976
+ scrubLines,
22655
22977
  foldedAssistantFields,
22656
22978
  foldedLiveFields,
22657
22979
  buildTranscriptMeta,
@@ -22683,6 +23005,8 @@ export {
22683
23005
  withLiveUsage,
22684
23006
  prefixStableActive,
22685
23007
  buildRoundZeroPrefix,
23008
+ COMMANDS,
23009
+ isSaveCommand,
22686
23010
  nextMode,
22687
23011
  turnMode,
22688
23012
  turnTools,
@@ -22690,35 +23014,41 @@ export {
22690
23014
  isMinimalPrompt,
22691
23015
  isGrindPrompt,
22692
23016
  turnRefines,
22693
- COMMANDS,
23017
+ modeSide,
23018
+ resolveModeCommand,
23019
+ isLargePaste,
23020
+ rememberPaste,
23021
+ expandPastes,
23022
+ hasPasteMarker,
23023
+ parseCommand,
23024
+ resolveTurnCommand,
23025
+ resolveSkillCommand,
22694
23026
  IMPLEMENT_MODES,
22695
- buildImplementPrompt,
22696
- buildSearchPrompt,
22697
- searchModeRefusal,
22698
- searchUnavailableNotice,
22699
23027
  isImplementCommand,
22700
- isSaveCommand,
22701
23028
  createSession,
22702
23029
  NATIVE_IMAGE_NOTE,
22703
23030
  nextImageMarker,
22704
- attachImageBlocks,
22705
- readNativeAttachments,
22706
23031
  hasImageMarker,
22707
- expandMentions,
22708
23032
  hasBareImagePath,
22709
- planPastedUrls,
22710
- expandPastedUrls,
22711
23033
  matchSkill,
22712
23034
  shouldAutoInject,
22713
- shouldConfirmInject,
22714
23035
  systemOcr,
22715
23036
  sniffImageMime,
22716
23037
  imageReader,
22717
23038
  pasteIsNative,
23039
+ skillToConfirm,
23040
+ urlsToConfirm,
23041
+ submitStageLabel,
23042
+ buildSubmitInput,
22718
23043
  APPROVAL_OPTIONS,
22719
23044
  APPROVAL_FEEDBACK_INDEX,
22720
23045
  CONFIRM_DECLINE,
22721
23046
  CONFIRM_ACCEPT,
22722
23047
  skillConfirmSpec,
22723
- pastedUrlConfirmSpec
23048
+ pastedUrlConfirmSpec,
23049
+ implementModeConfirmSpec,
23050
+ TOGGLE_ON,
23051
+ TOGGLE_OFF,
23052
+ TOGGLE_CANCEL,
23053
+ toggleConfirmSpec
22724
23054
  };