@skillcap/gdh 0.23.0 → 0.25.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 (165) hide show
  1. package/INSTALL-BUNDLE.json +1 -1
  2. package/RELEASE-SPAN-UPDATE-CONTRACTS.json +122 -0
  3. package/node_modules/@gdh/adapters/dist/authoring-hook-render.d.ts.map +1 -1
  4. package/node_modules/@gdh/adapters/dist/authoring-hook-render.js +9 -131
  5. package/node_modules/@gdh/adapters/dist/authoring-hook-render.js.map +1 -1
  6. package/node_modules/@gdh/adapters/dist/claude-statusline-render.d.ts.map +1 -1
  7. package/node_modules/@gdh/adapters/dist/claude-statusline-render.js +6 -28
  8. package/node_modules/@gdh/adapters/dist/claude-statusline-render.js.map +1 -1
  9. package/node_modules/@gdh/adapters/dist/claude-update-hook-render.d.ts.map +1 -1
  10. package/node_modules/@gdh/adapters/dist/claude-update-hook-render.js +7 -40
  11. package/node_modules/@gdh/adapters/dist/claude-update-hook-render.js.map +1 -1
  12. package/node_modules/@gdh/adapters/dist/claude-update-worker-render.d.ts.map +1 -1
  13. package/node_modules/@gdh/adapters/dist/claude-update-worker-render.js +7 -68
  14. package/node_modules/@gdh/adapters/dist/claude-update-worker-render.js.map +1 -1
  15. package/node_modules/@gdh/adapters/dist/deferred-actions-advisory.d.ts +71 -0
  16. package/node_modules/@gdh/adapters/dist/deferred-actions-advisory.d.ts.map +1 -0
  17. package/node_modules/@gdh/adapters/dist/deferred-actions-advisory.js +89 -0
  18. package/node_modules/@gdh/adapters/dist/deferred-actions-advisory.js.map +1 -0
  19. package/node_modules/@gdh/adapters/dist/durable-backup.d.ts +209 -0
  20. package/node_modules/@gdh/adapters/dist/durable-backup.d.ts.map +1 -0
  21. package/node_modules/@gdh/adapters/dist/durable-backup.js +346 -0
  22. package/node_modules/@gdh/adapters/dist/durable-backup.js.map +1 -0
  23. package/node_modules/@gdh/adapters/dist/index.d.ts +11 -3
  24. package/node_modules/@gdh/adapters/dist/index.d.ts.map +1 -1
  25. package/node_modules/@gdh/adapters/dist/index.js +79 -43
  26. package/node_modules/@gdh/adapters/dist/index.js.map +1 -1
  27. package/node_modules/@gdh/adapters/dist/inventory-sweep.d.ts +53 -0
  28. package/node_modules/@gdh/adapters/dist/inventory-sweep.d.ts.map +1 -0
  29. package/node_modules/@gdh/adapters/dist/inventory-sweep.js +98 -0
  30. package/node_modules/@gdh/adapters/dist/inventory-sweep.js.map +1 -0
  31. package/node_modules/@gdh/adapters/dist/process-orchestration.d.ts +223 -0
  32. package/node_modules/@gdh/adapters/dist/process-orchestration.d.ts.map +1 -0
  33. package/node_modules/@gdh/adapters/dist/process-orchestration.js +368 -0
  34. package/node_modules/@gdh/adapters/dist/process-orchestration.js.map +1 -0
  35. package/node_modules/@gdh/adapters/dist/self-update-mechanics.d.ts +157 -14
  36. package/node_modules/@gdh/adapters/dist/self-update-mechanics.d.ts.map +1 -1
  37. package/node_modules/@gdh/adapters/dist/self-update-mechanics.js +570 -89
  38. package/node_modules/@gdh/adapters/dist/self-update-mechanics.js.map +1 -1
  39. package/node_modules/@gdh/adapters/dist/skill-rendering.d.ts +2 -5
  40. package/node_modules/@gdh/adapters/dist/skill-rendering.d.ts.map +1 -1
  41. package/node_modules/@gdh/adapters/dist/skill-rendering.js +39 -56
  42. package/node_modules/@gdh/adapters/dist/skill-rendering.js.map +1 -1
  43. package/node_modules/@gdh/adapters/dist/template-assets.d.ts +2 -0
  44. package/node_modules/@gdh/adapters/dist/template-assets.d.ts.map +1 -0
  45. package/node_modules/@gdh/adapters/dist/template-assets.js +26 -0
  46. package/node_modules/@gdh/adapters/dist/template-assets.js.map +1 -0
  47. package/node_modules/@gdh/adapters/dist/templates/authoring-hook.js.tpl +128 -0
  48. package/node_modules/@gdh/adapters/dist/templates/claude-check-update-hook.js.tpl +37 -0
  49. package/node_modules/@gdh/adapters/dist/templates/claude-check-update-worker.js.tpl +65 -0
  50. package/node_modules/@gdh/adapters/dist/templates/claude-statusline.js.tpl +25 -0
  51. package/node_modules/@gdh/adapters/package.json +8 -8
  52. package/node_modules/@gdh/authoring/package.json +2 -2
  53. package/node_modules/@gdh/cli/dist/index.d.ts +9 -0
  54. package/node_modules/@gdh/cli/dist/index.d.ts.map +1 -1
  55. package/node_modules/@gdh/cli/dist/index.js +249 -6
  56. package/node_modules/@gdh/cli/dist/index.js.map +1 -1
  57. package/node_modules/@gdh/cli/dist/migrate.d.ts +152 -1
  58. package/node_modules/@gdh/cli/dist/migrate.d.ts.map +1 -1
  59. package/node_modules/@gdh/cli/dist/migrate.js +355 -8
  60. package/node_modules/@gdh/cli/dist/migrate.js.map +1 -1
  61. package/node_modules/@gdh/cli/dist/self-update.d.ts +14 -0
  62. package/node_modules/@gdh/cli/dist/self-update.d.ts.map +1 -1
  63. package/node_modules/@gdh/cli/dist/self-update.js +197 -15
  64. package/node_modules/@gdh/cli/dist/self-update.js.map +1 -1
  65. package/node_modules/@gdh/cli/dist/setup.d.ts +4 -0
  66. package/node_modules/@gdh/cli/dist/setup.d.ts.map +1 -1
  67. package/node_modules/@gdh/cli/dist/setup.js +8 -67
  68. package/node_modules/@gdh/cli/dist/setup.js.map +1 -1
  69. package/node_modules/@gdh/cli/package.json +10 -10
  70. package/node_modules/@gdh/core/dist/index.d.ts +99 -5
  71. package/node_modules/@gdh/core/dist/index.d.ts.map +1 -1
  72. package/node_modules/@gdh/core/dist/index.js +24 -5
  73. package/node_modules/@gdh/core/dist/index.js.map +1 -1
  74. package/node_modules/@gdh/core/dist/migrations/entries/s2c2_to_s2c3_rules_schema_v2_to_v3.d.ts +3 -0
  75. package/node_modules/@gdh/core/dist/migrations/entries/s2c2_to_s2c3_rules_schema_v2_to_v3.d.ts.map +1 -0
  76. package/node_modules/@gdh/core/dist/migrations/entries/s2c2_to_s2c3_rules_schema_v2_to_v3.js +247 -0
  77. package/node_modules/@gdh/core/dist/migrations/entries/s2c2_to_s2c3_rules_schema_v2_to_v3.js.map +1 -0
  78. package/node_modules/@gdh/core/dist/migrations/entries/s3c8_to_s3c9_register_runtime_bridge_autoload.d.ts +3 -0
  79. package/node_modules/@gdh/core/dist/migrations/entries/s3c8_to_s3c9_register_runtime_bridge_autoload.d.ts.map +1 -0
  80. package/node_modules/@gdh/core/dist/migrations/entries/s3c8_to_s3c9_register_runtime_bridge_autoload.js +152 -0
  81. package/node_modules/@gdh/core/dist/migrations/entries/s3c8_to_s3c9_register_runtime_bridge_autoload.js.map +1 -0
  82. package/node_modules/@gdh/core/dist/migrations/envelopes/envelope-output-validator.d.ts +3 -0
  83. package/node_modules/@gdh/core/dist/migrations/envelopes/envelope-output-validator.d.ts.map +1 -0
  84. package/node_modules/@gdh/core/dist/migrations/envelopes/envelope-output-validator.js +67 -0
  85. package/node_modules/@gdh/core/dist/migrations/envelopes/envelope-output-validator.js.map +1 -0
  86. package/node_modules/@gdh/core/dist/migrations/envelopes/index.d.ts +37 -0
  87. package/node_modules/@gdh/core/dist/migrations/envelopes/index.d.ts.map +1 -0
  88. package/node_modules/@gdh/core/dist/migrations/envelopes/index.js +60 -0
  89. package/node_modules/@gdh/core/dist/migrations/envelopes/index.js.map +1 -0
  90. package/node_modules/@gdh/core/dist/migrations/envelopes/types.d.ts +121 -0
  91. package/node_modules/@gdh/core/dist/migrations/envelopes/types.d.ts.map +1 -0
  92. package/node_modules/@gdh/core/dist/migrations/envelopes/types.js +2 -0
  93. package/node_modules/@gdh/core/dist/migrations/envelopes/types.js.map +1 -0
  94. package/node_modules/@gdh/core/dist/migrations/golden-harness.d.ts +40 -0
  95. package/node_modules/@gdh/core/dist/migrations/golden-harness.d.ts.map +1 -0
  96. package/node_modules/@gdh/core/dist/migrations/golden-harness.js +71 -0
  97. package/node_modules/@gdh/core/dist/migrations/golden-harness.js.map +1 -0
  98. package/node_modules/@gdh/core/dist/migrations/managed-surface-classes.d.ts +322 -0
  99. package/node_modules/@gdh/core/dist/migrations/managed-surface-classes.d.ts.map +1 -0
  100. package/node_modules/@gdh/core/dist/migrations/managed-surface-classes.js +384 -0
  101. package/node_modules/@gdh/core/dist/migrations/managed-surface-classes.js.map +1 -0
  102. package/node_modules/@gdh/core/dist/migrations/managed-target-surface-inventory.d.ts +294 -0
  103. package/node_modules/@gdh/core/dist/migrations/managed-target-surface-inventory.d.ts.map +1 -0
  104. package/node_modules/@gdh/core/dist/migrations/managed-target-surface-inventory.js +365 -0
  105. package/node_modules/@gdh/core/dist/migrations/managed-target-surface-inventory.js.map +1 -0
  106. package/node_modules/@gdh/core/dist/migrations/probes.d.ts +58 -0
  107. package/node_modules/@gdh/core/dist/migrations/probes.d.ts.map +1 -0
  108. package/node_modules/@gdh/core/dist/migrations/probes.js +112 -0
  109. package/node_modules/@gdh/core/dist/migrations/probes.js.map +1 -0
  110. package/node_modules/@gdh/core/dist/migrations/registry.d.ts +205 -0
  111. package/node_modules/@gdh/core/dist/migrations/registry.d.ts.map +1 -0
  112. package/node_modules/@gdh/core/dist/migrations/registry.js +214 -0
  113. package/node_modules/@gdh/core/dist/migrations/registry.js.map +1 -0
  114. package/node_modules/@gdh/core/dist/state/atomic-write.d.ts +19 -0
  115. package/node_modules/@gdh/core/dist/state/atomic-write.d.ts.map +1 -0
  116. package/node_modules/@gdh/core/dist/state/atomic-write.js +34 -0
  117. package/node_modules/@gdh/core/dist/state/atomic-write.js.map +1 -0
  118. package/node_modules/@gdh/core/dist/state/migration-state.d.ts +135 -0
  119. package/node_modules/@gdh/core/dist/state/migration-state.d.ts.map +1 -0
  120. package/node_modules/@gdh/core/dist/state/migration-state.js +186 -0
  121. package/node_modules/@gdh/core/dist/state/migration-state.js.map +1 -0
  122. package/node_modules/@gdh/core/dist/state/processes-snapshot.d.ts +72 -0
  123. package/node_modules/@gdh/core/dist/state/processes-snapshot.d.ts.map +1 -0
  124. package/node_modules/@gdh/core/dist/state/processes-snapshot.js +113 -0
  125. package/node_modules/@gdh/core/dist/state/processes-snapshot.js.map +1 -0
  126. package/node_modules/@gdh/core/dist/state/render-inventory.d.ts +54 -0
  127. package/node_modules/@gdh/core/dist/state/render-inventory.d.ts.map +1 -0
  128. package/node_modules/@gdh/core/dist/state/render-inventory.js +77 -0
  129. package/node_modules/@gdh/core/dist/state/render-inventory.js.map +1 -0
  130. package/node_modules/@gdh/core/package.json +1 -1
  131. package/node_modules/@gdh/docs/dist/agent-contract.d.ts +2 -1
  132. package/node_modules/@gdh/docs/dist/agent-contract.d.ts.map +1 -1
  133. package/node_modules/@gdh/docs/dist/agent-contract.js +5 -3
  134. package/node_modules/@gdh/docs/dist/agent-contract.js.map +1 -1
  135. package/node_modules/@gdh/docs/dist/guidance.d.ts +2 -0
  136. package/node_modules/@gdh/docs/dist/guidance.d.ts.map +1 -1
  137. package/node_modules/@gdh/docs/dist/guidance.js +29 -255
  138. package/node_modules/@gdh/docs/dist/guidance.js.map +1 -1
  139. package/node_modules/@gdh/docs/dist/index.d.ts +1 -1
  140. package/node_modules/@gdh/docs/dist/index.d.ts.map +1 -1
  141. package/node_modules/@gdh/docs/dist/index.js +1 -1
  142. package/node_modules/@gdh/docs/dist/index.js.map +1 -1
  143. package/node_modules/@gdh/docs/dist/query.d.ts.map +1 -1
  144. package/node_modules/@gdh/docs/dist/query.js +4 -5
  145. package/node_modules/@gdh/docs/dist/query.js.map +1 -1
  146. package/node_modules/@gdh/docs/dist/recovery-hints.js +1 -1
  147. package/node_modules/@gdh/docs/dist/recovery-hints.js.map +1 -1
  148. package/node_modules/@gdh/docs/dist/template-assets.d.ts +2 -0
  149. package/node_modules/@gdh/docs/dist/template-assets.d.ts.map +1 -0
  150. package/node_modules/@gdh/docs/dist/template-assets.js +26 -0
  151. package/node_modules/@gdh/docs/dist/template-assets.js.map +1 -0
  152. package/node_modules/@gdh/docs/dist/templates/guidance/authoring-and-validation.md.tpl +111 -0
  153. package/node_modules/@gdh/docs/dist/templates/guidance/gdh-glossary.md.tpl +34 -0
  154. package/node_modules/@gdh/docs/dist/templates/guidance/persistence-semantics.md.tpl +24 -0
  155. package/node_modules/@gdh/docs/dist/templates/guidance/project-migration.md.tpl +19 -0
  156. package/node_modules/@gdh/docs/dist/templates/guidance/project-surfaces.md.tpl +14 -0
  157. package/node_modules/@gdh/docs/package.json +2 -2
  158. package/node_modules/@gdh/mcp/package.json +8 -8
  159. package/node_modules/@gdh/observability/package.json +2 -2
  160. package/node_modules/@gdh/runtime/dist/bridge-surface.js +63 -2
  161. package/node_modules/@gdh/runtime/dist/bridge-surface.js.map +1 -1
  162. package/node_modules/@gdh/runtime/package.json +2 -2
  163. package/node_modules/@gdh/scan/package.json +3 -3
  164. package/node_modules/@gdh/verify/package.json +7 -7
  165. package/package.json +11 -11
@@ -1,4 +1,4 @@
1
- import type { GdhLifecycleTerminalResult, GdhManagedProjectSurfaceId, GdhProjectLifecycleCompatibilityResult } from "@gdh/core";
1
+ import type { GdhLifecycleTerminalResult, GdhManagedProjectSurfaceId, GdhProjectLifecycleCompatibilityResult, GdhHostHarnessIntrospect, GdhProcessRestartProbe, GdhMigrationEnvelopeOutput } from "@gdh/core";
2
2
  export declare const GDH_PROJECT_SURFACE_MIGRATION_ID = "project_surface_lifecycle_v1";
3
3
  type MigrationActionKind = "rewrite_file" | "rename_directory" | "delete_file" | "validate_surface" | "run_command" | "manual_review";
4
4
  type MigrationActionState = "planned" | "applied" | "unchanged" | "blocked";
@@ -62,5 +62,156 @@ export declare function deriveLifecycleTerminalResult(input: {
62
62
  readonly state: MigrationRunState;
63
63
  }): GdhLifecycleTerminalResult;
64
64
  export declare function rewriteProjectConfig(content: string): string;
65
+ /**
66
+ * Discriminated result of {@link clearMigrationBackups} (D-17 / STA-04).
67
+ *
68
+ * - `cleared`: every probe was clean, the staging dir was absent, and
69
+ * `.gdh-state/backup/` was removed from disk. Idempotent retry returns `noop`.
70
+ * - `noop`: nothing to do — either no migration state and no backup
71
+ * (`no_migration_state`), or a migration state exists but no backup is
72
+ * present (`no_backup_present`). Both safe to ignore.
73
+ * - `blocked_by_pending_probes`: cleanup refused. Either at least one probed
74
+ * deferred action returned `pending` or `stale` (`deferred_actions_pending`,
75
+ * `pending` carries the action ids), or `.gdh-state/backup.new/` exists
76
+ * indicating an interrupted migration (`migration_in_progress`, `pending`
77
+ * is empty).
78
+ */
79
+ export type GdhClearBackupsResult = {
80
+ readonly state: "cleared";
81
+ readonly cleared_backup_path: string;
82
+ } | {
83
+ readonly state: "noop";
84
+ readonly reason: "no_backup_present" | "no_migration_state";
85
+ } | {
86
+ readonly state: "blocked_by_pending_probes";
87
+ readonly pending: readonly string[];
88
+ readonly reason: "deferred_actions_pending" | "migration_in_progress";
89
+ };
90
+ export interface GdhClearMigrationBackupsInput {
91
+ readonly targetPath: string;
92
+ readonly adapters?: {
93
+ readonly hostHarnessIntrospect?: GdhHostHarnessIntrospect;
94
+ readonly processProbe?: GdhProcessRestartProbe;
95
+ };
96
+ }
97
+ /**
98
+ * Idempotent backup-cleanup command (D-17 / STA-04).
99
+ *
100
+ * Three-gate truth table:
101
+ * 1. Refuse if `.gdh-state/backup.new/` exists (interrupted migration:
102
+ * `migration_in_progress`).
103
+ * 2. Noop if neither backup nor migration state exist (`no_migration_state`),
104
+ * or if no backup but migration state exists (`no_backup_present`).
105
+ * 3. For each deferred action, run the probe; if any probe is not `clean`,
106
+ * refuse with `deferred_actions_pending` and the pending action ids.
107
+ * 4. Otherwise remove `.gdh-state/backup/` recursively and return `cleared`.
108
+ *
109
+ * The migration.json file is NOT modified. Deferred actions are independent of
110
+ * the backup directory; they may have been satisfied previously.
111
+ *
112
+ * Threat mitigations:
113
+ * - T-72-05-03 (TOCTOU): re-reads migration.json AND backup state freshly per
114
+ * call; no cached probe results consumed across calls. Same handler used by
115
+ * the advisory gate in `buildGdhStatusResult` (Plan 05 Task 03).
116
+ * - T-72-05-05 (silent deletion under pending probes): probe-gate is mandatory
117
+ * and `state: "blocked_by_pending_probes"` is exit code 1 with structured
118
+ * `pending` ids; idempotent retry is safe.
119
+ * - T-72-05-07 (clear during interrupted migration): staging-dir check at
120
+ * step 1 returns `migration_in_progress` and refuses cleanup.
121
+ *
122
+ * Defaults: `adapters.hostHarnessIntrospect = null` and `adapters.processProbe
123
+ * = null` so probes degrade to `pending` when the host cannot evaluate the
124
+ * deferred conditions; cleanup then refuses safely instead of spuriously
125
+ * clearing.
126
+ */
127
+ export declare function clearMigrationBackups(input: GdhClearMigrationBackupsInput): Promise<GdhClearBackupsResult>;
128
+ /**
129
+ * Discriminated result of {@link recordEnvelopeResult}.
130
+ *
131
+ * - `recorded`: payload validated, marker triple matched, slot written
132
+ * atomically. `pending_envelope_resume` is preserved by D-13 — the calling
133
+ * agent re-runs `gdh self-update` to advance the chain past the envelope.
134
+ * - `blocked`: validation gate failed. Each `reason` corresponds to a typed
135
+ * failure mode the dispatcher surfaces with exit code 1 (Pitfall 4 — never
136
+ * let JSON.parse / readFile / schema-mismatch escape as raw exceptions).
137
+ *
138
+ * The seven blocked reasons enumerated cover every gate executed by
139
+ * `recordEnvelopeResult`. `input_required` is reserved for the dispatcher's
140
+ * usage-error surface (mutually-exclusive --result / --result-file gate).
141
+ */
142
+ export type GdhRecordEnvelopeResultResult = {
143
+ readonly state: "recorded";
144
+ readonly envelope_ref: string;
145
+ readonly recorded_at: string;
146
+ readonly from_pin: string;
147
+ readonly to_pin: string;
148
+ readonly output_contract_state: GdhMigrationEnvelopeOutput["state"];
149
+ } | {
150
+ readonly state: "blocked";
151
+ readonly reason: "envelope_not_found" | "no_pending_chain" | "envelope_ref_mismatch" | "parse_failed" | "schema_violation" | "result_file_unreadable" | "input_required";
152
+ readonly details: string;
153
+ };
154
+ export interface GdhRecordEnvelopeResultInput {
155
+ readonly targetPath: string;
156
+ readonly envelopeRef: string;
157
+ readonly resultSource: {
158
+ readonly kind: "inline";
159
+ readonly json: string;
160
+ } | {
161
+ readonly kind: "file";
162
+ readonly absolutePath: string;
163
+ };
164
+ /** Deterministic clock injection for tests. */
165
+ readonly nowIso?: () => string;
166
+ }
167
+ /**
168
+ * Record an envelope output_contract block to `.gdh-state/migration.json` per
169
+ * D-07 / D-08 / D-13.
170
+ *
171
+ * Gate sequence (fail-closed, no exception propagates to caller):
172
+ * 1. Slug shape (path-traversal defense via {@link isEnvelopeSlug}).
173
+ * 2. Read --result-file (or use --result inline).
174
+ * 3. JSON.parse (Pitfall 4 — caught and surfaced as `parse_failed`).
175
+ * 4. Schema validation against {@link isEnvelopeOutput} typed union.
176
+ * 5. Read migration.json; require `pending_envelope_resume` marker
177
+ * (D-09 / D-11 / D-13 — chain must be paused before record).
178
+ * 6. Triple match: marker.envelope_ref === input.envelopeRef.
179
+ * 7. Append prior slot to `attempts[]` (Pitfall 2 — outer fields become a
180
+ * new attempt; existing attempts[] history accumulates).
181
+ * 8. Atomic write through {@link writeMigrationState}; D-13 preserves
182
+ * `pending_envelope_resume` (record does NOT clear it).
183
+ *
184
+ * The function NEVER calls `bumpAndRebakePin` and NEVER advances the chain
185
+ * (D-13 lock). The agent re-runs `gdh self-update` to resume.
186
+ */
187
+ export declare function recordEnvelopeResult(input: GdhRecordEnvelopeResultInput): Promise<GdhRecordEnvelopeResultResult>;
188
+ /**
189
+ * Discriminated result of {@link clearEnvelope}.
190
+ *
191
+ * - `cleared`: the per-slug slot was removed from `migration.json.envelopes`.
192
+ * `pending_envelope_resume` is NOT touched (mirrors D-13 isolation).
193
+ * - `noop` with `slot_not_present`: state exists but no slot for this slug.
194
+ * - `noop` with `no_migration_state`: no migration.json on disk.
195
+ *
196
+ * Idempotent — re-running on a missing slot returns `noop`, not `blocked`.
197
+ */
198
+ export type GdhClearEnvelopeResult = {
199
+ readonly state: "cleared";
200
+ readonly envelope_ref: string;
201
+ } | {
202
+ readonly state: "noop";
203
+ readonly reason: "slot_not_present" | "no_migration_state";
204
+ };
205
+ export interface GdhClearEnvelopeInput {
206
+ readonly targetPath: string;
207
+ readonly envelopeRef: string;
208
+ }
209
+ /**
210
+ * Remove the per-slug slot from `migration.json.envelopes`. Testing/debug
211
+ * companion to {@link recordEnvelopeResult}; does NOT touch
212
+ * `pending_envelope_resume` (deliberate isolation — clearing the slot does
213
+ * not unpause a chain).
214
+ */
215
+ export declare function clearEnvelope(input: GdhClearEnvelopeInput): Promise<GdhClearEnvelopeResult>;
65
216
  export {};
66
217
  //# sourceMappingURL=migrate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAG1B,sCAAsC,EAEvC,MAAM,WAAW,CAAC;AAOnB,eAAO,MAAM,gCAAgC,iCAAiC,CAAC;AAE/E,KAAK,mBAAmB,GACpB,cAAc,GACd,kBAAkB,GAClB,aAAa,GACb,kBAAkB,GAClB,aAAa,GACb,eAAe,CAAC;AACpB,KAAK,oBAAoB,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;AAC5E,KAAK,iBAAiB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,kBAAkB,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IAC5D,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED,MAAM,MAAM,gBAAgB,GAAG,S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AAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;CAC5D,CAAC;AAEN,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,sBAAsB,CAAC,CAejC"}
@@ -2,8 +2,9 @@ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import * as gdhCore from "@gdh/core";
4
4
  import { readProjectConfig, resolveProjectRoot } from "@gdh/authoring";
5
- import { inspectProjectLifecycleCompatibility, installSupportedAgentAdapters, } from "@gdh/adapters";
5
+ import { BACKUP_RELATIVE_PATH, BACKUP_STAGING_RELATIVE_PATH, inspectProjectLifecycleCompatibility, installSupportedAgentAdapters, readBackupManifest, } from "@gdh/adapters";
6
6
  import { planAgentContractWrite, planGuidanceArtifactWrites, planRulesArtifactWrite } from "@gdh/docs";
7
+ import { isEnvelopeOutput, isEnvelopeSlug, readMigrationState, runDeferredActionProbe, writeMigrationState, } from "@gdh/core";
7
8
  import { inspectRuntimeBridgeSurface, repairRuntimeBridgeSurface, } from "@gdh/runtime";
8
9
  import { applyRepairableOnboardingWrites } from "@gdh/scan";
9
10
  export const GDH_PROJECT_SURFACE_MIGRATION_ID = "project_surface_lifecycle_v1";
@@ -117,11 +118,19 @@ export async function migrateProjectLifecycleSurface(input) {
117
118
  if (launcherAction !== null) {
118
119
  actions.push(launcherAction);
119
120
  }
120
- const runtimeTerminology = await migrateRuntimeTerminologySurface({
121
- targetPath,
122
- dryRun: input.dryRun,
123
- });
124
- actions.push(...translateRuntimeTerminologyActions(runtimeTerminology.actions));
121
+ // Phase 72 Plan 02: the schema/contract orchestration that
122
+ // migrateRuntimeTerminologySurface drove (recipes→run-configurations
123
+ // rename, scenarios→verification-scenarios rename, project.yaml
124
+ // schema-2→schema-3 rewrite, legacy project_entries.gd copy) is dead
125
+ // code in the v0.18+ supported range. Per the audit at
126
+ // .planning/phases/72-migration-workflow-internals-registry-inventory-durable-back/72-02-AUDIT.md,
127
+ // the only real class-2/3 migration in the supported range is the
128
+ // s2c2→s2c3 rules-schema bump, now owned by the registry entry
129
+ // entry_s2c2_to_s2c3_rules_schema in @gdh/core. Plan 03's inventory
130
+ // sweep deletes the unreachable sub-functions and their pre-v0.18
131
+ // regression tests atomically. WFL-03 (D-20/D-21) makes pre-v0.18
132
+ // pins unreachable for self-update consumers; the schema/contract
133
+ // rewrite paths are no longer driven by any post-v0.18 invocation.
125
134
  let projectConfig = await readProjectConfig(targetPath);
126
135
  if (projectConfig !== null) {
127
136
  const repairableWrites = await planRepairableProjectSurfaceWrites(targetPath, projectConfig, compatibility);
@@ -131,6 +140,11 @@ export async function migrateProjectLifecycleSurface(input) {
131
140
  allowDurableTruthOverwrites: true,
132
141
  });
133
142
  }
143
+ actions.push(...(await migrateLegacyDocsAgentGuidance({
144
+ targetPath,
145
+ projectConfig,
146
+ dryRun: input.dryRun,
147
+ })));
134
148
  if (shouldRepairAdapterSurfaces()) {
135
149
  const adaptersResult = await installSupportedAgentAdapters(targetPath, {
136
150
  dryRun: input.dryRun,
@@ -240,6 +254,64 @@ function shouldRepairAdapterSurfaces() {
240
254
  // surfaces gracefully and ensures new skills are installed on upgrade.
241
255
  return true;
242
256
  }
257
+ const LEGACY_GUIDANCE_RELATIVE_PATHS = [
258
+ "docs/agent/README.md",
259
+ "docs/agent/00-gdh-onboarding.md",
260
+ "docs/agent/gdh-glossary.md",
261
+ "docs/agent/authoring-and-validation.md",
262
+ "docs/agent/project-migration.md",
263
+ "docs/agent/project-surfaces.md",
264
+ "docs/agent/persistence-semantics.md",
265
+ ];
266
+ async function migrateLegacyDocsAgentGuidance(input) {
267
+ const legacyGuidanceRoot = input.projectConfig.primaryGodotProjectPath === "."
268
+ ? input.targetPath
269
+ : path.resolve(input.targetPath, input.projectConfig.primaryGodotProjectPath);
270
+ const actions = [];
271
+ for (const legacyRelativePath of LEGACY_GUIDANCE_RELATIVE_PATHS) {
272
+ const absolutePath = path.join(legacyGuidanceRoot, legacyRelativePath);
273
+ const content = await fs.readFile(absolutePath, "utf8").catch(() => null);
274
+ if (content === null || !isGdhManagedLegacyGuidance(legacyRelativePath, content)) {
275
+ continue;
276
+ }
277
+ if (!input.dryRun) {
278
+ await fs.rm(absolutePath, { force: true });
279
+ }
280
+ const workspaceRelativePath = path.relative(input.targetPath, absolutePath).split(path.sep).join("/");
281
+ actions.push({
282
+ id: `delete-legacy-guidance-${workspaceRelativePath}`,
283
+ surface: legacyRelativePath === "docs/agent/README.md" ? "guidance_index" : "guidance_unit",
284
+ kind: "delete_file",
285
+ state: input.dryRun ? "planned" : "applied",
286
+ relativePath: workspaceRelativePath,
287
+ summary: "Remove legacy GDH-managed docs/agent guidance after writing the canonical .gdh/guidance surface.",
288
+ command: null,
289
+ validationCommands: [],
290
+ manualSteps: [],
291
+ });
292
+ }
293
+ if (!input.dryRun && actions.length > 0) {
294
+ await removeEmptyLegacyGuidanceDirectories(legacyGuidanceRoot);
295
+ }
296
+ return actions;
297
+ }
298
+ function isGdhManagedLegacyGuidance(relativePath, content) {
299
+ if (relativePath === "docs/agent/README.md") {
300
+ return content.includes("<!-- GDH GUIDANCE INDEX VERSION:");
301
+ }
302
+ return (content.includes("id: ") &&
303
+ /^version:\s+\d+$/m.test(content) &&
304
+ content.includes("when:"));
305
+ }
306
+ async function removeEmptyLegacyGuidanceDirectories(legacyGuidanceRoot) {
307
+ for (const relativePath of ["docs/agent", "docs"]) {
308
+ const absolutePath = path.join(legacyGuidanceRoot, relativePath);
309
+ const entries = await fs.readdir(absolutePath).catch(() => null);
310
+ if (entries !== null && entries.length === 0) {
311
+ await fs.rmdir(absolutePath).catch(() => { });
312
+ }
313
+ }
314
+ }
243
315
  function createBrokerTransitionMigrationSummary() {
244
316
  return {
245
317
  state: "supported",
@@ -512,10 +584,10 @@ function mapWriteSurface(relativePath) {
512
584
  if (relativePath === ".gdh/rules.yaml") {
513
585
  return "rules_schema";
514
586
  }
515
- if (relativePath === "docs/agent/README.md") {
587
+ if (relativePath === ".gdh/guidance/README.md") {
516
588
  return "guidance_index";
517
589
  }
518
- if (relativePath.startsWith("docs/agent/")) {
590
+ if (relativePath.startsWith(".gdh/guidance/")) {
519
591
  return "guidance_unit";
520
592
  }
521
593
  if (relativePath === ".cursor/rules/gdh-agent.mdc") {
@@ -594,6 +666,28 @@ async function migrateLegacyLauncher(input) {
594
666
  manualSteps: [],
595
667
  };
596
668
  }
669
+ // TODO(72-Plan-03): unreachable from migrateProjectLifecycleSurface as of
670
+ // Phase 72 Plan 02. Preconditions (.gdh/recipes/, .gdh/scenarios/, legacy
671
+ // project_entries.gd) never match the v0.18+ supported range. Plan 03's
672
+ // inventory sweep deletes this function and its descendants
673
+ // (migrateLegacyProjectBridgeEntry,
674
+ // rewriteRunConfiguration, rewriteVerificationScenario, rewriteVersionHeader,
675
+ // extractPrimaryGodotProjectPath, ensureProjectAllowedProviders,
676
+ // isDockerWideningEligibleRunConfiguration, ensureYamlStringListValues,
677
+ // ensureRuntimeBridgeProjectEntryPath, ensureRuntimeKnowledgePath) plus the
678
+ // pre-v0.18 regression test groups in migrate.test.ts atomically. See
679
+ // .planning/phases/72-migration-workflow-internals-registry-inventory-durable-back/72-02-AUDIT.md
680
+ // "Disposition Table" for the full deletion set.
681
+ //
682
+ // WR-09: `rewriteProjectConfig` is RETAINED — do NOT delete in the Plan-03
683
+ // sweep even though it appears in the descendant chain above. It has a live
684
+ // caller at `preHealMissingGdhVersionField` (this file) AND is exported and
685
+ // imported directly by `migrate.test.ts`. The audit's deletion set was
686
+ // computed from the dead-code reachability graph rooted in
687
+ // `migrateRuntimeTerminologySurface`; the live preheal caller arrived later
688
+ // (D-06 minimal pre-heal) and was not re-checked. See the "RETAINED" guard
689
+ // comment immediately above `export function rewriteProjectConfig` for the
690
+ // in-place marker.
597
691
  async function migrateRuntimeTerminologySurface(input) {
598
692
  const targetPath = path.resolve(input.targetPath);
599
693
  const configPath = path.join(targetPath, PROJECT_CONFIG_PATH);
@@ -908,6 +1002,18 @@ async function applyMinimalDryRunPreHeal(targetPath) {
908
1002
  await fs.writeFile(configPath, originalContent, "utf8");
909
1003
  };
910
1004
  }
1005
+ // WR-09: RETAINED — do NOT delete in the Plan-03 dead-code sweep. Despite
1006
+ // appearing in the TODO(72-Plan-03) deletion set at line ~923 (which
1007
+ // references the dead-code chain rooted in migrateRuntimeTerminologySurface),
1008
+ // this function has TWO live consumers in the v0.18+ supported range:
1009
+ // 1. `preHealMissingGdhVersionField` at line ~1266 (D-06 auto-heal of
1010
+ // missing `gdh_version:` field on unmigrated projects).
1011
+ // 2. Direct import in `packages/cli/src/migrate.test.ts` for the
1012
+ // pre-v0.18 regression test groups (those groups themselves remain
1013
+ // live regression coverage for the auto-heal branch).
1014
+ // The Plan-03 sweep MUST distinguish this function from the genuinely dead
1015
+ // helpers in the same chain. See the WR-09 note above the
1016
+ // migrateRuntimeTerminologySurface TODO block.
911
1017
  export function rewriteProjectConfig(content) {
912
1018
  let next = rewriteVersionHeader(content, 3);
913
1019
  next = next.replace(/^default_recipe:/m, "default_run_configuration:");
@@ -1098,4 +1204,245 @@ async function directoryExists(directoryPath) {
1098
1204
  return false;
1099
1205
  }
1100
1206
  }
1207
+ /**
1208
+ * Idempotent backup-cleanup command (D-17 / STA-04).
1209
+ *
1210
+ * Three-gate truth table:
1211
+ * 1. Refuse if `.gdh-state/backup.new/` exists (interrupted migration:
1212
+ * `migration_in_progress`).
1213
+ * 2. Noop if neither backup nor migration state exist (`no_migration_state`),
1214
+ * or if no backup but migration state exists (`no_backup_present`).
1215
+ * 3. For each deferred action, run the probe; if any probe is not `clean`,
1216
+ * refuse with `deferred_actions_pending` and the pending action ids.
1217
+ * 4. Otherwise remove `.gdh-state/backup/` recursively and return `cleared`.
1218
+ *
1219
+ * The migration.json file is NOT modified. Deferred actions are independent of
1220
+ * the backup directory; they may have been satisfied previously.
1221
+ *
1222
+ * Threat mitigations:
1223
+ * - T-72-05-03 (TOCTOU): re-reads migration.json AND backup state freshly per
1224
+ * call; no cached probe results consumed across calls. Same handler used by
1225
+ * the advisory gate in `buildGdhStatusResult` (Plan 05 Task 03).
1226
+ * - T-72-05-05 (silent deletion under pending probes): probe-gate is mandatory
1227
+ * and `state: "blocked_by_pending_probes"` is exit code 1 with structured
1228
+ * `pending` ids; idempotent retry is safe.
1229
+ * - T-72-05-07 (clear during interrupted migration): staging-dir check at
1230
+ * step 1 returns `migration_in_progress` and refuses cleanup.
1231
+ *
1232
+ * Defaults: `adapters.hostHarnessIntrospect = null` and `adapters.processProbe
1233
+ * = null` so probes degrade to `pending` when the host cannot evaluate the
1234
+ * deferred conditions; cleanup then refuses safely instead of spuriously
1235
+ * clearing.
1236
+ */
1237
+ export async function clearMigrationBackups(input) {
1238
+ const backupAbs = path.join(input.targetPath, BACKUP_RELATIVE_PATH);
1239
+ const stagingAbs = path.join(input.targetPath, BACKUP_STAGING_RELATIVE_PATH);
1240
+ // Gate 1: refuse during in-progress migration (D-17, T-72-05-07)
1241
+ const stagingExists = await fs
1242
+ .stat(stagingAbs)
1243
+ .then(() => true)
1244
+ .catch(() => false);
1245
+ if (stagingExists) {
1246
+ return {
1247
+ state: "blocked_by_pending_probes",
1248
+ pending: [],
1249
+ reason: "migration_in_progress",
1250
+ };
1251
+ }
1252
+ const manifest = await readBackupManifest(input.targetPath);
1253
+ const backupExists = manifest !== null;
1254
+ const migrationState = await readMigrationState(input.targetPath);
1255
+ // Gate 2: noop discriminator
1256
+ if (!backupExists && migrationState === null) {
1257
+ return { state: "noop", reason: "no_migration_state" };
1258
+ }
1259
+ if (!backupExists) {
1260
+ return { state: "noop", reason: "no_backup_present" };
1261
+ }
1262
+ // Gate 3: probe-gate (T-72-05-05)
1263
+ const pending = [];
1264
+ for (const action of migrationState?.deferred_actions ?? []) {
1265
+ const result = await runDeferredActionProbe(action, {
1266
+ targetPath: input.targetPath,
1267
+ hostHarnessIntrospect: input.adapters?.hostHarnessIntrospect ?? null,
1268
+ processProbe: input.adapters?.processProbe ?? null,
1269
+ });
1270
+ if (result.status !== "clean") {
1271
+ pending.push(action.id);
1272
+ }
1273
+ }
1274
+ if (pending.length > 0) {
1275
+ return {
1276
+ state: "blocked_by_pending_probes",
1277
+ pending,
1278
+ reason: "deferred_actions_pending",
1279
+ };
1280
+ }
1281
+ // Gate 4: clear (does NOT modify migration.json)
1282
+ await fs.rm(backupAbs, { recursive: true, force: true });
1283
+ return { state: "cleared", cleared_backup_path: backupAbs };
1284
+ }
1285
+ /**
1286
+ * Record an envelope output_contract block to `.gdh-state/migration.json` per
1287
+ * D-07 / D-08 / D-13.
1288
+ *
1289
+ * Gate sequence (fail-closed, no exception propagates to caller):
1290
+ * 1. Slug shape (path-traversal defense via {@link isEnvelopeSlug}).
1291
+ * 2. Read --result-file (or use --result inline).
1292
+ * 3. JSON.parse (Pitfall 4 — caught and surfaced as `parse_failed`).
1293
+ * 4. Schema validation against {@link isEnvelopeOutput} typed union.
1294
+ * 5. Read migration.json; require `pending_envelope_resume` marker
1295
+ * (D-09 / D-11 / D-13 — chain must be paused before record).
1296
+ * 6. Triple match: marker.envelope_ref === input.envelopeRef.
1297
+ * 7. Append prior slot to `attempts[]` (Pitfall 2 — outer fields become a
1298
+ * new attempt; existing attempts[] history accumulates).
1299
+ * 8. Atomic write through {@link writeMigrationState}; D-13 preserves
1300
+ * `pending_envelope_resume` (record does NOT clear it).
1301
+ *
1302
+ * The function NEVER calls `bumpAndRebakePin` and NEVER advances the chain
1303
+ * (D-13 lock). The agent re-runs `gdh self-update` to resume.
1304
+ */
1305
+ export async function recordEnvelopeResult(input) {
1306
+ // Gate 1: slug shape (path-traversal defense). isEnvelopeSlug rejects
1307
+ // non-string, uppercase, dashes, and traversal segments.
1308
+ if (!isEnvelopeSlug(input.envelopeRef)) {
1309
+ return {
1310
+ state: "blocked",
1311
+ reason: "envelope_not_found",
1312
+ details: `invalid slug shape: ${input.envelopeRef}`,
1313
+ };
1314
+ }
1315
+ // Gate 2: read --result-file or use --result inline.
1316
+ let rawJson;
1317
+ if (input.resultSource.kind === "file") {
1318
+ const read = await fs
1319
+ .readFile(input.resultSource.absolutePath, "utf8")
1320
+ .catch(() => null);
1321
+ if (read === null) {
1322
+ return {
1323
+ state: "blocked",
1324
+ reason: "result_file_unreadable",
1325
+ details: input.resultSource.absolutePath,
1326
+ };
1327
+ }
1328
+ rawJson = read;
1329
+ }
1330
+ else {
1331
+ rawJson = input.resultSource.json;
1332
+ }
1333
+ // Gate 3: JSON parse (Pitfall 4 — never let JSON.parse throw out of the CLI).
1334
+ let parsed;
1335
+ try {
1336
+ parsed = JSON.parse(rawJson);
1337
+ }
1338
+ catch (error) {
1339
+ return {
1340
+ state: "blocked",
1341
+ reason: "parse_failed",
1342
+ details: error instanceof Error ? error.message : String(error),
1343
+ };
1344
+ }
1345
+ // Gate 4: schema validation against typed union.
1346
+ if (!isEnvelopeOutput(parsed)) {
1347
+ const preview = JSON.stringify(parsed).slice(0, 120);
1348
+ return {
1349
+ state: "blocked",
1350
+ reason: "schema_violation",
1351
+ details: `expected GdhMigrationEnvelopeOutput, got ${preview}`,
1352
+ };
1353
+ }
1354
+ // Gate 5: read migration.json; require pending_envelope_resume marker.
1355
+ const state = await readMigrationState(input.targetPath);
1356
+ const marker = state?.pending_envelope_resume ?? null;
1357
+ if (marker === null) {
1358
+ return {
1359
+ state: "blocked",
1360
+ reason: "no_pending_chain",
1361
+ details: "no pending_envelope_resume marker in migration.json",
1362
+ };
1363
+ }
1364
+ if (marker.envelope_ref !== input.envelopeRef) {
1365
+ return {
1366
+ state: "blocked",
1367
+ // WR-02: this is a slug/marker mismatch, NOT a pin pair mismatch. The
1368
+ // pin-staleness check (D-10) lives in applyMigrationChain via
1369
+ // isEnvelopeRecordValid. Use a discriminant that names what actually
1370
+ // failed so dispatcher messages and dogfooding log scrapers don't
1371
+ // mislead operators.
1372
+ reason: "envelope_ref_mismatch",
1373
+ details: `pending_envelope_resume.envelope_ref is "${marker.envelope_ref}", not "${input.envelopeRef}"`,
1374
+ };
1375
+ }
1376
+ // Gate 6: append prior slot to attempts[] (Pitfall 2). The prior slot's OWN
1377
+ // outer fields become a new attempt; we ALSO carry forward the prior slot's
1378
+ // existing attempts[] so history accumulates across re-records.
1379
+ const priorSlot = state?.envelopes?.[input.envelopeRef] ?? null;
1380
+ const nowIso = (input.nowIso ?? (() => new Date().toISOString()))();
1381
+ const newAttempts = priorSlot
1382
+ ? [
1383
+ ...priorSlot.attempts,
1384
+ {
1385
+ recorded_at: priorSlot.recorded_at,
1386
+ from_pin: priorSlot.from_pin,
1387
+ to_pin: priorSlot.to_pin,
1388
+ output_contract: priorSlot.output_contract,
1389
+ },
1390
+ ]
1391
+ : [];
1392
+ const newSlot = {
1393
+ recorded_at: nowIso,
1394
+ from_pin: marker.from_pin,
1395
+ to_pin: marker.to_pin,
1396
+ output_contract: parsed,
1397
+ attempts: newAttempts,
1398
+ };
1399
+ // Gate 7: atomic write through writeMigrationState (Pitfall 6).
1400
+ // D-13: do NOT clear pending_envelope_resume here. The next bumpAndRebakePin
1401
+ // run reads the recorded slot, advances the chain, and clears the marker
1402
+ // on success.
1403
+ //
1404
+ // WR-05: `state` is guaranteed non-null past Gate 5 (line 1869-1875 returns
1405
+ // `blocked: no_pending_chain` when `state?.pending_envelope_resume` is null,
1406
+ // which transitively requires `state` to be non-null). The previous fallback
1407
+ // (`state ?? {... last_applied_at: { schema: 0, agentContract: 0 } ...}`)
1408
+ // was unreachable AND would have written invalid (0, 0) bumps to disk if a
1409
+ // refactor ever weakened Gate 5. We assert non-null here so a future weaken
1410
+ // of Gate 5 fails type-check rather than corrupting last_applied_at.
1411
+ const baseState = state;
1412
+ await writeMigrationState(input.targetPath, {
1413
+ ...baseState,
1414
+ envelopes: { ...(baseState.envelopes ?? {}), [input.envelopeRef]: newSlot },
1415
+ pending_envelope_resume: marker, // preserve — D-13
1416
+ });
1417
+ return {
1418
+ state: "recorded",
1419
+ envelope_ref: input.envelopeRef,
1420
+ recorded_at: nowIso,
1421
+ from_pin: marker.from_pin,
1422
+ to_pin: marker.to_pin,
1423
+ output_contract_state: parsed.state,
1424
+ };
1425
+ }
1426
+ /**
1427
+ * Remove the per-slug slot from `migration.json.envelopes`. Testing/debug
1428
+ * companion to {@link recordEnvelopeResult}; does NOT touch
1429
+ * `pending_envelope_resume` (deliberate isolation — clearing the slot does
1430
+ * not unpause a chain).
1431
+ */
1432
+ export async function clearEnvelope(input) {
1433
+ const state = await readMigrationState(input.targetPath);
1434
+ if (state === null) {
1435
+ return { state: "noop", reason: "no_migration_state" };
1436
+ }
1437
+ if (!state.envelopes || !(input.envelopeRef in state.envelopes)) {
1438
+ return { state: "noop", reason: "slot_not_present" };
1439
+ }
1440
+ const { [input.envelopeRef]: _drop, ...rest } = state.envelopes;
1441
+ void _drop;
1442
+ await writeMigrationState(input.targetPath, {
1443
+ ...state,
1444
+ envelopes: rest,
1445
+ });
1446
+ return { state: "cleared", envelope_ref: input.envelopeRef };
1447
+ }
1101
1448
  //# sourceMappingURL=migrate.js.map