@osfactory/otel-hook 0.4.1 → 0.6.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 (43) hide show
  1. package/dist/{adapter-BgqtlADe.d.ts → adapter-BJiz6lqM.d.ts} +2 -3
  2. package/dist/cli.js +100 -35
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{events-C3h3GvHj.d.ts → events-B3MHoJTD.d.ts} +190 -1
  5. package/dist/{filesystem-store-BAq3VGVv.d.ts → filesystem-store-r-nNA3BA.d.ts} +1 -1
  6. package/dist/{hook-CQiNa88Q.d.ts → hook-Dh8OO4Wa.d.ts} +4 -4
  7. package/dist/index.d.ts +12 -13
  8. package/dist/index.js +105 -35
  9. package/dist/index.js.map +1 -1
  10. package/dist/install.d.ts +4 -5
  11. package/dist/install.js +13 -3
  12. package/dist/install.js.map +1 -1
  13. package/dist/integration.d.ts +8 -9
  14. package/dist/integration.js +2299 -2246
  15. package/dist/integration.js.map +1 -1
  16. package/dist/lifecycle.d.ts +3 -3
  17. package/dist/lifecycle.js +762 -213
  18. package/dist/lifecycle.js.map +1 -1
  19. package/dist/{memory-kflYgZbg.d.ts → memory-Bl9ANVff.d.ts} +2 -2
  20. package/dist/model.d.ts +1 -2
  21. package/dist/model.js +20 -4
  22. package/dist/model.js.map +1 -1
  23. package/dist/{otlp-log-sink-BZIgYPKN.d.ts → otlp-log-sink-eUEjaLhk.d.ts} +3 -3
  24. package/dist/{payload-DpyU8F-z.d.ts → payload-Ci8_ERm6.d.ts} +1 -1
  25. package/dist/{ports-B_iwJQPQ.d.ts → ports-n7KFOpKo.d.ts} +9 -1
  26. package/dist/providers.d.ts +10 -11
  27. package/dist/providers.js +37 -14
  28. package/dist/providers.js.map +1 -1
  29. package/dist/{registry-BSBS8t7S.d.ts → registry-CIVvRlVK.d.ts} +1 -1
  30. package/dist/runtime.d.ts +32 -16
  31. package/dist/runtime.js +57 -15
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/{semconv-BeUPQ7_q.d.ts → semconv-fPRb-dpU.d.ts} +1 -1
  34. package/dist/state.d.ts +4 -4
  35. package/dist/state.js.map +1 -1
  36. package/dist/telemetry.d.ts +6 -6
  37. package/dist/telemetry.js +953 -414
  38. package/dist/telemetry.js.map +1 -1
  39. package/dist/testing.d.ts +14 -9
  40. package/dist/testing.js +45 -20
  41. package/dist/testing.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/target-8RfaVxp8.d.ts +0 -83
@@ -1,6 +1,6 @@
1
1
  import { e as DetectionPolicy } from './schema-Cn0-xz8L.js';
2
2
  import { OtelHookErrorInfo } from './errors.js';
3
- import { P as ProviderAdapter, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext } from './adapter-BgqtlADe.js';
3
+ import { P as ProviderAdapter, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext } from './adapter-BJiz6lqM.js';
4
4
 
5
5
  type DetectionCandidate = {
6
6
  readonly adapter: ProviderAdapter;
package/dist/runtime.d.ts CHANGED
@@ -1,20 +1,19 @@
1
- import { c as LogLevel, d as Logger, W as WorktreeLocator } from './ports-B_iwJQPQ.js';
2
- export { A as AppliedDelivery, C as Clock, E as EventIdSeed, I as IdGenerator, a as InvocationIdSeed, L as LOG_LEVEL_RANK, b as LocatedWorktree, S as StateRecord, e as StateStore, f as StateValue, T as TelemetryEmitResult, g as TelemetrySink, h as appliedDeliverySchema, l as logLevelSchema, s as stateRecordSchema, i as stateValueSchema } from './ports-B_iwJQPQ.js';
3
- export { D as DeterministicIdOptions, F as FixedClock, a as FixedClockOptions, I as InMemoryStateStore, b as InMemoryStateStoreOptions, L as LogRecord, R as RecordingLogger, c as RecordingTelemetrySink, d as RecordingTelemetrySinkOptions, e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, h as createNullTelemetrySink, i as createRandomIdGenerator, j as createRecordingLogger, k as createRecordingTelemetrySink, l as createSystemClock } from './memory-kflYgZbg.js';
4
- export { C as CumulativeUsageSeries, D as DeliveryDurability, a as DeliveryOrigin, b as DeliveryResolution, c as DeliveryUnavailableReason, H as HookIngestInput, d as HookIngestOptions, e as HookIngestOutcome, O as OtelHook, f as OtelHookDependencies, R as ResolvedDeliveryIdentity, U as UsageObservation, g as UsageScope, h as classifyDurability, i as createOtelHook, j as hostDeliveryIdentity, k as isCommittable, r as resolveDeliveryIdentity, u as usageScopeSchema } from './hook-CQiNa88Q.js';
5
- import { b as CanonicalEvent } from './events-C3h3GvHj.js';
1
+ import { c as LogLevel, d as Logger, W as WorktreeLocator } from './ports-n7KFOpKo.js';
2
+ export { A as AppliedDelivery, C as Clock, E as EventIdSeed, I as IdGenerator, a as InvocationIdSeed, L as LOG_LEVEL_RANK, b as LocatedWorktree, S as StateRecord, e as StateStore, f as StateValue, T as TelemetryEmitResult, g as TelemetrySink, h as appliedDeliverySchema, l as logLevelSchema, s as stateRecordSchema, i as stateValueSchema } from './ports-n7KFOpKo.js';
3
+ export { D as DeterministicIdOptions, F as FixedClock, a as FixedClockOptions, I as InMemoryStateStore, b as InMemoryStateStoreOptions, L as LogRecord, R as RecordingLogger, c as RecordingTelemetrySink, d as RecordingTelemetrySinkOptions, e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, h as createNullTelemetrySink, i as createRandomIdGenerator, j as createRecordingLogger, k as createRecordingTelemetrySink, l as createSystemClock } from './memory-Bl9ANVff.js';
4
+ export { C as CumulativeUsageSeries, D as DeliveryDurability, a as DeliveryOrigin, b as DeliveryResolution, c as DeliveryUnavailableReason, H as HookIngestInput, d as HookIngestOptions, e as HookIngestOutcome, O as OtelHook, f as OtelHookDependencies, R as ResolvedDeliveryIdentity, U as UsageObservation, g as UsageScope, h as classifyDurability, i as createOtelHook, j as hostDeliveryIdentity, k as isCommittable, r as resolveDeliveryIdentity, u as usageScopeSchema } from './hook-Dh8OO4Wa.js';
5
+ import { b as CanonicalEvent, u as TargetHint } from './events-B3MHoJTD.js';
6
6
  import { d as EventId } from './primitives-CJ8-rn-f.js';
7
- import { T as TargetHint } from './target-8RfaVxp8.js';
8
7
  import { P as PrivacyService } from './service-CbI9CObT.js';
9
8
  import 'zod';
10
9
  import './errors.js';
11
10
  import './taxonomy-DwhTtuWd.js';
12
11
  import './schema-Cn0-xz8L.js';
13
12
  import './identity-BrVBs901.js';
14
- import './adapter-BgqtlADe.js';
13
+ import './adapter-BJiz6lqM.js';
15
14
  import './policy-CimmCfRp.js';
16
15
  import './content-M9xIKG7h.js';
17
- import './registry-BSBS8t7S.js';
16
+ import './registry-CIVvRlVK.js';
18
17
 
19
18
  declare const createNullLogger: () => Logger;
20
19
  type StderrLoggerOptions = {
@@ -42,10 +41,24 @@ declare const createStderrLogger: (options?: StderrLoggerOptions) => Logger;
42
41
  * `gitdir: <path>`, relative to the worktree root when not absolute.
43
42
  *
44
43
  * The branch is read from `<gitdir>/HEAD`: `ref: refs/heads/<name>` names a
45
- * branch; anything else (a detached commit id) names none. A `.git` entry that
46
- * cannot be read, points nowhere, or has no readable `HEAD` makes the answer
47
- * `undefined` — a broken worktree is not evidence, and the walk does not skip
48
- * past it to an enclosing repository that the event did not target.
44
+ * branch; anything else (a detached commit id) names none.
45
+ *
46
+ * Which repository the worktree belongs to is read the same way git reads it:
47
+ *
48
+ * - A git dir holding a `commondir` file is a **linked** worktree's; that file
49
+ * names the repository's common git dir, relative to the git dir. When the
50
+ * common dir is a directory named `.git`, its parent is the main worktree —
51
+ * the path `git worktree list` prints first. Any other common dir (a bare
52
+ * repository, a `--separate-git-dir` repository, a submodule's
53
+ * `.git/modules/<name>`) or one that no longer exists names no main worktree.
54
+ * - A git dir without one is a **main** worktree's, including a submodule's
55
+ * (`gitdir: <super>/.git/modules/<name>`): a submodule is its own repository,
56
+ * not a linked worktree of the superproject.
57
+ *
58
+ * A `.git` entry that cannot be read, points nowhere, or has no readable `HEAD`
59
+ * makes the answer `undefined` — a broken worktree is not evidence, and the walk
60
+ * does not skip past it to an enclosing repository that the event did not
61
+ * target. A repository that cannot be named costs only `mainRoot`.
49
62
  *
50
63
  * Everything is bounded: walk depth, bytes read per file, and cache size. Every
51
64
  * failure is `undefined`; nothing throws.
@@ -58,6 +71,8 @@ declare const DEFAULT_WORKTREE_CACHE_TTL_MILLIS = 5000;
58
71
  declare const parseHeadBranch: (head: string) => string | undefined;
59
72
  /** `gitdir: <path>` → the path, resolved against the worktree root. */
60
73
  declare const parseGitDirFile: (content: string, worktreeRoot: string) => string | undefined;
74
+ /** A `commondir` file → the common git dir it names, resolved against the git dir. */
75
+ declare const parseCommonDirFile: (content: string, gitDir: string) => string | undefined;
61
76
  type FilesystemWorktreeLocatorOptions = {
62
77
  /** Monotonic milliseconds for cache expiry. Defaults to `performance.now()`. */
63
78
  readonly monotonicMillis?: () => number;
@@ -73,8 +88,9 @@ declare const createFilesystemWorktreeLocator: (options?: FilesystemWorktreeLoca
73
88
  * Turns adapters' target hints into exported worktree targets (ADR 0008).
74
89
  *
75
90
  * This is where local paths stop. A hint's paths are resolved to a worktree
76
- * root and branch through the injected {@link WorktreeLocator}; only the salted
77
- * `git-root` handle of that root and the branch name survive onto the event.
91
+ * root, branch, and repository through the injected {@link WorktreeLocator};
92
+ * only salted `git-root` handles of the root and of its repository's main
93
+ * worktree, the worktree's kind, and the branch name survive onto the event.
78
94
  *
79
95
  * Fail-open in both directions that matter: a slow or failing filesystem costs
80
96
  * the event its target, never the event — and never the host more than the
@@ -99,10 +115,10 @@ type ResolveEventTargetsResult = {
99
115
  readonly timedOut: boolean;
100
116
  };
101
117
  /**
102
- * Attach a `target` to each tool event that has a resolvable hint. Never
118
+ * Attach a `target` to each targeted event (`TARGETED_EVENT_TYPES`) that has a resolvable hint. Never
103
119
  * throws or rejects; events without a hint, or whose hint does not resolve,
104
120
  * are returned unchanged.
105
121
  */
106
122
  declare const resolveEventTargets: (input: ResolveEventTargetsInput) => Promise<ResolveEventTargetsResult>;
107
123
 
108
- export { DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS, DEFAULT_WORKTREE_CACHE_TTL_MILLIS, type FilesystemWorktreeLocatorOptions, LogLevel, Logger, MAX_WORKTREE_WALK_DEPTH, type ResolveEventTargetsInput, type ResolveEventTargetsResult, type StderrLoggerOptions, WorktreeLocator, createFilesystemWorktreeLocator, createNullLogger, createStderrLogger, parseGitDirFile, parseHeadBranch, resolveEventTargets };
124
+ export { DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS, DEFAULT_WORKTREE_CACHE_TTL_MILLIS, type FilesystemWorktreeLocatorOptions, LogLevel, Logger, MAX_WORKTREE_WALK_DEPTH, type ResolveEventTargetsInput, type ResolveEventTargetsResult, type StderrLoggerOptions, WorktreeLocator, createFilesystemWorktreeLocator, createNullLogger, createStderrLogger, parseCommonDirFile, parseGitDirFile, parseHeadBranch, resolveEventTargets };
package/dist/runtime.js CHANGED
@@ -1733,11 +1733,15 @@ var targetHintSchema = z13.strictObject({
1733
1733
  /** Absolute directory that relative `paths` resolve against. */
1734
1734
  baseDirectory: localPathSchema.optional()
1735
1735
  }).readonly();
1736
+ var worktreeKindSchema = z13.enum(["main", "linked"]);
1736
1737
  var workspaceTargetSchema = z13.strictObject({
1737
1738
  workspaceId: workspaceIdSchema,
1738
1739
  /** Branch checked out in that worktree; absent on a detached HEAD. */
1739
1740
  vcsBranchName: nonEmptyStringSchema.optional(),
1740
- source: targetSourceSchema
1741
+ source: targetSourceSchema,
1742
+ /** `git-root` handle of the repository's main worktree; absent when there is none to name. */
1743
+ repositoryId: workspaceIdSchema.optional(),
1744
+ worktreeKind: worktreeKindSchema.optional()
1741
1745
  }).readonly();
1742
1746
  var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
1743
1747
  var subagentIdSchema = z13.string().regex(SUBAGENT_ID_PATTERN);
@@ -1794,7 +1798,9 @@ var sessionStartEventSchema = event({
1794
1798
  sessionKind: z14.enum(["interactive", "non-interactive", "unknown"]),
1795
1799
  agentName: nonEmptyStringSchema.optional(),
1796
1800
  agentVersion: nonEmptyStringSchema.optional(),
1797
- model: modelDescriptorSchema.optional()
1801
+ model: modelDescriptorSchema.optional(),
1802
+ /** The git worktree the session runs in, resolved by the core (ADR 0008). */
1803
+ target: workspaceTargetSchema.optional()
1798
1804
  });
1799
1805
  var sessionEndEventSchema = event({
1800
1806
  type: z14.literal("session.end"),
@@ -1808,7 +1814,9 @@ var promptSubmittedEventSchema = event({
1808
1814
  type: z14.literal("prompt.submitted"),
1809
1815
  promptSource: z14.enum(["user", "automation", "resumed", "unknown"]),
1810
1816
  content: contentFactSchema.optional(),
1811
- turnIndex: z14.number().int().min(0).optional()
1817
+ turnIndex: z14.number().int().min(0).optional(),
1818
+ /** The git worktree the session runs in, resolved by the core (ADR 0008). */
1819
+ target: workspaceTargetSchema.optional()
1812
1820
  });
1813
1821
  var generationStartEventSchema = event({
1814
1822
  type: z14.literal("generation.start"),
@@ -1908,6 +1916,9 @@ var canonicalEventSchema = z14.discriminatedUnion("type", [
1908
1916
  compactionPerformedEventSchema,
1909
1917
  errorRaisedEventSchema
1910
1918
  ]);
1919
+ var TARGETED_EVENT_TYPES = ["session.start", "prompt.submitted", "tool.start", "tool.end"];
1920
+ var TARGETED = new Set(TARGETED_EVENT_TYPES);
1921
+ var isTargetedEvent = (event2) => TARGETED.has(event2.type);
1911
1922
 
1912
1923
  // src/providers/adapter.ts
1913
1924
  var providerDetectionSchema = z15.strictObject({
@@ -2256,17 +2267,18 @@ var resolveHint = async (hint, locator, privacy) => {
2256
2267
  if (identity.keySource !== "git-root") {
2257
2268
  return void 0;
2258
2269
  }
2270
+ const repository = first.mainRoot === void 0 ? void 0 : deriveWorkspaceIdentity(privacy, { kind: "git-root", absolutePath: first.mainRoot });
2259
2271
  const parsed = workspaceTargetSchema.safeParse({
2260
2272
  workspaceId: identity.workspaceId,
2261
2273
  ...identity.vcsBranchName === void 0 ? {} : { vcsBranchName: identity.vcsBranchName },
2262
- source: hint.source
2274
+ source: hint.source,
2275
+ ...repository?.keySource === "git-root" ? { repositoryId: repository.workspaceId } : {},
2276
+ ...first.kind === void 0 ? {} : { worktreeKind: first.kind }
2263
2277
  });
2264
2278
  return parsed.success ? parsed.data : void 0;
2265
2279
  };
2266
2280
  var resolveEventTargets = async (input) => {
2267
- const pending = input.events.filter(
2268
- (event2) => (event2.type === "tool.start" || event2.type === "tool.end") && input.hints.has(event2.eventId)
2269
- );
2281
+ const pending = input.events.filter((event2) => isTargetedEvent(event2) && input.hints.has(event2.eventId));
2270
2282
  if (pending.length === 0) {
2271
2283
  return { events: input.events, resolved: 0, timedOut: false };
2272
2284
  }
@@ -2298,7 +2310,7 @@ var resolveEventTargets = async (input) => {
2298
2310
  const settled = new Map(targets);
2299
2311
  const events = input.events.map((event2) => {
2300
2312
  const target = settled.get(event2.eventId);
2301
- if (target === void 0 || event2.type !== "tool.start" && event2.type !== "tool.end") {
2313
+ if (target === void 0 || !isTargetedEvent(event2)) {
2302
2314
  return event2;
2303
2315
  }
2304
2316
  return { ...event2, target };
@@ -3091,7 +3103,7 @@ var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
3091
3103
  };
3092
3104
 
3093
3105
  // src/runtime/git-worktree.ts
3094
- import { open, stat } from "fs/promises";
3106
+ import { lstat, open, stat } from "fs/promises";
3095
3107
  import * as path2 from "path";
3096
3108
  var MAX_WORKTREE_WALK_DEPTH = 128;
3097
3109
  var MAX_GIT_FILE_BYTES = 4096;
@@ -3123,13 +3135,41 @@ var parseHeadBranch = (head) => {
3123
3135
  }
3124
3136
  return branch;
3125
3137
  };
3138
+ var firstLine = (content) => content.split(/\r?\n/, 1)[0]?.trim() ?? "";
3139
+ var resolveGitPath = (target, base) => target === void 0 || target.length === 0 || target.includes("\0") ? void 0 : path2.resolve(base, target);
3126
3140
  var parseGitDirFile = (content, worktreeRoot) => {
3127
- const line = content.split(/\r?\n/, 1)[0]?.trim() ?? "";
3128
- const target = line.startsWith("gitdir:") ? line.slice("gitdir:".length).trim() : void 0;
3129
- if (target === void 0 || target.length === 0 || target.includes("\0")) {
3130
- return void 0;
3141
+ const line = firstLine(content);
3142
+ return resolveGitPath(
3143
+ line.startsWith("gitdir:") ? line.slice("gitdir:".length).trim() : void 0,
3144
+ worktreeRoot
3145
+ );
3146
+ };
3147
+ var parseCommonDirFile = (content, gitDir) => resolveGitPath(firstLine(content), gitDir);
3148
+ var isMissing = async (filePath) => {
3149
+ try {
3150
+ await lstat(filePath);
3151
+ return false;
3152
+ } catch (error) {
3153
+ const code = error.code;
3154
+ return code === "ENOENT" || code === "ENOTDIR";
3131
3155
  }
3132
- return path2.resolve(worktreeRoot, target);
3156
+ };
3157
+ var isDirectory = async (directory) => {
3158
+ try {
3159
+ return (await stat(directory)).isDirectory();
3160
+ } catch {
3161
+ return false;
3162
+ }
3163
+ };
3164
+ var repositoryOf = async (worktreeRoot, gitDir) => {
3165
+ const commonDirFile = path2.join(gitDir, "commondir");
3166
+ const content = await readBounded(commonDirFile);
3167
+ if (content === void 0) {
3168
+ return await isMissing(commonDirFile) ? { kind: "main", mainRoot: worktreeRoot } : { kind: "linked" };
3169
+ }
3170
+ const commonDir = parseCommonDirFile(content, gitDir);
3171
+ const mainRoot = commonDir !== void 0 && path2.basename(commonDir) === ".git" && await isDirectory(commonDir) ? path2.dirname(commonDir) : void 0;
3172
+ return { kind: "linked", ...mainRoot === void 0 ? {} : { mainRoot } };
3133
3173
  };
3134
3174
  var probeDirectory = async (directory) => {
3135
3175
  const dotGit = path2.join(directory, ".git");
@@ -3154,9 +3194,10 @@ var probeDirectory = async (directory) => {
3154
3194
  return INVALID;
3155
3195
  }
3156
3196
  const branch = parseHeadBranch(head);
3197
+ const repository = info.isDirectory() ? { kind: "main", mainRoot: directory } : await repositoryOf(directory, gitDir);
3157
3198
  return {
3158
3199
  kind: "worktree",
3159
- located: { root: directory, ...branch === void 0 ? {} : { branch } }
3200
+ located: { root: directory, ...branch === void 0 ? {} : { branch }, ...repository }
3160
3201
  };
3161
3202
  };
3162
3203
  var createFilesystemWorktreeLocator = (options = {}) => {
@@ -3225,6 +3266,7 @@ export {
3225
3266
  hostDeliveryIdentity,
3226
3267
  isCommittable,
3227
3268
  logLevelSchema,
3269
+ parseCommonDirFile,
3228
3270
  parseGitDirFile,
3229
3271
  parseHeadBranch,
3230
3272
  resolveDeliveryIdentity,