team-anya-cli 0.1.8 → 1.0.1

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 (168) hide show
  1. package/README.md +1 -37
  2. package/package.json +6 -37
  3. package/anya/prompts/execution-guides/git-delivery.md +0 -38
  4. package/anya/prompts/execution-guides/testing-and-self-heal.md +0 -28
  5. package/anya/prompts/protocols/brief-assembly.md +0 -55
  6. package/anya/prompts/protocols/report.md +0 -175
  7. package/anya/prompts/protocols/review.md +0 -90
  8. package/anya/prompts/task-claude-md.template.md +0 -32
  9. package/apps/server/dist/broker/cc-broker.js +0 -261
  10. package/apps/server/dist/cli.js +0 -296
  11. package/apps/server/dist/config.js +0 -76
  12. package/apps/server/dist/daemon.js +0 -51
  13. package/apps/server/dist/franky/context-builder.js +0 -160
  14. package/apps/server/dist/franky/franky-mcp-server.js +0 -107
  15. package/apps/server/dist/franky/franky-orchestrator.js +0 -450
  16. package/apps/server/dist/franky/index.js +0 -5
  17. package/apps/server/dist/franky/topic-router.js +0 -16
  18. package/apps/server/dist/gateway/chat-sync.js +0 -135
  19. package/apps/server/dist/gateway/command-router.js +0 -114
  20. package/apps/server/dist/gateway/commands/cancel.js +0 -32
  21. package/apps/server/dist/gateway/commands/help.js +0 -16
  22. package/apps/server/dist/gateway/commands/index.js +0 -26
  23. package/apps/server/dist/gateway/commands/restart.js +0 -34
  24. package/apps/server/dist/gateway/commands/status.js +0 -34
  25. package/apps/server/dist/gateway/commands/tasks.js +0 -33
  26. package/apps/server/dist/gateway/feishu-sender.js +0 -410
  27. package/apps/server/dist/gateway/feishu-ws.js +0 -256
  28. package/apps/server/dist/gateway/http.js +0 -1019
  29. package/apps/server/dist/gateway/media-downloader.js +0 -149
  30. package/apps/server/dist/gateway/message-events.js +0 -10
  31. package/apps/server/dist/gateway/message-intake.js +0 -67
  32. package/apps/server/dist/gateway/message-queue.js +0 -118
  33. package/apps/server/dist/gateway/session-reader.js +0 -142
  34. package/apps/server/dist/gateway/ws-push.js +0 -115
  35. package/apps/server/dist/loid/brain.js +0 -105
  36. package/apps/server/dist/loid/clarifier.js +0 -162
  37. package/apps/server/dist/loid/context-builder.js +0 -413
  38. package/apps/server/dist/loid/mcp-server.js +0 -106
  39. package/apps/server/dist/loid/memory-settler.js +0 -189
  40. package/apps/server/dist/loid/opportunity-manager.js +0 -148
  41. package/apps/server/dist/loid/profile-updater.js +0 -179
  42. package/apps/server/dist/loid/reporter.js +0 -148
  43. package/apps/server/dist/loid/schemas.js +0 -117
  44. package/apps/server/dist/loid/self-calibrator.js +0 -314
  45. package/apps/server/dist/loid/session-manager.js +0 -301
  46. package/apps/server/dist/loid/session.js +0 -271
  47. package/apps/server/dist/loid/worktree-manager.js +0 -191
  48. package/apps/server/dist/main.js +0 -393
  49. package/apps/server/dist/tracing/index.js +0 -2
  50. package/apps/server/dist/tracing/trace-context.js +0 -92
  51. package/apps/server/dist/types/message.js +0 -2
  52. package/apps/server/dist/yor/yor-mcp-server.js +0 -104
  53. package/apps/server/dist/yor/yor-orchestrator.js +0 -233
  54. package/apps/web/dist/assets/index-BiiEB0qZ.css +0 -1
  55. package/apps/web/dist/assets/index-D1AK5ZEE.js +0 -798
  56. package/apps/web/dist/index.html +0 -13
  57. package/packages/cc-client/dist/claude-code-backend.js +0 -664
  58. package/packages/cc-client/dist/index.js +0 -2
  59. package/packages/cc-client/package.json +0 -11
  60. package/packages/core/dist/constants.js +0 -59
  61. package/packages/core/dist/errors.js +0 -35
  62. package/packages/core/dist/index.js +0 -7
  63. package/packages/core/dist/office-init.js +0 -101
  64. package/packages/core/dist/scope/checker.js +0 -114
  65. package/packages/core/dist/scope/defaults.js +0 -55
  66. package/packages/core/dist/scope/index.js +0 -3
  67. package/packages/core/dist/state-machine.js +0 -85
  68. package/packages/core/dist/types/audit.js +0 -12
  69. package/packages/core/dist/types/backend.js +0 -2
  70. package/packages/core/dist/types/commitment.js +0 -17
  71. package/packages/core/dist/types/communication.js +0 -18
  72. package/packages/core/dist/types/index.js +0 -8
  73. package/packages/core/dist/types/opportunity.js +0 -27
  74. package/packages/core/dist/types/org.js +0 -26
  75. package/packages/core/dist/types/task.js +0 -46
  76. package/packages/core/package.json +0 -10
  77. package/packages/db/dist/client.js +0 -69
  78. package/packages/db/dist/index.js +0 -691
  79. package/packages/db/dist/schema/audit-events.js +0 -13
  80. package/packages/db/dist/schema/cc-sessions.js +0 -14
  81. package/packages/db/dist/schema/chats.js +0 -33
  82. package/packages/db/dist/schema/commitments.js +0 -18
  83. package/packages/db/dist/schema/communication-events.js +0 -14
  84. package/packages/db/dist/schema/index.js +0 -13
  85. package/packages/db/dist/schema/message-log.js +0 -20
  86. package/packages/db/dist/schema/opportunities.js +0 -23
  87. package/packages/db/dist/schema/org.js +0 -36
  88. package/packages/db/dist/schema/projects.js +0 -23
  89. package/packages/db/dist/schema/tasks.js +0 -48
  90. package/packages/db/dist/schema/topics.js +0 -20
  91. package/packages/db/dist/schema/trace-spans.js +0 -19
  92. package/packages/db/package.json +0 -12
  93. package/packages/db/src/migrations/0000_baseline.sql +0 -251
  94. package/packages/db/src/migrations/meta/_journal.json +0 -13
  95. package/packages/mcp-tools/dist/index.js +0 -41
  96. package/packages/mcp-tools/dist/layer1/audit-append.js +0 -38
  97. package/packages/mcp-tools/dist/layer1/audit-query.js +0 -51
  98. package/packages/mcp-tools/dist/layer1/memory-brief.js +0 -168
  99. package/packages/mcp-tools/dist/layer1/memory-context.js +0 -124
  100. package/packages/mcp-tools/dist/layer1/memory-digest.js +0 -126
  101. package/packages/mcp-tools/dist/layer1/memory-forget.js +0 -108
  102. package/packages/mcp-tools/dist/layer1/memory-learn.js +0 -63
  103. package/packages/mcp-tools/dist/layer1/memory-recall.js +0 -287
  104. package/packages/mcp-tools/dist/layer1/memory-reflect.js +0 -80
  105. package/packages/mcp-tools/dist/layer1/memory-remember.js +0 -119
  106. package/packages/mcp-tools/dist/layer1/memory-search.js +0 -263
  107. package/packages/mcp-tools/dist/layer1/memory-write.js +0 -21
  108. package/packages/mcp-tools/dist/layer1/org-lookup.js +0 -47
  109. package/packages/mcp-tools/dist/layer1/project-get.js +0 -28
  110. package/packages/mcp-tools/dist/layer1/project-list.js +0 -20
  111. package/packages/mcp-tools/dist/layer1/report-daily.js +0 -68
  112. package/packages/mcp-tools/dist/layer1/task-get.js +0 -29
  113. package/packages/mcp-tools/dist/layer1/task-update.js +0 -34
  114. package/packages/mcp-tools/dist/layer2/franky/topic-checkpoint.js +0 -43
  115. package/packages/mcp-tools/dist/layer2/franky/topic-escalate.js +0 -19
  116. package/packages/mcp-tools/dist/layer2/loid/decision-log.js +0 -15
  117. package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +0 -15
  118. package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +0 -30
  119. package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +0 -12
  120. package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +0 -77
  121. package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +0 -18
  122. package/packages/mcp-tools/dist/layer2/loid/project-remove.js +0 -16
  123. package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +0 -33
  124. package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +0 -196
  125. package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +0 -38
  126. package/packages/mcp-tools/dist/layer2/loid/topic-close.js +0 -22
  127. package/packages/mcp-tools/dist/layer2/loid/topic-create.js +0 -56
  128. package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +0 -8
  129. package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +0 -7
  130. package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +0 -7
  131. package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +0 -15
  132. package/packages/mcp-tools/dist/layer2/loid/yor-status.js +0 -8
  133. package/packages/mcp-tools/dist/layer2/yor/task-block.js +0 -11
  134. package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +0 -35
  135. package/packages/mcp-tools/dist/layer2/yor/task-progress.js +0 -21
  136. package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +0 -192
  137. package/packages/mcp-tools/dist/layer3/adapters/types.js +0 -28
  138. package/packages/mcp-tools/dist/layer3/channel-receive.js +0 -11
  139. package/packages/mcp-tools/dist/layer3/channel-send.js +0 -91
  140. package/packages/mcp-tools/dist/layer3/file-upload.js +0 -44
  141. package/packages/mcp-tools/dist/registry.js +0 -871
  142. package/packages/mcp-tools/package.json +0 -13
  143. package/workspace/.claude/settings.local.json +0 -9
  144. package/workspace/.mcp.json +0 -12
  145. package/workspace/CHARTER.md +0 -76
  146. package/workspace/CLAUDE.md +0 -58
  147. package/workspace/PROTOCOL.md +0 -160
  148. package/workspace/TOOLS.md +0 -470
  149. package/workspace/audit/.gitkeep +0 -0
  150. package/workspace/franky/CLAUDE.md +0 -37
  151. package/workspace/franky/PLAYBOOK.md +0 -215
  152. package/workspace/franky/PROFILE.md +0 -80
  153. package/workspace/loid/CLAUDE.md +0 -12
  154. package/workspace/loid/PLAYBOOK.md +0 -198
  155. package/workspace/loid/PROFILE.md +0 -78
  156. package/workspace/memory/commitments/.gitkeep +0 -0
  157. package/workspace/memory/execution/.gitkeep +0 -0
  158. package/workspace/memory/people/.gitkeep +0 -0
  159. package/workspace/memory/projects/.gitkeep +0 -0
  160. package/workspace/memory/self/.gitkeep +0 -0
  161. package/workspace/reference/identity/.gitkeep +0 -0
  162. package/workspace/reference/org/escalation.yaml +0 -24
  163. package/workspace/reference/org/ownership.yaml +0 -28
  164. package/workspace/reports/.gitkeep +0 -0
  165. package/workspace/yor/CLAUDE.md +0 -22
  166. package/workspace/yor/PLAYBOOK.md +0 -73
  167. package/workspace/yor/PROFILE.md +0 -52
  168. package/workspace/yor/SELF-HEAL.md +0 -39
@@ -1,160 +0,0 @@
1
- import { readFile, readdir, writeFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { existsSync } from 'node:fs';
4
- import { execSync } from 'node:child_process';
5
- import { getTopic, getRecentMessages } from '@team-anya/db';
6
- /**
7
- * 为 Franky CC 实例重建上下文
8
- * 按 checkpoint 截断策略:所有 checkpoint 标题 + 最近 2 个详情 + 末个 checkpoint 后对话
9
- */
10
- export async function buildTopicContext(deps, topicId) {
11
- const topic = getTopic(deps.db, topicId);
12
- if (!topic)
13
- throw new Error(`专项 ${topicId} 不存在`);
14
- const topicDir = join(deps.workspacePath, 'franky', 'topics', topicId);
15
- const sections = [];
16
- // 1. Topic 元信息
17
- sections.push(`# 专项上下文:${topic.title} (${topic.id})`);
18
- sections.push('');
19
- sections.push('## 目标');
20
- sections.push(topic.description ?? '(未设定)');
21
- sections.push('');
22
- sections.push('## 通讯信息');
23
- if (topic.chat_id)
24
- sections.push(`- 群聊 ID:\`${topic.chat_id}\``);
25
- if (topic.root_message_id)
26
- sections.push(`- 话题根消息 ID:\`${topic.root_message_id}\``);
27
- if (topic.thread_id)
28
- sections.push(`- 话题 ID:\`${topic.thread_id}\`(仅供参考,channel.send 的 reply_to 请用根消息 ID)`);
29
- sections.push('');
30
- sections.push('## 项目信息');
31
- sections.push(`- 专项 ID:${topic.id}`);
32
- sections.push(`- 状态:${topic.status}`);
33
- if (topic.project_id)
34
- sections.push(`- 关联项目:${topic.project_id}`);
35
- if (topic.branch_name)
36
- sections.push(`- 分支:${topic.branch_name}`);
37
- sections.push('');
38
- // 1.5 代码工作区(worktree 信息)
39
- if (topic.project_id && topic.workspace_path) {
40
- try {
41
- const entries = await readdir(topic.workspace_path, { withFileTypes: true });
42
- const worktreeDirs = entries
43
- .filter(e => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'checkpoints')
44
- .map(e => e.name);
45
- if (worktreeDirs.length > 0) {
46
- sections.push('## 代码工作区');
47
- sections.push('');
48
- for (const dir of worktreeDirs) {
49
- const fullPath = join(topic.workspace_path, dir);
50
- const branchInfo = topic.branch_name ? `分支 \`${topic.branch_name}\`,` : '';
51
- sections.push(`- \`${dir}/\` → ${branchInfo}路径 \`${fullPath}\``);
52
- }
53
- sections.push('');
54
- sections.push('> 代码在上述 worktree 子目录中,git 操作请进入对应子目录执行。');
55
- sections.push('');
56
- }
57
- }
58
- catch {
59
- // workspace 不可读,跳过
60
- }
61
- }
62
- // 2. Checkpoints
63
- const checkpointsDir = join(topicDir, 'checkpoints');
64
- let checkpointFiles = [];
65
- if (existsSync(checkpointsDir)) {
66
- const files = await readdir(checkpointsDir);
67
- checkpointFiles = files.filter(f => f.match(/^\d{3}-.*\.md$/)).sort();
68
- }
69
- if (checkpointFiles.length > 0) {
70
- sections.push('## Checkpoint 概览');
71
- for (const file of checkpointFiles) {
72
- const num = file.split('-')[0];
73
- const name = file.replace(/^\d{3}-/, '').replace(/\.md$/, '');
74
- sections.push(`${parseInt(num, 10)}. ${name}`);
75
- }
76
- sections.push('');
77
- // 最近 2 个 checkpoint 的完整内容
78
- const recentCheckpoints = checkpointFiles.slice(-2);
79
- sections.push('## 最近 Checkpoint 详情');
80
- sections.push('');
81
- for (const file of recentCheckpoints) {
82
- try {
83
- const content = await readFile(join(checkpointsDir, file), 'utf-8');
84
- sections.push(content.trim());
85
- sections.push('');
86
- }
87
- catch {
88
- // 文件读取失败,跳过
89
- }
90
- }
91
- }
92
- // 3. Git log(如果有 worktree)
93
- const gitDir = join(topicDir);
94
- try {
95
- const gitLog = execSync('git log --oneline -10 2>/dev/null || true', {
96
- cwd: gitDir,
97
- encoding: 'utf-8',
98
- timeout: 5000,
99
- }).trim();
100
- if (gitLog) {
101
- sections.push('## 近期 Git 记录');
102
- sections.push('```');
103
- sections.push(gitLog);
104
- sections.push('```');
105
- sections.push('');
106
- }
107
- }
108
- catch {
109
- // 不是 git 仓库或命令失败,跳过
110
- }
111
- // 4. 最后一个 checkpoint 之后的对话(用 thread_id 所在的 chat_id + since 过滤)
112
- if (topic.chat_id) {
113
- try {
114
- // 查找最后一个 checkpoint 的时间戳,只拉取其后的消息
115
- let since;
116
- if (checkpointFiles.length > 0) {
117
- try {
118
- const lastCheckpointPath = join(checkpointsDir, checkpointFiles[checkpointFiles.length - 1]);
119
- const stat = await import('node:fs/promises').then(m => m.stat(lastCheckpointPath));
120
- since = stat.mtime.toISOString().replace(/\.\d{3}Z$/, 'Z');
121
- }
122
- catch {
123
- // stat 失败,不设 since 过滤
124
- }
125
- }
126
- const messages = getRecentMessages(deps.db, {
127
- chat_id: topic.chat_id,
128
- limit: 30,
129
- sort: 'asc',
130
- ...(since ? { since } : {}),
131
- });
132
- if (messages.length > 0) {
133
- sections.push('## 近期对话');
134
- sections.push('');
135
- for (const msg of messages) {
136
- const direction = msg.direction === 'outbound' ? 'Anya' : (msg.sender_name ?? msg.sender ?? '用户');
137
- sections.push(`**${direction}** (${msg.created_at}):`);
138
- // 截断过长的消息
139
- const content = msg.content.length > 500 ? msg.content.slice(0, 500) + '...' : msg.content;
140
- sections.push(content);
141
- sections.push('');
142
- }
143
- }
144
- }
145
- catch (err) {
146
- deps.logger?.error('[TopicContextBuilder] 查询对话历史失败:', err);
147
- }
148
- }
149
- return sections.join('\n');
150
- }
151
- /**
152
- * 生成并写入 context.md 文件
153
- */
154
- export async function writeTopicContext(deps, topicId) {
155
- const content = await buildTopicContext(deps, topicId);
156
- const contextPath = join(deps.workspacePath, 'franky', 'topics', topicId, 'context.md');
157
- await writeFile(contextPath, content, 'utf-8');
158
- return contextPath;
159
- }
160
- //# sourceMappingURL=context-builder.js.map
@@ -1,107 +0,0 @@
1
- import { createServer } from 'node:http';
2
- import { randomUUID } from 'node:crypto';
3
- import { Server } from '@modelcontextprotocol/sdk/server';
4
- import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
- import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
6
- import { zodToJsonSchema } from 'zod-to-json-schema';
7
- import { createToolRouter } from '@team-anya/mcp-tools';
8
- // ── MCP Server 创建(薄路由层) ──
9
- function createFrankyMcpServer(deps) {
10
- const logger = deps.logger ?? { info: console.log, error: console.error };
11
- const routerDeps = {
12
- db: deps.db,
13
- workspacePath: deps.workspacePath,
14
- currentTopicId: deps.topicId,
15
- replyToThreadId: deps.replyToThreadId,
16
- channelRegistry: deps.channelRegistry,
17
- onMessageSent: deps.onMessageSent,
18
- onTopicClosed: deps.onTopicClosed,
19
- onTopicEscalated: deps.onTopicEscalated,
20
- logger,
21
- };
22
- const router = createToolRouter('franky', routerDeps);
23
- const server = new Server({ name: 'franky-mcp', version: '1.0.0' }, { capabilities: { tools: {} } });
24
- server.setRequestHandler(ListToolsRequestSchema, async () => {
25
- const tools = router.tools.map(def => ({
26
- name: def.name,
27
- description: def.description,
28
- inputSchema: zodToJsonSchema(def.inputSchema),
29
- }));
30
- return { tools };
31
- });
32
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
33
- const { name, arguments: args } = request.params;
34
- return router.handleToolCall(name, args ?? {});
35
- });
36
- return server;
37
- }
38
- /**
39
- * 启动 Franky MCP server(薄路由层)
40
- *
41
- * Franky 可以使用 Layer 1 全部共享工具 + Layer 3 Franky 专属工具(channel.send 等)。
42
- * 不需要 Yor 的 deliver/block 工具。
43
- *
44
- * 所有工具实现来自 @team-anya/mcp-tools。
45
- */
46
- export async function startFrankyMcpServer(deps) {
47
- const sessions = new Map();
48
- const httpServer = createServer(async (req, res) => {
49
- const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
50
- if (url.pathname !== '/mcp') {
51
- res.writeHead(404);
52
- res.end('Not Found');
53
- return;
54
- }
55
- const sessionId = req.headers['mcp-session-id'];
56
- if (sessionId && sessions.has(sessionId)) {
57
- const { transport } = sessions.get(sessionId);
58
- await transport.handleRequest(req, res);
59
- return;
60
- }
61
- if (req.method === 'POST') {
62
- const transport = new StreamableHTTPServerTransport({
63
- sessionIdGenerator: () => randomUUID(),
64
- });
65
- const server = createFrankyMcpServer(deps);
66
- transport.onclose = () => {
67
- if (transport.sessionId) {
68
- sessions.delete(transport.sessionId);
69
- }
70
- };
71
- await server.connect(transport);
72
- await transport.handleRequest(req, res);
73
- if (transport.sessionId) {
74
- sessions.set(transport.sessionId, { server, transport });
75
- }
76
- return;
77
- }
78
- res.writeHead(400);
79
- res.end('Bad Request: No valid session');
80
- });
81
- await new Promise((resolve) => {
82
- httpServer.listen(0, '127.0.0.1', resolve);
83
- });
84
- const addr = httpServer.address();
85
- const port = typeof addr === 'object' && addr !== null ? addr.port : 0;
86
- const serverUrl = `http://127.0.0.1:${port}/mcp`;
87
- return {
88
- port,
89
- url: serverUrl,
90
- close: async () => {
91
- for (const { server, transport } of sessions.values()) {
92
- await transport.close();
93
- await server.close();
94
- }
95
- sessions.clear();
96
- await new Promise((resolve, reject) => {
97
- httpServer.close((err) => {
98
- if (err)
99
- reject(err);
100
- else
101
- resolve();
102
- });
103
- });
104
- },
105
- };
106
- }
107
- //# sourceMappingURL=franky-mcp-server.js.map