vc-extras 0.0.0-stage → 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 (243) hide show
  1. package/README.md +128 -3
  2. package/agent-install.mjs +159 -0
  3. package/agents/tester.md +23 -0
  4. package/install-extras.mjs +66 -0
  5. package/install-menu.mjs +42 -0
  6. package/install-skills.mjs +112 -0
  7. package/package.json +72 -6
  8. package/plugin-registry.mjs +73 -0
  9. package/plugins/config-ui/index.ts +160 -0
  10. package/plugins/config-ui/lib/arguments.mjs +24 -0
  11. package/plugins/config-ui/lib/documents.mjs +67 -0
  12. package/plugins/config-ui/lib/frontmatter.mjs +91 -0
  13. package/plugins/config-ui/lib/open.mjs +17 -0
  14. package/plugins/config-ui/lib/ownership.mjs +99 -0
  15. package/plugins/config-ui/lib/page.mjs +11 -0
  16. package/plugins/config-ui/lib/patch.mjs +36 -0
  17. package/plugins/config-ui/lib/paths.mjs +14 -0
  18. package/plugins/config-ui/lib/plugin-fields.mjs +86 -0
  19. package/plugins/config-ui/lib/plugin-validation.mjs +28 -0
  20. package/plugins/config-ui/lib/redaction.mjs +8 -0
  21. package/plugins/config-ui/lib/registry.mjs +282 -0
  22. package/plugins/config-ui/lib/secrets.mjs +45 -0
  23. package/plugins/config-ui/lib/server.mjs +251 -0
  24. package/plugins/config-ui/lib/sources.mjs +96 -0
  25. package/plugins/config-ui/lib/state.mjs +157 -0
  26. package/plugins/config-ui/lib/themes.mjs +113 -0
  27. package/plugins/config-ui/lib/writer.mjs +691 -0
  28. package/plugins/config-ui/package.json +12 -0
  29. package/plugins/config-ui/project-local-owner.ts +106 -0
  30. package/plugins/config-ui/vc-extras.plugin.json +13 -0
  31. package/plugins/config-ui/web/app.mjs +997 -0
  32. package/plugins/config-ui/web/index.html +342 -0
  33. package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
  34. package/plugins/pi-btw/vc-extras.plugin.json +12 -0
  35. package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
  36. package/plugins/pi-fff/vc-extras.plugin.json +12 -0
  37. package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
  38. package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
  39. package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
  40. package/plugins/vc-ask/claude-hook.mjs +37 -0
  41. package/plugins/vc-ask/codex-native.mjs +28 -0
  42. package/plugins/vc-ask/host-channel.mjs +75 -0
  43. package/plugins/vc-ask/index.ts +57 -0
  44. package/plugins/vc-ask/native-questions.mjs +33 -0
  45. package/plugins/vc-ask/package.json +10 -0
  46. package/plugins/vc-ask/payload.ts +170 -0
  47. package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
  48. package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
  49. package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
  50. package/plugins/vc-ask/questionnaire/config.ts +180 -0
  51. package/plugins/vc-ask/questionnaire/events.ts +154 -0
  52. package/plugins/vc-ask/questionnaire/execute.ts +688 -0
  53. package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
  54. package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
  55. package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
  56. package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
  57. package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
  58. package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
  59. package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
  60. package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
  61. package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
  62. package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
  63. package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
  64. package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
  65. package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
  66. package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
  67. package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
  68. package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
  69. package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
  70. package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
  71. package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
  72. package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
  73. package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
  74. package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
  75. package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
  76. package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
  77. package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
  78. package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
  79. package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
  80. package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
  81. package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
  82. package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
  83. package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
  84. package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
  85. package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
  86. package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
  87. package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
  88. package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
  89. package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
  90. package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
  91. package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
  92. package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
  93. package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
  94. package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
  95. package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
  96. package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
  97. package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
  98. package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
  99. package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
  100. package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
  101. package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
  102. package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
  103. package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
  104. package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
  105. package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
  106. package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
  107. package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
  108. package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
  109. package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
  110. package/plugins/vc-ask/user-input-events.ts +34 -0
  111. package/plugins/vc-ask/vc-extras.plugin.json +18 -0
  112. package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
  113. package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
  114. package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
  115. package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
  116. package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
  117. package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
  118. package/plugins/vc-footer/agents/codex/native.mjs +19 -0
  119. package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
  120. package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
  121. package/plugins/vc-footer/agents/pi/index.js +84 -0
  122. package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
  123. package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
  124. package/plugins/vc-footer/core/data.mjs +218 -0
  125. package/plugins/vc-footer/core/render.mjs +291 -0
  126. package/plugins/vc-footer/core/types.d.ts +29 -0
  127. package/plugins/vc-footer/package.json +22 -0
  128. package/plugins/vc-footer/vc-extras.plugin.json +32 -0
  129. package/skills/animate/LICENSE +21 -0
  130. package/skills/animate/RECIPES.md +324 -0
  131. package/skills/animate/SKILL.md +208 -0
  132. package/skills/animate/UPSTREAM.md +19 -0
  133. package/skills/animation-performance/LICENSE +21 -0
  134. package/skills/animation-performance/SKILL.md +223 -0
  135. package/skills/animation-performance/UPSTREAM.md +19 -0
  136. package/skills/answer-me-with-html/SKILL.md +174 -0
  137. package/skills/answer-me-with-html/scripts/am.mjs +12896 -0
  138. package/skills/apple-design/LICENSE +21 -0
  139. package/skills/apple-design/SKILL.md +291 -0
  140. package/skills/apple-design/UPSTREAM.md +19 -0
  141. package/skills/bad-smell/SKILL.md +44 -0
  142. package/skills/commit/SKILL.md +90 -0
  143. package/skills/emil-design-eng/LICENSE +21 -0
  144. package/skills/emil-design-eng/SKILL.md +677 -0
  145. package/skills/emil-design-eng/UPSTREAM.md +19 -0
  146. package/skills/find-the-truth/SKILL.md +38 -0
  147. package/skills/find-the-truth/references/trace-method.md +48 -0
  148. package/skills/find-the-truth/references/truth-method.md +39 -0
  149. package/skills/gestures/LICENSE +21 -0
  150. package/skills/gestures/SKILL.md +107 -0
  151. package/skills/gestures/UPSTREAM.md +19 -0
  152. package/skills/humanizer-zh/LICENSE +21 -0
  153. package/skills/humanizer-zh/SKILL.md +409 -0
  154. package/skills/humanizer-zh/UPSTREAM.md +7 -0
  155. package/skills/impeccable/LICENSE +191 -0
  156. package/skills/impeccable/NOTICE.md +11 -0
  157. package/skills/impeccable/SKILL.md +90 -0
  158. package/skills/impeccable/licenses/modern-screenshot-MIT.txt +9 -0
  159. package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -0
  160. package/skills/impeccable/reference/adapt.md +318 -0
  161. package/skills/impeccable/reference/adapt.native.md +58 -0
  162. package/skills/impeccable/reference/android.md +46 -0
  163. package/skills/impeccable/reference/animate.md +89 -0
  164. package/skills/impeccable/reference/audit.md +139 -0
  165. package/skills/impeccable/reference/audit.native.md +139 -0
  166. package/skills/impeccable/reference/bolder.md +33 -0
  167. package/skills/impeccable/reference/clarify.md +94 -0
  168. package/skills/impeccable/reference/colorize.md +86 -0
  169. package/skills/impeccable/reference/component-review.md +63 -0
  170. package/skills/impeccable/reference/craft-floor.md +44 -0
  171. package/skills/impeccable/reference/craft.md +5 -0
  172. package/skills/impeccable/reference/critique.md +819 -0
  173. package/skills/impeccable/reference/degraded/asset-producer.md +42 -0
  174. package/skills/impeccable/reference/degraded/documenter.md +24 -0
  175. package/skills/impeccable/reference/degraded/finish-reviewer.md +38 -0
  176. package/skills/impeccable/reference/degraded/manual-edit-applier.md +93 -0
  177. package/skills/impeccable/reference/delight.md +70 -0
  178. package/skills/impeccable/reference/distill.md +111 -0
  179. package/skills/impeccable/reference/doctor.md +54 -0
  180. package/skills/impeccable/reference/document.md +416 -0
  181. package/skills/impeccable/reference/extract.md +69 -0
  182. package/skills/impeccable/reference/generate.md +101 -0
  183. package/skills/impeccable/reference/harden.md +362 -0
  184. package/skills/impeccable/reference/hooks.md +114 -0
  185. package/skills/impeccable/reference/init.md +131 -0
  186. package/skills/impeccable/reference/ios.md +51 -0
  187. package/skills/impeccable/reference/layout.md +84 -0
  188. package/skills/impeccable/reference/live-setup.md +104 -0
  189. package/skills/impeccable/reference/live.md +327 -0
  190. package/skills/impeccable/reference/mode-operate.md +21 -0
  191. package/skills/impeccable/reference/mode-persuade.md +19 -0
  192. package/skills/impeccable/reference/mode-read.md +21 -0
  193. package/skills/impeccable/reference/new-work.md +152 -0
  194. package/skills/impeccable/reference/onboard.md +234 -0
  195. package/skills/impeccable/reference/operate.md +61 -0
  196. package/skills/impeccable/reference/optimize.md +257 -0
  197. package/skills/impeccable/reference/overdrive.md +127 -0
  198. package/skills/impeccable/reference/polish.md +105 -0
  199. package/skills/impeccable/reference/quieter.md +99 -0
  200. package/skills/impeccable/reference/region-map.md +26 -0
  201. package/skills/impeccable/reference/routing.md +24 -0
  202. package/skills/impeccable/reference/shape.md +59 -0
  203. package/skills/impeccable/reference/typeset.md +90 -0
  204. package/skills/impeccable/reference/visualize.md +47 -0
  205. package/skills/impeccable/scripts/VERSION +1 -0
  206. package/skills/impeccable/scripts/command-metadata.json +98 -0
  207. package/skills/impeccable/scripts/data/font-index-failures.json +121 -0
  208. package/skills/impeccable/scripts/data/font-index.json +1 -0
  209. package/skills/impeccable/scripts/engine-checksums.txt +9 -0
  210. package/skills/impeccable/scripts/impeccable +249 -0
  211. package/skills/impeccable/scripts/impeccable.cmd +278 -0
  212. package/skills/impeccable/scripts/live-browser-dom.js +320 -0
  213. package/skills/impeccable/scripts/live-browser-ignores.js +246 -0
  214. package/skills/impeccable/scripts/live-browser-session.js +183 -0
  215. package/skills/impeccable/scripts/live-browser.js +13862 -0
  216. package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
  217. package/skills/improve-animations/AUDIT.md +115 -0
  218. package/skills/improve-animations/LICENSE +21 -0
  219. package/skills/improve-animations/PLAN-TEMPLATE.md +73 -0
  220. package/skills/improve-animations/SKILL.md +110 -0
  221. package/skills/improve-animations/UPSTREAM.md +19 -0
  222. package/skills/pick-ui-library/LICENSE +21 -0
  223. package/skills/pick-ui-library/SKILL.md +85 -0
  224. package/skills/pick-ui-library/UPSTREAM.md +19 -0
  225. package/skills/review-animations/LICENSE +21 -0
  226. package/skills/review-animations/SKILL.md +120 -0
  227. package/skills/review-animations/STANDARDS.md +187 -0
  228. package/skills/review-animations/UPSTREAM.md +19 -0
  229. package/skills/test/SKILL.md +29 -0
  230. package/skills/test/references/test-method.md +60 -0
  231. package/skills/write-doc/SKILL.md +115 -0
  232. package/skills/write-doc/examples/result-report.md +53 -0
  233. package/skills/write-doc/examples/task-summary.md +45 -0
  234. package/skills/write-doc/references/terminology.md +147 -0
  235. package/specs/ask-host-protocol-v1.md +58 -0
  236. package/specs/design-demo.md +1102 -0
  237. package/specs/frontend-immersive.md +28 -0
  238. package/specs/plugin-install-v2.md +123 -0
  239. package/specs/plugin-install.md +38 -0
  240. package/specs/web-modes/explore.md +31 -0
  241. package/specs/web-modes/risk.md +15 -0
  242. package/specs/web-modes/verify.md +16 -0
  243. package/vc-extras.mjs +62 -0
@@ -0,0 +1,218 @@
1
+ import { CURSOR_MARKER, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Editor } from "@earendil-works/pi-tui";
2
+ import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
3
+ import { MarkdownContentCache } from "./components/preview/markdown-content-cache.js";
4
+ import type { QuestionData } from "../tool/types.js";
5
+ import { formatAnswerScalar } from "../tool/format-answer.js";
6
+ import type { QuestionnaireState, QuestionnaireViewport } from "../state/state.js";
7
+ import { clamp, dockCapacity, formDockCapacity, floatPanel, isDocked, type PanelGeometry } from "../state/geometry.js";
8
+ import { fitHint, PanelChrome, panelBlank, panelBottom, panelTop, type AskPalette } from "./panel-chrome.js";
9
+
10
+ interface VerticalConfig {
11
+ theme: Theme;
12
+ palette?: AskPalette;
13
+ questions: readonly QuestionData[];
14
+ input: Editor;
15
+ notes: Editor;
16
+ rows: () => number;
17
+ columns?: () => number;
18
+ initialState: QuestionnaireState;
19
+ requestRender?: () => void;
20
+ }
21
+ export interface FormTarget { kind: "option" | "tab" | "review" | "submit" | "cancel"; question: number; index: number }
22
+ interface BodyRow { text: string; target?: FormTarget; active?: boolean }
23
+
24
+ /** The approved ask demo expressed in terminal cells, with a fixed header and footer. */
25
+ export class VerticalView {
26
+ private state: QuestionnaireState;
27
+ private top = 0;
28
+ private manualScroll = false;
29
+ private listMax = 0;
30
+ private revision = 0;
31
+ private previewRect = { x: 0, y: 0, width: 0, height: 0 };
32
+ private targets = new Map<number, FormTarget>();
33
+ private tabTargets: { from: number; to: number; target: FormTarget }[] = [];
34
+ private viewport: QuestionnaireViewport = { scrollStart: 0, pageSize: 1, maxScrollStart: 0 };
35
+ private panel: PanelGeometry = { col: 0, row: 0, w: 0, h: 0 };
36
+ private readonly previews: MarkdownContentCache[];
37
+ focused = false;
38
+ editorWidth = 1;
39
+ actionable = false;
40
+
41
+ constructor(private readonly config: VerticalConfig) {
42
+ this.state = config.initialState;
43
+ this.previews = config.questions.map(q => new MarkdownContentCache(q, config.theme, getMarkdownTheme()));
44
+ }
45
+ dispose(): void {}
46
+ setProps(state: QuestionnaireState): void {
47
+ if (state.currentTab !== this.state.currentTab || state.verticalScreen !== this.state.verticalScreen) this.top = 0;
48
+ if (state.currentTab !== this.state.currentTab || state.optionIndex !== this.state.optionIndex || state.inputMode !== this.state.inputMode || state.verticalScreen !== this.state.verticalScreen || state.verticalReviewIndex !== this.state.verticalReviewIndex) this.manualScroll = false;
49
+ this.state = state;
50
+ }
51
+ scrollList(lines: number): boolean {
52
+ if (!Number.isFinite(lines)) return false;
53
+ const next = clamp(this.top + Math.trunc(lines), 0, this.listMax);
54
+ if (next === this.top) return false;
55
+ this.manualScroll = true; this.top = next; this.revision++;
56
+ return true;
57
+ }
58
+ scrollAt(_x: number, lines: number): boolean { return this.scrollList(lines); }
59
+ isPreviewAt(x: number, y: number): boolean {
60
+ const panel = this.hitRect(), p = this.previewRect;
61
+ x -= panel.col; y -= panel.row;
62
+ return x >= p.x && x < p.x + p.width && y >= p.y && y < p.y + p.height;
63
+ }
64
+ getViewport(): QuestionnaireViewport { return this.viewport; }
65
+ getRenderVersion(): number { return this.revision; }
66
+ reposition(panel: PanelGeometry): void { this.panel = panel; }
67
+ panelRect(): PanelGeometry { return this.panel; }
68
+ hitRect(): PanelGeometry { return isDocked(this.state) ? { ...this.panel, col: 0, row: 0 } : this.panel; }
69
+ targetAt(x: number, y: number): FormTarget | undefined {
70
+ const p = this.hitRect(), col = x - p.col, row = y - p.row;
71
+ if (col <= 0 || col >= p.w - 1) return undefined;
72
+ if (row === 2) return this.tabTargets.find(t => col >= t.from && col < t.to)?.target;
73
+ return this.targets.get(row);
74
+ }
75
+ dragKindAt(x: number, y: number): "dock-resize" | "move" | "resize-w" | "resize-h" | "resize-both" | null {
76
+ const p = this.hitRect();
77
+ if (x < p.col || x >= p.col + p.w || y < p.row || y >= p.row + p.h) return null;
78
+ if (y === p.row) return isDocked(this.state) ? "dock-resize" : "move";
79
+ if (isDocked(this.state)) return null;
80
+ const right = x === p.col + p.w - 1, bottom = y === p.row + p.h - 1;
81
+ return right && bottom ? "resize-both" : right ? "resize-w" : bottom ? "resize-h" : null;
82
+ }
83
+ invalidate(): void { this.revision++; this.config.input.invalidate(); this.config.notes.invalidate(); this.previews.forEach(p => p.invalidate()); }
84
+
85
+ private tabLine(chrome: PanelChrome, available: number): string {
86
+ const { questions } = this.config, s = this.state;
87
+ this.tabTargets = [];
88
+ const reviewText = " ✓ 复核答案 ";
89
+ const count = "已答 " + s.answers.size + "/" + questions.length;
90
+ const room = Math.max(0, available - visibleWidth(reviewText + " " + count));
91
+ const maxTab = Math.max(6, room);
92
+ const segments = questions.map((q, i) => truncateToWidth(" " + (s.answers.has(i) ? "■" : s.deferredQuestions?.has(i) ? "○" : "□") + " " + (q.header || q.question) + " ", maxTab, "…"));
93
+ let start = 0;
94
+ while (start < s.currentTab && segments.slice(start, s.currentTab + 1).reduce((n, v) => n + visibleWidth(v), 0) > room) start++;
95
+ let line = "", cells = 0;
96
+ for (let i = start; i < questions.length; i++) {
97
+ const segment = truncateToWidth(segments[i]!, Math.max(0, room - cells), "…");
98
+ if (!segment || cells >= room) break;
99
+ const active = s.verticalScreen !== "review" && i === s.currentTab;
100
+ line += active ? chrome.selected(segment) : s.answers.has(i) ? chrome.accent(segment) : chrome.muted(segment);
101
+ this.tabTargets.push({ from: 3 + cells, to: 3 + cells + visibleWidth(segment), target: { kind: "tab", question: i, index: -1 } });
102
+ cells += visibleWidth(segment);
103
+ }
104
+ this.tabTargets.push({ from: 3 + cells, to: 3 + cells + visibleWidth(reviewText), target: { kind: "review", question: questions.length, index: -1 } });
105
+ line += s.verticalScreen === "review" ? chrome.selected(reviewText) : chrome.muted(reviewText);
106
+ return line + " ".repeat(Math.max(1, available - visibleWidth(line) - visibleWidth(count))) + chrome.muted(count);
107
+ }
108
+
109
+ render(width: number): string[] {
110
+ const { theme, questions, input, notes } = this.config, s = this.state;
111
+ const screen = { columns: this.config.columns?.() ?? width, rows: Math.max(1, this.config.rows()) };
112
+ const docked = isDocked(s), floating = docked ? undefined : floatPanel(s, screen);
113
+ width = floating?.w ?? width;
114
+ const chrome = new PanelChrome(theme, docked ? "dock" : "float", true, this.config.palette);
115
+ const review = s.verticalScreen === "review", q = questions[s.currentTab]!;
116
+ const cache = this.previews[s.currentTab]!;
117
+ const hasPreview = !review && Boolean(q.preview || cache.hasAnyPreview());
118
+ const inner = Math.max(1, width - 6), split = hasPreview && inner >= 100;
119
+ const leftWidth = split ? Math.floor(inner * .52) : inner;
120
+ const contentWidth = Math.max(1, leftWidth - 2);
121
+ const previewWidth = split ? inner - leftWidth - 1 : inner;
122
+ const body: BodyRow[] = [];
123
+ this.targets.clear(); this.previewRect = { x: 0, y: 0, width: 0, height: 0 };
124
+ this.actionable = width >= 40 && screen.rows >= 12;
125
+ if (!this.actionable) {
126
+ this.panel = floating ?? { col: 0, row: 0, w: width, h: 2 };
127
+ return [truncateToWidth("Enlarge: 40x12 / 请放大终端", width), truncateToWidth("Esc / Ctrl+C: Cancel", width)];
128
+ }
129
+ input.focused = this.focused && s.inputMode;
130
+ notes.focused = this.focused && s.notesVisible;
131
+ const add = (prefix: string, text: string, target?: FormTarget, active = false) => {
132
+ const indent = visibleWidth(prefix);
133
+ wrapTextWithAnsi(text, Math.max(1, contentWidth - indent)).forEach((line, i) => body.push({ text: (i ? " ".repeat(indent) : prefix) + line, target, active: active && i === 0 }));
134
+ };
135
+ const editorRows = (editor: Editor, target?: FormTarget, label = "Type Something") => {
136
+ this.editorWidth = Math.max(1, contentWidth - 4);
137
+ const rendered = editor.render(this.editorWidth).slice(1, -1);
138
+ if (!editor.getText() && rendered[0]) rendered[0] = CURSOR_MARKER + chrome.dim(label);
139
+ const answer = s.answers.get(s.currentTab);
140
+ const checked = Boolean(answer && (answer.kind === "custom" || answer.kind === "multi") && answer.answer?.trim());
141
+ const mark = q.multiSelect ? (checked ? "☑" : "☐") : checked ? "◉" : "○";
142
+ const cursor = Math.max(0, rendered.findIndex(line => line.includes(CURSOR_MARKER)));
143
+ rendered.slice(Math.max(0, cursor - 3), Math.max(4, cursor + 1)).forEach((line, i) => body.push({ text: (i ? " " : "› " + mark + " ") + line, target, active: line.includes(CURSOR_MARKER) }));
144
+ };
145
+ if (review) {
146
+ add(" ", chrome.accent("复核你的答案")); body.push({ text: "" });
147
+ questions.forEach((question, i) => {
148
+ const answer = s.answers.get(i), active = (s.verticalReviewIndex ?? questions.length) === i;
149
+ const target: FormTarget = { kind: "tab", question: i, index: -1 };
150
+ add(active ? chrome.accent("› ● ") : chrome.muted(" ● "), chrome.muted(question.header || question.question), target, active);
151
+ add(" ", chrome.text("→ " + (answer ? formatAnswerScalar(answer, "summary") : "未选择,后续讨论")), target);
152
+ if (answer?.notes) add(" ", chrome.muted(answer.notes), target);
153
+ body.push({ text: "" });
154
+ });
155
+ add(" ", chrome.border("─".repeat(Math.max(1, contentWidth - 2)))); body.push({ text: "" });
156
+ for (const [i, label] of ["提交答案", "取消"].entries()) {
157
+ const active = (s.verticalReviewIndex ?? questions.length) === questions.length + i;
158
+ add(active ? chrome.accent("› ") : " ", active ? chrome.accent(label) : chrome.text(label), { kind: i ? "cancel" : "submit", question: questions.length, index: i }, active);
159
+ }
160
+ } else {
161
+ add(" ", chrome.bold(chrome.text(q.question)) + chrome.muted(q.multiSelect ? " 多选" : " 单选"));
162
+ body.push({ text: "" });
163
+ const answer = s.answers.get(s.currentTab);
164
+ q.options.forEach((option, i) => {
165
+ const checked = answer?.kind === "option" ? answer.answer === option.label : answer?.kind === "multi" && answer.selected?.includes(option.label);
166
+ const active = s.optionIndex === i && !s.notesVisible;
167
+ const mark = q.multiSelect ? (checked ? "☑" : "☐") : checked ? "◉" : "○";
168
+ const prefix = chrome.accent(active ? "› " : " ") + (checked ? chrome.accent(mark) : chrome.muted(mark)) + " ";
169
+ const label = (active ? chrome.accent(chrome.bold(option.label)) : chrome.text(option.label)) + (q.recommended?.includes(i) ? chrome.accent(" (推荐)") : "");
170
+ const target: FormTarget = { kind: "option", question: s.currentTab, index: i };
171
+ add(prefix, label, target, active);
172
+ if (option.description) add(" ", chrome.muted(option.description), target);
173
+ body.push({ text: "" });
174
+ });
175
+ const custom: FormTarget = { kind: "option", question: s.currentTab, index: q.options.length };
176
+ if (s.inputMode) editorRows(input, custom);
177
+ else {
178
+ const value = s.customDraftsByTab.get(s.currentTab) ?? ((answer?.kind === "custom" || answer?.kind === "multi") ? answer.answer ?? "" : "");
179
+ const checked = Boolean(answer && (answer.kind === "custom" || answer.kind === "multi") && answer.answer?.trim());
180
+ const mark = q.multiSelect ? (checked ? "☑" : "☐") : checked ? "◉" : "○";
181
+ add(s.optionIndex === q.options.length ? chrome.accent("› " + mark + " ") : checked ? chrome.accent(" " + mark + " ") : chrome.muted(" " + mark + " "), chrome.muted(value || "Type Something"), custom, s.optionIndex === q.options.length);
182
+ }
183
+ body.push({ text: "" });
184
+ const active = s.optionIndex === q.options.length + 1;
185
+ add(active ? chrome.accent("› ○ ") : chrome.muted(" ○ "), active ? chrome.accent("暂不选择,后续讨论") : chrome.text("暂不选择,后续讨论"), { kind: "option", question: s.currentTab, index: q.options.length + 1 }, active);
186
+ }
187
+ if (s.notesVisible) { body.push({ text: "" }); add(" ", chrome.muted("备注")); editorRows(notes, undefined, "补充你希望说明的内容"); }
188
+ else if (review && s.globalNote) { body.push({ text: "" }); add(" ", chrome.muted("整份问卷备注")); add(" ", chrome.text(s.globalNote)); }
189
+ const previewBody = !hasPreview ? [] : q.preview ? cache.questionBodyFor(Math.max(1, previewWidth - 2)) : cache.bodyFor(s.optionIndex, Math.max(1, previewWidth - 2));
190
+ const dockMax = formDockCapacity(screen);
191
+ const chromeRows = 9, maxHeight = docked ? clamp(s.dockRows ?? dockMax, Math.min(7, screen.rows), dockMax) : s.panelAutoSize === false ? floating?.h ?? screen.rows - 2 : screen.rows - 2;
192
+ const natural = chromeRows + body.length + (!split && hasPreview ? Math.min(8, previewBody.length + 1) : 0);
193
+ const height = s.panelAutoSize === false ? maxHeight : clamp(natural, Math.min(12, maxHeight), maxHeight);
194
+ this.panel = floating ? { ...floating, h: height, row: s.panelAutoSize === false ? Math.min(floating.row, screen.rows - height) : Math.max(0, Math.floor((screen.rows - height) / 2)) } : { col: 0, row: screen.rows - height, w: width, h: height };
195
+ const capacity = Math.max(1, height - chromeRows);
196
+ const previewHeight = !hasPreview ? 0 : split ? capacity : Math.min(Math.max(1, Math.floor(capacity / 2)), Math.max(1, previewBody.length));
197
+ const listCapacity = split ? capacity : Math.max(1, capacity - previewHeight);
198
+ const activeRow = Math.max(0, body.findIndex(row => row.active));
199
+ this.listMax = Math.max(0, body.length - listCapacity);
200
+ if (!this.manualScroll) { if (activeRow < this.top) this.top = activeRow; if (activeRow >= this.top + listCapacity) this.top = activeRow - listCapacity + 1; }
201
+ this.top = clamp(this.top, 0, this.listMax);
202
+ const previewTop = clamp(s.previewScrollOffset ?? 0, 0, Math.max(0, previewBody.length - previewHeight));
203
+ this.viewport = hasPreview ? { scrollStart: previewTop, pageSize: previewHeight, maxScrollStart: Math.max(0, previewBody.length - previewHeight) } : { scrollStart: this.top, pageSize: listCapacity, maxScrollStart: this.listMax };
204
+ if (hasPreview) this.previewRect = { x: split ? leftWidth + 3 : 1, y: split ? 4 : listCapacity + 4, width: previewWidth, height: previewHeight };
205
+ const row = (text: string) => chrome.line(chrome.border("│") + truncateToWidth(" " + text, width - 2, "", true) + chrome.border("│"), width);
206
+ const rows = Array.from({ length: capacity }, (_, i) => {
207
+ const entry = i < listCapacity ? body[this.top + i] : undefined;
208
+ if (entry?.target) this.targets.set(i + 4, entry.target);
209
+ let text = truncateToWidth(entry?.text ?? "", leftWidth, "", true);
210
+ if (split) text += chrome.border("│") + truncateToWidth(" " + (previewBody[previewTop + i] ?? ""), previewWidth, "", true);
211
+ else if (hasPreview && i >= listCapacity) text = " " + (previewBody[previewTop + i - listCapacity] ?? "");
212
+ return row(text);
213
+ });
214
+ const hints = review ? ["↑↓ 移动 Enter 确认 Esc 返回 Ctrl+N 备注", "Enter 确认 Esc 返回"] : s.inputMode ? ["Enter 保存继续 Shift+Enter 换行 Esc 返回", "Enter 保存 Esc 返回"] : q.multiSelect ? ["↑↓ 移动 Space 勾选 Enter 下一题 Tab 换题", "Space 勾选 Enter 下一题"] : ["↑↓ 移动 Enter 选择 Tab 换题 Ctrl+N 备注", "Enter 选择 Tab 换题"];
215
+ const footer = s.verticalMessage ? chrome.accent(s.verticalMessage) : chrome.muted(fitHint(hints, inner));
216
+ return [panelTop(chrome, width, chrome.bold("📄 " + (review ? "确认答案" : "Emma 有 " + questions.length + " 个问题")), ""), panelBlank(chrome, width), row(this.tabLine(chrome, inner)), panelBlank(chrome, width), ...rows, panelBlank(chrome, width), row(chrome.border("─".repeat(inner))), row(" " + footer), panelBlank(chrome, width), panelBottom(chrome, width)];
217
+ }
218
+ }
@@ -0,0 +1,34 @@
1
+ import type { EventBus } from "@earendil-works/pi-coding-agent";
2
+
3
+ export const EMMA_USER_INPUT_EVENT = "emma:user-input";
4
+
5
+ export type EmmaUserInputEvent = {
6
+ version: 1;
7
+ sessionId: string;
8
+ requestId: string;
9
+ reason: "questionnaire";
10
+ waiting: boolean;
11
+ message?: string;
12
+ };
13
+
14
+ export function emitUserInputEvent(
15
+ events: Pick<EventBus, "emit">,
16
+ sessionId: string,
17
+ requestId: string,
18
+ waiting: boolean,
19
+ message?: string,
20
+ ): void {
21
+ const payload: EmmaUserInputEvent = {
22
+ version: 1,
23
+ sessionId,
24
+ requestId,
25
+ reason: "questionnaire",
26
+ waiting,
27
+ };
28
+ if (waiting && message) payload.message = message;
29
+ try {
30
+ events.emit(EMMA_USER_INPUT_EVENT, payload);
31
+ } catch {
32
+ // Observability must never alter the questionnaire result.
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "protocol": "vc-extras/plugin",
3
+ "protocolVersion": 1,
4
+ "id": "vc-ask",
5
+ "label": "vc-ask 问卷(支持 tty7)",
6
+ "targets": {
7
+ "pi": {
8
+ "kind": "pi-package",
9
+ "entry": "./index.ts",
10
+ "files": ["index.ts", "payload.ts", "user-input-events.ts", "host-channel.mjs", "questionnaire"]
11
+ },
12
+ "claude-code": {
13
+ "kind": "claude-ask-hook",
14
+ "entry": "./claude-hook.mjs",
15
+ "files": ["claude-hook.mjs", "host-channel.mjs", "native-questions.mjs"]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,29 @@
1
+ import { collectGit, collectTranscriptMetrics } from "../../core/data.mjs";
2
+ export function claudeFooterData(input) {
3
+ const cwd = input.workspace?.current_dir || input.cwd || input.workspace?.project_dir || process.cwd();
4
+ const projectDir = input.workspace?.project_dir || cwd;
5
+ const metrics = collectTranscriptMetrics(input.transcript_path || "");
6
+ const usage = input.context_window?.current_usage;
7
+ const inputTotal = usage ? (usage.input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0) : 0;
8
+ const latestHitRate = inputTotal > 0 ? (usage?.cache_read_input_tokens ?? 0) * 100 / inputTotal : null;
9
+ return {
10
+ projectDir,
11
+ cwd,
12
+ git: collectGit(cwd),
13
+ context: contextUsage(input),
14
+ cacheHitRate: latestHitRate ?? metrics.cacheHitRate,
15
+ tokensPerSecond: metrics.tokensPerSecond
16
+ };
17
+ }
18
+ function contextUsage(input) {
19
+ const windowSize = input.context_window?.context_window_size ?? 0;
20
+ if (windowSize <= 0) return null;
21
+ const current = input.context_window?.current_usage;
22
+ const used = current ? (current.input_tokens ?? 0) + (current.cache_creation_input_tokens ?? 0) + (current.cache_read_input_tokens ?? 0) : 0;
23
+ const percent = input.context_window?.used_percentage ?? (windowSize > 0 ? used * 100 / windowSize : 0);
24
+ return {
25
+ used,
26
+ window: windowSize,
27
+ percent
28
+ };
29
+ }
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { pathToFileURL } from "node:url";
4
+ import { claudeFooterData } from "./adapter.mjs";
5
+ import { renderClaude } from "./renderer.mjs";
6
+ export function renderStatusline(raw, columns) {
7
+ if (!raw.trim()) return "";
8
+ try {
9
+ const input = JSON.parse(raw);
10
+ return renderClaude(claudeFooterData(input), columns);
11
+ } catch {
12
+ return "";
13
+ }
14
+ }
15
+ export function main(stdin, columns) {
16
+ const output = renderStatusline(stdin(), columns);
17
+ if (output) process.stdout.write(`${output}\n`);
18
+ return 0;
19
+ }
20
+ if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
21
+ const columns = Number.parseInt(process.env.COLUMNS ?? "", 10) || process.stdout.columns || 200;
22
+ process.exitCode = main(() => readFileSync(0, "utf8"), Math.max(0, columns - 4));
23
+ }
@@ -0,0 +1 @@
1
+ export { renderFooter as renderClaude } from '../../core/render.mjs';
@@ -0,0 +1,38 @@
1
+ /** Status-line JSON that Claude Code sends to a command on stdin. */
2
+ export interface ClaudeStatusInput {
3
+ cwd?: string;
4
+ workspace?: {
5
+ current_dir?: string;
6
+ project_dir?: string;
7
+ };
8
+ transcript_path?: string;
9
+ context_window?: {
10
+ used_percentage?: number | null;
11
+ context_window_size?: number;
12
+ total_input_tokens?: number;
13
+ total_output_tokens?: number;
14
+ current_usage?: {
15
+ input_tokens?: number;
16
+ output_tokens?: number;
17
+ cache_creation_input_tokens?: number;
18
+ cache_read_input_tokens?: number;
19
+ } | null;
20
+ } | null;
21
+ prompt_cache?: {
22
+ hit_ratio?: number | null;
23
+ caching_observed?: boolean;
24
+ warm?: boolean;
25
+ } | null;
26
+ session_id?: string;
27
+ session_name?: string;
28
+ model?: {
29
+ id?: string;
30
+ display_name?: string;
31
+ };
32
+ effort?: {
33
+ level?: string;
34
+ };
35
+ thinking?: {
36
+ enabled?: boolean;
37
+ };
38
+ }
@@ -0,0 +1,13 @@
1
+ import { collectGitFast } from '../../core/data.mjs';
2
+
3
+ export function codexFooterData(state) {
4
+ const thread = state?.thread;
5
+ const cwd = typeof thread?.workspace?.cwd === 'string' ? thread.workspace.cwd : '';
6
+ const usage = thread?.usage?.context;
7
+ const window = usage?.context_window_size;
8
+ const used = usage?.used_tokens;
9
+ const percent = usage?.used_percentage ?? (Number.isFinite(used) && window > 0 ? used * 100 / window : null);
10
+ return { cwd, projectDir: cwd, git: collectGitFast(cwd),
11
+ context: Number.isFinite(window) && window > 0 && Number.isFinite(percent) ? { used: used ?? null, window, percent } : null,
12
+ cacheHitRate: null, tokensPerSecond: null };
13
+ }
@@ -0,0 +1,45 @@
1
+ import { createInterface } from 'node:readline';
2
+ import { realpathSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { codexFooterData } from './adapter.mjs';
5
+ import { renderCodex } from './renderer.mjs';
6
+
7
+ export const URI = 'ui://vc-footer/footer';
8
+ const resource = { name: 'footer', uri: URI, mimeType: 'application/json' };
9
+ const tool = { name: 'statusline', title: 'vc-footer', description: 'Display project, Git and context in the Codex footer.',
10
+ inputSchema: { type: 'object', properties: {} },
11
+ _meta: { 'openai/ui': { entrypoints: [{ type: 'statusline', resourceUri: URI }] } },
12
+ };
13
+ function respond(method, p) {
14
+ switch (method) {
15
+ case 'initialize': return { protocolVersion: '2025-06-18', capabilities: { tools: {}, resources: {} }, serverInfo: { name: 'vc-footer', version: '0.1.0' } };
16
+ case 'ping': return {};
17
+ case 'tools/list': return { tools: [tool] };
18
+ case 'tools/call': if (p.name === tool.name) return { content: [{ type: 'text', text: URI }] }; break;
19
+ case 'resources/list': return { resources: [resource] };
20
+ case 'resources/templates/list': return { resourceTemplates: [] };
21
+ case 'resources/read': if (p.uri === URI) return { contents: [{ uri: URI, mimeType: resource.mimeType,
22
+ text: JSON.stringify(renderCodex(codexFooterData(p._meta?.['com.openai/codex-statusline-state']))) }] }; break;
23
+ default: throw Object.assign(new Error('Method not found'), { code: -32601 });
24
+ }
25
+ throw Object.assign(new Error('Invalid parameters'), { code: -32602 });
26
+ }
27
+ export function reply(line) {
28
+ let id = null;
29
+ try {
30
+ let request;
31
+ try { request = JSON.parse(line); } catch { throw Object.assign(new Error('Parse error'), { code: -32700 }); }
32
+ if (request?.jsonrpc !== '2.0' || typeof request.method !== 'string') throw Object.assign(new Error('Invalid request'), { code: -32600 });
33
+ if (!Object.hasOwn(request, 'id')) return;
34
+ id = request.id;
35
+ return { jsonrpc: '2.0', id, result: respond(request.method, request.params ?? {}) };
36
+ } catch (error) {
37
+ return { jsonrpc: '2.0', id, error: { code: error.code ?? -32603, message: error.code ? error.message : 'Internal error' } };
38
+ }
39
+ }
40
+ if (process.argv[1] && realpathSync(process.argv[1], { throwIfNoEntry: false }) === fileURLToPath(import.meta.url)) {
41
+ for await (const line of createInterface({ input: process.stdin, crlfDelay: Infinity })) {
42
+ const response = reply(line);
43
+ if (response) process.stdout.write(JSON.stringify(response) + '\n');
44
+ }
45
+ }
@@ -0,0 +1,19 @@
1
+ export const CODEX_NATIVE_STATUS_ITEMS = [
2
+ "project-name",
3
+ "git-branch",
4
+ "context-used",
5
+ "context-window-size"
6
+ ];
7
+ export function codexStatusLineConfig() {
8
+ return {
9
+ tui: {
10
+ status_line: [
11
+ ...CODEX_NATIVE_STATUS_ITEMS
12
+ ],
13
+ status_line_use_colors: true
14
+ }
15
+ };
16
+ }
17
+ export function codexStatusLineToml() {
18
+ return `[tui]\nstatus_line = ${JSON.stringify(CODEX_NATIVE_STATUS_ITEMS)}\nstatus_line_use_colors = true`;
19
+ }
@@ -0,0 +1,2 @@
1
+ import { renderFooter } from '../../core/render.mjs';
2
+ export function renderCodex(data) { return data.cwd ? renderFooter(data, 200) : null; }
@@ -0,0 +1,23 @@
1
+ import { collectGit, collectTranscriptMetrics } from "../../core/data.mjs";
2
+ export function piFooterData(context) {
3
+ const cwd = context.cwd || process.cwd();
4
+ const usage = context.getContextUsage();
5
+ const windowSize = usage?.contextWindow ?? context.model?.contextWindow ?? 0;
6
+ const used = usage?.tokens ?? 0;
7
+ const percent = usage?.percent ?? (windowSize > 0 ? used * 100 / windowSize : null);
8
+ const contextUsage = windowSize > 0 && percent !== null ? {
9
+ used,
10
+ window: windowSize,
11
+ percent
12
+ } : null;
13
+ const transcriptPath = context.sessionManager.getSessionFile() || "";
14
+ const metrics = collectTranscriptMetrics(transcriptPath);
15
+ return {
16
+ projectDir: cwd,
17
+ cwd,
18
+ git: collectGit(cwd),
19
+ context: contextUsage,
20
+ cacheHitRate: metrics.cacheHitRate,
21
+ tokensPerSecond: metrics.tokensPerSecond
22
+ };
23
+ }
@@ -0,0 +1,84 @@
1
+ import { piFooterData } from "./adapter.mjs";
2
+ import { renderPi } from "./renderer.mjs";
3
+ import { shouldYieldToProject } from "./project-local-owner.mjs";
4
+ function reportError(stage, error) {
5
+ const message = error instanceof Error ? error.message : String(error);
6
+ console.error(`vc-footer ${stage} failed: ${message}`);
7
+ }
8
+ export default function vcFooterExtension(pi) {
9
+ let snapshot = null;
10
+ let footerInstalled = false;
11
+ let startupTimer;
12
+ let requestRender = ()=>{};
13
+ const refresh = (context)=>{
14
+ try {
15
+ snapshot = piFooterData(context);
16
+ requestRender();
17
+ } catch (error) {
18
+ reportError("refresh", error);
19
+ }
20
+ };
21
+ const installFooter = (context)=>{
22
+ if (context.mode !== "tui") return;
23
+ const cwd = context.cwd ?? process.cwd();
24
+ const trusted = context.isProjectTrusted?.() === true;
25
+ if (["./runtime/vc-footer/index.ts", "./runtime/essrj/index.ts"].some(entry =>
26
+ shouldYieldToProject(import.meta.url, entry, cwd, trusted))) return;
27
+ try {
28
+ snapshot = piFooterData(context);
29
+ context.ui.setFooter((tui, theme, footerData)=>{
30
+ requestRender = ()=>tui.requestRender();
31
+ const unsubscribe = footerData.onBranchChange(()=>refresh(context));
32
+ return {
33
+ dispose () {
34
+ try {
35
+ unsubscribe();
36
+ } catch (error) {
37
+ reportError("dispose", error);
38
+ }
39
+ requestRender = ()=>{};
40
+ },
41
+ invalidate () {},
42
+ render (width) {
43
+ try {
44
+ return renderPi(snapshot, width, theme);
45
+ } catch (error) {
46
+ reportError("render", error);
47
+ return [];
48
+ }
49
+ }
50
+ };
51
+ });
52
+ footerInstalled = true;
53
+ } catch (error) {
54
+ reportError("install", error);
55
+ }
56
+ };
57
+ pi.on("session_start", ()=>{
58
+ if (startupTimer) clearTimeout(startupTimer);
59
+ startupTimer = undefined;
60
+ });
61
+ pi.on("resources_discover", (_event, context)=>{
62
+ if (startupTimer) clearTimeout(startupTimer);
63
+ startupTimer = setTimeout(()=>{
64
+ startupTimer = undefined;
65
+ installFooter(context);
66
+ }, 0);
67
+ startupTimer.unref?.();
68
+ });
69
+ pi.on("before_agent_start", (_event, context)=>refresh(context));
70
+ pi.on("turn_end", (_event, context)=>refresh(context));
71
+ pi.on("tool_execution_end", (_event, context)=>refresh(context));
72
+ pi.on("model_select", (_event, context)=>refresh(context));
73
+ pi.on("thinking_level_select", (_event, context)=>refresh(context));
74
+ pi.on("session_info_changed", (_event, context)=>refresh(context));
75
+ pi.on("session_compact", (_event, context)=>refresh(context));
76
+ pi.on("session_shutdown", (_event, context)=>{
77
+ if (startupTimer) clearTimeout(startupTimer);
78
+ startupTimer = undefined;
79
+ if (context.mode === "tui" && footerInstalled) context.ui.setFooter(undefined);
80
+ snapshot = null;
81
+ footerInstalled = false;
82
+ requestRender = ()=>{};
83
+ });
84
+ }