@cheemsup/dsh-plugin-console 0.0.0-stage → 0.2.0

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.
Files changed (101) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +95 -3
  3. package/cordis.patch.yml +5 -0
  4. package/icon.svg +203 -0
  5. package/lib/client.activity.js +222 -0
  6. package/lib/client.apply.js +171 -0
  7. package/lib/client.changes.js +206 -0
  8. package/lib/client.cleanup.js +270 -0
  9. package/lib/client.control.js +247 -0
  10. package/lib/client.dialog.js +77 -0
  11. package/lib/client.disable-preview.js +904 -0
  12. package/lib/client.draft.js +280 -0
  13. package/lib/client.editor-messages.js +421 -0
  14. package/lib/client.editor-store.js +266 -0
  15. package/lib/client.editor.js +433 -0
  16. package/lib/client.effects.js +115 -0
  17. package/lib/client.impact-tree.js +487 -0
  18. package/lib/client.influence.js +361 -0
  19. package/lib/client.js +246 -0
  20. package/lib/client.page.js +646 -0
  21. package/lib/client.plugin-filters.js +62 -0
  22. package/lib/client.plugins.js +506 -0
  23. package/lib/client.preview-messages.js +506 -0
  24. package/lib/client.preview-raw.js +132 -0
  25. package/lib/client.preview-store.js +128 -0
  26. package/lib/client.preview-tools.js +194 -0
  27. package/lib/client.preview.js +448 -0
  28. package/lib/client.relation-graph.js +364 -0
  29. package/lib/client.schema.js +327 -0
  30. package/lib/client.search.js +409 -0
  31. package/lib/client.session-detail.js +503 -0
  32. package/lib/client.sessions.js +495 -0
  33. package/lib/client.shared.js +562 -0
  34. package/lib/client.store.js +452 -0
  35. package/lib/client.styles.js +589 -0
  36. package/lib/client.template-card.js +240 -0
  37. package/lib/client.tools.js +366 -0
  38. package/lib/client.workspace-picker.js +204 -0
  39. package/lib/host/activity.js +252 -0
  40. package/lib/host/assembly-preview.js +244 -0
  41. package/lib/host/attribution.js +341 -0
  42. package/lib/host/catalog.js +133 -0
  43. package/lib/host/categorize.js +40 -0
  44. package/lib/host/config-layers.js +589 -0
  45. package/lib/host/constants.js +69 -0
  46. package/lib/host/control.js +159 -0
  47. package/lib/host/disable-preview.js +651 -0
  48. package/lib/host/entries.js +289 -0
  49. package/lib/host/fiber.js +86 -0
  50. package/lib/host/fs.js +99 -0
  51. package/lib/host/health.js +178 -0
  52. package/lib/host/http.js +65 -0
  53. package/lib/host/impact.js +138 -0
  54. package/lib/host/injection-owners.js +60 -0
  55. package/lib/host/layers.js +132 -0
  56. package/lib/host/masks.js +145 -0
  57. package/lib/host/modes.js +96 -0
  58. package/lib/host/names.js +44 -0
  59. package/lib/host/patch-config.js +554 -0
  60. package/lib/host/patch-scan.js +103 -0
  61. package/lib/host/preview-conditions.js +281 -0
  62. package/lib/host/preview-contexts.js +174 -0
  63. package/lib/host/preview-envelope.js +31 -0
  64. package/lib/host/preview-instructions.js +450 -0
  65. package/lib/host/preview-messages.js +284 -0
  66. package/lib/host/preview-modules.js +233 -0
  67. package/lib/host/preview-skills.js +200 -0
  68. package/lib/host/prompt.js +213 -0
  69. package/lib/host/recipe-overlay.js +209 -0
  70. package/lib/host/request-preview.js +114 -0
  71. package/lib/host/routes/activation.js +96 -0
  72. package/lib/host/routes/activity.js +22 -0
  73. package/lib/host/routes/apply.js +93 -0
  74. package/lib/host/routes/cleanup.js +62 -0
  75. package/lib/host/routes/control.js +22 -0
  76. package/lib/host/routes/disable-preview.js +19 -0
  77. package/lib/host/routes/impact.js +19 -0
  78. package/lib/host/routes/operations.js +22 -0
  79. package/lib/host/routes/preview.js +58 -0
  80. package/lib/host/routes/session-influence.js +23 -0
  81. package/lib/host/routes/snapshot.js +21 -0
  82. package/lib/host/routes/template.js +54 -0
  83. package/lib/host/routes/templates.js +28 -0
  84. package/lib/host/scope-impact.js +125 -0
  85. package/lib/host/session-events.js +39 -0
  86. package/lib/host/session-influence.js +467 -0
  87. package/lib/host/sessions.js +293 -0
  88. package/lib/host/snapshot.js +218 -0
  89. package/lib/host/source-scan.js +225 -0
  90. package/lib/host/templates/cleanup.js +219 -0
  91. package/lib/host/templates/inheritance.js +144 -0
  92. package/lib/host/templates/materialize.js +317 -0
  93. package/lib/host/templates/message-overlay.js +184 -0
  94. package/lib/host/templates/repository.js +323 -0
  95. package/lib/host/templates/store.js +131 -0
  96. package/lib/host/tool-set.js +150 -0
  97. package/lib/host/tools.js +129 -0
  98. package/lib/index.js +106 -0
  99. package/locale/en.json +6 -0
  100. package/locale/zh.json +6 -0
  101. package/package.json +124 -6
@@ -0,0 +1,133 @@
1
+ /**
2
+ * skill 目录的模型可见帧。
3
+ *
4
+ * 这段文字属于 `@deepseek-ai/dsh-tool-skill`,不属于本插件;预演与真实 pre-step
5
+ * 改写必须渲染出**同一份**帧,所以集中在这里,只保留一处可移植的副本。
6
+ *
7
+ * 帧抄自已安装版 `0.2.2-rc.1`。DSH 升级后如果文案变化,`verify-request-preview`
8
+ * 的逐字 fixture 会先红,改这里即可。
9
+ * @module dsh-plugin-console/host/catalog
10
+ */
11
+
12
+ /** 行配置缺省值,与已安装版 `@deepseek-ai/dsh-tool-skill` 的 Config 默认一致。 */
13
+ export const CATALOG_DEFAULT_MAX_LENGTH = 500
14
+
15
+ /** 目录描述里的 `&` / `<` / `>` 必须转义:它们会被嵌进伪 XML 帧里。 */
16
+ export function escapeText(value) {
17
+ return String(value ?? '').replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
18
+ }
19
+
20
+ /** 属性值只转义会破坏引号结构的字符。 */
21
+ export function escapeAttr(value) {
22
+ return String(value ?? '').replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;')
23
+ }
24
+
25
+ /**
26
+ * 描述归一化并截断:连续空白折成一个空格,超长截到 `maxLength - 3` 再补 `...`。
27
+ * @param {string} value - 原始描述。
28
+ * @param {number} maxLength - 上限。
29
+ * @returns {string} 归一化后的描述。
30
+ */
31
+ export function catalogDescription(value, maxLength) {
32
+ const normalized = String(value ?? '').replaceAll(/\s+/g, ' ').trim()
33
+ return normalized.length <= maxLength ? normalized : `${normalized.slice(0, maxLength - 3)}...`
34
+ }
35
+
36
+ /** 目录条目行;条目只暴露 name / description。 */
37
+ function renderCatalogEntries(entries) {
38
+ return entries.map((entry) => `- \`${entry.name}\`: ${escapeText(entry.description)}`)
39
+ }
40
+
41
+ /** 不完整目录的提示句,首包与更新包共用。 */
42
+ function incompleteCatalogNotice() {
43
+ return 'Some skills could not be checked. Only confirmed skills are listed; a lower-priority definition of the same name may be selected when a preferred source is unavailable. Discovery will be retried on the next request.'
44
+ }
45
+
46
+ /**
47
+ * 首包目录消息。
48
+ *
49
+ * 与「目录更新」消息(后续轮次才会出现)刻意不同:首包要解释「这是本会话可见的
50
+ * 全部 skill」,更新包要说明「它替换了之前的列表」。首请求只会遇到前者。
51
+ * @param {Array<{name: string, description: string}>} entries - 目录条目。
52
+ * @param {boolean} incomplete - 快照是否不完整。
53
+ * @returns {string} 消息正文。
54
+ */
55
+ export function renderCatalogMessage(entries, incomplete) {
56
+ return [
57
+ '<system-reminder>',
58
+ entries.length === 0
59
+ ? 'No skills could be confirmed in this discovery attempt.'
60
+ : 'A skill is a reusable set of task-specific instructions. The following skills are available in this session:',
61
+ '',
62
+ '<available_skills>',
63
+ ...renderCatalogEntries(entries),
64
+ '</available_skills>',
65
+ '',
66
+ ...(incomplete ? [incompleteCatalogNotice(), ''] : []),
67
+ entries.length === 0
68
+ ? 'Wait for an updated catalog before calling the `skill` tool. Do not infer skill instructions from an empty catalog.'
69
+ : "If the user names a skill, or the task clearly matches a skill's description, call the `skill` tool with the exact skill name before taking task actions. Load all applicable skills, then follow their full instructions. This catalog contains summaries only; do not infer or follow a skill's instructions until it has been loaded.",
70
+ 'A user may also invoke a skill directly; its <skill_content> block then appears in this conversation. Follow it, and do not call the `skill` tool again for that skill.',
71
+ '</system-reminder>',
72
+ ].join('\n')
73
+ }
74
+
75
+ /**
76
+ * 目录更新消息(后续轮次才会出现)。
77
+ *
78
+ * 之所以也要移植:如果会话运行中 skill 目录真的变了,DSH 会发更新帧;模板对条目的
79
+ * 覆盖必须在更新帧上继续成立,不能只在首包生效。
80
+ * @param {Array<{name: string, description: string}>} entries - 目录条目。
81
+ * @param {boolean} incomplete - 快照是否不完整。
82
+ * @returns {string} 消息正文。
83
+ */
84
+ export function renderCatalogUpdate(entries, incomplete) {
85
+ const availability = entries.length === 0
86
+ ? [
87
+ incomplete
88
+ ? 'No skills could be confirmed in this discovery attempt. Do not use names from earlier skill catalogs.'
89
+ : 'No skills are currently available through the `skill` tool. Do not use names from earlier skill catalogs.',
90
+ 'A user may still invoke a skill directly; its <skill_content> block then appears in this conversation. Follow it, and do not call the `skill` tool for it.',
91
+ ]
92
+ : [
93
+ 'Use only names in this replacement catalog. If the user names a listed skill, or the task clearly matches its description, call the `skill` tool with the exact name before acting.',
94
+ 'A user may also invoke a skill directly; its <skill_content> block then appears in this conversation. Follow it, and do not call the `skill` tool again for that skill.',
95
+ ]
96
+ return [
97
+ '<system-reminder>',
98
+ incomplete
99
+ ? 'Skill discovery is incomplete. This catalog of currently available skills replaces every earlier available-skills list in this session:'
100
+ : 'The available skill catalog changed. This complete catalog replaces every earlier available-skills list in this session:',
101
+ '',
102
+ '<available_skills>',
103
+ ...renderCatalogEntries(entries),
104
+ '</available_skills>',
105
+ '',
106
+ ...(incomplete ? [incompleteCatalogNotice(), ''] : []),
107
+ ...availability,
108
+ '</system-reminder>',
109
+ ].join('\n')
110
+ }
111
+
112
+ /**
113
+ * 按模板覆盖过滤/改写目录条目。
114
+ *
115
+ * 目录改写与「真实 pre-step 改写」共用这一份,避免两处对“隐藏哪些、用谁的描述”
116
+ * 给出不同答案。描述覆盖不截断:它是用户明确写下的最终文字。
117
+ * @param {Array<{name: string, description: string}>} entries - 原始条目。
118
+ * @param {object | undefined} overrides - `recipe.messages['skill-catalog']`。
119
+ * @returns {Array<{name: string, description: string}>} 过滤后的条目。
120
+ */
121
+ export function applyCatalogOverrides(entries, overrides) {
122
+ const hidden = new Set(Array.isArray(overrides?.hiddenEntries) ? overrides.hiddenEntries : [])
123
+ const descriptions = overrides?.descriptions ?? {}
124
+ const out = []
125
+ for (const entry of Array.isArray(entries) ? entries : []) {
126
+ if (typeof entry?.name !== 'string' || hidden.has(entry.name)) continue
127
+ const description = typeof descriptions[entry.name] === 'string'
128
+ ? descriptions[entry.name]
129
+ : entry.description
130
+ out.push({ ...entry, description: typeof description === 'string' ? description : '' })
131
+ }
132
+ return out
133
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 面向用户的能力分类。
3
+ *
4
+ * 分类依据是包的职责而不是命名:用户问「哪些插件给我加了工具」时,
5
+ * `dsh-tool-fs` 和 `dsh-mcp-client` 应该在同一个栏,尽管后者名字里没有 tool。
6
+ * 顺序有意义——先命中先返回,所以 `tool-` 规则必须排在 `client-*` 之前。
7
+ * @module dsh-plugin-console/host/categorize
8
+ */
9
+
10
+ /**
11
+ * 把插件归到一个面向用户的「能力类别」。
12
+ * @param {string} moduleName - 行的模块标识。
13
+ * @param {object} entry - 已采集的条目(用于看它注册了什么)。
14
+ * @returns {string} 类别 id。
15
+ */
16
+ export function categorize(moduleName, entry) {
17
+ const name = typeof moduleName === 'string' ? moduleName : ''
18
+ // 结构行与 MCP 客户端优先
19
+ if (name.startsWith('cordis:')) return 'structure'
20
+ if (/dsh-mcp-client|dsh-mcp-resources/.test(name)) return 'extend'
21
+ // 工具:名字里带 tool,或实际注册了工具且不是 MCP
22
+ if (/dsh-tool[-/]|\/tools$|-tools$/.test(name)) return 'tool'
23
+ // 界面
24
+ if (/client-ui/.test(name)) return 'ui'
25
+ // 模型
26
+ if (/dsh-llm/.test(name)) return 'model'
27
+ // 会话与持久化
28
+ if (/dsh-session|session-projection|session-query|session-format|session-persistence/.test(name)) return 'session'
29
+ // 安全
30
+ if (/sandbox|approval|permission-presets|fs-observation-policy|authorization|credentials/.test(name)) return 'safety'
31
+ // 传输与网关
32
+ if (/dsh-api-|api-gateway|typert|remote-access|dsh-acp|jsonrpc/.test(name)) return 'transport'
33
+ // 扩展能力
34
+ if (/dsh-skill|dsh-command|dsh-goal|plan-mode|compaction|dsh-subagent|workflow|dsh-ptc|dsh-web|repeat-tool|spill|token-meter|context-|persona|agent-instructions|system-prompt|attachment|file-reference|deliverable/.test(name)) return 'extend'
35
+ // 客户端内核
36
+ if (/dsh-client-|dsh-web-app|dsh-frontend|dsh-web-frontend/.test(name)) return 'client'
37
+ // 其余是宿主基础设施
38
+ if (/dsh-storage|dsh-subprocess|dsh-timer|cordis-plugin|dsh-hmr|dsh-otel|dsh-shell-env|dsh-config-editor|dsh-settings|dsh-workspace|dsh-home-paths|dsh-atomic|dsh-timeout|dsh-chunked|dsh-jobs|plugin-manager|plugin-inventory|package-inventory|dsh-brand|dsh-deepseek-account|dsh-agent|dsh-scope|dsh-tools/.test(name)) return 'infra'
39
+ return 'other'
40
+ }