@moxxy/plugin-terminal 0.41.2 → 0.42.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/terminal.d.ts.map +1 -1
- package/dist/terminal.js +83 -9
- package/dist/terminal.js.map +1 -1
- package/package.json +4 -4
- package/src/pty.test.ts +6 -4
- package/src/terminal.shell.test.ts +106 -0
- package/src/terminal.test.ts +42 -2
- package/src/terminal.ts +95 -12
package/dist/terminal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAmCvE,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAyB,GACxE,OAAO,CAAC,eAAe,CAAC,CA8B1B;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,IAAI,IAAI,CASxC;AAWD;yCACyC;AACzC,wBAAgB,oBAAoB,oCA2EnC;AAmBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,iCAmChC;AAyCD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM;AACjB;wEACwE;AACxE,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAkBzE"}
|
package/dist/terminal.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
2
5
|
import { defineSurface, defineTool, z } from '@moxxy/sdk';
|
|
3
6
|
import { createTerminalProcess } from './pty.js';
|
|
4
7
|
/**
|
|
@@ -300,6 +303,7 @@ signal) {
|
|
|
300
303
|
return new Promise((resolve) => {
|
|
301
304
|
let acc = '';
|
|
302
305
|
let settled = false;
|
|
306
|
+
let typed;
|
|
303
307
|
const finish = (exitCode, timedOut) => {
|
|
304
308
|
if (settled)
|
|
305
309
|
return;
|
|
@@ -309,7 +313,21 @@ signal) {
|
|
|
309
313
|
clearTimeout(timer);
|
|
310
314
|
if (onAbort)
|
|
311
315
|
signal?.removeEventListener('abort', onAbort);
|
|
312
|
-
|
|
316
|
+
typed?.remove();
|
|
317
|
+
const output = cleanOutput(acc, `${command}\n${typed?.line ?? ''}`, marker);
|
|
318
|
+
const waiting = timedOut ? unfinishedPrompt(acc) : undefined;
|
|
319
|
+
if (waiting === undefined) {
|
|
320
|
+
resolve({ output, exitCode, timedOut });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
// The shell sits at a continuation prompt (`heredoc>`): every later command
|
|
324
|
+
// would be swallowed as more of this one. Ctrl-C drops only that input.
|
|
325
|
+
proc.write('\u0003');
|
|
326
|
+
resolve({
|
|
327
|
+
output: `${output}\n[the shell was waiting for the rest of an unfinished command (${waiting}); cancelled it with Ctrl-C]`,
|
|
328
|
+
exitCode,
|
|
329
|
+
timedOut,
|
|
330
|
+
});
|
|
313
331
|
};
|
|
314
332
|
// Already aborted before we even start? Finish immediately — don't write to
|
|
315
333
|
// the shell, don't arm a timeout. The command never runs; null exit.
|
|
@@ -394,8 +412,11 @@ signal) {
|
|
|
394
412
|
// $? reflects the command's exit. A leading newline before the printf
|
|
395
413
|
// terminates any dangling/unterminated command line (trailing backslash,
|
|
396
414
|
// unbalanced quote) so the sentinel is always emitted rather than consumed
|
|
397
|
-
// as a continuation — otherwise such a command would always time out.
|
|
398
|
-
//
|
|
415
|
+
// as a continuation — otherwise such a command would always time out. The
|
|
416
|
+
// printf starts its own output with a newline too: shell hooks (zsh
|
|
417
|
+
// `preexec` setting the window title) print right before it, and the
|
|
418
|
+
// sentinel is only recognized at the start of a line. On a non-PTY pipe the
|
|
419
|
+
// shell still runs both sequentially.
|
|
399
420
|
const writeAndArm = () => {
|
|
400
421
|
if (settled)
|
|
401
422
|
return; // shell died (or we were torn down) before our turn
|
|
@@ -410,8 +431,9 @@ signal) {
|
|
|
410
431
|
return;
|
|
411
432
|
}
|
|
412
433
|
timer = setTimeout(() => finish(null, true), timeoutMs);
|
|
413
|
-
|
|
414
|
-
proc.write(
|
|
434
|
+
typed = typeable(command, marker);
|
|
435
|
+
proc.write(`${typed.line}\n`);
|
|
436
|
+
proc.write(`\n${sentinelPrintf(marker)}\n`);
|
|
415
437
|
};
|
|
416
438
|
// Idle shell → write now (keeps the single-command path fully synchronous).
|
|
417
439
|
// Busy shell → wait our turn; the timeout clock only starts when we write, so
|
|
@@ -422,6 +444,60 @@ signal) {
|
|
|
422
444
|
writeAndArm();
|
|
423
445
|
});
|
|
424
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* A terminal takes typed input through a buffer of about a kilobyte, and the
|
|
449
|
+
* shell redraws the line as each character arrives. A long or multi-line
|
|
450
|
+
* command typed in can lose characters, and a lost heredoc end line leaves the
|
|
451
|
+
* shell waiting forever. Such a command goes to a file the shell sources, so
|
|
452
|
+
* only one short line is typed and what it changes (cd, exports) stays, as if
|
|
453
|
+
* typed. Windows shells keep the typed form: `.` sourcing is POSIX.
|
|
454
|
+
*/
|
|
455
|
+
const TYPED_LIMIT = 512;
|
|
456
|
+
function typeable(command, marker) {
|
|
457
|
+
if (process.platform === 'win32' || (!command.includes('\n') && command.length <= TYPED_LIMIT)) {
|
|
458
|
+
return { line: command, remove: () => { } };
|
|
459
|
+
}
|
|
460
|
+
const file = join(tmpdir(), `moxxy-command-${marker}.sh`);
|
|
461
|
+
writeFileSync(file, `${command}\n`, { mode: 0o600 });
|
|
462
|
+
return {
|
|
463
|
+
line: `. '${file.replace(/'/g, `'\\''`)}'`,
|
|
464
|
+
remove: () => rmSync(file, { force: true }),
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/** zsh's continuation prompt (`heredoc> `, `dquote> `, `for if> `) as the last line shown. */
|
|
468
|
+
const CONTINUATION_PROMPT = /^((?:[a-z]+ )*[a-z]+)>$/u;
|
|
469
|
+
function unfinishedPrompt(raw) {
|
|
470
|
+
const last = plainText(raw).split('\n').filter((line) => line.trim() !== '').at(-1) ?? '';
|
|
471
|
+
return CONTINUATION_PROMPT.exec(last.trimEnd())?.[1];
|
|
472
|
+
}
|
|
473
|
+
/** The shell command that prints `<marker> <exit code>` on a line of its own. */
|
|
474
|
+
function sentinelPrintf(marker) {
|
|
475
|
+
return `printf '\\n%s %s\\n' "${marker}" "$?"`;
|
|
476
|
+
}
|
|
477
|
+
// Terminal control sequences an interactive shell mixes into its output: OSC
|
|
478
|
+
// (window title, cwd), CSI (colors, cursor, bracketed paste) and the remaining
|
|
479
|
+
// two-byte escapes (keypad mode).
|
|
480
|
+
const CONTROL_SEQUENCE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]|\u001b[ -/]*[0-~]/gu;
|
|
481
|
+
const OVERSTRUCK = /[^\n\u0008]\u0008/gu;
|
|
482
|
+
/**
|
|
483
|
+
* What the terminal shows as text: control sequences dropped, backspaced
|
|
484
|
+
* characters erased, and a line rewritten after a carriage return (a prompt
|
|
485
|
+
* redraw, a progress bar) reduced to what it ends up as.
|
|
486
|
+
*/
|
|
487
|
+
function plainText(raw) {
|
|
488
|
+
let text = raw.replace(CONTROL_SEQUENCE, '');
|
|
489
|
+
for (let before = ''; before !== text;) {
|
|
490
|
+
before = text;
|
|
491
|
+
text = text.replace(OVERSTRUCK, '');
|
|
492
|
+
}
|
|
493
|
+
return text
|
|
494
|
+
.split('\n')
|
|
495
|
+
.map((line) => {
|
|
496
|
+
const shown = line.replace(/\r+$/u, '');
|
|
497
|
+
return shown.slice(shown.lastIndexOf('\r') + 1);
|
|
498
|
+
})
|
|
499
|
+
.join('\n');
|
|
500
|
+
}
|
|
425
501
|
/** Strip the echoed command + sentinel lines so the model sees just the output. */
|
|
426
502
|
function cleanOutput(acc, command, marker) {
|
|
427
503
|
// A multi-line command is echoed by an echo-on PTY one line at a time; none of
|
|
@@ -431,11 +507,9 @@ function cleanOutput(acc, command, marker) {
|
|
|
431
507
|
.split('\n')
|
|
432
508
|
.map((l) => l.trim())
|
|
433
509
|
.filter((l) => l.length > 0));
|
|
434
|
-
return acc
|
|
510
|
+
return plainText(acc)
|
|
435
511
|
.split('\n')
|
|
436
|
-
.filter((line) => !line.includes(marker) &&
|
|
437
|
-
!commandLines.has(line.trim()) &&
|
|
438
|
-
!line.includes(`printf '%s %s\\n' "${marker}"`))
|
|
512
|
+
.filter((line) => !line.includes(marker) && !commandLines.has(line.trim()))
|
|
439
513
|
.join('\n')
|
|
440
514
|
.trim();
|
|
441
515
|
}
|
package/dist/terminal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,EAAwB,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAwB,MAAM,UAAU,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;AAClD;;;;;;;GAOG;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoC,CAAC;AAC5D;;;;;;;;;;;;;;GAcG;AACH,IAAI,KAAK,GAAG,C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AE,EAAE;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,mFAAmF;AACnF,SAAS,WAAW,CAAC,GAAW,EAAE,OAAe,EAAE,MAAc;IAC/D,+EAA+E;IAC/E,2EAA2E;IAC3E,0EAA0E;IAC1E,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,OAAO;SACJ,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAC/B,CAAC;IACF,OAAO,SAAS,CAAC,GAAG,CAAC;SAClB,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SAC1E,IAAI,CAAC,IAAI,CAAC;SACV,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moxxy/plugin-terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "A shared terminal surface for moxxy: an embedded PTY the user and the agent drive together (the `terminal` tool runs commands; the desktop renders the live session).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"moxxy",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@moxxy/sdk": "0.
|
|
45
|
+
"@moxxy/sdk": "0.42.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"node-pty": "^1.0.0"
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^22.
|
|
56
|
+
"@types/node": "^22.20.5",
|
|
57
57
|
"typescript": "^6.0.3",
|
|
58
|
-
"vitest": "^
|
|
58
|
+
"vitest": "^5.0.3",
|
|
59
59
|
"@moxxy/tsconfig": "0.0.0",
|
|
60
60
|
"@moxxy/vitest-preset": "0.0.0"
|
|
61
61
|
},
|
package/src/pty.test.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { mkdtempSync,
|
|
2
|
+
import { mkdtempSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { posixFileModes } from '@moxxy/vitest-preset/platform';
|
|
6
7
|
import { makeExecutable, resolveNodePtyModule, TerminalProcessImpl } from './pty.js';
|
|
8
|
+
import { removeDirSync } from '@moxxy/vitest-preset/fs';
|
|
7
9
|
|
|
8
10
|
const MAX_SCROLLBACK = 200_000;
|
|
9
11
|
|
|
@@ -64,11 +66,11 @@ describe('resolveNodePtyModule (degrade on a malformed optional dep)', () => {
|
|
|
64
66
|
describe('makeExecutable (node-pty spawn-helper repair)', () => {
|
|
65
67
|
let dir: string | null = null;
|
|
66
68
|
afterEach(() => {
|
|
67
|
-
if (dir)
|
|
69
|
+
if (dir) removeDirSync(dir);
|
|
68
70
|
dir = null;
|
|
69
71
|
});
|
|
70
72
|
|
|
71
|
-
it('adds the executable bit to a file that lacks it', () => {
|
|
73
|
+
it.skipIf(!posixFileModes)('adds the executable bit to a file that lacks it', () => {
|
|
72
74
|
dir = mkdtempSync(join(tmpdir(), 'moxxy-pty-'));
|
|
73
75
|
const file = join(dir, 'spawn-helper');
|
|
74
76
|
writeFileSync(file, 'binary');
|
|
@@ -80,7 +82,7 @@ describe('makeExecutable (node-pty spawn-helper repair)', () => {
|
|
|
80
82
|
expect(statSync(file).mode & 0o111).not.toBe(0);
|
|
81
83
|
});
|
|
82
84
|
|
|
83
|
-
it('is idempotent on an already-executable file', () => {
|
|
85
|
+
it.skipIf(!posixFileModes)('is idempotent on an already-executable file', () => {
|
|
84
86
|
dir = mkdtempSync(join(tmpdir(), 'moxxy-pty-'));
|
|
85
87
|
const file = join(dir, 'spawn-helper');
|
|
86
88
|
writeFileSync(file, 'binary', { mode: 0o755 });
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runCommand against a REAL interactive zsh set up the way Oh My Zsh does it:
|
|
3
|
+
* `preexec` prints an OSC title sequence right before the command's own output,
|
|
4
|
+
* so the sentinel line does not start at a newline, and every typed character
|
|
5
|
+
* goes through the `url-quote-magic` widget, so zsh reads typed input slowly.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
13
|
+
import { createTerminalProcess, type TerminalProcess } from './pty.js';
|
|
14
|
+
import { runCommand } from './terminal.js';
|
|
15
|
+
import { removeDirSync } from '@moxxy/vitest-preset/fs';
|
|
16
|
+
|
|
17
|
+
const zsh = spawnSync('zsh', ['-c', 'command -v zsh'], { encoding: 'utf8' });
|
|
18
|
+
const zshPath = zsh.status === 0 ? zsh.stdout.trim() : null;
|
|
19
|
+
|
|
20
|
+
/** Well under the test timeout, so a missed sentinel reads as `timedOut`. */
|
|
21
|
+
const COMMAND_TIMEOUT_MS = 3_000;
|
|
22
|
+
|
|
23
|
+
const TITLE_HOOKS = [
|
|
24
|
+
"preexec() { printf '\\e]2;%s\\a\\e]1;%s\\a' \"$1\" \"${1%% *}\"; }",
|
|
25
|
+
"precmd() { printf '\\e]2;%s\\a' \"$PWD\"; }",
|
|
26
|
+
"PROMPT='%~ %# '",
|
|
27
|
+
'autoload -Uz url-quote-magic',
|
|
28
|
+
'zle -N self-insert url-quote-magic',
|
|
29
|
+
'unset HISTFILE',
|
|
30
|
+
].join('\n');
|
|
31
|
+
|
|
32
|
+
describe.skipIf(zshPath === null)('runCommand in a zsh set up like Oh My Zsh', () => {
|
|
33
|
+
const saved = { SHELL: process.env.SHELL, ZDOTDIR: process.env.ZDOTDIR };
|
|
34
|
+
let dotdir: string;
|
|
35
|
+
let term: TerminalProcess;
|
|
36
|
+
|
|
37
|
+
beforeEach(async () => {
|
|
38
|
+
dotdir = mkdtempSync(path.join(os.tmpdir(), 'moxxy-zsh-'));
|
|
39
|
+
writeFileSync(path.join(dotdir, '.zshrc'), `${TITLE_HOOKS}\n`);
|
|
40
|
+
process.env.SHELL = zshPath ?? undefined;
|
|
41
|
+
process.env.ZDOTDIR = dotdir;
|
|
42
|
+
term = await createTerminalProcess(os.tmpdir());
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
term.kill();
|
|
47
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
48
|
+
if (value === undefined) delete process.env[key];
|
|
49
|
+
else process.env[key] = value;
|
|
50
|
+
}
|
|
51
|
+
removeDirSync(dotdir);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('finishes as soon as the command does instead of waiting out the timeout', async () => {
|
|
55
|
+
const res = await runCommand(term, 'echo hi', '__MOXXY_DONE_zsh_0__', COMMAND_TIMEOUT_MS);
|
|
56
|
+
|
|
57
|
+
expect(res.timedOut).toBe(false);
|
|
58
|
+
expect(res.exitCode).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('reports the exit code of a failing command', async () => {
|
|
62
|
+
const res = await runCommand(term, 'false', '__MOXXY_DONE_zsh_1__', COMMAND_TIMEOUT_MS);
|
|
63
|
+
|
|
64
|
+
expect(res.exitCode).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns the output as plain text, without the terminal control sequences', async () => {
|
|
68
|
+
const res = await runCommand(term, 'echo hi', '__MOXXY_DONE_zsh_2__', COMMAND_TIMEOUT_MS);
|
|
69
|
+
|
|
70
|
+
expect(res.output.split('\n')).toContain('hi');
|
|
71
|
+
expect(res.output).not.toContain('\u001b');
|
|
72
|
+
expect(res.output).not.toContain('\u0007');
|
|
73
|
+
expect(res.output).not.toContain('\r');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('runs a long script fed through a heredoc whole, and the shell takes the next command', async () => {
|
|
77
|
+
// Lines wider than the 80-column terminal: typed in, zsh redraws them while
|
|
78
|
+
// more input arrives and loses characters (the heredoc's end line with them).
|
|
79
|
+
const body = Array.from({ length: 60 }, (_, i) => `print('line ${i} ${'x'.repeat(100)}')`).join('\n');
|
|
80
|
+
const script = `python3 - <<'PY'\n${body}\nPY`;
|
|
81
|
+
|
|
82
|
+
const res = await runCommand(term, script, '__MOXXY_DONE_zsh_3__', COMMAND_TIMEOUT_MS);
|
|
83
|
+
const next = await runCommand(term, 'echo ok', '__MOXXY_DONE_zsh_4__', COMMAND_TIMEOUT_MS);
|
|
84
|
+
|
|
85
|
+
expect(res.timedOut).toBe(false);
|
|
86
|
+
const printed = res.output.split('\n').filter((line) => line.startsWith('line '));
|
|
87
|
+
expect(printed).toEqual(Array.from({ length: 60 }, (_, i) => `line ${i} ${'x'.repeat(100)}`));
|
|
88
|
+
expect(next.output.split('\n')).toContain('ok');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('keeps what a script changes in the shell, as if it had been typed', async () => {
|
|
92
|
+
await runCommand(term, `cd /\nexport MOXXY_SEEN=${'y'.repeat(600)}`, '__MOXXY_DONE_zsh_5__', COMMAND_TIMEOUT_MS);
|
|
93
|
+
const res = await runCommand(term, 'pwd; echo ${#MOXXY_SEEN}', '__MOXXY_DONE_zsh_6__', COMMAND_TIMEOUT_MS);
|
|
94
|
+
|
|
95
|
+
expect(res.output.split('\n')).toEqual(expect.arrayContaining(['/', '600']));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('frees a shell left waiting for the end of an unfinished command', async () => {
|
|
99
|
+
const stuck = await runCommand(term, "cat <<'NEVER'", '__MOXXY_DONE_zsh_7__', 1_000);
|
|
100
|
+
const next = await runCommand(term, 'echo ok', '__MOXXY_DONE_zsh_8__', COMMAND_TIMEOUT_MS);
|
|
101
|
+
|
|
102
|
+
expect(stuck.timedOut).toBe(true);
|
|
103
|
+
expect(stuck.output).toContain('waiting for the rest of an unfinished command');
|
|
104
|
+
expect(next.output.split('\n')).toContain('ok');
|
|
105
|
+
});
|
|
106
|
+
});
|
package/src/terminal.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
1
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
3
|
import { runCommand } from './terminal.js';
|
|
3
4
|
import type { TerminalProcess } from './pty.js';
|
|
@@ -106,7 +107,7 @@ describe('runCommand sentinel detection (tail-scan, single RegExp compile)', ()
|
|
|
106
107
|
|
|
107
108
|
// The shell echoes the printf command itself first (contains the marker but
|
|
108
109
|
// NOT "<marker> <digits>"), then later the real sentinel value line.
|
|
109
|
-
term.feed(`printf '%s %s\\n' "${marker}" "$?"\n`);
|
|
110
|
+
term.feed(`printf '\\n%s %s\\n' "${marker}" "$?"\n`);
|
|
110
111
|
term.feed('echo done\n');
|
|
111
112
|
term.feed('done\n');
|
|
112
113
|
term.feed(`${marker} 0\n`);
|
|
@@ -243,7 +244,7 @@ describe('runCommand sentinel detection (tail-scan, single RegExp compile)', ()
|
|
|
243
244
|
|
|
244
245
|
const all = term.writes.join('');
|
|
245
246
|
// The printf line is preceded by a newline (its own write begins with "\n").
|
|
246
|
-
expect(all).toContain(`\nprintf '%s %s\\n' "${marker}" "$?"\n`);
|
|
247
|
+
expect(all).toContain(`\nprintf '\\n%s %s\\n' "${marker}" "$?"\n`);
|
|
247
248
|
|
|
248
249
|
// And completion still works end-to-end.
|
|
249
250
|
term.feed(`${marker} 0\n`);
|
|
@@ -285,6 +286,45 @@ describe('runCommand sentinel detection (tail-scan, single RegExp compile)', ()
|
|
|
285
286
|
});
|
|
286
287
|
});
|
|
287
288
|
|
|
289
|
+
describe.skipIf(process.platform === 'win32')('runCommand with a long or multi-line command', () => {
|
|
290
|
+
it('types one short line that runs the command from a file, and removes the file when done', async () => {
|
|
291
|
+
const term = fakeTerminal();
|
|
292
|
+
const marker = '__MOXXY_DONE_file_0__';
|
|
293
|
+
const command = "python3 - <<'PY'\nprint('hi')\nPY";
|
|
294
|
+
const p = runCommand(term, command, marker, 5_000);
|
|
295
|
+
|
|
296
|
+
const typed = term.writes[0] ?? '';
|
|
297
|
+
const file = /^\. '([^']+)'\n$/.exec(typed)?.[1];
|
|
298
|
+
expect(file).toBeDefined();
|
|
299
|
+
expect(readFileSync(file ?? '', 'utf8')).toBe(`${command}\n`);
|
|
300
|
+
|
|
301
|
+
term.feed(typed);
|
|
302
|
+
term.feed('hi\n');
|
|
303
|
+
term.feed(`${marker} 0\n`);
|
|
304
|
+
const res = await p;
|
|
305
|
+
expect(res.output).toBe('hi');
|
|
306
|
+
expect(existsSync(file ?? '')).toBe(false);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('runs a single line longer than the terminal input buffer from a file too', async () => {
|
|
310
|
+
const term = fakeTerminal();
|
|
311
|
+
const p = runCommand(term, `echo ${'x'.repeat(2_000)}`, '__MOXXY_DONE_file_1__', 5_000);
|
|
312
|
+
|
|
313
|
+
expect(term.writes[0]?.length).toBeLessThan(300);
|
|
314
|
+
term.feed('__MOXXY_DONE_file_1__ 0\n');
|
|
315
|
+
await p;
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('types a short one-line command as it is', async () => {
|
|
319
|
+
const term = fakeTerminal();
|
|
320
|
+
const p = runCommand(term, 'ls -la', '__MOXXY_DONE_file_2__', 5_000);
|
|
321
|
+
|
|
322
|
+
expect(term.writes[0]).toBe('ls -la\n');
|
|
323
|
+
term.feed('__MOXXY_DONE_file_2__ 0\n');
|
|
324
|
+
await p;
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
288
328
|
describe('runCommand abort handling (turn-cancel must not hang the tool slot)', () => {
|
|
289
329
|
// The turn's AbortSignal must end a running command promptly — without it the
|
|
290
330
|
// call blocked the tool slot for up to the full timeout (600s) after the user
|
package/src/terminal.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
2
5
|
import { defineSurface, defineTool, z, type SurfaceInstance } from '@moxxy/sdk';
|
|
3
6
|
import { createTerminalProcess, type TerminalProcess } from './pty.js';
|
|
4
7
|
|
|
@@ -320,6 +323,7 @@ function runCommandSerialized(
|
|
|
320
323
|
return new Promise((resolve) => {
|
|
321
324
|
let acc = '';
|
|
322
325
|
let settled = false;
|
|
326
|
+
let typed: TypedCommand | undefined;
|
|
323
327
|
const finish = (exitCode: number | null, timedOut: boolean): void => {
|
|
324
328
|
if (settled) return;
|
|
325
329
|
settled = true;
|
|
@@ -327,7 +331,21 @@ function runCommandSerialized(
|
|
|
327
331
|
unsubExit();
|
|
328
332
|
clearTimeout(timer);
|
|
329
333
|
if (onAbort) signal?.removeEventListener('abort', onAbort);
|
|
330
|
-
|
|
334
|
+
typed?.remove();
|
|
335
|
+
const output = cleanOutput(acc, `${command}\n${typed?.line ?? ''}`, marker);
|
|
336
|
+
const waiting = timedOut ? unfinishedPrompt(acc) : undefined;
|
|
337
|
+
if (waiting === undefined) {
|
|
338
|
+
resolve({ output, exitCode, timedOut });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
// The shell sits at a continuation prompt (`heredoc>`): every later command
|
|
342
|
+
// would be swallowed as more of this one. Ctrl-C drops only that input.
|
|
343
|
+
proc.write('\u0003');
|
|
344
|
+
resolve({
|
|
345
|
+
output: `${output}\n[the shell was waiting for the rest of an unfinished command (${waiting}); cancelled it with Ctrl-C]`,
|
|
346
|
+
exitCode,
|
|
347
|
+
timedOut,
|
|
348
|
+
});
|
|
331
349
|
};
|
|
332
350
|
// Already aborted before we even start? Finish immediately — don't write to
|
|
333
351
|
// the shell, don't arm a timeout. The command never runs; null exit.
|
|
@@ -411,8 +429,11 @@ function runCommandSerialized(
|
|
|
411
429
|
// $? reflects the command's exit. A leading newline before the printf
|
|
412
430
|
// terminates any dangling/unterminated command line (trailing backslash,
|
|
413
431
|
// unbalanced quote) so the sentinel is always emitted rather than consumed
|
|
414
|
-
// as a continuation — otherwise such a command would always time out.
|
|
415
|
-
//
|
|
432
|
+
// as a continuation — otherwise such a command would always time out. The
|
|
433
|
+
// printf starts its own output with a newline too: shell hooks (zsh
|
|
434
|
+
// `preexec` setting the window title) print right before it, and the
|
|
435
|
+
// sentinel is only recognized at the start of a line. On a non-PTY pipe the
|
|
436
|
+
// shell still runs both sequentially.
|
|
416
437
|
const writeAndArm = (): void => {
|
|
417
438
|
if (settled) return; // shell died (or we were torn down) before our turn
|
|
418
439
|
// The shell is ALREADY dead at write time (it exited before our turn, or
|
|
@@ -426,8 +447,9 @@ function runCommandSerialized(
|
|
|
426
447
|
return;
|
|
427
448
|
}
|
|
428
449
|
timer = setTimeout(() => finish(null, true), timeoutMs);
|
|
429
|
-
|
|
430
|
-
proc.write(
|
|
450
|
+
typed = typeable(command, marker);
|
|
451
|
+
proc.write(`${typed.line}\n`);
|
|
452
|
+
proc.write(`\n${sentinelPrintf(marker)}\n`);
|
|
431
453
|
};
|
|
432
454
|
// Idle shell → write now (keeps the single-command path fully synchronous).
|
|
433
455
|
// Busy shell → wait our turn; the timeout clock only starts when we write, so
|
|
@@ -437,6 +459,72 @@ function runCommandSerialized(
|
|
|
437
459
|
});
|
|
438
460
|
}
|
|
439
461
|
|
|
462
|
+
/**
|
|
463
|
+
* A terminal takes typed input through a buffer of about a kilobyte, and the
|
|
464
|
+
* shell redraws the line as each character arrives. A long or multi-line
|
|
465
|
+
* command typed in can lose characters, and a lost heredoc end line leaves the
|
|
466
|
+
* shell waiting forever. Such a command goes to a file the shell sources, so
|
|
467
|
+
* only one short line is typed and what it changes (cd, exports) stays, as if
|
|
468
|
+
* typed. Windows shells keep the typed form: `.` sourcing is POSIX.
|
|
469
|
+
*/
|
|
470
|
+
const TYPED_LIMIT = 512;
|
|
471
|
+
|
|
472
|
+
interface TypedCommand {
|
|
473
|
+
readonly line: string;
|
|
474
|
+
remove(): void;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function typeable(command: string, marker: string): TypedCommand {
|
|
478
|
+
if (process.platform === 'win32' || (!command.includes('\n') && command.length <= TYPED_LIMIT)) {
|
|
479
|
+
return { line: command, remove: () => {} };
|
|
480
|
+
}
|
|
481
|
+
const file = join(tmpdir(), `moxxy-command-${marker}.sh`);
|
|
482
|
+
writeFileSync(file, `${command}\n`, { mode: 0o600 });
|
|
483
|
+
return {
|
|
484
|
+
line: `. '${file.replace(/'/g, `'\\''`)}'`,
|
|
485
|
+
remove: () => rmSync(file, { force: true }),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** zsh's continuation prompt (`heredoc> `, `dquote> `, `for if> `) as the last line shown. */
|
|
490
|
+
const CONTINUATION_PROMPT = /^((?:[a-z]+ )*[a-z]+)>$/u;
|
|
491
|
+
|
|
492
|
+
function unfinishedPrompt(raw: string): string | undefined {
|
|
493
|
+
const last = plainText(raw).split('\n').filter((line) => line.trim() !== '').at(-1) ?? '';
|
|
494
|
+
return CONTINUATION_PROMPT.exec(last.trimEnd())?.[1];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** The shell command that prints `<marker> <exit code>` on a line of its own. */
|
|
498
|
+
function sentinelPrintf(marker: string): string {
|
|
499
|
+
return `printf '\\n%s %s\\n' "${marker}" "$?"`;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Terminal control sequences an interactive shell mixes into its output: OSC
|
|
503
|
+
// (window title, cwd), CSI (colors, cursor, bracketed paste) and the remaining
|
|
504
|
+
// two-byte escapes (keypad mode).
|
|
505
|
+
const CONTROL_SEQUENCE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]|\u001b[ -/]*[0-~]/gu;
|
|
506
|
+
const OVERSTRUCK = /[^\n\u0008]\u0008/gu;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* What the terminal shows as text: control sequences dropped, backspaced
|
|
510
|
+
* characters erased, and a line rewritten after a carriage return (a prompt
|
|
511
|
+
* redraw, a progress bar) reduced to what it ends up as.
|
|
512
|
+
*/
|
|
513
|
+
function plainText(raw: string): string {
|
|
514
|
+
let text = raw.replace(CONTROL_SEQUENCE, '');
|
|
515
|
+
for (let before = ''; before !== text; ) {
|
|
516
|
+
before = text;
|
|
517
|
+
text = text.replace(OVERSTRUCK, '');
|
|
518
|
+
}
|
|
519
|
+
return text
|
|
520
|
+
.split('\n')
|
|
521
|
+
.map((line) => {
|
|
522
|
+
const shown = line.replace(/\r+$/u, '');
|
|
523
|
+
return shown.slice(shown.lastIndexOf('\r') + 1);
|
|
524
|
+
})
|
|
525
|
+
.join('\n');
|
|
526
|
+
}
|
|
527
|
+
|
|
440
528
|
/** Strip the echoed command + sentinel lines so the model sees just the output. */
|
|
441
529
|
function cleanOutput(acc: string, command: string, marker: string): string {
|
|
442
530
|
// A multi-line command is echoed by an echo-on PTY one line at a time; none of
|
|
@@ -448,14 +536,9 @@ function cleanOutput(acc: string, command: string, marker: string): string {
|
|
|
448
536
|
.map((l) => l.trim())
|
|
449
537
|
.filter((l) => l.length > 0), // never strip blank output lines
|
|
450
538
|
);
|
|
451
|
-
return acc
|
|
539
|
+
return plainText(acc)
|
|
452
540
|
.split('\n')
|
|
453
|
-
.filter(
|
|
454
|
-
(line) =>
|
|
455
|
-
!line.includes(marker) &&
|
|
456
|
-
!commandLines.has(line.trim()) &&
|
|
457
|
-
!line.includes(`printf '%s %s\\n' "${marker}"`),
|
|
458
|
-
)
|
|
541
|
+
.filter((line) => !line.includes(marker) && !commandLines.has(line.trim()))
|
|
459
542
|
.join('\n')
|
|
460
543
|
.trim();
|
|
461
544
|
}
|