@docyrus/docyrus 0.0.21 → 0.0.22

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": "@docyrus/docyrus",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "private": false,
5
5
  "description": "Docyrus API CLI",
6
6
  "main": "./main.js",
@@ -13,18 +13,21 @@
13
13
  "@modelcontextprotocol/ext-apps": "^1.2.2",
14
14
  "@modelcontextprotocol/sdk": "^1.25.1",
15
15
  "@mariozechner/pi-ai": "0.61.0",
16
- "@mariozechner/pi-coding-agent": "0.61.0",
16
+ "@mariozechner/pi-coding-agent": "0.61.1",
17
17
  "@opentui/core": "^0.1.85",
18
18
  "@opentui/react": "^0.1.85",
19
+ "@xterm/headless": "^5.5.0",
19
20
  "cheerio": "^1.1.2",
20
21
  "diff": "^8.0.2",
21
22
  "incur": "^0.1.6",
22
23
  "jsdom": "^27.0.1",
23
24
  "marked": "^15.0.12",
24
25
  "marked-terminal": "^7.3.0",
26
+ "node-pty": "^1.0.0",
25
27
  "picocolors": "^1.1.1",
26
28
  "puppeteer-core": "^24.31.0",
27
29
  "react": "^19.1.1",
30
+ "strip-ansi": "^7.1.0",
28
31
  "turndown": "^7.2.2",
29
32
  "turndown-plugin-gfm": "^1.0.2",
30
33
  "undici": "^7.16.0",
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Meijer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # pi-bash-live-view
2
+
3
+ When agents emit tool calls calls for build systems, those calls can take a long time.
4
+ Often they have really nice visualizations of progress.
5
+ I cannot see those in pi, making me blind to what is happening.
6
+
7
+ This extension upgrades model-initiated `bash` calls with an optional PTY-backed live terminal view.
8
+
9
+ [![Demo](assets/demo.gif)](https://github.com/lucasmeijer/pi-bash-live-view/releases/download/readme-assets/Screen.Recording.2026-03-20.at.22.27.36.web.mp4)
10
+
11
+ _Open the full demo video:_
12
+ https://github.com/lucasmeijer/pi-bash-live-view/releases/download/readme-assets/Screen.Recording.2026-03-20.at.22.27.36.web.mp4
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pi install npm:pi-bash-live-view
18
+ ```
19
+
@@ -0,0 +1,52 @@
1
+ import { createBashTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext } from '@mariozechner/pi-coding-agent';
2
+ import { Type } from '@sinclair/typebox';
3
+ import { executePtyCommand } from './pty-execute.ts';
4
+ import { ensureSpawnHelperExecutable } from './spawn-helper.ts';
5
+
6
+ const bashLiveViewParams = Type.Object({
7
+ command: Type.String({ description: 'Command to execute' }),
8
+ timeout: Type.Optional(Type.Number({ description: 'Timeout in seconds' })),
9
+ usePTY: Type.Optional(Type.Boolean({ description: 'Run inside a PTY with a live terminal widget the user can see while its running. Use this when you suspect the program being ran has interesting ansi progress output, like buildsystems.' })),
10
+ });
11
+
12
+ ensureSpawnHelperExecutable();
13
+
14
+ async function runSlashCommand(args: string, ctx: ExtensionCommandContext) {
15
+ const command = args.trim();
16
+ if (!command) {
17
+ ctx.ui.notify('Usage: /bash-pty <command>', 'error');
18
+ return;
19
+ }
20
+ const result = await executePtyCommand(
21
+ `slash-${Date.now()}`,
22
+ { command },
23
+ new AbortController().signal,
24
+ ctx as unknown as ExtensionContext,
25
+ );
26
+ const text = result.content[0]?.type === 'text' ? result.content[0].text : '(no output)';
27
+ ctx.ui.notify(text.slice(0, 4000), 'info');
28
+ }
29
+
30
+ export default function bashLiveView(pi: ExtensionAPI) {
31
+ const originalBash = createBashTool(process.cwd());
32
+
33
+ pi.registerTool({
34
+ name: 'bash',
35
+ label: 'bash',
36
+ description: `${originalBash.description} Supports optional usePTY=true live terminal rendering for terminal-style programs and richer progress UIs.`,
37
+ parameters: bashLiveViewParams,
38
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
39
+ if (params.usePTY !== true) {
40
+ return originalBash.execute(toolCallId, params, signal, onUpdate);
41
+ }
42
+ return executePtyCommand(toolCallId, params, signal, ctx);
43
+ },
44
+ });
45
+
46
+ pi.registerCommand('bash-pty', {
47
+ description: 'Run a command through the PTY-backed bash path',
48
+ handler: async (args, ctx) => {
49
+ await runSlashCommand(args, ctx);
50
+ },
51
+ });
52
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "pi-bash-live-view",
3
+ "version": "0.1.1",
4
+ "description": "A pi extension that adds optional PTY-backed live terminal rendering to the bash tool via usePTY=true.",
5
+ "type": "module",
6
+ "author": "Lucas Meijer",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/lucasmeijer/pi-bash-live-view.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/lucasmeijer/pi-bash-live-view/issues"
14
+ },
15
+ "homepage": "https://github.com/lucasmeijer/pi-bash-live-view#readme",
16
+ "keywords": [
17
+ "pi-package",
18
+ "pi",
19
+ "pi-coding-agent",
20
+ "extension",
21
+ "bash",
22
+ "pty",
23
+ "terminal",
24
+ "tui"
25
+ ],
26
+ "files": [
27
+ "index.ts",
28
+ "pty-execute.ts",
29
+ "pty-kill.ts",
30
+ "pty-session.ts",
31
+ "spawn-helper.ts",
32
+ "truncate.ts",
33
+ "widget.ts",
34
+ "terminal-emulator.ts",
35
+ "examples/",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "pi": {
40
+ "extensions": [
41
+ "./index.ts"
42
+ ]
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "scripts": {
48
+ "test": "node --test tests/*.test.mjs"
49
+ },
50
+ "dependencies": {
51
+ "@mariozechner/pi-coding-agent": "^0.58.4",
52
+ "@sinclair/typebox": "^0.34.38",
53
+ "node-pty": "^1.0.0",
54
+ "strip-ansi": "^7.1.0",
55
+ "@xterm/headless": "^5.5.0"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "^24.3.0",
59
+ "typescript": "^5.7.3"
60
+ }
61
+ }
@@ -0,0 +1,97 @@
1
+ import { getShellConfig, type ExtensionContext } from '@mariozechner/pi-coding-agent';
2
+ import { buildAbortError, buildExitCodeError, buildSuccessfulBashResult, buildTimeoutError } from './truncate.ts';
3
+ import { hideWidget, showWidget, type LiveSession } from './widget.ts';
4
+ import { PtyTerminalSession } from './pty-session.ts';
5
+
6
+ export const WIDGET_DELAY_MS = 100;
7
+ export const WIDGET_HEIGHT = 15;
8
+ export const DEFAULT_PTY_COLS = 100;
9
+ export const XTERM_SCROLLBACK_LINES = 100_000;
10
+
11
+ export async function executePtyCommand(
12
+ toolCallId: string,
13
+ params: { command: string; timeout?: number },
14
+ signal: AbortSignal,
15
+ ctx: ExtensionContext,
16
+ ) {
17
+ const shellConfig = getShellConfig();
18
+ const cols = DEFAULT_PTY_COLS;
19
+ const rows = WIDGET_HEIGHT;
20
+ const ptySession = new PtyTerminalSession({
21
+ command: params.command,
22
+ cwd: ctx.cwd,
23
+ cols,
24
+ rows,
25
+ scrollback: XTERM_SCROLLBACK_LINES,
26
+ shell: shellConfig.shell,
27
+ shellArgs: shellConfig.args,
28
+ });
29
+
30
+ const session: LiveSession = {
31
+ id: toolCallId,
32
+ startedAt: Date.now(),
33
+ rows,
34
+ visible: false,
35
+ disposed: false,
36
+ session: ptySession,
37
+ };
38
+
39
+ const unsubscribe = ptySession.subscribe(() => {
40
+ session.requestRender?.();
41
+ });
42
+
43
+ if (ctx.hasUI) {
44
+ session.timer = setTimeout(() => showWidget(ctx, session), WIDGET_DELAY_MS);
45
+ }
46
+
47
+ let timeoutHandle: NodeJS.Timeout | undefined;
48
+ let timedOut = false;
49
+ let aborted = false;
50
+
51
+ const kill = () => {
52
+ ptySession.kill();
53
+ };
54
+ const onAbort = () => {
55
+ aborted = true;
56
+ kill();
57
+ };
58
+
59
+ if (params.timeout && params.timeout > 0) {
60
+ timeoutHandle = setTimeout(() => {
61
+ timedOut = true;
62
+ kill();
63
+ }, params.timeout * 1000);
64
+ }
65
+ if (signal.aborted) {
66
+ onAbort();
67
+ } else {
68
+ signal.addEventListener('abort', onAbort, { once: true });
69
+ }
70
+
71
+ const exit = await new Promise<{ exitCode: number | null }>((resolve) => {
72
+ ptySession.addExitListener((exitCode) => resolve({ exitCode }));
73
+ });
74
+
75
+ await ptySession.whenIdle();
76
+ if (timeoutHandle) clearTimeout(timeoutHandle);
77
+ signal.removeEventListener('abort', onAbort);
78
+ if (session.timer) clearTimeout(session.timer);
79
+ session.disposed = true;
80
+ hideWidget(ctx, session);
81
+ unsubscribe();
82
+
83
+ const fullText = ptySession.getStrippedTextIncludingEntireScrollback();
84
+ ptySession.dispose();
85
+
86
+ if (aborted) {
87
+ throw buildAbortError(fullText);
88
+ }
89
+ if (timedOut && params.timeout && params.timeout > 0) {
90
+ throw buildTimeoutError(fullText, params.timeout);
91
+ }
92
+ if (exit.exitCode !== 0 && exit.exitCode !== null) {
93
+ throw buildExitCodeError(fullText, exit.exitCode);
94
+ }
95
+
96
+ return buildSuccessfulBashResult(fullText);
97
+ }
@@ -0,0 +1,25 @@
1
+ import type pty from 'node-pty';
2
+
3
+ export type PtyLikeProcess = {
4
+ pid: number;
5
+ kill: (signal?: string) => void;
6
+ };
7
+
8
+ export function killPtyProcess(ptyProcess: PtyLikeProcess, signal: string = 'SIGTERM'): void {
9
+ const pid = ptyProcess.pid;
10
+
11
+ if (process.platform !== 'win32' && pid) {
12
+ try {
13
+ process.kill(-pid, signal as NodeJS.Signals);
14
+ return;
15
+ } catch {
16
+ // Fall through to direct PTY kill.
17
+ }
18
+ }
19
+
20
+ try {
21
+ ptyProcess.kill(signal);
22
+ } catch {
23
+ // Process may already be dead.
24
+ }
25
+ }
@@ -0,0 +1,143 @@
1
+ import { createRequire } from 'node:module';
2
+ import { createTerminalEmulator } from './terminal-emulator.ts';
3
+ import { killPtyProcess } from './pty-kill.ts';
4
+
5
+ const require = createRequire(import.meta.url);
6
+ const pty = require('node-pty') as typeof import('node-pty');
7
+
8
+ export type PtyTerminalSessionOptions = {
9
+ command: string;
10
+ cwd: string;
11
+ cols: number;
12
+ rows: number;
13
+ scrollback: number;
14
+ shell: string;
15
+ shellArgs?: string[];
16
+ env?: Record<string, string | undefined>;
17
+ };
18
+
19
+ type TerminalEmulator = ReturnType<typeof createTerminalEmulator>;
20
+
21
+ type ExitListener = (exitCode: number | null, signal?: number) => void;
22
+
23
+ export class PtyTerminalSession {
24
+ private readonly ptyProcess: pty.IPty;
25
+ private readonly terminalEmulator: TerminalEmulator;
26
+ private readonly startedAt = Date.now();
27
+ private readonly exitListeners = new Set<ExitListener>();
28
+ private _exited = false;
29
+ private _exitCode: number | null = null;
30
+ private _signal: number | undefined;
31
+ private disposed = false;
32
+
33
+ constructor(options: PtyTerminalSessionOptions) {
34
+ const {
35
+ command,
36
+ cwd,
37
+ cols,
38
+ rows,
39
+ scrollback,
40
+ shell,
41
+ shellArgs = [],
42
+ env,
43
+ } = options;
44
+
45
+ this.terminalEmulator = createTerminalEmulator({ cols, rows, scrollback });
46
+ this.ptyProcess = pty.spawn(shell, [...shellArgs, command], {
47
+ name: 'xterm-256color',
48
+ cols,
49
+ rows,
50
+ cwd,
51
+ env: {
52
+ ...process.env,
53
+ ...env,
54
+ TERM: 'xterm-256color',
55
+ COLORTERM: 'truecolor',
56
+ },
57
+ });
58
+
59
+ this.ptyProcess.onData((chunk) => {
60
+ void this.terminalEmulator.consumeProcessStdout(chunk, {
61
+ elapsedMs: Date.now() - this.startedAt,
62
+ });
63
+ });
64
+
65
+ this.ptyProcess.onExit(({ exitCode, signal }) => {
66
+ this._exited = true;
67
+ this._exitCode = exitCode;
68
+ this._signal = signal;
69
+ void this.whenIdle().then(() => {
70
+ for (const listener of [...this.exitListeners]) {
71
+ listener(exitCode, signal);
72
+ }
73
+ });
74
+ });
75
+ }
76
+
77
+ get exited() {
78
+ return this._exited;
79
+ }
80
+
81
+ get exitCode() {
82
+ return this._exitCode;
83
+ }
84
+
85
+ get signal() {
86
+ return this._signal;
87
+ }
88
+
89
+ get pid() {
90
+ return this.ptyProcess.pid;
91
+ }
92
+
93
+ get cols() {
94
+ return this.terminalEmulator.cols;
95
+ }
96
+
97
+ get rows() {
98
+ return this.terminalEmulator.rows;
99
+ }
100
+
101
+ addExitListener(listener: ExitListener): () => void {
102
+ this.exitListeners.add(listener);
103
+ if (this._exited) {
104
+ void this.whenIdle().then(() => {
105
+ if (this.exitListeners.has(listener)) {
106
+ listener(this._exitCode, this._signal);
107
+ }
108
+ });
109
+ }
110
+ return () => {
111
+ this.exitListeners.delete(listener);
112
+ };
113
+ }
114
+
115
+ whenIdle(): Promise<void> {
116
+ return this.terminalEmulator.whenIdle();
117
+ }
118
+
119
+ getViewportSnapshot() {
120
+ return this.terminalEmulator.getViewportSnapshot();
121
+ }
122
+
123
+ getStrippedTextIncludingEntireScrollback() {
124
+ return this.terminalEmulator.getStrippedTextIncludingEntireScrollback();
125
+ }
126
+
127
+ subscribe(listener: (payload: { elapsedMs: number; snapshot: ReturnType<TerminalEmulator['getViewportSnapshot']>; inAltScreen: boolean; inSyncRender: boolean }) => void): () => void {
128
+ return this.terminalEmulator.subscribe(listener);
129
+ }
130
+
131
+ kill(signal = 'SIGTERM') {
132
+ if (this._exited) return;
133
+ killPtyProcess(this.ptyProcess, signal);
134
+ }
135
+
136
+ dispose() {
137
+ if (this.disposed) return;
138
+ this.disposed = true;
139
+ this.kill();
140
+ this.terminalEmulator.dispose();
141
+ this.exitListeners.clear();
142
+ }
143
+ }
@@ -0,0 +1,31 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+
5
+ const require = createRequire(import.meta.url);
6
+
7
+ export function getBundledSpawnHelperPaths() {
8
+ const base = path.dirname(require.resolve('node-pty/package.json'));
9
+ return [
10
+ path.join(base, 'prebuilds', 'darwin-arm64', 'spawn-helper'),
11
+ path.join(base, 'prebuilds', 'darwin-x64', 'spawn-helper'),
12
+ ];
13
+ }
14
+
15
+ export function ensureExecutablePaths(paths: string[], log?: (...args: unknown[]) => void) {
16
+ for (const helper of paths) {
17
+ if (!fs.existsSync(helper)) continue;
18
+ const mode = fs.statSync(helper).mode & 0o777;
19
+ if (mode === 0o755) continue;
20
+ fs.chmodSync(helper, 0o755);
21
+ log?.('chmod', helper);
22
+ }
23
+ }
24
+
25
+ export function ensureSpawnHelperExecutable(log?: (...args: unknown[]) => void) {
26
+ try {
27
+ ensureExecutablePaths(getBundledSpawnHelperPaths(), log);
28
+ } catch (error) {
29
+ log?.('spawn-helper chmod failed', error);
30
+ }
31
+ }