@osfactory/otel-hook 0.1.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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1020 -0
  3. package/dist/adapter-DIgRACtL.d.ts +303 -0
  4. package/dist/cli.js +12607 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config.d.ts +233 -0
  7. package/dist/config.js +996 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/content-CoB7aNP1.d.ts +118 -0
  10. package/dist/diagnostics.d.ts +58 -0
  11. package/dist/diagnostics.js +46 -0
  12. package/dist/diagnostics.js.map +1 -0
  13. package/dist/errors.d.ts +91 -0
  14. package/dist/errors.js +322 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/events-VxBnDFaO.d.ts +2044 -0
  17. package/dist/filesystem-store-J8jjDMTh.d.ts +65 -0
  18. package/dist/hook-CGpo-vks.d.ts +292 -0
  19. package/dist/identity-BrVBs901.d.ts +227 -0
  20. package/dist/index.d.ts +44 -0
  21. package/dist/index.js +11798 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/install.d.ts +1021 -0
  24. package/dist/install.js +3271 -0
  25. package/dist/install.js.map +1 -0
  26. package/dist/integration.d.ts +303 -0
  27. package/dist/integration.js +5942 -0
  28. package/dist/integration.js.map +1 -0
  29. package/dist/keys-Dej5bN3L.d.ts +7 -0
  30. package/dist/lifecycle.d.ts +428 -0
  31. package/dist/lifecycle.js +1077 -0
  32. package/dist/lifecycle.js.map +1 -0
  33. package/dist/memory-DXVBc8V9.d.ts +94 -0
  34. package/dist/model.d.ts +45 -0
  35. package/dist/model.js +1023 -0
  36. package/dist/model.js.map +1 -0
  37. package/dist/otlp-log-sink-CeIFDDpn.d.ts +457 -0
  38. package/dist/payload-CHr53E_v.d.ts +201 -0
  39. package/dist/policy-D1CrlYn3.d.ts +73 -0
  40. package/dist/ports-Q8x0ODhs.d.ts +200 -0
  41. package/dist/primitives-CJ8-rn-f.d.ts +75 -0
  42. package/dist/privacy.d.ts +51 -0
  43. package/dist/privacy.js +633 -0
  44. package/dist/privacy.js.map +1 -0
  45. package/dist/providers.d.ts +257 -0
  46. package/dist/providers.js +4398 -0
  47. package/dist/providers.js.map +1 -0
  48. package/dist/registry-BzYmC9OC.d.ts +49 -0
  49. package/dist/runtime.d.ts +32 -0
  50. package/dist/runtime.js +2907 -0
  51. package/dist/runtime.js.map +1 -0
  52. package/dist/schema-Cn0-xz8L.d.ts +224 -0
  53. package/dist/semconv-Baoz-0OI.d.ts +188 -0
  54. package/dist/service-j4jEO6cZ.d.ts +68 -0
  55. package/dist/state.d.ts +36 -0
  56. package/dist/state.js +710 -0
  57. package/dist/state.js.map +1 -0
  58. package/dist/taxonomy-DwhTtuWd.d.ts +87 -0
  59. package/dist/telemetry.d.ts +77 -0
  60. package/dist/telemetry.js +2294 -0
  61. package/dist/telemetry.js.map +1 -0
  62. package/dist/testing.d.ts +155 -0
  63. package/dist/testing.js +6513 -0
  64. package/dist/testing.js.map +1 -0
  65. package/package.json +124 -0
@@ -0,0 +1,1021 @@
1
+ import { d as AntigravityHookEventName, m as ClaudeHookEventName, n as CodexHookEventName, o as CursorHookEventName, s as GeminiHookEventName, q as GEMINI_PROVIDER_ID, b as ANTIGRAVITY_PROVIDER_ID, C as CLAUDE_CODE_PROVIDER_ID, h as CODEX_PROVIDER_ID, k as CURSOR_PROVIDER_ID } from './payload-CHr53E_v.js';
2
+ import { C as Clock } from './ports-Q8x0ODhs.js';
3
+ import 'zod';
4
+ import './primitives-CJ8-rn-f.js';
5
+ import './adapter-DIgRACtL.js';
6
+ import './errors.js';
7
+ import './taxonomy-DwhTtuWd.js';
8
+ import './events-VxBnDFaO.js';
9
+ import './identity-BrVBs901.js';
10
+ import './policy-D1CrlYn3.js';
11
+ import './content-CoB7aNP1.js';
12
+ import './service-j4jEO6cZ.js';
13
+
14
+ /**
15
+ * Pure merge/removal engine for the "nested command hooks" configuration family.
16
+ *
17
+ * Claude Code and the Codex CLI document the same document shape:
18
+ *
19
+ * ```jsonc
20
+ * {
21
+ * "hooks": {
22
+ * "<EventName>": [
23
+ * { "matcher": "Bash", "hooks": [{ "type": "command", "command": "…", "timeout": 30 }] }
24
+ * ]
25
+ * }
26
+ * }
27
+ * ```
28
+ *
29
+ * The shape is generic; the *vocabulary* is not. Which events exist, which
30
+ * matchers are meaningful, and what a timeout means stay in each provider's own
31
+ * planner (`claude/registration.ts`, `codex/registration.ts`), so nothing here
32
+ * encodes a provider contract and nothing here has to be re-verified when one
33
+ * provider adds an event.
34
+ *
35
+ * Everything is pure: callers read the file, pass the parsed value in, and write
36
+ * the returned document back (ADR 0003). Two properties this engine guarantees,
37
+ * both covered by tests:
38
+ *
39
+ * - **Idempotence.** Re-merging identical options against the returned document
40
+ * yields `changed: false` and a deep-equal document.
41
+ * - **Reversibility.** `removeNestedHookRegistrations` after
42
+ * `mergeNestedHookRegistration` restores the input document exactly, including
43
+ * dropping structure the merge created.
44
+ *
45
+ * A document whose `hooks` value is not the documented shape is *reported*, not
46
+ * coerced: silently replacing a developer's unexpected `hooks` value would
47
+ * destroy configuration this package does not understand.
48
+ */
49
+ type CommandHookEntry = {
50
+ readonly type: "command";
51
+ readonly command: string;
52
+ /**
53
+ * Whatever unit the *provider's* vocabulary uses — seconds for Claude Code and
54
+ * the Codex CLI, milliseconds for the Gemini CLI. Each planner converts before
55
+ * building its entry; this engine only copies the number through.
56
+ */
57
+ readonly timeout?: number;
58
+ readonly [key: string]: unknown;
59
+ };
60
+ type HookGroupEntry = {
61
+ readonly matcher?: string;
62
+ readonly hooks: readonly unknown[];
63
+ readonly [key: string]: unknown;
64
+ };
65
+ type HookDocumentAction = "added" | "updated" | "unchanged" | "removed";
66
+ type HookDocumentChange = {
67
+ readonly event: string;
68
+ readonly action: HookDocumentAction;
69
+ };
70
+ /** A structural surprise. Reported so a caller can refuse to write. */
71
+ type HookDocumentConflict = {
72
+ /** Dotted location inside the document, e.g. `hooks.PreToolUse`. */
73
+ readonly location: string;
74
+ readonly detail: string;
75
+ };
76
+ type NestedHookDocumentResult = {
77
+ /** Write this back verbatim. Identical to the input when `conflicts` is non-empty. */
78
+ readonly document: Record<string, unknown>;
79
+ readonly changed: boolean;
80
+ readonly changes: readonly HookDocumentChange[];
81
+ readonly conflicts: readonly HookDocumentConflict[];
82
+ };
83
+ type MergeNestedHookInput = {
84
+ /** Parsed configuration document, or anything else when no file exists yet. */
85
+ readonly existing?: unknown;
86
+ readonly events: readonly string[];
87
+ /** The exact command entry to write. Compared field-by-field for idempotence. */
88
+ readonly entry: CommandHookEntry;
89
+ /**
90
+ * Matcher for a *newly created* group. Omitted means "no matcher key", which
91
+ * both vocabularies define as matching every occurrence.
92
+ */
93
+ readonly matcher?: string;
94
+ /**
95
+ * Recognizes a handler this tool previously wrote, so an upgrade rewrites its
96
+ * own entry instead of appending a second one. Takes the whole handler
97
+ * because the identity key differs by vocabulary: Gemini CLI handlers carry a
98
+ * `name`, Claude Code and Codex handlers are identified by their command.
99
+ */
100
+ readonly identifies: HookHandlerPredicate;
101
+ };
102
+ type HookHandlerPredicate = (handler: Readonly<Record<string, unknown>>) => boolean;
103
+ type RemoveNestedHookInput = {
104
+ readonly existing?: unknown;
105
+ /** Restrict removal to these events. Omitted means every event in the document. */
106
+ readonly events?: readonly string[];
107
+ readonly identifies: HookHandlerPredicate;
108
+ };
109
+ /**
110
+ * Merge one command registration into the document, once per event.
111
+ *
112
+ * Identity is `(event, managed handler)`, deliberately not
113
+ * `(event, matcher, command)`. An event ends up with **exactly one** handler of
114
+ * ours afterwards, wherever it was before, which is what makes the three
115
+ * interesting cases behave:
116
+ *
117
+ * - *Repeat.* Same options twice is a no-op, in place, byte for byte.
118
+ * - *Upgrade.* A changed command, timeout, or matcher rewrites — or moves —
119
+ * the entry we already own instead of appending a second one that would
120
+ * double every span this event produces.
121
+ * - *Repair.* Pre-existing duplicates of ours are collapsed to one.
122
+ *
123
+ * A handler that stays in its group is rewritten at its original index rather
124
+ * than removed and re-appended, so an unchanged merge cannot reorder a
125
+ * developer's file.
126
+ */
127
+ declare const mergeNestedHookRegistration: (input: MergeNestedHookInput) => NestedHookDocumentResult;
128
+ /**
129
+ * Remove every registration this tool owns, leaving all other handlers,
130
+ * matchers, events, and top-level keys untouched.
131
+ *
132
+ * Removal scans events actually present in the document rather than a fixed
133
+ * list, so an uninstall still cleans up after a setup that used `--event`.
134
+ */
135
+ declare const removeNestedHookRegistrations: (input: RemoveNestedHookInput) => NestedHookDocumentResult;
136
+ /**
137
+ * Every managed command string currently registered, per event.
138
+ *
139
+ * Used by `diagnose` to tell "registered with the command we would write" from
140
+ * "registered with a stale command an upgrade should rewrite".
141
+ */
142
+ declare const readNestedHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
143
+
144
+ /** One command entry inside an Antigravity hook event's list. */
145
+ type AntigravityHookCommandEntry = {
146
+ readonly matcher?: string;
147
+ readonly command: string;
148
+ };
149
+ type MergeAntigravityHookRegistrationInput = {
150
+ /** Parsed JSON of an existing hook file, or `undefined`/anything non-object if none exists yet. */
151
+ readonly existing?: unknown;
152
+ /** Command line this library's hook installs for every targeted event. */
153
+ readonly command: string;
154
+ /** Defaults to all five documented events. */
155
+ readonly events?: readonly AntigravityHookEventName[];
156
+ readonly matcher?: string;
157
+ /**
158
+ * Recognizes entries an earlier version of this tool wrote, so a changed
159
+ * command string rewrites its own entry instead of leaving a stale one
160
+ * firing beside the new one. Defaults to exact-command equality.
161
+ */
162
+ readonly identifies?: HookHandlerPredicate;
163
+ };
164
+ type MergeAntigravityHookRegistrationResult = {
165
+ /** The merged document; write this back verbatim. */
166
+ readonly config: Record<string, unknown>;
167
+ /** True when the merge added or changed anything relative to `existing`. */
168
+ readonly changed: boolean;
169
+ };
170
+ /**
171
+ * Idempotently merge this library's hook registration into an Antigravity
172
+ * workspace or global hook file, without touching unrelated keys or events.
173
+ *
174
+ * Pure and filesystem-free by design (see ADR 0003): callers own reading and
175
+ * writing the file. Calling this twice with the same inputs is a no-op the
176
+ * second time (`changed: false`), and every top-level key and every hook
177
+ * event not named in `events` is carried through unmodified.
178
+ */
179
+ declare const mergeAntigravityHookRegistration: (input: MergeAntigravityHookRegistrationInput) => MergeAntigravityHookRegistrationResult;
180
+ type RemoveAntigravityHookRegistrationInput = {
181
+ readonly existing?: unknown;
182
+ /** Restrict removal to these events. Omitted means every event in the document. */
183
+ readonly events?: readonly AntigravityHookEventName[];
184
+ /** Recognizes hook entries this tool wrote, across versions. */
185
+ readonly identifies: HookHandlerPredicate;
186
+ };
187
+ /**
188
+ * Reverse {@link mergeAntigravityHookRegistration}.
189
+ *
190
+ * Antigravity's hook file is a *flat* list of command entries per event, not
191
+ * the nested matcher-group shape Claude Code, Codex, and the Gemini CLI use, so
192
+ * this cannot share their engine. An event whose list becomes empty is deleted,
193
+ * and an emptied `hooks` object is deleted with it, so an uninstall restores a
194
+ * document that had no hooks before setup.
195
+ */
196
+ declare const removeAntigravityHookRegistration: (input: RemoveAntigravityHookRegistrationInput) => MergeAntigravityHookRegistrationResult;
197
+ /** Managed command strings currently registered, per event. */
198
+ declare const readAntigravityHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
199
+
200
+ /**
201
+ * Idempotent registration planner for Claude Code's `settings.json`.
202
+ *
203
+ * ## Evidence
204
+ *
205
+ * The document shape, the scopes, and the event vocabulary come from the public
206
+ * Claude Code hooks reference (`code.claude.com/docs/en/hooks`, read 2026-07),
207
+ * cross-checked against the setup implementation in
208
+ * `o11y-dev/opentelemetry-hooks` v0.14.0 (`setup.sh`, `setup_claude`). Both
209
+ * agree on:
210
+ *
211
+ * - `hooks.<EventName>` is an array of groups; each group is
212
+ * `{ matcher?, hooks: [{ type: "command", command, timeout? }] }`.
213
+ * - `~/.claude/settings.json` is the user-global file and
214
+ * `.claude/settings.json` the project file (`.claude/settings.local.json` is
215
+ * the gitignored project override).
216
+ * - `timeout` is in seconds.
217
+ *
218
+ * The reference additionally documents that an omitted `matcher` matches every
219
+ * occurrence, and that `UserPromptSubmit` and `Stop` take no matcher at all.
220
+ * This planner therefore writes **no** `matcher` key by default: one spelling
221
+ * that is valid for every event it registers, rather than a per-event table
222
+ * that would have to be re-verified whenever Claude Code adds an event.
223
+ *
224
+ * ## Why not every documented event
225
+ *
226
+ * {@link CLAUDE_REGISTRABLE_HOOK_EVENTS} is the intersection of "documented as a
227
+ * hook event" and "this adapter turns it into a canonical event". `PreCompact`
228
+ * and `PermissionRequest` are parsed but deliberately produce no telemetry
229
+ * (see `events.ts`), so registering them would spawn a process per occurrence
230
+ * for nothing. Callers who want them anyway can pass `events` explicitly.
231
+ */
232
+ /** Every event name this repository's Claude Code adapter accepts on stdin. */
233
+ declare const CLAUDE_HOOK_EVENTS_MODELLED: readonly ClaudeHookEventName[];
234
+ /**
235
+ * Default registration set: the modelled events that yield telemetry.
236
+ * Ordered as the reference documents the lifecycle, so a written settings file
237
+ * reads in the order the events fire.
238
+ */
239
+ declare const CLAUDE_REGISTRABLE_HOOK_EVENTS: readonly ClaudeHookEventName[];
240
+ /** Documented but intentionally not registered, with the reason. */
241
+ declare const CLAUDE_UNREGISTERED_HOOK_EVENTS: Readonly<Record<string, string>>;
242
+ type ClaudeHookRegistrationOptions = {
243
+ /** Parsed `settings.json`, or `undefined` when the file does not exist yet. */
244
+ readonly existing?: unknown;
245
+ readonly command: string;
246
+ /** Defaults to {@link CLAUDE_REGISTRABLE_HOOK_EVENTS}. */
247
+ readonly events?: readonly string[];
248
+ /** Seconds. Omitted leaves Claude Code's own default in force. */
249
+ readonly timeoutSeconds?: number;
250
+ /**
251
+ * Written only when creating a new group. Omitted (the default) means "every
252
+ * occurrence", the only spelling valid for every registrable event.
253
+ */
254
+ readonly matcher?: string;
255
+ /** Recognizes entries written by an earlier version of this tool. */
256
+ readonly identifies: HookHandlerPredicate;
257
+ };
258
+ type ClaudeHookRemovalOptions = {
259
+ readonly existing?: unknown;
260
+ readonly events?: readonly string[];
261
+ readonly identifies: HookHandlerPredicate;
262
+ };
263
+ declare const mergeClaudeHookRegistration: (options: ClaudeHookRegistrationOptions) => NestedHookDocumentResult;
264
+ declare const removeClaudeHookRegistration: (options: ClaudeHookRemovalOptions) => NestedHookDocumentResult;
265
+ declare const readClaudeHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
266
+
267
+ /**
268
+ * Idempotent registration planner for the Codex CLI's `hooks.json`.
269
+ *
270
+ * ## Evidence
271
+ *
272
+ * The public Codex hooks reference (`developers.openai.com/codex/hooks`,
273
+ * redirecting to `learn.chatgpt.com/docs/hooks`, read 2026-07 — the same source
274
+ * `payload.ts` cites for the stdin payloads) documents:
275
+ *
276
+ * - Discovery locations `~/.codex/hooks.json` and `<repo>/.codex/hooks.json`,
277
+ * with equivalent inline `[[hooks.EventName]]` tables in `config.toml`.
278
+ * - The `hooks.<EventName>` → array-of-groups → `{ matcher?, hooks: [...] }`
279
+ * shape, matching Claude Code's.
280
+ * - `matcher` optional, where omitting it "matches every occurrence".
281
+ * - `timeout` in seconds.
282
+ * - Hooks **enabled by default**; `[features] hooks = false` in `config.toml`
283
+ * turns them off.
284
+ *
285
+ * This planner writes only `hooks.json`. It never edits `config.toml`: hooks
286
+ * being on by default means no edit is required, and rewriting a hand-authored
287
+ * TOML file to flip a flag that is already set is a mutation with more downside
288
+ * (comment loss, formatting loss, merge-warning on a layer that also declares
289
+ * inline hooks) than value. {@link readCodexHooksFeatureFlag} lets `diagnose`
290
+ * *report* an explicit opt-out instead.
291
+ *
292
+ * ## Why not every documented event
293
+ *
294
+ * The reference lists `SessionEnd`, but this repository's adapter deliberately
295
+ * does not model it (see `payload.ts`: Codex has no dependable `SessionEnd`, and
296
+ * `adapter.ts` substitutes `Stop` plus a state-store TTL). Registering an event
297
+ * whose payload the adapter would reject is worse than not registering it.
298
+ * `PermissionRequest` is modelled but produces no telemetry of its own, so it is
299
+ * not in the default set either.
300
+ */
301
+ /** Every `hook_event_name` this repository's Codex adapter accepts. */
302
+ declare const CODEX_HOOK_EVENTS_MODELLED: readonly CodexHookEventName[];
303
+ /** Default registration set: modelled events that yield telemetry, in lifecycle order. */
304
+ declare const CODEX_REGISTRABLE_HOOK_EVENTS: readonly CodexHookEventName[];
305
+ /** Documented or modelled but intentionally not registered, with the reason. */
306
+ declare const CODEX_UNREGISTERED_HOOK_EVENTS: Readonly<Record<string, string>>;
307
+ type CodexHookRegistrationOptions = {
308
+ /** Parsed `hooks.json`, or `undefined` when the file does not exist yet. */
309
+ readonly existing?: unknown;
310
+ readonly command: string;
311
+ /** Defaults to {@link CODEX_REGISTRABLE_HOOK_EVENTS}. */
312
+ readonly events?: readonly string[];
313
+ /** Seconds. Omitted leaves Codex's own per-event default in force. */
314
+ readonly timeoutSeconds?: number;
315
+ readonly matcher?: string;
316
+ readonly identifies: HookHandlerPredicate;
317
+ };
318
+ type CodexHookRemovalOptions = {
319
+ readonly existing?: unknown;
320
+ readonly events?: readonly string[];
321
+ readonly identifies: HookHandlerPredicate;
322
+ };
323
+ declare const mergeCodexHookRegistration: (options: CodexHookRegistrationOptions) => NestedHookDocumentResult;
324
+ declare const removeCodexHookRegistration: (options: CodexHookRemovalOptions) => NestedHookDocumentResult;
325
+ declare const readCodexHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
326
+ type CodexHooksFeatureFlag = "enabled" | "disabled" | "unset";
327
+ /**
328
+ * Read the `[features] hooks` opt-out from a `config.toml`'s text.
329
+ *
330
+ * Line-scoped on purpose: this is a read-only diagnostic for one documented
331
+ * boolean, not a TOML parser, and it must never be used to decide a write. It
332
+ * looks only at bare `key = value` lines inside a top-level `[features]` table,
333
+ * so a `hooks` key in any other table cannot be mistaken for this one. Anything
334
+ * it cannot interpret is reported as `"unset"` — Codex's own default.
335
+ */
336
+ declare const readCodexHooksFeatureFlag: (configToml: string) => CodexHooksFeatureFlag;
337
+
338
+ /**
339
+ * Idempotent registration planner for Cursor's `hooks.json`.
340
+ *
341
+ * ## Evidence
342
+ *
343
+ * The document half was already verified before the payload half was: Cursor's
344
+ * hooks reference (`cursor.com/docs/agent/hooks` and `cursor.com/docs/hooks.md`,
345
+ * read 2026-07-29) documents the discovery locations `~/.cursor/hooks.json`
346
+ * (user) and `<project-root>/.cursor/hooks.json` (project), and the document
347
+ * shape
348
+ *
349
+ * ```jsonc
350
+ * {
351
+ * "version": 1,
352
+ * "hooks": {
353
+ * "preToolUse": [
354
+ * { "command": "…", "type": "command", "timeout": 30, "matcher": "…" }
355
+ * ]
356
+ * }
357
+ * }
358
+ * ```
359
+ *
360
+ * with `timeout` in **seconds**, `type` defaulting to `"command"`, `matcher`
361
+ * optional, and `failClosed` defaulting to false. `o11y-dev/opentelemetry-hooks`
362
+ * v0.14.0 writes exactly that shape. Enterprise-managed locations
363
+ * (`/etc/cursor/hooks.json` and the macOS/Windows equivalents) are documented
364
+ * too but are deliberately not offered as a scope: they are MDM-owned, live
365
+ * outside a home directory, and this tool has no business writing there.
366
+ *
367
+ * The list is *flat* — one array of command entries per event, no matcher-group
368
+ * nesting — so this cannot share the engine Claude Code, Codex, and the Gemini
369
+ * CLI use, for the same reason Antigravity cannot.
370
+ *
371
+ * ## Why not every documented event
372
+ *
373
+ * {@link CURSOR_REGISTRABLE_HOOK_EVENTS} is the intersection of "Cursor
374
+ * documents it", "this adapter turns it into telemetry", and "registering it
375
+ * does not double-count something already registered".
376
+ * {@link CURSOR_UNREGISTERED_HOOK_EVENTS} records every exclusion with its
377
+ * reason; the shell and MCP exclusions are the interesting ones, and they come
378
+ * from a capture rather than from the reference — see `payload.ts`.
379
+ */
380
+ /** Every `hook_event_name` this repository's Cursor adapter accepts. */
381
+ declare const CURSOR_HOOK_EVENTS_MODELLED: readonly CursorHookEventName[];
382
+ /** Default registration set: modelled events that yield telemetry, in lifecycle order. */
383
+ declare const CURSOR_REGISTRABLE_HOOK_EVENTS: readonly CursorHookEventName[];
384
+ /** Documented or modelled but intentionally not registered, with the reason. */
385
+ declare const CURSOR_UNREGISTERED_HOOK_EVENTS: Readonly<Record<string, string>>;
386
+ /** The schema version Cursor documents for `hooks.json`. */
387
+ declare const CURSOR_HOOKS_DOCUMENT_VERSION = 1;
388
+ /** One command entry inside a Cursor hook event's list. */
389
+ type CursorHookCommandEntry = {
390
+ readonly type: "command";
391
+ readonly command: string;
392
+ /** Seconds, per the reference. */
393
+ readonly timeout?: number;
394
+ readonly matcher?: string;
395
+ };
396
+ type MergeCursorHookRegistrationInput = {
397
+ /** Parsed `hooks.json`, or `undefined`/anything non-object when none exists yet. */
398
+ readonly existing?: unknown;
399
+ readonly command: string;
400
+ /** Defaults to {@link CURSOR_REGISTRABLE_HOOK_EVENTS}. */
401
+ readonly events?: readonly string[];
402
+ /** Seconds. Omitted leaves Cursor's own default in force. */
403
+ readonly timeoutSeconds?: number;
404
+ readonly matcher?: string;
405
+ /** Recognizes entries an earlier version of this tool wrote. */
406
+ readonly identifies: HookHandlerPredicate;
407
+ };
408
+ type CursorHookRemovalInput = {
409
+ readonly existing?: unknown;
410
+ /** Restrict removal to these events. Omitted means every event in the document. */
411
+ readonly events?: readonly string[];
412
+ readonly identifies: HookHandlerPredicate;
413
+ };
414
+ type CursorHookDocumentResult = {
415
+ /** Write this back verbatim. */
416
+ readonly config: Record<string, unknown>;
417
+ readonly changed: boolean;
418
+ };
419
+ /**
420
+ * Merge this tool's registration into a Cursor hook document.
421
+ *
422
+ * Pure and filesystem-free (ADR 0003): the caller reads the file, passes the
423
+ * parsed value in, and writes the returned document back. Two guarantees, both
424
+ * asserted in `tests/install/cursor-registration.test.ts`:
425
+ *
426
+ * - **Idempotence.** Re-merging identical options against the returned document
427
+ * is a no-op (`changed: false`) with a deep-equal document.
428
+ * - **One entry per event.** Our entry is rewritten in place on an upgrade and
429
+ * any duplicate of it is collapsed, so a changed command cannot leave a stale
430
+ * handler firing beside the new one and double every span.
431
+ *
432
+ * `version` is added only when the document does not already declare one. A
433
+ * developer's existing `version` is never rewritten — Cursor could raise it, and
434
+ * downgrading a document to match this constant would be a guess about a schema
435
+ * this tool does not own.
436
+ */
437
+ declare const mergeCursorHookRegistration: (input: MergeCursorHookRegistrationInput) => CursorHookDocumentResult;
438
+ /**
439
+ * Reverse {@link mergeCursorHookRegistration}.
440
+ *
441
+ * An event whose list becomes empty is deleted, and an emptied `hooks` object is
442
+ * deleted with it, so uninstalling restores a document that had no hooks before
443
+ * setup. A lone `version` left behind by that pruning is dropped too: a
444
+ * `hooks.json` declaring a schema version for no hooks is a document Cursor
445
+ * reads nothing from, and leaving it would mean `setup` followed by `uninstall`
446
+ * created a file where there was none.
447
+ */
448
+ declare const removeCursorHookRegistration: (input: CursorHookRemovalInput) => CursorHookDocumentResult;
449
+ /** Managed command strings currently registered, per event. */
450
+ declare const readCursorHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
451
+
452
+ /**
453
+ * Idempotent helper for registering this adapter's command hook into a Gemini
454
+ * CLI `settings.json`. It never touches the filesystem itself — callers read
455
+ * the existing settings, pass the parsed value in, and write the returned
456
+ * value back — so the merge logic stays pure and testable, and this package
457
+ * never needs a filesystem handle (see ADR 0003).
458
+ *
459
+ * Gemini CLI's settings share the nested `hooks -> event -> [{matcher, hooks}]`
460
+ * shape that Claude Code and the Codex CLI document, so the merge itself is
461
+ * delegated to `providers/hook-document.ts`; what stays here is the part that is
462
+ * specific to Gemini. Four things are, all read from
463
+ * `google-gemini/gemini-cli@3499c84` (`docs/hooks/reference.md`,
464
+ * `packages/core/src/hooks/types.ts`, `packages/core/src/hooks/hookPlanner.ts`):
465
+ *
466
+ * - **`timeout` is milliseconds**, default `60000` — not seconds, as Claude Code
467
+ * and the Codex CLI both use. `hookRunner` passes the value straight to
468
+ * `setTimeout`. Callers speak seconds ({@link RegisterGeminiHookOptions}), and
469
+ * the conversion happens here, because writing `timeout: 30` from a
470
+ * `--timeout-seconds 30` would kill the hook after 30ms.
471
+ * - **`"*"` is a real matcher value.** `HookPlanner.matchesContext` special-cases
472
+ * `""` and `"*"` as match-everything before treating a matcher as a regex, so
473
+ * the wildcard is safe here even though `new RegExp("*")` would throw.
474
+ * - **`name` is the identity key.** The CLI's own `getHookKey` is
475
+ * `` `${name}:${command}` ``, which would treat a changed command as a
476
+ * *different* hook and leave the stale entry firing beside the new one. This
477
+ * planner keys on `name` alone so an upgrade rewrites in place.
478
+ * - **`hooks` holds non-event keys.** `HOOKS_CONFIG_FIELDS` is
479
+ * `['enabled', 'disabled', 'notifications']`, so `hooks.enabled: true` sits
480
+ * beside the event arrays. Both merge and removal are therefore driven by an
481
+ * explicit event list and never iterate the object's keys.
482
+ *
483
+ * The scopes are `~/.gemini/settings.json` (user-global) and
484
+ * `.gemini/settings.json` (project), as written by `o11y-dev/opentelemetry-hooks`
485
+ * v0.14.0 (`setup.sh`, `setup_gemini`).
486
+ */
487
+ type GeminiHookCommandEntry = {
488
+ readonly name: string;
489
+ readonly type: "command";
490
+ readonly command: string;
491
+ /** Milliseconds, per the Gemini CLI's own `CommandHookConfig`. */
492
+ readonly timeout?: number;
493
+ };
494
+ type GeminiHookMatcherEntry = {
495
+ readonly matcher?: string;
496
+ /** True runs the group's hooks one after another; preserved, never written. */
497
+ readonly sequential?: boolean;
498
+ readonly hooks: readonly GeminiHookCommandEntry[];
499
+ };
500
+ type GeminiHooksObject = Partial<Record<GeminiHookEventName, readonly GeminiHookMatcherEntry[]>> & {
501
+ readonly enabled?: boolean;
502
+ readonly disabled?: readonly string[];
503
+ readonly notifications?: unknown;
504
+ };
505
+ type GeminiHooksSettings = {
506
+ readonly hooks?: GeminiHooksObject;
507
+ readonly [key: string]: unknown;
508
+ };
509
+ type RegisterGeminiHookOptions = {
510
+ /** Hook id as it will appear in settings.json; also the idempotency key. */
511
+ readonly name: string;
512
+ readonly command: string;
513
+ /** Defaults to `"*"` (every tool / every context). */
514
+ readonly matcher?: string;
515
+ /** Defaults to {@link GEMINI_REGISTRABLE_HOOK_EVENTS}. */
516
+ readonly events?: readonly GeminiHookEventName[];
517
+ /**
518
+ * Seconds, matching every other planner's vocabulary. Converted to the
519
+ * milliseconds the Gemini CLI expects before it is written.
520
+ */
521
+ readonly timeoutSeconds?: number;
522
+ /**
523
+ * Recognizes registrations this tool owns. Defaults to `name` equality — the
524
+ * documented idempotency key — but an installer that has to find entries an
525
+ * older version wrote under a different name can widen it.
526
+ */
527
+ readonly identifies?: HookHandlerPredicate;
528
+ };
529
+ type MergeGeminiHookResult = {
530
+ readonly settings: GeminiHooksSettings;
531
+ /** False when every requested event already had this exact registration. */
532
+ readonly changed: boolean;
533
+ readonly registeredEvents: readonly GeminiHookEventName[];
534
+ /** Per-event outcome, for a caller that reports what it is about to do. */
535
+ readonly changes: readonly HookDocumentChange[];
536
+ /** Non-empty when the document's `hooks` value is not the documented shape. */
537
+ readonly conflicts: readonly HookDocumentConflict[];
538
+ };
539
+ /**
540
+ * Merge this adapter's hook registration into an existing (parsed)
541
+ * `settings.json` value, once per requested event.
542
+ *
543
+ * Re-running with identical options is a no-op (`changed: false`). Existing
544
+ * hooks from other tools, matchers a developer narrowed by hand, and settings
545
+ * fields outside `hooks` are all preserved untouched.
546
+ */
547
+ declare const mergeGeminiHookRegistration: (existing: unknown, options: RegisterGeminiHookOptions) => MergeGeminiHookResult;
548
+ type RemoveGeminiHookOptions = {
549
+ /** Restrict removal to these events. Omitted means the whole event vocabulary. */
550
+ readonly events?: readonly GeminiHookEventName[];
551
+ /** Recognizes handlers this tool wrote, across versions. */
552
+ readonly identifies: HookHandlerPredicate;
553
+ };
554
+ /**
555
+ * Reverse {@link mergeGeminiHookRegistration}.
556
+ *
557
+ * An emptied matcher group, an emptied event, and an emptied `hooks` key are all
558
+ * dropped, which is what makes setup-then-uninstall restore the original
559
+ * document exactly.
560
+ *
561
+ * Removal names the full event vocabulary rather than letting the engine scan
562
+ * the document's own keys, because in this vocabulary not every key under
563
+ * `hooks` is an event: `HOOKS_CONFIG_FIELDS` puts `enabled`, `disabled`, and
564
+ * `notifications` there too. Scanning would read `hooks.enabled: true` as a
565
+ * malformed event list, report a conflict, and abandon the whole uninstall —
566
+ * leaving every registration in place on exactly the documents that had hooks
567
+ * configured most deliberately. `GEMINI_HOOK_EVENT_NAMES` is complete, so naming
568
+ * it loses nothing: the CLI cannot fire an event outside it.
569
+ */
570
+ declare const removeGeminiHookRegistration: (existing: unknown, options: RemoveGeminiHookOptions) => NestedHookDocumentResult;
571
+ declare const readGeminiHookRegistrations: (existing: unknown, identifies: HookHandlerPredicate) => ReadonlyMap<string, readonly string[]>;
572
+
573
+ /**
574
+ * One uniform interface over planners whose *document shapes differ*.
575
+ *
576
+ * Four providers, three shapes: Claude Code, the Codex CLI, and the Gemini CLI
577
+ * share the nested matcher-group document (with Gemini adding a `name` field),
578
+ * while Antigravity's hook file is a flat list per event. Keeping the shape
579
+ * knowledge inside each provider's planner and adapting only the *result* here
580
+ * is what lets `setup`, `diagnose`, and `uninstall` be written once.
581
+ *
582
+ * Nothing in this module reads or writes a file; `lifecycle.ts` does that.
583
+ */
584
+ /** The hook name this tool registers under, where the vocabulary has one. */
585
+ declare const MANAGED_HOOK_NAME = "otel-hook";
586
+ /**
587
+ * Substring that marks a command as this tool's, across versions.
588
+ *
589
+ * Setup has to recognize what an *older* version of itself wrote, or an upgrade
590
+ * that changed the command string (a new absolute path, a new `--endpoint`)
591
+ * would append a second registration and double every span. There is no field
592
+ * in either documented vocabulary to stamp ownership into, so the command
593
+ * string is the only available marker.
594
+ */
595
+ declare const DEFAULT_MANAGED_COMMAND_MARKER = "otel-hook";
596
+ /**
597
+ * The token that makes a marker *this tool's*.
598
+ *
599
+ * Ownership cannot be inferred from a command being "specific enough" — a
600
+ * plausible-looking marker like `run` or `npm` is specific enough to read as
601
+ * deliberate and still matches half the hooks a developer has configured. So the
602
+ * marker has to name this package, and the only name that does is this one.
603
+ */
604
+ declare const MANAGED_MARKER_TOKEN = "otel-hook";
605
+ type ManagedMarkerRejection = "empty" | "too-long" | "untrimmed" | "not-ownership-bearing";
606
+ /** Non-sensitive explanations, safe to print: the operator just typed the marker. */
607
+ declare const MANAGED_MARKER_REJECTION_DETAIL: Readonly<Record<ManagedMarkerRejection, string>>;
608
+ /**
609
+ * Why a managed marker is unusable, or `undefined` when it is safe.
610
+ *
611
+ * The marker is used as a **substring test** against commands already in a
612
+ * developer's configuration, and that test decides what `uninstall` deletes and
613
+ * what `setup` rewrites in place. Two failure modes, both destructive, and neither
614
+ * recoverable from a backup the developer does not have:
615
+ *
616
+ * - An empty marker makes `"".includes()` true for every handler, so
617
+ * `uninstall --managed-marker ""` would delete every hook configured by every
618
+ * tool.
619
+ * - A *generic* marker is the same bug wearing a disguise. `run` matches
620
+ * `npm run build`, `cargo run`, and any `runner.sh`; `npm` matches every npm
621
+ * script hook a developer has. Length and alphanumerics do not distinguish these
622
+ * from a real marker, so the test is ownership: the marker must either name this
623
+ * package or be an absolute path to it.
624
+ *
625
+ * Validated *before* a document is read, let alone written — a refusal costs one
626
+ * re-run, a wrong match costs a configuration nobody has a copy of.
627
+ */
628
+ declare const checkManagedMarker: (marker: string) => ManagedMarkerRejection | undefined;
629
+ /**
630
+ * Recognizes a hook handler this tool owns, by hook name or command marker.
631
+ *
632
+ * Throws on a marker {@link checkManagedMarker} refuses. A predicate is built
633
+ * before any file is opened, so throwing here cannot leave a document
634
+ * half-changed — and returning a match-everything predicate instead would turn
635
+ * an operator's typo into data loss.
636
+ */
637
+ declare const managedHookPredicate: (marker: string) => HookHandlerPredicate;
638
+ type RegistrationPlanInput = {
639
+ /** Parsed configuration document, or `undefined` when the file is absent. */
640
+ readonly existing?: unknown;
641
+ readonly command: string;
642
+ /** Overrides the planner's default event set. */
643
+ readonly events?: readonly string[];
644
+ readonly matcher?: string;
645
+ readonly timeoutSeconds?: number;
646
+ readonly identifies: HookHandlerPredicate;
647
+ };
648
+ type RegistrationRemovalInput = {
649
+ readonly existing?: unknown;
650
+ readonly events?: readonly string[];
651
+ readonly identifies: HookHandlerPredicate;
652
+ };
653
+ type ProviderRegistrationPlanner = {
654
+ readonly providerId: string;
655
+ /**
656
+ * Events registered when the caller names none: the intersection of "the
657
+ * provider documents it" and "this adapter turns it into telemetry". Each
658
+ * planner's module records the exclusions and why.
659
+ */
660
+ readonly defaultEvents: readonly string[];
661
+ merge(input: RegistrationPlanInput): NestedHookDocumentResult;
662
+ remove(input: RegistrationRemovalInput): NestedHookDocumentResult;
663
+ read(existing: unknown, identifies: HookHandlerPredicate): ReadonlyMap<string, readonly string[]>;
664
+ };
665
+ declare const findRegistrationPlanner: (providerId: string) => ProviderRegistrationPlanner | undefined;
666
+ declare const REGISTRATION_PLANNERS: readonly ProviderRegistrationPlanner[];
667
+
668
+ /**
669
+ * Per-provider registration availability, and the evidence behind it.
670
+ *
671
+ * `supported: false` is a statement about *this repository's* verified
672
+ * knowledge, not about the provider. Each entry is meant to be checkable: a
673
+ * reviewer should be able to read the reason, open the named source, and agree
674
+ * or disagree without running anything.
675
+ */
676
+ type ProviderRegistrationSupport = {
677
+ readonly providerId: string;
678
+ readonly supported: boolean;
679
+ /** Why registration is or is not offered, in one reviewable sentence. */
680
+ readonly reason: string;
681
+ /** Name of the planner to call, when supported. */
682
+ readonly helper?: string;
683
+ /** For an unsupported provider: precisely what would have to be verified. */
684
+ readonly evidenceBlocker?: string;
685
+ };
686
+ declare const PROVIDER_REGISTRATION_SUPPORT: readonly ProviderRegistrationSupport[];
687
+ declare const findRegistrationSupport: (providerId: string) => ProviderRegistrationSupport | undefined;
688
+ /** Provider ids this repository can plan a registration for, in catalog order. */
689
+ declare const SUPPORTED_REGISTRATION_PROVIDER_IDS: readonly string[];
690
+
691
+ /**
692
+ * Where each provider keeps the configuration document this tool registers into.
693
+ *
694
+ * A path here is a claim about a third party's on-disk layout, so each one names
695
+ * the source that established it. A provider with a verified *planner* but no
696
+ * verified *location* (Antigravity) is deliberately absent: `setup` then requires
697
+ * an explicit `--settings-file`, which is honest about what this repository knows
698
+ * rather than writing a plausible-looking path into a developer's home
699
+ * directory.
700
+ */
701
+ type RegistrationScope = "global" | "project";
702
+ declare const REGISTRATION_SCOPES: readonly RegistrationScope[];
703
+ type InstallLocation = {
704
+ readonly providerId: string;
705
+ readonly scope: RegistrationScope;
706
+ /** Path segments below the home directory (global) or project root (project). */
707
+ readonly segments: readonly string[];
708
+ /** One reviewable sentence naming what verified this path. */
709
+ readonly evidence: string;
710
+ };
711
+ declare const PROVIDER_INSTALL_LOCATIONS: readonly InstallLocation[];
712
+ /**
713
+ * Providers whose planner is verified but whose install location is not, with
714
+ * the blocker. `setup --provider <id> --settings-file <path>` still works.
715
+ */
716
+ declare const PROVIDERS_WITHOUT_VERIFIED_LOCATION: Readonly<Record<string, string>>;
717
+ /**
718
+ * Providers this tool can find on its own, in catalog order.
719
+ *
720
+ * This — not "every provider with a planner" — is what a bare `diagnose`
721
+ * sweeps: a provider whose path must be supplied by hand has nowhere to look.
722
+ */
723
+ declare const PROVIDERS_WITH_VERIFIED_LOCATION: readonly string[];
724
+ declare const findInstallLocation: (providerId: string, scope: RegistrationScope) => InstallLocation | undefined;
725
+ type ScopeRoots = {
726
+ readonly homeDir: string;
727
+ readonly projectDir: string;
728
+ };
729
+ declare const resolveInstallPath: (location: InstallLocation, roots: ScopeRoots) => string;
730
+
731
+ /**
732
+ * Reading and writing a *third party's* configuration document.
733
+ *
734
+ * Two properties matter more here than anywhere else in this package, because
735
+ * the file belongs to the developer and not to us:
736
+ *
737
+ * 1. **Never lose a byte we did not mean to change.** The file's indentation,
738
+ * line endings, and trailing newline are detected on read and reproduced on
739
+ * write, so a registration shows up in `git diff` as the lines it added and
740
+ * nothing else. A document that cannot be parsed is reported, never
741
+ * overwritten.
742
+ * 2. **Never leave a half-written file.** Every write lands through a temp file
743
+ * in the same directory plus `rename`, which is atomic on POSIX and, via
744
+ * libuv's `MoveFileExW(MOVEFILE_REPLACE_EXISTING)`, on Windows. A process
745
+ * killed mid-write leaves an orphaned temp file, never a truncated
746
+ * `settings.json`.
747
+ */
748
+ type JsonDocumentFormat = {
749
+ /** Indent string detected from the file, e.g. `" "` or `"\t"`. */
750
+ readonly indent: string;
751
+ readonly eol: "\n" | "\r\n";
752
+ readonly trailingNewline: boolean;
753
+ };
754
+ /**
755
+ * What a brand-new document looks like. `"\n"` rather than the platform EOL: a
756
+ * config file this tool creates should read the same on every machine that
757
+ * shares the repository, and every JSON parser accepts it.
758
+ */
759
+ declare const DEFAULT_DOCUMENT_FORMAT: JsonDocumentFormat;
760
+ type ReadDocumentResult = {
761
+ readonly status: "absent";
762
+ readonly format: JsonDocumentFormat;
763
+ } | {
764
+ readonly status: "ok";
765
+ readonly value: unknown;
766
+ readonly raw: string;
767
+ readonly format: JsonDocumentFormat;
768
+ } | {
769
+ readonly status: "unparseable";
770
+ readonly raw: string;
771
+ /** Non-sensitive: the parser message, never the file's contents. */
772
+ readonly detail: string;
773
+ readonly format: JsonDocumentFormat;
774
+ } | {
775
+ readonly status: "unreadable";
776
+ readonly detail: string;
777
+ };
778
+ /**
779
+ * Infer the indent, line ending, and trailing newline actually used.
780
+ *
781
+ * The indent is read from the first indented line rather than from the deepest
782
+ * one, because that is the level `JSON.stringify` will reproduce first and the
783
+ * only one it can reproduce at all — it has a single indent setting.
784
+ */
785
+ declare const detectDocumentFormat: (raw: string) => JsonDocumentFormat;
786
+ declare const renderJsonDocument: (value: unknown, format: JsonDocumentFormat) => string;
787
+ declare const readJsonDocument: (filePath: string) => Promise<ReadDocumentResult>;
788
+ /**
789
+ * Write `contents` to `filePath` atomically, creating parent directories.
790
+ *
791
+ * The temp file is created in the destination directory so the rename stays
792
+ * within one filesystem, and is fsynced before the rename so a crash cannot
793
+ * leave the renamed file pointing at unflushed data.
794
+ *
795
+ * A rename replaces the destination *inode*, so the mode travels with the temp
796
+ * file rather than with the path — which means an atomic replace silently
797
+ * re-permissions the file unless the original mode is carried across. An
798
+ * existing document keeps exactly the mode it had (a developer who chmodded
799
+ * their `settings.json` to 0600, or to 0644, keeps that decision); a file this
800
+ * tool creates gets {@link NEW_DOCUMENT_MODE} rather than whatever the umask
801
+ * would have allowed. The temp file is owner-only for its whole life, so the
802
+ * contents are never briefly readable by anyone who could not read the result.
803
+ */
804
+ declare const writeDocumentAtomically: (filePath: string, contents: string) => Promise<void>;
805
+
806
+ /**
807
+ * Cross-process advisory lock around one configuration file.
808
+ *
809
+ * Two `otel-hook setup` runs against the same `settings.json` — a shell loop, a
810
+ * provisioning tool, two terminals — would otherwise both read the original
811
+ * document and both write their own merge, so whichever finished last would
812
+ * silently drop the other's registration. Atomic renames make each *write*
813
+ * safe; only a lock makes the read-merge-write *sequence* safe.
814
+ *
815
+ * `open(path, "wx")` is the primitive: it either creates the file or fails with
816
+ * `EEXIST`, atomically, on every platform this package supports. A lock whose
817
+ * recorded acquisition time is older than `staleMillis` is assumed to belong to
818
+ * a process that crashed while holding it and is reclaimed, so a killed setup
819
+ * cannot wedge every later one.
820
+ *
821
+ * This is a separate implementation from the state store's session lock on
822
+ * purpose: that one is namespaced under the state directory and keyed by session
823
+ * id, while this one has to live beside a file it does not own.
824
+ */
825
+ type FileLockOptions = {
826
+ readonly clock: Clock;
827
+ /** How long to wait for the holder before giving up. Default 5,000ms. */
828
+ readonly timeoutMillis?: number;
829
+ /** A lock older than this is treated as abandoned. Default 30,000ms. */
830
+ readonly staleMillis?: number;
831
+ /** Delay between acquisition attempts. Default 25ms. */
832
+ readonly pollIntervalMillis?: number;
833
+ };
834
+ declare class FileLockTimeoutError extends Error {
835
+ constructor(lockPath: string, timeoutMillis: number);
836
+ }
837
+ /** Where the lock for a configuration file lives: beside it, clearly ours. */
838
+ declare const lockPathFor: (filePath: string) => string;
839
+ /**
840
+ * Run `fn` while holding the lock for `filePath`, releasing it on every path.
841
+ *
842
+ * The timeout bounds only lock *acquisition*; `fn` itself is not interrupted,
843
+ * because aborting a caller partway through a read-merge-write is exactly the
844
+ * outcome the lock exists to prevent.
845
+ */
846
+ declare const withFileLock: <T>(filePath: string, options: FileLockOptions, fn: () => Promise<T>) => Promise<T>;
847
+
848
+ /**
849
+ * `setup`, `diagnose`, and `uninstall` over a provider's configuration file.
850
+ *
851
+ * The three commands are one function because they are one algorithm with three
852
+ * endings: resolve where the document lives, take the lock, read it, ask the
853
+ * provider's pure planner what the document should become, and then either
854
+ * report the plan (`diagnose`, `--dry-run`) or write it atomically. Sharing the
855
+ * path means a dry run cannot drift from what a real run would do — it is
856
+ * literally the same plan, printed instead of written.
857
+ *
858
+ * Refusals are deliberate and specific. A document that does not parse, or whose
859
+ * `hooks` value is not the documented shape, is reported and left exactly as it
860
+ * is: overwriting a developer's configuration to make an installer succeed is a
861
+ * worse outcome than the installer failing.
862
+ */
863
+ type RegistrationAction = "setup" | "diagnose" | "uninstall";
864
+ type RegistrationOutcomeStatus =
865
+ /** A change is required and this is a dry run. */
866
+ "planned"
867
+ /** A change was required and has been written. */
868
+ | "applied"
869
+ /** The document already says exactly what it should. */
870
+ | "unchanged"
871
+ /** Nothing of ours is registered here (diagnose and uninstall). */
872
+ | "absent"
873
+ /** We refuse to touch this document; see `problems`. */
874
+ | "blocked"
875
+ /** This repository cannot plan a registration for this provider. */
876
+ | "unsupported"
877
+ /** The filesystem operation itself failed. */
878
+ | "failed";
879
+ type RegistrationOutcome = {
880
+ readonly providerId: string;
881
+ readonly scope: RegistrationScope;
882
+ readonly configPath?: string;
883
+ /** What established the path and document shape. */
884
+ readonly evidence?: string;
885
+ readonly status: RegistrationOutcomeStatus;
886
+ readonly changed: boolean;
887
+ readonly changes: readonly HookDocumentChange[];
888
+ readonly conflicts: readonly HookDocumentConflict[];
889
+ /** Events with a registration of ours right now. */
890
+ readonly registeredEvents: readonly string[];
891
+ /** Events that should be registered but are not. */
892
+ readonly missingEvents: readonly string[];
893
+ /** Informational; never a reason to exit non-zero. */
894
+ readonly notes: readonly string[];
895
+ /** Anything an operator must act on. Non-empty means the run is not `ok`. */
896
+ readonly problems: readonly string[];
897
+ /** Exact bytes a non-dry run would write. Present only when a change is planned. */
898
+ readonly plannedContents?: string;
899
+ };
900
+ type RegistrationReport = {
901
+ readonly action: RegistrationAction;
902
+ readonly dryRun: boolean;
903
+ readonly ok: boolean;
904
+ readonly hookCommand: string;
905
+ readonly outcomes: readonly RegistrationOutcome[];
906
+ };
907
+ type RegistrationLifecycleRequest = {
908
+ readonly action: RegistrationAction;
909
+ readonly providerIds: readonly string[];
910
+ readonly scopes: readonly RegistrationScope[];
911
+ readonly roots: ScopeRoots;
912
+ /** Overrides the resolved location. Required for a provider with no verified path. */
913
+ readonly configFile?: string;
914
+ /** Defaults to {@link defaultHookCommand} for each provider. */
915
+ readonly command?: string;
916
+ readonly events?: readonly string[];
917
+ readonly matcher?: string;
918
+ readonly timeoutSeconds?: number;
919
+ readonly managedMarker?: string;
920
+ readonly dryRun: boolean;
921
+ readonly clock: Clock;
922
+ readonly lock?: Omit<FileLockOptions, "clock">;
923
+ };
924
+ /** What this tool registers when the caller names no command. */
925
+ declare const defaultHookCommand: (providerId: string) => string;
926
+ /**
927
+ * Run one lifecycle action across every requested provider and scope.
928
+ *
929
+ * Targets are processed sequentially rather than concurrently: they are few, and
930
+ * a serial run makes the output order deterministic and keeps two targets that
931
+ * resolve to the same file (a `--settings-file` naming a shared document) from
932
+ * contending for the same lock.
933
+ */
934
+ declare const runRegistrationLifecycle: (request: RegistrationLifecycleRequest) => Promise<RegistrationReport>;
935
+
936
+ /**
937
+ * Registration lifecycle: pure planners, plus the safe application of a plan.
938
+ *
939
+ * Two layers, deliberately separated:
940
+ *
941
+ * - **Planners** (`providers/<id>/registration.ts`, re-exported here) are pure.
942
+ * They take the *already parsed* contents of a provider's configuration
943
+ * document and return the document to write back plus whether anything
944
+ * changed. ADR 0003 keeps a provider adapter away from the filesystem, and a
945
+ * pure merge is testable against every "already registered", "registered with
946
+ * an older command", and "unrelated hooks present" case without a temporary
947
+ * directory.
948
+ * - **Lifecycle** (`lifecycle.ts`) reads and writes real files: locking a
949
+ * third party's config for the read-merge-write, preserving its formatting,
950
+ * writing atomically, and refusing rather than clobbering when the document
951
+ * is not what the provider documents.
952
+ *
953
+ * Registration is only offered for providers whose configuration contract this
954
+ * repository has verified. {@link PROVIDER_REGISTRATION_SUPPORT} names the
955
+ * others and says exactly what would unblock them — an invented settings shape
956
+ * written into a real `settings.json` is worse than no installer at all.
957
+ */
958
+
959
+ type PlanProviderRegistrationInput = {
960
+ readonly providerId: typeof GEMINI_PROVIDER_ID;
961
+ /** Parsed contents of the provider's settings document, if one exists. */
962
+ readonly existing?: unknown;
963
+ readonly options: RegisterGeminiHookOptions;
964
+ } | {
965
+ readonly providerId: typeof ANTIGRAVITY_PROVIDER_ID;
966
+ readonly existing?: unknown;
967
+ readonly options: Omit<MergeAntigravityHookRegistrationInput, "existing">;
968
+ } | {
969
+ readonly providerId: typeof CLAUDE_CODE_PROVIDER_ID;
970
+ readonly existing?: unknown;
971
+ readonly options: Omit<ClaudeHookRegistrationOptions, "existing" | "identifies"> & {
972
+ readonly identifies?: HookHandlerPredicate;
973
+ };
974
+ } | {
975
+ readonly providerId: typeof CODEX_PROVIDER_ID;
976
+ readonly existing?: unknown;
977
+ readonly options: Omit<CodexHookRegistrationOptions, "existing" | "identifies"> & {
978
+ readonly identifies?: HookHandlerPredicate;
979
+ };
980
+ } | {
981
+ readonly providerId: typeof CURSOR_PROVIDER_ID;
982
+ readonly existing?: unknown;
983
+ readonly options: Omit<MergeCursorHookRegistrationInput, "existing" | "identifies"> & {
984
+ readonly identifies?: HookHandlerPredicate;
985
+ };
986
+ } | {
987
+ readonly providerId: string;
988
+ readonly existing?: unknown;
989
+ readonly options?: unknown;
990
+ };
991
+ type PlanProviderRegistrationResult = {
992
+ readonly status: "planned";
993
+ readonly providerId: string;
994
+ /** Write this back verbatim; unrelated keys are carried through unchanged. */
995
+ readonly document: Record<string, unknown>;
996
+ /** False when the document already contained exactly this registration. */
997
+ readonly changed: boolean;
998
+ readonly changes: readonly HookDocumentChange[];
999
+ } | {
1000
+ /** The document is not the shape this provider documents; nothing was changed. */
1001
+ readonly status: "conflict";
1002
+ readonly providerId: string;
1003
+ readonly conflicts: readonly HookDocumentConflict[];
1004
+ } | {
1005
+ readonly status: "unsupported";
1006
+ readonly providerId: string;
1007
+ readonly reason: string;
1008
+ } | {
1009
+ readonly status: "invalid";
1010
+ readonly providerId: string;
1011
+ readonly reason: string;
1012
+ };
1013
+ /**
1014
+ * Plan one provider's hook registration.
1015
+ *
1016
+ * Idempotent: calling it again with the same `options` against the document it
1017
+ * returned yields `changed: false` and an identical document.
1018
+ */
1019
+ declare const planProviderRegistration: (input: PlanProviderRegistrationInput) => PlanProviderRegistrationResult;
1020
+
1021
+ export { type AntigravityHookCommandEntry, CLAUDE_HOOK_EVENTS_MODELLED, CLAUDE_REGISTRABLE_HOOK_EVENTS, CLAUDE_UNREGISTERED_HOOK_EVENTS, CODEX_HOOK_EVENTS_MODELLED, CODEX_REGISTRABLE_HOOK_EVENTS, CODEX_UNREGISTERED_HOOK_EVENTS, CURSOR_HOOKS_DOCUMENT_VERSION, CURSOR_HOOK_EVENTS_MODELLED, CURSOR_REGISTRABLE_HOOK_EVENTS, CURSOR_UNREGISTERED_HOOK_EVENTS, type ClaudeHookRegistrationOptions, type ClaudeHookRemovalOptions, type CodexHookRegistrationOptions, type CodexHookRemovalOptions, type CodexHooksFeatureFlag, type CommandHookEntry, type CursorHookCommandEntry, type CursorHookDocumentResult, type CursorHookRemovalInput, DEFAULT_DOCUMENT_FORMAT, DEFAULT_MANAGED_COMMAND_MARKER, type FileLockOptions, FileLockTimeoutError, type GeminiHookCommandEntry, type GeminiHookMatcherEntry, type GeminiHooksSettings, type HookDocumentAction, type HookDocumentChange, type HookDocumentConflict, type HookGroupEntry, type HookHandlerPredicate, type InstallLocation, type JsonDocumentFormat, MANAGED_HOOK_NAME, MANAGED_MARKER_REJECTION_DETAIL, MANAGED_MARKER_TOKEN, type ManagedMarkerRejection, type MergeAntigravityHookRegistrationInput, type MergeAntigravityHookRegistrationResult, type MergeCursorHookRegistrationInput, type MergeGeminiHookResult, type MergeNestedHookInput, type NestedHookDocumentResult, PROVIDERS_WITHOUT_VERIFIED_LOCATION, PROVIDERS_WITH_VERIFIED_LOCATION, PROVIDER_INSTALL_LOCATIONS, PROVIDER_REGISTRATION_SUPPORT, type PlanProviderRegistrationInput, type PlanProviderRegistrationResult, type ProviderRegistrationPlanner, type ProviderRegistrationSupport, REGISTRATION_PLANNERS, REGISTRATION_SCOPES, type ReadDocumentResult, type RegisterGeminiHookOptions, type RegistrationAction, type RegistrationLifecycleRequest, type RegistrationOutcome, type RegistrationOutcomeStatus, type RegistrationPlanInput, type RegistrationRemovalInput, type RegistrationReport, type RegistrationScope, type RemoveAntigravityHookRegistrationInput, type RemoveGeminiHookOptions, type RemoveNestedHookInput, SUPPORTED_REGISTRATION_PROVIDER_IDS, type ScopeRoots, checkManagedMarker, defaultHookCommand, detectDocumentFormat, findInstallLocation, findRegistrationPlanner, findRegistrationSupport, lockPathFor, managedHookPredicate, mergeAntigravityHookRegistration, mergeClaudeHookRegistration, mergeCodexHookRegistration, mergeCursorHookRegistration, mergeGeminiHookRegistration, mergeNestedHookRegistration, planProviderRegistration, readAntigravityHookRegistrations, readClaudeHookRegistrations, readCodexHookRegistrations, readCodexHooksFeatureFlag, readCursorHookRegistrations, readGeminiHookRegistrations, readJsonDocument, readNestedHookRegistrations, removeAntigravityHookRegistration, removeClaudeHookRegistration, removeCodexHookRegistration, removeCursorHookRegistration, removeGeminiHookRegistration, removeNestedHookRegistrations, renderJsonDocument, resolveInstallPath, runRegistrationLifecycle, withFileLock, writeDocumentAtomically };