@osfactory/otel-hook 0.13.1 → 0.14.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.
Files changed (41) hide show
  1. package/README.md +94 -3
  2. package/dist/{adapter-DyCb7y1N.d.ts → adapter-D5R8lhfl.d.ts} +1 -1
  3. package/dist/cli.js +1240 -200
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +32 -4
  6. package/dist/config.js +200 -14
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-DvqsPulb.d.ts → destinations-2KrcRslo.d.ts} +92 -2
  9. package/dist/{export-destinations-DUeQKr_C.d.ts → export-destinations-DvoH4QOe.d.ts} +135 -11
  10. package/dist/{hook-D5imE0Qc.d.ts → hook-DVK8Don-.d.ts} +4 -4
  11. package/dist/index.d.ts +11 -11
  12. package/dist/index.js +1262 -228
  13. package/dist/index.js.map +1 -1
  14. package/dist/install.d.ts +3 -3
  15. package/dist/install.js +1 -0
  16. package/dist/install.js.map +1 -1
  17. package/dist/integration.d.ts +16 -9
  18. package/dist/integration.js +1298 -205
  19. package/dist/integration.js.map +1 -1
  20. package/dist/lifecycle.js +1 -1
  21. package/dist/lifecycle.js.map +1 -1
  22. package/dist/{payload-CdDKeRpH.d.ts → payload-D4r71EL-.d.ts} +18 -2
  23. package/dist/privacy.d.ts +2 -2
  24. package/dist/privacy.js +42 -1
  25. package/dist/privacy.js.map +1 -1
  26. package/dist/providers.d.ts +94 -9
  27. package/dist/providers.js +300 -2
  28. package/dist/providers.js.map +1 -1
  29. package/dist/{registry-BKQhhIO3.d.ts → registry-DOJh9mzB.d.ts} +2 -2
  30. package/dist/runtime.d.ts +5 -5
  31. package/dist/runtime.js +151 -5
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/{schema-SpFM6YQY.d.ts → schema-oRsbo7WO.d.ts} +77 -3
  34. package/dist/{service-CbI9CObT.d.ts → service-DySC7KQM.d.ts} +6 -1
  35. package/dist/telemetry.d.ts +5 -4
  36. package/dist/telemetry.js +1076 -476
  37. package/dist/telemetry.js.map +1 -1
  38. package/dist/testing.d.ts +5 -5
  39. package/dist/testing.js +178 -21
  40. package/dist/testing.js.map +1 -1
  41. package/package.json +1 -1
package/dist/testing.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { O as OtelHookConfig, i as OtelHookConfigPatch } from './schema-SpFM6YQY.js';
1
+ import { O as OtelHookConfig, k as OtelHookConfigPatch } from './schema-oRsbo7WO.js';
2
2
  import { b as CanonicalEvent } from './events-fcomX6d5.js';
3
3
  import { I as IdentityClaim, d as InvocationIdentity, S as SourceProvenance } from './identity-BrVBs901.js';
4
- import { P as PrivacyService } from './service-CbI9CObT.js';
5
- import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-DyCb7y1N.js';
6
- import { P as ProviderRegistry } from './registry-BKQhhIO3.js';
4
+ import { P as PrivacyService } from './service-DySC7KQM.js';
5
+ import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-D5R8lhfl.js';
6
+ import { P as ProviderRegistry } from './registry-DOJh9mzB.js';
7
7
  import { I as IdGenerator, W as WorktreeLocator, P as PayloadEnricher, S as SessionContextReader } from './ports-DhpSDIkp.js';
8
8
  import { c as RecordingTelemetrySink, I as InMemoryStateStore, F as FixedClock, R as RecordingLogger } from './memory-B3r6sZtC.js';
9
9
  export { e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, j as createRecordingLogger, k as createRecordingTelemetrySink } from './memory-B3r6sZtC.js';
10
- import { O as OtelHook } from './hook-D5imE0Qc.js';
10
+ import { O as OtelHook } from './hook-DVK8Don-.js';
11
11
  import { z } from 'zod';
12
12
  import { a as ContentDisclosure, b as ContentFact } from './content-M9xIKG7h.js';
13
13
  import './primitives-CJ8-rn-f.js';
package/dist/testing.js CHANGED
@@ -153,6 +153,59 @@ var OTLP_HEADER_VARIABLES = Object.freeze({
153
153
  logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
154
154
  });
155
155
 
156
+ // src/config/repository-key.ts
157
+ var MAX_REPOSITORY_REFERENCE_LENGTH = 2048;
158
+ var SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
159
+ var SCP_LIKE_PATTERN = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)(.+)$/;
160
+ var trimTrailingSlashes = (value) => {
161
+ let end = value.length;
162
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
163
+ return value.slice(0, end);
164
+ };
165
+ var keyOf = (host, pathname) => {
166
+ const withoutSlashes = trimTrailingSlashes(pathname);
167
+ const cleanedPath = trimTrailingSlashes(
168
+ withoutSlashes.toLowerCase().endsWith(".git") ? withoutSlashes.slice(0, -4) : withoutSlashes
169
+ );
170
+ if (host.length === 0 || cleanedPath.length === 0 || cleanedPath === "/") {
171
+ return void 0;
172
+ }
173
+ const withSlash = cleanedPath.startsWith("/") ? cleanedPath : `/${cleanedPath}`;
174
+ return `${host}${withSlash}`.toLowerCase();
175
+ };
176
+ var normalizeRepositoryKey = (reference) => {
177
+ const trimmed = reference.trim();
178
+ if (trimmed.length === 0 || trimmed.length > MAX_REPOSITORY_REFERENCE_LENGTH) {
179
+ return void 0;
180
+ }
181
+ if (SCHEME_PATTERN.test(trimmed)) {
182
+ let url;
183
+ try {
184
+ url = new URL(trimmed);
185
+ } catch {
186
+ return void 0;
187
+ }
188
+ if (url.protocol === "file:") {
189
+ return void 0;
190
+ }
191
+ return keyOf(url.hostname, url.pathname);
192
+ }
193
+ if (trimmed.startsWith("/") || trimmed.startsWith(".") || trimmed.includes("\\")) {
194
+ return void 0;
195
+ }
196
+ const scp = SCP_LIKE_PATTERN.exec(trimmed);
197
+ if (scp !== null && !trimmed.split(":")[0]?.includes("/")) {
198
+ const [, host, pathPart] = scp;
199
+ return host === void 0 || pathPart === void 0 ? void 0 : keyOf(host, pathPart);
200
+ }
201
+ try {
202
+ const url = new URL(`https://${trimmed}`);
203
+ return keyOf(url.hostname, url.pathname);
204
+ } catch {
205
+ return void 0;
206
+ }
207
+ };
208
+
156
209
  // src/config/destinations.ts
157
210
  var DEFAULT_DESTINATION_NAME = "default";
158
211
  var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
@@ -171,6 +224,30 @@ var headerValueSchema = z3.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
171
224
  "an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
172
225
  );
173
226
  var endpointSchema = z3.string().url().max(2048);
227
+ var MAX_DESTINATION_SCOPES = 64;
228
+ var MAX_SCOPE_REPOSITORIES = 256;
229
+ var ALL_REPOSITORIES = "*";
230
+ var repositoryReferenceSchema = z3.string().min(1).max(MAX_REPOSITORY_REFERENCE_LENGTH).refine(
231
+ (value) => normalizeRepositoryKey(value) !== void 0,
232
+ "not a repository URL: use https://host/owner/repo, git@host:owner/repo.git, or host/owner/repo"
233
+ );
234
+ var destinationScopeSchema = z3.strictObject({
235
+ /**
236
+ * Repository URLs (any spelling of the remote; compared by host and path,
237
+ * case-insensitively, without `.git`), or `"*"` for every record that names
238
+ * a repository. A record that names none never matches a scope.
239
+ */
240
+ repositories: z3.union([
241
+ z3.literal(ALL_REPOSITORIES),
242
+ z3.array(repositoryReferenceSchema).min(1).max(MAX_SCOPE_REPOSITORIES).readonly()
243
+ ]),
244
+ /** Signals sent for these repositories. Default: every signal the destination takes. */
245
+ signals: z3.array(exportSignalSchema).min(1).max(3).readonly().optional(),
246
+ /** Content disclosure for these repositories, never above `privacy.contentMode`. Default: unchanged. */
247
+ contentMode: contentModeSchema.optional(),
248
+ /** False leaves `session.id` off metric data points for these repositories. Default true. */
249
+ includeSessionId: z3.boolean().optional()
250
+ });
174
251
  var exportDestinationSchema = z3.strictObject({
175
252
  /** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
176
253
  name: z3.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
@@ -204,7 +281,15 @@ var exportDestinationSchema = z3.strictObject({
204
281
  * opt-in for content-bearing records leaving the host. `metrics` is never on by
205
282
  * default: a destination receives hook-derived metrics only when it lists them.
206
283
  */
207
- signals: z3.array(exportSignalSchema).min(1).max(3).readonly().optional()
284
+ signals: z3.array(exportSignalSchema).min(1).max(3).readonly().optional(),
285
+ /**
286
+ * Per-repository filter. Absent: every record goes to this destination, as
287
+ * before scopes existed. Present: a record goes only when its repository
288
+ * (`vcs.repository.url.full`) matches a scope — the first matching scope
289
+ * decides its signals, content mode, and session id — and a record that
290
+ * names no repository is not sent here at all.
291
+ */
292
+ scopes: z3.array(destinationScopeSchema).min(1).max(MAX_DESTINATION_SCOPES).readonly().optional()
208
293
  }).refine(
209
294
  (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
210
295
  "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
@@ -397,7 +482,22 @@ var exporterPolicySchema = z5.strictObject({
397
482
  * Per-destination retry spool bounds, each optional and merged per leaf; any
398
483
  * bound left unset takes its value from `DEFAULT_SPOOL_POLICY`.
399
484
  */
400
- spool: spoolPolicySchema.partial().optional()
485
+ spool: spoolPolicySchema.partial().optional(),
486
+ /**
487
+ * The most time one hook invocation spends trying to reach one endpoint, in
488
+ * milliseconds: caps `timeoutMillis` for every OTLP request (connection setup
489
+ * included) and the exporter's own retries inside it. A batch that does not
490
+ * get through in time is spooled. Default {@link DEFAULT_EXPORT_BUDGET_MILLIS}:
491
+ * the host agent waits for its hooks, so a down collector must not stall it.
492
+ */
493
+ exportBudgetMillis: z5.number().int().min(50).max(6e5).optional(),
494
+ /**
495
+ * After an endpoint was unreachable (refused, timed out, or answered a
496
+ * retryable status), every hook spools for it without trying for this long,
497
+ * in milliseconds; then one hook probes it again. 0 disables the window.
498
+ * Default {@link DEFAULT_ENDPOINT_DOWN_MILLIS}.
499
+ */
500
+ endpointDownMillis: z5.number().int().min(0).max(36e5).optional()
401
501
  });
402
502
  var detectionPolicySchema = z5.strictObject({
403
503
  /** Detections below this confidence resolve to the unknown provider. */
@@ -415,6 +515,9 @@ var diagnosticsPolicySchema = z5.strictObject({
415
515
  var providersPolicySchema = z5.strictObject({
416
516
  claudeCode: z5.strictObject({
417
517
  readTranscriptUsage: z5.boolean()
518
+ }).optional(),
519
+ codex: z5.strictObject({
520
+ readRolloutUsage: z5.boolean()
418
521
  }).optional()
419
522
  });
420
523
  var sessionContextPolicySchema = z5.strictObject({
@@ -444,7 +547,8 @@ var otelHookConfigPatchSchema = z5.strictObject({
444
547
  detection: detectionPolicySchema.partial().optional(),
445
548
  diagnostics: diagnosticsPolicySchema.partial().optional(),
446
549
  providers: z5.strictObject({
447
- claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional()
550
+ claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional(),
551
+ codex: z5.strictObject({ readRolloutUsage: z5.boolean() }).partial().optional()
448
552
  }).partial().optional(),
449
553
  sessionContext: sessionContextPolicySchema.partial().optional()
450
554
  });
@@ -471,7 +575,8 @@ var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
471
575
  emitErrorEvents: true
472
576
  });
473
577
  var DEFAULT_PROVIDERS_POLICY = Object.freeze({
474
- claudeCode: Object.freeze({ readTranscriptUsage: false })
578
+ claudeCode: Object.freeze({ readTranscriptUsage: false }),
579
+ codex: Object.freeze({ readRolloutUsage: false })
475
580
  });
476
581
  var DEFAULT_CONFIG = Object.freeze({
477
582
  exporter: DEFAULT_EXPORTER_POLICY,
@@ -706,6 +811,23 @@ var EMPTY_EXTENSIONS = Object.freeze({});
706
811
  var emptyExtensions = () => ({});
707
812
 
708
813
  // src/privacy/service.ts
814
+ var DISCLOSURE_RANK = Object.freeze({
815
+ omitted: 0,
816
+ masked: 1,
817
+ redacted: 2,
818
+ raw: 3
819
+ });
820
+ var WHITESPACE = /\s/u;
821
+ var withoutTrailingToken = (text) => {
822
+ let end = text.length;
823
+ while (end > 0) {
824
+ const low = text.charCodeAt(end - 1);
825
+ const width = end >= 2 && low >= 56320 && low <= 57343 ? 2 : 1;
826
+ if (WHITESPACE.test(text.slice(end - width, end))) break;
827
+ end -= width;
828
+ }
829
+ return text.slice(0, end);
830
+ };
709
831
  var compilePatterns = (sources, flags) => {
710
832
  const compiled = [];
711
833
  for (const source of sources) {
@@ -923,11 +1045,11 @@ var createPrivacyService = (policyInput) => {
923
1045
  };
924
1046
  const flattenToAttributes = (value, prefix) => {
925
1047
  const attributes = {};
926
- const walk = (current, path4) => {
1048
+ const walk = (current, path5) => {
927
1049
  if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
928
1050
  const primitive = toAttributePrimitive(current);
929
1051
  if (primitive !== void 0) {
930
- attributes[path4] = primitive;
1052
+ attributes[path5] = primitive;
931
1053
  }
932
1054
  return;
933
1055
  }
@@ -946,16 +1068,16 @@ var createPrivacyService = (policyInput) => {
946
1068
  primitives.push(entryPrimitive);
947
1069
  }
948
1070
  if (uniform) {
949
- attributes[path4] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
1071
+ attributes[path5] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
950
1072
  return;
951
1073
  }
952
1074
  for (const [index, entry] of current.entries()) {
953
- walk(entry, `${path4}.${index}`);
1075
+ walk(entry, `${path5}.${index}`);
954
1076
  }
955
1077
  return;
956
1078
  }
957
1079
  for (const [key, entry] of Object.entries(current)) {
958
- walk(entry, path4 === "" ? key : `${path4}.${key}`);
1080
+ walk(entry, path5 === "" ? key : `${path5}.${key}`);
959
1081
  }
960
1082
  };
961
1083
  walk(value, prefix);
@@ -1043,7 +1165,31 @@ var createPrivacyService = (policyInput) => {
1043
1165
  flattenToAttributes,
1044
1166
  sanitizeAttributes,
1045
1167
  sanitizeExtensions,
1046
- boundString
1168
+ boundString,
1169
+ restrictContent: (fact, mode) => {
1170
+ const target = CONTENT_MODE_DISCLOSURE[mode];
1171
+ if (fact.text === void 0 || DISCLOSURE_RANK[fact.disclosure] <= DISCLOSURE_RANK[target]) {
1172
+ return fact;
1173
+ }
1174
+ const { text, ...rest } = fact;
1175
+ switch (target) {
1176
+ case "omitted":
1177
+ return { ...rest, disclosure: "omitted", truncated: false };
1178
+ case "masked":
1179
+ return { ...rest, disclosure: "masked", text: maskText(text) };
1180
+ case "redacted": {
1181
+ const redacted = redactSecretSpans(fact.truncated ? withoutTrailingToken(text) : text);
1182
+ return {
1183
+ ...rest,
1184
+ disclosure: "redacted",
1185
+ text: redacted.text,
1186
+ secretsRedacted: fact.secretsRedacted + redacted.count
1187
+ };
1188
+ }
1189
+ case "raw":
1190
+ return fact;
1191
+ }
1192
+ }
1047
1193
  };
1048
1194
  };
1049
1195
 
@@ -4202,6 +4348,7 @@ var permissionModeSchema = z18.enum([
4202
4348
  var codexUsageSchema = z18.object({
4203
4349
  input_tokens: z18.number().int().min(0).optional(),
4204
4350
  cached_input_tokens: z18.number().int().min(0).optional(),
4351
+ cache_write_input_tokens: z18.number().int().min(0).optional(),
4205
4352
  output_tokens: z18.number().int().min(0).optional(),
4206
4353
  reasoning_output_tokens: z18.number().int().min(0).optional(),
4207
4354
  total_tokens: z18.number().int().min(0).optional()
@@ -4457,6 +4604,10 @@ var codexUsageToReport = (usage, temporality) => ({
4457
4604
  temporality,
4458
4605
  ...usage.input_tokens === void 0 ? {} : { inputTokens: usage.input_tokens },
4459
4606
  ...usage.cached_input_tokens === void 0 ? {} : { cachedInputTokens: usage.cached_input_tokens },
4607
+ ...usage.cache_write_input_tokens === void 0 ? {} : {
4608
+ cacheCreationInputTokens: usage.cache_write_input_tokens,
4609
+ cacheCreationAccounting: "included-in-input"
4610
+ },
4460
4611
  ...usage.output_tokens === void 0 ? {} : { outputTokens: usage.output_tokens },
4461
4612
  ...usage.reasoning_output_tokens === void 0 ? {} : { reasoningOutputTokens: usage.reasoning_output_tokens },
4462
4613
  ...usage.total_tokens === void 0 ? {} : { providerTotalTokens: usage.total_tokens }
@@ -4485,8 +4636,9 @@ var CODEX_CAPABILITIES = Object.freeze({
4485
4636
  // turn; see docs/usage-semantics.md.
4486
4637
  cumulativeUsageSeries: "session-lifetime",
4487
4638
  reportsCachedInput: true,
4488
- reportsCacheCreation: false,
4489
- cacheCreationAccounting: "not-reported",
4639
+ // Codex 0.163+ reports `cache_write_input_tokens`, a subset of `input_tokens`.
4640
+ reportsCacheCreation: true,
4641
+ cacheCreationAccounting: "included-in-input",
4490
4642
  reportsReasoningOutput: true,
4491
4643
  reportsProviderTotal: true,
4492
4644
  reportsCost: false,
@@ -4845,6 +4997,11 @@ var createCodexAdapter = () => ({
4845
4997
  hookResponse
4846
4998
  });
4847
4999
 
5000
+ // src/providers/codex/rollout-usage.ts
5001
+ import { createHash as createHash3 } from "crypto";
5002
+ import { open as open2, readdir, stat as stat2 } from "fs/promises";
5003
+ import path2 from "path";
5004
+
4848
5005
  // src/providers/gemini/delivery.ts
4849
5006
  var GEMINI_UNIDENTIFIABLE_CALLBACKS = Object.freeze({
4850
5007
  SessionStart: "fires again within the same session_id on resume and clear (payload `source`), so session_id names a class of firings rather than one",
@@ -5869,9 +6026,9 @@ var resolveDeliveryIdentity = (input) => {
5869
6026
  };
5870
6027
 
5871
6028
  // src/runtime/ids.ts
5872
- import { createHash as createHash3, randomUUID } from "crypto";
6029
+ import { createHash as createHash4, randomUUID } from "crypto";
5873
6030
  var digest = (namespace, parts) => {
5874
- const hash = createHash3("sha256");
6031
+ const hash = createHash4("sha256");
5875
6032
  hash.update(namespace);
5876
6033
  for (const part of parts) {
5877
6034
  hash.update("\0");
@@ -6003,16 +6160,16 @@ var createNullLogger = () => ({
6003
6160
  });
6004
6161
 
6005
6162
  // src/runtime/target-resolution.ts
6006
- import * as path2 from "path";
6163
+ import * as path3 from "path";
6007
6164
  var DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS = 50;
6008
6165
  var absolutePathsOf = (hint) => {
6009
- const base = hint.baseDirectory !== void 0 && path2.isAbsolute(hint.baseDirectory) ? hint.baseDirectory : void 0;
6166
+ const base = hint.baseDirectory !== void 0 && path3.isAbsolute(hint.baseDirectory) ? hint.baseDirectory : void 0;
6010
6167
  const resolved = [];
6011
6168
  for (const candidate of hint.paths) {
6012
- if (path2.isAbsolute(candidate)) {
6013
- resolved.push(path2.resolve(candidate));
6169
+ if (path3.isAbsolute(candidate)) {
6170
+ resolved.push(path3.resolve(candidate));
6014
6171
  } else if (base !== void 0) {
6015
- resolved.push(path2.resolve(base, candidate));
6172
+ resolved.push(path3.resolve(base, candidate));
6016
6173
  } else {
6017
6174
  return void 0;
6018
6175
  }
@@ -6119,8 +6276,8 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
6119
6276
  };
6120
6277
 
6121
6278
  // src/runtime/session-context.ts
6122
- import { open as open2 } from "fs/promises";
6123
- import * as path3 from "path";
6279
+ import { open as open3 } from "fs/promises";
6280
+ import * as path4 from "path";
6124
6281
  import { z as z22 } from "zod";
6125
6282
  var SESSION_CONTEXT_FILE_VERSION = 1;
6126
6283
  var DEFAULT_SESSION_CONTEXT_MAX_BYTES = 256 * 1024;