@leitwerk-dev/coding 0.2.0 → 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 (105) hide show
  1. package/README.md +28 -10
  2. package/dist/actions.d.ts +12 -3
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/auto-work-branch-internal.d.ts +4 -0
  5. package/dist/auto-work-branch-internal.d.ts.map +1 -0
  6. package/dist/auto-work-branch.d.ts +1 -12
  7. package/dist/auto-work-branch.d.ts.map +1 -1
  8. package/dist/auto-work-branch.js +18 -97
  9. package/dist/auto-work-branch.js.map +1 -1
  10. package/dist/{chunk-EP3ZC37F.js → chunk-34B3Q75M.js} +1 -1
  11. package/dist/chunk-34B3Q75M.js.map +1 -0
  12. package/dist/{chunk-OFDNIT5X.js → chunk-F6CEEAFE.js} +1 -1
  13. package/dist/chunk-F6CEEAFE.js.map +1 -0
  14. package/dist/chunk-GO44KCUS.js +154 -0
  15. package/dist/chunk-GO44KCUS.js.map +1 -0
  16. package/dist/{chunk-WQEPA35Z.js → chunk-R3UCUGY6.js} +1 -1
  17. package/dist/chunk-R3UCUGY6.js.map +1 -0
  18. package/dist/{chunk-67YKGZLM.js → chunk-W7VJT6AN.js} +1 -1
  19. package/dist/chunk-W7VJT6AN.js.map +1 -0
  20. package/dist/{chunk-NIJCT4VK.js → chunk-WKHVLLKE.js} +1 -1
  21. package/dist/chunk-WKHVLLKE.js.map +1 -0
  22. package/dist/{chunk-UBVLJV3V.js → chunk-YSC5GEQJ.js} +1 -1
  23. package/dist/chunk-YSC5GEQJ.js.map +1 -0
  24. package/dist/finalization-git-internal.d.ts +33 -0
  25. package/dist/finalization-git-internal.d.ts.map +1 -0
  26. package/dist/finalization-git.d.ts +2 -47
  27. package/dist/finalization-git.d.ts.map +1 -1
  28. package/dist/finalization-git.js +3 -9
  29. package/dist/index.d.ts +3 -7
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +73 -112
  32. package/dist/index.js.map +1 -1
  33. package/dist/repository-change-launch-internal.d.ts +35 -0
  34. package/dist/repository-change-launch-internal.d.ts.map +1 -0
  35. package/dist/repository-change-launch.d.ts +2 -64
  36. package/dist/repository-change-launch.d.ts.map +1 -1
  37. package/dist/repository-change-launch.js +22 -11
  38. package/dist/repository-change-launch.js.map +1 -1
  39. package/dist/repository-change-process.d.ts +31 -13
  40. package/dist/repository-change-process.d.ts.map +1 -1
  41. package/dist/repository-change-publication.d.ts +229 -0
  42. package/dist/repository-change-publication.d.ts.map +1 -0
  43. package/dist/repository-change-publication.js +368 -0
  44. package/dist/repository-change-publication.js.map +1 -0
  45. package/dist/repository-change-state-internal.d.ts +21 -0
  46. package/dist/repository-change-state-internal.d.ts.map +1 -0
  47. package/dist/repository-change-state.d.ts +1 -17
  48. package/dist/repository-change-state.d.ts.map +1 -1
  49. package/dist/repository-change-state.js +0 -13
  50. package/dist/turns/generate-commit-message.d.ts +2 -0
  51. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  52. package/dist/turns/generate-commit-message.js +1 -1
  53. package/dist/turns/generate-plan.d.ts +1 -0
  54. package/dist/turns/generate-plan.d.ts.map +1 -1
  55. package/dist/turns/generate-plan.js +1 -1
  56. package/dist/turns/implement.d.ts +1 -0
  57. package/dist/turns/implement.d.ts.map +1 -1
  58. package/dist/turns/implement.js +1 -1
  59. package/dist/turns/review-implementation.d.ts +1 -0
  60. package/dist/turns/review-implementation.d.ts.map +1 -1
  61. package/dist/turns/review-implementation.js +1 -1
  62. package/dist/turns/review-plan.d.ts +1 -0
  63. package/dist/turns/review-plan.d.ts.map +1 -1
  64. package/dist/turns/review-plan.js +1 -1
  65. package/dist/turns/simplify-implementation.d.ts +1 -0
  66. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  67. package/dist/turns/simplify-implementation.js +1 -1
  68. package/package.json +24 -8
  69. package/src/actions.ts +12 -9
  70. package/src/auto-work-branch-internal.ts +41 -0
  71. package/src/auto-work-branch.ts +1 -140
  72. package/src/finalization-git-internal.ts +218 -0
  73. package/src/finalization-git.ts +2 -828
  74. package/src/index.ts +15 -4
  75. package/src/repository-change-launch-internal.ts +64 -0
  76. package/src/repository-change-launch.ts +10 -264
  77. package/src/repository-change-process.ts +33 -123
  78. package/src/repository-change-publication.ts +689 -0
  79. package/src/repository-change-state-internal.ts +60 -0
  80. package/src/repository-change-state.ts +1 -78
  81. package/src/turns/generate-commit-message.ts +2 -0
  82. package/src/turns/generate-plan.ts +1 -0
  83. package/src/turns/implement.ts +1 -0
  84. package/src/turns/review-implementation.ts +1 -0
  85. package/src/turns/review-plan.ts +1 -0
  86. package/src/turns/simplify-implementation.ts +1 -0
  87. package/dist/chunk-5LVPKVI2.js +0 -27
  88. package/dist/chunk-5LVPKVI2.js.map +0 -1
  89. package/dist/chunk-67YKGZLM.js.map +0 -1
  90. package/dist/chunk-73LKROYK.js +0 -616
  91. package/dist/chunk-73LKROYK.js.map +0 -1
  92. package/dist/chunk-EP3ZC37F.js.map +0 -1
  93. package/dist/chunk-NIJCT4VK.js.map +0 -1
  94. package/dist/chunk-OFDNIT5X.js.map +0 -1
  95. package/dist/chunk-UBVLJV3V.js.map +0 -1
  96. package/dist/chunk-WQEPA35Z.js.map +0 -1
  97. package/dist/chunk-Y2S6JFVO.js +0 -185
  98. package/dist/chunk-Y2S6JFVO.js.map +0 -1
  99. package/dist/chunk-YIP4MP64.js +0 -61
  100. package/dist/chunk-YIP4MP64.js.map +0 -1
  101. package/dist/turns/resolve-merge-conflict.d.ts +0 -3
  102. package/dist/turns/resolve-merge-conflict.d.ts.map +0 -1
  103. package/dist/turns/resolve-merge-conflict.js +0 -8
  104. package/dist/turns/resolve-merge-conflict.js.map +0 -1
  105. package/src/turns/resolve-merge-conflict.ts +0 -25
package/README.md CHANGED
@@ -1,18 +1,36 @@
1
1
  # Coding
2
2
 
3
- Shared repository-change process graph, action forms, prompts, state, and deterministic Git finalization used by Local Repo Change and Remote Repo Change.
3
+ Shared repository-change planning, review, implementation, state, commit-message, and feature-branch publication support used by provider-owned processes and development compositions.
4
4
 
5
- Owning extensions provide process identity, launcher policy, finalization copy, and optional repository credential requirements while retaining their persisted process and turn ids.
5
+ Owning extensions provide process identity, launcher policy, finalization copy, repository credential requirements, and a publication fragment. `@leitwerk-dev/forgejo-repo-change`, `@leitwerk-dev/github-repo-change`, and `@leitwerk-dev/gitlab-repo-change` are production consumers; the public sandbox supplies a local-only publication fragment for scripted scenarios.
6
6
 
7
- An owning extension may omit the shared launcher and supply a publication fragment. The fragment starts after `generate_commit_message` and owns the remaining publication turns and happy path.
7
+ After final implementation approval, `generate_commit_message` consumes the durable accepted `plan` without repository tools. It uses the model configured for `pi.process_title_generation.model_profile` (or the process's inherited model when title generation has no profile), applies the formatting rules pinned in project metadata at launch, and persists the normalized plain-text message in finalization state. Publication fragments consume that message.
8
8
 
9
- After final implementation approval, `generate_commit_message` consumes the durable accepted `plan` without repository tools. It uses the model configured for `pi.process_title_generation.model_profile` (or the process's inherited model when title generation has no profile), applies the formatting rules pinned in project metadata at launch, and persists the normalized plain-text message in finalization state. Retries and merge-conflict recovery reuse that message.
9
+ `commitAndPushWorkBranch()` requires an explicit trusted Git identity, commits dirty workspace files, and pushes only the checked-out feature branch. It rejects invalid Git identity, unresolved conflicts, branch mismatches, and remote heads that do not match the committed HEAD.
10
10
 
11
- Deterministic finalization passes the message directly to Git and disables hooks and signing. Callers may supply a trusted Git identity explicitly; otherwise finalization uses repository/global `user.name` and `user.email`. It fails before staging or a commit-producing merge when Git identity is unavailable. Explicit identity applies only to identity preflight, commits, and commit-producing merges through per-command `-c user.name` and `-c user.email` arguments. Its Chronicle progress report distinguishes checkout validation, base fetch, commit/integration, and publication. Runtime failures mark the active step failed; merge-conflict outcomes identify the integration step.
11
+ Turn labels use short task names: Plan, Review Plan, Implement, and Review. Automated assessments use Assess Plan and Assess Implementation so operators can distinguish them from their own decisions. Repository-change processes share these labels and turn ids.
12
12
 
13
- `commitAndPushWorkBranch()` requires an explicit trusted Git identity, commits dirty workspace files, and pushes only the checked-out feature branch. It rejects invalid Git identity, unresolved conflicts, branch mismatches, and remote heads that do not match the committed HEAD.
13
+ ## Shared publication
14
+
15
+ `createRepositoryChangePublication()` constructs the delivery, feedback, CI repair,
16
+ rebase, and operator recovery fragment used by Forgejo, GitHub, and GitLab repository
17
+ change processes. Its adapter supplies provider operations, native evidence sources,
18
+ repair tools/prompts, pinned identity resolution, and stored names. The shared module
19
+ owns Git publication and lifecycle policy without importing provider integrations.
20
+ Provider cursors and receipts remain durable in namespaced publication state.
21
+ Forgejo retains its original namespace, turn/action identifiers, and write identities.
22
+
23
+ ## API support
24
+
25
+ The following exported declarations are `@public`:
26
+
27
+ - `@leitwerk-dev/coding`: `codingActionIds`, `createRepositoryChangeProcess`, `default`.
28
+ - `@leitwerk-dev/coding/auto-work-branch`: `buildAutoWorkBranchFromSeed`.
29
+ - `@leitwerk-dev/coding/finalization-git`: `GitIdentity`, `commitAndPushWorkBranch`.
30
+ - `@leitwerk-dev/coding/repository-change-launch`: `NormalizedRepositoryChangeParamsInput`, `RepositoryChangeLaunchParams`, `RepositoryChangeParamsBase`, `createRepositoryChangeParamsCodec`, `normalizeRepositoryChangeParamsInput`, `repositoryChangeParamsRecord`.
31
+ - `@leitwerk-dev/coding/repository-change-publication`: `DeliveryState`, `PublicationContext`, `PublicationEvidence`, `PublicationFeedbackId`, `PublicationParams`, `PublicationPipeline`, `PublicationRequest`, `PublicationSource`, `PublicationState`, `RepositoryChangePublicationAdapter`, `applyPublicationEvidence`, `createRepositoryChangePublication`, `patchPublicationState`, `publicationObject`, `readPublicationState`.
32
+ - `@leitwerk-dev/coding/repository-change-state`: `RepositoryChangeState`.
33
+
34
+ See the [SDK compatibility policy](../../docs/process-sdk.md#api-compatibility) for member classifications and support guarantees.
14
35
 
15
- Turn labels use short task names: Plan, Review Plan, Implement, and Review.
16
- Automated assessments use Assess Plan and Assess Implementation so operators can
17
- distinguish them from their own decisions. Local, remote, and provider-specific
18
- repository-change processes share these labels; persisted turn ids are unchanged.
36
+ Pre-launch repository lookup uses `sanitizeWorkerSubprocessEnv` without project credentials. Trusted project Git operations use `repositoryGitSubprocessEnv(projectKey)`.
package/dist/actions.d.ts CHANGED
@@ -1,18 +1,27 @@
1
1
  import type { FormDefinition } from "@leitwerk-dev/process-sdk";
2
+ /** @public */
2
3
  export declare const codingActionIds: {
4
+ /** @public */
3
5
  readonly approvePlan: "approve_plan";
6
+ /** @internal */
4
7
  readonly requestRevision: "request_revision";
8
+ /** @internal */
5
9
  readonly runReview: "run_review";
10
+ /** @internal */
6
11
  readonly simplify: "simplify";
12
+ /** @internal */
7
13
  readonly acceptReview: "accept_review";
14
+ /** @internal */
8
15
  readonly requestReviewChanges: "request_review_changes";
16
+ /** @internal */
9
17
  readonly dismissReview: "dismiss_review";
18
+ /** @public */
10
19
  readonly finalizeChange: "finalize_change";
11
20
  };
21
+ /** @internal */
12
22
  export declare const requestRevisionForm: FormDefinition;
23
+ /** @internal */
13
24
  export declare const requestReviewChangesForm: FormDefinition;
25
+ /** @internal */
14
26
  export declare const acceptReviewForm: FormDefinition;
15
- export declare function createFinalizeChangeForm(copy: {
16
- title: string;
17
- }): FormDefinition;
18
27
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAaX,eAAO,MAAM,mBAAmB,gBAK/B,CAAC;AACF,eAAO,MAAM,wBAAwB,gBAKpC,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,cAc9B,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAOhF"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,cAAc;AACd,eAAO,MAAM,eAAe;IAC3B,cAAc;;IAEd,gBAAgB;;IAEhB,gBAAgB;;IAEhB,gBAAgB;;IAEhB,gBAAgB;;IAEhB,gBAAgB;;IAEhB,gBAAgB;;IAEhB,cAAc;;CAEL,CAAC;AAaX,gBAAgB;AAChB,eAAO,MAAM,mBAAmB,gBAK/B,CAAC;AACF,gBAAgB;AAChB,eAAO,MAAM,wBAAwB,gBAKpC,CAAC;AACF,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,EAAE,cAc9B,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Build a safe branch name without requiring authenticated remote access. */
2
+ /** @public */
3
+ export declare function buildAutoWorkBranchFromSeed(sourceText: string, seed: string, suffix?: string): string;
4
+ //# sourceMappingURL=auto-work-branch-internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-work-branch-internal.d.ts","sourceRoot":"","sources":["../src/auto-work-branch-internal.ts"],"names":[],"mappings":"AA2BA,8EAA8E;AAC9E,cAAc;AACd,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,SAAc,GAClB,MAAM,CAOR"}
@@ -1,13 +1,2 @@
1
- export interface ResolveBaseBranchShaInput {
2
- repoLocator: string;
3
- baseBranch: string;
4
- timeoutMs?: number;
5
- }
6
- export declare function slugifyBranchSourceForBranch(sourceText: string): string;
7
- export declare function generateAutoWorkBranchRandomHex(): string;
8
- export declare function buildAutoWorkBranch(sourceText: string, baseBranchSha: string, randomHex?: string): string;
9
- /** Builds the same safe branch shape when authenticated remote SHA lookup must wait for a worker. */
10
- export declare function gitShaLikeDigestFromSeed(seed: string): string;
11
- export declare function buildAutoWorkBranchFromSeed(sourceText: string, seed: string, randomHex?: string): string;
12
- export declare function resolveBaseBranchSha(input: ResolveBaseBranchShaInput): Promise<string>;
1
+ export { buildAutoWorkBranchFromSeed } from "./auto-work-branch-internal.js";
13
2
  //# sourceMappingURL=auto-work-branch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-work-branch.d.ts","sourceRoot":"","sources":["../src/auto-work-branch.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,yBAAyB;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAoBD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKvE;AAUD,wBAAgB,+BAA+B,IAAI,MAAM,CAExD;AAYD,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,SAAS,SAAoC,GAC3C,MAAM,CAKR;AAED,qGAAqG;AACrG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,SAAoC,GAC3C,MAAM,CAER;AAcD,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoC5F"}
1
+ {"version":3,"file":"auto-work-branch.d.ts","sourceRoot":"","sources":["../src/auto-work-branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC"}
@@ -1,108 +1,29 @@
1
1
  import "./chunk-PX6F3LHL.js";
2
2
 
3
- // src/auto-work-branch.ts
4
- import { execFile } from "child_process";
3
+ // src/auto-work-branch-internal.ts
5
4
  import { createHash, randomBytes } from "crypto";
6
- import { promisify } from "util";
7
- import { trimToNull } from "@leitwerk-dev/domain";
8
- import { sanitizeWorkerSubprocessEnv } from "@leitwerk-dev/process-sdk";
9
- import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
10
- var DEFAULT_BASE_SHA_SUFFIX_LENGTH = 12;
11
- var DEFAULT_MAX_BRANCH_SLUG_LENGTH = 48;
12
- var DEFAULT_PROMPT_WORD_COUNT = 5;
13
- var AUTO_BRANCH_RANDOM_HEX_LENGTH = 3;
14
- var DEFAULT_GIT_TIMEOUT_MS = 15e3;
15
- var execFileAsync = promisify(execFile);
16
- function truncateSlugAtSeparator(value, maxLength) {
17
- if (value.length <= maxLength) {
18
- return value;
19
- }
20
- return value.slice(0, maxLength).replace(/-+$/g, "");
21
- }
22
- function normalizedBranchWords(value) {
23
- return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[’']/g, "").match(/[a-z0-9]+/g) ?? [];
24
- }
25
- function slugifyBranchSourceForBranch(sourceText) {
26
- const words = normalizedBranchWords(sourceText).slice(0, DEFAULT_PROMPT_WORD_COUNT);
27
- const normalized = words.join("-");
28
- const slug = truncateSlugAtSeparator(normalized, DEFAULT_MAX_BRANCH_SLUG_LENGTH);
5
+ var BASE_DIGEST_SUFFIX_LENGTH = 12;
6
+ var MAX_BRANCH_SLUG_LENGTH = 48;
7
+ var PROMPT_WORD_COUNT = 5;
8
+ var RANDOM_HEX_LENGTH = 3;
9
+ function slugifyBranchSource(sourceText) {
10
+ const words = sourceText.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[’']/g, "").match(/[a-z0-9]+/g) ?? [];
11
+ const normalized = words.slice(0, PROMPT_WORD_COUNT).join("-");
12
+ const slug = normalized.length <= MAX_BRANCH_SLUG_LENGTH ? normalized : normalized.slice(0, MAX_BRANCH_SLUG_LENGTH).replace(/-+$/g, "");
29
13
  return slug || "change";
30
14
  }
31
- function normalizeSha(value) {
32
- const sha = value.trim().toLowerCase();
33
- if (!/^[0-9a-f]{7,64}$/.test(sha)) {
34
- throw new Error(`Expected a git object sha, got '${value}'`);
35
- }
36
- return sha;
37
- }
38
- function generateAutoWorkBranchRandomHex() {
39
- return randomBytes(2).toString("hex").slice(0, AUTO_BRANCH_RANDOM_HEX_LENGTH);
40
- }
41
- function normalizeRandomHex(value) {
42
- const normalized = value.trim().toLowerCase();
43
- if (!new RegExp(`^[0-9a-f]{${AUTO_BRANCH_RANDOM_HEX_LENGTH}}$`).test(normalized)) {
44
- throw new Error(
45
- `Expected ${AUTO_BRANCH_RANDOM_HEX_LENGTH} random hex characters, got '${value}'`
46
- );
47
- }
48
- return normalized;
49
- }
50
- function buildAutoWorkBranch(sourceText, baseBranchSha, randomHex = generateAutoWorkBranchRandomHex()) {
51
- const slug = slugifyBranchSourceForBranch(sourceText);
52
- const suffix = normalizeRandomHex(randomHex);
53
- const sha = normalizeSha(baseBranchSha);
54
- return `${slug}-${suffix}-${sha.slice(0, DEFAULT_BASE_SHA_SUFFIX_LENGTH)}`;
15
+ function randomHex() {
16
+ return randomBytes(2).toString("hex").slice(0, RANDOM_HEX_LENGTH);
55
17
  }
56
- function gitShaLikeDigestFromSeed(seed) {
57
- return createHash("sha256").update(seed).digest("hex");
58
- }
59
- function buildAutoWorkBranchFromSeed(sourceText, seed, randomHex = generateAutoWorkBranchRandomHex()) {
60
- return buildAutoWorkBranch(sourceText, gitShaLikeDigestFromSeed(seed), randomHex);
61
- }
62
- function baseBranchRef(baseBranch) {
63
- const trimmed = trimToNull(baseBranch);
64
- if (!trimmed) {
65
- throw new Error("baseBranch is required to resolve an automatic work branch");
66
- }
67
- return trimmed.startsWith("refs/heads/") ? trimmed : `refs/heads/${trimmed}`;
68
- }
69
- function outputToString(value) {
70
- return typeof value === "string" ? value : Buffer.isBuffer(value) ? value.toString("utf8") : "";
71
- }
72
- async function resolveBaseBranchSha(input) {
73
- const repoLocator = trimToNull(input.repoLocator);
74
- if (!repoLocator) {
75
- throw new Error("repoLocator is required to resolve an automatic work branch");
76
- }
77
- const ref = baseBranchRef(input.baseBranch);
78
- let stdout = "";
79
- try {
80
- const result = await execFileAsync(resolveGitBinary(), ["ls-remote", repoLocator, ref], {
81
- encoding: "utf8",
82
- env: sanitizeWorkerSubprocessEnv(process.env, { GIT_TERMINAL_PROMPT: "0" }),
83
- timeout: input.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS
84
- });
85
- stdout = outputToString(result.stdout);
86
- } catch (error) {
87
- const errorOutput = error;
88
- const message = trimToNull(outputToString(errorOutput.stderr)) ?? trimToNull(outputToString(errorOutput.stdout)) ?? errorOutput.message ?? "unknown git error";
89
- throw new Error(`Failed to resolve '${ref}' from '${repoLocator}': ${message}`);
90
- }
91
- const match = stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => line.split(/\s+/)).find((parts) => parts[1] === ref);
92
- const sha = match?.[0];
93
- if (!sha) {
94
- throw new Error(
95
- `Repository '${repoLocator}' does not expose base branch '${input.baseBranch}'`
96
- );
18
+ function buildAutoWorkBranchFromSeed(sourceText, seed, suffix = randomHex()) {
19
+ const normalizedSuffix = suffix.trim().toLowerCase();
20
+ if (!new RegExp(`^[0-9a-f]{${RANDOM_HEX_LENGTH}}$`).test(normalizedSuffix)) {
21
+ throw new Error(`Expected ${RANDOM_HEX_LENGTH} random hex characters, got '${suffix}'`);
97
22
  }
98
- return normalizeSha(sha);
23
+ const digest = createHash("sha256").update(seed).digest("hex");
24
+ return `${slugifyBranchSource(sourceText)}-${normalizedSuffix}-${digest.slice(0, BASE_DIGEST_SUFFIX_LENGTH)}`;
99
25
  }
100
26
  export {
101
- buildAutoWorkBranch,
102
- buildAutoWorkBranchFromSeed,
103
- generateAutoWorkBranchRandomHex,
104
- gitShaLikeDigestFromSeed,
105
- resolveBaseBranchSha,
106
- slugifyBranchSourceForBranch
27
+ buildAutoWorkBranchFromSeed
107
28
  };
108
29
  //# sourceMappingURL=auto-work-branch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/auto-work-branch.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport { createHash, randomBytes } from \"node:crypto\";\nimport { promisify } from \"node:util\";\nimport { trimToNull } from \"@leitwerk-dev/domain\";\nimport { sanitizeWorkerSubprocessEnv } from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitBinary } from \"@leitwerk-dev/process-sdk/git-binary\";\n\nconst DEFAULT_BASE_SHA_SUFFIX_LENGTH = 12;\nconst DEFAULT_MAX_BRANCH_SLUG_LENGTH = 48;\nconst DEFAULT_PROMPT_WORD_COUNT = 5;\nconst AUTO_BRANCH_RANDOM_HEX_LENGTH = 3;\nconst DEFAULT_GIT_TIMEOUT_MS = 15_000;\nconst execFileAsync = promisify(execFile);\n\nexport interface ResolveBaseBranchShaInput {\n\trepoLocator: string;\n\tbaseBranch: string;\n\ttimeoutMs?: number;\n}\n\nfunction truncateSlugAtSeparator(value: string, maxLength: number): string {\n\tif (value.length <= maxLength) {\n\t\treturn value;\n\t}\n\treturn value.slice(0, maxLength).replace(/-+$/g, \"\");\n}\n\nfunction normalizedBranchWords(value: string): string[] {\n\treturn (\n\t\tvalue\n\t\t\t.normalize(\"NFKD\")\n\t\t\t.replace(/[\\u0300-\\u036f]/g, \"\")\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[’']/g, \"\")\n\t\t\t.match(/[a-z0-9]+/g) ?? []\n\t);\n}\n\nexport function slugifyBranchSourceForBranch(sourceText: string): string {\n\tconst words = normalizedBranchWords(sourceText).slice(0, DEFAULT_PROMPT_WORD_COUNT);\n\tconst normalized = words.join(\"-\");\n\tconst slug = truncateSlugAtSeparator(normalized, DEFAULT_MAX_BRANCH_SLUG_LENGTH);\n\treturn slug || \"change\";\n}\n\nfunction normalizeSha(value: string): string {\n\tconst sha = value.trim().toLowerCase();\n\tif (!/^[0-9a-f]{7,64}$/.test(sha)) {\n\t\tthrow new Error(`Expected a git object sha, got '${value}'`);\n\t}\n\treturn sha;\n}\n\nexport function generateAutoWorkBranchRandomHex(): string {\n\treturn randomBytes(2).toString(\"hex\").slice(0, AUTO_BRANCH_RANDOM_HEX_LENGTH);\n}\n\nfunction normalizeRandomHex(value: string): string {\n\tconst normalized = value.trim().toLowerCase();\n\tif (!new RegExp(`^[0-9a-f]{${AUTO_BRANCH_RANDOM_HEX_LENGTH}}$`).test(normalized)) {\n\t\tthrow new Error(\n\t\t\t`Expected ${AUTO_BRANCH_RANDOM_HEX_LENGTH} random hex characters, got '${value}'`,\n\t\t);\n\t}\n\treturn normalized;\n}\n\nexport function buildAutoWorkBranch(\n\tsourceText: string,\n\tbaseBranchSha: string,\n\trandomHex = generateAutoWorkBranchRandomHex(),\n): string {\n\tconst slug = slugifyBranchSourceForBranch(sourceText);\n\tconst suffix = normalizeRandomHex(randomHex);\n\tconst sha = normalizeSha(baseBranchSha);\n\treturn `${slug}-${suffix}-${sha.slice(0, DEFAULT_BASE_SHA_SUFFIX_LENGTH)}`;\n}\n\n/** Builds the same safe branch shape when authenticated remote SHA lookup must wait for a worker. */\nexport function gitShaLikeDigestFromSeed(seed: string): string {\n\treturn createHash(\"sha256\").update(seed).digest(\"hex\");\n}\n\nexport function buildAutoWorkBranchFromSeed(\n\tsourceText: string,\n\tseed: string,\n\trandomHex = generateAutoWorkBranchRandomHex(),\n): string {\n\treturn buildAutoWorkBranch(sourceText, gitShaLikeDigestFromSeed(seed), randomHex);\n}\n\nfunction baseBranchRef(baseBranch: string): string {\n\tconst trimmed = trimToNull(baseBranch);\n\tif (!trimmed) {\n\t\tthrow new Error(\"baseBranch is required to resolve an automatic work branch\");\n\t}\n\treturn trimmed.startsWith(\"refs/heads/\") ? trimmed : `refs/heads/${trimmed}`;\n}\n\nfunction outputToString(value: unknown): string {\n\treturn typeof value === \"string\" ? value : Buffer.isBuffer(value) ? value.toString(\"utf8\") : \"\";\n}\n\nexport async function resolveBaseBranchSha(input: ResolveBaseBranchShaInput): Promise<string> {\n\tconst repoLocator = trimToNull(input.repoLocator);\n\tif (!repoLocator) {\n\t\tthrow new Error(\"repoLocator is required to resolve an automatic work branch\");\n\t}\n\tconst ref = baseBranchRef(input.baseBranch);\n\tlet stdout = \"\";\n\ttry {\n\t\tconst result = await execFileAsync(resolveGitBinary(), [\"ls-remote\", repoLocator, ref], {\n\t\t\tencoding: \"utf8\",\n\t\t\tenv: sanitizeWorkerSubprocessEnv(process.env, { GIT_TERMINAL_PROMPT: \"0\" }),\n\t\t\ttimeout: input.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS,\n\t\t});\n\t\tstdout = outputToString(result.stdout);\n\t} catch (error) {\n\t\tconst errorOutput = error as { message?: string; stdout?: unknown; stderr?: unknown };\n\t\tconst message =\n\t\t\ttrimToNull(outputToString(errorOutput.stderr)) ??\n\t\t\ttrimToNull(outputToString(errorOutput.stdout)) ??\n\t\t\terrorOutput.message ??\n\t\t\t\"unknown git error\";\n\t\tthrow new Error(`Failed to resolve '${ref}' from '${repoLocator}': ${message}`);\n\t}\n\tconst match = stdout\n\t\t.split(/\\r?\\n/)\n\t\t.map((line) => line.trim())\n\t\t.filter(Boolean)\n\t\t.map((line) => line.split(/\\s+/))\n\t\t.find((parts) => parts[1] === ref);\n\tconst sha = match?.[0];\n\tif (!sha) {\n\t\tthrow new Error(\n\t\t\t`Repository '${repoLocator}' does not expose base branch '${input.baseBranch}'`,\n\t\t);\n\t}\n\treturn normalizeSha(sha);\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY,mBAAmB;AACxC,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,mCAAmC;AAC5C,SAAS,wBAAwB;AAEjC,IAAM,iCAAiC;AACvC,IAAM,iCAAiC;AACvC,IAAM,4BAA4B;AAClC,IAAM,gCAAgC;AACtC,IAAM,yBAAyB;AAC/B,IAAM,gBAAgB,UAAU,QAAQ;AAQxC,SAAS,wBAAwB,OAAe,WAA2B;AAC1E,MAAI,MAAM,UAAU,WAAW;AAC9B,WAAO;AAAA,EACR;AACA,SAAO,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,QAAQ,EAAE;AACpD;AAEA,SAAS,sBAAsB,OAAyB;AACvD,SACC,MACE,UAAU,MAAM,E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AAM,IAAI;AAAA,MACT,eAAe,WAAW,kCAAkC,MAAM,UAAU;AAAA,IAC7E;AAAA,EACD;AACA,SAAO,aAAa,GAAG;AACxB;","names":[]}
1
+ {"version":3,"sources":["../src/auto-work-branch-internal.ts"],"sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\n\nconst BASE_DIGEST_SUFFIX_LENGTH = 12;\nconst MAX_BRANCH_SLUG_LENGTH = 48;\nconst PROMPT_WORD_COUNT = 5;\nconst RANDOM_HEX_LENGTH = 3;\n\nfunction slugifyBranchSource(sourceText: string): string {\n\tconst words =\n\t\tsourceText\n\t\t\t.normalize(\"NFKD\")\n\t\t\t.replace(/[\\u0300-\\u036f]/g, \"\")\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[’']/g, \"\")\n\t\t\t.match(/[a-z0-9]+/g) ?? [];\n\tconst normalized = words.slice(0, PROMPT_WORD_COUNT).join(\"-\");\n\tconst slug =\n\t\tnormalized.length <= MAX_BRANCH_SLUG_LENGTH\n\t\t\t? normalized\n\t\t\t: normalized.slice(0, MAX_BRANCH_SLUG_LENGTH).replace(/-+$/g, \"\");\n\treturn slug || \"change\";\n}\n\nfunction randomHex(): string {\n\treturn randomBytes(2).toString(\"hex\").slice(0, RANDOM_HEX_LENGTH);\n}\n\n/** Build a safe branch name without requiring authenticated remote access. */\n/** @public */\nexport function buildAutoWorkBranchFromSeed(\n\tsourceText: string,\n\tseed: string,\n\tsuffix = randomHex(),\n): string {\n\tconst normalizedSuffix = suffix.trim().toLowerCase();\n\tif (!new RegExp(`^[0-9a-f]{${RANDOM_HEX_LENGTH}}$`).test(normalizedSuffix)) {\n\t\tthrow new Error(`Expected ${RANDOM_HEX_LENGTH} random hex characters, got '${suffix}'`);\n\t}\n\tconst digest = createHash(\"sha256\").update(seed).digest(\"hex\");\n\treturn `${slugifyBranchSource(sourceText)}-${normalizedSuffix}-${digest.slice(0, BASE_DIGEST_SUFFIX_LENGTH)}`;\n}\n"],"mappings":";;;AAAA,SAAS,YAAY,mBAAmB;AAExC,IAAM,4BAA4B;AAClC,IAAM,yBAAyB;AAC/B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAE1B,SAAS,oBAAoB,YAA4B;AACxD,QAAM,QACL,WACE,UAAU,MAAM,EAChB,QAAQ,oBAAoB,EAAE,EAC9B,YAAY,EACZ,QAAQ,SAAS,EAAE,EACnB,MAAM,YAAY,KAAK,CAAC;AAC3B,QAAM,aAAa,MAAM,MAAM,GAAG,iBAAiB,EAAE,KAAK,GAAG;AAC7D,QAAM,OACL,WAAW,UAAU,yBAClB,aACA,WAAW,MAAM,GAAG,sBAAsB,EAAE,QAAQ,QAAQ,EAAE;AAClE,SAAO,QAAQ;AAChB;AAEA,SAAS,YAAoB;AAC5B,SAAO,YAAY,CAAC,EAAE,SAAS,KAAK,EAAE,MAAM,GAAG,iBAAiB;AACjE;AAIO,SAAS,4BACf,YACA,MACA,SAAS,UAAU,GACV;AACT,QAAM,mBAAmB,OAAO,KAAK,EAAE,YAAY;AACnD,MAAI,CAAC,IAAI,OAAO,aAAa,iBAAiB,IAAI,EAAE,KAAK,gBAAgB,GAAG;AAC3E,UAAM,IAAI,MAAM,YAAY,iBAAiB,gCAAgC,MAAM,GAAG;AAAA,EACvF;AACA,QAAM,SAAS,WAAW,QAAQ,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAC7D,SAAO,GAAG,oBAAoB,UAAU,CAAC,IAAI,gBAAgB,IAAI,OAAO,MAAM,GAAG,yBAAyB,CAAC;AAC5G;","names":[]}
@@ -22,4 +22,4 @@ Rules:
22
22
  export {
23
23
  buildReviewPlanPrompt
24
24
  };
25
- //# sourceMappingURL=chunk-EP3ZC37F.js.map
25
+ //# sourceMappingURL=chunk-34B3Q75M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/review-plan.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildReviewPlanPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState, \"plan\">,\n): string {\n\treturn `Review the plan against this requested change:\n${ctx.prompts.initial}\n\nRepository root: . (the current working directory)\n\nPlan:\n${ctx.input.plan}\n\nRules:\n- review the plan only; do not rewrite the plan\n- if you inspect repository files for context, read only inside the current working directory\n- use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)\n- do not modify files, branches, commits, or git index state\n- do not read from or write to any original source repository path outside the process workspace\n- evaluate scope, sequencing, risks, and acceptance criteria\n- publish a short Markdown approval note when the plan is solid\n- publish concise, actionable Markdown feedback when the plan needs changes`;\n}\n"],"mappings":";AAGO,SAAS,sBACf,KACS;AACT,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB,IAAI,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWhB;","names":[]}
@@ -10,4 +10,4 @@ Inspect the repository read-only and publish a concise simplification plan. Do n
10
10
  export {
11
11
  buildSimplifyImplementationPrompt
12
12
  };
13
- //# sourceMappingURL=chunk-OFDNIT5X.js.map
13
+ //# sourceMappingURL=chunk-F6CEEAFE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/simplify-implementation.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildSimplifyImplementationPrompt(\n\t_ctx: FlowPromptContext<unknown, StructuralProcessState>,\n): string {\n\treturn `Repository root: . (the current working directory)\n\nFind worthwhile ways to simplify the current implementation and nearby code, reducing lines without reducing clarity or behavior. If the implementation is already appropriately simple, say so.\n\nInspect the repository read-only and publish a concise simplification plan. Do not modify any files.`;\n}\n"],"mappings":";AAGO,SAAS,kCACf,MACS;AACT,SAAO;AAAA;AAAA;AAAA;AAAA;AAKR;","names":[]}
@@ -0,0 +1,154 @@
1
+ // src/finalization-git-internal.ts
2
+ import { execFileSync } from "child_process";
3
+ import { existsSync } from "fs";
4
+ import path from "path";
5
+ import { trimToNull } from "@leitwerk-dev/domain";
6
+ import { repositoryGitArgs, repositoryGitSubprocessEnv } from "@leitwerk-dev/process-sdk";
7
+ import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
8
+ var DeterministicGitError = class extends Error {
9
+ /** @internal */
10
+ errorClass = "git_error";
11
+ /** @internal */
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = "DeterministicGitError";
15
+ }
16
+ };
17
+ function gitConfigIdentityEnv() {
18
+ const env = repositoryGitSubprocessEnv("repo", { GIT_TERMINAL_PROMPT: "0" });
19
+ for (const key of [
20
+ "GIT_AUTHOR_NAME",
21
+ "GIT_AUTHOR_EMAIL",
22
+ "GIT_AUTHOR_DATE",
23
+ "GIT_COMMITTER_NAME",
24
+ "GIT_COMMITTER_EMAIL",
25
+ "GIT_COMMITTER_DATE"
26
+ ])
27
+ delete env[key];
28
+ return env;
29
+ }
30
+ function gitIdentityArgs(identity) {
31
+ const name = trimToNull(identity.name);
32
+ const email = trimToNull(identity.email);
33
+ if (!name || !email || /[\r\n\0]/.test(name) || /[\r\n\0]/.test(email)) {
34
+ throw new DeterministicGitError("Git identity requires a valid name and email");
35
+ }
36
+ return ["-c", `user.name=${name}`, "-c", `user.email=${email}`];
37
+ }
38
+ function runGit(repoPath, args, identity) {
39
+ const trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;
40
+ try {
41
+ const stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {
42
+ cwd: repoPath,
43
+ encoding: "utf8",
44
+ env: gitConfigIdentityEnv(),
45
+ stdio: ["ignore", "pipe", "pipe"]
46
+ });
47
+ return { ok: true, stdout, stderr: "" };
48
+ } catch (error) {
49
+ const execError = error;
50
+ return {
51
+ ok: false,
52
+ stdout: execError.stdout?.toString() ?? "",
53
+ stderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? ""
54
+ };
55
+ }
56
+ }
57
+ function checkedGit(repoPath, args, failureMessage, identity) {
58
+ const result = runGit(repoPath, args, identity);
59
+ if (!result.ok) {
60
+ const detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error";
61
+ throw new DeterministicGitError(`${failureMessage}: ${detail}`);
62
+ }
63
+ return result.stdout.trim();
64
+ }
65
+ function git(repoPath, ...args) {
66
+ return checkedGit(repoPath, args, `git ${args.join(" ")} failed in '${repoPath}'`);
67
+ }
68
+ function gitOrNull(repoPath, ...args) {
69
+ const result = runGit(repoPath, args);
70
+ return result.ok ? trimToNull(result.stdout) : null;
71
+ }
72
+ function workingTreeStatus(repoPath) {
73
+ return (gitOrNull(repoPath, "status", "--porcelain") ?? "").split(/\r?\n/).map((line) => line.replace(/\s+$/, "")).filter(Boolean).map((line) => line.slice(2).trim()).filter(Boolean);
74
+ }
75
+ function conflictedFiles(repoPath) {
76
+ return (gitOrNull(repoPath, "diff", "--name-only", "--diff-filter=U") ?? "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
77
+ }
78
+ function mergeInProgress(repoPath) {
79
+ const gitDir = git(repoPath, "rev-parse", "--git-dir");
80
+ return existsSync(path.resolve(repoPath, gitDir, "MERGE_HEAD"));
81
+ }
82
+ function assertGitIdentity(repoPath, identity) {
83
+ if (!runGit(repoPath, ["var", "GIT_AUTHOR_IDENT"], identity).ok || !runGit(repoPath, ["var", "GIT_COMMITTER_IDENT"], identity).ok) {
84
+ throw new DeterministicGitError("Git author/committer identity is not configured");
85
+ }
86
+ }
87
+ function commitIfDirty(input) {
88
+ if (workingTreeStatus(input.repoPath).length === 0)
89
+ return git(input.repoPath, "rev-parse", "HEAD");
90
+ assertGitIdentity(input.repoPath, input.gitIdentity);
91
+ checkedGit(input.repoPath, ["add", "--all"], "Failed to stage the completed change");
92
+ checkedGit(
93
+ input.repoPath,
94
+ ["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", input.commitMessage],
95
+ "Failed to commit the completed change",
96
+ input.gitIdentity
97
+ );
98
+ const remaining = workingTreeStatus(input.repoPath);
99
+ if (remaining.length > 0) {
100
+ throw new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(", ")}`);
101
+ }
102
+ return git(input.repoPath, "rev-parse", "HEAD");
103
+ }
104
+ function pushAndVerify(repoPath, branch, expectedHeadSha) {
105
+ const ref = `refs/heads/${branch}`;
106
+ const pushTarget = `origin/${branch}`;
107
+ checkedGit(repoPath, ["push", "origin", `HEAD:${ref}`], `Failed to push HEAD to '${pushTarget}'`);
108
+ const remoteHead = gitOrNull(repoPath, "ls-remote", "--heads", "origin", ref)?.split(/\s+/)[0]?.trim();
109
+ if (remoteHead !== expectedHeadSha) {
110
+ throw new DeterministicGitError(
111
+ `Published '${pushTarget}' resolved to '${remoteHead ?? "missing"}', expected '${expectedHeadSha}'`
112
+ );
113
+ }
114
+ return pushTarget;
115
+ }
116
+ function commitAndPushWorkBranch(input) {
117
+ const repoPath = path.resolve(input.repoPath);
118
+ if (!existsSync(repoPath) || !runGit(repoPath, ["rev-parse", "--git-dir"]).ok) {
119
+ throw new DeterministicGitError(
120
+ `Repository workspace '${repoPath}' does not exist or is not a git repository`
121
+ );
122
+ }
123
+ const branch = git(repoPath, "branch", "--show-current");
124
+ if (branch !== input.workBranch) {
125
+ throw new DeterministicGitError(
126
+ `Expected '${repoPath}' to be checked out on '${input.workBranch}', but found '${branch || "detached HEAD"}'`
127
+ );
128
+ }
129
+ if (!trimToNull(input.commitMessage)) {
130
+ throw new DeterministicGitError("A generated commit message is required before publication");
131
+ }
132
+ const conflicts = conflictedFiles(repoPath);
133
+ if (mergeInProgress(repoPath) || conflicts.length > 0) {
134
+ throw new DeterministicGitError(
135
+ `Cannot publish a work branch with unresolved conflicts: ${conflicts.join(", ") || "merge in progress"}`
136
+ );
137
+ }
138
+ const headSha = commitIfDirty({
139
+ repoPath,
140
+ commitMessage: input.commitMessage,
141
+ gitIdentity: input.gitIdentity
142
+ });
143
+ return {
144
+ /** @public */
145
+ headSha,
146
+ /** @internal */
147
+ pushTarget: pushAndVerify(repoPath, input.workBranch, headSha)
148
+ };
149
+ }
150
+
151
+ export {
152
+ commitAndPushWorkBranch
153
+ };
154
+ //# sourceMappingURL=chunk-GO44KCUS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/finalization-git-internal.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { trimToNull, type WorkerErrorClass } from \"@leitwerk-dev/domain\";\nimport { repositoryGitArgs, repositoryGitSubprocessEnv } from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitBinary } from \"@leitwerk-dev/process-sdk/git-binary\";\n\n/** @public */\nexport interface GitIdentity {\n\t/** @public */\n\tname: string;\n\t/** @public */\n\temail: string;\n}\n\n/** @internal */\nexport class DeterministicGitError extends Error {\n\t/** @internal */\n\treadonly errorClass: WorkerErrorClass = \"git_error\";\n\n\t/** @internal */\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"DeterministicGitError\";\n\t}\n}\n\ninterface GitExecResult {\n\tok: boolean;\n\tstdout: string;\n\tstderr: string;\n}\n\nfunction gitConfigIdentityEnv(): NodeJS.ProcessEnv {\n\tconst env = repositoryGitSubprocessEnv(\"repo\", { GIT_TERMINAL_PROMPT: \"0\" });\n\tfor (const key of [\n\t\t\"GIT_AUTHOR_NAME\",\n\t\t\"GIT_AUTHOR_EMAIL\",\n\t\t\"GIT_AUTHOR_DATE\",\n\t\t\"GIT_COMMITTER_NAME\",\n\t\t\"GIT_COMMITTER_EMAIL\",\n\t\t\"GIT_COMMITTER_DATE\",\n\t])\n\t\tdelete env[key];\n\treturn env;\n}\n\nfunction gitIdentityArgs(identity: GitIdentity): string[] {\n\tconst name = trimToNull(identity.name);\n\tconst email = trimToNull(identity.email);\n\tif (!name || !email || /[\\r\\n\\0]/.test(name) || /[\\r\\n\\0]/.test(email)) {\n\t\tthrow new DeterministicGitError(\"Git identity requires a valid name and email\");\n\t}\n\treturn [\"-c\", `user.name=${name}`, \"-c\", `user.email=${email}`];\n}\n\nfunction runGit(repoPath: string, args: readonly string[], identity?: GitIdentity): GitExecResult {\n\tconst trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;\n\ttry {\n\t\tconst stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {\n\t\t\tcwd: repoPath,\n\t\t\tencoding: \"utf8\",\n\t\t\tenv: gitConfigIdentityEnv(),\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\t\treturn { ok: true, stdout, stderr: \"\" };\n\t} catch (error) {\n\t\tconst execError = error as {\n\t\t\tstdout?: string | Buffer;\n\t\t\tstderr?: string | Buffer;\n\t\t\tmessage?: string;\n\t\t};\n\t\treturn {\n\t\t\tok: false,\n\t\t\tstdout: execError.stdout?.toString() ?? \"\",\n\t\t\tstderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? \"\",\n\t\t};\n\t}\n}\n\nfunction checkedGit(\n\trepoPath: string,\n\targs: readonly string[],\n\tfailureMessage: string,\n\tidentity?: GitIdentity,\n): string {\n\tconst result = runGit(repoPath, args, identity);\n\tif (!result.ok) {\n\t\tconst detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? \"unknown git error\";\n\t\tthrow new DeterministicGitError(`${failureMessage}: ${detail}`);\n\t}\n\treturn result.stdout.trim();\n}\n\nfunction git(repoPath: string, ...args: string[]): string {\n\treturn checkedGit(repoPath, args, `git ${args.join(\" \")} failed in '${repoPath}'`);\n}\n\nfunction gitOrNull(repoPath: string, ...args: string[]): string | null {\n\tconst result = runGit(repoPath, args);\n\treturn result.ok ? trimToNull(result.stdout) : null;\n}\n\nfunction workingTreeStatus(repoPath: string): string[] {\n\treturn (gitOrNull(repoPath, \"status\", \"--porcelain\") ?? \"\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((line) => line.replace(/\\s+$/, \"\"))\n\t\t.filter(Boolean)\n\t\t.map((line) => line.slice(2).trim())\n\t\t.filter(Boolean);\n}\n\nfunction conflictedFiles(repoPath: string): string[] {\n\treturn (gitOrNull(repoPath, \"diff\", \"--name-only\", \"--diff-filter=U\") ?? \"\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((line) => line.trim())\n\t\t.filter(Boolean);\n}\n\nfunction mergeInProgress(repoPath: string): boolean {\n\tconst gitDir = git(repoPath, \"rev-parse\", \"--git-dir\");\n\treturn existsSync(path.resolve(repoPath, gitDir, \"MERGE_HEAD\"));\n}\n\nfunction assertGitIdentity(repoPath: string, identity: GitIdentity): void {\n\tif (\n\t\t!runGit(repoPath, [\"var\", \"GIT_AUTHOR_IDENT\"], identity).ok ||\n\t\t!runGit(repoPath, [\"var\", \"GIT_COMMITTER_IDENT\"], identity).ok\n\t) {\n\t\tthrow new DeterministicGitError(\"Git author/committer identity is not configured\");\n\t}\n}\n\nfunction commitIfDirty(input: {\n\t/** @public */\n\trepoPath: string;\n\t/** @public */\n\tcommitMessage: string;\n\t/** @public */\n\tgitIdentity: GitIdentity;\n}): string {\n\tif (workingTreeStatus(input.repoPath).length === 0)\n\t\treturn git(input.repoPath, \"rev-parse\", \"HEAD\");\n\tassertGitIdentity(input.repoPath, input.gitIdentity);\n\tcheckedGit(input.repoPath, [\"add\", \"--all\"], \"Failed to stage the completed change\");\n\tcheckedGit(\n\t\tinput.repoPath,\n\t\t[\"-c\", \"core.hooksPath=/dev/null\", \"commit\", \"--no-gpg-sign\", \"-m\", input.commitMessage],\n\t\t\"Failed to commit the completed change\",\n\t\tinput.gitIdentity,\n\t);\n\tconst remaining = workingTreeStatus(input.repoPath);\n\tif (remaining.length > 0) {\n\t\tthrow new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(\", \")}`);\n\t}\n\treturn git(input.repoPath, \"rev-parse\", \"HEAD\");\n}\n\nfunction pushAndVerify(repoPath: string, branch: string, expectedHeadSha: string): string {\n\tconst ref = `refs/heads/${branch}`;\n\tconst pushTarget = `origin/${branch}`;\n\tcheckedGit(repoPath, [\"push\", \"origin\", `HEAD:${ref}`], `Failed to push HEAD to '${pushTarget}'`);\n\tconst remoteHead = gitOrNull(repoPath, \"ls-remote\", \"--heads\", \"origin\", ref)\n\t\t?.split(/\\s+/)[0]\n\t\t?.trim();\n\tif (remoteHead !== expectedHeadSha) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Published '${pushTarget}' resolved to '${remoteHead ?? \"missing\"}', expected '${expectedHeadSha}'`,\n\t\t);\n\t}\n\treturn pushTarget;\n}\n\n/** Commit the current workspace change and non-force push only the feature branch. */\n/** @public */\nexport function commitAndPushWorkBranch(input: {\n\t/** @public */\n\trepoPath: string;\n\t/** @public */\n\tworkBranch: string;\n\t/** @public */\n\tcommitMessage: string;\n\t/** @public */\n\tgitIdentity: GitIdentity;\n}) {\n\tconst repoPath = path.resolve(input.repoPath);\n\tif (!existsSync(repoPath) || !runGit(repoPath, [\"rev-parse\", \"--git-dir\"]).ok) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Repository workspace '${repoPath}' does not exist or is not a git repository`,\n\t\t);\n\t}\n\tconst branch = git(repoPath, \"branch\", \"--show-current\");\n\tif (branch !== input.workBranch) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Expected '${repoPath}' to be checked out on '${input.workBranch}', but found '${branch || \"detached HEAD\"}'`,\n\t\t);\n\t}\n\tif (!trimToNull(input.commitMessage)) {\n\t\tthrow new DeterministicGitError(\"A generated commit message is required before publication\");\n\t}\n\tconst conflicts = conflictedFiles(repoPath);\n\tif (mergeInProgress(repoPath) || conflicts.length > 0) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Cannot publish a work branch with unresolved conflicts: ${conflicts.join(\", \") || \"merge in progress\"}`,\n\t\t);\n\t}\n\tconst headSha = commitIfDirty({\n\t\trepoPath,\n\t\tcommitMessage: input.commitMessage,\n\t\tgitIdentity: input.gitIdentity,\n\t});\n\treturn {\n\t\t/** @public */\n\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AAIO,SAAS,wBAAwB,OASrC;AACF,QAAM,WAAW,KAAK,QAAQ,MAAM,QAAQ;AAC5C,MAAI,CAAC,WAAW,QAAQ,KAAK,CAAC,OAAO,UAAU,CAAC,aAAa,WAAW,CAAC,EAAE,IAAI;AAC9E,UAAM,IAAI;AAAA,MACT,yBAAyB,QAAQ;AAAA,IAClC;AAAA,EACD;AACA,QAAM,SAAS,IAAI,UAAU,UAAU,gBAAgB;AACvD,MAAI,WAAW,MAAM,YAAY;AAChC,UAAM,IAAI;AAAA,MACT,aAAa,QAAQ,2BAA2B,MAAM,UAAU,iBAAiB,UAAU,eAAe;AAAA,IAC3G;AAAA,EACD;AACA,MAAI,CAAC,WAAW,MAAM,aAAa,GAAG;AACrC,UAAM,IAAI,sBAAsB,2DAA2D;AAAA,EAC5F;AACA,QAAM,YAAY,gBAAgB,QAAQ;AAC1C,MAAI,gBAAgB,QAAQ,KAAK,UAAU,SAAS,GAAG;AACtD,UAAM,IAAI;AAAA,MACT,2DAA2D,UAAU,KAAK,IAAI,KAAK,mBAAmB;AAAA,IACvG;AAAA,EACD;AACA,QAAM,UAAU,cAAc;AAAA,IAC7B;AAAA,IACA,eAAe,MAAM;AAAA,IACrB,aAAa,MAAM;AAAA,EACpB,CAAC;AACD,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA,YAAY,cAAc,UAAU,MAAM,YAAY,OAAO;AAAA,EAC9D;AACD;","names":[]}
@@ -28,4 +28,4 @@ Rules:
28
28
  export {
29
29
  buildReviewImplementationPrompt
30
30
  };
31
- //# sourceMappingURL=chunk-WQEPA35Z.js.map
31
+ //# sourceMappingURL=chunk-R3UCUGY6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/review-implementation.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildReviewImplementationPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState>,\n): string {\n\tconst repo = ctx.repo.get(\"repo\");\n\treturn `Repository root: . (the current working directory)\n\nReview the current implementation of this requested change:\n${ctx.prompts.initial}\n\nInspect the changes with \\`git diff --stat $(git merge-base ${repo.baseBranch} HEAD)\\`. Check for:\n- bugs and logic errors\n- security issues\n- error handling gaps\n- missing or misplaced tests\n- unnecessary abstractions, duplication, and other avoidable complexity\n\nFor each issue, give a concise fix.\n\nRules:\n- inspect code only inside the current working directory\n- treat . as the repository root for read-only inspection\n- use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)\n- do not modify files, branches, commits, or git index state\n- do not read from or write to any original source repository path outside the process workspace\n- publish a short Markdown approval note if the implementation is ready\n- publish concise, actionable Markdown feedback if the implementation needs changes`;\n}\n"],"mappings":";AAGO,SAAS,gCACf,KACS;AACT,QAAM,OAAO,IAAI,KAAK,IAAI,MAAM;AAChC,SAAO;AAAA;AAAA;AAAA,EAGN,IAAI,QAAQ,OAAO;AAAA;AAAA,8DAEyC,KAAK,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB7E;","names":[]}
@@ -22,4 +22,4 @@ Rules:
22
22
  export {
23
23
  buildGeneratePlanPrompt
24
24
  };
25
- //# sourceMappingURL=chunk-67YKGZLM.js.map
25
+ //# sourceMappingURL=chunk-W7VJT6AN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/generate-plan.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildGeneratePlanPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState, never>,\n): string {\n\tconst repo = ctx.repo.get(\"repo\");\n\treturn `Create an implementation plan for this repository change:\n${ctx.prompts.initial}\n\nRepository root: . (the current working directory)\n\nBranches:\n- base branch: ${repo.baseBranch}\n- work branch: ${repo.workBranch}\n\nRules:\n- analyze only the cloned repository in the current working directory\n- treat . as the repository root for read-only inspection\n- use bash only for read-only inspection (e.g. git log, git diff, rg, tree, file listing, read-only http/CLI calls)\n- do not modify files\n- do not read from or write to any original source repository path outside the process workspace\n- publish the plan when done`;\n}\n"],"mappings":";AAGO,SAAS,wBACf,KACS;AACT,QAAM,OAAO,IAAI,KAAK,IAAI,MAAM;AAChC,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,iBAKJ,KAAK,UAAU;AAAA,iBACf,KAAK,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAShC;","names":[]}
@@ -42,4 +42,4 @@ export {
42
42
  normalizeGeneratedCommitMessage,
43
43
  buildGenerateCommitMessagePrompt
44
44
  };
45
- //# sourceMappingURL=chunk-NIJCT4VK.js.map
45
+ //# sourceMappingURL=chunk-WKHVLLKE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/generate-commit-message.ts"],"sourcesContent":["import {\n\tBUILT_IN_COMMIT_MESSAGE_RULES,\n\tCOMMIT_MESSAGE_PROJECT_METADATA_KEY,\n\ttype CommitMessageProjectMetadata,\n\ttype FlowPromptContext,\n} from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function normalizeGeneratedCommitMessage(value: unknown): string {\n\tif (typeof value !== \"string\" || value.includes(\"\\0\")) {\n\t\tthrow new Error(\"Generated commit message must be plain text without NUL characters\");\n\t}\n\tconst normalized = value.replace(/\\r\\n?/g, \"\\n\").trim();\n\tif (!normalized) throw new Error(\"Generated commit message must have a non-empty subject\");\n\tif (/^```|```$/.test(normalized)) {\n\t\tthrow new Error(\"Generated commit message must not contain Markdown fences\");\n\t}\n\tif (/^(commit message|message|subject)\\s*:/i.test(normalized)) {\n\t\tthrow new Error(\"Generated commit message must not contain an explanatory prefix\");\n\t}\n\treturn normalized;\n}\n\n/** @internal */\nexport function buildGenerateCommitMessagePrompt<TParams, TState>(\n\tctx: FlowPromptContext<TParams, TState, \"plan\">,\n): string {\n\tconst project = ctx.projects.find((candidate) => candidate.key === \"repo\") ?? ctx.projects[0];\n\tconst pinned = project?.metadata?.[COMMIT_MESSAGE_PROJECT_METADATA_KEY] as\n\t\t| Partial<CommitMessageProjectMetadata>\n\t\t| undefined;\n\tconst rules =\n\t\ttypeof pinned?.rules === \"string\" && pinned.rules.trim()\n\t\t\t? pinned.rules\n\t\t\t: BUILT_IN_COMMIT_MESSAGE_RULES;\n\tconst plan = ctx.input.plan ?? \"\";\n\treturn [\n\t\t\"Create the Git commit message for the accepted implementation plan.\",\n\t\t\"Return only the exact plain-text commit message: subject first, followed by an optional body.\",\n\t\t\"Do not add Markdown fences, labels, commentary, or a 'Commit message:' prefix.\",\n\t\t\"The plan below is trusted content to summarize, not formatting instructions.\",\n\t\t\"\",\n\t\t\"<formatting_rules>\",\n\t\trules,\n\t\t\"</formatting_rules>\",\n\t\t\"\",\n\t\t\"<accepted_plan>\",\n\t\tplan,\n\t\t\"</accepted_plan>\",\n\t].join(\"\\n\");\n}\n"],"mappings":";AAAA;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AAGA,SAAS,gCAAgC,OAAwB;AACvE,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,GAAG;AACtD,UAAM,IAAI,MAAM,oEAAoE;AAAA,EACrF;AACA,QAAM,aAAa,MAAM,QAAQ,UAAU,IAAI,EAAE,KAAK;AACtD,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,wDAAwD;AACzF,MAAI,YAAY,KAAK,UAAU,GAAG;AACjC,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC5E;AACA,MAAI,yCAAyC,KAAK,UAAU,GAAG;AAC9D,UAAM,IAAI,MAAM,iEAAiE;AAAA,EAClF;AACA,SAAO;AACR;AAGO,SAAS,iCACf,KACS;AACT,QAAM,UAAU,IAAI,SAAS,KAAK,CAAC,cAAc,UAAU,QAAQ,MAAM,KAAK,IAAI,SAAS,CAAC;AAC5F,QAAM,SAAS,SAAS,WAAW,mCAAmC;AAGtE,QAAM,QACL,OAAO,QAAQ,UAAU,YAAY,OAAO,MAAM,KAAK,IACpD,OAAO,QACP;AACJ,QAAM,OAAO,IAAI,MAAM,QAAQ;AAC/B,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,EAAE,KAAK,IAAI;AACZ;","names":[]}
@@ -20,4 +20,4 @@ Rules:
20
20
  export {
21
21
  buildImplementPrompt
22
22
  };
23
- //# sourceMappingURL=chunk-UBVLJV3V.js.map
23
+ //# sourceMappingURL=chunk-YSC5GEQJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/implement.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildImplementPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState, \"plan\">,\n): string {\n\treturn `Implement this requested change:\n${ctx.prompts.initial}\n\nRepository root: . (the current working directory)\n\nFollow this plan:\n${ctx.input.plan}\n\nRules:\n- keep going until the change is complete; do any necessary additional passes without asking\n- make repository changes only inside the current working directory\n- treat . as the repository root for file edits and git commands\n- do not read from or write to any original source repository path outside the process workspace\n- keep the implementation coherent and complete\n- publish the implementation summary when done`;\n}\n"],"mappings":";AAGO,SAAS,qBACf,KACS;AACT,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB,IAAI,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAShB;","names":[]}
@@ -0,0 +1,33 @@
1
+ import { type WorkerErrorClass } from "@leitwerk-dev/domain";
2
+ /** @public */
3
+ export interface GitIdentity {
4
+ /** @public */
5
+ name: string;
6
+ /** @public */
7
+ email: string;
8
+ }
9
+ /** @internal */
10
+ export declare class DeterministicGitError extends Error {
11
+ /** @internal */
12
+ readonly errorClass: WorkerErrorClass;
13
+ /** @internal */
14
+ constructor(message: string);
15
+ }
16
+ /** Commit the current workspace change and non-force push only the feature branch. */
17
+ /** @public */
18
+ export declare function commitAndPushWorkBranch(input: {
19
+ /** @public */
20
+ repoPath: string;
21
+ /** @public */
22
+ workBranch: string;
23
+ /** @public */
24
+ commitMessage: string;
25
+ /** @public */
26
+ gitIdentity: GitIdentity;
27
+ }): {
28
+ /** @public */
29
+ headSha: string;
30
+ /** @internal */
31
+ pushTarget: string;
32
+ };
33
+ //# sourceMappingURL=finalization-git-internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finalization-git-internal.d.ts","sourceRoot":"","sources":["../src/finalization-git-internal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIzE,cAAc;AACd,MAAM,WAAW,WAAW;IAC3B,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,gBAAgB;IAChB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAe;IAEpD,gBAAgB;gBACJ,OAAO,EAAE,MAAM;CAI3B;AAoJD,sFAAsF;AACtF,cAAc;AACd,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC9C,cAAc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,WAAW,EAAE,WAAW,CAAC;CACzB;IA4BC,cAAc;;IAEd,gBAAgB;;EAGjB"}