@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
@@ -33,6 +33,8 @@ export interface TaSessionContext {
33
33
  requestClose(session: TaSession): void;
34
34
  /** TaOpenSessionOptions.group. */
35
35
  group?: string;
36
+ /** The location of the directory pi works in (PiDirectories.fromPi); default: that directory. */
37
+ locate?(cwd: string): string;
36
38
  }
37
39
 
38
40
  /**
@@ -62,6 +64,11 @@ export class TaSession {
62
64
  return this.runtime.session;
63
65
  }
64
66
 
67
+ /** Where the session works, as clients name it: a path, or an `ssh://` location. */
68
+ get cwd(): string {
69
+ return this.context.locate ? this.context.locate(this.runtime.cwd) : this.runtime.cwd;
70
+ }
71
+
65
72
  async start(): Promise<void> {
66
73
  this.runtime.setRebindSession(() => this.bind());
67
74
  await this.bind();
@@ -76,7 +83,7 @@ export class TaSession {
76
83
  return {
77
84
  sessionId: this.id,
78
85
  piSessionId: pi.sessionId,
79
- cwd: this.runtime.cwd,
86
+ cwd: this.cwd,
80
87
  sessionFile: pi.sessionFile,
81
88
  sessionName: pi.sessionName,
82
89
  firstMessage: SessionInfoUtil.firstMessage(pi.messages),
@@ -56,7 +56,7 @@ export class DefaultTaTerminals implements TaTerminals, ApplicationLifecycle<App
56
56
 
57
57
  async open(connection: RpcConnection, options: TaOpenTerminalOptions & { cwd: string }): Promise<TaTerminalInfo> {
58
58
  const env = this.environments.create(options.cwd);
59
- const stat = await env.stat(options.cwd);
59
+ const stat = await env.stat(env.cwd);
60
60
  if (!stat?.isDirectory) {
61
61
  throw TaErrors.invalidArgument(`${options.cwd} is not a directory.`, 'Open the terminal in a directory that exists.');
62
62
  }
@@ -69,7 +69,7 @@ describe('WebExtensionCatalogImpl', () => {
69
69
  mkdirSync(cwd);
70
70
  const agentDir = join(home, 'agent');
71
71
  catalog = new WebExtensionCatalogImpl();
72
- Object.assign(catalog, { codingAgentOptions: { agentDir } });
72
+ Object.assign(catalog, { codingAgentOptions: { agentDir }, directories: { toPi: (location: string) => location, fromPi: (dir: string) => dir } });
73
73
  // A directory in extensions/, and a package of the packages setting elsewhere.
74
74
  write(join(agentDir, 'extensions/notes/package.json'), JSON.stringify({ name: 'notes', pi: { web: ['web.js'] } }));
75
75
  write(join(agentDir, 'extensions/notes/web.js'), WEB);
@@ -1,12 +1,13 @@
1
1
  import { rmSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { CODING_AGENT_OPTIONS, type CodingAgentOptions, type PiSdk, PiSdkUtil } from '@celljs/ai-coding-agent';
4
- import { Component, Value } from '@celljs/core';
4
+ import { Autowired, Component, Value } from '@celljs/core';
5
5
  import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
6
6
  import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
7
7
  import type { TaPackageInfo, TaSettingsScope, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
8
8
  import { WebExtensionCatalog } from './host-protocol';
9
9
  import { PackageSwitch } from './package-switch';
10
+ import { PiDirectories } from './remote/remote-protocol';
10
11
  import { TaErrors } from './ta-errors';
11
12
  import { type WebExtensionPackage, WebExtensionUtil } from './web-extension-util';
12
13
 
@@ -31,6 +32,9 @@ export class WebExtensionCatalogImpl implements WebExtensionCatalog {
31
32
  @Value(CODING_AGENT_OPTIONS)
32
33
  protected readonly codingAgentOptions?: CodingAgentOptions;
33
34
 
35
+ @Autowired(PiDirectories)
36
+ protected readonly directories: PiDirectories;
37
+
34
38
  async packages(cwd: string): Promise<TaPackageInfo[]> {
35
39
  const { packages } = await this.load(cwd);
36
40
  return packages.map(pkg => WebExtensionUtil.describePackage(pkg));
@@ -131,7 +135,8 @@ export class WebExtensionCatalogImpl implements WebExtensionCatalog {
131
135
  return manager.resolve(async () => 'skip');
132
136
  }
133
137
 
134
- protected async load(cwd: string): Promise<Loaded> {
138
+ protected async load(location: string): Promise<Loaded> {
139
+ const cwd = this.directories.toPi(location);
135
140
  const sdk = await PiSdkUtil.load();
136
141
  const agentDir = this.codingAgentOptions?.agentDir ?? sdk.getAgentDir();
137
142
  const trusted = new sdk.ProjectTrustStore(agentDir).get(cwd) ?? !sdk.hasTrustRequiringProjectResources(cwd);
@@ -6,12 +6,22 @@ import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
6
6
 
7
7
  export const TaWorkingDirectory = Symbol('TaWorkingDirectory');
8
8
 
9
- /** The working directory the user chose for ta serve (TaServer.setWorkingDirectory), kept across restarts. */
9
+ /**
10
+ * The working directory the user chose for ta serve (TaServer.setWorkingDirectory), and the hosts of the
11
+ * remote directories opened lately (TaRemoteServer), kept across restarts.
12
+ */
10
13
  export interface TaWorkingDirectory {
11
14
  get(): string | undefined;
12
15
  set(cwd: string): void;
16
+ /** The latest first. */
17
+ recentHosts(): string[];
18
+ addRecentHost(host: string): void;
19
+ removeRecentHost(host: string): void;
13
20
  }
14
21
 
22
+ /** Hosts kept in recentHosts. */
23
+ const RECENT_HOSTS = 10;
24
+
15
25
  /** In ta.json of the agent directory, beside Ta's other settings of its own; the file keeps its other keys. */
16
26
  @Component(TaWorkingDirectory)
17
27
  export class TaWorkingDirectoryImpl implements TaWorkingDirectory {
@@ -23,7 +33,30 @@ export class TaWorkingDirectoryImpl implements TaWorkingDirectory {
23
33
  }
24
34
 
25
35
  set(cwd: string): void {
26
- writeFileSync(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), workingDirectory: cwd }, null, 2)}\n`);
36
+ this.write({ workingDirectory: cwd });
37
+ }
38
+
39
+ recentHosts(): string[] {
40
+ const { remoteHosts } = this.read();
41
+ return Array.isArray(remoteHosts) ? remoteHosts.filter((host): host is string => typeof host === 'string') : [];
42
+ }
43
+
44
+ addRecentHost(host: string): void {
45
+ const hosts = this.recentHosts();
46
+ if (hosts[0] !== host) {
47
+ this.write({ remoteHosts: [host, ...hosts.filter(other => other !== host)].slice(0, RECENT_HOSTS) });
48
+ }
49
+ }
50
+
51
+ removeRecentHost(host: string): void {
52
+ const hosts = this.recentHosts();
53
+ if (hosts.includes(host)) {
54
+ this.write({ remoteHosts: hosts.filter(other => other !== host) });
55
+ }
56
+ }
57
+
58
+ protected write(changes: Record<string, unknown>): void {
59
+ writeFileSync(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), ...changes }, null, 2)}\n`);
27
60
  renameSync(`${this.file}.tmp`, this.file);
28
61
  }
29
62
 
@@ -159,7 +159,7 @@ export class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
159
159
 
160
160
  protected async send(request: IncomingMessage, response: ServerResponse, cwd: string, path: string): Promise<void> {
161
161
  const env = this.environments.create(cwd);
162
- const file = await this.find(env, cwd, path);
162
+ const file = await this.find(env, path);
163
163
  if (!file) {
164
164
  this.fail(response, 404);
165
165
  return;
@@ -207,10 +207,10 @@ export class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
207
207
  }
208
208
 
209
209
  /** The file at `path`, or the `index.html` of the directory there. */
210
- protected async find(env: ExecEnvironment, cwd: string, path: string): Promise<{ absolute: string; stat: FileStat } | undefined> {
210
+ protected async find(env: ExecEnvironment, path: string): Promise<{ absolute: string; stat: FileStat } | undefined> {
211
211
  let absolute: string;
212
212
  try {
213
- absolute = WorkspaceUtil.inside(cwd, path).absolute;
213
+ absolute = WorkspaceUtil.inside(env.cwd, path).absolute;
214
214
  } catch {
215
215
  return undefined;
216
216
  }
@@ -58,7 +58,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
58
58
 
59
59
  async listDirectory(cwd: string, path: string): Promise<TaDirEntry[]> {
60
60
  const env = this.environments.create(cwd);
61
- const target = WorkspaceUtil.inside(cwd, path);
61
+ const target = WorkspaceUtil.inside(env.cwd, path);
62
62
  const stat = await env.stat(target.absolute);
63
63
  if (!stat?.isDirectory) {
64
64
  throw TaErrors.invalidArgument(`${path} is not a directory.`, 'Pass the path of a directory inside the workspace.');
@@ -82,7 +82,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
82
82
 
83
83
  async readFile(cwd: string, path: string): Promise<TaFileContent> {
84
84
  const env = this.environments.create(cwd);
85
- const target = WorkspaceUtil.inside(cwd, path);
85
+ const target = WorkspaceUtil.inside(env.cwd, path);
86
86
  const stat = await env.stat(target.absolute);
87
87
  if (!stat || stat.isDirectory) {
88
88
  throw TaErrors.invalidArgument(`${path} is not a file.`, 'Pass the path of a file inside the workspace.');
@@ -101,7 +101,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
101
101
 
102
102
  async writeFile(cwd: string, path: string, text: string): Promise<void> {
103
103
  const env = this.environments.create(cwd);
104
- const target = WorkspaceUtil.inside(cwd, path);
104
+ const target = WorkspaceUtil.inside(env.cwd, path);
105
105
  const [stat, parent] = await Promise.all([env.stat(target.absolute), env.stat(dirname(target.absolute))]);
106
106
  if (stat?.isDirectory || !parent?.isDirectory) {
107
107
  throw TaErrors.invalidArgument(