@kiturone/kapibala 0.0.4 → 0.0.5
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.cjs +1648 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +500 -159
- package/dist/index.d.ts +500 -159
- package/dist/index.js +1705 -218
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
+
/** 技能知识来源;层级决定覆盖顺序,不授予文件或执行权限。 */
|
|
2
|
+
type SkillScope = 'builtin' | 'global' | 'project';
|
|
3
|
+
/** 结构化技能诊断;路径及文案需由宿主安全展示,不包含正文或凭据。 */
|
|
4
|
+
interface SkillDiagnostic {
|
|
5
|
+
code: string;
|
|
6
|
+
level: 'warn' | 'error';
|
|
7
|
+
path: string;
|
|
8
|
+
message: string;
|
|
9
|
+
winnerPath?: string;
|
|
10
|
+
loserPath?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 已校验的文件内容;available=false 的执行扩展仅供诊断,不得激活。 */
|
|
13
|
+
interface SkillDocument {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
body: string;
|
|
17
|
+
when?: string;
|
|
18
|
+
license?: string;
|
|
19
|
+
compatibility?: string;
|
|
20
|
+
argumentHint?: string;
|
|
21
|
+
metadata?: Readonly<Record<string, string>>;
|
|
22
|
+
frontmatter: Readonly<Record<string, unknown>>;
|
|
23
|
+
allowedTools?: readonly string[];
|
|
24
|
+
modelInvocable: boolean;
|
|
25
|
+
userInvocable: boolean;
|
|
26
|
+
available: boolean;
|
|
27
|
+
unavailableReason?: string;
|
|
28
|
+
diagnostics: readonly SkillDiagnostic[];
|
|
29
|
+
}
|
|
30
|
+
/** 宿主显式提供的扫描根;项目缺省不可信,boundary 必须是授权物理边界。 */
|
|
31
|
+
interface SkillRoot {
|
|
32
|
+
path: string;
|
|
33
|
+
scope: SkillScope;
|
|
34
|
+
kind?: 'native' | 'agents';
|
|
35
|
+
trusted?: boolean;
|
|
36
|
+
boundary?: string;
|
|
37
|
+
}
|
|
38
|
+
/** 可查询元数据;文件指纹来自发现快照,加载前必须重新核验。 */
|
|
39
|
+
interface SkillMetadata extends Omit<SkillDocument, 'body' | 'frontmatter' | 'diagnostics'> {
|
|
40
|
+
scope: SkillScope;
|
|
41
|
+
sourceRoot: string;
|
|
42
|
+
filePath: string;
|
|
43
|
+
baseDir: string;
|
|
44
|
+
contentDigest: string;
|
|
45
|
+
/** 原词法发现身份;加载重核根链接,不以旧物理文件继续授权。 */
|
|
46
|
+
discoveryRoot: string;
|
|
47
|
+
discoveryPath: string;
|
|
48
|
+
priority: number;
|
|
49
|
+
disabled: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** 完整快照实体;正文仅在校验通过后按需进入模型历史。 */
|
|
52
|
+
interface SkillDefinition extends SkillMetadata {
|
|
53
|
+
body: string;
|
|
54
|
+
}
|
|
55
|
+
/** 会话技能选项;无根即不扫描 home,disabled 名称不能由项目配置重新启用。 */
|
|
56
|
+
interface SkillOptions {
|
|
57
|
+
roots: readonly SkillRoot[];
|
|
58
|
+
enabled?: boolean;
|
|
59
|
+
disabled?: readonly string[];
|
|
60
|
+
}
|
|
61
|
+
/** 技能正文持久来源;只追踪事实,历史来源不恢复授权。 */
|
|
62
|
+
interface SkillContentSource {
|
|
63
|
+
version: 1;
|
|
64
|
+
name: string;
|
|
65
|
+
scope: SkillScope;
|
|
66
|
+
filePath: string;
|
|
67
|
+
baseDir: string;
|
|
68
|
+
contentDigest: string;
|
|
69
|
+
renderedDigest: string;
|
|
70
|
+
caller: 'user' | 'model';
|
|
71
|
+
runId: string;
|
|
72
|
+
invocationId: string;
|
|
73
|
+
}
|
|
74
|
+
/** 本轮活动记录;pending 只收紧,committed 后才可受控读取资源。 */
|
|
75
|
+
interface SkillActivation {
|
|
76
|
+
definition: SkillDefinition;
|
|
77
|
+
source: SkillContentSource;
|
|
78
|
+
state: 'pending' | 'committed';
|
|
79
|
+
allowedTools?: ReadonlySet<string>;
|
|
80
|
+
}
|
|
81
|
+
/** 统一默认限额;宿主不得另算一套目录、文件或响应预算。 */
|
|
82
|
+
declare const SKILL_LIMITS: Readonly<{
|
|
83
|
+
fileBytes: number;
|
|
84
|
+
frontmatterBytes: number;
|
|
85
|
+
depth: 6;
|
|
86
|
+
directories: 2000;
|
|
87
|
+
entries: 20000;
|
|
88
|
+
descriptionChars: 250;
|
|
89
|
+
catalogTokens: 2000;
|
|
90
|
+
queryTokens: 1000;
|
|
91
|
+
resourceBytes: number;
|
|
92
|
+
resourceFiles: 20;
|
|
93
|
+
}>;
|
|
94
|
+
|
|
1
95
|
/** 内置适配器的实际请求目标;用于拒绝模型、协议或端点错配的绑定。 */
|
|
2
96
|
interface ModelProviderBinding {
|
|
3
97
|
protocol: ModelProtocol;
|
|
@@ -245,6 +339,8 @@ type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock |
|
|
|
245
339
|
interface TextBlock {
|
|
246
340
|
type: 'text';
|
|
247
341
|
text: string;
|
|
342
|
+
/** 宿主注入技能的可选来源;只追踪正文,缺失或恢复不授予权限。 */
|
|
343
|
+
skillSource?: SkillContentSource;
|
|
248
344
|
/** 源 wire Item 元数据;正文被改写后由调用方清除,不作为业务身份。 */
|
|
249
345
|
protocolMeta?: ProtocolItemMetadata;
|
|
250
346
|
}
|
|
@@ -262,6 +358,8 @@ interface ToolUseBlock {
|
|
|
262
358
|
}
|
|
263
359
|
interface ToolResultBlock {
|
|
264
360
|
type: 'tool_result';
|
|
361
|
+
/** 完整技能正文的宿主来源;不发送到Provider wire,不从历史恢复授权。 */
|
|
362
|
+
skillSource?: SkillContentSource;
|
|
265
363
|
toolUseId: string;
|
|
266
364
|
content: string;
|
|
267
365
|
isError?: boolean;
|
|
@@ -383,6 +481,11 @@ interface StepLogEntry {
|
|
|
383
481
|
* 不应直接把本类型当作长期兼容的网络协议。
|
|
384
482
|
*/
|
|
385
483
|
type SessionEvent = {
|
|
484
|
+
type: 'skill_loaded';
|
|
485
|
+
source: SkillContentSource;
|
|
486
|
+
messageId: string;
|
|
487
|
+
persistence: 'memory' | 'disk';
|
|
488
|
+
} | {
|
|
386
489
|
type: 'session_resumed';
|
|
387
490
|
conversationId: string;
|
|
388
491
|
runtimeSessionId: string;
|
|
@@ -1022,7 +1125,7 @@ declare class ContextManager {
|
|
|
1022
1125
|
private publishSnapshot;
|
|
1023
1126
|
/** 最终请求与只读估算共用来源和状态计数。 */
|
|
1024
1127
|
private buildSnapshot;
|
|
1025
|
-
/**
|
|
1128
|
+
/** 摘要与技能重载事实由已验证原历史生成,不升级为系统指令或恢复旧授权;旧检查点同样适用。 */
|
|
1026
1129
|
private summaryMessage;
|
|
1027
1130
|
/**
|
|
1028
1131
|
* 旧轮次仅在工具事务闭合时可摘要;成功可由旧记录推断,失败或中断必须有运行终态来源。
|
|
@@ -1273,37 +1376,89 @@ interface InstructionLoadOptions {
|
|
|
1273
1376
|
*/
|
|
1274
1377
|
declare function loadInstructions(options: InstructionLoadOptions): InstructionSnapshot;
|
|
1275
1378
|
|
|
1276
|
-
/**
|
|
1277
|
-
|
|
1278
|
-
/**
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1379
|
+
/** 安全名称语法;不接受厂商命名空间、路径或连续连字符。 */
|
|
1380
|
+
declare function isSkillName(value: string): boolean;
|
|
1381
|
+
/** 解析常用 Frontmatter 子集;格式错误抛出,未知执行扩展返回不可执行诊断,正文不截断。 */
|
|
1382
|
+
declare function parseSkillDocument(content: string, filePath: string): SkillDocument;
|
|
1383
|
+
|
|
1384
|
+
/** 技能错误仅返回受控文案;retryPolicy 不触发工具内部重试。 */
|
|
1385
|
+
declare function skillFailure(code: string, message: string): KapibalaError;
|
|
1386
|
+
/** 以路径段判断物理边界,允许边界自身但不接受越界或其他盘符。 */
|
|
1387
|
+
declare function isWithinSkillRoot(root: string, target: string): boolean;
|
|
1388
|
+
/** Windows 物理身份忽略盘符/路径大小写,其他平台维持文件系统原义。 */
|
|
1389
|
+
declare function skillPathKey(value: string): string;
|
|
1390
|
+
/** 按 code point 排序,不使用受语言区域影响的比较器。 */
|
|
1391
|
+
declare function compareSkillPaths(left: string, right: string): number;
|
|
1392
|
+
/** 有界 UTF-8 读取;先检查文件类型/大小,增长中的文件也不能突破上限。 */
|
|
1393
|
+
declare function readBoundedSkillText(filePath: string, maximum: number, signal?: AbortSignal): Promise<string>;
|
|
1394
|
+
/** 原文件字节摘要;有效 UTF-8 的重新编码保留 BOM 与换行,不使用规范化正文替代。 */
|
|
1395
|
+
declare function skillDigest(content: string): string;
|
|
1396
|
+
/** 单根发现结果;诊断可包含无效候选,扫描结束后只保留元数据,不常驻正文。 */
|
|
1397
|
+
interface SkillScanResult {
|
|
1398
|
+
skills: SkillMetadata[];
|
|
1399
|
+
diagnostics: SkillDiagnostic[];
|
|
1400
|
+
}
|
|
1401
|
+
/** 扫描单根的技能边界;有界异步遍历,项目未声明信任时实体只供宿主诊断。 */
|
|
1402
|
+
declare function scanSkillRoot(root: SkillRoot, signal?: AbortSignal): Promise<SkillScanResult>;
|
|
1403
|
+
|
|
1404
|
+
/** 使用现有 Unicode 估算器计完整文本,非 ASCII 不按四字符折算。 */
|
|
1405
|
+
declare function estimateSkillTokens(text: string): number;
|
|
1406
|
+
/** 技能元数据的 XML 转义;不把未转义的描述或路径当作目录结构。 */
|
|
1407
|
+
declare function escapeSkillXml(text: string): string;
|
|
1408
|
+
/** 完整目录投影及遗漏统计;text 为空表示最小目录也无法容纳。 */
|
|
1409
|
+
interface SkillCatalog {
|
|
1410
|
+
text: string;
|
|
1411
|
+
included: number;
|
|
1412
|
+
omitted: number;
|
|
1413
|
+
estimatedTokens: number;
|
|
1414
|
+
}
|
|
1415
|
+
/** 生成确定性 L2.5;预算含标题、XML、转义及遗漏提示,只删完整条目。 */
|
|
1416
|
+
declare function formatSkillCatalog(skills: readonly SkillMetadata[], contextWindow?: number, remainingTokens?: number): SkillCatalog;
|
|
1417
|
+
/** 模型目录分页输入;游标只定位快照,不提供信任或正文访问授权。 */
|
|
1418
|
+
interface SkillQuery {
|
|
1419
|
+
query?: string;
|
|
1420
|
+
cursor?: string;
|
|
1421
|
+
limit?: number;
|
|
1422
|
+
}
|
|
1423
|
+
/** 有界模型元数据页;不包含正文,游标按实际返回条目推进。 */
|
|
1424
|
+
interface SkillQueryPage {
|
|
1425
|
+
skills: {
|
|
1426
|
+
name: string;
|
|
1427
|
+
description: string;
|
|
1428
|
+
scope: string;
|
|
1429
|
+
argumentHint?: string;
|
|
1430
|
+
}[];
|
|
1431
|
+
total: number;
|
|
1432
|
+
nextCursor?: string;
|
|
1286
1433
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1434
|
+
|
|
1435
|
+
/** 确定性技能注册表;刷新原子替换快照,运行中加载必须与发现指纹一致。 */
|
|
1436
|
+
declare class SkillRegistry {
|
|
1437
|
+
private readonly options;
|
|
1438
|
+
private definitions;
|
|
1439
|
+
private warnings;
|
|
1440
|
+
private revisionValue;
|
|
1441
|
+
/** 固定宿主配置副本,外部对象变更不能静默改变本轮发现或信任。 */
|
|
1442
|
+
constructor(options: SkillOptions);
|
|
1443
|
+
/** 获取独立诊断副本,调用方不能修改生效候选或权限。 */
|
|
1444
|
+
get diagnostics(): SkillDiagnostic[];
|
|
1445
|
+
/** 快照游标身份随正文、来源、可用性变化而失效。 */
|
|
1446
|
+
get revision(): string;
|
|
1447
|
+
/** 是否由宿主启用;关闭只影响本次能力,不删除历史或文件。 */
|
|
1448
|
+
get enabled(): boolean;
|
|
1449
|
+
/** 每轮开始重新发现;取消不发布半个快照,非法单文件只产生诊断。 */
|
|
1450
|
+
refresh(signal?: AbortSignal): Promise<void>;
|
|
1451
|
+
/** 按名称查询胜出元数据副本;未知名称返回 undefined,正文仅由 load 校验后懒读取。 */
|
|
1452
|
+
get(name: string): SkillMetadata | undefined;
|
|
1453
|
+
/** 宿主可检查不可用条目;模型/用户视图分别施加调用控制,均不读取正文。 */
|
|
1454
|
+
list(caller?: 'host' | 'model' | 'user', query?: string): SkillMetadata[];
|
|
1455
|
+
/** 按当前快照校验调用控制与物理身份,不接受模型提供的信任或 caller 升级。 */
|
|
1456
|
+
load(name: string, caller: 'model' | 'user', signal?: AbortSignal): Promise<SkillDefinition>;
|
|
1457
|
+
/** 查询可信模型集合;过期游标可修正,预算不足不返回不前进的分页。 */
|
|
1458
|
+
queryModel(input?: SkillQuery, remainingTokens?: number): SkillQueryPage;
|
|
1459
|
+
/** 复核配置根、词法发现路径和原文件字节,返回本次有界读取文本;漂移要求新运行,不能热替换。 */
|
|
1460
|
+
verify(skill: SkillMetadata, signal?: AbortSignal): Promise<string>;
|
|
1295
1461
|
}
|
|
1296
|
-
/**
|
|
1297
|
-
* 按 uname 输出分类 bash 家族:Git Bash/MSYS2/Cygwin 归 native bash,
|
|
1298
|
-
* Windows 上报告 Linux 的是 WSL launcher(独立 kind,路径语义不同)。
|
|
1299
|
-
*/
|
|
1300
|
-
declare function classifyBashOutput(unameOutput: string, platform: NodeJS.Platform): ShellKind | undefined;
|
|
1301
|
-
/**
|
|
1302
|
-
* 发现并固定实际解释器:只用 PATH 与用户显式给出的路径,不写死任何安装目录。
|
|
1303
|
-
* auto 在 Windows 上按 native Bash → WSL → pwsh → powershell 依次兜底,
|
|
1304
|
-
* bash 家族用运行时 uname 探针区分 Git Bash 与 WSL launcher。
|
|
1305
|
-
*/
|
|
1306
|
-
declare function detectShell(options: ShellDetectOptions): ShellEnvironment;
|
|
1307
1462
|
|
|
1308
1463
|
/** 本次会话的自动执行边界;FullAccess 只能由宿主为本次会话显式选择。 */
|
|
1309
1464
|
type SessionMode = 'Approval' | 'Plan' | 'Auto' | 'FullAccess';
|
|
@@ -1407,75 +1562,32 @@ declare function defineTool<TInput = Record<string, unknown>, TOutput = unknown>
|
|
|
1407
1562
|
/** 投影为模型可见的工具描述;刻意丢弃 metadata 与 approvalScope,执行侧信息不进入协议。 */
|
|
1408
1563
|
declare function toToolDefinition(tool: Tool): ToolDefinition;
|
|
1409
1564
|
|
|
1410
|
-
/**
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
cwd?: string;
|
|
1415
|
-
timeout_ms?: number;
|
|
1416
|
-
}
|
|
1417
|
-
/** 命令执行结果;output 只是内联前缀,完整输出超过内联上限的部分落盘为受管结果文件。 */
|
|
1418
|
-
interface CommandResult {
|
|
1419
|
-
/** 进程正常退出时的退出码;被信号终止时为 null。 */
|
|
1420
|
-
exitCode: number | null;
|
|
1421
|
-
/** stdout 与 stderr 交错合并的文本,最多前 64 KiB(按 UTF-8 字符边界截断)。 */
|
|
1422
|
-
output: string;
|
|
1423
|
-
/** output 并非全部输出的标志;超出内联上限的完整内容写入 outputFile。 */
|
|
1424
|
-
outputTruncated: boolean;
|
|
1425
|
-
/** 受管结果文件路径(工作区内 .kapibala/tool-results/),仅输出超过内联上限时存在。 */
|
|
1426
|
-
outputFile?: string;
|
|
1427
|
-
/** 结果文件触及 16 MiB 上限后被截断的标志。 */
|
|
1428
|
-
outputFileTruncated: boolean;
|
|
1429
|
-
/** 两个流产生的原始字节总数(不受截断影响),供进度与审计使用。 */
|
|
1430
|
-
outputBytes: number;
|
|
1431
|
-
shell: ShellEnvironment['kind'];
|
|
1432
|
-
}
|
|
1433
|
-
/** 仅清理受管 UUID 文件,避免删除用户在同目录保存的结果。 */
|
|
1434
|
-
declare function cleanupCommandResults(rootDir: string, now?: number): void;
|
|
1435
|
-
/** 使用固定解释器执行命令;超时和中止必须先处理进程树再返回。 */
|
|
1436
|
-
declare function createRunCommandTool(environment: ShellEnvironment): Tool<RunCommandInput, CommandResult>;
|
|
1565
|
+
/** 归一化技能白名单;参数模式/未知名称不得退化成宽泛命令授权。 */
|
|
1566
|
+
declare function normalizeSkillTools(skill: SkillDefinition, tools: readonly Tool[]): ReadonlySet<string> | undefined;
|
|
1567
|
+
/** 多活动技能白名单取交集;未声明不参与,空集合不等于无限制。 */
|
|
1568
|
+
declare function intersectSkillTools(activations: Iterable<Pick<SkillActivation, 'allowedTools'>>): ReadonlySet<string> | undefined;
|
|
1437
1569
|
|
|
1438
|
-
/**
|
|
1439
|
-
interface
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
allowSymlinks?: boolean;
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* 把文件访问限制在 rootDir 内:先做词法归一化检查,再展开符号链接做物理检查,两层都通过才放行。
|
|
1449
|
-
* 实例会缓存 rootDir 的物理路径,应按 rootDir 复用实例,而不是每次调用新建。
|
|
1450
|
-
*/
|
|
1451
|
-
declare class PathSandbox {
|
|
1452
|
-
readonly rootDir: string;
|
|
1453
|
-
readonly allowSymlinks: boolean;
|
|
1454
|
-
private cachedRealRootDir?;
|
|
1455
|
-
constructor(config: SandboxConfig);
|
|
1456
|
-
/**
|
|
1457
|
-
* rootDir 的物理路径。rootDir 自身可能是一个符号链接(如 macOS 的 /var → /private/var),
|
|
1458
|
-
* 必须先归一化,否则物理路径与 rootDir 比较时会产生误判。
|
|
1459
|
-
*/
|
|
1460
|
-
private get realRootDir();
|
|
1461
|
-
/**
|
|
1462
|
-
* 检查并解析安全路径
|
|
1463
|
-
* 1. 解析相对路径为相对于 rootDir 的绝对路径
|
|
1464
|
-
* 2. 词法检查:`..` 归一化后必须仍在 rootDir 内
|
|
1465
|
-
* 3. 物理检查:解析符号链接后的真实路径必须仍在 rootDir 内
|
|
1466
|
-
*/
|
|
1467
|
-
resolveSafePath(targetPath: string): string;
|
|
1468
|
-
/**
|
|
1469
|
-
* 把词法路径映射为物理路径。
|
|
1470
|
-
*
|
|
1471
|
-
* 关键点在于**向上回溯到最近一个真实存在的祖先**再取 realpath,然后把尚未存在的尾段拼回去:
|
|
1472
|
-
* - 目标已存在 → 直接 realpath,符号链接立刻被展开;
|
|
1473
|
-
* - 目标不存在(典型场景:write_file 新建文件) → 若只看目标本身,所有校验都会被跳过,
|
|
1474
|
-
* 于是 `write_file('linkDir/new.txt')` 可以借道指向外部的 linkDir 越界写入。
|
|
1475
|
-
* 回溯到 linkDir 取 realpath 即可识破这种穿透。
|
|
1476
|
-
*/
|
|
1477
|
-
private toPhysicalPath;
|
|
1570
|
+
/** 受控文本范围;offset 用于 UTF-8 大行续读,不能与行范围混用。 */
|
|
1571
|
+
interface SkillResourceInput {
|
|
1572
|
+
name: string;
|
|
1573
|
+
path: string;
|
|
1574
|
+
startLine?: number;
|
|
1575
|
+
endLine?: number;
|
|
1576
|
+
offset?: number;
|
|
1478
1577
|
}
|
|
1578
|
+
/** 只读资源页;nextOffset 是完整 UTF-8 字符边界,不代表文件执行授权。 */
|
|
1579
|
+
interface SkillResourcePage {
|
|
1580
|
+
text: string;
|
|
1581
|
+
truncated: boolean;
|
|
1582
|
+
nextOffset?: number;
|
|
1583
|
+
}
|
|
1584
|
+
/** 读取技能根内文本;复核物理边界,有界返回并关闭文件,不扩大普通文件沙箱。 */
|
|
1585
|
+
declare function readSkillResource(skill: SkillDefinition, input: SkillResourceInput, signal?: AbortSignal): Promise<SkillResourcePage>;
|
|
1586
|
+
/** 限量列出包内资源名而不读取正文;外部链接、默认忽略目录及深层资源不展开。 */
|
|
1587
|
+
declare function listSkillResources(skill: SkillDefinition, signal?: AbortSignal): Promise<{
|
|
1588
|
+
files: string[];
|
|
1589
|
+
truncated: boolean;
|
|
1590
|
+
}>;
|
|
1479
1591
|
|
|
1480
1592
|
/**
|
|
1481
1593
|
* 人工审批的五选一结果。allow_once / deny_once 只作用于本次执行;
|
|
@@ -1526,54 +1638,14 @@ declare class ToolRegistry {
|
|
|
1526
1638
|
registerSource(source: string, tools: Tool[]): void;
|
|
1527
1639
|
unregisterSource(source: string): void;
|
|
1528
1640
|
get(name: string): Tool | undefined;
|
|
1641
|
+
/** 注销指定名称及来源记录;调用方须核对实例身份,不能移除同名替代工具。 */
|
|
1642
|
+
unregister(name: string): void;
|
|
1529
1643
|
/** 未命中时抛 ToolNotFound,并携带当前全部可用名称辅助模型自纠。 */
|
|
1530
1644
|
resolve(name: string): Tool;
|
|
1531
1645
|
list(): Tool[];
|
|
1532
1646
|
definitions(): ToolDefinition[];
|
|
1533
1647
|
}
|
|
1534
1648
|
|
|
1535
|
-
declare const readFileTool: Tool<{
|
|
1536
|
-
path: string;
|
|
1537
|
-
startLine?: number;
|
|
1538
|
-
endLine?: number;
|
|
1539
|
-
}, string>;
|
|
1540
|
-
declare const writeFileTool: Tool<{
|
|
1541
|
-
path: string;
|
|
1542
|
-
content: string;
|
|
1543
|
-
}, string>;
|
|
1544
|
-
declare const editFileTool: Tool<{
|
|
1545
|
-
path: string;
|
|
1546
|
-
targetContent: string;
|
|
1547
|
-
replacementContent: string;
|
|
1548
|
-
}, string>;
|
|
1549
|
-
declare const globTool: Tool<{
|
|
1550
|
-
pattern: string;
|
|
1551
|
-
subDirectory?: string;
|
|
1552
|
-
}, string>;
|
|
1553
|
-
declare const grepTool: Tool<{
|
|
1554
|
-
pattern: string;
|
|
1555
|
-
path?: string;
|
|
1556
|
-
}, string>;
|
|
1557
|
-
/** 五个内置文件工具的聚合;全部经 PathSandbox 校验,路径越界或符号链接穿透一律拒绝。 */
|
|
1558
|
-
declare const builtinTools: (Tool<{
|
|
1559
|
-
path: string;
|
|
1560
|
-
startLine?: number;
|
|
1561
|
-
endLine?: number;
|
|
1562
|
-
}, string> | Tool<{
|
|
1563
|
-
path: string;
|
|
1564
|
-
content: string;
|
|
1565
|
-
}, string> | Tool<{
|
|
1566
|
-
path: string;
|
|
1567
|
-
targetContent: string;
|
|
1568
|
-
replacementContent: string;
|
|
1569
|
-
}, string> | Tool<{
|
|
1570
|
-
pattern: string;
|
|
1571
|
-
subDirectory?: string;
|
|
1572
|
-
}, string> | Tool<{
|
|
1573
|
-
pattern: string;
|
|
1574
|
-
path?: string;
|
|
1575
|
-
}, string>)[];
|
|
1576
|
-
|
|
1577
1649
|
/**
|
|
1578
1650
|
* 运行时钩子契约:宿主与插件在固定切点观察或调整流程。
|
|
1579
1651
|
* 通知型切点由 HookRegistry.emit 串行触发;需要返回值的 model:before / tool:before
|
|
@@ -1639,25 +1711,19 @@ declare class HookRegistry {
|
|
|
1639
1711
|
emit<K extends 'session:start' | 'session:end' | 'model:after' | 'tool:after' | 'error'>(point: K, ctx: HookContext, ...args: any[]): Promise<void>;
|
|
1640
1712
|
}
|
|
1641
1713
|
|
|
1642
|
-
/** setup 收到的能力入口;tools / hooks 是会话共享的注册表,注册的条目影响后续所有执行。 */
|
|
1643
|
-
interface PluginContext {
|
|
1644
|
-
readonly tools: ToolRegistry;
|
|
1645
|
-
readonly hooks: HookRegistry;
|
|
1646
|
-
/** 本次会话的绝对工具根目录;工具的路径解析与审批都以此为基准。 */
|
|
1647
|
-
readonly rootDir: string;
|
|
1648
|
-
readonly logger?: (msg: string) => void;
|
|
1649
|
-
}
|
|
1650
|
-
/** 插件生命周期:setup 在会话空闲时挂载执行一次,teardown 在会话销毁时逐个调用以回收资源。 */
|
|
1651
|
-
interface AgentPlugin {
|
|
1652
|
-
/** 用于挂载失败与 teardown 的诊断信息。 */
|
|
1653
|
-
readonly name: string;
|
|
1654
|
-
readonly version?: string;
|
|
1655
|
-
setup(ctx: PluginContext): void | Promise<void>;
|
|
1656
|
-
teardown?(): void | Promise<void>;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
1714
|
/** ToolExecutor 的构造项;审计写入需要 eventLogger 与 sessionId 同时提供,否则不产生审计。 */
|
|
1715
|
+
/** 宿主运行级硬限制;优先于模式、审批及缓存,文案和字段不得携带凭据。 */
|
|
1716
|
+
interface ToolHardDenial {
|
|
1717
|
+
code: string;
|
|
1718
|
+
message: string;
|
|
1719
|
+
retryPolicy: ToolResultBlock['retryPolicy'];
|
|
1720
|
+
fields?: Record<string, unknown>;
|
|
1721
|
+
}
|
|
1660
1722
|
interface ExecutorOptions {
|
|
1723
|
+
/** 在最终参数上补充硬拒绝,不能把拒绝转为授权。 */
|
|
1724
|
+
hardDenial?: (tool: Tool, input: Record<string, unknown>) => ToolHardDenial | undefined;
|
|
1725
|
+
/** 结果钩子和执行审计完成后调用;用于在同批次下一调用前安装宿主收紧状态。 */
|
|
1726
|
+
onToolResult?: (tool: Tool, input: Record<string, unknown>, result: ToolResultBlock) => void | Promise<void>;
|
|
1661
1727
|
tools: ToolRegistry;
|
|
1662
1728
|
hooks: HookRegistry;
|
|
1663
1729
|
/** 工具执行的绝对根目录;路径解析与审批均以此为基准。 */
|
|
@@ -1684,6 +1750,8 @@ interface ExecutorOptions {
|
|
|
1684
1750
|
* 同一 run 内参数完全相同的 never 失败会被拒绝重复执行。
|
|
1685
1751
|
*/
|
|
1686
1752
|
declare class ToolExecutor {
|
|
1753
|
+
private readonly hardDenial?;
|
|
1754
|
+
private readonly onToolResult?;
|
|
1687
1755
|
private readonly tools;
|
|
1688
1756
|
private readonly hooks;
|
|
1689
1757
|
private readonly rootDir;
|
|
@@ -1703,13 +1771,16 @@ declare class ToolExecutor {
|
|
|
1703
1771
|
constructor(options: ExecutorOptions);
|
|
1704
1772
|
/** 中止本轮正在等待或执行的工具;调用方仍须等待 runAll 完成资源回收及结果审计。 */
|
|
1705
1773
|
cancel(): void;
|
|
1706
|
-
/**
|
|
1774
|
+
/**
|
|
1775
|
+
* 串行执行全部调用并返回与入参顺序一致的结果;某个结果要求用户介入后,其余调用直接拒绝。
|
|
1776
|
+
* onResult 在每个最终结果(含拒绝/失败)产生后提供独立快照,供在途预算估算,不代表历史已提交;回调不得抛错。
|
|
1777
|
+
*/
|
|
1707
1778
|
runAll(calls: ToolUseBlock[], onProgress?: (event: {
|
|
1708
1779
|
id: string;
|
|
1709
1780
|
name: string;
|
|
1710
1781
|
elapsedMs: number;
|
|
1711
1782
|
outputBytes: number;
|
|
1712
|
-
}) => void): Promise<ToolResultBlock[]>;
|
|
1783
|
+
}) => void, onResult?: (result: ToolResultBlock) => void): Promise<ToolResultBlock[]>;
|
|
1713
1784
|
/**
|
|
1714
1785
|
* 在最终参数上裁决并审计一次调用,所有拒绝和异常均闭合为工具结果。
|
|
1715
1786
|
* 为调用记录本次绝对工具根目录,供跨目录恢复后的文件事实解析;不使用历史目录授权。
|
|
@@ -1731,6 +1802,237 @@ declare class ToolExecutor {
|
|
|
1731
1802
|
private withTimeout;
|
|
1732
1803
|
}
|
|
1733
1804
|
|
|
1805
|
+
/** 加载预检结果;只有最终成功工具结果或真实用户消息提交后才形成活动资格。 */
|
|
1806
|
+
interface PreparedSkill {
|
|
1807
|
+
/** 本轮完整正文仍可见时只引用,引用结果不附完整正文来源。 */
|
|
1808
|
+
alreadyPresent?: boolean;
|
|
1809
|
+
definition: SkillDefinition;
|
|
1810
|
+
source: SkillContentSource;
|
|
1811
|
+
text: string;
|
|
1812
|
+
allowedTools?: ReadonlySet<string>;
|
|
1813
|
+
}
|
|
1814
|
+
/** 会话内技能运行状态;控制工具按实例身份识别,pending 只收紧而不授予资源。 */
|
|
1815
|
+
declare class SkillRuntime {
|
|
1816
|
+
readonly registry: SkillRegistry;
|
|
1817
|
+
private readonly tools;
|
|
1818
|
+
private readonly onResourceRead?;
|
|
1819
|
+
readonly loaderTool: Tool;
|
|
1820
|
+
readonly queryTool: Tool;
|
|
1821
|
+
readonly resourceTool: Tool;
|
|
1822
|
+
private readonly controls;
|
|
1823
|
+
private readonly prepared;
|
|
1824
|
+
private readonly active;
|
|
1825
|
+
private runId;
|
|
1826
|
+
private history;
|
|
1827
|
+
private projection;
|
|
1828
|
+
private reservedTokens;
|
|
1829
|
+
private remaining;
|
|
1830
|
+
/** 注册表和工具集合属于一个Session;不跨会话共享授权或隐式目录。 */
|
|
1831
|
+
constructor(registry: SkillRegistry, tools: ToolRegistry, onResourceRead?: ((source: SkillContentSource, input: SkillResourceInput, page: SkillResourcePage) => Promise<void>) | undefined);
|
|
1832
|
+
/**
|
|
1833
|
+
* 开始新运行;历史正文只作事实,必须由本轮加载重新激活。
|
|
1834
|
+
* remaining 必须扣除在途 assistant 和普通工具结果;尚未提交的成功技能正文由本类独立预留,不重复扣除。
|
|
1835
|
+
*/
|
|
1836
|
+
begin(runId: string, history: () => readonly CanonicalMessage[], remaining: () => number, projection?: () => readonly CanonicalMessage[]): void;
|
|
1837
|
+
/** 按实际集合安装实例工具;同名插件不覆盖为受信任工具,也不能制造目录引导。 */
|
|
1838
|
+
syncTools(): void;
|
|
1839
|
+
/** 清空本轮状态;调用方必须先等待工具和历史事务清理,不能提前释放会话锁。 */
|
|
1840
|
+
clear(): void;
|
|
1841
|
+
/** 查询本轮活动状态副本,避免宿主修改限制。 */
|
|
1842
|
+
get activations(): SkillActivation[];
|
|
1843
|
+
/** 预检正文、限制和输入空间;调用方由宿主固定,不读取模型伪造caller。 */
|
|
1844
|
+
prepare(name: string, caller: 'model' | 'user', signal?: AbortSignal): Promise<PreparedSkill>;
|
|
1845
|
+
/** 真实用户入口安装pending;正文需进入用户消息,提交前不提供资源。 */
|
|
1846
|
+
acceptUser(prepared: PreparedSkill): void;
|
|
1847
|
+
/** 最终工具结果通过执行器钩子/审计后安装收紧;同名或仿造结果不激活。 */
|
|
1848
|
+
acceptResult(tool: Tool, result: ToolResultBlock): void;
|
|
1849
|
+
/** 业务调用的动态硬拒绝;控制工具仅按实例豁免,仍须宿主权限裁决。 */
|
|
1850
|
+
denial(tool: Tool): ToolHardDenial | undefined;
|
|
1851
|
+
/** 完整消息提交后记录审计再发布事件;失败不回滚历史,但不提交资源资格。 */
|
|
1852
|
+
commit(audit: (source: SkillContentSource, messageId: string) => Promise<void>, persistence: 'memory' | 'disk'): Promise<SessionEvent[]>;
|
|
1853
|
+
/** 检查最终模型投影的完整活动指导;钩子或压缩不能移走后继续执行。 */
|
|
1854
|
+
assertProjection(messages: readonly CanonicalMessage[]): void;
|
|
1855
|
+
/** 只读本轮已提交技能资源;文件/来源漂移要求重新开始,不重放脚本。 */
|
|
1856
|
+
readResource(input: SkillResourceInput, signal?: AbortSignal): Promise<SkillResourcePage>;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
/** 技能正文在实际投影中的状态;来源只关联事实,present 不代表当前运行获得授权。 */
|
|
1860
|
+
interface SkillContextState {
|
|
1861
|
+
source: SkillContentSource;
|
|
1862
|
+
messageId: string;
|
|
1863
|
+
state: 'present' | 'requires_reload';
|
|
1864
|
+
}
|
|
1865
|
+
/** 查找真实投影中的完整正文来源;字段缺失、未知版本或文本摘要不匹配不用于去重。 */
|
|
1866
|
+
declare function findSkillContent(history: readonly CanonicalMessage[], source: SkillContentSource): {
|
|
1867
|
+
messageId: string;
|
|
1868
|
+
source: SkillContentSource;
|
|
1869
|
+
} | undefined;
|
|
1870
|
+
/** 比较原始来源与真实投影,以最后一次相同文件/版本正文为准;不恢复旧授权或执行动作。 */
|
|
1871
|
+
declare function inspectSkillContent(raw: readonly CanonicalMessage[], projected: readonly CanonicalMessage[]): SkillContextState[];
|
|
1872
|
+
/** 将离开投影的旧正文表示为有界重载事实;最多50条,遗漏数明确,不把历史包装成当前指令。 */
|
|
1873
|
+
declare function renderSkillReloads(covered: readonly CanonicalMessage[]): string;
|
|
1874
|
+
|
|
1875
|
+
/** 受支持的解释器家族;wsl 是 Windows 上的 WSL bash launcher,路径与输出语义与 native bash 不同。 */
|
|
1876
|
+
type ShellKind = 'bash' | 'wsl' | 'pwsh' | 'powershell';
|
|
1877
|
+
/** auto / 具名解释器,或用户显式提供的解释器可执行文件全路径。 */
|
|
1878
|
+
type ShellPreference = 'auto' | ShellKind | (string & {});
|
|
1879
|
+
/** 探测成功后固定的解释器身份;executableDigest 参与命令审批指纹,解释器被替换即失配。 */
|
|
1880
|
+
interface ShellEnvironment {
|
|
1881
|
+
kind: ShellKind;
|
|
1882
|
+
executable: string;
|
|
1883
|
+
executableDigest: string;
|
|
1884
|
+
cwd: string;
|
|
1885
|
+
}
|
|
1886
|
+
interface ShellDetectOptions {
|
|
1887
|
+
/** 'auto'、具名解释器,或解释器可执行文件全路径;含路径分隔符或 .exe 后缀按显式路径处理。 */
|
|
1888
|
+
preference?: ShellPreference;
|
|
1889
|
+
/** 探测与后续执行的基准目录;探测前先取 realpath,符号链接会被展开。 */
|
|
1890
|
+
cwd: string;
|
|
1891
|
+
/** 以下两项供测试注入平台与 PATH;缺省取当前进程的值。 */
|
|
1892
|
+
platform?: NodeJS.Platform;
|
|
1893
|
+
pathEnv?: string;
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* 按 uname 输出分类 bash 家族:Git Bash/MSYS2/Cygwin 归 native bash,
|
|
1897
|
+
* Windows 上报告 Linux 的是 WSL launcher(独立 kind,路径语义不同)。
|
|
1898
|
+
*/
|
|
1899
|
+
declare function classifyBashOutput(unameOutput: string, platform: NodeJS.Platform): ShellKind | undefined;
|
|
1900
|
+
/**
|
|
1901
|
+
* 发现并固定实际解释器:只用 PATH 与用户显式给出的路径,不写死任何安装目录。
|
|
1902
|
+
* auto 在 Windows 上按 native Bash → WSL → pwsh → powershell 依次兜底,
|
|
1903
|
+
* bash 家族用运行时 uname 探针区分 Git Bash 与 WSL launcher。
|
|
1904
|
+
*/
|
|
1905
|
+
declare function detectShell(options: ShellDetectOptions): ShellEnvironment;
|
|
1906
|
+
|
|
1907
|
+
/** run_command 的输入;cwd 相对工作区根解析,timeout_ms 合法区间 1..600000,越界在执行前失败。 */
|
|
1908
|
+
interface RunCommandInput {
|
|
1909
|
+
[key: string]: unknown;
|
|
1910
|
+
command: string;
|
|
1911
|
+
cwd?: string;
|
|
1912
|
+
timeout_ms?: number;
|
|
1913
|
+
}
|
|
1914
|
+
/** 命令执行结果;output 只是内联前缀,完整输出超过内联上限的部分落盘为受管结果文件。 */
|
|
1915
|
+
interface CommandResult {
|
|
1916
|
+
/** 进程正常退出时的退出码;被信号终止时为 null。 */
|
|
1917
|
+
exitCode: number | null;
|
|
1918
|
+
/** stdout 与 stderr 交错合并的文本,最多前 64 KiB(按 UTF-8 字符边界截断)。 */
|
|
1919
|
+
output: string;
|
|
1920
|
+
/** output 并非全部输出的标志;超出内联上限的完整内容写入 outputFile。 */
|
|
1921
|
+
outputTruncated: boolean;
|
|
1922
|
+
/** 受管结果文件路径(工作区内 .kapibala/tool-results/),仅输出超过内联上限时存在。 */
|
|
1923
|
+
outputFile?: string;
|
|
1924
|
+
/** 结果文件触及 16 MiB 上限后被截断的标志。 */
|
|
1925
|
+
outputFileTruncated: boolean;
|
|
1926
|
+
/** 两个流产生的原始字节总数(不受截断影响),供进度与审计使用。 */
|
|
1927
|
+
outputBytes: number;
|
|
1928
|
+
shell: ShellEnvironment['kind'];
|
|
1929
|
+
}
|
|
1930
|
+
/** 仅清理受管 UUID 文件,避免删除用户在同目录保存的结果。 */
|
|
1931
|
+
declare function cleanupCommandResults(rootDir: string, now?: number): void;
|
|
1932
|
+
/** 使用固定解释器执行命令;超时和中止必须先处理进程树再返回。 */
|
|
1933
|
+
declare function createRunCommandTool(environment: ShellEnvironment): Tool<RunCommandInput, CommandResult>;
|
|
1934
|
+
|
|
1935
|
+
/** 路径沙箱配置;rootDir 是所有文件访问的词法与物理边界。 */
|
|
1936
|
+
interface SandboxConfig {
|
|
1937
|
+
rootDir: string;
|
|
1938
|
+
/**
|
|
1939
|
+
* v0.0.1 恒为严格模式:任何解析后落在 rootDir 之外的物理路径一律拒绝,
|
|
1940
|
+
* 不存在 fail-open 开关。该字段为 v0.0.2 权限引擎预留,当前不改变校验行为。
|
|
1941
|
+
*/
|
|
1942
|
+
allowSymlinks?: boolean;
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* 把文件访问限制在 rootDir 内:先做词法归一化检查,再展开符号链接做物理检查,两层都通过才放行。
|
|
1946
|
+
* 实例会缓存 rootDir 的物理路径,应按 rootDir 复用实例,而不是每次调用新建。
|
|
1947
|
+
*/
|
|
1948
|
+
declare class PathSandbox {
|
|
1949
|
+
readonly rootDir: string;
|
|
1950
|
+
readonly allowSymlinks: boolean;
|
|
1951
|
+
private cachedRealRootDir?;
|
|
1952
|
+
constructor(config: SandboxConfig);
|
|
1953
|
+
/**
|
|
1954
|
+
* rootDir 的物理路径。rootDir 自身可能是一个符号链接(如 macOS 的 /var → /private/var),
|
|
1955
|
+
* 必须先归一化,否则物理路径与 rootDir 比较时会产生误判。
|
|
1956
|
+
*/
|
|
1957
|
+
private get realRootDir();
|
|
1958
|
+
/**
|
|
1959
|
+
* 检查并解析安全路径
|
|
1960
|
+
* 1. 解析相对路径为相对于 rootDir 的绝对路径
|
|
1961
|
+
* 2. 词法检查:`..` 归一化后必须仍在 rootDir 内
|
|
1962
|
+
* 3. 物理检查:解析符号链接后的真实路径必须仍在 rootDir 内
|
|
1963
|
+
*/
|
|
1964
|
+
resolveSafePath(targetPath: string): string;
|
|
1965
|
+
/**
|
|
1966
|
+
* 把词法路径映射为物理路径。
|
|
1967
|
+
*
|
|
1968
|
+
* 关键点在于**向上回溯到最近一个真实存在的祖先**再取 realpath,然后把尚未存在的尾段拼回去:
|
|
1969
|
+
* - 目标已存在 → 直接 realpath,符号链接立刻被展开;
|
|
1970
|
+
* - 目标不存在(典型场景:write_file 新建文件) → 若只看目标本身,所有校验都会被跳过,
|
|
1971
|
+
* 于是 `write_file('linkDir/new.txt')` 可以借道指向外部的 linkDir 越界写入。
|
|
1972
|
+
* 回溯到 linkDir 取 realpath 即可识破这种穿透。
|
|
1973
|
+
*/
|
|
1974
|
+
private toPhysicalPath;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
declare const readFileTool: Tool<{
|
|
1978
|
+
path: string;
|
|
1979
|
+
startLine?: number;
|
|
1980
|
+
endLine?: number;
|
|
1981
|
+
}, string>;
|
|
1982
|
+
declare const writeFileTool: Tool<{
|
|
1983
|
+
path: string;
|
|
1984
|
+
content: string;
|
|
1985
|
+
}, string>;
|
|
1986
|
+
declare const editFileTool: Tool<{
|
|
1987
|
+
path: string;
|
|
1988
|
+
targetContent: string;
|
|
1989
|
+
replacementContent: string;
|
|
1990
|
+
}, string>;
|
|
1991
|
+
declare const globTool: Tool<{
|
|
1992
|
+
pattern: string;
|
|
1993
|
+
subDirectory?: string;
|
|
1994
|
+
}, string>;
|
|
1995
|
+
declare const grepTool: Tool<{
|
|
1996
|
+
pattern: string;
|
|
1997
|
+
path?: string;
|
|
1998
|
+
}, string>;
|
|
1999
|
+
/** 五个内置文件工具的聚合;全部经 PathSandbox 校验,路径越界或符号链接穿透一律拒绝。 */
|
|
2000
|
+
declare const builtinTools: (Tool<{
|
|
2001
|
+
path: string;
|
|
2002
|
+
startLine?: number;
|
|
2003
|
+
endLine?: number;
|
|
2004
|
+
}, string> | Tool<{
|
|
2005
|
+
path: string;
|
|
2006
|
+
content: string;
|
|
2007
|
+
}, string> | Tool<{
|
|
2008
|
+
path: string;
|
|
2009
|
+
targetContent: string;
|
|
2010
|
+
replacementContent: string;
|
|
2011
|
+
}, string> | Tool<{
|
|
2012
|
+
pattern: string;
|
|
2013
|
+
subDirectory?: string;
|
|
2014
|
+
}, string> | Tool<{
|
|
2015
|
+
pattern: string;
|
|
2016
|
+
path?: string;
|
|
2017
|
+
}, string>)[];
|
|
2018
|
+
|
|
2019
|
+
/** setup 收到的能力入口;tools / hooks 是会话共享的注册表,注册的条目影响后续所有执行。 */
|
|
2020
|
+
interface PluginContext {
|
|
2021
|
+
readonly tools: ToolRegistry;
|
|
2022
|
+
readonly hooks: HookRegistry;
|
|
2023
|
+
/** 本次会话的绝对工具根目录;工具的路径解析与审批都以此为基准。 */
|
|
2024
|
+
readonly rootDir: string;
|
|
2025
|
+
readonly logger?: (msg: string) => void;
|
|
2026
|
+
}
|
|
2027
|
+
/** 插件生命周期:setup 在会话空闲时挂载执行一次,teardown 在会话销毁时逐个调用以回收资源。 */
|
|
2028
|
+
interface AgentPlugin {
|
|
2029
|
+
/** 用于挂载失败与 teardown 的诊断信息。 */
|
|
2030
|
+
readonly name: string;
|
|
2031
|
+
readonly version?: string;
|
|
2032
|
+
setup(ctx: PluginContext): void | Promise<void>;
|
|
2033
|
+
teardown?(): void | Promise<void>;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
1734
2036
|
/** Chat 端点配置;能力覆盖只改变请求字段和完成边界,不改变协议身份。 */
|
|
1735
2037
|
interface OpenAIProviderOptions {
|
|
1736
2038
|
baseURL: string;
|
|
@@ -1866,7 +2168,13 @@ declare class OpenAIResponsesProvider implements ModelProvider {
|
|
|
1866
2168
|
private toUsage;
|
|
1867
2169
|
}
|
|
1868
2170
|
|
|
2171
|
+
/** 分层提示选项;目录受实际工具定义和请求剩余空间约束,不能用同名工具冒充加载能力。 */
|
|
1869
2172
|
interface PromptAssemblerOptions {
|
|
2173
|
+
/** 可信技能快照;仅匹配加载工具实例实际可见时注入L2.5。 */
|
|
2174
|
+
skills?: SkillRegistry;
|
|
2175
|
+
skillLoader?: Tool;
|
|
2176
|
+
contextWindow?: number;
|
|
2177
|
+
skillBudgetTokens?: number;
|
|
1870
2178
|
/** 提供时才生成 L2 工具清单段;缺省表示本次运行不向模型展示任何工具。 */
|
|
1871
2179
|
tools?: ToolRegistry;
|
|
1872
2180
|
/** L3 环境段展示的工作区根目录;文件工具的沙箱边界与其保持一致。 */
|
|
@@ -1884,6 +2192,7 @@ interface PromptAssemblerOptions {
|
|
|
1884
2192
|
* 各段之间以 `\n\n---\n\n` 分隔;不提供的内容整段跳过,不做占位填充。
|
|
1885
2193
|
*/
|
|
1886
2194
|
declare class PromptAssembler {
|
|
2195
|
+
private readonly options;
|
|
1887
2196
|
private readonly tools?;
|
|
1888
2197
|
private readonly rootDir;
|
|
1889
2198
|
private readonly agentName;
|
|
@@ -1893,11 +2202,14 @@ declare class PromptAssembler {
|
|
|
1893
2202
|
constructor(options: PromptAssemblerOptions);
|
|
1894
2203
|
/** 按固定层级拼装系统提示词;同一选项集总是产出相同文本,便于审计与缓存。 */
|
|
1895
2204
|
assemble(): string;
|
|
2205
|
+
/** 返回与 assemble 相同的目录统计;加载器被隐藏、替换或禁用时省略执行目录。 */
|
|
2206
|
+
getSkillCatalog(): SkillCatalog;
|
|
1896
2207
|
private getL1Behavior;
|
|
1897
2208
|
private getL2Tools;
|
|
1898
2209
|
private getL3Environment;
|
|
1899
2210
|
}
|
|
1900
2211
|
|
|
2212
|
+
/** 循环宿主配置;请求投影与在途预算只操作临时视图,历史仍按完整工具事务追加。 */
|
|
1901
2213
|
interface AgentLoopOptions {
|
|
1902
2214
|
/** 本次交互身份,内部步骤仍独立编号。 */
|
|
1903
2215
|
interactionId?: string;
|
|
@@ -1910,6 +2222,8 @@ interface AgentLoopOptions {
|
|
|
1910
2222
|
prepareRequest?: RequestPreparation;
|
|
1911
2223
|
/** 每次收到 usage 后回调;attemptId 标识 run:step:attempt,便于按尝试归因。 */
|
|
1912
2224
|
onUsage?: (request: ModelRequest, usage: Usage, attemptId: string) => Promise<void>;
|
|
2225
|
+
/** 在途批次预算视图;含当前 assistant 和已完成结果,不能作为落盘或授权依据,闭合后清空;回调不得抛错。 */
|
|
2226
|
+
onToolBatchUpdate?: (messages: readonly CanonicalMessage[]) => void;
|
|
1913
2227
|
provider: ModelProvider;
|
|
1914
2228
|
executor: ToolExecutor;
|
|
1915
2229
|
tools: ToolRegistry;
|
|
@@ -1939,6 +2253,7 @@ declare class AgentLoop {
|
|
|
1939
2253
|
private readonly projectHistory?;
|
|
1940
2254
|
private readonly prepareRequest?;
|
|
1941
2255
|
private readonly onUsage?;
|
|
2256
|
+
private readonly onToolBatchUpdate?;
|
|
1942
2257
|
private readonly provider;
|
|
1943
2258
|
private readonly executor;
|
|
1944
2259
|
private readonly tools;
|
|
@@ -1966,6 +2281,8 @@ declare class AgentLoop {
|
|
|
1966
2281
|
|
|
1967
2282
|
/** AgentSession 的构造配置;除主任务绑定外均可缺省,缺省行为见各字段。 */
|
|
1968
2283
|
interface SessionConfig {
|
|
2284
|
+
/** 宿主显式技能配置;缺省不扫描home,项目根需独立信任。 */
|
|
2285
|
+
skills?: SkillOptions;
|
|
1969
2286
|
/** 持久会话身份;有版本化 Store 时须与头部一致,日志实例身份保持独立。 */
|
|
1970
2287
|
conversationId?: string;
|
|
1971
2288
|
tokenEstimator?: TokenEstimator;
|
|
@@ -2022,6 +2339,8 @@ interface SessionStats {
|
|
|
2022
2339
|
* 运行或清理进行中,改变状态的公开方法一律被拒绝;Core 不承担任何界面职责。
|
|
2023
2340
|
*/
|
|
2024
2341
|
declare class AgentSession {
|
|
2342
|
+
private readonly skillRegistry?;
|
|
2343
|
+
private readonly skillRuntime?;
|
|
2025
2344
|
private persistentId;
|
|
2026
2345
|
private readonly configuredConversationId?;
|
|
2027
2346
|
private readonly estimator?;
|
|
@@ -2101,6 +2420,17 @@ declare class AgentSession {
|
|
|
2101
2420
|
getHistory(): CanonicalMessage[];
|
|
2102
2421
|
/** 返回当前投影视图,区别于原始历史;不执行模型或 Hook。 */
|
|
2103
2422
|
getContextHistory(): CanonicalMessage[];
|
|
2423
|
+
/** 查询技能元数据、诊断与本轮活动状态;只读,不加载正文或改变权限。 */
|
|
2424
|
+
getSkills(query?: string): {
|
|
2425
|
+
skills: SkillMetadata[];
|
|
2426
|
+
diagnostics: SkillDiagnostic[];
|
|
2427
|
+
activations: SkillActivation[];
|
|
2428
|
+
content: SkillContextState[];
|
|
2429
|
+
catalog: {
|
|
2430
|
+
included: number;
|
|
2431
|
+
omitted: number;
|
|
2432
|
+
};
|
|
2433
|
+
};
|
|
2104
2434
|
/** 查询最近最终请求的预算快照,尚未准备请求时返回 undefined。 */
|
|
2105
2435
|
getContextSnapshot(): ContextSnapshot | undefined;
|
|
2106
2436
|
/** 执行中止后的工具/摘要与存储收口期间仍返回 true。 */
|
|
@@ -2129,11 +2459,22 @@ declare class AgentSession {
|
|
|
2129
2459
|
signal?: AbortSignal;
|
|
2130
2460
|
role?: PrimaryModelRole;
|
|
2131
2461
|
}): AsyncIterable<SessionEvent>;
|
|
2462
|
+
/** 显式用户技能入口;任务原文单条提交,与普通run共享互斥、取消及清理,不恢复历史授权。 */
|
|
2463
|
+
runSkill(name: string, task: string, options?: {
|
|
2464
|
+
signal?: AbortSignal;
|
|
2465
|
+
role?: PrimaryModelRole;
|
|
2466
|
+
}): AsyncIterable<SessionEvent>;
|
|
2132
2467
|
/** 单次任务执行主体;调用方 return 的中止与 finally 清理由外层统一协调。 */
|
|
2133
2468
|
private runOperation;
|
|
2134
2469
|
/** 幂等销毁:卸载插件后发出 session:end;运行中拒绝,teardown 失败聚合抛出且不完成销毁。 */
|
|
2135
2470
|
destroy(): Promise<void>;
|
|
2136
2471
|
private assertIdle;
|
|
2472
|
+
/** 实际请求、静态统计和手动压缩共用目录空间推导;先计正文、工具和非目录提示,再预算整段目录。 */
|
|
2473
|
+
private createPromptAssembler;
|
|
2474
|
+
/** 完整消息提交后完成技能审计;审计失败保留真实历史,停止本轮且不发布成功事件。 */
|
|
2475
|
+
private commitSkills;
|
|
2476
|
+
/** 显式加载仍按同一读取策略、精确缓存与宿主审批裁决;拒绝/取消/审计失败时不追加用户任务。 */
|
|
2477
|
+
private authorizeSkill;
|
|
2137
2478
|
/**
|
|
2138
2479
|
* 计算最近一次内部模型请求的上下文占用;无 usage 时显式标注预算估算。
|
|
2139
2480
|
* run 累计 promptTokens 会重复计算每一步都重发的历史,不能用于窗口占用率。
|
|
@@ -2164,4 +2505,4 @@ declare class AgentSession {
|
|
|
2164
2505
|
private findClosedToolMessages;
|
|
2165
2506
|
}
|
|
2166
2507
|
|
|
2167
|
-
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginContext, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, executionFingerprint, extractFileDetails, globTool, grepTool, identifyHistory, indexInteractions, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, loadInstructions, normalizeHistory, projectSafeFields, readFileTool, recoverIncompleteAudit, renderFileDetails, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
|
|
2508
|
+
export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginContext, type PreparedSkill, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type SkillActivation, type SkillCatalog, type SkillContentSource, type SkillContextState, type SkillDefinition, type SkillDiagnostic, type SkillDocument, type SkillMetadata, type SkillOptions, type SkillQuery, type SkillQueryPage, SkillRegistry, type SkillResourceInput, type SkillResourcePage, type SkillRoot, SkillRuntime, type SkillScanResult, type SkillScope, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolHardDenial, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatSkillCatalog, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isSkillName, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, listSkillResources, loadInstructions, normalizeHistory, normalizeSkillTools, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
|