@leitwerk-dev/coding 0.2.1 → 0.3.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 (58) hide show
  1. package/README.md +18 -12
  2. package/dist/actions.d.ts +0 -5
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/auto-work-branch-internal.d.ts +2 -18
  5. package/dist/auto-work-branch-internal.d.ts.map +1 -1
  6. package/dist/auto-work-branch.d.ts +1 -2
  7. package/dist/auto-work-branch.d.ts.map +1 -1
  8. package/dist/auto-work-branch.js +17 -94
  9. package/dist/auto-work-branch.js.map +1 -1
  10. package/dist/chunk-GO44KCUS.js +154 -0
  11. package/dist/chunk-GO44KCUS.js.map +1 -0
  12. package/dist/finalization-git-internal.d.ts +6 -45
  13. package/dist/finalization-git-internal.d.ts.map +1 -1
  14. package/dist/finalization-git.js +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +48 -91
  18. package/dist/index.js.map +1 -1
  19. package/dist/repository-change-launch-internal.d.ts +3 -84
  20. package/dist/repository-change-launch-internal.d.ts.map +1 -1
  21. package/dist/repository-change-launch.d.ts +2 -2
  22. package/dist/repository-change-launch.d.ts.map +1 -1
  23. package/dist/repository-change-launch.js +2 -159
  24. package/dist/repository-change-launch.js.map +1 -1
  25. package/dist/repository-change-process.d.ts +7 -19
  26. package/dist/repository-change-process.d.ts.map +1 -1
  27. package/dist/repository-change-publication.d.ts +229 -0
  28. package/dist/repository-change-publication.d.ts.map +1 -0
  29. package/dist/repository-change-publication.js +368 -0
  30. package/dist/repository-change-publication.js.map +1 -0
  31. package/dist/repository-change-state-internal.d.ts +2 -11
  32. package/dist/repository-change-state-internal.d.ts.map +1 -1
  33. package/dist/repository-change-state.d.ts +0 -1
  34. package/dist/repository-change-state.d.ts.map +1 -1
  35. package/dist/repository-change-state.js +0 -7
  36. package/package.json +10 -4
  37. package/src/actions.ts +0 -13
  38. package/src/auto-work-branch-internal.ts +22 -130
  39. package/src/auto-work-branch.ts +1 -7
  40. package/src/finalization-git-internal.ts +60 -697
  41. package/src/index.ts +0 -1
  42. package/src/repository-change-launch-internal.ts +4 -268
  43. package/src/repository-change-launch.ts +1 -6
  44. package/src/repository-change-process.ts +8 -126
  45. package/src/repository-change-publication.ts +689 -0
  46. package/src/repository-change-state-internal.ts +4 -34
  47. package/src/repository-change-state.ts +0 -1
  48. package/dist/chunk-HUVXPZSF.js +0 -61
  49. package/dist/chunk-HUVXPZSF.js.map +0 -1
  50. package/dist/chunk-MY6XFGHM.js +0 -614
  51. package/dist/chunk-MY6XFGHM.js.map +0 -1
  52. package/dist/chunk-OERAYSVI.js +0 -27
  53. package/dist/chunk-OERAYSVI.js.map +0 -1
  54. package/dist/turns/resolve-merge-conflict.d.ts +0 -4
  55. package/dist/turns/resolve-merge-conflict.d.ts.map +0 -1
  56. package/dist/turns/resolve-merge-conflict.js +0 -8
  57. package/dist/turns/resolve-merge-conflict.js.map +0 -1
  58. package/src/turns/resolve-merge-conflict.ts +0 -26
@@ -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 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);
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
- /** @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
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
- /** @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);
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 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");
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
- randomHex = generateAutoWorkBranchRandomHex(),
33
+ suffix = randomHex(),
96
34
  ): 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
- );
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
- return normalizeSha(sha);
39
+ const digest = createHash("sha256").update(seed).digest("hex");
40
+ return `${slugifyBranchSource(sourceText)}-${normalizedSuffix}-${digest.slice(0, BASE_DIGEST_SUFFIX_LENGTH)}`;
149
41
  }
@@ -1,7 +1 @@
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";
1
+ export { buildAutoWorkBranchFromSeed } from "./auto-work-branch-internal.js";