pal-code 0.0.19 → 0.0.21
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 +4 -0
- package/assets/pal-herdr.svg +14 -0
- package/assets/pal.svg +46 -0
- package/bin/pal-code.js +15 -1
- package/package.json +3 -2
- package/packages/cli/src/agent-ui.ts +10 -0
- package/packages/cli/src/index.ts +215 -37
- package/packages/cli/src/overlays/model-picker.ts +3 -0
- package/packages/cli/src/state.ts +13 -0
- package/packages/cli/src/theme.ts +1 -1
- package/packages/cli/src/themes/github-dark.ts +1 -0
- package/packages/cli/src/themes/github-light.ts +187 -0
- package/packages/cli/src/themes/index.ts +49 -8
- package/packages/cli/src/themes/types.ts +13 -0
- package/packages/cli/src/themes/vanilla-pi.ts +25 -18
- package/packages/cli/src/utils/cost.ts +17 -86
- package/packages/cli/src/utils/osc-canvas.ts +79 -0
- package/packages/cli/src/utils/osc-status.ts +178 -0
- package/packages/cli/src/utils/permissions.ts +13 -0
- package/packages/cli/src/utils/status-report.ts +125 -0
package/README.md
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="pal">
|
|
2
|
+
<title>pal</title>
|
|
3
|
+
<!--
|
|
4
|
+
pal in Herdr's agents list and on pane borders.
|
|
5
|
+
|
|
6
|
+
A prompt caret inside a rounded terminal frame: the same silhouette as the
|
|
7
|
+
`>_` a terminal agent lives behind, drawn as a single-color glyph so
|
|
8
|
+
Herdr can tint it with `svg(icon)` and put it on a colored tile.
|
|
9
|
+
Sized to the 24x24 grid Herdr's own icons use.
|
|
10
|
+
-->
|
|
11
|
+
<rect x="2.4" y="3.6" width="19.2" height="16.8" rx="3.2" />
|
|
12
|
+
<path d="M7.2 8.9 10.4 12l-3.2 3.1" />
|
|
13
|
+
<path d="M12.9 15.1h4" />
|
|
14
|
+
</svg>
|
package/assets/pal.svg
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128" role="img" aria-label="pal">
|
|
2
|
+
<title>pal</title>
|
|
3
|
+
<!--
|
|
4
|
+
The pal mark.
|
|
5
|
+
|
|
6
|
+
A caret and an underscore inside a terminal frame — `>_`, the shortest
|
|
7
|
+
possible statement of "a program you talk to" — with the frame corner cut
|
|
8
|
+
open at the top-right to read as a tab being pulled away from a window.
|
|
9
|
+
Self-contained (no currentColor), so it renders the same in a README, an
|
|
10
|
+
app icon slot, or a social preview.
|
|
11
|
+
-->
|
|
12
|
+
<defs>
|
|
13
|
+
<linearGradient id="pal-tile" x1="0" y1="0" x2="0" y2="1">
|
|
14
|
+
<stop offset="0" stop-color="#1f2a3a" />
|
|
15
|
+
<stop offset="1" stop-color="#12161f" />
|
|
16
|
+
</linearGradient>
|
|
17
|
+
<linearGradient id="pal-mark" x1="0" y1="0" x2="1" y2="1">
|
|
18
|
+
<stop offset="0" stop-color="#5ee6c4" />
|
|
19
|
+
<stop offset="1" stop-color="#3aa0ff" />
|
|
20
|
+
</linearGradient>
|
|
21
|
+
</defs>
|
|
22
|
+
|
|
23
|
+
<rect x="4" y="4" width="120" height="120" rx="28" fill="url(#pal-tile)" />
|
|
24
|
+
<rect
|
|
25
|
+
x="4.75"
|
|
26
|
+
y="4.75"
|
|
27
|
+
width="118.5"
|
|
28
|
+
height="118.5"
|
|
29
|
+
rx="27.25"
|
|
30
|
+
fill="none"
|
|
31
|
+
stroke="#ffffff"
|
|
32
|
+
stroke-opacity="0.10"
|
|
33
|
+
stroke-width="1.5"
|
|
34
|
+
/>
|
|
35
|
+
|
|
36
|
+
<g
|
|
37
|
+
fill="none"
|
|
38
|
+
stroke="url(#pal-mark)"
|
|
39
|
+
stroke-width="8"
|
|
40
|
+
stroke-linecap="round"
|
|
41
|
+
stroke-linejoin="round"
|
|
42
|
+
>
|
|
43
|
+
<path d="M34 40.5 55 64l-21 23.5" />
|
|
44
|
+
<path d="M70 87h26" />
|
|
45
|
+
</g>
|
|
46
|
+
</svg>
|
package/bin/pal-code.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* pal-code launcher
|
|
@@ -16,6 +16,20 @@ const { spawn } = require('child_process');
|
|
|
16
16
|
const { existsSync } = require('fs');
|
|
17
17
|
const { join, dirname } = require('path');
|
|
18
18
|
|
|
19
|
+
// Advertise this process as `pal`, not `node`.
|
|
20
|
+
//
|
|
21
|
+
// `npm install -g pal-code` puts this file in `bin`, so the process the
|
|
22
|
+
// terminal sees is `node bin/pal-code.js`. Terminals that name a pane from its
|
|
23
|
+
// foreground process (Herdr among them) therefore label a running pal as
|
|
24
|
+
// "node" until the real UI reports itself. Rewriting the process title fixes
|
|
25
|
+
// the window before that, so a pane never reads "node".
|
|
26
|
+
//
|
|
27
|
+
// This is best-effort and platform-dependent: it cannot survive the exec into
|
|
28
|
+
// the real binary on every platform. The authoritative label is the OSC 7501
|
|
29
|
+
// `app=pal` report the CLI emits once its UI starts — see
|
|
30
|
+
// `packages/cli/src/utils/osc-status.ts`.
|
|
31
|
+
process.title = 'pal';
|
|
32
|
+
|
|
19
33
|
// Fast version check — before any binary lookup
|
|
20
34
|
const argv = process.argv.slice(2);
|
|
21
35
|
if (argv[0] === '--version' || argv[0] === '-v' || argv[0] === '--v' || argv[0] === '-version') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pal-code",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "A terminal coding agent with BYOK, tool use, and extensions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"bin/",
|
|
21
|
+
"assets/",
|
|
21
22
|
"packages/cli/src/**/*.ts",
|
|
22
23
|
"packages/cli/src/**/*.tsx",
|
|
23
24
|
"!**/*.test.ts",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"gemini"
|
|
66
67
|
],
|
|
67
68
|
"dependencies": {
|
|
68
|
-
"@pal-code/core": "0.0.
|
|
69
|
+
"@pal-code/core": "0.0.21",
|
|
69
70
|
"@earendil-works/pi-tui": "^0.85.1",
|
|
70
71
|
"get-east-asian-width": "1.6.0",
|
|
71
72
|
"marked": "^18.1.3"
|
|
@@ -8,6 +8,8 @@ import type {Container, TUI} from '@earendil-works/pi-tui';
|
|
|
8
8
|
|
|
9
9
|
import {RunView} from './components/run-view.js';
|
|
10
10
|
import {state} from './state.js';
|
|
11
|
+
import {c} from './theme.js';
|
|
12
|
+
import {Text} from './tui/components/text.js';
|
|
11
13
|
import {checkToolPermission} from './utils/permissions.js';
|
|
12
14
|
|
|
13
15
|
export function createTuiAgentUi(tui: TUI, container: Container): AgentUi {
|
|
@@ -45,6 +47,14 @@ export function createTuiAgentUi(tui: TUI, container: Container): AgentUi {
|
|
|
45
47
|
extensions(extensions) {
|
|
46
48
|
state.extensions = extensions;
|
|
47
49
|
},
|
|
50
|
+
advisories(lines) {
|
|
51
|
+
// Rendered into the transcript rather than a run block: this fires before
|
|
52
|
+
// any turn exists, so `notice()` would be dropped.
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
container.addChild(new Text(`${c.yellow} ${line}${c.reset}`, 1, 0));
|
|
55
|
+
}
|
|
56
|
+
tui.requestRender();
|
|
57
|
+
},
|
|
48
58
|
mcpServers(servers) {
|
|
49
59
|
state.mcpServers = servers;
|
|
50
60
|
},
|
|
@@ -23,7 +23,10 @@ import {
|
|
|
23
23
|
setTheme,
|
|
24
24
|
activeTheme,
|
|
25
25
|
listThemes,
|
|
26
|
+
listThemeChoices,
|
|
26
27
|
resolveTheme,
|
|
28
|
+
wantsAutoTheme,
|
|
29
|
+
AUTO_THEME,
|
|
27
30
|
} from './theme.js';
|
|
28
31
|
import {
|
|
29
32
|
generateTitle,
|
|
@@ -57,7 +60,12 @@ import {
|
|
|
57
60
|
saveUpdateCache,
|
|
58
61
|
} from './commands/update-check.js';
|
|
59
62
|
import {showSessionSelector, cmdResume} from './overlays/session-picker.js';
|
|
60
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
loadCostManifest,
|
|
65
|
+
isPricedModel,
|
|
66
|
+
registerModelPricing,
|
|
67
|
+
resolveTurnCost,
|
|
68
|
+
} from './utils/cost.js';
|
|
61
69
|
import {
|
|
62
70
|
buildOsc22Pointer,
|
|
63
71
|
buildOsc52Sequence,
|
|
@@ -69,7 +77,10 @@ import {
|
|
|
69
77
|
buildCanvasRestore,
|
|
70
78
|
buildOsc10Set,
|
|
71
79
|
buildOsc11Set,
|
|
80
|
+
buildSchemeSubscribe,
|
|
81
|
+
detectScheme,
|
|
72
82
|
parseCanvasReplies,
|
|
83
|
+
parseSchemeReport,
|
|
73
84
|
planCanvasSync,
|
|
74
85
|
} from './utils/osc-canvas.js';
|
|
75
86
|
import type {CanvasSync} from './utils/osc-canvas.js';
|
|
@@ -123,7 +134,7 @@ import type {SessionStore as SessionStoreType} from '@pal-code/core';
|
|
|
123
134
|
// (see buildModelOptions). Static curated lists live in @pal-code/core PROVIDERS as fallback.
|
|
124
135
|
|
|
125
136
|
// Version synced from version.json via `node scripts/sync-version.js`.
|
|
126
|
-
const VERSION = '0.0.
|
|
137
|
+
const VERSION = '0.0.21';
|
|
127
138
|
|
|
128
139
|
// ── Canvas sync (OSC 10/11) ──
|
|
129
140
|
// Raw reply payloads captured after a successful startup query + set, or null
|
|
@@ -156,6 +167,21 @@ import {
|
|
|
156
167
|
runTurn as runAgentTurn,
|
|
157
168
|
} from '@pal-code/core';
|
|
158
169
|
import {approveTool, createTuiAgentUi} from './agent-ui.js';
|
|
170
|
+
import {settledStatus} from './utils/osc-status.js';
|
|
171
|
+
import {createStatusReporter} from './utils/status-report.js';
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Whether a turn failed because the user aborted it.
|
|
175
|
+
*
|
|
176
|
+
* The abort path surfaces as an `AbortError`, but it can also arrive as the
|
|
177
|
+
* reason string on a rejected provider request, so check both the name and the
|
|
178
|
+
* message rather than trusting `err.name` alone.
|
|
179
|
+
*/
|
|
180
|
+
function isAbortError(err: unknown): boolean {
|
|
181
|
+
if (!(err instanceof Error)) return false;
|
|
182
|
+
if (err.name === 'AbortError') return true;
|
|
183
|
+
return /aborted|abort error/i.test(err.message);
|
|
184
|
+
}
|
|
159
185
|
|
|
160
186
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
161
187
|
// Main
|
|
@@ -189,13 +215,82 @@ async function main() {
|
|
|
189
215
|
|
|
190
216
|
// Resolve the theme before any component or banner is constructed, so every
|
|
191
217
|
// palette read below uses it (PAL_THEME env wins over ~/.pal/config.json).
|
|
192
|
-
|
|
218
|
+
//
|
|
219
|
+
// `auto` needs the terminal's own background before it can pick a half, and
|
|
220
|
+
// that only exists after tui.start() (raw stdin). Until then the resolved
|
|
221
|
+
// standalone theme is the provisional default, so the banner and every
|
|
222
|
+
// component still have a coherent palette from the first frame; the real
|
|
223
|
+
// half arrives in the canvas-sync block at the end of main().
|
|
224
|
+
const palConfig = readPalConfig();
|
|
225
|
+
const autoTheme = wantsAutoTheme(palConfig, process.env.PAL_THEME);
|
|
226
|
+
// Live `auto` flag and the last scheme the terminal reported. Both outlive
|
|
227
|
+
// the startup decision: `/theme auto` can switch the mode on mid-session and
|
|
228
|
+
// the 2031 subscription below keeps `detectedScheme` current.
|
|
229
|
+
let themeAuto = autoTheme;
|
|
230
|
+
let detectedScheme: 'dark' | 'light' | null = null;
|
|
231
|
+
setTheme(resolveTheme(palConfig, process.env.PAL_THEME));
|
|
193
232
|
|
|
194
233
|
// Canvas plan is pure and computed here, but the query itself runs at the
|
|
195
234
|
// end of main(): raw stdin only exists after tui.start(). An empty plan
|
|
196
235
|
// (vanilla-pi: window bg/fg '') skips the whole block — zero bytes.
|
|
197
236
|
const canvasPlan = planCanvasSync(activeTheme().surface.window);
|
|
198
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Swap the active palette and repaint everything that reads it live.
|
|
240
|
+
*
|
|
241
|
+
* Two classes of component: the live-reading ones (sidebar, status line,
|
|
242
|
+
* markdown/`AssistantBody`, code boxes) re-render from the palette getters
|
|
243
|
+
* once invalidated, while plain `Text` rows embed the bytes they were built
|
|
244
|
+
* with. So a swap also rebuilds the transcript from the store when a session
|
|
245
|
+
* backs the view — otherwise old rows keep the previous scheme's colours.
|
|
246
|
+
*/
|
|
247
|
+
const applyTheme = (name: string): void => {
|
|
248
|
+
if (!setTheme(name)) return;
|
|
249
|
+
statusLine.invalidate();
|
|
250
|
+
sidebar.refresh();
|
|
251
|
+
if (store && currentSessionId) {
|
|
252
|
+
const stored = store.getMessages(currentSessionId);
|
|
253
|
+
messagesContainer.clear();
|
|
254
|
+
renderHistory(messagesContainer, tui, stored, {
|
|
255
|
+
compactions: store.getCompactions(currentSessionId),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
messagesContainer.invalidate();
|
|
259
|
+
editorRow.invalidate();
|
|
260
|
+
updateStatusLine();
|
|
261
|
+
tui.requestRender();
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Apply a `/theme` choice, persisting it.
|
|
266
|
+
*
|
|
267
|
+
* `auto` is not a palette: it stores the mode and resolves to the GitHub
|
|
268
|
+
* half that matches the terminal's last reported (or startup-detected)
|
|
269
|
+
* background, so the choice survives a restart and the 2031 subscription
|
|
270
|
+
* keeps following the OS afterwards.
|
|
271
|
+
*/
|
|
272
|
+
const applyThemeChoice = (choice: string): void => {
|
|
273
|
+
if (choice === AUTO_THEME) {
|
|
274
|
+
themeAuto = true;
|
|
275
|
+
saveSetting('theme', AUTO_THEME);
|
|
276
|
+
applyTheme(resolveTheme({theme: AUTO_THEME}, undefined, detectedScheme ?? undefined));
|
|
277
|
+
} else {
|
|
278
|
+
themeAuto = false;
|
|
279
|
+
saveSetting('theme', choice);
|
|
280
|
+
applyTheme(choice);
|
|
281
|
+
}
|
|
282
|
+
messagesContainer.addChild(
|
|
283
|
+
new Text(
|
|
284
|
+
`${c.green} ✓ theme: ${choice}${c.reset}` +
|
|
285
|
+
`${choice === AUTO_THEME ? `${c.dim} (follows terminal)${c.reset}` : `${c.dim} (saved)${c.reset}`}`,
|
|
286
|
+
1,
|
|
287
|
+
0,
|
|
288
|
+
),
|
|
289
|
+
);
|
|
290
|
+
messagesContainer.invalidate();
|
|
291
|
+
tui.requestRender();
|
|
292
|
+
};
|
|
293
|
+
|
|
199
294
|
// Load any user-defined custom providers from ~/.pal/providers.json
|
|
200
295
|
loadCustomProviders();
|
|
201
296
|
|
|
@@ -276,8 +371,34 @@ async function main() {
|
|
|
276
371
|
});
|
|
277
372
|
}
|
|
278
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Teach the cost table what this provider charges.
|
|
376
|
+
*
|
|
377
|
+
* Gateways price their own catalogue, and that catalogue is keyed by gateway
|
|
378
|
+
* model id — which the LiteLLM manifest does not know (`deepseek-v4.1-flash`
|
|
379
|
+
* vs `azure_ai/deepseek-v4.1-flash`). Without this, a paid gateway model
|
|
380
|
+
* matched nothing and every turn displayed `$0.00`. Fire-and-forget and
|
|
381
|
+
* once per provider: a failure just leaves the fallback table in place.
|
|
382
|
+
*/
|
|
383
|
+
const pricingSynced = new Set<string>();
|
|
384
|
+
function syncModelPricing(provider: Provider): void {
|
|
385
|
+
const id = provider.id;
|
|
386
|
+
if (pricingSynced.has(id)) return;
|
|
387
|
+
pricingSynced.add(id);
|
|
388
|
+
void provider
|
|
389
|
+
.models()
|
|
390
|
+
.then((models) => {
|
|
391
|
+
registerModelPricing(models, id);
|
|
392
|
+
refreshSidebar();
|
|
393
|
+
})
|
|
394
|
+
.catch(() => {
|
|
395
|
+
// offline or unauthenticated — the hardcoded/manifest table still applies
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
279
399
|
const providerRef = {current: createProvider(config.model)};
|
|
280
400
|
await providerRef.current.init();
|
|
401
|
+
syncModelPricing(providerRef.current);
|
|
281
402
|
|
|
282
403
|
// ── Session store (deferred — bun:sqlite breaks pi-tui stdin) ──
|
|
283
404
|
let store: SessionStoreType | null = null;
|
|
@@ -317,6 +438,12 @@ async function main() {
|
|
|
317
438
|
const terminal = new ProcessTerminal();
|
|
318
439
|
const tui: TUI = new TuiMainScreen(terminal);
|
|
319
440
|
|
|
441
|
+
// ── Terminal program-status reporting (OSC 7501) ──
|
|
442
|
+
// Lets Herdr (and any other agent inbox) list this pane as pal, with a live
|
|
443
|
+
// working/blocked/done state, instead of only seeing the process name.
|
|
444
|
+
// Enabled only when stdout is a terminal; `PAL_NO_STATUS=1` opts out.
|
|
445
|
+
state.statusReporter = createStatusReporter();
|
|
446
|
+
|
|
320
447
|
// ── Components ──
|
|
321
448
|
const messagesContainer = new Container();
|
|
322
449
|
// theme-captured at construction — applies on restart (Editor reads
|
|
@@ -863,7 +990,9 @@ async function main() {
|
|
|
863
990
|
contextPct,
|
|
864
991
|
ctxTokens,
|
|
865
992
|
contextLimit: config.contextLimit,
|
|
866
|
-
priced
|
|
993
|
+
// A turn whose cost the provider actually reported is priced by
|
|
994
|
+
// definition, even if our table doesn't know the model.
|
|
995
|
+
priced: isPricedModel(config.model) || state.sessionTokenomics.cost > 0,
|
|
867
996
|
});
|
|
868
997
|
tui.requestRender();
|
|
869
998
|
}
|
|
@@ -907,6 +1036,7 @@ async function main() {
|
|
|
907
1036
|
}
|
|
908
1037
|
providerRef.current = createProvider(config.model);
|
|
909
1038
|
providerRef.current.init();
|
|
1039
|
+
syncModelPricing(providerRef.current);
|
|
910
1040
|
updateStatusLine();
|
|
911
1041
|
};
|
|
912
1042
|
|
|
@@ -1649,28 +1779,28 @@ async function main() {
|
|
|
1649
1779
|
}
|
|
1650
1780
|
if (trimmed === '/theme') {
|
|
1651
1781
|
const active = activeTheme();
|
|
1782
|
+
// `auto` is offered alongside the real themes; it is not a registered
|
|
1783
|
+
// palette, so it is marked active from the saved config rather than from
|
|
1784
|
+
// the theme object.
|
|
1785
|
+
const current = wantsAutoTheme(readPalConfig(), process.env.PAL_THEME)
|
|
1786
|
+
? AUTO_THEME
|
|
1787
|
+
: active.name;
|
|
1652
1788
|
showSelectOverlay(
|
|
1653
1789
|
{
|
|
1654
1790
|
title: 'Select theme',
|
|
1655
|
-
items:
|
|
1791
|
+
items: listThemeChoices().map((name) => ({
|
|
1656
1792
|
value: name,
|
|
1657
|
-
label: name,
|
|
1658
|
-
description:
|
|
1793
|
+
label: name === AUTO_THEME ? 'auto (follow terminal)' : name,
|
|
1794
|
+
description:
|
|
1795
|
+
name === current
|
|
1796
|
+
? 'active'
|
|
1797
|
+
: name === AUTO_THEME
|
|
1798
|
+
? 'github-dark / github-light by terminal background'
|
|
1799
|
+
: undefined,
|
|
1659
1800
|
})),
|
|
1660
|
-
selectedValue:
|
|
1801
|
+
selectedValue: current,
|
|
1661
1802
|
height: 10,
|
|
1662
|
-
onSelect: (item) =>
|
|
1663
|
-
if (!setTheme(item.value)) return;
|
|
1664
|
-
saveSetting('theme', item.value);
|
|
1665
|
-
messagesContainer.addChild(
|
|
1666
|
-
new Text(`${c.green} ✓ theme: ${item.value} (saved)${c.reset}`, 1, 0),
|
|
1667
|
-
);
|
|
1668
|
-
messagesContainer.invalidate();
|
|
1669
|
-
editorRow.invalidate();
|
|
1670
|
-
state.refreshStatusLine();
|
|
1671
|
-
refreshSidebar();
|
|
1672
|
-
tui.requestRender();
|
|
1673
|
-
},
|
|
1803
|
+
onSelect: (item) => applyThemeChoice(item.value),
|
|
1674
1804
|
},
|
|
1675
1805
|
{container: messagesContainer, editor, editorRow, tui},
|
|
1676
1806
|
);
|
|
@@ -1678,11 +1808,11 @@ async function main() {
|
|
|
1678
1808
|
}
|
|
1679
1809
|
if (trimmed.startsWith('/theme ')) {
|
|
1680
1810
|
const name = trimmed.slice('/theme '.length).trim();
|
|
1681
|
-
if (!
|
|
1811
|
+
if (!listThemeChoices().includes(name)) {
|
|
1682
1812
|
messagesContainer.addChild(
|
|
1683
1813
|
new Text(
|
|
1684
1814
|
`${c.red} Unknown theme: ${name}${c.reset} ` +
|
|
1685
|
-
`${c.dim}(${
|
|
1815
|
+
`${c.dim}(${listThemeChoices().join(', ')})${c.reset}`,
|
|
1686
1816
|
1,
|
|
1687
1817
|
0,
|
|
1688
1818
|
),
|
|
@@ -1690,16 +1820,7 @@ async function main() {
|
|
|
1690
1820
|
tui.requestRender();
|
|
1691
1821
|
return;
|
|
1692
1822
|
}
|
|
1693
|
-
|
|
1694
|
-
messagesContainer.addChild(new Text(`${c.green} ✓ theme: ${name} (saved)${c.reset}`, 1, 0));
|
|
1695
|
-
// Same repaint path as /model NAME (refresh status + requestRender),
|
|
1696
|
-
// plus container invalidation so render-time components (markdown,
|
|
1697
|
-
// sidebar) repaint from source with the new palette.
|
|
1698
|
-
messagesContainer.invalidate();
|
|
1699
|
-
editorRow.invalidate();
|
|
1700
|
-
state.refreshStatusLine();
|
|
1701
|
-
refreshSidebar();
|
|
1702
|
-
tui.requestRender();
|
|
1823
|
+
applyThemeChoice(name);
|
|
1703
1824
|
return;
|
|
1704
1825
|
}
|
|
1705
1826
|
if (trimmed === '/model' || trimmed === '/model ') {
|
|
@@ -1712,6 +1833,7 @@ async function main() {
|
|
|
1712
1833
|
providerRef,
|
|
1713
1834
|
createProvider,
|
|
1714
1835
|
allKeys,
|
|
1836
|
+
syncModelPricing,
|
|
1715
1837
|
);
|
|
1716
1838
|
return;
|
|
1717
1839
|
}
|
|
@@ -1722,6 +1844,7 @@ async function main() {
|
|
|
1722
1844
|
saveSetting('model', newName);
|
|
1723
1845
|
providerRef.current = createProvider(newName);
|
|
1724
1846
|
providerRef.current.init();
|
|
1847
|
+
syncModelPricing(providerRef.current);
|
|
1725
1848
|
messagesContainer.addChild(
|
|
1726
1849
|
new Text(`${c.green} Model set to: ${config.model}${c.reset}`, 1, 0),
|
|
1727
1850
|
);
|
|
@@ -2090,6 +2213,7 @@ async function main() {
|
|
|
2090
2213
|
const runTurn = async (message: string): Promise<void> => {
|
|
2091
2214
|
pendingExecution = false;
|
|
2092
2215
|
state.activeAbort = new AbortController();
|
|
2216
|
+
state.statusReporter.report('working');
|
|
2093
2217
|
|
|
2094
2218
|
let answered = false;
|
|
2095
2219
|
try {
|
|
@@ -2124,12 +2248,16 @@ async function main() {
|
|
|
2124
2248
|
state.activeRun.finish(true);
|
|
2125
2249
|
state.lastRun = state.activeRun; // ctrl+o can re-inflate this run
|
|
2126
2250
|
}
|
|
2251
|
+
state.statusReporter.report(settledStatus(false));
|
|
2127
2252
|
|
|
2128
2253
|
const tok = state.sessionTokenomics;
|
|
2129
2254
|
tok.inputTokens += result.inputTokens;
|
|
2130
2255
|
tok.cachedTokens += result.cachedTokens;
|
|
2131
2256
|
tok.outputTokens += result.outputTokens;
|
|
2132
|
-
|
|
2257
|
+
// Prefer the provider's own billed figure: it is authoritative and
|
|
2258
|
+
// already reflects cache discounts and account-level pricing.
|
|
2259
|
+
const turnCost = resolveTurnCost(
|
|
2260
|
+
result.reportedCost,
|
|
2133
2261
|
result.model,
|
|
2134
2262
|
result.inputTokens,
|
|
2135
2263
|
result.outputTokens,
|
|
@@ -2168,6 +2296,10 @@ async function main() {
|
|
|
2168
2296
|
const msg = err instanceof Error ? err.message : String(err);
|
|
2169
2297
|
messagesContainer.addChild(new Text(`${c.red} Error: ${msg}${c.reset}`, 1, 0));
|
|
2170
2298
|
tui.requestRender();
|
|
2299
|
+
// An abort is the user's own Esc, not a failure — the spec's rule is to
|
|
2300
|
+
// report `idle` for a cancelled program, so a deliberate stop does not
|
|
2301
|
+
// raise a red badge in the terminal's agent list.
|
|
2302
|
+
state.statusReporter.report(settledStatus(isAbortError(err)));
|
|
2171
2303
|
// Roll the transcript back to the start of this turn (core owns the rule).
|
|
2172
2304
|
const rolledBackTo = rollbackTurn(messages);
|
|
2173
2305
|
// Keep the append-only store consistent: drop any rows this failed turn
|
|
@@ -2267,6 +2399,9 @@ async function main() {
|
|
|
2267
2399
|
const _keepAlive = setInterval(() => {}, 60_000);
|
|
2268
2400
|
process.on('exit', () => {
|
|
2269
2401
|
clearInterval(_keepAlive);
|
|
2402
|
+
// Drop pal's OSC 7501 records so a pane that is no longer running pal does
|
|
2403
|
+
// not keep a stale "done" badge in the terminal's agent list.
|
|
2404
|
+
state.statusReporter.clear();
|
|
2270
2405
|
// Restore the terminal: leaving SGR mouse reporting on would make the
|
|
2271
2406
|
// parent shell print raw mouse escape codes.
|
|
2272
2407
|
disableMouse();
|
|
@@ -2275,14 +2410,18 @@ async function main() {
|
|
|
2275
2410
|
restoreCanvas();
|
|
2276
2411
|
});
|
|
2277
2412
|
|
|
2278
|
-
// ── Canvas sync (OSC 10/11) ──
|
|
2413
|
+
// ── Canvas sync (OSC 10/11) + scheme detection ──
|
|
2279
2414
|
// Runs after tui.start() (raw stdin only exists now) and after the exit
|
|
2280
2415
|
// handler registration above, so every set has a restore path from the
|
|
2281
2416
|
// moment it is written. Replies are harvested by a temporary input listener
|
|
2282
2417
|
// on pi-tui's normal pipeline (StdinBuffer emits whole escape sequences) —
|
|
2283
2418
|
// stdin is never intercepted, so keystrokes during the window flow to the
|
|
2284
2419
|
// regular listeners untouched and no drain buffer is needed.
|
|
2285
|
-
|
|
2420
|
+
//
|
|
2421
|
+
// The query also runs when `auto` still owes us a decision: the OSC 11 reply
|
|
2422
|
+
// is the only reliable statement of the terminal's background, and it is
|
|
2423
|
+
// needed even for theme halves that do not sync the canvas themselves.
|
|
2424
|
+
if (canvasPlan.fg !== undefined || canvasPlan.bg !== undefined || themeAuto) {
|
|
2286
2425
|
let replyBytes = '';
|
|
2287
2426
|
let settled = false;
|
|
2288
2427
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -2299,6 +2438,11 @@ async function main() {
|
|
|
2299
2438
|
}
|
|
2300
2439
|
replyBytes += data;
|
|
2301
2440
|
const replies = parseCanvasReplies(replyBytes);
|
|
2441
|
+
// `auto` settles on the background alone — it is what picks the half.
|
|
2442
|
+
if (themeAuto && replies.bg !== undefined) {
|
|
2443
|
+
finish?.();
|
|
2444
|
+
return {consume: true};
|
|
2445
|
+
}
|
|
2302
2446
|
const fgDone = canvasPlan.fg === undefined || replies.fg !== undefined;
|
|
2303
2447
|
const bgDone = canvasPlan.bg === undefined || replies.bg !== undefined;
|
|
2304
2448
|
if (fgDone && bgDone) finish?.(); // both planned channels answered — skip the rest of the timeout
|
|
@@ -2322,10 +2466,19 @@ async function main() {
|
|
|
2322
2466
|
unsubscribe();
|
|
2323
2467
|
finish = undefined;
|
|
2324
2468
|
|
|
2469
|
+
// Both consumers read the same captured bytes: `auto` needs the detected
|
|
2470
|
+
// scheme, canvas sync needs the raw payloads to restore verbatim on exit.
|
|
2471
|
+
const replies = parseCanvasReplies(replyBytes);
|
|
2472
|
+
replyBytes = ''; // explicit discard — the parses above are the only consumers
|
|
2473
|
+
detectedScheme = detectScheme(replies.bg);
|
|
2474
|
+
|
|
2475
|
+
if (themeAuto) {
|
|
2476
|
+
const chosen = resolveTheme(palConfig, process.env.PAL_THEME, detectedScheme ?? undefined);
|
|
2477
|
+
if (chosen !== activeTheme().name) applyTheme(chosen);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2325
2480
|
// Set only channels present in BOTH the plan and the reply; the raw reply
|
|
2326
2481
|
// payload is what we restore verbatim on exit.
|
|
2327
|
-
const replies = parseCanvasReplies(replyBytes);
|
|
2328
|
-
replyBytes = ''; // explicit discard — the parse above is the only consumer
|
|
2329
2482
|
const sets: string[] = [];
|
|
2330
2483
|
const saved: CanvasSync = {};
|
|
2331
2484
|
if (canvasPlan.fg !== undefined && replies.fg !== undefined) {
|
|
@@ -2341,6 +2494,31 @@ async function main() {
|
|
|
2341
2494
|
tui.terminal.write(sets.join(''));
|
|
2342
2495
|
}
|
|
2343
2496
|
}
|
|
2497
|
+
|
|
2498
|
+
// ── Live scheme flips (DECSET 2031) ──
|
|
2499
|
+
// With `auto` the palette must follow the OS switch, not just startup: a
|
|
2500
|
+
// light terminal that flips to dark would otherwise keep the light theme's
|
|
2501
|
+
// white canvas under ANSI-coloured text. Terminals that don't support the
|
|
2502
|
+
// mode ignore the sequence silently; those that do report `CSI ? 997 ; N n`
|
|
2503
|
+
// for every change, which we parse and map to a theme half.
|
|
2504
|
+
// Installed unconditionally (it costs one ignored byte-sequence on terminals
|
|
2505
|
+
// that don't implement 2031) so `/theme auto` works without a restart.
|
|
2506
|
+
{
|
|
2507
|
+
const unsubscribe = tui.addInputListener((data: string) => {
|
|
2508
|
+
const scheme = parseSchemeReport(data);
|
|
2509
|
+
if (scheme === null) return undefined;
|
|
2510
|
+
detectedScheme = scheme;
|
|
2511
|
+
if (!themeAuto) return {consume: true}; // tracked, but the user pinned a theme
|
|
2512
|
+
const chosen = resolveTheme(palConfig, process.env.PAL_THEME, scheme);
|
|
2513
|
+
if (chosen !== activeTheme().name) applyTheme(chosen);
|
|
2514
|
+
return {consume: true};
|
|
2515
|
+
});
|
|
2516
|
+
tui.terminal.write(buildSchemeSubscribe(true));
|
|
2517
|
+
process.on('exit', () => {
|
|
2518
|
+
unsubscribe();
|
|
2519
|
+
process.stdout.write(buildSchemeSubscribe(false));
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2344
2522
|
}
|
|
2345
2523
|
|
|
2346
2524
|
main().catch((err) => {
|
|
@@ -48,6 +48,8 @@ export function showModelSelector(
|
|
|
48
48
|
providerRef: {current: Provider},
|
|
49
49
|
createProviderFn: (model: string) => Provider,
|
|
50
50
|
allKeys: ProviderKeys,
|
|
51
|
+
/** Called with the freshly built provider so callers can refresh pricing. */
|
|
52
|
+
onProviderChange?: (provider: Provider) => void,
|
|
51
53
|
): void {
|
|
52
54
|
showSelectOverlay(
|
|
53
55
|
{
|
|
@@ -61,6 +63,7 @@ export function showModelSelector(
|
|
|
61
63
|
saveSetting('model', item.value);
|
|
62
64
|
providerRef.current = createProviderFn(item.value);
|
|
63
65
|
providerRef.current.init();
|
|
66
|
+
onProviderChange?.(providerRef.current);
|
|
64
67
|
state.refreshStatusLine();
|
|
65
68
|
},
|
|
66
69
|
},
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
import {createSharedState} from '@pal-code/core';
|
|
22
22
|
import type {PermissionPrompt} from './components/permission-prompt.js';
|
|
23
23
|
import type {RunView} from './components/run-view.js';
|
|
24
|
+
import {nullStatusReporter, type StatusReporter} from './utils/status-report.js';
|
|
24
25
|
|
|
25
26
|
export type {BackgroundAgent, TodoItem} from '@pal-code/core';
|
|
26
27
|
export type ExtensionInfo = ExtensionStatus;
|
|
@@ -74,6 +75,17 @@ export interface AppState extends SharedState {
|
|
|
74
75
|
target: string;
|
|
75
76
|
summary: string;
|
|
76
77
|
}>;
|
|
78
|
+
|
|
79
|
+
// ── Terminal integration ──
|
|
80
|
+
/**
|
|
81
|
+
* Reports pal's state to the terminal over OSC 7501, so an agent inbox
|
|
82
|
+
* (Herdr) lists the pane as pal's agent instead of only seeing a process.
|
|
83
|
+
*
|
|
84
|
+
* Rebound by `main()` once stdout is known to be a terminal. The permission
|
|
85
|
+
* gate also reaches the reporter through here, which is why it lives on the
|
|
86
|
+
* session state rather than being threaded down as a parameter.
|
|
87
|
+
*/
|
|
88
|
+
statusReporter: StatusReporter;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
export const state: AppState = {
|
|
@@ -93,6 +105,7 @@ export const state: AppState = {
|
|
|
93
105
|
pendingPermission: null,
|
|
94
106
|
permissionPrompt: null,
|
|
95
107
|
permissionQueue: [],
|
|
108
|
+
statusReporter: nullStatusReporter,
|
|
96
109
|
};
|
|
97
110
|
|
|
98
111
|
/**
|
|
@@ -16,7 +16,7 @@ import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from '.
|
|
|
16
16
|
import {themes} from './themes/index.js';
|
|
17
17
|
import {vanillaPi} from './themes/vanilla-pi.js';
|
|
18
18
|
|
|
19
|
-
export {listThemes, resolveTheme} from './themes/index.js';
|
|
19
|
+
export {listThemes, listThemeChoices, resolveTheme, wantsAutoTheme, AUTO_THEME} from './themes/index.js';
|
|
20
20
|
|
|
21
21
|
let current: Theme = vanillaPi;
|
|
22
22
|
|