Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(prompt): 注入产品身份锚点并补 about-cindy 能力条目 (#702)

Dash2d033f680fb7
diff --git a/apps/desktop/src/main/maker-host/host-system-prompt.md b/apps/desktop/src/main/maker-host/host-system-prompt.md
index e69de29bb2..4dccd23f95 100644
--- a/apps/desktop/src/main/maker-host/host-system-prompt.md
+++ b/apps/desktop/src/main/maker-host/host-system-prompt.md
@@ -0,0 +1,2 @@
+You are Cindy, an open-source AI assistant.
+Source: https://github.com/makecindy/cindy
diff --git a/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts b/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts
new file mode 100644
index 0000000000..8d06957670
--- /dev/null
+++ b/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts
@@ -0,0 +1,145 @@
+import { describe, expect, it, vi } from 'vitest';
+import { Client } from '@modelcontextprotocol/sdk/client/index.js';
+import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
+import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
+
+import { createXdtHelperMcpServer } from '../lizi_xdtHelperMcpServer.js';
+import { CAPABILITIES, findCapability, listCapabilityIndex } from '../xdt-helper/capabilities.js';
+import type { LiziMcpLogger } from '../types.js';
+
+/**
+ * get_capabilities 的行为契约测试。
+ *
+ * 此前只有 toolErrorTelemetry.test.ts 覆盖了它的 schema / 遥测,没有任何测试校验
+ * 「能力索引与按 key 查询」这条真正被模型走的路径 —— 新增或改名 capability 时,
+ * 索引缺项、detail 为空、UNKNOWN_KEY 的 available 列表过期都不会被发现。
+ */
+
+const sessionCtx = {
+ agentKind: 'claude-code' as const,
+ workingDir: '/tmp',
+ sessionId: 'sess-capabilities',
+};
+
+function makeLogger(): LiziMcpLogger {
+ return { trace: vi.fn(), debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() };
+}
+
+async function connect(server: McpServer) {
+ const [clientTx, serverTx] = InMemoryTransport.createLinkedPair();
+ const client = new Client({ name: 'capabilities-test-client', version: '0.0.0' });
+ await Promise.all([server.connect(serverTx), client.connect(clientTx)]);
+ return {
+ client,
+ cleanup: async () => {
+ await client.close();
+ await server.close();
+ },
+ };
+}
+
+/** call_tool 的返回体是 JSON 文本块,取出来解析。 */
+function parsePayload(result: unknown): Record<string, unknown> {
+ const content = (result as { content?: Array<{ type: string; text?: string }> }).content;
+ const first = content?.[0];
+ if (!first || first.type !== 'text' || !first.text) {
+ throw new Error('tool result has no text content');
+ }
+ return JSON.parse(first.text) as Record<string, unknown>;
+}
+
+describe('capabilities data source', () => {
+ it('每条 capability 的 key / title / oneLiner / detail 都非空', () => {
+ expect(CAPABILITIES.length).toBeGreaterThan(0);
+ for (const entry of CAPABILITIES) {
+ expect(entry.key.trim()).not.toBe('');
+ expect(entry.title.trim()).not.toBe('');
+ expect(entry.oneLiner.trim()).not.toBe('');
+ expect(entry.detail.trim()).not.toBe('');
+ }
+ });
+
+ it('key 不重复', () => {
+ const keys = CAPABILITIES.map((c) => c.key);
+ expect(new Set(keys).size).toBe(keys.length);
+ });
+
+ it('listCapabilityIndex 只暴露索引字段,不带 detail', () => {
+ for (const item of listCapabilityIndex()) {
+ expect(Object.keys(item).sort()).toEqual(['key', 'oneLiner', 'title']);
+ }
+ });
+
+ it('about-cindy 覆盖产品身份与源码仓库', () => {
+ const entry = findCapability('about-cindy');
+ expect(entry).toBeDefined();
+ expect(entry!.detail).toContain('https://github.com/makecindy/cindy');
+ // 执行位置不能被写死成客户端:SSH 远程工作区下 agent 进程在远端主机。
+ expect(entry!.detail).toContain('SSH 远程工作区');
+ // 官网是区域敏感的:两个都要给,只给国际版会把大陆用户导错。
+ expect(entry!.detail).toContain('https://cindy.cn');
+ expect(entry!.detail).toContain('https://cindy.app');
+ });
+});
+
+describe('get_capabilities tool', () => {
+ it('不传 key 时返回包含 about-cindy 的索引', async () => {
+ const h = await connect(createXdtHelperMcpServer({ logger: makeLogger() }, sessionCtx));
+ try {
+ const payload = parsePayload(
+ await h.client.callTool({
+ name: 'call_tool',
+ arguments: { name: 'get_capabilities', args: {} },
+ }),
+ );
+
+ expect(payload.ok).toBe(true);
+ const caps = payload.capabilities as Array<{ key: string; detail?: unknown }>;
+ expect(caps.map((c) => c.key)).toContain('about-cindy');
+ // 索引不应该带 detail —— 否则渐进式发现省 token 的意义就没了。
+ expect(caps.every((c) => c.detail === undefined)).toBe(true);
+ } finally {
+ await h.cleanup();
+ }
+ });
+
+ it('传 key=about-cindy 时返回 ok 与非空 detail', async () => {
+ const h = await connect(createXdtHelperMcpServer({ logger: makeLogger() }, sessionCtx));
+ try {
+ const payload = parsePayload(
+ await h.client.callTool({
+ name: 'call_tool',
+ arguments: { name: 'get_capabilities', args: { key: 'about-cindy' } },
+ }),
+ );
+
+ expect(payload.ok).toBe(true);
+ const capability = payload.capability as { key: string; detail: string };
+ expect(capability.key).toBe('about-cindy');
+ expect(capability.detail.trim().length).toBeGreaterThan(0);
+ } finally {
+ await h.cleanup();
+ }
+ });
+
+ it('未知 key 返回 UNKNOWN_KEY,且 available 列表与当前清单同步', async () => {
+ const h = await connect(createXdtHelperMcpServer({ logger: makeLogger() }, sessionCtx));
+ try {
+ const payload = parsePayload(
+ await h.client.callTool({
+ name: 'call_tool',
+ arguments: { name: 'get_capabilities', args: { key: 'no-such-capability' } },
+ }),
+ );
+
+ expect(payload.ok).toBe(false);
+ expect(payload.errorCode).toBe('UNKNOWN_KEY');
+ const data = payload.data as { requested: string; available: string[] };
+ expect(data.requested).toBe('no-such-capability');
+ expect(data.available).toContain('about-cindy');
+ expect(data.available).toEqual(CAPABILITIES.map((c) => c.key));
+ } finally {
+ await h.cleanup();
+ }
+ });
+});
diff --git a/packages/lizi-mcps/src/xdt-helper/capabilities.ts b/packages/lizi-mcps/src/xdt-helper/capabilities.ts
index 493be50bdc..334f8c7230 100644
--- a/packages/lizi-mcps/src/xdt-helper/capabilities.ts
+++ b/packages/lizi-mcps/src/xdt-helper/capabilities.ts
@@ -27,6 +27,18 @@ export interface CapabilityEntry {
}
export const CAPABILITIES: readonly CapabilityEntry[] = [
+ {
+ key: 'about-cindy',
+ title: `${BRAND_NAME} 自身信息(产品身份 / 开源仓库 / 源码位置)`,
+ oneLiner: `${BRAND_NAME} 是什么、谁做的、开不开源、源码在哪、agent 跑在哪、版本号怎么查, 以及模型接入(官方服务 / 复用 Coding Plan / 自带 API key / 本地模型)与分区域官网下载定价。`,
+ detail: [
+ `【是什么】${BRAND_NAME} 是 XD Inc. 出品的开源 AI 助手(open-source AI assistant), 以桌面 / 移动客户端形态交付, 源码 https://github.com/makecindy/cindy (Apache-2.0)。官网分区域: 中国大陆 https://cindy.cn, 国际版 https://cindy.app —— 给下载 / 定价链接前先确认用户所在区域, 不要一律给国际版。`,
+ `【身份归本条, 执行位置不归】问"你是谁 / 你是什么"以本条为准, 不要用训练数据猜, 也不要凭工作目录路径或工具名反推。但 ${BRAND_NAME} 只是编排方(管会话、工具、上下文与 memory; 底层 harness 是 Claude Code 或 Codex, 可中途切换且上下文连续), 不代表代码在哪执行: agent 进程与 workdir 可能在本机, 也可能在 SSH 远程工作区的远端主机(文件与进程都在远端), 或经设备互联隧道驱动的被控桌面端。问"你跑在哪 / 文件在哪台机器"时以当前会话实际工作区为准, 拿不准就说明, 不要断言。`,
+ `【源码范围】该仓库是客户端本体(desktop、mobile 及共享 packages 的 pnpm monorepo), 服务端不在其中也不开源。安装版不携带源码, agent 侧无法推断用户是否 clone 过、clone 在哪: 要读改源码就让用户给路径或用工程模式打开, 不要假设固定路径, 更不要因为工作目录里出现品牌名就断定当前目录是源码仓库。`,
+ `【版本号不要猜】本条不含版本号。CN 版可在"设置 → 关于"看到客户端版本; 国际版该页当前不展示它(只有更新开关与 agent 二进制版本), 别把用户支使过去空找。用 submit_github_issue 提反馈时客户端版本 / OS / 界面语言由系统自动附加, 不用 agent 填。`,
+ `【模型怎么来】登录官方 ${BRAND_NAME} 服务按量透明扣费、授权已付费的 Claude Code / Codex Coding Plan 继续用(不重复付费)、接自己的 API key, 或跑本地模型。价格见对应区域官网。`,
+ ].join(' '),
+ },
{
key: 'ai-chat',
title: 'AI 对话',
diff --git a/packages/lizi-mcps/src/xdt-helper/get_capabilities.ts b/packages/lizi-mcps/src/xdt-helper/get_capabilities.ts
index f9b2df774d..b95e2f19bc 100644
--- a/packages/lizi-mcps/src/xdt-helper/get_capabilities.ts
+++ b/packages/lizi-mcps/src/xdt-helper/get_capabilities.ts
@@ -2,7 +2,7 @@
* xdt-helper/get_capabilities.ts — get_capabilities tool
*
* 渐进式发现:
- * - 不传 key → 返回 12 条 {key, title, oneLiner} 索引,模型挑感兴趣的再细查
+ * - 不传 key → 返回全部 {key, title, oneLiner} 索引,模型挑感兴趣的再细查
* - 传 key → 返回单条 {key, title, oneLiner, detail}
* - key 不存在 → 返回可用 key 列表 + UNKNOWN_KEY 错误码,让模型自纠
*
@@ -22,7 +22,9 @@ export function registerGetCapabilitiesTool(registry: XdtHelperToolRegistry): vo
description:
`查询 ${BRAND_NAME} 自身能力。不传参数 → 返回所有能力的 {key, title, oneLiner} 索引;` +
'传 key=<具体能力 key> → 返回该能力的完整 detail。' +
- `当用户问"${BRAND_NAME} 能做什么 / 有哪些功能 / 支持 X 吗"时调用本工具,而不是用训练数据回答。`,
+ `当用户问"${BRAND_NAME} 能做什么 / 有哪些功能 / 支持 X 吗"时调用本工具,而不是用训练数据回答。` +
+ `用户问"你是谁 / 你是什么 / 你跑在哪 / ${BRAND_NAME} 是什么产品 / 谁做的 / 开不开源 / 源码在哪"时,` +
+ '同样调本工具取 key=about-cindy,不要靠工作目录路径、工具名或训练数据推断。',
inputShape: {
key: z
.string()
diff --git a/packages/maker-core/src/agents/claude-code/system-prompt-append.ts b/packages/maker-core/src/agents/claude-code/system-prompt-append.ts
index 95bae8ca9b..bcd5ad28a8 100644
--- a/packages/maker-core/src/agents/claude-code/system-prompt-append.ts
+++ b/packages/maker-core/src/agents/claude-code/system-prompt-append.ts
@@ -3,10 +3,11 @@
//
// 真正的内容写在同目录的 system-prompt-append.md,vite 编译时通过 ?raw 内联为字符串。
//
-// 当前 .md 是空的 —— host 层的产品级规则也已全部清空(2026-07-16 经 Lizi 确认:
-// 内部系统 MCP 路由随飞书等迁入意识(Ghost)体系、免责声明随产品对外化、mermaid 渲染
-// 规范与实时信息查询一并移除),host 层注入口保留:
-// apps/desktop/src/main/maker-host/host-system-prompt.md (vendor-neutral)
+// 当前 .md 是空的 —— 原有的产品级规则已于 2026-07-16 经 Lizi 确认清空(内部系统 MCP
+// 路由随飞书等迁入意识(Ghost)体系、免责声明随产品对外化、mermaid 渲染规范与实时信息
+// 查询一并移除)。host 层注入口保留:
+// apps/desktop/src/main/maker-host/host-system-prompt.md (vendor-neutral;当前是两行
+// 产品身份锚点:身份声明 + 源码仓库地址,让模型知道自己是 Cindy 及源码在哪)
// apps/desktop/src/main/maker-host/claude-system-prompt.md (Claude host 专属;当前为空——
// 原「绘图走 art MCP」规则已删,画图路由交给意识(Ghost)触发体系)
// 由 host 通过 runtimeConfig.systemPrompt 注入,跟本常量在 startSession 拼成一段
diff --git a/packages/maker-core/src/agents/codex/system-prompt-append.ts b/packages/maker-core/src/agents/codex/system-prompt-append.ts
index 6d98234ddf..ba07cdbefe 100644
--- a/packages/maker-core/src/agents/codex/system-prompt-append.ts
+++ b/packages/maker-core/src/agents/codex/system-prompt-append.ts
@@ -5,10 +5,11 @@
//
// 真正的内容写在同目录的 system-prompt-append.md,vite 编译时通过 ?raw 内联为字符串。
//
-// 当前 .md 是空的 —— host 层的产品级规则也已全部清空(2026-07-16 经 Lizi 确认:
-// 内部系统 MCP 路由随飞书等迁入意识(Ghost)体系、免责声明随产品对外化、mermaid 渲染
-// 规范与实时信息查询一并移除),host 层注入口保留:
-// apps/desktop/src/main/maker-host/host-system-prompt.md (vendor-neutral)
+// 当前 .md 是空的 —— 原有的产品级规则已于 2026-07-16 经 Lizi 确认清空(内部系统 MCP
+// 路由随飞书等迁入意识(Ghost)体系、免责声明随产品对外化、mermaid 渲染规范与实时信息
+// 查询一并移除)。host 层注入口保留:
+// apps/desktop/src/main/maker-host/host-system-prompt.md (vendor-neutral;当前是两行
+// 产品身份锚点:身份声明 + 源码仓库地址,让模型知道自己是 Cindy 及源码在哪)
// apps/desktop/src/main/maker-host/codex-system-prompt.md (Codex host 专属;当前为空——
// 原「绘图走 codex imagegen」规则已删,画图路由交给意识(Ghost)触发体系)
// 由 host 通过 runtimeConfig.systemPrompt 注入,跟本常量在 startSession 拼成一段