@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.
Files changed (86) hide show
  1. package/dist/acceptance-close-gate.d.ts +10 -1
  2. package/dist/acceptance-close-gate.js +12 -0
  3. package/dist/agent-supervision.d.ts +81 -0
  4. package/dist/agent-supervision.js +1 -0
  5. package/dist/attention.d.ts +44 -0
  6. package/dist/attention.js +1 -0
  7. package/dist/bot-access-policy.d.ts +29 -0
  8. package/dist/bot-access-policy.js +1 -0
  9. package/dist/bot-conversation-read.d.ts +25 -0
  10. package/dist/bot-conversation-read.js +9 -0
  11. package/dist/bot-model-selection.d.ts +13 -0
  12. package/dist/bot-model-selection.js +1 -0
  13. package/dist/browser-window.d.ts +48 -0
  14. package/dist/browser-window.js +23 -0
  15. package/dist/capability-admission.d.ts +20 -0
  16. package/dist/capability-admission.js +1 -0
  17. package/dist/delegation-coordination.d.ts +81 -0
  18. package/dist/delegation-coordination.js +1 -0
  19. package/dist/delegation.d.ts +216 -7
  20. package/dist/delegation.js +43 -39
  21. package/dist/document-reference.d.ts +83 -0
  22. package/dist/document-reference.js +1 -0
  23. package/dist/evidence-inspection.d.ts +64 -0
  24. package/dist/evidence-inspection.js +1 -0
  25. package/dist/goal.d.ts +50 -2
  26. package/dist/index.d.ts +56 -5
  27. package/dist/index.js +25 -0
  28. package/dist/input-prediction.d.ts +86 -0
  29. package/dist/input-prediction.js +48 -0
  30. package/dist/intent-coordination.d.ts +201 -0
  31. package/dist/intent-coordination.js +1 -0
  32. package/dist/interactive-result.d.ts +363 -0
  33. package/dist/interactive-result.js +215 -0
  34. package/dist/interactive-verification.d.ts +41 -0
  35. package/dist/interactive-verification.js +65 -0
  36. package/dist/local-git.d.ts +44 -0
  37. package/dist/local-git.js +3 -0
  38. package/dist/local-image.d.ts +53 -0
  39. package/dist/local-image.js +5 -0
  40. package/dist/model-reasoning.d.ts +13 -0
  41. package/dist/model-reasoning.js +18 -0
  42. package/dist/model-routing.d.ts +37 -3
  43. package/dist/model-routing.js +31 -5
  44. package/dist/project-agent-failure.d.ts +30 -0
  45. package/dist/project-agent-failure.js +44 -0
  46. package/dist/project-input-recovery.d.ts +65 -0
  47. package/dist/project-input-recovery.js +5 -0
  48. package/dist/project-recovery.d.ts +43 -0
  49. package/dist/project-recovery.js +1 -0
  50. package/dist/project.d.ts +81 -0
  51. package/dist/project.js +8 -5
  52. package/dist/remote-access.d.ts +15 -0
  53. package/dist/remote-access.js +1 -1
  54. package/dist/reply-delivery.d.ts +28 -0
  55. package/dist/reply-delivery.js +1 -0
  56. package/dist/resource-edit-execution.d.ts +68 -0
  57. package/dist/resource-edit-execution.js +96 -0
  58. package/dist/resource-edit.d.ts +237 -0
  59. package/dist/resource-edit.js +134 -0
  60. package/dist/resource-feedback-transport.d.ts +25 -0
  61. package/dist/resource-feedback-transport.js +93 -0
  62. package/dist/resource-feedback.d.ts +98 -0
  63. package/dist/resource-feedback.js +151 -0
  64. package/dist/resource-file-replace.d.ts +36 -0
  65. package/dist/resource-file-replace.js +40 -0
  66. package/dist/resource-reference-hints.d.ts +3 -0
  67. package/dist/resource-reference-hints.js +58 -0
  68. package/dist/resource-window.d.ts +222 -0
  69. package/dist/resource-window.js +252 -0
  70. package/dist/runtime-session-facts.d.ts +58 -0
  71. package/dist/runtime-session-facts.js +55 -0
  72. package/dist/session-control.d.ts +196 -0
  73. package/dist/session-control.js +48 -0
  74. package/dist/session-facts.d.ts +29 -0
  75. package/dist/session-facts.js +35 -0
  76. package/dist/system-context.d.ts +6 -0
  77. package/dist/task-overview.d.ts +90 -0
  78. package/dist/task-overview.js +322 -17
  79. package/dist/tool-activity-preview.d.ts +4 -0
  80. package/dist/tool-activity-preview.js +72 -0
  81. package/dist/usage-accounting.d.ts +1 -1
  82. package/dist/user-anchor.d.ts +17 -0
  83. package/dist/user-anchor.js +1 -0
  84. package/dist/work-coordination.d.ts +165 -0
  85. package/dist/work-coordination.js +1 -0
  86. package/package.json +1 -1
@@ -1,13 +1,52 @@
1
1
  /**
2
2
  * Project-agent delegation contracts. Pure projections only; nothing here runs a tool.
3
- * The user-visible conclusion of a work session is projectGoalPlan's conclusion.
3
+ * The user-visible conclusion of a work session is `decideLifecycle`'s conclusion.
4
4
  */
5
5
  import type { ModelSelectionSnapshot } from './model-routing.ts';
6
- import { type GoalPlanProjectionSnapshot, type TaskOverviewItem } from './task-overview.ts';
7
- export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
8
- export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
6
+ import { type ExecutionOwnership, type GoalPlanProjectionSnapshot, type TaskOverviewItem } from './task-overview.ts';
7
+ export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'waiting_agent' | 'stopping' | 'awaiting_outcome' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
8
+ export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "waiting_agent", "stopping", "awaiting_outcome", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
9
9
  export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
10
10
  export interface DelegationOrigin {
11
+ readonly capabilityAdmission?: import('./capability-admission.ts').DelegationCapabilityAdmission;
12
+ readonly executionGeneration?: string;
13
+ readonly executionControl?: import('./session-control.ts').SessionControlOperation;
14
+ /** Host receipt for a user-authorized claim closure. It is not a stop receipt. */
15
+ readonly executionClaimClosure?: import('./session-control.ts').ExecutionClaimClosure;
16
+ /** Host receipt for an unknown-outcome resolution (ADR 127). It ends occupancy only; not a stop receipt or a tool result. */
17
+ readonly unknownOutcomeResolution?: import('./session-control.ts').UnknownOutcomeResolution;
18
+ readonly takeover?: {
19
+ operationId: string;
20
+ phase: 'stopping' | 'completed' | 'superseded' | 'rejected';
21
+ supersededBy?: string;
22
+ text: string;
23
+ binding: import('./delegation-coordination.ts').CoordinationExecutionBinding;
24
+ requestedAt: string;
25
+ completedAt?: string;
26
+ repair?: boolean;
27
+ };
28
+ readonly coordinationBinding?: import('./delegation-coordination.ts').CoordinationExecutionBinding;
29
+ readonly cancellation?: {
30
+ readonly operationId: string;
31
+ readonly reason: string;
32
+ readonly phase: 'stopping' | 'awaiting_outcome' | 'completed';
33
+ readonly requestedAt: string;
34
+ readonly completedAt?: string;
35
+ readonly evidenceCalls?: readonly string[];
36
+ readonly preserveArtifacts?: boolean;
37
+ readonly disposition?: 'user_withdrawn';
38
+ readonly withdrawal?: {
39
+ readonly workspaceId: string;
40
+ readonly parentConversationId: string;
41
+ readonly sessionId: string;
42
+ readonly planId: string;
43
+ readonly anchorMessageId: string;
44
+ readonly inputId: string;
45
+ readonly admittedAt: string;
46
+ };
47
+ };
48
+ readonly retainedForRecovery?: boolean;
49
+ readonly workId?: string;
11
50
  readonly anchorMessageId: string;
12
51
  readonly inputId: string;
13
52
  readonly surface: InputSurface;
@@ -28,13 +67,24 @@ export interface DelegationOrigin {
28
67
  readonly depth: number;
29
68
  }
30
69
  export interface SessionQueueFacts {
70
+ readonly resourceBlocker?: import('./session-control.ts').ExecutionResourceBlocker;
71
+ readonly executionClaimClosure?: import('./session-control.ts').ExecutionClaimClosure;
72
+ readonly unknownOutcomePolicy?: import('./session-control.ts').UnknownOutcomePolicyTier;
73
+ readonly unknownOutcomeResolution?: import('./session-control.ts').UnknownOutcomeResolution;
74
+ readonly retainedUnknowns?: readonly {
75
+ readonly closureId: string;
76
+ readonly unknownCalls: readonly string[];
77
+ readonly at: string;
78
+ readonly proof: 'verified_dead' | 'legacy_user_confirmed';
79
+ }[];
31
80
  readonly queuedBehind?: readonly {
32
81
  readonly sessionId: string;
33
82
  readonly title: string;
34
83
  }[];
35
- readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | null;
84
+ readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | 'resource_protection' | 'resource_recovery' | null;
36
85
  }
37
86
  export interface WorkSessionConversationMeta extends SessionQueueFacts {
87
+ readonly coordination?: import('./delegation-coordination.ts').CoordinationSessionFacts;
38
88
  readonly sessionId?: string;
39
89
  readonly conversationId?: string;
40
90
  readonly workspaceId: string;
@@ -42,11 +92,21 @@ export interface WorkSessionConversationMeta extends SessionQueueFacts {
42
92
  readonly origin: DelegationOrigin;
43
93
  readonly supersededBy?: string;
44
94
  readonly acceptance?: 'auto' | 'confirm';
95
+ readonly resultConfirmationRequired?: boolean;
45
96
  readonly accepted?: boolean;
46
97
  readonly verifying?: boolean;
47
98
  readonly phase?: 'starting' | 'verifying' | 'paused';
99
+ /** 进程内执行所有权(runtime 采集);缺省表示该入口尚未接入所有权事实。 */
100
+ readonly executionOwnership?: ExecutionOwnership;
101
+ readonly obligationDisposition?: 'indexed' | 'suspended' | 'current';
48
102
  }
49
103
  export interface WorkSession extends SessionQueueFacts {
104
+ readonly executionOwnership?: ExecutionOwnership;
105
+ readonly followUp?: import('./task-overview.ts').FollowUpProjection;
106
+ readonly verificationProgress?: VerificationProgress;
107
+ readonly completionReviewRequired?: boolean;
108
+ readonly resultConfirmationRequired?: boolean;
109
+ readonly coordination?: import('./delegation-coordination.ts').CoordinationSessionFacts;
50
110
  readonly sessionId: string;
51
111
  readonly workspaceId: string;
52
112
  readonly title: string;
@@ -55,6 +115,8 @@ export interface WorkSession extends SessionQueueFacts {
55
115
  readonly actionRight: TaskOverviewItem['actionRight'];
56
116
  readonly nextAction: TaskOverviewItem['nextAction'];
57
117
  readonly statusLabel: string;
118
+ /** 是否可取消;由生命周期决策统一给出,renderer 不再自行推断。 */
119
+ readonly cancelable?: boolean;
58
120
  readonly needsYouReason?: TaskOverviewItem['needsYouReason'];
59
121
  readonly spawnedAt: string;
60
122
  readonly conversationId?: string;
@@ -62,18 +124,61 @@ export interface WorkSession extends SessionQueueFacts {
62
124
  readonly supersededBy?: string;
63
125
  }
64
126
  export interface SessionReport {
127
+ readonly agentSupervision?: import('./agent-supervision.ts').AgentSupervisionReport;
128
+ /** Current host verification, loaded with task details; never assistant prose. */
129
+ readonly verification?: SessionVerificationDetail;
65
130
  readonly sessionId: string;
66
131
  readonly planId: string | null;
67
132
  readonly status: WorkSessionStatus;
68
133
  readonly summary: string;
134
+ readonly taskBrief?: string;
69
135
  readonly keyFindings: readonly string[];
70
136
  readonly changedFiles: readonly {
71
137
  readonly path: string;
72
138
  readonly summary: string;
73
139
  }[];
74
140
  readonly evidenceRefs: readonly string[];
141
+ /** Persisted worker output is a claim; verification still comes from host Evidence. */
142
+ readonly contentSource?: {
143
+ readonly kind: 'worker_message' | 'task_results';
144
+ readonly conversationId?: string;
145
+ readonly messageId?: string;
146
+ readonly verification: 'unverified';
147
+ };
148
+ }
149
+ export type DelegationEventKind = 'agent_message' | 'session_running' | 'session_spawned' | 'session_progress' | 'session_needs_user' | 'report_available' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
150
+ /** Local orchestration facts; never a human authorization or a verified result. */
151
+ export interface AgentMessage {
152
+ readonly deliveryIntent?: import('./agent-supervision.ts').AgentDeliveryIntent;
153
+ readonly decisionRequest?: import('./agent-supervision.ts').AgentDecisionRequest;
154
+ readonly decisionAnswer?: import('./agent-supervision.ts').AgentDecisionAnswer;
155
+ readonly goalRevision?: number;
156
+ readonly executionEpoch?: string;
157
+ readonly replyTo?: string;
158
+ readonly messageId: string;
159
+ readonly workspaceId: string;
160
+ readonly sessionId: string;
161
+ readonly senderConversationId: string;
162
+ readonly recipientConversationId: string;
163
+ readonly direction: 'parent_to_child' | 'child_to_parent';
164
+ readonly purpose: 'update' | 'question' | 'answer';
165
+ readonly text: string;
166
+ readonly at: string;
167
+ }
168
+ export interface VerificationProgress {
169
+ readonly continuationId: string;
170
+ readonly startedAt: string;
171
+ readonly lastProgressAt: string;
172
+ readonly observationCount: number;
173
+ readonly phase: 'ready' | 'requesting' | 'tools' | 'completed';
174
+ }
175
+ export interface AgentActivity {
176
+ readonly verificationProgress?: VerificationProgress;
177
+ readonly eventId: string;
178
+ readonly sessionId: string;
179
+ readonly name: string;
180
+ readonly state: 'queued' | 'started' | 'update' | 'question' | 'answer' | 'reported' | 'verified' | 'verifying' | 'ended' | 'cancelled' | 'blocked';
75
181
  }
76
- export type DelegationEventKind = 'session_spawned' | 'session_progress' | 'session_needs_user' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
77
182
  export type JsonValue = null | string | number | boolean | readonly JsonValue[] | {
78
183
  readonly [key: string]: JsonValue;
79
184
  };
@@ -101,6 +206,9 @@ export interface AgentReplyMeta {
101
206
  readonly surfacing: 'interrupt' | 'message' | 'digest' | 'silent';
102
207
  }
103
208
  export interface ReplySessionState {
209
+ readonly sourceRevision?: string;
210
+ /** Stable reporting facts, including a changed verifier failure; not acceptance authority. */
211
+ readonly observationRevision?: string;
104
212
  readonly sessionId: string;
105
213
  readonly status: WorkSessionStatus;
106
214
  }
@@ -155,6 +263,26 @@ export interface DispositionEvent {
155
263
  readonly replyMessageId?: string;
156
264
  }
157
265
  export type VerificationOutcome = 'passed' | 'failed' | 'partial' | 'unverifiable';
266
+ /** Host-bound manual completion review; distinct from acceptance of a completed result. */
267
+ export interface SessionCompletionReview {
268
+ readonly sessionId: string;
269
+ readonly reviewToken: string;
270
+ readonly criteria: readonly {
271
+ readonly id: string;
272
+ readonly description: string;
273
+ }[];
274
+ readonly report: string;
275
+ readonly confirmed?: boolean;
276
+ }
277
+ export type SessionConfirmationInput = {
278
+ readonly workspaceId: string;
279
+ readonly sessionId: string;
280
+ } & ({
281
+ readonly stage?: 'result_acceptance';
282
+ } | {
283
+ readonly stage: 'manual_completion';
284
+ readonly reviewToken: string;
285
+ });
158
286
  export type IndependentVerifierState = 'passed' | 'failed' | 'not_required' | 'missing';
159
287
  export interface VerificationCheck {
160
288
  readonly name: string;
@@ -169,6 +297,56 @@ export interface VerificationVerdict {
169
297
  readonly checks: readonly VerificationCheck[];
170
298
  readonly evidenceRefs: readonly string[];
171
299
  }
300
+ export interface SessionVerificationDetail {
301
+ readonly sessionId: string;
302
+ readonly outcome: VerificationOutcome;
303
+ /** A host review is active. The outcome describes evidence already recorded. */
304
+ readonly verificationInProgress?: true;
305
+ /** A persisted explicit review of the current task and report. */
306
+ readonly explicitVerification?: {
307
+ readonly verdictRef: string;
308
+ readonly outcome: VerificationOutcome;
309
+ };
310
+ readonly checks: readonly {
311
+ readonly name: string;
312
+ readonly result: 'passed' | 'failed';
313
+ readonly evidenceRefs: readonly string[];
314
+ readonly reason?: string;
315
+ }[];
316
+ readonly workerModel: string | null;
317
+ readonly verifierModel: string | null;
318
+ readonly sameSource: boolean;
319
+ readonly reviewAttempts: readonly VerificationAttemptDiagnostic[];
320
+ readonly outputs: readonly {
321
+ readonly name: string;
322
+ readonly evidenceRef: string;
323
+ readonly summary: string;
324
+ readonly truncated: boolean;
325
+ }[];
326
+ }
327
+ /** Bounded persisted diagnostics, never an input to acceptance or Evidence authority. */
328
+ export interface VerificationAttemptDiagnostic {
329
+ readonly verifierRunId: string;
330
+ readonly status: 'passed' | 'failed';
331
+ readonly diagnosticOnly: true;
332
+ /** null means this historical run has no source-version binding. */
333
+ readonly matchesCurrentSource: boolean | null;
334
+ readonly completedAt: string;
335
+ readonly failureReason: string;
336
+ readonly failedCriteria: readonly {
337
+ readonly criterionId: string;
338
+ readonly reason: string;
339
+ readonly evidenceRefs: readonly string[];
340
+ }[];
341
+ readonly missingEvidence: readonly {
342
+ readonly taskId: string;
343
+ readonly reason: string;
344
+ readonly evidenceRefs: readonly string[];
345
+ }[];
346
+ readonly risks: readonly string[];
347
+ readonly recommendedNextAction: string;
348
+ readonly evidenceRefs: readonly string[];
349
+ }
172
350
  export type AcceptancePolicy = 'auto' | 'confirm';
173
351
  export type AcceptanceReason = 'verdict_not_passed' | 'manual_criteria_pending' | 'external_side_effects' | 'destructive_operation' | 'out_of_scope_write' | 'project_requires_confirm' | 'user_requested_review' | 'verification_below_floor';
174
352
  export interface AcceptanceDecision {
@@ -200,6 +378,22 @@ export interface SurfacingEvent {
200
378
  readonly severity: 'info' | 'notable' | 'urgent';
201
379
  readonly deadlineImminent?: boolean;
202
380
  }
381
+ /** Explicit user uploads are factual user context, never execution authority. */
382
+ export type ProjectInputAttachment = {
383
+ readonly id: string;
384
+ readonly name: string;
385
+ readonly mimeType: string;
386
+ readonly size: number;
387
+ readonly sourceKind: 'user_upload';
388
+ } & ({
389
+ readonly kind: 'image';
390
+ readonly dataUrl: string;
391
+ } | {
392
+ readonly kind: 'text';
393
+ readonly text: string;
394
+ } | {
395
+ readonly kind: 'unsupported';
396
+ });
203
397
  export interface ProjectInput {
204
398
  readonly inputId: string;
205
399
  readonly workspaceId: string;
@@ -208,10 +402,23 @@ export interface ProjectInput {
208
402
  readonly anchorRefs: readonly string[];
209
403
  readonly quoteRefs: readonly string[];
210
404
  readonly attachmentRefs: readonly string[];
405
+ readonly attachments?: readonly ProjectInputAttachment[];
406
+ readonly resourceFeedback?: readonly import('./resource-feedback.ts').ResourceFeedback[];
211
407
  readonly createdAt: string;
212
408
  }
213
- export type PendingApprovalState = 'open' | 'approved' | 'denied' | 'expired' | 'stale';
409
+ /** Existing durable input receipt. A later handoff can fail after input was saved. */
410
+ export interface ProjectAgentSubmitInputResult {
411
+ readonly ok: boolean;
412
+ readonly code?: string;
413
+ readonly message?: string;
414
+ readonly input?: ProjectInput;
415
+ readonly delivery?: 'queued' | 'user_intervened';
416
+ }
417
+ export type PendingApprovalState = 'open' | 'approved' | 'denied' | 'expired' | 'stale' | 'cancelled';
214
418
  export interface PendingApproval {
419
+ readonly policyRevision?: string;
420
+ readonly imageReadScope?: import('./local-image.ts').LocalImagePermissionScope;
421
+ readonly imageReadGrant?: import('./local-image.ts').ImageReadGrant;
215
422
  readonly approvalId: string;
216
423
  readonly workspaceId: string | null;
217
424
  readonly sessionId?: string | null;
@@ -225,6 +432,8 @@ export interface PendingApproval {
225
432
  readonly argsDigest: string;
226
433
  readonly createdAt: string;
227
434
  readonly state: PendingApprovalState;
435
+ readonly deadlineAt?: string;
436
+ readonly decisionReason?: 'permission_cancelled' | 'permission_timeout' | 'permission_unavailable' | 'local_user_denied' | 'permission_policy_changed';
228
437
  readonly decidedAt?: string;
229
438
  readonly decidedBy?: 'local_ui' | 'policy';
230
439
  }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Project-agent delegation contracts. Pure projections only; nothing here runs a tool.
3
- * The user-visible conclusion of a work session is projectGoalPlan's conclusion.
3
+ * The user-visible conclusion of a work session is `decideLifecycle`'s conclusion.
4
4
  */
5
- import { projectGoalPlan, } from "./task-overview.js";
6
- export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
5
+ import { controlPhasesForOrigin } from "./session-control.js";
6
+ import { decideLifecycle, } from "./task-overview.js";
7
+ export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'waiting_agent', 'stopping', 'awaiting_outcome', 'verifying',
7
8
  'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
8
9
  function fnv1a(text) {
9
10
  let hash = 0x811c9dc5;
@@ -43,60 +44,63 @@ export function createDelegationEvent(input) {
43
44
  payload,
44
45
  };
45
46
  }
46
- function delegationStatus(snapshot, meta, projected) {
47
- if (snapshot.status === 'failed')
48
- return 'failed';
49
- if (snapshot.status === 'cancelled')
50
- return 'cancelled';
51
- if (snapshot.status === 'completed') {
52
- if (meta.verifying || meta.phase === 'verifying')
53
- return 'verifying';
54
- if (meta.acceptance === 'confirm' && meta.accepted !== true)
55
- return 'result_ready';
56
- return 'accepted';
57
- }
58
- if (meta.supersededBy)
59
- return 'superseded';
60
- if (meta.phase === 'paused')
61
- return 'paused';
62
- // 复核进行中盖过「需要你」。草稿、待批准、等回答的计划在独立复核时都显示 verifying。
63
- if (meta.verifying || meta.phase === 'verifying')
64
- return 'verifying';
65
- if (projected.actionRight === 'needs_you')
66
- return 'waiting_user';
67
- if (snapshot.runnerStatus === 'exploring')
68
- return 'verifying';
69
- if (meta.phase === 'starting')
70
- return 'starting';
71
- if (snapshot.status === 'approved'
72
- || snapshot.status === 'accepted'
73
- || snapshot.status === 'paused'
74
- || snapshot.status === 'interrupted'
75
- || projected.actionRight === 'paused') {
76
- return 'queued';
77
- }
78
- return 'running';
79
- }
80
47
  /**
81
48
  * Project a GoalPlan snapshot into a work session.
82
49
  * actionRight / nextAction / statusLabel come from projectGoalPlan, so the two projections cannot disagree.
83
50
  * A paused plan has no delegation status of its own; it is queued, and the visible conclusion stays paused.
84
51
  */
85
52
  export function projectWorkSession(plan, conversationMeta) {
86
- const projected = projectGoalPlan(plan);
53
+ const projected = decideLifecycle(plan, {
54
+ ...(conversationMeta.executionOwnership ? { executionOwnership: conversationMeta.executionOwnership } : {}),
55
+ // `delegated` 必须是真实事实;不能用"这是工作会话"反推,否则会改写非委派历史语义。
56
+ ...(plan.delegated === true ? { delegated: true } : {}),
57
+ ...(conversationMeta.acceptance ? { acceptance: conversationMeta.acceptance } : {}),
58
+ humanGate: conversationMeta.resultConfirmationRequired === true,
59
+ accepted: conversationMeta.accepted === true ||
60
+ (plan.delegated !== true &&
61
+ plan.status === 'completed' &&
62
+ conversationMeta.acceptance !== 'confirm' &&
63
+ conversationMeta.accepted === undefined &&
64
+ !conversationMeta.verifying &&
65
+ !plan.runnerStatus),
66
+ superseded: Boolean(conversationMeta.supersededBy),
67
+ needsUser: plan.status === 'awaiting_approval' || plan.needsUser === true,
68
+ verificationActive: conversationMeta.verifying === true,
69
+ ...(conversationMeta.phase ? { phase: conversationMeta.phase } : {}),
70
+ blockedReason: plan.agentWaiting ? 'waiting_parent_agent' : plan.blockedReason,
71
+ interrupted: plan.interrupted,
72
+ interruptionOrigin: plan.interruptionOrigin,
73
+ ...controlPhasesForOrigin(conversationMeta.origin),
74
+ ...(conversationMeta.obligationDisposition ? { obligationDisposition: conversationMeta.obligationDisposition } : {}),
75
+ ...(conversationMeta.origin.cancellation?.disposition ? { cancellationDisposition: conversationMeta.origin.cancellation.disposition } : {}),
76
+ ...(!conversationMeta.origin.executionControl && conversationMeta.coordination?.phase === 'awaiting_outcome'
77
+ ? { takeoverPhase: 'awaiting_outcome' }
78
+ : {}),
79
+ });
80
+ const status = projected.status;
87
81
  return {
88
82
  sessionId: conversationMeta.sessionId ?? plan.conversationId ?? plan.planId,
89
83
  workspaceId: conversationMeta.workspaceId,
90
84
  title: plan.title,
91
85
  planId: plan.planId,
92
- status: delegationStatus(plan, conversationMeta, projected),
86
+ status,
87
+ // 直接消费同一份决策;这里再改写就等于第二套状态机。
93
88
  actionRight: projected.actionRight,
94
89
  nextAction: projected.nextAction,
95
90
  statusLabel: projected.statusLabel,
91
+ cancelable: projected.cancelable,
92
+ followUp: projected.followUp,
93
+ ...(conversationMeta.executionOwnership ? { executionOwnership: conversationMeta.executionOwnership } : {}),
96
94
  ...(projected.needsYouReason ? { needsYouReason: projected.needsYouReason } : {}),
95
+ ...(conversationMeta.coordination ? { coordination: conversationMeta.coordination } : {}),
97
96
  spawnedAt: conversationMeta.spawnedAt ?? plan.updatedAt ?? '',
98
97
  ...(conversationMeta.conversationId ? { conversationId: conversationMeta.conversationId } : {}),
99
98
  origin: conversationMeta.origin,
99
+ ...(conversationMeta.resourceBlocker ? { resourceBlocker: conversationMeta.resourceBlocker } : {}),
100
+ ...(conversationMeta.executionClaimClosure ? { executionClaimClosure: conversationMeta.executionClaimClosure } : {}),
101
+ ...(conversationMeta.unknownOutcomePolicy ? { unknownOutcomePolicy: conversationMeta.unknownOutcomePolicy } : {}),
102
+ ...(conversationMeta.unknownOutcomeResolution ? { unknownOutcomeResolution: conversationMeta.unknownOutcomeResolution } : {}),
103
+ ...(conversationMeta.retainedUnknowns?.length ? { retainedUnknowns: conversationMeta.retainedUnknowns } : {}),
100
104
  ...(conversationMeta.queuedBehind ? { queuedBehind: conversationMeta.queuedBehind.map(item => ({ ...item })) } : {}),
101
105
  ...(conversationMeta.queueReason ? { queueReason: conversationMeta.queueReason } : {}),
102
106
  ...(conversationMeta.supersededBy ? { supersededBy: conversationMeta.supersededBy } : {}),
@@ -0,0 +1,83 @@
1
+ export interface GitDocumentRevision {
2
+ readonly kind: 'git';
3
+ /** Complete immutable commit SHA only; never a branch or Git expression. */
4
+ readonly commit: string;
5
+ /** Host-confirmed device-local repository binding, not an authorization ticket. */
6
+ readonly repositoryId?: string;
7
+ }
8
+ export interface ConfirmedGitDocumentRevision extends GitDocumentRevision {
9
+ readonly repositoryId: string;
10
+ readonly path: string;
11
+ }
12
+ /** Human-initiated preview only. This reference never grants model/tool access. */
13
+ export interface BotDocumentReference {
14
+ readonly workspaceId: string;
15
+ readonly path: string;
16
+ readonly relativeTo?: string;
17
+ /** Host revalidates Session/GoalPlan ownership on every read; never a root or grant. */
18
+ readonly task?: {
19
+ readonly sessionId: string;
20
+ readonly planId: string;
21
+ };
22
+ /** Explicit UI navigation intent; never an authorization root. */
23
+ readonly kind?: 'file' | 'directory';
24
+ /** Resolve/stat only; never returns file contents. */
25
+ readonly metadataOnly?: boolean;
26
+ /** Conditional text/image read only; an observation never grants access. */
27
+ readonly expectedObservation?: {
28
+ readonly resourceId: string;
29
+ readonly contentVersion?: string;
30
+ };
31
+ readonly revision?: GitDocumentRevision;
32
+ }
33
+ /** Device-local locator identity, revalidated by the host on every access. */
34
+ export interface LocalDocumentIdentity {
35
+ readonly sourceId: string;
36
+ readonly resourceId: string;
37
+ readonly relativePath: string;
38
+ }
39
+ /** Version of the actual bytes returned by a successful read; not a saved snapshot. */
40
+ export interface LocalDocumentObservation extends LocalDocumentIdentity {
41
+ readonly contentVersion: string;
42
+ }
43
+ export interface LocalDocumentReadResult {
44
+ readonly metadataOnly?: boolean;
45
+ readonly ok: boolean;
46
+ readonly status: 'ok' | 'not_found' | 'not_file' | 'too_large' | 'binary' | 'invalid_path' | 'error' | 'permission_denied' | 'scope_denied' | 'ambiguous_path' | 'workspace_unavailable' | 'relative_base_required' | 'version_changed' | 'source_changed' | 'version_unavailable' | 'not_git_repo' | 'invalid_ref' | 'revision_unavailable' | 'unsupported_entry';
47
+ readonly content: string;
48
+ readonly size?: number;
49
+ readonly resolvedFrom?: string;
50
+ readonly resolvedPath?: string;
51
+ readonly identity?: LocalDocumentIdentity;
52
+ readonly observation?: LocalDocumentObservation;
53
+ readonly revision?: ConfirmedGitDocumentRevision;
54
+ /** Confirmed locations for an explicit human choice; never an authorization ticket. */
55
+ readonly candidates?: readonly {
56
+ readonly path: string;
57
+ readonly root: string;
58
+ }[];
59
+ /** Bot project root used when a file citation was not found. Not an authorization root. */
60
+ readonly attemptedRoot?: string;
61
+ readonly error?: string;
62
+ }
63
+ /** Bounded presentation metadata from a known local file Tool Result in the same turn.
64
+ * A restored hint must be re-resolved under the current Bot scope before reading. */
65
+ export interface BotResourceReferenceHint {
66
+ readonly path: string;
67
+ readonly tool: 'read_file' | 'write_file' | 'edit_file';
68
+ }
69
+ /** Human-initiated, bounded filename discovery; every selected hit is re-authorized on read. */
70
+ export interface BotResourceSearchResult {
71
+ readonly ok: boolean;
72
+ readonly status: LocalDocumentReadResult['status'] | 'not_dir';
73
+ readonly scoped?: boolean;
74
+ readonly workspacePath?: string;
75
+ readonly files: readonly {
76
+ readonly relPath: string;
77
+ readonly name: string;
78
+ readonly kind: 'file' | 'directory';
79
+ }[];
80
+ readonly truncated?: boolean;
81
+ readonly visited?: number;
82
+ readonly error?: string;
83
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ import type { BotDocumentReference } from './document-reference.ts';
2
+ import type { InteractiveResultReference } from './interactive-result.ts';
3
+ /** Read-only display facts. A saved operation is not proof that its task completed. */
4
+ export interface EvidenceSourceDescription {
5
+ readonly evidenceRef: string;
6
+ readonly toolName?: string;
7
+ readonly createdAt?: string;
8
+ }
9
+ export interface ProjectAgentEvidenceReadRequest {
10
+ readonly context?: {
11
+ readonly workspaceId: string;
12
+ readonly task?: BotDocumentReference['task'];
13
+ };
14
+ readonly evidenceRef?: string;
15
+ /** Source descriptions only; at most 100 unique references, no body or artifact reads. */
16
+ readonly evidenceRefs?: readonly string[];
17
+ }
18
+ export interface ProjectAgentEvidenceReadResult {
19
+ readonly interactiveAvailability?: 'origin_only';
20
+ readonly deliveryStatus?: 'available' | 'scope_denied' | 'unavailable';
21
+ readonly deliveries?: readonly EvidenceDelivery[];
22
+ readonly ok: boolean;
23
+ readonly code?: string;
24
+ readonly evidenceRef?: string;
25
+ readonly kind?: 'file' | 'command' | 'diff' | 'screenshot' | 'observation';
26
+ readonly summary?: string;
27
+ readonly truncated?: boolean;
28
+ readonly availability?: 'available' | 'metadata_only' | 'not_found' | 'unavailable';
29
+ readonly source?: EvidenceSourceDescription;
30
+ readonly items?: readonly EvidenceSourceDescription[];
31
+ }
32
+ /** Navigation provenance only; revalidated against the canonical index after restore. */
33
+ export interface EvidenceDeliveryBinding {
34
+ readonly evidenceRef: string;
35
+ readonly artifactRef: string;
36
+ }
37
+ export interface EvidenceFileDelivery extends EvidenceDeliveryBinding {
38
+ readonly kind: 'file' | 'code-change' | 'image';
39
+ readonly label: string;
40
+ /** A locator, never a grant or proof of historical bytes. Read through the existing scoped service. */
41
+ readonly reference?: BotDocumentReference;
42
+ readonly savedPreview?: {
43
+ readonly kind: 'diff-summary';
44
+ readonly text: string;
45
+ readonly truncated: true;
46
+ } | {
47
+ readonly kind: 'image';
48
+ readonly dataUrl: string;
49
+ readonly width: number;
50
+ readonly height: number;
51
+ };
52
+ readonly previewUnavailable?: boolean;
53
+ }
54
+ /** A published domain reference. Never a filesystem locator or execution/verification receipt. */
55
+ export interface EvidenceInteractiveDelivery extends EvidenceDeliveryBinding {
56
+ readonly kind: 'interactive';
57
+ readonly label: string;
58
+ readonly interactiveReference: InteractiveResultReference;
59
+ readonly specHash: string;
60
+ readonly reference?: never;
61
+ readonly savedPreview?: never;
62
+ readonly previewUnavailable?: never;
63
+ }
64
+ export type EvidenceDelivery = EvidenceFileDelivery | EvidenceInteractiveDelivery;
@@ -0,0 +1 @@
1
+ export {};