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
@@ -26,9 +26,24 @@
26
26
 
27
27
  import { t } from "@dalcode/dal-pi-kit";
28
28
  import { defaultConfig } from "@dalcode/deepailab/oidc";
29
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
29
+ import {
30
+ type ExtensionAPI,
31
+ type ExtensionCommandContext,
32
+ type ExtensionContext,
33
+ getAgentDir,
34
+ } from "@earendil-works/pi-coding-agent";
30
35
  import { Type } from "typebox";
31
36
  import { fetchSkillBody, fetchSkillIndex, type SkillSummary } from "./client.ts";
37
+ import { listLocalSkills } from "./discover.ts";
38
+ import { runInstallCommand } from "./install.ts";
39
+ import { runSkillCommand } from "./manage.ts";
40
+ import {
41
+ type AccountPackage,
42
+ fetchAccountPackages,
43
+ missingPackages,
44
+ readInstalledSources,
45
+ shouldAnnouncePending,
46
+ } from "./packages.ts";
32
47
 
33
48
  const skillSchema = Type.Object({
34
49
  name: Type.String({ description: t("要加载的技能名称,取自本工具描述中列出的清单") }),
@@ -110,6 +125,23 @@ export default function (pi: ExtensionAPI) {
110
125
  return;
111
126
  }
112
127
 
128
+ // Best-effort and quiet on failure: a recommendation list that cannot be
129
+ // fetched is not worth interrupting anyone over, unlike skills or MCP which
130
+ // change what the agent can do.
131
+ try {
132
+ const account = await fetchAccountPackages(cfg.apiBase, vk);
133
+ const installed = readInstalledSources(getAgentDir());
134
+ pendingPackages = missingPackages(account, installed);
135
+ if (ctx.hasUI && shouldAnnouncePending(getAgentDir(), pendingPackages)) {
136
+ ctx.ui.notify(
137
+ `${t("账号里有")}${pendingPackages.length}${t(" 个扩展本机还没装,/install 可直接安装。")}`,
138
+ "info",
139
+ );
140
+ }
141
+ } catch {
142
+ // Ignored on purpose — see above.
143
+ }
144
+
113
145
  if (catalogue.length === 0) return;
114
146
 
115
147
  pi.registerTool({
@@ -161,6 +193,45 @@ export default function (pi: ExtensionAPI) {
161
193
  } as never);
162
194
  });
163
195
 
196
+ // Extensions the account recommends. Still only a list: an extension is
197
+ // code on this machine, and a list we merely display cannot become one —
198
+ // the install stays a command the user types, now `/install` in-session.
199
+ let pendingPackages: readonly AccountPackage[] = [];
200
+ const describePackages = (list: readonly AccountPackage[]): string =>
201
+ list.map((p) => ` /install ${p.source} # ${p.name}${p.description ? ` — ${p.description}` : ""}`).join("\n");
202
+
203
+ pi.registerCommand("packages", {
204
+ description: t("查看账号推荐的扩展"),
205
+ handler: async (_args: string, ctx: ExtensionContext) => {
206
+ if (pendingPackages.length === 0) {
207
+ ctx.ui.notify(t("账号里的扩展都已安装。"), "info");
208
+ return;
209
+ }
210
+ ctx.ui.notify(`${t("账号推荐、本机尚未安装的扩展:")}\n${describePackages(pendingPackages)}`, "info");
211
+ },
212
+ });
213
+
214
+ pi.registerCommand("install", {
215
+ description: t("安装扩展(<npm:包名|git:...> [--local];无参数从账号推荐中选择)"),
216
+ getArgumentCompletions: (prefix: string) => {
217
+ const trimmed = prefix.trimStart();
218
+ if (trimmed.includes(" ")) return null;
219
+ const choices = [
220
+ ...pendingPackages.map((pkg) => ({
221
+ value: pkg.source,
222
+ label: (pkg.description || pkg.name).slice(0, 80),
223
+ })),
224
+ { value: "--local", label: t("安装到当前项目") },
225
+ ];
226
+ if (trimmed.length === 0) return choices;
227
+ return choices.filter((choice) => choice.value.startsWith(trimmed));
228
+ },
229
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
230
+ const outcome = await runInstallCommand(args, ctx, { recommended: pendingPackages });
231
+ if (outcome.kept) pendingPackages = pendingPackages.filter((pkg) => pkg.source !== outcome.kept);
232
+ },
233
+ });
234
+
164
235
  pi.registerCommand("skills", {
165
236
  description: t("查看可用的 DeepAILab 云端技能"),
166
237
  handler: async (_args: string, ctx: ExtensionContext) => {
@@ -175,4 +246,32 @@ export default function (pi: ExtensionAPI) {
175
246
  );
176
247
  },
177
248
  });
249
+
250
+ // Local skill management — the host already loads ~/.dal/agent/skills and
251
+ // .dal/skills; /skill is the add/list/show/remove surface on top of them,
252
+ // including AI drafting (a skill is a prompt wearing a filename).
253
+ pi.registerCommand("skill", {
254
+ description: t("管理本地技能(list | show <name> | add | remove <name>);/skills 查看云端技能"),
255
+ getArgumentCompletions: (prefix: string) => {
256
+ const trimmed = prefix.trimStart();
257
+ const space = trimmed.indexOf(" ");
258
+ if (space === -1) {
259
+ const subcommands = ["list", "add", "remove", "show"];
260
+ return subcommands
261
+ .filter((sub) => sub.startsWith(trimmed))
262
+ .map((sub) => ({ value: `${sub} `, label: sub }));
263
+ }
264
+ const sub = trimmed.slice(0, space);
265
+ const rest = trimmed.slice(space + 1);
266
+ if ((sub === "show" || sub === "remove") && !rest.includes(" ")) {
267
+ // The completion callback has no ctx; the process cwd is where the
268
+ // CLI started, which is the cwd the session uses.
269
+ return listLocalSkills(process.cwd())
270
+ .filter((skill) => skill.name.startsWith(rest))
271
+ .map((skill) => ({ value: `${sub} ${skill.name}`, label: skill.description.slice(0, 80) }));
272
+ }
273
+ return null;
274
+ },
275
+ handler: async (args: string, ctx: ExtensionCommandContext) => runSkillCommand(args, ctx),
276
+ });
178
277
  }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * /install — install an extension from inside the session.
3
+ *
4
+ * packages.ts shows what the account recommends and deliberately stops there:
5
+ * an extension is code on this machine, so the install itself must stay a
6
+ * command the user types. This file is that command — same deliberate act as
7
+ * `dal install npm:…`, just without quitting the session to type it.
8
+ *
9
+ * The flow mirrors the CLI one (download → keep? → persist → reload) so both
10
+ * surfaces keep telling the same story about what happens to the machine.
11
+ */
12
+
13
+ import { t } from "@dalcode/dal-pi-kit";
14
+ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
15
+ import { DefaultPackageManager, getAgentDir, SettingsManager } from "@earendil-works/pi-coding-agent";
16
+ import type { AccountPackage } from "./packages.ts";
17
+
18
+ /**
19
+ * The slice of DefaultPackageManager this command drives. Structural, so the
20
+ * real manager satisfies it as-is and tests can hand over a fake.
21
+ */
22
+ export interface InstallManagerLike {
23
+ install(source: string, options?: { local?: boolean }): Promise<void>;
24
+ remove(source: string, options?: { local?: boolean }): Promise<void>;
25
+ addSourceToSettings(source: string, options?: { local?: boolean; resolvedCommit?: string }): boolean;
26
+ getInstalledPath(source: string, scope: "user" | "project"): string | undefined;
27
+ readDeclaredPermissions(installedPath: string | undefined): string[] | undefined;
28
+ readGitHead(installedPath: string | undefined): Promise<string | undefined>;
29
+ setProgressCallback(callback: ((event: { type: string; message?: string }) => void) | undefined): void;
30
+ }
31
+
32
+ /** Build the real manager the same way the `dal install` CLI does. */
33
+ export function createInstallManager(cwd: string): InstallManagerLike {
34
+ return new DefaultPackageManager({ cwd, agentDir: getAgentDir(), settingsManager: SettingsManager.create(cwd) });
35
+ }
36
+
37
+ export interface InstallCommandOptions {
38
+ /** Account-recommended, not-yet-installed packages — the no-argument picker list. */
39
+ recommended?: readonly AccountPackage[];
40
+ createManager?: (cwd: string) => InstallManagerLike;
41
+ }
42
+
43
+ export interface InstallOutcome {
44
+ /** The source that was installed, kept, and persisted — undefined otherwise. */
45
+ kept?: string;
46
+ }
47
+
48
+ function showWorking(ctx: ExtensionCommandContext, message: string | undefined): void {
49
+ if (!ctx.hasUI) return;
50
+ ctx.ui.setWorkingVisible?.(message !== undefined);
51
+ ctx.ui.setWorkingMessage?.(message);
52
+ }
53
+
54
+ async function installOne(
55
+ source: string,
56
+ ctx: ExtensionCommandContext,
57
+ local: boolean,
58
+ createManager: (cwd: string) => InstallManagerLike,
59
+ ): Promise<InstallOutcome> {
60
+ if (local && !ctx.isProjectTrusted()) {
61
+ ctx.ui.notify(t("项目未受信任,无法安装项目级扩展。先运行 /trust 保存信任决策,再重试。"), "error");
62
+ return {};
63
+ }
64
+
65
+ const manager = createManager(ctx.cwd);
66
+ showWorking(ctx, t("正在安装扩展,请稍候…"));
67
+ manager.setProgressCallback((event) => {
68
+ if (event.message) showWorking(ctx, event.message);
69
+ });
70
+ try {
71
+ await manager.install(source, { local });
72
+ } catch (error) {
73
+ ctx.ui.notify(`${t("扩展安装失败:")}${error instanceof Error ? error.message : String(error)}`, "error");
74
+ return {};
75
+ } finally {
76
+ showWorking(ctx, undefined);
77
+ }
78
+
79
+ // Same contract as the CLI: the download lands first, the user decides
80
+ // whether it stays, and only a "keep" writes the settings entry.
81
+ const scope = local ? "project" : "user";
82
+ const installedPath = manager.getInstalledPath(source, scope);
83
+ const permissions = manager.readDeclaredPermissions(installedPath) ?? [];
84
+ const commit = await manager.readGitHead(installedPath);
85
+ const confirmed = await ctx.ui.confirm(
86
+ t("保留该扩展?"),
87
+ `${source}${local ? t("(项目级)") : t("(用户级)")}${permissions.length > 0 ? `\n${t("声明的权限:")}${permissions.join(", ")}` : ""}`,
88
+ );
89
+ if (!confirmed) {
90
+ try {
91
+ await manager.remove(source, { local });
92
+ } catch (error) {
93
+ ctx.ui.notify(
94
+ `${t("移除未保留的扩展失败,可稍后手动清理:")}${error instanceof Error ? error.message : String(error)}`,
95
+ "warning",
96
+ );
97
+ return {};
98
+ }
99
+ ctx.ui.notify(t("已取消安装。"), "info");
100
+ return {};
101
+ }
102
+
103
+ manager.addSourceToSettings(source, { local, resolvedCommit: commit });
104
+ ctx.ui.notify(`${t("已安装扩展:")}${source}${commit ? `\n${t("锁定提交:")}${commit.slice(0, 12)}` : ""}`, "info");
105
+ if (permissions.length > 0) {
106
+ ctx.ui.notify(`${t("该扩展声明了额外权限,请留意:")}${permissions.join(", ")}`, "warning");
107
+ }
108
+ await ctx.reload();
109
+ return { kept: source };
110
+ }
111
+
112
+ /** Entry point registered as the /install command. Returns what was kept. */
113
+ export async function runInstallCommand(
114
+ args: string,
115
+ ctx: ExtensionCommandContext,
116
+ options: InstallCommandOptions = {},
117
+ ): Promise<InstallOutcome> {
118
+ const createManager = options.createManager ?? createInstallManager;
119
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
120
+ const local = tokens.includes("--local");
121
+ const source = tokens.find((token) => token !== "--local");
122
+
123
+ if (!source) {
124
+ const recommended = options.recommended ?? [];
125
+ if (recommended.length === 0) {
126
+ ctx.ui.notify(t("账号推荐的扩展都已安装。也可以用 /install <npm:包名> 直接安装。"), "info");
127
+ return {};
128
+ }
129
+ const choices = recommended.map(
130
+ (pkg) => `${pkg.source} — ${pkg.name}${pkg.description ? `:${pkg.description}` : ""}`,
131
+ );
132
+ const picked = await ctx.ui.select(t("选择要安装的扩展:"), choices);
133
+ if (picked === undefined) return {};
134
+ const pkg = recommended[choices.indexOf(picked)];
135
+ if (!pkg) return {};
136
+ return installOne(pkg.source, ctx, local, createManager);
137
+ }
138
+
139
+ return installOne(source, ctx, local, createManager);
140
+ }