pal-code 0.0.20 → 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/index.ts +173 -34
- 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/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"
|
|
@@ -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,
|
|
@@ -74,7 +77,10 @@ import {
|
|
|
74
77
|
buildCanvasRestore,
|
|
75
78
|
buildOsc10Set,
|
|
76
79
|
buildOsc11Set,
|
|
80
|
+
buildSchemeSubscribe,
|
|
81
|
+
detectScheme,
|
|
77
82
|
parseCanvasReplies,
|
|
83
|
+
parseSchemeReport,
|
|
78
84
|
planCanvasSync,
|
|
79
85
|
} from './utils/osc-canvas.js';
|
|
80
86
|
import type {CanvasSync} from './utils/osc-canvas.js';
|
|
@@ -128,7 +134,7 @@ import type {SessionStore as SessionStoreType} from '@pal-code/core';
|
|
|
128
134
|
// (see buildModelOptions). Static curated lists live in @pal-code/core PROVIDERS as fallback.
|
|
129
135
|
|
|
130
136
|
// Version synced from version.json via `node scripts/sync-version.js`.
|
|
131
|
-
const VERSION = '0.0.
|
|
137
|
+
const VERSION = '0.0.21';
|
|
132
138
|
|
|
133
139
|
// ── Canvas sync (OSC 10/11) ──
|
|
134
140
|
// Raw reply payloads captured after a successful startup query + set, or null
|
|
@@ -161,6 +167,21 @@ import {
|
|
|
161
167
|
runTurn as runAgentTurn,
|
|
162
168
|
} from '@pal-code/core';
|
|
163
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
|
+
}
|
|
164
185
|
|
|
165
186
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
166
187
|
// Main
|
|
@@ -194,13 +215,82 @@ async function main() {
|
|
|
194
215
|
|
|
195
216
|
// Resolve the theme before any component or banner is constructed, so every
|
|
196
217
|
// palette read below uses it (PAL_THEME env wins over ~/.pal/config.json).
|
|
197
|
-
|
|
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));
|
|
198
232
|
|
|
199
233
|
// Canvas plan is pure and computed here, but the query itself runs at the
|
|
200
234
|
// end of main(): raw stdin only exists after tui.start(). An empty plan
|
|
201
235
|
// (vanilla-pi: window bg/fg '') skips the whole block — zero bytes.
|
|
202
236
|
const canvasPlan = planCanvasSync(activeTheme().surface.window);
|
|
203
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
|
+
|
|
204
294
|
// Load any user-defined custom providers from ~/.pal/providers.json
|
|
205
295
|
loadCustomProviders();
|
|
206
296
|
|
|
@@ -348,6 +438,12 @@ async function main() {
|
|
|
348
438
|
const terminal = new ProcessTerminal();
|
|
349
439
|
const tui: TUI = new TuiMainScreen(terminal);
|
|
350
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
|
+
|
|
351
447
|
// ── Components ──
|
|
352
448
|
const messagesContainer = new Container();
|
|
353
449
|
// theme-captured at construction — applies on restart (Editor reads
|
|
@@ -1683,28 +1779,28 @@ async function main() {
|
|
|
1683
1779
|
}
|
|
1684
1780
|
if (trimmed === '/theme') {
|
|
1685
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;
|
|
1686
1788
|
showSelectOverlay(
|
|
1687
1789
|
{
|
|
1688
1790
|
title: 'Select theme',
|
|
1689
|
-
items:
|
|
1791
|
+
items: listThemeChoices().map((name) => ({
|
|
1690
1792
|
value: name,
|
|
1691
|
-
label: name,
|
|
1692
|
-
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,
|
|
1693
1800
|
})),
|
|
1694
|
-
selectedValue:
|
|
1801
|
+
selectedValue: current,
|
|
1695
1802
|
height: 10,
|
|
1696
|
-
onSelect: (item) =>
|
|
1697
|
-
if (!setTheme(item.value)) return;
|
|
1698
|
-
saveSetting('theme', item.value);
|
|
1699
|
-
messagesContainer.addChild(
|
|
1700
|
-
new Text(`${c.green} ✓ theme: ${item.value} (saved)${c.reset}`, 1, 0),
|
|
1701
|
-
);
|
|
1702
|
-
messagesContainer.invalidate();
|
|
1703
|
-
editorRow.invalidate();
|
|
1704
|
-
state.refreshStatusLine();
|
|
1705
|
-
refreshSidebar();
|
|
1706
|
-
tui.requestRender();
|
|
1707
|
-
},
|
|
1803
|
+
onSelect: (item) => applyThemeChoice(item.value),
|
|
1708
1804
|
},
|
|
1709
1805
|
{container: messagesContainer, editor, editorRow, tui},
|
|
1710
1806
|
);
|
|
@@ -1712,11 +1808,11 @@ async function main() {
|
|
|
1712
1808
|
}
|
|
1713
1809
|
if (trimmed.startsWith('/theme ')) {
|
|
1714
1810
|
const name = trimmed.slice('/theme '.length).trim();
|
|
1715
|
-
if (!
|
|
1811
|
+
if (!listThemeChoices().includes(name)) {
|
|
1716
1812
|
messagesContainer.addChild(
|
|
1717
1813
|
new Text(
|
|
1718
1814
|
`${c.red} Unknown theme: ${name}${c.reset} ` +
|
|
1719
|
-
`${c.dim}(${
|
|
1815
|
+
`${c.dim}(${listThemeChoices().join(', ')})${c.reset}`,
|
|
1720
1816
|
1,
|
|
1721
1817
|
0,
|
|
1722
1818
|
),
|
|
@@ -1724,16 +1820,7 @@ async function main() {
|
|
|
1724
1820
|
tui.requestRender();
|
|
1725
1821
|
return;
|
|
1726
1822
|
}
|
|
1727
|
-
|
|
1728
|
-
messagesContainer.addChild(new Text(`${c.green} ✓ theme: ${name} (saved)${c.reset}`, 1, 0));
|
|
1729
|
-
// Same repaint path as /model NAME (refresh status + requestRender),
|
|
1730
|
-
// plus container invalidation so render-time components (markdown,
|
|
1731
|
-
// sidebar) repaint from source with the new palette.
|
|
1732
|
-
messagesContainer.invalidate();
|
|
1733
|
-
editorRow.invalidate();
|
|
1734
|
-
state.refreshStatusLine();
|
|
1735
|
-
refreshSidebar();
|
|
1736
|
-
tui.requestRender();
|
|
1823
|
+
applyThemeChoice(name);
|
|
1737
1824
|
return;
|
|
1738
1825
|
}
|
|
1739
1826
|
if (trimmed === '/model' || trimmed === '/model ') {
|
|
@@ -2126,6 +2213,7 @@ async function main() {
|
|
|
2126
2213
|
const runTurn = async (message: string): Promise<void> => {
|
|
2127
2214
|
pendingExecution = false;
|
|
2128
2215
|
state.activeAbort = new AbortController();
|
|
2216
|
+
state.statusReporter.report('working');
|
|
2129
2217
|
|
|
2130
2218
|
let answered = false;
|
|
2131
2219
|
try {
|
|
@@ -2160,6 +2248,7 @@ async function main() {
|
|
|
2160
2248
|
state.activeRun.finish(true);
|
|
2161
2249
|
state.lastRun = state.activeRun; // ctrl+o can re-inflate this run
|
|
2162
2250
|
}
|
|
2251
|
+
state.statusReporter.report(settledStatus(false));
|
|
2163
2252
|
|
|
2164
2253
|
const tok = state.sessionTokenomics;
|
|
2165
2254
|
tok.inputTokens += result.inputTokens;
|
|
@@ -2207,6 +2296,10 @@ async function main() {
|
|
|
2207
2296
|
const msg = err instanceof Error ? err.message : String(err);
|
|
2208
2297
|
messagesContainer.addChild(new Text(`${c.red} Error: ${msg}${c.reset}`, 1, 0));
|
|
2209
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)));
|
|
2210
2303
|
// Roll the transcript back to the start of this turn (core owns the rule).
|
|
2211
2304
|
const rolledBackTo = rollbackTurn(messages);
|
|
2212
2305
|
// Keep the append-only store consistent: drop any rows this failed turn
|
|
@@ -2306,6 +2399,9 @@ async function main() {
|
|
|
2306
2399
|
const _keepAlive = setInterval(() => {}, 60_000);
|
|
2307
2400
|
process.on('exit', () => {
|
|
2308
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();
|
|
2309
2405
|
// Restore the terminal: leaving SGR mouse reporting on would make the
|
|
2310
2406
|
// parent shell print raw mouse escape codes.
|
|
2311
2407
|
disableMouse();
|
|
@@ -2314,14 +2410,18 @@ async function main() {
|
|
|
2314
2410
|
restoreCanvas();
|
|
2315
2411
|
});
|
|
2316
2412
|
|
|
2317
|
-
// ── Canvas sync (OSC 10/11) ──
|
|
2413
|
+
// ── Canvas sync (OSC 10/11) + scheme detection ──
|
|
2318
2414
|
// Runs after tui.start() (raw stdin only exists now) and after the exit
|
|
2319
2415
|
// handler registration above, so every set has a restore path from the
|
|
2320
2416
|
// moment it is written. Replies are harvested by a temporary input listener
|
|
2321
2417
|
// on pi-tui's normal pipeline (StdinBuffer emits whole escape sequences) —
|
|
2322
2418
|
// stdin is never intercepted, so keystrokes during the window flow to the
|
|
2323
2419
|
// regular listeners untouched and no drain buffer is needed.
|
|
2324
|
-
|
|
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) {
|
|
2325
2425
|
let replyBytes = '';
|
|
2326
2426
|
let settled = false;
|
|
2327
2427
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -2338,6 +2438,11 @@ async function main() {
|
|
|
2338
2438
|
}
|
|
2339
2439
|
replyBytes += data;
|
|
2340
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
|
+
}
|
|
2341
2446
|
const fgDone = canvasPlan.fg === undefined || replies.fg !== undefined;
|
|
2342
2447
|
const bgDone = canvasPlan.bg === undefined || replies.bg !== undefined;
|
|
2343
2448
|
if (fgDone && bgDone) finish?.(); // both planned channels answered — skip the rest of the timeout
|
|
@@ -2361,10 +2466,19 @@ async function main() {
|
|
|
2361
2466
|
unsubscribe();
|
|
2362
2467
|
finish = undefined;
|
|
2363
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
|
+
|
|
2364
2480
|
// Set only channels present in BOTH the plan and the reply; the raw reply
|
|
2365
2481
|
// payload is what we restore verbatim on exit.
|
|
2366
|
-
const replies = parseCanvasReplies(replyBytes);
|
|
2367
|
-
replyBytes = ''; // explicit discard — the parse above is the only consumer
|
|
2368
2482
|
const sets: string[] = [];
|
|
2369
2483
|
const saved: CanvasSync = {};
|
|
2370
2484
|
if (canvasPlan.fg !== undefined && replies.fg !== undefined) {
|
|
@@ -2380,6 +2494,31 @@ async function main() {
|
|
|
2380
2494
|
tui.terminal.write(sets.join(''));
|
|
2381
2495
|
}
|
|
2382
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
|
+
}
|
|
2383
2522
|
}
|
|
2384
2523
|
|
|
2385
2524
|
main().catch((err) => {
|
|
@@ -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
|
|