@oh-my-pi/pi-tui 18.2.7 → 18.2.9

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/src/tools/bash.ts CHANGED
@@ -25,7 +25,7 @@ export const BASH_DEFAULT_PREVIEW_LINES = DEFAULT_TERMINAL_PREVIEW_LINES;
25
25
 
26
26
  /** LLM-facing footer appended when a tool call becomes a background job. */
27
27
  export function formatBackgroundNotice(jobId: string): string {
28
- return `Backgrounded as job ${jobId}; result will be delivered automatically.`;
28
+ return `Backgrounded as job ${jobId}; its output is injected into the conversation as a follow-up the moment it finishes. Do NOT poll for it (no \`sleep\`, \`ps\`, \`pgrep\`, \`top\`, \`pidwait\`, log tailing): every poll is a wasted turn. Do other work, or end your reply and wait to be woken.`;
29
29
  }
30
30
 
31
31
  /** Shell execution metadata used by transcript rendering. */
package/src/tools/find.ts CHANGED
@@ -7,7 +7,15 @@ import * as path from "node:path";
7
7
  import { formatDuration, formatNumber } from "@oh-my-pi/pi-utils";
8
8
  import { renderProgressBar } from "../components/progress-bar";
9
9
  import { Text } from "../components/text";
10
- import { Ellipsis, fileHyperlink, getTreeBranch, renderStatusLine, renderTreeList, truncateToWidth } from "../render";
10
+ import {
11
+ Ellipsis,
12
+ fileHyperlink,
13
+ getTreeBranch,
14
+ renderStatusLine,
15
+ renderTreeList,
16
+ truncateToWidth,
17
+ uriHyperlink,
18
+ } from "../render";
11
19
  import {
12
20
  createCachedComponent,
13
21
  formatCount,
@@ -31,7 +39,7 @@ export interface FindRange {
31
39
 
32
40
  /** A file whose verified passages cleared the threshold; `ranges` are merged positive spans, strongest first. */
33
41
  export interface FindHit {
34
- /** Display path relative to {@link FindToolDetails.cwd}. */
42
+ /** Display path relative to {@link FindToolDetails.cwd}, or an `omp://` doc URL for docs scopes. */
35
43
  rel: string;
36
44
  /** Filename judgment, when the name batch answered. */
37
45
  nameScore?: number;
@@ -116,9 +124,14 @@ function gauge(p: number, theme: Theme): string {
116
124
  }
117
125
 
118
126
  function renderHit(hit: FindHit, rangeLimit: number, cwd: string | undefined, theme: Theme): string[] {
119
- const absPath = cwd === undefined ? undefined : path.join(cwd, hit.rel);
120
- const link = (text: string, line?: number) =>
121
- absPath === undefined ? text : fileHyperlink(absPath, text, { line });
127
+ // `omp://` hits are virtual docs, not files under `cwd`: link the URL
128
+ // itself instead of joining it onto a filesystem base.
129
+ const isOmpHit = /^omp:\/\//i.test(hit.rel);
130
+ const link = (text: string, line?: number): string => {
131
+ if (isOmpHit) return uriHyperlink(line === undefined ? hit.rel : `${hit.rel}:${line}`, text);
132
+ const absPath = cwd === undefined ? undefined : path.join(cwd, hit.rel);
133
+ return absPath === undefined ? text : fileHyperlink(absPath, text, { line });
134
+ };
122
135
  const coverage = hit.truncated ? `${hit.linesSeen} lines judged, partial` : `${hit.linesSeen} lines judged`;
123
136
  const lines = [
124
137
  `${gauge(hit.contentScore, theme)} ${theme.fg(scoreColor(hit.contentScore), hit.contentScore.toFixed(2))} ${link(theme.fg("accent", hit.rel))} ${theme.fg("dim", coverage)}`,
package/src/tools/hub.ts CHANGED
@@ -100,6 +100,8 @@ export interface JobSnapshot {
100
100
  status: "running" | "completed" | "failed" | "cancelled";
101
101
  label: string;
102
102
  durationMs: number;
103
+ /** Process exit status when the job reports one. */
104
+ exitCode?: number;
103
105
  /** Effective task model selector, including an explicit reasoning suffix when configured. */
104
106
  resolvedModel?: string;
105
107
  /** Provider/id including routing, with no added thinking suffix. */
@@ -570,11 +572,11 @@ export function jobsRenderResult(
570
572
  renderItem: (job, context) => {
571
573
  const rowWidth = Math.max(0, width - (context.prefixWidth ?? 0));
572
574
  const lines: string[] = [];
573
- const icon = formatStatusIcon(
575
+ const icon = `${formatStatusIcon(
574
576
  statusToIcon(job.status),
575
577
  uiTheme,
576
578
  job.status === "running" ? options.spinnerFrame : undefined,
577
- );
579
+ )}${job.exitCode === undefined ? "" : `${uiTheme.sep.dot}${uiTheme.fg(job.exitCode === 0 ? "muted" : "error", `exit ${job.exitCode}`)}`}`;
578
580
  const typeBadge = formatBadge(job.type, statusToColor(job.status), uiTheme);
579
581
  const durationSuffix = `${uiTheme.sep.dot}${uiTheme.fg("dim", formatDuration(job.durationMs))}`;
580
582
  const displayId = truncateToWidth(
package/src/utils.ts CHANGED
@@ -384,6 +384,70 @@ export function visibleWidth(str: string): number {
384
384
  return width;
385
385
  }
386
386
 
387
+ /** Remove ANSI, OSC, and APC control sequences while preserving visible text. */
388
+ export function stripTerminalSequences(str: string): string {
389
+ if (!str.includes("\x1b")) return str;
390
+ let result = "";
391
+ let i = 0;
392
+ while (i < str.length) {
393
+ const ansi = extractAnsiCode(str, i);
394
+ if (ansi) {
395
+ i += ansi.length;
396
+ continue;
397
+ }
398
+ result += str[i];
399
+ i++;
400
+ }
401
+ return result;
402
+ }
403
+
404
+ /**
405
+ * Extract ANSI escape sequences from a string at the given position.
406
+ * Copied verbatim from pi-mono `packages/tui/src/utils.ts` alongside
407
+ * `stripTerminalSequences` so both behave identically to upstream pi. Kept
408
+ * module-private: it was removed from the public API in 9.6.2 and this port
409
+ * does not reintroduce that export.
410
+ */
411
+ function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {
412
+ if (pos >= str.length || str[pos] !== "\x1b") return null;
413
+
414
+ const next = str[pos + 1];
415
+
416
+ // CSI sequence: ESC [ ... m/G/K/H/J
417
+ if (next === "[") {
418
+ let j = pos + 2;
419
+ while (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;
420
+ if (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };
421
+ return null;
422
+ }
423
+
424
+ // OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \)
425
+ // Used for hyperlinks (OSC 8), window titles, etc.
426
+ if (next === "]") {
427
+ let j = pos + 2;
428
+ while (j < str.length) {
429
+ if (str[j] === "\x07") return { code: str.substring(pos, j + 1), length: j + 1 - pos };
430
+ if (str[j] === "\x1b" && str[j + 1] === "\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };
431
+ j++;
432
+ }
433
+ return null;
434
+ }
435
+
436
+ // APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \)
437
+ // Used for cursor marker and application-specific commands
438
+ if (next === "_") {
439
+ let j = pos + 2;
440
+ while (j < str.length) {
441
+ if (str[j] === "\x07") return { code: str.substring(pos, j + 1), length: j + 1 - pos };
442
+ if (str[j] === "\x1b" && str[j + 1] === "\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };
443
+ j++;
444
+ }
445
+ return null;
446
+ }
447
+
448
+ return null;
449
+ }
450
+
387
451
  /**
388
452
  * Scaled spans must bypass wrapping/padding and, when scaled up, reserve the
389
453
  * terminal rows their multicell glyphs flow into.