pal-code 0.0.17 → 0.0.18
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.
- package/README.md +9 -6
- package/SYSTEM.md +17 -2
- package/package.json +10 -5
- package/packages/cli/src/agent-ui.ts +66 -0
- package/packages/cli/src/commands/ext-registry.ts +7 -0
- package/packages/cli/src/commands.ts +31 -101
- package/packages/cli/src/components/assistant-body.ts +2 -1
- package/packages/cli/src/components/message-box.ts +1 -1
- package/packages/cli/src/components/sidebar.ts +8 -2
- package/packages/cli/src/config.ts +6 -129
- package/packages/cli/src/index.ts +130 -43
- package/packages/cli/src/overlays/key-input.ts +140 -120
- package/packages/cli/src/overlays/model-picker.ts +19 -57
- package/packages/cli/src/overlays/select.ts +102 -0
- package/packages/cli/src/overlays/session-picker.ts +12 -39
- package/packages/cli/src/overlays/wizard.ts +107 -42
- package/packages/cli/src/prompt/select.ts +181 -0
- package/packages/cli/src/slash-commands.ts +105 -0
- package/packages/cli/src/state.ts +20 -74
- package/packages/cli/src/tui/render/markdown.ts +529 -0
- package/packages/cli/src/turn.ts +0 -298
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for slash commands.
|
|
3
|
+
*
|
|
4
|
+
* Both `/help` and the editor's autocomplete read from this list. Keep it in
|
|
5
|
+
* sync with the dispatch chain in `index.ts` — `slash-commands.test.ts` scans
|
|
6
|
+
* that file and fails when a handler exists without a registry entry (or the
|
|
7
|
+
* other way around).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface SlashCommandDetail {
|
|
11
|
+
/** Text after the command name, e.g. `add <pkg>`. */
|
|
12
|
+
usage: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SlashCommand {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
/** Argument hint shown after the name, e.g. `[provider] [key]`. */
|
|
20
|
+
usage?: string;
|
|
21
|
+
aliases?: string[];
|
|
22
|
+
/** Only shown when debug mode is enabled. */
|
|
23
|
+
debugOnly?: boolean;
|
|
24
|
+
/** Subcommands rendered as indented rows under the command. */
|
|
25
|
+
details?: SlashCommandDetail[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const SLASH_COMMANDS: SlashCommand[] = [
|
|
29
|
+
{name: 'help', description: 'Show this help message', aliases: ['h']},
|
|
30
|
+
{name: 'exit', description: 'Save session and quit', aliases: ['quit']},
|
|
31
|
+
{name: 'new', description: 'Start a new session'},
|
|
32
|
+
{name: 'clear', description: 'Reset conversation'},
|
|
33
|
+
{name: 'sessions', description: 'List recent sessions'},
|
|
34
|
+
{name: 'resume', description: 'Load a previous session', usage: 'ID'},
|
|
35
|
+
{name: 'cost', description: 'Show token usage and estimated cost'},
|
|
36
|
+
{name: 'model', description: 'Switch model (picker, or pass provider/name)', usage: '[name]'},
|
|
37
|
+
{
|
|
38
|
+
name: 'key',
|
|
39
|
+
description: 'Set an API key (interactive, or provider + key)',
|
|
40
|
+
usage: '[provider] [key]',
|
|
41
|
+
aliases: ['config'],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'rotation',
|
|
45
|
+
description: 'Toggle automatic model switching on failure',
|
|
46
|
+
usage: '[on|off]',
|
|
47
|
+
},
|
|
48
|
+
{name: 'keys', description: 'Show configured API keys'},
|
|
49
|
+
{name: 'theme', description: 'Switch color theme (picker, or pass name)', usage: '[name]'},
|
|
50
|
+
{name: 'compact', description: 'Compress context when nearing the limit'},
|
|
51
|
+
{name: 'effort', description: 'Set reasoning effort', usage: 'low|medium|high'},
|
|
52
|
+
{name: 'plan', description: 'Enter read-only plan mode', usage: '[task]'},
|
|
53
|
+
{name: 'execute', description: 'Leave plan mode and implement'},
|
|
54
|
+
{name: 'undo', description: 'Restore the file from your last edit'},
|
|
55
|
+
{name: 'snapshots', description: 'List recent file snapshots'},
|
|
56
|
+
{
|
|
57
|
+
name: 'permission',
|
|
58
|
+
description: 'Show permission rules and whitelist',
|
|
59
|
+
aliases: ['perm'],
|
|
60
|
+
},
|
|
61
|
+
{name: 'copy', description: 'Copy last reply (or code block) to clipboard', usage: '[code]'},
|
|
62
|
+
{
|
|
63
|
+
name: 'ext',
|
|
64
|
+
description: 'Manage extensions',
|
|
65
|
+
details: [
|
|
66
|
+
{usage: 'add <pkg>', description: 'Install an extension from npm'},
|
|
67
|
+
{usage: 'remove <pkg>', description: 'Remove an extension'},
|
|
68
|
+
{usage: 'list', description: 'List loaded extensions'},
|
|
69
|
+
{usage: 'search <q>', description: 'Search the npm registry'},
|
|
70
|
+
{usage: 'browse', description: 'Browse curated extensions'},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'mcp',
|
|
75
|
+
description: 'Manage MCP servers',
|
|
76
|
+
details: [
|
|
77
|
+
{usage: 'add <name> <cmd> [args]', description: 'Add a local MCP server'},
|
|
78
|
+
{usage: 'add-remote <name> <url>', description: 'Add a remote MCP server'},
|
|
79
|
+
{usage: 'remove <name>', description: 'Remove an MCP server'},
|
|
80
|
+
{usage: 'list', description: 'List MCP servers'},
|
|
81
|
+
{usage: 'browse', description: 'Browse curated MCP servers'},
|
|
82
|
+
{usage: 'search <q>', description: 'Search curated MCP servers'},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{name: 'export', description: 'Export config to JSON (secrets excluded)', usage: '[file]'},
|
|
86
|
+
{name: 'import', description: 'Merge an export (local API keys kept)', usage: '<file>'},
|
|
87
|
+
{name: 'roles', description: 'List agent roles (agents extension)'},
|
|
88
|
+
{name: 'reload', description: 'Hot-reload extensions (dev)', debugOnly: true},
|
|
89
|
+
{name: 'restart', description: 'Restart pal (saves session first)', debugOnly: true},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
/** Registry entries that should be visible in the current mode. */
|
|
93
|
+
export function visibleCommands(debug = false): SlashCommand[] {
|
|
94
|
+
return SLASH_COMMANDS.filter((cmd) => debug || !cmd.debugOnly);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Items for the editor's `/` autocomplete. */
|
|
98
|
+
export function autocompleteItems(debug = false): Array<{name: string; description: string}> {
|
|
99
|
+
return visibleCommands(debug).map(({name, description}) => ({name, description}));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Resolve a name or alias (without the leading slash). */
|
|
103
|
+
export function findCommand(name: string): SlashCommand | null {
|
|
104
|
+
return SLASH_COMMANDS.find((cmd) => cmd.name === name || cmd.aliases?.includes(name)) ?? null;
|
|
105
|
+
}
|
|
@@ -1,66 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session-scoped mutable UI state.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* any one overlay impossible.
|
|
4
|
+
* The shared, frontend-agnostic part lives in `@pal-code/core`
|
|
5
|
+
* (`SharedState` / `createSharedState`). This object adds only the state the
|
|
6
|
+
* terminal frontend owns: overlays, focus, the active run block and the
|
|
7
|
+
* permission modal plumbing.
|
|
9
8
|
*
|
|
10
9
|
* Deliberately a plain object rather than exported `let` bindings: importers
|
|
11
10
|
* mutate `state.x` directly, and reads always see the current value (a plain
|
|
12
11
|
* object export is a live reference; a `let` export would be a snapshot at the
|
|
13
12
|
* import site).
|
|
14
|
-
*
|
|
15
|
-
* Only *presentation* state lives here. Anything that decides what the agent
|
|
16
|
-
* does belongs in `@pal-code/core` (see SYSTEM.md).
|
|
17
13
|
*/
|
|
18
14
|
|
|
19
|
-
import type {
|
|
20
|
-
|
|
15
|
+
import type {
|
|
16
|
+
ExtensionStatus,
|
|
17
|
+
McpServerStatus,
|
|
18
|
+
SharedState,
|
|
19
|
+
SessionTokenomics,
|
|
20
|
+
} from '@pal-code/core';
|
|
21
|
+
import {createSharedState} from '@pal-code/core';
|
|
21
22
|
import type {PermissionPrompt} from './components/permission-prompt.js';
|
|
23
|
+
import type {RunView} from './components/run-view.js';
|
|
24
|
+
|
|
25
|
+
export type {BackgroundAgent, TodoItem} from '@pal-code/core';
|
|
26
|
+
export type ExtensionInfo = ExtensionStatus;
|
|
27
|
+
export type McpServerInfo = McpServerStatus;
|
|
22
28
|
|
|
23
|
-
export type OverlayMode = 'none' | '
|
|
29
|
+
export type OverlayMode = 'none' | 'select' | 'key-input' | 'agents' | 'permission';
|
|
24
30
|
|
|
25
31
|
/**
|
|
26
32
|
* Name of the active **primary agent** (the one the user talks to, cycled with
|
|
27
|
-
* Tab). Populated from the orchestration extension at load time
|
|
28
|
-
* 'pal' (the orchestrator) when no extension provides primaries.
|
|
33
|
+
* Tab). Populated from the orchestration extension at load time.
|
|
29
34
|
*
|
|
30
35
|
* Not to be confused with a delegation role — see `@pal-code/core`'s `PrimarySpec`.
|
|
31
36
|
*/
|
|
32
37
|
export type AgentRole = string;
|
|
33
38
|
|
|
34
|
-
export interface
|
|
35
|
-
id: string;
|
|
36
|
-
task: string;
|
|
37
|
-
status: 'running' | 'done' | 'error';
|
|
38
|
-
startedAt: number;
|
|
39
|
-
finishedAt?: number;
|
|
40
|
-
result?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface TodoItem {
|
|
44
|
-
content: string;
|
|
45
|
-
status: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface ExtensionInfo {
|
|
49
|
-
/** Extension package name (e.g. '@pal-code/web-search'). */
|
|
50
|
-
name: string;
|
|
51
|
-
/** Whether the extension loaded successfully and its tools are available. */
|
|
52
|
-
active: boolean;
|
|
53
|
-
/** Why loading failed, when `active` is false. */
|
|
54
|
-
reason?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface McpServerInfo {
|
|
58
|
-
name: string;
|
|
59
|
-
status: 'connected' | 'error' | 'starting';
|
|
60
|
-
toolCount: number;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface AppState {
|
|
39
|
+
export interface AppState extends SharedState {
|
|
64
40
|
/** Which overlay (if any) currently owns the editor area. */
|
|
65
41
|
overlayMode: OverlayMode;
|
|
66
42
|
/** Bound by `main()`; re-renders the status line. */
|
|
@@ -69,12 +45,6 @@ export interface AppState {
|
|
|
69
45
|
refreshSidebar: () => void;
|
|
70
46
|
/** Bound by `main()`; re-reads keys and rebuilds the provider after `/key`. */
|
|
71
47
|
reloadKeys: (() => void) | null;
|
|
72
|
-
/** Title of the current session, shown at the top of the sidebar. */
|
|
73
|
-
sessionTitle: string | null;
|
|
74
|
-
/** Latest todo list from the `todos-updated` event. */
|
|
75
|
-
currentTodos: readonly TodoItem[];
|
|
76
|
-
/** Sub-agents spawned by `delegate`, shown in the ctrl+b panel. */
|
|
77
|
-
backgroundAgents: BackgroundAgent[];
|
|
78
48
|
/** The run block for the in-flight turn. */
|
|
79
49
|
activeRun: RunView | null;
|
|
80
50
|
/** Cancels the in-flight turn (Esc). */
|
|
@@ -85,20 +55,12 @@ export interface AppState {
|
|
|
85
55
|
lastRun: RunView | null;
|
|
86
56
|
/** Messages submitted while a turn was running; drained one per settled turn. */
|
|
87
57
|
pendingMessages: string[];
|
|
88
|
-
/** Loaded extensions and their status. */
|
|
89
|
-
extensions: ExtensionInfo[];
|
|
90
|
-
/** MCP servers discovered during startup. */
|
|
91
|
-
mcpServers: McpServerInfo[];
|
|
92
|
-
/** Currently selected primary agent (see AgentRole). */
|
|
93
|
-
currentAgentRole: AgentRole;
|
|
94
58
|
/** Bound by `main()`; re-renders the input role indicator after extensions load. */
|
|
95
59
|
refreshRoleIndicator: () => void;
|
|
96
60
|
/** Bound by `main()`; shows the centered permission modal overlay. */
|
|
97
61
|
showPermissionModal: () => void;
|
|
98
62
|
|
|
99
63
|
// ── Permission system ──
|
|
100
|
-
/** Session-scoped "always allow" entries. Cleared on /new. */
|
|
101
|
-
permissionWhitelist: Array<{tool: string; pattern: string}>;
|
|
102
64
|
/** Resolves an async permission prompt (set by main()). Returns 'allow' | 'deny'. */
|
|
103
65
|
permissionResolver: ((allow: boolean) => void) | null;
|
|
104
66
|
/** Context for the current permission overlay (shown in the prompt). */
|
|
@@ -112,41 +74,25 @@ export interface AppState {
|
|
|
112
74
|
target: string;
|
|
113
75
|
summary: string;
|
|
114
76
|
}>;
|
|
115
|
-
|
|
116
|
-
// ── Session-scoped tokenomics ──
|
|
117
|
-
/**
|
|
118
|
-
* Accumulated token usage and cost for the *current* session only — the
|
|
119
|
-
* sidebar stats, `/cost`, and `saveSession` all read this single object.
|
|
120
|
-
* Zeroed on `/new`, restored when a session is resumed, and persisted with
|
|
121
|
-
* the session row on every save.
|
|
122
|
-
*/
|
|
123
|
-
sessionTokenomics: SessionTokenomics;
|
|
124
77
|
}
|
|
125
78
|
|
|
126
79
|
export const state: AppState = {
|
|
80
|
+
...createSharedState(),
|
|
127
81
|
overlayMode: 'none',
|
|
128
82
|
refreshStatusLine: () => {},
|
|
129
83
|
refreshSidebar: () => {},
|
|
130
84
|
reloadKeys: null,
|
|
131
|
-
sessionTitle: null,
|
|
132
|
-
currentTodos: [],
|
|
133
|
-
backgroundAgents: [],
|
|
134
85
|
activeRun: null,
|
|
135
86
|
activeAbort: null,
|
|
136
87
|
abortArmed: false,
|
|
137
88
|
lastRun: null,
|
|
138
89
|
pendingMessages: [],
|
|
139
|
-
extensions: [],
|
|
140
|
-
mcpServers: [],
|
|
141
|
-
currentAgentRole: 'pal',
|
|
142
90
|
refreshRoleIndicator: () => {},
|
|
143
91
|
showPermissionModal: () => {},
|
|
144
|
-
permissionWhitelist: [],
|
|
145
92
|
permissionResolver: null,
|
|
146
93
|
pendingPermission: null,
|
|
147
94
|
permissionPrompt: null,
|
|
148
95
|
permissionQueue: [],
|
|
149
|
-
sessionTokenomics: {inputTokens: 0, outputTokens: 0, cachedTokens: 0, cost: 0},
|
|
150
96
|
};
|
|
151
97
|
|
|
152
98
|
/**
|