terminal-pilot 0.0.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.
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env tsx
2
+ import readline from "node:readline";
3
+ const options = ["Option 1", "Option 2", "Option 3"];
4
+ const { stdin, stdout } = process;
5
+ let selectedIndex = 0;
6
+ let renderedLineCount = 0;
7
+ let hasExited = false;
8
+ readline.emitKeypressEvents(stdin);
9
+ if (stdin.isTTY) {
10
+ stdin.setRawMode(true);
11
+ }
12
+ stdin.resume();
13
+ render();
14
+ stdin.on("keypress", (_, key) => {
15
+ if (key.ctrl && key.name === "c") {
16
+ exitWithCode(130);
17
+ return;
18
+ }
19
+ if (key.name === "up") {
20
+ selectedIndex = (selectedIndex + options.length - 1) % options.length;
21
+ render();
22
+ return;
23
+ }
24
+ if (key.name === "down") {
25
+ selectedIndex = (selectedIndex + 1) % options.length;
26
+ render();
27
+ return;
28
+ }
29
+ if (key.name === "return" || key.name === "enter") {
30
+ cleanup();
31
+ stdout.write(`You selected: ${options[selectedIndex]}\n`);
32
+ process.exit(0);
33
+ }
34
+ });
35
+ process.on("SIGINT", () => {
36
+ exitWithCode(130);
37
+ });
38
+ function cleanup() {
39
+ if (stdin.isTTY) {
40
+ stdin.setRawMode(false);
41
+ }
42
+ stdin.pause();
43
+ }
44
+ function render() {
45
+ if (renderedLineCount > 0) {
46
+ readline.moveCursor(stdout, 0, -renderedLineCount);
47
+ readline.clearScreenDown(stdout);
48
+ }
49
+ const lines = [
50
+ "Select an option:",
51
+ ...options.map((option, index) => `${index === selectedIndex ? ">" : " "} ${option}`)
52
+ ];
53
+ stdout.write(`${lines.join("\n")}\n`);
54
+ renderedLineCount = lines.length;
55
+ }
56
+ function exitWithCode(code) {
57
+ if (hasExited) {
58
+ return;
59
+ }
60
+ hasExited = true;
61
+ cleanup();
62
+ process.exit(code);
63
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env tsx
2
+ export {};
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env tsx
2
+ import readline from "node:readline";
3
+ const terminal = readline.createInterface({
4
+ input: process.stdin,
5
+ output: process.stdout
6
+ });
7
+ let hasGreeted = false;
8
+ process.stdout.write("What is your name? ");
9
+ terminal.on("line", (name) => {
10
+ if (hasGreeted) {
11
+ return;
12
+ }
13
+ hasGreeted = true;
14
+ console.log(`Hello, ${name}!`);
15
+ terminal.close();
16
+ });
17
+ terminal.on("close", () => {
18
+ if (!hasGreeted) {
19
+ console.log(`Hello, ${terminal.line}!`);
20
+ }
21
+ process.exit(0);
22
+ });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "terminal-pilot",
3
+ "version": "0.0.1",
4
+ "description": "Headless terminal session manager with MCP server support",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./mcp": {
14
+ "types": "./dist/mcp-server.d.ts",
15
+ "import": "./dist/mcp-server.js"
16
+ }
17
+ },
18
+ "bin": {
19
+ "terminal-pilot-mcp": "dist/mcp-server.js"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "prepublishOnly": "tsc",
24
+ "install-local-package": "TMPD=$(mktemp -d) && cd ../tiny-stdio-mcp-server && npm pack --pack-destination $TMPD && cd ../terminal-pilot && npm pack --pack-destination $TMPD && npm install -g $TMPD/poe-code-terminal-pilot-*.tgz $TMPD/tiny-stdio-mcp-server-*.tgz && rm -rf $TMPD"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/poe-platform/poe-code.git",
35
+ "directory": "packages/terminal-pilot"
36
+ },
37
+ "license": "MIT",
38
+ "keywords": [
39
+ "terminal",
40
+ "mcp",
41
+ "pty",
42
+ "headless"
43
+ ],
44
+ "dependencies": {
45
+ "headless-terminal": "^0.4.0",
46
+ "node-pty": "^1.1.0",
47
+ "tiny-stdio-mcp-server": "^0.1.0"
48
+ },
49
+ "devDependencies": {}
50
+ }