talon-agent 3.32.1 → 3.33.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 (138) hide show
  1. package/package.json +1 -1
  2. package/src/backend/claude-sdk/constants.ts +1 -6
  3. package/src/backend/claude-sdk/index.ts +2 -11
  4. package/src/backend/claude-sdk/models/parsing.ts +2 -2
  5. package/src/backend/claude-sdk/plan-usage.ts +0 -5
  6. package/src/backend/claude-sdk/stream.ts +1 -1
  7. package/src/backend/codex/auth.ts +2 -2
  8. package/src/backend/codex/constants.ts +0 -21
  9. package/src/backend/codex/handler/index.ts +0 -1
  10. package/src/backend/codex/mcp-config.ts +2 -2
  11. package/src/backend/codex/plan-usage.ts +0 -5
  12. package/src/backend/codex/state.ts +1 -1
  13. package/src/backend/codex/token-usage.ts +1 -1
  14. package/src/backend/kilo/factory.ts +39 -119
  15. package/src/backend/kilo/handler/index.ts +1 -11
  16. package/src/backend/kilo/handler/message.ts +20 -317
  17. package/src/backend/kilo/index.ts +0 -6
  18. package/src/backend/kilo/server.ts +55 -292
  19. package/src/backend/kilo/sessions.ts +5 -86
  20. package/src/backend/openai-agents/handler/index.ts +0 -1
  21. package/src/backend/openai-agents/handler/state.ts +0 -5
  22. package/src/backend/openai-agents/init.ts +1 -18
  23. package/src/backend/opencode/factory.ts +41 -118
  24. package/src/backend/opencode/handler/index.ts +1 -11
  25. package/src/backend/opencode/handler/message.ts +20 -321
  26. package/src/backend/opencode/index.ts +0 -4
  27. package/src/backend/opencode/server.ts +56 -225
  28. package/src/backend/opencode/sessions.ts +5 -86
  29. package/src/backend/remote-server/chat-turn.ts +359 -0
  30. package/src/backend/remote-server/client.ts +1 -1
  31. package/src/backend/remote-server/events.ts +1 -1
  32. package/src/backend/remote-server/factory.ts +150 -0
  33. package/src/backend/remote-server/index.ts +15 -43
  34. package/src/backend/remote-server/mcp.ts +1 -4
  35. package/src/backend/remote-server/model-catalog/catalog.ts +1 -1
  36. package/src/backend/remote-server/model-catalog/index.ts +1 -15
  37. package/src/backend/remote-server/model-catalog/provider.ts +0 -1
  38. package/src/backend/remote-server/server-bindings.ts +232 -0
  39. package/src/backend/remote-server/sse-stream.ts +1 -3
  40. package/src/backend/remote-server/turn-timeout.ts +1 -1
  41. package/src/backend/{kilo/handler → remote-server}/turn.ts +103 -67
  42. package/src/backend/shared/index.ts +7 -43
  43. package/src/cli/logs.ts +1 -1
  44. package/src/cli/status.ts +1 -1
  45. package/src/core/agent-runtime/backend-registry.ts +1 -1
  46. package/src/core/agent-runtime/capabilities.ts +1 -1
  47. package/src/core/agent-runtime/events.ts +1 -1
  48. package/src/core/background/heartbeat/agent.ts +1 -1
  49. package/src/core/background/heartbeat/index.ts +1 -2
  50. package/src/core/background/isolated-agent.ts +1 -1
  51. package/src/core/background/triggers/exit.ts +1 -1
  52. package/src/core/background/triggers/index.ts +1 -1
  53. package/src/core/bus/events.ts +2 -2
  54. package/src/core/doctor.ts +1 -1
  55. package/src/core/engine/backend-controller/index.ts +1 -3
  56. package/src/core/engine/backend-controller/rebind.ts +2 -2
  57. package/src/core/engine/dispatcher.ts +1 -15
  58. package/src/core/engine/gateway-actions/index.ts +0 -3
  59. package/src/core/engine/gateway-actions/types.ts +1 -1
  60. package/src/core/frontend-runtime/capabilities.ts +0 -2
  61. package/src/core/frontend-runtime/index.ts +1 -6
  62. package/src/core/frontend-runtime/routing.ts +0 -1
  63. package/src/core/mcp-hub/children.ts +0 -5
  64. package/src/core/mesh/bridge-links.ts +319 -0
  65. package/src/core/mesh/common.ts +30 -0
  66. package/src/core/mesh/device-files.ts +710 -0
  67. package/src/core/mesh/index.ts +1 -18
  68. package/src/core/mesh/service.ts +72 -894
  69. package/src/core/models/active-model.ts +0 -19
  70. package/src/core/plugin/index.ts +0 -1
  71. package/src/core/plugin/registry.ts +1 -1
  72. package/src/core/prompt/templates.ts +0 -5
  73. package/src/core/scripting/lua-runner.ts +1 -1
  74. package/src/core/scripts/runner.ts +1 -1
  75. package/src/core/soul/critic.ts +1 -1
  76. package/src/core/soul/embedder.ts +2 -2
  77. package/src/core/soul/governance.ts +1 -1
  78. package/src/core/soul/hdc.ts +1 -1
  79. package/src/core/soul/reflex.ts +2 -2
  80. package/src/core/soul/retrieve.ts +1 -1
  81. package/src/core/soul/signals.ts +4 -4
  82. package/src/core/soul/types.ts +1 -1
  83. package/src/core/tasks/index.ts +0 -4
  84. package/src/core/tasks/types.ts +1 -1
  85. package/src/core/tools/index.ts +1 -6
  86. package/src/core/tools/mcp-env.ts +3 -33
  87. package/src/core/types.ts +1 -1
  88. package/src/core/update/self-update.ts +1 -1
  89. package/src/core/vfs/fusefs.ts +1 -1
  90. package/src/core/vfs/types.ts +1 -1
  91. package/src/core/weaver/index.ts +1 -1
  92. package/src/core/weaver/typing-loop.ts +1 -1
  93. package/src/frontend/discord/actions/types.ts +1 -1
  94. package/src/frontend/discord/commands/definitions.ts +1 -1
  95. package/src/frontend/discord/handlers/access.ts +7 -61
  96. package/src/frontend/discord/handlers/index.ts +2 -15
  97. package/src/frontend/discord/handlers/registry.ts +0 -6
  98. package/src/frontend/discord/handlers/state.ts +15 -8
  99. package/src/frontend/native/protocol.ts +1 -4
  100. package/src/frontend/native/server.ts +392 -324
  101. package/src/frontend/shared/access.ts +152 -0
  102. package/src/frontend/shared/status-context.ts +1 -1
  103. package/src/frontend/telegram/actions/types.ts +1 -1
  104. package/src/frontend/telegram/commands/index.ts +1 -1
  105. package/src/frontend/telegram/commands/state.ts +1 -1
  106. package/src/frontend/telegram/handlers/access.ts +8 -25
  107. package/src/frontend/telegram/handlers/index.ts +0 -1
  108. package/src/frontend/telegram/handlers/queue.ts +3 -35
  109. package/src/frontend/telegram/handlers/state.ts +15 -8
  110. package/src/frontend/telegram/helpers/menu.ts +1 -1
  111. package/src/frontend/terminal/commands.ts +1 -4
  112. package/src/frontend/terminal/renderer.ts +1 -1
  113. package/src/frontend/whatsapp/actions/chat-info.ts +0 -3
  114. package/src/frontend/whatsapp/actions/messaging.ts +1 -7
  115. package/src/frontend/whatsapp/actions/shared.ts +1 -1
  116. package/src/frontend/whatsapp/actions/types.ts +1 -1
  117. package/src/frontend/whatsapp/formatting.ts +1 -1
  118. package/src/frontend/whatsapp/media-store.ts +1 -1
  119. package/src/frontend/whatsapp/pins.ts +0 -5
  120. package/src/native/fusefs.ts +3 -3
  121. package/src/native/scheduler-core.ts +1 -1
  122. package/src/native/warden.ts +2 -2
  123. package/src/plugins/mempalace/provision.ts +1 -5
  124. package/src/plugins/playwright/provision.ts +1 -1
  125. package/src/storage/db.ts +1 -1
  126. package/src/storage/goal-store.ts +1 -5
  127. package/src/storage/metrics.ts +0 -5
  128. package/src/storage/repositories/scripts-repo.ts +0 -5
  129. package/src/storage/scheduled-store.ts +1 -5
  130. package/src/storage/script-store.ts +5 -13
  131. package/src/storage/sessions.ts +0 -3
  132. package/src/storage/skill-store.ts +3 -3
  133. package/src/util/exec-output.ts +1 -1
  134. package/src/util/mcp-launcher.ts +3 -0
  135. package/src/backend/kilo/events.ts +0 -60
  136. package/src/backend/kilo/handler/state.ts +0 -9
  137. package/src/backend/opencode/handler/state.ts +0 -9
  138. package/src/backend/opencode/handler/turn.ts +0 -314
@@ -1,19 +1,14 @@
1
1
  /**
2
- * Kilo server lifecycle — thin wrapper around `backend/remote-server/`.
2
+ * Kilo server lifecycle — the Kilo profile bound through
3
+ * `backend/remote-server/server-bindings.ts`.
3
4
  *
4
- * The MCP / session / provider plumbing is identical to OpenCode (Kilo
5
- * is a fork of OpenCode that exposes the same HTTP API), so this module
6
- * keeps only the Kilo-specific bits:
7
- *
8
- * - Constants (port 4097, system-prompt suffix wording).
9
- * - SDK-specific client factory (`createKiloClient` + `createKiloServer`).
10
- * - Backend-specific model parser (the `kilo/` prefix hint).
11
- * - Pre-warm hook that triggers immediately at init.
12
- *
13
- * The shared machinery (server spawn, MCP registration, session creation,
14
- * provider resolution) lives in `backend/remote-server/`. All the
15
- * existing exports from this module are preserved for back-compat with
16
- * the handler / tests / heartbeat code that already imports them.
5
+ * Kilo is a fork of OpenCode with the same HTTP API, so the server spawn,
6
+ * MCP registration, session creation, and provider resolution are the
7
+ * shared family implementation. This module holds only what is Kilo's:
8
+ * the SDK constructors, port 4097, the text-or-tools delivery contract,
9
+ * and the `kilo/`-prefix model parser. The exports keep their historical
10
+ * names — the models module, one-shot runner, tests, and
11
+ * `vi.mock("../backend/kilo/server.js")` all address them.
17
12
  */
18
13
 
19
14
  import {
@@ -21,249 +16,14 @@ import {
21
16
  createKiloServer,
22
17
  type KiloClient,
23
18
  } from "@kilocode/sdk/v2";
24
- import type { TalonConfig } from "../../util/config.js";
25
- import type { FrontendName } from "../../core/agent-runtime/backend-registry.js";
26
- import { buildDeliveryContract } from "../shared/delivery-contract.js";
27
- import {
28
- guessProviderID,
29
- getBucketPriority,
30
- normalizeModelLookup,
31
- parseRemoteModelQuery as parseOpenCodeModelQuery,
32
- } from "../remote-server/model-catalog/index.js";
33
19
  import {
34
- createRemoteServerState,
35
- ensureRemoteServer as ensureRemoteServerShared,
36
- stopRemoteServer,
37
- ensureChatMcpServer as ensureChatMcpServerShared,
38
- ensurePluginMcpServers as ensurePluginMcpServersShared,
39
- buildToolOverrides as buildToolOverridesShared,
40
- disconnectChatMcpServer as disconnectChatMcpServerShared,
41
- refreshPluginMcpServers as refreshPluginMcpServersShared,
42
- ensureRemoteSession,
43
- warmRemoteSession,
44
- resolveProviderID as resolveProviderIDShared,
45
- getRegisteredMcpServerNames as getRegisteredMcpServerNamesShared,
46
- errMsg as sharedErrMsg,
47
- TALON_MCP_SERVER_NAME as SHARED_TALON_MCP_SERVER_NAME,
48
- type RemoteServerState,
49
- } from "../remote-server/index.js";
50
-
51
- // ── Constants ───────────────────────────────────────────────────────────────
52
-
53
- /** Loopback hostname Talon binds the Kilo server on — never exposed externally. */
54
- export const KILO_HOSTNAME = "127.0.0.1";
55
- /** Default TCP port for the local Kilo server. Overridable via `KILO_PORT`
56
- * env var so integration tests can spawn an isolated Kilo server alongside
57
- * a running production Talon (which holds the default 4097). */
58
- export const KILO_PORT = Number(process.env.KILO_PORT ?? 4097);
59
- /** Convenience URL composed from KILO_HOSTNAME + KILO_PORT. */
60
- export const KILO_BASE_URL = `http://${KILO_HOSTNAME}:${KILO_PORT}`;
61
- /** Re-export of the chat MCP server name prefix shared across backends. */
62
- export const TALON_MCP_SERVER_NAME = SHARED_TALON_MCP_SERVER_NAME;
63
-
64
- /**
65
- * System-prompt suffix appended to the user-configured system prompt.
66
- *
67
- * Kilo delivery model: the model's reply reaches the user via either
68
- *
69
- * 1. A `type: "text"` part — what most Kilo-routed models emit by
70
- * default (DeepSeek, GLM, openrouter routes). Talon walks the
71
- * `parts` list at end of turn and ships text-part content via
72
- * `onTextBlock`. Reasoning parts are dropped as scratchpad.
73
- *
74
- * 2. A delivery tool — `end_turn` / `send` / `react`. The tool itself
75
- * bridges to Telegram, so it's the right path when you need
76
- * reply-to targeting, buttons, photos, polls, etc.
77
- *
78
- * Both routes work; pick whichever fits the message. The shared
79
- * text-or-tools contract (prompts/system/contract-text-or-tools.md)
80
- * documents the choice — the tool descriptions carry the detail.
81
- * Telegram-shaped tool names: this constant is static and the prior
82
- * hand-written text hardcoded the same names.
83
- */
84
- export function kiloSystemPromptSuffix(frontend: string): string {
85
- return `\n\n${buildDeliveryContract("text-or-tools", frontend)}\n`;
86
- }
87
-
88
- /** Telegram-shaped default, kept for one-shot (cross-surface) paths. */
89
- export const KILO_SYSTEM_PROMPT_SUFFIX = kiloSystemPromptSuffix("telegram");
90
-
91
- // ── State ───────────────────────────────────────────────────────────────────
92
-
93
- const state: RemoteServerState<KiloClient> =
94
- createRemoteServerState<KiloClient>({
95
- label: "Kilo",
96
- hostname: KILO_HOSTNAME,
97
- port: KILO_PORT,
98
- });
99
-
100
- function createStrictKiloClient(baseUrl: string): KiloClient {
101
- return createKiloClient({
102
- baseUrl,
103
- throwOnError: true,
104
- });
105
- }
106
-
107
- // ── Init / teardown ─────────────────────────────────────────────────────────
108
-
109
- /**
110
- * Initialise the Kilo backend.
111
- *
112
- * Stores the config + gateway-port resolver + frontend label needed by
113
- * downstream helpers. Does NOT spawn the Kilo server — that happens
114
- * lazily on the first `ensureServer()` call (so empty / heartbeat-only
115
- * Talon installs don't pay the startup cost until they need it).
116
- */
117
- export function initKiloAgent(
118
- cfg: TalonConfig,
119
- getGatewayPort?: () => number,
120
- frontend?: FrontendName,
121
- ): void {
122
- state.config = cfg;
123
- if (getGatewayPort) state.gatewayPortFn = getGatewayPort;
124
- if (frontend) state.frontendName = frontend;
125
- }
20
+ bindRemoteServer,
21
+ type RemoteModelSelection,
22
+ } from "../remote-server/server-bindings.js";
126
23
 
127
24
  /**
128
- * Callbacks run when the server stops — cache invalidation lives with the
129
- * caches. The models module registers its clear here at load time, so the
130
- * server never has to import it (which would be a cycle).
131
- */
132
- const stopHooks = new Set<() => void>();
133
-
134
- /** Register a callback to run whenever the Kilo server is stopped. */
135
- export function onServerStop(hook: () => void): void {
136
- stopHooks.add(hook);
137
- }
138
-
139
- /**
140
- * Stop the local Kilo server (if we own it) and clear caches.
141
- *
142
- * Idempotent: safe to call multiple times. If we reused a pre-existing
143
- * server, this leaves it running — we don't own it.
144
- */
145
- export function stopKiloServer(): void {
146
- stopRemoteServer(state, () => {
147
- for (const hook of stopHooks) hook();
148
- });
149
- }
150
-
151
- // ── Server lifecycle ────────────────────────────────────────────────────────
152
-
153
- /**
154
- * Lazily start (or reuse) the local Kilo server and return a strict client.
155
- *
156
- * Delegates to the shared `ensureRemoteServer` helper which handles the
157
- * spawn-race, the reuse-existing-server probe (`/global/health`), and
158
- * the wrap-after-bind fallback.
159
- */
160
- export function ensureServer(): Promise<KiloClient> {
161
- return ensureRemoteServerShared({
162
- state,
163
- createClient: createStrictKiloClient,
164
- createServer: ({ hostname, port, timeout }) =>
165
- createKiloServer({ hostname, port, timeout }),
166
- });
167
- }
168
-
169
- // ── MCP server registration ─────────────────────────────────────────────────
170
-
171
- /**
172
- * Ensure the per-chat Talon MCP server is registered with Kilo. See
173
- * `backend/remote-server/mcp.ts` for the full rationale + visibility-model
174
- * explanation; this wrapper just passes the Kilo state through.
175
- */
176
- export function ensureChatMcpServer(
177
- oc: KiloClient,
178
- chatId: string,
179
- ): Promise<string> {
180
- return ensureChatMcpServerShared(oc, state, chatId);
181
- }
182
-
183
- /** Register all plugin-provided MCP servers with Kilo. */
184
- export function ensurePluginMcpServers(
185
- oc: KiloClient,
186
- chatId: string,
187
- ): Promise<string[]> {
188
- return ensurePluginMcpServersShared(oc, state, chatId);
189
- }
190
-
191
- /**
192
- * Build a `tools` override map that enables ONLY this chat's Talon tools.
193
- *
194
- * Kilo's session-level `permission` rules cover *execution* hiding; this
195
- * `tools` map covers *visibility* — necessary because Kilo exposes every
196
- * registered MCP server's tools to every session by default.
197
- */
198
- export function buildToolOverrides(
199
- oc: KiloClient,
200
- chatServerName: string,
201
- pluginServerNames: readonly string[] = [],
202
- ): Promise<Record<string, boolean> | undefined> {
203
- return buildToolOverridesShared(oc, state, chatServerName, pluginServerNames);
204
- }
205
-
206
- /** Disconnect a per-chat MCP server (explicit teardown for hot-swap paths). */
207
- export function disconnectChatMcpServer(
208
- oc: KiloClient,
209
- serverName: string,
210
- ): Promise<void> {
211
- return disconnectChatMcpServerShared(oc, state, serverName);
212
- }
213
-
214
- export async function refreshPluginMcpServers(chatId: string) {
215
- const oc = await ensureServer();
216
- return refreshPluginMcpServersShared(oc, state, chatId);
217
- }
218
-
219
- export function updateSystemPrompt(prompt: string): void {
220
- if (state.config) state.config.systemPrompt = prompt;
221
- }
222
-
223
- // ── Session management ─────────────────────────────────────────────────────
224
-
225
- /**
226
- * Ensure a Kilo session exists for this chat. Resumes the stored session
227
- * id if `session.get` confirms it's still alive; otherwise resets and
228
- * creates a fresh session with Talon's standard permission ruleset.
229
- */
230
- export function ensureSession(oc: KiloClient, chatId: string): Promise<string> {
231
- return ensureRemoteSession(oc, state, chatId);
232
- }
233
-
234
- /**
235
- * Front-load a chat's cold start after `/reset`. Mirrors the Claude
236
- * backend's `warmSession` so the `sessions` capability slot behaves the
237
- * same across backends. Never throws — see `warmRemoteSession`.
238
- */
239
- export function warmSession(chatId: string): Promise<void> {
240
- return warmRemoteSession(state, chatId, {
241
- ensureServer,
242
- ensureSession,
243
- ensureChatMcpServer,
244
- ensurePluginMcpServers,
245
- });
246
- }
247
-
248
- // ── Provider resolution ────────────────────────────────────────────────────
249
-
250
- /**
251
- * Resolve a model id to its provider id by querying Kilo's provider list.
252
- * The Kilo-specific bucket-priority + name-prefix heuristic comes from
253
- * `./models.ts`.
254
- */
255
- export function resolveProviderID(
256
- oc: KiloClient,
257
- modelID: string,
258
- ): Promise<string> {
259
- return resolveProviderIDShared(oc, state, modelID, {
260
- guessProviderID,
261
- getBucketPriority,
262
- });
263
- }
264
-
265
- /**
266
- * Parse the stored model-selection string into a `{providerID?, modelID}` pair.
25
+ * Parse the stored model-selection string into a `{providerID?, modelID}`
26
+ * pair.
267
27
  *
268
28
  * Kilo model ids frequently contain `/` and `:` inside the model.id itself
269
29
  * (e.g. `inclusionai/ling-2.6-1t:free`, `deepseek/deepseek-v4-flash:free`).
@@ -279,10 +39,9 @@ export function resolveProviderID(
279
39
  * its own provider in front, producing
280
40
  * `Model not found: opencode/kilo/deepseek/deepseek-v4-flash:free`.
281
41
  */
282
- export function parseStoredKiloModelSelection(value: string): {
283
- providerID?: string;
284
- modelID: string;
285
- } {
42
+ export function parseStoredKiloModelSelection(
43
+ value: string,
44
+ ): RemoteModelSelection {
286
45
  const trimmed = value.trim();
287
46
  if (trimmed.startsWith("kilo/")) {
288
47
  return {
@@ -296,39 +55,43 @@ export function parseStoredKiloModelSelection(value: string): {
296
55
  };
297
56
  }
298
57
 
299
- // ── Internal accessors ─────────────────────────────────────────────────────
300
-
301
- export function getConfig(): TalonConfig {
302
- if (!state.config) {
303
- throw new Error("Kilo agent not initialized — call initKiloAgent first");
304
- }
305
- return state.config;
306
- }
307
-
308
58
  /**
309
- * Snapshot of the locally-cached MCP server registrations. Test-only:
310
- * Kilo's `GET /mcp` returns `{}` regardless of state, so integration
311
- * tests use this to assert concurrent chat registrations are retained.
59
+ * Kilo delivery model: the reply reaches the user either as a `text` part
60
+ * (what most Kilo-routed models emit by default — DeepSeek, GLM,
61
+ * openrouter routes) or through a delivery tool (`end_turn` / `send` /
62
+ * `react`) when reply-to targeting, buttons, photos, or polls are needed.
63
+ * Both routes work; the shared text-or-tools contract documents the
64
+ * choice.
312
65
  */
313
- export function getRegisteredMcpServerNames(): string[] {
314
- return getRegisteredMcpServerNamesShared(state);
315
- }
316
-
317
- export function getGatewayPortFn(): () => number {
318
- return state.gatewayPortFn;
319
- }
320
-
321
- export function getFrontendName(): FrontendName {
322
- return state.frontendName;
323
- }
324
-
325
- /** Common error→message helper, re-exported for legacy importers. */
326
- export const errMsg = sharedErrMsg;
327
-
328
- // Re-export the model-helper imports for kilo-internal consumers
329
- export {
330
- guessProviderID,
331
- getBucketPriority,
332
- normalizeModelLookup,
333
- parseOpenCodeModelQuery,
334
- };
66
+ const kilo = bindRemoteServer<KiloClient>({
67
+ label: "Kilo",
68
+ defaultPort: 4097,
69
+ portEnv: "KILO_PORT",
70
+ deliveryContract: "text-or-tools",
71
+ createClient: (baseUrl) => createKiloClient({ baseUrl, throwOnError: true }),
72
+ createServer: ({ hostname, port, timeout }) =>
73
+ createKiloServer({ hostname, port, timeout }),
74
+ parseModelSelection: parseStoredKiloModelSelection,
75
+ });
76
+
77
+ export const KILO_BASE_URL = kilo.baseUrl;
78
+ export const kiloSystemPromptSuffix = kilo.systemPromptSuffix;
79
+ export const KILO_SYSTEM_PROMPT_SUFFIX = kilo.defaultSystemPromptSuffix;
80
+ export const initKiloAgent = kilo.init;
81
+ export const stopKiloServer = kilo.stop;
82
+ export const {
83
+ onServerStop,
84
+ ensureServer,
85
+ ensureChatMcpServer,
86
+ ensurePluginMcpServers,
87
+ buildToolOverrides,
88
+ disconnectChatMcpServer,
89
+ refreshPluginMcpServers,
90
+ updateSystemPrompt,
91
+ ensureSession,
92
+ warmSession,
93
+ resolveProviderID,
94
+ getConfig,
95
+ getRegisteredMcpServerNames,
96
+ errMsg,
97
+ } = kilo;
@@ -1,118 +1,37 @@
1
1
  /**
2
- * Kilo session helpers — thin wrapper around
3
- * `backend/remote-server/session-helpers.ts`.
4
- *
5
- * Kilo organises a session as an ordered list of `messages`, each with a
6
- * typed parts array (text / tool / reasoning / step-start / step-finish).
7
- * The wire format is identical to OpenCode (Kilo is a fork), so the
8
- * actual parsing, summarisation, snapshot construction, and question-
9
- * rejection logic lives in the shared module. This file binds the Kilo
10
- * backend label and re-exports under Kilo-named symbols for back-compat
11
- * with handler / index imports.
2
+ * Kilo session helpers — the shared `remote-server/session-helpers.ts`
3
+ * bound to the Kilo client, re-exported under Kilo-named symbols for the
4
+ * handler / index / test imports.
12
5
  */
13
6
 
14
7
  import type { KiloClient } from "@kilocode/sdk/v2";
15
8
  import {
16
- REMOTE_SESSION_MESSAGE_LIMIT,
17
9
  extractPartsSummary as extractPartsSummaryShared,
18
10
  extractAssistantUsage as extractAssistantUsageShared,
19
11
  summarizeAssistantMessages,
20
- getTurnSummary,
21
12
  getSessionSnapshot,
22
- rejectPendingQuestions as rejectPendingQuestionsShared,
23
- approvePendingPermissions as approvePendingPermissionsShared,
24
- type RemoteAssistantInfo,
25
13
  type RemoteSessionSnapshot,
26
14
  type RemoteSessionClient,
27
15
  } from "../remote-server/session-helpers.js";
28
16
  import { ensureServer } from "./server.js";
29
17
 
30
- // ── Constants / type aliases (Kilo-named surface) ──────────────────────────
31
-
32
- export const KILO_SESSION_MESSAGE_LIMIT = REMOTE_SESSION_MESSAGE_LIMIT;
33
-
34
- /** Subset of Kilo's `Message.info` used by Talon for usage accounting. */
35
- export type KiloAssistantInfo = RemoteAssistantInfo;
36
-
37
18
  /** Snapshot of a Kilo session's lifetime + last-turn assistant info. */
38
19
  export type KiloSessionSnapshot = RemoteSessionSnapshot;
39
20
 
40
- // ── Re-exports of pure helpers ─────────────────────────────────────────────
41
-
42
21
  export const extractPartsSummary = extractPartsSummaryShared;
43
22
  export const extractAssistantUsage = extractAssistantUsageShared;
44
23
 
45
- /**
46
- * Summarise a batch of session messages into per-turn usage totals.
47
- * Re-exported under the Kilo-prefixed name for back-compat with
48
- * existing imports.
49
- */
24
+ /** Summarise a batch of session messages into per-turn usage totals. */
50
25
  export const summarizeKiloAssistantMessages = summarizeAssistantMessages;
51
26
 
52
- // ── Session-messages aggregators ──────────────────────────────────────────
53
-
54
- /**
55
- * Aggregate the most recent turn's assistant messages into a usage
56
- * summary. Delegates to the shared helper with a Kilo-typed client.
57
- */
58
- export function getKiloTurnSummary(
59
- oc: KiloClient,
60
- sessionId: string,
61
- minCreatedAt: number,
62
- ): Promise<ReturnType<typeof summarizeAssistantMessages>> {
63
- return getTurnSummary(
64
- oc as unknown as RemoteSessionClient,
65
- sessionId,
66
- minCreatedAt,
67
- );
68
- }
69
-
70
27
  /**
71
28
  * Build a {@link KiloSessionSnapshot} for the given session id.
72
- *
73
29
  * Returns `undefined` if no session id was provided.
74
30
  */
75
31
  export async function getKiloSessionSnapshot(
76
32
  sessionId: string | undefined,
77
33
  ): Promise<KiloSessionSnapshot | undefined> {
78
34
  if (!sessionId) return undefined;
79
- const oc = await ensureServer();
35
+ const oc: KiloClient = await ensureServer();
80
36
  return getSessionSnapshot(oc as unknown as RemoteSessionClient, sessionId);
81
37
  }
82
-
83
- // ── Pending-question guard ─────────────────────────────────────────────────
84
-
85
- /**
86
- * Auto-respond to pending Kilo questions for this session. Delegates to
87
- * the shared helper with the Kilo backend label.
88
- */
89
- export function rejectPendingQuestions(
90
- oc: KiloClient,
91
- sessionId: string,
92
- chatId: string,
93
- seenQuestionIds: Set<string>,
94
- ): Promise<void> {
95
- return rejectPendingQuestionsShared(
96
- oc as unknown as RemoteSessionClient,
97
- sessionId,
98
- chatId,
99
- seenQuestionIds,
100
- "Kilo",
101
- );
102
- }
103
-
104
- /** Auto-approve pending Kilo permissions for this headless session. */
105
- export function approvePendingPermissions(
106
- oc: KiloClient,
107
- sessionId: string,
108
- chatId: string,
109
- seenPermissionIds: Set<string>,
110
- ): Promise<void> {
111
- return approvePendingPermissionsShared(
112
- oc as unknown as RemoteSessionClient,
113
- sessionId,
114
- chatId,
115
- seenPermissionIds,
116
- "Kilo",
117
- );
118
- }
@@ -10,4 +10,3 @@
10
10
  */
11
11
 
12
12
  export { handleMessage } from "./message.js";
13
- export { getActiveAbort } from "./state.js";
@@ -6,8 +6,3 @@
6
6
  */
7
7
 
8
8
  export const activeAborts = new Map<string, AbortController>();
9
-
10
- /** Get the in-flight abort controller for a chat, if a turn is running. */
11
- export function getActiveAbort(chatId: string): AbortController | undefined {
12
- return activeAborts.get(chatId);
13
- }
@@ -48,7 +48,7 @@ import type { FrontendName } from "../../core/agent-runtime/backend-registry.js"
48
48
  import { log, logWarn } from "../../util/log.js";
49
49
  import { nonTerminalFrontends } from "../shared/frontends.js";
50
50
  import { getState } from "./state.js";
51
- import { startDiscovery, refreshDiscovery } from "./discovery.js";
51
+ import { startDiscovery } from "./discovery.js";
52
52
 
53
53
  /**
54
54
  * Initialise the OpenAI Agents backend.
@@ -180,23 +180,6 @@ export function initOpenAIAgentsAgent(
180
180
  void startDiscovery(effectiveBaseURL, apiKey);
181
181
  }
182
182
 
183
- /**
184
- * Trigger a fresh discovery fetch using the resolved endpoint stored
185
- * on state at init time. Returns the new promise so callers can await
186
- * if they want; safe to fire-and-forget.
187
- *
188
- * Useful when the operator wants to refresh the catalog without
189
- * restarting Talon — e.g. after an endpoint outage clears or a new
190
- * model is published.
191
- */
192
- export function triggerDiscoveryRefresh(): Promise<void> {
193
- const state = getState();
194
- if (!state.baseURL) {
195
- return Promise.resolve();
196
- }
197
- return refreshDiscovery(state.baseURL, state.apiKey);
198
- }
199
-
200
183
  /**
201
184
  * Get the OpenAI API key Talon should use for the Agents SDK.
202
185
  *