@jayyuen66/dsh-dir-prep-organize 0.1.1 → 0.1.2

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/host.js CHANGED
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import Schema from "@deepseek-ai/schemastery";
5
5
  import { brandString } from "@deepseek-ai/dsh-brand";
6
6
  import { guardBody, queryParam, sendJson } from "@jayyuen66/dsh-plugin-shared/lib/http";
7
- import { guardTrust } from "@jayyuen66/dsh-plugin-shared/lib/trust";
7
+ import { guardTrust, isNonLoopbackBindHost } from "@jayyuen66/dsh-plugin-shared/lib/trust";
8
8
  import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
9
9
  import { isRecord } from "@jayyuen66/dsh-plugin-shared/lib/record";
10
10
  import { errorText } from "@jayyuen66/dsh-plugin-shared/lib/errors";
@@ -261,10 +261,10 @@ function condenseRoleBody(body) {
261
261
  /** 本包送进 `llm.stream({ messages })` 的整理请求帧是 **request-only 输入**:它从不落
262
262
  * 任何持久消息位(`runOrganize` 只回 `{ content }`,路由也不把帧身份回投给卡片),所以
263
263
  * 按 0.1.7 它既不需要 `id` 也不带 `source`——证据三条:
264
- * 1. installed `@deepseek-ai/dsh-llm/lib/types/types.d.ts:457-462` 的 `RequestUserInput`
264
+ * 1. installed `@deepseek-ai/dsh-llm/lib/types/types.d.ts:468-473` 的 `RequestUserInput`
265
265
  * 把两面都标成 `?: never`(`readonly id?: never` / `readonly source?: never`),
266
266
  * `GenerateOptions.messages` 收的是 `RequestMessage[] = Message | RequestUserInput`
267
- * (同文件 :464,字段注记 "a hand-built one-shot may include identity-free user
267
+ * (同文件 :475,字段注记 "a hand-built one-shot may include identity-free user
268
268
  * inputs");
269
269
  * 2. 持久那半边 `Message` 要的 `source.kind` 必须是**已声明**进 `MessageSourceMap` 的
270
270
  * kind(installed `dsh-llm/lib/types/message.d.ts:101-133`),本包的
@@ -442,7 +442,7 @@ function isSessionsService(value) {
442
442
  return hasFnMember(value, "get");
443
443
  }
444
444
  function isFsService(value) {
445
- return hasFnMember(value, "resolve");
445
+ return hasFnMember(value, "resolve") && hasFnMember(value, "stat");
446
446
  }
447
447
  function isLlmService(value) {
448
448
  return hasFnMember(value, "stream");
@@ -488,9 +488,13 @@ function isKeyFile(name) {
488
488
  return KEY_EXT.has(lower.slice(dot));
489
489
  }
490
490
  /** 关键文件摘要:全量正文(用户拍板不截断——上下文完整性优先,
491
- * 模型 context 超限由模型报错提示用户自行处理)。仅 trim 去头尾空白。 */
491
+ * 模型 context 超限由模型报错提示用户自行处理)。仅 trim 去头尾空白。
492
+ * ⚠ 行尾先归一:官方 readText 承诺 byte-for-byte(**不归一 CRLF**,宿主 fs-local
493
+ * 源码注明),于是 Windows 仓库里的 `\r` 会原样进摘要;client 侧的折行压平只换
494
+ * `\n`,`\r` 就留在发给模型的 prompt 里(既污染文本又让行数统计失真)。
495
+ * 归一放在这一层而不是 client:host 是「真实字节 → 模型文本」的唯一转换点。 */
492
496
  function makeSnippet(content) {
493
- const trimmed = content.trim();
497
+ const trimmed = content.replaceAll("\r\n", "\n").replaceAll("\r", "\n").trim();
494
498
  return trimmed.length === 0 ? "" : trimmed;
495
499
  }
496
500
  /**
@@ -536,7 +540,8 @@ function skipCounts() {
536
540
  tooLarge: 0,
537
541
  unreadable: 0,
538
542
  deeper: 0,
539
- unnamed: 0
543
+ unnamed: 0,
544
+ escaped: 0
540
545
  };
541
546
  }
542
547
  /** 关键文件 → 摘要(字节上限 + 未知大小一律跳过:readWholeText 无上限,
@@ -613,8 +618,9 @@ async function collectDirContext(fs, cwd, messages, limits) {
613
618
  try {
614
619
  const dirTarget = await fs.resolve(cwd);
615
620
  const raw = await fs.listDir(dirTarget);
616
- const keyFiles = raw.filter((item) => item.type === "file" && isKeyFile(item.name));
621
+ const keyFiles = raw.filter((item) => item.type === "file" && isKeyFile(item.name) && fs.contains(dirTarget, item.target));
617
622
  const skipped = skipCounts();
623
+ skipped.escaped = raw.filter((item) => item.type === "file" && isKeyFile(item.name) && !fs.contains(dirTarget, item.target)).length;
618
624
  const reads = await mapBounded(keyFiles, scan.readConcurrency, async (item) => ({
619
625
  targetKey: item.target.targetKey,
620
626
  ...await readSnippetBounded(fs, item, scan.maxSnippetBytes)
@@ -636,7 +642,7 @@ async function collectDirContext(fs, cwd, messages, limits) {
636
642
  sizeBytes: item.size ?? 0,
637
643
  snippet: item.type === "directory" ? void 0 : snippetByTarget.get(item.target.targetKey)
638
644
  })),
639
- truncated: skipped.tooLarge + skipped.unreadable > 0,
645
+ truncated: skipped.tooLarge + skipped.unreadable + skipped.escaped > 0,
640
646
  skipped
641
647
  };
642
648
  } catch (error) {
@@ -720,6 +726,12 @@ function outsideRootsError(absolute, roots, messages) {
720
726
  const zones = roots.map((root) => `${root.label} ${root.absolute}`);
721
727
  return fillTemplate(messages.outsideRoots, [["{zones}", zones.join(messages.zoneSeparator)], ["{absolute}", absolute]]);
722
728
  }
729
+ /** 真实目标是否落在**每一个**允许根之外。判据交给后端(`contains` 用它自己的世界判
730
+ * 包含关系),而不是再写第二条字符串规则:符号链接让「路径长得合法」与「读的是哪个
731
+ * 对象」分叉,只有后端能收这个叉。一个根命中即放行;全落空即为逃逸。 */
732
+ async function escapesAllRoots(fs, target, roots) {
733
+ return !(await Promise.all(roots.map((root) => fs.resolve(root.absolute)))).some((root) => fs.contains(root, target));
734
+ }
723
735
  function importPathError(requested, cwd, allowRoots, messages) {
724
736
  const trimmed = requested.trim();
725
737
  if (trimmed.length === 0) return messages.emptyImportPath;
@@ -761,9 +773,15 @@ function isVisibleDirectory(child) {
761
773
  function isVisibleMdFile(child) {
762
774
  return child.type === "file" && child.name.endsWith(".md") && !child.name.startsWith(".");
763
775
  }
764
- /** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。 */
765
- function mdCandidates(fs, parent, children, dirName) {
766
- return children.filter((child) => fs.contains(parent, child.target)).filter((child) => isVisibleMdFile(child)).map((child) => ({
776
+ /** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。
777
+ * `skipped` 就地累加 escaped 计数:被 contains 拦下的链接文件如果不数出来,
778
+ * 用户只会看到「导入 3 条」而不知道有一份被安全闸门挡在门外。 */
779
+ function mdCandidates(fs, parent, children, dirName, skipped) {
780
+ return children.filter((child) => isVisibleMdFile(child)).filter((child) => {
781
+ const contained = fs.contains(parent, child.target);
782
+ if (!contained) skipped.escaped += 1;
783
+ return contained;
784
+ }).map((child) => ({
767
785
  name: child.name,
768
786
  dirName,
769
787
  target: child.target,
@@ -791,10 +809,44 @@ async function readCandidate(fs, file, maxBytes) {
791
809
  function importGate(requested, cwd, allowRoots, messages, skip) {
792
810
  return skip ? void 0 : importPathError(requested, cwd, allowRoots, messages);
793
811
  }
794
- /** 单文件导入(路径直指一个角色 .md):解析不出 name → 记 unnamed 并回原因;
795
- * 读到了但正文提炼为空 → 空条目列表(agentEntryFromFile 返回 undefined 的形状)。 */
796
- async function importFromFile(fs, absolute, target, skipped, messages) {
797
- const info = parseAgentFrontmatter(await fs.readText(target));
812
+ /** 单个候选的字节上限判定:与 readSnippetBounded 同一口径——**size 未知即拒读**。
813
+ *
814
+ * 为什么单文件分支也需要这道门:目录分支的每个候选都自带 `listDir` 给的 `size`,于是
815
+ * `readCandidate` 能在读之前判上限;而单文件导入只有一个 `resolve` 出来的 target,
816
+ * 不 `stat` 就只能盲读——官方 `readText` 自述"读整份文本"、**没有任何上限**,于是一个
817
+ * 几 MB 的 .md 会整份进宿主内存(实测把 maxSnippetBytes 配成 1024,3 MB 的文件照样
818
+ * 被读进来并返回成模板条目)。宁可少导一条并如实计数,也不拿宿主进程的存亡去赌。
819
+ *
820
+ * @returns 通过时给出字节数,未通过时给出 undefined(调用方计 tooLarge)。
821
+ */
822
+ async function fileBytesWithin(fs, target, maxBytes) {
823
+ const size = (await fs.stat(target).catch(() => null))?.size;
824
+ return size === void 0 || size > maxBytes ? void 0 : size;
825
+ }
826
+ /** 单文件导入(路径直指一个角色 .md):字节超限或读失败各计各的;解析不出 name →
827
+ * 记 unnamed 并回原因;读到了但正文提炼为空 → 空条目列表(agentEntryFromFile
828
+ * 返回 undefined 的形状)。 */
829
+ async function importFromFile(args, absolute) {
830
+ const { fs, target, limits, skipped, messages } = args;
831
+ if (await fileBytesWithin(fs, target, limits.maxSnippetBytes) === void 0) {
832
+ skipped.tooLarge += 1;
833
+ return {
834
+ entries: [],
835
+ truncated: true,
836
+ skipped
837
+ };
838
+ }
839
+ let info;
840
+ try {
841
+ info = parseAgentFrontmatter(await fs.readText(target));
842
+ } catch {
843
+ skipped.unreadable += 1;
844
+ return {
845
+ entries: [],
846
+ truncated: true,
847
+ skipped
848
+ };
849
+ }
798
850
  if (info === void 0) {
799
851
  skipped.unnamed = 1;
800
852
  return {
@@ -811,11 +863,29 @@ async function importFromFile(fs, absolute, target, skipped, messages) {
811
863
  skipped
812
864
  };
813
865
  }
866
+ /**
867
+ * listDir 的降级读面:列不出来(EACCES / ELOOP / 枚举期间被删)时记 unreadable 并交空表。
868
+ *
869
+ * 为什么必须有:`mapBounded` 内部是 `Promise.all`,worker 一抛就整批 reject,把**同一批
870
+ * 里已经读完的结果一起丢掉**,上层 `collectAgentTemplates` 的 catch 再把整次导入变成
871
+ * 「导入失败」。实测:一个 chmod 000 的子目录就让同层读得好好的 .md 一条都进不来。
872
+ * 文件级读取早就有这道降级(`readCandidate` → `{kind:"unreadable"}`),目录枚举却漏了,
873
+ * 口径不一致;`mapBounded` 自己的注释也写着「worker 自己负责错误降级(不抛)」。
874
+ */
875
+ async function listDirOrUnreadable(fs, target, skipped) {
876
+ try {
877
+ return await fs.listDir(target);
878
+ } catch {
879
+ skipped.unreadable += 1;
880
+ return [];
881
+ }
882
+ }
814
883
  /** 更深层(第三层)目录:只清点可见 .md 数、不读正文——扫描深度是设计上限,
815
- * 但静默省略是 bug(内置库 game-development/<engine>/*.md 曾整批消失)。 */
816
- async function countDeeperMdFiles(fs, deepDirs, readConcurrency) {
884
+ * 但静默省略是 bug(内置库 game-development/<engine>/*.md 曾整批消失)。
885
+ * 列不出来的深层目录按 unreadable 计数,不让整次导入归零。 */
886
+ async function countDeeperMdFiles(fs, deepDirs, readConcurrency, skipped) {
817
887
  const counts = await mapBounded(deepDirs, readConcurrency, async (dir) => {
818
- return (await fs.listDir(dir)).filter((child) => isVisibleMdFile(child)).length;
888
+ return (await listDirOrUnreadable(fs, dir, skipped)).filter((child) => isVisibleMdFile(child)).length;
819
889
  });
820
890
  let total = 0;
821
891
  for (const count of counts) total += count;
@@ -848,11 +918,11 @@ function pushReadResult(read, entries, collided, skipped) {
848
918
  * 上层 catch 仍要报出已经数到的那部分。 */
849
919
  async function importFromDirectory(fs, absolute, target, limits, skipped) {
850
920
  const rootChildren = await fs.listDir(target);
851
- const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute));
921
+ const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute), skipped);
852
922
  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.listDir(sub);
923
+ const children = await listDirOrUnreadable(fs, sub, skipped);
854
924
  return {
855
- files: mdCandidates(fs, sub, children, path.basename(sub.displayPath)),
925
+ files: mdCandidates(fs, target, children, path.basename(sub.displayPath), skipped),
856
926
  deeper: children.filter((child) => isVisibleDirectory(child)).map((child) => child.target)
857
927
  };
858
928
  });
@@ -862,7 +932,7 @@ async function importFromDirectory(fs, absolute, target, limits, skipped) {
862
932
  subFiles.push(...scan.files);
863
933
  deepDirs.push(...scan.deeper);
864
934
  }
865
- const deeperMdCount = await countDeeperMdFiles(fs, deepDirs, limits.readConcurrency);
935
+ const deeperMdCount = await countDeeperMdFiles(fs, deepDirs, limits.readConcurrency, skipped);
866
936
  skipped.deeper += deeperMdCount;
867
937
  const reads = await mapBounded([...rootFiles, ...subFiles], limits.readConcurrency, (file) => readCandidate(fs, file, limits.maxSnippetBytes));
868
938
  const entries = [];
@@ -879,7 +949,8 @@ async function importFromDirectory(fs, absolute, target, limits, skipped) {
879
949
  * allowRoots = 设置 importAllowRoots 登记的额外允许目录(由路由注入)。 */
880
950
  async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
881
951
  const limits = opts?.limits ?? DEFAULT_LIMITS;
882
- const policyError = importGate(requested, cwd, opts?.allowRoots ?? [], messages, opts?.skipPolicy === true);
952
+ const allowRoots = opts?.allowRoots ?? [];
953
+ const policyError = importGate(requested, cwd, allowRoots, messages, opts?.skipPolicy === true);
883
954
  if (policyError !== void 0) return {
884
955
  entries: [],
885
956
  truncated: false,
@@ -890,10 +961,26 @@ async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
890
961
  const skipped = skipCounts();
891
962
  try {
892
963
  const target = await fs.resolve(absolute);
893
- if (absolute.endsWith(".md")) return await importFromFile(fs, absolute, target, skipped, messages);
964
+ const roots = importRootsOf(cwd, allowRoots, messages);
965
+ if (await escapesAllRoots(fs, target, roots)) {
966
+ skipped.escaped = 1;
967
+ return {
968
+ entries: [],
969
+ truncated: true,
970
+ skipped,
971
+ error: outsideRootsError(target.displayPath, roots, messages)
972
+ };
973
+ }
974
+ if (absolute.endsWith(".md")) return await importFromFile({
975
+ fs,
976
+ target,
977
+ limits,
978
+ skipped,
979
+ messages
980
+ }, absolute);
894
981
  return {
895
982
  entries: await importFromDirectory(fs, absolute, target, limits, skipped),
896
- truncated: skipped.tooLarge + skipped.unreadable + skipped.deeper > 0,
983
+ truncated: skipped.tooLarge + skipped.unreadable + skipped.deeper + skipped.escaped > 0,
897
984
  skipped
898
985
  };
899
986
  } catch (error) {
@@ -1514,7 +1601,7 @@ function apply(ctx, config) {
1514
1601
  const webServer = isWebServerService(rawWebServer) ? rawWebServer : void 0;
1515
1602
  if (webServer === void 0) return noopDisposer;
1516
1603
  const csrf = randomUUID();
1517
- const servingNonLoopback = isRecord(rawWebServer) && rawWebServer["host"] === "0.0.0.0";
1604
+ const servingNonLoopback = isNonLoopbackBindHost(webServer.host);
1518
1605
  const handlers = createRouteHandlers({
1519
1606
  sessions: () => {
1520
1607
  const service = getService("sessions");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-dir-prep-organize",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "dsh 插件:对话输入框「整理」按钮(主键直接整理/▾ 以角色视角整理,结合当前目录 + session 模型整理优化草稿)+「模板」下拉(内置精选角色集生成自插件 agents/ 角色库,可按部门分组;设置卡可增删改/一键导入内置全部/导入本地角色 .md)",
5
5
  "homepage": "https://github.com/JayYuen666/dsh-dir-prep-organize#readme",
6
6
  "bugs": {
@@ -45,68 +45,98 @@
45
45
  "registry": "https://registry.npmjs.org"
46
46
  },
47
47
  "dependencies": {
48
- "@deepseek-ai/cosmokit": "1.8.6-alpha.1",
49
- "@deepseek-ai/dsh-brand": "0.2.1-alpha.1",
50
- "@deepseek-ai/schemastery": "3.18.5-alpha.1",
51
- "@jayyuen66/dsh-plugin-shared": "^0.1.2"
48
+ "@jayyuen66/dsh-plugin-shared": "^0.1.5-rc"
52
49
  },
53
50
  "devDependencies": {
54
51
  "@deepseek-ai/cordis": "4.0.5-alpha.1",
55
- "@deepseek-ai/dsh-agent": "0.2.1-alpha.1",
56
- "@deepseek-ai/dsh-agent-default-model": "0.2.1-alpha.1",
57
- "@deepseek-ai/dsh-api-remotes": "0.2.1-alpha.1",
58
- "@deepseek-ai/dsh-api-workspace-controller": "0.2.1-alpha.1",
59
- "@deepseek-ai/dsh-client-locale": "0.2.1-alpha.1",
60
- "@deepseek-ai/dsh-client-store": "0.2.1-alpha.1",
61
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-alpha.1",
62
- "@deepseek-ai/dsh-client-ui-layout": "0.2.1-alpha.1",
63
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-alpha.1",
64
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-alpha.1",
65
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-alpha.1",
66
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-alpha.1",
67
- "@deepseek-ai/dsh-fs": "0.2.1-alpha.1",
68
- "@deepseek-ai/dsh-host-directory-picker": "0.2.1-alpha.1",
69
- "@deepseek-ai/dsh-host-webserver": "0.2.1-alpha.1",
70
- "@deepseek-ai/dsh-llm": "0.2.1-alpha.1",
71
- "@deepseek-ai/dsh-llm-retry": "0.2.1-alpha.1",
72
- "@deepseek-ai/dsh-package-manifest": "0.2.1-alpha.1",
73
- "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.1",
74
- "@deepseek-ai/dsh-scope": "0.2.1-alpha.1",
75
- "@deepseek-ai/dsh-session": "0.2.1-alpha.1",
76
- "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.1",
77
- "@deepseek-ai/dsh-settings": "0.2.1-alpha.1",
78
- "@types/node": "26.6.3",
52
+ "@deepseek-ai/cosmokit": "1.8.6-alpha.1",
53
+ "@deepseek-ai/dsh-agent-default-model": "0.2.1-alpha.2",
54
+ "@deepseek-ai/dsh-app-boot": "0.2.1-alpha.2",
55
+ "@deepseek-ai/dsh-brand": "0.2.1-alpha.2",
56
+ "@deepseek-ai/dsh-client-locale": "0.2.1-alpha.2",
57
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-alpha.2",
58
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-alpha.2",
59
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-alpha.2",
60
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-alpha.2",
61
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-alpha.2",
62
+ "@deepseek-ai/dsh-config-editor": "0.2.1-alpha.2",
63
+ "@deepseek-ai/dsh-fs": "0.2.1-alpha.2",
64
+ "@deepseek-ai/dsh-host-webserver": "0.2.1-alpha.2",
65
+ "@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
66
+ "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2",
67
+ "@deepseek-ai/dsh-session": "0.2.1-alpha.2",
68
+ "@deepseek-ai/dsh-settings": "0.2.1-alpha.2",
69
+ "@deepseek-ai/schemastery": "3.18.5-alpha.1",
70
+ "@types/node": "26.6.5",
79
71
  "@types/react": "19.3.0",
80
72
  "@types/react-dom": "19.3.0",
81
- "@vitest/coverage-v8": "5.0.2",
73
+ "@vitest/coverage-v8": "5.0.3",
82
74
  "eslint-plugin-sonarjs": "4.2.2",
83
- "happy-dom": "20.14.5",
84
- "oxfmt": "0.71.0",
85
- "oxlint": "1.86.0",
86
- "oxlint-tsgolint": "7.0.2003",
75
+ "happy-dom": "20.14.6",
76
+ "oxfmt": "0.72.0",
77
+ "oxlint": "1.87.0",
78
+ "oxlint-tsgolint": "7.0.2004",
87
79
  "react": "^19.3.0",
88
80
  "react-dom": "^19.3.0",
89
- "rolldown": "1.2.11",
81
+ "rolldown": "1.2.13",
90
82
  "typescript": "7.0.2",
91
- "vite": "8.3.1",
92
- "vitest": "5.0.2"
83
+ "vite": "8.3.4",
84
+ "vitest": "5.0.3"
93
85
  },
94
86
  "peerDependencies": {
87
+ "@deepseek-ai/cordis": "4.0.5-alpha.1",
88
+ "@deepseek-ai/cosmokit": "1.8.6-alpha.1",
95
89
  "@deepseek-ai/dsh": ">=0.2.0-rc.2",
96
- "@deepseek-ai/dsh-agent-default-model": "0.2.1-alpha.1",
97
- "@deepseek-ai/dsh-fs": "0.2.1-alpha.1",
90
+ "@deepseek-ai/dsh-agent-default-model": "0.2.1-alpha.2",
91
+ "@deepseek-ai/dsh-brand": "0.2.1-alpha.2",
92
+ "@deepseek-ai/dsh-client-locale": "0.2.1-alpha.2",
93
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-alpha.2",
94
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-alpha.2",
95
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-alpha.2",
96
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-alpha.2",
97
+ "@deepseek-ai/dsh-fs": "0.2.1-alpha.2",
98
+ "@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
99
+ "@deepseek-ai/dsh-session": "0.2.1-alpha.2",
100
+ "@deepseek-ai/schemastery": "3.18.5-alpha.1",
98
101
  "react": "^19.3.0"
99
102
  },
100
103
  "peerDependenciesMeta": {
104
+ "@deepseek-ai/cordis": {
105
+ "optional": true
106
+ },
107
+ "@deepseek-ai/cosmokit": {
108
+ "optional": true
109
+ },
101
110
  "@deepseek-ai/dsh": {
102
111
  "optional": true
103
112
  },
104
113
  "@deepseek-ai/dsh-agent-default-model": {
105
114
  "optional": true
106
115
  },
116
+ "@deepseek-ai/dsh-client-locale": {
117
+ "optional": true
118
+ },
119
+ "@deepseek-ai/dsh-client-ui-conversation": {
120
+ "optional": true
121
+ },
122
+ "@deepseek-ai/dsh-client-ui-renderer": {
123
+ "optional": true
124
+ },
125
+ "@deepseek-ai/dsh-client-ui-settings": {
126
+ "optional": true
127
+ },
128
+ "@deepseek-ai/dsh-client-ui-slots": {
129
+ "optional": true
130
+ },
107
131
  "@deepseek-ai/dsh-fs": {
108
132
  "optional": true
109
133
  },
134
+ "@deepseek-ai/dsh-llm": {
135
+ "optional": true
136
+ },
137
+ "@deepseek-ai/dsh-session": {
138
+ "optional": true
139
+ },
110
140
  "react": {
111
141
  "optional": true
112
142
  }
package/types/host.d.ts CHANGED
@@ -45,11 +45,17 @@ export declare function clampInt(value: number, min: number, max: number, fallba
45
45
  export type { FsDirEntry, FsTarget } from "@deepseek-ai/dsh-fs";
46
46
  /**
47
47
  * 官方 `FileSystem`(installed @deepseek-ai/dsh-fs/lib/types/index.d.ts:61,cordis `Service`
48
- * 子类 → 名义比较)的方法面投影:本包只用 `resolve`(:94) / `listDir`(:208) / `readText`(:162)。
49
- * 旧镜像漏抄了官方那三位的可选 `signal?: AbortSignal` 形参(抄本里没有的形参在 TS 里
50
- * 是"少收一个参数",调用点不会报错,但真实宿主多一档取消语义);投影之后它回到官方形状。
48
+ * 子类 → 名义比较)的方法面投影:本包用 `resolve`(:94) / `listDir`(:208) / `readText`(:162)
49
+ * / `contains`(:173) / `stat`(:181)。旧镜像漏抄了官方那几位的可选 `signal?: AbortSignal`
50
+ * 形参(抄本里没有的形参在 TS 里是"少收一个参数",调用点不会报错,但真实宿主多一档取消
51
+ * 语义);投影之后它回到官方形状。
52
+ *
53
+ * `stat`(installed index.d.ts:181-187,返回 `{version,type,size?}`)是**单文件导入**那条
54
+ * 路径唯一的字节上限来源:目录分支的每个候选都自带 `listDir` 给的 `size`,而单文件导入
55
+ * 只有一个 `resolve` 出来的 target,不 stat 就无从判断该不该读——而官方 `readText`
56
+ * 自述"读整份文本"、**没有任何上限**。缺了它,一个几 MB 的 .md 就能把整份读进宿主内存。
51
57
  */
52
- export type FsService = Pick<FileSystem, "resolve" | "listDir" | "readText" | "contains">;
58
+ export type FsService = Pick<FileSystem, "resolve" | "listDir" | "readText" | "contains" | "stat">;
53
59
  /**
54
60
  * 本包从会话消息史的读取面 = **官方 `Message` 的键名投影**(installed
55
61
  * @deepseek-ai/dsh-llm/lib/types/message.d.ts:124-133 `MessageBase` 与各变体的 `role`),
@@ -82,10 +88,10 @@ export interface DerivedMessageView {
82
88
  }
83
89
  /**
84
90
  * 本包读到的会话面 = 官方 `Session` 两位成员的**边界投影**(installed
85
- * @deepseek-ai/dsh-session/lib/types/index.d.ts:`readonly header: SessionHeader` :118、
86
- * `deriveMessages(): Message[]` :292)。
91
+ * @deepseek-ai/dsh-session/lib/types/index.d.ts:`readonly header: SessionHeader` :150、
92
+ * `deriveMessages(): Message[]` :347)。
87
93
  * 键名一律借自官方(`header` 借 `Session`、`cwd` 借 `SessionHeader`,installed
88
- * @deepseek-ai/dsh-llm 域内 types.d.ts:69 `readonly cwd?: string`),值域收成"本包真的读的那位
94
+ * @deepseek-ai/dsh-session 域内 types.d.ts:69 `readonly cwd?: string`),值域收成"本包真的读的那位
89
95
  * + 可缺失":官方把 header/deriveMessages 记成必选成员,但那句承诺说的是宿主自己 `new`
90
96
  * 出来的 Session;跨进程递来的会话是否具备某位只能运行时判(见 `extractSessionConversation`
91
97
  * 的 `typeof session.deriveMessages !== "function"` 与 `cwdOfSession` 的 `typeof === "string"`
@@ -97,10 +103,10 @@ export interface SessionLike {
97
103
  }
98
104
  /**
99
105
  * `Context.sessions`(官方 `SessionStore`,installed @deepseek-ai/dsh-session/lib/types/
100
- * index.d.ts:26-28)的 `get` 一位(:436 `get(id: SessionId): Session | undefined`)在本包的
106
+ * index.d.ts:26-28)的 `get` 一位(:491 `get(id: SessionId): Session | undefined`)在本包的
101
107
  * 读法:入参就此是官方品牌的 `SessionId`(边界上递来的是裸 string,构造口只有文件头那枚
102
108
  * `brandString<SessionId>`),返回值域换成上面的 `SessionLike` 投影——直接取官方返回的整枚
103
- * `Session` 类会把名义类一路渗进本包(`private log`/`surfaceManager`,:105-107),那三道运行时
109
+ * `Session` 类会把名义类一路渗进本包(`private log`/`surfaceManager`,:137-139),那三道运行时
104
110
  * 守卫当场在编译器眼里变成死代码,而它们挡的是真实输入。返回 `undefined` 与官方一致。
105
111
  * 口径同 danger-guard/host.ts 的 `GuardExecution`(借键名、值域换投影)。
106
112
  */
@@ -113,7 +119,7 @@ export interface SessionsService {
113
119
  * 「转换点为 0」并不成立。取官方类型后模型选择与 stream 入参两侧共用同一真值。 */
114
120
  export type { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
115
121
  /** 默认模型选择直接取官方成员的返回形状(`AgentDefaultModelConfig.currentSelection()`
116
- * 的返回类型,installed @deepseek-ai/dsh-agent-default-model/lib/types/index.d.ts:41)。
122
+ * 的返回类型,installed @deepseek-ai/dsh-agent-default-model/lib/types/index.d.ts:42)。
117
123
  * 旧镜像自己抄了 `{ provider, model, reasoningEffort? }` 三位——其中 `reasoningEffort` 是
118
124
  * `ReasoningEffortId` 品牌(本文件上面已按官方 re-export),抄本一旦与官方漂开,
119
125
  * 品牌值塞不进 stream 入参就是静默丢字段。取 ReturnType 之后本包不再裁定它的形状。 */
@@ -130,7 +136,7 @@ export type { RequestUserInput, TextBlock } from "@deepseek-ai/dsh-llm";
130
136
  export type { FinishReason, StreamChunk } from "@deepseek-ai/dsh-llm";
131
137
  /** stream 入参:官方 `GenerateOptions` 的本包用到的子集。此前这里在 `Pick` 之外**另加**
132
138
  * 了一枚 `signal?: AbortSignal`,注释写着"本包附加的取消位"——官方其实**就有**这一位
133
- * (installed @deepseek-ai/dsh-llm/lib/types/types.d.ts:494),另写一次等于凭空多出一个
139
+ * (installed @deepseek-ai/dsh-llm/lib/types/types.d.ts:519),另写一次等于凭空多出一个
134
140
  * 与官方并行的形状声明;现在连同 `signal` 一起 `Pick`,一处来源。 */
135
141
  export type LlmStreamOptions = Pick<GenerateOptions, "provider" | "model" | "reasoningEffort" | "messages" | "system" | "signal">;
136
142
  /** 官方 `LlmRuntime`(`Context.llm` 的类型,installed @deepseek-ai/dsh-llm/lib/types/
@@ -156,6 +162,10 @@ export interface SkipCounts {
156
162
  deeper: number;
157
163
  /** 读到了但解析不出角色 name(非角色文件)而被跳过的文件数(仅导入端点用)。 */
158
164
  unnamed: number;
165
+ /** 真实目标落在允许根之外(符号链接指向根外文件)而被策略排除的文件数。
166
+ * 必须单列:它既不是读失败也不是超限,把「凭据文件被链接进工作目录」这类事
167
+ * 混进 unreadable,用户就看不出是安全闸门拦的还是目录本身坏了。 */
168
+ escaped: number;
159
169
  }
160
170
  export interface CollectResult {
161
171
  cwd: string;
@@ -204,7 +214,7 @@ type RouteLimits = DirScanLimits & {
204
214
  * @returns 两项关键值已夹位、其余原样透传的新对象
205
215
  */
206
216
  export declare function sanitizeLimits(limits: RouteLimits): RouteLimits;
207
- export declare function collectDirContext(fs: Pick<FsService, "resolve" | "listDir" | "readText">, cwd: string | undefined, messages: HostMessages, limits?: DirScanLimits): Promise<CollectResult>;
217
+ export declare function collectDirContext(fs: Pick<FsService, "resolve" | "listDir" | "readText" | "contains">, cwd: string | undefined, messages: HostMessages, limits?: DirScanLimits): Promise<CollectResult>;
208
218
  export interface ImportResult {
209
219
  entries: TemplateEntry[];
210
220
  truncated: boolean;
@@ -219,7 +229,7 @@ export declare function importPathError(requested: string, cwd: string | undefin
219
229
  * skipPolicy 用于内置角色库自检(AGENTS_DIR 是策略里的允许根,用户输入路径正常
220
230
  * 不需要它;保留这个开关只为让"内置全量导入"不依赖安装位置是否命中隐藏段判断)。
221
231
  * allowRoots = 设置 importAllowRoots 登记的额外允许目录(由路由注入)。 */
222
- export declare function collectAgentTemplates(fs: Pick<FsService, "resolve" | "listDir" | "readText" | "contains">, requested: string, cwd: string | undefined, messages: HostMessages, opts?: {
232
+ export declare function collectAgentTemplates(fs: Pick<FsService, "resolve" | "listDir" | "readText" | "contains" | "stat">, requested: string, cwd: string | undefined, messages: HostMessages, opts?: {
223
233
  skipPolicy?: boolean;
224
234
  allowRoots?: readonly string[];
225
235
  limits?: DirScanLimits;
@@ -367,8 +377,8 @@ export interface RouteDeps {
367
377
  loadDefaultTemplates?: () => Promise<readonly TemplateEntry[]>;
368
378
  }
369
379
  /** 路由 handler 形状(本包自己的路由表投影)。官方 `WebRoute["handler"]` 的返回是
370
- * `void | Promise<void>`(installed `@deepseek-ai/dsh-host-webserver/lib/types/index.d.ts:38`),
371
- * dispatcher 侧写成 `await route.handler(req, res)`(installed lib/index.js:235)——
380
+ * `void | Promise<void>`(installed `@deepseek-ai/dsh-host-webserver/lib/types/index.d.ts:40`),
381
+ * dispatcher 侧写成 `await route.handler(req, res)`(installed lib/index.js:356)——
372
382
  * await 对同步返回同样成立,而外层 `handle` 本身是 async,故同步抛与 reject 在调用方
373
383
  * 观察上等价:**没有调用方依赖 handler 返回 promise**。于是投影按实现拆成两枚,
374
384
  * 让 createRouteHandlers 的返回值继续自证——确有 await 的三枚是 AsyncRouteHandler,
@@ -13,6 +13,14 @@ export interface DirEntryView {
13
13
  sizeBytes: number;
14
14
  snippet?: string;
15
15
  }
16
+ export interface ImportSkips {
17
+ tooLarge: number;
18
+ unreadable: number;
19
+ deeper: number;
20
+ unnamed: number;
21
+ /** 真实目标落在允许根之外(符号链接)被排除的项数;旧 host 不回这一位时读作 0。 */
22
+ escaped: number;
23
+ }
16
24
  export interface ContextResponse {
17
25
  ok: boolean;
18
26
  error?: string;
@@ -21,12 +29,14 @@ export interface ContextResponse {
21
29
  truncated?: boolean;
22
30
  entries?: DirEntryView[];
23
31
  }
24
- export interface ImportSkips {
25
- tooLarge: number;
26
- unreadable: number;
27
- deeper: number;
28
- unnamed: number;
32
+ export interface OrganizeResponse {
33
+ ok: boolean;
34
+ error?: string;
35
+ content?: string;
29
36
  }
37
+ export declare function parseContextResponse(raw: unknown): ContextResponse;
38
+ export declare function parseOrganizeResponse(raw: unknown): OrganizeResponse;
39
+ /** 导入跳过计数 → 一句话(无计数时返回空串,调用方据此不追加任何文案)。 */
30
40
  export declare function formatImportSkips(t: Translate, skips: ImportSkips | undefined): string;
31
41
  export declare function formatContextSummary(resp: ContextResponse): string;
32
42
  export type BuiltinPhase = "idle" | "loading" | "ready" | "error";
@@ -56,7 +66,6 @@ export interface PersistedView {
56
66
  templates: readonly TemplateEntry[];
57
67
  allowRoots: readonly string[];
58
68
  }
59
- export declare function rawOrganizeTimeoutMsOf(value: Record<string, unknown>): number | undefined;
60
69
  export declare function persistError(t: Translate, persisted: Pick<PersistedView, "ready" | "revision" | "templates">, expected: readonly TemplateEntry[], action: string, opts?: {
61
70
  treatEmptyAsReverted?: boolean;
62
71
  }): string | undefined;
@@ -0,0 +1 @@
1
+ export declare const CARD_STYLES: string;
@@ -0,0 +1,30 @@
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
+ * 而这一侧是**唯一**发起 fetch 的地方,它要是没夹,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;
@@ -96,6 +96,8 @@ export interface UiMessages {
96
96
  readonly skipUnreadable: string;
97
97
  /** 跳过计数:非角色文件。 */
98
98
  readonly skipUnnamed: string;
99
+ /** 跳过计数:真实目标在允许根之外(符号链接逃逸),被安全闸门拦下。 */
100
+ readonly skipEscaped: string;
99
101
  /** 跳过计数整句的外层括号。 */
100
102
  readonly skipSummary: string;
101
103
  /** 跳过计数各项的分隔符。 */
@@ -167,7 +169,7 @@ export interface UiMessages {
167
169
  }
168
170
  /**
169
171
  * 本包的文案命名空间 merge 进官方的 `LocaleNamespaceMap`(installed
170
- * `dsh-client-ui-slots/lib/types/index.d.ts:33`「Dictionary owners extend via declaration
172
+ * `dsh-client-ui-slots/lib/types/index.d.ts:23`「Dictionary owners extend via declaration
171
173
  * merging (exactly like SlotMap)」)。这不是美化:不 merge 时 `ctx.locale.bind(NS)` 只能
172
174
  * 落到官方那条**未类型化**重载(返回 `Translate<string>`),卡片要的窄键集 `t` 就无官方
173
175
  * 来源,本地只好手写一份同构签名(就是被这一段替换掉的旧版本)。