@peer-agent/protocol 0.1.0-rc.30 → 0.1.0-rc.33

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,8 +1,11 @@
1
1
  /** Coordination authority is issued by the local host, never by model arguments. */
2
+ export type { ReplyDeliveryReceipt, IntentReplyBinding, ReplyGoalScope } from './reply-delivery.ts';
3
+ export type { InputDispositionKind, InputDisposition, IntentRequirement, IntentInterpretation, GoalCoverageItem, WorkDisposition, IntentAssessment, IntentCoordination, IntentClosureRequest, IntentDecisionReceipt, IntentCoordinationRequest, CoordinationDecisionFrame, ProgressObservation } from './intent-coordination.ts';
2
4
  export type CoordinationAction = 'parallel' | 'augment' | 'revise' | 'query' | 'answer' | 'cancel' | 'replace' | 'handoff' | 'resume';
3
5
  export type CoordinationLifecycle = 'active' | 'paused' | 'cancelled' | 'fulfilled';
4
6
  export interface CoordinationMandate {
5
7
  schemaVersion: 1;
8
+ intentSchemaVersion?: 1;
6
9
  mandateId: string;
7
10
  workId: string;
8
11
  workspaceId: string;
@@ -25,6 +28,7 @@ export interface CoordinationDecision {
25
28
  expectedRevision: number;
26
29
  action: CoordinationAction;
27
30
  sourceInputIds: string[];
31
+ sourceDecisionRef?: string;
28
32
  sourceEventIds: string[];
29
33
  sessionId?: string;
30
34
  reason: string;
@@ -52,6 +56,7 @@ export interface TaskTransition {
52
56
  executionEffect?: 'pending' | 'applied' | 'unknown' | 'rejected';
53
57
  executionAttemptRef?: string;
54
58
  reconciliationRef?: string;
59
+ controlOperationRef?: string;
55
60
  updatedAt: string;
56
61
  }
57
62
  export interface CoordinationExecutionBinding {
@@ -9,9 +9,12 @@ export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "start
9
9
  export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
10
10
  export interface DelegationOrigin {
11
11
  readonly capabilityAdmission?: import('./capability-admission.ts').DelegationCapabilityAdmission;
12
+ readonly executionGeneration?: string;
13
+ readonly executionControl?: import('./session-control.ts').SessionControlOperation;
12
14
  readonly takeover?: {
13
15
  operationId: string;
14
- phase: 'stopping' | 'completed';
16
+ phase: 'stopping' | 'completed' | 'superseded' | 'rejected';
17
+ supersededBy?: string;
15
18
  text: string;
16
19
  binding: import('./delegation-coordination.ts').CoordinationExecutionBinding;
17
20
  requestedAt: string;
@@ -60,11 +63,12 @@ export interface DelegationOrigin {
60
63
  readonly depth: number;
61
64
  }
62
65
  export interface SessionQueueFacts {
66
+ readonly resourceBlocker?: import('./session-control.ts').ExecutionResourceBlocker;
63
67
  readonly queuedBehind?: readonly {
64
68
  readonly sessionId: string;
65
69
  readonly title: string;
66
70
  }[];
67
- readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | null;
71
+ readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | 'resource_protection' | 'resource_recovery' | null;
68
72
  }
69
73
  export interface WorkSessionConversationMeta extends SessionQueueFacts {
70
74
  readonly coordination?: import('./delegation-coordination.ts').CoordinationSessionFacts;
@@ -2,6 +2,7 @@
2
2
  * Project-agent delegation contracts. Pure projections only; nothing here runs a tool.
3
3
  * The user-visible conclusion of a work session is `decideLifecycle`'s conclusion.
4
4
  */
5
+ import { controlPhasesForOrigin } from "./session-control.js";
5
6
  import { decideLifecycle, } from "./task-overview.js";
6
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'];
@@ -69,15 +70,11 @@ export function projectWorkSession(plan, conversationMeta) {
69
70
  blockedReason: plan.agentWaiting ? 'waiting_parent_agent' : plan.blockedReason,
70
71
  interrupted: plan.interrupted,
71
72
  interruptionOrigin: plan.interruptionOrigin,
72
- ...(conversationMeta.origin.cancellation?.phase
73
- ? { cancellationPhase: conversationMeta.origin.cancellation.phase }
74
- : {}),
73
+ ...controlPhasesForOrigin(conversationMeta.origin),
75
74
  ...(conversationMeta.origin.cancellation?.disposition ? { cancellationDisposition: conversationMeta.origin.cancellation.disposition } : {}),
76
- ...(conversationMeta.coordination?.phase === 'awaiting_outcome'
75
+ ...(!conversationMeta.origin.executionControl && conversationMeta.coordination?.phase === 'awaiting_outcome'
77
76
  ? { takeoverPhase: 'awaiting_outcome' }
78
- : conversationMeta.origin.takeover?.phase
79
- ? { takeoverPhase: conversationMeta.origin.takeover.phase }
80
- : {}),
77
+ : {}),
81
78
  });
82
79
  const status = projected.status;
83
80
  return {
@@ -97,6 +94,7 @@ export function projectWorkSession(plan, conversationMeta) {
97
94
  spawnedAt: conversationMeta.spawnedAt ?? plan.updatedAt ?? '',
98
95
  ...(conversationMeta.conversationId ? { conversationId: conversationMeta.conversationId } : {}),
99
96
  origin: conversationMeta.origin,
97
+ ...(conversationMeta.resourceBlocker ? { resourceBlocker: conversationMeta.resourceBlocker } : {}),
100
98
  ...(conversationMeta.queuedBehind ? { queuedBehind: conversationMeta.queuedBehind.map(item => ({ ...item })) } : {}),
101
99
  ...(conversationMeta.queueReason ? { queueReason: conversationMeta.queueReason } : {}),
102
100
  ...(conversationMeta.supersededBy ? { supersededBy: conversationMeta.supersededBy } : {}),
@@ -56,6 +56,8 @@ export interface LocalDocumentReadResult {
56
56
  readonly path: string;
57
57
  readonly root: string;
58
58
  }[];
59
+ /** Bot project root used when a file citation was not found. Not an authorization root. */
60
+ readonly attemptedRoot?: string;
59
61
  readonly error?: string;
60
62
  }
61
63
  /** Bounded presentation metadata from a known local file Tool Result in the same turn.
package/dist/index.d.ts CHANGED
@@ -911,3 +911,6 @@ export * from './resource-edit.ts';
911
911
  export * from './resource-file-replace.ts';
912
912
  export * from './resource-edit-execution.ts';
913
913
  export { decideFollowUp, type FollowUpOwner, type FollowUpReason, type FollowUpProjection } from './task-overview.ts';
914
+ export type { SessionExecutionIdentity, StopBarrierReceipt, SessionControlOperation, ExecutionResourceBlocker, ExecutionResourceClaim, ExecutionResourceScope } from './session-control.ts';
915
+ export { controlPhasesForOrigin } from './session-control.ts';
916
+ export * from './input-prediction.ts';
package/dist/index.js CHANGED
@@ -56,3 +56,5 @@ export * from "./resource-edit.js";
56
56
  export * from "./resource-file-replace.js";
57
57
  export * from "./resource-edit-execution.js";
58
58
  export { decideFollowUp } from "./task-overview.js";
59
+ export { controlPhasesForOrigin } from "./session-control.js";
60
+ export * from "./input-prediction.js";
@@ -0,0 +1,86 @@
1
+ /** Suggestions are ephemeral presentation data, never input receipts or grants. */
2
+ export type InputPredictionMode = 'next_turn' | 'continuation';
3
+ export type InputPredictionSurface = 'desktop_bot' | 'desktop_classic';
4
+ export interface InputPredictionSettings {
5
+ readonly schemaVersion: 1;
6
+ readonly enabled: boolean;
7
+ readonly continuationEnabled: boolean;
8
+ readonly disabledWorkspaceIds: readonly string[];
9
+ readonly dailyRequestLimit: number;
10
+ readonly dailyTokenLimit: number;
11
+ }
12
+ export declare const INPUT_PREDICTION_LIMITS: Readonly<{
13
+ inputTokens: 4096;
14
+ outputTokens: 128;
15
+ draftLength: 2048;
16
+ candidateLength: 240;
17
+ candidateGraphemes: 120;
18
+ timeoutMs: 2000;
19
+ validationMs: 150;
20
+ ttlMs: 60000;
21
+ requestIntervalMs: 3000;
22
+ requestsPerMinute: 12;
23
+ }>;
24
+ export declare function normalizeInputPredictionSettings(value: unknown): InputPredictionSettings;
25
+ export interface InputPredictionRequest {
26
+ readonly requestId: string;
27
+ readonly workspaceId: string;
28
+ readonly conversationId: string;
29
+ readonly composerInstanceId: string;
30
+ readonly surface: InputPredictionSurface;
31
+ readonly mode: InputPredictionMode;
32
+ readonly draftVersion: number;
33
+ readonly draftText: string;
34
+ readonly selectionStart: number;
35
+ readonly selectionEnd: number;
36
+ readonly quoteMessageId?: string;
37
+ }
38
+ export interface InputCandidate {
39
+ readonly candidateId: string;
40
+ readonly requestId: string;
41
+ readonly workspaceId: string;
42
+ readonly conversationId: string;
43
+ readonly composerInstanceId: string;
44
+ readonly mode: InputPredictionMode;
45
+ readonly insertionText: string;
46
+ readonly draftVersion: number;
47
+ /** Host context identity only. This conveys no permission. */
48
+ readonly contextToken: string;
49
+ readonly expiresAt: string;
50
+ }
51
+ export type InputPredictionResult = {
52
+ readonly kind: 'candidate';
53
+ readonly candidate: InputCandidate;
54
+ } | {
55
+ readonly kind: 'none';
56
+ readonly reason: string;
57
+ } | {
58
+ readonly kind: 'unavailable';
59
+ readonly reason: string;
60
+ } | {
61
+ readonly kind: 'cancelled';
62
+ } | {
63
+ readonly kind: 'error';
64
+ readonly code: string;
65
+ };
66
+ export interface InputPredictionReference {
67
+ readonly composerInstanceId: string;
68
+ readonly requestId: string;
69
+ readonly candidateId?: string;
70
+ }
71
+ export type InputPredictionValidation = {
72
+ readonly kind: 'valid' | 'stale' | 'expired' | 'unavailable';
73
+ };
74
+ export interface InputPredictionPort {
75
+ request(request: InputPredictionRequest): Promise<InputPredictionResult>;
76
+ cancel(reference: InputPredictionReference): Promise<unknown>;
77
+ validate(reference: InputPredictionReference): Promise<InputPredictionValidation>;
78
+ }
79
+ export interface InputPredictionStatus {
80
+ readonly reason: 'ready' | 'disabled' | 'model_unconfigured' | 'budget' | 'usage_unavailable' | 'provider_error';
81
+ readonly requests: number;
82
+ readonly tokens: number;
83
+ readonly estimated: boolean;
84
+ }
85
+ export declare function isInputPredictionRequest(value: unknown): value is InputPredictionRequest;
86
+ export declare function isInputPredictionReference(value: unknown): value is InputPredictionReference;
@@ -0,0 +1,48 @@
1
+ export const INPUT_PREDICTION_LIMITS = Object.freeze({
2
+ inputTokens: 4096, outputTokens: 128, draftLength: 2048,
3
+ candidateLength: 240, candidateGraphemes: 120,
4
+ timeoutMs: 2000, validationMs: 150, ttlMs: 60_000,
5
+ requestIntervalMs: 3000, requestsPerMinute: 12,
6
+ });
7
+ export function normalizeInputPredictionSettings(value) {
8
+ const raw = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
9
+ const supported = (value == null || value === raw)
10
+ && (raw.schemaVersion === undefined || raw.schemaVersion === 1);
11
+ const input = supported ? raw : {};
12
+ const enabled = supported && (input.enabled === undefined || input.enabled === true);
13
+ const limit = (value, fallback) => typeof value === 'number'
14
+ && Number.isSafeInteger(value) && value >= 0 ? value : fallback;
15
+ return {
16
+ schemaVersion: 1,
17
+ enabled,
18
+ // Preserve an existing explicit refusal until the user enables or selects a model again.
19
+ continuationEnabled: enabled && (input.continuationEnabled === undefined || input.continuationEnabled === true),
20
+ disabledWorkspaceIds: Array.isArray(input.disabledWorkspaceIds)
21
+ ? [...new Set(input.disabledWorkspaceIds.filter((id) => typeof id === 'string' && id.length > 0 && id.length <= 200))] : [],
22
+ dailyRequestLimit: limit(input.dailyRequestLimit, 100),
23
+ dailyTokenLimit: limit(input.dailyTokenLimit, 100_000),
24
+ };
25
+ }
26
+ export function isInputPredictionRequest(value) {
27
+ if (!value || typeof value !== 'object')
28
+ return false;
29
+ const row = value;
30
+ const id = (key) => typeof row[key] === 'string' && row[key].length > 0 && row[key].length <= 200;
31
+ return ['requestId', 'workspaceId', 'conversationId', 'composerInstanceId'].every(id)
32
+ && ['desktop_bot', 'desktop_classic'].includes(String(row.surface))
33
+ && ['next_turn', 'continuation'].includes(String(row.mode))
34
+ && Number.isSafeInteger(row.draftVersion) && Number(row.draftVersion) >= 0
35
+ && typeof row.draftText === 'string' && row.draftText.length <= INPUT_PREDICTION_LIMITS.draftLength
36
+ && Number.isSafeInteger(row.selectionStart) && Number.isSafeInteger(row.selectionEnd)
37
+ && Number(row.selectionStart) >= 0 && Number(row.selectionStart) === Number(row.selectionEnd)
38
+ && Number(row.selectionEnd) === row.draftText.length
39
+ && (row.mode === 'next_turn' ? row.draftText === '' : row.draftText.length > 0)
40
+ && (row.quoteMessageId === undefined || id('quoteMessageId'));
41
+ }
42
+ export function isInputPredictionReference(value) {
43
+ if (!value || typeof value !== 'object')
44
+ return false;
45
+ const row = value;
46
+ return ['composerInstanceId', 'requestId'].every(key => typeof row[key] === 'string' && row[key].length > 0 && row[key].length <= 200)
47
+ && (row.candidateId === undefined || typeof row.candidateId === 'string' && row.candidateId.length > 0 && row.candidateId.length <= 200);
48
+ }
@@ -0,0 +1,199 @@
1
+ /** ADR 117: model interpretations are continuity facts, never permissions or task acceptance. */
2
+ export type InputDispositionKind = 'discuss' | 'answer' | 'delegate' | 'augment' | 'revise' | 'withdraw';
3
+ export interface InputDisposition {
4
+ readonly inputId: string;
5
+ readonly kind: InputDispositionKind;
6
+ readonly reason: string;
7
+ }
8
+ export interface IntentRequirement {
9
+ readonly requirementId: string;
10
+ readonly text: string;
11
+ readonly sourceInputIds: readonly string[];
12
+ }
13
+ export interface IntentInterpretation {
14
+ readonly outcome: string;
15
+ readonly constraints: readonly string[];
16
+ readonly nonGoals: readonly string[];
17
+ readonly openQuestions: readonly string[];
18
+ readonly requirements: readonly IntentRequirement[];
19
+ }
20
+ export interface GoalCoverageItem {
21
+ readonly requirementId: string;
22
+ readonly status: 'remaining' | 'covered' | 'uncertain';
23
+ readonly explanation: string;
24
+ readonly sources: readonly {
25
+ readonly sessionId: string;
26
+ readonly sourceRevision: string;
27
+ readonly evidenceRefs: readonly string[];
28
+ }[];
29
+ }
30
+ export type WorkDisposition = {
31
+ readonly kind: 'continue';
32
+ readonly operationRefs: readonly string[];
33
+ } | {
34
+ readonly kind: 'wait';
35
+ readonly waitFor: readonly {
36
+ readonly kind: 'session' | 'human_request' | 'resource' | 'recovery';
37
+ readonly id: string;
38
+ readonly revision: string;
39
+ }[];
40
+ }
41
+ /** Host-reserved reply reference; local bindings resolve the actual canonical message or digest. */
42
+ | {
43
+ readonly kind: 'return';
44
+ readonly replyRef: string;
45
+ } | {
46
+ readonly kind: 'blocked_system';
47
+ readonly code: string;
48
+ readonly recoveryRef: string;
49
+ } | {
50
+ readonly kind: 'withdraw';
51
+ readonly controlRef: string;
52
+ };
53
+ export interface IntentAssessment {
54
+ readonly operationId: string;
55
+ readonly workId: string;
56
+ /** Semantic coordination revision, independent of budget writes and journal sequence. */
57
+ readonly expectedWorkRevision: number;
58
+ readonly expectedGoalRevision: number;
59
+ readonly sourceInputIds: readonly string[];
60
+ readonly sourceEventIds: readonly string[];
61
+ readonly sourceDecisionRef?: string;
62
+ readonly inputs: readonly InputDisposition[];
63
+ readonly interpretation?: IntentInterpretation;
64
+ readonly coverage: readonly GoalCoverageItem[];
65
+ readonly disposition: WorkDisposition;
66
+ readonly reason: string;
67
+ }
68
+ export interface IntentCoordination {
69
+ readonly schemaVersion: 1;
70
+ readonly revision: number;
71
+ readonly goalRevision: number;
72
+ readonly interpretation: IntentInterpretation;
73
+ readonly inputs: Readonly<Record<string, InputDisposition>>;
74
+ readonly coverage: readonly GoalCoverageItem[];
75
+ readonly decision: IntentAssessment;
76
+ readonly decisionTurnId?: string;
77
+ readonly lifecycle: 'active' | 'fulfilled' | 'cancelled';
78
+ readonly updatedAt: string;
79
+ readonly review?: {
80
+ readonly reviewRef: string;
81
+ readonly passed: boolean;
82
+ readonly goalRevision: number;
83
+ readonly intentRevision: number;
84
+ readonly coverageDigest: string;
85
+ readonly sources: readonly {
86
+ readonly sessionId: string;
87
+ readonly sourceRevision: string;
88
+ readonly observationRevision: string;
89
+ }[];
90
+ readonly evidenceRefs: readonly string[];
91
+ readonly at: string;
92
+ };
93
+ readonly closure?: {
94
+ readonly operationId: string;
95
+ readonly replyRef?: string;
96
+ readonly replyRefs?: readonly string[];
97
+ readonly intentReplyRef?: string;
98
+ readonly reviewRef?: string;
99
+ readonly at: string;
100
+ };
101
+ }
102
+ export interface IntentClosureRequest {
103
+ readonly operationId: string;
104
+ readonly workId: string;
105
+ readonly expectedWorkRevision: number;
106
+ readonly expectedGoalRevision: number;
107
+ readonly lifecycle: 'fulfilled' | 'cancelled';
108
+ }
109
+ export interface IntentDecisionReceipt {
110
+ readonly operationId: string;
111
+ readonly workId: string;
112
+ readonly workRevision: number;
113
+ readonly goalRevision: number;
114
+ readonly at: string;
115
+ readonly turnId?: string;
116
+ readonly continuation?: boolean;
117
+ }
118
+ export type IntentCoordinationRequest = {
119
+ readonly action: 'query';
120
+ readonly workId: string;
121
+ readonly expectedRevision?: number;
122
+ readonly expectedWorkRevision?: number;
123
+ readonly afterSessionId?: string;
124
+ readonly afterInputId?: string;
125
+ readonly inputId?: string;
126
+ readonly eventId?: string;
127
+ readonly payloadOffset?: number;
128
+ } | {
129
+ readonly action: 'assess';
130
+ readonly assessment: Omit<IntentAssessment, 'operationId'>;
131
+ };
132
+ /** Bounded host projection. Available actions are a snapshot, not grants. */
133
+ export interface CoordinationDecisionFrame {
134
+ readonly workId: string;
135
+ readonly workRevision: number;
136
+ readonly goalRevision: number;
137
+ readonly sourceInputIds: readonly string[];
138
+ readonly sourceEventIds: readonly string[];
139
+ readonly sourceDecisionRef?: string;
140
+ readonly intent: {
141
+ readonly lifecycle: IntentCoordination['lifecycle'];
142
+ readonly outcome: string;
143
+ readonly constraints: readonly string[];
144
+ readonly nonGoals: readonly string[];
145
+ readonly openQuestions: readonly string[];
146
+ readonly openQuestionCount: number;
147
+ readonly remainingRequirementCount: number;
148
+ readonly inputDispositions: readonly InputDisposition[];
149
+ readonly requirements: readonly (IntentRequirement & {
150
+ readonly status: GoalCoverageItem['status'];
151
+ })[];
152
+ readonly disposition: WorkDisposition['kind'];
153
+ readonly review?: {
154
+ readonly reviewRef: string;
155
+ readonly passed: boolean;
156
+ readonly current: boolean;
157
+ readonly goalRevision: number;
158
+ } | null;
159
+ } | null;
160
+ readonly sessions: readonly {
161
+ readonly sessionId: string;
162
+ readonly title: string;
163
+ readonly status: string;
164
+ readonly sourceRevision?: string;
165
+ readonly observationRevision?: string;
166
+ readonly humanGate: boolean;
167
+ }[];
168
+ readonly events: readonly {
169
+ readonly eventId: string;
170
+ readonly kind: string;
171
+ readonly sessionId?: string;
172
+ readonly payload: Readonly<Record<string, unknown>>;
173
+ }[];
174
+ readonly questions: readonly Readonly<Record<string, unknown>>[];
175
+ readonly operations: readonly Readonly<Record<string, unknown>>[];
176
+ readonly unknownEffects: readonly Readonly<Record<string, unknown>>[];
177
+ readonly controls: Readonly<Record<string, unknown>>;
178
+ readonly omitted: Readonly<Record<string, number | boolean>>;
179
+ readonly retrieval: {
180
+ readonly tool: 'coordinate_work';
181
+ readonly action: 'query';
182
+ readonly workId: string;
183
+ readonly expectedRevision: number;
184
+ readonly afterSessionId?: string;
185
+ };
186
+ readonly availableActions: readonly {
187
+ readonly action: string;
188
+ readonly allowed: boolean;
189
+ readonly reason?: string;
190
+ }[];
191
+ readonly truncated: boolean;
192
+ }
193
+ export interface ProgressObservation {
194
+ readonly kind: 'observed' | 'admitted' | 'advanced';
195
+ readonly fingerprint: string;
196
+ readonly failure: boolean;
197
+ /** Host-normalized facts; this record is neither Evidence nor an execution/permission receipt. */
198
+ readonly fact: Readonly<Record<string, unknown>>;
199
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,7 @@ import { type ModelReasoningEffort } from './model-reasoning.ts';
4
4
  * Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
5
5
  */
6
6
  export type ModelTier = 'strong' | 'fast' | 'economy' | 'vision';
7
- export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor';
7
+ export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor' | 'input_predictor';
8
8
  export type RoleSetting = ({
9
9
  readonly mode: 'tier';
10
10
  readonly tier: ModelTier;
@@ -56,6 +56,7 @@ function roleNeeds(input) {
56
56
  case 'objective_probe':
57
57
  return { tools: true, vision: false, structured: false, minContext: 0 };
58
58
  case 'compactor':
59
+ case 'input_predictor':
59
60
  return { tools: false, vision: false, structured: false, minContext: Math.max(context, 1) };
60
61
  default:
61
62
  return { tools: false, vision: false, structured: false, minContext: 0 };
@@ -0,0 +1,28 @@
1
+ /** The old delivered aggregate still requires both canonical commit and host settlement. */
2
+ export interface ReplyDeliveryReceipt {
3
+ readonly state: 'prepared' | 'delivered' | 'invalidated' | 'deferred' | 'aggregated';
4
+ readonly heldAt?: string;
5
+ readonly deliveredBy?: string;
6
+ readonly canonicalCommittedAt?: string;
7
+ readonly settlement?: {
8
+ readonly operationId: string;
9
+ readonly status: 'pending' | 'failed' | 'applied';
10
+ readonly attempts: number;
11
+ readonly updatedAt: string;
12
+ readonly phase?: 'commit' | 'settlement';
13
+ readonly error?: string;
14
+ readonly retryAt?: string;
15
+ };
16
+ }
17
+ /** Derived locally from current assessments, never accepted from assistant reply metadata. */
18
+ export interface IntentReplyBinding {
19
+ readonly workId: string;
20
+ readonly goalRevision: number;
21
+ readonly intentRevision: number;
22
+ readonly decisionRef: string;
23
+ readonly replyRef: string;
24
+ }
25
+ export interface ReplyGoalScope {
26
+ readonly workId: string;
27
+ readonly goalRevision: number;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,100 @@
1
+ /** Host-issued control and resource facts. None of these receipts grants tool permission. */
2
+ export interface ExecutionResourceScope {
3
+ readonly kind: 'directory';
4
+ readonly path: string;
5
+ }
6
+ export interface SessionExecutionIdentity {
7
+ readonly planId: string;
8
+ readonly sessionId: string;
9
+ readonly executionEpoch: string;
10
+ readonly goalRevision?: number;
11
+ readonly generation?: string;
12
+ }
13
+ export interface StopBarrierReceipt {
14
+ readonly receiptId: string;
15
+ readonly operationId: string;
16
+ readonly execution: SessionExecutionIdentity;
17
+ readonly admissionClosed: true;
18
+ readonly runnerIdle: true;
19
+ readonly schedulerIdle: true;
20
+ readonly resourceClaims: readonly {
21
+ readonly claimId: string;
22
+ readonly revision: number;
23
+ }[];
24
+ readonly unknownCalls: readonly string[];
25
+ readonly completedAt: string;
26
+ readonly scope: 'managed_execution';
27
+ }
28
+ export interface SessionControlOperation {
29
+ readonly operationId: string;
30
+ readonly requestDigest: string;
31
+ readonly revision: number;
32
+ readonly workspaceId: string;
33
+ readonly parentConversationId: string;
34
+ readonly sessionId: string;
35
+ readonly planId: string;
36
+ readonly kind: 'pause' | 'cancel' | 'takeover' | 'resume';
37
+ readonly authorityRef: string;
38
+ readonly hostEpoch?: string;
39
+ readonly unproven?: boolean;
40
+ readonly recoveryFactsDigest?: string;
41
+ readonly priorStopReceiptId?: string;
42
+ readonly expectedExecution: SessionExecutionIdentity;
43
+ readonly phase: 'recorded' | 'draining' | 'reconciling' | 'settled';
44
+ readonly outcome?: 'applied' | 'superseded' | 'rejected';
45
+ readonly supersededBy?: string;
46
+ readonly nextAction?: string;
47
+ readonly stopReceipt?: StopBarrierReceipt;
48
+ readonly updatedAt: string;
49
+ }
50
+ export type ExecutionResourceBlocker = {
51
+ readonly kind: 'owner';
52
+ readonly code: 'resource_busy';
53
+ readonly resourceRef: string;
54
+ readonly claimId: string;
55
+ readonly sessionId: string;
56
+ readonly title: string;
57
+ } | {
58
+ readonly kind: 'protection';
59
+ readonly nextAction?: 'reconcile_execution_outcome' | 'confirm_execution_stopped';
60
+ readonly code: 'execution_outcome_unknown' | 'execution_stop_unconfirmed';
61
+ readonly resourceRef: string;
62
+ readonly claimId: string;
63
+ readonly sessionId?: string;
64
+ readonly operationId?: string;
65
+ readonly evidenceCalls: readonly string[];
66
+ } | {
67
+ readonly kind: 'recovery';
68
+ readonly nextAction?: 'inspect_resource_recovery';
69
+ readonly code: string;
70
+ readonly resourceRef?: string;
71
+ };
72
+ export interface ExecutionResourceClaim {
73
+ readonly claimId: string;
74
+ readonly resourceRef: string;
75
+ readonly execution: SessionExecutionIdentity;
76
+ readonly workspaceId: string;
77
+ readonly hostEpoch: string;
78
+ readonly state: 'reserved' | 'active' | 'draining' | 'reconciling' | 'released';
79
+ readonly revision: number;
80
+ readonly handles?: Readonly<Record<string, {
81
+ readonly handleId: string;
82
+ readonly toolCallId: string;
83
+ readonly state: 'active' | 'ended' | 'unknown';
84
+ readonly completedAt?: string;
85
+ }>>;
86
+ readonly evidenceCalls: readonly string[];
87
+ }
88
+ /** Feed the existing lifecycle projector; a stale compatibility mirror cannot revive an old stop. */
89
+ export declare function controlPhasesForOrigin(origin: {
90
+ readonly executionControl?: SessionControlOperation;
91
+ readonly cancellation?: {
92
+ readonly phase: string;
93
+ };
94
+ readonly takeover?: {
95
+ readonly phase: string;
96
+ };
97
+ }): {
98
+ cancellationPhase?: string;
99
+ takeoverPhase?: string;
100
+ };
@@ -0,0 +1,14 @@
1
+ /** Feed the existing lifecycle projector; a stale compatibility mirror cannot revive an old stop. */
2
+ export function controlPhasesForOrigin(origin) {
3
+ const control = origin.executionControl;
4
+ if (!control)
5
+ return { cancellationPhase: origin.cancellation?.phase, takeoverPhase: origin.takeover?.phase };
6
+ const stopping = control.phase === 'reconciling' && control.stopReceipt?.unknownCalls.length ? 'awaiting_outcome' : 'stopping';
7
+ return {
8
+ cancellationPhase: control.kind === 'cancel'
9
+ ? control.phase === 'settled' && control.outcome === 'applied' ? 'completed' : stopping
10
+ : origin.cancellation?.phase,
11
+ takeoverPhase: control.phase === 'settled' && control.stopReceipt ? undefined
12
+ : control.kind === 'takeover' ? stopping : origin.takeover?.phase,
13
+ };
14
+ }
@@ -14,7 +14,7 @@ export interface UsageAmounts {
14
14
  export interface ProviderRequestUsage extends UsageAmounts {
15
15
  readonly usageScope: 'provider_request';
16
16
  readonly requestIndex: number;
17
- readonly requestPurpose: 'agent' | 'compaction_summary';
17
+ readonly requestPurpose: 'agent' | 'compaction_summary' | 'input_prediction';
18
18
  readonly requestFingerprint?: string;
19
19
  }
20
20
  /** Billable sum of every provider request executed by one user/runtime turn. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.1.0-rc.30",
3
+ "version": "0.1.0-rc.33",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",