@gajae-code/coding-agent 0.21.0 → 0.21.1

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/types/config/autorouting-contract.d.ts +4 -4
  3. package/dist/types/config/autorouting-tier-map.d.ts +1 -1
  4. package/dist/types/config/keybindings.d.ts +1 -5
  5. package/dist/types/config/model-profile-activation.d.ts +30 -3
  6. package/dist/types/config/model-registry.d.ts +2 -0
  7. package/dist/types/config/models-config-schema.d.ts +8 -0
  8. package/dist/types/config/settings-schema.d.ts +7 -3
  9. package/dist/types/coordinator-mcp/canonical-json.d.ts +7 -0
  10. package/dist/types/extensibility/gjc-plugins/metadata.d.ts +1 -1
  11. package/dist/types/harness-control-plane/receipts.d.ts +1 -1
  12. package/dist/types/modes/components/settings-selector.d.ts +5 -2
  13. package/dist/types/modes/controllers/command-controller.d.ts +1 -1
  14. package/dist/types/modes/controllers/input-controller.d.ts +12 -0
  15. package/dist/types/modes/controllers/selector-controller.d.ts +1 -1
  16. package/dist/types/modes/interactive-mode.d.ts +1 -1
  17. package/dist/types/modes/shared/agent-wire/workflow-gate-schema.d.ts +1 -1
  18. package/dist/types/modes/types.d.ts +1 -1
  19. package/dist/types/session/agent-session.d.ts +101 -6
  20. package/dist/types/session/session-manager.d.ts +124 -9
  21. package/dist/types/setup/provider-onboarding.d.ts +55 -2
  22. package/dist/types/slash-commands/builtin-registry.d.ts +11 -0
  23. package/dist/types/utils/clipboard.d.ts +18 -0
  24. package/dist/types/utils/pasted-image-path.d.ts +2 -0
  25. package/dist/types/web/search/providers/keenable.d.ts +30 -0
  26. package/dist/types/web/search/types.d.ts +2 -2
  27. package/package.json +7 -7
  28. package/scripts/generate-sdk-operation-inventory.ts +28 -0
  29. package/src/cli/doctor/config-repairs.ts +1 -4
  30. package/src/cli/local-provider-smoke.ts +1 -4
  31. package/src/cli/public-command-help.ts +1 -1
  32. package/src/config/autorouting-contract.ts +5 -8
  33. package/src/config/autorouting-tier-map.ts +1 -1
  34. package/src/config/keybindings.ts +1 -2
  35. package/src/config/model-profile-activation.ts +332 -28
  36. package/src/config/model-registry.ts +156 -8
  37. package/src/config/models-config-schema.ts +27 -0
  38. package/src/config/settings-schema.ts +6 -0
  39. package/src/coordinator-mcp/canonical-json.ts +15 -0
  40. package/src/coordinator-mcp/policy.ts +1 -0
  41. package/src/coordinator-mcp/question-gate-codec.ts +1 -2
  42. package/src/coordinator-mcp/question-state.ts +2 -12
  43. package/src/coordinator-mcp/server.ts +1 -10
  44. package/src/customization/import.ts +1 -5
  45. package/src/discovery/mcp-compat.ts +1 -5
  46. package/src/discovery/mcp-json.ts +1 -4
  47. package/src/edit/notebook.ts +1 -5
  48. package/src/extensibility/gjc-plugins/lifecycle.ts +1 -3
  49. package/src/extensibility/gjc-plugins/metadata.ts +2 -5
  50. package/src/extensibility/gjc-plugins/schema.ts +1 -4
  51. package/src/gjc-runtime/deep-interview-crystallize.ts +1 -4
  52. package/src/gjc-runtime/deep-interview-runtime.ts +1 -4
  53. package/src/gjc-runtime/state-renderer.ts +1 -5
  54. package/src/gjc-runtime/tmux-owner-isolation.ts +1 -3
  55. package/src/gjc-runtime/ultragoal-owner-loss-recovery.ts +1 -4
  56. package/src/gjc-runtime/ultragoal-succession.ts +1 -4
  57. package/src/goals/continuation-timeout-guard.ts +1 -4
  58. package/src/harness-control-plane/receipts.ts +1 -1
  59. package/src/internal-urls/docs-index.generated.ts +4 -4
  60. package/src/migrate/mcp-mapper.ts +2 -4
  61. package/src/modes/components/hook-editor.ts +4 -8
  62. package/src/modes/components/hook-selector.ts +3 -1
  63. package/src/modes/components/settings-selector.ts +26 -2
  64. package/src/modes/controllers/command-controller.ts +4 -98
  65. package/src/modes/controllers/extension-ui-controller.ts +6 -14
  66. package/src/modes/controllers/goal-mode-controller.ts +4 -4
  67. package/src/modes/controllers/input-controller.ts +110 -46
  68. package/src/modes/controllers/plan-mode-controller.ts +6 -10
  69. package/src/modes/controllers/selector-controller.ts +66 -23
  70. package/src/modes/controllers/todo-command-controller.ts +2 -2
  71. package/src/modes/interactive-mode.ts +2 -2
  72. package/src/modes/prompt-action-autocomplete.ts +1 -1
  73. package/src/modes/runtime-init.ts +4 -4
  74. package/src/modes/shared/agent-wire/workflow-gate-schema.ts +1 -1
  75. package/src/modes/types.ts +1 -1
  76. package/src/modes/utils/hotkeys-markdown.ts +1 -1
  77. package/src/runtime-mcp/client.ts +1 -4
  78. package/src/runtime-mcp/elicitation.ts +1 -5
  79. package/src/runtime-mcp/protocol.ts +2 -4
  80. package/src/sdk/broker/lifecycle-ledger.ts +1 -0
  81. package/src/sdk/broker/lifecycle.ts +1 -0
  82. package/src/sdk/cli/rows.ts +2 -3
  83. package/src/sdk/cli/session-cli.ts +2 -8
  84. package/src/sdk/host/query/cursor.ts +1 -0
  85. package/src/sdk/host/reverse-leases.ts +1 -0
  86. package/src/sdk/lifecycle/service.ts +1 -0
  87. package/src/sdk/protocol/operation-inventory.generated.json +154 -0
  88. package/src/session/agent-session.ts +1877 -224
  89. package/src/session/btw-prefix-ledger.ts +1 -4
  90. package/src/session/internal/managed-gc-retirement-codec.ts +1 -4
  91. package/src/session/session-manager.ts +732 -224
  92. package/src/session/task-artifact-owner-codec.ts +1 -4
  93. package/src/session-import/claude.ts +1 -4
  94. package/src/session-import/detect.ts +1 -6
  95. package/src/session-import/provider-codex.ts +1 -6
  96. package/src/session-import/provider-service.ts +4 -0
  97. package/src/setup/hermes-setup.ts +1 -4
  98. package/src/setup/provider-onboarding.ts +514 -26
  99. package/src/slash-commands/builtin-registry.ts +26 -13
  100. package/src/slash-commands/helpers/todo.ts +3 -1
  101. package/src/task/delegation-hint.ts +1 -4
  102. package/src/task/executor.ts +4 -2
  103. package/src/task/provider-retry-status.ts +1 -4
  104. package/src/tools/json-tree.ts +1 -4
  105. package/src/tools/recipe/runners/pkg.ts +1 -5
  106. package/src/utils/clipboard.ts +155 -2
  107. package/src/utils/mac-file-urls.applescript +37 -0
  108. package/src/utils/pasted-image-path.ts +5 -0
  109. package/src/web/search/provider.ts +6 -0
  110. package/src/web/search/providers/keenable.ts +207 -0
  111. package/src/web/search/types.ts +2 -0
@@ -50,6 +50,7 @@ import {
50
50
  } from "../setup/model-onboarding-guidance";
51
51
  import {
52
52
  addApiCompatibleProvider,
53
+ assertProviderConfigLoaded,
53
54
  formatProviderPresetList,
54
55
  formatProviderSetupResult,
55
56
  parseProviderCompatibility,
@@ -188,7 +189,7 @@ async function regenerateSessionTitle(runtime: SlashCommandRuntime): Promise<Sla
188
189
  return usage("Could not generate a session title — pass one: /rename <title>", runtime);
189
190
  }
190
191
 
191
- const stored = await runtime.sessionManager.setSessionName(generated, "user");
192
+ const stored = await runtime.session.setSessionName(generated, "user");
192
193
  if (!stored) {
193
194
  await runtime.output("Session name not changed (a user-set name takes precedence).");
194
195
  return commandConsumed();
@@ -224,7 +225,7 @@ async function updateSessionStar(
224
225
  return commandConsumed();
225
226
  }
226
227
 
227
- function parseProviderSetupSlashArgs(args: string): {
228
+ export function parseProviderSetupSlashArgs(args: string): {
228
229
  preset?: string;
229
230
  compat?: string;
230
231
  provider?: string;
@@ -771,7 +772,7 @@ async function handleEffortCommand(
771
772
 
772
773
  const levelToApply =
773
774
  requestedLevel === ThinkingLevel.Inherit ? runtime.settings.get("defaultThinkingLevel") : requestedLevel;
774
- runtime.session.setThinkingLevel(levelToApply, false);
775
+ await runtime.session.setThinkingLevelForControl(levelToApply, false);
775
776
  const effectiveLevel = runtime.session.thinkingLevel ?? ThinkingLevel.Off;
776
777
  const requestedLabel =
777
778
  requestedLevel === ThinkingLevel.Inherit ? `${requestedLevel} (${levelToApply})` : requestedLevel;
@@ -1280,7 +1281,7 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
1280
1281
  cause: "user-selection",
1281
1282
  });
1282
1283
  if (existingDefaultThinkingLevel) {
1283
- runtime.session.setThinkingLevel(existingDefaultThinkingLevel);
1284
+ await runtime.session.setThinkingLevelForSession(existingDefaultThinkingLevel);
1284
1285
  }
1285
1286
  }
1286
1287
  if (!includesDefault) {
@@ -1375,17 +1376,17 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
1375
1376
  handle: async (command, runtime) => {
1376
1377
  const arg = command.args.toLowerCase();
1377
1378
  if (!arg || arg === "toggle") {
1378
- const enabled = runtime.session.toggleFastMode();
1379
+ const enabled = await runtime.session.toggleFastMode();
1379
1380
  await runtime.output(`Fast mode ${enabled ? "enabled" : "disabled"}.`);
1380
1381
  return commandConsumed();
1381
1382
  }
1382
1383
  if (arg === "on") {
1383
- runtime.session.setFastMode(true);
1384
+ await runtime.session.setFastMode(true);
1384
1385
  await runtime.output("Fast mode enabled.");
1385
1386
  return commandConsumed();
1386
1387
  }
1387
1388
  if (arg === "off") {
1388
- runtime.session.setFastMode(false);
1389
+ await runtime.session.setFastMode(false);
1389
1390
  await runtime.output("Fast mode disabled.");
1390
1391
  return commandConsumed();
1391
1392
  }
@@ -1401,24 +1402,24 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
1401
1402
  }
1402
1403
  return usage("Usage: /fast [on|off|status]", runtime);
1403
1404
  },
1404
- handleTui: (command, runtime) => {
1405
+ handleTui: async (command, runtime) => {
1405
1406
  const arg = command.args.trim().toLowerCase();
1406
1407
  if (!arg || arg === "toggle") {
1407
- const enabled = runtime.ctx.session.toggleFastMode();
1408
+ const enabled = await runtime.ctx.session.toggleFastMode();
1408
1409
  refreshStatusLine(runtime.ctx);
1409
1410
  runtime.ctx.showStatus(`Fast mode ${enabled ? "enabled" : "disabled"}.`);
1410
1411
  runtime.ctx.editor.setText("");
1411
1412
  return;
1412
1413
  }
1413
1414
  if (arg === "on") {
1414
- runtime.ctx.session.setFastMode(true);
1415
+ await runtime.ctx.session.setFastMode(true);
1415
1416
  refreshStatusLine(runtime.ctx);
1416
1417
  runtime.ctx.showStatus("Fast mode enabled.");
1417
1418
  runtime.ctx.editor.setText("");
1418
1419
  return;
1419
1420
  }
1420
1421
  if (arg === "off") {
1421
- runtime.ctx.session.setFastMode(false);
1422
+ await runtime.ctx.session.setFastMode(false);
1422
1423
  refreshStatusLine(runtime.ctx);
1423
1424
  runtime.ctx.showStatus("Fast mode disabled.");
1424
1425
  runtime.ctx.editor.setText("");
@@ -1561,7 +1562,7 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
1561
1562
  runtime.ctx.editor.setText("");
1562
1563
  return;
1563
1564
  }
1564
- runtime.ctx.handleCopyCommand(undefined);
1565
+ runtime.ctx.handleCopyCommand();
1565
1566
  runtime.ctx.editor.setText("");
1566
1567
  },
1567
1568
  },
@@ -2104,6 +2105,12 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
2104
2105
  } else {
2105
2106
  await runtime.session.modelRegistry.refresh("offline", runtime.session.credentialSessionId);
2106
2107
  }
2108
+ assertProviderConfigLoaded(
2109
+ runtime.session.modelRegistry,
2110
+ result.providerId,
2111
+ result.modelsPath,
2112
+ result.credentialSource,
2113
+ );
2107
2114
  await runtime.output(
2108
2115
  recoveryHint
2109
2116
  ? `${formatProviderSetupResult(result)}\n${recoveryHint}`
@@ -2165,6 +2172,12 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
2165
2172
  } else {
2166
2173
  await runtime.ctx.session.modelRegistry.refresh("offline", runtime.ctx.session.credentialSessionId);
2167
2174
  }
2175
+ assertProviderConfigLoaded(
2176
+ runtime.ctx.session.modelRegistry,
2177
+ result.providerId,
2178
+ result.modelsPath,
2179
+ result.credentialSource,
2180
+ );
2168
2181
  runtime.ctx.showStatus(
2169
2182
  recoveryHint
2170
2183
  ? `${formatProviderSetupResult(result)}\n${recoveryHint}`
@@ -2582,7 +2595,7 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
2582
2595
  handle: async (command, runtime) => {
2583
2596
  if (!command.args) return regenerateSessionTitle(runtime);
2584
2597
  invalidateSessionTitleGeneration(runtime.sessionManager);
2585
- const ok = await runtime.sessionManager.setSessionName(command.args, "user");
2598
+ const ok = await runtime.session.setSessionName(command.args, "user");
2586
2599
  if (!ok) {
2587
2600
  await runtime.output("Session name not changed (a user-set name takes precedence).");
2588
2601
  return commandConsumed();
@@ -97,7 +97,9 @@ function currentPhases(runtime: SlashCommandRuntime): TodoPhase[] {
97
97
 
98
98
  function commitTodos(runtime: SlashCommandRuntime, phases: TodoPhase[]): void {
99
99
  runtime.session.setTodoPhases(phases);
100
- runtime.sessionManager.appendCustomEntry(USER_TODO_EDIT_CUSTOM_TYPE, { phases });
100
+ // Slash-command surfaces stay synchronous; a shared-append session publishes the
101
+ // entry through its admitted path in the background.
102
+ runtime.session.appendCustomEntryInBackground(USER_TODO_EDIT_CUSTOM_TYPE, { phases });
101
103
  }
102
104
 
103
105
  const TODO_HELP_TEXT = [
@@ -1,6 +1,7 @@
1
1
  import * as crypto from "node:crypto";
2
2
  import * as http from "node:http";
3
3
  import * as stream from "node:stream";
4
+ import { isRecord } from "@gajae-code/utils";
4
5
  import { AUTOROUTING_TIERS, type AutoroutingTier } from "../config/autorouting-contract";
5
6
  import { expandApplyPatchToEntries } from "../edit/modes/apply-patch";
6
7
 
@@ -84,10 +85,6 @@ function normalizeMetrics(metrics: DelegationHintMetrics): DelegationHintMetrics
84
85
  };
85
86
  }
86
87
 
87
- function isRecord(value: unknown): value is Record<string, unknown> {
88
- return value !== null && typeof value === "object" && !Array.isArray(value);
89
- }
90
-
91
88
  function parseDecision(content: string, choices: readonly Tier[]): KevDecision | undefined {
92
89
  let value: unknown;
93
90
  try {
@@ -2377,10 +2377,12 @@ export async function runSubprocessOnce(options: ExecutorOptions): Promise<Singl
2377
2377
  return send;
2378
2378
  },
2379
2379
  appendEntry: (customType, data) => {
2380
- session.sessionManager.appendCustomEntry(customType, data);
2380
+ // A shared-append session refuses the legacy append after its first
2381
+ // canonical publication; publish through the session's admitted path.
2382
+ void session.appendCustomEntryInBackground(customType, data);
2381
2383
  },
2382
2384
  setLabel: (targetId, label) => {
2383
- session.sessionManager.appendLabelChange(targetId, label);
2385
+ void session.appendLabelChangeInBackground(targetId, label);
2384
2386
  },
2385
2387
  getActiveTools: () => session.getActiveToolNames(),
2386
2388
  getAllTools: () => session.getAllToolNames(),
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "@gajae-code/utils";
1
2
  import type { AgentProgress, TaskToolDetails } from "./types";
2
3
 
3
4
  export type ProviderRetryKind = NonNullable<AgentProgress["retryState"]>["kind"];
@@ -52,10 +53,6 @@ export function providerProgressAgeLabel(retryState: NonNullable<AgentProgress["
52
53
  return `last provider progress ${ageSeconds}s ago`;
53
54
  }
54
55
 
55
- function isRecord(value: unknown): value is Record<string, unknown> {
56
- return Boolean(value) && typeof value === "object";
57
- }
58
-
59
56
  function isTaskToolDetails(value: unknown): value is TaskToolDetails {
60
57
  return (
61
58
  isRecord(value) && Array.isArray(value.results) && (value.progress === undefined || Array.isArray(value.progress))
@@ -2,6 +2,7 @@
2
2
  * JSON tree rendering utilities shared across tool renderers.
3
3
  */
4
4
  import { INTENT_FIELD } from "@gajae-code/agent-core";
5
+ import { isRecord } from "@gajae-code/utils";
5
6
  import type { Theme } from "../modes/theme/theme";
6
7
  import { truncateToWidth } from "./render-utils";
7
8
 
@@ -20,10 +21,6 @@ const ARGS_INLINE_PAIR_SEP_WIDTH = Bun.stringWidth(ARGS_INLINE_PAIR_SEP);
20
21
  const ARGS_INLINE_MORE = "…";
21
22
  const ARGS_INLINE_MORE_WIDTH = Bun.stringWidth(ARGS_INLINE_MORE);
22
23
 
23
- function isRecord(value: unknown): value is Record<string, unknown> {
24
- return !!value && typeof value === "object" && !Array.isArray(value);
25
- }
26
-
27
24
  /**
28
25
  * Format a scalar value for inline display.
29
26
  */
@@ -1,6 +1,6 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
- import { $which, isEnoent, logger } from "@gajae-code/utils";
3
+ import { $which, isEnoent, isRecord, logger } from "@gajae-code/utils";
4
4
  import type { DetectedRunner, RunnerTask, TaskRunner } from "../runner";
5
5
 
6
6
  interface PackageJsonInfo {
@@ -26,10 +26,6 @@ async function resolvePackageRunner(cwd: string): Promise<string> {
26
26
  return "npm run";
27
27
  }
28
28
 
29
- function isRecord(value: unknown): value is Record<string, unknown> {
30
- return typeof value === "object" && value !== null && !Array.isArray(value);
31
- }
32
-
33
29
  function shellQuote(value: string): string {
34
30
  return `'${value.replaceAll("'", `'\\''`)}'`;
35
31
  }
@@ -1,4 +1,3 @@
1
- import { execSync } from "node:child_process";
2
1
  import type { ClipboardImage } from "@gajae-code/natives";
3
2
 
4
3
  let nativeClipboardModule: typeof import("@gajae-code/natives") | undefined;
@@ -10,6 +9,7 @@ function nativeClipboard(): typeof import("@gajae-code/natives") {
10
9
 
11
10
  import { logger } from "@gajae-code/utils";
12
11
  import { settings } from "../config/settings";
12
+ import MAC_FILE_URL_SCRIPT from "./mac-file-urls.applescript" with { type: "text" };
13
13
 
14
14
  function hasDisplay(): boolean {
15
15
  return process.platform !== "linux" || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
@@ -285,11 +285,56 @@ function emitOsc52(text: string): boolean {
285
285
  return delivered;
286
286
  }
287
287
 
288
+ type SpawnCaptureOptions = { input?: string; timeoutMs?: number };
289
+
290
+ /**
291
+ * Run a subprocess and capture its stdout without blocking the event loop.
292
+ * A synchronous `execSync` parks the render loop until the child exits or the
293
+ * timeout fires, so a slow or hung clipboard helper would freeze the TUI.
294
+ *
295
+ * @throws Error when the child fails to spawn, is killed by the timeout, or
296
+ * exits with a non-zero status.
297
+ */
298
+ async function spawnCapture(cmd: string[], options: SpawnCaptureOptions = {}): Promise<string> {
299
+ const timeoutMs = options.timeoutMs ?? 2000;
300
+ const proc = Bun.spawn(cmd, {
301
+ stdout: "pipe",
302
+ stderr: "ignore",
303
+ stdin: options.input !== undefined ? Buffer.from(options.input) : "ignore",
304
+ });
305
+ let timedOut = false;
306
+ const timer = setTimeout(() => {
307
+ timedOut = true;
308
+ proc.kill();
309
+ }, timeoutMs);
310
+ try {
311
+ const stdout = await new Response(proc.stdout).text();
312
+ await proc.exited;
313
+ if (timedOut) {
314
+ throw new Error(`${cmd[0]} timed out after ${timeoutMs}ms`);
315
+ }
316
+ if (proc.exitCode !== 0) {
317
+ throw new Error(`${cmd[0]} exited with code ${proc.exitCode}`);
318
+ }
319
+ return stdout;
320
+ } finally {
321
+ clearTimeout(timer);
322
+ }
323
+ }
324
+
325
+ // Clipboard writes that spawn a helper finish asynchronously; chain them so the
326
+ // last copy invoked is the one left on the clipboard.
327
+ let clipboardWriteChain: Promise<void> = Promise.resolve();
328
+
288
329
  async function copyToClipboardNative(text: string): Promise<boolean> {
330
+ const previousWrite = clipboardWriteChain;
331
+ const { promise, resolve } = Promise.withResolvers<void>();
332
+ clipboardWriteChain = promise;
333
+ await previousWrite;
289
334
  try {
290
335
  if (process.env.TERMUX_VERSION) {
291
336
  try {
292
- execSync("termux-clipboard-set", { input: text, timeout: 5000 });
337
+ await spawnCapture(["termux-clipboard-set"], { input: text, timeoutMs: 5000 });
293
338
  return true;
294
339
  } catch {
295
340
  // Fall through to native
@@ -303,6 +348,8 @@ async function copyToClipboardNative(text: string): Promise<boolean> {
303
348
  return true;
304
349
  } catch {
305
350
  return false;
351
+ } finally {
352
+ resolve();
306
353
  }
307
354
  }
308
355
 
@@ -431,6 +478,112 @@ async function readImageViaPowerShell(): Promise<ClipboardImage | null> {
431
478
  }
432
479
  }
433
480
 
481
+ /**
482
+ * Read file paths from the macOS pasteboard's `public.file-url` representation.
483
+ *
484
+ * A Finder Cmd+C on an image file puts only file URLs plus a generated file-icon bitmap on the
485
+ * pasteboard; reading the bitmap first would attach the generic icon instead of the file.
486
+ * Returns an empty list off Darwin, under the `ssh` clipboard transport (the local pasteboard is
487
+ * not the configured clipboard), when AppleScript is unavailable, or when no file URL is present.
488
+ */
489
+ export async function readMacFileUrlsFromClipboard(): Promise<string[]> {
490
+ if (process.platform !== "darwin" || getClipboardTransportConfig().transport === "ssh") return [];
491
+ try {
492
+ const stdout = await spawnCapture(["osascript", "-"], { input: MAC_FILE_URL_SCRIPT });
493
+ return stdout
494
+ .split(/\r?\n/)
495
+ .map(line => line.trim())
496
+ .filter(line => line.length > 0);
497
+ } catch (error) {
498
+ logger.warn("clipboard: failed to read macOS file URLs", { error: String(error) });
499
+ return [];
500
+ }
501
+ }
502
+
503
+ // PowerShell one-liner that emits the Windows clipboard text as UTF-8, or nothing when the
504
+ // clipboard holds no text. `[Console]::Out.Write` avoids the trailing newline Write-Output adds.
505
+ const POWERSHELL_TEXT_SCRIPT = `
506
+ $ErrorActionPreference = 'Stop'
507
+ [Console]::OutputEncoding = [Text.Encoding]::UTF8
508
+ [Console]::Out.Write([string](Get-Clipboard -Raw))
509
+ `;
510
+
511
+ /**
512
+ * Read clipboard text through Windows PowerShell (native win32 or the WSL host over interop).
513
+ * Returns null when the bridge fails so WSL callers can fall through to wl-paste/xclip; an empty
514
+ * string is a successful "no text" read.
515
+ */
516
+ async function readTextViaPowerShell(): Promise<string | null> {
517
+ try {
518
+ const proc = Bun.spawn(["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", POWERSHELL_TEXT_SCRIPT], {
519
+ stdout: "pipe",
520
+ stderr: "ignore",
521
+ stdin: "ignore",
522
+ });
523
+ const timer = setTimeout(() => proc.kill(), POWERSHELL_TIMEOUT_MS);
524
+ let stdout = "";
525
+ try {
526
+ stdout = await new Response(proc.stdout).text();
527
+ await proc.exited;
528
+ } catch (err) {
529
+ logger.warn("clipboard: powershell text read failed", { error: String(err) });
530
+ return null;
531
+ } finally {
532
+ clearTimeout(timer);
533
+ }
534
+ if (proc.exitCode !== 0) return null;
535
+ return stdout.replaceAll("\r\n", "\n");
536
+ } catch {
537
+ return null;
538
+ }
539
+ }
540
+
541
+ async function readTextFromX11Clipboard(): Promise<string> {
542
+ try {
543
+ return await spawnCapture(["xclip", "-selection", "clipboard", "-o"]);
544
+ } catch {
545
+ return await spawnCapture(["xsel", "--clipboard", "--output"]);
546
+ }
547
+ }
548
+
549
+ /**
550
+ * Read plain text from the system clipboard for the smart-paste fallback.
551
+ *
552
+ * Under the `ssh` clipboard transport this reads the configured host's clipboard and throws
553
+ * {@link ClipboardTransportError} on failure; it never falls back to the local clipboard.
554
+ * Otherwise it uses `pbpaste` on macOS, PowerShell on Windows/WSL, `termux-clipboard-get`, or
555
+ * wl-paste/xclip/xsel on Linux. Returns an empty string when no text can be read.
556
+ */
557
+ export async function readTextFromClipboard(): Promise<string> {
558
+ const { transport, sshHost } = getClipboardTransportConfig();
559
+ if (transport === "ssh") return await pasteFromClipboardViaSsh(sshHost);
560
+ try {
561
+ const platform = process.platform;
562
+ if (platform === "darwin") return await spawnCapture(["pbpaste"]);
563
+ if (platform === "win32") return (await readTextViaPowerShell()) ?? "";
564
+ if (process.env.TERMUX_VERSION) return await spawnCapture(["termux-clipboard-get"]);
565
+ if (isWsl()) {
566
+ const text = await readTextViaPowerShell();
567
+ if (text !== null) return text;
568
+ // Bridge failed: fall through to the wl-paste/xclip paths below.
569
+ }
570
+ const hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);
571
+ const hasX11Display = Boolean(process.env.DISPLAY);
572
+ if (hasWaylandDisplay) {
573
+ try {
574
+ return await spawnCapture(["wl-paste", "--type", "text", "--no-newline"]);
575
+ } catch {
576
+ if (hasX11Display) return await readTextFromX11Clipboard();
577
+ }
578
+ } else if (hasX11Display) {
579
+ return await readTextFromX11Clipboard();
580
+ }
581
+ } catch (error) {
582
+ logger.warn("clipboard: failed to read clipboard text", { error: String(error) });
583
+ }
584
+ return "";
585
+ }
586
+
434
587
  /**
435
588
  * Read an image from the system clipboard.
436
589
  *
@@ -0,0 +1,37 @@
1
+ -- Returns the POSIX paths of every file URL currently on the macOS
2
+ -- pasteboard, one path per line. `pbpaste(1)` only surfaces plain text,
3
+ -- EPS, or RTF, so a Finder Cmd+C (which puts only a `public.file-url`
4
+ -- representation on the pasteboard) makes `pbpaste` empty. The
5
+ -- `«class furl»` coercion reaches the file-URL representation directly and
6
+ -- works for both single-file and multi-file selections.
7
+ --
8
+ -- The coercion is guarded by `clipboard info for «class furl»`: AppleScript
9
+ -- happily coerces plain *text* into a file URL by treating it as an HFS
10
+ -- path, so an unguarded cast turns a copied `https://i.can.ac/x.png` string
11
+ -- into the mangled `/https/::i.can.ac:x.png` (HFS `:`↔`/` swap) and the
12
+ -- paste dead-ends with "Image not found" instead of falling back to pasting
13
+ -- the text. `clipboard info for` inspects the actual pasteboard types, so
14
+ -- it is `{}` unless a real `public.file-url` representation is present.
15
+ --
16
+ -- The `try` blocks suppress the `-1700` "can't make … into type" error
17
+ -- AppleScript raises when the clipboard holds no file URLs, so the script's
18
+ -- exit status only reflects `osascript` itself.
19
+ on run
20
+ set output to ""
21
+ try
22
+ if (clipboard info for «class furl») is {} then return output
23
+ set theClip to the clipboard as «class furl»
24
+ if class of theClip is list then
25
+ repeat with anItem in theClip
26
+ try
27
+ set output to output & POSIX path of anItem & linefeed
28
+ end try
29
+ end repeat
30
+ else
31
+ try
32
+ set output to POSIX path of theClip & linefeed
33
+ end try
34
+ end if
35
+ end try
36
+ return output
37
+ end run
@@ -432,3 +432,8 @@ export function locatePastedImageReferenceAroundCursor(
432
432
  if (cursorCol === placeholderEnd) return { imageIndex, startCol, endCol: placeholderEnd };
433
433
  }
434
434
  }
435
+
436
+ /** Image files among absolute paths (macOS pasteboard file list), in order. */
437
+ export function imageFilePathsFromList(paths: readonly string[]): string[] {
438
+ return paths.filter(candidate => path.posix.isAbsolute(candidate) && IMAGE_FILE_EXTENSION_PATTERN.test(candidate));
439
+ }
@@ -83,6 +83,11 @@ const PROVIDER_META: Record<SearchProviderId, ProviderMeta> = {
83
83
  label: "SearXNG",
84
84
  load: async () => new (await import("./providers/searxng")).SearXNGProvider(),
85
85
  },
86
+ keenable: {
87
+ id: "keenable",
88
+ label: "Keenable",
89
+ load: async () => new (await import("./providers/keenable")).KeenableProvider(),
90
+ },
86
91
  duckduckgo: {
87
92
  id: "duckduckgo",
88
93
  label: "DuckDuckGo",
@@ -134,6 +139,7 @@ export const SEARCH_PROVIDER_ORDER: SearchProviderId[] = [
134
139
  "kagi",
135
140
  "synthetic",
136
141
  "searxng",
142
+ "keenable",
137
143
  ];
138
144
 
139
145
  const MODEL_PROVIDER_TO_SEARCH: Record<string, SearchProviderId> = {