deplhoy 0.0.0-stage → 0.3.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 +24 -2
- package/dist/collect.js +81 -0
- package/dist/config.js +48 -0
- package/dist/core.js +180 -0
- package/dist/git.js +21 -0
- package/dist/index.js +195 -0
- package/dist/mcp.js +156 -0
- package/dist/secrets.js +44 -0
- package/dist/setup.js +108 -0
- package/package.json +33 -4
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# deplhoy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Publish the prototypes you build with a coding agent and get a private link for your team, stakeholders and test users. Comments go back to your agent, and the agreed version is handed off to development.
|
|
4
|
+
|
|
5
|
+
deplhoy is in closed beta: request access at [deplhoy.app](https://deplhoy.app).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y deplhoy login # once: confirm in the browser
|
|
9
|
+
npx -y deplhoy setup # once per project: teaches your agent to publish (AGENTS.md, CLAUDE.md, skill)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Add the MCP server to your agent once:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
claude mcp add deplhoy -- npx -y deplhoy mcp # Claude Code
|
|
16
|
+
codex mcp add deplhoy -- npx -y deplhoy mcp # Codex
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then tell your agent "deplhoy this". Or publish a build folder yourself:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx -y deplhoy publish dist --name "My prototype"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run `npx -y deplhoy --help` for every command. Needs Node.js 20 or later.
|
package/dist/collect.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* PUB-3: find the build folder and list the files to upload. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
4
|
+
import { basename, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
export const MAX_VERSION_BYTES = 100 * 1024 * 1024; // PUB-8, same as LIMITS in @deplhoy/shared
|
|
6
|
+
export const BUILD_DIRS = ['dist', 'build', 'out'];
|
|
7
|
+
const IGNORED_DIRS = new Set(['node_modules', '.git', '.deplhoy', '.svn', '.hg', '.vercel', '.netlify']);
|
|
8
|
+
const IGNORED_FILES = new Set(['.DS_Store', 'Thumbs.db', 'desktop.ini']);
|
|
9
|
+
/** Why a name is left out, or null when it is uploaded. */
|
|
10
|
+
export function ignoredReason(name, isDir) {
|
|
11
|
+
if (isDir && IGNORED_DIRS.has(name))
|
|
12
|
+
return name;
|
|
13
|
+
if (name.startsWith('.env'))
|
|
14
|
+
return '.env*';
|
|
15
|
+
if (!isDir && name.endsWith('.map'))
|
|
16
|
+
return 'source maps';
|
|
17
|
+
if (!isDir && IGNORED_FILES.has(name))
|
|
18
|
+
return name;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
/** The folder given, else the first of dist, build, out with an index.html, else the current folder if it has one. */
|
|
22
|
+
export function detectBuildDir(cwd, explicit) {
|
|
23
|
+
if (explicit) {
|
|
24
|
+
const dir = resolve(cwd, explicit);
|
|
25
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory())
|
|
26
|
+
throw new Error(`${explicit} is not a folder.`);
|
|
27
|
+
return { dir, detected: false };
|
|
28
|
+
}
|
|
29
|
+
for (const d of BUILD_DIRS) {
|
|
30
|
+
const dir = join(cwd, d);
|
|
31
|
+
if (existsSync(join(dir, 'index.html')))
|
|
32
|
+
return { dir, detected: true };
|
|
33
|
+
}
|
|
34
|
+
if (existsSync(join(cwd, 'index.html')))
|
|
35
|
+
return { dir: cwd, detected: true };
|
|
36
|
+
throw new Error(`No build found. Build the project first, or pass the folder: deplhoy publish <dir> (looked for ${BUILD_DIRS.join(', ')} with an index.html).`);
|
|
37
|
+
}
|
|
38
|
+
export function collectFiles(dir) {
|
|
39
|
+
const files = [];
|
|
40
|
+
const skipped = new Map();
|
|
41
|
+
const symlinks = [];
|
|
42
|
+
let total = 0;
|
|
43
|
+
const walk = (abs) => {
|
|
44
|
+
for (const name of readdirSync(abs).sort()) {
|
|
45
|
+
const p = join(abs, name);
|
|
46
|
+
const st = lstatSync(p);
|
|
47
|
+
const rel = relative(dir, p).split(sep).join('/');
|
|
48
|
+
if (st.isSymbolicLink()) {
|
|
49
|
+
symlinks.push(rel);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const why = ignoredReason(name, st.isDirectory());
|
|
53
|
+
if (why) {
|
|
54
|
+
skipped.set(why, (skipped.get(why) ?? 0) + 1);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (st.isDirectory())
|
|
58
|
+
walk(p);
|
|
59
|
+
else if (st.isFile()) {
|
|
60
|
+
files.push({ path: rel, abs: p, size: st.size });
|
|
61
|
+
total += st.size;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
walk(dir);
|
|
66
|
+
return { files, total, skipped, symlinks };
|
|
67
|
+
}
|
|
68
|
+
export const sha256File = (abs) => createHash('sha256').update(readFileSync(abs)).digest('hex');
|
|
69
|
+
/** package.json name of the project that owns the build (the build's parent for dist/build/out), else a folder name. */
|
|
70
|
+
export function defaultName(cwd, dir, detected) {
|
|
71
|
+
const isBuildDir = BUILD_DIRS.includes(basename(dir));
|
|
72
|
+
const projectDir = isBuildDir ? resolve(dir, '..') : detected ? cwd : dir;
|
|
73
|
+
try {
|
|
74
|
+
const pkg = JSON.parse(readFileSync(join(projectDir, 'package.json'), 'utf8'));
|
|
75
|
+
if (pkg.name)
|
|
76
|
+
return pkg.name.replace(/^@[^/]+\//, '');
|
|
77
|
+
}
|
|
78
|
+
catch { /* no package.json */ }
|
|
79
|
+
return basename(projectDir);
|
|
80
|
+
}
|
|
81
|
+
export const formatBytes = (n) => (n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${(n / 1024).toFixed(1)} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`);
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* Local state: the CLI token per API (~/.config/deplhoy/config.json, readable only by you)
|
|
2
|
+
and which prototype each build folder publishes to (<project>/.deplhoy/project.json). */
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
export const DEFAULT_API = 'https://deplhoy.app';
|
|
7
|
+
export function configPath(env) {
|
|
8
|
+
const base = env.DEPLHOY_CONFIG_DIR ?? join(env.XDG_CONFIG_HOME ?? join(homedir(), '.config'), 'deplhoy');
|
|
9
|
+
return join(base, 'config.json');
|
|
10
|
+
}
|
|
11
|
+
function readJson(path, fallback) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function readAccount(env, api) {
|
|
20
|
+
const a = readJson(configPath(env), { accounts: {} }).accounts[api];
|
|
21
|
+
return a && new Date(a.expires_at) > new Date() ? a : null;
|
|
22
|
+
}
|
|
23
|
+
export function writeAccount(env, api, account) {
|
|
24
|
+
const path = configPath(env);
|
|
25
|
+
const cfg = readJson(path, { accounts: {} });
|
|
26
|
+
if (account)
|
|
27
|
+
cfg.accounts[api] = account;
|
|
28
|
+
else
|
|
29
|
+
delete cfg.accounts[api];
|
|
30
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
31
|
+
writeFileSync(path, JSON.stringify(cfg, null, 2) + '\n', { mode: 0o600 });
|
|
32
|
+
chmodSync(path, 0o600);
|
|
33
|
+
}
|
|
34
|
+
const projectPath = (cwd) => join(cwd, '.deplhoy', 'project.json');
|
|
35
|
+
export function readProject(cwd, buildKey) {
|
|
36
|
+
return readJson(projectPath(cwd), { prototypes: {} }).prototypes?.[buildKey] ?? null;
|
|
37
|
+
}
|
|
38
|
+
/** Every prototype this project publishes to (one per build folder). */
|
|
39
|
+
export function readProjects(cwd) {
|
|
40
|
+
return Object.values(readJson(projectPath(cwd), { prototypes: {} }).prototypes ?? {});
|
|
41
|
+
}
|
|
42
|
+
export function writeProject(cwd, buildKey, entry) {
|
|
43
|
+
const path = projectPath(cwd);
|
|
44
|
+
const file = existsSync(path) ? readJson(path, { prototypes: {} }) : { prototypes: {} };
|
|
45
|
+
file.prototypes = { ...(file.prototypes ?? {}), [buildKey]: entry };
|
|
46
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
47
|
+
writeFileSync(path, JSON.stringify(file, null, 2) + '\n');
|
|
48
|
+
}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/* What the CLI commands and the MCP tools share: the API client and the publish flow (PUB-3 to PUB-8). */
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { collectFiles, defaultName, detectBuildDir, formatBytes, MAX_VERSION_BYTES, sha256File } from './collect.js';
|
|
5
|
+
import { DEFAULT_API, readAccount, readProject, readProjects, writeProject } from './config.js';
|
|
6
|
+
import { gitInfo } from './git.js';
|
|
7
|
+
import { scanFiles } from './secrets.js';
|
|
8
|
+
export const VERSION = '0.3.1';
|
|
9
|
+
export const BEHAVIOR_MAX_BYTES = 4 * 1024; // same limit as the API
|
|
10
|
+
export class CliError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(message, code = 1) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const apiBase = (ctx) => (ctx.env.DEPLHOY_API_URL ?? DEFAULT_API).replace(/\/$/, '');
|
|
18
|
+
export async function call(ctx, path, init = {}) {
|
|
19
|
+
const headers = new Headers(init.headers);
|
|
20
|
+
if (init.token)
|
|
21
|
+
headers.set('authorization', `Bearer ${init.token}`);
|
|
22
|
+
if (typeof init.body === 'string')
|
|
23
|
+
headers.set('content-type', 'application/json');
|
|
24
|
+
let res;
|
|
25
|
+
try {
|
|
26
|
+
res = await ctx.fetch(`${apiBase(ctx)}${path}`, { ...init, headers });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new CliError(`Cannot reach ${apiBase(ctx)}. Check the network connection${apiBase(ctx).includes('localhost') ? ' and that deplhoy is running (npm run dev)' : ''}. Agents in a sandbox need permission to use the network for this command.`);
|
|
30
|
+
}
|
|
31
|
+
const data = (await res.json().catch(() => ({})));
|
|
32
|
+
if (res.status === 401)
|
|
33
|
+
throw new CliError('The deplhoy session expired or was revoked. Run `deplhoy login` in a terminal.');
|
|
34
|
+
if (!res.ok)
|
|
35
|
+
throw new CliError(data.message ?? `${res.status} ${data.error ?? res.statusText}`);
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
export function requireAccount(ctx) {
|
|
39
|
+
const account = readAccount(ctx.env, apiBase(ctx));
|
|
40
|
+
if (!account)
|
|
41
|
+
throw new CliError('Not signed in to deplhoy. Run `deplhoy login` in a terminal once (it opens the browser), then publish again.');
|
|
42
|
+
return account;
|
|
43
|
+
}
|
|
44
|
+
function readSitemap(ctx, opts, warnings) {
|
|
45
|
+
if (opts.sitemap !== undefined && opts.sitemap !== null)
|
|
46
|
+
return opts.sitemap;
|
|
47
|
+
const file = opts.sitemapFile ? resolve(ctx.cwd, opts.sitemapFile) : join(ctx.cwd, '.deplhoy', 'sitemap.json');
|
|
48
|
+
if (!existsSync(file)) {
|
|
49
|
+
if (opts.sitemapFile)
|
|
50
|
+
warnings.push(`Sitemap file not found: ${opts.sitemapFile}`);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
warnings.push(`Sitemap ignored: ${relative(ctx.cwd, file)} is not valid JSON (${e.message}).`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function readBehavior(ctx, opts, warnings) {
|
|
62
|
+
let text = opts.behavior ?? null;
|
|
63
|
+
if (text === null) {
|
|
64
|
+
const file = opts.behaviorFile ? resolve(ctx.cwd, opts.behaviorFile) : join(ctx.cwd, '.deplhoy', 'behavior.md');
|
|
65
|
+
if (existsSync(file))
|
|
66
|
+
text = readFileSync(file, 'utf8');
|
|
67
|
+
else if (opts.behaviorFile)
|
|
68
|
+
warnings.push(`Behavior file not found: ${opts.behaviorFile}`);
|
|
69
|
+
}
|
|
70
|
+
if (text && Buffer.byteLength(text) > BEHAVIOR_MAX_BYTES) {
|
|
71
|
+
throw new CliError(`The behavior note is ${(Buffer.byteLength(text) / 1024).toFixed(1)} KB. The limit is 4 KB: keep what a reviewer or developer needs to know.`);
|
|
72
|
+
}
|
|
73
|
+
if (!text?.trim())
|
|
74
|
+
warnings.push('No behavior note: add .deplhoy/behavior.md (what the prototype does, its states and assumptions) so reviewers and developers get it.');
|
|
75
|
+
return text?.trim() || null;
|
|
76
|
+
}
|
|
77
|
+
/** Validate, scan for secrets, upload, finalize. `say` gets human progress lines; the result is the same for CLI and MCP. */
|
|
78
|
+
export async function publishBuild(ctx, opts, say = () => { }) {
|
|
79
|
+
const started = Date.now();
|
|
80
|
+
const account = requireAccount(ctx);
|
|
81
|
+
const warnings = [];
|
|
82
|
+
const { dir, detected } = detectBuildDir(ctx.cwd, opts.dir);
|
|
83
|
+
const buildKey = relative(ctx.cwd, dir).split(sep).join('/') || '.';
|
|
84
|
+
const { files, total, skipped, symlinks } = collectFiles(dir);
|
|
85
|
+
if (!files.length)
|
|
86
|
+
throw new CliError(`${buildKey} has no files to publish.`);
|
|
87
|
+
if (!files.some((f) => f.path === 'index.html'))
|
|
88
|
+
throw new CliError(`${buildKey} has no index.html at its root.`);
|
|
89
|
+
if (total > MAX_VERSION_BYTES)
|
|
90
|
+
throw new CliError(`The build is ${formatBytes(total)}. The limit is ${formatBytes(MAX_VERSION_BYTES)} per version.`);
|
|
91
|
+
const findings = scanFiles(files);
|
|
92
|
+
if (findings.length) {
|
|
93
|
+
const lines = findings.slice(0, 20).map((f) => ` ${buildKey === '.' ? '' : buildKey + '/'}${f.path}:${f.line} ${f.kind}`);
|
|
94
|
+
throw new CliError(`Nothing was uploaded: the build contains secret keys.\n${lines.join('\n')}${findings.length > 20 ? `\n …and ${findings.length - 20} more` : ''}\nRemove them from the build (keep secrets on a server, never in browser code) and publish again.`);
|
|
95
|
+
}
|
|
96
|
+
const sitemap = readSitemap(ctx, opts, warnings);
|
|
97
|
+
const behavior = readBehavior(ctx, opts, warnings);
|
|
98
|
+
const saved = readProject(ctx.cwd, buildKey);
|
|
99
|
+
const name = opts.name?.trim() || saved?.name || defaultName(ctx.cwd, dir, detected);
|
|
100
|
+
const prototypeId = saved && saved.name.toLowerCase() === name.toLowerCase() ? saved.id : null;
|
|
101
|
+
const notes = [...skipped].map(([what, n]) => `${what} (${n})`);
|
|
102
|
+
say(`Publishing ${buildKey} as “${name}”: ${files.length} files, ${formatBytes(total)}${notes.length ? ` · left out: ${notes.join(', ')}` : ''}`);
|
|
103
|
+
if (symlinks.length)
|
|
104
|
+
warnings.push(`Skipped ${symlinks.length} symbolic link(s), e.g. ${symlinks[0]}`);
|
|
105
|
+
const manifest = files.map((f) => ({ path: f.path, size: f.size, sha256: sha256File(f.abs) }));
|
|
106
|
+
const start = await call(ctx, '/v1/versions', { method: 'POST', token: account.token, body: JSON.stringify({ name, prototype_id: prototypeId, files: manifest, git: gitInfo(ctx.cwd), sitemap, behavior }) });
|
|
107
|
+
warnings.push(...(start.warnings ?? []));
|
|
108
|
+
const byPath = new Map(files.map((f) => [f.path, f]));
|
|
109
|
+
const queue = [...start.uploads];
|
|
110
|
+
let done = 0;
|
|
111
|
+
const worker = async () => {
|
|
112
|
+
for (let u = queue.shift(); u; u = queue.shift()) {
|
|
113
|
+
const body = readFileSync(byPath.get(u.path).abs);
|
|
114
|
+
await call(ctx, u.upload_url, { method: 'PUT', token: account.token, body, headers: { 'content-type': 'application/octet-stream' } });
|
|
115
|
+
done++;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
await Promise.all(Array.from({ length: 6 }, worker));
|
|
119
|
+
if (done !== start.uploads.length)
|
|
120
|
+
throw new CliError('Some files did not upload. Publish again.');
|
|
121
|
+
const r = await call(ctx, `/v1/versions/${start.version.id}/finalize`, { method: 'POST', token: account.token });
|
|
122
|
+
writeProject(ctx.cwd, buildKey, { id: r.prototype.id, name: r.prototype.name, slug: r.prototype.slug });
|
|
123
|
+
return {
|
|
124
|
+
url: r.url, version: `v${r.version}`, build_url: r.build_url, prototype: r.prototype,
|
|
125
|
+
pages: start.pages ?? 0, connections: start.connections ?? 0, files: files.length, bytes: total,
|
|
126
|
+
seconds: Number(((Date.now() - started) / 1000).toFixed(1)), warnings,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export async function listPrototypes(ctx) {
|
|
130
|
+
const account = requireAccount(ctx);
|
|
131
|
+
return (await call(ctx, '/v1/prototypes', { token: account.token })).prototypes;
|
|
132
|
+
}
|
|
133
|
+
export const orgOf = (ctx) => readAccount(ctx.env, apiBase(ctx))?.org ?? 'your organization';
|
|
134
|
+
/* ---- comments (L4, PUB-9): read the open ones, close one; never move them ---- */
|
|
135
|
+
/** The prototype a command is about: the one named (slug or name), else the only one in .deplhoy/project.json. */
|
|
136
|
+
export async function resolvePrototype(ctx, arg) {
|
|
137
|
+
const all = await listPrototypes(ctx);
|
|
138
|
+
if (arg) {
|
|
139
|
+
const a = arg.trim().toLowerCase();
|
|
140
|
+
const hit = all.find((p) => p.slug === a) ?? all.find((p) => p.name.toLowerCase() === a);
|
|
141
|
+
if (!hit)
|
|
142
|
+
throw new CliError(`No prototype called “${arg}” that you can see. Run \`deplhoy list\`.`);
|
|
143
|
+
return hit;
|
|
144
|
+
}
|
|
145
|
+
const local = readProjects(ctx.cwd);
|
|
146
|
+
const mine = local.map((e) => all.find((p) => p.id === e.id)).filter((p) => !!p);
|
|
147
|
+
const unique = [...new Map(mine.map((p) => [p.id, p])).values()];
|
|
148
|
+
if (unique.length === 1)
|
|
149
|
+
return unique[0];
|
|
150
|
+
if (unique.length > 1)
|
|
151
|
+
throw new CliError(`This project publishes several prototypes (${unique.map((p) => p.slug).join(', ')}). Say which one.`);
|
|
152
|
+
throw new CliError('Which prototype? Pass its name or slug (see `deplhoy list`), or run this in the project that publishes it.');
|
|
153
|
+
}
|
|
154
|
+
const forAgent = (t, live) => ({
|
|
155
|
+
comment: t.number, kind: t.kind, version: `v${t.version}`, pending: t.version !== live, page: t.page, device: t.device, target: t.target,
|
|
156
|
+
instruction: t.instruction ?? null,
|
|
157
|
+
thread: t.comments.map((c) => ({ author: c.via === 'agent' ? `${c.author.email ?? 'someone'} (agent)` : c.author.name ?? c.author.email ?? 'someone', text: c.body, at: c.created_at })),
|
|
158
|
+
});
|
|
159
|
+
export async function getComments(ctx, prototype) {
|
|
160
|
+
const account = requireAccount(ctx);
|
|
161
|
+
const p = await resolvePrototype(ctx, prototype);
|
|
162
|
+
const r = await call(ctx, `/v1/prototypes/${p.slug}/comments?open=1`, { token: account.token });
|
|
163
|
+
return {
|
|
164
|
+
prototype: { slug: p.slug, name: p.name, live_version: `v${r.prototype.live_version}`, url: p.url },
|
|
165
|
+
// only the comments an owner sent to agents; `waiting` more wait for an owner's decision in the app (decision 39)
|
|
166
|
+
comments: r.comments.map((t) => forAgent(t, r.prototype.live_version)),
|
|
167
|
+
waiting_for_owner: r.waiting ?? 0,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export async function resolveComment(ctx, comment, opts = {}) {
|
|
171
|
+
const account = requireAccount(ctx);
|
|
172
|
+
const n = Number(String(comment).replace(/^#/, ''));
|
|
173
|
+
if (!Number.isInteger(n) || n < 1)
|
|
174
|
+
throw new CliError(`“${comment}” is not a comment number. Use the number from get_comments, e.g. 3.`);
|
|
175
|
+
const p = await resolvePrototype(ctx, opts.prototype);
|
|
176
|
+
const r = await call(ctx, `/v1/prototypes/${p.slug}/comments/${n}/resolve`, {
|
|
177
|
+
method: 'POST', token: account.token, body: JSON.stringify({ message: opts.message ?? '' }),
|
|
178
|
+
});
|
|
179
|
+
return { comment: r.thread.number, status: r.thread.status, version: `v${r.thread.version}`, url: `${p.url}?v=${r.thread.version}&c=${n}` };
|
|
180
|
+
}
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* PUB-7: when the project folder is a git repo, record repo, branch, commit and uncommitted changes, as information only. */
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
const git = (cwd, args) => {
|
|
4
|
+
try {
|
|
5
|
+
return execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim() || null;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export function gitInfo(cwd) {
|
|
12
|
+
if (git(cwd, ['rev-parse', '--is-inside-work-tree']) !== 'true')
|
|
13
|
+
return null;
|
|
14
|
+
const remote = git(cwd, ['remote', 'get-url', 'origin']);
|
|
15
|
+
return {
|
|
16
|
+
repo: remote ? remote.replace(/\/\/[^/@]*@/, '//') : null, // never send credentials from a remote URL
|
|
17
|
+
branch: git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']),
|
|
18
|
+
commit: git(cwd, ['rev-parse', 'HEAD']),
|
|
19
|
+
dirty: !!git(cwd, ['status', '--porcelain']),
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* deplhoy CLI. L1: login, logout, publish, list. L2: mcp, setup, --sitemap and --behavior. L4: comments, resolve. */
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { realpathSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { hostname } from 'node:os';
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import { DEFAULT_API, readAccount, writeAccount } from './config.js';
|
|
9
|
+
import { apiBase, call, CliError, getComments, listPrototypes, orgOf, publishBuild, resolveComment, VERSION } from './core.js';
|
|
10
|
+
import { serveMcp } from './mcp.js';
|
|
11
|
+
import { setupProject } from './setup.js';
|
|
12
|
+
const HELP = `deplhoy ${VERSION} · publish prototypes from your agent
|
|
13
|
+
|
|
14
|
+
Usage: deplhoy <command> [options]
|
|
15
|
+
|
|
16
|
+
Commands
|
|
17
|
+
login Sign in from the browser
|
|
18
|
+
--no-browser Only print the link (e.g. over SSH)
|
|
19
|
+
logout Sign out and revoke this computer's token
|
|
20
|
+
publish [dir] Publish a build and get a URL (detects dist, build or out)
|
|
21
|
+
--name <name> Prototype name (default: package.json name or folder name)
|
|
22
|
+
--sitemap <file> Pages and links (default .deplhoy/sitemap.json)
|
|
23
|
+
--behavior <file> Behavior note, markdown, 4 KB max (default .deplhoy/behavior.md)
|
|
24
|
+
--json Print the result as JSON (for agents)
|
|
25
|
+
list Prototypes you can see, with their live version
|
|
26
|
+
setup Teach this project's agents to publish (AGENTS.md, CLAUDE.md, skill)
|
|
27
|
+
mcp Start the MCP server over stdio (tools: publish, list, get_comments, resolve_comment)
|
|
28
|
+
comments [prototype] Open comments: on the live version and pending from earlier ones
|
|
29
|
+
--json Print them as JSON (for agents)
|
|
30
|
+
resolve <number> Close a comment, e.g. deplhoy resolve 3
|
|
31
|
+
--message <text> Say what changed (added as a reply)
|
|
32
|
+
--prototype <name> When the project publishes more than one
|
|
33
|
+
|
|
34
|
+
Options
|
|
35
|
+
-h, --help Show this help
|
|
36
|
+
-v, --version Show the version
|
|
37
|
+
|
|
38
|
+
Environment
|
|
39
|
+
DEPLHOY_API_URL API to talk to (default ${DEFAULT_API})
|
|
40
|
+
`;
|
|
41
|
+
/* ---- login (PUB-2) ---- */
|
|
42
|
+
async function login(ctx, args) {
|
|
43
|
+
const { values } = parseArgs({ args, options: { 'no-browser': { type: 'boolean' } } });
|
|
44
|
+
const d = await call(ctx, '/auth/cli/device', {
|
|
45
|
+
method: 'POST', body: JSON.stringify({ label: `${hostname()} · CLI` }),
|
|
46
|
+
});
|
|
47
|
+
ctx.out(`Confirm this code in your browser: ${d.user_code}\n${d.verification_url}\n`);
|
|
48
|
+
if (!values['no-browser'])
|
|
49
|
+
ctx.openUrl(d.verification_url);
|
|
50
|
+
const deadline = Date.now() + d.expires_in * 1000;
|
|
51
|
+
while (Date.now() < deadline) {
|
|
52
|
+
await ctx.sleep(d.interval * 1000);
|
|
53
|
+
const res = await ctx.fetch(`${apiBase(ctx)}/auth/cli/token`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ device_code: d.device_code }) });
|
|
54
|
+
const body = (await res.json().catch(() => ({})));
|
|
55
|
+
if (res.ok && body.token) {
|
|
56
|
+
writeAccount(ctx.env, apiBase(ctx), { token: body.token, email: body.member.email, org: body.org.name, expires_at: body.expires_at });
|
|
57
|
+
ctx.out(`Signed in as ${body.member.email} (${body.org.name}). The token lasts 90 days; revoke it any time from the web.`);
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
if (body.error === 'expired_token')
|
|
61
|
+
break;
|
|
62
|
+
if (body.error !== 'authorization_pending')
|
|
63
|
+
throw new CliError(`Sign-in failed: ${body.error ?? res.status}`);
|
|
64
|
+
}
|
|
65
|
+
throw new CliError('The code expired. Run deplhoy login again.');
|
|
66
|
+
}
|
|
67
|
+
async function logout(ctx) {
|
|
68
|
+
const account = readAccount(ctx.env, apiBase(ctx));
|
|
69
|
+
if (account)
|
|
70
|
+
await call(ctx, '/v1/cli/logout', { method: 'POST', token: account.token }).catch(() => { });
|
|
71
|
+
writeAccount(ctx.env, apiBase(ctx), null);
|
|
72
|
+
ctx.out('Signed out.');
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
/* ---- publish (PUB-3 to PUB-8) ---- */
|
|
76
|
+
async function publish(ctx, args) {
|
|
77
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { name: { type: 'string' }, sitemap: { type: 'string' }, behavior: { type: 'string' }, json: { type: 'boolean' } } });
|
|
78
|
+
const r = await publishBuild(ctx, { dir: positionals[0], name: values.name, sitemapFile: values.sitemap, behaviorFile: values.behavior }, values.json ? () => { } : ctx.out);
|
|
79
|
+
if (values.json) {
|
|
80
|
+
ctx.out(JSON.stringify(r));
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
const flow = r.pages ? `${r.pages} page${r.pages === 1 ? '' : 's'}, ${r.connections} link${r.connections === 1 ? '' : 's'}` : 'no sitemap';
|
|
84
|
+
ctx.out(`\nPublished ${r.version} in ${r.seconds}s (${flow})\n ${r.url}\n Only people in ${orgOf(ctx)} can open it.`);
|
|
85
|
+
for (const w of r.warnings)
|
|
86
|
+
ctx.out(` ! ${w}`);
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
async function list(ctx) {
|
|
90
|
+
const prototypes = await listPrototypes(ctx);
|
|
91
|
+
if (!prototypes.length) {
|
|
92
|
+
ctx.out('No prototypes yet. Publish one with: deplhoy publish');
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
for (const p of prototypes)
|
|
96
|
+
ctx.out(`${p.name.padEnd(28)} v${String(p.live_version).padEnd(4)} ${p.visibility === 'private' ? 'private ' : ''}${p.url}`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
/* ---- comments and resolve (PUB-9) ---- */
|
|
100
|
+
async function comments(ctx, args) {
|
|
101
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { json: { type: 'boolean' } } });
|
|
102
|
+
const r = await getComments(ctx, positionals[0]);
|
|
103
|
+
if (values.json) {
|
|
104
|
+
ctx.out(JSON.stringify(r));
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
const waiting = r.waiting_for_owner ? `${r.waiting_for_owner} more wait${r.waiting_for_owner === 1 ? 's' : ''} for an owner to decide in the app: ${r.prototype.url}` : '';
|
|
108
|
+
if (!r.comments.length) {
|
|
109
|
+
ctx.out(`No open comments for agents on ${r.prototype.name} (${r.prototype.live_version}).${waiting ? `\n${waiting}` : ''}`);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
ctx.out(`${r.prototype.name} · ${r.prototype.live_version} live · ${r.comments.length} open\n`);
|
|
113
|
+
for (const c of r.comments) {
|
|
114
|
+
ctx.out(`#${c.comment} ${c.kind === 'note' ? 'owner note' : c.pending ? `pending from ${c.version}` : c.version} ${c.target}`);
|
|
115
|
+
for (const m of c.thread)
|
|
116
|
+
ctx.out(` ${m.author}: ${m.text.replace(/\n/g, '\n ')}`);
|
|
117
|
+
if (c.instruction)
|
|
118
|
+
ctx.out(` Owner's instruction: ${c.instruction.replace(/\n/g, '\n ')}`);
|
|
119
|
+
}
|
|
120
|
+
if (waiting)
|
|
121
|
+
ctx.out(`\n${waiting}`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
async function resolve(ctx, args) {
|
|
125
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { message: { type: 'string', short: 'm' }, prototype: { type: 'string' } } });
|
|
126
|
+
if (!positionals[0])
|
|
127
|
+
throw new CliError('Which comment? deplhoy resolve <number>, e.g. deplhoy resolve 3');
|
|
128
|
+
const r = await resolveComment(ctx, positionals[0], { prototype: values.prototype, message: values.message });
|
|
129
|
+
ctx.out(`Closed comment #${r.comment} (${r.version}).\n ${r.url}`);
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
function setup(ctx) {
|
|
133
|
+
const local = ctx.env.DEPLHOY_LOCAL_BIN;
|
|
134
|
+
for (const line of setupProject(ctx.cwd, local ?? 'npx -y deplhoy'))
|
|
135
|
+
ctx.out(line);
|
|
136
|
+
if (!readAccount(ctx.env, apiBase(ctx)))
|
|
137
|
+
ctx.out('\nYou are not signed in yet: run deplhoy login once.');
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
export async function run(argv, partial = {}) {
|
|
141
|
+
const ctx = {
|
|
142
|
+
out: console.log, err: console.error, env: process.env, cwd: process.cwd(), fetch: globalThis.fetch,
|
|
143
|
+
openUrl: openInBrowser, sleep: (ms) => new Promise((r) => setTimeout(r, ms)), ...partial,
|
|
144
|
+
};
|
|
145
|
+
const [cmd, ...rest] = argv;
|
|
146
|
+
try {
|
|
147
|
+
if (!cmd || cmd === '-h' || cmd === '--help' || cmd === 'help') {
|
|
148
|
+
ctx.out(HELP);
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
if (cmd === '-v' || cmd === '--version') {
|
|
152
|
+
ctx.out(VERSION);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
if (cmd === 'login')
|
|
156
|
+
return await login(ctx, rest);
|
|
157
|
+
if (cmd === 'logout')
|
|
158
|
+
return await logout(ctx);
|
|
159
|
+
if (cmd === 'publish')
|
|
160
|
+
return await publish(ctx, rest);
|
|
161
|
+
if (cmd === 'list')
|
|
162
|
+
return await list(ctx);
|
|
163
|
+
if (cmd === 'setup')
|
|
164
|
+
return setup(ctx);
|
|
165
|
+
if (cmd === 'mcp')
|
|
166
|
+
return await serveMcp(ctx);
|
|
167
|
+
if (cmd === 'comments')
|
|
168
|
+
return await comments(ctx, rest);
|
|
169
|
+
if (cmd === 'resolve')
|
|
170
|
+
return await resolve(ctx, rest);
|
|
171
|
+
ctx.err(`Unknown command: ${cmd}\n\n${HELP}`);
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
ctx.err(e instanceof Error ? e.message : String(e));
|
|
176
|
+
return e instanceof CliError ? e.code : 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function openInBrowser(url) {
|
|
180
|
+
const [bin, args] = process.platform === 'darwin' ? ['open', [url]] : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
|
|
181
|
+
try {
|
|
182
|
+
spawn(bin, args, { stdio: 'ignore', detached: true }).on('error', () => { }).unref();
|
|
183
|
+
}
|
|
184
|
+
catch { /* the URL is printed anyway */ }
|
|
185
|
+
}
|
|
186
|
+
/* npx and npm install run the CLI through a symlink (node_modules/.bin/deplhoy): compare real paths */
|
|
187
|
+
const realPath = (p) => { try {
|
|
188
|
+
return realpathSync(p);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return p;
|
|
192
|
+
} };
|
|
193
|
+
const isMain = !!process.argv[1] && realPath(process.argv[1]) === realPath(fileURLToPath(import.meta.url));
|
|
194
|
+
if (isMain)
|
|
195
|
+
run(process.argv.slice(2)).then((code) => { process.exitCode = code; });
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/* `deplhoy mcp`: a local MCP server over stdio (PUB-1, PUB-9 first part). A thin layer over the CLI:
|
|
2
|
+
the same publish flow, the same token (~/.config/deplhoy). JSON-RPC 2.0, one message per line.
|
|
3
|
+
stdout carries protocol messages only; anything for a human goes to stderr.
|
|
4
|
+
Tools: publish, list (L2), get_comments, resolve_comment (L4). Agents close comments; they never move them (PUB-9). */
|
|
5
|
+
import { createInterface } from 'node:readline';
|
|
6
|
+
import { CliError, getComments, listPrototypes, publishBuild, resolveComment, VERSION } from './core.js';
|
|
7
|
+
const INSTRUCTIONS = `deplhoy publishes static prototypes (HTML/CSS/JS builds) and returns a private URL for the team.
|
|
8
|
+
Before calling publish: build the project as static files; write .deplhoy/sitemap.json (entry, pages, links) and .deplhoy/behavior.md (what it does, states, assumptions, at most 4 KB), or pass them as arguments.
|
|
9
|
+
Reply to the person with the url and the version. If publish says the build has secret keys, show the file and line and do not remove anything without asking.
|
|
10
|
+
Review comments: get_comments lists the open ones an owner sent to agents (pinned to an element of a page). When a comment has an instruction from the owner, follow the instruction: it is the owner's decision on that feedback. Change the prototype, publish, then close each comment you addressed with resolve_comment and a short message saying what changed. Leave comments you did not address open, and owner notes alone. If waiting_for_owner is above 0, tell the person that many comments wait for their decision in the app; you cannot see or act on them.`;
|
|
11
|
+
const TOOLS = [
|
|
12
|
+
{
|
|
13
|
+
name: 'publish',
|
|
14
|
+
title: 'Publish a prototype',
|
|
15
|
+
description: 'Publish a static build (a folder with index.html: dist, build or out by default) to deplhoy and get its URL. Every call creates a new immutable version. ' +
|
|
16
|
+
'Send the sitemap and the behavior note so reviewers get the flow and developers the handoff. Needs network access.',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
dir: { type: 'string', description: 'Build folder, relative to the project. Default: dist, build or out with an index.html, else the project folder.' },
|
|
21
|
+
name: { type: 'string', description: 'Prototype name. Default: the name used last time for this folder, else package.json name.' },
|
|
22
|
+
behavior: { type: 'string', description: 'Markdown, at most 4 KB: what the prototype does, its states, data and assumptions. Default: .deplhoy/behavior.md' },
|
|
23
|
+
sitemap: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
description: 'Pages and the links between them. Default: .deplhoy/sitemap.json',
|
|
26
|
+
properties: {
|
|
27
|
+
entry: { type: 'string', description: 'Route of the first page, e.g. "/"' },
|
|
28
|
+
pages: { type: 'array', items: { type: 'object', properties: { route: { type: 'string' }, name: { type: 'string' }, group: { type: 'string' } }, required: ['route', 'name'] } },
|
|
29
|
+
links: { type: 'array', items: { type: 'object', properties: { from: { type: 'string' }, to: { type: 'string' }, label: { type: 'string', description: 'Text of the control that navigates' } }, required: ['from', 'to'] } },
|
|
30
|
+
},
|
|
31
|
+
required: ['pages'],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'list',
|
|
39
|
+
title: 'List prototypes',
|
|
40
|
+
description: 'Prototypes you can see on deplhoy, with their live version, open comments and URL.',
|
|
41
|
+
inputSchema: { type: 'object', properties: {} },
|
|
42
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'get_comments',
|
|
46
|
+
title: 'Get open review comments',
|
|
47
|
+
description: 'Open review comments an owner sent to agents: on the live version, plus pending ones from earlier versions. Each has a number, the element it is pinned to ' +
|
|
48
|
+
'(role, text, page, device), its thread and the owner\'s instruction, if any, which wins over the comment. Owner notes (kind "note") are context for the handoff: never close them. ' +
|
|
49
|
+
'waiting_for_owner counts comments the owner has not decided on yet: you cannot see or close them.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: { prototype: { type: 'string', description: 'Slug or name. Default: the prototype this project publishes to (.deplhoy/project.json).' } },
|
|
53
|
+
},
|
|
54
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'resolve_comment',
|
|
58
|
+
title: 'Close a review comment',
|
|
59
|
+
description: 'Close an open comment once the published prototype addresses it. Say what changed in message. Agents cannot move comments between versions.',
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
comment: { type: 'integer', description: 'The comment number from get_comments.' },
|
|
64
|
+
message: { type: 'string', description: 'What changed, added to the thread as a reply, e.g. "Fixed in v3: the price shows taxes."' },
|
|
65
|
+
prototype: { type: 'string', description: 'Slug or name. Default: the prototype this project publishes to.' },
|
|
66
|
+
},
|
|
67
|
+
required: ['comment'],
|
|
68
|
+
},
|
|
69
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const text = (obj, isError = false) => ({
|
|
73
|
+
content: [{ type: 'text', text: typeof obj === 'string' ? obj : JSON.stringify(obj, null, 2) }],
|
|
74
|
+
...(typeof obj === 'object' && obj && !Array.isArray(obj) ? { structuredContent: obj } : {}),
|
|
75
|
+
...(isError ? { isError: true } : {}),
|
|
76
|
+
});
|
|
77
|
+
async function callTool(ctx, name, args) {
|
|
78
|
+
try {
|
|
79
|
+
if (name === 'publish') {
|
|
80
|
+
const r = await publishBuild(ctx, {
|
|
81
|
+
dir: typeof args.dir === 'string' ? args.dir : undefined,
|
|
82
|
+
name: typeof args.name === 'string' ? args.name : undefined,
|
|
83
|
+
behavior: typeof args.behavior === 'string' ? args.behavior : undefined,
|
|
84
|
+
sitemap: args.sitemap ?? undefined,
|
|
85
|
+
});
|
|
86
|
+
return text({ url: r.url, version: r.version, build_url: r.build_url, pages: r.pages, connections: r.connections, warnings: r.warnings });
|
|
87
|
+
}
|
|
88
|
+
if (name === 'list') {
|
|
89
|
+
const list = await listPrototypes(ctx);
|
|
90
|
+
return text({ prototypes: list.map((p) => ({ id: p.id, title: p.name, slug: p.slug, live_version: `v${p.live_version}`, url: p.url, open_comments: p.open_comments ?? 0 })) });
|
|
91
|
+
}
|
|
92
|
+
const str = (x) => (typeof x === 'string' && x.trim() ? x : undefined);
|
|
93
|
+
if (name === 'get_comments')
|
|
94
|
+
return text(await getComments(ctx, str(args.prototype)));
|
|
95
|
+
if (name === 'resolve_comment') {
|
|
96
|
+
if (args.comment === undefined)
|
|
97
|
+
return text('Pass the comment number from get_comments.', true);
|
|
98
|
+
return text(await resolveComment(ctx, args.comment, { prototype: str(args.prototype), message: str(args.message) }));
|
|
99
|
+
}
|
|
100
|
+
return text(`Unknown tool: ${name}`, true);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
return text(e instanceof CliError || e instanceof Error ? e.message : String(e), true);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Handles one JSON-RPC message; returns the response, or null for notifications. */
|
|
107
|
+
export async function handleMcpMessage(ctx, msg) {
|
|
108
|
+
const reply = (result) => ({ jsonrpc: '2.0', id: msg.id ?? null, result });
|
|
109
|
+
const fail = (code, message) => ({ jsonrpc: '2.0', id: msg.id ?? null, error: { code, message } });
|
|
110
|
+
if (msg.id === undefined)
|
|
111
|
+
return null; // notifications (initialized, cancelled…) need no answer
|
|
112
|
+
switch (msg.method) {
|
|
113
|
+
case 'initialize':
|
|
114
|
+
return reply({
|
|
115
|
+
// speak the client's version: we only use tools, which every version has
|
|
116
|
+
protocolVersion: typeof msg.params?.protocolVersion === 'string' ? msg.params.protocolVersion : '2025-06-18',
|
|
117
|
+
capabilities: { tools: { listChanged: false } },
|
|
118
|
+
serverInfo: { name: 'deplhoy', title: 'deplhoy', version: VERSION },
|
|
119
|
+
instructions: INSTRUCTIONS,
|
|
120
|
+
});
|
|
121
|
+
case 'ping':
|
|
122
|
+
return reply({});
|
|
123
|
+
case 'tools/list':
|
|
124
|
+
return reply({ tools: TOOLS });
|
|
125
|
+
case 'tools/call': {
|
|
126
|
+
const name = String(msg.params?.name ?? '');
|
|
127
|
+
return reply(await callTool(ctx, name, msg.params?.arguments ?? {}));
|
|
128
|
+
}
|
|
129
|
+
case 'resources/list':
|
|
130
|
+
return reply({ resources: [] });
|
|
131
|
+
case 'prompts/list':
|
|
132
|
+
return reply({ prompts: [] });
|
|
133
|
+
default:
|
|
134
|
+
return fail(-32601, `Method not found: ${msg.method}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export function serveMcp(ctx) {
|
|
138
|
+
const send = (m) => process.stdout.write(JSON.stringify(m) + '\n');
|
|
139
|
+
const quietCtx = { ...ctx, out: ctx.err }; // never print to stdout outside the protocol
|
|
140
|
+
const rl = createInterface({ input: process.stdin });
|
|
141
|
+
rl.on('line', (line) => {
|
|
142
|
+
if (!line.trim())
|
|
143
|
+
return;
|
|
144
|
+
let msg;
|
|
145
|
+
try {
|
|
146
|
+
msg = JSON.parse(line);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
handleMcpMessage(quietCtx, msg).then((r) => { if (r)
|
|
153
|
+
send(r); }, (e) => send({ jsonrpc: '2.0', id: msg.id ?? null, error: { code: -32603, message: String(e) } }));
|
|
154
|
+
});
|
|
155
|
+
return new Promise((done) => rl.on('close', () => done(0)));
|
|
156
|
+
}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* PUB-4: block a publish when the build contains secret keys. Says file and line, never prints the secret.
|
|
2
|
+
Only keys that must never reach a browser: publishable keys (Stripe pk_, Firebase/Google AIza…) are fine. */
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
const PATTERNS = [
|
|
5
|
+
['Private key', /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP |ENCRYPTED )?PRIVATE KEY-----/g],
|
|
6
|
+
['AWS access key', /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
|
|
7
|
+
['Stripe secret key', /\b[sr]k_live_[0-9a-zA-Z]{20,}/g],
|
|
8
|
+
['GitHub token', /\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{50,})/g],
|
|
9
|
+
['Slack token', /\bxox[abposr]-[A-Za-z0-9-]{10,}/g],
|
|
10
|
+
['Anthropic API key', /\bsk-ant-[A-Za-z0-9_-]{20,}/g],
|
|
11
|
+
['OpenAI API key', /\bsk-(?:proj-|svcacct-|admin-)?(?!ant-)[A-Za-z0-9_-]{32,}/g],
|
|
12
|
+
['SendGrid API key', /\bSG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}/g],
|
|
13
|
+
['Database URL with a password', /\b(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis|rediss):\/\/[^\s:@/'"`]+:[^\s@/'"`]+@/g],
|
|
14
|
+
];
|
|
15
|
+
const MAX_SCAN_BYTES = 5 * 1024 * 1024;
|
|
16
|
+
export function scanText(path, text) {
|
|
17
|
+
const found = [];
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
for (const [kind, re] of PATTERNS) {
|
|
20
|
+
re.lastIndex = 0;
|
|
21
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
22
|
+
const line = text.slice(0, m.index).split('\n').length;
|
|
23
|
+
const key = `${line}`;
|
|
24
|
+
if (!seen.has(key)) {
|
|
25
|
+
seen.add(key);
|
|
26
|
+
found.push({ path, line, kind });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return found.sort((a, b) => a.line - b.line);
|
|
31
|
+
}
|
|
32
|
+
/** Scans every file that looks like text (no NUL byte in its first 8 KB). */
|
|
33
|
+
export function scanFiles(files) {
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const f of files) {
|
|
36
|
+
if (f.size > MAX_SCAN_BYTES)
|
|
37
|
+
continue;
|
|
38
|
+
const buf = readFileSync(f.abs);
|
|
39
|
+
if (buf.subarray(0, 8192).includes(0))
|
|
40
|
+
continue;
|
|
41
|
+
out.push(...scanText(f.path, buf.toString('utf8')));
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* `deplhoy setup` (PUB-10): teaches the project's agents to publish with deplhoy.
|
|
2
|
+
Writes a block in AGENTS.md (Codex, VS Code and most agents) and makes Claude Code read it, adds a Claude Code skill,
|
|
3
|
+
keeps .deplhoy/project.json out of git, and prints how to register the MCP server in each agent.
|
|
4
|
+
Re-running it updates the block in place (between the deplhoy:start/end markers). */
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
const START = '<!-- deplhoy:start -->';
|
|
8
|
+
const END = '<!-- deplhoy:end -->';
|
|
9
|
+
export const AGENT_INSTRUCTIONS = `${START}
|
|
10
|
+
## Publishing prototypes with deplhoy
|
|
11
|
+
|
|
12
|
+
When the person asks to publish, share or "deplhoy" this prototype:
|
|
13
|
+
|
|
14
|
+
1. **Build it as static files** (\`npm run build\` or the project's equivalent). deplhoy serves HTML, CSS and JS only: no server code, no API routes, no secrets in the build. If the prototype needs a server of its own (its own API, keys for an AI model, server rendering), stop and explain why it cannot be published.
|
|
15
|
+
- Next.js: set \`output: 'export'\` and \`images: { unoptimized: true }\` in next.config. Dynamic routes whose ids only exist in the browser become a query string (\`/cards?id=…\` instead of \`/cards/[id]\`). Make these changes on a branch and say so.
|
|
16
|
+
- Vite, React, Vue, Svelte, plain HTML: build as usual.
|
|
17
|
+
2. **Update \`.deplhoy/sitemap.json\`**: every page a person can reach, and the links between pages with the text of the control that navigates. Group pages by flow if it helps. A page that only shows other data by query string (\`/product?id=…\`) goes once, with one example; list a query variant as its own page only when it is a different state (\`/checkout?price=up\`). deplhoy draws the flow from this file and adds the pages people reach that are missing.
|
|
18
|
+
\`\`\`json
|
|
19
|
+
{
|
|
20
|
+
"entry": "/",
|
|
21
|
+
"pages": [
|
|
22
|
+
{ "route": "/", "name": "Home" },
|
|
23
|
+
{ "route": "/checkout", "name": "Checkout", "group": "Purchase" }
|
|
24
|
+
],
|
|
25
|
+
"links": [{ "from": "/", "to": "/checkout", "label": "Buy now" }]
|
|
26
|
+
}
|
|
27
|
+
\`\`\`
|
|
28
|
+
If the project has design-system components, keep \`data-ds-component="Name"\` (and \`data-ds-variant\`) on their root element: the handoff lists them with their measures and CSS variables.
|
|
29
|
+
3. **Update \`.deplhoy/behavior.md\`** (at most 4 KB): what the prototype does, its states and edge cases, which data is fake, what is out of scope, and open questions. Reviewers and developers read it.
|
|
30
|
+
4. **Publish** with the deplhoy MCP tool \`publish\`, or \`npx deplhoy publish\` in a terminal. Building and publishing need network access: ask for it if you run in a sandbox.
|
|
31
|
+
5. **Reply** with the URL and the version, plus any warnings. If publishing reports secret keys, show the file and line and do not remove anything without asking.
|
|
32
|
+
|
|
33
|
+
Publishing does not change the prototype: do not edit its content or copy to publish it. If you notice a problem, mention it in the reply or under open questions in behavior.md.
|
|
34
|
+
|
|
35
|
+
When the person asks to work on the review comments:
|
|
36
|
+
1. Read them with the MCP tool \`get_comments\` (or \`npx deplhoy comments --json\`). You only get the comments an owner sent to agents. Each one says the element it is pinned to (role, text, page, device), its thread and, when the owner gave one, an \`instruction\`: follow it, it is the owner's decision on that feedback. Comments "pending" from an earlier version may already be fixed: check the code.
|
|
37
|
+
2. Change the prototype, only what the comments ask (mention anything else you notice), then build and publish as above.
|
|
38
|
+
3. Close each comment you addressed with \`resolve_comment\` (or \`npx deplhoy resolve <number> -m "…"\`) and a short message saying what changed. Leave the others open and say why in your reply. Never close owner notes; you cannot move comments between versions. If \`waiting_for_owner\` is above 0, tell the person how many comments wait for their decision in the app.
|
|
39
|
+
|
|
40
|
+
\`.deplhoy/project.json\` remembers which prototype this folder publishes to: keep it out of git.
|
|
41
|
+
${END}`;
|
|
42
|
+
export const SKILL = `---
|
|
43
|
+
name: deplhoy
|
|
44
|
+
description: Publish this prototype to deplhoy and get a private URL for the team, and work on its review comments. Use when the person says "deplhoy this", asks to publish, share or put the prototype online for review, asks for a link to it, or asks to address the comments or feedback on it.
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
# Publish with deplhoy
|
|
48
|
+
|
|
49
|
+
Follow the "Publishing prototypes with deplhoy" section of AGENTS.md in this project. In short:
|
|
50
|
+
|
|
51
|
+
1. Build static files. Stop and explain if the prototype needs a server of its own.
|
|
52
|
+
2. Update \`.deplhoy/sitemap.json\` (entry, pages, links with the text of the control) and \`.deplhoy/behavior.md\` (at most 4 KB).
|
|
53
|
+
3. Call the \`publish\` tool of the deplhoy MCP server (or run \`npx deplhoy publish\`). It needs network access.
|
|
54
|
+
4. Reply with the URL, the version and any warnings.
|
|
55
|
+
|
|
56
|
+
For review comments: \`get_comments\`, change and publish, then \`resolve_comment\` with what changed for each one you addressed.
|
|
57
|
+
`;
|
|
58
|
+
/** Puts the block in a markdown file, replacing an earlier one. Returns what happened. */
|
|
59
|
+
export function upsertBlock(path, block) {
|
|
60
|
+
if (!existsSync(path)) {
|
|
61
|
+
writeFileSync(path, block + '\n');
|
|
62
|
+
return 'created';
|
|
63
|
+
}
|
|
64
|
+
const current = readFileSync(path, 'utf8');
|
|
65
|
+
const a = current.indexOf(START), b = current.indexOf(END);
|
|
66
|
+
if (a !== -1 && b > a) {
|
|
67
|
+
const next = current.slice(0, a) + block + current.slice(b + END.length);
|
|
68
|
+
if (next === current)
|
|
69
|
+
return 'unchanged';
|
|
70
|
+
writeFileSync(path, next);
|
|
71
|
+
return 'updated';
|
|
72
|
+
}
|
|
73
|
+
writeFileSync(path, current.replace(/\s*$/, '\n\n') + block + '\n');
|
|
74
|
+
return 'added';
|
|
75
|
+
}
|
|
76
|
+
function ensureLine(path, line) {
|
|
77
|
+
const current = existsSync(path) ? readFileSync(path, 'utf8') : '';
|
|
78
|
+
if (current.split('\n').some((l) => l.trim() === line))
|
|
79
|
+
return false;
|
|
80
|
+
writeFileSync(path, current.replace(/\s*$/, current ? '\n' : '') + line + '\n');
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
export function setupProject(cwd, mcpCommand) {
|
|
84
|
+
const done = [];
|
|
85
|
+
const agents = join(cwd, 'AGENTS.md');
|
|
86
|
+
done.push(`AGENTS.md: ${upsertBlock(agents, AGENT_INSTRUCTIONS)}`);
|
|
87
|
+
// Claude Code reads CLAUDE.md: import AGENTS.md so there is one copy of the instructions
|
|
88
|
+
const claude = join(cwd, 'CLAUDE.md');
|
|
89
|
+
const claudeText = existsSync(claude) ? readFileSync(claude, 'utf8') : '';
|
|
90
|
+
if (!existsSync(claude)) {
|
|
91
|
+
writeFileSync(claude, '@AGENTS.md\n');
|
|
92
|
+
done.push('CLAUDE.md: created (imports AGENTS.md)');
|
|
93
|
+
}
|
|
94
|
+
else if (/^@AGENTS\.md\s*$/m.test(claudeText))
|
|
95
|
+
done.push('CLAUDE.md: already imports AGENTS.md');
|
|
96
|
+
else
|
|
97
|
+
done.push(`CLAUDE.md: ${upsertBlock(claude, AGENT_INSTRUCTIONS)}`);
|
|
98
|
+
const skill = join(cwd, '.claude', 'skills', 'deplhoy', 'SKILL.md');
|
|
99
|
+
mkdirSync(dirname(skill), { recursive: true });
|
|
100
|
+
const had = existsSync(skill) && readFileSync(skill, 'utf8') === SKILL;
|
|
101
|
+
if (!had)
|
|
102
|
+
writeFileSync(skill, SKILL);
|
|
103
|
+
done.push(`.claude/skills/deplhoy/SKILL.md: ${had ? 'unchanged' : 'written'}`);
|
|
104
|
+
if (ensureLine(join(cwd, '.gitignore'), '.deplhoy/project.json'))
|
|
105
|
+
done.push('.gitignore: added .deplhoy/project.json');
|
|
106
|
+
done.push('', 'Register the MCP server once per agent:', ` Claude Code claude mcp add deplhoy -- ${mcpCommand} mcp`, ` Codex codex mcp add deplhoy -- ${mcpCommand} mcp`, ` VS Code .vscode/mcp.json → { "servers": { "deplhoy": { "type": "stdio", "command": "${mcpCommand.split(' ')[0]}", "args": [${[...mcpCommand.split(' ').slice(1), 'mcp'].map((a) => `"${a}"`).join(', ')}] } } }`, '', 'Then tell your agent: "deplhoy this".');
|
|
107
|
+
return done;
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deplhoy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Publish prototypes from your agent and get a URL. CLI + MCP server.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"prototype",
|
|
7
|
+
"mcp",
|
|
8
|
+
"claude-code",
|
|
9
|
+
"codex",
|
|
10
|
+
"cursor",
|
|
11
|
+
"vibe-coding",
|
|
12
|
+
"deploy"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://deplhoy.app",
|
|
15
|
+
"license": "UNLICENSED",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"bin": {
|
|
18
|
+
"deplhoy": "dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
29
|
+
"start": "tsx src/index.ts",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsx": "^4.19.2"
|
|
34
|
+
}
|
|
35
|
+
}
|