@celljs/ta-workspace 4.6.1 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-cn.md +29 -0
- package/package.json +3 -3
- package/web/index.js +47 -6
- package/web-src/browser.tsx +46 -11
- package/web-src/util/workspace.spec.ts +10 -0
- package/web-src/util/workspace.ts +23 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A pi package that comes with Ta: the workspace of the conversation shown, in the
|
|
|
9
9
|
| Search | Text in the files (ripgrep, git grep or grep, whichever the machine has): match case, whole word, a regular expression (its error shown), files to include and to exclude (globs separated by commas, a folder takes all inside it); each match of a line is a result, which opens the file selected on it. Replace one, in a file or all (with `$1` for a group), the change shown on each result; dismiss results (a file or a folder); collapse and expand all; the results as a list or a tree of folders |
|
|
10
10
|
| Source control | The branch with what it is ahead and behind, a box for the commit message (Ctrl+Enter or Cmd+Enter; with nothing staged it offers to stage all), merge changes, staged changes and changes, as a list or a tree; stage, unstage and discard a file or a group (discarding asks; for an untracked file it deletes), pull, push and fetch. A change opens in Monaco's diff editor, side by side or inline, the unchanged lines folded; a change not staged can be edited there and saved |
|
|
11
11
|
| Terminal | Shells on the machine of the session, in one tab; the first opens with it; they survive a dropped connection for 30 s |
|
|
12
|
-
| Browser | A page in its tab, such as the dev server the agent started: back, forward, reload and the address in one bar, a line while the page loads; a start page with the addresses opened lately (remove one with its ×), or the ports dev servers take when there are none yet. A page of the origin of Ta itself runs without `allow-same-origin`, so it cannot reach the page or its token |
|
|
12
|
+
| Browser | A page in its tab, such as the dev server the agent started: back, forward, reload and the address in one bar, a line while the page loads; a start page with the addresses opened lately (remove one with its ×), or the ports dev servers take when there are none yet. A page of the origin of Ta itself runs without `allow-same-origin`, so it cannot reach the page or its token. In a directory of another machine (`ssh://`), a page of its `localhost` is that machine's: its port is opened on the machine of `ta serve` (`pi.remote.forwardPort`), and the bar keeps the address as typed |
|
|
13
13
|
|
|
14
14
|
Each view is a `panel` view of its web extension, opened from the `+` of the workbench or its empty state (`pi.web` of `package.json`); the work runs on the server through `pi.workspace` (`listDirectory`, `readFile`, `writeFile`, `fileUrl`, `runCommand`, …) and `pi.terminals`, in the execution environment of the directory, so a remote `ta exec-server` works the same. Search, source control and the changes to files are this package's: it runs `rg` (or `git grep`, or `grep`), `git`, `mkdir`, `mv -n` and `rm` with `runCommand` and reads their output; paths go to git as `:(literal)` pathspecs. Paths may not leave the directory. What the agent changes with its tools shows at once.
|
|
15
15
|
|
package/README.zh-cn.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @celljs/ta-workspace
|
|
2
|
+
|
|
3
|
+
Ta 自带的 pi 包:`ta serve` 的 web 客户端中会话的工作区,以 IDE 工具的形式显示在对话旁的工作台中。
|
|
4
|
+
|
|
5
|
+
| 视图 | 功能 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| 资源管理器 | 会话目录的文件,带有 VS Code 的文件图标、git 的颜色和字母(文件夹显示其内部的更改,被忽略的文件变暗)并缩进指南;它遵循显示的标签页。单击打开文件作为预览标签页(下一个预览替换它),双击保留它:Markdown、HTML、图像、视频、声音和 PDF 作为预览,其余的在 Monaco(`pi.ui.CodeEditor`)中,用 Ctrl+S 或 Cmd+S 保存。新建文件和文件夹(`a/b.ts` 创建文件夹)、就地重命名和删除,带有 VS Code 的名称检查;右键菜单有复制路径和文件夹中查找;树的按键(箭头、Home/End、F2 或 Mac 上的 Enter、Delete) |
|
|
8
|
+
| 打开的文件 | 此包打开的文件和更改的标签页,显示的被标记;关闭、关闭其他、关闭下方、在资源管理器中显示 |
|
|
9
|
+
| 搜索 | 文件中的文本(ripgrep、git grep 或 grep,机器有哪个就用哪个):匹配大小写、全词、正则表达式(其错误显示)、要包含和排除的文件(逗号分隔的 glob,一个文件夹包含其内部所有文件);一行的每个匹配都是一个结果,在它上面打开选中的文件。替换一个、在一个文件中或全部(用 `$1` 表示组),变更显示在每个结果上;关闭结果(一个文件或文件夹);全部折叠和展开;结果作为列表或文件夹树 |
|
|
10
|
+
| 源代码管理 | 分支及其领先和落后的情况,提交消息的框(Ctrl+Enter 或 Cmd+Enter;没有暂存任何东西时提供暂存全部),合并变更、暂存的变更和变更,作为列表或树;暂存、取消暂存和放弃一个文件或组(放弃询问;对于未跟踪的文件它删除)、拉取、推送和获取。不暂存的变更在 Monaco 的 diff 编辑器中打开,并排或内联,未更改的行折叠;不暂存的变更可以在那里编辑并保存 |
|
|
11
|
+
| 终端 | 会话机器上的 shell,在一个标签页中;第一个与它一起打开;它们在丢失连接后存活 30 秒 |
|
|
12
|
+
| 浏览器 | 其标签页中的页面,例如 agent 启动的开发服务器:后退、前进、重新加载和一行中的地址,页面加载时的一条线;如果还没有的话,带有最近打开的地址(用其 × 删除一个)的起始页,或开发服务器采用的端口。Ta 本身的来源的页面在没有 `allow-same-origin` 的情况下运行,因此无法到达页面或其令牌。在其他机器的目录里(`ssh://`),页面里的 `localhost` 是那台机器的:它的端口在 `ta serve` 所在的机器上打开(`pi.remote.forwardPort`),地址栏保留输入的地址 |
|
|
13
|
+
|
|
14
|
+
每个视图是其 web 扩展的 `panel` 视图,从工作台的 `+` 或其空状态打开(`pi.web` 的 `package.json`);工作通过 `pi.workspace`(`listDirectory`、`readFile`、`writeFile`、`fileUrl`、`runCommand` 等)和 `pi.terminals` 在目录的执行环境上运行,所以远程 `ta exec-server` 一样工作。搜索、源代码管理和对文件的更改是此包的:它用 `runCommand` 运行 `rg`(或 `git grep`,或 `grep`)、`git`、`mkdir`、`mv -n` 和 `rm` 并读取其输出;路径作为 `:(literal)` pathspec 传递给 git。路径不能离开目录。agent 用其工具所做的更改立即显示。
|
|
15
|
+
|
|
16
|
+
文件在 Monaco 中打开,页面带来(`pi.ui.CodeEditor`,与 Ta 打包,无网络);Markdown、HTML、SVG 首先作为预览打开,旁边有编辑。预览从 `TaWorkspaceServer.fileUrl` 加载文件:页面在其自己的原始地点沙箱化,Markdown(用 marked 呈现,打包在)不运行脚本,两个都用相对 URL 加载其旁边的文件。Diff 在 Monaco 的 diff 编辑器中打开(`pi.ui.DiffEditor`),终端由小 ANSI 屏幕绘制(颜色、光标、擦除)。文件图标是 VS Code 默认显示的 Seti 图标(字体和地图来自 microsoft/vscode 的 `extensions/theme-seti`,MIT;`bun scripts/seti.ts` 将它们再次写入 `web-src/util/seti*.ts`)。在服务器上用 `script` 时,shell 获得伪终端;没有它,它在管道上运行,服务器回显并编辑线。
|
|
17
|
+
|
|
18
|
+
回复的链接在这里打开(`pi.registerOpener`):文件作为其标签页,链接名称选中的行(`src/a.ts#L10-L20`、`src/a.ts:10:5`),甚至文件打开有更改,这保留它们;资源管理器中的目录,切换到它;浏览器中的页面。Cmd 或 Ctrl + 单击在系统的浏览器中打开页面,Ta 自己做。
|
|
19
|
+
|
|
20
|
+
在设置 → 包中关闭。
|
|
21
|
+
|
|
22
|
+
## 开发
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
bun run build # tsc -b,然后 bun build web-src/index.tsx → web/index.js(一个模块,无导入)
|
|
26
|
+
bun run test
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
web 扩展从页面获得 React(`web-src/react.ts`)和来自 `pi.ui.icons` 的图标:它在运行时不导入任何东西。要用已安装的 Ta 试用它,将包链接到 `~/.ta/agent/extensions/`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-workspace",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "A pi package for Ta: the workspace beside the conversation, with an explorer, open files, search, source control, terminals and a browser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@celljs/ta-protocol": "4.
|
|
29
|
-
"@celljs/ta-web": "4.
|
|
28
|
+
"@celljs/ta-protocol": "4.7.0",
|
|
29
|
+
"@celljs/ta-web": "4.7.0",
|
|
30
30
|
"@types/react": "^19.3.0",
|
|
31
31
|
"marked": "^14.0.0"
|
|
32
32
|
},
|
package/web/index.js
CHANGED
|
@@ -1003,6 +1003,27 @@ var WorkspaceUtil;
|
|
|
1003
1003
|
return path ? `${cwd.replace(/\/+$/, "")}/${path}` : cwd;
|
|
1004
1004
|
}
|
|
1005
1005
|
WorkspaceUtil.absolute = absolute;
|
|
1006
|
+
function localPort(url) {
|
|
1007
|
+
try {
|
|
1008
|
+
const parsed = new URL(url);
|
|
1009
|
+
if (!/^https?:$/.test(parsed.protocol) || !["localhost", "127.0.0.1", "0.0.0.0", "[::1]"].includes(parsed.hostname)) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
return Number(parsed.port || (parsed.protocol === "https:" ? 443 : 80));
|
|
1013
|
+
} catch {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
WorkspaceUtil.localPort = localPort;
|
|
1018
|
+
function withPort(url, port) {
|
|
1019
|
+
const parsed = new URL(url);
|
|
1020
|
+
if (parsed.hostname === "0.0.0.0") {
|
|
1021
|
+
parsed.hostname = "localhost";
|
|
1022
|
+
}
|
|
1023
|
+
parsed.port = String(port);
|
|
1024
|
+
return parsed.toString();
|
|
1025
|
+
}
|
|
1026
|
+
WorkspaceUtil.withPort = withPort;
|
|
1006
1027
|
function toUrl(input) {
|
|
1007
1028
|
const text = input.trim();
|
|
1008
1029
|
if (!text) {
|
|
@@ -1200,10 +1221,30 @@ function Home({ onOpen }) {
|
|
|
1200
1221
|
}, t("frameHint")));
|
|
1201
1222
|
}
|
|
1202
1223
|
var ShowPage = new Channel;
|
|
1224
|
+
function useForwarded(url, cwd) {
|
|
1225
|
+
const port = WorkspaceUtil.localPort(url);
|
|
1226
|
+
const remote = cwd.startsWith("ssh://") && port !== undefined;
|
|
1227
|
+
const [forwarded, setForwarded] = React.useState();
|
|
1228
|
+
React.useEffect(() => {
|
|
1229
|
+
if (!remote || port === undefined) {
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
let current = true;
|
|
1233
|
+
pi.remote.forwardPort(port, cwd).then(({ localPort }) => current && setForwarded({ url, to: WorkspaceUtil.withPort(url, localPort) }), (error) => current && pi.ui.notify(Host.message(error), "error"));
|
|
1234
|
+
return () => {
|
|
1235
|
+
current = false;
|
|
1236
|
+
};
|
|
1237
|
+
}, [remote, port, cwd, url]);
|
|
1238
|
+
if (!remote) {
|
|
1239
|
+
return url;
|
|
1240
|
+
}
|
|
1241
|
+
return forwarded?.url === url ? forwarded.to : undefined;
|
|
1242
|
+
}
|
|
1203
1243
|
function BrowserView() {
|
|
1204
1244
|
const [history, setHistory] = React.useState({ list: [""], index: 0, reloads: 0 });
|
|
1205
1245
|
const [loading, setLoading] = React.useState(false);
|
|
1206
1246
|
const url = history.list[history.index];
|
|
1247
|
+
const shown = useForwarded(url, pi.ui.useCwd());
|
|
1207
1248
|
const go = (next) => {
|
|
1208
1249
|
if (next) {
|
|
1209
1250
|
Recent.add(next);
|
|
@@ -1254,17 +1295,17 @@ function BrowserView() {
|
|
|
1254
1295
|
}), /* @__PURE__ */ React.createElement(Action, {
|
|
1255
1296
|
icon: "ExternalLink",
|
|
1256
1297
|
label: t("openExternal"),
|
|
1257
|
-
disabled: !
|
|
1258
|
-
onClick: () => window.open(
|
|
1298
|
+
disabled: !shown,
|
|
1299
|
+
onClick: () => shown && window.open(shown, "_blank", "noopener,noreferrer")
|
|
1259
1300
|
}), loading ? /* @__PURE__ */ React.createElement("span", {
|
|
1260
1301
|
className: "taw-browser-loading"
|
|
1261
|
-
}) : undefined), url ? /* @__PURE__ */ React.createElement("iframe", {
|
|
1302
|
+
}) : undefined), url ? shown && /* @__PURE__ */ React.createElement("iframe", {
|
|
1262
1303
|
key: `${history.index}:${history.reloads}`,
|
|
1263
1304
|
className: "taw-frame",
|
|
1264
|
-
title: url
|
|
1265
|
-
src:
|
|
1305
|
+
title: shown === url ? url : `${url} → ${shown}`,
|
|
1306
|
+
src: shown,
|
|
1266
1307
|
referrerPolicy: "no-referrer",
|
|
1267
|
-
sandbox: WorkspaceUtil.frameSandbox(
|
|
1308
|
+
sandbox: WorkspaceUtil.frameSandbox(shown, location.origin),
|
|
1268
1309
|
onLoad: () => setLoading(false)
|
|
1269
1310
|
}) : /* @__PURE__ */ React.createElement(Home, {
|
|
1270
1311
|
onOpen: go
|
package/web-src/browser.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Action, Glyph } from './common';
|
|
2
|
-
import { Channel, pi } from './host';
|
|
2
|
+
import { Channel, Host, pi } from './host';
|
|
3
3
|
import { t } from './i18n';
|
|
4
4
|
import { React } from './react';
|
|
5
5
|
import { WorkspaceUtil } from './util/workspace';
|
|
@@ -177,6 +177,33 @@ function Home({ onOpen }: { onOpen(url: string): void }) {
|
|
|
177
177
|
/** A page to show, from a link of a reply. */
|
|
178
178
|
export const ShowPage = new Channel<string>();
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* The address the frame loads for `url`: in a directory of another machine, a page of its localhost is a
|
|
182
|
+
* port of that machine, opened here (TaRemoteServer.forwardPort); `undefined` until it is.
|
|
183
|
+
*/
|
|
184
|
+
function useForwarded(url: string, cwd: string): string | undefined {
|
|
185
|
+
const port = WorkspaceUtil.localPort(url);
|
|
186
|
+
const remote = cwd.startsWith('ssh://') && port !== undefined;
|
|
187
|
+
const [forwarded, setForwarded] = React.useState<{ url: string; to: string }>();
|
|
188
|
+
React.useEffect(() => {
|
|
189
|
+
if (!remote || port === undefined) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
let current = true;
|
|
193
|
+
pi.remote.forwardPort(port, cwd).then(
|
|
194
|
+
({ localPort }) => current && setForwarded({ url, to: WorkspaceUtil.withPort(url, localPort) }),
|
|
195
|
+
error => current && pi.ui.notify(Host.message(error), 'error'),
|
|
196
|
+
);
|
|
197
|
+
return () => {
|
|
198
|
+
current = false;
|
|
199
|
+
};
|
|
200
|
+
}, [remote, port, cwd, url]);
|
|
201
|
+
if (!remote) {
|
|
202
|
+
return url;
|
|
203
|
+
}
|
|
204
|
+
return forwarded?.url === url ? forwarded.to : undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
180
207
|
interface History {
|
|
181
208
|
/** The addresses opened here, '' for the start page. */
|
|
182
209
|
list: string[];
|
|
@@ -192,6 +219,7 @@ export function BrowserView() {
|
|
|
192
219
|
const [history, setHistory] = React.useState<History>({ list: [''], index: 0, reloads: 0 });
|
|
193
220
|
const [loading, setLoading] = React.useState(false);
|
|
194
221
|
const url = history.list[history.index];
|
|
222
|
+
const shown = useForwarded(url, pi.ui.useCwd());
|
|
195
223
|
const go = (next: string) => {
|
|
196
224
|
if (next) {
|
|
197
225
|
Recent.add(next);
|
|
@@ -219,19 +247,26 @@ export function BrowserView() {
|
|
|
219
247
|
<Action icon="RefreshCw" label={t('refresh')} disabled={!url} onClick={reload} />
|
|
220
248
|
<AddressBar value={url} loading={loading} onOpen={go} />
|
|
221
249
|
<Action icon="House" label={t('home')} disabled={!url} onClick={() => go('')} />
|
|
222
|
-
<Action
|
|
250
|
+
<Action
|
|
251
|
+
icon="ExternalLink"
|
|
252
|
+
label={t('openExternal')}
|
|
253
|
+
disabled={!shown}
|
|
254
|
+
onClick={() => shown && window.open(shown, '_blank', 'noopener,noreferrer')}
|
|
255
|
+
/>
|
|
223
256
|
{loading ? <span className="taw-browser-loading" /> : undefined}
|
|
224
257
|
</header>
|
|
225
258
|
{url ? (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
259
|
+
shown && (
|
|
260
|
+
<iframe
|
|
261
|
+
key={`${history.index}:${history.reloads}`}
|
|
262
|
+
className="taw-frame"
|
|
263
|
+
title={shown === url ? url : `${url} → ${shown}`}
|
|
264
|
+
src={shown}
|
|
265
|
+
referrerPolicy="no-referrer"
|
|
266
|
+
sandbox={WorkspaceUtil.frameSandbox(shown, location.origin)}
|
|
267
|
+
onLoad={() => setLoading(false)}
|
|
268
|
+
/>
|
|
269
|
+
)
|
|
235
270
|
) : (
|
|
236
271
|
<Home onOpen={go} />
|
|
237
272
|
)}
|
|
@@ -188,4 +188,14 @@ describe('WorkspaceUtil kept state', () => {
|
|
|
188
188
|
expect(WorkspaceUtil.paths(['src', 1, 'src/a'])).toEqual(['src', 'src/a']);
|
|
189
189
|
expect(WorkspaceUtil.paths('src')).toEqual([]);
|
|
190
190
|
});
|
|
191
|
+
|
|
192
|
+
it('tells the port of a page of localhost, and moves it to another', () => {
|
|
193
|
+
expect(WorkspaceUtil.localPort('http://localhost:5173/app')).toBe(5173);
|
|
194
|
+
expect(WorkspaceUtil.localPort('http://127.0.0.1/')).toBe(80);
|
|
195
|
+
expect(WorkspaceUtil.localPort('http://[::1]:3000')).toBe(3000);
|
|
196
|
+
expect(WorkspaceUtil.localPort('https://example.com:3000')).toBeUndefined();
|
|
197
|
+
expect(WorkspaceUtil.localPort('not a url')).toBeUndefined();
|
|
198
|
+
expect(WorkspaceUtil.withPort('http://localhost:5173/app?x=1#y', 61000)).toBe('http://localhost:61000/app?x=1#y');
|
|
199
|
+
expect(WorkspaceUtil.withPort('http://0.0.0.0:8080/', 61001)).toBe('http://localhost:61001/');
|
|
200
|
+
});
|
|
191
201
|
});
|
|
@@ -296,6 +296,29 @@ export namespace WorkspaceUtil {
|
|
|
296
296
|
return path ? `${cwd.replace(/\/+$/, '')}/${path}` : cwd;
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
/** The port of a page of localhost (`localhost`, `127.0.0.1`, `0.0.0.0`, `[::1]`); undefined for others. */
|
|
300
|
+
export function localPort(url: string): number | undefined {
|
|
301
|
+
try {
|
|
302
|
+
const parsed = new URL(url);
|
|
303
|
+
if (!/^https?:$/.test(parsed.protocol) || !['localhost', '127.0.0.1', '0.0.0.0', '[::1]'].includes(parsed.hostname)) {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
return Number(parsed.port || (parsed.protocol === 'https:' ? 443 : 80));
|
|
307
|
+
} catch {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The URL on another port of localhost. */
|
|
313
|
+
export function withPort(url: string, port: number): string {
|
|
314
|
+
const parsed = new URL(url);
|
|
315
|
+
if (parsed.hostname === '0.0.0.0') {
|
|
316
|
+
parsed.hostname = 'localhost';
|
|
317
|
+
}
|
|
318
|
+
parsed.port = String(port);
|
|
319
|
+
return parsed.toString();
|
|
320
|
+
}
|
|
321
|
+
|
|
299
322
|
/** What the address bar holds, as a URL: a bare host gets http, a word becomes a search. */
|
|
300
323
|
export function toUrl(input: string): string | undefined {
|
|
301
324
|
const text = input.trim();
|