@peer-agent/protocol 0.1.0-rc.5 → 0.1.0-rc.50
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 +67 -0
- package/dist/bot-conversation-read.js +9 -0
- package/dist/bot-direct-step.d.ts +11 -0
- package/dist/bot-direct-step.js +1 -0
- package/dist/bot-git.d.ts +55 -0
- package/dist/bot-git.js +1 -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/compaction-history-selection.d.ts +15 -0
- package/dist/compaction-history-selection.js +30 -0
- package/dist/compaction.d.ts +5 -0
- package/dist/compaction.js +6 -0
- package/dist/context-accounting.d.ts +3 -0
- package/dist/conversation-execution.d.ts +68 -0
- package/dist/conversation-execution.js +222 -0
- package/dist/delegation-coordination.d.ts +81 -0
- package/dist/delegation-coordination.js +1 -0
- package/dist/delegation.d.ts +260 -7
- package/dist/delegation.js +97 -39
- package/dist/document-reference.d.ts +111 -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/gemini-standard-pricing.json +105 -0
- package/dist/goal.d.ts +50 -2
- package/dist/hook-observation.d.ts +2 -0
- package/dist/hook-observation.js +19 -0
- package/dist/index.d.ts +109 -25
- package/dist/index.js +38 -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/local-read.d.ts +9 -0
- package/dist/local-read.js +1 -0
- package/dist/memory.d.ts +71 -11
- package/dist/memory.js +12 -0
- package/dist/model-reasoning.d.ts +16 -0
- package/dist/model-reasoning.js +25 -0
- package/dist/model-routing.d.ts +39 -3
- package/dist/model-routing.js +31 -5
- package/dist/native-process.d.ts +21 -0
- package/dist/native-process.js +51 -0
- package/dist/parent-coordination.d.ts +104 -0
- package/dist/parent-coordination.js +2 -0
- package/dist/project-agent-failure.d.ts +30 -0
- package/dist/project-agent-failure.js +44 -0
- package/dist/project-input-recovery.d.ts +83 -0
- package/dist/project-input-recovery.js +25 -0
- package/dist/project-matter.d.ts +225 -0
- package/dist/project-matter.js +1 -0
- package/dist/project-recovery.d.ts +43 -0
- package/dist/project-recovery.js +1 -0
- package/dist/project.d.ts +136 -0
- package/dist/project.js +130 -5
- package/dist/quiet-reply.d.ts +9 -0
- package/dist/quiet-reply.js +43 -0
- 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 +26 -0
- package/dist/resource-feedback-transport.js +94 -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 +57 -0
- package/dist/session-control.d.ts +211 -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/skill-marketplace.d.ts +39 -4
- package/dist/spend-budget.d.ts +69 -0
- package/dist/spend-budget.js +1 -0
- package/dist/system-context.d.ts +7 -0
- package/dist/task-overview.d.ts +91 -0
- package/dist/task-overview.js +325 -17
- package/dist/tool-activity-preview.d.ts +4 -0
- package/dist/tool-activity-preview.js +72 -0
- package/dist/updater.d.ts +13 -3
- package/dist/usage-accounting.d.ts +42 -1
- package/dist/user-anchor.d.ts +17 -0
- package/dist/user-anchor.js +1 -0
- package/dist/work-coordination.d.ts +188 -0
- package/dist/work-coordination.js +1 -0
- package/dist/work-hook.d.ts +3 -0
- package/dist/work-hook.js +76 -0
- package/dist/working-plan.d.ts +18 -0
- package/dist/working-plan.js +1 -0
- package/package.json +1 -1
package/dist/task-overview.js
CHANGED
|
@@ -1,24 +1,319 @@
|
|
|
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 === 'result_ready' && facts.verificationFailed === true)
|
|
43
|
+
return followUpOf('bot', 'verification_failed');
|
|
44
|
+
// 终态执行失败(未产生可核验结果):归入历史记录,不再伪装成待重验任务钉死在活跃列表。
|
|
45
|
+
if (status === 'failed')
|
|
46
|
+
return followUpOf('none', 'execution_failed');
|
|
47
|
+
if (facts.accepted === true)
|
|
48
|
+
return followUpOf('none', 'settled');
|
|
49
|
+
if (stopStatus)
|
|
50
|
+
return followUpOf('none', 'stop_confirmed');
|
|
51
|
+
// 4) 父代理等技术阻塞:主 Bot 责任,不显示需要用户确认。
|
|
52
|
+
if (status === 'waiting_agent')
|
|
53
|
+
return followUpOf('bot', 'technical_block');
|
|
54
|
+
// 5) 执行交回不等于验收:普通结果由 Bot 自动收口,只有宿主确认过的人工门才换责任人。
|
|
55
|
+
if (status === 'result_ready')
|
|
56
|
+
return followUpOf('bot', 'awaiting_acceptance_technical');
|
|
57
|
+
// 11. 活动执行/核验:保留在当前列表。
|
|
58
|
+
if (status === 'verifying' || status === 'running' || status === 'starting' || status === 'queued') {
|
|
59
|
+
return followUpOf('bot', 'live_execution');
|
|
60
|
+
}
|
|
61
|
+
// 12. 用户暂停:等待用户恢复,维持既有「不在当前待办」表现。
|
|
62
|
+
if (status === 'paused') {
|
|
63
|
+
if (facts.interrupted === true && facts.interruptionOrigin !== 'user') {
|
|
64
|
+
return followUpOf('bot', facts.interruptionOrigin && facts.interruptionOrigin !== 'unknown' ? 'technical_block' : 'unknown_facts');
|
|
65
|
+
}
|
|
66
|
+
return followUpOf('none', 'paused');
|
|
67
|
+
}
|
|
68
|
+
// 13. 已是验收事实的状态。
|
|
69
|
+
if (status === 'accepted')
|
|
70
|
+
return followUpOf('none', 'settled');
|
|
71
|
+
// 14. 事实缺失或未知停止回执:fail closed。
|
|
72
|
+
return followUpOf('bot', 'unknown_facts');
|
|
73
|
+
}
|
|
74
|
+
/** 仍在占用执行体的 runner 状态(持久化字符串本身不构成活体证据)。 */
|
|
75
|
+
const ACTIVE_EXECUTION_RUNNER_STATUSES = new Set([
|
|
76
|
+
'running',
|
|
77
|
+
'starting',
|
|
78
|
+
'waiting_provider',
|
|
79
|
+
'resuming_after_compaction',
|
|
80
|
+
'exploring',
|
|
81
|
+
]);
|
|
82
|
+
/** 终态与"结果待核实"不可取消:停止中/结果未知也不能靠重复取消恢复。 */
|
|
83
|
+
const NON_CANCELABLE_STATUSES = new Set([
|
|
84
|
+
'accepted',
|
|
85
|
+
'failed',
|
|
86
|
+
'cancelled',
|
|
87
|
+
'superseded',
|
|
88
|
+
'result_ready',
|
|
89
|
+
'stopping',
|
|
90
|
+
'awaiting_outcome',
|
|
91
|
+
]);
|
|
92
|
+
/**
|
|
93
|
+
* 生命周期唯一决策。
|
|
5
94
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
95
|
+
* 关键不变量:
|
|
96
|
+
* - 活 token 不能压过等待用户/父代理、核验、停止中/结果未知、中断等更具体事实;
|
|
97
|
+
* - 持久化 `runnerStatus` 在 ownership=unknown 时不得当作"还在跑";
|
|
98
|
+
* - `accepted` 只来自真实验收事实(本函数不制造 accepted);
|
|
99
|
+
* - 返回的字段必须被所有投影直接消费,不得二次推导。
|
|
9
100
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
101
|
+
* 过渡兼容:不传 `executionOwnership` 的旧入口按 `unknown` 处理——
|
|
102
|
+
* `runner.status` 字符串本身不能证明"还在跑";真实入口(S2/S3)应显式传入 live/ended/unknown。
|
|
103
|
+
*/
|
|
104
|
+
function decideLifecycleCore(snapshot, facts = {}) {
|
|
105
|
+
const declaredOwnership = facts.executionOwnership ?? snapshot.executionOwnership;
|
|
106
|
+
const ownership = declaredOwnership ?? 'unknown';
|
|
107
|
+
const persistedRunner = snapshot.runnerStatus;
|
|
108
|
+
const persistedActive = persistedRunner ? ACTIVE_EXECUTION_RUNNER_STATUSES.has(persistedRunner) : false;
|
|
109
|
+
const liveExecution = ownership === 'live' && (persistedActive || persistedRunner === undefined);
|
|
110
|
+
// 持久化 runner 状态不是活体证据:unknown(重启遗留)和 ended(活流已结束、数据滞后)
|
|
111
|
+
// 都不能凭字符串冒充 live。waiting_user 的待消费问题按 ADR 100 保留。
|
|
112
|
+
const stalePersistedRunner = persistedActive && ownership !== 'live';
|
|
113
|
+
const runnerStatus = stalePersistedRunner ? undefined : persistedRunner;
|
|
114
|
+
const { runnerStatus: _rawRunnerStatus, ...snapshotRest } = snapshot;
|
|
115
|
+
const canonical = {
|
|
116
|
+
...snapshotRest,
|
|
117
|
+
...(runnerStatus ? { runnerStatus } : {}),
|
|
118
|
+
liveExecution,
|
|
119
|
+
};
|
|
120
|
+
const decision = decideGoalPlan(canonical);
|
|
121
|
+
const accepted = facts.accepted ?? snapshot.accepted;
|
|
122
|
+
const needsUserFacts = facts.needsUser === true ||
|
|
123
|
+
snapshot.needsUser === true ||
|
|
124
|
+
snapshot.status === 'awaiting_approval';
|
|
125
|
+
const verificationActive = facts.verificationActive === true;
|
|
126
|
+
const blockedReason = facts.blockedReason ?? snapshot.blockedReason;
|
|
127
|
+
const interrupted = facts.interrupted ?? snapshot.interrupted === true;
|
|
128
|
+
const interruptionOrigin = facts.interruptionOrigin ?? snapshot.interruptionOrigin;
|
|
129
|
+
const delegated = facts.delegated ?? snapshot.delegated === true;
|
|
130
|
+
let status;
|
|
131
|
+
// A host-confirmed stop wins over stale recovery/takeover fields, never a live owner.
|
|
132
|
+
if (snapshot.status === 'cancelled' || facts.cancellationPhase === 'completed' && ownership !== 'live')
|
|
133
|
+
status = 'cancelled';
|
|
134
|
+
else if (snapshot.status === 'failed')
|
|
135
|
+
status = 'failed';
|
|
136
|
+
else if (accepted === true)
|
|
137
|
+
status = 'accepted';
|
|
138
|
+
else if (facts.cancellationPhase === 'awaiting_outcome' ||
|
|
139
|
+
facts.takeoverPhase === 'awaiting_outcome')
|
|
140
|
+
status = 'awaiting_outcome';
|
|
141
|
+
else if (facts.cancellationPhase === 'stopping')
|
|
142
|
+
status = 'stopping';
|
|
143
|
+
else if (facts.takeoverPhase === 'stopping')
|
|
144
|
+
status = 'starting';
|
|
145
|
+
else if (facts.superseded === true && snapshot.status !== 'completed')
|
|
146
|
+
status = 'superseded';
|
|
147
|
+
else if ((facts.phase === 'paused' || runnerStatus === 'paused') && snapshot.status !== 'completed')
|
|
148
|
+
status = 'paused';
|
|
149
|
+
// A failed delegated attempt leaves recovery with the parent, not a human pause.
|
|
150
|
+
else if (interrupted && interruptionOrigin !== 'user' && delegated && runnerStatus === 'failed' && !needsUserFacts && !liveExecution)
|
|
151
|
+
status = 'waiting_agent';
|
|
152
|
+
// 未消费中断优先于 completed/结果就绪(decideGoalPlan rule 1 已按此给文案),
|
|
153
|
+
// 但持久化终态(cancelled/failed)和真实验收结论先于它。
|
|
154
|
+
else if (interrupted)
|
|
155
|
+
status = 'paused';
|
|
156
|
+
else if (needsUserFacts || runnerStatus === 'waiting_user')
|
|
157
|
+
status = 'waiting_user';
|
|
158
|
+
// 预算/范围耗尽是真的需要人决策(rule 5b 已给 needs_you/decide_blocked):
|
|
159
|
+
// 不能被父代理等待标记等技术阻塞吞掉,也不能让 status 落在 running,
|
|
160
|
+
// 否则同一行会出现「由主 Bot 跟进 / 运行中 + 需要你决定」,真实预算决策丢失。
|
|
161
|
+
// 活流(liveExecution / conversationLive)说明预算门尚未真正落下,交给既有规则。
|
|
162
|
+
else if (runnerStatus === 'budget_exhausted' &&
|
|
163
|
+
!liveExecution &&
|
|
164
|
+
snapshot.conversationLive !== true)
|
|
165
|
+
status = 'waiting_user';
|
|
166
|
+
// 技术阻塞是父代理的工作,不是人类问题;活流说明阻塞已过期。
|
|
167
|
+
// 这里刻意保留 completed 的既有优先级:技术残留不越过完成,也不制造人类门,
|
|
168
|
+
// 只有真实人类门(审批/权限/提问/预算)能越过 completed(见 lifecyclePresentation)。
|
|
169
|
+
else if ((blockedReason === 'waiting_parent_agent' || snapshot.agentWaiting === true) &&
|
|
170
|
+
facts.phase !== 'paused' &&
|
|
171
|
+
facts.superseded !== true &&
|
|
172
|
+
runnerStatus !== 'paused' &&
|
|
173
|
+
!liveExecution)
|
|
174
|
+
status = 'waiting_agent';
|
|
175
|
+
else if (verificationActive)
|
|
176
|
+
status = 'verifying';
|
|
177
|
+
else if (runnerStatus === 'blocked' && !liveExecution)
|
|
178
|
+
status = 'waiting_agent';
|
|
179
|
+
else if (snapshot.status === 'completed' && runnerStatus && ACTIVE_EXECUTION_RUNNER_STATUSES.has(runnerStatus))
|
|
180
|
+
status = 'running';
|
|
181
|
+
// 计划已完成、但本进程仍持有执行 token(可能还没有 runner 状态字符串)。
|
|
182
|
+
else if (snapshot.status === 'completed' && liveExecution)
|
|
183
|
+
status = 'running';
|
|
184
|
+
else if (snapshot.status === 'completed')
|
|
185
|
+
status = 'result_ready';
|
|
186
|
+
else if (facts.phase === 'starting')
|
|
187
|
+
status = 'starting';
|
|
188
|
+
else if (['approved', 'accepted', 'paused', 'interrupted'].includes(snapshot.status) ||
|
|
189
|
+
facts.phase === 'queued')
|
|
190
|
+
status = 'queued';
|
|
191
|
+
else
|
|
192
|
+
status = 'running';
|
|
193
|
+
// 五字段必须同源:状态定稿后由同一个出口给出文案/行动权/下一步/可取消。
|
|
194
|
+
const presentation = lifecyclePresentation(status, decision, {
|
|
195
|
+
delegated,
|
|
196
|
+
accepted: accepted === true,
|
|
197
|
+
takeoverStopping: facts.takeoverPhase === 'stopping',
|
|
198
|
+
budgetGate: runnerStatus === 'budget_exhausted' &&
|
|
199
|
+
!liveExecution &&
|
|
200
|
+
snapshot.conversationLive !== true,
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
...presentation,
|
|
204
|
+
status,
|
|
205
|
+
cancelable: presentation.actionRight !== 'terminal' && !NON_CANCELABLE_STATUSES.has(status),
|
|
206
|
+
needsUser: status === 'waiting_user',
|
|
207
|
+
verificationActive: status === 'verifying',
|
|
208
|
+
...(blockedReason ? { blockedReason } : {}),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 状态语义 → 同一行文案/行动权(ADR 102 §4)。
|
|
15
213
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* 存储读出字段后组装快照,renderer 只拿到投影产物。这样契约边界清晰,
|
|
19
|
-
* 且测试无需构造巨型 fixture。
|
|
214
|
+
* 只覆盖"旧规则看不到这些事实"的 status;其余沿用既有文案,避免修一个坑挖一个坑。
|
|
215
|
+
* 调用方(任务卡/工作会话/抽屉)必须直接消费 decideLifecycle 的返回值。
|
|
20
216
|
*/
|
|
21
|
-
|
|
217
|
+
function lifecyclePresentation(status, legacy, facts) {
|
|
218
|
+
switch (status) {
|
|
219
|
+
case 'cancelled':
|
|
220
|
+
return {
|
|
221
|
+
actionRight: 'terminal',
|
|
222
|
+
nextAction: 'none',
|
|
223
|
+
statusLabel: '已取消',
|
|
224
|
+
actionLabel: '查看 →',
|
|
225
|
+
};
|
|
226
|
+
case 'waiting_user':
|
|
227
|
+
// completed 只说明计划已落库完成,不等于没有待你消费的决策:旧规则表把
|
|
228
|
+
// completed 放在最前(rule 16),会把预算门/待确认门吞成「已完成 / terminal」。
|
|
229
|
+
// 规则表已经给出 needs_you 的(审批、提问、权限、活跃计划预算)原样沿用,
|
|
230
|
+
// 只补它看不到的事实,文案/下一步复用既有配对,不新发明口径。
|
|
231
|
+
if (legacy.actionRight === 'needs_you')
|
|
232
|
+
return legacy;
|
|
233
|
+
return facts.budgetGate
|
|
234
|
+
? {
|
|
235
|
+
actionRight: 'needs_you',
|
|
236
|
+
needsYouReason: 'decision',
|
|
237
|
+
nextAction: 'decide_blocked',
|
|
238
|
+
statusLabel: '预算已耗尽',
|
|
239
|
+
actionLabel: '决策',
|
|
240
|
+
}
|
|
241
|
+
: {
|
|
242
|
+
actionRight: 'needs_you',
|
|
243
|
+
needsYouReason: 'user_input',
|
|
244
|
+
nextAction: 'answer_question',
|
|
245
|
+
statusLabel: '等待你的选择',
|
|
246
|
+
actionLabel: '回答 →',
|
|
247
|
+
};
|
|
248
|
+
case 'verifying':
|
|
249
|
+
// 核验 ≠ 完成:即使 plan 已落 completed,核验在跑就是核验中。
|
|
250
|
+
return {
|
|
251
|
+
actionRight: 'peer_advancing',
|
|
252
|
+
nextAction: 'none',
|
|
253
|
+
statusLabel: '核验中',
|
|
254
|
+
actionLabel: '查看 →',
|
|
255
|
+
};
|
|
256
|
+
case 'stopping':
|
|
257
|
+
return {
|
|
258
|
+
actionRight: 'peer_advancing',
|
|
259
|
+
nextAction: 'none',
|
|
260
|
+
statusLabel: '正在停止',
|
|
261
|
+
actionLabel: '查看 →',
|
|
262
|
+
};
|
|
263
|
+
case 'awaiting_outcome':
|
|
264
|
+
return {
|
|
265
|
+
actionRight: 'peer_advancing',
|
|
266
|
+
nextAction: 'none',
|
|
267
|
+
statusLabel: '执行结果待核实',
|
|
268
|
+
actionLabel: '查看 →',
|
|
269
|
+
};
|
|
270
|
+
case 'waiting_agent':
|
|
271
|
+
// 技术阻塞是父代理的跟进项,不是人类待办;具体文案(等待答复/系统中断)沿用旧规则。
|
|
272
|
+
return legacy.actionRight === 'needs_you' || (facts.delegated && legacy.actionRight === 'paused')
|
|
273
|
+
? {
|
|
274
|
+
actionRight: 'peer_advancing',
|
|
275
|
+
nextAction: 'none',
|
|
276
|
+
statusLabel: '由主 Bot 跟进',
|
|
277
|
+
actionLabel: '查看 →',
|
|
278
|
+
}
|
|
279
|
+
: legacy;
|
|
280
|
+
case 'starting':
|
|
281
|
+
return facts.takeoverStopping
|
|
282
|
+
? {
|
|
283
|
+
actionRight: 'peer_advancing',
|
|
284
|
+
nextAction: 'none',
|
|
285
|
+
statusLabel: '正在接手',
|
|
286
|
+
actionLabel: '查看 →',
|
|
287
|
+
}
|
|
288
|
+
: legacy;
|
|
289
|
+
case 'result_ready':
|
|
290
|
+
// 委派结果必须等真实验收:完成 ≠ 已验收(ADR 102 O4.2)。
|
|
291
|
+
// 非委派历史数据沿用既有完成契约(rule 6),不强制进入验收卡点。
|
|
292
|
+
return facts.delegated && !facts.accepted
|
|
293
|
+
? {
|
|
294
|
+
actionRight: 'result_ready',
|
|
295
|
+
nextAction: 'review_result',
|
|
296
|
+
statusLabel: '等待验收',
|
|
297
|
+
actionLabel: '验收 →',
|
|
298
|
+
}
|
|
299
|
+
: legacy;
|
|
300
|
+
default:
|
|
301
|
+
return legacy;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 公开唯一出口:先取既有生命周期结论,再补同一份事实算出的跟进责任(ADR 110)。
|
|
306
|
+
* 适配器只读 `followUp`,不得按 `status` 自行再判一次列表归属与责任人。
|
|
307
|
+
*/
|
|
308
|
+
export function decideLifecycle(snapshot, facts = {}) {
|
|
309
|
+
const core = decideLifecycleCore(snapshot, facts);
|
|
310
|
+
// 与核心同一表达式的读取:不新增事实来源,也不引入第二套规则。
|
|
311
|
+
const ownership = facts.executionOwnership ?? snapshot.executionOwnership ?? 'unknown';
|
|
312
|
+
return { ...core, followUp: decideFollowUp(core, { ...facts,
|
|
313
|
+
interrupted: facts.interrupted ?? snapshot.interrupted,
|
|
314
|
+
interruptionOrigin: facts.interruptionOrigin ?? snapshot.interruptionOrigin,
|
|
315
|
+
}, ownership) };
|
|
316
|
+
}
|
|
22
317
|
/** Conversation → 无计划讨论态(工作台动线 §15)。 */
|
|
23
318
|
/**
|
|
24
319
|
* 会话是否对首页「正在讨论」可见(未读)。
|
|
@@ -93,7 +388,7 @@ export function projectConversation(snapshot) {
|
|
|
93
388
|
* 因此实现时将 rule 14 放在 rule 8 之后、仅当 runner 显式 idle 时生效。
|
|
94
389
|
*/
|
|
95
390
|
export function projectGoalPlan(snapshot, options) {
|
|
96
|
-
const decision =
|
|
391
|
+
const decision = decideLifecycle(snapshot);
|
|
97
392
|
const projectedTiming = projectGoalTiming(snapshot.timing, options?.nowMs);
|
|
98
393
|
const durationMs = typeof projectedTiming?.activeMs === 'number' && Number.isFinite(projectedTiming.activeMs)
|
|
99
394
|
? Math.max(0, Math.floor(projectedTiming.activeMs))
|
|
@@ -170,6 +465,7 @@ export function projectGoalPlan(snapshot, options) {
|
|
|
170
465
|
: {}),
|
|
171
466
|
...(modelLabel ? { modelLabel } : {}),
|
|
172
467
|
...(providerLabel ? { providerLabel } : {}),
|
|
468
|
+
cancelable: decision.cancelable,
|
|
173
469
|
actionLabel: decision.actionLabel,
|
|
174
470
|
...(snapshot.conversationId ? { conversationId: snapshot.conversationId } : {}),
|
|
175
471
|
};
|
|
@@ -234,6 +530,15 @@ function decideGoalPlan(snapshot) {
|
|
|
234
530
|
};
|
|
235
531
|
}
|
|
236
532
|
}
|
|
533
|
+
// 计划已完成但本进程仍持有真实执行 token:不得投影为终态/已完成。
|
|
534
|
+
if (snapshot.liveExecution === true) {
|
|
535
|
+
return {
|
|
536
|
+
actionRight: 'peer_advancing',
|
|
537
|
+
nextAction: 'none',
|
|
538
|
+
statusLabel: 'Peer 正在推进',
|
|
539
|
+
actionLabel: '查看 →',
|
|
540
|
+
};
|
|
541
|
+
}
|
|
237
542
|
return {
|
|
238
543
|
actionRight: 'terminal',
|
|
239
544
|
nextAction: 'none',
|
|
@@ -271,6 +576,9 @@ function decideGoalPlan(snapshot) {
|
|
|
271
576
|
}
|
|
272
577
|
const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
|
|
273
578
|
const conversationLive = snapshot.conversationLive === true;
|
|
579
|
+
if (snapshot.agentWaiting && runnerStatus !== 'waiting_user' && ['executing', 'completed'].includes(status)) {
|
|
580
|
+
return { actionRight: 'peer_advancing', nextAction: 'none', statusLabel: '等待主 Bot 答复', actionLabel: '' };
|
|
581
|
+
}
|
|
274
582
|
const recoverableSystemBlocked = runnerStatus === 'blocked'
|
|
275
583
|
&& snapshot.systemBlocked === true;
|
|
276
584
|
// 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
|
+
}
|
package/dist/updater.d.ts
CHANGED
|
@@ -17,12 +17,22 @@ export type UpdateChannelPreference = 'auto' | UpdateChannel;
|
|
|
17
17
|
export type UpdaterPhase = 'idle' | 'checking' | 'available' | 'not-available' | 'downloading'
|
|
18
18
|
/** 更新已下载,等待用户点击「安装」后退出替换并重启(mac / Windows / Linux AppImage 同一语义)。 */
|
|
19
19
|
| 'downloaded' | 'error';
|
|
20
|
+
export type UpdaterDownloadStage = 'connecting' | 'downloading' | 'verifying';
|
|
21
|
+
/** Download facts projected by the desktop host. The package estimate is independent of the transfer total. */
|
|
22
|
+
export interface UpdaterDownloadTelemetry {
|
|
23
|
+
readonly transferredBytes?: number;
|
|
24
|
+
readonly totalBytes?: number;
|
|
25
|
+
readonly bytesPerSecond?: number;
|
|
26
|
+
readonly downloadStage?: UpdaterDownloadStage;
|
|
27
|
+
readonly packageSizeBytes?: number;
|
|
28
|
+
readonly isFallbackFull?: boolean;
|
|
29
|
+
}
|
|
20
30
|
/** 主进程向渲染层广播的更新事件(与 auto-updater 的 onEvent 一一对应)。 */
|
|
21
|
-
export interface UpdaterEvent {
|
|
31
|
+
export interface UpdaterEvent extends UpdaterDownloadTelemetry {
|
|
22
32
|
readonly type: 'checking-for-update' | 'update-available' | 'update-not-available' | 'download-progress' | 'update-downloaded' | 'error';
|
|
23
33
|
/** 目标/可用版本号(available / downloaded / not-available 时携带)。 */
|
|
24
34
|
readonly version?: string;
|
|
25
|
-
/** 下载进度百分比(download-progress 时携带,0–100
|
|
35
|
+
/** 下载进度百分比(download-progress 时携带,0–100,最多一位小数)。 */
|
|
26
36
|
readonly percent?: number;
|
|
27
37
|
/** 错误信息(error 时携带)。 */
|
|
28
38
|
readonly message?: string;
|
|
@@ -32,7 +42,7 @@ export interface UpdaterEvent {
|
|
|
32
42
|
readonly releaseNotes?: string;
|
|
33
43
|
}
|
|
34
44
|
/** 渲染层订阅 / 主动查询时获得的更新状态快照。 */
|
|
35
|
-
export interface UpdaterStatus {
|
|
45
|
+
export interface UpdaterStatus extends UpdaterDownloadTelemetry {
|
|
36
46
|
/** 当前应用版本号(来自 app.getVersion)。 */
|
|
37
47
|
readonly currentVersion: string;
|
|
38
48
|
/** 实际生效的更新通道(preference=auto 时为版本号推断结果)。 */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Usage scopes are deliberately explicit because the same token fields have
|
|
3
3
|
* different meanings at each runtime boundary.
|
|
4
4
|
*/
|
|
5
|
+
import type { SessionExecutionIdentity } from './session-control.ts';
|
|
5
6
|
export type UsageScope = 'provider_request' | 'runtime_turn' | 'conversation_lifetime';
|
|
6
7
|
export interface UsageAmounts {
|
|
7
8
|
readonly inputTokens: number;
|
|
@@ -14,13 +15,53 @@ export interface UsageAmounts {
|
|
|
14
15
|
export interface ProviderRequestUsage extends UsageAmounts {
|
|
15
16
|
readonly usageScope: 'provider_request';
|
|
16
17
|
readonly requestIndex: number;
|
|
17
|
-
readonly requestPurpose: 'agent' | 'compaction_summary';
|
|
18
|
+
readonly requestPurpose: 'agent' | 'compaction_summary' | 'input_prediction';
|
|
18
19
|
readonly requestFingerprint?: string;
|
|
19
20
|
}
|
|
21
|
+
export interface RequestSpend {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly at: string;
|
|
24
|
+
readonly groupId: string;
|
|
25
|
+
readonly model: string;
|
|
26
|
+
readonly modelVersion?: string;
|
|
27
|
+
readonly rawPromptTokens?: number;
|
|
28
|
+
readonly usage: UsageAmounts | null;
|
|
29
|
+
readonly estimatedCostUsd: string | null;
|
|
30
|
+
readonly pricingSource?: 'manual' | 'provider' | 'gemini-official-reference' | 'models.dev-reference';
|
|
31
|
+
}
|
|
20
32
|
/** Billable sum of every provider request executed by one user/runtime turn. */
|
|
21
33
|
export interface RuntimeTurnUsage extends UsageAmounts {
|
|
22
34
|
readonly usageScope: 'runtime_turn';
|
|
23
35
|
readonly providerRequestCount: number;
|
|
36
|
+
readonly requestBreakdown?: readonly RequestSpend[];
|
|
37
|
+
}
|
|
38
|
+
/** ADR131 canonical billing snapshot. It never seeds context or proves execution. */
|
|
39
|
+
export interface NativeRuntimeUsageSnapshot {
|
|
40
|
+
readonly schemaVersion: 1;
|
|
41
|
+
readonly knownAmountsOnly: true;
|
|
42
|
+
readonly workId: string;
|
|
43
|
+
readonly execution: SessionExecutionIdentity;
|
|
44
|
+
readonly conversationId: string;
|
|
45
|
+
readonly usage: RuntimeTurnUsage;
|
|
46
|
+
readonly attribution: {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly streamId: string;
|
|
49
|
+
readonly at: string;
|
|
50
|
+
readonly modelProviderId: string;
|
|
51
|
+
readonly model: string;
|
|
52
|
+
readonly groupId?: string | null;
|
|
53
|
+
readonly role: 'work_session';
|
|
54
|
+
readonly workspaceId: string;
|
|
55
|
+
readonly providerName?: string | null;
|
|
56
|
+
readonly estimatedCostUsd?: number | null;
|
|
57
|
+
readonly pricingSource?: string | null;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** One bounded native recovery batch; remaining records retain their identity. */
|
|
61
|
+
export interface NativeUsageRecoveryProgress {
|
|
62
|
+
readonly schemaVersion: 1;
|
|
63
|
+
readonly settled: number;
|
|
64
|
+
readonly remaining: number;
|
|
24
65
|
}
|
|
25
66
|
/** Durable billable sum for one provider/model key inside a conversation ledger. */
|
|
26
67
|
export interface ConversationLifetimeModelUsage {
|
|
@@ -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 {};
|