@narumitw/pi-plan-mode 0.53.0 → 0.54.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.
package/dist/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
- // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
2
+ // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  IMPLEMENTATION_PLAN_RETENTIONS,
5
5
  PLAN_HISTORY_IMPLEMENTATION_PROMPT,
@@ -22,6 +22,7 @@ import {
22
22
  exportStoredPlan,
23
23
  filterAvailableSelectedToolNames,
24
24
  findBlockedCommandSegment,
25
+ findBlockedPowerShellCommandSegment,
25
26
  implementationRetentionPreview,
26
27
  invalidPlanMessage,
27
28
  latestAssistantStopReason,
@@ -42,7 +43,7 @@ import {
42
43
  toolPolicyLabel,
43
44
  unique,
44
45
  updatePlanModeSettings
45
- } from "./chunks/chunk-D2V3VWND.js";
46
+ } from "./chunks/chunk-U5CQ7RQX.js";
46
47
 
47
48
  // src/plan-mode.ts
48
49
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -643,34 +644,43 @@ function createPlanExportController(options) {
643
644
  }
644
645
 
645
646
  // src/presentation.ts
647
+ import { stripTerminalSequences, truncateToWidth } from "@earendil-works/pi-tui";
646
648
  var STATUS_KEY = "plan-mode";
647
649
  var PLAN_WIDGET_KEY = "plan-mode-plan";
650
+ var BIDI_CONTROLS = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
648
651
  function updatePlanModeUi(ctx, state, toolSummary) {
649
652
  ctx.ui.setStatus(STATUS_KEY, formatStatus(state));
653
+ let lines;
650
654
  if (state.enabled && state.latestPlan) {
651
- ctx.ui.setWidget(PLAN_WIDGET_KEY, [
652
- "Proposed plan ready",
653
- "Use /plan to implement, save, revise, or exit Plan mode."
654
- ]);
655
+ lines = ["Proposed plan ready", "Use /plan to implement, save, revise, or exit Plan mode."];
655
656
  } else if (state.enabled) {
656
- ctx.ui.setWidget(PLAN_WIDGET_KEY, [
657
+ lines = [
657
658
  "Plan mode: planning",
658
659
  toolSummary(),
659
660
  "Finish with plan_mode_complete when decision-ready."
660
- ]);
661
+ ];
661
662
  } else if (state.savedPlan) {
662
- ctx.ui.setWidget(PLAN_WIDGET_KEY, [
663
- "Plan saved for later",
664
- "Use /plan to show, implement, or clear it."
665
- ]);
663
+ lines = ["Plan saved for later", "Use /plan to show, implement, or clear it."];
666
664
  } else if (state.activeImplementation) {
667
- ctx.ui.setWidget(PLAN_WIDGET_KEY, [
668
- "Implementation plan active",
669
- "Use /plan to show, replace, or clear it."
670
- ]);
671
- } else {
672
- ctx.ui.setWidget(PLAN_WIDGET_KEY, void 0);
665
+ lines = ["Implementation plan active", "Use /plan to show, replace, or clear it."];
666
+ }
667
+ publishPlanModeWidget(ctx, lines);
668
+ }
669
+ function renderPlanModeWidget(lines, theme, width) {
670
+ const renderWidth = Math.max(0, width);
671
+ return [
672
+ theme.fg("borderMuted", "\u2500".repeat(renderWidth)),
673
+ ...lines.map((line) => truncateToWidth(sanitizePlanModeWidgetLine(line), renderWidth, ""))
674
+ ];
675
+ }
676
+ function sanitizePlanModeWidgetLine(value) {
677
+ let text = "";
678
+ for (const character of stripTerminalSequences(value).replace(BIDI_CONTROLS, "")) {
679
+ const codePoint = character.codePointAt(0) ?? 0;
680
+ const isControl = codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
681
+ text += isControl ? " " : character;
673
682
  }
683
+ return text;
674
684
  }
675
685
  function clearPlanModeUi(ctx) {
676
686
  ctx.ui.setStatus(STATUS_KEY, void 0);
@@ -722,6 +732,22 @@ function planModeStatusText(state, toolSummary) {
722
732
  if (state.activeImplementation) return "An implementation plan is active.";
723
733
  return "Plan mode is off.";
724
734
  }
735
+ function publishPlanModeWidget(ctx, lines) {
736
+ if (!lines) {
737
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, void 0);
738
+ return;
739
+ }
740
+ if (ctx.mode !== "tui") {
741
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, [...lines]);
742
+ return;
743
+ }
744
+ const snapshot = [...lines];
745
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, (_tui, theme) => ({
746
+ render: (width) => renderPlanModeWidget(snapshot, theme, width),
747
+ invalidate: () => {
748
+ }
749
+ }));
750
+ }
725
751
  function formatStatus(state) {
726
752
  if (state.enabled) {
727
753
  if (state.awaitingAction || state.latestPlan) return "plan ready";
@@ -939,7 +965,7 @@ function planMode(pi, dependencies = {}) {
939
965
  const loadInteractiveUi = () => {
940
966
  if (dependencies.loadInteractiveUi) return dependencies.loadInteractiveUi();
941
967
  if (!interactiveUiPromise) {
942
- interactiveUiPromise = import("./chunks/interactive-ui-VESWS25D.js").catch((error) => {
968
+ interactiveUiPromise = import("./chunks/interactive-ui-W3VYAJIQ.js").catch((error) => {
943
969
  interactiveUiPromise = void 0;
944
970
  throw error;
945
971
  });
@@ -1368,14 +1394,28 @@ function planMode(pi, dependencies = {}) {
1368
1394
  reason: `Plan mode blocks tool '${event.toolName}' because its safe policy metadata is unavailable.`
1369
1395
  };
1370
1396
  }
1371
- if (event.toolName !== "bash") return;
1372
- const blocked = findBlockedCommandSegment(readCommand(event.input), settings.safeSubcommands);
1373
- if (blocked !== void 0) {
1374
- return {
1375
- block: true,
1376
- reason: `Plan mode blocks bash commands outside its reviewed inspection policy or containing explicitly unsafe arguments.
1397
+ if (event.toolName === "bash") {
1398
+ const blocked = findBlockedCommandSegment(readCommand(event.input), settings.safeSubcommands);
1399
+ if (blocked !== void 0) {
1400
+ return {
1401
+ block: true,
1402
+ reason: `Plan mode blocks bash commands outside its reviewed inspection policy or containing explicitly unsafe arguments.
1377
1403
  Blocked command: ${blocked}`
1378
- };
1404
+ };
1405
+ }
1406
+ }
1407
+ if (event.toolName === "powershell") {
1408
+ const blocked = findBlockedPowerShellCommandSegment(
1409
+ readCommand(event.input),
1410
+ settings.safeSubcommands
1411
+ );
1412
+ if (blocked !== void 0) {
1413
+ return {
1414
+ block: true,
1415
+ reason: `Plan mode blocks PowerShell commands outside its reviewed inspection policy or containing explicitly unsafe syntax.
1416
+ Blocked command: ${blocked}`
1417
+ };
1418
+ }
1379
1419
  }
1380
1420
  });
1381
1421
  pi.on("message_start", (event) => {