@x-otto/runtime 0.0.1-alpha.1 → 0.0.1-alpha.10
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 +4 -3
- package/dist/index.d.ts +433 -69
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,207 @@ 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
5
|
import { InMemorySession, LeaseInspection, Session, SessionEntry, SessionPersistence, SessionSnapshot } from "@x-otto/session";
|
|
6
6
|
import { OttoProcessInfo } from "@x-otto/env";
|
|
7
|
-
import { Agent, AgentEvent, AgentMessage, AgentSessionEvent, AgentSessionEventMap, AgentSessionEventType, AgentSessionSubscriber, AgentTool, ApprovalRisk, AskUserQuestion, ClockPort, DescribeImagesPort, GrillAnswer, GrillQuestion, GrillRequest, MemoryPort, MemoryPort as MemoryPort$1, StreamFunction, StreamRetryConfig, ToolHookExecutor, ToolResult, TraceEvent, TraceRecorder, applyMemoryTransform } from "@x-otto/agent";
|
|
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";
|
|
8
8
|
import * as _$_x_otto_session_contract0 from "@x-otto/session-contract";
|
|
9
9
|
import { ResidencyBudgetConfig, TurnRecord, TurnRecord as TurnRecord$1 } from "@x-otto/session-contract";
|
|
10
10
|
import { ChildProcess, SpawnOptions } from "node:child_process";
|
|
11
11
|
import { Devtools } from "@x-otto/devtools";
|
|
12
12
|
|
|
13
|
+
//#region src/plane/host-registry.d.ts
|
|
14
|
+
type RegistrationPlane = 'host' | 'preset';
|
|
15
|
+
/** 注册条目公共字段(平面无关)。 */
|
|
16
|
+
interface BasePlaneEntry {
|
|
17
|
+
/** 条目唯一 id(格内唯一;插件注册约定 `plugin:<pluginId>` / `waterfall:<timing>`)。 */
|
|
18
|
+
id: string;
|
|
19
|
+
/** 贡献类型标签('plugin' 身份声明 / 'waterfall' 贡献 / 未来轴)。 */
|
|
20
|
+
kind: string;
|
|
21
|
+
/** 贡献载荷(注册者语义自定)。 */
|
|
22
|
+
value: unknown;
|
|
23
|
+
/** 来源插件 id(非插件来源的注册可省略)。 */
|
|
24
|
+
pluginId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* R6':来源插件 manifest 版本(信任绑定版本——插件更新后需重新评估白名单,
|
|
27
|
+
* trust 不跨版本自动存续)。非插件来源注册可省略。
|
|
28
|
+
*/
|
|
29
|
+
pluginVersion?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* host 平面条目草稿(进程级单例)。`plane: 'host'` + `scope: 'process'` 为编译期
|
|
33
|
+
* 字面量——只能传给 HostRegistry.register(),传进任何 PRESET 格注册 API 即编译错误。
|
|
34
|
+
*/
|
|
35
|
+
type HostPlaneDraft = BasePlaneEntry & {
|
|
36
|
+
readonly plane: 'host';
|
|
37
|
+
readonly scope: 'process';
|
|
38
|
+
};
|
|
39
|
+
/** PRESET workspace 格条目草稿——`scope: 'workspace'` 只能传给 workspace 格的注册 API。 */
|
|
40
|
+
type WorkspacePresetDraft = BasePlaneEntry & {
|
|
41
|
+
readonly plane: 'preset';
|
|
42
|
+
readonly scope: 'workspace';
|
|
43
|
+
};
|
|
44
|
+
/** PRESET 会话格条目草稿——`scope: 'session'` 只能传给会话格的注册 API。 */
|
|
45
|
+
type SessionPresetDraft = BasePlaneEntry & {
|
|
46
|
+
readonly plane: 'preset';
|
|
47
|
+
readonly scope: 'session';
|
|
48
|
+
};
|
|
49
|
+
/** 已盖章的 host 平面条目(无附加键)。 */
|
|
50
|
+
interface HostPlaneEntry extends HostPlaneDraft {}
|
|
51
|
+
/** 已盖章的 PRESET workspace 条目——workspaceKey 由格在注册时盖章(调用方不可自报)。 */
|
|
52
|
+
interface WorkspacePresetEntry extends WorkspacePresetDraft {
|
|
53
|
+
/** 所属 workspace key(`ws_<uuid>`)。由格盖章,非调用方自报。 */
|
|
54
|
+
workspaceKey: string;
|
|
55
|
+
}
|
|
56
|
+
/** 已盖章的 PRESET 会话条目——sessionId 由格在注册时盖章(调用方不可自报)。 */
|
|
57
|
+
interface SessionPresetEntry extends SessionPresetDraft {
|
|
58
|
+
/** 所属会话 id。由格盖章,非调用方自报。 */
|
|
59
|
+
sessionId: string;
|
|
60
|
+
}
|
|
61
|
+
type PlaneEntry = HostPlaneEntry | WorkspacePresetEntry | SessionPresetEntry;
|
|
62
|
+
/** 发射端上下文(host 单点发射携带)。缺省字段 = 不匹配对应平面。 */
|
|
63
|
+
interface EmitContext {
|
|
64
|
+
/** 发射时已知的会话 id——会话格条目仅当匹配才可达。 */
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
/** 发射时已知的 workspace key——workspace 格条目仅当匹配才可达。 */
|
|
67
|
+
workspaceKey?: string;
|
|
68
|
+
}
|
|
69
|
+
/** R6' 版本漂移条目(插件更新后残留的旧版本注册,需重新评估)。 */
|
|
70
|
+
interface StalePlaneEntry {
|
|
71
|
+
entry: PlaneEntry;
|
|
72
|
+
/** 注册时快照的版本。 */
|
|
73
|
+
registeredVersion: string | undefined;
|
|
74
|
+
/** 插件当前 manifest 版本(可能缺省——manifest 无版本字段)。 */
|
|
75
|
+
currentVersion: string | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** PRESET workspace 格(注册 + 列表 + 清理)。 */
|
|
78
|
+
declare class WorkspacePresetGrid {
|
|
79
|
+
/** workspace key(`ws_<uuid>`)——构造时由 HostRegistry.workspace() 传入。 */
|
|
80
|
+
readonly key: string;
|
|
81
|
+
private readonly entries;
|
|
82
|
+
/** 已 dispose(格关闭后拒绝新注册,fail-closed)。 */
|
|
83
|
+
private disposed;
|
|
84
|
+
constructor(/** workspace key(`ws_<uuid>`)——构造时由 HostRegistry.workspace() 传入。 */
|
|
85
|
+
|
|
86
|
+
key: string);
|
|
87
|
+
/**
|
|
88
|
+
* 注册一条 workspace 级 PRESET 贡献。同 id 重复注册 = 整体替换(R6':新评估覆盖
|
|
89
|
+
* 旧评估,不继承——插件更新后经 unregister→register 全量替换)。
|
|
90
|
+
*/
|
|
91
|
+
register(draft: WorkspacePresetDraft): WorkspacePresetEntry;
|
|
92
|
+
unregister(id: string): boolean;
|
|
93
|
+
/** 撤销某插件的全部条目(pluginId 匹配)。返回撤销条数。 */
|
|
94
|
+
unregisterByPlugin(pluginId: string): number;
|
|
95
|
+
list(): readonly WorkspacePresetEntry[];
|
|
96
|
+
/** workspace 关闭 → 清空本格。幂等。 */
|
|
97
|
+
dispose(): void;
|
|
98
|
+
}
|
|
99
|
+
/** PRESET 会话格(注册 + 列表 + 清理)。 */
|
|
100
|
+
declare class SessionPresetGrid {
|
|
101
|
+
readonly sessionId: string;
|
|
102
|
+
private readonly entries;
|
|
103
|
+
private disposed;
|
|
104
|
+
constructor(sessionId: string);
|
|
105
|
+
register(draft: SessionPresetDraft): SessionPresetEntry;
|
|
106
|
+
unregister(id: string): boolean;
|
|
107
|
+
unregisterByPlugin(pluginId: string): number;
|
|
108
|
+
list(): readonly SessionPresetEntry[];
|
|
109
|
+
/** 会话 dispose → 清空本格。幂等。 */
|
|
110
|
+
dispose(): void;
|
|
111
|
+
}
|
|
112
|
+
/** PRESET workspace 作用域句柄——`workspace.preset.register()`(RFC-327 D2 API 形状)。 */
|
|
113
|
+
declare class WorkspacePresetScope {
|
|
114
|
+
readonly workspaceKey: string;
|
|
115
|
+
/**
|
|
116
|
+
* PRESET workspace 格。注册 API 形状 = `workspace.preset.register(draft)`。
|
|
117
|
+
* 语义同 WorkspacePresetGrid(注册/撤销/列表/清理),随 workspace 生命周期。
|
|
118
|
+
*/
|
|
119
|
+
readonly preset: WorkspacePresetGrid;
|
|
120
|
+
constructor(workspaceKey: string);
|
|
121
|
+
/** workspace 关闭 → 清 workspace 格(R2':HOST 桶不受影响)。幂等。 */
|
|
122
|
+
dispose(): void;
|
|
123
|
+
}
|
|
124
|
+
/** PRESET 会话作用域句柄——`session.preset.register()`(RFC-327 D2 API 形状)。 */
|
|
125
|
+
declare class SessionPresetScope {
|
|
126
|
+
readonly sessionId: string;
|
|
127
|
+
/**
|
|
128
|
+
* PRESET 会话格。注册 API 形状 = `session.preset.register(draft)`。
|
|
129
|
+
* 语义同 SessionPresetGrid(注册/撤销/列表/清理),随会话生命周期。
|
|
130
|
+
*/
|
|
131
|
+
readonly preset: SessionPresetGrid;
|
|
132
|
+
constructor(sessionId: string);
|
|
133
|
+
/** 会话 dispose → 清会话格(R2':HOST 桶与 workspace 格不受影响)。幂等。 */
|
|
134
|
+
dispose(): void;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* HostRegistry —— 进程级单例注册表(RFC-327 修订 D2,T-327-M2-01/02)。
|
|
138
|
+
*
|
|
139
|
+
* 三桶:host 平面(进程级单例)+ PRESET workspace 格(按 workspaceKey)+ PRESET
|
|
140
|
+
* 会话格(按 sessionId)。生命周期=进程;dispose() 清空全部。
|
|
141
|
+
*
|
|
142
|
+
* 编译期跨平面拒绝(R2'):register 只收 HostPlaneDraft(plane:'host'),
|
|
143
|
+
* workspace/session 格的注册 API 只收各自字面量草稿——跨平面注册在类型层即失败。
|
|
144
|
+
*/
|
|
145
|
+
declare class HostRegistry {
|
|
146
|
+
private readonly hostEntries;
|
|
147
|
+
private readonly workspaceScopes;
|
|
148
|
+
private readonly sessionScopes;
|
|
149
|
+
private disposed;
|
|
150
|
+
private ensureNotDisposed;
|
|
151
|
+
/** host 平面注册(进程级单例)。`host.register()`(RFC-327 D2 API 形状)。 */
|
|
152
|
+
register(draft: HostPlaneDraft): HostPlaneEntry;
|
|
153
|
+
unregister(id: string): boolean;
|
|
154
|
+
/** 撤销某插件在 host 平面的全部条目。返回撤销条数。 */
|
|
155
|
+
unregisterByPlugin(pluginId: string): number;
|
|
156
|
+
/** host 平面条目(进程级单例,不随任何会话/workspace 清理)。 */
|
|
157
|
+
list(): readonly HostPlaneEntry[];
|
|
158
|
+
/**
|
|
159
|
+
* PRESET workspace 格句柄(ensure 语义——workspace 挂载/首次注册时建格,幂等)。
|
|
160
|
+
* 注册 API 形状 = `workspace.preset.register(draft)`。
|
|
161
|
+
*/
|
|
162
|
+
workspace(workspaceKey: string): WorkspacePresetScope;
|
|
163
|
+
/**
|
|
164
|
+
* PRESET 会话格句柄(ensure 语义——会话创建时派生会话格,幂等)。
|
|
165
|
+
* 注册 API 形状 = `session.preset.register(draft)`。
|
|
166
|
+
*/
|
|
167
|
+
session(sessionId: string): SessionPresetScope;
|
|
168
|
+
/** workspace 关闭 → 清 workspace 格(不重建;不存在即 no-op)。 */
|
|
169
|
+
disposeWorkspaceGrid(workspaceKey: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* RFC-327 修订 D2(M2,应用点 B 建议修订):把 `fromKey` 格的条目迁移到 `toKey` 格。
|
|
172
|
+
*
|
|
173
|
+
* 场景:pendingWorkspaceInit(交互态首次打开待信任确认)路径下插件 reload 先于
|
|
174
|
+
* workspaceRef 就位,PMM 用 DEFAULT_WORKSPACE_KEY('default')兜底注册;真实 key
|
|
175
|
+
* 就位后(completeWorkspaceDependentStartup)必须把 default 格条目迁到真实格,
|
|
176
|
+
* 否则两格并存、发射端按真实 key 路由查不到插件条目。
|
|
177
|
+
*
|
|
178
|
+
* 语义:条目按 id 迁移(整体搬,不重新盖章之外不改变语义);fromKey 格迁移后清空
|
|
179
|
+
* 且 dispose(fail-closed,防后续误注册到已废弃格)。fromKey 不存在 / toKey===fromKey
|
|
180
|
+
* 均为 no-op。只迁移 workspace 级条目(host/会话格不涉及)。
|
|
181
|
+
*/
|
|
182
|
+
migrateWorkspaceGrid(fromKey: string, toKey: string): void;
|
|
183
|
+
/** 会话 dispose → 清会话格(不重建;不存在即 no-op)。 */
|
|
184
|
+
disposeSessionGrid(sessionId: string): void;
|
|
185
|
+
/** 撤销某插件在全部平面(host + 全部 workspace 格 + 全部会话格)的条目。返回撤销条数。 */
|
|
186
|
+
unregisterByPluginEverywhere(pluginId: string): number;
|
|
187
|
+
/**
|
|
188
|
+
* R6' 版本漂移检出:返回 pluginId 名下所有注册版本 ≠ 当前版本的条目。
|
|
189
|
+
* 插件更新后,正常 reload 走 unregister→register 全量替换;本方法兜底检出
|
|
190
|
+
* 「旧版本条目残留」(脏插件/撤销失败等异常路径)——调用方应据此重新评估
|
|
191
|
+
* 白名单(trust 不跨版本自动存续)。`currentVersion` 为 undefined(manifest
|
|
192
|
+
* 无版本)时,无版本条目视为一致、带版本条目视为漂移(需重新评估)。
|
|
193
|
+
*/
|
|
194
|
+
revalidatePlugin(pluginId: string, currentVersion: string | undefined): StalePlaneEntry[];
|
|
195
|
+
/**
|
|
196
|
+
* 发射端路由(host 单点发射携带上下文)——按上下文过滤 PRESET 注册:
|
|
197
|
+
* host 平面条目恒达(进程级单例);
|
|
198
|
+
* workspace 格条目仅当 ctx.workspaceKey 匹配;
|
|
199
|
+
* 会话格条目仅当 ctx.sessionId 匹配(s1 事件不达 s2 的 PRESET)。
|
|
200
|
+
*/
|
|
201
|
+
resolveForEmit(ctx: EmitContext): readonly PlaneEntry[];
|
|
202
|
+
/** 全部平面的全部条目(诊断/审计用)。 */
|
|
203
|
+
listAll(): readonly PlaneEntry[];
|
|
204
|
+
/** 进程生命周期结束 → 清空全部平面(host + workspace 格 + 会话格)。幂等。 */
|
|
205
|
+
dispose(): void;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
13
208
|
//#region src/context-source.d.ts
|
|
14
209
|
interface ContextSource {
|
|
15
210
|
/** 本源的唯一标识。重复注册→覆盖前一次同 id 源。 */
|
|
@@ -57,6 +252,10 @@ declare class ContextSourceRegistry {
|
|
|
57
252
|
sealAndBuildHooks(workspaceDir?: string, memory?: ContextBuildInput['memory']): HookSpec[];
|
|
58
253
|
}
|
|
59
254
|
//#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
|
|
60
259
|
//#region src/context-sources/memory-delta.d.ts
|
|
61
260
|
/**
|
|
62
261
|
* memory-delta(#3 volatile memory delta)
|
|
@@ -287,7 +486,19 @@ interface AgentSessionOptions {
|
|
|
287
486
|
nondetFlush?: () => void;
|
|
288
487
|
clock?: ClockPort;
|
|
289
488
|
depth?: number;
|
|
489
|
+
/**
|
|
490
|
+
* RFC-371 M-A:父任务锚点(任务树语义)。orchestrator 委派子会话时注入
|
|
491
|
+
* `RunSessionOptions.parentTaskId`,透传 Agent → ToolExecutor → 工具上下文 →
|
|
492
|
+
* task_delegate/agent_call → orchestrator per-parent fan-out 闸。undefined = root 层。
|
|
493
|
+
*/
|
|
494
|
+
parentTaskId?: string;
|
|
290
495
|
interactive?: boolean;
|
|
496
|
+
/**
|
|
497
|
+
* RFC-380 T4:LLM 语义审批层(opt-in)。仅升级审批(sandbox-denied escalate ask)
|
|
498
|
+
* 且配置时生效;allow/deny 自动裁决(宿主侧需消费 approval.required 的
|
|
499
|
+
* semanticVerdict 记命令 bypass),abstain/未配置 → 既有用户弹窗流程。
|
|
500
|
+
*/
|
|
501
|
+
semanticReviewer?: SemanticReviewer;
|
|
291
502
|
/**
|
|
292
503
|
* 是否在 `/resume` 列表中可见(缺省 = 可见)。`false` 用于 headless 一次性内部会话
|
|
293
504
|
* (`otto --print/--json`)——照常落盘(sessionId/trace 有外部契约消费方),但不进列表。
|
|
@@ -412,6 +623,13 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
412
623
|
systemTail?: string[];
|
|
413
624
|
agentName: string;
|
|
414
625
|
depth: number;
|
|
626
|
+
/**
|
|
627
|
+
* RFC-371 M-A:父任务锚点(透传面)。orchestrator 委派子会话时注入
|
|
628
|
+
* `runOptions.parentTaskId`,Agent 构造经 `AgentConfig.parentTaskId` 透传给
|
|
629
|
+
* ToolExecutor——task_delegate/agent_call 的 per-parent fan-out 闸依赖此字段。
|
|
630
|
+
* undefined = root 层(顶层用户会话),不受 fan-out 闸约束。
|
|
631
|
+
*/
|
|
632
|
+
readonly parentTaskId?: string;
|
|
415
633
|
/**
|
|
416
634
|
* orchestrator ephemeral 委派子会话标记 —— 契约上不落盘(见
|
|
417
635
|
* `PersistenceSync.isTransient`)、不进 `/resume` 列表。构造期固定,运行中不变。
|
|
@@ -441,7 +659,9 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
441
659
|
/** RFC-145 D3:nondet batch 冲洗回调。 */
|
|
442
660
|
private readonly nondetFlush?;
|
|
443
661
|
private readonly clock?;
|
|
444
|
-
/** RFC-337 D2:steer 消息 id 单调计数器(会话内唯一,供 ESC 撤回按序移除)。
|
|
662
|
+
/** RFC-337 D2:steer 消息 id 单调计数器(会话内唯一,供 ESC 撤回按序移除)。
|
|
663
|
+
* RFC-372 S7:改为 `{ value: number }` 对象——steer 逻辑提取到 agent-session-steer.ts
|
|
664
|
+
* 后需经引用传递(number 是值类型,函数内 ++ 不会回传)。 */
|
|
445
665
|
private steerSeq;
|
|
446
666
|
private readonly persistence;
|
|
447
667
|
/**
|
|
@@ -491,6 +711,8 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
491
711
|
* task-runner 在跑 task_delegate/fork 子会话时据此把运行态接入 globalAgentObservability。
|
|
492
712
|
*/
|
|
493
713
|
get coreAgent(): Agent;
|
|
714
|
+
/** RFC-372 S7:steer 集群的依赖面(供 agent-session-steer.ts 消费)。 */
|
|
715
|
+
private get steerDeps();
|
|
494
716
|
get isExecuting(): boolean;
|
|
495
717
|
/**
|
|
496
718
|
* prompt 全生命周期忙判定。isExecuting 只覆盖 streaming/tool_executing,
|
|
@@ -559,8 +781,13 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
559
781
|
* hadToolActivity:本轮是否有真实工具调用产出(assistant tool_call 消息),供闸门
|
|
560
782
|
* 无进展判定区分"零动作卡死"(放行)与"有产出但没同步 todo 状态"(定向续跑一次)。
|
|
561
783
|
* images(RFC-111 D4b):仅首轮(外层 `prompt()` 调用)传入,todo 续跑等内部触发轮
|
|
562
|
-
* 不重复携带图片——避免同一张图片在续跑轮里被重复注入上下文。
|
|
784
|
+
* 不重复携带图片——避免同一张图片在续跑轮里被重复注入上下文。
|
|
785
|
+
*
|
|
786
|
+
* RFC-372 M3:实现提取到 agent-session-prompt-round.ts(runPromptRound 函数),
|
|
787
|
+
* 此处经 promptRoundHost getter 桥接全部依赖。纯结构重构,行为零变化。 */
|
|
563
788
|
private runPromptRound;
|
|
789
|
+
/** RFC-372 M3:runPromptRound 的依赖面(供 agent-session-prompt-round.ts 消费)。 */
|
|
790
|
+
private get promptRoundHost();
|
|
564
791
|
/**
|
|
565
792
|
* RFC-337 D2:注入一条 steer 消息并返回其稳定 `id`(供 cli 侧持有以便 ESC 撤回)。
|
|
566
793
|
*
|
|
@@ -571,11 +798,6 @@ declare class AgentSession extends EventBus<AgentSessionEventMap> {
|
|
|
571
798
|
steer(text: string): {
|
|
572
799
|
id: string;
|
|
573
800
|
};
|
|
574
|
-
/**
|
|
575
|
-
* RFC-337 D2:按 id 移除一条尚未被模型消费的 steer 消息,返回是否命中。
|
|
576
|
-
* 未命中(已被 `drainSteeringQueue` 交付进 LLM 上下文)时返回 `false`——调用方据此退化
|
|
577
|
-
* 为「中止整回合」(见 RFC-337 §D3)。转调 `Agent.removeSteer`,只操作内存态队列。
|
|
578
|
-
*/
|
|
579
801
|
removeSteer(id: string): boolean;
|
|
580
802
|
followUp(text: string): void;
|
|
581
803
|
abort(): void;
|
|
@@ -975,6 +1197,15 @@ interface SessionPoolOptions {
|
|
|
975
1197
|
* 确定性时钟端口。缺省=真实系统时钟(行为不变);replay 由 trace 回灌。
|
|
976
1198
|
*/
|
|
977
1199
|
clock?: ClockPort;
|
|
1200
|
+
/**
|
|
1201
|
+
* 确定性 id 生成端口(M-2)。缺省=systemId(crypto.randomUUID);replay/测试注入固定序列。
|
|
1202
|
+
* 透传给 InMemorySession 与 fork 产物。
|
|
1203
|
+
*/
|
|
1204
|
+
idGen?: IdPort;
|
|
1205
|
+
/**
|
|
1206
|
+
* 确定性随机端口(M-2)。缺省=systemRandom(Math.random);replay 由 trace 回灌。
|
|
1207
|
+
*/
|
|
1208
|
+
randomGen?: RandomPort;
|
|
978
1209
|
/**
|
|
979
1210
|
* 仅用于 restore / restoreAll 场景。
|
|
980
1211
|
* 正常 createSession 路径必须传入完整 ResolvedSessionConfig,不使用此字段。
|
|
@@ -994,6 +1225,13 @@ interface SessionPoolOptions {
|
|
|
994
1225
|
residencyGovernor?: ResidencyGovernor;
|
|
995
1226
|
/** RFC-323 M4:驻留预算运行时配置 getter(settings 注入,透传给 PersistenceSync)。 */
|
|
996
1227
|
getResidencyConfig?: () => _$_x_otto_session_contract0.ResidencyBudgetConfig | undefined;
|
|
1228
|
+
/**
|
|
1229
|
+
* RFC-327 修订 D2(M2):双平面注册边界——进程级 HostRegistry(可选注入)。
|
|
1230
|
+
* 注入后会话在进池(create/fork/restore 三个装池点)时派生 PRESET 会话格,
|
|
1231
|
+
* 出池(remove/idle 驱逐/LRU 驱逐/池 dispose)时清理会话格。未注入 = 不派生
|
|
1232
|
+
* (宿主不接双平面即零影响)。
|
|
1233
|
+
*/
|
|
1234
|
+
planeRegistry?: HostRegistry;
|
|
997
1235
|
/**
|
|
998
1236
|
* RFC-146:本地高效冷会话枚举策略(可选注入)。仅本地 SQLite 后端在
|
|
999
1237
|
* `session-pool-factory.ts` 构造期注入(内部持有 `SqliteSessionRepository`,
|
|
@@ -1057,6 +1295,26 @@ declare class SessionPool {
|
|
|
1057
1295
|
private readonly panelStateStoreRef;
|
|
1058
1296
|
private readonly sessions;
|
|
1059
1297
|
private readonly configs;
|
|
1298
|
+
/**
|
|
1299
|
+
* 驻留时钟(in-memory 池的"这个会话是何时被装进池子的"),**与 `lastActiveAt` 分离**。
|
|
1300
|
+
*
|
|
1301
|
+
* 背景(/resume 时间戳全变"刚刚"的根因):`restore`/`restoreAll` 此前用
|
|
1302
|
+
* `{ ...snapshot.metadata, lastActiveAt: Date.now() }` 装载快照,把"恢复"当成了"活动"。
|
|
1303
|
+
* 该值随后被 `save()` 的 `touchSession(..., snapshot.metadata.lastActiveAt, ...)` 原样
|
|
1304
|
+
* 写回 DB —— 每次启动 `restoreAll` 恢复的会话(池容量 50)都被盖成当前时间且**永久落盘**,
|
|
1305
|
+
* 于是 `/resume` 列表里所有历史会话都显示成"N 秒前",真实活动时间被不可逆地抹掉,
|
|
1306
|
+
* 同时按 `lastActiveAt` 降序的排序也彻底失去意义(全部并列在同一时刻)。
|
|
1307
|
+
*
|
|
1308
|
+
* 但那个 `Date.now()` 并非笔误:它保护刚恢复的会话不被 `collectIdle` 立刻自食
|
|
1309
|
+
* (快照的 `lastActiveAt` 可能已是 99 小时前,一装载就超 idleTimeout,见
|
|
1310
|
+
* m17-session-persistence-e2e "M18-PR-03:restore 刷新 lastActiveAt=now(恢复不自食)")。
|
|
1311
|
+
*
|
|
1312
|
+
* 所以正确的切分是:**驱逐判据 = max(进池时刻, 真实活动时间),展示与排序只看
|
|
1313
|
+
* `lastActiveAt`(真实活动时间、落盘)**。本时钟只记"何时进的池"(create/fork/restore
|
|
1314
|
+
* 三个装池点登记,出池时清除),活动侧的续期由 `lastActiveAt` 天然承担——两者如何
|
|
1315
|
+
* 合成见 `residencySince`。本时钟是进程内易失状态,永不落盘,故不会污染 /resume。
|
|
1316
|
+
*/
|
|
1317
|
+
private readonly residencyClock;
|
|
1060
1318
|
private readonly persistence;
|
|
1061
1319
|
private readonly maxSessions;
|
|
1062
1320
|
private readonly idleTimeoutMs;
|
|
@@ -1070,8 +1328,12 @@ declare class SessionPool {
|
|
|
1070
1328
|
private readonly traceStore?;
|
|
1071
1329
|
private readonly checkpointStore?;
|
|
1072
1330
|
private readonly clock?;
|
|
1331
|
+
private readonly idGen;
|
|
1332
|
+
private readonly randomGen;
|
|
1073
1333
|
private readonly residencyGovernor?;
|
|
1074
1334
|
private readonly getResidencyConfig?;
|
|
1335
|
+
/** RFC-327 修订 D2(M2):双平面注册边界——会话格派生/清理的宿主注册表(可选)。 */
|
|
1336
|
+
private readonly planeRegistry?;
|
|
1075
1337
|
private readonly configProvider?;
|
|
1076
1338
|
/** RFC-146:本地高效冷会话枚举策略(可选,见 SessionPoolOptions.listColdSessionsOverride)。 */
|
|
1077
1339
|
private readonly listColdSessionsOverride?;
|
|
@@ -1112,6 +1374,31 @@ declare class SessionPool {
|
|
|
1112
1374
|
/** 会话级「账号可用模型」读写(同 permissionAlwaysAllow 持久化语义)。 */
|
|
1113
1375
|
getSessionAvailableModels(id: string): string[];
|
|
1114
1376
|
setSessionAvailableModels(id: string, models: readonly string[]): void;
|
|
1377
|
+
/**
|
|
1378
|
+
* 登记"会话进池时刻"(create/fork/restore 三个装池点)。纯进程内状态,永不落盘,
|
|
1379
|
+
* 不会污染 `/resume` 展示的 `lastActiveAt`。活动侧续期见 `residencySince`。
|
|
1380
|
+
*
|
|
1381
|
+
* RFC-327 修订 D2(M2):同一装池点是会话格的派生点——派生 PRESET 会话格
|
|
1382
|
+
* (`session.preset.register()` 的目标)。会话级贡献随会话 dispose 清理
|
|
1383
|
+
* (见 clearSessionPlaneGrid 在四个出池点的调用)。
|
|
1384
|
+
*/
|
|
1385
|
+
private admitToResidency;
|
|
1386
|
+
/** RFC-327 修订 D2(M2):会话出池 → 清理 PRESET 会话格(不重建;未派生即 no-op)。 */
|
|
1387
|
+
private clearSessionPlaneGrid;
|
|
1388
|
+
/**
|
|
1389
|
+
* 驱逐判据用的"最近驻留活动时刻" = **进池时刻与真实活动时间中较新的那个**。
|
|
1390
|
+
*
|
|
1391
|
+
* 两个来源各自只能守住一半,必须取 max:
|
|
1392
|
+
* - 只读 `lastActiveAt`:刚恢复的会话带着快照里可能 99 小时前的时间戳,一进池就超
|
|
1393
|
+
* idleTimeout 被自食(旧 M18-PR-03 要防的正是这个)。
|
|
1394
|
+
* - 只读驻留时钟:它仅在装池时登记、不随对话续期,判据会退化成"进池后过了多久"——
|
|
1395
|
+
* 用户连用两小时的会话反而因"进池早"被当成 idle 驱逐,且 `collectIdle` 并不豁免
|
|
1396
|
+
* `activeSessionId`,连当前正在用的会话都可能被踢出池。
|
|
1397
|
+
*
|
|
1398
|
+
* 取较新值后:恢复瞬间由进池时刻托底,此后每次真实活动经 `lastActiveAt` 自然续期,
|
|
1399
|
+
* 而真正长期无活动的会话两个值都旧,仍会被正常驱逐(不会变成"永不驱逐")。
|
|
1400
|
+
*/
|
|
1401
|
+
private residencySince;
|
|
1115
1402
|
/**
|
|
1116
1403
|
* 保持既有 private 外观(createSession/fork/restore 调用点不变)。
|
|
1117
1404
|
*/
|
|
@@ -1202,15 +1489,15 @@ declare class SessionPool {
|
|
|
1202
1489
|
* 不阻塞会话删除本身)。
|
|
1203
1490
|
*/
|
|
1204
1491
|
private clearSessionStores;
|
|
1205
|
-
/**
|
|
1206
|
-
* fork 直接复用 source session 自身的已解析配置,
|
|
1207
|
-
* 消息通过复制 snapshot entries 完整迁移。
|
|
1208
|
-
*/
|
|
1209
1492
|
/**
|
|
1210
1493
|
* RFC-160 D3/D4:出口 hydrate(fork 用)。无剥离态直通;有剥离态且持久层具备能力则回填;
|
|
1211
1494
|
* 能力缺席 → 断言炸(接线遗漏立即暴露,绝不把剥离态固化为新会话正文)。
|
|
1212
1495
|
*/
|
|
1213
1496
|
private ensureEntriesHydrated;
|
|
1497
|
+
/**
|
|
1498
|
+
* fork 直接复用 source session 自身的已解析配置,
|
|
1499
|
+
* 消息通过复制 snapshot entries 完整迁移。
|
|
1500
|
+
*/
|
|
1214
1501
|
forkSession(sourceId: string, newId?: string): Promise<AgentSession | undefined>;
|
|
1215
1502
|
save(id: string): Promise<void>;
|
|
1216
1503
|
saveAll(): Promise<void>;
|
|
@@ -1350,6 +1637,13 @@ interface RuntimeOptions {
|
|
|
1350
1637
|
residencyGovernor?: ResidencyGovernor;
|
|
1351
1638
|
/** RFC-323 M4:驻留预算运行时配置 getter(settings 注入透传)。 */
|
|
1352
1639
|
getResidencyConfig?: () => _$_x_otto_session_contract0.ResidencyBudgetConfig | undefined;
|
|
1640
|
+
/**
|
|
1641
|
+
* RFC-327 修订 D2(M2):双平面注册边界——进程级 HostRegistry(可选注入)。
|
|
1642
|
+
* 注入后会话池在会话创建/fork/restore 时派生 PRESET 会话格,会话移除/驱逐/池
|
|
1643
|
+
* dispose 时清理会话格(对齐「会话创建派生会话格、会话 dispose 清会话格」生命周期)。
|
|
1644
|
+
* 未注入 = 会话格不派生(行为不变,宿主不接双平面即零影响)。
|
|
1645
|
+
*/
|
|
1646
|
+
planeRegistry?: HostRegistry;
|
|
1353
1647
|
}
|
|
1354
1648
|
interface AgentRuntime {
|
|
1355
1649
|
/** 统一派生入口:子 runtime / 宿主 / swarm / task-runner 皆经此(§4-11)。 */
|
|
@@ -1593,11 +1887,6 @@ declare class MemoryGovernor {
|
|
|
1593
1887
|
constructor(options?: MemoryGovernorOptions);
|
|
1594
1888
|
/** 当前分级(供外部只读查询,如 TUI 状态展示)。 */
|
|
1595
1889
|
get currentLevel(): MemoryPressureLevel;
|
|
1596
|
-
/**
|
|
1597
|
-
* 晚绑定 onWarning/onCritical/onCriticalDuringGrace(App 构造时活跃 session 尚不存在,
|
|
1598
|
-
* M2/M3 在 session 就绪后调用注入)。对齐 `App.setScheduleService` 的晚绑定模式,
|
|
1599
|
-
* 非构造期可选依赖。
|
|
1600
|
-
*/
|
|
1601
1890
|
/**
|
|
1602
1891
|
* 合并式更新(每个字段独立覆盖,未传的字段保留原值)——RFC-115 追补:`app.ts`
|
|
1603
1892
|
* 启动期注入 `onSample`(trace 落盘)后,`interactive.ts` 会话就绪时再调用一次
|
|
@@ -2021,6 +2310,12 @@ interface ApplyDiffResult {
|
|
|
2021
2310
|
* apply 可能出乎意料地冲突/无冲突",不用来拒绝 apply。
|
|
2022
2311
|
*/
|
|
2023
2312
|
declare function hasRepoDrifted(repoRoot: string, base: string): boolean;
|
|
2313
|
+
/**
|
|
2314
|
+
* 纯预检:diff 能否干净 apply 到主仓工作区(`git apply --check`,无任何副作用)。
|
|
2315
|
+
* 供 governance/apply-policy 的 `conflict` 信号使用——在真正 `applyDiff` 之前判定"是否可干净
|
|
2316
|
+
* 落地"。空 diff 视为干净。true=无冲突可落地;false=有冲突/无法判定(交给 applyDiff 兜底)。
|
|
2317
|
+
*/
|
|
2318
|
+
declare function checkApply(repoRoot: string, diff: string): boolean;
|
|
2024
2319
|
/**
|
|
2025
2320
|
* 把作业 diff apply 到主仓工作区。**check-first,不强改**:先 `git apply --check` 验证能否干净
|
|
2026
2321
|
* 应用——能才真 apply;不能(主仓漂移/冲突)则返回 applied=false + conflictPaths,**绝不**往主树
|
|
@@ -2555,9 +2850,9 @@ declare function createDocSyncReminderHooks(port: DocSyncPort, priority?: 64): H
|
|
|
2555
2850
|
*
|
|
2556
2851
|
* 放在 @x-otto/runtime(coding 依赖 runtime、反向不依赖):coding 侧 hook 经 `@x-otto/runtime` import。
|
|
2557
2852
|
* 注:本表是**排序权威**(方案 H:section 仍由各自 hook 自注册,priority 数字降级为对本表的引用);
|
|
2558
|
-
* 不强行把 `SYSTEM_PROMPT_SECTIONS` 各 section 物理并入单一 registry
|
|
2853
|
+
* 不强行把 `SYSTEM_PROMPT_SECTIONS` 各 section 物理并入单一 registry(那超出外科尺度、非目标)。
|
|
2559
2854
|
* section 数量以该常量的字段数为准,不在本段注释里重复写死具体数字(history: 建表时 7 个,
|
|
2560
|
-
* 后追加 docSyncReminder 成 8
|
|
2855
|
+
* 后追加 docSyncReminder 成 8 个,又补 skillLoopGuidance 成 9 个——写死数字会重犯本次发现的漂移)。
|
|
2561
2856
|
*/
|
|
2562
2857
|
type SystemPromptLane = 'stable' | 'volatile';
|
|
2563
2858
|
interface SystemPromptSectionSpec {
|
|
@@ -2565,12 +2860,20 @@ interface SystemPromptSectionSpec {
|
|
|
2565
2860
|
readonly name: string;
|
|
2566
2861
|
readonly priority: number;
|
|
2567
2862
|
readonly lane: SystemPromptLane;
|
|
2863
|
+
/**
|
|
2864
|
+
* RFC-374 M3:本 section 的注入字节硬顶(UTF-8)。注入点经
|
|
2865
|
+
* `applySectionBudget` 统一裁剪——预算只此一处声明,各注入点不持局部常量。
|
|
2866
|
+
* 取值原则:明显高于常态内容(防御失控注入而非改变正常行为),
|
|
2867
|
+
* 需要收紧时只改本表。
|
|
2868
|
+
*/
|
|
2869
|
+
readonly budgetBytes: number;
|
|
2568
2870
|
}
|
|
2569
2871
|
declare const SYSTEM_PROMPT_SECTIONS: {
|
|
2570
2872
|
readonly toolGuidance: {
|
|
2571
2873
|
readonly name: "tool-guidance-injection";
|
|
2572
2874
|
readonly priority: 20;
|
|
2573
2875
|
readonly lane: "stable";
|
|
2876
|
+
readonly budgetBytes: 20000;
|
|
2574
2877
|
};
|
|
2575
2878
|
/**
|
|
2576
2879
|
* RFC-318 D7:三分流判别(缺工具 / 流程重复 / 其余)。紧跟 toolGuidance——它是对
|
|
@@ -2580,43 +2883,83 @@ declare const SYSTEM_PROMPT_SECTIONS: {
|
|
|
2580
2883
|
readonly name: "skill-loop-guidance-injection";
|
|
2581
2884
|
readonly priority: 21;
|
|
2582
2885
|
readonly lane: "stable";
|
|
2886
|
+
readonly budgetBytes: 2000;
|
|
2583
2887
|
};
|
|
2584
2888
|
readonly environment: {
|
|
2585
2889
|
readonly name: "runtime:environment";
|
|
2586
2890
|
readonly priority: 25;
|
|
2587
2891
|
readonly lane: "stable";
|
|
2892
|
+
readonly budgetBytes: 8000;
|
|
2588
2893
|
};
|
|
2589
2894
|
readonly memoryIndex: {
|
|
2590
2895
|
readonly name: "runtime:memory-index";
|
|
2591
2896
|
readonly priority: 35;
|
|
2592
2897
|
readonly lane: "stable";
|
|
2898
|
+
readonly budgetBytes: 24000;
|
|
2593
2899
|
};
|
|
2594
2900
|
readonly skillCatalog: {
|
|
2595
2901
|
readonly name: "skill-catalog-injection";
|
|
2596
2902
|
readonly priority: 38;
|
|
2597
2903
|
readonly lane: "stable";
|
|
2904
|
+
readonly budgetBytes: 12000;
|
|
2598
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 预算约束。 */
|
|
2599
2909
|
readonly lesson: {
|
|
2600
2910
|
readonly name: "lesson-injection";
|
|
2601
2911
|
readonly priority: 40;
|
|
2602
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;
|
|
2603
2932
|
};
|
|
2604
2933
|
readonly memoryDelta: {
|
|
2605
2934
|
readonly name: "memory-delta-injection";
|
|
2606
2935
|
readonly priority: 60;
|
|
2607
2936
|
readonly lane: "volatile";
|
|
2937
|
+
readonly budgetBytes: 8000;
|
|
2608
2938
|
};
|
|
2609
2939
|
readonly todoReminder: {
|
|
2610
2940
|
readonly name: "todo-reminder-injection";
|
|
2611
2941
|
readonly priority: 62;
|
|
2612
2942
|
readonly lane: "volatile";
|
|
2943
|
+
readonly budgetBytes: 4000;
|
|
2613
2944
|
};
|
|
2614
2945
|
readonly docSyncReminder: {
|
|
2615
2946
|
readonly name: "doc-sync-reminder-injection";
|
|
2616
2947
|
readonly priority: 64;
|
|
2617
2948
|
readonly lane: "volatile";
|
|
2949
|
+
readonly budgetBytes: 4000;
|
|
2618
2950
|
};
|
|
2619
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;
|
|
2620
2963
|
//#endregion
|
|
2621
2964
|
//#region src/session-stable.d.ts
|
|
2622
2965
|
interface SessionStableInjectionOptions {
|
|
@@ -2627,6 +2970,18 @@ interface SessionStableInjectionOptions {
|
|
|
2627
2970
|
}
|
|
2628
2971
|
declare function createSessionStableInjectionHooks(options: SessionStableInjectionOptions): HookSpec[];
|
|
2629
2972
|
//#endregion
|
|
2973
|
+
//#region src/session/tool-result-store-global.d.ts
|
|
2974
|
+
/**
|
|
2975
|
+
* tool-result-store-global.ts — RFC-093:ToolResultStore 全局单例
|
|
2976
|
+
*
|
|
2977
|
+
* AgentSession 构造 spill 闭包时引用。懒初始化(首次 spill 时基于 cwd 解析 .otto 目录)——
|
|
2978
|
+
* 避免模块加载期做 fs 探测。
|
|
2979
|
+
*/
|
|
2980
|
+
declare const globalToolResultStore: {
|
|
2981
|
+
spill(sessionId: string, toolCallId: string, text: string): Promise<string | undefined>;
|
|
2982
|
+
cleanupSession(sessionId: string): Promise<void>;
|
|
2983
|
+
};
|
|
2984
|
+
//#endregion
|
|
2630
2985
|
//#region src/session/derive-title.d.ts
|
|
2631
2986
|
/**
|
|
2632
2987
|
* 从会话消息列表中派生标题(RFC-030 P1)。
|
|
@@ -2658,6 +3013,21 @@ interface ToolHookOptions {
|
|
|
2658
3013
|
}
|
|
2659
3014
|
declare function createToolHookExecutor(options: ToolHookOptions): ToolHookExecutor;
|
|
2660
3015
|
//#endregion
|
|
3016
|
+
//#region src/session/session-compaction-lock.d.ts
|
|
3017
|
+
/**
|
|
3018
|
+
* RFC-381 M1/M2:跨进程 durable 压缩锁端口(与 @x-otto/memory 的 CompactionLockPort
|
|
3019
|
+
* 结构同形——runtime 不依赖 memory 包,结构子类型即满足;memory 侧注入处见
|
|
3020
|
+
* MemoryManagerConfig.compactionLock)。
|
|
3021
|
+
*/
|
|
3022
|
+
interface SessionCompactionLockPort {
|
|
3023
|
+
acquire(sessionId: string, token: string): Promise<boolean>;
|
|
3024
|
+
release(sessionId: string, token: string): Promise<void>;
|
|
3025
|
+
}
|
|
3026
|
+
declare const DEFAULT_COMPACTION_LOCK_ORPHAN_TIMEOUT_MS = 60000;
|
|
3027
|
+
declare function createSessionCompactionLock(session: Session<unknown>, options?: {
|
|
3028
|
+
orphanTimeoutMs?: number;
|
|
3029
|
+
}): SessionCompactionLockPort;
|
|
3030
|
+
//#endregion
|
|
2661
3031
|
//#region src/session/persistence-sync.d.ts
|
|
2662
3032
|
interface PersistenceSyncDeps {
|
|
2663
3033
|
persistence: SessionPersistence<AgentMessage>;
|
|
@@ -2708,6 +3078,15 @@ interface PersistenceSyncDeps {
|
|
|
2708
3078
|
* 这是后端能力事实,不是用户配置——未来远端支持 append-tail 后改声明即可自动升级。
|
|
2709
3079
|
*/
|
|
2710
3080
|
turnFlush?: 'incremental' | 'snapshot';
|
|
3081
|
+
/**
|
|
3082
|
+
* M-2:确定性时钟端口(可选)。restore/restoreAll 装载快照时注入 InMemorySession——
|
|
3083
|
+
* restore 本身不产生活动(快照 metadata 权威),但为确定性重放/测试保持一致构造。
|
|
3084
|
+
*/
|
|
3085
|
+
clock?: ClockPort;
|
|
3086
|
+
/**
|
|
3087
|
+
* M-2:确定性 id 生成端口(可选)。restore 路径不 append entry,故当前仅作一致性注入。
|
|
3088
|
+
*/
|
|
3089
|
+
idGen?: IdPort;
|
|
2711
3090
|
}
|
|
2712
3091
|
declare class PersistenceSync {
|
|
2713
3092
|
private readonly deps;
|
|
@@ -2784,13 +3163,6 @@ declare class PersistenceSync {
|
|
|
2784
3163
|
*/
|
|
2785
3164
|
track(agentSession: AgentSession, transient: boolean): void;
|
|
2786
3165
|
flushPending(id: string): Promise<void>;
|
|
2787
|
-
/**
|
|
2788
|
-
* P2 缓解(独立 review 补充,2026-07-12):会话可能经 idle 驱逐(`collectIdle`)或满池 LRU
|
|
2789
|
-
* 驱逐(`evictLeastRecent`)消失,这两条路径不经过 `removeSession`/`flushPending`(前者是
|
|
2790
|
-
* 同步批量收集不适合 await 落盘完成,后者已自行 fire-and-forget 触发 `saveSnapshot`)——
|
|
2791
|
-
* 提供一个轻量同步纯清理方法,供这两条驱逐路径调用,与 `flushPending` 共享同一清理意图
|
|
2792
|
-
* 但不附带"等待落盘完成"的语义(驱逐场景不需要,也不应阻塞驱逐循环)。
|
|
2793
|
-
*/
|
|
2794
3166
|
/**
|
|
2795
3167
|
* RFC-323 D4:计算用于预算分配的活跃会话数(排除 transient)。
|
|
2796
3168
|
*
|
|
@@ -2808,6 +3180,13 @@ declare class PersistenceSync {
|
|
|
2808
3180
|
* 一致地排除 transient(不订阅持久化、不参与预算分摊)。
|
|
2809
3181
|
*/
|
|
2810
3182
|
private sumEstimatedContentBytes;
|
|
3183
|
+
/**
|
|
3184
|
+
* P2 缓解(独立 review 补充,2026-07-12):会话可能经 idle 驱逐(`collectIdle`)或满池 LRU
|
|
3185
|
+
* 驱逐(`evictLeastRecent`)消失,这两条路径不经过 `removeSession`/`flushPending`(前者是
|
|
3186
|
+
* 同步批量收集不适合 await 落盘完成,后者已自行 fire-and-forget 触发 `saveSnapshot`)——
|
|
3187
|
+
* 提供一个轻量同步纯清理方法,供这两条驱逐路径调用,与 `flushPending` 共享同一清理意图
|
|
3188
|
+
* 但不附带"等待落盘完成"的语义(驱逐场景不需要,也不应阻塞驱逐循环)。
|
|
3189
|
+
*/
|
|
2811
3190
|
forgetSession(id: string): void;
|
|
2812
3191
|
/**
|
|
2813
3192
|
* RFC-352 D2:驱逐的最终 snapshot 仍在队列中时不能提前清 residency 状态。
|
|
@@ -2830,26 +3209,6 @@ declare class PersistenceSync {
|
|
|
2830
3209
|
*/
|
|
2831
3210
|
private isTransient;
|
|
2832
3211
|
save(id: string): Promise<void>;
|
|
2833
|
-
/**
|
|
2834
|
-
* RFC-336 D1:会话行预建——会话创建即落 `sessions` 一行(无 entries),不等首条消息。
|
|
2835
|
-
*
|
|
2836
|
-
* **要解决的问题**(实测复现,2026-08-10):`repo.createSession()` 的唯一调用点是
|
|
2837
|
-
* `RelationalSessionPersistence.save()`,而 save 由 `track()` 订阅的 `turn.end`/
|
|
2838
|
-
* `prompt.end` 触发——两者都发生在**首个模型回合完成之后**。因此"用户已回车、模型还没
|
|
2839
|
-
* 回任何东西"这段窗口(≈ 一次完整模型往返,数秒~数十秒)内进程若被强杀(SIGKILL/OOM/
|
|
2840
|
-
* 断电),DB 里连 `sessions` 行都不存在 → 整个会话蒸发,`/resume` 完全看不到,
|
|
2841
|
-
* 且 `detectCrashGap` 因 `load()` 返回 null 而根本不执行(RFC-305 D3 的盲区)。
|
|
2842
|
-
*
|
|
2843
|
-
* **为什么复用 doSaveEntries 而非直调 repo**(D1-b,RFC-159 D3):写租约检查在
|
|
2844
|
-
* `RelationalSessionPersistence.save()` 入口,是所有会话写路径的单一汇聚点。直调
|
|
2845
|
-
* `repo.createSession()` 会开一条无租约的写路径先例。走这里则天然经 `enqueue` 串行链
|
|
2846
|
-
* → `doSaveEntries` → `persistence.save()`,租约与写序语义全部继承,零新增写路径。
|
|
2847
|
-
* 空 entries 快照在 save 内部即 `createSession()` + 零次 `appendEntry()`,正是所需语义。
|
|
2848
|
-
*
|
|
2849
|
-
* **幂等**:`createSession` 是 `ON CONFLICT DO NOTHING`;重复调用安全。
|
|
2850
|
-
* **fire-and-forget**(规则 3):失败只 warn,绝不阻塞会话创建——预建是可用性增强,
|
|
2851
|
-
* 不是创建流程的正确性前提(失败时退化为改动前行为:首个 turn 后才落行)。
|
|
2852
|
-
*/
|
|
2853
3212
|
/**
|
|
2854
3213
|
* RFC-336 D2:输入边界落盘——prep 成功、模型往返开始**之前**把新增 entries 落库。
|
|
2855
3214
|
*
|
|
@@ -2870,6 +3229,26 @@ declare class PersistenceSync {
|
|
|
2870
3229
|
* prompt 终态落盘共用同一条 per-session 链,天然串行、写租约语义一致。
|
|
2871
3230
|
*/
|
|
2872
3231
|
requestInputBoundaryFlush(agentSession: AgentSession, transient: boolean): void;
|
|
3232
|
+
/**
|
|
3233
|
+
* RFC-336 D1:会话行预建——会话创建即落 `sessions` 一行(无 entries),不等首条消息。
|
|
3234
|
+
*
|
|
3235
|
+
* **要解决的问题**(实测复现,2026-08-10):`repo.createSession()` 的唯一调用点是
|
|
3236
|
+
* `RelationalSessionPersistence.save()`,而 save 由 `track()` 订阅的 `turn.end`/
|
|
3237
|
+
* `prompt.end` 触发——两者都发生在**首个模型回合完成之后**。因此"用户已回车、模型还没
|
|
3238
|
+
* 回任何东西"这段窗口(≈ 一次完整模型往返,数秒~数十秒)内进程若被强杀(SIGKILL/OOM/
|
|
3239
|
+
* 断电),DB 里连 `sessions` 行都不存在 → 整个会话蒸发,`/resume` 完全看不到,
|
|
3240
|
+
* 且 `detectCrashGap` 因 `load()` 返回 null 而根本不执行(RFC-305 D3 的盲区)。
|
|
3241
|
+
*
|
|
3242
|
+
* **为什么复用 doSaveEntries 而非直调 repo**(D1-b,RFC-159 D3):写租约检查在
|
|
3243
|
+
* `RelationalSessionPersistence.save()` 入口,是所有会话写路径的单一汇聚点。直调
|
|
3244
|
+
* `repo.createSession()` 会开一条无租约的写路径先例。走这里则天然经 `enqueue` 串行链
|
|
3245
|
+
* → `doSaveEntries` → `persistence.save()`,租约与写序语义全部继承,零新增写路径。
|
|
3246
|
+
* 空 entries 快照在 save 内部即 `createSession()` + 零次 `appendEntry()`,正是所需语义。
|
|
3247
|
+
*
|
|
3248
|
+
* **幂等**:`createSession` 是 `ON CONFLICT DO NOTHING`;重复调用安全。
|
|
3249
|
+
* **fire-and-forget**(规则 3):失败只 warn,绝不阻塞会话创建——预建是可用性增强,
|
|
3250
|
+
* 不是创建流程的正确性前提(失败时退化为改动前行为:首个 turn 后才落行)。
|
|
3251
|
+
*/
|
|
2873
3252
|
precreateSessionRow(agentSession: AgentSession, transient: boolean): void;
|
|
2874
3253
|
/**
|
|
2875
3254
|
* 驱逐路径专用:用调用方**同步捕获**的快照入链落盘。
|
|
@@ -2942,21 +3321,6 @@ declare class PersistenceSync {
|
|
|
2942
3321
|
* 若未提供 configProvider 则返回 null。
|
|
2943
3322
|
*/
|
|
2944
3323
|
restore(id: string): Promise<AgentSession | null>;
|
|
2945
|
-
/**
|
|
2946
|
-
* RFC-305 D3:restore 时 trace↔DB 对账——检出"上次进程异常终止时已发生但未落库"的
|
|
2947
|
-
* turn 缺口并告警。对账基准 = trace append-log(逐事件实时落盘,独立于 save 链):
|
|
2948
|
-
* DB 最后一条已持久化 entry 时间戳之后,trace 仍有 `turn.end` lifecycle 事件 →
|
|
2949
|
-
* 这些 turn 的消息只进过内存、从未进 DB,已随崩溃永久丢失。
|
|
2950
|
-
*
|
|
2951
|
-
* 用时间戳而非 turn 号对账:trace 的 turn 字段 per-prompt 从 0 重置,跨 prompt 不可比;
|
|
2952
|
-
* ts 与 entry.timestamp 同源(Date.now 系时钟),单机单调可比。
|
|
2953
|
-
*
|
|
2954
|
-
* 容忍度:正常退出路径(prompt.end 立即落盘 + turn 级入链)下 trace turn.end 与 DB
|
|
2955
|
-
* 落库几乎同时,容忍 CRASH_GAP_TOLERANCE_MS 内的尾差(在途写 + 时钟粒度),超出才告警。
|
|
2956
|
-
*
|
|
2957
|
-
* fail-soft:traceStore 缺失/读取异常/无 turn.end 事件 → 静默跳过(debug 日志),
|
|
2958
|
-
* 绝不阻塞 restore、绝不产生假告警。
|
|
2959
|
-
*/
|
|
2960
3324
|
/**
|
|
2961
3325
|
* RFC-305 D3:对账结果查询口——restore/restoreAll 内部把本次恢复检出的崩溃缺口记入
|
|
2962
3326
|
* per-session 缓存,调用方(CLI resume 路径)在订阅建立后读取并 toast。缓存随
|
|
@@ -2999,7 +3363,7 @@ interface EngineSnapshot {
|
|
|
2999
3363
|
}
|
|
3000
3364
|
/** 引擎产出的治理决策(所有字段确定性)。 */
|
|
3001
3365
|
interface ResidencyDecision {
|
|
3002
|
-
/**
|
|
3366
|
+
/** 单会话当前有效字节预算(分配量经压力档缩放后的最终值)。 */
|
|
3003
3367
|
maxBytesPerSession: number;
|
|
3004
3368
|
/** 当前全局驻留压力比例(0.0 ~ 1.0)。 */
|
|
3005
3369
|
globalPressure: number;
|
|
@@ -3007,15 +3371,15 @@ interface ResidencyDecision {
|
|
|
3007
3371
|
isGlobalPressure: boolean;
|
|
3008
3372
|
}
|
|
3009
3373
|
/**
|
|
3010
|
-
*
|
|
3374
|
+
* 计算给定 snapshot 下每个会话的有效字节预算。
|
|
3011
3375
|
*
|
|
3012
|
-
*
|
|
3013
|
-
* - 负反馈:currentTotalResidentBytes 越大 pressure 越高 →
|
|
3014
|
-
* - 下界 MIN_PER_SESSION
|
|
3015
|
-
* - 上界 MAX_PER_SESSION
|
|
3016
|
-
* - 确定性:相同 snapshot → 相同 decision(R4
|
|
3376
|
+
* 特性:
|
|
3377
|
+
* - 负反馈:currentTotalResidentBytes 越大 → pressure 越高 → 每个会话预算越低。
|
|
3378
|
+
* - 下界 MIN_PER_SESSION:防会话数极大时分配结果不可用。
|
|
3379
|
+
* - 上界 MAX_PER_SESSION:单会话驻留上限。
|
|
3380
|
+
* - 确定性:相同 snapshot → 相同 decision(R4)。
|
|
3017
3381
|
*/
|
|
3018
3382
|
declare function decide(snapshot: EngineSnapshot): ResidencyDecision;
|
|
3019
3383
|
//#endregion
|
|
3020
|
-
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, CAPABILITY_SURFACE_PATTERNS, type Checkpoint, type CheckpointData, type ContextBuildInput, type ContextInjectionPort, type ContextSource, ContextSourceRegistry, DEFAULT_MAX_AUTO_APPLY_LINES, type DiskSessionPoolOptions, type DocSyncPort, type EngineStoreLocation, type EngineStoreOverrides, type ExitResult, FORBIDDEN_ZONE_PATTERNS, type FileEntrySnapshot, type FileSnapshot, FleetMonitor, type FleetMonitorOptions, type FleetSample, type GrillAnswer, type GrillQuestion, type GrillRequest, type KillOptions, LEVEL_DIVISOR, type ManagedProcess, type MemoryDeltaPort, MemoryGovernor, type MemoryGovernorOptions, type MemoryPort, type MemoryPressureLevel, type MemorySample, type MemorySubsystem, PanelStateStore, PersistenceSync, type PersistenceSyncDeps, type ProcessCategory, type ProcessFilter, type ProcessLifecycle, type ProcessListener, type ProcessOwner, ProcessRegistry, type ProcessRegistryOptions, ProcessRuntime, type ProcessRuntimeOptions, type ProcessSpawnConfig, type ProcessStatus, type PromptOptions, type PromptRefresh, RUNTIME_DEFAULTS, type RegisterAgentJobInput, type RegisterInput, 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, SessionPool, type SessionPoolOptions, type SessionPorts, type SessionStableInjectionOptions, type SessionStorageConfig, type SystemPromptSectionSpec, TimeTravelController, type TimeTravelDeps, type TodoReminderPort, type TracebackView, type TurnRecord, type Verdict, type Worktree, applyDiff, applyMemoryTransform, attachAgentObserver, buildEngineStores, captureFiles, createAgentRuntime, createDefaultContextSourceRegistry, createDiskSessionPool, createDocSyncReminderHooks, createEnvironmentContextSource, createInMemorySessionPool, createMemoryDeltaHooks, createMemoryIndexContextSource, createRemoteSessionPool, createSessionStableInjectionHooks, createTodoReminderHooks, createToolHookExecutor, createWorktree, decideApply, decide as decideResidency, defaultMaxToolTurnExtensions, deriveSessionTitle, diffTouchedPaths, effectiveResidencyBudget, formatDocSyncReminder, globalAgentJobRegistry, globalAgentObservability, globalProcessRegistry, globalProcessRuntime, hasRepoDrifted, installAgentJobReaper, installExitReaper, installProcessReaper, messagesFromSnapshot, pruneOrphanWorktrees, reconstructMessages, removeWorktree, resolveSessionTitle, resolveTodoContinuationConfig, restoreFiles, revertDiff, touchesCapabilitySurface, touchesForbiddenZone, worktreeDiff };
|
|
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 DiskSessionPoolOptions, type DocSyncPort, type EmitContext, type EngineStoreLocation, type EngineStoreOverrides, 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 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, 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 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, applyDiff, applyMemoryTransform, applySectionBudget, attachAgentObserver, buildEngineStores, captureFiles, checkApply, createAgentRuntime, createDefaultContextSourceRegistry, createDiskSessionPool, createDocSyncReminderHooks, createEnvironmentContextSource, createInMemorySessionPool, createMemoryDeltaHooks, createMemoryIndexContextSource, createRemoteSessionPool, createSessionCompactionLock, createSessionStableInjectionHooks, createTodoReminderHooks, createToolHookExecutor, createWorktree, decideApply, decide as decideResidency, defaultMaxToolTurnExtensions, deriveSessionTitle, diffTouchedPaths, effectiveResidencyBudget, formatDocSyncReminder, globalAgentJobRegistry, globalAgentObservability, globalProcessRegistry, globalProcessRuntime, globalToolResultStore, hasRepoDrifted, installAgentJobReaper, installExitReaper, installProcessReaper, messagesFromSnapshot, pruneOrphanWorktrees, reconstructMessages, removeWorktree, resolveSessionTitle, resolveTodoContinuationConfig, restoreFiles, revertDiff, touchesCapabilitySurface, touchesForbiddenZone, worktreeDiff };
|
|
3021
3385
|
//# sourceMappingURL=index.d.ts.map
|