@kiturone/kapibala 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.cjs +1859 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +354 -22
- package/dist/index.d.ts +354 -22
- package/dist/index.js +1841 -117
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ interface ToolResultBlock {
|
|
|
19
19
|
isError?: boolean;
|
|
20
20
|
/** 单次工具调用总耗时,包含 tool hooks 与实际执行。 */
|
|
21
21
|
durationMs?: number;
|
|
22
|
+
/** 稳定错误类别;旧历史中的该字段可缺省。 */
|
|
23
|
+
errorCode?: string;
|
|
24
|
+
/** 不代表自动重试,只描述调用方应如何处理该错误。 */
|
|
25
|
+
retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
22
26
|
}
|
|
23
27
|
interface ThinkingBlock {
|
|
24
28
|
type: 'thinking';
|
|
@@ -112,6 +116,12 @@ type SessionEvent = {
|
|
|
112
116
|
id: string;
|
|
113
117
|
name: string;
|
|
114
118
|
input: Record<string, unknown>;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'tool_progress';
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
elapsedMs: number;
|
|
124
|
+
outputBytes: number;
|
|
115
125
|
} | {
|
|
116
126
|
type: 'tool_finish';
|
|
117
127
|
id: string;
|
|
@@ -191,7 +201,14 @@ interface ModelRequest {
|
|
|
191
201
|
* Error Taxonomy for Kapibala Agent Harness
|
|
192
202
|
*/
|
|
193
203
|
declare class KapibalaError extends Error {
|
|
194
|
-
|
|
204
|
+
readonly code: string;
|
|
205
|
+
readonly retryPolicy: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
206
|
+
readonly safeMessage: string;
|
|
207
|
+
constructor(message: string, options?: {
|
|
208
|
+
code?: string;
|
|
209
|
+
retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
|
|
210
|
+
safeMessage?: string;
|
|
211
|
+
});
|
|
195
212
|
}
|
|
196
213
|
declare class ModelError extends KapibalaError {
|
|
197
214
|
readonly status?: number;
|
|
@@ -223,6 +240,248 @@ declare class SessionBusyError extends KapibalaError {
|
|
|
223
240
|
constructor(operation: string);
|
|
224
241
|
}
|
|
225
242
|
|
|
243
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
244
|
+
type LogChannel = 'operation' | 'audit';
|
|
245
|
+
type LogField = string | number | boolean | null;
|
|
246
|
+
/** 单条可持久化的脱敏运行或审计事件。 */
|
|
247
|
+
interface LogEvent {
|
|
248
|
+
schemaVersion: 1;
|
|
249
|
+
timestamp: string;
|
|
250
|
+
level: LogLevel;
|
|
251
|
+
channel: LogChannel;
|
|
252
|
+
event: string;
|
|
253
|
+
sessionId: string;
|
|
254
|
+
runId?: string;
|
|
255
|
+
operationId?: string;
|
|
256
|
+
toolUseId?: string;
|
|
257
|
+
fields: Record<string, LogField>;
|
|
258
|
+
}
|
|
259
|
+
/** 宿主提供的事件存储入口;审计 Sink 的写入完成代表已持久化。 */
|
|
260
|
+
interface LogSink {
|
|
261
|
+
write(event: LogEvent): Promise<void>;
|
|
262
|
+
}
|
|
263
|
+
interface LogInput {
|
|
264
|
+
level: LogLevel;
|
|
265
|
+
event: string;
|
|
266
|
+
sessionId: string;
|
|
267
|
+
runId?: string;
|
|
268
|
+
operationId?: string;
|
|
269
|
+
toolUseId?: string;
|
|
270
|
+
fields?: Record<string, unknown>;
|
|
271
|
+
}
|
|
272
|
+
/** Core 与宿主共同使用的运行日志和审批审计入口。 */
|
|
273
|
+
interface EventLogger {
|
|
274
|
+
record(event: LogInput): Promise<void>;
|
|
275
|
+
recordAudit(event: LogInput): Promise<void>;
|
|
276
|
+
}
|
|
277
|
+
/** 将任意来源的字段缩减为可写入日志的固定集合。 */
|
|
278
|
+
declare function projectSafeFields(fields: Record<string, unknown>): Record<string, LogField>;
|
|
279
|
+
/** 生成不依赖模型工具调用 ID 的内部关联标识。 */
|
|
280
|
+
declare function createLogId(): string;
|
|
281
|
+
/** 只暴露固定命令类别与参数数目,避免把自由文本写入审计。 */
|
|
282
|
+
declare function commandAuditSummary(command: string): {
|
|
283
|
+
commandDigest: string;
|
|
284
|
+
commandPreview: string;
|
|
285
|
+
commandLength: number;
|
|
286
|
+
argumentCount: number;
|
|
287
|
+
};
|
|
288
|
+
/** 将批准范围绑定到最终命令、解释器、目录与执行选项。 */
|
|
289
|
+
declare function executionFingerprint(input: {
|
|
290
|
+
command: string;
|
|
291
|
+
shell: string;
|
|
292
|
+
executable: string;
|
|
293
|
+
cwd: string;
|
|
294
|
+
environmentDigest: string;
|
|
295
|
+
timeoutMs: number;
|
|
296
|
+
outputLimitBytes: number;
|
|
297
|
+
targetDigest?: string;
|
|
298
|
+
}): string;
|
|
299
|
+
/** 统一筛选和脱敏日志;运行日志失败只报告安全诊断,审计失败仍向调用方传播。 */
|
|
300
|
+
declare class StructuredLogger implements EventLogger {
|
|
301
|
+
private readonly operationSink;
|
|
302
|
+
private readonly auditSink;
|
|
303
|
+
private readonly debug;
|
|
304
|
+
private readonly onDiagnostic?;
|
|
305
|
+
constructor(options: {
|
|
306
|
+
operationSink: LogSink;
|
|
307
|
+
auditSink: LogSink;
|
|
308
|
+
debug?: boolean;
|
|
309
|
+
onDiagnostic?: (message: string) => void;
|
|
310
|
+
});
|
|
311
|
+
/** 普通日志写入失败不阻断业务,也不声称持久化成功;诊断不携带原始异常内容。 */
|
|
312
|
+
record(event: LogInput): Promise<void>;
|
|
313
|
+
/** 审计必须成功持久化;异常交由执行器拒绝启动工具或报告已执行操作的结果未知。 */
|
|
314
|
+
recordAudit(event: LogInput): Promise<void>;
|
|
315
|
+
private format;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
interface FileLogSinkOptions {
|
|
319
|
+
directory: string;
|
|
320
|
+
prefix: 'operation' | 'audit';
|
|
321
|
+
maxBytes?: number;
|
|
322
|
+
retentionDays?: number;
|
|
323
|
+
sync?: boolean;
|
|
324
|
+
}
|
|
325
|
+
/** 将每条 JSONL 事件完整追加到本地文件,并按日期及文件大小轮转。 */
|
|
326
|
+
declare class FileLogSink implements LogSink {
|
|
327
|
+
readonly directory: string;
|
|
328
|
+
readonly prefix: 'operation' | 'audit';
|
|
329
|
+
private readonly maxBytes;
|
|
330
|
+
private readonly retentionDays?;
|
|
331
|
+
private readonly sync;
|
|
332
|
+
constructor(options: FileLogSinkOptions);
|
|
333
|
+
write(event: LogEvent): Promise<void>;
|
|
334
|
+
/** 返回该通道已占用的字节数,供宿主提示长期保留的审计用量。 */
|
|
335
|
+
getUsageBytes(): number;
|
|
336
|
+
private chooseFile;
|
|
337
|
+
private cleanupExpired;
|
|
338
|
+
private isOwnedFile;
|
|
339
|
+
}
|
|
340
|
+
/** 构造 CLI 与默认 SDK 使用的用户级运行及审计 Sink。 */
|
|
341
|
+
declare function createDefaultLogSinks(baseDirectory?: string): {
|
|
342
|
+
operationSink: FileLogSink;
|
|
343
|
+
auditSink: FileLogSink;
|
|
344
|
+
};
|
|
345
|
+
/** 启动时保守关闭上次进程未完成的审计事务,绝不将其当作未执行或自动重试。 */
|
|
346
|
+
declare function recoverIncompleteAudit(directory: string): Promise<number>;
|
|
347
|
+
|
|
348
|
+
interface InstructionSource {
|
|
349
|
+
path: string;
|
|
350
|
+
content: string;
|
|
351
|
+
}
|
|
352
|
+
interface InstructionSnapshot {
|
|
353
|
+
sources: readonly InstructionSource[];
|
|
354
|
+
totalBytes: number;
|
|
355
|
+
}
|
|
356
|
+
interface InstructionLoadOptions {
|
|
357
|
+
projectRoot: string;
|
|
358
|
+
cwd: string;
|
|
359
|
+
userFile?: string;
|
|
360
|
+
}
|
|
361
|
+
/** 按用户层和项目根至 cwd 的目录链读取指令,全部成功后才返回快照。 */
|
|
362
|
+
declare function loadInstructions(options: InstructionLoadOptions): InstructionSnapshot;
|
|
363
|
+
|
|
364
|
+
type ShellKind = 'bash' | 'wsl' | 'pwsh' | 'powershell';
|
|
365
|
+
/** auto / 具名解释器,或用户显式提供的解释器可执行文件全路径。 */
|
|
366
|
+
type ShellPreference = 'auto' | ShellKind | (string & {});
|
|
367
|
+
interface ShellEnvironment {
|
|
368
|
+
kind: ShellKind;
|
|
369
|
+
executable: string;
|
|
370
|
+
executableDigest: string;
|
|
371
|
+
cwd: string;
|
|
372
|
+
}
|
|
373
|
+
interface ShellDetectOptions {
|
|
374
|
+
preference?: ShellPreference;
|
|
375
|
+
cwd: string;
|
|
376
|
+
platform?: NodeJS.Platform;
|
|
377
|
+
pathEnv?: string;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* 按 uname 输出分类 bash 家族:Git Bash/MSYS2/Cygwin 归 native bash,
|
|
381
|
+
* Windows 上报告 Linux 的是 WSL launcher(独立 kind,路径语义不同)。
|
|
382
|
+
*/
|
|
383
|
+
declare function classifyBashOutput(unameOutput: string, platform: NodeJS.Platform): ShellKind | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* 发现并固定实际解释器:只用 PATH 与用户显式给出的路径,不写死任何安装目录。
|
|
386
|
+
* auto 在 Windows 上按 native Bash → WSL → pwsh → powershell 依次兜底,
|
|
387
|
+
* bash 家族用运行时 uname 探针区分 Git Bash 与 WSL launcher。
|
|
388
|
+
*/
|
|
389
|
+
declare function detectShell(options: ShellDetectOptions): ShellEnvironment;
|
|
390
|
+
|
|
391
|
+
/** 本次会话的自动执行边界;FullAccess 只能由宿主为本次会话显式选择。 */
|
|
392
|
+
type SessionMode = 'Approval' | 'Plan' | 'Auto' | 'FullAccess';
|
|
393
|
+
type PermissionAction = 'allow' | 'ask' | 'deny';
|
|
394
|
+
interface ShellScope {
|
|
395
|
+
command: string;
|
|
396
|
+
interpreter: string;
|
|
397
|
+
executablePath?: string;
|
|
398
|
+
cwd: string;
|
|
399
|
+
executableDigest?: string;
|
|
400
|
+
scriptDigest?: string;
|
|
401
|
+
executionFingerprint?: string;
|
|
402
|
+
}
|
|
403
|
+
interface PermissionRule {
|
|
404
|
+
action: PermissionAction;
|
|
405
|
+
tool?: string;
|
|
406
|
+
capability?: Capability;
|
|
407
|
+
shell?: ShellScope;
|
|
408
|
+
}
|
|
409
|
+
interface PermissionRequest {
|
|
410
|
+
mode: SessionMode;
|
|
411
|
+
toolName: string;
|
|
412
|
+
capabilities: readonly Capability[];
|
|
413
|
+
dangerous?: boolean;
|
|
414
|
+
hardDenied?: boolean;
|
|
415
|
+
shell?: ShellScope;
|
|
416
|
+
rules?: readonly PermissionRule[];
|
|
417
|
+
cachedApproval?: boolean;
|
|
418
|
+
cachedDenial?: boolean;
|
|
419
|
+
}
|
|
420
|
+
interface PermissionDecision {
|
|
421
|
+
decision: PermissionAction;
|
|
422
|
+
source: 'hard_limit' | 'plan' | 'explicit_rule' | 'session_cache' | 'mode_default';
|
|
423
|
+
ruleIndex?: number;
|
|
424
|
+
}
|
|
425
|
+
/** 拒绝含糊的 Shell 前缀/通配符和结构不完整的规则。 */
|
|
426
|
+
declare function validatePermissionRules(rules: readonly PermissionRule[]): void;
|
|
427
|
+
/** 纯策略裁决;宿主硬限制和 Plan 始终先于任何规则或会话缓存。 */
|
|
428
|
+
declare class PermissionPolicy {
|
|
429
|
+
decide(request: PermissionRequest): PermissionDecision;
|
|
430
|
+
}
|
|
431
|
+
/** 只向模型展示当前模式与整项拒绝规则允许请求的工具。 */
|
|
432
|
+
declare function visibleTools(tools: readonly Tool[], mode: SessionMode, rules?: readonly PermissionRule[]): Tool[];
|
|
433
|
+
|
|
434
|
+
type Capability = 'fs:read' | 'fs:write' | 'exec' | 'net:outbound' | 'env:read' | 'agent:spawn';
|
|
435
|
+
interface ToolMetadata {
|
|
436
|
+
source?: string;
|
|
437
|
+
dangerous?: boolean;
|
|
438
|
+
/** 所需能力的声明;v0.0.1 不据此授权,v0.0.2 的执行前权限决策才会消费。 */
|
|
439
|
+
permissions?: Capability[];
|
|
440
|
+
/** 工具自身等待进程资源回收,执行器不可再使用通用 Promise.race 超时。 */
|
|
441
|
+
managesTimeout?: boolean;
|
|
442
|
+
}
|
|
443
|
+
interface ToolContext {
|
|
444
|
+
rootDir: string;
|
|
445
|
+
signal?: AbortSignal;
|
|
446
|
+
logger?: (message: string) => void;
|
|
447
|
+
/** 命令工具在真实进程创建后调用;审计失败时须先回收进程再报告结果未知。 */
|
|
448
|
+
onProcessSpawned?: () => Promise<void>;
|
|
449
|
+
onProgress?: (progress: {
|
|
450
|
+
elapsedMs: number;
|
|
451
|
+
outputBytes: number;
|
|
452
|
+
}) => void;
|
|
453
|
+
}
|
|
454
|
+
interface Tool<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
455
|
+
readonly name: string;
|
|
456
|
+
readonly description: string;
|
|
457
|
+
readonly parameters: Record<string, unknown>;
|
|
458
|
+
readonly metadata?: ToolMetadata;
|
|
459
|
+
approvalScope?(input: TInput, rootDir: string): ShellScope;
|
|
460
|
+
execute(input: TInput, ctx: ToolContext): Promise<TOutput>;
|
|
461
|
+
}
|
|
462
|
+
declare function defineTool<TInput = Record<string, unknown>, TOutput = unknown>(tool: Tool<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
463
|
+
declare function toToolDefinition(tool: Tool): ToolDefinition;
|
|
464
|
+
|
|
465
|
+
interface RunCommandInput {
|
|
466
|
+
[key: string]: unknown;
|
|
467
|
+
command: string;
|
|
468
|
+
cwd?: string;
|
|
469
|
+
timeout_ms?: number;
|
|
470
|
+
}
|
|
471
|
+
interface CommandResult {
|
|
472
|
+
exitCode: number | null;
|
|
473
|
+
output: string;
|
|
474
|
+
outputTruncated: boolean;
|
|
475
|
+
outputFile?: string;
|
|
476
|
+
outputFileTruncated: boolean;
|
|
477
|
+
outputBytes: number;
|
|
478
|
+
shell: ShellEnvironment['kind'];
|
|
479
|
+
}
|
|
480
|
+
/** 仅清理受管 UUID 文件,避免删除用户在同目录保存的结果。 */
|
|
481
|
+
declare function cleanupCommandResults(rootDir: string, now?: number): void;
|
|
482
|
+
/** 使用固定解释器执行命令;超时和中止必须先处理进程树再返回。 */
|
|
483
|
+
declare function createRunCommandTool(environment: ShellEnvironment): Tool<RunCommandInput, CommandResult>;
|
|
484
|
+
|
|
226
485
|
interface SandboxConfig {
|
|
227
486
|
rootDir: string;
|
|
228
487
|
/**
|
|
@@ -260,27 +519,28 @@ declare class PathSandbox {
|
|
|
260
519
|
private toPhysicalPath;
|
|
261
520
|
}
|
|
262
521
|
|
|
263
|
-
type
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
interface ToolContext {
|
|
522
|
+
type ApprovalChoice = 'allow_once' | 'allow_session' | 'deny_once' | 'deny_session' | 'cancel';
|
|
523
|
+
/** 宿主展示实际执行目标并取得人工选择;无通道视为非交互拒绝。 */
|
|
524
|
+
interface ApprovalRequest {
|
|
525
|
+
toolName: string;
|
|
526
|
+
capabilities: readonly Capability[];
|
|
527
|
+
input: Record<string, unknown>;
|
|
271
528
|
rootDir: string;
|
|
272
|
-
|
|
273
|
-
|
|
529
|
+
shell?: ShellScope;
|
|
530
|
+
sessionAllowed: boolean;
|
|
274
531
|
}
|
|
275
|
-
interface
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
532
|
+
interface ApprovalChannel {
|
|
533
|
+
requestApproval(request: ApprovalRequest, signal?: AbortSignal): Promise<ApprovalChoice>;
|
|
534
|
+
}
|
|
535
|
+
/** 规范化 JSON 序列化:递归对对象键按字典序排序,保证相同的输入结构产生一致的字符串和 Hash。 */
|
|
536
|
+
declare function stableJsonStringify(value: unknown): string;
|
|
537
|
+
/** 只在当前 Session 内复用精确调用范围,不存储原始工具参数。 */
|
|
538
|
+
declare class SessionApprovalCache {
|
|
539
|
+
private readonly choices;
|
|
540
|
+
key(request: ApprovalRequest): string;
|
|
541
|
+
get(request: ApprovalRequest): 'allow' | 'deny' | undefined;
|
|
542
|
+
set(request: ApprovalRequest, choice: 'allow' | 'deny'): void;
|
|
281
543
|
}
|
|
282
|
-
declare function defineTool<TInput = Record<string, unknown>, TOutput = unknown>(tool: Tool<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
283
|
-
declare function toToolDefinition(tool: Tool): ToolDefinition;
|
|
284
544
|
|
|
285
545
|
type ConflictPolicy = 'error' | 'prefer-builtin' | 'prefer-last';
|
|
286
546
|
declare class ToolRegistry {
|
|
@@ -408,6 +668,13 @@ interface ExecutorOptions {
|
|
|
408
668
|
logger?: (msg: string) => void;
|
|
409
669
|
/** 单次工具执行超时(毫秒)。异步挂起的工具超时后返回 isError 结果,避免永久卡死会话循环 */
|
|
410
670
|
toolTimeoutMs?: number;
|
|
671
|
+
eventLogger?: EventLogger;
|
|
672
|
+
sessionId?: string;
|
|
673
|
+
runId?: string;
|
|
674
|
+
mode?: SessionMode | (() => SessionMode);
|
|
675
|
+
permissionRules?: readonly PermissionRule[];
|
|
676
|
+
approvalChannel?: ApprovalChannel;
|
|
677
|
+
approvalCache?: SessionApprovalCache;
|
|
411
678
|
}
|
|
412
679
|
declare class ToolExecutor {
|
|
413
680
|
private readonly tools;
|
|
@@ -416,9 +683,33 @@ declare class ToolExecutor {
|
|
|
416
683
|
private readonly signal?;
|
|
417
684
|
private readonly logger?;
|
|
418
685
|
private readonly toolTimeoutMs;
|
|
686
|
+
private readonly eventLogger?;
|
|
687
|
+
private readonly sessionId?;
|
|
688
|
+
private readonly runId?;
|
|
689
|
+
private readonly mode;
|
|
690
|
+
private readonly permissionRules;
|
|
691
|
+
private readonly approvalChannel?;
|
|
692
|
+
private readonly approvalCache;
|
|
693
|
+
private readonly policy;
|
|
694
|
+
private readonly neverFailures;
|
|
695
|
+
private readonly cancellation;
|
|
419
696
|
constructor(options: ExecutorOptions);
|
|
420
|
-
runAll
|
|
421
|
-
|
|
697
|
+
/** 中止本轮正在等待或执行的工具;调用方仍须等待 runAll 完成资源回收及结果审计。 */
|
|
698
|
+
cancel(): void;
|
|
699
|
+
runAll(calls: ToolUseBlock[], onProgress?: (event: {
|
|
700
|
+
id: string;
|
|
701
|
+
name: string;
|
|
702
|
+
elapsedMs: number;
|
|
703
|
+
outputBytes: number;
|
|
704
|
+
}) => void): Promise<ToolResultBlock[]>;
|
|
705
|
+
/** 在最终参数上裁决并审计一次调用,所有拒绝和异常均闭合为工具结果。 */
|
|
706
|
+
executeOne(call: ToolUseBlock, onProgress?: (event: {
|
|
707
|
+
id: string;
|
|
708
|
+
name: string;
|
|
709
|
+
elapsedMs: number;
|
|
710
|
+
outputBytes: number;
|
|
711
|
+
}) => void, forcedDeny?: boolean): Promise<ToolResultBlock>;
|
|
712
|
+
private executeResolved;
|
|
422
713
|
/**
|
|
423
714
|
* 给工具执行加超时护栏:Promise.race 在超时后reject,循环拿到 isError 结果继续运转,
|
|
424
715
|
* 不会因某个异步工具(如未来接入的网络/exec 工具)挂起而永久卡死。
|
|
@@ -524,12 +815,16 @@ interface PromptAssemblerOptions {
|
|
|
524
815
|
rootDir: string;
|
|
525
816
|
agentName?: string;
|
|
526
817
|
customInstructions?: string;
|
|
818
|
+
instructionSources?: readonly InstructionSource[];
|
|
819
|
+
visibleTools?: readonly Tool[];
|
|
527
820
|
}
|
|
528
821
|
declare class PromptAssembler {
|
|
529
822
|
private readonly tools?;
|
|
530
823
|
private readonly rootDir;
|
|
531
824
|
private readonly agentName;
|
|
532
825
|
private readonly customInstructions?;
|
|
826
|
+
private readonly instructionSources;
|
|
827
|
+
private readonly visibleTools?;
|
|
533
828
|
constructor(options: PromptAssemblerOptions);
|
|
534
829
|
assemble(): string;
|
|
535
830
|
private getL1Behavior;
|
|
@@ -546,6 +841,11 @@ interface AgentLoopOptions {
|
|
|
546
841
|
maxSteps?: number;
|
|
547
842
|
maxConsecutiveErrors?: number;
|
|
548
843
|
signal?: AbortSignal;
|
|
844
|
+
eventLogger?: EventLogger;
|
|
845
|
+
sessionId?: string;
|
|
846
|
+
runId?: string;
|
|
847
|
+
getMode?: () => SessionMode;
|
|
848
|
+
permissionRules?: readonly PermissionRule[];
|
|
549
849
|
}
|
|
550
850
|
declare class AgentLoop {
|
|
551
851
|
private readonly provider;
|
|
@@ -556,6 +856,11 @@ declare class AgentLoop {
|
|
|
556
856
|
private readonly maxSteps;
|
|
557
857
|
private readonly maxConsecutiveErrors;
|
|
558
858
|
private readonly signal?;
|
|
859
|
+
private readonly eventLogger?;
|
|
860
|
+
private readonly sessionId?;
|
|
861
|
+
private readonly runId?;
|
|
862
|
+
private readonly getMode;
|
|
863
|
+
private readonly permissionRules;
|
|
559
864
|
constructor(options: AgentLoopOptions);
|
|
560
865
|
run(history: CanonicalMessage[]): AsyncIterable<SessionEvent>;
|
|
561
866
|
}
|
|
@@ -568,6 +873,17 @@ interface SessionConfig {
|
|
|
568
873
|
systemPrompt?: string;
|
|
569
874
|
maxSteps?: number;
|
|
570
875
|
logger?: (msg: string) => void;
|
|
876
|
+
eventLogger?: EventLogger;
|
|
877
|
+
loggingDirectory?: string;
|
|
878
|
+
mode?: SessionMode;
|
|
879
|
+
permissionRules?: readonly PermissionRule[];
|
|
880
|
+
approvalChannel?: ApprovalChannel;
|
|
881
|
+
projectRoot?: string;
|
|
882
|
+
cwd?: string;
|
|
883
|
+
userInstructionsPath?: string;
|
|
884
|
+
auditRecoveryDirectory?: string;
|
|
885
|
+
/** 接收普通运行日志失败的脱敏诊断;诊断失败也不得中断问答或替代审计。 */
|
|
886
|
+
onDiagnostic?: (message: string) => void;
|
|
571
887
|
}
|
|
572
888
|
interface SessionStats {
|
|
573
889
|
totalTurns: number;
|
|
@@ -587,6 +903,17 @@ declare class AgentSession {
|
|
|
587
903
|
private readonly customSystemPrompt?;
|
|
588
904
|
private readonly maxSteps;
|
|
589
905
|
private readonly logger?;
|
|
906
|
+
private readonly eventLogger;
|
|
907
|
+
private readonly sessionId;
|
|
908
|
+
private mode;
|
|
909
|
+
private readonly permissionRules;
|
|
910
|
+
private readonly approvalChannel?;
|
|
911
|
+
private readonly approvalCache;
|
|
912
|
+
private readonly projectRoot;
|
|
913
|
+
private readonly cwd;
|
|
914
|
+
private readonly userInstructionsPath?;
|
|
915
|
+
private instructionSnapshot?;
|
|
916
|
+
private readonly auditRecoveryDirectory?;
|
|
590
917
|
private history;
|
|
591
918
|
private totalTurns;
|
|
592
919
|
private usageStats;
|
|
@@ -601,6 +928,11 @@ declare class AgentSession {
|
|
|
601
928
|
use(plugin: AgentPlugin): Promise<void>;
|
|
602
929
|
switchModel(profile: ModelProfile, role?: ModelRole, provider?: ModelProvider): void;
|
|
603
930
|
getActiveProfile(role?: ModelRole): ModelProfile;
|
|
931
|
+
/** 只在空闲时切换本次会话模式;宿主负责 FullAccess 的显式选择交互。 */
|
|
932
|
+
switchMode(mode: SessionMode): void;
|
|
933
|
+
getMode(): SessionMode;
|
|
934
|
+
/** 返回最近一次成功装载的来源路径,不暴露指令正文。 */
|
|
935
|
+
getInstructionSources(): string[];
|
|
604
936
|
getHistory(): CanonicalMessage[];
|
|
605
937
|
getStats(): SessionStats;
|
|
606
938
|
getLastMetrics(): TurnMetrics | undefined;
|
|
@@ -633,4 +965,4 @@ declare class AgentSession {
|
|
|
633
965
|
private findClosedToolMessages;
|
|
634
966
|
}
|
|
635
967
|
|
|
636
|
-
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, type CanonicalMessage, type Capability, type ConflictPolicy, type ContentBlock, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type ExecutorOptions, FatalError, type HookContext, type HookHandlers, type HookPoint, HookRegistry, JSONLMessageStore, KapibalaError, type MessageRole, type MessageStore, ModelError, type ModelEvent, type ModelProfile, type ModelProvider, type ModelRequest, type ModelRole, type ModelRouter, OpenAICompatibleProvider, type OpenAIProviderOptions, PathSandbox, type PluginContext, PromptAssembler, type PromptAssemblerOptions, type RedactedThinkingBlock, type ResolvedContextWindow, type RunMetrics, type SandboxConfig, SessionBusyError, type SessionConfig, type SessionEvent, type SessionStats, SimpleModelRouter, type StepLogEntry, type StepLogStage, type TextBlock, type ThinkingBlock, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, type Usage, builtinTools, defineTool, editFileTool, globTool, grepTool, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, readFileTool, resolveContextWindow, toToolDefinition, writeFileTool };
|
|
968
|
+
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, FileLogSink, type FileLogSinkOptions, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type MessageRole, type MessageStore, ModelError, type ModelEvent, type ModelProfile, type ModelProvider, type ModelRequest, type ModelRole, type ModelRouter, OpenAICompatibleProvider, type OpenAIProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginContext, PromptAssembler, type PromptAssemblerOptions, type RedactedThinkingBlock, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionMode, type SessionStats, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type StepLogEntry, type StepLogStage, StructuredLogger, type TextBlock, type ThinkingBlock, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, type Usage, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, createDefaultLogSinks, createLogId, createRunCommandTool, defineTool, detectShell, editFileTool, executionFingerprint, globTool, grepTool, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, loadInstructions, projectSafeFields, readFileTool, recoverIncompleteAudit, resolveContextWindow, stableJsonStringify, toToolDefinition, validatePermissionRules, visibleTools, writeFileTool };
|