@roll-agent/protocol 0.8.1 → 0.10.0

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.
package/dist/index.js CHANGED
@@ -14,10 +14,14 @@ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V14 = [
14
14
  "1.4",
15
15
  ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V13,
16
16
  ];
17
- export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = [
17
+ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V15 = [
18
18
  "1.5",
19
19
  ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V14,
20
20
  ];
21
+ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = [
22
+ "1.6",
23
+ ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V15,
24
+ ];
21
25
  export const RUNTIME_PROTOCOL_VERSION = SUPPORTED_RUNTIME_PROTOCOL_VERSIONS[0];
22
26
  export const RUNTIME_EVENT_NOTIFICATION = "runtime.event";
23
27
  export const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION = "runtime.serverRequest.cancel";
@@ -89,6 +93,13 @@ export const USER_INPUT_CONTROL_TYPES = {
89
93
  choice: "choice",
90
94
  };
91
95
  export const RUNTIME_PROTOCOL_CAPABILITIES = {
96
+ "1.6": {
97
+ serverRequests: true,
98
+ serverRequestCapabilityNegotiation: true,
99
+ approvalResolvedEvents: true,
100
+ clientApprovalResponses: false,
101
+ requiredServerRequestMethods: [],
102
+ },
92
103
  "1.5": {
93
104
  serverRequests: true,
94
105
  serverRequestCapabilityNegotiation: true,
@@ -133,6 +144,7 @@ export const RUNTIME_PROTOCOL_CAPABILITIES = {
133
144
  },
134
145
  };
135
146
  export const REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION = {
147
+ "1.6": RUNTIME_PROTOCOL_CAPABILITIES["1.6"].requiredServerRequestMethods,
136
148
  "1.5": RUNTIME_PROTOCOL_CAPABILITIES["1.5"].requiredServerRequestMethods,
137
149
  "1.4": RUNTIME_PROTOCOL_CAPABILITIES["1.4"].requiredServerRequestMethods,
138
150
  "1.3": RUNTIME_PROTOCOL_CAPABILITIES["1.3"].requiredServerRequestMethods,
@@ -175,6 +187,7 @@ export const RUNTIME_METHODS = {
175
187
  turnStart: "turn.start",
176
188
  turnCancel: "turn.cancel",
177
189
  approvalRespond: "approval.respond",
190
+ approvalPreview: "approval.preview",
178
191
  operationGet: "operation.get",
179
192
  attachmentStage: "attachment.stage",
180
193
  attachmentChunk: "attachment.chunk",
@@ -193,7 +206,8 @@ export const RUNTIME_FEATURES_V13 = [
193
206
  ];
194
207
  export const RUNTIME_FEATURES_V14 = [...RUNTIME_FEATURES_V13, "attachments"];
195
208
  export const RUNTIME_FEATURES_V15 = [...RUNTIME_FEATURES_V14, "app-output"];
196
- export const RUNTIME_FEATURES = RUNTIME_FEATURES_V15;
209
+ export const RUNTIME_FEATURES_V16 = [...RUNTIME_FEATURES_V15, "context-recovery"];
210
+ export const RUNTIME_FEATURES = RUNTIME_FEATURES_V16;
197
211
  export const RUNTIME_ERROR_CODES_V11 = {
198
212
  protocolVersionUnsupported: "PROTOCOL_VERSION_UNSUPPORTED",
199
213
  initializeRequired: "INITIALIZE_REQUIRED",
@@ -239,22 +253,29 @@ export const TOOL_OUTCOME_KINDS = [
239
253
  "cancelled",
240
254
  "tool_failed",
241
255
  ];
242
- export const threadIdSchema = z.string().uuid().brand();
243
- export const turnIdSchema = z.string().uuid().brand();
244
- export const approvalIdSchema = z.string().uuid().brand();
245
- export const interactionIdSchema = z.string().uuid().brand();
246
- export const runtimeInstanceIdSchema = z.string().uuid().brand();
247
- export const requestIdSchema = z.string().uuid().brand();
248
- export const streamIdSchema = z.string().uuid().brand();
249
- export const operationIdSchema = z.string().uuid().brand();
250
- export const runtimeEventIdSchema = z.string().uuid().brand();
251
- export const attachmentIdSchema = z.string().uuid().brand();
256
+ // Wire formats are owned by Protocol: dependency upgrades must not broaden UUIDs or
257
+ // reject timestamps that existing clients could send (including minute precision).
258
+ export const uuidSchema = z
259
+ .string()
260
+ .check(z.stringFormat("uuid", /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/));
261
+ export const timestampSchema = z
262
+ .string()
263
+ .check(z.stringFormat("datetime", /^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|([+-]\d{2}:\d{2})))$/));
264
+ export const threadIdSchema = uuidSchema.clone().brand();
265
+ export const turnIdSchema = uuidSchema.clone().brand();
266
+ export const approvalIdSchema = uuidSchema.clone().brand();
267
+ export const interactionIdSchema = uuidSchema.clone().brand();
268
+ export const runtimeInstanceIdSchema = uuidSchema.clone().brand();
269
+ export const requestIdSchema = uuidSchema.clone().brand();
270
+ export const streamIdSchema = uuidSchema.clone().brand();
271
+ export const operationIdSchema = uuidSchema.clone().brand();
272
+ export const runtimeEventIdSchema = uuidSchema.clone().brand();
273
+ export const attachmentIdSchema = uuidSchema.clone().brand();
252
274
  export const runtimeEventCursorSchema = z
253
275
  .string()
254
276
  .max(128)
255
277
  .regex(/^rte1:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}:(?:0|[1-9]\d*):[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/u)
256
278
  .brand();
257
- export const timestampSchema = z.string().datetime({ offset: true });
258
279
  export const jsonValueSchema = z.json();
259
280
  export const jsonRpcIdSchema = z.union([z.string(), z.number()]);
260
281
  export const runtimeProtocolVersionSchema = z.enum(SUPPORTED_RUNTIME_PROTOCOL_VERSIONS);
@@ -285,6 +306,8 @@ export const fileChangeDiffSchema = z
285
306
  hunks: z.number().int().nonnegative(),
286
307
  unified: z.string().max(FILE_CHANGE_DIFF_UNIFIED_MAX_CHARS).optional(),
287
308
  truncated: z.boolean(),
309
+ /** True when the counts describe whole before/after files rather than a line diff. */
310
+ coarse: z.boolean().optional(),
288
311
  })
289
312
  .readonly();
290
313
  export const fileChangeDisplaySchema = z
@@ -457,8 +480,15 @@ export const initializeResultV15Schema = z
457
480
  })
458
481
  .strict()
459
482
  .readonly();
483
+ export const initializeResultV16Schema = initializeResultV15Schema.def.innerType
484
+ .extend({
485
+ protocolVersion: z.literal("1.6"),
486
+ features: z.array(z.enum(RUNTIME_FEATURES_V16)),
487
+ })
488
+ .readonly();
460
489
  /** Any currently supported Runtime Protocol initialize result. */
461
490
  export const initializeResultSchema = z.union([
491
+ initializeResultV16Schema,
462
492
  initializeResultV15Schema,
463
493
  initializeResultV14Schema,
464
494
  initializeResultV13Schema,
@@ -911,14 +941,8 @@ const recoveryThreadSummarySchema = z
911
941
  id: threadIdSchema,
912
942
  title: z.string().max(RUNTIME_V13_RECOVERY_SNAPSHOT_METADATA_MAX_CHARS).optional(),
913
943
  model: z.string().max(RUNTIME_V13_RECOVERY_SNAPSHOT_METADATA_MAX_CHARS).optional(),
914
- createdAt: z
915
- .string()
916
- .max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS)
917
- .datetime({ offset: true }),
918
- updatedAt: z
919
- .string()
920
- .max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS)
921
- .datetime({ offset: true }),
944
+ createdAt: timestampSchema.max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS),
945
+ updatedAt: timestampSchema.max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS),
922
946
  messageCount: z.number().int().nonnegative(),
923
947
  })
924
948
  .strict()
@@ -941,10 +965,7 @@ const recoveryActiveTurnSchema = z
941
965
  .object({
942
966
  id: turnIdSchema,
943
967
  status: z.enum(["running", "cancelling", "waiting-for-user"]),
944
- startedAt: z
945
- .string()
946
- .max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS)
947
- .datetime({ offset: true }),
968
+ startedAt: timestampSchema.max(RUNTIME_V13_RECOVERY_SNAPSHOT_TIMESTAMP_MAX_CHARS),
948
969
  })
949
970
  .strict()
950
971
  .readonly();
@@ -990,7 +1011,31 @@ export const threadSnapshotV15Schema = z.union([
990
1011
  threadSnapshotV15FullSchema,
991
1012
  threadRecoverySnapshotV13Schema,
992
1013
  ]);
993
- export const threadSnapshotSchema = threadSnapshotV15Schema;
1014
+ /** Bounded Harness state only; no model-authored recovery notes or fact contents cross the wire. */
1015
+ export const contextRecoveryViewSchema = z
1016
+ .object({
1017
+ checkpointId: uuidSchema.clone(),
1018
+ required: z.boolean(),
1019
+ unextracted: z.boolean(),
1020
+ requiredItemCount: z.number().int().nonnegative(),
1021
+ })
1022
+ .strict()
1023
+ .readonly();
1024
+ export const threadSnapshotV16FullSchema = threadSnapshotV15FullSchema.def.innerType
1025
+ .extend({
1026
+ contextRecovery: contextRecoveryViewSchema.nullable(),
1027
+ })
1028
+ .readonly();
1029
+ export const threadRecoverySnapshotV16Schema = threadRecoverySnapshotV13Schema.def.innerType
1030
+ .extend({
1031
+ contextRecovery: contextRecoveryViewSchema.nullable(),
1032
+ })
1033
+ .readonly();
1034
+ export const threadSnapshotV16Schema = z.union([
1035
+ threadSnapshotV16FullSchema,
1036
+ threadRecoverySnapshotV16Schema,
1037
+ ]);
1038
+ export const threadSnapshotSchema = threadSnapshotV16Schema;
994
1039
  const pageSizeSchema = z.number().int().min(1).max(500).default(100);
995
1040
  const requestFields = { requestId: requestIdSchema };
996
1041
  const threadRequestFields = { threadId: threadIdSchema };
@@ -1264,6 +1309,25 @@ export const approvalRespondResultSchema = z
1264
1309
  .object({ resolved: z.literal(true) })
1265
1310
  .strict()
1266
1311
  .readonly();
1312
+ /** Offsets count UTF-16 code units in the stable, redacted review text. */
1313
+ export const approvalPreviewParamsSchema = z
1314
+ .object({
1315
+ ...threadRequestFields,
1316
+ turnId: turnIdSchema,
1317
+ approvalId: approvalIdSchema,
1318
+ offset: z.number().int().nonnegative().default(0),
1319
+ maxChars: z.number().int().min(1).max(32_000).default(12_000),
1320
+ })
1321
+ .strict()
1322
+ .readonly();
1323
+ export const approvalPreviewResultSchema = z
1324
+ .object({
1325
+ text: z.string().max(32_000),
1326
+ totalChars: z.number().int().nonnegative(),
1327
+ nextOffset: z.number().int().nonnegative().nullable(),
1328
+ })
1329
+ .strict()
1330
+ .readonly();
1267
1331
  export const approvalRequestParamsSchema = z
1268
1332
  .object({
1269
1333
  threadId: threadIdSchema,
@@ -1545,8 +1609,23 @@ export const runtimeEventV15Schema = z.union([
1545
1609
  runtimeDurableEventV15Schema,
1546
1610
  runtimeEphemeralEventV13Schema,
1547
1611
  ]);
1612
+ export const contextRecoveryChangedEventSchema = z
1613
+ .object({
1614
+ type: z.literal("context.recovery.changed"),
1615
+ contextRecovery: contextRecoveryViewSchema.nullable(),
1616
+ })
1617
+ .strict()
1618
+ .readonly();
1619
+ export const runtimeDurableEventV16Schema = z.discriminatedUnion("type", [
1620
+ ...runtimeDurableEventV15Schema.options,
1621
+ contextRecoveryChangedEventSchema,
1622
+ ]);
1623
+ export const runtimeEventV16Schema = z.union([
1624
+ runtimeDurableEventV16Schema,
1625
+ runtimeEphemeralEventV13Schema,
1626
+ ]);
1548
1627
  /** Latest Runtime Protocol event payloads. */
1549
- export const runtimeEventSchema = runtimeEventV15Schema;
1628
+ export const runtimeEventSchema = runtimeEventV16Schema;
1550
1629
  const runtimeEventEnvelopeFields = {
1551
1630
  runtimeInstanceId: runtimeInstanceIdSchema,
1552
1631
  sequence: z.number().int().nonnegative(),
@@ -1663,7 +1742,34 @@ export const runtimeEventEnvelopeV15Schema = z.discriminatedUnion("durability",
1663
1742
  runtimeEphemeralEventEnvelopeV15Schema,
1664
1743
  ]);
1665
1744
  /** Any currently supported Runtime Event envelope. */
1745
+ export const runtimeDurableEventEnvelopeV16Schema = z
1746
+ .object({
1747
+ protocolVersion: z.literal("1.6"),
1748
+ ...runtimeEventEnvelopeFields,
1749
+ durability: z.literal("durable"),
1750
+ eventId: runtimeEventIdSchema,
1751
+ cursor: runtimeEventCursorSchema,
1752
+ event: runtimeDurableEventV16Schema,
1753
+ })
1754
+ .strict()
1755
+ .superRefine(validateRuntimeEventCapabilities)
1756
+ .readonly();
1757
+ export const runtimeEphemeralEventEnvelopeV16Schema = z
1758
+ .object({
1759
+ protocolVersion: z.literal("1.6"),
1760
+ ...runtimeEventEnvelopeFields,
1761
+ durability: z.literal("ephemeral"),
1762
+ event: runtimeEphemeralEventV13Schema,
1763
+ })
1764
+ .strict()
1765
+ .superRefine(validateRuntimeEventCapabilities)
1766
+ .readonly();
1767
+ export const runtimeEventEnvelopeV16Schema = z.discriminatedUnion("durability", [
1768
+ runtimeDurableEventEnvelopeV16Schema,
1769
+ runtimeEphemeralEventEnvelopeV16Schema,
1770
+ ]);
1666
1771
  export const runtimeEventEnvelopeSchema = z.union([
1772
+ runtimeEventEnvelopeV16Schema,
1667
1773
  runtimeEventEnvelopeV15Schema,
1668
1774
  runtimeEventEnvelopeV14Schema,
1669
1775
  runtimeEventEnvelopeV13Schema,
@@ -1853,7 +1959,23 @@ export const runtimeMethodSchemasV15 = {
1853
1959
  result: operationResultGetResultSchema,
1854
1960
  },
1855
1961
  };
1856
- export const runtimeMethodSchemas = runtimeMethodSchemasV15;
1962
+ export const runtimeMethodSchemasV16 = {
1963
+ ...runtimeMethodSchemasV15,
1964
+ [RUNTIME_METHODS.approvalPreview]: {
1965
+ params: approvalPreviewParamsSchema,
1966
+ result: approvalPreviewResultSchema,
1967
+ },
1968
+ [RUNTIME_METHODS.initialize]: {
1969
+ params: initializeParamsSchema,
1970
+ result: initializeResultV16Schema,
1971
+ },
1972
+ [RUNTIME_METHODS.threadOpen]: { params: threadOpenParamsSchema, result: threadSnapshotV16Schema },
1973
+ [RUNTIME_METHODS.threadSnapshot]: {
1974
+ params: threadSnapshotParamsV13Schema,
1975
+ result: threadSnapshotV16Schema,
1976
+ },
1977
+ };
1978
+ export const runtimeMethodSchemas = runtimeMethodSchemasV16;
1857
1979
  export const runtimeServerRequestSchemasV10 = {};
1858
1980
  export const runtimeServerRequestSchemasV11 = {
1859
1981
  [RUNTIME_SERVER_REQUEST_METHODS.approvalRequest]: {
@@ -1875,6 +1997,14 @@ export const runtimeServerRequestSchemasV13 = runtimeServerRequestSchemasV12;
1875
1997
  /** Protocol 1.1 compatibility facade. Prefer the version registry in new code. */
1876
1998
  export const runtimeServerRequestSchemas = runtimeServerRequestSchemasV11;
1877
1999
  export const RUNTIME_PROTOCOL_REGISTRY = {
2000
+ "1.6": {
2001
+ methods: runtimeMethodSchemasV16,
2002
+ serverRequests: runtimeServerRequestSchemasV13,
2003
+ serverRequestMethods: RUNTIME_SERVER_REQUEST_METHOD_VALUES,
2004
+ serverRequestCancelParamsSchema: runtimeServerRequestCancelParamsV12Schema,
2005
+ eventEnvelopeSchema: runtimeEventEnvelopeV16Schema,
2006
+ errorDataSchema: runtimeProtocolErrorDataV14Schema,
2007
+ },
1878
2008
  "1.5": {
1879
2009
  methods: runtimeMethodSchemasV15,
1880
2010
  serverRequests: runtimeServerRequestSchemasV13,
@@ -2152,7 +2282,7 @@ function projectUiMessagePageToTextParts(page) {
2152
2282
  }
2153
2283
  export function projectOperationViewForVersion(version, value) {
2154
2284
  const current = operationViewV15Schema.safeParse(value);
2155
- if (version === "1.5") {
2285
+ if (version === "1.5" || version === "1.6") {
2156
2286
  return current.success
2157
2287
  ? current.data
2158
2288
  : operationViewV15Schema.parse({
@@ -2166,6 +2296,14 @@ export function projectOperationViewForVersion(version, value) {
2166
2296
  return operationViewSchema.parse(legacy);
2167
2297
  }
2168
2298
  export function projectThreadSnapshotForVersion(version, value) {
2299
+ if (version === "1.6") {
2300
+ return threadSnapshotV16Schema.parse(value);
2301
+ }
2302
+ const latestV16 = threadSnapshotV16Schema.safeParse(value);
2303
+ if (latestV16.success) {
2304
+ const { contextRecovery: _contextRecovery, ...legacy } = latestV16.data;
2305
+ value = legacy;
2306
+ }
2169
2307
  const latestV15 = threadSnapshotV15Schema.safeParse(value);
2170
2308
  if (version === "1.5") {
2171
2309
  return threadSnapshotV15Schema.parse(value);
@@ -2230,7 +2368,17 @@ export function projectThreadSnapshotForVersion(version, value) {
2230
2368
  });
2231
2369
  }
2232
2370
  export function projectRuntimeEventEnvelopeForVersion(version, value) {
2233
- const parsedSource = runtimeEventEnvelopeSchema.parse(value);
2371
+ const latest = runtimeEventEnvelopeSchema.parse(value);
2372
+ if (version === "1.6") {
2373
+ return runtimeEventEnvelopeV16Schema.parse({
2374
+ ...latest,
2375
+ protocolVersion: version,
2376
+ });
2377
+ }
2378
+ // Preserve durable cursor continuity for old clients; the available tool set changed.
2379
+ const parsedSource = latest.event.type === "context.recovery.changed"
2380
+ ? { ...latest, event: { type: "capabilities.changed" } }
2381
+ : latest;
2234
2382
  if (version === "1.5") {
2235
2383
  return runtimeEventEnvelopeV15Schema.parse({
2236
2384
  ...parsedSource,