vc-extras 0.1.0 → 0.1.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.
Files changed (249) hide show
  1. package/README.md +128 -71
  2. package/agent-install.mjs +159 -0
  3. package/agents/tester.md +23 -23
  4. package/install-extras.mjs +41 -109
  5. package/install-menu.mjs +22 -43
  6. package/install-skills.mjs +112 -112
  7. package/package.json +72 -28
  8. package/plugin-registry.mjs +73 -0
  9. package/plugins/config-ui/index.ts +159 -159
  10. package/plugins/config-ui/lib/arguments.mjs +24 -24
  11. package/plugins/config-ui/lib/documents.mjs +67 -67
  12. package/plugins/config-ui/lib/frontmatter.mjs +91 -91
  13. package/plugins/config-ui/lib/open.mjs +16 -16
  14. package/plugins/config-ui/lib/ownership.mjs +99 -99
  15. package/plugins/config-ui/lib/page.mjs +11 -11
  16. package/plugins/config-ui/lib/patch.mjs +35 -35
  17. package/plugins/config-ui/lib/paths.mjs +14 -14
  18. package/plugins/config-ui/lib/plugin-fields.mjs +86 -86
  19. package/plugins/config-ui/lib/plugin-validation.mjs +28 -28
  20. package/plugins/config-ui/lib/redaction.mjs +8 -8
  21. package/plugins/config-ui/lib/registry.mjs +282 -282
  22. package/plugins/config-ui/lib/secrets.mjs +44 -44
  23. package/plugins/config-ui/lib/server.mjs +250 -250
  24. package/plugins/config-ui/lib/sources.mjs +96 -96
  25. package/plugins/config-ui/lib/state.mjs +156 -156
  26. package/plugins/config-ui/lib/themes.mjs +113 -113
  27. package/plugins/config-ui/lib/writer.mjs +690 -690
  28. package/plugins/config-ui/project-local-owner.ts +106 -106
  29. package/plugins/config-ui/vc-extras.plugin.json +13 -0
  30. package/plugins/config-ui/web/app.mjs +997 -997
  31. package/plugins/config-ui/web/index.html +342 -342
  32. package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
  33. package/plugins/pi-btw/vc-extras.plugin.json +12 -0
  34. package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
  35. package/plugins/pi-fff/vc-extras.plugin.json +12 -0
  36. package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
  37. package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
  38. package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
  39. package/plugins/vc-ask/claude-hook.mjs +37 -0
  40. package/plugins/vc-ask/codex-native.mjs +28 -0
  41. package/plugins/vc-ask/host-channel.mjs +75 -0
  42. package/plugins/vc-ask/index.ts +57 -0
  43. package/plugins/vc-ask/native-questions.mjs +33 -0
  44. package/plugins/vc-ask/package.json +10 -0
  45. package/plugins/vc-ask/payload.ts +170 -0
  46. package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
  47. package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
  48. package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
  49. package/plugins/vc-ask/questionnaire/config.ts +180 -0
  50. package/plugins/vc-ask/questionnaire/events.ts +154 -0
  51. package/plugins/vc-ask/questionnaire/execute.ts +688 -0
  52. package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
  53. package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
  54. package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
  55. package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
  56. package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
  57. package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
  58. package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
  59. package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
  60. package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
  61. package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
  62. package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
  63. package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
  64. package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
  65. package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
  66. package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
  67. package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
  68. package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
  69. package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
  70. package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
  71. package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
  72. package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
  73. package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
  74. package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
  75. package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
  76. package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
  77. package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
  78. package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
  79. package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
  80. package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
  81. package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
  82. package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
  83. package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
  84. package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
  85. package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
  86. package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
  87. package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
  88. package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
  89. package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
  90. package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
  91. package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
  92. package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
  93. package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
  94. package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
  95. package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
  96. package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
  97. package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
  98. package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
  99. package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
  100. package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
  101. package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
  102. package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
  103. package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
  104. package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
  105. package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
  106. package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
  107. package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
  108. package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
  109. package/plugins/vc-ask/user-input-events.ts +34 -0
  110. package/plugins/vc-ask/vc-extras.plugin.json +18 -0
  111. package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
  112. package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
  113. package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
  114. package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
  115. package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
  116. package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
  117. package/plugins/vc-footer/agents/codex/native.mjs +19 -0
  118. package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
  119. package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
  120. package/plugins/vc-footer/agents/pi/index.js +84 -0
  121. package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
  122. package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
  123. package/plugins/vc-footer/core/data.mjs +218 -0
  124. package/plugins/vc-footer/core/render.mjs +291 -0
  125. package/plugins/vc-footer/core/types.d.ts +29 -0
  126. package/plugins/vc-footer/package.json +22 -0
  127. package/plugins/vc-footer/vc-extras.plugin.json +32 -0
  128. package/skills/animate/LICENSE +21 -21
  129. package/skills/animate/RECIPES.md +324 -324
  130. package/skills/animate/SKILL.md +208 -208
  131. package/skills/animate/UPSTREAM.md +19 -19
  132. package/skills/animation-performance/LICENSE +21 -21
  133. package/skills/animation-performance/SKILL.md +223 -223
  134. package/skills/animation-performance/UPSTREAM.md +19 -19
  135. package/skills/answer-me-with-html/SKILL.md +174 -174
  136. package/skills/answer-me-with-html/scripts/am.mjs +12896 -12896
  137. package/skills/apple-design/LICENSE +21 -21
  138. package/skills/apple-design/SKILL.md +291 -291
  139. package/skills/apple-design/UPSTREAM.md +19 -19
  140. package/skills/bad-smell/SKILL.md +44 -44
  141. package/skills/commit/SKILL.md +90 -90
  142. package/skills/emil-design-eng/LICENSE +21 -21
  143. package/skills/emil-design-eng/SKILL.md +677 -677
  144. package/skills/emil-design-eng/UPSTREAM.md +19 -19
  145. package/skills/find-the-truth/SKILL.md +38 -38
  146. package/skills/find-the-truth/references/trace-method.md +48 -48
  147. package/skills/find-the-truth/references/truth-method.md +39 -39
  148. package/skills/gestures/LICENSE +21 -21
  149. package/skills/gestures/SKILL.md +107 -107
  150. package/skills/gestures/UPSTREAM.md +19 -19
  151. package/skills/humanizer-zh/LICENSE +21 -21
  152. package/skills/humanizer-zh/SKILL.md +409 -409
  153. package/skills/humanizer-zh/UPSTREAM.md +7 -7
  154. package/skills/impeccable/LICENSE +191 -191
  155. package/skills/impeccable/NOTICE.md +11 -11
  156. package/skills/impeccable/SKILL.md +89 -89
  157. package/skills/impeccable/licenses/modern-screenshot-MIT.txt +8 -8
  158. package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -21
  159. package/skills/impeccable/reference/adapt.md +318 -318
  160. package/skills/impeccable/reference/adapt.native.md +58 -58
  161. package/skills/impeccable/reference/android.md +46 -46
  162. package/skills/impeccable/reference/animate.md +89 -89
  163. package/skills/impeccable/reference/audit.md +139 -139
  164. package/skills/impeccable/reference/audit.native.md +139 -139
  165. package/skills/impeccable/reference/bolder.md +33 -33
  166. package/skills/impeccable/reference/clarify.md +94 -94
  167. package/skills/impeccable/reference/colorize.md +86 -86
  168. package/skills/impeccable/reference/component-review.md +63 -63
  169. package/skills/impeccable/reference/craft-floor.md +44 -44
  170. package/skills/impeccable/reference/craft.md +5 -5
  171. package/skills/impeccable/reference/critique.md +819 -819
  172. package/skills/impeccable/reference/degraded/asset-producer.md +41 -41
  173. package/skills/impeccable/reference/degraded/documenter.md +23 -23
  174. package/skills/impeccable/reference/degraded/finish-reviewer.md +37 -37
  175. package/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -92
  176. package/skills/impeccable/reference/delight.md +70 -70
  177. package/skills/impeccable/reference/distill.md +111 -111
  178. package/skills/impeccable/reference/doctor.md +54 -54
  179. package/skills/impeccable/reference/document.md +416 -416
  180. package/skills/impeccable/reference/extract.md +69 -69
  181. package/skills/impeccable/reference/generate.md +101 -101
  182. package/skills/impeccable/reference/harden.md +362 -362
  183. package/skills/impeccable/reference/hooks.md +114 -114
  184. package/skills/impeccable/reference/init.md +131 -131
  185. package/skills/impeccable/reference/ios.md +51 -51
  186. package/skills/impeccable/reference/layout.md +84 -84
  187. package/skills/impeccable/reference/live-setup.md +104 -104
  188. package/skills/impeccable/reference/live.md +327 -327
  189. package/skills/impeccable/reference/mode-operate.md +21 -21
  190. package/skills/impeccable/reference/mode-persuade.md +19 -19
  191. package/skills/impeccable/reference/mode-read.md +21 -21
  192. package/skills/impeccable/reference/new-work.md +152 -152
  193. package/skills/impeccable/reference/onboard.md +234 -234
  194. package/skills/impeccable/reference/operate.md +61 -61
  195. package/skills/impeccable/reference/optimize.md +257 -257
  196. package/skills/impeccable/reference/overdrive.md +127 -127
  197. package/skills/impeccable/reference/polish.md +105 -105
  198. package/skills/impeccable/reference/quieter.md +99 -99
  199. package/skills/impeccable/reference/region-map.md +26 -26
  200. package/skills/impeccable/reference/routing.md +24 -24
  201. package/skills/impeccable/reference/shape.md +59 -59
  202. package/skills/impeccable/reference/typeset.md +90 -90
  203. package/skills/impeccable/reference/visualize.md +47 -47
  204. package/skills/impeccable/scripts/VERSION +1 -1
  205. package/skills/impeccable/scripts/command-metadata.json +98 -98
  206. package/skills/impeccable/scripts/data/font-index-failures.json +120 -120
  207. package/skills/impeccable/scripts/engine-checksums.txt +9 -9
  208. package/skills/impeccable/scripts/impeccable +249 -249
  209. package/skills/impeccable/scripts/impeccable.cmd +278 -278
  210. package/skills/impeccable/scripts/live-browser-dom.js +320 -320
  211. package/skills/impeccable/scripts/live-browser-ignores.js +246 -246
  212. package/skills/impeccable/scripts/live-browser-session.js +183 -183
  213. package/skills/impeccable/scripts/live-browser.js +13862 -13862
  214. package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -14
  215. package/skills/improve-animations/AUDIT.md +115 -115
  216. package/skills/improve-animations/LICENSE +21 -21
  217. package/skills/improve-animations/PLAN-TEMPLATE.md +73 -73
  218. package/skills/improve-animations/SKILL.md +110 -110
  219. package/skills/improve-animations/UPSTREAM.md +19 -19
  220. package/skills/pick-ui-library/LICENSE +21 -21
  221. package/skills/pick-ui-library/SKILL.md +85 -85
  222. package/skills/pick-ui-library/UPSTREAM.md +19 -19
  223. package/skills/review-animations/LICENSE +21 -21
  224. package/skills/review-animations/SKILL.md +120 -120
  225. package/skills/review-animations/STANDARDS.md +187 -187
  226. package/skills/review-animations/UPSTREAM.md +19 -19
  227. package/skills/test/SKILL.md +29 -29
  228. package/skills/test/references/test-method.md +60 -60
  229. package/skills/write-doc/SKILL.md +115 -115
  230. package/skills/write-doc/examples/result-report.md +53 -53
  231. package/skills/write-doc/examples/task-summary.md +45 -45
  232. package/skills/write-doc/references/terminology.md +147 -147
  233. package/specs/ask-host-protocol-v1.md +58 -0
  234. package/specs/design-demo.md +1102 -1102
  235. package/specs/frontend-immersive.md +28 -28
  236. package/specs/plugin-install-v2.md +123 -0
  237. package/specs/plugin-install.md +38 -0
  238. package/specs/web-modes/explore.md +31 -31
  239. package/specs/web-modes/risk.md +15 -15
  240. package/specs/web-modes/verify.md +16 -16
  241. package/vc-extras.mjs +46 -62
  242. package/plugins/essrj/context.ts +0 -47
  243. package/plugins/essrj/data.ts +0 -190
  244. package/plugins/essrj/index.ts +0 -139
  245. package/plugins/essrj/package.json +0 -12
  246. package/plugins/essrj/project-local-owner.ts +0 -106
  247. package/plugins/essrj/render.ts +0 -217
  248. package/plugins/essrj/types.ts +0 -40
  249. package/plugins.json +0 -38
@@ -0,0 +1,131 @@
1
+ /** Panel geometry in terminal cells. `col`/`row` are 0-based screen coordinates. */
2
+ export interface PanelGeometry {
3
+ col: number;
4
+ row: number;
5
+ w: number;
6
+ h: number;
7
+ }
8
+
9
+ export interface TerminalSize {
10
+ columns: number;
11
+ rows: number;
12
+ }
13
+
14
+ /** Chrome rows the panel always needs: top border + one padding row + bottom border. */
15
+ export const PANEL_CHROME_ROWS = 3;
16
+ /** Left/right padding inside the border, in cells. */
17
+ export const PANEL_PADDING_X = 2;
18
+
19
+ export const FLOAT_MIN_COLS = 40;
20
+ export const FLOAT_MIN_ROWS = 12;
21
+ /** Floating panels leave one column of breathing room on the right edge. */
22
+ export const FLOAT_EDGE_GAP = 1;
23
+ export const FLOAT_WIDTH_RATIO = 0.7;
24
+ export const FLOAT_HEIGHT_RATIO = 0.8;
25
+ /** A dragged panel must keep this much of its top border on screen. */
26
+ export const FLOAT_GRAB_COLS = 10;
27
+
28
+ export const DOCK_MIN_ROWS = 7;
29
+ export const DOCK_HEIGHT_RATIO = 0.45;
30
+ /** Rows the transcript keeps for itself while a docked panel is open. */
31
+ export const DOCK_RESERVED_ROWS = 6;
32
+
33
+ export function clamp(value: number, min: number, max: number): number {
34
+ return Math.max(min, Math.min(value, max));
35
+ }
36
+
37
+ /** Tallest a docked panel may become on this terminal, always leaving the transcript its rows. */
38
+ export function dockCapacity(size: TerminalSize): number {
39
+ const room = size.rows - DOCK_RESERVED_ROWS;
40
+ if (room < DOCK_MIN_ROWS) return Math.min(DOCK_MIN_ROWS, size.rows);
41
+ return Math.min(Math.round(size.rows * DOCK_HEIGHT_RATIO), room);
42
+ }
43
+
44
+ /** Default floating geometry: centred, 70% × 80%; views fit their content within the viewport. */
45
+ export function floatDefault(size: TerminalSize): PanelGeometry {
46
+ const w = clamp(Math.round(size.columns * FLOAT_WIDTH_RATIO), Math.min(FLOAT_MIN_COLS, size.columns), size.columns);
47
+ const h = clamp(Math.round(size.rows * FLOAT_HEIGHT_RATIO), Math.min(FLOAT_MIN_ROWS, size.rows), size.rows);
48
+ return {
49
+ col: Math.max(0, Math.floor((size.columns - w) / 2)),
50
+ row: Math.max(0, Math.round((size.rows - h) / 2)),
51
+ w,
52
+ h,
53
+ };
54
+ }
55
+
56
+ /** Initial form bounds; explicit resizing and maximization remain available. */
57
+ export function formDefault(size: TerminalSize, preferred = floatDefault(size)): PanelGeometry {
58
+ const w = clamp(preferred.w, Math.ceil(size.columns * 0.5), Math.max(1, Math.round(size.columns * 0.7)));
59
+ const h = clamp(preferred.h, Math.ceil(size.rows * 0.6), Math.max(1, Math.round(size.rows * 0.8)));
60
+ return { w, h, col: clamp(preferred.col, 0, Math.max(0, size.columns - w)), row: clamp(preferred.row, 0, Math.max(0, size.rows - h)) };
61
+ }
62
+
63
+ /** Native overlays stay inside the viewport; keep state and host hit rectangles identical. */
64
+ export function clampFloat(geo: PanelGeometry, size: TerminalSize): PanelGeometry {
65
+ const w = clamp(geo.w, Math.min(FLOAT_MIN_COLS, size.columns), size.columns);
66
+ const h = clamp(geo.h, Math.min(FLOAT_MIN_ROWS, size.rows), size.rows);
67
+ return {
68
+ w,
69
+ h,
70
+ col: clamp(geo.col, 0, Math.max(0, size.columns - w)),
71
+ row: clamp(geo.row, 0, Math.max(0, size.rows - h)),
72
+ };
73
+ }
74
+
75
+ /** Full-screen maximised panel, flush with every edge. */
76
+ export function maximize(size: TerminalSize): PanelGeometry {
77
+ return { col: 0, row: 0, w: size.columns, h: size.rows };
78
+ }
79
+
80
+ /** Rows a docked panel of this height can show, on top of the fixed chrome. */
81
+ export function formDockCapacity(size: TerminalSize): number {
82
+ return Math.max(dockCapacity(size), Math.min(18, Math.max(0, size.rows - DOCK_RESERVED_ROWS)));
83
+ }
84
+ export function clampDockRows(rows: number, size: TerminalSize, form = false): number {
85
+ return clamp(rows, Math.min(DOCK_MIN_ROWS, size.rows), form ? formDockCapacity(size) : dockCapacity(size));
86
+ }
87
+
88
+ /** Content rows a panel of this height can show, on top of the fixed chrome. */
89
+ export function bodyHeight(panelHeight: number): number {
90
+ return Math.max(0, panelHeight - PANEL_CHROME_ROWS);
91
+ }
92
+
93
+ /**
94
+ * Does this content fit the dock, or does it need the floating form?
95
+ * `contentRows` counts preview rows plus the option block the caller will draw.
96
+ */
97
+ export function fitsDock(contentRows: number, size: TerminalSize): boolean {
98
+ return contentRows + PANEL_CHROME_ROWS <= dockCapacity(size);
99
+ }
100
+
101
+ /** Floating geometry from state, clamped to the current terminal. */
102
+ export function floatPanel(state: PanelState, size: TerminalSize): PanelGeometry {
103
+ return clampFloat(state.panel ?? floatDefault(size), size);
104
+ }
105
+
106
+ /**
107
+ * Docked panel rect: full width on the bottom edge, as tall as the content or the
108
+ * user's setting allows. The transcript above it is never covered.
109
+ */
110
+ export function dockPanel(state: PanelState, size: TerminalSize, contentRows: number): PanelGeometry {
111
+ const natural = contentRows + PANEL_CHROME_ROWS;
112
+ const h = clamp(state.dockRows ?? natural, Math.min(DOCK_MIN_ROWS, size.rows), dockCapacity(size));
113
+ return { col: 0, row: Math.max(0, size.rows - h), w: size.columns, h };
114
+ }
115
+
116
+ /** State fields the geometry helpers read. Kept structural so views and tests can pass partial state. */
117
+ export interface PanelState {
118
+ panelForm?: "dock" | "float";
119
+ panel?: PanelGeometry;
120
+ restorePanel?: PanelGeometry | null;
121
+ dockRows?: number | null;
122
+ }
123
+
124
+ export function isDocked(state: PanelState): boolean {
125
+ return state.panelForm === "dock";
126
+ }
127
+
128
+ /** Panel rect for either form; `contentRows` only matters while docked. */
129
+ export function panelRect(state: PanelState, size: TerminalSize, contentRows: number): PanelGeometry {
130
+ return isDocked(state) ? dockPanel(state, size, contentRows) : floatPanel(state, size);
131
+ }
@@ -0,0 +1,382 @@
1
+ import { Key, matchesKey } from "@earendil-works/pi-tui";
2
+ import { routeVertical, type VerticalAction } from "./vertical.js";
3
+ import { hasQuestionLevelPreview } from "../question-preview.js";
4
+ import type { QuestionAnswer } from "../tool/types.js";
5
+ import { ROW_INTENT_META } from "./row-intent.js";
6
+ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
7
+
8
+ const KEYBIND_UP = "tui.select.up";
9
+ const KEYBIND_DOWN = "tui.select.down";
10
+ const KEYBIND_CONFIRM = "tui.select.confirm";
11
+ const KEYBIND_CANCEL = "tui.select.cancel";
12
+ const KEYBIND_NEW_LINE = "tui.input.newLine";
13
+ const KEYBIND_EDITOR_UP = "tui.editor.cursorUp";
14
+ const KEYBIND_EDITOR_DOWN = "tui.editor.cursorDown";
15
+ const KEYBIND_CLEAR = "tui.editor.deleteToLineStart";
16
+ const KEYBIND_EXTERNAL_EDITOR = "app.editor.external";
17
+
18
+ const NOTES_ACTIVATE_KEY = "n";
19
+ const SPACE_KEY = " ";
20
+
21
+ /**
22
+ * Preview paging keys. Full-screen Pi claims bare `pageUp`/`pageDown` and the mouse
23
+ * wheel for transcript scrolling; the questionnaire listener also checks these keys
24
+ * first and uses the ctrl variants for long previews while the card is active.
25
+ */
26
+ const PREVIEW_PAGE_UP = Key.ctrl("pageUp");
27
+ const PREVIEW_PAGE_DOWN = Key.ctrl("pageDown");
28
+
29
+ export type QuestionnaireAction = VerticalAction
30
+ | { kind: "nav"; nextIndex: number; inputValue: string }
31
+ | { kind: "input_clear" }
32
+ | { kind: "input_edit"; value: string }
33
+ | { kind: "input_replace"; value: string }
34
+ | { kind: "tab_switch"; nextTab: number }
35
+ | { kind: "confirm"; answer: QuestionAnswer; autoAdvanceTab?: number }
36
+ | { kind: "toggle"; index: number }
37
+ | { kind: "multi_confirm"; selected: string[]; autoAdvanceTab?: number }
38
+ | { kind: "cancel" }
39
+ | { kind: "notes_enter" }
40
+ | { kind: "notes_exit" }
41
+ | { kind: "submit" }
42
+ | { kind: "submit_nav"; nextIndex: 0 | 1 }
43
+ | { kind: "notes_forward"; data: string }
44
+ | { kind: "preview_scroll"; offset: number }
45
+ /** Panel geometry actions, driven by mouse drags and the `alt` key bindings. */
46
+ | { kind: "panel_move"; col: number; row: number }
47
+ | { kind: "panel_resize"; w: number; h: number }
48
+ | { kind: "panel_maximize" }
49
+ | { kind: "panel_reset" }
50
+ | { kind: "panel_promote" }
51
+ | { kind: "dock_resize"; rows: number }
52
+ /** Flip `state.collapsed`. Always available, regardless of inner mode (see top intercept in `routeKey`). */
53
+ | { kind: "toggle_collapsed" }
54
+ | { kind: "ignore" };
55
+
56
+ export function wrapTab(index: number, total: number): number {
57
+ if (total <= 0) return 0;
58
+ return ((index % total) + total) % total;
59
+ }
60
+
61
+ export function allAnswered(state: QuestionnaireState, runtime: QuestionnaireRuntime): boolean {
62
+ if (runtime.questions.length === 0) return false;
63
+ for (let i = 0; i < runtime.questions.length; i++) {
64
+ if (!state.answers.has(i)) return false;
65
+ }
66
+ return true;
67
+ }
68
+
69
+ function totalTabs(runtime: QuestionnaireRuntime): number {
70
+ return runtime.isMulti ? runtime.questions.length + 1 : 1;
71
+ }
72
+
73
+ function computeAutoAdvanceTab(state: QuestionnaireState, runtime: QuestionnaireRuntime): number | undefined {
74
+ if (!runtime.isMulti) return undefined;
75
+ if (state.currentTab < runtime.questions.length - 1) return state.currentTab + 1;
76
+ return runtime.questions.length;
77
+ }
78
+
79
+ function buildSingleSelectAnswer(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionAnswer | null {
80
+ const q = runtime.questions[state.currentTab];
81
+ if (!q) return null;
82
+
83
+ const item = runtime.currentItem;
84
+
85
+ if (state.inputMode) {
86
+ const label = runtime.inputBuffer;
87
+ return {
88
+ questionIndex: state.currentTab,
89
+ question: q.question,
90
+ kind: "custom",
91
+ answer: label.length > 0 ? label : null,
92
+ };
93
+ }
94
+ if (!item) return null;
95
+ if (item.kind === "other") {
96
+ return null;
97
+ }
98
+ if (item.kind === "next") {
99
+ return null;
100
+ }
101
+ return {
102
+ questionIndex: state.currentTab,
103
+ question: q.question,
104
+ kind: "option",
105
+ answer: item.label,
106
+ };
107
+ }
108
+
109
+ function buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRuntime): string[] {
110
+ const q = runtime.questions[state.currentTab];
111
+ if (!q) return [];
112
+ const out: string[] = [];
113
+ for (let i = 0; i < q.options.length; i++) {
114
+ if (state.multiSelectChecked.has(i)) {
115
+ const label = q.options[i]?.label;
116
+ if (typeof label === "string") out.push(label);
117
+ }
118
+ }
119
+ return out;
120
+ }
121
+
122
+ function tabSwitchAction(
123
+ data: string,
124
+ state: QuestionnaireState,
125
+ runtime: QuestionnaireRuntime,
126
+ ): QuestionnaireAction | null {
127
+ if (!runtime.isMulti) return null;
128
+ const total = totalTabs(runtime);
129
+ if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {
130
+ return { kind: "tab_switch", nextTab: wrapTab(state.currentTab + 1, total) };
131
+ }
132
+ if (matchesKey(data, Key.shift("tab")) || matchesKey(data, Key.left)) {
133
+ return { kind: "tab_switch", nextTab: wrapTab(state.currentTab - 1, total) };
134
+ }
135
+ return null;
136
+ }
137
+
138
+ // DOWN at the last item wraps to the first (cycle through [option0, …, optionLast]).
139
+ function nextNavOnDown(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
140
+ return {
141
+ kind: "nav",
142
+ nextIndex: wrapTab(state.optionIndex + 1, Math.max(1, runtime.items.length)),
143
+ inputValue: runtime.inputBuffer,
144
+ };
145
+ }
146
+
147
+ // UP at the first item wraps to the last (symmetric with nextNavOnDown).
148
+ function prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
149
+ return {
150
+ kind: "nav",
151
+ nextIndex: wrapTab(state.optionIndex - 1, Math.max(1, runtime.items.length)),
152
+ inputValue: runtime.inputBuffer,
153
+ };
154
+ }
155
+
156
+ export type TerminalScrollIntent =
157
+ | { kind: "page"; direction: -1 | 1 }
158
+ | { kind: "lines"; lines: number };
159
+
160
+ /** Decode page and wheel inputs so the active question preview can consume them when needed. */
161
+ export function terminalScrollIntent(data: string): TerminalScrollIntent | undefined {
162
+ if (matchesKey(data, Key.pageUp) || matchesKey(data, PREVIEW_PAGE_UP)) {
163
+ return { kind: "page", direction: -1 };
164
+ }
165
+ if (matchesKey(data, Key.pageDown) || matchesKey(data, PREVIEW_PAGE_DOWN)) {
166
+ return { kind: "page", direction: 1 };
167
+ }
168
+
169
+ let button: number | undefined;
170
+ const sgr = /^\x1b\[<(\d+);\d+;\d+[Mm]$/.exec(data);
171
+ if (sgr) button = Number.parseInt(sgr[1]!, 10);
172
+ else if (data.length === 6 && data.startsWith("\x1b[M")) button = data.charCodeAt(3) - 32;
173
+ if (button === undefined || (button & 64) === 0) return undefined;
174
+ const direction = button & 3;
175
+ if (direction === 0) return { kind: "lines", lines: -3 };
176
+ if (direction === 1) return { kind: "lines", lines: 3 };
177
+ return undefined;
178
+ }
179
+
180
+ export function previewScrollAction(
181
+ state: QuestionnaireState,
182
+ runtime: QuestionnaireRuntime,
183
+ lines: number,
184
+ ): QuestionnaireAction | null {
185
+ const question = runtime.questions[state.currentTab];
186
+ if (
187
+ !(hasQuestionLevelPreview(question) || (runtime.vertical && question?.options.some(option => option.preview))) ||
188
+ state.collapsed ||
189
+ (!runtime.document && !runtime.vertical && (state.notesVisible || state.inputMode)) ||
190
+ runtime.viewport.maxScrollStart <= 0 ||
191
+ !Number.isFinite(lines)
192
+ ) {
193
+ return null;
194
+ }
195
+ const offset = Math.max(
196
+ 0,
197
+ Math.min(runtime.viewport.maxScrollStart, runtime.viewport.scrollStart + Math.trunc(lines)),
198
+ );
199
+ // Already at either boundary: report "not handled" instead of claiming a no-op scroll,
200
+ // so hosts (and `scrollPreviewBy`'s caller) keep the keystroke.
201
+ if (offset === runtime.viewport.scrollStart) return null;
202
+ return { kind: "preview_scroll", offset };
203
+ }
204
+
205
+ export function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
206
+ if (runtime.document && runtime.keybindings.matches(data, KEYBIND_CANCEL)) {
207
+ if (state.notesVisible) return { kind: "notes_exit" };
208
+ if (state.inputMode) return { kind: "list_rollback" };
209
+ return { kind: "cancel" };
210
+ }
211
+ if (runtime.document && runtime.keybindings.matches(data, KEYBIND_CONFIRM) && runtime.currentItem?.label === "Cancel") {
212
+ return { kind: "list_focus", question: state.currentTab, index: 0 };
213
+ }
214
+ const kb = runtime.keybindings;
215
+
216
+ // Collapse/expand is intercepted before inner questionnaire modes so it works from
217
+ // notes, inline input, submit review, and multi-select. The terminal input listener
218
+ // routes it to the active session and mirrors the reducer state into the transcript entry.
219
+ //
220
+ // The default `ctrl+]` is free in every mainstream macOS terminal (Terminal.app,
221
+ // iTerm2, Warp), every multiplexer (tmux, zellij, screen — none use it as a prefix),
222
+ // and the legacy telnet/ssh escape role doesn't apply because Emma handles the key
223
+ // in-process. It is, however, awkward on keyboard layouts where `]` is on the
224
+ // shifted layer (Latin American `es-AR`/`es-MX` require `Ctrl+Shift+}` for `Ctrl+]`)
225
+ // — use the `collapseKey` config field to override.
226
+ // Treat a missing/non-string key as disabled. This can occur at runtime when
227
+ // a long-lived Pi process retains an older outer module while a package update
228
+ // replaces the lazily imported QuestionnaireSession graph on disk. Passing
229
+ // undefined into matchesKey reaches parseKeyId().toLowerCase() and crashes the
230
+ // entire host process, so keep the runtime boundary defensive even though the
231
+ // TypeScript contract requires a string.
232
+ if (
233
+ typeof runtime.collapseKey === "string" &&
234
+ runtime.collapseKey !== "off" &&
235
+ matchesKey(data, runtime.collapseKey as Parameters<typeof matchesKey>[1])
236
+ ) {
237
+ return { kind: "toggle_collapsed" };
238
+ }
239
+
240
+ // While collapsed, prevent keystrokes from mutating answers or notes. Non-cancel
241
+ // keys return `ignore`, allowing the host to handle transcript scrolling and other input.
242
+ if (state.collapsed) {
243
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
244
+ return { kind: "ignore" };
245
+ }
246
+
247
+ if (runtime.vertical) return routeVertical(data, state, runtime);
248
+
249
+ if (runtime.document && !state.collapsed) {
250
+ if (matchesKey(data, PREVIEW_PAGE_UP) || matchesKey(data, PREVIEW_PAGE_DOWN)) {
251
+ const direction = matchesKey(data, PREVIEW_PAGE_UP) ? -1 : 1;
252
+ return previewScrollAction(state, runtime, direction * Math.max(1, runtime.viewport.pageSize - 1)) ?? { kind: "ignore" };
253
+ }
254
+ if (!state.notesVisible && (matchesKey(data, Key.tab) || matchesKey(data, Key.shift("tab")))) {
255
+ return matchesKey(data, Key.tab) ? nextNavOnDown(state, runtime) : prevNavOnUp(state, runtime);
256
+ }
257
+ }
258
+
259
+ if (state.notesVisible) {
260
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "notes_exit" };
261
+ if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "notes_forward", data };
262
+ if (kb.matches(data, KEYBIND_CONFIRM)) return { kind: "notes_exit" };
263
+ return { kind: "notes_forward", data };
264
+ }
265
+
266
+ if (state.inputMode) {
267
+ // Newline takes precedence over confirmation if a user configuration binds
268
+ // the same physical key to both semantic actions.
269
+ if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "ignore" };
270
+ if (kb.matches(data, KEYBIND_CONFIRM)) {
271
+ const answer = buildSingleSelectAnswer(state, runtime);
272
+ if (!answer) return { kind: "ignore" };
273
+ return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
274
+ }
275
+ // Treat Pi's Ctrl+U line-kill binding as an explicit whole-draft clear,
276
+ // independent of the current cursor position.
277
+ if (kb.matches(data, KEYBIND_CLEAR)) return { kind: "input_clear" };
278
+ if (kb.matches(data, KEYBIND_EXTERNAL_EDITOR)) return { kind: "input_edit", value: runtime.inputBuffer };
279
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
280
+ if (kb.matches(data, KEYBIND_EDITOR_UP) && runtime.canMoveInputUp) return { kind: "ignore" };
281
+ if (kb.matches(data, KEYBIND_EDITOR_DOWN) && runtime.canMoveInputDown) {
282
+ return { kind: "ignore" };
283
+ }
284
+ if (kb.matches(data, KEYBIND_UP)) return prevNavOnUp(state, runtime);
285
+ if (kb.matches(data, KEYBIND_DOWN)) return nextNavOnDown(state, runtime);
286
+ return { kind: "ignore" };
287
+ }
288
+
289
+ if (runtime.isMulti && state.currentTab === runtime.questions.length) {
290
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
291
+ const tab = tabSwitchAction(data, state, runtime);
292
+ if (tab) return tab;
293
+ if (kb.matches(data, KEYBIND_UP) || kb.matches(data, KEYBIND_DOWN)) {
294
+ const delta = kb.matches(data, KEYBIND_DOWN) ? 1 : -1;
295
+ const next = wrapTab(state.submitChoiceIndex + delta, 2);
296
+ return { kind: "submit_nav", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };
297
+ }
298
+ if (kb.matches(data, KEYBIND_CONFIRM)) {
299
+ // D1 (revised): Submit always submits; Cancel always cancels. The warning header
300
+ // is informational only — `allAnswered(state)` no longer gates submission. Partial
301
+ // answers flow through `orderedAnswers()` in the host.
302
+ return state.submitChoiceIndex === 1 ? { kind: "cancel" } : { kind: "submit" };
303
+ }
304
+ return { kind: "ignore" };
305
+ }
306
+
307
+ const tab = tabSwitchAction(data, state, runtime);
308
+ if (tab) return tab;
309
+
310
+ const q = runtime.questions[state.currentTab];
311
+ if (!q) return { kind: "ignore" };
312
+
313
+ if (matchesKey(data, Key.pageUp) || matchesKey(data, PREVIEW_PAGE_UP)) {
314
+ return previewScrollAction(state, runtime, -Math.max(1, runtime.viewport.pageSize - 1)) ?? { kind: "ignore" };
315
+ }
316
+ if (matchesKey(data, Key.pageDown) || matchesKey(data, PREVIEW_PAGE_DOWN)) {
317
+ return previewScrollAction(state, runtime, Math.max(1, runtime.viewport.pageSize - 1)) ?? { kind: "ignore" };
318
+ }
319
+
320
+ // Universal `n` activation (FR-1): the notes editor opens on every question tab
321
+ // (single- or multi-select, preview or no-preview). The blocks above already
322
+ // swallow `n` when it should NOT reach here — notesVisible forwards to the
323
+ // notes Input, inputMode forwards to the inline Input, the submit-tab block
324
+ // ignores it, and tabSwitchAction ignores it — so by the time we reach this
325
+ // gate, `n` is unambiguously a notes-enter request. Row intent (Next sentinel,
326
+ // "Type something.") is irrelevant: the gate sits ABOVE the multi-select
327
+ // toggle block and the Next sentinel never activates inputMode, so `n` is
328
+ // neither swallowed earlier nor blocked by `blocksMultiToggle`.
329
+ if (data === NOTES_ACTIVATE_KEY) {
330
+ return { kind: "notes_enter" };
331
+ }
332
+
333
+ if (kb.matches(data, KEYBIND_UP)) {
334
+ return prevNavOnUp(state, runtime);
335
+ }
336
+ if (kb.matches(data, KEYBIND_DOWN)) {
337
+ return nextNavOnDown(state, runtime);
338
+ }
339
+
340
+ if (q.multiSelect) {
341
+ const focusedKind = runtime.currentItem?.kind;
342
+ const focusedMeta = focusedKind ? ROW_INTENT_META[focusedKind] : undefined;
343
+ // Space toggles the focused row's checkbox. Suppressed on rows whose META declares
344
+ // `blocksMultiToggle` (the Next sentinel) or `activatesInputMode` (the "Type
345
+ // something." row — it is an inline input, not a checkable option).
346
+ if (data === SPACE_KEY) {
347
+ if (focusedMeta?.blocksMultiToggle) return { kind: "ignore" };
348
+ if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
349
+ return { kind: "toggle", index: state.optionIndex };
350
+ }
351
+ if (kb.matches(data, KEYBIND_CONFIRM)) {
352
+ // Enter on the "Type something." row is handled by the inputMode block above
353
+ // (→ confirm kind:"custom"). Defensive: never enter the toggle/multi_confirm
354
+ // path for an inputMode-activating row.
355
+ if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
356
+ // Enter on a regular row toggles (matching Space) — committing the question is now
357
+ // gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`
358
+ // (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes
359
+ // without leaving the keyboard home row.
360
+ if (!focusedMeta?.autoSubmitsInMulti) return { kind: "toggle", index: state.optionIndex };
361
+ // Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in
362
+ // multi-question mode, OR submit the dialog in single-question mode
363
+ // (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select
364
+ // question would have no way to commit at all.
365
+ return {
366
+ kind: "multi_confirm",
367
+ selected: buildMultiSelected(state, runtime),
368
+ autoAdvanceTab: computeAutoAdvanceTab(state, runtime),
369
+ };
370
+ }
371
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
372
+ return { kind: "ignore" };
373
+ }
374
+
375
+ if (kb.matches(data, KEYBIND_CONFIRM)) {
376
+ const answer = buildSingleSelectAnswer(state, runtime);
377
+ if (!answer) return { kind: "ignore" };
378
+ return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
379
+ }
380
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
381
+ return { kind: "ignore" };
382
+ }
@@ -0,0 +1,32 @@
1
+ import { Markdown, wrapTextWithAnsi } from "@earendil-works/pi-tui";
2
+ import type { QuestionData } from "../tool/types.js";
3
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
4
+ import { dockCapacity, DOCK_MIN_ROWS, DOCK_RESERVED_ROWS, type TerminalSize } from "./geometry.js";
5
+
6
+ export function panelInnerWidth(columns: number): number { return Math.max(1, columns - 7); }
7
+
8
+ const identity = (text: string) => text;
9
+ const measureTheme = { heading: identity, link: identity, linkUrl: identity, code: identity, codeBlock: identity, codeBlockBorder: identity, quote: identity, quoteBorder: identity, hr: identity, listBullet: identity, bold: identity, italic: identity, strikethrough: identity, underline: identity };
10
+
11
+ /** Opening-time measurement; the renderer owns subsequent scrolling, not mode changes. */
12
+ export function markdownRows(text: string, columns: number): number {
13
+ return new Markdown(text, 0, 0, measureTheme, undefined, { preserveOrderedListMarkers: true, renderLatex: false }).render(panelInnerWidth(columns)).length;
14
+ }
15
+ export function contentRows(question: QuestionData, items: readonly WrappingSelectItem[], columns: number): number {
16
+ return markdownRows(question.preview ?? "", columns) + items.length + 5;
17
+ }
18
+ export function routePanelForm(question: QuestionData, items: readonly WrappingSelectItem[], size: TerminalSize): "dock" | "float" {
19
+ if (size.rows < DOCK_MIN_ROWS + DOCK_RESERVED_ROWS) return "float";
20
+ return contentRows(question, items, size.columns) + 3 <= dockCapacity(size) ? "dock" : "float";
21
+ }
22
+ export function routeAskPanel(questions: readonly QuestionData[], items: ReadonlyArray<readonly WrappingSelectItem[]>, size: TerminalSize, document: boolean): "dock" | "float" {
23
+ if (size.rows < DOCK_MIN_ROWS + DOCK_RESERVED_ROWS || size.columns < 40) return "float";
24
+ if (!document && size.rows < 22) return "float";
25
+ if (document) return routePanelForm(questions[0]!, items[0] ?? [], size);
26
+ const room = Math.max(3, dockCapacity(size) - 10);
27
+ for (const question of questions) {
28
+ const previews = [question.preview, ...question.options.map(option => option.preview)].filter((text): text is string => Boolean(text));
29
+ if (previews.some(text => markdownRows(text, size.columns) > room)) return "float";
30
+ }
31
+ return "dock";
32
+ }