@@ -19,6 +19,23 @@ import { applyCreateBufferToValues } from "./menu-create-step-apply.js"
1919import { resolveCreateDisplaySteps , resolveCreateFlowSteps } from "./menu-create-steps.js"
2020import type { CreateInputs , CreateStep } from "./menu-types.js"
2121
22+ /**
23+ * Creates the initial repo-url prompt view for the create flow.
24+ *
25+ * @pure true
26+ * @invariant step = 0 and values are empty
27+ * @complexity O(1)
28+ */
29+ // CHANGE: expose a deterministic initial create-flow view constructor
30+ // WHY: CLI and browser callers need the same pure starting state
31+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
32+ // REF: issue-339
33+ // SOURCE: n/a
34+ // FORMAT THEOREM: forall b: initial(b).step = 0
35+ // PURITY: CORE
36+ // EFFECT: n/a
37+ // INVARIANT: initial values contain no committed create inputs
38+ // COMPLEXITY: O(1)
2239export const createInitialFlowView = ( buffer = "" ) : CreateModeFlowView => ( {
2340 mode : "create" ,
2441 step : 0 ,
@@ -37,6 +54,23 @@ const resolveDisplayFlowStep = (view: CreateFlowView): number => {
3754 return clampCreateSettingsStep ( displayStep === - 1 ? view . step : displayStep , displaySteps . length - 1 )
3855}
3956
57+ /**
58+ * Converts a create-flow view into the browser display-settings projection.
59+ *
60+ * @pure true
61+ * @invariant values are preserved exactly
62+ * @complexity O(s) where s = number of create steps
63+ */
64+ // CHANGE: map create-mode progress onto browser display settings
65+ // WHY: display mode keeps all rows visible while preserving committed values
66+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
67+ // REF: issue-339
68+ // SOURCE: n/a
69+ // FORMAT THEOREM: forall v: display(v).values = v.values
70+ // PURITY: CORE
71+ // EFFECT: n/a
72+ // INVARIANT: display step is clamped to the settings range
73+ // COMPLEXITY: O(s) where s = number of create steps
4074export const createDisplayFlowView = ( view : CreateFlowView ) : DisplayModeFlowView => ( {
4175 mode : "display" ,
4276 step : resolveDisplayFlowStep ( view ) ,
@@ -130,6 +164,23 @@ const withActiveCreateDisplayContext = (
130164 return active === null ? null : onActive ( active )
131165}
132166
167+ /**
168+ * Applies the current browser display-settings row without moving selection.
169+ *
170+ * @pure true
171+ * @invariant display mode remains display mode on Continue
172+ * @complexity O(k) where k = number of stored create inputs
173+ */
174+ // CHANGE: apply browser display settings through the shared pure step applicator
175+ // WHY: display mode must preserve row position while committing one decoded value
176+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
177+ // REF: issue-339
178+ // SOURCE: n/a
179+ // FORMAT THEOREM: active(view) -> result in {Continue, Error}
180+ // PURITY: CORE
181+ // EFFECT: n/a
182+ // INVARIANT: inactive rows return null
183+ // COMPLEXITY: O(k) where k = number of stored create inputs
133184export const applyCreateDisplaySettingsStep = (
134185 contextOrCwd : string | CreateFlowContext ,
135186 view : DisplayModeFlowView
@@ -140,6 +191,23 @@ export const applyCreateDisplaySettingsStep = (
140191 ( nextValues ) => continueCreateDisplayFlow ( view , nextValues )
141192 ) )
142193
194+ /**
195+ * Applies the current browser display-settings row and advances one row.
196+ *
197+ * @pure true
198+ * @invariant successful application clears the buffer
199+ * @complexity O(k + s) where s = number of display steps
200+ */
201+ // CHANGE: compose display setting application with wrapped display navigation
202+ // WHY: Enter in browser settings should commit the row and move to the next editable row
203+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
204+ // REF: issue-339
205+ // SOURCE: n/a
206+ // FORMAT THEOREM: Continue(v) -> step(next(v)) = wrappedSuccessor(v.step)
207+ // PURITY: CORE
208+ // EFFECT: n/a
209+ // INVARIANT: errors do not advance selection
210+ // COMPLEXITY: O(k + s) where s = number of display steps
143211export const advanceCreateDisplaySettingsStep = (
144212 contextOrCwd : string | CreateFlowContext ,
145213 view : DisplayModeFlowView
@@ -153,6 +221,23 @@ export const advanceCreateDisplaySettingsStep = (
153221 return movedView === null ? applied : { ...applied , view : movedView }
154222}
155223
224+ /**
225+ * Completes browser display settings, applying a non-empty active buffer first.
226+ *
227+ * @pure true
228+ * @invariant completion resolves total CreateInputs
229+ * @complexity O(k) where k = number of stored create inputs
230+ */
231+ // CHANGE: finish browser settings with optional final-row validation
232+ // WHY: a typed buffer should not be discarded when the user presses Done
233+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
234+ // REF: issue-339
235+ // SOURCE: n/a
236+ // FORMAT THEOREM: complete(view) -> Complete(resolve(values')) or Error
237+ // PURITY: CORE
238+ // EFFECT: n/a
239+ // INVARIANT: invalid active buffers return typed parse errors
240+ // COMPLEXITY: O(k) where k = number of stored create inputs
156241export const completeCreateDisplaySettingsFlow = (
157242 contextOrCwd : string | CreateFlowContext ,
158243 view : DisplayModeFlowView
@@ -179,8 +264,25 @@ const resolveNextCreateFlowStep = (
179264) : number =>
180265 currentStep === "repoUrl"
181266 ? firstCreateSettingsStepIndex
182- : clampCreateSettingsStep ( currentStepIndex , nextSteps . length - 1 )
267+ : clampCreateSettingsStep ( currentStepIndex + 1 , nextSteps . length - 1 )
183268
269+ /**
270+ * Advances create mode by applying the active prompt buffer.
271+ *
272+ * @pure true
273+ * @invariant non-repo steps advance to the next remaining settings index when continuing
274+ * @complexity O(k + s) where s = number of remaining create steps
275+ */
276+ // CHANGE: advance normal create-flow settings after committing the active prompt
277+ // WHY: applying a non-repo step must move forward instead of reselecting the same index
278+ // QUOTE(ТЗ): "after applying a non-repoUrl step it advances to currentStepIndex + 1"
279+ // REF: issue-339
280+ // SOURCE: n/a
281+ // FORMAT THEOREM: step != repoUrl -> nextStep = clamp(stepIndex + 1)
282+ // PURITY: CORE
283+ // EFFECT: n/a
284+ // INVARIANT: next step is always within the current settings range when continuing
285+ // COMPLEXITY: O(k + s) where s = number of remaining create steps
184286export const advanceCreateFlow = (
185287 contextOrCwd : string | CreateFlowContext ,
186288 view : CreateModeFlowView ,
@@ -209,6 +311,23 @@ export const advanceCreateFlow = (
209311 )
210312}
211313
314+ /**
315+ * Dispatches an advance result to imperative TUI handlers.
316+ *
317+ * @pure false
318+ * @effect AdvanceCreateFlowHandlers
319+ * @complexity O(1)
320+ */
321+ // CHANGE: keep create-flow result handling at the shell boundary
322+ // WHY: pure transition results are interpreted by caller-provided side-effect handlers
323+ // QUOTE(ТЗ): "fix CodeRabbit review comments"
324+ // REF: issue-339
325+ // SOURCE: n/a
326+ // FORMAT THEOREM: forall r: exactly one matching handler is invoked, except null
327+ // PURITY: SHELL
328+ // EFFECT: AdvanceCreateFlowHandlers
329+ // INVARIANT: null results invoke no handler
330+ // COMPLEXITY: O(1)
212331export const handleAdvanceCreateFlowResult = (
213332 next : AdvanceCreateFlowResult | null ,
214333 handlers : AdvanceCreateFlowHandlers
0 commit comments