@osfactory/otel-hook 0.8.0 → 0.9.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/runtime.js CHANGED
@@ -837,10 +837,10 @@ var resolveDeliveryIdentity = (input) => {
837
837
  };
838
838
 
839
839
  // src/runtime/hook.ts
840
- import { z as z16 } from "zod";
840
+ import { z as z17 } from "zod";
841
841
 
842
842
  // src/config/schema.ts
843
- import { z as z8 } from "zod";
843
+ import { z as z9 } from "zod";
844
844
 
845
845
  // src/privacy/policy.ts
846
846
  import { z as z6 } from "zod";
@@ -929,8 +929,112 @@ var resolvePrivacyPolicy = (policy) => {
929
929
  return { policy: parsed, notes: [] };
930
930
  };
931
931
 
932
- // src/config/resource-attributes.ts
932
+ // src/config/destinations.ts
933
933
  import { z as z7 } from "zod";
934
+
935
+ // src/config/header-value.ts
936
+ var isUnsafeHeaderValue = (value) => [...value].some((char) => {
937
+ const code = char.codePointAt(0) ?? 0;
938
+ return code < 32 && code !== 9 || code === 127 || code > 255;
939
+ });
940
+
941
+ // src/config/otlp-headers.ts
942
+ var MAX_OTLP_HEADERS = 32;
943
+ var OTLP_HEADER_VARIABLES = Object.freeze({
944
+ generic: "OTEL_EXPORTER_OTLP_HEADERS",
945
+ traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
946
+ logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
947
+ });
948
+
949
+ // src/config/destinations.ts
950
+ var DEFAULT_DESTINATION_NAME = "default";
951
+ var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
952
+ var MAX_EXPORT_DESTINATIONS = 16;
953
+ var MAX_DESTINATION_HEADERS = MAX_OTLP_HEADERS;
954
+ var HEADER_ENV_REFERENCE_PREFIX = "env:";
955
+ var HEADER_NAME_PATTERN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
956
+ var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
957
+ var MAX_HEADER_VALUE_LENGTH = 8192;
958
+ var exportSignalSchema = z7.enum(["traces", "logs"]);
959
+ var headerValueSchema = z7.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
960
+ (value) => !isUnsafeHeaderValue(value),
961
+ "header values may not contain line breaks, control characters, or characters beyond Latin-1"
962
+ ).refine(
963
+ (value) => !value.startsWith(HEADER_ENV_REFERENCE_PREFIX) || ENV_VARIABLE_NAME_PATTERN.test(value.slice(HEADER_ENV_REFERENCE_PREFIX.length)),
964
+ "an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
965
+ );
966
+ var endpointSchema = z7.string().url().max(2048);
967
+ var exportDestinationSchema = z7.strictObject({
968
+ /** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
969
+ name: z7.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
970
+ /** Default true. A disabled destination is neither sent to nor drained. */
971
+ enabled: z7.boolean().optional(),
972
+ /**
973
+ * Traces URL, with the same meaning as `exporter.endpoint`: the logs URL is
974
+ * derived from it (`/v1/traces` becomes `/v1/logs`) unless `logsEndpoint` is set.
975
+ */
976
+ endpoint: endpointSchema.optional(),
977
+ /** Per-signal override of `endpoint` for traces. */
978
+ tracesEndpoint: endpointSchema.optional(),
979
+ /** Per-signal override of the derived logs URL. */
980
+ logsEndpoint: endpointSchema.optional(),
981
+ /** Defaults to `exporter.protocol`. */
982
+ protocol: z7.enum(["http/protobuf", "http/json", "none"]).optional(),
983
+ /**
984
+ * Header name to value. A value of the form `env:NAME` is read from that
985
+ * environment variable at send time, so a credential never has to be written
986
+ * into the file. Values never appear in a snapshot, a diagnostic, or `doctor`.
987
+ */
988
+ headers: z7.record(z7.string().regex(HEADER_NAME_PATTERN, "not a valid header name"), headerValueSchema).refine(
989
+ (headers) => Object.keys(headers).length <= MAX_DESTINATION_HEADERS,
990
+ `at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
991
+ ).optional(),
992
+ /**
993
+ * Which signals this destination receives. Default: both. The logs signal is
994
+ * still governed by `exporter.logs.enabled`, which stays the one opt-in for a
995
+ * second stream leaving the host.
996
+ */
997
+ signals: z7.array(exportSignalSchema).min(1).max(2).readonly().optional()
998
+ }).refine(
999
+ (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0,
1000
+ "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint"
1001
+ );
1002
+ var exportDestinationsSchema = z7.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
1003
+ const seen = /* @__PURE__ */ new Set();
1004
+ destinations.forEach((destination, index) => {
1005
+ if (destination.name === DEFAULT_DESTINATION_NAME) {
1006
+ context.addIssue({
1007
+ code: "custom",
1008
+ path: [index, "name"],
1009
+ message: 'the name "default" is reserved for exporter.endpoint and the OTEL_EXPORTER_OTLP_* variables'
1010
+ });
1011
+ }
1012
+ if (seen.has(destination.name)) {
1013
+ context.addIssue({
1014
+ code: "custom",
1015
+ path: [index, "name"],
1016
+ message: `duplicate destination name "${destination.name}"`
1017
+ });
1018
+ }
1019
+ seen.add(destination.name);
1020
+ });
1021
+ });
1022
+ var spoolPolicySchema = z7.strictObject({
1023
+ /** Total bytes of queued batches. Default 16 MiB. */
1024
+ maxBytes: z7.number().int().min(1024).max(1073741824),
1025
+ /** A batch older than this is dropped instead of sent. Default 72 hours. */
1026
+ maxAgeMillis: z7.number().int().min(1e3).max(30 * 24 * 60 * 60 * 1e3),
1027
+ /** Number of queued batches. Default 500. */
1028
+ maxBatches: z7.number().int().min(1).max(65536)
1029
+ });
1030
+ var DEFAULT_SPOOL_POLICY = Object.freeze({
1031
+ maxBytes: 16 * 1024 * 1024,
1032
+ maxAgeMillis: 72 * 60 * 60 * 1e3,
1033
+ maxBatches: 500
1034
+ });
1035
+
1036
+ // src/config/resource-attributes.ts
1037
+ import { z as z8 } from "zod";
934
1038
  var MAX_RESOURCE_ATTRIBUTES = 64;
935
1039
  var MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH = 255;
936
1040
  var MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH = 2048;
@@ -975,12 +1079,12 @@ var checkResourceAttributeKey = (key) => {
975
1079
  }
976
1080
  return void 0;
977
1081
  };
978
- var resourceAttributeValueSchema = z7.union([
979
- z7.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
980
- z7.number().finite(),
981
- z7.boolean()
1082
+ var resourceAttributeValueSchema = z8.union([
1083
+ z8.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
1084
+ z8.number().finite(),
1085
+ z8.boolean()
982
1086
  ]);
983
- var resourceAttributesSchema = z7.record(z7.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
1087
+ var resourceAttributesSchema = z8.record(z8.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
984
1088
  const keys = Object.keys(value);
985
1089
  if (keys.length > MAX_RESOURCE_ATTRIBUTES) {
986
1090
  ctx.addIssue({
@@ -1002,36 +1106,36 @@ var resourceAttributesSchema = z7.record(z7.string(), resourceAttributeValueSche
1002
1106
  var EMPTY_RESOURCE_ATTRIBUTES = Object.freeze({});
1003
1107
 
1004
1108
  // src/config/schema.ts
1005
- var logsPolicySchema = z8.strictObject({
1006
- enabled: z8.boolean(),
1109
+ var logsPolicySchema = z9.strictObject({
1110
+ enabled: z9.boolean(),
1007
1111
  /**
1008
1112
  * Full URL for the logs signal.
1009
1113
  *
1010
1114
  * Absent, it is derived from `endpoint`: a trailing `/v1/traces` becomes
1011
1115
  * `/v1/logs`, and an endpoint with no signal path has `/v1/logs` appended.
1012
1116
  */
1013
- endpoint: z8.string().url().max(2048).optional(),
1014
- includeContent: z8.boolean(),
1015
- maxBatchSize: z8.number().int().min(1).max(4096)
1117
+ endpoint: z9.string().url().max(2048).optional(),
1118
+ includeContent: z9.boolean(),
1119
+ maxBatchSize: z9.number().int().min(1).max(4096)
1016
1120
  });
1017
1121
  var DEFAULT_LOGS_POLICY = Object.freeze({
1018
1122
  enabled: false,
1019
1123
  includeContent: false,
1020
1124
  maxBatchSize: 128
1021
1125
  });
1022
- var exporterPolicySchema = z8.strictObject({
1023
- enabled: z8.boolean(),
1024
- protocol: z8.enum(["http/protobuf", "http/json", "none"]),
1025
- endpoint: z8.string().url().max(2048).optional(),
1126
+ var exporterPolicySchema = z9.strictObject({
1127
+ enabled: z9.boolean(),
1128
+ protocol: z9.enum(["http/protobuf", "http/json", "none"]),
1129
+ endpoint: z9.string().url().max(2048).optional(),
1026
1130
  /**
1027
1131
  * Header names only. Values are supplied separately at construction time and
1028
1132
  * are never part of a resolved-config snapshot, which is logged and exported.
1029
1133
  */
1030
- headerNames: z8.array(nonEmptyStringSchema).max(32).readonly(),
1031
- timeoutMillis: z8.number().int().min(1).max(6e5),
1032
- maxBatchSize: z8.number().int().min(1).max(4096),
1033
- maxQueueSize: z8.number().int().min(1).max(65536),
1034
- maxRetryAttempts: z8.number().int().min(0).max(10),
1134
+ headerNames: z9.array(nonEmptyStringSchema).max(32).readonly(),
1135
+ timeoutMillis: z9.number().int().min(1).max(6e5),
1136
+ maxBatchSize: z9.number().int().min(1).max(4096),
1137
+ maxQueueSize: z9.number().int().min(1).max(65536),
1138
+ maxRetryAttempts: z9.number().int().min(0).max(10),
1035
1139
  serviceName: nonEmptyStringSchema,
1036
1140
  serviceNamespace: nonEmptyStringSchema.optional(),
1037
1141
  /**
@@ -1048,32 +1152,52 @@ var exporterPolicySchema = z8.strictObject({
1048
1152
  * headers, timeout, protocol, service identity, and resource attributes above —
1049
1153
  * a second top-level section would invite two of each to drift apart.
1050
1154
  */
1051
- logs: logsPolicySchema
1155
+ logs: logsPolicySchema,
1156
+ /**
1157
+ * Additional OTLP destinations, each sent every batch in parallel.
1158
+ *
1159
+ * Absent (the default), the exporter has exactly one destination — the
1160
+ * single-endpoint settings above, named `default` — and behaves exactly as it
1161
+ * did before this list existed. See `destinations.ts`.
1162
+ *
1163
+ * Merged as one leaf: a higher layer that sets the list replaces it whole,
1164
+ * because "the union of two partial lists" has no answer an operator could
1165
+ * predict.
1166
+ */
1167
+ destinations: exportDestinationsSchema.optional(),
1168
+ /**
1169
+ * Per-destination retry spool bounds, each optional and merged per leaf; any
1170
+ * bound left unset takes its value from `DEFAULT_SPOOL_POLICY`.
1171
+ */
1172
+ spool: spoolPolicySchema.partial().optional()
1052
1173
  });
1053
- var detectionPolicySchema = z8.strictObject({
1174
+ var detectionPolicySchema = z9.strictObject({
1054
1175
  /** Detections below this confidence resolve to the unknown provider. */
1055
1176
  minimumConfidence: detectionConfidenceSchema,
1056
1177
  /** When false, an ambiguous detection is an error rather than unknown. */
1057
- allowAmbiguousFallback: z8.boolean(),
1178
+ allowAmbiguousFallback: z9.boolean(),
1058
1179
  /** Optional allow-list of provider ids; empty means "any registered". */
1059
- allowedProviderIds: z8.array(nonEmptyStringSchema).max(32).readonly()
1180
+ allowedProviderIds: z9.array(nonEmptyStringSchema).max(32).readonly()
1060
1181
  });
1061
- var diagnosticsPolicySchema = z8.strictObject({
1062
- logLevel: z8.enum(["silent", "error", "warn", "info", "debug"]),
1182
+ var diagnosticsPolicySchema = z9.strictObject({
1183
+ logLevel: z9.enum(["silent", "error", "warn", "info", "debug"]),
1063
1184
  /** Emit `error.raised` events for contained failures. */
1064
- emitErrorEvents: z8.boolean()
1185
+ emitErrorEvents: z9.boolean()
1065
1186
  });
1066
- var otelHookConfigSchema = z8.strictObject({
1187
+ var otelHookConfigSchema = z9.strictObject({
1067
1188
  exporter: exporterPolicySchema,
1068
1189
  privacy: privacyPolicySchema,
1069
1190
  detection: detectionPolicySchema,
1070
1191
  diagnostics: diagnosticsPolicySchema
1071
1192
  });
1072
- var otelHookConfigPatchSchema = z8.strictObject({
1193
+ var otelHookConfigPatchSchema = z9.strictObject({
1073
1194
  // `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
1074
1195
  // merging happens per leaf, so a layer must be able to set `logs.enabled` alone
1075
1196
  // without also restating the endpoint and the batch size.
1076
- exporter: exporterPolicySchema.omit({ logs: true }).partial().extend({ logs: logsPolicySchema.partial().optional() }).optional(),
1197
+ exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
1198
+ logs: logsPolicySchema.partial().optional(),
1199
+ spool: spoolPolicySchema.partial().optional()
1200
+ }).optional(),
1077
1201
  privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
1078
1202
  detection: detectionPolicySchema.partial().optional(),
1079
1203
  diagnostics: diagnosticsPolicySchema.partial().optional()
@@ -1107,8 +1231,8 @@ var DEFAULT_CONFIG = Object.freeze({
1107
1231
  });
1108
1232
 
1109
1233
  // src/model/content.ts
1110
- import { z as z9 } from "zod";
1111
- var contentKindSchema = z9.enum([
1234
+ import { z as z10 } from "zod";
1235
+ var contentKindSchema = z10.enum([
1112
1236
  "prompt",
1113
1237
  "response",
1114
1238
  "reasoning",
@@ -1118,42 +1242,42 @@ var contentKindSchema = z9.enum([
1118
1242
  "system-instruction",
1119
1243
  "attachment"
1120
1244
  ]);
1121
- var contentRoleSchema = z9.enum(["user", "assistant", "system", "tool", "unknown"]);
1122
- var contentDisclosureSchema = z9.enum(["omitted", "masked", "redacted", "raw"]);
1245
+ var contentRoleSchema = z10.enum(["user", "assistant", "system", "tool", "unknown"]);
1246
+ var contentDisclosureSchema = z10.enum(["omitted", "masked", "redacted", "raw"]);
1123
1247
  var CONTENT_HASH_PATTERN = /^sha256:[0-9a-f]{64}$/;
1124
- var contentFactSchema = z9.strictObject({
1248
+ var contentFactSchema = z10.strictObject({
1125
1249
  kind: contentKindSchema,
1126
1250
  role: contentRoleSchema.optional(),
1127
1251
  /** Unicode code point count of the original content. */
1128
- characterLength: z9.number().int().min(0),
1252
+ characterLength: z10.number().int().min(0),
1129
1253
  /** UTF-8 byte length of the original content. */
1130
- byteLength: z9.number().int().min(0),
1254
+ byteLength: z10.number().int().min(0),
1131
1255
  /** Stable salted digest of the original content. */
1132
- contentHash: z9.string().regex(CONTENT_HASH_PATTERN),
1256
+ contentHash: z10.string().regex(CONTENT_HASH_PATTERN),
1133
1257
  disclosure: contentDisclosureSchema,
1134
1258
  /** Disclosed text, bounded by the privacy policy. Absent when omitted. */
1135
- text: z9.string().optional(),
1259
+ text: z10.string().optional(),
1136
1260
  /** True when `text` was cut short by the configured string bound. */
1137
- truncated: z9.boolean(),
1261
+ truncated: z10.boolean(),
1138
1262
  /** Number of secret-looking spans replaced while producing `text`. */
1139
- secretsRedacted: z9.number().int().min(0),
1263
+ secretsRedacted: z10.number().int().min(0),
1140
1264
  /** Optional non-sensitive label, e.g. a MIME type or tool name. */
1141
1265
  label: nonEmptyStringSchema.optional()
1142
1266
  });
1143
- var contentFactsSchema = z9.array(contentFactSchema).max(64);
1267
+ var contentFactsSchema = z10.array(contentFactSchema).max(64);
1144
1268
  var isContentFactConsistent = (fact) => fact.disclosure === "omitted" ? fact.text === void 0 : fact.text !== void 0;
1145
1269
  var isUnavailableContentFact = (fact) => fact.disclosure === "omitted" && fact.text === void 0 && fact.characterLength === 0 && fact.byteLength === 0;
1146
1270
 
1147
1271
  // src/model/identity.ts
1148
- import { z as z10 } from "zod";
1149
- var workspaceKeySourceSchema = z10.enum([
1272
+ import { z as z11 } from "zod";
1273
+ var workspaceKeySourceSchema = z11.enum([
1150
1274
  "git-remote",
1151
1275
  "git-root",
1152
1276
  "working-directory",
1153
1277
  "explicit",
1154
1278
  "unknown"
1155
1279
  ]);
1156
- var workspaceIdentitySchema = z10.strictObject({
1280
+ var workspaceIdentitySchema = z11.strictObject({
1157
1281
  workspaceId: workspaceIdSchema,
1158
1282
  keySource: workspaceKeySourceSchema,
1159
1283
  /** Repository name only; never an owner path or URL with credentials. */
@@ -1167,7 +1291,7 @@ var unknownWorkspaceIdentity = () => workspaceIdentitySchema.parse({
1167
1291
  workspaceId: UNKNOWN_WORKSPACE_ID,
1168
1292
  keySource: "unknown"
1169
1293
  });
1170
- var sourceProvenanceSchema = z10.strictObject({
1294
+ var sourceProvenanceSchema = z11.strictObject({
1171
1295
  providerId: resolvedProviderIdSchema,
1172
1296
  providerVersion: nonEmptyStringSchema.optional(),
1173
1297
  adapterId: nonEmptyStringSchema,
@@ -1178,7 +1302,7 @@ var sourceProvenanceSchema = z10.strictObject({
1178
1302
  transport: sourceTransportSchema
1179
1303
  }).readonly();
1180
1304
  var consumerAttributesSchema = attributesSchema.readonly();
1181
- var invocationIdentitySchema = z10.strictObject({
1305
+ var invocationIdentitySchema = z11.strictObject({
1182
1306
  invocationId: invocationIdSchema,
1183
1307
  sessionId: sessionIdSchema,
1184
1308
  /** Set when this invocation runs beneath another agent invocation. */
@@ -1192,7 +1316,7 @@ var invocationIdentitySchema = z10.strictObject({
1192
1316
  startedAt: epochMillisSchema,
1193
1317
  consumerAttributes: consumerAttributesSchema
1194
1318
  }).readonly();
1195
- var identityClaimFieldsSchema = z10.strictObject({
1319
+ var identityClaimFieldsSchema = z11.strictObject({
1196
1320
  invocationId: invocationIdSchema.optional(),
1197
1321
  sessionId: sessionIdSchema.optional(),
1198
1322
  parentInvocationId: invocationIdSchema.optional(),
@@ -1201,7 +1325,7 @@ var identityClaimFieldsSchema = z10.strictObject({
1201
1325
  workspace: workspaceIdentitySchema.optional(),
1202
1326
  startedAt: epochMillisSchema.optional()
1203
1327
  });
1204
- var identityClaimSchema = z10.strictObject({
1328
+ var identityClaimSchema = z11.strictObject({
1205
1329
  /** Non-sensitive label, e.g. `adapter:acme-cli` or `env:OTEL_HOOK_SESSION_ID`. */
1206
1330
  source: nonEmptyStringSchema,
1207
1331
  confidence: detectionConfidenceSchema,
@@ -1322,15 +1446,15 @@ var resolveInvocationIdentity = (input) => {
1322
1446
  };
1323
1447
 
1324
1448
  // src/model/version.ts
1325
- import { z as z11 } from "zod";
1449
+ import { z as z12 } from "zod";
1326
1450
  var CANONICAL_SCHEMA_VERSION = 1;
1327
- var canonicalSchemaVersionSchema = z11.literal(CANONICAL_SCHEMA_VERSION);
1451
+ var canonicalSchemaVersionSchema = z12.literal(CANONICAL_SCHEMA_VERSION);
1328
1452
 
1329
1453
  // src/privacy/service.ts
1330
1454
  import { createHash as createHash2 } from "crypto";
1331
1455
 
1332
1456
  // src/model/extensions.ts
1333
- import { z as z12 } from "zod";
1457
+ import { z as z13 } from "zod";
1334
1458
  var EXTENSION_KEY_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*(?:\.[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*)+$/;
1335
1459
  var RESERVED_EXTENSION_NAMESPACES = Object.freeze([
1336
1460
  "otelhook",
@@ -1341,7 +1465,7 @@ var MAX_EXTENSION_ENTRIES = 64;
1341
1465
  var extensionKeyNamespace = (key) => key.slice(0, key.indexOf("."));
1342
1466
  var isReservedExtensionNamespace = (key) => RESERVED_EXTENSION_NAMESPACES.includes(extensionKeyNamespace(key));
1343
1467
  var isValidExtensionKey = (key) => EXTENSION_KEY_PATTERN.test(key) && !isReservedExtensionNamespace(key);
1344
- var extensionsSchema = z12.record(z12.string(), attributeValueSchema).check((ctx) => {
1468
+ var extensionsSchema = z13.record(z13.string(), attributeValueSchema).check((ctx) => {
1345
1469
  const keys = Object.keys(ctx.value);
1346
1470
  if (keys.length > MAX_EXTENSION_ENTRIES) {
1347
1471
  ctx.issues.push({
@@ -1716,25 +1840,25 @@ var createPrivacyService = (policyInput) => {
1716
1840
  };
1717
1841
 
1718
1842
  // src/providers/adapter.ts
1719
- import { z as z15 } from "zod";
1843
+ import { z as z16 } from "zod";
1720
1844
 
1721
1845
  // src/model/events.ts
1722
- import { z as z14 } from "zod";
1846
+ import { z as z15 } from "zod";
1723
1847
 
1724
1848
  // src/model/target.ts
1725
- import { z as z13 } from "zod";
1726
- var targetSourceSchema = z13.enum(["tool-path", "shell-cwd", "session-cwd"]);
1849
+ import { z as z14 } from "zod";
1850
+ var targetSourceSchema = z14.enum(["tool-path", "shell-cwd", "session-cwd"]);
1727
1851
  var MAX_TARGET_HINT_PATHS = 8;
1728
1852
  var MAX_TARGET_PATH_LENGTH = 4096;
1729
- var localPathSchema = z13.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
1730
- var targetHintSchema = z13.strictObject({
1853
+ var localPathSchema = z14.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
1854
+ var targetHintSchema = z14.strictObject({
1731
1855
  source: targetSourceSchema,
1732
- paths: z13.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
1856
+ paths: z14.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
1733
1857
  /** Absolute directory that relative `paths` resolve against. */
1734
1858
  baseDirectory: localPathSchema.optional()
1735
1859
  }).readonly();
1736
- var worktreeKindSchema = z13.enum(["main", "linked"]);
1737
- var workspaceTargetSchema = z13.strictObject({
1860
+ var worktreeKindSchema = z14.enum(["main", "linked"]);
1861
+ var workspaceTargetSchema = z14.strictObject({
1738
1862
  workspaceId: workspaceIdSchema,
1739
1863
  /** Branch checked out in that worktree; absent on a detached HEAD. */
1740
1864
  vcsBranchName: nonEmptyStringSchema.optional(),
@@ -1744,22 +1868,22 @@ var workspaceTargetSchema = z13.strictObject({
1744
1868
  worktreeKind: worktreeKindSchema.optional()
1745
1869
  }).readonly();
1746
1870
  var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
1747
- var subagentIdSchema = z13.string().regex(SUBAGENT_ID_PATTERN);
1871
+ var subagentIdSchema = z14.string().regex(SUBAGENT_ID_PATTERN);
1748
1872
 
1749
1873
  // src/model/events.ts
1750
- var modelDescriptorSchema = z14.strictObject({
1874
+ var modelDescriptorSchema = z15.strictObject({
1751
1875
  modelId: nonEmptyStringSchema,
1752
1876
  /** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
1753
1877
  vendor: nonEmptyStringSchema.optional(),
1754
1878
  family: nonEmptyStringSchema.optional()
1755
1879
  });
1756
- var costFactsSchema = z14.strictObject({
1880
+ var costFactsSchema = z15.strictObject({
1757
1881
  /** ISO 4217 code. */
1758
- currency: z14.string().length(3),
1759
- amount: z14.number().min(0).finite(),
1760
- source: z14.enum(["provider-reported", "computed"])
1882
+ currency: z15.string().length(3),
1883
+ amount: z15.number().min(0).finite(),
1884
+ source: z15.enum(["provider-reported", "computed"])
1761
1885
  });
1762
- var canonicalEventTypeSchema = z14.enum([
1886
+ var canonicalEventTypeSchema = z15.enum([
1763
1887
  "session.start",
1764
1888
  "session.end",
1765
1889
  "prompt.submitted",
@@ -1773,7 +1897,7 @@ var canonicalEventTypeSchema = z14.enum([
1773
1897
  "error.raised"
1774
1898
  ]);
1775
1899
  var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
1776
- var outcomeSchema = z14.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
1900
+ var outcomeSchema = z15.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
1777
1901
  var baseEventFields = {
1778
1902
  schemaVersion: canonicalSchemaVersionSchema,
1779
1903
  eventId: eventIdSchema,
@@ -1792,10 +1916,10 @@ var baseEventFields = {
1792
1916
  subagentId: subagentIdSchema.optional(),
1793
1917
  extensions: extensionsSchema.default(emptyExtensions)
1794
1918
  };
1795
- var event = (shape) => z14.strictObject({ ...baseEventFields, ...shape });
1919
+ var event = (shape) => z15.strictObject({ ...baseEventFields, ...shape });
1796
1920
  var sessionStartEventSchema = event({
1797
- type: z14.literal("session.start"),
1798
- sessionKind: z14.enum(["interactive", "non-interactive", "unknown"]),
1921
+ type: z15.literal("session.start"),
1922
+ sessionKind: z15.enum(["interactive", "non-interactive", "unknown"]),
1799
1923
  agentName: nonEmptyStringSchema.optional(),
1800
1924
  agentVersion: nonEmptyStringSchema.optional(),
1801
1925
  model: modelDescriptorSchema.optional(),
@@ -1803,30 +1927,30 @@ var sessionStartEventSchema = event({
1803
1927
  target: workspaceTargetSchema.optional()
1804
1928
  });
1805
1929
  var sessionEndEventSchema = event({
1806
- type: z14.literal("session.end"),
1807
- reason: z14.enum(["completed", "aborted", "error", "timeout", "unknown"]),
1930
+ type: z15.literal("session.end"),
1931
+ reason: z15.enum(["completed", "aborted", "error", "timeout", "unknown"]),
1808
1932
  durationMillis: durationMillisSchema.optional(),
1809
1933
  /** Session totals, typically cumulative. */
1810
1934
  usage: canonicalUsageSchema.optional(),
1811
1935
  cost: costFactsSchema.optional()
1812
1936
  });
1813
1937
  var promptSubmittedEventSchema = event({
1814
- type: z14.literal("prompt.submitted"),
1815
- promptSource: z14.enum(["user", "automation", "resumed", "unknown"]),
1938
+ type: z15.literal("prompt.submitted"),
1939
+ promptSource: z15.enum(["user", "automation", "resumed", "unknown"]),
1816
1940
  content: contentFactSchema.optional(),
1817
- turnIndex: z14.number().int().min(0).optional(),
1941
+ turnIndex: z15.number().int().min(0).optional(),
1818
1942
  /** The git worktree the session runs in, resolved by the core (ADR 0008). */
1819
1943
  target: workspaceTargetSchema.optional()
1820
1944
  });
1821
1945
  var generationStartEventSchema = event({
1822
- type: z14.literal("generation.start"),
1946
+ type: z15.literal("generation.start"),
1823
1947
  generationId: nonEmptyStringSchema,
1824
1948
  model: modelDescriptorSchema,
1825
1949
  requestedMaxOutputTokens: tokenCountSchema.optional(),
1826
1950
  inputContent: contentFactsSchema.optional()
1827
1951
  });
1828
1952
  var generationEndEventSchema = event({
1829
- type: z14.literal("generation.end"),
1953
+ type: z15.literal("generation.end"),
1830
1954
  generationId: nonEmptyStringSchema,
1831
1955
  model: modelDescriptorSchema,
1832
1956
  outcome: outcomeSchema,
@@ -1836,7 +1960,7 @@ var generationEndEventSchema = event({
1836
1960
  cost: costFactsSchema.optional(),
1837
1961
  outputContent: contentFactsSchema.optional()
1838
1962
  });
1839
- var toolKindSchema = z14.enum([
1963
+ var toolKindSchema = z15.enum([
1840
1964
  "read",
1841
1965
  "write",
1842
1966
  "execute",
@@ -1847,7 +1971,7 @@ var toolKindSchema = z14.enum([
1847
1971
  "unknown"
1848
1972
  ]);
1849
1973
  var toolStartEventSchema = event({
1850
- type: z14.literal("tool.start"),
1974
+ type: z15.literal("tool.start"),
1851
1975
  toolCallId: nonEmptyStringSchema,
1852
1976
  toolName: nonEmptyStringSchema,
1853
1977
  toolKind: toolKindSchema,
@@ -1857,53 +1981,53 @@ var toolStartEventSchema = event({
1857
1981
  target: workspaceTargetSchema.optional()
1858
1982
  });
1859
1983
  var toolEndEventSchema = event({
1860
- type: z14.literal("tool.end"),
1984
+ type: z15.literal("tool.end"),
1861
1985
  toolCallId: nonEmptyStringSchema,
1862
1986
  toolName: nonEmptyStringSchema,
1863
1987
  outcome: outcomeSchema,
1864
1988
  durationMillis: durationMillisSchema.optional(),
1865
1989
  /** Present when the host asked for or recorded a permission decision. */
1866
- permissionDecision: z14.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
1990
+ permissionDecision: z15.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
1867
1991
  output: contentFactSchema.optional(),
1868
1992
  /** The git worktree this call targeted, resolved by the core (ADR 0008). */
1869
1993
  target: workspaceTargetSchema.optional()
1870
1994
  });
1871
1995
  var subagentStartEventSchema = event({
1872
- type: z14.literal("subagent.start"),
1996
+ type: z15.literal("subagent.start"),
1873
1997
  subagentInvocationId: invocationIdSchema,
1874
1998
  subagentType: nonEmptyStringSchema.optional(),
1875
1999
  /** 0 for the top-level agent; 1 for its direct children. */
1876
- delegationDepth: z14.number().int().min(0).max(64),
2000
+ delegationDepth: z15.number().int().min(0).max(64),
1877
2001
  model: modelDescriptorSchema.optional()
1878
2002
  });
1879
2003
  var subagentEndEventSchema = event({
1880
- type: z14.literal("subagent.end"),
2004
+ type: z15.literal("subagent.end"),
1881
2005
  subagentInvocationId: invocationIdSchema,
1882
2006
  outcome: outcomeSchema,
1883
2007
  durationMillis: durationMillisSchema.optional(),
1884
2008
  usage: canonicalUsageSchema.optional()
1885
2009
  });
1886
2010
  var compactionPerformedEventSchema = event({
1887
- type: z14.literal("compaction.performed"),
1888
- trigger: z14.enum(["automatic", "manual", "unknown"]),
2011
+ type: z15.literal("compaction.performed"),
2012
+ trigger: z15.enum(["automatic", "manual", "unknown"]),
1889
2013
  /** Provider-reported context size before and after compaction, if known. */
1890
2014
  contextTokensBefore: tokenCountSchema.optional(),
1891
2015
  contextTokensAfter: tokenCountSchema.optional(),
1892
- droppedMessageCount: z14.number().int().min(0).optional(),
2016
+ droppedMessageCount: z15.number().int().min(0).optional(),
1893
2017
  usage: canonicalUsageSchema.optional()
1894
2018
  });
1895
2019
  var errorRaisedEventSchema = event({
1896
- type: z14.literal("error.raised"),
2020
+ type: z15.literal("error.raised"),
1897
2021
  errorCode: otelHookErrorCodeSchema,
1898
2022
  severity: errorSeveritySchema,
1899
2023
  phase: errorPhaseSchema,
1900
- retryable: z14.boolean(),
2024
+ retryable: z15.boolean(),
1901
2025
  /** Error text is content: it is described, never embedded verbatim by default. */
1902
2026
  message: contentFactSchema.optional(),
1903
2027
  /** Non-sensitive, provider-agnostic short label. */
1904
2028
  detail: nonEmptyStringSchema.optional()
1905
2029
  });
1906
- var canonicalEventSchema = z14.discriminatedUnion("type", [
2030
+ var canonicalEventSchema = z15.discriminatedUnion("type", [
1907
2031
  sessionStartEventSchema,
1908
2032
  sessionEndEventSchema,
1909
2033
  promptSubmittedEventSchema,
@@ -1921,26 +2045,26 @@ var TARGETED = new Set(TARGETED_EVENT_TYPES);
1921
2045
  var isTargetedEvent = (event2) => TARGETED.has(event2.type);
1922
2046
 
1923
2047
  // src/providers/adapter.ts
1924
- var providerDetectionSchema = z15.strictObject({
2048
+ var providerDetectionSchema = z16.strictObject({
1925
2049
  providerId: resolvedProviderIdSchema,
1926
2050
  confidence: detectionConfidenceSchema,
1927
2051
  /**
1928
2052
  * Short, non-sensitive justifications, e.g. `"payload.hook_event_name present"`.
1929
2053
  * Reasons are exported in diagnostics, so they must not quote payload values.
1930
2054
  */
1931
- reasons: z15.array(z15.string().min(1).max(160)).max(8),
2055
+ reasons: z16.array(z16.string().min(1).max(160)).max(8),
1932
2056
  providerVersion: nonEmptyStringSchema.optional(),
1933
2057
  /** The provider's own name for this event, when the payload states one. */
1934
2058
  sourceEventName: nonEmptyStringSchema.optional()
1935
2059
  });
1936
- var deliveryIdentifierSupportSchema = z15.enum(["none", "partial", "all"]);
2060
+ var deliveryIdentifierSupportSchema = z16.enum(["none", "partial", "all"]);
1937
2061
  var DELIVERY_COMPONENT_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
1938
- var deliveryComponentSchema = z15.string().regex(
2062
+ var deliveryComponentSchema = z16.string().regex(
1939
2063
  DELIVERY_COMPONENT_PATTERN,
1940
2064
  "delivery component must be identifier-shaped: no whitespace, no path separators"
1941
2065
  );
1942
2066
  var MAX_DELIVERY_COMPONENTS = 8;
1943
- var providerDeliveryClaimSchema = z15.strictObject({
2067
+ var providerDeliveryClaimSchema = z16.strictObject({
1944
2068
  /**
1945
2069
  * The provider's own session/conversation id. Scopes the callback identity, so
1946
2070
  * two sessions reusing one tool-call id never collide.
@@ -1952,26 +2076,26 @@ var providerDeliveryClaimSchema = z15.strictObject({
1952
2076
  * Identifier-shaped payload fields that, together with `sourceEventName`,
1953
2077
  * name this callback within the session exactly once.
1954
2078
  */
1955
- components: z15.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
2079
+ components: z16.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
1956
2080
  /**
1957
2081
  * Short, non-sensitive justifications, e.g. `"payload.tool_use_id names one
1958
2082
  * tool call"`. Evidence reaches diagnostics, so it must name fields, never
1959
2083
  * quote their values.
1960
2084
  */
1961
- evidence: z15.array(z15.string().min(1).max(160)).min(1).max(4).readonly()
2085
+ evidence: z16.array(z16.string().min(1).max(160)).min(1).max(4).readonly()
1962
2086
  });
1963
2087
  var DELIVERY_GAP_REASON_PATTERN = /^[^\n\r\t\\/]{1,240}$/;
1964
- var deliveryGapReasonSchema = z15.string().regex(
2088
+ var deliveryGapReasonSchema = z16.string().regex(
1965
2089
  DELIVERY_GAP_REASON_PATTERN,
1966
2090
  "delivery gap reason must be one line of prose: no path separators, no control characters"
1967
2091
  );
1968
2092
  var MAX_DELIVERY_GAPS = 48;
1969
- var providerDeliveryGapsSchema = z15.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
2093
+ var providerDeliveryGapsSchema = z16.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
1970
2094
  message: `at most ${String(MAX_DELIVERY_GAPS)} delivery gaps may be declared`
1971
2095
  });
1972
- var providerCapabilitiesSchema = z15.strictObject({
2096
+ var providerCapabilitiesSchema = z16.strictObject({
1973
2097
  /** Event types the adapter can produce. */
1974
- lifecycleEvents: z15.array(canonicalEventTypeSchema).max(32).readonly(),
2098
+ lifecycleEvents: z16.array(canonicalEventTypeSchema).max(32).readonly(),
1975
2099
  usageTemporality: usageTemporalitySchema,
1976
2100
  /**
1977
2101
  * Which accumulator series a `cumulative` report continues — that is, which
@@ -1990,32 +2114,32 @@ var providerCapabilitiesSchema = z15.strictObject({
1990
2114
  * Subagent snapshots keep their own series regardless: a delegated agent's
1991
2115
  * counter is not a point on the parent session's curve.
1992
2116
  */
1993
- cumulativeUsageSeries: z15.enum(["event-scope", "session-lifetime"]).optional(),
1994
- reportsCachedInput: z15.boolean(),
1995
- reportsCacheCreation: z15.boolean(),
2117
+ cumulativeUsageSeries: z16.enum(["event-scope", "session-lifetime"]).optional(),
2118
+ reportsCachedInput: z16.boolean(),
2119
+ reportsCacheCreation: z16.boolean(),
1996
2120
  cacheCreationAccounting: cacheCreationAccountingSchema,
1997
- reportsReasoningOutput: z15.boolean(),
1998
- reportsProviderTotal: z15.boolean(),
1999
- reportsCost: z15.boolean(),
2000
- emitsSubagentEvents: z15.boolean(),
2001
- emitsCompactionEvents: z15.boolean(),
2121
+ reportsReasoningOutput: z16.boolean(),
2122
+ reportsProviderTotal: z16.boolean(),
2123
+ reportsCost: z16.boolean(),
2124
+ emitsSubagentEvents: z16.boolean(),
2125
+ emitsCompactionEvents: z16.boolean(),
2002
2126
  /** True when the provider reads a structured response from stdout. */
2003
- requiresHookResponse: z15.boolean(),
2127
+ requiresHookResponse: z16.boolean(),
2004
2128
  /** How much of this provider's hook traffic is replay-identifiable. */
2005
2129
  deliveryIdentifier: deliveryIdentifierSupportSchema
2006
2130
  });
2007
- var providerHookResponseSchema = z15.strictObject({
2131
+ var providerHookResponseSchema = z16.strictObject({
2008
2132
  /**
2009
2133
  * Always 0. A telemetry hook that can fail the host agent is a liability, so
2010
2134
  * the type forbids expressing anything else (ADR 0004).
2011
2135
  */
2012
- exitCode: z15.literal(0),
2136
+ exitCode: z16.literal(0),
2013
2137
  /** Protocol response text. Omit to write nothing at all. */
2014
- stdout: z15.string().max(8192).optional(),
2138
+ stdout: z16.string().max(8192).optional(),
2015
2139
  /** Non-sensitive diagnostic text for stderr. */
2016
- stderr: z15.string().max(8192).optional(),
2140
+ stderr: z16.string().max(8192).optional(),
2017
2141
  /** Declares which of the two stdout contracts this response follows. */
2018
- contract: z15.enum(["silent", "provider-protocol"])
2142
+ contract: z16.enum(["silent", "provider-protocol"])
2019
2143
  });
2020
2144
  var SILENT_HOOK_RESPONSE = Object.freeze({
2021
2145
  exitCode: 0,
@@ -2347,7 +2471,7 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
2347
2471
  };
2348
2472
 
2349
2473
  // src/runtime/hook.ts
2350
- var usageScopeSchema = z16.enum(["session", "generation", "subagent"]);
2474
+ var usageScopeSchema = z17.enum(["session", "generation", "subagent"]);
2351
2475
  var classifyDurability = (input) => {
2352
2476
  if (!input.attempted) {
2353
2477
  return "nothing-to-deliver";