@suifei/dsh-ai-team 0.4.143 → 0.4.145
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -21
- package/README.md +4 -0
- package/client.js +22 -14
- package/cordis.patch.yml +31 -31
- package/icon.svg +12 -12
- package/index.js +4 -3
- package/lib/domain/ids.js +26 -26
- package/lib/domain/inbox.js +93 -93
- package/lib/domain/member-config.js +168 -168
- package/lib/host/decision-report.js +72 -72
- package/lib/host/default-workspace.js +69 -69
- package/lib/host/fault-adapter.js +50 -50
- package/lib/host/people-view.js +120 -120
- package/lib/host/permission-guard.js +61 -61
- package/lib/host/pmo.js +13 -13
- package/lib/host/project-registry.js +104 -104
- package/lib/host/risk-view.js +99 -99
- package/lib/host/weekly-view.js +86 -86
- package/lib/host/workspace-path.js +94 -94
- package/lib/ledger/checkpoint.js +415 -415
- package/lib/ledger/events.js +398 -398
- package/lib/ledger/namespace.js +124 -124
- package/lib/ledger/tools.js +118 -118
- package/lib/ledger/writer.js +1266 -1266
- package/lib/runtime/error-chain.js +31 -31
- package/lib/runtime/shell-guard.js +102 -102
- package/lib/runtime/skill-catalog.js +41 -41
- package/lib/runtime/skill-policy.js +12 -12
- package/lib/skillopt/adopt-gate.js +108 -108
- package/lib/skillopt/gate-wiring.js +146 -146
- package/lib/skillopt/job-runner.js +5 -4
- package/lib/skillopt/jobs.js +135 -135
- package/lib/skillopt/judge.js +163 -143
- package/lib/skillopt/optimizer.js +183 -182
- package/lib/skillopt/proposal-store.js +33 -33
- package/lib/skillopt/review-runner.js +107 -107
- package/lib/skillopt/reviewer.js +87 -85
- package/lib/skillopt/rubric.js +189 -189
- package/lib/skillopt/subagent-text.js +101 -101
- package/lib/skillopt/tool-access.js +56 -56
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +1 -1
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
/** Lightweight Project index. The ledger remains the source of truth for Project state. */
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { DEFAULT_PROJECT_ID } from './project-runtime.js';
|
|
5
|
-
import { reportFail } from '../diaglog.js';
|
|
6
|
-
|
|
7
|
-
export class ProjectRegistry {
|
|
8
|
-
constructor({ rootDir, projects, activeProjectId }) {
|
|
9
|
-
this.rootDir = rootDir;
|
|
10
|
-
this.projects = Array.isArray(projects) ? projects : [];
|
|
11
|
-
this.activeProjectId = activeProjectId ?? DEFAULT_PROJECT_ID;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static load(rootDir, options = {}) {
|
|
15
|
-
// 初装时会给一个默认项目;它必须有工作目录,否则成员会话的 cwd 只能落到
|
|
16
|
-
// 插件数据目录(workspace attach 会被拒,成员也在错误目录里干活)。
|
|
17
|
-
const defaultWorkspacePath = typeof options.defaultWorkspacePath === 'string' ? options.defaultWorkspacePath : '';
|
|
18
|
-
mkdirSync(rootDir, { recursive: true });
|
|
19
|
-
const file = join(rootDir, 'projects.json');
|
|
20
|
-
let parsed;
|
|
21
|
-
try {
|
|
22
|
-
parsed = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
// A corrupt index must not silently vanish the user's project list:
|
|
25
|
-
// keep the broken file for forensics, then fall back to the default.
|
|
26
|
-
const kept = `${file}.corrupt-${Date.now()}`;
|
|
27
|
-
try { renameSync(file, kept); } catch { /* rename is best-effort */ }
|
|
28
|
-
reportFail('registry.corrupt.fail', { kept }, `[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
|
|
29
|
-
parsed = null;
|
|
30
|
-
}
|
|
31
|
-
// 默认项目只在**一个项目都没有**时播种(初装的第一入口)。此前只要列表里
|
|
32
|
-
// 缺少 `prj_main` 就补一条:用户把它删掉后会被静默复活,等于删不掉。
|
|
33
|
-
const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
|
|
34
|
-
? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
|
|
35
|
-
: [];
|
|
36
|
-
if (projects.length === 0) projects.push({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
|
|
37
|
-
const active = projects.some((project) => project.id === parsed?.activeProjectId)
|
|
38
|
-
? parsed.activeProjectId
|
|
39
|
-
: projects[0].id;
|
|
40
|
-
const registry = new ProjectRegistry({ rootDir, projects, activeProjectId: active });
|
|
41
|
-
if (!existsSync(file)) registry.save();
|
|
42
|
-
return registry;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get activeProject() {
|
|
46
|
-
return this.projects.find((project) => project.id === this.activeProjectId) ?? this.projects[0];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
list() {
|
|
50
|
-
return this.projects.map((project) => ({ ...project, active: project.id === this.activeProjectId }));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** 更新某个项目的工作目录(与账本的 project/workspace-changed 保持同步)。 */
|
|
54
|
-
setWorkspace(id, workspacePath) {
|
|
55
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
56
|
-
if (project === undefined) return false;
|
|
57
|
-
const next = typeof workspacePath === 'string' ? workspacePath : '';
|
|
58
|
-
if ((project.workspacePath ?? '') === next) return false;
|
|
59
|
-
project.workspacePath = next;
|
|
60
|
-
this.save();
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
add({ id, name, createdAt, goal, workspacePath }) {
|
|
64
|
-
if (typeof id !== 'string' || id === '') throw new Error('project id is required');
|
|
65
|
-
if (!this.projects.some((project) => project.id === id)) {
|
|
66
|
-
this.projects.push({ id, name: name ?? id, goal: goal ?? '', workspacePath: workspacePath ?? '', createdAt: createdAt ?? Date.now() });
|
|
67
|
-
this.save();
|
|
68
|
-
}
|
|
69
|
-
return this.projects.find((project) => project.id === id);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setActive(id) {
|
|
73
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
74
|
-
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
75
|
-
// 归档项目不能成为 active:registry 的 active 会被 bootstrap 当作「默认项目」,
|
|
76
|
-
// 指向一个已归档/无账本的项目会让工作台直接不可达。
|
|
77
|
-
if (project.archived === true) throw new Error(`project ${id} is archived`);
|
|
78
|
-
this.activeProjectId = id;
|
|
79
|
-
this.save();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Mirror a Project's archive flag into the global index (ledger stays the source of truth). */
|
|
83
|
-
setArchived(id, archived) {
|
|
84
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
85
|
-
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
86
|
-
project.archived = archived === true;
|
|
87
|
-
if (archived === true && this.activeProjectId === id) {
|
|
88
|
-
const fallback = this.projects.find((entry) => entry.id !== id && entry.archived !== true);
|
|
89
|
-
if (fallback !== undefined) this.activeProjectId = fallback.id;
|
|
90
|
-
}
|
|
91
|
-
this.save();
|
|
92
|
-
return project;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
save() {
|
|
96
|
-
const file = join(this.rootDir, 'projects.json');
|
|
97
|
-
const temp = `${file}.tmp`;
|
|
98
|
-
writeFileSync(temp, JSON.stringify({
|
|
99
|
-
activeProjectId: this.activeProjectId,
|
|
100
|
-
projects: this.projects,
|
|
101
|
-
}, null, 2), 'utf8');
|
|
102
|
-
renameSync(temp, file);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
1
|
+
/** Lightweight Project index. The ledger remains the source of truth for Project state. */
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { DEFAULT_PROJECT_ID } from './project-runtime.js';
|
|
5
|
+
import { reportFail } from '../diaglog.js';
|
|
6
|
+
|
|
7
|
+
export class ProjectRegistry {
|
|
8
|
+
constructor({ rootDir, projects, activeProjectId }) {
|
|
9
|
+
this.rootDir = rootDir;
|
|
10
|
+
this.projects = Array.isArray(projects) ? projects : [];
|
|
11
|
+
this.activeProjectId = activeProjectId ?? DEFAULT_PROJECT_ID;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static load(rootDir, options = {}) {
|
|
15
|
+
// 初装时会给一个默认项目;它必须有工作目录,否则成员会话的 cwd 只能落到
|
|
16
|
+
// 插件数据目录(workspace attach 会被拒,成员也在错误目录里干活)。
|
|
17
|
+
const defaultWorkspacePath = typeof options.defaultWorkspacePath === 'string' ? options.defaultWorkspacePath : '';
|
|
18
|
+
mkdirSync(rootDir, { recursive: true });
|
|
19
|
+
const file = join(rootDir, 'projects.json');
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// A corrupt index must not silently vanish the user's project list:
|
|
25
|
+
// keep the broken file for forensics, then fall back to the default.
|
|
26
|
+
const kept = `${file}.corrupt-${Date.now()}`;
|
|
27
|
+
try { renameSync(file, kept); } catch { /* rename is best-effort */ }
|
|
28
|
+
reportFail('registry.corrupt.fail', { kept }, `[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
|
|
29
|
+
parsed = null;
|
|
30
|
+
}
|
|
31
|
+
// 默认项目只在**一个项目都没有**时播种(初装的第一入口)。此前只要列表里
|
|
32
|
+
// 缺少 `prj_main` 就补一条:用户把它删掉后会被静默复活,等于删不掉。
|
|
33
|
+
const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
|
|
34
|
+
? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
|
|
35
|
+
: [];
|
|
36
|
+
if (projects.length === 0) projects.push({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
|
|
37
|
+
const active = projects.some((project) => project.id === parsed?.activeProjectId)
|
|
38
|
+
? parsed.activeProjectId
|
|
39
|
+
: projects[0].id;
|
|
40
|
+
const registry = new ProjectRegistry({ rootDir, projects, activeProjectId: active });
|
|
41
|
+
if (!existsSync(file)) registry.save();
|
|
42
|
+
return registry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get activeProject() {
|
|
46
|
+
return this.projects.find((project) => project.id === this.activeProjectId) ?? this.projects[0];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
list() {
|
|
50
|
+
return this.projects.map((project) => ({ ...project, active: project.id === this.activeProjectId }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 更新某个项目的工作目录(与账本的 project/workspace-changed 保持同步)。 */
|
|
54
|
+
setWorkspace(id, workspacePath) {
|
|
55
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
56
|
+
if (project === undefined) return false;
|
|
57
|
+
const next = typeof workspacePath === 'string' ? workspacePath : '';
|
|
58
|
+
if ((project.workspacePath ?? '') === next) return false;
|
|
59
|
+
project.workspacePath = next;
|
|
60
|
+
this.save();
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
add({ id, name, createdAt, goal, workspacePath }) {
|
|
64
|
+
if (typeof id !== 'string' || id === '') throw new Error('project id is required');
|
|
65
|
+
if (!this.projects.some((project) => project.id === id)) {
|
|
66
|
+
this.projects.push({ id, name: name ?? id, goal: goal ?? '', workspacePath: workspacePath ?? '', createdAt: createdAt ?? Date.now() });
|
|
67
|
+
this.save();
|
|
68
|
+
}
|
|
69
|
+
return this.projects.find((project) => project.id === id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setActive(id) {
|
|
73
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
74
|
+
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
75
|
+
// 归档项目不能成为 active:registry 的 active 会被 bootstrap 当作「默认项目」,
|
|
76
|
+
// 指向一个已归档/无账本的项目会让工作台直接不可达。
|
|
77
|
+
if (project.archived === true) throw new Error(`project ${id} is archived`);
|
|
78
|
+
this.activeProjectId = id;
|
|
79
|
+
this.save();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Mirror a Project's archive flag into the global index (ledger stays the source of truth). */
|
|
83
|
+
setArchived(id, archived) {
|
|
84
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
85
|
+
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
86
|
+
project.archived = archived === true;
|
|
87
|
+
if (archived === true && this.activeProjectId === id) {
|
|
88
|
+
const fallback = this.projects.find((entry) => entry.id !== id && entry.archived !== true);
|
|
89
|
+
if (fallback !== undefined) this.activeProjectId = fallback.id;
|
|
90
|
+
}
|
|
91
|
+
this.save();
|
|
92
|
+
return project;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
save() {
|
|
96
|
+
const file = join(this.rootDir, 'projects.json');
|
|
97
|
+
const temp = `${file}.tmp`;
|
|
98
|
+
writeFileSync(temp, JSON.stringify({
|
|
99
|
+
activeProjectId: this.activeProjectId,
|
|
100
|
+
projects: this.projects,
|
|
101
|
+
}, null, 2), 'utf8');
|
|
102
|
+
renameSync(temp, file);
|
|
103
|
+
}
|
|
104
|
+
}
|
package/lib/host/risk-view.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 风险清单投影(R-07 / 视图组合纪律 V1):三类需要 Human 注意的风险,
|
|
3
|
-
* 全部从既有账本投影只读聚合,零新事件、零新数据结构——
|
|
4
|
-
* 1. 受阻任务:pending 且依赖未完成(isTaskBlocked);
|
|
5
|
-
* 2. 失败成员:agent 带未清除的 lastFailure(或 status=failed);
|
|
6
|
-
* 3. 待决超时:Human 收件箱中 unread 的 decision_required,超过 staleHours。
|
|
7
|
-
*
|
|
8
|
-
* 输出行复用 quadrantItem 的形状约定(kind/taskId/taskNumber/title/...),
|
|
9
|
-
* 前端零新交互模式即可渲染。
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { isTaskBlocked } from '../ledger/fold.js';
|
|
13
|
-
|
|
14
|
-
const RISK_KINDS = Object.freeze({
|
|
15
|
-
BLOCKED_TASK: 'blocked_task',
|
|
16
|
-
FAILED_MEMBER: 'failed_member',
|
|
17
|
-
STALE_DECISION: 'stale_decision',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export function riskView(state, { now = Date.now(), staleHours = 24 } = {}) {
|
|
21
|
-
const humanId = state.humanMemberId
|
|
22
|
-
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
23
|
-
?? null;
|
|
24
|
-
const cutoff = now - staleHours * 60 * 60 * 1000;
|
|
25
|
-
|
|
26
|
-
const blocked = [];
|
|
27
|
-
for (const task of Object.values(state.tasks ?? {})) {
|
|
28
|
-
if (task.tombstone === true) continue;
|
|
29
|
-
if (task.status !== 'pending') continue;
|
|
30
|
-
if (!isTaskBlocked(state, task)) continue;
|
|
31
|
-
blocked.push({
|
|
32
|
-
kind: RISK_KINDS.BLOCKED_TASK,
|
|
33
|
-
taskId: task.id,
|
|
34
|
-
taskNumber: task.number ?? null,
|
|
35
|
-
title: task.title ?? '',
|
|
36
|
-
ownerId: task.ownerId ?? null,
|
|
37
|
-
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
38
|
-
blockedBy: Array.isArray(task.blockedBy) ? [...task.blockedBy] : [],
|
|
39
|
-
waitingSince: task.updatedAt ?? null,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const failures = [];
|
|
44
|
-
for (const member of Object.values(state.members ?? {})) {
|
|
45
|
-
if (member.kind !== 'agent') continue;
|
|
46
|
-
const failure = member.lastFailure;
|
|
47
|
-
if (member.status !== 'failed' && (failure === undefined || failure === null)) continue;
|
|
48
|
-
// Ledgers written before the fold cleared lastFailure on recovery:
|
|
49
|
-
// a failure older than the last recovery is not an open risk.
|
|
50
|
-
if (failure !== undefined && failure !== null
|
|
51
|
-
&& Number.isFinite(member.lastRecoveredAt) && Number.isFinite(failure.at)
|
|
52
|
-
&& member.lastRecoveredAt >= failure.at) continue;
|
|
53
|
-
failures.push({
|
|
54
|
-
kind: RISK_KINDS.FAILED_MEMBER,
|
|
55
|
-
memberId: member.id,
|
|
56
|
-
name: member.name ?? member.id,
|
|
57
|
-
role: member.role ?? '',
|
|
58
|
-
status: member.status ?? 'idle',
|
|
59
|
-
category: failure?.category ?? null,
|
|
60
|
-
attempt: failure?.attempt ?? (member.attempts ?? 0),
|
|
61
|
-
message: failure?.message ?? member.failure ?? null,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const staleDecisions = [];
|
|
66
|
-
for (const item of Object.values(state.inbox ?? {})) {
|
|
67
|
-
if (humanId !== null && item.memberId !== humanId) continue;
|
|
68
|
-
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
69
|
-
if (item.state !== 'unread') continue;
|
|
70
|
-
const createdAt = item.createdAt ?? null;
|
|
71
|
-
const waitingHours = createdAt !== null && Number.isFinite(createdAt)
|
|
72
|
-
? Math.max(0, Math.round((now - createdAt) / (60 * 60 * 1000)))
|
|
73
|
-
: null;
|
|
74
|
-
if (createdAt === null || now - createdAt < staleHours * 60 * 60 * 1000) continue;
|
|
75
|
-
staleDecisions.push({
|
|
76
|
-
kind: RISK_KINDS.STALE_DECISION,
|
|
77
|
-
itemId: item.id,
|
|
78
|
-
title: item.ref?.title ?? item.type ?? 'decision_required',
|
|
79
|
-
taskId: item.ref?.taskId ?? null,
|
|
80
|
-
waitingHours,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
staleDecisions.sort((left, right) => (right.waitingHours ?? 0) - (left.waitingHours ?? 0));
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
rev: state.lastSeq ?? 0,
|
|
87
|
-
generatedAt: now,
|
|
88
|
-
blocked,
|
|
89
|
-
failures,
|
|
90
|
-
staleDecisions,
|
|
91
|
-
counts: {
|
|
92
|
-
blocked: blocked.length,
|
|
93
|
-
failures: failures.length,
|
|
94
|
-
staleDecisions: staleDecisions.length,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export { RISK_KINDS };
|
|
1
|
+
/**
|
|
2
|
+
* 风险清单投影(R-07 / 视图组合纪律 V1):三类需要 Human 注意的风险,
|
|
3
|
+
* 全部从既有账本投影只读聚合,零新事件、零新数据结构——
|
|
4
|
+
* 1. 受阻任务:pending 且依赖未完成(isTaskBlocked);
|
|
5
|
+
* 2. 失败成员:agent 带未清除的 lastFailure(或 status=failed);
|
|
6
|
+
* 3. 待决超时:Human 收件箱中 unread 的 decision_required,超过 staleHours。
|
|
7
|
+
*
|
|
8
|
+
* 输出行复用 quadrantItem 的形状约定(kind/taskId/taskNumber/title/...),
|
|
9
|
+
* 前端零新交互模式即可渲染。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { isTaskBlocked } from '../ledger/fold.js';
|
|
13
|
+
|
|
14
|
+
const RISK_KINDS = Object.freeze({
|
|
15
|
+
BLOCKED_TASK: 'blocked_task',
|
|
16
|
+
FAILED_MEMBER: 'failed_member',
|
|
17
|
+
STALE_DECISION: 'stale_decision',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export function riskView(state, { now = Date.now(), staleHours = 24 } = {}) {
|
|
21
|
+
const humanId = state.humanMemberId
|
|
22
|
+
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
23
|
+
?? null;
|
|
24
|
+
const cutoff = now - staleHours * 60 * 60 * 1000;
|
|
25
|
+
|
|
26
|
+
const blocked = [];
|
|
27
|
+
for (const task of Object.values(state.tasks ?? {})) {
|
|
28
|
+
if (task.tombstone === true) continue;
|
|
29
|
+
if (task.status !== 'pending') continue;
|
|
30
|
+
if (!isTaskBlocked(state, task)) continue;
|
|
31
|
+
blocked.push({
|
|
32
|
+
kind: RISK_KINDS.BLOCKED_TASK,
|
|
33
|
+
taskId: task.id,
|
|
34
|
+
taskNumber: task.number ?? null,
|
|
35
|
+
title: task.title ?? '',
|
|
36
|
+
ownerId: task.ownerId ?? null,
|
|
37
|
+
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
38
|
+
blockedBy: Array.isArray(task.blockedBy) ? [...task.blockedBy] : [],
|
|
39
|
+
waitingSince: task.updatedAt ?? null,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const failures = [];
|
|
44
|
+
for (const member of Object.values(state.members ?? {})) {
|
|
45
|
+
if (member.kind !== 'agent') continue;
|
|
46
|
+
const failure = member.lastFailure;
|
|
47
|
+
if (member.status !== 'failed' && (failure === undefined || failure === null)) continue;
|
|
48
|
+
// Ledgers written before the fold cleared lastFailure on recovery:
|
|
49
|
+
// a failure older than the last recovery is not an open risk.
|
|
50
|
+
if (failure !== undefined && failure !== null
|
|
51
|
+
&& Number.isFinite(member.lastRecoveredAt) && Number.isFinite(failure.at)
|
|
52
|
+
&& member.lastRecoveredAt >= failure.at) continue;
|
|
53
|
+
failures.push({
|
|
54
|
+
kind: RISK_KINDS.FAILED_MEMBER,
|
|
55
|
+
memberId: member.id,
|
|
56
|
+
name: member.name ?? member.id,
|
|
57
|
+
role: member.role ?? '',
|
|
58
|
+
status: member.status ?? 'idle',
|
|
59
|
+
category: failure?.category ?? null,
|
|
60
|
+
attempt: failure?.attempt ?? (member.attempts ?? 0),
|
|
61
|
+
message: failure?.message ?? member.failure ?? null,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const staleDecisions = [];
|
|
66
|
+
for (const item of Object.values(state.inbox ?? {})) {
|
|
67
|
+
if (humanId !== null && item.memberId !== humanId) continue;
|
|
68
|
+
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
69
|
+
if (item.state !== 'unread') continue;
|
|
70
|
+
const createdAt = item.createdAt ?? null;
|
|
71
|
+
const waitingHours = createdAt !== null && Number.isFinite(createdAt)
|
|
72
|
+
? Math.max(0, Math.round((now - createdAt) / (60 * 60 * 1000)))
|
|
73
|
+
: null;
|
|
74
|
+
if (createdAt === null || now - createdAt < staleHours * 60 * 60 * 1000) continue;
|
|
75
|
+
staleDecisions.push({
|
|
76
|
+
kind: RISK_KINDS.STALE_DECISION,
|
|
77
|
+
itemId: item.id,
|
|
78
|
+
title: item.ref?.title ?? item.type ?? 'decision_required',
|
|
79
|
+
taskId: item.ref?.taskId ?? null,
|
|
80
|
+
waitingHours,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
staleDecisions.sort((left, right) => (right.waitingHours ?? 0) - (left.waitingHours ?? 0));
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
rev: state.lastSeq ?? 0,
|
|
87
|
+
generatedAt: now,
|
|
88
|
+
blocked,
|
|
89
|
+
failures,
|
|
90
|
+
staleDecisions,
|
|
91
|
+
counts: {
|
|
92
|
+
blocked: blocked.length,
|
|
93
|
+
failures: failures.length,
|
|
94
|
+
staleDecisions: staleDecisions.length,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { RISK_KINDS };
|
package/lib/host/weekly-view.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 项目周报投影(R-11 / 视图组合纪律):同一份账本投影的窗口聚合,产出
|
|
3
|
-
* 正向/负向两种解读共用的数据结构——正向 = 完成了什么、一次通过多少;
|
|
4
|
-
* 负向 = 哪些返工了、Human 介入了几次、多少任务仍受阻。纯计数投影,
|
|
5
|
-
* 无新事件、无新数据结构。
|
|
6
|
-
*
|
|
7
|
-
* 口径(全部来自既有投影字段):
|
|
8
|
-
* - completed:status=done 且 updatedAt 在窗口内(done 的 updatedAt 即验收时间);
|
|
9
|
-
* - reworked:reviewRound ≥ 2(经历过 task/changes-requested)且窗口内有动静;
|
|
10
|
-
* - humanTouches:Thread 中 authorId === humanId 的条目数(窗口内 at)+
|
|
11
|
-
* 已答复决策数(requiresDecision 且 state==='done',ackedAt 窗口内);
|
|
12
|
-
* - humanTasks:ownerId === humanId 的活跃任务数("交给人"的负担面)。
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export function weeklyView(state, { now = Date.now(), weeks = 1 } = {}) {
|
|
16
|
-
const windowStart = now - weeks * 7 * 24 * 60 * 60 * 1000;
|
|
17
|
-
const humanId = state.humanMemberId
|
|
18
|
-
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
19
|
-
?? null;
|
|
20
|
-
|
|
21
|
-
const completed = [];
|
|
22
|
-
const reworked = [];
|
|
23
|
-
let createdCount = 0;
|
|
24
|
-
for (const task of Object.values(state.tasks ?? {})) {
|
|
25
|
-
if (task.tombstone === true) continue;
|
|
26
|
-
const touchedAt = Math.max(task.updatedAt ?? 0, task.createdAt ?? 0);
|
|
27
|
-
if (task.createdAt >= windowStart) createdCount += 1;
|
|
28
|
-
if (task.status === 'done' && (task.updatedAt ?? 0) >= windowStart) {
|
|
29
|
-
completed.push({
|
|
30
|
-
taskId: task.id,
|
|
31
|
-
number: task.number ?? null,
|
|
32
|
-
title: task.title ?? '',
|
|
33
|
-
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
34
|
-
reviewRound: task.reviewRound ?? 1,
|
|
35
|
-
updatedAt: task.updatedAt ?? null,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if ((task.reviewRound ?? 0) >= 2 && touchedAt >= windowStart) {
|
|
39
|
-
reworked.push({
|
|
40
|
-
taskId: task.id,
|
|
41
|
-
number: task.number ?? null,
|
|
42
|
-
title: task.title ?? '',
|
|
43
|
-
reviewRound: task.reviewRound,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let humanThreadMessages = 0;
|
|
49
|
-
for (const thread of Object.values(state.threads ?? {})) {
|
|
50
|
-
for (const entry of thread.entries ?? []) {
|
|
51
|
-
if ((entry.at ?? 0) >= windowStart && entry.authorId === humanId) humanThreadMessages += 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
let decisionsAnswered = 0;
|
|
55
|
-
for (const item of Object.values(state.inbox ?? {})) {
|
|
56
|
-
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
57
|
-
if (item.state !== 'done' && item.state !== 'resolved') continue;
|
|
58
|
-
// PMO 自动答复(decision.auto === true)不是 Human 介入:周报的
|
|
59
|
-
// 「零 Human」口径若把自动决策算进去,就永远看不到真实的人工干预。
|
|
60
|
-
if (item.decision?.auto === true) continue;
|
|
61
|
-
if ((item.ackedAt ?? 0) >= windowStart) decisionsAnswered += 1;
|
|
62
|
-
}
|
|
63
|
-
const humanTasks = humanId === null ? 0
|
|
64
|
-
: Object.values(state.tasks ?? {}).filter((task) =>
|
|
65
|
-
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
66
|
-
&& (task.ownerId === humanId || task.assigneeId === humanId)).length;
|
|
67
|
-
|
|
68
|
-
const completedTitles = completed.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title);
|
|
69
|
-
return {
|
|
70
|
-
windowStart,
|
|
71
|
-
generatedAt: now,
|
|
72
|
-
weeks,
|
|
73
|
-
completedCount: completed.length,
|
|
74
|
-
createdCount,
|
|
75
|
-
reworkedCount: reworked.length,
|
|
76
|
-
humanThreadMessages,
|
|
77
|
-
decisionsAnswered,
|
|
78
|
-
humanTasks,
|
|
79
|
-
completed,
|
|
80
|
-
reworked,
|
|
81
|
-
// 正向解读的数据面:完成的清单与「零 Human 发言」的直通任务。
|
|
82
|
-
positive: { completedTitles, humanThreadMessages, decisionsAnswered },
|
|
83
|
-
// 负向解读的数据面:返工清单(reviewRound>=2)与仍然阻塞/待人的任务。
|
|
84
|
-
negative: { reworkedTitles: reworked.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title), humanTasks },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 项目周报投影(R-11 / 视图组合纪律):同一份账本投影的窗口聚合,产出
|
|
3
|
+
* 正向/负向两种解读共用的数据结构——正向 = 完成了什么、一次通过多少;
|
|
4
|
+
* 负向 = 哪些返工了、Human 介入了几次、多少任务仍受阻。纯计数投影,
|
|
5
|
+
* 无新事件、无新数据结构。
|
|
6
|
+
*
|
|
7
|
+
* 口径(全部来自既有投影字段):
|
|
8
|
+
* - completed:status=done 且 updatedAt 在窗口内(done 的 updatedAt 即验收时间);
|
|
9
|
+
* - reworked:reviewRound ≥ 2(经历过 task/changes-requested)且窗口内有动静;
|
|
10
|
+
* - humanTouches:Thread 中 authorId === humanId 的条目数(窗口内 at)+
|
|
11
|
+
* 已答复决策数(requiresDecision 且 state==='done',ackedAt 窗口内);
|
|
12
|
+
* - humanTasks:ownerId === humanId 的活跃任务数("交给人"的负担面)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function weeklyView(state, { now = Date.now(), weeks = 1 } = {}) {
|
|
16
|
+
const windowStart = now - weeks * 7 * 24 * 60 * 60 * 1000;
|
|
17
|
+
const humanId = state.humanMemberId
|
|
18
|
+
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
19
|
+
?? null;
|
|
20
|
+
|
|
21
|
+
const completed = [];
|
|
22
|
+
const reworked = [];
|
|
23
|
+
let createdCount = 0;
|
|
24
|
+
for (const task of Object.values(state.tasks ?? {})) {
|
|
25
|
+
if (task.tombstone === true) continue;
|
|
26
|
+
const touchedAt = Math.max(task.updatedAt ?? 0, task.createdAt ?? 0);
|
|
27
|
+
if (task.createdAt >= windowStart) createdCount += 1;
|
|
28
|
+
if (task.status === 'done' && (task.updatedAt ?? 0) >= windowStart) {
|
|
29
|
+
completed.push({
|
|
30
|
+
taskId: task.id,
|
|
31
|
+
number: task.number ?? null,
|
|
32
|
+
title: task.title ?? '',
|
|
33
|
+
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
34
|
+
reviewRound: task.reviewRound ?? 1,
|
|
35
|
+
updatedAt: task.updatedAt ?? null,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if ((task.reviewRound ?? 0) >= 2 && touchedAt >= windowStart) {
|
|
39
|
+
reworked.push({
|
|
40
|
+
taskId: task.id,
|
|
41
|
+
number: task.number ?? null,
|
|
42
|
+
title: task.title ?? '',
|
|
43
|
+
reviewRound: task.reviewRound,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let humanThreadMessages = 0;
|
|
49
|
+
for (const thread of Object.values(state.threads ?? {})) {
|
|
50
|
+
for (const entry of thread.entries ?? []) {
|
|
51
|
+
if ((entry.at ?? 0) >= windowStart && entry.authorId === humanId) humanThreadMessages += 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let decisionsAnswered = 0;
|
|
55
|
+
for (const item of Object.values(state.inbox ?? {})) {
|
|
56
|
+
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
57
|
+
if (item.state !== 'done' && item.state !== 'resolved') continue;
|
|
58
|
+
// PMO 自动答复(decision.auto === true)不是 Human 介入:周报的
|
|
59
|
+
// 「零 Human」口径若把自动决策算进去,就永远看不到真实的人工干预。
|
|
60
|
+
if (item.decision?.auto === true) continue;
|
|
61
|
+
if ((item.ackedAt ?? 0) >= windowStart) decisionsAnswered += 1;
|
|
62
|
+
}
|
|
63
|
+
const humanTasks = humanId === null ? 0
|
|
64
|
+
: Object.values(state.tasks ?? {}).filter((task) =>
|
|
65
|
+
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
66
|
+
&& (task.ownerId === humanId || task.assigneeId === humanId)).length;
|
|
67
|
+
|
|
68
|
+
const completedTitles = completed.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title);
|
|
69
|
+
return {
|
|
70
|
+
windowStart,
|
|
71
|
+
generatedAt: now,
|
|
72
|
+
weeks,
|
|
73
|
+
completedCount: completed.length,
|
|
74
|
+
createdCount,
|
|
75
|
+
reworkedCount: reworked.length,
|
|
76
|
+
humanThreadMessages,
|
|
77
|
+
decisionsAnswered,
|
|
78
|
+
humanTasks,
|
|
79
|
+
completed,
|
|
80
|
+
reworked,
|
|
81
|
+
// 正向解读的数据面:完成的清单与「零 Human 发言」的直通任务。
|
|
82
|
+
positive: { completedTitles, humanThreadMessages, decisionsAnswered },
|
|
83
|
+
// 负向解读的数据面:返工清单(reviewRound>=2)与仍然阻塞/待人的任务。
|
|
84
|
+
negative: { reworkedTitles: reworked.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title), humanTasks },
|
|
85
|
+
};
|
|
86
|
+
}
|