@dreamtree-org/harness-device 0.9.2 → 0.9.4
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 +1 -1
- package/package.json +1 -1
- package/src/device.js +3 -0
- package/src/mcp/server.js +1 -1
- package/src/platform/darwin.js +7 -1
- package/src/preview.js +14 -5
- package/src/remove.js +12 -3
package/README.md
CHANGED
|
@@ -209,7 +209,7 @@ Repositories this device runs, kept in `APPS_DIR` (default `~/apps`). Unlike pro
|
|
|
209
209
|
| `exec` | One program with an argv and no shell. The program must be on `EXEC_ALLOW` (a default list of dev tools); shells and wrappers such as `bash`, `env`, `sudo` or `xargs` are always refused. Runs in the app folder or a confined sub-folder. `env_refs` injects device secrets by name and redacts them from output. Timeout and output cap (head and tail kept). A durable job: `job_status` with `offset` streams new output, `job_cancel` kills the whole process tree. Never restarted. Linux holds the per-process caps in a systemd scope; on macOS the watchdog covers running jobs. Each run is recorded in `events` (program, folder, outcome, exit code, duration; never env or output) |
|
|
210
210
|
| `app_remove` | Removes a managed app (asks first; CLI `harness-device app rm <app> [--force]`): stops its process and previews, archives its workspaces, deletes its folder and forgets its record, port and code graph. It refuses while the app holds work found nowhere else (uncommitted or untracked files, commits on no remote, workspaces) unless `discard_changes` is set after the user agrees. Session projects and folders outside `APPS_DIR` are never deleted |
|
|
211
211
|
| `workspace_create` / `workspace_list` / `workspace_status` / `workspace_archive` | Per-ticket workspaces of a cloned app. Each is a git worktree under `APPS_DIR/.worktrees/<app>/<ticket>` on branch `ticket/<TICKET>`, created from a pinned revision (`base`, default `origin/<branch>`; the SHA is recorded). It gets its own port (4100–4999, kept across retries) and is registered as the app `<app>--<ticket>`, so every app tool works on it. Creating it again returns the same workspace. Git operations on one repository are serialized by a lock. Archiving stops its process, removes the folder, frees the port and keeps the branch; uncommitted changes make it refuse unless the user agrees to discard them. `REPO_ALLOW` (owner/repo, owner/*) limits which repositories `git_clone` and workspaces accept. Per-workspace databases (`database: true`) answer BLOCKED until the shared development DB provisioner exists; no local database container is started instead |
|
|
212
|
-
| `preview_start` / `preview_list` / `preview_stop` / `preview_screenshot` | Protected previews of an app or workspace. Starts its dev server on its own port if nothing answers there and health-checks it; on failure it returns the app's last output and stops it. A per-preview proxy listens on 127.0.0.1 only and forwards to that one app port. Every request needs a token bound to the preview and its expiry, signed with a device key (`state/preview.key`). The link sets an HttpOnly cookie. The record is checked on each request, so a stopped preview is refused at once, and WebSocket upgrades are checked too. Reach it with the SSH tunnel command it returns. A public ngrok URL is opt-in (`public: true`, user-approved) and still needs the token. `preview_stop` revokes the link, stops the proxy, closes the tunnel and stops the app if the preview started it. Expired previews, and previews whose app or proxy is gone, are ended by `preview_list` and by every watchdog pass (`limits --enforce`). `preview_screenshot` (browser capability) loads it in the device browser and returns a PNG; `save: true` also keeps it in the app's `.dreamtree/evidence/captures/` for ai-builder's `evidence add screenshot` |
|
|
212
|
+
| `preview_start` / `preview_list` / `preview_stop` / `preview_screenshot` | Protected previews of an app or workspace. Starts its dev server on its own port if nothing answers there and health-checks it; on failure it returns the app's last output and stops it. A per-preview proxy listens on 127.0.0.1 only and forwards to that one app port. Every request needs a token bound to the preview and its expiry, signed with a device key (`state/preview.key`). The link sets an HttpOnly cookie. The record is checked on each request, so a stopped preview is refused at once, and WebSocket upgrades are checked too. Reach it with the SSH tunnel command it returns. A public ngrok URL is opt-in (`public: true`, user-approved) and still needs the token; when the tunnel sits behind ngrok's login (app tunnels unless `NGROK_APPS_PUBLIC=1`) that login comes back as `public_login` (never stored). If the tunnel does not open, the preview stays local and returns `public_error`. `preview_stop` revokes the link, stops the proxy, closes the tunnel and stops the app if the preview started it. Expired previews, and previews whose app or proxy is gone, are ended by `preview_list` and by every watchdog pass (`limits --enforce`). `preview_screenshot` (browser capability) loads it in the device browser and returns a PNG; `save: true` also keeps it in the app's `.dreamtree/evidence/captures/` for ai-builder's `evidence add screenshot` |
|
|
213
213
|
| `shell_exec` (`app exec <app> -- <cmd>`) | One command in the app folder: up to 120s inline, otherwise as a job. Through the pool it needs `device:admin` |
|
|
214
214
|
| `job_submit` | A durable job under an `effect_key`: steps, each an argv as in `exec` (same allowlist). The same key always returns the same job and never runs it twice; the same key with another payload is refused (`EFFECT_KEY_CONFLICT`). Finished steps are checkpointed. `retries` (up to 5, exponential backoff from `retry_backoff_seconds`) resume at the failed step. `artifacts` are recorded with size and sha256 |
|
|
215
215
|
| `graph_index` | Builds or updates the app's Graphify code graph (needs the `graphify` capability), as a job. It indexes the git view only: tracked files plus untracked files that aren't ignored. Secrets and key material (`.env*`, `*.pem`, `*.key`, `id_*`, credentials, files named secret), ignored paths and anything outside the repository are never indexed. Pinned to the HEAD it saw; later runs copy only the changed files and use `graphify --update` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamtree-org/harness-device",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Turn a Linux server into a reboot-proof Claude Code harness: Remote Control per project in tmux, a persistent Chromium + Playwright MCP on a virtual display, live viewers (noVNC, ttyd, Playwright UI), self-healing systemd services, plus Docker, Dokploy, ngrok and AI-provider tooling.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Partha Preetham Krishna",
|
package/src/device.js
CHANGED
|
@@ -188,6 +188,9 @@ export async function ngrokUp(ctx, { tunnels = [], ports = [] } = {}) {
|
|
|
188
188
|
tunnels: s.tunnels,
|
|
189
189
|
shared: ngrok.sharedUrls(s.tunnels),
|
|
190
190
|
missing: names.filter((n) => !s.tunnels.some((t) => t.name === n)),
|
|
191
|
+
...(names.some((n) => !s.tunnels.some((t) => t.name === n))
|
|
192
|
+
? { error: `${s.running ? 'ngrok runs but' : 'ngrok did not start, so'} ${names.filter((n) => !s.tunnels.some((t) => t.name === n)).join(', ')} did not open within 30s; see logs svc-ngrok (harness-device logs ngrok). A free ngrok plan allows one URL at a time.` }
|
|
193
|
+
: {}),
|
|
191
194
|
login: guarded.length ? { user: cfg.NGROK_VIEWER_USER, password: cfg.NGROK_VIEWER_PASS, for: guarded } : null,
|
|
192
195
|
};
|
|
193
196
|
}
|
package/src/mcp/server.js
CHANGED
|
@@ -125,7 +125,7 @@ export function buildServer(env = process.env, opts = {}) {
|
|
|
125
125
|
{ app: APP, discard_changes: z.boolean().optional(), ...CONFIRM },
|
|
126
126
|
async (c, a, u) => {
|
|
127
127
|
const p = removal.removalPlan(c, a.app);
|
|
128
|
-
if (!p.safe && !a.discard_changes) return { isError: true, content: [{ type: 'text', text:
|
|
128
|
+
if (!p.safe && !a.discard_changes) return { isError: true, content: [{ type: 'text', text: removal.refusal(p, 'call again with discard_changes=true') }] };
|
|
129
129
|
await u.confirm(removal.describePlan(p));
|
|
130
130
|
return text(await removal.removeApp(c, { name: a.app, force: !!a.discard_changes }));
|
|
131
131
|
});
|
package/src/platform/darwin.js
CHANGED
|
@@ -190,7 +190,11 @@ export function ngrokUp(ctx) {
|
|
|
190
190
|
lc(['bootout', `${domain()}/${l}`]);
|
|
191
191
|
for (let i = 0; i < 25 && loaded(l); i++) sleepMs(200);
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
// `harness-device stop` disables every job (ngrok too) and `start` brings back
|
|
194
|
+
// only the always-on ones, so enable it here or launchd refuses to load it
|
|
195
|
+
// (bootstrap: 5 Input/output error).
|
|
196
|
+
lc(['enable', `${domain()}/${l}`]);
|
|
197
|
+
bootstrap(file, l, { dryRun: false });
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
export function ngrokDown(ctx) {
|
|
@@ -272,6 +276,8 @@ export function stopServices(ctx, { persist = false, dryRun = false } = {}) {
|
|
|
272
276
|
/** Enable and load every harness job again (tmux first, heal last). */
|
|
273
277
|
export function startServices(ctx, { dryRun = false } = {}) {
|
|
274
278
|
const dir = serviceDir(ctx.env);
|
|
279
|
+
// ngrok runs on demand (ngrok_up), so it is not loaded here; but stop disabled it, so enable it again.
|
|
280
|
+
lc(['enable', `${domain()}/${labelOf('harness-ngrok')}`], { dryRun });
|
|
275
281
|
for (const u of [...STOP_ORDER(ctx.units)].reverse()) {
|
|
276
282
|
const l = labelOf(u);
|
|
277
283
|
lc(['enable', `${domain()}/${l}`], { dryRun });
|
package/src/preview.js
CHANGED
|
@@ -159,12 +159,19 @@ export async function startPreview(ctx, { app: name, ttlMinutes = 60, healthSeco
|
|
|
159
159
|
state.addProc(ctx, `preview-${id}`, app.dir, `HARNESS_DEVICE_HOME=${q(ctx.paths.home)} exec ${q(process.execPath)} ${q(path.join(PKG_ROOT, 'bin', 'harness-device.js'))} preview proxy ${id}`);
|
|
160
160
|
if (!(await waitPort(proxyPort, 15))) { await stopPreview(ctx, { id, reason: 'proxy did not start', stopApp: startedApp }); throw new Error(`The preview proxy did not start (logs: proc-preview-${id})`); }
|
|
161
161
|
}
|
|
162
|
+
let pubLogin = null;
|
|
162
163
|
if (pub) {
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
let r;
|
|
165
|
+
try { r = await (publish || defaultPublish)(ctx, proxyPort); } catch (e) { r = { url: null, error: e.message }; }
|
|
166
|
+
// Public only with a URL: a preview never claims a tunnel it does not have.
|
|
167
|
+
pubLogin = r.url ? r.login || null : null;
|
|
168
|
+
savePreview(ctx, { ...getPreview(ctx, id), public: !!r.url, publicUrl: r.url || null, publicError: r.url ? null : (r.error || 'no public URL') });
|
|
165
169
|
}
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
const saved = getPreview(ctx, id);
|
|
171
|
+
// The tunnel's own login (app tunnels sit behind one unless NGROK_APPS_PUBLIC=1) is returned, never stored with the preview.
|
|
172
|
+
const login = pub && saved.public && pubLogin ? { public_login: { ...pubLogin, note: 'The public URL asks for this ngrok login first, then the preview link token applies. Give both to the user.' } } : {};
|
|
173
|
+
state.event(ctx, `preview ${id} of ${app.name}: app port ${port}, proxy ${proxyPort}, expires ${expiresAt}${pub ? (saved.public ? ', public URL opened' : `, public URL FAILED: ${saved.publicError}`) : ''}`);
|
|
174
|
+
return { ...link(ctx, saved), ...login };
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
/** The links for a preview (a fresh token valid until the preview expires). */
|
|
@@ -175,6 +182,7 @@ export function link(ctx, rec) {
|
|
|
175
182
|
url: `http://127.0.0.1:${rec.proxyPort}/?${PARAM}=${token}`,
|
|
176
183
|
ssh_tunnel: `ssh -N -L ${rec.proxyPort}:127.0.0.1:${rec.proxyPort} <user>@<this-machine> (then open the url on your computer)`,
|
|
177
184
|
...(rec.publicUrl ? { public_url: `${rec.publicUrl}/?${PARAM}=${token}` } : {}),
|
|
185
|
+
...(rec.publicError ? { public_error: `No public URL: ${rec.publicError}. The preview works locally (url / ssh_tunnel); preview_stop it and retry public once ngrok is fixed.` } : {}),
|
|
178
186
|
};
|
|
179
187
|
}
|
|
180
188
|
|
|
@@ -182,7 +190,8 @@ async function defaultPublish(ctx, port) {
|
|
|
182
190
|
const device = await import('./device.js');
|
|
183
191
|
const r = await device.ngrokUp(ctx, { ports: [port] });
|
|
184
192
|
const t = r.tunnels.find((x) => String(x.addr || '').endsWith(`:${port}`) || x.name === `app${port}`);
|
|
185
|
-
|
|
193
|
+
const login = t && r.login && r.login.for && r.login.for.includes(t.name) ? { user: r.login.user, password: r.login.password } : null;
|
|
194
|
+
return { url: t ? t.url : null, login, error: t ? null : (r.error || 'the ngrok tunnel did not open') };
|
|
186
195
|
}
|
|
187
196
|
|
|
188
197
|
async function defaultUnpublish(ctx, stillPublic) {
|
package/src/remove.js
CHANGED
|
@@ -44,19 +44,28 @@ export function removalPlan(ctx, name) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** One line for the confirmation question. */
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
function lostItems(p) {
|
|
48
|
+
return [
|
|
49
49
|
p.dirty.length && `${p.dirty.length} uncommitted/untracked file(s) (${p.dirty.slice(0, 5).join(', ')}${p.dirty.length > 5 ? ', …' : ''})`,
|
|
50
50
|
p.unpushed.length && `${p.unpushed.length} commit(s) on no remote (${p.unpushed.slice(0, 3).join('; ')}${p.unpushed.length > 3 ? '; …' : ''})`,
|
|
51
51
|
p.workspaces.length && `workspace(s) ${p.workspaces.join(', ')} and their ticket branches`,
|
|
52
52
|
].filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function describePlan(p) {
|
|
56
|
+
const lost = lostItems(p);
|
|
53
57
|
return `Remove app ${p.name}? Its folder ${p.dir} is deleted${p.running ? ', its process stopped' : ''}${p.previews.length ? `, ${p.previews.length} preview(s) stopped` : ''}, and its record, port and code graph forgotten.${lost.length ? ` LOST for good: ${lost.join('; ')}.` : ' Everything in it is on its remote.'}`;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
/** Why an app with unsaved work was not removed (nothing was changed). */
|
|
61
|
+
export function refusal(p, retry = 'remove with force') {
|
|
62
|
+
return `${p.name} was not removed (nothing was changed): removing it would lose ${lostItems(p).join('; ')}. Push or archive that work first, or ${retry} once the user agrees to lose it.`;
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
export async function removeApp(ctx, { name, force = false }) {
|
|
57
66
|
const p = removalPlan(ctx, name);
|
|
58
67
|
if (!p.safe && !force) {
|
|
59
|
-
throw Object.assign(new Error(
|
|
68
|
+
throw Object.assign(new Error(refusal(p)), { code: 'NOT_SAFE', plan: p });
|
|
60
69
|
}
|
|
61
70
|
const app = getApp(ctx, name);
|
|
62
71
|
for (const id of p.previews) await stopPreview(ctx, { id, reason: 'app removed' }).catch(() => {});
|