@jayyuen66/dsh-dir-prep-organize 0.1.2-rc → 0.1.3
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 +21 -29
- package/README.zh-CN.md +24 -32
- package/client.js +423 -215
- package/cordis.patch.yml +12 -16
- package/host.js +380 -381
- package/package.json +49 -51
- package/types/host.d.ts +118 -77
- package/types/src/client-entry.d.ts +20 -7
- package/types/src/client-styles.d.ts +1 -0
- package/types/src/client-timeouts.d.ts +30 -0
- package/types/src/host-messages.d.ts +0 -2
- package/types/src/remote.d.ts +24 -0
- package/types/src/templates.d.ts +4 -4
- package/types/src/ui-messages.d.ts +5 -3
package/host.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// GENERATED by build-host.mjs — edit host.ts / src/*.ts, then run `node build-host.mjs`.
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import Schema from "@deepseek-ai/schemastery";
|
|
5
4
|
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
6
|
-
import {
|
|
7
|
-
import { guardTrust, isNonLoopbackBindHost } from "@jayyuen66/dsh-plugin-shared/lib/trust";
|
|
5
|
+
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
8
6
|
import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
|
|
9
7
|
import { isRecord } from "@jayyuen66/dsh-plugin-shared/lib/record";
|
|
10
8
|
import { errorText } from "@jayyuen66/dsh-plugin-shared/lib/errors";
|
|
@@ -50,7 +48,6 @@ const HOST_MESSAGES = {
|
|
|
50
48
|
emptyPrompt: "用户要求为空,无法整理",
|
|
51
49
|
noModelSelected: "当前无可用模型选择",
|
|
52
50
|
emptyOrganizeResult: "模型整理结果为空",
|
|
53
|
-
invalidJsonBody: "请求体不是合法 JSON",
|
|
54
51
|
fsUnavailable: "fs 服务不可用",
|
|
55
52
|
cwdUnknown: "无法确定会话 cwd(sessionId 缺失或会话不存在)",
|
|
56
53
|
modelServiceUnavailable: "agentDefaultModel 服务不可用",
|
|
@@ -98,7 +95,6 @@ const HOST_MESSAGES = {
|
|
|
98
95
|
emptyPrompt: "The request is empty: nothing to refine",
|
|
99
96
|
noModelSelected: "No model selection is available",
|
|
100
97
|
emptyOrganizeResult: "The model returned an empty result",
|
|
101
|
-
invalidJsonBody: "Request body is not valid JSON",
|
|
102
98
|
fsUnavailable: "fs service unavailable",
|
|
103
99
|
cwdUnknown: "Cannot determine the session cwd (sessionId missing or session unknown)",
|
|
104
100
|
modelServiceUnavailable: "agentDefaultModel service unavailable",
|
|
@@ -144,8 +140,8 @@ const AGENT_DIR_GROUP_LABELS = {
|
|
|
144
140
|
* scripts/gen-defaults-lib.mjs,键序 = 下拉分组展示序),本文件不再同名 re-export:
|
|
145
141
|
* 实测同名两处导出正是 fallow `duplicate_export`(severity=error)报出来的那一条,
|
|
146
142
|
* 而"两份名字保持同步"的纪律并不由 re-export 保证。表体仍是生成物;host 半引本文件的
|
|
147
|
-
* groupLabelOf/parseAgentFrontmatter
|
|
148
|
-
*
|
|
143
|
+
* groupLabelOf/parseAgentFrontmatter,精选集(生成物)也由 host 半引走、经
|
|
144
|
+
* `dirPrepOrganize.defaults` 方法按需下发,client 半不打包它。 */
|
|
149
145
|
/** 仓库目录名 → 分组标签(groupLabelOf(engineering) === "工程";未收录回落目录名)。
|
|
150
146
|
* 必须只认**自有属性**:`AGENT_DIR_GROUP_LABELS["constructor"]` 会命中原型上的
|
|
151
147
|
* function(`?? dirName` 不触发)→ TemplateEntry.group 拿到函数、JSON.stringify
|
|
@@ -259,15 +255,15 @@ function condenseRoleBody(body) {
|
|
|
259
255
|
//#endregion
|
|
260
256
|
//#region host.ts
|
|
261
257
|
/** 本包送进 `llm.stream({ messages })` 的整理请求帧是 **request-only 输入**:它从不落
|
|
262
|
-
* 任何持久消息位(`runOrganize` 只回 `{ content }
|
|
258
|
+
* 任何持久消息位(`runOrganize` 只回 `{ content }`,读面也不把帧身份回投给卡片),所以
|
|
263
259
|
* 按 0.1.7 它既不需要 `id` 也不带 `source`——证据三条:
|
|
264
|
-
* 1. installed `@deepseek-ai/dsh-llm/lib/types/types.d.ts
|
|
260
|
+
* 1. installed `@deepseek-ai/dsh-llm/lib/types/types.d.ts` 的 `RequestUserInput`
|
|
265
261
|
* 把两面都标成 `?: never`(`readonly id?: never` / `readonly source?: never`),
|
|
266
262
|
* `GenerateOptions.messages` 收的是 `RequestMessage[] = Message | RequestUserInput`
|
|
267
|
-
*
|
|
263
|
+
* (`GenerateOptions` 的字段注记 "a hand-built one-shot may include identity-free user
|
|
268
264
|
* inputs");
|
|
269
265
|
* 2. 持久那半边 `Message` 要的 `source.kind` 必须是**已声明**进 `MessageSourceMap` 的
|
|
270
|
-
* kind(installed `dsh-llm/lib/types/message.d.ts
|
|
266
|
+
* kind(installed `dsh-llm/lib/types/message.d.ts`),本包的
|
|
271
267
|
* `plugin:dir-prep-organize` 不在其中——旧代码同时带上 `id` 与该 kind,造的正是宿主
|
|
272
268
|
* 没有的第三种形状;
|
|
273
269
|
* 3. 宿主的持久化归属策略是「request-only 输入不需要持久身份」:把一次性提示构造成
|
|
@@ -277,12 +273,7 @@ function condenseRoleBody(body) {
|
|
|
277
273
|
* 故旧的 `ORGANIZE_SOURCE_KIND` 常量(连同只被它和帧 id 用到的 `PLUGIN_NAME`)一并撤下。
|
|
278
274
|
* 本包没有读回侧需要它:`extractRecentTurns` 只认真人 `kind === 'user'` 与模型
|
|
279
275
|
* `kind === 'model'`,从不按本包 kind 去重或断链,所以删除它不牵动任何 dedupe 配对。
|
|
280
|
-
* 同款 request-only 先例:harness `packages/compaction/compaction-basic/src/summarizer.ts
|
|
281
|
-
const CONTEXT_PATH = "/_dsh/dir-prep/context";
|
|
282
|
-
const MODEL_PATH = "/_dsh/dir-prep/model";
|
|
283
|
-
const ORGANIZE_PATH = "/_dsh/dir-prep/organize";
|
|
284
|
-
const IMPORT_PATH = "/_dsh/dir-prep/import";
|
|
285
|
-
const DEFAULTS_PATH = "/_dsh/dir-prep/default-templates";
|
|
276
|
+
* 同款 request-only 先例:harness `packages/compaction/compaction-basic/src/summarizer.ts`。 */
|
|
286
277
|
/** 插件自带角色库目录(agency-agents-zh 部门目录移入)。导入路径留空 = 全量导入此目录。 */
|
|
287
278
|
const AGENTS_DIR = path.join(import.meta.dirname, "agents");
|
|
288
279
|
/**
|
|
@@ -303,7 +294,7 @@ let defaultTemplatesPromise;
|
|
|
303
294
|
/**
|
|
304
295
|
* 产物导出值的守卫:只认「是数组」这一条。
|
|
305
296
|
*
|
|
306
|
-
*
|
|
297
|
+
* 元素级校验刻意不在这一层做——读面把这张表原样 JSON 序列化下发,渲染侧的兜底在 client
|
|
307
298
|
* 半;在这里逐条断言字段只会让守卫和生成脚本的字段集耦在一起,改一个字段要动两处。
|
|
308
299
|
* `Array.isArray` 本身会把 unknown 收窄成 `any[]`,经类型谓词再收一次,返回值才不是
|
|
309
300
|
* 不安全返回(no-unsafe-return)。
|
|
@@ -332,10 +323,10 @@ async function importDefaultTemplates() {
|
|
|
332
323
|
return defaultTemplatesFrom(await import(DEFAULT_TEMPLATES_URL.href));
|
|
333
324
|
}
|
|
334
325
|
/**
|
|
335
|
-
*
|
|
326
|
+
* 内置精选模板表:按需载入,永不静态导入。
|
|
336
327
|
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
328
|
+
* 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
|
|
329
|
+
* 读面,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一口径。
|
|
339
330
|
*
|
|
340
331
|
* @returns 内置精选模板表
|
|
341
332
|
*/
|
|
@@ -380,10 +371,6 @@ const SECRET_PATTERN = /(?:^|[^a-z0-9])(?:credentials?|secrets?|id_rsa|pem|p12|p
|
|
|
380
371
|
/** LLM 整理超时。 */
|
|
381
372
|
/** schema .default() 的单源(host 消费走 config 字段,不再直读常量)。 */
|
|
382
373
|
const ORGANIZE_TIMEOUT_MS = 12e4;
|
|
383
|
-
/** organize/import POST body 物理上限的 schema .default()(内存防爆纵深防御,非功能
|
|
384
|
-
* 截断:两条路由提交的都是整理草稿与模板产物,不是大文件本体;超大输入产物由模型
|
|
385
|
-
* context 报错反馈用户自行处理)。部署间需要更宽的走 `importBodyMaxBytes` 配置字段。 */
|
|
386
|
-
const DEFAULT_IMPORT_BODY_MAX_BYTES = 8388608;
|
|
387
374
|
/** 单个关键文件的摘要字节上限。harness 的 readWholeText 无上限,超限文件整份
|
|
388
375
|
* 跳过(不截半份——半份摘要会以"全量"的名义喂给模型,比没有更误导),
|
|
389
376
|
* 并计入 skipped.tooLarge 回报。 */
|
|
@@ -391,13 +378,12 @@ const MAX_SNIPPET_BYTES = 262144;
|
|
|
391
378
|
/** 单次整理带进模型的全部摘要的**总量**上限。
|
|
392
379
|
*
|
|
393
380
|
* 为什么需要总量而单文件上限不够:`maxSnippetBytes` 只管每个文件,而条目数不设上界
|
|
394
|
-
* (用户拍板)。于是 client 把所有摘要拼成 `entriesSummary` 原样回投 organize
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* 「organize 必然失败」。留足余量:JSON 转义与 client 侧的拼接还会再放大一截。 */
|
|
381
|
+
* (用户拍板)。于是 client 把所有摘要拼成 `entriesSummary` 原样回投 organize,请求
|
|
382
|
+
* 仍要过宿主 /api 网关的请求体上限,摘要一多就顶得过它,结果是 context 读面成功、
|
|
383
|
+
* UI 正常列出文件树,用户点「整理」才在网关处失败。这里给总量封顶,让「context 成功」
|
|
384
|
+
* 不再意味着「organize 必然失败」。留足余量:JSON 转义与 client 侧的拼接还会再放大一截。 */
|
|
399
385
|
const MAX_CONTEXT_TOTAL_BYTES = 2097152;
|
|
400
|
-
/** 文件读取并发上限:Promise.all
|
|
386
|
+
/** 文件读取并发上限:Promise.all 一次铺开会在导入内置角色库(整棵 agents/)时打满
|
|
401
387
|
* fd,EMFILE 抛错被单文件 catch 吞掉 → 条目静默丢失而仍报 ok:true。 */
|
|
402
388
|
const READ_CONCURRENCY = 8;
|
|
403
389
|
/** `readConcurrency` 的上界。再往上只是更快撞上 fd 上限——而那正是这个字段存在的
|
|
@@ -423,8 +409,6 @@ function clampInt(value, min, max, fallback) {
|
|
|
423
409
|
if (!Number.isFinite(value)) return fallback;
|
|
424
410
|
return Math.min(Math.max(Math.trunc(value), min), max);
|
|
425
411
|
}
|
|
426
|
-
/** organize 回填的 CSRF 头名(与 client-entry 侧一致)。 */
|
|
427
|
-
const CSRF_HEADER = "x-dir-prep-csrf";
|
|
428
412
|
/** 会话 id 的官方品牌构造:把边界上读来的裸 string 送进 `SessionStore.get`。 */
|
|
429
413
|
const sessionIdOf = (value) => brandString(value);
|
|
430
414
|
/** 服务形状守卫:value 是对象且具名成员是函数(绕开 `as Service` 断言)。 */
|
|
@@ -435,14 +419,11 @@ function hasFnMember(value, member) {
|
|
|
435
419
|
function isSettingsService(value) {
|
|
436
420
|
return hasFnMember(value, "describe");
|
|
437
421
|
}
|
|
438
|
-
function isWebServerService(value) {
|
|
439
|
-
return hasFnMember(value, "register") && hasFnMember(value, "registerFallback");
|
|
440
|
-
}
|
|
441
422
|
function isSessionsService(value) {
|
|
442
423
|
return hasFnMember(value, "get");
|
|
443
424
|
}
|
|
444
425
|
function isFsService(value) {
|
|
445
|
-
return hasFnMember(value, "resolve");
|
|
426
|
+
return hasFnMember(value, "resolve") && hasFnMember(value, "stat");
|
|
446
427
|
}
|
|
447
428
|
function isLlmService(value) {
|
|
448
429
|
return hasFnMember(value, "stream");
|
|
@@ -462,7 +443,7 @@ function fillTemplate(template, tokens) {
|
|
|
462
443
|
return text;
|
|
463
444
|
}
|
|
464
445
|
/** 有界并发的 map:批内并行、批间串行等待,从而把同时在打开的文件数压在 limit 以内。
|
|
465
|
-
* 不用 `Promise.all(items.map(...))`
|
|
446
|
+
* 不用 `Promise.all(items.map(...))` 一次铺开——导入内置库(整棵 agents/ 的 .md)会把
|
|
466
447
|
* 进程 fd 打满,EMFILE 抛错被单文件 catch 吞掉 → 条目静默丢失而仍报 ok:true。
|
|
467
448
|
* 分片用**递归**而非 for+await:批间等待是并发上限的实现手段,而 await-in-loop
|
|
468
449
|
* 在本包严格档里是 error(不用 disable 注释换取绿灯)。
|
|
@@ -488,9 +469,13 @@ function isKeyFile(name) {
|
|
|
488
469
|
return KEY_EXT.has(lower.slice(dot));
|
|
489
470
|
}
|
|
490
471
|
/** 关键文件摘要:全量正文(用户拍板不截断——上下文完整性优先,
|
|
491
|
-
* 模型 context 超限由模型报错提示用户自行处理)。仅 trim 去头尾空白。
|
|
472
|
+
* 模型 context 超限由模型报错提示用户自行处理)。仅 trim 去头尾空白。
|
|
473
|
+
* ⚠ 行尾先归一:官方 readText 承诺 byte-for-byte(**不归一 CRLF**,宿主 fs-local
|
|
474
|
+
* 源码注明),于是 Windows 仓库里的 `\r` 会原样进摘要;client 侧的折行压平只换
|
|
475
|
+
* `\n`,`\r` 就留在发给模型的 prompt 里(既污染文本又让行数统计失真)。
|
|
476
|
+
* 归一放在这一层而不是 client:host 是「真实字节 → 模型文本」的唯一转换点。 */
|
|
492
477
|
function makeSnippet(content) {
|
|
493
|
-
const trimmed = content.trim();
|
|
478
|
+
const trimmed = content.replaceAll("\r\n", "\n").replaceAll("\r", "\n").trim();
|
|
494
479
|
return trimmed.length === 0 ? "" : trimmed;
|
|
495
480
|
}
|
|
496
481
|
/**
|
|
@@ -536,7 +521,8 @@ function skipCounts() {
|
|
|
536
521
|
tooLarge: 0,
|
|
537
522
|
unreadable: 0,
|
|
538
523
|
deeper: 0,
|
|
539
|
-
unnamed: 0
|
|
524
|
+
unnamed: 0,
|
|
525
|
+
escaped: 0
|
|
540
526
|
};
|
|
541
527
|
}
|
|
542
528
|
/** 关键文件 → 摘要(字节上限 + 未知大小一律跳过:readWholeText 无上限,
|
|
@@ -566,14 +552,13 @@ async function readSnippetBounded(fs, entry, maxBytes) {
|
|
|
566
552
|
const DEFAULT_LIMITS = {
|
|
567
553
|
organizeTimeoutMs: ORGANIZE_TIMEOUT_MS,
|
|
568
554
|
maxSnippetBytes: MAX_SNIPPET_BYTES,
|
|
569
|
-
readConcurrency: READ_CONCURRENCY
|
|
570
|
-
importBodyMaxBytes: DEFAULT_IMPORT_BODY_MAX_BYTES
|
|
555
|
+
readConcurrency: READ_CONCURRENCY
|
|
571
556
|
};
|
|
572
557
|
/**
|
|
573
|
-
*
|
|
558
|
+
* 部署值的唯一收口:把会致命的几个数夹进安全区间,再交给读面。
|
|
574
559
|
*
|
|
575
|
-
* 为什么放在这里而不是各消费点:`limitsOf()`
|
|
576
|
-
*
|
|
560
|
+
* 为什么放在这里而不是各消费点:`limitsOf()` 是 context/organize/importTemplates
|
|
561
|
+
* 三个读面读 limits 的**唯一入口**,一处收口就不会漏掉将来新增的读面;而散在
|
|
577
562
|
* 各消费点夹,哪天新增一个调用点就等于新增一个漏洞。
|
|
578
563
|
*
|
|
579
564
|
* 夹哪两个、为什么:
|
|
@@ -583,9 +568,9 @@ const DEFAULT_LIMITS = {
|
|
|
583
568
|
* - `organizeTimeoutMs` → `[1, 2^31-1]`。上界超了会被 `setTimeout` 静默夹成 1 ms,
|
|
584
569
|
* 「调大超时」变成「立刻失败」。
|
|
585
570
|
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
571
|
+
* 剩下 `maxSnippetBytes` **故意不夹**:schema 已经挡住 NaN/±Infinity/负数/小数,
|
|
572
|
+
* 唯一还能配出来的越界值 `0` 有确定且已记账的行为(全跳过并计 tooLarge),那是用户
|
|
573
|
+
* 的显式意图,不该被悄悄改写。
|
|
589
574
|
*
|
|
590
575
|
* @param limits - 未经夹位的部署值
|
|
591
576
|
* @returns 两项关键值已夹位、其余原样透传的新对象
|
|
@@ -613,8 +598,9 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
613
598
|
try {
|
|
614
599
|
const dirTarget = await fs.resolve(cwd);
|
|
615
600
|
const raw = await fs.listDir(dirTarget);
|
|
616
|
-
const keyFiles = raw.filter((item) => item.type === "file" && isKeyFile(item.name));
|
|
601
|
+
const keyFiles = raw.filter((item) => item.type === "file" && isKeyFile(item.name) && fs.contains(dirTarget, item.target));
|
|
617
602
|
const skipped = skipCounts();
|
|
603
|
+
skipped.escaped = raw.filter((item) => item.type === "file" && isKeyFile(item.name) && !fs.contains(dirTarget, item.target)).length;
|
|
618
604
|
const reads = await mapBounded(keyFiles, scan.readConcurrency, async (item) => ({
|
|
619
605
|
targetKey: item.target.targetKey,
|
|
620
606
|
...await readSnippetBounded(fs, item, scan.maxSnippetBytes)
|
|
@@ -636,7 +622,7 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
636
622
|
sizeBytes: item.size ?? 0,
|
|
637
623
|
snippet: item.type === "directory" ? void 0 : snippetByTarget.get(item.target.targetKey)
|
|
638
624
|
})),
|
|
639
|
-
truncated: skipped.tooLarge + skipped.unreadable > 0,
|
|
625
|
+
truncated: skipped.tooLarge + skipped.unreadable + skipped.escaped > 0,
|
|
640
626
|
skipped
|
|
641
627
|
};
|
|
642
628
|
} catch (error) {
|
|
@@ -651,7 +637,7 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
651
637
|
}
|
|
652
638
|
}
|
|
653
639
|
/**
|
|
654
|
-
*
|
|
640
|
+
* 导入路径安全策略(只读读面,无副作用:不调 LLM、不写盘,结果回给设置卡)。
|
|
655
641
|
* 规则名:「cwd 内 + 内置角色目录 allowlist」。
|
|
656
642
|
*
|
|
657
643
|
* 允许根只有三类(除此之外**一律拒绝**,含所有绝对路径):
|
|
@@ -660,7 +646,7 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
660
646
|
* - 用户在设置 `importAllowRoots` 里逐条登记的目录。
|
|
661
647
|
*
|
|
662
648
|
* 拒绝规则(确定性,测试锁死):
|
|
663
|
-
* - 空串/纯空白不是路径 →
|
|
649
|
+
* - 空串/纯空白不是路径 → 拒(读面把「精确空串」当作"导入内置库"的哨兵并在调用前
|
|
664
650
|
* 拦掉,走到这里说明调用方没做归一,绝不静默降级成"全量导入");
|
|
665
651
|
* - **先查原始串的段**再查解析结果:path.resolve 会把 `..` 归一掉,只查解析后的
|
|
666
652
|
* 绝对路径等于放行 `../../etc/passwd.md`(审计复现);原始串只判 `.` / `..`,
|
|
@@ -678,30 +664,35 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
678
664
|
* 门禁后仍要求每个文件能解析出非空 frontmatter name(parseAgentFrontmatter),
|
|
679
665
|
* 否则跳过并计数——绝不返回任意文件原文,只产出模板条目形状。
|
|
680
666
|
*/
|
|
667
|
+
/** 路径拆段(**逐段**比较而非字符串前缀:`/home/dev/project-two/x.md` 会骗过
|
|
668
|
+
* `startsWith("/home/dev/project")`,前缀式包含判断等于放行兄弟目录)。
|
|
669
|
+
* 两种分隔符都拆:win32 的 `path.resolve`/`path.relative` 产出 `\`,只按 `/` 拆会
|
|
670
|
+
* 把整条路径当成一段,于是合法子路径被判成越界、`..\` 也漏过逐段校验。 */
|
|
671
|
+
function pathSegments(absolute) {
|
|
672
|
+
return absolute.split(/[\\/]/u).filter((token) => token.length > 0);
|
|
673
|
+
}
|
|
681
674
|
/** 逐段校验:段为 "." / ".." 一律拒(归一前必须先拦,否则 path.resolve 吃掉 `..`);
|
|
682
675
|
* checkHidden=true 时额外拒隐藏段(凭据/敏感目录,如 `.ssh`)。 */
|
|
683
676
|
function pathTokensError(absolute, checkHidden, messages) {
|
|
684
677
|
let errorMessage;
|
|
685
|
-
for (const token of absolute
|
|
678
|
+
for (const token of pathSegments(absolute)) if (token === "." || token === ".." || checkHidden && token.startsWith(".")) {
|
|
686
679
|
errorMessage = messages.illegalPathSegment;
|
|
687
680
|
break;
|
|
688
681
|
}
|
|
689
682
|
return errorMessage;
|
|
690
683
|
}
|
|
691
|
-
/**
|
|
692
|
-
* `
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return
|
|
684
|
+
/** child 是否落在 root 之内(含"child 就是 root 本身"= 导入根目录)。
|
|
685
|
+
* 包含关系交给 `path.relative`:win32 的盘符大小写由它的平台语义收口
|
|
686
|
+
* (实测 `path.win32.relative("C:\\Users\\Me\\Roles", "c:\\users\\me\\roles\\x.md")`
|
|
687
|
+
* 给出 `x.md`),而兄弟目录仍以 `..` 开头被拒。 */
|
|
688
|
+
function isWithinRoot(root, child) {
|
|
689
|
+
const relative = path.relative(root, child);
|
|
690
|
+
if (relative === "") return true;
|
|
691
|
+
return !path.isAbsolute(relative) && pathSegments(relative)[0] !== "..";
|
|
699
692
|
}
|
|
700
693
|
function toImportRoot(rawPath, label) {
|
|
701
|
-
const absolute = path.resolve(rawPath);
|
|
702
694
|
return {
|
|
703
|
-
absolute,
|
|
704
|
-
segments: pathSegments(absolute),
|
|
695
|
+
absolute: path.resolve(rawPath),
|
|
705
696
|
label
|
|
706
697
|
};
|
|
707
698
|
}
|
|
@@ -720,6 +711,12 @@ function outsideRootsError(absolute, roots, messages) {
|
|
|
720
711
|
const zones = roots.map((root) => `${root.label} ${root.absolute}`);
|
|
721
712
|
return fillTemplate(messages.outsideRoots, [["{zones}", zones.join(messages.zoneSeparator)], ["{absolute}", absolute]]);
|
|
722
713
|
}
|
|
714
|
+
/** 真实目标是否落在**每一个**允许根之外。判据交给后端(`contains` 用它自己的世界判
|
|
715
|
+
* 包含关系),而不是再写第二条字符串规则:符号链接让「路径长得合法」与「读的是哪个
|
|
716
|
+
* 对象」分叉,只有后端能收这个叉。一个根命中即放行;全落空即为逃逸。 */
|
|
717
|
+
async function escapesAllRoots(fs, target, roots) {
|
|
718
|
+
return !(await Promise.all(roots.map((root) => fs.resolve(root.absolute)))).some((root) => fs.contains(root, target));
|
|
719
|
+
}
|
|
723
720
|
function importPathError(requested, cwd, allowRoots, messages) {
|
|
724
721
|
const trimmed = requested.trim();
|
|
725
722
|
if (trimmed.length === 0) return messages.emptyImportPath;
|
|
@@ -728,8 +725,7 @@ function importPathError(requested, cwd, allowRoots, messages) {
|
|
|
728
725
|
if (!path.isAbsolute(trimmed) && cwd === void 0) return messages.relativeNeedsCwd;
|
|
729
726
|
const absolute = path.resolve(cwd ?? "", trimmed);
|
|
730
727
|
const roots = importRootsOf(cwd, allowRoots, messages);
|
|
731
|
-
const
|
|
732
|
-
const matched = roots.find((root) => withinRoot(child, root.segments));
|
|
728
|
+
const matched = roots.find((root) => isWithinRoot(root.absolute, absolute));
|
|
733
729
|
if (matched === void 0) return outsideRootsError(absolute, roots, messages);
|
|
734
730
|
return pathTokensError(path.relative(matched.absolute, absolute), true, messages);
|
|
735
731
|
}
|
|
@@ -739,8 +735,12 @@ function agentEntryFromFile(slug, dirName, info, collided) {
|
|
|
739
735
|
const text = condenseRoleBody(info.body);
|
|
740
736
|
let result;
|
|
741
737
|
if (text.length > 0) {
|
|
738
|
+
let suffix = collided.size;
|
|
742
739
|
let id = slug;
|
|
743
|
-
while (collided.has(id))
|
|
740
|
+
while (collided.has(id)) {
|
|
741
|
+
suffix += 1;
|
|
742
|
+
id = `${slug}-${String(suffix)}`;
|
|
743
|
+
}
|
|
744
744
|
collided.add(id);
|
|
745
745
|
result = {
|
|
746
746
|
id,
|
|
@@ -761,9 +761,15 @@ function isVisibleDirectory(child) {
|
|
|
761
761
|
function isVisibleMdFile(child) {
|
|
762
762
|
return child.type === "file" && child.name.endsWith(".md") && !child.name.startsWith(".");
|
|
763
763
|
}
|
|
764
|
-
/** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。
|
|
765
|
-
|
|
766
|
-
|
|
764
|
+
/** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。
|
|
765
|
+
* `skipped` 就地累加 escaped 计数:被 contains 拦下的链接文件如果不数出来,
|
|
766
|
+
* 用户只会看到「导入 3 条」而不知道有一份被安全闸门挡在门外。 */
|
|
767
|
+
function mdCandidates(fs, parent, children, dirName, skipped) {
|
|
768
|
+
return children.filter((child) => isVisibleMdFile(child)).filter((child) => {
|
|
769
|
+
const contained = fs.contains(parent, child.target);
|
|
770
|
+
if (!contained) skipped.escaped += 1;
|
|
771
|
+
return contained;
|
|
772
|
+
}).map((child) => ({
|
|
767
773
|
name: child.name,
|
|
768
774
|
dirName,
|
|
769
775
|
target: child.target,
|
|
@@ -791,10 +797,44 @@ async function readCandidate(fs, file, maxBytes) {
|
|
|
791
797
|
function importGate(requested, cwd, allowRoots, messages, skip) {
|
|
792
798
|
return skip ? void 0 : importPathError(requested, cwd, allowRoots, messages);
|
|
793
799
|
}
|
|
794
|
-
/**
|
|
795
|
-
*
|
|
796
|
-
|
|
797
|
-
|
|
800
|
+
/** 单个候选的字节上限判定:与 readSnippetBounded 同一口径——**size 未知即拒读**。
|
|
801
|
+
*
|
|
802
|
+
* 为什么单文件分支也需要这道门:目录分支的每个候选都自带 `listDir` 给的 `size`,于是
|
|
803
|
+
* `readCandidate` 能在读之前判上限;而单文件导入只有一个 `resolve` 出来的 target,
|
|
804
|
+
* 不 `stat` 就只能盲读——官方 `readText` 自述"读整份文本"、**没有任何上限**,于是一个
|
|
805
|
+
* 几 MB 的 .md 会整份进宿主内存(实测把 maxSnippetBytes 配成 1024,3 MB 的文件照样
|
|
806
|
+
* 被读进来并返回成模板条目)。宁可少导一条并如实计数,也不拿宿主进程的存亡去赌。
|
|
807
|
+
*
|
|
808
|
+
* @returns 通过时给出字节数,未通过时给出 undefined(调用方计 tooLarge)。
|
|
809
|
+
*/
|
|
810
|
+
async function fileBytesWithin(fs, target, maxBytes) {
|
|
811
|
+
const size = (await fs.stat(target).catch(() => null))?.size;
|
|
812
|
+
return size === void 0 || size > maxBytes ? void 0 : size;
|
|
813
|
+
}
|
|
814
|
+
/** 单文件导入(路径直指一个角色 .md):字节超限或读失败各计各的;解析不出 name →
|
|
815
|
+
* 记 unnamed 并回原因;读到了但正文提炼为空 → 空条目列表(agentEntryFromFile
|
|
816
|
+
* 返回 undefined 的形状)。 */
|
|
817
|
+
async function importFromFile(args, absolute) {
|
|
818
|
+
const { fs, target, limits, skipped, messages } = args;
|
|
819
|
+
if (await fileBytesWithin(fs, target, limits.maxSnippetBytes) === void 0) {
|
|
820
|
+
skipped.tooLarge += 1;
|
|
821
|
+
return {
|
|
822
|
+
entries: [],
|
|
823
|
+
truncated: true,
|
|
824
|
+
skipped
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
let info;
|
|
828
|
+
try {
|
|
829
|
+
info = parseAgentFrontmatter(await fs.readText(target));
|
|
830
|
+
} catch {
|
|
831
|
+
skipped.unreadable += 1;
|
|
832
|
+
return {
|
|
833
|
+
entries: [],
|
|
834
|
+
truncated: true,
|
|
835
|
+
skipped
|
|
836
|
+
};
|
|
837
|
+
}
|
|
798
838
|
if (info === void 0) {
|
|
799
839
|
skipped.unnamed = 1;
|
|
800
840
|
return {
|
|
@@ -811,11 +851,29 @@ async function importFromFile(fs, absolute, target, skipped, messages) {
|
|
|
811
851
|
skipped
|
|
812
852
|
};
|
|
813
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* listDir 的降级读面:列不出来(EACCES / ELOOP / 枚举期间被删)时记 unreadable 并交空表。
|
|
856
|
+
*
|
|
857
|
+
* 为什么必须有:`mapBounded` 内部是 `Promise.all`,worker 一抛就整批 reject,把**同一批
|
|
858
|
+
* 里已经读完的结果一起丢掉**,上层 `collectAgentTemplates` 的 catch 再把整次导入变成
|
|
859
|
+
* 「导入失败」。实测:一个 chmod 000 的子目录就让同层读得好好的 .md 一条都进不来。
|
|
860
|
+
* 文件级读取早就有这道降级(`readCandidate` → `{kind:"unreadable"}`),目录枚举却漏了,
|
|
861
|
+
* 口径不一致;`mapBounded` 自己的注释也写着「worker 自己负责错误降级(不抛)」。
|
|
862
|
+
*/
|
|
863
|
+
async function listDirOrUnreadable(fs, target, skipped) {
|
|
864
|
+
try {
|
|
865
|
+
return await fs.listDir(target);
|
|
866
|
+
} catch {
|
|
867
|
+
skipped.unreadable += 1;
|
|
868
|
+
return [];
|
|
869
|
+
}
|
|
870
|
+
}
|
|
814
871
|
/** 更深层(第三层)目录:只清点可见 .md 数、不读正文——扫描深度是设计上限,
|
|
815
|
-
* 但静默省略是 bug(内置库 game-development/<engine>/*.md 曾整批消失)。
|
|
816
|
-
|
|
872
|
+
* 但静默省略是 bug(内置库 game-development/<engine>/*.md 曾整批消失)。
|
|
873
|
+
* 列不出来的深层目录按 unreadable 计数,不让整次导入归零。 */
|
|
874
|
+
async function countDeeperMdFiles(fs, deepDirs, readConcurrency, skipped) {
|
|
817
875
|
const counts = await mapBounded(deepDirs, readConcurrency, async (dir) => {
|
|
818
|
-
return (await fs
|
|
876
|
+
return (await listDirOrUnreadable(fs, dir, skipped)).filter((child) => isVisibleMdFile(child)).length;
|
|
819
877
|
});
|
|
820
878
|
let total = 0;
|
|
821
879
|
for (const count of counts) total += count;
|
|
@@ -848,11 +906,11 @@ function pushReadResult(read, entries, collided, skipped) {
|
|
|
848
906
|
* 上层 catch 仍要报出已经数到的那部分。 */
|
|
849
907
|
async function importFromDirectory(fs, absolute, target, limits, skipped) {
|
|
850
908
|
const rootChildren = await fs.listDir(target);
|
|
851
|
-
const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute));
|
|
909
|
+
const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute), skipped);
|
|
852
910
|
const subScans = await mapBounded(rootChildren.filter((child) => isVisibleDirectory(child)).map((child) => child.target).toSorted((left, right) => left.displayPath.localeCompare(right.displayPath)), limits.readConcurrency, async (sub) => {
|
|
853
|
-
const children = await fs
|
|
911
|
+
const children = await listDirOrUnreadable(fs, sub, skipped);
|
|
854
912
|
return {
|
|
855
|
-
files: mdCandidates(fs,
|
|
913
|
+
files: mdCandidates(fs, target, children, path.basename(sub.displayPath), skipped),
|
|
856
914
|
deeper: children.filter((child) => isVisibleDirectory(child)).map((child) => child.target)
|
|
857
915
|
};
|
|
858
916
|
});
|
|
@@ -862,7 +920,7 @@ async function importFromDirectory(fs, absolute, target, limits, skipped) {
|
|
|
862
920
|
subFiles.push(...scan.files);
|
|
863
921
|
deepDirs.push(...scan.deeper);
|
|
864
922
|
}
|
|
865
|
-
const deeperMdCount = await countDeeperMdFiles(fs, deepDirs, limits.readConcurrency);
|
|
923
|
+
const deeperMdCount = await countDeeperMdFiles(fs, deepDirs, limits.readConcurrency, skipped);
|
|
866
924
|
skipped.deeper += deeperMdCount;
|
|
867
925
|
const reads = await mapBounded([...rootFiles, ...subFiles], limits.readConcurrency, (file) => readCandidate(fs, file, limits.maxSnippetBytes));
|
|
868
926
|
const entries = [];
|
|
@@ -876,10 +934,11 @@ async function importFromDirectory(fs, absolute, target, limits, skipped) {
|
|
|
876
934
|
* truncated 反映"确实有东西没进来",不再硬编码 false。
|
|
877
935
|
* skipPolicy 用于内置角色库自检(AGENTS_DIR 是策略里的允许根,用户输入路径正常
|
|
878
936
|
* 不需要它;保留这个开关只为让"内置全量导入"不依赖安装位置是否命中隐藏段判断)。
|
|
879
|
-
* allowRoots = 设置 importAllowRoots
|
|
937
|
+
* allowRoots = 设置 importAllowRoots 登记的额外允许目录(由读面注入)。 */
|
|
880
938
|
async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
|
|
881
939
|
const limits = opts?.limits ?? DEFAULT_LIMITS;
|
|
882
|
-
const
|
|
940
|
+
const allowRoots = opts?.allowRoots ?? [];
|
|
941
|
+
const policyError = importGate(requested, cwd, allowRoots, messages, opts?.skipPolicy === true);
|
|
883
942
|
if (policyError !== void 0) return {
|
|
884
943
|
entries: [],
|
|
885
944
|
truncated: false,
|
|
@@ -890,10 +949,26 @@ async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
|
|
|
890
949
|
const skipped = skipCounts();
|
|
891
950
|
try {
|
|
892
951
|
const target = await fs.resolve(absolute);
|
|
893
|
-
|
|
952
|
+
const roots = importRootsOf(cwd, allowRoots, messages);
|
|
953
|
+
if (await escapesAllRoots(fs, target, roots)) {
|
|
954
|
+
skipped.escaped = 1;
|
|
955
|
+
return {
|
|
956
|
+
entries: [],
|
|
957
|
+
truncated: true,
|
|
958
|
+
skipped,
|
|
959
|
+
error: outsideRootsError(target.displayPath, roots, messages)
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
if (absolute.endsWith(".md")) return await importFromFile({
|
|
963
|
+
fs,
|
|
964
|
+
target,
|
|
965
|
+
limits,
|
|
966
|
+
skipped,
|
|
967
|
+
messages
|
|
968
|
+
}, absolute);
|
|
894
969
|
return {
|
|
895
970
|
entries: await importFromDirectory(fs, absolute, target, limits, skipped),
|
|
896
|
-
truncated: skipped.tooLarge + skipped.unreadable + skipped.deeper > 0,
|
|
971
|
+
truncated: skipped.tooLarge + skipped.unreadable + skipped.deeper + skipped.escaped > 0,
|
|
897
972
|
skipped
|
|
898
973
|
};
|
|
899
974
|
} catch (error) {
|
|
@@ -1013,7 +1088,7 @@ async function drainStreamToText(stream, messages) {
|
|
|
1013
1088
|
}
|
|
1014
1089
|
return text.trim();
|
|
1015
1090
|
}
|
|
1016
|
-
/**
|
|
1091
|
+
/** 整理入口(读面调用;导出供测试注入假 stream)。失败文案与 system 提示都来自
|
|
1017
1092
|
* 注入的字典,本函数不读设置。 */
|
|
1018
1093
|
async function runOrganize(llm, input, messages, timeoutMs = ORGANIZE_TIMEOUT_MS, callerSignal) {
|
|
1019
1094
|
const { prompt } = input;
|
|
@@ -1072,10 +1147,10 @@ const TemplateEntrySchema = Schema.object({
|
|
|
1072
1147
|
/** settings 命名空间与 loader 行 config 共用同一 schema(单源,防漂移)。
|
|
1073
1148
|
* 值名退避为 configSchema:避免与同名 interface Config 触发 no-redeclare;
|
|
1074
1149
|
* 外部仍以 `Config` 名导入(export as),公开 API 不变。
|
|
1075
|
-
* 写入校验由 dsh-settings 在持久化前按此 schema
|
|
1150
|
+
* 写入校验由 dsh-settings 在持久化前按此 schema 完成;凡是要出现在卡上的字段都必须 `.volatile()`
|
|
1076
1151
|
* ——没有任何 volatile 字段的条目会被宿主 describe() 整条跳过
|
|
1077
|
-
* (packages/settings/settings/src/index.ts
|
|
1078
|
-
* `has no volatile fields
|
|
1152
|
+
* (packages/settings/settings/src/index.ts),设置卡读不到、写入则抛
|
|
1153
|
+
* `has no volatile fields`。
|
|
1079
1154
|
*
|
|
1080
1155
|
* 旧 `settings.register(ns, Config, { base })` 的 base 底座取消,逐字段落到 `.default(...)`:
|
|
1081
1156
|
* - importAllowRoots:`.default([])`。**空表是策略不是缺省占位**——登记目录是用户的
|
|
@@ -1083,14 +1158,14 @@ const TemplateEntrySchema = Schema.object({
|
|
|
1083
1158
|
* 见 importPathError);
|
|
1084
1159
|
* - templates:**标 volatile、不给默认**。内置精选集(scripts/gen-defaults.mjs 从
|
|
1085
1160
|
* agents/ 角色库生成的 src/default-templates.generated.ts,~640 KB)由 **host 半**
|
|
1086
|
-
* 持有、经
|
|
1161
|
+
* 持有、经 `dirPrepOrganize.defaults` 方法按需下发,client 拉到后作回落:⚠ 不给默认**不等于**读回 undefined——schemastery 对 array 字段把缺失
|
|
1087
1162
|
* 值 cast 成 `[]`(实测 `configSchema["~standard"].validate({})` 之后 `templates` 引用
|
|
1088
|
-
* `.get() === []`),宿主 describe() 又只丢 undefined
|
|
1163
|
+
* `.get() === []`),宿主 describe() 又只丢 undefined 位(`SettingsForms.projectForm`),
|
|
1089
1164
|
* 所以「未设置」递到客户端看到的就是一张空表。回落判据因此落在 client 半
|
|
1090
1165
|
* (client-entry.ts 的 `fromSettings`:空表按未设置处理),设置卡「恢复默认」=
|
|
1091
1166
|
* `unset("templates")` 且复读空值按已回落处理,故「缺失」「空表」「内置」三者同义。
|
|
1092
|
-
* 写成 `.default(...)` 会让宿主每次 describe() 都重新序列化这 640 KB(index.ts
|
|
1093
|
-
* `JSON.stringify([uid, schema.toJSON(), entry.options.config])` 取指纹,schema.ts
|
|
1167
|
+
* 写成 `.default(...)` 会让宿主每次 describe() 都重新序列化这 640 KB(index.ts 对
|
|
1168
|
+
* `JSON.stringify([uid, schema.toJSON(), entry.options.config])` 取指纹,schema.ts
|
|
1094
1169
|
* 的 plainSchema 保留 meta.default),所以内置集不进 schema、由 host 半端点按需下发;而既然空表就是
|
|
1095
1170
|
* 「未设置」的运行时形状,回落判据仍由 client 半出。 */
|
|
1096
1171
|
const configShape = {
|
|
@@ -1098,8 +1173,7 @@ const configShape = {
|
|
|
1098
1173
|
importAllowRoots: Schema.array(Schema.string()).default([]).volatile(),
|
|
1099
1174
|
organizeTimeoutMs: Schema.natural().default(ORGANIZE_TIMEOUT_MS).volatile(),
|
|
1100
1175
|
maxSnippetBytes: Schema.natural().default(MAX_SNIPPET_BYTES),
|
|
1101
|
-
readConcurrency: Schema.natural().default(READ_CONCURRENCY)
|
|
1102
|
-
importBodyMaxBytes: Schema.natural().default(DEFAULT_IMPORT_BODY_MAX_BYTES)
|
|
1176
|
+
readConcurrency: Schema.natural().default(READ_CONCURRENCY)
|
|
1103
1177
|
};
|
|
1104
1178
|
const configSchema = Schema.object(configShape);
|
|
1105
1179
|
/** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
|
|
@@ -1112,29 +1186,13 @@ function importAllowRootsOf(raw) {
|
|
|
1112
1186
|
}
|
|
1113
1187
|
return roots;
|
|
1114
1188
|
}
|
|
1115
|
-
/** 注入的服务面:
|
|
1189
|
+
/** 注入的服务面:settings 为硬依赖(cordis 等它就绪才 apply)。
|
|
1116
1190
|
* 0.1.7 起命名空间是隐式的(= 本条目在 cordis.patch.yml 里的裸 id,可编辑字段取自
|
|
1117
1191
|
* 导出的 Config),所以 settings 不再是「注册的前提」而是「页面策略(configure)与
|
|
1118
1192
|
* 跨命名空间读(describe)」的载体;设置页只派发「host 已 serve 的命名空间 ∩
|
|
1119
1193
|
* settings.plugin.item 卡」(dsh-client-ui-settings-plugins 源码语义),configure 必须
|
|
1120
1194
|
* 发生在 apply 期,故仍硬注入。sessions/fs/llm/agentDefaultModel 仍可选读。 */
|
|
1121
1195
|
const inject = ["settings"];
|
|
1122
|
-
/** 405 回执(四个端点同形,抽出来避免重复)。 */
|
|
1123
|
-
function methodNotAllowed(res, allow) {
|
|
1124
|
-
res.setHeader("Allow", allow);
|
|
1125
|
-
sendJson(res, 405, {
|
|
1126
|
-
ok: false,
|
|
1127
|
-
error: `${allow} only`
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
/** JSON.parse 失败回执(读 body 与解析分离:超限/坏流由 guardBody 回 413/400,
|
|
1131
|
-
* 这里只对"确实读到了但不是 JSON"回 400)。文案取自字典,故由调用方现读后传入。 */
|
|
1132
|
-
function sendBadRequestJson(res, error) {
|
|
1133
|
-
sendJson(res, 400, {
|
|
1134
|
-
ok: false,
|
|
1135
|
-
error
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
1196
|
/** 当前默认模型解析(缺服务/抛错 → undefined)。 */
|
|
1139
1197
|
function resolveModel(deps) {
|
|
1140
1198
|
const current = deps.agentDefaultModel?.();
|
|
@@ -1184,42 +1242,42 @@ function importRequestOf(parsed, messages) {
|
|
|
1184
1242
|
sessionId: typeof sessionId === "string" ? sessionId : null
|
|
1185
1243
|
};
|
|
1186
1244
|
}
|
|
1187
|
-
/**
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1245
|
+
/** 内置精选模板表的读面。两头都按需:表在独立产物 templates.data.mjs 里,第一次被
|
|
1246
|
+
* 调用时才 import;client 首次打开「模板」下拉时才拉这一发。 */
|
|
1247
|
+
async function defaultsPayload(scope) {
|
|
1248
|
+
try {
|
|
1249
|
+
return {
|
|
1250
|
+
ok: true,
|
|
1251
|
+
templates: await (scope.deps.loadDefaultTemplates ?? loadDefaultTemplates)()
|
|
1252
|
+
};
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
return {
|
|
1255
|
+
ok: false,
|
|
1256
|
+
error: errorText(error)
|
|
1257
|
+
};
|
|
1193
1258
|
}
|
|
1259
|
+
}
|
|
1260
|
+
/** 目录上下文:缺 fs / 缺 cwd / 扫描报错各回一句,成功才下发条目表。 */
|
|
1261
|
+
async function contextPayload(scope, sessionId) {
|
|
1262
|
+
const messages = scope.messagesOf();
|
|
1194
1263
|
try {
|
|
1195
1264
|
const fs = scope.deps.fs?.();
|
|
1196
|
-
const sessionId = queryParam(req, "sessionId");
|
|
1197
1265
|
const cwd = cwdOfSession(scope.deps.sessions?.(), sessionId);
|
|
1198
|
-
if (fs === void 0) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
sendJson(res, 200, {
|
|
1207
|
-
ok: false,
|
|
1208
|
-
error: messages.cwdUnknown
|
|
1209
|
-
});
|
|
1210
|
-
return;
|
|
1211
|
-
}
|
|
1266
|
+
if (fs === void 0) return {
|
|
1267
|
+
ok: false,
|
|
1268
|
+
error: messages.fsUnavailable
|
|
1269
|
+
};
|
|
1270
|
+
if (cwd === void 0) return {
|
|
1271
|
+
ok: false,
|
|
1272
|
+
error: messages.cwdUnknown
|
|
1273
|
+
};
|
|
1212
1274
|
const result = await collectDirContext(fs, cwd, messages, scope.limitsOf());
|
|
1213
|
-
if (result.error !== void 0) {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
sendJson(res, 200, {
|
|
1275
|
+
if (result.error !== void 0) return {
|
|
1276
|
+
ok: false,
|
|
1277
|
+
error: result.error
|
|
1278
|
+
};
|
|
1279
|
+
return {
|
|
1221
1280
|
ok: true,
|
|
1222
|
-
csrf: scope.csrf,
|
|
1223
1281
|
cwd: result.cwd,
|
|
1224
1282
|
truncated: result.truncated,
|
|
1225
1283
|
skipped: result.skipped,
|
|
@@ -1229,46 +1287,38 @@ async function sendContextResponse(scope, req, res) {
|
|
|
1229
1287
|
sizeBytes: entry.sizeBytes,
|
|
1230
1288
|
snippet: entry.snippet
|
|
1231
1289
|
}))
|
|
1232
|
-
}
|
|
1290
|
+
};
|
|
1233
1291
|
} catch (error) {
|
|
1234
|
-
|
|
1292
|
+
return {
|
|
1235
1293
|
ok: false,
|
|
1236
1294
|
error: fillTemplate(messages.collectFailed, [["{reason}", errorText(error)]])
|
|
1237
|
-
}
|
|
1295
|
+
};
|
|
1238
1296
|
}
|
|
1239
1297
|
}
|
|
1240
|
-
/**
|
|
1241
|
-
function
|
|
1298
|
+
/** 当前默认模型(provider/model/effort)。 */
|
|
1299
|
+
function modelPayload(scope) {
|
|
1242
1300
|
const messages = scope.messagesOf();
|
|
1243
|
-
if (req.method !== "GET") {
|
|
1244
|
-
methodNotAllowed(res, "GET");
|
|
1245
|
-
return;
|
|
1246
|
-
}
|
|
1247
1301
|
const agentDefaultModel = scope.deps.agentDefaultModel?.();
|
|
1248
|
-
if (agentDefaultModel === void 0) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
});
|
|
1253
|
-
return;
|
|
1254
|
-
}
|
|
1302
|
+
if (agentDefaultModel === void 0) return {
|
|
1303
|
+
ok: false,
|
|
1304
|
+
error: messages.modelServiceUnavailable
|
|
1305
|
+
};
|
|
1255
1306
|
try {
|
|
1256
1307
|
const sel = agentDefaultModel.currentSelection();
|
|
1257
|
-
|
|
1308
|
+
return {
|
|
1258
1309
|
ok: true,
|
|
1259
|
-
csrf: scope.csrf,
|
|
1260
1310
|
provider: sel.provider,
|
|
1261
1311
|
model: sel.model,
|
|
1262
1312
|
...sel.reasoningEffort === void 0 ? {} : { reasoningEffort: sel.reasoningEffort }
|
|
1263
|
-
}
|
|
1313
|
+
};
|
|
1264
1314
|
} catch (error) {
|
|
1265
|
-
|
|
1315
|
+
return {
|
|
1266
1316
|
ok: false,
|
|
1267
1317
|
error: fillTemplate(messages.readModelFailed, [["{reason}", errorText(error)]])
|
|
1268
|
-
}
|
|
1318
|
+
};
|
|
1269
1319
|
}
|
|
1270
1320
|
}
|
|
1271
|
-
/** organize 请求体的输入面:JSON
|
|
1321
|
+
/** organize 请求体的输入面:JSON 已解析的 unknown → 整理入参(非字符串一律按空值处理)。 */
|
|
1272
1322
|
function organizeRequestOf(body) {
|
|
1273
1323
|
const { prompt, sessionId, entriesSummary, roleText } = body;
|
|
1274
1324
|
return {
|
|
@@ -1278,206 +1328,191 @@ function organizeRequestOf(body) {
|
|
|
1278
1328
|
sessionId: typeof sessionId === "string" ? sessionId : null
|
|
1279
1329
|
};
|
|
1280
1330
|
}
|
|
1281
|
-
/**
|
|
1282
|
-
*
|
|
1283
|
-
|
|
1284
|
-
|
|
1331
|
+
/** 整理:LLM 调用与两层错误回执。内层 catch 是「整理过程本身失败」(回裸 errorText),
|
|
1332
|
+
* 外层是「装配入参时炸」。`messages` 每次调用现读一次,不在此处二次现读。 */
|
|
1333
|
+
async function organizePayload(scope, parsed) {
|
|
1334
|
+
const messages = scope.messagesOf();
|
|
1285
1335
|
try {
|
|
1286
1336
|
const llm = scope.deps.llm?.();
|
|
1287
|
-
if (llm === void 0) {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
});
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1337
|
+
if (llm === void 0) return {
|
|
1338
|
+
ok: false,
|
|
1339
|
+
error: messages.llmUnavailable
|
|
1340
|
+
};
|
|
1294
1341
|
const { prompt, entriesSummary, roleText: roleTextRaw, sessionId: sessionIdText } = organizeRequestOf(isRecord(parsed) ? parsed : {});
|
|
1295
1342
|
const sessions = scope.deps.sessions?.();
|
|
1296
1343
|
const recentTurns = resolveRecentTurns(sessions, sessionIdText);
|
|
1297
1344
|
const cwd = cwdOfSession(sessions, sessionIdText);
|
|
1298
|
-
if (cwd === void 0) {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
});
|
|
1303
|
-
return;
|
|
1304
|
-
}
|
|
1345
|
+
if (cwd === void 0) return {
|
|
1346
|
+
ok: false,
|
|
1347
|
+
error: messages.cwdUnknown
|
|
1348
|
+
};
|
|
1305
1349
|
const model = resolveModel(scope.deps);
|
|
1306
1350
|
try {
|
|
1307
|
-
|
|
1308
|
-
prompt,
|
|
1309
|
-
cwd,
|
|
1310
|
-
entriesSummary,
|
|
1311
|
-
recentTurns,
|
|
1312
|
-
...roleTextRaw.length === 0 ? {} : { roleText: roleTextRaw },
|
|
1313
|
-
...model === void 0 ? {} : { model }
|
|
1314
|
-
}, messages, scope.limitsOf().organizeTimeoutMs, callerSignal);
|
|
1315
|
-
sendJson(res, 200, {
|
|
1351
|
+
return {
|
|
1316
1352
|
ok: true,
|
|
1317
|
-
content:
|
|
1318
|
-
|
|
1353
|
+
content: (await runOrganize(llm, {
|
|
1354
|
+
prompt,
|
|
1355
|
+
cwd,
|
|
1356
|
+
entriesSummary,
|
|
1357
|
+
recentTurns,
|
|
1358
|
+
...roleTextRaw.length === 0 ? {} : { roleText: roleTextRaw },
|
|
1359
|
+
...model === void 0 ? {} : { model }
|
|
1360
|
+
}, messages, scope.limitsOf().organizeTimeoutMs)).content
|
|
1361
|
+
};
|
|
1319
1362
|
} catch (error) {
|
|
1320
|
-
|
|
1363
|
+
return {
|
|
1321
1364
|
ok: false,
|
|
1322
1365
|
error: errorText(error)
|
|
1323
|
-
}
|
|
1366
|
+
};
|
|
1324
1367
|
}
|
|
1325
1368
|
} catch (error) {
|
|
1326
|
-
|
|
1369
|
+
return {
|
|
1327
1370
|
ok: false,
|
|
1328
1371
|
error: fillTemplate(messages.organizeFailed, [["{reason}", errorText(error)]])
|
|
1329
|
-
}
|
|
1372
|
+
};
|
|
1330
1373
|
}
|
|
1331
1374
|
}
|
|
1332
|
-
/**
|
|
1333
|
-
*
|
|
1334
|
-
|
|
1335
|
-
|
|
1375
|
+
/** 导入:路径策略拒绝单独回 4xx,导入过程本身失败回 ok:false(界面读同一句原因)。
|
|
1376
|
+
* `messages` 同 organize:字典取表一次调用一次。 */
|
|
1377
|
+
async function importPayload(scope, parsed) {
|
|
1378
|
+
const messages = scope.messagesOf();
|
|
1336
1379
|
try {
|
|
1337
1380
|
const fs = scope.deps.fs?.();
|
|
1338
|
-
if (fs === void 0) {
|
|
1339
|
-
|
|
1381
|
+
if (fs === void 0) return {
|
|
1382
|
+
status: 200,
|
|
1383
|
+
body: {
|
|
1340
1384
|
ok: false,
|
|
1341
1385
|
error: messages.fsUnavailable
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
}
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1345
1388
|
const request = importRequestOf(parsed, messages);
|
|
1346
|
-
if (request.rejected) {
|
|
1347
|
-
|
|
1389
|
+
if (request.rejected) return {
|
|
1390
|
+
status: request.status,
|
|
1391
|
+
body: {
|
|
1348
1392
|
ok: false,
|
|
1349
1393
|
error: request.error
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1353
1396
|
const allowRoots = scope.deps.importAllowRoots?.() ?? [];
|
|
1354
1397
|
const cwd = cwdOfSession(scope.deps.sessions?.(), request.sessionId);
|
|
1355
1398
|
if (!request.isBuiltin) {
|
|
1356
1399
|
const policyError = importPathError(request.requested, cwd, allowRoots, messages);
|
|
1357
|
-
if (policyError !== void 0) {
|
|
1358
|
-
|
|
1400
|
+
if (policyError !== void 0) return {
|
|
1401
|
+
status: 403,
|
|
1402
|
+
body: {
|
|
1359
1403
|
ok: false,
|
|
1360
1404
|
error: policyError
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
}
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1364
1407
|
}
|
|
1365
1408
|
const result = await collectAgentTemplates(fs, request.isBuiltin ? AGENTS_DIR : request.requested, cwd, messages, {
|
|
1366
1409
|
skipPolicy: request.isBuiltin,
|
|
1367
1410
|
allowRoots,
|
|
1368
1411
|
limits: scope.limitsOf()
|
|
1369
1412
|
});
|
|
1370
|
-
if (result.error !== void 0) {
|
|
1371
|
-
|
|
1413
|
+
if (result.error !== void 0) return {
|
|
1414
|
+
status: 200,
|
|
1415
|
+
body: {
|
|
1372
1416
|
ok: false,
|
|
1373
1417
|
error: result.error
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
return {
|
|
1421
|
+
status: 200,
|
|
1422
|
+
body: {
|
|
1423
|
+
ok: true,
|
|
1424
|
+
count: result.entries.length,
|
|
1425
|
+
truncated: result.truncated,
|
|
1426
|
+
skipped: result.skipped,
|
|
1427
|
+
entries: result.entries
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1384
1430
|
} catch (error) {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1431
|
+
return {
|
|
1432
|
+
status: 200,
|
|
1433
|
+
body: {
|
|
1434
|
+
ok: false,
|
|
1435
|
+
error: fillTemplate(messages.importException, [["{reason}", errorText(error)]])
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1389
1438
|
}
|
|
1390
1439
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1440
|
+
/** 五个读面的纯载荷入口(服务与测试共用):不含任何传输层判定。 */
|
|
1441
|
+
function createRemotePayloads(deps, messagesOf) {
|
|
1393
1442
|
const scope = {
|
|
1394
1443
|
deps,
|
|
1395
|
-
csrf,
|
|
1396
1444
|
messagesOf,
|
|
1397
|
-
limitsOf
|
|
1445
|
+
limitsOf: () => sanitizeLimits(deps.limits?.() ?? DEFAULT_LIMITS)
|
|
1398
1446
|
};
|
|
1399
1447
|
return {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
sendBadRequestJson(res, messages.invalidJsonBody);
|
|
1450
|
-
return;
|
|
1451
|
-
}
|
|
1452
|
-
const disconnected = new AbortController();
|
|
1453
|
-
req.on("close", () => {
|
|
1454
|
-
disconnected.abort();
|
|
1455
|
-
});
|
|
1456
|
-
await sendOrganizeResponse(scope, res, messages, parsed, disconnected.signal);
|
|
1457
|
-
},
|
|
1458
|
-
async importAgent(req, res) {
|
|
1459
|
-
if (!guardTrust(req, res, { servingNonLoopback })) return;
|
|
1460
|
-
const messages = messagesOf();
|
|
1461
|
-
if (req.method !== "POST") {
|
|
1462
|
-
methodNotAllowed(res, "POST");
|
|
1463
|
-
return;
|
|
1464
|
-
}
|
|
1465
|
-
const raw = await guardBody(req, res, { maxBytes: scope.limitsOf().importBodyMaxBytes });
|
|
1466
|
-
if (raw === null) return;
|
|
1467
|
-
let parsed;
|
|
1468
|
-
try {
|
|
1469
|
-
parsed = JSON.parse(raw);
|
|
1470
|
-
} catch {
|
|
1471
|
-
sendBadRequestJson(res, messages.invalidJsonBody);
|
|
1472
|
-
return;
|
|
1473
|
-
}
|
|
1474
|
-
await sendImportResponse(scope, res, messages, parsed);
|
|
1448
|
+
defaults: () => defaultsPayload(scope),
|
|
1449
|
+
context: (sessionId) => contextPayload(scope, sessionId),
|
|
1450
|
+
model: () => modelPayload(scope),
|
|
1451
|
+
organize: (parsed) => organizePayload(scope, parsed),
|
|
1452
|
+
importTemplates: (parsed) => importPayload(scope, parsed)
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
/** 官方 Typert Remote 的服务键(= 线上命名空间)。 */
|
|
1456
|
+
const DIR_PREP_REMOTE_NAMESPACE = "dirPrepOrganize";
|
|
1457
|
+
/**
|
|
1458
|
+
* 设置卡的宿主读面(官方 Typert Remote):目录上下文、当前模型、整理、导入与内置模板。
|
|
1459
|
+
* 取代原先的五条 HTTP 端点(旧数据面已删除)。
|
|
1460
|
+
*/
|
|
1461
|
+
var DirPrepRemoteService = class extends TypertRemoteService {
|
|
1462
|
+
scope;
|
|
1463
|
+
constructor(ctx, scope) {
|
|
1464
|
+
super(ctx, DIR_PREP_REMOTE_NAMESPACE);
|
|
1465
|
+
this.scope = scope;
|
|
1466
|
+
}
|
|
1467
|
+
async defaults() {
|
|
1468
|
+
return defaultsPayload(this.scope);
|
|
1469
|
+
}
|
|
1470
|
+
async context(request) {
|
|
1471
|
+
const sessionId = isRecord(request) && typeof request.sessionId === "string" ? request.sessionId : null;
|
|
1472
|
+
return contextPayload(this.scope, sessionId);
|
|
1473
|
+
}
|
|
1474
|
+
model(request) {
|
|
1475
|
+
return modelPayload(this.scope);
|
|
1476
|
+
}
|
|
1477
|
+
async organize(request) {
|
|
1478
|
+
return organizePayload(this.scope, request);
|
|
1479
|
+
}
|
|
1480
|
+
async importTemplates(request) {
|
|
1481
|
+
const result = await importPayload(this.scope, request);
|
|
1482
|
+
return result.status === 200 ? result.body : {
|
|
1483
|
+
...result.body,
|
|
1484
|
+
status: result.status
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
/** 标准装饰器的程序化调用:标记落到真正的原型上,源码不引装饰器语法。 */
|
|
1489
|
+
function markRemote(prototype, methodName) {
|
|
1490
|
+
const context = {
|
|
1491
|
+
kind: "method",
|
|
1492
|
+
name: methodName,
|
|
1493
|
+
static: false,
|
|
1494
|
+
private: false,
|
|
1495
|
+
addInitializer: (initializer) => {
|
|
1496
|
+
Reflect.apply(initializer, Object.create(prototype), []);
|
|
1475
1497
|
}
|
|
1476
1498
|
};
|
|
1499
|
+
const decorate = Remote(methodName);
|
|
1500
|
+
Reflect.apply(decorate, void 0, [Reflect.get(prototype, methodName), context]);
|
|
1501
|
+
}
|
|
1502
|
+
markRemote(DirPrepRemoteService.prototype, "defaults");
|
|
1503
|
+
markRemote(DirPrepRemoteService.prototype, "context");
|
|
1504
|
+
markRemote(DirPrepRemoteService.prototype, "model");
|
|
1505
|
+
markRemote(DirPrepRemoteService.prototype, "organize");
|
|
1506
|
+
markRemote(DirPrepRemoteService.prototype, "importTemplates");
|
|
1507
|
+
/** 注册读面(构造即注册);替身上下文没有注册口时只少掉这一栏。 */
|
|
1508
|
+
function installDirPrepRemote(ctx, scope) {
|
|
1509
|
+
if (!isRecord(ctx) || !isRecord(ctx.reflect) || typeof ctx.reflect.provide !== "function") return false;
|
|
1510
|
+
new DirPrepRemoteService(ctx, scope);
|
|
1511
|
+
return true;
|
|
1477
1512
|
}
|
|
1478
1513
|
/** settings 注册的占位清理(无额外拆卸动作,注册随插件生命周期存续)。 */
|
|
1479
1514
|
function noopDisposer() {}
|
|
1480
|
-
/** host apply:登记设置页策略 +
|
|
1515
|
+
/** host apply:登记设置页策略 + 注册官方 Remote 读面(注入子上下文,卸载即撤)。
|
|
1481
1516
|
* 0.1.7 起模板设置是**隐式注册**的(导出的 Config + 字段上的 .volatile()),本函数
|
|
1482
1517
|
* 不再向 settings 注册任何东西;配置值由 cordis 校验并填过默认后按 volatile 引用交进来
|
|
1483
1518
|
* (第二参数 config),读当前值一律 `.get()`。 */
|
|
@@ -1508,74 +1543,38 @@ function apply(ctx, config) {
|
|
|
1508
1543
|
return settings.configure({ auto: false }, ctx.fiber);
|
|
1509
1544
|
}, "dir-prep-organize: settings presentation");
|
|
1510
1545
|
});
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
}, csrf, localeMessages, servingNonLoopback);
|
|
1543
|
-
const disposeDefaults = webServer.register({
|
|
1544
|
-
kind: "exact",
|
|
1545
|
-
path: DEFAULTS_PATH,
|
|
1546
|
-
handler: (req, res) => handlers.defaults(req, res)
|
|
1547
|
-
});
|
|
1548
|
-
const disposeContext = webServer.register({
|
|
1549
|
-
kind: "exact",
|
|
1550
|
-
path: CONTEXT_PATH,
|
|
1551
|
-
handler: (req, res) => handlers.context(req, res)
|
|
1552
|
-
});
|
|
1553
|
-
const disposeModel = webServer.register({
|
|
1554
|
-
kind: "exact",
|
|
1555
|
-
path: MODEL_PATH,
|
|
1556
|
-
handler: (req, res) => {
|
|
1557
|
-
handlers.model(req, res);
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
const disposeOrganize = webServer.register({
|
|
1561
|
-
kind: "exact",
|
|
1562
|
-
path: ORGANIZE_PATH,
|
|
1563
|
-
handler: (req, res) => handlers.organize(req, res)
|
|
1564
|
-
});
|
|
1565
|
-
const disposeImport = webServer.register({
|
|
1566
|
-
kind: "exact",
|
|
1567
|
-
path: IMPORT_PATH,
|
|
1568
|
-
handler: (req, res) => handlers.importAgent(req, res)
|
|
1569
|
-
});
|
|
1570
|
-
return () => {
|
|
1571
|
-
disposeDefaults();
|
|
1572
|
-
disposeContext();
|
|
1573
|
-
disposeModel();
|
|
1574
|
-
disposeOrganize();
|
|
1575
|
-
disposeImport();
|
|
1576
|
-
};
|
|
1577
|
-
}, "dir-prep-organize: webServer routes");
|
|
1546
|
+
const limitsOfConfig = () => ({
|
|
1547
|
+
organizeTimeoutMs: config.organizeTimeoutMs.get(),
|
|
1548
|
+
maxSnippetBytes: config.maxSnippetBytes,
|
|
1549
|
+
readConcurrency: config.readConcurrency
|
|
1550
|
+
});
|
|
1551
|
+
const scope = {
|
|
1552
|
+
deps: {
|
|
1553
|
+
sessions: () => {
|
|
1554
|
+
const service = getService("sessions");
|
|
1555
|
+
return isSessionsService(service) ? service : void 0;
|
|
1556
|
+
},
|
|
1557
|
+
fs: () => {
|
|
1558
|
+
const service = getService("fs");
|
|
1559
|
+
return isFsService(service) ? service : void 0;
|
|
1560
|
+
},
|
|
1561
|
+
llm: () => {
|
|
1562
|
+
const service = getService("llm");
|
|
1563
|
+
return isLlmService(service) ? service : void 0;
|
|
1564
|
+
},
|
|
1565
|
+
agentDefaultModel: () => {
|
|
1566
|
+
const service = getService("agentDefaultModel");
|
|
1567
|
+
return isAgentDefaultModel(service) ? service : void 0;
|
|
1568
|
+
},
|
|
1569
|
+
importAllowRoots: () => importAllowRootsOf(config.importAllowRoots.get()),
|
|
1570
|
+
limits: limitsOfConfig
|
|
1571
|
+
},
|
|
1572
|
+
messagesOf: localeMessages,
|
|
1573
|
+
limitsOf: () => sanitizeLimits(limitsOfConfig())
|
|
1574
|
+
};
|
|
1575
|
+
ctx.inject([], (child) => {
|
|
1576
|
+
installDirPrepRemote(child, scope);
|
|
1578
1577
|
});
|
|
1579
1578
|
}
|
|
1580
1579
|
//#endregion
|
|
1581
|
-
export { configSchema as Config, apply, buildOrganizeSystem, buildOrganizeUser, clampInt, collectAgentTemplates, collectDirContext,
|
|
1580
|
+
export { configSchema as Config, DIR_PREP_REMOTE_NAMESPACE, DirPrepRemoteService, apply, buildOrganizeSystem, buildOrganizeUser, clampInt, collectAgentTemplates, collectDirContext, createRemotePayloads, defaultTemplatesFrom, drainStreamToText, extractRecentTurns, importAllowRootsOf, importPathError, inject, installDirPrepRemote, loadDefaultTemplates, runOrganize, sanitizeLimits };
|