@treestructuredplanning/gateway 0.3.0 → 0.3.4
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 +31 -6
- package/dist/cli.js +254 -161
- package/dist/gateway-schema.json +84 -0
- package/dist/{shared-KRIZBGVD.js → shared-IDNTQEWS.js} +1580 -598
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,23 +22,48 @@ only connects outward to TSP.
|
|
|
22
22
|
you: installing or signing in to a harness, or accepting its trust prompt. Once one harness is ready
|
|
23
23
|
in a folder, steps for your other harnesses are optional.
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Install and connect
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Install the gateway, then run `connect` inside the repository you want TSP to build in:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install --global @treestructuredplanning/gateway
|
|
31
|
+
tsp-gateway connect
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If your shell can't find `tsp-gateway` after the install, npm's folder for global commands
|
|
35
|
+
isn't on your `PATH`. npm's guide to
|
|
36
|
+
[where it installs commands](https://docs.npmjs.com/cli/configuring-npm/folders#executables)
|
|
37
|
+
names the folder to add.
|
|
38
|
+
|
|
39
|
+
Turning the gateway off, disconnecting, every command, what leaves your computer, and
|
|
28
40
|
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).
|
|
41
|
+
[Build on your machine](https://treestructuredplanning.com/docs/drive-with-your-agent/build-on-your-machine).
|
|
42
|
+
|
|
43
|
+
## Update
|
|
44
|
+
|
|
45
|
+
`tsp-gateway status` says when a newer gateway version is available. To update:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
tsp-gateway update
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This installs the latest gateway and restarts it. Pairing and registered folders stay. If you
|
|
52
|
+
set up the gateway with `npx`, run `npx -y @treestructuredplanning/gateway@latest update`
|
|
53
|
+
to install it globally. After a successful update, TSP shows `tsp-gateway` commands when
|
|
54
|
+
the command on the gateway's PATH runs that gateway. Otherwise it shows `npx` commands.
|
|
30
55
|
|
|
31
56
|
## Remove it completely
|
|
32
57
|
|
|
33
58
|
After `disconnect`, delete the config and state folders listed under
|
|
34
|
-
[What it stores](#what-it-stores)
|
|
59
|
+
[What it stores](#what-it-stores). If you installed the gateway globally, uninstall it:
|
|
35
60
|
|
|
36
61
|
```sh
|
|
37
62
|
npm uninstall --global @treestructuredplanning/gateway
|
|
38
63
|
```
|
|
39
64
|
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
If you clear npm's npx cache, run `npx -y @treestructuredplanning/gateway@latest connect`
|
|
66
|
+
again to restore the gateway.
|
|
42
67
|
|
|
43
68
|
## What TSP can ask it to do
|
|
44
69
|
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
+
ActionableError,
|
|
4
5
|
ActivityReporter,
|
|
6
|
+
CONNECTION,
|
|
5
7
|
CheckoutPreparer,
|
|
6
8
|
Commands,
|
|
7
9
|
GATEWAY_CLOSE_DISPOSITION,
|
|
@@ -9,9 +11,13 @@ import {
|
|
|
9
11
|
HarnessExecutor,
|
|
10
12
|
Journal,
|
|
11
13
|
OAuthTokens,
|
|
14
|
+
UsageError,
|
|
12
15
|
addRepository,
|
|
13
16
|
awaitDaemonConnection,
|
|
17
|
+
blank,
|
|
14
18
|
builtinHarnesses,
|
|
19
|
+
command,
|
|
20
|
+
commandPathLines,
|
|
15
21
|
connect,
|
|
16
22
|
connectLines,
|
|
17
23
|
connectWorktreeArgs,
|
|
@@ -20,17 +26,27 @@ import {
|
|
|
20
26
|
decodeLaunchConfig,
|
|
21
27
|
decodeReporting,
|
|
22
28
|
disconnect,
|
|
29
|
+
entry,
|
|
30
|
+
errorLines,
|
|
23
31
|
execute,
|
|
24
32
|
field,
|
|
25
33
|
folderSetups,
|
|
34
|
+
gateway,
|
|
35
|
+
gatewayInstall,
|
|
36
|
+
heading,
|
|
26
37
|
installLoginItem,
|
|
27
38
|
isObject,
|
|
28
39
|
keychain,
|
|
29
40
|
locations,
|
|
30
41
|
loginItemHome,
|
|
42
|
+
marked,
|
|
43
|
+
newerRelease,
|
|
44
|
+
nextLines,
|
|
45
|
+
notConnected,
|
|
46
|
+
note,
|
|
47
|
+
package_default,
|
|
31
48
|
parseJson,
|
|
32
49
|
parseRepositoryRemote,
|
|
33
|
-
printWorktreeRoots,
|
|
34
50
|
privateDirectory,
|
|
35
51
|
readConfig,
|
|
36
52
|
readLaunchObservation,
|
|
@@ -41,75 +57,170 @@ import {
|
|
|
41
57
|
repositoryKey,
|
|
42
58
|
runDaemon,
|
|
43
59
|
saveConfig,
|
|
60
|
+
shippedRelease,
|
|
44
61
|
statusLines,
|
|
62
|
+
text,
|
|
45
63
|
updateGateway,
|
|
46
64
|
validateOrigin,
|
|
47
65
|
watchConfig,
|
|
48
|
-
worktreesCommand
|
|
49
|
-
|
|
66
|
+
worktreesCommand,
|
|
67
|
+
writeLines
|
|
68
|
+
} from "./shared-IDNTQEWS.js";
|
|
50
69
|
|
|
51
70
|
// src/cli.ts
|
|
52
|
-
import {
|
|
53
|
-
import { isAbsolute, join } from "node:path";
|
|
71
|
+
import { isAbsolute, join as join2 } from "node:path";
|
|
54
72
|
import { fileURLToPath } from "node:url";
|
|
55
73
|
import { parseArgs } from "node:util";
|
|
56
74
|
|
|
57
|
-
//
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"tsp-gateway": "dist/cli.js"
|
|
68
|
-
},
|
|
69
|
-
files: [
|
|
70
|
-
"dist/cli.js",
|
|
71
|
-
"dist/shared-*.js",
|
|
72
|
-
"dist/vendor.js",
|
|
73
|
-
"dist/gateway-schema.json",
|
|
74
|
-
"README.md"
|
|
75
|
-
],
|
|
76
|
-
scripts: {
|
|
77
|
-
build: "node scripts/build.mjs",
|
|
78
|
-
prepack: "pnpm build",
|
|
79
|
-
test: "pnpm build && node --test --test-concurrency=3 --test-timeout=120000 --test-force-exit test/*.test.mjs",
|
|
80
|
-
"measure:launch": "pnpm build && node scripts/measure-launch.mjs",
|
|
81
|
-
typecheck: "tsc --noEmit",
|
|
82
|
-
lint: "eslint src --report-unused-disable-directives --max-warnings 0",
|
|
83
|
-
check: "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test",
|
|
84
|
-
"format:check": 'prettier --check "src/**/*.ts" "test/*.mjs" "scripts/*.mjs" README.md package.json tsconfig.json',
|
|
85
|
-
"test:coverage": 'pnpm build && node --test-concurrency=3 --test-timeout=120000 --test-force-exit --experimental-test-coverage --test-coverage-lines=80 --test --test-coverage-include="dist/*.js" --test-coverage-exclude="dist/vendor.js" test/*.test.mjs'
|
|
86
|
-
},
|
|
87
|
-
devDependencies: {
|
|
88
|
-
"@tsp/shared": "workspace:*",
|
|
89
|
-
"@types/node": "^24.10.9",
|
|
90
|
-
esbuild: "0.25.12",
|
|
91
|
-
typescript: "^5.7.2"
|
|
75
|
+
// src/cli-help.ts
|
|
76
|
+
var HELP = [
|
|
77
|
+
{
|
|
78
|
+
title: "Set up",
|
|
79
|
+
commands: [
|
|
80
|
+
["connect [folder]", "Pair if needed, register the folder and start the gateway"],
|
|
81
|
+
["disconnect", "Stop the gateway starting at login, then unpair"],
|
|
82
|
+
["add <folder>", "Register a repository folder"],
|
|
83
|
+
["remove <host/owner/name>", "Unregister a repository"]
|
|
84
|
+
]
|
|
92
85
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
{
|
|
87
|
+
title: "Run",
|
|
88
|
+
commands: [
|
|
89
|
+
["start", "Start the gateway in the background now and each time you log in"],
|
|
90
|
+
["stop", "Stop the gateway and turn off its start at login"],
|
|
91
|
+
["run", "Run the gateway in this terminal; Ctrl-C stops it"],
|
|
92
|
+
["update", "Install the latest gateway and restart it"]
|
|
93
|
+
]
|
|
98
94
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
{
|
|
96
|
+
title: "Check and configure",
|
|
97
|
+
commands: [
|
|
98
|
+
["status [--json]", "Show pairing, connection and each folder's next steps"],
|
|
99
|
+
["worktrees", "Show where each folder's agents get their own worktree"],
|
|
100
|
+
[
|
|
101
|
+
"config worktrees-root [--repo <folder>] <path|--reset>",
|
|
102
|
+
"Choose where those worktrees go"
|
|
103
|
+
],
|
|
104
|
+
["configure-launch '<json>'", "Set how agents start"],
|
|
105
|
+
["configure-reporting <activity|off>", "Choose whether TSP sees what agents are doing"]
|
|
106
|
+
]
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
+
];
|
|
109
|
+
var ENTRY_WIDTH = 40;
|
|
110
|
+
function helpLines(version) {
|
|
111
|
+
const width = Math.max(
|
|
112
|
+
...HELP.flatMap((group) => group.commands.map(([name]) => name.length)).filter(
|
|
113
|
+
(length) => length <= ENTRY_WIDTH
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
return [
|
|
117
|
+
heading(`TSP gateway ${version}`),
|
|
118
|
+
text("Lets the Tree-Structured Planning canvas start coding agents on this computer."),
|
|
119
|
+
blank,
|
|
120
|
+
text(`Usage: ${gateway("<command>")}`),
|
|
121
|
+
...HELP.flatMap((group) => [
|
|
122
|
+
blank,
|
|
123
|
+
heading(group.title),
|
|
124
|
+
...group.commands.flatMap(
|
|
125
|
+
([name, summary]) => name.length > ENTRY_WIDTH ? [command(name, 1), text(summary, 3)] : [entry(name, summary, width, 1)]
|
|
126
|
+
)
|
|
127
|
+
]),
|
|
128
|
+
blank,
|
|
129
|
+
note(
|
|
130
|
+
"Docs: https://treestructuredplanning.com/docs/drive-with-your-agent/build-on-your-machine"
|
|
131
|
+
)
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
var HELP_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "help"]);
|
|
135
|
+
|
|
136
|
+
// src/status-report.ts
|
|
137
|
+
import { readFile } from "node:fs/promises";
|
|
138
|
+
import { join } from "node:path";
|
|
139
|
+
async function readStatus(paths, config, executor, idle = CONNECTION.notRunning.message) {
|
|
140
|
+
const connection = await daemonConnection(join(paths.state, "status.json")) ?? idle;
|
|
141
|
+
let daemonLaunch = null;
|
|
142
|
+
let lastMessage = null;
|
|
143
|
+
let closeCode = null;
|
|
144
|
+
let closeDisposition = null;
|
|
145
|
+
try {
|
|
146
|
+
const status = parseJson(await readFile(join(paths.state, "status.json"), "utf8"));
|
|
147
|
+
if (isObject(status)) {
|
|
148
|
+
daemonLaunch = readLaunchObservation(field(status, "launch"));
|
|
149
|
+
const code = field(status, "close_code"), recovery = field(status, "close_disposition");
|
|
150
|
+
if (typeof code === "number" && Number.isInteger(code)) closeCode = code;
|
|
151
|
+
closeDisposition = Object.values(GATEWAY_CLOSE_DISPOSITION).find((value) => value === recovery) ?? null;
|
|
152
|
+
}
|
|
153
|
+
if (isObject(status) && typeof field(status, "message") === "string")
|
|
154
|
+
lastMessage = field(status, "message");
|
|
155
|
+
} catch {
|
|
156
|
+
lastMessage = null;
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
paired: config.pairing !== null,
|
|
160
|
+
machine_id: config.pairing?.machine_id ?? null,
|
|
161
|
+
connection,
|
|
162
|
+
last_message: lastMessage,
|
|
163
|
+
close_code: closeCode,
|
|
164
|
+
close_disposition: closeDisposition,
|
|
165
|
+
launch: await executor.status(),
|
|
166
|
+
launch_source: "status-probe",
|
|
167
|
+
last_daemon_launch: daemonLaunch,
|
|
168
|
+
repositories: Object.keys(config.repositories),
|
|
169
|
+
reporting: config.reporting
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function printStatus({ paths, config, drivers, executor, version, releaseOf = shippedRelease }, json) {
|
|
173
|
+
const update = config.pairing ? releaseOf(config.pairing.origin).then((shipped) => newerRelease(version, shipped)) : Promise.resolve(null);
|
|
174
|
+
if (json) {
|
|
175
|
+
const [status2, harnesses, updateAvailable2] = await Promise.all([
|
|
176
|
+
readStatus(paths, config, executor),
|
|
177
|
+
drivers.detect(),
|
|
178
|
+
update
|
|
179
|
+
]);
|
|
180
|
+
const { launch, launch_source, last_daemon_launch, repositories, reporting, ...daemon } = status2;
|
|
181
|
+
console.log(
|
|
182
|
+
JSON.stringify(
|
|
183
|
+
{
|
|
184
|
+
...daemon,
|
|
185
|
+
update_available: updateAvailable2,
|
|
186
|
+
harnesses,
|
|
187
|
+
launch,
|
|
188
|
+
launch_source,
|
|
189
|
+
last_daemon_launch,
|
|
190
|
+
repositories,
|
|
191
|
+
reporting
|
|
192
|
+
},
|
|
193
|
+
null,
|
|
194
|
+
2
|
|
195
|
+
)
|
|
196
|
+
);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const [status, setups, updateAvailable] = await Promise.all([
|
|
200
|
+
readStatus(paths, config, executor),
|
|
201
|
+
folderSetups(drivers, config, null, executor),
|
|
202
|
+
update
|
|
203
|
+
]);
|
|
204
|
+
writeLines(
|
|
205
|
+
statusLines(machineView(status, version, updateAvailable), setups, drivers.displayName)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function machineView(status, version, update = null) {
|
|
209
|
+
return {
|
|
210
|
+
version,
|
|
211
|
+
update,
|
|
212
|
+
machineId: status.machine_id,
|
|
213
|
+
connection: status.connection,
|
|
214
|
+
lastMessage: status.last_message,
|
|
215
|
+
launch: status.launch,
|
|
216
|
+
reporting: status.reporting
|
|
217
|
+
};
|
|
218
|
+
}
|
|
108
219
|
|
|
109
220
|
// src/cli.ts
|
|
110
|
-
async function runLocal(loginPath, paths, config, version) {
|
|
221
|
+
async function runLocal(loginPath, paths, config, version, host) {
|
|
111
222
|
const pairing = config.pairing;
|
|
112
|
-
if (!pairing) throw
|
|
223
|
+
if (!pairing) throw notConnected();
|
|
113
224
|
await privateDirectory(paths.state);
|
|
114
225
|
const release = await daemonLock(paths.state);
|
|
115
226
|
const abort = new AbortController();
|
|
@@ -118,7 +229,7 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
118
229
|
process.once("SIGTERM", stop);
|
|
119
230
|
let drivers;
|
|
120
231
|
try {
|
|
121
|
-
const journal = new Journal(
|
|
232
|
+
const journal = new Journal(join2(paths.state, `${pairing.machine_id}-receipts.jsonl`));
|
|
122
233
|
await journal.load(repositoryFolders(config));
|
|
123
234
|
const repositories = async () => repositoryFolders(await readConfig(paths.config));
|
|
124
235
|
const environment = {
|
|
@@ -131,8 +242,8 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
131
242
|
void status.refresh().catch(() => console.error("Could not update gateway launch status"));
|
|
132
243
|
}
|
|
133
244
|
});
|
|
134
|
-
const status = new GatewayStatus(
|
|
135
|
-
drivers = builtinHarnesses(environment, executor,
|
|
245
|
+
const status = new GatewayStatus(join2(paths.state, "status.json"), executor);
|
|
246
|
+
drivers = builtinHarnesses(environment, executor, join2(paths.state, "acp-groups.json"));
|
|
136
247
|
await drivers.reap();
|
|
137
248
|
const registry = drivers;
|
|
138
249
|
const commands = new Commands(journal, registry, repositories, {
|
|
@@ -142,10 +253,12 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
142
253
|
await runDaemon({
|
|
143
254
|
pairing,
|
|
144
255
|
version,
|
|
256
|
+
install: gatewayInstall(host.entry, environment, host.platform),
|
|
145
257
|
drivers: registry,
|
|
146
258
|
commands,
|
|
147
259
|
tokens: new OAuthTokens(pairing, keychain(pairing.origin)),
|
|
148
|
-
repositories: async () => registry.repositories(await repositories()),
|
|
260
|
+
repositories: async (harnesses, read) => registry.repositories(await repositories(), harnesses, read),
|
|
261
|
+
trust: async (harnesses, read) => registry.trust(await repositories(), harnesses, read),
|
|
149
262
|
watchFacts: (changed) => watchConfig(paths.config, () => {
|
|
150
263
|
executor.invalidate();
|
|
151
264
|
changed();
|
|
@@ -161,59 +274,6 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
161
274
|
await release();
|
|
162
275
|
}
|
|
163
276
|
}
|
|
164
|
-
async function readStatus(paths, config, drivers, executor, idle = "Not running") {
|
|
165
|
-
const connection = await daemonConnection(join(paths.state, "status.json")) ?? idle;
|
|
166
|
-
let daemonLaunch = null;
|
|
167
|
-
let lastMessage = null;
|
|
168
|
-
let closeCode = null;
|
|
169
|
-
let closeDisposition = null;
|
|
170
|
-
try {
|
|
171
|
-
const status = parseJson(await readFile(join(paths.state, "status.json"), "utf8"));
|
|
172
|
-
if (isObject(status)) {
|
|
173
|
-
daemonLaunch = readLaunchObservation(field(status, "launch"));
|
|
174
|
-
const code = field(status, "close_code"), recovery = field(status, "close_disposition");
|
|
175
|
-
if (typeof code === "number" && Number.isInteger(code)) closeCode = code;
|
|
176
|
-
closeDisposition = Object.values(GATEWAY_CLOSE_DISPOSITION).find((value) => value === recovery) ?? null;
|
|
177
|
-
}
|
|
178
|
-
if (isObject(status) && typeof field(status, "message") === "string")
|
|
179
|
-
lastMessage = field(status, "message");
|
|
180
|
-
} catch {
|
|
181
|
-
lastMessage = null;
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
paired: config.pairing !== null,
|
|
185
|
-
machine_id: config.pairing?.machine_id ?? null,
|
|
186
|
-
connection,
|
|
187
|
-
last_message: lastMessage,
|
|
188
|
-
close_code: closeCode,
|
|
189
|
-
close_disposition: closeDisposition,
|
|
190
|
-
harnesses: await drivers.detect(),
|
|
191
|
-
launch: await executor.status(),
|
|
192
|
-
launch_source: "status-probe",
|
|
193
|
-
last_daemon_launch: daemonLaunch,
|
|
194
|
-
repositories: Object.keys(config.repositories),
|
|
195
|
-
reporting: config.reporting
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
async function printStatus(paths, config, drivers, executor, json) {
|
|
199
|
-
const status = await readStatus(paths, config, drivers, executor);
|
|
200
|
-
if (json) {
|
|
201
|
-
console.log(JSON.stringify(status, null, 2));
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const view = machineView(status);
|
|
205
|
-
const setups = await folderSetups(drivers, config, null, executor);
|
|
206
|
-
for (const line of statusLines(view, setups, drivers.displayName)) console.log(line);
|
|
207
|
-
}
|
|
208
|
-
function machineView(status) {
|
|
209
|
-
return {
|
|
210
|
-
machineId: status.machine_id,
|
|
211
|
-
connection: status.connection,
|
|
212
|
-
lastMessage: status.last_message,
|
|
213
|
-
launch: status.launch,
|
|
214
|
-
reporting: status.reporting
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
277
|
function startupOptions(args, version) {
|
|
218
278
|
const options = args[0] === "run" ? parseArgs({
|
|
219
279
|
args: args.slice(1),
|
|
@@ -225,8 +285,9 @@ function startupOptions(args, version) {
|
|
|
225
285
|
}
|
|
226
286
|
}).values : void 0;
|
|
227
287
|
if (options?.["expected-version"] !== void 0 && options["expected-version"] !== version)
|
|
228
|
-
throw new
|
|
229
|
-
"
|
|
288
|
+
throw new ActionableError(
|
|
289
|
+
"The installed gateway version changed.",
|
|
290
|
+
CONNECTION.outdated.next
|
|
230
291
|
);
|
|
231
292
|
const defaults = locations();
|
|
232
293
|
const paths = {
|
|
@@ -249,99 +310,133 @@ function gatewayOrigin(config) {
|
|
|
249
310
|
}
|
|
250
311
|
async function configureLaunch(args, config, path) {
|
|
251
312
|
const json = args[1];
|
|
252
|
-
if (!json || args.length !== 2)
|
|
253
|
-
throw new Error("Usage: tsp-gateway configure-launch '<JSON object>'");
|
|
313
|
+
if (!json || args.length !== 2) throw new UsageError("configure-launch '<JSON object>'");
|
|
254
314
|
config.launch = decodeLaunchConfig(parseJson(json));
|
|
255
315
|
await saveConfig(path, config);
|
|
256
|
-
|
|
316
|
+
writeLines([marked("pass", "Launch settings saved"), PICKED_UP]);
|
|
257
317
|
}
|
|
258
318
|
async function configureReporting(args, config, path) {
|
|
259
|
-
if (args.length !== 2) throw new
|
|
319
|
+
if (args.length !== 2) throw new UsageError("configure-reporting <activity|off>");
|
|
260
320
|
config.reporting = decodeReporting(args[1]);
|
|
261
321
|
await saveConfig(path, config);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
322
|
+
writeLines([
|
|
323
|
+
marked(
|
|
324
|
+
"pass",
|
|
325
|
+
config.reporting === "off" ? "Activity reporting off: TSP shows only your sessions' state" : "Activity reporting on: TSP shows each session's kind of work and its counts of files edited and commands run"
|
|
326
|
+
),
|
|
327
|
+
PICKED_UP
|
|
328
|
+
]);
|
|
265
329
|
}
|
|
330
|
+
var PICKED_UP = note("The running gateway picks up the change automatically.", 1);
|
|
266
331
|
var VERBS = {
|
|
267
|
-
connect: async ({ args, config, host, paths, drivers, executor }) => {
|
|
332
|
+
connect: async ({ args, config, host, paths, drivers, executor, version }) => {
|
|
268
333
|
const choice = connectWorktreeArgs(args);
|
|
269
334
|
const since = Date.now();
|
|
270
335
|
const outcome = await connect(host, config, choice.folder);
|
|
271
336
|
await recordConnectRoot(config, paths.config, outcome.repository?.slug, choice.root);
|
|
272
|
-
await
|
|
273
|
-
|
|
337
|
+
const [reported, setups] = await Promise.all([
|
|
338
|
+
outcome.loginItem === "installed" ? awaitDaemonConnection(join2(paths.state, "status.json"), since) : null,
|
|
339
|
+
folderSetups(drivers, config, outcome.repository, executor)
|
|
340
|
+
]);
|
|
274
341
|
const status = await readStatus(
|
|
275
342
|
paths,
|
|
276
343
|
config,
|
|
277
|
-
drivers,
|
|
278
344
|
executor,
|
|
279
|
-
outcome.loginItem === "installed" && reported === null ?
|
|
345
|
+
outcome.loginItem === "installed" && reported === null ? CONNECTION.starting.message : void 0
|
|
280
346
|
);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
347
|
+
writeLines([
|
|
348
|
+
...outcome.pairing === "paired" ? [blank] : [],
|
|
349
|
+
...connectLines(machineView(status, version), setups, drivers.displayName),
|
|
350
|
+
...await commandPathLines(host.entry, host.env, host.platform)
|
|
351
|
+
]);
|
|
284
352
|
},
|
|
285
353
|
config: worktreesCommand,
|
|
286
354
|
worktrees: worktreesCommand,
|
|
287
355
|
disconnect: async ({ args, host, config }) => {
|
|
288
|
-
if (args.length !== 1) throw new
|
|
356
|
+
if (args.length !== 1) throw new UsageError("disconnect");
|
|
289
357
|
const outcome = await disconnect(host, config);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
358
|
+
writeLines([
|
|
359
|
+
marked(
|
|
360
|
+
"pass",
|
|
361
|
+
outcome.loginItem === "removed" ? "Stopped the gateway and turned off its start at login" : "The gateway wasn't set to start at login"
|
|
362
|
+
),
|
|
363
|
+
marked("pass", outcome.pairing.replace(/\.$/, "")),
|
|
364
|
+
note("Registered folders stay.", 1),
|
|
365
|
+
...nextLines(
|
|
366
|
+
{ instruction: "Connect this computer again", command: gateway("connect") },
|
|
367
|
+
1
|
|
368
|
+
)
|
|
369
|
+
]);
|
|
293
370
|
},
|
|
294
371
|
add: async ({ args, argument, host, config, drivers }) => {
|
|
295
|
-
if (!argument || args.length !== 2) throw new
|
|
296
|
-
|
|
297
|
-
for (const line of registeredLines(registered, drivers)) console.log(line);
|
|
372
|
+
if (!argument || args.length !== 2) throw new UsageError("add <folder>");
|
|
373
|
+
writeLines(registeredLines(await addRepository(host, config, argument), drivers));
|
|
298
374
|
},
|
|
299
375
|
remove: async ({ argument, config, paths }) => {
|
|
300
376
|
const repository = argument ? parseRepositoryRemote(argument) : null;
|
|
301
|
-
if (!repository) throw new
|
|
377
|
+
if (!repository) throw new UsageError("remove <host/owner/name>");
|
|
302
378
|
delete config.repositories[repositoryKey(repository)];
|
|
303
379
|
await saveConfig(paths.config, config);
|
|
304
|
-
|
|
380
|
+
writeLines([marked("pass", `Removed ${repositoryKey(repository)}`), PICKED_UP]);
|
|
305
381
|
},
|
|
306
382
|
"configure-launch": ({ args, config, paths }) => configureLaunch(args, config, paths.config),
|
|
307
383
|
"configure-reporting": ({ args, config, paths }) => configureReporting(args, config, paths.config),
|
|
308
|
-
status: (
|
|
384
|
+
status: (context) => {
|
|
385
|
+
const { args } = context;
|
|
309
386
|
const json = args[1] === "--json";
|
|
310
387
|
if (args.length > 2 || args.length === 2 && !json)
|
|
311
|
-
throw new
|
|
312
|
-
return printStatus(
|
|
388
|
+
throw new UsageError("status [--json]");
|
|
389
|
+
return printStatus(context, json);
|
|
313
390
|
},
|
|
314
391
|
start: async ({ args, host, config, version }) => {
|
|
315
|
-
if (args.length !== 1) throw new
|
|
392
|
+
if (args.length !== 1) throw new UsageError("start");
|
|
316
393
|
await installLoginItem(host, config);
|
|
317
|
-
|
|
394
|
+
writeLines([
|
|
395
|
+
marked("pass", `Started tsp-gateway ${version}. It also starts each time you log in.`),
|
|
396
|
+
...nextLines({ instruction: "Check its connection", command: gateway("status") }, 1)
|
|
397
|
+
]);
|
|
318
398
|
},
|
|
319
399
|
stop: async ({ args, host }) => {
|
|
320
|
-
if (args.length !== 1) throw new
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
400
|
+
if (args.length !== 1) throw new UsageError("stop");
|
|
401
|
+
const removed = await removeLoginItem(host) === "removed";
|
|
402
|
+
writeLines([
|
|
403
|
+
marked(
|
|
404
|
+
"pass",
|
|
405
|
+
removed ? "Stopped the gateway and turned off its start at login" : "The gateway wasn't set to start at login, so nothing changed"
|
|
406
|
+
),
|
|
407
|
+
note("Pairing and registered folders stay.", 1),
|
|
408
|
+
...nextLines({ instruction: "Start it again", command: gateway("start") }, 1)
|
|
409
|
+
]);
|
|
324
410
|
},
|
|
325
411
|
update: async ({ args, host, config }) => {
|
|
326
|
-
if (args.length !== 1) throw new
|
|
327
|
-
await updateGateway(host, config);
|
|
328
|
-
|
|
412
|
+
if (args.length !== 1) throw new UsageError("update");
|
|
413
|
+
const updated = await updateGateway(host, config);
|
|
414
|
+
writeLines([
|
|
415
|
+
marked("pass", `Updated to tsp-gateway ${updated.version} and restarted it`),
|
|
416
|
+
note("Pairing and registered folders stay.", 1),
|
|
417
|
+
...await commandPathLines(updated.entry, host.env, host.platform)
|
|
418
|
+
]);
|
|
329
419
|
},
|
|
330
|
-
run: ({ loginPath, paths, config, version }) => runLocal(loginPath, paths, config, version)
|
|
420
|
+
run: ({ loginPath, paths, config, version, host }) => runLocal(loginPath, paths, config, version, host)
|
|
331
421
|
};
|
|
332
422
|
function isVerbName(name) {
|
|
333
423
|
return Object.hasOwn(VERBS, name);
|
|
334
424
|
}
|
|
335
425
|
async function main(args) {
|
|
336
|
-
const [
|
|
337
|
-
const verb =
|
|
426
|
+
const [command2, argument] = args;
|
|
427
|
+
const verb = command2 !== void 0 && isVerbName(command2) ? VERBS[command2] : null;
|
|
428
|
+
const version = package_default.version;
|
|
338
429
|
if (!verb) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
430
|
+
writeLines(helpLines(version));
|
|
431
|
+
if (command2 !== void 0 && !HELP_FLAGS.has(command2)) {
|
|
432
|
+
writeLines(
|
|
433
|
+
[blank, marked("fail", `tsp-gateway has no ${command2} command.`)],
|
|
434
|
+
process.stderr
|
|
435
|
+
);
|
|
436
|
+
process.exitCode = 1;
|
|
437
|
+
}
|
|
342
438
|
return;
|
|
343
439
|
}
|
|
344
|
-
const version = package_default.version;
|
|
345
440
|
const { paths, loginPath } = startupOptions(args, version);
|
|
346
441
|
const config = await readConfig(paths.config);
|
|
347
442
|
const environment = { ...process.env, PATH: config.loginPath ?? process.env["PATH"] };
|
|
@@ -371,14 +466,12 @@ async function main(args) {
|
|
|
371
466
|
cwd: process.cwd(),
|
|
372
467
|
tokens: keychain,
|
|
373
468
|
openBrowser: openAuthorization,
|
|
374
|
-
report: (
|
|
469
|
+
report: (lines) => writeLines(lines)
|
|
375
470
|
}
|
|
376
471
|
});
|
|
377
472
|
}
|
|
378
473
|
void main(process.argv.slice(2)).catch((error) => {
|
|
379
|
-
|
|
380
|
-
error instanceof Error ? error.message : "Gateway could not complete the command"
|
|
381
|
-
);
|
|
474
|
+
writeLines(errorLines(error), process.stderr);
|
|
382
475
|
process.exitCode = 1;
|
|
383
476
|
});
|
|
384
477
|
//# sourceMappingURL=cli.js.map
|