Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(ui,runtime): explain the server access key link and pin review follow-ups

Alan Buscagliafda4434d8fd2
diff --git a/e2e/web.spec.ts b/e2e/web.spec.ts
index 47f9cb8..1f2eafa 100644
--- a/e2e/web.spec.ts
+++ b/e2e/web.spec.ts
@@ -303,6 +303,9 @@ test("explains a rejected access key", async ({ page }) => {
test("asks for the access key when there is none", async ({ page }) => {
await page.goto("/");
await expect(page.getByRole("status")).toContainText("This page needs your access key");
+ await expect(page.getByRole("status")).toContainText(
+ "on a server, open the link with #token=<your access key>",
+ );
});
test("keeps the onboarding banner in its own space, above the first message", async ({ page }) => {
diff --git a/packages/daemon/src/runtime-build.ts b/packages/daemon/src/runtime-build.ts
index d0aa52f..4350abd 100644
--- a/packages/daemon/src/runtime-build.ts
+++ b/packages/daemon/src/runtime-build.ts
@@ -33,6 +33,18 @@ export function lockedDependencies(
return versions;
}
+/**
+ * An engine package's key in the lockfile's `packages:` section: two spaces, an optional quote,
+ * the `@earendil-works/` name, `@`, then the version up to a peer suffix `(`, the quote or the `:`.
+ * For ` '@earendil-works/[email protected]([email protected])':` that is `@earendil-works/pi-ai` and `1.4.0`.
+ */
+const ENGINE_PACKAGE_KEY = /^ {2}'?(?<name>@earendil-works\/[^@'/]+)@(?<version>[^(':]+)/;
+
+function enginePackageKey(line: string): { name: string; version: string } | undefined {
+ const { name, version } = ENGINE_PACKAGE_KEY.exec(line)?.groups ?? {};
+ return name && version ? { name, version } : undefined;
+}
+
/**
* The lockfile's versions of the engine's own packages (`@earendil-works/*`) that the runtime
* does not list directly. The engine asks for them with `^` ranges, so a fresh `npm install`
@@ -46,9 +58,9 @@ export function lockedEnginePackages(
let inPackages = false;
for (const line of lockfile.split("\n")) {
if (/^\S/.test(line)) inPackages = line.trim() === "packages:";
- const match = inPackages ? /^ {2}'?(@earendil-works\/[^@'/]+)@([^(':]+)/.exec(line) : null;
- if (!match?.[1] || !match[2] || match[1] in direct) continue;
- const [, name, version] = match;
+ const entry = inPackages ? enginePackageKey(line) : undefined;
+ if (!entry || entry.name in direct) continue;
+ const { name, version } = entry;
if (versions[name] && versions[name] !== version)
throw new Error(`The lockfile holds two versions of ${name}.`);
versions[name] = version;
diff --git a/packages/daemon/test/rotation.test.ts b/packages/daemon/test/rotation.test.ts
index fd09f2f..d339aee 100644
--- a/packages/daemon/test/rotation.test.ts
+++ b/packages/daemon/test/rotation.test.ts
@@ -270,6 +270,18 @@ describe("handoff session file", () => {
const reopened = SessionManager.open(file).buildSessionContext().messages;
expect(reopened.map((m) => m.role)).toEqual(["custom", "user"]);
});
+
+ // SessionManager.open migrates an older header up to its own version, so the check above
+ // cannot see a stale version; the bytes on disk can.
+ it("writes the installed engine's session version in its header", async () => {
+ const dir = tempDir();
+ const previous = join(dir, "previous.jsonl");
+ writeFileSync(previous, `${JSON.stringify({ type: "session", version: 3, id: "p", cwd: dir })}\n`);
+ const file = await writeHandoffSession(previous, "Summary.");
+ const { CURRENT_SESSION_VERSION } = await import("@earendil-works/pi-coding-agent");
+ const header = JSON.parse(readFileSync(file, "utf8").split("\n")[0] ?? "");
+ expect(header).toMatchObject({ type: "session", version: CURRENT_SESSION_VERSION });
+ });
});
describe("recent history", () => {
diff --git a/packages/daemon/test/runtime-build.test.ts b/packages/daemon/test/runtime-build.test.ts
index 522c6ee..802cad3 100644
--- a/packages/daemon/test/runtime-build.test.ts
+++ b/packages/daemon/test/runtime-build.test.ts
@@ -13,6 +13,7 @@ import {
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { beforeAll, describe, expect, it } from "vitest";
+import { lockedEnginePackages } from "../src/runtime-build.ts";
import { tempDir } from "./helpers.ts";
const PACKAGE = fileURLToPath(new URL("..", import.meta.url));
@@ -78,6 +79,9 @@ describe("build:runtime", () => {
// The engine asks for its siblings with `^` ranges; a fresh install would take newer ones
// that no longer match it (pi-codemode 1.4.0 broke pi-coding-agent 1.0.4).
+ // The manifest is this suite's boundary: proving npm honours `overrides` needs a real
+ // install from the registry, which the packaging step does (scripts/package/stage-runtime.mjs
+ // installs from this manifest, then scripts/package/smoke-runtime.mjs starts the engine).
it("pins the engine's own packages to the lockfile's versions", () => {
const manifest = JSON.parse(readFileSync(join(out, "daemon", "package.json"), "utf8"));
expect(manifest.overrides).toEqual({
@@ -87,6 +91,40 @@ describe("build:runtime", () => {
});
});
+ it("reads the engine packages from a lockfile, without the direct dependencies", () => {
+ const lockfile = [
+ "importers:",
+ " '@earendil-works/[email protected]':",
+ "packages:",
+ " '@earendil-works/[email protected]':",
+ " '@earendil-works/[email protected]':",
+ "snapshots:",
+ " '@earendil-works/[email protected]':",
+ "packages:",
+ " '@earendil-works/[email protected]':",
+ " '@earendil-works/[email protected]([email protected])':",
+ ].join("\n");
+ expect(lockedEnginePackages({ "@earendil-works/pi-coding-agent": "1.4.0" }, lockfile)).toEqual({
+ "@earendil-works/pi-ai": "1.4.0",
+ "@earendil-works/pi-agent-core": "1.4.0",
+ });
+ });
+
+ it("refuses a lockfile holding two versions of one engine package", () => {
+ const lockfile = [
+ "packages:",
+ " '@earendil-works/[email protected]':",
+ " '@earendil-works/[email protected]([email protected])':",
+ ].join("\n");
+ expect(() => lockedEnginePackages({}, lockfile)).toThrow(
+ "The lockfile holds two versions of @earendil-works/pi-codemode.",
+ );
+ // Two versions of a direct dependency are pnpm's business, not an override's.
+ expect(lockedEnginePackages({ "@earendil-works/pi-codemode": "1.4.0" }, lockfile)).toEqual({});
+ });
+
it("runs its self-check from the output with the engine resolved inside it", () => {
symlinkSync(join(PACKAGE, "node_modules"), join(out, "daemon", "node_modules"));
const check = spawnSync(process.execPath, [join(out, "daemon", "cli.mjs"), "--self-check"], {
diff --git a/packages/ui/src/App.tsx b/packages/ui/src/App.tsx
index 5f83c17..3476eb1 100644
--- a/packages/ui/src/App.tsx
+++ b/packages/ui/src/App.tsx
@@ -194,7 +194,7 @@ function Assistant({ surface }: { surface: Surface }) {
<div className="chat chat-web">
<div className="status" role="status">
{unreachable ??
- "This page needs your access key. Open it from the Gentle Dot menu (Open in browser)."}
+ "This page needs your access key. On your computer, open it from the Gentle Dot menu (Open in browser); on a server, open the link with #token=<your access key>."}
</div>
</div>
);
diff --git a/packages/ui/test/settings.test.tsx b/packages/ui/test/settings.test.tsx
index 9aac243..8543ca7 100644
--- a/packages/ui/test/settings.test.tsx
+++ b/packages/ui/test/settings.test.tsx
@@ -152,6 +152,17 @@ describe("when the app cannot reach its assistant (S35.2)", () => {
});
});
+describe("when the web page has no access key", () => {
+ it("tells both a computer user and a server user how to open it", async () => {
+ h.tauri = false;
+ await renderApp("?surface=web");
+ const status = await screen.findByRole("status");
+ expect(status).toHaveTextContent(
+ "This page needs your access key. On your computer, open it from the Gentle Dot menu (Open in browser); on a server, open the link with #token=<your access key>.",
+ );
+ });
+});
+
describe("the Settings screen (S33.1)", () => {
it("opens from a gear in the desktop panel header", async () => {
const settings = await openSettings();