@celljs/ta 4.5.0 → 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 (55) hide show
  1. package/README.md +5 -3
  2. package/bin/ta.mjs +1 -1
  3. package/dist/cli.mjs +517 -0
  4. package/dist/pi/CHANGELOG.md +6 -0
  5. package/dist/pi/node_modules/@silvia-odwyer/photon-node/LICENSE.md +201 -0
  6. package/dist/pi/node_modules/@silvia-odwyer/photon-node/README.md +158 -0
  7. package/dist/pi/node_modules/@silvia-odwyer/photon-node/package.json +23 -0
  8. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs.d.ts +3226 -0
  9. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs.js +4521 -0
  10. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs_bg.js +4270 -0
  11. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm +0 -0
  12. package/dist/pi/node_modules/jiti/LICENSE +21 -0
  13. package/dist/pi/node_modules/jiti/README.md +258 -0
  14. package/dist/pi/node_modules/jiti/dist/babel.cjs +257 -0
  15. package/dist/pi/node_modules/jiti/dist/jiti.cjs +1 -0
  16. package/dist/pi/node_modules/jiti/lib/jiti-cli.mjs +34 -0
  17. package/dist/pi/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
  18. package/dist/pi/node_modules/jiti/lib/jiti-native.mjs +121 -0
  19. package/dist/pi/node_modules/jiti/lib/jiti-register.d.mts +1 -0
  20. package/dist/pi/node_modules/jiti/lib/jiti-register.mjs +4 -0
  21. package/dist/pi/node_modules/jiti/lib/jiti-static.mjs +23 -0
  22. package/dist/pi/node_modules/jiti/lib/jiti.cjs +30 -0
  23. package/dist/pi/node_modules/jiti/lib/jiti.d.cts +8 -0
  24. package/dist/pi/node_modules/jiti/lib/jiti.d.mts +8 -0
  25. package/dist/pi/node_modules/jiti/lib/jiti.mjs +29 -0
  26. package/dist/pi/node_modules/jiti/lib/types.d.ts +420 -0
  27. package/dist/pi/node_modules/jiti/package.json +146 -0
  28. package/dist/pi/node_modules/quickjs-wasi/LICENSE +21 -0
  29. package/dist/pi/node_modules/quickjs-wasi/README.md +852 -0
  30. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.d.ts +110 -0
  31. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.d.ts.map +1 -0
  32. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.js +372 -0
  33. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.js.map +1 -0
  34. package/dist/pi/node_modules/quickjs-wasi/dist/index.d.ts +1263 -0
  35. package/dist/pi/node_modules/quickjs-wasi/dist/index.d.ts.map +1 -0
  36. package/dist/pi/node_modules/quickjs-wasi/dist/index.js +2787 -0
  37. package/dist/pi/node_modules/quickjs-wasi/dist/index.js.map +1 -0
  38. package/dist/pi/node_modules/quickjs-wasi/dist/version.d.ts +2 -0
  39. package/dist/pi/node_modules/quickjs-wasi/dist/version.d.ts.map +1 -0
  40. package/dist/pi/node_modules/quickjs-wasi/dist/version.js +3 -0
  41. package/dist/pi/node_modules/quickjs-wasi/dist/version.js.map +1 -0
  42. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.d.ts +61 -0
  43. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.d.ts.map +1 -0
  44. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.js +103 -0
  45. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.js.map +1 -0
  46. package/dist/pi/node_modules/quickjs-wasi/extensions/crypto/crypto.so +0 -0
  47. package/dist/pi/node_modules/quickjs-wasi/extensions/encoding/encoding.so +0 -0
  48. package/dist/pi/node_modules/quickjs-wasi/extensions/headers/headers.so +0 -0
  49. package/dist/pi/node_modules/quickjs-wasi/extensions/structured-clone/structured-clone.so +0 -0
  50. package/dist/pi/node_modules/quickjs-wasi/extensions/url/url.so +0 -0
  51. package/dist/pi/node_modules/quickjs-wasi/package.json +69 -0
  52. package/dist/pi/node_modules/quickjs-wasi/quickjs.wasm +0 -0
  53. package/dist/pi/package.json +1 -1
  54. package/dist/serve/index.mjs +1 -1
  55. package/package.json +15 -21
package/README.md CHANGED
@@ -39,7 +39,9 @@ ta serve --host 0.0.0.0 --port 4100
39
39
 
40
40
  ## 构建
41
41
 
42
- `bun run build` 先用 `cell build` 把 ta serve 的服务端打成 `dist/serve/index.mjs`,再由 `scripts/assemble.ts` 生成 `dist/pi/`:一个把 pi 改名为 ta 的 package.json(`piConfig`),加上 pi 的主题、HTML 导出模板、docs 和 examples。`ta` 启动时让 pi 从这个目录读取品牌信息(`PI_PACKAGE_DIR`),和 pi 官方二进制的目录布局相同。
42
+ `bun run build` 先用 `cell build --root serve` 把 ta serve 的服务端打成 `dist/serve/index.mjs`,再由 `scripts/assemble.ts` 把 `ta` 命令(ta-harness 的 `TaCli`)打成 `dist/cli.mjs`,并生成 `dist/pi/`:一个把 pi 改名为 ta 的 package.json(`piConfig`),加上 pi 的主题、HTML 导出模板、docs 和 examples。`ta` 启动时让 pi 从这个目录读取品牌信息(`PI_PACKAGE_DIR`),和 pi 官方二进制的目录布局相同。
43
+
44
+ `ta` 运行时用到的都在 `dist/` 里,所以发布的包没有 `dependencies`,装 `ta` 不会再装 Cell 和 pi;构建用到的包都是 `devDependencies`。ta serve 的服务端是 `serve/` 下单独的 Cell 应用(私有,不在 workspaces 里):Cell 只从 `dependencies` 收集组件,它的 `serve/package.json` 列出这些组件,`@celljs/ta` 自己就不必有 `dependencies`。给 ta serve 加组件时,两处都要加(`serve/package.json` 的 `dependencies` 决定打包内容,`package.json` 的 `devDependencies` 决定 turbo 的构建顺序)。
43
45
 
44
46
  `ta` 命令本身不加载 Cell,启动时间和内存与 `pi` 相同;只有 `ta serve` 加载 Cell。
45
47
 
@@ -48,8 +50,8 @@ ta serve --host 0.0.0.0 --port 4100
48
50
  pi 里写死的品牌文字和 `/bug`、`/share` 两个内置命令,用补丁改:
49
51
 
50
52
  - 补丁是仓库根目录的 `patches/@earendil-works%2Fpi-coding-agent@<版本>.patch`,由 `bun patch` 生成,登记在根 `package.json` 的 `patchedDependencies`,`bun install` 时自动打上。只改 pi 的打包产物 `dist/bundle`(ta 只运行它)。
51
- - 包管理器的补丁只在本仓库生效,装 `@celljs/ta` 的用户拿到的是原版 pi。所以构建时 `scripts/assemble.ts` 把打过补丁的 `dist/bundle` 复制进 `dist/pi/dist/bundle` 随包发布(约 9 MB);`ta` 设置 `PI_PACKAGE_DIR` 指向 `dist/pi`,`PiBundleUtil` 就加载这一份。进程里只有这一份 pi,扩展通过它内置的模块表拿到同一个实例。没打补丁时构建直接失败。
52
- - 打包产物的外部依赖(`typebox`、`@silvia-odwyer/photon-node`、`quickjs-wasi`)是 `@celljs/ta` 的直接依赖,版本与 pi 相同。
53
+ - 包管理器的补丁只在本仓库生效,所以构建时 `scripts/assemble.ts` 把打过补丁的 `dist/bundle` 复制进 `dist/pi/dist/bundle` 随包发布(约 9 MB);`ta` 设置 `PI_PACKAGE_DIR` 指向 `dist/pi`,`PiBundleUtil` 就加载这一份。进程里只有这一份 pi,扩展通过它内置的模块表拿到同一个实例。没打补丁时构建直接失败。
54
+ - 打包产物运行时从 node_modules 加载的 `jiti`(加载扩展)、`@silvia-odwyer/photon-node`(图片缩放)和 `quickjs-wasi`(codemode 的 WebAssembly)也由 `scripts/assemble.ts` 从 pi 旁边复制进 `dist/pi/node_modules`,版本与 pi 相同;扩展用到的 `typebox` 和 pi 自己的包走打包产物内置的模块表。构建时会扫描打包产物里按名字加载的包,出现不在这份清单(或可选清单)里的就失败,升级 pi 时照提示补上。
53
55
 
54
56
  改了什么:
55
57
 
package/bin/ta.mjs CHANGED
@@ -6,5 +6,5 @@ import { fileURLToPath } from 'node:url';
6
6
  enableCompileCache();
7
7
 
8
8
  const dist = join(dirname(fileURLToPath(import.meta.url)), '..', 'dist');
9
- const { TaCli } = await import('@celljs/ta-harness/lib/node/ta-cli');
9
+ const { TaCli } = await import('../dist/cli.mjs');
10
10
  await TaCli.run(process.argv.slice(2), { brandDir: join(dist, 'pi'), serveEntry: join(dist, 'serve', 'index.mjs') });
package/dist/cli.mjs ADDED
@@ -0,0 +1,517 @@
1
+ // ../../ta-packages/ta-harness/esm/node/ta-cli.js
2
+ import { parseArgs } from "node:util";
3
+
4
+ // ../../ai-packages/ai-coding-agent/esm/node/pi/pi-bundle-util.js
5
+ import { fileURLToPath as __cellFileURLToPath } from "node:url";
6
+ import { dirname as __cellDirname } from "node:path";
7
+ import { existsSync } from "node:fs";
8
+ import { createRequire } from "node:module";
9
+ import { join } from "node:path";
10
+ import { pathToFileURL } from "node:url";
11
+ var __filename2 = __cellFileURLToPath(import.meta.url);
12
+ var __dirname2 = __cellDirname(__filename2);
13
+ var PiBundleUtil;
14
+ (function(PiBundleUtil2) {
15
+ const PACKAGE = "@earendil-works/pi-coding-agent";
16
+ const BUNDLE = "dist/bundle/index.js";
17
+ function specifier() {
18
+ var _a;
19
+ if (process.versions.bun) {
20
+ return PACKAGE;
21
+ }
22
+ const packageDir = process.env.PI_PACKAGE_DIR;
23
+ if (packageDir && existsSync(join(packageDir, BUNDLE))) {
24
+ return pathToFileURL(join(packageDir, BUNDLE)).href;
25
+ }
26
+ for (const nodeModules of (_a = createRequire(__filename2).resolve.paths(PACKAGE)) !== null && _a !== undefined ? _a : []) {
27
+ const bundle = join(nodeModules, PACKAGE, BUNDLE);
28
+ if (existsSync(bundle)) {
29
+ return pathToFileURL(bundle).href;
30
+ }
31
+ }
32
+ return PACKAGE;
33
+ }
34
+ PiBundleUtil2.specifier = specifier;
35
+ })(PiBundleUtil || (PiBundleUtil = {}));
36
+
37
+ // ../../ta-packages/ta-harness/esm/node/bug-report.js
38
+ import { spawn } from "node:child_process";
39
+ var BugReport;
40
+ (function(BugReport2) {
41
+ BugReport2.ISSUES_URL = "https://github.com/cellbang/cell/issues/new";
42
+ function issueUrl(description, environment) {
43
+ var _a;
44
+ const url = new URL(BugReport2.ISSUES_URL);
45
+ url.searchParams.set("title", `[ta] ${description.trim() || "Describe the bug"}`);
46
+ url.searchParams.set("labels", "ta");
47
+ url.searchParams.set("body", [
48
+ "## What happened",
49
+ "",
50
+ description.trim() || "<!-- What did you do, what did you expect, what happened instead? -->",
51
+ "",
52
+ "## Environment",
53
+ "",
54
+ `- ta ${environment.version}`,
55
+ `- model: ${(_a = environment.model) !== null && _a !== undefined ? _a : "none"}`,
56
+ `- ${environment.platform}, Node.js ${environment.node}`
57
+ ].join(`
58
+ `));
59
+ return url.href;
60
+ }
61
+ BugReport2.issueUrl = issueUrl;
62
+ function currentEnvironment(version, model) {
63
+ return { version, model: model && `${model.provider}/${model.id}`, platform: `${process.platform} ${process.arch}`, node: process.versions.node };
64
+ }
65
+ BugReport2.currentEnvironment = currentEnvironment;
66
+ function open(url) {
67
+ const [command, ...args] = process.platform === "darwin" ? ["open"] : process.platform === "win32" ? ["cmd", "/c", "start", '""'] : ["xdg-open"];
68
+ const child = spawn(command, [...args, url], { detached: true, stdio: "ignore" });
69
+ child.on("error", () => {
70
+ return;
71
+ });
72
+ child.unref();
73
+ }
74
+ BugReport2.open = open;
75
+ })(BugReport || (BugReport = {}));
76
+
77
+ // ../../ta-packages/ta-harness/esm/node/dino-logo.js
78
+ var DinoLogo;
79
+ (function(DinoLogo2) {
80
+ const PIXELS = [
81
+ "........######..",
82
+ ".......########.",
83
+ ".......##.######",
84
+ ".......#########",
85
+ "#......#########",
86
+ "#......####.....",
87
+ "##.....#######..",
88
+ "##....#######...",
89
+ "###..########...",
90
+ ".###########.##.",
91
+ "..##########..#.",
92
+ "...########.....",
93
+ "....######......",
94
+ "....##..##......",
95
+ "....##..##......",
96
+ "...###..###....."
97
+ ];
98
+ DinoLogo2.WIDTH = PIXELS[0].length;
99
+ DinoLogo2.HEIGHT = PIXELS.length / 2;
100
+ const GREEN = { truecolor: "\x1B[38;2;16;185;129m", "256color": "\x1B[38;5;36m" };
101
+ const RESET = "\x1B[39m";
102
+ function lines(mode) {
103
+ const lines2 = [];
104
+ for (let row = 0;row < PIXELS.length; row += 2) {
105
+ let line = "";
106
+ for (let column = 0;column < DinoLogo2.WIDTH; column++) {
107
+ line += cell(PIXELS[row][column] === "#", PIXELS[row + 1][column] === "#");
108
+ }
109
+ lines2.push(paint(mode, line));
110
+ }
111
+ return lines2;
112
+ }
113
+ DinoLogo2.lines = lines;
114
+ function paint(mode, text) {
115
+ return `${GREEN[mode]}${text}${RESET}`;
116
+ }
117
+ DinoLogo2.paint = paint;
118
+ function cell(top, bottom) {
119
+ if (top && bottom) {
120
+ return "█";
121
+ }
122
+ if (top) {
123
+ return "▀";
124
+ }
125
+ return bottom ? "▄" : " ";
126
+ }
127
+ function isSupported(env = process.env) {
128
+ return env.TERM_PROGRAM !== "Apple_Terminal";
129
+ }
130
+ DinoLogo2.isSupported = isSupported;
131
+ })(DinoLogo || (DinoLogo = {}));
132
+
133
+ // ../../ta-packages/ta-harness/esm/node/ta-header.js
134
+ var INDENT = 2;
135
+ var GAP = 4;
136
+ var SEPARATOR = " · ";
137
+ var LOGO_MIN_WIDTH = INDENT + DinoLogo.WIDTH + GAP + 36;
138
+ var COMPACT_HINTS = [
139
+ [
140
+ { key: "app.interrupt", description: "interrupt" },
141
+ { key: "app.clear", description: "clear" },
142
+ { key: "app.exit", description: "exit" }
143
+ ],
144
+ [
145
+ { key: "/", description: "commands", raw: true },
146
+ { key: "!", description: "bash", raw: true },
147
+ { key: "app.tools.expand", description: "more" }
148
+ ]
149
+ ];
150
+ var EXPANDED_HINTS = [
151
+ { key: "app.interrupt", description: "to interrupt" },
152
+ { key: "app.clear", description: "to clear" },
153
+ { key: "app.exit", description: "to exit (empty)" },
154
+ { key: "app.suspend", description: "to suspend" },
155
+ { key: "tui.editor.deleteToLineEnd", description: "to delete to end" },
156
+ { key: "app.thinking.cycle", description: "to cycle thinking level" },
157
+ { key: "app.model.cycleForward", description: "to cycle models" },
158
+ { key: "app.model.select", description: "to select model" },
159
+ { key: "app.tools.expand", description: "to expand tools" },
160
+ { key: "app.thinking.toggle", description: "to expand thinking" },
161
+ { key: "app.editor.external", description: "for external editor" },
162
+ { key: "/", description: "for commands", raw: true },
163
+ { key: "!", description: "to run bash", raw: true },
164
+ { key: "!!", description: "to run bash (no context)", raw: true },
165
+ { key: "app.message.followUp", description: "to queue follow-up" },
166
+ { key: "app.message.dequeue", description: "to edit all queued messages" },
167
+ { key: "app.clipboard.pasteImage", description: "to paste images or files" }
168
+ ];
169
+
170
+ class TaHeader {
171
+ constructor(theme, options) {
172
+ this.theme = theme;
173
+ this.options = options;
174
+ this.expanded = false;
175
+ }
176
+ setExpanded(expanded) {
177
+ this.expanded = expanded;
178
+ }
179
+ invalidate() {}
180
+ render(width) {
181
+ var _a;
182
+ const withLogo = ((_a = this.options.logo) !== null && _a !== undefined ? _a : DinoLogo.isSupported()) && width >= LOGO_MIN_WIDTH;
183
+ const lines = withLogo ? this.besideLogo(width) : this.indented(this.intro(width - INDENT));
184
+ if (this.expanded) {
185
+ lines.push("", ...this.indented(this.keyTable(width - INDENT)));
186
+ }
187
+ lines.push("");
188
+ return lines;
189
+ }
190
+ besideLogo(width) {
191
+ const logo = DinoLogo.lines(this.theme.getColorMode());
192
+ const intro = this.intro(width - INDENT - DinoLogo.WIDTH - GAP);
193
+ const top = Math.max(0, Math.floor((logo.length - intro.length) / 2));
194
+ const pad = " ".repeat(INDENT);
195
+ const gap = " ".repeat(GAP);
196
+ return Array.from({ length: Math.max(logo.length, top + intro.length) }, (_, i) => {
197
+ var _a;
198
+ var _b, _c;
199
+ const text = (_b = (_a = intro[i - top]) === null || _a === undefined ? undefined : _a.text) !== null && _b !== undefined ? _b : "";
200
+ return `${pad}${(_c = logo[i]) !== null && _c !== undefined ? _c : " ".repeat(DinoLogo.WIDTH)}${text ? gap + text : ""}`;
201
+ });
202
+ }
203
+ intro(width) {
204
+ const { theme } = this;
205
+ const title = `ta v${this.options.version}`;
206
+ const green = (text) => DinoLogo.paint(theme.getColorMode(), text);
207
+ return [
208
+ this.span(title, width, (text) => text === title ? `${theme.bold(green("ta"))} ${theme.fg("dim", title.slice(4))}` : green(text)),
209
+ this.span("a coding agent on Cell and pi", width, (text) => theme.fg("muted", text)),
210
+ { text: "", width: 0 },
211
+ ...COMPACT_HINTS.flatMap((group) => this.flow(this.hints(group), width)),
212
+ { text: "", width: 0 },
213
+ this.span("Ask ta how to use or extend it.", width, (text) => theme.fg("dim", text))
214
+ ];
215
+ }
216
+ flow(hints, width) {
217
+ const separator = this.theme.fg("dim", SEPARATOR);
218
+ const lines = [];
219
+ for (const hint of hints) {
220
+ const last = lines[lines.length - 1];
221
+ if (last && last.width + SEPARATOR.length + hint.width <= width) {
222
+ last.text += separator + hint.text;
223
+ last.width += SEPARATOR.length + hint.width;
224
+ } else if (hint.width <= width) {
225
+ lines.push({ ...hint });
226
+ }
227
+ }
228
+ return lines;
229
+ }
230
+ keyTable(width) {
231
+ const hints = this.resolve(EXPANDED_HINTS);
232
+ const keyWidth = Math.max(...hints.map((hint) => hint.keys.length));
233
+ const cellWidth = keyWidth + 2 + Math.max(...hints.map((hint) => hint.description.length));
234
+ const columnWidth = cellWidth + GAP;
235
+ const columns = Math.max(1, Math.floor((width + GAP) / columnWidth));
236
+ const rows = Math.ceil(hints.length / columns);
237
+ const lines = [];
238
+ for (let row = 0;row < rows; row++) {
239
+ const cells = hints.slice(row * columns, row * columns + columns).map((hint) => {
240
+ const description = hint.description.padEnd(cellWidth - keyWidth - 2);
241
+ return `${this.theme.fg("text", hint.keys.padEnd(keyWidth))} ${this.theme.fg("muted", description)}`;
242
+ });
243
+ const lineWidth = cells.length * columnWidth - GAP;
244
+ lines.push(lineWidth <= width ? { text: cells.join(" ".repeat(GAP)), width: lineWidth } : this.span(`${hints[row].keys} ${hints[row].description}`, width, (text) => this.theme.fg("muted", text)));
245
+ }
246
+ return lines;
247
+ }
248
+ hints(hints) {
249
+ return this.resolve(hints).map(({ keys, description }) => ({
250
+ text: `${this.theme.fg("text", keys)} ${this.theme.fg("muted", description)}`,
251
+ width: keys.length + 1 + description.length
252
+ }));
253
+ }
254
+ resolve(hints) {
255
+ return hints.map((hint) => ({ keys: hint.raw ? hint.key : this.options.keyText(hint.key), description: hint.description })).filter((hint) => hint.keys);
256
+ }
257
+ span(plain, width, style) {
258
+ const text = plain.length > width ? `${plain.slice(0, Math.max(0, width - 1))}…` : plain;
259
+ return { text: text ? style(text) : "", width: Math.min(plain.length, width) };
260
+ }
261
+ indented(spans) {
262
+ return spans.map((span) => span.text ? " ".repeat(INDENT) + span.text : "");
263
+ }
264
+ }
265
+
266
+ // ../../ta-packages/ta-harness/esm/node/brand-extension.js
267
+ class BrandExtension {
268
+ constructor(sdk) {
269
+ this.sdk = sdk;
270
+ this.name = "ta:brand";
271
+ }
272
+ register(pi) {
273
+ pi.on("session_start", (_event, ctx) => {
274
+ if (ctx.mode === "tui" && !this.isQuiet(ctx.cwd)) {
275
+ const keyText = this.sdk.keyText;
276
+ ctx.ui.setHeader((_tui, theme) => new TaHeader(theme, { version: this.sdk.VERSION, keyText }));
277
+ }
278
+ });
279
+ pi.registerCommand("bug", {
280
+ description: "Open an issue for ta on GitHub",
281
+ handler: async (args, ctx) => {
282
+ const url = BugReport.issueUrl(args, BugReport.currentEnvironment(this.sdk.VERSION, ctx.model));
283
+ if (ctx.mode === "tui") {
284
+ BugReport.open(url);
285
+ }
286
+ ctx.ui.notify(`A new issue for ta, with its version, the model and the platform and nothing else, opens in the browser. If it did not:
287
+ ${url}`, "info");
288
+ }
289
+ });
290
+ }
291
+ isQuiet(cwd) {
292
+ return this.sdk.SettingsManager.create(cwd, this.sdk.getAgentDir()).getQuietStartup() === true;
293
+ }
294
+ }
295
+
296
+ // ../../ta-packages/ta-harness/esm/node/extensions.js
297
+ var TaExtensionUtil;
298
+ (function(TaExtensionUtil2) {
299
+ function toInline(extension) {
300
+ return { name: extension.name, factory: (pi) => extension.register(pi) };
301
+ }
302
+ TaExtensionUtil2.toInline = toInline;
303
+ function bundle(extensions) {
304
+ return {
305
+ name: "ta",
306
+ factory: (pi) => {
307
+ for (const extension of extensions) {
308
+ extension.register(pi);
309
+ }
310
+ }
311
+ };
312
+ }
313
+ TaExtensionUtil2.bundle = bundle;
314
+ })(TaExtensionUtil || (TaExtensionUtil = {}));
315
+
316
+ class SessionLockExtension {
317
+ constructor(lock) {
318
+ this.lock = lock;
319
+ this.name = "ta:session-lock";
320
+ }
321
+ register(pi) {
322
+ pi.on("session_before_switch", (event) => {
323
+ if (event.targetSessionFile && this.lock.isHeldByOther(event.targetSessionFile)) {
324
+ return { cancel: true };
325
+ }
326
+ return;
327
+ });
328
+ pi.on("session_start", (_event, ctx) => {
329
+ const file = ctx.sessionManager.getSessionFile();
330
+ if (file && !this.lock.acquire(file)) {
331
+ this.refuse(file, ctx);
332
+ }
333
+ });
334
+ pi.on("session_shutdown", (_event, ctx) => {
335
+ const file = ctx.sessionManager.getSessionFile();
336
+ if (file) {
337
+ this.lock.release(file);
338
+ }
339
+ });
340
+ }
341
+ refuse(file, ctx) {
342
+ const message = `This session is open in another ta process. If that process is gone, delete ${this.lock.path(file)}.`;
343
+ if (ctx.mode === "tui") {
344
+ ctx.ui.notify(message, "error");
345
+ ctx.shutdown();
346
+ return;
347
+ }
348
+ process.stderr.write(`${message}
349
+ `);
350
+ process.exit(1);
351
+ }
352
+ }
353
+
354
+ // ../../ta-packages/ta-harness/esm/node/session-lock.js
355
+ import { randomUUID } from "node:crypto";
356
+ import { linkSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
357
+ import { hostname } from "node:os";
358
+ import { dirname } from "node:path";
359
+
360
+ class SessionLock {
361
+ constructor() {
362
+ this.owner = randomUUID();
363
+ this.held = new Set;
364
+ }
365
+ acquire(sessionFile) {
366
+ if (this.held.has(sessionFile)) {
367
+ return true;
368
+ }
369
+ mkdirSync(dirname(sessionFile), { recursive: true });
370
+ for (let attempt = 0;attempt < 2; attempt++) {
371
+ if (this.create(sessionFile)) {
372
+ this.held.add(sessionFile);
373
+ return true;
374
+ }
375
+ if (this.isHeldByOther(sessionFile)) {
376
+ return false;
377
+ }
378
+ rmSync(this.path(sessionFile), { force: true });
379
+ }
380
+ return false;
381
+ }
382
+ isHeldByOther(sessionFile) {
383
+ const lock = this.read(sessionFile);
384
+ return lock !== undefined && lock.owner !== this.owner && this.isAlive(lock);
385
+ }
386
+ release(sessionFile) {
387
+ if (this.held.delete(sessionFile)) {
388
+ rmSync(this.path(sessionFile), { force: true });
389
+ }
390
+ }
391
+ releaseAll() {
392
+ for (const sessionFile of [...this.held]) {
393
+ this.release(sessionFile);
394
+ }
395
+ }
396
+ path(sessionFile) {
397
+ return `${sessionFile}.lock`;
398
+ }
399
+ create(sessionFile) {
400
+ const lock = { owner: this.owner, pid: process.pid, host: hostname(), createdAt: Date.now() };
401
+ const draft = `${this.path(sessionFile)}.${this.owner}`;
402
+ writeFileSync(draft, JSON.stringify(lock));
403
+ try {
404
+ linkSync(draft, this.path(sessionFile));
405
+ return true;
406
+ } catch (error) {
407
+ if (error.code === "EEXIST") {
408
+ return false;
409
+ }
410
+ throw error;
411
+ } finally {
412
+ rmSync(draft, { force: true });
413
+ }
414
+ }
415
+ read(sessionFile) {
416
+ try {
417
+ return JSON.parse(readFileSync(this.path(sessionFile), "utf8"));
418
+ } catch (error) {
419
+ if (error.code === "ENOENT") {
420
+ return;
421
+ }
422
+ throw error;
423
+ }
424
+ }
425
+ isAlive(lock) {
426
+ if (lock.host !== hostname()) {
427
+ return true;
428
+ }
429
+ try {
430
+ process.kill(lock.pid, 0);
431
+ return true;
432
+ } catch (error) {
433
+ return error.code === "EPERM";
434
+ }
435
+ }
436
+ }
437
+
438
+ // ../../ta-packages/ta-harness/esm/node/ta-brand.js
439
+ import { homedir } from "node:os";
440
+ import { join as join2 } from "node:path";
441
+ var TaBrand;
442
+ (function(TaBrand2) {
443
+ TaBrand2.NAME = "ta";
444
+ TaBrand2.ENV_ALIASES = {
445
+ TA_OFFLINE: "PI_OFFLINE",
446
+ TA_SELF_UPDATE_COMMAND: "PI_SELF_UPDATE_COMMAND",
447
+ TA_TELEMETRY: "PI_TELEMETRY",
448
+ TA_SKIP_VERSION_CHECK: "PI_SKIP_VERSION_CHECK"
449
+ };
450
+ function agentDir() {
451
+ var _a;
452
+ return (_a = process.env.TA_CODING_AGENT_DIR) !== null && _a !== undefined ? _a : join2(homedir(), ".ta", "agent");
453
+ }
454
+ TaBrand2.agentDir = agentDir;
455
+ function activate(brandDir) {
456
+ var _a, _b;
457
+ var _c, _d;
458
+ process.env.PI_PACKAGE_DIR = brandDir;
459
+ for (const [ta, pi] of Object.entries(TaBrand2.ENV_ALIASES)) {
460
+ if (process.env[ta] !== undefined) {
461
+ process.env[pi] = process.env[ta];
462
+ }
463
+ }
464
+ (_a = (_c = process.env).PI_SKIP_VERSION_CHECK) !== null && _a !== undefined || (_c.PI_SKIP_VERSION_CHECK = "1");
465
+ (_b = (_d = process.env).PI_TELEMETRY) !== null && _b !== undefined || (_d.PI_TELEMETRY = "0");
466
+ process.env.PI_CODING_AGENT = "true";
467
+ process.env.AI_AGENT = TaBrand2.NAME;
468
+ process.title = TaBrand2.NAME;
469
+ process.emitWarning = () => {
470
+ return;
471
+ };
472
+ }
473
+ TaBrand2.activate = activate;
474
+ })(TaBrand || (TaBrand = {}));
475
+
476
+ // ../../ta-packages/ta-harness/esm/node/ta-cli.js
477
+ var SERVE_HELP = `Usage: ta serve [--host <host>] [--port <port>]
478
+
479
+ Serves pi sessions over WebSocket to any number of clients. Stops on SIGINT or SIGTERM.
480
+
481
+ --host Address to listen on. Default: 127.0.0.1
482
+ --port Port to listen on. Default: a free port
483
+
484
+ The URL and the access token are written to serve.json in the agent directory.
485
+ Set TA_SERVE_TOKEN to choose the token.
486
+ `;
487
+ var TaCli;
488
+ (function(TaCli2) {
489
+ async function run(argv, options) {
490
+ TaBrand.activate(options.brandDir);
491
+ if (argv[0] === "serve") {
492
+ await serve(argv.slice(1), options.serveEntry);
493
+ return;
494
+ }
495
+ const sdk = await import(PiBundleUtil.specifier());
496
+ const builtIn = TaExtensionUtil.bundle([new SessionLockExtension(new SessionLock), new BrandExtension(sdk)]);
497
+ await sdk.main(argv, { extensionFactories: [builtIn] });
498
+ }
499
+ TaCli2.run = run;
500
+ async function serve(argv, entry) {
501
+ const { values } = parseArgs({ args: argv, options: { host: { type: "string" }, port: { type: "string" }, help: { type: "boolean", short: "h" } } });
502
+ if (values.help) {
503
+ process.stdout.write(SERVE_HELP);
504
+ return;
505
+ }
506
+ if (values.host) {
507
+ process.env.CELL_SERVER__HOST = values.host;
508
+ }
509
+ if (values.port) {
510
+ process.env.CELL_SERVER__PORT = values.port;
511
+ }
512
+ await import(entry);
513
+ }
514
+ })(TaCli || (TaCli = {}));
515
+ export {
516
+ TaCli
517
+ };
@@ -1,5 +1,11 @@
1
1
  # @celljs/ta
2
2
 
3
+ ## 4.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f4bcde1: ta 不再有 dependencies:`ta` 命令打包为 `dist/cli.mjs`,pi 打包产物运行时需要的 jiti、photon-node、quickjs-wasi 随包放在 `dist/pi/node_modules`,安装 ta 不再连带安装 Cell 和 pi
8
+
3
9
  ## 4.5.0
4
10
 
5
11
  ### Minor Changes