@treestructuredplanning/gateway 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -87
- package/dist/cli.js +29 -34
- package/dist/{shared-IOW65S5G.js → shared-KRIZBGVD.js} +169 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# TSP gateway
|
|
2
2
|
|
|
3
3
|
The TSP gateway lets the [Tree-Structured Planning](https://treestructuredplanning.com)
|
|
4
|
-
(TSP) canvas start, stop and
|
|
4
|
+
(TSP) canvas start, stop and continue Claude Code, Codex and Cursor sessions on your computer, in the
|
|
5
5
|
repository folders you register. It runs in the background under your own user account and
|
|
6
6
|
only connects outward to TSP.
|
|
7
7
|
|
|
@@ -17,81 +17,28 @@ only connects outward to TSP.
|
|
|
17
17
|
count for a repository inside it.
|
|
18
18
|
- On Linux, a running Secret Service such as GNOME Keyring or KWallet. The gateway will not
|
|
19
19
|
run without an OS credential store.
|
|
20
|
-
- Build must be available for your TSP account.
|
|
21
20
|
|
|
22
21
|
`connect` and `tsp-gateway status` say which harnesses can build in each folder and what is left to
|
|
23
22
|
you: installing or signing in to a harness, or accepting its trust prompt. Once one harness is ready
|
|
24
23
|
in a folder, steps for your other harnesses are optional.
|
|
25
24
|
|
|
26
|
-
## Connect
|
|
25
|
+
## Connect, disconnect and commands
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
Connecting, turning the gateway off, disconnecting, every command, what leaves your computer, and
|
|
28
|
+
stopping and continuing agents are documented on one page:
|
|
29
|
+
[Build on your machine](https://treestructuredplanning.com/docs/drive-with-your-agent/build-on-your-machine). Start there.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
npx -y @treestructuredplanning/gateway@latest connect
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
`connect [folder]` (the folder defaults to the current one) does the whole setup, and running
|
|
35
|
-
it again is safe:
|
|
36
|
-
|
|
37
|
-
1. It checks that the folder is a clone with a GitHub remote, so a wrong folder fails before
|
|
38
|
-
anything changes.
|
|
39
|
-
2. It pairs this computer with your TSP account, only after you approve in the browser window
|
|
40
|
-
it opens. It also prints the approval link in case no browser opens. A working pairing is
|
|
41
|
-
kept.
|
|
42
|
-
3. It registers the folder.
|
|
43
|
-
4. It installs a login item that starts the gateway when you log in.
|
|
44
|
-
5. It prints a short summary: which harnesses are ready in each folder, and the steps only you can
|
|
45
|
-
take (install a harness, sign in, or run it there once to accept its trust prompt). They are
|
|
46
|
-
required until one harness is ready, and optional after that.
|
|
47
|
-
|
|
48
|
-
Run outside any clone, `connect` keeps the folders already registered and repairs the rest,
|
|
49
|
-
so it also fixes a stopped, outdated or revoked gateway. If TSP cannot be reached, nothing
|
|
50
|
-
changes; try again later. The login item runs the copy of the gateway that `connect` ran
|
|
51
|
-
from. With `npx` that is npm's cache, so if you clear that cache, run `connect` again.
|
|
52
|
-
|
|
53
|
-
For Build to carry a change all the way, your agent needs to be able to commit, push and open a pull request. If your setup doesn't allow that, Build stops where your agent stops and you land the change yourself.
|
|
54
|
-
|
|
55
|
-
## Disconnect and uninstall
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
npx -y @treestructuredplanning/gateway@latest disconnect
|
|
59
|
-
```
|
|
31
|
+
## Remove it completely
|
|
60
32
|
|
|
61
|
-
`disconnect
|
|
62
|
-
its stored credential. Registered folders stay in the config file. If TSP cannot be reached,
|
|
63
|
-
the pairing is kept; run `disconnect` again. If the credential was already missing, the
|
|
64
|
-
computer may still be listed in TSP; remove it from Settings there.
|
|
65
|
-
|
|
66
|
-
To leave nothing behind, also delete the config and state folders listed under
|
|
33
|
+
After `disconnect`, delete the config and state folders listed under
|
|
67
34
|
[What it stores](#what-it-stores), and if you installed globally:
|
|
68
35
|
|
|
69
36
|
```sh
|
|
70
37
|
npm uninstall --global @treestructuredplanning/gateway
|
|
71
38
|
```
|
|
72
39
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
With a global install (`npm install --global @treestructuredplanning/gateway@latest`) the
|
|
76
|
-
command is `tsp-gateway`; with `npx`, use `npx -y @treestructuredplanning/gateway@latest`
|
|
77
|
-
in its place.
|
|
78
|
-
|
|
79
|
-
| Command | What it does |
|
|
80
|
-
| ----------------------------- | ------------------------------------------------------------------------------- |
|
|
81
|
-
| `connect [folder]` | Pair if needed, register the folder, install the login item, print a summary. |
|
|
82
|
-
| `disconnect` | Remove the login item, then unpair. |
|
|
83
|
-
| `pair` | Pair this computer with your TSP account (replaces any existing pairing). |
|
|
84
|
-
| `add <folder>` | Register a repository folder. |
|
|
85
|
-
| `remove <host/owner/name>` | Unregister a repository. |
|
|
86
|
-
| `configure-launch '<json>'` | Set how sessions get your shell environment (see below). |
|
|
87
|
-
| `configure-reporting <level>` | `activity` (default) or `off`: whether session activity is sent to TSP. |
|
|
88
|
-
| `status [--json]` | Show pairing, connection and each folder's next steps; `--json` is for scripts. |
|
|
89
|
-
| `start` | Run the gateway in the foreground. Ctrl-C stops it, not your sessions. |
|
|
90
|
-
| `install` | Install or refresh the login item. Run it again after upgrading the gateway. |
|
|
91
|
-
| `uninstall` | Remove the login item; keep the pairing and folders. |
|
|
92
|
-
| `unpair` | Revoke this computer's pairing in TSP and delete the stored credential. |
|
|
93
|
-
|
|
94
|
-
Registering or removing a folder takes effect in the running gateway without a restart.
|
|
40
|
+
The login item runs the copy of the gateway that `connect` ran from. With `npx` that is npm's
|
|
41
|
+
cache, so if you clear that cache, run `connect` again.
|
|
95
42
|
|
|
96
43
|
## What TSP can ask it to do
|
|
97
44
|
|
|
@@ -100,14 +47,14 @@ TSP can ask the gateway for exactly four things, and only in folders you registe
|
|
|
100
47
|
- **Launch** a Claude Code, Codex or Cursor session, with a prompt describing the TSP work you
|
|
101
48
|
started from the canvas.
|
|
102
49
|
- **Stop** that session.
|
|
103
|
-
- **
|
|
104
|
-
|
|
105
|
-
|
|
50
|
+
- **Continue** that session. A stopped session gets the fixed prompt
|
|
51
|
+
`Continue where you left off.`; a done or failed session reopens without a prompt and
|
|
52
|
+
waits for you.
|
|
106
53
|
- **Report status**: which harnesses are installed, signed in and trust each registered
|
|
107
54
|
folder, and how each launched session is doing.
|
|
108
55
|
|
|
109
56
|
Only your own clicks in TSP send a prompt. Claude Code and Codex sessions keep running if the
|
|
110
|
-
gateway stops; a Cursor session ends with the gateway, and
|
|
57
|
+
gateway stops; a Cursor session ends with the gateway, and Continue reopens its chat. A
|
|
111
58
|
session that finishes does not mean TSP has reviewed or accepted its work. Keep the
|
|
112
59
|
[TSP plugin](https://github.com/WebifyServices/tsp-plugin) installed so launched sessions
|
|
113
60
|
have TSP's tools.
|
|
@@ -134,22 +81,6 @@ child process for each running turn. It sends no mode, model, permission or sign
|
|
|
134
81
|
Cursor applies your own settings and permission rules, and the gateway starts a session only in a
|
|
135
82
|
folder you have already trusted.
|
|
136
83
|
|
|
137
|
-
## What leaves your computer
|
|
138
|
-
|
|
139
|
-
The gateway sends TSP only repository names (`owner/name`), which harnesses are available,
|
|
140
|
-
signed in and trusted per folder, and session status, including any waiting message with
|
|
141
|
-
folder paths removed. For each launched session it also sends what the session is doing
|
|
142
|
-
(reading, editing, running a command), when it was last active, and counts of files edited
|
|
143
|
-
and commands run; never file names or commands. When a Cursor turn finishes it also sends what
|
|
144
|
-
Cursor last said, trimmed to 240 characters with folder paths removed, so TSP can show it; no
|
|
145
|
-
other transcript text is sent. Folder paths, environment variables, command lines, transcripts
|
|
146
|
-
and raw error output stay on your computer. Run
|
|
147
|
-
`tsp-gateway configure-reporting off` to stop sending activity (`activity` turns it back on).
|
|
148
|
-
|
|
149
|
-
The gateway only connects outward, to TSP, and accepts no inbound connections. The only
|
|
150
|
-
exception is pairing: while you approve in the browser, it listens briefly on `127.0.0.1`
|
|
151
|
-
(your computer only) for the browser's reply, then stops.
|
|
152
|
-
|
|
153
84
|
## How sessions get your environment
|
|
154
85
|
|
|
155
86
|
By default, Claude Code sessions start through your login shell, so variables your shell
|
|
@@ -215,11 +146,6 @@ or choose `direct`. Changes apply to sessions started afterwards, not to running
|
|
|
215
146
|
On Windows, access to these folders follows your user profile's permissions. Delete the state
|
|
216
147
|
folder only after `disconnect`, once no gateway is running.
|
|
217
148
|
|
|
218
|
-
## Help
|
|
219
|
-
|
|
220
|
-
See the [TSP documentation](https://treestructuredplanning.com/docs) or email
|
|
221
|
-
`support@treestructuredplanning.com`.
|
|
222
|
-
|
|
223
149
|
Repository advertisements and launches use protocol 2, with an explicit host, owner and name. Upgrade a protocol 1 gateway when TSP shows the update state. Only `github.com` launches are supported. Existing local GitHub registrations are expanded and rewritten on the next config read.
|
|
224
150
|
|
|
225
151
|
## Attempt checkouts
|
|
@@ -260,3 +186,9 @@ refuses before copying it. Tracked destination files are never written. A local
|
|
|
260
186
|
named `tsp` blocks the `tsp/<attempt-id>` namespace and must be renamed by the user.
|
|
261
187
|
TSP never deletes worktrees or branches. Reusing an attempt never rebases its
|
|
262
188
|
branch; the reported base is its shared ancestor with the fetched landing line.
|
|
189
|
+
|
|
190
|
+
## Help
|
|
191
|
+
|
|
192
|
+
See the
|
|
193
|
+
[TSP documentation](https://treestructuredplanning.com/docs/drive-with-your-agent/build-on-your-machine)
|
|
194
|
+
or email `support@treestructuredplanning.com`.
|
package/dist/cli.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
isObject,
|
|
28
28
|
keychain,
|
|
29
29
|
locations,
|
|
30
|
-
|
|
30
|
+
loginItemHome,
|
|
31
31
|
parseJson,
|
|
32
32
|
parseRepositoryRemote,
|
|
33
33
|
printWorktreeRoots,
|
|
@@ -35,21 +35,21 @@ import {
|
|
|
35
35
|
readConfig,
|
|
36
36
|
readLaunchObservation,
|
|
37
37
|
recordConnectRoot,
|
|
38
|
+
registeredLines,
|
|
38
39
|
removeLoginItem,
|
|
39
40
|
repositoryFolders,
|
|
40
41
|
repositoryKey,
|
|
41
42
|
runDaemon,
|
|
42
43
|
saveConfig,
|
|
43
44
|
statusLines,
|
|
44
|
-
|
|
45
|
+
updateGateway,
|
|
45
46
|
validateOrigin,
|
|
46
47
|
watchConfig,
|
|
47
48
|
worktreesCommand
|
|
48
|
-
} from "./shared-
|
|
49
|
+
} from "./shared-KRIZBGVD.js";
|
|
49
50
|
|
|
50
51
|
// src/cli.ts
|
|
51
52
|
import { readFile } from "node:fs/promises";
|
|
52
|
-
import { homedir } from "node:os";
|
|
53
53
|
import { isAbsolute, join } from "node:path";
|
|
54
54
|
import { fileURLToPath } from "node:url";
|
|
55
55
|
import { parseArgs } from "node:util";
|
|
@@ -57,7 +57,7 @@ import { parseArgs } from "node:util";
|
|
|
57
57
|
// package.json
|
|
58
58
|
var package_default = {
|
|
59
59
|
name: "@treestructuredplanning/gateway",
|
|
60
|
-
version: "0.
|
|
60
|
+
version: "0.3.0",
|
|
61
61
|
description: "Outbound local harness gateway for Tree-Structured Planning",
|
|
62
62
|
type: "module",
|
|
63
63
|
engines: {
|
|
@@ -109,7 +109,7 @@ var package_default = {
|
|
|
109
109
|
// src/cli.ts
|
|
110
110
|
async function runLocal(loginPath, paths, config, version) {
|
|
111
111
|
const pairing = config.pairing;
|
|
112
|
-
if (!pairing) throw new Error("Run tsp-gateway
|
|
112
|
+
if (!pairing) throw new Error("Run tsp-gateway connect first.");
|
|
113
113
|
await privateDirectory(paths.state);
|
|
114
114
|
const release = await daemonLock(paths.state);
|
|
115
115
|
const abort = new AbortController();
|
|
@@ -178,6 +178,7 @@ async function readStatus(paths, config, drivers, executor, idle = "Not running"
|
|
|
178
178
|
if (isObject(status) && typeof field(status, "message") === "string")
|
|
179
179
|
lastMessage = field(status, "message");
|
|
180
180
|
} catch {
|
|
181
|
+
lastMessage = null;
|
|
181
182
|
}
|
|
182
183
|
return {
|
|
183
184
|
paired: config.pairing !== null,
|
|
@@ -194,9 +195,6 @@ async function readStatus(paths, config, drivers, executor, idle = "Not running"
|
|
|
194
195
|
reporting: config.reporting
|
|
195
196
|
};
|
|
196
197
|
}
|
|
197
|
-
function harnessName(drivers) {
|
|
198
|
-
return (harness) => drivers.get(harness).displayName;
|
|
199
|
-
}
|
|
200
198
|
async function printStatus(paths, config, drivers, executor, json) {
|
|
201
199
|
const status = await readStatus(paths, config, drivers, executor);
|
|
202
200
|
if (json) {
|
|
@@ -205,7 +203,7 @@ async function printStatus(paths, config, drivers, executor, json) {
|
|
|
205
203
|
}
|
|
206
204
|
const view = machineView(status);
|
|
207
205
|
const setups = await folderSetups(drivers, config, null, executor);
|
|
208
|
-
for (const line of statusLines(view, setups,
|
|
206
|
+
for (const line of statusLines(view, setups, drivers.displayName)) console.log(line);
|
|
209
207
|
}
|
|
210
208
|
function machineView(status) {
|
|
211
209
|
return {
|
|
@@ -217,7 +215,7 @@ function machineView(status) {
|
|
|
217
215
|
};
|
|
218
216
|
}
|
|
219
217
|
function startupOptions(args, version) {
|
|
220
|
-
const options = args[0] === "
|
|
218
|
+
const options = args[0] === "run" ? parseArgs({
|
|
221
219
|
args: args.slice(1),
|
|
222
220
|
options: {
|
|
223
221
|
"expected-version": { type: "string" },
|
|
@@ -227,7 +225,9 @@ function startupOptions(args, version) {
|
|
|
227
225
|
}
|
|
228
226
|
}).values : void 0;
|
|
229
227
|
if (options?.["expected-version"] !== void 0 && options["expected-version"] !== version)
|
|
230
|
-
throw new Error(
|
|
228
|
+
throw new Error(
|
|
229
|
+
"Installed gateway version changed. Run npx @treestructuredplanning/gateway@latest update."
|
|
230
|
+
);
|
|
231
231
|
const defaults = locations();
|
|
232
232
|
const paths = {
|
|
233
233
|
config: options?.["config-file"] ?? defaults.config,
|
|
@@ -279,7 +279,7 @@ var VERBS = {
|
|
|
279
279
|
outcome.loginItem === "installed" && reported === null ? "Starting" : void 0
|
|
280
280
|
);
|
|
281
281
|
const setups = await folderSetups(drivers, config, outcome.repository, executor);
|
|
282
|
-
for (const line of connectLines(machineView(status), setups,
|
|
282
|
+
for (const line of connectLines(machineView(status), setups, drivers.displayName))
|
|
283
283
|
console.log(line);
|
|
284
284
|
},
|
|
285
285
|
config: worktreesCommand,
|
|
@@ -288,19 +288,13 @@ var VERBS = {
|
|
|
288
288
|
if (args.length !== 1) throw new Error("Usage: tsp-gateway disconnect");
|
|
289
289
|
const outcome = await disconnect(host, config);
|
|
290
290
|
console.log(
|
|
291
|
-
`${outcome.loginItem === "removed" ? "Login item removed." : "No login item was installed."} ${outcome.pairing} Registered folders are kept.`
|
|
291
|
+
`${outcome.loginItem === "removed" ? "Login item removed." : "No login item was installed."} ${outcome.pairing} Registered folders are kept. Run tsp-gateway connect to reconnect.`
|
|
292
292
|
);
|
|
293
293
|
},
|
|
294
|
-
pair: async ({ host, config }) => {
|
|
295
|
-
await pairMachine(host, config);
|
|
296
|
-
console.log("Paired. Use tsp-gateway add <folder>, then tsp-gateway install.");
|
|
297
|
-
},
|
|
298
294
|
add: async ({ args, argument, host, config, drivers }) => {
|
|
299
295
|
if (!argument || args.length !== 2) throw new Error("Usage: tsp-gateway add <folder>");
|
|
300
296
|
const registered = await addRepository(host, config, argument);
|
|
301
|
-
console.log(
|
|
302
|
-
`Registered ${registered.slug}. ${drivers.setupInstructions().join(" ")} The running gateway picks up the change automatically.`
|
|
303
|
-
);
|
|
297
|
+
for (const line of registeredLines(registered, drivers)) console.log(line);
|
|
304
298
|
},
|
|
305
299
|
remove: async ({ argument, config, paths }) => {
|
|
306
300
|
const repository = argument ? parseRepositoryRemote(argument) : null;
|
|
@@ -317,32 +311,33 @@ var VERBS = {
|
|
|
317
311
|
throw new Error("Usage: tsp-gateway status [--json]");
|
|
318
312
|
return printStatus(paths, config, drivers, executor, json);
|
|
319
313
|
},
|
|
320
|
-
|
|
314
|
+
start: async ({ args, host, config, version }) => {
|
|
315
|
+
if (args.length !== 1) throw new Error("Usage: tsp-gateway start");
|
|
321
316
|
await installLoginItem(host, config);
|
|
322
|
-
console.log(`
|
|
317
|
+
console.log(`Started tsp-gateway ${version} now and at login.`);
|
|
323
318
|
},
|
|
324
|
-
|
|
319
|
+
stop: async ({ args, host }) => {
|
|
320
|
+
if (args.length !== 1) throw new Error("Usage: tsp-gateway stop");
|
|
325
321
|
console.log(
|
|
326
|
-
`${await removeLoginItem(host) === "removed" ? "Login item removed." : "No login item was installed."}
|
|
322
|
+
`${await removeLoginItem(host) === "removed" ? "Login item removed." : "No login item was installed."} The link and registered folders are kept.`
|
|
327
323
|
);
|
|
328
324
|
},
|
|
329
|
-
|
|
330
|
-
|
|
325
|
+
update: async ({ args, host, config }) => {
|
|
326
|
+
if (args.length !== 1) throw new Error("Usage: tsp-gateway update");
|
|
327
|
+
await updateGateway(host, config);
|
|
328
|
+
console.log("Gateway updated and restarted. The link and registered folders are kept.");
|
|
331
329
|
},
|
|
332
|
-
|
|
330
|
+
run: ({ loginPath, paths, config, version }) => runLocal(loginPath, paths, config, version)
|
|
333
331
|
};
|
|
334
332
|
function isVerbName(name) {
|
|
335
333
|
return Object.hasOwn(VERBS, name);
|
|
336
334
|
}
|
|
337
|
-
function verbNamed(name) {
|
|
338
|
-
return name !== void 0 && isVerbName(name) ? VERBS[name] : null;
|
|
339
|
-
}
|
|
340
335
|
async function main(args) {
|
|
341
336
|
const [command, argument] = args;
|
|
342
|
-
const verb =
|
|
337
|
+
const verb = command !== void 0 && isVerbName(command) ? VERBS[command] : null;
|
|
343
338
|
if (!verb) {
|
|
344
339
|
console.log(
|
|
345
|
-
"Usage: tsp-gateway connect [folder] | disconnect |
|
|
340
|
+
"Usage: tsp-gateway connect [folder] | disconnect | add <folder> | remove <slug> | configure-launch <json> | configure-reporting <activity|off> | status [--json] | worktrees (config) | start | stop | run | update\n\nstart: Start the background gateway now and at login.\nstop: Stop it and disable login startup; keep the link and folders.\nrun: Run the gateway in the foreground.\nupdate: Install the latest version and restart; keep the link and folders."
|
|
346
341
|
);
|
|
347
342
|
return;
|
|
348
343
|
}
|
|
@@ -372,7 +367,7 @@ async function main(args) {
|
|
|
372
367
|
entry: fileURLToPath(import.meta.url),
|
|
373
368
|
env: process.env,
|
|
374
369
|
platform: process.platform,
|
|
375
|
-
home:
|
|
370
|
+
home: loginItemHome(),
|
|
376
371
|
cwd: process.cwd(),
|
|
377
372
|
tokens: keychain,
|
|
378
373
|
openBrowser: openAuthorization,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// ../tsp-shared/src/generated/constants.ts
|
|
4
|
-
var GATEWAY_PACKAGE_VERSION = "0.
|
|
4
|
+
var GATEWAY_PACKAGE_VERSION = "0.3.0";
|
|
5
5
|
var GATEWAY_PROTOCOL_VERSION = 3;
|
|
6
6
|
var SESSION_ACTIVITY_COUNT_MAX = 1e6;
|
|
7
7
|
var AGENT_SESSION_STATE = {
|
|
@@ -544,7 +544,7 @@ function excludeLine(clone, root) {
|
|
|
544
544
|
|
|
545
545
|
// src/process.ts
|
|
546
546
|
import { spawn } from "node:child_process";
|
|
547
|
-
function execute(file, args, env, cwd) {
|
|
547
|
+
function execute(file, args, env, cwd, { timeoutMs = 3e4 } = {}) {
|
|
548
548
|
return new Promise((resolve13, reject) => {
|
|
549
549
|
const child = spawn(file, args, {
|
|
550
550
|
env,
|
|
@@ -556,7 +556,7 @@ function execute(file, args, env, cwd) {
|
|
|
556
556
|
const timer = setTimeout(() => {
|
|
557
557
|
child.kill();
|
|
558
558
|
reject(new Error("Local command timed out"));
|
|
559
|
-
},
|
|
559
|
+
}, timeoutMs);
|
|
560
560
|
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
561
561
|
stdout += chunk;
|
|
562
562
|
if (stdout.length > 4e6) {
|
|
@@ -1486,15 +1486,15 @@ var AcpDriver = class {
|
|
|
1486
1486
|
this.displayName = agent.displayName;
|
|
1487
1487
|
this.signInInstruction = agent.signInInstruction;
|
|
1488
1488
|
this.installInstruction = agent.installInstruction;
|
|
1489
|
-
this.repositorySetupInstruction = agent.repositorySetupInstruction;
|
|
1490
1489
|
this.unknownTrustAdmits = agent.unknownTrustAdmits;
|
|
1490
|
+
this.repositorySetup = (folder) => agent.repositorySetup(folder);
|
|
1491
1491
|
this.hold = /* @__PURE__ */ new Set([ACP_PERMISSION_METHOD, ...agent.holdMethods]);
|
|
1492
1492
|
}
|
|
1493
1493
|
displayName;
|
|
1494
1494
|
signInInstruction;
|
|
1495
1495
|
installInstruction;
|
|
1496
|
-
repositorySetupInstruction;
|
|
1497
1496
|
unknownTrustAdmits;
|
|
1497
|
+
repositorySetup;
|
|
1498
1498
|
sessions = /* @__PURE__ */ new Map();
|
|
1499
1499
|
stored = /* @__PURE__ */ new Map();
|
|
1500
1500
|
hold;
|
|
@@ -2324,6 +2324,11 @@ var ClaudeTrust = class {
|
|
|
2324
2324
|
}
|
|
2325
2325
|
};
|
|
2326
2326
|
|
|
2327
|
+
// src/folder-command.ts
|
|
2328
|
+
function inFolder(folder, program, platform = process.platform) {
|
|
2329
|
+
return platform === "win32" ? `Set-Location -LiteralPath '${folder.replace(/'/g, "''")}'; ${program}` : `cd '${folder.replace(/'/g, "'\\''")}' && ${program}`;
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2327
2332
|
// src/harness-executor.ts
|
|
2328
2333
|
import { spawn as spawn3 } from "node:child_process";
|
|
2329
2334
|
import { homedir as homedir5 } from "node:os";
|
|
@@ -2596,7 +2601,12 @@ var ClaudeDriver = class {
|
|
|
2596
2601
|
this.trust = trust ?? new ClaudeTrust((folder) => this.executor.environment(false, folder));
|
|
2597
2602
|
}
|
|
2598
2603
|
trust;
|
|
2599
|
-
|
|
2604
|
+
repositorySetup(folder) {
|
|
2605
|
+
return {
|
|
2606
|
+
instruction: "Run claude in the repository's folder once and accept its trust prompt.",
|
|
2607
|
+
command: inFolder(folder, "claude")
|
|
2608
|
+
};
|
|
2609
|
+
}
|
|
2600
2610
|
displayName = "Claude Code";
|
|
2601
2611
|
signInInstruction = "Run claude and sign in.";
|
|
2602
2612
|
installInstruction = "Install it with npm install --global @anthropic-ai/claude-code, then run connect again.";
|
|
@@ -3570,7 +3580,12 @@ var CodexDriver = class {
|
|
|
3570
3580
|
this.trust = new CodexTrust(executor);
|
|
3571
3581
|
this.timeouts = { ...CODEX_TIMEOUTS, ...timeouts };
|
|
3572
3582
|
}
|
|
3573
|
-
|
|
3583
|
+
repositorySetup(folder) {
|
|
3584
|
+
return {
|
|
3585
|
+
instruction: "Run codex in the repository's folder once and accept its trust prompt.",
|
|
3586
|
+
command: inFolder(folder, "codex")
|
|
3587
|
+
};
|
|
3588
|
+
}
|
|
3574
3589
|
displayName = "Codex";
|
|
3575
3590
|
signInInstruction = "Run codex login and sign in.";
|
|
3576
3591
|
installInstruction = `Install Codex ${MINIMUM_CODEX_VERSION} or newer with npm install --global @openai/codex, then run connect again.`;
|
|
@@ -3820,7 +3835,7 @@ var CodexDriver = class {
|
|
|
3820
3835
|
// src/cursor-agent.ts
|
|
3821
3836
|
import { open as open5, realpath as realpath7 } from "node:fs/promises";
|
|
3822
3837
|
import { homedir as homedir8 } from "node:os";
|
|
3823
|
-
import { join as join8 } from "node:path";
|
|
3838
|
+
import { basename as basename4, dirname as dirname4, join as join8 } from "node:path";
|
|
3824
3839
|
var MINIMUM_CURSOR_VERSION = "2026.10.19";
|
|
3825
3840
|
var MAX_RECORD_BYTES = 64 * 1024;
|
|
3826
3841
|
function supportedVersion(version) {
|
|
@@ -3842,7 +3857,12 @@ var CursorAgent = class {
|
|
|
3842
3857
|
executable = "agent";
|
|
3843
3858
|
args = ["acp"];
|
|
3844
3859
|
holdMethods = ["cursor/ask_question", "cursor/create_plan"];
|
|
3845
|
-
|
|
3860
|
+
repositorySetup(folder) {
|
|
3861
|
+
return {
|
|
3862
|
+
instruction: "Run agent in the repository's folder once and trust the workspace when it asks.",
|
|
3863
|
+
command: inFolder(folder, "agent")
|
|
3864
|
+
};
|
|
3865
|
+
}
|
|
3846
3866
|
signInInstruction = "Run agent login and sign in.";
|
|
3847
3867
|
installInstruction = `Install the Cursor CLI ${MINIMUM_CURSOR_VERSION} or newer with curl https://cursor.com/install -fsS | bash, then run connect again.`;
|
|
3848
3868
|
/** ACP has no trust gate of its own, so an undecided folder is a step to take, not a launch to admit. */
|
|
@@ -3858,24 +3878,41 @@ var CursorAgent = class {
|
|
|
3858
3878
|
probe.signedIn = /not logged in|not authenticated|login required/i.test(text4) ? false : status.code === 0 && /logged in/i.test(text4) ? true : null;
|
|
3859
3879
|
return probe;
|
|
3860
3880
|
}
|
|
3881
|
+
/**
|
|
3882
|
+
* The folder's own record, then, for a linked worktree, its main repository's: the
|
|
3883
|
+
* gateway's attempt worktrees are new folders no one can have trusted ahead of time.
|
|
3884
|
+
*/
|
|
3861
3885
|
async trust(executor, folder) {
|
|
3862
3886
|
try {
|
|
3863
3887
|
const env = await executor.environment(false, folder);
|
|
3864
3888
|
const root = env["CURSOR_CONFIG_DIR"] ?? join8(env["HOME"] ?? homedir8(), ".cursor");
|
|
3865
|
-
const
|
|
3866
|
-
for (const spelling of /* @__PURE__ */ new Set([canonical2, folder])) {
|
|
3889
|
+
const trusted = async (spelling) => {
|
|
3867
3890
|
const record = await readRecord(
|
|
3868
3891
|
join8(root, "projects", cursorProjectKey(spelling), ".workspace-trusted")
|
|
3869
3892
|
);
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3893
|
+
return isObject(record) && field(record, "workspacePath") === spelling;
|
|
3894
|
+
};
|
|
3895
|
+
for (const spelling of /* @__PURE__ */ new Set([await realpath7(folder), folder]))
|
|
3896
|
+
if (await trusted(spelling)) return "trusted";
|
|
3897
|
+
const main = await mainRepository(executor, folder);
|
|
3898
|
+
return main && await trusted(main) ? "trusted" : "unknown";
|
|
3874
3899
|
} catch {
|
|
3875
3900
|
return "unknown";
|
|
3876
3901
|
}
|
|
3877
3902
|
}
|
|
3878
3903
|
};
|
|
3904
|
+
async function mainRepository(executor, folder) {
|
|
3905
|
+
const common = await executor.execute(
|
|
3906
|
+
"git",
|
|
3907
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
3908
|
+
"read",
|
|
3909
|
+
folder
|
|
3910
|
+
);
|
|
3911
|
+
const commonDir = common.code === 0 ? common.stdout.trim() : "";
|
|
3912
|
+
if (basename4(commonDir) !== ".git") return null;
|
|
3913
|
+
const main = await realpath7(dirname4(commonDir));
|
|
3914
|
+
return main === await realpath7(folder) ? null : main;
|
|
3915
|
+
}
|
|
3879
3916
|
async function readRecord(path) {
|
|
3880
3917
|
try {
|
|
3881
3918
|
const file = await open5(path, "r");
|
|
@@ -3914,8 +3951,13 @@ var HarnessRegistry = class {
|
|
|
3914
3951
|
if (detection.signed_in === false) throw new HarnessRefusal("not_signed_in");
|
|
3915
3952
|
return driver;
|
|
3916
3953
|
}
|
|
3917
|
-
|
|
3918
|
-
|
|
3954
|
+
/** A harness's name as a person knows it, such as "Claude Code". */
|
|
3955
|
+
displayName = (harness) => this.get(harness).displayName;
|
|
3956
|
+
/** Every harness's one-time step for a newly registered folder. */
|
|
3957
|
+
repositorySetups(folder) {
|
|
3958
|
+
return Object.entries(this.drivers).map(
|
|
3959
|
+
([harness, driver]) => ({ harness, ...driver.repositorySetup(folder) })
|
|
3960
|
+
);
|
|
3919
3961
|
}
|
|
3920
3962
|
async detect() {
|
|
3921
3963
|
return Promise.all(Object.values(this.drivers).map((driver) => driver.detect()));
|
|
@@ -4068,12 +4110,12 @@ function fetchFailureCause(stderr) {
|
|
|
4068
4110
|
|
|
4069
4111
|
// src/checkout.ts
|
|
4070
4112
|
import { access as access2, appendFile as appendFile2, constants as constants4, mkdir as mkdir3, readFile as readFile4, realpath as realpath11 } from "node:fs/promises";
|
|
4071
|
-
import { dirname as
|
|
4113
|
+
import { dirname as dirname6, resolve as resolve10 } from "node:path";
|
|
4072
4114
|
|
|
4073
4115
|
// src/checkout-includes.ts
|
|
4074
4116
|
import { constants as constants3 } from "node:fs";
|
|
4075
4117
|
import { appendFile, copyFile, lstat, mkdir as mkdir2, readFile as readFile3, realpath as realpath9 } from "node:fs/promises";
|
|
4076
|
-
import { dirname as
|
|
4118
|
+
import { dirname as dirname5, posix as posix2, resolve as resolve8 } from "node:path";
|
|
4077
4119
|
async function copyIncluded(git, folder, requireLive, prefix = "") {
|
|
4078
4120
|
const include = resolve8(git.clone, ".worktreeinclude");
|
|
4079
4121
|
try {
|
|
@@ -4112,7 +4154,7 @@ async function copyIncluded(git, folder, requireLive, prefix = "") {
|
|
|
4112
4154
|
if (tracked.code !== 1) throw new Error("Cannot check included destination index");
|
|
4113
4155
|
await ensureIgnored(git, folder, destinationName, requireLive);
|
|
4114
4156
|
requireLive();
|
|
4115
|
-
await mkdir2(
|
|
4157
|
+
await mkdir2(dirname5(destination), { recursive: true });
|
|
4116
4158
|
requireLive();
|
|
4117
4159
|
await copyFile(source2, destination, constants3.COPYFILE_EXCL).catch((error) => {
|
|
4118
4160
|
if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
|
|
@@ -4121,7 +4163,7 @@ async function copyIncluded(git, folder, requireLive, prefix = "") {
|
|
|
4121
4163
|
}
|
|
4122
4164
|
}
|
|
4123
4165
|
async function checkDestination(destinationRoot, destination) {
|
|
4124
|
-
let parent =
|
|
4166
|
+
let parent = dirname5(destination);
|
|
4125
4167
|
while (parent !== destinationRoot) {
|
|
4126
4168
|
try {
|
|
4127
4169
|
if (!inside(destinationRoot, await realpath9(parent)))
|
|
@@ -4131,7 +4173,7 @@ async function checkDestination(destinationRoot, destination) {
|
|
|
4131
4173
|
if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
|
|
4132
4174
|
throw error;
|
|
4133
4175
|
}
|
|
4134
|
-
parent =
|
|
4176
|
+
parent = dirname5(parent);
|
|
4135
4177
|
}
|
|
4136
4178
|
try {
|
|
4137
4179
|
if ((await lstat(destination)).isSymbolicLink())
|
|
@@ -4153,7 +4195,7 @@ async function ensureIgnored(git, folder, name, requireLive) {
|
|
|
4153
4195
|
const line = `/${name.replace(/[\\*?[\] ]/g, "\\$&")}`;
|
|
4154
4196
|
if (!contents.split(/\r?\n/).includes(line)) {
|
|
4155
4197
|
requireLive();
|
|
4156
|
-
await mkdir2(
|
|
4198
|
+
await mkdir2(dirname5(exclude), { recursive: true });
|
|
4157
4199
|
requireLive();
|
|
4158
4200
|
await appendFile(exclude, `${contents && !contents.endsWith("\n") ? "\n" : ""}${line}
|
|
4159
4201
|
`);
|
|
@@ -4301,7 +4343,7 @@ var CheckoutPreparer = class {
|
|
|
4301
4343
|
if (!previous.worktreeFolder) throw new Error("Missing worktree root");
|
|
4302
4344
|
const location = previous.location ?? "in_clone";
|
|
4303
4345
|
root = {
|
|
4304
|
-
folder:
|
|
4346
|
+
folder: dirname6(previous.worktreeFolder),
|
|
4305
4347
|
location,
|
|
4306
4348
|
setting: await this.previousSetting(clone, location)
|
|
4307
4349
|
};
|
|
@@ -4461,7 +4503,7 @@ async function prepareRoot(git, root, top, requireLive) {
|
|
|
4461
4503
|
});
|
|
4462
4504
|
if (contents.split(/\r?\n/).includes(line)) return;
|
|
4463
4505
|
requireLive();
|
|
4464
|
-
await mkdir3(
|
|
4506
|
+
await mkdir3(dirname6(exclude), { recursive: true });
|
|
4465
4507
|
requireLive();
|
|
4466
4508
|
await appendFile2(exclude, `${contents.endsWith("\n") || !contents ? "" : "\n"}${line}
|
|
4467
4509
|
`);
|
|
@@ -4737,7 +4779,7 @@ var CommandLifetimes = class {
|
|
|
4737
4779
|
// src/journal.ts
|
|
4738
4780
|
import { createHash } from "node:crypto";
|
|
4739
4781
|
import { open as open6, readFile as readFile5, truncate } from "node:fs/promises";
|
|
4740
|
-
import { dirname as
|
|
4782
|
+
import { dirname as dirname7 } from "node:path";
|
|
4741
4783
|
|
|
4742
4784
|
// src/journal-codec.ts
|
|
4743
4785
|
import { isAbsolute as isAbsolute9 } from "node:path";
|
|
@@ -4976,7 +5018,7 @@ var Journal = class {
|
|
|
4976
5018
|
unreadableCommandIds = /* @__PURE__ */ new Set();
|
|
4977
5019
|
unreadableRows = [];
|
|
4978
5020
|
async load(folders = {}) {
|
|
4979
|
-
await privateDirectory(
|
|
5021
|
+
await privateDirectory(dirname7(this.path));
|
|
4980
5022
|
let bytes;
|
|
4981
5023
|
try {
|
|
4982
5024
|
bytes = await readFile5(this.path);
|
|
@@ -5677,7 +5719,7 @@ var Commands = class {
|
|
|
5677
5719
|
|
|
5678
5720
|
// src/config-watch.ts
|
|
5679
5721
|
import { statSync, watch } from "node:fs";
|
|
5680
|
-
import { basename as
|
|
5722
|
+
import { basename as basename5, dirname as dirname8 } from "node:path";
|
|
5681
5723
|
var watchDirectory = (directory, listener) => watch(directory, (_, filename) => listener(filename));
|
|
5682
5724
|
function watchConfig(path, changed, options = {}) {
|
|
5683
5725
|
let reported = identity(path);
|
|
@@ -5698,8 +5740,8 @@ function watchConfig(path, changed, options = {}) {
|
|
|
5698
5740
|
if (pending === void 0 && identity(path) !== reported) settle();
|
|
5699
5741
|
}, options.pollMs ?? 1e3);
|
|
5700
5742
|
try {
|
|
5701
|
-
watcher = (options.watchDirectory ?? watchDirectory)(
|
|
5702
|
-
if (filename === null || filename ===
|
|
5743
|
+
watcher = (options.watchDirectory ?? watchDirectory)(dirname8(path), (filename) => {
|
|
5744
|
+
if (filename === null || filename === basename5(path)) settle();
|
|
5703
5745
|
});
|
|
5704
5746
|
watcher.on("error", () => watcher?.close());
|
|
5705
5747
|
} catch {
|
|
@@ -6093,7 +6135,7 @@ var OAuthTokens = class {
|
|
|
6093
6135
|
if (!force && this.current && this.current.expiresAt > Date.now() + 3e4)
|
|
6094
6136
|
return this.current;
|
|
6095
6137
|
const refresh = await this.store.get();
|
|
6096
|
-
if (!refresh) throw new TokenAccessDenied("No gateway token. Run tsp-gateway
|
|
6138
|
+
if (!refresh) throw new TokenAccessDenied("No gateway token. Run tsp-gateway connect.");
|
|
6097
6139
|
const endpoints = await discover(this.pairing.origin);
|
|
6098
6140
|
const tokens = await tokenExchange(
|
|
6099
6141
|
endpoints.token,
|
|
@@ -6407,7 +6449,7 @@ async function accessToken(options, state, handover) {
|
|
|
6407
6449
|
if (options.signal.aborted) return "exit";
|
|
6408
6450
|
if (error instanceof TokenAccessDenied) {
|
|
6409
6451
|
await handover.predecessor?.retire();
|
|
6410
|
-
await state.status(false, "Token refresh failed. Run tsp-gateway
|
|
6452
|
+
await state.status(false, "Token refresh failed. Run tsp-gateway connect again.");
|
|
6411
6453
|
return "halt";
|
|
6412
6454
|
}
|
|
6413
6455
|
if (!handover.predecessor)
|
|
@@ -6430,18 +6472,21 @@ async function afterClose(options, state, result, handover) {
|
|
|
6430
6472
|
if (recovery === "outdated") {
|
|
6431
6473
|
await state.status(
|
|
6432
6474
|
false,
|
|
6433
|
-
"This gateway is outdated. Run
|
|
6475
|
+
"This gateway is outdated. Run npx @treestructuredplanning/gateway@latest update."
|
|
6434
6476
|
);
|
|
6435
6477
|
await state.pause(OUTDATED_RETRY_MS);
|
|
6436
6478
|
return "retry";
|
|
6437
6479
|
}
|
|
6438
6480
|
if (recovery === "terminal") {
|
|
6439
|
-
await state.status(false, "Machine access ended. Run tsp-gateway
|
|
6481
|
+
await state.status(false, "Machine access ended. Run tsp-gateway connect again.");
|
|
6440
6482
|
return "halt";
|
|
6441
6483
|
}
|
|
6442
6484
|
if (recovery === "token") {
|
|
6443
6485
|
if (state.rejectedToken) {
|
|
6444
|
-
await state.status(
|
|
6486
|
+
await state.status(
|
|
6487
|
+
false,
|
|
6488
|
+
"Token rejected after refresh. Run tsp-gateway connect again."
|
|
6489
|
+
);
|
|
6445
6490
|
return "halt";
|
|
6446
6491
|
}
|
|
6447
6492
|
state.rejectedToken = true;
|
|
@@ -6601,26 +6646,10 @@ function readLaunchObservation(value) {
|
|
|
6601
6646
|
return { effective_mode: mode, shell, reason };
|
|
6602
6647
|
}
|
|
6603
6648
|
|
|
6604
|
-
// src/keychain.ts
|
|
6605
|
-
import { AsyncEntry } from "@napi-rs/keyring";
|
|
6606
|
-
function keychainOptions(platform = process.platform) {
|
|
6607
|
-
return platform === "linux" ? { linux: { store: "secret-service" } } : {};
|
|
6608
|
-
}
|
|
6609
|
-
function keychain(account) {
|
|
6610
|
-
const entry = new AsyncEntry("com.treestructuredplanning.gateway", account, keychainOptions());
|
|
6611
|
-
return {
|
|
6612
|
-
get: () => entry.getPassword(),
|
|
6613
|
-
set: (token) => entry.setPassword(token),
|
|
6614
|
-
delete: async () => {
|
|
6615
|
-
await entry.deletePassword();
|
|
6616
|
-
}
|
|
6617
|
-
};
|
|
6618
|
-
}
|
|
6619
|
-
|
|
6620
6649
|
// src/installer.ts
|
|
6621
6650
|
import { readFile as readFile7, rm as rm2 } from "node:fs/promises";
|
|
6622
6651
|
import { homedir as homedir9, userInfo as userInfo2 } from "node:os";
|
|
6623
|
-
import { dirname as
|
|
6652
|
+
import { dirname as dirname9, isAbsolute as isAbsolute10, join as join10, win32 } from "node:path";
|
|
6624
6653
|
var label = "com.treestructuredplanning.tsp-gateway";
|
|
6625
6654
|
function xml(value) {
|
|
6626
6655
|
return value.replace(
|
|
@@ -6643,7 +6672,7 @@ function installDefinition(platform, spec) {
|
|
|
6643
6672
|
const args = [
|
|
6644
6673
|
spec.node,
|
|
6645
6674
|
spec.entry,
|
|
6646
|
-
"
|
|
6675
|
+
"run",
|
|
6647
6676
|
"--expected-version",
|
|
6648
6677
|
spec.version,
|
|
6649
6678
|
"--config-file",
|
|
@@ -6681,7 +6710,7 @@ WantedBy=default.target
|
|
|
6681
6710
|
`;
|
|
6682
6711
|
if (platform === "win32")
|
|
6683
6712
|
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
6684
|
-
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><RegistrationInfo><Description>TSP gateway ${xml(spec.version)}</Description></RegistrationInfo><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(spec.user ?? userInfo2().username)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(spec.user ?? userInfo2().username)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(spec.node)}</Command><Arguments>${xml(args.slice(1).map(quoted).join(" "))}</Arguments><WorkingDirectory>${xml(win32.isAbsolute(spec.entry) ? win32.dirname(spec.entry) :
|
|
6713
|
+
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><RegistrationInfo><Description>TSP gateway ${xml(spec.version)}</Description></RegistrationInfo><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(spec.user ?? userInfo2().username)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(spec.user ?? userInfo2().username)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(spec.node)}</Command><Arguments>${xml(args.slice(1).map(quoted).join(" "))}</Arguments><WorkingDirectory>${xml(win32.isAbsolute(spec.entry) ? win32.dirname(spec.entry) : dirname9(spec.entry))}</WorkingDirectory></Exec></Actions></Task>
|
|
6685
6714
|
`;
|
|
6686
6715
|
throw new Error("Login items support macOS, Linux and Windows");
|
|
6687
6716
|
}
|
|
@@ -6701,7 +6730,10 @@ async function captureLoginPath(env = process.env, platform = process.platform,
|
|
|
6701
6730
|
if (!path || /[\r\n\0]/.test(path)) throw new Error("Could not capture login-shell PATH");
|
|
6702
6731
|
return path;
|
|
6703
6732
|
}
|
|
6704
|
-
function
|
|
6733
|
+
function loginItemHome(env = process.env, home = homedir9()) {
|
|
6734
|
+
return env["TSP_GATEWAY_LOGIN_ITEM_HOME"] || home;
|
|
6735
|
+
}
|
|
6736
|
+
function installPath(platform, state, home = loginItemHome()) {
|
|
6705
6737
|
if (platform === "darwin") return join10(home, "Library", "LaunchAgents", `${label}.plist`);
|
|
6706
6738
|
if (platform === "linux")
|
|
6707
6739
|
return join10(home, ".config", "systemd", "user", "tsp-gateway.service");
|
|
@@ -6738,11 +6770,11 @@ async function systemCommand(file, args) {
|
|
|
6738
6770
|
if (result.code !== 0)
|
|
6739
6771
|
throw new Error(`Could not update login item (${file}, exit ${result.code})`);
|
|
6740
6772
|
}
|
|
6741
|
-
async function install(spec, platform = process.platform, home =
|
|
6773
|
+
async function install(spec, platform = process.platform, home = loginItemHome()) {
|
|
6742
6774
|
const destination = installPath(platform, spec.state, home);
|
|
6743
6775
|
await privateDirectory(spec.state);
|
|
6744
6776
|
await import("node:fs/promises").then(
|
|
6745
|
-
(fs) => fs.mkdir(
|
|
6777
|
+
(fs) => fs.mkdir(dirname9(destination), { recursive: true })
|
|
6746
6778
|
);
|
|
6747
6779
|
const definition = installDefinition(platform, spec);
|
|
6748
6780
|
if (platform === "win32") {
|
|
@@ -6767,7 +6799,7 @@ async function install(spec, platform = process.platform, home = homedir9()) {
|
|
|
6767
6799
|
}
|
|
6768
6800
|
await privateWrite(join10(spec.state, "installation.json"), JSON.stringify(spec));
|
|
6769
6801
|
}
|
|
6770
|
-
async function uninstall(state, platform = process.platform, home =
|
|
6802
|
+
async function uninstall(state, platform = process.platform, home = loginItemHome()) {
|
|
6771
6803
|
const destination = installPath(platform, state, home);
|
|
6772
6804
|
try {
|
|
6773
6805
|
await readFile7(destination);
|
|
@@ -6787,7 +6819,7 @@ async function uninstall(state, platform = process.platform, home = homedir9())
|
|
|
6787
6819
|
await rm2(join10(state, "installation.json"), { force: true });
|
|
6788
6820
|
return true;
|
|
6789
6821
|
}
|
|
6790
|
-
async function loginItemCurrent(spec, platform = process.platform, home =
|
|
6822
|
+
async function loginItemCurrent(spec, platform = process.platform, home = loginItemHome()) {
|
|
6791
6823
|
try {
|
|
6792
6824
|
const recorded = parseJson(await readFile7(join10(spec.state, "installation.json"), "utf8"));
|
|
6793
6825
|
await readFile7(installPath(platform, spec.state, home));
|
|
@@ -6800,7 +6832,25 @@ async function loginItemCurrent(spec, platform = process.platform, home = homedi
|
|
|
6800
6832
|
return running2(platform);
|
|
6801
6833
|
}
|
|
6802
6834
|
|
|
6835
|
+
// src/keychain.ts
|
|
6836
|
+
import { AsyncEntry } from "@napi-rs/keyring";
|
|
6837
|
+
function keychainOptions(platform = process.platform) {
|
|
6838
|
+
return platform === "linux" ? { linux: { store: "secret-service" } } : {};
|
|
6839
|
+
}
|
|
6840
|
+
function keychain(account) {
|
|
6841
|
+
const entry = new AsyncEntry("com.treestructuredplanning.gateway", account, keychainOptions());
|
|
6842
|
+
return {
|
|
6843
|
+
get: () => entry.getPassword(),
|
|
6844
|
+
set: (token) => entry.setPassword(token),
|
|
6845
|
+
delete: async () => {
|
|
6846
|
+
await entry.deletePassword();
|
|
6847
|
+
}
|
|
6848
|
+
};
|
|
6849
|
+
}
|
|
6850
|
+
|
|
6803
6851
|
// src/setup.ts
|
|
6852
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
6853
|
+
import { dirname as dirname10, join as join11 } from "node:path";
|
|
6804
6854
|
async function pairMachine(host, config) {
|
|
6805
6855
|
const pairing = await pair(
|
|
6806
6856
|
host.origin,
|
|
@@ -6828,7 +6878,7 @@ async function addRepository(host, config, folder) {
|
|
|
6828
6878
|
return saveRepository(host, config, await registerFolder(folder, host.env));
|
|
6829
6879
|
}
|
|
6830
6880
|
async function installLoginItem(host, config, refresh = "always") {
|
|
6831
|
-
if (!config.pairing) throw new Error("Run tsp-gateway
|
|
6881
|
+
if (!config.pairing) throw new Error("Run tsp-gateway connect first.");
|
|
6832
6882
|
const path = await captureLoginPath(host.env, host.platform, config.launch);
|
|
6833
6883
|
const spec = {
|
|
6834
6884
|
node: host.node,
|
|
@@ -6845,6 +6895,33 @@ async function installLoginItem(host, config, refresh = "always") {
|
|
|
6845
6895
|
await install(spec, host.platform, host.home);
|
|
6846
6896
|
return "installed";
|
|
6847
6897
|
}
|
|
6898
|
+
var PACKAGE_INSTALL_TIMEOUT_MS = 6e5;
|
|
6899
|
+
async function updateGateway(host, config, run2 = execute) {
|
|
6900
|
+
if (!config.pairing) throw new Error("Run tsp-gateway connect first.");
|
|
6901
|
+
let latest = host;
|
|
6902
|
+
const npm = host.platform === "win32" ? host.node : "npm";
|
|
6903
|
+
const npmArgs = host.platform === "win32" ? [join11(dirname10(host.node), "node_modules", "npm", "bin", "npm-cli.js")] : [];
|
|
6904
|
+
if (!host.entry.split(/[\\/]/).includes("_npx")) {
|
|
6905
|
+
const installed = await run2(
|
|
6906
|
+
npm,
|
|
6907
|
+
[...npmArgs, "install", "--global", "@treestructuredplanning/gateway@latest"],
|
|
6908
|
+
host.env,
|
|
6909
|
+
void 0,
|
|
6910
|
+
{ timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS }
|
|
6911
|
+
);
|
|
6912
|
+
if (installed.code !== 0) throw new Error("Could not install the latest gateway.");
|
|
6913
|
+
const root = await run2(npm, [...npmArgs, "root", "--global"], host.env);
|
|
6914
|
+
if (root.code !== 0 || !root.stdout.trim())
|
|
6915
|
+
throw new Error("Could not locate the updated gateway.");
|
|
6916
|
+
const folder = join11(root.stdout.trim(), "@treestructuredplanning", "gateway");
|
|
6917
|
+
const manifest = parseJson(await readFile8(join11(folder, "package.json"), "utf8"));
|
|
6918
|
+
const version = isObject(manifest) ? field(manifest, "version") : null;
|
|
6919
|
+
if (typeof version !== "string" || !version)
|
|
6920
|
+
throw new Error("Updated gateway has no version.");
|
|
6921
|
+
latest = { ...host, entry: join11(folder, "dist", "cli.js"), version };
|
|
6922
|
+
}
|
|
6923
|
+
await installLoginItem(latest, config);
|
|
6924
|
+
}
|
|
6848
6925
|
async function removeLoginItem(host) {
|
|
6849
6926
|
return await uninstall(host.paths.state, host.platform, host.home) ? "removed" : "absent";
|
|
6850
6927
|
}
|
|
@@ -6921,10 +6998,13 @@ async function folderSetups(drivers, config, repository, executor) {
|
|
|
6921
6998
|
for (const row of found) {
|
|
6922
6999
|
const driver = drivers.get(row.harness);
|
|
6923
7000
|
const own = [];
|
|
6924
|
-
if (row.signed_in !== true)
|
|
6925
|
-
|
|
7001
|
+
if (row.signed_in !== true)
|
|
7002
|
+
own.push({ harness: row.harness, instruction: driver.signInInstruction });
|
|
7003
|
+
const folder = folders[slug];
|
|
7004
|
+
if (folder && trustIsStep(row.trust, driver))
|
|
7005
|
+
own.push({ harness: row.harness, ...driver.repositorySetup(folder) });
|
|
6926
7006
|
if (own.length === 0) ready.push(row.harness);
|
|
6927
|
-
steps.push(...own
|
|
7007
|
+
steps.push(...own);
|
|
6928
7008
|
}
|
|
6929
7009
|
setups.push(
|
|
6930
7010
|
ready.length > 0 ? { slug, ready, required: [], optional: steps } : { slug, ready, required: steps, optional: [] }
|
|
@@ -6961,7 +7041,10 @@ function sentence(text4) {
|
|
|
6961
7041
|
return text4.replace(/\.+$/, "") + ".";
|
|
6962
7042
|
}
|
|
6963
7043
|
function stepLines(steps, lead, name) {
|
|
6964
|
-
return steps.
|
|
7044
|
+
return steps.flatMap((step) => {
|
|
7045
|
+
const head = ` ${lead(name(step.harness))}: ${lowerFirst(step.instruction)}`;
|
|
7046
|
+
return step.command ? [head.replace(/\.+$/, ":"), ` ${step.command}`] : [head];
|
|
7047
|
+
});
|
|
6965
7048
|
}
|
|
6966
7049
|
function setupLines(setups, name) {
|
|
6967
7050
|
return setups.flatMap((setup) => {
|
|
@@ -6978,11 +7061,25 @@ function setupLines(setups, name) {
|
|
|
6978
7061
|
];
|
|
6979
7062
|
});
|
|
6980
7063
|
}
|
|
7064
|
+
function registeredLines(registered2, drivers) {
|
|
7065
|
+
return [
|
|
7066
|
+
`Registered ${registered2.slug}. The running gateway picks up the change automatically. Use tsp-gateway start to run it now and at login.`,
|
|
7067
|
+
...stepLines(
|
|
7068
|
+
drivers.repositorySetups(registered2.folder),
|
|
7069
|
+
(harness) => `To build with ${harness}`,
|
|
7070
|
+
drivers.displayName
|
|
7071
|
+
)
|
|
7072
|
+
];
|
|
7073
|
+
}
|
|
6981
7074
|
function pairedLine(view) {
|
|
6982
7075
|
return view.machineId === null ? "Not paired. Run tsp-gateway connect to set up this computer." : `Paired as ${view.machineId}. ${sentence(view.connection)}`;
|
|
6983
7076
|
}
|
|
6984
7077
|
function connectLines(view, setups, name) {
|
|
6985
|
-
return [
|
|
7078
|
+
return [
|
|
7079
|
+
pairedLine(view),
|
|
7080
|
+
...setupLines(setups, name),
|
|
7081
|
+
"Use tsp-gateway stop to stop background startup, start to enable it, or update to upgrade. The link and folders stay."
|
|
7082
|
+
];
|
|
6986
7083
|
}
|
|
6987
7084
|
function statusLines(view, setups, name) {
|
|
6988
7085
|
const reason = REASONS[view.launch.reason] ?? view.launch.reason;
|
|
@@ -7028,6 +7125,7 @@ export {
|
|
|
7028
7125
|
AcpGroupLedger,
|
|
7029
7126
|
ClaudeTranscripts,
|
|
7030
7127
|
ClaudeTrust,
|
|
7128
|
+
inFolder,
|
|
7031
7129
|
HarnessExecutor,
|
|
7032
7130
|
ClaudeDriver,
|
|
7033
7131
|
CodexActivity,
|
|
@@ -7065,24 +7163,25 @@ export {
|
|
|
7065
7163
|
daemonConnection,
|
|
7066
7164
|
awaitDaemonConnection,
|
|
7067
7165
|
readLaunchObservation,
|
|
7068
|
-
keychainOptions,
|
|
7069
|
-
keychain,
|
|
7070
7166
|
installDefinition,
|
|
7071
7167
|
captureLoginPath,
|
|
7168
|
+
loginItemHome,
|
|
7072
7169
|
installPath,
|
|
7073
7170
|
install,
|
|
7074
7171
|
uninstall,
|
|
7075
7172
|
loginItemCurrent,
|
|
7076
|
-
|
|
7173
|
+
keychainOptions,
|
|
7174
|
+
keychain,
|
|
7077
7175
|
addRepository,
|
|
7078
7176
|
installLoginItem,
|
|
7177
|
+
updateGateway,
|
|
7079
7178
|
removeLoginItem,
|
|
7080
|
-
unpairMachine,
|
|
7081
7179
|
connect,
|
|
7082
7180
|
disconnect,
|
|
7083
7181
|
folderSetups,
|
|
7084
7182
|
setupLines,
|
|
7183
|
+
registeredLines,
|
|
7085
7184
|
connectLines,
|
|
7086
7185
|
statusLines
|
|
7087
7186
|
};
|
|
7088
|
-
//# sourceMappingURL=shared-
|
|
7187
|
+
//# sourceMappingURL=shared-KRIZBGVD.js.map
|