@huseynsnmz/pi-suite 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +88 -2
  4. package/SECURITY.md +5 -0
  5. package/package.json +112 -4
  6. package/packages/board/CHANGELOG.md +340 -0
  7. package/packages/board/CONTRIBUTING.md +7 -0
  8. package/packages/board/LICENSE +21 -0
  9. package/packages/board/README.md +88 -0
  10. package/packages/board/SECURITY.md +19 -0
  11. package/packages/board/docs/how-it-works.md +31 -0
  12. package/packages/board/docs/reference.md +278 -0
  13. package/packages/board/package.json +81 -0
  14. package/packages/board/runner/job-runner-legacy.mjs +68 -0
  15. package/packages/board/runner/job-runner.mjs +834 -0
  16. package/packages/board/runner/pty-runner-legacy.mjs +50 -0
  17. package/packages/board/runner/pty-runner.mjs +2175 -0
  18. package/packages/board/runner/state-coordinator.mjs +673 -0
  19. package/packages/board/runner/state-runner.mjs +203 -0
  20. package/packages/board/runner/title-runner.mjs +80 -0
  21. package/packages/board/src/commands/agent-board.ts +394 -0
  22. package/packages/board/src/commands/attach-decision.mjs +66 -0
  23. package/packages/board/src/commands/attach-flow.ts +251 -0
  24. package/packages/board/src/commands/bg.ts +103 -0
  25. package/packages/board/src/commands/board-model.ts +21 -0
  26. package/packages/board/src/core/atomic.mjs +184 -0
  27. package/packages/board/src/core/attach-delete.mjs +24 -0
  28. package/packages/board/src/core/attach-frame-proof.mjs +870 -0
  29. package/packages/board/src/core/attach-frame-reporter.mjs +648 -0
  30. package/packages/board/src/core/attach-frame-stream.mjs +266 -0
  31. package/packages/board/src/core/attach-view-proof.mjs +709 -0
  32. package/packages/board/src/core/auto-state.mjs +377 -0
  33. package/packages/board/src/core/background-runs.mjs +273 -0
  34. package/packages/board/src/core/code-refs-store.mjs +315 -0
  35. package/packages/board/src/core/code-refs.mjs +913 -0
  36. package/packages/board/src/core/config.mjs +77 -0
  37. package/packages/board/src/core/control-protocol.mjs +482 -0
  38. package/packages/board/src/core/coordinator-client.mjs +633 -0
  39. package/packages/board/src/core/coordinator-journal.mjs +282 -0
  40. package/packages/board/src/core/coordinator-protocol.mjs +14 -0
  41. package/packages/board/src/core/cwd-stats.mjs +114 -0
  42. package/packages/board/src/core/dashboard-render.mjs +10 -0
  43. package/packages/board/src/core/derive.mjs +117 -0
  44. package/packages/board/src/core/diagnostics.mjs +133 -0
  45. package/packages/board/src/core/double-press.mjs +26 -0
  46. package/packages/board/src/core/editor-state-reporter.mjs +112 -0
  47. package/packages/board/src/core/events.mjs +286 -0
  48. package/packages/board/src/core/evidence.mjs +245 -0
  49. package/packages/board/src/core/follow-up-queue.mjs +211 -0
  50. package/packages/board/src/core/foreground-preview-cache.mjs +117 -0
  51. package/packages/board/src/core/foreground-projection-cache.mjs +99 -0
  52. package/packages/board/src/core/frame-witness-update.mjs +35 -0
  53. package/packages/board/src/core/heuristics.mjs +313 -0
  54. package/packages/board/src/core/hold-input.mjs +27 -0
  55. package/packages/board/src/core/host-coordination.mjs +300 -0
  56. package/packages/board/src/core/host-crash.mjs +79 -0
  57. package/packages/board/src/core/host-probe.mjs +207 -0
  58. package/packages/board/src/core/host-protocol.mjs +73 -0
  59. package/packages/board/src/core/ids.mjs +35 -0
  60. package/packages/board/src/core/ime-cursor-coalesce.mjs +193 -0
  61. package/packages/board/src/core/invocation.mjs +43 -0
  62. package/packages/board/src/core/launch-options.mjs +418 -0
  63. package/packages/board/src/core/launch.mjs +157 -0
  64. package/packages/board/src/core/load-config.mjs +4 -0
  65. package/packages/board/src/core/locks.mjs +530 -0
  66. package/packages/board/src/core/paths.mjs +183 -0
  67. package/packages/board/src/core/pid.mjs +75 -0
  68. package/packages/board/src/core/prewarm-schedule.mjs +41 -0
  69. package/packages/board/src/core/process-identity-probe.mjs +228 -0
  70. package/packages/board/src/core/prompt-transport.mjs +13 -0
  71. package/packages/board/src/core/pty-attach-jiggle-controller.mjs +356 -0
  72. package/packages/board/src/core/pty-attach-jiggle-retry.mjs +109 -0
  73. package/packages/board/src/core/pty-attach-reconnect.mjs +61 -0
  74. package/packages/board/src/core/pty-attach-render.mjs +229 -0
  75. package/packages/board/src/core/pty-links.mjs +81 -0
  76. package/packages/board/src/core/pty-scroll.mjs +522 -0
  77. package/packages/board/src/core/pty-support.mjs +327 -0
  78. package/packages/board/src/core/repo.mjs +103 -0
  79. package/packages/board/src/core/rows.mjs +414 -0
  80. package/packages/board/src/core/screen-log-gc.mjs +198 -0
  81. package/packages/board/src/core/screen-log.mjs +160 -0
  82. package/packages/board/src/core/session-view.mjs +174 -0
  83. package/packages/board/src/core/slash-commands.mjs +52 -0
  84. package/packages/board/src/core/state-commands.mjs +757 -0
  85. package/packages/board/src/core/status-consistency.mjs +98 -0
  86. package/packages/board/src/core/steering-prompts.mjs +34 -0
  87. package/packages/board/src/core/steering.mjs +133 -0
  88. package/packages/board/src/core/stop-latch.mjs +41 -0
  89. package/packages/board/src/core/store.mjs +523 -0
  90. package/packages/board/src/core/suspend.mjs +36 -0
  91. package/packages/board/src/core/terminal-attach-client.mjs +981 -0
  92. package/packages/board/src/core/terminal-attach-protocol.mjs +460 -0
  93. package/packages/board/src/core/terminal-model.mjs +222 -0
  94. package/packages/board/src/core/terminal-query-sequences.mjs +239 -0
  95. package/packages/board/src/core/terminal-reply-guard.mjs +222 -0
  96. package/packages/board/src/core/terminal-snapshot.mjs +440 -0
  97. package/packages/board/src/core/test-knobs.mjs +28 -0
  98. package/packages/board/src/core/title.mjs +43 -0
  99. package/packages/board/src/core/types.mjs +414 -0
  100. package/packages/board/src/core/warm-host-sweeper.mjs +168 -0
  101. package/packages/board/src/core/worktree.mjs +65 -0
  102. package/packages/board/src/index.ts +303 -0
  103. package/packages/board/src/runtime/service.mjs +3222 -0
  104. package/packages/board/src/ui/chrome.ts +20 -0
  105. package/packages/board/src/ui/dashboard-decisions.mjs +55 -0
  106. package/packages/board/src/ui/dashboard-evidence.mjs +85 -0
  107. package/packages/board/src/ui/dashboard.ts +2237 -0
  108. package/packages/board/src/ui/double-left.ts +30 -0
  109. package/packages/board/src/ui/external-editor.ts +25 -0
  110. package/packages/board/src/ui/focus.ts +32 -0
  111. package/packages/board/src/ui/pty-attach.ts +3184 -0
  112. package/packages/board/src/ui/waiting.ts +30 -0
  113. package/packages/commands/LICENSE +21 -0
  114. package/packages/commands/README.md +19 -0
  115. package/packages/commands/package.json +22 -0
  116. package/packages/commands/src/index.ts +43 -0
  117. package/packages/commands/src/security-review.ts +109 -0
  118. package/packages/frame/CHANGELOG.md +113 -0
  119. package/packages/frame/CONTRIBUTING.md +7 -0
  120. package/packages/frame/LICENSE +22 -0
  121. package/packages/frame/README.md +105 -0
  122. package/packages/frame/SECURITY.md +16 -0
  123. package/packages/frame/docs/how-it-works.md +53 -0
  124. package/packages/frame/docs/reference.md +78 -0
  125. package/packages/frame/package.json +72 -0
  126. package/packages/frame/src/data/git.ts +90 -0
  127. package/packages/frame/src/data/github.ts +140 -0
  128. package/packages/frame/src/data/gitlab.ts +63 -0
  129. package/packages/frame/src/data/mode.ts +49 -0
  130. package/packages/frame/src/data/past-prompts.ts +57 -0
  131. package/packages/frame/src/data/runner.ts +32 -0
  132. package/packages/frame/src/data/snapshot.ts +223 -0
  133. package/packages/frame/src/data/start-notes.ts +104 -0
  134. package/packages/frame/src/data/telemetry.ts +337 -0
  135. package/packages/frame/src/data/todos.ts +162 -0
  136. package/packages/frame/src/data/totals.ts +94 -0
  137. package/packages/frame/src/data/visits.ts +45 -0
  138. package/packages/frame/src/index.ts +696 -0
  139. package/packages/frame/src/kit/LICENSE +21 -0
  140. package/packages/frame/src/kit/app/attribution.ts +30 -0
  141. package/packages/frame/src/kit/app/builder.ts +186 -0
  142. package/packages/frame/src/kit/app/claim.ts +27 -0
  143. package/packages/frame/src/kit/app/feature.ts +91 -0
  144. package/packages/frame/src/kit/app/host.ts +214 -0
  145. package/packages/frame/src/kit/app/renderers.ts +62 -0
  146. package/packages/frame/src/kit/app/scope.ts +125 -0
  147. package/packages/frame/src/kit/board/model.ts +337 -0
  148. package/packages/frame/src/kit/contract.ts +79 -0
  149. package/packages/frame/src/kit/contracts/accounts.ts +33 -0
  150. package/packages/frame/src/kit/contracts/ask.ts +120 -0
  151. package/packages/frame/src/kit/contracts/board.ts +6 -0
  152. package/packages/frame/src/kit/contracts/by.ts +22 -0
  153. package/packages/frame/src/kit/contracts/calls.ts +46 -0
  154. package/packages/frame/src/kit/contracts/events.ts +89 -0
  155. package/packages/frame/src/kit/contracts/mode.ts +26 -0
  156. package/packages/frame/src/kit/contracts/names.ts +12 -0
  157. package/packages/frame/src/kit/contracts/peers.ts +77 -0
  158. package/packages/frame/src/kit/contracts/prompts.ts +8 -0
  159. package/packages/frame/src/kit/contracts/screen.ts +75 -0
  160. package/packages/frame/src/kit/contracts/skills.ts +81 -0
  161. package/packages/frame/src/kit/contracts/sources.ts +81 -0
  162. package/packages/frame/src/kit/contracts/views.ts +42 -0
  163. package/packages/frame/src/kit/control.ts +59 -0
  164. package/packages/frame/src/kit/dark-theme.ts +41 -0
  165. package/packages/frame/src/kit/decode.ts +210 -0
  166. package/packages/frame/src/kit/events/log.ts +313 -0
  167. package/packages/frame/src/kit/format.ts +25 -0
  168. package/packages/frame/src/kit/host.ts +4 -0
  169. package/packages/frame/src/kit/index.ts +25 -0
  170. package/packages/frame/src/kit/legacy-tasks.ts +39 -0
  171. package/packages/frame/src/kit/overlay-images.ts +36 -0
  172. package/packages/frame/src/kit/paths.ts +16 -0
  173. package/packages/frame/src/kit/screen/client.ts +74 -0
  174. package/packages/frame/src/kit/screen/feature.ts +64 -0
  175. package/packages/frame/src/kit/screen/model.ts +182 -0
  176. package/packages/frame/src/kit/screen/view.ts +838 -0
  177. package/packages/frame/src/kit/settings/files.ts +90 -0
  178. package/packages/frame/src/kit/settings/setting.ts +57 -0
  179. package/packages/frame/src/kit/settings/store.ts +192 -0
  180. package/packages/frame/src/kit/sources/file.ts +129 -0
  181. package/packages/frame/src/kit/sources/follow.ts +155 -0
  182. package/packages/frame/src/kit/testing.ts +260 -0
  183. package/packages/frame/src/kit/totals.ts +72 -0
  184. package/packages/frame/src/kit/ui/entry.ts +75 -0
  185. package/packages/frame/src/kit/ui/frame.ts +212 -0
  186. package/packages/frame/src/kit/ui/glyphs.ts +132 -0
  187. package/packages/frame/src/kit/ui/scroll.ts +14 -0
  188. package/packages/frame/src/render/diff.ts +157 -0
  189. package/packages/frame/src/render/fit.ts +86 -0
  190. package/packages/frame/src/render/format.ts +108 -0
  191. package/packages/frame/src/render/frame.ts +106 -0
  192. package/packages/frame/src/render/glyphs.ts +189 -0
  193. package/packages/frame/src/render/keys.ts +43 -0
  194. package/packages/frame/src/render/lead.ts +37 -0
  195. package/packages/frame/src/render/paint.ts +135 -0
  196. package/packages/frame/src/render/safe.ts +19 -0
  197. package/packages/frame/src/render/segments.ts +735 -0
  198. package/packages/frame/src/render/streaming.ts +223 -0
  199. package/packages/frame/src/render/timing.ts +106 -0
  200. package/packages/frame/src/render/tools.ts +167 -0
  201. package/packages/frame/src/settings.ts +105 -0
  202. package/packages/frame/src/ui/editor.ts +272 -0
  203. package/packages/frame/src/ui/effort.ts +36 -0
  204. package/packages/frame/src/ui/footer.ts +165 -0
  205. package/packages/frame/src/ui/header.ts +362 -0
  206. package/packages/frame/src/ui/history-search.ts +23 -0
  207. package/packages/frame/src/ui/interrupt.ts +21 -0
  208. package/packages/frame/src/ui/outputs.ts +170 -0
  209. package/packages/frame/src/ui/pi-entries.ts +298 -0
  210. package/packages/frame/src/ui/previews.ts +72 -0
  211. package/packages/frame/src/ui/queue.ts +75 -0
  212. package/packages/frame/src/ui/screen.ts +59 -0
  213. package/packages/frame/src/ui/timings.ts +48 -0
  214. package/packages/frame/src/ui/todos.ts +205 -0
  215. package/packages/frame/src/ui/tool-frame.ts +595 -0
  216. package/packages/frame/src/ui/working.ts +25 -0
  217. package/packages/frame/src/view/state.ts +97 -0
  218. package/packages/frame/src/view/transcript.ts +175 -0
  219. package/packages/frame/src/view/view.ts +162 -0
  220. package/packages/memory/CONTRIBUTING.md +7 -0
  221. package/packages/memory/LICENSE +21 -0
  222. package/packages/memory/README.md +44 -0
  223. package/packages/memory/SECURITY.md +20 -0
  224. package/packages/memory/package.json +55 -0
  225. package/packages/memory/skills/review-memory/SKILL.md +48 -0
  226. package/packages/memory/src/index.ts +163 -0
  227. package/packages/memory/src/prompt.ts +25 -0
  228. package/packages/memory/src/review.ts +150 -0
  229. package/packages/memory/src/secrets.ts +22 -0
  230. package/packages/memory/src/store.ts +173 -0
  231. package/packages/modes/CHANGELOG.md +104 -0
  232. package/packages/modes/CONTRIBUTING.md +7 -0
  233. package/packages/modes/LICENSE +21 -0
  234. package/packages/modes/README.md +174 -0
  235. package/packages/modes/SECURITY.md +17 -0
  236. package/packages/modes/package.json +55 -0
  237. package/packages/modes/skills/review-permissions/SKILL.md +54 -0
  238. package/packages/modes/src/bash.ts +218 -0
  239. package/packages/modes/src/deny-off.ts +62 -0
  240. package/packages/modes/src/git-safety.ts +72 -0
  241. package/packages/modes/src/index.ts +338 -0
  242. package/packages/modes/src/interview.ts +206 -0
  243. package/packages/modes/src/judge-gate.ts +113 -0
  244. package/packages/modes/src/modes.ts +121 -0
  245. package/packages/modes/src/review/apply.mjs +156 -0
  246. package/packages/modes/src/review/collect.mjs +208 -0
  247. package/packages/modes/src/review/tools.ts +71 -0
  248. package/packages/modes/src/sandbox.ts +37 -0
  249. package/packages/router/CHANGELOG.md +8 -0
  250. package/packages/router/LICENSE +21 -0
  251. package/packages/router/README.md +90 -0
  252. package/packages/router/package.json +51 -0
  253. package/packages/router/src/config.ts +65 -0
  254. package/packages/router/src/index.ts +172 -0
  255. package/packages/router/src/judge.ts +51 -0
  256. package/packages/router/src/route.ts +67 -0
  257. package/packages/web/CHANGELOG.md +36 -0
  258. package/packages/web/LICENSE +21 -0
  259. package/packages/web/README.md +87 -0
  260. package/packages/web/SECURITY.md +13 -0
  261. package/packages/web/package.json +59 -0
  262. package/packages/web/src/config.ts +109 -0
  263. package/packages/web/src/dnsfilter.ts +97 -0
  264. package/packages/web/src/extract.ts +65 -0
  265. package/packages/web/src/index.ts +217 -0
  266. package/packages/web/src/markdown.ts +122 -0
  267. package/packages/web/src/net.ts +109 -0
  268. package/packages/web/src/reader.ts +73 -0
  269. package/packages/web/src/sanitize.ts +50 -0
  270. package/packages/web/src/search.ts +76 -0
  271. package/packages/web/src/secrets.ts +22 -0
  272. package/packages/web/src/validate.ts +186 -0
  273. package/src/index.ts +156 -0
  274. package/src/settings.ts +79 -0
@@ -0,0 +1,696 @@
1
+ import { dirname, join } from "node:path";
2
+
3
+ import {
4
+ ACCOUNT,
5
+ type AccountState,
6
+ BOARD,
7
+ createApp,
8
+ PEERS,
9
+ PROMPT_FROM,
10
+ defineFeature,
11
+ drawSkillRefs,
12
+ type FeatureScope,
13
+ hideImagesUnderOverlays,
14
+ NAMES,
15
+ SKILL_REF,
16
+ provideViews,
17
+ type SessionSource,
18
+ skillNames,
19
+ sourceFor,
20
+ } from "./kit/index.ts";
21
+ import type {
22
+ ExtensionAPI,
23
+ ExtensionContext,
24
+ ReadonlyFooterDataProvider,
25
+ } from "@earendil-works/pi-coding-agent";
26
+ import { keyText } from "@earendil-works/pi-coding-agent";
27
+ import { Key, type KeyId, type TUI } from "@earendil-works/pi-tui";
28
+
29
+ import { type GitState, readGit } from "./data/git.ts";
30
+ import { cmdAsKey, SETTINGS_SHORTCUT, watchCmdKey } from "./render/keys.ts";
31
+ import { frameColorOf, type Mode, modeOf, SENT_IN_ENTRY, sentInFromEntries } from "./data/mode.ts";
32
+ import { type GithubState, readGithub } from "./data/github.ts";
33
+ import { emptySnapshot, type LiveInputs, type Snapshot, SnapshotReader } from "./data/snapshot.ts";
34
+ import type { LastVisit } from "./data/start-notes.ts";
35
+ import { Telemetry } from "./data/telemetry.ts";
36
+ import type { DeltaKind } from "./data/telemetry.ts";
37
+ import { REQUEST_CHANGES, type RequestRecord } from "./data/totals.ts";
38
+ import { visit } from "./data/visits.ts";
39
+ import { type Glyphs, glyphsOf } from "./render/glyphs.ts";
40
+ import { PLAIN, themePaint } from "./render/paint.ts";
41
+ import { claimedStatuses, renderSegments, SEGMENTS } from "./render/segments.ts";
42
+ import {
43
+ cursor,
44
+ frame,
45
+ gaugeCells,
46
+ header,
47
+ icons,
48
+ labels,
49
+ FRAME_SETTINGS,
50
+ pathLength,
51
+ SECTIONS,
52
+ SEPARATOR,
53
+ SLOTS,
54
+ userFrame,
55
+ timing,
56
+ } from "./settings.ts";
57
+ import { pastPrompts } from "./data/past-prompts.ts";
58
+ import { applyCursor, FrameEditor } from "./ui/editor.ts";
59
+ import { registerEffort } from "./ui/effort.ts";
60
+ import { FooterComponent, StripComponent } from "./ui/footer.ts";
61
+ import { PACKAGE_VERSION, HeaderComponent, type LoadedCounts } from "./ui/header.ts";
62
+ import { EXIT_WINDOW_MS, type InterruptState, nextInterrupt } from "./ui/interrupt.ts";
63
+ import { OutputView, outputsOf } from "./ui/outputs.ts";
64
+ import { framePiEntries, loadedLists, onLoadedListsChange } from "./ui/pi-entries.ts";
65
+ import { showTimings } from "./ui/timings.ts";
66
+ import { timingLine } from "./render/timing.ts";
67
+ import { frameQueue } from "./ui/queue.ts";
68
+ import type { Screen, SlotName } from "./ui/screen.ts";
69
+ import { registerTodos } from "./ui/todos.ts";
70
+ import { registerToolFrames } from "./ui/tool-frame.ts";
71
+ import { type Activity, describe, draftedTool } from "./ui/working.ts";
72
+ import { SessionView } from "./view/view.ts";
73
+
74
+ export { SEGMENT_IDS, SEGMENTS, type SegmentId } from "./render/segments.ts";
75
+ import type { SegmentId } from "./render/segments.ts";
76
+ export { ROLE_TOKENS } from "./render/paint.ts";
77
+
78
+ const STRIP_WIDGET = "pi-frame:strip";
79
+ const TICK_MS = 500;
80
+ // Once per process, however many sessions it opens.
81
+ let probedGithub = false;
82
+
83
+ interface Live {
84
+ ctx: ExtensionContext | undefined;
85
+ footerData: ReadonlyFooterDataProvider | undefined;
86
+ tui: TUI | undefined;
87
+ repaint: (() => void) | undefined;
88
+ git: GitState | undefined;
89
+ github: GithubState | undefined;
90
+ probing: boolean;
91
+ ticker: ReturnType<typeof setInterval> | undefined;
92
+ frame: Snapshot | undefined;
93
+ activity: string | undefined;
94
+ interrupts: InterruptState;
95
+ notice: string | undefined;
96
+ noticeTimer: ReturnType<typeof setTimeout> | undefined;
97
+ }
98
+
99
+ export const frameFeature = defineFeature({
100
+ id: "frame",
101
+ description:
102
+ "The start screen, a framed editor, the footer and a working line that says what runs",
103
+ sections: SECTIONS,
104
+ settings: FRAME_SETTINGS,
105
+ setup(scope) {
106
+ const telemetry = new Telemetry();
107
+ const reader = new SnapshotReader();
108
+ const live: Live = {
109
+ ctx: undefined,
110
+ footerData: undefined,
111
+ tui: undefined,
112
+ repaint: undefined,
113
+ git: undefined,
114
+ github: undefined,
115
+ probing: false,
116
+ ticker: undefined,
117
+ frame: undefined,
118
+ activity: undefined,
119
+ interrupts: {},
120
+ notice: undefined,
121
+ noticeTimer: undefined,
122
+ };
123
+
124
+ const glyphs = glyphsOf(() => icons.get(scope));
125
+ const screen = createScreen(scope, live, reader, telemetry, glyphs);
126
+ registerToolFrames(scope);
127
+ registerEffort(scope);
128
+ registerTodos(scope, () => glyphs().set);
129
+ const sentLive = new Map<string, Mode>();
130
+ let sentSaved = { length: -1, modes: new Map<string, Mode>() };
131
+ framePiEntries(() => {
132
+ if (live.ctx === undefined) return undefined;
133
+ return {
134
+ theme: live.ctx.ui.theme,
135
+ set: glyphs().set,
136
+ you: userFrame.get(scope),
137
+ from: (text: string) => PROMPT_FROM.current(scope, text)?.name,
138
+ sentIn: (id: string | undefined, text: string) => {
139
+ if (id === undefined) return sentLive.get(text);
140
+ const entries = live.ctx?.sessionManager.getEntries() ?? [];
141
+ if (entries.length !== sentSaved.length) sentSaved = { length: entries.length, modes: sentInFromEntries(entries) };
142
+ return sentSaved.modes.get(id);
143
+ },
144
+ };
145
+ });
146
+ showTimings((message, width) => {
147
+ if (live.ctx === undefined || !timing.get(scope)) return undefined;
148
+ const line = timingLine(telemetry.timingOf(message.timestamp), message, width);
149
+ return live.ctx.ui.theme.fg("dim", line);
150
+ });
151
+ onLoadedListsChange(() => queueMicrotask(() => live.repaint?.()));
152
+ frameQueue(() => live.ctx?.ui.theme);
153
+ const repaint = () => {
154
+ screen.bump();
155
+ live.repaint?.();
156
+ };
157
+
158
+ for (const entry of FRAME_SETTINGS) entry.listen(scope, repaint);
159
+ frame.listen(scope, () => live.ctx && installEditor(live.ctx, screen, live, scope));
160
+ const visitsFile = join(dirname(scope.settings.globalPath), "frame-visits.json");
161
+ let visited = false;
162
+ let lastVisit: LastVisit | undefined;
163
+
164
+ provideViews(
165
+ scope.events,
166
+ (address) => {
167
+ const ctx = live.ctx;
168
+ const source = sourceFor(scope.events, address);
169
+ if (ctx === undefined || ctx.mode !== "tui" || source === undefined) return false;
170
+ openView(ctx, screen, source).catch((error: unknown) => {
171
+ scope.warn(`pi-frame: could not show ${address.session}: ${String(error)}`);
172
+ });
173
+ return true;
174
+ },
175
+ () => live.ctx?.mode === "tui",
176
+ );
177
+
178
+ scope.registerShortcut(Key.alt("o"), {
179
+ description: "A tool call's whole output, to scroll; the arrows move between calls",
180
+ handler: (ctx) => openOutputs(ctx),
181
+ });
182
+
183
+ let stopCmdKeys: (() => void) | undefined;
184
+ watchCmdKey(() => live.tui?.terminal.kittyProtocolActive === true);
185
+
186
+ const installFooter = (ctx: ExtensionContext) =>
187
+ ctx.ui.setFooter(
188
+ (tui, _theme, data) =>
189
+ new FooterComponent(tui, data, screen, {
190
+ attach: (footerData, paint) => {
191
+ live.footerData = footerData;
192
+ // Anything that asks for a redraw bumps the revision that kept drawings compare.
193
+ live.repaint = () => {
194
+ screen.bump();
195
+ paint();
196
+ };
197
+ },
198
+ detach: () => {
199
+ live.footerData = undefined;
200
+ live.repaint = undefined;
201
+ },
202
+ }),
203
+ );
204
+
205
+ const showHeader = (ctx: ExtensionContext) =>
206
+ installHeader(
207
+ ctx,
208
+ screen,
209
+ scope,
210
+ () => lastVisit,
211
+ () => live.github,
212
+ );
213
+
214
+ // A board blanks these while it's up, and Pi can only give back its own.
215
+ scope.events.on("agent-board:closed", () => {
216
+ const ctx = live.ctx;
217
+ if (ctx?.mode !== "tui") return;
218
+ installFooter(ctx);
219
+ showHeader(ctx);
220
+ });
221
+
222
+ scope.onSessionStart((ctx) => {
223
+ live.ctx = ctx;
224
+ telemetry.reset();
225
+ telemetry.restore(ctx.sessionManager.getEntries());
226
+ sentLive.clear();
227
+ void probeGit(live);
228
+ if (ctx.mode !== "tui") return;
229
+
230
+ stopCmdKeys?.();
231
+ stopCmdKeys = ctx.ui.onTerminalInput((data) => {
232
+ const key = cmdAsKey(data);
233
+ return key === undefined ? undefined : { data: key };
234
+ });
235
+
236
+ installFooter(ctx);
237
+ ctx.ui.setWidget(STRIP_WIDGET, () => new StripComponent(screen), {
238
+ placement: "aboveEditor",
239
+ });
240
+ installEditor(ctx, screen, live, scope);
241
+ // A new session in the same pi is not a return to the folder.
242
+ if (!visited) {
243
+ visited = true;
244
+ lastVisit = visit(visitsFile, ctx.cwd, PACKAGE_VERSION, Date.now());
245
+ }
246
+ // Off the critical path: the card shows these lines when the answers arrive.
247
+ if (!probedGithub) {
248
+ probedGithub = true;
249
+ void probeGithub(live, lastVisit?.at);
250
+ }
251
+ showHeader(ctx);
252
+ });
253
+
254
+ scope.on("message_start", (event) => {
255
+ if (event.message.role !== "user") return;
256
+ const mode = modeOf(live.footerData?.getExtensionStatuses() ?? new Map());
257
+ if (mode === undefined) return;
258
+ const { content, timestamp } = event.message;
259
+ const text = typeof content === "string" ? content : content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("");
260
+ sentLive.set(text, mode);
261
+ // Normal draws as a plain message, so a resumed session needs nothing saved for it.
262
+ if (mode !== "normal") scope.appendEntry(SENT_IN_ENTRY, { at: timestamp, mode });
263
+ });
264
+
265
+ scope.onShutdown(() => {
266
+ stopCmdKeys?.();
267
+ stopCmdKeys = undefined;
268
+ stopTicking(live);
269
+ const ctx = live.ctx;
270
+ if (ctx?.mode === "tui") {
271
+ ctx.ui.setFooter(undefined);
272
+ ctx.ui.setWidget(STRIP_WIDGET, undefined);
273
+ ctx.ui.setHeader(undefined);
274
+ ctx.ui.setEditorComponent(undefined);
275
+ ctx.ui.setWorkingMessage();
276
+ }
277
+ if (live.tui !== undefined) applyCursor(live.tui, "block");
278
+ live.ctx = undefined;
279
+ live.tui = undefined;
280
+ });
281
+
282
+ // Only for the agent's calls, not pi's cache warming.
283
+ scope.on("before_provider_request", () => telemetry.providerRequestSent());
284
+ scope.on("after_provider_response", () => telemetry.providerResponseArrived());
285
+
286
+ scope.on("agent_start", () => {
287
+ telemetry.runStarted();
288
+ setActivity(live, { kind: "waiting" });
289
+ startTicking(live);
290
+ });
291
+
292
+ scope.on("turn_start", () => {
293
+ telemetry.requestStarted();
294
+ setActivity(live, { kind: "waiting" });
295
+ });
296
+
297
+ scope.on("message_start", (event) => {
298
+ if (event.message.role === "assistant") telemetry.answerStarted(event.message.timestamp);
299
+ });
300
+
301
+ scope.on("message_update", (event) => {
302
+ const message = event.message;
303
+ if (message.role !== "assistant") return;
304
+ const update = event.assistantMessageEvent;
305
+ const delta = "delta" in update ? update.delta : "";
306
+ const kind: DeltaKind = update.type.startsWith("thinking") ? "thinking" : "writing";
307
+ telemetry.answerGrew(delta, message.usage, kind);
308
+
309
+ if (update.type === "thinking_start" || update.type === "thinking_delta") {
310
+ setActivity(live, { kind: "thinking" });
311
+ } else if (update.type === "text_delta" || update.type === "text_start") {
312
+ setActivity(live, { kind: "writing" });
313
+ } else if (update.type === "toolcall_start" || update.type === "toolcall_delta") {
314
+ const tool = draftedTool(message.content);
315
+ if (tool !== undefined) setActivity(live, { kind: "drafting", tool });
316
+ }
317
+ });
318
+
319
+ scope.on("message_end", (event) => {
320
+ if (event.message.role !== "assistant") return;
321
+ const record = telemetry.answerEnded(event.message.usage);
322
+ // Pi records usage without a duration, so the session keeps it for the speeds after a resume.
323
+ if (record !== undefined) scope.appendEntry<RequestRecord>(REQUEST_CHANGES, record);
324
+ repaint();
325
+ });
326
+
327
+ scope.on("tool_execution_start", (event) => {
328
+ setActivity(live, { kind: "running", tool: event.toolName });
329
+ });
330
+
331
+ scope.on("tool_execution_end", () => void probeGit(live));
332
+
333
+ scope.on("agent_end", () => {
334
+ telemetry.runEnded();
335
+ stopTicking(live);
336
+ live.activity = undefined;
337
+ live.ctx?.ui.setWorkingMessage();
338
+ repaint();
339
+ });
340
+
341
+ scope.on("agent_settled", () => void probeGit(live));
342
+ scope.on("model_select", repaint);
343
+ scope.on("thinking_level_select", repaint);
344
+ scope.on("session_compact", repaint);
345
+ scope.on("session_tree", repaint);
346
+
347
+ scope.screen.action({
348
+ id: "explain",
349
+ section: "Appearance",
350
+ label: "What is on screen",
351
+ description: "Every piece around the editor right now, and what it means.",
352
+ run: () => explain(screen),
353
+ });
354
+ },
355
+ });
356
+
357
+ const SLOT_TITLES: Record<SlotName, string> = {
358
+ strip: "Above the editor, this answer",
359
+ stripRight: "Above the editor, on the right",
360
+ topLeft: "Frame, top left",
361
+ topRight: "Frame, top right",
362
+ bottomLeft: "Frame, bottom left",
363
+ bottomRight: "Frame, bottom right",
364
+ below: "Below the editor, the session",
365
+ belowRight: "Below the editor, on the right",
366
+ };
367
+
368
+ function explain(screen: Screen): string {
369
+ const snapshot = screen.snapshot();
370
+ const paint = screen.paint();
371
+ const lines: string[] = [paint.bold("What is on screen")];
372
+ const groups: [string, readonly SegmentId[]][] = [
373
+ ...(Object.keys(SLOT_TITLES) as SlotName[]).map((name): [string, readonly SegmentId[]] => [
374
+ SLOT_TITLES[name],
375
+ screen.slot(name),
376
+ ]),
377
+ // Not on screen: kept for when an answer feels slow.
378
+ ["The last call to the model", ["last", "wait", "speed", "server", "request"]],
379
+ ];
380
+ for (const [title, ids] of groups) {
381
+ if (ids.length === 0) continue;
382
+ lines.push("", paint.role("brand", title));
383
+ for (const id of ids) {
384
+ const [piece] = renderSegments([id], {
385
+ snapshot,
386
+ glyphs: screen.glyphs(),
387
+ paint,
388
+ options: screen.options(),
389
+ });
390
+ const meaning = id.startsWith("status:")
391
+ ? `what ${id.slice("status:".length)} reports`
392
+ : (SEGMENTS[id as keyof typeof SEGMENTS]?.describe ?? "");
393
+ const shown = piece === undefined ? paint.dim("(nothing yet)") : piece.text;
394
+ lines.push(` ${shown}`, ` ${paint.dim(`${id}: ${meaning}`)}`);
395
+ }
396
+ }
397
+ lines.push("", paint.dim("In is what was sent to the model, out is what came back."));
398
+ return lines.join("\n");
399
+ }
400
+
401
+ function createScreen(
402
+ scope: FeatureScope,
403
+ live: Live,
404
+ reader: SnapshotReader,
405
+ telemetry: Telemetry,
406
+ glyphs: () => Glyphs,
407
+ ): Screen {
408
+ let revision = 0;
409
+ return {
410
+ snapshot() {
411
+ const ctx = live.ctx;
412
+ if (ctx === undefined) return emptySnapshot();
413
+ if (live.frame !== undefined) return live.frame;
414
+ const snapshot = reader.read(ctx, {
415
+ branch: live.footerData?.getGitBranch() ?? null,
416
+ git: live.git,
417
+ account: accountOf(scope, ctx.model?.provider),
418
+ request: telemetry.request(),
419
+ last: telemetry.last(),
420
+ run: telemetry.run(),
421
+ statuses: live.footerData?.getExtensionStatuses() ?? new Map(),
422
+ sandboxInstalled: sandboxInstalled(scope),
423
+ ...boardAndPeersOf(scope),
424
+ });
425
+ live.frame = snapshot;
426
+ queueMicrotask(() => {
427
+ live.frame = undefined;
428
+ });
429
+ return snapshot;
430
+ },
431
+ glyphs,
432
+ revision: () => revision,
433
+ bump: () => {
434
+ revision++;
435
+ },
436
+ paint: (border) => (live.ctx === undefined ? PLAIN : themePaint(live.ctx.ui.theme, border)),
437
+ separator: () => SEPARATOR,
438
+ options: () => ({
439
+ pathLength,
440
+ gaugeCells,
441
+ labels,
442
+ claimed: claimedStatuses(Object.values(SLOTS)),
443
+ }),
444
+ statusesKey: () => [...(live.footerData?.getExtensionStatuses().values() ?? [])].join("\u0000"),
445
+ notice: () => {
446
+ const theme = live.ctx?.ui.theme;
447
+ return live.notice === undefined || theme === undefined
448
+ ? undefined
449
+ : theme.fg("warning", live.notice);
450
+ },
451
+ interrupt: (clearEditor) => pressCtrlC(live, clearEditor),
452
+ slot: (name) => SLOTS[name],
453
+ promptColor: (kind) => {
454
+ const theme = live.ctx?.ui.theme;
455
+ if (theme === undefined) return (text) => text;
456
+ return (text) => theme.fg(kind === "bash" ? "bashMode" : "accent", text);
457
+ },
458
+ pastPrompts: () => {
459
+ try {
460
+ return pastPrompts(live.ctx?.sessionManager.getSessionDir() ?? "");
461
+ } catch {
462
+ return [];
463
+ }
464
+ },
465
+ frameStyle: () => frame.get(scope),
466
+ frameColor: () => {
467
+ const theme = live.ctx?.ui.theme;
468
+ const color = frameColorOf(live.footerData?.getExtensionStatuses() ?? new Map());
469
+ return theme === undefined || color === undefined
470
+ ? undefined
471
+ : (text) => theme.fg(color, text);
472
+ },
473
+ cursor: () => cursor,
474
+ decorate: (line) => {
475
+ const theme = live.ctx?.ui.theme;
476
+ if (theme === undefined) return line;
477
+ return drawSkillRefs(line, skillNames(scope), (name) =>
478
+ theme.fg("customMessageLabel", `${SKILL_REF}${name}`),
479
+ );
480
+ },
481
+ skills: () => skillNames(scope).length > 0,
482
+ };
483
+ }
484
+
485
+ function accountOf(scope: FeatureScope, provider: string | undefined): AccountState | undefined {
486
+ return provider === undefined ? undefined : ACCOUNT.current(scope, provider);
487
+ }
488
+
489
+ function boardAndPeersOf(
490
+ scope: FeatureScope,
491
+ ): Pick<LiveInputs, "board" | "me" | "peers" | "peersRooms" | "peersUnread" | "peersWriting"> {
492
+ const peers = PEERS.current(scope);
493
+ const handle = NAMES.current(scope)?.handle;
494
+ const color = peers?.me?.handle === handle ? peers?.me?.color : undefined;
495
+ return {
496
+ board: BOARD.current(scope),
497
+ me: handle === undefined ? undefined : { handle, ...(color === undefined ? {} : { color }) },
498
+ peers: peers?.peers,
499
+ peersRooms: peers?.rooms,
500
+ peersUnread: peers?.unread,
501
+ peersWriting: peers?.writing,
502
+ };
503
+ }
504
+
505
+ function pressCtrlC(live: Live, clearEditor: () => void): void {
506
+ const ctx = live.ctx;
507
+ if (ctx === undefined) return;
508
+ const now = Date.now();
509
+ const step = nextInterrupt(live.interrupts, ctx.isIdle(), now);
510
+ live.interrupts = step.state;
511
+ if (step.action === "exit") {
512
+ ctx.shutdown();
513
+ return;
514
+ }
515
+ if (step.action === "abort") ctx.abort();
516
+ else clearEditor();
517
+ live.notice = step.action === "abort" ? "Aborted" : `Press ${keyText("app.clear")} again to exit`;
518
+ if (live.noticeTimer !== undefined) clearTimeout(live.noticeTimer);
519
+ live.noticeTimer = setTimeout(() => {
520
+ live.notice = undefined;
521
+ live.interrupts = {};
522
+ live.repaint?.();
523
+ }, EXIT_WINDOW_MS);
524
+ live.noticeTimer.unref?.();
525
+ live.repaint?.();
526
+ }
527
+
528
+ function installEditor(
529
+ ctx: ExtensionContext,
530
+ screen: Screen,
531
+ live: Live,
532
+ scope: FeatureScope,
533
+ ): void {
534
+ if (ctx.mode !== "tui") return;
535
+ if (frame.get(scope) === "off") {
536
+ ctx.ui.setEditorComponent(undefined);
537
+ return;
538
+ }
539
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => {
540
+ live.tui = tui;
541
+ applyCursor(tui, cursor);
542
+ return new FrameEditor(tui, theme, keybindings, screen);
543
+ });
544
+ }
545
+
546
+ function installHeader(
547
+ ctx: ExtensionContext,
548
+ screen: Screen,
549
+ scope: FeatureScope,
550
+ lastVisit: () => LastVisit | undefined,
551
+ github: () => GithubState | undefined,
552
+ ): void {
553
+ if (ctx.mode !== "tui") return;
554
+ ctx.ui.setHeader(
555
+ (tui) =>
556
+ new HeaderComponent(
557
+ screen,
558
+ {
559
+ style: () => header,
560
+ counts: () => loadedCounts(scope),
561
+ lastVisit,
562
+ github,
563
+ loaded: loadedLists,
564
+ },
565
+ tui,
566
+ ),
567
+ );
568
+ }
569
+
570
+ function sandboxInstalled(pi: ExtensionAPI): boolean {
571
+ return pi.getCommands().some((command) => command.name === "sandbox-enable");
572
+ }
573
+
574
+ function loadedCounts(pi: ExtensionAPI): LoadedCounts {
575
+ const commands = pi.getCommands();
576
+ const extensions = new Set<string>();
577
+ for (const command of commands) {
578
+ if (command.source === "extension") extensions.add(command.sourceInfo.path);
579
+ }
580
+ for (const tool of pi.getAllTools()) {
581
+ const source = tool.sourceInfo.source;
582
+ if (source !== "builtin" && source !== "sdk") extensions.add(tool.sourceInfo.path);
583
+ }
584
+ return {
585
+ tools: pi.getActiveTools().length,
586
+ skills: commands.filter((command) => command.source === "skill").length,
587
+ prompts: commands.filter((command) => command.source === "prompt").length,
588
+ extensions: extensions.size,
589
+ };
590
+ }
591
+
592
+ function setActivity(live: Live, activity: Activity): void {
593
+ const message = describe(activity);
594
+ if (message === live.activity) return;
595
+ live.activity = message;
596
+ live.ctx?.ui.setWorkingMessage(message);
597
+ }
598
+
599
+ async function probeGithub(live: Live, since: number | undefined): Promise<void> {
600
+ const ctx = live.ctx;
601
+ if (ctx === undefined) return;
602
+ const github = await readGithub(ctx.cwd, since);
603
+ if (live.ctx === undefined) return;
604
+ live.github = github;
605
+ // The card keeps its drawing for a second; this makes the new lines appear.
606
+ live.repaint?.();
607
+ }
608
+
609
+ async function probeGit(live: Live): Promise<void> {
610
+ const ctx = live.ctx;
611
+ if (ctx === undefined || live.probing) return;
612
+ live.probing = true;
613
+ try {
614
+ live.git = await readGit(ctx.cwd);
615
+ live.repaint?.();
616
+ } finally {
617
+ live.probing = false;
618
+ }
619
+ }
620
+
621
+ function startTicking(live: Live): void {
622
+ stopTicking(live);
623
+ live.ticker = setInterval(() => live.repaint?.(), TICK_MS);
624
+ live.ticker.unref?.();
625
+ }
626
+
627
+ function stopTicking(live: Live): void {
628
+ if (live.ticker === undefined) return;
629
+ clearInterval(live.ticker);
630
+ live.ticker = undefined;
631
+ }
632
+
633
+ /** The kit's settings screen asks for Alt+S, which pi-sandbox also needs and can't give up. */
634
+ function withSettingsKey(pi: ExtensionAPI): ExtensionAPI {
635
+ return new Proxy(pi, {
636
+ get(target, name) {
637
+ if (name === "registerShortcut") {
638
+ return (key: KeyId, options: Parameters<ExtensionAPI["registerShortcut"]>[1]) =>
639
+ target.registerShortcut(key === Key.alt("s") ? SETTINGS_SHORTCUT : key, options);
640
+ }
641
+ if (name === "registerCommand") {
642
+ return (command: string, options: Parameters<ExtensionAPI["registerCommand"]>[1]) =>
643
+ target.registerCommand(command, {
644
+ ...options,
645
+ description: options.description?.replace("Alt+S", "Ctrl+S"),
646
+ });
647
+ }
648
+ const value: unknown = Reflect.get(target, name);
649
+ return typeof value === "function" ? value.bind(target) : value;
650
+ },
651
+ });
652
+ }
653
+
654
+ export default function piLook(pi: ExtensionAPI): void {
655
+ createApp(withSettingsKey(pi), { name: "pi-frame" }).use(frameFeature).build();
656
+ }
657
+
658
+ async function openView(
659
+ ctx: ExtensionContext,
660
+ screen: Screen,
661
+ source: SessionSource,
662
+ ): Promise<void> {
663
+ let view: SessionView | undefined;
664
+ await ctx.ui.custom<void>(
665
+ (tui, theme, _keybindings, done) => {
666
+ hideImagesUnderOverlays(tui);
667
+ view = new SessionView({ tui, theme, screen, source, close: () => done() });
668
+ return view;
669
+ },
670
+ {
671
+ overlay: true,
672
+ overlayOptions: { anchor: "center", width: "100%", maxHeight: "100%" },
673
+ },
674
+ );
675
+ view?.dispose();
676
+ }
677
+
678
+ async function openOutputs(ctx: ExtensionContext): Promise<void> {
679
+ if (ctx.mode !== "tui") return;
680
+ const outputs = outputsOf(ctx.sessionManager.getBranch());
681
+ await ctx.ui.custom<void>(
682
+ (tui, theme, _keybindings, done) => {
683
+ hideImagesUnderOverlays(tui);
684
+ return new OutputView({
685
+ theme,
686
+ outputs,
687
+ rows: () => Math.floor(tui.terminal.rows * 0.85),
688
+ close: () => done(),
689
+ });
690
+ },
691
+ {
692
+ overlay: true,
693
+ overlayOptions: { anchor: "center", width: "90%", minWidth: 60, maxHeight: "85%" },
694
+ },
695
+ );
696
+ }