dal-code 1.0.0 → 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.
- package/CHANGELOG.md +67 -1
- package/dist/core/auth-guidance.d.ts +1 -0
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js +6 -0
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +4 -7
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +13 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +47 -48
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +46 -43
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +10 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +13 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +61 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +43 -6
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/dal/builtins.d.ts.map +1 -1
- package/dist/dal/builtins.js +1 -0
- package/dist/dal/builtins.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +12 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +39 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +200 -29
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +35 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +177 -23
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +2 -2
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +9 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.ts +142 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.ts +218 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.ts +99 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +161 -18
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.ts +8 -3
- package/dist/node_modules/@dalcode/dal-office/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-office/package.json +37 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/csv.ts +84 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/index.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.ts +109 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/paths.ts +107 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.ts +155 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.ts +386 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/scenes.ts +197 -0
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.ts +49 -0
- package/dist/node_modules/@dalcode/dal-office/src/themes.ts +240 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.ts +122 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.ts +123 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.ts +76 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.ts +106 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.ts +91 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.ts +71 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/shared.ts +54 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.ts +101 -0
- package/dist/node_modules/@dalcode/dal-office/src/truncate.ts +27 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +233 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +322 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-skills/src/discover.ts +101 -0
- package/dist/node_modules/@dalcode/dal-skills/src/index.ts +71 -9
- package/dist/node_modules/@dalcode/dal-skills/src/install.ts +140 -0
- package/dist/node_modules/@dalcode/dal-skills/src/manage.ts +446 -0
- package/dist/node_modules/@dalcode/dal-skills/src/packages.ts +39 -1
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-subagent/src/index.ts +46 -4
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@dalcode/deepailab/src/index.ts +7 -1
- package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +42 -6
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +23 -22
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +4 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/utils/changelog.d.ts +37 -4
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +80 -17
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +13 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +1 -1
- package/npm-shrinkwrap.json +1511 -25
- package/package.json +8 -2
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
* That also means this file never shells out. It reads a list and compares.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { readFileSync } from "node:fs";
|
|
14
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
|
|
17
|
+
const NAG_FILE = "install-nag.json";
|
|
18
|
+
|
|
17
19
|
export interface AccountPackage {
|
|
18
20
|
readonly source: string;
|
|
19
21
|
readonly name: string;
|
|
@@ -90,3 +92,39 @@ export function missingPackages(
|
|
|
90
92
|
);
|
|
91
93
|
return account.filter((p) => !have.has(p.source.trim().toLowerCase()));
|
|
92
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": "1.0.
|
|
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": "1.0.
|
|
21
|
-
"@dalcode/dal-guard": "1.0.
|
|
22
|
-
"@earendil-works/pi-agent-core": "^0.
|
|
23
|
-
"@earendil-works/pi-ai": "^0.
|
|
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.
|
|
27
|
+
"@earendil-works/pi-coding-agent": "^1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependenciesMeta": {
|
|
30
30
|
"@earendil-works/pi-coding-agent": {
|