@celljs/ta-host 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.en.md +68 -0
- package/README.md +13 -2
- package/cell.schema.json +21 -0
- package/cell.yml +7 -0
- package/esm/node/exec-environment-factory.d.ts +8 -4
- package/esm/node/exec-environment-factory.js +28 -6
- package/esm/node/exec-environment-factory.js.map +1 -1
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/index.js.map +1 -1
- package/esm/node/package-hosts.d.ts +4 -0
- package/esm/node/package-hosts.js +30 -0
- package/esm/node/package-hosts.js.map +1 -1
- package/esm/node/remote/index.d.ts +5 -0
- package/esm/node/remote/index.js +6 -0
- package/esm/node/remote/index.js.map +1 -0
- package/esm/node/remote/pi-directories.d.ts +14 -0
- package/esm/node/remote/pi-directories.js +64 -0
- package/esm/node/remote/pi-directories.js.map +1 -0
- package/esm/node/remote/port-forwards.d.ts +35 -0
- package/esm/node/remote/port-forwards.js +150 -0
- package/esm/node/remote/port-forwards.js.map +1 -0
- package/esm/node/remote/remote-hosts.d.ts +40 -0
- package/esm/node/remote/remote-hosts.js +170 -0
- package/esm/node/remote/remote-hosts.js.map +1 -0
- package/esm/node/remote/remote-protocol.d.ts +51 -0
- package/esm/node/remote/remote-protocol.js +5 -0
- package/esm/node/remote/remote-protocol.js.map +1 -0
- package/esm/node/remote/remote-server-impl.d.ts +19 -0
- package/esm/node/remote/remote-server-impl.js +66 -0
- package/esm/node/remote/remote-server-impl.js.map +1 -0
- package/esm/node/settings-store.d.ts +3 -1
- package/esm/node/settings-store.js +9 -2
- package/esm/node/settings-store.js.map +1 -1
- package/esm/node/ta-server-impl.d.ts +2 -0
- package/esm/node/ta-server-impl.js +16 -4
- package/esm/node/ta-server-impl.js.map +1 -1
- package/esm/node/ta-session-factory.d.ts +16 -2
- package/esm/node/ta-session-factory.js +38 -8
- package/esm/node/ta-session-factory.js.map +1 -1
- package/esm/node/ta-session.d.ts +4 -0
- package/esm/node/ta-session.js +5 -1
- package/esm/node/ta-session.js.map +1 -1
- package/esm/node/terminal-service.js +1 -1
- package/esm/node/terminal-service.js.map +1 -1
- package/esm/node/web-extension-catalog.d.ts +3 -1
- package/esm/node/web-extension-catalog.js +8 -2
- package/esm/node/web-extension-catalog.js.map +1 -1
- package/esm/node/working-directory.d.ts +12 -1
- package/esm/node/working-directory.js +22 -1
- package/esm/node/working-directory.js.map +1 -1
- package/esm/node/workspace-files.d.ts +1 -1
- package/esm/node/workspace-files.js +3 -3
- package/esm/node/workspace-files.js.map +1 -1
- package/esm/node/workspace-service.js +3 -3
- package/esm/node/workspace-service.js.map +1 -1
- package/lib/node/exec-environment-factory.d.ts +8 -4
- package/lib/node/exec-environment-factory.d.ts.map +1 -1
- package/lib/node/exec-environment-factory.js +28 -6
- package/lib/node/exec-environment-factory.js.map +1 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/package-hosts.d.ts +4 -0
- package/lib/node/package-hosts.d.ts.map +1 -1
- package/lib/node/package-hosts.js +30 -0
- package/lib/node/package-hosts.js.map +1 -1
- package/lib/node/remote/index.d.ts +6 -0
- package/lib/node/remote/index.d.ts.map +1 -0
- package/lib/node/remote/index.js +22 -0
- package/lib/node/remote/index.js.map +1 -0
- package/lib/node/remote/pi-directories.d.ts +15 -0
- package/lib/node/remote/pi-directories.d.ts.map +1 -0
- package/lib/node/remote/pi-directories.js +67 -0
- package/lib/node/remote/pi-directories.js.map +1 -0
- package/lib/node/remote/port-forwards.d.ts +36 -0
- package/lib/node/remote/port-forwards.d.ts.map +1 -0
- package/lib/node/remote/port-forwards.js +153 -0
- package/lib/node/remote/port-forwards.js.map +1 -0
- package/lib/node/remote/remote-hosts.d.ts +41 -0
- package/lib/node/remote/remote-hosts.d.ts.map +1 -0
- package/lib/node/remote/remote-hosts.js +173 -0
- package/lib/node/remote/remote-hosts.js.map +1 -0
- package/lib/node/remote/remote-protocol.d.ts +52 -0
- package/lib/node/remote/remote-protocol.d.ts.map +1 -0
- package/lib/node/remote/remote-protocol.js +8 -0
- package/lib/node/remote/remote-protocol.js.map +1 -0
- package/lib/node/remote/remote-server-impl.d.ts +20 -0
- package/lib/node/remote/remote-server-impl.d.ts.map +1 -0
- package/lib/node/remote/remote-server-impl.js +69 -0
- package/lib/node/remote/remote-server-impl.js.map +1 -0
- package/lib/node/remote/remote.spec.d.ts +2 -0
- package/lib/node/remote/remote.spec.d.ts.map +1 -0
- package/lib/node/remote/remote.spec.js +130 -0
- package/lib/node/remote/remote.spec.js.map +1 -0
- package/lib/node/settings-store.d.ts +3 -1
- package/lib/node/settings-store.d.ts.map +1 -1
- package/lib/node/settings-store.js +9 -2
- package/lib/node/settings-store.js.map +1 -1
- package/lib/node/settings-store.spec.js +2 -1
- package/lib/node/settings-store.spec.js.map +1 -1
- package/lib/node/ta-server-impl.d.ts +2 -0
- package/lib/node/ta-server-impl.d.ts.map +1 -1
- package/lib/node/ta-server-impl.js +16 -4
- package/lib/node/ta-server-impl.js.map +1 -1
- package/lib/node/ta-session-factory.d.ts +16 -2
- package/lib/node/ta-session-factory.d.ts.map +1 -1
- package/lib/node/ta-session-factory.js +37 -7
- package/lib/node/ta-session-factory.js.map +1 -1
- package/lib/node/ta-session.d.ts +4 -0
- package/lib/node/ta-session.d.ts.map +1 -1
- package/lib/node/ta-session.js +5 -1
- package/lib/node/ta-session.js.map +1 -1
- package/lib/node/terminal-service.js +1 -1
- package/lib/node/terminal-service.js.map +1 -1
- package/lib/node/web-extension-catalog.d.ts +3 -1
- package/lib/node/web-extension-catalog.d.ts.map +1 -1
- package/lib/node/web-extension-catalog.js +7 -1
- package/lib/node/web-extension-catalog.js.map +1 -1
- package/lib/node/web-extension-catalog.spec.js +1 -1
- package/lib/node/web-extension-catalog.spec.js.map +1 -1
- package/lib/node/working-directory.d.ts +12 -1
- package/lib/node/working-directory.d.ts.map +1 -1
- package/lib/node/working-directory.js +22 -1
- package/lib/node/working-directory.js.map +1 -1
- package/lib/node/workspace-files.d.ts +1 -1
- package/lib/node/workspace-files.d.ts.map +1 -1
- package/lib/node/workspace-files.js +3 -3
- package/lib/node/workspace-files.js.map +1 -1
- package/lib/node/workspace-service.js +3 -3
- package/lib/node/workspace-service.js.map +1 -1
- package/package.json +14 -10
- package/src/node/exec-environment-factory.ts +26 -6
- package/src/node/index.ts +1 -0
- package/src/node/package-hosts.ts +28 -0
- package/src/node/remote/index.ts +5 -0
- package/src/node/remote/pi-directories.ts +49 -0
- package/src/node/remote/port-forwards.ts +148 -0
- package/src/node/remote/remote-hosts.ts +170 -0
- package/src/node/remote/remote-protocol.ts +57 -0
- package/src/node/remote/remote-server-impl.ts +60 -0
- package/src/node/remote/remote.spec.ts +142 -0
- package/src/node/settings-store.spec.ts +2 -1
- package/src/node/settings-store.ts +8 -2
- package/src/node/ta-server-impl.ts +18 -4
- package/src/node/ta-session-factory.ts +40 -7
- package/src/node/ta-session.ts +8 -1
- package/src/node/terminal-service.ts +1 -1
- package/src/node/web-extension-catalog.spec.ts +1 -1
- package/src/node/web-extension-catalog.ts +7 -2
- package/src/node/working-directory.ts +35 -2
- package/src/node/workspace-files.ts +3 -3
- package/src/node/workspace-service.ts +3 -3
package/src/node/ta-session.ts
CHANGED
|
@@ -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.
|
|
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(
|
|
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(
|
|
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
|
-
/**
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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(
|