@celljs/ta-host 4.6.0 → 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.
Files changed (154) hide show
  1. package/README.en.md +68 -0
  2. package/README.md +13 -2
  3. package/cell.schema.json +21 -0
  4. package/cell.yml +7 -0
  5. package/esm/node/exec-environment-factory.d.ts +8 -4
  6. package/esm/node/exec-environment-factory.js +28 -6
  7. package/esm/node/exec-environment-factory.js.map +1 -1
  8. package/esm/node/index.d.ts +1 -0
  9. package/esm/node/index.js +1 -0
  10. package/esm/node/index.js.map +1 -1
  11. package/esm/node/package-hosts.d.ts +4 -0
  12. package/esm/node/package-hosts.js +30 -0
  13. package/esm/node/package-hosts.js.map +1 -1
  14. package/esm/node/remote/index.d.ts +5 -0
  15. package/esm/node/remote/index.js +6 -0
  16. package/esm/node/remote/index.js.map +1 -0
  17. package/esm/node/remote/pi-directories.d.ts +14 -0
  18. package/esm/node/remote/pi-directories.js +64 -0
  19. package/esm/node/remote/pi-directories.js.map +1 -0
  20. package/esm/node/remote/port-forwards.d.ts +35 -0
  21. package/esm/node/remote/port-forwards.js +150 -0
  22. package/esm/node/remote/port-forwards.js.map +1 -0
  23. package/esm/node/remote/remote-hosts.d.ts +40 -0
  24. package/esm/node/remote/remote-hosts.js +170 -0
  25. package/esm/node/remote/remote-hosts.js.map +1 -0
  26. package/esm/node/remote/remote-protocol.d.ts +51 -0
  27. package/esm/node/remote/remote-protocol.js +5 -0
  28. package/esm/node/remote/remote-protocol.js.map +1 -0
  29. package/esm/node/remote/remote-server-impl.d.ts +19 -0
  30. package/esm/node/remote/remote-server-impl.js +66 -0
  31. package/esm/node/remote/remote-server-impl.js.map +1 -0
  32. package/esm/node/settings-store.d.ts +3 -1
  33. package/esm/node/settings-store.js +9 -2
  34. package/esm/node/settings-store.js.map +1 -1
  35. package/esm/node/ta-server-impl.d.ts +2 -0
  36. package/esm/node/ta-server-impl.js +16 -4
  37. package/esm/node/ta-server-impl.js.map +1 -1
  38. package/esm/node/ta-session-factory.d.ts +16 -2
  39. package/esm/node/ta-session-factory.js +38 -8
  40. package/esm/node/ta-session-factory.js.map +1 -1
  41. package/esm/node/ta-session.d.ts +4 -0
  42. package/esm/node/ta-session.js +5 -1
  43. package/esm/node/ta-session.js.map +1 -1
  44. package/esm/node/terminal-service.js +1 -1
  45. package/esm/node/terminal-service.js.map +1 -1
  46. package/esm/node/web-extension-catalog.d.ts +3 -1
  47. package/esm/node/web-extension-catalog.js +8 -2
  48. package/esm/node/web-extension-catalog.js.map +1 -1
  49. package/esm/node/working-directory.d.ts +12 -1
  50. package/esm/node/working-directory.js +22 -1
  51. package/esm/node/working-directory.js.map +1 -1
  52. package/esm/node/workspace-files.d.ts +1 -1
  53. package/esm/node/workspace-files.js +3 -3
  54. package/esm/node/workspace-files.js.map +1 -1
  55. package/esm/node/workspace-service.js +3 -3
  56. package/esm/node/workspace-service.js.map +1 -1
  57. package/lib/node/exec-environment-factory.d.ts +8 -4
  58. package/lib/node/exec-environment-factory.d.ts.map +1 -1
  59. package/lib/node/exec-environment-factory.js +28 -6
  60. package/lib/node/exec-environment-factory.js.map +1 -1
  61. package/lib/node/index.d.ts +1 -0
  62. package/lib/node/index.d.ts.map +1 -1
  63. package/lib/node/index.js +1 -0
  64. package/lib/node/index.js.map +1 -1
  65. package/lib/node/package-hosts.d.ts +4 -0
  66. package/lib/node/package-hosts.d.ts.map +1 -1
  67. package/lib/node/package-hosts.js +30 -0
  68. package/lib/node/package-hosts.js.map +1 -1
  69. package/lib/node/remote/index.d.ts +6 -0
  70. package/lib/node/remote/index.d.ts.map +1 -0
  71. package/lib/node/remote/index.js +22 -0
  72. package/lib/node/remote/index.js.map +1 -0
  73. package/lib/node/remote/pi-directories.d.ts +15 -0
  74. package/lib/node/remote/pi-directories.d.ts.map +1 -0
  75. package/lib/node/remote/pi-directories.js +67 -0
  76. package/lib/node/remote/pi-directories.js.map +1 -0
  77. package/lib/node/remote/port-forwards.d.ts +36 -0
  78. package/lib/node/remote/port-forwards.d.ts.map +1 -0
  79. package/lib/node/remote/port-forwards.js +153 -0
  80. package/lib/node/remote/port-forwards.js.map +1 -0
  81. package/lib/node/remote/remote-hosts.d.ts +41 -0
  82. package/lib/node/remote/remote-hosts.d.ts.map +1 -0
  83. package/lib/node/remote/remote-hosts.js +173 -0
  84. package/lib/node/remote/remote-hosts.js.map +1 -0
  85. package/lib/node/remote/remote-protocol.d.ts +52 -0
  86. package/lib/node/remote/remote-protocol.d.ts.map +1 -0
  87. package/lib/node/remote/remote-protocol.js +8 -0
  88. package/lib/node/remote/remote-protocol.js.map +1 -0
  89. package/lib/node/remote/remote-server-impl.d.ts +20 -0
  90. package/lib/node/remote/remote-server-impl.d.ts.map +1 -0
  91. package/lib/node/remote/remote-server-impl.js +69 -0
  92. package/lib/node/remote/remote-server-impl.js.map +1 -0
  93. package/lib/node/remote/remote.spec.d.ts +2 -0
  94. package/lib/node/remote/remote.spec.d.ts.map +1 -0
  95. package/lib/node/remote/remote.spec.js +130 -0
  96. package/lib/node/remote/remote.spec.js.map +1 -0
  97. package/lib/node/settings-store.d.ts +3 -1
  98. package/lib/node/settings-store.d.ts.map +1 -1
  99. package/lib/node/settings-store.js +9 -2
  100. package/lib/node/settings-store.js.map +1 -1
  101. package/lib/node/settings-store.spec.js +2 -1
  102. package/lib/node/settings-store.spec.js.map +1 -1
  103. package/lib/node/ta-server-impl.d.ts +2 -0
  104. package/lib/node/ta-server-impl.d.ts.map +1 -1
  105. package/lib/node/ta-server-impl.js +16 -4
  106. package/lib/node/ta-server-impl.js.map +1 -1
  107. package/lib/node/ta-session-factory.d.ts +16 -2
  108. package/lib/node/ta-session-factory.d.ts.map +1 -1
  109. package/lib/node/ta-session-factory.js +37 -7
  110. package/lib/node/ta-session-factory.js.map +1 -1
  111. package/lib/node/ta-session.d.ts +4 -0
  112. package/lib/node/ta-session.d.ts.map +1 -1
  113. package/lib/node/ta-session.js +5 -1
  114. package/lib/node/ta-session.js.map +1 -1
  115. package/lib/node/terminal-service.js +1 -1
  116. package/lib/node/terminal-service.js.map +1 -1
  117. package/lib/node/web-extension-catalog.d.ts +3 -1
  118. package/lib/node/web-extension-catalog.d.ts.map +1 -1
  119. package/lib/node/web-extension-catalog.js +7 -1
  120. package/lib/node/web-extension-catalog.js.map +1 -1
  121. package/lib/node/web-extension-catalog.spec.js +1 -1
  122. package/lib/node/web-extension-catalog.spec.js.map +1 -1
  123. package/lib/node/working-directory.d.ts +12 -1
  124. package/lib/node/working-directory.d.ts.map +1 -1
  125. package/lib/node/working-directory.js +22 -1
  126. package/lib/node/working-directory.js.map +1 -1
  127. package/lib/node/workspace-files.d.ts +1 -1
  128. package/lib/node/workspace-files.d.ts.map +1 -1
  129. package/lib/node/workspace-files.js +3 -3
  130. package/lib/node/workspace-files.js.map +1 -1
  131. package/lib/node/workspace-service.js +3 -3
  132. package/lib/node/workspace-service.js.map +1 -1
  133. package/package.json +14 -10
  134. package/src/node/exec-environment-factory.ts +26 -6
  135. package/src/node/index.ts +1 -0
  136. package/src/node/package-hosts.ts +28 -0
  137. package/src/node/remote/index.ts +5 -0
  138. package/src/node/remote/pi-directories.ts +49 -0
  139. package/src/node/remote/port-forwards.ts +148 -0
  140. package/src/node/remote/remote-hosts.ts +170 -0
  141. package/src/node/remote/remote-protocol.ts +57 -0
  142. package/src/node/remote/remote-server-impl.ts +60 -0
  143. package/src/node/remote/remote.spec.ts +142 -0
  144. package/src/node/settings-store.spec.ts +2 -1
  145. package/src/node/settings-store.ts +8 -2
  146. package/src/node/ta-server-impl.ts +18 -4
  147. package/src/node/ta-session-factory.ts +40 -7
  148. package/src/node/ta-session.ts +8 -1
  149. package/src/node/terminal-service.ts +1 -1
  150. package/src/node/web-extension-catalog.spec.ts +1 -1
  151. package/src/node/web-extension-catalog.ts +7 -2
  152. package/src/node/working-directory.ts +35 -2
  153. package/src/node/workspace-files.ts +3 -3
  154. package/src/node/workspace-service.ts +3 -3
package/README.en.md ADDED
@@ -0,0 +1,68 @@
1
+ # Cell - Ta Host
2
+
3
+ The server-side component of `ta serve`. It is functionally equivalent to Codex's app-server: pi only supports RPC mode over stdio (one process per session, one controller), and this component adds multi-session, multi-client, disconnect recovery, remote authorization, idempotent acknowledgments, and session locking. Command and event semantics are consistent with pi's RPC mode.
4
+
5
+ ## Components
6
+
7
+ | Component | Purpose |
8
+ | --- | --- |
9
+ | `TaServerImpl` | `@Rpc(TaServer)`, handles sessions and pi RPC commands. Each command is forwarded to `AgentSession` / `AgentSessionRuntime` following pi's `rpc-mode` approach (pi only exports `runRpcMode` bound to stdio, so each command is mapped here; verify against pi's `rpc-mode` when upgrading pi). |
10
+ | `TaWorkspaceServerImpl` / `TaTerminalServerImpl` / `TaSettingsServerImpl` / `TaPackageServerImpl` / `TaAuthServerImpl` / `RelayBridge` | Other services on the same WebSocket; each forwards to the component below. `TaAccess` rejects HTTP-style calls (`POST /api/<service>` returns 404). |
11
+ | `TaAuthServerImpl` | `@Rpc(TaAuthServer)`: runs pi's `/login` flow on the server (OAuth login page, device code, or API key). It sends only the page to open and fields for the user to fill to the initiating connection (`TaClient.onAuthEvent`); the user's answer is sent back via `answer`. The `logout` method deletes stored credentials. Credentials are written to the server-side pi's `auth.json` and shared across all sessions; they are never sent back to the client. |
12
+ | `RelayBridge` | `@Rpc(TaRelayServer)`: reads `relay.json` from the agent directory. When paired devices exist, it connects to Relay and opens a connection to `/api/ws` on this machine for each device (see [@celljs/ta-relay](../ta-relay/README.md)). The `pair` and `unpair` commands work the same as `ta pair`. If no Relay is provided, it uses `https://relay.cellbang.com`. |
13
+ | `TaWorkingDirectory` | The working directory set by `setWorkingDirectory`, recorded in `ta.json` in the agent directory (`workingDirectory`), persists across restarts. Open sessions are unaffected. |
14
+ | `TaSessionRegistry` | Manages open sessions. Rejects requests when exceeding `maxSessions`, closes sessions that are idle (no clients, not running, no pending dialogs) for longer than `idleTimeoutMs`. Session files are retained. |
15
+ | `TaSessionFactory` | Assembles sessions the same way the pi command does: project trust, settings, extensions, themes. All sessions share one model runtime. Can be replaced by `rebind`. |
16
+ | `TaSession` | One open session: event log, acknowledgments, connected clients. After `newSession`/`fork`/`switchSession` the id remains unchanged and broadcasts `session_replaced`. The `navigateTree` command (pi's `/tree`) also broadcasts when switching branches within the same session. |
17
+ | `RemoteUiContext` | The pi extension's `ctx.ui`: dialogs are broadcast to all clients. The first response takes effect; if timed out, the default value from the extension is used. |
18
+ | `EventLog` / `ClientChannel` | Each session retains recent events in bytes for reconnection recovery. Each client merges into a frame every 30ms and sends the next frame after the client acknowledges. Clients that fall too far behind are disconnected to force reconnection. |
19
+ | `TaAccess` | Validates tokens (WebSocket handshake and HTTP), listens on localhost and validates the `Host` header to prevent DNS rebinding, writes `serve.json`. The token and port are saved to `serve-state.json` and reused on the next startup. |
20
+ | `WebExtensionCatalog`(`WebExtensionCatalogImpl`) | `listWebExtensions` / `readWebExtension` / `removeWebExtension`: finds web extensions in packages using pi's package loading method (`packages` setting and `extensions/` directory, project packages only when trusted). Reads only declared, in-package files that are under 2 MB. |
21
+ | Packages (`listPackages` / `installPackage` / `removePackage`) | Lists all packages loaded by pi (with or without web extensions) and includes `resources` (`extensions`, `web`, `skills`, `prompts`, `themes`). The `installPackage` command works the same as `ta install` (`project` is `-l`, only for trusted projects). The `removePackage` command works the same as `removeWebExtension` and removes by package id. |
22
+ | Package host service (`callPackageHost`) | Calls methods on objects returned by the built-in package `pi.host` (arguments and return values are JSON), for use by its web extensions. Methods that cannot be called are `dispose`, `constructor`, methods starting with `_`, or methods built into objects. |
23
+ | Toggles (`setPackageEnabled`) | Ta's built-in pi packages ([`TaPackages`](../ta-harness/README.md)) are toggled by name and listed with `origin: 'builtin'`. They can only be toggled, not removed. The toggle state is saved to `ta.json` in the agent directory (`disabledPackages`). Other packages are toggled by the id from `listPackages` and work the same as `ta config`, writing each resource individually to pi's settings (`PackageSwitch`: paths in `extensions/` are written as `+path` / `-path` to the `extensions` list, items in `packages` are written to that item's filter). The terminal `ta` recognizes this as well. Packages with no pi loading and only web extensions are recorded in `ta.json`'s `disabledWeb`. `enabled`: set to true when pi loads any resource from it (for web-only packages check `disabledWeb`). Disabled packages' web extensions are not loaded. Takes effect after session `reload`. |
24
+ | `TaSettingsStore`(`TaSettingsStoreImpl`) | `getSettings` / `updateSettings`: ta's settings (keys listed in `TA_SETTINGS`) are pi's `settings.json`, user-level in the agent directory, project-level in `<cwd>/.ta/`. Changes only the provided keys (set to `null` to delete; an empty object deletes the file thereafter). Preserves other content and uses atomic writes via temporary file. Only one write happens at a time. During writes, it acquires the same file lock as pi (`<file>.lock` directory, considered stale after 10 seconds), so the terminal `ta` changing settings simultaneously does not overwrite (pi rereads within the lock and only writes back the keys it changed). Does not overwrite unreadable files. At project level, pi requests trust for projects that have not been trusted (with extensions, skills, etc.). Writing without requiring trust is treated as trusting (otherwise pi will not read). After writing, it notifies related sessions' `SettingsManager` to reload (model and reasoning level take effect for new sessions). |
25
+ | `ExtensionDataStore`(`ExtensionDataStoreImpl`) | `getExtensionData` / `setExtensionData`: data stored on the server for packages (web extensions' `pi.storage`). One file per package at `<agentDir>/extension-data/<package name>.json` (mode 0600), with serial writes to the same file. Set values to `null` to delete keys. 4 MB limit per package. When `cwd` is provided, it is data for that directory at `extension-data/directories/<dir name>-<hash>/<package name>.json`. The hash includes the execution environment, so same-name directories do not interfere when running remotely. Notifications include `cwd`. |
26
+ | `ClientToolBroker` | Client tools (`clientTools`): each is a pi tool that broadcasts `client_tool_request` on call and waits for the first client to respond via `respondClientTool`. Ends with failure if the run is aborted or the session closes. |
27
+ | `DefaultExecEnvironmentFactory` | Tools execute based on directory: `ssh://<host>/<path>` runs on that host (`RemoteHosts`); local paths run locally; when `ta.exec.url` is configured, tools run on `ta exec-server` (see @celljs/ta-exec). The environment's `cwd` is the path in that environment; all paths resolve by it. A custom `ExecEnvironmentFactory` can also be used via `rebind`. |
28
+ | `RemoteHosts` / `TaRemoteServerImpl` | `@Rpc(TaRemoteServer)`: hosts for `ssh://` directories, each with an `SshHost` (uses system `ssh` and its config; auto-installs Node.js and the server on first use), connects on first call and reconnects after disconnection. Provides `listHosts` (Hosts from `~/.ssh/config` without wildcards and known to ssh, plus from `ta.json`'s `remoteHosts`), `addHost` / `removeHost` (remember or forget a host), `resolveLocation` (expand location without path to home directory), `watch` / `answer` (when ssh needs password, confirmation, or new host, asks all pages; first response wins), `disconnect`. Pushes connection steps and changes to `TaClient.onRemoteEvent`. |
29
+ | `PortForwards` | `forwardPort`: opens ports from the host of a remote directory on localhost's `127.0.0.1` (trying to reuse the same port number), with each connection forwarded through the execution environment's `connect`. Local directories are returned as-is. |
30
+ | `PiDirectories` | Remote directories (and all directories when `ta.exec.url` is set) use shadow directories on localhost: `<agent directory>/remote/ssh/<host>/<path>`. Pi names session files by them and writes project settings there; session info then switches back to the location. Files like AGENTS.md from remote projects are read by `RemoteContextFiles` and provided to pi (see [ta-remote-ssh.md](../../docs/design/ta-remote-ssh.md)). |
31
+
32
+ Each session loads extensions the same way as the `ta` command: pi's built-in codemode, tool search, and MCP (pi's SDK does not auto-load them; when the execution environment is not local, stdio MCP services start in the execution environment). Ta's built-in extensions, enabled built-in packages' pi extensions, and `AgentExtension` and `AgentTool` components (@celljs/ai-coding-agent).
33
+
34
+ ## Configuration
35
+
36
+ ```yaml
37
+ ta:
38
+ host:
39
+ maxSessions: 32
40
+ idleTimeoutMs: 600000
41
+ eventBufferBytes: 524288 # per-session event amount for recovery
42
+ clientBacklogBytes: 8388608 # per-client backlog allowed
43
+ exec:
44
+ url: '' # address of ta exec-server (ta serve --exec); empty: local
45
+ token: '' # ta serve will fill TA_EXEC_TOKEN here
46
+ remote:
47
+ ssh: ssh # ssh command for ssh:// directories; ~/.ssh/config applies normally
48
+ sshArgs: [] # prepended to each host, e.g. ["-F", "/path/config"]
49
+ nodeMirror: '' # where to download Node.js if the host lacks 18+; empty: https://nodejs.org/dist
50
+ ```
51
+
52
+ When [@celljs/ta-web](../ta-web/README.md) is installed, the `/` path on the same port serves the Web client: GET requests for page files do not require a token (they contain no data), and all calls under `/api` require a token. When listening on localhost, both validate the `Host` header.
53
+
54
+ ## Session Storage (Cloud)
55
+
56
+ `ta serve` locally uses pi's session files, relying on session locks to ensure only one process writes at a time. In the cloud there may be multiple `ta serve` replicas, any of which may take over a session. In this case, the session is stored in `TaSessionStorage`:
57
+
58
+ - **Lease + epoch**: `acquire` increments the epoch when obtaining a session. Each `write` includes the lease, and requests are rejected if the epoch is not current (`StaleLeaseError`), so nothing is written. The old holder, even if not yet aware of being taken over by another replica (`takeOver` or after lease expiration), cannot write. The expiration time only determines when others can take it without going through takeover.
59
+ - **`FileSessionStorage`**: `<id>.jsonl` (pi's format) and `<id>.lease.json` in a directory, using lock directories for atomicity. Can be used locally or on a shared filesystem, and also serves as a reference for cloud implementations (conditional database updates, compare-and-swap in KV stores) to follow.
60
+ - **`StoredSession`**: pi's `SessionManager` (in-memory mode) plus write-through to storage. Each time pi adds a record, it is written out in order, the same as pi writing to a file. Nothing is written until the first user or model message. The lease is renewed at one-third intervals. After the lease is lost, pi adding records fails (like file write failure), and `onLost` notifies the host to stop the session.
61
+
62
+ Which cloud storage to use has not yet been decided, so `TaSessionFactory` has not integrated it yet. Pi's `AgentSessionRuntime` still creates `SessionManager` by file when creating new conversations, forking, or switching sessions. When integration happens, these places will switch to `StoredSession`.
63
+
64
+ ## Known Limitations
65
+
66
+ - When there are no available models (model service not signed in, no model selected), pi's error will mention the `/login` command and its documentation path in the terminal. This is changed here to `CELL_TA_NOT_SIGNED_IN` with a prompt to sign in first using `TaAuthServer`.
67
+ - The deduplication table, event log, and pending dialogs are all in memory. After service restart, dialogs become invalid (extensions receive the default value), and clients should call `getMessages` first to verify before deciding to resend.
68
+ - When executing remotely, pi's resources (`AGENTS.md`, project `.ta/` settings and skills) still read from the same paths on the host machine. Project resources on the execution machine rely on a custom ResourceLoader (not yet implemented).
package/README.md CHANGED
@@ -7,7 +7,10 @@
7
7
  | 组件 | 作用 |
8
8
  | --- | --- |
9
9
  | `TaServerImpl` | `@Rpc(TaServer)`,会话与 pi 的 RPC 命令,各命令照 pi `rpc-mode` 的做法转给 `AgentSession` / `AgentSessionRuntime`(pi 只导出绑在 stdio 上的 `runRpcMode`,所以这里逐条对应;升级 pi 时对照它的 `rpc-mode` 检查) |
10
- | `TaWorkspaceServerImpl` / `TaTerminalServerImpl` / `TaSettingsServerImpl` / `TaPackageServerImpl` | 同一条 WebSocket 上的其他服务,各自转给下面的组件;`TaAccess` 拒绝 HTTP 形式的调用(`POST /api/<服务>` 返回 404) |
10
+ | `TaWorkspaceServerImpl` / `TaTerminalServerImpl` / `TaSettingsServerImpl` / `TaPackageServerImpl` / `TaAuthServerImpl` / `RelayBridge` | 同一条 WebSocket 上的其他服务,各自转给下面的组件;`TaAccess` 拒绝 HTTP 形式的调用(`POST /api/<服务>` 返回 404) |
11
+ | `TaAuthServerImpl` | `@Rpc(TaAuthServer)`:在服务端跑 pi 的 `/login` 流程(OAuth 的登录页或设备码,或 API Key),把要打开的页面、要用户填的内容只发给发起登录的连接(`TaClient.onAuthEvent`),用户的回答用 `answer` 送回;`logout` 删掉存下的凭据。凭据写进服务端 pi 的 `auth.json`,所有会话共用,不会发回客户端 |
12
+ | `RelayBridge` | `@Rpc(TaRelayServer)`:读 agent 目录的 `relay.json`,有配对的设备时连上 Relay,并替每台设备开一条到本机 `/api/ws` 的连接(见 [@celljs/ta-relay](../ta-relay/README.md));`pair` / `unpair` 与 `ta pair` 相同,没给 Relay 时用 `https://relay.cellbang.com` |
13
+ | `TaWorkingDirectory` | `setWorkingDirectory` 设的工作目录,记在 agent 目录的 `ta.json`(`workingDirectory`),跨重启保留;已经打开的会话不受影响 |
11
14
  | `TaSessionRegistry` | 打开的会话;超过 `maxSessions` 拒绝,空闲(无客户端、无运行、无待答对话框)超过 `idleTimeoutMs` 关闭,会话文件保留 |
12
15
  | `TaSessionFactory` | 像 pi 命令那样装配会话:项目信任、设置、扩展、主题;所有会话共用一个模型运行时。可 `rebind` 替换 |
13
16
  | `TaSession` | 一个打开的会话:事件日志、回执、已连接的客户端;`newSession`/`fork`/`switchSession` 后 id 不变,并发 `session_replaced`;`navigateTree`(pi 的 `/tree`)在同一会话里换分支后也发 |
@@ -21,7 +24,10 @@
21
24
  | `TaSettingsStore`(`TaSettingsStoreImpl`) | `getSettings` / `updateSettings`:ta 的设置(`TA_SETTINGS` 列出的键)就是 pi 的 `settings.json`,用户层在 agent 目录、项目层在 `<cwd>/.ta/`;只改给出的键(`null` 删除,空对象随之删掉),其余内容原样保留,整文件经临时文件写入、同一时间只写一次,写时持有与 pi 相同的文件锁(`<文件>.lock` 目录,超过 10 秒视为失效),所以终端里的 `ta` 同时改设置不会互相覆盖(pi 在锁内重读文件、只写回它改过的键);读不了的文件不覆盖。项目层:pi 会询问信任的项目(有扩展、技能等)未被信任时拒绝写入,没有需要询问的内容时写入即记为信任(否则 pi 不读)。写入后让相关会话的 `SettingsManager` 重新加载(模型与思考强度对新会话生效) |
22
25
  | `ExtensionDataStore`(`ExtensionDataStoreImpl`) | `getExtensionData` / `setExtensionData`:包存在服务器上的小数据(Web 扩展的 `pi.storage`),每个包一个 `<agentDir>/extension-data/<包名>.json`(权限 0600),同一文件串行写入;值为 `null` 删除该键;每个包上限 4 MB。带 `cwd` 时是该目录的数据(`pi.storage.directory(cwd)`),存在 `extension-data/directories/<目录名>-<哈希>/<包名>.json`,哈希含执行环境,远程执行时同名目录互不影响;变更通知带上 `cwd` |
23
26
  | `ClientToolBroker` | 客户端工具(`clientTools`):每个是 pi 的一个工具,调用时广播 `client_tool_request`,等第一个客户端用 `respondClientTool` 回答;run 中止或会话关闭时以失败结束 |
24
- | `DefaultExecEnvironmentFactory` | 工具在本机执行;配了 `ta.exec.url` 时在 `ta exec-server` 上执行(见 @celljs/ta-exec)。也可 `rebind` 自己的 `ExecEnvironmentFactory` |
27
+ | `DefaultExecEnvironmentFactory` | 按目录给执行环境:`ssh://<host>/<path>` 在那台主机上(`RemoteHosts`),本机路径在本机,配了 `ta.exec.url` 时在 `ta exec-server` 上(见 @celljs/ta-exec)。返回的环境的 `cwd` 是环境里的路径,路径都按它解析。也可 `rebind` 自己的 `ExecEnvironmentFactory` |
28
+ | `RemoteHosts` / `TaRemoteServerImpl` | `@Rpc(TaRemoteServer)`:`ssh://` 目录的主机,每台一个 `SshHost`(用系统 `ssh` 和它的配置,首次自动装 Node.js 和服务器),第一次调用时连接、断线后下次调用重连。`listHosts`(`~/.ssh/config` 里没有通配符、ssh 能用的 Host,和 `ta.json` 的 `remoteHosts`)、`addHost` / `removeHost`(记下或忘掉一台主机)、`resolveLocation`(不带路径的位置换成家目录)、`watch` / `answer`(ssh 要密码、口令、确认新主机时问所有页面,第一个回答生效)、`disconnect`;连接步骤和连上断开都推给 `TaClient.onRemoteEvent` |
29
+ | `PortForwards` | `forwardPort`:远端目录所在主机的端口在本机 `127.0.0.1` 上打开(尽量同一个端口号),每个连接经执行环境的 `connect` 转发;本机目录原样返回 |
30
+ | `PiDirectories` | 远端目录(以及 `ta.exec.url` 时的所有目录)交给 pi 的本机影子目录 `<agent 目录>/remote/ssh/<host>/<path>`:pi 的会话文件按它命名,项目设置写在它下面;会话信息里再换回位置。远端项目的 AGENTS.md 等由 `RemoteContextFiles` 读来交给 pi(见 [ta-remote-ssh.md](../../docs/design/ta-remote-ssh.md)) |
25
31
 
26
32
  每个会话加载的扩展与 `ta` 命令相同:pi 命令自带的 codemode、tool search、MCP(pi 的 SDK 不自动加载它们;执行环境不在本机时 stdio MCP 服务在执行环境里启动),Ta 的内置扩展,开启着的内置包的 pi 扩展,以及 `AgentExtension`、`AgentTool` 组件(@celljs/ai-coding-agent)。
27
33
 
@@ -37,6 +43,10 @@ ta:
37
43
  exec:
38
44
  url: '' # ta exec-server 的地址(ta serve --exec);空:本机
39
45
  token: '' # ta serve 会把 TA_EXEC_TOKEN 填到这里
46
+ remote:
47
+ ssh: ssh # ssh:// 目录用的 ssh 命令,~/.ssh/config 照常生效
48
+ sshArgs: [] # 加在每个主机前,如 ["-F", "/path/config"]
49
+ nodeMirror: '' # 主机没有 Node.js 18+ 时从哪下载;空:https://nodejs.org/dist
40
50
  ```
41
51
 
42
52
  装了 [@celljs/ta-web](../ta-web/README.md) 时同一端口的 `/` 是 Web 客户端:GET 页面文件不需要 token(不含数据),`/api` 下的调用都要 token,监听本机时两者都校验 `Host`。
@@ -53,5 +63,6 @@ ta:
53
63
 
54
64
  ## 已知限制
55
65
 
66
+ - 没有可用的模型(模型服务没登录、没选模型)时,pi 的报错会提到终端里的 `/login` 和它的文档路径;这里改成 `CELL_TA_NOT_SIGNED_IN`,提示先用 `TaAuthServer` 登录。
56
67
  - 去重表、事件日志和待答对话框都在内存里:服务重启后对话框作废(扩展拿到默认值),客户端应先 `getMessages` 核对再决定是否重发。
57
68
  - 远程执行时,pi 的资源(`AGENTS.md`、项目 `.ta/` 设置与 Skills)仍从宿主上同名路径读取;执行机上的项目资源要靠自定义 ResourceLoader(尚未实现)。
package/cell.schema.json CHANGED
@@ -44,6 +44,27 @@
44
44
  "description": "Fences older hosts on the exec server; default: the time this host started."
45
45
  }
46
46
  }
47
+ },
48
+ "remote": {
49
+ "type": "object",
50
+ "description": "How ta serve reaches the hosts of ssh:// locations.",
51
+ "properties": {
52
+ "ssh": {
53
+ "type": "string",
54
+ "description": "The ssh command; its configuration (~/.ssh/config) applies."
55
+ },
56
+ "sshArgs": {
57
+ "type": "array",
58
+ "items": {
59
+ "type": "string"
60
+ },
61
+ "description": "Arguments before each host, as -F <file>."
62
+ },
63
+ "nodeMirror": {
64
+ "type": "string",
65
+ "description": "Where Node.js comes from for hosts without one, in the layout of https://nodejs.org/dist; empty: that."
66
+ }
67
+ }
47
68
  }
48
69
  }
49
70
  }
package/cell.yml CHANGED
@@ -16,3 +16,10 @@ ta:
16
16
  # A ta exec-server to run commands and file operations on another machine (ta serve --exec); empty: this machine.
17
17
  url: ''
18
18
  token: ''
19
+ remote:
20
+ # The ssh of ssh:// locations: its configuration (~/.ssh/config) applies.
21
+ ssh: ssh
22
+ # Before each host, as -F <file>.
23
+ sshArgs: []
24
+ # Where Node.js comes from for hosts without one; empty: https://nodejs.org/dist.
25
+ nodeMirror: ''
@@ -1,16 +1,20 @@
1
1
  import { ExecClient, type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
2
2
  import { type TaExecOptions } from './host-protocol.js';
3
+ import { RemoteHosts } from './remote/remote-protocol.js';
3
4
  import { TaWorkingDirectory } from './working-directory.js';
4
5
  /**
5
- * Sessions run on this machine, or, with `ta.exec.url`, on the machine of a `ta exec-server`: the
6
- * agent loop stays here, commands and files are there. All sessions share one connection. The default
7
- * directory is the one the user chose (TaWorkingDirectory), if any.
6
+ * Where a location runs. `ssh://<host>/<path>`: on that host, through ssh (RemoteHosts). A path: on this
7
+ * machine, or with `ta.exec.url` on the machine of a `ta exec-server`, all sessions on one connection.
8
+ * The agent loop stays here; commands and files are there. The default directory is the one the user
9
+ * chose (TaWorkingDirectory), if any.
8
10
  */
9
11
  export declare class DefaultExecEnvironmentFactory implements ExecEnvironmentFactory {
10
12
  protected readonly options?: TaExecOptions;
11
13
  protected readonly workingDirectory?: TaWorkingDirectory;
14
+ protected readonly remoteHosts: RemoteHosts;
12
15
  protected client?: ExecClient;
13
- create(cwd: string): ExecEnvironment;
16
+ /** Its `cwd` is the path there: the one to resolve paths against, not the location. */
17
+ create(location: string): ExecEnvironment;
14
18
  /** The working directory the user chose, else that of this process, or of the exec server. */
15
19
  defaultCwd(): Promise<string>;
16
20
  protected remote(): ExecClient | undefined;
@@ -9,17 +9,35 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { Autowired, Component, Optional, Value } from '@celljs/core';
11
11
  import { ExecClient, ExecEnvironmentFactory, LocalExecEnvironment, RemoteExecEnvironment } from '@celljs/ta-exec';
12
+ import { TaLocation } from '@celljs/ta-protocol';
12
13
  import { TA_EXEC_OPTIONS } from './host-protocol.js';
14
+ import { RemoteHosts } from './remote/remote-protocol.js';
15
+ import { TaErrors } from './ta-errors.js';
13
16
  import { TaWorkingDirectory } from './working-directory.js';
14
17
  /**
15
- * Sessions run on this machine, or, with `ta.exec.url`, on the machine of a `ta exec-server`: the
16
- * agent loop stays here, commands and files are there. All sessions share one connection. The default
17
- * directory is the one the user chose (TaWorkingDirectory), if any.
18
+ * Where a location runs. `ssh://<host>/<path>`: on that host, through ssh (RemoteHosts). A path: on this
19
+ * machine, or with `ta.exec.url` on the machine of a `ta exec-server`, all sessions on one connection.
20
+ * The agent loop stays here; commands and files are there. The default directory is the one the user
21
+ * chose (TaWorkingDirectory), if any.
18
22
  */
19
23
  let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
20
- create(cwd) {
24
+ /** Its `cwd` is the path there: the one to resolve paths against, not the location. */
25
+ create(location) {
26
+ let remote;
27
+ try {
28
+ remote = TaLocation.parse(location);
29
+ }
30
+ catch (error) {
31
+ throw TaErrors.invalidArgument(error.message, 'Write ssh://<host>/<absolute path>.');
32
+ }
33
+ if (remote) {
34
+ if (!remote.path) {
35
+ throw TaErrors.invalidArgument(`${location} names no directory.`, 'Resolve it first (TaRemoteServer.resolveLocation), or write its path.');
36
+ }
37
+ return new RemoteExecEnvironment(this.remoteHosts.client(remote.host), remote.path);
38
+ }
21
39
  const client = this.remote();
22
- return client ? new RemoteExecEnvironment(client, cwd) : new LocalExecEnvironment(cwd);
40
+ return client ? new RemoteExecEnvironment(client, location) : new LocalExecEnvironment(location);
23
41
  }
24
42
  /** The working directory the user chose, else that of this process, or of the exec server. */
25
43
  async defaultCwd() {
@@ -38,7 +56,7 @@ let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
38
56
  return undefined;
39
57
  }
40
58
  // A host started later fences the ones before it.
41
- (_b = this.client) !== null && _b !== void 0 ? _b : (this.client = new ExecClient({ url, token, epoch: epoch || Date.now() }));
59
+ (_b = this.client) !== null && _b !== void 0 ? _b : (this.client = new ExecClient({ connect: ExecClient.webSocket(url, token), epoch: epoch || Date.now() }));
42
60
  return this.client;
43
61
  }
44
62
  };
@@ -51,6 +69,10 @@ __decorate([
51
69
  Optional(),
52
70
  __metadata("design:type", Object)
53
71
  ], DefaultExecEnvironmentFactory.prototype, "workingDirectory", void 0);
72
+ __decorate([
73
+ Autowired(RemoteHosts),
74
+ __metadata("design:type", Object)
75
+ ], DefaultExecEnvironmentFactory.prototype, "remoteHosts", void 0);
54
76
  DefaultExecEnvironmentFactory = __decorate([
55
77
  Component(ExecEnvironmentFactory)
56
78
  ], DefaultExecEnvironmentFactory);
@@ -1 +1 @@
1
- {"version":3,"file":"exec-environment-factory.js","sourceRoot":"","sources":["../../src/node/exec-environment-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,UAAU,EAAwB,sBAAsB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxI,OAAO,EAAE,eAAe,EAAsB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;GAIG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAUtC,MAAM,CAAC,GAAW;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAC3F,CAAC;IAED,8FAA8F;IAC9F,KAAK,CAAC,UAAU;;QACZ,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,gBAAgB,0CAAE,GAAG,EAAE,CAAC;QAC5C,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,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AM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9D,CAAC;IAES,MAAM;;QACZ,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,EAAE,SAAG,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QACtD,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,kDAAkD;QAClD,MAAA,IAAI,CAAC,MAAM,oCAAX,IAAI,CAAC,MAAM,GAAK,IAAI,UAAU,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,EAAC;QAC1G,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CACJ,CAAA;AAhDsB;IADlB,KAAK,CAAC,eAAe,CAAC;;8DACoB;AAIxB;IAFlB,SAAS,CAAC,kBAAkB,CAAC;IAC7B,QAAQ,EAAE;;uEAC8C;AAGtC;IADlB,SAAS,CAAC,WAAW,CAAC;;kEACqB;AATnC,6BAA6B;IADzC,SAAS,CAAC,sBAAsB,CAAC;GACrB,6BAA6B,CAkDzC"}
@@ -11,6 +11,7 @@ export * from './package-hosts.js';
11
11
  export * from './package-server-impl.js';
12
12
  export * from './receipt-book.js';
13
13
  export * from './relay-bridge.js';
14
+ export * from './remote/index.js';
14
15
  export * from './remote-ui-context.js';
15
16
  export * from './session-info-util.js';
16
17
  export * from './session-storage/index.js';
package/esm/node/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './package-hosts.js';
11
11
  export * from './package-server-impl.js';
12
12
  export * from './receipt-book.js';
13
13
  export * from './relay-bridge.js';
14
+ export * from './remote/index.js';
14
15
  export * from './remote-ui-context.js';
15
16
  export * from './session-info-util.js';
16
17
  export * from './session-storage/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
@@ -2,6 +2,7 @@ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { type TaExtensionHost, type TaHostAnswer, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
4
4
  import { ExtensionDataStore } from './extension-data.js';
5
+ import { PiDirectories } from './remote/remote-protocol.js';
5
6
  export declare const PackageHosts: unique symbol;
6
7
  /**
7
8
  * The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
@@ -18,6 +19,8 @@ export interface PackageHosts {
18
19
  call(name: string, method: string, params: unknown[]): Promise<unknown>;
19
20
  }
20
21
  export declare namespace PackageHostUtil {
22
+ /** The `cwd` of the header of a pi session file; undefined when it has none. */
23
+ function sessionCwd(file: string): Promise<string | undefined>;
21
24
  /** The file of `pi.host`, inside the package; undefined when it has none. */
22
25
  function entry(root: string): string | undefined;
23
26
  }
@@ -25,6 +28,7 @@ interface Running {
25
28
  service: Promise<TaPackageService | undefined>;
26
29
  }
27
30
  export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecycle<Application> {
31
+ protected readonly directories: PiDirectories;
28
32
  protected readonly codingAgentOptions?: CodingAgentOptions;
29
33
  protected readonly data: ExtensionDataStore;
30
34
  protected readonly server: TaServer;
@@ -8,6 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { readFileSync } from 'node:fs';
11
+ import { open } from 'node:fs/promises';
11
12
  import { join, relative, resolve, sep } from 'node:path';
12
13
  import { pathToFileURL } from 'node:url';
13
14
  import { CODING_AGENT_OPTIONS } from '@celljs/ai-coding-agent';
@@ -16,10 +17,31 @@ import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
16
17
  import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
17
18
  import { TaPackageServer, TaServer } from '@celljs/ta-protocol';
18
19
  import { ExtensionDataStore } from './extension-data.js';
20
+ import { PiDirectories } from './remote/remote-protocol.js';
19
21
  import { TaErrors } from './ta-errors.js';
20
22
  export const PackageHosts = Symbol('PackageHosts');
21
23
  export var PackageHostUtil;
22
24
  (function (PackageHostUtil) {
25
+ /** The bytes of a session file that hold its header, its first line. */
26
+ const HEADER_BYTES = 16384;
27
+ /** The `cwd` of the header of a pi session file; undefined when it has none. */
28
+ async function sessionCwd(file) {
29
+ let handle;
30
+ try {
31
+ handle = await open(file, 'r');
32
+ const buffer = Buffer.alloc(HEADER_BYTES);
33
+ const { bytesRead } = await handle.read(buffer, 0, HEADER_BYTES, 0);
34
+ const header = JSON.parse(buffer.subarray(0, bytesRead).toString('utf8').split('\n')[0]);
35
+ return (header === null || header === void 0 ? void 0 : header.type) === 'session' && typeof header.cwd === 'string' ? header.cwd : undefined;
36
+ }
37
+ catch (_a) {
38
+ return undefined;
39
+ }
40
+ finally {
41
+ await (handle === null || handle === void 0 ? void 0 : handle.close());
42
+ }
43
+ }
44
+ PackageHostUtil.sessionCwd = sessionCwd;
23
45
  /** The file of `pi.host`, inside the package; undefined when it has none. */
24
46
  function entry(root) {
25
47
  var _a, _b;
@@ -122,6 +144,10 @@ let PackageHostsImpl = class PackageHostsImpl {
122
144
  const packages = this.packages;
123
145
  this.extensionHost = {
124
146
  agentDir: this.agentDir(),
147
+ sessionCwd: async (file) => {
148
+ const cwd = await PackageHostUtil.sessionCwd(file);
149
+ return cwd === undefined ? undefined : this.directories.fromPi(cwd);
150
+ },
125
151
  listPackages: cwd => packages.listPackages(cwd),
126
152
  getServerInfo: () => server.getServerInfo(),
127
153
  listSessions: () => server.listSessions(),
@@ -144,6 +170,10 @@ let PackageHostsImpl = class PackageHostsImpl {
144
170
  return (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : TaBrand.agentDir();
145
171
  }
146
172
  };
173
+ __decorate([
174
+ Autowired(PiDirectories),
175
+ __metadata("design:type", Object)
176
+ ], PackageHostsImpl.prototype, "directories", void 0);
147
177
  __decorate([
148
178
  Value(CODING_AGENT_OPTIONS),
149
179
  __metadata("design:type", Object)
@@ -1 +1 @@
1
- {"version":3,"file":"package-hosts.js","sourceRoot":"","sources":["../../src/node/package-hosts.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAA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';
2
+ export * from './port-forwards.js';
3
+ export * from './remote-hosts.js';
4
+ export * from './remote-protocol.js';
5
+ export * from './remote-server-impl.js';
@@ -0,0 +1,6 @@
1
+ export * from './pi-directories.js';
2
+ export * from './port-forwards.js';
3
+ export * from './remote-hosts.js';
4
+ export * from './remote-protocol.js';
5
+ export * from './remote-server-impl.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/remote/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
+ import { type TaExecOptions } from '../host-protocol.js';
3
+ import { PiDirectories } from './remote-protocol.js';
4
+ /**
5
+ * `<agent directory>/remote/ssh/<host>/<path>` for `ssh://<host>/<path>`. With `ta.exec.url` every
6
+ * directory is one of the machine of the exec server: `<agent directory>/remote/exec/<path>`.
7
+ */
8
+ export declare class DefaultPiDirectories implements PiDirectories {
9
+ protected readonly codingAgentOptions?: CodingAgentOptions;
10
+ protected readonly execOptions?: TaExecOptions;
11
+ toPi(location: string): string;
12
+ fromPi(cwd: string): string;
13
+ protected root(): string;
14
+ }
@@ -0,0 +1,64 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { mkdirSync } from 'node:fs';
11
+ import { join, sep } from 'node:path';
12
+ import { CODING_AGENT_OPTIONS } from '@celljs/ai-coding-agent';
13
+ import { Component, Value } from '@celljs/core';
14
+ import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
15
+ import { TaLocation } from '@celljs/ta-protocol';
16
+ import { TA_EXEC_OPTIONS } from '../host-protocol.js';
17
+ import { PiDirectories } from './remote-protocol.js';
18
+ /**
19
+ * `<agent directory>/remote/ssh/<host>/<path>` for `ssh://<host>/<path>`. With `ta.exec.url` every
20
+ * directory is one of the machine of the exec server: `<agent directory>/remote/exec/<path>`.
21
+ */
22
+ let DefaultPiDirectories = class DefaultPiDirectories {
23
+ toPi(location) {
24
+ var _a;
25
+ const remote = TaLocation.parse(location);
26
+ const prefix = remote ? join('ssh', remote.host) : ((_a = this.execOptions) === null || _a === void 0 ? void 0 : _a.url) ? 'exec' : undefined;
27
+ if (!prefix) {
28
+ return location;
29
+ }
30
+ const path = remote ? remote.path : location;
31
+ const cwd = join(this.root(), prefix, ...path.split('/').filter(Boolean));
32
+ mkdirSync(cwd, { recursive: true });
33
+ return cwd;
34
+ }
35
+ fromPi(cwd) {
36
+ const root = this.root() + sep;
37
+ if (!cwd.startsWith(root)) {
38
+ return cwd;
39
+ }
40
+ const [kind, ...rest] = cwd.slice(root.length).split(sep);
41
+ if (kind === 'ssh' && rest.length > 0 && TaLocation.isHost(rest[0])) {
42
+ return TaLocation.ssh(rest[0], `/${rest.slice(1).join('/')}`);
43
+ }
44
+ return kind === 'exec' ? `/${rest.join('/')}` : cwd;
45
+ }
46
+ root() {
47
+ var _a;
48
+ var _b;
49
+ return join((_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : TaBrand.agentDir(), 'remote');
50
+ }
51
+ };
52
+ __decorate([
53
+ Value(CODING_AGENT_OPTIONS),
54
+ __metadata("design:type", Object)
55
+ ], DefaultPiDirectories.prototype, "codingAgentOptions", void 0);
56
+ __decorate([
57
+ Value(TA_EXEC_OPTIONS),
58
+ __metadata("design:type", Object)
59
+ ], DefaultPiDirectories.prototype, "execOptions", void 0);
60
+ DefaultPiDirectories = __decorate([
61
+ Component(PiDirectories)
62
+ ], DefaultPiDirectories);
63
+ export { DefaultPiDirectories };
64
+ //# sourceMappingURL=pi-directories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi-directories.js","sourceRoot":"","sources":["../../../src/node/remote/pi-directories.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAA2B,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;GAGG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAO7B,IAAI,CAAC,QAAgB;;QACjB,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,GAAG,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9F,IAAI,CAAC,MA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A,IAAI,CAAC,kBAAkB,0CAAE,QAAQ,mCAAI,OAAO,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;CACJ,CAAA;AAhCsB;IADlB,KAAK,CAAC,oBAAoB,CAAC;;gEAC+B;AAGxC;IADlB,KAAK,CAAC,eAAe,CAAC;;yDACwB;AALtC,oBAAoB;IADhC,SAAS,CAAC,aAAa,CAAC;GACZ,oBAAoB,CAkChC"}
@@ -0,0 +1,35 @@
1
+ import { type Server, type Socket } from 'node:net';
2
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
3
+ import { type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
4
+ import { type TaForwardedPort } from '@celljs/ta-protocol';
5
+ import { PortForwards, RemoteHosts } from './remote-protocol.js';
6
+ interface Forward {
7
+ info: TaForwardedPort;
8
+ server: Server;
9
+ sockets: Set<Socket>;
10
+ }
11
+ /**
12
+ * A port of another machine as a port of 127.0.0.1 here: each connection to it is one from the server
13
+ * of Ta there (ExecEnvironment.connect). The same number when it is free here, as VS Code does, so that
14
+ * the pages of a dev server keep their links.
15
+ */
16
+ export declare class DefaultPortForwards implements PortForwards, ApplicationLifecycle<Application> {
17
+ protected readonly environments: ExecEnvironmentFactory;
18
+ protected readonly hosts: RemoteHosts;
19
+ protected readonly forwards: Map<string, Promise<Forward>>;
20
+ /** Those open. */
21
+ protected readonly open: Map<string, TaForwardedPort>;
22
+ protected watching: boolean;
23
+ forward(cwd: string, port: number): Promise<TaForwardedPort>;
24
+ list(): TaForwardedPort[];
25
+ close(host: string, remotePort: number): Promise<void>;
26
+ onStop(): Promise<void>;
27
+ protected listenFor(env: ExecEnvironment, host: string, port: number): Promise<Forward>;
28
+ protected listen(server: Server, port: number): Promise<number>;
29
+ /** One connection: data both ways until either side ends it. */
30
+ protected pipe(env: ExecEnvironment, port: number, socket: Socket): Promise<void>;
31
+ /** A host disconnected on purpose takes its ports with it. */
32
+ protected watch(): void;
33
+ protected split(key: string): [string, number];
34
+ }
35
+ export {};