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
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"plugins/claude-tty": "0.6.0",
"plugins/discord-rich-presence": "0.3.0",
"plugins/guided-review": "0.3.0",
"plugins/task-runner": "0.0.0",
"apps/claude-tty-acp": "0.6.0"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ My plugins for [Paseo](https://github.com/getpaseo/paseo).
| [Catppuccin theme](plugins/catppuccin-theme) | Add all four Catppuccin flavours as app themes. |
| [Claude TTY](plugins/claude-tty) | Deprecated: offer the Claude TTY ACP adapter as a Paseo provider, and manage it on the daemon host. |
| [Guided Review](plugins/guided-review) | Show a trunk-first guide to a pull request or merge request, and build your draft review alongside it. |
| [Task Runner](plugins/task-runner) | Run a project's own scripts from a sidebar panel. |

| ACP | Description |
| ------------------------------------- | -------------------------------------------------------------------------------------- |
Expand Down
11 changes: 11 additions & 0 deletions plugins/task-runner/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Working on this plugin

Run `paseo plugin reload task-runner` after every change, then `paseo plugin logs task-runner`.
The reload is the only compile check of the two bundles the daemon builds.

## Traps

- A dependency whose entry is a UMD build fails at load with `Cannot find module`, because the daemon's bundler cannot follow its dynamic `require`, while typecheck and tests pass.
`jsonc-parser` is one, which is why `server/discovery/files.ts` reads JSONC itself.
- A change to `WRAPPER` in `server/runs/shell-wrapper.ts` has to be tried on real terminals with both zsh and bash, with a single-command task and with Ctrl+C.
- `pnpm test` runs `node --test` with Node's type stripping: write only erasable TypeScript and keep the `.ts` extension on relative imports.
56 changes: 56 additions & 0 deletions plugins/task-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Task Runner

Run the scripts your project already defines from a **Tasks** panel in the Explorer, without declaring them again in `paseo.json`.
It lists `package.json` scripts, Makefile targets, Nx targets and `.vscode/tasks.json` tasks.

## Screenshots

![Tasks grouped by package in a monorepo](./docs/screenshots/panel.png)

![A finished task expanded to its output](./docs/screenshots/output.png)

![A running task with Stop and Restart](./docs/screenshots/running.png)

## Installation

Requires:

- Paseo 0.15 or newer
- A macOS or Linux host

```sh
paseo plugin add github:sleeyax/paseo-plugins:plugins/task-runner
```

Update with `paseo plugin update task-runner`.
To install from source, see the [root README](../../README.md#from-source).

## Usage

### Run a task

Open **Tasks** in the Explorer, or choose **Run Task...** in the Command Center.
Select the play button on a task.
It runs in its own workspace terminal, which opens as a tab without taking focus.

### Run a task from the keyboard

Choose **Run Task...** in the Command Center, pick a task with the arrow keys, and press Enter.
Recently run tasks are listed first.
**Rerun Last Task** in the Command Center runs the last one again.

### List targets inferred by Nx plugins

Select **Load inferred targets** in the panel, which runs the repository's own `nx`.
The choice is remembered per workspace.

### Run a command that has no script

Add it to `.vscode/tasks.json`.
The `label`, `command`, `args` and `options.cwd` fields are read, and only `${workspaceFolder}` is filled in.

## Development

For development instructions, see the [root README](../../README.md#development).

Design decisions are in [docs/adr](docs/adr).
108 changes: 108 additions & 0 deletions plugins/task-runner/client/task-list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import type { Task } from "../shared/task.ts";
import { buildSections, filterTasks, groupTasks } from "./task-list.ts";

const task = (label: string, group = "app", source = "pnpm"): Task => ({
id: `task: ${group}: ${label}`,
label,
group,
source,
command: source,
args: [],
cwd: "/repo",
description: null,
disabledReason: null,
});

const tasks = [task("build"), task("dev"), task("build", "web", "nx"), task("image", "web", "make")];
const shown = (query: string) => filterTasks(tasks, query).map((item) => `${item.group}/${item.label}`);

describe("filterTasks", () => {
it("keeps everything for an empty query", () => {
assert.equal(filterTasks(tasks, " ").length, 4);
});

it("matches the label regardless of case", () => {
assert.deepEqual(shown("BUI"), ["app/build", "web/build"]);
});

it("requires every word, which may match the group or source", () => {
assert.deepEqual(shown("web build"), ["web/build"]);
assert.deepEqual(shown("make"), ["web/image"]);
});

it("finds nothing when a word matches nothing", () => {
assert.deepEqual(shown("build zzz"), []);
});
});

describe("groupTasks", () => {
it("keeps groups in the order they first appear", () => {
assert.deepEqual(groupTasks(tasks).map((group) => [group.name, group.tasks.length]), [["app", 2], ["web", 2]]);
});
});

describe("buildSections", () => {
const layout = (options: Partial<Parameters<typeof buildSections>[1]> = {}) =>
buildSections(tasks, { query: "", recentIds: [], collapsed: new Set(), ...options });
const rows = (result: ReturnType<typeof buildSections>) =>
result.sections.map((section) => [section.title, section.rows.map((row) => `${row.index}:${row.task.group}/${row.task.label}`)]);

it("numbers the rows of every group in order for the keyboard", () => {
assert.deepEqual(rows(layout()), [
["app", ["0:app/build", "1:app/dev"]],
["web", ["2:web/build", "3:web/image"]],
]);
assert.deepEqual(layout().navigable.map((item) => item.label), ["build", "dev", "build", "image"]);
});

it("puts recently run tasks first, under recent, with their group shown", () => {
const result = layout({ recentIds: ["task: web: image", "task: app: dev"] });
assert.deepEqual(rows(result)[0], ["recent", ["0:web/image", "1:app/dev"]]);
assert.equal(result.sections[0]?.rows[0]?.showGroup, true);
assert.equal(result.sections[1]?.rows[0]?.index, 2);
});

it("filters recent tasks too, and skips ones no longer listed", () => {
const result = layout({ query: "image", recentIds: ["task: gone: x", "task: web: image", "task: app: dev"] });
assert.deepEqual(rows(result), [
["recent", ["0:web/image"]],
["web", ["1:web/image"]],
]);
});

it("shows at most five recent tasks", () => {
const many = Array.from({ length: 7 }, (_, index) => task(`t${index}`));
const result = buildSections(many, { query: "", recentIds: many.map((item) => item.id), collapsed: new Set() });
assert.equal(result.sections[0]?.rows.length, 5);
});

it("leaves a collapsed group's rows out of the keyboard order, unless searching", () => {
assert.deepEqual(rows(layout({ collapsed: new Set(["group:app"]) })), [
["app", []],
["web", ["0:web/build", "1:web/image"]],
]);
assert.equal(layout({ collapsed: new Set(["group:app"]) }).sections[0]?.open, false);
assert.equal(layout({ collapsed: new Set(["group:app"]), query: "dev" }).sections[0]?.open, true);
});

it("collapses recent like a group, leaving its rows out of the keyboard order", () => {
const result = layout({ recentIds: ["task: app: dev"], collapsed: new Set(["recent"]) });
assert.equal(result.sections[0]?.title, "recent");
assert.equal(result.sections[0]?.collapsible, true);
assert.equal(result.sections[0]?.open, false);
assert.equal(result.sections[1]?.rows[0]?.index, 0);
});

it("does not confuse a package named recent with the recent section", () => {
const named = [task("a", "recent"), task("b", "other")];
const result = buildSections(named, { query: "", recentIds: ["task: recent: a"], collapsed: new Set(["group:recent"]) });
assert.deepEqual(result.sections.map((section) => [section.title, section.open]), [["recent", true], ["recent", false], ["other", true]]);
});

it("gives a single group no title", () => {
const result = buildSections([task("a"), task("b")], { query: "", recentIds: [], collapsed: new Set() });
assert.deepEqual(result.sections.map((section) => section.title), [null]);
});
});
70 changes: 70 additions & 0 deletions plugins/task-runner/client/task-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { Task } from "../shared/task.ts";

export type TaskGroup = { name: string; tasks: Task[] };

export function filterTasks(tasks: Task[], query: string): Task[] {
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
if (words.length === 0) return tasks;
return tasks.filter((task) => {
const haystack = `${task.label} ${task.group} ${task.source}`.toLowerCase();
return words.every((word) => haystack.includes(word));
});
}

export function groupTasks(tasks: Task[]): TaskGroup[] {
const groups = new Map<string, Task[]>();
for (const task of tasks) groups.set(task.group, [...(groups.get(task.group) ?? []), task]);
return [...groups].map(([name, grouped]) => ({ name, tasks: grouped }));
}

const RECENT_SHOWN = 5;

export type TaskSectionRow = {
task: Task;
/** The row's place in the keyboard order. */
index: number;
/** Whether the row sits outside its group, so its group needs naming. */
showGroup: boolean;
};

export type TaskSection = {
key: string;
/** Null for the only group, which needs no header. */
title: string | null;
collapsible: boolean;
open: boolean;
rows: TaskSectionRow[];
};

export type SectionOptions = {
query: string;
recentIds: string[];
/** Section keys, so a package named recent does not share the recent section's state. */
collapsed: ReadonlySet<string>;
};

export function buildSections(tasks: Task[], { query, recentIds, collapsed }: SectionOptions): { sections: TaskSection[]; navigable: Task[] } {
const shown = filterTasks(tasks, query);
const grouped = groupTasks(tasks).length > 1;
const searching = query.trim() !== "";
const navigable: Task[] = [];
const rowsOf = (sectionTasks: Task[], showGroup: boolean) =>
sectionTasks.map((task) => {
navigable.push(task);
return { task, index: navigable.length - 1, showGroup };
});

const sections: TaskSection[] = [];
const isOpen = (key: string) => searching || !collapsed.has(key);
const recent = recentIds.flatMap((id) => shown.find((task) => task.id === id) ?? []).slice(0, RECENT_SHOWN);
if (recent.length > 0) {
const open = isOpen("recent");
sections.push({ key: "recent", title: "recent", collapsible: true, open, rows: open ? rowsOf(recent, grouped) : [] });
}
for (const group of groupTasks(shown)) {
const key = `group:${group.name}`;
const open = isOpen(key);
sections.push({ key, title: grouped ? group.name : null, collapsible: grouped, open, rows: open ? rowsOf(group.tasks, false) : [] });
}
return { sections, navigable };
}
123 changes: 123 additions & 0 deletions plugins/task-runner/client/task-row.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import type { PluginTheme } from "@getpaseo/plugin";
import { Icon } from "@getpaseo/plugin/client/ui";
import { useState } from "react";
import { Platform, Pressable, Text, View } from "react-native";
import { isRunActive, type RunState, type Task } from "../shared/task.ts";

type Colors = PluginTheme["colors"];

const MONOSPACE = Platform.select({ ios: "Menlo", android: "monospace", default: "monospace" });

export type TaskActions = {
run(task: Task): void;
stop(run: RunState): void;
forceKill(run: RunState): void;
};

function statusText(run: RunState): string {
switch (run.status) {
case "running":
return "Running";
case "stopping":
return "Stopping…";
case "stopped":
return "Stopped";
case "succeeded":
return "Done";
case "failed":
return `Failed (exit ${run.exitCode ?? "?"})`;
}
}

function statusColor(run: RunState, colors: Colors): string {
switch (run.status) {
case "running":
case "stopping":
return colors.accent;
case "succeeded":
return colors.statusSuccess;
case "failed":
return colors.statusDanger;
case "stopped":
return colors.statusWarning;
}
}

function IconButton({ colors, icon, label, disabled, onPress }: { colors: Colors; icon: string; label: string; disabled?: boolean; onPress: () => void }) {
return (
<Pressable accessibilityRole="button" accessibilityLabel={label} disabled={disabled} onPress={onPress} hitSlop={4} style={{ padding: 4, opacity: disabled ? 0.4 : 1 }}>
<Icon name={icon} size={15} color={colors.foregroundMuted} />
</Pressable>
);
}

function Controls({ colors, task, run, busy, actions }: { colors: Colors; task: Task; run: RunState | null; busy: boolean; actions: TaskActions }) {
if (task.disabledReason !== null) return null;
if (run === null || !isRunActive(run)) return <IconButton colors={colors} icon="Play" label={`Run ${task.label}`} disabled={busy} onPress={() => actions.run(task)} />;
return (
<View style={{ flexDirection: "row", alignItems: "center", gap: 2 }}>
{run.canForceKill ? (
<Pressable accessibilityRole="button" onPress={() => actions.forceKill(run)} hitSlop={4} style={{ paddingHorizontal: 4 }}>
<Text style={{ color: colors.statusDanger, fontSize: 12 }}>Force kill</Text>
</Pressable>
) : null}
{run.status === "running" ? <IconButton colors={colors} icon="Square" label={`Stop ${task.label}`} disabled={busy} onPress={() => actions.stop(run)} /> : null}
<IconButton colors={colors} icon="RotateCw" label={`Restart ${task.label}`} disabled={busy} onPress={() => actions.run(task)} />
</View>
);
}

export type TaskRowProps = {
colors: Colors;
task: Task;
/** Named when the row is listed outside its group, as under recent. */
groupName: string | null;
/** The row Enter runs from the search box. */
highlighted: boolean;
run: RunState | null;
busy: boolean;
actions: TaskActions;
};

export function TaskRow({ colors, task, groupName, highlighted, run, busy, actions }: TaskRowProps) {
const [expanded, setExpanded] = useState(false);
const lastLine = run?.output.at(-1) ?? null;
const hasOutput = lastLine !== null;
const muted = task.disabledReason !== null;
return (
<View style={{ paddingVertical: 4, paddingHorizontal: 8, gap: 2, borderRadius: 4, backgroundColor: highlighted ? colors.surface2 : undefined }}>
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
<Pressable accessibilityRole="button" accessibilityState={{ expanded }} disabled={!hasOutput} onPress={() => setExpanded(!expanded)} style={{ flex: 1, flexDirection: "row", alignItems: "center", gap: 6, minWidth: 0 }}>
<View style={{ width: 7, height: 7, borderRadius: 4, backgroundColor: run === null ? colors.border : statusColor(run, colors) }} />
{groupName !== null ? (
<Text numberOfLines={1} style={{ flexShrink: 2, color: colors.foregroundMuted, fontSize: 13 }}>
{groupName} ›
</Text>
) : null}
<Text numberOfLines={1} style={{ flexShrink: 1, color: muted ? colors.foregroundMuted : colors.foreground, fontSize: 13 }}>
{task.label}
</Text>
<Text numberOfLines={1} style={{ color: colors.foregroundMuted, fontSize: 11 }}>
{run === null ? task.source : statusText(run)}
</Text>
</Pressable>
<Controls colors={colors} task={task} run={run} busy={busy} actions={actions} />
</View>
{task.disabledReason !== null || task.description !== null ? (
<Text numberOfLines={2} style={{ color: colors.foregroundMuted, fontSize: 12, paddingLeft: 13 }}>
{task.disabledReason ?? task.description}
</Text>
) : null}
{hasOutput && !expanded ? (
<Text numberOfLines={1} style={{ color: colors.foregroundMuted, fontSize: 11, fontFamily: MONOSPACE, paddingLeft: 13 }}>
{lastLine}
</Text>
) : null}
{hasOutput && expanded ? (
<Text selectable style={{ color: colors.foreground, fontSize: 11, fontFamily: MONOSPACE, padding: 6, marginLeft: 13, borderRadius: 4, backgroundColor: colors.surface2 }}>
{run?.output.join("\n")}
</Text>
) : null}
</View>
);
}
Loading
Loading