pal-code 0.0.5

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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/SYSTEM.md +146 -0
  4. package/bin/pal-code.js +131 -0
  5. package/package.json +68 -0
  6. package/packages/cli/README.md +77 -0
  7. package/packages/cli/src/agent-panel.ts +94 -0
  8. package/packages/cli/src/commands/ext.ts +79 -0
  9. package/packages/cli/src/commands/mcp-registry.ts +136 -0
  10. package/packages/cli/src/commands/mcp.ts +186 -0
  11. package/packages/cli/src/commands.ts +153 -0
  12. package/packages/cli/src/components/message-box.ts +35 -0
  13. package/packages/cli/src/components/permission-prompt.ts +185 -0
  14. package/packages/cli/src/components/render-history.ts +143 -0
  15. package/packages/cli/src/components/run-view.ts +256 -0
  16. package/packages/cli/src/components/sidebar.ts +120 -0
  17. package/packages/cli/src/components/status-line.ts +26 -0
  18. package/packages/cli/src/config.ts +107 -0
  19. package/packages/cli/src/index.ts +1606 -0
  20. package/packages/cli/src/overlays/key-input.ts +167 -0
  21. package/packages/cli/src/overlays/model-picker.ts +106 -0
  22. package/packages/cli/src/overlays/session-picker.ts +168 -0
  23. package/packages/cli/src/overlays/wizard.ts +145 -0
  24. package/packages/cli/src/state.ts +133 -0
  25. package/packages/cli/src/theme.ts +88 -0
  26. package/packages/cli/src/turn.ts +266 -0
  27. package/packages/cli/src/utils/cost.ts +111 -0
  28. package/packages/cli/src/utils/format.test.ts +167 -0
  29. package/packages/cli/src/utils/format.ts +248 -0
  30. package/packages/cli/src/utils/highlight.ts +358 -0
  31. package/packages/cli/src/utils/permissions.ts +196 -0
  32. package/packages/core/src/agent/events.ts +36 -0
  33. package/packages/core/src/agent/fallback.test.ts +99 -0
  34. package/packages/core/src/agent/fallback.ts +344 -0
  35. package/packages/core/src/agent/index.ts +35 -0
  36. package/packages/core/src/agent/protocol.test.ts +136 -0
  37. package/packages/core/src/agent/resume-compaction.test.ts +116 -0
  38. package/packages/core/src/agent/roles.ts +188 -0
  39. package/packages/core/src/agent/run.test.ts +207 -0
  40. package/packages/core/src/agent/run.ts +713 -0
  41. package/packages/core/src/agent/scope.ts +34 -0
  42. package/packages/core/src/agent/todos.ts +66 -0
  43. package/packages/core/src/compaction.protocol.test.ts +90 -0
  44. package/packages/core/src/compaction.test.ts +101 -0
  45. package/packages/core/src/compaction.ts +243 -0
  46. package/packages/core/src/config.test.ts +40 -0
  47. package/packages/core/src/config.ts +387 -0
  48. package/packages/core/src/extensions.ts +178 -0
  49. package/packages/core/src/index.ts +157 -0
  50. package/packages/core/src/logger.ts +54 -0
  51. package/packages/core/src/provider/auth.ts +153 -0
  52. package/packages/core/src/provider/complete.ts +63 -0
  53. package/packages/core/src/provider/index.ts +6 -0
  54. package/packages/core/src/provider/openrouter.test.ts +59 -0
  55. package/packages/core/src/provider/openrouter.ts +304 -0
  56. package/packages/core/src/provider/pick-model.ts +43 -0
  57. package/packages/core/src/provider/registry.ts +222 -0
  58. package/packages/core/src/provider/types.ts +61 -0
  59. package/packages/core/src/repo-map.ts +177 -0
  60. package/packages/core/src/session/index.ts +2 -0
  61. package/packages/core/src/session/migration.test.ts +104 -0
  62. package/packages/core/src/session/store-v2-repair.test.ts +209 -0
  63. package/packages/core/src/session/store.test.ts +235 -0
  64. package/packages/core/src/session/store.ts +677 -0
  65. package/packages/core/src/session/types.ts +72 -0
  66. package/packages/core/src/snapshots.ts +107 -0
  67. package/packages/core/src/tools/definitions.ts +365 -0
  68. package/packages/core/src/tools/executor.test.ts +122 -0
  69. package/packages/core/src/tools/executor.ts +1363 -0
  70. package/packages/core/src/tools/index.ts +5 -0
  71. package/packages/core/src/tools/search.ts +201 -0
  72. package/scripts/postinstall.js +121 -0
  73. package/scripts/preinstall.js +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pal-code contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # pal-code
2
+
3
+ A terminal coding agent with tool use, built in TypeScript on Bun.
4
+
5
+ pal-code runs in your project, reads your files, and can edit them — all through a
6
+ streaming TUI. It's BYOK (bring your own key) and speaks the OpenAI-compatible
7
+ Chat Completions API, so one adapter drives DeepSeek, Gemini, OpenRouter,
8
+ OpenCode Zen, OpenAI, Groq, xAI, and Mistral.
9
+
10
+ ## Requirements
11
+
12
+ **Bun ≥ 1.1 is required.** pal-code uses Bun's built-in modules and cannot run on Node.js.
13
+
14
+ ### Install Bun
15
+
16
+ **macOS / Linux:**
17
+ ```bash
18
+ curl -fsSL https://bun.sh/install | bash
19
+ ```
20
+
21
+ **Windows (PowerShell):**
22
+ ```powershell
23
+ powershell -c "irm bun.sh/install.ps1 | iex"
24
+ ```
25
+
26
+ **Other methods:**
27
+ - npm: `npm install -g bun`
28
+ - Homebrew: `brew install oven-sh/bun/bun`
29
+ - Docker: `oven/bun`
30
+
31
+ Verify Bun is installed:
32
+ ```bash
33
+ bun --version # Should print 1.1 or higher
34
+ ```
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ npm install -g pal-code
40
+ ```
41
+
42
+ Or with Bun:
43
+ ```bash
44
+ bun add -g pal-code
45
+ ```
46
+
47
+ ## Run
48
+
49
+ ```bash
50
+ pal
51
+ ```
52
+
53
+ On first launch, pal-code runs a short setup wizard. Pick a provider and paste an API
54
+ key (or press Enter for a keyless provider like OpenCode Zen).
55
+
56
+ ## Features
57
+
58
+ - **TUI** built on `@earendil-works/pi-tui` with streaming markdown, a model
59
+ picker, session selector, and a live status line (tokens, cache-hit %, cost).
60
+ - **Tool use** — read/write/edit files, run shell commands, grep/glob/ast-grep
61
+ search, repo maps, `verify`, and `delegate` sub-agents.
62
+ - **BYOK provider registry** with key-shape detection, live `/models` fetching,
63
+ curated fallback model lists, and retry/backoff with quota-vs-rate-limit-aware
64
+ fallback switching.
65
+ - **Safety & context** — `.pal.json` ignore patterns, file-size limits, file
66
+ snapshots for `/undo`, context compaction, and secret-redacting debug logs.
67
+ - **Sessions** — SQLite-backed (`bun:sqlite`) with resume via `/sessions` or
68
+ `/resume <id>`.
69
+ - **Extensions** — install additional tools like web search and multi-agent orchestration.
70
+ - **MCP** — connect to Model Context Protocol servers for external tool integrations.
71
+
72
+ ## Extensions
73
+
74
+ Install extensions from any directory:
75
+
76
+ ```bash
77
+ pal add @pal/web-search # Web search tools (fetch_url, web_search)
78
+ pal add @pal/agents # Multi-agent orchestration (delegate, explore, etc.)
79
+ ```
80
+
81
+ Extensions are installed to `~/.pal/extensions/` and persist across sessions.
82
+
83
+ ## MCP (Model Context Protocol)
84
+
85
+ Add MCP servers for external tool integrations:
86
+
87
+ ```bash
88
+ pal mcp add filesystem npx @anthropic-ai/mcp-server-filesystem /path/to/dir
89
+ pal mcp add github npx @anthropic-ai/mcp-server-github
90
+ ```
91
+
92
+ MCP config is stored in `~/.pal/mcp.json` (user-level) or `./mcp.json` (project-level).
93
+
94
+ ## Configuration
95
+
96
+ API keys are resolved from (in order):
97
+
98
+ 1. Environment variables — `DEEPSEEK_API_KEY`, `GEMINI_API_KEY`,
99
+ `OPENROUTER_API_KEY`, `ZEN_API_KEY`, `OPENAI_API_KEY`, `GROQ_API_KEY`,
100
+ `XAI_API_KEY`, `MISTRAL_API_KEY`.
101
+ 2. `~/.pal/config.json` — `{ "keys": { "<provider>": "<key>" } }`.
102
+
103
+ Keyless providers are opted into by setting `"keyless": "<provider-id>"`.
104
+
105
+ ### Data storage
106
+
107
+ All user data lives in `~/.pal/`:
108
+
109
+ ```
110
+ ~/.pal/
111
+ config.json # API keys, default model, extensions list
112
+ sessions.db # Conversation history (SQLite)
113
+ mcp.json # MCP server configuration
114
+ extensions/ # Installed extension packages
115
+ snapshots/ # File backups for /undo
116
+ logs/ # Debug logs (when PAL_DEBUG=1)
117
+ ```
118
+
119
+ ## Slash commands
120
+
121
+ | Command | Action |
122
+ |---|---|
123
+ | `/help` | Show commands |
124
+ | `/model` | Open the model picker |
125
+ | `/model NAME` | Set a model directly |
126
+ | `/key` | Set an API key interactively |
127
+ | `/keys` | Show configured keys |
128
+ | `/sessions` / `/resume ID` | List / resume sessions |
129
+ | `/snapshots` / `/undo [id]` | Restore a pre-edit file |
130
+ | `/compact` | Compress conversation context |
131
+ | `/effort low\|medium\|high` | Set reasoning effort |
132
+ | `/cost` | Show token usage and estimated cost |
133
+ | `/clear` | Start a fresh session |
134
+ | `/exit` | Save and quit |
135
+
136
+ ## Architecture
137
+
138
+ **Logic lives in `@pal/core`; rendering lives in `@pal/cli`.**
139
+
140
+ The one agent loop (`runAgent`) lives in core and streams events; the CLI only
141
+ renders them. Full rules, the event protocol, and the termination/interrupt
142
+ design are in **[`SYSTEM.md`](./SYSTEM.md)**.
143
+
144
+ ## Development
145
+
146
+ ```bash
147
+ bun test # run the test suite
148
+ bunx tsc --noEmit # typecheck
149
+ ```
150
+
151
+ ### Layout
152
+
153
+ ```
154
+ packages/
155
+ core/ # agent loop, providers, tools, session, compaction, snapshots
156
+ cli/ # the TUI front-end (rendering only)
157
+ mcp/ # MCP client integration
158
+ web-search/ # Web search extension
159
+ agents/ # Multi-agent orchestration extension
160
+ ```
161
+
162
+ ## License
163
+
164
+ MIT
165
+
166
+ ## Roadmap
167
+
168
+ See [`EXTENSIONS.md`](./EXTENSIONS.md) for the extension roadmap (MCP, ACP,
169
+ session handoff, sandboxing, and OMO-style orchestration).
package/SYSTEM.md ADDED
@@ -0,0 +1,146 @@
1
+ # pal — System
2
+
3
+ How pal is put together, and the rules that keep it that way.
4
+
5
+ ## The boundary rule
6
+
7
+ **Logic lives in `@pal/core`. Rendering lives in `@pal/cli`.**
8
+
9
+ This is the single most important rule in the codebase. Every capability has
10
+ exactly one home, and the split is by *responsibility*, not convenience:
11
+
12
+ | Lives in `@pal/core` | Lives in `@pal/cli` |
13
+ |---|---|
14
+ | The agent loop (`runAgent`) | The pi-tui `RunView`, todo panel, status bar |
15
+ | Tool implementations + `executeTool` | Slash-command parsing and command output |
16
+ | Provider registry, streaming, retry/fallback policy | Model picker / session picker overlays |
17
+ | Conversation shape (`ConversationMessage`), compaction | Keybindings (Esc, ctrl+b, ctrl+o) |
18
+ | Session persistence (`bun:sqlite`) | Session browser UI |
19
+ | Snapshots, logging, cost math | Formatting tokens/cost for display |
20
+
21
+ Consequences:
22
+
23
+ - A front-end **must never reimplement engine behaviour**. If two front-ends
24
+ would both need it, it belongs in core.
25
+ - Core **must never import a TUI**. `@pal/core` has no knowledge of pi-tui.
26
+ - The **only vocabulary** between the layers is the event stream below.
27
+
28
+ If you are unsure where something goes, ask: *does this decide what the agent
29
+ does, or does it only show the agent?* Decide → core. Show → cli.
30
+
31
+ ## One loop
32
+
33
+ `runAgent(opts)` in `packages/core/src/agent/run.ts` is the **only** agent loop.
34
+ Both the interactive CLI and the `delegate` sub-agent drive it:
35
+
36
+ ```ts
37
+ for await (const ev of runAgent({messages, tools, provider, model, signal, ...})) {
38
+ // render — do not reason
39
+ }
40
+ ```
41
+
42
+ It owns:
43
+
44
+ - the round loop and the round cap
45
+ - context compaction (`shouldCompact` / `compactMessages`)
46
+ - message shaping, including echoing Gemini's `thought_signature`
47
+ - parallel vs sequential tool dispatch (read-only tools run concurrently)
48
+ - loop detection (identical tool calls)
49
+ - usage accumulation
50
+ - interrupt handling
51
+
52
+ `executeTool` is **injected** by the caller, so `run.ts` never imports the tool
53
+ registry — that would create a cycle (`executor → run → executor`).
54
+
55
+ ### Termination
56
+
57
+ The loop runs until the model stops requesting tools. Two backstops:
58
+
59
+ 1. **Round cap** — `maxRounds` (default 100). Hitting it degrades *gracefully*:
60
+ the loop injects a wrap-up instruction and makes one final call with tools
61
+ withheld, so the user gets a summary instead of a wall of tool calls.
62
+ 2. **Interrupt** — an `AbortSignal` cancels the in-flight provider request and
63
+ skips queued tools. The CLI binds this to **Esc**. The session survives.
64
+
65
+ ## Event protocol
66
+
67
+ `runAgent` yields `AgentRunEvent`s and never touches the screen:
68
+
69
+ | Event | Meaning |
70
+ |---|---|
71
+ | `model-start` | A model was selected for this attempt (`runWithFallback` only) |
72
+ | `round-start` | A new model call is beginning (`round` / `max`) |
73
+ | `text-delta` | Streamed assistant text |
74
+ | `tool-start` / `tool-end` | A tool call began / finished (result + duration) |
75
+ | `notice` | System-level message (compaction, loop detection, cap, wrap-up) |
76
+ | `aborted` | The user interrupted the turn |
77
+ | `done` | Turn finished, with usage totals |
78
+
79
+ Adding a front-end means consuming this stream. Adding a capability means
80
+ extending it — not reaching around it.
81
+
82
+ ## Reliability: `runWithFallback`
83
+
84
+ `runAgent` drives **one** model. `runWithFallback` (`agent/fallback.ts`) is the
85
+ policy layer that keeps a turn alive across providers:
86
+
87
+ ```
88
+ runWithFallback → decides which model, retries, backoff (core)
89
+ └─ runAgent → drives that model to completion (core)
90
+ ```
91
+
92
+ - **Same provider first** (same rate-limit pool), then other configured
93
+ providers — the candidate list is built from each provider's live `/models`,
94
+ never from invented names.
95
+ - **Quota exhausted** → switch immediately (retrying only burns RPM).
96
+ - **Rate limited** → exponential backoff, `maxRetries` attempts, then switch.
97
+ - **Anything else** → rethrow.
98
+
99
+ It yields `runAgent`'s events plus `model-start` (so the UI can relabel the run
100
+ with the model actually serving it) and `notice` for each fallback decision.
101
+
102
+ This lives in core precisely because it *decides*: the CLI's only job is to
103
+ render those events.
104
+
105
+ ## Run scope
106
+
107
+ Core keeps a little module-level state for ergonomics: the todo list
108
+ (`agent/todos.ts`) and the tracked shell cwd (`tools/executor.ts`).
109
+
110
+ That is safe for a single interactive turn, but `delegate` starts a **nested**
111
+ run in the same process — a child calling `todo` or `cd` would otherwise
112
+ clobber the parent's plan and working directory. `agent/scope.ts` provides
113
+ `captureRunScope()` / `restoreRunScope()`; `delegate` wraps the child in them
114
+ and re-emits `todos-updated` so the UI re-syncs to the parent's list.
115
+
116
+ ## Ignores are universal
117
+
118
+ `.pal.json` `ignore` patterns are enforced by **every** file-touching tool —
119
+ `read_file`, `list_directory`, `grep`, `grep_search`, `glob_search`,
120
+ `repo_map`. The pure-JS walkers take an `isIgnored` predicate; the ripgrep
121
+ paths append `--glob '!pat'` **after** any include glob (ripgrep resolves
122
+ overlapping globs by last-match-wins, so excludes must come last).
123
+
124
+ Symlinked directories are never followed (`Dirent` uses lstat semantics), so
125
+ directory cycles are impossible.
126
+
127
+ ## Layout
128
+
129
+ ```
130
+ packages/
131
+ core/ # agent loop, providers, tools, session, compaction, snapshots
132
+ cli/ # the TUI front-end (rendering only)
133
+ ```
134
+
135
+ ## Development
136
+
137
+ ```bash
138
+ bun test # run the test suite
139
+ bunx tsc --noEmit # typecheck
140
+ ```
141
+
142
+ ## See also
143
+
144
+ - [`README.md`](./README.md) — what pal is, install, commands
145
+ - [`EXTENSIONS.md`](./EXTENSIONS.md) — the extension roadmap (MCP, ACP, session
146
+ handoff, sandboxing, OMO-style orchestration)
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * pal-code launcher
5
+ *
6
+ * This thin wrapper detects the current platform and spawns the appropriate
7
+ * compiled binary. Users run `pal` after `npm install -g pal-code`.
8
+ *
9
+ * The actual binary is built with `bun build --compile` and ships as a
10
+ * platform-specific optional dependency (see optionalDependencies below).
11
+ */
12
+
13
+ const { spawn } = require('child_process');
14
+ const { existsSync, readFileSync } = require('fs');
15
+ const { join, dirname } = require('path');
16
+
17
+ // Fast version check — before any binary lookup
18
+ const argv = process.argv.slice(2);
19
+ if (argv[0] === '--version' || argv[0] === '-v' || argv[0] === '--v' || argv[0] === '-version') {
20
+ try {
21
+ const pkg = require('../package.json');
22
+ console.log(`pal-code v${pkg.version}`);
23
+ } catch {
24
+ console.log('pal-code (unknown version)');
25
+ }
26
+ process.exit(0);
27
+ }
28
+
29
+ // Platform detection
30
+ function getPlatform() {
31
+ const platform = process.platform; // 'darwin', 'linux', 'win32'
32
+ const arch = process.arch; // 'arm64', 'x64', 'arm'
33
+
34
+ const platformMap = {
35
+ 'darwin-arm64': 'darwin-arm64',
36
+ 'darwin-x64': 'darwin-x64',
37
+ 'linux-x64': 'linux-x64',
38
+ 'linux-arm64': 'linux-arm64',
39
+ 'win32-x64': 'windows-x64',
40
+ };
41
+
42
+ const key = `${platform}-${arch}`;
43
+ return platformMap[key] || null;
44
+ }
45
+
46
+ // Find the binary
47
+ function findBinary() {
48
+ const platform = getPlatform();
49
+ if (!platform) {
50
+ console.error(`Error: Unsupported platform ${process.platform}-${process.arch}`);
51
+ console.error('Supported platforms: darwin-arm64, darwin-x64, linux-x64, linux-arm64, windows-x64');
52
+ process.exit(1);
53
+ }
54
+
55
+ // Try to find the platform binary via require.resolve
56
+ try {
57
+ const pkgName = `pal-code-${platform}`;
58
+ const pkgPath = require.resolve(`${pkgName}/package.json`);
59
+ const pkgDir = dirname(pkgPath);
60
+ const binName = platform === 'windows-x64' ? 'pal.exe' : 'pal';
61
+ const binPath = join(pkgDir, 'bin', binName);
62
+
63
+ if (existsSync(binPath)) {
64
+ return binPath;
65
+ }
66
+ } catch (e) {
67
+ // Package not found, try fallback
68
+ }
69
+
70
+ // Fallback: look for compiled binary in dist/
71
+ const distDir = join(dirname(__dirname), 'dist');
72
+ const binName = platform === 'windows-x64' ? 'pal.exe' : 'pal';
73
+ const distBin = join(distDir, binName);
74
+
75
+ if (existsSync(distBin)) {
76
+ return distBin;
77
+ }
78
+
79
+ // Fallback: check if bun is available and run source directly
80
+ const { execSync } = require('child_process');
81
+ try {
82
+ execSync('bun --version', { stdio: 'ignore' });
83
+ const srcPath = join(__dirname, '../packages/cli/src/index.ts');
84
+ if (existsSync(srcPath)) {
85
+ console.error('pal-code: Using Bun runtime (binary not found, falling back to source)');
86
+ return 'bun';
87
+ }
88
+ } catch (e) {
89
+ // Bun not available
90
+ }
91
+
92
+ console.error('Error: pal binary not found.');
93
+ console.error('Please reinstall: npm install -g pal-code');
94
+ console.error('Or install Bun and run from source: bun add -g pal-code');
95
+ process.exit(1);
96
+ }
97
+
98
+ // Main
99
+ const binary = findBinary();
100
+
101
+ if (binary === 'bun') {
102
+ // Running from source via Bun
103
+ const srcPath = join(__dirname, '../packages/cli/src/index.ts');
104
+ const args = [srcPath, ...process.argv.slice(2)];
105
+
106
+ const child = spawn('bun', args, {
107
+ stdio: 'inherit',
108
+ env: process.env,
109
+ });
110
+
111
+ child.on('exit', (code) => {
112
+ process.exit(code || 0);
113
+ });
114
+ } else {
115
+ // Running compiled binary
116
+ const args = process.argv.slice(2);
117
+
118
+ const child = spawn(binary, args, {
119
+ stdio: 'inherit',
120
+ env: process.env,
121
+ });
122
+
123
+ // Forward signals
124
+ process.on('SIGINT', () => child.kill('SIGINT'));
125
+ process.on('SIGTERM', () => child.kill('SIGTERM'));
126
+ process.on('SIGHUP', () => child.kill('SIGHUP'));
127
+
128
+ child.on('exit', (code) => {
129
+ process.exit(code || 0);
130
+ });
131
+ }
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "pal-code",
3
+ "version": "0.0.5",
4
+ "description": "A terminal coding agent with BYOK, tool use, and extensions",
5
+ "license": "MIT",
6
+ "engines": {
7
+ "bun": ">=1.1.0"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/fngadiyo/the-agent.git"
12
+ },
13
+ "bin": {
14
+ "pal": "./bin/pal-code.js"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "scripts/",
19
+ "packages/cli/src/**/*.ts",
20
+ "packages/cli/src/**/*.tsx",
21
+ "packages/core/src/**/*.ts",
22
+ "packages/core/src/**/*.tsx",
23
+ "!packages/core/src/**/*.test.db",
24
+ "!packages/core/src/**/*.test-*.db",
25
+ "SYSTEM.md",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "scripts": {
30
+ "start": "cd packages/cli && bun src/index.ts",
31
+ "dev": "cd packages/cli && bun src/index.ts",
32
+ "test": "bun test",
33
+ "typecheck": "bunx tsc --noEmit",
34
+ "lint": "biome check .",
35
+ "lint:fix": "biome check --write .",
36
+ "format": "biome format --write .",
37
+ "check": "bun run typecheck && bun run lint && bun test",
38
+ "build": "bun run build:darwin-arm64 && bun run build:darwin-x64 && bun run build:linux-x64 && bun run build:linux-arm64 && bun run build:windows-x64",
39
+ "build:darwin-arm64": "bun build --compile packages/cli/src/index.ts --target=bun-darwin-arm64 --outfile dist/pal-darwin-arm64",
40
+ "build:darwin-x64": "bun build --compile packages/cli/src/index.ts --target=bun-darwin-x64 --outfile dist/pal-darwin-x64",
41
+ "build:linux-x64": "bun build --compile packages/cli/src/index.ts --target=bun-linux-x64 --outfile dist/pal-linux-x64",
42
+ "build:linux-arm64": "bun build --compile packages/cli/src/index.ts --target=bun-linux-arm64 --outfile dist/pal-linux-arm64",
43
+ "build:windows-x64": "bun build --compile packages/cli/src/index.ts --target=bun-windows-x64 --outfile dist/pal-windows-x64.exe",
44
+ "publish:all": "npm publish && npm run publish:web-search && npm run publish:agents && npm run publish:mcp",
45
+ "publish:web-search": "cd packages/web-search && npm publish",
46
+ "publish:agents": "cd packages/agents && npm publish",
47
+ "publish:mcp": "cd packages/mcp && npm publish",
48
+ "preinstall": "node scripts/preinstall.js",
49
+ "postinstall": "node scripts/postinstall.js"
50
+ },
51
+ "keywords": [
52
+ "ai",
53
+ "coding",
54
+ "agent",
55
+ "terminal",
56
+ "cli",
57
+ "llm",
58
+ "deepseek",
59
+ "openai",
60
+ "anthropic",
61
+ "gemini"
62
+ ],
63
+ "devDependencies": {
64
+ "@biomejs/biome": "^2.5.13",
65
+ "@types/bun": "latest",
66
+ "typescript": "^5.6.0"
67
+ }
68
+ }
@@ -0,0 +1,77 @@
1
+ # @pal/cli
2
+
3
+ Terminal UI for the [pal](../..) coding agent. This package provides the TUI
4
+ interface — streaming markdown display, editor, model picker, session selector,
5
+ and live status line — while [`@pal/core`](../core) supplies the provider
6
+ abstraction, session store, agent loop, and tools.
7
+
8
+ ## Quick start
9
+
10
+ ```bash
11
+ bun install
12
+ bun start # or: cd packages/cli && bun src/index.ts
13
+ ```
14
+
15
+ On first launch, pal runs a setup wizard. Pick a provider and paste an API key
16
+ (or press Enter for a keyless provider).
17
+
18
+ ## Source layout
19
+
20
+ ```
21
+ src/
22
+ index.ts Entry point and main()
23
+ config.ts CLI configuration (env → file → defaults)
24
+ state.ts Shared mutable UI state
25
+ turn.ts Agent turn loop and extension loading
26
+ commands.ts Slash-command renderers (/help, /cost)
27
+ theme.ts ANSI colors and editor theme
28
+ agent-panel.ts Background agents overlay (ctrl+b)
29
+
30
+ utils/
31
+ cost.ts Token cost estimation and formatting
32
+ format.ts Text truncation, wrapping, message boxes
33
+ highlight.ts Syntax highlighting
34
+ format.test.ts Tests for format.ts
35
+
36
+ components/
37
+ message-box.ts User message display component
38
+ run-view.ts Agent turn rendering (streaming markdown)
39
+ sidebar.ts Right sidebar (todos, stats, info)
40
+ status-line.ts Bottom status bar
41
+
42
+ overlays/
43
+ key-input.ts API key input dialog
44
+ model-picker.ts Model selection overlay
45
+ session-picker.ts Session list and resume
46
+ wizard.ts First-run setup wizard
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ | Command | Description |
52
+ |---------|-------------|
53
+ | `/help` | Show available commands |
54
+ | `/model` | Switch model (interactive picker or `/model provider/name`) |
55
+ | `/key` | Add or change an API key |
56
+ | `/keys` | Show configured keys |
57
+ | `/sessions` | List and resume past sessions |
58
+ | `/clear` | Reset conversation |
59
+ | `/compact` | Compress context when nearing the limit |
60
+ | `/undo` | Restore the most recent file snapshot |
61
+ | `/cost` | Show token usage and estimated cost |
62
+ | `/effort low\|medium\|high` | Set reasoning effort |
63
+ | `/plan <task>` | Enter read-only planning mode |
64
+ | `/execute` | Return to implementation mode |
65
+ | `/reload` | Hot-reload extensions (debug mode only) |
66
+ | `/restart` | Save and relaunch (debug mode only) |
67
+ | `exit` | Save session and quit |
68
+
69
+ ## Keybindings
70
+
71
+ | Key | Action |
72
+ |-----|--------|
73
+ | `Tab` | Cycle primary agent (when editor is empty) |
74
+ | `Esc` | Abort a running turn |
75
+ | `Ctrl+B` | Toggle background agents panel |
76
+ | `Ctrl+O` | Re-expand last collapsed run |
77
+ | `Ctrl+C` / `Ctrl+D` | Exit (when editor is empty) |