@treestructuredplanning/gateway 0.1.1 → 0.1.2
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 +28 -20
- package/dist/cli.js +72 -46
- package/dist/gateway-schema.json +79 -2
- package/dist/{shared-3OFEPCJI.js → shared-M7CEELPK.js} +1077 -298
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,9 @@ only connects outward to TSP.
|
|
|
18
18
|
run without an OS credential store.
|
|
19
19
|
- Build must be available for your TSP account.
|
|
20
20
|
|
|
21
|
-
`connect` and `tsp-gateway status`
|
|
22
|
-
installing or signing in to a harness or accepting its trust prompt.
|
|
21
|
+
`connect` and `tsp-gateway status` say which harnesses can build in each folder and what is left to
|
|
22
|
+
you: installing or signing in to a harness, or accepting its trust prompt. Once one harness is ready
|
|
23
|
+
in a folder, steps for your other harnesses are optional.
|
|
23
24
|
|
|
24
25
|
## Connect this computer
|
|
25
26
|
|
|
@@ -39,8 +40,9 @@ it again is safe:
|
|
|
39
40
|
kept.
|
|
40
41
|
3. It registers the folder.
|
|
41
42
|
4. It installs a login item that starts the gateway when you log in.
|
|
42
|
-
5. It prints
|
|
43
|
-
harness, sign in, or run
|
|
43
|
+
5. It prints a short summary: which harnesses are ready in each folder, and the steps only you can
|
|
44
|
+
take (install a harness, sign in, or run it there once to accept its trust prompt). They are
|
|
45
|
+
required until one harness is ready, and optional after that.
|
|
44
46
|
|
|
45
47
|
Run outside any clone, `connect` keeps the folders already registered and repairs the rest,
|
|
46
48
|
so it also fixes a stopped, outdated or revoked gateway. If TSP cannot be reached, nothing
|
|
@@ -71,19 +73,20 @@ With a global install (`npm install --global @treestructuredplanning/gateway@lat
|
|
|
71
73
|
command is `tsp-gateway`; with `npx`, use `npx -y @treestructuredplanning/gateway@latest`
|
|
72
74
|
in its place.
|
|
73
75
|
|
|
74
|
-
| Command
|
|
75
|
-
|
|
|
76
|
-
| `connect [folder]`
|
|
77
|
-
| `disconnect`
|
|
78
|
-
| `pair`
|
|
79
|
-
| `add <folder>`
|
|
80
|
-
| `remove <owner/name>`
|
|
81
|
-
| `configure-launch '<json>'`
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
76
|
+
| Command | What it does |
|
|
77
|
+
| ----------------------------- | ------------------------------------------------------------------------------- |
|
|
78
|
+
| `connect [folder]` | Pair if needed, register the folder, install the login item, print a summary. |
|
|
79
|
+
| `disconnect` | Remove the login item, then unpair. |
|
|
80
|
+
| `pair` | Pair this computer with your TSP account (replaces any existing pairing). |
|
|
81
|
+
| `add <folder>` | Register a repository folder. |
|
|
82
|
+
| `remove <owner/name>` | Unregister a repository. |
|
|
83
|
+
| `configure-launch '<json>'` | Set how sessions get your shell environment (see below). |
|
|
84
|
+
| `configure-reporting <level>` | `activity` (default) or `off`: whether session activity is sent to TSP. |
|
|
85
|
+
| `status [--json]` | Show pairing, connection and each folder's next steps; `--json` is for scripts. |
|
|
86
|
+
| `start` | Run the gateway in the foreground. Ctrl-C stops it, not your sessions. |
|
|
87
|
+
| `install` | Install or refresh the login item. Run it again after upgrading the gateway. |
|
|
88
|
+
| `uninstall` | Remove the login item; keep the pairing and folders. |
|
|
89
|
+
| `unpair` | Revoke this computer's pairing in TSP and delete the stored credential. |
|
|
87
90
|
|
|
88
91
|
Registering or removing a folder takes effect in the running gateway without a restart.
|
|
89
92
|
|
|
@@ -123,8 +126,11 @@ needed and never stops.
|
|
|
123
126
|
|
|
124
127
|
The gateway sends TSP only repository names (`owner/name`), which harnesses are available,
|
|
125
128
|
signed in and trusted per folder, and session status, including any waiting message with
|
|
126
|
-
folder paths removed.
|
|
127
|
-
|
|
129
|
+
folder paths removed. For each launched session it also sends what the session is doing
|
|
130
|
+
(reading, editing, running a command), when it was last active, and counts of files edited
|
|
131
|
+
and commands run; never file names, commands or transcript text. Folder paths, environment
|
|
132
|
+
variables, command lines, transcripts and raw error output stay on your computer. Run
|
|
133
|
+
`tsp-gateway configure-reporting off` to stop sending activity (`activity` turns it back on).
|
|
128
134
|
|
|
129
135
|
The gateway only connects outward, to TSP, and accepts no inbound connections. The only
|
|
130
136
|
exception is pairing: while you approve in the browser, it listens briefly on `127.0.0.1`
|
|
@@ -143,7 +149,9 @@ Supported shells are bash, zsh, ksh, fish, csh, tcsh and sh. With any other shel
|
|
|
143
149
|
the gateway falls back to `/bin/sh`, then to starting the harness directly. On Windows the
|
|
144
150
|
harness always starts directly and PowerShell or cmd profiles are not loaded. Your shell
|
|
145
151
|
startup must finish quickly, must not wait for input, and must not redirect its own output to
|
|
146
|
-
a file or terminal.
|
|
152
|
+
a file or terminal. If it takes longer than 10 seconds, for example on a busy computer, the
|
|
153
|
+
session starts with the environment your shell gave the gateway last time; the first time, the
|
|
154
|
+
gateway waits up to 30 seconds before it gives up.
|
|
147
155
|
|
|
148
156
|
Change this with `configure-launch`, which sets the `launch` section of the gateway's config
|
|
149
157
|
file. Omitted settings use defaults:
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
+
ActivityReporter,
|
|
4
5
|
Commands,
|
|
5
6
|
GATEWAY_CLOSE_DISPOSITION,
|
|
6
7
|
GatewayStatus,
|
|
@@ -11,12 +12,15 @@ import {
|
|
|
11
12
|
awaitDaemonConnection,
|
|
12
13
|
builtinHarnesses,
|
|
13
14
|
connect,
|
|
15
|
+
connectLines,
|
|
14
16
|
daemonConnection,
|
|
15
17
|
daemonLock,
|
|
16
18
|
decodeLaunchConfig,
|
|
19
|
+
decodeReporting,
|
|
17
20
|
disconnect,
|
|
18
21
|
execute,
|
|
19
22
|
field,
|
|
23
|
+
folderSetups,
|
|
20
24
|
installLoginItem,
|
|
21
25
|
isObject,
|
|
22
26
|
keychain,
|
|
@@ -26,15 +30,15 @@ import {
|
|
|
26
30
|
privateDirectory,
|
|
27
31
|
readConfig,
|
|
28
32
|
readLaunchObservation,
|
|
29
|
-
remainingSteps,
|
|
30
33
|
removeLoginItem,
|
|
31
34
|
runDaemon,
|
|
32
35
|
saveConfig,
|
|
36
|
+
statusLines,
|
|
33
37
|
unpairMachine,
|
|
34
38
|
validSlug,
|
|
35
39
|
validateOrigin,
|
|
36
40
|
watchConfig
|
|
37
|
-
} from "./shared-
|
|
41
|
+
} from "./shared-M7CEELPK.js";
|
|
38
42
|
|
|
39
43
|
// src/cli.ts
|
|
40
44
|
import { readFile } from "node:fs/promises";
|
|
@@ -46,7 +50,7 @@ import { parseArgs } from "node:util";
|
|
|
46
50
|
// package.json
|
|
47
51
|
var package_default = {
|
|
48
52
|
name: "@treestructuredplanning/gateway",
|
|
49
|
-
version: "0.1.
|
|
53
|
+
version: "0.1.2",
|
|
50
54
|
description: "Outbound local harness gateway for Tree-Structured Planning",
|
|
51
55
|
type: "module",
|
|
52
56
|
engines: {
|
|
@@ -121,7 +125,9 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
121
125
|
});
|
|
122
126
|
const status = new GatewayStatus(join(paths.state, "status.json"), executor);
|
|
123
127
|
const drivers = builtinHarnesses(environment, executor);
|
|
124
|
-
const commands = new Commands(journal, drivers, repositories
|
|
128
|
+
const commands = new Commands(journal, drivers, repositories, {
|
|
129
|
+
activity: new ActivityReporter(async () => (await readConfig(paths.config)).reporting)
|
|
130
|
+
});
|
|
125
131
|
await runDaemon({
|
|
126
132
|
pairing,
|
|
127
133
|
version,
|
|
@@ -143,7 +149,7 @@ async function runLocal(loginPath, paths, config, version) {
|
|
|
143
149
|
await release();
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
async function
|
|
152
|
+
async function readStatus(paths, config, drivers, executor, idle = "Not running") {
|
|
147
153
|
const connection = await daemonConnection(join(paths.state, "status.json")) ?? idle;
|
|
148
154
|
let daemonLaunch = null;
|
|
149
155
|
let lastMessage = null;
|
|
@@ -161,25 +167,42 @@ async function printStatus(paths, config, drivers, executor, idle = "Not running
|
|
|
161
167
|
lastMessage = field(status, "message");
|
|
162
168
|
} catch {
|
|
163
169
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
return {
|
|
171
|
+
paired: config.pairing !== null,
|
|
172
|
+
machine_id: config.pairing?.machine_id ?? null,
|
|
173
|
+
connection,
|
|
174
|
+
last_message: lastMessage,
|
|
175
|
+
close_code: closeCode,
|
|
176
|
+
close_disposition: closeDisposition,
|
|
177
|
+
harnesses: await drivers.detect(),
|
|
178
|
+
launch: await executor.status(),
|
|
179
|
+
launch_source: "status-probe",
|
|
180
|
+
last_daemon_launch: daemonLaunch,
|
|
181
|
+
repositories: Object.keys(config.repositories),
|
|
182
|
+
reporting: config.reporting
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function harnessName(drivers) {
|
|
186
|
+
return (harness) => drivers.get(harness).displayName;
|
|
187
|
+
}
|
|
188
|
+
async function printStatus(paths, config, drivers, executor, json) {
|
|
189
|
+
const status = await readStatus(paths, config, drivers, executor);
|
|
190
|
+
if (json) {
|
|
191
|
+
console.log(JSON.stringify(status, null, 2));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const view = machineView(status);
|
|
195
|
+
const setups = await folderSetups(drivers, config, null);
|
|
196
|
+
for (const line of statusLines(view, setups, harnessName(drivers))) console.log(line);
|
|
197
|
+
}
|
|
198
|
+
function machineView(status) {
|
|
199
|
+
return {
|
|
200
|
+
machineId: status.machine_id,
|
|
201
|
+
connection: status.connection,
|
|
202
|
+
lastMessage: status.last_message,
|
|
203
|
+
launch: status.launch,
|
|
204
|
+
reporting: status.reporting
|
|
205
|
+
};
|
|
183
206
|
}
|
|
184
207
|
function startupOptions(args, version) {
|
|
185
208
|
const options = args[0] === "start" ? parseArgs({
|
|
@@ -220,37 +243,30 @@ async function configureLaunch(args, config, path) {
|
|
|
220
243
|
await saveConfig(path, config);
|
|
221
244
|
console.log("Launch settings saved. The running gateway picks up the change automatically.");
|
|
222
245
|
}
|
|
223
|
-
function
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
outcome.loginItem === "current" ? `The login item already runs tsp-gateway ${version}.` : `Installed tsp-gateway ${version} as a login item.`
|
|
231
|
-
];
|
|
246
|
+
async function configureReporting(args, config, path) {
|
|
247
|
+
if (args.length !== 2) throw new Error("Usage: tsp-gateway configure-reporting <activity|off>");
|
|
248
|
+
config.reporting = decodeReporting(args[1]);
|
|
249
|
+
await saveConfig(path, config);
|
|
250
|
+
console.log(
|
|
251
|
+
config.reporting === "off" ? "Reporting off: TSP shows your sessions' state only. The running gateway picks up the change automatically." : "Reporting activity: TSP shows what your sessions are doing, without file names, commands or text. The running gateway picks up the change automatically."
|
|
252
|
+
);
|
|
232
253
|
}
|
|
233
254
|
var VERBS = {
|
|
234
|
-
connect: async ({ args, argument, config,
|
|
255
|
+
connect: async ({ args, argument, config, host, paths, drivers, executor }) => {
|
|
235
256
|
if (args.length > 2) throw new Error("Usage: tsp-gateway connect [folder]");
|
|
236
257
|
const since = Date.now();
|
|
237
258
|
const outcome = await connect(host, config, argument);
|
|
238
|
-
for (const line of connectSummary(outcome, config, version)) console.log(line);
|
|
239
259
|
const reported = outcome.loginItem === "installed" ? await awaitDaemonConnection(join(paths.state, "status.json"), since) : null;
|
|
240
|
-
await
|
|
260
|
+
const status = await readStatus(
|
|
241
261
|
paths,
|
|
242
262
|
config,
|
|
243
263
|
drivers,
|
|
244
264
|
executor,
|
|
245
265
|
outcome.loginItem === "installed" && reported === null ? "Starting" : void 0
|
|
246
266
|
);
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
remaining.length === 1 ? "Remaining step:" : "Remaining steps:",
|
|
251
|
-
...remaining
|
|
252
|
-
].join("\n") : "Connected. Nothing left to do on this computer."
|
|
253
|
-
);
|
|
267
|
+
const setups = await folderSetups(drivers, config, outcome.repository);
|
|
268
|
+
for (const line of connectLines(machineView(status), setups, harnessName(drivers)))
|
|
269
|
+
console.log(line);
|
|
254
270
|
},
|
|
255
271
|
disconnect: async ({ args, host, config }) => {
|
|
256
272
|
if (args.length !== 1) throw new Error("Usage: tsp-gateway disconnect");
|
|
@@ -278,7 +294,13 @@ var VERBS = {
|
|
|
278
294
|
console.log("Repository removed. The running gateway picks up the change automatically.");
|
|
279
295
|
},
|
|
280
296
|
"configure-launch": ({ args, config, paths }) => configureLaunch(args, config, paths.config),
|
|
281
|
-
|
|
297
|
+
"configure-reporting": ({ args, config, paths }) => configureReporting(args, config, paths.config),
|
|
298
|
+
status: ({ args, paths, config, drivers, executor }) => {
|
|
299
|
+
const json = args[1] === "--json";
|
|
300
|
+
if (args.length > 2 || args.length === 2 && !json)
|
|
301
|
+
throw new Error("Usage: tsp-gateway status [--json]");
|
|
302
|
+
return printStatus(paths, config, drivers, executor, json);
|
|
303
|
+
},
|
|
282
304
|
install: async ({ host, config, version }) => {
|
|
283
305
|
await installLoginItem(host, config);
|
|
284
306
|
console.log(`Installed tsp-gateway ${version} as a login item.`);
|
|
@@ -304,7 +326,7 @@ async function main(args) {
|
|
|
304
326
|
const verb = verbNamed(command);
|
|
305
327
|
if (!verb) {
|
|
306
328
|
console.log(
|
|
307
|
-
"Usage: tsp-gateway connect [folder] | disconnect | pair | add <folder> | remove <slug> | configure-launch <json> | status | start | install | uninstall | unpair"
|
|
329
|
+
"Usage: tsp-gateway connect [folder] | disconnect | pair | add <folder> | remove <slug> | configure-launch <json> | configure-reporting <activity|off> | status [--json] | start | install | uninstall | unpair"
|
|
308
330
|
);
|
|
309
331
|
return;
|
|
310
332
|
}
|
|
@@ -312,7 +334,11 @@ async function main(args) {
|
|
|
312
334
|
const { paths, loginPath } = startupOptions(args, version);
|
|
313
335
|
const config = await readConfig(paths.config);
|
|
314
336
|
const environment = { ...process.env, PATH: config.loginPath ?? process.env["PATH"] };
|
|
315
|
-
const executor = new HarnessExecutor(environment, {
|
|
337
|
+
const executor = new HarnessExecutor(environment, {
|
|
338
|
+
config: async () => config.launch,
|
|
339
|
+
log: () => {
|
|
340
|
+
}
|
|
341
|
+
});
|
|
316
342
|
await verb({
|
|
317
343
|
args,
|
|
318
344
|
argument,
|
package/dist/gateway-schema.json
CHANGED
|
@@ -388,6 +388,11 @@
|
|
|
388
388
|
"requester_mismatch",
|
|
389
389
|
"protocol_outdated",
|
|
390
390
|
"start_failed",
|
|
391
|
+
"shell_startup_timeout",
|
|
392
|
+
"shell_startup_failed",
|
|
393
|
+
"repository_folder_unavailable",
|
|
394
|
+
"harness_exited",
|
|
395
|
+
"start_uncertain",
|
|
391
396
|
"stop_failed",
|
|
392
397
|
"session_not_found",
|
|
393
398
|
"machine_offline",
|
|
@@ -401,11 +406,12 @@
|
|
|
401
406
|
"control_expired",
|
|
402
407
|
"control_withdrawn"
|
|
403
408
|
],
|
|
404
|
-
"title": "LaunchRefusalReason"
|
|
409
|
+
"title": "LaunchRefusalReason",
|
|
410
|
+
"description": "Why a gateway or the server refused a launch, stop or resume.\n\nThe start failures a gateway can prove are named for what went wrong:\n``shell_startup_timeout`` (the login shell was too slow to start and the\ngateway had no earlier environment to use instead), ``shell_startup_failed``\n(the login shell exited before running the harness),\n``repository_folder_unavailable`` (the registered folder could not be\nentered), ``harness_exited`` (the harness exited with an error while\nstarting) and ``start_uncertain`` (a retried attempt could not tell whether\nan earlier one started a session, so it did not start a second).\n``start_failed`` is what gateways before 0.1.2 send for all of these."
|
|
405
411
|
},
|
|
406
412
|
"GatewayRetire": {
|
|
407
413
|
"additionalProperties": false,
|
|
408
|
-
"description": "Forget local tracking for an action no longer
|
|
414
|
+
"description": "Forget local tracking for an action TSP has released or no longer resolves.\n\nIt ends tracking only: the gateway leaves any running session alone.",
|
|
409
415
|
"properties": {
|
|
410
416
|
"protocol_version": {
|
|
411
417
|
"const": 1,
|
|
@@ -791,6 +797,18 @@
|
|
|
791
797
|
],
|
|
792
798
|
"default": null,
|
|
793
799
|
"title": "Resumed As"
|
|
800
|
+
},
|
|
801
|
+
"activity": {
|
|
802
|
+
"anyOf": [
|
|
803
|
+
{
|
|
804
|
+
"$ref": "#/components/schemas/GatewaySessionActivity"
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
"type": "null"
|
|
808
|
+
}
|
|
809
|
+
],
|
|
810
|
+
"default": null,
|
|
811
|
+
"description": "Coarse, content-free activity the gateway derived locally; absent from gateways before 0.1.2 and when its reporting level is off."
|
|
794
812
|
}
|
|
795
813
|
},
|
|
796
814
|
"required": [
|
|
@@ -837,6 +855,65 @@
|
|
|
837
855
|
"title": "AttachHint",
|
|
838
856
|
"description": "Path-free session identity; command rendering belongs to the consumer."
|
|
839
857
|
},
|
|
858
|
+
"GatewaySessionActivity": {
|
|
859
|
+
"additionalProperties": false,
|
|
860
|
+
"description": "The snapshot as the gateway sends it, relative to its own send time.",
|
|
861
|
+
"properties": {
|
|
862
|
+
"kind": {
|
|
863
|
+
"anyOf": [
|
|
864
|
+
{
|
|
865
|
+
"$ref": "#/components/schemas/SessionActivityKind"
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
"type": "null"
|
|
869
|
+
}
|
|
870
|
+
],
|
|
871
|
+
"description": "What the session is doing now; null unless it is working."
|
|
872
|
+
},
|
|
873
|
+
"files_edited": {
|
|
874
|
+
"description": "Distinct files the session edited successfully.",
|
|
875
|
+
"maximum": 1000000,
|
|
876
|
+
"minimum": 0,
|
|
877
|
+
"title": "Files Edited",
|
|
878
|
+
"type": "integer"
|
|
879
|
+
},
|
|
880
|
+
"commands_run": {
|
|
881
|
+
"description": "Commands the session ran, reads excluded.",
|
|
882
|
+
"maximum": 1000000,
|
|
883
|
+
"minimum": 0,
|
|
884
|
+
"title": "Commands Run",
|
|
885
|
+
"type": "integer"
|
|
886
|
+
},
|
|
887
|
+
"idle_ms": {
|
|
888
|
+
"description": "Milliseconds since the session was last active, measured by the gateway when it sent the frame, so no clock skew reaches TSP.",
|
|
889
|
+
"minimum": 0,
|
|
890
|
+
"title": "Idle Ms",
|
|
891
|
+
"type": "integer"
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
"required": [
|
|
895
|
+
"kind",
|
|
896
|
+
"files_edited",
|
|
897
|
+
"commands_run",
|
|
898
|
+
"idle_ms"
|
|
899
|
+
],
|
|
900
|
+
"title": "GatewaySessionActivity",
|
|
901
|
+
"type": "object"
|
|
902
|
+
},
|
|
903
|
+
"SessionActivityKind": {
|
|
904
|
+
"type": "string",
|
|
905
|
+
"enum": [
|
|
906
|
+
"thinking",
|
|
907
|
+
"reading",
|
|
908
|
+
"editing",
|
|
909
|
+
"running_command",
|
|
910
|
+
"using_plan",
|
|
911
|
+
"delegating",
|
|
912
|
+
"using_tool"
|
|
913
|
+
],
|
|
914
|
+
"title": "SessionActivityKind",
|
|
915
|
+
"description": "What a working session is doing right now, as its harness shows it.\n\nReported only while the session is working. Waiting on the person is the\nsession's ``needs_input`` state, not a kind."
|
|
916
|
+
},
|
|
840
917
|
"GatewayPong": {
|
|
841
918
|
"additionalProperties": false,
|
|
842
919
|
"properties": {
|