ai-kanban-terminal 0.2.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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}*{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif}main{height:100vh;display:flex;flex-direction:column}.terminal-container{display:flex;flex-direction:column;height:100%;background:#1e1e1e;color:#d4d4d4}.terminal-header{display:flex;justify-content:space-between;align-items:center;padding:1rem 1.5rem;background:#252526;border-bottom:1px solid #3e3e42}.terminal-header h1{font-size:1.25rem;font-weight:600;color:#ccc;margin:0}.connection-status{display:flex;align-items:center;gap:.5rem;font-size:.875rem;color:#ccc}.status-indicator{width:10px;height:10px;border-radius:50%;transition:background-color .3s ease}.status-indicator.connected{background-color:#0dbc79;box-shadow:0 0 8px #0dbc7980}.status-indicator.disconnected{background-color:#cd3131;box-shadow:0 0 8px #cd313180}.terminal{flex:1;padding:1rem;overflow:hidden;outline:none}.terminal:focus{box-shadow:inset 0 0 0 2px #0078d4}.terminal .xterm{height:100%;width:100%}@media(prefers-contrast:high){.terminal-container{border:2px solid #ffffff}.terminal-header{border-bottom:2px solid #ffffff}.status-indicator.connected,.status-indicator.disconnected{border:2px solid #ffffff}}@media(prefers-reduced-motion:reduce){.status-indicator{transition:none}}@media(max-width:768px){.terminal-header{padding:.75rem 1rem}.terminal-header h1{font-size:1rem}.connection-status{font-size:.75rem}.terminal{padding:.5rem}}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <meta name="description" content="Browser-based terminal with bidirectional shell" />
7
+ <title>AI Kanban Terminal</title>
8
+ <script type="module" crossorigin src="/assets/index-CMu989wp.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-DCBCU9ry.css">
10
+ </head>
11
+ <body>
12
+ <div id="root"></div>
13
+ </body>
14
+ </html>
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "ai-kanban-terminal",
3
+ "version": "0.2.0",
4
+ "description": "Browser-based terminal with bidirectional shell using Vite, Express, node-pty, xterm.js, and Socket.IO",
5
+ "main": "server.js",
6
+ "type": "commonjs",
7
+ "bin": {
8
+ "ai-kanban-terminal": "./server.js"
9
+ },
10
+ "scripts": {
11
+ "dev": "vite",
12
+ "build": "vite build",
13
+ "start": "NODE_ENV=production node server.js",
14
+ "postinstall": "npm run build",
15
+ "prepublishOnly": "npm run build",
16
+ "test": "echo \"Error: no test specified\" && exit 1"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "server.js",
21
+ "package.json",
22
+ "README.md"
23
+ ],
24
+ "keywords": [
25
+ "terminal",
26
+ "xterm",
27
+ "node-pty",
28
+ "socket.io",
29
+ "vite",
30
+ "express",
31
+ "shell",
32
+ "browser-terminal"
33
+ ],
34
+ "author": "kght6123",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/kght6123/ai-kanban-terminal"
38
+ },
39
+ "license": "MIT",
40
+ "dependencies": {
41
+ "express": "^4.22.1",
42
+ "node-pty": "^1.1.0",
43
+ "socket.io": "^4.8.3",
44
+ "socket.io-client": "^4.8.3"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^25.0.9",
48
+ "@types/react": "^19.2.8",
49
+ "@types/react-dom": "^19.2.3",
50
+ "@vitejs/plugin-react": "^4.3.4",
51
+ "@xterm/addon-fit": "^0.11.0",
52
+ "@xterm/xterm": "^6.0.0",
53
+ "react": "^19.2.3",
54
+ "react-dom": "^19.2.3",
55
+ "typescript": "^5.9.3",
56
+ "vite": "^6.0.7"
57
+ }
58
+ }
package/server.js ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+
3
+ const express = require('express');
4
+ const path = require('path');
5
+ const { createServer } = require('http');
6
+ const { Server } = require('socket.io');
7
+ const pty = require('node-pty');
8
+ const os = require('os');
9
+
10
+ const hostname = 'localhost';
11
+ const port = parseInt(process.env.PORT || '3000', 10);
12
+
13
+ const expressApp = express();
14
+ const httpServer = createServer(expressApp);
15
+ const io = new Server(httpServer, {
16
+ cors: {
17
+ // NOTE: Wildcard origin is used for development convenience.
18
+ // For production, replace with specific allowed origins:
19
+ // origin: process.env.ALLOWED_ORIGINS?.split(',') || 'https://yourdomain.com'
20
+ origin: '*',
21
+ methods: ['GET', 'POST']
22
+ }
23
+ });
24
+
25
+ // Serve static files from dist directory
26
+ const distPath = path.join(__dirname, 'dist');
27
+ expressApp.use(express.static(distPath));
28
+
29
+ // Store terminal instances per socket
30
+ const terminals = new Map();
31
+
32
+ io.on('connection', (socket) => {
33
+ console.log('Client connected:', socket.id);
34
+
35
+ socket.on('create-terminal', ({ cols, rows }) => {
36
+ console.log('Creating terminal for socket:', socket.id);
37
+
38
+ try {
39
+ // Determine shell based on OS
40
+ const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
41
+
42
+ // Create pseudo-terminal
43
+ // NOTE: Uses HOME directory as working directory for development.
44
+ // For production or sandboxed environments, consider using a specific
45
+ // restricted directory: cwd: path.join(process.cwd(), 'workspace')
46
+ const ptyProcess = pty.spawn(shell, [], {
47
+ name: 'xterm-color',
48
+ cols: cols || 80,
49
+ rows: rows || 24,
50
+ cwd: process.env.HOME || process.cwd(),
51
+ env: process.env
52
+ });
53
+
54
+ // Store terminal instance
55
+ terminals.set(socket.id, ptyProcess);
56
+
57
+ // Send data from terminal to client
58
+ ptyProcess.onData((data) => {
59
+ socket.emit('terminal-output', data);
60
+ });
61
+
62
+ // Handle terminal exit
63
+ ptyProcess.onExit(({ exitCode, signal }) => {
64
+ console.log(`Terminal exited for ${socket.id}:`, exitCode, signal);
65
+ terminals.delete(socket.id);
66
+ socket.emit('terminal-exit', { exitCode, signal });
67
+ });
68
+
69
+ socket.emit('terminal-ready');
70
+ } catch (err) {
71
+ console.error('Failed to create terminal:', err);
72
+ socket.emit('terminal-error', { message: "Failed to create terminal" });
73
+ }
74
+ });
75
+
76
+ // Handle input from client
77
+ socket.on('terminal-input', (data) => {
78
+ const terminal = terminals.get(socket.id);
79
+ if (terminal) {
80
+ terminal.write(data);
81
+ }
82
+ });
83
+
84
+ // Handle terminal resize
85
+ socket.on('terminal-resize', ({ cols, rows }) => {
86
+ const terminal = terminals.get(socket.id);
87
+ if (terminal) {
88
+ terminal.resize(cols, rows);
89
+ }
90
+ });
91
+
92
+ // Clean up on disconnect
93
+ socket.on('disconnect', () => {
94
+ console.log('Client disconnected:', socket.id);
95
+ const terminal = terminals.get(socket.id);
96
+ if (terminal) {
97
+ terminal.kill();
98
+ terminals.delete(socket.id);
99
+ }
100
+ });
101
+ });
102
+
103
+ // Fallback to serve index.html for client-side routing
104
+ expressApp.get('*', (req, res) => {
105
+ res.sendFile(path.join(distPath, 'index.html'), (err) => {
106
+ if (err) {
107
+ console.error('Failed to serve index.html:', err);
108
+ res.status(500).send("Build artifacts (dist/index.html) not found. Please run 'npm run build' first.");
109
+ }
110
+ });
111
+ });
112
+
113
+ httpServer.listen(port, () => {
114
+ console.log(`> ai-kanban-terminal ready on http://${hostname}:${port}`);
115
+ }).on('error', (err) => {
116
+ console.error('Server failed to start:', err);
117
+ process.exit(1);
118
+ });