@dreamtree-org/harness-device 0.9.3 → 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 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",
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/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: `${removal.describePlan(p).replace(/^Remove app \S+\? /, `${a.app} was not removed. `)} Push or archive that work first, or call again with discard_changes=true after the user agrees to lose it.` }] };
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/preview.js CHANGED
@@ -159,15 +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
  let r;
164
165
  try { r = await (publish || defaultPublish)(ctx, proxyPort); } catch (e) { r = { url: null, error: e.message }; }
165
166
  // Public only with a URL: a preview never claims a tunnel it does not have.
167
+ pubLogin = r.url ? r.login || null : null;
166
168
  savePreview(ctx, { ...getPreview(ctx, id), public: !!r.url, publicUrl: r.url || null, publicError: r.url ? null : (r.error || 'no public URL') });
167
169
  }
168
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.' } } : {};
169
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}`) : ''}`);
170
- return link(ctx, saved);
174
+ return { ...link(ctx, saved), ...login };
171
175
  }
172
176
 
173
177
  /** The links for a preview (a fresh token valid until the preview expires). */
@@ -186,7 +190,8 @@ async function defaultPublish(ctx, port) {
186
190
  const device = await import('./device.js');
187
191
  const r = await device.ngrokUp(ctx, { ports: [port] });
188
192
  const t = r.tunnels.find((x) => String(x.addr || '').endsWith(`:${port}`) || x.name === `app${port}`);
189
- return { url: t ? t.url : null, error: t ? null : (r.error || 'the ngrok tunnel did not open') };
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') };
190
195
  }
191
196
 
192
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
- export function describePlan(p) {
48
- const lost = [
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(`${describePlan(p).replace(/^Remove app \S+\? /, `${name} was not removed. `)} Push or archive that work first, or remove with force once the user agrees to lose it.`), { code: 'NOT_SAFE', plan: p });
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(() => {});