luxe 0.1.4: remembered models, wheel-driven lists, and a steadier phone app
- luxe starts on the model you last chose in this project, then the last one anywhere. Signing in opens the model picker instead of choosing for you. - Every list in a modal takes the mouse wheel and a draggable scrollbar. - The phone app shows reasoning in full, stays put while you read back through a long session, and shows a question's answer on its card. - On Windows, luxe update replaces the running luxe, and a signed-in install no longer sees setup again. - The file tree no longer shows "engine busy" in a large project, loop output is easier to follow, and the name is written lowercase. The CHANGELOG has the full list.
This commit is contained in:
43
crates/luxe-remote/app-tests/answers.test.mjs
Normal file
43
crates/luxe-remote/app-tests/answers.test.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
// A question card's answers, read back out of the call's result. Each result text is a literal
|
||||
// copied from a saved session or from `luxe_core::question`'s own tests, so a reworded ending on
|
||||
// the host fails here rather than leaving the phone's card quietly blank.
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { questionOutcome } from "../app/answers.js";
|
||||
|
||||
// The break this catches: a single answer, the usual case, left off the card
|
||||
test("one answer reads back as that answer", () => {
|
||||
assert.deepEqual(questionOutcome("The user answered: Now, with my phone"), { answers: ["Now, with my phone"], note: "" });
|
||||
});
|
||||
|
||||
// The break this catches: several answers run together as one, or a comma inside an answer
|
||||
// splitting it in two
|
||||
test("several answers read back one per line, commas and all", () => {
|
||||
const result = "The user answered:\n- Dark mode\n- also, vim keys";
|
||||
assert.deepEqual(questionOutcome(result), { answers: ["Dark mode", "also, vim keys"], note: "" });
|
||||
});
|
||||
|
||||
// The break this catches: a dismissal drawn as though the reader chose something
|
||||
test("a dismissal says so and credits no answer", () => {
|
||||
const outcome = questionOutcome("The user dismissed the question without answering.");
|
||||
assert.deepEqual(outcome, { answers: [], note: "dismissed without answering" });
|
||||
});
|
||||
|
||||
// The break this catches: an empty submission mistaken for a dismissal, or for text the card can't read
|
||||
test("an empty submission says it had no answer", () => {
|
||||
const outcome = questionOutcome("The user submitted the question with no selection.");
|
||||
assert.deepEqual(outcome, { answers: [], note: "submitted with no answer" });
|
||||
});
|
||||
|
||||
// The break this catches: a default the call fell back to credited to a reader who was never asked
|
||||
test("an answer nobody gave says it came from the default", () => {
|
||||
const outcome = questionOutcome("[Auto-answered, no interactive session] Which runtime?\nAnswer: tokio");
|
||||
assert.deepEqual(outcome, { answers: ["tokio"], note: "nobody to ask · answered from the default" });
|
||||
});
|
||||
|
||||
// The break this catches: the card inventing an answer from text that isn't one of the host's endings
|
||||
test("text that isn't a question's ending reads as nothing", () => {
|
||||
assert.equal(questionOutcome("Error: question needs a prompt"), null);
|
||||
assert.equal(questionOutcome("[Auto-answered, no interactive session] Which runtime?"), null);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
// A Luxe of the test's own: a session in a fresh git project, driven by the mock model, and a
|
||||
// A luxe of the test's own: a session in a fresh git project, driven by the mock model, and a
|
||||
// bridge serving it, all under one temporary directory, so nothing touches the real config.
|
||||
|
||||
import { spawn, execFileSync } from "node:child_process";
|
||||
@@ -17,11 +17,11 @@ export const LOGIN = "e2e@luxe.test";
|
||||
/** The `luxe` to test: `LUXE_BIN`, or the debug build. */
|
||||
const LUXE = process.env.LUXE_BIN ?? join(REPO, "target/debug/luxe");
|
||||
|
||||
/** Starts a session and a bridge for the mock model on `modelPort`. */
|
||||
export async function startHost(modelPort) {
|
||||
/** Starts a session and a bridge for the mock model on `modelPort`, in a project named `name`. */
|
||||
export async function startHost(modelPort, name = "project") {
|
||||
const root = mkdtempSync(join(tmpdir(), "luxe-e2e-"));
|
||||
const env = isolatedEnv(root);
|
||||
const project = gitProject(root);
|
||||
const project = gitProject(root, name);
|
||||
writeConfig(env.LUXE_CONFIG_DIR, modelPort);
|
||||
const children = [];
|
||||
const host = { root, project, children, stop: () => stop(host) };
|
||||
@@ -39,11 +39,11 @@ function isolatedEnv(root) {
|
||||
return env;
|
||||
}
|
||||
|
||||
function gitProject(root) {
|
||||
const project = join(root, "project");
|
||||
function gitProject(root, name) {
|
||||
const project = join(root, name);
|
||||
mkdirSync(project);
|
||||
const git = (...args) => execFileSync("git", ["-c", "user.name=e2e", "-c", "user.email=e2e@luxe.test", ...args], { cwd: project });
|
||||
git("init", "-q");
|
||||
git("init", "-q", "-b", "main");
|
||||
// a few lines, so a phone can pick a range of them and select part of one
|
||||
writeFileSync(join(project, "README.md"), "# e2e\n\nThe port is 4519.\nThe host is luxe.local.\n");
|
||||
git("add", ".");
|
||||
|
||||
127
crates/luxe-remote/app-tests/e2e/screenshots.mjs
Normal file
127
crates/luxe-remote/app-tests/e2e/screenshots.mjs
Normal file
@@ -0,0 +1,127 @@
|
||||
// The phone app's screenshots for the guide's "Luxe on your phone" page, taken of the real app: a
|
||||
// session in a scratch project, a bridge, and a scripted model that reads a file, edits it (which
|
||||
// asks permission), runs it, and says what it did. Nothing here is drawn by hand.
|
||||
//
|
||||
// Needs a built `luxe` (`LUXE_BIN`, or target/debug/luxe) and Playwright's WebKit or Chromium.
|
||||
// Run from app-tests: node e2e/screenshots.mjs [out-dir], by default docs/guide/phone/
|
||||
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { createServer } from "node:http";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { LOGIN, startHost } from "./host.mjs";
|
||||
|
||||
const playwright = createRequire(import.meta.url)("playwright");
|
||||
const REPO = resolve(dirname(fileURLToPath(import.meta.url)), "../../../..");
|
||||
const OUT = resolve(process.argv[2] ?? join(REPO, "docs/guide/phone"));
|
||||
|
||||
const APP = `import argparse
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Count the words in a file.")
|
||||
parser.add_argument("path")
|
||||
args = parser.parse_args()
|
||||
with open(args.path) as file:
|
||||
print(len(file.read().split()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
`;
|
||||
|
||||
const OLD = ` parser.add_argument("path")\n args = parser.parse_args()\n with open(args.path) as file:\n print(len(file.read().split()))`;
|
||||
const NEW = ` parser.add_argument("path")\n parser.add_argument("--top", type=int, help="also list the most common words")\n args = parser.parse_args()\n with open(args.path) as file:\n words = file.read().lower().split()\n print(len(words))\n for word, count in Counter(words).most_common(args.top or 0):\n print(f"{count:>5} {word}")`;
|
||||
|
||||
/** Each step of the script, picked by how many tool results the request carries. */
|
||||
const STEPS = [
|
||||
{ say: "I'll read the script first.", tool: "read", args: { path: "wc.py" } },
|
||||
{ say: "It counts but doesn't rank. Adding `--top`:", tool: "edit", args: { path: "wc.py", edits: [{ oldText: OLD, newText: NEW }, { oldText: "import argparse\n", newText: "import argparse\nfrom collections import Counter\n" }] } },
|
||||
{ say: null, tool: "bash", args: { command: "python3 wc.py README.md --top 3", description: "Try the new flag" } },
|
||||
{ done: "Added **`--top N`** to `wc.py`. It still prints the total first, then the `N` most common words with their counts:\n\n```text\n12\n 2 the\n 1 port\n 1 is\n```\n\nWords are lowercased before counting, so `The` and `the` are one word. Without `--top` the output is unchanged." },
|
||||
];
|
||||
|
||||
const chunk = (delta, finish = null) => ({ id: "shot", object: "chat.completion.chunk", created: 0, model: "scripted", choices: [{ index: 0, delta, finish_reason: finish }] });
|
||||
const usage = { id: "shot", object: "chat.completion.chunk", created: 0, model: "scripted", choices: [], usage: { prompt_tokens: 18400, completion_tokens: 240, total_tokens: 18640 } };
|
||||
|
||||
function reply(body) {
|
||||
if (!body.tools?.length) return [chunk({ role: "assistant", content: "Rank words" }), chunk({}, "stop"), usage];
|
||||
const step = STEPS[Math.min(body.messages.filter((m) => m.role === "tool").length, STEPS.length - 1)];
|
||||
if (step.done) return [chunk({ role: "assistant", content: step.done }), chunk({}, "stop"), usage];
|
||||
const call = { index: 0, id: `call_${step.tool}`, type: "function", function: { name: step.tool, arguments: JSON.stringify(step.args) } };
|
||||
return [chunk({ role: "assistant", content: step.say, tool_calls: [call] }), chunk({}, "tool_calls"), usage];
|
||||
}
|
||||
|
||||
async function startModel() {
|
||||
const server = createServer(async (request, response) => {
|
||||
let text = "";
|
||||
for await (const part of request) text += part;
|
||||
response.writeHead(200, { "content-type": "text/event-stream" });
|
||||
for (const piece of reply(JSON.parse(text))) response.write(`data: ${JSON.stringify(piece)}\n\n`);
|
||||
response.end("data: [DONE]\n\n");
|
||||
});
|
||||
await new Promise((done) => server.listen(0, "127.0.0.1", () => done(undefined)));
|
||||
return { port: /** @type {import("node:net").AddressInfo} */ (server.address()).port, close: () => server.close() };
|
||||
}
|
||||
|
||||
// As flow.mjs pairs: paste the link, carry the Secure cookie over plain HTTP by hand
|
||||
async function pair(page, host) {
|
||||
await page.goto(host.url);
|
||||
await page.locator(".pair-link input").fill(`https://desk.example.ts.net/pair#${host.invitation}`);
|
||||
await page.locator(".pair-link button").click();
|
||||
const answered = page.waitForResponse("**/api/pair");
|
||||
await page.locator("#pair button").click();
|
||||
const cookie = (await (await answered).headerValue("set-cookie"))?.split(";")[0] ?? "";
|
||||
await page.waitForURL((url) => url.pathname === "/", { waitUntil: "networkidle" });
|
||||
const at = cookie.indexOf("=");
|
||||
await page.context().addCookies([{ name: cookie.slice(0, at), value: cookie.slice(at + 1), url: host.url }]);
|
||||
await page.goto(host.url);
|
||||
}
|
||||
|
||||
async function launch() {
|
||||
try {
|
||||
return await playwright.webkit.launch();
|
||||
} catch (error) {
|
||||
console.warn(`WebKit wouldn't start, using Chromium: ${String(error).split("\n")[0]}`);
|
||||
return playwright.chromium.launch();
|
||||
}
|
||||
}
|
||||
|
||||
async function shoot(page, name) {
|
||||
await page.waitForTimeout(400);
|
||||
await page.screenshot({ path: join(OUT, `${name}.png`) });
|
||||
console.log(`wrote ${join(OUT, `${name}.png`)}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
mkdirSync(OUT, { recursive: true });
|
||||
const model = await startModel();
|
||||
const host = await startHost(model.port, "wordcount");
|
||||
writeFileSync(join(host.project, "wc.py"), APP);
|
||||
const git = (...args) => execFileSync("git", ["-c", "user.name=e2e", "-c", "user.email=e2e@luxe.test", ...args], { cwd: host.project });
|
||||
git("add", "wc.py");
|
||||
git("commit", "-qm", "wc");
|
||||
const browser = await launch();
|
||||
const { defaultBrowserType: _, ...phone } = playwright.devices["iPhone 15 Pro"];
|
||||
const context = await browser.newContext({ ...phone, deviceScaleFactor: 2, extraHTTPHeaders: { "Tailscale-User-Login": LOGIN } });
|
||||
const page = await context.newPage();
|
||||
try {
|
||||
await pair(page, host);
|
||||
await page.locator("a.session").click();
|
||||
await page.locator(".composer textarea").fill("Add a --top flag to wc.py that lists the most common words");
|
||||
await page.locator(".send").click();
|
||||
await page.locator(".prompt .choice.once").waitFor();
|
||||
await shoot(page, "remote-permission");
|
||||
await page.locator(".prompt .choice.once").click();
|
||||
await page.locator(".item.reply", { hasText: "Without --top" }).waitFor({ timeout: 20000 });
|
||||
await shoot(page, "remote-turn");
|
||||
} finally {
|
||||
await browser.close();
|
||||
await host.stop();
|
||||
model.close();
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -43,8 +43,8 @@ test("an answer to an earlier question is ignored", () => {
|
||||
assert.equal(models.listing.value.state, "asking");
|
||||
});
|
||||
|
||||
// The break this catches: an older Luxe's refusal ignored, so the sheet says it's listing forever
|
||||
test("a Luxe that doesn't know the question is told apart", () => {
|
||||
// The break this catches: an older luxe's refusal ignored, so the sheet says it's listing forever
|
||||
test("a luxe that doesn't know the question is told apart", () => {
|
||||
const { models } = asked();
|
||||
models.apply({ kind: "action_rejected", content: { kind: "list_models", reason: "unknown kind" } });
|
||||
assert.equal(models.listing.value.state, "unsupported");
|
||||
|
||||
@@ -43,7 +43,7 @@ test("a push it can't read still shows a notification", async () => {
|
||||
const { fire, shown } = worker();
|
||||
await fire("push", push("not json"));
|
||||
await fire("push", { data: null });
|
||||
assert.deepEqual(shown.map((notice) => notice.title), ["Luxe", "Luxe"]);
|
||||
assert.deepEqual(shown.map((notice) => notice.title), ["luxe", "luxe"]);
|
||||
});
|
||||
|
||||
const click = (session) => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { test } from "node:test";
|
||||
import { WINDOW, elapsed, windowOf } from "../app/items.js";
|
||||
import { WINDOW, elapsed, windowOf, windowStart } from "../app/items.js";
|
||||
import { createTranscript, formatTokens } from "../app/transcript.js";
|
||||
|
||||
/** A session joined through the bridge: the snapshot, then a live turn with two tool calls. */
|
||||
@@ -214,7 +214,42 @@ test("a transcript that fits is drawn whole", () => {
|
||||
assert.deepEqual(windowOf(items, 3), { hidden: 0, drawn: items });
|
||||
});
|
||||
|
||||
// The break this catches: a reader at the bottom left with an ever-growing page, or a first draw
|
||||
// that doesn't start from the latest items
|
||||
test("the window slides to the latest items while the reader follows the bottom", () => {
|
||||
assert.equal(windowStart(null, WINDOW + 5, WINDOW, false), 5);
|
||||
assert.equal(windowStart(5, WINDOW + 6, WINDOW, true), 6);
|
||||
});
|
||||
|
||||
// The break this catches: each new item taking the oldest from the top while the reader is scrolled
|
||||
// up, which in WebKit moves everything they were reading up the screen
|
||||
test("the window holds its start while the reader reads above the bottom", () => {
|
||||
assert.equal(windowStart(5, WINDOW + 6, WINDOW, false), 5);
|
||||
assert.equal(windowStart(5, WINDOW + 40, WINDOW, false), 5);
|
||||
});
|
||||
|
||||
// The break this catches: "Show earlier" doing nothing while the reader is scrolled up to tap it
|
||||
test("asking for earlier items moves the start back while reading above the bottom", () => {
|
||||
assert.equal(windowStart(500, 900, 900 - 200, false), 200);
|
||||
});
|
||||
|
||||
// The break this catches: a reader back at the bottom keeping every item that came while they read
|
||||
test("back at the bottom, the window trims to the latest items again", () => {
|
||||
assert.equal(windowStart(5, WINDOW + 40, WINDOW, true), 40);
|
||||
});
|
||||
|
||||
// The break this catches: a duration written differently from the TUI's card beside it.
|
||||
test("durations read as the TUI writes them", () => {
|
||||
assert.deepEqual([0.4, 19, 1500, 63000].map(elapsed), ["<1ms", "19ms", "1.5s", "1m 3s"]);
|
||||
});
|
||||
|
||||
// The break this catches: reasoning clipped to a few rows with nothing to say there's more, which
|
||||
// reads as the agent's thought cut off mid-sentence where the TUI shows all of it
|
||||
test("reasoning is drawn whole, never clipped", () => {
|
||||
const css = readFileSync(new URL("../app/style.css", import.meta.url), "utf8");
|
||||
const rules = [...css.matchAll(/([^{}]*\.thinking[^{}]*)\{([^}]*)\}/g)];
|
||||
assert.ok(rules.length > 0, "the reasoning rule is where this test looks");
|
||||
for (const [, selector, body] of rules) {
|
||||
assert.doesNotMatch(body, /max-height|overflow\s*:\s*hidden|line-clamp/, `${selector.trim()} clips`);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user