@jayyuen66/dsh-dir-prep-organize 0.1.6 → 0.1.8
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/CHANGELOG.md +48 -0
- package/LICENSE +1 -8
- package/README.md +23 -19
- package/README.zh-CN.md +23 -19
- package/THIRD_PARTY_NOTICES.md +7 -5
- package/client.js +466 -281
- package/docs/DETAIL.md +26 -0
- package/docs/DETAIL.zh.md +26 -0
- package/host.js +119 -44
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +56 -45
- package/types/host.d.ts +35 -2
- package/types/src/client-entry.d.ts +2 -3
- package/types/src/input-writeback.d.ts +32 -0
- package/types/src/templates.d.ts +22 -10
- package/types/src/ui-messages.d.ts +14 -4
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Draft polish and templates
|
|
2
|
+
|
|
3
|
+
Polishes the draft sitting in the input box before you send it, and inserts curated templates at the cursor.
|
|
4
|
+
|
|
5
|
+
## What the card changes
|
|
6
|
+
|
|
7
|
+
This card has two list editors rather than a grid of knobs.
|
|
8
|
+
|
|
9
|
+
- **Role library** — rows of name, emoji, group, description and body, which the input-box Template picker reads. Leaving the table empty is not a disabled state: the plugin then serves its built-in curated set, fetched on demand rather than shipped inside the form description.
|
|
10
|
+
- **Import-allowed roots** — additional absolute directories whose role files may be imported. An empty list adds nothing: this card has no session context, so only the bundled `agents/` role library stays importable; the endpoint called with a session also accepts paths inside that session's cwd. Absolute paths outside those zones stay refused. It is not a placeholder waiting to be filled.
|
|
11
|
+
|
|
12
|
+
Both are read per request, so a change applies on the next action without restarting the host.
|
|
13
|
+
|
|
14
|
+
## Values that are not on the card
|
|
15
|
+
|
|
16
|
+
`organizeTimeoutMs` is marked as a live value but has no knob here: the client reads it only to size its own fetch timeout, and the host times out first.
|
|
17
|
+
|
|
18
|
+
`maxSnippetBytes` and `readConcurrency` are deployment assumptions kept off the card deliberately. Set them in the `config:` block of this plugin's row in `cordis.patch.yml`; they take effect on restart.
|
|
19
|
+
|
|
20
|
+
## What it needs from outside
|
|
21
|
+
|
|
22
|
+
No external CLI, interpreter or credential of its own. It uses the host's model runtime and model selection (the live agent's current choice, falling back to the default selection), the session store and the filesystem service; polish follows the model selected for that conversation, so switching the model in the input area changes what the next polish call uses.
|
|
23
|
+
|
|
24
|
+
## Further detail
|
|
25
|
+
|
|
26
|
+
The vendored role library, the generated default-template table and the import-scan depth rules are developer-facing and live in the package README (`README.md` / `README.zh-CN.md`).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# 输入框润色与模板
|
|
2
|
+
|
|
3
|
+
在发送之前把输入框里的草稿润色一遍,并把精选模板插到光标处。
|
|
4
|
+
|
|
5
|
+
## 设置卡上改的是什么
|
|
6
|
+
|
|
7
|
+
这张卡是两个列表编辑器,不是一堆开关。
|
|
8
|
+
|
|
9
|
+
- **角色库** — 每行是名称、表情、分组、说明与正文,输入框的「模板」选择器读的就是这张表。把表清空不是关掉功能:插件会改用随包内置的精选集合,需要时由宿主现取,而不是把整份塞进表单描述里。
|
|
10
|
+
- **允许导入的目录** — 额外允许导入角色文件的绝对目录。留空不额外放行:这张卡没有会话上下文,因此只剩随包内置的 `agents/` 角色库可导入;带会话调用的端点还接受该会话 cwd 之内的路径。这些区域之外的绝对路径仍被拒绝,而不是等着填的占位。
|
|
11
|
+
|
|
12
|
+
两者都是每次请求现读,改完下一次动作就生效,不需要重启宿主。
|
|
13
|
+
|
|
14
|
+
## 卡上没有的值
|
|
15
|
+
|
|
16
|
+
`organizeTimeoutMs` 虽标为即时生效,但卡上没有它的旋钮:客户端只读它来对齐自己的 fetch 超时,真正先超时的是宿主那侧。
|
|
17
|
+
|
|
18
|
+
`maxSnippetBytes` 与 `readConcurrency` 是刻意留在卡外的部署假定值。写在本插件注册行的 `config:` 块,改值随重启生效。
|
|
19
|
+
|
|
20
|
+
## 需要外部提供什么
|
|
21
|
+
|
|
22
|
+
不需要外部 CLI、解释器或自有凭据。它用宿主的模型运行时与模型选择(会话活 Agent 的当前选择,取不到时回落默认选择)、会话存储与文件系统服务;润色跟随当前会话选定的模型,所以在输入区换模型会改变下一次润色用的是哪个。
|
|
23
|
+
|
|
24
|
+
## 更完整的说明
|
|
25
|
+
|
|
26
|
+
vendored 角色库、生成的默认模板表、导入扫描的层数规则都属于开发面,写在随包 README(`README.md` / `README.zh-CN.md`)。
|
package/host.js
CHANGED
|
@@ -134,6 +134,9 @@ const AGENT_DIR_GROUP_LABELS = {
|
|
|
134
134
|
testing: "测试"
|
|
135
135
|
};
|
|
136
136
|
// src/templates.ts
|
|
137
|
+
/** frontmatter 的闭合围栏与正文行分隔。 */
|
|
138
|
+
const FRONTMATTER_CLOSE = /^---[ \t]*$/mu;
|
|
139
|
+
const LINE_BREAK = /\r?\n/u;
|
|
137
140
|
/** 角色正文提炼/「按角色风格润色」上下文:不设字符上限(用户拍板,
|
|
138
141
|
* 上下文完整性优先;模型 context 超限由模型报错提示用户自行处理)。 */
|
|
139
142
|
/** 仓库目录名 → 下拉分组标签的**唯一**导出点在 `./group-labels.generated.ts`(表源 =
|
|
@@ -162,9 +165,10 @@ function stripPairQuotes(value) {
|
|
|
162
165
|
return value;
|
|
163
166
|
}
|
|
164
167
|
/** frontmatter 键名形状:字母开头,随后字母/数字/下划线/连字符。 */
|
|
165
|
-
const FRONTMATTER_KEY = /^[A-Za-z][
|
|
166
|
-
/** 头部只解析前
|
|
167
|
-
|
|
168
|
+
const FRONTMATTER_KEY = /^[A-Za-z][\w-]*$/u;
|
|
169
|
+
/** 头部只解析前 200 行键值对(防御恶意超长头部拖慢)。20 行会让带 tags/多行说明的
|
|
170
|
+
* 合法角色文件在后半段丢 name/description,整份被判成非角色文件。 */
|
|
171
|
+
const FRONTMATTER_MAX_LINES = 200;
|
|
168
172
|
/** 视觉标记进入下拉前缀的最大字符数。 */
|
|
169
173
|
const EMOJI_MAX_LENGTH = 12;
|
|
170
174
|
/** 一行 frontmatter → `键 + 原样值`;无冒号 / 键名不合法 / 值为空 → 不算键值对。
|
|
@@ -183,13 +187,22 @@ function readFrontmatterPair(line) {
|
|
|
183
187
|
}
|
|
184
188
|
return result;
|
|
185
189
|
}
|
|
186
|
-
/**
|
|
190
|
+
/** 按 Unicode 码点截断:`String#slice` 数的是 UTF-16 码元,会把一个 emoji(代理对)或
|
|
191
|
+
* 组合字符劈成半个,落进模板后显示成空白方块。两个截断点(frontmatter 与设置卡草稿)
|
|
192
|
+
* 共用这一份实现,scripts/gen-defaults-lib.mjs 有同源镜像。 */
|
|
193
|
+
function truncateCodePoints(value, max) {
|
|
194
|
+
const points = Array.from(value);
|
|
195
|
+
return points.length > max ? points.slice(0, max).join("") : value;
|
|
196
|
+
}
|
|
197
|
+
/** 键 → 目标位:防重复(已有值不覆盖,取首个同名键);emoji 截断至 EMOJI_MAX_LENGTH(按码点)。 */
|
|
187
198
|
function takeFrontmatterField(fields, key, value) {
|
|
188
199
|
if (key === "name" && fields.name === "" && value.length > 0) fields.name = value;
|
|
189
200
|
else if (key === "description" && fields.description === "" && value.length > 0) fields.description = value;
|
|
190
|
-
else if (key === "emoji" && fields.emoji === "") fields.emoji = value
|
|
201
|
+
else if (key === "emoji" && fields.emoji === "") fields.emoji = truncateCodePoints(value, EMOJI_MAX_LENGTH);
|
|
191
202
|
}
|
|
192
|
-
/**
|
|
203
|
+
/** 缩进行:属于嵌套映射(`metadata:` 下的 `name:` 之类),不是 frontmatter 顶层键。 */
|
|
204
|
+
const INDENTED_LINE = /^\s/u;
|
|
205
|
+
/** 从 frontmatter 头部解析 name/description/emoji(只解析前 FRONTMATTER_MAX_LINES 行键值对,
|
|
193
206
|
* 防御恶意超长头部拖慢;防重复,取首个同名键)。 */
|
|
194
207
|
function parseFrontmatterFields(head) {
|
|
195
208
|
const fields = {
|
|
@@ -199,8 +212,10 @@ function parseFrontmatterFields(head) {
|
|
|
199
212
|
};
|
|
200
213
|
for (const [lineNum, rawLine] of head.split("\n").entries()) {
|
|
201
214
|
if (lineNum >= FRONTMATTER_MAX_LINES) break;
|
|
202
|
-
|
|
203
|
-
|
|
215
|
+
if (!INDENTED_LINE.test(rawLine)) {
|
|
216
|
+
const pair = readFrontmatterPair(rawLine.trim());
|
|
217
|
+
if (pair !== void 0) takeFrontmatterField(fields, pair.key, stripPairQuotes(pair.value));
|
|
218
|
+
}
|
|
204
219
|
}
|
|
205
220
|
return fields;
|
|
206
221
|
}
|
|
@@ -218,7 +233,7 @@ function parseAgentFrontmatter(text) {
|
|
|
218
233
|
let result;
|
|
219
234
|
if (firstNl !== -1 && norm.slice(0, firstNl).trim() === "---") {
|
|
220
235
|
const rest = norm.slice(firstNl + 1);
|
|
221
|
-
const closeIdx = rest.search(
|
|
236
|
+
const closeIdx = rest.search(FRONTMATTER_CLOSE);
|
|
222
237
|
if (closeIdx !== -1) {
|
|
223
238
|
const head = rest.slice(0, closeIdx);
|
|
224
239
|
const bodyStart = rest.indexOf("\n", closeIdx) + 1;
|
|
@@ -234,18 +249,8 @@ function parseAgentFrontmatter(text) {
|
|
|
234
249
|
}
|
|
235
250
|
return result;
|
|
236
251
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
*
|
|
240
|
-
* 规则(确定性,测试锁死):
|
|
241
|
-
* - ``` 围栏行整体剔除(围栏内容多为长代码样例,对角色语境价值低);
|
|
242
|
-
* - 行内反引号一并剔除——沿用"正文不含反引号、插入不破坏 markdown 围栏"不变式;
|
|
243
|
-
* - 不设字符上限(用户拍板):全量保留叙述内容,避免截断影响
|
|
244
|
-
* 「以角色风格润色」的上下文完整性;模型 context 超限由模型报错提示用户自行处理;
|
|
245
|
-
* - 结果 trim;空正文(全围栏/全空白)→ 空串。
|
|
246
|
-
*/
|
|
247
|
-
function condenseRoleBody(body) {
|
|
248
|
-
const lines = body.split(/\r?\n/u);
|
|
252
|
+
function tryCondenseRoleBody(body) {
|
|
253
|
+
const lines = body.split(LINE_BREAK);
|
|
249
254
|
const out = [];
|
|
250
255
|
let inFence = false;
|
|
251
256
|
let fenceStart = 0;
|
|
@@ -253,8 +258,10 @@ function condenseRoleBody(body) {
|
|
|
253
258
|
fenceStart = inFence ? 0 : index + 1;
|
|
254
259
|
inFence = !inFence;
|
|
255
260
|
} else if (inFence) {} else out.push(raw.replaceAll("`", ""));
|
|
256
|
-
|
|
257
|
-
|
|
261
|
+
return {
|
|
262
|
+
text: out.join("\n").trim(),
|
|
263
|
+
unclosedFenceLine: inFence ? fenceStart : void 0
|
|
264
|
+
};
|
|
258
265
|
}
|
|
259
266
|
// host.ts
|
|
260
267
|
/** 本包送进 `llm.stream({ messages })` 的润色请求帧是 **request-only 输入**:它从不落
|
|
@@ -331,11 +338,19 @@ async function importDefaultTemplates() {
|
|
|
331
338
|
* 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
|
|
332
339
|
* 读面,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一口径。
|
|
333
340
|
*
|
|
341
|
+
* @param load - 载入器,缺省即真实 import 产物;单测靠它把「首读失败」那一档做成可复跑
|
|
342
|
+
* 的判据(产物 URL 一旦被成功加载就进 ESM 缓存,改磁盘内容对后续 import 无效,所以失败路径
|
|
343
|
+
* 只能从这一个缝注入)。
|
|
334
344
|
* @returns 内置精选模板表
|
|
335
345
|
*/
|
|
336
|
-
async function loadDefaultTemplates() {
|
|
337
|
-
defaultTemplatesPromise ??=
|
|
338
|
-
|
|
346
|
+
async function loadDefaultTemplates(load = importDefaultTemplates) {
|
|
347
|
+
defaultTemplatesPromise ??= load();
|
|
348
|
+
try {
|
|
349
|
+
return await defaultTemplatesPromise;
|
|
350
|
+
} catch (error) {
|
|
351
|
+
defaultTemplatesPromise = void 0;
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
339
354
|
}
|
|
340
355
|
/** 关键文本扩展名(这些文件取首段摘要)。仅代码/文档/结构配置面;
|
|
341
356
|
* yaml/env 等敏感配置不取摘要(凭据泄露风险,实测 .credentials.yaml 被带出)。 */
|
|
@@ -425,8 +440,11 @@ function isSettingsService(value) {
|
|
|
425
440
|
function isSessionsService(value) {
|
|
426
441
|
return hasFnMember(value, "get");
|
|
427
442
|
}
|
|
443
|
+
function isAgentsService(value) {
|
|
444
|
+
return hasFnMember(value, "get");
|
|
445
|
+
}
|
|
428
446
|
function isFsService(value) {
|
|
429
|
-
return hasFnMember(value, "resolve") && hasFnMember(value, "stat");
|
|
447
|
+
return hasFnMember(value, "resolve") && hasFnMember(value, "stat") && hasFnMember(value, "listDir") && hasFnMember(value, "readText") && hasFnMember(value, "contains");
|
|
430
448
|
}
|
|
431
449
|
function isLlmService(value) {
|
|
432
450
|
return hasFnMember(value, "stream");
|
|
@@ -677,12 +695,14 @@ async function collectDirContext(fs, cwd, messages, limits) {
|
|
|
677
695
|
* 门禁后仍要求每个文件能解析出非空 frontmatter name(parseAgentFrontmatter),
|
|
678
696
|
* 否则跳过并计数——绝不返回任意文件原文,只产出模板条目形状。
|
|
679
697
|
*/
|
|
698
|
+
/** 两种路径分隔符(win32 与 POSIX)。 */
|
|
699
|
+
const PATH_SEPARATOR = /[\\/]/u;
|
|
680
700
|
/** 路径拆段(**逐段**比较而非字符串前缀:`/home/dev/project-two/x.md` 会骗过
|
|
681
701
|
* `startsWith("/home/dev/project")`,前缀式包含判断等于放行兄弟目录)。
|
|
682
702
|
* 两种分隔符都拆:win32 的 `path.resolve`/`path.relative` 产出 `\`,只按 `/` 拆会
|
|
683
703
|
* 把整条路径当成一段,于是合法子路径被判成越界、`..\` 也漏过逐段校验。 */
|
|
684
704
|
function pathSegments(absolute) {
|
|
685
|
-
return absolute.split(
|
|
705
|
+
return absolute.split(PATH_SEPARATOR).filter((token) => token.length > 0);
|
|
686
706
|
}
|
|
687
707
|
/** 逐段校验:段为 "." / ".." 一律拒(归一前必须先拦,否则 path.resolve 吃掉 `..`);
|
|
688
708
|
* checkHidden=true 时额外拒隐藏段(凭据/敏感目录,如 `.ssh`)。 */
|
|
@@ -747,14 +767,16 @@ function importPathError(requested, cwd, allowRoots, messages) {
|
|
|
747
767
|
if (!path.isAbsolute(trimmed) && cwd === void 0) return messages.relativeNeedsCwd;
|
|
748
768
|
const absolute = path.resolve(cwd ?? "", trimmed);
|
|
749
769
|
const roots = importRootsOf(cwd, allowRoots, messages);
|
|
750
|
-
const matched = roots.
|
|
751
|
-
if (matched ===
|
|
752
|
-
|
|
770
|
+
const matched = roots.filter((root) => isWithinRoot(root.absolute, absolute));
|
|
771
|
+
if (matched.length === 0) return outsideRootsError(absolute, roots, messages);
|
|
772
|
+
const errors = matched.toSorted((left, right) => right.absolute.length - left.absolute.length).map((root) => pathTokensError(path.relative(root.absolute, absolute), true, messages));
|
|
773
|
+
return errors.some((error) => error === void 0) ? void 0 : errors[0];
|
|
753
774
|
}
|
|
754
775
|
/** 角色文件 → 模板条目(正文提炼 + 目录分组标签 + 确定性 id 去重)。
|
|
755
776
|
* 正文提炼不设字符上限。 */
|
|
756
777
|
function agentEntryFromFile(slug, dirName, info, collided) {
|
|
757
|
-
const text =
|
|
778
|
+
const { text: condensedText, unclosedFenceLine } = tryCondenseRoleBody(info.body);
|
|
779
|
+
const text = unclosedFenceLine === void 0 ? condensedText : "";
|
|
758
780
|
let result;
|
|
759
781
|
if (text.length > 0) {
|
|
760
782
|
let suffix = collided.size;
|
|
@@ -779,9 +801,19 @@ function agentEntryFromFile(slug, dirName, info, collided) {
|
|
|
779
801
|
function isVisibleDirectory(child) {
|
|
780
802
|
return child.type === "directory" && !child.name.startsWith(".");
|
|
781
803
|
}
|
|
804
|
+
/** 扩展名是否 .md:不区分大小写。macOS 默认文件系统不区分大小写,`Agent.MD` 在用户看来
|
|
805
|
+
* 就是一份角色文件;按字节判后缀会把它静默丢在扫描面之外(且不计任何 skipped)。 */
|
|
806
|
+
function isMdName(name) {
|
|
807
|
+
return name.toLowerCase().endsWith(".md");
|
|
808
|
+
}
|
|
809
|
+
const MD_SUFFIX = /\.md$/iu;
|
|
810
|
+
/** 去掉 .md 后缀(大小写不敏感);没有该后缀时原样返回(replace 不命中即原样,无需分支)。 */
|
|
811
|
+
function stripMdSuffix(name) {
|
|
812
|
+
return name.replace(MD_SUFFIX, "");
|
|
813
|
+
}
|
|
782
814
|
/** 目录项是「可见 .md 文件」?(候选收集与第三层清点同一判据,两处必须数到同一批)。 */
|
|
783
815
|
function isVisibleMdFile(child) {
|
|
784
|
-
return child.type === "file" && child.name
|
|
816
|
+
return child.type === "file" && isMdName(child.name) && !child.name.startsWith(".");
|
|
785
817
|
}
|
|
786
818
|
/** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。
|
|
787
819
|
* `skipped` 就地累加 escaped 计数:被 contains 拦下的链接文件如果不数出来,
|
|
@@ -866,9 +898,17 @@ async function importFromFile(args, absolute) {
|
|
|
866
898
|
error: messages.missingRoleName
|
|
867
899
|
};
|
|
868
900
|
}
|
|
869
|
-
const entry = agentEntryFromFile(path.basename(absolute
|
|
901
|
+
const entry = agentEntryFromFile(stripMdSuffix(path.basename(absolute)), path.basename(path.dirname(absolute)), info, /* @__PURE__ */ new Set());
|
|
902
|
+
if (entry === void 0) {
|
|
903
|
+
skipped.unnamed += 1;
|
|
904
|
+
return {
|
|
905
|
+
entries: [],
|
|
906
|
+
truncated: true,
|
|
907
|
+
skipped
|
|
908
|
+
};
|
|
909
|
+
}
|
|
870
910
|
return {
|
|
871
|
-
entries:
|
|
911
|
+
entries: [entry],
|
|
872
912
|
truncated: false,
|
|
873
913
|
skipped
|
|
874
914
|
};
|
|
@@ -916,7 +956,7 @@ function pushReadResult(read, entries, collided, skipped) {
|
|
|
916
956
|
skipped.unnamed += 1;
|
|
917
957
|
return;
|
|
918
958
|
}
|
|
919
|
-
const entry = agentEntryFromFile(
|
|
959
|
+
const entry = agentEntryFromFile(stripMdSuffix(read.file.name), read.file.dirName, read.info, collided);
|
|
920
960
|
if (entry === void 0) {
|
|
921
961
|
skipped.unnamed += 1;
|
|
922
962
|
return;
|
|
@@ -930,11 +970,16 @@ function pushReadResult(read, entries, collided, skipped) {
|
|
|
930
970
|
async function importFromDirectory(fs, absolute, target, limits, skipped) {
|
|
931
971
|
const rootChildren = await fs.listDir(target);
|
|
932
972
|
const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute), skipped);
|
|
933
|
-
const subScans = await mapBounded(rootChildren.filter((child) =>
|
|
973
|
+
const subScans = await mapBounded(rootChildren.filter((child) => {
|
|
974
|
+
if (!isVisibleDirectory(child)) return false;
|
|
975
|
+
const inside = fs.contains(target, child.target);
|
|
976
|
+
if (!inside) skipped.escaped += 1;
|
|
977
|
+
return inside;
|
|
978
|
+
}).map((child) => child.target).toSorted((left, right) => left.displayPath.localeCompare(right.displayPath)), limits.readConcurrency, async (sub) => {
|
|
934
979
|
const children = await listDirOrUnreadable(fs, sub, skipped);
|
|
935
980
|
return {
|
|
936
981
|
files: mdCandidates(fs, target, children, path.basename(sub.displayPath), skipped),
|
|
937
|
-
deeper: children.filter((child) => isVisibleDirectory(child)).map((child) => child.target)
|
|
982
|
+
deeper: children.filter((child) => isVisibleDirectory(child) && fs.contains(target, child.target)).map((child) => child.target)
|
|
938
983
|
};
|
|
939
984
|
});
|
|
940
985
|
const subFiles = [];
|
|
@@ -982,7 +1027,7 @@ async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
|
|
|
982
1027
|
error: outsideRootsError(target.displayPath, roots, messages)
|
|
983
1028
|
};
|
|
984
1029
|
}
|
|
985
|
-
if (absolute
|
|
1030
|
+
if (isMdName(absolute)) return await importFromFile({
|
|
986
1031
|
fs,
|
|
987
1032
|
target,
|
|
988
1033
|
limits,
|
|
@@ -1209,11 +1254,21 @@ const configShape = {
|
|
|
1209
1254
|
const configSchema = Schema.object(configShape);
|
|
1210
1255
|
/** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
|
|
1211
1256
|
* 引用背后可能是存量脏配置:非数组一律空表(fail-closed),非字符串/纯空白项逐个
|
|
1212
|
-
* 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
|
|
1257
|
+
* 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
|
|
1258
|
+
* 相对路径同样丢弃:契约写的是「额外允许的**绝对**目录」(见 schema describe 与 DETAIL
|
|
1259
|
+
* 文档),放进来会被 toImportRoot 的 path.resolve 按**宿主进程 cwd** 解析,变成一条用户
|
|
1260
|
+
* 没写过、也不知道存在着的允许根。 */
|
|
1213
1261
|
function importAllowRootsOf(raw) {
|
|
1214
1262
|
const roots = [];
|
|
1263
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1215
1264
|
if (Array.isArray(raw)) {
|
|
1216
|
-
for (const item of raw) if (typeof item === "string" && item.trim().length > 0
|
|
1265
|
+
for (const item of raw) if (typeof item === "string" && item.trim().length > 0 && path.isAbsolute(item.trim())) {
|
|
1266
|
+
const normalized = path.resolve(item.trim());
|
|
1267
|
+
if (!seen.has(normalized)) {
|
|
1268
|
+
seen.add(normalized);
|
|
1269
|
+
roots.push(normalized);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1217
1272
|
}
|
|
1218
1273
|
return roots;
|
|
1219
1274
|
}
|
|
@@ -1224,8 +1279,20 @@ function importAllowRootsOf(raw) {
|
|
|
1224
1279
|
* settings.plugin.item 卡」(dsh-client-ui-settings-plugins 源码语义),configure 必须
|
|
1225
1280
|
* 发生在 apply 期,故仍硬注入。sessions/fs/llm/agentDefaultModel 仍可选读。 */
|
|
1226
1281
|
const inject = ["settings"];
|
|
1282
|
+
/** 会话活线模型:新版读 `agent.model.current()`(含待切换选择),旧版回落
|
|
1283
|
+
* `agent.options`。没有活 Agent、或两处都答不全时 undefined(调用方回落默认模型)。
|
|
1284
|
+
* 与 rescue 同一条规则:`current()` 交回 undefined 是「还没记录过选择」,不是读失败。 */
|
|
1285
|
+
function liveModelOf(deps, sessionId) {
|
|
1286
|
+
const agent = sessionId === null ? void 0 : deps.agents?.()?.get(sessionIdOf(sessionId));
|
|
1287
|
+
const raw = agent?.model?.current() ?? agent?.options;
|
|
1288
|
+
return raw !== void 0 && typeof raw.provider === "string" && raw.provider.length > 0 && typeof raw.model === "string" && raw.model.length > 0 ? {
|
|
1289
|
+
provider: raw.provider,
|
|
1290
|
+
model: raw.model,
|
|
1291
|
+
...raw.reasoningEffort === void 0 ? {} : { reasoningEffort: raw.reasoningEffort }
|
|
1292
|
+
} : void 0;
|
|
1293
|
+
}
|
|
1227
1294
|
/** 当前默认模型解析(缺服务/抛错 → undefined)。 */
|
|
1228
|
-
function
|
|
1295
|
+
function defaultModelOf(deps) {
|
|
1229
1296
|
const current = deps.agentDefaultModel?.();
|
|
1230
1297
|
let result;
|
|
1231
1298
|
if (current !== void 0) try {
|
|
@@ -1238,6 +1305,10 @@ function resolveModel(deps) {
|
|
|
1238
1305
|
} catch {}
|
|
1239
1306
|
return result;
|
|
1240
1307
|
}
|
|
1308
|
+
/** 润色的模型来源:会话活线优先,没有才用默认模型。 */
|
|
1309
|
+
function resolveModel(deps, sessionId) {
|
|
1310
|
+
return liveModelOf(deps, sessionId) ?? defaultModelOf(deps);
|
|
1311
|
+
}
|
|
1241
1312
|
/** 会话最近对话文本提取(deriveMessages 尾部;缺会话/无方法/抛错 → 空串)。 */
|
|
1242
1313
|
function resolveRecentTurns(sessions, sessionId) {
|
|
1243
1314
|
const session = sessionId === null ? void 0 : sessions?.get(sessionIdOf(sessionId));
|
|
@@ -1377,7 +1448,7 @@ async function organizePayload(scope, parsed) {
|
|
|
1377
1448
|
ok: false,
|
|
1378
1449
|
error: messages.cwdUnknown
|
|
1379
1450
|
};
|
|
1380
|
-
const model = resolveModel(scope.deps);
|
|
1451
|
+
const model = resolveModel(scope.deps, sessionIdText);
|
|
1381
1452
|
try {
|
|
1382
1453
|
return {
|
|
1383
1454
|
ok: true,
|
|
@@ -1597,6 +1668,10 @@ function apply(ctx, config) {
|
|
|
1597
1668
|
const service = getService("agentDefaultModel");
|
|
1598
1669
|
return isAgentDefaultModel(service) ? service : void 0;
|
|
1599
1670
|
},
|
|
1671
|
+
agents: () => {
|
|
1672
|
+
const service = getService("agents");
|
|
1673
|
+
return isAgentsService(service) ? service : void 0;
|
|
1674
|
+
},
|
|
1600
1675
|
importAllowRoots: () => importAllowRootsOf(config.importAllowRoots.get()),
|
|
1601
1676
|
limits: limitsOfConfig
|
|
1602
1677
|
},
|
|
@@ -1607,4 +1682,4 @@ function apply(ctx, config) {
|
|
|
1607
1682
|
installDirPrepRemote(child, scope);
|
|
1608
1683
|
});
|
|
1609
1684
|
}
|
|
1610
|
-
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 };
|
|
1685
|
+
export { configSchema as Config, DIR_PREP_REMOTE_NAMESPACE, DirPrepRemoteService, apply, buildOrganizeSystem, buildOrganizeUser, clampInt, collectAgentTemplates, collectDirContext, createRemotePayloads, defaultTemplatesFrom, drainStreamToText, extractRecentTurns, importAllowRootsOf, importPathError, inject, installDirPrepRemote, liveModelOf, loadDefaultTemplates, runOrganize, sanitizeLimits };
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayyuen66/dsh-dir-prep-organize",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "dsh 插件:对话输入框「润色」按钮(主键直接润色/▾ 以角色风格润色,结合当前目录 + session 模型润色草稿)+「模板」下拉(内置精选角色集生成自插件 agents/ 角色库,可按部门分组;设置卡可增删改/一键导入内置全部/导入本地角色 .md)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cordis",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"url": "https://github.com/JayYuen666/dsh-dir-prep-organize/issues"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"author":
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "JayYuen",
|
|
20
|
+
"url": "https://github.com/JayYuen666"
|
|
21
|
+
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
21
24
|
"url": "git+https://github.com/JayYuen666/dsh-dir-prep-organize.git"
|
|
@@ -28,6 +31,9 @@
|
|
|
28
31
|
"types",
|
|
29
32
|
"cordis.patch.yml",
|
|
30
33
|
"agents",
|
|
34
|
+
"locale/zh.json",
|
|
35
|
+
"locale/en.json",
|
|
36
|
+
"docs",
|
|
31
37
|
"README.zh-CN.md",
|
|
32
38
|
"CHANGELOG.md",
|
|
33
39
|
"THIRD_PARTY_NOTICES.md"
|
|
@@ -47,6 +53,7 @@
|
|
|
47
53
|
},
|
|
48
54
|
"./client": "./client.js",
|
|
49
55
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
56
|
+
"./locale/*.json": "./locale/*.json",
|
|
50
57
|
"./package.json": "./package.json"
|
|
51
58
|
},
|
|
52
59
|
"publishConfig": {
|
|
@@ -54,42 +61,46 @@
|
|
|
54
61
|
"registry": "https://registry.npmjs.org"
|
|
55
62
|
},
|
|
56
63
|
"dependencies": {
|
|
57
|
-
"@jayyuen66/dsh-plugin-shared": "0.
|
|
64
|
+
"@jayyuen66/dsh-plugin-shared": "0.2.2",
|
|
65
|
+
"zod": "4.6.7"
|
|
58
66
|
},
|
|
59
67
|
"devDependencies": {
|
|
60
|
-
"@deepseek-ai/cordis": "4.0.
|
|
61
|
-
"@deepseek-ai/cordis-plugin-group": "1.0.
|
|
62
|
-
"@deepseek-ai/cordis-plugin-include": "1.0.
|
|
63
|
-
"@deepseek-ai/cosmokit": "1.8.
|
|
64
|
-
"@deepseek-ai/dsh-agent-default-model": "0.2.
|
|
65
|
-
"@deepseek-ai/dsh-app-boot": "0.2.
|
|
66
|
-
"@deepseek-ai/dsh-brand": "0.2.
|
|
67
|
-
"@deepseek-ai/dsh-client-locale": "0.2.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.
|
|
70
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.
|
|
72
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.
|
|
73
|
-
"@deepseek-ai/dsh-config-editor": "0.2.
|
|
74
|
-
"@deepseek-ai/dsh-fs": "0.2.
|
|
75
|
-
"@deepseek-ai/dsh-home-paths": "0.2.
|
|
76
|
-
"@deepseek-ai/dsh-
|
|
77
|
-
"@deepseek-ai/dsh-
|
|
78
|
-
"@deepseek-ai/dsh-
|
|
79
|
-
"@deepseek-ai/dsh-
|
|
80
|
-
"@deepseek-ai/dsh-
|
|
81
|
-
"@deepseek-ai/dsh-
|
|
82
|
-
"@deepseek-ai/dsh-
|
|
83
|
-
"@deepseek-ai/
|
|
84
|
-
"@
|
|
85
|
-
"@types/node": "26.6.
|
|
68
|
+
"@deepseek-ai/cordis": "4.0.6-alpha.1",
|
|
69
|
+
"@deepseek-ai/cordis-plugin-group": "1.0.6-alpha.1",
|
|
70
|
+
"@deepseek-ai/cordis-plugin-include": "1.0.11-alpha.1",
|
|
71
|
+
"@deepseek-ai/cosmokit": "1.8.7-alpha.1",
|
|
72
|
+
"@deepseek-ai/dsh-agent-default-model": "0.2.2-alpha.2",
|
|
73
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-alpha.2",
|
|
74
|
+
"@deepseek-ai/dsh-brand": "0.2.2-alpha.2",
|
|
75
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-alpha.2",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-alpha.2",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-alpha.2",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-alpha.2",
|
|
79
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-alpha.2",
|
|
80
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-alpha.2",
|
|
81
|
+
"@deepseek-ai/dsh-config-editor": "0.2.2-alpha.2",
|
|
82
|
+
"@deepseek-ai/dsh-fs": "0.2.2-alpha.2",
|
|
83
|
+
"@deepseek-ai/dsh-home-paths": "0.2.2-alpha.2",
|
|
84
|
+
"@deepseek-ai/dsh-launch-environment": "0.2.2-alpha.2",
|
|
85
|
+
"@deepseek-ai/dsh-llm": "0.2.2-alpha.2",
|
|
86
|
+
"@deepseek-ai/dsh-sandbox": "0.2.2-alpha.2",
|
|
87
|
+
"@deepseek-ai/dsh-scope": "0.2.2-alpha.2",
|
|
88
|
+
"@deepseek-ai/dsh-session": "0.2.2-alpha.2",
|
|
89
|
+
"@deepseek-ai/dsh-settings": "0.2.2-alpha.2",
|
|
90
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-alpha.2",
|
|
91
|
+
"@deepseek-ai/schemastery": "3.18.6-alpha.1",
|
|
92
|
+
"@e18e/eslint-plugin": "0.8.1",
|
|
93
|
+
"@types/node": "26.6.6",
|
|
86
94
|
"@types/react": "19.3.0",
|
|
87
95
|
"@types/react-dom": "19.3.0",
|
|
88
96
|
"@vitest/coverage-v8": "5.0.5",
|
|
97
|
+
"eslint-plugin-regexp": "3.3.2",
|
|
89
98
|
"eslint-plugin-sonarjs": "4.2.2",
|
|
99
|
+
"eslint-plugin-zod": "5.2.2",
|
|
100
|
+
"fast-check": "4.10.2",
|
|
90
101
|
"happy-dom": "21.0.4",
|
|
91
|
-
"oxfmt": "0.
|
|
92
|
-
"oxlint": "1.
|
|
102
|
+
"oxfmt": "0.75.0",
|
|
103
|
+
"oxlint": "1.90.0",
|
|
93
104
|
"oxlint-tsgolint": "7.0.2005",
|
|
94
105
|
"react": "^19.3.0",
|
|
95
106
|
"react-dom": "^19.3.0",
|
|
@@ -99,21 +110,21 @@
|
|
|
99
110
|
"vitest": "5.0.5"
|
|
100
111
|
},
|
|
101
112
|
"peerDependencies": {
|
|
102
|
-
"@deepseek-ai/cordis": "4.0.5",
|
|
103
|
-
"@deepseek-ai/cosmokit": "1.8.
|
|
113
|
+
"@deepseek-ai/cordis": "~4.0.5 || 4.0.6-alpha.1",
|
|
114
|
+
"@deepseek-ai/cosmokit": "1.8.7-alpha.1",
|
|
104
115
|
"@deepseek-ai/dsh": "^0.2.1-rc.3",
|
|
105
|
-
"@deepseek-ai/dsh-agent-default-model": "0.2.1-rc.3",
|
|
106
|
-
"@deepseek-ai/dsh-brand": "0.2.1-rc.3",
|
|
107
|
-
"@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
|
|
108
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.3",
|
|
109
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
|
|
110
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
|
|
111
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
|
|
112
|
-
"@deepseek-ai/dsh-fs": "0.2.1-rc.3",
|
|
113
|
-
"@deepseek-ai/dsh-llm": "0.2.1-rc.3",
|
|
114
|
-
"@deepseek-ai/dsh-session": "0.2.1-rc.3",
|
|
115
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3",
|
|
116
|
-
"@deepseek-ai/schemastery": "3.18.
|
|
116
|
+
"@deepseek-ai/dsh-agent-default-model": "^0.2.1-rc.3",
|
|
117
|
+
"@deepseek-ai/dsh-brand": "^0.2.1-rc.3",
|
|
118
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.1-rc.3",
|
|
119
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.1-rc.3",
|
|
120
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.3",
|
|
121
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.1-rc.3",
|
|
122
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
|
|
123
|
+
"@deepseek-ai/dsh-fs": "^0.2.1-rc.3",
|
|
124
|
+
"@deepseek-ai/dsh-llm": "^0.2.1-rc.3",
|
|
125
|
+
"@deepseek-ai/dsh-session": "^0.2.1-rc.3",
|
|
126
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
|
|
127
|
+
"@deepseek-ai/schemastery": "^3.18.6-alpha.1"
|
|
117
128
|
},
|
|
118
129
|
"peerDependenciesMeta": {
|
|
119
130
|
"@deepseek-ai/cordis": {
|
package/types/host.d.ts
CHANGED
|
@@ -24,9 +24,12 @@ export declare function defaultTemplatesFrom(raw: unknown): readonly TemplateEnt
|
|
|
24
24
|
* 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
|
|
25
25
|
* 读面,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一口径。
|
|
26
26
|
*
|
|
27
|
+
* @param load - 载入器,缺省即真实 import 产物;单测靠它把「首读失败」那一档做成可复跑
|
|
28
|
+
* 的判据(产物 URL 一旦被成功加载就进 ESM 缓存,改磁盘内容对后续 import 无效,所以失败路径
|
|
29
|
+
* 只能从这一个缝注入)。
|
|
27
30
|
* @returns 内置精选模板表
|
|
28
31
|
*/
|
|
29
|
-
export declare function loadDefaultTemplates(): Promise<readonly TemplateEntry[]>;
|
|
32
|
+
export declare function loadDefaultTemplates(load?: () => Promise<readonly TemplateEntry[]>): Promise<readonly TemplateEntry[]>;
|
|
30
33
|
/**
|
|
31
34
|
* 把一个部署来的数夹进 `[min, max]`,非有限值回落到 `fallback`。
|
|
32
35
|
*
|
|
@@ -112,6 +115,27 @@ export interface SessionLike {
|
|
|
112
115
|
export interface SessionsService {
|
|
113
116
|
get: (id: SessionId) => SessionLike | undefined;
|
|
114
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
|
+
}
|
|
115
139
|
/** `ReasoningEffortId` 取官方真品牌(`Branded<'ReasoningEffortId'>`,以 dsh-brand 的
|
|
116
140
|
* `unique symbol` 为键)。本地重述成 `string & { effortBrand: ... }` 是**假品牌**:
|
|
117
141
|
* 键不同名即不同型,宿主真值塞不进来、任何带该属性的字符串反倒能通过,注释里那句
|
|
@@ -360,7 +384,10 @@ export interface Config {
|
|
|
360
384
|
export { configSchema as Config };
|
|
361
385
|
/** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
|
|
362
386
|
* 引用背后可能是存量脏配置:非数组一律空表(fail-closed),非字符串/纯空白项逐个
|
|
363
|
-
* 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
|
|
387
|
+
* 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
|
|
388
|
+
* 相对路径同样丢弃:契约写的是「额外允许的**绝对**目录」(见 schema describe 与 DETAIL
|
|
389
|
+
* 文档),放进来会被 toImportRoot 的 path.resolve 按**宿主进程 cwd** 解析,变成一条用户
|
|
390
|
+
* 没写过、也不知道存在着的允许根。 */
|
|
364
391
|
export declare function importAllowRootsOf(raw: unknown): string[];
|
|
365
392
|
/** 注入的服务面:settings 为硬依赖(cordis 等它就绪才 apply)。
|
|
366
393
|
* 命名空间是隐式的(= 本条目在 cordis.patch.yml 里的裸 id,可编辑字段取自
|
|
@@ -376,6 +403,8 @@ export interface RouteDeps {
|
|
|
376
403
|
fs?: () => FsService | undefined;
|
|
377
404
|
llm?: () => LlmService | undefined;
|
|
378
405
|
agentDefaultModel?: () => AgentDefaultModel | undefined;
|
|
406
|
+
/** 会话活线:有活 Agent 时润色跟随它的模型,没有才回落默认模型。 */
|
|
407
|
+
agents?: () => AgentsService | undefined;
|
|
379
408
|
/** 设置里登记的额外导入允许根(每次请求现读,改设置无需重启)。 */
|
|
380
409
|
importAllowRoots?: () => readonly string[];
|
|
381
410
|
/** 部署值(Config 化):润色超时 / 摘要字节上限 / 读取并发。
|
|
@@ -388,6 +417,10 @@ export interface RouteDeps {
|
|
|
388
417
|
/** 回执字典的现读 getter:每个请求取一次,用户在「设置 → 常规」改语言后下一个请求即
|
|
389
418
|
* 切文案(不重启、不加插件自己的 locale 设置项;与 importAllowRoots 的现读同构)。 */
|
|
390
419
|
export type MessagesOf = () => HostMessages;
|
|
420
|
+
/** 会话活线模型:新版读 `agent.model.current()`(含待切换选择),旧版回落
|
|
421
|
+
* `agent.options`。没有活 Agent、或两处都答不全时 undefined(调用方回落默认模型)。
|
|
422
|
+
* 与 rescue 同一条规则:`current()` 交回 undefined 是「还没记录过选择」,不是读失败。 */
|
|
423
|
+
export declare function liveModelOf(deps: RouteDeps, sessionId: string | null): ModelSelection | undefined;
|
|
391
424
|
/** 读面每次调用的共享面:服务 getter 与现读文案/限额。 */
|
|
392
425
|
interface RemoteScope {
|
|
393
426
|
readonly deps: RouteDeps;
|