@dreamtree-org/harness-device 0.9.2 → 0.9.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/harness-device",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
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
  }
@@ -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
- lc(['bootstrap', domain(), file]);
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
@@ -160,11 +160,14 @@ export async function startPreview(ctx, { app: name, ttlMinutes = 60, healthSeco
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
162
  if (pub) {
163
- const r = await (publish || defaultPublish)(ctx, proxyPort);
164
- savePreview(ctx, { ...getPreview(ctx, id), public: true, publicUrl: r.url || null });
163
+ let r;
164
+ try { r = await (publish || defaultPublish)(ctx, proxyPort); } catch (e) { r = { url: null, error: e.message }; }
165
+ // Public only with a URL: a preview never claims a tunnel it does not have.
166
+ savePreview(ctx, { ...getPreview(ctx, id), public: !!r.url, publicUrl: r.url || null, publicError: r.url ? null : (r.error || 'no public URL') });
165
167
  }
166
- state.event(ctx, `preview ${id} of ${app.name}: app port ${port}, proxy ${proxyPort}, expires ${expiresAt}${pub ? ', public URL opened' : ''}`);
167
- return link(ctx, getPreview(ctx, id));
168
+ const saved = getPreview(ctx, id);
169
+ 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);
168
171
  }
169
172
 
170
173
  /** The links for a preview (a fresh token valid until the preview expires). */
@@ -175,6 +178,7 @@ export function link(ctx, rec) {
175
178
  url: `http://127.0.0.1:${rec.proxyPort}/?${PARAM}=${token}`,
176
179
  ssh_tunnel: `ssh -N -L ${rec.proxyPort}:127.0.0.1:${rec.proxyPort} <user>@<this-machine> (then open the url on your computer)`,
177
180
  ...(rec.publicUrl ? { public_url: `${rec.publicUrl}/?${PARAM}=${token}` } : {}),
181
+ ...(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
182
  };
179
183
  }
180
184
 
@@ -182,7 +186,7 @@ async function defaultPublish(ctx, port) {
182
186
  const device = await import('./device.js');
183
187
  const r = await device.ngrokUp(ctx, { ports: [port] });
184
188
  const t = r.tunnels.find((x) => String(x.addr || '').endsWith(`:${port}`) || x.name === `app${port}`);
185
- return { url: t ? t.url : null };
189
+ return { url: t ? t.url : null, error: t ? null : (r.error || 'the ngrok tunnel did not open') };
186
190
  }
187
191
 
188
192
  async function defaultUnpublish(ctx, stillPublic) {