@trim21/personal-pi-extensions 0.0.293 → 0.0.295

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.293",
3
+ "version": "0.0.295",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
package/src/lib/ui.ts CHANGED
@@ -53,19 +53,21 @@ export async function selectWithOptionalInput(
53
53
  };
54
54
  }
55
55
 
56
- const CHECKED_PREFIX = "[X]: ";
57
- const UNCHECKED_PREFIX = "[ ]: ";
56
+ /** 已选 / 未选 的符号标记:打勾方框 / 空方框 */
57
+ const CHECKED_PREFIX = " ";
58
+ const UNCHECKED_PREFIX = "☐ ";
58
59
 
59
60
  /**
60
61
  * Toggle-style multi-select loop built on `ui.select`.
61
62
  *
62
63
  * Every round lists ALL `entries` — already-selected ones render with a
63
- * `[X]: ` checkbox marker, the rest with `[ ]: ` — so re-selecting an entry
64
- * unchecks it. Picking an entry with `inputPrompt` opens an input dialog and,
65
- * when non-empty, adds the typed text and ends the loop. Picking `doneLabel`
66
- * (or dismissing the dialog) ends the loop and returns the selected labels in
67
- * selection order. Display text is mapped back to the original label via an
68
- * explicit table so a `[ ]:` / `[X]:` prefix inside a label is unambiguous.
64
+ * `☑ ` marker, the rest with `☐ ` — so re-selecting an entry unchecks it.
65
+ * Picking an entry with `inputPrompt` opens an input dialog; the typed text
66
+ * joins the selection as a `☑ ` row in later rounds and can be unselected
67
+ * like any other entry. Picking `doneLabel` (or dismissing the dialog) ends
68
+ * the loop and returns the selected labels in selection order. Display text
69
+ * is mapped back to the original label via an explicit table so a `☐ ` /
70
+ * `☑ ` prefix inside a label is unambiguous.
69
71
  */
70
72
  export async function selectMultiple(
71
73
  title: string,
@@ -77,11 +79,19 @@ export async function selectMultiple(
77
79
  while (true) {
78
80
  const selectedSet = new Set(selected);
79
81
  const displayToLabel = new Map<string, string>();
80
- const round = entries.map((entry) => {
82
+ const round: SelectAction[] = [];
83
+ for (const entry of entries) {
81
84
  const display = `${selectedSet.has(entry.label) ? CHECKED_PREFIX : UNCHECKED_PREFIX}${entry.label}`;
82
85
  displayToLabel.set(display, entry.label);
83
- return { ...entry, label: display };
84
- });
86
+ round.push({ ...entry, label: display });
87
+ }
88
+ // 经 inputPrompt 输入的自定义答案不是固定条目:单独列出,同样可反选
89
+ for (const label of selected) {
90
+ if (entries.some((entry) => entry.label === label)) continue;
91
+ const display = `${CHECKED_PREFIX}${label}`;
92
+ displayToLabel.set(display, label);
93
+ round.push({ label: display });
94
+ }
85
95
  const result = await selectWithOptionalInput(
86
96
  title,
87
97
  [...round, { label: opts.doneLabel }],
@@ -90,8 +100,9 @@ export async function selectMultiple(
90
100
  );
91
101
  if (result === undefined || result.label === opts.doneLabel) break;
92
102
  if (result.prompted) {
93
- if (result.input) selected.push(result.input);
94
- break;
103
+ // 自定义答案进入已选并继续循环:可反选或继续勾选,最终手动提交
104
+ if (result.input && !selectedSet.has(result.input)) selected.push(result.input);
105
+ continue;
95
106
  }
96
107
  const label = displayToLabel.get(result.label);
97
108
  if (label === undefined) continue;
@@ -5,13 +5,13 @@
5
5
  * https://github.com/anomalyco/opencode/blob/999be62662/packages/opencode/src/tool/question.ts
6
6
  * 与 opencode 的差异:opencode 输出 title "Asked N question(s)",这里未设置;
7
7
  * 多选交互是平台差异(opencode 用 checkbox,这里循环 ctx.ui.select 勾选,
8
- * 已选项显示 `[X]: ` 前缀,再次选择即反选,最后选「✓ Done」提交)。
8
+ * 已选项显示 `☑ ` 前缀,再次选择即反选,最后选「✓ Done」提交)。
9
9
  *
10
10
  * 参数与语义和 opencode 的 `question` 工具一致:
11
11
  * questions 数组,每项含 question / header / options / multiple:
12
12
  * - options 每项为 label / description
13
13
  * - 单选(默认):用户在选项里选一个,也可选「Type your own answer.」自由输入
14
- * - 多选(multiple: true):循环用 ui.select 勾选/反选([X] 标记已选),直到「✓ Done」
14
+ * - 多选(multiple: true):循环用 ui.select 勾选/反选(☑ 标记已选),直到「✓ Done」
15
15
  * - 每个问题返回一个 label 数组(Answer = string[]),跳过的为空数组
16
16
  * - 输出与 opencode 一致:
17
17
  * User has answered your questions: "q"="a", "q2"="Unanswered"...