@agimon-ai/doompi-user-feedback 0.0.1-alpha.16 → 0.0.1-alpha.18

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 (79) hide show
  1. package/README.md +29 -18
  2. package/dist/_virtual/_rolldown/runtime.cjs +1 -0
  3. package/dist/adapters/config/configAdapter.cjs +2 -0
  4. package/dist/adapters/config/configAdapter.cjs.map +1 -0
  5. package/dist/adapters/config/configAdapter.mjs +2 -0
  6. package/dist/adapters/config/configAdapter.mjs.map +1 -0
  7. package/dist/adapters/doom/voiceQuestionHandoff.cjs +5 -0
  8. package/dist/adapters/doom/voiceQuestionHandoff.cjs.map +1 -0
  9. package/dist/adapters/doom/voiceQuestionHandoff.mjs +5 -0
  10. package/dist/adapters/doom/voiceQuestionHandoff.mjs.map +1 -0
  11. package/dist/adapters/pi/askUserQuestionAdapter.cjs +15 -0
  12. package/dist/adapters/pi/askUserQuestionAdapter.cjs.map +1 -0
  13. package/dist/adapters/pi/askUserQuestionAdapter.mjs +15 -0
  14. package/dist/adapters/pi/askUserQuestionAdapter.mjs.map +1 -0
  15. package/dist/adapters/pi/extension.cjs +2 -0
  16. package/dist/adapters/pi/extension.cjs.map +1 -0
  17. package/dist/adapters/pi/extension.d.cts +8 -0
  18. package/dist/adapters/pi/extension.d.cts.map +1 -0
  19. package/dist/adapters/pi/extension.d.mts +8 -0
  20. package/dist/adapters/pi/extension.d.mts.map +1 -0
  21. package/dist/adapters/pi/extension.mjs +2 -0
  22. package/dist/adapters/pi/extension.mjs.map +1 -0
  23. package/dist/adapters/pi/reconcileAdapter.cjs +2 -0
  24. package/dist/adapters/pi/reconcileAdapter.cjs.map +1 -0
  25. package/dist/adapters/pi/reconcileAdapter.mjs +2 -0
  26. package/dist/adapters/pi/reconcileAdapter.mjs.map +1 -0
  27. package/dist/adapters/pi/rpcQuestionnaireAdapter.cjs +2 -0
  28. package/dist/adapters/pi/rpcQuestionnaireAdapter.cjs.map +1 -0
  29. package/dist/adapters/pi/rpcQuestionnaireAdapter.mjs +2 -0
  30. package/dist/adapters/pi/rpcQuestionnaireAdapter.mjs.map +1 -0
  31. package/dist/extensions/pi.cjs +1 -0
  32. package/dist/extensions/pi.d.cts +2 -0
  33. package/dist/extensions/pi.d.mts +2 -0
  34. package/dist/extensions/pi.mjs +1 -0
  35. package/dist/index.cjs +0 -0
  36. package/dist/index.d.cts +3 -0
  37. package/dist/index.d.mts +3 -0
  38. package/dist/index.mjs +1 -0
  39. package/dist/schemas/questionnaire.cjs +2 -0
  40. package/dist/schemas/questionnaire.cjs.map +1 -0
  41. package/dist/schemas/questionnaire.d.cts +18 -0
  42. package/dist/schemas/questionnaire.d.cts.map +1 -0
  43. package/dist/schemas/questionnaire.d.mts +18 -0
  44. package/dist/schemas/questionnaire.d.mts.map +1 -0
  45. package/dist/schemas/questionnaire.mjs +2 -0
  46. package/dist/schemas/questionnaire.mjs.map +1 -0
  47. package/dist/services/questionnaireCoordinator.cjs +2 -0
  48. package/dist/services/questionnaireCoordinator.cjs.map +1 -0
  49. package/dist/services/questionnaireCoordinator.mjs +2 -0
  50. package/dist/services/questionnaireCoordinator.mjs.map +1 -0
  51. package/dist/services/responseService.cjs +2 -0
  52. package/dist/services/responseService.cjs.map +1 -0
  53. package/dist/services/responseService.mjs +2 -0
  54. package/dist/services/responseService.mjs.map +1 -0
  55. package/dist/services/validationService.cjs +2 -0
  56. package/dist/services/validationService.cjs.map +1 -0
  57. package/dist/services/validationService.mjs +2 -0
  58. package/dist/services/validationService.mjs.map +1 -0
  59. package/dist/services/voiceQuestionNarration.cjs +2 -0
  60. package/dist/services/voiceQuestionNarration.cjs.map +1 -0
  61. package/dist/services/voiceQuestionNarration.mjs +2 -0
  62. package/dist/services/voiceQuestionNarration.mjs.map +1 -0
  63. package/dist/tui/externalEditor.cjs +2 -0
  64. package/dist/tui/externalEditor.cjs.map +1 -0
  65. package/dist/tui/externalEditor.mjs +2 -0
  66. package/dist/tui/externalEditor.mjs.map +1 -0
  67. package/dist/tui/questionnaireComponent.cjs +2 -0
  68. package/dist/tui/questionnaireComponent.cjs.map +1 -0
  69. package/dist/tui/questionnaireComponent.mjs +2 -0
  70. package/dist/tui/questionnaireComponent.mjs.map +1 -0
  71. package/dist/tui/runQuestionnaire.cjs +2 -0
  72. package/dist/tui/runQuestionnaire.cjs.map +1 -0
  73. package/dist/tui/runQuestionnaire.mjs +2 -0
  74. package/dist/tui/runQuestionnaire.mjs.map +1 -0
  75. package/dist/types/questionnaire.d.cts +31 -0
  76. package/dist/types/questionnaire.d.cts.map +1 -0
  77. package/dist/types/questionnaire.d.mts +31 -0
  78. package/dist/types/questionnaire.d.mts.map +1 -0
  79. package/package.json +8 -8
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # @agimon-ai/doompi-user-feedback
2
2
 
3
- Structured, blocking user questions for Pi, with an autonomous Voice handoff.
3
+ Structured user questions that wait for an answer in interactive Pi sessions, with an autonomous
4
+ Voice handoff.
4
5
 
5
6
  Part of the [DoomPi distribution](https://www.npmjs.com/package/@agimon-ai/doompi).
6
7
 
7
- The `ask_user_question` tool presents concrete options instead of asking the model to continue on a guess.
8
+ The `ask_user_question` tool presents concrete options instead of asking the model to continue on a
9
+ guess.
8
10
 
9
11
  > **Alpha:** tool and Voice-handoff contracts may change between releases.
10
12
 
@@ -15,7 +17,8 @@ The `ask_user_question` tool presents concrete options instead of asking the mod
15
17
 
16
18
  ## Install
17
19
 
18
- Add the package to a DoomPi layer. DoomPi preserves authored layer and package occurrence order, while activating this package once per canonical resolved path:
20
+ Add the package to a DoomPi layer. DoomPi preserves authored layer and package occurrence order,
21
+ while activating this package once per canonical resolved path:
19
22
 
20
23
  ```yaml
21
24
  layers:
@@ -29,7 +32,8 @@ For standalone Pi:
29
32
  pi install npm:@agimon-ai/doompi-user-feedback
30
33
  ```
31
34
 
32
- Pi discovers the sole factory through `package.json.pi.extensions`. Each factory invocation joins the runner-scoped Cordis host, mounts one package plugin fiber, and disposes that fiber before releasing its host lease on shutdown.
35
+ Pi loads the package through `package.json.pi.extensions`. Each factory invocation owns one package
36
+ instance. Session replacement resets its state, and shutdown removes its registrations.
33
37
 
34
38
  ## Ask a question
35
39
 
@@ -55,32 +59,39 @@ Pi discovers the sole factory through `package.json.pi.extensions`. Each factory
55
59
  }
56
60
  ```
57
61
 
58
- A call accepts 1–4 questions. Each question requires 2–4 options. Headers are at most 16 characters; option labels are at most 60 characters. Use `multiSelect: true` when several choices are valid. An option can include a Markdown `preview` for meaningful visual comparison.
62
+ A call accepts 1 to 4 questions. Each question requires 2 to 4 options. Headers are at most 16
63
+ characters; option labels are at most 60 characters. Use `multiSelect: true` when several choices
64
+ are valid. An option can include a Markdown `preview` for meaningful visual comparison.
59
65
 
60
- The tool result contains readable answer text plus structured `details.answers`; cancellation sets `cancelled: true`. Pressing Escape declines the questionnaire. Do not add an `Other` option because the UI supplies a custom-text row.
66
+ The tool result contains readable answer text plus structured `details.answers`; cancellation sets
67
+ `cancelled: true`. Pressing Escape declines the questionnaire. Do not add an `Other` option because
68
+ the UI supplies a custom-text row.
61
69
 
62
70
  ## UI, RPC, and headless behavior
63
71
 
64
- The tool requires an interactive UI. It uses the TUI questionnaire when available and can use Pi's dialog/RPC UI bridge. A truly headless context returns a structured `no_ui` cancellation rather than waiting forever.
72
+ The tool requires an interactive UI. It uses the TUI questionnaire when available and can use Pi's
73
+ dialog or RPC UI bridge. A headless context without either UI returns a structured `no_ui`
74
+ cancellation rather than waiting forever.
65
75
 
66
- Questionnaires are coordinated one at a time. Cancellation, session replacement, or shutdown aborts the active prompt and settles queued work.
76
+ Questionnaires are coordinated one at a time. Cancellation, session replacement, or shutdown
77
+ aborts the active prompt and settles queued work.
67
78
 
68
79
  ## Autonomous Voice handoff
69
80
 
70
- When autonomous Voice mode is active, the extension formats the questions as plain text, requests narration, and returns `terminate: true`. The current turn ends while waiting; the next spoken answer arrives as a normal user message rather than a synthetic questionnaire selection.
81
+ When autonomous Voice mode is active, the extension formats the questions as plain text, requests
82
+ narration, and returns `terminate: true`. The current turn ends while waiting; the next spoken
83
+ answer arrives as a normal user message rather than a synthetic questionnaire selection.
71
84
 
72
- The handoff reacts to the shared `doom/minor-mode-catalog` and `doom/narration`
73
- Cordis services. If either provider unloads, user-feedback immediately falls
74
- back to its interactive questionnaire without retaining the old provider.
85
+ The handoff uses the shared `doom/minor-mode-catalog` and `doom/narration` Cordis services. If either
86
+ provider unloads, User Feedback immediately falls back to its interactive questionnaire without
87
+ retaining the old provider.
75
88
 
76
89
  ## Public API
77
90
 
78
- Question and result types are available from the package root. Cross-extension
79
- ask-user events and Voice services are owned by
80
- `@agimon-ai/doompi-extension-contracts`; consumers should inject or subscribe
81
- to those Cordis contracts. The only Pi-loaded factory is the default export of
82
- `/extensions/pi`; package installation should use Pi's package metadata rather
83
- than calling a registration function.
91
+ Question and result types are available from the package root. Cross-extension ask-user events and
92
+ Voice services come from `@agimon-ai/doompi-extension-contracts`; consumers should use those Cordis
93
+ contracts. Pi loads the default export of `/extensions/pi` through package metadata, so installation
94
+ does not require a manual registration call.
84
95
 
85
96
  ## Development
86
97
 
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));exports.__toESM=s;
@@ -0,0 +1,2 @@
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:fs");t=e.__toESM(t,1);let n=require("node:os");n=e.__toESM(n,1);let r=require("node:path");r=e.__toESM(r,1);const i=`ctrl+]`;function a(e){let t=e.XDG_CONFIG_HOME?.trim()||r.default.join(n.default.homedir(),`.config`);return r.default.join(t,`rpiv-ask-user-question`,`config.json`)}function o(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function s(e=process.env){let n=a(e);if(!t.default.existsSync(n))return{};try{let e=JSON.parse(t.default.readFileSync(n,`utf8`));if(!o(e))return{};let r=o(e.guidance)?e.guidance:void 0,i=r?{...typeof r.promptSnippet==`string`?{promptSnippet:r.promptSnippet}:{},...Array.isArray(r.promptGuidelines)&&r.promptGuidelines.every(e=>typeof e==`string`)?{promptGuidelines:r.promptGuidelines}:{}}:void 0;return{...typeof e.collapseKey==`string`?{collapseKey:e.collapseKey}:{},...i?{guidance:i}:{}}}catch{return{}}}function c(e){let t=e.collapseKey?.trim().toLowerCase();return t?t===`off`?`off`:/^[a-z0-9_+\-\]{}]+$/u.test(t)?t:i:i}exports.DEFAULT_COLLAPSE_KEY=i,exports.loadUserFeedbackConfig=s,exports.resolveCollapseKey=c;
2
+ //# sourceMappingURL=configAdapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configAdapter.cjs","names":["path","os","fs"],"sources":["../../../src/adapters/config/configAdapter.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const DEFAULT_COLLAPSE_KEY = 'ctrl+]';\nexport const COLLAPSE_KEY_OFF = 'off';\n\nexport interface GuidanceConfig {\n promptSnippet?: string;\n promptGuidelines?: string[];\n}\n\nexport interface UserFeedbackConfig {\n collapseKey?: string;\n guidance?: GuidanceConfig;\n}\n\nfunction legacyConfigPath(environment: NodeJS.ProcessEnv): string {\n const configRoot = environment.XDG_CONFIG_HOME?.trim() || path.join(os.homedir(), '.config');\n return path.join(configRoot, 'rpiv-ask-user-question', 'config.json');\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function loadUserFeedbackConfig(environment: NodeJS.ProcessEnv = process.env): UserFeedbackConfig {\n const filePath = legacyConfigPath(environment);\n if (!fs.existsSync(filePath)) return {};\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(filePath, 'utf8'));\n if (!isRecord(parsed)) return {};\n const rawGuidance = isRecord(parsed.guidance) ? parsed.guidance : undefined;\n const guidance = rawGuidance\n ? {\n ...(typeof rawGuidance.promptSnippet === 'string' ? { promptSnippet: rawGuidance.promptSnippet } : {}),\n ...(Array.isArray(rawGuidance.promptGuidelines) &&\n rawGuidance.promptGuidelines.every((item) => typeof item === 'string')\n ? { promptGuidelines: rawGuidance.promptGuidelines as string[] }\n : {}),\n }\n : undefined;\n return {\n ...(typeof parsed.collapseKey === 'string' ? { collapseKey: parsed.collapseKey } : {}),\n ...(guidance ? { guidance } : {}),\n };\n } catch {\n return {};\n }\n}\n\nexport function resolveCollapseKey(config: UserFeedbackConfig): string {\n const value = config.collapseKey?.trim().toLowerCase();\n if (!value) return DEFAULT_COLLAPSE_KEY;\n if (value === COLLAPSE_KEY_OFF) return COLLAPSE_KEY_OFF;\n return /^[a-z0-9_+\\-\\]{}]+$/u.test(value) ? value : DEFAULT_COLLAPSE_KEY;\n}\n"],"mappings":"wLAIA,MAAa,EAAuB,SAapC,SAAS,EAAiB,EAAwC,CAChE,IAAM,EAAa,EAAY,iBAAiB,KAAK,GAAKA,EAAAA,QAAK,KAAKC,EAAAA,QAAG,QAAQ,EAAG,SAAS,EAC3F,OAAOD,EAAAA,QAAK,KAAK,EAAY,yBAA0B,aAAa,CACtE,CAEA,SAAS,EAAS,EAAkD,CAClE,OAAO,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,CAAK,CAC5E,CAEA,SAAgB,EAAuB,EAAiC,QAAQ,IAAyB,CACvG,IAAM,EAAW,EAAiB,CAAW,EAC7C,GAAI,CAACE,EAAAA,QAAG,WAAW,CAAQ,EAAG,MAAO,CAAC,EACtC,GAAI,CACF,IAAM,EAAkB,KAAK,MAAMA,EAAAA,QAAG,aAAa,EAAU,MAAM,CAAC,EACpE,GAAI,CAAC,EAAS,CAAM,EAAG,MAAO,CAAC,EAC/B,IAAM,EAAc,EAAS,EAAO,QAAQ,EAAI,EAAO,SAAW,IAAA,GAC5D,EAAW,EACb,CACE,GAAI,OAAO,EAAY,eAAkB,SAAW,CAAE,cAAe,EAAY,aAAc,EAAI,CAAC,EACpG,GAAI,MAAM,QAAQ,EAAY,gBAAgB,GAC9C,EAAY,iBAAiB,MAAO,GAAS,OAAO,GAAS,QAAQ,EACjE,CAAE,iBAAkB,EAAY,gBAA6B,EAC7D,CAAC,CACP,EACA,IAAA,GACJ,MAAO,CACL,GAAI,OAAO,EAAO,aAAgB,SAAW,CAAE,YAAa,EAAO,WAAY,EAAI,CAAC,EACpF,GAAI,EAAW,CAAE,UAAS,EAAI,CAAC,CACjC,CACF,MAAQ,CACN,MAAO,CAAC,CACV,CACF,CAEA,SAAgB,EAAmB,EAAoC,CACrE,IAAM,EAAQ,EAAO,aAAa,KAAK,CAAC,CAAC,YAAY,EAGrD,OAFK,EACD,IAAA,MAA4B,MACzB,uBAAuB,KAAK,CAAK,EAAI,EAAQ,EAFjC,CAGrB"}
@@ -0,0 +1,2 @@
1
+ import e from"node:fs";import t from"node:os";import n from"node:path";const r=`ctrl+]`;function i(e){let r=e.XDG_CONFIG_HOME?.trim()||n.join(t.homedir(),`.config`);return n.join(r,`rpiv-ask-user-question`,`config.json`)}function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function o(t=process.env){let n=i(t);if(!e.existsSync(n))return{};try{let t=JSON.parse(e.readFileSync(n,`utf8`));if(!a(t))return{};let r=a(t.guidance)?t.guidance:void 0,i=r?{...typeof r.promptSnippet==`string`?{promptSnippet:r.promptSnippet}:{},...Array.isArray(r.promptGuidelines)&&r.promptGuidelines.every(e=>typeof e==`string`)?{promptGuidelines:r.promptGuidelines}:{}}:void 0;return{...typeof t.collapseKey==`string`?{collapseKey:t.collapseKey}:{},...i?{guidance:i}:{}}}catch{return{}}}function s(e){let t=e.collapseKey?.trim().toLowerCase();return t?t===`off`?`off`:/^[a-z0-9_+\-\]{}]+$/u.test(t)?t:r:r}export{r as DEFAULT_COLLAPSE_KEY,o as loadUserFeedbackConfig,s as resolveCollapseKey};
2
+ //# sourceMappingURL=configAdapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configAdapter.mjs","names":[],"sources":["../../../src/adapters/config/configAdapter.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const DEFAULT_COLLAPSE_KEY = 'ctrl+]';\nexport const COLLAPSE_KEY_OFF = 'off';\n\nexport interface GuidanceConfig {\n promptSnippet?: string;\n promptGuidelines?: string[];\n}\n\nexport interface UserFeedbackConfig {\n collapseKey?: string;\n guidance?: GuidanceConfig;\n}\n\nfunction legacyConfigPath(environment: NodeJS.ProcessEnv): string {\n const configRoot = environment.XDG_CONFIG_HOME?.trim() || path.join(os.homedir(), '.config');\n return path.join(configRoot, 'rpiv-ask-user-question', 'config.json');\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function loadUserFeedbackConfig(environment: NodeJS.ProcessEnv = process.env): UserFeedbackConfig {\n const filePath = legacyConfigPath(environment);\n if (!fs.existsSync(filePath)) return {};\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(filePath, 'utf8'));\n if (!isRecord(parsed)) return {};\n const rawGuidance = isRecord(parsed.guidance) ? parsed.guidance : undefined;\n const guidance = rawGuidance\n ? {\n ...(typeof rawGuidance.promptSnippet === 'string' ? { promptSnippet: rawGuidance.promptSnippet } : {}),\n ...(Array.isArray(rawGuidance.promptGuidelines) &&\n rawGuidance.promptGuidelines.every((item) => typeof item === 'string')\n ? { promptGuidelines: rawGuidance.promptGuidelines as string[] }\n : {}),\n }\n : undefined;\n return {\n ...(typeof parsed.collapseKey === 'string' ? { collapseKey: parsed.collapseKey } : {}),\n ...(guidance ? { guidance } : {}),\n };\n } catch {\n return {};\n }\n}\n\nexport function resolveCollapseKey(config: UserFeedbackConfig): string {\n const value = config.collapseKey?.trim().toLowerCase();\n if (!value) return DEFAULT_COLLAPSE_KEY;\n if (value === COLLAPSE_KEY_OFF) return COLLAPSE_KEY_OFF;\n return /^[a-z0-9_+\\-\\]{}]+$/u.test(value) ? value : DEFAULT_COLLAPSE_KEY;\n}\n"],"mappings":"uEAIA,MAAa,EAAuB,SAapC,SAAS,EAAiB,EAAwC,CAChE,IAAM,EAAa,EAAY,iBAAiB,KAAK,GAAK,EAAK,KAAK,EAAG,QAAQ,EAAG,SAAS,EAC3F,OAAO,EAAK,KAAK,EAAY,yBAA0B,aAAa,CACtE,CAEA,SAAS,EAAS,EAAkD,CAClE,OAAO,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,CAAK,CAC5E,CAEA,SAAgB,EAAuB,EAAiC,QAAQ,IAAyB,CACvG,IAAM,EAAW,EAAiB,CAAW,EAC7C,GAAI,CAAC,EAAG,WAAW,CAAQ,EAAG,MAAO,CAAC,EACtC,GAAI,CACF,IAAM,EAAkB,KAAK,MAAM,EAAG,aAAa,EAAU,MAAM,CAAC,EACpE,GAAI,CAAC,EAAS,CAAM,EAAG,MAAO,CAAC,EAC/B,IAAM,EAAc,EAAS,EAAO,QAAQ,EAAI,EAAO,SAAW,IAAA,GAC5D,EAAW,EACb,CACE,GAAI,OAAO,EAAY,eAAkB,SAAW,CAAE,cAAe,EAAY,aAAc,EAAI,CAAC,EACpG,GAAI,MAAM,QAAQ,EAAY,gBAAgB,GAC9C,EAAY,iBAAiB,MAAO,GAAS,OAAO,GAAS,QAAQ,EACjE,CAAE,iBAAkB,EAAY,gBAA6B,EAC7D,CAAC,CACP,EACA,IAAA,GACJ,MAAO,CACL,GAAI,OAAO,EAAO,aAAgB,SAAW,CAAE,YAAa,EAAO,WAAY,EAAI,CAAC,EACpF,GAAI,EAAW,CAAE,UAAS,EAAI,CAAC,CACjC,CACF,MAAQ,CACN,MAAO,CAAC,CACV,CACF,CAEA,SAAgB,EAAmB,EAAoC,CACrE,IAAM,EAAQ,EAAO,aAAa,KAAK,CAAC,CAAC,YAAY,EAGrD,OAFK,EACD,IAAA,MAA4B,MACzB,uBAAuB,KAAK,CAAK,EAAI,EAAQ,EAFjC,CAGrB"}
@@ -0,0 +1,5 @@
1
+ const e=require("../../services/voiceQuestionNarration.cjs");let t=require("@agimon-ai/doompi-extension-contracts/narration");const n=`The questions were spoken through autonomous voice. Stop now and wait for the user's next message; it will arrive as an ordinary user message.`;function r(e){return e.descriptor.source===t.DOOM_VOICE_SOURCE&&e.descriptor.id===t.DOOM_VOICE_AUTO_MODE_ID&&e.state.activation===`active`}function i(e){let t=e.questions.length>1;return e.questions.map((e,n)=>[`${t?`${n+1}. `:``}${e.question}${e.multiSelect?` (Select all that apply.)`:``}`,...e.options.map((e,t)=>` ${t+1}. ${e.label}`),` Type something.`].join(`
2
+ `)).join(`
3
+
4
+ `)}var a=class{modes;narration;buildNarration;constructor(t,n,r=e.buildVoiceQuestionNarration){this.modes=t,this.narration=n,this.buildNarration=r}async handoff(e){if(!this.modes.list().some(r))return;let n=(0,t.createNarrationRequest)(this.buildNarration(e));if(n)return await this.narration.request(n),{answers:[],cancelled:!1,delivery:`voice`,awaitingResponse:!0,voicePrompt:i(e)}}};function o(e,t){return new a(e,t)}function s(e){let t=e.voicePrompt?.trim();return{content:[{type:`text`,text:t?`${t}\n\n${n}`:n}],details:e,terminate:!0}}exports.VOICE_WAIT_MESSAGE=n,exports.VoiceQuestionHandoff=a,exports.buildVoiceToolResult=s,exports.createVoiceQuestionHandoff=o,exports.formatVoiceQuestionPrompt=i;
5
+ //# sourceMappingURL=voiceQuestionHandoff.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voiceQuestionHandoff.cjs","names":["DOOM_VOICE_SOURCE","DOOM_VOICE_AUTO_MODE_ID","buildVoiceQuestionNarration","createNarrationRequest"],"sources":["../../../src/adapters/doom/voiceQuestionHandoff.ts"],"sourcesContent":["import type { MinorModeCatalogService, MinorModeRecord } from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n createNarrationRequest,\n type DoomNarrationService,\n DOOM_VOICE_AUTO_MODE_ID,\n DOOM_VOICE_SOURCE,\n} from '@agimon-ai/doompi-extension-contracts/narration';\nimport type { QuestionParams } from '../../schemas/questionnaire.js';\nimport { buildVoiceQuestionNarration } from '../../services/voiceQuestionNarration.js';\nimport type { QuestionnaireResult, ToolTextResult } from '../../types/questionnaire.js';\n\nexport const VOICE_WAIT_MESSAGE =\n \"The questions were spoken through autonomous voice. Stop now and wait for the user's next message; it will arrive as an ordinary user message.\";\n\nfunction isAutonomousVoice(record: MinorModeRecord): boolean {\n return (\n record.descriptor.source === DOOM_VOICE_SOURCE &&\n record.descriptor.id === DOOM_VOICE_AUTO_MODE_ID &&\n record.state.activation === 'active'\n );\n}\n\nexport function formatVoiceQuestionPrompt(params: QuestionParams): string {\n const numberQuestions = params.questions.length > 1;\n return params.questions\n .map((question, questionIndex) => {\n const heading = `${numberQuestions ? `${questionIndex + 1}. ` : ''}${question.question}${question.multiSelect ? ' (Select all that apply.)' : ''}`;\n const options = question.options.map((option, optionIndex) => ` ${optionIndex + 1}. ${option.label}`);\n return [heading, ...options, ' Type something.'].join('\\n');\n })\n .join('\\n\\n');\n}\n\nexport class VoiceQuestionHandoff {\n constructor(\n private readonly modes: Pick<MinorModeCatalogService, 'list'>,\n private readonly narration: Pick<DoomNarrationService, 'request'>,\n private readonly buildNarration: (params: QuestionParams) => string = buildVoiceQuestionNarration,\n ) {}\n\n async handoff(params: QuestionParams): Promise<QuestionnaireResult | undefined> {\n if (!this.modes.list().some(isAutonomousVoice)) return undefined;\n const narration = createNarrationRequest(this.buildNarration(params));\n if (!narration) return undefined;\n await this.narration.request(narration);\n return {\n answers: [],\n cancelled: false,\n delivery: 'voice',\n awaitingResponse: true,\n voicePrompt: formatVoiceQuestionPrompt(params),\n };\n }\n}\n\n/** Create a handoff from services whose lifecycle is owned by a Cordis injection. */\nexport function createVoiceQuestionHandoff(\n modes: Pick<MinorModeCatalogService, 'list'>,\n narration: Pick<DoomNarrationService, 'request'>,\n): VoiceQuestionHandoff {\n return new VoiceQuestionHandoff(modes, narration);\n}\n\nexport function buildVoiceToolResult(details: QuestionnaireResult): ToolTextResult {\n const prompt = details.voicePrompt?.trim();\n return {\n content: [{ type: 'text', text: prompt ? `${prompt}\\n\\n${VOICE_WAIT_MESSAGE}` : VOICE_WAIT_MESSAGE }],\n details,\n terminate: true,\n };\n}\n"],"mappings":"8HAWA,MAAa,EACX,iJAEF,SAAS,EAAkB,EAAkC,CAC3D,OACE,EAAO,WAAW,SAAWA,EAAAA,mBAC7B,EAAO,WAAW,KAAOC,EAAAA,yBACzB,EAAO,MAAM,aAAe,QAEhC,CAEA,SAAgB,EAA0B,EAAgC,CACxE,IAAM,EAAkB,EAAO,UAAU,OAAS,EAClD,OAAO,EAAO,UACX,KAAK,EAAU,IAGP,CAAC,GAFW,EAAkB,GAAG,EAAgB,EAAE,IAAM,KAAK,EAAS,WAAW,EAAS,YAAc,4BAA8B,KAE7H,GADD,EAAS,QAAQ,KAAK,EAAQ,IAAgB,KAAK,EAAc,EAAE,IAAI,EAAO,OACpE,EAAG,mBAAmB,CAAC,CAAC,KAAK;CAAI,CAC5D,CAAC,CACD,KAAK;;CAAM,CAChB,CAEA,IAAa,EAAb,KAAkC,CAEb,MACA,UACA,eAHnB,YACE,EACA,EACA,EAAsEC,EAAAA,4BACtE,CAHiB,KAAA,MAAA,EACA,KAAA,UAAA,EACA,KAAA,eAAA,CAChB,CAEH,MAAM,QAAQ,EAAkE,CAC9E,GAAI,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,KAAK,CAAiB,EAAG,OAChD,IAAM,GAAA,EAAYC,EAAAA,uBAAAA,CAAuB,KAAK,eAAe,CAAM,CAAC,EAC/D,KAEL,OADA,MAAM,KAAK,UAAU,QAAQ,CAAS,EAC/B,CACL,QAAS,CAAC,EACV,UAAW,GACX,SAAU,QACV,iBAAkB,GAClB,YAAa,EAA0B,CAAM,CAC/C,CACF,CACF,EAGA,SAAgB,EACd,EACA,EACsB,CACtB,OAAO,IAAI,EAAqB,EAAO,CAAS,CAClD,CAEA,SAAgB,EAAqB,EAA8C,CACjF,IAAM,EAAS,EAAQ,aAAa,KAAK,EACzC,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAS,GAAG,EAAO,MAAM,IAAuB,CAAmB,CAAC,EACpG,UACA,UAAW,EACb,CACF"}
@@ -0,0 +1,5 @@
1
+ import{buildVoiceQuestionNarration as e}from"../../services/voiceQuestionNarration.mjs";import{DOOM_VOICE_AUTO_MODE_ID as t,DOOM_VOICE_SOURCE as n,createNarrationRequest as r}from"@agimon-ai/doompi-extension-contracts/narration";const i=`The questions were spoken through autonomous voice. Stop now and wait for the user's next message; it will arrive as an ordinary user message.`;function a(e){return e.descriptor.source===n&&e.descriptor.id===t&&e.state.activation===`active`}function o(e){let t=e.questions.length>1;return e.questions.map((e,n)=>[`${t?`${n+1}. `:``}${e.question}${e.multiSelect?` (Select all that apply.)`:``}`,...e.options.map((e,t)=>` ${t+1}. ${e.label}`),` Type something.`].join(`
2
+ `)).join(`
3
+
4
+ `)}var s=class{modes;narration;buildNarration;constructor(t,n,r=e){this.modes=t,this.narration=n,this.buildNarration=r}async handoff(e){if(!this.modes.list().some(a))return;let t=r(this.buildNarration(e));if(t)return await this.narration.request(t),{answers:[],cancelled:!1,delivery:`voice`,awaitingResponse:!0,voicePrompt:o(e)}}};function c(e,t){return new s(e,t)}function l(e){let t=e.voicePrompt?.trim();return{content:[{type:`text`,text:t?`${t}\n\n${i}`:i}],details:e,terminate:!0}}export{i as VOICE_WAIT_MESSAGE,s as VoiceQuestionHandoff,l as buildVoiceToolResult,c as createVoiceQuestionHandoff,o as formatVoiceQuestionPrompt};
5
+ //# sourceMappingURL=voiceQuestionHandoff.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voiceQuestionHandoff.mjs","names":[],"sources":["../../../src/adapters/doom/voiceQuestionHandoff.ts"],"sourcesContent":["import type { MinorModeCatalogService, MinorModeRecord } from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n createNarrationRequest,\n type DoomNarrationService,\n DOOM_VOICE_AUTO_MODE_ID,\n DOOM_VOICE_SOURCE,\n} from '@agimon-ai/doompi-extension-contracts/narration';\nimport type { QuestionParams } from '../../schemas/questionnaire.js';\nimport { buildVoiceQuestionNarration } from '../../services/voiceQuestionNarration.js';\nimport type { QuestionnaireResult, ToolTextResult } from '../../types/questionnaire.js';\n\nexport const VOICE_WAIT_MESSAGE =\n \"The questions were spoken through autonomous voice. Stop now and wait for the user's next message; it will arrive as an ordinary user message.\";\n\nfunction isAutonomousVoice(record: MinorModeRecord): boolean {\n return (\n record.descriptor.source === DOOM_VOICE_SOURCE &&\n record.descriptor.id === DOOM_VOICE_AUTO_MODE_ID &&\n record.state.activation === 'active'\n );\n}\n\nexport function formatVoiceQuestionPrompt(params: QuestionParams): string {\n const numberQuestions = params.questions.length > 1;\n return params.questions\n .map((question, questionIndex) => {\n const heading = `${numberQuestions ? `${questionIndex + 1}. ` : ''}${question.question}${question.multiSelect ? ' (Select all that apply.)' : ''}`;\n const options = question.options.map((option, optionIndex) => ` ${optionIndex + 1}. ${option.label}`);\n return [heading, ...options, ' Type something.'].join('\\n');\n })\n .join('\\n\\n');\n}\n\nexport class VoiceQuestionHandoff {\n constructor(\n private readonly modes: Pick<MinorModeCatalogService, 'list'>,\n private readonly narration: Pick<DoomNarrationService, 'request'>,\n private readonly buildNarration: (params: QuestionParams) => string = buildVoiceQuestionNarration,\n ) {}\n\n async handoff(params: QuestionParams): Promise<QuestionnaireResult | undefined> {\n if (!this.modes.list().some(isAutonomousVoice)) return undefined;\n const narration = createNarrationRequest(this.buildNarration(params));\n if (!narration) return undefined;\n await this.narration.request(narration);\n return {\n answers: [],\n cancelled: false,\n delivery: 'voice',\n awaitingResponse: true,\n voicePrompt: formatVoiceQuestionPrompt(params),\n };\n }\n}\n\n/** Create a handoff from services whose lifecycle is owned by a Cordis injection. */\nexport function createVoiceQuestionHandoff(\n modes: Pick<MinorModeCatalogService, 'list'>,\n narration: Pick<DoomNarrationService, 'request'>,\n): VoiceQuestionHandoff {\n return new VoiceQuestionHandoff(modes, narration);\n}\n\nexport function buildVoiceToolResult(details: QuestionnaireResult): ToolTextResult {\n const prompt = details.voicePrompt?.trim();\n return {\n content: [{ type: 'text', text: prompt ? `${prompt}\\n\\n${VOICE_WAIT_MESSAGE}` : VOICE_WAIT_MESSAGE }],\n details,\n terminate: true,\n };\n}\n"],"mappings":"qOAWA,MAAa,EACX,iJAEF,SAAS,EAAkB,EAAkC,CAC3D,OACE,EAAO,WAAW,SAAW,GAC7B,EAAO,WAAW,KAAO,GACzB,EAAO,MAAM,aAAe,QAEhC,CAEA,SAAgB,EAA0B,EAAgC,CACxE,IAAM,EAAkB,EAAO,UAAU,OAAS,EAClD,OAAO,EAAO,UACX,KAAK,EAAU,IAGP,CAAC,GAFW,EAAkB,GAAG,EAAgB,EAAE,IAAM,KAAK,EAAS,WAAW,EAAS,YAAc,4BAA8B,KAE7H,GADD,EAAS,QAAQ,KAAK,EAAQ,IAAgB,KAAK,EAAc,EAAE,IAAI,EAAO,OACpE,EAAG,mBAAmB,CAAC,CAAC,KAAK;CAAI,CAC5D,CAAC,CACD,KAAK;;CAAM,CAChB,CAEA,IAAa,EAAb,KAAkC,CAEb,MACA,UACA,eAHnB,YACE,EACA,EACA,EAAsE,EACtE,CAHiB,KAAA,MAAA,EACA,KAAA,UAAA,EACA,KAAA,eAAA,CAChB,CAEH,MAAM,QAAQ,EAAkE,CAC9E,GAAI,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,KAAK,CAAiB,EAAG,OAChD,IAAM,EAAY,EAAuB,KAAK,eAAe,CAAM,CAAC,EAC/D,KAEL,OADA,MAAM,KAAK,UAAU,QAAQ,CAAS,EAC/B,CACL,QAAS,CAAC,EACV,UAAW,GACX,SAAU,QACV,iBAAkB,GAClB,YAAa,EAA0B,CAAM,CAC/C,CACF,CACF,EAGA,SAAgB,EACd,EACA,EACsB,CACtB,OAAO,IAAI,EAAqB,EAAO,CAAS,CAClD,CAEA,SAAgB,EAAqB,EAA8C,CACjF,IAAM,EAAS,EAAQ,aAAa,KAAK,EACzC,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAS,GAAG,EAAO,MAAM,IAAuB,CAAmB,CAAC,EACpG,UACA,UAAW,EACb,CACF"}
@@ -0,0 +1,15 @@
1
+ const e=require("../doom/voiceQuestionHandoff.cjs"),t=require("../../schemas/questionnaire.cjs"),n=require("../../services/responseService.cjs"),r=require("../../services/validationService.cjs"),i=require("../config/configAdapter.cjs"),a=require("./rpcQuestionnaireAdapter.cjs");let o=require("@agimon-ai/doompi-extension-contracts/ask-user"),s=require("@agimon-ai/doompi-ui/toolChrome");const c=`ask_user_question`,l=`Ask the user up to 4 structured questions (2-4 options each) when requirements are ambiguous`,u=[`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to 4 questions per invocation.`,`Each question MUST have 2-4 options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer via the automatically appended "Type something." row on every question, or press Esc to abandon the questionnaire. Do NOT author "Other" or "Type something." labels yourself — reserved labels are rejected at runtime.`,`Set multiSelect: true when multiple answers are valid. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. If you recommend a specific option, make that the first option and append "(Recommended)" to its label.`,`Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.`];function d(e,t){let n={questions:t.questions.map(e=>({question:e.question,header:e.header,multiSelect:e.multiSelect??!1,options:e.options.map(e=>({label:e.label,description:e.description,hasPreview:!!e.preview}))}))};e.emit(o.DOOM_ASK_USER_PROMPT_EVENT,n)}function f(e,t){let n={active:t};e.emit(o.DOOM_ASK_USER_BLOCKED_EVENT,n)}function p(e){let t=e.ui;return typeof t.select==`function`&&typeof t.input==`function`}function m(o,m,h){let g=i.loadUserFeedbackConfig().guidance;o.registerTool({name:c,label:`Ask User Question`,renderShell:`self`,description:`Ask the user one or more structured questions during execution. Use when you need to:
2
+ 1. Gather user preferences or requirements
3
+ 2. Clarify ambiguous instructions
4
+ 3. Get decisions on implementation choices as you work
5
+ 4. Offer choices to the user about what direction to take
6
+
7
+ Usage notes:
8
+ - Users can type a custom answer via the automatically appended "Type something." row on every question or press Esc to abandon the questionnaire. Do NOT author "Other" or "Type something." labels yourself — reserved labels are rejected at runtime.
9
+ - Use multiSelect: true when multiple answers are valid.
10
+ - If you recommend a specific option, make that the first option and add "(Recommended)" at the end of the label.
11
+
12
+ Preview feature:
13
+ Use the optional preview field for ASCII mockups, code snippets, diagrams, or configuration examples that users should compare visually. Do not use previews for simple preference questions.`,promptSnippet:g?.promptSnippet??l,promptGuidelines:g?.promptGuidelines??u,parameters:t.QuestionParamsSchema,executionMode:`sequential`,async execute(t,o,s,c,l){let u=o,g=e=>h.isActive?.(l,e)??!0,_=()=>({answers:[],cancelled:!0});if(!g(s))return n.buildToolResult(`Error: the questionnaire session is no longer active.`,_());if(!l.hasUI)return n.buildToolResult(`Error: UI not available (running in non-interactive mode)`,{answers:[],cancelled:!0,error:`no_ui`});let v=r.validateQuestionnaire(u);if(!v.ok)return n.buildToolResult(v.message,{answers:[],cancelled:!0,error:v.error});try{let t=await h.enqueue(async({signal:e,reportProgress:t})=>{if(!g(e))return _();d(m,u);let n=await h.tryVoice?.(u);if(n)return n;let r=!0,o=()=>{r&&(r=!1,g()&&f(m,!1))};e.addEventListener(`abort`,o,{once:!0}),f(m,!0);try{if(!g(e))return _();if(l.mode===`rpc`&&p(l)){let n=await a.runRpcQuestionnaire(l,u,e,t);return g(e)?n:_()}let n=await h.runTui(l,u,i.resolveCollapseKey(i.loadUserFeedbackConfig()),e,t);if(!g(e))return _();if(n!==void 0)return n;if(p(l)){let n=await a.runRpcQuestionnaire(l,u,e,t);return g(e)?n:_()}return{answers:[],cancelled:!0,error:`no_custom_ui`}}finally{e.removeEventListener(`abort`,o),o()}},s);return t.delivery===`voice`?e.buildVoiceToolResult(t):t.error===`no_custom_ui`?n.buildToolResult(`Error: this client cannot render the questionnaire (custom UI is unavailable). The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, without using this tool.`,t):n.buildQuestionnaireResponse(t,u)}catch(e){let t=e instanceof Error?e.message:String(e);return n.buildToolResult(`Error: the questionnaire UI failed to load. The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead. (cause: ${t})`,{answers:[],cancelled:!0,error:`session_load_failed`})}},renderCall(e,t){let n=e,r=n.questions.map(e=>e.header).join(`, `),i=`${n.questions.length} question${n.questions.length===1?``:`s`}`,a=(0,s.renderToolHeading)(`ask`,i,t);return new s.DoomToolCall(r?`${a} ${t.fg(`dim`,`(${r})`)}`:a)},renderResult(e,t,n,r){let i=e.details;if(!i){let t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
14
+ `),i=r.isError?`error`:`toolOutput`,a=r.isError?`✗ failed`:`✓ submitted`;return new s.DoomToolResult([n.fg(i,t||a)],n,{wrap:!0})}if(i.cancelled)return new s.DoomToolResult([n.fg(`warning`,`◐`)+n.fg(`dim`,` cancelled`)],n);if(i.delivery===`voice`&&i.voicePrompt)return new s.DoomToolResult([n.fg(`toolOutput`,i.voicePrompt)],n,{wrap:!0});let a=i.answers.map(e=>{let t=e.kind===`multi`?(e.selected??[]).join(`, `):e.answer;return`${n.fg(`success`,`✓`)} ${n.fg(`accent`,e.question)}: ${n.fg(`toolOutput`,t??``)}`});return a.length===0&&a.push(n.fg(`success`,`✓`)+n.fg(`dim`,` submitted`)),new s.DoomToolResult(a,n,{wrap:!0})}})}exports.ASK_USER_QUESTION_TOOL_NAME=c,exports.DEFAULT_PROMPT_GUIDELINES=u,exports.DEFAULT_PROMPT_SNIPPET=l,exports.registerAskUserQuestionTool=m;
15
+ //# sourceMappingURL=askUserQuestionAdapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"askUserQuestionAdapter.cjs","names":["DOOM_ASK_USER_PROMPT_EVENT","DOOM_ASK_USER_BLOCKED_EVENT","loadUserFeedbackConfig","QuestionParamsSchema","buildToolResult","validateQuestionnaire","runRpcQuestionnaire","resolveCollapseKey","buildVoiceToolResult","buildQuestionnaireResponse","renderToolHeading","DoomToolCall","DoomToolResult"],"sources":["../../../src/adapters/pi/askUserQuestionAdapter.ts"],"sourcesContent":["import {\n type AskUserBlockedEvent,\n type AskUserPromptEvent,\n DOOM_ASK_USER_BLOCKED_EVENT,\n DOOM_ASK_USER_PROMPT_EVENT,\n} from '@agimon-ai/doompi-extension-contracts/ask-user';\nimport { DoomToolCall, DoomToolResult, renderToolHeading } from '@agimon-ai/doompi-ui/toolChrome';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport {\n MAX_OPTIONS,\n MAX_QUESTIONS,\n MIN_OPTIONS,\n type QuestionParams,\n QuestionParamsSchema,\n} from '../../schemas/questionnaire.js';\nimport type { QuestionnaireRunner } from '../../services/questionnaireCoordinator.js';\nimport { buildQuestionnaireResponse, buildToolResult } from '../../services/responseService.js';\nimport { validateQuestionnaire } from '../../services/validationService.js';\nimport type { QuestionnaireResult } from '../../types/questionnaire.js';\nimport { loadUserFeedbackConfig, resolveCollapseKey } from '../config/configAdapter.js';\nimport { buildVoiceToolResult } from '../doom/voiceQuestionHandoff.js';\nimport { runRpcQuestionnaire } from './rpcQuestionnaireAdapter.js';\n\nexport const ASK_USER_QUESTION_TOOL_NAME = 'ask_user_question';\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES = [\n `Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n `Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer via the automatically appended \"Type something.\" row on every question, or press Esc to abandon the questionnaire. Do NOT author \"Other\" or \"Type something.\" labels yourself — reserved labels are rejected at runtime.`,\n 'Set multiSelect: true when multiple answers are valid. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. If you recommend a specific option, make that the first option and append \"(Recommended)\" to its label.',\n 'Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.',\n];\n\nconst ERROR_NO_UI = 'Error: UI not available (running in non-interactive mode)';\nconst ERROR_NO_CUSTOM_UI =\n 'Error: this client cannot render the questionnaire (custom UI is unavailable). The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, without using this tool.';\nconst ERROR_SESSION_LOAD_FAILED =\n 'Error: the questionnaire UI failed to load. The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead.';\nconst ERROR_SESSION_INACTIVE = 'Error: the questionnaire session is no longer active.';\n\nexport interface AskUserQuestionToolDependencies {\n enqueue: (runner: QuestionnaireRunner, signal?: AbortSignal) => Promise<QuestionnaireResult>;\n isActive?: (context: ExtensionContext, signal?: AbortSignal) => boolean;\n tryVoice?: (params: QuestionParams) => QuestionnaireResult | undefined | Promise<QuestionnaireResult | undefined>;\n runTui: (\n context: ExtensionContext,\n params: QuestionParams,\n collapseKey: string,\n signal?: AbortSignal,\n reportProgress?: (result: QuestionnaireResult) => void,\n ) => Promise<QuestionnaireResult | undefined>;\n}\n\nfunction emitPrompt(cordis: Context, params: QuestionParams): void {\n const payload: AskUserPromptEvent = {\n questions: params.questions.map((question) => ({\n question: question.question,\n header: question.header,\n multiSelect: question.multiSelect ?? false,\n options: question.options.map((option) => ({\n label: option.label,\n description: option.description,\n hasPreview: Boolean(option.preview),\n })),\n })),\n };\n cordis.emit(DOOM_ASK_USER_PROMPT_EVENT, payload);\n}\n\nfunction emitBlocked(cordis: Context, active: boolean): void {\n const payload: AskUserBlockedEvent = { active };\n cordis.emit(DOOM_ASK_USER_BLOCKED_EVENT, payload);\n}\n\nfunction hasDialogUI(context: ExtensionContext): boolean {\n const ui = context.ui as unknown as { select?: unknown; input?: unknown };\n return typeof ui.select === 'function' && typeof ui.input === 'function';\n}\n\nexport function registerAskUserQuestionTool(\n pi: ExtensionAPI,\n cordis: Context,\n dependencies: AskUserQuestionToolDependencies,\n): void {\n const configuredGuidance = loadUserFeedbackConfig().guidance;\n pi.registerTool({\n name: ASK_USER_QUESTION_TOOL_NAME,\n label: 'Ask User Question',\n renderShell: 'self',\n description: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users can type a custom answer via the automatically appended \"Type something.\" row on every question or press Esc to abandon the questionnaire. Do NOT author \"Other\" or \"Type something.\" labels yourself — reserved labels are rejected at runtime.\n- Use multiSelect: true when multiple answers are valid.\n- If you recommend a specific option, make that the first option and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional preview field for ASCII mockups, code snippets, diagrams, or configuration examples that users should compare visually. Do not use previews for simple preference questions.`,\n promptSnippet: configuredGuidance?.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n promptGuidelines: configuredGuidance?.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n parameters: QuestionParamsSchema,\n executionMode: 'sequential',\n\n async execute(_toolCallId, params, signal, _onUpdate, context) {\n const typed = params as QuestionParams;\n const isActive = (activeSignal?: AbortSignal): boolean => dependencies.isActive?.(context, activeSignal) ?? true;\n const cancelled = (): QuestionnaireResult => ({ answers: [], cancelled: true });\n if (!isActive(signal)) return buildToolResult(ERROR_SESSION_INACTIVE, cancelled());\n if (!context.hasUI) {\n return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: 'no_ui' });\n }\n\n const validation = validateQuestionnaire(typed);\n if (!validation.ok) {\n return buildToolResult(validation.message, {\n answers: [],\n cancelled: true,\n error: validation.error,\n });\n }\n\n try {\n const result = await dependencies.enqueue(async ({ signal: activeSignal, reportProgress }) => {\n if (!isActive(activeSignal)) return cancelled();\n emitPrompt(cordis, typed);\n const voiceResult = await dependencies.tryVoice?.(typed);\n if (voiceResult) return voiceResult;\n\n let blocked = true;\n const clearBlocked = (): void => {\n if (!blocked) return;\n blocked = false;\n if (isActive()) emitBlocked(cordis, false);\n };\n activeSignal.addEventListener('abort', clearBlocked, { once: true });\n emitBlocked(cordis, true);\n try {\n if (!isActive(activeSignal)) return cancelled();\n if (context.mode === 'rpc' && hasDialogUI(context)) {\n const rpcResult = await runRpcQuestionnaire(context, typed, activeSignal, reportProgress);\n return isActive(activeSignal) ? rpcResult : cancelled();\n }\n\n const tuiResult = await dependencies.runTui(\n context,\n typed,\n resolveCollapseKey(loadUserFeedbackConfig()),\n activeSignal,\n reportProgress,\n );\n if (!isActive(activeSignal)) return cancelled();\n if (tuiResult !== undefined) return tuiResult;\n if (hasDialogUI(context)) {\n const rpcResult = await runRpcQuestionnaire(context, typed, activeSignal, reportProgress);\n return isActive(activeSignal) ? rpcResult : cancelled();\n }\n return { answers: [], cancelled: true, error: 'no_custom_ui' };\n } finally {\n activeSignal.removeEventListener('abort', clearBlocked);\n clearBlocked();\n }\n }, signal);\n\n if (result.delivery === 'voice') return buildVoiceToolResult(result);\n if (result.error === 'no_custom_ui') return buildToolResult(ERROR_NO_CUSTOM_UI, result);\n return buildQuestionnaireResponse(result, typed);\n } catch (error) {\n const cause = error instanceof Error ? error.message : String(error);\n return buildToolResult(`${ERROR_SESSION_LOAD_FAILED} (cause: ${cause})`, {\n answers: [],\n cancelled: true,\n error: 'session_load_failed',\n });\n }\n },\n\n renderCall(args, theme) {\n const params = args as QuestionParams;\n const headers = params.questions.map((question) => question.header).join(', ');\n const count = `${params.questions.length} question${params.questions.length === 1 ? '' : 's'}`;\n const heading = renderToolHeading('ask', count, theme);\n return new DoomToolCall(headers ? `${heading} ${theme.fg('dim', `(${headers})`)}` : heading);\n },\n\n renderResult(result, _options, theme, context) {\n const details = result.details as QuestionnaireResult | undefined;\n if (!details) {\n const raw = result.content\n .filter((block) => block.type === 'text')\n .map((block) => block.text)\n .join('\\n');\n const color = context.isError ? 'error' : 'toolOutput';\n const fallback = context.isError ? '✗ failed' : '✓ submitted';\n return new DoomToolResult([theme.fg(color, raw || fallback)], theme, { wrap: true });\n }\n if (details.cancelled) {\n return new DoomToolResult([theme.fg('warning', '◐') + theme.fg('dim', ' cancelled')], theme);\n }\n if (details.delivery === 'voice' && details.voicePrompt) {\n return new DoomToolResult([theme.fg('toolOutput', details.voicePrompt)], theme, { wrap: true });\n }\n const lines = details.answers.map((answer) => {\n const scalar = answer.kind === 'multi' ? (answer.selected ?? []).join(', ') : answer.answer;\n return `${theme.fg('success', '✓')} ${theme.fg('accent', answer.question)}: ${theme.fg(\n 'toolOutput',\n scalar ?? '',\n )}`;\n });\n if (lines.length === 0) lines.push(theme.fg('success', '✓') + theme.fg('dim', ' submitted'));\n return new DoomToolResult(lines, theme, { wrap: true });\n },\n });\n}\n"],"mappings":"oYAwBA,MAAa,EAA8B,oBAE9B,EAAyB,+FACzB,EAA4B,CACvC,wKACA,uaACA,yUACA,kHACF,EAsBA,SAAS,EAAW,EAAiB,EAA8B,CACjE,IAAM,EAA8B,CAClC,UAAW,EAAO,UAAU,IAAK,IAAc,CAC7C,SAAU,EAAS,SACnB,OAAQ,EAAS,OACjB,YAAa,EAAS,aAAe,GACrC,QAAS,EAAS,QAAQ,IAAK,IAAY,CACzC,MAAO,EAAO,MACd,YAAa,EAAO,YACpB,WAAY,EAAQ,EAAO,OAC7B,EAAE,CACJ,EAAE,CACJ,EACA,EAAO,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,EAAO,QAAQ,EAAE,IAAI,EAAM,GAClF,aACA,GAAU,EACZ,GACF,CAAC,EAED,OADI,EAAM,SAAW,GAAG,EAAM,KAAK,EAAM,GAAG,UAAW,GAAG,EAAI,EAAM,GAAG,MAAO,YAAY,CAAC,EACpF,IAAIA,EAAAA,eAAe,EAAO,EAAO,CAAE,KAAM,EAAK,CAAC,CACxD,CACF,CAAC,CACH"}
@@ -0,0 +1,15 @@
1
+ import{buildVoiceToolResult as e}from"../doom/voiceQuestionHandoff.mjs";import{QuestionParamsSchema as t}from"../../schemas/questionnaire.mjs";import{buildQuestionnaireResponse as n,buildToolResult as r}from"../../services/responseService.mjs";import{validateQuestionnaire as i}from"../../services/validationService.mjs";import{loadUserFeedbackConfig as a,resolveCollapseKey as o}from"../config/configAdapter.mjs";import{runRpcQuestionnaire as s}from"./rpcQuestionnaireAdapter.mjs";import{DOOM_ASK_USER_BLOCKED_EVENT as c,DOOM_ASK_USER_PROMPT_EVENT as l}from"@agimon-ai/doompi-extension-contracts/ask-user";import{DoomToolCall as u,DoomToolResult as d,renderToolHeading as f}from"@agimon-ai/doompi-ui/toolChrome";const p=`ask_user_question`,m=`Ask the user up to 4 structured questions (2-4 options each) when requirements are ambiguous`,h=[`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to 4 questions per invocation.`,`Each question MUST have 2-4 options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer via the automatically appended "Type something." row on every question, or press Esc to abandon the questionnaire. Do NOT author "Other" or "Type something." labels yourself — reserved labels are rejected at runtime.`,`Set multiSelect: true when multiple answers are valid. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. If you recommend a specific option, make that the first option and append "(Recommended)" to its label.`,`Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.`];function g(e,t){let n={questions:t.questions.map(e=>({question:e.question,header:e.header,multiSelect:e.multiSelect??!1,options:e.options.map(e=>({label:e.label,description:e.description,hasPreview:!!e.preview}))}))};e.emit(l,n)}function _(e,t){let n={active:t};e.emit(c,n)}function v(e){let t=e.ui;return typeof t.select==`function`&&typeof t.input==`function`}function y(c,l,y){let b=a().guidance;c.registerTool({name:p,label:`Ask User Question`,renderShell:`self`,description:`Ask the user one or more structured questions during execution. Use when you need to:
2
+ 1. Gather user preferences or requirements
3
+ 2. Clarify ambiguous instructions
4
+ 3. Get decisions on implementation choices as you work
5
+ 4. Offer choices to the user about what direction to take
6
+
7
+ Usage notes:
8
+ - Users can type a custom answer via the automatically appended "Type something." row on every question or press Esc to abandon the questionnaire. Do NOT author "Other" or "Type something." labels yourself — reserved labels are rejected at runtime.
9
+ - Use multiSelect: true when multiple answers are valid.
10
+ - If you recommend a specific option, make that the first option and add "(Recommended)" at the end of the label.
11
+
12
+ Preview feature:
13
+ Use the optional preview field for ASCII mockups, code snippets, diagrams, or configuration examples that users should compare visually. Do not use previews for simple preference questions.`,promptSnippet:b?.promptSnippet??m,promptGuidelines:b?.promptGuidelines??h,parameters:t,executionMode:`sequential`,async execute(t,c,u,d,f){let p=c,m=e=>y.isActive?.(f,e)??!0,h=()=>({answers:[],cancelled:!0});if(!m(u))return r(`Error: the questionnaire session is no longer active.`,h());if(!f.hasUI)return r(`Error: UI not available (running in non-interactive mode)`,{answers:[],cancelled:!0,error:`no_ui`});let b=i(p);if(!b.ok)return r(b.message,{answers:[],cancelled:!0,error:b.error});try{let t=await y.enqueue(async({signal:e,reportProgress:t})=>{if(!m(e))return h();g(l,p);let n=await y.tryVoice?.(p);if(n)return n;let r=!0,i=()=>{r&&(r=!1,m()&&_(l,!1))};e.addEventListener(`abort`,i,{once:!0}),_(l,!0);try{if(!m(e))return h();if(f.mode===`rpc`&&v(f)){let n=await s(f,p,e,t);return m(e)?n:h()}let n=await y.runTui(f,p,o(a()),e,t);if(!m(e))return h();if(n!==void 0)return n;if(v(f)){let n=await s(f,p,e,t);return m(e)?n:h()}return{answers:[],cancelled:!0,error:`no_custom_ui`}}finally{e.removeEventListener(`abort`,i),i()}},u);return t.delivery===`voice`?e(t):t.error===`no_custom_ui`?r(`Error: this client cannot render the questionnaire (custom UI is unavailable). The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, without using this tool.`,t):n(t,p)}catch(e){let t=e instanceof Error?e.message:String(e);return r(`Error: the questionnaire UI failed to load. The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead. (cause: ${t})`,{answers:[],cancelled:!0,error:`session_load_failed`})}},renderCall(e,t){let n=e,r=n.questions.map(e=>e.header).join(`, `),i=`${n.questions.length} question${n.questions.length===1?``:`s`}`,a=f(`ask`,i,t);return new u(r?`${a} ${t.fg(`dim`,`(${r})`)}`:a)},renderResult(e,t,n,r){let i=e.details;if(!i){let t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
14
+ `),i=r.isError?`error`:`toolOutput`,a=r.isError?`✗ failed`:`✓ submitted`;return new d([n.fg(i,t||a)],n,{wrap:!0})}if(i.cancelled)return new d([n.fg(`warning`,`◐`)+n.fg(`dim`,` cancelled`)],n);if(i.delivery===`voice`&&i.voicePrompt)return new d([n.fg(`toolOutput`,i.voicePrompt)],n,{wrap:!0});let a=i.answers.map(e=>{let t=e.kind===`multi`?(e.selected??[]).join(`, `):e.answer;return`${n.fg(`success`,`✓`)} ${n.fg(`accent`,e.question)}: ${n.fg(`toolOutput`,t??``)}`});return a.length===0&&a.push(n.fg(`success`,`✓`)+n.fg(`dim`,` submitted`)),new d(a,n,{wrap:!0})}})}export{p as ASK_USER_QUESTION_TOOL_NAME,h as DEFAULT_PROMPT_GUIDELINES,m as DEFAULT_PROMPT_SNIPPET,y as registerAskUserQuestionTool};
15
+ //# sourceMappingURL=askUserQuestionAdapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"askUserQuestionAdapter.mjs","names":[],"sources":["../../../src/adapters/pi/askUserQuestionAdapter.ts"],"sourcesContent":["import {\n type AskUserBlockedEvent,\n type AskUserPromptEvent,\n DOOM_ASK_USER_BLOCKED_EVENT,\n DOOM_ASK_USER_PROMPT_EVENT,\n} from '@agimon-ai/doompi-extension-contracts/ask-user';\nimport { DoomToolCall, DoomToolResult, renderToolHeading } from '@agimon-ai/doompi-ui/toolChrome';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport {\n MAX_OPTIONS,\n MAX_QUESTIONS,\n MIN_OPTIONS,\n type QuestionParams,\n QuestionParamsSchema,\n} from '../../schemas/questionnaire.js';\nimport type { QuestionnaireRunner } from '../../services/questionnaireCoordinator.js';\nimport { buildQuestionnaireResponse, buildToolResult } from '../../services/responseService.js';\nimport { validateQuestionnaire } from '../../services/validationService.js';\nimport type { QuestionnaireResult } from '../../types/questionnaire.js';\nimport { loadUserFeedbackConfig, resolveCollapseKey } from '../config/configAdapter.js';\nimport { buildVoiceToolResult } from '../doom/voiceQuestionHandoff.js';\nimport { runRpcQuestionnaire } from './rpcQuestionnaireAdapter.js';\n\nexport const ASK_USER_QUESTION_TOOL_NAME = 'ask_user_question';\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES = [\n `Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n `Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer via the automatically appended \"Type something.\" row on every question, or press Esc to abandon the questionnaire. Do NOT author \"Other\" or \"Type something.\" labels yourself — reserved labels are rejected at runtime.`,\n 'Set multiSelect: true when multiple answers are valid. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. If you recommend a specific option, make that the first option and append \"(Recommended)\" to its label.',\n 'Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.',\n];\n\nconst ERROR_NO_UI = 'Error: UI not available (running in non-interactive mode)';\nconst ERROR_NO_CUSTOM_UI =\n 'Error: this client cannot render the questionnaire (custom UI is unavailable). The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, without using this tool.';\nconst ERROR_SESSION_LOAD_FAILED =\n 'Error: the questionnaire UI failed to load. The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead.';\nconst ERROR_SESSION_INACTIVE = 'Error: the questionnaire session is no longer active.';\n\nexport interface AskUserQuestionToolDependencies {\n enqueue: (runner: QuestionnaireRunner, signal?: AbortSignal) => Promise<QuestionnaireResult>;\n isActive?: (context: ExtensionContext, signal?: AbortSignal) => boolean;\n tryVoice?: (params: QuestionParams) => QuestionnaireResult | undefined | Promise<QuestionnaireResult | undefined>;\n runTui: (\n context: ExtensionContext,\n params: QuestionParams,\n collapseKey: string,\n signal?: AbortSignal,\n reportProgress?: (result: QuestionnaireResult) => void,\n ) => Promise<QuestionnaireResult | undefined>;\n}\n\nfunction emitPrompt(cordis: Context, params: QuestionParams): void {\n const payload: AskUserPromptEvent = {\n questions: params.questions.map((question) => ({\n question: question.question,\n header: question.header,\n multiSelect: question.multiSelect ?? false,\n options: question.options.map((option) => ({\n label: option.label,\n description: option.description,\n hasPreview: Boolean(option.preview),\n })),\n })),\n };\n cordis.emit(DOOM_ASK_USER_PROMPT_EVENT, payload);\n}\n\nfunction emitBlocked(cordis: Context, active: boolean): void {\n const payload: AskUserBlockedEvent = { active };\n cordis.emit(DOOM_ASK_USER_BLOCKED_EVENT, payload);\n}\n\nfunction hasDialogUI(context: ExtensionContext): boolean {\n const ui = context.ui as unknown as { select?: unknown; input?: unknown };\n return typeof ui.select === 'function' && typeof ui.input === 'function';\n}\n\nexport function registerAskUserQuestionTool(\n pi: ExtensionAPI,\n cordis: Context,\n dependencies: AskUserQuestionToolDependencies,\n): void {\n const configuredGuidance = loadUserFeedbackConfig().guidance;\n pi.registerTool({\n name: ASK_USER_QUESTION_TOOL_NAME,\n label: 'Ask User Question',\n renderShell: 'self',\n description: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users can type a custom answer via the automatically appended \"Type something.\" row on every question or press Esc to abandon the questionnaire. Do NOT author \"Other\" or \"Type something.\" labels yourself — reserved labels are rejected at runtime.\n- Use multiSelect: true when multiple answers are valid.\n- If you recommend a specific option, make that the first option and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional preview field for ASCII mockups, code snippets, diagrams, or configuration examples that users should compare visually. Do not use previews for simple preference questions.`,\n promptSnippet: configuredGuidance?.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n promptGuidelines: configuredGuidance?.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n parameters: QuestionParamsSchema,\n executionMode: 'sequential',\n\n async execute(_toolCallId, params, signal, _onUpdate, context) {\n const typed = params as QuestionParams;\n const isActive = (activeSignal?: AbortSignal): boolean => dependencies.isActive?.(context, activeSignal) ?? true;\n const cancelled = (): QuestionnaireResult => ({ answers: [], cancelled: true });\n if (!isActive(signal)) return buildToolResult(ERROR_SESSION_INACTIVE, cancelled());\n if (!context.hasUI) {\n return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: 'no_ui' });\n }\n\n const validation = validateQuestionnaire(typed);\n if (!validation.ok) {\n return buildToolResult(validation.message, {\n answers: [],\n cancelled: true,\n error: validation.error,\n });\n }\n\n try {\n const result = await dependencies.enqueue(async ({ signal: activeSignal, reportProgress }) => {\n if (!isActive(activeSignal)) return cancelled();\n emitPrompt(cordis, typed);\n const voiceResult = await dependencies.tryVoice?.(typed);\n if (voiceResult) return voiceResult;\n\n let blocked = true;\n const clearBlocked = (): void => {\n if (!blocked) return;\n blocked = false;\n if (isActive()) emitBlocked(cordis, false);\n };\n activeSignal.addEventListener('abort', clearBlocked, { once: true });\n emitBlocked(cordis, true);\n try {\n if (!isActive(activeSignal)) return cancelled();\n if (context.mode === 'rpc' && hasDialogUI(context)) {\n const rpcResult = await runRpcQuestionnaire(context, typed, activeSignal, reportProgress);\n return isActive(activeSignal) ? rpcResult : cancelled();\n }\n\n const tuiResult = await dependencies.runTui(\n context,\n typed,\n resolveCollapseKey(loadUserFeedbackConfig()),\n activeSignal,\n reportProgress,\n );\n if (!isActive(activeSignal)) return cancelled();\n if (tuiResult !== undefined) return tuiResult;\n if (hasDialogUI(context)) {\n const rpcResult = await runRpcQuestionnaire(context, typed, activeSignal, reportProgress);\n return isActive(activeSignal) ? rpcResult : cancelled();\n }\n return { answers: [], cancelled: true, error: 'no_custom_ui' };\n } finally {\n activeSignal.removeEventListener('abort', clearBlocked);\n clearBlocked();\n }\n }, signal);\n\n if (result.delivery === 'voice') return buildVoiceToolResult(result);\n if (result.error === 'no_custom_ui') return buildToolResult(ERROR_NO_CUSTOM_UI, result);\n return buildQuestionnaireResponse(result, typed);\n } catch (error) {\n const cause = error instanceof Error ? error.message : String(error);\n return buildToolResult(`${ERROR_SESSION_LOAD_FAILED} (cause: ${cause})`, {\n answers: [],\n cancelled: true,\n error: 'session_load_failed',\n });\n }\n },\n\n renderCall(args, theme) {\n const params = args as QuestionParams;\n const headers = params.questions.map((question) => question.header).join(', ');\n const count = `${params.questions.length} question${params.questions.length === 1 ? '' : 's'}`;\n const heading = renderToolHeading('ask', count, theme);\n return new DoomToolCall(headers ? `${heading} ${theme.fg('dim', `(${headers})`)}` : heading);\n },\n\n renderResult(result, _options, theme, context) {\n const details = result.details as QuestionnaireResult | undefined;\n if (!details) {\n const raw = result.content\n .filter((block) => block.type === 'text')\n .map((block) => block.text)\n .join('\\n');\n const color = context.isError ? 'error' : 'toolOutput';\n const fallback = context.isError ? '✗ failed' : '✓ submitted';\n return new DoomToolResult([theme.fg(color, raw || fallback)], theme, { wrap: true });\n }\n if (details.cancelled) {\n return new DoomToolResult([theme.fg('warning', '◐') + theme.fg('dim', ' cancelled')], theme);\n }\n if (details.delivery === 'voice' && details.voicePrompt) {\n return new DoomToolResult([theme.fg('toolOutput', details.voicePrompt)], theme, { wrap: true });\n }\n const lines = details.answers.map((answer) => {\n const scalar = answer.kind === 'multi' ? (answer.selected ?? []).join(', ') : answer.answer;\n return `${theme.fg('success', '✓')} ${theme.fg('accent', answer.question)}: ${theme.fg(\n 'toolOutput',\n scalar ?? '',\n )}`;\n });\n if (lines.length === 0) lines.push(theme.fg('success', '✓') + theme.fg('dim', ' submitted'));\n return new DoomToolResult(lines, theme, { wrap: true });\n },\n });\n}\n"],"mappings":"ysBAwBA,MAAa,EAA8B,oBAE9B,EAAyB,+FACzB,EAA4B,CACvC,wKACA,uaACA,yUACA,kHACF,EAsBA,SAAS,EAAW,EAAiB,EAA8B,CACjE,IAAM,EAA8B,CAClC,UAAW,EAAO,UAAU,IAAK,IAAc,CAC7C,SAAU,EAAS,SACnB,OAAQ,EAAS,OACjB,YAAa,EAAS,aAAe,GACrC,QAAS,EAAS,QAAQ,IAAK,IAAY,CACzC,MAAO,EAAO,MACd,YAAa,EAAO,YACpB,WAAY,EAAQ,EAAO,OAC7B,EAAE,CACJ,EAAE,CACJ,EACA,EAAO,KAAK,EAA4B,CAAO,CACjD,CAEA,SAAS,EAAY,EAAiB,EAAuB,CAC3D,IAAM,EAA+B,CAAE,QAAO,EAC9C,EAAO,KAAK,EAA6B,CAAO,CAClD,CAEA,SAAS,EAAY,EAAoC,CACvD,IAAM,EAAK,EAAQ,GACnB,OAAO,OAAO,EAAG,QAAW,YAAc,OAAO,EAAG,OAAU,UAChE,CAEA,SAAgB,EACd,EACA,EACA,EACM,CACN,IAAM,EAAqB,EAAuB,CAAC,CAAC,SACpD,EAAG,aAAa,CACd,KAAM,EACN,MAAO,oBACP,YAAa,OACb,YAAa;;;;;;;;;;;;+LAab,cAAe,GAAoB,eAAiB,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C,EAAW,EAAQ,QAAU,WAAa,cAChD,OAAO,IAAI,EAAe,CAAC,EAAM,GAAG,EAAO,GAAO,CAAQ,CAAC,EAAG,EAAO,CAAE,KAAM,EAAK,CAAC,CACrF,CACA,GAAI,EAAQ,UACV,OAAO,IAAI,EAAe,CAAC,EAAM,GAAG,UAAW,GAAG,EAAI,EAAM,GAAG,MAAO,YAAY,CAAC,EAAG,CAAK,EAE7F,GAAI,EAAQ,WAAa,SAAW,EAAQ,YAC1C,OAAO,IAAI,EAAe,CAAC,EAAM,GAAG,aAAc,EAAQ,WAAW,CAAC,EAAG,EAAO,CAAE,KAAM,EAAK,CAAC,EAEhG,IAAM,EAAQ,EAAQ,QAAQ,IAAK,GAAW,CAC5C,IAAM,EAAS,EAAO,OAAS,SAAW,EAAO,UAAY,CAAC,EAAA,CAAG,KAAK,IAAI,EAAI,EAAO,OACrF,MAAO,GAAG,EAAM,GAAG,UAAW,GAAG,EAAE,GAAG,EAAM,GAAG,SAAU,EAAO,QAAQ,EAAE,IAAI,EAAM,GAClF,aACA,GAAU,EACZ,GACF,CAAC,EAED,OADI,EAAM,SAAW,GAAG,EAAM,KAAK,EAAM,GAAG,UAAW,GAAG,EAAI,EAAM,GAAG,MAAO,YAAY,CAAC,EACpF,IAAI,EAAe,EAAO,EAAO,CAAE,KAAM,EAAK,CAAC,CACxD,CACF,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ const e=require("../../services/questionnaireCoordinator.cjs"),t=require("../doom/voiceQuestionHandoff.cjs"),n=require("./askUserQuestionAdapter.cjs"),r=require("./reconcileAdapter.cjs");let i=require("@agimon-ai/doompi-extension-contracts/cordis-host"),a=require("@agimon-ai/doompi-extension-contracts/mode"),o=require("@agimon-ai/doompi-extension-contracts/narration");const s=`@agimon-ai/doompi-user-feedback`;function c(){return{answers:[],cancelled:!0}}function l(i,l){let u=!0,d=0,f,p=!1,m=new e.QuestionnaireCoordinator,h,g=Promise.resolve(),_=new Set,v=e=>(_.add(e),e.then(()=>_.delete(e),()=>_.delete(e)),e),y=(e,t)=>u&&e===d&&t===f,b=(e,t)=>u&&p&&t?.aborted!==!0&&e.sessionManager.getSessionId()===f,x=async()=>{if(!u)return;let e=m;e.shutdown(),u=!1,d+=1,p=!1,f=void 0,await Promise.allSettled(_),await e.waitForIdle()};i.effect(()=>x,`${s}/runtime`),i.inject([a.DOOM_MINOR_MODE_CATALOG_SERVICE,o.DOOM_NARRATION_SERVICE],e=>{let n=t.createVoiceQuestionHandoff((0,a.requireMinorModeCatalog)(e),(0,o.requireDoomNarrationService)(e));return h=n,()=>{h===n&&(h=void 0)}}),n.registerAskUserQuestionTool(l,i,{enqueue:(e,t)=>{let n=m,r=d,i=f;return!p||!y(r,i)||t?.aborted?Promise.resolve(c()):n.enqueue(async t=>{if(!p||!y(r,i)||t.signal.aborted)return c();let n=await e({...t,reportProgress:e=>{y(r,i)&&!t.signal.aborted&&t.reportProgress(e)}});return p&&y(r,i)&&!t.signal.aborted?n:c()},t)},isActive:b,runTui:async(e,t,n,r,i)=>{if(!b(e,r))return;let{runTuiQuestionnaire:a}=await Promise.resolve().then(()=>require("../../tui/runQuestionnaire.cjs"));if(!b(e,r))return;let o=await a(e,t,n,r,i);return b(e,r)?o:void 0},tryVoice:e=>u&&p?h?.handoff(e):void 0}),r.registerAskUserQuestionReconciler(l,b),l.on(`session_start`,(t,n)=>{if(!u)return;let r=m;r.shutdown();let i=n.sessionManager.getSessionId(),a=++d;m=new e.QuestionnaireCoordinator,f=i,p=!1;let o=async()=>{await r.waitForIdle(),y(a,i)&&(p=!0)},s=g.then(o,o);return g=s.catch(()=>void 0),v(s)})}async function u(e){let t=await(0,i.connectDoomCordisHost)(e,s),n=t.root.plugin(d,{pi:e});try{await n}catch(e){try{await n.dispose()}finally{await t.dispose()}throw e}let r;e.on(`session_shutdown`,()=>r??=(async()=>{try{await n.dispose()}finally{await t.dispose()}})())}function d(e,t){l(e,t.pi)}exports.default=u,exports.userFeedbackExtension=u,exports.installUserFeedbackRuntime=l;
2
+ //# sourceMappingURL=extension.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.cjs","names":["QuestionnaireCoordinator","DOOM_MINOR_MODE_CATALOG_SERVICE","DOOM_NARRATION_SERVICE","createVoiceQuestionHandoff","requireMinorModeCatalog","requireDoomNarrationService","connectDoomCordisHost"],"sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import { connectDoomCordisHost } from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_MINOR_MODE_CATALOG_SERVICE, requireMinorModeCatalog } from '@agimon-ai/doompi-extension-contracts/mode';\nimport { DOOM_NARRATION_SERVICE, requireDoomNarrationService } from '@agimon-ai/doompi-extension-contracts/narration';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { QuestionnaireCoordinator, type QuestionnaireRunner } from '../../services/questionnaireCoordinator.js';\nimport type { QuestionnaireResult } from '../../types/questionnaire.js';\nimport { createVoiceQuestionHandoff, type VoiceQuestionHandoff } from '../doom/voiceQuestionHandoff.js';\nimport { registerAskUserQuestionTool } from './askUserQuestionAdapter.js';\nimport { registerAskUserQuestionReconciler } from './reconcileAdapter.js';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi-user-feedback';\nconst SESSION_START_EVENT = 'session_start';\n\nfunction cancelledResult(): QuestionnaireResult {\n return { answers: [], cancelled: true };\n}\n\n/** Install one user-feedback runtime into its host-owned Cordis plugin fiber. */\nexport function installUserFeedbackRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let sessionGeneration = 0;\n let sessionId: string | undefined;\n let sessionReady = false;\n let coordinator = new QuestionnaireCoordinator();\n let voiceHandoff: VoiceQuestionHandoff | undefined;\n let lifecycleQueue: Promise<void> = Promise.resolve();\n const pendingOperations = new Set<Promise<unknown>>();\n\n const trackOperation = <T>(operation: Promise<T>): Promise<T> => {\n pendingOperations.add(operation);\n void operation.then(\n () => pendingOperations.delete(operation),\n () => pendingOperations.delete(operation),\n );\n return operation;\n };\n const ownsGeneration = (generation: number, expectedSessionId: string | undefined): boolean =>\n active && generation === sessionGeneration && expectedSessionId === sessionId;\n const isContextActive = (context: ExtensionContext, signal?: AbortSignal): boolean =>\n active && sessionReady && signal?.aborted !== true && context.sessionManager.getSessionId() === sessionId;\n\n const shutdownRuntime = async (): Promise<void> => {\n if (!active) return;\n const ownedCoordinator = coordinator;\n ownedCoordinator.shutdown();\n active = false;\n sessionGeneration += 1;\n sessionReady = false;\n sessionId = undefined;\n await Promise.allSettled(pendingOperations);\n await ownedCoordinator.waitForIdle();\n };\n cordis.effect(() => shutdownRuntime, `${PACKAGE_SOURCE}/runtime`);\n\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE, DOOM_NARRATION_SERVICE], (serviceContext) => {\n const handoff = createVoiceQuestionHandoff(\n requireMinorModeCatalog(serviceContext),\n requireDoomNarrationService(serviceContext),\n );\n voiceHandoff = handoff;\n return () => {\n if (voiceHandoff === handoff) voiceHandoff = undefined;\n };\n });\n\n registerAskUserQuestionTool(pi, cordis, {\n enqueue: (runner: QuestionnaireRunner, signal?: AbortSignal) => {\n const ownedCoordinator = coordinator;\n const generation = sessionGeneration;\n const expectedSessionId = sessionId;\n if (!sessionReady || !ownsGeneration(generation, expectedSessionId) || signal?.aborted) {\n return Promise.resolve(cancelledResult());\n }\n return ownedCoordinator.enqueue(async (context) => {\n if (!sessionReady || !ownsGeneration(generation, expectedSessionId) || context.signal.aborted) {\n return cancelledResult();\n }\n const result = await runner({\n ...context,\n reportProgress: (progress) => {\n if (ownsGeneration(generation, expectedSessionId) && !context.signal.aborted) {\n context.reportProgress(progress);\n }\n },\n });\n return sessionReady && ownsGeneration(generation, expectedSessionId) && !context.signal.aborted\n ? result\n : cancelledResult();\n }, signal);\n },\n isActive: isContextActive,\n runTui: async (context, params, collapseKey, signal, reportProgress) => {\n if (!isContextActive(context, signal)) return undefined;\n const { runTuiQuestionnaire } = await import('../../tui/runQuestionnaire.js');\n if (!isContextActive(context, signal)) return undefined;\n const result = await runTuiQuestionnaire(context, params, collapseKey, signal, reportProgress);\n return isContextActive(context, signal) ? result : undefined;\n },\n tryVoice: (params) => (active && sessionReady ? voiceHandoff?.handoff(params) : undefined),\n });\n registerAskUserQuestionReconciler(pi, isContextActive);\n\n pi.on(SESSION_START_EVENT, (_event, context) => {\n if (!active) return;\n const previousCoordinator = coordinator;\n previousCoordinator.shutdown();\n const activeSessionId = context.sessionManager.getSessionId();\n const generation = ++sessionGeneration;\n const nextCoordinator = new QuestionnaireCoordinator();\n coordinator = nextCoordinator;\n sessionId = activeSessionId;\n sessionReady = false;\n\n const initializeSession = async (): Promise<void> => {\n await previousCoordinator.waitForIdle();\n if (!ownsGeneration(generation, activeSessionId)) return;\n sessionReady = true;\n };\n\n const operation = lifecycleQueue.then(initializeSession, initializeSession);\n lifecycleQueue = operation.catch(() => undefined);\n return trackOperation(operation);\n });\n}\n\n/** The package's sole Pi factory; Pi reloads it and Cordis owns all package resources. */\nexport async function userFeedbackExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(userFeedbackPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface UserFeedbackPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction userFeedbackPlugin(cordis: Context, config: UserFeedbackPluginConfig): void {\n installUserFeedbackRuntime(cordis, config.pi);\n}\n\nexport default userFeedbackExtension;\n"],"mappings":"mXAWA,MAAM,EAAiB,kCAGvB,SAAS,GAAuC,CAC9C,MAAO,CAAE,QAAS,CAAC,EAAG,UAAW,EAAK,CACxC,CAGA,S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AAI,CAAc,EAC3D,EAAQ,EAAW,KAAK,OAAO,EAAoB,CAAE,IAAG,CAAC,EAC/D,GAAI,CACF,MAAM,CACR,OAAS,EAAO,CACd,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACA,MAAM,CACR,CACA,IAAI,EACJ,EAAG,GACD,uBAEG,KAAc,SAAY,CACzB,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACF,EAAA,CAAG,CACP,CACF,CAMA,SAAS,EAAmB,EAAiB,EAAwC,CACnF,EAA2B,EAAQ,EAAO,EAAE,CAC9C"}
@@ -0,0 +1,8 @@
1
+ import "@deepseek-ai/cordis";
2
+ import { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ //#region src/adapters/pi/extension.d.ts
4
+ /** The package's sole Pi factory; Pi reloads it and Cordis owns all package resources. */
5
+ declare function userFeedbackExtension(pi: ExtensionAPI): Promise<void>;
6
+ //#endregion
7
+ export { userFeedbackExtension as default, userFeedbackExtension };
8
+ //# sourceMappingURL=extension.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.cts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBA+HsB,sBAAsB,IAAI,eAAe"}
@@ -0,0 +1,8 @@
1
+ import { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import "@deepseek-ai/cordis";
3
+ //#region src/adapters/pi/extension.d.ts
4
+ /** The package's sole Pi factory; Pi reloads it and Cordis owns all package resources. */
5
+ declare function userFeedbackExtension(pi: ExtensionAPI): Promise<void>;
6
+ //#endregion
7
+ export { userFeedbackExtension as default, userFeedbackExtension };
8
+ //# sourceMappingURL=extension.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.mts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBA+HsB,sBAAsB,IAAI,eAAe"}
@@ -0,0 +1,2 @@
1
+ import{QuestionnaireCoordinator as e}from"../../services/questionnaireCoordinator.mjs";import{createVoiceQuestionHandoff as t}from"../doom/voiceQuestionHandoff.mjs";import{registerAskUserQuestionTool as n}from"./askUserQuestionAdapter.mjs";import{registerAskUserQuestionReconciler as r}from"./reconcileAdapter.mjs";import{connectDoomCordisHost as i}from"@agimon-ai/doompi-extension-contracts/cordis-host";import{DOOM_MINOR_MODE_CATALOG_SERVICE as a,requireMinorModeCatalog as o}from"@agimon-ai/doompi-extension-contracts/mode";import{DOOM_NARRATION_SERVICE as s,requireDoomNarrationService as c}from"@agimon-ai/doompi-extension-contracts/narration";const l=`@agimon-ai/doompi-user-feedback`;function u(){return{answers:[],cancelled:!0}}function d(i,d){let f=!0,p=0,m,h=!1,g=new e,_,v=Promise.resolve(),y=new Set,b=e=>(y.add(e),e.then(()=>y.delete(e),()=>y.delete(e)),e),x=(e,t)=>f&&e===p&&t===m,S=(e,t)=>f&&h&&t?.aborted!==!0&&e.sessionManager.getSessionId()===m,C=async()=>{if(!f)return;let e=g;e.shutdown(),f=!1,p+=1,h=!1,m=void 0,await Promise.allSettled(y),await e.waitForIdle()};i.effect(()=>C,`${l}/runtime`),i.inject([a,s],e=>{let n=t(o(e),c(e));return _=n,()=>{_===n&&(_=void 0)}}),n(d,i,{enqueue:(e,t)=>{let n=g,r=p,i=m;return!h||!x(r,i)||t?.aborted?Promise.resolve(u()):n.enqueue(async t=>{if(!h||!x(r,i)||t.signal.aborted)return u();let n=await e({...t,reportProgress:e=>{x(r,i)&&!t.signal.aborted&&t.reportProgress(e)}});return h&&x(r,i)&&!t.signal.aborted?n:u()},t)},isActive:S,runTui:async(e,t,n,r,i)=>{if(!S(e,r))return;let{runTuiQuestionnaire:a}=await import(`../../tui/runQuestionnaire.mjs`);if(!S(e,r))return;let o=await a(e,t,n,r,i);return S(e,r)?o:void 0},tryVoice:e=>f&&h?_?.handoff(e):void 0}),r(d,S),d.on(`session_start`,(t,n)=>{if(!f)return;let r=g;r.shutdown();let i=n.sessionManager.getSessionId(),a=++p;g=new e,m=i,h=!1;let o=async()=>{await r.waitForIdle(),x(a,i)&&(h=!0)},s=v.then(o,o);return v=s.catch(()=>void 0),b(s)})}async function f(e){let t=await i(e,l),n=t.root.plugin(p,{pi:e});try{await n}catch(e){try{await n.dispose()}finally{await t.dispose()}throw e}let r;e.on(`session_shutdown`,()=>r??=(async()=>{try{await n.dispose()}finally{await t.dispose()}})())}function p(e,t){d(e,t.pi)}export{f as default,f as userFeedbackExtension,d as installUserFeedbackRuntime};
2
+ //# sourceMappingURL=extension.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.mjs","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import { connectDoomCordisHost } from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_MINOR_MODE_CATALOG_SERVICE, requireMinorModeCatalog } from '@agimon-ai/doompi-extension-contracts/mode';\nimport { DOOM_NARRATION_SERVICE, requireDoomNarrationService } from '@agimon-ai/doompi-extension-contracts/narration';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { QuestionnaireCoordinator, type QuestionnaireRunner } from '../../services/questionnaireCoordinator.js';\nimport type { QuestionnaireResult } from '../../types/questionnaire.js';\nimport { createVoiceQuestionHandoff, type VoiceQuestionHandoff } from '../doom/voiceQuestionHandoff.js';\nimport { registerAskUserQuestionTool } from './askUserQuestionAdapter.js';\nimport { registerAskUserQuestionReconciler } from './reconcileAdapter.js';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi-user-feedback';\nconst SESSION_START_EVENT = 'session_start';\n\nfunction cancelledResult(): QuestionnaireResult {\n return { answers: [], cancelled: true };\n}\n\n/** Install one user-feedback runtime into its host-owned Cordis plugin fiber. */\nexport function installUserFeedbackRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let sessionGeneration = 0;\n let sessionId: string | undefined;\n let sessionReady = false;\n let coordinator = new QuestionnaireCoordinator();\n let voiceHandoff: VoiceQuestionHandoff | undefined;\n let lifecycleQueue: Promise<void> = Promise.resolve();\n const pendingOperations = new Set<Promise<unknown>>();\n\n const trackOperation = <T>(operation: Promise<T>): Promise<T> => {\n pendingOperations.add(operation);\n void operation.then(\n () => pendingOperations.delete(operation),\n () => pendingOperations.delete(operation),\n );\n return operation;\n };\n const ownsGeneration = (generation: number, expectedSessionId: string | undefined): boolean =>\n active && generation === sessionGeneration && expectedSessionId === sessionId;\n const isContextActive = (context: ExtensionContext, signal?: AbortSignal): boolean =>\n active && sessionReady && signal?.aborted !== true && context.sessionManager.getSessionId() === sessionId;\n\n const shutdownRuntime = async (): Promise<void> => {\n if (!active) return;\n const ownedCoordinator = coordinator;\n ownedCoordinator.shutdown();\n active = false;\n sessionGeneration += 1;\n sessionReady = false;\n sessionId = undefined;\n await Promise.allSettled(pendingOperations);\n await ownedCoordinator.waitForIdle();\n };\n cordis.effect(() => shutdownRuntime, `${PACKAGE_SOURCE}/runtime`);\n\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE, DOOM_NARRATION_SERVICE], (serviceContext) => {\n const handoff = createVoiceQuestionHandoff(\n requireMinorModeCatalog(serviceContext),\n requireDoomNarrationService(serviceContext),\n );\n voiceHandoff = handoff;\n return () => {\n if (voiceHandoff === handoff) voiceHandoff = undefined;\n };\n });\n\n registerAskUserQuestionTool(pi, cordis, {\n enqueue: (runner: QuestionnaireRunner, signal?: AbortSignal) => {\n const ownedCoordinator = coordinator;\n const generation = sessionGeneration;\n const expectedSessionId = sessionId;\n if (!sessionReady || !ownsGeneration(generation, expectedSessionId) || signal?.aborted) {\n return Promise.resolve(cancelledResult());\n }\n return ownedCoordinator.enqueue(async (context) => {\n if (!sessionReady || !ownsGeneration(generation, expectedSessionId) || context.signal.aborted) {\n return cancelledResult();\n }\n const result = await runner({\n ...context,\n reportProgress: (progress) => {\n if (ownsGeneration(generation, expectedSessionId) && !context.signal.aborted) {\n context.reportProgress(progress);\n }\n },\n });\n return sessionReady && ownsGeneration(generation, expectedSessionId) && !context.signal.aborted\n ? result\n : cancelledResult();\n }, signal);\n },\n isActive: isContextActive,\n runTui: async (context, params, collapseKey, signal, reportProgress) => {\n if (!isContextActive(context, signal)) return undefined;\n const { runTuiQuestionnaire } = await import('../../tui/runQuestionnaire.js');\n if (!isContextActive(context, signal)) return undefined;\n const result = await runTuiQuestionnaire(context, params, collapseKey, signal, reportProgress);\n return isContextActive(context, signal) ? result : undefined;\n },\n tryVoice: (params) => (active && sessionReady ? voiceHandoff?.handoff(params) : undefined),\n });\n registerAskUserQuestionReconciler(pi, isContextActive);\n\n pi.on(SESSION_START_EVENT, (_event, context) => {\n if (!active) return;\n const previousCoordinator = coordinator;\n previousCoordinator.shutdown();\n const activeSessionId = context.sessionManager.getSessionId();\n const generation = ++sessionGeneration;\n const nextCoordinator = new QuestionnaireCoordinator();\n coordinator = nextCoordinator;\n sessionId = activeSessionId;\n sessionReady = false;\n\n const initializeSession = async (): Promise<void> => {\n await previousCoordinator.waitForIdle();\n if (!ownsGeneration(generation, activeSessionId)) return;\n sessionReady = true;\n };\n\n const operation = lifecycleQueue.then(initializeSession, initializeSession);\n lifecycleQueue = operation.catch(() => undefined);\n return trackOperation(operation);\n });\n}\n\n/** The package's sole Pi factory; Pi reloads it and Cordis owns all package resources. */\nexport async function userFeedbackExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(userFeedbackPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface UserFeedbackPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction userFeedbackPlugin(cordis: Context, config: UserFeedbackPluginConfig): void {\n installUserFeedbackRuntime(cordis, config.pi);\n}\n\nexport default userFeedbackExtension;\n"],"mappings":"yoBAWA,MAAM,EAAiB,kCAGvB,SAAS,GAAuC,CAC9C,MAAO,CAAE,QAAS,CAAC,EAAG,UAAW,EAAK,CACxC,CAGA,SAAgB,EAA2B,EAAiB,EAAwB,CAClF,IAAI,EAAS,GACT,EAAoB,EACpB,EACA,EAAe,GACf,EAAc,IAAI,EAClB,EACA,EAAgC,QAAQ,QAAQ,EAC9C,EAAoB,IAAI,IAExB,EAAqB,IACzB,EAAkB,IAAI,CAAS,EAC/B,EAAe,SACP,EAAkB,OAAO,CAAS,MAClC,EAAkB,OAAO,CAAS,CAC1C,EACO,GAEH,GAAkB,EAAoB,IAC1C,GAAU,IAAe,GAAqB,IAAsB,EAChE,GAAmB,EAA2B,IAClD,GAAU,GAAgB,GAAQ,UAAY,IAAQ,EAAQ,eAAe,aAAa,IAAM,EAE5F,EAAkB,SAA2B,CACjD,GAAI,CAAC,EAAQ,OACb,IAAM,EAAmB,EACzB,EAAiB,SAAS,EAC1B,EAAS,GACT,GAAqB,EACrB,EAAe,GACf,EAAY,IAAA,GACZ,MAAM,QAAQ,WAAW,CAAiB,EAC1C,MAAM,EAAiB,YAAY,CACrC,EACA,EAAO,WAAa,EAAiB,GAAG,EAAe,SAAS,EAEhE,EAAO,OAAO,CAAC,EAAiC,CAAsB,EAAI,GAAmB,CAC3F,IAAM,EAAU,EACd,EAAwB,CAAc,EACtC,EAA4B,CAAc,CAC5C,EAEA,MADA,GAAe,MACF,CACP,IAAiB,IAAS,EAAe,IAAA,GAC/C,CACF,CAAC,EAED,EAA4B,EAAI,EAAQ,CACtC,SAAU,EAA6B,IAAyB,CAC9D,IAAM,EAAmB,EACnB,EAAa,EACb,EAAoB,EAI1B,MAHI,CAAC,GAAgB,CAAC,EAAe,EAAY,CAAiB,GAAK,GAAQ,QACtE,QAAQ,QAAQ,EAAg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sB,EAAiC,CAC3E,IAAM,EAAa,MAAM,EAAsB,EAAI,CAAc,EAC3D,EAAQ,EAAW,KAAK,OAAO,EAAoB,CAAE,IAAG,CAAC,EAC/D,GAAI,CACF,MAAM,CACR,OAAS,EAAO,CACd,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACA,MAAM,CACR,CACA,IAAI,EACJ,EAAG,GACD,uBAEG,KAAc,SAAY,CACzB,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACF,EAAA,CAAG,CACP,CACF,CAMA,SAAS,EAAmB,EAAiB,EAAwC,CACnF,EAA2B,EAAQ,EAAO,EAAE,CAC9C"}
@@ -0,0 +1,2 @@
1
+ const e=require("./askUserQuestionAdapter.cjs");function t(t,n){let r=t.getActiveTools(),i=r.includes(e.ASK_USER_QUESTION_TOOL_NAME);if(!n.hasUI&&i){t.setActiveTools(r.filter(t=>t!==e.ASK_USER_QUESTION_TOOL_NAME));return}n.hasUI&&!i&&t.setActiveTools([...r,e.ASK_USER_QUESTION_TOOL_NAME])}function n(e,n=()=>!0){e.on(`before_agent_start`,(r,i)=>{n(i)&&t(e,i)})}exports.reconcileAskUserQuestionTool=t,exports.registerAskUserQuestionReconciler=n;
2
+ //# sourceMappingURL=reconcileAdapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcileAdapter.cjs","names":["ASK_USER_QUESTION_TOOL_NAME"],"sources":["../../../src/adapters/pi/reconcileAdapter.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { ASK_USER_QUESTION_TOOL_NAME } from './askUserQuestionAdapter.js';\n\nexport function reconcileAskUserQuestionTool(pi: ExtensionAPI, context: Pick<ExtensionContext, 'hasUI'>): void {\n const activeTools = pi.getActiveTools();\n const active = activeTools.includes(ASK_USER_QUESTION_TOOL_NAME);\n if (!context.hasUI && active) {\n pi.setActiveTools(activeTools.filter((name) => name !== ASK_USER_QUESTION_TOOL_NAME));\n return;\n }\n if (context.hasUI && !active) {\n pi.setActiveTools([...activeTools, ASK_USER_QUESTION_TOOL_NAME]);\n }\n}\n\nexport function registerAskUserQuestionReconciler(\n pi: ExtensionAPI,\n isActive: (context: ExtensionContext) => boolean = () => true,\n): void {\n pi.on('before_agent_start', (_event, context) => {\n if (isActive(context)) reconcileAskUserQuestionTool(pi, context);\n });\n}\n"],"mappings":"gDAGA,SAAgB,EAA6B,EAAkB,EAAgD,CAC7G,IAAM,EAAc,EAAG,eAAe,EAChC,EAAS,EAAY,SAASA,EAAAA,2BAA2B,EAC/D,GAAI,CAAC,EAAQ,OAAS,EAAQ,CAC5B,EAAG,eAAe,EAAY,OAAQ,GAAS,IAASA,EAAAA,2BAA2B,CAAC,EACpF,MACF,CACI,EAAQ,OAAS,CAAC,GACpB,EAAG,eAAe,CAAC,GAAG,EAAaA,EAAAA,2BAA2B,CAAC,CAEnE,CAEA,SAAgB,EACd,EACA,MAAyD,GACnD,CACN,EAAG,GAAG,sBAAuB,EAAQ,IAAY,CAC3C,EAAS,CAAO,GAAG,EAA6B,EAAI,CAAO,CACjE,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ import{ASK_USER_QUESTION_TOOL_NAME as e}from"./askUserQuestionAdapter.mjs";function t(t,n){let r=t.getActiveTools(),i=r.includes(e);if(!n.hasUI&&i){t.setActiveTools(r.filter(t=>t!==e));return}n.hasUI&&!i&&t.setActiveTools([...r,e])}function n(e,n=()=>!0){e.on(`before_agent_start`,(r,i)=>{n(i)&&t(e,i)})}export{t as reconcileAskUserQuestionTool,n as registerAskUserQuestionReconciler};
2
+ //# sourceMappingURL=reconcileAdapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcileAdapter.mjs","names":[],"sources":["../../../src/adapters/pi/reconcileAdapter.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { ASK_USER_QUESTION_TOOL_NAME } from './askUserQuestionAdapter.js';\n\nexport function reconcileAskUserQuestionTool(pi: ExtensionAPI, context: Pick<ExtensionContext, 'hasUI'>): void {\n const activeTools = pi.getActiveTools();\n const active = activeTools.includes(ASK_USER_QUESTION_TOOL_NAME);\n if (!context.hasUI && active) {\n pi.setActiveTools(activeTools.filter((name) => name !== ASK_USER_QUESTION_TOOL_NAME));\n return;\n }\n if (context.hasUI && !active) {\n pi.setActiveTools([...activeTools, ASK_USER_QUESTION_TOOL_NAME]);\n }\n}\n\nexport function registerAskUserQuestionReconciler(\n pi: ExtensionAPI,\n isActive: (context: ExtensionContext) => boolean = () => true,\n): void {\n pi.on('before_agent_start', (_event, context) => {\n if (isActive(context)) reconcileAskUserQuestionTool(pi, context);\n });\n}\n"],"mappings":"2EAGA,SAAgB,EAA6B,EAAkB,EAAgD,CAC7G,IAAM,EAAc,EAAG,eAAe,EAChC,EAAS,EAAY,SAAS,CAA2B,EAC/D,GAAI,CAAC,EAAQ,OAAS,EAAQ,CAC5B,EAAG,eAAe,EAAY,OAAQ,GAAS,IAAS,CAA2B,CAAC,EACpF,MACF,CACI,EAAQ,OAAS,CAAC,GACpB,EAAG,eAAe,CAAC,GAAG,EAAa,CAA2B,CAAC,CAEnE,CAEA,SAAgB,EACd,EACA,MAAyD,GACnD,CACN,EAAG,GAAG,sBAAuB,EAAQ,IAAY,CAC3C,EAAS,CAAO,GAAG,EAA6B,EAAI,CAAO,CACjE,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ const e=`Type something.`,t=`Next`;function n(e){return{answers:e,cancelled:!0}}async function r(e,t,n,r){let i=await e.ui.input(t.question,`Type your answer`,{signal:r});if(i!==void 0)return{questionIndex:n,question:t.question,kind:`custom`,answer:i}}async function i(t,n,i,a){let o=[...n.options.map(e=>e.label),e],s=await t.ui.select(n.question,o,{signal:a});if(s===void 0)return;if(s===e)return r(t,n,i,a);let c=n.options.find(e=>e.label===s);if(c)return{questionIndex:i,question:n.question,kind:`option`,answer:c.label,...c.preview?{preview:c.preview}:{}}}function a(n,r){return[...n.options.map(e=>`${r.has(e.label)?`[x]`:`[ ]`} ${e.label}`),e,t]}function o(e){return e.replace(/^\[[ x]\]\s/u,``)}async function s(n,i,s,c){let l=new Set;for(;!c?.aborted;){let u=await n.ui.select(`${i.question} (choose options, then Next)`,a(i,l),{signal:c});if(u===void 0)return;if(u===e)return r(n,i,s,c);if(u===t)return{questionIndex:s,question:i.question,kind:`multi`,answer:null,selected:[...l]};let d=o(u);i.options.some(e=>e.label===d)&&(l.has(d)?l.delete(d):l.add(d))}}async function c(e,t,r,a){let o=[];for(let c=0;c<t.questions.length;c+=1){if(r?.aborted)return n(o);let l=t.questions[c];if(!l)continue;let u=l.multiSelect?await s(e,l,c,r):await i(e,l,c,r);if(!u)return n(o);o.push(u),a?.({answers:o.map(e=>({...e})),cancelled:!1})}return{answers:o,cancelled:!1}}exports.runRpcQuestionnaire=c;
2
+ //# sourceMappingURL=rpcQuestionnaireAdapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcQuestionnaireAdapter.cjs","names":[],"sources":["../../../src/adapters/pi/rpcQuestionnaireAdapter.ts"],"sourcesContent":["import type { ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport type { QuestionData, QuestionParams } from '../../schemas/questionnaire.js';\nimport type { QuestionAnswer, QuestionnaireResult } from '../../types/questionnaire.js';\n\nconst CUSTOM_LABEL = 'Type something.';\nconst DONE_LABEL = 'Next';\n\nfunction cancelled(answers: QuestionAnswer[]): QuestionnaireResult {\n return { answers, cancelled: true };\n}\n\nasync function askForCustomAnswer(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const answer = await context.ui.input(question.question, 'Type your answer', { signal });\n if (answer === undefined) return undefined;\n return {\n questionIndex,\n question: question.question,\n kind: 'custom',\n answer,\n };\n}\n\nasync function askSingleChoice(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const labels = [...question.options.map((option) => option.label), CUSTOM_LABEL];\n const selected = await context.ui.select(question.question, labels, { signal });\n if (selected === undefined) return undefined;\n if (selected === CUSTOM_LABEL) {\n return askForCustomAnswer(context, question, questionIndex, signal);\n }\n const option = question.options.find((candidate) => candidate.label === selected);\n if (!option) return undefined;\n return {\n questionIndex,\n question: question.question,\n kind: 'option',\n answer: option.label,\n ...(option.preview ? { preview: option.preview } : {}),\n };\n}\n\nfunction multiChoiceLabels(question: QuestionData, selected: ReadonlySet<string>): string[] {\n const options = question.options.map((option) => {\n const marker = selected.has(option.label) ? '[x]' : '[ ]';\n return `${marker} ${option.label}`;\n });\n return [...options, CUSTOM_LABEL, DONE_LABEL];\n}\n\nfunction stripSelectionMarker(value: string): string {\n return value.replace(/^\\[[ x]\\]\\s/u, '');\n}\n\nasync function askMultipleChoice(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const selected = new Set<string>();\n while (!signal?.aborted) {\n const choice = await context.ui.select(\n `${question.question} (choose options, then Next)`,\n multiChoiceLabels(question, selected),\n { signal },\n );\n if (choice === undefined) return undefined;\n if (choice === CUSTOM_LABEL) {\n return askForCustomAnswer(context, question, questionIndex, signal);\n }\n if (choice === DONE_LABEL) {\n return {\n questionIndex,\n question: question.question,\n kind: 'multi',\n answer: null,\n selected: [...selected],\n };\n }\n const label = stripSelectionMarker(choice);\n if (!question.options.some((option) => option.label === label)) continue;\n if (selected.has(label)) selected.delete(label);\n else selected.add(label);\n }\n return undefined;\n}\n\nexport async function runRpcQuestionnaire(\n context: ExtensionContext,\n params: QuestionParams,\n signal?: AbortSignal,\n reportProgress?: (result: QuestionnaireResult) => void,\n): Promise<QuestionnaireResult> {\n const answers: QuestionAnswer[] = [];\n for (let questionIndex = 0; questionIndex < params.questions.length; questionIndex += 1) {\n if (signal?.aborted) return cancelled(answers);\n const question = params.questions[questionIndex];\n if (!question) continue;\n const answer = question.multiSelect\n ? await askMultipleChoice(context, question, questionIndex, signal)\n : await askSingleChoice(context, question, questionIndex, signal);\n if (!answer) return cancelled(answers);\n answers.push(answer);\n reportProgress?.({ answers: answers.map((item) => ({ ...item })), cancelled: false });\n }\n return { answers, cancelled: false };\n}\n"],"mappings":"AAIA,MAAM,EAAe,kBACf,EAAa,OAEnB,SAAS,EAAU,EAAgD,CACjE,MAAO,CAAE,UAAS,UAAW,EAAK,CACpC,CAEA,eAAe,EACb,EACA,EACA,EACA,EACqC,CACrC,IAAM,EAAS,MAAM,EAAQ,GAAG,MAAM,EAAS,SAAU,mBAAoB,CAAE,QAAO,CAAC,EACnF,OAAW,IAAA,GACf,MAAO,CACL,gBACA,SAAU,EAAS,SACnB,KAAM,SACN,QACF,CACF,CAEA,eAAe,EACb,EACA,EACA,EACA,EACqC,CACrC,IAAM,EAAS,CAAC,GAAG,EAAS,QAAQ,IAAK,GAAW,EAAO,KAAK,EAAG,CAAY,EACzE,EAAW,MAAM,EAAQ,GAAG,OAAO,EAAS,SAAU,EAAQ,CAAE,QAAO,CAAC,EAC9E,GAAI,IAAa,IAAA,GAAW,OAC5B,GAAI,IAAa,EACf,OAAO,EAAmB,EAAS,EAAU,EAAe,CAAM,EAEpE,IAAM,EAAS,EAAS,QAAQ,KAAM,GAAc,EAAU,QAAU,CAAQ,EAC3E,KACL,MAAO,CACL,gBACA,SAAU,EAAS,SACnB,KAAM,SACN,OAAQ,EAAO,MACf,GAAI,EAAO,QAAU,CAAE,QAAS,EAAO,OAAQ,EAAI,CAAC,CACtD,CACF,CAEA,SAAS,EAAkB,EAAwB,EAAyC,CAK1F,MAAO,CAAC,GAJQ,EAAS,QAAQ,IAAK,GAE7B,GADQ,EAAS,IAAI,EAAO,KAAK,EAAI,MAAQ,MACnC,GAAG,EAAO,OAEZ,EAAG,EAAc,CAAU,CAC9C,CAEA,SAAS,EAAqB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(e){return{answers:e,cancelled:!0}}async function r(e,t,n,r){let i=await e.ui.input(t.question,`Type your answer`,{signal:r});if(i!==void 0)return{questionIndex:n,question:t.question,kind:`custom`,answer:i}}async function i(t,n,i,a){let o=[...n.options.map(e=>e.label),e],s=await t.ui.select(n.question,o,{signal:a});if(s===void 0)return;if(s===e)return r(t,n,i,a);let c=n.options.find(e=>e.label===s);if(c)return{questionIndex:i,question:n.question,kind:`option`,answer:c.label,...c.preview?{preview:c.preview}:{}}}function a(n,r){return[...n.options.map(e=>`${r.has(e.label)?`[x]`:`[ ]`} ${e.label}`),e,t]}function o(e){return e.replace(/^\[[ x]\]\s/u,``)}async function s(n,i,s,c){let l=new Set;for(;!c?.aborted;){let u=await n.ui.select(`${i.question} (choose options, then Next)`,a(i,l),{signal:c});if(u===void 0)return;if(u===e)return r(n,i,s,c);if(u===t)return{questionIndex:s,question:i.question,kind:`multi`,answer:null,selected:[...l]};let d=o(u);i.options.some(e=>e.label===d)&&(l.has(d)?l.delete(d):l.add(d))}}async function c(e,t,r,a){let o=[];for(let c=0;c<t.questions.length;c+=1){if(r?.aborted)return n(o);let l=t.questions[c];if(!l)continue;let u=l.multiSelect?await s(e,l,c,r):await i(e,l,c,r);if(!u)return n(o);o.push(u),a?.({answers:o.map(e=>({...e})),cancelled:!1})}return{answers:o,cancelled:!1}}export{c as runRpcQuestionnaire};
2
+ //# sourceMappingURL=rpcQuestionnaireAdapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcQuestionnaireAdapter.mjs","names":[],"sources":["../../../src/adapters/pi/rpcQuestionnaireAdapter.ts"],"sourcesContent":["import type { ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport type { QuestionData, QuestionParams } from '../../schemas/questionnaire.js';\nimport type { QuestionAnswer, QuestionnaireResult } from '../../types/questionnaire.js';\n\nconst CUSTOM_LABEL = 'Type something.';\nconst DONE_LABEL = 'Next';\n\nfunction cancelled(answers: QuestionAnswer[]): QuestionnaireResult {\n return { answers, cancelled: true };\n}\n\nasync function askForCustomAnswer(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const answer = await context.ui.input(question.question, 'Type your answer', { signal });\n if (answer === undefined) return undefined;\n return {\n questionIndex,\n question: question.question,\n kind: 'custom',\n answer,\n };\n}\n\nasync function askSingleChoice(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const labels = [...question.options.map((option) => option.label), CUSTOM_LABEL];\n const selected = await context.ui.select(question.question, labels, { signal });\n if (selected === undefined) return undefined;\n if (selected === CUSTOM_LABEL) {\n return askForCustomAnswer(context, question, questionIndex, signal);\n }\n const option = question.options.find((candidate) => candidate.label === selected);\n if (!option) return undefined;\n return {\n questionIndex,\n question: question.question,\n kind: 'option',\n answer: option.label,\n ...(option.preview ? { preview: option.preview } : {}),\n };\n}\n\nfunction multiChoiceLabels(question: QuestionData, selected: ReadonlySet<string>): string[] {\n const options = question.options.map((option) => {\n const marker = selected.has(option.label) ? '[x]' : '[ ]';\n return `${marker} ${option.label}`;\n });\n return [...options, CUSTOM_LABEL, DONE_LABEL];\n}\n\nfunction stripSelectionMarker(value: string): string {\n return value.replace(/^\\[[ x]\\]\\s/u, '');\n}\n\nasync function askMultipleChoice(\n context: ExtensionContext,\n question: QuestionData,\n questionIndex: number,\n signal?: AbortSignal,\n): Promise<QuestionAnswer | undefined> {\n const selected = new Set<string>();\n while (!signal?.aborted) {\n const choice = await context.ui.select(\n `${question.question} (choose options, then Next)`,\n multiChoiceLabels(question, selected),\n { signal },\n );\n if (choice === undefined) return undefined;\n if (choice === CUSTOM_LABEL) {\n return askForCustomAnswer(context, question, questionIndex, signal);\n }\n if (choice === DONE_LABEL) {\n return {\n questionIndex,\n question: question.question,\n kind: 'multi',\n answer: null,\n selected: [...selected],\n };\n }\n const label = stripSelectionMarker(choice);\n if (!question.options.some((option) => option.label === label)) continue;\n if (selected.has(label)) selected.delete(label);\n else selected.add(label);\n }\n return undefined;\n}\n\nexport async function runRpcQuestionnaire(\n context: ExtensionContext,\n params: QuestionParams,\n signal?: AbortSignal,\n reportProgress?: (result: QuestionnaireResult) => void,\n): Promise<QuestionnaireResult> {\n const answers: QuestionAnswer[] = [];\n for (let questionIndex = 0; questionIndex < params.questions.length; questionIndex += 1) {\n if (signal?.aborted) return cancelled(answers);\n const question = params.questions[questionIndex];\n if (!question) continue;\n const answer = question.multiSelect\n ? await askMultipleChoice(context, question, questionIndex, signal)\n : await askSingleChoice(context, question, questionIndex, signal);\n if (!answer) return cancelled(answers);\n answers.push(answer);\n reportProgress?.({ answers: answers.map((item) => ({ ...item })), cancelled: false });\n }\n return { answers, cancelled: false };\n}\n"],"mappings":"AAIA,MAAM,EAAe,kBACf,EAAa,OAEnB,SAAS,EAAU,EAAgD,CACjE,MAAO,CAAE,UAAS,UAAW,EAAK,CACpC,CAEA,eAAe,EACb,EACA,EACA,EACA,EACqC,CACrC,IAAM,EAAS,MAAM,EAAQ,GAAG,MAAM,EAAS,SAAU,mBAAoB,CAAE,QAAO,CAAC,EACnF,OAAW,IAAA,GACf,MAAO,CACL,gBACA,SAAU,EAAS,SACnB,KAAM,SACN,QACF,CACF,CAEA,eAAe,EACb,EACA,EACA,EACA,EACqC,CACrC,IAAM,EAAS,CAAC,GAAG,EAAS,QAAQ,IAAK,GAAW,EAAO,KAAK,EAAG,CAAY,EACzE,EAAW,MAAM,EAAQ,GAAG,OAAO,EAAS,SAAU,EAAQ,CAAE,QAAO,CAAC,EAC9E,GAAI,IAAa,IAAA,GAAW,OAC5B,GAAI,IAAa,EACf,OAAO,EAAmB,EAAS,EAAU,EAAe,CAAM,EAEpE,IAAM,EAAS,EAAS,QAAQ,KAAM,GAAc,EAAU,QAAU,CAAQ,EAC3E,KACL,MAAO,CACL,gBACA,SAAU,EAAS,SACnB,KAAM,SACN,OAAQ,EAAO,MACf,GAAI,EAAO,QAAU,CAAE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C,EAAQ,OAAO,EAAU,CAAO,EACrC,EAAQ,KAAK,CAAM,EACnB,IAAiB,CAAE,QAAS,EAAQ,IAAK,IAAU,CAAE,GAAG,CAAK,EAAE,EAAG,UAAW,EAAM,CAAC,CACtF,CACA,MAAO,CAAE,UAAS,UAAW,EAAM,CACrC"}
@@ -0,0 +1 @@
1
+ const e=require("../adapters/pi/extension.cjs");module.exports=e.default;
@@ -0,0 +1,2 @@
1
+ import userFeedbackExtension from "../adapters/pi/extension.cjs";
2
+ export = userFeedbackExtension;
@@ -0,0 +1,2 @@
1
+ import userFeedbackExtension from "../adapters/pi/extension.mjs";
2
+ export { userFeedbackExtension as default };
@@ -0,0 +1 @@
1
+ import e from"../adapters/pi/extension.mjs";export{e as default};
package/dist/index.cjs ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ import { QuestionParams } from "./schemas/questionnaire.cjs";
2
+ import { QuestionnaireResult, ToolTextResult } from "./types/questionnaire.cjs";
3
+ export type { QuestionParams, QuestionnaireResult, ToolTextResult };
@@ -0,0 +1,3 @@
1
+ import { QuestionParams } from "./schemas/questionnaire.mjs";
2
+ import { QuestionnaireResult, ToolTextResult } from "./types/questionnaire.mjs";
3
+ export type { QuestionParams, QuestionnaireResult, ToolTextResult };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,2 @@
1
+ let e=require("typebox");const t=[`Other`,`Type something.`,`Next`],n=e.Type.Object({label:e.Type.String({maxLength:60,description:`MAX 60 CHARACTERS — hard limit. Concise option label shown to the user, ideally 1-5 words.`}),description:e.Type.String({description:`Explanation of what the option means and its important trade-offs.`}),preview:e.Type.Optional(e.Type.String({description:`Optional markdown preview rendered while this option is focused.`}))},{additionalProperties:!1}),r=e.Type.Object({question:e.Type.String({description:`The complete, clear question to ask the user.`}),header:e.Type.String({maxLength:16,description:`MAX 16 CHARACTERS — short label used when navigating several questions.`}),options:e.Type.Array(n,{minItems:2,maxItems:4,description:`The 2-4 choices offered for this question.`}),multiSelect:e.Type.Optional(e.Type.Boolean({description:`Allow more than one option to be selected.`,default:!1}))},{additionalProperties:!1}),i=e.Type.Object({questions:e.Type.Array(r,{minItems:1,maxItems:4,description:`Questions to ask the user (1-4 questions).`})},{additionalProperties:!1});exports.OptionSchema=n,exports.QuestionParamsSchema=i,exports.QuestionSchema=r,exports.RESERVED_LABELS=t;
2
+ //# sourceMappingURL=questionnaire.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questionnaire.cjs","names":["Type"],"sources":["../../src/schemas/questionnaire.ts"],"sourcesContent":["import { type Static, Type } from 'typebox';\n\nexport const MAX_QUESTIONS = 4;\nexport const MIN_OPTIONS = 2;\nexport const MAX_OPTIONS = 4;\nexport const MAX_HEADER_LENGTH = 16;\nexport const MAX_LABEL_LENGTH = 60;\n\nexport const RESERVED_LABELS = ['Other', 'Type something.', 'Next'] as const;\n\nexport const OptionSchema = Type.Object(\n {\n label: Type.String({\n maxLength: MAX_LABEL_LENGTH,\n description: 'MAX 60 CHARACTERS — hard limit. Concise option label shown to the user, ideally 1-5 words.',\n }),\n description: Type.String({\n description: 'Explanation of what the option means and its important trade-offs.',\n }),\n preview: Type.Optional(\n Type.String({ description: 'Optional markdown preview rendered while this option is focused.' }),\n ),\n },\n { additionalProperties: false },\n);\n\nexport const QuestionSchema = Type.Object(\n {\n question: Type.String({ description: 'The complete, clear question to ask the user.' }),\n header: Type.String({\n maxLength: MAX_HEADER_LENGTH,\n description: 'MAX 16 CHARACTERS — short label used when navigating several questions.',\n }),\n options: Type.Array(OptionSchema, {\n minItems: MIN_OPTIONS,\n maxItems: MAX_OPTIONS,\n description: 'The 2-4 choices offered for this question.',\n }),\n multiSelect: Type.Optional(\n Type.Boolean({ description: 'Allow more than one option to be selected.', default: false }),\n ),\n },\n { additionalProperties: false },\n);\n\nexport const QuestionParamsSchema = Type.Object(\n {\n questions: Type.Array(QuestionSchema, {\n minItems: 1,\n maxItems: MAX_QUESTIONS,\n description: 'Questions to ask the user (1-4 questions).',\n }),\n },\n { additionalProperties: false },\n);\n\nexport type OptionData = Static<typeof OptionSchema>;\nexport type QuestionData = Static<typeof QuestionSchema>;\nexport type QuestionParams = Static<typeof QuestionParamsSchema>;\n"],"mappings":"yBAQA,MAAa,EAAkB,CAAC,QAAS,kBAAmB,MAAM,EAErD,EAAeA,EAAAA,KAAK,OAC/B,CACE,MAAOA,EAAAA,KAAK,OAAO,CACjB,UAAA,GACA,YAAa,4FACf,CAAC,EACD,YAAaA,EAAAA,KAAK,OAAO,CACvB,YAAa,oEACf,CAAC,EACD,QAASA,EAAAA,KAAK,SACZA,EAAAA,KAAK,OAAO,CAAE,YAAa,kEAAmE,CAAC,CACjG,CACF,EACA,CAAE,qBAAsB,EAAM,CAChC,EAEa,EAAiBA,EAAAA,KAAK,OACjC,CACE,SAAUA,EAAAA,KAAK,OAAO,CAAE,YAAa,+CAAgD,CAAC,EACtF,OAAQA,EAAAA,KAAK,OAAO,CAClB,UAAA,GACA,YAAa,yEACf,CAAC,EACD,QAASA,EAAAA,KAAK,MAAM,EAAc,CAChC,SAAA,EACA,SAAA,EACA,YAAa,4CACf,CAAC,EACD,YAAaA,EAAAA,KAAK,SAChBA,EAAAA,KAAK,QAAQ,CAAE,YAAa,6CAA8C,QAAS,EAAM,CAAC,CAC5F,CACF,EACA,CAAE,qBAAsB,EAAM,CAChC,EAEa,EAAuBA,EAAAA,KAAK,OACvC,CACE,UAAWA,EAAAA,KAAK,MAAM,EAAgB,CACpC,SAAU,EACV,SAAA,EACA,YAAa,4CACf,CAAC,CACH,EACA,CAAE,qBAAsB,EAAM,CAChC"}
@@ -0,0 +1,18 @@
1
+ import { Static, Type } from "typebox";
2
+ //#region src/schemas/questionnaire.d.ts
3
+ declare const QuestionParamsSchema: Type.TObject<{
4
+ questions: Type.TArray<Type.TObject<{
5
+ question: Type.TString;
6
+ header: Type.TString;
7
+ options: Type.TArray<Type.TObject<{
8
+ label: Type.TString;
9
+ description: Type.TString;
10
+ preview: Type.TOptional<Type.TString>;
11
+ }>>;
12
+ multiSelect: Type.TOptional<Type.TBoolean>;
13
+ }>>;
14
+ }>;
15
+ type QuestionParams = Static<typeof QuestionParamsSchema>;
16
+ //#endregion
17
+ export { QuestionParams, QuestionParamsSchema };
18
+ //# sourceMappingURL=questionnaire.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questionnaire.d.cts","names":[],"sources":["../../src/schemas/questionnaire.ts"],"mappings":";;cA6Ca,sBAAoB,KAAA;;;;;;;;;;;;KAarB,iBAAiB,cAAc"}
@@ -0,0 +1,18 @@
1
+ import { Static, Type } from "typebox";
2
+ //#region src/schemas/questionnaire.d.ts
3
+ declare const QuestionParamsSchema: Type.TObject<{
4
+ questions: Type.TArray<Type.TObject<{
5
+ question: Type.TString;
6
+ header: Type.TString;
7
+ options: Type.TArray<Type.TObject<{
8
+ label: Type.TString;
9
+ description: Type.TString;
10
+ preview: Type.TOptional<Type.TString>;
11
+ }>>;
12
+ multiSelect: Type.TOptional<Type.TBoolean>;
13
+ }>>;
14
+ }>;
15
+ type QuestionParams = Static<typeof QuestionParamsSchema>;
16
+ //#endregion
17
+ export { QuestionParams, QuestionParamsSchema };
18
+ //# sourceMappingURL=questionnaire.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questionnaire.d.mts","names":[],"sources":["../../src/schemas/questionnaire.ts"],"mappings":";;cA6Ca,sBAAoB,KAAA;;;;;;;;;;;;KAarB,iBAAiB,cAAc"}
@@ -0,0 +1,2 @@
1
+ import{Type as e}from"typebox";const t=[`Other`,`Type something.`,`Next`],n=e.Object({label:e.String({maxLength:60,description:`MAX 60 CHARACTERS — hard limit. Concise option label shown to the user, ideally 1-5 words.`}),description:e.String({description:`Explanation of what the option means and its important trade-offs.`}),preview:e.Optional(e.String({description:`Optional markdown preview rendered while this option is focused.`}))},{additionalProperties:!1}),r=e.Object({question:e.String({description:`The complete, clear question to ask the user.`}),header:e.String({maxLength:16,description:`MAX 16 CHARACTERS — short label used when navigating several questions.`}),options:e.Array(n,{minItems:2,maxItems:4,description:`The 2-4 choices offered for this question.`}),multiSelect:e.Optional(e.Boolean({description:`Allow more than one option to be selected.`,default:!1}))},{additionalProperties:!1}),i=e.Object({questions:e.Array(r,{minItems:1,maxItems:4,description:`Questions to ask the user (1-4 questions).`})},{additionalProperties:!1});export{n as OptionSchema,i as QuestionParamsSchema,r as QuestionSchema,t as RESERVED_LABELS};
2
+ //# sourceMappingURL=questionnaire.mjs.map