@celljs/ta-harness 0.0.0-stage → 4.5.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.
Files changed (150) hide show
  1. package/README.md +13 -2
  2. package/esm/node/brand-extension.d.ts +15 -0
  3. package/esm/node/brand-extension.js +37 -0
  4. package/esm/node/brand-extension.js.map +1 -0
  5. package/esm/node/bug-report.d.ts +19 -0
  6. package/esm/node/bug-report.js +38 -0
  7. package/esm/node/bug-report.js.map +1 -0
  8. package/esm/node/dino-logo.d.ts +18 -0
  9. package/esm/node/dino-logo.js +66 -0
  10. package/esm/node/dino-logo.js.map +1 -0
  11. package/esm/node/exec-extension.d.ts +15 -0
  12. package/esm/node/exec-extension.js +28 -0
  13. package/esm/node/exec-extension.js.map +1 -0
  14. package/esm/node/exec-mcp-transport.d.ts +27 -0
  15. package/esm/node/exec-mcp-transport.js +76 -0
  16. package/esm/node/exec-mcp-transport.js.map +1 -0
  17. package/esm/node/exec-operations.d.ts +22 -0
  18. package/esm/node/exec-operations.js +95 -0
  19. package/esm/node/exec-operations.js.map +1 -0
  20. package/esm/node/extensions.d.ts +24 -0
  21. package/esm/node/extensions.js +61 -0
  22. package/esm/node/extensions.js.map +1 -0
  23. package/esm/node/glob-util.d.ts +7 -0
  24. package/esm/node/glob-util.js +57 -0
  25. package/esm/node/glob-util.js.map +1 -0
  26. package/esm/node/index.d.ts +13 -0
  27. package/esm/node/index.js +14 -0
  28. package/esm/node/index.js.map +1 -0
  29. package/esm/node/pi-types.d.ts +13 -0
  30. package/esm/node/pi-types.js +2 -0
  31. package/esm/node/pi-types.js.map +1 -0
  32. package/esm/node/session-lock.d.ts +27 -0
  33. package/esm/node/session-lock.js +96 -0
  34. package/esm/node/session-lock.js.map +1 -0
  35. package/esm/node/ta-brand.d.ts +14 -0
  36. package/esm/node/ta-brand.js +44 -0
  37. package/esm/node/ta-brand.js.map +1 -0
  38. package/esm/node/ta-cli.d.ts +13 -0
  39. package/esm/node/ta-cli.js +50 -0
  40. package/esm/node/ta-cli.js.map +1 -0
  41. package/esm/node/ta-header.d.ts +61 -0
  42. package/esm/node/ta-header.js +149 -0
  43. package/esm/node/ta-header.js.map +1 -0
  44. package/esm/package.json +3 -0
  45. package/lib/node/brand-extension.d.ts +16 -0
  46. package/lib/node/brand-extension.d.ts.map +1 -0
  47. package/lib/node/brand-extension.js +41 -0
  48. package/lib/node/brand-extension.js.map +1 -0
  49. package/lib/node/brand-extension.spec.d.ts +2 -0
  50. package/lib/node/brand-extension.spec.d.ts.map +1 -0
  51. package/lib/node/brand-extension.spec.js +57 -0
  52. package/lib/node/brand-extension.spec.js.map +1 -0
  53. package/lib/node/bug-report.d.ts +20 -0
  54. package/lib/node/bug-report.d.ts.map +1 -0
  55. package/lib/node/bug-report.js +41 -0
  56. package/lib/node/bug-report.js.map +1 -0
  57. package/lib/node/dino-logo.d.ts +19 -0
  58. package/lib/node/dino-logo.d.ts.map +1 -0
  59. package/lib/node/dino-logo.js +69 -0
  60. package/lib/node/dino-logo.js.map +1 -0
  61. package/lib/node/exec-extension.d.ts +16 -0
  62. package/lib/node/exec-extension.d.ts.map +1 -0
  63. package/lib/node/exec-extension.js +32 -0
  64. package/lib/node/exec-extension.js.map +1 -0
  65. package/lib/node/exec-mcp-transport.d.ts +28 -0
  66. package/lib/node/exec-mcp-transport.d.ts.map +1 -0
  67. package/lib/node/exec-mcp-transport.js +80 -0
  68. package/lib/node/exec-mcp-transport.js.map +1 -0
  69. package/lib/node/exec-operations.d.ts +23 -0
  70. package/lib/node/exec-operations.d.ts.map +1 -0
  71. package/lib/node/exec-operations.js +99 -0
  72. package/lib/node/exec-operations.js.map +1 -0
  73. package/lib/node/exec-operations.spec.d.ts +2 -0
  74. package/lib/node/exec-operations.spec.d.ts.map +1 -0
  75. package/lib/node/exec-operations.spec.js +76 -0
  76. package/lib/node/exec-operations.spec.js.map +1 -0
  77. package/lib/node/extensions.d.ts +25 -0
  78. package/lib/node/extensions.d.ts.map +1 -0
  79. package/lib/node/extensions.js +65 -0
  80. package/lib/node/extensions.js.map +1 -0
  81. package/lib/node/extensions.spec.d.ts +2 -0
  82. package/lib/node/extensions.spec.d.ts.map +1 -0
  83. package/lib/node/extensions.spec.js +94 -0
  84. package/lib/node/extensions.spec.js.map +1 -0
  85. package/lib/node/glob-util.d.ts +8 -0
  86. package/lib/node/glob-util.d.ts.map +1 -0
  87. package/lib/node/glob-util.js +60 -0
  88. package/lib/node/glob-util.js.map +1 -0
  89. package/lib/node/glob-util.spec.d.ts +2 -0
  90. package/lib/node/glob-util.spec.d.ts.map +1 -0
  91. package/lib/node/glob-util.spec.js +27 -0
  92. package/lib/node/glob-util.spec.js.map +1 -0
  93. package/lib/node/index.d.ts +14 -0
  94. package/lib/node/index.d.ts.map +1 -0
  95. package/lib/node/index.js +30 -0
  96. package/lib/node/index.js.map +1 -0
  97. package/lib/node/pi-types.d.ts +14 -0
  98. package/lib/node/pi-types.d.ts.map +1 -0
  99. package/lib/node/pi-types.js +3 -0
  100. package/lib/node/pi-types.js.map +1 -0
  101. package/lib/node/session-lock.d.ts +28 -0
  102. package/lib/node/session-lock.d.ts.map +1 -0
  103. package/lib/node/session-lock.js +100 -0
  104. package/lib/node/session-lock.js.map +1 -0
  105. package/lib/node/session-lock.spec.d.ts +2 -0
  106. package/lib/node/session-lock.spec.d.ts.map +1 -0
  107. package/lib/node/session-lock.spec.js +53 -0
  108. package/lib/node/session-lock.spec.js.map +1 -0
  109. package/lib/node/ta-brand.d.ts +15 -0
  110. package/lib/node/ta-brand.d.ts.map +1 -0
  111. package/lib/node/ta-brand.js +47 -0
  112. package/lib/node/ta-brand.js.map +1 -0
  113. package/lib/node/ta-brand.spec.d.ts +2 -0
  114. package/lib/node/ta-brand.spec.d.ts.map +1 -0
  115. package/lib/node/ta-brand.spec.js +43 -0
  116. package/lib/node/ta-brand.spec.js.map +1 -0
  117. package/lib/node/ta-cli.d.ts +14 -0
  118. package/lib/node/ta-cli.d.ts.map +1 -0
  119. package/lib/node/ta-cli.js +53 -0
  120. package/lib/node/ta-cli.js.map +1 -0
  121. package/lib/node/ta-header.d.ts +62 -0
  122. package/lib/node/ta-header.d.ts.map +1 -0
  123. package/lib/node/ta-header.js +153 -0
  124. package/lib/node/ta-header.js.map +1 -0
  125. package/lib/node/ta-header.spec.d.ts +2 -0
  126. package/lib/node/ta-header.spec.d.ts.map +1 -0
  127. package/lib/node/ta-header.spec.js +67 -0
  128. package/lib/node/ta-header.spec.js.map +1 -0
  129. package/package.json +57 -4
  130. package/src/node/brand-extension.spec.ts +63 -0
  131. package/src/node/brand-extension.ts +43 -0
  132. package/src/node/bug-report.ts +48 -0
  133. package/src/node/dino-logo.ts +70 -0
  134. package/src/node/exec-extension.ts +33 -0
  135. package/src/node/exec-mcp-transport.ts +89 -0
  136. package/src/node/exec-operations.spec.ts +83 -0
  137. package/src/node/exec-operations.ts +106 -0
  138. package/src/node/extensions.spec.ts +110 -0
  139. package/src/node/extensions.ts +69 -0
  140. package/src/node/glob-util.spec.ts +29 -0
  141. package/src/node/glob-util.ts +47 -0
  142. package/src/node/index.ts +13 -0
  143. package/src/node/pi-types.ts +15 -0
  144. package/src/node/session-lock.spec.ts +56 -0
  145. package/src/node/session-lock.ts +105 -0
  146. package/src/node/ta-brand.spec.ts +46 -0
  147. package/src/node/ta-brand.ts +41 -0
  148. package/src/node/ta-cli.ts +58 -0
  149. package/src/node/ta-header.spec.ts +74 -0
  150. package/src/node/ta-header.ts +192 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bun_test_1 = require("bun:test");
4
+ const node_util_1 = require("node:util");
5
+ const dino_logo_1 = require("./dino-logo");
6
+ const ta_header_1 = require("./ta-header");
7
+ const plain = node_util_1.stripVTControlCharacters;
8
+ const theme = {
9
+ fg: (_color, text) => `\x1b[2m${text}\x1b[22m`,
10
+ bold: text => `\x1b[1m${text}\x1b[22m`,
11
+ getColorMode: () => 'truecolor',
12
+ };
13
+ const KEYS = { 'app.interrupt': 'escape', 'app.clear': 'ctrl+c', 'app.exit': 'ctrl+d', 'app.tools.expand': 'ctrl+o' };
14
+ const header = (logo = true) => new ta_header_1.TaHeader(theme, { version: '4.4.1', keyText: key => { var _a; return (_a = KEYS[key]) !== null && _a !== void 0 ? _a : ''; }, logo });
15
+ (0, bun_test_1.describe)('TaHeader', () => {
16
+ (0, bun_test_1.it)('never renders a line wider than it is given', () => {
17
+ for (const expanded of [false, true]) {
18
+ const component = header();
19
+ component.setExpanded(expanded);
20
+ for (let width = 10; width <= 160; width++) {
21
+ for (const line of component.render(width)) {
22
+ (0, bun_test_1.expect)(plain(line).length).toBeLessThanOrEqual(width);
23
+ }
24
+ }
25
+ }
26
+ });
27
+ (0, bun_test_1.it)('draws the dinosaur beside the name, version and keys when there is room', () => {
28
+ const lines = header().render(100).map(plain);
29
+ (0, bun_test_1.expect)(lines.length).toBe(dino_logo_1.DinoLogo.HEIGHT + 1);
30
+ (0, bun_test_1.expect)(lines.some(line => line.includes('█') && line.includes('ta v4.4.1'))).toBe(true);
31
+ (0, bun_test_1.expect)(lines.join('\n')).toContain('escape interrupt · ctrl+c clear · ctrl+d exit');
32
+ (0, bun_test_1.expect)(lines.join('\n')).toContain('/ commands · ! bash · ctrl+o more');
33
+ });
34
+ (0, bun_test_1.it)('leaves the dinosaur out where the terminal is narrow or cannot draw it', () => {
35
+ (0, bun_test_1.expect)(header().render(50).map(plain).join('')).not.toContain('█');
36
+ (0, bun_test_1.expect)(header(false).render(120).map(plain).join('')).not.toContain('█');
37
+ (0, bun_test_1.expect)(plain(header().render(50)[0])).toBe(' ta v4.4.1');
38
+ });
39
+ (0, bun_test_1.it)('lists every bound key when expanded, and skips unbound ones', () => {
40
+ const component = header();
41
+ component.setExpanded(true);
42
+ const text = component.render(100).map(plain).join('\n');
43
+ (0, bun_test_1.expect)(text).toContain('ctrl+o');
44
+ (0, bun_test_1.expect)(text).toContain('to expand tools');
45
+ (0, bun_test_1.expect)(text).toContain('to run bash (no context)');
46
+ (0, bun_test_1.expect)(text).not.toContain('to suspend');
47
+ });
48
+ (0, bun_test_1.it)('ends with an empty line, apart from what pi shows below', () => {
49
+ (0, bun_test_1.expect)(header().render(100).at(-1)).toBe('');
50
+ });
51
+ });
52
+ (0, bun_test_1.describe)('DinoLogo', () => {
53
+ (0, bun_test_1.it)('is 16 columns by 8 lines in the brand green', () => {
54
+ const lines = dino_logo_1.DinoLogo.lines('truecolor');
55
+ (0, bun_test_1.expect)(lines).toHaveLength(8);
56
+ for (const line of lines) {
57
+ (0, bun_test_1.expect)(plain(line)).toHaveLength(dino_logo_1.DinoLogo.WIDTH);
58
+ (0, bun_test_1.expect)(line).toStartWith('\x1b[38;2;16;185;129m');
59
+ }
60
+ (0, bun_test_1.expect)(dino_logo_1.DinoLogo.lines('256color')[0]).toStartWith('\x1b[38;5;36m');
61
+ });
62
+ (0, bun_test_1.it)('is not drawn in Apple Terminal', () => {
63
+ (0, bun_test_1.expect)(dino_logo_1.DinoLogo.isSupported({ TERM_PROGRAM: 'Apple_Terminal' })).toBe(false);
64
+ (0, bun_test_1.expect)(dino_logo_1.DinoLogo.isSupported({ TERM_PROGRAM: 'iTerm.app' })).toBe(true);
65
+ });
66
+ });
67
+ //# sourceMappingURL=ta-header.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ta-header.spec.js","sourceRoot":"","sources":["../../src/node/ta-header.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,yCAAqD;AACrD,2CAAuC;AACvC,2CAAyD;AAEzD,MAAM,KAAK,GAAG,oCAAwB,CAAC;AAEvC,MAAM,KAAK,GAAgB;IACvB,EAAE,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,IAAI,UAAU;IAC9C,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,IAAI,UAAU;IACtC,YAAY,EAAE,GAAG,EAAE,CAAC,WAAW;CAClC,CAAC;AAE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AAC,CAAC,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,IAAA,iBAAM,EAAC,oBAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7E,IAAA,iBAAM,EAAC,oBAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@celljs/ta-harness",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.5.1",
4
+ "description": "The agent runtime of ta on pi: branding, session locks and execution environment adapters",
5
+ "homepage": "https://github.com/cellbang/cell",
6
+ "bugs": {
7
+ "url": "https://github.com/cellbang/cell/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/cellbang/cell.git"
12
+ },
13
+ "license": "MIT",
14
+ "engines": {
15
+ "node": ">=22.19.0"
16
+ },
17
+ "main": "lib/node/index.js",
18
+ "typings": "lib/node/index.d.ts",
19
+ "files": [
20
+ "lib",
21
+ "esm",
22
+ "src"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsc -b && bun ../../scripts/build-esm.ts",
26
+ "clean": "rm -rf lib esm *.tsbuildinfo",
27
+ "test": "bun test ./lib",
28
+ "watch": "tsc -b -w --preserveWatchOutput"
29
+ },
30
+ "dependencies": {
31
+ "@celljs/ai-coding-agent": "4.5.1",
32
+ "@celljs/ta-exec": "4.5.1",
33
+ "@earendil-works/pi-coding-agent": "^1.5.0",
34
+ "@earendil-works/pi-mcp": "^1.5.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "exports": {
40
+ ".": {
41
+ "import": "./esm/node/index.js",
42
+ "default": "./lib/node/index.js"
43
+ },
44
+ "./package.json": "./package.json",
45
+ "./lib/node": {
46
+ "import": "./esm/node/index.js",
47
+ "default": "./lib/node/index.js"
48
+ },
49
+ "./lib/*.js": {
50
+ "import": "./esm/*.js",
51
+ "default": "./lib/*.js"
52
+ },
53
+ "./lib/*": {
54
+ "import": "./esm/*.js",
55
+ "default": "./lib/*.js"
56
+ },
57
+ "./*": "./*"
58
+ }
59
+ }
@@ -0,0 +1,63 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { mkdtempSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { PiBundleUtil } from '@celljs/ai-coding-agent/lib/node/pi/pi-bundle-util';
6
+ import { BrandExtension } from './brand-extension';
7
+ import { BugReport } from './bug-report';
8
+ import type { ExtensionAPI, PiSdk } from './pi-types';
9
+ import { TaHeader } from './ta-header';
10
+
11
+ type Handler = (event: any, ctx: any) => any;
12
+
13
+ async function setup(settings: object = {}) {
14
+ const agentDir = mkdtempSync(join(tmpdir(), 'ta-brand-'));
15
+ writeFileSync(join(agentDir, 'settings.json'), JSON.stringify(settings));
16
+ const sdk: PiSdk = await import(PiBundleUtil.specifier());
17
+ const handlers = new Map<string, Handler>();
18
+ const commands = new Map<string, { handler: Handler }>();
19
+ const pi = {
20
+ on: (name: string, handler: Handler) => handlers.set(name, handler),
21
+ registerCommand: (name: string, options: { handler: Handler }) => commands.set(name, options),
22
+ };
23
+ new BrandExtension({ ...sdk, VERSION: '9.9.9', getAgentDir: () => agentDir }).register(pi as unknown as ExtensionAPI);
24
+ const headers: unknown[] = [];
25
+ const start = (mode: string) =>
26
+ handlers.get('session_start')!({}, { mode, cwd: agentDir, ui: { setHeader: (factory: any) => headers.push(factory(undefined, {})) } });
27
+ return { commands, headers, start };
28
+ }
29
+
30
+ describe('BrandExtension', () => {
31
+ it("shows ta's header in the terminal UI only", async () => {
32
+ const { headers, start } = await setup();
33
+ start('rpc');
34
+ expect(headers).toEqual([]);
35
+ start('tui');
36
+ expect(headers[0]).toBeInstanceOf(TaHeader);
37
+ });
38
+
39
+ it('shows no header when the user asked for a quiet start', async () => {
40
+ const { headers, start } = await setup({ quietStartup: true });
41
+ start('tui');
42
+ expect(headers).toEqual([]);
43
+ });
44
+
45
+ it('answers /bug with a link to a new issue for ta', async () => {
46
+ const { commands } = await setup();
47
+ const notes: string[] = [];
48
+ await commands.get('bug')!.handler('it crashed', { model: { provider: 'fake', id: 'm1' }, ui: { notify: (text: string) => notes.push(text) } });
49
+ const url = new URL(notes[0].slice(notes[0].indexOf('https://')));
50
+ expect(url.origin + url.pathname).toBe(BugReport.ISSUES_URL);
51
+ expect(url.searchParams.get('title')).toBe('[ta] it crashed');
52
+ expect(url.searchParams.get('body')).toContain('- ta 9.9.9');
53
+ expect(url.searchParams.get('body')).toContain('- model: fake/m1');
54
+ });
55
+ });
56
+
57
+ describe('BugReport', () => {
58
+ it('leaves a placeholder when the user wrote nothing', () => {
59
+ const url = new URL(BugReport.issueUrl('', { version: '1.0.0', platform: 'linux x64', node: '24.0.0' }));
60
+ expect(url.searchParams.get('title')).toBe('[ta] Describe the bug');
61
+ expect(url.searchParams.get('body')).toContain('- model: none');
62
+ });
63
+ });
@@ -0,0 +1,43 @@
1
+ import { BugReport } from './bug-report';
2
+ import type { TaExtension } from './extensions';
3
+ import type { ExtensionAPI, PiSdk } from './pi-types';
4
+ import { TaHeader } from './ta-header';
5
+
6
+ /**
7
+ * What ta adds to its patched pi to look and act as ta: the startup header of the terminal UI, and
8
+ * `/bug`, which opens an issue for ta instead of reporting to pi's developers. The rest of what says
9
+ * ta is in the patch of pi (patches/ at the root of the repository).
10
+ */
11
+ export class BrandExtension implements TaExtension {
12
+ readonly name = 'ta:brand';
13
+
14
+ constructor(protected readonly sdk: Pick<PiSdk, 'VERSION' | 'keyText' | 'SettingsManager' | 'getAgentDir'>) {}
15
+
16
+ register(pi: ExtensionAPI): void {
17
+ pi.on('session_start', (_event, ctx) => {
18
+ if (ctx.mode === 'tui' && !this.isQuiet(ctx.cwd)) {
19
+ const keyText = this.sdk.keyText as (keybinding: string) => string;
20
+ ctx.ui.setHeader((_tui, theme) => new TaHeader(theme, { version: this.sdk.VERSION, keyText }));
21
+ }
22
+ });
23
+ pi.registerCommand('bug', {
24
+ description: 'Open an issue for ta on GitHub',
25
+ handler: async (args, ctx) => {
26
+ const url = BugReport.issueUrl(args, BugReport.currentEnvironment(this.sdk.VERSION, ctx.model));
27
+ // In the terminal UI the browser is on this machine; a client of ta serve shows the link itself.
28
+ if (ctx.mode === 'tui') {
29
+ BugReport.open(url);
30
+ }
31
+ ctx.ui.notify(
32
+ `A new issue for ta, with its version, the model and the platform and nothing else, opens in the browser. If it did not:\n${url}`,
33
+ 'info',
34
+ );
35
+ },
36
+ });
37
+ }
38
+
39
+ /** `quietStartup: true` hides pi's header; it hides this one too. */
40
+ protected isQuiet(cwd: string): boolean {
41
+ return this.sdk.SettingsManager.create(cwd, this.sdk.getAgentDir()).getQuietStartup() === true;
42
+ }
43
+ }
@@ -0,0 +1,48 @@
1
+ import { spawn } from 'node:child_process';
2
+
3
+ /** What a bug report on ta says about where it happened; no keys, paths or conversation. */
4
+ export interface BugReportEnvironment {
5
+ version: string;
6
+ /** `<provider>/<model id>`. */
7
+ model?: string;
8
+ platform: string;
9
+ node: string;
10
+ }
11
+
12
+ export namespace BugReport {
13
+ export const ISSUES_URL = 'https://github.com/cellbang/cell/issues/new';
14
+
15
+ /** A new issue on GitHub, filled in with the description and the environment. */
16
+ export function issueUrl(description: string, environment: BugReportEnvironment): string {
17
+ const url = new URL(ISSUES_URL);
18
+ url.searchParams.set('title', `[ta] ${description.trim() || 'Describe the bug'}`);
19
+ url.searchParams.set('labels', 'ta');
20
+ url.searchParams.set(
21
+ 'body',
22
+ [
23
+ '## What happened',
24
+ '',
25
+ description.trim() || '<!-- What did you do, what did you expect, what happened instead? -->',
26
+ '',
27
+ '## Environment',
28
+ '',
29
+ `- ta ${environment.version}`,
30
+ `- model: ${environment.model ?? 'none'}`,
31
+ `- ${environment.platform}, Node.js ${environment.node}`,
32
+ ].join('\n'),
33
+ );
34
+ return url.href;
35
+ }
36
+
37
+ export function currentEnvironment(version: string, model?: { provider: string; id: string }): BugReportEnvironment {
38
+ return { version, model: model && `${model.provider}/${model.id}`, platform: `${process.platform} ${process.arch}`, node: process.versions.node };
39
+ }
40
+
41
+ /** Opens the link in the browser of this machine; nothing happens where there is none. */
42
+ export function open(url: string): void {
43
+ const [command, ...args] = process.platform === 'darwin' ? ['open'] : process.platform === 'win32' ? ['cmd', '/c', 'start', '""'] : ['xdg-open'];
44
+ const child = spawn(command, [...args, url], { detached: true, stdio: 'ignore' });
45
+ child.on('error', () => undefined);
46
+ child.unref();
47
+ }
48
+ }
@@ -0,0 +1,70 @@
1
+ /** The terminal color depths pi renders for. */
2
+ export type ColorMode = '256color' | 'truecolor';
3
+
4
+ /**
5
+ * Cell's dinosaur (assets/logo.svg) as pixel art: 16 by 16 pixels, drawn with half blocks as 16
6
+ * columns and 8 lines. Its green stays the same across themes, as a brand color does.
7
+ */
8
+ export namespace DinoLogo {
9
+ const PIXELS = [
10
+ '........######..',
11
+ '.......########.',
12
+ '.......##.######',
13
+ '.......#########',
14
+ '#......#########',
15
+ '#......####.....',
16
+ '##.....#######..',
17
+ '##....#######...',
18
+ '###..########...',
19
+ '.###########.##.',
20
+ '..##########..#.',
21
+ '...########.....',
22
+ '....######......',
23
+ '....##..##......',
24
+ '....##..##......',
25
+ '...###..###.....',
26
+ ];
27
+
28
+ export const WIDTH = PIXELS[0].length;
29
+ export const HEIGHT = PIXELS.length / 2;
30
+
31
+ /** #10B981, and the nearest color of the 256-color palette. */
32
+ const GREEN: Record<ColorMode, string> = { truecolor: '\x1b[38;2;16;185;129m', '256color': '\x1b[38;5;36m' };
33
+ const RESET = '\x1b[39m';
34
+
35
+ export function lines(mode: ColorMode): string[] {
36
+ const lines: string[] = [];
37
+ for (let row = 0; row < PIXELS.length; row += 2) {
38
+ let line = '';
39
+ for (let column = 0; column < WIDTH; column++) {
40
+ line += cell(PIXELS[row][column] === '#', PIXELS[row + 1][column] === '#');
41
+ }
42
+ lines.push(paint(mode, line));
43
+ }
44
+ return lines;
45
+ }
46
+
47
+ /** Text in the green of the logo. */
48
+ export function paint(mode: ColorMode, text: string): string {
49
+ return `${GREEN[mode]}${text}${RESET}`;
50
+ }
51
+
52
+ /** Two pixels, one above the other, in one character. */
53
+ function cell(top: boolean, bottom: boolean): string {
54
+ if (top && bottom) {
55
+ return '█';
56
+ }
57
+ if (top) {
58
+ return '▀';
59
+ }
60
+ return bottom ? '▄' : ' ';
61
+ }
62
+
63
+ /**
64
+ * Apple's Terminal leaves gaps between lines and misaligns half blocks, which breaks the picture: pi
65
+ * shows a text logo there too.
66
+ */
67
+ export function isSupported(env: NodeJS.ProcessEnv = process.env): boolean {
68
+ return env.TERM_PROGRAM !== 'Apple_Terminal';
69
+ }
70
+ }
@@ -0,0 +1,33 @@
1
+ import type { ExecEnvironment } from '@celljs/ta-exec';
2
+ import { ExecOperations } from './exec-operations';
3
+ import type { TaExtension } from './extensions';
4
+ import type { ExtensionAPI, PiSdk } from './pi-types';
5
+
6
+ /**
7
+ * Sends pi's built-in tools and `!` commands to an environment that is not this machine, by registering
8
+ * tools of the same names, as pi's documentation describes. Only for those: a local environment keeps
9
+ * pi's own tools, which do the same work.
10
+ */
11
+ export class ExecExtension implements TaExtension {
12
+ readonly name = 'ta:exec';
13
+
14
+ constructor(
15
+ protected readonly environment: ExecEnvironment,
16
+ protected readonly sdk: PiSdk,
17
+ ) {}
18
+
19
+ register(pi: ExtensionAPI): void {
20
+ const { cwd } = this.environment;
21
+ const operations = new ExecOperations(this.environment);
22
+ pi.registerTool(this.sdk.createReadToolDefinition(cwd, { operations: operations.read }));
23
+ pi.registerTool(this.sdk.createBashToolDefinition(cwd, { operations: operations.bash }));
24
+ pi.registerTool(this.sdk.createEditToolDefinition(cwd, { operations: operations.edit }));
25
+ pi.registerTool(this.sdk.createWriteToolDefinition(cwd, { operations: operations.write }));
26
+ pi.registerTool(this.sdk.createLsToolDefinition(cwd, { operations: operations.ls }));
27
+ pi.registerTool(this.sdk.createFindToolDefinition(cwd, { operations: operations.find }));
28
+ pi.on('user_bash', () => ({ operations: operations.bash }));
29
+ // pi's grep always runs ripgrep on this machine, whatever its operations say: without the tool the
30
+ // model searches with rg through bash, in the environment.
31
+ pi.on('session_start', () => pi.setActiveTools(pi.getActiveTools().filter(name => name !== 'grep')));
32
+ }
33
+ }
@@ -0,0 +1,89 @@
1
+ import type { ExecEnvironment, ExecProcess } from '@celljs/ta-exec';
2
+ import type { JsonRpcMessage, McpServerEntry, McpTransport } from './pi-types';
3
+
4
+ type Listener<T extends unknown[]> = (...args: T) => void;
5
+
6
+ /** An MCP server over stdio, started in an {@link ExecEnvironment}: one JSON message per line. */
7
+ export class ExecMcpTransport implements McpTransport {
8
+ protected process?: ExecProcess;
9
+ protected buffer = '';
10
+ protected readonly decoder = new TextDecoder();
11
+ protected readonly messageListeners = new Set<Listener<[JsonRpcMessage]>>();
12
+ protected readonly errorListeners = new Set<Listener<[Error]>>();
13
+ protected readonly closeListeners = new Set<Listener<[]>>();
14
+
15
+ constructor(
16
+ protected readonly environment: ExecEnvironment,
17
+ protected readonly entry: McpServerEntry,
18
+ ) {}
19
+
20
+ async start(): Promise<void> {
21
+ const config = this.entry.config;
22
+ if ('url' in config) {
23
+ throw new Error(`The MCP server ${this.entry.name} has a URL: it needs no process in the execution environment.`);
24
+ }
25
+ const child = this.environment.spawn(config.command, config.args ?? [], { cwd: config.cwd, env: { ...process.env, ...config.env } });
26
+ child.onStdout(data => this.receive(data));
27
+ child.onExit(() => this.closed());
28
+ this.process = child;
29
+ }
30
+
31
+ async send(message: JsonRpcMessage): Promise<void> {
32
+ if (!this.process) {
33
+ throw new Error(`The MCP server ${this.entry.name} is not running.`);
34
+ }
35
+ this.process.write(`${JSON.stringify(message)}\n`);
36
+ }
37
+
38
+ async close(): Promise<void> {
39
+ this.process?.kill();
40
+ }
41
+
42
+ onMessage(listener: Listener<[JsonRpcMessage]>): () => void {
43
+ return this.listen(this.messageListeners, listener);
44
+ }
45
+
46
+ onError(listener: Listener<[Error]>): () => void {
47
+ return this.listen(this.errorListeners, listener);
48
+ }
49
+
50
+ onClose(listener: Listener<[]>): () => void {
51
+ return this.listen(this.closeListeners, listener);
52
+ }
53
+
54
+ protected listen<T extends unknown[]>(listeners: Set<Listener<T>>, listener: Listener<T>): () => void {
55
+ listeners.add(listener);
56
+ return () => listeners.delete(listener);
57
+ }
58
+
59
+ protected emit<T extends unknown[]>(listeners: Set<Listener<T>>, ...args: T): void {
60
+ for (const listener of listeners) {
61
+ listener(...args);
62
+ }
63
+ }
64
+
65
+ protected receive(data: Uint8Array): void {
66
+ const lines = (this.buffer + this.decoder.decode(data, { stream: true })).split('\n');
67
+ this.buffer = lines.pop() ?? '';
68
+ for (const line of lines) {
69
+ if (line.trim()) {
70
+ this.dispatch(line);
71
+ }
72
+ }
73
+ }
74
+
75
+ protected dispatch(line: string): void {
76
+ try {
77
+ const message = JSON.parse(line) as JsonRpcMessage;
78
+ this.emit(this.messageListeners, message);
79
+ } catch (cause) {
80
+ const error = new Error(`The MCP server ${this.entry.name} sent something that is not JSON: ${line}`, { cause });
81
+ this.emit(this.errorListeners, error);
82
+ }
83
+ }
84
+
85
+ protected closed(): void {
86
+ this.process = undefined;
87
+ this.emit(this.closeListeners);
88
+ }
89
+ }
@@ -0,0 +1,83 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { mkdtempSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { LocalExecEnvironment } from '@celljs/ta-exec';
6
+ import { ExecMcpTransport } from './exec-mcp-transport';
7
+ import { ExecOperations } from './exec-operations';
8
+ import type { JsonRpcMessage, McpServerEntry } from './pi-types';
9
+
10
+ function setup() {
11
+ const environment = new LocalExecEnvironment(mkdtempSync(join(tmpdir(), 'ta-ops-')));
12
+ return { environment, cwd: environment.cwd, operations: new ExecOperations(environment) };
13
+ }
14
+
15
+ describe('ExecOperations', () => {
16
+ it("runs bash with pi's timeout in seconds", async () => {
17
+ const { operations, cwd } = setup();
18
+ const chunks: Buffer[] = [];
19
+ const result = await operations.bash.exec('echo hi', cwd, { onData: data => chunks.push(data) });
20
+ expect(result.exitCode).toBe(0);
21
+ expect(Buffer.concat(chunks).toString()).toBe('hi\n');
22
+ const start = Date.now();
23
+ await operations.bash.exec('sleep 30', cwd, { onData: () => undefined, timeout: 0.05 });
24
+ expect(Date.now() - start).toBeLessThan(5000);
25
+ });
26
+
27
+ it('reads and writes files', async () => {
28
+ const { operations, cwd } = setup();
29
+ await operations.write.mkdir(join(cwd, 'a'));
30
+ await operations.write.writeFile(join(cwd, 'a/b.txt'), 'data');
31
+ expect((await operations.read.readFile(join(cwd, 'a/b.txt'))).toString()).toBe('data');
32
+ await operations.edit.access(join(cwd, 'a/b.txt'));
33
+ });
34
+
35
+ it("reports a missing file with ENOENT, as pi's tools expect", async () => {
36
+ const { operations, cwd } = setup();
37
+ await expect(operations.read.access(join(cwd, 'nope'))).rejects.toMatchObject({ code: 'ENOENT' });
38
+ });
39
+
40
+ it('lists directories', async () => {
41
+ const { operations, environment, cwd } = setup();
42
+ await environment.writeFile('a.txt', '');
43
+ expect(await operations.ls.readdir(cwd)).toEqual(['a.txt']);
44
+ expect((await operations.ls.stat(cwd)).isDirectory()).toBe(true);
45
+ });
46
+
47
+ it('finds files by glob, honors ignores and stops at the limit', async () => {
48
+ const { operations, environment, cwd } = setup();
49
+ await environment.mkdir('src/gen');
50
+ for (const name of ['src/a.ts', 'src/b.ts', 'src/gen/c.ts', 'src/d.js']) {
51
+ await environment.writeFile(name, '');
52
+ }
53
+ const found = await operations.find.glob('*.ts', cwd, { ignore: ['src/gen/**'], limit: 10 });
54
+ expect((found as string[]).sort()).toEqual([join(cwd, 'src/a.ts'), join(cwd, 'src/b.ts')]);
55
+ expect(await operations.find.glob('*.ts', cwd, { ignore: [], limit: 1 })).toHaveLength(1);
56
+ });
57
+ });
58
+
59
+ describe('ExecMcpTransport', () => {
60
+ const entry = (command: string, args: string[]): McpServerEntry => ({ name: 'test', source: 'test', config: { command, args } });
61
+
62
+ it('exchanges one JSON message per line with the server', async () => {
63
+ const { environment } = setup();
64
+ const transport = new ExecMcpTransport(environment, entry('cat', []));
65
+ const received = new Promise<JsonRpcMessage>(done => transport.onMessage(done));
66
+ const closed = new Promise<void>(done => transport.onClose(done));
67
+ await transport.start();
68
+ const message = { jsonrpc: '2.0', id: 1, method: 'ping' } as JsonRpcMessage;
69
+ await transport.send(message);
70
+ expect(await received).toEqual(message);
71
+ await transport.close();
72
+ await closed;
73
+ });
74
+
75
+ it('reports output that is not JSON', async () => {
76
+ const { environment } = setup();
77
+ const transport = new ExecMcpTransport(environment, entry('sh', ['-c', 'echo nonsense; sleep 5']));
78
+ const error = new Promise<Error>(done => transport.onError(done));
79
+ await transport.start();
80
+ expect((await error).message).toContain('nonsense');
81
+ await transport.close();
82
+ });
83
+ });