Skip to content

Commit 2e600e5

Browse files
authored
Merge branch 'main' into feat/scope-storage-a1
2 parents 445c153 + 6bc3117 commit 2e600e5

7 files changed

Lines changed: 130 additions & 17 deletions

File tree

‎.coderabbit.yaml‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# CodeRabbit 审阅配置:额度优先。
2-
# 个人 Free 档限额很小(1 次/小时),默认的「每个 PR 自动审、每次 push 重审」
3-
# 会把额度烧光。这里关掉自动审,需要 AI 审阅时在 PR 里评论 `@coderabbitai review`
4-
# 按需触发——外部大 PR 才值得花额度;维护者自己的小改动走本地审阅 +
5-
# Copilot code review(教育版额度)覆盖。
1+
# CodeRabbit 审阅配置:自动审兜底。
2+
# Copilot 教育版额度不足,恢复 CodeRabbit 自动审阅兜底。
3+
# Free 档限额仍小,保持 chill 档 + 锁文件/素材排除,控制额度消耗。
64
language: zh-CN
75

86
reviews:
97
profile: chill
108
auto_review:
11-
enabled: false
12-
# 锁文件与素材目录没有审阅价值,显式排除(预防将来开自动审时浪费额度)。
9+
enabled: true
10+
# 锁文件与素材目录没有审阅价值,显式排除。
1311
path_filters:
1412
- "!**/package-lock.json"
1513
- "!images/**"

‎dsh-mneme/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ dsh web
123123

124124
- **用户画像**:一段自由文本描述用户自己(角色、背景、偏好),**每轮注入**到系统提示,让 Agent 始终遵循
125125
- **规则**:Agent 必须遵守的行为规则列表(如"回答先给结论"),同样每轮注入
126-
- **自定义指令**:注册斜杠命令(`/名称`),触发时把用户定义的指令内容交给 Agent。命令持久化到 SQLite,启动时自动注册到 DSH 命令表,增删实时生效
126+
- **自定义指令**:注册斜杠命令(`/名称 [补充说明]`),触发时把用户定义的指令内容作为一条用户消息提交给当前 Agent,命令后缀会作为补充说明一并提交;界面仅显示提交回执(宿主不支持 followup 提交时退回旧行为,指令原文会显示在界面,便于复制后手动发送)。命令持久化到 SQLite,启动时自动注册到 DSH 命令表,增删实时生效
127127

128128
> 画像与规则通过独立的 `[用户设置]` 注入区块(优先级高于记忆库),即使记忆为空也会注入。
129129

‎dsh-mneme/lib/commands.js‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import { createUserMessage } from "@deepseek-ai/dsh-llm";
12
import { STR } from "./lang.js";
23

34
// Custom slash-command manager: keeps the DSH command registry in sync with
45
// user-defined commands persisted in SQLite. Commands are registered on boot
56
// and (re)registered on add/remove through the API.
67
//
7-
// Each custom command's handler returns the user-authored instruction as a
8-
// success result; the DSH UI surfaces it as a model-directed instruction.
8+
// Per the DSH command contract, a handler's CommandResult text is only a UI
9+
// settlement notice and never reaches the model. To actually drive the agent,
10+
// the handler submits the user-authored instruction itself as a user followup
11+
// message on the receiving agent (same pattern as the official /goal command).
12+
// The notice just acknowledges the submission; an optional rawInput suffix
13+
// typed after the command is appended for the model.
914

1015
export function createCommandManager({ ctx, settings, logger, language = "zh" }) {
1116
const registered = new Map(); // name -> disposer
@@ -18,7 +23,8 @@ export function createCommandManager({ ctx, settings, logger, language = "zh" })
1823
name: command.name,
1924
// 缺省描述随实例语言(命令描述进命令注册表,对 LLM 可见)。
2025
description: command.description || STR.commandFallbackDesc[language](command.name),
21-
handler: () => ({ kind: "success", text: command.instruction })
26+
input: { hint: STR.commandInputHint[language] },
27+
handler: (invocation) => submit(command, invocation)
2228
});
2329
} catch (error) {
2430
logger?.warn?.(`dsh-mneme: failed to register command /${command.name}: ${String(error)}`);
@@ -27,6 +33,27 @@ export function createCommandManager({ ctx, settings, logger, language = "zh" })
2733
registered.set(command.name, dispose);
2834
}
2935

36+
/** Submit the instruction (plus optional rawInput suffix) to the receiving agent. */
37+
function submit(command, invocation) {
38+
const suffix = typeof invocation?.rawInput === "string" ? invocation.rawInput.trim() : "";
39+
const text = suffix ? `${command.instruction}\n\n${suffix}` : command.instruction;
40+
const agent = invocation?.agent;
41+
if (typeof agent?.followup !== "function") {
42+
// 兜底:宿主未提供接收 agent 时退回旧行为,至少把指令展示在 notice 里。
43+
return { kind: "success", text };
44+
}
45+
try {
46+
agent.followup(createUserMessage({
47+
content: [{ type: "text", text }],
48+
source: { kind: "user" }
49+
}));
50+
} catch (error) {
51+
logger?.warn?.(`dsh-mneme: failed to submit /${command.name} to agent: ${String(error)}`);
52+
return { kind: "error", text: STR.commandSubmitFailed[language](command.name) };
53+
}
54+
return { kind: "success", text: STR.commandSubmitted[language](command.name) };
55+
}
56+
3057
function unregisterOne(name) {
3158
const dispose = registered.get(name);
3259
if (dispose) {

‎dsh-mneme/lib/lang.js‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dsh-mneme/src/commands.js‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import { createUserMessage } from "@deepseek-ai/dsh-llm";
12
import { STR } from "./lang.js";
23

34
// Custom slash-command manager: keeps the DSH command registry in sync with
45
// user-defined commands persisted in SQLite. Commands are registered on boot
56
// and (re)registered on add/remove through the API.
67
//
7-
// Each custom command's handler returns the user-authored instruction as a
8-
// success result; the DSH UI surfaces it as a model-directed instruction.
8+
// Per the DSH command contract, a handler's CommandResult text is only a UI
9+
// settlement notice and never reaches the model. To actually drive the agent,
10+
// the handler submits the user-authored instruction itself as a user followup
11+
// message on the receiving agent (same pattern as the official /goal command).
12+
// The notice just acknowledges the submission; an optional rawInput suffix
13+
// typed after the command is appended for the model.
914

1015
export function createCommandManager({ ctx, settings, logger, language = "zh" }) {
1116
const registered = new Map(); // name -> disposer
@@ -18,7 +23,8 @@ export function createCommandManager({ ctx, settings, logger, language = "zh" })
1823
name: command.name,
1924
// 缺省描述随实例语言(命令描述进命令注册表,对 LLM 可见)。
2025
description: command.description || STR.commandFallbackDesc[language](command.name),
21-
handler: () => ({ kind: "success", text: command.instruction })
26+
input: { hint: STR.commandInputHint[language] },
27+
handler: (invocation) => submit(command, invocation)
2228
});
2329
} catch (error) {
2430
logger?.warn?.(`dsh-mneme: failed to register command /${command.name}: ${String(error)}`);
@@ -27,6 +33,27 @@ export function createCommandManager({ ctx, settings, logger, language = "zh" })
2733
registered.set(command.name, dispose);
2834
}
2935

36+
/** Submit the instruction (plus optional rawInput suffix) to the receiving agent. */
37+
function submit(command, invocation) {
38+
const suffix = typeof invocation?.rawInput === "string" ? invocation.rawInput.trim() : "";
39+
const text = suffix ? `${command.instruction}\n\n${suffix}` : command.instruction;
40+
const agent = invocation?.agent;
41+
if (typeof agent?.followup !== "function") {
42+
// 兜底:宿主未提供接收 agent 时退回旧行为,至少把指令展示在 notice 里。
43+
return { kind: "success", text };
44+
}
45+
try {
46+
agent.followup(createUserMessage({
47+
content: [{ type: "text", text }],
48+
source: { kind: "user" }
49+
}));
50+
} catch (error) {
51+
logger?.warn?.(`dsh-mneme: failed to submit /${command.name} to agent: ${String(error)}`);
52+
return { kind: "error", text: STR.commandSubmitFailed[language](command.name) };
53+
}
54+
return { kind: "success", text: STR.commandSubmitted[language](command.name) };
55+
}
56+
3057
function unregisterOne(name) {
3158
const dispose = registered.get(name);
3259
if (dispose) {

‎dsh-mneme/src/lang.js‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dsh-mneme/test/commands.test.js‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,51 @@ test("add registers live; remove unregisters live", () => {
4040
store.close();
4141
});
4242

43-
test("handler returns the instruction as success text", async () => {
43+
test("handler submits the instruction to the agent and returns a receipt", async () => {
4444
const { store, manager, registered } = setup();
4545
manager.add({ name: "fmt", description: "格式化", instruction: "请按项目的 lint 规则格式化当前文件" });
4646
const def = registered.get("fmt");
4747
assert.ok(def, "definition registered");
48-
const result = await def.handler({ agent: {}, rawInput: "", signal: null });
48+
assert.equal(def.input.hint, "可选:追加给模型的补充说明");
49+
const submitted = [];
50+
const agent = { followup: (message) => submitted.push(message) };
51+
const result = await def.handler({ agent, rawInput: "", signal: null });
4952
assert.equal(result.kind, "success");
50-
assert.equal(result.text, "请按项目的 lint 规则格式化当前文件");
53+
assert.equal(result.text, "已提交指令:fmt");
54+
assert.equal(submitted.length, 1);
55+
assert.equal(submitted[0].role, "user");
56+
assert.deepEqual(submitted[0].content, [{ type: "text", text: "请按项目的 lint 规则格式化当前文件" }]);
57+
assert.deepEqual(submitted[0].source, { kind: "user" });
58+
store.close();
59+
});
60+
61+
test("rawInput suffix is appended for the model", async () => {
62+
const { store, manager, registered } = setup();
63+
manager.add({ name: "mneme", instruction: "以「小墨」的口吻自我介绍" });
64+
const def = registered.get("mneme");
65+
const submitted = [];
66+
await def.handler({ agent: { followup: (m) => submitted.push(m) }, rawInput: " 顺便列出归档数量 " });
67+
assert.equal(submitted[0].content[0].text, "以「小墨」的口吻自我介绍\n\n顺便列出归档数量");
68+
store.close();
69+
});
70+
71+
test("handler without a receiving agent falls back to surfacing the instruction", () => {
72+
const { store, manager, registered } = setup();
73+
manager.add({ name: "fmt", instruction: "legacy text" });
74+
const def = registered.get("fmt");
75+
const result = def.handler({ rawInput: "" });
76+
assert.equal(result.kind, "success");
77+
assert.equal(result.text, "legacy text");
78+
store.close();
79+
});
80+
81+
test("handler returns an error result when the agent rejects the submission", () => {
82+
const { store, manager, registered } = setup();
83+
manager.add({ name: "boom", instruction: "x" });
84+
const def = registered.get("boom");
85+
const result = def.handler({ agent: { followup: () => { throw new Error("nope"); } } });
86+
assert.equal(result.kind, "error");
87+
assert.match(result.text, /boom/);
5188
store.close();
5289
});
5390

0 commit comments

Comments
 (0)