@peer-agent/protocol 0.1.0-rc.3 → 0.1.0-rc.30
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 +76 -0
- package/dist/delegation-coordination.js +1 -0
- package/dist/delegation.d.ts +189 -6
- package/dist/delegation.js +39 -39
- package/dist/document-reference.d.ts +81 -0
- package/dist/document-reference.js +1 -0
- package/dist/evidence-inspection.d.ts +51 -0
- package/dist/evidence-inspection.js +1 -0
- package/dist/goal.d.ts +49 -2
- package/dist/index.d.ts +46 -5
- package/dist/index.js +19 -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 +36 -2
- package/dist/model-routing.js +30 -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 +63 -0
- package/dist/project.js +2 -5
- 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.d.ts +91 -0
- package/dist/resource-feedback.js +120 -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 +138 -0
- package/dist/resource-window.js +116 -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 +89 -0
- package/dist/task-overview.js +317 -17
- package/dist/tool-activity-preview.d.ts +4 -0
- package/dist/tool-activity-preview.js +72 -0
- package/dist/work-coordination.d.ts +136 -0
- package/dist/work-coordination.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { decideLifecycle, } from "./task-overview.js";
|
|
2
|
+
/**
|
|
3
|
+
* 兼容入口:把扁平事实交给唯一的生命周期决策器。
|
|
4
|
+
* 旧的直接判定逻辑已删除,`status / needsUser / blockedReason` 全部来自 `decideLifecycle`。
|
|
5
|
+
*/
|
|
6
|
+
export function deriveSessionFacts(input) {
|
|
7
|
+
const snapshot = {
|
|
8
|
+
conversationId: '',
|
|
9
|
+
title: '',
|
|
10
|
+
planId: '',
|
|
11
|
+
status: (input.status ?? 'executing'),
|
|
12
|
+
...(input.runnerStatus ? { runnerStatus: input.runnerStatus } : {}),
|
|
13
|
+
};
|
|
14
|
+
const decision = decideLifecycle(snapshot, {
|
|
15
|
+
...(input.executionOwnership ? { executionOwnership: input.executionOwnership } : {}),
|
|
16
|
+
...(input.phase ? { phase: input.phase } : {}),
|
|
17
|
+
...(input.accepted !== undefined ? { accepted: input.accepted } : {}),
|
|
18
|
+
...(input.superseded !== undefined ? { superseded: input.superseded } : {}),
|
|
19
|
+
...(input.needsUser !== undefined ? { needsUser: input.needsUser } : {}),
|
|
20
|
+
...(input.blockedReason ? { blockedReason: input.blockedReason } : {}),
|
|
21
|
+
...(input.verificationActive !== undefined ? { verificationActive: input.verificationActive } : {}),
|
|
22
|
+
...(input.interrupted !== undefined ? { interrupted: input.interrupted } : {}),
|
|
23
|
+
...(input.interruptionOrigin ? { interruptionOrigin: input.interruptionOrigin } : {}),
|
|
24
|
+
...(input.delegated !== undefined ? { delegated: input.delegated } : {}),
|
|
25
|
+
...(input.cancellationPhase ? { cancellationPhase: input.cancellationPhase } : {}),
|
|
26
|
+
...(input.cancellationDisposition ? { cancellationDisposition: input.cancellationDisposition } : {}),
|
|
27
|
+
...(input.takeoverPhase ? { takeoverPhase: input.takeoverPhase } : {}),
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
status: decision.status,
|
|
31
|
+
verificationActive: decision.verificationActive,
|
|
32
|
+
needsUser: decision.needsUser,
|
|
33
|
+
...(decision.blockedReason ? { blockedReason: decision.blockedReason } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/system-context.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export type AttachmentContextKind = 'image' | 'text' | 'unsupported';
|
|
2
|
+
/** Host failure facts retained with an interrupted reply; never execution authority. */
|
|
3
|
+
export interface ChatStreamFailure {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly causeCode?: string;
|
|
6
|
+
readonly precedingCode?: string;
|
|
7
|
+
}
|
|
2
8
|
export type AttachmentContextTransport = 'provider_image_part' | 'user_text_part' | 'metadata_only' | string;
|
|
3
9
|
/**
|
|
4
10
|
* 全局「兜底多模态模型」配置。
|
package/dist/task-overview.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkSessionStatus } from './delegation.ts';
|
|
1
2
|
/**
|
|
2
3
|
* TaskOverview 行动权投影契约 —— Peer 2.0 阶段 0 协议层。
|
|
3
4
|
*
|
|
@@ -103,6 +104,11 @@ export interface TaskOverviewItem {
|
|
|
103
104
|
readonly source: TaskOverviewSourceKind;
|
|
104
105
|
/** 行动权归属。 */
|
|
105
106
|
readonly actionRight: TaskActionRight;
|
|
107
|
+
/**
|
|
108
|
+
* 本投影是否真的可取消(生命周期决策给出)。
|
|
109
|
+
* 缺省表示来自尚未接入决策的旧入口;renderer 不得自行再写一套生命周期规则。
|
|
110
|
+
*/
|
|
111
|
+
readonly cancelable?: boolean;
|
|
106
112
|
/** needs_you 细分桶;仅 actionRight === 'needs_you' 时有值。 */
|
|
107
113
|
readonly needsYouReason?: TaskNeedsYouReason;
|
|
108
114
|
/** 下一步动作标识。 */
|
|
@@ -240,12 +246,16 @@ export interface ConversationProjectionSnapshot {
|
|
|
240
246
|
readonly providerLabel?: string;
|
|
241
247
|
}
|
|
242
248
|
export interface GoalPlanProjectionSnapshot {
|
|
249
|
+
readonly needsUser?: boolean;
|
|
250
|
+
readonly blockedReason?: string;
|
|
243
251
|
readonly planId: string;
|
|
244
252
|
readonly status: GoalPlanStatus;
|
|
245
253
|
/** Runner 实时态;Plan 未进入自驱时为 undefined。 */
|
|
246
254
|
readonly runnerStatus?: GoalRunnerStatus;
|
|
247
255
|
/** Runner 阻塞是否由系统基础设施持有,而不是用户行动权。 */
|
|
248
256
|
readonly systemBlocked?: boolean;
|
|
257
|
+
/** A delegated worker is coordinating with its parent, not asking the human. */
|
|
258
|
+
readonly agentWaiting?: boolean;
|
|
249
259
|
/**
|
|
250
260
|
* 同一会话此刻是否有前台活流(正在输出 / 调工具 / compact)。
|
|
251
261
|
* 由聚合层从 listActiveStreams 写入;协议层只认这个布尔事实。
|
|
@@ -255,6 +265,7 @@ export interface GoalPlanProjectionSnapshot {
|
|
|
255
265
|
readonly interrupted?: boolean;
|
|
256
266
|
/** 持久化中断事实中的用户可展示原因。 */
|
|
257
267
|
readonly interruptionReason?: string;
|
|
268
|
+
readonly interruptionOrigin?: import('./agent-supervision.ts').InterruptionOrigin;
|
|
258
269
|
readonly title: string;
|
|
259
270
|
readonly workspaceLabel?: string;
|
|
260
271
|
/** 用户可见的交付路由;缺目标分支时写「未确认」。 */
|
|
@@ -300,6 +311,15 @@ export interface GoalPlanProjectionSnapshot {
|
|
|
300
311
|
* 完成即终态,合回/自检未结束仍走 peer_advancing 或 needs_you。
|
|
301
312
|
*/
|
|
302
313
|
readonly accepted?: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* 进程内执行所有权(runtime → protocol 事实)。
|
|
316
|
+
* 只有 `live` 能证明"还在跑";重启后缺 token 只能 `unknown`,既不是活体也不是已结束。
|
|
317
|
+
*/
|
|
318
|
+
readonly executionOwnership?: ExecutionOwnership;
|
|
319
|
+
/** 是否委派会话;委派任务的 accepted 只能来自真实落盘的验收结论。 */
|
|
320
|
+
readonly delegated?: boolean;
|
|
321
|
+
/** 归一化后的活体执行事实,仅由 decideLifecycle 计算,调用方不得直接写。 */
|
|
322
|
+
readonly liveExecution?: boolean;
|
|
303
323
|
/** 有代码副作用时,完成门之后还要质量自检过线才能进终态。 */
|
|
304
324
|
readonly requiresQualityReview?: boolean;
|
|
305
325
|
readonly qualityReviewStatus?: 'reviewing' | 'passed' | 'failed';
|
|
@@ -357,6 +377,74 @@ export interface ShellBackgroundProjectionSnapshot {
|
|
|
357
377
|
readonly toolCallId?: string;
|
|
358
378
|
readonly conversationId?: string;
|
|
359
379
|
}
|
|
380
|
+
interface ProjectionDecision {
|
|
381
|
+
readonly actionRight: TaskActionRight;
|
|
382
|
+
readonly needsYouReason?: TaskNeedsYouReason;
|
|
383
|
+
readonly nextAction: TaskNextAction;
|
|
384
|
+
readonly statusLabel: string;
|
|
385
|
+
readonly actionLabel: string;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* 进程内执行所有权。`live` 只能由本进程持有的执行/核验 token 产生;
|
|
389
|
+
* 重启后持久化标记只能算 `unknown`(不许当活体,也不许当已结束)。
|
|
390
|
+
*/
|
|
391
|
+
export type ExecutionOwnership = 'live' | 'ended' | 'unknown';
|
|
392
|
+
/**
|
|
393
|
+
* 生命周期事实:runtime 只提供事实,不提供结论。
|
|
394
|
+
* `decideLifecycle` 是 `status / statusLabel / actionRight / nextAction / cancelable`
|
|
395
|
+
* 的唯一出口;任何适配器都不得自行改写生命周期结论。
|
|
396
|
+
*/
|
|
397
|
+
export interface LifecycleFacts {
|
|
398
|
+
readonly humanGate?: boolean;
|
|
399
|
+
readonly executionOwnership?: ExecutionOwnership;
|
|
400
|
+
readonly phase?: string;
|
|
401
|
+
readonly delegated?: boolean;
|
|
402
|
+
readonly acceptance?: string;
|
|
403
|
+
readonly accepted?: boolean;
|
|
404
|
+
readonly superseded?: boolean;
|
|
405
|
+
readonly needsUser?: boolean;
|
|
406
|
+
/** 未消费的执行中断是当前行动权事实,优先于 completed/结果就绪。 */
|
|
407
|
+
readonly interrupted?: boolean;
|
|
408
|
+
readonly interruptionOrigin?: import('./agent-supervision.ts').InterruptionOrigin;
|
|
409
|
+
readonly verificationActive?: boolean;
|
|
410
|
+
readonly blockedReason?: string;
|
|
411
|
+
readonly cancellationPhase?: string;
|
|
412
|
+
readonly cancellationDisposition?: 'user_withdrawn';
|
|
413
|
+
readonly takeoverPhase?: string;
|
|
414
|
+
readonly coordinationPhase?: string;
|
|
415
|
+
}
|
|
416
|
+
export interface LifecycleCoreDecision extends ProjectionDecision {
|
|
417
|
+
readonly status: WorkSessionStatus;
|
|
418
|
+
readonly cancelable: boolean;
|
|
419
|
+
readonly needsUser: boolean;
|
|
420
|
+
readonly verificationActive: boolean;
|
|
421
|
+
readonly blockedReason?: string;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* 当前跟进责任(ADR 110)。`bot` = 主 Bot 自己收口的技术跟进;`user` = 真实人工/策略门槛;
|
|
425
|
+
* `none` = 退出当前待办(已签收、已被完成替换承接、用户停止已确认)。
|
|
426
|
+
* `inCurrentList` 是派生事实,不允许消费端各自按 status 再判一次。
|
|
427
|
+
*/
|
|
428
|
+
export type FollowUpOwner = 'bot' | 'user' | 'none';
|
|
429
|
+
export type FollowUpReason = 'settled' | 'superseded' | 'stop_confirmed' | 'user_withdrawn' | 'stop_unconfirmed' | 'human_request' | 'awaiting_human_gate' | 'technical_block' | 'awaiting_acceptance_technical' | 'verification_failed' | 'live_execution' | 'paused' | 'unknown_facts';
|
|
430
|
+
export interface FollowUpProjection {
|
|
431
|
+
readonly owner: FollowUpOwner;
|
|
432
|
+
readonly inCurrentList: boolean;
|
|
433
|
+
readonly reason: FollowUpReason;
|
|
434
|
+
}
|
|
435
|
+
export interface LifecycleDecision extends LifecycleCoreDecision {
|
|
436
|
+
readonly followUp: FollowUpProjection;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* 责任判定:只读同一份生命周期结论 + 同一份权威事实,不引入第二套状态机。
|
|
440
|
+
* 缺事实一律 fail closed(留在当前列表、责任在 bot),不按文案推断承接或停止。
|
|
441
|
+
*/
|
|
442
|
+
export declare function decideFollowUp(decision: Pick<LifecycleCoreDecision, 'status' | 'needsYouReason'>, facts?: LifecycleFacts, ownership?: ExecutionOwnership): FollowUpProjection;
|
|
443
|
+
/**
|
|
444
|
+
* 公开唯一出口:先取既有生命周期结论,再补同一份事实算出的跟进责任(ADR 110)。
|
|
445
|
+
* 适配器只读 `followUp`,不得按 `status` 自行再判一次列表归属与责任人。
|
|
446
|
+
*/
|
|
447
|
+
export declare function decideLifecycle(snapshot: GoalPlanProjectionSnapshot, facts?: LifecycleFacts): LifecycleDecision;
|
|
360
448
|
/** Conversation → 无计划讨论态(工作台动线 §15)。 */
|
|
361
449
|
/**
|
|
362
450
|
* 会话是否对首页「正在讨论」可见(未读)。
|
|
@@ -420,3 +508,4 @@ export declare function areTaskOverviewItemsEqual(current: TaskOverviewItem, nex
|
|
|
420
508
|
* 首页无 conversationId,只能整表重拉;复用后单路进度不会拖垮其余卡。
|
|
421
509
|
*/
|
|
422
510
|
export declare function reuseUnchangedTaskOverviewItems(current: readonly TaskOverviewItem[], next: readonly TaskOverviewItem[]): TaskOverviewItem[];
|
|
511
|
+
export {};
|
package/dist/task-overview.js
CHANGED
|
@@ -1,24 +1,311 @@
|
|
|
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
|
+
if (stopPending)
|
|
29
|
+
return followUpOf('bot', 'stop_unconfirmed');
|
|
30
|
+
if (stopStatus && facts.cancellationDisposition === 'user_withdrawn')
|
|
31
|
+
return followUpOf('none', 'user_withdrawn');
|
|
32
|
+
// 2) 退出当前待办:只有上面三类事实都不成立时,承接 / 失败 / 签收 / 已确认停止才生效。
|
|
33
|
+
// 退出只影响“当前列表归属”,不改写原验收、原核验与未完成事实。
|
|
34
|
+
if (facts.superseded === true || status === 'superseded')
|
|
35
|
+
return followUpOf('none', 'superseded');
|
|
36
|
+
// 3) 核验失败/缺证据:即使存在历史 accepted 事实也不能静默(那次验收是旧结论)。
|
|
37
|
+
if (status === 'failed')
|
|
38
|
+
return followUpOf('bot', 'verification_failed');
|
|
39
|
+
if (facts.accepted === true)
|
|
40
|
+
return followUpOf('none', 'settled');
|
|
41
|
+
if (stopStatus)
|
|
42
|
+
return followUpOf('none', 'stop_confirmed');
|
|
43
|
+
// 4) 父代理等技术阻塞:主 Bot 责任,不显示需要用户确认。
|
|
44
|
+
if (status === 'waiting_agent')
|
|
45
|
+
return followUpOf('bot', 'technical_block');
|
|
46
|
+
// 5) 执行交回不等于验收:普通结果由 Bot 自动收口,只有宿主确认过的人工门才换责任人。
|
|
47
|
+
if (status === 'result_ready')
|
|
48
|
+
return followUpOf('bot', 'awaiting_acceptance_technical');
|
|
49
|
+
// 11. 活动执行/核验:保留在当前列表。
|
|
50
|
+
if (status === 'verifying' || status === 'running' || status === 'starting' || status === 'queued') {
|
|
51
|
+
return followUpOf('bot', 'live_execution');
|
|
52
|
+
}
|
|
53
|
+
// 12. 用户暂停:等待用户恢复,维持既有「不在当前待办」表现。
|
|
54
|
+
if (status === 'paused') {
|
|
55
|
+
if (facts.interrupted === true && facts.interruptionOrigin !== 'user') {
|
|
56
|
+
return followUpOf('bot', facts.interruptionOrigin && facts.interruptionOrigin !== 'unknown' ? 'technical_block' : 'unknown_facts');
|
|
57
|
+
}
|
|
58
|
+
return followUpOf('none', 'paused');
|
|
59
|
+
}
|
|
60
|
+
// 13. 已是验收事实的状态。
|
|
61
|
+
if (status === 'accepted')
|
|
62
|
+
return followUpOf('none', 'settled');
|
|
63
|
+
// 14. 事实缺失或未知停止回执:fail closed。
|
|
64
|
+
return followUpOf('bot', 'unknown_facts');
|
|
65
|
+
}
|
|
66
|
+
/** 仍在占用执行体的 runner 状态(持久化字符串本身不构成活体证据)。 */
|
|
67
|
+
const ACTIVE_EXECUTION_RUNNER_STATUSES = new Set([
|
|
68
|
+
'running',
|
|
69
|
+
'starting',
|
|
70
|
+
'waiting_provider',
|
|
71
|
+
'resuming_after_compaction',
|
|
72
|
+
'exploring',
|
|
73
|
+
]);
|
|
74
|
+
/** 终态与"结果待核实"不可取消:停止中/结果未知也不能靠重复取消恢复。 */
|
|
75
|
+
const NON_CANCELABLE_STATUSES = new Set([
|
|
76
|
+
'accepted',
|
|
77
|
+
'failed',
|
|
78
|
+
'cancelled',
|
|
79
|
+
'superseded',
|
|
80
|
+
'result_ready',
|
|
81
|
+
'stopping',
|
|
82
|
+
'awaiting_outcome',
|
|
83
|
+
]);
|
|
84
|
+
/**
|
|
85
|
+
* 生命周期唯一决策。
|
|
5
86
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
87
|
+
* 关键不变量:
|
|
88
|
+
* - 活 token 不能压过等待用户/父代理、核验、停止中/结果未知、中断等更具体事实;
|
|
89
|
+
* - 持久化 `runnerStatus` 在 ownership=unknown 时不得当作"还在跑";
|
|
90
|
+
* - `accepted` 只来自真实验收事实(本函数不制造 accepted);
|
|
91
|
+
* - 返回的字段必须被所有投影直接消费,不得二次推导。
|
|
9
92
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
93
|
+
* 过渡兼容:不传 `executionOwnership` 的旧入口按 `unknown` 处理——
|
|
94
|
+
* `runner.status` 字符串本身不能证明"还在跑";真实入口(S2/S3)应显式传入 live/ended/unknown。
|
|
95
|
+
*/
|
|
96
|
+
function decideLifecycleCore(snapshot, facts = {}) {
|
|
97
|
+
const declaredOwnership = facts.executionOwnership ?? snapshot.executionOwnership;
|
|
98
|
+
const ownership = declaredOwnership ?? 'unknown';
|
|
99
|
+
const persistedRunner = snapshot.runnerStatus;
|
|
100
|
+
const persistedActive = persistedRunner ? ACTIVE_EXECUTION_RUNNER_STATUSES.has(persistedRunner) : false;
|
|
101
|
+
const liveExecution = ownership === 'live' && (persistedActive || persistedRunner === undefined);
|
|
102
|
+
// 持久化 runner 状态不是活体证据:unknown(重启遗留)和 ended(活流已结束、数据滞后)
|
|
103
|
+
// 都不能凭字符串冒充 live。waiting_user 的待消费问题按 ADR 100 保留。
|
|
104
|
+
const stalePersistedRunner = persistedActive && ownership !== 'live';
|
|
105
|
+
const runnerStatus = stalePersistedRunner ? undefined : persistedRunner;
|
|
106
|
+
const { runnerStatus: _rawRunnerStatus, ...snapshotRest } = snapshot;
|
|
107
|
+
const canonical = {
|
|
108
|
+
...snapshotRest,
|
|
109
|
+
...(runnerStatus ? { runnerStatus } : {}),
|
|
110
|
+
liveExecution,
|
|
111
|
+
};
|
|
112
|
+
const decision = decideGoalPlan(canonical);
|
|
113
|
+
const accepted = facts.accepted ?? snapshot.accepted;
|
|
114
|
+
const needsUserFacts = facts.needsUser === true ||
|
|
115
|
+
snapshot.needsUser === true ||
|
|
116
|
+
snapshot.status === 'awaiting_approval';
|
|
117
|
+
const verificationActive = facts.verificationActive === true;
|
|
118
|
+
const blockedReason = facts.blockedReason ?? snapshot.blockedReason;
|
|
119
|
+
const interrupted = facts.interrupted ?? snapshot.interrupted === true;
|
|
120
|
+
const interruptionOrigin = facts.interruptionOrigin ?? snapshot.interruptionOrigin;
|
|
121
|
+
const delegated = facts.delegated ?? snapshot.delegated === true;
|
|
122
|
+
let status;
|
|
123
|
+
// A host-confirmed stop wins over stale recovery/takeover fields, never a live owner.
|
|
124
|
+
if (snapshot.status === 'cancelled' || facts.cancellationPhase === 'completed' && ownership !== 'live')
|
|
125
|
+
status = 'cancelled';
|
|
126
|
+
else if (snapshot.status === 'failed')
|
|
127
|
+
status = 'failed';
|
|
128
|
+
else if (accepted === true)
|
|
129
|
+
status = 'accepted';
|
|
130
|
+
else if (facts.cancellationPhase === 'awaiting_outcome' ||
|
|
131
|
+
facts.takeoverPhase === 'awaiting_outcome')
|
|
132
|
+
status = 'awaiting_outcome';
|
|
133
|
+
else if (facts.cancellationPhase === 'stopping')
|
|
134
|
+
status = 'stopping';
|
|
135
|
+
else if (facts.takeoverPhase === 'stopping')
|
|
136
|
+
status = 'starting';
|
|
137
|
+
else if (facts.superseded === true && snapshot.status !== 'completed')
|
|
138
|
+
status = 'superseded';
|
|
139
|
+
else if ((facts.phase === 'paused' || runnerStatus === 'paused') && snapshot.status !== 'completed')
|
|
140
|
+
status = 'paused';
|
|
141
|
+
// A failed delegated attempt leaves recovery with the parent, not a human pause.
|
|
142
|
+
else if (interrupted && interruptionOrigin !== 'user' && delegated && runnerStatus === 'failed' && !needsUserFacts && !liveExecution)
|
|
143
|
+
status = 'waiting_agent';
|
|
144
|
+
// 未消费中断优先于 completed/结果就绪(decideGoalPlan rule 1 已按此给文案),
|
|
145
|
+
// 但持久化终态(cancelled/failed)和真实验收结论先于它。
|
|
146
|
+
else if (interrupted)
|
|
147
|
+
status = 'paused';
|
|
148
|
+
else if (needsUserFacts || runnerStatus === 'waiting_user')
|
|
149
|
+
status = 'waiting_user';
|
|
150
|
+
// 预算/范围耗尽是真的需要人决策(rule 5b 已给 needs_you/decide_blocked):
|
|
151
|
+
// 不能被父代理等待标记等技术阻塞吞掉,也不能让 status 落在 running,
|
|
152
|
+
// 否则同一行会出现「由主 Bot 跟进 / 运行中 + 需要你决定」,真实预算决策丢失。
|
|
153
|
+
// 活流(liveExecution / conversationLive)说明预算门尚未真正落下,交给既有规则。
|
|
154
|
+
else if (runnerStatus === 'budget_exhausted' &&
|
|
155
|
+
!liveExecution &&
|
|
156
|
+
snapshot.conversationLive !== true)
|
|
157
|
+
status = 'waiting_user';
|
|
158
|
+
// 技术阻塞是父代理的工作,不是人类问题;活流说明阻塞已过期。
|
|
159
|
+
// 这里刻意保留 completed 的既有优先级:技术残留不越过完成,也不制造人类门,
|
|
160
|
+
// 只有真实人类门(审批/权限/提问/预算)能越过 completed(见 lifecyclePresentation)。
|
|
161
|
+
else if ((blockedReason === 'waiting_parent_agent' || snapshot.agentWaiting === true) &&
|
|
162
|
+
facts.phase !== 'paused' &&
|
|
163
|
+
facts.superseded !== true &&
|
|
164
|
+
runnerStatus !== 'paused' &&
|
|
165
|
+
!liveExecution)
|
|
166
|
+
status = 'waiting_agent';
|
|
167
|
+
else if (verificationActive)
|
|
168
|
+
status = 'verifying';
|
|
169
|
+
else if (runnerStatus === 'blocked' && !liveExecution)
|
|
170
|
+
status = 'waiting_agent';
|
|
171
|
+
else if (snapshot.status === 'completed' && runnerStatus && ACTIVE_EXECUTION_RUNNER_STATUSES.has(runnerStatus))
|
|
172
|
+
status = 'running';
|
|
173
|
+
// 计划已完成、但本进程仍持有执行 token(可能还没有 runner 状态字符串)。
|
|
174
|
+
else if (snapshot.status === 'completed' && liveExecution)
|
|
175
|
+
status = 'running';
|
|
176
|
+
else if (snapshot.status === 'completed')
|
|
177
|
+
status = 'result_ready';
|
|
178
|
+
else if (facts.phase === 'starting')
|
|
179
|
+
status = 'starting';
|
|
180
|
+
else if (['approved', 'accepted', 'paused', 'interrupted'].includes(snapshot.status) ||
|
|
181
|
+
facts.phase === 'queued')
|
|
182
|
+
status = 'queued';
|
|
183
|
+
else
|
|
184
|
+
status = 'running';
|
|
185
|
+
// 五字段必须同源:状态定稿后由同一个出口给出文案/行动权/下一步/可取消。
|
|
186
|
+
const presentation = lifecyclePresentation(status, decision, {
|
|
187
|
+
delegated,
|
|
188
|
+
accepted: accepted === true,
|
|
189
|
+
takeoverStopping: facts.takeoverPhase === 'stopping',
|
|
190
|
+
budgetGate: runnerStatus === 'budget_exhausted' &&
|
|
191
|
+
!liveExecution &&
|
|
192
|
+
snapshot.conversationLive !== true,
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
...presentation,
|
|
196
|
+
status,
|
|
197
|
+
cancelable: presentation.actionRight !== 'terminal' && !NON_CANCELABLE_STATUSES.has(status),
|
|
198
|
+
needsUser: status === 'waiting_user',
|
|
199
|
+
verificationActive: status === 'verifying',
|
|
200
|
+
...(blockedReason ? { blockedReason } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 状态语义 → 同一行文案/行动权(ADR 102 §4)。
|
|
15
205
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* 存储读出字段后组装快照,renderer 只拿到投影产物。这样契约边界清晰,
|
|
19
|
-
* 且测试无需构造巨型 fixture。
|
|
206
|
+
* 只覆盖"旧规则看不到这些事实"的 status;其余沿用既有文案,避免修一个坑挖一个坑。
|
|
207
|
+
* 调用方(任务卡/工作会话/抽屉)必须直接消费 decideLifecycle 的返回值。
|
|
20
208
|
*/
|
|
21
|
-
|
|
209
|
+
function lifecyclePresentation(status, legacy, facts) {
|
|
210
|
+
switch (status) {
|
|
211
|
+
case 'cancelled':
|
|
212
|
+
return {
|
|
213
|
+
actionRight: 'terminal',
|
|
214
|
+
nextAction: 'none',
|
|
215
|
+
statusLabel: '已取消',
|
|
216
|
+
actionLabel: '查看 →',
|
|
217
|
+
};
|
|
218
|
+
case 'waiting_user':
|
|
219
|
+
// completed 只说明计划已落库完成,不等于没有待你消费的决策:旧规则表把
|
|
220
|
+
// completed 放在最前(rule 16),会把预算门/待确认门吞成「已完成 / terminal」。
|
|
221
|
+
// 规则表已经给出 needs_you 的(审批、提问、权限、活跃计划预算)原样沿用,
|
|
222
|
+
// 只补它看不到的事实,文案/下一步复用既有配对,不新发明口径。
|
|
223
|
+
if (legacy.actionRight === 'needs_you')
|
|
224
|
+
return legacy;
|
|
225
|
+
return facts.budgetGate
|
|
226
|
+
? {
|
|
227
|
+
actionRight: 'needs_you',
|
|
228
|
+
needsYouReason: 'decision',
|
|
229
|
+
nextAction: 'decide_blocked',
|
|
230
|
+
statusLabel: '预算已耗尽',
|
|
231
|
+
actionLabel: '决策',
|
|
232
|
+
}
|
|
233
|
+
: {
|
|
234
|
+
actionRight: 'needs_you',
|
|
235
|
+
needsYouReason: 'user_input',
|
|
236
|
+
nextAction: 'answer_question',
|
|
237
|
+
statusLabel: '等待你的选择',
|
|
238
|
+
actionLabel: '回答 →',
|
|
239
|
+
};
|
|
240
|
+
case 'verifying':
|
|
241
|
+
// 核验 ≠ 完成:即使 plan 已落 completed,核验在跑就是核验中。
|
|
242
|
+
return {
|
|
243
|
+
actionRight: 'peer_advancing',
|
|
244
|
+
nextAction: 'none',
|
|
245
|
+
statusLabel: '核验中',
|
|
246
|
+
actionLabel: '查看 →',
|
|
247
|
+
};
|
|
248
|
+
case 'stopping':
|
|
249
|
+
return {
|
|
250
|
+
actionRight: 'peer_advancing',
|
|
251
|
+
nextAction: 'none',
|
|
252
|
+
statusLabel: '正在停止',
|
|
253
|
+
actionLabel: '查看 →',
|
|
254
|
+
};
|
|
255
|
+
case 'awaiting_outcome':
|
|
256
|
+
return {
|
|
257
|
+
actionRight: 'peer_advancing',
|
|
258
|
+
nextAction: 'none',
|
|
259
|
+
statusLabel: '执行结果待核实',
|
|
260
|
+
actionLabel: '查看 →',
|
|
261
|
+
};
|
|
262
|
+
case 'waiting_agent':
|
|
263
|
+
// 技术阻塞是父代理的跟进项,不是人类待办;具体文案(等待答复/系统中断)沿用旧规则。
|
|
264
|
+
return legacy.actionRight === 'needs_you' || (facts.delegated && legacy.actionRight === 'paused')
|
|
265
|
+
? {
|
|
266
|
+
actionRight: 'peer_advancing',
|
|
267
|
+
nextAction: 'none',
|
|
268
|
+
statusLabel: '由主 Bot 跟进',
|
|
269
|
+
actionLabel: '查看 →',
|
|
270
|
+
}
|
|
271
|
+
: legacy;
|
|
272
|
+
case 'starting':
|
|
273
|
+
return facts.takeoverStopping
|
|
274
|
+
? {
|
|
275
|
+
actionRight: 'peer_advancing',
|
|
276
|
+
nextAction: 'none',
|
|
277
|
+
statusLabel: '正在接手',
|
|
278
|
+
actionLabel: '查看 →',
|
|
279
|
+
}
|
|
280
|
+
: legacy;
|
|
281
|
+
case 'result_ready':
|
|
282
|
+
// 委派结果必须等真实验收:完成 ≠ 已验收(ADR 102 O4.2)。
|
|
283
|
+
// 非委派历史数据沿用既有完成契约(rule 6),不强制进入验收卡点。
|
|
284
|
+
return facts.delegated && !facts.accepted
|
|
285
|
+
? {
|
|
286
|
+
actionRight: 'result_ready',
|
|
287
|
+
nextAction: 'review_result',
|
|
288
|
+
statusLabel: '等待验收',
|
|
289
|
+
actionLabel: '验收 →',
|
|
290
|
+
}
|
|
291
|
+
: legacy;
|
|
292
|
+
default:
|
|
293
|
+
return legacy;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 公开唯一出口:先取既有生命周期结论,再补同一份事实算出的跟进责任(ADR 110)。
|
|
298
|
+
* 适配器只读 `followUp`,不得按 `status` 自行再判一次列表归属与责任人。
|
|
299
|
+
*/
|
|
300
|
+
export function decideLifecycle(snapshot, facts = {}) {
|
|
301
|
+
const core = decideLifecycleCore(snapshot, facts);
|
|
302
|
+
// 与核心同一表达式的读取:不新增事实来源,也不引入第二套规则。
|
|
303
|
+
const ownership = facts.executionOwnership ?? snapshot.executionOwnership ?? 'unknown';
|
|
304
|
+
return { ...core, followUp: decideFollowUp(core, { ...facts,
|
|
305
|
+
interrupted: facts.interrupted ?? snapshot.interrupted,
|
|
306
|
+
interruptionOrigin: facts.interruptionOrigin ?? snapshot.interruptionOrigin,
|
|
307
|
+
}, ownership) };
|
|
308
|
+
}
|
|
22
309
|
/** Conversation → 无计划讨论态(工作台动线 §15)。 */
|
|
23
310
|
/**
|
|
24
311
|
* 会话是否对首页「正在讨论」可见(未读)。
|
|
@@ -93,7 +380,7 @@ export function projectConversation(snapshot) {
|
|
|
93
380
|
* 因此实现时将 rule 14 放在 rule 8 之后、仅当 runner 显式 idle 时生效。
|
|
94
381
|
*/
|
|
95
382
|
export function projectGoalPlan(snapshot, options) {
|
|
96
|
-
const decision =
|
|
383
|
+
const decision = decideLifecycle(snapshot);
|
|
97
384
|
const projectedTiming = projectGoalTiming(snapshot.timing, options?.nowMs);
|
|
98
385
|
const durationMs = typeof projectedTiming?.activeMs === 'number' && Number.isFinite(projectedTiming.activeMs)
|
|
99
386
|
? Math.max(0, Math.floor(projectedTiming.activeMs))
|
|
@@ -170,6 +457,7 @@ export function projectGoalPlan(snapshot, options) {
|
|
|
170
457
|
: {}),
|
|
171
458
|
...(modelLabel ? { modelLabel } : {}),
|
|
172
459
|
...(providerLabel ? { providerLabel } : {}),
|
|
460
|
+
cancelable: decision.cancelable,
|
|
173
461
|
actionLabel: decision.actionLabel,
|
|
174
462
|
...(snapshot.conversationId ? { conversationId: snapshot.conversationId } : {}),
|
|
175
463
|
};
|
|
@@ -234,6 +522,15 @@ function decideGoalPlan(snapshot) {
|
|
|
234
522
|
};
|
|
235
523
|
}
|
|
236
524
|
}
|
|
525
|
+
// 计划已完成但本进程仍持有真实执行 token:不得投影为终态/已完成。
|
|
526
|
+
if (snapshot.liveExecution === true) {
|
|
527
|
+
return {
|
|
528
|
+
actionRight: 'peer_advancing',
|
|
529
|
+
nextAction: 'none',
|
|
530
|
+
statusLabel: 'Peer 正在推进',
|
|
531
|
+
actionLabel: '查看 →',
|
|
532
|
+
};
|
|
533
|
+
}
|
|
237
534
|
return {
|
|
238
535
|
actionRight: 'terminal',
|
|
239
536
|
nextAction: 'none',
|
|
@@ -271,6 +568,9 @@ function decideGoalPlan(snapshot) {
|
|
|
271
568
|
}
|
|
272
569
|
const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
|
|
273
570
|
const conversationLive = snapshot.conversationLive === true;
|
|
571
|
+
if (snapshot.agentWaiting && runnerStatus !== 'waiting_user' && ['executing', 'completed'].includes(status)) {
|
|
572
|
+
return { actionRight: 'peer_advancing', nextAction: 'none', statusLabel: '等待主 Bot 答复', actionLabel: '' };
|
|
573
|
+
}
|
|
274
574
|
const recoverableSystemBlocked = runnerStatus === 'blocked'
|
|
275
575
|
&& snapshot.systemBlocked === true;
|
|
276
576
|
// 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
|
+
}
|