@geoqiao/pi-ask 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/LICENSE +22 -0
  3. package/README.md +282 -0
  4. package/docs/README.md +33 -0
  5. package/docs/configuration.md +406 -0
  6. package/docs/contract.md +309 -0
  7. package/docs/remote-events.md +187 -0
  8. package/package.json +130 -0
  9. package/skills/ask-user/SKILL.md +110 -0
  10. package/src/answer-commands.ts +361 -0
  11. package/src/answer-extraction.ts +354 -0
  12. package/src/ask-payload-store.ts +86 -0
  13. package/src/ask-settings-command.ts +14 -0
  14. package/src/ask-tool-helpers.ts +172 -0
  15. package/src/ask-tool.ts +84 -0
  16. package/src/config/defaults.ts +216 -0
  17. package/src/config/migrate.ts +70 -0
  18. package/src/config/migrations/index.ts +139 -0
  19. package/src/config/migrations/types.ts +10 -0
  20. package/src/config/schema.ts +287 -0
  21. package/src/config/store.ts +227 -0
  22. package/src/constants/keymaps.ts +721 -0
  23. package/src/constants/text.ts +12 -0
  24. package/src/constants/ui.ts +22 -0
  25. package/src/index.ts +30 -0
  26. package/src/math.ts +3 -0
  27. package/src/notifications.ts +119 -0
  28. package/src/remote-ask.ts +563 -0
  29. package/src/result-format.ts +157 -0
  30. package/src/result.ts +23 -0
  31. package/src/schema.ts +74 -0
  32. package/src/state/answers.ts +251 -0
  33. package/src/state/create.ts +18 -0
  34. package/src/state/editor.ts +70 -0
  35. package/src/state/navigation.ts +86 -0
  36. package/src/state/normalize.ts +326 -0
  37. package/src/state/question-type.ts +128 -0
  38. package/src/state/result.ts +263 -0
  39. package/src/state/selectors.ts +135 -0
  40. package/src/state/transitions.ts +330 -0
  41. package/src/state/view.ts +28 -0
  42. package/src/text.ts +98 -0
  43. package/src/types.ts +169 -0
  44. package/src/ui/auto-submit.ts +36 -0
  45. package/src/ui/autocomplete.ts +52 -0
  46. package/src/ui/controller.ts +645 -0
  47. package/src/ui/dismiss-guard.ts +26 -0
  48. package/src/ui/input.ts +160 -0
  49. package/src/ui/render-frame.ts +235 -0
  50. package/src/ui/render-helpers.ts +385 -0
  51. package/src/ui/render-question.ts +288 -0
  52. package/src/ui/render-submit.ts +168 -0
  53. package/src/ui/render-types.ts +33 -0
  54. package/src/ui/render.ts +53 -0
  55. package/src/ui/review-shortcuts.ts +43 -0
  56. package/src/ui/settings-list.ts +461 -0
  57. package/src/ui/show-settings.ts +37 -0
  58. package/src/ui/view-models/question.ts +203 -0
  59. package/src/ui/view-models/review.ts +100 -0
@@ -0,0 +1,100 @@
1
+ import { visibleWidth } from "@earendil-works/pi-tui";
2
+ import { SUBMIT_CHOICES } from "../../constants/text.ts";
3
+ import { UI_DIMENSIONS } from "../../constants/ui.ts";
4
+ import { isCustomOnlyAnswer } from "../../state/answers.ts";
5
+ import {
6
+ type ReviewAnswer,
7
+ shouldRenderAnswersIndividually,
8
+ toReviewAnswer,
9
+ } from "../../state/result.ts";
10
+ import type { AskState } from "../../types.ts";
11
+
12
+ export interface ReviewSelectionModel {
13
+ label: string;
14
+ note?: string;
15
+ }
16
+
17
+ export interface ReviewQuestionModel {
18
+ answerText?: string;
19
+ extraOptionNotes?: Array<{ label: string; note: string }>;
20
+ isCustomOnly?: boolean;
21
+ label: string;
22
+ note?: string;
23
+ selections?: ReviewSelectionModel[];
24
+ unanswered: boolean;
25
+ }
26
+
27
+ export interface ReviewScreenModel {
28
+ actionColumnWidth: number;
29
+ actions: Array<{ label: string; selected: boolean }>;
30
+ layout: "stacked" | "wide";
31
+ questions: ReviewQuestionModel[];
32
+ }
33
+
34
+ export function buildReviewScreenModel(
35
+ state: AskState,
36
+ width: number
37
+ ): ReviewScreenModel {
38
+ const showAllNotes = state.activeSubmitActionIndex === 1;
39
+ const actionColumnWidth = getSubmitActionColumnWidth();
40
+ return {
41
+ actionColumnWidth,
42
+ actions: SUBMIT_CHOICES.map((label, index) => ({
43
+ label,
44
+ selected: index === state.activeSubmitActionIndex,
45
+ })),
46
+ layout: shouldUseWideSubmitLayout(width, actionColumnWidth)
47
+ ? "wide"
48
+ : "stacked",
49
+ questions: state.questions.map((question) =>
50
+ toReviewQuestionModel(
51
+ question.label,
52
+ toReviewAnswer(question, state.answers[question.id], showAllNotes)
53
+ )
54
+ ),
55
+ };
56
+ }
57
+
58
+ function toReviewQuestionModel(
59
+ label: string,
60
+ answer: ReviewAnswer | undefined
61
+ ): ReviewQuestionModel {
62
+ if (!answer) {
63
+ return { label, unanswered: true };
64
+ }
65
+
66
+ return {
67
+ answerText: shouldRenderAnswersIndividually(answer)
68
+ ? undefined
69
+ : answer.labels.join(", "),
70
+ extraOptionNotes: answer.extraOptionNotes,
71
+ isCustomOnly: isCustomOnlyAnswer(answer),
72
+ label,
73
+ note: answer.note,
74
+ selections: shouldRenderAnswersIndividually(answer)
75
+ ? answer.labels.map((selectionLabel, index) => ({
76
+ label: selectionLabel,
77
+ note: answer.optionNotes?.[answer.values[index] ?? selectionLabel],
78
+ }))
79
+ : undefined,
80
+ unanswered: false,
81
+ };
82
+ }
83
+
84
+ function getSubmitActionColumnWidth(): number {
85
+ return Math.max(
86
+ ...SUBMIT_CHOICES.map((choice, index) =>
87
+ visibleWidth(`❯ ${index + 1}. ${choice}`)
88
+ )
89
+ );
90
+ }
91
+
92
+ function shouldUseWideSubmitLayout(
93
+ width: number,
94
+ actionColumnWidth: number
95
+ ): boolean {
96
+ return (
97
+ width >= UI_DIMENSIONS.submitWideMinWidth &&
98
+ width - actionColumnWidth - 2 >= UI_DIMENSIONS.submitMinReviewWidth
99
+ );
100
+ }