@peer-agent/protocol 0.1.0-rc.7 → 0.1.0-rc.8

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.
@@ -1,4 +1,4 @@
1
- import type { GoalCriterionResult, GoalManualConfirmation, GoalSuccessCriterion } from './goal.ts';
1
+ import type { GoalCriterionResult, GoalManualConfirmation, GoalSuccessCriterion, GoalModelReview } from './goal.ts';
2
2
  export declare const ACCEPTANCE_CLOSE_GATE_CODE = "acceptance_evidence_incomplete";
3
3
  export type AcceptanceCloseGapReason = 'missing' | 'failed' | 'unresolved';
4
4
  export interface AcceptanceCloseGap {
@@ -17,6 +17,15 @@ export interface AcceptanceCloseTaskLike {
17
17
  }
18
18
  export interface AcceptanceClosePlanLike {
19
19
  readonly successCriteria?: readonly GoalSuccessCriterion[] | null;
20
+ /** Current content revision derived by the host store, never admitted from a model patch. */
21
+ readonly modelReviewSourceRevision?: string;
22
+ readonly modelReviews?: readonly GoalModelReview[];
23
+ readonly runner?: {
24
+ readonly verifierRuns?: readonly {
25
+ readonly verifierRunId: string;
26
+ readonly status: string;
27
+ }[];
28
+ };
20
29
  readonly criterionResults?: readonly GoalCriterionResult[] | null;
21
30
  readonly manualConfirmations?: readonly GoalManualConfirmation[] | null;
22
31
  readonly evidenceRefs?: readonly string[] | null;
@@ -85,6 +85,18 @@ export function evaluateAcceptanceCloseGate(plan, options = {}) {
85
85
  const description = criterion.description?.trim() || id;
86
86
  const isAuto = AUTO_CRITERION_KINDS.has(criterion.kind);
87
87
  const result = results.get(id) ?? null;
88
+ if (criterion.kind === 'model_review') {
89
+ const review = plan?.modelReviews?.slice().reverse().find(row => row.criterionId === id);
90
+ const current = review && plan?.modelReviewSourceRevision && review.sourceRevision === plan.modelReviewSourceRevision;
91
+ const verified = current && plan?.runner?.verifierRuns?.some(run => run.verifierRunId === review.verifierRunId && run.status === 'passed');
92
+ if (!current || !verified)
93
+ gaps.push({ criterionId: id, description, reason: 'missing' });
94
+ else if (!review.passed)
95
+ gaps.push({ criterionId: id, description, reason: 'failed' });
96
+ else if (!review.evidenceRefs.length || !review.evidenceRefs.every(ref => known.has(ref)))
97
+ gaps.push({ criterionId: id, description, reason: 'unresolved' });
98
+ continue;
99
+ }
88
100
  if (!isAuto && latestManualApproval(plan ?? {}, id))
89
101
  continue;
90
102
  if (!result) {
@@ -0,0 +1,13 @@
1
+ import type { BotProfile } from './project.ts';
2
+ import type { ModelReasoningEffort } from './model-reasoning.ts';
3
+ /** A user choice for the Bot's future replies; never a per-input runtime override. */
4
+ export interface BotModelSelectionUpdateRequest {
5
+ readonly workspaceId: string;
6
+ readonly modelProviderId: string;
7
+ readonly reasoningEffort?: ModelReasoningEffort;
8
+ }
9
+ export interface BotModelSelectionUpdateResult {
10
+ readonly ok: boolean;
11
+ readonly code?: string;
12
+ readonly profile?: BotProfile;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -8,6 +8,7 @@ export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | '
8
8
  export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
9
9
  export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
10
10
  export interface DelegationOrigin {
11
+ readonly workId?: string;
11
12
  readonly anchorMessageId: string;
12
13
  readonly inputId: string;
13
14
  readonly surface: InputSurface;
@@ -66,14 +67,22 @@ export interface SessionReport {
66
67
  readonly planId: string | null;
67
68
  readonly status: WorkSessionStatus;
68
69
  readonly summary: string;
70
+ readonly taskBrief?: string;
69
71
  readonly keyFindings: readonly string[];
70
72
  readonly changedFiles: readonly {
71
73
  readonly path: string;
72
74
  readonly summary: string;
73
75
  }[];
74
76
  readonly evidenceRefs: readonly string[];
77
+ /** Persisted worker output is a claim; verification still comes from host Evidence. */
78
+ readonly contentSource?: {
79
+ readonly kind: 'worker_message' | 'task_results';
80
+ readonly conversationId?: string;
81
+ readonly messageId?: string;
82
+ readonly verification: 'unverified';
83
+ };
75
84
  }
76
- export type DelegationEventKind = 'session_spawned' | 'session_progress' | 'session_needs_user' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
85
+ export type DelegationEventKind = 'session_spawned' | 'session_progress' | 'session_needs_user' | 'report_available' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
77
86
  export type JsonValue = null | string | number | boolean | readonly JsonValue[] | {
78
87
  readonly [key: string]: JsonValue;
79
88
  };
@@ -101,6 +110,7 @@ export interface AgentReplyMeta {
101
110
  readonly surfacing: 'interrupt' | 'message' | 'digest' | 'silent';
102
111
  }
103
112
  export interface ReplySessionState {
113
+ readonly sourceRevision?: string;
104
114
  readonly sessionId: string;
105
115
  readonly status: WorkSessionStatus;
106
116
  }
@@ -155,6 +165,26 @@ export interface DispositionEvent {
155
165
  readonly replyMessageId?: string;
156
166
  }
157
167
  export type VerificationOutcome = 'passed' | 'failed' | 'partial' | 'unverifiable';
168
+ /** Host-bound manual completion review; distinct from acceptance of a completed result. */
169
+ export interface SessionCompletionReview {
170
+ readonly sessionId: string;
171
+ readonly reviewToken: string;
172
+ readonly criteria: readonly {
173
+ readonly id: string;
174
+ readonly description: string;
175
+ }[];
176
+ readonly report: string;
177
+ readonly confirmed?: boolean;
178
+ }
179
+ export type SessionConfirmationInput = {
180
+ readonly workspaceId: string;
181
+ readonly sessionId: string;
182
+ } & ({
183
+ readonly stage?: 'result_acceptance';
184
+ } | {
185
+ readonly stage: 'manual_completion';
186
+ readonly reviewToken: string;
187
+ });
158
188
  export type IndependentVerifierState = 'passed' | 'failed' | 'not_required' | 'missing';
159
189
  export interface VerificationCheck {
160
190
  readonly name: string;
@@ -1,7 +1,4 @@
1
- /**
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.
4
- */
1
+ import { deriveSessionFacts } from "./session-facts.js";
5
2
  import { projectGoalPlan, } from "./task-overview.js";
6
3
  export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
7
4
  'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
@@ -44,38 +41,12 @@ export function createDelegationEvent(input) {
44
41
  };
45
42
  }
46
43
  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';
44
+ return deriveSessionFacts({ status: snapshot.status, runnerStatus: snapshot.runnerStatus,
45
+ accepted: meta.accepted === true || (snapshot.status === 'completed' && meta.acceptance !== 'confirm'
46
+ && meta.accepted === undefined && !meta.verifying && !snapshot.runnerStatus),
47
+ superseded: Boolean(meta.supersededBy), phase: meta.phase,
48
+ needsUser: snapshot.status === 'awaiting_approval', verificationActive: meta.verifying === true,
49
+ }).status;
79
50
  }
80
51
  /**
81
52
  * Project a GoalPlan snapshot into a work session.
@@ -0,0 +1,22 @@
1
+ /** Read-only display facts. A saved operation is not proof that its task completed. */
2
+ export interface EvidenceSourceDescription {
3
+ readonly evidenceRef: string;
4
+ readonly toolName?: string;
5
+ readonly createdAt?: string;
6
+ }
7
+ export interface ProjectAgentEvidenceReadRequest {
8
+ readonly evidenceRef?: string;
9
+ /** Source descriptions only; at most 100 unique references, no body or artifact reads. */
10
+ readonly evidenceRefs?: readonly string[];
11
+ }
12
+ export interface ProjectAgentEvidenceReadResult {
13
+ readonly ok: boolean;
14
+ readonly code?: string;
15
+ readonly evidenceRef?: string;
16
+ readonly kind?: 'file' | 'command' | 'diff' | 'screenshot' | 'observation';
17
+ readonly summary?: string;
18
+ readonly truncated?: boolean;
19
+ readonly availability?: 'available' | 'metadata_only' | 'not_found' | 'unavailable';
20
+ readonly source?: EvidenceSourceDescription;
21
+ readonly items?: readonly EvidenceSourceDescription[];
22
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/goal.d.ts CHANGED
@@ -444,7 +444,7 @@ export interface GoalRunTrace {
444
444
  readonly lastCheckpointNodeId?: string;
445
445
  readonly events: readonly GoalRunEvent[];
446
446
  }
447
- export type GoalSuccessCriterionKind = 'command' | 'test' | 'file-contains' | 'file-exists' | 'manual';
447
+ export type GoalSuccessCriterionKind = 'command' | 'test' | 'file-contains' | 'file-exists' | 'model_review' | 'manual';
448
448
  export interface GoalSuccessCriterion {
449
449
  readonly id: string;
450
450
  readonly kind: GoalSuccessCriterionKind;
@@ -452,6 +452,21 @@ export interface GoalSuccessCriterion {
452
452
  readonly command?: string;
453
453
  readonly path?: string;
454
454
  readonly expect?: string;
455
+ readonly authority?: {
456
+ readonly source: 'model' | 'user' | 'project_policy' | 'legacy_unknown';
457
+ readonly sourceRef?: string;
458
+ readonly version: number;
459
+ readonly verifier: 'mechanical' | 'host_model' | 'human';
460
+ readonly rationale: string;
461
+ };
462
+ }
463
+ export interface GoalModelReview {
464
+ readonly criterionId: string;
465
+ readonly sourceRevision: string;
466
+ readonly verifierRunId: string;
467
+ readonly passed: boolean;
468
+ readonly evidenceRefs: readonly string[];
469
+ readonly checkedAt: string;
455
470
  }
456
471
  export interface GoalCriterionResult {
457
472
  readonly criterionId: string;
@@ -678,6 +693,9 @@ export interface GoalPlan {
678
693
  readonly successCriteria: readonly GoalSuccessCriterion[];
679
694
  readonly criterionResults: readonly GoalCriterionResult[];
680
695
  readonly manualConfirmations?: readonly GoalManualConfirmation[];
696
+ readonly modelReviews?: readonly GoalModelReview[];
697
+ /** Host-derived current revision for checking semantic review freshness. */
698
+ readonly modelReviewSourceRevision?: string;
681
699
  readonly boundaries: GoalBoundaries;
682
700
  readonly exceptionPolicies: ExceptionPolicy[];
683
701
  /** 顶层汇总(来源于子任务) */
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export type { ProjectWorkReceipt, ProjectWorkState, ProjectTurnEnd } from './work-coordination.ts';
2
+ export { deriveSessionFacts, type SessionFactSnapshot } from './session-facts.ts';
3
+ export { projectAgentFailureKind, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
4
+ export type { EvidenceSourceDescription, ProjectAgentEvidenceReadRequest, ProjectAgentEvidenceReadResult } from './evidence-inspection.ts';
1
5
  export { toolActivityPreview, toolActivitySummary } from './tool-activity-preview.ts';
2
6
  export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort, type ModelReasoningEffort } from './model-reasoning.ts';
3
7
  export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead } from './selection-reference.ts';
@@ -872,3 +876,4 @@ export * from './model-routing.ts';
872
876
  export * from './project.ts';
873
877
  export * from './objectives.ts';
874
878
  export * from './remote-access-settings.ts';
879
+ export type { BotModelSelectionUpdateRequest, BotModelSelectionUpdateResult } from './bot-model-selection.ts';
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export { deriveSessionFacts } from "./session-facts.js";
2
+ export { projectAgentFailureKind } from "./project-agent-failure.js";
1
3
  export { toolActivityPreview, toolActivitySummary } from "./tool-activity-preview.js";
2
4
  export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort } from "./model-reasoning.js";
3
5
  export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
@@ -0,0 +1,13 @@
1
+ import type { DelegationEvent } from './delegation.ts';
2
+ /** Host failure classification, including the persisted diagnostic prefix used by older cards. */
3
+ export declare function projectAgentFailureKind(reason: unknown): 'budget_exhausted' | 'unavailable';
4
+ /** Durable host facts for an explicit retry; never a new user authorization. */
5
+ export interface ProjectAgentTurnRecovery {
6
+ readonly events: readonly DelegationEvent[];
7
+ readonly throughSeq: number;
8
+ }
9
+ /** Factual recovery data returned by post_reply after anchor validation fails. */
10
+ export interface ReplyAnchorCandidate {
11
+ readonly messageId: string;
12
+ readonly text: string;
13
+ }
@@ -0,0 +1,8 @@
1
+ /** Host failure classification, including the persisted diagnostic prefix used by older cards. */
2
+ export function projectAgentFailureKind(reason) {
3
+ if (typeof reason !== 'string')
4
+ return 'unavailable';
5
+ const code = reason.trim().replace(/^代理暂时不可用:\s*/, '');
6
+ return /^(agent_tool_budget_exhausted|agent_loop_exhausted|work_budget_limited)(?:\s*:|$)/.test(code)
7
+ ? 'budget_exhausted' : 'unavailable';
8
+ }
package/dist/project.d.ts CHANGED
@@ -207,7 +207,15 @@ export interface ProjectAgentToolActivity {
207
207
  readonly result?: ProjectAgentToolPreview;
208
208
  readonly receivedChars?: number;
209
209
  }
210
- /** Ephemeral user-turn presentation. No hidden reasoning or Evidence. */
210
+ /** Public conversation update, never hidden reasoning, Tool Result or Evidence.
211
+ * User agent_turn records may persist these as publicUpdates (100 / 32000 chars).
212
+ * Legacy rounds[].text is not a public-update source.
213
+ */
214
+ export interface ProjectAgentPublicUpdate {
215
+ readonly id: string;
216
+ readonly text: string;
217
+ }
218
+ /** Ephemeral interactive-turn presentation, including explicit wake retries. No hidden reasoning or Evidence. */
211
219
  export interface ProjectAgentActivity {
212
220
  readonly workspaceId: string;
213
221
  readonly conversationId: string;
@@ -219,11 +227,9 @@ export interface ProjectAgentActivity {
219
227
  readonly replyTo: readonly string[];
220
228
  readonly phase: 'waiting' | 'thinking' | 'responding' | 'tool' | 'settling' | 'done' | 'error' | 'stopped' | 'disposed';
221
229
  readonly replyText: string;
222
- readonly segments: readonly ({
230
+ readonly segments: readonly (({
223
231
  readonly kind: 'text';
224
- readonly id: string;
225
- readonly text: string;
226
- } | ProjectAgentToolActivity)[];
232
+ } & ProjectAgentPublicUpdate) | ProjectAgentToolActivity)[];
227
233
  }
228
234
  export interface ProjectAgentStopResponseRequest {
229
235
  readonly workspaceId: string;
@@ -0,0 +1,17 @@
1
+ import type { WorkSessionStatus } from './delegation.ts';
2
+ export interface SessionFactSnapshot {
3
+ readonly status: WorkSessionStatus;
4
+ readonly verificationActive: boolean;
5
+ readonly needsUser: boolean;
6
+ readonly blockedReason?: string;
7
+ }
8
+ export declare function deriveSessionFacts(input: {
9
+ status?: string;
10
+ phase?: string;
11
+ runnerStatus?: string;
12
+ accepted?: boolean;
13
+ superseded?: boolean;
14
+ needsUser?: boolean;
15
+ blockedReason?: string;
16
+ verificationActive?: boolean;
17
+ }): SessionFactSnapshot;
@@ -0,0 +1,30 @@
1
+ export function deriveSessionFacts(input) {
2
+ const verificationActive = input.verificationActive === true;
3
+ let status;
4
+ if (input.status === 'cancelled')
5
+ status = 'cancelled';
6
+ else if (input.status === 'failed')
7
+ status = 'failed';
8
+ else if (input.accepted)
9
+ status = 'accepted';
10
+ else if (input.needsUser || ['blocked', 'waiting_user'].includes(input.runnerStatus || ''))
11
+ status = 'waiting_user';
12
+ else if (verificationActive)
13
+ status = 'verifying';
14
+ else if (input.status === 'completed' && ['running', 'starting', 'waiting_provider', 'resuming_after_compaction'].includes(input.runnerStatus || ''))
15
+ status = 'running';
16
+ else if (input.status === 'completed')
17
+ status = 'result_ready';
18
+ else if (input.superseded)
19
+ status = 'superseded';
20
+ else if (input.phase === 'paused')
21
+ status = 'paused';
22
+ else if (input.phase === 'starting')
23
+ status = 'starting';
24
+ else if (['approved', 'accepted', 'paused', 'interrupted'].includes(input.status || '') || input.phase === 'queued')
25
+ status = 'queued';
26
+ else
27
+ status = 'running';
28
+ return { status, verificationActive: status === 'verifying', needsUser: status === 'waiting_user',
29
+ ...(input.blockedReason ? { blockedReason: input.blockedReason } : {}) };
30
+ }
@@ -0,0 +1,58 @@
1
+ export type ProjectWorkState = 'runnable' | 'waiting_children' | 'waiting_user' | 'retry_wait' | 'paused' | 'budget_limited' | 'blocked_system' | 'delivered' | 'cancelled';
2
+ export type ProjectTurnEnd = 'reply_committed' | 'awaiting_children' | 'yielded' | 'awaiting_user' | 'budget_limited' | 'provider_retryable' | 'no_progress' | 'user_stopped' | 'fatal';
3
+ export interface ProjectWorkReceipt {
4
+ readonly schemaVersion: 1;
5
+ readonly workId: string;
6
+ readonly workspaceId: string;
7
+ readonly parentConversationId: string;
8
+ readonly anchorInputIds: readonly string[];
9
+ readonly sessionIds: readonly string[];
10
+ readonly state: ProjectWorkState;
11
+ readonly revision: number;
12
+ readonly checkpointRef?: string;
13
+ readonly nativeCheckpointRef?: string;
14
+ readonly end?: ProjectTurnEnd;
15
+ readonly attemptId?: string;
16
+ readonly pendingEventIds?: readonly string[];
17
+ readonly waitFor: readonly {
18
+ readonly kind: 'session' | 'approval' | 'question' | 'retry_timer';
19
+ readonly id: string;
20
+ }[];
21
+ readonly consumedEventIds: readonly string[];
22
+ readonly pendingResultRefs: readonly string[];
23
+ readonly lastDeliveredFactKey?: string;
24
+ readonly budgetRef?: string;
25
+ readonly budget?: {
26
+ readonly modelRequests: number;
27
+ readonly toolCalls: number;
28
+ readonly tokens: number;
29
+ readonly costUsd: number;
30
+ readonly unknownUsage: boolean;
31
+ readonly unknownCost: boolean;
32
+ readonly limits: {
33
+ readonly maxModelRequests: number;
34
+ readonly maxToolCalls: number;
35
+ readonly maxTokens?: number;
36
+ readonly maxCostUsd?: number;
37
+ readonly source: string;
38
+ };
39
+ readonly attempts: Readonly<Record<string, {
40
+ readonly role: string;
41
+ readonly requests?: number;
42
+ readonly modelProviderId?: string;
43
+ readonly checkpointRef?: string;
44
+ readonly pendingTools?: readonly {
45
+ readonly toolCallId: string | null;
46
+ readonly capabilityId: string | null;
47
+ }[];
48
+ }>>;
49
+ readonly uncertainDispatches?: readonly {
50
+ readonly attemptId: string;
51
+ readonly role: string;
52
+ readonly toolCallId: string | null;
53
+ readonly capabilityId: string | null;
54
+ }[];
55
+ };
56
+ readonly stopScope: 'reply' | 'work';
57
+ readonly updatedAt: string;
58
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.1.0-rc.7",
3
+ "version": "0.1.0-rc.8",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",