@suifei/dsh-ai-team 0.4.145 → 0.4.147
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 +11 -0
- package/LICENSE +21 -21
- package/README.md +31 -2
- package/client.js +551 -49
- package/cordis.patch.yml +31 -31
- package/icon.svg +12 -12
- package/index.js +105 -25
- package/lib/domain/ids.js +26 -26
- package/lib/domain/inbox.js +93 -93
- package/lib/domain/member-config.js +168 -168
- package/lib/domain/policy.js +8 -1
- package/lib/domain/task.js +2 -0
- package/lib/domain/team-blueprint.js +240 -0
- package/lib/host/decision-report.js +72 -72
- package/lib/host/default-roster.js +18 -0
- package/lib/host/default-workspace.js +69 -69
- package/lib/host/fault-adapter.js +50 -50
- package/lib/host/member-tools.js +6 -1
- package/lib/host/people-view.js +9 -2
- package/lib/host/permission-guard.js +61 -61
- package/lib/host/project-registry.js +104 -104
- package/lib/host/project-runtime.js +2 -2
- package/lib/host/risk-view.js +99 -99
- package/lib/host/service.js +195 -16
- package/lib/host/views.js +42 -1
- package/lib/host/waker.js +38 -8
- 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/fold.js +23 -0
- 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/runtime/stop-guard.js +17 -2
- package/lib/skillopt/adopt-gate.js +108 -108
- package/lib/skillopt/gate-wiring.js +146 -146
- package/lib/skillopt/jobs.js +135 -135
- package/lib/skillopt/proposal-store.js +33 -33
- package/lib/skillopt/review-runner.js +107 -107
- 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
package/cordis.patch.yml
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# dsh-ai-team bundle patch: mounts the Host half.
|
|
2
|
-
# The Client half is discovered from this package's `dsh.client` declaration.
|
|
3
|
-
# AI Team is a dedicated, trusted profile: members run with full access by
|
|
4
|
-
# design. These patches make that explicit at the profile layer, so a plain
|
|
5
|
-
# web/desktop profile is never affected.
|
|
6
|
-
- insert:
|
|
7
|
-
- id: ai-team
|
|
8
|
-
name: '@suifei/dsh-ai-team'
|
|
9
|
-
|
|
10
|
-
# The Team profile must be danger-full-access end to end. The Host validates
|
|
11
|
-
# this at boot (E_PERMISSION_PROFILE) and refuses to serve a weaker profile.
|
|
12
|
-
- id: sandbox-policy
|
|
13
|
-
config:
|
|
14
|
-
mode: danger-full-access
|
|
15
|
-
workspaceRoot: !!js process.cwd()
|
|
16
|
-
- id: approval
|
|
17
|
-
config:
|
|
18
|
-
policy: never
|
|
19
|
-
- id: permission
|
|
20
|
-
config:
|
|
21
|
-
defaultPreset: danger-full-access
|
|
22
|
-
presets:
|
|
23
|
-
read-only:
|
|
24
|
-
sandbox: read-only
|
|
25
|
-
approval: ask
|
|
26
|
-
workspace-write:
|
|
27
|
-
sandbox: workspace-write
|
|
28
|
-
approval: ask
|
|
29
|
-
danger-full-access:
|
|
30
|
-
sandbox: danger-full-access
|
|
31
|
-
approval: never
|
|
1
|
+
# dsh-ai-team bundle patch: mounts the Host half.
|
|
2
|
+
# The Client half is discovered from this package's `dsh.client` declaration.
|
|
3
|
+
# AI Team is a dedicated, trusted profile: members run with full access by
|
|
4
|
+
# design. These patches make that explicit at the profile layer, so a plain
|
|
5
|
+
# web/desktop profile is never affected.
|
|
6
|
+
- insert:
|
|
7
|
+
- id: ai-team
|
|
8
|
+
name: '@suifei/dsh-ai-team'
|
|
9
|
+
|
|
10
|
+
# The Team profile must be danger-full-access end to end. The Host validates
|
|
11
|
+
# this at boot (E_PERMISSION_PROFILE) and refuses to serve a weaker profile.
|
|
12
|
+
- id: sandbox-policy
|
|
13
|
+
config:
|
|
14
|
+
mode: danger-full-access
|
|
15
|
+
workspaceRoot: !!js process.cwd()
|
|
16
|
+
- id: approval
|
|
17
|
+
config:
|
|
18
|
+
policy: never
|
|
19
|
+
- id: permission
|
|
20
|
+
config:
|
|
21
|
+
defaultPreset: danger-full-access
|
|
22
|
+
presets:
|
|
23
|
+
read-only:
|
|
24
|
+
sandbox: read-only
|
|
25
|
+
approval: ask
|
|
26
|
+
workspace-write:
|
|
27
|
+
sandbox: workspace-write
|
|
28
|
+
approval: ask
|
|
29
|
+
danger-full-access:
|
|
30
|
+
sandbox: danger-full-access
|
|
31
|
+
approval: never
|
package/icon.svg
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="文渊阁">
|
|
2
|
-
<!-- 重檐(上层屋顶) -->
|
|
3
|
-
<path d="M5 8l7-4 7 4" />
|
|
4
|
-
<path d="M7 11h10" />
|
|
5
|
-
<!-- 出檐(下层屋檐) -->
|
|
6
|
-
<path d="M4 14h16" />
|
|
7
|
-
<!-- 立柱(三开间) -->
|
|
8
|
-
<path d="M9 14v3" />
|
|
9
|
-
<path d="M15 14v3" />
|
|
10
|
-
<!-- 渊水(底部波纹) -->
|
|
11
|
-
<path d="M4 20c2.5-1.5 5.5-1.5 8 0s5.5 1.5 8 0" />
|
|
12
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="文渊阁">
|
|
2
|
+
<!-- 重檐(上层屋顶) -->
|
|
3
|
+
<path d="M5 8l7-4 7 4" />
|
|
4
|
+
<path d="M7 11h10" />
|
|
5
|
+
<!-- 出檐(下层屋檐) -->
|
|
6
|
+
<path d="M4 14h16" />
|
|
7
|
+
<!-- 立柱(三开间) -->
|
|
8
|
+
<path d="M9 14v3" />
|
|
9
|
+
<path d="M15 14v3" />
|
|
10
|
+
<!-- 渊水(底部波纹) -->
|
|
11
|
+
<path d="M4 20c2.5-1.5 5.5-1.5 8 0s5.5 1.5 8 0" />
|
|
12
|
+
</svg>
|
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ import { activationSpec } from './lib/runtime/activation-spec.js';
|
|
|
28
28
|
import { repairArchivedHosts as repairHostSessions, repairOnce } from './lib/runtime/host-repair.js';
|
|
29
29
|
import { classifyLlmFailure, nextRequestAttempt, retryDecision } from './lib/runtime/failure-policy.js';
|
|
30
30
|
import { memberIdentity } from './lib/domain/member-profile.js';
|
|
31
|
+
import { blocksBlueprintTask, blueprintFingerprint, blueprintUseCases, buildTeamBlueprint, renderTeamBlueprint } from './lib/domain/team-blueprint.js';
|
|
31
32
|
import { findSkill, findSkillText, loadSkillContext } from './lib/runtime/skill-loader.js';
|
|
32
33
|
import { skillKindForMember } from './lib/runtime/core-skill.js';
|
|
33
34
|
import { formatSkillCatalog } from './lib/runtime/skill-catalog.js';
|
|
@@ -67,7 +68,7 @@ import { registerHostSessionGate } from './lib/runtime/host-session-gate.js';
|
|
|
67
68
|
import { createActivationBudget } from './lib/runtime/activation-budget.js';
|
|
68
69
|
import { blocksActivation, probeProviderRegistration } from './lib/runtime/subagent-probe.js';
|
|
69
70
|
import { isRuntimeUnavailableFailure, resolveSubagentProviderName } from './lib/runtime/subagent-provider.js';
|
|
70
|
-
import { aggregatePeople } from './lib/host/people-view.js';
|
|
71
|
+
import { aggregatePeople, peopleProjectIsArchived } from './lib/host/people-view.js';
|
|
71
72
|
import { riskView } from './lib/host/risk-view.js';
|
|
72
73
|
import { weeklyView } from './lib/host/weekly-view.js';
|
|
73
74
|
import { isInformationalThreadMention } from './lib/domain/inbox.js';
|
|
@@ -95,6 +96,10 @@ const VERSION = (() => {
|
|
|
95
96
|
}
|
|
96
97
|
})();
|
|
97
98
|
const HUMAN_ID = 'mem_human';
|
|
99
|
+
const BLUEPRINT_ADVANCE_EVENTS = new Set([
|
|
100
|
+
'project/blueprint-evidence', 'project/blueprint-measured', 'project/member-added', 'project/pmo-updated',
|
|
101
|
+
'project/run-state', 'task/accepted', 'review/accepted', 'inbox/acked',
|
|
102
|
+
]);
|
|
98
103
|
|
|
99
104
|
const SKILLOPT_BACKENDS = ['mock', 'claude', 'codex', 'copilot', 'cursor', 'pi', 'opencode', 'handoff', 'azure_openai'];
|
|
100
105
|
|
|
@@ -398,6 +403,7 @@ export function apply(ctx, config = {}) {
|
|
|
398
403
|
|
|
399
404
|
let booted = null;
|
|
400
405
|
let bootError = null;
|
|
406
|
+
let blueprintGuardReady = false;
|
|
401
407
|
// 卸载闸门:teardown 之后仍在飞的异步链(boot 续体、ensureParent、归档修复重试)
|
|
402
408
|
// 不能继续写状态,否则会把句柄塞进已清空的表里、或在清理之后重建定时器。
|
|
403
409
|
let disposed = false;
|
|
@@ -419,7 +425,7 @@ export function apply(ctx, config = {}) {
|
|
|
419
425
|
|| Object.values(state.members ?? {}).some((member) => member?.sessionId === sessionId);
|
|
420
426
|
if (!inTeam) continue;
|
|
421
427
|
const project = state.projects?.[runtime.id];
|
|
422
|
-
return { projectId: runtime.id, projectName: project?.name ?? '', stopped: project?.runState === 'stopped' };
|
|
428
|
+
return { projectId: runtime.id, projectName: project?.name ?? '', stopped: project?.runState === 'stopped', blueprint: Boolean(project?.blueprint) };
|
|
423
429
|
}
|
|
424
430
|
return null;
|
|
425
431
|
};
|
|
@@ -1045,6 +1051,7 @@ export function apply(ctx, config = {}) {
|
|
|
1045
1051
|
// 主动触发的唤醒(如私信 member.message)仍放行——停止的是机器
|
|
1046
1052
|
// 驱动,不断 Human 通道。
|
|
1047
1053
|
const gateProject = projectRuntime.service.state.projects?.[projectRuntime.id];
|
|
1054
|
+
if (gateProject?.blueprint && (!blueprintGuardReady || gateProject.status === 'archived')) return;
|
|
1048
1055
|
if (gateProject !== undefined && gateProject.runState === 'stopped' && actor?.kind !== 'human') return;
|
|
1049
1056
|
const plans = planWakes(projectRuntime.service.state, result, actor, { projectId: projectRuntime.id });
|
|
1050
1057
|
if (plans.length === 0) return;
|
|
@@ -1331,6 +1338,14 @@ export function apply(ctx, config = {}) {
|
|
|
1331
1338
|
}).finally(() => handoffBusy.delete(workspace));
|
|
1332
1339
|
};
|
|
1333
1340
|
|
|
1341
|
+
const advanceBlueprint = async (runtime) => {
|
|
1342
|
+
if (disposed || !blueprintGuardReady || !runtime.service.state.projects?.[runtime.id]?.blueprint) return;
|
|
1343
|
+
try {
|
|
1344
|
+
await runtime.service.autoAdvanceBlueprint(runtime.id);
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
diag.append({ ev: 'blueprint.advance.fail', projectId: runtime.id, message: error?.message ?? String(error) });
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1334
1349
|
const pmoTick = async (projectRuntime) => {
|
|
1335
1350
|
if (projectRuntime === null || projectRuntime === undefined) return;
|
|
1336
1351
|
// 归档修复重试点:boot 时 workspaceRegistry 往往还没 active,等 tick
|
|
@@ -1387,7 +1402,9 @@ export function apply(ctx, config = {}) {
|
|
|
1387
1402
|
}
|
|
1388
1403
|
}
|
|
1389
1404
|
const results = await projectRuntime.service.autoAnswerDecisions(projectRuntime.id);
|
|
1405
|
+
if (project.blueprint) await advanceBlueprint(projectRuntime);
|
|
1390
1406
|
for (const result of results) {
|
|
1407
|
+
if (project.blueprint) break; // 试跑等 inbox/acked 后再按当前岗位投递。
|
|
1391
1408
|
const taskId = result?.item?.ref?.taskId;
|
|
1392
1409
|
if (typeof taskId === 'string' && result.entry !== null && result.entry !== undefined) {
|
|
1393
1410
|
await wakeFromResult(projectRuntime, {
|
|
@@ -1396,7 +1413,8 @@ export function apply(ctx, config = {}) {
|
|
|
1396
1413
|
}
|
|
1397
1414
|
}
|
|
1398
1415
|
const active = Object.values(state.tasks ?? {}).filter((task) =>
|
|
1399
|
-
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
1416
|
+
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
1417
|
+
&& (!project.blueprint || !blocksBlueprintTask(state, task.id)));
|
|
1400
1418
|
const now = Date.now();
|
|
1401
1419
|
// R-14 pending 快速补派:task/created 的事件唤醒可能在责任位正忙时被投递语义
|
|
1402
1420
|
// 吞掉,60s tick 兜底。判定(实时回合、每卡上限)在 planDispatch(lib/host/pmo.js)。
|
|
@@ -1424,6 +1442,7 @@ export function apply(ctx, config = {}) {
|
|
|
1424
1442
|
await wakeFromResult(projectRuntime, { event: nudgeEvent[kind](task) }, {});
|
|
1425
1443
|
}
|
|
1426
1444
|
}
|
|
1445
|
+
if (project.blueprint) return;
|
|
1427
1446
|
// 空闲必派:看板上还有活时,空闲开发一个都不能闲着(判定在 planIdleStaffing,lib/host/pmo.js)。
|
|
1428
1447
|
const staffing = planIdleStaffing(state, { now, inTurn: (id) => turnsInFlight.has(id), last: pmoLastStaffing.get(projectRuntime.id) });
|
|
1429
1448
|
if (staffing !== null) {
|
|
@@ -1978,6 +1997,7 @@ export function apply(ctx, config = {}) {
|
|
|
1978
1997
|
console.warn('[ai-team] bundled SkillOpt tools failed:', error?.message ?? error);
|
|
1979
1998
|
}
|
|
1980
1999
|
let disposeTool = () => {};
|
|
2000
|
+
let teamToolReady = false;
|
|
1981
2001
|
try {
|
|
1982
2002
|
disposeTool = tools?.register
|
|
1983
2003
|
? tools.register(createTeamTool({
|
|
@@ -1999,6 +2019,7 @@ export function apply(ctx, config = {}) {
|
|
|
1999
2019
|
when: () => booted !== null,
|
|
2000
2020
|
})
|
|
2001
2021
|
: () => {};
|
|
2022
|
+
teamToolReady = typeof tools?.register === 'function';
|
|
2002
2023
|
} catch (error) {
|
|
2003
2024
|
diag.append({ ev: 'team.tool.fail', message: error?.message ?? String(error) });
|
|
2004
2025
|
console.warn('[ai-team] team tool registration failed:', error?.message ?? error);
|
|
@@ -2031,7 +2052,9 @@ export function apply(ctx, config = {}) {
|
|
|
2031
2052
|
let disposeStopGuard = () => {};
|
|
2032
2053
|
let disposeOneShotToolGuard = () => {};
|
|
2033
2054
|
try {
|
|
2034
|
-
|
|
2055
|
+
const toolService = tools ?? serviceOf(ctx, 'tools');
|
|
2056
|
+
disposeStopGuard = registerStopGuard({ tools: toolService, projectOf: teamProjectOf, diag });
|
|
2057
|
+
blueprintGuardReady = teamToolReady && typeof toolService?.guard === 'function';
|
|
2035
2058
|
disposeOneShotToolGuard = registerOneShotToolGuard({ tools: tools ?? serviceOf(ctx, 'tools'), isOneShot: (sessionId) => teamDiscipline.isOneShot?.(sessionId) === true, diag });
|
|
2036
2059
|
} catch (error) {
|
|
2037
2060
|
diag.append({ ev: 'stop.guard.fail', message: error?.message ?? String(error) });
|
|
@@ -2139,6 +2162,10 @@ export function apply(ctx, config = {}) {
|
|
|
2139
2162
|
await projectRuntime.service.bindHostSession(value.sessionId, projectId);
|
|
2140
2163
|
} catch (error) {
|
|
2141
2164
|
diag.append({ ev: 'host.bind.fail', projectId, sessionId: value.sessionId, message: error?.message ?? String(error) });
|
|
2165
|
+
if (project.blueprint) {
|
|
2166
|
+
try { await value.dispose?.(); } catch { /* already gone */ }
|
|
2167
|
+
throw error;
|
|
2168
|
+
}
|
|
2142
2169
|
}
|
|
2143
2170
|
}
|
|
2144
2171
|
// 归入项目工作区并命名:否则 DSH 侧栏里它是「未分组 / 未命名」,成员子会话跟着它。
|
|
@@ -2156,6 +2183,8 @@ export function apply(ctx, config = {}) {
|
|
|
2156
2183
|
return pending;
|
|
2157
2184
|
};
|
|
2158
2185
|
const activateMember = async (body, projectRuntime) => {
|
|
2186
|
+
const project = projectRuntime.service.state.projects?.[projectRuntime.id];
|
|
2187
|
+
if (project?.blueprint && !blueprintGuardReady) return { error: { code: 'E_RUNTIME_UNAVAILABLE', message: '宿主未注册首发试跑工具门禁' }, status: 503 };
|
|
2159
2188
|
const member = projectRuntime.service.state.members?.[body.payload?.memberId];
|
|
2160
2189
|
if (member === undefined) return { error: { code: 'E_NOT_FOUND', message: 'member not found' }, status: 404 };
|
|
2161
2190
|
if (member.status === 'retired') return { error: { code: 'E_INVALID_STATE', message: 'member is retired' }, status: 409 };
|
|
@@ -2231,23 +2260,20 @@ export function apply(ctx, config = {}) {
|
|
|
2231
2260
|
preset: 'standard',
|
|
2232
2261
|
cwd: effectiveDir,
|
|
2233
2262
|
});
|
|
2263
|
+
const blueprintRole = project?.blueprint?.roles.find((role) => role.id === member.id);
|
|
2264
|
+
const skillContext = blueprintRole ? `\n\n${blueprintRole.prompt}` : (
|
|
2265
|
+
await formatSkillCatalog(skillsService, { cwd: effectiveDir }) +
|
|
2266
|
+
await loadSkillContext(activationMember, memberSkillRoots(activationMember, projectRuntime, diag), {
|
|
2267
|
+
vars: { GOAL: goalForProject(projectRuntime), PROJECT: project?.name ?? '', MEMBER: activationMember.name ?? '', WORKSPACE: effectiveDir },
|
|
2268
|
+
preset: resolveTeam(talentCatalog(diag), activationMember.team ?? DEFAULT_TEAM, { diag }),
|
|
2269
|
+
ownerId: project?.ownerMemberId ?? project?.ownerId,
|
|
2270
|
+
})
|
|
2271
|
+
);
|
|
2234
2272
|
const result = await runtime.activate(activationMember, {
|
|
2235
2273
|
// #65:激活时若带着 Human 消息的图片/文件,一并放进首条消息。
|
|
2236
2274
|
prompt: messageContent(`${memberIdentity(activationMember)}\n\n${typeof body.payload?.prompt === 'string'
|
|
2237
2275
|
? body.payload.prompt
|
|
2238
|
-
: '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${
|
|
2239
|
-
vars: {
|
|
2240
|
-
GOAL: goalForProject(projectRuntime),
|
|
2241
|
-
PROJECT: projectRuntime.service.state.projects?.[projectRuntime.id]?.name ?? '',
|
|
2242
|
-
MEMBER: activationMember.name ?? '',
|
|
2243
|
-
WORKSPACE: effectiveDir,
|
|
2244
|
-
},
|
|
2245
|
-
// 成员来自哪个团队就用哪个团队的岗位规程与技能(老成员没有记录 → 默认团队)。
|
|
2246
|
-
preset: resolveTeam(talentCatalog(diag), activationMember.team ?? DEFAULT_TEAM, { diag }),
|
|
2247
|
-
// 按身份装配岗位规程:项目主理人拿审查规程,验收拿复跑规程,其余拿执行规程。
|
|
2248
|
-
ownerId: projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerMemberId
|
|
2249
|
-
?? projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerId,
|
|
2250
|
-
})}`, body.payload?.attachments),
|
|
2276
|
+
: '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${skillContext}`, body.payload?.attachments),
|
|
2251
2277
|
});
|
|
2252
2278
|
let bound;
|
|
2253
2279
|
try {
|
|
@@ -2309,7 +2335,15 @@ export function apply(ctx, config = {}) {
|
|
|
2309
2335
|
attachRuntime = (runtime) => {
|
|
2310
2336
|
runtime.ledger.onEvent = (event) => {
|
|
2311
2337
|
broadcast(event, runtime);
|
|
2338
|
+
if (BLUEPRINT_ADVANCE_EVENTS.has(event?.type)) void advanceBlueprint(runtime);
|
|
2312
2339
|
if (event?.type === 'project/run-state' && event.payload?.runState === 'stopped') interruptTeam(runtime);
|
|
2340
|
+
const decision = event?.type === 'inbox/item-created' ? event.payload?.ref : null;
|
|
2341
|
+
if ((decision?.blueprintDecision === true && decision.humanOnly === false)
|
|
2342
|
+
|| (event?.type === 'project/pmo-updated' && event.payload.pmoAuto === true && runtime.service.state.projects?.[runtime.id]?.blueprint)) {
|
|
2343
|
+
void runtime.service.autoAnswerDecisions(runtime.id).catch((error) => {
|
|
2344
|
+
diag.append({ ev: 'blueprint.decision.fail', projectId: runtime.id, message: error?.message ?? String(error) });
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2313
2347
|
const actorId = event?.actor?.kind === 'agent' ? event.actor.memberId : undefined;
|
|
2314
2348
|
void wakeFromResult(runtime, { event }, actorId === undefined ? {} : { agentId: actorId }).catch((error) => {
|
|
2315
2349
|
diag.append({ ev: 'wake.plan.fail', projectId: runtime.id, eventType: event?.type ?? null, message: error?.message ?? String(error) });
|
|
@@ -2340,6 +2374,7 @@ export function apply(ctx, config = {}) {
|
|
|
2340
2374
|
// A restart is an explicit lifecycle event: resume unfinished Tasks
|
|
2341
2375
|
// once per Project, without timers or periodic polling.
|
|
2342
2376
|
for (const runtime of value.runtimes.values()) {
|
|
2377
|
+
void advanceBlueprint(runtime);
|
|
2343
2378
|
void wakeFromResult(runtime, { event: { type: 'team/startup' } }, {}).catch((error) => {
|
|
2344
2379
|
diag.append({ ev: 'wake.plan.fail', projectId: runtime.id, eventType: 'team/startup', message: error?.message ?? String(error) });
|
|
2345
2380
|
console.warn('[ai-team] startup wake planner failed:', error?.message ?? error);
|
|
@@ -2389,7 +2424,8 @@ export function apply(ctx, config = {}) {
|
|
|
2389
2424
|
entry.timer.unref?.();
|
|
2390
2425
|
};
|
|
2391
2426
|
|
|
2392
|
-
|
|
2427
|
+
const blueprintCreations = new Map();
|
|
2428
|
+
async function activateProject(nextProjectId, projectName, projectGoal, workspacePath = '', team = '', blueprint = null) {
|
|
2393
2429
|
await ready;
|
|
2394
2430
|
if (booted === null) throw new Error('team ledger is unavailable');
|
|
2395
2431
|
let next = projectRuntime(nextProjectId);
|
|
@@ -2402,8 +2438,16 @@ export function apply(ctx, config = {}) {
|
|
|
2402
2438
|
workspacePath,
|
|
2403
2439
|
diag,
|
|
2404
2440
|
pmoMaxRounds: config.pmoMaxRounds,
|
|
2405
|
-
teamPreset: teamPresetFor(config, diag, team),
|
|
2441
|
+
teamPreset: blueprint ? null : teamPresetFor(config, diag, team),
|
|
2442
|
+
blueprint,
|
|
2406
2443
|
});
|
|
2444
|
+
// 账本和两个岗位先落地,重启时才不会把半写的蓝图项目播种成预设团队。
|
|
2445
|
+
try {
|
|
2446
|
+
booted.registry.add({ id: nextProjectId, name: projectName, goal: projectGoal, workspacePath });
|
|
2447
|
+
} catch (error) {
|
|
2448
|
+
next.close();
|
|
2449
|
+
throw error;
|
|
2450
|
+
}
|
|
2407
2451
|
booted.runtimes.set(nextProjectId, next);
|
|
2408
2452
|
attachRuntime(next);
|
|
2409
2453
|
}
|
|
@@ -2511,7 +2555,7 @@ export function apply(ctx, config = {}) {
|
|
|
2511
2555
|
}
|
|
2512
2556
|
// 团队列表(新建项目选团队、组队面板);defaultTeam 是插件设置里的默认团队。
|
|
2513
2557
|
if (req.method === 'GET' && url.pathname === '/ai-team/api/teams') {
|
|
2514
|
-
return send(res, { teams: listTeams(talentCatalog(diag)), defaultTeam: config?.teamPreset || DEFAULT_TEAM });
|
|
2558
|
+
return send(res, { teams: listTeams(talentCatalog(diag)), defaultTeam: config?.teamPreset || DEFAULT_TEAM, blueprintUseCases });
|
|
2515
2559
|
}
|
|
2516
2560
|
// 组队:从人才里挑人建一个用户团队(只写用户根;新建撞名加序号,改写需 overwrite)。
|
|
2517
2561
|
if (req.method === 'POST' && url.pathname === '/ai-team/api/teams') {
|
|
@@ -2738,6 +2782,7 @@ export function apply(ctx, config = {}) {
|
|
|
2738
2782
|
const revived = [];
|
|
2739
2783
|
const skipped = [];
|
|
2740
2784
|
for (const runtime of runtimeEntries) {
|
|
2785
|
+
if (peopleProjectIsArchived(booted.registry.list().find((entry) => entry.id === runtime.id), runtime)) continue;
|
|
2741
2786
|
for (const member of Object.values(runtime.service.state.members ?? {})) {
|
|
2742
2787
|
if (member.kind !== 'agent' || member.status === 'retired') continue;
|
|
2743
2788
|
const eligible = includeAll ? member.status === 'failed' : isRuntimeUnavailableFailure(member);
|
|
@@ -3070,6 +3115,11 @@ export function apply(ctx, config = {}) {
|
|
|
3070
3115
|
if (typeof body?.type !== 'string' || body.type === '') {
|
|
3071
3116
|
return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: 'command type is required' } }, 400);
|
|
3072
3117
|
}
|
|
3118
|
+
// 人员池可能还持有归档前的快照,不允许旧的批量配置修改归档项目。
|
|
3119
|
+
if (body.type === 'member.config.update' &&
|
|
3120
|
+
peopleProjectIsArchived(booted.registry.list().find((entry) => entry.id === runtime.id), runtime)) {
|
|
3121
|
+
return send(res, { error: { code: 'E_INVALID_STATE', message: 'project is archived' } }, 409);
|
|
3122
|
+
}
|
|
3073
3123
|
// 归档保护在实际的全局清单上判定(registry 跨项目;service 只见
|
|
3074
3124
|
// 自己的账本,旧实现在 service 内判定导致所有归档被误拒)。
|
|
3075
3125
|
if (body.type === 'project.archive' && body.payload?.archived !== false) {
|
|
@@ -3125,10 +3175,11 @@ export function apply(ctx, config = {}) {
|
|
|
3125
3175
|
if (distilled.error !== undefined) return send(res, { error: distilled.error }, distilled.status ?? 502);
|
|
3126
3176
|
return send(res, distilled);
|
|
3127
3177
|
}
|
|
3128
|
-
if (body.type === 'project.create') {
|
|
3178
|
+
if (body.type === 'project.create' || body.type === 'project.blueprint.preview') {
|
|
3129
3179
|
const name = typeof body.payload?.name === 'string' ? body.payload.name.trim() : '';
|
|
3130
3180
|
const goal = typeof body.payload?.goal === 'string' ? body.payload.goal.trim() : '';
|
|
3131
3181
|
const workspacePath = typeof body.payload?.workspacePath === 'string' ? body.payload.workspacePath.trim() : '';
|
|
3182
|
+
const preview = body.type === 'project.blueprint.preview';
|
|
3132
3183
|
if (name === '') return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: 'project name is required' } }, 400);
|
|
3133
3184
|
// 每个项目都必须指定工作目录:先在这里挡,别把一行没有目录的
|
|
3134
3185
|
// registry 记录写进去(service 也会再校验一次)。
|
|
@@ -3147,6 +3198,36 @@ export function apply(ctx, config = {}) {
|
|
|
3147
3198
|
return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: `工作目录不存在或不是目录:${workspacePath}` } }, 400);
|
|
3148
3199
|
}
|
|
3149
3200
|
}
|
|
3201
|
+
const blueprint = preview || body.payload?.blueprint !== undefined ? buildTeamBlueprint({ ...body.payload?.blueprint, goal }) : null;
|
|
3202
|
+
if (blueprint) {
|
|
3203
|
+
const id = preview ? ids.project() : body.payload?.blueprintId;
|
|
3204
|
+
if (typeof id !== 'string' || !/^prj_[0-9A-HJKMNP-TV-Z]{22}$/.test(id)) {
|
|
3205
|
+
return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '请先预览试跑蓝图' } }, 400);
|
|
3206
|
+
}
|
|
3207
|
+
const fingerprint = blueprintFingerprint({ id, name, workspacePath, blueprint });
|
|
3208
|
+
if (preview) {
|
|
3209
|
+
diag.append({ ev: 'blueprint.previewed', id, useCase: blueprint.selected.kind, candidates: blueprint.candidates.filter((entry) => entry.work).length });
|
|
3210
|
+
return send(res, { ok: true, id, fingerprint, markdown: renderTeamBlueprint(blueprint) });
|
|
3211
|
+
}
|
|
3212
|
+
if (body.payload?.blueprintFingerprint !== fingerprint) {
|
|
3213
|
+
return send(res, { error: { code: 'E_CONFLICT', message: '答案有更新,请重新预览并确认蓝图' } }, 409);
|
|
3214
|
+
}
|
|
3215
|
+
const existing = projectRuntime(id)?.service.state.projects?.[id];
|
|
3216
|
+
if (existing) {
|
|
3217
|
+
const existingFingerprint = blueprintFingerprint({ id, name: existing.name, workspacePath: existing.workspacePath, blueprint: existing.blueprint });
|
|
3218
|
+
if (fingerprint !== existingFingerprint) return send(res, { error: { code: 'E_CONFLICT', message: '蓝图对应的项目已存在' } }, 409);
|
|
3219
|
+
return send(res, { ok: true, project: existing });
|
|
3220
|
+
}
|
|
3221
|
+
let pending = blueprintCreations.get(id);
|
|
3222
|
+
if (pending && pending.fingerprint !== fingerprint) return send(res, { error: { code: 'E_CONFLICT', message: '这个蓝图正在创建' } }, 409);
|
|
3223
|
+
if (!pending) {
|
|
3224
|
+
const runtimePromise = activateProject(id, name, goal, workspacePath, '', blueprint).finally(() => blueprintCreations.delete(id));
|
|
3225
|
+
pending = { fingerprint, runtimePromise };
|
|
3226
|
+
blueprintCreations.set(id, pending);
|
|
3227
|
+
}
|
|
3228
|
+
const next = await pending.runtimePromise;
|
|
3229
|
+
return send(res, { ok: true, project: next.service.state.projects[id] });
|
|
3230
|
+
}
|
|
3150
3231
|
// 新建时选的团队:必须在目录里且引用的人才都在(否则种成员会悄悄退回默认团队)。
|
|
3151
3232
|
const team = typeof body.payload?.team === 'string' ? body.payload.team.trim() : '';
|
|
3152
3233
|
if (team !== '') {
|
|
@@ -3155,14 +3236,13 @@ export function apply(ctx, config = {}) {
|
|
|
3155
3236
|
if (chosen.broken) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: `团队「${chosen.name}」引用了不存在的人才,先修好再用` } }, 400);
|
|
3156
3237
|
}
|
|
3157
3238
|
const id = ids.project();
|
|
3158
|
-
// 先校验工作目录(上面已做),再写 registry、最后开 runtime:
|
|
3159
|
-
// activateProject 内部会调用 registry.setActive(id),因此该行必须已
|
|
3160
|
-
// 存在。校验前置后,不会再把一个打不开的项目写进 projects.json。
|
|
3161
|
-
booted.registry.add({ id, name, goal, workspacePath });
|
|
3162
3239
|
const next = await activateProject(id, name, goal, workspacePath, team);
|
|
3163
3240
|
diag?.append({ ev: 'project.create', id, team: team || null });
|
|
3164
3241
|
return send(res, { ok: true, project: next.service.state.projects[id] ?? { id, name } });
|
|
3165
3242
|
}
|
|
3243
|
+
if (body.type === 'project.blueprint.start' && runtime.service.state.projects?.[runtime.id]?.blueprint && !blueprintGuardReady) {
|
|
3244
|
+
return errorResponse(res, Object.assign(new Error('宿主未注册首发试跑工具门禁'), { code: 'E_RUNTIME_UNAVAILABLE', status: 503 }));
|
|
3245
|
+
}
|
|
3166
3246
|
if (body.type === 'project.activate') {
|
|
3167
3247
|
const target = body.payload?.projectId;
|
|
3168
3248
|
if (typeof target !== 'string' || !booted.registry.list().some((project) => project.id === target)) {
|
package/lib/domain/ids.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
4
|
-
|
|
5
|
-
/** Monotonic-ish ULID-style id: 10 chars time + 12 chars randomness. */
|
|
6
|
-
export function newId(prefix = '') {
|
|
7
|
-
let time = Date.now();
|
|
8
|
-
let out = '';
|
|
9
|
-
for (let i = 0; i < 10; i += 1) {
|
|
10
|
-
out = CROCKFORD[time % 32] + out;
|
|
11
|
-
time = Math.floor(time / 32);
|
|
12
|
-
}
|
|
13
|
-
const bytes = randomBytes(12);
|
|
14
|
-
for (const byte of bytes) out += CROCKFORD[byte % 32];
|
|
15
|
-
return prefix === '' ? out : `${prefix}_${out}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const ids = {
|
|
19
|
-
project: () => newId('prj'),
|
|
20
|
-
member: () => newId('mem'),
|
|
21
|
-
task: () => newId('tsk'),
|
|
22
|
-
event: () => newId('evt'),
|
|
23
|
-
stream: () => newId('str'),
|
|
24
|
-
inbox: () => newId('inb'),
|
|
25
|
-
review: () => newId('rev'),
|
|
26
|
-
};
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
4
|
+
|
|
5
|
+
/** Monotonic-ish ULID-style id: 10 chars time + 12 chars randomness. */
|
|
6
|
+
export function newId(prefix = '') {
|
|
7
|
+
let time = Date.now();
|
|
8
|
+
let out = '';
|
|
9
|
+
for (let i = 0; i < 10; i += 1) {
|
|
10
|
+
out = CROCKFORD[time % 32] + out;
|
|
11
|
+
time = Math.floor(time / 32);
|
|
12
|
+
}
|
|
13
|
+
const bytes = randomBytes(12);
|
|
14
|
+
for (const byte of bytes) out += CROCKFORD[byte % 32];
|
|
15
|
+
return prefix === '' ? out : `${prefix}_${out}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ids = {
|
|
19
|
+
project: () => newId('prj'),
|
|
20
|
+
member: () => newId('mem'),
|
|
21
|
+
task: () => newId('tsk'),
|
|
22
|
+
event: () => newId('evt'),
|
|
23
|
+
stream: () => newId('str'),
|
|
24
|
+
inbox: () => newId('inb'),
|
|
25
|
+
review: () => newId('rev'),
|
|
26
|
+
};
|
package/lib/domain/inbox.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { ERRORS, fail } from './errors.js';
|
|
2
|
-
import { ids } from './ids.js';
|
|
3
|
-
|
|
4
|
-
/** The 12 closed inbox types from 02 FR-028. */
|
|
5
|
-
export const INBOX_TYPES = new Set([
|
|
6
|
-
'mention',
|
|
7
|
-
'assigned',
|
|
8
|
-
'handoff',
|
|
9
|
-
'review_requested',
|
|
10
|
-
'review_result',
|
|
11
|
-
'task_blocked',
|
|
12
|
-
'dependency_cleared',
|
|
13
|
-
'member_stalled',
|
|
14
|
-
'project_recovered',
|
|
15
|
-
'followed_task_update',
|
|
16
|
-
'decision_required',
|
|
17
|
-
'stale_reply_rejected',
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
export const DECISION_TYPES = new Set(['decision_required']);
|
|
21
|
-
|
|
22
|
-
/** Progress reports mentioning Human are not actionable decisions. */
|
|
23
|
-
export function isInformationalThreadMention(item) {
|
|
24
|
-
return item?.ref?.category === 'thread_mention'
|
|
25
|
-
&& !(Array.isArray(item.ref?.questions) && item.ref.questions.length > 0);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Create one inbox item. It points at a source object; it is not a copy of the
|
|
30
|
-
* message body (the reader pulls the source on demand).
|
|
31
|
-
*/
|
|
32
|
-
export function createInboxItem(input, options = {}) {
|
|
33
|
-
if (typeof input.memberId !== 'string' || input.memberId === '') fail(ERRORS.INVALID_ARGUMENT, 'memberId is required');
|
|
34
|
-
if (!INBOX_TYPES.has(input.type)) fail(ERRORS.INVALID_ARGUMENT, `unknown inbox type: ${String(input.type)}`);
|
|
35
|
-
if (input.ref === undefined || input.ref === null) fail(ERRORS.INVALID_ARGUMENT, 'ref is required');
|
|
36
|
-
const requiresDecision = input.requiresDecision ?? DECISION_TYPES.has(input.type);
|
|
37
|
-
return {
|
|
38
|
-
id: input.id ?? ids.inbox(),
|
|
39
|
-
memberId: input.memberId,
|
|
40
|
-
type: input.type,
|
|
41
|
-
ref: input.ref,
|
|
42
|
-
requiresDecision,
|
|
43
|
-
state: 'unread',
|
|
44
|
-
createdAt: options.at ?? Date.now(),
|
|
45
|
-
ackedAt: null,
|
|
46
|
-
disposition: null,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Acknowledge one item. Decision items may be marked read but cannot be marked
|
|
52
|
-
* done without an explicit decision; they can never be bulk-acked.
|
|
53
|
-
*/
|
|
54
|
-
export function ackInboxItem(item, input, options = {}) {
|
|
55
|
-
if (item.state === 'resolved' || item.state === 'dismissed' || item.state === 'superseded') return item;
|
|
56
|
-
const disposition = input.disposition ?? 'read';
|
|
57
|
-
if (disposition !== 'read' && disposition !== 'done' && disposition !== 'dismiss') {
|
|
58
|
-
fail(ERRORS.INVALID_ARGUMENT, 'disposition must be read, done or dismiss');
|
|
59
|
-
}
|
|
60
|
-
if (item.requiresDecision && disposition === 'done' && input.decision === undefined) {
|
|
61
|
-
fail(ERRORS.INVALID_STATE, 'a decision item requires an explicit decision before it can be done', {
|
|
62
|
-
details: { itemId: item.id },
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
...item,
|
|
67
|
-
state: disposition === 'done' ? 'resolved' : disposition === 'dismiss' ? 'dismissed' : 'read',
|
|
68
|
-
disposition,
|
|
69
|
-
decision: input.decision ?? null,
|
|
70
|
-
ackedAt: options.at ?? Date.now(),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Bulk read only touches non-decision items; decision items stay unread. */
|
|
75
|
-
export function markAllRead(items, options = {}) {
|
|
76
|
-
let changed = 0;
|
|
77
|
-
const next = items.map((item) => {
|
|
78
|
-
if (item.state !== 'unread' || item.requiresDecision) return item;
|
|
79
|
-
changed += 1;
|
|
80
|
-
return { ...item, state: 'read', disposition: 'read', ackedAt: options.at ?? Date.now() };
|
|
81
|
-
});
|
|
82
|
-
return { items: next, changed };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Five fixed Human-inbox groups, in product order. */
|
|
86
|
-
export function inboxGroup(item) {
|
|
87
|
-
if (item.requiresDecision) return 'needs_decision';
|
|
88
|
-
if (item.type === 'review_requested') return 'needs_review';
|
|
89
|
-
if (item.type === 'mention') return 'mentions';
|
|
90
|
-
if (item.type === 'followed_task_update') return 'following';
|
|
91
|
-
if (item.type === 'member_stalled' || item.type === 'project_recovered' || item.type === 'task_blocked') return 'failures';
|
|
92
|
-
return 'other';
|
|
93
|
-
}
|
|
1
|
+
import { ERRORS, fail } from './errors.js';
|
|
2
|
+
import { ids } from './ids.js';
|
|
3
|
+
|
|
4
|
+
/** The 12 closed inbox types from 02 FR-028. */
|
|
5
|
+
export const INBOX_TYPES = new Set([
|
|
6
|
+
'mention',
|
|
7
|
+
'assigned',
|
|
8
|
+
'handoff',
|
|
9
|
+
'review_requested',
|
|
10
|
+
'review_result',
|
|
11
|
+
'task_blocked',
|
|
12
|
+
'dependency_cleared',
|
|
13
|
+
'member_stalled',
|
|
14
|
+
'project_recovered',
|
|
15
|
+
'followed_task_update',
|
|
16
|
+
'decision_required',
|
|
17
|
+
'stale_reply_rejected',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const DECISION_TYPES = new Set(['decision_required']);
|
|
21
|
+
|
|
22
|
+
/** Progress reports mentioning Human are not actionable decisions. */
|
|
23
|
+
export function isInformationalThreadMention(item) {
|
|
24
|
+
return item?.ref?.category === 'thread_mention'
|
|
25
|
+
&& !(Array.isArray(item.ref?.questions) && item.ref.questions.length > 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create one inbox item. It points at a source object; it is not a copy of the
|
|
30
|
+
* message body (the reader pulls the source on demand).
|
|
31
|
+
*/
|
|
32
|
+
export function createInboxItem(input, options = {}) {
|
|
33
|
+
if (typeof input.memberId !== 'string' || input.memberId === '') fail(ERRORS.INVALID_ARGUMENT, 'memberId is required');
|
|
34
|
+
if (!INBOX_TYPES.has(input.type)) fail(ERRORS.INVALID_ARGUMENT, `unknown inbox type: ${String(input.type)}`);
|
|
35
|
+
if (input.ref === undefined || input.ref === null) fail(ERRORS.INVALID_ARGUMENT, 'ref is required');
|
|
36
|
+
const requiresDecision = input.requiresDecision ?? DECISION_TYPES.has(input.type);
|
|
37
|
+
return {
|
|
38
|
+
id: input.id ?? ids.inbox(),
|
|
39
|
+
memberId: input.memberId,
|
|
40
|
+
type: input.type,
|
|
41
|
+
ref: input.ref,
|
|
42
|
+
requiresDecision,
|
|
43
|
+
state: 'unread',
|
|
44
|
+
createdAt: options.at ?? Date.now(),
|
|
45
|
+
ackedAt: null,
|
|
46
|
+
disposition: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Acknowledge one item. Decision items may be marked read but cannot be marked
|
|
52
|
+
* done without an explicit decision; they can never be bulk-acked.
|
|
53
|
+
*/
|
|
54
|
+
export function ackInboxItem(item, input, options = {}) {
|
|
55
|
+
if (item.state === 'resolved' || item.state === 'dismissed' || item.state === 'superseded') return item;
|
|
56
|
+
const disposition = input.disposition ?? 'read';
|
|
57
|
+
if (disposition !== 'read' && disposition !== 'done' && disposition !== 'dismiss') {
|
|
58
|
+
fail(ERRORS.INVALID_ARGUMENT, 'disposition must be read, done or dismiss');
|
|
59
|
+
}
|
|
60
|
+
if (item.requiresDecision && disposition === 'done' && input.decision === undefined) {
|
|
61
|
+
fail(ERRORS.INVALID_STATE, 'a decision item requires an explicit decision before it can be done', {
|
|
62
|
+
details: { itemId: item.id },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...item,
|
|
67
|
+
state: disposition === 'done' ? 'resolved' : disposition === 'dismiss' ? 'dismissed' : 'read',
|
|
68
|
+
disposition,
|
|
69
|
+
decision: input.decision ?? null,
|
|
70
|
+
ackedAt: options.at ?? Date.now(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Bulk read only touches non-decision items; decision items stay unread. */
|
|
75
|
+
export function markAllRead(items, options = {}) {
|
|
76
|
+
let changed = 0;
|
|
77
|
+
const next = items.map((item) => {
|
|
78
|
+
if (item.state !== 'unread' || item.requiresDecision) return item;
|
|
79
|
+
changed += 1;
|
|
80
|
+
return { ...item, state: 'read', disposition: 'read', ackedAt: options.at ?? Date.now() };
|
|
81
|
+
});
|
|
82
|
+
return { items: next, changed };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Five fixed Human-inbox groups, in product order. */
|
|
86
|
+
export function inboxGroup(item) {
|
|
87
|
+
if (item.requiresDecision) return 'needs_decision';
|
|
88
|
+
if (item.type === 'review_requested') return 'needs_review';
|
|
89
|
+
if (item.type === 'mention') return 'mentions';
|
|
90
|
+
if (item.type === 'followed_task_update') return 'following';
|
|
91
|
+
if (item.type === 'member_stalled' || item.type === 'project_recovered' || item.type === 'task_blocked') return 'failures';
|
|
92
|
+
return 'other';
|
|
93
|
+
}
|