@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.
- 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
|
@@ -0,0 +1,150 @@
|
|
|
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 { createServer } from 'node:net';
|
|
11
|
+
import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
|
|
12
|
+
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
13
|
+
import { TaLocation } from '@celljs/ta-protocol';
|
|
14
|
+
import { TaErrors } from '../ta-errors.js';
|
|
15
|
+
import { PortForwards, RemoteHosts } from './remote-protocol.js';
|
|
16
|
+
/**
|
|
17
|
+
* A port of another machine as a port of 127.0.0.1 here: each connection to it is one from the server
|
|
18
|
+
* of Ta there (ExecEnvironment.connect). The same number when it is free here, as VS Code does, so that
|
|
19
|
+
* the pages of a dev server keep their links.
|
|
20
|
+
*/
|
|
21
|
+
let DefaultPortForwards = class DefaultPortForwards {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.forwards = new Map();
|
|
24
|
+
/** Those open. */
|
|
25
|
+
this.open = new Map();
|
|
26
|
+
this.watching = false;
|
|
27
|
+
}
|
|
28
|
+
async forward(cwd, port) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
31
|
+
throw TaErrors.invalidArgument(`${port} is not a port.`, 'Pass a port from 1 to 65535.');
|
|
32
|
+
}
|
|
33
|
+
const env = this.environments.create(cwd);
|
|
34
|
+
const host = (_a = TaLocation.host(cwd)) !== null && _a !== void 0 ? _a : '';
|
|
35
|
+
if (!env.connect) {
|
|
36
|
+
return { host, remotePort: port, localPort: port };
|
|
37
|
+
}
|
|
38
|
+
this.watch();
|
|
39
|
+
const key = `${host}:${port}`;
|
|
40
|
+
let forward = this.forwards.get(key);
|
|
41
|
+
if (!forward) {
|
|
42
|
+
forward = this.listenFor(env, host, port);
|
|
43
|
+
this.forwards.set(key, forward);
|
|
44
|
+
forward.then(({ info }) => this.forwards.has(key) && this.open.set(key, info), () => this.forwards.delete(key));
|
|
45
|
+
}
|
|
46
|
+
return (await forward).info;
|
|
47
|
+
}
|
|
48
|
+
list() {
|
|
49
|
+
return [...this.open.values()];
|
|
50
|
+
}
|
|
51
|
+
async close(host, remotePort) {
|
|
52
|
+
var _a;
|
|
53
|
+
const key = `${host}:${remotePort}`;
|
|
54
|
+
const forward = await ((_a = this.forwards.get(key)) === null || _a === void 0 ? void 0 : _a.catch(() => undefined));
|
|
55
|
+
this.forwards.delete(key);
|
|
56
|
+
this.open.delete(key);
|
|
57
|
+
if (forward) {
|
|
58
|
+
for (const socket of forward.sockets) {
|
|
59
|
+
socket.destroy();
|
|
60
|
+
}
|
|
61
|
+
await new Promise(resolve => forward.server.close(() => resolve()));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async onStop() {
|
|
65
|
+
await Promise.all([...this.forwards.keys()].map(key => this.close(...this.split(key))));
|
|
66
|
+
}
|
|
67
|
+
async listenFor(env, host, port) {
|
|
68
|
+
const sockets = new Set();
|
|
69
|
+
const server = createServer(socket => {
|
|
70
|
+
sockets.add(socket);
|
|
71
|
+
socket.once('close', () => sockets.delete(socket));
|
|
72
|
+
void this.pipe(env, port, socket);
|
|
73
|
+
});
|
|
74
|
+
const localPort = await this.listen(server, port).catch(() => this.listen(server, 0));
|
|
75
|
+
return { info: { host, remotePort: port, localPort }, server, sockets };
|
|
76
|
+
}
|
|
77
|
+
listen(server, port) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const failed = (error) => reject(error);
|
|
80
|
+
server.once('error', failed);
|
|
81
|
+
server.listen(port, '127.0.0.1', () => {
|
|
82
|
+
server.removeListener('error', failed);
|
|
83
|
+
resolve(server.address().port);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** One connection: data both ways until either side ends it. */
|
|
88
|
+
async pipe(env, port, socket) {
|
|
89
|
+
// What comes before the other end is there waits for it.
|
|
90
|
+
const early = [];
|
|
91
|
+
let ended = false;
|
|
92
|
+
let remote;
|
|
93
|
+
const end = () => {
|
|
94
|
+
if (remote) {
|
|
95
|
+
remote.end();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
ended = true;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
socket.on('data', data => (remote ? remote.write(data) : early.push(data)));
|
|
102
|
+
socket.once('end', end);
|
|
103
|
+
socket.once('error', end);
|
|
104
|
+
try {
|
|
105
|
+
remote = await env.connect(port);
|
|
106
|
+
}
|
|
107
|
+
catch (_a) {
|
|
108
|
+
socket.destroy();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
remote.onData(data => socket.write(data));
|
|
112
|
+
remote.onClose(() => socket.end());
|
|
113
|
+
for (const data of early) {
|
|
114
|
+
remote.write(data);
|
|
115
|
+
}
|
|
116
|
+
if (ended) {
|
|
117
|
+
remote.end();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** A host disconnected on purpose takes its ports with it. */
|
|
121
|
+
watch() {
|
|
122
|
+
if (!this.watching) {
|
|
123
|
+
this.watching = true;
|
|
124
|
+
this.hosts.onDisconnect(host => {
|
|
125
|
+
for (const key of [...this.forwards.keys()]) {
|
|
126
|
+
if (key.startsWith(`${host}:`)) {
|
|
127
|
+
void this.close(...this.split(key));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
split(key) {
|
|
134
|
+
const at = key.lastIndexOf(':');
|
|
135
|
+
return [key.slice(0, at), Number(key.slice(at + 1))];
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
__decorate([
|
|
139
|
+
Autowired(ExecEnvironmentFactory),
|
|
140
|
+
__metadata("design:type", Object)
|
|
141
|
+
], DefaultPortForwards.prototype, "environments", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
Autowired(RemoteHosts),
|
|
144
|
+
__metadata("design:type", Object)
|
|
145
|
+
], DefaultPortForwards.prototype, "hosts", void 0);
|
|
146
|
+
DefaultPortForwards = __decorate([
|
|
147
|
+
Component([PortForwards, ApplicationLifecycle])
|
|
148
|
+
], DefaultPortForwards);
|
|
149
|
+
export { DefaultPortForwards };
|
|
150
|
+
//# sourceMappingURL=port-forwards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port-forwards.js","sourceRoot":"","sources":["../../../src/node/remote/port-forwards.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAC;AAClE,OAAO,EAAoB,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAwB,sBAAsB,EAAmB,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAwB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQ9D;;;;GAIG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QAOgB,aAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;QAClE,kBAAkB;QACC,SAAI,GAAG,IAAI,GAAG,EAA2B,CAAC;QACnD,aAAQ,GAAG,KAAK,CAAC;IAsH/B,CAAC;IApHG,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,IAAY;;QACnC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;YACtD,MAAM,QAAQ,CAAC,eAAe,CAAC,GAAG,IAAI,iBAAiB,EAAE,8BAA8B,CAAC,CAAC;QAC7F,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,IAAI,SAAG,UAAU,CAA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IAES,KAAK,CAAC,GAAW;QACvB,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;CACJ,CAAA;AA9HsB;IADlB,SAAS,CAAC,sBAAsB,CAAC;;yDACsB;AAGrC;IADlB,SAAS,CAAC,WAAW,CAAC;;kDACe;AAL7B,mBAAmB;IAD/B,SAAS,CAAC,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;GACnC,mBAAmB,CAgI/B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
2
|
+
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
4
|
+
import { type ExecClient, SshHost, type SshQuestion } from '@celljs/ta-exec';
|
|
5
|
+
import { TaLocation, type TaRemoteEvent, type TaRemoteHost, type TaRemotePrompt } from '@celljs/ta-protocol';
|
|
6
|
+
import { TaWorkingDirectory } from '../working-directory.js';
|
|
7
|
+
import { RemoteHosts, type TaRemoteOptions } from './remote-protocol.js';
|
|
8
|
+
interface Waiting {
|
|
9
|
+
prompt: TaRemotePrompt;
|
|
10
|
+
settle(value: string | undefined): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One SshHost per host, which connects on the first call there and again after a loss. What ssh asks
|
|
14
|
+
* goes to every client that watches, and the first answer counts, as with the dialogs of sessions.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DefaultRemoteHosts implements RemoteHosts, ApplicationLifecycle<Application> {
|
|
17
|
+
protected readonly options?: TaRemoteOptions;
|
|
18
|
+
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
19
|
+
protected readonly workingDirectory: TaWorkingDirectory;
|
|
20
|
+
protected readonly hosts: Map<string, SshHost>;
|
|
21
|
+
protected readonly waiting: Map<string, Waiting>;
|
|
22
|
+
protected readonly watchers: Set<RpcConnection>;
|
|
23
|
+
protected readonly disconnectListeners: Set<(host: string) => void>;
|
|
24
|
+
client(host: string): ExecClient;
|
|
25
|
+
list(): TaRemoteHost[];
|
|
26
|
+
add(host: string): void;
|
|
27
|
+
remove(host: string): Promise<void>;
|
|
28
|
+
resolve(location: string): Promise<string>;
|
|
29
|
+
disconnect(host: string): Promise<void>;
|
|
30
|
+
onDisconnect(listener: (host: string) => void): () => void;
|
|
31
|
+
watch(connection: RpcConnection): TaRemotePrompt[];
|
|
32
|
+
answer(promptId: string, value: string | null): boolean;
|
|
33
|
+
onStop(): Promise<void>;
|
|
34
|
+
protected ask(host: string, question: SshQuestion): Promise<string | undefined>;
|
|
35
|
+
protected broadcast(event: TaRemoteEvent): void;
|
|
36
|
+
protected check(host: string): string;
|
|
37
|
+
protected connected(host: string): boolean;
|
|
38
|
+
protected parse(location: string): TaLocation.Remote | undefined;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { randomUUID } from 'node:crypto';
|
|
11
|
+
import { CODING_AGENT_OPTIONS } from '@celljs/ai-coding-agent';
|
|
12
|
+
import { ApplicationLifecycle, Autowired, Component, Value } from '@celljs/core';
|
|
13
|
+
import { SshConfig, SshHost } from '@celljs/ta-exec';
|
|
14
|
+
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
15
|
+
import { TaClient, TaLocation } from '@celljs/ta-protocol';
|
|
16
|
+
import { TaErrors } from '../ta-errors.js';
|
|
17
|
+
import { TaWorkingDirectory } from '../working-directory.js';
|
|
18
|
+
import { RemoteHosts, TA_REMOTE_OPTIONS } from './remote-protocol.js';
|
|
19
|
+
/** A prompt nobody answers is cancelled after this: ssh gives up. */
|
|
20
|
+
const PROMPT_TIMEOUT_MS = 5 * 60 * 1000;
|
|
21
|
+
/**
|
|
22
|
+
* One SshHost per host, which connects on the first call there and again after a loss. What ssh asks
|
|
23
|
+
* goes to every client that watches, and the first answer counts, as with the dialogs of sessions.
|
|
24
|
+
*/
|
|
25
|
+
let DefaultRemoteHosts = class DefaultRemoteHosts {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.hosts = new Map();
|
|
28
|
+
this.waiting = new Map();
|
|
29
|
+
this.watchers = new Set();
|
|
30
|
+
this.disconnectListeners = new Set();
|
|
31
|
+
}
|
|
32
|
+
client(host) {
|
|
33
|
+
var _a, _b, _c, _d;
|
|
34
|
+
var _e;
|
|
35
|
+
this.check(host);
|
|
36
|
+
let ssh = this.hosts.get(host);
|
|
37
|
+
if (!ssh) {
|
|
38
|
+
ssh = new SshHost({
|
|
39
|
+
host,
|
|
40
|
+
stateDir: (_e = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _e !== void 0 ? _e : TaBrand.agentDir(),
|
|
41
|
+
ssh: ((_b = this.options) === null || _b === void 0 ? void 0 : _b.ssh) || undefined,
|
|
42
|
+
sshArgs: (_c = this.options) === null || _c === void 0 ? void 0 : _c.sshArgs,
|
|
43
|
+
nodeMirror: ((_d = this.options) === null || _d === void 0 ? void 0 : _d.nodeMirror) || undefined,
|
|
44
|
+
ask: question => this.ask(host, question),
|
|
45
|
+
onStep: (step, detail) => this.broadcast({ type: 'progress', host, step, detail }),
|
|
46
|
+
});
|
|
47
|
+
ssh.client.onState((connected, error) => {
|
|
48
|
+
if (connected) {
|
|
49
|
+
this.workingDirectory.addRecentHost(host);
|
|
50
|
+
}
|
|
51
|
+
this.broadcast(error ? { type: 'connection', host, connected, error } : { type: 'connection', host, connected });
|
|
52
|
+
});
|
|
53
|
+
this.hosts.set(host, ssh);
|
|
54
|
+
}
|
|
55
|
+
return ssh.client;
|
|
56
|
+
}
|
|
57
|
+
list() {
|
|
58
|
+
const recent = this.workingDirectory.recentHosts();
|
|
59
|
+
const config = SshConfig.hosts().filter(host => TaLocation.isHost(host) && !recent.includes(host));
|
|
60
|
+
return [
|
|
61
|
+
...recent.map(host => ({ host, source: 'recent', connected: this.connected(host) })),
|
|
62
|
+
...config.map(host => ({ host, source: 'config', connected: this.connected(host) })),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
add(host) {
|
|
66
|
+
this.workingDirectory.addRecentHost(this.check(host));
|
|
67
|
+
}
|
|
68
|
+
async remove(host) {
|
|
69
|
+
await this.disconnect(host);
|
|
70
|
+
this.workingDirectory.removeRecentHost(host);
|
|
71
|
+
}
|
|
72
|
+
async resolve(location) {
|
|
73
|
+
const remote = this.parse(location);
|
|
74
|
+
if (!remote || remote.path) {
|
|
75
|
+
return location;
|
|
76
|
+
}
|
|
77
|
+
return TaLocation.ssh(remote.host, (await this.client(remote.host).info()).cwd);
|
|
78
|
+
}
|
|
79
|
+
async disconnect(host) {
|
|
80
|
+
const ssh = this.hosts.get(host);
|
|
81
|
+
this.hosts.delete(host);
|
|
82
|
+
for (const listener of this.disconnectListeners) {
|
|
83
|
+
listener(host);
|
|
84
|
+
}
|
|
85
|
+
await (ssh === null || ssh === void 0 ? void 0 : ssh.dispose());
|
|
86
|
+
}
|
|
87
|
+
onDisconnect(listener) {
|
|
88
|
+
this.disconnectListeners.add(listener);
|
|
89
|
+
return () => this.disconnectListeners.delete(listener);
|
|
90
|
+
}
|
|
91
|
+
watch(connection) {
|
|
92
|
+
if (!this.watchers.has(connection)) {
|
|
93
|
+
this.watchers.add(connection);
|
|
94
|
+
connection.onClose(() => this.watchers.delete(connection));
|
|
95
|
+
}
|
|
96
|
+
return [...this.waiting.values()].map(({ prompt }) => prompt);
|
|
97
|
+
}
|
|
98
|
+
answer(promptId, value) {
|
|
99
|
+
const waiting = this.waiting.get(promptId);
|
|
100
|
+
waiting === null || waiting === void 0 ? void 0 : waiting.settle(typeof value === 'string' ? value : undefined);
|
|
101
|
+
return waiting !== undefined;
|
|
102
|
+
}
|
|
103
|
+
async onStop() {
|
|
104
|
+
for (const waiting of [...this.waiting.values()]) {
|
|
105
|
+
waiting.settle(undefined);
|
|
106
|
+
}
|
|
107
|
+
await Promise.all([...this.hosts.keys()].map(host => this.disconnect(host)));
|
|
108
|
+
}
|
|
109
|
+
ask(host, question) {
|
|
110
|
+
const prompt = { promptId: randomUUID(), host, ...question };
|
|
111
|
+
return new Promise(resolve => {
|
|
112
|
+
const timer = setTimeout(() => settle(undefined), PROMPT_TIMEOUT_MS);
|
|
113
|
+
const settle = (value) => {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
if (this.waiting.delete(prompt.promptId)) {
|
|
116
|
+
this.broadcast({ type: 'prompt_closed', promptId: prompt.promptId });
|
|
117
|
+
resolve(value);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
this.waiting.set(prompt.promptId, { prompt, settle });
|
|
121
|
+
this.broadcast({ type: 'prompt', prompt });
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
broadcast(event) {
|
|
125
|
+
for (const connection of this.watchers) {
|
|
126
|
+
if (!connection.closed) {
|
|
127
|
+
connection
|
|
128
|
+
.client(TaClient)
|
|
129
|
+
.onRemoteEvent(event)
|
|
130
|
+
.catch(() => undefined);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
check(host) {
|
|
135
|
+
if (typeof host !== 'string' || !TaLocation.isHost(host)) {
|
|
136
|
+
throw TaErrors.invalidArgument(`${JSON.stringify(host)} is not a host.`, 'Name a Host of ~/.ssh/config, or [user@]host[:port].');
|
|
137
|
+
}
|
|
138
|
+
return host;
|
|
139
|
+
}
|
|
140
|
+
connected(host) {
|
|
141
|
+
var _a;
|
|
142
|
+
var _b;
|
|
143
|
+
return (_b = (_a = this.hosts.get(host)) === null || _a === void 0 ? void 0 : _a.client.connected) !== null && _b !== void 0 ? _b : false;
|
|
144
|
+
}
|
|
145
|
+
parse(location) {
|
|
146
|
+
try {
|
|
147
|
+
return TaLocation.parse(location);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw TaErrors.invalidArgument(error.message, 'Write ssh://<host>/<absolute path>.');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
__decorate([
|
|
155
|
+
Value(TA_REMOTE_OPTIONS),
|
|
156
|
+
__metadata("design:type", Object)
|
|
157
|
+
], DefaultRemoteHosts.prototype, "options", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
Value(CODING_AGENT_OPTIONS),
|
|
160
|
+
__metadata("design:type", Object)
|
|
161
|
+
], DefaultRemoteHosts.prototype, "codingAgentOptions", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
Autowired(TaWorkingDirectory),
|
|
164
|
+
__metadata("design:type", Object)
|
|
165
|
+
], DefaultRemoteHosts.prototype, "workingDirectory", void 0);
|
|
166
|
+
DefaultRemoteHosts = __decorate([
|
|
167
|
+
Component([RemoteHosts, ApplicationLifecycle])
|
|
168
|
+
], DefaultRemoteHosts);
|
|
169
|
+
export { DefaultRemoteHosts };
|
|
170
|
+
//# sourceMappingURL=remote-hosts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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EAAE,oBAAoB,CAAC,CAAC;GAClC,kBAAkB,CAiJ9B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import type { ExecClient } from '@celljs/ta-exec';
|
|
3
|
+
import type { TaForwardedPort, TaRemoteHost, TaRemotePrompt } from '@celljs/ta-protocol';
|
|
4
|
+
export declare const TA_REMOTE_OPTIONS = "ta.remote";
|
|
5
|
+
/** `ta.remote`: how ta serve reaches other machines. */
|
|
6
|
+
export interface TaRemoteOptions {
|
|
7
|
+
/** The ssh command; default `ssh`. */
|
|
8
|
+
ssh?: string;
|
|
9
|
+
/** Before each host, as `-F <file>`. */
|
|
10
|
+
sshArgs?: string[];
|
|
11
|
+
/** Where Node.js comes from for hosts without one; empty: nodejs.org. */
|
|
12
|
+
nodeMirror?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const RemoteHosts: unique symbol;
|
|
15
|
+
export declare const PiDirectories: unique symbol;
|
|
16
|
+
export declare const PortForwards: unique symbol;
|
|
17
|
+
/** The hosts of `ssh://` locations, one connection each, and what their ssh asks the users. */
|
|
18
|
+
export interface RemoteHosts {
|
|
19
|
+
/** The connection to a host, made on its first call. */
|
|
20
|
+
client(host: string): ExecClient;
|
|
21
|
+
list(): TaRemoteHost[];
|
|
22
|
+
/** Keeps a host in the list without connecting; throws for what is not a host. */
|
|
23
|
+
add(host: string): void;
|
|
24
|
+
/** Disconnects and drops it from the list of those opened before. */
|
|
25
|
+
remove(host: string): Promise<void>;
|
|
26
|
+
/** The location with the home directory as its path when it has none. */
|
|
27
|
+
resolve(location: string): Promise<string>;
|
|
28
|
+
disconnect(host: string): Promise<void>;
|
|
29
|
+
/** Runs once a host is disconnected on purpose. */
|
|
30
|
+
onDisconnect(listener: (host: string) => void): () => void;
|
|
31
|
+
/** The connection hears TaClient.onRemoteEvent; the prompts that wait now. */
|
|
32
|
+
watch(connection: RpcConnection): TaRemotePrompt[];
|
|
33
|
+
answer(promptId: string, value: string | null): boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The directory pi works in for a location. pi reads and writes this machine's files in it (its
|
|
37
|
+
* sessions are named after it, the project's settings are there), so a directory of another machine
|
|
38
|
+
* gets one here, empty, under `<agent directory>/remote/`; the agent's tools work there.
|
|
39
|
+
*/
|
|
40
|
+
export interface PiDirectories {
|
|
41
|
+
/** Creates it when it is not there. */
|
|
42
|
+
toPi(location: string): string;
|
|
43
|
+
/** The location of a directory that `toPi` gave; any other is a directory of this machine. */
|
|
44
|
+
fromPi(cwd: string): string;
|
|
45
|
+
}
|
|
46
|
+
/** Ports of other machines, opened on this one. */
|
|
47
|
+
export interface PortForwards {
|
|
48
|
+
forward(cwd: string, port: number): Promise<TaForwardedPort>;
|
|
49
|
+
list(): TaForwardedPort[];
|
|
50
|
+
close(host: string, remotePort: number): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-protocol.js","sourceRoot":"","sources":["../../../src/node/remote/remote-protocol.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAY7C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
2
|
+
import { type TaForwardedPort, type TaRemoteHost, type TaRemotePrompt, TaRemoteServer } from '@celljs/ta-protocol';
|
|
3
|
+
import { PortForwards, RemoteHosts } from './remote-protocol.js';
|
|
4
|
+
/** The other machines that conversations work on, for the clients. */
|
|
5
|
+
export declare class TaRemoteServerImpl implements TaRemoteServer {
|
|
6
|
+
protected readonly hosts: RemoteHosts;
|
|
7
|
+
protected readonly ports: PortForwards;
|
|
8
|
+
protected readonly environments: ExecEnvironmentFactory;
|
|
9
|
+
listHosts(): Promise<TaRemoteHost[]>;
|
|
10
|
+
addHost(host: string): Promise<void>;
|
|
11
|
+
removeHost(host: string): Promise<void>;
|
|
12
|
+
resolveLocation(location: string): Promise<string>;
|
|
13
|
+
forwardPort(port: number, cwd?: string): Promise<TaForwardedPort>;
|
|
14
|
+
listForwardedPorts(): Promise<TaForwardedPort[]>;
|
|
15
|
+
closeForwardedPort(host: string, remotePort: number): Promise<void>;
|
|
16
|
+
watch(): Promise<TaRemotePrompt[]>;
|
|
17
|
+
answer(promptId: string, value: string | null): Promise<boolean>;
|
|
18
|
+
disconnect(host: string): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { Autowired } from '@celljs/core';
|
|
11
|
+
import { Rpc } from '@celljs/rpc';
|
|
12
|
+
import { RpcContext } from '@celljs/rpc/lib/node';
|
|
13
|
+
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
14
|
+
import { TaRemoteServer } from '@celljs/ta-protocol';
|
|
15
|
+
import { TaErrors } from '../ta-errors.js';
|
|
16
|
+
import { PortForwards, RemoteHosts } from './remote-protocol.js';
|
|
17
|
+
/** The other machines that conversations work on, for the clients. */
|
|
18
|
+
let TaRemoteServerImpl = class TaRemoteServerImpl {
|
|
19
|
+
async listHosts() {
|
|
20
|
+
return TaErrors.guard(() => this.hosts.list());
|
|
21
|
+
}
|
|
22
|
+
addHost(host) {
|
|
23
|
+
return TaErrors.guard(() => this.hosts.add(host));
|
|
24
|
+
}
|
|
25
|
+
removeHost(host) {
|
|
26
|
+
return TaErrors.guard(() => this.hosts.remove(host));
|
|
27
|
+
}
|
|
28
|
+
resolveLocation(location) {
|
|
29
|
+
return TaErrors.guard(() => this.hosts.resolve(location));
|
|
30
|
+
}
|
|
31
|
+
forwardPort(port, cwd) {
|
|
32
|
+
return TaErrors.guard(async () => this.ports.forward(cwd || (await this.environments.defaultCwd()), port));
|
|
33
|
+
}
|
|
34
|
+
async listForwardedPorts() {
|
|
35
|
+
return this.ports.list();
|
|
36
|
+
}
|
|
37
|
+
closeForwardedPort(host, remotePort) {
|
|
38
|
+
return TaErrors.guard(() => this.ports.close(host, remotePort));
|
|
39
|
+
}
|
|
40
|
+
async watch() {
|
|
41
|
+
return this.hosts.watch(RpcContext.requireConnection());
|
|
42
|
+
}
|
|
43
|
+
async answer(promptId, value) {
|
|
44
|
+
return this.hosts.answer(promptId, value);
|
|
45
|
+
}
|
|
46
|
+
disconnect(host) {
|
|
47
|
+
return TaErrors.guard(() => this.hosts.disconnect(host));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
__decorate([
|
|
51
|
+
Autowired(RemoteHosts),
|
|
52
|
+
__metadata("design:type", Object)
|
|
53
|
+
], TaRemoteServerImpl.prototype, "hosts", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
Autowired(PortForwards),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], TaRemoteServerImpl.prototype, "ports", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
Autowired(ExecEnvironmentFactory),
|
|
60
|
+
__metadata("design:type", Object)
|
|
61
|
+
], TaRemoteServerImpl.prototype, "environments", void 0);
|
|
62
|
+
TaRemoteServerImpl = __decorate([
|
|
63
|
+
Rpc(TaRemoteServer)
|
|
64
|
+
], TaRemoteServerImpl);
|
|
65
|
+
export { TaRemoteServerImpl };
|
|
66
|
+
//# sourceMappingURL=remote-server-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-server-impl.js","sourceRoot":"","sources":["../../../src/node/remote/remote-server-impl.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAgE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9D,sEAAsE;AAE/D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAU3B,KAAK,CAAC,SAAS;QACX,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,UAAU,CAAC,IAAY;QACnB,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;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sB;AAR/C,kBAAkB;IAD9B,GAAG,CAAC,cAAc,CAAC;GACP,kBAAkB,CAiD9B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CodingAgentOptions, ModelRuntimeProvider } from '@celljs/ai-coding-agent';
|
|
2
2
|
import { type TaSettingSpec, type TaSettingsScope, type TaSettingsSnapshot } from '@celljs/ta-protocol';
|
|
3
3
|
import { TaSessionRegistry } from './host-protocol.js';
|
|
4
|
+
import { PiDirectories } from './remote/remote-protocol.js';
|
|
4
5
|
export declare const TaSettingsStore: unique symbol;
|
|
5
6
|
/** The settings of ta (TA_SETTINGS) in pi's `settings.json` of the user and of a project. */
|
|
6
7
|
export interface TaSettingsStore {
|
|
@@ -34,6 +35,7 @@ export declare class TaSettingsStoreImpl implements TaSettingsStore {
|
|
|
34
35
|
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
35
36
|
protected readonly modelRuntimeProvider: ModelRuntimeProvider;
|
|
36
37
|
protected readonly sessions: TaSessionRegistry;
|
|
38
|
+
protected readonly directories: PiDirectories;
|
|
37
39
|
/** One write at a time, so that two changes of one file both stay. */
|
|
38
40
|
protected writing: Promise<unknown>;
|
|
39
41
|
get(cwd: string): Promise<TaSettingsSnapshot>;
|
|
@@ -43,7 +45,7 @@ export declare class TaSettingsStoreImpl implements TaSettingsStore {
|
|
|
43
45
|
* `trusted`: pi's decision for the project, or false when it has resources pi asks about first;
|
|
44
46
|
* undefined when nobody decided and there is nothing to ask about, as pi trusts it then.
|
|
45
47
|
*/
|
|
46
|
-
protected files(
|
|
48
|
+
protected files(location: string): Promise<{
|
|
47
49
|
userFile: string;
|
|
48
50
|
projectFile: string;
|
|
49
51
|
trusted?: boolean;
|
|
@@ -13,6 +13,7 @@ import { CODING_AGENT_OPTIONS, ModelRuntimeProvider, PiSdkUtil } from '@celljs/a
|
|
|
13
13
|
import { Autowired, Component, Value } from '@celljs/core';
|
|
14
14
|
import { TA_SETTINGS } from '@celljs/ta-protocol';
|
|
15
15
|
import { TaSessionRegistry } from './host-protocol.js';
|
|
16
|
+
import { PiDirectories } from './remote/remote-protocol.js';
|
|
16
17
|
import { TaErrors } from './ta-errors.js';
|
|
17
18
|
export const TaSettingsStore = Symbol('TaSettingsStore');
|
|
18
19
|
export var TaSettingsUtil;
|
|
@@ -243,9 +244,11 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
243
244
|
* `trusted`: pi's decision for the project, or false when it has resources pi asks about first;
|
|
244
245
|
* undefined when nobody decided and there is nothing to ask about, as pi trusts it then.
|
|
245
246
|
*/
|
|
246
|
-
async files(
|
|
247
|
+
async files(location) {
|
|
247
248
|
var _a;
|
|
248
249
|
var _b;
|
|
250
|
+
// The project of a directory of another machine is the directory here that pi works in for it.
|
|
251
|
+
const cwd = this.directories.toPi(location);
|
|
249
252
|
const sdk = await PiSdkUtil.load();
|
|
250
253
|
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
|
|
251
254
|
const store = new sdk.ProjectTrustStore(agentDir);
|
|
@@ -277,7 +280,7 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
277
280
|
}
|
|
278
281
|
async reloadSessions(scope, cwd) {
|
|
279
282
|
for (const session of this.sessions.list()) {
|
|
280
|
-
if (scope === 'user' || session.
|
|
283
|
+
if (scope === 'user' || session.cwd === cwd) {
|
|
281
284
|
const manager = session.pi.settingsManager;
|
|
282
285
|
if (scope === 'project' && !manager.isProjectTrusted()) {
|
|
283
286
|
manager.setProjectTrusted(true);
|
|
@@ -299,6 +302,10 @@ __decorate([
|
|
|
299
302
|
Autowired(TaSessionRegistry),
|
|
300
303
|
__metadata("design:type", Object)
|
|
301
304
|
], TaSettingsStoreImpl.prototype, "sessions", void 0);
|
|
305
|
+
__decorate([
|
|
306
|
+
Autowired(PiDirectories),
|
|
307
|
+
__metadata("design:type", Object)
|
|
308
|
+
], TaSettingsStoreImpl.prototype, "directories", void 0);
|
|
302
309
|
TaSettingsStoreImpl = __decorate([
|
|
303
310
|
Component(TaSettingsStore)
|
|
304
311
|
], TaSettingsStoreImpl);
|