@peer-agent/protocol 0.0.4-beta.2 → 0.0.4-beta.3

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/goal.d.ts CHANGED
@@ -16,6 +16,57 @@ import type { ExecutionStatus, HumanConfirmationDecision } from './execution.ts'
16
16
  export type GoalPlanStatus = 'drafting' | 'awaiting_approval' | 'approved' | 'accepted' | 'executing' | 'paused' | 'completed' | 'cancelled' | 'failed';
17
17
  /** Goal artifact 的工作流语义:Plan 审批门 vs Goal 自驱契约。 */
18
18
  export type GoalWorkflowKind = 'plan_approval' | 'goal_self_driven';
19
+ /**
20
+ * 目标分支从哪来。P0-A 必须可见,禁止静默写成 main。
21
+ * - user_confirmed:用户确认过的目标分支
22
+ * - workspace_head:读取目标仓库当前 HEAD 分支(不是猜 main)
23
+ * - preconfigured:仓库/工作区已配置且仍有效的目标分支
24
+ */
25
+ export type GoalTargetBranchSource = 'user_confirmed' | 'workspace_head' | 'preconfigured';
26
+ /** 有代码副作用时:未隔离执行,或独立 Worktree。 */
27
+ export type GoalExecutionIsolation = 'none' | 'worktree';
28
+ /**
29
+ * 有代码副作用的 Goal 才建立的交付绑定。
30
+ * 入口/上下文仓库 ≠ 交付仓库;知识仓分支不能推断代码仓目标分支。
31
+ */
32
+ export interface GoalDeliveryBinding {
33
+ readonly repoId: string;
34
+ readonly targetWorkspacePath?: string;
35
+ readonly targetBranch: string;
36
+ readonly baseCommit?: string;
37
+ readonly targetBranchSource: GoalTargetBranchSource;
38
+ readonly executionIsolation: GoalExecutionIsolation;
39
+ /** 隔离执行用的任务分支;未建 Worktree 时可缺省。 */
40
+ readonly taskBranch?: string;
41
+ /** 隔离执行目录;未建 Worktree 时可缺省。 */
42
+ readonly worktreePath?: string;
43
+ readonly boundAt: string;
44
+ }
45
+ /**
46
+ * 用户可见的交付路由。缺目标分支时写「未确认」,绝不补 main。
47
+ */
48
+ export declare function formatGoalDeliveryRoute(input: {
49
+ readonly originWorkspacePath?: string | null;
50
+ readonly targetWorkspacePath?: string | null;
51
+ readonly targetRepoId?: string | null;
52
+ readonly targetBranch?: string | null;
53
+ readonly executionIsolation?: GoalExecutionIsolation | null;
54
+ readonly deliveryBinding?: GoalDeliveryBinding | null;
55
+ }, options?: {
56
+ readonly locale?: 'zh' | 'en';
57
+ }): string | undefined;
58
+ /**
59
+ * 用户可见的交回状态。没隔离或没验收时不展示。
60
+ */
61
+ export declare function formatGoalDeliveryHandoff(input: {
62
+ readonly deliveryHandoff?: GoalDeliveryHandoff | null;
63
+ readonly resultAcceptance?: {
64
+ readonly acceptedAt?: string | null;
65
+ } | null;
66
+ readonly deliveryBinding?: GoalDeliveryBinding | null;
67
+ }, options?: {
68
+ readonly locale?: 'zh' | 'en';
69
+ }): string | undefined;
19
70
  /**
20
71
  * Goal/Plan 的执行准入事实。
21
72
  *
@@ -169,7 +220,44 @@ export interface GoalRevision {
169
220
  export type GoalRunnerStatus = 'idle' | 'running' | 'compacting_context' | 'resuming_after_compaction' | 'paused' | 'exploring' | 'waiting_user' | 'blocked' | 'budget_exhausted' | 'completed' | 'failed';
170
221
  /** Goal Runner 当前推进意图;只描述编排意图,不替代工具执行 Evidence。 */
171
222
  export type GoalRunnerIntent = 'execute' | 'verify' | 'explore' | 'synthesize' | 'block';
172
- export type GoalRunnerPhase = 'orient' | 'inspect' | 'plan_scaffold' | 'act' | 'verify' | 'repair' | 'synthesize' | 'blocked';
223
+ export type GoalRunnerPhase = 'orient' | 'inspect' | 'plan_scaffold' | 'act' | 'verify' | 'repair' | 'quality_review' | 'synthesize' | 'blocked';
224
+ export type GoalQualityReviewStatus = 'reviewing' | 'passed' | 'failed';
225
+ /** 验收后把隔离改动交回目标分支的结果;不做排队 UI。 */
226
+ export type GoalDeliveryHandoffStatus = 'idle' | 'delivering' | 'delivered' | 'stopped';
227
+ export interface GoalDeliveryHandoff {
228
+ readonly status: GoalDeliveryHandoffStatus;
229
+ readonly repoId?: string;
230
+ readonly targetBranch?: string;
231
+ readonly taskBranch?: string;
232
+ readonly commitSha?: string;
233
+ readonly stoppedReason?: string;
234
+ readonly updatedAt: string;
235
+ }
236
+ export type GoalQualityCheckStatus = 'passed' | 'failed' | 'skipped';
237
+ /** 用户可见的通俗检查记录;内部四层检查名不进界面。 */
238
+ export interface GoalQualityCheck {
239
+ readonly id: 'intent' | 'mechanical' | 'artifact' | 'integration';
240
+ readonly label: string;
241
+ readonly status: GoalQualityCheckStatus;
242
+ readonly note?: string;
243
+ }
244
+ /**
245
+ * 完成门之后、待验收之前的质量自检。
246
+ * 有代码副作用时必须过线,才能进入 result_ready。
247
+ */
248
+ export interface GoalQualityReview {
249
+ readonly status: GoalQualityReviewStatus;
250
+ readonly reviewedAt?: string;
251
+ readonly checks?: readonly GoalQualityCheck[];
252
+ }
253
+ export declare function planRequiresQualityReview(plan: {
254
+ readonly targetWorkspacePath?: string | null;
255
+ readonly targetRepoId?: string | null;
256
+ readonly deliveryBinding?: GoalDeliveryBinding | null;
257
+ } | null | undefined): boolean;
258
+ export declare function isQualityReviewPassed(plan: {
259
+ readonly qualityReview?: GoalQualityReview | null;
260
+ } | null | undefined): boolean;
173
261
  export interface GoalBlockerAudit {
174
262
  readonly fingerprint: string;
175
263
  readonly occurrences: number;
@@ -493,6 +581,23 @@ export interface GoalPlan {
493
581
  readonly originWorkspacePath?: string;
494
582
  /** Workspace/repository where the Goal should write and verify changes. */
495
583
  readonly targetWorkspacePath?: string;
584
+ /**
585
+ * 交付仓库标识。不能只靠 workspace 路径推断;跨仓时入口仓 ≠ 交付仓。
586
+ */
587
+ readonly targetRepoId?: string;
588
+ /**
589
+ * 本次开发要合入的目标分支。不是固定 main,也不得在缺失时静默兜底 main。
590
+ */
591
+ readonly targetBranch?: string;
592
+ /** 建立交付绑定时所对照的目标分支 tip。 */
593
+ readonly baseCommit?: string;
594
+ /** 目标分支的确认来源;缺字段表示尚未确认,不能当已绑定。 */
595
+ readonly targetBranchSource?: GoalTargetBranchSource;
596
+ /**
597
+ * 有代码副作用时才物化。有交付绑定后可记下 taskBranch / worktreePath;
598
+ * isolation 为 `worktree` 时界面写独立执行环境,否则仍标明未隔离执行。
599
+ */
600
+ readonly deliveryBinding?: GoalDeliveryBinding;
496
601
  /** 派生目标关系;全部可选以兼容历史计划。 */
497
602
  readonly parentPlanId?: string;
498
603
  readonly sourceTaskId?: string;
@@ -529,6 +634,10 @@ export interface GoalPlan {
529
634
  readonly version: number;
530
635
  readonly revisionHistory: GoalRevision[];
531
636
  readonly evidenceRefs: string[];
637
+ /**
638
+ * 完成门之后的质量自检。有代码副作用时未过线不得进入待验收。
639
+ */
640
+ readonly qualityReview?: GoalQualityReview;
532
641
  /**
533
642
  * 用户对 completed 结果的验收(工作台一键确认写入)。
534
643
  * 与 GoalPlanStatus.accepted(计划被接受执行)无关。
@@ -538,6 +647,8 @@ export interface GoalPlan {
538
647
  readonly acceptedAt: string;
539
648
  readonly acceptedBy?: 'user' | string;
540
649
  };
650
+ /** 验收后交回目标分支的结果;缺字段表示尚未交回。 */
651
+ readonly deliveryHandoff?: GoalDeliveryHandoff;
541
652
  /** 对齐 system-context.ts 的 epoch */
542
653
  readonly promptContextEpochId?: string;
543
654
  readonly createdAt: string;
package/dist/goal.js CHANGED
@@ -1,3 +1,97 @@
1
+ function workspaceLeafName(pathValue) {
2
+ if (typeof pathValue !== 'string')
3
+ return undefined;
4
+ const trimmed = pathValue.trim().replace(/[\\/]+$/, '');
5
+ if (!trimmed)
6
+ return undefined;
7
+ const parts = trimmed.split(/[\\/]/).filter(Boolean);
8
+ return parts.at(-1) || undefined;
9
+ }
10
+ /**
11
+ * 用户可见的交付路由。缺目标分支时写「未确认」,绝不补 main。
12
+ */
13
+ export function formatGoalDeliveryRoute(input, options) {
14
+ const locale = options?.locale === 'en' ? 'en' : 'zh';
15
+ const origin = workspaceLeafName(input.originWorkspacePath);
16
+ const targetPath = workspaceLeafName(input.deliveryBinding?.targetWorkspacePath ?? input.targetWorkspacePath);
17
+ const repoId = input.deliveryBinding?.repoId?.trim() || input.targetRepoId?.trim() || undefined;
18
+ const target = repoId || targetPath;
19
+ const branch = input.deliveryBinding?.targetBranch?.trim() || input.targetBranch?.trim() || undefined;
20
+ const isolation = input.deliveryBinding?.executionIsolation ?? input.executionIsolation;
21
+ const parts = [];
22
+ if (origin && target && origin !== target) {
23
+ parts.push(locale === 'zh' ? `来源 ${origin}` : `from ${origin}`);
24
+ }
25
+ if (target) {
26
+ parts.push(locale === 'zh' ? `交付 ${target}` : `to ${target}`);
27
+ }
28
+ else if (origin) {
29
+ parts.push(origin);
30
+ }
31
+ if (branch) {
32
+ parts.push(branch);
33
+ }
34
+ else if (target || origin) {
35
+ parts.push(locale === 'zh' ? '目标分支未确认' : 'target branch unconfirmed');
36
+ }
37
+ if (isolation === 'worktree' && (branch || target)) {
38
+ parts.push(locale === 'zh' ? '独立执行环境' : 'isolated worktree');
39
+ }
40
+ else if (isolation === 'none' && (branch || target)) {
41
+ parts.push(locale === 'zh' ? '未隔离执行' : 'not isolated');
42
+ }
43
+ return parts.length > 0 ? parts.join(' · ') : undefined;
44
+ }
45
+ function handoffTargetLabel(handoff) {
46
+ const repo = typeof handoff.repoId === 'string' ? handoff.repoId.trim() : '';
47
+ const branch = typeof handoff.targetBranch === 'string' ? handoff.targetBranch.trim() : '';
48
+ if (repo && branch)
49
+ return `${repo} / ${branch}`;
50
+ if (branch)
51
+ return branch;
52
+ if (repo)
53
+ return repo;
54
+ return undefined;
55
+ }
56
+ function handoffStoppedReasonLabel(reason, locale) {
57
+ switch (reason) {
58
+ case 'target_branch_moved':
59
+ return locale === 'zh' ? '目标分支已更新' : 'target branch moved';
60
+ case 'same_target_busy':
61
+ return locale === 'zh' ? '同一目标正在交回' : 'same target is delivering';
62
+ case 'merge_conflict':
63
+ return locale === 'zh' ? '交回时发生冲突' : 'delivery conflicted';
64
+ default:
65
+ return locale === 'zh' ? '交回已停止' : 'delivery stopped';
66
+ }
67
+ }
68
+ /**
69
+ * 用户可见的交回状态。没隔离或没验收时不展示。
70
+ */
71
+ export function formatGoalDeliveryHandoff(input, options) {
72
+ const locale = options?.locale === 'en' ? 'en' : 'zh';
73
+ const acceptedAt = input.resultAcceptance?.acceptedAt;
74
+ if (typeof acceptedAt !== 'string' || !acceptedAt.trim())
75
+ return undefined;
76
+ if (input.deliveryBinding?.executionIsolation !== 'worktree')
77
+ return undefined;
78
+ const handoff = input.deliveryHandoff;
79
+ if (!handoff?.status || handoff.status === 'idle')
80
+ return undefined;
81
+ const target = handoffTargetLabel(handoff);
82
+ if (handoff.status === 'delivering') {
83
+ return locale === 'zh' ? '正在交回目标分支' : 'delivering to target branch';
84
+ }
85
+ if (handoff.status === 'delivered') {
86
+ return target
87
+ ? (locale === 'zh' ? `已交回 ${target}` : `delivered to ${target}`)
88
+ : (locale === 'zh' ? '已交回目标分支' : 'delivered to target branch');
89
+ }
90
+ if (handoff.status === 'stopped') {
91
+ return handoffStoppedReasonLabel(handoff.stoppedReason, locale);
92
+ }
93
+ return undefined;
94
+ }
1
95
  /**
2
96
  * 统一 live 与终态用时口径。
3
97
  * - 终态优先使用落盘 activeMs / wallClockMs
@@ -67,3 +161,13 @@ export function projectGoalTiming(timing, nowMs = Date.now()) {
67
161
  isLive: true,
68
162
  };
69
163
  }
164
+ export function planRequiresQualityReview(plan) {
165
+ if (!plan)
166
+ return false;
167
+ // 只有真正建立了交付绑定的代码副作用 Goal 才强制自检。
168
+ // 仅有 workspace 路径不等于要改仓库,不能把问答/存量完成结果拦在待验收外。
169
+ return Boolean(plan.deliveryBinding);
170
+ }
171
+ export function isQualityReviewPassed(plan) {
172
+ return plan?.qualityReview?.status === 'passed';
173
+ }
@@ -83,6 +83,16 @@ export interface TaskOverviewItem {
83
83
  readonly currentGoalTitle?: string;
84
84
  /** Workspace 标签(原型卡片右上角)。 */
85
85
  readonly workspaceLabel?: string;
86
+ /**
87
+ * 用户可见的交付路由:来源工作区 · 目标仓库 · 目标分支。
88
+ * 缺目标分支时写「未确认」,不得补 main。
89
+ */
90
+ readonly deliveryRoute?: string;
91
+ /**
92
+ * 用户可见的交回状态:已交回 / 正在交回 / 停止原因。
93
+ * 没隔离或没验收时不出现。
94
+ */
95
+ readonly deliveryHandoffLabel?: string;
86
96
  /** 状态描述(原型卡片中部,如「Peer 正在验证」「等待权限」)。 */
87
97
  readonly statusLabel: string;
88
98
  /** 执行异常的可展示原因;仅异常/暂停投影存在,不承载控制状态。 */
@@ -121,7 +131,7 @@ export interface TaskOverviewItem {
121
131
  * 来源:modelProviderId 的 group 段;无绑定时省略。
122
132
  */
123
133
  readonly providerLabel?: string;
124
- /** 动作按钮标签(原型「处理 →」「验收 →」「继续 →」)。 */
134
+ /** 动作按钮标签(原型「处理 →」「查看结果」「继续 →」)。 */
125
135
  readonly actionLabel: string;
126
136
  /**
127
137
  * 是否存在用户尚未查看的新动态。
@@ -152,12 +162,18 @@ export interface GoalPlanProjectionSnapshot {
152
162
  readonly status: GoalPlanStatus;
153
163
  /** Runner 实时态;Plan 未进入自驱时为 undefined。 */
154
164
  readonly runnerStatus?: GoalRunnerStatus;
165
+ /** Runner 阻塞是否由系统基础设施持有,而不是用户行动权。 */
166
+ readonly systemBlocked?: boolean;
155
167
  /** Runner 上存在尚未被 resume 消费的网络/流式中断事实。 */
156
168
  readonly interrupted?: boolean;
157
169
  /** 持久化中断事实中的用户可展示原因。 */
158
170
  readonly interruptionReason?: string;
159
171
  readonly title: string;
160
172
  readonly workspaceLabel?: string;
173
+ /** 用户可见的交付路由;缺目标分支时写「未确认」。 */
174
+ readonly deliveryRoute?: string;
175
+ /** 用户可见的交回状态;没隔离或没验收时省略。 */
176
+ readonly deliveryHandoffLabel?: string;
161
177
  readonly progress?: {
162
178
  readonly completed: number;
163
179
  readonly total: number;
@@ -187,6 +203,15 @@ export interface GoalPlanProjectionSnapshot {
187
203
  * result_ready,由用户在 Result Review 页手动归档)。
188
204
  */
189
205
  readonly accepted?: boolean;
206
+ /** 有代码副作用时,完成门之后还要质量自检过线才能待验收。 */
207
+ readonly requiresQualityReview?: boolean;
208
+ readonly qualityReviewStatus?: 'reviewing' | 'passed' | 'failed';
209
+ readonly qualityChecks?: readonly {
210
+ readonly id: string;
211
+ readonly label: string;
212
+ readonly status: 'passed' | 'failed' | 'skipped';
213
+ readonly note?: string;
214
+ }[];
190
215
  }
191
216
  /** Automation 投影所需的最小字段快照(Definition 与 Run 联合判断)。 */
192
217
  export interface AutomationProjectionSnapshot {
@@ -123,6 +123,11 @@ export function projectGoalPlan(snapshot, options) {
123
123
  nextAction: decision.nextAction,
124
124
  title: snapshot.title,
125
125
  ...(snapshot.workspaceLabel ? { workspaceLabel: snapshot.workspaceLabel } : {}),
126
+ ...(snapshot.deliveryRoute ? { deliveryRoute: snapshot.deliveryRoute } : {}),
127
+ ...(snapshot.deliveryHandoffLabel ? { deliveryHandoffLabel: snapshot.deliveryHandoffLabel } : {}),
128
+ ...(snapshot.requiresQualityReview ? { requiresQualityReview: true } : {}),
129
+ ...(snapshot.qualityReviewStatus ? { qualityReviewStatus: snapshot.qualityReviewStatus } : {}),
130
+ ...(snapshot.qualityChecks?.length ? { qualityChecks: snapshot.qualityChecks } : {}),
126
131
  statusLabel: decision.statusLabel,
127
132
  ...(decision.actionRight === 'paused' && snapshot.interruptionReason
128
133
  ? { issueDetail: snapshot.interruptionReason }
@@ -167,12 +172,21 @@ function decideGoalPlan(snapshot) {
167
172
  // rule 16 first: 其他终态计划优先于 runner 残留态
168
173
  // (历史 failed/cancelled/completed 上的 runner.blocked 不得再进 needs_you)
169
174
  if (status === 'completed' && accepted !== true) {
175
+ if (snapshot.requiresQualityReview === true
176
+ && snapshot.qualityReviewStatus !== 'passed') {
177
+ return {
178
+ actionRight: 'peer_advancing',
179
+ nextAction: 'none',
180
+ statusLabel: 'Peer 正在自检',
181
+ actionLabel: '查看 →',
182
+ };
183
+ }
170
184
  // rule 6: 完成且未验收 → 结果就绪
171
185
  return {
172
186
  actionRight: 'result_ready',
173
187
  nextAction: 'review_result',
174
188
  statusLabel: '待用户验收',
175
- actionLabel: '验收 →',
189
+ actionLabel: '查看结果',
176
190
  };
177
191
  }
178
192
  if (status === 'completed' || status === 'cancelled' || status === 'failed') {
@@ -204,6 +218,18 @@ function decideGoalPlan(snapshot) {
204
218
  };
205
219
  }
206
220
  const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
221
+ const recoverableSystemBlocked = runnerStatus === 'blocked'
222
+ && snapshot.systemBlocked === true;
223
+ // System infrastructure failures are not user decisions. A foreground turn may
224
+ // take over this blocker; until then expose an inspectable interruption.
225
+ if (planStillActive && recoverableSystemBlocked) {
226
+ return {
227
+ actionRight: 'paused',
228
+ nextAction: 'inspect',
229
+ statusLabel: '系统执行中断',
230
+ actionLabel: '诊断 →',
231
+ };
232
+ }
207
233
  // rule 4: Runner 已明确把行动权交给用户,不再展示为“Peer 正在推进”。
208
234
  if (planStillActive && runnerStatus === 'waiting_user') {
209
235
  return {
@@ -223,7 +249,7 @@ function decideGoalPlan(snapshot) {
223
249
  needsYouReason: 'decision',
224
250
  nextAction: 'decide_blocked',
225
251
  statusLabel: runnerStatus === 'budget_exhausted' ? '预算已耗尽' : '执行受阻',
226
- actionLabel: '决策 →',
252
+ actionLabel: '决策',
227
253
  };
228
254
  }
229
255
  // rule 12: 计划暂停(先于 runner 态判断,用户主动暂停优先)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.0.4-beta.2",
3
+ "version": "0.0.4-beta.3",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",