@leitwerk-dev/coding 0.4.0 → 0.4.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.
- package/README.md +67 -11
- package/dist/{chunk-Q24RPXOA.js → chunk-3WJRJ3Q7.js} +68 -7
- package/dist/chunk-3WJRJ3Q7.js.map +1 -0
- package/dist/chunk-B3PE6DPF.js +820 -0
- package/dist/chunk-B3PE6DPF.js.map +1 -0
- package/dist/chunk-E3DB4TIZ.js +49 -0
- package/dist/chunk-E3DB4TIZ.js.map +1 -0
- package/dist/{chunk-BI45R2FH.js → chunk-QD6FI4HR.js} +1 -1
- package/dist/chunk-QD6FI4HR.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +6 -0
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.js +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/pull-request-publication-internal.d.ts +8 -0
- package/dist/pull-request-publication-internal.d.ts.map +1 -1
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +16 -3
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +283 -69
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-publication-receipt.d.ts +23 -0
- package/dist/repository-publication-receipt.d.ts.map +1 -0
- package/dist/repository-rebase/git.d.ts +8 -0
- package/dist/repository-rebase/git.d.ts.map +1 -1
- package/dist/repository-reconciliation.d.ts +47 -0
- package/dist/repository-reconciliation.d.ts.map +1 -0
- package/dist/repository-record.d.ts +6 -0
- package/dist/repository-record.d.ts.map +1 -0
- package/dist/turns/implement.d.ts +1 -1
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/package.json +5 -5
- package/src/finalization-git-internal.ts +75 -6
- package/src/pull-request-publication-internal.ts +3 -2
- package/src/repository-change-process.ts +19 -2
- package/src/repository-change-publication.ts +243 -57
- package/src/repository-publication-receipt.ts +71 -0
- package/src/repository-rebase/git.ts +108 -29
- package/src/repository-reconciliation.ts +600 -0
- package/src/repository-record.ts +14 -0
- package/src/turns/implement.ts +4 -1
- package/dist/chunk-BI45R2FH.js.map +0 -1
- package/dist/chunk-OM2AMDTJ.js +0 -347
- package/dist/chunk-OM2AMDTJ.js.map +0 -1
- package/dist/chunk-Q24RPXOA.js.map +0 -1
|
@@ -12,10 +12,23 @@ import {
|
|
|
12
12
|
type GitIdentity,
|
|
13
13
|
repositoryHasChanges,
|
|
14
14
|
} from "./finalization-git.js";
|
|
15
|
+
import { RemoteBranchChangedError } from "./finalization-git-internal.js";
|
|
15
16
|
import type { RepositoryChangeState } from "./repository-change-state.js";
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
ConcurrentRebaseSourceError,
|
|
19
|
+
hasPreparedRebase,
|
|
20
|
+
publishRebase,
|
|
21
|
+
startRebase,
|
|
22
|
+
} from "./repository-rebase/git.js";
|
|
17
23
|
import { type ConflictEvidence, conflictKey, validateConflict } from "./repository-rebase/index.js";
|
|
18
24
|
import { rebasePrompt } from "./repository-rebase/prompt.js";
|
|
25
|
+
import {
|
|
26
|
+
reconcilePublicationRepository,
|
|
27
|
+
reconciliationPrompt,
|
|
28
|
+
recordRepositoryPublication,
|
|
29
|
+
repositoryWorktreeIsDirty,
|
|
30
|
+
retainConcurrentRebase,
|
|
31
|
+
} from "./repository-reconciliation.js";
|
|
19
32
|
import { codingPurposes } from "./settings.js";
|
|
20
33
|
|
|
21
34
|
export {
|
|
@@ -78,6 +91,12 @@ export function requirePublicationParams<P>(params: P): P & PublicationParams {
|
|
|
78
91
|
/** @public */
|
|
79
92
|
export type PublicationContext<P> = FlowAutomaticRunContext<P, RepositoryChangeState>;
|
|
80
93
|
|
|
94
|
+
/** Remote reconciliation has no worker checkout or filesystem access. @public */
|
|
95
|
+
export type PublicationReconciliationContext<P> = Pick<
|
|
96
|
+
PublicationContext<P>,
|
|
97
|
+
"process" | "projects" | "params" | "state" | "callIntegrationTool"
|
|
98
|
+
>;
|
|
99
|
+
|
|
81
100
|
/** @public */
|
|
82
101
|
export type PublicationEvidence = (
|
|
83
102
|
| {
|
|
@@ -128,6 +147,7 @@ export type PublicationEvidence = (
|
|
|
128
147
|
) & {
|
|
129
148
|
/** @public */
|
|
130
149
|
observationKey?: string;
|
|
150
|
+
/** Current provider source revision. @internal */ remoteHeadSha?: string;
|
|
131
151
|
/** Coordinated repository key. @public */ projectKey?: string;
|
|
132
152
|
};
|
|
133
153
|
|
|
@@ -197,11 +217,11 @@ export interface RepositoryChangePublicationAdapter<P> {
|
|
|
197
217
|
): Promise<PublicationRequest | null>;
|
|
198
218
|
|
|
199
219
|
/** @public */
|
|
200
|
-
sourceCancelled?(ctx:
|
|
220
|
+
sourceCancelled?(ctx: PublicationReconciliationContext<P>): Promise<boolean>;
|
|
201
221
|
|
|
202
222
|
/** @public */
|
|
203
223
|
reconcileAll?(
|
|
204
|
-
ctx:
|
|
224
|
+
ctx: PublicationReconciliationContext<P>,
|
|
205
225
|
results: readonly {
|
|
206
226
|
/** @internal */
|
|
207
227
|
key: string;
|
|
@@ -252,7 +272,7 @@ export interface RepositoryChangePublicationAdapter<P> {
|
|
|
252
272
|
|
|
253
273
|
/** @public */
|
|
254
274
|
reconcileTerminal(
|
|
255
|
-
ctx:
|
|
275
|
+
ctx: PublicationReconciliationContext<P>,
|
|
256
276
|
current: PublicationState,
|
|
257
277
|
request: PublicationRequest,
|
|
258
278
|
): Promise<void>;
|
|
@@ -312,6 +332,8 @@ type AdjustmentInvocation = {
|
|
|
312
332
|
|
|
313
333
|
/** @public */
|
|
314
334
|
publishRequired: boolean;
|
|
335
|
+
/** Operator-facing no-change diagnosis retained until delivery. @internal */
|
|
336
|
+
summary?: string;
|
|
315
337
|
};
|
|
316
338
|
|
|
317
339
|
/** @public */
|
|
@@ -350,6 +372,15 @@ export interface PublicationState {
|
|
|
350
372
|
/** @public */
|
|
351
373
|
headSha: string | null;
|
|
352
374
|
|
|
375
|
+
/** Baseline retained until the worker reconciles its unpublished delta. @internal */
|
|
376
|
+
workBaselineSha?: string | null;
|
|
377
|
+
/** Historical publication receipt, not an eligibility condition. @internal */
|
|
378
|
+
lastPublishedHeadSha?: string | null;
|
|
379
|
+
/** Combined tree needs validation before publication. @internal */
|
|
380
|
+
reconciliationRequired?: boolean;
|
|
381
|
+
/** Bound automatic reconciliation loops under continuously moving branches. @internal */
|
|
382
|
+
reconciliationCycles?: number;
|
|
383
|
+
|
|
353
384
|
/** @public */
|
|
354
385
|
prNumber: number | null;
|
|
355
386
|
|
|
@@ -478,6 +509,14 @@ export function applyPublicationEvidence(
|
|
|
478
509
|
): PublicationState {
|
|
479
510
|
if (evidence.observationKey !== undefined)
|
|
480
511
|
current = { ...current, observationKey: evidence.observationKey };
|
|
512
|
+
if (evidence.remoteHeadSha && evidence.remoteHeadSha !== current.headSha)
|
|
513
|
+
current = {
|
|
514
|
+
...current,
|
|
515
|
+
workBaselineSha: current.workBaselineSha ?? current.headSha,
|
|
516
|
+
lastPublishedHeadSha: current.lastPublishedHeadSha ?? current.headSha,
|
|
517
|
+
headSha: evidence.remoteHeadSha,
|
|
518
|
+
pipeline: null,
|
|
519
|
+
};
|
|
481
520
|
switch (evidence.kind) {
|
|
482
521
|
case "feedback": {
|
|
483
522
|
const { kind: _, ...batch } = evidence;
|
|
@@ -594,7 +633,11 @@ export function createRepositoryChangePublication<P>(
|
|
|
594
633
|
state: RepositoryChangeState,
|
|
595
634
|
patch: Partial<Omit<PublicationState, "delivery">> & { delivery?: Partial<DeliveryState> },
|
|
596
635
|
) => patchPublicationState(state, namespace(state), patch);
|
|
597
|
-
async function commitWorkBranch(
|
|
636
|
+
async function commitWorkBranch(
|
|
637
|
+
ctx: PublicationContext<P>,
|
|
638
|
+
commitMessage: string,
|
|
639
|
+
expectedRemoteHead = remote(ctx.state).headSha,
|
|
640
|
+
) {
|
|
598
641
|
const repo = ctx.repo.get("repo");
|
|
599
642
|
const gitIdentity = await adapter.identity(ctx);
|
|
600
643
|
if (adapter.maintenance)
|
|
@@ -605,6 +648,17 @@ export function createRepositoryChangePublication<P>(
|
|
|
605
648
|
workBranch: repo.workBranch,
|
|
606
649
|
commitMessage,
|
|
607
650
|
gitIdentity,
|
|
651
|
+
expectedRemoteHead,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
async function reconcile(ctx: PublicationContext<P>, current: PublicationState) {
|
|
655
|
+
const repo = ctx.repo.get("repo");
|
|
656
|
+
return reconcilePublicationRepository({
|
|
657
|
+
projectKey: repo.key,
|
|
658
|
+
repoPath: repo.fsPath,
|
|
659
|
+
workBranch: repo.workBranch,
|
|
660
|
+
baselineSha: current.workBaselineSha ?? current.headSha ?? undefined,
|
|
661
|
+
gitIdentity: await adapter.identity(ctx),
|
|
608
662
|
});
|
|
609
663
|
}
|
|
610
664
|
const runRepository = async (ctx: PublicationContext<P>) => {
|
|
@@ -612,6 +666,26 @@ export function createRepositoryChangePublication<P>(
|
|
|
612
666
|
const update = (patch: Parameters<typeof patchRemote>[1]) => {
|
|
613
667
|
current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
|
|
614
668
|
};
|
|
669
|
+
const acknowledgePublication = (headSha: string, changed: boolean) => {
|
|
670
|
+
update({
|
|
671
|
+
headSha,
|
|
672
|
+
workBaselineSha: headSha,
|
|
673
|
+
lastPublishedHeadSha: changed ? headSha : current.lastPublishedHeadSha,
|
|
674
|
+
reconciliationRequired: false,
|
|
675
|
+
reconciliationCycles: 0,
|
|
676
|
+
pipeline: changed ? null : current.pipeline,
|
|
677
|
+
});
|
|
678
|
+
const repo = ctx.repo.get("repo");
|
|
679
|
+
recordRepositoryPublication(
|
|
680
|
+
{
|
|
681
|
+
projectKey: repo.key,
|
|
682
|
+
repoPath: repo.fsPath,
|
|
683
|
+
workBranch: repo.workBranch,
|
|
684
|
+
baselineSha: headSha,
|
|
685
|
+
},
|
|
686
|
+
headSha,
|
|
687
|
+
);
|
|
688
|
+
};
|
|
615
689
|
const result = (
|
|
616
690
|
outcome:
|
|
617
691
|
| "awaiting"
|
|
@@ -637,6 +711,19 @@ export function createRepositoryChangePublication<P>(
|
|
|
637
711
|
if (evidence.kind === "conflict") return result("conflict_ready");
|
|
638
712
|
}
|
|
639
713
|
ctx.reportProgress(deliveryProgress(current, adapter.label));
|
|
714
|
+
const reconcileAgain = () => {
|
|
715
|
+
const cycles = (current.reconciliationCycles ?? 0) + 1;
|
|
716
|
+
update({
|
|
717
|
+
reconciliationRequired: true,
|
|
718
|
+
reconciliationCycles: cycles,
|
|
719
|
+
repairPending: true,
|
|
720
|
+
conflict: null,
|
|
721
|
+
lastConflictKey: null,
|
|
722
|
+
pipeline: null,
|
|
723
|
+
delivery: { adjustment: null, feedbackResult: null },
|
|
724
|
+
});
|
|
725
|
+
return result(cycles > 3 ? "operator_action" : "conflict_ready");
|
|
726
|
+
};
|
|
640
727
|
|
|
641
728
|
if (current.delivery.terminalPullRequest) {
|
|
642
729
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "reconcile_terminal"));
|
|
@@ -659,15 +746,34 @@ export function createRepositoryChangePublication<P>(
|
|
|
659
746
|
await adapter.unchanged?.(ctx);
|
|
660
747
|
return result("completed");
|
|
661
748
|
}
|
|
749
|
+
let publicationLease = current.headSha;
|
|
750
|
+
if (
|
|
751
|
+
(!current.headSha || current.delivery.adjustment) &&
|
|
752
|
+
current.delivery.adjustment?.origin !== "rebase"
|
|
753
|
+
) {
|
|
754
|
+
const synchronized = await reconcile(ctx, current);
|
|
755
|
+
if (synchronized.changed || synchronized.status === "conflicts") return reconcileAgain();
|
|
756
|
+
// Fetch is authoritative even if the watcher has not observed a developer push yet.
|
|
757
|
+
publicationLease = synchronized.remoteHead;
|
|
758
|
+
if (current.headSha && synchronized.remoteHead && current.headSha !== synchronized.remoteHead)
|
|
759
|
+
update({ headSha: synchronized.remoteHead, workBaselineSha: synchronized.remoteHead });
|
|
760
|
+
}
|
|
662
761
|
if (!current.headSha) {
|
|
663
762
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_branch"));
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
ctx
|
|
668
|
-
""
|
|
669
|
-
|
|
670
|
-
|
|
763
|
+
let published: { headSha: string };
|
|
764
|
+
try {
|
|
765
|
+
published = await commitWorkBranch(
|
|
766
|
+
ctx,
|
|
767
|
+
ctx.state.finalization.commitMessages?.[ctx.repo.get("repo").key] ??
|
|
768
|
+
ctx.state.finalization.generatedCommitMessage ??
|
|
769
|
+
"",
|
|
770
|
+
publicationLease,
|
|
771
|
+
);
|
|
772
|
+
} catch (error) {
|
|
773
|
+
if (!(error instanceof RemoteBranchChangedError)) throw error;
|
|
774
|
+
return reconcileAgain();
|
|
775
|
+
}
|
|
776
|
+
acknowledgePublication(published.headSha, true);
|
|
671
777
|
}
|
|
672
778
|
|
|
673
779
|
if (!current.prNumber || !current.prUrl) {
|
|
@@ -684,22 +790,49 @@ export function createRepositoryChangePublication<P>(
|
|
|
684
790
|
|
|
685
791
|
if (current.delivery.adjustment) {
|
|
686
792
|
const adjustment = current.delivery.adjustment;
|
|
687
|
-
if (adjustment.
|
|
793
|
+
if (adjustment.origin === "rebase" && !hasPreparedRebase(rebaseInput(ctx)))
|
|
794
|
+
return reconcileAgain();
|
|
795
|
+
let adjustmentPublished = false;
|
|
796
|
+
if (adjustment.publishRequired || adjustment.origin === "rebase" || adapter.maintenance) {
|
|
688
797
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_adjustment"));
|
|
689
798
|
if (adapter.maintenance)
|
|
690
799
|
await ctx.callIntegrationTool(adapter.maintenance.ownershipTool, {
|
|
691
800
|
projectKey: ctx.repo.get("repo").key,
|
|
692
801
|
});
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
802
|
+
let published: { headSha: string };
|
|
803
|
+
try {
|
|
804
|
+
published =
|
|
805
|
+
adjustment.origin === "rebase"
|
|
806
|
+
? publishRebase(rebaseInput(ctx))
|
|
807
|
+
: await commitWorkBranch(
|
|
808
|
+
{ ...ctx, state: patchRemote(ctx.state, current) },
|
|
809
|
+
adapter.commitMessage(adjustment.origin),
|
|
810
|
+
);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
if (error instanceof ConcurrentRebaseSourceError) {
|
|
813
|
+
if (error.published) return reconcileAgain();
|
|
814
|
+
const project = ctx.repo.get("repo");
|
|
815
|
+
retainConcurrentRebase({
|
|
816
|
+
projectKey: project.key,
|
|
817
|
+
repoPath: project.fsPath,
|
|
818
|
+
workBranch: project.workBranch,
|
|
819
|
+
baselineSha: error.repair.originalHead,
|
|
820
|
+
rebasedHead: error.repair.headSha,
|
|
821
|
+
targetBase: error.repair.baseSha,
|
|
822
|
+
gitIdentity: await adapter.identity(ctx),
|
|
823
|
+
});
|
|
824
|
+
return reconcileAgain();
|
|
825
|
+
}
|
|
826
|
+
if (!(error instanceof RemoteBranchChangedError)) throw error;
|
|
827
|
+
return reconcileAgain();
|
|
828
|
+
}
|
|
697
829
|
if (adjustment.origin === "rebase") {
|
|
698
830
|
const head = await adapter.head(ctx, current);
|
|
699
831
|
if (head !== published.headSha)
|
|
700
832
|
throw new Error("Pull request head has not caught up with rebase publication");
|
|
701
833
|
}
|
|
702
|
-
|
|
834
|
+
adjustmentPublished = published.headSha !== publicationLease;
|
|
835
|
+
acknowledgePublication(published.headSha, adjustmentPublished);
|
|
703
836
|
}
|
|
704
837
|
if (adjustment.origin === "rebase") await adapter.afterRebase(ctx, current);
|
|
705
838
|
if (adjustment.origin === "feedback" && !adapter.maintenance) {
|
|
@@ -714,8 +847,10 @@ export function createRepositoryChangePublication<P>(
|
|
|
714
847
|
...(adjustment.origin === "feedback" && adapter.maintenance
|
|
715
848
|
? {
|
|
716
849
|
feedbackResult: {
|
|
717
|
-
published:
|
|
718
|
-
summary:
|
|
850
|
+
published: adjustmentPublished,
|
|
851
|
+
summary: adjustmentPublished
|
|
852
|
+
? "Review adjustment published"
|
|
853
|
+
: (adjustment.summary ?? "No repository change was required"),
|
|
719
854
|
},
|
|
720
855
|
}
|
|
721
856
|
: {}),
|
|
@@ -747,12 +882,7 @@ export function createRepositoryChangePublication<P>(
|
|
|
747
882
|
!current.stopped &&
|
|
748
883
|
!current.noChanges &&
|
|
749
884
|
!current.delivery.terminalPullRequest &&
|
|
750
|
-
(current.delivery.stage !== "awaiting" ||
|
|
751
|
-
!!(
|
|
752
|
-
current.delivery.adjustment &&
|
|
753
|
-
(current.delivery.adjustment.publishRequired ||
|
|
754
|
-
current.delivery.adjustment.origin === "rebase")
|
|
755
|
-
))
|
|
885
|
+
(current.delivery.stage !== "awaiting" || !!current.delivery.adjustment)
|
|
756
886
|
);
|
|
757
887
|
return (
|
|
758
888
|
current.delivery.stage !== "awaiting" ||
|
|
@@ -835,13 +965,11 @@ export function createRepositoryChangePublication<P>(
|
|
|
835
965
|
delivery.outcome("feedback_ready", (o) =>
|
|
836
966
|
outcome(o, "Pull request feedback is acknowledged and ready for revision").to(ids.feedback),
|
|
837
967
|
);
|
|
838
|
-
for (const [name, target] of
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
["operator_action", ids.operator],
|
|
844
|
-
] as const)) {
|
|
968
|
+
for (const [name, target] of [
|
|
969
|
+
["ci_ready", ids.ciRepair],
|
|
970
|
+
["conflict_ready", ids.feedback],
|
|
971
|
+
["operator_action", ids.operator],
|
|
972
|
+
] as const) {
|
|
845
973
|
delivery.outcome(name, (o) => outcome(o, "Route observed delivery evidence").to(target));
|
|
846
974
|
}
|
|
847
975
|
for (const source of adapter.sources) {
|
|
@@ -929,11 +1057,22 @@ export function createRepositoryChangePublication<P>(
|
|
|
929
1057
|
}
|
|
930
1058
|
|
|
931
1059
|
function revisionPrompt(kind: "feedback" | "ci") {
|
|
932
|
-
return (ctx: {
|
|
1060
|
+
return (ctx: {
|
|
1061
|
+
state: RepositoryChangeState;
|
|
1062
|
+
prepared?: unknown;
|
|
1063
|
+
prompts?: { initial: string };
|
|
1064
|
+
}) => {
|
|
933
1065
|
const current = remote(ctx.state);
|
|
1066
|
+
const repository = adapter.repositories
|
|
1067
|
+
? `Repository: ${activeKey(ctx.state)}. Apply changes only to this checkout. `
|
|
1068
|
+
: "";
|
|
1069
|
+
if (asUnknownRecord(ctx.prepared)?.deferredRebase)
|
|
1070
|
+
return `${repository}${reconciliationPrompt}\nThe source branch or retained local work must be reconciled before the target-branch repair. Resolve any source reconciliation, then use changes_ready. Delivery will restore and validate the result before reassessing current target conflicts.`;
|
|
1071
|
+
if (current.reconciliationRequired)
|
|
1072
|
+
return `${repository}${reconciliationPrompt}\nValidate the reconciled repository, including retained local work, against the requested change and pending feedback: ${JSON.stringify(current.feedbackIds)}. Treat the current remote as authoritative; do not restore deliberately removed code simply to match an older plan. Use changes_ready after validation, even when no further edit is needed, so retained local changes are published. If blocked use cannot_repair.\nOriginal request for context: ${ctx.prompts?.initial ?? "Inspect the current repository and retained request"}`;
|
|
934
1073
|
if (repairReason(ctx.state, kind) === "rebase")
|
|
935
1074
|
return `${rebasePrompt} Evidence: ${JSON.stringify(current.conflict)}. Call changes_ready or no_changes when verified complete, cannot_repair when blocked.`;
|
|
936
|
-
return `${adapter.repositories ? `Repository: ${activeKey(ctx.state)}. Apply changes only to this checkout. ` : ""}${adapter.prompt(kind, current)}`;
|
|
1075
|
+
return `${adapter.repositories ? `Repository: ${activeKey(ctx.state)}. Apply changes only to this checkout. ` : ""}${adapter.prompt(kind, current)}\n\n${reconciliationPrompt}`;
|
|
937
1076
|
};
|
|
938
1077
|
}
|
|
939
1078
|
|
|
@@ -947,23 +1086,67 @@ export function createRepositoryChangePublication<P>(
|
|
|
947
1086
|
!current.stopped &&
|
|
948
1087
|
!current.delivery.terminalPullRequest &&
|
|
949
1088
|
(kind === "feedback"
|
|
950
|
-
? current.feedbackIds.length > 0 ||
|
|
1089
|
+
? current.feedbackIds.length > 0 ||
|
|
1090
|
+
!!current.conflict ||
|
|
1091
|
+
!!current.reconciliationRequired
|
|
951
1092
|
: current.repairReason === "ci" && current.pipeline !== null)
|
|
952
1093
|
);
|
|
953
1094
|
})
|
|
954
1095
|
.executionPurpose(codingPurposes.implementation)
|
|
955
1096
|
.tools("read", "bash", "edit", "write")
|
|
956
1097
|
.resolveIntegrationTools((_params, state) =>
|
|
957
|
-
repairReason(state, kind) === "rebase"
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
repairReason(ctx.state, kind) === "rebase" ? startRebase(rebaseInput(ctx)) : {},
|
|
1098
|
+
repairReason(state, kind) === "rebase" && !remote(state).reconciliationRequired
|
|
1099
|
+
? []
|
|
1100
|
+
: adapter.tools[kind],
|
|
961
1101
|
)
|
|
1102
|
+
.prepare(async (ctx) => {
|
|
1103
|
+
const project = ctx.repo.get(activeKey(ctx.state) ?? "repo");
|
|
1104
|
+
const current = remote(ctx.state);
|
|
1105
|
+
const targetRebase =
|
|
1106
|
+
repairReason(ctx.state, kind) === "rebase" && !current.reconciliationRequired;
|
|
1107
|
+
// Resume Git's existing target repair; it must not be mistaken for source synchronization.
|
|
1108
|
+
if (targetRebase && hasPreparedRebase(rebaseInput(ctx)))
|
|
1109
|
+
return { rebase: startRebase(rebaseInput(ctx)) };
|
|
1110
|
+
ctx.reportProgress({
|
|
1111
|
+
title: "Repository reconciliation",
|
|
1112
|
+
steps: [
|
|
1113
|
+
{
|
|
1114
|
+
id: "reconcile_source",
|
|
1115
|
+
label: "Reconcile remote source and retained local work",
|
|
1116
|
+
status: "in_progress",
|
|
1117
|
+
},
|
|
1118
|
+
],
|
|
1119
|
+
});
|
|
1120
|
+
const reconciliation = await reconcile(repositoryContext(ctx), current);
|
|
1121
|
+
ctx.reportProgress({
|
|
1122
|
+
title: "Repository reconciliation",
|
|
1123
|
+
steps: [
|
|
1124
|
+
{
|
|
1125
|
+
id: "reconcile_source",
|
|
1126
|
+
label:
|
|
1127
|
+
reconciliation.status === "conflicts"
|
|
1128
|
+
? "Resolve source reconciliation conflicts"
|
|
1129
|
+
: "Remote source reconciled",
|
|
1130
|
+
status: reconciliation.status === "conflicts" ? "in_progress" : "completed",
|
|
1131
|
+
},
|
|
1132
|
+
],
|
|
1133
|
+
});
|
|
1134
|
+
if (targetRebase) {
|
|
1135
|
+
if (
|
|
1136
|
+
reconciliation.changed ||
|
|
1137
|
+
reconciliation.headSha !== current.conflict?.headSha ||
|
|
1138
|
+
repositoryWorktreeIsDirty({ projectKey: project.key, repoPath: project.fsPath })
|
|
1139
|
+
)
|
|
1140
|
+
return { reconciliation, deferredRebase: true };
|
|
1141
|
+
return { rebase: startRebase(rebaseInput(ctx)) };
|
|
1142
|
+
}
|
|
1143
|
+
return { reconciliation };
|
|
1144
|
+
})
|
|
962
1145
|
.freshPrimary()
|
|
963
1146
|
.prompt(revisionPrompt(kind));
|
|
964
|
-
for (const [name, description
|
|
965
|
-
["changes_ready", "Repository changes are ready to publish"
|
|
966
|
-
["no_changes", "No repository change is required"
|
|
1147
|
+
for (const [name, description] of [
|
|
1148
|
+
["changes_ready", "Repository changes are ready to publish"],
|
|
1149
|
+
["no_changes", "No repository change is required"],
|
|
967
1150
|
] as const) {
|
|
968
1151
|
turn.outcomeTool(name, (tool) =>
|
|
969
1152
|
tool
|
|
@@ -974,19 +1157,18 @@ export function createRepositoryChangePublication<P>(
|
|
|
974
1157
|
patchRemote(ctx.state, {
|
|
975
1158
|
repairPending: false,
|
|
976
1159
|
delivery: {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
: {}),
|
|
1160
|
+
// Even no_changes must cross delivery's remote race check. It may
|
|
1161
|
+
// have inherited unpublished work or a concurrent developer push.
|
|
1162
|
+
adjustment: {
|
|
1163
|
+
origin: remote(ctx.state).reconciliationRequired
|
|
1164
|
+
? "feedback"
|
|
1165
|
+
: repairReason(ctx.state, kind),
|
|
1166
|
+
publishRequired:
|
|
1167
|
+
name === "changes_ready" || !!remote(ctx.state).reconciliationRequired,
|
|
1168
|
+
summary: String(
|
|
1169
|
+
event.params?.resultSummary ?? "No repository change was required",
|
|
1170
|
+
),
|
|
1171
|
+
},
|
|
990
1172
|
},
|
|
991
1173
|
}),
|
|
992
1174
|
),
|
|
@@ -1032,9 +1214,13 @@ export function createRepositoryChangePublication<P>(
|
|
|
1032
1214
|
label: "Retry repair",
|
|
1033
1215
|
acceptanceState: "accepted",
|
|
1034
1216
|
branches: { feedback: { to: ids.feedback }, ci: { to: ids.ciRepair } },
|
|
1217
|
+
effect: adapter.maintenance
|
|
1218
|
+
? ({ ctx }) => ({ state: patchRemote(ctx.state, { reconciliationCycles: 0 }) })
|
|
1219
|
+
: undefined,
|
|
1035
1220
|
choose: ({ ctx }) =>
|
|
1036
1221
|
remote(ctx.state).repairReason === "rebase" ||
|
|
1037
|
-
remote(ctx.state).repairReason === "feedback"
|
|
1222
|
+
remote(ctx.state).repairReason === "feedback" ||
|
|
1223
|
+
remote(ctx.state).reconciliationRequired
|
|
1038
1224
|
? "feedback"
|
|
1039
1225
|
: "ci",
|
|
1040
1226
|
},
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { repositoryRecord } from "./repository-record.js";
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
export interface RepositoryBinding {
|
|
7
|
+
branch: string;
|
|
8
|
+
origin: string;
|
|
9
|
+
pushOrigin: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export function readRepositoryBinding(
|
|
14
|
+
git: (...args: string[]) => string,
|
|
15
|
+
branch: string,
|
|
16
|
+
): RepositoryBinding {
|
|
17
|
+
return {
|
|
18
|
+
branch,
|
|
19
|
+
origin: git("remote", "get-url", "origin"),
|
|
20
|
+
pushOrigin: git("remote", "get-url", "--push", "--all", "origin"),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export function repositoryBindingMatches(
|
|
26
|
+
record: RepositoryBinding | null,
|
|
27
|
+
binding: RepositoryBinding,
|
|
28
|
+
): boolean {
|
|
29
|
+
return (
|
|
30
|
+
!record ||
|
|
31
|
+
(record.branch === binding.branch &&
|
|
32
|
+
record.origin === binding.origin &&
|
|
33
|
+
record.pushOrigin === binding.pushOrigin)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A local write-ahead receipt, not a replacement for the server-owned process state. @internal */
|
|
38
|
+
export interface RepositoryPublicationReceipt extends RepositoryBinding {
|
|
39
|
+
expectedHead: string | null;
|
|
40
|
+
candidate: string;
|
|
41
|
+
status: "attempting" | "accepted" | "rejected";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export function readPublicationReceipt(gitDirectory: string): RepositoryPublicationReceipt | null {
|
|
46
|
+
const file = join(gitDirectory, "leitwerk-publication.json");
|
|
47
|
+
if (!existsSync(file)) return null;
|
|
48
|
+
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
49
|
+
if (
|
|
50
|
+
!value ||
|
|
51
|
+
typeof value.branch !== "string" ||
|
|
52
|
+
typeof value.origin !== "string" ||
|
|
53
|
+
typeof value.pushOrigin !== "string" ||
|
|
54
|
+
!["attempting", "accepted", "rejected"].includes(value.status) ||
|
|
55
|
+
!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value.candidate) ||
|
|
56
|
+
!(value.expectedHead === null || /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value.expectedHead))
|
|
57
|
+
)
|
|
58
|
+
throw new Error("Invalid repository publication receipt; local work was retained");
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Persist intent before sending and acceptance before checking for subsequent remote movement. @internal */
|
|
63
|
+
export const savePublicationReceipt = (
|
|
64
|
+
gitDirectory: string,
|
|
65
|
+
receipt: RepositoryPublicationReceipt,
|
|
66
|
+
) => repositoryRecord(gitDirectory, "publication").save(receipt);
|
|
67
|
+
|
|
68
|
+
/** Porcelain rejection is proof of no write; transport failures are not. @internal */
|
|
69
|
+
export function pushWasRejected(porcelain: string): boolean {
|
|
70
|
+
return porcelain.split("\n").some((line) => /^!\t[^\t]+\t\[(?:remote )?rejected\]/.test(line));
|
|
71
|
+
}
|