@juicesharp/rpiv-ask-user-question 1.12.0 → 1.14.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.
@@ -1,5 +1,6 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { loadConfig, validateGuidanceFields } from "./config.js";
3
+ import { ASK_USER_PROMPT_EVENT, type AskUserPromptEventPayload } from "./events.js";
3
4
  import { displayLabel } from "./state/i18n-bridge.js";
4
5
  import { QuestionnaireSession } from "./state/questionnaire-session.js";
5
6
  import { sentinelsToAppend } from "./state/row-intent.js";
@@ -16,6 +17,22 @@ import {
16
17
  import { validateQuestionnaire } from "./tool/validate-questionnaire.js";
17
18
  import type { WrappingSelectItem } from "./view/components/wrapping-select.js";
18
19
 
20
+ function emitAskUserPromptEvent(pi: ExtensionAPI, params: QuestionParams): void {
21
+ const payload: AskUserPromptEventPayload = {
22
+ questions: params.questions.map((q) => ({
23
+ question: q.question,
24
+ header: q.header,
25
+ multiSelect: q.multiSelect ?? false,
26
+ options: q.options.map((o) => ({
27
+ label: o.label,
28
+ description: o.description,
29
+ hasPreview: typeof o.preview === "string" && o.preview.length > 0,
30
+ })),
31
+ })),
32
+ };
33
+ pi.events.emit(ASK_USER_PROMPT_EVENT, payload);
34
+ }
35
+
19
36
  const ERROR_NO_UI = "Error: UI not available (running in non-interactive mode)";
20
37
 
21
38
  export function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {
@@ -80,18 +97,32 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
80
97
  });
81
98
  }
82
99
 
100
+ // Emit event for external listeners (e.g., notification plugins)
101
+ emitAskUserPromptEvent(pi, typed);
102
+
83
103
  const itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));
84
104
 
85
- const result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {
86
- const session = new QuestionnaireSession({
87
- tui,
88
- theme,
89
- params: typed,
90
- itemsByTab,
91
- done,
92
- });
93
- return session.component;
94
- });
105
+ const result = await ctx.ui.custom<QuestionnaireResult>(
106
+ (tui, theme, _kb, done) => {
107
+ const session = new QuestionnaireSession({
108
+ tui,
109
+ theme,
110
+ params: typed,
111
+ itemsByTab,
112
+ done,
113
+ });
114
+ return session.component;
115
+ },
116
+ {
117
+ overlay: true,
118
+ overlayOptions: {
119
+ anchor: "bottom-center",
120
+ width: "100%",
121
+ maxHeight: "100%",
122
+ margin: { left: 0, right: 0, bottom: 0 },
123
+ },
124
+ },
125
+ );
95
126
 
96
127
  return buildQuestionnaireResponse(result, typed);
97
128
  },
package/events.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Public event contract for @juicesharp/rpiv-ask-user-question.
3
+ *
4
+ * STABILITY POLICY — applies to every event in the `rpiv:*` namespace.
5
+ *
6
+ * 1. Channel names are immutable. Once shipped, never rename.
7
+ * 2. Payload changes are append-only. Listeners MUST tolerate unknown
8
+ * fields. New fields ship as optional (`?:`).
9
+ * 3. Breaking changes (rename, retype, remove a field; change emission
10
+ * semantics) require a NEW channel, e.g. `rpiv:ask-user:prompt.v2`,
11
+ * with dual-emit during a deprecation window.
12
+ * 4. No `version` field inside payloads. Version via channel name only.
13
+ * 5. Payloads must be JSON-safe: primitives, arrays, plain objects.
14
+ * No Set/Map/Date/class instances — payloads must survive JSON
15
+ * serialization when listeners forward them across process or
16
+ * network boundaries.
17
+ *
18
+ * Naming: `rpiv:<package-or-tool>:<phase>`, lowercase, hyphen-separated.
19
+ * Aligns with Pi's `"my-extension:status"` example and UniPi's `unipi:*`.
20
+ */
21
+
22
+ export const ASK_USER_PROMPT_EVENT = "rpiv:ask-user:prompt" as const;
23
+
24
+ export interface AskUserPromptEventPayload {
25
+ questions: ReadonlyArray<AskUserPromptQuestion>;
26
+ }
27
+
28
+ export interface AskUserPromptQuestion {
29
+ /** The full question text, exactly as the agent authored it. */
30
+ question: string;
31
+ /** The short chip/tag shown next to the question. */
32
+ header: string;
33
+ /** True iff the user may pick multiple options. Normalized from optional. */
34
+ multiSelect: boolean;
35
+ options: ReadonlyArray<AskUserPromptOption>;
36
+ }
37
+
38
+ export interface AskUserPromptOption {
39
+ label: string;
40
+ description: string;
41
+ /** True iff the option carries rich preview content (content not shipped). */
42
+ hasPreview: boolean;
43
+ }
package/index.ts CHANGED
@@ -37,6 +37,13 @@ try {
37
37
  // SDK absent — extension still loads with English-only UI.
38
38
  }
39
39
 
40
+ export {
41
+ ASK_USER_PROMPT_EVENT,
42
+ type AskUserPromptEventPayload,
43
+ type AskUserPromptOption,
44
+ type AskUserPromptQuestion,
45
+ } from "./events.js";
46
+
40
47
  export default function (pi: ExtensionAPI) {
41
48
  registerAskUserQuestionTool(pi);
42
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "1.12.0",
3
+ "version": "1.14.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",
@@ -8,6 +8,10 @@
8
8
  "rpiv"
9
9
  ],
10
10
  "type": "module",
11
+ "exports": {
12
+ ".": "./index.ts",
13
+ "./events": "./events.ts"
14
+ },
11
15
  "license": "MIT",
12
16
  "author": "juicesharp",
13
17
  "repository": {
@@ -28,6 +32,7 @@
28
32
  "files": [
29
33
  "ask-user-question.ts",
30
34
  "config.ts",
35
+ "events.ts",
31
36
  "index.ts",
32
37
  "LICENSE",
33
38
  "locales/",
@@ -82,6 +87,6 @@
82
87
  }
83
88
  },
84
89
  "dependencies": {
85
- "@juicesharp/rpiv-config": "^1.12.0"
90
+ "@juicesharp/rpiv-config": "^1.14.0"
86
91
  }
87
92
  }