team-anya 0.2.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 (145) hide show
  1. package/README.md +38 -0
  2. package/apps/server/dist/broker/cc-broker.js +267 -0
  3. package/apps/server/dist/cli.js +296 -0
  4. package/apps/server/dist/config.js +78 -0
  5. package/apps/server/dist/daemon.js +51 -0
  6. package/apps/server/dist/franky/context-builder.js +161 -0
  7. package/apps/server/dist/franky/franky-mcp-server.js +110 -0
  8. package/apps/server/dist/franky/franky-orchestrator.js +629 -0
  9. package/apps/server/dist/franky/index.js +5 -0
  10. package/apps/server/dist/franky/topic-router.js +16 -0
  11. package/apps/server/dist/gateway/chat-sync.js +135 -0
  12. package/apps/server/dist/gateway/command-router.js +116 -0
  13. package/apps/server/dist/gateway/commands/cancel.js +32 -0
  14. package/apps/server/dist/gateway/commands/help.js +16 -0
  15. package/apps/server/dist/gateway/commands/index.js +26 -0
  16. package/apps/server/dist/gateway/commands/restart.js +43 -0
  17. package/apps/server/dist/gateway/commands/status.js +34 -0
  18. package/apps/server/dist/gateway/commands/tasks.js +33 -0
  19. package/apps/server/dist/gateway/feishu-sender.js +508 -0
  20. package/apps/server/dist/gateway/feishu-ws.js +353 -0
  21. package/apps/server/dist/gateway/health-monitor.js +154 -0
  22. package/apps/server/dist/gateway/http.js +1064 -0
  23. package/apps/server/dist/gateway/media-downloader.js +182 -0
  24. package/apps/server/dist/gateway/message-events.js +10 -0
  25. package/apps/server/dist/gateway/message-intake.js +72 -0
  26. package/apps/server/dist/gateway/message-queue.js +118 -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 +121 -0
  30. package/apps/server/dist/loid/clarifier.js +162 -0
  31. package/apps/server/dist/loid/context-builder.js +462 -0
  32. package/apps/server/dist/loid/mcp-server.js +119 -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/project-registry.js +192 -0
  37. package/apps/server/dist/loid/reporter.js +148 -0
  38. package/apps/server/dist/loid/schemas.js +117 -0
  39. package/apps/server/dist/loid/self-calibrator.js +314 -0
  40. package/apps/server/dist/loid/session-manager.js +472 -0
  41. package/apps/server/dist/loid/session.js +276 -0
  42. package/apps/server/dist/main.js +528 -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 +107 -0
  47. package/apps/server/dist/yor/yor-orchestrator.js +248 -0
  48. package/apps/web/dist/assets/index-BiiEB0qZ.css +1 -0
  49. package/apps/web/dist/assets/index-Dnb9LGZd.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 +792 -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 +60 -0
  56. package/packages/core/dist/errors.js +35 -0
  57. package/packages/core/dist/index.js +9 -0
  58. package/packages/core/dist/office-init.js +190 -0
  59. package/packages/core/dist/repo-cache.js +70 -0
  60. package/packages/core/dist/scope/checker.js +114 -0
  61. package/packages/core/dist/scope/defaults.js +55 -0
  62. package/packages/core/dist/scope/index.js +3 -0
  63. package/packages/core/dist/state-machine.js +86 -0
  64. package/packages/core/dist/types/audit.js +12 -0
  65. package/packages/core/dist/types/backend.js +2 -0
  66. package/packages/core/dist/types/commitment.js +17 -0
  67. package/packages/core/dist/types/communication.js +18 -0
  68. package/packages/core/dist/types/index.js +9 -0
  69. package/packages/core/dist/types/opportunity.js +27 -0
  70. package/packages/core/dist/types/org.js +26 -0
  71. package/packages/core/dist/types/task.js +46 -0
  72. package/packages/core/dist/types/workspace.js +39 -0
  73. package/packages/core/dist/workspace-manager.js +314 -0
  74. package/packages/core/package.json +10 -0
  75. package/packages/db/dist/client.js +69 -0
  76. package/packages/db/dist/index.js +756 -0
  77. package/packages/db/dist/schema/audit-events.js +13 -0
  78. package/packages/db/dist/schema/cc-sessions.js +14 -0
  79. package/packages/db/dist/schema/chats.js +35 -0
  80. package/packages/db/dist/schema/commitments.js +18 -0
  81. package/packages/db/dist/schema/communication-events.js +14 -0
  82. package/packages/db/dist/schema/index.js +14 -0
  83. package/packages/db/dist/schema/message-log.js +20 -0
  84. package/packages/db/dist/schema/opportunities.js +23 -0
  85. package/packages/db/dist/schema/org.js +36 -0
  86. package/packages/db/dist/schema/projects.js +23 -0
  87. package/packages/db/dist/schema/tasks.js +51 -0
  88. package/packages/db/dist/schema/topics.js +22 -0
  89. package/packages/db/dist/schema/trace-spans.js +19 -0
  90. package/packages/db/dist/schema/workspaces.js +15 -0
  91. package/packages/db/package.json +12 -0
  92. package/packages/db/src/migrations/0000_baseline.sql +251 -0
  93. package/packages/db/src/migrations/0001_workspaces.sql +19 -0
  94. package/packages/db/src/migrations/0002_workspace_parent.sql +1 -0
  95. package/packages/db/src/migrations/0003_chat_context.sql +3 -0
  96. package/packages/db/src/migrations/meta/_journal.json +34 -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/franky/topic-checkpoint.js +43 -0
  117. package/packages/mcp-tools/dist/layer2/franky/topic-escalate.js +19 -0
  118. package/packages/mcp-tools/dist/layer2/loid/decision-log.js +15 -0
  119. package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +15 -0
  120. package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +30 -0
  121. package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +12 -0
  122. package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +77 -0
  123. package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +18 -0
  124. package/packages/mcp-tools/dist/layer2/loid/project-remove.js +16 -0
  125. package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +33 -0
  126. package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +206 -0
  127. package/packages/mcp-tools/dist/layer2/loid/task-escalate-to-topic.js +170 -0
  128. package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +45 -0
  129. package/packages/mcp-tools/dist/layer2/loid/topic-close.js +22 -0
  130. package/packages/mcp-tools/dist/layer2/loid/topic-create.js +60 -0
  131. package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +8 -0
  132. package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +7 -0
  133. package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +7 -0
  134. package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +28 -0
  135. package/packages/mcp-tools/dist/layer2/loid/yor-status.js +8 -0
  136. package/packages/mcp-tools/dist/layer2/yor/task-block.js +11 -0
  137. package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +35 -0
  138. package/packages/mcp-tools/dist/layer2/yor/task-progress.js +21 -0
  139. package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +203 -0
  140. package/packages/mcp-tools/dist/layer3/adapters/types.js +28 -0
  141. package/packages/mcp-tools/dist/layer3/channel-receive.js +11 -0
  142. package/packages/mcp-tools/dist/layer3/channel-send.js +75 -0
  143. package/packages/mcp-tools/dist/layer3/file-upload.js +44 -0
  144. package/packages/mcp-tools/dist/registry.js +911 -0
  145. package/packages/mcp-tools/package.json +13 -0
@@ -0,0 +1,13 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const auditEvents = sqliteTable('audit_events', {
4
+ id: integer('id').primaryKey({ autoIncrement: true }),
5
+ event_type: text('event_type').notNull(),
6
+ actor: text('actor').notNull(),
7
+ task_id: text('task_id'),
8
+ summary: text('summary').notNull(),
9
+ detail: text('detail'), // JSON 字符串
10
+ file_ref: text('file_ref'),
11
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
12
+ });
13
+ //# sourceMappingURL=audit-events.js.map
@@ -0,0 +1,14 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const ccSessions = sqliteTable('cc_sessions', {
4
+ id: integer('id').primaryKey({ autoIncrement: true }),
5
+ session_id: text('session_id').notNull().unique(),
6
+ role: text('role').notNull(), // 'loid' | 'yor'
7
+ instance_id: text('instance_id'),
8
+ task_id: text('task_id'),
9
+ chat_id: text('chat_id'),
10
+ project_path: text('project_path'),
11
+ started_at: text('started_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
12
+ ended_at: text('ended_at'),
13
+ });
14
+ //# sourceMappingURL=cc-sessions.js.map
@@ -0,0 +1,35 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ import { orgMembers } from './org.js';
4
+ // chats 表 — 群聊实体
5
+ export const chats = sqliteTable('chats', {
6
+ chat_id: text('chat_id').primaryKey(), // 飞书 oc_xxx
7
+ platform: text('platform').notNull().default('feishu'),
8
+ name: text('name'),
9
+ description: text('description'),
10
+ avatar: text('avatar'), // 群头像 URL
11
+ owner_id: text('owner_id'), // 群主 open_id
12
+ chat_mode: text('chat_mode'), // group / topic
13
+ chat_type: text('chat_type'), // private / public
14
+ chat_tag: text('chat_tag'), // inner / tenant / department / meeting
15
+ chat_status: text('chat_status').default('normal'), // normal / dissolved
16
+ external: integer('external').default(0), // 是否外部群 0/1
17
+ tenant_key: text('tenant_key'),
18
+ user_count: integer('user_count'),
19
+ bot_count: integer('bot_count'),
20
+ default_project_id: text('default_project_id'), // 绑定的默认项目 ID
21
+ custom_context: text('custom_context'), // 自定义上下文(自由文本)
22
+ metadata: text('metadata'), // JSON 扩展
23
+ first_seen_at: text('first_seen_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
24
+ last_synced_at: text('last_synced_at'),
25
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
26
+ });
27
+ // chat_members 关联表 — 群 ↔ 人 多对多
28
+ export const chatMembers = sqliteTable('chat_members', {
29
+ id: integer('id').primaryKey({ autoIncrement: true }),
30
+ chat_id: text('chat_id').notNull().references(() => chats.chat_id),
31
+ member_id: text('member_id').notNull().references(() => orgMembers.member_id),
32
+ role: text('role').default('member'), // owner / admin / member
33
+ synced_at: text('synced_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
34
+ });
35
+ //# sourceMappingURL=chats.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @deprecated 此模块已废弃,改为 Agent 自主判断/使用 memory 系统。
3
+ * 保留此文件仅为兼容历史数据,新代码请勿使用。
4
+ */
5
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
6
+ import { sql } from 'drizzle-orm';
7
+ import { tasks } from './tasks.js';
8
+ export const commitments = sqliteTable('commitments', {
9
+ id: integer('id').primaryKey({ autoIncrement: true }),
10
+ task_id: text('task_id').notNull().references(() => tasks.task_id),
11
+ promised_to: text('promised_to').notNull(),
12
+ promise: text('promise').notNull(),
13
+ deadline: text('deadline'),
14
+ status: text('status').notNull().default('active'),
15
+ break_reason: text('break_reason'),
16
+ promised_at: text('promised_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
17
+ });
18
+ //# sourceMappingURL=commitments.js.map
@@ -0,0 +1,14 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const communicationEvents = sqliteTable('communication_events', {
4
+ id: integer('id').primaryKey({ autoIncrement: true }),
5
+ source_type: text('source_type').notNull(),
6
+ source_ref: text('source_ref'),
7
+ intent_level: integer('intent_level').notNull(),
8
+ sender: text('sender'),
9
+ summary: text('summary').notNull(),
10
+ raw_content_path: text('raw_content_path'),
11
+ opportunity_id: text('opportunity_id'),
12
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
13
+ });
14
+ //# sourceMappingURL=communication-events.js.map
@@ -0,0 +1,14 @@
1
+ export * from './tasks.js';
2
+ export * from './commitments.js';
3
+ export * from './opportunities.js';
4
+ export * from './audit-events.js';
5
+ export * from './communication-events.js';
6
+ export * from './message-log.js';
7
+ export * from './org.js';
8
+ export * from './chats.js';
9
+ export * from './trace-spans.js';
10
+ export * from './projects.js';
11
+ export * from './cc-sessions.js';
12
+ export * from './topics.js';
13
+ export * from './workspaces.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,20 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const messageLog = sqliteTable('message_log', {
4
+ id: integer('id').primaryKey({ autoIncrement: true }),
5
+ direction: text('direction').notNull(), // 'inbound' | 'outbound'
6
+ source_type: text('source_type').notNull(), // 'feishu'
7
+ source_ref: text('source_ref'), // 飞书 message_id
8
+ sender: text('sender'),
9
+ receiver: text('receiver'),
10
+ chat_id: text('chat_id'), // 群聊 ID 或私聊对方 ID
11
+ chat_type: text('chat_type'), // 'group' | 'p2p'
12
+ content: text('content').notNull(),
13
+ message_type: text('message_type'), // 'text' | 'card' | 'clarification' | 'alert' | 'report' | 'task_done'
14
+ intent_level: integer('intent_level'),
15
+ related_task_id: text('related_task_id'),
16
+ metadata: text('metadata'), // JSON
17
+ trace_id: text('trace_id'),
18
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
19
+ });
20
+ //# sourceMappingURL=message-log.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @deprecated 此模块已废弃,改为 Agent 自主判断/使用 memory 系统。
3
+ * 保留此文件仅为兼容历史数据,新代码请勿使用。
4
+ */
5
+ import { sqliteTable, text, real } from 'drizzle-orm/sqlite-core';
6
+ import { sql } from 'drizzle-orm';
7
+ import { tasks } from './tasks.js';
8
+ export const opportunities = sqliteTable('opportunities', {
9
+ id: text('id').primaryKey(),
10
+ status: text('status').notNull().default('detected'),
11
+ source_ref: text('source_ref'),
12
+ summary: text('summary').notNull(),
13
+ // 评分
14
+ score_impact: real('score_impact'),
15
+ score_urgency: real('score_urgency'),
16
+ score_feasibility: real('score_feasibility'),
17
+ score_permission: real('score_permission'),
18
+ total_score: real('total_score'),
19
+ converted_task_id: text('converted_task_id').references(() => tasks.task_id),
20
+ detected_at: text('detected_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
21
+ claimed_at: text('claimed_at'),
22
+ });
23
+ //# sourceMappingURL=opportunities.js.map
@@ -0,0 +1,36 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const orgMembers = sqliteTable('org_members', {
4
+ member_id: text('member_id').primaryKey(),
5
+ name: text('name').notNull(),
6
+ role: text('role'),
7
+ team: text('team'),
8
+ timezone: text('timezone'),
9
+ profile_path: text('profile_path'),
10
+ response_pattern: text('response_pattern'),
11
+ platform: text('platform').default('feishu'),
12
+ union_id: text('union_id'),
13
+ user_id: text('user_id'), // 飞书租户内 ID
14
+ en_name: text('en_name'),
15
+ email: text('email'),
16
+ employee_no: text('employee_no'),
17
+ avatar_url: text('avatar_url'),
18
+ metadata: text('metadata'), // JSON 扩展
19
+ last_synced_at: text('last_synced_at'),
20
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
21
+ });
22
+ export const orgOwnership = sqliteTable('org_ownership', {
23
+ id: integer('id').primaryKey({ autoIncrement: true }),
24
+ scope: text('scope').notNull(),
25
+ target: text('target').notNull(),
26
+ member_id: text('member_id').notNull().references(() => orgMembers.member_id),
27
+ role: text('role').notNull().default('owner'),
28
+ });
29
+ export const orgEscalationRules = sqliteTable('org_escalation_rules', {
30
+ id: integer('id').primaryKey({ autoIncrement: true }),
31
+ scope: text('scope').notNull().default('global'),
32
+ after_minutes: integer('after_minutes').notNull(),
33
+ action: text('action').notNull(),
34
+ targets: text('targets').notNull(), // JSON 数组字符串
35
+ });
36
+ //# sourceMappingURL=org.js.map
@@ -0,0 +1,23 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const projects = sqliteTable('projects', {
4
+ project_id: text('project_id').primaryKey(),
5
+ name: text('name').notNull(),
6
+ description: text('description'),
7
+ platform: text('platform').default('github'), // github | gitlab | local
8
+ claude_md: text('claude_md'),
9
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
10
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
11
+ deleted_at: text('deleted_at'), // null = 活跃,有值 = 已软删除
12
+ });
13
+ // project_repos 关联表 — 项目 ↔ 仓库 一对多
14
+ export const projectRepos = sqliteTable('project_repos', {
15
+ id: integer('id').primaryKey({ autoIncrement: true }),
16
+ project_id: text('project_id').notNull().references(() => projects.project_id),
17
+ name: text('name').notNull(), // 仓库名,也是子目录名
18
+ git_url: text('git_url'), // 远程仓库地址,用于自动 clone
19
+ repo_path: text('repo_path'), // 主仓库绝对路径
20
+ default_branch: text('default_branch').default('main'),
21
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
22
+ });
23
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1,51 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const tasks = sqliteTable('tasks', {
4
+ task_id: text('task_id').primaryKey(),
5
+ title: text('title').notNull(),
6
+ status: text('status').notNull().default('NEW'),
7
+ // 来源
8
+ source_type: text('source_type').notNull(),
9
+ source_ref: text('source_ref'),
10
+ created_by: text('created_by'), // 任务创建者(人名或 'loid')
11
+ source_chat_id: text('source_chat_id'), // 触发任务的聊天 ID
12
+ // 需求定义
13
+ objective: text('objective'),
14
+ acceptance_criteria: text('acceptance_criteria'), // JSON 数组字符串
15
+ context: text('context'),
16
+ // 执行信息
17
+ project_id: text('project_id'),
18
+ assignee: text('assignee'),
19
+ branch: text('branch'),
20
+ pr_url: text('pr_url'),
21
+ // 重试与阻塞
22
+ retry_count: integer('retry_count').notNull().default(0),
23
+ max_retries: integer('max_retries').notNull().default(3),
24
+ blocked_reason: text('blocked_reason'),
25
+ blocked_since: text('blocked_since'),
26
+ // 执行指引
27
+ execution_guidance: text('execution_guidance'),
28
+ // CC 会话
29
+ cc_session_id: text('cc_session_id'),
30
+ // 文件路径
31
+ workspace_path: text('workspace_path'),
32
+ // 话题关联(可选,用于回溯关联)
33
+ topic_id: text('topic_id'),
34
+ // 工作区关联
35
+ workspace_id: text('workspace_id'),
36
+ escalated_to_topic_id: text('escalated_to_topic_id'),
37
+ // 时间戳
38
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
39
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
40
+ });
41
+ export const taskClarifications = sqliteTable('task_clarifications', {
42
+ id: integer('id').primaryKey({ autoIncrement: true }),
43
+ task_id: text('task_id').notNull().references(() => tasks.task_id),
44
+ question: text('question').notNull(),
45
+ answer: text('answer'),
46
+ asked_by: text('asked_by').notNull().default('loid'),
47
+ answered_by: text('answered_by'),
48
+ asked_at: text('asked_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
49
+ answered_at: text('answered_at'),
50
+ });
51
+ //# sourceMappingURL=tasks.js.map
@@ -0,0 +1,22 @@
1
+ import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ import { projects } from './projects.js';
4
+ export const topics = sqliteTable('topics', {
5
+ id: text('id').primaryKey(),
6
+ project_id: text('project_id').references(() => projects.project_id),
7
+ title: text('title').notNull(),
8
+ description: text('description'),
9
+ status: text('status').notNull().default('active'),
10
+ thread_id: text('thread_id'),
11
+ root_message_id: text('root_message_id'),
12
+ chat_id: text('chat_id'),
13
+ workspace_path: text('workspace_path'),
14
+ workspace_id: text('workspace_id'),
15
+ escalated_from_task_id: text('escalated_from_task_id'),
16
+ branch_name: text('branch_name'),
17
+ created_by: text('created_by'),
18
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
19
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
20
+ closed_at: text('closed_at'),
21
+ });
22
+ //# sourceMappingURL=topics.js.map
@@ -0,0 +1,19 @@
1
+ import { sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const traceSpans = sqliteTable('trace_spans', {
4
+ id: integer('id').primaryKey({ autoIncrement: true }),
5
+ trace_id: text('trace_id').notNull(),
6
+ span_id: text('span_id').notNull(),
7
+ parent_span_id: text('parent_span_id'),
8
+ operation: text('operation').notNull(),
9
+ status: text('status').notNull().default('in_progress'), // 'in_progress' | 'success' | 'error'
10
+ started_at: text('started_at').notNull(),
11
+ ended_at: text('ended_at'),
12
+ duration_ms: real('duration_ms'),
13
+ input: text('input'), // JSON
14
+ output: text('output'), // JSON
15
+ error: text('error'),
16
+ metadata: text('metadata'), // JSON
17
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
18
+ });
19
+ //# sourceMappingURL=trace-spans.js.map
@@ -0,0 +1,15 @@
1
+ import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
2
+ import { sql } from 'drizzle-orm';
3
+ export const workspaces = sqliteTable('workspaces', {
4
+ id: text('id').primaryKey(),
5
+ path: text('path').notNull(),
6
+ project_id: text('project_id'),
7
+ current_role: text('current_role').notNull(),
8
+ current_owner_type: text('current_owner_type').notNull(),
9
+ current_owner_id: text('current_owner_id').notNull(),
10
+ parent_workspace_id: text('parent_workspace_id'),
11
+ status: text('status').notNull().default('active'),
12
+ created_at: text('created_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
13
+ updated_at: text('updated_at').notNull().default(sql `(strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`),
14
+ });
15
+ //# sourceMappingURL=workspaces.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@team-anya/db",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "@team-anya/core": "file:../core",
9
+ "better-sqlite3": "^11.8.0",
10
+ "drizzle-orm": "^0.38.0"
11
+ }
12
+ }
@@ -0,0 +1,251 @@
1
+ -- Baseline: squash of migrations 0000-0007
2
+ -- Generated: 2026-02-26
3
+ CREATE TABLE IF NOT EXISTS `tasks` (
4
+ `task_id` text PRIMARY KEY NOT NULL,
5
+ `title` text NOT NULL,
6
+ `status` text DEFAULT 'NEW' NOT NULL,
7
+ `source_type` text NOT NULL,
8
+ `source_ref` text,
9
+ `created_by` text,
10
+ `source_chat_id` text,
11
+ `objective` text,
12
+ `acceptance_criteria` text,
13
+ `context` text,
14
+ `project_id` text,
15
+ `assignee` text,
16
+ `branch` text,
17
+ `pr_url` text,
18
+ `retry_count` integer DEFAULT 0 NOT NULL,
19
+ `max_retries` integer DEFAULT 3 NOT NULL,
20
+ `blocked_reason` text,
21
+ `blocked_since` text,
22
+ `execution_guidance` text,
23
+ `cc_session_id` text,
24
+ `workspace_path` text,
25
+ `topic_id` text REFERENCES `topics`(`id`),
26
+ `created_at` text DEFAULT (datetime('now')) NOT NULL,
27
+ `updated_at` text DEFAULT (datetime('now')) NOT NULL
28
+ );
29
+ --> statement-breakpoint
30
+ CREATE TABLE IF NOT EXISTS `task_clarifications` (
31
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
32
+ `task_id` text NOT NULL,
33
+ `question` text NOT NULL,
34
+ `answer` text,
35
+ `asked_by` text DEFAULT 'loid' NOT NULL,
36
+ `answered_by` text,
37
+ `asked_at` text DEFAULT (datetime('now')) NOT NULL,
38
+ `answered_at` text,
39
+ FOREIGN KEY (`task_id`) REFERENCES `tasks`(`task_id`) ON UPDATE no action ON DELETE no action
40
+ );
41
+ --> statement-breakpoint
42
+ CREATE TABLE IF NOT EXISTS `commitments` (
43
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
44
+ `task_id` text NOT NULL,
45
+ `promised_to` text NOT NULL,
46
+ `promise` text NOT NULL,
47
+ `deadline` text,
48
+ `status` text DEFAULT 'active' NOT NULL,
49
+ `break_reason` text,
50
+ `promised_at` text DEFAULT (datetime('now')) NOT NULL,
51
+ FOREIGN KEY (`task_id`) REFERENCES `tasks`(`task_id`) ON UPDATE no action ON DELETE no action
52
+ );
53
+ --> statement-breakpoint
54
+ CREATE TABLE IF NOT EXISTS `opportunities` (
55
+ `id` text PRIMARY KEY NOT NULL,
56
+ `status` text DEFAULT 'detected' NOT NULL,
57
+ `source_ref` text,
58
+ `summary` text NOT NULL,
59
+ `score_impact` real,
60
+ `score_urgency` real,
61
+ `score_feasibility` real,
62
+ `score_permission` real,
63
+ `total_score` real,
64
+ `converted_task_id` text,
65
+ `detected_at` text DEFAULT (datetime('now')) NOT NULL,
66
+ `claimed_at` text,
67
+ FOREIGN KEY (`converted_task_id`) REFERENCES `tasks`(`task_id`) ON UPDATE no action ON DELETE no action
68
+ );
69
+ --> statement-breakpoint
70
+ CREATE TABLE IF NOT EXISTS `audit_events` (
71
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
72
+ `event_type` text NOT NULL,
73
+ `actor` text NOT NULL,
74
+ `task_id` text,
75
+ `summary` text NOT NULL,
76
+ `detail` text,
77
+ `file_ref` text,
78
+ `created_at` text DEFAULT (datetime('now')) NOT NULL
79
+ );
80
+ --> statement-breakpoint
81
+ CREATE TABLE IF NOT EXISTS `communication_events` (
82
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
83
+ `source_type` text NOT NULL,
84
+ `source_ref` text,
85
+ `intent_level` integer NOT NULL,
86
+ `sender` text,
87
+ `summary` text NOT NULL,
88
+ `raw_content_path` text,
89
+ `opportunity_id` text,
90
+ `created_at` text DEFAULT (datetime('now')) NOT NULL
91
+ );
92
+ --> statement-breakpoint
93
+ CREATE TABLE IF NOT EXISTS `message_log` (
94
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
95
+ `direction` text NOT NULL,
96
+ `source_type` text NOT NULL,
97
+ `source_ref` text,
98
+ `sender` text,
99
+ `receiver` text,
100
+ `chat_id` text,
101
+ `chat_type` text,
102
+ `content` text NOT NULL,
103
+ `message_type` text,
104
+ `intent_level` integer,
105
+ `related_task_id` text,
106
+ `metadata` text,
107
+ `trace_id` text,
108
+ `created_at` text DEFAULT (datetime('now')) NOT NULL
109
+ );
110
+ --> statement-breakpoint
111
+ CREATE TABLE IF NOT EXISTS `org_members` (
112
+ `member_id` text PRIMARY KEY NOT NULL,
113
+ `name` text NOT NULL,
114
+ `role` text,
115
+ `team` text,
116
+ `timezone` text,
117
+ `profile_path` text,
118
+ `response_pattern` text,
119
+ `platform` text DEFAULT 'feishu',
120
+ `union_id` text,
121
+ `user_id` text,
122
+ `en_name` text,
123
+ `email` text,
124
+ `employee_no` text,
125
+ `avatar_url` text,
126
+ `metadata` text,
127
+ `last_synced_at` text,
128
+ `updated_at` text DEFAULT (datetime('now')) NOT NULL
129
+ );
130
+ --> statement-breakpoint
131
+ CREATE TABLE IF NOT EXISTS `org_ownership` (
132
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
133
+ `scope` text NOT NULL,
134
+ `target` text NOT NULL,
135
+ `member_id` text NOT NULL,
136
+ `role` text DEFAULT 'owner' NOT NULL,
137
+ FOREIGN KEY (`member_id`) REFERENCES `org_members`(`member_id`) ON UPDATE no action ON DELETE no action
138
+ );
139
+ --> statement-breakpoint
140
+ CREATE TABLE IF NOT EXISTS `org_escalation_rules` (
141
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
142
+ `scope` text DEFAULT 'global' NOT NULL,
143
+ `after_minutes` integer NOT NULL,
144
+ `action` text NOT NULL,
145
+ `targets` text NOT NULL
146
+ );
147
+ --> statement-breakpoint
148
+ CREATE TABLE IF NOT EXISTS `trace_spans` (
149
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
150
+ `trace_id` text NOT NULL,
151
+ `span_id` text NOT NULL,
152
+ `parent_span_id` text,
153
+ `operation` text NOT NULL,
154
+ `status` text DEFAULT 'in_progress' NOT NULL,
155
+ `started_at` text NOT NULL,
156
+ `ended_at` text,
157
+ `duration_ms` real,
158
+ `input` text,
159
+ `output` text,
160
+ `error` text,
161
+ `metadata` text,
162
+ `created_at` text DEFAULT (datetime('now')) NOT NULL
163
+ );
164
+ --> statement-breakpoint
165
+ CREATE TABLE IF NOT EXISTS `chats` (
166
+ `chat_id` text PRIMARY KEY NOT NULL,
167
+ `platform` text DEFAULT 'feishu' NOT NULL,
168
+ `name` text,
169
+ `description` text,
170
+ `avatar` text,
171
+ `owner_id` text,
172
+ `chat_mode` text,
173
+ `chat_type` text,
174
+ `chat_tag` text,
175
+ `chat_status` text DEFAULT 'normal',
176
+ `external` integer DEFAULT 0,
177
+ `tenant_key` text,
178
+ `user_count` integer,
179
+ `bot_count` integer,
180
+ `metadata` text,
181
+ `first_seen_at` text DEFAULT (datetime('now')) NOT NULL,
182
+ `last_synced_at` text,
183
+ `updated_at` text DEFAULT (datetime('now')) NOT NULL
184
+ );
185
+ --> statement-breakpoint
186
+ CREATE TABLE IF NOT EXISTS `chat_members` (
187
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
188
+ `chat_id` text NOT NULL,
189
+ `member_id` text NOT NULL,
190
+ `role` text DEFAULT 'member',
191
+ `synced_at` text DEFAULT (datetime('now')) NOT NULL,
192
+ FOREIGN KEY (`chat_id`) REFERENCES `chats`(`chat_id`) ON UPDATE no action ON DELETE no action,
193
+ FOREIGN KEY (`member_id`) REFERENCES `org_members`(`member_id`) ON UPDATE no action ON DELETE no action
194
+ );
195
+ --> statement-breakpoint
196
+ CREATE TABLE IF NOT EXISTS `projects` (
197
+ `project_id` text PRIMARY KEY NOT NULL,
198
+ `name` text NOT NULL,
199
+ `description` text,
200
+ `platform` text DEFAULT 'github',
201
+ `claude_md` text,
202
+ `deleted_at` text,
203
+ `created_at` text DEFAULT (datetime('now')) NOT NULL,
204
+ `updated_at` text DEFAULT (datetime('now')) NOT NULL
205
+ );
206
+ --> statement-breakpoint
207
+ CREATE TABLE IF NOT EXISTS `project_repos` (
208
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
209
+ `project_id` text NOT NULL,
210
+ `name` text NOT NULL,
211
+ `git_url` text,
212
+ `repo_path` text,
213
+ `default_branch` text DEFAULT 'main',
214
+ `created_at` text DEFAULT (datetime('now')) NOT NULL,
215
+ FOREIGN KEY (`project_id`) REFERENCES `projects`(`project_id`) ON UPDATE no action ON DELETE no action
216
+ );
217
+ --> statement-breakpoint
218
+ CREATE TABLE IF NOT EXISTS `cc_sessions` (
219
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
220
+ `session_id` text NOT NULL,
221
+ `role` text NOT NULL,
222
+ `instance_id` text,
223
+ `task_id` text,
224
+ `chat_id` text,
225
+ `project_path` text,
226
+ `started_at` text DEFAULT (datetime('now')) NOT NULL,
227
+ `ended_at` text
228
+ );
229
+ --> statement-breakpoint
230
+ CREATE UNIQUE INDEX IF NOT EXISTS `cc_sessions_session_id_unique` ON `cc_sessions` (`session_id`);
231
+ --> statement-breakpoint
232
+ CREATE TABLE IF NOT EXISTS `topics` (
233
+ `id` text PRIMARY KEY NOT NULL,
234
+ `project_id` text REFERENCES `projects`(`project_id`),
235
+ `title` text NOT NULL,
236
+ `description` text,
237
+ `status` text NOT NULL DEFAULT 'active',
238
+ `thread_id` text,
239
+ `root_message_id` text,
240
+ `chat_id` text,
241
+ `workspace_path` text,
242
+ `branch_name` text,
243
+ `created_by` text,
244
+ `created_at` text NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
245
+ `updated_at` text NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
246
+ `closed_at` text
247
+ );
248
+ --> statement-breakpoint
249
+ CREATE INDEX IF NOT EXISTS `idx_topics_thread_id` ON `topics` (`thread_id`);
250
+ --> statement-breakpoint
251
+ CREATE INDEX IF NOT EXISTS `idx_topics_status` ON `topics` (`status`);
@@ -0,0 +1,19 @@
1
+ CREATE TABLE `workspaces` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `path` text NOT NULL,
4
+ `project_id` text,
5
+ `current_role` text NOT NULL,
6
+ `current_owner_type` text NOT NULL,
7
+ `current_owner_id` text NOT NULL,
8
+ `status` text DEFAULT 'active' NOT NULL,
9
+ `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')) NOT NULL,
10
+ `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')) NOT NULL
11
+ );
12
+ --> statement-breakpoint
13
+ ALTER TABLE `tasks` ADD COLUMN `workspace_id` text;
14
+ --> statement-breakpoint
15
+ ALTER TABLE `tasks` ADD COLUMN `escalated_to_topic_id` text;
16
+ --> statement-breakpoint
17
+ ALTER TABLE `topics` ADD COLUMN `workspace_id` text;
18
+ --> statement-breakpoint
19
+ ALTER TABLE `topics` ADD COLUMN `escalated_from_task_id` text;
@@ -0,0 +1 @@
1
+ ALTER TABLE `workspaces` ADD COLUMN `parent_workspace_id` text;
@@ -0,0 +1,3 @@
1
+ ALTER TABLE chats ADD COLUMN default_project_id text;
2
+ --> statement-breakpoint
3
+ ALTER TABLE chats ADD COLUMN custom_context text;
@@ -0,0 +1,34 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "sqlite",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1772100000000,
9
+ "tag": "0000_baseline",
10
+ "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1772200000000,
16
+ "tag": "0001_workspaces",
17
+ "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1772300000000,
23
+ "tag": "0002_workspace_parent",
24
+ "breakpoints": true
25
+ },
26
+ {
27
+ "idx": 3,
28
+ "version": "7",
29
+ "when": 1772400000000,
30
+ "tag": "0003_chat_context",
31
+ "breakpoints": true
32
+ }
33
+ ]
34
+ }