@zergai/ztc 0.16.2-dev.202611091056 → 0.17.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/RUST_THIRD_PARTY_LICENSES.txt +790 -753
- package/THIRD_PARTY_NOTICES.md +1203 -8
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +0 -0
- package/dist/agent/commands/settings.js +17 -0
- package/dist/config/types.d.ts +9 -0
- package/dist/diagnostics/native_terminal_benchmark.js +9 -2
- package/dist/mcp/workspace_server.d.ts +10 -0
- package/dist/mcp/workspace_server.js +8 -0
- package/dist/panes/agent_cli.d.ts +6 -2
- package/dist/panes/agent_cli.js +7 -2
- package/dist/panes/agent_panes.d.ts +1 -1
- package/dist/panes/agent_panes.js +15 -1
- package/dist/panes/claude_notifications.d.ts +27 -0
- package/dist/panes/claude_notifications.js +34 -0
- package/dist/ui/core/text_width.d.ts +16 -5
- package/dist/ui/core/text_width.js +100 -22
- package/dist/ui/ratatui/pane_relay.js +2 -2
- package/dist/ui/ratatui/protocol.d.ts +57 -0
- package/dist/ui/ratatui/protocol.js +11 -0
- package/dist/ui/scrollback.js +11 -3
- package/dist/zlm-embed.mjs +1 -1
- package/package.json +44 -10
package/bin/zmux-darwin-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/ztc-llm-darwin-arm64
CHANGED
|
Binary file
|
package/bin/ztc-tts-darwin-arm64
CHANGED
|
Binary file
|
package/bin/ztc-tui-darwin-arm64
CHANGED
|
Binary file
|
package/bin/zterm-darwin-arm64
CHANGED
|
Binary file
|
|
@@ -16,6 +16,7 @@ import { loadRouterCredentials, routingAfterLogout } from '../../router_auth.js'
|
|
|
16
16
|
import { CODEX_REASONING_EFFORTS } from '../../config/types.js';
|
|
17
17
|
import { customPaneOptions, storedCustomPaneOptions, withCustomPaneOptions, } from '../../config/panes.js';
|
|
18
18
|
import { getMcpServerStatuses } from '../../mcp/registry.js';
|
|
19
|
+
import { claudeBadgesOn } from '../../panes/claude_notifications.js';
|
|
19
20
|
import { CLAUDE_SUBSCRIPTION_POLICY, isRetiredProvider, retiredProviderMessage } from '../../config/retired_routes.js';
|
|
20
21
|
import { subsCommand } from './subs.js';
|
|
21
22
|
import { modelForProviderSwitch } from './provider_model_defaults.js';
|
|
@@ -919,6 +920,17 @@ export async function buildSettingsCategories(ctx) {
|
|
|
919
920
|
},
|
|
920
921
|
],
|
|
921
922
|
},
|
|
923
|
+
{
|
|
924
|
+
name: 'panesClaudeBadges',
|
|
925
|
+
label: 'Claude Code badges',
|
|
926
|
+
value: String(claudeBadgesOn(config.panes)),
|
|
927
|
+
type: 'select',
|
|
928
|
+
options: [
|
|
929
|
+
{ value: 'true', label: 'on', description: 'Claude Code panes the desktop app opens notify through kitty\'s channel, which badges the pane, ahead of a channel chosen in Claude Code' },
|
|
930
|
+
{ value: 'false', label: 'off', description: 'ZTC passes nothing: Claude Code notifies as its own settings say' },
|
|
931
|
+
],
|
|
932
|
+
description: 'Desktop app only. A --settings you give a pane yourself still wins.',
|
|
933
|
+
},
|
|
922
934
|
],
|
|
923
935
|
},
|
|
924
936
|
{
|
|
@@ -1281,6 +1293,11 @@ function applySettingChange(ctx, setting, value) {
|
|
|
1281
1293
|
// opens. A renderer without that surface must not store a typed line over
|
|
1282
1294
|
// the list, so refuse rather than corrupt the entries.
|
|
1283
1295
|
throw new Error('Custom pane options are edited from the manager on this row (Enter).');
|
|
1296
|
+
case 'panesClaudeBadges':
|
|
1297
|
+
if (value !== 'true' && value !== 'false')
|
|
1298
|
+
throw new Error('Claude Code badges must be on or off.');
|
|
1299
|
+
ctx.config.set('panes', { ...ctx.config.get().panes, claudeBadges: value === 'true' });
|
|
1300
|
+
break;
|
|
1284
1301
|
case 'authMode':
|
|
1285
1302
|
if (ctx.config.setAuthMode)
|
|
1286
1303
|
ctx.config.setAuthMode(value);
|
package/dist/config/types.d.ts
CHANGED
|
@@ -291,6 +291,15 @@ export interface PanesSettings {
|
|
|
291
291
|
* on. False: never.
|
|
292
292
|
*/
|
|
293
293
|
remoteView?: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Ask the Claude Code panes the desktop app opens to notify through kitty's
|
|
296
|
+
* channel (`--settings '{"preferredNotifChannel":"kitty"}'`), which the
|
|
297
|
+
* desktop terminal shows as a badge on the pane. Claude Code takes it over a
|
|
298
|
+
* channel chosen in its own settings; the person's own `--settings` for the
|
|
299
|
+
* pane still wins. False: ZTC passes nothing and Claude Code's own choice
|
|
300
|
+
* applies. ZTC never opens Claude Code's files to decide. Default: true.
|
|
301
|
+
*/
|
|
302
|
+
claudeBadges?: boolean;
|
|
294
303
|
/** The ZTC sign-in profile new Claude Code / Codex panes start on; unset for the CLI's own sign-in. */
|
|
295
304
|
agentProfiles?: Partial<Record<'claude' | 'codex', string>>;
|
|
296
305
|
/**
|
|
@@ -6,7 +6,7 @@ import { createServer as createHttpServer } from 'node:http';
|
|
|
6
6
|
import { syncBuiltinESMExports } from 'node:module';
|
|
7
7
|
import net from 'node:net';
|
|
8
8
|
import os from 'node:os';
|
|
9
|
-
import { basename, join, resolve } from 'node:path';
|
|
9
|
+
import { basename, join, resolve, sep } from 'node:path';
|
|
10
10
|
import { performance } from 'node:perf_hooks';
|
|
11
11
|
import { promisify } from 'node:util';
|
|
12
12
|
export class NativeTerminalBenchmarkError extends Error {
|
|
@@ -616,6 +616,13 @@ export function evaluateNativeBudget(id, attempts, budget, smoke, cleanup) {
|
|
|
616
616
|
|| (limits.mean !== undefined && Number(row.max) > limits.mean));
|
|
617
617
|
return { id, status: breached ? 'failed' : 'passed', summary, limits, ...(conditions.length ? { conditions } : {}) };
|
|
618
618
|
}
|
|
619
|
+
/** Every Rust file under `directory`, a working-directory path, sorted. Receipts bind each renderer module, so code
|
|
620
|
+
* moved into a new module stays in the receipt and in the unchanged-sources gate. */
|
|
621
|
+
async function rustSourceFiles(directory) {
|
|
622
|
+
const { readdir } = await import('node:fs/promises');
|
|
623
|
+
const entries = await readdir(resolve(directory), { recursive: true });
|
|
624
|
+
return entries.filter(entry => entry.endsWith('.rs')).map(entry => `${directory}/${entry.split(sep).join('/')}`).sort();
|
|
625
|
+
}
|
|
619
626
|
/** Actual native process/Unix IPC measurements. All attempts and policy gaps are retained. */
|
|
620
627
|
export async function runNativeTerminalBenchmark(options) {
|
|
621
628
|
if (!options.binary.trim() || !options.outputDirectory.trim() || !options.budgetsPath.trim()) {
|
|
@@ -634,7 +641,7 @@ export async function runNativeTerminalBenchmark(options) {
|
|
|
634
641
|
const attempts = [];
|
|
635
642
|
const cleanup = [];
|
|
636
643
|
const sourceFiles = ['src/diagnostics/native_terminal_benchmark.ts', 'scripts/benchmark-zterm.ts', 'src/cli_ratatui.ts',
|
|
637
|
-
'src/ui/ratatui/process.ts', 'src/ui/ratatui/protocol.ts', 'packages/ztc-core/src/protocol.rs',
|
|
644
|
+
'src/ui/ratatui/process.ts', 'src/ui/ratatui/protocol.ts', 'packages/ztc-core/src/protocol.rs', ...await rustSourceFiles('packages/zterm/src'), 'packages/zterm/Cargo.lock'];
|
|
638
645
|
const sourceHashes = {};
|
|
639
646
|
for (const path of sourceFiles)
|
|
640
647
|
sourceHashes[path] = sha256(await readFile(resolve(path)));
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* another agent; close a pane. Messages travel over ZTC's bus when the mirror
|
|
9
9
|
* is reachable, so ZTC panes receive them as messages from this pane;
|
|
10
10
|
* otherwise they are typed in with the sender's name.
|
|
11
|
+
*
|
|
12
|
+
* It runs in a process of its own, so it reads ZTC's saved settings before
|
|
13
|
+
* each pane it opens, and the pane follows them as they are then: Claude Code
|
|
14
|
+
* badges, the sign-in profile, MotSi's remote view, a ZTC pane's route.
|
|
11
15
|
*/
|
|
12
16
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
13
17
|
import { type AgentCliId, type PaneProgram } from '../panes/agent_cli.js';
|
|
@@ -37,6 +41,12 @@ export interface WorkspaceMcpOptions {
|
|
|
37
41
|
cwd?: string;
|
|
38
42
|
/** `motsi` to start panes through (Zerg Router's Command Central); null for none; default: MotSi's remote view. */
|
|
39
43
|
motsi?: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Reads ZTC's saved settings into this process's config store; awaited
|
|
46
|
+
* before each pane opens. `ztc workspace-mcp` learns them no other way. A
|
|
47
|
+
* server in a ZTC process whose store is loaded already leaves it unset.
|
|
48
|
+
*/
|
|
49
|
+
loadSettings?: () => Promise<unknown>;
|
|
40
50
|
}
|
|
41
51
|
/** The MCP server, connected to a workspace through `transport`. */
|
|
42
52
|
export declare function createWorkspaceMcpServer(options: WorkspaceMcpOptions): Server;
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* another agent; close a pane. Messages travel over ZTC's bus when the mirror
|
|
9
9
|
* is reachable, so ZTC panes receive them as messages from this pane;
|
|
10
10
|
* otherwise they are typed in with the sender's name.
|
|
11
|
+
*
|
|
12
|
+
* It runs in a process of its own, so it reads ZTC's saved settings before
|
|
13
|
+
* each pane it opens, and the pane follows them as they are then: Claude Code
|
|
14
|
+
* badges, the sign-in profile, MotSi's remote view, a ZTC pane's route.
|
|
11
15
|
*/
|
|
12
16
|
import { request } from 'node:http';
|
|
13
17
|
import { randomUUID } from 'node:crypto';
|
|
@@ -270,6 +274,8 @@ export function createWorkspaceMcpServer(options) {
|
|
|
270
274
|
.join('\n');
|
|
271
275
|
},
|
|
272
276
|
open_pane: async (args) => {
|
|
277
|
+
// Each pane follows ZTC's settings as they are saved when it opens.
|
|
278
|
+
await options.loadSettings?.();
|
|
273
279
|
const kind = String(args.kind ?? '');
|
|
274
280
|
const cwd = typeof args.cwd === 'string' && args.cwd.trim() ? args.cwd.trim() : (options.cwd ?? process.cwd());
|
|
275
281
|
if (kind === 'ztc')
|
|
@@ -404,6 +410,8 @@ export async function runWorkspaceMcpServer(env = process.env) {
|
|
|
404
410
|
ownPaneId: Number.isSafeInteger(paneId) && paneId >= 0 ? paneId : null,
|
|
405
411
|
bus: mirrorBusSender(env),
|
|
406
412
|
env,
|
|
413
|
+
// Nothing else in this process loads them: cli_main.ts starts the server first.
|
|
414
|
+
loadSettings: () => configStore.load(true),
|
|
407
415
|
});
|
|
408
416
|
const stdio = new StdioServerTransport();
|
|
409
417
|
const closed = new Promise(resolve => { stdio.onclose = () => resolve(); });
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* What ZTC adds is a session-scoped MCP server, `ztc workspace-mcp`, passed on
|
|
11
11
|
* the command line (Claude Code `--mcp-config`, Codex `-c mcp_servers.ztc.*`),
|
|
12
12
|
* so the agent can list, open, read, type into, message and close the other
|
|
13
|
-
* panes of the workspace
|
|
13
|
+
* panes of the workspace; and in the desktop app, which badges panes, the
|
|
14
|
+
* notification channel Claude Code doesn't know to use there, while ZTC's
|
|
15
|
+
* `panes.claudeBadges` setting asks for it (claude_notifications.ts). The
|
|
16
|
+
* user's own CLI configuration is never edited.
|
|
14
17
|
*/
|
|
15
18
|
export type AgentCliId = 'claude' | 'codex';
|
|
16
19
|
export interface AgentCliSpec {
|
|
@@ -67,7 +70,8 @@ export interface PaneProgram {
|
|
|
67
70
|
}
|
|
68
71
|
export declare const WORKSPACE_MCP_SERVER_NAME = "ztc";
|
|
69
72
|
/**
|
|
70
|
-
* Variables the workspace server reads
|
|
73
|
+
* Variables the workspace server reads, where ZTC's settings are among them
|
|
74
|
+
* (the profile and ZTC_CONFIG_DIR). Codex starts MCP servers with a short
|
|
71
75
|
* allowlist of variables, so these are named for it to forward; Claude Code
|
|
72
76
|
* passes its whole environment. They reach the pane through its environment,
|
|
73
77
|
* never its command line.
|
package/dist/panes/agent_cli.js
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* What ZTC adds is a session-scoped MCP server, `ztc workspace-mcp`, passed on
|
|
11
11
|
* the command line (Claude Code `--mcp-config`, Codex `-c mcp_servers.ztc.*`),
|
|
12
12
|
* so the agent can list, open, read, type into, message and close the other
|
|
13
|
-
* panes of the workspace
|
|
13
|
+
* panes of the workspace; and in the desktop app, which badges panes, the
|
|
14
|
+
* notification channel Claude Code doesn't know to use there, while ZTC's
|
|
15
|
+
* `panes.claudeBadges` setting asks for it (claude_notifications.ts). The
|
|
16
|
+
* user's own CLI configuration is never edited.
|
|
14
17
|
*/
|
|
15
18
|
import { accessSync, constants, existsSync, statSync } from 'node:fs';
|
|
16
19
|
import { homedir } from 'node:os';
|
|
@@ -187,7 +190,8 @@ export function parseAgentCommandBody(body) {
|
|
|
187
190
|
}
|
|
188
191
|
export const WORKSPACE_MCP_SERVER_NAME = 'ztc';
|
|
189
192
|
/**
|
|
190
|
-
* Variables the workspace server reads
|
|
193
|
+
* Variables the workspace server reads, where ZTC's settings are among them
|
|
194
|
+
* (the profile and ZTC_CONFIG_DIR). Codex starts MCP servers with a short
|
|
191
195
|
* allowlist of variables, so these are named for it to forward; Claude Code
|
|
192
196
|
* passes its whole environment. They reach the pane through its environment,
|
|
193
197
|
* never its command line.
|
|
@@ -200,6 +204,7 @@ export const WORKSPACE_MCP_ENV = Object.freeze([
|
|
|
200
204
|
'ZTC_MIRROR_GROUP',
|
|
201
205
|
'ZTC_NAVIGATOR_GROUP',
|
|
202
206
|
'ZTC_PROFILE',
|
|
207
|
+
'ZTC_CONFIG_DIR',
|
|
203
208
|
]);
|
|
204
209
|
function tomlString(value) {
|
|
205
210
|
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/[\u0000-\u001f\u007f]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`)}"`;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* the process has: the overseer's renderer connection, or a child pane's relay.
|
|
8
8
|
*/
|
|
9
9
|
import type { PaneCommandTransport } from '../ui/ratatui/pane_relay.js';
|
|
10
|
-
import type
|
|
10
|
+
import { type SplitDirection } from '../ui/ratatui/protocol.js';
|
|
11
11
|
import { type AgentCliId, type AgentLaunchRequest, type PaneProgram } from './agent_cli.js';
|
|
12
12
|
/** Request ids of agent pane launches start with this, so the overseer can tell them apart. */
|
|
13
13
|
export declare const AGENT_PANE_REQUEST_PREFIX = "agent-pane:";
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
10
|
import { listWorkspacePanes, waitForPaneCreatedOrError } from '../agent/tools/pane.js';
|
|
11
|
+
import { CAPABILITY_ATTENTION_BADGES, CAPABILITY_SYNCHRONIZED_OUTPUT } from '../ui/ratatui/protocol.js';
|
|
11
12
|
import { AGENT_CLIS, agentCliArgs, agentPaneEnv, findAgentCli, isAgentCliId, loginShellExec, nextPaneTitle, workspaceMcpProgram, } from './agent_cli.js';
|
|
12
13
|
import { sessionNamePaneTitle } from './labels.js';
|
|
13
14
|
import { MOTSI_PANE_ENV, remoteViewMotsi, throughMotsi } from './motsi.js';
|
|
14
15
|
import { agentProfileClearedEnv, agentProfileEnv, ensureAgentProfile } from './agent_profiles.js';
|
|
16
|
+
import { badgedNotificationArgs } from './claude_notifications.js';
|
|
15
17
|
import { configStore } from '../config.js';
|
|
16
18
|
/** Request ids of agent pane launches start with this, so the overseer can tell them apart. */
|
|
17
19
|
export const AGENT_PANE_REQUEST_PREFIX = 'agent-pane:';
|
|
@@ -58,9 +60,16 @@ export async function openAgentPane(transport, options) {
|
|
|
58
60
|
}
|
|
59
61
|
const label = profile ? `${spec.label} (${profile})` : spec.label;
|
|
60
62
|
const title = options.title?.trim() || nextPaneTitle(label, await existingTitles(transport));
|
|
63
|
+
// Claude Code notifies only terminals it knows by name, and zterm isn't one:
|
|
64
|
+
// on a renderer that badges panes it is asked for a channel zterm reads,
|
|
65
|
+
// while ZTC's own setting says so (claude_notifications.ts).
|
|
66
|
+
const notifyArgs = options.cli === 'claude' && transport.hasCapability?.(CAPABILITY_ATTENTION_BADGES)
|
|
67
|
+
? badgedNotificationArgs(options.request?.words ?? [], configStore.get().panes)
|
|
68
|
+
: [];
|
|
61
69
|
const cliArgs = [
|
|
62
70
|
// On a profile, Codex keeps the sign-in in the profile's files, never a keyring entry other terminals share.
|
|
63
71
|
...(profile && options.cli === 'codex' ? ['-c', 'cli_auth_credentials_store="file"'] : []),
|
|
72
|
+
...notifyArgs,
|
|
64
73
|
...agentCliArgs(options.cli, options.request ?? { words: [] }, attached),
|
|
65
74
|
];
|
|
66
75
|
const motsi = options.motsi === undefined ? remoteViewMotsi(configStore.get().panes, { env }) : options.motsi;
|
|
@@ -72,6 +81,11 @@ export async function openAgentPane(transport, options) {
|
|
|
72
81
|
? loginShellExec(motsi, throughMotsi(motsi, title, { command: binary, args: cliArgs }).args, env.SHELL, process.platform, cleared)
|
|
73
82
|
: loginShellExec(binary, cliArgs, env.SHELL, process.platform, cleared);
|
|
74
83
|
const requestId = `${AGENT_PANE_REQUEST_PREFIX}${options.cli}:${randomUUID()}`;
|
|
84
|
+
// Claude Code draws in synchronized updates only in terminals it knows by
|
|
85
|
+
// name; a renderer that shows them whole (zterm) says so, and it is told.
|
|
86
|
+
const syncEnv = options.cli === 'claude' && transport.hasCapability?.(CAPABILITY_SYNCHRONIZED_OUTPUT)
|
|
87
|
+
? { CLAUDE_CODE_FORCE_SYNC_OUTPUT: '1' }
|
|
88
|
+
: {};
|
|
75
89
|
const created = waitForPaneCreatedOrError(transport, { requestId }, 15000);
|
|
76
90
|
const sent = transport.send({
|
|
77
91
|
type: 'create_pane',
|
|
@@ -85,7 +99,7 @@ export async function openAgentPane(transport, options) {
|
|
|
85
99
|
...(options.ratio !== undefined ? { ratio: options.ratio } : {}),
|
|
86
100
|
...(options.target !== undefined ? { target: options.target } : {}),
|
|
87
101
|
...(options.newWindow ? { new_window: true } : {}),
|
|
88
|
-
env: { ...agentPaneEnv(env), ...(motsi ? MOTSI_PANE_ENV : {}), ...profileEnv },
|
|
102
|
+
env: { ...agentPaneEnv(env), ...(motsi ? MOTSI_PANE_ENV : {}), ...syncEnv, ...profileEnv },
|
|
89
103
|
});
|
|
90
104
|
if (!sent) {
|
|
91
105
|
created.catch(() => { });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How Claude Code panes notify in a renderer that badges panes (zterm).
|
|
3
|
+
*
|
|
4
|
+
* Claude Code picks how to notify by the terminal's name when its
|
|
5
|
+
* `preferredNotifChannel` is "auto", its default: the bell in Terminal, OSC 9
|
|
6
|
+
* in iTerm2, OSC 99 in kitty, OSC 777 in Ghostty, and nothing anywhere else,
|
|
7
|
+
* zterm included. In a renderer that badges a pane whose program notifies,
|
|
8
|
+
* ZTC asks for kitty's channel, whose notifications carry a title and a body,
|
|
9
|
+
* on the command line as it passes the workspace server, while ZTC's
|
|
10
|
+
* `panes.claudeBadges` setting is on (its default). Claude Code takes a
|
|
11
|
+
* setting there over its own settings files, so the request comes before a
|
|
12
|
+
* channel the person chose in Claude Code; off, ZTC passes nothing and Claude
|
|
13
|
+
* Code's own choice applies. ZTC decides from its own setting alone and never
|
|
14
|
+
* opens Claude Code's files: Claude Code reads its own when it runs.
|
|
15
|
+
*/
|
|
16
|
+
import type { PanesSettings } from '../config/types.js';
|
|
17
|
+
/** The channel ZTC asks for: kitty's notifications, which zterm reads. */
|
|
18
|
+
export declare const BADGED_NOTIFICATION_CHANNEL = "kitty";
|
|
19
|
+
/** Whether ZTC asks Claude Code panes for the channel a badging renderer reads: on unless `panes.claudeBadges` is false. */
|
|
20
|
+
export declare function claudeBadgesOn(panes: Pick<PanesSettings, 'claudeBadges'> | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The arguments that ask Claude Code for the channel a badging renderer
|
|
23
|
+
* reads, given ZTC's pane settings and the person's own `words` for the
|
|
24
|
+
* pane: none when the setting is off or the person passes settings of their
|
|
25
|
+
* own.
|
|
26
|
+
*/
|
|
27
|
+
export declare function badgedNotificationArgs(words: readonly string[], panes: Pick<PanesSettings, 'claudeBadges'> | undefined): string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How Claude Code panes notify in a renderer that badges panes (zterm).
|
|
3
|
+
*
|
|
4
|
+
* Claude Code picks how to notify by the terminal's name when its
|
|
5
|
+
* `preferredNotifChannel` is "auto", its default: the bell in Terminal, OSC 9
|
|
6
|
+
* in iTerm2, OSC 99 in kitty, OSC 777 in Ghostty, and nothing anywhere else,
|
|
7
|
+
* zterm included. In a renderer that badges a pane whose program notifies,
|
|
8
|
+
* ZTC asks for kitty's channel, whose notifications carry a title and a body,
|
|
9
|
+
* on the command line as it passes the workspace server, while ZTC's
|
|
10
|
+
* `panes.claudeBadges` setting is on (its default). Claude Code takes a
|
|
11
|
+
* setting there over its own settings files, so the request comes before a
|
|
12
|
+
* channel the person chose in Claude Code; off, ZTC passes nothing and Claude
|
|
13
|
+
* Code's own choice applies. ZTC decides from its own setting alone and never
|
|
14
|
+
* opens Claude Code's files: Claude Code reads its own when it runs.
|
|
15
|
+
*/
|
|
16
|
+
/** The channel ZTC asks for: kitty's notifications, which zterm reads. */
|
|
17
|
+
export const BADGED_NOTIFICATION_CHANNEL = 'kitty';
|
|
18
|
+
/** Whether ZTC asks Claude Code panes for the channel a badging renderer reads: on unless `panes.claudeBadges` is false. */
|
|
19
|
+
export function claudeBadgesOn(panes) {
|
|
20
|
+
return panes?.claudeBadges !== false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The arguments that ask Claude Code for the channel a badging renderer
|
|
24
|
+
* reads, given ZTC's pane settings and the person's own `words` for the
|
|
25
|
+
* pane: none when the setting is off or the person passes settings of their
|
|
26
|
+
* own.
|
|
27
|
+
*/
|
|
28
|
+
export function badgedNotificationArgs(words, panes) {
|
|
29
|
+
if (!claudeBadgesOn(panes))
|
|
30
|
+
return [];
|
|
31
|
+
if (words.some(word => word === '--settings' || word.startsWith('--settings=')))
|
|
32
|
+
return [];
|
|
33
|
+
return ['--settings', JSON.stringify({ preferredNotifChannel: BADGED_NOTIFICATION_CHANNEL })];
|
|
34
|
+
}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Single source of truth for:
|
|
5
5
|
* - CRLF + non-SGR terminal-control stripping (`normalizeTranscriptText`)
|
|
6
6
|
* - complete terminal-control stripping for untrusted values (`sanitizeTerminalText`)
|
|
7
|
-
* - Display-cell width
|
|
8
|
-
*
|
|
7
|
+
* - Display-cell width (`displayWidth`): two columns for each character
|
|
8
|
+
* Rust's `unicode-width` 0.2 gives two (its table, `WIDE_RANGES`), none
|
|
9
|
+
* for controls and the common combining marks, one for the rest
|
|
9
10
|
* - Right-padding to a target display width (`padEndDisplay`)
|
|
10
11
|
*
|
|
11
12
|
* Used by:
|
|
@@ -13,12 +14,22 @@
|
|
|
13
14
|
* - `ui/core/layout_yoga.ts` yoga measure callback
|
|
14
15
|
* - any future call site that needs display-cell math
|
|
15
16
|
*
|
|
16
|
-
* Cross-language parity is enforced by `tests/unit/
|
|
17
|
-
* shared fixture at `tests/fixtures/widths.json
|
|
18
|
-
* `ztc/packages/
|
|
17
|
+
* Cross-language parity is enforced by `tests/unit/text_width_parity.test.ts`
|
|
18
|
+
* and the shared fixture at `tests/fixtures/widths.json`, which zterm's ZTC
|
|
19
|
+
* pane parser reads too (`ztc/packages/zterm/src/ztc_text/cells.rs`).
|
|
19
20
|
*/
|
|
20
21
|
export declare function normalizeTranscriptText(value: string): string;
|
|
21
22
|
/** Remove every terminal control sequence from untrusted display values. */
|
|
22
23
|
export declare function sanitizeTerminalText(value: string): string;
|
|
23
24
|
export declare function displayWidth(value: string): number;
|
|
25
|
+
/** Columns from one tab stop to the next, a terminal's. */
|
|
26
|
+
export declare const TAB_STOP = 8;
|
|
27
|
+
/**
|
|
28
|
+
* `line` with each tab replaced by the spaces that reach the next tab stop,
|
|
29
|
+
* counting the columns from the line's start as `displayWidth` does: its
|
|
30
|
+
* SGR sequences (the only escapes `normalizeTranscriptText` keeps) take
|
|
31
|
+
* none. zterm and zmux give a tab no column, as `displayWidth` does, so a
|
|
32
|
+
* transcript line's tabs become spaces before it is wrapped and padded.
|
|
33
|
+
*/
|
|
34
|
+
export declare function expandTabs(line: string): string;
|
|
24
35
|
export declare function padEndDisplay(value: string, targetWidth: number): string;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Single source of truth for:
|
|
5
5
|
* - CRLF + non-SGR terminal-control stripping (`normalizeTranscriptText`)
|
|
6
6
|
* - complete terminal-control stripping for untrusted values (`sanitizeTerminalText`)
|
|
7
|
-
* - Display-cell width
|
|
8
|
-
*
|
|
7
|
+
* - Display-cell width (`displayWidth`): two columns for each character
|
|
8
|
+
* Rust's `unicode-width` 0.2 gives two (its table, `WIDE_RANGES`), none
|
|
9
|
+
* for controls and the common combining marks, one for the rest
|
|
9
10
|
* - Right-padding to a target display width (`padEndDisplay`)
|
|
10
11
|
*
|
|
11
12
|
* Used by:
|
|
@@ -13,9 +14,9 @@
|
|
|
13
14
|
* - `ui/core/layout_yoga.ts` yoga measure callback
|
|
14
15
|
* - any future call site that needs display-cell math
|
|
15
16
|
*
|
|
16
|
-
* Cross-language parity is enforced by `tests/unit/
|
|
17
|
-
* shared fixture at `tests/fixtures/widths.json
|
|
18
|
-
* `ztc/packages/
|
|
17
|
+
* Cross-language parity is enforced by `tests/unit/text_width_parity.test.ts`
|
|
18
|
+
* and the shared fixture at `tests/fixtures/widths.json`, which zterm's ZTC
|
|
19
|
+
* pane parser reads too (`ztc/packages/zterm/src/ztc_text/cells.rs`).
|
|
19
20
|
*/
|
|
20
21
|
const ESC = 0x1b;
|
|
21
22
|
const BEL = 0x07;
|
|
@@ -165,19 +166,62 @@ function isCombiningCodePoint(code) {
|
|
|
165
166
|
|| code === 0xfe0e
|
|
166
167
|
|| code === 0xfe0f;
|
|
167
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* The code points `unicode-width` 0.2.0 gives two columns, as inclusive
|
|
171
|
+
* [first, last] pairs in order: the version zterm, zmux and alacritty
|
|
172
|
+
* measure with, so a character ZTC lays out takes the columns a ZTC pane
|
|
173
|
+
* and a terminal draw it in. Among them are the wide emoji of the BMP
|
|
174
|
+
* (⌚ ⏳ ☕ ⚡ ✅ ❌ ⭐ and the rest East Asian Width calls W) and outside
|
|
175
|
+
* it (🀄 🆕 🈁 ...). Generated from `UnicodeWidthChar::width` over every
|
|
176
|
+
* code point; regenerate it when the crate's version changes.
|
|
177
|
+
*/
|
|
178
|
+
const WIDE_RANGES = [
|
|
179
|
+
0x1100, 0x115f, 0x17a4, 0x17a4, 0x231a, 0x231b, 0x2329, 0x232a, 0x23e9, 0x23ec, 0x23f0, 0x23f0,
|
|
180
|
+
0x23f3, 0x23f3, 0x25fd, 0x25fe, 0x2614, 0x2615, 0x2648, 0x2653, 0x267f, 0x267f, 0x2693, 0x2693,
|
|
181
|
+
0x26a1, 0x26a1, 0x26aa, 0x26ab, 0x26bd, 0x26be, 0x26c4, 0x26c5, 0x26ce, 0x26ce, 0x26d4, 0x26d4,
|
|
182
|
+
0x26ea, 0x26ea, 0x26f2, 0x26f3, 0x26f5, 0x26f5, 0x26fa, 0x26fa, 0x26fd, 0x26fd, 0x2705, 0x2705,
|
|
183
|
+
0x270a, 0x270b, 0x2728, 0x2728, 0x274c, 0x274c, 0x274e, 0x274e, 0x2753, 0x2755, 0x2757, 0x2757,
|
|
184
|
+
0x2795, 0x2797, 0x27b0, 0x27b0, 0x27bf, 0x27bf, 0x2b1b, 0x2b1c, 0x2b50, 0x2b50, 0x2b55, 0x2b55,
|
|
185
|
+
0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5, 0x2ff0, 0x3029, 0x3030, 0x303e, 0x3041, 0x3096,
|
|
186
|
+
0x309b, 0x30ff, 0x3105, 0x312f, 0x3131, 0x3163, 0x3165, 0x318e, 0x3190, 0x31e3, 0x31ef, 0x321e,
|
|
187
|
+
0x3220, 0x3247, 0x3250, 0x4dbf, 0x4e00, 0xa48c, 0xa490, 0xa4c6, 0xa960, 0xa97c, 0xac00, 0xd7a3,
|
|
188
|
+
0xf900, 0xfaff, 0xfe10, 0xfe19, 0xfe30, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xff01, 0xff60,
|
|
189
|
+
0xffe0, 0xffe6, 0x16fe0, 0x16fe3, 0x16ff0, 0x16ff1, 0x17000, 0x187f7, 0x18800, 0x18cd5,
|
|
190
|
+
0x18d00, 0x18d08, 0x1aff0, 0x1aff3, 0x1aff5, 0x1affb, 0x1affd, 0x1affe, 0x1b000, 0x1b122,
|
|
191
|
+
0x1b132, 0x1b132, 0x1b150, 0x1b152, 0x1b155, 0x1b155, 0x1b164, 0x1b167, 0x1b170, 0x1b2fb,
|
|
192
|
+
0x1f004, 0x1f004, 0x1f0cf, 0x1f0cf, 0x1f18e, 0x1f18e, 0x1f191, 0x1f19a, 0x1f200, 0x1f202,
|
|
193
|
+
0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250, 0x1f251, 0x1f260, 0x1f265, 0x1f300, 0x1f320,
|
|
194
|
+
0x1f32d, 0x1f335, 0x1f337, 0x1f37c, 0x1f37e, 0x1f393, 0x1f3a0, 0x1f3ca, 0x1f3cf, 0x1f3d3,
|
|
195
|
+
0x1f3e0, 0x1f3f0, 0x1f3f4, 0x1f3f4, 0x1f3f8, 0x1f43e, 0x1f440, 0x1f440, 0x1f442, 0x1f4fc,
|
|
196
|
+
0x1f4ff, 0x1f53d, 0x1f54b, 0x1f54e, 0x1f550, 0x1f567, 0x1f57a, 0x1f57a, 0x1f595, 0x1f596,
|
|
197
|
+
0x1f5a4, 0x1f5a4, 0x1f5fb, 0x1f64f, 0x1f680, 0x1f6c5, 0x1f6cc, 0x1f6cc, 0x1f6d0, 0x1f6d2,
|
|
198
|
+
0x1f6d5, 0x1f6d7, 0x1f6dc, 0x1f6df, 0x1f6eb, 0x1f6ec, 0x1f6f4, 0x1f6fc, 0x1f7e0, 0x1f7eb,
|
|
199
|
+
0x1f7f0, 0x1f7f0, 0x1f90c, 0x1f93a, 0x1f93c, 0x1f945, 0x1f947, 0x1f9ff, 0x1fa70, 0x1fa7c,
|
|
200
|
+
0x1fa80, 0x1fa88, 0x1fa90, 0x1fabd, 0x1fabf, 0x1fac5, 0x1face, 0x1fadb, 0x1fae0, 0x1fae8,
|
|
201
|
+
0x1faf0, 0x1faf8, 0x20000, 0x2fffd, 0x30000, 0x3fffd,
|
|
202
|
+
];
|
|
168
203
|
function isWideCodePoint(code) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
if (code < WIDE_RANGES[0])
|
|
205
|
+
return false;
|
|
206
|
+
// The last pair whose first code point is at or below `code`.
|
|
207
|
+
let low = 0;
|
|
208
|
+
let high = WIDE_RANGES.length / 2 - 1;
|
|
209
|
+
while (low < high) {
|
|
210
|
+
const middle = (low + high + 1) >> 1;
|
|
211
|
+
if (WIDE_RANGES[middle * 2] <= code)
|
|
212
|
+
low = middle;
|
|
213
|
+
else
|
|
214
|
+
high = middle - 1;
|
|
215
|
+
}
|
|
216
|
+
return code <= WIDE_RANGES[low * 2 + 1];
|
|
217
|
+
}
|
|
218
|
+
/** The columns one code point takes: none for a control or a combining mark. */
|
|
219
|
+
function codePointWidth(code) {
|
|
220
|
+
if (code < 0x20 || (code >= 0x7f && code < 0xa0))
|
|
221
|
+
return 0;
|
|
222
|
+
if (isCombiningCodePoint(code))
|
|
223
|
+
return 0;
|
|
224
|
+
return isWideCodePoint(code) ? 2 : 1;
|
|
181
225
|
}
|
|
182
226
|
export function displayWidth(value) {
|
|
183
227
|
const clean = sanitizeTerminalText(value);
|
|
@@ -185,15 +229,49 @@ export function displayWidth(value) {
|
|
|
185
229
|
return clean.length;
|
|
186
230
|
let width = 0;
|
|
187
231
|
for (const char of clean) {
|
|
188
|
-
|
|
189
|
-
|
|
232
|
+
width += codePointWidth(char.codePointAt(0) ?? 0);
|
|
233
|
+
}
|
|
234
|
+
return width;
|
|
235
|
+
}
|
|
236
|
+
/** Columns from one tab stop to the next, a terminal's. */
|
|
237
|
+
export const TAB_STOP = 8;
|
|
238
|
+
/**
|
|
239
|
+
* `line` with each tab replaced by the spaces that reach the next tab stop,
|
|
240
|
+
* counting the columns from the line's start as `displayWidth` does: its
|
|
241
|
+
* SGR sequences (the only escapes `normalizeTranscriptText` keeps) take
|
|
242
|
+
* none. zterm and zmux give a tab no column, as `displayWidth` does, so a
|
|
243
|
+
* transcript line's tabs become spaces before it is wrapped and padded.
|
|
244
|
+
*/
|
|
245
|
+
export function expandTabs(line) {
|
|
246
|
+
if (!line.includes('\t'))
|
|
247
|
+
return line;
|
|
248
|
+
let output = '';
|
|
249
|
+
let column = 0;
|
|
250
|
+
let index = 0;
|
|
251
|
+
while (index < line.length) {
|
|
252
|
+
const code = line.codePointAt(index) ?? 0;
|
|
253
|
+
const csiStart = code === ESC && line.charCodeAt(index + 1) === 0x5b
|
|
254
|
+
? index + 2
|
|
255
|
+
: code === C1_CSI ? index + 1 : -1;
|
|
256
|
+
if (csiStart >= 0) {
|
|
257
|
+
const { end } = scanCsi(line, csiStart);
|
|
258
|
+
output += line.slice(index, end);
|
|
259
|
+
index = end;
|
|
190
260
|
continue;
|
|
191
261
|
}
|
|
192
|
-
if (
|
|
262
|
+
if (code === 0x09) {
|
|
263
|
+
const spaces = TAB_STOP - (column % TAB_STOP);
|
|
264
|
+
output += ' '.repeat(spaces);
|
|
265
|
+
column += spaces;
|
|
266
|
+
index += 1;
|
|
193
267
|
continue;
|
|
194
|
-
|
|
268
|
+
}
|
|
269
|
+
const char = String.fromCodePoint(code);
|
|
270
|
+
output += char;
|
|
271
|
+
column += codePointWidth(code);
|
|
272
|
+
index += char.length;
|
|
195
273
|
}
|
|
196
|
-
return
|
|
274
|
+
return output;
|
|
197
275
|
}
|
|
198
276
|
export function padEndDisplay(value, targetWidth) {
|
|
199
277
|
const padding = Math.max(0, targetWidth - displayWidth(value));
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { createServer, createConnection } from 'net';
|
|
13
13
|
import { createInterface } from 'readline';
|
|
14
|
-
import { serializeCommand, parseEvent, CAPABILITY_PANE_DELIVERY_ACK, CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_SESSION_SHARE } from './protocol.js';
|
|
14
|
+
import { serializeCommand, parseEvent, CAPABILITY_PANE_DELIVERY_ACK, CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_SESSION_SHARE, CAPABILITY_SYNCHRONIZED_OUTPUT, CAPABILITY_ATTENTION_BADGES } from './protocol.js';
|
|
15
15
|
import { runtimeDiag } from '../../utils/debug_log.js';
|
|
16
16
|
import { generateIpcPath, removeOwnedIpcPath } from './ipc_path.js';
|
|
17
17
|
// ============================================================================
|
|
@@ -54,7 +54,7 @@ export class PaneRelayServer {
|
|
|
54
54
|
this.server = createServer((client) => {
|
|
55
55
|
this.clients.add(client);
|
|
56
56
|
client.write(JSON.stringify({ type: 'ready', version: 'pane-relay', cols: 0, rows: 0,
|
|
57
|
-
capabilities: [CAPABILITY_PANE_DELIVERY_ACK, 'pane_labels_v1', CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_SESSION_SHARE]
|
|
57
|
+
capabilities: [CAPABILITY_PANE_DELIVERY_ACK, 'pane_labels_v1', CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_SESSION_SHARE, CAPABILITY_SYNCHRONIZED_OUTPUT, CAPABILITY_ATTENTION_BADGES]
|
|
58
58
|
.filter(capability => this.transport.hasCapability?.(capability)),
|
|
59
59
|
}) + '\n');
|
|
60
60
|
const rl = createInterface({ input: client, crlfDelay: Infinity });
|