portless-studio 0.0.0-stage → 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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +321 -2
  3. package/dist/cli/cli-args.js +201 -0
  4. package/dist/cli/command-runner.js +10 -0
  5. package/dist/cli/config-command.js +46 -0
  6. package/dist/cli/doctor-command.js +36 -0
  7. package/dist/cli/focus-command.js +15 -0
  8. package/dist/cli/index.js +378 -0
  9. package/dist/cli/init.js +200 -0
  10. package/dist/cli/list-command.js +51 -0
  11. package/dist/cli/login-service.js +248 -0
  12. package/dist/cli/mcp/mcp-server.js +125 -0
  13. package/dist/cli/mcp/studio-client.js +201 -0
  14. package/dist/cli/mcp/studio-tools.js +610 -0
  15. package/dist/cli/open-browser.js +24 -0
  16. package/dist/cli/prompter.js +59 -0
  17. package/dist/cli/run-command.js +97 -0
  18. package/dist/cli/shutdown.js +14 -0
  19. package/dist/cli/studio-alias.js +56 -0
  20. package/dist/cli/studio-items.js +31 -0
  21. package/dist/cli/studio-service-control.js +56 -0
  22. package/dist/cli/uninstall.js +155 -0
  23. package/dist/core/api/contract.js +85 -0
  24. package/dist/core/config/studio-config.js +166 -0
  25. package/dist/core/doctor/doctor-check.js +8 -0
  26. package/dist/core/doctor/platform-commands.js +42 -0
  27. package/dist/core/ports/detected-port.js +64 -0
  28. package/dist/core/ports/name-template.js +114 -0
  29. package/dist/core/projects/custom-app.js +105 -0
  30. package/dist/core/projects/item-project.js +11 -0
  31. package/dist/core/projects/project-icon.js +20 -0
  32. package/dist/core/result.js +2 -0
  33. package/dist/core/routes/route-name.js +24 -0
  34. package/dist/core/routes/route.js +28 -0
  35. package/dist/core/terminals/output-buffer.js +56 -0
  36. package/dist/core/terminals/terminal.js +28 -0
  37. package/dist/core/updates/version.js +62 -0
  38. package/dist/core/views/arrange-routes.js +104 -0
  39. package/dist/core/views/view.js +165 -0
  40. package/dist/server/application/app-error.js +1 -0
  41. package/dist/server/application/auto-named-store.js +10 -0
  42. package/dist/server/application/auto-namer.js +70 -0
  43. package/dist/server/application/config-store.js +1 -0
  44. package/dist/server/application/doctor.js +337 -0
  45. package/dist/server/application/icon-resolver.js +67 -0
  46. package/dist/server/application/open-with.js +77 -0
  47. package/dist/server/application/port-discovery.js +72 -0
  48. package/dist/server/application/port-scanner.js +1 -0
  49. package/dist/server/application/process-control.js +1 -0
  50. package/dist/server/application/proxy-control.js +47 -0
  51. package/dist/server/application/proxy-start-check.js +83 -0
  52. package/dist/server/application/route-registry.js +1 -0
  53. package/dist/server/application/route-use-cases.js +66 -0
  54. package/dist/server/application/stop-process.js +24 -0
  55. package/dist/server/application/studio-events.js +127 -0
  56. package/dist/server/application/studio-runtime.js +581 -0
  57. package/dist/server/application/studio-service.js +1 -0
  58. package/dist/server/application/system-notifier.js +2 -0
  59. package/dist/server/application/terminals.js +446 -0
  60. package/dist/server/application/update-check.js +66 -0
  61. package/dist/server/infrastructure/apps/app-catalog.js +153 -0
  62. package/dist/server/infrastructure/apps/detached-launcher.js +62 -0
  63. package/dist/server/infrastructure/apps/json-stores.js +83 -0
  64. package/dist/server/infrastructure/config/atomic-write.js +41 -0
  65. package/dist/server/infrastructure/config/json-auto-named-store.js +40 -0
  66. package/dist/server/infrastructure/config/json-config-store.js +97 -0
  67. package/dist/server/infrastructure/config/json-update-cache.js +35 -0
  68. package/dist/server/infrastructure/config/proxy-start-record.js +54 -0
  69. package/dist/server/infrastructure/portless/portless-cli.js +110 -0
  70. package/dist/server/infrastructure/portless/portless-registry.js +181 -0
  71. package/dist/server/infrastructure/portless/state-files.js +146 -0
  72. package/dist/server/infrastructure/system/doctor-facts.js +214 -0
  73. package/dist/server/infrastructure/system/favicon-fetcher.js +145 -0
  74. package/dist/server/infrastructure/system/linux-ports.js +84 -0
  75. package/dist/server/infrastructure/system/macos-ports.js +76 -0
  76. package/dist/server/infrastructure/system/npm-registry.js +20 -0
  77. package/dist/server/infrastructure/system/os-notifier.js +143 -0
  78. package/dist/server/infrastructure/system/powershell.js +20 -0
  79. package/dist/server/infrastructure/system/process-runner.js +191 -0
  80. package/dist/server/infrastructure/system/project-info.js +127 -0
  81. package/dist/server/infrastructure/system/system-io.js +38 -0
  82. package/dist/server/infrastructure/system/system-port-scanner.js +103 -0
  83. package/dist/server/infrastructure/system/system-process-control.js +129 -0
  84. package/dist/server/infrastructure/system/windows-ports.js +193 -0
  85. package/dist/server/infrastructure/terminal/terminal-spawner.js +177 -0
  86. package/dist/server/interface/http/focus-broker.js +98 -0
  87. package/dist/server/interface/http/http-server.js +395 -0
  88. package/dist/server/interface/http/json-io.js +84 -0
  89. package/dist/server/interface/http/request-guards.js +40 -0
  90. package/dist/server/interface/http/snapshot-events.js +83 -0
  91. package/dist/server/interface/http/static-files.js +140 -0
  92. package/dist/server/interface/http/terminal-streams.js +69 -0
  93. package/dist/server/main.js +240 -0
  94. package/dist/web/assets/Geist-Variable-Bj2R_7yk.woff2 +0 -0
  95. package/dist/web/assets/GeistMono-Variable-Dispecij.woff2 +0 -0
  96. package/dist/web/assets/addon-fit-DIOBYJe3.js +1 -0
  97. package/dist/web/assets/index-B3KMqQ-l.js +15 -0
  98. package/dist/web/assets/index-CWujmTe4.css +1 -0
  99. package/dist/web/assets/xterm-B1njb2Cr.css +1 -0
  100. package/dist/web/assets/xterm-CerOhKYV.js +16 -0
  101. package/dist/web/index.html +19 -0
  102. package/dist/web/theme-init.js +6 -0
  103. package/package.json +67 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Keven Bardales
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.
package/README.md CHANGED
@@ -1,3 +1,322 @@
1
- # Temporary Holding Version
1
+ # portless studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/portless-studio)](https://www.npmjs.com/package/portless-studio)
4
+ [![CI](https://github.com/keven-bardales/portless-studio/actions/workflows/ci.yml/badge.svg)](https://github.com/keven-bardales/portless-studio/actions/workflows/ci.yml)
5
+
6
+ A local web dashboard for [portless](https://github.com/vercel-labs/portless): see every dev server
7
+ on your machine, give each one a name like `web.myapp.localhost`, and open it from one page.
8
+
9
+ <picture>
10
+ <source media="(prefers-color-scheme: dark)" srcset="docs/images/dashboard-dark.png">
11
+ <img alt="The Studio dashboard: detected ports without a name at the top, named routes grouped by project below, each with its branch, folder, port and uptime" src="docs/images/dashboard-light.png" width="1280">
12
+ </picture>
13
+
14
+ portless replaces port numbers with names: `portless api pnpm dev` serves your app at
15
+ `http://api.localhost:1355` instead of `http://localhost:3000`. It has no interface of its own, so
16
+ with ten dev servers across several projects you have to remember which names exist and which
17
+ ports have none. Studio shows both, live, and names a port in one click.
18
+
19
+ ![Naming port 8000, searching routes with Ctrl+K, filtering with the Filter popover and running pnpm dev in a Studio terminal](docs/images/demo.gif)
20
+
21
+ The screenshots use the built-in sample data (`?demo`), not a real machine.
22
+
23
+ ## Install
24
+
25
+ Requires Node 22 or later.
26
+
27
+ To try it, run it straight from npm:
28
+
29
+ ```bash
30
+ npx portless-studio init
31
+ ```
32
+
33
+ For everyday use, and always for "start at login", install it globally:
34
+
35
+ ```bash
36
+ npm i -g portless-studio
37
+ portless-studio init
38
+ ```
39
+
40
+ The login service starts Studio from the files npm installed. Run through `npx`, those files sit in
41
+ npm's cache, which npm can clear at any time, and then Studio stops starting at login.
42
+
43
+ To update, install the latest version and restart Studio:
44
+
45
+ ```bash
46
+ npm i -g portless-studio@latest
47
+ ```
48
+
49
+ To remove it, undo the setup first, then remove the package:
50
+
51
+ ```bash
52
+ portless-studio uninstall
53
+ npm rm -g portless-studio
54
+ ```
55
+
56
+ ## Quick start
57
+
58
+ `init` asks a few questions and leaves everything working:
59
+
60
+ - Checks that portless is installed and offers to install it with `npm install -g portless`.
61
+ - Asks for the basic settings (auto mode, start at login, port, open the browser) and saves them.
62
+ - Finds the dev servers already running, suggests a name for each and names them in portless.
63
+ - Starts the portless proxy on port 1355 over HTTP, which needs no password, certificate or extra
64
+ tool on macOS, Windows or Linux, and can set Studio to start when you log in.
65
+
66
+ `init --yes` accepts every default without asking. After that, `portless-studio` starts
67
+ Studio at `http://127.0.0.1:4949`, registers it in portless as `studio` and opens your browser.
68
+ Your apps open at names like `http://web.myapp.localhost:1355`: Chrome, Edge and Firefox send
69
+ every `*.localhost` name to your own machine, with no hosts file and no DNS setup.
70
+
71
+ To try the page without portless, start Studio and open `http://127.0.0.1:4949/?demo` for sample
72
+ data, or `?demo&noportless` to walk through the install flow with a fake install.
73
+
74
+ ## What it does
75
+
76
+ - **Live list** of portless routes: name, URL, port, app or alias, uptime and any Tailscale, ngrok
77
+ or Cloudflare tunnel. It updates as soon as a route appears or goes away.
78
+ - **Detected ports:** listening ports that answer HTTP but have no name yet, with the process, the
79
+ project folder and a suggested name. Name one, name them all, or ignore one.
80
+ - **Auto mode** (off by default): every new dev server gets its suggested name by itself, once
81
+ it has shown up unnamed in two scans in a row, so a server started with `portless <name>` keeps
82
+ the name portless gives it. Names auto mode gave are removed 10 minutes after their port closes.
83
+ - **Name a port** that portless did not start, such as a database in Docker (`db` gives
84
+ `db.localhost`). Rename or remove those names later.
85
+ - **Where each server runs:** every row shows the git branch, the linked worktree and the project
86
+ folder. A route whose server is down keeps the last place it ran.
87
+ - **Views:** group by project, worktree, kind or status, or into your own groups; sort, and
88
+ filter by kind, status or project from the Filter button; save the combination as a named view
89
+ and pick the one that opens by default.
90
+ - **Terminals:** run a command per project inside Studio and watch its output in a panel. You, the
91
+ CLI and your AI agents drive the same terminals. See [docs/terminals.md](docs/terminals.md).
92
+ - **Agents:** an MCP server lets Claude Code, Cursor and other agents list, name and stop dev
93
+ servers and run commands in Studio terminals. See [docs/mcp.md](docs/mcp.md).
94
+ - **Open with:** right-click a row to open its folder in an editor found on your machine (VS Code,
95
+ Cursor, Zed, WebStorm, IntelliJ IDEA, Sublime Text), reveal it in the file manager or copy its
96
+ path. Add your own apps in Settings.
97
+ - **Health:** each route's dot says whether its port answers. The Health panel and
98
+ `portless-studio doctor` find a proxy left running as root, two proxies at once, an untrusted
99
+ certificate or a taken port, and give the fix.
100
+ - **Proxy and Studio control:** start, stop or restart the portless proxy, and stop or restart
101
+ Studio, from the page.
102
+ - **Stop a dev server** from its row, after a confirmation. Only your own processes on a port
103
+ Studio shows.
104
+ - **Project icons:** the favicon the server serves, else one in the project folder, else the
105
+ project's initials. Set an emoji or an image per project in Settings.
106
+ - **Notifications** in the page when a server is detected or named, and optionally from the
107
+ operating system.
108
+ - **Install portless** from the page when the `portless` command is missing.
109
+ - **Keyboard first:** every action has a key, `?` lists them and `Ctrl+K` (`Cmd+K`) runs any of
110
+ them by name.
111
+
112
+ ## How naming works
113
+
114
+ A suggested name says what the work is, then the app, then the repository. The package
115
+ `@acme/web` in the `acme-monorepo` folder on the branch `feat/ED-1234-add-x` gets
116
+ `ed-1234.web.acme`, so two worktrees of one repository get different names. That is the order
117
+ portless uses for worktrees, `<branch>.<name>.localhost`.
118
+
119
+ Change it with `nameTemplate`, for example `{ticket}.{repo}` or `{package}-{port}`.
120
+ [docs/naming.md](docs/naming.md) lists every token and how empty or repeated parts are dropped.
121
+
122
+ Anything that names a route through the portless CLI also shows up in Studio:
123
+
124
+ ```bash
125
+ portless web.myapp pnpm dev # a dev server, at web.myapp.localhost
126
+ portless alias db.myapp 5432 # a port something else opened, at db.myapp.localhost
127
+ ```
128
+
129
+ ## Agents and MCP
130
+
131
+ `portless-studio mcp` is an [MCP](https://modelcontextprotocol.io) server on stdio. It talks to the
132
+ Studio already running, so whatever an agent changes shows up in the page at once. For Claude Code:
133
+
134
+ ```bash
135
+ claude mcp add --scope user portless-studio -- npx -y portless-studio mcp
136
+ ```
137
+
138
+ [docs/mcp.md](docs/mcp.md) has the setup for Cursor and other clients, the list of tools, and
139
+ instructions to paste into your agent so it names dev servers after the ticket or pull request.
140
+ `portless-studio list --json` and `doctor --json` give the same data to scripts.
141
+
142
+ ## Terminals
143
+
144
+ ```bash
145
+ portless-studio run -- pnpm dev
146
+ ```
147
+
148
+ `run` starts the command in a Studio terminal in the current folder, prints its output here,
149
+ names the first port it opens and stops it on Ctrl+C. The terminal stays visible in the page.
150
+ [docs/terminals.md](docs/terminals.md) covers the panel, the CLI and the security rules.
151
+
152
+ ## Platforms
153
+
154
+ Studio runs on Linux, macOS and Windows with Node 22 or later and installs nothing beyond portless. Each
155
+ feature uses tools the system already has (`/proc` on Linux, `lsof` on macOS, `netstat` and
156
+ PowerShell on Windows). [docs/platforms.md](docs/platforms.md) says what each system uses and what
157
+ does not work the same everywhere.
158
+
159
+ ## Commands
160
+
161
+ | Command | What it does |
162
+ | --- | --- |
163
+ | `portless-studio` | Starts Studio with the settings from the config file. |
164
+ | `portless-studio init [--yes]` | The setup above. Safe to run again. |
165
+ | `portless-studio uninstall [--yes]` | Undoes the setup: removes the login service, the names auto mode gave and the `studio` name, and stops the proxy if Studio started it. Names you or an agent gave stay. Asks before deleting the settings folder. |
166
+ | `portless-studio service install` | Starts Studio when you log in: a systemd user unit on Linux, a LaunchAgent on macOS, a script in the Startup folder on Windows. |
167
+ | `portless-studio service uninstall` | Undoes `service install`. |
168
+ | `portless-studio service status` | Says whether the login service is installed and running. |
169
+ | `portless-studio config [--edit] [--json]` | Prints the config file path and contents, or opens it in `$EDITOR`. |
170
+ | `portless-studio doctor [--json]` | Checks portless, the proxy, the certificate, Studio's port and the login service, and prints the fix for each problem. Exits with 1 when something fails. |
171
+ | `portless-studio list [--json]` | Lists named routes and ports without a name. |
172
+ | `portless-studio mcp` | Runs the MCP server on stdio for AI agents. |
173
+ | `portless-studio run [--name <name>] [--cwd <dir>] -- <command...>` | Runs a command in a Studio terminal and names the port it opens. |
174
+ | `portless-studio open [target]` | Brings Studio to the front showing a route, project, terminal id or `port:<n>`. |
175
+
176
+ | Flag | Effect |
177
+ | --- | --- |
178
+ | `--port <n>` | Port for the dashboard on 127.0.0.1. Default: `port` in the config, 4949. `0` picks a free one. |
179
+ | `--no-open` | Do not open the browser. |
180
+ | `--no-register` | Do not register the `studio` name in portless. |
181
+ | `-y`, `--yes` | With `init` and `uninstall`: accept every default. |
182
+ | `-h`, `--help` | Show the help. |
183
+ | `-v`, `--version` | Show the version. |
184
+
185
+ | Environment variable | What it does |
186
+ | --- | --- |
187
+ | `PORTLESS_STUDIO_CONFIG` | Path of the config file. |
188
+ | `PORTLESS_STATE_DIR` | portless state folder. Default `~/.portless`. |
189
+ | `PORTLESS_BIN` | portless binary used to create and remove names. Default `portless`. |
190
+ | `PORTLESS_STUDIO_URL` | Studio that `mcp`, `list`, `run` and `open` talk to. Default `http://127.0.0.1:<port>`. |
191
+ | `PORTLESS_STUDIO_NO_UPDATE_CHECK` | `1` turns the daily update check off, whatever the config says. |
192
+ | `EDITOR` | Editor that `config --edit` opens. |
193
+
194
+ ## Config file
195
+
196
+ Settings live in one JSON file: `~/.config/portless-studio/config.json` on Linux and macOS (or
197
+ under `$XDG_CONFIG_HOME`), `%APPDATA%\portless-studio\config.json` on Windows. `portless-studio
198
+ config` prints the path. Edit it by hand or from the Settings panel; a running Studio picks up the
199
+ changes without a restart. Missing fields take their default.
200
+
201
+ | Field | Default | What it does |
202
+ | --- | --- | --- |
203
+ | `port` | `4949` | Port Studio listens on, on 127.0.0.1. |
204
+ | `autoName` | `false` | Gives every new dev server a portless name automatically. |
205
+ | `autoRemoveAfterMinutes` | `10` | Minutes a name auto mode gave survives after its port closes. `0` keeps them. |
206
+ | `openBrowser` | `true` | Opens the browser when Studio starts. |
207
+ | `registerStudioAlias` | `true` | Registers Studio itself in portless as `studio`. |
208
+ | `startProxy` | `true` | Starts the portless proxy when Studio starts and it is not running. |
209
+ | `proxyPort` | `1355` | Port of that proxy. 1355 needs no administrator rights; 443 removes the port from URLs. |
210
+ | `proxyHttps` | `false` | Serves the names over HTTPS. See the FAQ. |
211
+ | `scanIntervalMs` | `3000` | How often Studio looks for new listening ports, in milliseconds (at least 1000). |
212
+ | `ignoredPorts` | `[]` | Ports never shown as detected and never named automatically. |
213
+ | `ignoredProcesses` | editors, chat apps, browsers | Process names whose ports are never shown. |
214
+ | `views` | one view, `All`, grouped by project | Saved views: grouping, sort, filters and custom groups. |
215
+ | `defaultViewId` | `"all"` | The view the page opens with. |
216
+ | `favorites` | `[]` | Routes pinned above every group, by name or as `"port:3000"`. |
217
+ | `desktopNotifications` | `false` | Notifies from an open Studio tab while it is in the background. |
218
+ | `systemNotifications` | `false` | Asks the operating system to notify when no Studio tab is open. |
219
+ | `nameTemplate` | `"{work}.{package}.{repo}"` | How suggested names are built. See [docs/naming.md](docs/naming.md). |
220
+ | `projectIcons` | `{}` | Icon per project: an emoji, an http(s) image URL or a `data:image` URL. |
221
+ | `checkForUpdates` | `true` | Once a day, asks npm whether a newer portless-studio exists. See "Update notice" below. |
222
+
223
+ The `--port`, `--no-open` and `--no-register` flags win over the file for one run. Apps you add to
224
+ the Open with menu live in `open-with.json` next to the config file.
225
+
226
+ ### Update notice
227
+
228
+ Once a day Studio asks the npm registry for the latest version of portless-studio. When a newer
229
+ one exists, it prints one line on start and shows a banner in the page with the command to update;
230
+ dismissing the banner hides it until the next version. The request is a plain
231
+ `GET https://registry.npmjs.org/portless-studio/latest`: Studio sends nothing about your machine,
232
+ your projects or your routes. It gives up after 3 seconds and stays quiet when you are offline,
233
+ and it keeps the time of the last check in `update-check.json` next to the config file. It never
234
+ runs when the `CI` variable is set. Turn it off with `checkForUpdates: false`, the Settings
235
+ switch, or `PORTLESS_STUDIO_NO_UPDATE_CHECK=1`.
236
+
237
+ ## Keyboard shortcuts
238
+
239
+ | Keys | Action |
240
+ | --- | --- |
241
+ | `j` / `↓`, `k` / `↑` | Next and previous row |
242
+ | `Home`, `End` | First and last row |
243
+ | `/` | Search routes |
244
+ | `Enter` or `o` | Open the selected route |
245
+ | `c` | Copy its URL |
246
+ | `r` | Rename an alias |
247
+ | `Delete` or `Backspace` | Remove an alias |
248
+ | `f` | Pin or unpin as favorite |
249
+ | `.` or `Shift+F10` | Open with, copy path and more |
250
+ | `t` | Open a terminal in its folder |
251
+ | `n` | Name a port |
252
+ | `v` / `Shift+V` | Next view / open the view menu |
253
+ | `Shift+F` | Open the filters |
254
+ | `[`, `]` | Collapse or expand all groups |
255
+ | `Ctrl+K` / `Cmd+K` | Command menu |
256
+ | `,` | Settings |
257
+ | `?` | All keyboard shortcuts |
258
+ | `Esc` | Close a dialog or cancel |
259
+
260
+ ## Security
261
+
262
+ Studio is a local tool and only listens on `127.0.0.1`. It rejects requests whose `Host` or
263
+ `Origin` is not local, so other websites open in your browser cannot read your routes or call the
264
+ API. Every change (naming, removing, installing portless, controlling the proxy or Studio, stopping
265
+ a dev server, running terminals) also needs a token that changes on every run. The page reads it from
266
+ Studio, and browsers only let pages served by Studio itself read it. The portless install always runs the same fixed command.
267
+ A dev server can be stopped only when it belongs to your user and listens on a port Studio shows,
268
+ and Studio never runs a command that needs sudo. See [SECURITY.md](SECURITY.md) to report a
269
+ problem.
270
+
271
+ ## FAQ
272
+
273
+ **Safari does not open `*.localhost` names.** Safari does not always send `.localhost` names to
274
+ your machine. Open Studio at `http://127.0.0.1:4949` and each app at `http://127.0.0.1:<its port>`,
275
+ or use Chrome, Edge or Firefox.
276
+
277
+ **Why HTTP on port 1355, and how do I get HTTPS or port 443?** Port 1355 needs no administrator
278
+ rights on any system, and browsers treat plain HTTP on a `.localhost` name as a secure context, so
279
+ most apps work as they would on HTTPS. For URLs without a port, set `proxyPort` to `443`; on Linux
280
+ that needs sudo once to start the proxy. For HTTPS, set `proxyHttps` to `true` and trust the
281
+ portless certificate: `portless-studio doctor` prints the exact command for your system, and the
282
+ Health panel shows it too.
283
+
284
+ **Does it work on Windows?** Yes, with Node 22 or later and PowerShell 5 (included in Windows 10 and 11).
285
+ Ports come from `netstat`, process details from PowerShell, and start at login uses a hidden
286
+ script in the Startup folder. Windows has no service manager Studio can ask, so the page can stop
287
+ Studio but not restart it, and the doctor only sees the proxy portless records.
288
+ [docs/platforms.md](docs/platforms.md) lists every difference.
289
+
290
+ **How does it relate to portless?** Studio is an independent project, not part of portless and not
291
+ made by its authors. It reads the state portless keeps in `~/.portless` and names routes through
292
+ the `portless` command, so anything you or an agent do with portless shows up in Studio, and
293
+ Studio never changes how portless works.
294
+
295
+ **How do I remove it?** Run `portless-studio uninstall` (or `npx portless-studio uninstall` if you
296
+ never installed it globally). It removes the login service, the names auto mode gave and the
297
+ `studio` name, stops the proxy if Studio started it, and asks before deleting the settings folder.
298
+ Then remove the package with `npm rm -g portless-studio`. portless itself stays installed; remove it with
299
+ `npm uninstall -g portless`.
300
+
301
+ ## Development
302
+
303
+ ```bash
304
+ git clone https://github.com/keven-bardales/portless-studio
305
+ cd portless-studio
306
+ pnpm install
307
+ pnpm dev # API on :4949 and the web app with hot reload on :5173
308
+ pnpm test # unit and component tests
309
+ pnpm typecheck
310
+ pnpm check # lint and format check
311
+ pnpm build # builds dist/, then `pnpm start` runs it
312
+ pnpm smoke # starts the built CLI on a free port and checks the API answers
313
+ ```
314
+
315
+ The code is split so the web app can talk to another backend later: see
316
+ [docs/architecture.md](docs/architecture.md). Conventions are in
317
+ [docs/conventions.md](docs/conventions.md), and [CONTRIBUTING.md](CONTRIBUTING.md) covers pull
318
+ requests.
319
+
320
+ ## License
321
+
322
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,201 @@
1
+ import { parseArgs } from "node:util";
2
+ import { err, ok } from "../core/result.js";
3
+ import { parsePort } from "../core/routes/route-name.js";
4
+ export const DEFAULT_PORT = 4949;
5
+ export const HELP = `portless-studio: a local web dashboard for portless routes
6
+
7
+ Usage:
8
+ portless-studio [options] Start Studio
9
+ portless-studio init [--yes] Set everything up: portless, settings, names, proxy
10
+ portless-studio uninstall [--yes] Undo the setup: login service, names Studio gave, the
11
+ proxy it started; asks before deleting the settings
12
+ portless-studio service install Start Studio when you log in
13
+ portless-studio service uninstall Stop starting Studio when you log in
14
+ portless-studio service status Say whether the login service is installed and running
15
+ portless-studio config [--edit] Print the config file, or open it in $EDITOR
16
+ portless-studio doctor Check portless, the proxy and Studio, and say how to fix
17
+ what is wrong (exit code 1 when something fails)
18
+ portless-studio list [--json] List named routes and ports without a name, from the running
19
+ Studio (or read directly when it is not running)
20
+ portless-studio mcp Run an MCP server on stdio so AI agents can list, name and
21
+ stop dev servers through the running Studio (docs/mcp.md)
22
+ portless-studio run [--name <name>] [--cwd <dir>] -- <command...>
23
+ Run a command in a Studio terminal, name the port it
24
+ opens and print its output here until Ctrl+C, which stops
25
+ it (docs/terminals.md)
26
+ portless-studio open [target] Bring Studio to the front showing a route, project,
27
+ terminal id or port:<n>
28
+
29
+ Options:
30
+ --port <n> Port for the dashboard, on 127.0.0.1 (default from the config, ${DEFAULT_PORT};
31
+ 0 picks a free one)
32
+ --no-open Do not open the browser
33
+ --no-register Do not register the "studio" portless alias for the dashboard
34
+ -y, --yes With init and uninstall: accept every default without asking
35
+ --json With doctor, config and list: print JSON for scripts and agents
36
+ --name <name> With run: name for the port the command opens (default: the suggested one)
37
+ --cwd <dir> With run: folder to run in (default: the current folder)
38
+ -h, --help Show this help
39
+ -v, --version Show the version
40
+
41
+ Environment:
42
+ PORTLESS_STATE_DIR portless state directory (default ~/.portless)
43
+ PORTLESS_BIN portless binary used to create and remove aliases (default: portless)
44
+ EDITOR Editor that \`config --edit\` opens
45
+ PORTLESS_STUDIO_URL Studio that \`mcp\`, \`list\`, \`run\` and \`open\` talk to
46
+ (default http://127.0.0.1:<port>)
47
+ `;
48
+ const SUBCOMMANDS = new Set([
49
+ "init",
50
+ "uninstall",
51
+ "service",
52
+ "config",
53
+ "doctor",
54
+ "list",
55
+ "mcp",
56
+ "run",
57
+ "open",
58
+ ]);
59
+ const SERVICE_ACTIONS = new Set(["install", "uninstall", "status"]);
60
+ /** Turns command-line arguments into options, or a message saying what is wrong with them. */
61
+ export function parseCliArgs(argv) {
62
+ const first = argv[0];
63
+ const subcommand = first !== undefined && !first.startsWith("-") ? first : null;
64
+ if (subcommand !== null && !SUBCOMMANDS.has(subcommand)) {
65
+ return err(`Unknown command "${subcommand}".`);
66
+ }
67
+ const rest = subcommand === null ? argv : argv.slice(1);
68
+ let parsed;
69
+ try {
70
+ parsed = parseFlags(rest, subcommand);
71
+ }
72
+ catch (error) {
73
+ return err(error.message);
74
+ }
75
+ const { values, positionals } = parsed;
76
+ if (values.help)
77
+ return ok({ command: "help" });
78
+ if (values.version)
79
+ return ok({ command: "version" });
80
+ if (subcommand === "init")
81
+ return ok({ command: "init", yes: values.yes === true });
82
+ if (subcommand === "uninstall")
83
+ return ok({ command: "uninstall", yes: values.yes === true });
84
+ const json = values.json === true;
85
+ if (subcommand === "config") {
86
+ if (values.edit && json)
87
+ return err("Use either --edit or --json, not both.");
88
+ return ok({ command: "config", edit: values.edit === true, json });
89
+ }
90
+ if (subcommand === "doctor")
91
+ return ok({ command: "doctor", json });
92
+ if (subcommand === "list")
93
+ return ok({ command: "list", json });
94
+ if (subcommand === "mcp")
95
+ return ok({ command: "mcp" });
96
+ if (subcommand === "run") {
97
+ if (positionals.length === 0) {
98
+ return err('Give the command to run after "--", e.g. portless-studio run -- pnpm dev');
99
+ }
100
+ if (values.name !== undefined && values.name.trim() === "")
101
+ return err("--name needs a name.");
102
+ return ok({
103
+ command: "run",
104
+ cwd: values.cwd ?? null,
105
+ name: values.name?.trim() ?? null,
106
+ argv: positionals,
107
+ });
108
+ }
109
+ if (subcommand === "open") {
110
+ if (positionals.length > 1)
111
+ return err('Give one target to "open", e.g. web.myapp or t2.');
112
+ return ok({ command: "open", target: positionals[0] ?? null });
113
+ }
114
+ if (subcommand === "service") {
115
+ const action = positionals[0];
116
+ if (action === undefined || !SERVICE_ACTIONS.has(action) || positionals.length > 1) {
117
+ return err('Use "service install", "service uninstall" or "service status".');
118
+ }
119
+ return ok({ command: "service", action: action });
120
+ }
121
+ const overrides = {};
122
+ if (values.port !== undefined) {
123
+ const port = values.port.trim() === "0" ? ok(0) : parsePort(values.port);
124
+ if (!port.ok)
125
+ return err(`Invalid --port "${values.port}": use a number from 0 to 65535.`);
126
+ overrides.port = port.value;
127
+ }
128
+ if (values.open !== undefined)
129
+ overrides.open = values.open;
130
+ if (values.register !== undefined)
131
+ overrides.register = values.register;
132
+ return ok({ command: "start", overrides });
133
+ }
134
+ /** Settings for starting the server: the config, with any flag taking its place. */
135
+ export function resolveStartSettings(overrides, config) {
136
+ return {
137
+ port: overrides.port ?? config.port,
138
+ open: overrides.open ?? config.openBrowser,
139
+ register: overrides.register ?? config.registerStudioAlias,
140
+ };
141
+ }
142
+ /** Each subcommand accepts only its own flags, so a typo fails instead of being ignored. */
143
+ function parseFlags(args, subcommand) {
144
+ const common = {
145
+ help: { type: "boolean", short: "h" },
146
+ version: { type: "boolean", short: "v" },
147
+ };
148
+ const json = { type: "boolean" };
149
+ const options = subcommand === "init" || subcommand === "uninstall"
150
+ ? { ...common, yes: { type: "boolean", short: "y" } }
151
+ : subcommand === "config"
152
+ ? { ...common, edit: { type: "boolean" }, json }
153
+ : subcommand === "doctor" || subcommand === "list"
154
+ ? { ...common, json }
155
+ : subcommand === "service" || subcommand === "mcp" || subcommand === "open"
156
+ ? common
157
+ : subcommand === "run"
158
+ ? { ...common, name: { type: "string" }, cwd: { type: "string" } }
159
+ : {
160
+ ...common,
161
+ port: { type: "string" },
162
+ open: { type: "boolean" },
163
+ register: { type: "boolean" },
164
+ };
165
+ // parseArgs learned `allowNegative` in Node 22.4; reading `--no-<flag>` here keeps every Node 22.
166
+ const { args: positive, negated } = splitNegations(args, options);
167
+ const { values, positionals, tokens } = parseArgs({
168
+ args: positive,
169
+ options,
170
+ tokens: true,
171
+ allowPositionals: subcommand === "service" || subcommand === "run" || subcommand === "open",
172
+ });
173
+ for (const token of tokens) {
174
+ if (token.kind === "option" && options[token.name]?.type === "boolean") {
175
+ values[token.name] = !negated.has(token.index);
176
+ }
177
+ }
178
+ return {
179
+ positionals,
180
+ values: values,
181
+ };
182
+ }
183
+ /**
184
+ * Turns each `--no-<flag>` of a boolean option into `--<flag>` and remembers its position, so the
185
+ * last of `--open` and `--no-open` wins. Arguments after `--` are left alone.
186
+ */
187
+ function splitNegations(args, options) {
188
+ const negated = new Set();
189
+ const end = args.indexOf("--");
190
+ const positive = args.map((arg, index) => {
191
+ if (end !== -1 && index > end)
192
+ return arg;
193
+ const match = /^--no-([^=]+)(=.*)?$/.exec(arg);
194
+ const name = match?.[1];
195
+ if (name === undefined || options[name]?.type !== "boolean")
196
+ return arg;
197
+ negated.add(index);
198
+ return `--${name}${match?.[2] ?? ""}`;
199
+ });
200
+ return { args: positive, negated };
201
+ }
@@ -0,0 +1,10 @@
1
+ import { runProcess } from "../server/infrastructure/system/process-runner.js";
2
+ /** The server's process runner, so Windows quoting and UTF-8 output work the same in the CLI. */
3
+ export const runCommand = async (command, args, options = {}) => {
4
+ const outcome = await runProcess(command, args, { inherit: options.inherit === true });
5
+ return {
6
+ exitCode: outcome.exitCode,
7
+ output: outcome.error ?? outcome.combined.trim(),
8
+ missing: outcome.missing,
9
+ };
10
+ };
@@ -0,0 +1,46 @@
1
+ import * as fs from "node:fs";
2
+ /** `portless-studio config`: where the file is and what Studio reads from it. */
3
+ export async function printConfig(store, print) {
4
+ print(`Config file: ${store.path}`);
5
+ const read = await store.read();
6
+ if (!read.ok) {
7
+ print(`The file has a problem: ${read.error.message}`);
8
+ return;
9
+ }
10
+ print(JSON.stringify(read.value, null, 2));
11
+ if (!fs.existsSync(store.path))
12
+ print("(The file is not created yet; these are the defaults.)");
13
+ }
14
+ /** `portless-studio config --json`: the same `{ config, path }` shape `GET /api/config` answers. */
15
+ export async function printConfigJson(store, print) {
16
+ const read = await store.read();
17
+ if (!read.ok) {
18
+ print(JSON.stringify({ error: read.error.message, path: store.path }, null, 2));
19
+ return 1;
20
+ }
21
+ const response = { config: read.value, path: store.path };
22
+ print(JSON.stringify(response, null, 2));
23
+ return 0;
24
+ }
25
+ /**
26
+ * `portless-studio config --edit`: opens the file in `editor` (`$EDITOR`, which may carry flags
27
+ * such as `code -w`). The file is created with the current values first so there is something to
28
+ * edit. Without an editor it prints the path.
29
+ */
30
+ export async function editConfig(store, editor, run, print) {
31
+ if (!fs.existsSync(store.path)) {
32
+ const read = await store.read();
33
+ if (read.ok)
34
+ await store.write(read.value);
35
+ }
36
+ const [command, ...flags] = (editor ?? "").trim().split(/\s+/).filter(Boolean);
37
+ if (command === undefined) {
38
+ print(`Set $EDITOR to open it from here, or edit it directly: ${store.path}`);
39
+ return;
40
+ }
41
+ const result = await run(command, [...flags, store.path], { inherit: true });
42
+ if (result.exitCode !== 0)
43
+ print(`${command} did not open the file. Edit it at: ${store.path}`);
44
+ else
45
+ print("Saved changes reach a running Studio without a restart.");
46
+ }
@@ -0,0 +1,36 @@
1
+ import { overallStatus } from "../core/doctor/doctor-check.js";
2
+ const MARKS = { ok: "✓", warn: "!", fail: "✗" };
3
+ /** A readable checklist: one line per check, then what was found and the fix for each problem. */
4
+ export function formatDoctorReport(checks) {
5
+ const lines = [];
6
+ for (const check of checks) {
7
+ lines.push(` ${MARKS[check.status]} ${check.title}`);
8
+ if (check.status === "ok")
9
+ continue;
10
+ lines.push(` ${check.detail}`);
11
+ if (check.fix?.command)
12
+ lines.push(` Fix: ${check.fix.command}`);
13
+ else if (check.fix)
14
+ lines.push(` Fix: "${check.fix.label}" in Studio's Health panel`);
15
+ }
16
+ lines.push("", summary(checks));
17
+ return lines.join("\n");
18
+ }
19
+ /** Prints the report; the exit code is 1 when any check fails, so scripts can rely on it. */
20
+ export async function runDoctorCommand(check, print, options = {}) {
21
+ const checks = await check();
22
+ const status = overallStatus(checks);
23
+ print(options.json ? JSON.stringify({ status, checks }, null, 2) : formatDoctorReport(checks));
24
+ return status === "fail" ? 1 : 0;
25
+ }
26
+ function summary(checks) {
27
+ const failures = checks.filter((check) => check.status === "fail").length;
28
+ const warnings = checks.filter((check) => check.status === "warn").length;
29
+ if (failures === 0 && warnings === 0)
30
+ return "Everything looks good.";
31
+ const parts = [
32
+ failures > 0 ? `${failures} ${failures === 1 ? "problem" : "problems"}` : null,
33
+ warnings > 0 ? `${warnings} ${warnings === 1 ? "warning" : "warnings"}` : null,
34
+ ].filter(Boolean);
35
+ return `${parts.join(" and ")}.`;
36
+ }
@@ -0,0 +1,15 @@
1
+ import { API_PATHS } from "../core/api/contract.js";
2
+ import { describeFocus } from "./mcp/studio-tools.js";
3
+ /**
4
+ * `portless-studio open [target]`: brings the Studio page to the front showing a route, a
5
+ * project, a terminal or a port. Returns the exit code.
6
+ */
7
+ export async function runOpenCommand(client, target, print, printError) {
8
+ const result = await client.write("POST", API_PATHS.focus, target ? { target } : {});
9
+ if (!result.ok) {
10
+ printError(`Error: ${result.error.message}`);
11
+ return 1;
12
+ }
13
+ print(describeFocus(result.value));
14
+ return 0;
15
+ }