@24klynx/agent 0.1.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.
- package/dist/index.d.mts +1316 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4596 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1316 @@
|
|
|
1
|
+
import { ContentBlock, Message, Session, SessionId } from "@lynx/core";
|
|
2
|
+
import { ToolDescriptor, ToolHandler } from "@lynx/tools";
|
|
3
|
+
import { ChildProcess } from "node:child_process";
|
|
4
|
+
import { ChatMessage, LlmProvider, StreamEvent } from "@lynx/llm";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
/** Configuration passed to createQueryEngine at bootstrap time. */
|
|
8
|
+
interface AgentConfig {
|
|
9
|
+
/** LLM provider the engine should use for every turn. */
|
|
10
|
+
provider: LlmProvider;
|
|
11
|
+
/** Default model id (can be overridden per‑session). */
|
|
12
|
+
model: string;
|
|
13
|
+
/** System prompt template (assembled with project context + skills). */
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
/** Maximum tokens per request (input + output). */
|
|
16
|
+
maxTokens: number;
|
|
17
|
+
/** Maximum consecutive auto‑compaction failures before giving up. */
|
|
18
|
+
maxCompactionFailures: number;
|
|
19
|
+
/** Hard budget caps (set to Infinity to disable). */
|
|
20
|
+
budget: {
|
|
21
|
+
/** Maximum total input + output tokens across all turns. */maxTokens: number; /** Maximum USD spend (approximate, based on provider pricing). */
|
|
22
|
+
maxUsd: number; /** Maximum number of LLM turns before auto‑terminating. */
|
|
23
|
+
maxTurns: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
type AgentStatus = "idle" | "running" | "aborting" | "compacting";
|
|
27
|
+
interface AgentState {
|
|
28
|
+
status: AgentStatus;
|
|
29
|
+
/** How many turns have been executed in the current run. */
|
|
30
|
+
turnIndex: number;
|
|
31
|
+
/** Total error count since the session started. */
|
|
32
|
+
errorCount: number;
|
|
33
|
+
/** Number of consecutive auto‑compaction failures. */
|
|
34
|
+
consecutiveCompactionFailures: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Immutable snapshot of everything the query loop needs
|
|
38
|
+
* for a single invocation of the LLM.
|
|
39
|
+
*/
|
|
40
|
+
interface TurnContext {
|
|
41
|
+
session: Session;
|
|
42
|
+
/** Visible tools for this turn (after availability evaluation). */
|
|
43
|
+
visibleTools: ToolDescriptor[];
|
|
44
|
+
/** Agent lifecycle state at turn start. */
|
|
45
|
+
state: Readonly<AgentState>;
|
|
46
|
+
/** Abort signal for this turn. */
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The public API of the agent engine.
|
|
51
|
+
*
|
|
52
|
+
* Every method returns plain values — no internal mutable state leaks.
|
|
53
|
+
*/
|
|
54
|
+
interface QueryEngine {
|
|
55
|
+
/** Submit user input and begin streaming agent responses. */
|
|
56
|
+
submit(session: Session, userMessage: Message, signal: AbortSignal): AsyncGenerator<StreamEvent, void, void>;
|
|
57
|
+
/** Abort the currently running turn (first Ctrl+C). */
|
|
58
|
+
abort(): void;
|
|
59
|
+
/** Force immediate compaction of the session messages. */
|
|
60
|
+
compact(session: Session): Promise<Session>;
|
|
61
|
+
/** Take a snapshot of the current state for crash recovery. */
|
|
62
|
+
snapshot(session: Session): AgentSnapshot;
|
|
63
|
+
/** Restore agent state from a previous snapshot. */
|
|
64
|
+
restore(snapshot: AgentSnapshot): Promise<Session>;
|
|
65
|
+
/** Clean up resources (timers, MCP connections, sub‑agent pools). */
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
interface AgentSnapshot {
|
|
69
|
+
sessionId: SessionId;
|
|
70
|
+
turnIndex: number;
|
|
71
|
+
/** Serialised messages at the time of the snapshot. */
|
|
72
|
+
messages: ContentBlock[];
|
|
73
|
+
createdAt: number;
|
|
74
|
+
}
|
|
75
|
+
type CompactionStrategy = "auto" | "reactive" | "snip" | "seam";
|
|
76
|
+
interface CompactionResult {
|
|
77
|
+
/** Compressed messages that replace the original session content. */
|
|
78
|
+
compacted: ContentBlock[];
|
|
79
|
+
/** How many tokens were saved. */
|
|
80
|
+
tokensSaved: number;
|
|
81
|
+
/** Strategy that was applied. */
|
|
82
|
+
strategy: CompactionStrategy;
|
|
83
|
+
}
|
|
84
|
+
interface SubAgentResult {
|
|
85
|
+
agentId: string;
|
|
86
|
+
output: string;
|
|
87
|
+
tokensUsed: number;
|
|
88
|
+
}
|
|
89
|
+
interface SkillDefinition {
|
|
90
|
+
name: string;
|
|
91
|
+
description: string;
|
|
92
|
+
/** Relative path to the SKILL.md file. */
|
|
93
|
+
path: string;
|
|
94
|
+
/** The skill body (loaded on demand). */
|
|
95
|
+
body?: string;
|
|
96
|
+
}
|
|
97
|
+
type McpTransportKind = "stdio" | "sse" | "ws" | "inproc";
|
|
98
|
+
/** OAuth 2.0 PKCE 认证配置。 */
|
|
99
|
+
interface McpOAuthConfig {
|
|
100
|
+
/** 授权端点 URL。 */
|
|
101
|
+
authorizationEndpoint: string;
|
|
102
|
+
/** Token 端点 URL。 */
|
|
103
|
+
tokenEndpoint: string;
|
|
104
|
+
/** OAuth 客户端 ID。 */
|
|
105
|
+
clientId: string;
|
|
106
|
+
/** 回调 URL(默认 http://localhost:<随机端口>/callback)。 */
|
|
107
|
+
redirectUri?: string;
|
|
108
|
+
/** 请求的权限范围。 */
|
|
109
|
+
scopes?: string[];
|
|
110
|
+
}
|
|
111
|
+
/** XAA (Cross-Agent Authentication) 企业身份认证配置。 */
|
|
112
|
+
interface McpXaaConfig {
|
|
113
|
+
/** IdP 提供商 URL。 */
|
|
114
|
+
idpUrl: string;
|
|
115
|
+
/** 客户端 ID。 */
|
|
116
|
+
clientId: string;
|
|
117
|
+
/** 回调 URL。 */
|
|
118
|
+
redirectUri?: string;
|
|
119
|
+
}
|
|
120
|
+
interface McpServerConfig {
|
|
121
|
+
name: string;
|
|
122
|
+
/** Transport type — "stdio" spawns a process, "sse" connects to an HTTP endpoint, "ws" uses WebSocket, "inproc" uses an in-process linked pair. */
|
|
123
|
+
transport?: McpTransportKind;
|
|
124
|
+
/** Command to spawn (stdio transport). */
|
|
125
|
+
command?: string;
|
|
126
|
+
/** Arguments for the command (stdio transport). */
|
|
127
|
+
args?: string[];
|
|
128
|
+
/** Extra env vars (stdio transport). */
|
|
129
|
+
env?: Record<string, string>;
|
|
130
|
+
/** URL to connect to (sse transport, e.g. "http://localhost:8080/mcp"). */
|
|
131
|
+
url?: string;
|
|
132
|
+
/** WebSocket URL (ws transport). */
|
|
133
|
+
wsUrl?: string;
|
|
134
|
+
/** Custom headers for SSE/HTTP requests. */
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
/** Static tool list for test/fallback (when no command is configured). */
|
|
137
|
+
tools?: ToolDescriptor[];
|
|
138
|
+
/** OAuth 2.0 PKCE 认证配置(可选)。 */
|
|
139
|
+
oauth?: McpOAuthConfig;
|
|
140
|
+
/** XAA 企业身份认证配置(可选)。 */
|
|
141
|
+
xaa?: McpXaaConfig;
|
|
142
|
+
/** 是否支持 MCP resources 协议。 */
|
|
143
|
+
resourcesCapable?: boolean;
|
|
144
|
+
/** In-process transport peer handle (inproc transport). */
|
|
145
|
+
inProcPeer?: {
|
|
146
|
+
send(message: string): void;
|
|
147
|
+
onMessage: ((data: string) => void) | null;
|
|
148
|
+
close(): void;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** Reason a connection status changed. */
|
|
152
|
+
type McpStatusEvent = {
|
|
153
|
+
type: "connecting";
|
|
154
|
+
serverName: string;
|
|
155
|
+
} | {
|
|
156
|
+
type: "connected";
|
|
157
|
+
serverName: string;
|
|
158
|
+
toolCount: number;
|
|
159
|
+
} | {
|
|
160
|
+
type: "disconnected";
|
|
161
|
+
serverName: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: "error";
|
|
164
|
+
serverName: string;
|
|
165
|
+
message: string;
|
|
166
|
+
} | {
|
|
167
|
+
type: "reconnecting";
|
|
168
|
+
serverName: string;
|
|
169
|
+
attempt: number;
|
|
170
|
+
delayMs: number;
|
|
171
|
+
};
|
|
172
|
+
type McpStatusListener = (event: McpStatusEvent) => void;
|
|
173
|
+
/** Tool metadata for display in the MCP detail panel. */
|
|
174
|
+
interface McpToolMeta {
|
|
175
|
+
name: string;
|
|
176
|
+
description: string;
|
|
177
|
+
}
|
|
178
|
+
/** Resource metadata for display in the MCP detail panel. */
|
|
179
|
+
interface McpResourceMeta {
|
|
180
|
+
name: string;
|
|
181
|
+
uri: string;
|
|
182
|
+
}
|
|
183
|
+
interface McpConnection {
|
|
184
|
+
serverName: string;
|
|
185
|
+
status: "disconnected" | "connecting" | "connected" | "error";
|
|
186
|
+
/** Available tools exposed by this MCP server. */
|
|
187
|
+
tools: ToolDescriptor[];
|
|
188
|
+
/** Error message if status === "error". */
|
|
189
|
+
errorMessage?: string;
|
|
190
|
+
/** Transport type. */
|
|
191
|
+
transport?: "stdio" | "sse" | "ws" | "inproc";
|
|
192
|
+
/** Authentication status for OAuth/XAA-enabled servers. */
|
|
193
|
+
authStatus?: "none" | "authenticated" | "expired";
|
|
194
|
+
/** Number of resources exposed by this server. */
|
|
195
|
+
resourceCount?: number;
|
|
196
|
+
/** Resources exposed by this server (for detail display). */
|
|
197
|
+
resources?: McpResourceMeta[];
|
|
198
|
+
/** Tool metadata for detail display (name + description). */
|
|
199
|
+
toolsMeta?: McpToolMeta[];
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/engine.d.ts
|
|
203
|
+
interface EngineDeps {
|
|
204
|
+
config: AgentConfig;
|
|
205
|
+
provider: LlmProvider;
|
|
206
|
+
/** Map from executor ref → tool handler. */
|
|
207
|
+
toolHandlers: Map<string, ToolHandler>;
|
|
208
|
+
/** All registered tool descriptors. */
|
|
209
|
+
allTools: ToolDescriptor[];
|
|
210
|
+
/**
|
|
211
|
+
* Called before executing each tool. Returns true if execution is allowed.
|
|
212
|
+
* The callback may be async (e.g. to show a permission dialog).
|
|
213
|
+
* If omitted, all tools execute without permission checks.
|
|
214
|
+
*/
|
|
215
|
+
checkPermission?: (toolName: string, safety: string, description: string) => Promise<boolean>;
|
|
216
|
+
/** Discovered skills for progressive disclosure in the system prompt. */
|
|
217
|
+
skills?: SkillDefinition[];
|
|
218
|
+
/** Persistent memory facts to inject into the system prompt each turn. */
|
|
219
|
+
memoryFacts?: string[];
|
|
220
|
+
/** Textual rules/instructions to inject into the system prompt each turn. */
|
|
221
|
+
rules?: string[];
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create a QueryEngine instance.
|
|
225
|
+
*
|
|
226
|
+
* One engine per application — it manages the lifecycle
|
|
227
|
+
* of all active sessions, sub‑agents, and MCP connections.
|
|
228
|
+
*/
|
|
229
|
+
declare function createQueryEngine(deps: EngineDeps): QueryEngine;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/loop.d.ts
|
|
232
|
+
interface LoopDeps {
|
|
233
|
+
config: AgentConfig;
|
|
234
|
+
provider: LlmProvider;
|
|
235
|
+
/** Map from executor ref → handler. */
|
|
236
|
+
toolHandlers: Map<string, ToolHandler>;
|
|
237
|
+
/** All registered tool descriptors (for planning). */
|
|
238
|
+
allTools: ToolDescriptor[];
|
|
239
|
+
/**
|
|
240
|
+
* Called before executing each tool. Returns true if execution is allowed.
|
|
241
|
+
* The callback may be async (e.g. to show a permission dialog).
|
|
242
|
+
* If omitted, all tools execute without permission checks.
|
|
243
|
+
*/
|
|
244
|
+
checkPermission?: (toolName: string, safety: string, description: string) => Promise<boolean>;
|
|
245
|
+
/** Discovered skills (name + description only) for progressive disclosure. */
|
|
246
|
+
skills?: SkillDefinition[];
|
|
247
|
+
/** Persistent memory facts to inject into the system prompt each turn. */
|
|
248
|
+
memoryFacts?: string[];
|
|
249
|
+
/** Textual rules/instructions to inject into the system prompt each turn. */
|
|
250
|
+
rules?: string[];
|
|
251
|
+
}
|
|
252
|
+
declare function queryLoop(deps: LoopDeps, sessionMessages: Message[], workspace: string, signal: AbortSignal): AsyncGenerator<StreamEvent, void, void>;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/budget.d.ts
|
|
255
|
+
interface BudgetTracker {
|
|
256
|
+
/** Record token consumption after a turn completes. */
|
|
257
|
+
spend(inputTokens: number, outputTokens: number): void;
|
|
258
|
+
/** Record another turn has elapsed. */
|
|
259
|
+
incrementTurn(): void;
|
|
260
|
+
/** Whether at least one budget cap has been reached. */
|
|
261
|
+
isExhausted(): boolean;
|
|
262
|
+
/** Human‑readable summary of remaining budget. */
|
|
263
|
+
summary(): string;
|
|
264
|
+
readonly tokensUsed: number;
|
|
265
|
+
readonly turnsUsed: number;
|
|
266
|
+
readonly usdUsed: number;
|
|
267
|
+
readonly maxTokens: number;
|
|
268
|
+
readonly maxTurns: number;
|
|
269
|
+
readonly maxUsd: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a BudgetTracker from the agent configuration.
|
|
273
|
+
*
|
|
274
|
+
* Token counting is approximate (3.5 chars ≈ 1 token for English,
|
|
275
|
+
* ~1 char ≈ 1 token for CJK). For precise tracking, use the
|
|
276
|
+
* provider‑returned `totalTokens` in the `done` event.
|
|
277
|
+
*/
|
|
278
|
+
declare function createBudgetTracker(config: AgentConfig): BudgetTracker;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/state.d.ts
|
|
281
|
+
/** Create a fresh idle agent state. */
|
|
282
|
+
declare function createAgentState(): AgentState;
|
|
283
|
+
/**
|
|
284
|
+
* Transition the agent to a new status.
|
|
285
|
+
*
|
|
286
|
+
* Throws if the transition is not valid (e.g. idle → aborting,
|
|
287
|
+
* running → running, aborting → compacting).
|
|
288
|
+
*/
|
|
289
|
+
declare function transition(state: AgentState, status: AgentStatus): AgentState;
|
|
290
|
+
/** Advance the turn counter after a successful LLM round‑trip. */
|
|
291
|
+
declare function advanceTurn(state: AgentState): AgentState;
|
|
292
|
+
/** Record a non‑fatal error (bumps the counter). */
|
|
293
|
+
declare function recordError(state: AgentState): AgentState;
|
|
294
|
+
/** Record a successful compaction (resets the failure tally). */
|
|
295
|
+
declare function recordCompactionSuccess(state: AgentState): AgentState;
|
|
296
|
+
/** Record a failed compaction attempt. */
|
|
297
|
+
declare function recordCompactionFailure(state: AgentState): AgentState;
|
|
298
|
+
/**
|
|
299
|
+
* Check whether the compaction circuit breaker has tripped.
|
|
300
|
+
*
|
|
301
|
+
* After MAX failures, auto‑compaction is disabled for the
|
|
302
|
+
* remainder of the session to prevent infinite loops.
|
|
303
|
+
*/
|
|
304
|
+
declare function isCompactionCircuitOpen(state: AgentState, maxFailures: number): boolean;
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/compaction/manager.d.ts
|
|
307
|
+
interface CompactionManager {
|
|
308
|
+
/** Check whether compaction is needed and return the recommended strategy. */
|
|
309
|
+
evaluate(messages: Message[]): CompactionStrategy | undefined;
|
|
310
|
+
/** Execute compaction using the given strategy. */
|
|
311
|
+
compact(messages: Message[], strategy: CompactionStrategy): CompactionResult;
|
|
312
|
+
/** Estimate total tokens across all messages. */
|
|
313
|
+
estimateTokens(messages: Message[]): number;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Create a compaction manager.
|
|
317
|
+
*
|
|
318
|
+
* Each strategy preserves the most recent messages while
|
|
319
|
+
* compressing or dropping older ones. The `seam` strategy
|
|
320
|
+
* additionally preserves the system prompt prefix so the
|
|
321
|
+
* LLM's prefix cache stays warm.
|
|
322
|
+
*/
|
|
323
|
+
declare function createCompactionManager(): CompactionManager;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/prompt/base.d.ts
|
|
326
|
+
/**
|
|
327
|
+
* Lynx 基础系统提示词 — 对照 Claude Code prompts.ts 结构逐节适配。
|
|
328
|
+
*
|
|
329
|
+
* CC 结构: Intro → System → Doing Tasks → Actions → Using Your Tools → Tone → Output
|
|
330
|
+
* 静态节放这里,动态节(工具列表、环境、记忆等)仍由 assembler.ts 组装。
|
|
331
|
+
*/
|
|
332
|
+
/**
|
|
333
|
+
* Lynx 完整基础系统提示词。
|
|
334
|
+
*
|
|
335
|
+
* 动态部分(工具列表、环境信息、记忆、规则、MCP 工具等)
|
|
336
|
+
* 由 assembler.ts 在每回合动态组装。
|
|
337
|
+
*/
|
|
338
|
+
declare function getBaseSystemPrompt(): string;
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/prompt/handoff.d.ts
|
|
341
|
+
interface HandoffContext {
|
|
342
|
+
/** Concise summary of completed work. */
|
|
343
|
+
completed: string;
|
|
344
|
+
/** What is currently in progress. */
|
|
345
|
+
inProgress: string;
|
|
346
|
+
/** Any blockers the next session should know about. */
|
|
347
|
+
blockers: string[];
|
|
348
|
+
/** Important files or paths modified. */
|
|
349
|
+
touchedFiles: string[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Generate a handoff message from the last N messages in the session.
|
|
353
|
+
*
|
|
354
|
+
* Extracts file paths from tool results and builds a structured
|
|
355
|
+
* summary that can be injected as a system message in the next turn.
|
|
356
|
+
*/
|
|
357
|
+
declare function generateHandoff(lastMessages: Message[]): HandoffContext;
|
|
358
|
+
/**
|
|
359
|
+
* Render a HandoffContext as a system message content block.
|
|
360
|
+
*/
|
|
361
|
+
declare function renderHandoffBlock(ctx: HandoffContext): ContentBlock;
|
|
362
|
+
/**
|
|
363
|
+
* Check whether a session needs a handoff (more than N messages).
|
|
364
|
+
*/
|
|
365
|
+
declare function needsHandoff(messages: Message[], threshold?: number): boolean;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/prompt/assembler.d.ts
|
|
368
|
+
/** Options for controlling prompt assembly. */
|
|
369
|
+
interface AssembleOptions {
|
|
370
|
+
/** Visible tools for this turn. */
|
|
371
|
+
visibleTools: ToolDescriptor[];
|
|
372
|
+
/** Discovered skills (may be empty). */
|
|
373
|
+
skills?: SkillDefinition[];
|
|
374
|
+
/** Optional handoff from a previous session. */
|
|
375
|
+
handoff?: HandoffContext;
|
|
376
|
+
/** Language direction override from config/CLAUDE.md. */
|
|
377
|
+
languageDirection?: string;
|
|
378
|
+
/** Workspace path for loading project context. */
|
|
379
|
+
workspace?: string;
|
|
380
|
+
/** MCP tools from connected servers. */
|
|
381
|
+
mcpTools?: ToolDescriptor[];
|
|
382
|
+
/** Persistent memory facts to inject. */
|
|
383
|
+
memoryFacts?: string[];
|
|
384
|
+
/** Permission rules to inject. */
|
|
385
|
+
rules?: string[];
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Assemble the complete system prompt for a turn.
|
|
389
|
+
*
|
|
390
|
+
* Called at the start of every LLM invocation — the prompt may
|
|
391
|
+
* change between turns (tool visibility can shift due to permissions,
|
|
392
|
+
* new skills may be loaded, handoff may be injected).
|
|
393
|
+
*/
|
|
394
|
+
declare function assembleSystemPrompt(config: AgentConfig, opts: AssembleOptions | ToolDescriptor[]): string;
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/prompt/context.d.ts
|
|
397
|
+
/**
|
|
398
|
+
* Build the ChatMessage array for a single LLM invocation.
|
|
399
|
+
*
|
|
400
|
+
* Converts session Message[] history into ChatMessage[] (with roles preserved)
|
|
401
|
+
* and prepends project context as a system‑level message.
|
|
402
|
+
*/
|
|
403
|
+
declare function buildMessagesForTurn(messages: Message[], _visibleTools: ToolDescriptor[], workspace?: string): ChatMessage[];
|
|
404
|
+
/**
|
|
405
|
+
* Walk up from `workspace` looking for instruction files.
|
|
406
|
+
*
|
|
407
|
+
* The first file found at each directory level is loaded;
|
|
408
|
+
* higher‑priority files (CLAUDE.md) shadow lower ones.
|
|
409
|
+
* We stop at the filesystem root or when we've collected
|
|
410
|
+
* all known file names.
|
|
411
|
+
*/
|
|
412
|
+
declare function loadProjectContext(workspace?: string): string | undefined;
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/prompt/hash.d.ts
|
|
415
|
+
/**
|
|
416
|
+
* Prompt hash computation — used to detect when the system prompt
|
|
417
|
+
* has changed enough to invalidate the prefix cache.
|
|
418
|
+
*
|
|
419
|
+
* The hash is computed only over the "frozen" zone (everything before
|
|
420
|
+
* the tool catalog). When tools change, the hash changes and the cache
|
|
421
|
+
* is invalidated — which is correct, since tool schemas are part of
|
|
422
|
+
* the prompt.
|
|
423
|
+
*/
|
|
424
|
+
/**
|
|
425
|
+
* Compute a SHA‑256 hash of the frozen prefix zone.
|
|
426
|
+
*
|
|
427
|
+
* This hash is used as a cache key — if the frozen zone hasn't
|
|
428
|
+
* changed between turns, the LLM can reuse cached KV pairs.
|
|
429
|
+
*/
|
|
430
|
+
declare function computeFrozenHash(prompt: string): string;
|
|
431
|
+
/**
|
|
432
|
+
* Check if two prompts share the same frozen prefix.
|
|
433
|
+
*/
|
|
434
|
+
declare function sameFrozenPrefix(a: string, b: string): boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Extract the frozen zone from the full prompt.
|
|
437
|
+
* Everything before "## Available Tools" is considered frozen.
|
|
438
|
+
*/
|
|
439
|
+
declare function extractFrozenZone(prompt: string): string;
|
|
440
|
+
/**
|
|
441
|
+
* Extract the warm zone (tool catalog) from the full prompt.
|
|
442
|
+
*/
|
|
443
|
+
declare function extractWarmZone(prompt: string): string;
|
|
444
|
+
/**
|
|
445
|
+
* Extract the hot zone (session‑specific suffix) from the full prompt.
|
|
446
|
+
*/
|
|
447
|
+
declare function extractHotZone(prompt: string): string;
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/cache/prefix.d.ts
|
|
450
|
+
/**
|
|
451
|
+
* Prefix cache stability manager — three‑zone model.
|
|
452
|
+
*
|
|
453
|
+
* DeepSeek and Anthropic both implement automatic prefix caching:
|
|
454
|
+
* the first N tokens of the system prompt that don't change between
|
|
455
|
+
* requests are cached server‑side, reducing latency and cost.
|
|
456
|
+
*
|
|
457
|
+
* Zones:
|
|
458
|
+
* 1. Frozen prefix — never changes (tool catalog header, core rules)
|
|
459
|
+
* 2. Warm prefix — changes rarely (skill list, date)
|
|
460
|
+
* 3. Hot suffix — changes every turn (tool schema, session state)
|
|
461
|
+
*
|
|
462
|
+
* The manager computes a hash of each zone and emits a "stability"
|
|
463
|
+
* score — higher scores mean more tokens benefit from the cache.
|
|
464
|
+
*/
|
|
465
|
+
interface PrefixCacheManager {
|
|
466
|
+
/** Compute the stability score for a given system prompt. */
|
|
467
|
+
computeStability(prompt: string): PrefixStabilityReport;
|
|
468
|
+
/** Verify that the frozen prefix matches the expected hash. */
|
|
469
|
+
verifyFrozenPrefix(prompt: string, expectedHash: string): boolean;
|
|
470
|
+
/** Compute the SHA‑256 hash of the frozen zone. */
|
|
471
|
+
hashFrozenPrefix(prompt: string): string;
|
|
472
|
+
}
|
|
473
|
+
interface PrefixStabilityReport {
|
|
474
|
+
/** How many tokens (estimated) are within the frozen zone. */
|
|
475
|
+
frozenTokens: number;
|
|
476
|
+
/** How many tokens are within the warm zone. */
|
|
477
|
+
warmTokens: number;
|
|
478
|
+
/** How many tokens are in the hot suffix (no cache benefit). */
|
|
479
|
+
hotTokens: number;
|
|
480
|
+
/** Fraction of the prompt that is stable (0–1). */
|
|
481
|
+
stabilityScore: number;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Create a prefix cache manager.
|
|
485
|
+
*
|
|
486
|
+
* The frozen zone is everything before the tool catalog;
|
|
487
|
+
* the warm zone is the tool catalog itself; the hot zone
|
|
488
|
+
* is the session‑specific suffix.
|
|
489
|
+
*/
|
|
490
|
+
declare function createPrefixCacheManager(): PrefixCacheManager;
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region src/skills/loader.d.ts
|
|
493
|
+
interface SkillRegistry {
|
|
494
|
+
/** List all discovered skills (name + description only). */
|
|
495
|
+
list(): SkillDefinition[];
|
|
496
|
+
/** Load the full body of a skill by name. */
|
|
497
|
+
load(name: string): SkillDefinition | undefined;
|
|
498
|
+
/** Force a re‑scan of ALL registered skill directories. */
|
|
499
|
+
reload(): void;
|
|
500
|
+
/** Add an additional directory to scan for skills. */
|
|
501
|
+
addDirectory(dir: string): void;
|
|
502
|
+
/** Returns the primary skills directory. */
|
|
503
|
+
readonly skillsDir: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Create a skill registry that watches the given directory.
|
|
507
|
+
*
|
|
508
|
+
* If the directory doesn't exist, the registry starts empty
|
|
509
|
+
* and skills can be added later via reload().
|
|
510
|
+
*/
|
|
511
|
+
declare function createSkillRegistry(skillsDir: string): SkillRegistry;
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/skills/render.d.ts
|
|
514
|
+
/**
|
|
515
|
+
* Render the short form (name + description) for injection
|
|
516
|
+
* into the system prompt.
|
|
517
|
+
*/
|
|
518
|
+
declare function renderSkillSummary(skill: SkillDefinition): string;
|
|
519
|
+
/**
|
|
520
|
+
* Render the full body of a skill as a markdown block that
|
|
521
|
+
* can be inserted into the conversation as a user‑visible message.
|
|
522
|
+
*/
|
|
523
|
+
declare function renderSkillBody(skill: SkillDefinition): string;
|
|
524
|
+
/**
|
|
525
|
+
* Render all known skill summaries as a section for the system prompt.
|
|
526
|
+
*/
|
|
527
|
+
declare function renderSkillCatalog(skills: SkillDefinition[]): string;
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/skills/tool.d.ts
|
|
530
|
+
/** The tool name the model uses to request skill bodies. */
|
|
531
|
+
declare const SKILL_TOOL_NAME = "Skill";
|
|
532
|
+
/**
|
|
533
|
+
* Create a ToolHandler that serves skill bodies on demand.
|
|
534
|
+
*
|
|
535
|
+
* The handler looks up the requested skill by name and returns
|
|
536
|
+
* its full body as a tool result.
|
|
537
|
+
*/
|
|
538
|
+
declare function createSkillToolHandler(registry: SkillRegistry): ToolHandler;
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/skills/state.d.ts
|
|
541
|
+
type SkillLoadStatus = "unloaded" | "loading" | "loaded" | "failed";
|
|
542
|
+
interface SkillEntry {
|
|
543
|
+
definition: SkillDefinition;
|
|
544
|
+
status: SkillLoadStatus;
|
|
545
|
+
errorMessage?: string;
|
|
546
|
+
}
|
|
547
|
+
interface SkillState {
|
|
548
|
+
/** Get the tracked state for a skill by name. */
|
|
549
|
+
get(name: string): SkillEntry | undefined;
|
|
550
|
+
/** Mark a skill as loading. */
|
|
551
|
+
setLoading(name: string): void;
|
|
552
|
+
/** Mark a skill as loaded with its full definition. */
|
|
553
|
+
setLoaded(name: string, def: SkillDefinition): void;
|
|
554
|
+
/** Mark a skill as failed. */
|
|
555
|
+
setFailed(name: string, error: string): void;
|
|
556
|
+
/** List all tracked skills. */
|
|
557
|
+
list(): SkillEntry[];
|
|
558
|
+
/** Check if a skill is ready to use. */
|
|
559
|
+
isReady(name: string): boolean;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Create a skill state tracker.
|
|
563
|
+
*
|
|
564
|
+
* Tracks the lifecycle of each skill through unloaded → loading → loaded
|
|
565
|
+
* (or failed), so the prompt assembly knows which skills to include.
|
|
566
|
+
*/
|
|
567
|
+
declare function createSkillState(): SkillState;
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/skills/watcher.d.ts
|
|
570
|
+
interface SkillWatcher {
|
|
571
|
+
/** Start watching the skills directory. */
|
|
572
|
+
start(): void;
|
|
573
|
+
/** Stop watching. */
|
|
574
|
+
stop(): void;
|
|
575
|
+
/** Whether the watcher is currently active. */
|
|
576
|
+
readonly active: boolean;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Create a file watcher that auto‑reloads the skill registry
|
|
580
|
+
* when SKILL.md files change.
|
|
581
|
+
*
|
|
582
|
+
* Fail‑safe: file watch errors are logged but never crash the agent.
|
|
583
|
+
* If the directory doesn't exist, the watcher stays idle.
|
|
584
|
+
*/
|
|
585
|
+
declare function createSkillWatcher(registry: SkillRegistry): SkillWatcher;
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/snapshot/capture.d.ts
|
|
588
|
+
/** Capture a snapshot of the current agent state. */
|
|
589
|
+
declare function captureSnapshot(sessionId: SessionId, turnIndex: number, messages: ContentBlock[]): AgentSnapshot;
|
|
590
|
+
/** Check whether a snapshot is still within the valid time window. */
|
|
591
|
+
declare function isSnapshotValid(snapshot: AgentSnapshot, maxAgeMs?: number): boolean;
|
|
592
|
+
/** Estimate the token count of a snapshot's messages. */
|
|
593
|
+
declare function estimateSnapshotTokens(snapshot: AgentSnapshot): number;
|
|
594
|
+
/**
|
|
595
|
+
* Merge snapshot messages into an existing session message list.
|
|
596
|
+
*
|
|
597
|
+
* Preserves existing blocks before the snapshot's turn boundary
|
|
598
|
+
* and appends snapshot messages after. This avoids duplicating
|
|
599
|
+
* messages that were already persisted.
|
|
600
|
+
*/
|
|
601
|
+
declare function mergeSnapshot(existing: ContentBlock[], snapshot: AgentSnapshot): ContentBlock[];
|
|
602
|
+
//#endregion
|
|
603
|
+
//#region src/subagent/spawn.d.ts
|
|
604
|
+
interface SubAgentConfig {
|
|
605
|
+
/** Human‑readable label for logging. */
|
|
606
|
+
label: string;
|
|
607
|
+
/** System prompt override (if empty, uses parent config). */
|
|
608
|
+
systemPrompt?: string;
|
|
609
|
+
/** Tools this sub‑agent is allowed to use. */
|
|
610
|
+
allowedTools: string[];
|
|
611
|
+
/** Maximum turns before auto‑termination. */
|
|
612
|
+
maxTurns: number;
|
|
613
|
+
/**
|
|
614
|
+
* Called when the sub‑agent completes to deduct token usage
|
|
615
|
+
* from the parent agent's budget. Receives total tokens consumed.
|
|
616
|
+
*/
|
|
617
|
+
onTokensUsed?: (tokens: number) => void;
|
|
618
|
+
}
|
|
619
|
+
/** Options for {@link spawnSubAgent}. */
|
|
620
|
+
interface SpawnSubAgentOptions {
|
|
621
|
+
/** LLM provider for sub‑agent queries. */
|
|
622
|
+
provider: LlmProvider;
|
|
623
|
+
/** Tool handlers available to the sub‑agent. */
|
|
624
|
+
tools: Map<string, ToolHandler>;
|
|
625
|
+
/** All visible tool descriptors. */
|
|
626
|
+
allTools: ToolDescriptor[];
|
|
627
|
+
/** Parent agent configuration to inherit from. */
|
|
628
|
+
parentConfig: AgentConfig;
|
|
629
|
+
/** Sub‑agent configuration (restricted tools, budget, etc.). */
|
|
630
|
+
subConfig: SubAgentConfig;
|
|
631
|
+
/** The task description for the sub‑agent. */
|
|
632
|
+
task: string;
|
|
633
|
+
/** Workspace directory for the sub‑agent. */
|
|
634
|
+
workspace: string;
|
|
635
|
+
/** Abort signal for cancellation. */
|
|
636
|
+
signal: AbortSignal;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Spawn a sub‑agent to handle a specific task.
|
|
640
|
+
*
|
|
641
|
+
* The sub‑agent runs the same query loop as the parent but
|
|
642
|
+
* with a restricted tool set and budget. Results are collected
|
|
643
|
+
* and returned when the sub‑agent completes.
|
|
644
|
+
*/
|
|
645
|
+
declare function spawnSubAgent(opts: SpawnSubAgentOptions): Promise<SubAgentResult>;
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/subagent/lane.d.ts
|
|
648
|
+
interface LaneJob {
|
|
649
|
+
id: string;
|
|
650
|
+
config: SubAgentConfig;
|
|
651
|
+
task: string;
|
|
652
|
+
workspace: string;
|
|
653
|
+
}
|
|
654
|
+
interface LaneResult {
|
|
655
|
+
jobId: string;
|
|
656
|
+
result: SubAgentResult;
|
|
657
|
+
}
|
|
658
|
+
interface LaneDispatcher {
|
|
659
|
+
/** Submit a job to a lane. Returns the result when the sub‑agent completes. */
|
|
660
|
+
dispatch(job: LaneJob, signal: AbortSignal): Promise<LaneResult>;
|
|
661
|
+
/** How many lanes are currently busy. */
|
|
662
|
+
readonly activeCount: number;
|
|
663
|
+
/** How many jobs are queued. */
|
|
664
|
+
readonly queueSize: number;
|
|
665
|
+
}
|
|
666
|
+
/** Options for {@link createLaneDispatcher}. */
|
|
667
|
+
interface LaneDispatcherOptions {
|
|
668
|
+
/** LLM provider shared across all lanes. */
|
|
669
|
+
provider: LlmProvider;
|
|
670
|
+
/** Tool handlers shared across all lanes. */
|
|
671
|
+
tools: Map<string, ToolHandler>;
|
|
672
|
+
/** All visible tool descriptors. */
|
|
673
|
+
allTools: ToolDescriptor[];
|
|
674
|
+
/** Parent agent configuration. */
|
|
675
|
+
parentConfig: AgentConfig;
|
|
676
|
+
/** Maximum concurrent sub‑agents (default 4). */
|
|
677
|
+
maxLanes?: number;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Create a lane dispatcher for sub‑agent concurrency.
|
|
681
|
+
*
|
|
682
|
+
* Jobs exceeding the concurrency cap are queued and dequeued
|
|
683
|
+
* in FIFO order as lanes become free.
|
|
684
|
+
*/
|
|
685
|
+
declare function createLaneDispatcher(opts: LaneDispatcherOptions): LaneDispatcher;
|
|
686
|
+
//#endregion
|
|
687
|
+
//#region src/subagent/bridge.d.ts
|
|
688
|
+
interface PermissionScope {
|
|
689
|
+
/** Tools the sub‑agent is allowed to call. */
|
|
690
|
+
allowedTools: Set<string>;
|
|
691
|
+
/** Whether dangerous tools are auto‑denied for the sub‑agent. */
|
|
692
|
+
denyDangerous: boolean;
|
|
693
|
+
/** Whether workspace‑safe tools auto‑approve. */
|
|
694
|
+
autoApproveWorkspaceSafe: boolean;
|
|
695
|
+
/** Whether the sub‑agent can escalate to ask the user. */
|
|
696
|
+
canEscalate: boolean;
|
|
697
|
+
}
|
|
698
|
+
interface PermissionBridge {
|
|
699
|
+
/** Build a restricted tool list for a sub‑agent scope. */
|
|
700
|
+
filterTools(allTools: ToolDescriptor[], scope: PermissionScope): ToolDescriptor[];
|
|
701
|
+
/** Check whether a specific tool is allowed in the given scope. */
|
|
702
|
+
isAllowed(toolName: string, scope: PermissionScope): boolean;
|
|
703
|
+
/** Create a default restrictive scope for sub‑agents. */
|
|
704
|
+
createRestrictiveScope(allowedTools: string[]): PermissionScope;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Create a permission bridge for sub‑agent delegation.
|
|
708
|
+
*
|
|
709
|
+
* The bridge enforces that sub‑agents can never have more
|
|
710
|
+
* permissions than their parent.
|
|
711
|
+
*/
|
|
712
|
+
declare function createPermissionBridge(): PermissionBridge;
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/subagent/parallel.d.ts
|
|
715
|
+
interface ParallelTask {
|
|
716
|
+
/** Human‑readable label for logging. */
|
|
717
|
+
label: string;
|
|
718
|
+
/** The task description sent to the sub‑agent. */
|
|
719
|
+
task: string;
|
|
720
|
+
/** Tools this sub‑agent can use. */
|
|
721
|
+
allowedTools: string[];
|
|
722
|
+
}
|
|
723
|
+
interface ParallelResult {
|
|
724
|
+
label: string;
|
|
725
|
+
result: SubAgentResult | null;
|
|
726
|
+
error?: string;
|
|
727
|
+
}
|
|
728
|
+
/** Options for {@link runInParallel}. */
|
|
729
|
+
interface RunInParallelOptions {
|
|
730
|
+
/** LLM provider shared across all sub‑agents. */
|
|
731
|
+
provider: LlmProvider;
|
|
732
|
+
/** Tool handlers shared across all sub‑agents. */
|
|
733
|
+
tools: Map<string, ToolHandler>;
|
|
734
|
+
/** All visible tool descriptors. */
|
|
735
|
+
allTools: ToolDescriptor[];
|
|
736
|
+
/** Parent agent configuration. */
|
|
737
|
+
parentConfig: AgentConfig;
|
|
738
|
+
/** Tasks to fan‑out to sub‑agents. */
|
|
739
|
+
tasks: ParallelTask[];
|
|
740
|
+
/** Workspace directory for sub‑agents. */
|
|
741
|
+
workspace: string;
|
|
742
|
+
/** Abort signal for cancellation. */
|
|
743
|
+
signal: AbortSignal;
|
|
744
|
+
/** Maximum concurrent lanes (default 4). */
|
|
745
|
+
maxLanes?: number;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Run multiple sub‑agent tasks in parallel.
|
|
749
|
+
*
|
|
750
|
+
* Uses a lane dispatcher to control concurrency. Each task
|
|
751
|
+
* gets a unique sub‑agent instance. Failed tasks return null
|
|
752
|
+
* and an error string — the caller decides how to handle them.
|
|
753
|
+
*/
|
|
754
|
+
declare function runInParallel(opts: RunInParallelOptions): Promise<ParallelResult[]>;
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/mcp/connection.d.ts
|
|
757
|
+
/** An MCP resource exposed by a connected server. */
|
|
758
|
+
interface McpResource {
|
|
759
|
+
uri: string;
|
|
760
|
+
name: string;
|
|
761
|
+
mimeType?: string;
|
|
762
|
+
description?: string;
|
|
763
|
+
server: string;
|
|
764
|
+
}
|
|
765
|
+
interface McpManager {
|
|
766
|
+
/** Connect to a configured MCP server. */
|
|
767
|
+
connect(config: McpServerConfig): Promise<McpConnection>;
|
|
768
|
+
/** Disconnect from a server and remove its tools. */
|
|
769
|
+
disconnect(serverName: string): Promise<void>;
|
|
770
|
+
/** Reconnect to a previously configured server with exponential backoff. */
|
|
771
|
+
reconnect(serverName: string): Promise<McpConnection>;
|
|
772
|
+
/** List all active connections. */
|
|
773
|
+
listConnections(): McpConnection[];
|
|
774
|
+
/** Get all tools from all connected servers. */
|
|
775
|
+
getAllTools(): ToolDescriptor[];
|
|
776
|
+
/**
|
|
777
|
+
* Call a tool on a connected MCP server.
|
|
778
|
+
*
|
|
779
|
+
* The `toolName` should be the namespaced name
|
|
780
|
+
* (e.g. `mcp__filesystem__read_file`).
|
|
781
|
+
*/
|
|
782
|
+
callTool(toolName: string, args: Record<string, unknown>): Promise<{
|
|
783
|
+
content: string;
|
|
784
|
+
isError: boolean;
|
|
785
|
+
}>;
|
|
786
|
+
/** List all resources from all connected servers. */
|
|
787
|
+
getAllResources(): McpResource[];
|
|
788
|
+
/** Read a specific resource by URI from a server. */
|
|
789
|
+
readResource(serverName: string, uri: string): Promise<{
|
|
790
|
+
contents: unknown[];
|
|
791
|
+
}>;
|
|
792
|
+
/** Check if any connected server supports resources. */
|
|
793
|
+
hasResourceCapability(): boolean;
|
|
794
|
+
/**
|
|
795
|
+
* Subscribe to connection status changes.
|
|
796
|
+
* Returns an unsubscribe function.
|
|
797
|
+
*/
|
|
798
|
+
onStatus(listener: McpStatusListener): () => void;
|
|
799
|
+
/** Shut down all connections. */
|
|
800
|
+
destroy(): Promise<void>;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Create an MCP connection manager.
|
|
804
|
+
*
|
|
805
|
+
* Manages the lifecycle of multiple MCP server connections,
|
|
806
|
+
* including connect, disconnect, tool call forwarding,
|
|
807
|
+
* automatic reconnection with exponential backoff,
|
|
808
|
+
* resource discovery, and status event emission.
|
|
809
|
+
*/
|
|
810
|
+
declare function createMcpManager(): McpManager;
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/mcp/transport.d.ts
|
|
813
|
+
/** Result of a tools/call request. */
|
|
814
|
+
interface CallToolResult {
|
|
815
|
+
content: Array<{
|
|
816
|
+
type: "text" | "resource";
|
|
817
|
+
text?: string;
|
|
818
|
+
resource?: unknown;
|
|
819
|
+
}>;
|
|
820
|
+
isError?: boolean;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Connect to an MCP server over stdio transport.
|
|
824
|
+
*
|
|
825
|
+
* Spawns the server as a child process, performs the MCP
|
|
826
|
+
* initialization handshake, and discovers tools.
|
|
827
|
+
*/
|
|
828
|
+
/**
|
|
829
|
+
* Options for {@link connectStdioTransport}.
|
|
830
|
+
*/
|
|
831
|
+
interface ConnectStdioOptions {
|
|
832
|
+
/** Called immediately after the child process is spawned, before the handshake. */
|
|
833
|
+
onProcessSpawned?: (proc: ChildProcess) => void;
|
|
834
|
+
}
|
|
835
|
+
declare function connectStdioTransport(config: McpServerConfig, opts?: ConnectStdioOptions): Promise<{
|
|
836
|
+
connection: McpConnection;
|
|
837
|
+
process: ChildProcess;
|
|
838
|
+
tools: ToolDescriptor[];
|
|
839
|
+
}>;
|
|
840
|
+
/**
|
|
841
|
+
* Safely disconnect from an MCP server.
|
|
842
|
+
*/
|
|
843
|
+
declare function disconnectStdioTransport(proc: ChildProcess): void;
|
|
844
|
+
/**
|
|
845
|
+
* Extract the original server‑side tool name from a namespaced MCP tool name.
|
|
846
|
+
*
|
|
847
|
+
* Inverse of {@link mcpToolName}: `mcp__myserver__read_file` → `read_file`.
|
|
848
|
+
*/
|
|
849
|
+
declare function extractMcpToolName(namespaced: string): string;
|
|
850
|
+
/**
|
|
851
|
+
* Extract the server name from a namespaced MCP tool name.
|
|
852
|
+
*
|
|
853
|
+
* `mcp__myserver__read_file` → `myserver`.
|
|
854
|
+
*/
|
|
855
|
+
declare function extractMcpServerName(namespaced: string): string;
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region src/mcp/transport-sse.d.ts
|
|
858
|
+
/** Result of a tools/call request. */
|
|
859
|
+
interface CallToolResult$1 {
|
|
860
|
+
content: Array<{
|
|
861
|
+
type: "text" | "resource";
|
|
862
|
+
text?: string;
|
|
863
|
+
resource?: unknown;
|
|
864
|
+
}>;
|
|
865
|
+
isError?: boolean;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Lightweight SSE connection — manages the HTTP transport lifecycle
|
|
869
|
+
* for a single MCP server. The server must support the MCP streamable
|
|
870
|
+
* HTTP transport (SSE for server→client, POST for client→server).
|
|
871
|
+
*/
|
|
872
|
+
interface SseMcpConnection {
|
|
873
|
+
/** The MCP endpoint URL (e.g. "http://localhost:8080/mcp"). */
|
|
874
|
+
url: string;
|
|
875
|
+
/** Close the SSE stream and abort any in‑flight requests. */
|
|
876
|
+
close(): void;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Connect to an MCP server over SSE (HTTP) transport.
|
|
880
|
+
*
|
|
881
|
+
* Performs the MCP initialization handshake via HTTP POST,
|
|
882
|
+
* discovers tools, and returns the connection metadata.
|
|
883
|
+
* No persistent SSE stream is kept open — tool calls are
|
|
884
|
+
* also sent via POST for simplicity (MCP streamable HTTP spec).
|
|
885
|
+
*/
|
|
886
|
+
declare function connectSseTransport(config: McpServerConfig): Promise<{
|
|
887
|
+
connection: McpConnection;
|
|
888
|
+
sessionId?: string;
|
|
889
|
+
tools: ToolDescriptor[];
|
|
890
|
+
}>;
|
|
891
|
+
/** Options for {@link callToolSse}. */
|
|
892
|
+
interface CallToolSseOpts {
|
|
893
|
+
toolName: string;
|
|
894
|
+
args: Record<string, unknown>;
|
|
895
|
+
serverName: string;
|
|
896
|
+
headers?: Record<string, string>;
|
|
897
|
+
sessionId?: string;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Call a tool on an MCP server over SSE (HTTP) transport.
|
|
901
|
+
*
|
|
902
|
+
* Sends `tools/call` via HTTP POST and returns the parsed result.
|
|
903
|
+
* The `toolName` is the ORIGINAL server‑side name (not namespaced).
|
|
904
|
+
*/
|
|
905
|
+
declare function callToolSse(url: string, opts: CallToolSseOpts): Promise<CallToolResult$1>;
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/mcp/transport-ws.d.ts
|
|
908
|
+
/** Result of a tools/call request. */
|
|
909
|
+
interface CallToolResult$2 {
|
|
910
|
+
content: Array<{
|
|
911
|
+
type: "text" | "resource";
|
|
912
|
+
text?: string;
|
|
913
|
+
resource?: unknown;
|
|
914
|
+
}>;
|
|
915
|
+
isError?: boolean;
|
|
916
|
+
}
|
|
917
|
+
/** WebSocket 连接句柄 — 管理一个 WS 连接的生命周期。 */
|
|
918
|
+
interface WebSocketConnection {
|
|
919
|
+
ws: WebSocket;
|
|
920
|
+
/** 关闭 WebSocket 连接并清理待处理请求。 */
|
|
921
|
+
close(): void;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* 通过 WebSocket 连接到 MCP 服务器。
|
|
925
|
+
*
|
|
926
|
+
* 握手序列:new WebSocket(wsUrl) → onopen → initialize → notifications/initialized → tools/list。
|
|
927
|
+
* 使用 Node.js 22+ 内置 WebSocket API。
|
|
928
|
+
*
|
|
929
|
+
* 如果 initialize 在 CONNECT_TIMEOUT_MS 内未完成,则拒绝并关闭连接。
|
|
930
|
+
*/
|
|
931
|
+
declare function connectWsTransport(config: McpServerConfig): Promise<{
|
|
932
|
+
connection: McpConnection;
|
|
933
|
+
conn: WebSocketConnection;
|
|
934
|
+
tools: ToolDescriptor[];
|
|
935
|
+
}>;
|
|
936
|
+
/**
|
|
937
|
+
* 通过 WebSocket 调用 MCP 服务器上的工具。
|
|
938
|
+
*
|
|
939
|
+
* `toolName` 是原始服务器端名称(非命名空间格式)。
|
|
940
|
+
*/
|
|
941
|
+
declare function callToolWs(conn: WebSocketConnection, toolName: string, args: Record<string, unknown>, serverName: string): Promise<CallToolResult$2>;
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region src/mcp/transport-inproc.d.ts
|
|
944
|
+
/**
|
|
945
|
+
* In‑process 传输端点 — 链接对中的一端。
|
|
946
|
+
* 参考 Claude Code 的 InProcessTransport 设计。
|
|
947
|
+
*/
|
|
948
|
+
interface InProcTransport {
|
|
949
|
+
/** 向对端发送 JSON‑RPC 消息字符串。 */
|
|
950
|
+
send(message: string): void;
|
|
951
|
+
/** 对端消息到达时的回调。 */
|
|
952
|
+
onMessage: ((data: string) => void) | null;
|
|
953
|
+
/** 关闭此端点。 */
|
|
954
|
+
close(): void;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* 创建一对链接的 in‑process transport 端点。
|
|
958
|
+
*
|
|
959
|
+
* send() 在一端调用,通过 queueMicrotask 异步传递到对端的 onMessage。
|
|
960
|
+
* 返回 `[client, server]` — client 端由 Lynx MCP manager 持有,
|
|
961
|
+
* server 端交给 in‑process MCP server 使用。
|
|
962
|
+
*
|
|
963
|
+
* 两个端点共享一个消息队列,每个 send() 追加消息并调度一个 microtask
|
|
964
|
+
* 来排空队列并投递到对端的 onMessage。
|
|
965
|
+
*/
|
|
966
|
+
declare function createInProcPair(): [InProcTransport, InProcTransport];
|
|
967
|
+
/**
|
|
968
|
+
* 通过 in‑process transport 连接到 MCP 服务器。
|
|
969
|
+
*
|
|
970
|
+
* 在指定的端点 peer 上执行标准 MCP 握手:
|
|
971
|
+
* 1. 发送 initialize → 等待响应
|
|
972
|
+
* 2. 发送 notifications/initialized
|
|
973
|
+
* 3. 发送 tools/list → 构建 ToolDescriptor 列表
|
|
974
|
+
*
|
|
975
|
+
* In‑process 传输不需要超时保护(底层同步执行,microtask 调度保证公平性)。
|
|
976
|
+
*/
|
|
977
|
+
declare function connectInProcTransport(peer: InProcTransport, serverName: string): Promise<{
|
|
978
|
+
connection: McpConnection;
|
|
979
|
+
tools: ToolDescriptor[];
|
|
980
|
+
}>;
|
|
981
|
+
//#endregion
|
|
982
|
+
//#region src/mcp/oauth.d.ts
|
|
983
|
+
/** OAuth 2.0 token 响应。 */
|
|
984
|
+
interface OAuthToken {
|
|
985
|
+
accessToken: string;
|
|
986
|
+
refreshToken?: string;
|
|
987
|
+
/** 过期时间(epoch 毫秒),undefined 表示永不过期。 */
|
|
988
|
+
expiresAt?: number;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* 执行 OAuth 2.0 PKCE 授权码流程。
|
|
992
|
+
*
|
|
993
|
+
* 完整流程:
|
|
994
|
+
* 1. 生成 PKCE code_verifier(128 bytes,base64url)
|
|
995
|
+
* 2. 计算 code_challenge = SHA256(code_verifier),base64url 编码
|
|
996
|
+
* 3. 在随机端口启动临时 HTTP 服务器接收回调
|
|
997
|
+
* 4. 打开浏览器到授权端点
|
|
998
|
+
* 5. 接收回调,用 code + code_verifier 交换 token
|
|
999
|
+
*
|
|
1000
|
+
* 调用方负责用 {@link storeToken} 持久化返回的 token。
|
|
1001
|
+
*/
|
|
1002
|
+
declare function performPkceFlow(config: McpOAuthConfig): Promise<OAuthToken>;
|
|
1003
|
+
/**
|
|
1004
|
+
* 用 refresh_token 刷新过期的 access token。
|
|
1005
|
+
*
|
|
1006
|
+
* 向 tokenEndpoint 发送 `grant_type=refresh_token` 请求。
|
|
1007
|
+
* 如果刷新失败则抛出错误——调用方需自行调用 {@link deleteToken}
|
|
1008
|
+
* 清除已存储的过期 token,并引导用户重新授权。
|
|
1009
|
+
*
|
|
1010
|
+
* 如果端点未返回新的 refresh_token,会保留旧的 refresh_token 继续使用。
|
|
1011
|
+
*/
|
|
1012
|
+
declare function refreshOAuthToken(config: McpOAuthConfig, refreshToken: string): Promise<OAuthToken>;
|
|
1013
|
+
/**
|
|
1014
|
+
* 从 ~/.lynx/mcp-oauth.json 加载已存储的 token。
|
|
1015
|
+
*
|
|
1016
|
+
* @param serverName - MCP 服务器名称,对应配置文件中的 `name` 字段
|
|
1017
|
+
* @returns 已存储的 token,文件不存在或数据损坏时返回 undefined
|
|
1018
|
+
*/
|
|
1019
|
+
declare function loadToken(serverName: string): OAuthToken | undefined;
|
|
1020
|
+
/**
|
|
1021
|
+
* 将 token 原子写入 ~/.lynx/mcp-oauth.json。
|
|
1022
|
+
*
|
|
1023
|
+
* 按 serverName 为 key 分组存储,写入过程为原子操作
|
|
1024
|
+
*(写临时文件 + rename),不会因进程崩溃而产生损坏文件。
|
|
1025
|
+
*
|
|
1026
|
+
* @param serverName - MCP 服务器名称
|
|
1027
|
+
* @param token - 待持久化的 OAuth token
|
|
1028
|
+
*/
|
|
1029
|
+
declare function storeToken(serverName: string, token: OAuthToken): void;
|
|
1030
|
+
/**
|
|
1031
|
+
* 删除指定 server 的已存储 token。
|
|
1032
|
+
*
|
|
1033
|
+
* @param serverName - MCP 服务器名称
|
|
1034
|
+
*/
|
|
1035
|
+
declare function deleteToken(serverName: string): void;
|
|
1036
|
+
//#endregion
|
|
1037
|
+
//#region src/mcp/xaa.d.ts
|
|
1038
|
+
/**
|
|
1039
|
+
* XAA 身份认证结果。
|
|
1040
|
+
*
|
|
1041
|
+
* 包含 JWT access token、过期时间及 JWT claims,
|
|
1042
|
+
* 认证成功后持久化到 ~/.lynx/mcp-xaa.json。
|
|
1043
|
+
*/
|
|
1044
|
+
interface XaaIdentity {
|
|
1045
|
+
/** JWT access token。 */
|
|
1046
|
+
token: string;
|
|
1047
|
+
/** 过期时间(epoch ms)。 */
|
|
1048
|
+
expiresAt: number;
|
|
1049
|
+
/** JWT claims(iss, sub, aud 等)。 */
|
|
1050
|
+
claims: Record<string, unknown>;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* 执行 XAA (SEP-990) 企业身份认证流程。
|
|
1054
|
+
*
|
|
1055
|
+
* 完整步骤:
|
|
1056
|
+
* 1. PRM 发现 — GET {config.idpUrl}/.well-known/oauth-protected-resource 获取 AS URL
|
|
1057
|
+
* 2. AS 发现 — GET {asUrl}/.well-known/oauth-authorization-server 获取 token endpoint
|
|
1058
|
+
* 3. JWT Bearer Grant — 生成 HS256 JWT assertion → POST {tokenEndpoint}
|
|
1059
|
+
* 4. 本地持久化 — 写入 ~/.lynx/mcp-xaa.json
|
|
1060
|
+
*
|
|
1061
|
+
* @param config - XAA 认证配置
|
|
1062
|
+
* @returns 认证身份(含 token、过期时间、claims)
|
|
1063
|
+
* @throws 参数校验失败、发现失败、Token 交换失败 时抛出
|
|
1064
|
+
*/
|
|
1065
|
+
declare function performXaaLogin(config: McpXaaConfig): Promise<XaaIdentity>;
|
|
1066
|
+
/**
|
|
1067
|
+
* 用已缓存的 identity 尝试静默刷新。
|
|
1068
|
+
*
|
|
1069
|
+
* - 如果 token 仍然有效(expiresAt > now + 5min),直接返回缓存的身份
|
|
1070
|
+
* - 否则重新执行完整的 XAA 认证流程
|
|
1071
|
+
*
|
|
1072
|
+
* 刷新成功后自动更新持久化存储。
|
|
1073
|
+
*
|
|
1074
|
+
* @param config - XAA 认证配置(必须包含 serverName 或通过 loadIdentity/storeIdentity 使用)
|
|
1075
|
+
* @returns 有效的认证身份
|
|
1076
|
+
*/
|
|
1077
|
+
declare function refreshXaaToken(config: McpXaaConfig): Promise<XaaIdentity>;
|
|
1078
|
+
/**
|
|
1079
|
+
* 从 ~/.lynx/mcp-xaa.json 加载已存储的身份。
|
|
1080
|
+
*
|
|
1081
|
+
* @param serverName - MCP 服务器名称(用作存储键)
|
|
1082
|
+
* @returns 有效的 XaaIdentity,或 undefined 如果文件不存在 / token 已过期 / 数据损坏
|
|
1083
|
+
*/
|
|
1084
|
+
declare function loadIdentity(serverName: string): XaaIdentity | undefined;
|
|
1085
|
+
/**
|
|
1086
|
+
* 原子存储身份到 ~/.lynx/mcp-xaa.json。
|
|
1087
|
+
*
|
|
1088
|
+
* 读取现有缓存 → 更新目标 serverName 条目 → 原子写入。
|
|
1089
|
+
* 多进程并发写入由 rename 的原子性保证:最后一次写入获胜。
|
|
1090
|
+
*
|
|
1091
|
+
* @param serverName - MCP 服务器名称(用作存储键)
|
|
1092
|
+
* @param identity - 要存储的身份信息
|
|
1093
|
+
*/
|
|
1094
|
+
declare function storeIdentity(serverName: string, identity: XaaIdentity): void;
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/memory/manager.d.ts
|
|
1097
|
+
/**
|
|
1098
|
+
* Memory manager — persistent key‑value facts that survive
|
|
1099
|
+
* across sessions.
|
|
1100
|
+
*
|
|
1101
|
+
* Memory entries are simple markdown files with frontmatter,
|
|
1102
|
+
* stored in a configured directory. The agent can read/write
|
|
1103
|
+
* memories via tools.
|
|
1104
|
+
*
|
|
1105
|
+
* Pattern: inspired by Claude Code's memory system —
|
|
1106
|
+
* ● Each fact is one file
|
|
1107
|
+
* ● Frontmatter contains metadata (type, tags, timestamp)
|
|
1108
|
+
* ● An index file (MEMORY.md) lists all entries for fast scanning
|
|
1109
|
+
* ● Loading reads the index first, then lazy‑loads individual files
|
|
1110
|
+
*/
|
|
1111
|
+
interface MemoryEntry {
|
|
1112
|
+
/** File stem (slug). */
|
|
1113
|
+
name: string;
|
|
1114
|
+
/** Short description for relevance matching. */
|
|
1115
|
+
description: string;
|
|
1116
|
+
/** When the entry was last modified (Unix ms). */
|
|
1117
|
+
updatedAt: number;
|
|
1118
|
+
/** Full markdown content (lazy‑loaded). */
|
|
1119
|
+
content?: string;
|
|
1120
|
+
/** Metadata from frontmatter. */
|
|
1121
|
+
type: "user" | "feedback" | "project" | "reference";
|
|
1122
|
+
/** Absolute file path on disk. */
|
|
1123
|
+
filePath: string;
|
|
1124
|
+
/** Arbitrary extra metadata fields from frontmatter (e.g. tags, source). */
|
|
1125
|
+
metadata?: Record<string, unknown>;
|
|
1126
|
+
}
|
|
1127
|
+
interface MemoryManager {
|
|
1128
|
+
/** Load the index (all memory names + descriptions). */
|
|
1129
|
+
list(): MemoryEntry[];
|
|
1130
|
+
/** Load a single memory entry by name. */
|
|
1131
|
+
get(name: string): MemoryEntry | undefined;
|
|
1132
|
+
/** Write (create or update) a memory entry. */
|
|
1133
|
+
put(entry: MemoryEntry): void;
|
|
1134
|
+
/** Delete a memory entry by name. */
|
|
1135
|
+
delete(name: string): boolean;
|
|
1136
|
+
/** Reload the index from disk. */
|
|
1137
|
+
reload(): void;
|
|
1138
|
+
/** 全文搜索记忆 — 在名称、描述、内容中匹配关键词。按相关度排序。 */
|
|
1139
|
+
search(query: string): MemoryEntry[];
|
|
1140
|
+
/** 去重压缩 — 合并 Jaccard 相似度 > 0.8 的条目。返回合并后的条目列表。 */
|
|
1141
|
+
compact(): MemoryEntry[];
|
|
1142
|
+
/** 按 glob 模式批量删除匹配的记忆。返回删除的条目数。 */
|
|
1143
|
+
forget(pattern: string): number;
|
|
1144
|
+
/** 将所有记忆序列化为 JSON 字符串。 */
|
|
1145
|
+
exportAll(): string;
|
|
1146
|
+
/** 从 JSON 字符串批量导入记忆。跳过已存在的同名条目。返回导入数量。 */
|
|
1147
|
+
importAll(data: string): number;
|
|
1148
|
+
/** 合并另一个 memory 目录中的记忆文件。跳过冲突。返回合并的条目数。 */
|
|
1149
|
+
merge(sourceDir: string): number;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Create a memory manager backed by a directory on disk.
|
|
1153
|
+
*
|
|
1154
|
+
* If the directory doesn't exist, it is created.
|
|
1155
|
+
*/
|
|
1156
|
+
declare function createMemoryManager(dir: string): MemoryManager;
|
|
1157
|
+
//#endregion
|
|
1158
|
+
//#region src/memory/semantic-search.d.ts
|
|
1159
|
+
/** 单条搜索结果 */
|
|
1160
|
+
interface SemanticSearchResult {
|
|
1161
|
+
entry: MemoryEntry;
|
|
1162
|
+
score: number;
|
|
1163
|
+
/** 高亮片段 — 匹配词用 **...** 包裹 */
|
|
1164
|
+
snippet: string;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* 跨所有记忆执行语义搜索。
|
|
1168
|
+
*
|
|
1169
|
+
* 算法:
|
|
1170
|
+
* 1. 将查询解析为词元,移除停用词
|
|
1171
|
+
* 2. 对每条记忆计算:
|
|
1172
|
+
* - TF:词元在内容中出现的频率,按内容长度归一化
|
|
1173
|
+
* - 标题加权:匹配 entry.name 的词元权重 x3
|
|
1174
|
+
* - 描述加权:匹配 entry.description 的词元权重 x2
|
|
1175
|
+
* - 时间加权:越新的条目得分越高(1.0 ~ 0.5)
|
|
1176
|
+
* 3. 返回 topK 个结果,按评分降序排列,
|
|
1177
|
+
* 每条附带一个包含高亮标记的片段
|
|
1178
|
+
*/
|
|
1179
|
+
declare function searchMemorySemantic(manager: MemoryManager, query: string, topK?: number): SemanticSearchResult[];
|
|
1180
|
+
//#endregion
|
|
1181
|
+
//#region src/memory/expiry.d.ts
|
|
1182
|
+
/** 过期管理器接口 */
|
|
1183
|
+
interface ExpiryManager {
|
|
1184
|
+
/** 检查所有记忆并归档过期条目。返回归档数量。 */
|
|
1185
|
+
checkAndArchive(): number;
|
|
1186
|
+
/** 获取条目的时间衰减权重(0.0-1.0)。越新越高。 */
|
|
1187
|
+
getWeight(entry: MemoryEntry): number;
|
|
1188
|
+
/** 为条目设置过期天数。day=0 表示永不过期。 */
|
|
1189
|
+
setExpiry(name: string, days: number): void;
|
|
1190
|
+
/** 按权重升序排列条目(最低——最接近过期——排在前面)。 */
|
|
1191
|
+
listByExpiry(): Array<{
|
|
1192
|
+
name: string;
|
|
1193
|
+
weight: number;
|
|
1194
|
+
daysRemaining: number;
|
|
1195
|
+
}>;
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* 创建过期管理器。
|
|
1199
|
+
*
|
|
1200
|
+
* @param memoryDir - 记忆文件目录(如 ~/.lynx/memory/)
|
|
1201
|
+
*/
|
|
1202
|
+
declare function createExpiryManager(memoryDir: string): ExpiryManager;
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/memory/active-refine.d.ts
|
|
1205
|
+
/** 单条精炼建议 */
|
|
1206
|
+
interface RefinementSuggestion {
|
|
1207
|
+
entryName: string;
|
|
1208
|
+
reason: "内容过长" | "可能重复" | "信息过时" | "格式不规范";
|
|
1209
|
+
/** 面向人类可读的建议文本 */
|
|
1210
|
+
suggestion: string;
|
|
1211
|
+
}
|
|
1212
|
+
/** 活跃精炼管理器接口 */
|
|
1213
|
+
interface ActiveRefinementManager {
|
|
1214
|
+
/** 建议可以精炼的条目(过长、重复、过时、不规范)。 */
|
|
1215
|
+
suggestRefinements(): RefinementSuggestion[];
|
|
1216
|
+
/** 合并两条条目 — 将 source 的内容追加到 target 中,删除 source。 */
|
|
1217
|
+
mergeEntries(target: string, source: string): MemoryEntry;
|
|
1218
|
+
/** 摘要条目 — 将内容截断至 maxChars,添加摘要行。 */
|
|
1219
|
+
summarizeEntry(name: string, maxChars?: number): MemoryEntry;
|
|
1220
|
+
/** 检测并报告近似重复条目(内容 bigram Jaccard > 0.6)。 */
|
|
1221
|
+
findDuplicates(): Array<{
|
|
1222
|
+
entryA: string;
|
|
1223
|
+
entryB: string;
|
|
1224
|
+
similarity: number;
|
|
1225
|
+
}>;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* 创建活跃精炼管理器。
|
|
1229
|
+
*
|
|
1230
|
+
* 封装记忆精炼建议、合并、摘要和重复检测逻辑,
|
|
1231
|
+
* 供 agent 引擎定期或按需调用。
|
|
1232
|
+
*/
|
|
1233
|
+
declare function createActiveRefinementManager(memoryManager: MemoryManager): ActiveRefinementManager;
|
|
1234
|
+
//#endregion
|
|
1235
|
+
//#region src/memory/team.d.ts
|
|
1236
|
+
/** 团队上下文 */
|
|
1237
|
+
interface TeamContext {
|
|
1238
|
+
/** 团队 CLAUDE.md 文件内容 */
|
|
1239
|
+
teamClaudeMd: string;
|
|
1240
|
+
/** 团队规则列表(rules/ 目录下每个 .md 文件一条) */
|
|
1241
|
+
teamRules: string[];
|
|
1242
|
+
/** 团队事实(memory/ 目录中的记忆条目名) */
|
|
1243
|
+
teamFacts: string[];
|
|
1244
|
+
}
|
|
1245
|
+
/** 团队记忆管理器接口 */
|
|
1246
|
+
interface TeamMemoryManager {
|
|
1247
|
+
/** 从团队目录加载团队上下文。 */
|
|
1248
|
+
loadTeamContext(): TeamContext;
|
|
1249
|
+
/** 写入团队记忆条目(在 teamDir/memory/ 下创建/更新文件)。 */
|
|
1250
|
+
write(name: string, content: string, author: string): void;
|
|
1251
|
+
/** 列出所有团队记忆条目。 */
|
|
1252
|
+
list(): MemoryEntry[];
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* 创建团队记忆管理器。
|
|
1256
|
+
*
|
|
1257
|
+
* @param teamDir - 团队目录路径(如 /workspace/.claude/team/ 或 ~/.lynx/team/)
|
|
1258
|
+
*/
|
|
1259
|
+
declare function createTeamMemoryManager(teamDir: string): TeamMemoryManager;
|
|
1260
|
+
//#endregion
|
|
1261
|
+
//#region src/tasks/manager.d.ts
|
|
1262
|
+
/**
|
|
1263
|
+
* Background task manager — runs persistent tasks with lifecycle tracking.
|
|
1264
|
+
*
|
|
1265
|
+
* Tasks are long‑running operations (file watchers, MCP heartbeats,
|
|
1266
|
+
* auto‑save timers) that outlive a single query turn. The manager
|
|
1267
|
+
* provides start/stop/status for each task and graceful shutdown.
|
|
1268
|
+
*/
|
|
1269
|
+
interface TaskEntry {
|
|
1270
|
+
id: string;
|
|
1271
|
+
label: string;
|
|
1272
|
+
status: "running" | "stopping" | "stopped" | "errored";
|
|
1273
|
+
startedAt: number;
|
|
1274
|
+
stoppedAt?: number;
|
|
1275
|
+
error?: string;
|
|
1276
|
+
/** Accumulated output text. */
|
|
1277
|
+
output?: string;
|
|
1278
|
+
/** Progress percentage 0-100. */
|
|
1279
|
+
progress?: number;
|
|
1280
|
+
/** Output chunks with timestamps for streaming. */
|
|
1281
|
+
outputChunks?: Array<{
|
|
1282
|
+
text: string;
|
|
1283
|
+
timestamp: number;
|
|
1284
|
+
}>;
|
|
1285
|
+
}
|
|
1286
|
+
interface TaskManager {
|
|
1287
|
+
/** Register and start a background task. Returns a stop function. */
|
|
1288
|
+
start(id: string, label: string, run: (signal: AbortSignal) => Promise<void>): Promise<void>;
|
|
1289
|
+
/** Request graceful stop of a task. */
|
|
1290
|
+
stop(id: string): Promise<void>;
|
|
1291
|
+
/** Get a single task entry by id. Returns undefined if not found. */
|
|
1292
|
+
get(id: string): TaskEntry | undefined;
|
|
1293
|
+
/** Get status for all tasks. */
|
|
1294
|
+
list(): TaskEntry[];
|
|
1295
|
+
/** Get accumulated output for a task. */
|
|
1296
|
+
getOutput(id: string): string;
|
|
1297
|
+
/** Get all output chunks for a task since a given offset. */
|
|
1298
|
+
getOutputSince(id: string, sinceIndex: number): {
|
|
1299
|
+
output: string;
|
|
1300
|
+
newIndex: number;
|
|
1301
|
+
};
|
|
1302
|
+
/** Update task metadata (label, status, etc.). */
|
|
1303
|
+
update(id: string, patch: Partial<Pick<TaskEntry, "label" | "status">>): void;
|
|
1304
|
+
/** Stop all tasks and wait for them to finish. */
|
|
1305
|
+
destroy(): Promise<void>;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Create a background task manager.
|
|
1309
|
+
*
|
|
1310
|
+
* Each task receives an AbortSignal — when the manager calls stop(),
|
|
1311
|
+
* the signal fires and the task should clean up and exit.
|
|
1312
|
+
*/
|
|
1313
|
+
declare function createTaskManager(): TaskManager;
|
|
1314
|
+
//#endregion
|
|
1315
|
+
export { type ActiveRefinementManager, type AgentConfig, type AgentSnapshot, type AgentState, type AgentStatus, type AssembleOptions, type BudgetTracker, type CallToolResult, type CompactionManager, type CompactionResult, type CompactionStrategy, type EngineDeps, type ExpiryManager, type HandoffContext, type InProcTransport, type LaneDispatcher, type LaneJob, type LaneResult, type LoopDeps, type McpConnection, type McpManager, type McpOAuthConfig, type McpResource, type McpServerConfig, type McpStatusEvent, type McpStatusListener, type McpTransportKind, type MemoryEntry, type MemoryManager, type OAuthToken, type ParallelResult, type ParallelTask, type PermissionBridge, type PermissionScope, type PrefixCacheManager, type PrefixStabilityReport, type QueryEngine, type RefinementSuggestion, SKILL_TOOL_NAME, type SemanticSearchResult, type SkillDefinition, type SkillEntry, type SkillLoadStatus, type SkillRegistry, type SkillState, type SkillWatcher, type CallToolResult$1 as SseCallToolResult, type SseMcpConnection, type SubAgentConfig, type SubAgentResult, type TaskEntry, type TaskManager, type TeamContext, type TeamMemoryManager, type TurnContext, type WebSocketConnection, type CallToolResult$2 as WsCallToolResult, type XaaIdentity, advanceTurn, assembleSystemPrompt, buildMessagesForTurn, callToolSse, callToolWs, captureSnapshot, computeFrozenHash, connectInProcTransport, connectSseTransport, connectStdioTransport, connectWsTransport, createActiveRefinementManager, createAgentState, createBudgetTracker, createCompactionManager, createExpiryManager, createInProcPair, createLaneDispatcher, createMcpManager, createMemoryManager, createPermissionBridge, createPrefixCacheManager, createQueryEngine, createSkillRegistry, createSkillState, createSkillToolHandler, createSkillWatcher, createTaskManager, createTeamMemoryManager, deleteToken, disconnectStdioTransport, estimateSnapshotTokens, extractFrozenZone, extractHotZone, extractMcpServerName, extractMcpToolName, extractWarmZone, generateHandoff, getBaseSystemPrompt, isCompactionCircuitOpen, isSnapshotValid, loadIdentity, loadProjectContext, loadToken, mergeSnapshot, needsHandoff, performPkceFlow, performXaaLogin, queryLoop, recordCompactionFailure, recordCompactionSuccess, recordError, refreshOAuthToken, refreshXaaToken, renderHandoffBlock, renderSkillBody, renderSkillCatalog, renderSkillSummary, runInParallel, sameFrozenPrefix, searchMemorySemantic, spawnSubAgent, storeIdentity, storeToken, transition };
|
|
1316
|
+
//# sourceMappingURL=index.d.mts.map
|