@ymy88/pi-subagents 0.0.0-stage → 0.24.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 (196) hide show
  1. package/CHANGELOG.md +904 -0
  2. package/CONTRIBUTING.md +72 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1170 -2
  5. package/SECURITY.md +95 -0
  6. package/dist/abortable.d.ts +12 -0
  7. package/dist/abortable.js +42 -0
  8. package/dist/agent-color.d.ts +35 -0
  9. package/dist/agent-color.js +123 -0
  10. package/dist/agent-file-toggle.d.ts +133 -0
  11. package/dist/agent-file-toggle.js +287 -0
  12. package/dist/agent-manager.d.ts +552 -0
  13. package/dist/agent-manager.js +1466 -0
  14. package/dist/agent-record-entry.d.ts +96 -0
  15. package/dist/agent-record-entry.js +121 -0
  16. package/dist/agent-runner.d.ts +310 -0
  17. package/dist/agent-runner.js +1195 -0
  18. package/dist/agent-source-badge.d.ts +50 -0
  19. package/dist/agent-source-badge.js +74 -0
  20. package/dist/agent-types.d.ts +119 -0
  21. package/dist/agent-types.js +286 -0
  22. package/dist/child-context.d.ts +2 -0
  23. package/dist/child-context.js +12 -0
  24. package/dist/completion-outbox.d.ts +63 -0
  25. package/dist/completion-outbox.js +104 -0
  26. package/dist/context.d.ts +12 -0
  27. package/dist/context.js +56 -0
  28. package/dist/cross-extension-rpc.d.ts +72 -0
  29. package/dist/cross-extension-rpc.js +153 -0
  30. package/dist/custom-agents.d.ts +77 -0
  31. package/dist/custom-agents.js +396 -0
  32. package/dist/default-agents.d.ts +7 -0
  33. package/dist/default-agents.js +121 -0
  34. package/dist/enabled-models.d.ts +49 -0
  35. package/dist/enabled-models.js +145 -0
  36. package/dist/env.d.ts +6 -0
  37. package/dist/env.js +28 -0
  38. package/dist/group-join.d.ts +32 -0
  39. package/dist/group-join.js +116 -0
  40. package/dist/index.d.ts +50 -0
  41. package/dist/index.js +4111 -0
  42. package/dist/invocation-config.d.ts +108 -0
  43. package/dist/invocation-config.js +83 -0
  44. package/dist/memory.d.ts +53 -0
  45. package/dist/memory.js +165 -0
  46. package/dist/mention-clone.d.ts +79 -0
  47. package/dist/mention-clone.js +155 -0
  48. package/dist/mention.d.ts +81 -0
  49. package/dist/mention.js +131 -0
  50. package/dist/model-resolver.d.ts +36 -0
  51. package/dist/model-resolver.js +95 -0
  52. package/dist/model-scope.d.ts +49 -0
  53. package/dist/model-scope.js +48 -0
  54. package/dist/nested-tools.d.ts +57 -0
  55. package/dist/nested-tools.js +303 -0
  56. package/dist/output-file.d.ts +43 -0
  57. package/dist/output-file.js +153 -0
  58. package/dist/package-resources.d.ts +240 -0
  59. package/dist/package-resources.js +519 -0
  60. package/dist/prompts.d.ts +76 -0
  61. package/dist/prompts.js +121 -0
  62. package/dist/schedule-store.d.ts +38 -0
  63. package/dist/schedule-store.js +155 -0
  64. package/dist/schedule.d.ts +109 -0
  65. package/dist/schedule.js +359 -0
  66. package/dist/settings.d.ts +398 -0
  67. package/dist/settings.js +282 -0
  68. package/dist/skill-loader.d.ts +24 -0
  69. package/dist/skill-loader.js +93 -0
  70. package/dist/status-note.d.ts +61 -0
  71. package/dist/status-note.js +85 -0
  72. package/dist/structured-output.d.ts +61 -0
  73. package/dist/structured-output.js +112 -0
  74. package/dist/types.d.ts +391 -0
  75. package/dist/types.js +5 -0
  76. package/dist/ui/agent-mention.d.ts +82 -0
  77. package/dist/ui/agent-mention.js +187 -0
  78. package/dist/ui/agent-widget.d.ts +219 -0
  79. package/dist/ui/agent-widget.js +585 -0
  80. package/dist/ui/conversation-viewer.d.ts +177 -0
  81. package/dist/ui/conversation-viewer.js +905 -0
  82. package/dist/ui/fleet-list.d.ts +211 -0
  83. package/dist/ui/fleet-list.js +489 -0
  84. package/dist/ui/schedule-menu.d.ts +16 -0
  85. package/dist/ui/schedule-menu.js +94 -0
  86. package/dist/ui/select-item.d.ts +27 -0
  87. package/dist/ui/select-item.js +34 -0
  88. package/dist/ui/viewer-keys.d.ts +22 -0
  89. package/dist/ui/viewer-keys.js +18 -0
  90. package/dist/ui/workflow-card.d.ts +175 -0
  91. package/dist/ui/workflow-card.js +332 -0
  92. package/dist/ui/workflow-dialog.d.ts +305 -0
  93. package/dist/ui/workflow-dialog.js +843 -0
  94. package/dist/ui/workflow-menu.d.ts +60 -0
  95. package/dist/ui/workflow-menu.js +147 -0
  96. package/dist/usage.d.ts +135 -0
  97. package/dist/usage.js +120 -0
  98. package/dist/workflow/collisions.d.ts +95 -0
  99. package/dist/workflow/collisions.js +88 -0
  100. package/dist/workflow/entry.d.ts +32 -0
  101. package/dist/workflow/entry.js +29 -0
  102. package/dist/workflow/host.d.ts +62 -0
  103. package/dist/workflow/host.js +419 -0
  104. package/dist/workflow/journal.d.ts +97 -0
  105. package/dist/workflow/journal.js +120 -0
  106. package/dist/workflow/json-schema.d.ts +52 -0
  107. package/dist/workflow/json-schema.js +112 -0
  108. package/dist/workflow/meta.d.ts +67 -0
  109. package/dist/workflow/meta.js +317 -0
  110. package/dist/workflow/progress.d.ts +224 -0
  111. package/dist/workflow/progress.js +361 -0
  112. package/dist/workflow/runtime.d.ts +334 -0
  113. package/dist/workflow/runtime.js +830 -0
  114. package/dist/workflow/saved.d.ts +102 -0
  115. package/dist/workflow/saved.js +247 -0
  116. package/dist/workflow/task.d.ts +136 -0
  117. package/dist/workflow/task.js +207 -0
  118. package/dist/workflow/tool-description.d.ts +38 -0
  119. package/dist/workflow/tool-description.js +199 -0
  120. package/dist/workflow/worker-source.d.ts +47 -0
  121. package/dist/workflow/worker-source.js +778 -0
  122. package/dist/worktree.d.ts +52 -0
  123. package/dist/worktree.js +164 -0
  124. package/dist/xml.d.ts +10 -0
  125. package/dist/xml.js +12 -0
  126. package/docs/packages.md +211 -0
  127. package/docs/rpc.md +192 -0
  128. package/docs/workflows.md +447 -0
  129. package/examples/agent-tool-description.md +42 -0
  130. package/examples/workflows/compose.js +51 -0
  131. package/examples/workflows/fan-out-audit.js +47 -0
  132. package/examples/workflows/gated-fix.js +60 -0
  133. package/examples/workflows/lib/count-child.js +27 -0
  134. package/examples/workflows/review-panel.js +63 -0
  135. package/examples/workflows/structured-findings.js +78 -0
  136. package/package.json +74 -4
  137. package/src/abortable.ts +43 -0
  138. package/src/agent-color.ts +161 -0
  139. package/src/agent-file-toggle.ts +297 -0
  140. package/src/agent-manager.ts +1735 -0
  141. package/src/agent-record-entry.ts +153 -0
  142. package/src/agent-runner.ts +1468 -0
  143. package/src/agent-source-badge.ts +75 -0
  144. package/src/agent-types.ts +346 -0
  145. package/src/child-context.ts +15 -0
  146. package/src/completion-outbox.ts +116 -0
  147. package/src/context.ts +58 -0
  148. package/src/cross-extension-rpc.ts +221 -0
  149. package/src/custom-agents.ts +452 -0
  150. package/src/default-agents.ts +125 -0
  151. package/src/enabled-models.ts +180 -0
  152. package/src/env.ts +33 -0
  153. package/src/group-join.ts +141 -0
  154. package/src/index.ts +4433 -0
  155. package/src/invocation-config.ts +155 -0
  156. package/src/memory.ts +179 -0
  157. package/src/mention-clone.ts +195 -0
  158. package/src/mention.ts +141 -0
  159. package/src/model-resolver.ts +118 -0
  160. package/src/model-scope.ts +70 -0
  161. package/src/nested-tools.ts +426 -0
  162. package/src/output-file.ts +164 -0
  163. package/src/package-resources.ts +652 -0
  164. package/src/prompts.ts +171 -0
  165. package/src/schedule-store.ts +153 -0
  166. package/src/schedule.ts +386 -0
  167. package/src/settings.ts +650 -0
  168. package/src/skill-loader.ts +102 -0
  169. package/src/status-note.ts +90 -0
  170. package/src/structured-output.ts +130 -0
  171. package/src/types.ts +404 -0
  172. package/src/ui/agent-mention.ts +216 -0
  173. package/src/ui/agent-widget.ts +661 -0
  174. package/src/ui/conversation-viewer.ts +928 -0
  175. package/src/ui/fleet-list.ts +559 -0
  176. package/src/ui/schedule-menu.ts +105 -0
  177. package/src/ui/select-item.ts +45 -0
  178. package/src/ui/viewer-keys.ts +43 -0
  179. package/src/ui/workflow-card.ts +470 -0
  180. package/src/ui/workflow-dialog.ts +1115 -0
  181. package/src/ui/workflow-menu.ts +193 -0
  182. package/src/usage.ts +167 -0
  183. package/src/workflow/collisions.ts +123 -0
  184. package/src/workflow/entry.ts +47 -0
  185. package/src/workflow/host.ts +467 -0
  186. package/src/workflow/journal.ts +164 -0
  187. package/src/workflow/json-schema.ts +129 -0
  188. package/src/workflow/meta.ts +325 -0
  189. package/src/workflow/progress.ts +551 -0
  190. package/src/workflow/runtime.ts +1219 -0
  191. package/src/workflow/saved.ts +259 -0
  192. package/src/workflow/task.ts +302 -0
  193. package/src/workflow/tool-description.ts +200 -0
  194. package/src/workflow/worker-source.ts +781 -0
  195. package/src/worktree.ts +205 -0
  196. package/src/xml.ts +13 -0
@@ -0,0 +1,177 @@
1
+ /**
2
+ * conversation-viewer.ts — Live conversation overlay for viewing agent sessions.
3
+ *
4
+ * Displays a scrollable, live-updating view of an agent's conversation.
5
+ * Subscribes to session events for real-time streaming updates.
6
+ */
7
+ import { type AgentSession } from "@earendil-works/pi-coding-agent";
8
+ import { type Component, type Focusable, type OverlayOptions, type ScrollViewScrollbar, type TUI, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
9
+ import type { AgentRecord, ViewerMarkdownMode } from "../types.js";
10
+ import type { Theme } from "./agent-widget.js";
11
+ import { type AgentActivity } from "./agent-widget.js";
12
+ import { type ViewerKeybindings } from "./viewer-keys.js";
13
+ /** Height ceiling shared by the overlay's `maxHeight` and the viewer's internal viewport cap. */
14
+ export declare const VIEWPORT_HEIGHT_PCT = 70;
15
+ /** Follow the active renderer, not a setting that may require a restart. */
16
+ export declare function getConversationOverlayOptions(tui: Pick<TUI, "mode">): OverlayOptions;
17
+ /**
18
+ * Cap on a single tool result or bash output before the viewer elides the rest.
19
+ *
20
+ * The cap is not cosmetic — it bounds render cost. `buildContentLines()` runs on
21
+ * every render *and* on every scroll key (`handleInput` calls it to compute
22
+ * `maxScroll`), so an uncapped 200 KB result costs ~6 ms per keystroke to parse
23
+ * as Markdown, against ~0.5 ms once capped and effectively nothing on a cache
24
+ * hit (best of 5, width 76). 16 KB is roughly a screenful at every terminal size
25
+ * and still ~30x the 500 characters this replaces, which was small enough to cut
26
+ * most real results mid-sentence.
27
+ */
28
+ export declare const RESULT_MAX_CHARS = 16000;
29
+ /** The `b` affordance: whether this run can be handed to the background now, and the handoff. */
30
+ export interface ViewerBackgroundAction {
31
+ available(): boolean;
32
+ send(): void;
33
+ }
34
+ export declare class ConversationViewer implements Component, Focusable {
35
+ private tui;
36
+ private session;
37
+ private record;
38
+ private activity;
39
+ private theme;
40
+ private done;
41
+ /** Abort the agent shown here. Omitted → no stop affordance (e.g. read-only history). */
42
+ private onStop?;
43
+ /** Send a steering message to the agent. Omitted → no compose affordance. */
44
+ private onSteer?;
45
+ /**
46
+ * Whether the header shows an estimated cost after the token count. Read
47
+ * once, at construction: the overlay is opened from a menu, so the setting
48
+ * cannot change while it is on screen.
49
+ */
50
+ private showCost;
51
+ /**
52
+ * The current `viewerMarkdown` setting. Read live rather than captured,
53
+ * unlike `showCost`: `m` changes it while the overlay is on screen.
54
+ * Omitted → `assistant`.
55
+ */
56
+ private viewerMarkdown?;
57
+ /**
58
+ * Persist a mode chosen with `m`, so the key and `/agents → Settings` mean
59
+ * the same thing. Omitted → `m` still cycles, viewer-locally.
60
+ */
61
+ private onMarkdownMode?;
62
+ /**
63
+ * Hand this run to the background. `available` is read live — it turns
64
+ * false the instant the handoff lands or the run ends. Omitted → no `b`
65
+ * affordance (history views).
66
+ */
67
+ private onBackground?;
68
+ private scrollOffset;
69
+ private autoScroll;
70
+ focused: boolean;
71
+ private readonly fullscreen;
72
+ private viewport;
73
+ private scrollbarGrabOffset;
74
+ private footerTargets;
75
+ private latestTarget;
76
+ private newMessages;
77
+ private readonly scrollView;
78
+ private unsubscribe;
79
+ private lastInnerW;
80
+ private closed;
81
+ /** Two-press confirm guard for the stop key, so a stray key can't kill the agent. */
82
+ private stopArmed;
83
+ private keys;
84
+ /** Steering composer — present while the user is typing a message to the agent. */
85
+ private composer;
86
+ /** Resolved once: pi's Markdown theme is fixed for the life of the process. */
87
+ private readonly markdownTheme;
88
+ /** Set by the `m` key. Wins over the setting so `m` works without a persist hook. */
89
+ private markdownModeOverride;
90
+ /**
91
+ * One `Markdown` per message, so its own text/width cache does the work. A
92
+ * fresh instance per render would re-parse the whole transcript on every
93
+ * keystroke — the component caches, but only across calls to the same object.
94
+ * Weak so a compacted-away message doesn't pin its render.
95
+ */
96
+ private readonly markdownCache;
97
+ /** One block per tool call id, so a redraw reuses the component's own caches. */
98
+ private readonly toolBlocks;
99
+ /**
100
+ * Whether calls render through pi's components. Probe-gated: without pi's
101
+ * theme the viewer keeps its own plain rendering rather than throwing.
102
+ */
103
+ private readonly toolRendering;
104
+ /** Whether tool blocks show their full output; toggled with pi's expand key. */
105
+ private toolsExpanded;
106
+ constructor(tui: TUI, session: AgentSession, record: AgentRecord, activity: AgentActivity | undefined, theme: Theme, done: (result: undefined) => void,
107
+ /** Abort the agent shown here. Omitted → no stop affordance (e.g. read-only history). */
108
+ onStop?: (() => void) | undefined,
109
+ /** User keybindings from `ctx.ui.custom()`. Omitted → hardcoded defaults. */
110
+ keybindings?: ViewerKeybindings,
111
+ /** Send a steering message to the agent. Omitted → no compose affordance. */
112
+ onSteer?: ((message: string) => void) | undefined,
113
+ /**
114
+ * Whether the header shows an estimated cost after the token count. Read
115
+ * once, at construction: the overlay is opened from a menu, so the setting
116
+ * cannot change while it is on screen.
117
+ */
118
+ showCost?: boolean,
119
+ /**
120
+ * The current `viewerMarkdown` setting. Read live rather than captured,
121
+ * unlike `showCost`: `m` changes it while the overlay is on screen.
122
+ * Omitted → `assistant`.
123
+ */
124
+ viewerMarkdown?: (() => ViewerMarkdownMode) | undefined,
125
+ /**
126
+ * Persist a mode chosen with `m`, so the key and `/agents → Settings` mean
127
+ * the same thing. Omitted → `m` still cycles, viewer-locally.
128
+ */
129
+ onMarkdownMode?: ((mode: ViewerMarkdownMode) => void) | undefined,
130
+ /** Pi's fullscreen scrollbar preference, captured when the observer opens. */
131
+ scrollbarMode?: ScrollViewScrollbar,
132
+ /**
133
+ * Hand this run to the background. `available` is read live — it turns
134
+ * false the instant the handoff lands or the run ends. Omitted → no `b`
135
+ * affordance (history views).
136
+ */
137
+ onBackground?: ViewerBackgroundAction | undefined);
138
+ handleInput(data: string): void;
139
+ private jumpToLatest;
140
+ handleMouse(event: TuiMouseEvent): TuiMouseEventResult;
141
+ render(width: number): string[];
142
+ /** Stoppable only when a stop handler exists and the agent is still active. */
143
+ private isStoppable;
144
+ /** The mode in force: an `m` press, else the setting, else the default. */
145
+ private markdownMode;
146
+ /** Wrap `text` literally — the pre-Markdown path, and the fallback from it. */
147
+ private rawLines;
148
+ /** Render `text` as Markdown, reusing this message's component instance. */
149
+ private markdownLines;
150
+ /** Steerable only when a steer handler exists and the agent is still active. */
151
+ private canSteer;
152
+ /**
153
+ * Asked of the owner rather than derived from the record: only the caller
154
+ * blocked on this run knows it can let go of it, and `blocking` alone also
155
+ * matches spawns nobody can hand off (the agent generator).
156
+ */
157
+ private canSendToBackground;
158
+ /** Open the inline steering composer and route subsequent input to it. */
159
+ private openComposer;
160
+ invalidate(): void;
161
+ dispose(): void;
162
+ private viewportHeight;
163
+ private chromeLines;
164
+ private invocationLine;
165
+ private buildContentLines;
166
+ /**
167
+ * One tool call as pi draws it in the main transcript: the arguments on the
168
+ * call, then the result in that tool's own format — a bash box, read line
169
+ * numbers, an edit diff. Blocks are cached per call id because
170
+ * `ToolExecutionComponent` rebuilds its renderer tree on every update.
171
+ *
172
+ * A tool without a renderer still renders: the component falls back to a
173
+ * generic `name key=value` header plus a bounded preview that the expand key
174
+ * unfolds.
175
+ */
176
+ private toolBlockLines;
177
+ }