@ligeti/workflow-dynamic-factory 0.0.0-stage → 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 (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +314 -2
  3. package/dist/actions.d.ts +64 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/actions.js +243 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/budget.d.ts +13 -0
  8. package/dist/budget.d.ts.map +1 -0
  9. package/dist/budget.js +47 -0
  10. package/dist/budget.js.map +1 -0
  11. package/dist/children/agent-turn.d.ts +31 -0
  12. package/dist/children/agent-turn.d.ts.map +1 -0
  13. package/dist/children/agent-turn.js +53 -0
  14. package/dist/children/agent-turn.js.map +1 -0
  15. package/dist/children/ask.d.ts +30 -0
  16. package/dist/children/ask.d.ts.map +1 -0
  17. package/dist/children/ask.js +60 -0
  18. package/dist/children/ask.js.map +1 -0
  19. package/dist/children/fix-workflow.d.ts +45 -0
  20. package/dist/children/fix-workflow.d.ts.map +1 -0
  21. package/dist/children/fix-workflow.js +99 -0
  22. package/dist/children/fix-workflow.js.map +1 -0
  23. package/dist/children/notify.d.ts +16 -0
  24. package/dist/children/notify.d.ts.map +1 -0
  25. package/dist/children/notify.js +28 -0
  26. package/dist/children/notify.js.map +1 -0
  27. package/dist/children/push.d.ts +18 -0
  28. package/dist/children/push.d.ts.map +1 -0
  29. package/dist/children/push.js +27 -0
  30. package/dist/children/push.js.map +1 -0
  31. package/dist/decide.d.ts +27 -0
  32. package/dist/decide.d.ts.map +1 -0
  33. package/dist/decide.js +58 -0
  34. package/dist/decide.js.map +1 -0
  35. package/dist/diagram.d.ts +2 -0
  36. package/dist/diagram.d.ts.map +1 -0
  37. package/dist/diagram.js +18 -0
  38. package/dist/diagram.js.map +1 -0
  39. package/dist/end-result.d.ts +20 -0
  40. package/dist/end-result.d.ts.map +1 -0
  41. package/dist/end-result.js +4 -0
  42. package/dist/end-result.js.map +1 -0
  43. package/dist/error-key.d.ts +3 -0
  44. package/dist/error-key.d.ts.map +1 -0
  45. package/dist/error-key.js +20 -0
  46. package/dist/error-key.js.map +1 -0
  47. package/dist/fixed-end.d.ts +159 -0
  48. package/dist/fixed-end.d.ts.map +1 -0
  49. package/dist/fixed-end.js +68 -0
  50. package/dist/fixed-end.js.map +1 -0
  51. package/dist/fixed-start.d.ts +83 -0
  52. package/dist/fixed-start.d.ts.map +1 -0
  53. package/dist/fixed-start.js +55 -0
  54. package/dist/fixed-start.js.map +1 -0
  55. package/dist/gate-config.d.ts +9 -0
  56. package/dist/gate-config.d.ts.map +1 -0
  57. package/dist/gate-config.js +18 -0
  58. package/dist/gate-config.js.map +1 -0
  59. package/dist/gate-report.d.ts +47 -0
  60. package/dist/gate-report.d.ts.map +1 -0
  61. package/dist/gate-report.js +123 -0
  62. package/dist/gate-report.js.map +1 -0
  63. package/dist/gate.d.ts +19 -0
  64. package/dist/gate.d.ts.map +1 -0
  65. package/dist/gate.js +34 -0
  66. package/dist/gate.js.map +1 -0
  67. package/dist/history.d.ts +28 -0
  68. package/dist/history.d.ts.map +1 -0
  69. package/dist/history.js +118 -0
  70. package/dist/history.js.map +1 -0
  71. package/dist/human-wait.d.ts +2 -0
  72. package/dist/human-wait.d.ts.map +1 -0
  73. package/dist/human-wait.js +4 -0
  74. package/dist/human-wait.js.map +1 -0
  75. package/dist/land.d.ts +16 -0
  76. package/dist/land.d.ts.map +1 -0
  77. package/dist/land.js +211 -0
  78. package/dist/land.js.map +1 -0
  79. package/dist/pipeline-start.d.ts +15 -0
  80. package/dist/pipeline-start.d.ts.map +1 -0
  81. package/dist/pipeline-start.js +49 -0
  82. package/dist/pipeline-start.js.map +1 -0
  83. package/dist/prompts.d.ts +22 -0
  84. package/dist/prompts.d.ts.map +1 -0
  85. package/dist/prompts.js +73 -0
  86. package/dist/prompts.js.map +1 -0
  87. package/dist/push-head.d.ts +26 -0
  88. package/dist/push-head.d.ts.map +1 -0
  89. package/dist/push-head.js +17 -0
  90. package/dist/push-head.js.map +1 -0
  91. package/dist/rebase.d.ts +20 -0
  92. package/dist/rebase.d.ts.map +1 -0
  93. package/dist/rebase.js +29 -0
  94. package/dist/rebase.js.map +1 -0
  95. package/dist/run-action.d.ts +11 -0
  96. package/dist/run-action.d.ts.map +1 -0
  97. package/dist/run-action.js +54 -0
  98. package/dist/run-action.js.map +1 -0
  99. package/dist/run-agent.d.ts +14 -0
  100. package/dist/run-agent.d.ts.map +1 -0
  101. package/dist/run-agent.js +42 -0
  102. package/dist/run-agent.js.map +1 -0
  103. package/dist/trace-url.d.ts +2 -0
  104. package/dist/trace-url.d.ts.map +1 -0
  105. package/dist/trace-url.js +9 -0
  106. package/dist/trace-url.js.map +1 -0
  107. package/dist/urls.d.ts +11 -0
  108. package/dist/urls.d.ts.map +1 -0
  109. package/dist/urls.js +75 -0
  110. package/dist/urls.js.map +1 -0
  111. package/dist/workflow.d.ts +66 -0
  112. package/dist/workflow.d.ts.map +1 -0
  113. package/dist/workflow.js +269 -0
  114. package/dist/workflow.js.map +1 -0
  115. package/package.json +36 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Viktor "Bika" Nagy
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,315 @@
1
- # Temporary Holding Version
1
+ # @ligeti/workflow-dynamic-factory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reads a GitLab issue, opens a draft merge request, then lets Clef choose the next action in a loop
4
+ until the issue is implemented, gated and merged. The start and the end of the run are fixed; what
5
+ happens between them is decided one action at a time, and every action's result -- success or
6
+ failure -- is written into the loop's history, which is what Clef reads to decide the next action.
7
+ A failed action is therefore not a failed run: it is information the loop acts on, by retrying,
8
+ asking a human, or running an agent that investigates the failure.
9
+
10
+ It is modelled on `@ligeti/workflow-small-factory`. Workflows cannot import each other, so the
11
+ fixed start and the fixed end are copies of small-factory's modules, adapted. It is not one of the
12
+ default workflows: list this directory in `LIGETI_WORKFLOWS` to offer it.
13
+
14
+ ## Vocabulary
15
+
16
+ These words are binding on this package. The project-wide vocabulary is
17
+ [`docs/glossary.md`](../../docs/glossary.md); a word that only this package uses is defined here
18
+ instead, per [ADR-0006](../../adr/0006-ubiquitous-language-is-an-enforced-artifact.md).
19
+
20
+ | Term | Definition |
21
+ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22
+ | **Action** | One thing the loop can do next. Each action is a child run of one child workflow of this package, and is listed in `src/actions.ts` with the text Clef reads, the input built from the history and the reading of the child's output. The action ids are `notify`, `ask-choose`, `ask-input`, `agent-turn`, `push` and `fix-workflow`. |
23
+ | **History** | The issue plus the **entries** the loop has recorded so far. Clef's own input field is called `state`; this package never uses that word for the history. |
24
+ | **Entry** | One recorded result: the action id, its outcome (`success`, `error` or `cancelled`), a one-line summary, the full detail, and, when a child run produced it, the child run id, the trace URL and the input the child ran with. The fixed end records its failures as entries of the action `land`. |
25
+ | **Iteration** | One Clef decision and what follows it: the action it picks, or the question to a human and the action the human picks. |
26
+ | **Fixed start** | The steps that always open a run, in this order: comment the run link on the issue, add the starting label, create the worktree, read the issue, push the untouched branch, open the draft merge request. A step that throws fails the run. |
27
+ | **Fixed end** | The steps that land the merge request: rebase onto the target, gate, publish the attestation, push the gated commit, mark the merge request ready, await its pipeline and squash-merge it. It never asks a human and never runs an agent; every way it stops without merging is returned as data. |
28
+
29
+ ## Inputs
30
+
31
+ | Input | Required | Default | Notes |
32
+ | ------------------------------ | -------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
33
+ | `issueUrl` | yes | -- | A full GitLab issue URL, e.g. `https://gitlab.example/g/p/-/issues/19` or its `/-/work_items/19` form. |
34
+ | `repoPath` | yes | -- | Main repository checkout the worktree is created from. The fix agent works here, outside the worktree. |
35
+ | `model` | no | `"opus"` | Claude model for every agent turn and for the fix agent. |
36
+ | `turnTimeoutSeconds` | no | `1800` | How long to wait for an agent turn that continues the run's session. |
37
+ | `implementationTimeoutSeconds` | no | `14400` | How long to wait for the agent turn that starts the work, and for the fix agent. Longer than `turnTimeoutSeconds` because the first turn drives a full implementation-and-test pass. |
38
+ | `telegramChatId` | no | -- | Telegram chat id for every notification; defaults to `@ligeti/step-telegram-notify`'s own `LIGETI_TELEGRAM_CHAT_ID` when omitted. |
39
+ | `startingLabel` | no | -- | GitLab label added to the issue as soon as the run starts. No label is added when omitted. |
40
+ | `errorLabel` | no | `"ligeti::error"` | GitLab label added to the issue when the budget stops the run; a `startingLabel`, when given and different, is removed afterwards. |
41
+ | `fixClaudeConfigDir` | no | -- | Claude config directory (`CLAUDE_CONFIG_DIR`) of the fix agent. When omitted the fix agent uses `LIGETI_CLAUDE_CONFIG_DIR`. Either way the directory needs the ligeti plugin and Ligeti's hooks, see Prerequisites. |
42
+
43
+ ## The run
44
+
45
+ ```mermaid
46
+ flowchart TD
47
+ Start([Fixed start]) --> Budget{"Budget left?"}
48
+ Budget -->|no| Stopped[["failed: error label"]]
49
+ Budget -->|yes| Ask["Read the worktree status, ask Clef"]
50
+ Ask -->|done| End["Fixed end"]
51
+ End -->|merged| Completed[["completed"]]
52
+ End -->|not merged| Record
53
+ Ask -->|unsure| Human["Ask a human"]
54
+ Human -->|done| End
55
+ Human -->|an action| Run
56
+ Human -->|no answer| Record
57
+ Ask -->|sure| Run["Run the action"]
58
+ Run --> Record["Record an entry"]
59
+ Record --> Budget
60
+ ```
61
+
62
+ The workflow's own diagram shows the same loop and nothing else. The trace of a run
63
+ (`ligeti trace <run id>`) shows the path it actually took, including every child run.
64
+
65
+ ### The fixed start
66
+
67
+ The fixed start runs exactly the steps small-factory opens with, in the same order. Its steps
68
+ throw on failure and a throw fails the run: the loop begins only once the draft merge request
69
+ exists.
70
+
71
+ ### The loop and Clef's two questions
72
+
73
+ Every iteration starts with one `clef.ask` call over the history and two questions:
74
+
75
+ - **`next_action`**, a choice among the action ids, each described to Clef by the text in
76
+ `src/actions.ts`.
77
+ - **`done`**, a yes/no question: is the issue implemented and committed on the branch, with a clean
78
+ worktree status, so the merge request is ready to be gated and merged?
79
+
80
+ The answers are read with two thresholds, both `0.7`:
81
+
82
+ 1. If the probability of `done` is at least `0.7` and at least one `agent-turn` entry succeeded,
83
+ the fixed end runs. Until a turn has succeeded the `done` answer is ignored and the choice is
84
+ read as in the next two steps.
85
+ 2. Otherwise, if Clef's confidence in its choice is below `0.7`, a human picks the action: the
86
+ `ask-choose` action runs, and the action the human picks runs in the same iteration.
87
+ 3. Otherwise the action Clef chose runs.
88
+
89
+ Every iteration first runs `git.status` on the worktree and puts the result in Clef's input, as a
90
+ "Worktree status" section right after the issue's title and URL: `clean`, or the porcelain lines of
91
+ every staged, unstaged and untracked change. A listing longer than 2000 characters is cut with a
92
+ `[truncated]` marker. The `done` question tells Clef to answer yes only when that status is clean.
93
+
94
+ The history and the status are rendered to fit Clef's input limit however large they grow: the
95
+ issue description and the latest entry's detail are truncated first, then the oldest one-line entries are dropped
96
+ and replaced by a count. The latest human answer is cut to 2000 characters so it is never the part
97
+ a hard cut drops. A run never fails on Clef's size check. Everything else about an action
98
+ is data in its child run, not in the history: the history keeps one line per entry, and the full
99
+ detail only for the latest.
100
+
101
+ ### The actions
102
+
103
+ | Action | Child workflow | What it does |
104
+ | -------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
105
+ | `notify` | `dynamic-factory-notify` | Sends a Telegram message with the issue title, the latest summary and the run URL. It does not wait for a reply. |
106
+ | `ask-choose` | `dynamic-factory-ask` | Asks a human to pick an action. It mints an approval page whose buttons are every action id except `ask-choose`, plus `done`, sends its URL on Telegram, and waits up to 30 days. The answer is the picked option. |
107
+ | `ask-input` | `dynamic-factory-ask` | The same child with a free-text box. The answer is recorded on the entry as the latest human answer; the next question to Clef and the next agent turn quote it. In this version the question to the human is generic: the issue, the merge request and the latest entry. Nothing in the history yet lets Clef phrase a specific question. |
108
+ | `agent-turn` | `dynamic-factory-agent-turn` | Runs one Claude Code turn in the worktree. The first turn gets the issue prompt, and every later turn continues the run's one session (`resume`, in place) with the recent history one-liners, the latest result and the latest human answer. A turn commits its work on the branch; it never pushes. |
109
+ | `push` | `dynamic-factory-push` | Pushes the worktree's committed HEAD to the merge request's branch with `--no-verify`, as the fixed start does for the untouched branch. It commits nothing and runs no gate; the output is `{ sha }` and the summary is `pushed <short sha>`. Uncommitted changes are not saved by it. It pushes under a lease on the commit the run last pushed: see "The push lease" below. |
110
+ | `fix-workflow` | `dynamic-factory-fix-workflow` | Runs an agent outside the worktree, in a session of its own, to look into the latest failure. See below. |
111
+
112
+ A child run that ends in `error` or `cancelled` becomes an `error` or `cancelled` entry with the
113
+ child's own message; a child that succeeds becomes a `success` entry, except that an `ask` child
114
+ nobody answered within 30 days becomes an `error` entry and ends the iteration. The agent turn
115
+ child throws an `AgentTurnFailedError` when the agent does not succeed, which is how a failed turn
116
+ reaches the history.
117
+
118
+ Each entry stores the child run id (`handle.workflowId`) and the trace URL, derived from the run's
119
+ own URL by replacing its run id with the child's and appending `/trace`.
120
+
121
+ ### Retry with the same input
122
+
123
+ A `fix-workflow` entry records which entry it addressed: the latest failure when it ran. When the
124
+ latest `fix-workflow` entry is a success whose outcome was `fixed`, the entry it addressed is an
125
+ `error` entry of action X, no X succeeded since that failure and X has not run since the fix, then
126
+ choosing X again does not build a fresh input from the history: the child runs with the input the
127
+ failed run had. Other entries, such as a notification, may sit between the failure and the fix or
128
+ between the fix and the retry. A repair that fixed the cause should make the same call succeed, and
129
+ a fresh input would differ from it only because the history now mentions the repair. Any other
130
+ outcome of the fix agent, or any other choice, builds the input from the history as usual.
131
+
132
+ ### The fix agent
133
+
134
+ `fix-workflow` starts one agent whose prompt names the failed action, the error, the child run id
135
+ and its trace URL, and tells it to read the trace with `ligeti trace <child run id>` and to use the
136
+ Ligeti troubleshooting skill. It works in `repoPath`, never in the issue's worktree, and never
137
+ resumes a session: every fix is a session of its own, in `fixClaudeConfigDir` when given.
138
+
139
+ **It must not change installed workflow or step code.** A worker replays a run against the code it
140
+ was built with; editing that code under a run in flight breaks that run and every other one on the
141
+ same worker. The agent may fix only the state around the code: a stale lock, a dirty or detached
142
+ worktree, a missing branch, a leftover process. A failure that is a bug in Ligeti itself is
143
+ reported, not worked around.
144
+
145
+ The agent reports through a turn result at a path the workflow chose (given to it in the prompt and
146
+ in the environment variable `TURN_RESULT_PATH`, under `/tmp/ligeti-dynamic-factory/<run id>/`):
147
+
148
+ | `outcome` | Meaning | What the loop sees |
149
+ | ------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------- |
150
+ | `fixed` | The cause was repaired. | A success entry that enables the same-input retry. |
151
+ | `needs-human` | Only a person can resolve it. | A success entry; Clef usually asks a human next. |
152
+ | `code-bug` | The failure is a bug in a workflow or step, with a diagnosis in `summary`. | A success entry carrying the diagnosis for Clef and humans. |
153
+
154
+ A turn result that is missing or invalid, an agent that fails and an agent that does not respond
155
+ before the timeout throw a `FixWorkflowFailedError`, so the child run errors and the history
156
+ records that.
157
+
158
+ ### The budget
159
+
160
+ The loop stops, instead of spinning, as soon as any of these holds. The check runs before every
161
+ decision and after every entry:
162
+
163
+ | Rule | `stoppedAt` | Stops when |
164
+ | ------------ | ------------------ | ----------------------------------------------------------------------------------- |
165
+ | Iterations | `iterations` | 10 iterations were spent without a merge. |
166
+ | Same action | `repeated_action` | The last 3 entries are of the same action. |
167
+ | Same failure | `repeated_failure` | 3 `error` entries, consecutive or not, have the same action and the same error key. |
168
+
169
+ The error key is what makes two failures the same, because their detail never is: it embeds
170
+ pipeline URLs, commit shas and output tails. A `land` entry's key is `land:<status>`, with the
171
+ sorted ids of the failing checks for `gate_failed`, the sorted conflicted paths for
172
+ `rebase_conflict`, the cause for `pipeline_failed` (`head_moved` when the merge request head moved
173
+ while the pipeline was awaited, `gate_config` when the change modifies the gate config, otherwise
174
+ `status=<pipeline status>`) and the reason (a merge state or merge status, never a URL or a sha)
175
+ for `merge_failed`. A child's key is its error name and the first line of its message with URLs,
176
+ UUIDs, hex ids and numbers normalised, so a child workflow that fails puts its stable reason on the
177
+ first line and free text after it. An `error` entry that has no key, such as a question no human
178
+ answered, is counted by its whole detail.
179
+
180
+ A stop fails the run in the way small-factory's finish does: the merge request is assigned, a
181
+ Telegram notification names the rule and links back to the run, the error label is added to the
182
+ issue and the starting label, if it differs, is removed. The run outcome is `failed`.
183
+
184
+ ### The push lease
185
+
186
+ The loop keeps the commit the run last pushed to the merge request's branch: the fixed start's
187
+ first push, then every `push` action and every push of the fixed end, which pushes the gated commit
188
+ and, when it rebases a conflicted merge request, the rebased one. The `push` action passes it to
189
+ `git.push` as `expectedRemoteSha`, which pushes with
190
+ `--force-with-lease=refs/heads/<branch>:<sha>`. A fixed end that rebased the local branch and then
191
+ failed its gate leaves the local branch and the remote diverged; the lease lets the next `push`
192
+ replace the remote branch because it is still exactly what the run pushed, and refuses when
193
+ somebody else moved it. The fixed start's first push has no lease.
194
+
195
+ ### The fixed end
196
+
197
+ When the answer to `done` is yes, the fixed end runs small-factory's landing sequence. It differs
198
+ from small-factory in these ways:
199
+
200
+ - It asks no human and runs no fix turn. Whatever stops it without a merge is returned as data.
201
+ - When the merge request's head is still the commit it pushes, no new pipeline will come. It then
202
+ looks at the head's pipeline, and uses it only when it is a merge-request pipeline
203
+ (`source: merge_request_event`, or a `refs/merge-requests/` ref) built for the pushed commit (its
204
+ `sha` is the pushed commit, or its ref is a merged-results ref), which is what
205
+ `gitlab-mr.await-pipeline` accepts. Such a pipeline is merged on if it is `success`, and awaited
206
+ from its own id if its status is not final (`success`, `failed`, `canceled`, `skipped`, `manual`
207
+ and `scheduled` are final, as in `gitlab-mr.await-pipeline`). In every other case -- a final
208
+ status that is not green, a pipeline of an older commit, a branch pipeline -- it starts a new one
209
+ (`gitlab-mr.run-pipeline`) and awaits it from its id. When the push moved the head it awaits a
210
+ pipeline newer than the head's, as small-factory does.
211
+ - Its first rebase relies on the ancestry check of `git.rebase` and not on the lease of the initial
212
+ push, which small-factory has because it rebases the branch it just pushed.
213
+
214
+ Whatever stops it without a merge is returned as one of four results, and each becomes a `land`
215
+ entry in the history. A result also carries the commit the fixed end last pushed to the branch, if
216
+ it pushed one:
217
+
218
+ | Result | Detail recorded |
219
+ | ----------------- | ---------------------------------------------------------------------- |
220
+ | `rebase_conflict` | The branch, the target and the conflicted paths. |
221
+ | `gate_failed` | Every failing check with its command and the tail of its output. |
222
+ | `pipeline_failed` | The pipeline URL and status, with a note when the gate config changed. |
223
+ | `merge_failed` | Why the merge request could not be merged. |
224
+
225
+ Clef then decides what to do with it, typically an `agent-turn` that fixes the cause, followed by
226
+ `done` again, which runs the fixed end from the top. A `merged` result completes the run. A step
227
+ that throws inside the fixed end fails the run, as in the fixed start.
228
+
229
+ ## Output
230
+
231
+ On a merge:
232
+
233
+ | Field | Notes |
234
+ | ----------------- | ---------------------------------------------------- |
235
+ | `runOutcome` | `"completed"` |
236
+ | `worktreePath` | The worktree the run created. |
237
+ | `branchName` | Its branch. |
238
+ | `mergeRequestUrl` | The merge request that was merged. |
239
+ | `merged` | `true` |
240
+ | `iterations` | How many decisions Clef made, the last one included. |
241
+
242
+ When the budget stops the run:
243
+
244
+ | Field | Notes |
245
+ | ----------------- | ------------------------------------------------------------ |
246
+ | `runOutcome` | `"failed"` |
247
+ | `stoppedAt` | `"iterations"`, `"repeated_action"` or `"repeated_failure"`. |
248
+ | `detail` | What the rule saw. |
249
+ | `worktreePath` | The worktree the run created. |
250
+ | `branchName` | Its branch. |
251
+ | `mergeRequestUrl` | The merge request, now assigned to the token's owner. |
252
+ | `iterations` | How many decisions Clef made. |
253
+
254
+ ## Environment variables
255
+
256
+ This package reads no environment of its own; it only composes the settings of the steps it runs.
257
+ The ones an operator needs are:
258
+
259
+ - `@ligeti/step-clef`: `LIGETI_CLOUDFLARE_ACCOUNT_ID` and `LIGETI_CLOUDFLARE_API_TOKEN`, see
260
+ [`steps/clef/README.md`](../../steps/clef/README.md).
261
+ - `@ligeti/step-agent`: see [`steps/agent/README.md`](../../steps/agent/README.md).
262
+ `LIGETI_CLAUDE_CONFIG_DIR` is the Claude profile of every agent turn, and also of the fix agent
263
+ when `fixClaudeConfigDir` is not given. A profile used as the fix agent's needs the ligeti
264
+ plugin and Ligeti's hooks, as described below.
265
+ - `@ligeti/step-gitlab-issue` and `@ligeti/step-gitlab-mr`: the GitLab token, with write (`api`)
266
+ rights because the run marks the merge request ready, merges and assigns it, comments on the issue
267
+ and labels it. See [`steps/gitlab-issue/README.md`](../../steps/gitlab-issue/README.md).
268
+ - `@ligeti/step-telegram-notify`: `LIGETI_TELEGRAM_BOT_TOKEN`, see
269
+ [`steps/telegram-notify/README.md`](../../steps/telegram-notify/README.md). Every notification,
270
+ including the one that ends the run, is mandatory: a failed send fails the child or the run.
271
+ - The SDK's `LIGETI_PUBLIC_BASE_URL`, which `ctx.runUrl()` and the approval pages embed, see
272
+ [`packages/sdk/README.md`](../../packages/sdk/README.md).
273
+ - `@ligeti/step-git-worktree`, `@ligeti/step-attest` and `@ligeti/step-git-notes-attestation`: see
274
+ their READMEs.
275
+
276
+ ## Prerequisites
277
+
278
+ Beyond `AGENTS.md`'s tooling list and `@ligeti/step-agent`'s own
279
+ [prerequisites](../../steps/agent/README.md#prerequisites):
280
+
281
+ - The `ligeti` CLI is on the worker's `PATH`, because the fix agent reads the failed run with
282
+ `ligeti trace`.
283
+ - The Claude profile the fix agent runs under (`fixClaudeConfigDir`, else
284
+ `LIGETI_CLAUDE_CONFIG_DIR`) has the ligeti plugin installed, which provides the troubleshooting
285
+ skill the prompt points at, and carries Ligeti's Stop and StopFailure hooks, without which the
286
+ agent can never report back.
287
+ - The agent's Claude profile denies `git push`: no agent turn pushes or manages the merge request,
288
+ the workflow does both.
289
+ - The project's CI creates merge-request pipelines for the branch, because the fixed end waits for
290
+ one.
291
+
292
+ ## Known limits
293
+
294
+ - **Questions to a human are generic.** `ask-choose` and `ask-input` quote the issue, the merge
295
+ request and the latest entry; Clef does not write the question.
296
+ - **A failure outside the loop fails the run.** A throw in Clef itself (including an unavailable
297
+ Cloudflare API), in the fixed start, in the fixed end's steps or in the code that summarises a
298
+ child's output ends the run in `ERROR`, with no error label and no notification. Only a budget
299
+ stop labels the issue and notifies.
300
+ - **The turn result path is predictable and not cleaned up.** The fix agent's turn result lives at
301
+ `/tmp/ligeti-dynamic-factory/<run id>/turn-result.json`. In a shared `/tmp` on a host with several
302
+ users, another local user could plant a fake turn result or a symlink there. The file stays after
303
+ the run.
304
+ - **A `done` answer on a dirty worktree still discards the uncommitted work.** Clef sees the
305
+ worktree status before each decision and is told to answer `done` only when it is clean, but
306
+ nothing enforces that: when the answer is `done`, or a human picks `done`, the fixed end runs, and
307
+ its first rebase uses `discardChanges`, deleting whatever is still uncommitted. The status is not
308
+ shown to a human who is asked to choose. The `push` action only saves committed work, and the
309
+ agent turn prompts ask for a commit; nothing verifies it.
310
+ - **The fix agent cannot recover from an expired Claude login.** An agent turn waits for a human
311
+ to log in and relaunches; the fix agent does not, so an expired login ends the fix as an `error`
312
+ entry.
313
+ - **The diagram shows the loop only.** The path a run took is in its trace.
314
+ - **It is not one of the default workflows.** `ligeti serve` does not offer it unless
315
+ `LIGETI_WORKFLOWS` lists this directory.
@@ -0,0 +1,64 @@
1
+ import type { WorkflowContext, WorkflowDefinition } from "@ligeti/sdk";
2
+ import { type History } from "./history.js";
3
+ export declare const DONE_OPTION = "done";
4
+ export declare const LAND_ACTION = "land";
5
+ export declare const AGENT_TURN_ID = "agent-turn";
6
+ export declare const FIX_WORKFLOW_ID = "fix-workflow";
7
+ export declare const PUSH_ID = "push";
8
+ export interface FixedValues {
9
+ readonly issueUrl: string;
10
+ readonly repoPath: string;
11
+ readonly worktreePath: string;
12
+ readonly branchName: string;
13
+ readonly remoteSha: string | undefined;
14
+ readonly mergeRequestUrl: string;
15
+ readonly mergeRequestIid: number;
16
+ readonly model: string;
17
+ readonly sessionId: string | undefined;
18
+ readonly turnTimeoutSeconds: number;
19
+ readonly implementationTimeoutSeconds: number;
20
+ readonly telegramChatId: string | undefined;
21
+ readonly fixClaudeConfigDir: string | undefined;
22
+ readonly runId: string;
23
+ readonly runUrl: string;
24
+ readonly clefSuggestion?: {
25
+ readonly action: string;
26
+ readonly confidence: number;
27
+ };
28
+ }
29
+ export interface ActionSummary {
30
+ readonly outcome: "success" | "error";
31
+ readonly summary: string;
32
+ readonly detail: string;
33
+ readonly sessionId?: string;
34
+ readonly humanAnswer?: string;
35
+ readonly picked?: string;
36
+ readonly pushedSha?: string;
37
+ readonly repairedPrevious?: boolean;
38
+ }
39
+ export type ActionOutcome = {
40
+ readonly status: "success";
41
+ readonly summary: ActionSummary;
42
+ } | {
43
+ readonly status: "error";
44
+ readonly name: string;
45
+ readonly message: string;
46
+ } | {
47
+ readonly status: "cancelled";
48
+ };
49
+ export interface StartedAction {
50
+ readonly workflowId: string;
51
+ outcome(): Promise<ActionOutcome>;
52
+ }
53
+ export interface Action {
54
+ readonly id: string;
55
+ readonly description: string;
56
+ readonly child: WorkflowDefinition;
57
+ buildInput(history: History, fixed: FixedValues): unknown;
58
+ start(ctx: WorkflowContext, input: unknown): Promise<StartedAction>;
59
+ }
60
+ export declare function retryInput(history: History, actionId: string): unknown;
61
+ export declare const ACTIONS: readonly Action[];
62
+ export declare const ASK_CHOOSE_ID: string;
63
+ export declare function findAction(id: string): Action;
64
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,eAAe,EAAE,kBAAkB,EAAK,MAAM,aAAa,CAAC;AACvF,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAStB,eAAO,MAAM,WAAW,SAAS,CAAC;AAClC,eAAO,MAAM,WAAW,SAAS,CAAC;AAClC,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