shariq-pi-extensions 0.1.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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/docs/ARCHITECTURE.md +54 -0
  5. package/docs/DEVELOPMENT.md +88 -0
  6. package/docs/EXTENSIONS.md +89 -0
  7. package/extensions/antigravity-provider/LICENSE +21 -0
  8. package/extensions/antigravity-provider/README.md +23 -0
  9. package/extensions/antigravity-provider/antigravity/cloud-code-assist.ts +519 -0
  10. package/extensions/antigravity-provider/antigravity/index.ts +67 -0
  11. package/extensions/antigravity-provider/antigravity/models.ts +184 -0
  12. package/extensions/antigravity-provider/antigravity/oauth.ts +499 -0
  13. package/extensions/antigravity-provider/index.ts +3 -0
  14. package/extensions/ask-user/README.md +21 -0
  15. package/extensions/ask-user/index.ts +417 -0
  16. package/extensions/background-terminals/README.md +43 -0
  17. package/extensions/background-terminals/index.ts +400 -0
  18. package/extensions/background-terminals/src/manager.ts +480 -0
  19. package/extensions/background-terminals/src/output-buffer.ts +110 -0
  20. package/extensions/background-terminals/src/presentation.ts +74 -0
  21. package/extensions/background-terminals/src/types.ts +47 -0
  22. package/extensions/background-terminals/src/ui.ts +478 -0
  23. package/extensions/context-usage/LICENSE +21 -0
  24. package/extensions/context-usage/README.md +20 -0
  25. package/extensions/context-usage/index.ts +2006 -0
  26. package/extensions/context-usage/lib/ansi.ts +60 -0
  27. package/extensions/context-usage/lib/boundary.ts +27 -0
  28. package/extensions/context-usage/lib/chat.ts +190 -0
  29. package/extensions/context-usage/lib/config.ts +30 -0
  30. package/extensions/context-usage/lib/fmt.ts +59 -0
  31. package/extensions/context-usage/lib/style.ts +260 -0
  32. package/extensions/copy-all/README.md +15 -0
  33. package/extensions/copy-all/index.ts +72 -0
  34. package/extensions/factory-provider/API_KEYS.md +17 -0
  35. package/extensions/factory-provider/AUTH.md +15 -0
  36. package/extensions/factory-provider/README.md +90 -0
  37. package/extensions/factory-provider/REFRESH_MODELS.md +185 -0
  38. package/extensions/factory-provider/UPDATING.md +97 -0
  39. package/extensions/factory-provider/factory/api-keys.ts +407 -0
  40. package/extensions/factory-provider/factory/auth.ts +132 -0
  41. package/extensions/factory-provider/factory/constants.ts +15 -0
  42. package/extensions/factory-provider/factory/dashboard.ts +363 -0
  43. package/extensions/factory-provider/factory/droid.ts +84 -0
  44. package/extensions/factory-provider/factory/limits.ts +342 -0
  45. package/extensions/factory-provider/factory/models.ts +283 -0
  46. package/extensions/factory-provider/factory/responses.ts +331 -0
  47. package/extensions/factory-provider/factory/warm-theme.ts +53 -0
  48. package/extensions/factory-provider/factory/websocket.ts +130 -0
  49. package/extensions/factory-provider/index.ts +204 -0
  50. package/extensions/factory-provider/scripts/audit-reasoning-efforts.py +84 -0
  51. package/extensions/firecrawl-web/README.md +31 -0
  52. package/extensions/firecrawl-web/auth.ts +92 -0
  53. package/extensions/firecrawl-web/client.ts +238 -0
  54. package/extensions/firecrawl-web/index.ts +96 -0
  55. package/extensions/firecrawl-web/output.ts +125 -0
  56. package/extensions/git-info/README.md +25 -0
  57. package/extensions/git-info/index.ts +162 -0
  58. package/extensions/git-info/src/git.ts +206 -0
  59. package/extensions/git-info/src/ui.ts +291 -0
  60. package/extensions/goal/README.md +44 -0
  61. package/extensions/goal/constants.ts +4 -0
  62. package/extensions/goal/extension.ts +1064 -0
  63. package/extensions/goal/index.ts +2 -0
  64. package/extensions/goal/types.ts +56 -0
  65. package/extensions/goal/ui.ts +334 -0
  66. package/extensions/orchestration/README.md +58 -0
  67. package/extensions/orchestration/dashboard.ts +192 -0
  68. package/extensions/orchestration/engine.ts +706 -0
  69. package/extensions/orchestration/index.ts +243 -0
  70. package/extensions/orchestration/prompts.ts +124 -0
  71. package/extensions/orchestration/protocol.ts +116 -0
  72. package/extensions/orchestration/settings-ui.ts +41 -0
  73. package/extensions/orchestration/settings.ts +59 -0
  74. package/extensions/orchestration/storage.ts +49 -0
  75. package/extensions/orchestration/types.ts +105 -0
  76. package/extensions/performance-status/README.md +5 -0
  77. package/extensions/performance-status/index.ts +171 -0
  78. package/extensions/pi-memory/README.md +53 -0
  79. package/extensions/pi-memory/index.ts +326 -0
  80. package/extensions/pi-memory/src/config.ts +75 -0
  81. package/extensions/pi-memory/src/database.ts +617 -0
  82. package/extensions/pi-memory/src/extraction.ts +178 -0
  83. package/extensions/pi-memory/src/project.ts +80 -0
  84. package/extensions/pi-memory/src/projection.ts +59 -0
  85. package/extensions/pi-memory/src/redaction.ts +60 -0
  86. package/extensions/pi-memory/src/retrieval.ts +30 -0
  87. package/extensions/pi-memory/src/service.ts +194 -0
  88. package/extensions/pi-memory/src/session.ts +146 -0
  89. package/extensions/pi-memory/src/types.ts +82 -0
  90. package/extensions/shared/README.md +18 -0
  91. package/extensions/shared/activity-status.ts +31 -0
  92. package/extensions/shared/child-session.ts +150 -0
  93. package/extensions/shared/context-utilization.ts +47 -0
  94. package/extensions/shared/dashboard-state.ts +99 -0
  95. package/extensions/shared/tool-call-timeout.ts +104 -0
  96. package/extensions/shared/tui-dashboard.ts +139 -0
  97. package/extensions/shell-shortcuts/README.md +17 -0
  98. package/extensions/shell-shortcuts/features/exit-alias.ts +10 -0
  99. package/extensions/shell-shortcuts/index.ts +6 -0
  100. package/extensions/subagents/README.md +89 -0
  101. package/extensions/subagents/index.ts +1386 -0
  102. package/extensions/subagents/src/backend.ts +69 -0
  103. package/extensions/subagents/src/backends/pi.ts +781 -0
  104. package/extensions/subagents/src/catalog.ts +85 -0
  105. package/extensions/subagents/src/config.ts +241 -0
  106. package/extensions/subagents/src/context.ts +57 -0
  107. package/extensions/subagents/src/coordinator.ts +64 -0
  108. package/extensions/subagents/src/domain.ts +294 -0
  109. package/extensions/subagents/src/format.ts +74 -0
  110. package/extensions/subagents/src/manager.ts +813 -0
  111. package/extensions/subagents/src/prompt.ts +94 -0
  112. package/extensions/subagents/src/result-delivery.ts +20 -0
  113. package/extensions/subagents/src/runtime.ts +48 -0
  114. package/extensions/subagents/src/ui/takeover.ts +695 -0
  115. package/extensions/subagents/src/ui/transcript.ts +182 -0
  116. package/extensions/subagents/src/worktree.ts +175 -0
  117. package/extensions/web-fetch/README.md +13 -0
  118. package/extensions/web-fetch/index.ts +441 -0
  119. package/package.json +117 -0
  120. package/skills/background-terminals/SKILL.md +42 -0
  121. package/skills/orchestration/SKILL.md +33 -0
  122. package/skills/subagents/SKILL.md +89 -0
  123. package/themes/ember-warm-dark.json +85 -0
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Domain model for subagents.
3
+ *
4
+ * Everything downstream of the Pi backend (manager, tools, UI) speaks only
5
+ * these types. The backend translates Pi session events into the normalized
6
+ * `SubagentEvent` union.
7
+ */
8
+
9
+ import type { Message } from "@earendil-works/pi-ai";
10
+ import type { ModelRegistry } from "@earendil-works/pi-coding-agent";
11
+ import { Data } from "effect";
12
+ import type { CapabilityMode, IsolationMode } from "./config.ts";
13
+ import type { WorktreeInfo } from "./worktree.ts";
14
+
15
+ export type BackendName = "pi";
16
+ export type SubagentOrigin = "model" | "btw" | "orchestration";
17
+
18
+ /** Pi thinking levels. Omitted means inherit the parent level. */
19
+ export const REASONING_EFFORTS = [
20
+ "off",
21
+ "minimal",
22
+ "low",
23
+ "medium",
24
+ "high",
25
+ "xhigh",
26
+ "max",
27
+ ] as const;
28
+ export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
29
+
30
+ export type SubagentStatus = "running" | "done" | "error";
31
+
32
+ /** Parent-session context resolved by the tool layer and passed opaquely. */
33
+ export interface PeerAgent {
34
+ readonly id: string;
35
+ readonly title: string;
36
+ readonly status: SubagentStatus;
37
+ }
38
+
39
+ export interface ParentBridge {
40
+ notify(message: string): void;
41
+ ask(question: string, signal?: AbortSignal): Promise<string>;
42
+ /** Flat peer coordination routed by the main-thread manager. */
43
+ listPeers(): ReadonlyArray<PeerAgent>;
44
+ messagePeer(id: string, message: string): Promise<void>;
45
+ }
46
+
47
+ export interface ParentContext {
48
+ readonly parentCwd: string;
49
+ readonly projectTrusted: boolean;
50
+ /** In-process bridge used by child-only message_parent/ask_parent tools. */
51
+ readonly bridge?: ParentBridge;
52
+ /** Parent pi model, for the pi backend's "inherit" default. */
53
+ readonly inheritedModel?: { readonly provider: string; readonly id: string };
54
+ readonly inheritedThinkingLevel?: string;
55
+ /** Parent model registry; required by the pi backend to resolve models. */
56
+ readonly modelRegistry?: ModelRegistry;
57
+ /** Sanitized parent conversation selected by fork_turns. */
58
+ readonly inheritedMessages?: ReadonlyArray<Message>;
59
+ readonly parentSessionFile?: string;
60
+ }
61
+
62
+ export interface SpawnTask {
63
+ readonly prompt: string;
64
+ readonly title: string;
65
+ /** Who started the run; user-owned asides never wake the parent model. */
66
+ readonly origin: SubagentOrigin;
67
+ readonly cwd: string;
68
+ /** Pi model hint: "provider/model-id" or a bare model id. Omitted = inherit. */
69
+ readonly model?: string;
70
+ /** Pi thinking level. */
71
+ readonly reasoningEffort?: ReasoningEffort;
72
+ /** Coarse tool capability policy, resolved from profile/persona/override. */
73
+ readonly capability: CapabilityMode;
74
+ readonly agentType: string;
75
+ readonly persona?: string;
76
+ readonly isolation: IsolationMode;
77
+ readonly maxConcurrent: number;
78
+ /** Independent concurrency pool. Ordinary subagents use `default`; orchestration uses one pool per project. */
79
+ readonly concurrencyGroup?: string;
80
+ readonly worktree?: WorktreeInfo;
81
+ /** Existing child session to continue with a new prompt. */
82
+ readonly resumeSessionFile?: string;
83
+ /** Preserve a logical id when restoring a child from the persistent catalog. */
84
+ readonly preferredId?: string;
85
+ readonly parent: ParentContext;
86
+ }
87
+
88
+ export interface SubagentMeta {
89
+ readonly backend: BackendName;
90
+ readonly origin: SubagentOrigin;
91
+ /** Display label, e.g. "openai-codex/gpt-5.6-sol". */
92
+ readonly modelLabel?: string;
93
+ /** Context window capacity for utilization display, when known. */
94
+ readonly contextWindow?: number;
95
+ /** Pi child session file. */
96
+ readonly sessionFilePath?: string;
97
+ /** Native Pi child-session id, when available. */
98
+ readonly nativeSessionId?: string;
99
+ readonly agentType?: string;
100
+ readonly persona?: string;
101
+ readonly capability?: CapabilityMode;
102
+ readonly isolation?: IsolationMode;
103
+ readonly worktree?: WorktreeInfo;
104
+ readonly concurrencyGroup?: string;
105
+ readonly resumedFrom?: string;
106
+ }
107
+
108
+ // --- Transcript ------------------------------------------------------------
109
+
110
+ export type TranscriptPart =
111
+ | { readonly type: "text"; readonly text: string }
112
+ | {
113
+ readonly type: "thinking";
114
+ readonly text: string;
115
+ readonly redacted?: boolean;
116
+ }
117
+ | {
118
+ readonly type: "toolCall";
119
+ readonly toolId: string;
120
+ readonly name: string;
121
+ readonly argsPreview?: string;
122
+ };
123
+
124
+ export type TranscriptItem =
125
+ | { readonly kind: "user"; readonly text: string }
126
+ | {
127
+ readonly kind: "assistant";
128
+ readonly parts: ReadonlyArray<TranscriptPart>;
129
+ }
130
+ | {
131
+ readonly kind: "toolResult";
132
+ readonly toolId: string;
133
+ readonly name: string;
134
+ readonly isError: boolean;
135
+ readonly outputPreview?: string;
136
+ };
137
+
138
+ export interface LiveToolState {
139
+ readonly toolId: string;
140
+ readonly name: string;
141
+ readonly argsPreview?: string;
142
+ readonly outputPreview?: string;
143
+ readonly done?: boolean;
144
+ readonly isError?: boolean;
145
+ }
146
+
147
+ export interface QueuedMessage {
148
+ readonly text: string;
149
+ readonly kind: "steer" | "follow-up";
150
+ }
151
+
152
+ // --- Events ------------------------------------------------------------------
153
+
154
+ export type RunOutcome =
155
+ | { readonly _tag: "Completed"; readonly finalText: string }
156
+ | {
157
+ readonly _tag: "Failed";
158
+ readonly errorText: string;
159
+ readonly partialText?: string;
160
+ }
161
+ | { readonly _tag: "Interrupted"; readonly partialText?: string };
162
+
163
+ /**
164
+ * Normalized activity stream. Previews (`argsPreview`, `outputPreview`) are
165
+ * pre-flattened single-line strings because the UI only ever renders one
166
+ * sanitized line, which keeps three different native tool-result shapes out
167
+ * of the interface.
168
+ */
169
+ export type SubagentEvent =
170
+ // lifecycle (a session can run multiple turns via send())
171
+ | { readonly _tag: "RunStarted" }
172
+ | { readonly _tag: "RunSettled"; readonly outcome: RunOutcome }
173
+ // transcript building blocks
174
+ | { readonly _tag: "UserMessage"; readonly text: string }
175
+ | {
176
+ readonly _tag: "AssistantDelta";
177
+ readonly kind: "text" | "thinking";
178
+ readonly delta: string;
179
+ }
180
+ | {
181
+ readonly _tag: "AssistantMessage";
182
+ readonly parts: ReadonlyArray<TranscriptPart>;
183
+ }
184
+ | {
185
+ readonly _tag: "ToolStart";
186
+ readonly toolId: string;
187
+ readonly name: string;
188
+ readonly argsPreview?: string;
189
+ }
190
+ | {
191
+ readonly _tag: "ToolUpdate";
192
+ readonly toolId: string;
193
+ readonly outputPreview?: string;
194
+ }
195
+ | {
196
+ readonly _tag: "ToolEnd";
197
+ readonly toolId: string;
198
+ readonly name: string;
199
+ readonly isError: boolean;
200
+ readonly outputPreview?: string;
201
+ }
202
+ // bookkeeping
203
+ | {
204
+ readonly _tag: "QueueChanged";
205
+ readonly queued: ReadonlyArray<QueuedMessage>;
206
+ }
207
+ | {
208
+ readonly _tag: "UsageChanged";
209
+ readonly tokens?: number;
210
+ readonly contextWindow?: number;
211
+ }
212
+ | { readonly _tag: "MetaChanged"; readonly meta: Partial<SubagentMeta> }
213
+ /** Non-fatal diagnostics. Fatal failures arrive as a RunSettled outcome. */
214
+ | { readonly _tag: "BackendError"; readonly message: string };
215
+
216
+ // --- Snapshot ---------------------------------------------------------------
217
+
218
+ /**
219
+ * The manager folds `SubagentEvent`s into one snapshot per subagent. This is
220
+ * everything the tools, footer status, and both TUI views read.
221
+ */
222
+ export interface PeerMessage {
223
+ readonly id: string;
224
+ readonly sentAt: number;
225
+ readonly sender: string;
226
+ readonly senderId?: string;
227
+ readonly targetId: string;
228
+ readonly targetTitle: string;
229
+ readonly message: string;
230
+ readonly status: "delivered" | "failed";
231
+ readonly error?: string;
232
+ }
233
+
234
+ export interface SubagentSnapshot {
235
+ readonly id: string;
236
+ readonly backend: BackendName;
237
+ readonly title: string;
238
+ readonly prompt: string;
239
+ readonly cwd: string;
240
+ readonly status: SubagentStatus;
241
+ readonly createdAt: number;
242
+ readonly settledAt?: number;
243
+ readonly errorText?: string;
244
+ readonly meta: SubagentMeta;
245
+ readonly usage: { readonly tokens?: number; readonly contextWindow?: number };
246
+ readonly transcript: ReadonlyArray<TranscriptItem>;
247
+ /** Streaming assistant buffers, cleared when the finalized message lands. */
248
+ readonly liveAssistant?: { readonly text: string; readonly thinking: string };
249
+ readonly liveTools: ReadonlyArray<LiveToolState>;
250
+ readonly queued: ReadonlyArray<QueuedMessage>;
251
+ /** Final text of the most recent completed run (v1 `finalOutput`). */
252
+ readonly finalText: string;
253
+ /** Count of finalized assistant messages (for check_agent). */
254
+ readonly turns: number;
255
+ }
256
+
257
+ /** Final text, or the live streaming buffer while a run is active (v1 `latestOutput`). */
258
+ export function latestText(snap: SubagentSnapshot) {
259
+ const live = snap.liveAssistant?.text.trim();
260
+ if (live) return live;
261
+ return snap.finalText;
262
+ }
263
+
264
+ export function formatElapsed(snap: SubagentSnapshot) {
265
+ const end = snap.settledAt ?? Date.now();
266
+ const totalSeconds = Math.max(0, Math.round((end - snap.createdAt) / 1000));
267
+ const minutes = Math.floor(totalSeconds / 60);
268
+ const seconds = totalSeconds % 60;
269
+ return minutes > 0
270
+ ? `${minutes}m${seconds.toString().padStart(2, "0")}s`
271
+ : `${seconds}s`;
272
+ }
273
+
274
+ // --- Errors -------------------------------------------------------------------
275
+
276
+ export class SpawnError extends Data.TaggedError("SpawnError")<{
277
+ readonly message: string;
278
+ }> {}
279
+
280
+ export class BackendUnavailableError extends Data.TaggedError(
281
+ "BackendUnavailableError",
282
+ )<{
283
+ readonly message: string;
284
+ }> {}
285
+
286
+ export class ConcurrencyLimitError extends Data.TaggedError(
287
+ "ConcurrencyLimitError",
288
+ )<{
289
+ readonly message: string;
290
+ }> {}
291
+
292
+ export class SendError extends Data.TaggedError("SendError")<{
293
+ readonly message: string;
294
+ }> {}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Formatting helpers (self-contained copies of the v1 shared helpers:
3
+ * context-utilization + activity-status).
4
+ */
5
+
6
+ import type { Theme } from "@earendil-works/pi-coding-agent";
7
+
8
+ export interface ContextUtilization {
9
+ /** Current conversation context occupancy; undefined while unknown. */
10
+ tokens?: number | null;
11
+ /** Capacity of the model currently serving the conversation. */
12
+ contextWindow?: number | null;
13
+ }
14
+
15
+ function usableTokens(value: number | null | undefined) {
16
+ return typeof value === "number" && Number.isFinite(value) && value >= 0
17
+ ? value
18
+ : undefined;
19
+ }
20
+
21
+ function usableCapacity(value: number | null | undefined) {
22
+ return typeof value === "number" && Number.isFinite(value) && value > 0
23
+ ? value
24
+ : undefined;
25
+ }
26
+
27
+ export function contextPercent(usage: ContextUtilization) {
28
+ const tokens = usableTokens(usage.tokens);
29
+ const capacity = usableCapacity(usage.contextWindow);
30
+ if (tokens === undefined || capacity === undefined) return undefined;
31
+ return Math.round(Math.min(100, Math.max(0, (tokens / capacity) * 100)));
32
+ }
33
+
34
+ export function formatCompactTokens(count: number) {
35
+ if (count < 1000) return Math.round(count).toString();
36
+ if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
37
+ if (count < 1000000) return `${Math.round(count / 1000)}k`;
38
+ return `${(count / 1000000).toFixed(1)}M`;
39
+ }
40
+
41
+ /**
42
+ * Render `%/capacity`. If occupancy is unknown, retain the useful capacity
43
+ * as `?%/capacity`; with no valid capacity, omit the statistic entirely.
44
+ */
45
+ export function formatContextUtilization(usage: ContextUtilization) {
46
+ const capacity = usableCapacity(usage.contextWindow);
47
+ if (capacity === undefined) return "";
48
+ const percent = contextPercent(usage);
49
+ return `${percent === undefined ? "?" : percent}%/${formatCompactTokens(capacity)}`;
50
+ }
51
+
52
+ interface ActivityCounts {
53
+ running: number;
54
+ done: number;
55
+ failed: number;
56
+ }
57
+
58
+ const SQUARE = "■";
59
+
60
+ export function formatActivityStatus(theme: Theme, counts: ActivityCounts) {
61
+ const parts: string[] = [];
62
+ if (counts.running > 0) {
63
+ parts.push(theme.fg("warning", `${SQUARE} ${counts.running} running`));
64
+ }
65
+ if (counts.done > 0) {
66
+ parts.push(theme.fg("success", `${SQUARE} ${counts.done} done`));
67
+ }
68
+ if (counts.failed > 0) {
69
+ parts.push(theme.fg("error", `${SQUARE} ${counts.failed} failed`));
70
+ }
71
+ parts.push(theme.fg("accent", "/subagents") + theme.fg("dim", " to view"));
72
+
73
+ return `${theme.fg("muted", "subagents:")} ${parts.join(theme.fg("dim", " · "))}`;
74
+ }