@suifei/dsh-ai-team 0.3.56 → 0.3.60
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 +53 -0
- package/client.js +634 -65
- package/index.js +185 -23
- package/lib/diaglog.js +1 -1
- package/lib/host/people-view.js +104 -0
- package/lib/host/risk-view.js +94 -0
- package/lib/host/service.js +44 -31
- package/lib/host/waker.js +11 -1
- package/lib/host/weekly-view.js +83 -0
- package/lib/ledger/tools.js +118 -0
- package/lib/ledger/writer.js +6 -1
- package/lib/runtime/failure-policy.js +3 -1
- package/lib/runtime/member-runtime.js +2 -2
- package/lib/vendor/skillopt/src/index.js +12 -0
- package/package.json +1 -1
package/lib/host/service.js
CHANGED
|
@@ -120,16 +120,14 @@ export class TeamService {
|
|
|
120
120
|
? []
|
|
121
121
|
: (state.stream ?? []).filter((entry) => entry.projectId === project.id).slice(-200);
|
|
122
122
|
const selected = threadTaskId ?? tasks.find((task) => task.status === 'in_progress')?.id ?? tasks[0]?.id;
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (full === undefined) return [task.id, { taskId: task.id, headSeq: 0, entries: [], entryTotal: 0 }];
|
|
123
|
+
const threadOf = (taskId) => {
|
|
124
|
+
const full = taskId === undefined || taskId === null ? undefined : state.threads?.[taskId];
|
|
125
|
+
if (full === undefined) return { taskId, headSeq: 0, entries: [], entryTotal: 0 };
|
|
127
126
|
const entries = Array.isArray(full.entries) ? full.entries : [];
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}));
|
|
127
|
+
return { ...full, entries: entries.slice(-50), entryTotal: full.headSeq ?? entries.length };
|
|
128
|
+
};
|
|
129
|
+
const thread = selected === undefined ? null : threadOf(selected);
|
|
130
|
+
const threads = Object.fromEntries(tasks.map((task) => [task.id, threadOf(task.id)]));
|
|
133
131
|
const inbox = Object.values(state.inbox ?? {}).filter((item) =>
|
|
134
132
|
(item.memberId === this.humanId())
|
|
135
133
|
&& !isInformationalThreadMention(item));
|
|
@@ -232,31 +230,45 @@ export class TeamService {
|
|
|
232
230
|
async dispatch(command) {
|
|
233
231
|
const payload = command.payload ?? {};
|
|
234
232
|
const actor = command.actor;
|
|
235
|
-
if (actor === undefined || (actor.kind !== 'human' && actor.kind !== 'agent')) {
|
|
236
|
-
fail(ERRORS.UNAUTHORIZED, 'an exact Team member is required');
|
|
237
|
-
}
|
|
238
|
-
// An agent actor must resolve to a live, non-retired member: otherwise a
|
|
239
|
-
// forged or stale memberId would bypass owner/QA checks downstream.
|
|
240
|
-
if (actor.kind === 'agent') {
|
|
241
|
-
const actingMember = this.state.members?.[actor.memberId];
|
|
242
|
-
if (actingMember === undefined || actingMember.kind !== 'agent') {
|
|
243
|
-
fail(ERRORS.UNAUTHORIZED, `agent actor ${String(actor.memberId ?? '?')} is not a Team member`);
|
|
244
|
-
}
|
|
245
|
-
if (actingMember.status === 'retired') {
|
|
246
|
-
fail(ERRORS.INVALID_STATE, `agent ${actingMember.name ?? actingMember.id} is retired`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
233
|
// Diagnostic trail: one entry row per command, one failure row on throw,
|
|
250
|
-
// one done row with the duration in every case.
|
|
234
|
+
// one done row with the duration in every case. 前置校验失败也必须留痕
|
|
235
|
+
// (errors 档只留 .fail 行,校验抛出必须发生在 try 内才能落行)。
|
|
251
236
|
const startedAt = Date.now();
|
|
237
|
+
const failRow = (code, message) => {
|
|
238
|
+
this.diag?.append({
|
|
239
|
+
ev: 'dispatch.fail',
|
|
240
|
+
type: command.type,
|
|
241
|
+
code,
|
|
242
|
+
projectId: command.projectId ?? null,
|
|
243
|
+
message,
|
|
244
|
+
elapsedMs: Date.now() - startedAt,
|
|
245
|
+
});
|
|
246
|
+
};
|
|
252
247
|
this.diag?.append({
|
|
253
248
|
ev: 'dispatch.start',
|
|
254
249
|
type: command.type,
|
|
255
|
-
actor: actor
|
|
256
|
-
memberId: actor
|
|
250
|
+
actor: actor?.kind ?? null,
|
|
251
|
+
memberId: actor?.memberId ?? null,
|
|
257
252
|
projectId: command.projectId ?? null,
|
|
258
253
|
});
|
|
259
254
|
try {
|
|
255
|
+
if (actor === undefined || (actor.kind !== 'human' && actor.kind !== 'agent')) {
|
|
256
|
+
failRow(ERRORS.UNAUTHORIZED, 'an exact Team member is required');
|
|
257
|
+
fail(ERRORS.UNAUTHORIZED, 'an exact Team member is required');
|
|
258
|
+
}
|
|
259
|
+
// An agent actor must resolve to a live, non-retired member: otherwise a
|
|
260
|
+
// forged or stale memberId would bypass owner/QA checks downstream.
|
|
261
|
+
if (actor.kind === 'agent') {
|
|
262
|
+
const actingMember = this.state.members?.[actor.memberId];
|
|
263
|
+
if (actingMember === undefined || actingMember.kind !== 'agent') {
|
|
264
|
+
failRow(ERRORS.UNAUTHORIZED, `agent actor ${String(actor.memberId ?? '?')} is not a Team member`);
|
|
265
|
+
fail(ERRORS.UNAUTHORIZED, `agent actor ${String(actor.memberId ?? '?')} is not a Team member`);
|
|
266
|
+
}
|
|
267
|
+
if (actingMember.status === 'retired') {
|
|
268
|
+
failRow(ERRORS.INVALID_STATE, `agent ${actingMember.name ?? actingMember.id} is retired`);
|
|
269
|
+
fail(ERRORS.INVALID_STATE, `agent ${actingMember.name ?? actingMember.id} is retired`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
260
272
|
switch (command.type) {
|
|
261
273
|
case 'project.create': return await this.createProject(command, payload);
|
|
262
274
|
case 'project.owner.update': return await this.changeProjectOwner(command, payload);
|
|
@@ -332,7 +344,7 @@ export class TeamService {
|
|
|
332
344
|
if (command.actor.kind !== 'human') fail(ERRORS.UNAUTHORIZED, 'only Human may create a Project');
|
|
333
345
|
if (typeof payload.name !== 'string' || payload.name.trim() === '') fail(ERRORS.INVALID_ARGUMENT, 'project name is required');
|
|
334
346
|
const id = this.ledger.projectId ?? payload.id ?? ids.project();
|
|
335
|
-
const ownerMemberId = payload.ownerId ?? command.actor.memberId ??
|
|
347
|
+
const ownerMemberId = payload.ownerId ?? command.actor.memberId ?? this.humanId();
|
|
336
348
|
const project = {
|
|
337
349
|
id,
|
|
338
350
|
name: payload.name.trim(),
|
|
@@ -399,8 +411,9 @@ export class TeamService {
|
|
|
399
411
|
if (body === '') fail(ERRORS.INVALID_ARGUMENT, 'stream message body is required');
|
|
400
412
|
const author = this.state.members?.[command.actor.memberId];
|
|
401
413
|
if (author === undefined) fail(ERRORS.UNAUTHORIZED, 'actor must be a Team member');
|
|
414
|
+
// seq 由账本事件定(fold 用 event.seq;payload 里的幻影计数会被忽略,
|
|
415
|
+
// 并发下还会重复——曾造成 API 返回值与投影不一致)。
|
|
402
416
|
const entry = {
|
|
403
|
-
seq: (this.state.stream?.at(-1)?.seq ?? 0) + 1,
|
|
404
417
|
kind: 'human_message',
|
|
405
418
|
authorId: author.id,
|
|
406
419
|
body,
|
|
@@ -413,7 +426,7 @@ export class TeamService {
|
|
|
413
426
|
projectId: command.projectId,
|
|
414
427
|
at: this.now(),
|
|
415
428
|
});
|
|
416
|
-
return { entry, event };
|
|
429
|
+
return { entry: { ...entry, seq: event.seq }, event };
|
|
417
430
|
}
|
|
418
431
|
|
|
419
432
|
async addMember(command, payload) {
|
|
@@ -963,7 +976,7 @@ export class TeamService {
|
|
|
963
976
|
const following = payload.following === true;
|
|
964
977
|
await this.ledger.append({
|
|
965
978
|
type: following ? 'task/followed' : 'task/unfollowed',
|
|
966
|
-
payload: { taskId: payload.taskId, memberId: command.actor.memberId ??
|
|
979
|
+
payload: { taskId: payload.taskId, memberId: command.actor.memberId ?? this.humanId() },
|
|
967
980
|
actor: command.actor,
|
|
968
981
|
correlationId: command.correlationId,
|
|
969
982
|
projectId: command.projectId,
|
|
@@ -978,7 +991,7 @@ export class TeamService {
|
|
|
978
991
|
if (state.tasks?.[taskId] === undefined) fail(ERRORS.NOT_FOUND, `task ${String(taskId)} not found`);
|
|
979
992
|
const thread = state.threads?.[taskId] ?? createThread(taskId);
|
|
980
993
|
const actorKind = command.actor.kind;
|
|
981
|
-
const authorId = command.actor.memberId ??
|
|
994
|
+
const authorId = command.actor.memberId ?? this.humanId();
|
|
982
995
|
const outcome = appendReply(thread, { authorId, actorKind, baseSeq: payload.baseSeq, body: payload.body, refs: payload.refs }, { at: this.now() });
|
|
983
996
|
await this.ledger.append({
|
|
984
997
|
type: 'thread/posted',
|
package/lib/host/waker.js
CHANGED
|
@@ -16,7 +16,10 @@ function agentMember(state, memberId) {
|
|
|
16
16
|
if (typeof memberId !== 'string') return null;
|
|
17
17
|
const member = state.members?.[memberId];
|
|
18
18
|
if (member === undefined || member.kind !== 'agent') return null;
|
|
19
|
-
|
|
19
|
+
// failed 成员不自动唤醒(其 LLM 正在失败,自动唤醒只会烧预算):
|
|
20
|
+
// 恢复走 member.retry(Human/Project owner 显式动作)或 Human 在成员
|
|
21
|
+
// 资料里的「重试」;review 路径另经 eligibleReviewers 的同一排除。
|
|
22
|
+
if (member.status === 'retired' || member.status === 'failed') return null;
|
|
20
23
|
return member;
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -202,6 +205,13 @@ export function planWakes(state, result, actor = {}) {
|
|
|
202
205
|
if (task !== undefined) {
|
|
203
206
|
const bucket = event.payload?.bucket ?? Math.floor(Date.now() / 3_600_000);
|
|
204
207
|
add(task.ownerId, task.id, 'pmo_escalate', `pmo_escalate:${task.id}:${bucket}`);
|
|
208
|
+
// Handoffs and meeting decisions live in Thread text; the wake
|
|
209
|
+
// matrix cannot see them. Escalation therefore also reaches the
|
|
210
|
+
// Project owner, who may take the card or re-point it.
|
|
211
|
+
const projectOwner = Object.values(state.projects ?? {})[0]?.ownerMemberId;
|
|
212
|
+
if (projectOwner !== undefined && projectOwner !== task.ownerId) {
|
|
213
|
+
add(projectOwner, task.id, 'pmo_escalate', `pmo_escalate_owner:${task.id}:${bucket}`);
|
|
214
|
+
}
|
|
205
215
|
}
|
|
206
216
|
}
|
|
207
217
|
if (event?.type === 'pmo/heartbeat') {
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
if ((item.ackedAt ?? 0) >= windowStart) decisionsAnswered += 1;
|
|
59
|
+
}
|
|
60
|
+
const humanTasks = humanId === null ? 0
|
|
61
|
+
: Object.values(state.tasks ?? {}).filter((task) =>
|
|
62
|
+
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
63
|
+
&& (task.ownerId === humanId || task.assigneeId === humanId)).length;
|
|
64
|
+
|
|
65
|
+
const completedTitles = completed.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title);
|
|
66
|
+
return {
|
|
67
|
+
windowStart,
|
|
68
|
+
generatedAt: now,
|
|
69
|
+
weeks,
|
|
70
|
+
completedCount: completed.length,
|
|
71
|
+
createdCount,
|
|
72
|
+
reworkedCount: reworked.length,
|
|
73
|
+
humanThreadMessages,
|
|
74
|
+
decisionsAnswered,
|
|
75
|
+
humanTasks,
|
|
76
|
+
completed,
|
|
77
|
+
reworked,
|
|
78
|
+
// 正向解读的数据面:完成的清单与「零 Human 发言」的直通任务。
|
|
79
|
+
positive: { completedTitles, humanThreadMessages, decisionsAnswered },
|
|
80
|
+
// 负向解读的数据面:返工清单(reviewRound>=2)与仍然阻塞/待人的任务。
|
|
81
|
+
negative: { reworkedTitles: reworked.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title), humanTasks },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 账本工具面(R-15 / "plumbing 的 porcelain"):把 writer 已有的读取与
|
|
3
|
+
* 校验能力包装成不依赖宿主进程的人读操作——"一切有记录"的承诺必须可以
|
|
4
|
+
* **独立兑现**才成立。
|
|
5
|
+
*
|
|
6
|
+
* 纪律:全部只读;**不做 gc/压缩/删除**(D1 裁定:append-only 即历史不可变)。
|
|
7
|
+
*
|
|
8
|
+
* exportLedger(dir, outDir) 自包含导出包:段文件副本 + manifest.json +
|
|
9
|
+
* verify-report.md(人读校验结论)
|
|
10
|
+
* auditLedger(dir) 独立校验 hash 链,返回结构化结论(人读报告
|
|
11
|
+
* 由 CLI 层渲染)
|
|
12
|
+
* statsLedger(dir) 段/事件/字节计数与首尾时间
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fsDefault from 'node:fs';
|
|
16
|
+
import pathDefault from 'node:path';
|
|
17
|
+
import { verifyChain } from './events.js';
|
|
18
|
+
|
|
19
|
+
function listSegments(dir, fs = fsDefault) {
|
|
20
|
+
return fs.readdirSync(dir)
|
|
21
|
+
.filter((name) => /^ledger-\d+\.jsonl$/.test(name))
|
|
22
|
+
.sort();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readEvents(dir, fs = fsDefault) {
|
|
26
|
+
const segments = listSegments(dir, fs);
|
|
27
|
+
const events = [];
|
|
28
|
+
for (const name of segments) {
|
|
29
|
+
const text = fs.readFileSync(pathDefault.join(dir, name), 'utf8');
|
|
30
|
+
for (const line of text.split('\n')) {
|
|
31
|
+
if (line.trim() === '') continue;
|
|
32
|
+
events.push(JSON.parse(line));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { segments, events };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function bytesOf(dir, segments, fs = fsDefault) {
|
|
39
|
+
let total = 0;
|
|
40
|
+
for (const name of segments) {
|
|
41
|
+
total += fs.statSync(pathDefault.join(dir, name)).size;
|
|
42
|
+
}
|
|
43
|
+
return total;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 独立校验:读全部事件 → verifyChain(不加锁、不写盘、不 require 宿主)。 */
|
|
47
|
+
export function auditLedger(dir, options = {}) {
|
|
48
|
+
const fs = options.fs ?? fsDefault;
|
|
49
|
+
const { segments, events } = readEvents(dir, fs);
|
|
50
|
+
const projectId = events[0]?.projectId ?? null;
|
|
51
|
+
const chain = verifyChain(events, { projectId });
|
|
52
|
+
return {
|
|
53
|
+
ok: chain.ok,
|
|
54
|
+
dir,
|
|
55
|
+
projectId,
|
|
56
|
+
segments,
|
|
57
|
+
eventCount: events.length,
|
|
58
|
+
head: events.length > 0 ? { seq: events.at(-1).seq, hash: events.at(-1).hash, at: events.at(-1).at } : null,
|
|
59
|
+
error: chain.ok ? null : { code: chain.code, message: chain.message, details: chain.details ?? {}, index: chain.index ?? null },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 段/事件/字节/首尾时间统计。 */
|
|
64
|
+
export function statsLedger(dir, options = {}) {
|
|
65
|
+
const fs = options.fs ?? fsDefault;
|
|
66
|
+
const { segments, events } = readEvents(dir, fs);
|
|
67
|
+
const first = events[0] ?? null;
|
|
68
|
+
const last = events.at(-1) ?? null;
|
|
69
|
+
return {
|
|
70
|
+
dir,
|
|
71
|
+
segments: segments.length,
|
|
72
|
+
segmentBytes: segments.length > 0 ? bytesOf(dir, segments, fs) : 0,
|
|
73
|
+
eventCount: events.length,
|
|
74
|
+
firstAt: first?.at ?? null,
|
|
75
|
+
lastAt: last?.at ?? null,
|
|
76
|
+
headSeq: last?.seq ?? 0,
|
|
77
|
+
types: [...new Set(events.map((event) => event.type))].sort(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 自包含导出:段文件副本(字节级复制,不重排不重写)+ manifest.json(head/
|
|
83
|
+
* 事件计数/文件清单/导出时间)+ verify-report.md(人读校验结论)。导出包
|
|
84
|
+
* 拷到任何机器都可以用 audit 独立复检。
|
|
85
|
+
*/
|
|
86
|
+
export function exportLedger(dir, outDir, options = {}) {
|
|
87
|
+
const fs = options.fs ?? fsDefault;
|
|
88
|
+
const path = options.path ?? pathDefault;
|
|
89
|
+
const audit = auditLedger(dir, { fs });
|
|
90
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
91
|
+
const copied = [];
|
|
92
|
+
for (const name of audit.segments) {
|
|
93
|
+
fs.copyFileSync(path.join(dir, name), path.join(outDir, name));
|
|
94
|
+
copied.push({ name, bytes: fs.statSync(path.join(outDir, name)).size });
|
|
95
|
+
}
|
|
96
|
+
const manifest = {
|
|
97
|
+
exportedAt: new Date().toISOString(),
|
|
98
|
+
sourceDir: dir,
|
|
99
|
+
projectId: audit.projectId,
|
|
100
|
+
head: audit.head,
|
|
101
|
+
eventCount: audit.eventCount,
|
|
102
|
+
files: copied,
|
|
103
|
+
verify: { ok: audit.ok, error: audit.error },
|
|
104
|
+
};
|
|
105
|
+
fs.writeFileSync(path.join(outDir, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n', 'utf8');
|
|
106
|
+
const lines = [
|
|
107
|
+
'# Ledger export verify report', '',
|
|
108
|
+
'- source: `' + dir + '`',
|
|
109
|
+
'- projectId: `' + String(audit.projectId) + '`',
|
|
110
|
+
'- events: ' + String(audit.eventCount),
|
|
111
|
+
'- head: seq ' + String(audit.head?.seq ?? 0),
|
|
112
|
+
'- hash chain: ' + (audit.ok ? '**OK**' : '**BROKEN**'),
|
|
113
|
+
audit.error ? '- error: ' + audit.error.code + ' ' + audit.error.message : '- error: none',
|
|
114
|
+
'- exportedAt: ' + manifest.exportedAt,
|
|
115
|
+
];
|
|
116
|
+
fs.writeFileSync(path.join(outDir, 'verify-report.md'), lines.join('\n') + '\n', 'utf8');
|
|
117
|
+
return { ok: audit.ok, outDir, files: copied.map((file) => file.name).concat(['manifest.json', 'verify-report.md']) };
|
|
118
|
+
}
|
package/lib/ledger/writer.js
CHANGED
|
@@ -950,9 +950,14 @@ export function openLedger(options = {}) {
|
|
|
950
950
|
const saveCheckpointNow = () => {
|
|
951
951
|
if (!checkpointOptions) return null;
|
|
952
952
|
try {
|
|
953
|
+
// 水位取"fold 已应用前缀"而非 writer.head:跨调用交错下(B 批次可在
|
|
954
|
+
// A 的 facade 续体推进 state 之前提交),head 可能领先 state——按
|
|
955
|
+
// head 落盘会持久化一个 state 落后于 lastSeq 的检查点,崩溃重开时
|
|
956
|
+
// 零尾放静默吞掉投影。state.lastSeq/lastHash 由 advance() 逐事件
|
|
957
|
+
// 维护,永远 ≤ head,尾放从其 +1 重放天然自洽。
|
|
953
958
|
return saveCheckpoint(
|
|
954
959
|
checkpointDir,
|
|
955
|
-
{ stateVersion, lastSeq:
|
|
960
|
+
{ stateVersion, lastSeq: state.lastSeq, lastHash: state.lastHash, state },
|
|
956
961
|
{ hashAt: (seq) => writer.hashAt(seq) },
|
|
957
962
|
);
|
|
958
963
|
} catch (error) {
|
|
@@ -94,10 +94,11 @@ export function retryDecision(failure, config = {}, attempt = 1) {
|
|
|
94
94
|
? Math.max(1, Math.min(config.retry.maxAttempts, 5))
|
|
95
95
|
: 3;
|
|
96
96
|
if (!failure?.retryable) return { action: 'fail', attempt, reason: `${failure?.category ?? 'unknown'} is not retryable` };
|
|
97
|
-
if (attempt >= maxAttempts) return { action: 'fail', attempt, reason: `retry budget exhausted (${maxAttempts})` };
|
|
98
97
|
const nextFallbackIndex = attempt - 1;
|
|
99
98
|
const fallback = fallbackAt(config, nextFallbackIndex);
|
|
100
99
|
if (fallback !== null) {
|
|
100
|
+
// 换路优先于预算:fallback 不是同路由重试,预算钳制它会让 maxAttempts=1
|
|
101
|
+
// 的配置永远走不到备用路由。
|
|
101
102
|
return {
|
|
102
103
|
action: 'fallback',
|
|
103
104
|
attempt,
|
|
@@ -111,6 +112,7 @@ export function retryDecision(failure, config = {}, attempt = 1) {
|
|
|
111
112
|
reason: `fallback to ${fallback.provider ?? config.provider}/${fallback.model ?? config.model}`,
|
|
112
113
|
};
|
|
113
114
|
}
|
|
115
|
+
if (attempt >= maxAttempts) return { action: 'fail', attempt, reason: `retry budget exhausted (${maxAttempts})` };
|
|
114
116
|
// No fallback route configured: a rate limit would hit again at once
|
|
115
117
|
// without a backoff clock — end the turn and let the next event/startup
|
|
116
118
|
// try fresh instead of burning the budget on a throttled route.
|
|
@@ -244,7 +244,7 @@ export class MemberRuntime {
|
|
|
244
244
|
setup: async (agentCtx) => { await this.agentPresets.mount(agentCtx, preset); },
|
|
245
245
|
} : {}),
|
|
246
246
|
});
|
|
247
|
-
this.trackHandle?.(handle);
|
|
247
|
+
this.trackHandle?.(member.sessionId, handle);
|
|
248
248
|
agent = handle.agent;
|
|
249
249
|
} catch (error) {
|
|
250
250
|
fail('E_SESSION_MISSING', `member ${member.id} cannot be resumed: ${error?.message ?? error}`);
|
|
@@ -264,7 +264,7 @@ export class MemberRuntime {
|
|
|
264
264
|
if ((session === undefined || session === null) && this.agents?.resume !== undefined) {
|
|
265
265
|
try {
|
|
266
266
|
const handle = await this.agents.resume({ resumeSessionId: member.sessionId, parentAgent: this.parent });
|
|
267
|
-
this.trackHandle?.(handle);
|
|
267
|
+
this.trackHandle?.(member.sessionId, handle);
|
|
268
268
|
session = this.sessions?.get?.(member.sessionId);
|
|
269
269
|
} catch { /* fall through to sendMessage cold path */ }
|
|
270
270
|
}
|
|
@@ -170,6 +170,18 @@ function adoptGuardVerdict(project) {
|
|
|
170
170
|
return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
+
// 指针目录必须含 manifest.json(与引擎 latest_staging 一致),否则按扫描
|
|
174
|
+
// 回退——残指针不应产生误导性报因。
|
|
175
|
+
if (!latest || !existsSync(join(root, latest, 'manifest.json'))) {
|
|
176
|
+
try {
|
|
177
|
+
latest = readdirSync(root)
|
|
178
|
+
.filter((n) => /^\d{8}-\d{6}(-\d+)?$/.test(n) && existsSync(join(root, n, 'manifest.json')))
|
|
179
|
+
.sort()
|
|
180
|
+
.at(-1) ?? null
|
|
181
|
+
} catch {
|
|
182
|
+
return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
|
|
183
|
+
}
|
|
184
|
+
}
|
|
173
185
|
if (!latest) return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
|
|
174
186
|
const stagedDir = join(root, latest)
|
|
175
187
|
let backend = null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.60",
|
|
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",
|