@peer-agent/protocol 0.1.0-rc.4 → 0.1.0-rc.41
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/dist/acceptance-close-gate.d.ts +10 -1
- package/dist/acceptance-close-gate.js +12 -0
- package/dist/agent-supervision.d.ts +81 -0
- package/dist/agent-supervision.js +1 -0
- package/dist/attention.d.ts +44 -0
- package/dist/attention.js +1 -0
- package/dist/bot-access-policy.d.ts +29 -0
- package/dist/bot-access-policy.js +1 -0
- package/dist/bot-conversation-read.d.ts +25 -0
- package/dist/bot-conversation-read.js +9 -0
- package/dist/bot-model-selection.d.ts +13 -0
- package/dist/bot-model-selection.js +1 -0
- package/dist/browser-window.d.ts +48 -0
- package/dist/browser-window.js +23 -0
- package/dist/capability-admission.d.ts +20 -0
- package/dist/capability-admission.js +1 -0
- package/dist/delegation-coordination.d.ts +81 -0
- package/dist/delegation-coordination.js +1 -0
- package/dist/delegation.d.ts +216 -7
- package/dist/delegation.js +43 -39
- package/dist/document-reference.d.ts +83 -0
- package/dist/document-reference.js +1 -0
- package/dist/evidence-inspection.d.ts +64 -0
- package/dist/evidence-inspection.js +1 -0
- package/dist/goal.d.ts +50 -2
- package/dist/index.d.ts +56 -5
- package/dist/index.js +25 -0
- package/dist/input-prediction.d.ts +86 -0
- package/dist/input-prediction.js +48 -0
- package/dist/intent-coordination.d.ts +201 -0
- package/dist/intent-coordination.js +1 -0
- package/dist/interactive-result.d.ts +363 -0
- package/dist/interactive-result.js +215 -0
- package/dist/interactive-verification.d.ts +41 -0
- package/dist/interactive-verification.js +65 -0
- package/dist/local-git.d.ts +44 -0
- package/dist/local-git.js +3 -0
- package/dist/local-image.d.ts +53 -0
- package/dist/local-image.js +5 -0
- package/dist/model-reasoning.d.ts +13 -0
- package/dist/model-reasoning.js +18 -0
- package/dist/model-routing.d.ts +37 -3
- package/dist/model-routing.js +31 -5
- package/dist/project-agent-failure.d.ts +30 -0
- package/dist/project-agent-failure.js +44 -0
- package/dist/project-input-recovery.d.ts +65 -0
- package/dist/project-input-recovery.js +5 -0
- package/dist/project-recovery.d.ts +43 -0
- package/dist/project-recovery.js +1 -0
- package/dist/project.d.ts +81 -0
- package/dist/project.js +8 -5
- package/dist/remote-access.d.ts +15 -0
- package/dist/remote-access.js +1 -1
- package/dist/reply-delivery.d.ts +28 -0
- package/dist/reply-delivery.js +1 -0
- package/dist/resource-edit-execution.d.ts +68 -0
- package/dist/resource-edit-execution.js +96 -0
- package/dist/resource-edit.d.ts +237 -0
- package/dist/resource-edit.js +134 -0
- package/dist/resource-feedback-transport.d.ts +25 -0
- package/dist/resource-feedback-transport.js +93 -0
- package/dist/resource-feedback.d.ts +98 -0
- package/dist/resource-feedback.js +151 -0
- package/dist/resource-file-replace.d.ts +36 -0
- package/dist/resource-file-replace.js +40 -0
- package/dist/resource-reference-hints.d.ts +3 -0
- package/dist/resource-reference-hints.js +58 -0
- package/dist/resource-window.d.ts +222 -0
- package/dist/resource-window.js +252 -0
- package/dist/runtime-session-facts.d.ts +58 -0
- package/dist/runtime-session-facts.js +55 -0
- package/dist/session-control.d.ts +196 -0
- package/dist/session-control.js +48 -0
- package/dist/session-facts.d.ts +29 -0
- package/dist/session-facts.js +35 -0
- package/dist/system-context.d.ts +6 -0
- package/dist/task-overview.d.ts +90 -0
- package/dist/task-overview.js +322 -17
- package/dist/tool-activity-preview.d.ts +4 -0
- package/dist/tool-activity-preview.js +72 -0
- package/dist/usage-accounting.d.ts +1 -1
- package/dist/user-anchor.d.ts +17 -0
- package/dist/user-anchor.js +1 -0
- package/dist/work-coordination.d.ts +165 -0
- package/dist/work-coordination.js +1 -0
- package/package.json +1 -1
package/dist/task-overview.js
CHANGED
|
@@ -1,24 +1,316 @@
|
|
|
1
|
+
import { projectGoalTiming } from "./goal.js";
|
|
2
|
+
function followUpOf(owner, reason) {
|
|
3
|
+
return { owner, inCurrentList: owner !== 'none', reason };
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
6
|
+
* 责任判定:只读同一份生命周期结论 + 同一份权威事实,不引入第二套状态机。
|
|
7
|
+
* 缺事实一律 fail closed(留在当前列表、责任在 bot),不按文案推断承接或停止。
|
|
8
|
+
*/
|
|
9
|
+
export function decideFollowUp(decision, facts = {}, ownership = 'unknown') {
|
|
10
|
+
const status = decision.status;
|
|
11
|
+
const live = ownership === 'live';
|
|
12
|
+
// 停止回执是宿主在 abort + waitForIdle 之后写入的事实,不是从 status 猜的终态;
|
|
13
|
+
// `executionOwnership==='unknown'` 单独(重启残留的 running/idle/paused)不能证明已结束,
|
|
14
|
+
// 只有回执 completed 且没有活体执行才算已确认停止。
|
|
15
|
+
const stopStatus = status === 'cancelled' || status === 'stopping' || status === 'awaiting_outcome';
|
|
16
|
+
const stopPending = stopStatus && !(facts.cancellationPhase === 'completed' && !live);
|
|
17
|
+
const humanNeedsYou = status === 'waiting_user'
|
|
18
|
+
|| (status === 'result_ready' && facts.humanGate === true && facts.accepted !== true);
|
|
19
|
+
// 1) 保护性事实优先:活动执行、真实人工请求、未决停止回执,都不允许被“已签收 / 已被承接”
|
|
20
|
+
// 提前盖掉。`unknown` 本身不构成结束证据;停止只认宿主写入的完成回执。
|
|
21
|
+
if (humanNeedsYou) {
|
|
22
|
+
return status === 'result_ready' || decision.needsYouReason === 'decision'
|
|
23
|
+
? followUpOf('user', 'awaiting_human_gate')
|
|
24
|
+
: followUpOf('user', 'human_request');
|
|
25
|
+
}
|
|
26
|
+
if (live)
|
|
27
|
+
return followUpOf('bot', 'live_execution');
|
|
28
|
+
// An authorized follow-up retirement leaves the current list without claiming the stop succeeded.
|
|
29
|
+
if (facts.obligationDisposition === 'indexed')
|
|
30
|
+
return followUpOf('none', 'obligation_indexed');
|
|
31
|
+
if (stopPending)
|
|
32
|
+
return followUpOf('bot', 'stop_unconfirmed');
|
|
33
|
+
if (stopStatus && facts.cancellationDisposition === 'user_withdrawn')
|
|
34
|
+
return followUpOf('none', 'user_withdrawn');
|
|
35
|
+
// 2) 退出当前待办:只有上面三类事实都不成立时,承接 / 失败 / 签收 / 已确认停止才生效。
|
|
36
|
+
// 退出只影响“当前列表归属”,不改写原验收、原核验与未完成事实。
|
|
37
|
+
if (facts.superseded === true || status === 'superseded')
|
|
38
|
+
return followUpOf('none', 'superseded');
|
|
39
|
+
// 3) 核验失败/缺证据:即使存在历史 accepted 事实也不能静默(那次验收是旧结论)。
|
|
40
|
+
if (['failed', 'waiting_agent'].includes(status) && facts.blockedReason === 'conversation_persistence_failed')
|
|
41
|
+
return followUpOf('bot', 'local_persistence_failed');
|
|
42
|
+
if (status === 'failed')
|
|
43
|
+
return followUpOf('bot', 'verification_failed');
|
|
44
|
+
if (facts.accepted === true)
|
|
45
|
+
return followUpOf('none', 'settled');
|
|
46
|
+
if (stopStatus)
|
|
47
|
+
return followUpOf('none', 'stop_confirmed');
|
|
48
|
+
// 4) 父代理等技术阻塞:主 Bot 责任,不显示需要用户确认。
|
|
49
|
+
if (status === 'waiting_agent')
|
|
50
|
+
return followUpOf('bot', 'technical_block');
|
|
51
|
+
// 5) 执行交回不等于验收:普通结果由 Bot 自动收口,只有宿主确认过的人工门才换责任人。
|
|
52
|
+
if (status === 'result_ready')
|
|
53
|
+
return followUpOf('bot', 'awaiting_acceptance_technical');
|
|
54
|
+
// 11. 活动执行/核验:保留在当前列表。
|
|
55
|
+
if (status === 'verifying' || status === 'running' || status === 'starting' || status === 'queued') {
|
|
56
|
+
return followUpOf('bot', 'live_execution');
|
|
57
|
+
}
|
|
58
|
+
// 12. 用户暂停:等待用户恢复,维持既有「不在当前待办」表现。
|
|
59
|
+
if (status === 'paused') {
|
|
60
|
+
if (facts.interrupted === true && facts.interruptionOrigin !== 'user') {
|
|
61
|
+
return followUpOf('bot', facts.interruptionOrigin && facts.interruptionOrigin !== 'unknown' ? 'technical_block' : 'unknown_facts');
|
|
62
|
+
}
|
|
63
|
+
return followUpOf('none', 'paused');
|
|
64
|
+
}
|
|
65
|
+
// 13. 已是验收事实的状态。
|
|
66
|
+
if (status === 'accepted')
|
|
67
|
+
return followUpOf('none', 'settled');
|
|
68
|
+
// 14. 事实缺失或未知停止回执:fail closed。
|
|
69
|
+
return followUpOf('bot', 'unknown_facts');
|
|
70
|
+
}
|
|
71
|
+
/** 仍在占用执行体的 runner 状态(持久化字符串本身不构成活体证据)。 */
|
|
72
|
+
const ACTIVE_EXECUTION_RUNNER_STATUSES = new Set([
|
|
73
|
+
'running',
|
|
74
|
+
'starting',
|
|
75
|
+
'waiting_provider',
|
|
76
|
+
'resuming_after_compaction',
|
|
77
|
+
'exploring',
|
|
78
|
+
]);
|
|
79
|
+
/** 终态与"结果待核实"不可取消:停止中/结果未知也不能靠重复取消恢复。 */
|
|
80
|
+
const NON_CANCELABLE_STATUSES = new Set([
|
|
81
|
+
'accepted',
|
|
82
|
+
'failed',
|
|
83
|
+
'cancelled',
|
|
84
|
+
'superseded',
|
|
85
|
+
'result_ready',
|
|
86
|
+
'stopping',
|
|
87
|
+
'awaiting_outcome',
|
|
88
|
+
]);
|
|
89
|
+
/**
|
|
90
|
+
* 生命周期唯一决策。
|
|
5
91
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
92
|
+
* 关键不变量:
|
|
93
|
+
* - 活 token 不能压过等待用户/父代理、核验、停止中/结果未知、中断等更具体事实;
|
|
94
|
+
* - 持久化 `runnerStatus` 在 ownership=unknown 时不得当作"还在跑";
|
|
95
|
+
* - `accepted` 只来自真实验收事实(本函数不制造 accepted);
|
|
96
|
+
* - 返回的字段必须被所有投影直接消费,不得二次推导。
|
|
9
97
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
98
|
+
* 过渡兼容:不传 `executionOwnership` 的旧入口按 `unknown` 处理——
|
|
99
|
+
* `runner.status` 字符串本身不能证明"还在跑";真实入口(S2/S3)应显式传入 live/ended/unknown。
|
|
100
|
+
*/
|
|
101
|
+
function decideLifecycleCore(snapshot, facts = {}) {
|
|
102
|
+
const declaredOwnership = facts.executionOwnership ?? snapshot.executionOwnership;
|
|
103
|
+
const ownership = declaredOwnership ?? 'unknown';
|
|
104
|
+
const persistedRunner = snapshot.runnerStatus;
|
|
105
|
+
const persistedActive = persistedRunner ? ACTIVE_EXECUTION_RUNNER_STATUSES.has(persistedRunner) : false;
|
|
106
|
+
const liveExecution = ownership === 'live' && (persistedActive || persistedRunner === undefined);
|
|
107
|
+
// 持久化 runner 状态不是活体证据:unknown(重启遗留)和 ended(活流已结束、数据滞后)
|
|
108
|
+
// 都不能凭字符串冒充 live。waiting_user 的待消费问题按 ADR 100 保留。
|
|
109
|
+
const stalePersistedRunner = persistedActive && ownership !== 'live';
|
|
110
|
+
const runnerStatus = stalePersistedRunner ? undefined : persistedRunner;
|
|
111
|
+
const { runnerStatus: _rawRunnerStatus, ...snapshotRest } = snapshot;
|
|
112
|
+
const canonical = {
|
|
113
|
+
...snapshotRest,
|
|
114
|
+
...(runnerStatus ? { runnerStatus } : {}),
|
|
115
|
+
liveExecution,
|
|
116
|
+
};
|
|
117
|
+
const decision = decideGoalPlan(canonical);
|
|
118
|
+
const accepted = facts.accepted ?? snapshot.accepted;
|
|
119
|
+
const needsUserFacts = facts.needsUser === true ||
|
|
120
|
+
snapshot.needsUser === true ||
|
|
121
|
+
snapshot.status === 'awaiting_approval';
|
|
122
|
+
const verificationActive = facts.verificationActive === true;
|
|
123
|
+
const blockedReason = facts.blockedReason ?? snapshot.blockedReason;
|
|
124
|
+
const interrupted = facts.interrupted ?? snapshot.interrupted === true;
|
|
125
|
+
const interruptionOrigin = facts.interruptionOrigin ?? snapshot.interruptionOrigin;
|
|
126
|
+
const delegated = facts.delegated ?? snapshot.delegated === true;
|
|
127
|
+
let status;
|
|
128
|
+
// A host-confirmed stop wins over stale recovery/takeover fields, never a live owner.
|
|
129
|
+
if (snapshot.status === 'cancelled' || facts.cancellationPhase === 'completed' && ownership !== 'live')
|
|
130
|
+
status = 'cancelled';
|
|
131
|
+
else if (snapshot.status === 'failed')
|
|
132
|
+
status = 'failed';
|
|
133
|
+
else if (accepted === true)
|
|
134
|
+
status = 'accepted';
|
|
135
|
+
else if (facts.cancellationPhase === 'awaiting_outcome' ||
|
|
136
|
+
facts.takeoverPhase === 'awaiting_outcome')
|
|
137
|
+
status = 'awaiting_outcome';
|
|
138
|
+
else if (facts.cancellationPhase === 'stopping')
|
|
139
|
+
status = 'stopping';
|
|
140
|
+
else if (facts.takeoverPhase === 'stopping')
|
|
141
|
+
status = 'starting';
|
|
142
|
+
else if (facts.superseded === true && snapshot.status !== 'completed')
|
|
143
|
+
status = 'superseded';
|
|
144
|
+
else if ((facts.phase === 'paused' || runnerStatus === 'paused') && snapshot.status !== 'completed')
|
|
145
|
+
status = 'paused';
|
|
146
|
+
// A failed delegated attempt leaves recovery with the parent, not a human pause.
|
|
147
|
+
else if (interrupted && interruptionOrigin !== 'user' && delegated && runnerStatus === 'failed' && !needsUserFacts && !liveExecution)
|
|
148
|
+
status = 'waiting_agent';
|
|
149
|
+
// 未消费中断优先于 completed/结果就绪(decideGoalPlan rule 1 已按此给文案),
|
|
150
|
+
// 但持久化终态(cancelled/failed)和真实验收结论先于它。
|
|
151
|
+
else if (interrupted)
|
|
152
|
+
status = 'paused';
|
|
153
|
+
else if (needsUserFacts || runnerStatus === 'waiting_user')
|
|
154
|
+
status = 'waiting_user';
|
|
155
|
+
// 预算/范围耗尽是真的需要人决策(rule 5b 已给 needs_you/decide_blocked):
|
|
156
|
+
// 不能被父代理等待标记等技术阻塞吞掉,也不能让 status 落在 running,
|
|
157
|
+
// 否则同一行会出现「由主 Bot 跟进 / 运行中 + 需要你决定」,真实预算决策丢失。
|
|
158
|
+
// 活流(liveExecution / conversationLive)说明预算门尚未真正落下,交给既有规则。
|
|
159
|
+
else if (runnerStatus === 'budget_exhausted' &&
|
|
160
|
+
!liveExecution &&
|
|
161
|
+
snapshot.conversationLive !== true)
|
|
162
|
+
status = 'waiting_user';
|
|
163
|
+
// 技术阻塞是父代理的工作,不是人类问题;活流说明阻塞已过期。
|
|
164
|
+
// 这里刻意保留 completed 的既有优先级:技术残留不越过完成,也不制造人类门,
|
|
165
|
+
// 只有真实人类门(审批/权限/提问/预算)能越过 completed(见 lifecyclePresentation)。
|
|
166
|
+
else if ((blockedReason === 'waiting_parent_agent' || snapshot.agentWaiting === true) &&
|
|
167
|
+
facts.phase !== 'paused' &&
|
|
168
|
+
facts.superseded !== true &&
|
|
169
|
+
runnerStatus !== 'paused' &&
|
|
170
|
+
!liveExecution)
|
|
171
|
+
status = 'waiting_agent';
|
|
172
|
+
else if (verificationActive)
|
|
173
|
+
status = 'verifying';
|
|
174
|
+
else if (runnerStatus === 'blocked' && !liveExecution)
|
|
175
|
+
status = 'waiting_agent';
|
|
176
|
+
else if (snapshot.status === 'completed' && runnerStatus && ACTIVE_EXECUTION_RUNNER_STATUSES.has(runnerStatus))
|
|
177
|
+
status = 'running';
|
|
178
|
+
// 计划已完成、但本进程仍持有执行 token(可能还没有 runner 状态字符串)。
|
|
179
|
+
else if (snapshot.status === 'completed' && liveExecution)
|
|
180
|
+
status = 'running';
|
|
181
|
+
else if (snapshot.status === 'completed')
|
|
182
|
+
status = 'result_ready';
|
|
183
|
+
else if (facts.phase === 'starting')
|
|
184
|
+
status = 'starting';
|
|
185
|
+
else if (['approved', 'accepted', 'paused', 'interrupted'].includes(snapshot.status) ||
|
|
186
|
+
facts.phase === 'queued')
|
|
187
|
+
status = 'queued';
|
|
188
|
+
else
|
|
189
|
+
status = 'running';
|
|
190
|
+
// 五字段必须同源:状态定稿后由同一个出口给出文案/行动权/下一步/可取消。
|
|
191
|
+
const presentation = lifecyclePresentation(status, decision, {
|
|
192
|
+
delegated,
|
|
193
|
+
accepted: accepted === true,
|
|
194
|
+
takeoverStopping: facts.takeoverPhase === 'stopping',
|
|
195
|
+
budgetGate: runnerStatus === 'budget_exhausted' &&
|
|
196
|
+
!liveExecution &&
|
|
197
|
+
snapshot.conversationLive !== true,
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
...presentation,
|
|
201
|
+
status,
|
|
202
|
+
cancelable: presentation.actionRight !== 'terminal' && !NON_CANCELABLE_STATUSES.has(status),
|
|
203
|
+
needsUser: status === 'waiting_user',
|
|
204
|
+
verificationActive: status === 'verifying',
|
|
205
|
+
...(blockedReason ? { blockedReason } : {}),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 状态语义 → 同一行文案/行动权(ADR 102 §4)。
|
|
15
210
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* 存储读出字段后组装快照,renderer 只拿到投影产物。这样契约边界清晰,
|
|
19
|
-
* 且测试无需构造巨型 fixture。
|
|
211
|
+
* 只覆盖"旧规则看不到这些事实"的 status;其余沿用既有文案,避免修一个坑挖一个坑。
|
|
212
|
+
* 调用方(任务卡/工作会话/抽屉)必须直接消费 decideLifecycle 的返回值。
|
|
20
213
|
*/
|
|
21
|
-
|
|
214
|
+
function lifecyclePresentation(status, legacy, facts) {
|
|
215
|
+
switch (status) {
|
|
216
|
+
case 'cancelled':
|
|
217
|
+
return {
|
|
218
|
+
actionRight: 'terminal',
|
|
219
|
+
nextAction: 'none',
|
|
220
|
+
statusLabel: '已取消',
|
|
221
|
+
actionLabel: '查看 →',
|
|
222
|
+
};
|
|
223
|
+
case 'waiting_user':
|
|
224
|
+
// completed 只说明计划已落库完成,不等于没有待你消费的决策:旧规则表把
|
|
225
|
+
// completed 放在最前(rule 16),会把预算门/待确认门吞成「已完成 / terminal」。
|
|
226
|
+
// 规则表已经给出 needs_you 的(审批、提问、权限、活跃计划预算)原样沿用,
|
|
227
|
+
// 只补它看不到的事实,文案/下一步复用既有配对,不新发明口径。
|
|
228
|
+
if (legacy.actionRight === 'needs_you')
|
|
229
|
+
return legacy;
|
|
230
|
+
return facts.budgetGate
|
|
231
|
+
? {
|
|
232
|
+
actionRight: 'needs_you',
|
|
233
|
+
needsYouReason: 'decision',
|
|
234
|
+
nextAction: 'decide_blocked',
|
|
235
|
+
statusLabel: '预算已耗尽',
|
|
236
|
+
actionLabel: '决策',
|
|
237
|
+
}
|
|
238
|
+
: {
|
|
239
|
+
actionRight: 'needs_you',
|
|
240
|
+
needsYouReason: 'user_input',
|
|
241
|
+
nextAction: 'answer_question',
|
|
242
|
+
statusLabel: '等待你的选择',
|
|
243
|
+
actionLabel: '回答 →',
|
|
244
|
+
};
|
|
245
|
+
case 'verifying':
|
|
246
|
+
// 核验 ≠ 完成:即使 plan 已落 completed,核验在跑就是核验中。
|
|
247
|
+
return {
|
|
248
|
+
actionRight: 'peer_advancing',
|
|
249
|
+
nextAction: 'none',
|
|
250
|
+
statusLabel: '核验中',
|
|
251
|
+
actionLabel: '查看 →',
|
|
252
|
+
};
|
|
253
|
+
case 'stopping':
|
|
254
|
+
return {
|
|
255
|
+
actionRight: 'peer_advancing',
|
|
256
|
+
nextAction: 'none',
|
|
257
|
+
statusLabel: '正在停止',
|
|
258
|
+
actionLabel: '查看 →',
|
|
259
|
+
};
|
|
260
|
+
case 'awaiting_outcome':
|
|
261
|
+
return {
|
|
262
|
+
actionRight: 'peer_advancing',
|
|
263
|
+
nextAction: 'none',
|
|
264
|
+
statusLabel: '执行结果待核实',
|
|
265
|
+
actionLabel: '查看 →',
|
|
266
|
+
};
|
|
267
|
+
case 'waiting_agent':
|
|
268
|
+
// 技术阻塞是父代理的跟进项,不是人类待办;具体文案(等待答复/系统中断)沿用旧规则。
|
|
269
|
+
return legacy.actionRight === 'needs_you' || (facts.delegated && legacy.actionRight === 'paused')
|
|
270
|
+
? {
|
|
271
|
+
actionRight: 'peer_advancing',
|
|
272
|
+
nextAction: 'none',
|
|
273
|
+
statusLabel: '由主 Bot 跟进',
|
|
274
|
+
actionLabel: '查看 →',
|
|
275
|
+
}
|
|
276
|
+
: legacy;
|
|
277
|
+
case 'starting':
|
|
278
|
+
return facts.takeoverStopping
|
|
279
|
+
? {
|
|
280
|
+
actionRight: 'peer_advancing',
|
|
281
|
+
nextAction: 'none',
|
|
282
|
+
statusLabel: '正在接手',
|
|
283
|
+
actionLabel: '查看 →',
|
|
284
|
+
}
|
|
285
|
+
: legacy;
|
|
286
|
+
case 'result_ready':
|
|
287
|
+
// 委派结果必须等真实验收:完成 ≠ 已验收(ADR 102 O4.2)。
|
|
288
|
+
// 非委派历史数据沿用既有完成契约(rule 6),不强制进入验收卡点。
|
|
289
|
+
return facts.delegated && !facts.accepted
|
|
290
|
+
? {
|
|
291
|
+
actionRight: 'result_ready',
|
|
292
|
+
nextAction: 'review_result',
|
|
293
|
+
statusLabel: '等待验收',
|
|
294
|
+
actionLabel: '验收 →',
|
|
295
|
+
}
|
|
296
|
+
: legacy;
|
|
297
|
+
default:
|
|
298
|
+
return legacy;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 公开唯一出口:先取既有生命周期结论,再补同一份事实算出的跟进责任(ADR 110)。
|
|
303
|
+
* 适配器只读 `followUp`,不得按 `status` 自行再判一次列表归属与责任人。
|
|
304
|
+
*/
|
|
305
|
+
export function decideLifecycle(snapshot, facts = {}) {
|
|
306
|
+
const core = decideLifecycleCore(snapshot, facts);
|
|
307
|
+
// 与核心同一表达式的读取:不新增事实来源,也不引入第二套规则。
|
|
308
|
+
const ownership = facts.executionOwnership ?? snapshot.executionOwnership ?? 'unknown';
|
|
309
|
+
return { ...core, followUp: decideFollowUp(core, { ...facts,
|
|
310
|
+
interrupted: facts.interrupted ?? snapshot.interrupted,
|
|
311
|
+
interruptionOrigin: facts.interruptionOrigin ?? snapshot.interruptionOrigin,
|
|
312
|
+
}, ownership) };
|
|
313
|
+
}
|
|
22
314
|
/** Conversation → 无计划讨论态(工作台动线 §15)。 */
|
|
23
315
|
/**
|
|
24
316
|
* 会话是否对首页「正在讨论」可见(未读)。
|
|
@@ -93,7 +385,7 @@ export function projectConversation(snapshot) {
|
|
|
93
385
|
* 因此实现时将 rule 14 放在 rule 8 之后、仅当 runner 显式 idle 时生效。
|
|
94
386
|
*/
|
|
95
387
|
export function projectGoalPlan(snapshot, options) {
|
|
96
|
-
const decision =
|
|
388
|
+
const decision = decideLifecycle(snapshot);
|
|
97
389
|
const projectedTiming = projectGoalTiming(snapshot.timing, options?.nowMs);
|
|
98
390
|
const durationMs = typeof projectedTiming?.activeMs === 'number' && Number.isFinite(projectedTiming.activeMs)
|
|
99
391
|
? Math.max(0, Math.floor(projectedTiming.activeMs))
|
|
@@ -170,6 +462,7 @@ export function projectGoalPlan(snapshot, options) {
|
|
|
170
462
|
: {}),
|
|
171
463
|
...(modelLabel ? { modelLabel } : {}),
|
|
172
464
|
...(providerLabel ? { providerLabel } : {}),
|
|
465
|
+
cancelable: decision.cancelable,
|
|
173
466
|
actionLabel: decision.actionLabel,
|
|
174
467
|
...(snapshot.conversationId ? { conversationId: snapshot.conversationId } : {}),
|
|
175
468
|
};
|
|
@@ -234,6 +527,15 @@ function decideGoalPlan(snapshot) {
|
|
|
234
527
|
};
|
|
235
528
|
}
|
|
236
529
|
}
|
|
530
|
+
// 计划已完成但本进程仍持有真实执行 token:不得投影为终态/已完成。
|
|
531
|
+
if (snapshot.liveExecution === true) {
|
|
532
|
+
return {
|
|
533
|
+
actionRight: 'peer_advancing',
|
|
534
|
+
nextAction: 'none',
|
|
535
|
+
statusLabel: 'Peer 正在推进',
|
|
536
|
+
actionLabel: '查看 →',
|
|
537
|
+
};
|
|
538
|
+
}
|
|
237
539
|
return {
|
|
238
540
|
actionRight: 'terminal',
|
|
239
541
|
nextAction: 'none',
|
|
@@ -271,6 +573,9 @@ function decideGoalPlan(snapshot) {
|
|
|
271
573
|
}
|
|
272
574
|
const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
|
|
273
575
|
const conversationLive = snapshot.conversationLive === true;
|
|
576
|
+
if (snapshot.agentWaiting && runnerStatus !== 'waiting_user' && ['executing', 'completed'].includes(status)) {
|
|
577
|
+
return { actionRight: 'peer_advancing', nextAction: 'none', statusLabel: '等待主 Bot 答复', actionLabel: '' };
|
|
578
|
+
}
|
|
274
579
|
const recoverableSystemBlocked = runnerStatus === 'blocked'
|
|
275
580
|
&& snapshot.systemBlocked === true;
|
|
276
581
|
// System infrastructure failures are not user decisions. A foreground turn may
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProjectAgentToolPreview } from './project.ts';
|
|
2
|
+
/** One bounded display seam for tool parameters/results in live and historical presentation. It never executes a tool. */
|
|
3
|
+
export declare function toolActivityPreview(value: unknown, limit: number): ProjectAgentToolPreview;
|
|
4
|
+
export declare function toolActivitySummary(input: Readonly<Record<string, unknown>> | null | undefined): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const PRIVATE_FIELD = /(?:api.?key|token|secret|password|credential|authorization|cookie|private.?key|reasoning|thinking)/i;
|
|
2
|
+
/** One bounded display seam for tool parameters/results in live and historical presentation. It never executes a tool. */
|
|
3
|
+
export function toolActivityPreview(value, limit) {
|
|
4
|
+
// A missing result is not the JSON literal null. Stringifying it prints the word "null".
|
|
5
|
+
if (value == null)
|
|
6
|
+
return { text: '', truncated: false, redacted: false };
|
|
7
|
+
if (typeof value === 'string' && value.length > 64_000)
|
|
8
|
+
return { text: '', truncated: true, redacted: true };
|
|
9
|
+
let redacted = false, truncated = false, nodes = 0;
|
|
10
|
+
const cleanText = (text) => {
|
|
11
|
+
const bounded = text.slice(0, 6000);
|
|
12
|
+
if (bounded.length < text.length)
|
|
13
|
+
truncated = true;
|
|
14
|
+
const clean = bounded
|
|
15
|
+
.replace(/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, '[redacted]')
|
|
16
|
+
.replace(/AKIA[0-9A-Z]{16}/g, '[redacted]')
|
|
17
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi, 'Bearer [redacted]')
|
|
18
|
+
.replace(/((?:api[_-]?key|token|secret|password|authorization|cookie)\s*["']?\s*[:=]\s*["']?)[^\s,"';}]+/gi, '$1[redacted]')
|
|
19
|
+
.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*/g, '[redacted]');
|
|
20
|
+
if (clean !== bounded)
|
|
21
|
+
redacted = true;
|
|
22
|
+
return clean;
|
|
23
|
+
};
|
|
24
|
+
const visit = (item, depth = 0) => {
|
|
25
|
+
if (++nodes > 160 || depth > 6) {
|
|
26
|
+
truncated = true;
|
|
27
|
+
return '[truncated]';
|
|
28
|
+
}
|
|
29
|
+
if (typeof item === 'string')
|
|
30
|
+
return cleanText(item);
|
|
31
|
+
if (item == null || typeof item === 'boolean' || typeof item === 'number')
|
|
32
|
+
return item;
|
|
33
|
+
if (Array.isArray(item)) {
|
|
34
|
+
if (item.length > 40)
|
|
35
|
+
truncated = true;
|
|
36
|
+
return item.slice(0, 40).map(child => visit(child, depth + 1));
|
|
37
|
+
}
|
|
38
|
+
if (typeof item === 'object') {
|
|
39
|
+
const fields = [];
|
|
40
|
+
for (const key in item) {
|
|
41
|
+
if (!Object.hasOwn(item, key))
|
|
42
|
+
continue;
|
|
43
|
+
if (fields.length >= 40) {
|
|
44
|
+
truncated = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
if (PRIVATE_FIELD.test(key)) {
|
|
48
|
+
redacted = true;
|
|
49
|
+
fields.push([key, '[redacted]']);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
fields.push([cleanText(key), visit(item[key], depth + 1)]);
|
|
53
|
+
}
|
|
54
|
+
return Object.fromEntries(fields);
|
|
55
|
+
}
|
|
56
|
+
return String(item);
|
|
57
|
+
};
|
|
58
|
+
let parsed = value;
|
|
59
|
+
if (typeof value === 'string') {
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(value);
|
|
62
|
+
}
|
|
63
|
+
catch { /* Plain terminal/file output. */ }
|
|
64
|
+
}
|
|
65
|
+
const clean = visit(parsed);
|
|
66
|
+
const text = typeof clean === 'string' ? clean : JSON.stringify(clean ?? null, null, 2);
|
|
67
|
+
return { text: text.slice(0, limit), truncated: truncated || text.length > limit, redacted };
|
|
68
|
+
}
|
|
69
|
+
export function toolActivitySummary(input) {
|
|
70
|
+
const value = input?.path ?? input?.command ?? input?.cmd ?? input?.query ?? input?.title;
|
|
71
|
+
return typeof value === 'string' ? toolActivityPreview(value.replace(/\s+/g, ' ').trim(), 160).text : '';
|
|
72
|
+
}
|
|
@@ -14,7 +14,7 @@ export interface UsageAmounts {
|
|
|
14
14
|
export interface ProviderRequestUsage extends UsageAmounts {
|
|
15
15
|
readonly usageScope: 'provider_request';
|
|
16
16
|
readonly requestIndex: number;
|
|
17
|
-
readonly requestPurpose: 'agent' | 'compaction_summary';
|
|
17
|
+
readonly requestPurpose: 'agent' | 'compaction_summary' | 'input_prediction';
|
|
18
18
|
readonly requestFingerprint?: string;
|
|
19
19
|
}
|
|
20
20
|
/** Billable sum of every provider request executed by one user/runtime turn. */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Local identity provenance, never permission, Evidence identity or task completion. */
|
|
2
|
+
export interface UserAnchorResolution {
|
|
3
|
+
readonly field: 'anchorMessageIds' | 'task.anchorMessageIds' | 'replyTo';
|
|
4
|
+
readonly suppliedId: string;
|
|
5
|
+
readonly messageId: string;
|
|
6
|
+
readonly source: 'message_id' | 'input_id';
|
|
7
|
+
}
|
|
8
|
+
export interface UserAnchorCandidate {
|
|
9
|
+
readonly messageId: string;
|
|
10
|
+
/** At most 120 characters; no attachment payloads. */
|
|
11
|
+
readonly text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface UserAnchorDiagnostic {
|
|
14
|
+
readonly anchorResolutions?: readonly UserAnchorResolution[];
|
|
15
|
+
readonly availableAnchors?: readonly UserAnchorCandidate[];
|
|
16
|
+
readonly availableReplyAnchors?: readonly UserAnchorCandidate[];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { ProjectRecoveryFailureKind } from './project-agent-failure.ts';
|
|
2
|
+
export interface ProjectWorkBudgetLimits {
|
|
3
|
+
readonly schemaVersion?: 2;
|
|
4
|
+
readonly source: string;
|
|
5
|
+
readonly maxModelRequests?: number;
|
|
6
|
+
readonly maxToolCalls?: number;
|
|
7
|
+
readonly maxTokens?: number;
|
|
8
|
+
readonly maxCostUsd?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ProjectWorkBudgetBoundary {
|
|
11
|
+
readonly metric: 'modelRequests' | 'toolCalls' | 'tokens' | 'costUsd';
|
|
12
|
+
readonly used: number | null;
|
|
13
|
+
readonly limit: number;
|
|
14
|
+
readonly source: string;
|
|
15
|
+
readonly reason: 'limit_reached' | 'usage_unknown' | 'reservation_pending';
|
|
16
|
+
}
|
|
17
|
+
/** Current host admission; a card action never grants execution authority. */
|
|
18
|
+
export interface ProjectReplyRecoveryAction {
|
|
19
|
+
readonly canContinue: boolean;
|
|
20
|
+
readonly blockedReason?: string;
|
|
21
|
+
readonly budget?: ProjectWorkBudgetBoundary;
|
|
22
|
+
}
|
|
23
|
+
/** A reply attempt and delegated execution have independent outcomes. Host facts only. */
|
|
24
|
+
export interface ProjectReplyFailureStatus {
|
|
25
|
+
readonly phase: 'current' | 'retrying' | 'superseded' | 'recovered' | 'cancelled' | 'paused';
|
|
26
|
+
readonly turnKind: 'user' | 'wake';
|
|
27
|
+
readonly workId?: string;
|
|
28
|
+
readonly activeSessionIds: readonly string[];
|
|
29
|
+
readonly recoveredByReplyId?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Persisted on agent_turn.meta and the protected outcome; not a delivered reply. */
|
|
32
|
+
export interface ProjectAgentSilentWait {
|
|
33
|
+
readonly source: 'host' | 'tool';
|
|
34
|
+
readonly sessionIds: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
/** Local host reservation; neither model text nor a UI timer owns recovery. */
|
|
37
|
+
export interface ProjectWorkRecovery {
|
|
38
|
+
readonly failureKind: ProjectRecoveryFailureKind;
|
|
39
|
+
readonly retryable: boolean;
|
|
40
|
+
readonly autoAttempts: number;
|
|
41
|
+
readonly failedTurnId: string;
|
|
42
|
+
readonly retryAt?: string;
|
|
43
|
+
readonly reservationId?: string;
|
|
44
|
+
readonly deadlineAt?: string;
|
|
45
|
+
readonly dispatchesReconciled?: boolean;
|
|
46
|
+
readonly blockedCode?: 'RECOVERY_CHECKPOINT_UNAVAILABLE';
|
|
47
|
+
}
|
|
48
|
+
export type ProjectWorkState = 'runnable' | 'waiting_children' | 'waiting_user' | 'retry_wait' | 'paused' | 'budget_limited' | 'blocked_system' | 'delivered' | 'cancelled' | 'coalesced';
|
|
49
|
+
export type ProjectTurnEnd = 'reply_committed' | 'awaiting_children' | 'yielded' | 'awaiting_user' | 'budget_limited' | 'provider_retryable' | 'no_progress' | 'user_stopped' | 'fatal' | 'coalesced';
|
|
50
|
+
/** Host reconciliation closes an interrupted review/query, never supplies its result or verdict. */
|
|
51
|
+
export interface VerificationDispatchReconciliation {
|
|
52
|
+
readonly attemptId: string;
|
|
53
|
+
readonly toolCallId: string;
|
|
54
|
+
readonly capabilityId: 'verify_session' | 'local.delegation.verify_session' | 'get_session' | 'local.delegation.get_session' | 'get_verification_detail' | 'local.delegation.get_verification_detail';
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
readonly planId: string;
|
|
57
|
+
readonly sourceRevision: string;
|
|
58
|
+
readonly outcome: 'verification_interrupted' | 'query_interrupted';
|
|
59
|
+
readonly at: string;
|
|
60
|
+
}
|
|
61
|
+
/** A registered, paired delegation result settles its dispatch, never its task. */
|
|
62
|
+
export interface SettledDelegationDispatch {
|
|
63
|
+
readonly attemptId?: string;
|
|
64
|
+
readonly turnId: string;
|
|
65
|
+
readonly toolCallId: string;
|
|
66
|
+
readonly evidenceRef: string;
|
|
67
|
+
readonly operationId: string;
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
readonly executionEpoch: string;
|
|
70
|
+
readonly goalRevision: number;
|
|
71
|
+
readonly at: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ProjectWorkReceipt {
|
|
74
|
+
readonly schemaVersion: 1;
|
|
75
|
+
readonly workId: string;
|
|
76
|
+
readonly workspaceId: string;
|
|
77
|
+
readonly parentConversationId: string;
|
|
78
|
+
readonly anchorInputIds: readonly string[];
|
|
79
|
+
readonly sessionIds: readonly string[];
|
|
80
|
+
/** Current owned technical blockers; a public progress update does not discharge them. */
|
|
81
|
+
readonly repairSessionIds?: readonly string[];
|
|
82
|
+
/** Unresolved dispatch receipts, not execution grants or permission truth. */
|
|
83
|
+
readonly delegationFollowUp?: {
|
|
84
|
+
readonly blockers: readonly {
|
|
85
|
+
readonly taskKey: string;
|
|
86
|
+
/** Task body without the anchor ids being repaired. A corrected retry clears that obligation. */
|
|
87
|
+
readonly recoveryKey?: string;
|
|
88
|
+
readonly sourceTurnId: string;
|
|
89
|
+
readonly toolCallId: string;
|
|
90
|
+
readonly action: 'parallel' | 'replace';
|
|
91
|
+
readonly error: string;
|
|
92
|
+
readonly retryable: boolean;
|
|
93
|
+
readonly operationId?: string;
|
|
94
|
+
readonly sessionId?: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
readonly progressFacts?: readonly string[];
|
|
98
|
+
readonly state: ProjectWorkState;
|
|
99
|
+
readonly revision: number;
|
|
100
|
+
readonly checkpointRef?: string;
|
|
101
|
+
readonly nativeCheckpointRef?: string;
|
|
102
|
+
/** Only duplicate background observations transfer custody; all history remains. */
|
|
103
|
+
readonly continuationOwnerWorkId?: string;
|
|
104
|
+
readonly reportedWait?: {
|
|
105
|
+
readonly replyIds: readonly string[];
|
|
106
|
+
readonly waitingUser: boolean;
|
|
107
|
+
readonly sessionStates: readonly {
|
|
108
|
+
readonly sessionId: string;
|
|
109
|
+
readonly status: string;
|
|
110
|
+
readonly sourceRevision: string;
|
|
111
|
+
readonly observationRevision?: string;
|
|
112
|
+
}[];
|
|
113
|
+
};
|
|
114
|
+
readonly recovery?: ProjectWorkRecovery;
|
|
115
|
+
readonly end?: ProjectTurnEnd;
|
|
116
|
+
readonly attemptId?: string;
|
|
117
|
+
readonly pendingEventIds?: readonly string[];
|
|
118
|
+
readonly waitFor: readonly {
|
|
119
|
+
readonly kind: 'session' | 'approval' | 'question' | 'retry_timer' | 'human_request' | 'resource' | 'recovery';
|
|
120
|
+
readonly id: string;
|
|
121
|
+
readonly revision?: string;
|
|
122
|
+
}[];
|
|
123
|
+
readonly consumedEventIds: readonly string[];
|
|
124
|
+
readonly pendingResultRefs: readonly string[];
|
|
125
|
+
readonly lastDeliveredFactKey?: string;
|
|
126
|
+
readonly budgetRef?: string;
|
|
127
|
+
readonly budget?: {
|
|
128
|
+
readonly modelRequests: number;
|
|
129
|
+
readonly toolCalls: number;
|
|
130
|
+
readonly tokens: number;
|
|
131
|
+
readonly costUsd: number;
|
|
132
|
+
readonly unknownUsage: boolean;
|
|
133
|
+
readonly unknownCost: boolean;
|
|
134
|
+
readonly limits: ProjectWorkBudgetLimits;
|
|
135
|
+
readonly policyMigration?: {
|
|
136
|
+
readonly version: 2;
|
|
137
|
+
readonly reason: 'legacy_system_default_removed';
|
|
138
|
+
readonly previousLimits: ProjectWorkBudgetLimits;
|
|
139
|
+
readonly at: string;
|
|
140
|
+
};
|
|
141
|
+
readonly lastBoundary?: ProjectWorkBudgetBoundary;
|
|
142
|
+
readonly attempts: Readonly<Record<string, {
|
|
143
|
+
readonly role: string;
|
|
144
|
+
readonly requests?: number;
|
|
145
|
+
readonly modelProviderId?: string;
|
|
146
|
+
readonly checkpointRef?: string;
|
|
147
|
+
readonly pendingTools?: readonly {
|
|
148
|
+
readonly toolCallId: string | null;
|
|
149
|
+
readonly capabilityId: string | null;
|
|
150
|
+
readonly verificationSessionId?: string;
|
|
151
|
+
}[];
|
|
152
|
+
}>>;
|
|
153
|
+
readonly reconciledDispatches?: readonly VerificationDispatchReconciliation[];
|
|
154
|
+
readonly settledDispatches?: readonly SettledDelegationDispatch[];
|
|
155
|
+
readonly uncertainDispatches?: readonly {
|
|
156
|
+
readonly attemptId: string;
|
|
157
|
+
readonly role: string;
|
|
158
|
+
readonly toolCallId: string | null;
|
|
159
|
+
readonly capabilityId: string | null;
|
|
160
|
+
readonly verificationSessionId?: string;
|
|
161
|
+
}[];
|
|
162
|
+
};
|
|
163
|
+
readonly stopScope: 'reply' | 'work';
|
|
164
|
+
readonly updatedAt: string;
|
|
165
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|