@leitwerk-dev/coding 0.2.1 → 0.3.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 +51 -12
- package/dist/actions.d.ts +0 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/auto-work-branch-internal.d.ts +2 -18
- package/dist/auto-work-branch-internal.d.ts.map +1 -1
- package/dist/auto-work-branch.d.ts +1 -2
- package/dist/auto-work-branch.d.ts.map +1 -1
- package/dist/auto-work-branch.js +4 -102
- package/dist/auto-work-branch.js.map +1 -1
- package/dist/chunk-6E5VQPC4.js +28 -0
- package/dist/chunk-6E5VQPC4.js.map +1 -0
- package/dist/chunk-GO44KCUS.js +154 -0
- package/dist/chunk-GO44KCUS.js.map +1 -0
- package/dist/chunk-KFELB7ZC.js +70 -0
- package/dist/chunk-KFELB7ZC.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +6 -45
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -91
- package/dist/index.js.map +1 -1
- package/dist/profile-bindings-internal.d.ts +3 -0
- package/dist/profile-bindings-internal.d.ts.map +1 -0
- package/dist/pull-request-publication-internal.d.ts +73 -0
- package/dist/pull-request-publication-internal.d.ts.map +1 -0
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +67 -0
- package/dist/repository-change-launch-internal.d.ts +31 -82
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -2
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +205 -133
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process.d.ts +7 -19
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +229 -0
- package/dist/repository-change-publication.d.ts.map +1 -0
- package/dist/repository-change-publication.js +770 -0
- package/dist/repository-change-publication.js.map +1 -0
- package/dist/repository-change-state-internal.d.ts +2 -11
- package/dist/repository-change-state-internal.d.ts.map +1 -1
- package/dist/repository-change-state.d.ts +0 -1
- package/dist/repository-change-state.d.ts.map +1 -1
- package/dist/repository-change-state.js +0 -7
- package/dist/repository-change-ui-launcher-internal.d.ts +53 -0
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -0
- package/dist/repository-rebase/git.d.ts +31 -0
- package/dist/repository-rebase/git.d.ts.map +1 -0
- package/dist/repository-rebase/index.d.ts +42 -0
- package/dist/repository-rebase/index.d.ts.map +1 -0
- package/dist/repository-rebase/index.js +16 -0
- package/dist/repository-rebase/policy.d.ts +37 -0
- package/dist/repository-rebase/policy.d.ts.map +1 -0
- package/dist/repository-rebase/prompt.d.ts +3 -0
- package/dist/repository-rebase/prompt.d.ts.map +1 -0
- package/package.json +14 -4
- package/src/actions.ts +0 -13
- package/src/auto-work-branch-internal.ts +22 -130
- package/src/auto-work-branch.ts +1 -7
- package/src/finalization-git-internal.ts +60 -697
- package/src/index.ts +0 -1
- package/src/profile-bindings-internal.ts +39 -0
- package/src/pull-request-publication-internal.ts +286 -0
- package/src/repository-change-launch-internal.ts +79 -267
- package/src/repository-change-launch.ts +10 -6
- package/src/repository-change-process.ts +8 -126
- package/src/repository-change-publication.ts +673 -0
- package/src/repository-change-state-internal.ts +4 -34
- package/src/repository-change-state.ts +0 -1
- package/src/repository-change-ui-launcher-internal.ts +225 -0
- package/src/repository-rebase/git.ts +219 -0
- package/src/repository-rebase/index.ts +144 -0
- package/src/repository-rebase/policy.ts +75 -0
- package/src/repository-rebase/prompt.ts +2 -0
- package/dist/chunk-HUVXPZSF.js +0 -61
- package/dist/chunk-HUVXPZSF.js.map +0 -1
- package/dist/chunk-MY6XFGHM.js +0 -614
- package/dist/chunk-MY6XFGHM.js.map +0 -1
- package/dist/chunk-OERAYSVI.js +0 -27
- package/dist/chunk-OERAYSVI.js.map +0 -1
- package/dist/turns/resolve-merge-conflict.d.ts +0 -4
- package/dist/turns/resolve-merge-conflict.d.ts.map +0 -1
- package/dist/turns/resolve-merge-conflict.js +0 -8
- package/src/turns/resolve-merge-conflict.ts +0 -26
- /package/dist/{turns/resolve-merge-conflict.js.map → repository-rebase/index.js.map} +0 -0
|
@@ -1,149 +1,41 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
1
|
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
2
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const DEFAULT_GIT_TIMEOUT_MS = 15_000;
|
|
13
|
-
const execFileAsync = promisify(execFile);
|
|
3
|
+
const BASE_DIGEST_SUFFIX_LENGTH = 12;
|
|
4
|
+
const MAX_BRANCH_SLUG_LENGTH = 48;
|
|
5
|
+
const PROMPT_WORD_COUNT = 5;
|
|
6
|
+
const RANDOM_HEX_LENGTH = 3;
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
8
|
+
function slugifyBranchSource(sourceText: string): string {
|
|
9
|
+
const words =
|
|
10
|
+
sourceText
|
|
35
11
|
.normalize("NFKD")
|
|
36
12
|
.replace(/[\u0300-\u036f]/g, "")
|
|
37
13
|
.toLowerCase()
|
|
38
14
|
.replace(/[’']/g, "")
|
|
39
|
-
.match(/[a-z0-9]+/g) ?? []
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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);
|
|
15
|
+
.match(/[a-z0-9]+/g) ?? [];
|
|
16
|
+
const normalized = words.slice(0, PROMPT_WORD_COUNT).join("-");
|
|
17
|
+
const slug =
|
|
18
|
+
normalized.length <= MAX_BRANCH_SLUG_LENGTH
|
|
19
|
+
? normalized
|
|
20
|
+
: normalized.slice(0, MAX_BRANCH_SLUG_LENGTH).replace(/-+$/g, "");
|
|
48
21
|
return slug || "change";
|
|
49
22
|
}
|
|
50
23
|
|
|
51
|
-
function
|
|
52
|
-
|
|
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");
|
|
24
|
+
function randomHex(): string {
|
|
25
|
+
return randomBytes(2).toString("hex").slice(0, RANDOM_HEX_LENGTH);
|
|
89
26
|
}
|
|
90
27
|
|
|
28
|
+
/** Build a safe branch name without requiring authenticated remote access. */
|
|
91
29
|
/** @public */
|
|
92
30
|
export function buildAutoWorkBranchFromSeed(
|
|
93
31
|
sourceText: string,
|
|
94
32
|
seed: string,
|
|
95
|
-
|
|
33
|
+
suffix = randomHex(),
|
|
96
34
|
): string {
|
|
97
|
-
|
|
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
|
-
);
|
|
35
|
+
const normalizedSuffix = suffix.trim().toLowerCase();
|
|
36
|
+
if (!new RegExp(`^[0-9a-f]{${RANDOM_HEX_LENGTH}}$`).test(normalizedSuffix)) {
|
|
37
|
+
throw new Error(`Expected ${RANDOM_HEX_LENGTH} random hex characters, got '${suffix}'`);
|
|
147
38
|
}
|
|
148
|
-
|
|
39
|
+
const digest = createHash("sha256").update(seed).digest("hex");
|
|
40
|
+
return `${slugifyBranchSource(sourceText)}-${normalizedSuffix}-${digest.slice(0, BASE_DIGEST_SUFFIX_LENGTH)}`;
|
|
149
41
|
}
|
package/src/auto-work-branch.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
3
|
-
buildAutoWorkBranch,
|
|
4
|
-
buildAutoWorkBranchFromSeed,
|
|
5
|
-
generateAutoWorkBranchRandomHex,
|
|
6
|
-
resolveBaseBranchSha,
|
|
7
|
-
} from "./auto-work-branch-internal.js";
|
|
1
|
+
export { buildAutoWorkBranchFromSeed } from "./auto-work-branch-internal.js";
|