pi-odd-worktree 2.1.0 → 3.0.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 +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1421 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +323 -15
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1420 -0
- package/tools/bash-design.test.js +1093 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +613 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1889 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +417 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
package/lib/warp-create-panel.js
CHANGED
|
@@ -1,40 +1,79 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// The worktree CREATION panel (
|
|
3
|
-
// S1
|
|
2
|
+
// The worktree CREATION panel (warp-branch-field S1,S2,S6,S7,S8,S9,S10;
|
|
3
|
+
// warp-odd-picker S1,S2; worktree-ui-feedback S4,S12,S15).
|
|
4
4
|
//
|
|
5
5
|
// It is the TABBED bottom flow a human creates with (S7): a live branch/path
|
|
6
|
-
// preview ABOVE, then the
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// the form opens (`feat/` and the checkout directory `…-worktrees/feat-`) and
|
|
12
|
-
// completes as the name is typed: an incomplete form is not an error, so
|
|
13
|
-
// nothing in the preview is painted red or names a failure, while a refused
|
|
14
|
-
// submit still says exactly why. `tab`, `shift+tab`, `←` and `→` move between
|
|
15
|
-
// the two tabs; `↑`/`↓` pick the type; `enter` on the name creates (S12 keeps
|
|
16
|
-
// ONE create key — the duplicate `ctrl+s` was dropped and is not a binding).
|
|
6
|
+
// preview ABOVE, then the BRANCH and the ODD as the TWO TABS of one strip
|
|
7
|
+
// (`Branch · Odd`, with only the ACTIVE field's content under it). The Branch tab
|
|
8
|
+
// holds the typed name over the change types as an inline LIST; the Odd tab holds
|
|
9
|
+
// the ODD as an inline LIST too (there is no native dropdown in this host, and no
|
|
10
|
+
// second pop-up surface).
|
|
17
11
|
//
|
|
18
|
-
// S1:
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
12
|
+
// S1: the branch is the human's, never a derivation. `Branch` is the same input
|
|
13
|
+
// `worktree_create` has always taken, composed as `<type>/<name>`: the type is
|
|
14
|
+
// chosen from the repository's list and the name is typed. The ODD stays the ODD
|
|
15
|
+
// — the directory name — and never enters the branch's spelling, so no branch
|
|
16
|
+
// ever names a directory (R1). There is still no `Name` field (S2): the ODD is the
|
|
17
|
+
// checkout's identity, and the branch has its own name. S2: the ODD is CHOSEN,
|
|
18
|
+
// not typed from nothing — the list is the ODDs that exist in `main`
|
|
19
|
+
// (`lib/warp-create-picker.js` `listMainOddTasks`, injected as `oddOptions` by the
|
|
20
|
+
// caller that can await the read), with `new odd` as the FIRST entry; that entry,
|
|
21
|
+
// and only that entry, takes a typed name.
|
|
22
|
+
//
|
|
23
|
+
// S6: `feat` is the first type, so an untouched form already previews `feat/` and
|
|
24
|
+
// the human only has to type; the field reads the typed name on TOP and the type
|
|
25
|
+
// list under it.
|
|
26
|
+
//
|
|
27
|
+
// S7/S8/S9/S10: both typed fields share ONE typed-row design (`typedRow`) — the
|
|
28
|
+
// `❯` prompt, the field's static label, the composed prefix (`feat/`), the typed
|
|
29
|
+
// value, the caret, and the ghost placeholder while the value is empty. The lists
|
|
30
|
+
// beside them (the eleven types, the ODDs `main` carries) stay PLAIN rows, and a
|
|
31
|
+
// blank separator row puts the input region above its list: typing looks like
|
|
32
|
+
// typing in both fields, choosing looks like choosing, and the distinction
|
|
33
|
+
// survives a monochrome terminal because it rides spacing and markers, never a
|
|
34
|
+
// colour this module picks. The Odd field's first row IS its input: `new odd` is
|
|
35
|
+
// the only entry that takes a typed name, so while it is focused it renders as
|
|
36
|
+
// the shared typed row and the documents stand alone under the separator; while a
|
|
37
|
+
// DOCUMENT is focused there is no input under the list at all and `new odd` stays
|
|
38
|
+
// a plain row in its place. Nothing is echoed under the list.
|
|
39
|
+
//
|
|
40
|
+
// The preview shows the composed branch as soon as the form opens (`feat/`) and
|
|
41
|
+
// the worktree root `…-worktrees/`, completing as the name is typed and the ODD
|
|
42
|
+
// is picked: an incomplete form is not an error, so nothing in the preview is
|
|
43
|
+
// painted red or names a failure, while a refused submit still says exactly why.
|
|
44
|
+
// `tab`, `shift+tab`, `←` and `→` move between the two tabs; `↑`/`↓` pick from the
|
|
45
|
+
// active list; a printable character types the active field's own text; `enter`
|
|
46
|
+
// on the ODD creates (S12 keeps ONE create key — the duplicate `ctrl+s` was
|
|
47
|
+
// dropped and is not a binding).
|
|
48
|
+
//
|
|
49
|
+
// S5 (warp-branch-field): one ODD is one worktree, so an ODD whose checkout
|
|
50
|
+
// already exists is not a choice. The caller hands the existing checkouts over
|
|
51
|
+
// (`occupiedPaths`, reconciled against git's live listing so a stale registry row
|
|
52
|
+
// for a removed checkout never hides an ODD that is free again) and the panel
|
|
53
|
+
// drops exactly those options. The filter is an AID, never the check: an ODD that
|
|
54
|
+
// still collides is refused by the create path with its own sentence.
|
|
55
|
+
//
|
|
56
|
+
// Everything the panel does NOT do is as important: it creates no file, writes
|
|
57
|
+
// nothing and registers nothing. A chosen ODD that already has a document creates
|
|
58
|
+
// no document, and the document of a new ODD is left to the agent that starts
|
|
59
|
+
// work on it — nothing in this package anticipates that, waits for it or reports
|
|
60
|
+
// it. `done({ ok: true, branch, odd })` is the whole output.
|
|
24
61
|
//
|
|
25
62
|
// Pure Node, no package imports. The repository's own helpers do the work
|
|
26
|
-
// instead of a second implementation of the same convention:
|
|
27
|
-
// `
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
63
|
+
// instead of a second implementation of the same convention: the ported
|
|
64
|
+
// `lib/worktree-create.js` `isWorktreeSegment` decides what an ODD may say, so
|
|
65
|
+
// the preview and the create refuse the same values with the same words, and
|
|
66
|
+
// `lib/worktree-git.js` `canonicalWorktreePathOf` (or `canonicalWorktreePath` /
|
|
67
|
+
// `worktreePath`) over its memoized `repoIdentity` give the parent directory the
|
|
68
|
+
// create lays the ODD in. The git seam is injectable (`git`), so tests never touch
|
|
69
|
+
// a real checkout.
|
|
31
70
|
//
|
|
32
|
-
// S1 (
|
|
33
|
-
// Its preview derives from the PURE halves of those
|
|
34
|
-
// character costs no child at all — the blocking child that
|
|
35
|
-
// `render()` froze Pi for its whole lifetime per keystroke, which
|
|
36
|
-
// reported "creating a worktree left Pi stuck". The one authoritative
|
|
37
|
-
// check lives where it can be awaited: the create path that receives this
|
|
71
|
+
// S1 (worktree-ui-feedback): the panel is a FORM and spawns no
|
|
72
|
+
// `git check-ref-format`. Its preview derives from the PURE halves of those
|
|
73
|
+
// helpers, so a typed character costs no child at all — the blocking child that
|
|
74
|
+
// ran here from `render()` froze Pi for its whole lifetime per keystroke, which
|
|
75
|
+
// is the reported "creating a worktree left Pi stuck". The one authoritative
|
|
76
|
+
// branch check lives where it can be awaited: the create path that receives this
|
|
38
77
|
// panel's payload (`worktree_create` → `validateBranchAsync`), which refuses an
|
|
39
78
|
// invalid branch with its own message and nothing created.
|
|
40
79
|
//
|
|
@@ -43,23 +82,36 @@
|
|
|
43
82
|
// `{ render(width), handleInput(data), invalidate(), state }`.
|
|
44
83
|
//
|
|
45
84
|
// Completion (documented exactly, because it is the module's only output):
|
|
46
|
-
// done({ ok: true,
|
|
47
|
-
// on `enter` in the
|
|
48
|
-
// `done(null)` on `esc` (cancel). `
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
85
|
+
// done({ ok: true, branch, odd })
|
|
86
|
+
// on `enter` in the last field (the ODD), and
|
|
87
|
+
// `done(null)` on `esc` (cancel). `branch` is the composed `<type>/<name>`, passed
|
|
88
|
+
// through UNCHANGED (created when it is absent, adopted when it exists), and `odd`
|
|
89
|
+
// is the trimmed ODD that names the checkout's directory. Both typed halves pass
|
|
90
|
+
// ONE rule first, in both fields: one or more consecutive spaces become a single
|
|
91
|
+
// `-` (`change cost` is `change-cost`), after the trim the fields already had
|
|
92
|
+
// and before the type is composed onto the name or the ODD names the directory.
|
|
93
|
+
// The input row, the preview and this completion are the same derivation, so what
|
|
94
|
+
// a human reads is what the create makes. A completion NEVER
|
|
95
|
+
// carries `name` and NEVER carries `issues`: the ODD is the only identity and a
|
|
96
|
+
// new row is born without an issue association, and there is no other completion
|
|
97
|
+
// shape. A completion fires EXACTLY once. An invalid branch/path/ODD refuses
|
|
98
|
+
// creation (nothing is emitted) and the reason stays on screen.
|
|
54
99
|
//
|
|
55
100
|
// Options (every one optional; the seams exist so tests own the world):
|
|
56
101
|
// cwd checkout the panel derives the path from
|
|
57
102
|
// (default: process.cwd())
|
|
58
103
|
// changeTypes `[{id,label}]`; default exports CHANGE_TYPES, the
|
|
59
104
|
// repository's branch-pr convention
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
105
|
+
// oddOptions the ODDs to offer, already read from `main` (default: an
|
|
106
|
+
// empty list, which still offers `new odd`)
|
|
107
|
+
// occupiedPaths absolute paths of the checkouts that already exist; an ODD
|
|
108
|
+
// whose destination is one of them is not offered (default:
|
|
109
|
+
// none, which filters nothing)
|
|
110
|
+
// oddPlaceholder ghost hint of the new-ODD input (default ODD_PLACEHOLDER)
|
|
111
|
+
// branchPlaceholder ghost hint of the branch name (default BRANCH_PLACEHOLDER)
|
|
112
|
+
// initialOdd select this ODD when it is in the list, else prefill the
|
|
113
|
+
// new-ODD field with it (in the normalized spelling below)
|
|
114
|
+
// initialType pre-selected change-type id (default: the first, `feat`)
|
|
63
115
|
// rowsAvailable the row budget the host offers: the surface renders
|
|
64
116
|
// exactly its own content height (clamped by this)
|
|
65
117
|
// principalLayout derive the target with `canonicalWorktreePath`
|
|
@@ -68,17 +120,17 @@
|
|
|
68
120
|
// helpers/hostTui/theme the host seams the other panels use
|
|
69
121
|
// done (value) => void, see above
|
|
70
122
|
//
|
|
71
|
-
// Keys: the preview ABOVE (branch, then path), then the `
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
123
|
+
// Keys: the preview ABOVE (branch, then path), then the `Branch` and `Odd` tabs
|
|
124
|
+
// of one field strip. `tab`/`shift+tab`/`←`/`→` move between the two fields (a
|
|
125
|
+
// horizontal key at either end wraps around), `↑`/`↓` pick from the active list,
|
|
126
|
+
// a printable character types the active field's own text (the branch name, or
|
|
127
|
+
// the new ODD), `enter` on Branch reaches Odd, `enter` on Odd creates (the ONE
|
|
128
|
+
// create key), `esc` cancels. There is no `?` key list: the footer names every
|
|
129
|
+
// shortcut on ONE row.
|
|
78
130
|
|
|
79
131
|
const gitLib = require('./worktree-git.js');
|
|
132
|
+
const createLib = require('./worktree-create.js');
|
|
80
133
|
const path = require('node:path');
|
|
81
|
-
const picker = require('./warp-create-picker.js');
|
|
82
134
|
// S11: the ONE palette the readers share decides which theme role paints each
|
|
83
135
|
// kind of token (key, title, description, count, label, value, border, error),
|
|
84
136
|
// so a footer KEY is always distinguishable from the words beside it and this
|
|
@@ -104,23 +156,41 @@ const CHANGE_TYPES = Object.freeze([
|
|
|
104
156
|
{ id: 'revert', label: 'Revert' },
|
|
105
157
|
].map((type) => Object.freeze(type)));
|
|
106
158
|
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
const
|
|
159
|
+
// S2: the FIRST entry of the ODD list — the one entry that takes a typed name.
|
|
160
|
+
// Lowercase on purpose: it is the human's own word for it.
|
|
161
|
+
const NEW_ODD_LABEL = 'new odd';
|
|
162
|
+
|
|
163
|
+
// S2: the typed name's placeholder, rendered as GHOST text (dim, never a value:
|
|
164
|
+
// creating from a placeholder is refused). S8 uses the same ghost treatment for
|
|
165
|
+
// the branch name, so both typed rows read the same.
|
|
166
|
+
const ODD_PLACEHOLDER = 'odd-name';
|
|
167
|
+
const BRANCH_PLACEHOLDER = 'branch-name';
|
|
168
|
+
|
|
169
|
+
// S7: the branch the layout helpers are asked about when only the destination
|
|
170
|
+
// root is wanted. The root (`<principal>-worktrees`) never depends on it, so a
|
|
171
|
+
// fixed probe keeps the preview free of the branch's own spelling.
|
|
172
|
+
const DESTINATION_PROBE_BRANCH = 'worktree';
|
|
173
|
+
|
|
174
|
+
// S1/S2: the tab order. `tab`/`right` walk it forward, `shift+tab`/`left` back,
|
|
175
|
+
// and either end wraps — one rule for the strip and for the arrows. Branch comes
|
|
176
|
+
// first and Odd is the last field, the one whose `enter` creates.
|
|
177
|
+
const FIELD_ORDER = ['branch', 'odd'];
|
|
110
178
|
|
|
111
179
|
const PANEL_HEIGHT_MAX = 40;
|
|
112
180
|
|
|
113
181
|
// S12: the create surface's own fixed rows — top rule, title, branch preview,
|
|
114
|
-
// path preview, the `
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
const CREATE_FIXED_ROWS =
|
|
182
|
+
// path preview, the `Branch · Odd` tab strip, the one-row legend, the bottom
|
|
183
|
+
// rule. The active field's region — its typed row plus the S7 blank separator —
|
|
184
|
+
// and then its inline list take whatever the host budget leaves.
|
|
185
|
+
const CREATE_FIXED_ROWS = 7;
|
|
186
|
+
// S7: the typed row and the blank separator that keeps the input region apart
|
|
187
|
+
// from the list under it.
|
|
188
|
+
const CREATE_REGION_ROWS = 2;
|
|
118
189
|
|
|
119
190
|
// S7: the placeholder an underivable preview shows. `-` is the same
|
|
120
191
|
// missing-value mark the viewers use, so a preview with nothing derivable yet
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
// preview.
|
|
192
|
+
// reads as empty instead of broken — the reason for a failure belongs to the
|
|
193
|
+
// refused submit, never to the live preview.
|
|
124
194
|
const PREVIEW_EMPTY = '-';
|
|
125
195
|
|
|
126
196
|
// Raw terminal bytes per key id, mirroring pi-tui's legacy sequences so
|
|
@@ -175,7 +245,7 @@ function isKeyRelease(helpers, data) {
|
|
|
175
245
|
}
|
|
176
246
|
|
|
177
247
|
// One printable character, or '' for a control byte, an escape sequence
|
|
178
|
-
// or a key object. The
|
|
248
|
+
// or a key object. The typed-name rule (S6) needs exactly this distinction.
|
|
179
249
|
function printableChar(data) {
|
|
180
250
|
const raw = typeof data === 'string' ? data : (data && (data.name || data.key)) || '';
|
|
181
251
|
if (typeof raw !== 'string') return '';
|
|
@@ -193,25 +263,6 @@ function stripAnsi(text) {
|
|
|
193
263
|
.replace(/\x1b_[^\x07\x1b]*\x07/g, '');
|
|
194
264
|
}
|
|
195
265
|
|
|
196
|
-
// Word wrap for the pane state messages: a narrow list column must still
|
|
197
|
-
// say WHY it is empty instead of clipping the explanation away.
|
|
198
|
-
function wrapText(text, width) {
|
|
199
|
-
const limit = Math.max(1, width);
|
|
200
|
-
const words = String(text).split(/\s+/).filter((word) => word !== '');
|
|
201
|
-
const lines = [];
|
|
202
|
-
let line = '';
|
|
203
|
-
for (const word of words) {
|
|
204
|
-
if (line === '') line = word;
|
|
205
|
-
else if (line.length + 1 + word.length <= limit) line += ` ${word}`;
|
|
206
|
-
else {
|
|
207
|
-
lines.push(line);
|
|
208
|
-
line = word;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (line !== '') lines.push(line);
|
|
212
|
-
return lines.length > 0 ? lines : [''];
|
|
213
|
-
}
|
|
214
|
-
|
|
215
266
|
function measure(helpers, text) {
|
|
216
267
|
try {
|
|
217
268
|
if (helpers && typeof helpers.visibleWidth === 'function') {
|
|
@@ -252,16 +303,17 @@ function pad(helpers, text, width) {
|
|
|
252
303
|
// one used when the full form does not fit, and `priority` decides what a
|
|
253
304
|
// still-too-wide legend drops first (the lowest goes first, so the cancel key
|
|
254
305
|
// outlives the rest).
|
|
255
|
-
// S12:
|
|
256
|
-
// the
|
|
257
|
-
//
|
|
258
|
-
// the user reported as a duplicate of `enter`).
|
|
306
|
+
// S12: `↑/↓` picks from the active list — the types' or the ODDs' — and typing
|
|
307
|
+
// fills the active field's own name, so the legend names both; the ONE confirm
|
|
308
|
+
// key is `enter`.
|
|
259
309
|
const CREATE_KEYS = [
|
|
310
|
+
{ text: 'type to name', short: 'type', priority: 50 },
|
|
260
311
|
{ key: 'tab/←/→', text: 'tab/←/→ fields', short: 'tab/←/→', priority: 70 },
|
|
261
|
-
{ key: '↑/↓', text: '↑/↓
|
|
312
|
+
{ key: '↑/↓', text: '↑/↓ pick', short: '↑/↓', priority: 60 },
|
|
262
313
|
{ key: 'Enter', text: 'Enter confirm', short: 'Enter confirm', priority: 90 },
|
|
263
314
|
{ key: 'Esc', text: 'Esc cancel', short: 'Esc cancel', priority: 100 },
|
|
264
315
|
];
|
|
316
|
+
|
|
265
317
|
function shortError(err) {
|
|
266
318
|
if (err === null || err === undefined) return 'unknown error';
|
|
267
319
|
if (typeof err === 'string') return err.split('\n')[0];
|
|
@@ -273,6 +325,110 @@ function escapeRe(text) {
|
|
|
273
325
|
return String(text).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
274
326
|
}
|
|
275
327
|
|
|
328
|
+
// S2: the offered ODDs are names, not rows: strings only, no blanks, no
|
|
329
|
+
// duplicates, sorted ascending — so the list is the same on every render and on
|
|
330
|
+
// every host, whatever order the caller read them in.
|
|
331
|
+
function normalizeOddOptions(value) {
|
|
332
|
+
if (!Array.isArray(value)) return [];
|
|
333
|
+
const names = value.filter((entry) => typeof entry === 'string' && entry.trim() !== '').map((entry) => entry.trim());
|
|
334
|
+
return [...new Set(names)].sort();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// S5: the checkouts that already exist, as resolved absolute paths. The caller
|
|
338
|
+
// reconciles them (git's live listing plus the registry rows whose directory
|
|
339
|
+
// still exists), so a stale row for a removed checkout is not one of them and an
|
|
340
|
+
// ODD that became free again is offered again. Anything unusable is dropped:
|
|
341
|
+
// this list only ever HIDES a duplicate, and the create refuses a collision on
|
|
342
|
+
// its own.
|
|
343
|
+
function normalizeOccupiedPaths(value) {
|
|
344
|
+
const out = new Set();
|
|
345
|
+
for (const entry of Array.isArray(value) ? value : []) {
|
|
346
|
+
if (typeof entry !== 'string' || entry === '') continue;
|
|
347
|
+
try {
|
|
348
|
+
out.add(path.resolve(entry));
|
|
349
|
+
} catch {
|
|
350
|
+
// An unresolvable spelling names no checkout.
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return [...out];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// BOTH typed fields (the branch name and the `new odd` name) apply this ONE rule
|
|
357
|
+
// before anything is composed from what was typed: one or more consecutive spaces
|
|
358
|
+
// become a single `-`, so `change cost` is `change-cost`. The trim comes
|
|
359
|
+
// FIRST — it is the rule the fields already had — so a space at either end
|
|
360
|
+
// simply vanishes instead of becoming an edge dash, and a name that leaves
|
|
361
|
+
// nothing behind is the empty name it already was (and still refuses with its own
|
|
362
|
+
// words). Nothing else is touched: this is not a slugifier, so accents,
|
|
363
|
+
// punctuation and case keep their existing rules (`<type>/<name>` still refuses an
|
|
364
|
+
// uppercase name, and the ODD rule still refuses a path segment).
|
|
365
|
+
//
|
|
366
|
+
// It is applied where the typed text BECOMES a value — the typed row, the preview
|
|
367
|
+
// and the submit — never while the text is being typed: the raw keystrokes stay
|
|
368
|
+
// in the state so Backspace keeps deleting what a human last typed, and all three
|
|
369
|
+
// readers of that state derive the same name from it. A run still being typed is
|
|
370
|
+
// therefore not yet a dash, which is exactly why the row, the preview and the
|
|
371
|
+
// create cannot disagree.
|
|
372
|
+
function normalizeTypedName(value) {
|
|
373
|
+
return String(value).trim().replace(/\s+/g, '-');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// S2: the create wizard's ODD list — the ODDs that exist in `main`. The ref is
|
|
377
|
+
// named explicitly instead of resolved through `origin/HEAD`, because the list a
|
|
378
|
+
// human picks from must be the base the create starts from: the local `main`.
|
|
379
|
+
const MAIN_REF = 'refs/heads/main';
|
|
380
|
+
const ODD_TASKS_DIR = 'odd/tasks';
|
|
381
|
+
const ODD_DOCUMENT_EXTENSION = '.md';
|
|
382
|
+
const MAIN_ODD_TASKS_ARGS = ['ls-tree', '-r', '--name-only', '-z', MAIN_REF, '--', ODD_TASKS_DIR];
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* S2/S4: the ODD names `main` carries, sorted ascending and without duplicates.
|
|
386
|
+
*
|
|
387
|
+
* `opts.runAsync` is the package convention `(bin, argv, cwd) => Promise<{
|
|
388
|
+
* status, stdout, stderr, error}>`, and `opts.cwd` is any directory of the clone
|
|
389
|
+
* the read runs in. Nothing here is fatal: an absent `odd/tasks` directory, a
|
|
390
|
+
* clone without `main`, a failing child, a runner that throws or no runner at all
|
|
391
|
+
* is an empty list — the picker still opens with its `new odd` entry, which is why
|
|
392
|
+
* an unreadable list is never an error.
|
|
393
|
+
*
|
|
394
|
+
* The read is ONE bounded child, and it is AWAITED by the caller before the panel
|
|
395
|
+
* mounts: the panel itself never spawns, on a render or on a keystroke.
|
|
396
|
+
*/
|
|
397
|
+
async function listMainOddTasks(options) {
|
|
398
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
399
|
+
const runAsync = typeof opts.runAsync === 'function' ? opts.runAsync : null;
|
|
400
|
+
if (runAsync === null) return [];
|
|
401
|
+
const cwd = typeof opts.cwd === 'string' && opts.cwd.length > 0 ? opts.cwd : process.cwd();
|
|
402
|
+
let answer;
|
|
403
|
+
try {
|
|
404
|
+
answer = await runAsync('git', MAIN_ODD_TASKS_ARGS.slice(), cwd);
|
|
405
|
+
} catch {
|
|
406
|
+
return [];
|
|
407
|
+
}
|
|
408
|
+
if (!answer || answer.status !== 0 || typeof answer.stdout !== 'string') return [];
|
|
409
|
+
const names = new Set();
|
|
410
|
+
for (const entry of answer.stdout.split('\0')) {
|
|
411
|
+
if (!entry.startsWith(`${ODD_TASKS_DIR}/`)) continue;
|
|
412
|
+
const name = entry.slice(ODD_TASKS_DIR.length + 1);
|
|
413
|
+
// One path segment directly under odd/tasks, never a nested tree entry, a
|
|
414
|
+
// dotfile or a file that is not a document.
|
|
415
|
+
if (name === '' || name.includes('/') || name.includes('\\') || name.startsWith('.')) continue;
|
|
416
|
+
if (!name.toLowerCase().endsWith(ODD_DOCUMENT_EXTENSION)) continue;
|
|
417
|
+
names.add(name.slice(0, -ODD_DOCUMENT_EXTENSION.length));
|
|
418
|
+
}
|
|
419
|
+
return [...names].sort();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// The window one inline list shows around its cursor: `size` rows starting at
|
|
423
|
+
// `start`, centred on the selection while it can be and clamped to the edges
|
|
424
|
+
// after that, so the focused row is always on screen.
|
|
425
|
+
function listWindow(count, index, size) {
|
|
426
|
+
if (size <= 0) return { start: 0, size: 0 };
|
|
427
|
+
const width = Math.min(count, size);
|
|
428
|
+
const centred = index - Math.floor(width / 2);
|
|
429
|
+
return { start: Math.min(Math.max(0, centred), Math.max(0, count - width)), size: width };
|
|
430
|
+
}
|
|
431
|
+
|
|
276
432
|
function createWarpCreatePanel(options = {}) {
|
|
277
433
|
const opts = options && typeof options === 'object' ? options : {};
|
|
278
434
|
const cwd = typeof opts.cwd === 'string' && opts.cwd.length > 0 ? opts.cwd : process.cwd();
|
|
@@ -284,9 +440,17 @@ function createWarpCreatePanel(options = {}) {
|
|
|
284
440
|
const changeTypes = Array.isArray(opts.changeTypes) && opts.changeTypes.length > 0
|
|
285
441
|
? opts.changeTypes.filter((type) => type && typeof type.id === 'string' && type.id !== '')
|
|
286
442
|
: CHANGE_TYPES.slice();
|
|
287
|
-
const
|
|
288
|
-
? opts.
|
|
289
|
-
:
|
|
443
|
+
const oddPlaceholder = typeof opts.oddPlaceholder === 'string' && opts.oddPlaceholder !== ''
|
|
444
|
+
? opts.oddPlaceholder
|
|
445
|
+
: ODD_PLACEHOLDER;
|
|
446
|
+
const branchPlaceholder = typeof opts.branchPlaceholder === 'string' && opts.branchPlaceholder !== ''
|
|
447
|
+
? opts.branchPlaceholder
|
|
448
|
+
: BRANCH_PLACEHOLDER;
|
|
449
|
+
// S2: the ODDs that exist in `main`, read by the caller that can await the
|
|
450
|
+
// one bounded child (the panel never spawns on a render or a keystroke).
|
|
451
|
+
const oddCandidates = normalizeOddOptions(opts.oddOptions);
|
|
452
|
+
// S5: the checkouts that already exist, already reconciled by the caller.
|
|
453
|
+
const occupiedPaths = normalizeOccupiedPaths(opts.occupiedPaths);
|
|
290
454
|
const rawFinish = typeof opts.done === 'function' ? opts.done : () => {};
|
|
291
455
|
|
|
292
456
|
// The branch format is the repository's own: `<type-of-the-list>/<slug>`,
|
|
@@ -300,20 +464,41 @@ function createWarpCreatePanel(options = {}) {
|
|
|
300
464
|
rawFinish(value);
|
|
301
465
|
};
|
|
302
466
|
|
|
467
|
+
// S5: memoized once per mount — see `oddOptions()` below. Declared here so the
|
|
468
|
+
// `initialOdd` restore below can read the offered list safely.
|
|
469
|
+
let offeredOdds;
|
|
470
|
+
|
|
303
471
|
const state = {
|
|
304
|
-
//
|
|
305
|
-
//
|
|
472
|
+
// S6: `feat` is the first entry of the repository's type list, so index 0 IS
|
|
473
|
+
// the default and an untouched form already previews `feat/`. The type is
|
|
474
|
+
// picked from the inline list, so `typeIndex` IS the selection (there is no
|
|
475
|
+
// second cursor to keep in sync).
|
|
306
476
|
typeIndex: 0,
|
|
307
|
-
|
|
308
|
-
|
|
477
|
+
// S1: the name half of `<type>/<name>` — the Branch field's free text, typed
|
|
478
|
+
// and passed through unchanged.
|
|
479
|
+
branchName: '',
|
|
480
|
+
// S2: `oddIndex` 0 is the `new odd` entry, `1..n` are the offered ODDs.
|
|
481
|
+
oddIndex: 0,
|
|
482
|
+
// The typed ODD of the `new odd` entry; the Odd field's free text.
|
|
483
|
+
newOdd: '',
|
|
484
|
+
focus: 'branch',
|
|
309
485
|
message: '',
|
|
310
486
|
};
|
|
311
487
|
if (typeof opts.initialType === 'string') {
|
|
312
488
|
const at = changeTypes.findIndex((type) => type.id === opts.initialType);
|
|
313
489
|
if (at >= 0) state.typeIndex = at;
|
|
314
490
|
}
|
|
491
|
+
if (typeof opts.initialOdd === 'string' && opts.initialOdd !== '') {
|
|
492
|
+
const at = oddOptions().indexOf(opts.initialOdd);
|
|
493
|
+
// A known ODD selects its row; an unknown one is the new-ODD entry, so a
|
|
494
|
+
// caller can prefill a name that does not exist yet. The prefill is held in
|
|
495
|
+
// the same spelling a typed name has, so a prefilled space can never reach
|
|
496
|
+
// the preview as one thing and the create as another.
|
|
497
|
+
if (at >= 0) state.oddIndex = at + 1;
|
|
498
|
+
else state.newOdd = normalizeTypedName(opts.initialOdd);
|
|
499
|
+
}
|
|
315
500
|
|
|
316
|
-
// One derivation per distinct (type,
|
|
501
|
+
// One derivation per distinct (type, ODD), memoized, so a repaint of an
|
|
317
502
|
// unchanged form derives nothing.
|
|
318
503
|
let deriveCache = { key: null, value: null };
|
|
319
504
|
|
|
@@ -396,123 +581,161 @@ function createWarpCreatePanel(options = {}) {
|
|
|
396
581
|
return identityCache;
|
|
397
582
|
}
|
|
398
583
|
|
|
399
|
-
// The
|
|
400
|
-
//
|
|
401
|
-
// checkout
|
|
402
|
-
//
|
|
403
|
-
|
|
584
|
+
// The destination ROOT the create lays its checkouts in: `<principal>-worktrees`
|
|
585
|
+
// beside the PRINCIPAL checkout under `principalLayout` (the default), the calling
|
|
586
|
+
// checkout's own layout otherwise — exactly what the create path resolves. Only the
|
|
587
|
+
// root is derived here; the DIRECTORY name is the ODD (S7), so the branch's own
|
|
588
|
+
// spelling never reaches the preview.
|
|
589
|
+
function destinationRoot() {
|
|
404
590
|
const identity = repoIdentity();
|
|
591
|
+
let target;
|
|
405
592
|
if (principalLayout) {
|
|
406
|
-
if (identity && typeof git.canonicalWorktreePathOf === 'function')
|
|
407
|
-
if (typeof git.canonicalWorktreePath === 'function')
|
|
593
|
+
if (identity && typeof git.canonicalWorktreePathOf === 'function') target = git.canonicalWorktreePathOf(identity, DESTINATION_PROBE_BRANCH);
|
|
594
|
+
else if (typeof git.canonicalWorktreePath === 'function') target = git.canonicalWorktreePath(cwd, DESTINATION_PROBE_BRANCH);
|
|
408
595
|
} else if (identity && typeof git.worktreePathOf === 'function') {
|
|
409
|
-
|
|
596
|
+
target = git.worktreePathOf(identity, DESTINATION_PROBE_BRANCH);
|
|
410
597
|
}
|
|
411
|
-
|
|
598
|
+
if (typeof target !== 'string' || target === '') target = git.worktreePath(cwd, DESTINATION_PROBE_BRANCH);
|
|
599
|
+
// The layout helper answers `<root>/<slug of the branch>`, so its directory IS
|
|
600
|
+
// the root the ODD completes into — the one function the create derives it from.
|
|
601
|
+
return path.dirname(target);
|
|
412
602
|
}
|
|
413
603
|
|
|
414
|
-
//
|
|
415
|
-
//
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
604
|
+
// S7: `<root>/<odd>`, and nothing else: the root IS the `<repo-name>-worktrees`
|
|
605
|
+
// directory `worktreeDestinationPath` lays a name in, so completing it with the ODD
|
|
606
|
+
// is the same path the create makes, and the "one path segment" rule that guards
|
|
607
|
+
// it is the core's own `isWorktreeSegment`.
|
|
608
|
+
function destinationPathOf(root, odd) {
|
|
609
|
+
return odd === '' ? root : path.join(root, odd);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// S5: the offered ODDs — `main`'s documents minus the ones whose destination a
|
|
613
|
+
// checkout already occupies. Both inputs are fixed for the panel's lifetime and
|
|
614
|
+
// the root is memoized, so this is computed ONCE per mount and a frame stays
|
|
615
|
+
// free of work. A root that cannot be derived filters NOTHING: the create still
|
|
616
|
+
// refuses the collision with its own sentence, and hiding every ODD because one
|
|
617
|
+
// probe failed would be worse than showing a choice the create refuses.
|
|
618
|
+
function oddOptions() {
|
|
619
|
+
if (offeredOdds !== undefined) return offeredOdds;
|
|
620
|
+
if (occupiedPaths.length === 0) {
|
|
621
|
+
offeredOdds = oddCandidates;
|
|
622
|
+
return offeredOdds;
|
|
623
|
+
}
|
|
624
|
+
let root = null;
|
|
424
625
|
try {
|
|
425
|
-
|
|
426
|
-
} catch
|
|
427
|
-
|
|
626
|
+
root = destinationRoot();
|
|
627
|
+
} catch {
|
|
628
|
+
root = null;
|
|
428
629
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
630
|
+
if (typeof root !== 'string' || root === '') {
|
|
631
|
+
offeredOdds = oddCandidates;
|
|
632
|
+
return offeredOdds;
|
|
633
|
+
}
|
|
634
|
+
const taken = new Set(occupiedPaths);
|
|
635
|
+
offeredOdds = oddCandidates.filter((odd) => {
|
|
636
|
+
try {
|
|
637
|
+
return !taken.has(path.resolve(root, odd));
|
|
638
|
+
} catch {
|
|
639
|
+
return true;
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
return offeredOdds;
|
|
440
643
|
}
|
|
441
644
|
|
|
442
|
-
// The
|
|
443
|
-
//
|
|
444
|
-
//
|
|
445
|
-
|
|
446
|
-
|
|
645
|
+
// The ODD the form currently answers: the picked document, or the typed name of
|
|
646
|
+
// the `new odd` entry. Normalized here so every reader (preview, submit) sees the
|
|
647
|
+
// same value the create will receive.
|
|
648
|
+
function selectedOdd() {
|
|
649
|
+
if (state.oddIndex === 0) return normalizeTypedName(state.newOdd);
|
|
650
|
+
return (oddOptions()[state.oddIndex - 1] || '').trim();
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// The live derivation, memoized per distinct (type, name, ODD) and FREE of
|
|
654
|
+
// subprocesses: the branch format the repository publishes, the destination
|
|
655
|
+
// root and the ODD rule are all pure, so painting a keystroke asks git for
|
|
656
|
+
// nothing. Only the plain rejections run here; git's own verdict belongs to the
|
|
657
|
+
// create path, which can await it.
|
|
447
658
|
function derivePreview() {
|
|
448
659
|
const type = currentType();
|
|
449
|
-
const name = state.
|
|
450
|
-
const
|
|
660
|
+
const name = normalizeTypedName(state.branchName);
|
|
661
|
+
const odd = selectedOdd();
|
|
662
|
+
const key = `${type.id}\u0000${name}\u0000${odd}`;
|
|
451
663
|
if (deriveCache.key === key) return deriveCache.value;
|
|
452
|
-
|
|
664
|
+
|
|
665
|
+
// ---- the branch: `<type>/<name>`, the human's own answer (S1), passed
|
|
666
|
+
// through unchanged. An empty name still previews the type's prefix
|
|
667
|
+
// (`branchOk` is what the ROW paints), but it is not submittable, so `ok`
|
|
668
|
+
// stays false: display and validity are two different questions and this is
|
|
669
|
+
// where they part. Nothing derives the name from the ODD — the branch names
|
|
670
|
+
// no directory (R1).
|
|
671
|
+
let branch = null;
|
|
672
|
+
let branchOk = false;
|
|
673
|
+
let branchReason = null;
|
|
453
674
|
if (name === '') {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
675
|
+
branch = `${type.id}/`;
|
|
676
|
+
branchOk = true;
|
|
677
|
+
branchReason = 'branch name is empty';
|
|
678
|
+
} else if (!branchFormat.test(`${type.id}/${name}`)) {
|
|
679
|
+
branchReason = `invalid branch name: ${type.id}/${name}`;
|
|
457
680
|
} else {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
slug = String(typeof git.slugifyBranch === 'function' ? git.slugifyBranch(name) : '');
|
|
461
|
-
} catch {
|
|
462
|
-
slug = '';
|
|
463
|
-
}
|
|
464
|
-
const branch = slug === '' ? '' : `${type.id}/${slug}`;
|
|
465
|
-
if (branch === '' || !branchFormat.test(branch)) {
|
|
466
|
-
value = {
|
|
467
|
-
ok: false,
|
|
468
|
-
branch: branch === '' ? null : branch,
|
|
469
|
-
branchOk: false,
|
|
470
|
-
path: null,
|
|
471
|
-
pathOk: false,
|
|
472
|
-
reason: `invalid branch name: ${branch === '' ? name : branch}`,
|
|
473
|
-
};
|
|
474
|
-
} else {
|
|
475
|
-
let target = null;
|
|
476
|
-
let failure = null;
|
|
477
|
-
try {
|
|
478
|
-
target = layoutFor(branch);
|
|
479
|
-
} catch (err) {
|
|
480
|
-
failure = shortError(err);
|
|
481
|
-
}
|
|
482
|
-
value = typeof target === 'string' && target !== '' && !failure
|
|
483
|
-
? { ok: true, branch, branchOk: true, path: target, pathOk: true, reason: null }
|
|
484
|
-
: {
|
|
485
|
-
ok: false,
|
|
486
|
-
branch,
|
|
487
|
-
branchOk: true,
|
|
488
|
-
path: null,
|
|
489
|
-
pathOk: false,
|
|
490
|
-
reason: `cannot resolve the worktree path: ${failure || 'unknown error'}`,
|
|
491
|
-
};
|
|
492
|
-
}
|
|
681
|
+
branch = `${type.id}/${name}`;
|
|
682
|
+
branchOk = true;
|
|
493
683
|
}
|
|
684
|
+
|
|
685
|
+
// ---- the path: the ODD names it (S7), so the ODD is what completes it. The
|
|
686
|
+
// root alone is what an empty ODD previews; the create always writes one, so
|
|
687
|
+
// an empty ODD stays unsubmittable and is refused with its own words.
|
|
688
|
+
let root = null;
|
|
689
|
+
let rootFailure = null;
|
|
690
|
+
try {
|
|
691
|
+
root = destinationRoot();
|
|
692
|
+
} catch (err) {
|
|
693
|
+
rootFailure = shortError(err);
|
|
694
|
+
}
|
|
695
|
+
const rootOk = typeof root === 'string' && root !== '' && rootFailure === null;
|
|
696
|
+
const oddValid = createLib.isWorktreeSegment(odd);
|
|
697
|
+
const oddReason = odd === ''
|
|
698
|
+
? 'odd is empty'
|
|
699
|
+
: (oddValid ? null : `invalid odd name: ${JSON.stringify(odd)}`);
|
|
700
|
+
const pathOk = rootOk && (odd === '' || oddValid);
|
|
701
|
+
|
|
702
|
+
const value = {
|
|
703
|
+
ok: branchReason === null && oddReason === null && rootOk,
|
|
704
|
+
branch,
|
|
705
|
+
branchOk,
|
|
706
|
+
path: pathOk ? destinationPathOf(root, odd) : null,
|
|
707
|
+
pathOk,
|
|
708
|
+
reason: branchReason
|
|
709
|
+
?? oddReason
|
|
710
|
+
?? (rootOk ? null : `cannot resolve the worktree path: ${rootFailure || 'unknown error'}`),
|
|
711
|
+
};
|
|
494
712
|
deriveCache = { key, value };
|
|
495
713
|
return value;
|
|
496
714
|
}
|
|
497
715
|
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
//
|
|
502
|
-
|
|
716
|
+
// S8/S9: ONE typed-row design, used by BOTH typed fields — the branch name and
|
|
717
|
+
// the `new odd` name. It is the `❯` prompt, the field's own static label, the
|
|
718
|
+
// derived PREFIX the field composes (`feat/`), the typed value, and the caret:
|
|
719
|
+
// with the ghost placeholder while the value is empty, after the typed value
|
|
720
|
+
// otherwise. Every token takes a palette ROLE, so no colour is named here and
|
|
721
|
+
// the prompt + caret still say "type here" on a monochrome terminal.
|
|
722
|
+
function typedRow(width, { label, prefix, value, placeholder }) {
|
|
503
723
|
const caret = { kind: null, text: `${cursorMarker}▊` };
|
|
504
|
-
const segments = [{ kind: '
|
|
505
|
-
if (
|
|
506
|
-
|
|
724
|
+
const segments = [{ kind: 'accent', text: '❯ ' }];
|
|
725
|
+
if (label !== '') segments.push({ kind: 'label', text: label });
|
|
726
|
+
if (prefix !== '') segments.push({ kind: 'label', text: prefix });
|
|
727
|
+
if (value === '') segments.push(caret, { kind: 'description', text: placeholder });
|
|
728
|
+
else segments.push({ kind: 'value', text: value }, caret);
|
|
507
729
|
return composed(segments, width);
|
|
508
730
|
}
|
|
509
731
|
|
|
510
|
-
//
|
|
511
|
-
//
|
|
512
|
-
//
|
|
732
|
+
// S1/S2: the two fields are TABS, not stacked rows — one strip with the active
|
|
733
|
+
// label accented (and bold) and the other dimmed, so "where am I" reads the
|
|
734
|
+
// same everywhere. There is no third tab: the Branch (<type>/<name>) and the Odd
|
|
735
|
+
// (the directory) are the two things a create asks for.
|
|
513
736
|
function tabSegments() {
|
|
514
737
|
const tab = (field, text) => ({ kind: state.focus === field ? 'title' : 'label', text });
|
|
515
|
-
return [tab('
|
|
738
|
+
return [tab('branch', 'Branch'), { kind: null, text: ' · ' }, tab('odd', 'Odd')];
|
|
516
739
|
}
|
|
517
740
|
|
|
518
741
|
function rule(width) {
|
|
@@ -522,17 +745,9 @@ function createWarpCreatePanel(options = {}) {
|
|
|
522
745
|
// S12: the inline change-type list. The SELECTED type (and therefore the
|
|
523
746
|
// preview) follows the cursor, and the list is windowed around it when the
|
|
524
747
|
// host offers fewer rows than the convention has types. The `❯` marker is
|
|
525
|
-
// the same one the
|
|
526
|
-
function typeListWindow(room) {
|
|
527
|
-
const count = changeTypes.length;
|
|
528
|
-
const size = Math.min(count, Math.max(0, room));
|
|
529
|
-
if (size === 0) return { start: 0, size: 0 };
|
|
530
|
-
const centred = state.typeIndex - Math.floor(size / 2);
|
|
531
|
-
return { start: Math.min(Math.max(0, centred), count - size), size };
|
|
532
|
-
}
|
|
533
|
-
|
|
748
|
+
// the same one the ODD list uses, so "where am I" reads the same everywhere.
|
|
534
749
|
function typeListLines(width, room) {
|
|
535
|
-
const { start, size } =
|
|
750
|
+
const { start, size } = listWindow(changeTypes.length, state.typeIndex, room);
|
|
536
751
|
const out = [];
|
|
537
752
|
for (let offset = 0; offset < size; offset += 1) {
|
|
538
753
|
const at = start + offset;
|
|
@@ -544,19 +759,76 @@ function createWarpCreatePanel(options = {}) {
|
|
|
544
759
|
return out;
|
|
545
760
|
}
|
|
546
761
|
|
|
762
|
+
// S7/S8: the Branch field is TWO REGIONS — the typed name row on top (S6), a
|
|
763
|
+
// blank separator, then the eleven types as plain rows. The blank row is the
|
|
764
|
+
// separation the report asked for: it survives monochrome, and it keeps the
|
|
765
|
+
// typed name from reading as the list's first entry.
|
|
766
|
+
function branchFieldLines(width, room) {
|
|
767
|
+
const type = currentType();
|
|
768
|
+
const listRoom = Math.max(1, room - CREATE_REGION_ROWS);
|
|
769
|
+
return [
|
|
770
|
+
typedRow(width, {
|
|
771
|
+
label: '',
|
|
772
|
+
prefix: `${type.id}/`,
|
|
773
|
+
value: normalizeTypedName(state.branchName),
|
|
774
|
+
placeholder: branchPlaceholder,
|
|
775
|
+
}),
|
|
776
|
+
'',
|
|
777
|
+
...typeListLines(width, listRoom),
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// S7/S8: the Odd field is TWO REGIONS as well. `new odd` is the FIRST row and
|
|
782
|
+
// the only entry that takes a typed name, so while it is the focused row it IS
|
|
783
|
+
// the shared typed row — same design, same caret, the typed text in place — and
|
|
784
|
+
// the documents stand alone under the blank separator. While a DOCUMENT is
|
|
785
|
+
// focused there is no input under the list: `new odd` stays a plain row in its
|
|
786
|
+
// place and the documents below are the list. Nothing is echoed anywhere.
|
|
787
|
+
function oddFieldLines(width, room) {
|
|
788
|
+
const typing = state.oddIndex === 0;
|
|
789
|
+
const listRoom = Math.max(1, room - CREATE_REGION_ROWS);
|
|
790
|
+
const head = typing
|
|
791
|
+
? typedRow(width, {
|
|
792
|
+
label: `${NEW_ODD_LABEL}: `,
|
|
793
|
+
prefix: '',
|
|
794
|
+
value: normalizeTypedName(state.newOdd),
|
|
795
|
+
placeholder: oddPlaceholder,
|
|
796
|
+
})
|
|
797
|
+
: composed([{ kind: null, text: ` ${NEW_ODD_LABEL}` }], width);
|
|
798
|
+
return [head, '', ...oddListLines(width, listRoom)];
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// S2/S8/S10: the ODD list. The rows are the DOCUMENTS alone — `new odd` is the
|
|
802
|
+
// input row above the separator, never a document — and the `❯`-marked row is
|
|
803
|
+
// the answer. There is no separate echo row of the picked value.
|
|
804
|
+
function oddListLines(width, room) {
|
|
805
|
+
const options = oddOptions();
|
|
806
|
+
const selected = state.oddIndex - 1;
|
|
807
|
+
const { start, size } = listWindow(options.length, Math.max(0, selected), room);
|
|
808
|
+
const out = [];
|
|
809
|
+
for (let offset = 0; offset < size; offset += 1) {
|
|
810
|
+
const at = start + offset;
|
|
811
|
+
const focused = at === selected;
|
|
812
|
+
const text = `${focused ? '❯ ' : ' '}${options[at]}`;
|
|
813
|
+
const fitted = fit(helpers, text, width);
|
|
814
|
+
out.push(focused ? palette.highlight(theme, fitted, true) : fitted);
|
|
815
|
+
}
|
|
816
|
+
return out;
|
|
817
|
+
}
|
|
818
|
+
|
|
547
819
|
// S12: the create surface is COMPACT — it renders exactly its own content
|
|
548
820
|
// and never pads out to the host's row budget, so the host can mount it at
|
|
549
821
|
// the bottom of the terminal without slack rows above or below it. S7: the
|
|
550
|
-
// preview sits ABOVE the tab strip, only the ACTIVE
|
|
551
|
-
//
|
|
822
|
+
// preview sits ABOVE the tab strip, only the ACTIVE field's region (its typed
|
|
823
|
+
// row, the blank separator, its list) renders under it, and an underivable
|
|
552
824
|
// preview stays blank instead of red.
|
|
553
825
|
function renderCreate(w, maxRows) {
|
|
554
826
|
const messageRows = state.message ? 1 : 0;
|
|
555
|
-
if (maxRows < CREATE_FIXED_ROWS + messageRows) {
|
|
827
|
+
if (maxRows < CREATE_FIXED_ROWS + CREATE_REGION_ROWS + messageRows) {
|
|
556
828
|
return [pad(helpers, kindText('label', 'New worktree — enlarge the terminal'), w)];
|
|
557
829
|
}
|
|
558
830
|
const derived = derivePreview();
|
|
559
|
-
const room = Math.max(
|
|
831
|
+
const room = Math.max(CREATE_REGION_ROWS + 1, maxRows - CREATE_FIXED_ROWS - messageRows);
|
|
560
832
|
const lines = [
|
|
561
833
|
rule(w),
|
|
562
834
|
composed([{ kind: 'title', text: 'New worktree' }], w),
|
|
@@ -570,16 +842,8 @@ function createWarpCreatePanel(options = {}) {
|
|
|
570
842
|
], w),
|
|
571
843
|
composed(tabSegments(), w),
|
|
572
844
|
];
|
|
573
|
-
if (state.focus === '
|
|
574
|
-
|
|
575
|
-
lines.push(composed([
|
|
576
|
-
{ kind: 'label', text: 'Type: ' },
|
|
577
|
-
{ kind: 'value', text: `${type.label} (${type.id})` },
|
|
578
|
-
], w));
|
|
579
|
-
lines.push(...typeListLines(w, room));
|
|
580
|
-
} else {
|
|
581
|
-
lines.push(nameLine(w));
|
|
582
|
-
}
|
|
845
|
+
if (state.focus === 'branch') lines.push(...branchFieldLines(w, room));
|
|
846
|
+
else lines.push(...oddFieldLines(w, room));
|
|
583
847
|
if (state.message) lines.push(composed([{ kind: 'error', text: `cannot create: ${state.message}` }], w));
|
|
584
848
|
lines.push(palette.legendRow(theme, CREATE_KEYS, w, (text) => measure(helpers, text)));
|
|
585
849
|
lines.push(rule(w));
|
|
@@ -605,16 +869,32 @@ function createWarpCreatePanel(options = {}) {
|
|
|
605
869
|
requestPaint();
|
|
606
870
|
return;
|
|
607
871
|
}
|
|
608
|
-
//
|
|
609
|
-
//
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
name: state.name.trim(),
|
|
614
|
-
});
|
|
872
|
+
// S1/S4: a creation carries the branch EXACTLY as composed — created when it
|
|
873
|
+
// is absent, adopted when it exists — and the ODD that names the directory.
|
|
874
|
+
// No `name` (the ODD is the identity) and no `issues` (a brand-new row is
|
|
875
|
+
// born without an issue association).
|
|
876
|
+
finish({ ok: true, branch: derived.branch, odd: selectedOdd() });
|
|
615
877
|
}
|
|
616
878
|
|
|
617
|
-
function
|
|
879
|
+
function moveType(delta) {
|
|
880
|
+
const last = Math.max(0, changeTypes.length - 1);
|
|
881
|
+
state.typeIndex = Math.min(last, Math.max(0, state.typeIndex + delta));
|
|
882
|
+
state.message = '';
|
|
883
|
+
requestPaint();
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function moveOdd(delta) {
|
|
887
|
+
const last = oddOptions().length;
|
|
888
|
+
state.oddIndex = Math.min(last, Math.max(0, state.oddIndex + delta));
|
|
889
|
+
state.message = '';
|
|
890
|
+
requestPaint();
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// S1/S6/S8: the Branch field is a typed name OVER a list, so the same split the
|
|
894
|
+
// Odd field uses applies here: `↑`/`↓` choose the type, every printable
|
|
895
|
+
// character types the name, and Backspace edits it. Nothing is repurposed — a
|
|
896
|
+
// keystroke meant for the name never jumps fields.
|
|
897
|
+
function handleBranchField(data) {
|
|
618
898
|
if (keyText(helpers, data, ['up'])) {
|
|
619
899
|
moveType(-1);
|
|
620
900
|
return;
|
|
@@ -624,54 +904,57 @@ function createWarpCreatePanel(options = {}) {
|
|
|
624
904
|
return;
|
|
625
905
|
}
|
|
626
906
|
if (keyText(helpers, data, ['enter', 'return'])) {
|
|
627
|
-
state.focus = '
|
|
907
|
+
state.focus = 'odd';
|
|
628
908
|
requestPaint();
|
|
629
909
|
return;
|
|
630
910
|
}
|
|
911
|
+
if (keyText(helpers, data, ['backspace', 'delete', '\x7f'])) {
|
|
912
|
+
if (state.branchName !== '') {
|
|
913
|
+
state.branchName = [...state.branchName].slice(0, -1).join('');
|
|
914
|
+
state.message = '';
|
|
915
|
+
requestPaint();
|
|
916
|
+
}
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (keyText(helpers, data, ['pageup', 'pagedown'])) return;
|
|
631
920
|
const char = printableChar(data);
|
|
632
921
|
if (char !== '') {
|
|
633
|
-
state.
|
|
634
|
-
state.name += char;
|
|
922
|
+
state.branchName += char;
|
|
635
923
|
state.message = '';
|
|
636
924
|
requestPaint();
|
|
637
925
|
}
|
|
638
926
|
}
|
|
639
927
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
928
|
+
// S1/S2: only two fields exist while creating (Branch, then Odd), so `tab`,
|
|
929
|
+
// `shift+tab` and both horizontal arrows walk them; a horizontal key at either
|
|
930
|
+
// end wraps to the other end instead of dying.
|
|
931
|
+
function stepCreateField(delta) {
|
|
932
|
+
const at = FIELD_ORDER.indexOf(state.focus);
|
|
933
|
+
const next = (Math.max(0, at) + delta + FIELD_ORDER.length) % FIELD_ORDER.length;
|
|
934
|
+
state.focus = FIELD_ORDER[next];
|
|
644
935
|
requestPaint();
|
|
645
936
|
}
|
|
646
937
|
|
|
647
|
-
//
|
|
648
|
-
//
|
|
649
|
-
//
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
requestPaint();
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
function handleNameField(data) {
|
|
938
|
+
// S2: the ODD field is a LIST with one typed entry. `↑`/`↓` move the cursor
|
|
939
|
+
// through `new odd` and the documents, `enter` creates (the ODD is the LAST
|
|
940
|
+
// field), and editing keys belong to the typed entry alone — a document row
|
|
941
|
+
// has nothing to edit, so a stray keystroke cannot silently rename it.
|
|
942
|
+
function handleOddField(data) {
|
|
656
943
|
if (keyText(helpers, data, ['enter', 'return'])) {
|
|
657
|
-
// S12: the name is the SECOND and LAST field of a creation, so `enter`
|
|
658
|
-
// there creates.
|
|
659
944
|
create();
|
|
660
945
|
return;
|
|
661
946
|
}
|
|
662
947
|
if (keyText(helpers, data, ['down'])) {
|
|
663
|
-
|
|
664
|
-
// stays put.
|
|
948
|
+
moveOdd(1);
|
|
665
949
|
return;
|
|
666
950
|
}
|
|
667
951
|
if (keyText(helpers, data, ['up'])) {
|
|
668
|
-
|
|
669
|
-
requestPaint();
|
|
952
|
+
moveOdd(-1);
|
|
670
953
|
return;
|
|
671
954
|
}
|
|
672
955
|
if (keyText(helpers, data, ['backspace', 'delete', '\x7f'])) {
|
|
673
|
-
if (state.
|
|
674
|
-
state.
|
|
956
|
+
if (state.oddIndex === 0 && state.newOdd !== '') {
|
|
957
|
+
state.newOdd = [...state.newOdd].slice(0, -1).join('');
|
|
675
958
|
state.message = '';
|
|
676
959
|
requestPaint();
|
|
677
960
|
}
|
|
@@ -680,7 +963,8 @@ function createWarpCreatePanel(options = {}) {
|
|
|
680
963
|
if (keyText(helpers, data, ['pageup', 'pagedown'])) return;
|
|
681
964
|
const char = printableChar(data);
|
|
682
965
|
if (char !== '') {
|
|
683
|
-
state.
|
|
966
|
+
if (state.oddIndex !== 0) return;
|
|
967
|
+
state.newOdd += char;
|
|
684
968
|
state.message = '';
|
|
685
969
|
requestPaint();
|
|
686
970
|
}
|
|
@@ -694,21 +978,25 @@ function createWarpCreatePanel(options = {}) {
|
|
|
694
978
|
finish(null);
|
|
695
979
|
return;
|
|
696
980
|
}
|
|
697
|
-
// `tab`, `shift+tab` and the horizontal arrows move between the two
|
|
698
|
-
//
|
|
699
|
-
if (keyText(helpers, data, ['tab', '
|
|
700
|
-
|
|
981
|
+
// `tab`, `shift+tab` and the horizontal arrows move between the two fields,
|
|
982
|
+
// which is what the reported flow asked for (S12).
|
|
983
|
+
if (keyText(helpers, data, ['tab', 'right'])) {
|
|
984
|
+
stepCreateField(1);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (keyText(helpers, data, ['shift+tab', 'left'])) {
|
|
988
|
+
stepCreateField(-1);
|
|
701
989
|
return;
|
|
702
990
|
}
|
|
703
|
-
if (state.focus === '
|
|
704
|
-
|
|
991
|
+
if (state.focus === 'odd') {
|
|
992
|
+
handleOddField(data);
|
|
705
993
|
return;
|
|
706
994
|
}
|
|
707
|
-
|
|
995
|
+
handleBranchField(data);
|
|
708
996
|
}
|
|
709
997
|
|
|
710
|
-
// The panel caches nothing between frames (every line is derived from the
|
|
711
|
-
//
|
|
998
|
+
// The panel caches nothing between frames (every line is derived from the two
|
|
999
|
+
// fields), so a repaint request has nothing to drop; the host seam still
|
|
712
1000
|
// exists because the component contract asks for it.
|
|
713
1001
|
function invalidate() {}
|
|
714
1002
|
|
|
@@ -717,6 +1005,6 @@ function createWarpCreatePanel(options = {}) {
|
|
|
717
1005
|
|
|
718
1006
|
module.exports = {
|
|
719
1007
|
CHANGE_TYPES,
|
|
720
|
-
|
|
1008
|
+
listMainOddTasks,
|
|
721
1009
|
createWarpCreatePanel,
|
|
722
1010
|
};
|