@jackice/pi-approval-gate 0.1.4 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5
4
+
5
+ - Add OMP-style borders, spacing, and keyboard hints to the default approval dialog. Adapt the command preview to fit the choices and bottom border in short terminals.
6
+
3
7
  ## 0.1.4
4
8
 
5
9
  - English code comments, changelog, and review notes. No behavior change.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackice/pi-approval-gate",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Dangerous bash approval gate for Pi with final execution-parameter binding.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,12 +25,12 @@ export function createNativeApprovalView(
25
25
  });
26
26
  const limit = maxCommandLines !== undefined && Number.isFinite(maxCommandLines) && maxCommandLines >= 1
27
27
  ? Math.floor(maxCommandLines) : 8;
28
- const title = `Bash approval · ${escapeControls(request.toolName)}`;
28
+ const title = `Allow tool: ${escapeControls(request.toolName)}`;
29
29
  const risk = `Risk: ${request.risk.toUpperCase()}`;
30
30
  const fields = [
31
- `cwd: ${escapeControls(request.cwd)}`,
32
- `reason: ${escapeControls(request.reason)}`,
33
- `command: ${escapeControls(request.command)}`,
31
+ `Reason: ${escapeControls(request.reason)}`,
32
+ `Cwd: ${escapeControls(request.cwd)}`,
33
+ `Command: ${escapeControls(request.command)}`,
34
34
  ];
35
35
  let overlayHandle: OverlayHandle | undefined;
36
36
  let lines: string[] = [];
@@ -61,44 +61,57 @@ export function createNativeApprovalView(
61
61
  renderedContextFits = false;
62
62
  return [];
63
63
  }
64
+ const inset = width > 2 ? " " : "";
65
+ const innerWidth = width - 2 * inset.length;
64
66
  if (lastWidth !== width) {
65
67
  lastWidth = width;
66
- lines = fields.flatMap((field) => wrapCodeText(field, width));
68
+ lines = fields.flatMap((field) => wrapCodeText(field, innerWidth));
67
69
  }
68
- pageRows = Math.max(1, Math.min(limit, Math.floor(tui.terminal.rows * 0.75) - 6));
70
+ const terminalRows = tui.terminal.rows;
71
+ // Match the overlay's height cap, including its top and bottom margins.
72
+ const availableRows = Math.min(Math.floor(terminalRows * 0.9), terminalRows - 2);
73
+ const spacer = availableRows >= 15 ? [""] : [];
74
+ const fixedRows = 8 + 4 * spacer.length;
75
+ pageRows = Math.max(1, Math.min(limit, availableRows - fixedRows));
69
76
  offset = Math.min(offset, Math.max(0, lines.length - pageRows));
70
77
  const end = Math.min(lines.length, offset + pageRows);
71
78
  const fullPage = `Page ${offset + 1}-${end}/${lines.length}`;
72
79
  const compactRange = `${offset + 1}-${end}/${lines.length}`;
73
80
  const currentPage = `${offset + 1}/${lines.length}`;
74
- const page = visibleWidth(fullPage) <= width
81
+ const page = visibleWidth(fullPage) <= innerWidth
75
82
  ? fullPage
76
- : visibleWidth(compactRange) <= width
83
+ : visibleWidth(compactRange) <= innerWidth
77
84
  ? compactRange
78
- : visibleWidth(currentPage) <= width
85
+ : visibleWidth(currentPage) <= innerWidth
79
86
  ? currentPage
80
87
  : String(offset + 1);
81
- const riskLabel = visibleWidth(risk) <= width
88
+ const riskLabel = visibleWidth(risk) <= innerWidth
82
89
  ? risk
83
- : visibleWidth(`Risk: ${request.risk[0]!.toUpperCase()}`) <= width
90
+ : visibleWidth(`Risk: ${request.risk[0]!.toUpperCase()}`) <= innerWidth
84
91
  ? `Risk: ${request.risk[0]!.toUpperCase()}`
85
92
  : request.risk[0]!.toUpperCase();
86
- const hint = "PgUp/PgDn: scroll · Esc: deny";
87
- const choices = selection.render(width);
88
- const output = [
89
- truncateToWidth(theme.fg("warning", title), width),
90
- truncateToWidth(theme.fg("warning", riskLabel), width),
91
- truncateToWidth(theme.fg("muted", page), width),
93
+ const controls = "↑/↓ navigate Enter select Esc deny PgUp/PgDn scroll";
94
+ const hint = visibleWidth(controls) <= innerWidth ? controls : "↑/↓ Enter Esc PgUp/PgDn";
95
+ const choices = selection.render(innerWidth);
96
+ const border = theme.fg("border", "─".repeat(width));
97
+ const body = [
98
+ ...spacer,
99
+ theme.fg("accent", title),
100
+ theme.fg("warning", riskLabel),
101
+ theme.fg("muted", page),
92
102
  ...lines.slice(offset, end),
93
- truncateToWidth(theme.fg("muted", hint), width),
103
+ ...spacer,
94
104
  ...choices,
105
+ ...spacer,
106
+ theme.fg("dim", hint),
107
+ ...spacer,
95
108
  ];
109
+ const output = [border, ...body.map((line) => inset + truncateToWidth(line, innerWidth)), border];
96
110
  renderedWidth = width;
97
111
  renderedRows = output.length;
98
- renderedContextFits = [title, riskLabel, page, hint].every((line) => visibleWidth(line) <= width)
99
- && choices.length > 0
100
- && choices.every((line) => visibleWidth(line) <= width)
101
- && choices.some((line) => line.includes("Allow once"));
112
+ renderedContextFits = body.every((line) => visibleWidth(line) <= innerWidth)
113
+ && choices[0]?.includes("Deny") === true
114
+ && choices[1]?.includes("Allow once") === true;
102
115
  return output;
103
116
  },
104
117
  invalidate(): void {