@x-otto/runtime 0.0.1-alpha.10 → 0.0.1-alpha.11
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.ts +267 -276
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -10
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { CostSummary, Message, Model, ModelResolution, ProviderRegistry, ThinkingLevel } from "@x-otto/ai";
|
|
1
|
+
import { CostSummary, Message, Model, ModelResolution, ProviderRegistry, StreamFunction, ThinkingLevel } from "@x-otto/ai";
|
|
2
2
|
import { HookRegistry, HookSpec, SystemPromptTransformInput, ToolExecuteAfterInput } from "@x-otto/hooks";
|
|
3
3
|
import { EventBus, Events, Logger, TypedEventEmitter } from "@x-otto/shared";
|
|
4
4
|
import { AppendLog, PanelStateDraftEntry, PanelStateEditedFile, PanelStatePersistence, PanelStateSnapshot, PanelStateSubagentEntry, PanelStateTodoItem, PanelStateTurnSummary, PasteStatePersistence, PasteStateSnapshot } from "@x-otto/persistence";
|
|
5
|
-
import {
|
|
5
|
+
import { EVENT_DOMAIN, EventDomain, SYSTEM_PROMPT_SECTIONS, SystemPromptSectionSpec, applySectionBudget, getEventDomain } from "@x-otto/interchange";
|
|
6
|
+
import * as _$_x_otto_session0 from "@x-otto/session";
|
|
7
|
+
import { InMemorySession, LeaseInspection, Session, SessionEntry, SessionPanelState, SessionPersistence, SessionSnapshot } from "@x-otto/session";
|
|
6
8
|
import { OttoProcessInfo } from "@x-otto/env";
|
|
7
|
-
import { Agent, AgentEvent, AgentMessage, AgentSessionEvent, AgentSessionEventMap, AgentSessionEventType, AgentSessionSubscriber, AgentTool, ApprovalRisk, AskUserQuestion, ClockPort, DescribeImagesPort, GrillAnswer, GrillQuestion, GrillRequest, IdPort, MemoryPort, MemoryPort as MemoryPort$1, RandomPort, StreamFunction, StreamRetryConfig, ToolHookExecutor, ToolResult, TraceEvent, TraceRecorder, applyMemoryTransform } from "@x-otto/agent";
|
|
9
|
+
import { Agent, AgentEvent, AgentMessage, AgentSessionEvent, AgentSessionEventMap, AgentSessionEventType, AgentSessionSubscriber, AgentTool, ApprovalRisk, AskUserQuestion, ClockPort, DescribeImagesPort, GrillAnswer, GrillQuestion, GrillRequest, IdPort, MemoryPort, MemoryPort as MemoryPort$1, RandomPort, StreamFunction as StreamFunction$1, StreamRetryConfig, ToolHookExecutor, ToolResult, TraceEvent, TraceRecorder, applyMemoryTransform } from "@x-otto/agent";
|
|
8
10
|
import * as _$_x_otto_session_contract0 from "@x-otto/session-contract";
|
|
9
11
|
import { ResidencyBudgetConfig, TurnRecord, TurnRecord as TurnRecord$1 } from "@x-otto/session-contract";
|
|
10
12
|
import { ChildProcess, SpawnOptions } from "node:child_process";
|
|
@@ -205,6 +207,14 @@ declare class HostRegistry {
|
|
|
205
207
|
dispose(): void;
|
|
206
208
|
}
|
|
207
209
|
//#endregion
|
|
210
|
+
//#region src/session/semantic-reviewer.d.ts
|
|
211
|
+
type SemanticReviewerVerdict = 'allow' | 'deny' | 'abstain';
|
|
212
|
+
type SemanticReviewer = (toolName: string, args: Record<string, unknown>, description: string, risk?: ApprovalRisk) => Promise<SemanticReviewerVerdict>;
|
|
213
|
+
/** 升级审批哨兵(与 T2 的 escalation reason 同源;此处不 import agent 常量避免反向依赖,测试锁定同值)。 */
|
|
214
|
+
declare const ESCALATION_MARKER = "[sandbox-escalation]";
|
|
215
|
+
/** 仅「升级审批」请求可进语义裁决(普通 ask 仍走用户审批——范围克制,RFC §2 D3)。 */
|
|
216
|
+
declare function isEscalationApproval(description: string): boolean;
|
|
217
|
+
//#endregion
|
|
208
218
|
//#region src/context-source.d.ts
|
|
209
219
|
interface ContextSource {
|
|
210
220
|
/** 本源的唯一标识。重复注册→覆盖前一次同 id 源。 */
|
|
@@ -252,10 +262,6 @@ declare class ContextSourceRegistry {
|
|
|
252
262
|
sealAndBuildHooks(workspaceDir?: string, memory?: ContextBuildInput['memory']): HookSpec[];
|
|
253
263
|
}
|
|
254
264
|
//#endregion
|
|
255
|
-
//#region src/session/semantic-reviewer.d.ts
|
|
256
|
-
type SemanticReviewerVerdict = 'allow' | 'deny' | 'abstain';
|
|
257
|
-
type SemanticReviewer = (toolName: string, args: Record<string, unknown>, description: string, risk?: ApprovalRisk) => Promise<SemanticReviewerVerdict>;
|
|
258
|
-
//#endregion
|
|
259
265
|
//#region src/context-sources/memory-delta.d.ts
|
|
260
266
|
/**
|
|
261
267
|
* memory-delta(#3 volatile memory delta)
|
|
@@ -332,6 +338,11 @@ interface MemorySubsystem extends MemoryPort$1, ContextInjectionPort, MemoryDelt
|
|
|
332
338
|
* 经过宿主完整解析后的 session 配置。
|
|
333
339
|
* 所有业务字段均已确定,无需再做 merge。
|
|
334
340
|
* Manager 层只接受此类型来创建 session,不持有业务默认值。
|
|
341
|
+
*
|
|
342
|
+
* RFC-394 D2/R1:这是配置链的**唯一真源**。AgentSessionOptions 从本类型派生
|
|
343
|
+
* (`SessionConfigSubset`),AgentConfig 从 Options 映射,PersistedSessionConfig
|
|
344
|
+
* 从字段元数据(`PERSISTABLE_CONFIG_FIELDS`)生成——新增字段只改此处,编译器
|
|
345
|
+
* 自动传播,消灭手抄映射清单(此前 4 次漏传事故的根因)。
|
|
335
346
|
*/
|
|
336
347
|
interface ResolvedSessionConfig {
|
|
337
348
|
model: Model;
|
|
@@ -418,7 +429,27 @@ interface ResolvedSessionConfig {
|
|
|
418
429
|
*/
|
|
419
430
|
describeImages?: DescribeImagesPort;
|
|
420
431
|
}
|
|
421
|
-
|
|
432
|
+
/**
|
|
433
|
+
* RFC-394 D2/R1:从 ResolvedSessionConfig 派生到 AgentSessionOptions 的会话配置子集。
|
|
434
|
+
*
|
|
435
|
+
* 这 27 个字段是 ResolvedSessionConfig 中**同时出现在 AgentSessionOptions 里**的字段——
|
|
436
|
+
* 此前逐字段手抄(buildAgentSession:461+),现用 Pick 派生,增删只改 ResolvedSessionConfig
|
|
437
|
+
* 一处,编译器自动传播到 Options。AgentSessionOptions = SessionConfigSubset & InfrastructurePorts。
|
|
438
|
+
*
|
|
439
|
+
* 不在此子集的字段(permissionAlwaysAllow / availableModels)是会话级权限/模型集合,
|
|
440
|
+
* 不传给 AgentSession 构造(由 SessionPool 直接读写 configs Map)。
|
|
441
|
+
*/
|
|
442
|
+
type SessionConfigSubset = Pick<ResolvedSessionConfig, 'model' | 'titleModel' | 'modelResolution' | 'agentName' | 'systemPrompt' | 'systemTail' | 'tools' | 'thinkingLevel' | 'maxToolTurns' | 'maxToolTurnExtensions' | 'promptOutputTokenBudget' | 'promptWallClockBudgetMs' | 'stallDetection' | 'sessionCostBudgetUSD' | 'todoContinuation' | 'promptRefresh' | 'workspaceDir' | 'workspaceId' | 'transient' | 'depth' | 'interactive' | 'listable' | 'retryAccelerate' | 'streamRetry' | 'networkDisconnectRetry' | 'lifecycleAsyncTimeoutMs' | 'describeImages'>;
|
|
443
|
+
/**
|
|
444
|
+
* RFC-394 D2/R1:AgentSessionOptions = SessionConfigSubset(从 ResolvedSessionConfig 派生)
|
|
445
|
+
* + InfrastructurePorts(运行时注入的基础设施端口)。
|
|
446
|
+
*
|
|
447
|
+
* 此前 AgentSessionOptions 是 42 字段的独立 interface,27 个字段与 ResolvedSessionConfig
|
|
448
|
+
* 逐字段手抄重复——现用 Pick 派生消灭手抄。新增 ResolvedSessionConfig 字段时,
|
|
449
|
+
* SessionConfigSubset 自动跟随(如需传入 AgentSession),编译器报错提示遗漏。
|
|
450
|
+
*/
|
|
451
|
+
interface AgentSessionOptions extends SessionConfigSubset {
|
|
452
|
+
/** 会话 id(仅 createSession 路径可选注入)。 */
|
|
422
453
|
id?: string;
|
|
423
454
|
/**
|
|
424
455
|
* RFC-324 D1/R5:turn-gated 压缩的超时兜底(毫秒)惰性读数。
|
|
@@ -428,98 +459,29 @@ interface AgentSessionOptions {
|
|
|
428
459
|
* 未注入时回退 `SESSION_COMPACTION_TIMEOUT_MS`(其本身已含 env 覆盖)。
|
|
429
460
|
*/
|
|
430
461
|
getCompactionTimeoutMs?: () => number | undefined;
|
|
431
|
-
model: Model;
|
|
432
|
-
/** 模型决策溯源(为何选中此 model)——透传给观测层供 inspector 显示。 */
|
|
433
|
-
modelResolution?: ModelResolution;
|
|
434
|
-
agentName?: string;
|
|
435
|
-
systemPrompt?: string;
|
|
436
|
-
/** 会话恒定的 volatile system 尾段种子(append 子代理角色块等);透传至 PromptParams.systemTail。 */
|
|
437
|
-
systemTail?: string[];
|
|
438
|
-
tools?: AgentTool[];
|
|
439
|
-
thinkingLevel?: ThinkingLevel;
|
|
440
|
-
maxToolTurns?: number;
|
|
441
|
-
maxToolTurnExtensions?: number;
|
|
442
|
-
/** RFC-104 D3:per-prompt output-token 预算(AgentSessionOptions 透传面)。 */
|
|
443
|
-
promptOutputTokenBudget?: number;
|
|
444
|
-
/** RFC-104 D3:per-prompt 墙钟预算(ms)。 */
|
|
445
|
-
promptWallClockBudgetMs?: number;
|
|
446
462
|
/** RFC-104 D2 缺省:顶层默认开、子 agent 默认关;OTTO_BUDGET_STEER_WRAPUP=1/0 覆盖。 */
|
|
447
463
|
budgetSteerWrapUp?: boolean;
|
|
448
|
-
/**
|
|
449
|
-
* RFC-203/RFC-204 D4:早期停滞检测配置透传(第三层,此前 AgentConfig/agent.ts 两层
|
|
450
|
-
* 断链已在 RFC-204 M2 修复)。缺省启用(走 ENGINE_DEFAULTS);`false` 显式关闭。
|
|
451
|
-
*/
|
|
452
|
-
stallDetection?: {
|
|
453
|
-
windowTurns?: number;
|
|
454
|
-
repeatThreshold?: number;
|
|
455
|
-
} | false;
|
|
456
|
-
/**
|
|
457
|
-
* RFC-204 D1/D2:会话累计成本软预算(美元)。超过阈值时一次性 emit
|
|
458
|
-
* `session.cost-budget-exceeded`(不阻断)。缺省 = 不启用预算检测。
|
|
459
|
-
*/
|
|
460
|
-
sessionCostBudgetUSD?: number;
|
|
461
|
-
/**
|
|
462
|
-
* RFC-094:todo 停机闭环硬闸——prompt 结束后若 todoList 仍有未完成项,自动续跑(cap 轮内)。
|
|
463
|
-
* 缺省从 OTTO_TODO_CONTINUE / OTTO_TODO_CONTINUE_MAX 解析(默认开、cap=3);depth>0 恒不启闸。
|
|
464
|
-
*/
|
|
465
|
-
todoContinuation?: {
|
|
466
|
-
enabled: boolean;
|
|
467
|
-
max: number;
|
|
468
|
-
};
|
|
469
|
-
workspaceDir?: string;
|
|
470
|
-
/** workspace 逻辑标识(`workspaceRef.id`),按 workspace 过滤会话列表时使用。 */
|
|
471
|
-
workspaceId?: string;
|
|
472
|
-
transient?: boolean;
|
|
473
464
|
hookRegistry: HookRegistry;
|
|
474
|
-
stream: StreamFunction;
|
|
475
|
-
/**
|
|
476
|
-
* RFC-078 M134:标题生成用的便宜模型(app 层经 RFC-061 `category:'search'` + usability gate 解析)。
|
|
477
|
-
* 缺省 → 不启用 LLM 标题生成(仅保留 derived 启发式占位)。禁用对话模型/claude-OAuth(R3)。
|
|
478
|
-
*/
|
|
479
|
-
titleModel?: Model;
|
|
465
|
+
stream: StreamFunction$1;
|
|
480
466
|
logger: Logger;
|
|
481
467
|
devtools?: Devtools;
|
|
482
|
-
promptRefresh?: PromptRefresh;
|
|
483
468
|
memory?: MemoryPort;
|
|
484
469
|
recorder?: TraceRecorder;
|
|
485
470
|
/** RFC-145 D3:nondet batch 冲洗回调(透传给 Agent → work-loop)。缺省 = 不聚合。 */
|
|
486
471
|
nondetFlush?: () => void;
|
|
487
472
|
clock?: ClockPort;
|
|
488
|
-
depth?: number;
|
|
489
473
|
/**
|
|
490
474
|
* RFC-371 M-A:父任务锚点(任务树语义)。orchestrator 委派子会话时注入
|
|
491
475
|
* `RunSessionOptions.parentTaskId`,透传 Agent → ToolExecutor → 工具上下文 →
|
|
492
476
|
* task_delegate/agent_call → orchestrator per-parent fan-out 闸。undefined = root 层。
|
|
493
477
|
*/
|
|
494
478
|
parentTaskId?: string;
|
|
495
|
-
interactive?: boolean;
|
|
496
479
|
/**
|
|
497
480
|
* RFC-380 T4:LLM 语义审批层(opt-in)。仅升级审批(sandbox-denied escalate ask)
|
|
498
481
|
* 且配置时生效;allow/deny 自动裁决(宿主侧需消费 approval.required 的
|
|
499
482
|
* semanticVerdict 记命令 bypass),abstain/未配置 → 既有用户弹窗流程。
|
|
500
483
|
*/
|
|
501
484
|
semanticReviewer?: SemanticReviewer;
|
|
502
|
-
/**
|
|
503
|
-
* 是否在 `/resume` 列表中可见(缺省 = 可见)。`false` 用于 headless 一次性内部会话
|
|
504
|
-
* (`otto --print/--json`)——照常落盘(sessionId/trace 有外部契约消费方),但不进列表。
|
|
505
|
-
* 详见 `PersistedSessionConfig.listable`。
|
|
506
|
-
*/
|
|
507
|
-
listable?: boolean;
|
|
508
|
-
retryAccelerate?: {
|
|
509
|
-
skip: boolean;
|
|
510
|
-
};
|
|
511
|
-
/** RFC-230:流式重试策略投影,见 `ResolvedSessionConfig.streamRetry` 同名字段注释。 */
|
|
512
|
-
streamRetry?: StreamRetryConfig;
|
|
513
|
-
/** RFC-230:网络断连重试策略投影,见 `ResolvedSessionConfig.networkDisconnectRetry` 同名字段注释。 */
|
|
514
|
-
networkDisconnectRetry?: StreamRetryConfig;
|
|
515
|
-
/** RFC-366:lifecycleAsync 挂死兜底超时(毫秒),见 `ResolvedSessionConfig.lifecycleAsyncTimeoutMs` 同名字段注释。 */
|
|
516
|
-
lifecycleAsyncTimeoutMs?: number;
|
|
517
|
-
/**
|
|
518
|
-
* RFC-181 D3/M3:图像委托描述端口(宿主 VisionDelegateService 实现,coding 层在会话
|
|
519
|
-
* 装配时注入)。缺省 = 主模型不支持视觉时,image block 降级为占位文本(见
|
|
520
|
-
* @x-otto/agent 的 vision-gate.ts 完整设计说明)。
|
|
521
|
-
*/
|
|
522
|
-
describeImages?: DescribeImagesPort;
|
|
523
485
|
}
|
|
524
486
|
interface AgentSessionInfo {
|
|
525
487
|
id: string;
|
|
@@ -583,7 +545,7 @@ declare function resolveTodoContinuationConfig(env: {
|
|
|
583
545
|
max: number;
|
|
584
546
|
};
|
|
585
547
|
declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
586
|
-
readonly session: Session<AgentMessage
|
|
548
|
+
readonly session: Session<AgentMessage> & SessionPanelState;
|
|
587
549
|
readonly workspaceDir: string;
|
|
588
550
|
readonly workspaceId?: string;
|
|
589
551
|
private agent;
|
|
@@ -614,13 +576,43 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
614
576
|
}> | undefined;
|
|
615
577
|
/** RFC-324 D1/R5:turn-gate 超时兜底的惰性读数(见 AgentSessionOptions 同名字段)。 */
|
|
616
578
|
private readonly getCompactionTimeoutMs?;
|
|
617
|
-
|
|
579
|
+
private _model;
|
|
618
580
|
/** 模型决策溯源(哪层选中 + 拒了谁)——供 task-runner 透传观测层。 */
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
581
|
+
private _modelResolution?;
|
|
582
|
+
private _tools;
|
|
583
|
+
private _systemPrompt;
|
|
622
584
|
/** 会话恒定的 volatile system 尾段种子(append 子代理角色块等);透传至每轮 PromptParams.systemTail。 */
|
|
623
|
-
|
|
585
|
+
private _systemTail?;
|
|
586
|
+
private _maxToolTurns;
|
|
587
|
+
private _maxToolTurnExtensions;
|
|
588
|
+
/** RFC-104 D3:per-prompt 预算(fork 拷贝面;depth>0 构造时已被剥除)。 */
|
|
589
|
+
private _promptOutputTokenBudget?;
|
|
590
|
+
private _promptWallClockBudgetMs?;
|
|
591
|
+
private _thinkingLevel;
|
|
592
|
+
private _promptRefresh?;
|
|
593
|
+
/** 公开只读——模型。写操作走 applyModel()。 */
|
|
594
|
+
get model(): Model;
|
|
595
|
+
get modelResolution(): ModelResolution | undefined;
|
|
596
|
+
get tools(): AgentTool[];
|
|
597
|
+
get systemPrompt(): string;
|
|
598
|
+
get systemTail(): string[] | undefined;
|
|
599
|
+
get maxToolTurns(): number;
|
|
600
|
+
get maxToolTurnExtensions(): number;
|
|
601
|
+
get promptOutputTokenBudget(): number | undefined;
|
|
602
|
+
get promptWallClockBudgetMs(): number | undefined;
|
|
603
|
+
get thinkingLevel(): ThinkingLevel;
|
|
604
|
+
get promptRefresh(): PromptRefresh | undefined;
|
|
605
|
+
/** RFC-394 D4/R4:显式 apply 方法——外部写运行时状态的唯一入口。 */
|
|
606
|
+
applyModel(model: Model, resolution?: ModelResolution): void;
|
|
607
|
+
applyThinkingLevel(level: ThinkingLevel): void;
|
|
608
|
+
applyTools(tools: AgentTool[]): void;
|
|
609
|
+
applySystemPrompt(prompt: string): void;
|
|
610
|
+
applyBudgets(opts: {
|
|
611
|
+
maxToolTurns?: number;
|
|
612
|
+
maxToolTurnExtensions?: number;
|
|
613
|
+
promptOutputTokenBudget?: number;
|
|
614
|
+
promptWallClockBudgetMs?: number;
|
|
615
|
+
}): void;
|
|
624
616
|
agentName: string;
|
|
625
617
|
depth: number;
|
|
626
618
|
/**
|
|
@@ -643,13 +635,6 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
643
635
|
* 置 false —— 照常落盘但不进列表。详见 `PersistedSessionConfig.listable`。
|
|
644
636
|
*/
|
|
645
637
|
readonly listable: boolean;
|
|
646
|
-
maxToolTurns: number;
|
|
647
|
-
maxToolTurnExtensions: number;
|
|
648
|
-
/** RFC-104 D3:per-prompt 预算(fork 拷贝面;depth>0 构造时已被剥除)。 */
|
|
649
|
-
promptOutputTokenBudget?: number;
|
|
650
|
-
promptWallClockBudgetMs?: number;
|
|
651
|
-
thinkingLevel: ThinkingLevel;
|
|
652
|
-
promptRefresh?: PromptRefresh;
|
|
653
638
|
private logger;
|
|
654
639
|
private hookRegistry;
|
|
655
640
|
private devtools?;
|
|
@@ -731,7 +716,7 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
731
716
|
systemPromptLength: number;
|
|
732
717
|
tools: string[];
|
|
733
718
|
};
|
|
734
|
-
constructor(session: Session<AgentMessage
|
|
719
|
+
constructor(session: Session<AgentMessage> & SessionPanelState, options: AgentSessionOptions);
|
|
735
720
|
/**
|
|
736
721
|
* 由 SessionPool / 宿主类在 session.created hook 执行完毕后调用。
|
|
737
722
|
* 此时 EventBridge 已完成订阅,session.start 事件可被正确接收。
|
|
@@ -848,6 +833,25 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
848
833
|
renameSession(title: string): void;
|
|
849
834
|
/** H5-20:本会话累计用量 + 成本汇总(供 /cost 命令 / TUI 状态栏消费)。 */
|
|
850
835
|
getCostSummary(): CostSummary;
|
|
836
|
+
/**
|
|
837
|
+
* RFC-390 D2:最近一轮的 uncached input token(RFC-411 修正口径标注)。
|
|
838
|
+
* **口径事实(RFC-411)**:`usage.inputTokens` 是 provider 分桶中的 uncached 部分,
|
|
839
|
+
* **不含 cacheRead/cacheWrite 前缀**(三分桶铁证 packages/ai/src/cache-hit-rate.ts:75
|
|
840
|
+
* totalInput = cacheRead + cacheWrite + inputTokens)——它不是"当前上下文占用"。
|
|
841
|
+
* RFC-390 D2 原注释"total 口径含 cache 前缀"是错误标签,已废止(见 RFC-411 执行摘要)。
|
|
842
|
+
* 供 memory-manager 的 `getRealInputTokens` 惰性端口消费——空响应轮 `record()` 跳过时
|
|
843
|
+
* 值停留在上一轮。undefined = 本会话尚无 usage(首次请求前)。
|
|
844
|
+
* (RealInputPolicy 因该口径低估从"补漏"退化为近乎恒不触发,坐标换算修正 defer 至
|
|
845
|
+
* memory 包独立 RFC——TokenPressurePolicy 真实估算仍是主力防线。)
|
|
846
|
+
*/
|
|
847
|
+
getLastInputTokens(): number | undefined;
|
|
848
|
+
/**
|
|
849
|
+
* RFC-434 D2:上一轮请求的 **total 口径** input(`cacheRead + cacheWrite + inputTokens`)
|
|
850
|
+
* ——"上下文实际有多大"的 provider 权威读数。供 memory-manager 的 `getRealInputTokens`
|
|
851
|
+
* 端口消费,取代原先错用的 `getLastInputTokens`(uncached-only,见 RFC-411 口径定性)。
|
|
852
|
+
* `undefined` = 本会话尚无 usage。
|
|
853
|
+
*/
|
|
854
|
+
getLastTotalInputTokens(): number | undefined;
|
|
851
855
|
/**
|
|
852
856
|
* RFC-019 M1:最近一回合的缓存命中率(R1)。`null` = 供应商无缓存 API 或本回合无 usage 数据
|
|
853
857
|
* ——消费方应据此隐藏该字段,而非展示误导性的 0。供 `/cache-stats`、summary 行消费。
|
|
@@ -1107,6 +1111,9 @@ declare class PanelStateStore {
|
|
|
1107
1111
|
/**
|
|
1108
1112
|
* 批量加载——直接返回 `PanelStateSnapshot`,供 persistence-sync 恢复/迁移路径使用。
|
|
1109
1113
|
* 比分别调用 4 次 get 方法更高效(一次 load 而非四次)。
|
|
1114
|
+
*
|
|
1115
|
+
* RFC-393 M4:版本门——读出的 `ver` 不匹配 `PANEL_STATE_VER` 时废弃旧 checkpoint
|
|
1116
|
+
* (返回 null,触发全量重读/迁移兜底)。缺省(旧数据无 ver)= 0,自动废弃。
|
|
1110
1117
|
*/
|
|
1111
1118
|
loadAll(sessionId: string): Promise<PanelStateSnapshot | null>;
|
|
1112
1119
|
/**
|
|
@@ -1157,6 +1164,42 @@ declare class ResidencyGovernor {
|
|
|
1157
1164
|
}
|
|
1158
1165
|
//#endregion
|
|
1159
1166
|
//#region src/session/session-manager.d.ts
|
|
1167
|
+
/**
|
|
1168
|
+
* RFC-394 D3/R2:后端能力 seam——收敛此前散装旋钮为结构化能力接口。
|
|
1169
|
+
*
|
|
1170
|
+
* 此前 SessionPoolOptions 有 5 个后端能力旋钮(isSessionWriteLocked /
|
|
1171
|
+
* inspectSessionWriteLease / forceReleaseSessionWriteLease / listColdSessionsOverride /
|
|
1172
|
+
* panelStateStore),每个都是"未注入即降级"的独立可选字段。现在收敛为 2 个
|
|
1173
|
+
* 能力接口对象,由持久化后端自声明(复用 supportsArchive 式能力探测惯例)。
|
|
1174
|
+
*
|
|
1175
|
+
* residencyGovernor / getResidencyConfig / planeRegistry 不是后端能力旋钮
|
|
1176
|
+
* (它们是跨模块基础设施注入——内存治理信号源/双平面注册表),保留为显式注入。
|
|
1177
|
+
*/
|
|
1178
|
+
/**
|
|
1179
|
+
* 写租约管理能力——合并此前 3 个散装旋钮(isSessionWriteLocked /
|
|
1180
|
+
* inspectSessionWriteLease / forceReleaseSessionWriteLease)。
|
|
1181
|
+
*
|
|
1182
|
+
* 由本地 SQLite 后端注入(SessionWriteLeaseManager 的薄封装);
|
|
1183
|
+
* 远端/内存后端无租约机制,不注入(行为与迁移前一致)。
|
|
1184
|
+
*/
|
|
1185
|
+
interface WriteLeaseManager {
|
|
1186
|
+
/** 某会话当前是否被**另一存活进程**持有写租约(无副作用,不 acquire)。 */
|
|
1187
|
+
isLockedByOther(sessionId: string): boolean;
|
|
1188
|
+
/** 写租约只读诊断(持有者 pid/hostname/存活性/mtime 距今)。 */
|
|
1189
|
+
inspect(sessionId: string): _$_x_otto_session0.LeaseInspection;
|
|
1190
|
+
/** 强制释放写租约(跳过 token 实核,仅供用户主动 /session unlock --force)。 */
|
|
1191
|
+
forceRelease(sessionId: string): void;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* 冷会话枚举能力——收敛此前 listColdSessionsOverride 散装旋钮。
|
|
1195
|
+
*
|
|
1196
|
+
* 由本地 SQLite 后端注入(SqliteSessionRepository 单次 SQL 查询);
|
|
1197
|
+
* 远端后端不注入,缺省走 listPaginated+load 兜底路径。
|
|
1198
|
+
*/
|
|
1199
|
+
interface ColdSessionLister {
|
|
1200
|
+
/** 枚举持久化后端已知但未必已加载进内存的冷会话(本地高效 SQL / 远端兜底分页)。 */
|
|
1201
|
+
listColdSessions(workspaceKey: string): Promise<AgentSessionInfo[]>;
|
|
1202
|
+
}
|
|
1160
1203
|
/**
|
|
1161
1204
|
* Manager 只持有基础设施配置(持久化、网络、日志)。
|
|
1162
1205
|
* 业务配置(model、systemPrompt、tools 等)由宿主(coding/第二宿主)解析后
|
|
@@ -1233,37 +1276,20 @@ interface SessionPoolOptions {
|
|
|
1233
1276
|
*/
|
|
1234
1277
|
planeRegistry?: HostRegistry;
|
|
1235
1278
|
/**
|
|
1236
|
-
* RFC-
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1241
|
-
* `SessionPool` 只判断"策略是否已注入",不感知底层是什么仓储实现——
|
|
1242
|
-
* 消灭对具体仓储类型的依赖(见 RFC-146 §6b「sessionRepoRef 迁移策略」)。
|
|
1243
|
-
*/
|
|
1244
|
-
listColdSessionsOverride?: (workspaceKey: string) => Promise<AgentSessionInfo[]>;
|
|
1245
|
-
/**
|
|
1246
|
-
* 只读探测(可选注入):某会话当前是否被**另一存活进程**持有写租约(RFC-159 D3
|
|
1247
|
-
* SessionWriteLeaseManager.peekLockedByOther 的薄封装,无副作用)。仅本地 SQLite 后端
|
|
1248
|
-
* 注入(`session-pool-factory.ts`);未注入时 `listSessions`/`listAllPersistedSessions`
|
|
1249
|
-
* 恒不标注只读(远端/内存后端无租约机制,行为与迁移前一致)。用于 `/resume` 列表
|
|
1250
|
-
* 提前展示"切进去会是只读",而非等到真正 save 被拒才事后感知。
|
|
1251
|
-
*/
|
|
1252
|
-
isSessionWriteLocked?: (sessionId: string) => boolean;
|
|
1253
|
-
/**
|
|
1254
|
-
* RFC-171 D4:写租约只读诊断(可选注入)——`SessionWriteLeaseManager.inspect` 的薄封装。
|
|
1255
|
-
* 仅本地 SQLite 后端注入。供 `/session unlock` 只读诊断模式消费(持有者 pid/hostname/
|
|
1256
|
-
* 存活性/mtime 距今);未注入时恒返回 `{ locked: false }`(远端/内存后端无租约机制)。
|
|
1279
|
+
* RFC-394 D3/R2:后端能力 seam——收敛此前 5 个散装旋钮(listColdSessionsOverride /
|
|
1280
|
+
* isSessionWriteLocked / inspectSessionWriteLease / forceReleaseSessionWriteLease /
|
|
1281
|
+
* panelStateStore 的后端注入面)为 2 个能力接口。由持久化后端自声明注入;
|
|
1282
|
+
* 未注入时各方法走降级路径(行为与迁移前一致)。新后端能力走"能力接口 + 自声明"
|
|
1283
|
+
* 模式,禁止在 SessionPoolOptions 新增散装旋钮(R2)。
|
|
1257
1284
|
*/
|
|
1258
|
-
|
|
1285
|
+
writeLeaseManager?: WriteLeaseManager;
|
|
1286
|
+
coldSessionLister?: ColdSessionLister;
|
|
1259
1287
|
/**
|
|
1260
|
-
* RFC-
|
|
1261
|
-
*
|
|
1288
|
+
* RFC-380 T4:LLM 语义审批层(opt-in)——app 级共享,透传给每个 AgentSession。
|
|
1289
|
+
* 仅升级审批(description 含 [sandbox-escalation])触发;allow/deny 自动裁决,
|
|
1290
|
+
* abstain/未注入 → 既有用户弹窗流程(行为不变)。fail-closed 语义见 semantic-reviewer.ts。
|
|
1262
1291
|
*/
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1265
|
-
interface DiskSessionPoolOptions extends SessionPoolOptions {
|
|
1266
|
-
sessionDir: string;
|
|
1292
|
+
semanticReviewer?: SemanticReviewer;
|
|
1267
1293
|
}
|
|
1268
1294
|
interface RemoteSessionPoolOptions extends SessionPoolOptions {
|
|
1269
1295
|
sessionUrl: string;
|
|
@@ -1286,7 +1312,7 @@ interface SessionPorts {
|
|
|
1286
1312
|
recorder?: TraceRecorder;
|
|
1287
1313
|
/** RFC-145 D3:nondet batch 冲洗回调(RecordingPorts.flushNondetBatch)。缺省 = 不聚合。 */
|
|
1288
1314
|
nondetFlush?: () => void;
|
|
1289
|
-
stream?: StreamFunction;
|
|
1315
|
+
stream?: StreamFunction$1;
|
|
1290
1316
|
tools?: AgentTool[];
|
|
1291
1317
|
disableMemory?: boolean;
|
|
1292
1318
|
}
|
|
@@ -1320,7 +1346,7 @@ declare class SessionPool {
|
|
|
1320
1346
|
private readonly idleTimeoutMs;
|
|
1321
1347
|
private readonly threshold;
|
|
1322
1348
|
private activeSessionId?;
|
|
1323
|
-
readonly stream: StreamFunction;
|
|
1349
|
+
readonly stream: StreamFunction$1;
|
|
1324
1350
|
private readonly hookRegistry;
|
|
1325
1351
|
private readonly logger;
|
|
1326
1352
|
private readonly devtools?;
|
|
@@ -1335,13 +1361,11 @@ declare class SessionPool {
|
|
|
1335
1361
|
/** RFC-327 修订 D2(M2):双平面注册边界——会话格派生/清理的宿主注册表(可选)。 */
|
|
1336
1362
|
private readonly planeRegistry?;
|
|
1337
1363
|
private readonly configProvider?;
|
|
1338
|
-
/** RFC-
|
|
1339
|
-
private readonly
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
private readonly inspectSessionWriteLeaseFn?;
|
|
1344
|
-
private readonly forceReleaseSessionWriteLeaseFn?;
|
|
1364
|
+
/** RFC-394 D3:后端能力 seam(收敛此前 5 个散装旋钮)。 */
|
|
1365
|
+
private readonly writeLeaseManager?;
|
|
1366
|
+
private readonly coldSessionLister?;
|
|
1367
|
+
/** RFC-380 T4:LLM 语义审批层(opt-in)——透传给每个 buildAgentSession。 */
|
|
1368
|
+
private readonly semanticReviewer?;
|
|
1345
1369
|
/**
|
|
1346
1370
|
* 持久化是否为「自动行为」。disk/remote 后端 = true(prompt 终态增量落盘 +
|
|
1347
1371
|
* 宿主 start/stop 自动 restoreAll/saveAll);in-memory 缺省 = false(行为与历史一致,
|
|
@@ -1539,16 +1563,12 @@ declare class SessionPool {
|
|
|
1539
1563
|
private canAccommodate;
|
|
1540
1564
|
dispose(): void;
|
|
1541
1565
|
}
|
|
1542
|
-
declare function createDiskSessionPool(options: DiskSessionPoolOptions): SessionPool;
|
|
1543
1566
|
declare function createRemoteSessionPool(options: RemoteSessionPoolOptions): SessionPool;
|
|
1544
1567
|
declare function createInMemorySessionPool(options: SessionPoolOptions): SessionPool;
|
|
1545
1568
|
//#endregion
|
|
1546
1569
|
//#region src/create-agent-runtime.d.ts
|
|
1547
1570
|
type SessionStorageConfig = {
|
|
1548
1571
|
kind: 'in-memory';
|
|
1549
|
-
} | {
|
|
1550
|
-
kind: 'disk';
|
|
1551
|
-
sessionDir: string;
|
|
1552
1572
|
} | {
|
|
1553
1573
|
kind: 'remote';
|
|
1554
1574
|
sessionUrl: string;
|
|
@@ -1573,22 +1593,12 @@ type SessionStorageConfig = {
|
|
|
1573
1593
|
autoPersist?: boolean; /** 后端专属资源释放(如 SqliteSessionRepository.close());dispose 时在 sessions.dispose 后调用。 */
|
|
1574
1594
|
onDispose?: () => void | Promise<void>;
|
|
1575
1595
|
/**
|
|
1576
|
-
* RFC-
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
1579
|
-
*/
|
|
1580
|
-
listColdSessionsOverride?: (workspaceKey: string) => Promise<AgentSessionInfo[]>;
|
|
1581
|
-
/**
|
|
1582
|
-
* 只读探测策略透传(见 SessionPoolOptions.isSessionWriteLocked)。关系化 SQLite 分支
|
|
1583
|
-
* 经此注入 SessionWriteLeaseManager.peekLockedByOther 的薄封装。
|
|
1596
|
+
* RFC-394 D3/R2:后端能力 seam——收敛此前 4 个散装透传字段
|
|
1597
|
+
* (listColdSessionsOverride / isSessionWriteLocked / inspectSessionWriteLease /
|
|
1598
|
+
* forceReleaseSessionWriteLease)为 2 个能力接口。由后端自声明注入。
|
|
1584
1599
|
*/
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
* RFC-171 D4:写租约诊断/强制释放策略透传(见 SessionPoolOptions 对应字段)。
|
|
1588
|
-
* 关系化 SQLite 分支经此注入 SessionWriteLeaseManager.inspect/forceRelease 的薄封装。
|
|
1589
|
-
*/
|
|
1590
|
-
inspectSessionWriteLease?: (sessionId: string) => LeaseInspection;
|
|
1591
|
-
forceReleaseSessionWriteLease?: (sessionId: string) => void;
|
|
1600
|
+
writeLeaseManager?: WriteLeaseManager;
|
|
1601
|
+
coldSessionLister?: ColdSessionLister;
|
|
1592
1602
|
/**
|
|
1593
1603
|
* RFC-108 D3 面板态(todoList/editedFiles/subagents/drafts)独立持久化的落盘目录。
|
|
1594
1604
|
* 2026-07-21 修复:`kind:'custom'`(coding 默认的关系化 SQLite 后端)此前不构造
|
|
@@ -1644,6 +1654,11 @@ interface RuntimeOptions {
|
|
|
1644
1654
|
* 未注入 = 会话格不派生(行为不变,宿主不接双平面即零影响)。
|
|
1645
1655
|
*/
|
|
1646
1656
|
planeRegistry?: HostRegistry;
|
|
1657
|
+
/**
|
|
1658
|
+
* RFC-380 T4:LLM 语义审批层(opt-in)。注入后仅升级审批(sandbox-denied escalate ask)
|
|
1659
|
+
* 触发;allow/deny 自动裁决,abstain/未注入 → 既有用户弹窗流程(行为不变)。
|
|
1660
|
+
*/
|
|
1661
|
+
semanticReviewer?: SemanticReviewer;
|
|
1647
1662
|
}
|
|
1648
1663
|
interface AgentRuntime {
|
|
1649
1664
|
/** 统一派生入口:子 runtime / 宿主 / swarm / task-runner 皆经此(§4-11)。 */
|
|
@@ -1654,7 +1669,7 @@ interface AgentRuntime {
|
|
|
1654
1669
|
readonly sessions: SessionPool;
|
|
1655
1670
|
readonly hookRegistry: HookRegistry;
|
|
1656
1671
|
/** 引擎 stream(从 providerRegistry 派生,§4-11:子 runtime 用之而非各自 createStreamFunction)。 */
|
|
1657
|
-
readonly stream: StreamFunction;
|
|
1672
|
+
readonly stream: StreamFunction$1;
|
|
1658
1673
|
/** ContextSource 有序注册表(D33):通用源已内置注册,coding 策略源由宿主追加。 */
|
|
1659
1674
|
readonly contextSources: ContextSourceRegistry;
|
|
1660
1675
|
readonly traceStore: AppendLog<TraceEvent>;
|
|
@@ -1667,7 +1682,7 @@ interface AgentRuntime {
|
|
|
1667
1682
|
* createAgentRuntime 内置调用之;宿主的离线装配路径(不经 createAgentRuntime)亦复用,
|
|
1668
1683
|
* 确保「App 经 rt.contextSources 构建注入 hooks」对所有后端一致——消灭 App 端的二次造表。
|
|
1669
1684
|
*/
|
|
1670
|
-
declare function createDefaultContextSourceRegistry(
|
|
1685
|
+
declare function createDefaultContextSourceRegistry(_workspaceDir: string, _memory?: MemorySubsystem): ContextSourceRegistry;
|
|
1671
1686
|
declare function createAgentRuntime(options?: RuntimeOptions): AgentRuntime;
|
|
1672
1687
|
//#endregion
|
|
1673
1688
|
//#region src/engine-stores.d.ts
|
|
@@ -2162,6 +2177,11 @@ interface ProcessSpawnConfig {
|
|
|
2162
2177
|
*/
|
|
2163
2178
|
env?: Record<string, string>;
|
|
2164
2179
|
cwd?: string;
|
|
2180
|
+
/** RFC-394 M5:从 ProcessRegistry RegisterInput 收敛——输出落临时文件路径(bash 工具填)。 */
|
|
2181
|
+
logPath?: string;
|
|
2182
|
+
/** RFC-394 M5:从 ProcessRegistry RegisterInput 收敛——best-effort 嗅探端口/URL。 */
|
|
2183
|
+
port?: number;
|
|
2184
|
+
url?: string;
|
|
2165
2185
|
}
|
|
2166
2186
|
interface KillOptions {
|
|
2167
2187
|
graceMs?: number;
|
|
@@ -2185,6 +2205,22 @@ interface ManagedProcess {
|
|
|
2185
2205
|
readonly pgid: number | undefined;
|
|
2186
2206
|
readonly status: ProcessStatus;
|
|
2187
2207
|
readonly config: ProcessSpawnConfig;
|
|
2208
|
+
/** RFC-394 M5:便捷 getter(从 config 投影,消费方不用深挖 config.xxx)。 */
|
|
2209
|
+
readonly command: string;
|
|
2210
|
+
readonly cwd: string | undefined;
|
|
2211
|
+
readonly logPath: string | undefined;
|
|
2212
|
+
readonly port: number | undefined;
|
|
2213
|
+
readonly url: string | undefined;
|
|
2214
|
+
/** 进程启动时刻(spawn/register 时戳,注入时钟)。 */
|
|
2215
|
+
readonly startedAt: number;
|
|
2216
|
+
/** 退出码(未退出或被信号杀死为 undefined)。 */
|
|
2217
|
+
readonly exitCode: number | undefined;
|
|
2218
|
+
/**
|
|
2219
|
+
* RFC-223:运行时输出识别到的服务信息(url/port/protocol)。
|
|
2220
|
+
* 由 `ProcessRuntime.updateDetectedService` 按 D2 去重规则写入,供状态栏
|
|
2221
|
+
* 「服务」指示器与 ServicesDialog 消费。未识别到时为 undefined。
|
|
2222
|
+
*/
|
|
2223
|
+
readonly detectedService: DetectedService | undefined;
|
|
2188
2224
|
/** 原始字节流 stdin/stdout/stderr(规则 5/H2:非行缓冲,帧解析由消费者负责) */
|
|
2189
2225
|
readonly stdin: NodeJS.WritableStream | null;
|
|
2190
2226
|
readonly stdout: NodeJS.ReadableStream | null;
|
|
@@ -2227,6 +2263,18 @@ declare class ProcessRuntime {
|
|
|
2227
2263
|
get(id: string): ManagedProcess | undefined;
|
|
2228
2264
|
list(filter?: ProcessFilter): ManagedProcess[];
|
|
2229
2265
|
listForSession(sessionId: string): ManagedProcess[];
|
|
2266
|
+
/** RFC-394 M5:从 ProcessRegistry 收敛——按 sessionId+id 精确查找。 */
|
|
2267
|
+
getForSession(sessionId: string, id: string): ManagedProcess | undefined;
|
|
2268
|
+
/**
|
|
2269
|
+
* RFC-394 M5:从 ProcessRegistry 收敛——registry 级 kill(id)。
|
|
2270
|
+
* ProcessRuntime 的 kill 是实例方法(proc.kill()),此方法提供 registry 级入口。
|
|
2271
|
+
*/
|
|
2272
|
+
kill(id: string, opts?: KillOptions): Promise<void>;
|
|
2273
|
+
/**
|
|
2274
|
+
* RFC-394 M5:从 ProcessRegistry 收敛——更新已检测到的服务信息。
|
|
2275
|
+
* 用于 background bash 运行时输出识别到端口/URL 的场景(RFC-223)。
|
|
2276
|
+
*/
|
|
2277
|
+
updateDetectedService(id: string, service: DetectedService): void;
|
|
2230
2278
|
listForOwner(owner: ProcessOwner): ManagedProcess[];
|
|
2231
2279
|
touch(id: string): void;
|
|
2232
2280
|
remove(id: string): void;
|
|
@@ -2337,6 +2385,15 @@ declare function revertDiff(repoRoot: string, diff: string): ApplyDiffResult;
|
|
|
2337
2385
|
* 真实失败无声吞掉,运维完全无感知)。`onError` 缺省不传时行为与修复前一致(纯静默)。
|
|
2338
2386
|
*/
|
|
2339
2387
|
declare function removeWorktree(wt: Worktree, onError?: (op: 'worktree remove' | 'branch delete' | 'worktree prune', err: unknown) => void): void;
|
|
2388
|
+
/**
|
|
2389
|
+
* RFC-435 R8:扫描磁盘上存在的全部 job worktree id(跨进程 rehydrate 源)。
|
|
2390
|
+
*
|
|
2391
|
+
* 用与 pruneOrphanWorktrees 相同的筛选逻辑(tmpdir `otto-wt-*` 前缀 + `otto/job-*` branch),
|
|
2392
|
+
* 但**不删除任何东西**——只返回 jobId 集合。调用方(如 installAgentJobReaper)把本进程
|
|
2393
|
+
* 活跃集与此集合并后传给 pruneOrphanWorktrees,使"他进程(daemon/另一会话)创建的 job
|
|
2394
|
+
* worktree"不会被误判为孤儿销毁(R8:剪枝必须基于 rehydrate 后活跃集合)。
|
|
2395
|
+
*/
|
|
2396
|
+
declare function listWorktreeJobIds(repoRoot: string): string[];
|
|
2340
2397
|
/**
|
|
2341
2398
|
* 扫描并清理孤儿 worktree(SIGKILL/OOM 未走 exit reaper 留下的残留)。
|
|
2342
2399
|
* 用 `git -C repoRoot worktree list --porcelain` 列出该仓的全部已注册 worktree,
|
|
@@ -2768,6 +2825,11 @@ declare function attachAgentObserver(agent: Agent, meta: AgentObservationMeta, r
|
|
|
2768
2825
|
declare function createEnvironmentContextSource(workspaceDir: string): ContextSource;
|
|
2769
2826
|
//#endregion
|
|
2770
2827
|
//#region src/context-sources/memory-index.d.ts
|
|
2828
|
+
/**
|
|
2829
|
+
* RFC-390 D4:标准组合根不再注册此 source(memory 内容由 coding 侧 lesson-injection hook
|
|
2830
|
+
* 合并进 <agent_knowledge> 信封)。保留供 V 形态/无 coding 组合使用——priority 复用
|
|
2831
|
+
* agentKnowledge 的 35(同位替代)。
|
|
2832
|
+
*/
|
|
2771
2833
|
declare function createMemoryIndexContextSource(_workspaceDir: string, memory?: ContextBuildInput['memory']): ContextSource;
|
|
2772
2834
|
//#endregion
|
|
2773
2835
|
//#region src/context-sources/todo-reminder.d.ts
|
|
@@ -2836,131 +2898,6 @@ interface DocSyncPort {
|
|
|
2836
2898
|
declare function formatDocSyncReminder(toolName: string): string;
|
|
2837
2899
|
declare function createDocSyncReminderHooks(port: DocSyncPort, priority?: 64): HookSpec[];
|
|
2838
2900
|
//#endregion
|
|
2839
|
-
//#region src/context-sources/section-order.d.ts
|
|
2840
|
-
/**
|
|
2841
|
-
* RFC-020 Phase 3(M54)P3-04:system-prompt 注入 section 的**唯一有序声明**。
|
|
2842
|
-
*
|
|
2843
|
-
* 治病灶——此前各 section 的 priority 数字(20/25/35/38/40/60)散在 coding hooks 与 runtime
|
|
2844
|
-
* context-sources 两包里,"system prompt 各段什么顺序"得捞齐多处数字才能拼出。现收敛为此处一张表:
|
|
2845
|
-
* - 数组/字段顺序即 priority 升序 = 实际 `system.prompt.transform` hook 的执行/拼接顺序;
|
|
2846
|
-
* - `lane` 标明该段落 **stable 前缀**(systemPrompt,进 prompt cache)还是 **volatile 尾段**
|
|
2847
|
-
* (systemTail,落在 cache 断点之后,逐轮可变不击穿缓存);
|
|
2848
|
-
* - runtime context-sources(environment/memory-index/memory-delta)与 coding hooks
|
|
2849
|
-
* (tool-guidance/lesson/skill-catalog)均从此处取 priority —— 单一真相源,改序只此一处。
|
|
2850
|
-
*
|
|
2851
|
-
* 放在 @x-otto/runtime(coding 依赖 runtime、反向不依赖):coding 侧 hook 经 `@x-otto/runtime` import。
|
|
2852
|
-
* 注:本表是**排序权威**(方案 H:section 仍由各自 hook 自注册,priority 数字降级为对本表的引用);
|
|
2853
|
-
* 不强行把 `SYSTEM_PROMPT_SECTIONS` 各 section 物理并入单一 registry(那超出外科尺度、非目标)。
|
|
2854
|
-
* section 数量以该常量的字段数为准,不在本段注释里重复写死具体数字(history: 建表时 7 个,
|
|
2855
|
-
* 后追加 docSyncReminder 成 8 个,又补 skillLoopGuidance 成 9 个——写死数字会重犯本次发现的漂移)。
|
|
2856
|
-
*/
|
|
2857
|
-
type SystemPromptLane = 'stable' | 'volatile';
|
|
2858
|
-
interface SystemPromptSectionSpec {
|
|
2859
|
-
/** 对应 hook / ContextSource 的 name/id(与注册名一致,供 drift guard 比对)。 */
|
|
2860
|
-
readonly name: string;
|
|
2861
|
-
readonly priority: number;
|
|
2862
|
-
readonly lane: SystemPromptLane;
|
|
2863
|
-
/**
|
|
2864
|
-
* RFC-374 M3:本 section 的注入字节硬顶(UTF-8)。注入点经
|
|
2865
|
-
* `applySectionBudget` 统一裁剪——预算只此一处声明,各注入点不持局部常量。
|
|
2866
|
-
* 取值原则:明显高于常态内容(防御失控注入而非改变正常行为),
|
|
2867
|
-
* 需要收紧时只改本表。
|
|
2868
|
-
*/
|
|
2869
|
-
readonly budgetBytes: number;
|
|
2870
|
-
}
|
|
2871
|
-
declare const SYSTEM_PROMPT_SECTIONS: {
|
|
2872
|
-
readonly toolGuidance: {
|
|
2873
|
-
readonly name: "tool-guidance-injection";
|
|
2874
|
-
readonly priority: 20;
|
|
2875
|
-
readonly lane: "stable";
|
|
2876
|
-
readonly budgetBytes: 20000;
|
|
2877
|
-
};
|
|
2878
|
-
/**
|
|
2879
|
-
* RFC-318 D7:三分流判别(缺工具 / 流程重复 / 其余)。紧跟 toolGuidance——它是对
|
|
2880
|
-
* "现有工具够不够用"的元判断,语义上属工具指引的延伸;内容恒定故走 stable lane。
|
|
2881
|
-
*/
|
|
2882
|
-
readonly skillLoopGuidance: {
|
|
2883
|
-
readonly name: "skill-loop-guidance-injection";
|
|
2884
|
-
readonly priority: 21;
|
|
2885
|
-
readonly lane: "stable";
|
|
2886
|
-
readonly budgetBytes: 2000;
|
|
2887
|
-
};
|
|
2888
|
-
readonly environment: {
|
|
2889
|
-
readonly name: "runtime:environment";
|
|
2890
|
-
readonly priority: 25;
|
|
2891
|
-
readonly lane: "stable";
|
|
2892
|
-
readonly budgetBytes: 8000;
|
|
2893
|
-
};
|
|
2894
|
-
readonly memoryIndex: {
|
|
2895
|
-
readonly name: "runtime:memory-index";
|
|
2896
|
-
readonly priority: 35;
|
|
2897
|
-
readonly lane: "stable";
|
|
2898
|
-
readonly budgetBytes: 24000;
|
|
2899
|
-
};
|
|
2900
|
-
readonly skillCatalog: {
|
|
2901
|
-
readonly name: "skill-catalog-injection";
|
|
2902
|
-
readonly priority: 38;
|
|
2903
|
-
readonly lane: "stable";
|
|
2904
|
-
readonly budgetBytes: 12000;
|
|
2905
|
-
};
|
|
2906
|
-
/** RFC-374 M3 初始 8KB 低于 RFC-382 T5/T6 重建后的常态内容(8.5KB 实测,2026-08-14)——
|
|
2907
|
-
* 字节顶须 > 常态内容(防御失控注入而非改变正常行为),否则每次构建静默截掉 pack 尾部。
|
|
2908
|
-
* 10KB 维持 ~1.2x 防御余量;token 侧仍受 RFC-284 8k soft/12k hard 预算约束。 */
|
|
2909
|
-
readonly lesson: {
|
|
2910
|
-
readonly name: "lesson-injection";
|
|
2911
|
-
readonly priority: 40;
|
|
2912
|
-
readonly lane: "stable";
|
|
2913
|
-
readonly budgetBytes: 10000;
|
|
2914
|
-
}; /** RFC-318 R7 治理补全:lesson-relevant-hints 原为表外 hook,现纳入统一预算面(volatile 尾段)。 */
|
|
2915
|
-
readonly lessonRelevantHints: {
|
|
2916
|
-
readonly name: "lesson-relevant-hints";
|
|
2917
|
-
readonly priority: 41;
|
|
2918
|
-
readonly lane: "volatile";
|
|
2919
|
-
readonly budgetBytes: 4000;
|
|
2920
|
-
};
|
|
2921
|
-
/**
|
|
2922
|
-
* RFC-383 M2(§9 修订 6):高频 skill 内化指令核心——引擎内部 hook
|
|
2923
|
-
* `internalize-skill-injection` 的 volatile 尾段预算面。**必须注册**:不注册则
|
|
2924
|
-
* applySectionBudget 原样放行、4KB 硬顶失效(决策器提炼不受控)。priority 42 排在
|
|
2925
|
-
* lessonRelevantHints(41) 之后、memoryDelta(60) 之前。
|
|
2926
|
-
*/
|
|
2927
|
-
readonly internalize: {
|
|
2928
|
-
readonly name: "internalize-skill-injection";
|
|
2929
|
-
readonly priority: 42;
|
|
2930
|
-
readonly lane: "volatile";
|
|
2931
|
-
readonly budgetBytes: 4000;
|
|
2932
|
-
};
|
|
2933
|
-
readonly memoryDelta: {
|
|
2934
|
-
readonly name: "memory-delta-injection";
|
|
2935
|
-
readonly priority: 60;
|
|
2936
|
-
readonly lane: "volatile";
|
|
2937
|
-
readonly budgetBytes: 8000;
|
|
2938
|
-
};
|
|
2939
|
-
readonly todoReminder: {
|
|
2940
|
-
readonly name: "todo-reminder-injection";
|
|
2941
|
-
readonly priority: 62;
|
|
2942
|
-
readonly lane: "volatile";
|
|
2943
|
-
readonly budgetBytes: 4000;
|
|
2944
|
-
};
|
|
2945
|
-
readonly docSyncReminder: {
|
|
2946
|
-
readonly name: "doc-sync-reminder-injection";
|
|
2947
|
-
readonly priority: 64;
|
|
2948
|
-
readonly lane: "volatile";
|
|
2949
|
-
readonly budgetBytes: 4000;
|
|
2950
|
-
};
|
|
2951
|
-
};
|
|
2952
|
-
/**
|
|
2953
|
-
* RFC-374 M3:按 section name 应用注入预算。内容超预算时裁剪(boundFragment,
|
|
2954
|
-
* 纯文本截断后缀,RFC-142 红线兼容);name 不在表中时原样返回(插件自定义
|
|
2955
|
-
* context source 不受本表预算约束——它不进表就不进预算面,是显式而非默认)。
|
|
2956
|
-
*
|
|
2957
|
-
* 截断诊断(08-14 lesson 字节顶事故跟进):超预算裁剪是静默丢信息——内容里的
|
|
2958
|
-
* 截断后缀模型能看见但宿主日志看不见,预算配置漂移(如 pack 内容长大超过
|
|
2959
|
-
* budgetBytes)只表现为「注入内容莫名缺尾」。此处 warn(每进程每 section 一次)
|
|
2960
|
-
* 把截断升级为可诊断事件,触发即提示检查 budgetBytes 与内容常态体积是否匹配。
|
|
2961
|
-
*/
|
|
2962
|
-
declare function applySectionBudget(name: string, content: string): string;
|
|
2963
|
-
//#endregion
|
|
2964
2901
|
//#region src/session-stable.d.ts
|
|
2965
2902
|
interface SessionStableInjectionOptions {
|
|
2966
2903
|
name: string;
|
|
@@ -2970,6 +2907,35 @@ interface SessionStableInjectionOptions {
|
|
|
2970
2907
|
}
|
|
2971
2908
|
declare function createSessionStableInjectionHooks(options: SessionStableInjectionOptions): HookSpec[];
|
|
2972
2909
|
//#endregion
|
|
2910
|
+
//#region src/define-prompt-section.d.ts
|
|
2911
|
+
interface PromptSectionDefinition {
|
|
2912
|
+
/**
|
|
2913
|
+
* section 名称——必须在 SYSTEM_PROMPT_SECTIONS 表中已登记且 lane 为 'stable'。
|
|
2914
|
+
* priority / budgetBytes 从表查取,调用方不可覆盖。
|
|
2915
|
+
*/
|
|
2916
|
+
readonly name: string;
|
|
2917
|
+
/**
|
|
2918
|
+
* 计算注入内容。返回空/undefined 表示本会话无注入(首轮计算后会话内冻结,不再重算)。
|
|
2919
|
+
* 产物自动过 applySectionBudget(调用方不需手动套预算)。
|
|
2920
|
+
*/
|
|
2921
|
+
compute: (input: SystemPromptTransformInput) => Promise<string | undefined> | string | undefined;
|
|
2922
|
+
}
|
|
2923
|
+
/**
|
|
2924
|
+
* 定义一个 stable prompt section 注入 hook。
|
|
2925
|
+
*
|
|
2926
|
+
* 自动从 SYSTEM_PROMPT_SECTIONS 表查 priority / budgetBytes,走 session 冻结的 stable
|
|
2927
|
+
* lane,产物统一过 applySectionBudget。
|
|
2928
|
+
*
|
|
2929
|
+
* @example
|
|
2930
|
+
* ```ts
|
|
2931
|
+
* const hooks = definePromptSection({
|
|
2932
|
+
* name: SYSTEM_PROMPT_SECTIONS.skillLoopGuidance.name,
|
|
2933
|
+
* compute: async () => isEnabled() ? await loadGuidance() : undefined,
|
|
2934
|
+
* })
|
|
2935
|
+
* ```
|
|
2936
|
+
*/
|
|
2937
|
+
declare function definePromptSection(definition: PromptSectionDefinition): HookSpec[];
|
|
2938
|
+
//#endregion
|
|
2973
2939
|
//#region src/session/tool-result-store-global.d.ts
|
|
2974
2940
|
/**
|
|
2975
2941
|
* tool-result-store-global.ts — RFC-093:ToolResultStore 全局单例
|
|
@@ -3005,6 +2971,31 @@ declare function deriveSessionTitle(messages: readonly AgentMessage[]): string |
|
|
|
3005
2971
|
*/
|
|
3006
2972
|
declare function resolveSessionTitle(persistedTitle: string | undefined, messages: readonly AgentMessage[], id: string): string;
|
|
3007
2973
|
//#endregion
|
|
2974
|
+
//#region src/session/llm-escalation-reviewer.d.ts
|
|
2975
|
+
interface LlmEscalationReviewerDeps {
|
|
2976
|
+
/** 会话注入的流函数(与对话同一条,按 model.api 路由 provider)。 */
|
|
2977
|
+
stream: StreamFunction;
|
|
2978
|
+
/** 便宜判定模型(由 app 层解析,同 generateTitle 的 category:'search' 口径)。 */
|
|
2979
|
+
model: Model;
|
|
2980
|
+
/** 上限超时(ms),默认 10s;超时 → abstain。 */
|
|
2981
|
+
timeoutMs?: number;
|
|
2982
|
+
}
|
|
2983
|
+
/**
|
|
2984
|
+
* 解析 `{"verdict":"allow|deny|abstain"}`。
|
|
2985
|
+
*
|
|
2986
|
+
* **fail-closed 解析**:只有明确抽到 `allow`/`deny` 才返回之,其余(畸形 JSON、截断、
|
|
2987
|
+
* 散文、未知枚举值、空)一律 'abstain'。特别地,绝不因为文本里**出现** "allow" 字样
|
|
2988
|
+
* 就放行——必须是结构化 verdict 字段。
|
|
2989
|
+
*/
|
|
2990
|
+
declare function parseVerdict(raw: string): SemanticReviewerVerdict;
|
|
2991
|
+
/**
|
|
2992
|
+
* 构造 LLM 语义审批器。返回的函数签名即 `SemanticReviewer`。
|
|
2993
|
+
*
|
|
2994
|
+
* 注意:本函数**不做**「是否为升级审批」的判断——那由 gates 的 `isEscalationApproval`
|
|
2995
|
+
* 门负责(单一真源)。
|
|
2996
|
+
*/
|
|
2997
|
+
declare function createLlmEscalationReviewer(deps: LlmEscalationReviewerDeps): SemanticReviewer;
|
|
2998
|
+
//#endregion
|
|
3008
2999
|
//#region src/session/hooks.d.ts
|
|
3009
3000
|
interface ToolHookOptions {
|
|
3010
3001
|
hookRegistry: HookRegistry;
|
|
@@ -3381,5 +3372,5 @@ interface ResidencyDecision {
|
|
|
3381
3372
|
*/
|
|
3382
3373
|
declare function decide(snapshot: EngineSnapshot): ResidencyDecision;
|
|
3383
3374
|
//#endregion
|
|
3384
|
-
export { type AgentJobListener, AgentJobRegistry, type AgentJobRegistryOptions, type AgentJobStatus, type AgentObsStatus, type AgentObservabilityOptions, AgentObservabilityRegistry, type AgentObservation, type AgentObservationMeta, type AgentObservationSnapshot, type AgentRuntime, AgentSession, type AgentSessionEvent, type AgentSessionEventMap, type AgentSessionEventType, type AgentSessionInfo, type AgentSessionJob, type AgentSessionOptions, type AgentSessionSubscriber, type ApplyDiffResult, type ApplyPolicy, type ApplySignals, type ArchiveRecallPort, type AskUserQuestion, type AutonomyLevel, type BackgroundProcess, type BackgroundProcessStatus, type BasePlaneEntry, CAPABILITY_SURFACE_PATTERNS, type Checkpoint, type CheckpointData, type ContextBuildInput, type ContextInjectionPort, type ContextSource, ContextSourceRegistry, DEFAULT_COMPACTION_LOCK_ORPHAN_TIMEOUT_MS, DEFAULT_MAX_AUTO_APPLY_LINES, type
|
|
3375
|
+
export { type AgentJobListener, AgentJobRegistry, type AgentJobRegistryOptions, type AgentJobStatus, type AgentObsStatus, type AgentObservabilityOptions, AgentObservabilityRegistry, type AgentObservation, type AgentObservationMeta, type AgentObservationSnapshot, type AgentRuntime, AgentSession, type AgentSessionEvent, type AgentSessionEventMap, type AgentSessionEventType, type AgentSessionInfo, type AgentSessionJob, type AgentSessionOptions, type AgentSessionSubscriber, type ApplyDiffResult, type ApplyPolicy, type ApplySignals, type ArchiveRecallPort, type AskUserQuestion, type AutonomyLevel, type BackgroundProcess, type BackgroundProcessStatus, type BasePlaneEntry, CAPABILITY_SURFACE_PATTERNS, type Checkpoint, type CheckpointData, type ColdSessionLister, type ContextBuildInput, type ContextInjectionPort, type ContextSource, ContextSourceRegistry, DEFAULT_COMPACTION_LOCK_ORPHAN_TIMEOUT_MS, DEFAULT_MAX_AUTO_APPLY_LINES, type DocSyncPort, ESCALATION_MARKER, EVENT_DOMAIN, type EmitContext, type EngineStoreLocation, type EngineStoreOverrides, type EventDomain, type ExitResult, FORBIDDEN_ZONE_PATTERNS, type FileEntrySnapshot, type FileSnapshot, FleetMonitor, type FleetMonitorOptions, type FleetSample, type GrillAnswer, type GrillQuestion, type GrillRequest, type HostPlaneDraft, type HostPlaneEntry, HostRegistry, type KillOptions, LEVEL_DIVISOR, type LlmEscalationReviewerDeps, type ManagedProcess, type MemoryDeltaPort, MemoryGovernor, type MemoryGovernorOptions, type MemoryPort, type MemoryPressureLevel, type MemorySample, type MemorySubsystem, PanelStateStore, PersistenceSync, type PersistenceSyncDeps, type PlaneEntry, type ProcessCategory, type ProcessFilter, type ProcessLifecycle, type ProcessListener, type ProcessOwner, ProcessRegistry, type ProcessRegistryOptions, ProcessRuntime, type ProcessRuntimeOptions, type ProcessSpawnConfig, type ProcessStatus, type PromptOptions, type PromptRefresh, type PromptSectionDefinition, RUNTIME_DEFAULTS, type RegisterAgentJobInput, type RegisterInput, type RegistrationPlane, type RemoteSessionPoolOptions, type ReplayLevel, type ResidencyDiagnostics, ResidencyGovernor, type ResidencyPressureLevel, type ResolvedSessionConfig, type RestoreMode, type RuntimeOptions, SYSTEM_PROMPT_SECTIONS, type SandboxRunner, type SandboxToolCall, type SandboxToolResult, SandboxUnavailableError, type SemanticReviewer, type SemanticReviewerVerdict, type SessionCompactionLockPort, SessionPool, type SessionPoolOptions, type SessionPorts, type SessionPresetDraft, type SessionPresetEntry, type SessionStableInjectionOptions, type SessionStorageConfig, type StalePlaneEntry, type SystemPromptSectionSpec, TimeTravelController, type TimeTravelDeps, type TodoReminderPort, type TracebackView, type TurnRecord, type Verdict, type WorkspacePresetDraft, type WorkspacePresetEntry, type Worktree, type WriteLeaseManager, applyDiff, applyMemoryTransform, applySectionBudget, attachAgentObserver, buildEngineStores, captureFiles, checkApply, createAgentRuntime, createDefaultContextSourceRegistry, createDocSyncReminderHooks, createEnvironmentContextSource, createInMemorySessionPool, createLlmEscalationReviewer, createMemoryDeltaHooks, createMemoryIndexContextSource, createRemoteSessionPool, createSessionCompactionLock, createSessionStableInjectionHooks, createTodoReminderHooks, createToolHookExecutor, createWorktree, decideApply, decide as decideResidency, defaultMaxToolTurnExtensions, definePromptSection, deriveSessionTitle, diffTouchedPaths, effectiveResidencyBudget, formatDocSyncReminder, getEventDomain, globalAgentJobRegistry, globalAgentObservability, globalProcessRegistry, globalProcessRuntime, globalToolResultStore, hasRepoDrifted, installAgentJobReaper, installExitReaper, installProcessReaper, isEscalationApproval, listWorktreeJobIds, messagesFromSnapshot, parseVerdict, pruneOrphanWorktrees, reconstructMessages, removeWorktree, resolveSessionTitle, resolveTodoContinuationConfig, restoreFiles, revertDiff, touchesCapabilitySurface, touchesForbiddenZone, worktreeDiff };
|
|
3385
3376
|
//# sourceMappingURL=index.d.ts.map
|