@jayyuen66/dsh-dir-prep-organize 0.1.16 → 0.1.17

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/types/host.d.ts DELETED
@@ -1,483 +0,0 @@
1
- import Schema from "@deepseek-ai/schemastery";
2
- import type { Context, Volatile } from "@deepseek-ai/cordis";
3
- import type { FileSystem } from "@deepseek-ai/dsh-fs";
4
- import type { GenerateOptions, LlmRuntime, Message, ReasoningEffortId, StreamChunk } from "@deepseek-ai/dsh-llm";
5
- import type { SessionHeader, SessionId } from "@deepseek-ai/dsh-session";
6
- import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
7
- import type { HostMessages } from "./src/host-messages.js";
8
- import type { TemplateEntry } from "./src/templates.js";
9
- /**
10
- * 从 import 到的模块命名空间里取出内置精选模板表;形状不对就抛。
11
- *
12
- * 说明符是变量 ⇒ import() 的返回类型退化成 any,所以这一步必须自己验形状:产物发错、发旧、
13
- * 或被别的构建覆盖,症状都会是「模板下拉空着」,而带原因的报错比一张空列表好定位得多。
14
- * 提成纯函数是为了能脱离磁盘与模块缓存单测它——产物 URL 一旦被加载过就进了 Node 的 ESM
15
- * 缓存,改磁盘上的内容对后续 import 是无效的。
16
- *
17
- * @param raw - import 得到的模块命名空间
18
- * @returns 内置精选模板表
19
- */
20
- export declare function defaultTemplatesFrom(raw: unknown): readonly TemplateEntry[];
21
- /**
22
- * 内置精选模板表:按需载入,永不静态导入。
23
- *
24
- * 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
25
- * 读取方法,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一种做法。
26
- *
27
- * @param load - 载入器,缺省即真实 import 产物;单测靠它把「首读失败」那一档做成可复跑
28
- * 的判据(产物 URL 一旦被成功加载就进 ESM 缓存,改磁盘内容对后续 import 无效,所以失败路径
29
- * 只能从这一个缝注入)。
30
- * @returns 内置精选模板表
31
- */
32
- export declare function loadDefaultTemplates(load?: () => Promise<readonly TemplateEntry[]>): Promise<readonly TemplateEntry[]>;
33
- /**
34
- * 把一个部署来的数夹进 `[min, max]`,非有限值回落到 `fallback`。
35
- *
36
- * 为什么单独要一个函数:`Math.min(Math.max(NaN, 1), MAX)` 的结果是 `NaN`——两个 clamp
37
- * 都会把 NaN 原样放过去,于是「看起来夹过了」的代码对最危险的那个输入恰好无效。
38
- *
39
- * @param value - 待夹的数(可能非有限)
40
- * @param min - 下界(含)
41
- * @param max - 上界(含)
42
- * @param fallback - `value` 非有限时用的默认值
43
- * @returns `[min, max]` 区间内的整数
44
- */
45
- export declare function clampInt(value: number, min: number, max: number, fallback: number): number;
46
- /** 目标的官方形状直接 re-export(`targetKey` 就此带官方 `FsTargetKey` 的 `brand`,不再降级成 string)。 */
47
- export type { FsDirEntry, FsTarget } from "@deepseek-ai/dsh-fs";
48
- /**
49
- * 官方 `FileSystem`(installed @deepseek-ai/dsh-fs/lib/types/index.d.ts,cordis `Service`
50
- * 子类 → 名义比较)的方法子集投影:本包用 `resolve` / `listDir` / `readText`
51
- * / `contains` / `stat`。旧镜像漏抄了官方那几位的可选 `signal?: AbortSignal`
52
- * 形参(抄本里没有的形参在 TS 里是"少收一个参数",调用点不会报错,但真实宿主多一档取消
53
- * 语义);投影之后它回到官方形状。
54
- *
55
- * `stat`(installed `@deepseek-ai/dsh-fs/lib/types/index.d.ts`,返回 `{version,type,size?}`)是**单文件导入**那条
56
- * 路径唯一的字节上限来源:目录分支的每个候选都自带 `listDir` 给的 `size`,而单文件导入
57
- * 只有一个 `resolve` 出来的 target,不 stat 就无从判断该不该读——而官方 `readText`
58
- * 自述"读整份文本"、**没有任何上限**。缺了它,一个几 MB 的 .md 就能把整份读进宿主内存。
59
- */
60
- export type FsService = Pick<FileSystem, "resolve" | "listDir" | "readText" | "contains" | "stat">;
61
- /**
62
- * 本包从会话消息历史里读到的类型 = **官方 `Message` 的键名投影**(installed
63
- * @deepseek-ai/dsh-llm/lib/types/message.d.ts `MessageBase` 与各变体的 `role`),
64
- * 三位各自取到"本包能凭运行时守卫负责的那一档":
65
- * - `role` 就此是官方 `Message['role']` 的字面量联合(上游加/改角色即在此编译不过,
66
- * 下面 `role === "user" || role === "assistant"` 的判定跟着动)。
67
- * - `content` 官方是 `readonly ContentBlock[]`(message.d.ts),但本包的职责是
68
- * **逐块自证**:只认 `type==='text'` 且 `text` 是字符串的块(`isTextBlock`),其余
69
- * (tool-call / reasoning / image / 宿主新版本才有的块)一律跳过。这里留 `unknown`
70
- * 不是"抹平官方形状",而是本包**不假设交付**:`Array.isArray(msg.content)` 那道判据
71
- * 断言的正是"交来的可能根本不是数组",test/host.test.ts 的「坏形状」用例钉的就是
72
- * 非数组 content(字符串)与数组里的裸字符串/null 项。把值域收成官方联合等于宣称
73
- * "块形状可信",那几条用例便无法表达,而为了过类型删用例是本仓红线。
74
- * - `source.kind` 官方是 `MessageSourceMap` 的值联合(installed message.d.ts 只有
75
- * `user`/`model`/`tool`/`system-prompt`,宿主安装里另有 `model-selection` 一枚由
76
- * dsh-agent 自己 merge)。**本包要读的恰是这张表里没有的 kind**:真人过滤之外的
77
- * `agent-instructions` / `skill-catalog` / `memory-recall-step` / `plugin:<name>` 全是
78
- * 别的插件在自己模块里 merge 进来的 producer kind,不在本包的编译程序里。收成官方闭合联合
79
- * 只有两条路:要么在测试里伪造宿主声明(type theater),要么把"过滤注入"这几条用例删掉
80
- * ——两条都不接受,故 kind 留 `string`。真人的判据仍是官方那两枚值(`"user"`/`"model"`),
81
- * 写成 `source?.kind === "user"` 而不是比字符串常量表。
82
- * 键名一个都不重述:官方给 `MessageBase` 换名,这里立刻红。
83
- */
84
- export interface DerivedMessageView {
85
- readonly role?: Message["role"];
86
- readonly content?: unknown;
87
- readonly source?: {
88
- readonly kind?: string;
89
- };
90
- }
91
- /**
92
- * 本包读到的会话类型 = 官方 `Session` 两位成员的**边界投影**(installed
93
- * @deepseek-ai/dsh-session/lib/types/index.d.ts:`readonly header: SessionHeader`、
94
- * `deriveMessages(): Message[]`)。
95
- * 键名一律借自官方(`header` 借 `Session`、`cwd` 借 `SessionHeader`,installed
96
- * @deepseek-ai/dsh-session 域内 types.d.ts `readonly cwd?: string`),值域收成"本包真的读的那位
97
- * + 可缺失":官方把 header/deriveMessages 记成必选成员,但那句承诺说的是宿主自己 `new`
98
- * 出来的 Session;跨进程递来的会话是否具备某位只能运行时判(见 `extractSessionConversation`
99
- * 的 `typeof session.deriveMessages !== "function"` 与 `cwdOfSession` 的 `typeof === "string"`
100
- * 守卫)。官方类型说宿主**承诺**什么,守卫说**交付**什么,两者并存。
101
- */
102
- export interface SessionLike {
103
- readonly header?: Partial<Pick<SessionHeader, "cwd">>;
104
- readonly deriveMessages?: () => readonly DerivedMessageView[];
105
- }
106
- /**
107
- * `Context.sessions`(官方 `SessionStore`,installed @deepseek-ai/dsh-session/lib/types/
108
- * index.d.ts)的 `get` 一位(`Sessions.get(id: SessionId)`)在本包的
109
- * 读法:入参就此是官方品牌的 `SessionId`(边界上递来的是裸 string,构造口只有文件头那枚
110
- * `brandString<SessionId>`),返回值域换成上面的 `SessionLike` 投影——直接取官方返回的整枚
111
- * `Session` 类会把名义类一路渗进本包(`private log`/`surfaceManager`),那三道运行时
112
- * 守卫当场在编译器眼里变成死代码,而它们挡的是真实输入。返回 `undefined` 与官方一致。
113
- * 做法同 danger-guard/host.ts 的 `GuardExecution`(借键名、值域换投影)。
114
- */
115
- export interface SessionsService {
116
- get: (id: SessionId) => SessionLike | undefined;
117
- }
118
- /** 活 Agent 的模型选择接口(新版 `model.current()`;旧版只有 `options`)。 */
119
- export interface LiveModelSelection {
120
- readonly provider: string;
121
- readonly model: string;
122
- readonly reasoningEffort?: ModelSelection["reasoningEffort"];
123
- }
124
- /** 活 Agent 的只读投影:本包只碰模型这两位。 */
125
- export interface LiveAgent {
126
- readonly model?: {
127
- readonly current: () => LiveModelSelection | undefined;
128
- } | null;
129
- readonly options?: {
130
- readonly provider?: string;
131
- readonly model?: string;
132
- readonly reasoningEffort?: ModelSelection["reasoningEffort"];
133
- };
134
- }
135
- /** 宿主 agent 注册表的读取接口:按会话 id 取活 Agent。 */
136
- export interface AgentsService {
137
- get: (id: SessionId) => LiveAgent | undefined;
138
- }
139
- /** `ReasoningEffortId` 取官方真 `brand`(`Branded<'ReasoningEffortId'>`,以 dsh-brand 的
140
- * `unique symbol` 为键)。本地重述成 `string & { effortBrand: ... }` 只是**自造的假类型品牌**:
141
- * 键不同名即不同型,宿主真值塞不进来、任何带该属性的字符串反倒能通过,注释里那句
142
- * 「转换点为 0」并不成立。取官方类型后模型选择与 stream 入参两侧共用同一真值。 */
143
- export type { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
144
- /** 默认模型选择的三位形状:与官方 `ModelSelection`(`@deepseek-ai/dsh-agent` 的
145
- * model-selection.d.ts)同形。`reasoningEffort` 用官方真 `brand` 类型 `ReasoningEffortId`(上面已按
146
- * dsh-llm 的 peer 声明里的 re-export),`brand` 值塞不进 stream 入参时静默丢字段的风险仍留在类型上。
147
- *
148
- * 为什么不直接 import/re-export 官方类型:那会在 `types/host.d.ts` 里留下裸说明符
149
- * `@deepseek-ai/dsh-agent`,按本仓门禁它只能落进 peer 表,而本包运行期并不 import 它——
150
- * 为此扩一条 peer 是发布契约变更,归用户裁决;在此之前用结构等价类型。 */
151
- export interface ModelSelection {
152
- readonly provider: string;
153
- readonly model: string;
154
- readonly reasoningEffort?: ReasoningEffortId;
155
- }
156
- /** 默认模型服务里本包用到的那部分:只 `currentSelection()`,不写回(`saveSelection` 归 composer)。
157
- *
158
- * 刻意不 `Pick<AgentDefaultModelConfig, …>`:那个声明文件 import 了它自己没声明的
159
- * `@deepseek-ai/dsh-agent`,干净检出里这条链会退化成 error 类型,类型感知的 oxlint 在 CI
160
- * 上整片报 `no-unsafe-*`(伞根里经 hoist 解析得开,本机门禁看不见)。返回值用本仓的
161
- * 结构等价 `ModelSelection`,与真实服务的官方类型在成员上相容。 */
162
- export interface AgentDefaultModel {
163
- readonly currentSelection: () => ModelSelection;
164
- }
165
- /** 文本块与 request-only user 输入均取官方声明:`TextBlock` 与 `RequestUserInput`
166
- * (后者的 `content` 真值是 `UserMessage["content"]` 全块集,`id`/`source` 是
167
- * `?: never`——本包只发单条 user 文本消息,形状由官方约束而不是自己抄一半)。 */
168
- export type { RequestUserInput, TextBlock } from "@deepseek-ai/dsh-llm";
169
- /** 流块与终态取官方判别联合(`switch (chunk.type)` 即收窄载荷,不再把 `type` 写成
170
- * 裸 `string` + 全可选成员)。 */
171
- export type { FinishReason, StreamChunk } from "@deepseek-ai/dsh-llm";
172
- /** stream 入参:官方 `GenerateOptions` 的本包用到的子集。在 `Pick` 之外**另加**
173
- * 一枚 `signal?: AbortSignal` 是不行的——官方本来**就有**这一位
174
- * (installed @deepseek-ai/dsh-llm/lib/types/types.d.ts),另写一次等于凭空多出一个
175
- * 与官方并行的形状声明;连同 `signal` 一起 `Pick`,一处来源。 */
176
- export type LlmStreamOptions = Pick<GenerateOptions, "provider" | "model" | "reasoningEffort" | "messages" | "system" | "signal">;
177
- /** 官方 `LlmRuntime`(`Context.llm` 的类型,installed @deepseek-ai/dsh-llm/lib/types/
178
- * index.d.ts)的方法子集投影:本包只 `stream`。旧镜像把返回抄成
179
- * `AsyncIterable<StreamChunk>`——官方那一位的真实返回域由成员自己交出,重述一次就多一处
180
- * 会漂移的判决(`stream` 在 installed index.d.ts 上有数枚同名成员,本包用的是 runtime 那枚)。 */
181
- export type LlmService = Pick<LlmRuntime, "stream">;
182
- /** 官方工作目录服务的最小读取形状(`WorkingDirectoryService.get(session)` 同步、无 fs I/O)。 */
183
- interface WorkingDirectoryFace {
184
- get?: (session: unknown) => unknown;
185
- }
186
- export declare function isWorkingDirectory(value: unknown): value is WorkingDirectoryFace;
187
- /** 服务表里的 `workingDirectory` 只按形状收:缺席或形状不符都交回 undefined,由 header.cwd 回落。 */
188
- export declare function workingDirectoryOf(service: unknown): WorkingDirectoryFace | undefined;
189
- export interface DirEntry {
190
- name: string;
191
- isDir: boolean;
192
- sizeBytes: number;
193
- /** 关键文本文件首段摘要;非关键文件/目录为 undefined。 */
194
- snippet: string | undefined;
195
- }
196
- /** 静默丢数据的记录("读失败即 undefined、超限即忽略"的话没有任何回执,
197
- * 界面与 host 都显示成功)。dir context 与 import 两个读取方法共用此形状。 */
198
- export interface SkipCounts {
199
- /** 字节超限、整份跳过的文件数。 */
200
- tooLarge: number;
201
- /** 读取失败(含 EMFILE / 权限 / 非 UTF-8)的文件数。 */
202
- unreadable: number;
203
- /** 只在更深一层、被扫描深度限制造漏掉的 .md 数(只有导入接口用到)。 */
204
- deeper: number;
205
- /** 读到了但解析不出角色 name(非角色文件)而被跳过的文件数(只有导入接口用到)。 */
206
- unnamed: number;
207
- /** 真实目标落在允许根之外(符号链接指向根外文件)而被策略排除的文件数。
208
- * 必须单列:它既不是读失败也不是超限,把「凭据文件被链接进工作目录」这类事
209
- * 混进 unreadable,用户就看不出是被安全检查拦下的,还是目录本身坏了。 */
210
- escaped: number;
211
- }
212
- export interface CollectResult {
213
- cwd: string;
214
- entries: DirEntry[];
215
- /** 有任一文件被跳过即为 true(不再硬编码 false)。 */
216
- truncated: boolean;
217
- skipped: SkipCounts;
218
- error?: string;
219
- }
220
- /** 这几个方法实际用的收集函数:fs 服务 → DirEntry[](含关键文件全文摘要)。
221
- * 条目数不设上限(用户定下),但单文件按 MAX_SNIPPET_BYTES 整份跳过、
222
- * 读取按 READ_CONCURRENCY 有界并发;跳过项计入 skipped 并让 truncated 反映事实。
223
- * 回执文案取自注入的字典(纯函数不读设置)。 */
224
- export interface DirScanLimits {
225
- /** 单文件摘要字节上限(超出整份跳过)。 */
226
- maxSnippetBytes: number;
227
- /** 有界并发读取度。 */
228
- readConcurrency: number;
229
- /** 单次收集的全部摘要的字节总量上限。 */
230
- maxTotalBytes?: number;
231
- }
232
- /** 这几个方法实际用的 limits 全集。 */
233
- type RouteLimits = DirScanLimits & {
234
- organizeTimeoutMs: number;
235
- };
236
- /**
237
- * 部署值唯一一处统一处理:把会致命的几个数夹进安全区间,再交给读取方法。
238
- *
239
- * 为什么放在这里而不是各消费点:`limitsOf()` 是 context/organize/importTemplates
240
- * 三个方法读 limits 的**唯一入口**,一处统一处理就不会漏掉将来新增的方法;而散在
241
- * 各消费点夹,哪天新增一个调用点就等于新增一个漏洞。
242
- *
243
- * 夹哪两个、为什么:
244
- * - `readConcurrency` → `[1, 64]`。**下界 0 是致命的**:`mapBounded` 拿到 0 会无限
245
- * 自递归直到 OOM,**整个 DSH 宿主进程被带走**,而不只是这一次请求失败(见 mapBounded
246
- * 的注释)。schema 的 `natural()` 下界恰好是 0 且无上界,两个方向都得夹。
247
- * - `organizeTimeoutMs` → `[1, 2^31-1]`。上界超了会被 `setTimeout` 静默夹成 1 ms,
248
- * 「调大超时」变成「立刻失败」。
249
- *
250
- * 剩下 `maxSnippetBytes` **故意不夹**:schema 已经挡住 NaN/±Infinity/负数/小数,
251
- * 唯一还能配出来的越界值 `0` 有确定且已记录的行为(全跳过并计 tooLarge),那是用户
252
- * 的显式意图,不该被悄悄改写。
253
- *
254
- * @param limits - 未经夹位的部署值
255
- * @returns 两项关键值已夹位、其余原样透传的新对象
256
- */
257
- export declare function sanitizeLimits(limits: RouteLimits): RouteLimits;
258
- export declare function collectDirContext(fs: Pick<FsService, "resolve" | "listDir" | "readText" | "contains">, cwd: string | undefined, messages: HostMessages, limits?: DirScanLimits): Promise<CollectResult>;
259
- export interface ImportResult {
260
- entries: TemplateEntry[];
261
- truncated: boolean;
262
- skipped: SkipCounts;
263
- error?: string;
264
- }
265
- export declare function importPathError(requested: string, cwd: string | undefined, allowRoots: readonly string[], messages: HostMessages): string | undefined;
266
- /** 收集导入模板条目(纯逻辑,注入假 fs 可测;单文件/目录两路)。
267
- * 目录路径扫描两层(顶层 *.md + 一层子目录 *.md),排序固定保证确定性;
268
- * 第三层不扫描但**清点**(deeper 计数),读失败/超限/非角色同样计数回报,
269
- * truncated 反映"确实有东西没进来",不再硬编码 false。
270
- * skipPolicy 用于内置角色库自检(AGENTS_DIR 是策略里的允许根,用户输入路径正常
271
- * 不需要它;保留这个开关只为让"内置全量导入"不依赖安装位置是否命中隐藏段判断)。
272
- * allowRoots = 设置 importAllowRoots 登记的额外允许目录(由读取方法注入)。 */
273
- export declare function collectAgentTemplates(fs: Pick<FsService, "resolve" | "listDir" | "readText" | "contains" | "stat">, requested: string, cwd: string | undefined, messages: HostMessages, opts?: {
274
- skipPolicy?: boolean;
275
- allowRoots?: readonly string[];
276
- limits?: DirScanLimits;
277
- }): Promise<ImportResult>;
278
- export interface OrganizeInput {
279
- prompt: string;
280
- cwd: string;
281
- entriesSummary?: string;
282
- /** 会话最近对话文本(user/assistant 交替,host 侧从 deriveMessages 提取)。 */
283
- recentTurns?: string;
284
- /** 参考角色上下文(提炼自模板正文;可选)。提供时借用该角色的术语与风格润色 `prompt`。 */
285
- roleText?: string;
286
- model?: ModelSelection;
287
- }
288
- /** 构造 system 提示(导出供测试)。规则正文与各段标题全部取自注入的字典——
289
- * 面向模型的 prompt 也随官方 locale 偏好切语言;zh 输出的正文逐字取自该字典。 */
290
- export declare function buildOrganizeSystem(input: Omit<OrganizeInput, "prompt">, messages: HostMessages): string;
291
- /**
292
- * user 消息 = 用户草稿(`prompt`)+ 围栏起来的不可信数据块。
293
- *
294
- * 围栏用**成对的定界标记**而不是缩进或横线:模型侧最容易被无视的是「看起来像普通内容」
295
- * 的标记,而成对标签既显眼、又便于判断边界。
296
- *
297
- * ⚠ 标签本身拦不住数据:围栏内容来自用户仓库(目录摘要里的文件名、会话历史、角色 .md
298
- * 正文),里面完全可能含 `</data>`。原样拼进去会被读成提前闭合,其后的字符就重新落回
299
- * 指令位——围栏反而把不可信内容送到了它本该隔离的信任层。所以落进围栏的每一段文本都先
300
- * 把自己的定界标记替换成中性写法,标记只能由本函数产生。
301
- *
302
- * @param prompt - 真正的用户草稿
303
- * @param input - 其余上下文(摘要/历史/角色)
304
- * @param messages - 注入的字典
305
- * @returns 交给模型的那条 user 文本
306
- */
307
- export declare function buildOrganizeUser(prompt: string, input: Omit<OrganizeInput, "prompt">, messages: HostMessages): string;
308
- /**
309
- * 会话最近真人对话提取(deriveMessages → "user:/assistant:" 文本串)。
310
- * 不设条数/字符上限(用户定下不截断:上下文完整性优先,模型
311
- * context 超限由模型报错提示用户自行处理)。
312
- *
313
- * 注入过滤(隐藏 bug 复查 实测确认:真实会话 log 里 user 角色
314
- * 混有大量框架注入——agent-instructions / skill-catalog / 插件自己的
315
- * `plugin:<条目 id>`(本体系即 plugin:auto-recall / -step / -subagent),
316
- * 这些都不带 source.kind==='user',内容也不该进指代解析):
317
- * - role==='user' 且 source.kind==='user' → 真人输入,保留
318
- * - role==='assistant' 且 source.kind==='model' → 模型回复,保留
319
- * - 其余(注入类 user 消息 / tool-result 消息 / 空消息)全部跳过——
320
- * 注入内容会污染指代解析、把记忆库全文带给 LLM。
321
- * - 每条消息只取 text block(tool-call/reasoning/image 块跳过)。 */
322
- export declare function extractRecentTurns(messages: readonly DerivedMessageView[]): string;
323
- /** 流式聚合 text-delta 为完整文本;终态非 stop 视为失败(失败文本取自注入字典)。 */
324
- export declare function drainStreamToText(stream: AsyncIterable<StreamChunk>, messages: HostMessages): Promise<string>;
325
- /** 润色入口(读取方法调用;导出供测试注入假 stream)。失败文案与 system 提示都来自
326
- * 注入的字典,本函数不读设置。 */
327
- export declare function runOrganize(llm: LlmService, input: OrganizeInput, messages: HostMessages, timeoutMs?: number, callerSignal?: AbortSignal): Promise<{
328
- content: string;
329
- }>;
330
- /** settings 命名空间与 loader 行 config 共用同一 schema(唯一来源,防漂移)。
331
- * 值名退避为 configSchema:避免与同名 interface Config 触发 no-redeclare;
332
- * 外部仍以 `Config` 名导入(export as),公开 API 不变。
333
- * 写入校验由 dsh-settings 在持久化前按此 schema 完成;凡是要出现在卡上的字段都必须 `.volatile()`
334
- * ——没有任何 volatile 字段的条目会被宿主 describe() 整条跳过
335
- * (packages/settings/settings/src/index.ts),设置卡读不到、写入则抛
336
- * `has no volatile fields`。
337
- *
338
- * 旧 `settings.register(ns, Config, { base })` 的 base 底座取消,逐字段落到 `.default(...)`:
339
- * - importAllowRoots:`.default([])`。**空表是策略不是缺省占位**——登记目录是用户的
340
- * 显式信任动作,除会话 cwd 与内置角色库外默认不放行任何绝对路径(fail-closed,
341
- * 见 importPathError);
342
- * - templates:**标 volatile、不给默认**。内置精选集(scripts/gen-defaults.mjs 从
343
- * agents/ 角色库生成的 src/default-templates.generated.ts,~640 KB)由 **host 半**
344
- * 持有、经 `dirPrepOrganize.defaults` 方法按需下发,client 拉到后作回落:⚠ 不给默认**不等于**读回 undefined——schemastery 对 array 字段把缺失
345
- * 值 cast 成 `[]`(实测 `configSchema["~standard"].validate({})` 之后 `templates` 引用
346
- * `.get() === []`),宿主 describe() 又只丢 undefined 位(`SettingsForms.projectForm`),
347
- * 所以「未设置」递到客户端看到的就是一张空表。回落判据因此落在 client 半
348
- * (client-entry.ts 的 `fromSettings`:空表按未设置处理),设置卡「恢复默认」=
349
- * `unset("templates")` 且复读空值按已回落处理,故「缺失」「空表」「内置」三者同义。
350
- * 写成 `.default(...)` 会让宿主每次 describe() 都重新序列化这 640 KB(index.ts 对
351
- * `JSON.stringify([uid, schema.toJSON(), entry.options.config])` 取指纹,schema.ts
352
- * 的 plainSchema 保留 meta.default),所以内置集不进 schema、由 host 半端点按需下发;而既然空表就是
353
- * 「未设置」的运行时形状,回落判据仍由 client 半出。 */
354
- declare const configShape: {
355
- templates: Schema<NoInfer<({
356
- id?: string | null;
357
- name?: string | null;
358
- description?: string | null;
359
- text?: string | null;
360
- group?: string | null;
361
- emoji?: string | null;
362
- } & import("@deepseek-ai/cosmokit").Dict)[]>, NoInfer<Schemastery.ObjectT<NoInfer<{
363
- id: Schema<string, string, "plain">;
364
- name: Schema<string, string, "plain">;
365
- description: Schema<string, string, "defined">;
366
- text: Schema<string, string, "plain">;
367
- group: Schema<string, string, "defined">;
368
- emoji: Schema<string, string, "defined">;
369
- }>>[]>, "volatile">;
370
- importAllowRoots: Schema<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
371
- organizeTimeoutMs: Schema<number, number, "volatile-defined">;
372
- maxSnippetBytes: Schema<number, number, "defined">;
373
- readConcurrency: Schema<number, number, "defined">;
374
- };
375
- declare const configSchema: ReturnType<typeof Schema.object<typeof configShape>>;
376
- /** cordis 校验过 configSchema 后交进 apply 的那份配置:volatile 字段以 Volatile 引用
377
- * 形态进来,读当前值一律 `.get()`(改设置不必重挂载插件)。
378
- * ⚠ templates 的形参写 `| undefined` 只是留口:实测**未设置时 `.get()` 给的是 `[]`**
379
- * (schemastery 对 array 的 cast,见上方 configSchema 注释),而 host 半从不读这一位
380
- * (它只把 schema 交给设置卡),回落由 client 半判。 */
381
- export interface Config {
382
- templates: Volatile<TemplateEntry[] | undefined>;
383
- importAllowRoots: Volatile<string[]>;
384
- /** LLM 润色中止时限(volatile:客户端经 configForms 快照同源读取)。 */
385
- organizeTimeoutMs: Volatile<number>;
386
- /** 关键文件摘要的单文件字节上限(超出整份跳过)。 */
387
- maxSnippetBytes: number;
388
- /** 目录扫描/读取的有界并发度。 */
389
- readConcurrency: number;
390
- }
391
- export { configSchema as Config };
392
- /** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
393
- * 引用背后可能是存量脏配置:非数组一律空表(fail-closed),非字符串/纯空白项逐个
394
- * 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
395
- * 相对路径同样丢弃:契约写的是「额外允许的**绝对**目录」(见 schema describe 与 DETAIL
396
- * 文档),放进来会被 toImportRoot 的 path.resolve 按**宿主进程 cwd** 解析,变成一条用户
397
- * 没写过、也不知道存在着的允许根。 */
398
- export declare function importAllowRootsOf(raw: unknown): string[];
399
- /** 注入的服务:settings 为硬依赖(cordis 等它就绪才 apply)。
400
- * 命名空间是隐式的(= 本条目在 cordis.patch.yml 里的裸 id,可编辑字段取自
401
- * 导出的 Config),所以 settings 在这里的职责是「页面策略(configure)与跨命名空间读
402
- * (describe)」,而非「注册的前提」;设置页只派发「host 已 serve 的命名空间 ∩
403
- * settings.plugin.item 卡」(dsh-client-ui-settings-plugins 源码语义),configure 必须
404
- * 发生在 apply 期,故仍硬注入。sessions/fs/llm/agentDefaultModel 仍可选读。 */
405
- export declare const inject: string[];
406
- /** 这些方法用到的依赖,抽出来便于测试:apply 用 ctx.get 的惰性 getter 调用(服务可能在
407
- * 注册之后才就绪),测试可直接注入静态假服务。 */
408
- export interface RouteDeps {
409
- sessions?: () => SessionsService | undefined;
410
- /** 会话活目录服务(宿主 `ctx.workingDirectory`);缺席时 cwd 回落 `header.cwd`。 */
411
- workingDirectory?: () => WorkingDirectoryFace | undefined;
412
- fs?: () => FsService | undefined;
413
- llm?: () => LlmService | undefined;
414
- agentDefaultModel?: () => AgentDefaultModel | undefined;
415
- /** 会话活线:有活 Agent 时润色跟随它的模型,没有才回落默认模型。 */
416
- agents?: () => AgentsService | undefined;
417
- /** 设置里登记的额外导入允许根(每次请求现读,改设置无需重启)。 */
418
- importAllowRoots?: () => readonly string[];
419
- /** 部署值(Config 化):润色超时 / 摘要字节上限 / 读取并发。
420
- * 缺省回落原模块常量(与 schema .default 同值)——测试与旧调用方不必逐一改。 */
421
- limits?: () => RouteLimits;
422
- /** 内置精选模板表的取数口。缺省走按需 import 产物;测试替掉它即可覆盖载入失败那条回执,
423
- * 而不必去改磁盘上那份产物(它的 URL 一旦被加载过就进了 Node 的 ESM 缓存,改了也没用)。 */
424
- loadDefaultTemplates?: () => Promise<readonly TemplateEntry[]>;
425
- }
426
- /** 回执字典的现读 getter:每个请求取一次,用户在「设置 → 常规」改语言后下一个请求即
427
- * 切文案(不重启、不加插件自己的 locale 设置项;与 importAllowRoots 的现读同构)。 */
428
- export type MessagesOf = () => HostMessages;
429
- /** 会话活线模型:新版读 `agent.model.current()`(含待切换选择),旧版回落
430
- * `agent.options`。没有活 Agent、或两处都答不全时 undefined(调用方回落默认模型)。
431
- * 与 rescue 同一条规则:`current()` 交回 undefined 是「还没记录过选择」,不是读失败。 */
432
- export declare function liveModelOf(deps: RouteDeps, sessionId: string | null): ModelSelection | undefined;
433
- /** 读取方法每次调用共用的部分:服务 getter 与现读文案/限额。 */
434
- interface RemoteScope {
435
- readonly deps: RouteDeps;
436
- readonly messagesOf: MessagesOf;
437
- readonly limitsOf: () => RouteLimits;
438
- }
439
- /** 五个方法的纯载荷入口(服务与测试共用):不含任何传输层判定。 */
440
- export declare function createRemotePayloads(deps: RouteDeps, messagesOf: MessagesOf): {
441
- defaults: () => Promise<Record<string, unknown>>;
442
- context: (sessionId: string | null) => Promise<Record<string, unknown>>;
443
- model: () => Record<string, unknown>;
444
- organize: (parsed: unknown) => Promise<Record<string, unknown>>;
445
- importTemplates: (parsed: unknown) => Promise<{
446
- status: number;
447
- body: Record<string, unknown>;
448
- }>;
449
- };
450
- /** 官方 Typert Remote 的服务键(= 线上命名空间)。 */
451
- export declare const DIR_PREP_REMOTE_NAMESPACE = "dirPrepOrganize";
452
- interface ContextRequest {
453
- sessionId: string;
454
- }
455
- interface OrganizeRequest extends ContextRequest {
456
- prompt: string;
457
- entriesSummary: string;
458
- roleText?: string;
459
- }
460
- interface ImportTemplatesRequest {
461
- path: string;
462
- sessionId: string;
463
- }
464
- /**
465
- * 设置卡的宿主侧接口(官方 Typert Remote):目录上下文、当前模型、润色、导入与内置模板。
466
- * 本包不自建 HTTP 端点,认证与分派由宿主 /api 网关负责。
467
- */
468
- export declare class DirPrepRemoteService extends TypertRemoteService {
469
- private readonly scope;
470
- constructor(ctx: Context, scope: RemoteScope);
471
- defaults(): Promise<Record<string, unknown>>;
472
- context(request: ContextRequest): Promise<Record<string, unknown>>;
473
- model(request: ContextRequest): Record<string, unknown>;
474
- organize(request: OrganizeRequest): Promise<Record<string, unknown>>;
475
- importTemplates(request: ImportTemplatesRequest): Promise<Record<string, unknown>>;
476
- }
477
- /** 注册这组远端方法(构造即注册);替身上下文没有注册口时只少掉这一栏。 */
478
- export declare function installDirPrepRemote(ctx: Context, scope: RemoteScope): boolean;
479
- /** host apply:登记设置页策略 + 注册官方 Remote 服务(注入子上下文,卸载即撤)。
480
- * 模板设置是**隐式注册**的(导出的 Config + 字段上的 .volatile()),本函数
481
- * 不再向 settings 注册任何东西;配置值由 cordis 校验并填过默认后按 volatile 引用交进来
482
- * (第二参数 config),读当前值一律 `.get()`。 */
483
- export declare function apply(ctx: Context, config: Config): void;
@@ -1,99 +0,0 @@
1
- import type { TemplateEntry } from "./templates.js";
2
- import type { LocaleNs, Translate } from "./ui-messages.js";
3
- import type { Context } from "@deepseek-ai/cordis";
4
- import type { BuiltInLocaleId } from "@deepseek-ai/dsh-client-locale/client";
5
- import type { InputActions, InputState } from "@deepseek-ai/dsh-client-ui-conversation/client";
6
- import type { SlotRegistry } from "@deepseek-ai/dsh-client-ui-renderer/client";
7
- import type { LocaleDictOf } from "@deepseek-ai/dsh-client-ui-slots";
8
- import type { ConfigForm } from "@deepseek-ai/dsh-client-ui-settings/client";
9
- import type { DirPrepReader } from "./remote.js";
10
- declare const NS: LocaleNs;
11
- export interface DirEntryView {
12
- name: string;
13
- isDir: boolean;
14
- sizeBytes: number;
15
- snippet?: string;
16
- }
17
- export interface ImportSkips {
18
- tooLarge: number;
19
- unreadable: number;
20
- deeper: number;
21
- unnamed: number;
22
- /** 真实目标落在允许根之外(符号链接)被排除的项数;旧 host 不回这一位时读作 0。 */
23
- escaped: number;
24
- }
25
- export interface ContextResponse {
26
- ok: boolean;
27
- error?: string;
28
- cwd?: string;
29
- truncated?: boolean;
30
- entries?: DirEntryView[];
31
- }
32
- export interface OrganizeResponse {
33
- ok: boolean;
34
- error?: string;
35
- content?: string;
36
- }
37
- export declare function parseContextResponse(raw: unknown): ContextResponse;
38
- export declare function parseOrganizeResponse(raw: unknown): OrganizeResponse;
39
- /** 导入跳过计数 → 一句话(无计数时返回空串,调用方据此不追加任何文案)。 */
40
- export declare function formatImportSkips(t: Translate, skips: ImportSkips | undefined): string;
41
- export declare function formatContextSummary(resp: ContextResponse): string;
42
- export type BuiltinPhase = "idle" | "loading" | "ready" | "error";
43
- export interface BuiltinState {
44
- phase: BuiltinPhase;
45
- list: readonly TemplateEntry[];
46
- error: string;
47
- }
48
- export declare function builtinTemplatesSnapshot(): BuiltinState;
49
- /** 导出仅供单测:不经过 apply 的纯读取方法用例直接注入替身。 */
50
- export declare function setDirPrepReader(reader: DirPrepReader | undefined): void;
51
- export declare function loadBuiltinTemplates(): Promise<BuiltinState>;
52
- export declare function subscribeBuiltinTemplates(listener: () => void): () => void;
53
- export declare function resetBuiltinTemplates(): void;
54
- export type EntryForm = ConfigForm<Record<string, unknown>>;
55
- export interface TemplatesSnapshot {
56
- templates: readonly TemplateEntry[];
57
- fromSettings: boolean;
58
- builtinPhase: BuiltinPhase;
59
- builtinError: string;
60
- allowRoots: readonly string[];
61
- ready: boolean;
62
- writable: boolean;
63
- organizeTimeoutMs: number | undefined;
64
- }
65
- export interface PersistedView {
66
- ready: boolean;
67
- revision: number;
68
- templates: readonly TemplateEntry[];
69
- allowRoots: readonly string[];
70
- }
71
- export declare function persistError(t: Translate, persisted: Pick<PersistedView, "ready" | "revision" | "templates">, expected: readonly TemplateEntry[], action: string, opts?: {
72
- treatEmptyAsReverted?: boolean;
73
- }): string | undefined;
74
- export declare function rootsPersistError(t: Translate, persisted: Pick<PersistedView, "ready" | "revision" | "allowRoots">, expected: readonly string[], action: string): string | undefined;
75
- export interface KitProps {
76
- t: Translate;
77
- useCard: <TResult>(selector: (snap: TemplatesSnapshot) => TResult) => TResult;
78
- useInput?: <TResult>(selector: (state: Pick<InputState, "draft" | "draftRev" | "phase">) => TResult) => TResult;
79
- inputActions?: Pick<InputActions, "setDraft" | "captureInsertion" | "insertText">;
80
- sessionId?: string;
81
- }
82
- export interface ClientCtx {
83
- effect: Context["effect"];
84
- /** 官方的反射接口:远端接口经 `get("remote")` 取出来,不建立 inject 依赖(缺席只少一栏数据)。 */
85
- get: Context["get"];
86
- slots: Pick<SlotRegistry, "inject" | "register">;
87
- configForms: {
88
- get: (entryId: string) => EntryForm;
89
- };
90
- locale: {
91
- register: (ns: typeof NS, dicts: LocaleCatalog) => () => void;
92
- bind: (ns: typeof NS) => Translate;
93
- };
94
- }
95
- /** 官方 register 类型化重载的字典参数在本包命名空间上的实例化(两语必须齐)。 */
96
- export type LocaleCatalog = Record<BuiltInLocaleId, LocaleDictOf<typeof NS>>;
97
- declare const inject: string[];
98
- declare function apply(ctx: ClientCtx): void;
99
- export { inject, apply };
@@ -1 +0,0 @@
1
- export declare const CARD_STYLES: string;
@@ -1,30 +0,0 @@
1
- /**
2
- * `setTimeout` 延时上界(Node/V8 的 2^31-1 ms)。
3
- *
4
- * 超了它 V8 只往 stderr 打一条 TimeoutOverflowWarning,然后把延时**静默夹成 1 ms**。
5
- */
6
- export declare const MAX_TIMER_MS = 2147483647;
7
- /** 配置表单里读不到 `organizeTimeoutMs` 时的回落值(与 host 侧 ORGANIZE_TIMEOUT_MS 同值)。 */
8
- export declare const ORGANIZE_TIMEOUT_FALLBACK_MS = 120000;
9
- /** 客户端比 host 多等的余量:host 先超时,客户端留一点时间把它的回执读回来。 */
10
- export declare const ORGANIZE_TIMEOUT_SLACK_MS = 5000;
11
- /**
12
- * `organizeTimeoutMs` 的前端取表。
13
- *
14
- * 上界与 host 同为 `[1, MAX_TIMER_MS]`:host 自己夹了上界正是为了躲开上面那个静默的夹断,
15
- * 而这里是**唯一**发起润色读取方法调用的地方,它要是没夹,host 夹得再对也没用。
16
- *
17
- * @param value - 配置表单投影值
18
- * @returns `[1, MAX_TIMER_MS]` 区间内的整数;不合法时 undefined(回落默认)
19
- */
20
- export declare function rawOrganizeTimeoutMsOf(value: Record<string, unknown>): number | undefined;
21
- /**
22
- * 润色请求的客户端超时:host 的润色时限 + 余量,整条结果同样夹进 `[1, MAX_TIMER_MS]`。
23
- *
24
- * **加法之后还要再夹一次**,因为 `MAX_TIMER_MS + ORGANIZE_TIMEOUT_SLACK_MS` 自己就越界了
25
- * (实测 V8 把 2147488647 的延时夹成 1ms,点击润色立刻回「请求超时」)。
26
- *
27
- * @param raw - 配置表单投影里的润色时限(未夹)
28
- * @returns 可安全交给 setTimeout 的毫秒数
29
- */
30
- export declare function organizeFetchTimeoutMs(raw: number | undefined): number;
@@ -1,3 +0,0 @@
1
- import type { TemplateEntry } from "./templates.js";
2
- /** 内置精选角色默认模板(独立开发者高频角色;全量角色见 agents/ 目录,设置页可一键导入)。*/
3
- export declare const DEFAULT_TEMPLATES: readonly TemplateEntry[];
@@ -1,2 +0,0 @@
1
- /** 仓库目录名 → 下拉分组标签;未收录的目录回落目录名本身(见 templates.ts groupLabelOf)。 */
2
- export declare const AGENT_DIR_GROUP_LABELS: Readonly<Record<string, string>>;