@suifei/dsh-ai-team 0.4.90 → 0.4.92
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 +43 -0
- package/index.js +36 -0
- package/lib/diaglog.js +145 -143
- package/lib/domain/errors.js +0 -1
- package/lib/domain/thread.js +46 -54
- package/lib/host/member-tools.js +16 -4
- package/lib/host/service.js +1 -1
- package/lib/host/waker.js +5 -2
- package/lib/ledger/fold.js +18 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.92 - 2026-11-14
|
|
4
|
+
|
|
5
|
+
**会议并发回帖不再被拒:迟到的回帖照收,并把错过的发言带回去;PMO 叫不醒就不开会**
|
|
6
|
+
|
|
7
|
+
会议/复盘时多名成员读同一个 Thread head 后同时回帖,旧规则(`baseSeq` 必须等于 head,否则
|
|
8
|
+
`E_STALE_REPLY`)只放行第一条,其余重读、重写、再次落败——成员原话「三次回帖均因会议并发被拒」,
|
|
9
|
+
r09 一轮 46 次,失败计数全部来自这里。回帖本身没有错,只是晚了。
|
|
10
|
+
|
|
11
|
+
- `lib/domain/thread.js` `appendReply`:不再拒绝落后的 `baseSeq`,条目照记自己的 `baseSeq`,并返回
|
|
12
|
+
`missed`(读取之后新增的条目);超前的 `baseSeq` 仍是 `E_INVALID_ARGUMENT`。`E_STALE_REPLY` 错误码移除;
|
|
13
|
+
- `lib/host/member-tools.js` `reply`:有错过的他人发言时返回 `missed`(正文截 2000 字)与提示「只有它们
|
|
14
|
+
改变了你的结论才再补一条」;自己的旧帖不算错过;
|
|
15
|
+
- PMO 叫不醒就不开会(`lib/host/waker.js` `pmo/continue`):r13 中 PMO 因 AUTH 失败,定时推进仍把其余 5 名
|
|
16
|
+
成员拉进会议,无人主持、无人收口。现在 owner 不可唤醒(failed / retired / 缺失)时整场会议不规划;
|
|
17
|
+
- 测试:`node --test` **331 通过 / 1 跳过**;`waker` 新增无主持会议 1 条,`domain` 改写 1 条,新增 `thread-meeting`(三人并发全部落帖、
|
|
18
|
+
迟到者拿到错过的两条)。
|
|
19
|
+
- E2E(隔离 DSH_HOME,项目「排序-B」派一种排序,12 分钟):线程 7 条回帖中 2 条迟到(seq 4 基于 2、seq 5
|
|
20
|
+
基于 3)全部落帖,`E_STALE_REPLY` 0、`dispatch.fail` 0(旧规则下这 2 条会被拒并重写)。
|
|
21
|
+
|
|
22
|
+
## 0.4.91 - 2026-11-14
|
|
23
|
+
|
|
24
|
+
**停止即中断成员回合;重启不再惊动已静默的团队;已绑定的 PMO 会话启动即归入工作区**
|
|
25
|
+
|
|
26
|
+
- 停止即中断(`index.js` `interruptTeam`):停止门只拦新的自动派发,已在跑的回合会一直干下去——实机 il2c
|
|
27
|
+
12:34:20 停止后,青岚 12:39 仍提交了 #100、玄策 12:44 仍在 #101 发帖。现在项目切到 stopped 时对每个成员
|
|
28
|
+
`subagents.interrupt(sessionId, {kind:'user', parentSessionId: PMO 会话})`:取消当前执行,未认领收件保留、
|
|
29
|
+
Task 状态不动,重新运行后由心跳/巡检接着推进。rc.1 的 user 权威校验直接父会话(不带则 UNAUTHORIZED
|
|
30
|
+
「belongs to another parent session」,首轮 E2E 实测),rc.3 不校验该字段。诊断 `team.interrupt` 保留在
|
|
31
|
+
errors 级别;
|
|
32
|
+
- 簿记事件不算 Human 意图(`lib/ledger/fold.js` `isHumanIntent`,`FOLD_STATE_VERSION` 6→7):插件激活成员时以
|
|
33
|
+
Human 身份记 `member/session-bound`(失败记 `member/failed`),反思后记 `member/distilled`。它们曾被当作
|
|
34
|
+
Human 动作——每次重启重新激活成员,就重置 PMO 预算并把 `pmoNews` 置真,已静默的项目在启动 1 秒内各开一次会
|
|
35
|
+
(r10 重启复验:两项目各 1 次推进 + 5 次会议唤醒)。有界预算与新进展判定共用这一个判定;历史账本无需迁移;
|
|
36
|
+
- PMO 会话启动即归入工作区(`index.js` 启动修复):0.4.90 之前的 host 从未 attach,侧栏里挂在「未分组」;
|
|
37
|
+
而 `ensureParent` 只在唤醒时才跑,`pmoAuto` 关闭、看板静止的项目重载后永远等不到(实机 il2c:7 个成员已入
|
|
38
|
+
工作区,唯独 PMO 不在)。现在随归档修复一起对每个项目的 `hostSessionId` 做 `attachSession`,只动注册表、
|
|
39
|
+
不唤醒会话;cwd 不符的旧 host 记 `workspace.attach.fail`,下次唤醒由 `ensureParent` 换新;
|
|
40
|
+
- 测试:`node --test` **329 通过 / 1 跳过**;`pmo-quiet` 新增重启簿记 1 条,`host` 新增停止中断断言;
|
|
41
|
+
- E2E(隔离 DSH_HOME):从 `workspace.json` 摘掉两个 PMO 会话后重启 → 两个工作区各自重新挂回;用新折叠重放
|
|
42
|
+
r10 重启账本,推进前 `pmoNews` 为 false(旧折叠为 true);静默项目重启 150 秒内 0 次推进、0 次会议唤醒。
|
|
43
|
+
停止中断:主理人回合进行中停止 → 6 名成员中断,停止 15 秒后 0 个成员会话再写入;新建项目(新工作区)
|
|
44
|
+
启动后 PMO 会话与成员会话归入该工作区,侧栏挂在项目分组下。
|
|
45
|
+
|
|
3
46
|
## 0.4.90 - 2026-11-14
|
|
4
47
|
|
|
5
48
|
**核心模型落地:每个项目一个 PMO 会话,成员会话归入项目工作区;PMO 成为主流唯一发言人(先对话后开卡)**
|
package/index.js
CHANGED
|
@@ -716,6 +716,33 @@ export function apply(ctx, config = {}) {
|
|
|
716
716
|
// 每个项目一个 PMO 会话(核心模型):projectId → 已就绪的 host / 进行中的创建。
|
|
717
717
|
const hosts = new Map();
|
|
718
718
|
const hostPromises = new Map();
|
|
719
|
+
/**
|
|
720
|
+
* Human 停止项目:中断每个成员**正在进行的回合**。停止门只拦新的自动派发,已在跑
|
|
721
|
+
* 的回合会一直干下去(实机 il2c:点停止后两名成员仍执行命令、写会话)。
|
|
722
|
+
* `subagents.interrupt` 以 user 权威取消当前执行;未认领的收件保留、Task 状态不动,
|
|
723
|
+
* 重新运行后由心跳/巡检接着推进。缺此能力的宿主记一次 .fail,不影响停止本身。
|
|
724
|
+
* user 权威必须带直接父会话:rc.1 校验 `activation.parent.id === parentSessionId`
|
|
725
|
+
* (否则 UNAUTHORIZED「belongs to another parent session」),rc.3 不校验此字段。
|
|
726
|
+
* 成员都是本项目 PMO 会话的直接子会话。
|
|
727
|
+
*/
|
|
728
|
+
const interruptTeam = (projectRuntime) => {
|
|
729
|
+
const subagents = serviceOf(ctx, 'subagents');
|
|
730
|
+
if (typeof subagents?.interrupt !== 'function') {
|
|
731
|
+
diag.append({ ev: 'team.interrupt.unavailable.fail', projectId: projectRuntime.id });
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
const interrupted = [];
|
|
735
|
+
for (const member of Object.values(projectRuntime.service.state.members ?? {})) {
|
|
736
|
+
if (member.kind !== 'agent' || typeof member.sessionId !== 'string' || member.sessionId === '') continue;
|
|
737
|
+
try {
|
|
738
|
+
subagents.interrupt(member.sessionId, { kind: 'user', parentSessionId: projectRuntime.service.state.hostSessionId });
|
|
739
|
+
interrupted.push(member.id);
|
|
740
|
+
} catch (error) {
|
|
741
|
+
diag.append({ ev: 'team.interrupt.fail', projectId: projectRuntime.id, memberId: member.id, message: error?.message ?? String(error) });
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
diag.append({ ev: 'team.interrupt', projectId: projectRuntime.id, members: interrupted });
|
|
745
|
+
};
|
|
719
746
|
const wakeKeys = new Map();
|
|
720
747
|
// provider 探测状态去重:能力缺失/确认无 provider 只各记一次,避免每轮刷日志。
|
|
721
748
|
let lastProviderState = '';
|
|
@@ -1790,6 +1817,14 @@ export function apply(ctx, config = {}) {
|
|
|
1790
1817
|
return;
|
|
1791
1818
|
}
|
|
1792
1819
|
hostRepaired = true;
|
|
1820
|
+
// 已绑定的 PMO 会话归入项目工作区(只动注册表,不唤醒会话)。0.4.90 之前的
|
|
1821
|
+
// host 从未 attach,侧栏里挂在「未分组」;而 ensureParent 只在唤醒时才跑,
|
|
1822
|
+
// pmoAuto 关闭、看板静止的项目重载后永远等不到那一次(实机 il2c:7 个成员
|
|
1823
|
+
// 已入工作区,唯独 PMO 不在)。cwd 不符的旧 host 会 attach 失败并记 .fail,
|
|
1824
|
+
// 下次唤醒由 ensureParent 换成项目工作区里的新 PMO。
|
|
1825
|
+
for (const runtime of booted?.runtimes?.values() ?? []) {
|
|
1826
|
+
await attachMemberWorkspace(runtime, runtime?.service?.state?.hostSessionId);
|
|
1827
|
+
}
|
|
1793
1828
|
// 成功行必须留在 errors 级别:否则「归档修复有没有跑过」永远无法判定
|
|
1794
1829
|
// (只有 boot 瞬间那一行 deferred.fail 可见,见 lib/diaglog.js 白名单)。
|
|
1795
1830
|
diag.append({
|
|
@@ -2002,6 +2037,7 @@ export function apply(ctx, config = {}) {
|
|
|
2002
2037
|
attachRuntime = (runtime) => {
|
|
2003
2038
|
runtime.ledger.onEvent = (event) => {
|
|
2004
2039
|
broadcast(event, runtime);
|
|
2040
|
+
if (event?.type === 'project/run-state' && event.payload?.runState === 'stopped') interruptTeam(runtime);
|
|
2005
2041
|
const actorId = event?.actor?.kind === 'agent' ? event.actor.memberId : undefined;
|
|
2006
2042
|
void wakeFromResult(runtime, { event }, actorId === undefined ? {} : { agentId: actorId }).catch((error) => {
|
|
2007
2043
|
diag.append({ ev: 'wake.plan.fail', projectId: runtime.id, eventType: event?.type ?? null, message: error?.message ?? String(error) });
|
package/lib/diaglog.js
CHANGED
|
@@ -1,143 +1,145 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin-owned diagnostic log: one JSONL file per day, appended serially,
|
|
3
|
-
* rotated at a byte cap, and readable back through tail(). Both the Host
|
|
4
|
-
* (boot, dispatch, wake, PMO, member failure/recovery) and the Client half
|
|
5
|
-
* (via route rows) write into it, so "the panel shows no data" is answerable
|
|
6
|
-
* from evidence. Levels: 'off' silent, 'errors' crash/fail rows only
|
|
7
|
-
* (shipped default), 'full' everything (development).
|
|
8
|
-
*/
|
|
9
|
-
import { appendFile, mkdir, readFile, rename, stat } from 'node:fs/promises';
|
|
10
|
-
import { homedir } from 'node:os';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
|
|
13
|
-
/** The date-stamped file name carries the day; rows carry projectId/projectName. */
|
|
14
|
-
export function diagFileName(date = new Date()) {
|
|
15
|
-
return `aiteam-diag-${date.toISOString().slice(0, 10)}.jsonl`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function defaultDiagDir() {
|
|
19
|
-
// 必须与插件数据目录同源(`dshHome()`):否则设置了 `DSH_HOME` 的隔离实例
|
|
20
|
-
// (测试、临时 profile)会把诊断行写进**真实**的 `~/.dsh/ai-team`,污染生产日志
|
|
21
|
-
// ——实机上就混进过 `E:/definitely-not-existing-dir-xyz` 这类测试夹具的行。
|
|
22
|
-
const home = typeof process.env.DSH_HOME === 'string' && process.env.DSH_HOME.trim() !== ''
|
|
23
|
-
? process.env.DSH_HOME
|
|
24
|
-
: join(homedir(), '.dsh');
|
|
25
|
-
return join(home, 'ai-team');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Rows worth keeping when the logger runs in `errors` mode. */
|
|
29
|
-
export function isErrorEvent(ev) {
|
|
30
|
-
return typeof ev === 'string'
|
|
31
|
-
&& (ev.endsWith('.fail') || ev === 'boot.refused' || ev === 'route.reject' || ev === 'ledger.repair'
|
|
32
|
-
// 归档修复的**成功**行必须留在 `errors` 级别:否则「修没修」永远无法
|
|
33
|
-
// 判定(只有 boot 瞬间那一行 deferred.fail 可见)。
|
|
34
|
-
|| ev === 'host.repair.ok'
|
|
35
|
-
// 成员会话自愈(NOT_RESUMABLE → 重建)同理:它决定「成员还会不会被唤醒」,
|
|
36
|
-
// 必须在发布默认级别可见,否则只能看到一连串 wake.fail 而不知道有没有救回来。
|
|
37
|
-
|| ev === 'member.autoreseat'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Plugin-owned diagnostic log: one JSONL file per day, appended serially,
|
|
3
|
+
* rotated at a byte cap, and readable back through tail(). Both the Host
|
|
4
|
+
* (boot, dispatch, wake, PMO, member failure/recovery) and the Client half
|
|
5
|
+
* (via route rows) write into it, so "the panel shows no data" is answerable
|
|
6
|
+
* from evidence. Levels: 'off' silent, 'errors' crash/fail rows only
|
|
7
|
+
* (shipped default), 'full' everything (development).
|
|
8
|
+
*/
|
|
9
|
+
import { appendFile, mkdir, readFile, rename, stat } from 'node:fs/promises';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
/** The date-stamped file name carries the day; rows carry projectId/projectName. */
|
|
14
|
+
export function diagFileName(date = new Date()) {
|
|
15
|
+
return `aiteam-diag-${date.toISOString().slice(0, 10)}.jsonl`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function defaultDiagDir() {
|
|
19
|
+
// 必须与插件数据目录同源(`dshHome()`):否则设置了 `DSH_HOME` 的隔离实例
|
|
20
|
+
// (测试、临时 profile)会把诊断行写进**真实**的 `~/.dsh/ai-team`,污染生产日志
|
|
21
|
+
// ——实机上就混进过 `E:/definitely-not-existing-dir-xyz` 这类测试夹具的行。
|
|
22
|
+
const home = typeof process.env.DSH_HOME === 'string' && process.env.DSH_HOME.trim() !== ''
|
|
23
|
+
? process.env.DSH_HOME
|
|
24
|
+
: join(homedir(), '.dsh');
|
|
25
|
+
return join(home, 'ai-team');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Rows worth keeping when the logger runs in `errors` mode. */
|
|
29
|
+
export function isErrorEvent(ev) {
|
|
30
|
+
return typeof ev === 'string'
|
|
31
|
+
&& (ev.endsWith('.fail') || ev === 'boot.refused' || ev === 'route.reject' || ev === 'ledger.repair'
|
|
32
|
+
// 归档修复的**成功**行必须留在 `errors` 级别:否则「修没修」永远无法
|
|
33
|
+
// 判定(只有 boot 瞬间那一行 deferred.fail 可见)。
|
|
34
|
+
|| ev === 'host.repair.ok'
|
|
35
|
+
// 成员会话自愈(NOT_RESUMABLE → 重建)同理:它决定「成员还会不会被唤醒」,
|
|
36
|
+
// 必须在发布默认级别可见,否则只能看到一连串 wake.fail 而不知道有没有救回来。
|
|
37
|
+
|| ev === 'member.autoreseat'
|
|
38
|
+
// Human 停止时中断了哪些成员:决定「停了之后还在跑」是不是插件的锅。
|
|
39
|
+
|| ev === 'team.interrupt');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param options - { dir, maxBytes, now, enabled, level } seams for tests.
|
|
44
|
+
* `level`: 'off' drops every row (published default footprint), 'errors' keeps
|
|
45
|
+
* only crash/fail rows, 'full' writes everything (development).
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* 共享失败汇(进程级):库模块(ledger / registry / host-agent / skill-provider /
|
|
49
|
+
* jobs)拿不到 `diag` 实例,此前只能 `console.warn`——线上这些信息不可检索。
|
|
50
|
+
* 插件在 boot 时用 `installDiagSink()` 把真正的 diag 接进来;所有 `reportFail`
|
|
51
|
+
* 事件名以 `.fail` 结尾,因此在发布默认的 `errors` 级别下也会落盘。
|
|
52
|
+
*/
|
|
53
|
+
let sharedSink = null;
|
|
54
|
+
|
|
55
|
+
/** @returns {() => void} 卸载函数(teardown 时调用,避免热重载后写旧实例)。 */
|
|
56
|
+
export function installDiagSink(sink) {
|
|
57
|
+
sharedSink = typeof sink === 'function' ? sink : null;
|
|
58
|
+
return () => { if (sharedSink === sink) sharedSink = null; };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 记录一条失败:既进 diag(可检索),也保留原有 console 输出(开发期可见)。
|
|
63
|
+
* diag 写入永不抛出——诊断通道不能反过来把调用方弄挂。
|
|
64
|
+
*/
|
|
65
|
+
export function reportFail(event, payload = {}, consoleText = '') {
|
|
66
|
+
try {
|
|
67
|
+
if (sharedSink !== null) sharedSink({ ev: event, ...payload });
|
|
68
|
+
} catch { /* diagnostics must never break the caller */ }
|
|
69
|
+
if (consoleText !== '') {
|
|
70
|
+
try { console.warn(consoleText); } catch { /* console may be gone */ }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function createDiagLogger(options = {}) {
|
|
74
|
+
const dir = options.dir ?? defaultDiagDir();
|
|
75
|
+
const maxBytes = options.maxBytes ?? 1048576;
|
|
76
|
+
const enabled = options.enabled !== false;
|
|
77
|
+
const level = ['off', 'errors', 'full'].includes(options.level) ? options.level : 'errors';
|
|
78
|
+
const now = options.now ?? (() => new Date());
|
|
79
|
+
let queue = Promise.resolve();
|
|
80
|
+
let dirReady = null;
|
|
81
|
+
/** @type {number} */
|
|
82
|
+
let appended = 0;
|
|
83
|
+
|
|
84
|
+
const ensureDir = () => {
|
|
85
|
+
if (dirReady === null) dirReady = mkdir(dir, { recursive: true });
|
|
86
|
+
return dirReady;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const path = () => join(dir, diagFileName(now()));
|
|
90
|
+
|
|
91
|
+
function append(row) {
|
|
92
|
+
if (!enabled || level === 'off' || (level === 'errors' && !isErrorEvent(row.ev))) return queue;
|
|
93
|
+
const line = `${JSON.stringify({ t: now().toISOString(), ...row })}\n`;
|
|
94
|
+
queue = queue.then(async () => {
|
|
95
|
+
await ensureDir();
|
|
96
|
+
appended++;
|
|
97
|
+
if (appended % 20 === 1) {
|
|
98
|
+
// Cheap periodic rotation: stat at most every 20 appends.
|
|
99
|
+
try {
|
|
100
|
+
const info = await stat(path());
|
|
101
|
+
if (info.size > maxBytes) await rename(path(), `${path()}.1`);
|
|
102
|
+
} catch { /* first write: nothing to rotate */ }
|
|
103
|
+
}
|
|
104
|
+
await appendFile(path(), line, 'utf8');
|
|
105
|
+
}).catch(() => void 0);
|
|
106
|
+
return queue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Read back the newest rows of today's file.
|
|
111
|
+
* @param count - rows to return, newest last.
|
|
112
|
+
*/
|
|
113
|
+
async function tail(count = 50) {
|
|
114
|
+
let text = '';
|
|
115
|
+
try {
|
|
116
|
+
text = await readFile(path(), 'utf8');
|
|
117
|
+
} catch {
|
|
118
|
+
return { file: path(), rows: [] };
|
|
119
|
+
}
|
|
120
|
+
const rows = text
|
|
121
|
+
.split('\n')
|
|
122
|
+
.filter((line) => line !== '')
|
|
123
|
+
.map((line) => {
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(line);
|
|
126
|
+
} catch {
|
|
127
|
+
return { t: '?', ev: 'unparsed', line };
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return { file: path(), rows: rows.slice(-Math.max(1, Math.min(500, count))) };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
append,
|
|
135
|
+
tail,
|
|
136
|
+
path,
|
|
137
|
+
dir,
|
|
138
|
+
get level() {
|
|
139
|
+
return level;
|
|
140
|
+
},
|
|
141
|
+
get queueSize() {
|
|
142
|
+
return appended;
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
package/lib/domain/errors.js
CHANGED
|
@@ -24,7 +24,6 @@ export const ERRORS = {
|
|
|
24
24
|
BLOCKED: 'E_TASK_BLOCKED',
|
|
25
25
|
NOT_READY: 'E_TASK_NOT_READY',
|
|
26
26
|
NOT_ELIGIBLE: 'E_REVIEWER_NOT_ELIGIBLE',
|
|
27
|
-
STALE_REPLY: 'E_STALE_REPLY',
|
|
28
27
|
LIMIT: 'E_LIMIT',
|
|
29
28
|
IRREVERSIBLE_CONFIRM: 'E_IRREVERSIBLE_CONFIRM_REQUIRED',
|
|
30
29
|
INVALID_ARGUMENT: 'E_INVALID_ARGUMENT',
|
package/lib/domain/thread.js
CHANGED
|
@@ -1,54 +1,46 @@
|
|
|
1
|
-
import { ERRORS, fail } from './errors.js';
|
|
2
|
-
|
|
3
|
-
/** A thread is one append-only conversation attached to a Task. */
|
|
4
|
-
export function createThread(taskId) {
|
|
5
|
-
return { taskId, headSeq: 0, entries: [] };
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Append a reply.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
entry,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Entries after `baseSeq`, used by the stale-reply error and the UI diff. */
|
|
52
|
-
export function entriesSince(thread, baseSeq) {
|
|
53
|
-
return thread.entries.filter((entry) => entry.seq > baseSeq);
|
|
54
|
-
}
|
|
1
|
+
import { ERRORS, fail } from './errors.js';
|
|
2
|
+
|
|
3
|
+
/** A thread is one append-only conversation attached to a Task. */
|
|
4
|
+
export function createThread(taskId) {
|
|
5
|
+
return { taskId, headSeq: 0, entries: [] };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Append a reply. `baseSeq` is the head the author read; it is recorded on the
|
|
10
|
+
* entry, and every entry that landed after it comes back as `missed`, so the
|
|
11
|
+
* author learns what it did not see and can follow up if that changes its view.
|
|
12
|
+
*
|
|
13
|
+
* A stale `baseSeq` used to be rejected (E_STALE_REPLY). In a meeting five
|
|
14
|
+
* members read the same head and answer at once: only the first got through,
|
|
15
|
+
* the rest re-read, re-wrote and lost again ("三次回帖均因会议并发被拒";
|
|
16
|
+
* r09: 46 rejections in one round). The reply itself was never wrong — only
|
|
17
|
+
* late — so it is accepted and the gap is reported instead.
|
|
18
|
+
*/
|
|
19
|
+
export function appendReply(thread, input, options = {}) {
|
|
20
|
+
const body = typeof input.body === 'string' ? input.body.trim() : '';
|
|
21
|
+
if (body === '') fail(ERRORS.INVALID_ARGUMENT, 'reply body is required');
|
|
22
|
+
if (body.length > 16_384) fail(ERRORS.INVALID_ARGUMENT, 'reply body is too long');
|
|
23
|
+
if (typeof input.authorId !== 'string' || input.authorId === '') fail(ERRORS.INVALID_ARGUMENT, 'authorId is required');
|
|
24
|
+
const baseSeq = input.baseSeq ?? 0;
|
|
25
|
+
if (!Number.isSafeInteger(baseSeq) || baseSeq < 0) fail(ERRORS.INVALID_ARGUMENT, 'baseSeq must be a non-negative integer');
|
|
26
|
+
if (baseSeq > thread.headSeq) fail(ERRORS.INVALID_ARGUMENT, 'baseSeq is ahead of the thread head');
|
|
27
|
+
const missed = entriesSince(thread, baseSeq);
|
|
28
|
+
const entry = {
|
|
29
|
+
seq: thread.headSeq + 1,
|
|
30
|
+
authorId: input.authorId,
|
|
31
|
+
baseSeq,
|
|
32
|
+
body,
|
|
33
|
+
at: options.at ?? Date.now(),
|
|
34
|
+
refs: [...(input.refs ?? [])],
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
thread: { ...thread, headSeq: entry.seq, entries: [...thread.entries, entry] },
|
|
38
|
+
entry,
|
|
39
|
+
missed,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Entries after `baseSeq`, reported as `missed` on a late reply and used by the UI diff. */
|
|
44
|
+
export function entriesSince(thread, baseSeq) {
|
|
45
|
+
return thread.entries.filter((entry) => entry.seq > baseSeq);
|
|
46
|
+
}
|
package/lib/host/member-tools.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* once the AI Team runtime booted (see index.js `when`); the tool itself still
|
|
4
4
|
* refuses any session that is not a live Team member (`E_NOT_MEMBER`).
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Task mutations require `expectedRevision` (CAS). A reply carries `baseSeq`
|
|
7
|
+
* (the head it was written against); a late reply is accepted and the entries it
|
|
8
|
+
* missed come back in the result. Errors are returned as data so the member can re-read.
|
|
8
9
|
*/
|
|
9
10
|
import { taskCard } from './views.js';
|
|
10
11
|
import { isQaMember } from '../domain/member-profile.js';
|
|
@@ -62,7 +63,7 @@ export function createTeamTool(options) {
|
|
|
62
63
|
action: { type: 'string', enum: ACTIONS, description: 'Operation to perform.' },
|
|
63
64
|
taskId: { type: 'string', description: 'Task id from tasks.' },
|
|
64
65
|
expectedRevision: { type: 'integer', description: 'Task revision from tasks/claim; required for claim/submit/accept/requestChanges.' },
|
|
65
|
-
baseSeq: { type: 'integer', description: 'Thread headSeq read before replying; required for reply.' },
|
|
66
|
+
baseSeq: { type: 'integer', description: 'Thread headSeq read before replying; required for reply. A late reply is still posted and returns the entries you missed.' },
|
|
66
67
|
afterSeq: { type: 'integer', description: 'Return Thread entries after this seq.' },
|
|
67
68
|
summary: { type: 'string', description: 'What was done, for submit.' },
|
|
68
69
|
evidence: { type: 'array', items: { type: 'string' }, description: 'Evidence strings/paths, at least one for submit.' },
|
|
@@ -297,7 +298,18 @@ export function createTeamTool(options) {
|
|
|
297
298
|
if (!Number.isSafeInteger(args.baseSeq)) return failure({ code: 'E_INVALID_ARGUMENT', message: 'baseSeq is required; read thread first' });
|
|
298
299
|
if (typeof args.body !== 'string' || args.body.trim() === '') return failure({ code: 'E_INVALID_ARGUMENT', message: 'body is required' });
|
|
299
300
|
const result = await command('thread.post', { taskId: args.taskId, baseSeq: args.baseSeq, body: args.body });
|
|
300
|
-
|
|
301
|
+
const missed = (result.missed ?? []).filter((entry) => entry.authorId !== member.id);
|
|
302
|
+
if (missed.length === 0) return { ok: true, taskId: args.taskId, headSeq: result.thread.headSeq, entry: result.entry };
|
|
303
|
+
// 迟到的回帖照收(会议里并发是常态),把读取之后新增的发言带回去:
|
|
304
|
+
// 只有它们改变了你的结论才再补一条,不要为了「对齐」重复发言。
|
|
305
|
+
return {
|
|
306
|
+
ok: true,
|
|
307
|
+
taskId: args.taskId,
|
|
308
|
+
headSeq: result.thread.headSeq,
|
|
309
|
+
entry: result.entry,
|
|
310
|
+
missed: missed.map((entry) => ({ seq: entry.seq, authorId: entry.authorId, body: entry.body.slice(0, 2000) })),
|
|
311
|
+
note: `posted; ${missed.length} repl${missed.length === 1 ? 'y' : 'ies'} landed after you read the thread (shown in missed). Reply again only if they change your answer.`,
|
|
312
|
+
};
|
|
301
313
|
}
|
|
302
314
|
if (args.action === 'say') {
|
|
303
315
|
// 核心模型:只有项目 PMO 面向 Human 说话(主对话);成员在各自 Task Thread 里协作。
|
package/lib/host/service.js
CHANGED
|
@@ -1380,7 +1380,7 @@ export class TeamService {
|
|
|
1380
1380
|
projectId: command.projectId,
|
|
1381
1381
|
at: this.now(),
|
|
1382
1382
|
});
|
|
1383
|
-
return { thread: this.state.threads?.[taskId] ?? outcome.thread, entry: outcome.entry };
|
|
1383
|
+
return { thread: this.state.threads?.[taskId] ?? outcome.thread, entry: outcome.entry, missed: outcome.missed };
|
|
1384
1384
|
});
|
|
1385
1385
|
}
|
|
1386
1386
|
|
package/lib/host/waker.js
CHANGED
|
@@ -286,8 +286,11 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
286
286
|
const bucket = event.payload?.bucket ?? Math.floor(Date.now() / 600_000);
|
|
287
287
|
const ownerId = project?.ownerMemberId;
|
|
288
288
|
// PMO meetings include every agent member; the owner leads, everyone
|
|
289
|
-
// else contributes from their own professional seat.
|
|
290
|
-
|
|
289
|
+
// else contributes from their own professional seat. No wakeable owner,
|
|
290
|
+
// no meeting: r13 convened five members around a failed PMO (AUTH) —
|
|
291
|
+
// a headless meeting that nobody chairs or closes.
|
|
292
|
+
const members = agentMember(state, ownerId) === null ? [] : Object.values(state.members ?? {});
|
|
293
|
+
for (const member of members) {
|
|
291
294
|
if (member.kind !== 'agent' || member.status === 'retired') continue;
|
|
292
295
|
if (member.id === ownerId) {
|
|
293
296
|
add(member.id, null, 'pmo_continue', `pmo:${project?.id ?? 'project'}:${bucket}`);
|
package/lib/ledger/fold.js
CHANGED
|
@@ -47,8 +47,11 @@ import { isReviewCandidate } from '../domain/policy.js';
|
|
|
47
47
|
* v5:`team/host-bound` 换 PMO 会话时把已有会话的成员标为 routeStale(每项目一个 PMO)。
|
|
48
48
|
*
|
|
49
49
|
* v6:新增 `pmoNews`(见 applyEvent):PMO 看过空看板之后,没有新进展就不再定时推进。
|
|
50
|
+
*
|
|
51
|
+
* v7:插件内部以 Human 身份记的簿记事件(会话绑定 / 激活失败 / 人格蒸馏)不再算
|
|
52
|
+
* Human 意图——它们曾在每次重启时重置 PMO 预算并触发一次推进。
|
|
50
53
|
*/
|
|
51
|
-
export const FOLD_STATE_VERSION =
|
|
54
|
+
export const FOLD_STATE_VERSION = 7;
|
|
52
55
|
|
|
53
56
|
/**
|
|
54
57
|
* 投影封顶:大规模/长迭代账本下,stream 与每个 Thread 的 entries 不随事件数
|
|
@@ -675,14 +678,26 @@ function applyFollow(state, event, payload, following) {
|
|
|
675
678
|
* - PMO 被成功唤醒去看局面(pmo_continue / wave_done / human_message)→ false。
|
|
676
679
|
* r09:两个项目目标完成后,PMO 每 10 分钟被推进一次、拉 5 名成员开会,再发一条
|
|
677
680
|
* 「状态不变」,35 分钟 8 次推进 / 40 次会议唤醒;wave_done 与 pmo_continue 还在同一秒重复。
|
|
681
|
+
*
|
|
682
|
+
* 「Human 作者事件」指 Human 意图(`isHumanIntent`)。插件激活成员时以 Human 身份记
|
|
683
|
+
* `member/session-bound`(失败记 `member/failed`),反思后记 `member/distilled`;历史账本
|
|
684
|
+
* 里已大量存在。重启即重新激活成员,若把它们算作 Human 动作,每次重启都会重置预算
|
|
685
|
+
* 并推进一次(r10 复验:重启 1 秒内两个已静默项目各开会一次)。
|
|
678
686
|
*/
|
|
687
|
+
const HUMAN_BOOKKEEPING_EVENTS = new Set(['member/session-bound', 'member/failed', 'member/distilled']);
|
|
688
|
+
|
|
689
|
+
/** 事件是否代表 Human 的意图(而不是插件代 Human 记的簿记)。 */
|
|
690
|
+
export function isHumanIntent(event) {
|
|
691
|
+
return event?.actor?.kind === 'human' && !HUMAN_BOOKKEEPING_EVENTS.has(event.type);
|
|
692
|
+
}
|
|
693
|
+
|
|
679
694
|
const PMO_NEWS_TASK_EVENTS = new Set(['task/accepted', 'task/cancelled', 'task/deleted']);
|
|
680
695
|
const PMO_SEEN_REASONS = new Set(['pmo_continue', 'wave_done', 'human_message']);
|
|
681
696
|
|
|
682
697
|
export function applyEvent(state, event) {
|
|
683
698
|
const next = applyBudget(state, event, applyEventCore(state, event));
|
|
684
699
|
if (next === state) return next;
|
|
685
|
-
if (event
|
|
700
|
+
if (isHumanIntent(event) || PMO_NEWS_TASK_EVENTS.has(event.type)) {
|
|
686
701
|
return next.pmoNews === true ? next : { ...next, pmoNews: true };
|
|
687
702
|
}
|
|
688
703
|
if (event.type === 'wake/delivered' && PMO_SEEN_REASONS.has(event.payload?.reason)) {
|
|
@@ -699,7 +714,7 @@ export function pmoHasNews(state) {
|
|
|
699
714
|
function applyBudget(state, event, next) {
|
|
700
715
|
if (next === state) return next;
|
|
701
716
|
if (event.type === 'project/pmo-capped') return { ...next, pmoCapped: true };
|
|
702
|
-
if (event
|
|
717
|
+
if (isHumanIntent(event)) {
|
|
703
718
|
if (next.pmoFreeWave === true && (next.pmoRoundsUsed ?? 0) === 0 && next.pmoCapped !== true) return next;
|
|
704
719
|
return { ...next, pmoFreeWave: true, pmoRoundsUsed: 0, pmoCapped: false };
|
|
705
720
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.92",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|