@leitwerk-dev/coding 0.2.0 → 0.2.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 +12 -0
- package/dist/actions.d.ts +14 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/auto-work-branch-internal.d.ts +20 -0
- package/dist/auto-work-branch-internal.d.ts.map +1 -0
- package/dist/auto-work-branch.d.ts +2 -12
- package/dist/auto-work-branch.d.ts.map +1 -1
- package/dist/auto-work-branch.js +2 -4
- package/dist/auto-work-branch.js.map +1 -1
- package/dist/{chunk-EP3ZC37F.js → chunk-34B3Q75M.js} +1 -1
- package/dist/chunk-34B3Q75M.js.map +1 -0
- package/dist/{chunk-OFDNIT5X.js → chunk-F6CEEAFE.js} +1 -1
- package/dist/chunk-F6CEEAFE.js.map +1 -0
- package/dist/{chunk-YIP4MP64.js → chunk-HUVXPZSF.js} +2 -2
- package/dist/chunk-HUVXPZSF.js.map +1 -0
- package/dist/{chunk-73LKROYK.js → chunk-MY6XFGHM.js} +12 -14
- package/dist/chunk-MY6XFGHM.js.map +1 -0
- package/dist/{chunk-5LVPKVI2.js → chunk-OERAYSVI.js} +1 -1
- package/dist/chunk-OERAYSVI.js.map +1 -0
- package/dist/{chunk-WQEPA35Z.js → chunk-R3UCUGY6.js} +1 -1
- package/dist/chunk-R3UCUGY6.js.map +1 -0
- package/dist/{chunk-67YKGZLM.js → chunk-W7VJT6AN.js} +1 -1
- package/dist/chunk-W7VJT6AN.js.map +1 -0
- package/dist/{chunk-NIJCT4VK.js → chunk-WKHVLLKE.js} +1 -1
- package/dist/chunk-WKHVLLKE.js.map +1 -0
- package/dist/{chunk-UBVLJV3V.js → chunk-YSC5GEQJ.js} +1 -1
- package/dist/chunk-YSC5GEQJ.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +72 -0
- package/dist/finalization-git-internal.d.ts.map +1 -0
- package/dist/finalization-git.d.ts +2 -47
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +3 -9
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -25
- package/dist/index.js.map +1 -1
- package/dist/repository-change-launch-internal.d.ts +116 -0
- package/dist/repository-change-launch-internal.d.ts.map +1 -0
- package/dist/repository-change-launch.d.ts +2 -64
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +176 -8
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process.d.ts +32 -2
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-state-internal.d.ts +30 -0
- package/dist/repository-change-state-internal.d.ts.map +1 -0
- package/dist/repository-change-state.d.ts +2 -17
- package/dist/repository-change-state.d.ts.map +1 -1
- package/dist/repository-change-state.js +1 -7
- package/dist/turns/generate-commit-message.d.ts +2 -0
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +1 -1
- package/dist/turns/generate-plan.d.ts +1 -0
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/implement.d.ts +1 -0
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/resolve-merge-conflict.d.ts +1 -0
- package/dist/turns/resolve-merge-conflict.d.ts.map +1 -1
- package/dist/turns/resolve-merge-conflict.js +1 -1
- package/dist/turns/review-implementation.d.ts +1 -0
- package/dist/turns/review-implementation.d.ts.map +1 -1
- package/dist/turns/review-implementation.js +1 -1
- package/dist/turns/review-plan.d.ts +1 -0
- package/dist/turns/review-plan.d.ts.map +1 -1
- package/dist/turns/review-plan.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -0
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +1 -1
- package/package.json +18 -8
- package/src/actions.ts +17 -1
- package/src/auto-work-branch-internal.ts +149 -0
- package/src/auto-work-branch.ts +7 -140
- package/src/finalization-git-internal.ts +855 -0
- package/src/finalization-git.ts +2 -828
- package/src/index.ts +16 -4
- package/src/repository-change-launch-internal.ts +328 -0
- package/src/repository-change-launch.ts +15 -264
- package/src/repository-change-process.ts +31 -3
- package/src/repository-change-state-internal.ts +90 -0
- package/src/repository-change-state.ts +2 -78
- package/src/turns/generate-commit-message.ts +2 -0
- package/src/turns/generate-plan.ts +1 -0
- package/src/turns/implement.ts +1 -0
- package/src/turns/resolve-merge-conflict.ts +1 -0
- package/src/turns/review-implementation.ts +1 -0
- package/src/turns/review-plan.ts +1 -0
- package/src/turns/simplify-implementation.ts +1 -0
- package/dist/chunk-5LVPKVI2.js.map +0 -1
- package/dist/chunk-67YKGZLM.js.map +0 -1
- package/dist/chunk-73LKROYK.js.map +0 -1
- package/dist/chunk-EP3ZC37F.js.map +0 -1
- package/dist/chunk-NIJCT4VK.js.map +0 -1
- package/dist/chunk-OFDNIT5X.js.map +0 -1
- package/dist/chunk-UBVLJV3V.js.map +0 -1
- package/dist/chunk-WQEPA35Z.js.map +0 -1
- package/dist/chunk-Y2S6JFVO.js +0 -185
- package/dist/chunk-Y2S6JFVO.js.map +0 -1
- package/dist/chunk-YIP4MP64.js.map +0 -1
package/src/actions.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import type { FormDefinition } from "@leitwerk-dev/process-sdk";
|
|
2
2
|
|
|
3
|
+
/** @public */
|
|
3
4
|
export const codingActionIds = {
|
|
5
|
+
/** @public */
|
|
4
6
|
approvePlan: "approve_plan",
|
|
7
|
+
/** @internal */
|
|
5
8
|
requestRevision: "request_revision",
|
|
9
|
+
/** @internal */
|
|
6
10
|
runReview: "run_review",
|
|
11
|
+
/** @internal */
|
|
7
12
|
simplify: "simplify",
|
|
13
|
+
/** @internal */
|
|
8
14
|
acceptReview: "accept_review",
|
|
15
|
+
/** @internal */
|
|
9
16
|
requestReviewChanges: "request_review_changes",
|
|
17
|
+
/** @internal */
|
|
10
18
|
dismissReview: "dismiss_review",
|
|
19
|
+
/** @public */
|
|
11
20
|
finalizeChange: "finalize_change",
|
|
12
21
|
} as const;
|
|
13
22
|
|
|
@@ -22,18 +31,21 @@ function notesForm(id: string, title: string, label: string, description: string
|
|
|
22
31
|
};
|
|
23
32
|
}
|
|
24
33
|
|
|
34
|
+
/** @internal */
|
|
25
35
|
export const requestRevisionForm = notesForm(
|
|
26
36
|
codingActionIds.requestRevision,
|
|
27
37
|
"Request revision",
|
|
28
38
|
"Revision notes",
|
|
29
39
|
"Instructions for the next implementation pass.",
|
|
30
40
|
);
|
|
41
|
+
/** @internal */
|
|
31
42
|
export const requestReviewChangesForm = notesForm(
|
|
32
43
|
codingActionIds.requestReviewChanges,
|
|
33
44
|
"Request review changes",
|
|
34
45
|
"Review notes",
|
|
35
46
|
"Instructions for the next review pass.",
|
|
36
47
|
);
|
|
48
|
+
/** @internal */
|
|
37
49
|
export const acceptReviewForm: FormDefinition = {
|
|
38
50
|
id: codingActionIds.acceptReview,
|
|
39
51
|
title: "Accept review",
|
|
@@ -50,7 +62,11 @@ export const acceptReviewForm: FormDefinition = {
|
|
|
50
62
|
submitLabel: "Accept review",
|
|
51
63
|
};
|
|
52
64
|
|
|
53
|
-
|
|
65
|
+
/** @internal */
|
|
66
|
+
export function createFinalizeChangeForm(copy: {
|
|
67
|
+
/** @internal */
|
|
68
|
+
title: string;
|
|
69
|
+
}): FormDefinition {
|
|
54
70
|
return {
|
|
55
71
|
id: codingActionIds.finalizeChange,
|
|
56
72
|
title: copy.title,
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { trimToNull } from "@leitwerk-dev/domain";
|
|
5
|
+
import { sanitizeWorkerSubprocessEnv } from "@leitwerk-dev/process-sdk";
|
|
6
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
7
|
+
|
|
8
|
+
const DEFAULT_BASE_SHA_SUFFIX_LENGTH = 12;
|
|
9
|
+
const DEFAULT_MAX_BRANCH_SLUG_LENGTH = 48;
|
|
10
|
+
const DEFAULT_PROMPT_WORD_COUNT = 5;
|
|
11
|
+
const AUTO_BRANCH_RANDOM_HEX_LENGTH = 3;
|
|
12
|
+
const DEFAULT_GIT_TIMEOUT_MS = 15_000;
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
export interface ResolveBaseBranchShaInput {
|
|
17
|
+
/** @internal */
|
|
18
|
+
repoLocator: string;
|
|
19
|
+
/** @internal */
|
|
20
|
+
baseBranch: string;
|
|
21
|
+
/** @internal */
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function truncateSlugAtSeparator(value: string, maxLength: number): string {
|
|
26
|
+
if (value.length <= maxLength) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
return value.slice(0, maxLength).replace(/-+$/g, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizedBranchWords(value: string): string[] {
|
|
33
|
+
return (
|
|
34
|
+
value
|
|
35
|
+
.normalize("NFKD")
|
|
36
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.replace(/[’']/g, "")
|
|
39
|
+
.match(/[a-z0-9]+/g) ?? []
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
export function slugifyBranchSourceForBranch(sourceText: string): string {
|
|
45
|
+
const words = normalizedBranchWords(sourceText).slice(0, DEFAULT_PROMPT_WORD_COUNT);
|
|
46
|
+
const normalized = words.join("-");
|
|
47
|
+
const slug = truncateSlugAtSeparator(normalized, DEFAULT_MAX_BRANCH_SLUG_LENGTH);
|
|
48
|
+
return slug || "change";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeSha(value: string): string {
|
|
52
|
+
const sha = value.trim().toLowerCase();
|
|
53
|
+
if (!/^[0-9a-f]{7,64}$/.test(sha)) {
|
|
54
|
+
throw new Error(`Expected a git object sha, got '${value}'`);
|
|
55
|
+
}
|
|
56
|
+
return sha;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @public */
|
|
60
|
+
export function generateAutoWorkBranchRandomHex(): string {
|
|
61
|
+
return randomBytes(2).toString("hex").slice(0, AUTO_BRANCH_RANDOM_HEX_LENGTH);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function normalizeRandomHex(value: string): string {
|
|
65
|
+
const normalized = value.trim().toLowerCase();
|
|
66
|
+
if (!new RegExp(`^[0-9a-f]{${AUTO_BRANCH_RANDOM_HEX_LENGTH}}$`).test(normalized)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Expected ${AUTO_BRANCH_RANDOM_HEX_LENGTH} random hex characters, got '${value}'`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return normalized;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @internal */
|
|
75
|
+
export function buildAutoWorkBranch(
|
|
76
|
+
sourceText: string,
|
|
77
|
+
baseBranchSha: string,
|
|
78
|
+
randomHex = generateAutoWorkBranchRandomHex(),
|
|
79
|
+
): string {
|
|
80
|
+
const slug = slugifyBranchSourceForBranch(sourceText);
|
|
81
|
+
const suffix = normalizeRandomHex(randomHex);
|
|
82
|
+
const sha = normalizeSha(baseBranchSha);
|
|
83
|
+
return `${slug}-${suffix}-${sha.slice(0, DEFAULT_BASE_SHA_SUFFIX_LENGTH)}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Builds the same safe branch shape when authenticated remote SHA lookup must wait for a worker. @internal */
|
|
87
|
+
function gitShaLikeDigestFromSeed(seed: string): string {
|
|
88
|
+
return createHash("sha256").update(seed).digest("hex");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @public */
|
|
92
|
+
export function buildAutoWorkBranchFromSeed(
|
|
93
|
+
sourceText: string,
|
|
94
|
+
seed: string,
|
|
95
|
+
randomHex = generateAutoWorkBranchRandomHex(),
|
|
96
|
+
): string {
|
|
97
|
+
return buildAutoWorkBranch(sourceText, gitShaLikeDigestFromSeed(seed), randomHex);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function baseBranchRef(baseBranch: string): string {
|
|
101
|
+
const trimmed = trimToNull(baseBranch);
|
|
102
|
+
if (!trimmed) {
|
|
103
|
+
throw new Error("baseBranch is required to resolve an automatic work branch");
|
|
104
|
+
}
|
|
105
|
+
return trimmed.startsWith("refs/heads/") ? trimmed : `refs/heads/${trimmed}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function outputToString(value: unknown): string {
|
|
109
|
+
return typeof value === "string" ? value : Buffer.isBuffer(value) ? value.toString("utf8") : "";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** @internal */
|
|
113
|
+
export async function resolveBaseBranchSha(input: ResolveBaseBranchShaInput): Promise<string> {
|
|
114
|
+
const repoLocator = trimToNull(input.repoLocator);
|
|
115
|
+
if (!repoLocator) {
|
|
116
|
+
throw new Error("repoLocator is required to resolve an automatic work branch");
|
|
117
|
+
}
|
|
118
|
+
const ref = baseBranchRef(input.baseBranch);
|
|
119
|
+
let stdout = "";
|
|
120
|
+
try {
|
|
121
|
+
const result = await execFileAsync(resolveGitBinary(), ["ls-remote", repoLocator, ref], {
|
|
122
|
+
encoding: "utf8",
|
|
123
|
+
env: sanitizeWorkerSubprocessEnv(process.env, { GIT_TERMINAL_PROMPT: "0" }),
|
|
124
|
+
timeout: input.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS,
|
|
125
|
+
});
|
|
126
|
+
stdout = outputToString(result.stdout);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const errorOutput = error as { message?: string; stdout?: unknown; stderr?: unknown };
|
|
129
|
+
const message =
|
|
130
|
+
trimToNull(outputToString(errorOutput.stderr)) ??
|
|
131
|
+
trimToNull(outputToString(errorOutput.stdout)) ??
|
|
132
|
+
errorOutput.message ??
|
|
133
|
+
"unknown git error";
|
|
134
|
+
throw new Error(`Failed to resolve '${ref}' from '${repoLocator}': ${message}`);
|
|
135
|
+
}
|
|
136
|
+
const match = stdout
|
|
137
|
+
.split(/\r?\n/)
|
|
138
|
+
.map((line) => line.trim())
|
|
139
|
+
.filter(Boolean)
|
|
140
|
+
.map((line) => line.split(/\s+/))
|
|
141
|
+
.find((parts) => parts[1] === ref);
|
|
142
|
+
const sha = match?.[0];
|
|
143
|
+
if (!sha) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Repository '${repoLocator}' does not expose base branch '${input.baseBranch}'`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return normalizeSha(sha);
|
|
149
|
+
}
|
package/src/auto-work-branch.ts
CHANGED
|
@@ -1,140 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const DEFAULT_BASE_SHA_SUFFIX_LENGTH = 12;
|
|
9
|
-
const DEFAULT_MAX_BRANCH_SLUG_LENGTH = 48;
|
|
10
|
-
const DEFAULT_PROMPT_WORD_COUNT = 5;
|
|
11
|
-
const AUTO_BRANCH_RANDOM_HEX_LENGTH = 3;
|
|
12
|
-
const DEFAULT_GIT_TIMEOUT_MS = 15_000;
|
|
13
|
-
const execFileAsync = promisify(execFile);
|
|
14
|
-
|
|
15
|
-
export interface ResolveBaseBranchShaInput {
|
|
16
|
-
repoLocator: string;
|
|
17
|
-
baseBranch: string;
|
|
18
|
-
timeoutMs?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function truncateSlugAtSeparator(value: string, maxLength: number): string {
|
|
22
|
-
if (value.length <= maxLength) {
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
return value.slice(0, maxLength).replace(/-+$/g, "");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function normalizedBranchWords(value: string): string[] {
|
|
29
|
-
return (
|
|
30
|
-
value
|
|
31
|
-
.normalize("NFKD")
|
|
32
|
-
.replace(/[\u0300-\u036f]/g, "")
|
|
33
|
-
.toLowerCase()
|
|
34
|
-
.replace(/[’']/g, "")
|
|
35
|
-
.match(/[a-z0-9]+/g) ?? []
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function slugifyBranchSourceForBranch(sourceText: string): string {
|
|
40
|
-
const words = normalizedBranchWords(sourceText).slice(0, DEFAULT_PROMPT_WORD_COUNT);
|
|
41
|
-
const normalized = words.join("-");
|
|
42
|
-
const slug = truncateSlugAtSeparator(normalized, DEFAULT_MAX_BRANCH_SLUG_LENGTH);
|
|
43
|
-
return slug || "change";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function normalizeSha(value: string): string {
|
|
47
|
-
const sha = value.trim().toLowerCase();
|
|
48
|
-
if (!/^[0-9a-f]{7,64}$/.test(sha)) {
|
|
49
|
-
throw new Error(`Expected a git object sha, got '${value}'`);
|
|
50
|
-
}
|
|
51
|
-
return sha;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function generateAutoWorkBranchRandomHex(): string {
|
|
55
|
-
return randomBytes(2).toString("hex").slice(0, AUTO_BRANCH_RANDOM_HEX_LENGTH);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function normalizeRandomHex(value: string): string {
|
|
59
|
-
const normalized = value.trim().toLowerCase();
|
|
60
|
-
if (!new RegExp(`^[0-9a-f]{${AUTO_BRANCH_RANDOM_HEX_LENGTH}}$`).test(normalized)) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Expected ${AUTO_BRANCH_RANDOM_HEX_LENGTH} random hex characters, got '${value}'`,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
return normalized;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function buildAutoWorkBranch(
|
|
69
|
-
sourceText: string,
|
|
70
|
-
baseBranchSha: string,
|
|
71
|
-
randomHex = generateAutoWorkBranchRandomHex(),
|
|
72
|
-
): string {
|
|
73
|
-
const slug = slugifyBranchSourceForBranch(sourceText);
|
|
74
|
-
const suffix = normalizeRandomHex(randomHex);
|
|
75
|
-
const sha = normalizeSha(baseBranchSha);
|
|
76
|
-
return `${slug}-${suffix}-${sha.slice(0, DEFAULT_BASE_SHA_SUFFIX_LENGTH)}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Builds the same safe branch shape when authenticated remote SHA lookup must wait for a worker. */
|
|
80
|
-
export function gitShaLikeDigestFromSeed(seed: string): string {
|
|
81
|
-
return createHash("sha256").update(seed).digest("hex");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function buildAutoWorkBranchFromSeed(
|
|
85
|
-
sourceText: string,
|
|
86
|
-
seed: string,
|
|
87
|
-
randomHex = generateAutoWorkBranchRandomHex(),
|
|
88
|
-
): string {
|
|
89
|
-
return buildAutoWorkBranch(sourceText, gitShaLikeDigestFromSeed(seed), randomHex);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function baseBranchRef(baseBranch: string): string {
|
|
93
|
-
const trimmed = trimToNull(baseBranch);
|
|
94
|
-
if (!trimmed) {
|
|
95
|
-
throw new Error("baseBranch is required to resolve an automatic work branch");
|
|
96
|
-
}
|
|
97
|
-
return trimmed.startsWith("refs/heads/") ? trimmed : `refs/heads/${trimmed}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function outputToString(value: unknown): string {
|
|
101
|
-
return typeof value === "string" ? value : Buffer.isBuffer(value) ? value.toString("utf8") : "";
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function resolveBaseBranchSha(input: ResolveBaseBranchShaInput): Promise<string> {
|
|
105
|
-
const repoLocator = trimToNull(input.repoLocator);
|
|
106
|
-
if (!repoLocator) {
|
|
107
|
-
throw new Error("repoLocator is required to resolve an automatic work branch");
|
|
108
|
-
}
|
|
109
|
-
const ref = baseBranchRef(input.baseBranch);
|
|
110
|
-
let stdout = "";
|
|
111
|
-
try {
|
|
112
|
-
const result = await execFileAsync(resolveGitBinary(), ["ls-remote", repoLocator, ref], {
|
|
113
|
-
encoding: "utf8",
|
|
114
|
-
env: sanitizeWorkerSubprocessEnv(process.env, { GIT_TERMINAL_PROMPT: "0" }),
|
|
115
|
-
timeout: input.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS,
|
|
116
|
-
});
|
|
117
|
-
stdout = outputToString(result.stdout);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
const errorOutput = error as { message?: string; stdout?: unknown; stderr?: unknown };
|
|
120
|
-
const message =
|
|
121
|
-
trimToNull(outputToString(errorOutput.stderr)) ??
|
|
122
|
-
trimToNull(outputToString(errorOutput.stdout)) ??
|
|
123
|
-
errorOutput.message ??
|
|
124
|
-
"unknown git error";
|
|
125
|
-
throw new Error(`Failed to resolve '${ref}' from '${repoLocator}': ${message}`);
|
|
126
|
-
}
|
|
127
|
-
const match = stdout
|
|
128
|
-
.split(/\r?\n/)
|
|
129
|
-
.map((line) => line.trim())
|
|
130
|
-
.filter(Boolean)
|
|
131
|
-
.map((line) => line.split(/\s+/))
|
|
132
|
-
.find((parts) => parts[1] === ref);
|
|
133
|
-
const sha = match?.[0];
|
|
134
|
-
if (!sha) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
`Repository '${repoLocator}' does not expose base branch '${input.baseBranch}'`,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
return normalizeSha(sha);
|
|
140
|
-
}
|
|
1
|
+
export type { ResolveBaseBranchShaInput } from "./auto-work-branch-internal.js";
|
|
2
|
+
export {
|
|
3
|
+
buildAutoWorkBranch,
|
|
4
|
+
buildAutoWorkBranchFromSeed,
|
|
5
|
+
generateAutoWorkBranchRandomHex,
|
|
6
|
+
resolveBaseBranchSha,
|
|
7
|
+
} from "./auto-work-branch-internal.js";
|