dal-code 0.1.10 → 1.0.7

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 (166) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/dist/core/auth-guidance.d.ts +1 -0
  3. package/dist/core/auth-guidance.d.ts.map +1 -1
  4. package/dist/core/auth-guidance.js +6 -0
  5. package/dist/core/auth-guidance.js.map +1 -1
  6. package/dist/core/compaction/compaction.d.ts.map +1 -1
  7. package/dist/core/compaction/compaction.js +4 -7
  8. package/dist/core/compaction/compaction.js.map +1 -1
  9. package/dist/core/extensions/index.d.ts +1 -1
  10. package/dist/core/extensions/index.d.ts.map +1 -1
  11. package/dist/core/extensions/index.js.map +1 -1
  12. package/dist/core/extensions/loader.d.ts.map +1 -1
  13. package/dist/core/extensions/loader.js +13 -1
  14. package/dist/core/extensions/loader.js.map +1 -1
  15. package/dist/core/extensions/runner.d.ts.map +1 -1
  16. package/dist/core/extensions/runner.js +47 -48
  17. package/dist/core/extensions/runner.js.map +1 -1
  18. package/dist/core/extensions/types.d.ts +46 -43
  19. package/dist/core/extensions/types.d.ts.map +1 -1
  20. package/dist/core/extensions/types.js.map +1 -1
  21. package/dist/core/keybindings.d.ts +10 -0
  22. package/dist/core/keybindings.d.ts.map +1 -1
  23. package/dist/core/keybindings.js +13 -0
  24. package/dist/core/keybindings.js.map +1 -1
  25. package/dist/core/tools/bash.d.ts +3 -1
  26. package/dist/core/tools/bash.d.ts.map +1 -1
  27. package/dist/core/tools/bash.js +61 -8
  28. package/dist/core/tools/bash.js.map +1 -1
  29. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  30. package/dist/core/tools/renderers/bash.js +43 -6
  31. package/dist/core/tools/renderers/bash.js.map +1 -1
  32. package/dist/dal/builtins.d.ts.map +1 -1
  33. package/dist/dal/builtins.js +1 -0
  34. package/dist/dal/builtins.js.map +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/main.d.ts.map +1 -1
  39. package/dist/main.js +6 -0
  40. package/dist/main.js.map +1 -1
  41. package/dist/modes/interactive/components/assistant-message.d.ts +12 -0
  42. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  43. package/dist/modes/interactive/components/assistant-message.js +22 -1
  44. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  45. package/dist/modes/interactive/components/footer.d.ts +2 -0
  46. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  47. package/dist/modes/interactive/components/footer.js +24 -7
  48. package/dist/modes/interactive/components/footer.js.map +1 -1
  49. package/dist/modes/interactive/components/tool-execution.d.ts +39 -2
  50. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  51. package/dist/modes/interactive/components/tool-execution.js +200 -29
  52. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  53. package/dist/modes/interactive/interactive-mode.d.ts +35 -0
  54. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  55. package/dist/modes/interactive/interactive-mode.js +177 -23
  56. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  57. package/dist/modes/interactive/theme/dark.json +1 -1
  58. package/dist/modes/interactive/theme/light.json +1 -1
  59. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  60. package/dist/modes/interactive/tui-renderer.js +2 -2
  61. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  62. package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
  63. package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
  64. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
  65. package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
  66. package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
  67. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  68. package/dist/node_modules/@dalcode/dal-mcp/package.json +9 -6
  69. package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.ts +142 -0
  70. package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.ts +218 -0
  71. package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.ts +99 -0
  72. package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +161 -18
  73. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.ts +8 -3
  74. package/dist/node_modules/@dalcode/dal-office/LICENSE +21 -0
  75. package/dist/node_modules/@dalcode/dal-office/package.json +37 -0
  76. package/dist/node_modules/@dalcode/dal-office/src/extract/csv.ts +84 -0
  77. package/dist/node_modules/@dalcode/dal-office/src/extract/index.ts +111 -0
  78. package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.ts +109 -0
  79. package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.ts +43 -0
  80. package/dist/node_modules/@dalcode/dal-office/src/index.ts +43 -0
  81. package/dist/node_modules/@dalcode/dal-office/src/paths.ts +107 -0
  82. package/dist/node_modules/@dalcode/dal-office/src/render/chart.ts +111 -0
  83. package/dist/node_modules/@dalcode/dal-office/src/render/docx.ts +155 -0
  84. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.ts +386 -0
  85. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.ts +99 -0
  86. package/dist/node_modules/@dalcode/dal-office/src/scenes.ts +197 -0
  87. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.ts +49 -0
  88. package/dist/node_modules/@dalcode/dal-office/src/themes.ts +240 -0
  89. package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.ts +122 -0
  90. package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.ts +123 -0
  91. package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.ts +99 -0
  92. package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.ts +76 -0
  93. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.ts +106 -0
  94. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.ts +91 -0
  95. package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.ts +71 -0
  96. package/dist/node_modules/@dalcode/dal-office/src/tools/shared.ts +54 -0
  97. package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.ts +101 -0
  98. package/dist/node_modules/@dalcode/dal-office/src/truncate.ts +27 -0
  99. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
  100. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +237 -0
  101. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
  102. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  103. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +326 -0
  104. package/dist/node_modules/@dalcode/dal-skills/package.json +6 -5
  105. package/dist/node_modules/@dalcode/dal-skills/src/discover.ts +101 -0
  106. package/dist/node_modules/@dalcode/dal-skills/src/index.ts +100 -1
  107. package/dist/node_modules/@dalcode/dal-skills/src/install.ts +140 -0
  108. package/dist/node_modules/@dalcode/dal-skills/src/manage.ts +446 -0
  109. package/dist/node_modules/@dalcode/dal-skills/src/packages.ts +130 -0
  110. package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
  111. package/dist/node_modules/@dalcode/dal-subagent/src/index.ts +46 -4
  112. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  113. package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
  114. package/dist/node_modules/@dalcode/deepailab/src/index.ts +7 -1
  115. package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +42 -6
  116. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  117. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  118. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  119. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  120. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  121. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  122. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  123. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  124. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  125. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  126. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  127. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  128. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  129. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  130. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  131. package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
  132. package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
  133. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  134. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
  135. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +3 -1
  136. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
  137. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
  138. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +3 -1
  139. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
  140. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
  141. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +23 -22
  142. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
  143. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +4 -3
  144. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
  145. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -2
  146. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
  147. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  148. package/dist/utils/changelog.d.ts +37 -4
  149. package/dist/utils/changelog.d.ts.map +1 -1
  150. package/dist/utils/changelog.js +80 -17
  151. package/dist/utils/changelog.js.map +1 -1
  152. package/dist/utils/clipboard.d.ts.map +1 -1
  153. package/dist/utils/clipboard.js +13 -1
  154. package/dist/utils/clipboard.js.map +1 -1
  155. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  156. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  157. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  158. package/examples/extensions/gondolin/package-lock.json +2 -2
  159. package/examples/extensions/gondolin/package.json +1 -1
  160. package/examples/extensions/sandbox/package-lock.json +2 -2
  161. package/examples/extensions/sandbox/package.json +1 -1
  162. package/examples/extensions/with-deps/package-lock.json +2 -2
  163. package/examples/extensions/with-deps/package.json +1 -1
  164. package/examples/plugins/pi-example-plugin/package.json +1 -1
  165. package/npm-shrinkwrap.json +1489 -3
  166. package/package.json +8 -2
@@ -0,0 +1,446 @@
1
+ /**
2
+ * /skill — manage the local skills the host already loads from disk.
3
+ *
4
+ * Claude Code has no add command (mkdir by hand) and codex answers it with a
5
+ * $skill-creator skill; dal ships the whole flow as one command. The
6
+ * distinctive piece is drafting: a skill is just a prompt wearing a filename,
7
+ * so the wizard hands the description to the current model, the model returns
8
+ * a SKILL.md, and the user edits that draft in the multi-line editor before
9
+ * anything is written — AI writes, the human decides.
10
+ *
11
+ * Writing goes through ctx.reload() afterwards so the new skill is callable
12
+ * as /skill:<name> without restarting the session.
13
+ */
14
+
15
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import { t } from "@dalcode/dal-pi-kit";
18
+ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
19
+ import {
20
+ assertValidSkillName,
21
+ type LocalSkill,
22
+ listLocalSkills,
23
+ parseSkillFile,
24
+ type SkillScope,
25
+ skillRoots,
26
+ } from "./discover.ts";
27
+
28
+ const ADD_USAGE = t("用法:/skill add <name> -- <这个技能做什么、何时触发>(AI 起草),或 /skill add(交互式向导)");
29
+ const REMOVE_USAGE = t("用法:/skill remove <name> [--scope user|project|shared]");
30
+ const MAIN_USAGE = t(
31
+ "用法:/skill list | /skill show <name> | /skill add | /skill remove <name>。/skills 查看云端技能。",
32
+ );
33
+
34
+ /** hasUI, not `ui`: a headless run's notify does nothing, and /skill add's
35
+ * outcome (which file, did the AI draft fail) matters most exactly there. */
36
+ function report(ctx: ExtensionCommandContext, message: string, level: "info" | "warning" | "error"): void {
37
+ if (ctx.hasUI) ctx.ui.notify(message, level);
38
+ else process.stderr.write(`${message}\n`);
39
+ }
40
+
41
+ function errorMessage(error: unknown): string {
42
+ return error instanceof Error ? error.message : String(error);
43
+ }
44
+
45
+ function findSkill(cwd: string, name: string, includeProject: boolean): LocalSkill | undefined {
46
+ return listLocalSkills(cwd, { includeProject }).find((skill) => skill.name === name);
47
+ }
48
+
49
+ // ---------------------------------------------------------------------------
50
+ // AI drafting
51
+ // ---------------------------------------------------------------------------
52
+
53
+ function draftPrompt(name: string, purpose: string): string {
54
+ return [
55
+ "你是 SKILL.md(AI 技能文件)编写助手。请把下面的描述整理成一个规范的技能文件。",
56
+ "要求:",
57
+ `1. 第一行是 ---,随后是 YAML frontmatter:name 字段固定为 "${name}";description 字段用一两句话说明这个技能做什么、何时触发(不超过 1024 字符);然后单独一行 --- 结束 frontmatter。`,
58
+ "2. 正文是给 AI 助手看的执行指令:分步骤、具体可执行、没有废话;描述里的可复用提示词、清单或流程,整理为清晰的段落或列表。",
59
+ "3. 正文保持精炼(尽量 200 行以内);除 frontmatter 与正文外不要输出任何解释或代码围栏。",
60
+ "4. 使用描述所用的语言撰写。",
61
+ "",
62
+ "技能描述:",
63
+ purpose,
64
+ ].join("\n");
65
+ }
66
+
67
+ /** One synchronous model call, like the summarize extension. Shows the
68
+ * working indicator while it runs (drafting takes many seconds); throws with
69
+ * a user-facing message when there is no model or no auth. */
70
+ async function draftSkill(ctx: ExtensionCommandContext, name: string, purpose: string): Promise<string> {
71
+ const model = ctx.model;
72
+ if (!model) throw new Error(t("没有可用的当前模型,无法 AI 起草;请改为手写技能内容。"));
73
+ if (ctx.modelRegistry?.hasConfiguredAuth && !ctx.modelRegistry.hasConfiguredAuth(model)) {
74
+ throw new Error(t("当前模型未配置鉴权,无法 AI 起草;请改为手写技能内容。"));
75
+ }
76
+ // Stubs in tests may not carry these — optional calls keep them safe.
77
+ ctx.ui.setWorkingVisible?.(true);
78
+ ctx.ui.setWorkingMessage?.(t("AI 正在起草技能,请稍候…"));
79
+ try {
80
+ const response = await ctx.modelRegistry.complete(model, {
81
+ messages: [
82
+ {
83
+ role: "user" as const,
84
+ content: [{ type: "text" as const, text: draftPrompt(name, purpose) }],
85
+ timestamp: Date.now(),
86
+ },
87
+ ],
88
+ });
89
+ const text = response.content
90
+ .filter((c): c is { type: "text"; text: string } => c.type === "text")
91
+ .map((c) => c.text)
92
+ .join("\n")
93
+ .trim();
94
+ if (!text) throw new Error(t("模型没有返回内容,请重试或手写技能内容。"));
95
+ return text;
96
+ } finally {
97
+ ctx.ui.setWorkingVisible?.(false);
98
+ ctx.ui.setWorkingMessage?.(undefined);
99
+ }
100
+ }
101
+
102
+ function blankTemplate(name: string): string {
103
+ return `---\nname: ${name}\ndescription: \n---\n\n${t("<!-- 在这里写技能正文:给 AI 的分步指令 -->")}\n`;
104
+ }
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Writing
108
+ // ---------------------------------------------------------------------------
109
+
110
+ function resolveScopeDir(scope: SkillScope, cwd: string): string {
111
+ return skillRoots(cwd).find((root) => root.scope === scope)?.dir ?? join(cwd, ".dal", "skills");
112
+ }
113
+
114
+ /** Validates the draft, aligns frontmatter name with the directory name, writes SKILL.md. */
115
+ function writeSkill(ctx: ExtensionCommandContext, name: string, scope: SkillScope, content: string): string {
116
+ const parsed = parseSkillFile(content);
117
+ if (!parsed.description?.trim()) {
118
+ throw new Error(t("技能缺少 description(frontmatter 字段),请补充一句“做什么、何时触发”后重试。"));
119
+ }
120
+ let normalized = content;
121
+ if (parsed.name !== undefined && parsed.name !== name) {
122
+ // The directory name is the command name; a stale frontmatter name would
123
+ // silently disagree with it. Rewrite the first name line to match.
124
+ normalized = normalized.replace(/^---\nname:[^\n]*/i, `---\nname: ${name}`);
125
+ }
126
+ const dir = join(resolveScopeDir(scope, ctx.cwd), name);
127
+ if (existsSync(dir)) {
128
+ throw new Error(`${t("该技能已存在于 ")}${dir}${t("。先 /skill remove,或直接编辑该目录。")}`);
129
+ }
130
+ mkdirSync(dir, { recursive: true });
131
+ writeFileSync(join(dir, "SKILL.md"), normalized.endsWith("\n") ? normalized : `${normalized}\n`, "utf-8");
132
+ return dir;
133
+ }
134
+
135
+ async function reload(ctx: ExtensionCommandContext): Promise<void> {
136
+ try {
137
+ await ctx.reload?.();
138
+ } catch {
139
+ // Reload is best-effort: the files are on disk; a restart picks them up.
140
+ }
141
+ }
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // Subcommands
145
+ // ---------------------------------------------------------------------------
146
+
147
+ function runSkillList(ctx: ExtensionCommandContext): void {
148
+ const skills = listLocalSkills(ctx.cwd, { includeProject: ctx.isProjectTrusted() });
149
+ if (skills.length === 0) {
150
+ report(ctx, t("未发现本地技能。用 /skill add 创建,或把 <name>/SKILL.md 目录放进 ~/.dal/agent/skills。"), "info");
151
+ return;
152
+ }
153
+ const lines = skills.map((skill) => ` ${skill.name} [${skill.scope}] — ${skill.description}`);
154
+ report(ctx, `${t("本地技能")} (${skills.length})\n${lines.join("\n")}`, "info");
155
+ }
156
+
157
+ function runSkillShow(name: string, ctx: ExtensionCommandContext): void {
158
+ if (!name) {
159
+ report(ctx, t("用法:/skill show <name>"), "info");
160
+ return;
161
+ }
162
+ const skill = findSkill(ctx.cwd, name, ctx.isProjectTrusted());
163
+ if (!skill) {
164
+ report(ctx, `${t("未找到本地技能:")}${name}`, "warning");
165
+ return;
166
+ }
167
+ try {
168
+ report(ctx, readFileSync(skill.path, "utf8").trimEnd(), "info");
169
+ } catch (error) {
170
+ report(ctx, `${t("读取技能失败:")}${errorMessage(error)}`, "error");
171
+ }
172
+ }
173
+
174
+ const AI_DRAFT = t("AI 起草/整理(推荐)");
175
+ const HAND_WRITE = t("我自己手写(空白模板)");
176
+ const USER_SCOPE_LABEL = t("用户级(~/.dal/agent/skills,本机所有项目可用)");
177
+ const PROJECT_SCOPE_LABEL = t("项目级(.dal/skills,仅当前项目,需已信任)");
178
+
179
+ async function runSkillAdd(tokens: string[], ctx: ExtensionCommandContext): Promise<void> {
180
+ let parsedName: string | undefined;
181
+ let scope: SkillScope = "user";
182
+ let purpose: string | undefined;
183
+ let interactive = false;
184
+
185
+ // Head = everything before the standalone `--`; the tail after it is the
186
+ // purpose, kept verbatim (never re-joined with collapsed whitespace).
187
+ const dash = tokens.indexOf("--");
188
+ const head = dash === -1 ? tokens : tokens.slice(0, dash);
189
+ const tail = dash === -1 ? undefined : tokens.slice(dash + 1);
190
+
191
+ for (let i = 0; i < head.length; i++) {
192
+ const token = head[i];
193
+ if (token === "--scope" || token.startsWith("--scope=")) {
194
+ const value = token.startsWith("--scope=") ? token.slice("--scope=".length) : head[++i];
195
+ if (value !== "user" && value !== "project") {
196
+ report(ctx, `${t("--scope 仅支持 user 或 project:")}${value ?? ""}\n${ADD_USAGE}`, "info");
197
+ return;
198
+ }
199
+ scope = value;
200
+ continue;
201
+ }
202
+ if (token.startsWith("--")) {
203
+ report(ctx, `${t("未知参数:")}${token}\n${ADD_USAGE}`, "info");
204
+ return;
205
+ }
206
+ if (parsedName !== undefined) {
207
+ report(ctx, ADD_USAGE, "info");
208
+ return;
209
+ }
210
+ parsedName = token;
211
+ }
212
+
213
+ if (parsedName === undefined) {
214
+ interactive = true;
215
+ if (!ctx.hasUI) {
216
+ report(ctx, ADD_USAGE, "info");
217
+ return;
218
+ }
219
+ } else {
220
+ const candidate: string = parsedName;
221
+ if (tail === undefined || tail.length === 0) {
222
+ report(ctx, ADD_USAGE, "info");
223
+ return;
224
+ }
225
+ purpose = tail.join(" ").trim();
226
+ if (!purpose) {
227
+ report(ctx, ADD_USAGE, "info");
228
+ return;
229
+ }
230
+ try {
231
+ assertValidSkillName(candidate);
232
+ } catch (error) {
233
+ report(ctx, errorMessage(error), "error");
234
+ return;
235
+ }
236
+ }
237
+
238
+ const ui = ctx.ui;
239
+ let name = "";
240
+ if (interactive) {
241
+ const asked = await ui.input(t("技能名称(仅小写字母、数字、-):"));
242
+ if (asked === undefined) return;
243
+ const picked = asked.trim();
244
+ try {
245
+ assertValidSkillName(picked);
246
+ } catch (error) {
247
+ report(ctx, errorMessage(error), "error");
248
+ return;
249
+ }
250
+ name = picked;
251
+ } else {
252
+ // Non-interactive implies parsedName was found above.
253
+ name = parsedName ?? "";
254
+ }
255
+
256
+ // The purpose doubles as the AI's raw material: pasting an existing messy
257
+ // prompt here is the "AI tidies it up" path, not just fresh drafting.
258
+ let purposeText = purpose ?? "";
259
+ if (interactive) {
260
+ const described = await ui.editor(
261
+ t("描述这个技能:要做什么、何时触发、关键步骤(可粘贴现有提示词,交给 AI 整理)"),
262
+ );
263
+ if (described === undefined) return;
264
+ purposeText = described.trim();
265
+ }
266
+
267
+ let content: string;
268
+ if (interactive) {
269
+ const how = await ui.select(t("技能内容:"), [AI_DRAFT, HAND_WRITE]);
270
+ if (how === undefined) return;
271
+ if (how === HAND_WRITE) {
272
+ content = blankTemplate(name);
273
+ } else if (purposeText) {
274
+ // AI failed → fall through to the blank template rather than aborting:
275
+ // the wizard already collected a name and a purpose, and the user can
276
+ // still write by hand from here.
277
+ try {
278
+ content = await draftSkill(ctx, name, purposeText);
279
+ } catch (error) {
280
+ report(ctx, `${t("AI 起草失败:")}${errorMessage(error)}${t("已改为空白模板。")}`, "warning");
281
+ content = blankTemplate(name);
282
+ }
283
+ } else {
284
+ // Nothing to tidy up — drafting from an empty description makes no sense.
285
+ content = blankTemplate(name);
286
+ }
287
+ const drafted = await ui.editor(t("确认/修改技能内容(提交保存,Esc 取消)"), content);
288
+ if (drafted === undefined) return;
289
+ content = drafted;
290
+ } else {
291
+ try {
292
+ content = await draftSkill(ctx, name, purposeText);
293
+ } catch (error) {
294
+ report(ctx, `${t("AI 起草失败:")}${errorMessage(error)}`, "error");
295
+ return;
296
+ }
297
+ }
298
+
299
+ if (interactive) {
300
+ const picked = await ui.select(t("保存位置:"), [USER_SCOPE_LABEL, PROJECT_SCOPE_LABEL]);
301
+ if (picked === undefined) return;
302
+ scope = picked === PROJECT_SCOPE_LABEL ? "project" : "user";
303
+ }
304
+ if (scope === "project" && !ctx.isProjectTrusted()) {
305
+ report(ctx, t("项目未受信任,无法写入项目级 .dal/skills。先运行 /trust 保存信任决策,再重试。"), "warning");
306
+ return;
307
+ }
308
+
309
+ let dir: string;
310
+ try {
311
+ dir = writeSkill(ctx, name, scope, content);
312
+ } catch (error) {
313
+ report(ctx, errorMessage(error), "error");
314
+ return;
315
+ }
316
+ // Report BEFORE reload: the old ctx goes stale the moment reload() runs,
317
+ // and anything it touches afterwards throws.
318
+ report(
319
+ ctx,
320
+ `${t("已创建技能:")}${name}${t("(")}${scope}${t(")")}\n${dir}\n${t("已保存,正在重载技能;调用方式:")}/skill:${name}`,
321
+ "info",
322
+ );
323
+ await reload(ctx);
324
+ }
325
+
326
+ async function runSkillRemove(tokens: string[], ctx: ExtensionCommandContext): Promise<void> {
327
+ let scope: SkillScope | undefined;
328
+ const positional: string[] = [];
329
+ for (let i = 0; i < tokens.length; i++) {
330
+ const token = tokens[i];
331
+ if (token === "--scope") {
332
+ i += 1;
333
+ const value = tokens[i];
334
+ if (value !== "user" && value !== "project" && value !== "shared") {
335
+ report(ctx, `${t("--scope 仅支持 user、project 或 shared:")}${value ?? ""}`, "info");
336
+ return;
337
+ }
338
+ scope = value;
339
+ continue;
340
+ }
341
+ if (token.startsWith("--")) {
342
+ report(ctx, `${t("未知参数:")}${token}\n${REMOVE_USAGE}`, "info");
343
+ return;
344
+ }
345
+ positional.push(token);
346
+ }
347
+ const name = positional[0];
348
+ if (!name || positional.length > 1) {
349
+ // No name given: pick one interactively from what is actually on disk —
350
+ // listing by hand from /skill list and retyping the name is busywork.
351
+ if (!ctx.hasUI) {
352
+ report(ctx, REMOVE_USAGE, "info");
353
+ return;
354
+ }
355
+ const skills = listLocalSkills(ctx.cwd, { includeProject: ctx.isProjectTrusted() }).filter(
356
+ (skill) => !scope || skill.scope === scope,
357
+ );
358
+ if (skills.length === 0) {
359
+ report(
360
+ ctx,
361
+ t("未发现本地技能。用 /skill add 创建,或把 <name>/SKILL.md 目录放进 ~/.dal/agent/skills。"),
362
+ "info",
363
+ );
364
+ return;
365
+ }
366
+ const options = skills.map((skill) => `${skill.name} [${skill.scope}] — ${skill.description}`);
367
+ const picked = await ctx.ui.select(t("要删除的技能:"), options);
368
+ if (picked === undefined) return;
369
+ const skill = skills[options.indexOf(picked)];
370
+ if (!skill) return;
371
+ const confirmed = await ctx.ui.confirm(
372
+ t("确认删除该技能?"),
373
+ `${skill.name} [${skill.scope}]\n${skill.dir}\n${t("删除后不可恢复。")}`,
374
+ );
375
+ if (!confirmed) return;
376
+ rmSync(skill.dir, { recursive: true, force: true });
377
+ // Report BEFORE reload — the ctx is stale afterwards.
378
+ report(
379
+ ctx,
380
+ `${t("已删除技能:")}${skill.name}${t("(")}${skill.scope}${t(")")}
381
+ ${skill.dir}
382
+ ${t("(已保存,正在重载)")}`,
383
+ "info",
384
+ );
385
+ await reload(ctx);
386
+ return;
387
+ }
388
+ if (positional.length > 1) {
389
+ report(ctx, REMOVE_USAGE, "info");
390
+ return;
391
+ }
392
+ try {
393
+ assertValidSkillName(name);
394
+ } catch (error) {
395
+ report(ctx, errorMessage(error), "error");
396
+ return;
397
+ }
398
+ const order: SkillScope[] = scope ? [scope] : ["project", "user", "shared"];
399
+ for (const candidate of order) {
400
+ if (candidate === "project" && !ctx.isProjectTrusted()) continue;
401
+ const dir = join(resolveScopeDir(candidate, ctx.cwd), name);
402
+ if (!existsSync(join(dir, "SKILL.md"))) continue;
403
+ rmSync(dir, { recursive: true, force: true });
404
+ // Report BEFORE reload — the ctx is stale afterwards.
405
+ report(
406
+ ctx,
407
+ `${t("已删除技能:")}${name}${t("(")}${candidate}${t(")")}
408
+ ${dir}
409
+ ${t("(已保存,正在重载)")}`,
410
+ "info",
411
+ );
412
+ await reload(ctx);
413
+ return;
414
+ }
415
+ report(ctx, `${t("未找到本地技能:")}${name}`, "warning");
416
+ }
417
+
418
+ /** Entry point registered as the /skill command. */
419
+ export async function runSkillCommand(args: string, ctx: ExtensionCommandContext): Promise<void> {
420
+ const trimmed = args.trim();
421
+ if (!trimmed || trimmed === "list") {
422
+ runSkillList(ctx);
423
+ return;
424
+ }
425
+ const space = trimmed.indexOf(" ");
426
+ const sub = space === -1 ? trimmed : trimmed.slice(0, space);
427
+ const rest = space === -1 ? "" : trimmed.slice(space + 1).trim();
428
+ const restTokens = rest.split(/\s+/).filter(Boolean);
429
+ switch (sub) {
430
+ case "list":
431
+ runSkillList(ctx);
432
+ return;
433
+ case "show":
434
+ runSkillShow(rest, ctx);
435
+ return;
436
+ case "add":
437
+ // runSkillAdd splits head flags from the verbatim purpose after `--`.
438
+ await runSkillAdd(restTokens, ctx);
439
+ return;
440
+ case "remove":
441
+ await runSkillRemove(restTokens, ctx);
442
+ return;
443
+ default:
444
+ report(ctx, MAIN_USAGE, "info");
445
+ }
446
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Extensions recommended on the user's DeepAILab account.
3
+ *
4
+ * Deliberately a list and not an installation. A hosted MCP server can be
5
+ * pushed safely because the worst it does is answer requests; an extension is
6
+ * code that runs on the user's machine with their permissions, and there is no
7
+ * equivalent restriction that makes pushing one safe. So the account remembers
8
+ * what someone chose, every machine they sign in from is told about it, and the
9
+ * install itself stays a deliberate command they type.
10
+ *
11
+ * That also means this file never shells out. It reads a list and compares.
12
+ */
13
+
14
+ import { readFileSync, writeFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+
17
+ const NAG_FILE = "install-nag.json";
18
+
19
+ export interface AccountPackage {
20
+ readonly source: string;
21
+ readonly name: string;
22
+ readonly description: string;
23
+ }
24
+
25
+ /** Bounded: this runs at session start, before the first turn. */
26
+ const TIMEOUT_MS = 8_000;
27
+
28
+ /** Sources we are willing to repeat back. Anything else is a misconfiguration. */
29
+ function isPublishableSource(source: string): boolean {
30
+ return source.startsWith("npm:") || source.startsWith("git:") || source.startsWith("https://");
31
+ }
32
+
33
+ export async function fetchAccountPackages(apiBase: string, vk: string): Promise<readonly AccountPackage[]> {
34
+ const controller = new AbortController();
35
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
36
+ try {
37
+ const res = await fetch(`${apiBase}/portal/packages`, {
38
+ headers: { "x-bf-vk": vk, Accept: "application/json" },
39
+ signal: controller.signal,
40
+ });
41
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
42
+ const body = (await res.json()) as { packages?: Array<Partial<AccountPackage>> };
43
+ return (body.packages ?? [])
44
+ .filter(
45
+ (p): p is AccountPackage =>
46
+ typeof p?.source === "string" && p.source.length > 0 && isPublishableSource(p.source),
47
+ )
48
+ .map((p) => ({
49
+ source: p.source,
50
+ name: typeof p.name === "string" && p.name ? p.name : p.source,
51
+ description: typeof p.description === "string" ? p.description : "",
52
+ }));
53
+ } finally {
54
+ clearTimeout(timer);
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Which of the account's packages this machine does not have yet.
60
+ *
61
+ * Installed sources arrive in the shapes settings.json allows — a bare string,
62
+ * or an object with `source` — so both are normalised before comparing.
63
+ */
64
+ /**
65
+ * Package sources this machine already has.
66
+ *
67
+ * Read from settings.json directly: ExtensionContext exposes no settings
68
+ * accessor, and this only needs one array. A missing or malformed file means
69
+ * "nothing installed", which at worst shows a recommendation the user already
70
+ * has — the failure mode of guessing the other way is staying silent forever.
71
+ */
72
+ export function readInstalledSources(agentDir: string): readonly (string | { source?: string })[] {
73
+ try {
74
+ const parsed = JSON.parse(readFileSync(join(agentDir, "settings.json"), "utf8")) as {
75
+ packages?: (string | { source?: string })[];
76
+ };
77
+ return Array.isArray(parsed.packages) ? parsed.packages : [];
78
+ } catch {
79
+ return [];
80
+ }
81
+ }
82
+
83
+ export function missingPackages(
84
+ account: readonly AccountPackage[],
85
+ installed: readonly (string | { source?: string })[],
86
+ ): readonly AccountPackage[] {
87
+ const have = new Set(
88
+ installed
89
+ .map((entry) => (typeof entry === "string" ? entry : entry?.source))
90
+ .filter((s): s is string => typeof s === "string")
91
+ .map((s) => s.trim().toLowerCase()),
92
+ );
93
+ return account.filter((p) => !have.has(p.source.trim().toLowerCase()));
94
+ }
95
+
96
+ /**
97
+ * Whether a pending set is worth interrupting the user over.
98
+ *
99
+ * The recommendation is real, but it is not urgent, and repeating it at every
100
+ * single session start is how a useful notice becomes noise that people learn
101
+ * to read past. So it speaks once per *distinct* set: install one of them, or
102
+ * have a new one appear on the account, and the set changes and it speaks
103
+ * again. Nothing else resets it.
104
+ *
105
+ * Side-effecting on purpose — the record has to be written for the caller's
106
+ * `true` to mean "and now it is spoken for".
107
+ */
108
+ export function shouldAnnouncePending(agentDir: string, pending: readonly AccountPackage[]): boolean {
109
+ const fingerprint = pending
110
+ .map((p) => p.source.trim().toLowerCase())
111
+ .sort()
112
+ .join("\n");
113
+ if (fingerprint === "") return false;
114
+
115
+ const path = join(agentDir, NAG_FILE);
116
+ try {
117
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as { announced?: string };
118
+ if (parsed.announced === fingerprint) return false;
119
+ } catch {
120
+ // No record yet, or one we cannot read. Announcing is the safe side: being
121
+ // told twice is a nuisance, never being told wastes what the user bought.
122
+ }
123
+
124
+ try {
125
+ writeFileSync(path, `${JSON.stringify({ announced: fingerprint }, null, 2)}\n`);
126
+ } catch {
127
+ // Non-fatal. Worst case the notice repeats next session.
128
+ }
129
+ return true;
130
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-subagent",
3
- "version": "0.1.10",
3
+ "version": "1.0.7",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -17,14 +17,14 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "0.1.10",
21
- "@dalcode/dal-guard": "0.1.10",
22
- "@earendil-works/pi-agent-core": "^0.1.2",
23
- "@earendil-works/pi-ai": "^0.1.2",
20
+ "@dalcode/dal-pi-kit": "1.0.7",
21
+ "@dalcode/dal-guard": "1.0.7",
22
+ "@earendil-works/pi-agent-core": "^1.0.7",
23
+ "@earendil-works/pi-ai": "^1.0.7",
24
24
  "typebox": "1.3.7"
25
25
  },
26
26
  "peerDependencies": {
27
- "@earendil-works/pi-coding-agent": "^0.1.2"
27
+ "@earendil-works/pi-coding-agent": "^1.0.0"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "@earendil-works/pi-coding-agent": {
@@ -99,12 +99,34 @@ function filePathFromInput(input: Record<string, unknown>): string | undefined {
99
99
  return undefined;
100
100
  }
101
101
 
102
+ /** The shortest honest label for one sub-agent step: the tool, plus its target when there is one. */
103
+ function describeSubagentStep(toolName: string, params: unknown): string {
104
+ const hint = filePathFromInput(params as Record<string, unknown>);
105
+ if (hint) return `${toolName} ${hint.split("/").slice(-2).join("/")}`;
106
+ const record = (params ?? {}) as Record<string, unknown>;
107
+ for (const key of ["command", "pattern", "query"]) {
108
+ const value = record[key];
109
+ if (typeof value === "string" && value.trim()) {
110
+ const compact = value.replace(/\s+/g, " ").trim();
111
+ return `${toolName} ${compact.length > 40 ? `${compact.slice(0, 39)}…` : compact}`;
112
+ }
113
+ }
114
+ return toolName;
115
+ }
116
+
102
117
  /** Wraps each tool's execute so it goes through dal-guard's approval decision first, with hasUI forced false. */
103
- export function buildSubagentTools(cwd: string, readOnly: boolean, changedFiles?: string[]): AgentTool<any>[] {
118
+ export function buildSubagentTools(
119
+ cwd: string,
120
+ readOnly: boolean,
121
+ changedFiles?: string[],
122
+ /** Called as the sub-agent starts each tool, so the parent can show progress. */
123
+ onToolStart?: (toolName: string, params: unknown) => void,
124
+ ): AgentTool<any>[] {
104
125
  const tools = readOnly ? createReadOnlyTools(cwd) : createCodingTools(cwd);
105
126
  return tools.map((tool) => ({
106
127
  ...tool,
107
128
  execute: async (toolCallId, params, signal, onUpdate) => {
129
+ onToolStart?.(tool.name, params);
108
130
  const event = {
109
131
  type: "tool_call",
110
132
  toolCallId,
@@ -141,9 +163,23 @@ export function buildSubagentSystemPrompt(): string {
141
163
  );
142
164
  }
143
165
 
166
+ /**
167
+ * A line describing what the sub-agent is doing right now.
168
+ *
169
+ * Without this the parent shows nothing at all between dispatch and the final
170
+ * answer — four sub-agents could run for minutes behind a blank screen, which
171
+ * reads as the product having hung rather than as work in progress. The
172
+ * onUpdate callback was handed to the task tool from the start and ignored.
173
+ */
174
+ function progressLine(description: string, steps: number, current: string | undefined): string {
175
+ const suffix = current ? ` · ${current}` : "";
176
+ return `${description} — ${steps} ${t("步")}${suffix}`;
177
+ }
178
+
144
179
  async function runSubagent(
145
180
  input: TaskToolInput,
146
181
  ctx: ExtensionContext,
182
+ onProgress?: (text: string) => void,
147
183
  ): Promise<{ text: string; changedFiles: string[] }> {
148
184
  const model = ctx.model;
149
185
  if (!model) {
@@ -153,7 +189,11 @@ async function runSubagent(
153
189
  const release = await subagentSemaphore.acquire();
154
190
  const changedFiles: string[] = [];
155
191
  try {
156
- const tools = buildSubagentTools(ctx.cwd, input.readOnly === true, changedFiles);
192
+ let steps = 0;
193
+ const tools = buildSubagentTools(ctx.cwd, input.readOnly === true, changedFiles, (toolName, params) => {
194
+ steps += 1;
195
+ onProgress?.(progressLine(input.description, steps, describeSubagentStep(toolName, params)));
196
+ });
157
197
  const subagent = new Agent({
158
198
  initialState: {
159
199
  systemPrompt: buildSubagentSystemPrompt(),
@@ -204,8 +244,10 @@ export default function (pi: ExtensionAPI) {
204
244
  promptSnippet: t("task - 派发子 agent 并行处理独立子任务"),
205
245
  parameters: taskSchema,
206
246
  executionMode: "parallel",
207
- execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
208
- const { text, changedFiles } = await runSubagent(params, ctx);
247
+ execute: async (_toolCallId, params, _signal, onUpdate, ctx) => {
248
+ const { text, changedFiles } = await runSubagent(params, ctx, (progress) => {
249
+ onUpdate?.({ content: [{ type: "text", text: progress }], details: { description: params.description } });
250
+ });
209
251
  return {
210
252
  content: [{ type: "text", text }],
211
253
  details: {