From 5fc93e365e1b965027d7c7b416834ef52c0870f7 Mon Sep 17 00:00:00 2001 From: Theros Date: Sat, 7 Nov 2026 09:05:33 +0000 Subject: [PATCH 1/4] Organize application and Herdr target --- .gitignore | 3 +- AGENTS.md | 8 ++--- README.md | 31 +++++++++---------- SPEC.md | 18 +++++------ {service/src => app}/api.ts | 0 {service/src => app}/db.ts | 0 {service/src => app}/instructions.ts | 0 {service/src => app}/mcp.ts | 0 {service/src => app}/paths.ts | 0 {service/src => app}/projects.ts | 0 {service/src => app}/runbook.ts | 0 {service/src => app}/skill-content.ts | 2 +- {service/src => app}/skill.ts | 0 {service/src => app}/store.ts | 0 {service/src => app}/util.ts | 0 {service/src => app}/version.ts | 0 service/bun.lock => bun.lock | 2 +- service/src/cli.ts => cli.ts | 16 +++++----- service/src/install.ts => install.ts | 4 +-- package.json | 14 ++++++++- {service => scripts}/build-herdr-assets.ts | 6 ++-- {service => scripts}/build-skill.ts | 8 ++--- service/package.json | 21 ------------- .../src/installer => targets/herdr}/assets.ts | 4 +-- .../herdr.ts => targets/herdr/installer.ts | 14 ++++----- keys.json => targets/herdr/keys.json | 0 .../herdr/layouts}/muster.json | 0 {mods => targets/herdr/mods}/muster/bell.js | 0 {mods => targets/herdr/mods}/muster/board.js | 0 {mods => targets/herdr/mods}/muster/brand.js | 0 {mods => targets/herdr/mods}/muster/cards.js | 0 {mods => targets/herdr/mods}/muster/footer.js | 0 .../herdr/mods}/muster/gpui-kit.d.ts | 0 .../herdr/mods}/muster/helpers.js | 0 .../herdr/mods}/muster/icons/alert.svg | 0 .../mods}/muster/icons/arrow-up-right.svg | 0 .../herdr/mods}/muster/icons/bell.svg | 0 .../herdr/mods}/muster/icons/board.svg | 0 .../herdr/mods}/muster/icons/book.svg | 0 .../herdr/mods}/muster/icons/branch.svg | 0 .../herdr/mods}/muster/icons/cards.svg | 0 .../herdr/mods}/muster/icons/chart.svg | 0 .../herdr/mods}/muster/icons/check.svg | 0 .../mods}/muster/icons/chevron-right.svg | 0 .../herdr/mods}/muster/icons/clock.svg | 0 .../herdr/mods}/muster/icons/inbox.svg | 0 .../herdr/mods}/muster/icons/maximize.svg | 0 .../herdr/mods}/muster/icons/refresh.svg | 0 .../herdr/mods}/muster/icons/send.svg | 0 .../herdr/mods}/muster/icons/split-down.svg | 0 .../herdr/mods}/muster/icons/split-right.svg | 0 .../herdr/mods}/muster/icons/terminal.svg | 0 .../herdr/mods}/muster/icons/x.svg | 0 .../herdr/mods}/muster/jsconfig.json | 0 {mods => targets/herdr/mods}/muster/kit.js | 0 {mods => targets/herdr/mods}/muster/main.js | 0 {mods => targets/herdr/mods}/muster/mod.json | 0 {mods => targets/herdr/mods}/muster/pane.js | 0 .../herdr/mods}/muster/runbook.js | 0 .../herdr/mods}/muster/sidebar.js | 0 {mods => targets/herdr/mods}/muster/state.js | 2 +- {mods => targets/herdr/mods}/muster/stats.js | 0 {mods => targets/herdr/mods}/muster/status.js | 0 .../herdr/themes}/muster-day.json | 0 {themes => targets/herdr/themes}/muster.json | 0 {service/test => tests}/install.test.ts | 6 ++-- {service/test => tests}/mcp.test.ts | 6 ++-- {service/test => tests}/projects.test.ts | 2 +- {service/test => tests}/skill.test.ts | 8 ++--- {service/test => tests}/store.test.ts | 6 ++-- service/tsconfig.json => tsconfig.json | 3 +- 71 files changed, 86 insertions(+), 98 deletions(-) rename {service/src => app}/api.ts (100%) rename {service/src => app}/db.ts (100%) rename {service/src => app}/instructions.ts (100%) rename {service/src => app}/mcp.ts (100%) rename {service/src => app}/paths.ts (100%) rename {service/src => app}/projects.ts (100%) rename {service/src => app}/runbook.ts (100%) rename {service/src => app}/skill-content.ts (99%) rename {service/src => app}/skill.ts (100%) rename {service/src => app}/store.ts (100%) rename {service/src => app}/util.ts (100%) rename {service/src => app}/version.ts (100%) rename service/bun.lock => bun.lock (97%) rename service/src/cli.ts => cli.ts (98%) rename service/src/install.ts => install.ts (70%) rename {service => scripts}/build-herdr-assets.ts (77%) rename {service => scripts}/build-skill.ts (84%) delete mode 100644 service/package.json rename {service/src/installer => targets/herdr}/assets.ts (95%) rename service/src/installer/herdr.ts => targets/herdr/installer.ts (92%) rename keys.json => targets/herdr/keys.json (100%) rename {layouts => targets/herdr/layouts}/muster.json (100%) rename {mods => targets/herdr/mods}/muster/bell.js (100%) rename {mods => targets/herdr/mods}/muster/board.js (100%) rename {mods => targets/herdr/mods}/muster/brand.js (100%) rename {mods => targets/herdr/mods}/muster/cards.js (100%) rename {mods => targets/herdr/mods}/muster/footer.js (100%) rename {mods => targets/herdr/mods}/muster/gpui-kit.d.ts (100%) rename {mods => targets/herdr/mods}/muster/helpers.js (100%) rename {mods => targets/herdr/mods}/muster/icons/alert.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/arrow-up-right.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/bell.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/board.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/book.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/branch.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/cards.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/chart.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/check.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/chevron-right.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/clock.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/inbox.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/maximize.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/refresh.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/send.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/split-down.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/split-right.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/terminal.svg (100%) rename {mods => targets/herdr/mods}/muster/icons/x.svg (100%) rename {mods => targets/herdr/mods}/muster/jsconfig.json (100%) rename {mods => targets/herdr/mods}/muster/kit.js (100%) rename {mods => targets/herdr/mods}/muster/main.js (100%) rename {mods => targets/herdr/mods}/muster/mod.json (100%) rename {mods => targets/herdr/mods}/muster/pane.js (100%) rename {mods => targets/herdr/mods}/muster/runbook.js (100%) rename {mods => targets/herdr/mods}/muster/sidebar.js (100%) rename {mods => targets/herdr/mods}/muster/state.js (98%) rename {mods => targets/herdr/mods}/muster/stats.js (100%) rename {mods => targets/herdr/mods}/muster/status.js (100%) rename {themes => targets/herdr/themes}/muster-day.json (100%) rename {themes => targets/herdr/themes}/muster.json (100%) rename {service/test => tests}/install.test.ts (96%) rename {service/test => tests}/mcp.test.ts (98%) rename {service/test => tests}/projects.test.ts (99%) rename {service/test => tests}/skill.test.ts (86%) rename {service/test => tests}/store.test.ts (97%) rename service/tsconfig.json => tsconfig.json (69%) diff --git a/.gitignore b/.gitignore index 921508d..bb771f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Dependencies node_modules/ -service/node_modules/ # Local configuration and credentials .env @@ -22,7 +21,7 @@ muster.db # Build output bin/muster.exe -service/dist/ +dist/ # Editor / OS .vscode/settings.json diff --git a/AGENTS.md b/AGENTS.md index 2180e41..c4e1c71 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,18 +2,18 @@ ## Project Structure & Module Organization -Muster is a Herdr package backed by a local Bun and SQLite service. Service code is in `service/src/`: `store.ts` owns persistence, `api.ts` shares operations, and `cli.ts` and `mcp.ts` expose them. Tests live in `service/test/`. The Herdr views and SVG icons are in `mods/muster/`; layout and theme definitions are in `layouts/` and `themes/`. `keys.json` contains bindings, `service/src/installer/` installs the Herdr package, and `SPEC.md` documents shared contracts. +Muster is a Bun and SQLite app with a CLI, MCP server and Herdr target. Shared app code is in `app/`: `store.ts` owns persistence, `api.ts` shares operations, and `mcp.ts` serves MCP. Root `cli.ts` is the entry point and `install.ts` dispatches installation targets. `targets/herdr/` owns its installer, mod, SVG icons, layout, themes and bindings. Tests live in `tests/`; `SPEC.md` documents shared contracts. ## Build, Test, and Development Commands -Run service commands from `service/` with Bun 1.1 or newer: +Run commands from the repository root with Bun 1.1 or newer: - `bun test` runs the service test suite. - `bun install` installs development dependencies for type checking. - `bun run typecheck` runs TypeScript without emitting files. - `bun run muster -- version` runs the CLI; `bun run mcp` starts its stdio MCP server. -From the repository root, `herdr-app check mods\muster` checks the mod. Run `muster install` to install the Herdr package; use `--app-home DIR`, `--muster-home DIR`, or `--no-keys` when needed. Run `bun run build-herdr-assets.ts` in `service/` after changing Herdr assets. +`herdr-app check targets\herdr\mods\muster` checks the mod. Run `muster install` to install the Herdr package; use `--app-home DIR`, `--muster-home DIR`, or `--no-keys` when needed. Run `bun run build-herdr-assets` after changing Herdr assets and `bun run build-skill` after changing skill files. ## Coding Style & Naming Conventions @@ -21,7 +21,7 @@ Follow nearby TypeScript and JavaScript: two-space indentation, double-quoted st ## Testing Guidelines -Use Bun's `bun:test` and name service tests `*.test.ts` under `service/test/`. Add focused coverage for behavior changes, especially project identity, store operations and MCP contracts. Use temporary directories and isolated `MUSTER_HOME`/`MUSTER_DB` values; do not touch a real user database. Run `bun test` and `bun run typecheck` before submitting service changes. No coverage threshold is specified. +Use Bun's `bun:test` and name tests `*.test.ts` under `tests/`. Add focused coverage for behavior changes, especially project identity, store operations and MCP contracts. Use temporary directories and isolated `MUSTER_HOME`/`MUSTER_DB` values; do not touch a real user database. Run `bun test` and `bun run typecheck` before submitting app changes. No coverage threshold is specified. ## Commits & Pull Requests diff --git a/README.md b/README.md index e6012b0..02c1674 100644 --- a/README.md +++ b/README.md @@ -172,9 +172,9 @@ muster skill [skill|cli|mcp|cards|all] or `all` to read guides. Other arguments search all bundled skill files, for example `muster skill pending`. MCP clients can read `muster://skill` or use `muster://skill?section=pending`. The resource template is -`muster://skill{?section}`. These guides are embedded in the service and -compiled executable; regenerate them with `bun run build-skill.ts` in -`service/` after editing `.agents/skills/muster/`. +`muster://skill{?section}`. These guides are embedded in the app and +compiled executable; regenerate them with `bun run build-skill` after editing +`.agents/skills/muster/`. Add `--json` to any command for machine output. `--path` resolves a project from another folder; `--project` uses a project key directly. `MUSTER_HOME` @@ -217,25 +217,22 @@ the file stays where it is. Never put secrets in a card, note or event. ## Repository layout ```text -themes/ muster.json (dark), muster-day.json (light) -layouts/ muster.json -keys.json the layout:muster bindings -mods/muster/ one mod, one view per props.app -service/ Bun service: SQLite store, CLI, MCP server, tests -docs/ agent snippet and this package's notes -service/src/installer/ Herdr installation and embedded assets -SPEC.md the model, the wire formats and the decisions +cli.ts, install.ts command-line entry point and install dispatcher +app/ SQLite store, project logic, skill and MCP server +targets/herdr/ Herdr installer, themes, layout, mod and bindings +tests/ app and installation tests +scripts/ embedded asset and skill generators +docs/ agent snippet and package notes +SPEC.md model, wire formats and decisions ``` ## Development ```powershell -cd service -bun test # 33 tests: project resolution, store, MCP protocol -bun install # only for the type checker +bun install # development dependencies, including the type checker +bun test # application and installer tests bun run typecheck -cd .. -herdr-app check mods\muster +herdr-app check targets\herdr\mods\muster ``` The tests use temporary folders and never touch `%LOCALAPPDATA%\Muster`. @@ -244,6 +241,6 @@ The tests use temporary folders and never touch `%LOCALAPPDATA%\Muster`. v1 is the board, cards, runbooks and stats. Deferred: inbox and mail integrations, CI status, monitors, remote/shared stores, and any host-specific -assumptions such as unix sockets, `sh -c`, `lsof` or `sips`. The service is +assumptions such as unix sockets, `sh -c`, `lsof` or `sips`. The app is plain TypeScript on Bun, so a hosted or remote store can be added behind the same CLI and MCP surface later. diff --git a/SPEC.md b/SPEC.md index 491e7e3..ea2d693 100644 --- a/SPEC.md +++ b/SPEC.md @@ -340,13 +340,13 @@ except protocol messages is written to stdout; logs go to stderr. - Server name: `muster`. Supports MCP `2025-06-18`, `2025-03-26` and `2024-11-05`; an unknown requested version falls back to the newest. -- Advertises tools, plus empty resources and prompts. Implements `initialize`, - `ping`, `tools/list`, `tools/call`, the empty resource/prompt lists, +- Advertises tools and the `muster://skill` resource and section template, with + an empty prompts list. Implements `initialize`, `ping`, tool and resource calls, `logging/setLevel`, and the usual notifications. - Requests are processed in order because `ask_human` and `await_card` may block for up to 120 seconds. - The `initialize` result carries `MUSTER_INSTRUCTIONS` (see - `service/src/instructions.ts` and `docs/agents-snippet.md`). + `app/instructions.ts` and `docs/agents-snippet.md`). - Run identity prefers explicit tool parameters, then `MUSTER_PATH` / `MUSTER_AGENT` / `MUSTER_CLIENT`, `MUSTER_TERMINAL`, `HERDR_TERMINAL_ID`, then the server's working folder. @@ -381,7 +381,7 @@ instruction not to invent an answer. /themes/muster-day.json light theme /layouts/muster.json the layout /mods/muster/ the mod (JS, mod.json, icons) -/service/ the Bun service (src, package.json) +/muster/ the bundled CLI or standalone executable /muster.json the mod's install record /muster.db the SQLite database ``` @@ -396,17 +396,17 @@ The mod cannot read environment variables, so the installer writes: ```json { "command": "bun", - "prefix": ["C:\\Users\\you\\.config\\herdr-app\\service\\src\\cli.ts"], + "prefix": ["C:\\Users\\you\\.config\\herdr-app\\muster\\cli.js"], "db": "C:\\Users\\you\\AppData\\Local\\Muster\\muster.db", "version": "0.1.0" } ``` `state.js` reads it from `appHome()/muster.json`. If it is missing it falls back -to `bun /service/src/cli.ts`. `db` is prepended as `--db ` so +to `bun /muster/cli.js`. `db` is prepended as `--db ` so the window and the CLI always agree, even when `LOCALAPPDATA` differs. With -`-Compile`, `command` points at `/bin/muster.exe` and `prefix` is -empty. +the standalone binary, `command` points at the copy in `/muster/` +and `prefix` is empty. The mod runs the CLI through `exec(command, [...prefix, ...args])`; it never uses `sh -c` or environment injection. @@ -477,7 +477,7 @@ Commands are broadcast to every mounted view; each copy drains the queue with for project membership. - Git is invoked with `spawnSync(..., { windowsHide: true, timeout: 10s })`. - `.muster.json` discovery walks from a drive folder to its root. -- The installer is PowerShell (`install.ps1`), merges keys with a timestamped +- `muster install` merges keys with a timestamped backup, and leaves existing bindings alone. - The service also runs on macOS and Linux; `%LOCALAPPDATA%` becomes `XDG_DATA_HOME`. diff --git a/service/src/api.ts b/app/api.ts similarity index 100% rename from service/src/api.ts rename to app/api.ts diff --git a/service/src/db.ts b/app/db.ts similarity index 100% rename from service/src/db.ts rename to app/db.ts diff --git a/service/src/instructions.ts b/app/instructions.ts similarity index 100% rename from service/src/instructions.ts rename to app/instructions.ts diff --git a/service/src/mcp.ts b/app/mcp.ts similarity index 100% rename from service/src/mcp.ts rename to app/mcp.ts diff --git a/service/src/paths.ts b/app/paths.ts similarity index 100% rename from service/src/paths.ts rename to app/paths.ts diff --git a/service/src/projects.ts b/app/projects.ts similarity index 100% rename from service/src/projects.ts rename to app/projects.ts diff --git a/service/src/runbook.ts b/app/runbook.ts similarity index 100% rename from service/src/runbook.ts rename to app/runbook.ts diff --git a/service/src/skill-content.ts b/app/skill-content.ts similarity index 99% rename from service/src/skill-content.ts rename to app/skill-content.ts index 2ceb9a5..ae99805 100644 --- a/service/src/skill-content.ts +++ b/app/skill-content.ts @@ -1,5 +1,5 @@ // Generated from .agents/skills/muster/*.md. Do not edit by hand. -// Regenerate with: bun run build-skill.ts [--src DIR] [--out FILE] +// Regenerate with: bun run scripts/build-skill.ts [--src DIR] [--out FILE] export const SKILL_SECTIONS: Record = { "skill": `--- diff --git a/service/src/skill.ts b/app/skill.ts similarity index 100% rename from service/src/skill.ts rename to app/skill.ts diff --git a/service/src/store.ts b/app/store.ts similarity index 100% rename from service/src/store.ts rename to app/store.ts diff --git a/service/src/util.ts b/app/util.ts similarity index 100% rename from service/src/util.ts rename to app/util.ts diff --git a/service/src/version.ts b/app/version.ts similarity index 100% rename from service/src/version.ts rename to app/version.ts diff --git a/service/bun.lock b/bun.lock similarity index 97% rename from service/bun.lock rename to bun.lock index 7c93ba4..353163a 100644 --- a/service/bun.lock +++ b/bun.lock @@ -3,7 +3,7 @@ "configVersion": 1, "workspaces": { "": { - "name": "@muster/service", + "name": "muster-agent", "devDependencies": { "@types/bun": "^1.2.0", "typescript": "^5.7.0", diff --git a/service/src/cli.ts b/cli.ts similarity index 98% rename from service/src/cli.ts rename to cli.ts index ef0e8ab..1d27e74 100644 --- a/service/src/cli.ts +++ b/cli.ts @@ -28,12 +28,12 @@ import { snapshotView, statsView, whoami, -} from "./api.ts"; -import { initMarker, resolveProject } from "./projects.ts"; -import { skillText } from "./skill.ts"; -import { listProjects as readProjects, type CardState, type RunState, type StepState } from "./store.ts"; -import { ageText, plural } from "./util.ts"; -import { MUSTER_VERSION } from "./version.ts"; +} from "./app/api.ts"; +import { initMarker, resolveProject } from "./app/projects.ts"; +import { skillText } from "./app/skill.ts"; +import { listProjects as readProjects, type CardState, type RunState, type StepState } from "./app/store.ts"; +import { ageText, plural } from "./app/util.ts"; +import { MUSTER_VERSION } from "./app/version.ts"; const BOOLEAN = new Set(["json", "force", "help", "version", "all", "live", "quiet", "no-keys"]); const REPEATED = new Set(["action", "choice", "ref", "state"]); @@ -547,7 +547,7 @@ async function main(): Promise { return; } case "projects": { - const rows = readProjects((await import("./db.ts")).getDb()); + const rows = readProjects((await import("./app/db.ts")).getDb()); emit(rows, () => { for (const row of rows) console.log(`${row.name.padEnd(22)} ${row.key} ${row.source}`); }); @@ -573,7 +573,7 @@ async function main(): Promise { return; } case "mcp": { - const { startMcp } = await import("./mcp.ts"); + const { startMcp } = await import("./app/mcp.ts"); await startMcp(); return; } diff --git a/service/src/install.ts b/install.ts similarity index 70% rename from service/src/install.ts rename to install.ts index ca6568e..4fe4717 100644 --- a/service/src/install.ts +++ b/install.ts @@ -1,5 +1,5 @@ -import { MusterError } from "./store.ts"; -import { installHerdr, type HerdrInstallOptions } from "./installer/herdr.ts"; +import { MusterError } from "./app/store.ts"; +import { installHerdr, type HerdrInstallOptions } from "./targets/herdr/installer.ts"; /** Dispatch installation targets; Herdr is the default target. */ export async function install(target: string, options: HerdrInstallOptions) { diff --git a/package.json b/package.json index dedf03e..3c46746 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,18 @@ "type": "module", "description": "Muster CLI and MCP server for project-scoped agent coordination.", "bin": { - "muster": "./service/src/cli.ts" + "muster": "./cli.ts" + }, + "scripts": { + "muster": "bun run cli.ts", + "mcp": "bun run cli.ts mcp", + "build-herdr-assets": "bun run scripts/build-herdr-assets.ts", + "build-skill": "bun run scripts/build-skill.ts", + "test": "bun test", + "typecheck": "tsc --noEmit" + }, + "devDependencies": { + "@types/bun": "^1.2.0", + "typescript": "^5.7.0" } } diff --git a/service/build-herdr-assets.ts b/scripts/build-herdr-assets.ts similarity index 77% rename from service/build-herdr-assets.ts rename to scripts/build-herdr-assets.ts index 47b2de7..097aaaa 100644 --- a/service/build-herdr-assets.ts +++ b/scripts/build-herdr-assets.ts @@ -3,8 +3,8 @@ import { readdirSync, readFileSync, mkdirSync, writeFileSync } from "node:fs"; import { dirname, relative, resolve } from "node:path"; -const root = resolve(import.meta.dir, ".."); -const out = resolve(import.meta.dir, "src/installer/assets.ts"); +const root = resolve(import.meta.dir, "../targets/herdr"); +const out = resolve(root, "assets.ts"); const paths = ["themes/muster.json", "themes/muster-day.json", "layouts/muster.json", "keys.json"]; const mod = resolve(root, "mods/muster"); for (const entry of readdirSync(mod, { withFileTypes: true })) { @@ -16,5 +16,5 @@ for (const entry of readdirSync(resolve(mod, "icons"), { withFileTypes: true })) paths.sort(); const assets = Object.fromEntries(paths.map((path) => [path, readFileSync(resolve(root, path), "utf8")])); mkdirSync(dirname(out), { recursive: true }); -writeFileSync(out, `// Generated by bun run build-herdr-assets.ts; do not edit.\nexport const HERDR_ASSETS: Record = ${JSON.stringify(assets, null, 2)};\n`); +writeFileSync(out, `// Generated by bun run build-herdr-assets; do not edit.\nexport const HERDR_ASSETS: Record = ${JSON.stringify(assets, null, 2)};\n`); console.log(`wrote ${relative(root, out)} (${paths.length} assets)`); diff --git a/service/build-skill.ts b/scripts/build-skill.ts similarity index 84% rename from service/build-skill.ts rename to scripts/build-skill.ts index 476e6b1..c47c2f9 100644 --- a/service/build-skill.ts +++ b/scripts/build-skill.ts @@ -1,13 +1,13 @@ #!/usr/bin/env bun -// Regenerate service/src/skill-content.ts from the skill markdown files. -// Usage: bun run build-skill.ts [--src DIR] [--out FILE] +// Regenerate app/skill-content.ts from the skill markdown files. +// Usage: bun run scripts/build-skill.ts [--src DIR] [--out FILE] import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs"; import { resolve, dirname } from "node:path"; const args = process.argv.slice(2); let src = resolve(import.meta.dir, "../.agents/skills/muster"); -let out = resolve(import.meta.dir, "src/skill-content.ts"); +let out = resolve(import.meta.dir, "../app/skill-content.ts"); for (let i = 0; i < args.length; i++) { if (args[i] === "--src") src = resolve(args[++i] ?? ""); else if (args[i] === "--out") out = resolve(args[++i] ?? ""); @@ -32,7 +32,7 @@ function escape(value: string): string { } const body = `// Generated from .agents/skills/muster/*.md. Do not edit by hand. -// Regenerate with: bun run build-skill.ts [--src DIR] [--out FILE] +// Regenerate with: bun run scripts/build-skill.ts [--src DIR] [--out FILE] export const SKILL_SECTIONS: Record = { ${Object.entries(sections) diff --git a/service/package.json b/service/package.json deleted file mode 100644 index f1e51bf..0000000 --- a/service/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@muster/service", - "version": "0.1.0", - "private": true, - "type": "module", - "description": "Muster's local store, CLI and MCP server.", - "bin": { - "muster": "./src/cli.ts" - }, - "scripts": { - "muster": "bun run src/cli.ts", - "mcp": "bun run src/cli.ts mcp", - "build-herdr-assets": "bun run build-herdr-assets.ts", - "test": "bun test", - "typecheck": "tsc --noEmit" - }, - "devDependencies": { - "@types/bun": "^1.2.0", - "typescript": "^5.7.0" - } -} diff --git a/service/src/installer/assets.ts b/targets/herdr/assets.ts similarity index 95% rename from service/src/installer/assets.ts rename to targets/herdr/assets.ts index f887d60..9d2d251 100644 --- a/service/src/installer/assets.ts +++ b/targets/herdr/assets.ts @@ -1,4 +1,4 @@ -// Generated by bun run build-herdr-assets.ts; do not edit. +// Generated by bun run build-herdr-assets; do not edit. export const HERDR_ASSETS: Record = { "keys.json": "{\n \"layout:muster\": {\n \"ctrl-shift-1\": \"muster.go:board\",\n \"ctrl-shift-2\": \"muster.go:cards\",\n \"ctrl-shift-3\": \"muster.go:runbook\",\n \"ctrl-shift-4\": \"muster.go:stats\",\n \"ctrl-shift-5\": \"muster.go:work\",\n \"ctrl-shift-m\": \"muster.next\",\n \"ctrl-shift-r\": \"muster.refresh\"\n }\n}\n", "layouts/muster.json": "{\n \"id\": \"root\",\n \"type\": \"row\",\n \"titlebar\": \"none\",\n \"traffic_lights\": [12, 16],\n \"background\": \"chrome\",\n \"terminal_padding\": [14, 12],\n \"divider\": { \"width\": 1, \"color\": \"border\" },\n \"theme\": { \"light\": \"muster-day\", \"dark\": \"muster\" },\n \"children\": [\n {\n \"id\": \"sidebar\",\n \"type\": \"column\",\n \"size\": { \"px\": 268 },\n \"min\": 216,\n \"max\": 420,\n \"background\": \"chrome\",\n \"resizable\": true,\n \"children\": [\n {\n \"id\": \"brand\",\n \"type\": \"block\",\n \"size\": { \"px\": 46 },\n \"window_drag\": true,\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"brand\" } }\n },\n {\n \"id\": \"muster-sidebar\",\n \"type\": \"block\",\n \"size\": { \"weight\": 1 },\n \"min\": 140,\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"sidebar\" } }\n },\n {\n \"id\": \"sidebar-footer\",\n \"type\": \"block\",\n \"size\": { \"px\": 74 },\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"footer\" } }\n }\n ]\n },\n {\n \"id\": \"main-area\",\n \"type\": \"column\",\n \"padding\": 6,\n \"gap\": 4,\n \"children\": [\n {\n \"id\": \"topbar\",\n \"type\": \"row\",\n \"size\": { \"px\": 42 },\n \"resizable\": false,\n \"children\": [\n { \"id\": \"tabs\", \"type\": \"block\", \"window_drag\": true, \"content\": { \"mod\": \"tabs\" } },\n {\n \"id\": \"bell\",\n \"type\": \"block\",\n \"size\": { \"px\": 52 },\n \"window_drag\": true,\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"bell\" } }\n }\n ]\n },\n {\n \"id\": \"center\",\n \"type\": \"stack\",\n \"active\": \"board\",\n \"background\": \"canvas\",\n \"children\": [\n {\n \"id\": \"board\",\n \"type\": \"block\",\n \"radius\": 10,\n \"border\": { \"width\": 1, \"color\": \"border\" },\n \"background\": \"background\",\n \"shadow\": \"sm\",\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"board\" } }\n },\n {\n \"id\": \"cards\",\n \"type\": \"block\",\n \"radius\": 10,\n \"border\": { \"width\": 1, \"color\": \"border\" },\n \"background\": \"background\",\n \"shadow\": \"sm\",\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"cards\" } }\n },\n {\n \"id\": \"runbook\",\n \"type\": \"block\",\n \"radius\": 10,\n \"border\": { \"width\": 1, \"color\": \"border\" },\n \"background\": \"background\",\n \"shadow\": \"sm\",\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"runbook\" } }\n },\n {\n \"id\": \"stats\",\n \"type\": \"block\",\n \"radius\": 10,\n \"border\": { \"width\": 1, \"color\": \"border\" },\n \"background\": \"background\",\n \"shadow\": \"sm\",\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"stats\" } }\n },\n {\n \"id\": \"work\",\n \"type\": \"row\",\n \"padding\": 0,\n \"gap\": 6,\n \"children\": [\n {\n \"id\": \"view\",\n \"type\": \"stack\",\n \"active\": \"main\",\n \"children\": [\n {\n \"id\": \"main\",\n \"type\": \"block\",\n \"content\": {\n \"tab\": \"active\",\n \"pane\": {\n \"gap\": 6,\n \"radius\": 10,\n \"background\": \"background\",\n \"lone\": true,\n \"border\": { \"width\": 1, \"color\": \"border\" },\n \"focus\": { \"width\": 1, \"color\": \"solid\" },\n \"header\": {\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"pane\" } },\n \"height\": 30,\n \"position\": \"top\",\n \"reveal\": \"always\"\n }\n }\n }\n }\n ]\n }\n ]\n }\n ]\n },\n {\n \"id\": \"status\",\n \"type\": \"block\",\n \"size\": { \"px\": 28 },\n \"content\": { \"mod\": \"muster\", \"props\": { \"app\": \"status\" } }\n }\n ]\n }\n ]\n}\n", @@ -33,7 +33,7 @@ export const HERDR_ASSETS: Record = { "mods/muster/pane.js": "// A terminal's header in the Muster layout: the project the pane's folder\n// belongs to, its branch, the agent's live state, and the pane controls that\n// stay out of the way until the pointer arrives.\n\nimport { div } from \"gpui-kit\";\nimport { h_flex } from \"gpui-base\";\nimport { panes, props, run } from \"herdr\";\nimport { liveRuns, select, setProject, snapshot, subscribe } from \"./state.js\";\nimport { colors, Dot, Icon, ProjectMark, R, stateColor, T } from \"./kit.js\";import { shortHome } from \"./helpers.js\";\n\nconst clean = (path) => (path ?? \"\").replace(/[\\\\/]+/g, \"/\").replace(/\\/+$/, \"\").toLowerCase();\n\nfunction projectFor(rows, cwd) {\n const here = clean(cwd);\n if (!here) return null;\n let best = null;\n for (const row of rows) {\n const root = clean(row.root);\n if (!root) continue;\n if (here === root || here.startsWith(`${root}/`)) {\n if (!best || root.length > clean(best.root).length) best = row;\n }\n }\n return best;\n}\n\nexport default class Pane {\n init(_props, cx) {\n this.hovered = false;\n this.sub = subscribe(cx, () => cx.notify());\n }\n\n close() {\n this.sub?.stop();\n }\n\n me() {\n return panes().find((pane) => pane.pane === props()?.pane) ?? null;\n }\n\n button(k, id, icon, tip, onPress) {\n return h_flex().id(id).flex_none().size(20).items_center().justify_center().rounded(4)\n .cursor_pointer().tooltip(tip).hover((s) => s.bg(k.hover))\n .on_click((_event, cx) => {\n cx?.stop_propagation?.();\n onPress();\n })\n .child(Icon(icon, { size: 12, color: k.muted }));\n }\n\n render() {\n const k = colors();\n const pane = this.me();\n if (!pane) return div();\n const snap = snapshot();\n const row = snap ? projectFor(snap.board ?? [], pane.cwd) : null;\n const run = row ? liveRuns(snap).filter((entry) => entry.projectId === row.id).sort((a, b) => Date.parse(b.heartbeatAt) - Date.parse(a.heartbeatAt))[0] ?? null : null;\n const tone = run ? stateColor(run.state, k) : row?.color ?? k.dim;\n const title = pane.program?.agent || pane.program?.shell ? pane.program?.name : pane.title || pane.program?.name || pane.mod || \"shell\";\n\n return h_flex().id(`muster-pane-${pane.pane}`).size_full().px(10).gap(7).items_center()\n .bg(k.background).border_b(1).border_color(k.border).text_size(T.sm)\n .on_hover((hovered, cx) => {\n this.hovered = hovered;\n cx.notify();\n })\n .on_click(() => run(\"pane.focus\", { pane: pane.pane }))\n .when(Boolean(row), (el) =>\n el\n .child(ProjectMark(row.name, row.color, { size: 18 }))\n .child(\n h_flex().flex_none().items_center().gap(5).cursor_pointer().tooltip(\"Open this project's cards\")\n .on_click((_event, cx) => {\n cx?.stop_propagation?.();\n setProject(row.key);\n select(\"cards\");\n })\n .child(div().text_size(T.sm).text_color(k.foreground).child(row.name)),\n )\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(row.key)),\n )\n .when(!row, (el) =>\n el\n .child(Icon(\"terminal\", { size: 13, color: k.dim }))\n .child(div().flex_none().max_w(180).truncate().text_color(k.foreground).child(title)),\n )\n .child(\n div().flex_1().min_w(0).truncate().text_size(T.xs).text_color(k.dim)\n .tooltip(pane.cwd ?? \"\")\n .child(shortHome(pane.cwd ?? \"\")),\n )\n .when(Boolean(row?.branch), (el) =>\n el.child(\n h_flex().flex_none().h(18).items_center().gap(4).px(6).rounded(R.pill).bg(k.raised)\n .text_color(k.dim).text_size(T.xs)\n .child(Icon(\"branch\", { size: 10, color: k.dim }))\n .child(div().max_w(160).truncate().child(row.branch)),\n ),\n )\n .when(Boolean(run), (el) =>\n el\n .child(Dot({ color: tone, size: 6 }))\n .child(\n div().flex_none().max_w(220).truncate().text_size(T.xs).text_color(tone).tooltip(run.summary ?? run.state)\n .child(run.summary || run.state),\n ),\n )\n .when(this.hovered, (el) =>\n el.child(\n h_flex().flex_none().gap(1).items_center()\n .child(this.button(k, `muster-pane-${pane.pane}-right`, \"split-right\", \"Split right\", () => run(\"pane.split\", { direction: \"right\", pane: pane.pane })))\n .child(this.button(k, `muster-pane-${pane.pane}-down`, \"split-down\", \"Split down\", () => run(\"pane.split\", { direction: \"down\", pane: pane.pane })))\n .child(this.button(k, `muster-pane-${pane.pane}-zoom`, \"maximize\", \"Zoom\", () => run(\"pane.zoom\", { pane: pane.pane })))\n .child(this.button(k, `muster-pane-${pane.pane}-close`, \"x\", \"Close\", () => run(\"pane.close\", { pane: pane.pane }))),\n ),\n );\n }\n}\n", "mods/muster/runbook.js": "// Runbooks: the ordered steps a project has agreed to. A runbook is imported\n// from markdown, and re-importing keeps step state. Every press moves one step\n// through the CLI, so an agent sees the same state the window shows.\n\nimport { div } from \"gpui-kit\";\nimport { h_flex, v_flex } from \"gpui-base\";\nimport { call, refresh, selectedProject, snapshot, subscribe } from \"./state.js\";\nimport { Action, age, alpha, colors, Empty, G, Icon, ProjectMark, R, T } from \"./kit.js\";\nimport { stateIcon } from \"./helpers.js\";\n\nfunction joinPath(root, file) {\n if (/^[A-Za-z]:[\\\\/]/.test(file) || file.startsWith(\"\\\\\\\\\") || file.startsWith(\"/\")) return file;\n return `${root.replace(/[\\\\/]+$/, \"\")}/${file.replace(/^[\\\\/]+/, \"\")}`;\n}\n\nfunction progressTone(k, done, total) {\n if (!total || done === 0) return k.muted;\n return done === total ? k.done : k.working;\n}\n\nexport default class Runbook {\n init(_props, cx) {\n this.busy = null;\n this.error = null;\n this.notice = null;\n this.seq = 0;\n this.sub = subscribe(cx, () => cx.notify());\n }\n\n close() {\n this.sub?.stop();\n }\n\n async act(cx, label, work) {\n if (this.busy) return;\n const token = ++this.seq;\n this.busy = label;\n this.error = null;\n this.notice = null;\n cx.notify();\n try {\n await work();\n await refresh(true);\n this.notice = label;\n } catch (error) {\n this.error = String(error?.message ?? error);\n } finally {\n this.busy = null;\n cx.notify();\n cx.timer.after(3200, () => {\n if (this.seq === token && !this.busy) {\n this.notice = null;\n cx.notify();\n }\n });\n }\n }\n\n sync(cx, project) {\n if (!project?.runbook) return;\n return this.act(cx, `Imported ${project.runbook}`, () =>\n call([\"runbook\", \"import\", joinPath(project.root, project.runbook), \"--project\", project.key]),\n );\n }\n\n setStep(cx, book, step, state) {\n if (step.state === state) return;\n return this.act(cx, `${book.slug} step ${step.n} ${state}`, () =>\n call([\"runbook\", \"step\", String(step.n), state, \"--slug\", book.slug, \"--project\", book.projectKey]),\n );\n }\n\n render(cx) {\n const k = colors();\n const snap = snapshot();\n if (!snap) {\n return v_flex().size_full().items_center().justify_center()\n .child(div().text_size(T.base).text_color(k.muted).child(\"Reading runbooks…\"));\n }\n\n const selectedKey = selectedProject(snap);\n const projects = snap.board ?? [];\n const books = snap.runbooks ?? [];\n const selectedProjectRow = projects.find((row) => row.key === selectedKey) ?? null;\n const groups = new Map();\n for (const book of books) {\n const list = groups.get(book.projectKey) ?? [];\n list.push(book);\n groups.set(book.projectKey, list);\n }\n const ordered = [...groups.entries()].sort(([a], [b]) => {\n if (a === selectedKey) return -1;\n if (b === selectedKey) return 1;\n return (groups.get(a)?.[0]?.projectName ?? a).localeCompare(groups.get(b)?.[0]?.projectName ?? b);\n });\n\n const status = this.error\n ? { color: k.blocked, icon: \"alert\", text: this.error }\n : this.busy\n ? { color: k.working, icon: \"clock\", text: `${this.busy}…` }\n : this.notice\n ? { color: k.done, icon: \"check\", text: this.notice }\n : null;\n\n return v_flex().size_full().min_h(0)\n .child(\n h_flex().flex_none().w_full().items_end().gap(G.md).p(G.lg).pb(G.sm)\n .child(\n v_flex().flex_1().min_w(0).gap(2)\n .child(div().text_size(T.xl).text_color(k.foreground).child(\"Runbooks\"))\n .child(\n div().text_size(T.sm).text_color(k.dim)\n .child(\n books.length\n ? `${books.length} ${books.length === 1 ? \"runbook\" : \"runbooks\"} · ${projects.length} ${projects.length === 1 ? \"project\" : \"projects\"}`\n : \"No runbooks imported yet\",\n ),\n ),\n )\n .when(Boolean(selectedProjectRow?.runbook), (el) =>\n el.child(\n Action(\"muster-runbook-sync\", \"Sync marker\", {\n style: \"secondary\",\n icon: \"refresh\",\n onPress: () => this.sync(cx, selectedProjectRow),\n }).tooltip(`Re-import ${selectedProjectRow?.runbook}`),\n ),\n )\n .child(\n Action(\"muster-runbook-refresh\", \"Refresh\", {\n style: \"ghost\",\n icon: \"refresh\",\n onPress: () => refresh(true).then(() => cx.notify()).catch(() => cx.notify()),\n }),\n ),\n )\n .when(Boolean(status), (el) =>\n el.child(\n h_flex().flex_none().w_full().items_center().gap(6).px(G.lg).pb(G.sm)\n .child(Icon(status.icon, { size: 12, color: status.color }))\n .child(div().flex_1().min_w(0).truncate().text_size(T.xs).text_color(status.color).tooltip(status.text).child(status.text)),\n ),\n )\n .when(books.length === 0, (el) =>\n el.child(\n Empty({\n icon: \"book\",\n title: \"No runbook yet\",\n detail: selectedProjectRow?.runbook\n ? `Add “runbook”: “${selectedProjectRow.runbook}” to .muster.json, then refresh or sync.`\n : \"Add a \\\"runbook\\\" path to .muster.json, or ask the agent to call muster_runbook_import.\",\n action: selectedProjectRow?.runbook\n ? Action(\"muster-runbook-import\", \"Import from marker\", {\n style: \"primary\",\n icon: \"refresh\",\n onPress: () => this.sync(cx, selectedProjectRow),\n })\n : null,\n }),\n ),\n )\n .when(books.length > 0, (el) =>\n el.child(\n v_flex().id(\"muster-runbooks\").flex_1().min_h(0).w_full().overflow_y_scrollbar()\n .px(G.lg).pb(G.lg).gap(G.lg)\n .children(\n ordered.map(([projectKey, projectBooks]) =>\n v_flex().w_full().gap(G.sm)\n .child(\n h_flex().w_full().items_center().gap(G.sm)\n .child(ProjectMark(projectBooks[0]?.projectName ?? projectKey, projectBooks[0]?.color, { size: 20 }))\n .child(div().text_size(T.sm).text_color(k.foreground).child(projectBooks[0]?.projectName ?? projectKey))\n .child(div().text_size(T.xs).text_color(k.dim).child(projectKey))\n .child(div().flex_1())\n .when(projectKey === selectedKey, (row) =>\n row.child(div().text_size(T.xs).text_color(k.dim).child(\"selected\")),\n ),\n )\n .children(projectBooks.map((book) => this.book(cx, k, book))),\n ),\n ),\n ),\n );\n }\n\n book(cx, k, book) {\n const steps = book.steps ?? [];\n const done = steps.filter((step) => step.state === \"done\").length;\n const skipped = steps.filter((step) => step.state === \"skipped\").length;\n const total = steps.length;\n const percent = total ? Math.round(((done + skipped) / total) * 100) : 0;\n const tone = progressTone(k, done, total);\n\n return v_flex().flex_none().w_full().rounded(R.card).border_1().border_color(k.border)\n .bg(k.background).overflow_hidden()\n .child(\n h_flex().w_full().items_center().gap(G.sm).p(G.md)\n .child(\n v_flex().flex_1().min_w(0).gap(2)\n .child(\n h_flex().items_center().gap(7)\n .child(div().truncate().text_size(T.base).text_color(k.foreground).child(book.title))\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(book.slug)),\n )\n .child(\n h_flex().items_center().gap(6)\n .child(\n div().flex_none().text_size(T.xs).text_color(k.dim)\n .child(`${done}/${total} done${skipped ? ` · ${skipped} skipped` : \"\"}`),\n )\n .when(Boolean(book.sourcePath), (row) =>\n row\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"·\"))\n .child(\n div().flex_none().max_w(340).truncate().text_size(T.xs).text_color(k.dim)\n .tooltip(book.sourcePath).child(book.sourcePath),\n ),\n )\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(`· ${age(book.updatedAt)}`)),\n ),\n )\n .child(\n h_flex().flex_none().w(110).h(4).rounded(2).bg(k.border).overflow_hidden()\n .child(div().h_full().w(`${percent}%`).bg(tone)),\n )\n .child(div().flex_none().w(30).text_size(T.xs).text_color(tone).child(`${percent}%`)),\n )\n .when(steps.length === 0, (el) =>\n el.child(div().px(G.md).pb(G.md).text_size(T.sm).text_color(k.dim).child(\"This runbook has no steps.\")),\n )\n .when(steps.length > 0, (el) =>\n el.child(\n v_flex().w_full()\n .children(\n steps.map((step, index) => {\n const activeTone = step.state === \"done\" ? k.done : step.state === \"blocked\" ? k.blocked : step.state === \"doing\" ? k.working : k.dim;\n const mark = stateIcon(step.state);\n return v_flex().id(`muster-step-${book.projectKey}-${book.slug}-${step.n}`).w_full().gap(4).px(G.md).py(7)\n .when(index > 0, (row) => row.border_t(1).border_color(k.border))\n .hover((s) => s.bg(k.hover))\n .child(\n h_flex().w_full().items_center().gap(G.sm)\n .child(\n div().flex_none().size(18).rounded(5)\n .bg(alpha(activeTone, 0.12)).flex().items_center().justify_center()\n .when(Boolean(mark), (tile) => tile.child(Icon(mark, { size: 11, color: activeTone })))\n .when(!mark, (tile) => tile.child(div().size(5).rounded_full().bg(activeTone))),\n )\n .child(div().flex_none().w(18).text_size(T.xs).text_color(k.dim).child(String(step.n)))\n .child(\n div().flex_1().min_w(0).truncate().text_size(T.sm)\n .text_color(step.state === \"done\" || step.state === \"skipped\" ? k.muted : k.foreground)\n .child(step.title),\n )\n .when(Boolean(step.command), (row) =>\n row.child(\n div().flex_none().max_w(340).truncate().text_size(T.xs).text_color(k.dim)\n .tooltip(step.command).child(`$ ${step.command.split(\"\\n\")[0]}`),\n ),\n )\n .child(div().flex_none().w(4))\n .child(this.stepAction(k, `${step.n}-doing`, \"clock\", \"Doing\", step.state === \"doing\", () => this.setStep(cx, book, step, \"doing\")))\n .child(this.stepAction(k, `${step.n}-done`, \"check\", \"Done\", step.state === \"done\", () => this.setStep(cx, book, step, \"done\")))\n .child(this.stepAction(k, `${step.n}-blocked`, \"alert\", \"Blocked\", step.state === \"blocked\", () => this.setStep(cx, book, step, \"blocked\")))\n .child(this.stepAction(k, `${step.n}-skipped`, \"chevron-right\", \"Skipped\", step.state === \"skipped\", () => this.setStep(cx, book, step, \"skipped\")))\n .child(this.stepAction(k, `${step.n}-todo`, \"refresh\", \"Back to todo\", step.state === \"todo\", () => this.setStep(cx, book, step, \"todo\"))),\n )\n .when(Boolean(step.note), (row) =>\n row.child(\n h_flex().w_full().pl(50).gap(6)\n .child(Icon(\"cards\", { size: 10, color: k.dim }))\n .child(div().flex_1().min_w(0).text_size(T.xs).text_color(k.dim).child(step.note)),\n ),\n );\n }),\n ),\n ),\n );\n }\n\n stepAction(k, id, icon, tip, active, onPress) {\n return h_flex().id(`muster-step-${id}`).flex_none().size(20).items_center().justify_center()\n .rounded(4).cursor_pointer().tooltip(tip)\n .bg(active ? alpha(k.accent, 0.16) : \"transparent\")\n .hover((s) => s.bg(active ? alpha(k.accent, 0.22) : k.hover))\n .on_click(() => onPress())\n .child(Icon(icon, { size: 11, color: active ? k.accent : k.dim }));\n }\n}\n", "mods/muster/sidebar.js": "// The sidebar: the five places Muster shows, every project it knows, and the\n// runs that are live right now. Rows are quiet until a number needs you.\n\nimport { div } from \"gpui-kit\";\nimport { h_flex, v_flex } from \"gpui-base\";\nimport {\n activeView,\n liveRuns,\n needs,\n selectedProject,\n select,\n setCard,\n setProject,\n snapshot,\n subscribe,\n} from \"./state.js\";\nimport { age, colors, count, Dot, G, Icon, Pill, ProjectMark, R, T } from \"./kit.js\";\n\nfunction navRow(k, active, icon, label, badge, onPress) {\n return h_flex().id(`muster-nav-${label.toLowerCase()}`).flex_none().h(28).items_center().gap(9)\n .px(8).rounded(R.control).cursor_pointer()\n .bg(active ? k.selected : \"transparent\")\n .hover((s) => s.bg(active ? k.selected : k.hover))\n .on_click(onPress)\n .child(Icon(icon, { size: 14, color: active ? k.foreground : k.muted }))\n .child(div().flex_1().min_w(0).truncate().text_size(T.sm).text_color(active ? k.foreground : k.muted).child(label))\n .when(badge > 0, (el) => el.child(div().text_size(T.xs).text_color(k.dim).child(String(badge))));\n}\n\nexport default class Sidebar {\n init(_props, cx) {\n this.sub = subscribe(cx, () => cx.notify());\n }\n\n close() {\n this.sub?.stop();\n }\n\n render() {\n const k = colors();\n const snap = snapshot();\n const active = activeView();\n const key = selectedProject(snap);\n const waiting = needs(snap).length;\n const cards = (snap?.cards ?? []).filter((card) => [\"open\", \"claimed\"].includes(card.state));\n const runs = liveRuns(snap);\n const projects = snap?.board ?? [];\n const books = snap?.runbooks ?? [];\n\n return v_flex().size_full().min_h(0).bg(k.chrome)\n .child(\n v_flex().flex_none().p(G.xs + 2).gap(1)\n .child(navRow(k, active === \"board\", \"board\", \"Board\", 0, () => select(\"board\")))\n .child(navRow(k, active === \"cards\", \"cards\", \"Cards\", waiting || cards.length, () => select(\"cards\")))\n .child(navRow(k, active === \"runbook\", \"book\", \"Runbook\", books.length, () => select(\"runbook\")))\n .child(navRow(k, active === \"stats\", \"chart\", \"Stats\", 0, () => select(\"stats\")))\n .child(navRow(k, active === \"work\", \"terminal\", \"Terminals\", runs.length, () => select(\"work\"))),\n )\n .child(div().flex_none().h(1).mx(G.md).bg(k.border))\n .child(\n h_flex().flex_none().items_center().justify_between().px(G.md).pt(G.md).pb(G.xs)\n .child(div().text_size(T.xs).text_color(k.dim).child(\"Projects\"))\n .child(div().text_size(T.xs).text_color(k.dim).child(String(projects.length))),\n )\n .child(\n v_flex().id(\"muster-projects\").flex_1().min_h(0).overflow_y_scrollbar().px(G.xs + 2).pb(G.sm).gap(1)\n .when(projects.length === 0, (el) =>\n el.child(\n div().px(G.sm).py(G.sm).text_size(T.sm).text_color(k.dim)\n .child(\"Open a repository and run `muster whoami`, then refresh.\"),\n ),\n )\n .children(\n projects.map((row) => {\n const current = row.key === key;\n return h_flex().id(`muster-project-${row.key}`).flex_none().items_center().gap(G.sm)\n .px(7).py(6).rounded(R.control).cursor_pointer()\n .bg(current ? k.selected : \"transparent\")\n .hover((s) => s.bg(current ? k.selected : k.hover))\n .on_click(() => {\n setProject(row.key);\n setCard(null);\n select(\"cards\");\n })\n .child(ProjectMark(row.name, row.color, { size: 20 }))\n .child(\n v_flex().flex_1().min_w(0).gap(1)\n .child(div().truncate().text_size(T.sm).text_color(current ? k.foreground : k.muted).child(row.name))\n .child(\n div().truncate().text_size(T.xs).text_color(k.dim)\n .child(row.branch ?? row.next?.label ?? row.source),\n ),\n )\n .when(row.needs > 0, (el) => el.child(Pill(String(row.needs), { tone: k.blocked })))\n .when(row.needs === 0 && row.liveRuns > 0, (el) =>\n el.child(div().flex_none().pr(2).child(Dot({ color: k.working }))),\n )\n .when(row.needs === 0 && row.liveRuns === 0, (el) =>\n el.child(div().flex_none().text_size(T.xs).text_color(k.dim).child(age(row.lastAt))),\n );\n }),\n ),\n )\n .when(runs.length > 0, (el) =>\n el\n .child(div().flex_none().h(1).mx(G.md).bg(k.border))\n .child(\n v_flex().flex_none().px(G.md).pt(G.sm).pb(G.xs).gap(1)\n .child(\n h_flex().flex_none().items_center().justify_between()\n .child(div().text_size(T.xs).text_color(k.dim).child(\"Live runs\"))\n .child(div().text_size(T.xs).text_color(k.dim).child(String(runs.length))),\n )\n .children(\n runs.slice(0, 4).map((run) => {\n const project = projects.find((row) => row.id === run.projectId);\n return h_flex().id(`muster-run-${run.id}`).flex_none().items_center().gap(7).py(3)\n .cursor_pointer().rounded(R.control).hover((s) => s.bg(k.hover))\n .on_click(() => {\n if (project) {\n setProject(project.key);\n select(\"work\");\n }\n })\n .child(Dot({ color: run.state === \"blocked\" ? k.blocked : run.state === \"done\" ? k.done : k.working, size: 6 }))\n .child(div().flex_1().min_w(0).truncate().text_size(T.xs).text_color(k.muted).child(run.agent ?? run.terminal ?? \"agent\"))\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(count(project?.liveRuns ?? 0, \"run\")))\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(age(run.heartbeatAt)));\n }),\n ),\n ),\n )\n .child(div().flex_none().h(G.sm));\n }\n}\n", - "mods/muster/state.js": "// One snapshot shared by every Muster view. The mods run in Herdr's JS\n// runtime, so the store is reached through the `muster` CLI; the config the\n// installer writes (`{command, prefix, db?}`) says how to start it. A single\n// global keeps every mounted block on the same snapshot and one in-flight\n// process.\n\nimport { exec, appHome, readTextFile, shared, setShared, run } from \"herdr\";\n\nconst KEY = \"__musterStore\";\nconst CONFIG_KEY = \"__musterConfig\";\nconst SUCCESS_TTL = 2500;\nconst CONFIG_TTL = 5000;\n\nfunction store() {\n return (globalThis[KEY] ??= {\n snapshot: null,\n error: null,\n at: 0,\n loading: false,\n inflight: null,\n listeners: new Set(),\n });\n}\n\nexport function snapshot() {\n return store().snapshot;\n}\n\nexport function lastError() {\n return store().error;\n}\n\n/** The install record: `{ command, prefix, db? }`, falling back to Bun beside the app home. */\nexport async function config() {\n const cached = globalThis[CONFIG_KEY];\n if (cached && Date.now() - cached.at < CONFIG_TTL) return cached.value;\n let value = null;\n try {\n const text = await readTextFile(`${appHome()}/muster.json`);\n if (text) value = JSON.parse(text);\n } catch {\n // fall back below\n }\n value ??= { command: \"bun\", prefix: [`${appHome()}/service/muster/cli.js`] };\n if (!value.command) value.command = \"bun\";\n if (!Array.isArray(value.prefix)) value.prefix = [];\n globalThis[CONFIG_KEY] = { at: Date.now(), value };\n return value;\n}\n\n/** Runs a `muster` subcommand and returns stdout. Throws with stderr on failure. */\nexport async function call(args, options = {}) {\n const cfg = await config();\n const full = cfg.db ? [\"--db\", cfg.db, ...args] : args;\n const r = await exec(cfg.command, [...cfg.prefix, ...full], options.cwd ? { cwd: options.cwd } : undefined);\n if (r?.code !== 0) {\n const detail = String(r?.stderr || r?.stdout || \"\").trim();\n throw new Error(detail || `muster exited ${r?.code ?? \"?\"}`);\n }\n return String(r?.stdout ?? \"\");\n}\n\nasync function readSnapshot() {\n const text = await call([\"snapshot\", \"--json\"], { cwd: appHome() });\n return JSON.parse(text);\n}\n\nfunction settle() {\n const s = store();\n for (const entry of s.listeners) {\n try {\n entry.fn(entry.cx);\n } catch {\n // A view that is closing must not stop the others.\n }\n }\n}\n\n/** Reads a fresh snapshot, deduping concurrent callers. */\nexport function refresh(force = false) {\n const s = store();\n if (s.inflight) return s.inflight;\n if (!force && s.snapshot && Date.now() - s.at < SUCCESS_TTL) return Promise.resolve(s.snapshot);\n s.loading = true;\n s.inflight = readSnapshot()\n .then((value) => {\n s.snapshot = value;\n s.error = null;\n s.at = Date.now();\n return value;\n })\n .catch((error) => {\n s.error = String(error?.message ?? error);\n throw error;\n })\n .finally(() => {\n s.loading = false;\n s.inflight = null;\n settle();\n });\n return s.inflight;\n}\n\n/** Subscribes a view: one notify now and every refresh after. */\nexport function subscribe(cx, fn) {\n const s = store();\n const entry = { cx, fn };\n s.listeners.add(entry);\n cx.timer.every(3000, () => {\n refresh().catch(() => {});\n });\n refresh().catch(() => {});\n return {\n stop() {\n s.listeners.delete(entry);\n },\n };\n}\n\n/** The selected project key, or the first project the snapshot knows. */\nexport function selectedProject(snap = snapshot()) {\n const key = shared(\"muster.project\");\n if (key && snap?.board?.some((row) => row.key === key)) return key;\n return snap?.board?.[0]?.key ?? snap?.runbooks?.[0]?.projectKey ?? null;\n}\n\nexport function setProject(key) {\n setShared(\"muster.project\", key ?? null);\n}\n\nexport function selectedCard(snap = snapshot()) {\n const id = shared(\"muster.card\");\n if (id && snap?.cards?.some((card) => card.id === id)) return id;\n return null;\n}\n\nexport function setCard(id) {\n setShared(\"muster.card\", id ?? null);\n}\n\n/** The center view the person last chose. */\nexport function activeView() {\n return shared(\"muster.view\") ?? \"board\";\n}\n\nexport function setView(child) {\n setShared(\"muster.view\", child);\n}\n\n/** Move the center stack and remember it. */\nexport function select(child) {\n setView(child);\n run(\"layout.select\", { stack: \"center\", child });\n}\n\n/** Open a card in the cards view. */\nexport function openCard(card) {\n if (!card) return;\n setCard(card.id);\n if (card.project?.key) setProject(card.project.key);\n select(\"cards\");\n}\n\n/** Open a card by id when the snapshot may not carry the whole card. */\nexport function openCardId(projectKey, cardId) {\n if (cardId) setCard(cardId);\n if (projectKey) setProject(projectKey);\n select(\"cards\");\n}\n\nexport function projectRow(key, snap = snapshot()) {\n return snap?.board?.find((row) => row.key === key) ?? null;\n}\n\nexport function needs(snap = snapshot()) {\n return (snap?.cards ?? []).filter(\n (card) =>\n [\"open\", \"claimed\"].includes(card.state) &&\n ([\"question\", \"approval\"].includes(card.kind) || [\"blocked\", \"attention\"].includes(card.severity)),\n );\n}\n\nexport function liveRuns(snap = snapshot()) {\n return (snap?.runs ?? []).filter((run) => !run.endedAt);\n}\n\n/** The next thing that needs a person: a waiting card, else the first open one. */\nexport function nextCard(snap = snapshot()) {\n const waiting = needs(snap);\n if (waiting.length) return waiting[0];\n return (snap?.cards ?? []).find((card) => [\"open\", \"claimed\"].includes(card.state)) ?? null;\n}\n", + "mods/muster/state.js": "// One snapshot shared by every Muster view. The mods run in Herdr's JS\n// runtime, so the store is reached through the `muster` CLI; the config the\n// installer writes (`{command, prefix, db?}`) says how to start it. A single\n// global keeps every mounted block on the same snapshot and one in-flight\n// process.\n\nimport { exec, appHome, readTextFile, shared, setShared, run } from \"herdr\";\n\nconst KEY = \"__musterStore\";\nconst CONFIG_KEY = \"__musterConfig\";\nconst SUCCESS_TTL = 2500;\nconst CONFIG_TTL = 5000;\n\nfunction store() {\n return (globalThis[KEY] ??= {\n snapshot: null,\n error: null,\n at: 0,\n loading: false,\n inflight: null,\n listeners: new Set(),\n });\n}\n\nexport function snapshot() {\n return store().snapshot;\n}\n\nexport function lastError() {\n return store().error;\n}\n\n/** The install record: `{ command, prefix, db? }`, falling back to Bun beside the app home. */\nexport async function config() {\n const cached = globalThis[CONFIG_KEY];\n if (cached && Date.now() - cached.at < CONFIG_TTL) return cached.value;\n let value = null;\n try {\n const text = await readTextFile(`${appHome()}/muster.json`);\n if (text) value = JSON.parse(text);\n } catch {\n // fall back below\n }\n value ??= { command: \"bun\", prefix: [`${appHome()}/muster/cli.js`] };\n if (!value.command) value.command = \"bun\";\n if (!Array.isArray(value.prefix)) value.prefix = [];\n globalThis[CONFIG_KEY] = { at: Date.now(), value };\n return value;\n}\n\n/** Runs a `muster` subcommand and returns stdout. Throws with stderr on failure. */\nexport async function call(args, options = {}) {\n const cfg = await config();\n const full = cfg.db ? [\"--db\", cfg.db, ...args] : args;\n const r = await exec(cfg.command, [...cfg.prefix, ...full], options.cwd ? { cwd: options.cwd } : undefined);\n if (r?.code !== 0) {\n const detail = String(r?.stderr || r?.stdout || \"\").trim();\n throw new Error(detail || `muster exited ${r?.code ?? \"?\"}`);\n }\n return String(r?.stdout ?? \"\");\n}\n\nasync function readSnapshot() {\n const text = await call([\"snapshot\", \"--json\"], { cwd: appHome() });\n return JSON.parse(text);\n}\n\nfunction settle() {\n const s = store();\n for (const entry of s.listeners) {\n try {\n entry.fn(entry.cx);\n } catch {\n // A view that is closing must not stop the others.\n }\n }\n}\n\n/** Reads a fresh snapshot, deduping concurrent callers. */\nexport function refresh(force = false) {\n const s = store();\n if (s.inflight) return s.inflight;\n if (!force && s.snapshot && Date.now() - s.at < SUCCESS_TTL) return Promise.resolve(s.snapshot);\n s.loading = true;\n s.inflight = readSnapshot()\n .then((value) => {\n s.snapshot = value;\n s.error = null;\n s.at = Date.now();\n return value;\n })\n .catch((error) => {\n s.error = String(error?.message ?? error);\n throw error;\n })\n .finally(() => {\n s.loading = false;\n s.inflight = null;\n settle();\n });\n return s.inflight;\n}\n\n/** Subscribes a view: one notify now and every refresh after. */\nexport function subscribe(cx, fn) {\n const s = store();\n const entry = { cx, fn };\n s.listeners.add(entry);\n cx.timer.every(3000, () => {\n refresh().catch(() => {});\n });\n refresh().catch(() => {});\n return {\n stop() {\n s.listeners.delete(entry);\n },\n };\n}\n\n/** The selected project key, or the first project the snapshot knows. */\nexport function selectedProject(snap = snapshot()) {\n const key = shared(\"muster.project\");\n if (key && snap?.board?.some((row) => row.key === key)) return key;\n return snap?.board?.[0]?.key ?? snap?.runbooks?.[0]?.projectKey ?? null;\n}\n\nexport function setProject(key) {\n setShared(\"muster.project\", key ?? null);\n}\n\nexport function selectedCard(snap = snapshot()) {\n const id = shared(\"muster.card\");\n if (id && snap?.cards?.some((card) => card.id === id)) return id;\n return null;\n}\n\nexport function setCard(id) {\n setShared(\"muster.card\", id ?? null);\n}\n\n/** The center view the person last chose. */\nexport function activeView() {\n return shared(\"muster.view\") ?? \"board\";\n}\n\nexport function setView(child) {\n setShared(\"muster.view\", child);\n}\n\n/** Move the center stack and remember it. */\nexport function select(child) {\n setView(child);\n run(\"layout.select\", { stack: \"center\", child });\n}\n\n/** Open a card in the cards view. */\nexport function openCard(card) {\n if (!card) return;\n setCard(card.id);\n if (card.project?.key) setProject(card.project.key);\n select(\"cards\");\n}\n\n/** Open a card by id when the snapshot may not carry the whole card. */\nexport function openCardId(projectKey, cardId) {\n if (cardId) setCard(cardId);\n if (projectKey) setProject(projectKey);\n select(\"cards\");\n}\n\nexport function projectRow(key, snap = snapshot()) {\n return snap?.board?.find((row) => row.key === key) ?? null;\n}\n\nexport function needs(snap = snapshot()) {\n return (snap?.cards ?? []).filter(\n (card) =>\n [\"open\", \"claimed\"].includes(card.state) &&\n ([\"question\", \"approval\"].includes(card.kind) || [\"blocked\", \"attention\"].includes(card.severity)),\n );\n}\n\nexport function liveRuns(snap = snapshot()) {\n return (snap?.runs ?? []).filter((run) => !run.endedAt);\n}\n\n/** The next thing that needs a person: a waiting card, else the first open one. */\nexport function nextCard(snap = snapshot()) {\n const waiting = needs(snap);\n if (waiting.length) return waiting[0];\n return (snap?.cards ?? []).find((card) => [\"open\", \"claimed\"].includes(card.state)) ?? null;\n}\n", "mods/muster/stats.js": "// Stats: the quiet numbers that say whether attention is moving. Counts come\n// from the snapshot, the activity series is the last two weeks, and every\n// project row is a shortcut back to its cards.\n\nimport { div } from \"gpui-kit\";\nimport { h_flex, v_flex } from \"gpui-base\";\nimport { refresh, select, setCard, setProject, snapshot, subscribe } from \"./state.js\";\nimport {\n Action,\n age,\n alpha,\n colors,\n Empty,\n G,\n Icon,\n Metric,\n ProjectMark,\n R,\n T,\n} from \"./kit.js\";\n\nfunction duration(seconds) {\n if (seconds === null || seconds === undefined) return \"—\";\n if (seconds < 60) return `${Math.round(seconds)}s`;\n if (seconds < 3600) return `${Math.round(seconds / 60)}m`;\n if (seconds < 86_400) return `${(seconds / 3600).toFixed(1)}h`;\n return `${(seconds / 86_400).toFixed(1)}d`;\n}\n\nfunction shortDate(date) {\n const parts = String(date).split(\"-\");\n return parts.length === 3 ? `${Number(parts[1])}/${Number(parts[2])}` : date;\n}\n\nfunction panel(k, title, right, children) {\n return v_flex().flex_none().w_full().rounded(R.card).border_1().border_color(k.border)\n .bg(k.background).overflow_hidden()\n .child(\n h_flex().w_full().items_center().gap(G.sm).px(G.md).py(G.sm).border_b(1).border_color(k.border)\n .child(div().flex_1().text_size(T.xs).text_color(k.dim).child(title))\n .when(Boolean(right), (row) => row.child(right)),\n )\n .child(children);\n}\n\nexport default class Stats {\n init(_props, cx) {\n this.sub = subscribe(cx, () => cx.notify());\n }\n\n close() {\n this.sub?.stop();\n }\n\n render(cx) {\n const k = colors();\n const snap = snapshot();\n if (!snap) {\n return v_flex().size_full().items_center().justify_center()\n .child(div().text_size(T.base).text_color(k.muted).child(\"Reading stats…\"));\n }\n\n const stats = snap.stats;\n const totals = stats.totals;\n const response = stats.response;\n const days = stats.windowDays;\n const activity = stats.activity ?? [];\n const peak = activity.reduce((max, day) => Math.max(max, day.count), 0);\n const events = activity.reduce((sum, day) => sum + day.count, 0);\n const projects = stats.projects ?? [];\n const today = new Date().toISOString().slice(0, 10);\n\n const breakdown = (title, data, tone) => {\n const rows = Object.entries(data ?? {}).sort((a, b) => b[1] - a[1]);\n const max = rows.reduce((top, [, count]) => Math.max(top, count), 0);\n return panel(\n k,\n title,\n div().text_size(T.xs).text_color(k.dim).child(String(rows.reduce((sum, [, count]) => sum + count, 0))),\n v_flex().w_full().p(G.md).gap(6)\n .when(rows.length === 0, (el) => el.child(div().text_size(T.sm).text_color(k.dim).child(\"Nothing counted yet.\")))\n .children(\n rows.map(([label, count]) =>\n h_flex().w_full().items_center().gap(G.sm)\n .child(div().flex_none().w(72).text_size(T.xs).text_color(k.muted).child(label))\n .child(\n h_flex().flex_1().h(4).rounded(2).bg(k.border).overflow_hidden()\n .child(div().h_full().w(`${max ? Math.round((count / max) * 100) : 0}%`).bg(tone)),\n )\n .child(div().flex_none().w(26).text_size(T.xs).text_color(k.dim).child(String(count))),\n ),\n ),\n );\n };\n\n return v_flex().size_full().min_h(0)\n .child(\n h_flex().flex_none().w_full().items_end().gap(G.md).p(G.lg).pb(G.sm)\n .child(\n v_flex().flex_1().min_w(0).gap(2)\n .child(div().text_size(T.xl).text_color(k.foreground).child(\"Stats\"))\n .child(\n div().text_size(T.sm).text_color(k.dim)\n .child(`${days} day window · ${events} ${events === 1 ? \"event\" : \"events\"} · updated ${age(stats.generatedAt)}`),\n ),\n )\n .child(\n Action(\"muster-stats-refresh\", \"Refresh\", {\n style: \"ghost\",\n icon: \"refresh\",\n onPress: () => refresh(true).then(() => cx.notify()).catch(() => cx.notify()),\n }),\n ),\n )\n .child(\n v_flex().id(\"muster-stats\").flex_1().min_h(0).w_full().overflow_y_scrollbar().px(G.lg).pb(G.lg).gap(G.md)\n .child(\n h_flex().w_full().rounded(R.card).border_1().border_color(k.border).bg(k.background).items_center()\n .child(Metric(\"Need you\", totals.cardsNeeds, { color: totals.cardsNeeds > 0 ? k.blocked : k.foreground }))\n .child(div().flex_none().w(1).h(30).bg(k.border))\n .child(Metric(\"Open cards\", totals.cardsOpen))\n .child(div().flex_none().w(1).h(30).bg(k.border))\n .child(Metric(\"Answered\", totals.cardsAnswered, { color: totals.cardsAnswered > 0 ? k.done : k.foreground }))\n .child(div().flex_none().w(1).h(30).bg(k.border))\n .child(Metric(\"Median answer\", duration(response.medianSeconds), { detail: `p90 ${duration(response.p90Seconds)}` }))\n .child(div().flex_none().w(1).h(30).bg(k.border))\n .child(Metric(\"Live runs\", totals.runsLive, { detail: `${totals.agentsBlocked} blocked`, color: totals.agentsBlocked > 0 ? k.blocked : k.foreground }))\n .child(div().flex_none().w(1).h(30).bg(k.border))\n .child(Metric(\"Projects\", totals.projects)),\n )\n .child(\n panel(\n k,\n `Activity · ${days} days`,\n div().text_size(T.xs).text_color(k.dim).child(`${events} total`),\n h_flex().w_full().items_end().gap(4).px(G.md).pt(G.md).pb(G.sm).h(104)\n .children(\n activity.map((day) => {\n const height = peak ? Math.max(3, Math.round((day.count / peak) * 62)) : 3;\n const isToday = day.date === today;\n return v_flex().id(`muster-activity-${day.date}`).flex_1().min_w(0).items_center().justify_end().gap(4)\n .tooltip(`${shortDate(day.date)} · ${day.count} ${day.count === 1 ? \"event\" : \"events\"}`)\n .child(\n div().w_full().h(height).rounded(2)\n .bg(day.count === 0 ? k.border : isToday ? k.accent : alpha(k.accent, 0.45)),\n )\n .child(div().text_size(T.xs).text_color(isToday ? k.muted : k.dim).child(shortDate(day.date)));\n }),\n ),\n ),\n )\n .child(\n h_flex().w_full().gap(G.md).items_start()\n .child(div().flex_1().min_w(0).child(breakdown(\"Cards by state\", stats.cards.byState, alpha(k.accent, 0.7))))\n .child(div().flex_1().min_w(0).child(breakdown(\"Cards by kind\", stats.cards.byKind, alpha(k.working, 0.7)))),\n )\n .child(\n panel(\n k,\n \"Projects\",\n div().text_size(T.xs).text_color(k.dim).child(String(projects.length)),\n v_flex().w_full()\n .when(projects.length === 0, (el) =>\n el.child(\n Empty({ icon: \"board\", title: \"No projects yet\", detail: \"Run `muster whoami` in a repository.\" }),\n ),\n )\n .children(\n projects.map((row, index) =>\n h_flex().id(`muster-stats-project-${row.key}`).w_full().items_center().gap(G.sm).px(G.md).py(7)\n .when(index > 0, (line) => line.border_t(1).border_color(k.border))\n .cursor_pointer().hover((s) => s.bg(k.hover))\n .on_click(() => {\n setProject(row.key);\n setCard(null);\n select(\"cards\");\n })\n .child(ProjectMark(row.name, row.color, { size: 20 }))\n .child(div().flex_1().min_w(0).truncate().text_size(T.sm).text_color(k.foreground).child(row.name))\n .child(div().flex_none().w(64).text_size(T.xs).text_color(k.dim).child(`${row.open} open`))\n .child(\n div().flex_none().w(64).text_size(T.xs).text_color(row.needs > 0 ? k.blocked : k.dim)\n .child(`${row.needs} needs`),\n )\n .child(\n div().flex_none().w(58).text_size(T.xs).text_color(row.liveRuns > 0 ? k.working : k.dim)\n .child(`${row.liveRuns} live`),\n )\n .child(\n div().flex_none().w(74).text_size(T.xs).text_color(row.answered > 0 ? k.done : k.dim)\n .child(`${row.answered} answered`),\n )\n .child(div().flex_none().w(40).text_size(T.xs).text_color(k.dim).child(age(row.lastAt)))\n .child(Icon(\"chevron-right\", { size: 12, color: k.dim })),\n ),\n ),\n ),\n ),\n );\n }\n}\n", "mods/muster/status.js": "// The status bar: one quiet line. Where the selected project is on the left;\n// on the right, only what needs a person speaks up.\n\nimport { div } from \"gpui-kit\";\nimport { h_flex } from \"gpui-base\";\nimport {\n liveRuns,\n needs,\n nextCard,\n openCard,\n projectRow,\n selectedProject,\n select,\n snapshot,\n subscribe,\n} from \"./state.js\";\nimport { colors, Dot, G, Icon, stateColor, T } from \"./kit.js\";\nimport { runLine } from \"./helpers.js\";\n\nexport default class Status {\n init(_props, cx) {\n this.sub = subscribe(cx, () => cx.notify());\n }\n\n close() {\n this.sub?.stop();\n }\n\n render() {\n const k = colors();\n const snap = snapshot();\n const key = selectedProject(snap);\n const row = projectRow(key, snap);\n const waiting = needs(snap).length;\n const runs = liveRuns(snap);\n const mine = row ? runs.filter((run) => run.projectId === row.id) : runs;\n const run = mine.sort((a, b) => Date.parse(b.heartbeatAt) - Date.parse(a.heartbeatAt))[0] ?? null;\n const tone = run ? stateColor(run.state, k) : row?.color ?? k.dim;\n\n return h_flex().size_full().items_center().gap(G.sm).px(G.md).bg(k.chrome)\n .child(\n h_flex().flex_1().min_w(0).items_center().gap(7).cursor_pointer()\n .on_click(() => select(\"board\"))\n .child(Dot({ color: tone, size: 6 }))\n .child(\n div().flex_none().text_size(T.xs).text_color(row ? k.muted : k.dim)\n .child(row?.name ?? \"Muster\"),\n )\n .when(Boolean(run), (el) =>\n el\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"·\"))\n .child(div().flex_none().text_size(T.xs).text_color(tone).child(run.state))\n .when(Boolean(runLine(run)), (line) =>\n line\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"·\"))\n .child(\n div().flex_1().min_w(0).truncate().text_size(T.xs).text_color(k.dim)\n .child(runLine(run)),\n ),\n ),\n )\n .when(!run && Boolean(row), (el) =>\n el\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"·\"))\n .child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"no live run\")),\n ),\n )\n .when(waiting > 0, (el) =>\n el.child(\n h_flex().flex_none().items_center().gap(5).h(20).px(6).rounded(4).cursor_pointer()\n .hover((s) => s.bg(k.selected))\n .on_click(() => openCard(nextCard()))\n .child(Icon(\"bell\", { size: 11, color: k.blocked }))\n .child(\n div().text_size(T.xs).text_color(k.blocked)\n .child(`${waiting} ${waiting === 1 ? \"need\" : \"needs\"} you`),\n ),\n ),\n )\n .when(waiting === 0 && runs.length > 0, (el) =>\n el.child(\n h_flex().flex_none().items_center().gap(5)\n .child(Dot({ color: k.working, size: 5 }))\n .child(div().text_size(T.xs).text_color(k.dim).child(`${runs.length} live`)),\n ),\n )\n .when(waiting === 0 && runs.length === 0, (el) =>\n el.child(div().flex_none().text_size(T.xs).text_color(k.dim).child(\"All clear\")),\n );\n }\n}\n", "themes/muster-day.json": "{\n \"background\": \"#f4f0e6\",\n \"foreground\": \"#2f2b25\",\n \"selection\": \"#e4ddcc\",\n \"cursor\": \"#2f2b25\",\n \"ansi\": [\n \"#e6e1d6\", \"#9a5f57\", \"#5f7757\", \"#8a7136\", \"#5b7084\", \"#7c6874\", \"#557a74\", \"#5a564f\",\n \"#a9a397\", \"#b08079\", \"#7a8f70\", \"#a08a55\", \"#72869a\", \"#947f8c\", \"#6f8f89\", \"#2f2b25\"\n ],\n \"colors\": {\n \"canvas\": \"#eeeadf\",\n \"chrome\": \"#e9e4d8\",\n \"surface\": \"#f4f0e6\",\n \"popover\": \"#faf7ef\",\n \"raised\": \"#fbf9f3\",\n \"hover\": \"#ece6d9\",\n \"selected\": \"#e2dbca\",\n \"border\": \"#dcd5c4\",\n \"input\": \"#cec6b4\",\n \"foreground\": \"#2f2b25\",\n \"muted\": \"#6f695e\",\n \"dim\": \"#9a9285\",\n \"accent\": \"#66745b\",\n \"accent_foreground\": \"#fbf9f3\",\n \"solid\": \"#2f2b25\",\n \"solid_foreground\": \"#fbf9f3\",\n \"working\": \"#8a7136\",\n \"blocked\": \"#9a5f57\",\n \"done\": \"#5f7757\",\n \"idle\": \"#9a9285\",\n \"unknown\": \"#9a9285\"\n }\n}\n", diff --git a/service/src/installer/herdr.ts b/targets/herdr/installer.ts similarity index 92% rename from service/src/installer/herdr.ts rename to targets/herdr/installer.ts index dc69e29..b5f2b7c 100644 --- a/service/src/installer/herdr.ts +++ b/targets/herdr/installer.ts @@ -1,9 +1,9 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { basename, dirname, join, resolve } from "node:path"; -import { musterHome } from "../paths.ts"; -import { MusterError } from "../store.ts"; -import { MUSTER_VERSION } from "../version.ts"; +import { musterHome } from "../../app/paths.ts"; +import { MusterError } from "../../app/store.ts"; +import { MUSTER_VERSION } from "../../app/version.ts"; import { HERDR_ASSETS } from "./assets.ts"; export interface HerdrInstallOptions { @@ -56,14 +56,14 @@ export async function installHerdr(options: HerdrInstallOptions = {}) { const keysChanged = !options.noKeys && (existing === undefined || Object.keys(defaults).some((key) => !Object.hasOwn(existing as object, key))); if (keysChanged) keys["layout:muster"] = bindings; - const serviceDir = join(appHome, "service", "muster"); + const appDir = join(appHome, "muster"); const compiled = /(?:^|[\\/])(?:~BUN|\$bunfs)(?:[\\/]|$)/i.test(Bun.main); let command: string; let prefix: string[]; let bundle: Uint8Array | undefined; let binaryPath: string | undefined; if (compiled) { - binaryPath = join(serviceDir, basename(process.execPath)); + binaryPath = join(appDir, basename(process.execPath)); command = binaryPath; prefix = []; } else { @@ -71,7 +71,7 @@ export async function installHerdr(options: HerdrInstallOptions = {}) { if (!result.success || !result.outputs[0]) throw new MusterError("install_build", `Could not bundle Muster: ${result.logs.join("; ")}`); bundle = new Uint8Array(await result.outputs[0].arrayBuffer()); command = process.execPath; - prefix = [join(serviceDir, "cli.js")]; + prefix = [join(appDir, "cli.js")]; } const backups: string[] = []; @@ -84,7 +84,7 @@ export async function installHerdr(options: HerdrInstallOptions = {}) { mkdirSync(dirname(dest), { recursive: true }); writeFileSync(dest, content); } - mkdirSync(serviceDir, { recursive: true }); + mkdirSync(appDir, { recursive: true }); if (bundle) writeFileSync(prefix[0]!, bundle); if (binaryPath && resolve(process.execPath).toLowerCase() !== resolve(binaryPath).toLowerCase()) copyFileSync(process.execPath, binaryPath); mkdirSync(dataHome, { recursive: true }); diff --git a/keys.json b/targets/herdr/keys.json similarity index 100% rename from keys.json rename to targets/herdr/keys.json diff --git a/layouts/muster.json b/targets/herdr/layouts/muster.json similarity index 100% rename from layouts/muster.json rename to targets/herdr/layouts/muster.json diff --git a/mods/muster/bell.js b/targets/herdr/mods/muster/bell.js similarity index 100% rename from mods/muster/bell.js rename to targets/herdr/mods/muster/bell.js diff --git a/mods/muster/board.js b/targets/herdr/mods/muster/board.js similarity index 100% rename from mods/muster/board.js rename to targets/herdr/mods/muster/board.js diff --git a/mods/muster/brand.js b/targets/herdr/mods/muster/brand.js similarity index 100% rename from mods/muster/brand.js rename to targets/herdr/mods/muster/brand.js diff --git a/mods/muster/cards.js b/targets/herdr/mods/muster/cards.js similarity index 100% rename from mods/muster/cards.js rename to targets/herdr/mods/muster/cards.js diff --git a/mods/muster/footer.js b/targets/herdr/mods/muster/footer.js similarity index 100% rename from mods/muster/footer.js rename to targets/herdr/mods/muster/footer.js diff --git a/mods/muster/gpui-kit.d.ts b/targets/herdr/mods/muster/gpui-kit.d.ts similarity index 100% rename from mods/muster/gpui-kit.d.ts rename to targets/herdr/mods/muster/gpui-kit.d.ts diff --git a/mods/muster/helpers.js b/targets/herdr/mods/muster/helpers.js similarity index 100% rename from mods/muster/helpers.js rename to targets/herdr/mods/muster/helpers.js diff --git a/mods/muster/icons/alert.svg b/targets/herdr/mods/muster/icons/alert.svg similarity index 100% rename from mods/muster/icons/alert.svg rename to targets/herdr/mods/muster/icons/alert.svg diff --git a/mods/muster/icons/arrow-up-right.svg b/targets/herdr/mods/muster/icons/arrow-up-right.svg similarity index 100% rename from mods/muster/icons/arrow-up-right.svg rename to targets/herdr/mods/muster/icons/arrow-up-right.svg diff --git a/mods/muster/icons/bell.svg b/targets/herdr/mods/muster/icons/bell.svg similarity index 100% rename from mods/muster/icons/bell.svg rename to targets/herdr/mods/muster/icons/bell.svg diff --git a/mods/muster/icons/board.svg b/targets/herdr/mods/muster/icons/board.svg similarity index 100% rename from mods/muster/icons/board.svg rename to targets/herdr/mods/muster/icons/board.svg diff --git a/mods/muster/icons/book.svg b/targets/herdr/mods/muster/icons/book.svg similarity index 100% rename from mods/muster/icons/book.svg rename to targets/herdr/mods/muster/icons/book.svg diff --git a/mods/muster/icons/branch.svg b/targets/herdr/mods/muster/icons/branch.svg similarity index 100% rename from mods/muster/icons/branch.svg rename to targets/herdr/mods/muster/icons/branch.svg diff --git a/mods/muster/icons/cards.svg b/targets/herdr/mods/muster/icons/cards.svg similarity index 100% rename from mods/muster/icons/cards.svg rename to targets/herdr/mods/muster/icons/cards.svg diff --git a/mods/muster/icons/chart.svg b/targets/herdr/mods/muster/icons/chart.svg similarity index 100% rename from mods/muster/icons/chart.svg rename to targets/herdr/mods/muster/icons/chart.svg diff --git a/mods/muster/icons/check.svg b/targets/herdr/mods/muster/icons/check.svg similarity index 100% rename from mods/muster/icons/check.svg rename to targets/herdr/mods/muster/icons/check.svg diff --git a/mods/muster/icons/chevron-right.svg b/targets/herdr/mods/muster/icons/chevron-right.svg similarity index 100% rename from mods/muster/icons/chevron-right.svg rename to targets/herdr/mods/muster/icons/chevron-right.svg diff --git a/mods/muster/icons/clock.svg b/targets/herdr/mods/muster/icons/clock.svg similarity index 100% rename from mods/muster/icons/clock.svg rename to targets/herdr/mods/muster/icons/clock.svg diff --git a/mods/muster/icons/inbox.svg b/targets/herdr/mods/muster/icons/inbox.svg similarity index 100% rename from mods/muster/icons/inbox.svg rename to targets/herdr/mods/muster/icons/inbox.svg diff --git a/mods/muster/icons/maximize.svg b/targets/herdr/mods/muster/icons/maximize.svg similarity index 100% rename from mods/muster/icons/maximize.svg rename to targets/herdr/mods/muster/icons/maximize.svg diff --git a/mods/muster/icons/refresh.svg b/targets/herdr/mods/muster/icons/refresh.svg similarity index 100% rename from mods/muster/icons/refresh.svg rename to targets/herdr/mods/muster/icons/refresh.svg diff --git a/mods/muster/icons/send.svg b/targets/herdr/mods/muster/icons/send.svg similarity index 100% rename from mods/muster/icons/send.svg rename to targets/herdr/mods/muster/icons/send.svg diff --git a/mods/muster/icons/split-down.svg b/targets/herdr/mods/muster/icons/split-down.svg similarity index 100% rename from mods/muster/icons/split-down.svg rename to targets/herdr/mods/muster/icons/split-down.svg diff --git a/mods/muster/icons/split-right.svg b/targets/herdr/mods/muster/icons/split-right.svg similarity index 100% rename from mods/muster/icons/split-right.svg rename to targets/herdr/mods/muster/icons/split-right.svg diff --git a/mods/muster/icons/terminal.svg b/targets/herdr/mods/muster/icons/terminal.svg similarity index 100% rename from mods/muster/icons/terminal.svg rename to targets/herdr/mods/muster/icons/terminal.svg diff --git a/mods/muster/icons/x.svg b/targets/herdr/mods/muster/icons/x.svg similarity index 100% rename from mods/muster/icons/x.svg rename to targets/herdr/mods/muster/icons/x.svg diff --git a/mods/muster/jsconfig.json b/targets/herdr/mods/muster/jsconfig.json similarity index 100% rename from mods/muster/jsconfig.json rename to targets/herdr/mods/muster/jsconfig.json diff --git a/mods/muster/kit.js b/targets/herdr/mods/muster/kit.js similarity index 100% rename from mods/muster/kit.js rename to targets/herdr/mods/muster/kit.js diff --git a/mods/muster/main.js b/targets/herdr/mods/muster/main.js similarity index 100% rename from mods/muster/main.js rename to targets/herdr/mods/muster/main.js diff --git a/mods/muster/mod.json b/targets/herdr/mods/muster/mod.json similarity index 100% rename from mods/muster/mod.json rename to targets/herdr/mods/muster/mod.json diff --git a/mods/muster/pane.js b/targets/herdr/mods/muster/pane.js similarity index 100% rename from mods/muster/pane.js rename to targets/herdr/mods/muster/pane.js diff --git a/mods/muster/runbook.js b/targets/herdr/mods/muster/runbook.js similarity index 100% rename from mods/muster/runbook.js rename to targets/herdr/mods/muster/runbook.js diff --git a/mods/muster/sidebar.js b/targets/herdr/mods/muster/sidebar.js similarity index 100% rename from mods/muster/sidebar.js rename to targets/herdr/mods/muster/sidebar.js diff --git a/mods/muster/state.js b/targets/herdr/mods/muster/state.js similarity index 98% rename from mods/muster/state.js rename to targets/herdr/mods/muster/state.js index 4547c4e..4cce99a 100644 --- a/mods/muster/state.js +++ b/targets/herdr/mods/muster/state.js @@ -41,7 +41,7 @@ export async function config() { } catch { // fall back below } - value ??= { command: "bun", prefix: [`${appHome()}/service/muster/cli.js`] }; + value ??= { command: "bun", prefix: [`${appHome()}/muster/cli.js`] }; if (!value.command) value.command = "bun"; if (!Array.isArray(value.prefix)) value.prefix = []; globalThis[CONFIG_KEY] = { at: Date.now(), value }; diff --git a/mods/muster/stats.js b/targets/herdr/mods/muster/stats.js similarity index 100% rename from mods/muster/stats.js rename to targets/herdr/mods/muster/stats.js diff --git a/mods/muster/status.js b/targets/herdr/mods/muster/status.js similarity index 100% rename from mods/muster/status.js rename to targets/herdr/mods/muster/status.js diff --git a/themes/muster-day.json b/targets/herdr/themes/muster-day.json similarity index 100% rename from themes/muster-day.json rename to targets/herdr/themes/muster-day.json diff --git a/themes/muster.json b/targets/herdr/themes/muster.json similarity index 100% rename from themes/muster.json rename to targets/herdr/themes/muster.json diff --git a/service/test/install.test.ts b/tests/install.test.ts similarity index 96% rename from service/test/install.test.ts rename to tests/install.test.ts index e9611fe..8d35310 100644 --- a/service/test/install.test.ts +++ b/tests/install.test.ts @@ -3,10 +3,10 @@ import { spawnSync } from "node:child_process"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { HERDR_ASSETS } from "../src/installer/assets.ts"; +import { HERDR_ASSETS } from "../targets/herdr/assets.ts"; const root = mkdtempSync(join(tmpdir(), "muster-install-")); -const entry = join(import.meta.dir, "../src/cli.ts"); +const entry = join(import.meta.dir, "../cli.ts"); afterAll(() => rmSync(root, { recursive: true, force: true })); function run(...args: string[]) { @@ -65,7 +65,7 @@ describe("Herdr installation", () => { test("embedded assets match their repository sources", () => { for (const [path, content] of Object.entries(HERDR_ASSETS)) { - expect(content).toBe(readFileSync(join(import.meta.dir, "../..", path), "utf8")); + expect(content).toBe(readFileSync(join(import.meta.dir, "../targets/herdr", path), "utf8")); } }); }); diff --git a/service/test/mcp.test.ts b/tests/mcp.test.ts similarity index 98% rename from service/test/mcp.test.ts rename to tests/mcp.test.ts index 0d7ec42..f03d877 100644 --- a/service/test/mcp.test.ts +++ b/tests/mcp.test.ts @@ -2,9 +2,9 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { closeDb } from "../src/db.ts"; -import { answerCardById } from "../src/api.ts"; -import { handleMessage } from "../src/mcp.ts"; +import { closeDb } from "../app/db.ts"; +import { answerCardById } from "../app/api.ts"; +import { handleMessage } from "../app/mcp.ts"; let dir: string; let project: string; diff --git a/service/test/projects.test.ts b/tests/projects.test.ts similarity index 99% rename from service/test/projects.test.ts rename to tests/projects.test.ts index 32eb9c8..336eccd 100644 --- a/service/test/projects.test.ts +++ b/tests/projects.test.ts @@ -8,7 +8,7 @@ import { colorForKey, initMarker, resolveProject, -} from "../src/projects.ts"; +} from "../app/projects.ts"; function tempDir(label: string): string { return mkdtempSync(join(tmpdir(), `muster-${label}-`)); diff --git a/service/test/skill.test.ts b/tests/skill.test.ts similarity index 86% rename from service/test/skill.test.ts rename to tests/skill.test.ts index feb9b29..755ac62 100644 --- a/service/test/skill.test.ts +++ b/tests/skill.test.ts @@ -2,11 +2,11 @@ import { describe, expect, test } from "bun:test"; import { spawnSync } from "node:child_process"; import { readFileSync } from "node:fs"; import { join } from "node:path"; -import { skillText } from "../src/skill.ts"; -import { SKILL_SECTIONS } from "../src/skill-content.ts"; +import { skillText } from "../app/skill.ts"; +import { SKILL_SECTIONS } from "../app/skill-content.ts"; function cli(...args: string[]) { - return spawnSync(process.execPath, [join(import.meta.dir, "../src/cli.ts"), "skill", ...args], { encoding: "utf8" }); + return spawnSync(process.execPath, [join(import.meta.dir, "../cli.ts"), "skill", ...args], { encoding: "utf8" }); } describe("skill CLI", () => { @@ -33,7 +33,7 @@ describe("skill CLI", () => { test("embedded guides match their source files", () => { for (const [key, filename] of Object.entries({ skill: "SKILL.md", cli: "cli.md", mcp: "mcp.md", cards: "cards.md" })) { - expect(SKILL_SECTIONS[key]).toBe(readFileSync(join(import.meta.dir, "../../.agents/skills/muster", filename), "utf8")); + expect(SKILL_SECTIONS[key]).toBe(readFileSync(join(import.meta.dir, "../.agents/skills/muster", filename), "utf8")); } }); }); diff --git a/service/test/store.test.ts b/tests/store.test.ts similarity index 97% rename from service/test/store.test.ts rename to tests/store.test.ts index 78cc38f..736cb0c 100644 --- a/service/test/store.test.ts +++ b/tests/store.test.ts @@ -3,8 +3,8 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import type { Database } from "bun:sqlite"; -import { openDatabase } from "../src/db.ts"; -import type { ResolvedProject } from "../src/projects.ts"; +import { openDatabase } from "../app/db.ts"; +import type { ResolvedProject } from "../app/projects.ts"; import { answerCard, board, @@ -20,7 +20,7 @@ import { setRunState, snapshot, stats, -} from "../src/store.ts"; +} from "../app/store.ts"; const ref: ResolvedProject = { key: "gh:acme/api", diff --git a/service/tsconfig.json b/tsconfig.json similarity index 69% rename from service/tsconfig.json rename to tsconfig.json index cca859a..5f6ae94 100644 --- a/service/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,6 @@ "allowImportingTsExtensions": true, "verbatimModuleSyntax": true }, - "include": ["src/**/*.ts", "test/**/*.ts"] + "include": ["cli.ts", "install.ts", "app/**/*.ts", "targets/**/*.ts", "scripts/**/*.ts", "tests/**/*.ts"], + "exclude": ["targets/**/mods/**"] } From 2dbc72d8ee450924bd1d2cc8336f3cbed1473194 Mon Sep 17 00:00:00 2001 From: Theros Date: Sat, 7 Nov 2026 09:44:18 +0000 Subject: [PATCH 2/4] Add safe Herdr uninstall command --- .agents/skills/muster/SKILL.md | 3 +- .agents/skills/muster/cli.md | 5 ++ README.md | 22 ++++++ app/skill-content.ts | 8 ++- cli.ts | 14 ++++ install.ts | 6 ++ targets/herdr/installer.ts | 23 ++++++- targets/herdr/uninstaller.ts | 119 +++++++++++++++++++++++++++++++++ tests/install.test.ts | 61 +++++++++++++++++ 9 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 targets/herdr/uninstaller.ts diff --git a/.agents/skills/muster/SKILL.md b/.agents/skills/muster/SKILL.md index f1c5f26..4c125f6 100644 --- a/.agents/skills/muster/SKILL.md +++ b/.agents/skills/muster/SKILL.md @@ -35,7 +35,8 @@ Muster MCP server is connected, use the equivalent tools instead — see Install the CLI with `bun install -g 'github:SvalTek/Muster#main'`, then run `muster whoami`. Use `muster install` to install the Herdr layout, theme and -mod. The Herdr install record is at `%USERPROFILE%\.config\herdr-app\muster.json`. +mod, or `muster uninstall` to turn them off while preserving data. The Herdr +install record is at `%USERPROFILE%\.config\herdr-app\muster.json`. Add `--json` for machine-readable output. ## Details diff --git a/.agents/skills/muster/cli.md b/.agents/skills/muster/cli.md index 9d3f6de..77e1830 100644 --- a/.agents/skills/muster/cli.md +++ b/.agents/skills/muster/cli.md @@ -30,6 +30,7 @@ or a file, so quoting doesn't eat newlines. ```text muster install [herdr] [--app-home DIR] [--muster-home DIR] [--no-keys] +muster uninstall [herdr] [--app-home DIR] muster whoami [--path DIR] [--agent A] [--terminal T] muster status [summary] muster ask --question Q [--choice id:label]... [--timeout S] [--dedupe K] @@ -68,6 +69,10 @@ mcp`, `muster skill cards`, or `muster skill all` to read a guide. Other arguments search all bundled guides case-insensitively and return matching Markdown sections, for example `muster skill pending`. +`muster uninstall` disables the Herdr layout and mod, preserves data and +backups, and removes only recorded, unchanged key bindings. Close Herdr first; +use `--app-home DIR` when it is installed somewhere other than the default. + Card kinds: `question`, `approval`, `report`, `result`, `progress`. Severities: `info`, `attention`, `blocked`, `success` (defaults to `attention` for question/approval, else `info`). diff --git a/README.md b/README.md index 02c1674..86ade6a 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,28 @@ give it its own key, add this to the `global` section of `keys.json`: Claude Code, Codex, or any other MCP client can now connect to the service. +## Turn off or uninstall the Herdr integration + +If Herdr is open, switch to another layout and theme if possible, then close +Herdr. Run: + +```powershell +muster uninstall +``` + +Use `muster uninstall --app-home D:\herdr-app` for a custom app home. The +command removes Muster's layout, mod and theme files, backing up modified files. +It removes only unchanged key bindings recorded as added by Muster; older +installations without that record keep their bindings. The database, backups, +global CLI and MCP client configurations are kept. Reopen Herdr with another +layout; run `muster install` to install the integration again. + +If the CLI cannot start, close Herdr and rename `layouts/muster.json` and +`mods/muster/mod.json` in the Herdr app home (for example, give each a +`.disabled` extension). That makes the layout and mod unavailable without +deleting their contents or the database. The default app home on Windows is +`%USERPROFILE%\.config\herdr-app`. + ## Connect an agent The MCP server is the same executable as the CLI, with `mcp` after it. After diff --git a/app/skill-content.ts b/app/skill-content.ts index ae99805..2f2de78 100644 --- a/app/skill-content.ts +++ b/app/skill-content.ts @@ -39,7 +39,8 @@ Muster MCP server is connected, use the equivalent tools instead — see Install the CLI with \`bun install -g 'github:SvalTek/Muster#main'\`, then run \`muster whoami\`. Use \`muster install\` to install the Herdr layout, theme and -mod. The Herdr install record is at \`%USERPROFILE%\\.config\\herdr-app\\muster.json\`. +mod, or \`muster uninstall\` to turn them off while preserving data. The Herdr +install record is at \`%USERPROFILE%\\.config\\herdr-app\\muster.json\`. Add \`--json\` for machine-readable output. ## Details @@ -88,6 +89,7 @@ or a file, so quoting doesn't eat newlines. \`\`\`text muster install [herdr] [--app-home DIR] [--muster-home DIR] [--no-keys] +muster uninstall [herdr] [--app-home DIR] muster whoami [--path DIR] [--agent A] [--terminal T] muster status [summary] muster ask --question Q [--choice id:label]... [--timeout S] [--dedupe K] @@ -126,6 +128,10 @@ mcp\`, \`muster skill cards\`, or \`muster skill all\` to read a guide. Other arguments search all bundled guides case-insensitively and return matching Markdown sections, for example \`muster skill pending\`. +\`muster uninstall\` disables the Herdr layout and mod, preserves data and +backups, and removes only recorded, unchanged key bindings. Close Herdr first; +use \`--app-home DIR\` when it is installed somewhere other than the default. + Card kinds: \`question\`, \`approval\`, \`report\`, \`result\`, \`progress\`. Severities: \`info\`, \`attention\`, \`blocked\`, \`success\` (defaults to \`attention\` for question/approval, else \`info\`). diff --git a/cli.ts b/cli.ts index 1d27e74..9fd11f7 100644 --- a/cli.ts +++ b/cli.ts @@ -124,6 +124,7 @@ const USAGE = `muster ${MUSTER_VERSION} — project-scoped attention for coding Usage: muster install [herdr] [--app-home DIR] [--muster-home DIR] [--no-keys] + muster uninstall [herdr] [--app-home DIR] muster init [--name N] [--id ID] [--color #hex] [--runbook path] [--force] muster resolve [path] [--json] muster whoami [--path DIR] [--agent A] [--terminal T] @@ -239,6 +240,19 @@ async function main(): Promise { }; switch (command) { + case "uninstall": { + const { uninstall } = await import("./install.ts"); + const result = uninstall(sub, { appHome: flags.string("app-home") }); + emit(result, () => { + console.log(result.disabled ? `Muster disabled in Herdr: ${result.appHome}` : `Could not fully disable Muster: ${result.appHome}`); + console.log("Muster data, the global CLI, and MCP configuration were kept."); + if (result.backups.length) console.log(`Backups: ${result.backups.join(", ")}`); + for (const warning of result.warnings) console.warn(`muster: ${warning}`); + console.log("Switch Herdr to another layout and restart or reload it."); + }); + if (!result.disabled) process.exitCode = 1; + return; + } case "install": { const { install } = await import("./install.ts"); const result = await install(sub, { diff --git a/install.ts b/install.ts index 4fe4717..4ff4a46 100644 --- a/install.ts +++ b/install.ts @@ -1,8 +1,14 @@ import { MusterError } from "./app/store.ts"; import { installHerdr, type HerdrInstallOptions } from "./targets/herdr/installer.ts"; +import { uninstallHerdr } from "./targets/herdr/uninstaller.ts"; /** Dispatch installation targets; Herdr is the default target. */ export async function install(target: string, options: HerdrInstallOptions) { if (target && target !== "herdr") throw new MusterError("usage", `Unknown install target: ${target}. Available target: herdr.`); return installHerdr(options); } + +export function uninstall(target: string, options: { appHome?: string }) { + if (target && target !== "herdr") throw new MusterError("usage", `Unknown uninstall target: ${target}. Available target: herdr.`); + return uninstallHerdr(options); +} diff --git a/targets/herdr/installer.ts b/targets/herdr/installer.ts index b5f2b7c..22c8e8b 100644 --- a/targets/herdr/installer.ts +++ b/targets/herdr/installer.ts @@ -1,6 +1,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { basename, dirname, join, resolve } from "node:path"; +import { createHash } from "node:crypto"; import { musterHome } from "../../app/paths.ts"; import { MusterError } from "../../app/store.ts"; import { MUSTER_VERSION } from "../../app/version.ts"; @@ -52,6 +53,22 @@ export async function installHerdr(options: HerdrInstallOptions = {}) { throw new MusterError("install_config", `The layout:muster section in ${keysPath} must be an object.`); } const defaults = JSON.parse(HERDR_ASSETS["keys.json"]!)["layout:muster"] as Record; + let previous: Record = {}; + const recordPath = join(appHome, "muster.json"); + if (existsSync(recordPath)) { + try { previous = jsonFile(recordPath); } catch { /* Legacy or damaged record; retain existing bindings. */ } + } + const addedBindings: Record = {}; + if (object(previous.addedBindings)) { + for (const [key, value] of Object.entries(previous.addedBindings)) { + if (Object.hasOwn(defaults, key) && typeof value === "string") addedBindings[key] = value; + } + } + if (!options.noKeys) { + for (const [key, value] of Object.entries(defaults)) { + if (!object(existing) || !Object.hasOwn(existing, key)) addedBindings[key] = value; + } + } const bindings = { ...defaults, ...(object(existing) ? existing : {}) }; const keysChanged = !options.noKeys && (existing === undefined || Object.keys(defaults).some((key) => !Object.hasOwn(existing as object, key))); if (keysChanged) keys["layout:muster"] = bindings; @@ -89,8 +106,10 @@ export async function installHerdr(options: HerdrInstallOptions = {}) { if (binaryPath && resolve(process.execPath).toLowerCase() !== resolve(binaryPath).toLowerCase()) copyFileSync(process.execPath, binaryPath); mkdirSync(dataHome, { recursive: true }); mkdirSync(dirname(db), { recursive: true }); - const record = { command, prefix, db, version: MUSTER_VERSION, installedAt: new Date().toISOString() }; - writeFileSync(join(appHome, "muster.json"), `${JSON.stringify(record, null, 2)}\n`); + const runtimePath = binaryPath ?? prefix[0]!; + const runtime = { file: basename(runtimePath), sha256: createHash("sha256").update(readFileSync(runtimePath)).digest("hex") }; + const record = { command, prefix, db, version: MUSTER_VERSION, installedAt: new Date().toISOString(), addedBindings, runtime }; + writeFileSync(recordPath, `${JSON.stringify(record, null, 2)}\n`); if (keysChanged) writeFileSync(keysPath, `${JSON.stringify(keys, null, 2)}\n`); return { target: "herdr", appHome, dataHome, db, command, prefix, keysUpdated: keysChanged, backups }; } diff --git a/targets/herdr/uninstaller.ts b/targets/herdr/uninstaller.ts new file mode 100644 index 0000000..6f64dbf --- /dev/null +++ b/targets/herdr/uninstaller.ts @@ -0,0 +1,119 @@ +import { createHash } from "node:crypto"; +import { copyFileSync, existsSync, lstatSync, readFileSync, rmdirSync, statSync, unlinkSync, writeFileSync } from "node:fs"; +import { homedir } from "node:os"; +import { basename, join, relative, resolve, sep } from "node:path"; +import { HERDR_ASSETS } from "./assets.ts"; + +function object(value: unknown): value is Record { + return value !== null && typeof value === "object" && !Array.isArray(value); +} + +function backup(path: string): string { + const base = `${path}.bak-${Date.now()}`; + let dest = base; + let n = 1; + while (existsSync(dest)) dest = `${base}-${n++}`; + copyFileSync(path, dest); + return dest; +} + +/** Disable Muster's Herdr integration without deleting its data or other files. */ +export function uninstallHerdr(options: { appHome?: string } = {}) { + const appHome = resolve(options.appHome || process.env.HERDR_APP_HOME || join(homedir(), ".config", "herdr-app")); + const removed: string[] = []; + const backups: string[] = []; + const warnings: string[] = []; + const safePath = (path: string) => { + const parts = relative(appHome, path).split(sep); + if (parts.some((part) => part === "..")) return false; + let current = appHome; + for (const part of parts) { + current = join(current, part); + if (existsSync(current) && lstatSync(current).isSymbolicLink()) return false; + } + return true; + }; + const recordPath = join(appHome, "muster.json"); + let record: Record = {}; + if (existsSync(recordPath)) { + try { + const value: unknown = JSON.parse(readFileSync(recordPath, "utf8")); + if (object(value)) record = value; + else warnings.push("Install record is invalid; existing key bindings and runtime were kept."); + } catch { warnings.push("Install record is unreadable; existing key bindings and runtime were kept."); } + } + + // Remove the layout and mod manifest first so optional cleanup cannot leave them active. + const assetPaths = Object.keys(HERDR_ASSETS).filter((path) => path !== "keys.json"); + assetPaths.sort((a, b) => { + const priority = (path: string) => path === "layouts/muster.json" ? 0 : path === "mods/muster/mod.json" ? 1 : 2; + return priority(a) - priority(b); + }); + for (const path of assetPaths) { + const dest = join(appHome, ...path.split("/")); + if (!existsSync(dest)) continue; + try { + if (!safePath(dest)) throw new Error("Path contains a symbolic link"); + if (readFileSync(dest, "utf8") !== HERDR_ASSETS[path]) backups.push(backup(dest)); + unlinkSync(dest); + removed.push(dest); + } catch (error) { warnings.push(`Could not remove ${dest}: ${error instanceof Error ? error.message : String(error)}`); } + } + + const keysPath = join(appHome, "keys.json"); + if (object(record.addedBindings) && existsSync(keysPath)) { + try { + if (!safePath(keysPath)) throw new Error("Path contains a symbolic link"); + const keys: unknown = JSON.parse(readFileSync(keysPath, "utf8")); + if (!object(keys) || !object(keys["layout:muster"])) throw new Error("Invalid layout:muster bindings"); + const section = keys["layout:muster"]; + let changed = false; + const defaults = JSON.parse(HERDR_ASSETS["keys.json"]!)["layout:muster"] as Record; + for (const [key, value] of Object.entries(record.addedBindings)) { + if (Object.hasOwn(defaults, key) && typeof value === "string" && Object.hasOwn(section, key) && section[key] === value) { + delete section[key]; + changed = true; + } + } + if (changed) { + if (!Object.keys(section).length) delete keys["layout:muster"]; + backups.push(backup(keysPath)); + writeFileSync(keysPath, `${JSON.stringify(keys, null, 2)}\n`); + } + } catch (error) { warnings.push(`Could not clean up ${keysPath}: ${error instanceof Error ? error.message : String(error)}`); } + } else if (existsSync(keysPath) && !object(record.addedBindings)) { + warnings.push("Key ownership was not recorded; existing key bindings were kept."); + } + + const appDir = join(appHome, "muster"); + if (object(record.runtime) && typeof record.runtime.file === "string" && typeof record.runtime.sha256 === "string" + && basename(record.runtime.file) === record.runtime.file && ![".", ".."].includes(record.runtime.file)) { + const runtime = join(appDir, record.runtime.file); + if (existsSync(runtime)) { + try { + if (!safePath(runtime)) throw new Error("Path contains a symbolic link"); + let sameProcess = process.platform === "win32" + ? resolve(runtime).toLowerCase() === resolve(process.execPath).toLowerCase() + : resolve(runtime) === resolve(process.execPath); + if (!sameProcess) { + const targetStat = statSync(runtime); + const processStat = statSync(process.execPath); + sameProcess = targetStat.ino !== 0 && targetStat.ino === processStat.ino && targetStat.dev === processStat.dev; + } + if (sameProcess) warnings.push(`The running executable was kept: ${runtime}`); + else if (createHash("sha256").update(readFileSync(runtime)).digest("hex") !== record.runtime.sha256) warnings.push(`Modified app file was kept: ${runtime}`); + else { unlinkSync(runtime); removed.push(runtime); } + } catch (error) { warnings.push(`Could not remove ${runtime}: ${error instanceof Error ? error.message : String(error)}`); } + } + } else if (existsSync(appDir)) warnings.push(`App files were kept because their ownership was not recorded: ${appDir}`); + + if (existsSync(recordPath) && warnings.length === 0) { + try { unlinkSync(recordPath); removed.push(recordPath); } + catch (error) { warnings.push(`Could not remove ${recordPath}: ${error instanceof Error ? error.message : String(error)}`); } + } + for (const dir of [join(appHome, "mods", "muster", "icons"), join(appHome, "mods", "muster"), appDir]) { + try { rmdirSync(dir); } catch { /* Missing or contains user files/backups. */ } + } + const disabled = !existsSync(join(appHome, "layouts", "muster.json")) && !existsSync(join(appHome, "mods", "muster", "mod.json")); + return { target: "herdr", appHome, disabled, removed, backups, warnings }; +} diff --git a/tests/install.test.ts b/tests/install.test.ts index 8d35310..c9c898b 100644 --- a/tests/install.test.ts +++ b/tests/install.test.ts @@ -63,6 +63,67 @@ describe("Herdr installation", () => { expect(run("install", "missing-target").status).toBe(1); }, 30000); + test("uninstall disables Herdr and preserves data, modified files and user keys", () => { + const app = join(root, "uninstall-app"); + const data = join(root, "uninstall-data"); + mkdirSync(app); + writeFileSync(join(app, "keys.json"), JSON.stringify({ global: { "alt-m": "other" }, "layout:muster": { "ctrl-shift-1": "custom-before" } })); + expect(run("install", "--app-home", app, "--muster-home", data).status).toBe(0); + expect(run("install", "--app-home", app, "--muster-home", data).status).toBe(0); + writeFileSync(join(data, "muster.db"), "important data"); + writeFileSync(join(app, "mods", "muster", "user.js"), "custom file"); + writeFileSync(join(app, "layouts", "muster.json"), "modified layout"); + const keysPath = join(app, "keys.json"); + const keys = JSON.parse(readFileSync(keysPath, "utf8")); + keys["layout:muster"]["ctrl-shift-2"] = "custom-after"; + writeFileSync(keysPath, JSON.stringify(keys)); + const result = run("uninstall", "--app-home", app, "--json"); + expect(result.status).toBe(0); + const output = JSON.parse(result.stdout); + expect(output.disabled).toBe(true); + expect(existsSync(join(app, "layouts", "muster.json"))).toBe(false); + expect(existsSync(join(app, "mods", "muster", "mod.json"))).toBe(false); + expect(output.backups.some((path: string) => readFileSync(path, "utf8") === "modified layout")).toBe(true); + const remaining = JSON.parse(readFileSync(keysPath, "utf8")); + expect(remaining.global["alt-m"]).toBe("other"); + expect(remaining["layout:muster"]).toEqual({ "ctrl-shift-1": "custom-before", "ctrl-shift-2": "custom-after" }); + expect(readFileSync(join(data, "muster.db"), "utf8")).toBe("important data"); + expect(readFileSync(join(app, "mods", "muster", "user.js"), "utf8")).toBe("custom file"); + expect(run("uninstall", "--app-home", app, "--json").status).toBe(0); + }, 30000); + + test("uninstall still disables a legacy install with an unreadable record and keys", () => { + const app = join(root, "legacy-app"); + mkdirSync(join(app, "layouts"), { recursive: true }); + mkdirSync(join(app, "mods", "muster"), { recursive: true }); + writeFileSync(join(app, "layouts", "muster.json"), "broken layout"); + writeFileSync(join(app, "mods", "muster", "mod.json"), "broken mod"); + writeFileSync(join(app, "muster.json"), "invalid"); + writeFileSync(join(app, "keys.json"), "invalid"); + const result = run("uninstall", "--app-home", app, "--json"); + expect(result.status).toBe(0); + const output = JSON.parse(result.stdout); + expect(output.disabled).toBe(true); + expect(output.warnings.length).toBeGreaterThan(0); + expect(output.backups).toHaveLength(2); + expect(readFileSync(join(app, "keys.json"), "utf8")).toBe("invalid"); + expect(readFileSync(join(app, "muster.json"), "utf8")).toBe("invalid"); + }); + + test("bad keys do not prevent disabling an installation", () => { + const app = join(root, "broken-keys-uninstall"); + mkdirSync(app); + expect(run("install", "--app-home", app, "--muster-home", join(root, "broken-keys-data")).status).toBe(0); + writeFileSync(join(app, "keys.json"), "invalid"); + const result = run("uninstall", "--app-home", app, "--json"); + expect(result.status).toBe(0); + const output = JSON.parse(result.stdout); + expect(output.disabled).toBe(true); + expect(output.warnings.some((warning: string) => warning.includes("keys.json"))).toBe(true); + expect(readFileSync(join(app, "keys.json"), "utf8")).toBe("invalid"); + expect(existsSync(join(app, "muster.json"))).toBe(true); + }, 30000); + test("embedded assets match their repository sources", () => { for (const [path, content] of Object.entries(HERDR_ASSETS)) { expect(content).toBe(readFileSync(join(import.meta.dir, "../targets/herdr", path), "utf8")); From 5467d21150d4d4e625a3e767f0e97665142cd4b5 Mon Sep 17 00:00:00 2001 From: Theros Date: Sat, 7 Nov 2026 09:49:37 +0000 Subject: [PATCH 3/4] Build and publish rolling release channels --- .github/workflows/ci.yml | 85 ++++++++++++++++++++++++ .github/workflows/publish.yml | 117 ++++++++++++++++++++++++++++++++++ README.md | 16 +++++ 3 files changed, 218 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..41da05d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,85 @@ +name: Muster CI + +on: + push: + branches: [main, develop] + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Test (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.4.2 + - run: bun install --frozen-lockfile + - run: bun run typecheck + - run: bun test + - name: Check generated content + shell: bash + run: | + bun run build-skill + bun run build-herdr-assets + git diff --exit-code -- app/skill-content.ts targets/herdr/assets.ts + + build: + name: Build (${{ matrix.name }}) + needs: test + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + name: windows-x64 + executable: muster-windows-x64.exe + - os: ubuntu-latest + name: linux-x64 + executable: muster-linux-x64 + - os: ubuntu-24.04-arm + name: linux-arm64 + executable: muster-linux-arm64 + - os: macos-15-intel + name: macos-x64 + executable: muster-macos-x64 + - os: macos-latest + name: macos-arm64 + executable: muster-macos-arm64 + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.4.2 + - name: Compile and smoke test + shell: bash + env: + EXECUTABLE: ${{ matrix.executable }} + run: | + mkdir -p dist + bun build --compile ./cli.ts --outfile "dist/$EXECUTABLE" + "./dist/$EXECUTABLE" version + "./dist/$EXECUTABLE" skill cli > /dev/null + - uses: actions/upload-artifact@v4 + with: + name: muster-${{ matrix.name }} + path: dist/${{ matrix.executable }} + if-no-files-found: error + retention-days: 7 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..089045e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,117 @@ +name: Publish channel builds + +on: + workflow_run: + workflows: [Muster CI] + types: [completed] + +permissions: + actions: read + contents: write + pull-requests: read + +concurrency: + group: publish-${{ github.event.workflow_run.event }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: false + +jobs: + publish: + if: >- + github.event.workflow_run.conclusion == 'success' && + (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'pull_request') + runs-on: ubuntu-latest + steps: + # This workflow is loaded from the default branch. It never checks out or + # executes PR code: artifacts from the unprivileged CI run are data only. + - name: Resolve and validate channel + id: channel + shell: bash + env: + GH_TOKEN: ${{ github.token }} + EVENT: ${{ github.event.workflow_run.event }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }} + run: | + set -euo pipefail + if [[ ! "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]]; then + echo 'Invalid source commit' >&2; exit 1 + fi + if [[ "$EVENT" == push ]]; then + case "$HEAD_BRANCH" in + main) tag=stable ;; + develop) tag=dev ;; + *) echo 'Not a release branch'; exit 0 ;; + esac + current=$(gh api "repos/$GITHUB_REPOSITORY/branches/$HEAD_BRANCH" --jq '.commit.sha') + if [[ "$current" != "$HEAD_SHA" ]]; then + echo 'A newer branch commit exists; skip this run'; exit 0 + fi + else + prs=$(gh api --paginate -X GET "repos/$GITHUB_REPOSITORY/pulls" \ + -f state=open -f "head=$HEAD_OWNER:$HEAD_BRANCH" | \ + jq -s --arg sha "$HEAD_SHA" '[.[][] | select(.head.sha == $sha)]') + if [[ $(jq 'length' <<< "$prs") != 1 ]]; then + echo 'No unique open PR at this commit; skip this run'; exit 0 + fi + number=$(jq -r '.[0].number' <<< "$prs") + [[ "$number" =~ ^[0-9]+$ ]] || exit 1 + tag="pr-$number" + fi + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "sha=$HEAD_SHA" >> "$GITHUB_OUTPUT" + - name: Download build artifacts + if: steps.channel.outputs.tag != '' + env: + GH_TOKEN: ${{ github.token }} + RUN_ID: ${{ github.event.workflow_run.id }} + run: gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" --pattern 'muster-*' --dir "$RUNNER_TEMP/muster-artifacts" + - name: Publish release + if: steps.channel.outputs.tag != '' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ steps.channel.outputs.tag }} + SOURCE_SHA: ${{ steps.channel.outputs.sha }} + EVENT: ${{ github.event.workflow_run.event }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + run: | + set -euo pipefail + root="$RUNNER_TEMP/muster-artifacts" + files=( + "$root/muster-windows-x64/muster-windows-x64.exe" + "$root/muster-linux-x64/muster-linux-x64" + "$root/muster-linux-arm64/muster-linux-arm64" + "$root/muster-macos-x64/muster-macos-x64" + "$root/muster-macos-arm64/muster-macos-arm64" + ) + for file in "${files[@]}"; do + [[ -f "$file" && ! -L "$file" && -s "$file" ]] || { echo "Missing artifact: $file" >&2; exit 1; } + done + # A newer run may have completed while artifacts were downloading. + if [[ "$EVENT" == push ]]; then + current=$(gh api "repos/$GITHUB_REPOSITORY/branches/$HEAD_BRANCH" --jq '.commit.sha') + else + number=${TAG#pr-} + current=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$number" --jq 'if .state == "open" then .head.sha else "closed" end') + fi + [[ "$current" == "$SOURCE_SHA" ]] || { echo 'Source changed; skip this run'; exit 0; } + if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$TAG" > /dev/null 2>&1; then + gh api -X PATCH "repos/$GITHUB_REPOSITORY/git/refs/tags/$TAG" -f "sha=$SOURCE_SHA" -F force=true > /dev/null + else + gh api -X POST "repos/$GITHUB_REPOSITORY/git/refs" -f "ref=refs/tags/$TAG" -f "sha=$SOURCE_SHA" > /dev/null + fi + notes="Rolling $TAG build from commit $SOURCE_SHA. PR builds are untrusted previews." + if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then + if [[ "$TAG" == stable ]]; then + gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --title 'Stable' --notes "$notes" --latest + else + gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --title "$TAG" --notes "$notes" --prerelease --latest=false + fi + fi + gh release upload "$TAG" "${files[@]}" --repo "$GITHUB_REPOSITORY" --clobber + if [[ "$TAG" == stable ]]; then + gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --notes "$notes" --prerelease=false --latest + else + gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --notes "$notes" --prerelease --latest=false + fi diff --git a/README.md b/README.md index 86ade6a..d2faa4e 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,22 @@ herdr-app check targets\herdr\mods\muster The tests use temporary folders and never touch `%LOCALAPPDATA%\Muster`. +## Build channels + +GitHub Actions tests changes on Windows and Linux, then builds standalone +executables for Windows x64, Linux x64/arm64, and macOS x64/arm64. Successful +builds appear in [GitHub Releases](https://github.com/SvalTek/Muster/releases): + +- `stable` follows the latest successful build of `main` and is the latest release. +- `dev` follows `develop` and is a prerelease. +- `pr-N` follows the current head of open pull request N and is an untrusted + prerelease preview. A newer build replaces its assets. + +The tags are rolling channels rather than permanent version numbers. CI runs +with read-only permissions; a separate publisher checks that the branch or PR +still points at the built commit before attaching artifacts. GitHub only runs +the publisher once its workflow file exists on the default branch (`main`). + ## Scope v1 is the board, cards, runbooks and stats. Deferred: inbox and mail From 71831f32dc297149750a0510351041f753208327 Mon Sep 17 00:00:00 2001 From: Theros Date: Sat, 7 Nov 2026 09:54:29 +0000 Subject: [PATCH 4/4] Compare project paths by filesystem identity --- tests/projects.test.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/projects.test.ts b/tests/projects.test.ts index 336eccd..55e679f 100644 --- a/tests/projects.test.ts +++ b/tests/projects.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import { spawnSync } from "node:child_process"; -import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { mkdirSync, mkdtempSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { @@ -14,6 +14,17 @@ function tempDir(label: string): string { return mkdtempSync(join(tmpdir(), `muster-${label}-`)); } +function expectSameFile(first: string, second: string): void { + const a = statSync(first, { bigint: true }); + const b = statSync(second, { bigint: true }); + if (a.ino !== 0n && b.ino !== 0n) { + expect([a.dev, a.ino]).toEqual([b.dev, b.ino]); + } else { + const normalize = (path: string) => process.platform === "win32" ? realpathSync(path).toLowerCase() : realpathSync(path); + expect(normalize(first)).toBe(normalize(second)); + } +} + function git(cwd: string, ...args: string[]): void { const result = spawnSync("git", args, { cwd, encoding: "utf8", windowsHide: true }); if (result.status !== 0) { @@ -66,7 +77,7 @@ describe("resolveProject", () => { const sub = resolve(dir, "src", "deep"); mkdirSync(sub, { recursive: true }); expect(resolveProject(sub).key).toBe("gh:acme/api"); - expect(resolveProject(sub).root).toBe(resolve(dir)); + expectSameFile(resolveProject(sub).root, dir); } finally { rmSync(dir, { recursive: true, force: true }); } @@ -152,7 +163,7 @@ describe("initMarker", () => { expect(first.marker.runbook).toBe("docs/runbook.md"); const second = initMarker(dir, { name: "Acme API" }); - expect(second.path).toBe(first.path); + expectSameFile(second.path, first.path); expect(second.marker.id).toBe("gh:acme/api"); expect(second.marker.name).toBe("Acme API"); expect(resolveProject(dir).source).toBe("marker");