{"version":3,"file":"runQuestionnaire-C4n_SWi2.mjs","names":[],"sources":["../src/tui/externalEditor.ts","../src/tui/questionnaireComponent.ts","../src/tui/runQuestionnaire.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport type { ExternalEditResult } from '../types/questionnaire';\n\nconst UTF8_ENCODING = 'utf8';\n\nfunction editorCommand(): string {\n  return process.env.VISUAL || process.env.EDITOR || (process.platform === 'win32' ? 'notepad' : 'nano');\n}\n\nfunction quoteFileArgument(file: string): string {\n  if (process.platform === 'win32') return `\"${file.replaceAll('\"', '\\\\\"')}\"`;\n  return `'${file.replaceAll(\"'\", `'\\\\''`)}'`;\n}\n\nfunction runEditor(command: string, file: string): Promise<ExternalEditResult | undefined> {\n  return new Promise((resolve) => {\n    const child = spawn(`${command} ${quoteFileArgument(file)}`, { shell: true, stdio: 'inherit' });\n    let settled = false;\n    const finish = (result: ExternalEditResult | undefined): void => {\n      if (settled) return;\n      settled = true;\n      resolve(result);\n    };\n    child.once('error', (error) => finish({ status: 'failed', message: `External editor failed: ${error.message}` }));\n    child.once('exit', (code, signal) => {\n      if (code === 0) finish(undefined);\n      else {\n        finish({\n          status: 'failed',\n          message: `External editor exited with ${code === null ? `signal ${String(signal)}` : `code ${String(code)}`}`,\n        });\n      }\n    });\n  });\n}\n\nexport async function editQuestionnaireText(content: string): Promise<ExternalEditResult> {\n  const directory = await mkdtemp(path.join(os.tmpdir(), 'doompi-user-feedback-'));\n  const file = path.join(directory, 'response.md');\n  try {\n    await writeFile(file, content, UTF8_ENCODING);\n    const failure = await runEditor(editorCommand(), file);\n    if (failure) return failure;\n    return { status: 'complete', content: await readFile(file, UTF8_ENCODING) };\n  } catch (error) {\n    return {\n      status: 'failed',\n      message: `External editor failed: ${error instanceof Error ? error.message : String(error)}`,\n    };\n  } finally {\n    await rm(directory, { recursive: true, force: true });\n  }\n}\n","import type { KeybindingsManager, Theme } from '@earendil-works/pi-coding-agent';\nimport {\n  Editor,\n  Key,\n  Markdown,\n  matchesKey,\n  type Focusable,\n  type MarkdownTheme,\n  type TUI,\n  truncateToWidth,\n  visibleWidth,\n  wrapTextWithAnsi,\n} from '@earendil-works/pi-tui';\n\nimport type { QuestionData, QuestionParams } from '../schemas/questionnaire';\nimport type { ExternalEditResult, QuestionAnswer, QuestionnaireResult } from '../types/questionnaire';\n\nexport interface QuestionnaireComponentOptions {\n  tui: TUI;\n  theme: Theme;\n  markdownTheme: MarkdownTheme;\n  keybindings: KeybindingsManager;\n  params: QuestionParams;\n  collapseKey: string;\n  done: (result: QuestionnaireResult) => void;\n  editExternally: (content: string) => Promise<ExternalEditResult>;\n  reportProgress?: (result: QuestionnaireResult) => void;\n}\n\ntype EditorMode = 'custom' | 'notes';\n\nconst SELECT_CANCEL_KEYBINDING = 'tui.select.cancel';\nconst EXTERNAL_EDITOR_KEYBINDING = 'app.editor.external';\n\nexport class QuestionnaireComponent implements Focusable {\n  private readonly answers = new Map<number, QuestionAnswer>();\n  private readonly selectedOptions = new Map<number, Set<number>>();\n  private readonly notes = new Map<number, string>();\n  private readonly editor: Editor;\n  private currentQuestion = 0;\n  private currentOption = 0;\n  private editorMode: EditorMode | undefined;\n  private collapsed = false;\n  private settled = false;\n  private externalEditorError: string | undefined;\n  private cachedLines: string[] | undefined;\n  private cachedWidth: number | undefined;\n  private isFocused = false;\n\n  constructor(private readonly options: QuestionnaireComponentOptions) {\n    this.editor = new Editor(options.tui, {\n      borderColor: (text) => options.theme.fg('accent', text),\n      selectList: {\n        selectedPrefix: (text) => options.theme.fg('accent', text),\n        selectedText: (text) => options.theme.fg('accent', text),\n        description: (text) => options.theme.fg('muted', text),\n        scrollInfo: (text) => options.theme.fg('dim', text),\n        noMatch: (text) => options.theme.fg('warning', text),\n      },\n    });\n    this.editor.onSubmit = (value) => this.submitEditor(value);\n  }\n\n  get focused(): boolean {\n    return this.isFocused;\n  }\n\n  set focused(value: boolean) {\n    this.isFocused = value;\n    this.editor.focused = value;\n    this.invalidate();\n  }\n\n  invalidate(): void {\n    this.cachedLines = undefined;\n    this.cachedWidth = undefined;\n  }\n\n  cancel(): void {\n    this.finish(true);\n  }\n\n  handleInput(data: string): void {\n    if (this.settled) return;\n\n    if (\n      this.options.collapseKey !== 'off' &&\n      matchesKey(data, this.options.collapseKey as Parameters<typeof matchesKey>[1])\n    ) {\n      this.collapsed = !this.collapsed;\n      this.refresh();\n      return;\n    }\n\n    if (this.collapsed) return;\n\n    if (this.editorMode) {\n      if (this.options.keybindings.matches(data, SELECT_CANCEL_KEYBINDING)) {\n        this.editorMode = undefined;\n        this.externalEditorError = undefined;\n        this.editor.setText('');\n        this.refresh();\n        return;\n      }\n      if (this.options.keybindings.matches(data, EXTERNAL_EDITOR_KEYBINDING)) {\n        void this.openExternalEditor();\n        return;\n      }\n      this.editor.handleInput(data);\n      this.refresh();\n      return;\n    }\n\n    if (this.options.keybindings.matches(data, SELECT_CANCEL_KEYBINDING)) {\n      this.cancel();\n      return;\n    }\n    if (matchesKey(data, Key.up)) {\n      this.moveOption(-1);\n      return;\n    }\n    if (matchesKey(data, Key.down)) {\n      this.moveOption(1);\n      return;\n    }\n    if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {\n      this.moveQuestion(1);\n      return;\n    }\n    if (matchesKey(data, Key.shift('tab')) || matchesKey(data, Key.left)) {\n      this.moveQuestion(-1);\n      return;\n    }\n    if (matchesKey(data, 'n') || matchesKey(data, Key.shift('n'))) {\n      this.openEditor('notes');\n      return;\n    }\n    if (matchesKey(data, Key.space) || data === ' ') {\n      this.toggleCurrentOption();\n      return;\n    }\n    if (matchesKey(data, Key.enter)) {\n      this.confirmCurrentSelection();\n    }\n  }\n\n  render(width: number): string[] {\n    const renderWidth = Math.max(1, width);\n    if (this.cachedLines && this.cachedWidth === renderWidth) return this.cachedLines;\n    this.cachedWidth = renderWidth;\n    if (this.collapsed) {\n      const lines: string[] = [];\n      const answerCount = this.answers.size;\n      this.addWrapped(\n        lines,\n        '',\n        this.options.theme.fg(\n          'accent',\n          `▸ Questionnaire (${answerCount}/${this.options.params.questions.length} answered) — ${this.options.collapseKey} to expand`,\n        ),\n        renderWidth,\n      );\n      this.cachedLines = lines;\n      return lines;\n    }\n\n    const lines: string[] = [];\n    const question = this.question();\n    const border = this.options.theme.fg('accent', '─'.repeat(renderWidth));\n    lines.push(border);\n    this.addWrapped(lines, ' ', this.renderTabs(), renderWidth);\n    lines.push('');\n    this.addWrapped(lines, ' ', this.options.theme.bold(question.question), renderWidth);\n    lines.push('');\n\n    this.renderOptions(lines, question, renderWidth);\n    this.renderPreview(lines, question, renderWidth);\n    this.renderNotes(lines, renderWidth);\n    this.renderEditor(lines, renderWidth);\n    lines.push('');\n    this.addWrapped(lines, ' ', this.helpText(question), renderWidth);\n    lines.push(border);\n    this.cachedLines = lines;\n    return lines;\n  }\n\n  private question(): QuestionData {\n    const question = this.options.params.questions[this.currentQuestion];\n    if (!question) throw new Error('Questionnaire has no active question');\n    return question;\n  }\n\n  private optionCount(question: QuestionData): number {\n    return question.options.length + 1;\n  }\n\n  private renderTabs(): string {\n    const tabs = this.options.params.questions.map((question, index) => {\n      const mark = this.answers.has(index) ? '✓' : '○';\n      const label = ` ${mark} ${question.header} `;\n      return index === this.currentQuestion\n        ? this.options.theme.bg('selectedBg', this.options.theme.fg('text', label))\n        : this.options.theme.fg(this.answers.has(index) ? 'success' : 'muted', label);\n    });\n    return tabs.join(' ');\n  }\n\n  private renderOptions(lines: string[], question: QuestionData, width: number): void {\n    const selected = this.selectedOptions.get(this.currentQuestion) ?? new Set<number>();\n    question.options.forEach((option, index) => {\n      const focused = index === this.currentOption;\n      const checked = question.multiSelect ? (selected.has(index) ? '[x]' : '[ ]') : `${index + 1}.`;\n      const prefix = focused ? this.options.theme.fg('accent', '> ') : '  ';\n      const label = `${checked} ${option.label}`;\n      this.addWrapped(lines, prefix, this.options.theme.fg(focused ? 'accent' : 'text', label), width);\n      if (option.description) {\n        this.addWrapped(lines, '      ', this.options.theme.fg('muted', option.description), width);\n      }\n    });\n\n    const customIndex = question.options.length;\n    const customFocused = this.currentOption === customIndex;\n    this.addWrapped(\n      lines,\n      customFocused ? this.options.theme.fg('accent', '> ') : '  ',\n      this.options.theme.fg(customFocused ? 'accent' : 'text', '✎ Type something.'),\n      width,\n    );\n  }\n\n  private renderPreview(lines: string[], question: QuestionData, width: number): void {\n    if (this.currentOption >= question.options.length) return;\n    const preview = question.options[this.currentOption]?.preview;\n    if (!preview) return;\n    lines.push('');\n    this.addWrapped(lines, ' ', this.options.theme.fg('accent', this.options.theme.bold('Preview')), width);\n    const markdown = new Markdown(\n      preview,\n      0,\n      0,\n      this.options.markdownTheme,\n      { color: (text) => this.options.theme.fg('muted', text) },\n      { preserveOrderedListMarkers: true, preserveBackslashEscapes: true },\n    );\n    for (const previewLine of markdown.render(Math.max(1, width - 3))) {\n      this.addWrapped(lines, ' │ ', previewLine || ' ', width);\n    }\n  }\n\n  private renderNotes(lines: string[], width: number): void {\n    const note = this.notes.get(this.currentQuestion);\n    if (!note || this.editorMode === 'notes') return;\n    lines.push('');\n    this.addWrapped(lines, ' ', this.options.theme.fg('muted', `Note: ${note}`), width);\n  }\n\n  private renderEditor(lines: string[], width: number): void {\n    if (!this.editorMode) return;\n    lines.push('');\n    const label = this.editorMode === 'custom' ? 'Your answer:' : 'Optional note:';\n    this.addWrapped(lines, ' ', this.options.theme.fg('muted', label), width);\n    for (const line of this.editor.render(Math.max(1, width - 2))) {\n      lines.push(truncateToWidth(` ${line}`, width, ''));\n    }\n    if (this.externalEditorError) {\n      this.addWrapped(lines, ' ', this.options.theme.fg('warning', this.externalEditorError), width);\n    }\n  }\n\n  private helpText(question: QuestionData): string {\n    if (this.editorMode) return 'Enter submit • Esc/Ctrl+C return • Ctrl+G external editor';\n    const selectionHelp = question.multiSelect ? 'Space toggle • Enter confirm' : 'Enter select';\n    return `Tab/←→ questions • ↑↓ options • ${selectionHelp} • N note • Esc/Ctrl+C cancel`;\n  }\n\n  private addWrapped(lines: string[], prefix: string, text: string, width: number): void {\n    const prefixWidth = Math.min(visibleWidth(prefix), Math.max(0, width - 1));\n    const renderedPrefix = truncateToWidth(prefix, prefixWidth, '');\n    const available = Math.max(1, width - prefixWidth);\n    const wrapped = wrapTextWithAnsi(text, available);\n    if (wrapped.length === 0) {\n      lines.push(renderedPrefix);\n      return;\n    }\n    for (let index = 0; index < wrapped.length; index += 1) {\n      const linePrefix = index === 0 ? renderedPrefix : ' '.repeat(prefixWidth);\n      lines.push(truncateToWidth(`${linePrefix}${wrapped[index]}`, width, ''));\n    }\n  }\n\n  private moveOption(delta: number): void {\n    const count = this.optionCount(this.question());\n    this.currentOption = (this.currentOption + delta + count) % count;\n    this.refresh();\n  }\n\n  private moveQuestion(delta: number): void {\n    const count = this.options.params.questions.length;\n    this.currentQuestion = (this.currentQuestion + delta + count) % count;\n    this.currentOption = 0;\n    this.refresh();\n  }\n\n  private toggleCurrentOption(): void {\n    const question = this.question();\n    if (!question.multiSelect || this.currentOption >= question.options.length) return;\n    const selected = this.selectedOptions.get(this.currentQuestion) ?? new Set<number>();\n    if (selected.has(this.currentOption)) selected.delete(this.currentOption);\n    else selected.add(this.currentOption);\n    this.selectedOptions.set(this.currentQuestion, selected);\n    this.refresh();\n  }\n\n  private confirmCurrentSelection(): void {\n    const question = this.question();\n    if (this.currentOption === question.options.length) {\n      this.openEditor('custom');\n      return;\n    }\n\n    if (question.multiSelect) {\n      const selected = this.selectedOptions.get(this.currentQuestion) ?? new Set<number>();\n      if (selected.size === 0) selected.add(this.currentOption);\n      const labels = [...selected]\n        .sort((left, right) => left - right)\n        .flatMap((index) => (question.options[index] ? [question.options[index].label] : []));\n      this.recordAnswer({\n        questionIndex: this.currentQuestion,\n        question: question.question,\n        kind: 'multi',\n        answer: null,\n        selected: labels,\n        ...this.noteFields(),\n      });\n      return;\n    }\n\n    const option = question.options[this.currentOption];\n    if (!option) return;\n    this.recordAnswer({\n      questionIndex: this.currentQuestion,\n      question: question.question,\n      kind: 'option',\n      answer: option.label,\n      ...(option.preview ? { preview: option.preview } : {}),\n      ...this.noteFields(),\n    });\n  }\n\n  private openEditor(mode: EditorMode): void {\n    this.editorMode = mode;\n    this.externalEditorError = undefined;\n    this.editor.setText(mode === 'notes' ? (this.notes.get(this.currentQuestion) ?? '') : '');\n    this.refresh();\n  }\n\n  private async openExternalEditor(): Promise<void> {\n    const editorMode = this.editorMode;\n    if (!editorMode) return;\n    this.options.tui.stop();\n    try {\n      const result = await this.options.editExternally(this.editor.getText());\n      if (this.settled || this.editorMode !== editorMode) return;\n      if (result.status === 'complete') {\n        this.editor.setText(result.content);\n        this.externalEditorError = undefined;\n      } else {\n        this.externalEditorError = result.message;\n      }\n    } catch (error) {\n      this.externalEditorError = `External editor failed: ${error instanceof Error ? error.message : String(error)}`;\n    } finally {\n      this.options.tui.start();\n      this.refresh();\n    }\n  }\n\n  private submitEditor(value: string): void {\n    const mode = this.editorMode;\n    this.editorMode = undefined;\n    this.editor.setText('');\n    if (mode === 'notes') {\n      const trimmed = value.trim();\n      if (trimmed) this.notes.set(this.currentQuestion, trimmed);\n      else this.notes.delete(this.currentQuestion);\n      const answer = this.answers.get(this.currentQuestion);\n      if (answer) {\n        this.answers.set(this.currentQuestion, {\n          ...answer,\n          ...(trimmed ? { notes: trimmed } : { notes: undefined }),\n        });\n        this.reportProgress();\n      }\n      this.refresh();\n      return;\n    }\n    if (mode === 'custom') {\n      this.recordAnswer({\n        questionIndex: this.currentQuestion,\n        question: this.question().question,\n        kind: 'custom',\n        answer: value,\n        ...this.noteFields(),\n      });\n    }\n  }\n\n  private noteFields(): { notes?: string } {\n    const note = this.notes.get(this.currentQuestion);\n    return note ? { notes: note } : {};\n  }\n\n  private recordAnswer(answer: QuestionAnswer): void {\n    this.answers.set(this.currentQuestion, answer);\n    this.reportProgress();\n    if (this.answers.size === this.options.params.questions.length) {\n      this.finish(false);\n      return;\n    }\n    const next = this.options.params.questions.findIndex(\n      (_question, index) => index > this.currentQuestion && !this.answers.has(index),\n    );\n    this.currentQuestion =\n      next >= 0 ? next : this.options.params.questions.findIndex((_question, index) => !this.answers.has(index));\n    this.currentOption = 0;\n    this.refresh();\n  }\n\n  private orderedAnswers(): QuestionAnswer[] {\n    return [...this.answers.values()]\n      .sort((left, right) => left.questionIndex - right.questionIndex)\n      .map((answer) => ({ ...answer }));\n  }\n\n  private reportProgress(): void {\n    this.options.reportProgress?.({ answers: this.orderedAnswers(), cancelled: false });\n  }\n\n  private finish(cancelled: boolean): void {\n    if (this.settled) return;\n    this.settled = true;\n    this.options.done({ answers: this.orderedAnswers(), cancelled });\n  }\n\n  private refresh(): void {\n    this.invalidate();\n    this.options.tui.requestRender();\n  }\n}\n","import { getMarkdownTheme, type ExtensionContext } from '@earendil-works/pi-coding-agent';\n\nimport type { QuestionParams } from '../schemas/questionnaire';\nimport type { QuestionnaireResult } from '../types/questionnaire';\nimport { editQuestionnaireText } from './externalEditor';\nimport { QuestionnaireComponent } from './questionnaireComponent';\n\nexport async function runTuiQuestionnaire(\n  context: ExtensionContext,\n  params: QuestionParams,\n  collapseKey: string,\n  signal?: AbortSignal,\n  reportProgress?: (result: QuestionnaireResult) => void,\n): Promise<QuestionnaireResult | undefined> {\n  let component: QuestionnaireComponent | undefined;\n  const cancel = (): void => component?.cancel();\n  signal?.addEventListener('abort', cancel, { once: true });\n  try {\n    return await context.ui.custom<QuestionnaireResult>((tui, theme, keybindings, done) => {\n      component = new QuestionnaireComponent({\n        tui,\n        theme,\n        markdownTheme: getMarkdownTheme(),\n        keybindings,\n        params,\n        collapseKey,\n        done,\n        editExternally: editQuestionnaireText,\n        ...(reportProgress ? { reportProgress } : {}),\n      });\n      if (signal?.aborted) component.cancel();\n      return component;\n    });\n  } finally {\n    signal?.removeEventListener('abort', cancel);\n  }\n}\n"],"mappings":";;;;;;;AAOA,MAAM,gBAAgB;AAEtB,SAAS,gBAAwB;CAC/B,OAAO,QAAQ,IAA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