@fern-api/replay 0.11.0 → 0.12.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.
package/dist/index.d.cts CHANGED
@@ -434,6 +434,72 @@ interface ReplayOptions {
434
434
  /** SHA of the base branch HEAD before replay runs. Stored in lockfile for squash merge recovery. */
435
435
  baseBranchHead?: string;
436
436
  }
437
+ /**
438
+ * Options honored by `applyPreparedReplay()`. `cliVersion`, `generatorVersions`,
439
+ * `baseBranchHead`, `dryRun`, and `skipApplication` were all captured in phase 1
440
+ * and re-supplying them here is meaningless.
441
+ */
442
+ interface ApplyOptions {
443
+ /** Write files and stage changes, but don't commit */
444
+ stageOnly?: boolean;
445
+ }
446
+ /**
447
+ * Opaque handle returned by `prepareReplay()`. Consumed by `applyPreparedReplay()`
448
+ * to complete the run.
449
+ *
450
+ * Contract for consumers (e.g., generator-cli pipeline inserting AutoVersionStep):
451
+ *
452
+ * - Between `prepareReplay` and `applyPreparedReplay`, HEAD is at the new
453
+ * `[fern-generated]` commit (unless `_prepared.terminal === true`, e.g. dry-run).
454
+ * - Consumers MAY land additional commits on HEAD between phases. `applyPatches`
455
+ * runs against current HEAD at phase-2 call time, so mid-phase commits are
456
+ * respected. `rebasePatches` uses `currentGenerationSha` (the pure `[fern-generated]`
457
+ * SHA), NOT HEAD — mid-phase commits do not retarget patches' `base_generation`.
458
+ * - The service instance is single-use across the phase boundary: do not call
459
+ * other service methods (`syncFromDivergentMerge`, another `prepareReplay`, etc.)
460
+ * between phases. In-memory lockfile and warning state would be corrupted.
461
+ * - If the caller's mid-phase work throws or `applyPreparedReplay` is never called,
462
+ * the repo is left with the new `[fern-generated]` commit but a stale lockfile.
463
+ * Consumers MUST either (a) still call `applyPreparedReplay` so the lockfile
464
+ * advances, or (b) reset HEAD to `previousGenerationSha` and surface the failure.
465
+ *
466
+ * To decide whether to run autoversion between phases, use:
467
+ * prep.previousGenerationSha != null && prep.flow !== "skip-application"
468
+ */
469
+ interface ReplayPreparation {
470
+ flow: "first-generation" | "no-patches" | "normal-regeneration" | "skip-application";
471
+ /** lockfile.current_generation from BEFORE this run; null iff no prior generation exists */
472
+ previousGenerationSha: string | null;
473
+ /** SHA of the new [fern-generated] commit created by prepareReplay (or HEAD for dry-run terminals) */
474
+ currentGenerationSha: string;
475
+ /** options.baseBranchHead passed through */
476
+ baseBranchHead: string | null;
477
+ /** @internal Opaque state consumed by applyPreparedReplay */
478
+ readonly _prepared: InternalPreparationState;
479
+ }
480
+ /** @internal */
481
+ interface InternalPreparationState {
482
+ flow: "first-generation" | "no-patches" | "normal-regeneration" | "skip-application";
483
+ /** true → applyPreparedReplay returns preparedReport without disk/git work (dry-run path) */
484
+ terminal: boolean;
485
+ preparedReport?: ReplayReport;
486
+ /** post-preGenRebase, post-detection, post-absorption (references, not copies) */
487
+ patchesToApply: StoredPatch[];
488
+ /** subset of patchesToApply that were freshly detected this cycle (vs already in the lockfile) */
489
+ newPatchIds: Set<string>;
490
+ preRebaseCounts?: {
491
+ conflictResolved: number;
492
+ conflictAbsorbed: number;
493
+ contentRefreshed: number;
494
+ };
495
+ /** detector warnings snapshotted at end of phase 1 */
496
+ detectorWarnings: string[];
497
+ revertedCount: number;
498
+ /** [fern-generated] SHA; passed to rebasePatches as currentGenSha */
499
+ genSha: string;
500
+ /** cached phase-1 options for constructing the final ReplayReport in phase 2 */
501
+ optionsSnapshot?: ReplayOptions;
502
+ }
437
503
  declare class ReplayService {
438
504
  private git;
439
505
  private detector;
@@ -465,6 +531,33 @@ declare class ReplayService {
465
531
  */
466
532
  getLastResults(): ReadonlyArray<ReplayResult>;
467
533
  constructor(outputDir: string, _config: ReplayConfig);
534
+ /**
535
+ * Phase 1 of the two-phase replay flow. Runs preGenerationRebase (when applicable),
536
+ * detects new patches, and creates the `[fern-generated]` commit. Leaves HEAD at
537
+ * the generation commit (or unchanged for dry-run).
538
+ *
539
+ * Does NOT apply patches — the returned handle must be passed to
540
+ * `applyPreparedReplay()` to complete the run. No disk writes to the lockfile
541
+ * happen here; lockfile persistence is deferred to phase 2.
542
+ *
543
+ * Callers may land additional commits on HEAD between `prepareReplay` and
544
+ * `applyPreparedReplay` (e.g., `[fern-autoversion]`).
545
+ */
546
+ prepareReplay(options?: ReplayOptions): Promise<ReplayPreparation>;
547
+ /**
548
+ * Phase 2 of the two-phase replay flow. Applies patches, rebases them against
549
+ * the generation, saves the lockfile, and commits `[fern-replay]` (or stages
550
+ * under `stageOnly`). Operates on HEAD at call time — mid-phase commits are
551
+ * respected.
552
+ *
553
+ * For terminal handles (dry-run, first-gen has no patch work, skip-app does
554
+ * its own post-commit logic), this returns the precomputed report.
555
+ */
556
+ applyPreparedReplay(prep: ReplayPreparation, options?: ApplyOptions): Promise<ReplayReport>;
557
+ /**
558
+ * Backwards-compatible atomic entry point. Composes `prepareReplay` + `applyPreparedReplay`.
559
+ * Behavior is byte-identical to the pre-split implementation for all existing callers.
560
+ */
468
561
  runReplay(options?: ReplayOptions): Promise<ReplayReport>;
469
562
  /**
470
563
  * Sync the lockfile after a divergent PR was squash-merged.
@@ -482,15 +575,22 @@ declare class ReplayService {
482
575
  baseBranchHead?: string;
483
576
  }): Promise<void>;
484
577
  private determineFlow;
485
- private handleFirstGeneration;
578
+ private firstGenerationReport;
579
+ private _prepareFirstGeneration;
580
+ private _applyFirstGeneration;
486
581
  /**
487
- * Skip-application mode: commit the generation and update the lockfile
488
- * but don't detect or apply patches. Sets a marker so the next normal
489
- * run skips revert detection in preGenerationRebase().
582
+ * Skip-application mode phase 1: commit the generation and update the
583
+ * in-memory lockfile, but don't detect or apply patches. Sets a marker
584
+ * so the next normal run skips revert detection in preGenerationRebase().
585
+ *
586
+ * Disk save is deferred to `_applySkipApplication`.
490
587
  */
491
- private handleSkipApplication;
492
- private handleNoPatchesRegeneration;
493
- private handleNormalRegeneration;
588
+ private _prepareSkipApplication;
589
+ private _applySkipApplication;
590
+ private _prepareNoPatchesRegeneration;
591
+ private _applyNoPatchesRegeneration;
592
+ private _prepareNormalRegeneration;
593
+ private _applyNormalRegeneration;
494
594
  /**
495
595
  * Rebase cleanly applied patches so they are relative to the current generation.
496
596
  * This prevents recurring conflicts on subsequent regenerations.
@@ -761,4 +861,4 @@ interface StatusGeneration {
761
861
  }
762
862
  declare function status(outputDir: string): StatusResult;
763
863
 
764
- export { type BootstrapOptions, type BootstrapResult, CREDENTIAL_PATTERNS, type CommitInfo, type CommitOptions, type ConflictDetail, type ConflictMetadata, type ConflictReason, type ConflictRegion, type CredentialPattern, type CustomizationsConfig, type DetectionResult, type DiffStat, FERN_BOT_EMAIL, FERN_BOT_LOGIN, FERN_BOT_NAME, FernignoreMigrator, type FileResult, type ForgetOptions, type ForgetResult, type GenerationLock, type GenerationRecord, GitClient, LockfileManager, LockfileNotFoundError, type MatchedPatch, type MergeResult, type MigrationAnalysis, type MigrationResult, type MoveDeclaration, ReplayApplicator, ReplayCommitter, type ReplayConfig, ReplayDetector, type ReplayOptions, type ReplayReport, type ReplayResult, ReplayService, type ResetOptions, type ResetResult, type ResolveOptions, type ResolveResult, SENSITIVE_FILE_PATTERNS, type StatusGeneration, type StatusPatch, type StatusResult, type StoredPatch, type UnresolvedPatchInfo, bootstrap, forget, isGenerationCommit, isReplayCommit, isRevertCommit, isSensitiveFile, parseRevertedMessage, parseRevertedSha, reset, resolve, scanForCredentials, status, threeWayMerge };
864
+ export { type ApplyOptions, type BootstrapOptions, type BootstrapResult, CREDENTIAL_PATTERNS, type CommitInfo, type CommitOptions, type ConflictDetail, type ConflictMetadata, type ConflictReason, type ConflictRegion, type CredentialPattern, type CustomizationsConfig, type DetectionResult, type DiffStat, FERN_BOT_EMAIL, FERN_BOT_LOGIN, FERN_BOT_NAME, FernignoreMigrator, type FileResult, type ForgetOptions, type ForgetResult, type GenerationLock, type GenerationRecord, GitClient, LockfileManager, LockfileNotFoundError, type MatchedPatch, type MergeResult, type MigrationAnalysis, type MigrationResult, type MoveDeclaration, ReplayApplicator, ReplayCommitter, type ReplayConfig, ReplayDetector, type ReplayOptions, type ReplayPreparation, type ReplayReport, type ReplayResult, ReplayService, type ResetOptions, type ResetResult, type ResolveOptions, type ResolveResult, SENSITIVE_FILE_PATTERNS, type StatusGeneration, type StatusPatch, type StatusResult, type StoredPatch, type UnresolvedPatchInfo, bootstrap, forget, isGenerationCommit, isReplayCommit, isRevertCommit, isSensitiveFile, parseRevertedMessage, parseRevertedSha, reset, resolve, scanForCredentials, status, threeWayMerge };
package/dist/index.d.ts CHANGED
@@ -434,6 +434,72 @@ interface ReplayOptions {
434
434
  /** SHA of the base branch HEAD before replay runs. Stored in lockfile for squash merge recovery. */
435
435
  baseBranchHead?: string;
436
436
  }
437
+ /**
438
+ * Options honored by `applyPreparedReplay()`. `cliVersion`, `generatorVersions`,
439
+ * `baseBranchHead`, `dryRun`, and `skipApplication` were all captured in phase 1
440
+ * and re-supplying them here is meaningless.
441
+ */
442
+ interface ApplyOptions {
443
+ /** Write files and stage changes, but don't commit */
444
+ stageOnly?: boolean;
445
+ }
446
+ /**
447
+ * Opaque handle returned by `prepareReplay()`. Consumed by `applyPreparedReplay()`
448
+ * to complete the run.
449
+ *
450
+ * Contract for consumers (e.g., generator-cli pipeline inserting AutoVersionStep):
451
+ *
452
+ * - Between `prepareReplay` and `applyPreparedReplay`, HEAD is at the new
453
+ * `[fern-generated]` commit (unless `_prepared.terminal === true`, e.g. dry-run).
454
+ * - Consumers MAY land additional commits on HEAD between phases. `applyPatches`
455
+ * runs against current HEAD at phase-2 call time, so mid-phase commits are
456
+ * respected. `rebasePatches` uses `currentGenerationSha` (the pure `[fern-generated]`
457
+ * SHA), NOT HEAD — mid-phase commits do not retarget patches' `base_generation`.
458
+ * - The service instance is single-use across the phase boundary: do not call
459
+ * other service methods (`syncFromDivergentMerge`, another `prepareReplay`, etc.)
460
+ * between phases. In-memory lockfile and warning state would be corrupted.
461
+ * - If the caller's mid-phase work throws or `applyPreparedReplay` is never called,
462
+ * the repo is left with the new `[fern-generated]` commit but a stale lockfile.
463
+ * Consumers MUST either (a) still call `applyPreparedReplay` so the lockfile
464
+ * advances, or (b) reset HEAD to `previousGenerationSha` and surface the failure.
465
+ *
466
+ * To decide whether to run autoversion between phases, use:
467
+ * prep.previousGenerationSha != null && prep.flow !== "skip-application"
468
+ */
469
+ interface ReplayPreparation {
470
+ flow: "first-generation" | "no-patches" | "normal-regeneration" | "skip-application";
471
+ /** lockfile.current_generation from BEFORE this run; null iff no prior generation exists */
472
+ previousGenerationSha: string | null;
473
+ /** SHA of the new [fern-generated] commit created by prepareReplay (or HEAD for dry-run terminals) */
474
+ currentGenerationSha: string;
475
+ /** options.baseBranchHead passed through */
476
+ baseBranchHead: string | null;
477
+ /** @internal Opaque state consumed by applyPreparedReplay */
478
+ readonly _prepared: InternalPreparationState;
479
+ }
480
+ /** @internal */
481
+ interface InternalPreparationState {
482
+ flow: "first-generation" | "no-patches" | "normal-regeneration" | "skip-application";
483
+ /** true → applyPreparedReplay returns preparedReport without disk/git work (dry-run path) */
484
+ terminal: boolean;
485
+ preparedReport?: ReplayReport;
486
+ /** post-preGenRebase, post-detection, post-absorption (references, not copies) */
487
+ patchesToApply: StoredPatch[];
488
+ /** subset of patchesToApply that were freshly detected this cycle (vs already in the lockfile) */
489
+ newPatchIds: Set<string>;
490
+ preRebaseCounts?: {
491
+ conflictResolved: number;
492
+ conflictAbsorbed: number;
493
+ contentRefreshed: number;
494
+ };
495
+ /** detector warnings snapshotted at end of phase 1 */
496
+ detectorWarnings: string[];
497
+ revertedCount: number;
498
+ /** [fern-generated] SHA; passed to rebasePatches as currentGenSha */
499
+ genSha: string;
500
+ /** cached phase-1 options for constructing the final ReplayReport in phase 2 */
501
+ optionsSnapshot?: ReplayOptions;
502
+ }
437
503
  declare class ReplayService {
438
504
  private git;
439
505
  private detector;
@@ -465,6 +531,33 @@ declare class ReplayService {
465
531
  */
466
532
  getLastResults(): ReadonlyArray<ReplayResult>;
467
533
  constructor(outputDir: string, _config: ReplayConfig);
534
+ /**
535
+ * Phase 1 of the two-phase replay flow. Runs preGenerationRebase (when applicable),
536
+ * detects new patches, and creates the `[fern-generated]` commit. Leaves HEAD at
537
+ * the generation commit (or unchanged for dry-run).
538
+ *
539
+ * Does NOT apply patches — the returned handle must be passed to
540
+ * `applyPreparedReplay()` to complete the run. No disk writes to the lockfile
541
+ * happen here; lockfile persistence is deferred to phase 2.
542
+ *
543
+ * Callers may land additional commits on HEAD between `prepareReplay` and
544
+ * `applyPreparedReplay` (e.g., `[fern-autoversion]`).
545
+ */
546
+ prepareReplay(options?: ReplayOptions): Promise<ReplayPreparation>;
547
+ /**
548
+ * Phase 2 of the two-phase replay flow. Applies patches, rebases them against
549
+ * the generation, saves the lockfile, and commits `[fern-replay]` (or stages
550
+ * under `stageOnly`). Operates on HEAD at call time — mid-phase commits are
551
+ * respected.
552
+ *
553
+ * For terminal handles (dry-run, first-gen has no patch work, skip-app does
554
+ * its own post-commit logic), this returns the precomputed report.
555
+ */
556
+ applyPreparedReplay(prep: ReplayPreparation, options?: ApplyOptions): Promise<ReplayReport>;
557
+ /**
558
+ * Backwards-compatible atomic entry point. Composes `prepareReplay` + `applyPreparedReplay`.
559
+ * Behavior is byte-identical to the pre-split implementation for all existing callers.
560
+ */
468
561
  runReplay(options?: ReplayOptions): Promise<ReplayReport>;
469
562
  /**
470
563
  * Sync the lockfile after a divergent PR was squash-merged.
@@ -482,15 +575,22 @@ declare class ReplayService {
482
575
  baseBranchHead?: string;
483
576
  }): Promise<void>;
484
577
  private determineFlow;
485
- private handleFirstGeneration;
578
+ private firstGenerationReport;
579
+ private _prepareFirstGeneration;
580
+ private _applyFirstGeneration;
486
581
  /**
487
- * Skip-application mode: commit the generation and update the lockfile
488
- * but don't detect or apply patches. Sets a marker so the next normal
489
- * run skips revert detection in preGenerationRebase().
582
+ * Skip-application mode phase 1: commit the generation and update the
583
+ * in-memory lockfile, but don't detect or apply patches. Sets a marker
584
+ * so the next normal run skips revert detection in preGenerationRebase().
585
+ *
586
+ * Disk save is deferred to `_applySkipApplication`.
490
587
  */
491
- private handleSkipApplication;
492
- private handleNoPatchesRegeneration;
493
- private handleNormalRegeneration;
588
+ private _prepareSkipApplication;
589
+ private _applySkipApplication;
590
+ private _prepareNoPatchesRegeneration;
591
+ private _applyNoPatchesRegeneration;
592
+ private _prepareNormalRegeneration;
593
+ private _applyNormalRegeneration;
494
594
  /**
495
595
  * Rebase cleanly applied patches so they are relative to the current generation.
496
596
  * This prevents recurring conflicts on subsequent regenerations.
@@ -761,4 +861,4 @@ interface StatusGeneration {
761
861
  }
762
862
  declare function status(outputDir: string): StatusResult;
763
863
 
764
- export { type BootstrapOptions, type BootstrapResult, CREDENTIAL_PATTERNS, type CommitInfo, type CommitOptions, type ConflictDetail, type ConflictMetadata, type ConflictReason, type ConflictRegion, type CredentialPattern, type CustomizationsConfig, type DetectionResult, type DiffStat, FERN_BOT_EMAIL, FERN_BOT_LOGIN, FERN_BOT_NAME, FernignoreMigrator, type FileResult, type ForgetOptions, type ForgetResult, type GenerationLock, type GenerationRecord, GitClient, LockfileManager, LockfileNotFoundError, type MatchedPatch, type MergeResult, type MigrationAnalysis, type MigrationResult, type MoveDeclaration, ReplayApplicator, ReplayCommitter, type ReplayConfig, ReplayDetector, type ReplayOptions, type ReplayReport, type ReplayResult, ReplayService, type ResetOptions, type ResetResult, type ResolveOptions, type ResolveResult, SENSITIVE_FILE_PATTERNS, type StatusGeneration, type StatusPatch, type StatusResult, type StoredPatch, type UnresolvedPatchInfo, bootstrap, forget, isGenerationCommit, isReplayCommit, isRevertCommit, isSensitiveFile, parseRevertedMessage, parseRevertedSha, reset, resolve, scanForCredentials, status, threeWayMerge };
864
+ export { type ApplyOptions, type BootstrapOptions, type BootstrapResult, CREDENTIAL_PATTERNS, type CommitInfo, type CommitOptions, type ConflictDetail, type ConflictMetadata, type ConflictReason, type ConflictRegion, type CredentialPattern, type CustomizationsConfig, type DetectionResult, type DiffStat, FERN_BOT_EMAIL, FERN_BOT_LOGIN, FERN_BOT_NAME, FernignoreMigrator, type FileResult, type ForgetOptions, type ForgetResult, type GenerationLock, type GenerationRecord, GitClient, LockfileManager, LockfileNotFoundError, type MatchedPatch, type MergeResult, type MigrationAnalysis, type MigrationResult, type MoveDeclaration, ReplayApplicator, ReplayCommitter, type ReplayConfig, ReplayDetector, type ReplayOptions, type ReplayPreparation, type ReplayReport, type ReplayResult, ReplayService, type ResetOptions, type ResetResult, type ResolveOptions, type ResolveResult, SENSITIVE_FILE_PATTERNS, type StatusGeneration, type StatusPatch, type StatusResult, type StoredPatch, type UnresolvedPatchInfo, bootstrap, forget, isGenerationCommit, isReplayCommit, isRevertCommit, isSensitiveFile, parseRevertedMessage, parseRevertedSha, reset, resolve, scanForCredentials, status, threeWayMerge };