@treestructuredplanning/gateway 0.3.2 → 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 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
- ## Connect, disconnect and commands
25
+ ## Install and connect
26
26
 
27
- Connecting, turning the gateway off, disconnecting, every command, what leaves your computer, and
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). Start there.
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), and if you installed globally:
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
- 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.
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
@@ -17,6 +17,7 @@ import {
17
17
  blank,
18
18
  builtinHarnesses,
19
19
  command,
20
+ commandPathLines,
20
21
  connect,
21
22
  connectLines,
22
23
  connectWorktreeArgs,
@@ -30,6 +31,8 @@ import {
30
31
  execute,
31
32
  field,
32
33
  folderSetups,
34
+ gateway,
35
+ gatewayInstall,
33
36
  heading,
34
37
  installLoginItem,
35
38
  isObject,
@@ -37,9 +40,11 @@ import {
37
40
  locations,
38
41
  loginItemHome,
39
42
  marked,
43
+ newerRelease,
40
44
  nextLines,
41
45
  notConnected,
42
46
  note,
47
+ package_default,
43
48
  parseJson,
44
49
  parseRepositoryRemote,
45
50
  privateDirectory,
@@ -52,6 +57,7 @@ import {
52
57
  repositoryKey,
53
58
  runDaemon,
54
59
  saveConfig,
60
+ shippedRelease,
55
61
  statusLines,
56
62
  text,
57
63
  updateGateway,
@@ -59,65 +65,13 @@ import {
59
65
  watchConfig,
60
66
  worktreesCommand,
61
67
  writeLines
62
- } from "./shared-SSP3A5QQ.js";
68
+ } from "./shared-IDNTQEWS.js";
63
69
 
64
70
  // src/cli.ts
65
71
  import { isAbsolute, join as join2 } from "node:path";
66
72
  import { fileURLToPath } from "node:url";
67
73
  import { parseArgs } from "node:util";
68
74
 
69
- // package.json
70
- var package_default = {
71
- name: "@treestructuredplanning/gateway",
72
- version: "0.3.2",
73
- description: "Outbound local harness gateway for Tree-Structured Planning",
74
- type: "module",
75
- engines: {
76
- node: ">=22"
77
- },
78
- bin: {
79
- "tsp-gateway": "dist/cli.js"
80
- },
81
- files: [
82
- "dist/cli.js",
83
- "dist/shared-*.js",
84
- "dist/vendor.js",
85
- "dist/gateway-schema.json",
86
- "README.md"
87
- ],
88
- scripts: {
89
- build: "node scripts/build.mjs",
90
- prepack: "pnpm build",
91
- test: "pnpm build && node --test --test-concurrency=3 --test-timeout=120000 --test-force-exit test/*.test.mjs",
92
- "measure:launch": "pnpm build && node scripts/measure-launch.mjs",
93
- typecheck: "tsc --noEmit",
94
- lint: "eslint src --report-unused-disable-directives --max-warnings 0",
95
- check: "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test",
96
- "format:check": 'prettier --check "src/**/*.ts" "test/*.mjs" "scripts/*.mjs" README.md package.json tsconfig.json',
97
- "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'
98
- },
99
- devDependencies: {
100
- "@tsp/shared": "workspace:*",
101
- "@types/node": "^24.10.9",
102
- esbuild: "0.25.12",
103
- typescript: "^5.7.2"
104
- },
105
- license: "MIT",
106
- dependencies: {
107
- "@napi-rs/keyring": "2.1.2",
108
- "smol-toml": "1.6.0",
109
- ws: "8.21.0"
110
- },
111
- publishConfig: {
112
- access: "public"
113
- },
114
- repository: {
115
- type: "git",
116
- url: "git+https://github.com/WebifyServices/tsp.git",
117
- directory: "packages/tsp-gateway"
118
- }
119
- };
120
-
121
75
  // src/cli-help.ts
122
76
  var HELP = [
123
77
  {
@@ -163,7 +117,7 @@ function helpLines(version) {
163
117
  heading(`TSP gateway ${version}`),
164
118
  text("Lets the Tree-Structured Planning canvas start coding agents on this computer."),
165
119
  blank,
166
- text("Usage: tsp-gateway <command>"),
120
+ text(`Usage: ${gateway("<command>")}`),
167
121
  ...HELP.flatMap((group) => [
168
122
  blank,
169
123
  heading(group.title),
@@ -215,17 +169,20 @@ async function readStatus(paths, config, executor, idle = CONNECTION.notRunning.
215
169
  reporting: config.reporting
216
170
  };
217
171
  }
218
- async function printStatus({ paths, config, drivers, executor, version }, json) {
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);
219
174
  if (json) {
220
- const [status2, harnesses] = await Promise.all([
175
+ const [status2, harnesses, updateAvailable2] = await Promise.all([
221
176
  readStatus(paths, config, executor),
222
- drivers.detect()
177
+ drivers.detect(),
178
+ update
223
179
  ]);
224
180
  const { launch, launch_source, last_daemon_launch, repositories, reporting, ...daemon } = status2;
225
181
  console.log(
226
182
  JSON.stringify(
227
183
  {
228
184
  ...daemon,
185
+ update_available: updateAvailable2,
229
186
  harnesses,
230
187
  launch,
231
188
  launch_source,
@@ -239,15 +196,19 @@ async function printStatus({ paths, config, drivers, executor, version }, json)
239
196
  );
240
197
  return;
241
198
  }
242
- const [status, setups] = await Promise.all([
199
+ const [status, setups, updateAvailable] = await Promise.all([
243
200
  readStatus(paths, config, executor),
244
- folderSetups(drivers, config, null, executor)
201
+ folderSetups(drivers, config, null, executor),
202
+ update
245
203
  ]);
246
- writeLines(statusLines(machineView(status, version), setups, drivers.displayName));
204
+ writeLines(
205
+ statusLines(machineView(status, version, updateAvailable), setups, drivers.displayName)
206
+ );
247
207
  }
248
- function machineView(status, version) {
208
+ function machineView(status, version, update = null) {
249
209
  return {
250
210
  version,
211
+ update,
251
212
  machineId: status.machine_id,
252
213
  connection: status.connection,
253
214
  lastMessage: status.last_message,
@@ -257,7 +218,7 @@ function machineView(status, version) {
257
218
  }
258
219
 
259
220
  // src/cli.ts
260
- async function runLocal(loginPath, paths, config, version) {
221
+ async function runLocal(loginPath, paths, config, version, host) {
261
222
  const pairing = config.pairing;
262
223
  if (!pairing) throw notConnected();
263
224
  await privateDirectory(paths.state);
@@ -292,10 +253,12 @@ async function runLocal(loginPath, paths, config, version) {
292
253
  await runDaemon({
293
254
  pairing,
294
255
  version,
256
+ install: gatewayInstall(host.entry, environment, host.platform),
295
257
  drivers: registry,
296
258
  commands,
297
259
  tokens: new OAuthTokens(pairing, keychain(pairing.origin)),
298
- 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),
299
262
  watchFacts: (changed) => watchConfig(paths.config, () => {
300
263
  executor.invalidate();
301
264
  changed();
@@ -347,14 +310,13 @@ function gatewayOrigin(config) {
347
310
  }
348
311
  async function configureLaunch(args, config, path) {
349
312
  const json = args[1];
350
- if (!json || args.length !== 2)
351
- throw new UsageError("tsp-gateway configure-launch '<JSON object>'");
313
+ if (!json || args.length !== 2) throw new UsageError("configure-launch '<JSON object>'");
352
314
  config.launch = decodeLaunchConfig(parseJson(json));
353
315
  await saveConfig(path, config);
354
316
  writeLines([marked("pass", "Launch settings saved"), PICKED_UP]);
355
317
  }
356
318
  async function configureReporting(args, config, path) {
357
- if (args.length !== 2) throw new UsageError("tsp-gateway configure-reporting <activity|off>");
319
+ if (args.length !== 2) throw new UsageError("configure-reporting <activity|off>");
358
320
  config.reporting = decodeReporting(args[1]);
359
321
  await saveConfig(path, config);
360
322
  writeLines([
@@ -384,13 +346,14 @@ var VERBS = {
384
346
  );
385
347
  writeLines([
386
348
  ...outcome.pairing === "paired" ? [blank] : [],
387
- ...connectLines(machineView(status, version), setups, drivers.displayName)
349
+ ...connectLines(machineView(status, version), setups, drivers.displayName),
350
+ ...await commandPathLines(host.entry, host.env, host.platform)
388
351
  ]);
389
352
  },
390
353
  config: worktreesCommand,
391
354
  worktrees: worktreesCommand,
392
355
  disconnect: async ({ args, host, config }) => {
393
- if (args.length !== 1) throw new UsageError("tsp-gateway disconnect");
356
+ if (args.length !== 1) throw new UsageError("disconnect");
394
357
  const outcome = await disconnect(host, config);
395
358
  writeLines([
396
359
  marked(
@@ -400,18 +363,18 @@ var VERBS = {
400
363
  marked("pass", outcome.pairing.replace(/\.$/, "")),
401
364
  note("Registered folders stay.", 1),
402
365
  ...nextLines(
403
- { instruction: "Connect this computer again", command: "tsp-gateway connect" },
366
+ { instruction: "Connect this computer again", command: gateway("connect") },
404
367
  1
405
368
  )
406
369
  ]);
407
370
  },
408
371
  add: async ({ args, argument, host, config, drivers }) => {
409
- if (!argument || args.length !== 2) throw new UsageError("tsp-gateway add <folder>");
372
+ if (!argument || args.length !== 2) throw new UsageError("add <folder>");
410
373
  writeLines(registeredLines(await addRepository(host, config, argument), drivers));
411
374
  },
412
375
  remove: async ({ argument, config, paths }) => {
413
376
  const repository = argument ? parseRepositoryRemote(argument) : null;
414
- if (!repository) throw new UsageError("tsp-gateway remove <host/owner/name>");
377
+ if (!repository) throw new UsageError("remove <host/owner/name>");
415
378
  delete config.repositories[repositoryKey(repository)];
416
379
  await saveConfig(paths.config, config);
417
380
  writeLines([marked("pass", `Removed ${repositoryKey(repository)}`), PICKED_UP]);
@@ -422,19 +385,19 @@ var VERBS = {
422
385
  const { args } = context;
423
386
  const json = args[1] === "--json";
424
387
  if (args.length > 2 || args.length === 2 && !json)
425
- throw new UsageError("tsp-gateway status [--json]");
388
+ throw new UsageError("status [--json]");
426
389
  return printStatus(context, json);
427
390
  },
428
391
  start: async ({ args, host, config, version }) => {
429
- if (args.length !== 1) throw new UsageError("tsp-gateway start");
392
+ if (args.length !== 1) throw new UsageError("start");
430
393
  await installLoginItem(host, config);
431
394
  writeLines([
432
395
  marked("pass", `Started tsp-gateway ${version}. It also starts each time you log in.`),
433
- ...nextLines({ instruction: "Check its connection", command: "tsp-gateway status" }, 1)
396
+ ...nextLines({ instruction: "Check its connection", command: gateway("status") }, 1)
434
397
  ]);
435
398
  },
436
399
  stop: async ({ args, host }) => {
437
- if (args.length !== 1) throw new UsageError("tsp-gateway stop");
400
+ if (args.length !== 1) throw new UsageError("stop");
438
401
  const removed = await removeLoginItem(host) === "removed";
439
402
  writeLines([
440
403
  marked(
@@ -442,18 +405,19 @@ var VERBS = {
442
405
  removed ? "Stopped the gateway and turned off its start at login" : "The gateway wasn't set to start at login, so nothing changed"
443
406
  ),
444
407
  note("Pairing and registered folders stay.", 1),
445
- ...nextLines({ instruction: "Start it again", command: "tsp-gateway start" }, 1)
408
+ ...nextLines({ instruction: "Start it again", command: gateway("start") }, 1)
446
409
  ]);
447
410
  },
448
411
  update: async ({ args, host, config }) => {
449
- if (args.length !== 1) throw new UsageError("tsp-gateway update");
450
- const version = await updateGateway(host, config);
412
+ if (args.length !== 1) throw new UsageError("update");
413
+ const updated = await updateGateway(host, config);
451
414
  writeLines([
452
- marked("pass", `Updated to tsp-gateway ${version} and restarted it`),
453
- note("Pairing and registered folders stay.", 1)
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)
454
418
  ]);
455
419
  },
456
- run: ({ loginPath, paths, config, version }) => runLocal(loginPath, paths, config, version)
420
+ run: ({ loginPath, paths, config, version, host }) => runLocal(loginPath, paths, config, version, host)
457
421
  };
458
422
  function isVerbName(name) {
459
423
  return Object.hasOwn(VERBS, name);
@@ -6,6 +6,7 @@
6
6
  "launch": "#/components/schemas/GatewayLaunchOffer",
7
7
  "permit": "#/components/schemas/GatewayPermit",
8
8
  "ping": "#/components/schemas/GatewayPing",
9
+ "recheck_sign_in": "#/components/schemas/GatewayRecheckSignIn",
9
10
  "resume": "#/components/schemas/GatewayResumeOffer",
10
11
  "retire": "#/components/schemas/GatewayRetire",
11
12
  "stop": "#/components/schemas/GatewayStopOffer"
@@ -30,6 +31,9 @@
30
31
  },
31
32
  {
32
33
  "$ref": "#/components/schemas/GatewayRetire"
34
+ },
35
+ {
36
+ "$ref": "#/components/schemas/GatewayRecheckSignIn"
33
37
  }
34
38
  ],
35
39
  "title": "HubToGateway"
@@ -607,6 +611,7 @@
607
611
  "launch_superseded",
608
612
  "launch_expired",
609
613
  "launch_withdrawn",
614
+ "launch_dismissed",
610
615
  "control_expired",
611
616
  "control_withdrawn"
612
617
  ],
@@ -803,6 +808,32 @@
803
808
  "title": "GatewayRetire",
804
809
  "type": "object"
805
810
  },
811
+ "GatewayRecheckSignIn": {
812
+ "additionalProperties": false,
813
+ "description": "Check a signed-out harness's sign-in now and restart its close checking.\n\nSent only to a gateway whose advertisement carries that harness's\n``sign_in_check``: an older gateway closes on a kind it cannot decode.\n``MachineService.recheck_sign_in`` is the one sender. The gateway answers\nthrough its next advertisement, never with a receipt.",
814
+ "properties": {
815
+ "protocol_version": {
816
+ "const": 3,
817
+ "default": 3,
818
+ "title": "Protocol Version",
819
+ "type": "integer"
820
+ },
821
+ "kind": {
822
+ "const": "recheck_sign_in",
823
+ "default": "recheck_sign_in",
824
+ "title": "Kind",
825
+ "type": "string"
826
+ },
827
+ "harness": {
828
+ "$ref": "#/components/schemas/HarnessKind"
829
+ }
830
+ },
831
+ "required": [
832
+ "harness"
833
+ ],
834
+ "title": "GatewayRecheckSignIn",
835
+ "type": "object"
836
+ },
806
837
  "GatewayToHub": {
807
838
  "description": "The complete gateway-to-server frame; exported through OpenAPI.",
808
839
  "discriminator": {
@@ -871,6 +902,10 @@
871
902
  "title": "Repositories",
872
903
  "type": "array"
873
904
  },
905
+ "gateway_install": {
906
+ "$ref": "#/components/schemas/GatewayInstall",
907
+ "default": "npx"
908
+ },
874
909
  "kind": {
875
910
  "const": "hello",
876
911
  "default": "hello",
@@ -921,6 +956,17 @@
921
956
  },
922
957
  "operations": {
923
958
  "$ref": "#/components/schemas/HarnessOperations"
959
+ },
960
+ "sign_in_check": {
961
+ "anyOf": [
962
+ {
963
+ "$ref": "#/components/schemas/SignInCheck"
964
+ },
965
+ {
966
+ "type": "null"
967
+ }
968
+ ],
969
+ "description": "How closely the gateway is checking this harness's sign-in, sent only while it is installed and signed out. Its presence says the gateway accepts recheck_sign_in for this harness; older gateways omit it, are never sent that frame, and offer no recheck."
924
970
  }
925
971
  },
926
972
  "additionalProperties": false,
@@ -972,6 +1018,15 @@
972
1018
  ],
973
1019
  "title": "HarnessOperations"
974
1020
  },
1021
+ "SignInCheck": {
1022
+ "type": "string",
1023
+ "enum": [
1024
+ "close",
1025
+ "eased"
1026
+ ],
1027
+ "title": "SignInCheck",
1028
+ "description": "How closely the gateway is checking a harness it found installed but signed out.\n\n``close``: every few seconds, so a sign-in reaches the canvas without help.\n``eased``: a minute apart, or stopped, so the canvas offers a recheck."
1029
+ },
975
1030
  "AdvertisedRepository": {
976
1031
  "properties": {
977
1032
  "harness": {
@@ -1019,6 +1074,15 @@
1019
1074
  ],
1020
1075
  "title": "RepositoryTrust"
1021
1076
  },
1077
+ "GatewayInstall": {
1078
+ "type": "string",
1079
+ "enum": [
1080
+ "global",
1081
+ "npx"
1082
+ ],
1083
+ "title": "GatewayInstall",
1084
+ "description": "Which command can run this gateway on its machine.\n\nGlobal means the running entry is in npm's global layout, its command folder\nis on the gateway's PATH, and the first tsp-gateway there runs this gateway.\nNpx covers every other launch, including source, project, linked, off-PATH,\nand shadowed global copies. Commands use npx on a machine with npm.\nAn absent value reads as npx, including advertisements from older gateways."
1085
+ },
1022
1086
  "GatewayAdvertise": {
1023
1087
  "additionalProperties": false,
1024
1088
  "properties": {
@@ -1048,6 +1112,10 @@
1048
1112
  "title": "Repositories",
1049
1113
  "type": "array"
1050
1114
  },
1115
+ "gateway_install": {
1116
+ "$ref": "#/components/schemas/GatewayInstall",
1117
+ "default": "npx"
1118
+ },
1051
1119
  "kind": {
1052
1120
  "const": "advertise",
1053
1121
  "default": "advertise",
@@ -1404,5 +1472,21 @@
1404
1472
  "hub_path"
1405
1473
  ],
1406
1474
  "title": "GatewayMachineRegistered"
1475
+ },
1476
+ "GatewayRelease": {
1477
+ "properties": {
1478
+ "version": {
1479
+ "type": "string",
1480
+ "pattern": "^\\d+\\.\\d+\\.\\d+$",
1481
+ "title": "Version"
1482
+ }
1483
+ },
1484
+ "additionalProperties": false,
1485
+ "type": "object",
1486
+ "required": [
1487
+ "version"
1488
+ ],
1489
+ "title": "GatewayRelease",
1490
+ "description": "The gateway release TSP ships, which a gateway compares with its own version."
1407
1491
  }
1408
1492
  }