pi-btw 0.3.7 → 0.4.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-btw
2
2
 
3
- A small [pi](https://github.com/badlogic/pi-mono) extension that adds a `/btw` side conversation channel.
3
+ A small [pi](https://github.com/earendil-works/pi-mono) extension that adds a `/btw` side conversation channel.
4
4
 
5
5
  `/btw` opens a real pi sub-session with coding-tool access, and it runs immediately even while the main agent is still busy.
6
6
 
package/extensions/btw.ts CHANGED
@@ -2,7 +2,6 @@ import {
2
2
  buildSessionContext,
3
3
  createAgentSession,
4
4
  createExtensionRuntime,
5
- codingTools,
6
5
  SessionManager,
7
6
  type AgentSession,
8
7
  type AgentSessionEvent,
@@ -10,8 +9,8 @@ import {
10
9
  type ExtensionCommandContext,
11
10
  type ExtensionContext,
12
11
  type ResourceLoader,
13
- } from "@mariozechner/pi-coding-agent";
14
- import { type AssistantMessage, type Message, type ThinkingLevel as AiThinkingLevel, type UserMessage } from "@mariozechner/pi-ai";
12
+ } from "@earendil-works/pi-coding-agent";
13
+ import { type AssistantMessage, type Message, type ThinkingLevel as AiThinkingLevel, type UserMessage } from "@earendil-works/pi-ai";
15
14
  import {
16
15
  Box,
17
16
  Container,
@@ -26,7 +25,7 @@ import {
26
25
  type KeybindingsManager,
27
26
  type OverlayHandle,
28
27
  type TUI,
29
- } from "@mariozechner/pi-tui";
28
+ } from "@earendil-works/pi-tui";
30
29
 
31
30
  const BTW_MESSAGE_TYPE = "btw-note";
32
31
  const BTW_ENTRY_TYPE = "btw-thread-entry";
@@ -56,6 +55,11 @@ const BTW_CONTINUE_THREAD_ASSISTANT_TEXT = "Understood, continuing our side conv
56
55
  type SessionThinkingLevel = "off" | AiThinkingLevel;
57
56
  type BtwThreadMode = "contextual" | "tangent";
58
57
  type SessionModel = NonNullable<ExtensionCommandContext["model"]>;
58
+ /**
59
+ * Loose model reference parsed from `/btw:model <provider> <id> <api>` and persisted to
60
+ * session entries. Resolved to a full SessionModel via ctx.modelRegistry.find(...).
61
+ */
62
+ type BtwModelRef = Pick<SessionModel, "provider" | "id" | "api">;
59
63
 
60
64
  type BtwDetails = {
61
65
  question: string;
@@ -216,7 +220,7 @@ function parseBtwArgs(args: string): ParsedBtwArgs {
216
220
  function parseBtwModelArgs(args: string):
217
221
  | { action: "show" }
218
222
  | { action: "clear" }
219
- | { action: "set"; model: SessionModel }
223
+ | { action: "set"; model: BtwModelRef }
220
224
  | { action: "invalid"; message: string } {
221
225
  const trimmed = args.trim();
222
226
  if (!trimmed) {
@@ -233,7 +237,7 @@ function parseBtwModelArgs(args: string):
233
237
  }
234
238
 
235
239
  const [provider, id, api] = parts;
236
- return { action: "set", model: { provider, id, api } };
240
+ return { action: "set", model: { provider, id, api } as BtwModelRef };
237
241
  }
238
242
 
239
243
  function parseBtwThinkingArgs(args: string):
@@ -1083,6 +1087,17 @@ class BtwOverlayComponent extends Container implements Focusable {
1083
1087
 
1084
1088
  const originalHandleInput = this.input.handleInput.bind(this.input);
1085
1089
  this.input.handleInput = (data: string) => {
1090
+ if (keybindings.matches(data, "app.clear")) {
1091
+ if (this.input.getValue().length > 0) {
1092
+ this.input.setValue("");
1093
+ this.tui.requestRender();
1094
+ return;
1095
+ }
1096
+
1097
+ this.onDismissCallback();
1098
+ return;
1099
+ }
1100
+
1086
1101
  if (keybindings.matches(data, "tui.select.cancel")) {
1087
1102
  this.onDismissCallback();
1088
1103
  return;
@@ -1544,7 +1559,8 @@ export default function (pi: ExtensionAPI) {
1544
1559
  model: settings.model,
1545
1560
  modelRegistry: ctx.modelRegistry as AgentSession["modelRegistry"],
1546
1561
  thinkingLevel: settings.thinkingLevel,
1547
- tools: codingTools,
1562
+ // Match pi's default coding-agent toolset (read/bash/edit/write).
1563
+ tools: ["read", "bash", "edit", "write"],
1548
1564
  resourceLoader: createBtwResourceLoader(ctx),
1549
1565
  });
1550
1566
 
@@ -1749,7 +1765,19 @@ export default function (pi: ExtensionAPI) {
1749
1765
  return true;
1750
1766
  }
1751
1767
 
1752
- await setBtwModelOverride(ctx, parsed.action === "clear" ? null : parsed.model);
1768
+ if (parsed.action === "clear") {
1769
+ await setBtwModelOverride(ctx, null);
1770
+ return true;
1771
+ }
1772
+ const ref = parsed.model;
1773
+ const resolved = ctx.modelRegistry.find(ref.provider, ref.id);
1774
+ if (!resolved) {
1775
+ const message = `Unknown model ${ref.provider}/${ref.id}. Use /login or /models to add it before setting it as the BTW override.`;
1776
+ setOverlayStatus(message, ctx);
1777
+ notify(ctx, message, "error");
1778
+ return true;
1779
+ }
1780
+ await setBtwModelOverride(ctx, resolved);
1753
1781
  return true;
1754
1782
  }
1755
1783
 
@@ -1900,17 +1928,22 @@ export default function (pi: ExtensionAPI) {
1900
1928
 
1901
1929
  for (let i = 0; i < branch.length; i++) {
1902
1930
  if (isCustomEntry(branch[i], BTW_MODEL_OVERRIDE_TYPE)) {
1903
- const details = branch[i].data as BtwModelOverrideDetails | undefined;
1904
- btwModelOverride =
1905
- details?.action === "set"
1906
- ? { provider: details.provider, id: details.id, api: details.api }
1907
- : details?.action === "clear"
1908
- ? null
1909
- : btwModelOverride;
1931
+ const details = (branch[i] as unknown as { data?: BtwModelOverrideDetails }).data;
1932
+ if (details?.action === "set") {
1933
+ const resolved = ctx.modelRegistry.find(details.provider, details.id);
1934
+ if (resolved) {
1935
+ btwModelOverride = resolved;
1936
+ } else {
1937
+ // Configured override is no longer in the registry; drop it on restore.
1938
+ btwModelOverride = null;
1939
+ }
1940
+ } else if (details?.action === "clear") {
1941
+ btwModelOverride = null;
1942
+ }
1910
1943
  }
1911
1944
 
1912
1945
  if (isCustomEntry(branch[i], BTW_THINKING_OVERRIDE_TYPE)) {
1913
- const details = branch[i].data as BtwThinkingOverrideDetails | undefined;
1946
+ const details = (branch[i] as unknown as { data?: BtwThinkingOverrideDetails }).data;
1914
1947
  btwThinkingOverride =
1915
1948
  details?.action === "set"
1916
1949
  ? details.thinkingLevel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-btw",
3
- "version": "0.3.7",
3
+ "version": "0.4.0",
4
4
  "description": "A pi extension for parallel side conversations with /btw",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,9 +42,9 @@
42
42
  "image": "https://raw.githubusercontent.com/dbachelder/pi-btw/main/docs/btw-overlay.png"
43
43
  },
44
44
  "peerDependencies": {
45
- "@mariozechner/pi-ai": "^0.66.1",
46
- "@mariozechner/pi-coding-agent": "^0.66.1",
47
- "@mariozechner/pi-tui": "^0.66.1"
45
+ "@earendil-works/pi-ai": "^0.74.0",
46
+ "@earendil-works/pi-coding-agent": "^0.74.0",
47
+ "@earendil-works/pi-tui": "^0.74.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "^6.0.2",