pi-qq 0.1.6 → 0.1.7

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 (4) hide show
  1. package/README.md +7 -3
  2. package/package.json +3 -3
  3. package/qq-ui.ts +12 -3
  4. package/qq.ts +80 -2
package/README.md CHANGED
@@ -7,7 +7,7 @@ Ask quick side questions about your current [pi](https://pi.dev) session without
7
7
  ## Why try it?
8
8
 
9
9
  - **A real side channel:** ask `/qq why are we changing this file?` while the main agent keeps working. The answer shows in a bottom overlay and does not enter the main transcript.
10
- - **Context-aware, intentionally constrained:** `/qq` passes read-only main-session context, treats ambiguous references like “this”, “that”, “we”, and “the plan” as references to the active session, gives the side call no tools, and keeps no `/qq` history.
10
+ - **Context-aware, intentionally constrained:** `/qq` passes read-only main-session context, treats ambiguous references like “this”, “that”, “we”, and “the plan” as references to the active session, and gives the side call no tools. Previous `/qq` answers are available only through `/qq-history`; they are not fed back into future `/qq` calls.
11
11
  - **Fast, low-friction UX:** `/qq` uses recent context by default, automatically switches to broader context for retrospective questions, and supports explicit `--recent` / `--full` modes. Press **alt+q** / **Option+Q** to toggle `/qq `, then use **Esc** to cancel/dismiss or **↑/↓** to scroll longer answers.
12
12
 
13
13
  ## Demo
@@ -23,7 +23,7 @@ Another common flow:
23
23
  1. Press **alt+q** / **Option+Q**.
24
24
  2. Type `what's the risk with this plan?`.
25
25
  3. Hit Enter.
26
- 4. Read the concise overlay answer; press **Esc** to dismiss.
26
+ 4. Read the concise overlay answer; press **Esc** to dismiss. If you close it too soon, run `/qq-history` to reopen recent answers.
27
27
 
28
28
  ## Install
29
29
 
@@ -41,6 +41,7 @@ After installing, run `/reload` in pi or restart the session.
41
41
  /qq <question>
42
42
  /qq --recent <question>
43
43
  /qq --full <question>
44
+ /qq-history
44
45
  ```
45
46
 
46
47
  By default, `/qq` chooses a context mode automatically:
@@ -50,6 +51,8 @@ By default, `/qq` chooses a context mode automatically:
50
51
 
51
52
  Use `--recent` when you want the fastest answer from the latest messages. Use `--full` when you explicitly want broader session context.
52
53
 
54
+ Use `/qq-history` to reopen recent `/qq` answers from the current session. History is view-only and is not included as context for future `/qq` model calls.
55
+
53
56
  ### Shortcut
54
57
 
55
58
  Press **alt+q** / **Option+Q** to toggle `/qq ` at the front of the editor:
@@ -71,7 +74,8 @@ Press **alt+q** / **Option+Q** to toggle `/qq ` at the front of the editor:
71
74
  - Recent mode sends only the latest messages for speed; full mode sends broader bounded context.
72
75
  - Large text parts are clipped, thinking blocks are removed, and images are omitted from the side-call context for speed.
73
76
  - The side call has no tools.
74
- - `/qq` stores no quick-question history; each call is independent except for the main-session context.
77
+ - Recent `/qq` answers are kept in memory only so `/qq-history` can reopen them after dismissal.
78
+ - `/qq-history` is view-only; it is not used as context for future `/qq` model calls.
75
79
  - The system prompt biases answers toward concise, direct responses.
76
80
 
77
81
  ## License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-qq",
3
- "version": "0.1.6",
4
- "description": "Pi extension. Ask context-aware side questions with /qq or alt+q without polluting the main transcript.",
3
+ "version": "0.1.7",
4
+ "description": "Pi extension. Ask context-aware side questions with /qq or alt+q, then reopen answers with /qq-history.",
5
5
  "keywords": [
6
6
  "pi-package",
7
7
  "pi-extension",
@@ -9,7 +9,7 @@
9
9
  "side-question",
10
10
  "context-aware",
11
11
  "transcript-safe",
12
- "no-history",
12
+ "history",
13
13
  "question",
14
14
  "shortcut",
15
15
  "keybinding",
package/qq-ui.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * Esc → abort in-flight call + dismiss
13
13
  * ↑/↓ → scroll when content exceeds terminal
14
14
  *
15
- * Does not keep quick-question history.
15
+ * Used for both live /qq answers and view-only /qq-history.
16
16
  */
17
17
 
18
18
  import type { ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
@@ -49,6 +49,7 @@ export interface ShowQqOverlayParams {
49
49
  ctx: ExtensionCommandContext;
50
50
  question: string;
51
51
  controller: AbortController;
52
+ commandLabel?: string;
52
53
  }
53
54
 
54
55
  export interface ShowQqOverlayResult {
@@ -68,6 +69,7 @@ export class QqOverlayController implements Component {
68
69
  private readonly tui: TUI,
69
70
  private readonly done: (result?: undefined) => void,
70
71
  private readonly controller: AbortController,
72
+ private readonly commandLabel: string = QQ_LITERAL,
71
73
  ) {}
72
74
 
73
75
  setAnswer(text: string): void {
@@ -128,7 +130,7 @@ export class QqOverlayController implements Component {
128
130
  }
129
131
 
130
132
  private renderBanner(width: number): string {
131
- const prefix = `${SIDE_PAD}${QQ_LITERAL} `;
133
+ const prefix = `${SIDE_PAD}${this.commandLabel} `;
132
134
  const prefixWidth = visibleWidth(prefix);
133
135
  const questionWidth = Math.max(0, width - prefixWidth);
134
136
  const truncatedQuestion = truncateToWidth(this.question, questionWidth, "…", false);
@@ -170,7 +172,14 @@ export function showQqOverlay(params: ShowQqOverlayParams): ShowQqOverlayResult
170
172
 
171
173
  const overlayPromise = params.ctx.ui.custom<void>(
172
174
  (tui, theme, _keybindings, done) => {
173
- const controller = new QqOverlayController(params.question, theme, tui, done, params.controller);
175
+ const controller = new QqOverlayController(
176
+ params.question,
177
+ theme,
178
+ tui,
179
+ done,
180
+ params.controller,
181
+ params.commandLabel,
182
+ );
174
183
  resolveReady(controller);
175
184
  return controller;
176
185
  },
package/qq.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * conversation as read-only context. The answer is rendered ephemerally in a
6
6
  * bottom-slot overlay and never enters the main session transcript.
7
7
  *
8
- * Does not keep quick-question history.
8
+ * Keeps in-memory, view-only answer history for /qq-history.
9
9
  */
10
10
 
11
11
  import { readFileSync } from "node:fs";
@@ -27,6 +27,7 @@ import {
27
27
  import { showQqOverlay } from "./qq-ui.js";
28
28
 
29
29
  export const QQ_COMMAND_NAME = "qq";
30
+ export const QQ_HISTORY_COMMAND_NAME = "qq-history";
30
31
  export const QQ_PREFIX = `/${QQ_COMMAND_NAME} `;
31
32
  export const QQ_STATE_KEY = Symbol.for("pi-qq:qq");
32
33
 
@@ -34,6 +35,8 @@ const MSG_REQUIRES_INTERACTIVE = "/qq requires interactive mode";
34
35
  const MSG_USAGE = "Usage: /qq [--recent|--full] <question>";
35
36
  const MSG_NO_MODEL = "/qq requires an active model";
36
37
  const ERR_EMPTY_RESPONSE = "/qq returned no text content.";
38
+ const MSG_NO_HISTORY = "No /qq history for this session yet";
39
+ const QQ_HISTORY_LIMIT = 20;
37
40
  const RECENT_CONTEXT_MESSAGE_LIMIT = 12;
38
41
  const FULL_CONTEXT_HEAD_MESSAGE_LIMIT = 4;
39
42
  const FULL_CONTEXT_TAIL_MESSAGE_LIMIT = 80;
@@ -51,8 +54,15 @@ interface ParsedQqArgs {
51
54
  mode: QqContextMode;
52
55
  }
53
56
 
57
+ interface QqHistoryEntry {
58
+ question: string;
59
+ answer: string;
60
+ timestamp: number;
61
+ }
62
+
54
63
  interface QqState {
55
64
  snapshots: Map<string, { messages: Message[] }>;
65
+ histories: Map<string, QqHistoryEntry[]>;
56
66
  }
57
67
 
58
68
  export const QQ_SYSTEM_PROMPT = readFileSync(
@@ -64,7 +74,7 @@ function getState(): QqState {
64
74
  const globalState = globalThis as unknown as { [k: symbol]: QqState | undefined };
65
75
  let state = globalState[QQ_STATE_KEY];
66
76
  if (!state) {
67
- state = { snapshots: new Map() };
77
+ state = { snapshots: new Map(), histories: new Map() };
68
78
  globalState[QQ_STATE_KEY] = state;
69
79
  }
70
80
  return state;
@@ -82,10 +92,45 @@ function setSnapshot(ctx: ExtensionContext, snapshot: { messages: Message[] }):
82
92
  getState().snapshots.set(getSessionFile(ctx), snapshot);
83
93
  }
84
94
 
95
+ function getSessionHistory(ctx: ExtensionContext): QqHistoryEntry[] {
96
+ const key = getSessionFile(ctx);
97
+ const state = getState();
98
+ let history = state.histories.get(key);
99
+ if (!history) {
100
+ history = [];
101
+ state.histories.set(key, history);
102
+ }
103
+ return history;
104
+ }
105
+
106
+ function pushSessionHistory(ctx: ExtensionContext, entry: QqHistoryEntry): void {
107
+ const history = getSessionHistory(ctx);
108
+ history.push(entry);
109
+ if (history.length > QQ_HISTORY_LIMIT) {
110
+ history.splice(0, history.length - QQ_HISTORY_LIMIT);
111
+ }
112
+ }
113
+
85
114
  export function invalidateSnapshot(ctx: ExtensionContext): void {
86
115
  getState().snapshots.delete(getSessionFile(ctx));
87
116
  }
88
117
 
118
+ function formatHistoryTimestamp(timestamp: number): string {
119
+ return new Date(timestamp).toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
120
+ }
121
+
122
+ function formatQqHistory(entries: QqHistoryEntry[]): string {
123
+ return entries
124
+ .slice()
125
+ .reverse()
126
+ .map((entry, index) => {
127
+ const question = entry.question.replace(/\s+/g, " ").trim();
128
+ const answer = entry.answer.trim();
129
+ return `${index + 1}. ${formatHistoryTimestamp(entry.timestamp)} — /qq ${question}\n${answer}`;
130
+ })
131
+ .join("\n\n");
132
+ }
133
+
89
134
  export function assistantMessageText(msg: AssistantMessage): string {
90
135
  return msg.content
91
136
  .filter((content): content is { type: "text"; text: string } => content.type === "text")
@@ -344,6 +389,10 @@ export function registerQqCommand(pi: ExtensionAPI): void {
344
389
  description: "Ask a quick question without polluting the main conversation",
345
390
  handler: (args: string, ctx: ExtensionCommandContext) => handleQqCommand(args, ctx),
346
391
  });
392
+ pi.registerCommand(QQ_HISTORY_COMMAND_NAME, {
393
+ description: "Show recent /qq answers for this session",
394
+ handler: (_args: string, ctx: ExtensionCommandContext) => handleQqHistoryCommand(ctx),
395
+ });
347
396
  }
348
397
 
349
398
  async function handleQqCommand(args: string, ctx: ExtensionCommandContext): Promise<void> {
@@ -372,6 +421,11 @@ async function handleQqCommand(args: string, ctx: ExtensionCommandContext): Prom
372
421
  const result = await executeQq(parsedArgs.question, parsedArgs.mode, ctx, controller);
373
422
 
374
423
  if (result.ok && result.answer) {
424
+ pushSessionHistory(ctx, {
425
+ question: parsedArgs.question,
426
+ answer: result.answer,
427
+ timestamp: Date.now(),
428
+ });
375
429
  overlayCtl.setAnswer(result.answer);
376
430
  } else if (result.aborted) {
377
431
  // User Esc'd — overlay already dismissed via done(); no further action.
@@ -381,3 +435,27 @@ async function handleQqCommand(args: string, ctx: ExtensionCommandContext): Prom
381
435
 
382
436
  await overlayPromise;
383
437
  }
438
+
439
+ async function handleQqHistoryCommand(ctx: ExtensionCommandContext): Promise<void> {
440
+ if (!ctx.hasUI) {
441
+ ctx.ui.notify(MSG_REQUIRES_INTERACTIVE, "error");
442
+ return;
443
+ }
444
+ const history = getSessionHistory(ctx);
445
+ if (history.length === 0) {
446
+ ctx.ui.notify(MSG_NO_HISTORY, "info");
447
+ return;
448
+ }
449
+
450
+ const controller = new AbortController();
451
+ const { overlayPromise, controllerReady } = showQqOverlay({
452
+ ctx,
453
+ question: `${history.length} recent answer${history.length === 1 ? "" : "s"}`,
454
+ controller,
455
+ commandLabel: "/qq-history",
456
+ });
457
+
458
+ const overlayCtl = await controllerReady;
459
+ overlayCtl.setAnswer(formatQqHistory(history));
460
+ await overlayPromise;
461
+ }