@juicesharp/rpiv-ask-user-question 2.15.0 → 2.16.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.
@@ -61,9 +61,21 @@ function emitAskUserPromptEvent(pi: ExtensionAPI, params: QuestionParams, toolCa
61
61
  pi.events.emit(ASK_USER_PROMPT_EVENT, payload);
62
62
  }
63
63
 
64
+ /**
65
+ * Herdr's Pi integration marks the pane blocked only from this bus event, counting each
66
+ * `active: true` until its `active: false`; it reads neither OSC 7501 nor the screen.
67
+ */
68
+ const HERDR_BLOCKED_EVENT = "herdr:blocked";
69
+
70
+ /** The one status line terminals and Herdr show while a questionnaire waits: never question text. */
71
+ function blockedMessage(): string {
72
+ return t("status.blocked", "Waiting for your answer");
73
+ }
74
+
64
75
  function emitAskUserBlockedEvent(pi: ExtensionAPI, active: boolean, toolCallId: string): void {
65
76
  const payload: AskUserBlockedEventPayload = { active, toolCallId };
66
77
  pi.events.emit(ASK_USER_BLOCKED_EVENT, payload);
78
+ pi.events.emit(HERDR_BLOCKED_EVENT, { active, label: active ? blockedMessage() : undefined });
67
79
  }
68
80
 
69
81
  /** Non-interactive host backstop (the reconciler normally strips the tool first). */
@@ -121,6 +133,13 @@ type SessionModule = typeof import("./state/questionnaire-session.ts");
121
133
 
122
134
  type SessionRef = { current: import("./state/questionnaire-session.ts").QuestionnaireSession | null };
123
135
  type OverlayHandleRef = { current: OverlayHandle | undefined };
136
+ /**
137
+ * Pi's `custom()` options plus `blocked` (OSC 7501 program status): honoured inline on Pi 1.5.0+
138
+ * and for overlays on 1.5.1+, ignored by older Pi, whose typings lack it.
139
+ */
140
+ type CustomOptions = NonNullable<Parameters<ExtensionContext["ui"]["custom"]>[1]> & {
141
+ blocked?: { kind: "question"; message: string };
142
+ };
124
143
 
125
144
  type SessionLoad =
126
145
  | { ok: true; module: SessionModule }
@@ -308,24 +327,28 @@ async function mountQuestionnaire(config: {
308
327
  // may emit `setHidden` only when it was actually registered; otherwise collapse falls
309
328
  // back to the visible one-line row.
310
329
  const canReopenWhileHidden = removeOverlayInputListener !== undefined;
330
+ // Pi owns the OSC 7501 lifecycle. Resolved per mount so a /languages switch reaches the next questionnaire.
331
+ const blocked = { kind: "question" as const, message: blockedMessage() };
332
+ const options: CustomOptions = presentation.overlay
333
+ ? {
334
+ overlay: true,
335
+ blocked,
336
+ overlayOptions: {
337
+ anchor: "bottom-center",
338
+ width: "100%",
339
+ maxHeight: "100%",
340
+ margin: { left: 0, right: 0, bottom: 0 },
341
+ },
342
+ onHandle: (handle) => {
343
+ overlayHandleRef.current = handle;
344
+ sessionRef.current?.setOverlayHandle(handle);
345
+ },
346
+ }
347
+ : { overlay: false, blocked };
311
348
  try {
312
349
  return await ctx.ui.custom<QuestionnaireResult>(
313
350
  makeSessionFactory({ ...config, canReopenWhileHidden, sessionRef }),
314
- presentation.overlay
315
- ? {
316
- overlay: true,
317
- overlayOptions: {
318
- anchor: "bottom-center",
319
- width: "100%",
320
- maxHeight: "100%",
321
- margin: { left: 0, right: 0, bottom: 0 },
322
- },
323
- onHandle: (handle) => {
324
- overlayHandleRef.current = handle;
325
- sessionRef.current?.setOverlayHandle(handle);
326
- },
327
- }
328
- : { overlay: false },
351
+ options,
329
352
  );
330
353
  } finally {
331
354
  removeOverlayInputListener?.();
@@ -107,6 +107,22 @@ indexes are in `details.unanswered`. Both are absent when every question is answ
107
107
  A cancelled result always reads as the decline in text; its note, if any, survives only
108
108
  in `details.globalNote`.
109
109
 
110
+ ## Terminal program status
111
+
112
+ Questionnaires request `blocked` program status with kind `question` through
113
+ `ctx.ui.custom()`: supported for inline questionnaires on Pi 1.5.0+ and overlay fallbacks
114
+ on Pi 1.5.1+. Pi manages the OSC 7501 record and its cleanup. Overlay status remains blocked
115
+ while an unanswered questionnaire is hidden or covered by another overlay; closing one
116
+ questionnaire does not clear another pending question's status. The fixed message,
117
+ `Waiting for your answer` (translated as `status.blocked`), keeps question and answer text out of
118
+ the terminal status record.
119
+
120
+ Older Pi versions still render questionnaires but ignore unsupported `blocked` metadata.
121
+ `rpiv:ask-user:blocked` remains available for status integrations on all presentation paths.
122
+ Beside it, `herdr:blocked` (`{ active, label }`, the same translated message) brackets the same
123
+ wait, because Herdr's Pi integration reads only that event, not OSC 7501.
124
+ Progress reporting is not exposed by Pi's `blocked` option.
125
+
110
126
  ## Event contract
111
127
 
112
128
  Everything here imports from the `/events` subpath.
package/locales/de.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Gib deine Antwort ein:",
33
33
 
34
34
  "transcript.not_answered": "nicht beantwortet",
35
- "transcript.no_answer": "keine Antwort"
35
+ "transcript.no_answer": "keine Antwort",
36
+
37
+ "status.blocked": "Wartet auf deine Antwort"
36
38
  }
package/locales/en.json CHANGED
@@ -35,5 +35,7 @@
35
35
  "rpc.custom_answer_title": "Type your answer:",
36
36
 
37
37
  "transcript.not_answered": "not answered",
38
- "transcript.no_answer": "no answer"
38
+ "transcript.no_answer": "no answer",
39
+
40
+ "status.blocked": "Waiting for your answer"
39
41
  }
package/locales/es.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Escribe tu respuesta:",
33
33
 
34
34
  "transcript.not_answered": "sin responder",
35
- "transcript.no_answer": "sin respuesta"
35
+ "transcript.no_answer": "sin respuesta",
36
+
37
+ "status.blocked": "Esperando tu respuesta"
36
38
  }
package/locales/fr.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Tapez votre réponse :",
33
33
 
34
34
  "transcript.not_answered": "sans réponse",
35
- "transcript.no_answer": "aucune réponse"
35
+ "transcript.no_answer": "aucune réponse",
36
+
37
+ "status.blocked": "En attente de votre réponse"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Digite sua resposta:",
33
33
 
34
34
  "transcript.not_answered": "não respondida",
35
- "transcript.no_answer": "sem resposta"
35
+ "transcript.no_answer": "sem resposta",
36
+
37
+ "status.blocked": "Aguardando sua resposta"
36
38
  }
package/locales/pt.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Escreva a sua resposta:",
33
33
 
34
34
  "transcript.not_answered": "não respondida",
35
- "transcript.no_answer": "sem resposta"
35
+ "transcript.no_answer": "sem resposta",
36
+
37
+ "status.blocked": "À espera da sua resposta"
36
38
  }
package/locales/ru.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Введите свой ответ:",
33
33
 
34
34
  "transcript.not_answered": "без ответа",
35
- "transcript.no_answer": "ответа нет"
35
+ "transcript.no_answer": "ответа нет",
36
+
37
+ "status.blocked": "Ждёт вашего ответа"
36
38
  }
package/locales/uk.json CHANGED
@@ -32,5 +32,7 @@
32
32
  "rpc.custom_answer_title": "Введіть свою відповідь:",
33
33
 
34
34
  "transcript.not_answered": "без відповіді",
35
- "transcript.no_answer": "відповіді немає"
35
+ "transcript.no_answer": "відповіді немає",
36
+
37
+ "status.blocked": "Чекає на вашу відповідь"
36
38
  }
package/locales/zh.json CHANGED
@@ -34,5 +34,7 @@
34
34
  "rpc.custom_answer_title": "输入你的回答:",
35
35
 
36
36
  "transcript.not_answered": "未回答",
37
- "transcript.no_answer": "无回答"
37
+ "transcript.no_answer": "无回答",
38
+
39
+ "status.blocked": "等待你的回答"
38
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.15.0",
3
+ "version": "2.16.0",
4
4
  "description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -102,6 +102,6 @@
102
102
  }
103
103
  },
104
104
  "dependencies": {
105
- "@juicesharp/rpiv-config": "^2.15.0"
105
+ "@juicesharp/rpiv-config": "^2.16.0"
106
106
  }
107
107
  }
@@ -2,6 +2,7 @@ import type { Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { type Component, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
3
3
  import { t } from "../state/i18n-bridge.ts";
4
4
  import { NO_INPUT_PLACEHOLDER } from "../tool/format-answer.ts";
5
+ import { prepareQuestionArguments } from "../tool/normalize-params.ts";
5
6
  import {
6
7
  isQuestionnaireResult,
7
8
  type QuestionAnswer,
@@ -16,21 +17,50 @@ const RECOMMENDED_SUFFIX = /\s*\(Recommended\)$/;
16
17
 
17
18
  type ToolResultView = { content: ReadonlyArray<{ type: string; text?: string }>; details?: unknown };
18
19
 
19
- /** Lines laid out at render time, so wrapping and truncation follow the terminal width. */
20
+ /** The part of a recorded question the transcript draws. */
21
+ type RecordedQuestion = { header: string; question: string | undefined };
22
+
23
+ /**
24
+ * The questions as the session recorded them. Pi decodes a provider's double-encoded
25
+ * `questions` before the tool runs (#244), but a replayed session hands the renderers
26
+ * the raw recorded arguments, so they are decoded again here. A shape that is still
27
+ * not an array draws as no questions, and an element that is not a question keeps its
28
+ * slot (answers point at questions by index) with an empty header, so a malformed
29
+ * transcript cannot throw out of the render path.
30
+ */
31
+ function recordedQuestions(args: unknown): RecordedQuestion[] {
32
+ const questions: unknown = prepareQuestionArguments(args ?? {})?.questions;
33
+ if (!Array.isArray(questions)) return [];
34
+ return questions.map((q) => {
35
+ const fields = typeof q === "object" && q !== null ? (q as Record<string, unknown>) : {};
36
+ return {
37
+ header: typeof fields.header === "string" ? fields.header : "",
38
+ question: typeof fields.question === "string" ? fields.question : undefined,
39
+ };
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Lines laid out at render time, so wrapping and truncation follow the terminal width.
45
+ * Every line is clamped to the width: Pi stops the whole TUI on a line wider than the
46
+ * terminal, so no receipt branch may hand it one.
47
+ */
20
48
  class WidthLines implements Component {
21
49
  constructor(private readonly layout: (width: number) => string[]) {}
22
50
  render(width: number): string[] {
23
- return this.layout(width);
51
+ return this.layout(width).map((line) => truncateToWidth(line, width, "…"));
24
52
  }
25
53
  invalidate(): void {}
26
54
  }
27
55
 
28
56
  /** `Ask Format · Migration`: the headers name the questions. */
29
57
  export function renderAskCall(args: QuestionParams | undefined, theme: Theme): Component {
30
- const headers = (args?.questions ?? []).map((q) => q?.header).filter(Boolean);
58
+ const headers = recordedQuestions(args)
59
+ .map((q) => q.header)
60
+ .filter(Boolean);
31
61
  const title = theme.fg("toolTitle", theme.bold("Ask"));
32
62
  const text = headers.length > 0 ? `${title} ${theme.fg("accent", headers.join(" · "))}` : title;
33
- return new WidthLines((width) => [truncateToWidth(text, width, "…")]);
63
+ return new WidthLines(() => [text]);
34
64
  }
35
65
 
36
66
  /**
@@ -52,10 +82,10 @@ export function renderAskResult(
52
82
  if (details.cancelled) {
53
83
  return new WidthLines(() => [theme.fg("dim", `✗ ${t("transcript.no_answer", "no answer")}`)]);
54
84
  }
55
- const questions = args?.questions ?? [];
85
+ const questions = recordedQuestions(args);
56
86
  return new WidthLines((width) =>
57
87
  questions.length > 1
58
- ? tableLines(details, args as QuestionParams, theme, options.expanded, width)
88
+ ? tableLines(details, questions, theme, options.expanded, width)
59
89
  : singleLines(details, questions[0]?.question, theme, options.expanded, width),
60
90
  );
61
91
  }
@@ -75,14 +105,14 @@ function singleLines(
75
105
 
76
106
  function tableLines(
77
107
  details: QuestionnaireResult,
78
- args: QuestionParams,
108
+ questions: readonly RecordedQuestion[],
79
109
  theme: Theme,
80
110
  expanded: boolean,
81
111
  width: number,
82
112
  ): string[] {
83
- const headerWidth = Math.max(...args.questions.map((q) => visibleWidth(q.header)));
113
+ const headerWidth = Math.max(...questions.map((q) => visibleWidth(q.header)));
84
114
  const answerIndent = " ".repeat(INDENT.length + headerWidth + COLUMN_GAP.length);
85
- const lines = args.questions.flatMap((q, i) => {
115
+ const lines = questions.flatMap((q, i) => {
86
116
  const answer = details.answers.find((a) => a.questionIndex === i);
87
117
  const header = q.header + " ".repeat(headerWidth - visibleWidth(q.header));
88
118
  const row = hanging(`${INDENT}${theme.fg("muted", header)}${COLUMN_GAP}`, answerText(answer, theme), width);