@peer-agent/protocol 0.1.0-rc.10 → 0.1.0-rc.11

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.
@@ -4,8 +4,8 @@
4
4
  */
5
5
  import type { ModelSelectionSnapshot } from './model-routing.ts';
6
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"];
7
+ export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'waiting_agent' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
8
+ export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "waiting_agent", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
9
9
  export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
10
10
  export interface DelegationOrigin {
11
11
  readonly workId?: string;
@@ -82,7 +82,26 @@ export interface SessionReport {
82
82
  readonly verification: 'unverified';
83
83
  };
84
84
  }
85
- export type DelegationEventKind = 'session_spawned' | 'session_progress' | 'session_needs_user' | 'report_available' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
85
+ 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';
86
+ /** Local orchestration facts; never a human authorization or a verified result. */
87
+ export interface AgentMessage {
88
+ readonly replyTo?: string;
89
+ readonly messageId: string;
90
+ readonly workspaceId: string;
91
+ readonly sessionId: string;
92
+ readonly senderConversationId: string;
93
+ readonly recipientConversationId: string;
94
+ readonly direction: 'parent_to_child' | 'child_to_parent';
95
+ readonly purpose: 'update' | 'question' | 'answer';
96
+ readonly text: string;
97
+ readonly at: string;
98
+ }
99
+ export interface AgentActivity {
100
+ readonly eventId: string;
101
+ readonly sessionId: string;
102
+ readonly name: string;
103
+ readonly state: 'queued' | 'started' | 'update' | 'question' | 'answer' | 'reported' | 'verified' | 'ended' | 'cancelled' | 'blocked';
104
+ }
86
105
  export type JsonValue = null | string | number | boolean | readonly JsonValue[] | {
87
106
  readonly [key: string]: JsonValue;
88
107
  };
@@ -1,6 +1,6 @@
1
1
  import { deriveSessionFacts } from "./session-facts.js";
2
2
  import { projectGoalPlan, } from "./task-overview.js";
3
- export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
3
+ export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'waiting_agent', 'verifying',
4
4
  'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
5
5
  function fnv1a(text) {
6
6
  let hash = 0x811c9dc5;
@@ -46,6 +46,7 @@ function delegationStatus(snapshot, meta, projected) {
46
46
  && meta.accepted === undefined && !meta.verifying && !snapshot.runnerStatus),
47
47
  superseded: Boolean(meta.supersededBy), phase: meta.phase,
48
48
  needsUser: snapshot.status === 'awaiting_approval', verificationActive: meta.verifying === true,
49
+ ...(snapshot.agentWaiting ? { blockedReason: 'waiting_parent_agent' } : {}),
49
50
  }).status;
50
51
  }
51
52
  /**
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export type { ProjectWorkReceipt, ProjectWorkState, ProjectTurnEnd } from './work-coordination.ts';
1
+ export type { ProjectWorkReceipt, ProjectWorkRecovery, ProjectWorkState, ProjectTurnEnd } from './work-coordination.ts';
2
2
  export { deriveSessionFacts, type SessionFactSnapshot } from './session-facts.ts';
3
- export { projectAgentFailureKind, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
3
+ export { projectAgentFailureKind, classifyProjectAgentFailure, type ProjectRecoveryFailureKind, type ProviderRequestRecovery, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
4
4
  export type { EvidenceSourceDescription, ProjectAgentEvidenceReadRequest, ProjectAgentEvidenceReadResult } from './evidence-inspection.ts';
5
5
  export { toolActivityPreview, toolActivitySummary } from './tool-activity-preview.ts';
6
6
  export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort, type ModelReasoningEffort } from './model-reasoning.ts';
@@ -743,7 +743,7 @@ export interface PermissionGrant {
743
743
  readonly toolCallId: string;
744
744
  readonly granted: boolean;
745
745
  readonly duration: PermissionDuration;
746
- readonly scope?: string;
746
+ readonly scope?: string | import('./local-image.ts').LocalImagePermissionScope;
747
747
  readonly decidedAt: string;
748
748
  }
749
749
  /** Application-owned shell process snapshot. Source conversation is provenance, not ownership. */
@@ -877,3 +877,4 @@ export * from './project.ts';
877
877
  export * from './objectives.ts';
878
878
  export * from './remote-access-settings.ts';
879
879
  export type { BotModelSelectionUpdateRequest, BotModelSelectionUpdateResult } from './bot-model-selection.ts';
880
+ export * from './local-image.ts';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { deriveSessionFacts } from "./session-facts.js";
2
- export { projectAgentFailureKind } from "./project-agent-failure.js";
2
+ export { projectAgentFailureKind, classifyProjectAgentFailure } from "./project-agent-failure.js";
3
3
  export { toolActivityPreview, toolActivitySummary } from "./tool-activity-preview.js";
4
4
  export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort } from "./model-reasoning.js";
5
5
  export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
@@ -41,3 +41,4 @@ export * from "./model-routing.js";
41
41
  export * from "./project.js";
42
42
  export * from "./objectives.js";
43
43
  export * from "./remote-access-settings.js";
44
+ export * from "./local-image.js";
@@ -0,0 +1,36 @@
1
+ /** ADR 90: local images are factual context, never instructions or persisted pixels. */
2
+ export declare const LOCAL_IMAGE_CAPABILITY: "local.image.read";
3
+ export declare const LOCAL_IMAGE_TOOL: "view_image";
4
+ export declare const LOCAL_IMAGE_MAX_BYTES: number;
5
+ export declare const LOCAL_IMAGE_MAX_PIXELS = 24000000;
6
+ export type LocalImageMediaType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
7
+ export interface LocalImageMetadata {
8
+ path: string;
9
+ mediaType: LocalImageMediaType;
10
+ width: number;
11
+ height: number;
12
+ byteLength: number;
13
+ sha256: string;
14
+ artifactRef: string;
15
+ }
16
+ /** Ephemeral host sideband. Object identity must also be validated by its Provider. */
17
+ export interface LocalImageObservation extends LocalImageMetadata {
18
+ kind: 'local_image';
19
+ dataUrl: string;
20
+ }
21
+ import type { ClientToolResult, PermissionGrant } from './index.ts';
22
+ export interface LocalImagePermissionScope {
23
+ capabilityId: typeof LOCAL_IMAGE_CAPABILITY;
24
+ path: string;
25
+ workspacePath: string | null;
26
+ action: 'read_image_for_model';
27
+ }
28
+ /** Concrete image grant; legacy grant scopes remain unchanged. */
29
+ export interface LocalImagePermissionGrant extends PermissionGrant {
30
+ scope: LocalImagePermissionScope | typeof LOCAL_IMAGE_CAPABILITY;
31
+ }
32
+ export interface LocalImageToolResult extends ClientToolResult {
33
+ modelContext?: {
34
+ visualObservations: readonly LocalImageObservation[];
35
+ };
36
+ }
@@ -0,0 +1,5 @@
1
+ /** ADR 90: local images are factual context, never instructions or persisted pixels. */
2
+ export const LOCAL_IMAGE_CAPABILITY = 'local.image.read';
3
+ export const LOCAL_IMAGE_TOOL = 'view_image';
4
+ export const LOCAL_IMAGE_MAX_BYTES = 8 * 1024 * 1024;
5
+ export const LOCAL_IMAGE_MAX_PIXELS = 24_000_000;
@@ -1,4 +1,21 @@
1
1
  import type { DelegationEvent } from './delegation.ts';
2
+ export type ProjectRecoveryFailureKind = 'response_headers_timeout' | 'network' | 'stream_interrupted' | 'provider_transient' | 'rate_limited' | 'authentication' | 'invalid_request' | 'configuration' | 'permission' | 'budget_exhausted' | 'execution_outcome_unknown' | 'cancelled' | 'fatal';
3
+ /** Produced by the host request boundary; never inferred from assistant prose. */
4
+ export interface ProviderRequestRecovery {
5
+ readonly kind: ProjectRecoveryFailureKind;
6
+ readonly phase?: 'response_headers' | 'stream' | 'request';
7
+ readonly requestId?: string;
8
+ readonly attempts?: number;
9
+ readonly maxAttempts?: number;
10
+ readonly exhausted?: boolean;
11
+ readonly replaySafe?: boolean;
12
+ readonly retryable: boolean;
13
+ }
14
+ /** Legacy diagnostics are admitted only at this seam; structured host failure takes precedence. */
15
+ export declare function classifyProjectAgentFailure(reason: unknown, detail?: unknown): {
16
+ kind: ProjectRecoveryFailureKind;
17
+ retryable: boolean;
18
+ };
2
19
  /** Host failure classification, including the persisted diagnostic prefix used by older cards. */
3
20
  export declare function projectAgentFailureKind(reason: unknown): 'budget_exhausted' | 'unavailable';
4
21
  /** Durable host facts for an explicit retry; never a new user authorization. */
@@ -1,3 +1,39 @@
1
+ const RECOVERABLE = new Set(['response_headers_timeout', 'network', 'stream_interrupted', 'provider_transient', 'rate_limited']);
2
+ const FAILURE_KINDS = new Set([...RECOVERABLE, 'authentication', 'invalid_request', 'configuration', 'permission', 'budget_exhausted', 'execution_outcome_unknown', 'cancelled', 'fatal']);
3
+ /** Legacy diagnostics are admitted only at this seam; structured host failure takes precedence. */
4
+ export function classifyProjectAgentFailure(reason, detail) {
5
+ if (detail && typeof detail === 'object' && 'kind' in detail && FAILURE_KINDS.has(detail.kind)) {
6
+ const kind = detail.kind;
7
+ return { kind, retryable: RECOVERABLE.has(kind) && !('retryable' in detail && detail.retryable === false) };
8
+ }
9
+ const code = typeof reason === 'string' ? reason.trim().replace(/^代理暂时不可用:\s*/, '') : '';
10
+ let kind = 'fatal';
11
+ if (/^(agent_tool_budget_exhausted|agent_loop_exhausted|work_budget_limited)(?:\s*:|$)/.test(code))
12
+ kind = 'budget_exhausted';
13
+ else if (/^(execution_outcome_unknown|checkpoint_persistence_failed)(?:\s*:|$)/.test(code))
14
+ kind = 'execution_outcome_unknown';
15
+ else if (/^(work_execution_stopped|aborted|AbortError|user_stopped)(?:\s*:|$)/i.test(code))
16
+ kind = 'cancelled';
17
+ else if (/^(permission_denied|permission_revoked|authorization_denied)(?:\s*:|$)/i.test(code))
18
+ kind = 'permission';
19
+ else if (/^(connect timeout after|response_headers_timeout)|ConnectTimeoutError/.test(code))
20
+ kind = 'response_headers_timeout';
21
+ else if (/^(provider_stream_idle_timeout|provider_stream_interrupted)(?:\s*:|$)/.test(code))
22
+ kind = 'stream_interrupted';
23
+ else if (/^(HTTP\s*)?(401|403)(?:\s|:|$)|^(authentication_error|invalid_api_key|credential_unavailable)(?:\s*:|$)/i.test(code))
24
+ kind = 'authentication';
25
+ else if (/^(HTTP\s*)?429(?:\s|:|$)/i.test(code))
26
+ kind = 'rate_limited';
27
+ else if (/^(HTTP\s*)?(500|502|503|504)(?:\s|:|$)|^(server_error|server_is_overloaded)(?:\s*:|$)/i.test(code))
28
+ kind = 'provider_transient';
29
+ else if (/^(HTTP\s*)?(400|404|422)(?:\s|:|$)|^(invalid_request|provider_checkpoint_mismatch)(?:\s*:|$)/i.test(code))
30
+ kind = 'invalid_request';
31
+ else if (/^(CERT_|ERR_CERT_|UNABLE_TO_VERIFY|SELF_SIGNED|DEPTH_ZERO_SELF_SIGNED_CERT|provider_not_configured|work_budget_host_unavailable)/i.test(code))
32
+ kind = 'configuration';
33
+ else if (/^(fetch failed|network|ECONNRESET|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|EAI_AGAIN|UND_ERR_(SOCKET|CONNECT_TIMEOUT)|(?:net::)?ERR_(CONNECTION|NETWORK|TIMED_OUT|NAME_NOT_RESOLVED|PROXY_CONNECTION_FAILED|TUNNEL_CONNECTION_FAILED|SOCKS_CONNECTION_FAILED|INTERNET_DISCONNECTED))/i.test(code))
34
+ kind = 'network';
35
+ return { kind, retryable: RECOVERABLE.has(kind) };
36
+ }
1
37
  /** Host failure classification, including the persisted diagnostic prefix used by older cards. */
2
38
  export function projectAgentFailureKind(reason) {
3
39
  if (typeof reason !== 'string')
@@ -7,7 +7,11 @@ export function deriveSessionFacts(input) {
7
7
  status = 'failed';
8
8
  else if (input.accepted)
9
9
  status = 'accepted';
10
- else if (input.needsUser || ['blocked', 'waiting_user'].includes(input.runnerStatus || ''))
10
+ else if (input.needsUser || input.runnerStatus === 'waiting_user')
11
+ status = 'waiting_user';
12
+ else if (input.blockedReason === 'waiting_parent_agent' && input.phase !== 'paused' && !input.superseded && input.runnerStatus !== 'paused')
13
+ status = 'waiting_agent';
14
+ else if (input.runnerStatus === 'blocked')
11
15
  status = 'waiting_user';
12
16
  else if (verificationActive)
13
17
  status = 'verifying';
@@ -246,6 +246,8 @@ export interface GoalPlanProjectionSnapshot {
246
246
  readonly runnerStatus?: GoalRunnerStatus;
247
247
  /** Runner 阻塞是否由系统基础设施持有,而不是用户行动权。 */
248
248
  readonly systemBlocked?: boolean;
249
+ /** A delegated worker is coordinating with its parent, not asking the human. */
250
+ readonly agentWaiting?: boolean;
249
251
  /**
250
252
  * 同一会话此刻是否有前台活流(正在输出 / 调工具 / compact)。
251
253
  * 由聚合层从 listActiveStreams 写入;协议层只认这个布尔事实。
@@ -271,6 +271,9 @@ function decideGoalPlan(snapshot) {
271
271
  }
272
272
  const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
273
273
  const conversationLive = snapshot.conversationLive === true;
274
+ if (snapshot.agentWaiting && runnerStatus !== 'waiting_user' && ['executing', 'completed'].includes(status)) {
275
+ return { actionRight: 'peer_advancing', nextAction: 'none', statusLabel: '等待主 Bot 答复', actionLabel: '' };
276
+ }
274
277
  const recoverableSystemBlocked = runnerStatus === 'blocked'
275
278
  && snapshot.systemBlocked === true;
276
279
  // System infrastructure failures are not user decisions. A foreground turn may
@@ -1,3 +1,15 @@
1
+ import type { ProjectRecoveryFailureKind } from './project-agent-failure.ts';
2
+ /** Local host reservation; neither model text nor a UI timer owns recovery. */
3
+ export interface ProjectWorkRecovery {
4
+ readonly failureKind: ProjectRecoveryFailureKind;
5
+ readonly retryable: boolean;
6
+ readonly autoAttempts: number;
7
+ readonly failedTurnId: string;
8
+ readonly retryAt?: string;
9
+ readonly reservationId?: string;
10
+ readonly deadlineAt?: string;
11
+ readonly blockedCode?: 'RECOVERY_CHECKPOINT_UNAVAILABLE';
12
+ }
1
13
  export type ProjectWorkState = 'runnable' | 'waiting_children' | 'waiting_user' | 'retry_wait' | 'paused' | 'budget_limited' | 'blocked_system' | 'delivered' | 'cancelled';
2
14
  export type ProjectTurnEnd = 'reply_committed' | 'awaiting_children' | 'yielded' | 'awaiting_user' | 'budget_limited' | 'provider_retryable' | 'no_progress' | 'user_stopped' | 'fatal';
3
15
  export interface ProjectWorkReceipt {
@@ -11,6 +23,7 @@ export interface ProjectWorkReceipt {
11
23
  readonly revision: number;
12
24
  readonly checkpointRef?: string;
13
25
  readonly nativeCheckpointRef?: string;
26
+ readonly recovery?: ProjectWorkRecovery;
14
27
  readonly end?: ProjectTurnEnd;
15
28
  readonly attemptId?: string;
16
29
  readonly pendingEventIds?: readonly string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.1.0-rc.10",
3
+ "version": "0.1.0-rc.11",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",