@celljs/ta-harness 4.8.0 → 4.9.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.en.md +1 -1
- package/README.md +1 -1
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-archive.d.ts +38 -0
- package/esm/node/package-archive.js +258 -0
- package/esm/node/serve-state.d.ts +8 -0
- package/esm/node/serve-state.js +36 -0
- package/esm/node/ta-cli.d.ts +2 -0
- package/esm/node/ta-cli.js +45 -4
- package/esm/node/ta-packages.d.ts +1 -0
- package/esm/node/ta-packages.js +15 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-archive.d.ts +39 -0
- package/lib/node/package-archive.js +261 -0
- package/lib/node/serve-state.d.ts +8 -0
- package/lib/node/serve-state.js +36 -0
- package/lib/node/ta-cli.d.ts +2 -0
- package/lib/node/ta-cli.js +45 -4
- package/lib/node/ta-packages.d.ts +1 -0
- package/lib/node/ta-packages.js +15 -1
- package/package.json +6 -5
- package/esm/node/brand-extension.js.map +0 -1
- package/esm/node/bug-report.js.map +0 -1
- package/esm/node/dino-logo.js.map +0 -1
- package/esm/node/exec-extension.js.map +0 -1
- package/esm/node/exec-mcp-transport.js.map +0 -1
- package/esm/node/exec-operations.js.map +0 -1
- package/esm/node/extensions.js.map +0 -1
- package/esm/node/glob-util.js.map +0 -1
- package/esm/node/index.js.map +0 -1
- package/esm/node/pi-types.js.map +0 -1
- package/esm/node/remote-context-files.js.map +0 -1
- package/esm/node/serve-state.js.map +0 -1
- package/esm/node/session-lock.js.map +0 -1
- package/esm/node/ta-brand.js.map +0 -1
- package/esm/node/ta-cli.js.map +0 -1
- package/esm/node/ta-header.js.map +0 -1
- package/esm/node/ta-packages.js.map +0 -1
- package/lib/node/brand-extension.d.ts.map +0 -1
- package/lib/node/brand-extension.js.map +0 -1
- package/lib/node/brand-extension.spec.d.ts +0 -2
- package/lib/node/brand-extension.spec.d.ts.map +0 -1
- package/lib/node/brand-extension.spec.js +0 -57
- package/lib/node/brand-extension.spec.js.map +0 -1
- package/lib/node/bug-report.d.ts.map +0 -1
- package/lib/node/bug-report.js.map +0 -1
- package/lib/node/bug-report.spec.d.ts +0 -2
- package/lib/node/bug-report.spec.d.ts.map +0 -1
- package/lib/node/bug-report.spec.js +0 -11
- package/lib/node/bug-report.spec.js.map +0 -1
- package/lib/node/dino-logo.d.ts.map +0 -1
- package/lib/node/dino-logo.js.map +0 -1
- package/lib/node/exec-extension.d.ts.map +0 -1
- package/lib/node/exec-extension.js.map +0 -1
- package/lib/node/exec-mcp-transport.d.ts.map +0 -1
- package/lib/node/exec-mcp-transport.js.map +0 -1
- package/lib/node/exec-operations.d.ts.map +0 -1
- package/lib/node/exec-operations.js.map +0 -1
- package/lib/node/exec-operations.spec.d.ts +0 -2
- package/lib/node/exec-operations.spec.d.ts.map +0 -1
- package/lib/node/exec-operations.spec.js +0 -77
- package/lib/node/exec-operations.spec.js.map +0 -1
- package/lib/node/extensions.d.ts.map +0 -1
- package/lib/node/extensions.js.map +0 -1
- package/lib/node/extensions.spec.d.ts +0 -2
- package/lib/node/extensions.spec.d.ts.map +0 -1
- package/lib/node/extensions.spec.js +0 -94
- package/lib/node/extensions.spec.js.map +0 -1
- package/lib/node/glob-util.d.ts.map +0 -1
- package/lib/node/glob-util.js.map +0 -1
- package/lib/node/glob-util.spec.d.ts +0 -2
- package/lib/node/glob-util.spec.d.ts.map +0 -1
- package/lib/node/glob-util.spec.js +0 -27
- package/lib/node/glob-util.spec.js.map +0 -1
- package/lib/node/index.d.ts.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/pi-types.d.ts.map +0 -1
- package/lib/node/pi-types.js.map +0 -1
- package/lib/node/remote-context-files.d.ts.map +0 -1
- package/lib/node/remote-context-files.js.map +0 -1
- package/lib/node/remote-context-files.spec.d.ts +0 -2
- package/lib/node/remote-context-files.spec.d.ts.map +0 -1
- package/lib/node/remote-context-files.spec.js +0 -37
- package/lib/node/remote-context-files.spec.js.map +0 -1
- package/lib/node/serve-state.d.ts.map +0 -1
- package/lib/node/serve-state.js.map +0 -1
- package/lib/node/serve-state.spec.d.ts +0 -2
- package/lib/node/serve-state.spec.d.ts.map +0 -1
- package/lib/node/serve-state.spec.js +0 -35
- package/lib/node/serve-state.spec.js.map +0 -1
- package/lib/node/session-lock.d.ts.map +0 -1
- package/lib/node/session-lock.js.map +0 -1
- package/lib/node/session-lock.spec.d.ts +0 -2
- package/lib/node/session-lock.spec.d.ts.map +0 -1
- package/lib/node/session-lock.spec.js +0 -53
- package/lib/node/session-lock.spec.js.map +0 -1
- package/lib/node/ta-brand.d.ts.map +0 -1
- package/lib/node/ta-brand.js.map +0 -1
- package/lib/node/ta-brand.spec.d.ts +0 -2
- package/lib/node/ta-brand.spec.d.ts.map +0 -1
- package/lib/node/ta-brand.spec.js +0 -43
- package/lib/node/ta-brand.spec.js.map +0 -1
- package/lib/node/ta-cli.d.ts.map +0 -1
- package/lib/node/ta-cli.js.map +0 -1
- package/lib/node/ta-header.d.ts.map +0 -1
- package/lib/node/ta-header.js.map +0 -1
- package/lib/node/ta-header.spec.d.ts +0 -2
- package/lib/node/ta-header.spec.d.ts.map +0 -1
- package/lib/node/ta-header.spec.js +0 -67
- package/lib/node/ta-header.spec.js.map +0 -1
- package/lib/node/ta-packages.d.ts.map +0 -1
- package/lib/node/ta-packages.js.map +0 -1
- package/lib/node/ta-packages.spec.d.ts +0 -2
- package/lib/node/ta-packages.spec.d.ts.map +0 -1
- package/lib/node/ta-packages.spec.js +0 -89
- package/lib/node/ta-packages.spec.js.map +0 -1
- package/src/node/brand-extension.spec.ts +0 -63
- package/src/node/brand-extension.ts +0 -40
- package/src/node/bug-report.spec.ts +0 -9
- package/src/node/bug-report.ts +0 -55
- package/src/node/dino-logo.ts +0 -70
- package/src/node/exec-extension.ts +0 -40
- package/src/node/exec-mcp-transport.ts +0 -89
- package/src/node/exec-operations.spec.ts +0 -84
- package/src/node/exec-operations.ts +0 -123
- package/src/node/extensions.spec.ts +0 -110
- package/src/node/extensions.ts +0 -69
- package/src/node/glob-util.spec.ts +0 -29
- package/src/node/glob-util.ts +0 -47
- package/src/node/index.ts +0 -16
- package/src/node/pi-types.ts +0 -16
- package/src/node/remote-context-files.spec.ts +0 -37
- package/src/node/remote-context-files.ts +0 -51
- package/src/node/serve-state.spec.ts +0 -36
- package/src/node/serve-state.ts +0 -51
- package/src/node/session-lock.spec.ts +0 -56
- package/src/node/session-lock.ts +0 -105
- package/src/node/ta-brand.spec.ts +0 -46
- package/src/node/ta-brand.ts +0 -51
- package/src/node/ta-cli.ts +0 -207
- package/src/node/ta-header.spec.ts +0 -74
- package/src/node/ta-header.ts +0 -192
- package/src/node/ta-packages.spec.ts +0 -95
- package/src/node/ta-packages.ts +0 -208
package/src/node/ta-cli.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { parseArgs } from 'node:util';
|
|
3
|
-
import { PiBundleUtil } from '@celljs/ai-coding-agent/lib/node/pi/pi-bundle-util';
|
|
4
|
-
import { BrandExtension } from './brand-extension';
|
|
5
|
-
import { SessionLockExtension, TaExtensionUtil } from './extensions';
|
|
6
|
-
import type { PiSdk } from './pi-types';
|
|
7
|
-
import { TaServeStateUtil } from './serve-state';
|
|
8
|
-
import { SessionLock } from './session-lock';
|
|
9
|
-
import { TaBrand } from './ta-brand';
|
|
10
|
-
import { TaPackages } from './ta-packages';
|
|
11
|
-
|
|
12
|
-
const SERVE_HELP = `Usage: ta serve [--host <host>] [--port <port>] [--web] [--exec <url>]
|
|
13
|
-
|
|
14
|
-
Serves ta sessions over WebSocket to any number of clients, and the web client. Stops on SIGINT or SIGTERM.
|
|
15
|
-
|
|
16
|
-
--host Address to listen on. Default: 127.0.0.1
|
|
17
|
-
--port Port to listen on. Default: the port of the last start if it is free, so that a web app
|
|
18
|
-
installed from it finds it again; otherwise a free port
|
|
19
|
-
--web Open the web client in the browser
|
|
20
|
-
--exec Run the sessions' commands and file operations on a ta exec-server; TA_EXEC_TOKEN is its token
|
|
21
|
-
|
|
22
|
-
The URL and the access token are written to serve.json in the agent directory. The token stays the
|
|
23
|
-
same across restarts (serve-state.json there; remove it for a new token and port).
|
|
24
|
-
Set TA_SERVE_TOKEN to choose the token.
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
const EXEC_SERVER_HELP = `Usage: ta exec-server [--host <host>] [--port <port>] [--cwd <dir>]
|
|
28
|
-
|
|
29
|
-
Runs the commands and file operations of the sessions of a ta serve on this machine, for example a
|
|
30
|
-
container or a sandbox, while the agent runs elsewhere: ta serve --exec <url>. Stops on SIGINT or SIGTERM.
|
|
31
|
-
|
|
32
|
-
--host Address to listen on. Default: 127.0.0.1
|
|
33
|
-
--port Port to listen on. Default: a free port
|
|
34
|
-
--cwd Where sessions run when the host names no directory. Default: the current directory
|
|
35
|
-
|
|
36
|
-
Set TA_EXEC_TOKEN to choose the token hosts must present; otherwise a random one is printed.
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>]
|
|
40
|
-
|
|
41
|
-
Runs a relay, through which paired devices reach a ta serve from anywhere (ta pair). It only forwards:
|
|
42
|
-
what goes through is encrypted end to end. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
|
|
43
|
-
|
|
44
|
-
--host Address to listen on. Default: 127.0.0.1
|
|
45
|
-
--port Port to listen on. Default: 8080
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
const PAIR_HELP = `Usage: ta pair [<relay url>] [--name <device>]
|
|
49
|
-
ta pair --list
|
|
50
|
-
ta pair --remove <device id>
|
|
51
|
-
|
|
52
|
-
Pairs a device, such as a phone, with the ta serve of this user: prints a link to paste in the Ta app on
|
|
53
|
-
it. The relay is https://relay.cellbang.com unless named. With a device paired, ta serve connects to the relay; what goes through it is encrypted end to end,
|
|
54
|
-
with a key only the device and ta serve have. The devices are in relay.json in the agent directory.
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
export interface TaCliOptions {
|
|
58
|
-
/** The directory with ta's package.json and pi's assets. */
|
|
59
|
-
brandDir: string;
|
|
60
|
-
/** The built server of `ta serve`. */
|
|
61
|
-
serveEntry: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export namespace TaCli {
|
|
65
|
-
/**
|
|
66
|
-
* `serve` starts the server; anything else is pi's command as `ta`, with ta's built-in extensions. Nothing
|
|
67
|
-
* here loads Cell, so that `ta` costs what `pi` costs.
|
|
68
|
-
*/
|
|
69
|
-
export async function run(argv: string[], options: TaCliOptions): Promise<void> {
|
|
70
|
-
TaBrand.activate(options.brandDir);
|
|
71
|
-
if (argv[0] === 'serve') {
|
|
72
|
-
await serve(argv.slice(1), options.serveEntry);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (argv[0] === 'relay') {
|
|
76
|
-
await relay(argv.slice(1));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (argv[0] === 'pair') {
|
|
80
|
-
await pair(argv.slice(1));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (argv[0] === 'exec-server') {
|
|
84
|
-
await execServer(argv.slice(1));
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const sdk: PiSdk = await import(/* @vite-ignore */ PiBundleUtil.specifier());
|
|
88
|
-
const builtIn = TaExtensionUtil.bundle([new SessionLockExtension(new SessionLock()), new BrandExtension(sdk)]);
|
|
89
|
-
await sdk.main(TaPackages.withExtensions(argv, TaBrand.agentDir()), { extensionFactories: [builtIn] });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function serve(argv: string[], entry: string): Promise<void> {
|
|
93
|
-
const { values } = parseArgs({
|
|
94
|
-
args: argv,
|
|
95
|
-
options: {
|
|
96
|
-
host: { type: 'string' },
|
|
97
|
-
port: { type: 'string' },
|
|
98
|
-
web: { type: 'boolean' },
|
|
99
|
-
exec: { type: 'string' },
|
|
100
|
-
help: { type: 'boolean', short: 'h' },
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
if (values.help) {
|
|
104
|
-
process.stdout.write(SERVE_HELP);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// This process is already Node.js; in the commands of the agent, an Electron app would start as Node.js too.
|
|
108
|
-
delete process.env.ELECTRON_RUN_AS_NODE;
|
|
109
|
-
// Read by the server like any other key of its configuration.
|
|
110
|
-
if (values.host) {
|
|
111
|
-
process.env.CELL_SERVER__HOST = values.host;
|
|
112
|
-
}
|
|
113
|
-
if (values.port) {
|
|
114
|
-
process.env.CELL_SERVER__PORT = values.port;
|
|
115
|
-
} else if (!process.env.CELL_SERVER__PORT) {
|
|
116
|
-
const { port } = TaServeStateUtil.read();
|
|
117
|
-
if (port && (await TaServeStateUtil.isFree(port, process.env.CELL_SERVER__HOST ?? '127.0.0.1'))) {
|
|
118
|
-
process.env.CELL_SERVER__PORT = String(port);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (values.web) {
|
|
122
|
-
process.env.TA_SERVE_OPEN_WEB = '1';
|
|
123
|
-
}
|
|
124
|
-
if (values.exec) {
|
|
125
|
-
process.env.CELL_TA__EXEC__URL = values.exec;
|
|
126
|
-
}
|
|
127
|
-
if (process.env.TA_EXEC_TOKEN) {
|
|
128
|
-
process.env.CELL_TA__EXEC__TOKEN = process.env.TA_EXEC_TOKEN;
|
|
129
|
-
}
|
|
130
|
-
await import(/* @vite-ignore */ entry);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Without Cell, as the exec server. */
|
|
134
|
-
async function relay(argv: string[]): Promise<void> {
|
|
135
|
-
const { values } = parseArgs({ args: argv, options: { host: { type: 'string' }, port: { type: 'string' }, help: { type: 'boolean', short: 'h' } } });
|
|
136
|
-
if (values.help) {
|
|
137
|
-
process.stdout.write(RELAY_HELP);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const { RelayServer } = await import('@celljs/ta-relay/lib/node/relay-server');
|
|
141
|
-
const server = new RelayServer({ host: values.host, port: values.port ? Number(values.port) : 8080 });
|
|
142
|
-
console.log(`ta relay: ${await server.listen()}`);
|
|
143
|
-
const stop = () => void server.close().then(() => process.exit(0));
|
|
144
|
-
process.once('SIGINT', stop);
|
|
145
|
-
process.once('SIGTERM', stop);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async function pair(argv: string[]): Promise<void> {
|
|
149
|
-
const { values, positionals } = parseArgs({
|
|
150
|
-
args: argv,
|
|
151
|
-
allowPositionals: true,
|
|
152
|
-
options: { name: { type: 'string' }, list: { type: 'boolean' }, remove: { type: 'string' }, help: { type: 'boolean', short: 'h' } },
|
|
153
|
-
});
|
|
154
|
-
const { RelayStore } = await import('@celljs/ta-relay/lib/node/relay-store');
|
|
155
|
-
const { RelayPairingUtil } = await import('@celljs/ta-relay/lib/common/relay-pairing');
|
|
156
|
-
const store = new RelayStore(TaBrand.agentDir());
|
|
157
|
-
if (values.list) {
|
|
158
|
-
const { url, devices } = store.read();
|
|
159
|
-
console.log(devices.length === 0 ? 'No devices are paired.' : `Relay: ${url}`);
|
|
160
|
-
for (const device of devices) {
|
|
161
|
-
console.log(`${device.id} ${device.name} ${new Date(device.createdAt).toISOString()}`);
|
|
162
|
-
}
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (values.remove) {
|
|
166
|
-
if (!store.remove(values.remove)) {
|
|
167
|
-
console.error(`ta pair: no device ${values.remove}`);
|
|
168
|
-
process.exitCode = 1;
|
|
169
|
-
}
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const { RELAY_DEFAULT_URL } = await import('@celljs/ta-relay/lib/common/relay-protocol');
|
|
173
|
-
const [relayUrl = RELAY_DEFAULT_URL] = positionals;
|
|
174
|
-
if (values.help || !/^https?:\/\//.test(relayUrl)) {
|
|
175
|
-
process.stdout.write(PAIR_HELP);
|
|
176
|
-
process.exitCode = values.help ? 0 : 1;
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const pairing = store.pair(relayUrl, values.name ?? 'device');
|
|
180
|
-
console.log('Paste this link in the Ta app on the device. Anyone with it can reach your Ta: keep it to yourself.\n');
|
|
181
|
-
console.log(RelayPairingUtil.link(pairing));
|
|
182
|
-
console.log(`\nDevice id: ${pairing.device} (ta pair --remove ${pairing.device} to unpair it)`);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/** Without Cell: the exec server is a plain HTTP server, as small as it can be. */
|
|
186
|
-
async function execServer(argv: string[]): Promise<void> {
|
|
187
|
-
const { values } = parseArgs({
|
|
188
|
-
args: argv,
|
|
189
|
-
options: { host: { type: 'string' }, port: { type: 'string' }, cwd: { type: 'string' }, help: { type: 'boolean', short: 'h' } },
|
|
190
|
-
});
|
|
191
|
-
if (values.help) {
|
|
192
|
-
process.stdout.write(EXEC_SERVER_HELP);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
const { ExecServer } = await import('@celljs/ta-exec/lib/node/exec-server');
|
|
196
|
-
const token = process.env.TA_EXEC_TOKEN || randomBytes(32).toString('base64url');
|
|
197
|
-
const server = new ExecServer({ host: values.host, port: values.port ? Number(values.port) : undefined, cwd: values.cwd, token });
|
|
198
|
-
const url = await server.listen();
|
|
199
|
-
console.log(`ta exec-server: ${url}`);
|
|
200
|
-
if (!process.env.TA_EXEC_TOKEN) {
|
|
201
|
-
console.log(`token: ${token}`);
|
|
202
|
-
}
|
|
203
|
-
const stop = () => void server.close().then(() => process.exit(0));
|
|
204
|
-
process.once('SIGINT', stop);
|
|
205
|
-
process.once('SIGTERM', stop);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import { stripVTControlCharacters } from 'node:util';
|
|
3
|
-
import { DinoLogo } from './dino-logo';
|
|
4
|
-
import { type HeaderTheme, TaHeader } from './ta-header';
|
|
5
|
-
|
|
6
|
-
const plain = stripVTControlCharacters;
|
|
7
|
-
|
|
8
|
-
const theme: HeaderTheme = {
|
|
9
|
-
fg: (_color, text) => `\x1b[2m${text}\x1b[22m`,
|
|
10
|
-
bold: text => `\x1b[1m${text}\x1b[22m`,
|
|
11
|
-
getColorMode: () => 'truecolor',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const KEYS: Record<string, string> = { 'app.interrupt': 'escape', 'app.clear': 'ctrl+c', 'app.exit': 'ctrl+d', 'app.tools.expand': 'ctrl+o' };
|
|
15
|
-
const header = (logo = true) => new TaHeader(theme, { version: '4.4.1', keyText: key => KEYS[key] ?? '', logo });
|
|
16
|
-
|
|
17
|
-
describe('TaHeader', () => {
|
|
18
|
-
it('never renders a line wider than it is given', () => {
|
|
19
|
-
for (const expanded of [false, true]) {
|
|
20
|
-
const component = header();
|
|
21
|
-
component.setExpanded(expanded);
|
|
22
|
-
for (let width = 10; width <= 160; width++) {
|
|
23
|
-
for (const line of component.render(width)) {
|
|
24
|
-
expect(plain(line).length).toBeLessThanOrEqual(width);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('draws the dinosaur beside the name, version and keys when there is room', () => {
|
|
31
|
-
const lines = header().render(100).map(plain);
|
|
32
|
-
expect(lines.length).toBe(DinoLogo.HEIGHT + 1);
|
|
33
|
-
expect(lines.some(line => line.includes('█') && line.includes('Ta v4.4.1'))).toBe(true);
|
|
34
|
-
expect(lines.join('\n')).toContain('escape interrupt · ctrl+c clear · ctrl+d exit');
|
|
35
|
-
expect(lines.join('\n')).toContain('/ commands · ! bash · ctrl+o more');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('leaves the dinosaur out where the terminal is narrow or cannot draw it', () => {
|
|
39
|
-
expect(header().render(50).map(plain).join('')).not.toContain('█');
|
|
40
|
-
expect(header(false).render(120).map(plain).join('')).not.toContain('█');
|
|
41
|
-
expect(plain(header().render(50)[0])).toBe(' Ta v4.4.1');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('lists every bound key when expanded, and skips unbound ones', () => {
|
|
45
|
-
const component = header();
|
|
46
|
-
component.setExpanded(true);
|
|
47
|
-
const text = component.render(100).map(plain).join('\n');
|
|
48
|
-
expect(text).toContain('ctrl+o');
|
|
49
|
-
expect(text).toContain('to expand tools');
|
|
50
|
-
expect(text).toContain('to run bash (no context)');
|
|
51
|
-
expect(text).not.toContain('to suspend');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('ends with an empty line, apart from what pi shows below', () => {
|
|
55
|
-
expect(header().render(100).at(-1)).toBe('');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('DinoLogo', () => {
|
|
60
|
-
it('is 16 columns by 8 lines in the brand green', () => {
|
|
61
|
-
const lines = DinoLogo.lines('truecolor');
|
|
62
|
-
expect(lines).toHaveLength(8);
|
|
63
|
-
for (const line of lines) {
|
|
64
|
-
expect(plain(line)).toHaveLength(DinoLogo.WIDTH);
|
|
65
|
-
expect(line).toStartWith('\x1b[38;2;16;185;129m');
|
|
66
|
-
}
|
|
67
|
-
expect(DinoLogo.lines('256color')[0]).toStartWith('\x1b[38;5;36m');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('is not drawn in Apple Terminal', () => {
|
|
71
|
-
expect(DinoLogo.isSupported({ TERM_PROGRAM: 'Apple_Terminal' })).toBe(false);
|
|
72
|
-
expect(DinoLogo.isSupported({ TERM_PROGRAM: 'iTerm.app' })).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
});
|
package/src/node/ta-header.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { type ColorMode, DinoLogo } from './dino-logo';
|
|
2
|
-
|
|
3
|
-
/** The part of pi's theme the header uses. */
|
|
4
|
-
export interface HeaderTheme {
|
|
5
|
-
fg(color: 'accent' | 'dim' | 'muted' | 'text', text: string): string;
|
|
6
|
-
bold(text: string): string;
|
|
7
|
-
getColorMode(): ColorMode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** A key and what it does; keys come from the user's keybindings. */
|
|
11
|
-
export interface KeyHint {
|
|
12
|
-
/** A keybinding id of pi (`app.interrupt`), or the key itself (`/`). */
|
|
13
|
-
key: string;
|
|
14
|
-
description: string;
|
|
15
|
-
/** `key` is the key itself, not a keybinding id. */
|
|
16
|
-
raw?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface TaHeaderOptions {
|
|
20
|
-
version: string;
|
|
21
|
-
/** The keys of a keybinding of pi, as text; empty when unbound. */
|
|
22
|
-
keyText(keybinding: string): string;
|
|
23
|
-
/** Draws the dinosaur. Default: where the terminal can show it. */
|
|
24
|
-
logo?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Text with its width in columns, known before it is styled. */
|
|
28
|
-
interface Span {
|
|
29
|
-
text: string;
|
|
30
|
-
width: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const INDENT = 2;
|
|
34
|
-
const GAP = 4;
|
|
35
|
-
const SEPARATOR = ' · ';
|
|
36
|
-
/** Below this width the logo leaves too little room for the text. */
|
|
37
|
-
const LOGO_MIN_WIDTH = INDENT + DinoLogo.WIDTH + GAP + 36;
|
|
38
|
-
|
|
39
|
-
/** What the header shows, a line per group where the width allows; the expanded list is pi's startup help. */
|
|
40
|
-
export const COMPACT_HINTS: KeyHint[][] = [
|
|
41
|
-
[
|
|
42
|
-
{ key: 'app.interrupt', description: 'interrupt' },
|
|
43
|
-
{ key: 'app.clear', description: 'clear' },
|
|
44
|
-
{ key: 'app.exit', description: 'exit' },
|
|
45
|
-
],
|
|
46
|
-
[
|
|
47
|
-
{ key: '/', description: 'commands', raw: true },
|
|
48
|
-
{ key: '!', description: 'bash', raw: true },
|
|
49
|
-
{ key: 'app.tools.expand', description: 'more' },
|
|
50
|
-
],
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
export const EXPANDED_HINTS: KeyHint[] = [
|
|
54
|
-
{ key: 'app.interrupt', description: 'to interrupt' },
|
|
55
|
-
{ key: 'app.clear', description: 'to clear' },
|
|
56
|
-
{ key: 'app.exit', description: 'to exit (empty)' },
|
|
57
|
-
{ key: 'app.suspend', description: 'to suspend' },
|
|
58
|
-
{ key: 'tui.editor.deleteToLineEnd', description: 'to delete to end' },
|
|
59
|
-
{ key: 'app.thinking.cycle', description: 'to cycle thinking level' },
|
|
60
|
-
{ key: 'app.model.cycleForward', description: 'to cycle models' },
|
|
61
|
-
{ key: 'app.model.select', description: 'to select model' },
|
|
62
|
-
{ key: 'app.tools.expand', description: 'to expand tools' },
|
|
63
|
-
{ key: 'app.thinking.toggle', description: 'to expand thinking' },
|
|
64
|
-
{ key: 'app.editor.external', description: 'for external editor' },
|
|
65
|
-
{ key: '/', description: 'for commands', raw: true },
|
|
66
|
-
{ key: '!', description: 'to run bash', raw: true },
|
|
67
|
-
{ key: '!!', description: 'to run bash (no context)', raw: true },
|
|
68
|
-
{ key: 'app.message.followUp', description: 'to queue follow-up' },
|
|
69
|
-
{ key: 'app.message.dequeue', description: 'to edit all queued messages' },
|
|
70
|
-
{ key: 'app.clipboard.pasteImage', description: 'to paste images or files' },
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* ta's startup header in pi's terminal UI: the dinosaur, the name and version, and the keys that
|
|
75
|
-
* matter first; all of pi's keys when expanded (the key that expands tools). Every line fits the
|
|
76
|
-
* width it is given: the terminal UI refuses wider ones.
|
|
77
|
-
*/
|
|
78
|
-
export class TaHeader {
|
|
79
|
-
protected expanded = false;
|
|
80
|
-
|
|
81
|
-
constructor(
|
|
82
|
-
protected readonly theme: HeaderTheme,
|
|
83
|
-
protected readonly options: TaHeaderOptions,
|
|
84
|
-
) {}
|
|
85
|
-
|
|
86
|
-
setExpanded(expanded: boolean): void {
|
|
87
|
-
this.expanded = expanded;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
invalidate(): void {}
|
|
91
|
-
|
|
92
|
-
render(width: number): string[] {
|
|
93
|
-
const withLogo = (this.options.logo ?? DinoLogo.isSupported()) && width >= LOGO_MIN_WIDTH;
|
|
94
|
-
const lines = withLogo ? this.besideLogo(width) : this.indented(this.intro(width - INDENT));
|
|
95
|
-
if (this.expanded) {
|
|
96
|
-
lines.push('', ...this.indented(this.keyTable(width - INDENT)));
|
|
97
|
-
}
|
|
98
|
-
// pi puts no space between a header and what follows it.
|
|
99
|
-
lines.push('');
|
|
100
|
-
return lines;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The intro, vertically centered next to the logo. */
|
|
104
|
-
protected besideLogo(width: number): string[] {
|
|
105
|
-
const logo = DinoLogo.lines(this.theme.getColorMode());
|
|
106
|
-
const intro = this.intro(width - INDENT - DinoLogo.WIDTH - GAP);
|
|
107
|
-
const top = Math.max(0, Math.floor((logo.length - intro.length) / 2));
|
|
108
|
-
const pad = ' '.repeat(INDENT);
|
|
109
|
-
const gap = ' '.repeat(GAP);
|
|
110
|
-
return Array.from({ length: Math.max(logo.length, top + intro.length) }, (_, i) => {
|
|
111
|
-
const text = intro[i - top]?.text ?? '';
|
|
112
|
-
return `${pad}${logo[i] ?? ' '.repeat(DinoLogo.WIDTH)}${text ? gap + text : ''}`;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
protected intro(width: number): Span[] {
|
|
117
|
-
const { theme } = this;
|
|
118
|
-
const title = `Ta v${this.options.version}`;
|
|
119
|
-
const green = (text: string) => DinoLogo.paint(theme.getColorMode(), text);
|
|
120
|
-
return [
|
|
121
|
-
this.span(title, width, text => (text === title ? `${theme.bold(green('Ta'))} ${theme.fg('dim', title.slice(4))}` : green(text))),
|
|
122
|
-
this.span('a coding agent on Cell and pi', width, text => theme.fg('muted', text)),
|
|
123
|
-
{ text: '', width: 0 },
|
|
124
|
-
...COMPACT_HINTS.flatMap(group => this.flow(this.hints(group), width)),
|
|
125
|
-
{ text: '', width: 0 },
|
|
126
|
-
this.span('Ask Ta how to use or extend it.', width, text => theme.fg('dim', text)),
|
|
127
|
-
];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Hints in as few lines as the width allows, a hint never split. */
|
|
131
|
-
protected flow(hints: Span[], width: number): Span[] {
|
|
132
|
-
const separator = this.theme.fg('dim', SEPARATOR);
|
|
133
|
-
const lines: Span[] = [];
|
|
134
|
-
for (const hint of hints) {
|
|
135
|
-
const last = lines[lines.length - 1];
|
|
136
|
-
if (last && last.width + SEPARATOR.length + hint.width <= width) {
|
|
137
|
-
last.text += separator + hint.text;
|
|
138
|
-
last.width += SEPARATOR.length + hint.width;
|
|
139
|
-
} else if (hint.width <= width) {
|
|
140
|
-
lines.push({ ...hint });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return lines;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** All keys, in as many aligned columns as fit. */
|
|
147
|
-
protected keyTable(width: number): Span[] {
|
|
148
|
-
const hints = this.resolve(EXPANDED_HINTS);
|
|
149
|
-
const keyWidth = Math.max(...hints.map(hint => hint.keys.length));
|
|
150
|
-
const cellWidth = keyWidth + 2 + Math.max(...hints.map(hint => hint.description.length));
|
|
151
|
-
const columnWidth = cellWidth + GAP;
|
|
152
|
-
const columns = Math.max(1, Math.floor((width + GAP) / columnWidth));
|
|
153
|
-
const rows = Math.ceil(hints.length / columns);
|
|
154
|
-
const lines: Span[] = [];
|
|
155
|
-
for (let row = 0; row < rows; row++) {
|
|
156
|
-
const cells = hints.slice(row * columns, row * columns + columns).map(hint => {
|
|
157
|
-
const description = hint.description.padEnd(cellWidth - keyWidth - 2);
|
|
158
|
-
return `${this.theme.fg('text', hint.keys.padEnd(keyWidth))} ${this.theme.fg('muted', description)}`;
|
|
159
|
-
});
|
|
160
|
-
const lineWidth = cells.length * columnWidth - GAP;
|
|
161
|
-
// One column that is still too wide: the descriptions are cut.
|
|
162
|
-
lines.push(
|
|
163
|
-
lineWidth <= width
|
|
164
|
-
? { text: cells.join(' '.repeat(GAP)), width: lineWidth }
|
|
165
|
-
: this.span(`${hints[row].keys} ${hints[row].description}`, width, text => this.theme.fg('muted', text)),
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
return lines;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
protected hints(hints: KeyHint[]): Span[] {
|
|
172
|
-
return this.resolve(hints).map(({ keys, description }) => ({
|
|
173
|
-
text: `${this.theme.fg('text', keys)} ${this.theme.fg('muted', description)}`,
|
|
174
|
-
width: keys.length + 1 + description.length,
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** The hints whose keys are bound, with their keys as text. */
|
|
179
|
-
protected resolve(hints: KeyHint[]): { keys: string; description: string }[] {
|
|
180
|
-
return hints.map(hint => ({ keys: hint.raw ? hint.key : this.options.keyText(hint.key), description: hint.description })).filter(hint => hint.keys);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Plain text, cut to the width, then styled. */
|
|
184
|
-
protected span(plain: string, width: number, style: (text: string) => string): Span {
|
|
185
|
-
const text = plain.length > width ? `${plain.slice(0, Math.max(0, width - 1))}…` : plain;
|
|
186
|
-
return { text: text ? style(text) : '', width: Math.min(plain.length, width) };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
protected indented(spans: Span[]): string[] {
|
|
190
|
-
return spans.map(span => (span.text ? ' '.repeat(INDENT) + span.text : ''));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { TaPackages } from './ta-packages';
|
|
6
|
-
|
|
7
|
-
function write(file: string, content: string) {
|
|
8
|
-
mkdirSync(join(file, '..'), { recursive: true });
|
|
9
|
-
writeFileSync(file, content);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('TaPackages', () => {
|
|
13
|
-
let home: string;
|
|
14
|
-
let packageDir: string;
|
|
15
|
-
let agentDir: string;
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
home = mkdtempSync(join(tmpdir(), 'ta-packages-'));
|
|
18
|
-
packageDir = join(home, 'pi');
|
|
19
|
-
agentDir = join(home, 'agent');
|
|
20
|
-
write(join(packageDir, 'packages/ta-channels/package.json'), JSON.stringify({ name: '@celljs/ta-channels', pi: { web: ['web/index.js'] } }));
|
|
21
|
-
write(join(packageDir, 'packages/ta-notes/package.json'), JSON.stringify({ name: '@celljs/ta-notes', pi: { extensions: ['./index.ts'] } }));
|
|
22
|
-
write(join(packageDir, 'packages/ta-skills/package.json'), JSON.stringify({ name: '@celljs/ta-skills', pi: { skills: ['./skills'] } }));
|
|
23
|
-
mkdirSync(join(packageDir, 'packages/empty'));
|
|
24
|
-
});
|
|
25
|
-
afterEach(() => rmSync(home, { recursive: true, force: true }));
|
|
26
|
-
|
|
27
|
-
it('lists the packages of the package directory, with or without what pi loads', () => {
|
|
28
|
-
expect(TaPackages.builtins(packageDir)).toEqual([
|
|
29
|
-
{ name: '@celljs/ta-channels', root: join(packageDir, 'packages/ta-channels'), resources: false },
|
|
30
|
-
{ name: '@celljs/ta-notes', root: join(packageDir, 'packages/ta-notes'), resources: true },
|
|
31
|
-
{ name: '@celljs/ta-skills', root: join(packageDir, 'packages/ta-skills'), resources: true },
|
|
32
|
-
]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('finds the workspace packages when ta is not built', () => {
|
|
36
|
-
const names = TaPackages.builtins(join(home, 'nowhere')).map(pkg => pkg.name);
|
|
37
|
-
expect(names).toContain('@celljs/ta-channels');
|
|
38
|
-
expect(names.every(name => TaPackages.BUILTIN.includes(name))).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('turns packages off and on in ta.json, keeping the other settings', () => {
|
|
42
|
-
write(join(agentDir, 'ta.json'), JSON.stringify({ other: 1 }));
|
|
43
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-notes', false);
|
|
44
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-skills', false);
|
|
45
|
-
expect(TaPackages.enabled(agentDir, packageDir).map(pkg => pkg.name)).toEqual(['@celljs/ta-channels']);
|
|
46
|
-
expect(TaPackages.extensionPaths(agentDir, packageDir)).toEqual([]);
|
|
47
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-skills', true);
|
|
48
|
-
expect(JSON.parse(readFileSync(join(agentDir, 'ta.json'), 'utf8'))).toEqual({ other: 1, disabledPackages: ['@celljs/ta-notes'] });
|
|
49
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-notes', true);
|
|
50
|
-
expect(TaPackages.extensionPaths(agentDir, packageDir)).toEqual([join(packageDir, 'packages/ta-notes'), join(packageDir, 'packages/ta-skills')]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('adds the pi extensions to the command line, except for package commands and --no-extensions', () => {
|
|
54
|
-
const root = join(packageDir, 'packages/ta-notes');
|
|
55
|
-
const skills = join(packageDir, 'packages/ta-skills');
|
|
56
|
-
expect(TaPackages.withExtensions(['-p', 'hi'], agentDir, packageDir)).toEqual(['-p', 'hi', '--extension', root, '--extension', skills]);
|
|
57
|
-
expect(TaPackages.withExtensions(['install', 'npm:x'], agentDir, packageDir)).toEqual(['install', 'npm:x']);
|
|
58
|
-
expect(TaPackages.withExtensions(['-ne'], agentDir, packageDir)).toEqual(['-ne']);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('leaves out of what pi loaded the extensions of the packages turned off, as the setting is now', () => {
|
|
62
|
-
const root = join(packageDir, 'packages/ta-notes');
|
|
63
|
-
const options = TaPackages.loaderOptions(agentDir, packageDir);
|
|
64
|
-
expect(options.additionalExtensionPaths).toEqual([root, join(packageDir, 'packages/ta-skills')]);
|
|
65
|
-
const extension = (path: string) => ({ path, resolvedPath: path }) as never;
|
|
66
|
-
const loaded = {
|
|
67
|
-
extensions: [extension(join(root, 'index.ts')), extension('/elsewhere/index.ts')],
|
|
68
|
-
errors: [{ path: join(root, 'bad.ts'), error: 'x' }],
|
|
69
|
-
} as never;
|
|
70
|
-
expect(options.extensionsOverride(loaded).extensions).toHaveLength(2);
|
|
71
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-notes', false);
|
|
72
|
-
const after = options.extensionsOverride(loaded);
|
|
73
|
-
expect(after.extensions.map(item => item.path)).toEqual(['/elsewhere/index.ts']);
|
|
74
|
-
expect(after.errors).toEqual([]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('leaves out the skills and prompts of the packages turned off', () => {
|
|
78
|
-
const root = join(packageDir, 'packages/ta-skills');
|
|
79
|
-
const options = TaPackages.loaderOptions(agentDir, packageDir);
|
|
80
|
-
const skills = {
|
|
81
|
-
skills: [{ filePath: join(root, 'skills/a/SKILL.md') }, { filePath: '/elsewhere/SKILL.md' }],
|
|
82
|
-
diagnostics: [{ path: join(root, 'skills/b') }],
|
|
83
|
-
};
|
|
84
|
-
const prompts = { prompts: [{ filePath: join(root, 'prompts/p.md') }], diagnostics: [] };
|
|
85
|
-
expect(options.skillsOverride(skills)).toEqual(skills);
|
|
86
|
-
TaPackages.setEnabled(agentDir, '@celljs/ta-skills', false);
|
|
87
|
-
expect(options.skillsOverride(skills)).toEqual({ skills: [{ filePath: '/elsewhere/SKILL.md' }], diagnostics: [] });
|
|
88
|
-
expect(options.promptsOverride(prompts).prompts).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('names the directory of a package without its scope', () => {
|
|
92
|
-
expect(TaPackages.directoryName('@celljs/ta-channels')).toBe('ta-channels');
|
|
93
|
-
expect(TaPackages.directoryName('notes')).toBe('notes');
|
|
94
|
-
});
|
|
95
|
-
});
|