terminal-commands 0.1.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.
- package/README.md +130 -0
- package/dist/agent.js +35658 -0
- package/dist/cli.js +36600 -0
- package/dist/index.js +63164 -0
- package/dist/stdio.js +36796 -0
- package/package.json +38 -0
- package/src/agent-config.ts +40 -0
- package/src/agent-core.ts +173 -0
- package/src/agent.ts +16 -0
- package/src/cli-format.ts +57 -0
- package/src/cli-options.ts +459 -0
- package/src/cli.ts +475 -0
- package/src/credential-store.ts +98 -0
- package/src/device-auth.ts +163 -0
- package/src/index.ts +83 -0
- package/src/runner.ts +55 -0
- package/src/security.ts +112 -0
- package/src/server.ts +217 -0
- package/src/stdio.ts +16 -0
- package/test/agent-config.test.ts +32 -0
- package/test/agent-core.test.ts +37 -0
- package/test/cli-options.test.ts +121 -0
- package/test/credential-store.test.ts +44 -0
- package/test/device-auth.test.ts +88 -0
- package/test/runner.test.ts +29 -0
- package/test/security.test.ts +113 -0
- package/test/smoke.mjs +34 -0
- package/tsconfig.json +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Terminal Commands companion
|
|
2
|
+
|
|
3
|
+
A self-hosted MCP server for controlled terminal and filesystem access on the machine where it runs, reachable from ChatGPT, Claude, or any MCP-compatible client — locally over stdio, or remotely from ChatGPT web through Secure MCP Tunnel.
|
|
4
|
+
|
|
5
|
+
It can also run as the local execution component for the hosted Terminal Commands gateway. The
|
|
6
|
+
gateway connection is outbound-only and works on Windows, macOS, and Linux. The headless companion
|
|
7
|
+
forwards read-only tools by default and refuses command execution and file writes until terminal
|
|
8
|
+
approval prompts are enabled.
|
|
9
|
+
|
|
10
|
+
## Security model
|
|
11
|
+
|
|
12
|
+
- Binds to `127.0.0.1` by default and refuses public interfaces unless explicitly enabled.
|
|
13
|
+
- Intended for OpenAI Secure MCP Tunnel during private development.
|
|
14
|
+
- Marks command execution and file writes as destructive and also requires approval in the companion terminal.
|
|
15
|
+
- Runs programs without a shell. Shells, `sudo`, and `su` are blocked by default.
|
|
16
|
+
- Passes only a small environment allowlist to child processes, excluding API keys and other secrets.
|
|
17
|
+
- Restricts dedicated filesystem tools to the approved roots.
|
|
18
|
+
|
|
19
|
+
Command-line programs still execute with your operating-system user permissions. A program can access more than the dedicated filesystem tools, so review every command approval carefully.
|
|
20
|
+
|
|
21
|
+
## Run
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install
|
|
25
|
+
npm run build
|
|
26
|
+
MACHINE_TERMINAL_ROOTS="$HOME" npm start
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The health endpoint is `http://127.0.0.1:3333/health` and MCP is available at `http://127.0.0.1:3333/mcp`.
|
|
30
|
+
|
|
31
|
+
## Command line
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
terminal-commands login
|
|
35
|
+
terminal-commands connect --root ~/Documents/GitHub --root ~/work
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
From a checkout, the same commands run through npm. Everything after `--` reaches the CLI:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm run cli -- connect --root ~/Documents/GitHub --allow-destructive
|
|
42
|
+
npm run cli -- connect --help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Commands: `login`, `connect`, `status`, `logout`, `help`. Add `--help` to any of them to see only
|
|
46
|
+
the options it accepts.
|
|
47
|
+
|
|
48
|
+
### Options
|
|
49
|
+
|
|
50
|
+
| Option | Applies to | Environment variable | Meaning |
|
|
51
|
+
| -------------------------- | --------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `-r, --root <path>` | connect, status | `MACHINE_TERMINAL_ROOTS` | Approved filesystem root. Repeat the flag, or separate paths with the platform path delimiter. Defaults to the current directory. |
|
|
53
|
+
| `--name <name>` | connect, status | `MACHINE_TERMINAL_DEVICE_NAME` | Device name shown in the client. Defaults to the hostname. |
|
|
54
|
+
| `--device-id <id>` | connect, status | `MACHINE_TERMINAL_DEVICE_ID` | Device identifier to report. Defaults to the saved local device ID. |
|
|
55
|
+
| `--port <port>` | connect, status | `MACHINE_TERMINAL_PORT` | Port for the local MCP service. Defaults to `3333`. |
|
|
56
|
+
| `--host <host>` | connect, status | `MACHINE_TERMINAL_HOST` | Bind address for the local MCP service. Defaults to `127.0.0.1`. |
|
|
57
|
+
| `--gateway-url <url>` | connect, status | `MACHINE_TERMINAL_GATEWAY_URL` | Gateway WebSocket URL. |
|
|
58
|
+
| `--allow-destructive` | connect | `MACHINE_TERMINAL_AGENT_ALLOW_DESTRUCTIVE` | Ask in the terminal before each command and file write. Without it both are refused. |
|
|
59
|
+
| `--auto-approve` | connect | `MACHINE_TERMINAL_AUTO_APPROVE` | Approve every command and file write automatically, without a terminal prompt. Implies `--allow-destructive`. Use with caution. |
|
|
60
|
+
| `--allow-shell` | connect | `MACHINE_TERMINAL_ALLOW_SHELL` | Permit shells and privilege tools such as `sudo`. |
|
|
61
|
+
| `--allowed-program <name>` | connect | `MACHINE_TERMINAL_ALLOWED_PROGRAMS` | Executable allowlist. Repeat the flag or separate names with commas. |
|
|
62
|
+
| `--allow-public-bind` | connect | `MACHINE_TERMINAL_ALLOW_PUBLIC_BIND` | Permit a non-loopback bind. Only behind authenticated HTTPS. |
|
|
63
|
+
| `--auth-issuer <url>` | all | `MACHINE_TERMINAL_AUTH_ISSUER` | OAuth issuer, for a self-hosted gateway. |
|
|
64
|
+
| `--auth-client-id <id>` | all | `MACHINE_TERMINAL_AUTH_CLIENT_ID` | OAuth client ID. |
|
|
65
|
+
| `--auth-audience <url>` | all | `MACHINE_TERMINAL_AUTH_AUDIENCE` | OAuth audience. |
|
|
66
|
+
| `--dry-run` | connect | — | Print the resolved settings and exit without starting anything. |
|
|
67
|
+
| `--json` | connect, status | — | Print machine-readable JSON. |
|
|
68
|
+
|
|
69
|
+
A flag beats the environment variable, and the environment beats the default. `--root` replaces
|
|
70
|
+
`MACHINE_TERMINAL_ROOTS` rather than adding to it. On/off options accept `--no-` forms, so
|
|
71
|
+
`--no-allow-shell` overrides an environment variable that enabled shells.
|
|
72
|
+
|
|
73
|
+
Roots are expanded (`~` included), resolved to absolute paths, de-duplicated, and checked before
|
|
74
|
+
anything starts, so a typo fails immediately instead of silently approving the wrong folder.
|
|
75
|
+
`connect --dry-run` prints exactly what would be approved:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm run cli -- connect --root ~/Documents/GitHub --dry-run
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Configuration
|
|
82
|
+
|
|
83
|
+
Every option above can be set through its environment variable instead, which is what the Codex
|
|
84
|
+
plugin and service managers do.
|
|
85
|
+
|
|
86
|
+
- `MACHINE_TERMINAL_ROOTS`: path-delimited filesystem roots. Defaults to the directory where the companion starts.
|
|
87
|
+
- `MACHINE_TERMINAL_HOST`: bind host. Defaults to `127.0.0.1`.
|
|
88
|
+
- `MACHINE_TERMINAL_PORT`: bind port. Defaults to `3333`.
|
|
89
|
+
- `MACHINE_TERMINAL_ALLOWED_PROGRAMS`: optional comma-delimited executable allowlist.
|
|
90
|
+
- `MACHINE_TERMINAL_ALLOW_SHELL=1`: permits shells and privilege tools. Avoid enabling this unless necessary.
|
|
91
|
+
- `MACHINE_TERMINAL_ALLOW_PUBLIC_BIND=1`: permits a non-loopback bind. Do not enable without authenticated HTTPS and OAuth 2.1.
|
|
92
|
+
- `MACHINE_TERMINAL_AGENT_ALLOW_DESTRUCTIVE=1`: enables a terminal prompt for every command or file write. Non-interactive sessions deny these actions.
|
|
93
|
+
- `MACHINE_TERMINAL_AUTO_APPROVE=1`: approves every command and file write automatically, without prompting. Implies `MACHINE_TERMINAL_AGENT_ALLOW_DESTRUCTIVE=1`. Use with caution, and only when you trust the connected client.
|
|
94
|
+
|
|
95
|
+
## Hosted gateway companion
|
|
96
|
+
|
|
97
|
+
Run the local HTTP server and companion as separate processes:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm start
|
|
101
|
+
MACHINE_TERMINAL_GATEWAY_URL="wss://mcp.terminalcommands.fr/device/connect" \
|
|
102
|
+
MACHINE_TERMINAL_DEVICE_TOKEN="<short-lived-device-token>" \
|
|
103
|
+
MACHINE_TERMINAL_DEVICE_ID="my-computer" \
|
|
104
|
+
npm run start:agent
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The `terminal-commands login` command obtains the device token through OAuth Device Authorization
|
|
108
|
+
and stores it in a private local configuration file. Do not put real tokens in shell history.
|
|
109
|
+
|
|
110
|
+
## Connect an MCP client
|
|
111
|
+
|
|
112
|
+
Any MCP-compatible client can use this server. Local, stdio-based clients (such as Codex) connect
|
|
113
|
+
directly to the process; remote clients connect over HTTP to `http://127.0.0.1:3333/mcp` through a
|
|
114
|
+
tunnel or the hosted gateway.
|
|
115
|
+
|
|
116
|
+
### Connect ChatGPT web
|
|
117
|
+
|
|
118
|
+
1. Start this server locally.
|
|
119
|
+
2. In ChatGPT, enable Developer mode under **Settings → Security and login**.
|
|
120
|
+
3. Create or start an OpenAI Secure MCP Tunnel targeting `http://127.0.0.1:3333/mcp`.
|
|
121
|
+
4. In the Plugins page, add a connection, choose **Tunnel**, and select its `tunnel_id`.
|
|
122
|
+
5. Review the discovered tools and test in a new conversation.
|
|
123
|
+
|
|
124
|
+
### Connect Claude or other MCP clients
|
|
125
|
+
|
|
126
|
+
Point the client's remote MCP server configuration at the same `http://127.0.0.1:3333/mcp` endpoint
|
|
127
|
+
(or the tunneled/hosted HTTPS URL, once configured). Refer to the client's own documentation for how
|
|
128
|
+
it registers remote MCP servers; the connection and tool-discovery steps are otherwise identical.
|
|
129
|
+
|
|
130
|
+
For a published or independently hosted server, deploy a stable public HTTPS `/mcp` endpoint and implement OAuth 2.1. Do not expose this local server directly to the internet.
|