@peer-agent/protocol 0.1.0-rc.5 → 0.1.0-rc.50

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 (120) 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 +67 -0
  10. package/dist/bot-conversation-read.js +9 -0
  11. package/dist/bot-direct-step.d.ts +11 -0
  12. package/dist/bot-direct-step.js +1 -0
  13. package/dist/bot-git.d.ts +55 -0
  14. package/dist/bot-git.js +1 -0
  15. package/dist/bot-model-selection.d.ts +13 -0
  16. package/dist/bot-model-selection.js +1 -0
  17. package/dist/browser-window.d.ts +48 -0
  18. package/dist/browser-window.js +23 -0
  19. package/dist/capability-admission.d.ts +20 -0
  20. package/dist/capability-admission.js +1 -0
  21. package/dist/compaction-history-selection.d.ts +15 -0
  22. package/dist/compaction-history-selection.js +30 -0
  23. package/dist/compaction.d.ts +5 -0
  24. package/dist/compaction.js +6 -0
  25. package/dist/context-accounting.d.ts +3 -0
  26. package/dist/conversation-execution.d.ts +68 -0
  27. package/dist/conversation-execution.js +222 -0
  28. package/dist/delegation-coordination.d.ts +81 -0
  29. package/dist/delegation-coordination.js +1 -0
  30. package/dist/delegation.d.ts +260 -7
  31. package/dist/delegation.js +97 -39
  32. package/dist/document-reference.d.ts +111 -0
  33. package/dist/document-reference.js +1 -0
  34. package/dist/evidence-inspection.d.ts +64 -0
  35. package/dist/evidence-inspection.js +1 -0
  36. package/dist/gemini-standard-pricing.json +105 -0
  37. package/dist/goal.d.ts +50 -2
  38. package/dist/hook-observation.d.ts +2 -0
  39. package/dist/hook-observation.js +19 -0
  40. package/dist/index.d.ts +109 -25
  41. package/dist/index.js +38 -0
  42. package/dist/input-prediction.d.ts +86 -0
  43. package/dist/input-prediction.js +48 -0
  44. package/dist/intent-coordination.d.ts +201 -0
  45. package/dist/intent-coordination.js +1 -0
  46. package/dist/interactive-result.d.ts +363 -0
  47. package/dist/interactive-result.js +215 -0
  48. package/dist/interactive-verification.d.ts +41 -0
  49. package/dist/interactive-verification.js +65 -0
  50. package/dist/local-git.d.ts +44 -0
  51. package/dist/local-git.js +3 -0
  52. package/dist/local-image.d.ts +53 -0
  53. package/dist/local-image.js +5 -0
  54. package/dist/local-read.d.ts +9 -0
  55. package/dist/local-read.js +1 -0
  56. package/dist/memory.d.ts +71 -11
  57. package/dist/memory.js +12 -0
  58. package/dist/model-reasoning.d.ts +16 -0
  59. package/dist/model-reasoning.js +25 -0
  60. package/dist/model-routing.d.ts +39 -3
  61. package/dist/model-routing.js +31 -5
  62. package/dist/native-process.d.ts +21 -0
  63. package/dist/native-process.js +51 -0
  64. package/dist/parent-coordination.d.ts +104 -0
  65. package/dist/parent-coordination.js +2 -0
  66. package/dist/project-agent-failure.d.ts +30 -0
  67. package/dist/project-agent-failure.js +44 -0
  68. package/dist/project-input-recovery.d.ts +83 -0
  69. package/dist/project-input-recovery.js +25 -0
  70. package/dist/project-matter.d.ts +225 -0
  71. package/dist/project-matter.js +1 -0
  72. package/dist/project-recovery.d.ts +43 -0
  73. package/dist/project-recovery.js +1 -0
  74. package/dist/project.d.ts +136 -0
  75. package/dist/project.js +130 -5
  76. package/dist/quiet-reply.d.ts +9 -0
  77. package/dist/quiet-reply.js +43 -0
  78. package/dist/remote-access.d.ts +15 -0
  79. package/dist/remote-access.js +1 -1
  80. package/dist/reply-delivery.d.ts +28 -0
  81. package/dist/reply-delivery.js +1 -0
  82. package/dist/resource-edit-execution.d.ts +68 -0
  83. package/dist/resource-edit-execution.js +96 -0
  84. package/dist/resource-edit.d.ts +237 -0
  85. package/dist/resource-edit.js +134 -0
  86. package/dist/resource-feedback-transport.d.ts +26 -0
  87. package/dist/resource-feedback-transport.js +94 -0
  88. package/dist/resource-feedback.d.ts +98 -0
  89. package/dist/resource-feedback.js +151 -0
  90. package/dist/resource-file-replace.d.ts +36 -0
  91. package/dist/resource-file-replace.js +40 -0
  92. package/dist/resource-reference-hints.d.ts +3 -0
  93. package/dist/resource-reference-hints.js +58 -0
  94. package/dist/resource-window.d.ts +222 -0
  95. package/dist/resource-window.js +252 -0
  96. package/dist/runtime-session-facts.d.ts +58 -0
  97. package/dist/runtime-session-facts.js +57 -0
  98. package/dist/session-control.d.ts +211 -0
  99. package/dist/session-control.js +48 -0
  100. package/dist/session-facts.d.ts +29 -0
  101. package/dist/session-facts.js +35 -0
  102. package/dist/skill-marketplace.d.ts +39 -4
  103. package/dist/spend-budget.d.ts +69 -0
  104. package/dist/spend-budget.js +1 -0
  105. package/dist/system-context.d.ts +7 -0
  106. package/dist/task-overview.d.ts +91 -0
  107. package/dist/task-overview.js +325 -17
  108. package/dist/tool-activity-preview.d.ts +4 -0
  109. package/dist/tool-activity-preview.js +72 -0
  110. package/dist/updater.d.ts +13 -3
  111. package/dist/usage-accounting.d.ts +42 -1
  112. package/dist/user-anchor.d.ts +17 -0
  113. package/dist/user-anchor.js +1 -0
  114. package/dist/work-coordination.d.ts +188 -0
  115. package/dist/work-coordination.js +1 -0
  116. package/dist/work-hook.d.ts +3 -0
  117. package/dist/work-hook.js +76 -0
  118. package/dist/working-plan.d.ts +18 -0
  119. package/dist/working-plan.js +1 -0
  120. package/package.json +1 -1
@@ -0,0 +1,188 @@
1
+ import type { ProjectRecoveryFailureKind } from './project-agent-failure.ts';
2
+ import type { SessionExecutionIdentity, SessionControlOperation } from './session-control.ts';
3
+ import type { NativeOwnedProcess } from './native-process.ts';
4
+ /** ADR 131 native attempt metadata. Shape alone proves neither death nor effect. */
5
+ export interface NativeEpisodeRecorder {
6
+ readonly schemaVersion: 1;
7
+ readonly runtime: 'peer-native';
8
+ readonly execution: SessionExecutionIdentity;
9
+ readonly recorder: NonNullable<SessionControlOperation['recorder']>;
10
+ }
11
+ export interface ProjectWorkBudgetLimits {
12
+ readonly schemaVersion?: 2;
13
+ readonly source: string;
14
+ readonly maxModelRequests?: number;
15
+ readonly maxToolCalls?: number;
16
+ readonly maxTokens?: number;
17
+ readonly maxCostUsd?: number;
18
+ }
19
+ export interface ProjectWorkBudgetBoundary {
20
+ readonly metric: 'modelRequests' | 'toolCalls' | 'tokens' | 'costUsd';
21
+ readonly used: number | null;
22
+ readonly limit: number;
23
+ readonly source: string;
24
+ readonly reason: 'limit_reached' | 'usage_unknown' | 'reservation_pending';
25
+ }
26
+ /** Current host admission; a card action never grants execution authority. */
27
+ export interface ProjectReplyRecoveryAction {
28
+ readonly canContinue: boolean;
29
+ readonly blockedReason?: string;
30
+ readonly budget?: ProjectWorkBudgetBoundary;
31
+ }
32
+ /** A reply attempt and delegated execution have independent outcomes. Host facts only. */
33
+ export interface ProjectReplyFailureStatus {
34
+ readonly phase: 'current' | 'retrying' | 'superseded' | 'recovered' | 'cancelled' | 'paused';
35
+ readonly turnKind: 'user' | 'wake';
36
+ readonly workId?: string;
37
+ readonly activeSessionIds: readonly string[];
38
+ readonly recoveredByReplyId?: string;
39
+ }
40
+ /** Persisted on agent_turn.meta and the protected outcome; not a delivered reply. */
41
+ export interface ProjectAgentSilentWait {
42
+ readonly source: 'host' | 'tool';
43
+ readonly sessionIds: readonly string[];
44
+ }
45
+ /** Local host reservation; neither model text nor a UI timer owns recovery. */
46
+ export interface ProjectWorkRecovery {
47
+ readonly failureKind: ProjectRecoveryFailureKind;
48
+ readonly retryable: boolean;
49
+ readonly autoAttempts: number;
50
+ readonly failedTurnId: string;
51
+ readonly retryAt?: string;
52
+ readonly reservationId?: string;
53
+ readonly deadlineAt?: string;
54
+ readonly dispatchesReconciled?: boolean;
55
+ readonly blockedCode?: 'RECOVERY_CHECKPOINT_UNAVAILABLE';
56
+ }
57
+ export type ProjectWorkState = 'runnable' | 'waiting_children' | 'waiting_user' | 'retry_wait' | 'paused' | 'budget_limited' | 'blocked_system' | 'delivered' | 'cancelled' | 'coalesced';
58
+ export type ProjectTurnEnd = 'reply_committed' | 'awaiting_children' | 'yielded' | 'awaiting_user' | 'budget_limited' | 'provider_retryable' | 'no_progress' | 'user_stopped' | 'fatal' | 'coalesced';
59
+ /** Host reconciliation closes an interrupted review/query, never supplies its result or verdict. */
60
+ export interface VerificationDispatchReconciliation {
61
+ readonly attemptId: string;
62
+ readonly toolCallId: string;
63
+ readonly capabilityId: 'verify_session' | 'local.delegation.verify_session' | 'get_session' | 'local.delegation.get_session' | 'get_verification_detail' | 'local.delegation.get_verification_detail';
64
+ readonly sessionId: string;
65
+ readonly planId: string;
66
+ readonly sourceRevision: string;
67
+ readonly outcome: 'verification_interrupted' | 'query_interrupted';
68
+ readonly at: string;
69
+ }
70
+ /** A registered, paired delegation result settles its dispatch, never its task. */
71
+ export interface SettledDelegationDispatch {
72
+ readonly attemptId?: string;
73
+ readonly turnId: string;
74
+ readonly toolCallId: string;
75
+ readonly evidenceRef: string;
76
+ readonly operationId: string;
77
+ readonly sessionId: string;
78
+ readonly executionEpoch: string;
79
+ readonly goalRevision: number;
80
+ readonly at: string;
81
+ }
82
+ export interface ProjectWorkReceipt {
83
+ readonly schemaVersion: 1;
84
+ readonly workId: string;
85
+ readonly workspaceId: string;
86
+ readonly parentConversationId: string;
87
+ readonly anchorInputIds: readonly string[];
88
+ readonly sessionIds: readonly string[];
89
+ /** Current owned technical blockers; a public progress update does not discharge them. */
90
+ readonly repairSessionIds?: readonly string[];
91
+ /** Unresolved dispatch receipts, not execution grants or permission truth. */
92
+ readonly delegationFollowUp?: {
93
+ readonly blockers: readonly {
94
+ readonly taskKey: string;
95
+ /** Task body without the anchor ids being repaired. A corrected retry clears that obligation. */
96
+ readonly recoveryKey?: string;
97
+ readonly sourceTurnId: string;
98
+ readonly toolCallId: string;
99
+ readonly action: 'parallel' | 'replace';
100
+ readonly error: string;
101
+ readonly retryable: boolean;
102
+ readonly operationId?: string;
103
+ readonly sessionId?: string;
104
+ }[];
105
+ };
106
+ readonly progressFacts?: readonly string[];
107
+ readonly state: ProjectWorkState;
108
+ readonly revision: number;
109
+ readonly checkpointRef?: string;
110
+ readonly nativeCheckpointRef?: string;
111
+ /** Only duplicate background observations transfer custody; all history remains. */
112
+ readonly continuationOwnerWorkId?: string;
113
+ readonly reportedWait?: {
114
+ readonly replyIds: readonly string[];
115
+ readonly waitingUser: boolean;
116
+ readonly sessionStates: readonly {
117
+ readonly sessionId: string;
118
+ readonly status: string;
119
+ readonly sourceRevision: string;
120
+ readonly observationRevision?: string;
121
+ }[];
122
+ };
123
+ readonly recovery?: ProjectWorkRecovery;
124
+ readonly end?: ProjectTurnEnd;
125
+ readonly attemptId?: string;
126
+ readonly pendingEventIds?: readonly string[];
127
+ readonly waitFor: readonly {
128
+ readonly kind: 'session' | 'approval' | 'question' | 'retry_timer' | 'human_request' | 'resource' | 'recovery';
129
+ readonly id: string;
130
+ readonly revision?: string;
131
+ }[];
132
+ readonly consumedEventIds: readonly string[];
133
+ readonly pendingResultRefs: readonly string[];
134
+ readonly lastDeliveredFactKey?: string;
135
+ readonly budgetRef?: string;
136
+ readonly budget?: {
137
+ readonly modelRequests: number;
138
+ readonly toolCalls: number;
139
+ readonly tokens: number;
140
+ readonly costUsd: number;
141
+ readonly unknownUsage: boolean;
142
+ readonly unknownCost: boolean;
143
+ readonly limits: ProjectWorkBudgetLimits;
144
+ readonly policyMigration?: {
145
+ readonly version: 2;
146
+ readonly reason: 'legacy_system_default_removed';
147
+ readonly previousLimits: ProjectWorkBudgetLimits;
148
+ readonly at: string;
149
+ };
150
+ readonly lastBoundary?: ProjectWorkBudgetBoundary;
151
+ readonly attempts: Readonly<Record<string, {
152
+ readonly role: string;
153
+ readonly requests?: number;
154
+ readonly modelProviderId?: string;
155
+ readonly checkpointRef?: string;
156
+ readonly nativeRecorder?: NativeEpisodeRecorder;
157
+ /** Unvalidated stored snapshot; admit v1 before consuming billing facts. */
158
+ readonly nativeUsage?: unknown;
159
+ /** Loop admission ended; this is not a stop receipt. */
160
+ readonly nativeLoopFinished?: true;
161
+ readonly pendingTools?: readonly {
162
+ readonly toolCallId: string | null;
163
+ readonly capabilityId: string | null;
164
+ readonly verificationSessionId?: string;
165
+ readonly nativeRecorder?: NativeEpisodeRecorder;
166
+ readonly nativeProcess?: NativeOwnedProcess;
167
+ }[];
168
+ }>>;
169
+ readonly reconciledDispatches?: readonly VerificationDispatchReconciliation[];
170
+ /** Keep unknown/future records intact until a compatible billing owner acts. */
171
+ readonly nativeUsagePending?: Readonly<Record<string, {
172
+ readonly snapshot: unknown;
173
+ readonly nativeRecorder: unknown;
174
+ }>>;
175
+ readonly settledDispatches?: readonly SettledDelegationDispatch[];
176
+ readonly uncertainDispatches?: readonly {
177
+ readonly attemptId: string;
178
+ readonly role: string;
179
+ readonly toolCallId: string | null;
180
+ readonly capabilityId: string | null;
181
+ readonly verificationSessionId?: string;
182
+ readonly nativeRecorder?: NativeEpisodeRecorder;
183
+ readonly nativeProcess?: NativeOwnedProcess;
184
+ }[];
185
+ };
186
+ readonly stopScope: 'reply' | 'work';
187
+ readonly updatedAt: string;
188
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const WORK_HOOK_SEMANTIC_FLOOR = 14;
2
+ /** Shape only. OS observation, ownership and business effects require Host evidence. */
3
+ export declare function nativeWorkHasHookFacts(work: unknown): boolean;
@@ -0,0 +1,76 @@
1
+ import { isHookObservation } from "./hook-observation.js";
2
+ import { nativeProcessEnvelopeValid } from "./native-process.js";
3
+ import { normalizeSessionExecutionIdentity } from "./session-control.js";
4
+ export const WORK_HOOK_SEMANTIC_FLOOR = 14;
5
+ const maxHandles = 256;
6
+ const invalid = () => { throw new Error('native_work_hooks_invalid'); };
7
+ const record = (input) => input !== null && typeof input === 'object' && !Array.isArray(input) ? input : undefined;
8
+ const requiredId = (input) => typeof input === 'string' && input.length > 0
9
+ && new TextEncoder().encode(input).length <= 200;
10
+ const ownerKeys = ['pid', 'pidStart', 'bootId', 'hostId', 'acquiredAt'];
11
+ /** Shape only. OS observation, ownership and business effects require Host evidence. */
12
+ export function nativeWorkHasHookFacts(work) {
13
+ const budget = record(record(work)?.budget);
14
+ const pending = Object.values(record(budget?.attempts) ?? {}).flatMap(attempt => {
15
+ const pending = record(attempt)?.pendingTools;
16
+ return Array.isArray(pending) ? pending : [];
17
+ });
18
+ const rows = pending.concat(Array.isArray(budget?.uncertainDispatches) ? budget.uncertainDispatches : []);
19
+ const ids = new Set();
20
+ let found = false;
21
+ for (const input of rows) {
22
+ const row = record(input);
23
+ if (!row || !Object.hasOwn(row, 'nativeHooks'))
24
+ continue;
25
+ const hooks = record(row.nativeHooks);
26
+ const recorder = record(row.nativeRecorder);
27
+ const owner = record(recorder?.recorder);
28
+ const execution = normalizeSessionExecutionIdentity(recorder?.execution);
29
+ const provider = record(row.nativeProcess);
30
+ const intent = record(hooks?.intent);
31
+ if (!hooks || Object.keys(hooks).some(key => !['schemaVersion', 'providerPhase', 'handles', 'intent', 'grant'].includes(key))
32
+ || Object.hasOwn(hooks, 'intent') && (!intent || Object.keys(intent).length !== 2
33
+ || !requiredId(intent.messageId) || /[\u0000-\u001f\u007f-\u009f]/u.test(intent.messageId)
34
+ || typeof intent.argsDigest !== 'string' || !/^[a-f0-9]{64}$/.test(intent.argsDigest))
35
+ || hooks.schemaVersion !== 1
36
+ || !['prepared', 'dispatching'].some(phase => phase === hooks.providerPhase)
37
+ || !Array.isArray(hooks.handles) || hooks.handles.length > maxHandles
38
+ || recorder?.schemaVersion !== 1 || recorder.runtime !== 'peer-native' || !owner || !execution
39
+ || !Number.isInteger(owner.pid) || owner.pid <= 0 || owner.pid > 2147483647
40
+ || ownerKeys.slice(1).some(key => typeof owner[key] !== 'string' || !owner[key].length
41
+ || new TextEncoder().encode(owner[key]).length > 8192)
42
+ || !requiredId(row.toolCallId) || !requiredId(row.dispatchId)
43
+ || hooks.providerPhase === 'prepared' && Object.hasOwn(row, 'nativeProcess'))
44
+ return invalid();
45
+ if (Object.hasOwn(hooks, 'grant')) {
46
+ const grant = record(hooks.grant);
47
+ if (hooks.providerPhase !== 'dispatching' || !intent || !grant || grant.granted !== true
48
+ || grant.toolCallId !== row.toolCallId || grant.duration !== 'once'
49
+ || typeof grant.grantId !== 'string' || grant.grantId.length === 0)
50
+ return invalid();
51
+ }
52
+ found = true;
53
+ for (const input of hooks.handles) {
54
+ const hook = record(input);
55
+ const process = record(hook?.process);
56
+ const processOwner = record(process?.owner);
57
+ const processExecution = normalizeSessionExecutionIdentity(process?.execution);
58
+ if (!hook || Object.keys(hook).some(key => !['event', 'ruleDigest', 'process', 'observation'].includes(key))
59
+ || !['PreToolUse', 'PostToolUse'].some(event => event === hook.event)
60
+ || hooks.providerPhase === 'prepared' && hook.event === 'PostToolUse'
61
+ || typeof hook.ruleDigest !== 'string' || !/^[a-f0-9]{64}$/.test(hook.ruleDigest)
62
+ || !process || !nativeProcessEnvelopeValid(process) || !processOwner || !processExecution
63
+ || ownerKeys.some(key => processOwner[key] !== owner[key])
64
+ || JSON.stringify(processExecution) !== JSON.stringify(execution)
65
+ || process.toolCallId !== row.toolCallId || process.dispatchId !== row.dispatchId
66
+ || process.generation > 1
67
+ || ids.size >= maxHandles || ids.has(process.handleId) || process.handleId === provider?.handleId
68
+ || (process.stopObservation === 'owned_completion'
69
+ ? !isHookObservation(hook.observation, hook.event, hook.ruleDigest, process.handleId)
70
+ : Object.hasOwn(hook, 'observation')))
71
+ return invalid();
72
+ ids.add(process.handleId);
73
+ }
74
+ }
75
+ return found;
76
+ }
@@ -0,0 +1,18 @@
1
+ export type WorkingPlanStepStatus = 'pending' | 'in_progress' | 'completed' | 'blocked';
2
+ export interface WorkingPlanStepView {
3
+ readonly title: string;
4
+ readonly status: WorkingPlanStepStatus;
5
+ readonly check?: string;
6
+ readonly note?: string;
7
+ }
8
+ export interface WorkingPlanView {
9
+ readonly epoch: number;
10
+ readonly revision: number;
11
+ readonly updatedAt: string;
12
+ readonly summary?: string;
13
+ readonly invariants?: readonly string[];
14
+ readonly completed: number;
15
+ readonly total: number;
16
+ readonly blocked: number;
17
+ readonly steps: readonly WorkingPlanStepView[];
18
+ }
@@ -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.5",
3
+ "version": "0.1.0-rc.50",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",