@mu-agent/mu 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +236 -74
  2. package/dist/index.js +886 -192
  3. package/dist/mu.js +993 -273
  4. package/dist/types/ai/catalog.d.ts +0 -1
  5. package/dist/types/ai/providers/openai.d.ts +2 -0
  6. package/dist/types/ai/types.d.ts +50 -2
  7. package/dist/types/core/compaction.d.ts +9 -2
  8. package/dist/types/core/events.d.ts +7 -1
  9. package/dist/types/core/index.d.ts +3 -3
  10. package/dist/types/core/loop.d.ts +2 -1
  11. package/dist/types/core/messages.d.ts +4 -1
  12. package/dist/types/core/microcompaction.d.ts +3 -0
  13. package/dist/types/core/permission.d.ts +12 -0
  14. package/dist/types/core/profile.d.ts +8 -0
  15. package/dist/types/core/session.d.ts +1 -0
  16. package/dist/types/core/tools.d.ts +5 -0
  17. package/dist/types/index.d.ts +8 -4
  18. package/dist/types/profile-browser/actions/classify.d.ts +19 -0
  19. package/dist/types/profile-browser/actions/click.d.ts +48 -0
  20. package/dist/types/profile-browser/actions/dates.d.ts +11 -0
  21. package/dist/types/profile-browser/actions/files.d.ts +9 -0
  22. package/dist/types/profile-browser/actions/filetype.d.ts +8 -0
  23. package/dist/types/profile-browser/actions/input.d.ts +17 -0
  24. package/dist/types/profile-browser/actions/keyboard.d.ts +16 -0
  25. package/dist/types/profile-browser/actions/navigate.d.ts +11 -0
  26. package/dist/types/profile-browser/actions/page.d.ts +8 -0
  27. package/dist/types/profile-browser/actions/pointer.d.ts +39 -0
  28. package/dist/types/profile-browser/actions/scroll.d.ts +8 -0
  29. package/dist/types/profile-browser/actions/submission.d.ts +7 -0
  30. package/dist/types/profile-browser/actions/types.d.ts +38 -0
  31. package/dist/types/profile-browser/agent/dataflow.d.ts +18 -0
  32. package/dist/types/profile-browser/agent/handoff.d.ts +15 -0
  33. package/dist/types/profile-browser/agent/ledger.d.ts +4 -0
  34. package/dist/types/profile-browser/agent/notes.d.ts +6 -0
  35. package/dist/types/profile-browser/agent/permissions.d.ts +18 -0
  36. package/dist/types/profile-browser/agent/prompts.d.ts +4 -0
  37. package/dist/types/profile-browser/agent/state.d.ts +48 -0
  38. package/dist/types/profile-browser/browser/connect.d.ts +44 -0
  39. package/dist/types/profile-browser/browser/discover.d.ts +31 -0
  40. package/dist/types/profile-browser/browser/downloads.d.ts +24 -0
  41. package/dist/types/profile-browser/browser/frames.d.ts +34 -0
  42. package/dist/types/profile-browser/browser/launch.d.ts +42 -0
  43. package/dist/types/profile-browser/browser/manager.d.ts +135 -0
  44. package/dist/types/profile-browser/browser/tabs.d.ts +52 -0
  45. package/dist/types/profile-browser/cdp/connection.d.ts +53 -0
  46. package/dist/types/profile-browser/cdp/session.d.ts +23 -0
  47. package/dist/types/profile-browser/cdp/types.d.ts +10 -0
  48. package/dist/types/profile-browser/commands.d.ts +5 -0
  49. package/dist/types/profile-browser/config.d.ts +73 -0
  50. package/dist/types/profile-browser/evals/live.d.ts +64 -0
  51. package/dist/types/profile-browser/index.d.ts +21 -0
  52. package/dist/types/profile-browser/page/capture-script.d.ts +1 -0
  53. package/dist/types/profile-browser/page/injection.d.ts +2 -0
  54. package/dist/types/profile-browser/page/model.d.ts +67 -0
  55. package/dist/types/profile-browser/page/network.d.ts +12 -0
  56. package/dist/types/profile-browser/page/observe.d.ts +39 -0
  57. package/dist/types/profile-browser/page/refs.d.ts +38 -0
  58. package/dist/types/profile-browser/page/render.d.ts +27 -0
  59. package/dist/types/profile-browser/page/resolve.d.ts +15 -0
  60. package/dist/types/profile-browser/page/screenshot.d.ts +25 -0
  61. package/dist/types/profile-browser/page/secrets.d.ts +7 -0
  62. package/dist/types/profile-browser/page/settle.d.ts +13 -0
  63. package/dist/types/profile-browser/page/snapshot.d.ts +9 -0
  64. package/dist/types/profile-browser/page/text.d.ts +22 -0
  65. package/dist/types/profile-browser/testing/agent-scenarios.d.ts +27 -0
  66. package/dist/types/profile-browser/testing/bench.d.ts +19 -0
  67. package/dist/types/profile-browser/testing/chrome.d.ts +12 -0
  68. package/dist/types/profile-browser/testing/fixture-site.d.ts +14 -0
  69. package/dist/types/profile-browser/testing/pdf.d.ts +1 -0
  70. package/dist/types/profile-browser/testing/wait.d.ts +1 -0
  71. package/dist/types/profile-browser/tools/delegate.d.ts +23 -0
  72. package/dist/types/profile-browser/tools/files.d.ts +3 -0
  73. package/dist/types/profile-browser/tools/gate.d.ts +8 -0
  74. package/dist/types/profile-browser/tools/interact.d.ts +86 -0
  75. package/dist/types/profile-browser/tools/navigate.d.ts +5 -0
  76. package/dist/types/profile-browser/tools/observe.d.ts +18 -0
  77. package/dist/types/profile-browser/tools/shared.d.ts +23 -0
  78. package/dist/types/profile-browser/tools/tabs.d.ts +8 -0
  79. package/dist/types/profile-coding/index.d.ts +3 -3
  80. package/dist/types/profile-coding/prompts.d.ts +1 -1
  81. package/dist/types/sdk/agent.d.ts +5 -0
  82. package/dist/types/sdk/index.d.ts +3 -1
  83. package/dist/types/sdk/recall.d.ts +3 -0
  84. package/dist/types/sdk/subagents.d.ts +2 -1
  85. package/dist/types/{profile-coding/tools → sdk}/todo.d.ts +2 -2
  86. package/dist/types/sdk/web-search.d.ts +8 -0
  87. package/package.json +2 -1
package/README.md CHANGED
@@ -1,97 +1,125 @@
1
1
  # @mu-agent/mu
2
2
 
3
- The terminal and TypeScript SDK distribution of Mu, a general-purpose extensible AI
4
- agent platform. Coding is the default profile, not a constraint of the underlying kernel.
3
+ The CLI and TypeScript SDK distribution of [Mu](https://github.com/Spandan7724/mu), an
4
+ extensible AI agent with a built-in coding profile.
5
+
6
+ The package provides:
7
+
8
+ - the `mu` interactive terminal application;
9
+ - headless and NDJSON RPC modes;
10
+ - the public `Agent` and `createAgent` TypeScript APIs;
11
+ - the coding profile, TUI, extensions, MCP support, and a platform-specific ripgrep
12
+ sidecar.
13
+
14
+ This package requires Bun 1.3 or later at runtime.
15
+
16
+ ## Install the CLI
5
17
 
6
18
  ```sh
7
- # npm (requires Bun)
8
19
  npm install -g @mu-agent/mu
9
-
10
- # Bun
20
+ # or
11
21
  bun install -g @mu-agent/mu
22
+
12
23
  mu
13
24
  ```
14
25
 
15
- Update a global npm or Bun installation:
26
+ Run `/login` to configure a provider account or API key, then `/model` to select a model.
27
+ Environment variables such as `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, and `GEMINI_API_KEY`
28
+ also work.
16
29
 
17
30
  ```sh
18
- mu self update
31
+ mu # interactive TUI
32
+ mu -p "fix the failing test" # one-shot result
33
+ mu -p "review this patch" --json # JSON event stream
34
+ mu --resume <session-id> # resume a session
35
+ mu --rpc # NDJSON operations in, events out
36
+ mu agents # manage several sessions
19
37
  ```
20
38
 
21
- Install the package locally to embed Mu:
39
+ Run `mu --help` for all flags. Global npm and Bun installs can update or remove themselves:
22
40
 
23
41
  ```sh
24
- npm install @mu-agent/mu
25
- # or: bun add @mu-agent/mu
42
+ mu self update
43
+ mu self uninstall
26
44
  ```
27
45
 
28
- ```ts
29
- import { Agent, createAgent } from "@mu-agent/mu";
46
+ Native, runtime-free installers and release archives are documented in the
47
+ [project README](https://github.com/Spandan7724/mu#install).
30
48
 
31
- // A domain-neutral agent with a general prompt and no tools.
32
- const assistant = new Agent();
33
- console.log((await assistant.run("Explain how an AI agent loop works")).text);
49
+ ## Coding agent
34
50
 
35
- // Mu's built-in coding profile: file, search, shell, task, and checkpoint tools.
36
- const codingAgent = await createAgent({
37
- profile: "coding",
38
- profileOptions: { root: process.cwd() },
39
- });
40
- console.log((await codingAgent.run("Summarize this directory")).text);
41
- await codingAgent.shutdown();
42
- ```
51
+ The CLI loads the coding profile by default. It includes:
52
+
53
+ - `read`, `ls`, `edit`, and `write` file tools;
54
+ - foreground and PTY-backed background shell commands;
55
+ - repository search with `rg` and `rg --files`;
56
+ - read-before-write checks and diff previews for approvals;
57
+ - shadow-git workspace checkpoints with `/undo`, `/redo`, `/fork`, and `/diff`;
58
+ - durable sessions, automatic context compaction, and Markdown transcript export;
59
+ - managed `task` delegation and coding-specific `search`, `counsel`, and `recall` subagents.
60
+
61
+ Explicitly ask **“Ask Recall why we rejected SQLite”** to investigate retained project
62
+ sessions, including compacted history and alternate branches. Recall has only read-only
63
+ history tools, no workspace or network tools, and cites session/entry references. It uses
64
+ Search's same-provider model routing with the current model as fallback. Explicit-only
65
+ invocation is a parent-model instruction, not a classifier or runtime authorization gate.
66
+ Separate project directories, including other clones/worktrees, are not automatically joined.
67
+
68
+ The default permission mode allows inspection and asks before file changes or commands.
69
+ Use `/permissions` or `--permission-mode` to choose `default`, `accept-edits`,
70
+ `plan-readonly`, or `yolo`. These are permission rules, not an OS sandbox.
71
+
72
+ CLI sessions are scoped to the current project and stored under `~/.mu/sessions`.
73
+ Checkpoints are stored under `~/.mu/checkpoints` and do not add commits or refs to the
74
+ user's repository.
75
+
76
+ ### Interactive commands
77
+
78
+ | Command | Purpose |
79
+ |---|---|
80
+ | `/login`, `/logout` | Add or remove credentials stored by Mu |
81
+ | `/model` | Select the active model |
82
+ | `/permissions` | Change the current permission mode |
83
+ | `/resume`, `/new`, `/rename` | Open, create, or name conversations |
84
+ | `/compact [focus]` | Compact the active model context |
85
+ | `/undo`, `/redo`, `/fork`, `/diff` | Navigate the session and workspace history |
86
+ | `/export [path.md]` | Export the complete active branch |
87
+ | `/btw [question]` | Open an ephemeral read-only side conversation |
88
+ | `/instructions [reload]`, `/reload` | Inspect or reload repository instructions |
89
+ | `/subagents` | List subagents, their roles, and how to invoke them |
90
+ | `/cost` | Show session token and cost totals |
91
+ | `/keybindings` | Show Mu-specific keyboard controls |
92
+
93
+ During a run, Enter steers the current turn and Tab queues a follow-up. `Ctrl+O` opens
94
+ transcript review, `Alt+T` collapses expanded tool activity, `Shift+Tab` cycles permission
95
+ modes, and a leading `!` runs a command directly without a model call. Direct shell commands
96
+ are still recorded as session context.
43
97
 
44
- The matching OS/CPU package supplies a pinned ripgrep binary for fast search; installs
45
- without it fall back to `rg` on `PATH` or mu's built-in search.
46
-
47
- Run `/login` to sign in with an account or API key and `/logout` to remove a credential
48
- saved that way. Environment variables are not changed by `/logout`. `/model` only lists
49
- providers authenticated through `/login`; `openai-codex/*` rows use the ChatGPT plan and
50
- `openai/*` rows use a saved API key. Both OpenAI routes default to GPT-5.6 Sol. See the
51
- project repository for configuration, SDK, and development documentation.
52
-
53
- Local `llama-server` models are available under `llama-cpp/<alias>` without a login. Mu
54
- uses `http://127.0.0.1:8000` by default and discovers the alias exposed by `/v1/models`;
55
- set `LLAMA_CPP_BASE_URL` for another address and `LLAMA_CPP_API_KEY` for a secured server.
56
-
57
- Interactive runs are saved by working-directory scope under `~/.mu/sessions`; use
58
- `/resume` to choose one or `mu --resume <session-id>` to continue it directly. Mu prints
59
- the direct resume command when an interactive session closes. Use `/rename [name]` to name
60
- the current conversation; named conversations use that name in `/resume`. Press Delete
61
- twice on a `/resume` row to permanently remove it. Use `/new` to clear the terminal and
62
- start a fresh chat without deleting the previous saved session. Use
63
- `/permissions` to choose `default`, `accept-edits`, `plan-readonly`, or full-access
64
- behavior, including while the agent is running. In the coding TUI, `/btw [question]`
65
- opens an ephemeral read-only side conversation with the current chat as reference. Press
66
- Ctrl+B to switch between conversations or Escape to close the side conversation.
67
-
68
- Run `mu agents` to manage several sessions whose worker processes survive closing the
69
- viewer. Managed sessions commit the initiating prompt before contacting the provider and
70
- commit every completed assistant/tool turn before starting the next one. If a supervisor,
71
- worker, or machine stops during an in-flight provider or tool call, Mu marks that runtime
72
- failed and resumes from the last committed boundary; it never automatically replays the
73
- interrupted operation or claims exact mid-turn continuation.
74
-
75
- Coding workers that share a workspace serialize shadow-checkpoint Git operations with a
76
- cross-process ownership lock, including stale-owner recovery. Their filesystem itself is
77
- still shared: simultaneous agents can observe one another's edits, so coordinate tasks
78
- that modify the same files.
79
-
80
- Managed workers support built-in and external profiles through `--profile`. Profile
81
- commands, scoped session storage, runtime lifecycle hooks, and TUI renderers are preserved
82
- in managed mode. Environment needed only by a custom profile can be forwarded with
83
- uppercase `MU_PROFILE_*` variables; process identity variables such as `HOME` are never
84
- accepted through the viewer-to-supervisor handoff.
85
-
86
- Mu loads coding instructions from `~/.mu/AGENTS.md` and from the active project, stopping
87
- at its Git root. `AGENTS.override.md` takes precedence over `AGENTS.md`; Claude-compatible
88
- fallback files, `.mu/rules/`, `.claude/rules/`, conditional `paths` frontmatter, and safe
89
- `@file` imports are supported. Run `/instructions` to see the exact loaded files and
90
- warnings, `/instructions reload` (or `/reload`) to rescan, or start with
91
- `--no-instructions` to disable loading for one invocation.
92
-
93
- Instruction settings can be placed in user or project `.mu/config.json`; project values
94
- override user values:
98
+ ## Providers
99
+
100
+ Account sign-in is available for OpenAI Codex/ChatGPT, GitHub Copilot, Kimi Code,
101
+ OpenRouter, and xAI. API-key routes include Anthropic, OpenAI, Google, Z.AI Coding Plan,
102
+ Qwen Token Plan, and providers supported by Mu's shared OpenAI-compatible and
103
+ Gemini-compatible transports. Anthropic subscription OAuth is not supported.
104
+
105
+ OpenAI API-key models use the `openai/*` namespace. ChatGPT-plan models use
106
+ `openai-codex/*`; the credentials are separate and may coexist. Both routes receive
107
+ provider-hosted web search automatically. Other providers currently run without web
108
+ search.
109
+
110
+ A local `llama-server` is discovered at `http://127.0.0.1:8000` and exposed as
111
+ `llama-cpp/<alias>`. Set `LLAMA_CPP_BASE_URL` or `LLAMA_CPP_API_KEY` when needed.
112
+
113
+ ## Project instructions and extensions
114
+
115
+ The coding profile loads instructions from `~/.mu/AGENTS.md` and the active project,
116
+ stopping at its configured root marker (`.git` by default). It supports
117
+ `AGENTS.override.md`, `AGENTS.md`, configured fallback names such as `CLAUDE.md`,
118
+ `.mu/rules/`, `.claude/rules/`, conditional `paths` frontmatter, and scoped `@file`
119
+ imports.
120
+
121
+ Instruction settings can be placed in `~/.mu/config.json` or `.mu/config.json`. Project
122
+ values override user values.
95
123
 
96
124
  ```json
97
125
  {
@@ -104,3 +132,137 @@ override user values:
104
132
  }
105
133
  }
106
134
  ```
135
+
136
+ The CLI also discovers:
137
+
138
+ - TypeScript extensions in `~/.mu/extensions` and `.mu/extensions`;
139
+ - Markdown slash commands in `~/.mu/commands` and `.mu/commands`;
140
+ - skills in `~/.mu/skills` and `.mu/skills`;
141
+ - MCP servers from user and project `.mu/config.json`.
142
+
143
+ ```json
144
+ {
145
+ "mcpServers": {
146
+ "docs": {
147
+ "command": "bunx",
148
+ "args": ["-y", "your-mcp-server"],
149
+ "env": { "SERVER_TOKEN": "..." }
150
+ }
151
+ }
152
+ }
153
+ ```
154
+
155
+ MCP tools are named `mcp_<server>_<tool>` and use the same permission, event, and abort
156
+ paths as local tools.
157
+
158
+ ## TypeScript SDK
159
+
160
+ Install the package in a Bun project:
161
+
162
+ ```sh
163
+ bun add @mu-agent/mu
164
+ ```
165
+
166
+ ### Low-level agent
167
+
168
+ `new Agent()` is domain-neutral. It uses an in-memory session store and has no tools or
169
+ extensions unless they are supplied by the caller.
170
+
171
+ ```ts
172
+ import { Agent } from "@mu-agent/mu";
173
+
174
+ const agent = new Agent({
175
+ model: "anthropic/claude-sonnet-5",
176
+ budget: { maxTurns: 8, maxCostUsd: 1 },
177
+ });
178
+
179
+ const result = await agent.run("Summarize the design trade-offs");
180
+ console.log(result.text);
181
+ console.log(result.reason, result.usage);
182
+ ```
183
+
184
+ ### Coding agent
185
+
186
+ `createAgent()` adds managed `task` delegation. With `profile: "coding"`, it also loads
187
+ the shipped coding tools, project instructions, permissions, checkpoints, background
188
+ runtime, and `search`/`counsel`/`recall` specialists. Recall can access only history in the
189
+ configured session store; SDK agents use an in-memory store by default.
190
+
191
+ ```ts
192
+ import { createAgent } from "@mu-agent/mu";
193
+
194
+ const agent = await createAgent({
195
+ profile: "coding",
196
+ profileOptions: { root: process.cwd() },
197
+ budget: { maxCostUsd: 2 },
198
+ });
199
+
200
+ const result = await agent.run("Find and fix the failing test");
201
+ console.log(result.text);
202
+ await agent.shutdown();
203
+ ```
204
+
205
+ ### Browser agent
206
+
207
+ `profile: "browser"` drives a real Chrome-family browser over the Chrome DevTools Protocol:
208
+ mu's own persistent profile (`~/.mu/browser/profiles/<name>`, sign in once with
209
+ `mu browser login`) or any endpoint via `cdpUrl`. Actions that send, buy, delete, publish
210
+ or change account settings, typing into password fields, uploads and page scripts go
211
+ through `onPermission`; page content is treated as untrusted data.
212
+
213
+ ```ts
214
+ import { createAgent } from "@mu-agent/mu";
215
+
216
+ const agent = await createAgent({
217
+ profile: "browser",
218
+ profileOptions: { browserProfile: "default", headless: false },
219
+ onPermission: async (request) => (request.permission === "browser:commit" ? "deny" : "allow"),
220
+ });
221
+
222
+ const result = await agent.run("Summarize my three most recent unread emails");
223
+ console.log(result.text);
224
+ await agent.shutdown(); // the browser window stays open unless keepOpen: false
225
+ ```
226
+
227
+ Options: `browserProfile`, `connect` (`managed` | `cdp`), `cdpUrl`, `executable`,
228
+ `channel`, `headless`, `vision` (`auto` | `on` | `off`), `viewport`, `keepOpen`,
229
+ `downloadsDir`, `allowedHosts`, `blockedHosts`. The same keys are read from the `browser`
230
+ section of `~/.mu/config.json`; explicit options win.
231
+
232
+ ### Custom tools
233
+
234
+ Tools use Zod schemas. Arguments are validated before `execute`, and the schema is
235
+ converted to JSON Schema for providers.
236
+
237
+ ```ts
238
+ import { Agent, tool } from "@mu-agent/mu";
239
+ import { z } from "zod";
240
+
241
+ const add = tool({
242
+ name: "add",
243
+ description: "Add two numbers",
244
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
245
+ execute: ({ a, b }) => String(a + b),
246
+ });
247
+
248
+ const agent = new Agent({ tools: [add] });
249
+ const result = await agent.run("What is 17 + 25?");
250
+ console.log(result.text);
251
+ ```
252
+
253
+ `Agent` also supports:
254
+
255
+ - `stream()` for the same serializable event stream used by the TUI and RPC;
256
+ - Zod-validated structured output through `run(prompt, { output: schema })`;
257
+ - permission callbacks and layered permission rules;
258
+ - model, turn, token, and cost budgets;
259
+ - custom providers and models;
260
+ - `MemorySessionStore`, `FileSessionStore`, and caller-defined session stores;
261
+ - extensions, shell hooks, skills, MCP, child agents, and transcript serialization.
262
+
263
+ See the [project README](https://github.com/Spandan7724/mu#typescript-sdk) and
264
+ [source](https://github.com/Spandan7724/mu) for the complete project overview.
265
+
266
+ ## License
267
+
268
+ MIT