prismalens 0.5.6 → 0.5.8

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
@@ -1,92 +1,52 @@
1
1
  # prismalens
2
2
 
3
- PrismaLens is an incident investigator that runs as an app on your machine. When an alert arrives, the
4
- coding agent you already use reads a snapshot of the service's code, under a
5
- permission level you pick, and writes an ordered-evidence report: hypotheses
6
- ranked by the evidence behind them, with no numeric confidence scores. The run,
7
- the evidence and the cause stay on the incident. The agent runs as your user;
8
- PrismaLens adds no sandbox. This package is the `pl` command: it starts the
9
- app, checks a machine, pairs devices and manages a background service.
3
+ PrismaLens is an open-source app that runs the coding agents you already use,
4
+ such as Claude Code, Codex, OpenCode and Gemini CLI, on your machine, in
5
+ threads that each work in their own git worktree. This package is the `pl`
6
+ command: it starts the app, checks a machine, pairs devices, upgrades and
7
+ manages a background service.
10
8
 
11
- ## Install
12
-
13
- PrismaLens is alpha and changes often, so read the
14
- [release notes](https://github.com/prismalens/prismalens/releases) before upgrading.
9
+ PrismaLens is alpha. Read the
10
+ [release notes](https://github.com/prismalens/prismalens/releases) before
11
+ upgrading.
15
12
 
16
- ### npm
13
+ ## Install
17
14
 
18
- Needs Node.js 24 or later. The package has no dependencies: on first run `pl`
19
- downloads this version's build for your platform from the
20
- [GitHub release](https://github.com/prismalens/prismalens/releases), checks it
21
- against the release's `SHA256SUMS` and keeps it. Behind a proxy or offline, see
15
+ Needs Node.js. Other ways, without Node, are on
22
16
  [Install](https://docs.prismalens.io/install/).
23
17
 
24
18
  ```bash
25
19
  npm install -g prismalens
26
20
  ```
27
21
 
28
- To try it once without installing, run `npx prismalens@latest up`. npm carries
29
- stable releases; `pl upgrade --channel nightly` switches an install to the
30
- newest nightly build and `pl upgrade --channel stable` switches it back.
31
-
32
- ### macOS and Linux, without Node
33
-
34
- ```bash
35
- curl -fsSL https://prismalens.io/install.sh | sh
36
- ```
37
-
38
- ### Windows, without Node (preview)
39
-
40
- ```powershell
41
- irm https://prismalens.io/install.ps1 | iex
42
- ```
43
-
44
- Both installers bring their own Node, check the download against the
45
- release's `SHA256SUMS`, and put `pl` on your PATH.
46
-
47
- ### Homebrew, and Scoop (preview)
48
-
49
- ```bash
50
- brew install prismalens/tap/prismalens
51
- ```
52
-
53
- ```powershell
54
- scoop bucket add prismalens https://github.com/prismalens/scoop-bucket
55
- scoop install prismalens
56
- ```
57
-
58
22
  ## Quick start
59
23
 
60
- Check the machine, then start the app:
61
-
62
24
  ```bash
63
- pl doctor
64
25
  pl up
65
26
  ```
66
27
 
67
- `pl up` serves the dashboard on http://127.0.0.1:6473 and prints a one-time
68
- link that pairs your browser; there is no account. It opens that link for you,
69
- except under WSL and wherever no browser can open: open the printed link
70
- yourself there. Investigations need a
71
- coding agent: Settings → Agent in the app lists the ones that can run, and
72
- Add agent sets one up. `pl doctor` checks PrismaLens's own setup, not agents.
28
+ `pl up` serves the app on http://127.0.0.1:6473 and opens a one-time link that
29
+ signs your browser in; there is no account. Set up an agent in
30
+ **Settings → Agents**, then start a thread. If it won't start, run `pl doctor`.
73
31
 
74
32
  ## Commands
75
33
 
34
+ `pl <command> --help` lists each command's options.
35
+
76
36
  | Command | Description |
77
37
  | --- | --- |
78
- | `up` | Run PrismaLens as a single process serving the API and web dashboard (default port 6473); `--tailscale-serve` also publishes it on your tailnet over HTTPS. |
79
- | `doctor` | Preflight-check PrismaLens's own setup: Node, the workspace, Git, the webhook URL and port; coding agents are set up in Settings → Agent. |
80
- | `pair` | Print a one-time link that pairs another device with this instance, with `--tailscale` on its tailnet HTTPS address, or with `--operator` this machine's own browser. |
81
- | `reset` | Delete the workspace — database, secrets and logs — after naming the path and asking. |
82
- | `upgrade` | Upgrade the way PrismaLens was installed: npm, the installer, Homebrew or Scoop. A background service tries the new version first and goes back to the old one and its database if it fails. |
83
- | `service` | Run PrismaLens in the background for this user (`install`, `status`, `restart`, `uninstall`); Linux and macOS. `install --tailscale-serve` publishes it on your tailnet over HTTPS on every start. |
38
+ | `up` | Run PrismaLens as a single process: the API and the app on one port. |
39
+ | `doctor` | Check the machine `pl up` will run on. |
40
+ | `pair` | Print a one-time link that pairs another device. |
41
+ | `reset` | Delete the workspace: database, secrets and logs. |
42
+ | `upgrade` | Upgrade PrismaLens the same way it was installed: npm, the installer, Homebrew or Scoop. |
43
+ | `service` | Run PrismaLens in the background for this user (`install`, `status`, `restart`, `uninstall`); Linux and macOS. |
84
44
 
85
45
  ## Documentation
86
46
 
87
- Complete documentation, guides, and configuration references are available at https://docs.prismalens.io.
47
+ https://docs.prismalens.io
88
48
 
89
49
  ## License
90
50
 
91
51
  Apache-2.0. The package also bundles the agent adapters, including the Claude
92
- Agent SDK under Anthropic's own terms; `NOTICE` lists them and their licences.
52
+ Agent SDK under Anthropic's own terms; `NOTICE` lists them and their licenses.
@@ -27,6 +27,12 @@ export const TARGETS = [
27
27
  const STOP_MESSAGE = "prismalens:stop";
28
28
  export const DEFAULT_BASE =
29
29
  "https://github.com/prismalens/prismalens/releases/download";
30
+ /** Tried first; it keeps only the newest releases, so GitHub is the fallback (#1096). */
31
+ export const MIRROR_BASE = "https://downloads.prismalens.io";
32
+ export const DEFAULT_BASES = [MIRROR_BASE, DEFAULT_BASE];
33
+ /** A base with a successor is dropped after this long without a byte, and may use this share of the budget. */
34
+ const MIRROR_STALL_MS = 30_000;
35
+ const MIRROR_BUDGET_SHARE = 0.6;
30
36
  const HOUR = 3_600_000;
31
37
 
32
38
  export class LauncherError extends Error {}
@@ -67,10 +73,10 @@ export function cacheRoot(env = process.env, platform = process.platform) {
67
73
  // --- the release server ------------------------------------------------------------------
68
74
 
69
75
  /** https: or file: only; credentials leave the URL for an Authorization header. */
70
- export function parseBase(raw) {
76
+ export function parseBase(raw, fallback = DEFAULT_BASE) {
71
77
  let url;
72
78
  try {
73
- url = new URL(raw || DEFAULT_BASE);
79
+ url = new URL(raw || fallback);
74
80
  } catch {
75
81
  throw new LauncherError(
76
82
  "PRISMALENS_RELEASE_BASE_URL is not a valid URL (its value is not shown: it may hold a password).",
@@ -125,11 +131,24 @@ async function fetchOnce(url, net) {
125
131
  const headers = {};
126
132
  if (net.auth && current.origin === net.origin)
127
133
  headers.authorization = net.auth;
128
- const res = await fetch(current, {
129
- headers,
130
- redirect: "manual",
131
- signal: AbortSignal.timeout(Math.max(1, net.deadline - Date.now())),
132
- });
134
+ // A server that never answers is dropped after stallMs, not after the shared deadline.
135
+ const silent = new AbortController();
136
+ const timer = net.stallMs
137
+ ? setTimeout(() => silent.abort(), net.stallMs)
138
+ : null;
139
+ let res;
140
+ try {
141
+ res = await fetch(current, {
142
+ headers,
143
+ redirect: "manual",
144
+ signal: AbortSignal.any([
145
+ AbortSignal.timeout(Math.max(1, net.deadline - Date.now())),
146
+ silent.signal,
147
+ ]),
148
+ });
149
+ } finally {
150
+ clearTimeout(timer);
151
+ }
133
152
  if (res.status >= 300 && res.status < 400 && res.headers.get("location")) {
134
153
  await res.body?.cancel();
135
154
  current = new URL(res.headers.get("location"), current);
@@ -141,6 +160,7 @@ async function fetchOnce(url, net) {
141
160
  }
142
161
 
143
162
  export async function get(url, net) {
163
+ const attempts = net.attempts ?? 6;
144
164
  if (url.startsWith("file:")) {
145
165
  const file = fileURLToPath(url);
146
166
  if (!fs.existsSync(file))
@@ -158,7 +178,7 @@ export async function get(url, net) {
158
178
  await res.body?.cancel();
159
179
  if (res.status === 404)
160
180
  throw new NotFound(`${redact(url, net.secrets)} does not exist`);
161
- if (!transient(res.status) || attempt === 6)
181
+ if (!transient(res.status) || attempt >= attempts)
162
182
  throw new LauncherError(
163
183
  `GET ${redact(url, net.secrets)} returned HTTP ${res.status}`,
164
184
  );
@@ -171,7 +191,7 @@ export async function get(url, net) {
171
191
  } catch (error) {
172
192
  if (error instanceof LauncherError) throw error;
173
193
  lastError = error;
174
- if (attempt === 6 || Date.now() >= net.deadline)
194
+ if (attempt >= attempts || Date.now() >= net.deadline)
175
195
  throw unreachable(url, error, net);
176
196
  wait = 500 * 2 ** (attempt - 1);
177
197
  }
@@ -192,7 +212,9 @@ function unreachable(url, error, net) {
192
212
  code || (error?.cause?.message ?? error?.message),
193
213
  net.secrets,
194
214
  );
195
- const where = net.isDefault ? "github.com" : redact(net.base, net.secrets);
215
+ const where = net.isDefault
216
+ ? new URL(net.base).host
217
+ : redact(net.base, net.secrets);
196
218
  const tls = /CERT|SELF_SIGNED|UNABLE_TO_(VERIFY|GET_ISSUER)/.test(code)
197
219
  ? " Its certificate is not trusted here: behind a TLS-inspecting proxy, set NODE_EXTRA_CA_CERTS to your organisation's CA file (npm's cafile is used when it is unset)."
198
220
  : "";
@@ -338,19 +360,35 @@ export function makeNet({
338
360
  env = process.env,
339
361
  log = () => {},
340
362
  deadlineMs,
363
+ stallMs = MIRROR_STALL_MS,
364
+ defaultBases = DEFAULT_BASES,
341
365
  } = {}) {
342
- const parsed = parseBase(env.PRISMALENS_RELEASE_BASE_URL);
366
+ const raw = env.PRISMALENS_RELEASE_BASE_URL;
367
+ const parsedAll = raw
368
+ ? [parseBase(raw)]
369
+ : defaultBases.map((b) => parseBase(undefined, b));
370
+ const parsed = parsedAll[0];
343
371
  const ms =
344
372
  deadlineMs ??
345
373
  (Number(env.PRISMALENS_LAUNCHER_TIMEOUT_SECONDS) || 900) * 1000;
346
374
  let applied = null;
347
- return {
348
- ...parsed,
349
- origin: parsed.base.startsWith("https:")
350
- ? new URL(parsed.base).origin
351
- : null,
375
+ const shared = {
376
+ secrets: parsedAll.flatMap((p) => p.secrets),
352
377
  deadline: Date.now() + ms,
353
378
  log,
379
+ };
380
+ // A base that has a successor is tried briefly: its failure moves on to the next one.
381
+ const bases = parsedAll.map((p, i) => ({
382
+ ...shared,
383
+ ...p,
384
+ origin: p.base.startsWith("https:") ? new URL(p.base).origin : null,
385
+ attempts: i < parsedAll.length - 1 ? 2 : 6,
386
+ stallMs: i < parsedAll.length - 1 ? stallMs : 0,
387
+ }));
388
+ return {
389
+ ...bases[0],
390
+ stallMs: 0,
391
+ bases,
354
392
  /** The proxy/CA settings in force, applied once before the first request. */
355
393
  ready() {
356
394
  if (!applied && !parsed.base.startsWith("file:")) {
@@ -728,6 +766,25 @@ export function releaseLock(file, token) {
728
766
  return removeEntry(file, token);
729
767
  }
730
768
 
769
+ /** One body read; a broken or silent stream is a LauncherError, so the next base is tried. */
770
+ async function readChunk(reader, net, label) {
771
+ let timer;
772
+ const silence = new Error();
773
+ const stalled = new Promise((_, reject) => {
774
+ if (net.stallMs) timer = setTimeout(() => reject(silence), net.stallMs);
775
+ });
776
+ try {
777
+ return await Promise.race([reader.read(), stalled]);
778
+ } catch (error) {
779
+ reader.cancel().catch(() => {});
780
+ throw new LauncherError(
781
+ `the download of ${label} ${error === silence ? `stalled for ${net.stallMs} ms` : `broke (${error.message})`}`,
782
+ );
783
+ } finally {
784
+ clearTimeout(timer);
785
+ }
786
+ }
787
+
731
788
  async function download(url, file, net, label) {
732
789
  const res = await get(url, net);
733
790
  const total = Number(res.headers.get("content-length")) || 0;
@@ -736,8 +793,11 @@ async function download(url, file, net, label) {
736
793
  const tty = process.stderr.isTTY;
737
794
  let received = 0;
738
795
  let shown = -1;
796
+ const reader = res.body.getReader();
739
797
  try {
740
- for await (const chunk of res.body) {
798
+ for (;;) {
799
+ const { done, value: chunk } = await readChunk(reader, net, label);
800
+ if (done) break;
741
801
  hash.update(chunk);
742
802
  fs.writeSync(out, chunk);
743
803
  received += chunk.byteLength;
@@ -797,12 +857,25 @@ export async function ensureRuntime(root, want, net) {
797
857
 
798
858
  /**
799
859
  * The digest the archive must have: the one npm's launcher manifest pins for its own stable
800
- * release, else the release's SHA256SUMS line, which must match a digest this copy verified before.
860
+ * release, else the release's SHA256SUMS line from the last base (GitHub, or the one a set
861
+ * PRISMALENS_RELEASE_BASE_URL names), which must match a digest this copy verified before.
862
+ * A mirror's SHA256SUMS is never read: a mirror could alter an archive and its sums together.
801
863
  */
802
- async function expectedDigest(want, net, at, archive) {
864
+ async function expectedDigest(want, trusted, archive) {
803
865
  if (want.pinned)
804
866
  return { hex: want.pinned, source: "the digest npm's launcher pins" };
805
- const sums = await (await get(`${at}/SHA256SUMS`, net)).text();
867
+ const host = new URL(trusted.base).host || "disk";
868
+ const url = `${trusted.base}/${want.tag}/SHA256SUMS`;
869
+ let sums;
870
+ try {
871
+ sums = await (await get(url, trusted)).text();
872
+ } catch (error) {
873
+ if (!(error instanceof LauncherError)) throw error;
874
+ const refused = `${want.tag}'s SHA256SUMS is not on ${host}, the only source of checksums; nothing was installed (${error.message})`;
875
+ throw error instanceof NotFound
876
+ ? new NotFound(refused)
877
+ : new LauncherError(refused);
878
+ }
806
879
  const line = sums
807
880
  .split(/\r?\n/)
808
881
  .map((l) => /^([0-9a-f]{64})\s+\*?(.+)$/i.exec(l.trim()))
@@ -817,21 +890,61 @@ async function expectedDigest(want, net, at, archive) {
817
890
  return { hex, source: "SHA256SUMS" };
818
891
  }
819
892
 
893
+ /**
894
+ * The archive in `file`, hashed and checked against the digest from the last base's SHA256SUMS.
895
+ * The archive may come from any base; when one fails (a missing file, a broken or silent body,
896
+ * a wrong hash) the next is asked. A base with a successor gets part of the budget, so the
897
+ * last one always keeps time. Resolves to the sha256.
898
+ */
899
+ async function fetchVerified(want, net, archive, file) {
900
+ const bases = net.bases ?? [net];
901
+ const hostOf = (b) => new URL(b.base).host || "disk";
902
+ const expected = await expectedDigest(want, bases.at(-1), archive);
903
+ const failures = [];
904
+ for (const [i, b] of bases.entries()) {
905
+ const last = i === bases.length - 1;
906
+ const now = Date.now();
907
+ const from = last
908
+ ? b
909
+ : {
910
+ ...b,
911
+ deadline: now + Math.floor((b.deadline - now) * MIRROR_BUDGET_SHARE),
912
+ };
913
+ try {
914
+ const actual = await download(
915
+ `${b.base}/${want.tag}/${archive}`,
916
+ file,
917
+ from,
918
+ `${want.version} from ${hostOf(b)}`,
919
+ );
920
+ if (actual !== expected.hex)
921
+ throw new LauncherError(
922
+ `checksum mismatch for ${archive} (${expected.source} says ${expected.hex}, the download is ${actual}); nothing was installed`,
923
+ );
924
+ return actual;
925
+ } catch (error) {
926
+ if (!(error instanceof LauncherError) || bases.length === 1) throw error;
927
+ failures.push(error.message);
928
+ if (!last)
929
+ net.log(
930
+ `${error.message.split("\n")[0]}; trying ${hostOf(bases[i + 1])}`,
931
+ );
932
+ }
933
+ }
934
+ throw new LauncherError(
935
+ `could not download ${archive} from any of ${bases.map(hostOf).join(", ")}:\n${failures.join("\n")}`,
936
+ );
937
+ }
938
+
820
939
  async function install(root, want, net) {
821
940
  const { version, target, tag } = want;
822
941
  net.ready();
823
942
  const archive = archiveName(version, target);
824
- const at = `${net.base}/${tag}`;
825
- const expected = await expectedDigest(want, net, at, archive);
826
943
  const staging = path.join(root, `.staging-${randomBytes(6).toString("hex")}`);
827
944
  fs.mkdirSync(staging);
828
945
  try {
829
946
  const file = path.join(staging, archive);
830
- const actual = await download(`${at}/${archive}`, file, net, version);
831
- if (actual !== expected.hex)
832
- throw new LauncherError(
833
- `checksum mismatch for ${archive} (${expected.source} says ${expected.hex}, the download is ${actual}); nothing was installed`,
834
- );
947
+ const actual = await fetchVerified(want, net, archive, file);
835
948
  // Windows' own bsdtar reads zip; a Git-for-Windows tar on PATH cannot.
836
949
  const tar = target.startsWith("win32")
837
950
  ? path.join(
@@ -1070,7 +1183,8 @@ export function help(release, root, target) {
1070
1183
  return `PrismaLens launcher ${release.version}
1071
1184
 
1072
1185
  pl from npm is a launcher. On first run it downloads PrismaLens ${release.version} for
1073
- ${target} from its GitHub release, checks it against the release's SHA256SUMS,
1186
+ ${target} from ${new URL(MIRROR_BASE).host}, or from its GitHub release when that
1187
+ has no copy, checks it against the SHA256SUMS of its GitHub release,
1074
1188
  keeps it in ${root}, and runs it. Later runs start from that copy offline.
1075
1189
 
1076
1190
  npm carries stable releases. Inside the app, pl upgrade --channel nightly moves this
@@ -1085,8 +1199,9 @@ Commands
1085
1199
 
1086
1200
  Environment
1087
1201
  PRISMALENS_RELEASE_BASE_URL Where releases come from, as <base>/v<version>/<file>;
1088
- https: or file: only. Default:
1089
- ${DEFAULT_BASE}
1202
+ https: or file: only. When it is
1203
+ set, only it is used. Default: archives from ${MIRROR_BASE},
1204
+ then ${DEFAULT_BASE}; SHA256SUMS always from the latter.
1090
1205
  https://user:token@host/... sends an Authorization header;
1091
1206
  the credentials are never printed.
1092
1207
  PRISMALENS_LAUNCHER_DIR Where runtimes are kept. Default: ${root}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prismalens",
3
- "version": "0.5.6",
4
- "description": "Self-hosted incident investigation: an alert arrives, the coding agent you already use investigates a snapshot of the service's code, and the run, evidence and cause stay on the incident.",
3
+ "version": "0.5.8",
4
+ "description": "Run the coding agents you already use, such as Claude Code, Codex and OpenCode, in threads and git worktrees on your machine.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "bin": {
@@ -38,16 +38,16 @@
38
38
  "prismalens": {
39
39
  "release": {
40
40
  "channel": "stable",
41
- "tag": "v0.5.6",
42
- "version": "0.5.6",
41
+ "tag": "v0.5.8",
42
+ "version": "0.5.8",
43
43
  "sha256": {
44
- "darwin-arm64": "76919001307784f1ce78d18b20200b6f111f04b50a7d1db0095678a0c7305dc8",
45
- "darwin-x64": "9f07cfcd0e28fe082505e2a0aaaa277f654f226362072c9a32b7764fa974a737",
46
- "linux-arm64": "26069d2b028c6ee45d5714eb0204852fd8c57131ed843777788ecd4fc646f371",
47
- "linux-x64": "bb987bd2f698796581d2702a8f520eb4d65c1ea42958507bbd2c60d311e9c55a",
48
- "win32-x64": "08d39084bf4e6692ca57d46bf4e8ed353b032747c5c40e9b3951867b3f2b6296"
44
+ "darwin-arm64": "780c01155bcc14e5d3cadb17fd47b48f7458cb12af642c496d47bf22c10bafc9",
45
+ "darwin-x64": "ff2daf1873638a6acb2bdbef95d1ef57c586be5bbe365dc0b75f878c52414c75",
46
+ "linux-arm64": "d629a8c1c8c75720b18cb5404c7297755459683cb6b3e6d648109023e8daec4f",
47
+ "linux-x64": "2d69e6406f9b41738c9d6a76751530297e45f6c12a637a31f670dc9f605e92ed",
48
+ "win32-x64": "42050f90a7d9ed3eae278ab38bab7e2c4d20280ad5f47b8e1dde41d3bcd259e3"
49
49
  }
50
50
  }
51
51
  },
52
- "build": "c331126"
52
+ "build": "a193d90"
53
53
  }