@leitwerk-dev/coding 0.3.1 → 0.4.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 +154 -13
- package/dist/chunk-3WJRJ3Q7.js +220 -0
- package/dist/chunk-3WJRJ3Q7.js.map +1 -0
- package/dist/chunk-ABQH2WZT.js +36 -0
- package/dist/chunk-ABQH2WZT.js.map +1 -0
- package/dist/chunk-B3PE6DPF.js +820 -0
- package/dist/chunk-B3PE6DPF.js.map +1 -0
- package/dist/chunk-DNG7D77K.js +65 -0
- package/dist/chunk-DNG7D77K.js.map +1 -0
- package/dist/chunk-E3DB4TIZ.js +49 -0
- package/dist/chunk-E3DB4TIZ.js.map +1 -0
- package/dist/chunk-L2TFD72B.js +16320 -0
- package/dist/chunk-L2TFD72B.js.map +1 -0
- package/dist/chunk-M2VTUPFO.js +265 -0
- package/dist/chunk-M2VTUPFO.js.map +1 -0
- package/dist/{chunk-YSC5GEQJ.js → chunk-QD6FI4HR.js} +7 -3
- package/dist/chunk-QD6FI4HR.js.map +1 -0
- package/dist/chunk-SKGB4CZS.js +14 -0
- package/dist/chunk-SKGB4CZS.js.map +1 -0
- package/dist/chunk-SZ4WOGV2.js +120 -0
- package/dist/chunk-SZ4WOGV2.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +9 -0
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.d.ts +1 -1
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +6 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -591
- package/dist/index.js.map +1 -1
- package/dist/pull-request-publication-internal.d.ts +34 -24
- package/dist/pull-request-publication-internal.d.ts.map +1 -1
- package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
- package/dist/repository-change-launch-internal.d.ts +32 -11
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -3
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +162 -34
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
- package/dist/repository-change-process.d.ts +30 -25
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +76 -7
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +624 -136
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-change-state-internal.d.ts +18 -4
- package/dist/repository-change-state-internal.d.ts.map +1 -1
- package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
- package/dist/repository-publication-receipt.d.ts +23 -0
- package/dist/repository-publication-receipt.d.ts.map +1 -0
- package/dist/repository-rebase/git.d.ts +8 -0
- package/dist/repository-rebase/git.d.ts.map +1 -1
- package/dist/repository-reconciliation.d.ts +47 -0
- package/dist/repository-reconciliation.d.ts.map +1 -0
- package/dist/repository-record.d.ts +6 -0
- package/dist/repository-record.d.ts.map +1 -0
- package/dist/settings.d.ts +15 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.d.ts +35 -0
- package/dist/turns/commit-message-evidence.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.js +9 -0
- package/dist/turns/generate-commit-message.d.ts +4 -1
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +7 -5
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/git-inspection-profile.d.ts +25 -0
- package/dist/turns/git-inspection-profile.d.ts.map +1 -0
- package/dist/turns/git-inspection-profile.js +8 -0
- package/dist/turns/implement.d.ts +1 -1
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -1
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +3 -3
- package/package.json +5 -9
- package/src/finalization-git-internal.ts +186 -114
- package/src/finalization-git.ts +1 -1
- package/src/index.ts +4 -1
- package/src/pull-request-publication-internal.ts +158 -79
- package/src/repository-change-launch-internal.ts +119 -12
- package/src/repository-change-launch.ts +8 -4
- package/src/repository-change-process.ts +252 -524
- package/src/repository-change-publication.ts +702 -121
- package/src/repository-change-state-internal.ts +34 -20
- package/src/repository-change-ui-launcher-internal.ts +139 -56
- package/src/repository-publication-receipt.ts +71 -0
- package/src/repository-rebase/git.ts +108 -29
- package/src/repository-reconciliation.ts +600 -0
- package/src/repository-record.ts +14 -0
- package/src/settings.ts +79 -0
- package/src/turns/commit-message-evidence.ts +241 -0
- package/src/turns/generate-commit-message.ts +53 -23
- package/src/turns/generate-plan.ts +26 -12
- package/src/turns/git-inspection-profile.ts +134 -0
- package/src/turns/implement.ts +13 -3
- package/src/turns/simplify-implementation.ts +10 -6
- package/dist/chunk-34B3Q75M.js +0 -25
- package/dist/chunk-34B3Q75M.js.map +0 -1
- package/dist/chunk-F6CEEAFE.js +0 -13
- package/dist/chunk-F6CEEAFE.js.map +0 -1
- package/dist/chunk-GO44KCUS.js +0 -154
- package/dist/chunk-GO44KCUS.js.map +0 -1
- package/dist/chunk-R3UCUGY6.js +0 -31
- package/dist/chunk-R3UCUGY6.js.map +0 -1
- package/dist/chunk-W7VJT6AN.js +0 -25
- package/dist/chunk-W7VJT6AN.js.map +0 -1
- package/dist/chunk-WKHVLLKE.js +0 -45
- package/dist/chunk-WKHVLLKE.js.map +0 -1
- package/dist/chunk-YSC5GEQJ.js.map +0 -1
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
- package/dist/turns/review-implementation.d.ts +0 -4
- package/dist/turns/review-implementation.d.ts.map +0 -1
- package/dist/turns/review-implementation.js +0 -8
- package/dist/turns/review-plan.d.ts +0 -4
- package/dist/turns/review-plan.d.ts.map +0 -1
- package/dist/turns/review-plan.js +0 -8
- package/src/turns/review-implementation.ts +0 -30
- package/src/turns/review-plan.ts +0 -24
- /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
- /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
package/README.md
CHANGED
|
@@ -4,21 +4,116 @@ Shared repository-change planning, review, implementation, state, commit-message
|
|
|
4
4
|
|
|
5
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Before first publication, `generate_commit_message` consumes the durable accepted
|
|
8
|
+
`plan` and latest `implementation-summary`. Preparation captures each repository's
|
|
9
|
+
HEAD, Git status, staged and unstaged diffs, and untracked filenames without changing
|
|
10
|
+
the checkout. Evidence is bounded to fit a preparation checkpoint and marks truncated
|
|
11
|
+
fields. The model can inspect relevant files with Pi's read-only `read`, `grep`,
|
|
12
|
+
`find`, and `ls` tools; it cannot run shell commands or modify files. Messages describe
|
|
13
|
+
the implemented change, using the plan for intent and the launch-pinned formatting
|
|
14
|
+
rules. The turn uses the `coding.implementation` model purpose and persists normalized
|
|
15
|
+
plain-text messages by project in `finalization.commitMessages`. Deliver then commits,
|
|
16
|
+
pushes, and publishes. Publication fragments also accept the legacy
|
|
17
|
+
`generatedCommitMessage` for resumed processes.
|
|
18
|
+
|
|
19
|
+
Each Git inspection command has a 60-second deadline by default. Configure
|
|
20
|
+
`coding.commit_message_git_timeout_ms` in Settings at the Instance or Repository
|
|
21
|
+
scope to override it without restarting. The value is a positive integer in
|
|
22
|
+
milliseconds, up to 2147483647. A new turn start or operator retry captures the
|
|
23
|
+
value; worker recovery retains it. Multi-repository processes use their primary
|
|
24
|
+
repository's value, or the Instance value when no primary repository is bound.
|
|
25
|
+
Historical starts without this setting use the 60-second default. A timeout fails
|
|
26
|
+
preparation and reports the repository, Git command, and configured deadline.
|
|
27
|
+
|
|
28
|
+
Inspection refreshes a temporary copy of each repository's index and reuses that
|
|
29
|
+
cache across commands. The checkout's index and staged changes remain intact.
|
|
30
|
+
Worker diagnostics record each command's duration and outcome, with bounded Git
|
|
31
|
+
Trace2 counters for metadata checks, content scans, and inspection phases. Raw
|
|
32
|
+
Trace2 events, file contents, and paths are not stored in these diagnostics.
|
|
33
|
+
|
|
34
|
+
`commitAndPushWorkBranch()` requires an explicit trusted Git identity, commits dirty workspace files, and pushes only the checked-out feature branch. Ordinary publication must retain the captured remote head as an ancestor. An exact-SHA lease also rejects concurrent rewinds; a successful push with a lost acknowledgement is recognized without another commit. Invalid identity, unresolved conflicts, branch mismatches and changed remote heads fail without discarding the local commit.
|
|
10
35
|
|
|
11
36
|
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
37
|
|
|
38
|
+
## Planning contract
|
|
39
|
+
|
|
40
|
+
All consumers of the shared planner inspect relevant code, repository guidance,
|
|
41
|
+
dependency contracts, and external references before choosing the implementation.
|
|
42
|
+
A successful plan resolves questions affecting correctness, compatibility, and
|
|
43
|
+
feasibility, including access to required evidence. Material operator decisions
|
|
44
|
+
use `ask_questions` after discoverable facts are exhausted when the owning process
|
|
45
|
+
enables questions. When disabled, the planner decides from the requirement and
|
|
46
|
+
evidence, records minimal assumptions, and keeps the requested scope. Inaccessible
|
|
47
|
+
required evidence uses `abort_turn` with the resource, observed failure, and access needed;
|
|
48
|
+
the turn remains in error without publishing a successful plan or advancing.
|
|
49
|
+
|
|
50
|
+
Plans use **Findings and decisions**, **Changes**, and **Validation**, targeting
|
|
51
|
+
150–300 words for straightforward tickets and adding detail as complexity requires.
|
|
52
|
+
They record established decisions, concrete edits, and grouped validation checks.
|
|
53
|
+
`plan_saved` saves the finished plan with a one-sentence `summary` and
|
|
54
|
+
`acceptanceCriteria` limited to the requested outcomes. Approval and recovery use
|
|
55
|
+
the existing process flow.
|
|
56
|
+
|
|
13
57
|
## Shared publication
|
|
14
58
|
|
|
15
|
-
`createRepositoryChangePublication()`
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Forgejo retains its
|
|
59
|
+
`createRepositoryChangePublication()` builds shared delivery, feedback, CI/rebase
|
|
60
|
+
repair, and operator turns for Forgejo, GitHub, and GitLab. Adapters supply provider
|
|
61
|
+
operations, evidence sources, repair tools/prompts, and pinned identities.
|
|
62
|
+
`sourceCancelled`, `reconcileAll`, and `reconcileTerminal` receive
|
|
63
|
+
`PublicationReconciliationContext`: process, projects, params, state, and integration
|
|
64
|
+
calls, without worker filesystem access. Cursors and receipts remain namespaced;
|
|
65
|
+
Forgejo retains its namespace, turn/action IDs, and write identities.
|
|
66
|
+
|
|
67
|
+
## Source-branch reconciliation
|
|
68
|
+
|
|
69
|
+
The remote source branch is authoritative. Implementation preparation captures the
|
|
70
|
+
local baseline before editing. Feedback and CI preparation fetch the current source
|
|
71
|
+
branch; delivery fetches again before publication. Observed revisions and historical
|
|
72
|
+
publication receipts are separate from the baseline for unpublished local work.
|
|
73
|
+
A developer push or rewritten history does not disable feedback handling.
|
|
74
|
+
|
|
75
|
+
Reconciliation replays only the local work since that baseline onto the current
|
|
76
|
+
remote revision. Previously published commits removed by a developer rewrite are
|
|
77
|
+
not restored. Unpublished commits, staged and unstaged edits, and non-ignored
|
|
78
|
+
untracked files survive synchronization. Dirty submodules, ignored-file collisions,
|
|
79
|
+
missing published branches, unrelated Git operations and unprovable baselines stop
|
|
80
|
+
with an explicit error rather than guessing or discarding files. Fetch and push must
|
|
81
|
+
use the same single origin endpoint. Previously ignored files are protected from
|
|
82
|
+
accidental publication if ignore rules change.
|
|
83
|
+
|
|
84
|
+
Before changing the checkout, private Git refs retain the original HEAD and separate
|
|
85
|
+
index/worktree checkpoint commits. A journal records the operation and its remote
|
|
86
|
+
revision. Git's rebase state and the journal survive worker replacement. After a
|
|
87
|
+
clean reconciliation, checkpoint commits are removed from the work branch and the
|
|
88
|
+
staged/unstaged distinction is restored. Replayed commits preserve original authors
|
|
89
|
+
and sign-offs, with the captured trusted project identity as committer. New integration
|
|
90
|
+
commits use that identity too; checkpoint identities never enter the published branch.
|
|
91
|
+
Recovery refs are retained; they are never included in feature-branch publication. Only the accepted worker may edit the
|
|
92
|
+
workspace. Deterministic reconciliation additionally takes a repository-local lock;
|
|
93
|
+
a lock from another host is not stolen automatically.
|
|
94
|
+
|
|
95
|
+
Conflicts use the existing adjustment turn. Its prompt permits rebase continuation
|
|
96
|
+
but prohibits skipping or removing checkpoint commits, resetting, aborting or
|
|
97
|
+
pushing. Delivery restores the normal checkout after resolution, then requests
|
|
98
|
+
validation of the combined result before publishing. A source change after validation
|
|
99
|
+
starts another reconciliation/validation pass; more than three automatic passes
|
|
100
|
+
require operator action. Explicit retry grants a new budget. No synchronization turns
|
|
101
|
+
are added to the process graph.
|
|
102
|
+
|
|
103
|
+
Publication records local write-ahead intent before sending a push and acceptance
|
|
104
|
+
before checking for subsequent remote movement. This receipt survives a lost server
|
|
105
|
+
acknowledgement: a later developer rewrite does not turn already-published work back
|
|
106
|
+
into an unpublished delta. Remote equality or ancestry can prove uncertain acceptance.
|
|
107
|
+
An explicit Git ref rejection proves no write; an unprovable transport outcome stops
|
|
108
|
+
for operator reconciliation rather than retrying over a possible developer rewind.
|
|
109
|
+
Missing branches with accepted or uncertain publication are never recreated
|
|
110
|
+
automatically. Receipts are recovery evidence on workspace storage; the server remains
|
|
111
|
+
the owner of durable process state.
|
|
112
|
+
|
|
113
|
+
Maintained processes route even `no_changes` through Deliver. It checks the remote
|
|
114
|
+
lease and publishes any retained unpublished work before acknowledging feedback.
|
|
115
|
+
An unchanged checkout creates no commit or push. A watcher may observe an active
|
|
116
|
+
worker's new remote head, but never mutates its checkout or captured baseline.
|
|
22
117
|
|
|
23
118
|
## Git rebase repair
|
|
24
119
|
|
|
@@ -49,8 +144,13 @@ incorporate the fetched base even if merging is clean. Interrupted rebases resum
|
|
|
49
144
|
Git's existing state and preserve authors and sign-offs. Continuation verification
|
|
50
145
|
rejects unfinished/aborted rebases, wrong branches and dirty results. Publication
|
|
51
146
|
uses the original recorded head as an explicit lease, rejects concurrent pushes,
|
|
52
|
-
and recognizes an already-published result after a lost response.
|
|
53
|
-
|
|
147
|
+
and recognizes an already-published result after a lost response. When its source
|
|
148
|
+
lease changes, shared delivery retains the completed repair and reconciles its net
|
|
149
|
+
change relative to the original source snapshot onto the latest remote branch.
|
|
150
|
+
Developer deletions and the agent's conflict resolutions both survive. The combined
|
|
151
|
+
result retains target-branch ancestry and requires validation before ordinary
|
|
152
|
+
leased fast-forward publication; delivery never substitutes a new lease into the
|
|
153
|
+
old force push. Retained state and refs are not deleted on success or failure.
|
|
54
154
|
|
|
55
155
|
## API support
|
|
56
156
|
|
|
@@ -60,10 +160,51 @@ The following exported declarations are `@public`:
|
|
|
60
160
|
- `@leitwerk-dev/coding/auto-work-branch`: `buildAutoWorkBranchFromSeed`.
|
|
61
161
|
- `@leitwerk-dev/coding/finalization-git`: `GitIdentity`, `commitAndPushWorkBranch`.
|
|
62
162
|
- `@leitwerk-dev/coding/repository-change-launch`: `NormalizedRepositoryChangeParamsInput`, `RepositoryChangeLaunchParams`, `RepositoryChangeParamsBase`, `RepositoryIssueOriginParams`, `RepositoryUiOriginParams`, `createRepositoryChangeParamsCodec`, `normalizeRepositoryChangeParamsInput`, `repositoryChangeParamsRecord`.
|
|
63
|
-
- `@leitwerk-dev/coding/repository-change-publication`: `DeliveryState`, `PublicationContext`, `PublicationEvidence`, `PublicationFeedbackId`, `PublicationParams`, `PublicationPipeline`, `PublicationRequest`, `PublicationSource`, `PublicationState`, `RepositoryChangePublicationAdapter`, `applyPublicationEvidence`, `createRepositoryChangePublication`, `patchPublicationState`, `publicationObject`, `readPublicationState`.
|
|
163
|
+
- `@leitwerk-dev/coding/repository-change-publication`: `DeliveryState`, `PublicationContext`, `PublicationReconciliationContext`, `PublicationEvidence`, `PublicationFeedbackId`, `PublicationParams`, `PublicationPipeline`, `PublicationRequest`, `PublicationSource`, `PublicationState`, `RepositoryChangePublicationAdapter`, `applyPublicationEvidence`, `createRepositoryChangePublication`, `patchPublicationState`, `publicationObject`, `readPublicationState`.
|
|
64
164
|
- `@leitwerk-dev/coding/repository-rebase`: `ConflictEvidence`, `conflictEvidence`, `validateConflict`, `describeConflict`, `conflictKey`, `createConflictReporter`.
|
|
65
165
|
- `@leitwerk-dev/coding/repository-change-state`: `RepositoryChangeState`.
|
|
66
166
|
|
|
67
167
|
See the [SDK compatibility policy](../../docs/process-sdk.md#api-compatibility) for member classifications and support guarantees.
|
|
68
168
|
|
|
69
169
|
Pre-launch repository lookup uses `sanitizeWorkerSubprocessEnv` without project credentials. Trusted project Git operations use `repositoryGitSubprocessEnv(projectKey)`.
|
|
170
|
+
|
|
171
|
+
## Scoped settings
|
|
172
|
+
|
|
173
|
+
`coding.commit_message_git_timeout_ms` inherits Instance → Repository and is
|
|
174
|
+
captured with the implementation purpose for commit-message preparation.
|
|
175
|
+
|
|
176
|
+
Coding declares `coding.planning_model`, `coding.implementation_model`,
|
|
177
|
+
and `coding.review_model`. They inherit
|
|
178
|
+
Instance → Repository. Model null delegates to YAML and the allowed catalog;
|
|
179
|
+
explicit process/action choices take precedence.
|
|
180
|
+
|
|
181
|
+
Plan uses `coding.planning`; implementation, commit-message generation, feedback
|
|
182
|
+
revisions, CI repairs, and rebase repairs use `coding.implementation`;
|
|
183
|
+
simplification analysis uses `coding.review`. Each new step captures current values. Prepared starts and
|
|
184
|
+
worker recovery retain their snapshots. Model defaults use the primary repository.
|
|
185
|
+
|
|
186
|
+
## Streamlined coordinated changes
|
|
187
|
+
|
|
188
|
+
GitLab, GitHub, Forgejo, and Jira GitLab share six planning/implementation turns
|
|
189
|
+
plus four publication/repair turns. Plan decisions support approval and human-comment
|
|
190
|
+
revisions; implementation proceeds automatically to simplification and publication.
|
|
191
|
+
The optional `workflow` supplies server policies; `variant`, `finalizeLabel`, and
|
|
192
|
+
`finalizeForm` are deprecated and no longer select gates.
|
|
193
|
+
Server-side policies decide plan bypass and simplification routing. Decisions are
|
|
194
|
+
persisted with the plan revision or implementation boundary before routing.
|
|
195
|
+
The Workflow graph names these branches **Approval required**, **Skip plan
|
|
196
|
+
approval**, **Simplification enabled**, and **Skip simplification**. Route details
|
|
197
|
+
explain the policy and its launcher or source-label inputs. Applying simplification
|
|
198
|
+
rejoins commit-message generation as ordinary forward work.
|
|
199
|
+
|
|
200
|
+
Implementation starts at the session root with the accepted plan, not a prior review branch.
|
|
201
|
+
Simplification has a separate application turn consuming findings and plan. Multi-repository
|
|
202
|
+
sessions use the workspace root and persist commit messages by project key.
|
|
203
|
+
Before upgrading, finish or abort instances parked on removed plan-review,
|
|
204
|
+
implementation-review, implementation-approval, or simplification-approval turns.
|
|
205
|
+
Retain their history; existing delivery turns and state remain supported.
|
|
206
|
+
|
|
207
|
+
Publication adapters can coordinate repository-specific state and report aggregate
|
|
208
|
+
terminal outcomes while reusing the same publication, feedback, CI, and rebase logic.
|
|
209
|
+
GitLab, GitHub, and Forgejo adapters use `unchanged` to complete without publication,
|
|
210
|
+
removing the source trigger without closing the issue.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pushWasRejected,
|
|
3
|
+
readPublicationReceipt,
|
|
4
|
+
readRepositoryBinding,
|
|
5
|
+
repositoryBindingMatches,
|
|
6
|
+
savePublicationReceipt
|
|
7
|
+
} from "./chunk-E3DB4TIZ.js";
|
|
8
|
+
|
|
9
|
+
// src/finalization-git-internal.ts
|
|
10
|
+
import { execFileSync } from "child_process";
|
|
11
|
+
import { existsSync } from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { trimToNull } from "@leitwerk-dev/domain";
|
|
14
|
+
import { repositoryGitArgs, repositoryGitSubprocessEnv } from "@leitwerk-dev/process-sdk";
|
|
15
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
16
|
+
var DeterministicGitError = class extends Error {
|
|
17
|
+
/** @internal */
|
|
18
|
+
errorClass = "git_error";
|
|
19
|
+
/** @internal */
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "DeterministicGitError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var RemoteBranchChangedError = class extends DeterministicGitError {
|
|
26
|
+
constructor() {
|
|
27
|
+
super("The remote source branch changed before publication; reconcile and validate again");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function gitConfigIdentityEnv(projectKey) {
|
|
31
|
+
const env = repositoryGitSubprocessEnv(projectKey, { GIT_TERMINAL_PROMPT: "0" });
|
|
32
|
+
for (const key of [
|
|
33
|
+
"GIT_AUTHOR_NAME",
|
|
34
|
+
"GIT_AUTHOR_EMAIL",
|
|
35
|
+
"GIT_AUTHOR_DATE",
|
|
36
|
+
"GIT_COMMITTER_NAME",
|
|
37
|
+
"GIT_COMMITTER_EMAIL",
|
|
38
|
+
"GIT_COMMITTER_DATE"
|
|
39
|
+
])
|
|
40
|
+
delete env[key];
|
|
41
|
+
return env;
|
|
42
|
+
}
|
|
43
|
+
function gitIdentityArgs(identity) {
|
|
44
|
+
const name = trimToNull(identity.name);
|
|
45
|
+
const email = trimToNull(identity.email);
|
|
46
|
+
if (!name || !email || /[\r\n\0]/.test(name) || /[\r\n\0]/.test(email)) {
|
|
47
|
+
throw new DeterministicGitError("Git identity requires a valid name and email");
|
|
48
|
+
}
|
|
49
|
+
return ["-c", `user.name=${name}`, "-c", `user.email=${email}`];
|
|
50
|
+
}
|
|
51
|
+
function repositoryGit(projectKey, repoPath) {
|
|
52
|
+
function runGit(args, identity) {
|
|
53
|
+
const trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;
|
|
54
|
+
try {
|
|
55
|
+
const stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {
|
|
56
|
+
cwd: repoPath,
|
|
57
|
+
encoding: "utf8",
|
|
58
|
+
env: gitConfigIdentityEnv(projectKey),
|
|
59
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
60
|
+
});
|
|
61
|
+
return { ok: true, stdout, stderr: "" };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const execError = error;
|
|
64
|
+
return {
|
|
65
|
+
ok: false,
|
|
66
|
+
stdout: execError.stdout?.toString() ?? "",
|
|
67
|
+
stderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? ""
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function checkedGit(args, failureMessage, identity) {
|
|
72
|
+
const result = runGit(args, identity);
|
|
73
|
+
if (!result.ok) {
|
|
74
|
+
const detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error";
|
|
75
|
+
throw new DeterministicGitError(`${failureMessage}: ${detail}`);
|
|
76
|
+
}
|
|
77
|
+
return result.stdout.trim();
|
|
78
|
+
}
|
|
79
|
+
function git(...args) {
|
|
80
|
+
return checkedGit(args, `git ${args.join(" ")} failed in '${repoPath}'`);
|
|
81
|
+
}
|
|
82
|
+
function gitOrNull(...args) {
|
|
83
|
+
const result = runGit(args);
|
|
84
|
+
return result.ok ? trimToNull(result.stdout) : null;
|
|
85
|
+
}
|
|
86
|
+
function workingTreeStatus() {
|
|
87
|
+
return (gitOrNull("status", "--porcelain") ?? "").split(/\r?\n/).map((line) => line.replace(/\s+$/, "")).filter(Boolean).map((line) => line.slice(2).trim()).filter(Boolean);
|
|
88
|
+
}
|
|
89
|
+
function conflictedFiles() {
|
|
90
|
+
return (gitOrNull("diff", "--name-only", "--diff-filter=U") ?? "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
91
|
+
}
|
|
92
|
+
function mergeInProgress() {
|
|
93
|
+
const gitDir = git("rev-parse", "--git-dir");
|
|
94
|
+
return existsSync(path.resolve(repoPath, gitDir, "MERGE_HEAD"));
|
|
95
|
+
}
|
|
96
|
+
function assertGitIdentity(identity) {
|
|
97
|
+
if (!runGit(["var", "GIT_AUTHOR_IDENT"], identity).ok || !runGit(["var", "GIT_COMMITTER_IDENT"], identity).ok) {
|
|
98
|
+
throw new DeterministicGitError("Git author/committer identity is not configured");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function commitIfDirty(commitMessage, identity) {
|
|
102
|
+
if (workingTreeStatus().length === 0) return git("rev-parse", "HEAD");
|
|
103
|
+
assertGitIdentity(identity);
|
|
104
|
+
checkedGit(["add", "--all"], "Failed to stage the completed change");
|
|
105
|
+
checkedGit(
|
|
106
|
+
["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", commitMessage],
|
|
107
|
+
"Failed to commit the completed change",
|
|
108
|
+
identity
|
|
109
|
+
);
|
|
110
|
+
const remaining = workingTreeStatus();
|
|
111
|
+
if (remaining.length > 0) {
|
|
112
|
+
throw new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(", ")}`);
|
|
113
|
+
}
|
|
114
|
+
return git("rev-parse", "HEAD");
|
|
115
|
+
}
|
|
116
|
+
function pushAndVerify(branch, expectedHeadSha, expectedRemoteHead) {
|
|
117
|
+
const ref = `refs/heads/${branch}`;
|
|
118
|
+
const pushTarget = `origin/${branch}`;
|
|
119
|
+
const observed = git("ls-remote", "--heads", "origin", ref).split(/\s+/)[0] || null;
|
|
120
|
+
const lease = expectedRemoteHead === void 0 ? observed : expectedRemoteHead;
|
|
121
|
+
const directory = git("rev-parse", "--absolute-git-dir");
|
|
122
|
+
const binding = readRepositoryBinding(git, branch);
|
|
123
|
+
if (binding.origin !== binding.pushOrigin)
|
|
124
|
+
throw new DeterministicGitError("Fetch and push endpoints must match for publication");
|
|
125
|
+
const previous = readPublicationReceipt(directory);
|
|
126
|
+
if (!repositoryBindingMatches(previous, binding))
|
|
127
|
+
throw new DeterministicGitError("Repository publication receipt binding changed");
|
|
128
|
+
const receipt = {
|
|
129
|
+
...binding,
|
|
130
|
+
expectedHead: lease,
|
|
131
|
+
candidate: expectedHeadSha,
|
|
132
|
+
status: "attempting"
|
|
133
|
+
};
|
|
134
|
+
if (observed === expectedHeadSha) {
|
|
135
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
136
|
+
return pushTarget;
|
|
137
|
+
}
|
|
138
|
+
if (previous?.status === "attempting")
|
|
139
|
+
throw new DeterministicGitError(
|
|
140
|
+
"A prior publication is unresolved; retain local work and reconcile its exact candidate first"
|
|
141
|
+
);
|
|
142
|
+
if (previous?.status === "accepted" && previous.candidate === expectedHeadSha)
|
|
143
|
+
throw new RemoteBranchChangedError();
|
|
144
|
+
if (observed !== lease) throw new RemoteBranchChangedError();
|
|
145
|
+
if (lease && !runGit(["merge-base", "--is-ancestor", lease, expectedHeadSha]).ok)
|
|
146
|
+
throw new DeterministicGitError(
|
|
147
|
+
"Ordinary publication must preserve the captured remote head"
|
|
148
|
+
);
|
|
149
|
+
savePublicationReceipt(directory, receipt);
|
|
150
|
+
const pushed = runGit([
|
|
151
|
+
"push",
|
|
152
|
+
"--porcelain",
|
|
153
|
+
"--no-follow-tags",
|
|
154
|
+
"--recurse-submodules=no",
|
|
155
|
+
`--force-with-lease=${ref}:${lease ?? ""}`,
|
|
156
|
+
"origin",
|
|
157
|
+
`${expectedHeadSha}:${ref}`
|
|
158
|
+
]);
|
|
159
|
+
if (!pushed.ok) {
|
|
160
|
+
if (pushWasRejected(pushed.stdout))
|
|
161
|
+
savePublicationReceipt(directory, { ...receipt, status: "rejected" });
|
|
162
|
+
const latest = git("ls-remote", "--heads", "origin", ref).split(/\s+/)[0] || null;
|
|
163
|
+
if (latest === expectedHeadSha) {
|
|
164
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
165
|
+
return pushTarget;
|
|
166
|
+
}
|
|
167
|
+
if (latest !== lease) throw new RemoteBranchChangedError();
|
|
168
|
+
throw new DeterministicGitError(`Failed to push HEAD to '${pushTarget}': ${pushed.stderr}`);
|
|
169
|
+
}
|
|
170
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
171
|
+
const remoteHead = gitOrNull("ls-remote", "--heads", "origin", ref)?.split(/\s+/)[0]?.trim();
|
|
172
|
+
if (remoteHead !== expectedHeadSha) throw new RemoteBranchChangedError();
|
|
173
|
+
return pushTarget;
|
|
174
|
+
}
|
|
175
|
+
return { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify };
|
|
176
|
+
}
|
|
177
|
+
function repositoryHasChanges(repoPath, baseBranch, projectKey = "repo") {
|
|
178
|
+
const { git } = repositoryGit(projectKey, repoPath);
|
|
179
|
+
return Boolean(
|
|
180
|
+
git("status", "--porcelain") || git("diff", "--name-only", `origin/${baseBranch}...HEAD`)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
function commitAndPushWorkBranch(input) {
|
|
184
|
+
const repoPath = path.resolve(input.repoPath);
|
|
185
|
+
const { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify } = repositoryGit(input.projectKey ?? "repo", repoPath);
|
|
186
|
+
if (!existsSync(repoPath) || !runGit(["rev-parse", "--git-dir"]).ok) {
|
|
187
|
+
throw new DeterministicGitError(
|
|
188
|
+
`Repository workspace '${repoPath}' does not exist or is not a git repository`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
const branch = git("branch", "--show-current");
|
|
192
|
+
if (branch !== input.workBranch) {
|
|
193
|
+
throw new DeterministicGitError(
|
|
194
|
+
`Expected '${repoPath}' to be checked out on '${input.workBranch}', but found '${branch || "detached HEAD"}'`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (!trimToNull(input.commitMessage)) {
|
|
198
|
+
throw new DeterministicGitError("A generated commit message is required before publication");
|
|
199
|
+
}
|
|
200
|
+
const conflicts = conflictedFiles();
|
|
201
|
+
if (mergeInProgress() || conflicts.length > 0) {
|
|
202
|
+
throw new DeterministicGitError(
|
|
203
|
+
`Cannot publish a work branch with unresolved conflicts: ${conflicts.join(", ") || "merge in progress"}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
const headSha = commitIfDirty(input.commitMessage, input.gitIdentity);
|
|
207
|
+
return {
|
|
208
|
+
/** @public */
|
|
209
|
+
headSha,
|
|
210
|
+
/** @internal */
|
|
211
|
+
pushTarget: pushAndVerify(input.workBranch, headSha, input.expectedRemoteHead)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
RemoteBranchChangedError,
|
|
217
|
+
repositoryHasChanges,
|
|
218
|
+
commitAndPushWorkBranch
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=chunk-3WJRJ3Q7.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\";\nimport {\n\tpushWasRejected,\n\ttype RepositoryPublicationReceipt,\n\treadPublicationReceipt,\n\treadRepositoryBinding,\n\trepositoryBindingMatches,\n\tsavePublicationReceipt,\n} from \"./repository-publication-receipt.js\";\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\n/** @internal */\nexport class RemoteBranchChangedError extends DeterministicGitError {\n\tconstructor() {\n\t\tsuper(\"The remote source branch changed before publication; reconcile and validate again\");\n\t}\n}\n\ninterface GitExecResult {\n\tok: boolean;\n\tstdout: string;\n\tstderr: string;\n}\n\nfunction gitConfigIdentityEnv(projectKey: string): NodeJS.ProcessEnv {\n\tconst env = repositoryGitSubprocessEnv(projectKey, { 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 repositoryGit(projectKey: string, repoPath: string) {\n\tfunction runGit(args: readonly string[], identity?: GitIdentity): GitExecResult {\n\t\tconst trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;\n\t\ttry {\n\t\t\tconst stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {\n\t\t\t\tcwd: repoPath,\n\t\t\t\tencoding: \"utf8\",\n\t\t\t\tenv: gitConfigIdentityEnv(projectKey),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\treturn { ok: true, stdout, stderr: \"\" };\n\t\t} catch (error) {\n\t\t\tconst execError = error as {\n\t\t\t\tstdout?: string | Buffer;\n\t\t\t\tstderr?: string | Buffer;\n\t\t\t\tmessage?: string;\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tstdout: execError.stdout?.toString() ?? \"\",\n\t\t\t\tstderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? \"\",\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction checkedGit(\n\t\targs: readonly string[],\n\t\tfailureMessage: string,\n\t\tidentity?: GitIdentity,\n\t): string {\n\t\tconst result = runGit(args, identity);\n\t\tif (!result.ok) {\n\t\t\tconst detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? \"unknown git error\";\n\t\t\tthrow new DeterministicGitError(`${failureMessage}: ${detail}`);\n\t\t}\n\t\treturn result.stdout.trim();\n\t}\n\n\tfunction git(...args: string[]): string {\n\t\treturn checkedGit(args, `git ${args.join(\" \")} failed in '${repoPath}'`);\n\t}\n\n\tfunction gitOrNull(...args: string[]): string | null {\n\t\tconst result = runGit(args);\n\t\treturn result.ok ? trimToNull(result.stdout) : null;\n\t}\n\n\tfunction workingTreeStatus(): string[] {\n\t\treturn (gitOrNull(\"status\", \"--porcelain\") ?? \"\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => line.replace(/\\s+$/, \"\"))\n\t\t\t.filter(Boolean)\n\t\t\t.map((line) => line.slice(2).trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tfunction conflictedFiles(): string[] {\n\t\treturn (gitOrNull(\"diff\", \"--name-only\", \"--diff-filter=U\") ?? \"\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tfunction mergeInProgress(): boolean {\n\t\tconst gitDir = git(\"rev-parse\", \"--git-dir\");\n\t\treturn existsSync(path.resolve(repoPath, gitDir, \"MERGE_HEAD\"));\n\t}\n\n\tfunction assertGitIdentity(identity: GitIdentity): void {\n\t\tif (\n\t\t\t!runGit([\"var\", \"GIT_AUTHOR_IDENT\"], identity).ok ||\n\t\t\t!runGit([\"var\", \"GIT_COMMITTER_IDENT\"], identity).ok\n\t\t) {\n\t\t\tthrow new DeterministicGitError(\"Git author/committer identity is not configured\");\n\t\t}\n\t}\n\n\tfunction commitIfDirty(commitMessage: string, identity: GitIdentity): string {\n\t\tif (workingTreeStatus().length === 0) return git(\"rev-parse\", \"HEAD\");\n\t\tassertGitIdentity(identity);\n\t\tcheckedGit([\"add\", \"--all\"], \"Failed to stage the completed change\");\n\t\tcheckedGit(\n\t\t\t[\"-c\", \"core.hooksPath=/dev/null\", \"commit\", \"--no-gpg-sign\", \"-m\", commitMessage],\n\t\t\t\"Failed to commit the completed change\",\n\t\t\tidentity,\n\t\t);\n\t\tconst remaining = workingTreeStatus();\n\t\tif (remaining.length > 0) {\n\t\t\tthrow new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(\", \")}`);\n\t\t}\n\t\treturn git(\"rev-parse\", \"HEAD\");\n\t}\n\n\tfunction pushAndVerify(\n\t\tbranch: string,\n\t\texpectedHeadSha: string,\n\t\texpectedRemoteHead?: string | null,\n\t): string {\n\t\tconst ref = `refs/heads/${branch}`;\n\t\tconst pushTarget = `origin/${branch}`;\n\t\tconst observed = git(\"ls-remote\", \"--heads\", \"origin\", ref).split(/\\s+/)[0] || null;\n\t\tconst lease = expectedRemoteHead === undefined ? observed : expectedRemoteHead;\n\t\tconst directory = git(\"rev-parse\", \"--absolute-git-dir\");\n\t\tconst binding = readRepositoryBinding(git, branch);\n\t\tif (binding.origin !== binding.pushOrigin)\n\t\t\tthrow new DeterministicGitError(\"Fetch and push endpoints must match for publication\");\n\t\tconst previous = readPublicationReceipt(directory);\n\t\tif (!repositoryBindingMatches(previous, binding))\n\t\t\tthrow new DeterministicGitError(\"Repository publication receipt binding changed\");\n\t\tconst receipt: RepositoryPublicationReceipt = {\n\t\t\t...binding,\n\t\t\texpectedHead: lease,\n\t\t\tcandidate: expectedHeadSha,\n\t\t\tstatus: \"attempting\",\n\t\t};\n\t\t// Recover a successful push whose acknowledgement was lost.\n\t\tif (observed === expectedHeadSha) {\n\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\t\treturn pushTarget;\n\t\t}\n\t\tif (previous?.status === \"attempting\")\n\t\t\tthrow new DeterministicGitError(\n\t\t\t\t\"A prior publication is unresolved; retain local work and reconcile its exact candidate first\",\n\t\t\t);\n\t\tif (previous?.status === \"accepted\" && previous.candidate === expectedHeadSha)\n\t\t\tthrow new RemoteBranchChangedError();\n\t\tif (observed !== lease) throw new RemoteBranchChangedError();\n\t\tif (lease && !runGit([\"merge-base\", \"--is-ancestor\", lease, expectedHeadSha]).ok)\n\t\t\tthrow new DeterministicGitError(\n\t\t\t\t\"Ordinary publication must preserve the captured remote head\",\n\t\t\t);\n\t\tsavePublicationReceipt(directory, receipt);\n\t\tconst pushed = runGit([\n\t\t\t\"push\",\n\t\t\t\"--porcelain\",\n\t\t\t\"--no-follow-tags\",\n\t\t\t\"--recurse-submodules=no\",\n\t\t\t`--force-with-lease=${ref}:${lease ?? \"\"}`,\n\t\t\t\"origin\",\n\t\t\t`${expectedHeadSha}:${ref}`,\n\t\t]);\n\t\tif (!pushed.ok) {\n\t\t\tif (pushWasRejected(pushed.stdout))\n\t\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"rejected\" });\n\t\t\tconst latest = git(\"ls-remote\", \"--heads\", \"origin\", ref).split(/\\s+/)[0] || null;\n\t\t\tif (latest === expectedHeadSha) {\n\t\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\t\t\treturn pushTarget;\n\t\t\t}\n\t\t\tif (latest !== lease) throw new RemoteBranchChangedError();\n\t\t\tthrow new DeterministicGitError(`Failed to push HEAD to '${pushTarget}': ${pushed.stderr}`);\n\t\t}\n\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\tconst remoteHead = gitOrNull(\"ls-remote\", \"--heads\", \"origin\", ref)?.split(/\\s+/)[0]?.trim();\n\t\tif (remoteHead !== expectedHeadSha) throw new RemoteBranchChangedError();\n\t\treturn pushTarget;\n\t}\n\n\treturn { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify };\n}\n\n/** Inspect staged, unstaged, untracked, and already committed unpublished changes. @public */\nexport function repositoryHasChanges(\n\trepoPath: string,\n\tbaseBranch: string,\n\tprojectKey = \"repo\",\n): boolean {\n\tconst { git } = repositoryGit(projectKey, repoPath);\n\treturn Boolean(\n\t\tgit(\"status\", \"--porcelain\") || git(\"diff\", \"--name-only\", `origin/${baseBranch}...HEAD`),\n\t);\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 */ projectKey?: string;\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\t/** Captured remote head; null requires branch creation. @internal */\n\texpectedRemoteHead?: string | null;\n}) {\n\tconst repoPath = path.resolve(input.repoPath);\n\tconst { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify } =\n\t\trepositoryGit(input.projectKey ?? \"repo\", repoPath);\n\tif (!existsSync(repoPath) || !runGit([\"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(\"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();\n\tif (mergeInProgress() || 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(input.commitMessage, input.gitIdentity);\n\treturn {\n\t\t/** @public */\n\t\theadSha,\n\t\t/** @internal */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A;AAAA,IAEN;AAAA;AAAA,IAEA,YAAY,cAAc,MAAM,YAAY,SAAS,MAAM,kBAAkB;AAAA,EAC9E;AACD;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/turns/generate-plan.ts
|
|
2
|
+
function buildGeneratePlanPrompt(ctx) {
|
|
3
|
+
return `Create one coordinated implementation plan for this change:
|
|
4
|
+
${ctx.prompts.initial}
|
|
5
|
+
|
|
6
|
+
Repository checkouts: ${ctx.repo.all().map((repo) => `${repo.key}: ${repo.fsPath}`).join("; ")}
|
|
7
|
+
|
|
8
|
+
Planning completion:
|
|
9
|
+
- inspect relevant code, repository guidance, dependency contracts, and external references before selecting the implementation
|
|
10
|
+
- resolve questions affecting correctness, compatibility, or feasibility during planning; published steps must describe decided changes and validation after those changes, with no required investigation deferred to implementation
|
|
11
|
+
- verify access to the resources needed to establish those decisions; never assume implementation will receive additional access
|
|
12
|
+
- after exhausting discoverable facts, use ask_questions for material operator decisions when available and await the answers before finishing the plan
|
|
13
|
+
- when questions are disabled, make those decisions from the requirement and evidence, record minimal assumptions, and keep the requested scope
|
|
14
|
+
- if required evidence remains inaccessible, call abort_turn with the resource, observed failure, and access needed to continue; do not publish a conditional successful plan
|
|
15
|
+
- call plan_saved only after required investigation and access are complete and design-critical questions are resolved
|
|
16
|
+
|
|
17
|
+
Plan format:
|
|
18
|
+
- use three default sections: Findings and decisions, Changes, and Validation
|
|
19
|
+
- for straightforward tickets, target 150\u2013300 words; add detail when complexity requires it
|
|
20
|
+
- Findings and decisions: state what investigation established beyond the ticket, including exact locations, the selected approach, compatibility requirements, and behavior already satisfying the requirements
|
|
21
|
+
- Changes: describe concrete edits by affected component; label repository-specific work when planning across multiple repositories
|
|
22
|
+
- Validation: group related checks that verify the decided changes
|
|
23
|
+
- avoid repeating the ticket, duplicating acceptance criteria, or adding generic preservation and completion sections
|
|
24
|
+
- include snippets only when they resolve a meaningful implementation ambiguity
|
|
25
|
+
|
|
26
|
+
Inspection rules:
|
|
27
|
+
- follow each repository's instructions
|
|
28
|
+
- use bash only for read-only inspection (e.g. git log, git diff, rg, tree, file listing, read-only http/CLI calls)
|
|
29
|
+
- do not modify files, commit, or push
|
|
30
|
+
- keep the number of changed files small`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
buildGeneratePlanPrompt
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunk-ABQH2WZT.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\treturn `Create one coordinated implementation plan for this change:\n${ctx.prompts.initial}\n\nRepository checkouts: ${ctx.repo\n\t\t.all()\n\t\t.map((repo) => `${repo.key}: ${repo.fsPath}`)\n\t\t.join(\"; \")}\n\nPlanning completion:\n- inspect relevant code, repository guidance, dependency contracts, and external references before selecting the implementation\n- resolve questions affecting correctness, compatibility, or feasibility during planning; published steps must describe decided changes and validation after those changes, with no required investigation deferred to implementation\n- verify access to the resources needed to establish those decisions; never assume implementation will receive additional access\n- after exhausting discoverable facts, use ask_questions for material operator decisions when available and await the answers before finishing the plan\n- when questions are disabled, make those decisions from the requirement and evidence, record minimal assumptions, and keep the requested scope\n- if required evidence remains inaccessible, call abort_turn with the resource, observed failure, and access needed to continue; do not publish a conditional successful plan\n- call plan_saved only after required investigation and access are complete and design-critical questions are resolved\n\nPlan format:\n- use three default sections: Findings and decisions, Changes, and Validation\n- for straightforward tickets, target 150–300 words; add detail when complexity requires it\n- Findings and decisions: state what investigation established beyond the ticket, including exact locations, the selected approach, compatibility requirements, and behavior already satisfying the requirements\n- Changes: describe concrete edits by affected component; label repository-specific work when planning across multiple repositories\n- Validation: group related checks that verify the decided changes\n- avoid repeating the ticket, duplicating acceptance criteria, or adding generic preservation and completion sections\n- include snippets only when they resolve a meaningful implementation ambiguity\n\nInspection rules:\n- follow each repository's instructions\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, commit, or push\n- keep the number of changed files small`;\n}\n"],"mappings":";AAGO,SAAS,wBACf,KACS;AACT,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA,wBAEG,IAAI,KACzB,IAAI,EACJ,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,EAAE,EAC3C,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBb;","names":[]}
|