@osfactory/otel-hook 0.4.1 → 0.5.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-BS7xHKGQ.d.ts} +2 -3
  2. package/dist/cli.js +54 -12
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{events-C3h3GvHj.d.ts → events-CzZ5kukS.d.ts} +119 -1
  5. package/dist/{filesystem-store-BAq3VGVv.d.ts → filesystem-store-BcOveJYY.d.ts} +1 -1
  6. package/dist/{hook-CQiNa88Q.d.ts → hook-DxTakjAD.d.ts} +4 -4
  7. package/dist/index.d.ts +12 -13
  8. package/dist/index.js +56 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/install.d.ts +4 -5
  11. package/dist/install.js +5 -1
  12. package/dist/install.js.map +1 -1
  13. package/dist/integration.d.ts +8 -9
  14. package/dist/integration.js +54 -12
  15. package/dist/integration.js.map +1 -1
  16. package/dist/lifecycle.d.ts +3 -3
  17. package/dist/lifecycle.js +6 -2
  18. package/dist/lifecycle.js.map +1 -1
  19. package/dist/{memory-kflYgZbg.d.ts → memory-DkTohdIa.d.ts} +2 -2
  20. package/dist/model.d.ts +1 -2
  21. package/dist/model.js +7 -2
  22. package/dist/model.js.map +1 -1
  23. package/dist/{otlp-log-sink-BZIgYPKN.d.ts → otlp-log-sink-DaZDPKnR.d.ts} +3 -3
  24. package/dist/{payload-DpyU8F-z.d.ts → payload-2lnpKodw.d.ts} +1 -1
  25. package/dist/{ports-B_iwJQPQ.d.ts → ports-B0rC49b3.d.ts} +9 -1
  26. package/dist/providers.d.ts +7 -8
  27. package/dist/providers.js +5 -1
  28. package/dist/providers.js.map +1 -1
  29. package/dist/{registry-BSBS8t7S.d.ts → registry-DVnPA_b6.d.ts} +1 -1
  30. package/dist/runtime.d.ts +31 -15
  31. package/dist/runtime.js +46 -9
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/{semconv-BeUPQ7_q.d.ts → semconv-CtnDdsPk.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 +9 -3
  38. package/dist/telemetry.js.map +1 -1
  39. package/dist/testing.d.ts +7 -8
  40. package/dist/testing.js +9 -2
  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-BS7xHKGQ.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-B0rC49b3.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-B0rC49b3.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-DkTohdIa.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-DxTakjAD.js';
5
+ import { b as CanonicalEvent, T as TargetHint } from './events-CzZ5kukS.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-BS7xHKGQ.js';
15
14
  import './policy-CimmCfRp.js';
16
15
  import './content-M9xIKG7h.js';
17
- import './registry-BSBS8t7S.js';
16
+ import './registry-DVnPA_b6.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
@@ -105,4 +121,4 @@ type ResolveEventTargetsResult = {
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);
@@ -2256,10 +2260,13 @@ var resolveHint = async (hint, locator, privacy) => {
2256
2260
  if (identity.keySource !== "git-root") {
2257
2261
  return void 0;
2258
2262
  }
2263
+ const repository = first.mainRoot === void 0 ? void 0 : deriveWorkspaceIdentity(privacy, { kind: "git-root", absolutePath: first.mainRoot });
2259
2264
  const parsed = workspaceTargetSchema.safeParse({
2260
2265
  workspaceId: identity.workspaceId,
2261
2266
  ...identity.vcsBranchName === void 0 ? {} : { vcsBranchName: identity.vcsBranchName },
2262
- source: hint.source
2267
+ source: hint.source,
2268
+ ...repository?.keySource === "git-root" ? { repositoryId: repository.workspaceId } : {},
2269
+ ...first.kind === void 0 ? {} : { worktreeKind: first.kind }
2263
2270
  });
2264
2271
  return parsed.success ? parsed.data : void 0;
2265
2272
  };
@@ -3091,7 +3098,7 @@ var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
3091
3098
  };
3092
3099
 
3093
3100
  // src/runtime/git-worktree.ts
3094
- import { open, stat } from "fs/promises";
3101
+ import { lstat, open, stat } from "fs/promises";
3095
3102
  import * as path2 from "path";
3096
3103
  var MAX_WORKTREE_WALK_DEPTH = 128;
3097
3104
  var MAX_GIT_FILE_BYTES = 4096;
@@ -3123,13 +3130,41 @@ var parseHeadBranch = (head) => {
3123
3130
  }
3124
3131
  return branch;
3125
3132
  };
3133
+ var firstLine = (content) => content.split(/\r?\n/, 1)[0]?.trim() ?? "";
3134
+ var resolveGitPath = (target, base) => target === void 0 || target.length === 0 || target.includes("\0") ? void 0 : path2.resolve(base, target);
3126
3135
  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;
3136
+ const line = firstLine(content);
3137
+ return resolveGitPath(
3138
+ line.startsWith("gitdir:") ? line.slice("gitdir:".length).trim() : void 0,
3139
+ worktreeRoot
3140
+ );
3141
+ };
3142
+ var parseCommonDirFile = (content, gitDir) => resolveGitPath(firstLine(content), gitDir);
3143
+ var isMissing = async (filePath) => {
3144
+ try {
3145
+ await lstat(filePath);
3146
+ return false;
3147
+ } catch (error) {
3148
+ const code = error.code;
3149
+ return code === "ENOENT" || code === "ENOTDIR";
3131
3150
  }
3132
- return path2.resolve(worktreeRoot, target);
3151
+ };
3152
+ var isDirectory = async (directory) => {
3153
+ try {
3154
+ return (await stat(directory)).isDirectory();
3155
+ } catch {
3156
+ return false;
3157
+ }
3158
+ };
3159
+ var repositoryOf = async (worktreeRoot, gitDir) => {
3160
+ const commonDirFile = path2.join(gitDir, "commondir");
3161
+ const content = await readBounded(commonDirFile);
3162
+ if (content === void 0) {
3163
+ return await isMissing(commonDirFile) ? { kind: "main", mainRoot: worktreeRoot } : { kind: "linked" };
3164
+ }
3165
+ const commonDir = parseCommonDirFile(content, gitDir);
3166
+ const mainRoot = commonDir !== void 0 && path2.basename(commonDir) === ".git" && await isDirectory(commonDir) ? path2.dirname(commonDir) : void 0;
3167
+ return { kind: "linked", ...mainRoot === void 0 ? {} : { mainRoot } };
3133
3168
  };
3134
3169
  var probeDirectory = async (directory) => {
3135
3170
  const dotGit = path2.join(directory, ".git");
@@ -3154,9 +3189,10 @@ var probeDirectory = async (directory) => {
3154
3189
  return INVALID;
3155
3190
  }
3156
3191
  const branch = parseHeadBranch(head);
3192
+ const repository = info.isDirectory() ? { kind: "main", mainRoot: directory } : await repositoryOf(directory, gitDir);
3157
3193
  return {
3158
3194
  kind: "worktree",
3159
- located: { root: directory, ...branch === void 0 ? {} : { branch } }
3195
+ located: { root: directory, ...branch === void 0 ? {} : { branch }, ...repository }
3160
3196
  };
3161
3197
  };
3162
3198
  var createFilesystemWorktreeLocator = (options = {}) => {
@@ -3225,6 +3261,7 @@ export {
3225
3261
  hostDeliveryIdentity,
3226
3262
  isCommittable,
3227
3263
  logLevelSchema,
3264
+ parseCommonDirFile,
3228
3265
  parseGitDirFile,
3229
3266
  parseHeadBranch,
3230
3267
  resolveDeliveryIdentity,