@dzhechkov/harness-core 0.4.5 → 0.5.1

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 (141) hide show
  1. package/.dz-manifest.json +489 -105
  2. package/README.md +116 -5
  3. package/dist/agents-policy.d.ts +67 -0
  4. package/dist/agents-policy.d.ts.map +1 -0
  5. package/dist/agents-policy.js +258 -0
  6. package/dist/agents-policy.js.map +1 -0
  7. package/dist/codex-hooks-assets.d.ts +47 -0
  8. package/dist/codex-hooks-assets.d.ts.map +1 -0
  9. package/dist/codex-hooks-assets.js +324 -0
  10. package/dist/codex-hooks-assets.js.map +1 -0
  11. package/dist/codex-hooks-verify.d.ts +95 -0
  12. package/dist/codex-hooks-verify.d.ts.map +1 -0
  13. package/dist/codex-hooks-verify.js +169 -0
  14. package/dist/codex-hooks-verify.js.map +1 -0
  15. package/dist/codex-hooks.d.ts +341 -0
  16. package/dist/codex-hooks.d.ts.map +1 -0
  17. package/dist/codex-hooks.js +541 -0
  18. package/dist/codex-hooks.js.map +1 -0
  19. package/dist/discrimination-gate.d.ts +88 -15
  20. package/dist/discrimination-gate.d.ts.map +1 -1
  21. package/dist/discrimination-gate.js +343 -51
  22. package/dist/discrimination-gate.js.map +1 -1
  23. package/dist/feature-adr-checkpoints.d.ts +22 -0
  24. package/dist/feature-adr-checkpoints.d.ts.map +1 -1
  25. package/dist/feature-adr-checkpoints.js +42 -0
  26. package/dist/feature-adr-checkpoints.js.map +1 -1
  27. package/dist/feature-adr-routing.d.ts +218 -5
  28. package/dist/feature-adr-routing.d.ts.map +1 -1
  29. package/dist/feature-adr-routing.js +583 -54
  30. package/dist/feature-adr-routing.js.map +1 -1
  31. package/dist/guard.d.ts +13 -0
  32. package/dist/guard.d.ts.map +1 -1
  33. package/dist/guard.js +25 -1
  34. package/dist/guard.js.map +1 -1
  35. package/dist/index.d.ts +23 -7
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +37 -4
  38. package/dist/index.js.map +1 -1
  39. package/dist/loop-blobs.generated.d.ts +1 -1
  40. package/dist/loop-blobs.generated.d.ts.map +1 -1
  41. package/dist/loop-blobs.generated.js +12 -3
  42. package/dist/loop-blobs.generated.js.map +1 -1
  43. package/dist/loop-plan.d.ts +70 -0
  44. package/dist/loop-plan.d.ts.map +1 -1
  45. package/dist/loop-plan.js +103 -0
  46. package/dist/loop-plan.js.map +1 -1
  47. package/dist/loop-render.d.ts.map +1 -1
  48. package/dist/loop-render.js +37 -129
  49. package/dist/loop-render.js.map +1 -1
  50. package/dist/loop-run-semantics.d.ts +130 -0
  51. package/dist/loop-run-semantics.d.ts.map +1 -0
  52. package/dist/loop-run-semantics.js +257 -0
  53. package/dist/loop-run-semantics.js.map +1 -0
  54. package/dist/loop-trace.d.ts +31 -2
  55. package/dist/loop-trace.d.ts.map +1 -1
  56. package/dist/loop-trace.js +89 -12
  57. package/dist/loop-trace.js.map +1 -1
  58. package/dist/managed-hooks.d.ts +86 -0
  59. package/dist/managed-hooks.d.ts.map +1 -0
  60. package/dist/managed-hooks.js +101 -0
  61. package/dist/managed-hooks.js.map +1 -0
  62. package/dist/mutation-gate.d.ts +14 -0
  63. package/dist/mutation-gate.d.ts.map +1 -1
  64. package/dist/mutation-gate.js +25 -2
  65. package/dist/mutation-gate.js.map +1 -1
  66. package/dist/named-lock.d.ts +57 -0
  67. package/dist/named-lock.d.ts.map +1 -0
  68. package/dist/named-lock.js +247 -0
  69. package/dist/named-lock.js.map +1 -0
  70. package/dist/operations.d.ts +229 -0
  71. package/dist/operations.d.ts.map +1 -1
  72. package/dist/operations.js +880 -26
  73. package/dist/operations.js.map +1 -1
  74. package/dist/parity.d.ts +106 -1
  75. package/dist/parity.d.ts.map +1 -1
  76. package/dist/parity.js +209 -5
  77. package/dist/parity.js.map +1 -1
  78. package/dist/qe-bridge.d.ts +291 -0
  79. package/dist/qe-bridge.d.ts.map +1 -0
  80. package/dist/qe-bridge.js +538 -0
  81. package/dist/qe-bridge.js.map +1 -0
  82. package/dist/recall-usage.d.ts +53 -0
  83. package/dist/recall-usage.d.ts.map +1 -1
  84. package/dist/recall-usage.js +125 -2
  85. package/dist/recall-usage.js.map +1 -1
  86. package/dist/score.d.ts.map +1 -1
  87. package/dist/score.js +43 -9
  88. package/dist/score.js.map +1 -1
  89. package/dist/setup.d.ts.map +1 -1
  90. package/dist/setup.js +14 -26
  91. package/dist/setup.js.map +1 -1
  92. package/dist/shell-veto-policy.d.ts +53 -0
  93. package/dist/shell-veto-policy.d.ts.map +1 -0
  94. package/dist/shell-veto-policy.js +103 -0
  95. package/dist/shell-veto-policy.js.map +1 -0
  96. package/dist/skills.d.ts +86 -1
  97. package/dist/skills.d.ts.map +1 -1
  98. package/dist/skills.js +116 -1
  99. package/dist/skills.js.map +1 -1
  100. package/dist/targets.d.ts +75 -0
  101. package/dist/targets.d.ts.map +1 -1
  102. package/dist/targets.js +160 -0
  103. package/dist/targets.js.map +1 -1
  104. package/dist/workflow-run-dispatch.d.ts +230 -0
  105. package/dist/workflow-run-dispatch.d.ts.map +1 -0
  106. package/dist/workflow-run-dispatch.js +363 -0
  107. package/dist/workflow-run-dispatch.js.map +1 -0
  108. package/dist/workflow-run.d.ts +498 -0
  109. package/dist/workflow-run.d.ts.map +1 -0
  110. package/dist/workflow-run.js +1359 -0
  111. package/dist/workflow-run.js.map +1 -0
  112. package/package.json +6 -5
  113. package/sbom.json +1099 -139
  114. package/src/agents-policy.ts +338 -0
  115. package/src/codex-hooks-assets.ts +328 -0
  116. package/src/codex-hooks-verify.ts +237 -0
  117. package/src/codex-hooks.ts +723 -0
  118. package/src/discrimination-gate.ts +456 -58
  119. package/src/feature-adr-checkpoints.ts +38 -0
  120. package/src/feature-adr-routing.ts +697 -75
  121. package/src/guard.ts +36 -1
  122. package/src/index.ts +162 -2
  123. package/src/loop-blobs.generated.ts +12 -3
  124. package/src/loop-plan.ts +185 -0
  125. package/src/loop-render.ts +37 -127
  126. package/src/loop-run-semantics.ts +278 -0
  127. package/src/loop-trace.ts +84 -10
  128. package/src/managed-hooks.ts +150 -0
  129. package/src/mutation-gate.ts +24 -2
  130. package/src/named-lock.ts +277 -0
  131. package/src/operations.ts +1121 -29
  132. package/src/parity.ts +295 -6
  133. package/src/qe-bridge.ts +737 -0
  134. package/src/recall-usage.ts +184 -1
  135. package/src/score.ts +50 -9
  136. package/src/setup.ts +26 -27
  137. package/src/shell-veto-policy.ts +119 -0
  138. package/src/skills.ts +174 -1
  139. package/src/targets.ts +189 -0
  140. package/src/workflow-run-dispatch.ts +459 -0
  141. package/src/workflow-run.ts +1743 -0
@@ -0,0 +1,341 @@
1
+ /**
2
+ * The Codex hook registry model (`crossrt-2-codex-hooks`, ADR-001).
3
+ *
4
+ * Pure: paths, the managed entry set, sha-based attribution, the manifest, drift, and the TOML text
5
+ * of a trust block. Every filesystem and process action lives in `operations.ts`.
6
+ *
7
+ * ## Measured facts this module encodes (M0 spike, codex-cli 0.147.0 — see
8
+ * `features/crossrt-2-codex-hooks/07_code_changes/probe-results/spike-arming.md`)
9
+ *
10
+ * - `$CODEX_HOME/hooks.json` is the user registry and **`CODEX_HOME` relocates discovery**, which is
11
+ * what makes every automated probe hermetic (G-H). `$CODEX_HOME/hooks/hooks.json` is the PLUGIN
12
+ * bundle layout and does not fire.
13
+ * - Entries are trust-gated. An untrusted entry is silently not run. Trust is persisted per entry in
14
+ * `$CODEX_HOME/config.toml` as `[hooks.state."<key>"] trusted_hash = "<currentHash>"`, and both
15
+ * `key` and `currentHash` come from the runtime's own `hooks/list` RPC — they are **read, never
16
+ * computed**, because `currentHash`'s preimage is internal to codex.
17
+ * - `timeout` is in SECONDS and IS honored (600 → 5, MEASURED). `timeoutSec` in an entry is
18
+ * **silently ignored** and leaves the 600 s default in place — which is why this module emits
19
+ * `timeout` and a test pins the key set (AM-15, now probe-proven by spike S2).
20
+ * - The hook runner spawns via `$SHELL -lc`, so the emitted command is a SHELL string: the
21
+ * interpreter is an absolute `process.execPath` and both paths are single-quoted (AM-32/AM-35d).
22
+ *
23
+ * @packageDocumentation
24
+ */
25
+ /**
26
+ * Bump when a helper BODY changes: a changed body changes codex's `currentHash` ⇒ re-trust.
27
+ *
28
+ * 2 — the independent-QE fix round: the veto note stopped persisting the raw command line and the
29
+ * notes log/dir modes are now enforced on every write (finding 8).
30
+ * 3 — fix round 2: the note's `commandSynopsis` is a binary NAME or `(redacted)` — an
31
+ * env-assignment first token (`SECRET=xyz ssh …`) carried the credential the redaction removed
32
+ * everywhere else (R2-8).
33
+ */
34
+ export declare const DZ_HOOK_HELPER_VERSION = 3;
35
+ /** Seconds. Probe-proven (spike S2): `timeout` is honored, the unset default is 600 s. */
36
+ export declare const DZ_HOOK_TIMEOUT_SECONDS = 5;
37
+ /** The wide matcher (AM-8). Narrowing needs a recorded live probe; the guard keys on the payload. */
38
+ export declare const DZ_VETO_MATCHER = "Bash|shell|local_shell";
39
+ export interface CodexHooksPaths {
40
+ readonly codexHome: string;
41
+ readonly registry: string;
42
+ readonly configToml: string;
43
+ readonly helperDir: string;
44
+ readonly vetoHelper: string;
45
+ readonly recallHelper: string;
46
+ readonly manifest: string;
47
+ readonly errorLog: string;
48
+ }
49
+ /** Every path this leg touches, all `CODEX_HOME`-relative (AM-13). */
50
+ export declare function codexHooksPaths(codexHome: string): CodexHooksPaths;
51
+ /** The EMITTER's write-set (AM-12). The RUNTIME's is stated separately — see {@link runtimeWriteSet}. */
52
+ export declare function emitterWriteSet(paths: CodexHooksPaths): readonly string[];
53
+ /**
54
+ * The RUNTIME's write-set (AM-33). Exactly one path beyond the emitter's, and it is
55
+ * `CODEX_HOME`-local: a helper must never create a `.dz/` inside a repository the user merely ran
56
+ * `codex` in. (Recall rows are the one exception and they are opt-in-gated: they land in an
57
+ * ALREADY-EXISTING opted-in project's `.dz/`, so nothing is ever created.)
58
+ */
59
+ export declare function runtimeWriteSet(paths: CodexHooksPaths): readonly string[];
60
+ /** A single quote inside a single-quoted shell word cannot be escaped — such a path is REFUSED. */
61
+ export declare function isSafeForSingleQuote(path: string): boolean;
62
+ export declare function singleQuote(path: string): string;
63
+ /**
64
+ * The shell string codex runs. Absolute interpreter + single-quoted paths (AM-32/AM-35d).
65
+ * @throws when either path cannot be safely quoted — never emit a broken entry that READS installed.
66
+ */
67
+ export declare function buildHookCommand(nodePath: string, scriptPath: string): string;
68
+ export type CodexHookId = 'codex-veto' | 'codex-recall';
69
+ export type CodexHookEvent = 'PreToolUse' | 'UserPromptSubmit';
70
+ export interface CodexHookSpec {
71
+ readonly id: CodexHookId;
72
+ readonly event: CodexHookEvent;
73
+ readonly matcher?: string;
74
+ readonly script: 'veto' | 'recall';
75
+ }
76
+ /** The two entries this leg ships, and nothing else. */
77
+ export declare const CODEX_MANAGED_HOOKS: readonly CodexHookSpec[];
78
+ export interface BuildManagedEntriesOptions {
79
+ readonly nodePath: string;
80
+ readonly paths: CodexHooksPaths;
81
+ }
82
+ export interface ManagedEntry {
83
+ readonly id: CodexHookId;
84
+ readonly event: CodexHookEvent;
85
+ readonly command: string;
86
+ readonly entry: Record<string, unknown>;
87
+ }
88
+ /**
89
+ * Build the managed entries.
90
+ *
91
+ * Key set is EXACTLY `{matcher?, hooks:[{type, command, timeout}]}` (AM-15). `timeout` is included
92
+ * because spike S2 recorded a probe proving the registry loads with it AND honors it; every other
93
+ * key stays out until it has its own probe.
94
+ */
95
+ export declare function buildManagedEntries(opts: BuildManagedEntriesOptions): readonly ManagedEntry[];
96
+ /** `managed` in the shape {@link mergeManagedHookEntries} takes. */
97
+ export declare function managedByEvent(entries: readonly ManagedEntry[]): Record<string, unknown[]>;
98
+ export declare function codexHookSha256(text: string): string;
99
+ export interface CodexHookManifestEntry {
100
+ readonly id: CodexHookId;
101
+ readonly event: CodexHookEvent;
102
+ readonly matcher?: string;
103
+ readonly commandSha256: string;
104
+ /** The runtime trust key, as reported by `hooks/list`. Absent until a list succeeded. */
105
+ readonly trustKey?: string;
106
+ }
107
+ export interface CodexHookVerifyRecord {
108
+ readonly verdict: string;
109
+ readonly trust: string;
110
+ readonly bypassed: boolean;
111
+ readonly at: string;
112
+ readonly transcript?: string;
113
+ }
114
+ export interface CodexHookManifest {
115
+ readonly version: 1;
116
+ readonly writtenAt: string;
117
+ readonly codexVersion: string;
118
+ readonly registryPath: string;
119
+ readonly helperVersion: number;
120
+ readonly nodePath: string;
121
+ readonly entries: readonly CodexHookManifestEntry[];
122
+ readonly lastVerify?: CodexHookVerifyRecord;
123
+ }
124
+ export interface BuildManifestOptions {
125
+ readonly entries: readonly ManagedEntry[];
126
+ readonly paths: CodexHooksPaths;
127
+ readonly codexVersion: string;
128
+ readonly writtenAt: string;
129
+ readonly nodePath: string;
130
+ readonly trustKeys?: Readonly<Record<string, string>>;
131
+ readonly lastVerify?: CodexHookVerifyRecord;
132
+ }
133
+ export declare function buildCodexHookManifest(opts: BuildManifestOptions): CodexHookManifest;
134
+ export declare function parseCodexHookManifest(text: string): CodexHookManifest | undefined;
135
+ /**
136
+ * Attribution is `codexHookSha256(command) ∈ manifest` — never a substring guess.
137
+ *
138
+ * ADR-001 §3: dz deletes only what it can PROVE it wrote. An entry that merely looks like ours (it
139
+ * mentions our helper filename) but whose command hash is absent from the manifest is KEPT, counted
140
+ * in `unattributable`, and warned about. A hand-edited managed command therefore survives.
141
+ */
142
+ export declare function isDzManagedEntry(entry: unknown, manifest: CodexHookManifest | undefined): boolean;
143
+ /**
144
+ * Rebuild an OWNED entry from only the handlers that are NOT ours — per-HANDLER attribution.
145
+ *
146
+ * ADR-001 §5 promises that dz deletes only what it can prove it wrote. Attribution was applied to a
147
+ * whole MATCHER GROUP: a group holding one dz handler and one of the user's was removed (or
148
+ * replaced) wholesale, so a foreign handler was deleted by a rule written to protect it
149
+ * (independent review, finding 6). One dz handler in the group must cost exactly that handler.
150
+ *
151
+ * Returns `null` when every handler in the entry was ours (the entry itself is then dropped), and
152
+ * a rebuilt entry — same keys, same order, minus our handlers — when something foreign survives.
153
+ * A legacy FLAT entry (`{type, command}`) is one handler and has nothing to salvage.
154
+ */
155
+ export declare function retainForeignHandlers(entry: unknown, manifest: CodexHookManifest | undefined): unknown | null;
156
+ /** Cheap resemblance test — drives the `unattributable` COUNT only, never a deletion. */
157
+ export declare function looksLikeDzEntry(entry: unknown): boolean;
158
+ export interface CodexRegistry {
159
+ /** Every top-level key other than `hooks`, preserved verbatim. */
160
+ readonly rest: Record<string, unknown>;
161
+ readonly hooks: Record<string, unknown[]>;
162
+ }
163
+ export type ParseRegistryResult = {
164
+ readonly ok: true;
165
+ readonly registry: CodexRegistry;
166
+ } | {
167
+ readonly ok: false;
168
+ readonly error: string;
169
+ };
170
+ /**
171
+ * Parse an existing registry. An unparseable file is an ERROR, never an empty registry: silently
172
+ * treating it as `{}` would overwrite entries we promised to preserve (I1).
173
+ */
174
+ export declare function parseCodexRegistry(text: string | undefined): ParseRegistryResult;
175
+ export declare function serializeCodexRegistry(registry: CodexRegistry): string;
176
+ export interface CodexHooksPlan {
177
+ readonly registry: CodexRegistry;
178
+ readonly text: string;
179
+ readonly changed: boolean;
180
+ readonly foreignPreserved: number;
181
+ readonly unattributable: number;
182
+ }
183
+ export interface PlanCodexHooksInput {
184
+ readonly currentText: string | undefined;
185
+ readonly entries: readonly ManagedEntry[];
186
+ readonly manifest: CodexHookManifest | undefined;
187
+ }
188
+ /**
189
+ * Compute the merged registry.
190
+ *
191
+ * The merge itself is `mergeManagedHookEntries` — the SAME implementation the Claude path uses
192
+ * (AM-3 / G-E). Only the attribution predicate differs.
193
+ */
194
+ export declare function planCodexHooks(input: PlanCodexHooksInput): {
195
+ ok: true;
196
+ plan: CodexHooksPlan;
197
+ } | {
198
+ ok: false;
199
+ error: string;
200
+ };
201
+ export interface RemoveCodexHooksResult {
202
+ readonly registry: CodexRegistry;
203
+ readonly text: string;
204
+ readonly removed: number;
205
+ readonly changed: boolean;
206
+ readonly unattributable: number;
207
+ }
208
+ /**
209
+ * `--remove`: delete ONLY manifest-attributed entries.
210
+ *
211
+ * With the manifest deleted this removes **zero** entries and reports them all as `unattributable`.
212
+ * That is the intended, conservative behaviour: dz never deletes what it cannot prove it wrote.
213
+ */
214
+ export declare function removeCodexHooks(currentText: string | undefined, manifest: CodexHookManifest | undefined): {
215
+ ok: true;
216
+ result: RemoveCodexHooksResult;
217
+ } | {
218
+ ok: false;
219
+ error: string;
220
+ };
221
+ export interface DriftReport {
222
+ /** Both managed entries present in the registry and attributable. */
223
+ readonly installed: boolean;
224
+ readonly presentIds: readonly CodexHookId[];
225
+ readonly missingIds: readonly CodexHookId[];
226
+ readonly foreignPreserved: number;
227
+ readonly unattributable: number;
228
+ /** A managed command whose hash is not the one the manifest records for that id. */
229
+ readonly drifted: readonly CodexHookId[];
230
+ }
231
+ /** `--check` recomputes from the FILE; it never trusts the manifest's claim on its own. */
232
+ export declare function diffCodexHooks(currentText: string | undefined, entries: readonly ManagedEntry[], manifest: CodexHookManifest | undefined): DriftReport;
233
+ /** codex's snake_case event spelling inside a trust key (MEASURED from `hooks/list`). */
234
+ export declare function trustEventName(event: CodexHookEvent): string;
235
+ /**
236
+ * Compare two event spellings the way the runtime actually spells them.
237
+ *
238
+ * MEASURED, both on this machine, on the SAME response shape:
239
+ * - the trust KEY embeds `pre_tool_use` / `user_prompt_submit` (snake_case);
240
+ * - `hooks/list`'s `eventName` FIELD is `preToolUse` / `userPromptSubmit` on **codex-cli 0.148.0**
241
+ * (reproducer: `listCodexHooks(<temp home>)` after an install — the rows are printed verbatim in
242
+ * `07_code_changes/probe-results/fixround/trust-diagnosis.txt`).
243
+ *
244
+ * Pinning either spelling alone silently drops every row: the fix round's first cut compared the
245
+ * field against the KEY spelling, `hooks/list` matched 0 of 2 entries, trust was never written, and
246
+ * the live probe's ARMED leg stopped blocking. Case and separators are therefore normalised away —
247
+ * the spelling is the runtime's cosmetic choice, the EVENT is the fact.
248
+ */
249
+ export declare function sameHookEvent(a: string, b: string): boolean;
250
+ /**
251
+ * The trust key codex uses: `<sourcePath>:<snake_event>:<groupIndex>:<hookIndex>`.
252
+ *
253
+ * This is the EXPECTED spelling, used only to cross-check what `hooks/list` reports. The install
254
+ * path uses the reported key verbatim — a computed key that drifts from the runtime's would arm
255
+ * nothing while reading like success.
256
+ */
257
+ export declare function expectedTrustKey(registryPath: string, event: CodexHookEvent, groupIndex: number, hookIndex: number): string;
258
+ /**
259
+ * Split a `hooks/list` trust key into its parts, or `null` when it is not one.
260
+ *
261
+ * MEASURED shape: `<sourcePath>:<snake_event>:<groupIndex>:<hookIndex>`. The path may itself carry
262
+ * a colon, so the split is anchored at the END — the last two fields are the indices and the third
263
+ * from the end is the event.
264
+ *
265
+ * The INDICES are deliberately not predicted: they are positions inside the user's registry, and a
266
+ * foreign entry shifts them. What IS ours to require is the rest — this key names OUR registry and
267
+ * OUR event (fix round 2, R2-7: a row carrying an arbitrary key was selected on path+event+command
268
+ * alone, and the key is what dz then writes trust against).
269
+ */
270
+ export declare function parseTrustKey(key: string): {
271
+ readonly sourcePath: string;
272
+ readonly event: string;
273
+ readonly groupIndex: number;
274
+ readonly hookIndex: number;
275
+ } | null;
276
+ export interface HookTrustRow {
277
+ readonly key: string;
278
+ readonly trustedHash: string;
279
+ }
280
+ export declare const DZ_TRUST_BEGIN = "# --- dz codex hooks trust (managed block, dz-rewritten) ---";
281
+ export declare const DZ_TRUST_END = "# --- end dz codex hooks trust ---";
282
+ /**
283
+ * Render dz's trust rows as a MANAGED BLOCK in `config.toml`.
284
+ *
285
+ * A managed block, not a whole-file rewrite: `~/.codex/config.toml` already carries a
286
+ * `ruvnet-brain` managed block and seven `[projects."…"]` trust rows on this machine (MEASURED),
287
+ * and dz is not the only writer. The block is delimited so a re-run replaces exactly dz's rows and
288
+ * nothing else.
289
+ */
290
+ export declare function renderTrustBlock(rows: readonly HookTrustRow[]): string;
291
+ export type TrustBlockResult = {
292
+ readonly ok: true;
293
+ readonly text: string;
294
+ } | {
295
+ readonly ok: false;
296
+ readonly error: string;
297
+ };
298
+ /**
299
+ * Replace (or append) dz's managed trust block, leaving every other byte of config.toml alone.
300
+ *
301
+ * The fence must be **exactly one well-ordered pair**, or dz refuses (independent review, finding
302
+ * 9). The old `indexOf`-pair logic was satisfiable by a damaged file in three ways, and each one
303
+ * eats the user's TOML on the NEXT sync: a lone BEGIN made the rewrite append a second block, so
304
+ * the following run's `begin…end` window spanned everything between the orphan marker and the new
305
+ * block's END; a reversed pair did the same; duplicate pairs left an orphan block behind. Refusing
306
+ * costs one manual edit — the alternative silently deletes `[projects."…"]` trust rows.
307
+ */
308
+ export declare function upsertTrustBlock(configToml: string, rows: readonly HookTrustRow[]): TrustBlockResult;
309
+ export interface HooksListHookMetadata {
310
+ readonly key: string;
311
+ readonly eventName: string;
312
+ readonly command?: string | null;
313
+ readonly sourcePath: string;
314
+ readonly source: string;
315
+ readonly currentHash: string;
316
+ readonly trustStatus: 'managed' | 'untrusted' | 'trusted' | 'modified';
317
+ readonly enabled: boolean;
318
+ readonly timeoutSec: number;
319
+ }
320
+ export interface SelectOwnHookOptions {
321
+ /** The registry file dz wrote. A row from any other source path is not dz's row. */
322
+ readonly registryPath: string;
323
+ }
324
+ /**
325
+ * Pick, from a `hooks/list` response, the metadata of the entries WE wrote.
326
+ *
327
+ * The match is on THREE facts, not one (independent review, finding 7): the row's `sourcePath` is
328
+ * the registry dz wrote, its `eventName` is the event dz registered the entry under, and the
329
+ * command string is byte-equal. Command alone was not enough — a project-scoped
330
+ * `<repo>/.codex/hooks.json` DOES load on codex 0.148 (MEASURED, see ADR-004's addendum), so a
331
+ * shadow copy of dz's own command line could supply the `trusted` row that armed the user-global
332
+ * entry nobody had approved.
333
+ *
334
+ * AMBIGUITY IS REFUSED, not resolved: two rows claiming the same entry drop BOTH, because the one
335
+ * dz would arm is then a coin flip and the trust write is keyed by the row it picked.
336
+ */
337
+ export declare function selectOwnHookMetadata(hooks: readonly HooksListHookMetadata[], entries: readonly ManagedEntry[], options: SelectOwnHookOptions): {
338
+ readonly id: CodexHookId;
339
+ readonly meta: HooksListHookMetadata;
340
+ }[];
341
+ //# sour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