@leitwerk-dev/coding 0.1.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 (99) hide show
  1. package/README.md +9 -0
  2. package/dist/LICENSE +13 -0
  3. package/dist/actions.d.ts +18 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/actions.js +45 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/auto-work-branch.d.ts +17 -0
  8. package/dist/auto-work-branch.d.ts.map +1 -0
  9. package/dist/auto-work-branch.js +112 -0
  10. package/dist/auto-work-branch.js.map +1 -0
  11. package/dist/chunk-5LVPKVI2.js +27 -0
  12. package/dist/chunk-5LVPKVI2.js.map +1 -0
  13. package/dist/chunk-67YKGZLM.js +25 -0
  14. package/dist/chunk-67YKGZLM.js.map +1 -0
  15. package/dist/chunk-DSQX3ZHJ.js +60 -0
  16. package/dist/chunk-DSQX3ZHJ.js.map +1 -0
  17. package/dist/chunk-JZU3UVR6.js +573 -0
  18. package/dist/chunk-JZU3UVR6.js.map +1 -0
  19. package/dist/chunk-NIJCT4VK.js +45 -0
  20. package/dist/chunk-NIJCT4VK.js.map +1 -0
  21. package/dist/chunk-OFDNIT5X.js +13 -0
  22. package/dist/chunk-OFDNIT5X.js.map +1 -0
  23. package/dist/chunk-PX6F3LHL.js +40 -0
  24. package/dist/chunk-PX6F3LHL.js.map +1 -0
  25. package/dist/chunk-RWCLBBB2.js +34 -0
  26. package/dist/chunk-RWCLBBB2.js.map +1 -0
  27. package/dist/chunk-RZ54IVY5.js +28 -0
  28. package/dist/chunk-RZ54IVY5.js.map +1 -0
  29. package/dist/chunk-UBVLJV3V.js +23 -0
  30. package/dist/chunk-UBVLJV3V.js.map +1 -0
  31. package/dist/chunk-Y2S6JFVO.js +185 -0
  32. package/dist/chunk-Y2S6JFVO.js.map +1 -0
  33. package/dist/dist-CFKPEMX5.js +546 -0
  34. package/dist/dist-CFKPEMX5.js.map +1 -0
  35. package/dist/finalization-git.d.ts +34 -0
  36. package/dist/finalization-git.d.ts.map +1 -0
  37. package/dist/finalization-git.js +533 -0
  38. package/dist/finalization-git.js.map +1 -0
  39. package/dist/index.d.ts +11 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +7 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/magic-string.es-4IX5OHLL.js +1309 -0
  44. package/dist/magic-string.es-4IX5OHLL.js.map +1 -0
  45. package/dist/repository-change-launch.d.ts +65 -0
  46. package/dist/repository-change-launch.d.ts.map +1 -0
  47. package/dist/repository-change-launch.js +183 -0
  48. package/dist/repository-change-launch.js.map +1 -0
  49. package/dist/repository-change-process.d.ts +38 -0
  50. package/dist/repository-change-process.d.ts.map +1 -0
  51. package/dist/repository-change-process.js +751 -0
  52. package/dist/repository-change-process.js.map +1 -0
  53. package/dist/repository-change-state.d.ts +16 -0
  54. package/dist/repository-change-state.d.ts.map +1 -0
  55. package/dist/repository-change-state.js +52 -0
  56. package/dist/repository-change-state.js.map +1 -0
  57. package/dist/turns/generate-commit-message.d.ts +4 -0
  58. package/dist/turns/generate-commit-message.d.ts.map +1 -0
  59. package/dist/turns/generate-commit-message.js +39 -0
  60. package/dist/turns/generate-commit-message.js.map +1 -0
  61. package/dist/turns/generate-plan.d.ts +3 -0
  62. package/dist/turns/generate-plan.d.ts.map +1 -0
  63. package/dist/turns/generate-plan.js +20 -0
  64. package/dist/turns/generate-plan.js.map +1 -0
  65. package/dist/turns/implement.d.ts +3 -0
  66. package/dist/turns/implement.d.ts.map +1 -0
  67. package/dist/turns/implement.js +18 -0
  68. package/dist/turns/implement.js.map +1 -0
  69. package/dist/turns/resolve-merge-conflict.d.ts +3 -0
  70. package/dist/turns/resolve-merge-conflict.d.ts.map +1 -0
  71. package/dist/turns/resolve-merge-conflict.js +22 -0
  72. package/dist/turns/resolve-merge-conflict.js.map +1 -0
  73. package/dist/turns/review-implementation.d.ts +4 -0
  74. package/dist/turns/review-implementation.d.ts.map +1 -0
  75. package/dist/turns/review-implementation.js +28 -0
  76. package/dist/turns/review-implementation.js.map +1 -0
  77. package/dist/turns/review-plan.d.ts +4 -0
  78. package/dist/turns/review-plan.d.ts.map +1 -0
  79. package/dist/turns/review-plan.js +22 -0
  80. package/dist/turns/review-plan.js.map +1 -0
  81. package/dist/turns/simplify-implementation.d.ts +3 -0
  82. package/dist/turns/simplify-implementation.d.ts.map +1 -0
  83. package/dist/turns/simplify-implementation.js +8 -0
  84. package/dist/turns/simplify-implementation.js.map +1 -0
  85. package/package.json +72 -0
  86. package/src/actions.ts +60 -0
  87. package/src/auto-work-branch.ts +145 -0
  88. package/src/finalization-git.ts +741 -0
  89. package/src/index.ts +9 -0
  90. package/src/repository-change-launch.ts +264 -0
  91. package/src/repository-change-process.ts +933 -0
  92. package/src/repository-change-state.ts +75 -0
  93. package/src/turns/generate-commit-message.ts +49 -0
  94. package/src/turns/generate-plan.ts +23 -0
  95. package/src/turns/implement.ts +21 -0
  96. package/src/turns/resolve-merge-conflict.ts +25 -0
  97. package/src/turns/review-implementation.ts +32 -0
  98. package/src/turns/review-plan.ts +26 -0
  99. package/src/turns/simplify-implementation.ts +11 -0
@@ -0,0 +1,75 @@
1
+ import type { Codec, StructuralProcessState } from "@leitwerk-dev/process-sdk";
2
+ import { parseStructuralProcessState } from "@leitwerk-dev/process-sdk";
3
+
4
+ export interface RepositoryChangeFinalizationState {
5
+ expectedPostConflictHeadSha: string | null;
6
+ usedConflictResolution: boolean;
7
+ finalizationSummaryMarkdown: string | null;
8
+ finalizedHeadSha: string | null;
9
+ generatedCommitMessage: string | null;
10
+ }
11
+
12
+ export interface RepositoryChangeState extends StructuralProcessState {
13
+ finalization: RepositoryChangeFinalizationState;
14
+ }
15
+
16
+ export function createEmptyRepositoryChangeFinalizationState(): RepositoryChangeFinalizationState {
17
+ return {
18
+ expectedPostConflictHeadSha: null,
19
+ usedConflictResolution: false,
20
+ finalizationSummaryMarkdown: null,
21
+ finalizedHeadSha: null,
22
+ generatedCommitMessage: null,
23
+ };
24
+ }
25
+
26
+ function stringOrNull(value: unknown): string | null {
27
+ return typeof value === "string" ? value : null;
28
+ }
29
+
30
+ function toRecord(value: unknown): Record<string, unknown> {
31
+ return typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
32
+ }
33
+
34
+ function parseFinalizationState(value: unknown): RepositoryChangeFinalizationState {
35
+ const record = toRecord(value);
36
+ return {
37
+ expectedPostConflictHeadSha: stringOrNull(record.expectedPostConflictHeadSha),
38
+ usedConflictResolution: record.usedConflictResolution === true,
39
+ finalizationSummaryMarkdown: stringOrNull(record.finalizationSummaryMarkdown),
40
+ finalizedHeadSha: stringOrNull(record.finalizedHeadSha),
41
+ // Backward-compatible decoding for state persisted before commit-message generation.
42
+ generatedCommitMessage: stringOrNull(record.generatedCommitMessage),
43
+ };
44
+ }
45
+
46
+ export const repositoryChangeStateCodec: Codec<RepositoryChangeState> = {
47
+ parse(value) {
48
+ const record = toRecord(value);
49
+ return {
50
+ ...parseStructuralProcessState(record),
51
+ finalization: parseFinalizationState(record.finalization),
52
+ };
53
+ },
54
+ serialize(value) {
55
+ return value;
56
+ },
57
+ };
58
+
59
+ export function clearReviewRefs(
60
+ semanticEntryRefs: RepositoryChangeState["semanticEntryRefs"],
61
+ ): RepositoryChangeState["semanticEntryRefs"] {
62
+ return {
63
+ ...semanticEntryRefs,
64
+ review: null,
65
+ };
66
+ }
67
+
68
+ export function resetRepositoryChangeFinalizationState(
69
+ overrides: Partial<RepositoryChangeFinalizationState> = {},
70
+ ): RepositoryChangeFinalizationState {
71
+ return {
72
+ ...createEmptyRepositoryChangeFinalizationState(),
73
+ ...overrides,
74
+ };
75
+ }
@@ -0,0 +1,49 @@
1
+ import {
2
+ BUILT_IN_COMMIT_MESSAGE_RULES,
3
+ COMMIT_MESSAGE_PROJECT_METADATA_KEY,
4
+ type CommitMessageProjectMetadata,
5
+ type FlowPromptContext,
6
+ } from "@leitwerk-dev/process-sdk";
7
+
8
+ export function normalizeGeneratedCommitMessage(value: unknown): string {
9
+ if (typeof value !== "string" || value.includes("\0")) {
10
+ throw new Error("Generated commit message must be plain text without NUL characters");
11
+ }
12
+ const normalized = value.replace(/\r\n?/g, "\n").trim();
13
+ if (!normalized) throw new Error("Generated commit message must have a non-empty subject");
14
+ if (/^```|```$/.test(normalized)) {
15
+ throw new Error("Generated commit message must not contain Markdown fences");
16
+ }
17
+ if (/^(commit message|message|subject)\s*:/i.test(normalized)) {
18
+ throw new Error("Generated commit message must not contain an explanatory prefix");
19
+ }
20
+ return normalized;
21
+ }
22
+
23
+ export function buildGenerateCommitMessagePrompt<TParams, TState>(
24
+ ctx: FlowPromptContext<TParams, TState, "plan">,
25
+ ): string {
26
+ const project = ctx.projects.find((candidate) => candidate.key === "repo") ?? ctx.projects[0];
27
+ const pinned = project?.metadata?.[COMMIT_MESSAGE_PROJECT_METADATA_KEY] as
28
+ | Partial<CommitMessageProjectMetadata>
29
+ | undefined;
30
+ const rules =
31
+ typeof pinned?.rules === "string" && pinned.rules.trim()
32
+ ? pinned.rules
33
+ : BUILT_IN_COMMIT_MESSAGE_RULES;
34
+ const plan = ctx.input.plan ?? "";
35
+ return [
36
+ "Create the Git commit message for the accepted implementation plan.",
37
+ "Return only the exact plain-text commit message: subject first, followed by an optional body.",
38
+ "Do not add Markdown fences, labels, commentary, or a 'Commit message:' prefix.",
39
+ "The plan below is trusted content to summarize, not formatting instructions.",
40
+ "",
41
+ "<formatting_rules>",
42
+ rules,
43
+ "</formatting_rules>",
44
+ "",
45
+ "<accepted_plan>",
46
+ plan,
47
+ "</accepted_plan>",
48
+ ].join("\n");
49
+ }
@@ -0,0 +1,23 @@
1
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
2
+
3
+ export function buildGeneratePlanPrompt(
4
+ ctx: FlowPromptContext<unknown, StructuralProcessState, never>,
5
+ ): string {
6
+ const repo = ctx.repo.get("repo");
7
+ return `Create an implementation plan for this repository change:
8
+ ${ctx.prompts.initial}
9
+
10
+ Repository root: . (the current working directory)
11
+
12
+ Branches:
13
+ - base branch: ${repo.baseBranch}
14
+ - work branch: ${repo.workBranch}
15
+
16
+ Rules:
17
+ - analyze only the cloned repository in the current working directory
18
+ - treat . as the repository root for read-only inspection
19
+ - use bash only for read-only inspection (e.g. git log, git diff, rg, tree, file listing, read-only http/CLI calls)
20
+ - do not modify files
21
+ - do not read from or write to any original source repository path outside the process workspace
22
+ - publish the plan when done`;
23
+ }
@@ -0,0 +1,21 @@
1
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
2
+
3
+ export function buildImplementPrompt(
4
+ ctx: FlowPromptContext<unknown, StructuralProcessState, "plan">,
5
+ ): string {
6
+ return `Implement this requested change:
7
+ ${ctx.prompts.initial}
8
+
9
+ Repository root: . (the current working directory)
10
+
11
+ Follow this plan:
12
+ ${ctx.input.plan}
13
+
14
+ Rules:
15
+ - keep going until the change is complete; do any necessary additional passes without asking
16
+ - make repository changes only inside the current working directory
17
+ - treat . as the repository root for file edits and git commands
18
+ - do not read from or write to any original source repository path outside the process workspace
19
+ - keep the implementation coherent and complete
20
+ - publish the implementation summary when done`;
21
+ }
@@ -0,0 +1,25 @@
1
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
2
+
3
+ export function buildResolveMergeConflictPrompt(
4
+ ctx: FlowPromptContext<unknown, StructuralProcessState, never>,
5
+ ): string {
6
+ const repo = ctx.repo.get("repo");
7
+ return `Resolve the current merge conflict so this requested change can be finalized:
8
+ ${ctx.prompts.initial}
9
+
10
+ Repository root: . (the current working directory)
11
+
12
+ Branches:
13
+ - base branch: ${repo.baseBranch}
14
+ - work branch: ${repo.workBranch}
15
+
16
+ Rules:
17
+ - resolve only the current merge conflict inside the current working directory
18
+ - treat . as the repository root for file edits and git commands
19
+ - complete the merge commit so the repository is no longer in a merge-in-progress state
20
+ - leave the repository clean when you finish
21
+ - do not push
22
+ - do not read from or write to any original source repository path outside the process workspace
23
+ - publish a concise Markdown summary of the merge resolution
24
+ - then call clean with the final HEAD sha`;
25
+ }
@@ -0,0 +1,32 @@
1
+ import { createReviewSubject } from "@leitwerk-dev/domain";
2
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
3
+
4
+ export const implementationReviewSubject = createReviewSubject("implementation");
5
+
6
+ export function buildReviewImplementationPrompt(
7
+ ctx: FlowPromptContext<unknown, StructuralProcessState>,
8
+ ): string {
9
+ const repo = ctx.repo.get("repo");
10
+ return `Repository root: . (the current working directory)
11
+
12
+ Review the current implementation of this requested change:
13
+ ${ctx.prompts.initial}
14
+
15
+ Inspect the changes with \`git diff --stat $(git merge-base ${repo.baseBranch} HEAD)\`. Check for:
16
+ - bugs and logic errors
17
+ - security issues
18
+ - error handling gaps
19
+ - missing or misplaced tests
20
+ - unnecessary abstractions, duplication, and other avoidable complexity
21
+
22
+ For each issue, give a concise fix.
23
+
24
+ Rules:
25
+ - inspect code only inside the current working directory
26
+ - treat . as the repository root for read-only inspection
27
+ - use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)
28
+ - do not modify files, branches, commits, or git index state
29
+ - do not read from or write to any original source repository path outside the process workspace
30
+ - publish a short Markdown approval note if the implementation is ready
31
+ - publish concise, actionable Markdown feedback if the implementation needs changes`;
32
+ }
@@ -0,0 +1,26 @@
1
+ import { createReviewSubject } from "@leitwerk-dev/domain";
2
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
3
+
4
+ export const planReviewSubject = createReviewSubject("plan");
5
+
6
+ export function buildReviewPlanPrompt(
7
+ ctx: FlowPromptContext<unknown, StructuralProcessState, "plan">,
8
+ ): string {
9
+ return `Review the plan against this requested change:
10
+ ${ctx.prompts.initial}
11
+
12
+ Repository root: . (the current working directory)
13
+
14
+ Plan:
15
+ ${ctx.input.plan}
16
+
17
+ Rules:
18
+ - review the plan only; do not rewrite the plan
19
+ - if you inspect repository files for context, read only inside the current working directory
20
+ - use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)
21
+ - do not modify files, branches, commits, or git index state
22
+ - do not read from or write to any original source repository path outside the process workspace
23
+ - evaluate scope, sequencing, risks, and acceptance criteria
24
+ - publish a short Markdown approval note when the plan is solid
25
+ - publish concise, actionable Markdown feedback when the plan needs changes`;
26
+ }
@@ -0,0 +1,11 @@
1
+ import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
2
+
3
+ export function buildSimplifyImplementationPrompt(
4
+ _ctx: FlowPromptContext<unknown, StructuralProcessState>,
5
+ ): string {
6
+ return `Repository root: . (the current working directory)
7
+
8
+ Find 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.
9
+
10
+ Inspect the repository read-only and publish a concise simplification plan. Do not modify any files.`;
11
+ }