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.
- package/README.md +38 -0
- package/apps/server/dist/broker/cc-broker.js +267 -0
- package/apps/server/dist/cli.js +296 -0
- package/apps/server/dist/config.js +78 -0
- package/apps/server/dist/daemon.js +51 -0
- package/apps/server/dist/franky/context-builder.js +161 -0
- package/apps/server/dist/franky/franky-mcp-server.js +110 -0
- package/apps/server/dist/franky/franky-orchestrator.js +629 -0
- package/apps/server/dist/franky/index.js +5 -0
- package/apps/server/dist/franky/topic-router.js +16 -0
- package/apps/server/dist/gateway/chat-sync.js +135 -0
- package/apps/server/dist/gateway/command-router.js +116 -0
- package/apps/server/dist/gateway/commands/cancel.js +32 -0
- package/apps/server/dist/gateway/commands/help.js +16 -0
- package/apps/server/dist/gateway/commands/index.js +26 -0
- package/apps/server/dist/gateway/commands/restart.js +43 -0
- package/apps/server/dist/gateway/commands/status.js +34 -0
- package/apps/server/dist/gateway/commands/tasks.js +33 -0
- package/apps/server/dist/gateway/feishu-sender.js +508 -0
- package/apps/server/dist/gateway/feishu-ws.js +353 -0
- package/apps/server/dist/gateway/health-monitor.js +154 -0
- package/apps/server/dist/gateway/http.js +1064 -0
- package/apps/server/dist/gateway/media-downloader.js +182 -0
- package/apps/server/dist/gateway/message-events.js +10 -0
- package/apps/server/dist/gateway/message-intake.js +72 -0
- package/apps/server/dist/gateway/message-queue.js +118 -0
- package/apps/server/dist/gateway/session-reader.js +142 -0
- package/apps/server/dist/gateway/ws-push.js +115 -0
- package/apps/server/dist/loid/brain.js +121 -0
- package/apps/server/dist/loid/clarifier.js +162 -0
- package/apps/server/dist/loid/context-builder.js +462 -0
- package/apps/server/dist/loid/mcp-server.js +119 -0
- package/apps/server/dist/loid/memory-settler.js +189 -0
- package/apps/server/dist/loid/opportunity-manager.js +148 -0
- package/apps/server/dist/loid/profile-updater.js +179 -0
- package/apps/server/dist/loid/project-registry.js +192 -0
- package/apps/server/dist/loid/reporter.js +148 -0
- package/apps/server/dist/loid/schemas.js +117 -0
- package/apps/server/dist/loid/self-calibrator.js +314 -0
- package/apps/server/dist/loid/session-manager.js +472 -0
- package/apps/server/dist/loid/session.js +276 -0
- package/apps/server/dist/main.js +528 -0
- package/apps/server/dist/tracing/index.js +2 -0
- package/apps/server/dist/tracing/trace-context.js +92 -0
- package/apps/server/dist/types/message.js +2 -0
- package/apps/server/dist/yor/yor-mcp-server.js +107 -0
- package/apps/server/dist/yor/yor-orchestrator.js +248 -0
- package/apps/web/dist/assets/index-BiiEB0qZ.css +1 -0
- package/apps/web/dist/assets/index-Dnb9LGZd.js +798 -0
- package/apps/web/dist/index.html +13 -0
- package/package.json +42 -0
- package/packages/cc-client/dist/claude-code-backend.js +792 -0
- package/packages/cc-client/dist/index.js +2 -0
- package/packages/cc-client/package.json +11 -0
- package/packages/core/dist/constants.js +60 -0
- package/packages/core/dist/errors.js +35 -0
- package/packages/core/dist/index.js +9 -0
- package/packages/core/dist/office-init.js +190 -0
- package/packages/core/dist/repo-cache.js +70 -0
- package/packages/core/dist/scope/checker.js +114 -0
- package/packages/core/dist/scope/defaults.js +55 -0
- package/packages/core/dist/scope/index.js +3 -0
- package/packages/core/dist/state-machine.js +86 -0
- package/packages/core/dist/types/audit.js +12 -0
- package/packages/core/dist/types/backend.js +2 -0
- package/packages/core/dist/types/commitment.js +17 -0
- package/packages/core/dist/types/communication.js +18 -0
- package/packages/core/dist/types/index.js +9 -0
- package/packages/core/dist/types/opportunity.js +27 -0
- package/packages/core/dist/types/org.js +26 -0
- package/packages/core/dist/types/task.js +46 -0
- package/packages/core/dist/types/workspace.js +39 -0
- package/packages/core/dist/workspace-manager.js +314 -0
- package/packages/core/package.json +10 -0
- package/packages/db/dist/client.js +69 -0
- package/packages/db/dist/index.js +756 -0
- package/packages/db/dist/schema/audit-events.js +13 -0
- package/packages/db/dist/schema/cc-sessions.js +14 -0
- package/packages/db/dist/schema/chats.js +35 -0
- package/packages/db/dist/schema/commitments.js +18 -0
- package/packages/db/dist/schema/communication-events.js +14 -0
- package/packages/db/dist/schema/index.js +14 -0
- package/packages/db/dist/schema/message-log.js +20 -0
- package/packages/db/dist/schema/opportunities.js +23 -0
- package/packages/db/dist/schema/org.js +36 -0
- package/packages/db/dist/schema/projects.js +23 -0
- package/packages/db/dist/schema/tasks.js +51 -0
- package/packages/db/dist/schema/topics.js +22 -0
- package/packages/db/dist/schema/trace-spans.js +19 -0
- package/packages/db/dist/schema/workspaces.js +15 -0
- package/packages/db/package.json +12 -0
- package/packages/db/src/migrations/0000_baseline.sql +251 -0
- package/packages/db/src/migrations/0001_workspaces.sql +19 -0
- package/packages/db/src/migrations/0002_workspace_parent.sql +1 -0
- package/packages/db/src/migrations/0003_chat_context.sql +3 -0
- package/packages/db/src/migrations/meta/_journal.json +34 -0
- package/packages/mcp-tools/dist/index.js +41 -0
- package/packages/mcp-tools/dist/layer1/audit-append.js +38 -0
- package/packages/mcp-tools/dist/layer1/audit-query.js +51 -0
- package/packages/mcp-tools/dist/layer1/memory-brief.js +168 -0
- package/packages/mcp-tools/dist/layer1/memory-context.js +124 -0
- package/packages/mcp-tools/dist/layer1/memory-digest.js +126 -0
- package/packages/mcp-tools/dist/layer1/memory-forget.js +108 -0
- package/packages/mcp-tools/dist/layer1/memory-learn.js +63 -0
- package/packages/mcp-tools/dist/layer1/memory-recall.js +287 -0
- package/packages/mcp-tools/dist/layer1/memory-reflect.js +80 -0
- package/packages/mcp-tools/dist/layer1/memory-remember.js +119 -0
- package/packages/mcp-tools/dist/layer1/memory-search.js +263 -0
- package/packages/mcp-tools/dist/layer1/memory-write.js +21 -0
- package/packages/mcp-tools/dist/layer1/org-lookup.js +47 -0
- package/packages/mcp-tools/dist/layer1/project-get.js +28 -0
- package/packages/mcp-tools/dist/layer1/project-list.js +20 -0
- package/packages/mcp-tools/dist/layer1/report-daily.js +68 -0
- package/packages/mcp-tools/dist/layer1/task-get.js +29 -0
- package/packages/mcp-tools/dist/layer1/task-update.js +34 -0
- package/packages/mcp-tools/dist/layer2/franky/topic-checkpoint.js +43 -0
- package/packages/mcp-tools/dist/layer2/franky/topic-escalate.js +19 -0
- package/packages/mcp-tools/dist/layer2/loid/decision-log.js +15 -0
- package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +15 -0
- package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +30 -0
- package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +12 -0
- package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +77 -0
- package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +18 -0
- package/packages/mcp-tools/dist/layer2/loid/project-remove.js +16 -0
- package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +33 -0
- package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +206 -0
- package/packages/mcp-tools/dist/layer2/loid/task-escalate-to-topic.js +170 -0
- package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +45 -0
- package/packages/mcp-tools/dist/layer2/loid/topic-close.js +22 -0
- package/packages/mcp-tools/dist/layer2/loid/topic-create.js +60 -0
- package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +8 -0
- package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +7 -0
- package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +7 -0
- package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +28 -0
- package/packages/mcp-tools/dist/layer2/loid/yor-status.js +8 -0
- package/packages/mcp-tools/dist/layer2/yor/task-block.js +11 -0
- package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +35 -0
- package/packages/mcp-tools/dist/layer2/yor/task-progress.js +21 -0
- package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +203 -0
- package/packages/mcp-tools/dist/layer3/adapters/types.js +28 -0
- package/packages/mcp-tools/dist/layer3/channel-receive.js +11 -0
- package/packages/mcp-tools/dist/layer3/channel-send.js +75 -0
- package/packages/mcp-tools/dist/layer3/file-upload.js +44 -0
- package/packages/mcp-tools/dist/registry.js +911 -0
- package/packages/mcp-tools/package.json +13 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { execFile as execFileCb } from 'node:child_process';
|
|
2
|
+
import { mkdir, access, readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { getAllProjects, upsertProject, getProjectRepos, syncProjectRepos } from '@team-anya/db';
|
|
6
|
+
const execFile = promisify(execFileCb);
|
|
7
|
+
export class ProjectRegistry {
|
|
8
|
+
workspacePath;
|
|
9
|
+
projectsConfigPath;
|
|
10
|
+
reposPath;
|
|
11
|
+
db;
|
|
12
|
+
logger;
|
|
13
|
+
config = null;
|
|
14
|
+
constructor(deps) {
|
|
15
|
+
this.workspacePath = deps.workspacePath;
|
|
16
|
+
this.projectsConfigPath = deps.projectsConfigPath;
|
|
17
|
+
this.reposPath = deps.reposPath;
|
|
18
|
+
this.db = deps.db;
|
|
19
|
+
this.logger = deps.logger ?? { info: console.log, error: console.error };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 加载项目配置
|
|
23
|
+
*
|
|
24
|
+
* 优先从 DB 读取。如果 DB 为空且 JSON 文件存在,则从 JSON 导入到 DB。
|
|
25
|
+
*/
|
|
26
|
+
async loadConfig() {
|
|
27
|
+
if (this.config !== null)
|
|
28
|
+
return this.config;
|
|
29
|
+
// 先从 DB 读取
|
|
30
|
+
const dbProjects = getAllProjects(this.db);
|
|
31
|
+
if (dbProjects.length > 0) {
|
|
32
|
+
this.config = {
|
|
33
|
+
projects: dbProjects.map(p => {
|
|
34
|
+
const repos = getProjectRepos(this.db, p.project_id);
|
|
35
|
+
return {
|
|
36
|
+
projectId: p.project_id,
|
|
37
|
+
name: p.name,
|
|
38
|
+
description: p.description ?? undefined,
|
|
39
|
+
repos: repos.map(r => ({
|
|
40
|
+
name: r.name,
|
|
41
|
+
gitUrl: r.git_url ?? undefined,
|
|
42
|
+
repoPath: r.repo_path ?? undefined,
|
|
43
|
+
defaultBranch: r.default_branch ?? undefined,
|
|
44
|
+
})),
|
|
45
|
+
claudeMd: p.claude_md ?? undefined,
|
|
46
|
+
platform: p.platform ?? 'github',
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
return this.config;
|
|
51
|
+
}
|
|
52
|
+
// DB 为空,尝试从 JSON 文件导入
|
|
53
|
+
try {
|
|
54
|
+
await access(this.projectsConfigPath);
|
|
55
|
+
const content = await readFile(this.projectsConfigPath, 'utf-8');
|
|
56
|
+
const parsed = JSON.parse(content);
|
|
57
|
+
const jsonProjects = (parsed.projects ?? []);
|
|
58
|
+
// 导入到 DB(项目 + repos 关联表)
|
|
59
|
+
for (const p of jsonProjects) {
|
|
60
|
+
upsertProject(this.db, {
|
|
61
|
+
project_id: p.projectId,
|
|
62
|
+
name: p.name,
|
|
63
|
+
description: p.description,
|
|
64
|
+
platform: p.platform ?? 'github',
|
|
65
|
+
claude_md: p.claudeMd,
|
|
66
|
+
});
|
|
67
|
+
syncProjectRepos(this.db, p.projectId, p.repos.map(r => ({
|
|
68
|
+
name: r.name,
|
|
69
|
+
git_url: r.gitUrl,
|
|
70
|
+
repo_path: r.repoPath,
|
|
71
|
+
default_branch: r.defaultBranch,
|
|
72
|
+
})));
|
|
73
|
+
}
|
|
74
|
+
this.logger.info(`[ProjectRegistry] 从 JSON 导入 ${jsonProjects.length} 个项目到 DB`);
|
|
75
|
+
this.config = { projects: jsonProjects };
|
|
76
|
+
this.validateUniqueIds(this.config);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof Error && err.message.startsWith('ID 冲突')) {
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
this.logger.info('[ProjectRegistry] 项目注册表为空,使用空列表');
|
|
83
|
+
this.config = { projects: [] };
|
|
84
|
+
}
|
|
85
|
+
return this.config;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 向后兼容:返回 projects 列表
|
|
89
|
+
*/
|
|
90
|
+
async loadProjects() {
|
|
91
|
+
const config = await this.loadConfig();
|
|
92
|
+
return config.projects;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 重新从 DB 加载(清除缓存)
|
|
96
|
+
*/
|
|
97
|
+
invalidateCache() {
|
|
98
|
+
this.config = null;
|
|
99
|
+
}
|
|
100
|
+
validateUniqueIds(config) {
|
|
101
|
+
const ids = new Set();
|
|
102
|
+
for (const p of config.projects) {
|
|
103
|
+
if (ids.has(p.projectId)) {
|
|
104
|
+
throw new Error(`ID 冲突: "${p.projectId}" 在配置中重复出现`);
|
|
105
|
+
}
|
|
106
|
+
ids.add(p.projectId);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 解析 repoPath:如果配置中未指定,使用 {reposPath}/{name} 作为默认值
|
|
111
|
+
*/
|
|
112
|
+
resolveRepoPath(repoPath, name) {
|
|
113
|
+
return repoPath ?? join(this.reposPath, name);
|
|
114
|
+
}
|
|
115
|
+
findProject(id) {
|
|
116
|
+
return this.config?.projects.find(p => p.projectId === id);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 自动初始化:遍历所有配置的仓库,缺失的自动 clone
|
|
120
|
+
* 适合在服务启动时或手动初始化时调用
|
|
121
|
+
*/
|
|
122
|
+
async ensureRepos() {
|
|
123
|
+
await this.loadConfig();
|
|
124
|
+
await mkdir(this.reposPath, { recursive: true });
|
|
125
|
+
const result = { cloned: [], existed: [], failed: [] };
|
|
126
|
+
// 收集所有需要检查的仓库
|
|
127
|
+
for (const project of this.config.projects) {
|
|
128
|
+
for (const repo of project.repos) {
|
|
129
|
+
const repoPath = this.resolveRepoPath(repo.repoPath, repo.name);
|
|
130
|
+
// 检查是否已存在
|
|
131
|
+
try {
|
|
132
|
+
await access(join(repoPath, '.git'));
|
|
133
|
+
result.existed.push(repo.name);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// 不存在,需要 clone
|
|
138
|
+
}
|
|
139
|
+
if (!repo.gitUrl) {
|
|
140
|
+
result.failed.push({
|
|
141
|
+
name: repo.name,
|
|
142
|
+
error: `仓库不存在且未配置 gitUrl: ${repoPath}`,
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
this.logger.info(`[ProjectRegistry] 克隆 ${repo.name}: ${repo.gitUrl}`);
|
|
148
|
+
const cloneArgs = ['clone'];
|
|
149
|
+
if (repo.defaultBranch) {
|
|
150
|
+
cloneArgs.push('--branch', repo.defaultBranch);
|
|
151
|
+
}
|
|
152
|
+
cloneArgs.push(repo.gitUrl, repoPath);
|
|
153
|
+
await execFile('git', cloneArgs);
|
|
154
|
+
result.cloned.push(repo.name);
|
|
155
|
+
this.logger.info(`[ProjectRegistry] 克隆完成: ${repo.name}`);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
159
|
+
result.failed.push({ name: repo.name, error: msg });
|
|
160
|
+
this.logger.error(`[ProjectRegistry] 克隆失败 (${repo.name}):`, err);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 获取项目配置(不执行任何 git 命令)
|
|
168
|
+
* 找到项目 → 返回 project 模式(repos 数组)
|
|
169
|
+
* 未找到 → 返回 adhoc 模式
|
|
170
|
+
*/
|
|
171
|
+
async getProjectConfig(projectId) {
|
|
172
|
+
await this.loadConfig();
|
|
173
|
+
if (projectId) {
|
|
174
|
+
const project = this.findProject(projectId);
|
|
175
|
+
if (project) {
|
|
176
|
+
return {
|
|
177
|
+
mode: 'project',
|
|
178
|
+
platform: project.platform ?? 'github',
|
|
179
|
+
repos: project.repos.map(repo => ({
|
|
180
|
+
name: repo.name,
|
|
181
|
+
repo_path: this.resolveRepoPath(repo.repoPath, repo.name),
|
|
182
|
+
default_branch: repo.defaultBranch ?? 'main',
|
|
183
|
+
git_url: repo.gitUrl,
|
|
184
|
+
})),
|
|
185
|
+
claudeMd: project.claudeMd,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { mode: 'adhoc', platform: 'local' };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=project-registry.js.map
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
// ── 进行中状态集合 ──
|
|
3
|
+
const IN_PROGRESS_STATUSES = new Set(['IN_PROGRESS', 'TESTING', 'FIXING']);
|
|
4
|
+
const PR_STATUSES = new Set(['PR_OPEN', 'WAITING_REVIEW']);
|
|
5
|
+
// ── Reporter ──
|
|
6
|
+
export class Reporter {
|
|
7
|
+
deps;
|
|
8
|
+
config;
|
|
9
|
+
constructor(deps, config) {
|
|
10
|
+
this.deps = deps;
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 生成日报 Markdown 内容
|
|
15
|
+
*/
|
|
16
|
+
async generateDailyReport(date) {
|
|
17
|
+
const allTasks = this.deps.getAllTasks();
|
|
18
|
+
const commitments = this.deps.getActiveCommitments();
|
|
19
|
+
const opportunities = this.deps.getOpenOpportunities();
|
|
20
|
+
const auditEvents = this.deps.getAuditEventsByDate(date);
|
|
21
|
+
const lines = [];
|
|
22
|
+
const done = allTasks.filter((t) => t.status === 'DONE' && t.updated_at?.startsWith(date));
|
|
23
|
+
const prOpen = allTasks.filter((t) => PR_STATUSES.has(t.status));
|
|
24
|
+
const inProgress = allTasks.filter((t) => IN_PROGRESS_STATUSES.has(t.status));
|
|
25
|
+
const blocked = allTasks.filter((t) => t.status === 'BLOCKED');
|
|
26
|
+
// 开头一句话总结
|
|
27
|
+
const totalActive = inProgress.length + prOpen.length;
|
|
28
|
+
if (done.length > 0 && blocked.length === 0) {
|
|
29
|
+
lines.push(`今天完成了 ${done.length} 个任务${totalActive > 0 ? `,还有 ${totalActive} 个在跑` : ''}。\n`);
|
|
30
|
+
}
|
|
31
|
+
else if (done.length > 0 && blocked.length > 0) {
|
|
32
|
+
lines.push(`今天完成了 ${done.length} 个任务,但有 ${blocked.length} 个卡住了。\n`);
|
|
33
|
+
}
|
|
34
|
+
else if (blocked.length > 0) {
|
|
35
|
+
lines.push(`有 ${blocked.length} 个任务卡住了,需要关注。\n`);
|
|
36
|
+
}
|
|
37
|
+
else if (totalActive > 0) {
|
|
38
|
+
lines.push(`${totalActive} 个任务进行中。\n`);
|
|
39
|
+
}
|
|
40
|
+
// 完成的
|
|
41
|
+
if (done.length > 0) {
|
|
42
|
+
lines.push('**已完成**');
|
|
43
|
+
for (const t of done) {
|
|
44
|
+
const pr = t.pr_url ? ` → ${t.pr_url}` : '';
|
|
45
|
+
lines.push(`- ${t.title} (${t.task_id})${pr}`);
|
|
46
|
+
}
|
|
47
|
+
lines.push('');
|
|
48
|
+
}
|
|
49
|
+
// 等 Review 的
|
|
50
|
+
if (prOpen.length > 0) {
|
|
51
|
+
lines.push('**等 Review**');
|
|
52
|
+
for (const t of prOpen) {
|
|
53
|
+
const pr = t.pr_url ? ` → ${t.pr_url}` : '';
|
|
54
|
+
lines.push(`- ${t.title} (${t.task_id})${pr}`);
|
|
55
|
+
}
|
|
56
|
+
lines.push('');
|
|
57
|
+
}
|
|
58
|
+
// 进行中的
|
|
59
|
+
if (inProgress.length > 0) {
|
|
60
|
+
lines.push('**进行中**');
|
|
61
|
+
for (const t of inProgress) {
|
|
62
|
+
lines.push(`- ${t.title} (${t.task_id})`);
|
|
63
|
+
}
|
|
64
|
+
lines.push('');
|
|
65
|
+
}
|
|
66
|
+
// 卡住的(重点标出)
|
|
67
|
+
if (blocked.length > 0) {
|
|
68
|
+
lines.push('**卡住了**');
|
|
69
|
+
for (const t of blocked) {
|
|
70
|
+
lines.push(`- ${t.title} (${t.task_id}) — ${t.blocked_reason ?? '原因待查'}`);
|
|
71
|
+
}
|
|
72
|
+
lines.push('');
|
|
73
|
+
}
|
|
74
|
+
// 承诺追踪
|
|
75
|
+
if (commitments.length > 0) {
|
|
76
|
+
lines.push('**还欠着的**');
|
|
77
|
+
for (const c of commitments) {
|
|
78
|
+
const deadline = c.deadline ? `,截止 ${c.deadline}` : '';
|
|
79
|
+
lines.push(`- ${c.promise} (答应 ${c.promised_to} 的${deadline})`);
|
|
80
|
+
}
|
|
81
|
+
lines.push('');
|
|
82
|
+
}
|
|
83
|
+
// 机会
|
|
84
|
+
if (opportunities.length > 0) {
|
|
85
|
+
lines.push('**发现了几个可以做的事**');
|
|
86
|
+
for (const o of opportunities) {
|
|
87
|
+
lines.push(`- ${o.summary}`);
|
|
88
|
+
}
|
|
89
|
+
lines.push('');
|
|
90
|
+
}
|
|
91
|
+
return lines.join('\n');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 将日报写入文件
|
|
95
|
+
*/
|
|
96
|
+
async saveDailyReport(date, content) {
|
|
97
|
+
const reportsDir = join(this.config.workspacePath, 'reports');
|
|
98
|
+
await this.deps.mkdirp(reportsDir);
|
|
99
|
+
const filePath = join(reportsDir, `daily-${date}.md`);
|
|
100
|
+
await this.deps.writeFile(filePath, content);
|
|
101
|
+
return filePath;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 端到端:生成 + 写文件 + 飞书推送
|
|
105
|
+
*/
|
|
106
|
+
async publishDailyReport(date) {
|
|
107
|
+
const content = await this.generateDailyReport(date);
|
|
108
|
+
// 写文件(总是执行)
|
|
109
|
+
await this.saveDailyReport(date, content);
|
|
110
|
+
// 飞书推送(可选,失败不影响文件写入)
|
|
111
|
+
if (this.config.feishuDailyReportChatId) {
|
|
112
|
+
try {
|
|
113
|
+
await this.deps.sendDailyReport({
|
|
114
|
+
chatId: this.config.feishuDailyReportChatId,
|
|
115
|
+
reportContent: content,
|
|
116
|
+
date,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// 飞书发送失败不影响日报文件保存
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 实时告警:任务 BLOCKED
|
|
126
|
+
*/
|
|
127
|
+
async notifyBlocked(params) {
|
|
128
|
+
await this.deps.sendBlockedAlert({
|
|
129
|
+
targetUserIds: params.targetUserIds,
|
|
130
|
+
taskId: params.taskId,
|
|
131
|
+
reason: params.reason,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 任务完成通知
|
|
136
|
+
*/
|
|
137
|
+
async notifyTaskDone(params) {
|
|
138
|
+
if (!params.chatId)
|
|
139
|
+
return;
|
|
140
|
+
await this.deps.sendTaskDone({
|
|
141
|
+
chatId: params.chatId,
|
|
142
|
+
taskId: params.taskId,
|
|
143
|
+
prUrl: params.prUrl,
|
|
144
|
+
summary: params.summary,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=reporter.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ── Loid 行动工具 Input Schemas ──
|
|
3
|
+
export const DispatchTaskInputSchema = z.object({
|
|
4
|
+
title: z.string().describe('任务标题'),
|
|
5
|
+
brief: z.string().describe('执行 brief(Markdown 格式,只写做什么和标准,不写怎么做)'),
|
|
6
|
+
project_id: z.string().optional().describe('目标项目/仓库 ID'),
|
|
7
|
+
objective: z.string().describe('任务目标(一句话概括要达成什么)'),
|
|
8
|
+
acceptance_criteria: z.array(z.string()).describe('验收标准列表(至少一条可验证的完成条件)'),
|
|
9
|
+
context: z.string().optional().describe('背景信息(业务上下文、技术约束等)'),
|
|
10
|
+
conversation_id: z.string().optional().describe('关联的对话 ID(用于后续回复)'),
|
|
11
|
+
source_message_id: z.string().optional().describe('触发消息 ID'),
|
|
12
|
+
created_by: z.string().optional().describe('任务创建者(从当前事件的 sender_name 或 sender_id 提取)'),
|
|
13
|
+
source_chat_id: z.string().optional().describe('触发任务的聊天 ID(从当前对话的 chat_id 提取)'),
|
|
14
|
+
});
|
|
15
|
+
export const AskHumanInputSchema = z.object({
|
|
16
|
+
message: z.string().describe('要发送给人类的消息内容'),
|
|
17
|
+
chat_id: z.string().optional().describe('目标群聊 ID'),
|
|
18
|
+
reply_to_message_id: z.string().optional().describe('回复的消息 ID'),
|
|
19
|
+
task_id: z.string().optional().describe('关联任务 ID'),
|
|
20
|
+
intent: z.enum(['clarification', 'report', 'notification']).describe('消息意图'),
|
|
21
|
+
});
|
|
22
|
+
export const ApproveDeliveryInputSchema = z.object({
|
|
23
|
+
task_id: z.string().describe('要验收的任务 ID'),
|
|
24
|
+
summary: z.string().optional().describe('验收通过的简评'),
|
|
25
|
+
notify_human: z.boolean().default(true).describe('是否通知人类'),
|
|
26
|
+
});
|
|
27
|
+
export const RejectDeliveryInputSchema = z.object({
|
|
28
|
+
task_id: z.string().describe('要打回的任务 ID'),
|
|
29
|
+
reason: z.string().describe('打回原因'),
|
|
30
|
+
feedback: z.string().describe('给执行者的修改意见'),
|
|
31
|
+
});
|
|
32
|
+
export const LookupTaskInputSchema = z.object({
|
|
33
|
+
task_id: z.string().optional().describe('指定任务 ID'),
|
|
34
|
+
status: z.string().optional().describe('按状态过滤'),
|
|
35
|
+
});
|
|
36
|
+
export const LogDecisionInputSchema = z.object({
|
|
37
|
+
decision: z.string().describe('决策内容'),
|
|
38
|
+
reasoning: z.string().describe('决策理由'),
|
|
39
|
+
task_id: z.string().optional().describe('关联任务 ID'),
|
|
40
|
+
});
|
|
41
|
+
export const NoActionInputSchema = z.object({
|
|
42
|
+
reason: z.string().describe('不处理的原因'),
|
|
43
|
+
});
|
|
44
|
+
// ── Output Schemas(工具执行后返回给 Loid 的结果)──
|
|
45
|
+
export const DispatchTaskOutputSchema = z.object({
|
|
46
|
+
task_id: z.string(),
|
|
47
|
+
status: z.literal('dispatched'),
|
|
48
|
+
});
|
|
49
|
+
export const AskHumanOutputSchema = z.object({
|
|
50
|
+
sent: z.boolean(),
|
|
51
|
+
message_id: z.string().optional(),
|
|
52
|
+
});
|
|
53
|
+
export const ApproveDeliveryOutputSchema = z.object({
|
|
54
|
+
approved: z.boolean(),
|
|
55
|
+
task_id: z.string(),
|
|
56
|
+
});
|
|
57
|
+
export const RejectDeliveryOutputSchema = z.object({
|
|
58
|
+
rejected: z.boolean(),
|
|
59
|
+
task_id: z.string(),
|
|
60
|
+
retry_count: z.number(),
|
|
61
|
+
max_retries: z.number(),
|
|
62
|
+
});
|
|
63
|
+
export const LookupTaskOutputSchema = z.object({
|
|
64
|
+
tasks: z.array(z.object({
|
|
65
|
+
task_id: z.string(),
|
|
66
|
+
title: z.string(),
|
|
67
|
+
status: z.string(),
|
|
68
|
+
assignee: z.string().nullable(),
|
|
69
|
+
created_at: z.string().nullable(),
|
|
70
|
+
pr_url: z.string().nullable().optional(),
|
|
71
|
+
})),
|
|
72
|
+
});
|
|
73
|
+
export const LogDecisionOutputSchema = z.object({
|
|
74
|
+
logged: z.boolean(),
|
|
75
|
+
});
|
|
76
|
+
export const NoActionOutputSchema = z.object({
|
|
77
|
+
acknowledged: z.boolean(),
|
|
78
|
+
});
|
|
79
|
+
// ── Tool 注册表 ──
|
|
80
|
+
export const LOID_TOOL_REGISTRY = {
|
|
81
|
+
dispatch_task: {
|
|
82
|
+
description: '派工给执行者(Yor)。创建任务、写入 brief、启动执行。',
|
|
83
|
+
inputSchema: DispatchTaskInputSchema,
|
|
84
|
+
outputSchema: DispatchTaskOutputSchema,
|
|
85
|
+
},
|
|
86
|
+
ask_human: {
|
|
87
|
+
description: '向人类发送消息(提问、汇报结果、通知)。',
|
|
88
|
+
inputSchema: AskHumanInputSchema,
|
|
89
|
+
outputSchema: AskHumanOutputSchema,
|
|
90
|
+
},
|
|
91
|
+
approve_delivery: {
|
|
92
|
+
description: '验收通过执行者的交付成果。标记任务完成,可选通知人类。',
|
|
93
|
+
inputSchema: ApproveDeliveryInputSchema,
|
|
94
|
+
outputSchema: ApproveDeliveryOutputSchema,
|
|
95
|
+
},
|
|
96
|
+
reject_delivery: {
|
|
97
|
+
description: '打回执行者的交付,附带修改意见并重新派工。最多返工 3 次。',
|
|
98
|
+
inputSchema: RejectDeliveryInputSchema,
|
|
99
|
+
outputSchema: RejectDeliveryOutputSchema,
|
|
100
|
+
},
|
|
101
|
+
lookup_task: {
|
|
102
|
+
description: '查询任务状态和历史。可按 task_id 或 status 过滤。',
|
|
103
|
+
inputSchema: LookupTaskInputSchema,
|
|
104
|
+
outputSchema: LookupTaskOutputSchema,
|
|
105
|
+
},
|
|
106
|
+
log_decision: {
|
|
107
|
+
description: '记录决策理由到审计日志。',
|
|
108
|
+
inputSchema: LogDecisionInputSchema,
|
|
109
|
+
outputSchema: LogDecisionOutputSchema,
|
|
110
|
+
},
|
|
111
|
+
no_action: {
|
|
112
|
+
description: '明确表示不处理此消息。记录原因到日志。',
|
|
113
|
+
inputSchema: NoActionInputSchema,
|
|
114
|
+
outputSchema: NoActionOutputSchema,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=schemas.js.map
|