@juicesharp/rpiv-todo 2.4.0 → 2.5.1

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": "@juicesharp/rpiv-todo",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -47,6 +47,7 @@
47
47
  "state/store.ts",
48
48
  "state/task-graph.ts",
49
49
  "tool/response-envelope.ts",
50
+ "tool/sanitize.ts",
50
51
  "tool/types.ts",
51
52
  "view/format.ts"
52
53
  ],
@@ -67,7 +68,7 @@
67
68
  }
68
69
  },
69
70
  "dependencies": {
70
- "@juicesharp/rpiv-config": "^2.4.0",
71
+ "@juicesharp/rpiv-config": "^2.5.1",
71
72
  "typebox": "^1.1.24"
72
73
  }
73
74
  }
@@ -1,6 +1,7 @@
1
1
  import type { TaskState } from "../state/state.js";
2
2
  import type { Op } from "../state/state-reducer.js";
3
3
  import { deriveBlocks } from "../state/task-graph.js";
4
+ import { sanitizeTerminalText } from "./sanitize.js";
4
5
  import type { Task, TaskAction, TaskDetails, TaskMutationParams } from "./types.js";
5
6
 
6
7
  /**
@@ -10,8 +11,8 @@ import type { Task, TaskAction, TaskDetails, TaskMutationParams } from "./types.
10
11
  */
11
12
  function formatListLine(t: Task): string {
12
13
  const block = t.blockedBy?.length ? ` ⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}` : "";
13
- const form = t.status === "in_progress" && t.activeForm ? ` (${t.activeForm})` : "";
14
- return `[${t.status}] #${t.id} ${t.subject}${form}${block}`;
14
+ const form = t.status === "in_progress" && t.activeForm ? ` (${sanitizeTerminalText(t.activeForm)})` : "";
15
+ return `[${t.status}] #${t.id} ${sanitizeTerminalText(t.subject)}${form}${block}`;
15
16
  }
16
17
 
17
18
  /**
@@ -21,16 +22,16 @@ function formatListLine(t: Task): string {
21
22
  */
22
23
  function formatGetLines(task: Task, state: TaskState): string {
23
24
  const blocks = deriveBlocks(state.tasks).get(task.id) ?? [];
24
- const lines = [`#${task.id} [${task.status}] ${task.subject}`];
25
- if (task.description) lines.push(` description: ${task.description}`);
26
- if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);
25
+ const lines = [`#${task.id} [${task.status}] ${sanitizeTerminalText(task.subject)}`];
26
+ if (task.description) lines.push(` description: ${sanitizeTerminalText(task.description)}`);
27
+ if (task.activeForm) lines.push(` activeForm: ${sanitizeTerminalText(task.activeForm)}`);
27
28
  if (task.blockedBy?.length) {
28
29
  lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(", ")}`);
29
30
  }
30
31
  if (blocks.length) {
31
32
  lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(", ")}`);
32
33
  }
33
- if (task.owner) lines.push(` owner: ${task.owner}`);
34
+ if (task.owner) lines.push(` owner: ${sanitizeTerminalText(task.owner)}`);
34
35
  return lines.join("\n");
35
36
  }
36
37
 
@@ -46,7 +47,7 @@ export function formatContent(op: Op, state: TaskState): string {
46
47
  const t = state.tasks.find((x) => x.id === op.taskId);
47
48
  // Defensive — `op.taskId` always resolves on success path.
48
49
  if (!t) return `Created #${op.taskId}`;
49
- return `Created #${t.id}: ${t.subject} (pending)`;
50
+ return `Created #${t.id}: ${sanitizeTerminalText(t.subject)} (pending)`;
50
51
  }
51
52
  case "update": {
52
53
  if (!op.changed) {
@@ -56,7 +57,7 @@ export function formatContent(op: Op, state: TaskState): string {
56
57
  return `Updated #${op.id}${transition}`;
57
58
  }
58
59
  case "delete":
59
- return `Deleted #${op.id}: ${op.subject}`;
60
+ return `Deleted #${op.id}: ${sanitizeTerminalText(op.subject)}`;
60
61
  case "clear":
61
62
  return `Cleared ${op.count} tasks`;
62
63
  case "list": {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Remove terminal control characters from model-controlled task text before
3
+ * it reaches Pi's terminal renderer. Complete CSI/OSC escape sequences are
4
+ * dropped whole (no printable remnants like `[31m`), newlines and tabs
5
+ * become spaces so task fields cannot change the layout, and bidi controls
6
+ * are removed so a field cannot reorder how neighbouring output reads.
7
+ */
8
+ export function sanitizeTerminalText(value: string): string {
9
+ return (
10
+ value
11
+ // CSI sequences, via both ESC-[ and the C1 single-byte introducer.
12
+ .replace(/(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]/g, "")
13
+ // OSC sequences with their payload; an unterminated OSC swallows the
14
+ // rest of the string, matching how a real terminal would treat it.
15
+ .replace(/(?:\u001b\]|\u009d)[^\u0007\u009c\u001b]*(?:\u0007|\u009c|\u001b\\)?/g, "")
16
+ // Any remaining two-character ESC sequence.
17
+ .replace(/\u001b./g, "")
18
+ // Unicode line/paragraph separators join lines like \n does below.
19
+ .replace(/[\u2028\u2029]/g, " ")
20
+ .replace(/[\u0000-\u001f\u007f-\u009f]/g, (character) =>
21
+ character === "\n" || character === "\r" || character === "\t" ? " " : "",
22
+ )
23
+ // Bidi embedding/override/isolate controls and LRM/RLM marks.
24
+ .replace(/[\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, "")
25
+ );
26
+ }
package/view/format.ts CHANGED
@@ -3,6 +3,7 @@ import { Text } from "@earendil-works/pi-tui";
3
3
  import { formatStatusLabel } from "../state/i18n-bridge.js";
4
4
  import { selectTaskSubjectById } from "../state/selectors.js";
5
5
  import type { TaskState } from "../state/state.js";
6
+ import { sanitizeTerminalText } from "../tool/sanitize.js";
6
7
  import type { Task, TaskAction, TaskDetails, TaskMutationParams, TaskStatus } from "../tool/types.js";
7
8
 
8
9
  // Re-export so legacy import paths (todo.ts, tests) continue to resolve;
@@ -72,7 +73,7 @@ export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): s
72
73
  const glyph = overlayStatusGlyph(t.status, theme);
73
74
  const subjectColor =
74
75
  t.status === "in_progress" ? "accent" : t.status === "completed" || t.status === "deleted" ? "muted" : "text";
75
- let subject = theme.fg(subjectColor, t.subject);
76
+ let subject = theme.fg(subjectColor, sanitizeTerminalText(t.subject));
76
77
  if (t.status === "completed" || t.status === "deleted") {
77
78
  subject = theme.strikethrough(subject);
78
79
  }
@@ -80,7 +81,7 @@ export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): s
80
81
  if (showId) line += ` ${theme.fg("dim", `#${t.id}`)}`;
81
82
  line += ` ${subject}`;
82
83
  if (t.status === "in_progress" && t.activeForm) {
83
- line += ` ${theme.fg("muted", `(${t.activeForm})`)}`;
84
+ line += ` ${theme.fg("muted", `(${sanitizeTerminalText(t.activeForm)})`)}`;
84
85
  }
85
86
  if (t.blockedBy && t.blockedBy.length > 0) {
86
87
  line += ` ${theme.fg("muted", `⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}`)}`;
@@ -93,9 +94,9 @@ export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): s
93
94
  * indented bullet prefix). Pre-refactor `todo.ts:670-674`.
94
95
  */
95
96
  export function formatCommandTaskLine(t: Task, glyph: string): string {
96
- const form = t.status === "in_progress" && t.activeForm ? ` (${t.activeForm})` : "";
97
+ const form = t.status === "in_progress" && t.activeForm ? ` (${sanitizeTerminalText(t.activeForm)})` : "";
97
98
  const block = t.blockedBy?.length ? ` ⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}` : "";
98
- return ` ${glyph} #${t.id} ${t.subject}${form}${block}`;
99
+ return ` ${glyph} #${t.id} ${sanitizeTerminalText(t.subject)}${form}${block}`;
99
100
  }
100
101
 
101
102
  // ---------------------------------------------------------------------------
@@ -116,13 +117,13 @@ export function renderTodoCall(
116
117
  let text = theme.fg("toolTitle", theme.bold("todo ")) + theme.fg("muted", glyph);
117
118
 
118
119
  if (args.action === "create" && args.subject) {
119
- text += ` ${theme.fg("dim", args.subject)}`;
120
+ text += ` ${theme.fg("dim", sanitizeTerminalText(args.subject))}`;
120
121
  } else if (
121
122
  (args.action === "update" || args.action === "get" || args.action === "delete") &&
122
123
  args.id !== undefined
123
124
  ) {
124
125
  const subject = selectTaskSubjectById(state, args.id);
125
- text += ` ${theme.fg("accent", subject ?? `#${args.id}`)}`;
126
+ text += ` ${theme.fg("accent", subject ? sanitizeTerminalText(subject) : `#${args.id}`)}`;
126
127
  } else if (args.action === "list" && args.status) {
127
128
  text += ` ${theme.fg("muted", formatStatusLabel(args.status))}`;
128
129
  }