stage-ai 0.1.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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.js +54 -0
- package/dist/commands/exec.d.ts +4 -0
- package/dist/commands/exec.js +34 -0
- package/dist/commands/ls.d.ts +4 -0
- package/dist/commands/ls.js +32 -0
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.js +21 -0
- package/dist/commands/onboard.d.ts +2 -0
- package/dist/commands/onboard.js +69 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.js +82 -0
- package/dist/commands/read.d.ts +4 -0
- package/dist/commands/read.js +22 -0
- package/dist/commands/render.d.ts +4 -0
- package/dist/commands/render.js +24 -0
- package/dist/commands/write.d.ts +4 -0
- package/dist/commands/write.js +40 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +101 -0
- package/dist/utils/exit-codes.d.ts +5 -0
- package/dist/utils/exit-codes.js +5 -0
- package/dist/utils/output.d.ts +22 -0
- package/dist/utils/output.js +31 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Liv
|
|
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
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# stage-cli
|
|
2
|
+
|
|
3
|
+
> CLI client for [Stage](https://github.com/the-shift-dev/stage) — a sandboxed React runtime for AI agents.
|
|
4
|
+
|
|
5
|
+
Write files, run commands, and render React components in Stage's virtual filesystem. From the terminal. From any agent.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g stage-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Create a session
|
|
17
|
+
stage new
|
|
18
|
+
# ✓ Session created: abc123
|
|
19
|
+
# URL: http://localhost:3000/s/abc123
|
|
20
|
+
|
|
21
|
+
# Write a component
|
|
22
|
+
stage write /app/App.tsx ./App.tsx --session abc123
|
|
23
|
+
|
|
24
|
+
# Render it
|
|
25
|
+
stage render --session abc123
|
|
26
|
+
|
|
27
|
+
# Push a whole project
|
|
28
|
+
stage push ./my-app /app --session abc123
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Every command requires `--session <id>`. Create one with `stage new`.
|
|
32
|
+
|
|
33
|
+
## Commands
|
|
34
|
+
|
|
35
|
+
### `stage new`
|
|
36
|
+
|
|
37
|
+
Create a new session. Each session gets its own isolated virtual filesystem.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
stage new
|
|
41
|
+
stage new --json # { "id": "abc123", "url": "http://localhost:3000/s/abc123" }
|
|
42
|
+
stage new -q # prints just the ID
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `stage write <remote-path> [local-file] --session <id>`
|
|
46
|
+
|
|
47
|
+
Write a file to Stage's virtual FS. Reads from a local file or stdin (`-`).
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
stage write /app/App.tsx ./App.tsx --session abc123
|
|
51
|
+
echo '<h1>Hi</h1>' | stage write /app/App.tsx - --session abc123
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### `stage read <remote-path> --session <id>`
|
|
55
|
+
|
|
56
|
+
Read a file from Stage.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
stage read /app/App.tsx --session abc123
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `stage exec <command> --session <id>`
|
|
63
|
+
|
|
64
|
+
Run a bash command in Stage's virtual filesystem.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
stage exec "ls /app" --session abc123
|
|
68
|
+
stage exec "cat /app/App.tsx | grep import" --session abc123
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `stage render [entry] --session <id>`
|
|
72
|
+
|
|
73
|
+
Trigger Stage to render a component. Defaults to `/app/App.tsx`.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
stage render --session abc123 # renders /app/App.tsx
|
|
77
|
+
stage render /app/Dashboard.tsx --session abc123 # renders specific entry
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `stage ls [path] --session <id>`
|
|
81
|
+
|
|
82
|
+
List files in Stage's virtual FS.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
stage ls --session abc123 # list /app
|
|
86
|
+
stage ls /app/src --session abc123 # list subdirectory
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `stage push <local-dir> [remote-dir] --session <id>`
|
|
90
|
+
|
|
91
|
+
Push a local directory to Stage and auto-render.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
stage push ./my-app --session abc123 # push to /app
|
|
95
|
+
stage push ./src /app/src --session abc123 # push to specific dir
|
|
96
|
+
stage push ./my-app -e /app/Main.tsx --session abc123 # custom entry point
|
|
97
|
+
stage push ./my-app --no-render --session abc123 # skip auto-render
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `stage onboard`
|
|
101
|
+
|
|
102
|
+
Add Stage instructions to `CLAUDE.md` or `AGENTS.md` so agents know how to use it.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
stage onboard
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## For Agents
|
|
109
|
+
|
|
110
|
+
Every command supports `--json` for structured output:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
stage ls --json --session abc123
|
|
114
|
+
# { "path": "/app", "files": ["/app/App.tsx"], "count": 1, "session": "abc123" }
|
|
115
|
+
|
|
116
|
+
stage exec "ls /app" --json --session abc123
|
|
117
|
+
# { "stdout": "App.tsx\n", "stderr": "", "exitCode": 0, "session": "abc123" }
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Run `stage onboard` in your project to teach agents the commands.
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
| Env var | Default | Description |
|
|
125
|
+
|---------|---------|-------------|
|
|
126
|
+
| `STAGE_URL` | `http://localhost:3000` | Stage server URL |
|
|
127
|
+
|
|
128
|
+
## Available Libraries in Stage
|
|
129
|
+
|
|
130
|
+
Components rendered in Stage have access to:
|
|
131
|
+
|
|
132
|
+
- React (hooks, JSX)
|
|
133
|
+
- [shadcn/ui](https://ui.shadcn.com/) (Card, Button, Badge, Tabs, etc.)
|
|
134
|
+
- [Recharts](https://recharts.org/) (BarChart, LineChart, PieChart, etc.)
|
|
135
|
+
- [Lodash](https://lodash.com/)
|
|
136
|
+
- [PapaParse](https://www.papaparse.com/) (CSV parsing)
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage API client.
|
|
3
|
+
* Talks to the Stage server over HTTP.
|
|
4
|
+
*/
|
|
5
|
+
export declare function setBaseUrl(url: string): void;
|
|
6
|
+
export declare function getBaseUrl(): string;
|
|
7
|
+
export declare function stagePost(path: string, body: unknown, sessionId?: string): Promise<any>;
|
|
8
|
+
export declare function stageGet(path: string, sessionId?: string): Promise<any>;
|
|
9
|
+
export declare function stageDelete(path: string): Promise<any>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage API client.
|
|
3
|
+
* Talks to the Stage server over HTTP.
|
|
4
|
+
*/
|
|
5
|
+
let _urlOverride;
|
|
6
|
+
export function setBaseUrl(url) {
|
|
7
|
+
_urlOverride = url;
|
|
8
|
+
}
|
|
9
|
+
export function getBaseUrl() {
|
|
10
|
+
return _urlOverride || process.env.STAGE_URL || "http://localhost:3000";
|
|
11
|
+
}
|
|
12
|
+
function sessionHeaders(sessionId) {
|
|
13
|
+
return {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"X-Stage-Session": sessionId,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export async function stagePost(path, body, sessionId) {
|
|
19
|
+
const url = `${getBaseUrl()}${path}`;
|
|
20
|
+
const headers = sessionId
|
|
21
|
+
? sessionHeaders(sessionId)
|
|
22
|
+
: { "Content-Type": "application/json" };
|
|
23
|
+
const res = await fetch(url, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers,
|
|
26
|
+
body: JSON.stringify(body),
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
const text = await res.text();
|
|
30
|
+
throw new Error(`Stage ${res.status}: ${text}`);
|
|
31
|
+
}
|
|
32
|
+
return res.json();
|
|
33
|
+
}
|
|
34
|
+
export async function stageGet(path, sessionId) {
|
|
35
|
+
const url = `${getBaseUrl()}${path}`;
|
|
36
|
+
const headers = sessionId
|
|
37
|
+
? { "X-Stage-Session": sessionId }
|
|
38
|
+
: {};
|
|
39
|
+
const res = await fetch(url, { headers });
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const text = await res.text();
|
|
42
|
+
throw new Error(`Stage ${res.status}: ${text}`);
|
|
43
|
+
}
|
|
44
|
+
return res.json();
|
|
45
|
+
}
|
|
46
|
+
export async function stageDelete(path) {
|
|
47
|
+
const url = `${getBaseUrl()}${path}`;
|
|
48
|
+
const res = await fetch(url, { method: "DELETE" });
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
const text = await res.text();
|
|
51
|
+
throw new Error(`Stage ${res.status}: ${text}`);
|
|
52
|
+
}
|
|
53
|
+
return res.json();
|
|
54
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { stagePost } from "../client.js";
|
|
2
|
+
import { error, output } from "../utils/output.js";
|
|
3
|
+
import { EXIT_ERROR } from "../utils/exit-codes.js";
|
|
4
|
+
export async function exec(command, options) {
|
|
5
|
+
const sessionId = options.session;
|
|
6
|
+
try {
|
|
7
|
+
const result = await stagePost("/api/stage/exec", { command }, sessionId);
|
|
8
|
+
output(options, {
|
|
9
|
+
json: () => ({
|
|
10
|
+
stdout: result.stdout,
|
|
11
|
+
stderr: result.stderr,
|
|
12
|
+
exitCode: result.exitCode,
|
|
13
|
+
session: sessionId,
|
|
14
|
+
}),
|
|
15
|
+
quiet: () => {
|
|
16
|
+
if (result.stdout)
|
|
17
|
+
process.stdout.write(result.stdout);
|
|
18
|
+
process.exit(result.exitCode);
|
|
19
|
+
},
|
|
20
|
+
human: () => {
|
|
21
|
+
if (result.stdout)
|
|
22
|
+
process.stdout.write(result.stdout);
|
|
23
|
+
if (result.stderr)
|
|
24
|
+
process.stderr.write(result.stderr);
|
|
25
|
+
if (result.exitCode !== 0)
|
|
26
|
+
process.exit(result.exitCode);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
error(e.message);
|
|
32
|
+
process.exit(EXIT_ERROR);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { stagePost } from "../client.js";
|
|
2
|
+
import { error, output } from "../utils/output.js";
|
|
3
|
+
import { EXIT_ERROR } from "../utils/exit-codes.js";
|
|
4
|
+
export async function ls(remotePath, options) {
|
|
5
|
+
const sessionId = options.session;
|
|
6
|
+
const dir = remotePath || "/app";
|
|
7
|
+
try {
|
|
8
|
+
const result = await stagePost("/api/stage/exec", { command: `find ${dir} -type f 2>/dev/null | sort` }, sessionId);
|
|
9
|
+
const files = (result.stdout || "").trim();
|
|
10
|
+
const list = files ? files.split("\n") : [];
|
|
11
|
+
output(options, {
|
|
12
|
+
json: () => ({ path: dir, files: list, count: list.length, session: sessionId }),
|
|
13
|
+
quiet: () => {
|
|
14
|
+
if (files)
|
|
15
|
+
process.stdout.write(files + "\n");
|
|
16
|
+
},
|
|
17
|
+
human: () => {
|
|
18
|
+
if (!list.length) {
|
|
19
|
+
console.log("(empty)");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const f of list) {
|
|
23
|
+
console.log(f);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
error(e.message);
|
|
30
|
+
process.exit(EXIT_ERROR);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getBaseUrl, stagePost } from "../client.js";
|
|
2
|
+
import { error, output, success, hint } from "../utils/output.js";
|
|
3
|
+
import { EXIT_ERROR } from "../utils/exit-codes.js";
|
|
4
|
+
export async function newSession(options) {
|
|
5
|
+
try {
|
|
6
|
+
const result = await stagePost("/api/stage/sessions", {});
|
|
7
|
+
const url = `${getBaseUrl()}/s/${result.id}`;
|
|
8
|
+
output(options, {
|
|
9
|
+
json: () => ({ id: result.id, url }),
|
|
10
|
+
quiet: () => process.stdout.write(result.id),
|
|
11
|
+
human: () => {
|
|
12
|
+
success(`Session created: ${result.id}`);
|
|
13
|
+
hint(`URL: ${url}`);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
error(e.message);
|
|
19
|
+
process.exit(EXIT_ERROR);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { output, success } from "../utils/output.js";
|
|
4
|
+
const INSTRUCTIONS = `
|
|
5
|
+
<stage>
|
|
6
|
+
Use \`stage\` to write, read, and render files in Stage — a sandboxed React runtime.
|
|
7
|
+
Stage renders React components live in the browser. No build step, no deploy.
|
|
8
|
+
|
|
9
|
+
<commands>
|
|
10
|
+
- \`stage new\` — create a new session, returns session ID
|
|
11
|
+
- \`stage write <remote-path> <local-file> --session <id>\` — write a local file to Stage's virtual FS
|
|
12
|
+
- \`stage read <remote-path> --session <id>\` — read a file from Stage
|
|
13
|
+
- \`stage exec "<command>" --session <id>\` — run a bash command in Stage's virtual FS
|
|
14
|
+
- \`stage render [entry] --session <id>\` — trigger Stage to render (default: /app/App.tsx)
|
|
15
|
+
- \`stage ls [path] --session <id>\` — list files in Stage's virtual FS
|
|
16
|
+
- \`stage push <local-dir> [remote-dir] --session <id>\` — push a directory to Stage and render
|
|
17
|
+
</commands>
|
|
18
|
+
|
|
19
|
+
<rules>
|
|
20
|
+
- ALWAYS pass \`--session <id>\` on every command (create one with \`stage new\`)
|
|
21
|
+
- Use \`--json\` for structured output
|
|
22
|
+
- Remote paths are absolute (e.g. /app/App.tsx)
|
|
23
|
+
- Entry point must default-export a React component
|
|
24
|
+
- Available libraries: React, shadcn/ui, recharts, lodash, papaparse
|
|
25
|
+
- Set server with \`-u <url>\` flag or STAGE_URL env var (default: http://localhost:3000)
|
|
26
|
+
</rules>
|
|
27
|
+
</stage>
|
|
28
|
+
`.trim();
|
|
29
|
+
const MARKER = "<stage>";
|
|
30
|
+
export async function onboard(_args, options) {
|
|
31
|
+
const cwd = process.cwd();
|
|
32
|
+
const claudeMd = join(cwd, "CLAUDE.md");
|
|
33
|
+
const agentsMd = join(cwd, "AGENTS.md");
|
|
34
|
+
let targetFile;
|
|
35
|
+
if (existsSync(claudeMd)) {
|
|
36
|
+
targetFile = claudeMd;
|
|
37
|
+
}
|
|
38
|
+
else if (existsSync(agentsMd)) {
|
|
39
|
+
targetFile = agentsMd;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
targetFile = claudeMd;
|
|
43
|
+
}
|
|
44
|
+
let existingContent = "";
|
|
45
|
+
if (existsSync(targetFile)) {
|
|
46
|
+
existingContent = readFileSync(targetFile, "utf-8");
|
|
47
|
+
}
|
|
48
|
+
if (existingContent.includes(MARKER)) {
|
|
49
|
+
output(options, {
|
|
50
|
+
json: () => ({
|
|
51
|
+
success: true,
|
|
52
|
+
file: targetFile,
|
|
53
|
+
message: "already_onboarded",
|
|
54
|
+
}),
|
|
55
|
+
human: () => success(`Already onboarded (${targetFile})`),
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (existingContent) {
|
|
60
|
+
writeFileSync(targetFile, `${existingContent.trimEnd()}\n\n${INSTRUCTIONS}\n`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
writeFileSync(targetFile, `${INSTRUCTIONS}\n`);
|
|
64
|
+
}
|
|
65
|
+
output(options, {
|
|
66
|
+
json: () => ({ success: true, file: targetFile }),
|
|
67
|
+
human: () => success(`Added stage instructions to ${targetFile}`),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, posix } from "node:path";
|
|
3
|
+
import { stagePost } from "../client.js";
|
|
4
|
+
import { error, output, success, dim, bullet } from "../utils/output.js";
|
|
5
|
+
import { EXIT_ERROR, EXIT_USER_ERROR } from "../utils/exit-codes.js";
|
|
6
|
+
function walkDir(dir) {
|
|
7
|
+
const results = [];
|
|
8
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
9
|
+
const full = join(dir, entry.name);
|
|
10
|
+
if (entry.name === "node_modules" || entry.name.startsWith("."))
|
|
11
|
+
continue;
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
results.push(...walkDir(full));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
results.push(full);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
export async function push(localDir, remoteDir, options) {
|
|
22
|
+
const sessionId = options.session;
|
|
23
|
+
const targetDir = remoteDir || "/app";
|
|
24
|
+
let stat;
|
|
25
|
+
try {
|
|
26
|
+
stat = statSync(localDir);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
error(`Cannot read ${localDir}`);
|
|
30
|
+
process.exit(EXIT_USER_ERROR);
|
|
31
|
+
}
|
|
32
|
+
const files = {};
|
|
33
|
+
if (stat.isFile()) {
|
|
34
|
+
const name = localDir.split("/").pop();
|
|
35
|
+
const remotePath = posix.join(targetDir, name);
|
|
36
|
+
files[remotePath] = readFileSync(localDir, "utf-8");
|
|
37
|
+
}
|
|
38
|
+
else if (stat.isDirectory()) {
|
|
39
|
+
for (const localPath of walkDir(localDir)) {
|
|
40
|
+
const rel = relative(localDir, localPath);
|
|
41
|
+
const remotePath = posix.join(targetDir, ...rel.split("/"));
|
|
42
|
+
files[remotePath] = readFileSync(localPath, "utf-8");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!Object.keys(files).length) {
|
|
46
|
+
error("No files found");
|
|
47
|
+
process.exit(EXIT_USER_ERROR);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
await stagePost("/api/stage/files", { files }, sessionId);
|
|
51
|
+
let version;
|
|
52
|
+
if (options.render !== false) {
|
|
53
|
+
const entry = options.entry || `${targetDir}/App.tsx`;
|
|
54
|
+
const renderResult = await stagePost("/api/stage/render", { entry }, sessionId);
|
|
55
|
+
version = renderResult.version;
|
|
56
|
+
}
|
|
57
|
+
const paths = Object.keys(files);
|
|
58
|
+
output(options, {
|
|
59
|
+
json: () => ({
|
|
60
|
+
success: true,
|
|
61
|
+
files: paths,
|
|
62
|
+
count: paths.length,
|
|
63
|
+
version,
|
|
64
|
+
session: sessionId,
|
|
65
|
+
}),
|
|
66
|
+
quiet: () => { },
|
|
67
|
+
human: () => {
|
|
68
|
+
success(`Pushed ${paths.length} file${paths.length === 1 ? "" : "s"} to ${targetDir}`);
|
|
69
|
+
for (const p of paths) {
|
|
70
|
+
bullet(dim(p));
|
|
71
|
+
}
|
|
72
|
+
if (version !== undefined) {
|
|
73
|
+
success(`Rendered ${dim(`(v${version})`)}`);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
error(e.message);
|
|
80
|
+
process.exit(EXIT_ERROR);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { stageGet } from "../client.js";
|
|
2
|
+
import { error, output } from "../utils/output.js";
|
|
3
|
+
import { EXIT_ERROR, EXIT_NOT_FOUND } from "../utils/exit-codes.js";
|
|
4
|
+
export async function read(remotePath, options) {
|
|
5
|
+
const sessionId = options.session;
|
|
6
|
+
try {
|
|
7
|
+
const result = await stageGet(`/api/stage/files?path=${encodeURIComponent(remotePath)}`, sessionId);
|
|
8
|
+
if (result.error) {
|
|
9
|
+
error(result.error);
|
|
10
|
+
process.exit(EXIT_NOT_FOUND);
|
|
11
|
+
}
|
|
12
|
+
output(options, {
|
|
13
|
+
json: () => ({ path: remotePath, content: result.content, session: sessionId }),
|
|
14
|
+
quiet: () => process.stdout.write(result.content),
|
|
15
|
+
human: () => process.stdout.write(result.content),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
error(e.message);
|
|
20
|
+
process.exit(EXIT_ERROR);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stagePost } from "../client.js";
|
|
2
|
+
import { error, output, success, dim } from "../utils/output.js";
|
|
3
|
+
import { EXIT_ERROR } from "../utils/exit-codes.js";
|
|
4
|
+
export async function render(entry, options) {
|
|
5
|
+
const sessionId = options.session;
|
|
6
|
+
const entryPoint = entry || "/app/App.tsx";
|
|
7
|
+
try {
|
|
8
|
+
const result = await stagePost("/api/stage/render", { entry: entryPoint }, sessionId);
|
|
9
|
+
output(options, {
|
|
10
|
+
json: () => ({
|
|
11
|
+
success: true,
|
|
12
|
+
entry: entryPoint,
|
|
13
|
+
version: result.version,
|
|
14
|
+
session: sessionId,
|
|
15
|
+
}),
|
|
16
|
+
quiet: () => { },
|
|
17
|
+
human: () => success(`Rendered ${entryPoint} ${dim(`(v${result.version})`)}`),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
error(e.message);
|
|
22
|
+
process.exit(EXIT_ERROR);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { stagePost } from "../client.js";
|
|
3
|
+
import { error, output, success } from "../utils/output.js";
|
|
4
|
+
import { EXIT_ERROR, EXIT_USER_ERROR } from "../utils/exit-codes.js";
|
|
5
|
+
export async function write(remotePath, localPath, options) {
|
|
6
|
+
const sessionId = options.session;
|
|
7
|
+
let content;
|
|
8
|
+
if (localPath === "-" || (!localPath && !process.stdin.isTTY)) {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
for await (const chunk of process.stdin) {
|
|
11
|
+
chunks.push(chunk);
|
|
12
|
+
}
|
|
13
|
+
content = Buffer.concat(chunks).toString("utf-8");
|
|
14
|
+
}
|
|
15
|
+
else if (localPath) {
|
|
16
|
+
try {
|
|
17
|
+
content = readFileSync(localPath, "utf-8");
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
error(`Cannot read ${localPath}: ${e.message}`);
|
|
21
|
+
process.exit(EXIT_USER_ERROR);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
error("Provide a local file path or pipe content via stdin");
|
|
26
|
+
process.exit(EXIT_USER_ERROR);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await stagePost("/api/stage/files", { files: { [remotePath]: content } }, sessionId);
|
|
30
|
+
output(options, {
|
|
31
|
+
json: () => ({ success: true, path: remotePath, bytes: content.length, session: sessionId }),
|
|
32
|
+
quiet: () => { },
|
|
33
|
+
human: () => success(`${remotePath} (${content.length} bytes)`),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
error(e.message);
|
|
38
|
+
process.exit(EXIT_ERROR);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { setBaseUrl } from "./client.js";
|
|
5
|
+
import { newSession } from "./commands/new.js";
|
|
6
|
+
import { write } from "./commands/write.js";
|
|
7
|
+
import { read } from "./commands/read.js";
|
|
8
|
+
import { exec } from "./commands/exec.js";
|
|
9
|
+
import { render } from "./commands/render.js";
|
|
10
|
+
import { ls } from "./commands/ls.js";
|
|
11
|
+
import { push } from "./commands/push.js";
|
|
12
|
+
import { onboard } from "./commands/onboard.js";
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const { version } = require("../package.json");
|
|
15
|
+
const program = new Command();
|
|
16
|
+
program
|
|
17
|
+
.name("stage")
|
|
18
|
+
.description("CLI client for Stage — a sandboxed React runtime for AI agents")
|
|
19
|
+
.version(`stage ${version}`, "-v, --version")
|
|
20
|
+
.option("--json", "Output as JSON")
|
|
21
|
+
.option("-q, --quiet", "Suppress output")
|
|
22
|
+
.option("-u, --url <url>", "Stage server URL (default: $STAGE_URL or http://localhost:3000)");
|
|
23
|
+
program
|
|
24
|
+
.command("new")
|
|
25
|
+
.description("Create a new session")
|
|
26
|
+
.action(async (_opts, cmd) => {
|
|
27
|
+
const root = cmd.optsWithGlobals();
|
|
28
|
+
await newSession({ json: root.json, quiet: root.quiet });
|
|
29
|
+
});
|
|
30
|
+
program
|
|
31
|
+
.command("write <remote-path> [local-file]")
|
|
32
|
+
.description("Write a file to Stage (from local file or stdin)")
|
|
33
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
34
|
+
.action(async (remotePath, localFile, opts, cmd) => {
|
|
35
|
+
const root = cmd.optsWithGlobals();
|
|
36
|
+
await write(remotePath, localFile, { json: root.json, quiet: root.quiet, session: opts.session });
|
|
37
|
+
});
|
|
38
|
+
program
|
|
39
|
+
.command("read <remote-path>")
|
|
40
|
+
.description("Read a file from Stage")
|
|
41
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
42
|
+
.action(async (remotePath, opts, cmd) => {
|
|
43
|
+
const root = cmd.optsWithGlobals();
|
|
44
|
+
await read(remotePath, { json: root.json, quiet: root.quiet, session: opts.session });
|
|
45
|
+
});
|
|
46
|
+
program
|
|
47
|
+
.command("exec <command>")
|
|
48
|
+
.description("Run a bash command in Stage's virtual FS")
|
|
49
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
50
|
+
.action(async (command, opts, cmd) => {
|
|
51
|
+
const root = cmd.optsWithGlobals();
|
|
52
|
+
await exec(command, { json: root.json, quiet: root.quiet, session: opts.session });
|
|
53
|
+
});
|
|
54
|
+
program
|
|
55
|
+
.command("render [entry]")
|
|
56
|
+
.description("Trigger Stage to render a component (default: /app/App.tsx)")
|
|
57
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
58
|
+
.action(async (entry, opts, cmd) => {
|
|
59
|
+
const root = cmd.optsWithGlobals();
|
|
60
|
+
await render(entry, { json: root.json, quiet: root.quiet, session: opts.session });
|
|
61
|
+
});
|
|
62
|
+
program
|
|
63
|
+
.command("ls [path]")
|
|
64
|
+
.description("List files in Stage's virtual FS")
|
|
65
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
66
|
+
.action(async (path, opts, cmd) => {
|
|
67
|
+
const root = cmd.optsWithGlobals();
|
|
68
|
+
await ls(path, { json: root.json, quiet: root.quiet, session: opts.session });
|
|
69
|
+
});
|
|
70
|
+
program
|
|
71
|
+
.command("push <local-dir> [remote-dir]")
|
|
72
|
+
.description("Push a local directory to Stage and render")
|
|
73
|
+
.requiredOption("-s, --session <id>", "Session ID")
|
|
74
|
+
.option("-e, --entry <path>", "Entry point to render")
|
|
75
|
+
.option("--no-render", "Skip auto-render after push")
|
|
76
|
+
.action(async (localDir, remoteDir, opts, cmd) => {
|
|
77
|
+
const root = cmd.optsWithGlobals();
|
|
78
|
+
await push(localDir, remoteDir, {
|
|
79
|
+
json: root.json,
|
|
80
|
+
quiet: root.quiet,
|
|
81
|
+
session: opts.session,
|
|
82
|
+
entry: opts.entry,
|
|
83
|
+
render: opts.render,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
program
|
|
87
|
+
.command("onboard")
|
|
88
|
+
.description("Add stage instructions to CLAUDE.md or AGENTS.md")
|
|
89
|
+
.action(async (_opts, cmd) => {
|
|
90
|
+
const root = cmd.optsWithGlobals();
|
|
91
|
+
await onboard([], { json: root.json, quiet: root.quiet });
|
|
92
|
+
});
|
|
93
|
+
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
94
|
+
const root = actionCommand.optsWithGlobals();
|
|
95
|
+
if (root.url)
|
|
96
|
+
setBaseUrl(root.url);
|
|
97
|
+
});
|
|
98
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
99
|
+
console.error("Fatal error:", err.message);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface OutputOptions {
|
|
2
|
+
json?: boolean;
|
|
3
|
+
quiet?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const success: (msg: string) => void;
|
|
6
|
+
export declare const info: (msg: string) => void;
|
|
7
|
+
export declare const warn: (msg: string) => void;
|
|
8
|
+
export declare const error: (msg: string) => void;
|
|
9
|
+
export declare const bold: (s: string) => string;
|
|
10
|
+
export declare const dim: (s: string) => string;
|
|
11
|
+
export declare const cmd: (s: string) => string;
|
|
12
|
+
export declare const bullet: (msg: string) => void;
|
|
13
|
+
export declare const bulletDim: (msg: string) => void;
|
|
14
|
+
export declare const hint: (msg: string) => void;
|
|
15
|
+
export declare const nextStep: (command: string) => void;
|
|
16
|
+
export declare const header: (title: string) => void;
|
|
17
|
+
export declare function jsonOutput(data: object): void;
|
|
18
|
+
export declare function output(options: OutputOptions, handlers: {
|
|
19
|
+
json?: () => object;
|
|
20
|
+
quiet?: () => void;
|
|
21
|
+
human: () => void;
|
|
22
|
+
}): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export const success = (msg) => console.log(chalk.green("✓"), msg);
|
|
3
|
+
export const info = (msg) => console.log(chalk.blue("ℹ"), msg);
|
|
4
|
+
export const warn = (msg) => console.log(chalk.yellow("⚠"), msg);
|
|
5
|
+
export const error = (msg) => console.error(chalk.red("✗"), msg);
|
|
6
|
+
export const bold = (s) => chalk.bold(s);
|
|
7
|
+
export const dim = (s) => chalk.dim(s);
|
|
8
|
+
export const cmd = (s) => chalk.cyan(s);
|
|
9
|
+
export const bullet = (msg) => console.log(chalk.green("●"), msg);
|
|
10
|
+
export const bulletDim = (msg) => console.log(chalk.dim("●"), msg);
|
|
11
|
+
export const hint = (msg) => console.log(chalk.dim(` ${msg}`));
|
|
12
|
+
export const nextStep = (command) => console.log(` ${cmd(command)}`);
|
|
13
|
+
export const header = (title) => {
|
|
14
|
+
console.log();
|
|
15
|
+
console.log(chalk.bold(title));
|
|
16
|
+
console.log();
|
|
17
|
+
};
|
|
18
|
+
export function jsonOutput(data) {
|
|
19
|
+
console.log(JSON.stringify(data, null, 2));
|
|
20
|
+
}
|
|
21
|
+
export function output(options, handlers) {
|
|
22
|
+
if (options.json && handlers.json) {
|
|
23
|
+
jsonOutput(handlers.json());
|
|
24
|
+
}
|
|
25
|
+
else if (options.quiet && handlers.quiet) {
|
|
26
|
+
handlers.quiet();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
handlers.human();
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stage-ai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI client for Stage — a sandboxed React runtime for AI-generated applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"stage": "./dist/main.js"
|
|
9
|
+
},
|
|
10
|
+
"files": ["dist"],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"dev": "bun run src/main.ts",
|
|
15
|
+
"build:bun": "bun build --compile src/main.ts --outfile stage",
|
|
16
|
+
"build:bun-linux": "bun build --compile --target=bun-linux-x64 src/main.ts --outfile stage-linux-x64",
|
|
17
|
+
"build:bun-mac-arm": "bun build --compile --target=bun-darwin-arm64 src/main.ts --outfile stage-darwin-arm64",
|
|
18
|
+
"build:bun-mac-x64": "bun build --compile --target=bun-darwin-x64 src/main.ts --outfile stage-darwin-x64",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"format": "bunx biome format --write src/",
|
|
21
|
+
"lint": "bunx biome lint src/",
|
|
22
|
+
"check": "bunx biome check src/"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/the-shift-dev/stage-cli.git"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/the-shift-dev/stage-cli#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/the-shift-dev/stage-cli/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": ["ai", "agent", "sandbox", "react", "runtime", "cli", "stage"],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@biomejs/biome": "^2.3.14",
|
|
36
|
+
"typescript": "^5.8.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"chalk": "^5.6.2",
|
|
40
|
+
"commander": "^14.0.3"
|
|
41
|
+
}
|
|
42
|
+
}
|