@turri-dev/cli 0.4.2-next.a6867e8 → 0.4.3-next.620bae9
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/dist/chat-commands.d.ts +2 -10
- package/dist/chat-commands.js +3 -57
- package/dist/chat-tab-header.d.ts +15 -0
- package/dist/chat-tab-header.js +78 -0
- package/dist/chat-tabs.d.ts +20 -0
- package/dist/chat-tabs.js +96 -0
- package/dist/chat-terminal.js +54 -8
- package/dist/chat-waiting.d.ts +4 -1
- package/dist/chat-waiting.js +7 -4
- package/dist/chats.d.ts +3 -1
- package/dist/chats.js +1 -1
- package/dist/extension.js +81 -88
- package/dist/identity.js +1 -1
- package/dist/loop-tools.d.ts +2 -3
- package/dist/loop-tools.js +7 -12
- package/dist/pointer-hover.d.ts +12 -0
- package/dist/pointer-hover.js +44 -0
- package/dist/regenerate/chunk-plan.d.ts +2 -11
- package/dist/regenerate/chunk-plan.js +9 -20
- package/dist/regenerate/command-check.d.ts +9 -0
- package/dist/regenerate/command-check.js +83 -3
- package/dist/regenerate/jobs-tree.d.ts +1 -0
- package/dist/regenerate/jobs-tree.js +5 -1
- package/dist/regenerate/loop.d.ts +6 -14
- package/dist/regenerate/loop.js +42 -34
- package/dist/regenerate/side-panel.d.ts +4 -1
- package/dist/regenerate/side-panel.js +131 -22
- package/dist/regenerate/spec-map-view.d.ts +9 -1
- package/dist/regenerate/spec-map-view.js +22 -2
- package/dist/regenerate/test-scripts.d.ts +3 -0
- package/dist/regenerate/test-scripts.js +16 -5
- package/dist/resume-line.d.ts +4 -1
- package/dist/resume-line.js +5 -2
- package/dist/sentinel.js +1 -1
- package/docs/chats.md +6 -6
- package/docs/config.md +2 -0
- package/docs/regenerating.md +8 -7
- package/docs/sandbox.md +2 -0
- package/docs/skills-and-gates.md +1 -1
- package/docs/theming.md +1 -1
- package/docs/using.md +6 -3
- package/genome/rules/turri-regeneration.md +1 -1
- package/package.json +3 -3
- package/dist/regenerate/steer.d.ts +0 -34
- package/dist/regenerate/steer.js +0 -91
package/dist/chat-commands.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type
|
|
2
|
+
import { type TurriCore } from "./chats.ts";
|
|
3
3
|
/**
|
|
4
|
-
* The terminal's
|
|
5
|
-
* editor naming each chat with what it is doing.
|
|
4
|
+
* The keyboard counterparts to the terminal's chat tabs: `/chat` - new, close, a number, or a pick - and its keys.
|
|
6
5
|
*/
|
|
7
6
|
/** A fresh chat. */
|
|
8
7
|
export declare const NEW_CHAT_KEY = "alt+n";
|
|
@@ -15,11 +14,4 @@ export declare const CLOSE_CHAT_KEY = "alt+w";
|
|
|
15
14
|
export declare const OPTION_AS_META: string;
|
|
16
15
|
/** Said once a session, as its second chat opens, on a Mac. */
|
|
17
16
|
export declare function tellOfOptionOnce(session: TurriCore, platform?: NodeJS.Platform): void;
|
|
18
|
-
/** What a chat's mark in the strip and the picker says it is doing. */
|
|
19
|
-
export declare function chatMark(chat: ChatInfo, now?: number): string;
|
|
20
|
-
/** The strip: each chat by its number, its title and its mark - the one shown set apart - on one line, a rule between them. */
|
|
21
|
-
export declare function chatStrip(chats: ChatInfo[], width: number, style: {
|
|
22
|
-
shown: (text: string) => string;
|
|
23
|
-
muted: (text: string) => string;
|
|
24
|
-
}, now?: number): string[];
|
|
25
17
|
export declare function registerChats(pi: ExtensionAPI, session: TurriCore): void;
|
package/dist/chat-commands.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
1
|
import { MAX_CHATS } from "./chats.js";
|
|
3
|
-
import {
|
|
2
|
+
import { chatMark, closeTerminalChat } from "./chat-tabs.js";
|
|
4
3
|
/**
|
|
5
|
-
* The terminal's
|
|
6
|
-
* editor naming each chat with what it is doing.
|
|
4
|
+
* The keyboard counterparts to the terminal's chat tabs: `/chat` - new, close, a number, or a pick - and its keys.
|
|
7
5
|
*/
|
|
8
6
|
/** A fresh chat. */
|
|
9
7
|
export const NEW_CHAT_KEY = "alt+n";
|
|
@@ -11,7 +9,6 @@ export const NEW_CHAT_KEY = "alt+n";
|
|
|
11
9
|
export const CLOSE_CHAT_KEY = "alt+w";
|
|
12
10
|
/** alt+1 … alt+9: that chat, shown. */
|
|
13
11
|
const SHOW_KEYS = Array.from({ length: MAX_CHATS }, (_, index) => `alt+${index + 1}`);
|
|
14
|
-
const STRIP_WIDGET = "turri-chats";
|
|
15
12
|
/**
|
|
16
13
|
* On a Mac, alt is Option, which types ¡ and ñ unless the terminal sends it as Meta: said once a session, as the second
|
|
17
14
|
* chat opens - when the keys are first worth having.
|
|
@@ -34,33 +31,6 @@ export function tellOfOptionOnce(session, platform = process.platform) {
|
|
|
34
31
|
setTimeout(() => session.notify(OPTION_AS_META, "info"), 0);
|
|
35
32
|
});
|
|
36
33
|
}
|
|
37
|
-
/** What a chat's mark in the strip and the picker says it is doing. */
|
|
38
|
-
export function chatMark(chat, now = Date.now()) {
|
|
39
|
-
switch (chat.status) {
|
|
40
|
-
case "working":
|
|
41
|
-
return spinner(now);
|
|
42
|
-
case "question":
|
|
43
|
-
return "?";
|
|
44
|
-
case "unread":
|
|
45
|
-
return "•";
|
|
46
|
-
default:
|
|
47
|
-
return " ";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/** Between two chats in the strip. */
|
|
51
|
-
const STRIP_DELIMITER = " │ ";
|
|
52
|
-
/** The strip: each chat by its number, its title and its mark - the one shown set apart - on one line, a rule between them. */
|
|
53
|
-
export function chatStrip(chats, width, style, now = Date.now()) {
|
|
54
|
-
if (chats.length < 2)
|
|
55
|
-
return [];
|
|
56
|
-
const room = Math.max(8, Math.floor((width - 2) / chats.length) - STRIP_DELIMITER.length - 4);
|
|
57
|
-
const parts = chats.map((chat, index) => {
|
|
58
|
-
const mark = chatMark(chat, now).trim();
|
|
59
|
-
const label = `${index + 1} ${truncateToWidth(chat.title, room, "…")}${mark !== "" ? ` ${mark}` : ""}`;
|
|
60
|
-
return chat.shown ? style.shown(label) : style.muted(label);
|
|
61
|
-
});
|
|
62
|
-
return [truncateToWidth(` ${parts.join(style.muted(STRIP_DELIMITER))}`, width, "…")];
|
|
63
|
-
}
|
|
64
34
|
const label = (chat, index) => `${index + 1} ${chatMark(chat)} ${chat.title}${chat.shown ? " (shown)" : ""}`;
|
|
65
35
|
/** What the person asked of the chats, done once pi has finished with the command or key that asked it. */
|
|
66
36
|
function later(ctx, session, work) {
|
|
@@ -88,10 +58,7 @@ function closeChat(ctx, session, which) {
|
|
|
88
58
|
const chat = chatNamed(session, which);
|
|
89
59
|
if (typeof chat === "string")
|
|
90
60
|
return ctx.ui.notify(chat, "warning");
|
|
91
|
-
|
|
92
|
-
if (chat.role === undefined && session.chats().filter((other) => other.role === undefined).length === 1)
|
|
93
|
-
return ctx.ui.notify("This is the only chat - /quit leaves turri.", "info");
|
|
94
|
-
later(ctx, session, () => session.close(chat.id));
|
|
61
|
+
later(ctx, session, () => closeTerminalChat(session, chat.id));
|
|
95
62
|
}
|
|
96
63
|
function showChat(ctx, session, which) {
|
|
97
64
|
const chat = chatNamed(session, which);
|
|
@@ -139,25 +106,4 @@ export function registerChats(pi, session) {
|
|
|
139
106
|
description: `Show chat ${index + 1}`,
|
|
140
107
|
handler: async (ctx) => showChat(ctx, session, `${index + 1}`),
|
|
141
108
|
}));
|
|
142
|
-
// The strip above the editor, while there are two chats or more: drawn again as they change, and while one works.
|
|
143
|
-
pi.on("session_start", (_event, ctx) => {
|
|
144
|
-
if (!ctx.hasUI)
|
|
145
|
-
return;
|
|
146
|
-
ctx.ui.setWidget(STRIP_WIDGET, (tui, theme) => {
|
|
147
|
-
const stop = session.onChats(() => tui.requestRender());
|
|
148
|
-
const ticker = setInterval(() => {
|
|
149
|
-
if (session.chats().some((chat) => chat.status === "working"))
|
|
150
|
-
tui.requestRender();
|
|
151
|
-
}, 250);
|
|
152
|
-
ticker.unref?.();
|
|
153
|
-
return {
|
|
154
|
-
render: (width) => chatStrip(session.chats(), width, { shown: (text) => theme.bold(theme.fg("accent", text)), muted: (text) => theme.fg("muted", text) }),
|
|
155
|
-
invalidate: () => { },
|
|
156
|
-
dispose: () => {
|
|
157
|
-
stop();
|
|
158
|
-
clearInterval(ticker);
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
109
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Component, type Container, type ScrollView, type TUI } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { ChatTabs } from "./chat-tabs.ts";
|
|
3
|
+
export interface ChatScreen {
|
|
4
|
+
fullscreenLayoutRoot: Component;
|
|
5
|
+
documentContainer: Container;
|
|
6
|
+
chatContainer: Container;
|
|
7
|
+
transcriptScrollView: ScrollView;
|
|
8
|
+
}
|
|
9
|
+
/** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
|
|
10
|
+
* off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
|
|
11
|
+
export declare function chatTabHeader(tabs: ChatTabs): {
|
|
12
|
+
mount(screen: ChatScreen, components: Component[]): Component[];
|
|
13
|
+
afterBanner(chat: Container, entry: unknown): void;
|
|
14
|
+
watch(screen: ChatScreen, tui: TUI): () => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { VStack } from "@earendil-works/pi-tui";
|
|
2
|
+
import { terminalPointer } from "./pointer-hover.js";
|
|
3
|
+
/** Where pi drew a child. Use the row counts its Container already measured for mouse dispatch: the width of the
|
|
4
|
+
* chat, the banner's image and any wrapped warnings all affect where the divider lands. */
|
|
5
|
+
function rowOf(parent, child) {
|
|
6
|
+
const measured = parent.childLines;
|
|
7
|
+
if (measured === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
let row = 0;
|
|
10
|
+
for (const [index, component] of measured.children.entries()) {
|
|
11
|
+
if (component === child)
|
|
12
|
+
return row;
|
|
13
|
+
row += measured.parts[index].length;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
|
|
18
|
+
* off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
|
|
19
|
+
export function chatTabHeader(tabs) {
|
|
20
|
+
let pinned = true;
|
|
21
|
+
const sticky = {
|
|
22
|
+
render: (width) => pinned ? tabs.render(width) : [],
|
|
23
|
+
handleMouse: (event) => pinned ? tabs.handleMouse?.(event) : undefined,
|
|
24
|
+
invalidate() { },
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
mount(screen, components) {
|
|
28
|
+
if (components.includes(sticky))
|
|
29
|
+
return components;
|
|
30
|
+
screen.fullscreenLayoutRoot = new VStack([sticky, { component: screen.fullscreenLayoutRoot, basis: 0, grow: 1, minSize: 1 }]);
|
|
31
|
+
return [sticky, ...components];
|
|
32
|
+
},
|
|
33
|
+
afterBanner(chat, entry) {
|
|
34
|
+
if (chat.children.includes(tabs))
|
|
35
|
+
return;
|
|
36
|
+
const at = chat.children.findIndex((child) => child.entry === entry);
|
|
37
|
+
if (at !== -1)
|
|
38
|
+
chat.children.splice(at + 1, 0, tabs);
|
|
39
|
+
},
|
|
40
|
+
watch(screen, tui) {
|
|
41
|
+
if (tui.mode !== "fullscreen") {
|
|
42
|
+
// Regular mode has native scrollback: the row below the banner scrolls with it.
|
|
43
|
+
pinned = false;
|
|
44
|
+
return () => { };
|
|
45
|
+
}
|
|
46
|
+
const view = screen.transcriptScrollView;
|
|
47
|
+
tabs.pointer = terminalPointer(tui.terminal);
|
|
48
|
+
const update = view.updateLayout;
|
|
49
|
+
view.updateLayout = function (height, viewport, redraw) {
|
|
50
|
+
update.call(this, height, viewport, redraw);
|
|
51
|
+
const chat = rowOf(screen.documentContainer, screen.chatContainer);
|
|
52
|
+
const tab = rowOf(screen.chatContainer, tabs);
|
|
53
|
+
const row = chat === undefined || tab === undefined ? -1 : chat + tab;
|
|
54
|
+
const next = row < this.scrollTop || row >= this.scrollTop + viewport;
|
|
55
|
+
if (next !== pinned) {
|
|
56
|
+
pinned = next;
|
|
57
|
+
redraw();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// pi normally asks multiplexers for button motion only. The tabs need motion without a button too. pi disables
|
|
61
|
+
// all mouse modes itself when it leaves fullscreen, including when the terminal is suspended.
|
|
62
|
+
const mouse = tui;
|
|
63
|
+
const start = mouse.beforeTerminalStart;
|
|
64
|
+
mouse.beforeTerminalStart = function () {
|
|
65
|
+
start.call(this);
|
|
66
|
+
if (this.mouseEnabled)
|
|
67
|
+
tui.terminal.write("\x1b[?1003h");
|
|
68
|
+
};
|
|
69
|
+
const input = mouse.handleViewportInput;
|
|
70
|
+
mouse.handleViewportInput = (data) => tabs.pointer.dispatch(() => input.call(mouse, data), () => tui.requestRender());
|
|
71
|
+
return () => {
|
|
72
|
+
view.updateLayout = update;
|
|
73
|
+
mouse.beforeTerminalStart = start;
|
|
74
|
+
mouse.handleViewportInput = input;
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Component } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { ChatInfo, TurriCore } from "./chats.ts";
|
|
3
|
+
import { PointerHover, type ButtonPaint } from "./pointer-hover.ts";
|
|
4
|
+
/** Shared by the tabs and the /chat picker. */
|
|
5
|
+
export declare function chatMark(chat: ChatInfo): string;
|
|
6
|
+
export type TabAction = {
|
|
7
|
+
kind: "open";
|
|
8
|
+
} | {
|
|
9
|
+
kind: "plain";
|
|
10
|
+
} | {
|
|
11
|
+
kind: "show" | "close";
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
/** Shared by ×, /chat close and alt+w. The last person's chat stays open even if the sentinel has its own tab. */
|
|
15
|
+
export declare function closeTerminalChat(session: TurriCore, id: string): Promise<void>;
|
|
16
|
+
export interface ChatTabs extends Component {
|
|
17
|
+
pointer: PointerHover;
|
|
18
|
+
}
|
|
19
|
+
/** Mouse positions, like the layout, are in terminal cells, not string offsets. */
|
|
20
|
+
export declare function chatTabs(chats: () => ChatInfo[], style: ButtonPaint, pick: (action: TabAction) => void): ChatTabs;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { stripTerminalSequences, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { PointerHover } from "./pointer-hover.js";
|
|
3
|
+
import { spinner } from "./regenerate/job-panel.js";
|
|
4
|
+
/** Shared by the tabs and the /chat picker. */
|
|
5
|
+
export function chatMark(chat) {
|
|
6
|
+
switch (chat.status) {
|
|
7
|
+
case "working": return spinner(Date.now());
|
|
8
|
+
case "question": return "?";
|
|
9
|
+
case "unread": return "•";
|
|
10
|
+
default: return " ";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const buttonRole = { open: "new", plain: "panel", show: "tab", close: "close" };
|
|
14
|
+
function buttonKey(action) {
|
|
15
|
+
return "id" in action ? `${action.kind}:${action.id}` : action.kind;
|
|
16
|
+
}
|
|
17
|
+
/** Shared by ×, /chat close and alt+w. The last person's chat stays open even if the sentinel has its own tab. */
|
|
18
|
+
export async function closeTerminalChat(session, id) {
|
|
19
|
+
const chats = session.chats();
|
|
20
|
+
const people = chats.filter((chat) => chat.role === undefined);
|
|
21
|
+
if (people.length === 1 && people[0].id === id)
|
|
22
|
+
return session.notify("This is the only chat - /quit leaves turri.", "info");
|
|
23
|
+
await session.close(id);
|
|
24
|
+
}
|
|
25
|
+
function layout(chats, width) {
|
|
26
|
+
if (width <= 0)
|
|
27
|
+
return [];
|
|
28
|
+
// Keep the panel button at the right edge while chat titles grow and shrink on the left.
|
|
29
|
+
const panel = width >= 30 ? " ***plain › " : width >= 14 ? " ***plain " : width >= 6 ? "≡" : "";
|
|
30
|
+
const panelWidth = visibleWidth(panel);
|
|
31
|
+
const chatWidth = width - (panel ? panelWidth + 1 : 0);
|
|
32
|
+
// Reserve + and a close target per tab before spending cells on padding, gaps and titles.
|
|
33
|
+
const spaced = chatWidth >= chats.length * 5 + 3;
|
|
34
|
+
const plus = spaced ? " + " : "+";
|
|
35
|
+
const count = Math.min(chats.length, Math.floor((chatWidth - plus.length) / 2));
|
|
36
|
+
const room = Math.floor((chatWidth - plus.length) / Math.max(1, count)) - (spaced ? 1 : 0);
|
|
37
|
+
const parts = [];
|
|
38
|
+
for (const [index, chat] of chats.slice(0, count).entries()) {
|
|
39
|
+
const lead = !spaced ? "" : room >= 8 ? (chat.shown ? " ▸ " : " ") : (chat.shown ? "▸" : " ");
|
|
40
|
+
let label = `${lead}${index + 1}`;
|
|
41
|
+
const close = spaced ? (room > 4 ? " × " : "× ") : "×";
|
|
42
|
+
const mark = chatMark(chat).trim();
|
|
43
|
+
const suffix = mark ? ` ${mark}` : "";
|
|
44
|
+
const titleRoom = room - visibleWidth(label + close + suffix) - 1;
|
|
45
|
+
if (titleRoom > 0)
|
|
46
|
+
label += ` ${truncateToWidth(stripTerminalSequences(chat.title).replace(/\s+/g, " ").trim(), titleRoom, "…")}${suffix}`;
|
|
47
|
+
parts.push({ text: label, action: { kind: "show", id: chat.id }, shown: chat.shown }, { text: close, action: { kind: "close", id: chat.id }, shown: chat.shown });
|
|
48
|
+
if (spaced)
|
|
49
|
+
parts.push({ text: " " });
|
|
50
|
+
}
|
|
51
|
+
parts.push({ text: plus, action: { kind: "open" } });
|
|
52
|
+
if (panel) {
|
|
53
|
+
const used = parts.reduce((cells, part) => cells + visibleWidth(part.text), 0);
|
|
54
|
+
parts.push({ text: " ".repeat(width - used - panelWidth) }, { text: panel, action: { kind: "plain" } });
|
|
55
|
+
}
|
|
56
|
+
return parts;
|
|
57
|
+
}
|
|
58
|
+
/** Mouse positions, like the layout, are in terminal cells, not string offsets. */
|
|
59
|
+
export function chatTabs(chats, style, pick) {
|
|
60
|
+
let pressed;
|
|
61
|
+
return {
|
|
62
|
+
pointer: new PointerHover(),
|
|
63
|
+
render(width) {
|
|
64
|
+
return [layout(chats(), width).map((part) => part.action ? style(part.text, part.shown === true, this.pointer.target === buttonKey(part.action), buttonRole[part.action.kind]) : part.text).join("")];
|
|
65
|
+
},
|
|
66
|
+
handleMouse(event) {
|
|
67
|
+
const move = event.type === "move";
|
|
68
|
+
if (event.y !== 0 || (!move && (event.button !== "left" || (event.type !== "press" && event.type !== "click"))))
|
|
69
|
+
return;
|
|
70
|
+
const down = pressed;
|
|
71
|
+
if (!move)
|
|
72
|
+
pressed = undefined;
|
|
73
|
+
let x = 0;
|
|
74
|
+
for (const part of layout(chats(), event.width)) {
|
|
75
|
+
const end = x + visibleWidth(part.text);
|
|
76
|
+
if (event.x >= x && event.x < end && part.action) {
|
|
77
|
+
const key = buttonKey(part.action);
|
|
78
|
+
this.pointer.target = key;
|
|
79
|
+
if (move)
|
|
80
|
+
return { handled: true, render: false };
|
|
81
|
+
// Claim the press so pi delivers a click on release, without moving focus out of the editor.
|
|
82
|
+
if (event.type === "press")
|
|
83
|
+
pressed = key;
|
|
84
|
+
// A chat can change its title or close between press and release, moving another tab under the pointer.
|
|
85
|
+
else if (down === key && !(part.shown && part.action.kind === "show")) {
|
|
86
|
+
this.pointer.target = undefined;
|
|
87
|
+
pick(part.action);
|
|
88
|
+
}
|
|
89
|
+
return { handled: true };
|
|
90
|
+
}
|
|
91
|
+
x = end;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
invalidate() { },
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/chat-terminal.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { AgentSessionRuntime, InteractiveMode, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { chatTabHeader } from "./chat-tab-header.js";
|
|
3
|
+
import { chatTabs, closeTerminalChat } from "./chat-tabs.js";
|
|
2
4
|
import { showWaitingMessages } from "./chat-waiting.js";
|
|
5
|
+
import { buttonLabel } from "./pointer-hover.js";
|
|
3
6
|
import { interruptChat, terminalUi } from "./chats.js";
|
|
4
7
|
/**
|
|
5
8
|
* ctrl+c, in the chat shown: what it is doing stopped, the other chats left as they are (`interruptChat`). In a chat
|
|
@@ -59,6 +62,47 @@ export function driveTerminal(core, options = {}) {
|
|
|
59
62
|
};
|
|
60
63
|
showWaitingMessages();
|
|
61
64
|
const prototype = InteractiveMode.prototype;
|
|
65
|
+
let switching = false;
|
|
66
|
+
const tabs = chatTabs(() => core.chats(), (text, shown, hovered, role) => {
|
|
67
|
+
const theme = real?.theme;
|
|
68
|
+
return theme === undefined ? text : buttonLabel(theme, text, shown, hovered, role);
|
|
69
|
+
}, (action) => {
|
|
70
|
+
if (switching || runtime === undefined)
|
|
71
|
+
return;
|
|
72
|
+
if (action.kind === "plain")
|
|
73
|
+
return core.shownChat()?.instance?.openPlainPanel?.();
|
|
74
|
+
switching = true;
|
|
75
|
+
const change = action.kind === "open" ? core.open() : action.kind === "close" ? closeTerminalChat(core, action.id) : core.show(action.id);
|
|
76
|
+
void change.catch((error) => core.notify(error instanceof Error ? error.message : String(error), "warning")).finally(() => { switching = false; });
|
|
77
|
+
});
|
|
78
|
+
const header = chatTabHeader(tabs);
|
|
79
|
+
const addEntry = prototype.addCustomEntryToChat;
|
|
80
|
+
prototype.addCustomEntryToChat = function (entry) {
|
|
81
|
+
addEntry.call(this, entry);
|
|
82
|
+
if (entry.customType === "turri_banner")
|
|
83
|
+
header.afterBanner(this.chatContainer, entry);
|
|
84
|
+
};
|
|
85
|
+
let stopWatchingTabs;
|
|
86
|
+
const mount = prototype.mountInteractiveTui;
|
|
87
|
+
prototype.mountInteractiveTui = function (tui, components) {
|
|
88
|
+
stopWatchingTabs?.();
|
|
89
|
+
mount.call(this, tui, header.mount(this, components));
|
|
90
|
+
const unwatch = header.watch(this, tui);
|
|
91
|
+
let ticker;
|
|
92
|
+
const refresh = () => {
|
|
93
|
+
if (core.chats().some((chat) => chat.status === "working")) {
|
|
94
|
+
ticker ??= setInterval(() => tui.requestRender(), 250).unref();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
clearInterval(ticker);
|
|
98
|
+
ticker = undefined;
|
|
99
|
+
}
|
|
100
|
+
tui.requestRender();
|
|
101
|
+
};
|
|
102
|
+
const stop = core.onChats(refresh);
|
|
103
|
+
refresh();
|
|
104
|
+
stopWatchingTabs = () => { stop(); clearInterval(ticker); unwatch(); };
|
|
105
|
+
};
|
|
62
106
|
const rebind = prototype.rebindCurrentSession;
|
|
63
107
|
prototype.rebindCurrentSession = async function (...args) {
|
|
64
108
|
await rebind.apply(this, args);
|
|
@@ -102,8 +146,10 @@ export function driveTerminal(core, options = {}) {
|
|
|
102
146
|
// Leaving turri: every chat let go - the one shown by pi, as it always is.
|
|
103
147
|
const dispose = runtimes.dispose;
|
|
104
148
|
runtimes.dispose = async function () {
|
|
105
|
-
if (this === runtime)
|
|
149
|
+
if (this === runtime) {
|
|
150
|
+
stopWatchingTabs?.();
|
|
106
151
|
await core.dispose({ except: runtime.session });
|
|
152
|
+
}
|
|
107
153
|
return dispose.call(this);
|
|
108
154
|
};
|
|
109
155
|
core.setDriver({
|
|
@@ -135,17 +181,17 @@ export function driveTerminal(core, options = {}) {
|
|
|
135
181
|
return;
|
|
136
182
|
from?.ui?.hide();
|
|
137
183
|
// pi takes the shown chat's widgets and dialogs off the screen, as it does before replacing a session - but not the
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
184
|
+
// overlays on it: the side panel, the session's and not the chat's, stays where it is, beside the chat or over it.
|
|
185
|
+
// pi takes off every overlay it holds, so for that moment it holds none.
|
|
186
|
+
const overlays = screen?.extensionOverlays;
|
|
187
|
+
const kept = [...(overlays ?? [])];
|
|
188
|
+
overlays?.clear();
|
|
143
189
|
try {
|
|
144
190
|
runtime.beforeSessionInvalidate?.();
|
|
145
191
|
}
|
|
146
192
|
finally {
|
|
147
|
-
|
|
148
|
-
|
|
193
|
+
for (const [handle, remove] of kept)
|
|
194
|
+
overlays?.set(handle, remove);
|
|
149
195
|
}
|
|
150
196
|
runtime._session = chat.session;
|
|
151
197
|
runtime._services = chat.services;
|
package/dist/chat-waiting.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { type Component } from "@earendil-works/pi-tui";
|
|
|
14
14
|
export interface WaitingScreen {
|
|
15
15
|
chatContainer: Container;
|
|
16
16
|
pendingMessagesContainer: Container;
|
|
17
|
+
/** The output of commands the person ran (`!`) while the agent works: pi keeps it there until it goes in the chat. */
|
|
18
|
+
pendingBashComponents?: Component[];
|
|
17
19
|
getAllQueuedMessages(): {
|
|
18
20
|
steering: string[];
|
|
19
21
|
followUp: string[];
|
|
@@ -36,7 +38,8 @@ export declare class Shade implements Component {
|
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Under the chat, each message the agent has not read yet, drawn as pi draws a message in the chat - shaded, and
|
|
39
|
-
* marked not read yet - in the order they were sent
|
|
41
|
+
* marked not read yet - in the order they were sent; under the output of any command the person ran meanwhile, as pi
|
|
42
|
+
* draws them.
|
|
40
43
|
*/
|
|
41
44
|
export declare function showWaiting(screen: WaitingScreen): void;
|
|
42
45
|
/** What of pi's session `unqueue` reaches. */
|
package/dist/chat-waiting.js
CHANGED
|
@@ -21,11 +21,14 @@ export class Shade {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Under the chat, each message the agent has not read yet, drawn as pi draws a message in the chat - shaded, and
|
|
24
|
-
* marked not read yet - in the order they were sent
|
|
24
|
+
* marked not read yet - in the order they were sent; under the output of any command the person ran meanwhile, as pi
|
|
25
|
+
* draws them.
|
|
25
26
|
*/
|
|
26
27
|
export function showWaiting(screen) {
|
|
27
28
|
const area = screen.pendingMessagesContainer;
|
|
28
29
|
area.clear();
|
|
30
|
+
for (const output of screen.pendingBashComponents ?? [])
|
|
31
|
+
area.addChild(output);
|
|
29
32
|
const { steering, followUp } = screen.getAllQueuedMessages();
|
|
30
33
|
const waiting = [...steering, ...followUp];
|
|
31
34
|
if (waiting.length === 0)
|
|
@@ -36,9 +39,9 @@ export function showWaiting(screen) {
|
|
|
36
39
|
const chat = screen.chatContainer;
|
|
37
40
|
screen.chatContainer = area;
|
|
38
41
|
try {
|
|
39
|
-
for (const text of waiting) {
|
|
40
|
-
// A line between it and
|
|
41
|
-
if (
|
|
42
|
+
for (const [index, text] of waiting.entries()) {
|
|
43
|
+
// A line between it and what is above it; pi puts one between messages itself.
|
|
44
|
+
if (index === 0)
|
|
42
45
|
area.addChild(new Spacer(1));
|
|
43
46
|
const before = area.children.length;
|
|
44
47
|
screen.addMessageToChat({ role: "user", content: [{ type: "text", text }], timestamp: Date.now() });
|
package/dist/chats.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { type ChatRole, type Conclusion, type Notice, type NoticeAnswer, type No
|
|
|
14
14
|
* One turri process is one session on one project, and holds up to MAX_CHATS chats: conversations, each with its own
|
|
15
15
|
* history, model, thinking level and questions, each working while another is shown. What they share is the
|
|
16
16
|
* session's: the one job registry and work loop the project's pulses run in - a pulse any chat starts is in every
|
|
17
|
-
* chat's side panel - the coding model,
|
|
17
|
+
* chat's side panel - the coding model, launches and the ledger.
|
|
18
18
|
*
|
|
19
19
|
* A chat is a pi session with turri's extension in it. The extension, built once for each, links itself to its chat
|
|
20
20
|
* here (`attach`); its tools, commands and handlers then run inside the chat's scope (chat-scope.ts), so a pulse knows
|
|
@@ -102,6 +102,8 @@ export interface TurriHost {
|
|
|
102
102
|
}
|
|
103
103
|
/** What a chat's extension does for its chat when the session asks. */
|
|
104
104
|
export interface ChatInstance {
|
|
105
|
+
/** The terminal header's button: open the project's spec map beside this chat. */
|
|
106
|
+
openPlainPanel?(): void;
|
|
105
107
|
/** A pulse it asked for ended: said in the chat, and its agent told, to react to it. */
|
|
106
108
|
announce(job: Job): void;
|
|
107
109
|
/**
|
package/dist/chats.js
CHANGED
|
@@ -12,7 +12,7 @@ import { newNotice, noticeTask, SENTINEL, sentinelStartChoice, wentWrong } from
|
|
|
12
12
|
* One turri process is one session on one project, and holds up to MAX_CHATS chats: conversations, each with its own
|
|
13
13
|
* history, model, thinking level and questions, each working while another is shown. What they share is the
|
|
14
14
|
* session's: the one job registry and work loop the project's pulses run in - a pulse any chat starts is in every
|
|
15
|
-
* chat's side panel - the coding model,
|
|
15
|
+
* chat's side panel - the coding model, launches and the ledger.
|
|
16
16
|
*
|
|
17
17
|
* A chat is a pi session with turri's extension in it. The extension, built once for each, links itself to its chat
|
|
18
18
|
* here (`attach`); its tools, commands and handlers then run inside the chat's scope (chat-scope.ts), so a pulse knows
|