Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/desktop/e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,17 @@ test("primitives: the model Menu is keyboard-driven, and icon buttons are named,
await expect(more).toHaveAccessibleName("Project actions");
// Row actions are hidden until hover, but a keyboard user reaching one sees it, with its tooltip and shortcut.
await expect(more).toHaveCSS("opacity", "0");
await newThread.focus();
await page.keyboard.press("Tab"); // → worktree
// The row's actions run worktree chat, ⋯, new chat.
await tid(project, "project-new-worktree-thread").focus();
await page.keyboard.press("Tab"); // → ⋯
await expect(more).toBeFocused();
await expect(more).toHaveCSS("opacity", "1");
const tip = page.getByRole("tooltip", { name: "Project actions" });
await expect(tip).toHaveText("Project actions");
await expect(more).toHaveAttribute("aria-describedby", (await tip.getAttribute("id"))!);
// The ⋯ opens a Menu: focus lands on its first item (Open notes), Escape hands focus back.
// The ⋯ opens a Menu: focus lands on its first item (reveal the folder), Escape hands focus back.
await page.keyboard.press("Enter");
await expect(tid(project, "project-notes")).toBeFocused();
await expect(tid(project, "project-reveal")).toBeFocused();
await expect(tid(project, "project-remove")).toHaveRole("menuitem");
await page.keyboard.press("Escape");
await expect(tid(project, "project-remove")).toHaveCount(0);
Expand Down
9 changes: 8 additions & 1 deletion apps/desktop/e2e/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ test("browser without preload: add folder, approve a turn, inspect changes, term
await page.setViewportSize({ width: 1400, height: 1000 });
await tid(page, "empty-open-project").focus();
await expect(tid(page, "empty-open-project")).toBeFocused();
page.once("dialog", (dialog) => dialog.accept(repo));
// A project is made in the Create project dialog; a browser tab has no folder picker, so the path is typed.
await page.keyboard.press("Enter");
await expect(tid(page, "create-project")).toBeVisible();
await expect(tid(page, "create-project-submit")).toBeDisabled();
await tid(page, "create-project-path").fill(repo);
await page.keyboard.press("Enter");
await expect(tid(page, "create-project-folder")).toContainText(path.basename(repo));
await tid(page, "create-project-submit").click();
await expect(tid(page, "create-project")).toHaveCount(0);
await expect(tid(page, "draft-view")).toBeVisible();
await expect(tid(page, "model-picker")).toContainText("Scripted mock");
await tid(page, "composer-input").fill("Add a contributing guide");
Expand Down
51 changes: 41 additions & 10 deletions apps/desktop/e2e/routines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ async function openRoutines(page: Page) {
await expect(tid(page, "routines-view")).toBeVisible();
}

/** Selects the first task and shows its details and runs. A task that has run opens as its conversation first. */
async function openTaskDetails(page: Page) {
await tid(page, "routine-row").first().click();
await expect(tid(page, "routine-detail").or(tid(page, "sched-chat-title"))).toBeVisible();
if (await tid(page, "sched-chat-title").count()) {
await tid(page, "sched-chat-title").click();
await tid(page, "sched-details").click();
}
await expect(tid(page, "routine-detail")).toBeVisible();
}

test("with the window closed, a routine still runs, and reopening shows it in Activity", async () => {
test.skip(process.platform !== "darwin", "macOS keeps Modex running after its last window closes");
const { home } = seedHome();
Expand All @@ -42,6 +53,7 @@ test("with the window closed, a routine still runs, and reopening shows it in Ac
page = await nextWindow;
await waitForWindowReady(app, page);
await openRoutines(page);
await openTaskDetails(page);
const row = tid(page, "activity-row");
await expect(row).toHaveCount(1);
await expect(row).toHaveAttribute("data-status", "completed");
Expand Down Expand Up @@ -80,6 +92,7 @@ test("killing Modex mid-run leaves the run interrupted on restart, with no page
fs.writeFileSync(path.join(home, "app", "state.json"), JSON.stringify(restarted));
({ app, page } = await launch(home));
await openRoutines(page);
await openTaskDetails(page);
const interrupted = tid(page, "activity-row");
await expect(interrupted).toHaveCount(1, { timeout: 10_000 });
await expect(interrupted).toHaveAttribute("data-status", "interrupted");
Expand All @@ -93,7 +106,7 @@ test("killing Modex mid-run leaves the run interrupted on restart, with no page
await expect(tid(page, "activity-row")).toHaveCount(2);
});

test("a routine made in the editor runs read-only: its edit is refused with a receipt and the checkout is untouched", async () => {
test("a task made from a message runs read-only: its edit is refused with a receipt and the checkout is untouched", async () => {
const { home, repo } = seedHome();
const state = JSON.parse(fs.readFileSync(path.join(home, "app", "state.json"), "utf8"));
state.settings.mock_script = script(home, "edit", [
Expand All @@ -104,21 +117,39 @@ test("a routine made in the editor runs read-only: its edit is refused with a re
let page: Page;
({ app, page } = await launch(home));
await openRoutines(page);
// A task is made by describing it in a message, never in a form: the schedule is read from the message.
await tid(page, "routine-new").click();
await tid(page, "routine-name").fill("Weekly summary");
await tid(page, "routine-instructions").fill("Write a short summary of the week.");
await tid(page, "routine-mode-plan").check();
await tid(page, "routine-save").click();
await expect(tid(page, "routine-name")).toHaveCount(0);
await tid(page, "sched-compose-text").fill("Every week, write a short summary of the week.");
await expect(tid(page, "sched-reading")).toContainText("s at 8:00 AM · first run now");
await tid(page, "sched-compose-send").click();
const row = tid(page, "routine-row");
await expect(row).toContainText("Weekly summary");
await expect(row).toContainText("Plan (read-only)");
await expect(tid(row, "routine-next")).toContainText("Next run");
await expect(row).toContainText("Write a short summary of the week");

await tid(row, "routine-run-now").click();
// Its first run starts at once and opens as the task's conversation; the runs are one menu away.
await expect(tid(page, "sched-chat-title")).toContainText("Write a short summary of the week", { timeout: 30_000 });
await tid(page, "sched-chat-title").click();
await tid(page, "sched-details").click();
await expect(tid(page, "routine-detail")).toContainText("Chat (read-only)");
const activity = tid(page, "activity-row").first();
await expect(activity).toHaveAttribute("data-status", "completed", { timeout: 30_000 });
await expect(activity).toContainText("Run now");
await expect(tid(activity, "activity-page")).toHaveText("Weekly summary · revision 1");
await expect(tid(activity, "activity-page")).toHaveText("Write a short summary of the week · revision 1");
await expect(tid(page, "routine-next")).toContainText("Next run");

// What the run wrote opens beside its conversation, from the outputs list; the row's menu holds its actions.
await tid(page, "routine-row").first().click();
await tid(page, "sched-info").click();
await tid(page, "sched-output-open").click();
await expect(tid(page, "sched-output-page")).toContainText("I could not edit files, so here is the summary instead.");
await page.getByRole("button", { name: "Close output" }).click();
await expect(tid(page, "sched-output")).toHaveCount(0);
await tid(page, "routine-row").first().hover();
await tid(page, "routine-row-menu").first().click();
await expect(page.getByRole("menuitem", { name: "Pause" })).toBeVisible();
await page.keyboard.press("Escape");
await tid(page, "sched-chat-title").click();
await tid(page, "sched-details").click();
await tid(activity, "activity-thread").click();
// A finished turn folds its work; the refused approval is part of it.
await tid(page, "turn-label").last().click();
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/e2e/task-to-notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test("Save to Notes writes the turn's record into the project's notes, and savin
expect(saved[0]!.markdown).toContain("Fixed the import.");
expect(saved[0]!.markdown).toContain(`From modex thread ${threadId}.`);
expect(saved[0]!.markdown).not.toContain(repo);
await expect(save).toHaveText("Update note");
await expect(save).toHaveAccessibleName("Update note");
await save.click();
await expect(tid(page, "task-note-saved").first()).toContainText("Updated in Notes · Task:");
expect((await pages()).filter((p) => p.title.startsWith("Task:"))).toHaveLength(1);
Expand Down
9 changes: 8 additions & 1 deletion apps/desktop/e2e/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ test("new-tab menu, launcher, full view and Files replace the old panel", async
await tid(page, "workspace-full").click();
await expect(tid(page, "main")).toBeHidden();
await page.getByRole("button", { name: "Files ⌘P", exact: true }).click();
await page.getByRole("button", { name: "Open README.md", exact: true }).click();
await page.getByRole("treeitem", { name: "Open README.md", exact: true }).click();
// Markdown opens rendered; View source shows the file's own text. The crumb opens the folder tree.
await expect(tid(page, "workspace-file-content").getByRole("heading", { name: "e2e" })).toBeVisible();
await tid(page, "file-view-source").click();
await expect(tid(page, "workspace-file-content")).toContainText("# e2e");
await page.getByRole("navigation", { name: "File path" }).getByRole("button").first().click();
await expect(tid(page, "file-crumb-pop").getByRole("treeitem", { name: "Open README.md" })).toBeVisible();
await page.keyboard.press("Escape");
await expect(tid(page, "file-crumb-pop")).toHaveCount(0);
await tid(page, "workspace-full").click();
await expect(tid(page, "main")).toBeVisible();
await page.keyboard.press("Meta+Shift+f");
Expand Down
18 changes: 18 additions & 0 deletions apps/desktop/src/main/browser-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hydratePath } from "./engine/shell-env.js";
import { LIMITS } from "../shared/attachments.js";
import { revealAttachment } from "./reveal-attachment.js";
import { openTerminal } from "./engine/open-terminal.js";
import { RoutinePages, RoutineScheduler, validateRoutine } from "./engine/routines.js";

/** Local development transport only; never included in the packaged renderer. */
export function createBrowserDev(home: string) {
Expand Down Expand Up @@ -42,6 +43,22 @@ export function createBrowserDev(home: string) {
return store.thread(id)!.cwd;
}, (event) => broadcast("terminal", event), undefined, process.env,
process.env.MODEX_E2E ? { file: "/bin/bash", args: ["--noprofile", "--norc"] } : undefined);
// Scheduled tasks in browser development: they can be made, edited and run by hand. The timer is never
// started here, so nothing runs unattended from a dev server.
const routines = new RoutineScheduler(home, {
project: (id) => store.project(id),
createThread: async (projectId, routine) => { await pathReady; return runner.createRoutineThread(projectId, routine); },
sendUnattended: (id, text) => runner.sendUnattended(id, text),
stop: (id) => runner.stop(id),
items: (id) => runner.items(id),
status: (id) => runner.status(id),
addNotice: (id, level, text) => runner.addNotice(id, level, text),
pages: new RoutinePages(store.space),
});
handlers.set("routines:list", (() => routines.list()) as (payload: never) => unknown);
handlers.set("routines:save", ((draft: unknown) => routines.save(validateRoutine(draft, (id) => Boolean(store.project(id))))) as (payload: never) => unknown);
handlers.set("routines:delete", (({ id }: { id: string }) => routines.remove(id)) as (payload: never) => unknown);
handlers.set("routines:run", (({ id }: { id: string }) => routines.runNow(id)) as (payload: never) => unknown);
registerCommands((channel, handler) => handlers.set(channel, handler as (payload: never) => unknown), {
store, runner, terminals, emit,
pickDirectory: async () => { throw new Error("Enter the local project folder's absolute path."); },
Expand Down Expand Up @@ -171,6 +188,7 @@ export function createBrowserDev(home: string) {
for (const upload of uploads) upload.destroy();
for (const client of clients) client.end();
clients.clear();
try { routines.dispose(); } catch { /* Nothing was scheduled. */ }
const results = await Promise.allSettled([terminals.dispose(), runner.dispose()]);
const failure = results.find((result) => result.status === "rejected");
if (failure?.status === "rejected") throw failure.reason;
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/src/main/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export function registerCommands(handle: RegisterCommand, {
dir = await pickDirectory() ?? undefined;
if (!dir) return null;
}
return store.addProject(dir);
return store.addProject(dir, req?.name);
});
handle("project:pick-folder", async () => await pickDirectory() ?? null);
handle("project:remove", async ({ projectId }) => {
await runner.removeProject(projectId);
return store.snapshot();
Expand All @@ -109,6 +110,7 @@ export function registerCommands(handle: RegisterCommand, {
handle("thread:answer-question", ({ threadId, itemId, answers }) => runner.answerQuestion(threadId, itemId, answers));
handle("thread:update", ({ threadId, patch }) => runner.updateThread(threadId, patch));
handle("thread:archive", ({ threadId, archived }) => runner.setArchived(threadId, archived));
handle("thread:vote", ({ threadId, itemId, vote }) => runner.setVote(threadId, itemId, vote));
handle("thread:delete", async ({ threadId, removeWorktree }) => {
await runner.deleteThread(threadId, removeWorktree);
return store.snapshot();
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/main/engine/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,16 @@ export class ThreadRunner {
* phone; the transcript stays. A thread that is working cannot be archived, so nothing hidden ever
* waits for an answer.
*/
/** Records the person's rating of a reply with the thread. It is never sent to a CLI, a provider or any service. */
setVote(threadId: string, itemId: string, vote: "up" | "down" | null): void {
if (vote !== "up" && vote !== "down" && vote !== null) throw new Error("Choose up, down or no rating.");
if (!this.o.store.thread(threadId)) throw new Error(`unknown thread ${threadId}`);
const item = this.slot(threadId).items.find((i) => i.id === itemId);
if (!item || item.kind !== "assistant") throw new Error("Only a reply can be rated.");
if ((item.vote ?? null) === vote) return;
this.patchItem(threadId, itemId, { vote });
}

setArchived(threadId: string, archived: boolean): Thread {
this.assertNotRestarting();
if (typeof archived !== "boolean") throw new Error("Choose Archive or Unarchive.");
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/main/engine/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ export class Store {
return this.settings;
}

addProject(dir: string): Project {
addProject(dir: string, name?: string): Project {
const abs = path.resolve(dir);
const existing = this.state.projects.find((p) => p.path === abs);
if (existing) return existing;
const project: Project = { id: newId(), name: path.basename(abs), path: abs, addedAt: new Date().toISOString() };
const project: Project = { id: newId(), name: (typeof name === "string" && name.trim().slice(0, 80)) || path.basename(abs), path: abs, addedAt: new Date().toISOString() };
this.state.projects.push(project);
this.write();
// Notes never stand in the way of a project: a failure leaves it to be linked the next time notes open.
Expand Down
7 changes: 6 additions & 1 deletion apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,11 @@ handle("project:add", async (req) => {
if (r.canceled || !r.filePaths[0]) return null;
dir = r.filePaths[0];
}
return store.addProject(dir);
return store.addProject(dir, req?.name);
});
handle("project:pick-folder", async () => {
const r = await dialog.showOpenDialog(win!, { properties: ["openDirectory", "createDirectory"], title: "Choose a project folder" });
return r.canceled || !r.filePaths[0] ? null : r.filePaths[0];
});
handle("project:remove", async ({ projectId }) => {
await runner.removeProject(projectId);
Expand Down Expand Up @@ -857,6 +861,7 @@ handle("thread:answer", ({ threadId, itemId, answer }, event) => runner.answer(t
handle("thread:answer-question", ({ threadId, itemId, answers }, event) => runner.answerQuestion(threadId, itemId, answers, answeredFrom(event)));
handle("thread:update", ({ threadId, patch }, event) => runner.updateThread(threadId, patch, { by: answeredFrom(event) }));
handle("thread:archive", ({ threadId, archived }) => runner.setArchived(threadId, archived));
handle("thread:vote", ({ threadId, itemId, vote }) => runner.setVote(threadId, itemId, vote));
handle("thread:delete", async ({ threadId, removeWorktree }) => {
await runner.deleteThread(threadId, removeWorktree);
return store.snapshot();
Expand Down
Loading
Loading