team-anya-cli 0.1.0

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 (163) hide show
  1. package/README.md +38 -0
  2. package/anya/prompts/execution-guides/git-delivery.md +38 -0
  3. package/anya/prompts/execution-guides/testing-and-self-heal.md +28 -0
  4. package/anya/prompts/protocols/brief-assembly.md +55 -0
  5. package/anya/prompts/protocols/report.md +175 -0
  6. package/anya/prompts/protocols/review.md +90 -0
  7. package/anya/prompts/task-claude-md.template.md +32 -0
  8. package/apps/server/dist/broker/cc-broker.js +257 -0
  9. package/apps/server/dist/cli.js +296 -0
  10. package/apps/server/dist/config.js +76 -0
  11. package/apps/server/dist/daemon.js +51 -0
  12. package/apps/server/dist/gateway/chat-sync.js +135 -0
  13. package/apps/server/dist/gateway/command-router.js +114 -0
  14. package/apps/server/dist/gateway/commands/cancel.js +32 -0
  15. package/apps/server/dist/gateway/commands/help.js +16 -0
  16. package/apps/server/dist/gateway/commands/index.js +26 -0
  17. package/apps/server/dist/gateway/commands/restart.js +34 -0
  18. package/apps/server/dist/gateway/commands/status.js +34 -0
  19. package/apps/server/dist/gateway/commands/tasks.js +33 -0
  20. package/apps/server/dist/gateway/feishu-sender.js +346 -0
  21. package/apps/server/dist/gateway/feishu-ws.js +254 -0
  22. package/apps/server/dist/gateway/http.js +994 -0
  23. package/apps/server/dist/gateway/media-downloader.js +149 -0
  24. package/apps/server/dist/gateway/message-events.js +10 -0
  25. package/apps/server/dist/gateway/message-intake.js +50 -0
  26. package/apps/server/dist/gateway/message-queue.js +104 -0
  27. package/apps/server/dist/gateway/session-reader.js +142 -0
  28. package/apps/server/dist/gateway/ws-push.js +115 -0
  29. package/apps/server/dist/loid/brain.js +104 -0
  30. package/apps/server/dist/loid/clarifier.js +162 -0
  31. package/apps/server/dist/loid/context-builder.js +413 -0
  32. package/apps/server/dist/loid/mcp-server.js +104 -0
  33. package/apps/server/dist/loid/memory-settler.js +189 -0
  34. package/apps/server/dist/loid/opportunity-manager.js +148 -0
  35. package/apps/server/dist/loid/profile-updater.js +179 -0
  36. package/apps/server/dist/loid/reporter.js +148 -0
  37. package/apps/server/dist/loid/schemas.js +117 -0
  38. package/apps/server/dist/loid/self-calibrator.js +314 -0
  39. package/apps/server/dist/loid/session-manager.js +217 -0
  40. package/apps/server/dist/loid/session.js +271 -0
  41. package/apps/server/dist/loid/worktree-manager.js +191 -0
  42. package/apps/server/dist/main.js +337 -0
  43. package/apps/server/dist/tracing/index.js +2 -0
  44. package/apps/server/dist/tracing/trace-context.js +92 -0
  45. package/apps/server/dist/types/message.js +2 -0
  46. package/apps/server/dist/yor/yor-mcp-server.js +104 -0
  47. package/apps/server/dist/yor/yor-orchestrator.js +233 -0
  48. package/apps/web/dist/assets/index-CHIT0Dya.css +1 -0
  49. package/apps/web/dist/assets/index-CJzAjoVH.js +798 -0
  50. package/apps/web/dist/index.html +13 -0
  51. package/package.json +42 -0
  52. package/packages/cc-client/dist/claude-code-backend.js +664 -0
  53. package/packages/cc-client/dist/index.js +2 -0
  54. package/packages/cc-client/package.json +11 -0
  55. package/packages/core/dist/constants.js +59 -0
  56. package/packages/core/dist/errors.js +35 -0
  57. package/packages/core/dist/index.js +7 -0
  58. package/packages/core/dist/office-init.js +97 -0
  59. package/packages/core/dist/scope/checker.js +114 -0
  60. package/packages/core/dist/scope/defaults.js +40 -0
  61. package/packages/core/dist/scope/index.js +3 -0
  62. package/packages/core/dist/state-machine.js +85 -0
  63. package/packages/core/dist/types/audit.js +12 -0
  64. package/packages/core/dist/types/backend.js +2 -0
  65. package/packages/core/dist/types/commitment.js +17 -0
  66. package/packages/core/dist/types/communication.js +18 -0
  67. package/packages/core/dist/types/index.js +8 -0
  68. package/packages/core/dist/types/opportunity.js +27 -0
  69. package/packages/core/dist/types/org.js +26 -0
  70. package/packages/core/dist/types/task.js +46 -0
  71. package/packages/core/package.json +10 -0
  72. package/packages/db/dist/client.js +69 -0
  73. package/packages/db/dist/index.js +603 -0
  74. package/packages/db/dist/schema/audit-events.js +13 -0
  75. package/packages/db/dist/schema/cc-sessions.js +14 -0
  76. package/packages/db/dist/schema/chats.js +33 -0
  77. package/packages/db/dist/schema/commitments.js +18 -0
  78. package/packages/db/dist/schema/communication-events.js +14 -0
  79. package/packages/db/dist/schema/index.js +12 -0
  80. package/packages/db/dist/schema/message-log.js +20 -0
  81. package/packages/db/dist/schema/opportunities.js +23 -0
  82. package/packages/db/dist/schema/org.js +36 -0
  83. package/packages/db/dist/schema/projects.js +23 -0
  84. package/packages/db/dist/schema/tasks.js +46 -0
  85. package/packages/db/dist/schema/trace-spans.js +19 -0
  86. package/packages/db/package.json +12 -0
  87. package/packages/db/src/migrations/0000_simple_magneto.sql +148 -0
  88. package/packages/db/src/migrations/0001_nifty_morph.sql +42 -0
  89. package/packages/db/src/migrations/0002_common_joshua_kane.sql +20 -0
  90. package/packages/db/src/migrations/0003_add_cc_sessions.sql +13 -0
  91. package/packages/db/src/migrations/0004_jittery_triathlon.sql +1 -0
  92. package/packages/db/src/migrations/meta/0000_snapshot.json +987 -0
  93. package/packages/db/src/migrations/meta/0001_snapshot.json +1280 -0
  94. package/packages/db/src/migrations/meta/0002_snapshot.json +1417 -0
  95. package/packages/db/src/migrations/meta/0004_snapshot.json +1505 -0
  96. package/packages/db/src/migrations/meta/_journal.json +41 -0
  97. package/packages/mcp-tools/dist/index.js +41 -0
  98. package/packages/mcp-tools/dist/layer1/audit-append.js +38 -0
  99. package/packages/mcp-tools/dist/layer1/audit-query.js +51 -0
  100. package/packages/mcp-tools/dist/layer1/memory-brief.js +168 -0
  101. package/packages/mcp-tools/dist/layer1/memory-context.js +124 -0
  102. package/packages/mcp-tools/dist/layer1/memory-digest.js +126 -0
  103. package/packages/mcp-tools/dist/layer1/memory-forget.js +108 -0
  104. package/packages/mcp-tools/dist/layer1/memory-learn.js +63 -0
  105. package/packages/mcp-tools/dist/layer1/memory-recall.js +287 -0
  106. package/packages/mcp-tools/dist/layer1/memory-reflect.js +80 -0
  107. package/packages/mcp-tools/dist/layer1/memory-remember.js +119 -0
  108. package/packages/mcp-tools/dist/layer1/memory-search.js +263 -0
  109. package/packages/mcp-tools/dist/layer1/memory-write.js +21 -0
  110. package/packages/mcp-tools/dist/layer1/org-lookup.js +47 -0
  111. package/packages/mcp-tools/dist/layer1/project-get.js +28 -0
  112. package/packages/mcp-tools/dist/layer1/project-list.js +20 -0
  113. package/packages/mcp-tools/dist/layer1/report-daily.js +68 -0
  114. package/packages/mcp-tools/dist/layer1/task-get.js +29 -0
  115. package/packages/mcp-tools/dist/layer1/task-update.js +34 -0
  116. package/packages/mcp-tools/dist/layer2/loid/decision-log.js +15 -0
  117. package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +15 -0
  118. package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +30 -0
  119. package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +12 -0
  120. package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +77 -0
  121. package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +18 -0
  122. package/packages/mcp-tools/dist/layer2/loid/project-remove.js +16 -0
  123. package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +33 -0
  124. package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +177 -0
  125. package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +38 -0
  126. package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +8 -0
  127. package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +7 -0
  128. package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +7 -0
  129. package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +15 -0
  130. package/packages/mcp-tools/dist/layer2/loid/yor-status.js +8 -0
  131. package/packages/mcp-tools/dist/layer2/yor/task-block.js +11 -0
  132. package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +35 -0
  133. package/packages/mcp-tools/dist/layer2/yor/task-progress.js +21 -0
  134. package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +191 -0
  135. package/packages/mcp-tools/dist/layer3/adapters/types.js +28 -0
  136. package/packages/mcp-tools/dist/layer3/channel-receive.js +11 -0
  137. package/packages/mcp-tools/dist/layer3/channel-send.js +90 -0
  138. package/packages/mcp-tools/dist/layer3/file-upload.js +44 -0
  139. package/packages/mcp-tools/dist/registry.js +779 -0
  140. package/packages/mcp-tools/package.json +13 -0
  141. package/workspace/.claude/settings.local.json +9 -0
  142. package/workspace/.mcp.json +12 -0
  143. package/workspace/CHARTER.md +73 -0
  144. package/workspace/CLAUDE.md +49 -0
  145. package/workspace/PROTOCOL.md +126 -0
  146. package/workspace/TOOLS.md +464 -0
  147. package/workspace/audit/.gitkeep +0 -0
  148. package/workspace/loid/CLAUDE.md +12 -0
  149. package/workspace/loid/PLAYBOOK.md +198 -0
  150. package/workspace/loid/PROFILE.md +78 -0
  151. package/workspace/memory/commitments/.gitkeep +0 -0
  152. package/workspace/memory/execution/.gitkeep +0 -0
  153. package/workspace/memory/people/.gitkeep +0 -0
  154. package/workspace/memory/projects/.gitkeep +0 -0
  155. package/workspace/memory/self/.gitkeep +0 -0
  156. package/workspace/reference/identity/.gitkeep +0 -0
  157. package/workspace/reference/org/escalation.yaml +24 -0
  158. package/workspace/reference/org/ownership.yaml +28 -0
  159. package/workspace/reports/.gitkeep +0 -0
  160. package/workspace/yor/CLAUDE.md +22 -0
  161. package/workspace/yor/PLAYBOOK.md +73 -0
  162. package/workspace/yor/PROFILE.md +52 -0
  163. package/workspace/yor/SELF-HEAL.md +39 -0
@@ -0,0 +1,90 @@
1
+ import { insertAuditEvent, insertMessageLog } from '@team-anya/db';
2
+ /** 默认通道(当前只支持飞书) */
3
+ const DEFAULT_SCHEME = 'feishu';
4
+ /**
5
+ * 向飞书群发消息
6
+ *
7
+ * target 直接填群聊 ID(如 oc_xxx)。
8
+ * 支持发送文件、@ 用户和回复消息。
9
+ */
10
+ export async function channelSend(deps, input) {
11
+ const { db, channelRegistry, logger } = deps;
12
+ const scheme = DEFAULT_SCHEME;
13
+ const chatTarget = input.target;
14
+ const adapter = channelRegistry.get(scheme);
15
+ if (!adapter) {
16
+ const error = `通道 ${scheme} 未注册(已注册: ${channelRegistry.getSchemes().join(', ')})`;
17
+ logger?.error(`[anya:pipeline] channel.send: ${error}`);
18
+ return { sent: false, error };
19
+ }
20
+ const sendOptions = {
21
+ replyTo: input.reply_to,
22
+ mentions: input.mentions,
23
+ };
24
+ try {
25
+ let result;
26
+ if (input.file) {
27
+ if (!adapter.sendFile) {
28
+ const error = `通道 ${scheme} 不支持发送文件`;
29
+ logger?.error(`[anya:pipeline] channel.send: ${error}`);
30
+ return { sent: false, error };
31
+ }
32
+ result = await adapter.sendFile(chatTarget, {
33
+ filePath: input.file.file_path,
34
+ fileName: input.file.file_name,
35
+ fileType: input.file.file_type,
36
+ duration: input.file.duration,
37
+ }, input.message, sendOptions);
38
+ }
39
+ else {
40
+ result = await adapter.send(chatTarget, input.message, sendOptions);
41
+ }
42
+ // 记录出站消息
43
+ try {
44
+ insertMessageLog(db, {
45
+ direction: 'outbound',
46
+ source_type: scheme,
47
+ source_ref: result.id,
48
+ sender: 'anya',
49
+ receiver: chatTarget,
50
+ chat_id: chatTarget,
51
+ chat_type: 'group',
52
+ content: input.file ? `[文件] ${input.file.file_name ?? input.file.file_path} ${input.message}` : input.message,
53
+ message_type: 'message',
54
+ related_task_id: input.task_id ?? null,
55
+ });
56
+ }
57
+ catch (err) {
58
+ logger?.error('[anya:pipeline] channel.send: 记录 message_log 失败:', err);
59
+ }
60
+ // 审计日志
61
+ insertAuditEvent(db, {
62
+ event_type: 'channel_send',
63
+ actor: 'loid',
64
+ task_id: input.task_id ?? undefined,
65
+ summary: `通过 ${scheme} 发消息: ${input.message.slice(0, 100)}`,
66
+ detail: JSON.stringify({
67
+ target: chatTarget,
68
+ has_file: !!input.file,
69
+ has_mentions: !!input.mentions?.length,
70
+ reply_to: input.reply_to ?? null,
71
+ sent: true,
72
+ }),
73
+ });
74
+ deps.onMessageSent?.(chatTarget);
75
+ logger?.info(`[anya:pipeline] [Loid] channel.send (${scheme}${input.file ? ', file' : ''}): "${input.message.slice(0, 80)}"`);
76
+ return { sent: true, message_id: result.id };
77
+ }
78
+ catch (err) {
79
+ logger?.error(`[anya:pipeline] channel.send 失败:`, err);
80
+ insertAuditEvent(db, {
81
+ event_type: 'channel_send_failed',
82
+ actor: 'loid',
83
+ task_id: input.task_id ?? undefined,
84
+ summary: `通道发送失败: ${String(err)}`,
85
+ detail: JSON.stringify({ target: chatTarget, error: String(err) }),
86
+ });
87
+ return { sent: false, error: String(err) };
88
+ }
89
+ }
90
+ //# sourceMappingURL=channel-send.js.map
@@ -0,0 +1,44 @@
1
+ import { insertAuditEvent } from '@team-anya/db';
2
+ /**
3
+ * file.upload - 通用文件上传
4
+ *
5
+ * 与通道无关。当前使用本地文件复制实现。
6
+ * 上传到 $ANYA_HOME/uploads/ 目录,返回本地路径作为 URL。
7
+ */
8
+ export async function fileUpload(deps, input) {
9
+ const fs = await import('node:fs');
10
+ const path = await import('node:path');
11
+ const srcPath = input.file_path;
12
+ const fileName = input.file_name || path.basename(srcPath);
13
+ // 检查源文件是否存在
14
+ if (!fs.existsSync(srcPath)) {
15
+ throw new Error(`文件不存在: ${srcPath}`);
16
+ }
17
+ const stat = fs.statSync(srcPath);
18
+ if (!stat.isFile()) {
19
+ throw new Error(`路径不是文件: ${srcPath}`);
20
+ }
21
+ // 确保上传目录存在
22
+ fs.mkdirSync(deps.uploadDir, { recursive: true });
23
+ // 生成唯一文件名避免冲突
24
+ const timestamp = Date.now();
25
+ const uniqueName = `${timestamp}-${fileName}`;
26
+ const destPath = path.join(deps.uploadDir, uniqueName);
27
+ // 复制文件
28
+ fs.copyFileSync(srcPath, destPath);
29
+ const url = destPath; // 本地路径即 URL
30
+ deps.logger?.info(`[anya:pipeline] file.upload: ${fileName} (${stat.size} bytes) → ${destPath}`);
31
+ // 审计日志
32
+ insertAuditEvent(deps.db, {
33
+ event_type: 'file_upload',
34
+ actor: 'loid',
35
+ summary: `上传文件: ${fileName} (${stat.size} bytes)`,
36
+ detail: JSON.stringify({ src: srcPath, dest: destPath, size: stat.size }),
37
+ });
38
+ return {
39
+ url,
40
+ file_name: fileName,
41
+ file_size: stat.size,
42
+ };
43
+ }
44
+ //# sourceMappingURL=file-upload.js.map