@treestructuredplanning/gateway 0.1.2 → 0.2.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 CHANGED
@@ -1,18 +1,19 @@
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 resume Claude Code and Codex sessions on your computer, in the
4
+ (TSP) canvas start, stop and resume 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
 
8
8
  ## Requirements
9
9
 
10
10
  - Node.js **22 or newer**.
11
- - Claude Code, or Codex **0.162.1 or newer**, installed separately and signed in with its
12
- own login (`codex login` for Codex). The gateway never signs in for you.
11
+ - Claude Code, Codex **0.162.1 or newer**, or the Cursor CLI **2026.10.19 or newer**,
12
+ installed separately and signed in with its own login (`codex login` for Codex,
13
+ `agent login` for Cursor). The gateway never signs in for you.
13
14
  - Each folder you register must be a local clone with a GitHub remote, and the harness must
14
- trust it: run `claude` or `codex` in the folder once and accept its trust prompt. Codex
15
- sessions never start in a folder Codex has not trusted, and trusting a parent folder does not
15
+ trust it: run `claude`, `codex` or `agent` in the folder once and accept its trust prompt.
16
+ Codex and Cursor sessions never start in a folder they have not trusted, and trusting a parent folder does not
16
17
  count for a repository inside it.
17
18
  - On Linux, a running Secret Service such as GNOME Keyring or KWallet. The gateway will not
18
19
  run without an OS credential store.
@@ -49,6 +50,8 @@ so it also fixes a stopped, outdated or revoked gateway. If TSP cannot be reache
49
50
  changes; try again later. The login item runs the copy of the gateway that `connect` ran
50
51
  from. With `npx` that is npm's cache, so if you clear that cache, run `connect` again.
51
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
+
52
55
  ## Disconnect and uninstall
53
56
 
54
57
  ```sh
@@ -79,7 +82,7 @@ in its place.
79
82
  | `disconnect` | Remove the login item, then unpair. |
80
83
  | `pair` | Pair this computer with your TSP account (replaces any existing pairing). |
81
84
  | `add <folder>` | Register a repository folder. |
82
- | `remove <owner/name>` | Unregister a repository. |
85
+ | `remove <host/owner/name>` | Unregister a repository. |
83
86
  | `configure-launch '<json>'` | Set how sessions get your shell environment (see below). |
84
87
  | `configure-reporting <level>` | `activity` (default) or `off`: whether session activity is sent to TSP. |
85
88
  | `status [--json]` | Show pairing, connection and each folder's next steps; `--json` is for scripts. |
@@ -94,7 +97,7 @@ Registering or removing a folder takes effect in the running gateway without a r
94
97
 
95
98
  TSP can ask the gateway for exactly four things, and only in folders you registered:
96
99
 
97
- - **Launch** a Claude Code or Codex session, with a prompt describing the TSP work you
100
+ - **Launch** a Claude Code, Codex or Cursor session, with a prompt describing the TSP work you
98
101
  started from the canvas.
99
102
  - **Stop** that session.
100
103
  - **Resume** that session, with the text you typed. With no text, a stopped session gets the
@@ -103,17 +106,20 @@ TSP can ask the gateway for exactly four things, and only in folders you registe
103
106
  - **Report status**: which harnesses are installed, signed in and trust each registered
104
107
  folder, and how each launched session is doing.
105
108
 
106
- Only your own clicks in TSP send a prompt. Sessions keep running if the gateway stops. A
109
+ 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 Resume reopens its chat. A
107
111
  session that finishes does not mean TSP has reviewed or accepted its work. Keep the
108
112
  [TSP plugin](https://github.com/WebifyServices/tsp-plugin) installed so launched sessions
109
113
  have TSP's tools.
110
114
 
111
115
  The gateway never:
112
116
 
113
- - changes your Claude Code or Codex settings, permissions or configuration, or passes any
117
+ - changes your Claude Code, Codex or Cursor settings, permissions or configuration, or passes any
114
118
  flag that bypasses them. Your own settings govern every session.
115
119
  - answers an approval prompt or question inside a session. When a session needs you, TSP
116
- shows the command to open it yourself (`claude attach <id>` or `codex resume <id>`).
120
+ shows the command to open it yourself (`claude attach <id>` or `codex resume <id>`). A Cursor
121
+ session waiting on a prompt stays waiting until you Stop it, which answers the prompt
122
+ "cancelled"; the gateway never selects an option.
117
123
  - signs in, accepts a trust prompt, or approves pairing for you.
118
124
  - accepts a shell command, program, folder, file path or environment variable from TSP.
119
125
  - runs anything in a folder you have not registered, or starts Codex in a folder Codex does
@@ -122,14 +128,22 @@ The gateway never:
122
128
  For Codex, sessions run in Codex's own background service, which the gateway starts when
123
129
  needed and never stops.
124
130
 
131
+ For Cursor, the gateway runs `agent --version` and `agent status` to read the installed version
132
+ and whether you are signed in, and `agent acp` (Cursor's Agent Client Protocol mode) as its own
133
+ child process for each running turn. It sends no mode, model, permission or sign-in request.
134
+ Cursor applies your own settings and permission rules, and the gateway starts a session only in a
135
+ folder you have already trusted.
136
+
125
137
  ## What leaves your computer
126
138
 
127
139
  The gateway sends TSP only repository names (`owner/name`), which harnesses are available,
128
140
  signed in and trusted per folder, and session status, including any waiting message with
129
141
  folder paths removed. For each launched session it also sends what the session is doing
130
142
  (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
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
133
147
  `tsp-gateway configure-reporting off` to stop sending activity (`activity` turns it back on).
134
148
 
135
149
  The gateway only connects outward, to TSP, and accepts no inbound connections. The only
@@ -205,3 +219,44 @@ folder only after `disconnect`, once no gateway is running.
205
219
 
206
220
  See the [TSP documentation](https://treestructuredplanning.com/docs) or email
207
221
  `support@treestructuredplanning.com`.
222
+
223
+ 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
+
225
+ ## Attempt checkouts
226
+
227
+ With **Own worktree**, Build prepares a separate worktree at
228
+ `<Git top level>/.tsp/worktrees/<attempt-id>` on `tsp/<attempt-id>`. Registering `packages/app` starts the agent in
229
+ `<worktree>/packages/app`, preserving its package configuration. Its base is fetched from the repository's remote landing line;
230
+ a failed fetch refuses the launch. A dirty, stale or unrelated main checkout does
231
+ not determine that base. **Shared checkout, current branch** leaves its branch alone.
232
+ **Shared checkout, new branch** refuses to switch while another tracked agent is live
233
+ there or files are dirty.
234
+
235
+ Set the local machine root with `tsp-gateway config worktrees-root <path>`; restore
236
+ the default with `tsp-gateway config worktrees-root --reset`. Override one clone with
237
+ `tsp-gateway config worktrees-root --repo <folder> <path>`; clear that override with
238
+ `tsp-gateway config worktrees-root --repo <folder> --reset`. The folder must already
239
+ be registered. These config commands never install or change a login item.
240
+ `tsp-gateway worktrees` prints each registered folder's worktree folder in full and
241
+ which setting chose it. It prints only in your terminal; TSP never receives these paths.
242
+ `connect <folder> --worktrees-root <path>` also sets the override during setup.
243
+ Paths can be absolute, `~/`
244
+ relative, or relative to the registered folder. The root cannot be the clone or an ancestor. Existing
245
+ sessions keep their recorded folder when configuration changes. The default adds
246
+ `/.tsp/` to Git's local exclude file once. A custom root inside the repository
247
+ gets an exclude anchored at the Git top level, including any package prefix; an
248
+ outside root needs no root exclude.
249
+
250
+ Claude Code and Codex linked worktrees inherit the registered clone's trust. TSP never writes trust
251
+ or permission settings. Allow the worktree root in per-path tools such as direnv
252
+ or mise if your harness installation depends on them.
253
+
254
+ Only ignored files selected by `.worktreeinclude` are copied. No file is copied
255
+ when it is absent, and symlinks escaping the clone are not followed. Existing
256
+ files in the destination are preserved, including on reuse. Before copying a new
257
+ file, the gateway verifies that the destination ignores it, adding an exact path
258
+ to Git's local exclude when needed. If it cannot protect the file, the launch
259
+ refuses before copying it. Tracked destination files are never written. A local branch
260
+ named `tsp` blocks the `tsp/<attempt-id>` namespace and must be renamed by the user.
261
+ TSP never deletes worktrees or branches. Reusing an attempt never rebases its
262
+ branch; the reported base is its shared ancestor with the fetched landing line.
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
3
3
  import {
4
4
  ActivityReporter,
5
+ CheckoutPreparer,
5
6
  Commands,
6
7
  GATEWAY_CLOSE_DISPOSITION,
7
8
  GatewayStatus,
@@ -13,6 +14,7 @@ import {
13
14
  builtinHarnesses,
14
15
  connect,
15
16
  connectLines,
17
+ connectWorktreeArgs,
16
18
  daemonConnection,
17
19
  daemonLock,
18
20
  decodeLaunchConfig,
@@ -27,18 +29,23 @@ import {
27
29
  locations,
28
30
  pairMachine,
29
31
  parseJson,
32
+ parseRepositoryRemote,
33
+ printWorktreeRoots,
30
34
  privateDirectory,
31
35
  readConfig,
32
36
  readLaunchObservation,
37
+ recordConnectRoot,
33
38
  removeLoginItem,
39
+ repositoryFolders,
40
+ repositoryKey,
34
41
  runDaemon,
35
42
  saveConfig,
36
43
  statusLines,
37
44
  unpairMachine,
38
- validSlug,
39
45
  validateOrigin,
40
- watchConfig
41
- } from "./shared-M7CEELPK.js";
46
+ watchConfig,
47
+ worktreesCommand
48
+ } from "./shared-IOW65S5G.js";
42
49
 
43
50
  // src/cli.ts
44
51
  import { readFile } from "node:fs/promises";
@@ -50,7 +57,7 @@ import { parseArgs } from "node:util";
50
57
  // package.json
51
58
  var package_default = {
52
59
  name: "@treestructuredplanning/gateway",
53
- version: "0.1.2",
60
+ version: "0.2.0",
54
61
  description: "Outbound local harness gateway for Tree-Structured Planning",
55
62
  type: "module",
56
63
  engines: {
@@ -69,13 +76,13 @@ var package_default = {
69
76
  scripts: {
70
77
  build: "node scripts/build.mjs",
71
78
  prepack: "pnpm build",
72
- test: "pnpm build && node --test --test-concurrency=3 test/*.test.mjs",
79
+ test: "pnpm build && node --test --test-concurrency=3 --test-timeout=120000 --test-force-exit test/*.test.mjs",
73
80
  "measure:launch": "pnpm build && node scripts/measure-launch.mjs",
74
81
  typecheck: "tsc --noEmit",
75
82
  lint: "eslint src --report-unused-disable-directives --max-warnings 0",
76
83
  check: "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test",
77
84
  "format:check": 'prettier --check "src/**/*.ts" "test/*.mjs" "scripts/*.mjs" README.md package.json tsconfig.json',
78
- "test:coverage": 'pnpm build && node --test-concurrency=3 --experimental-test-coverage --test-coverage-lines=80 --test --test-coverage-include="dist/*.js" --test-coverage-exclude="dist/vendor.js" test/*.test.mjs'
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'
79
86
  },
80
87
  devDependencies: {
81
88
  "@tsp/shared": "workspace:*",
@@ -109,10 +116,11 @@ async function runLocal(loginPath, paths, config, version) {
109
116
  const stop = () => abort.abort();
110
117
  process.once("SIGINT", stop);
111
118
  process.once("SIGTERM", stop);
119
+ let drivers;
112
120
  try {
113
121
  const journal = new Journal(join(paths.state, `${pairing.machine_id}-receipts.jsonl`));
114
- await journal.load();
115
- const repositories = async () => (await readConfig(paths.config)).repositories;
122
+ await journal.load(repositoryFolders(config));
123
+ const repositories = async () => repositoryFolders(await readConfig(paths.config));
116
124
  const environment = {
117
125
  ...process.env,
118
126
  PATH: loginPath ?? config.loginPath ?? process.env["PATH"]
@@ -124,17 +132,20 @@ async function runLocal(loginPath, paths, config, version) {
124
132
  }
125
133
  });
126
134
  const status = new GatewayStatus(join(paths.state, "status.json"), executor);
127
- const drivers = builtinHarnesses(environment, executor);
128
- const commands = new Commands(journal, drivers, repositories, {
135
+ drivers = builtinHarnesses(environment, executor, join(paths.state, "acp-groups.json"));
136
+ await drivers.reap();
137
+ const registry = drivers;
138
+ const commands = new Commands(journal, registry, repositories, {
139
+ checkout: new CheckoutPreparer(executor, () => readConfig(paths.config)),
129
140
  activity: new ActivityReporter(async () => (await readConfig(paths.config)).reporting)
130
141
  });
131
142
  await runDaemon({
132
143
  pairing,
133
144
  version,
134
- drivers,
145
+ drivers: registry,
135
146
  commands,
136
147
  tokens: new OAuthTokens(pairing, keychain(pairing.origin)),
137
- repositories: async () => drivers.repositories(await repositories()),
148
+ repositories: async () => registry.repositories(await repositories()),
138
149
  watchFacts: (changed) => watchConfig(paths.config, () => {
139
150
  executor.invalidate();
140
151
  changed();
@@ -146,6 +157,7 @@ async function runLocal(loginPath, paths, config, version) {
146
157
  } finally {
147
158
  process.removeListener("SIGINT", stop);
148
159
  process.removeListener("SIGTERM", stop);
160
+ await drivers?.dispose();
149
161
  await release();
150
162
  }
151
163
  }
@@ -192,7 +204,7 @@ async function printStatus(paths, config, drivers, executor, json) {
192
204
  return;
193
205
  }
194
206
  const view = machineView(status);
195
- const setups = await folderSetups(drivers, config, null);
207
+ const setups = await folderSetups(drivers, config, null, executor);
196
208
  for (const line of statusLines(view, setups, harnessName(drivers))) console.log(line);
197
209
  }
198
210
  function machineView(status) {
@@ -252,10 +264,12 @@ async function configureReporting(args, config, path) {
252
264
  );
253
265
  }
254
266
  var VERBS = {
255
- connect: async ({ args, argument, config, host, paths, drivers, executor }) => {
256
- if (args.length > 2) throw new Error("Usage: tsp-gateway connect [folder]");
267
+ connect: async ({ args, config, host, paths, drivers, executor }) => {
268
+ const choice = connectWorktreeArgs(args);
257
269
  const since = Date.now();
258
- const outcome = await connect(host, config, argument);
270
+ const outcome = await connect(host, config, choice.folder);
271
+ await recordConnectRoot(config, paths.config, outcome.repository?.slug, choice.root);
272
+ await printWorktreeRoots(config, executor);
259
273
  const reported = outcome.loginItem === "installed" ? await awaitDaemonConnection(join(paths.state, "status.json"), since) : null;
260
274
  const status = await readStatus(
261
275
  paths,
@@ -264,10 +278,12 @@ var VERBS = {
264
278
  executor,
265
279
  outcome.loginItem === "installed" && reported === null ? "Starting" : void 0
266
280
  );
267
- const setups = await folderSetups(drivers, config, outcome.repository);
281
+ const setups = await folderSetups(drivers, config, outcome.repository, executor);
268
282
  for (const line of connectLines(machineView(status), setups, harnessName(drivers)))
269
283
  console.log(line);
270
284
  },
285
+ config: worktreesCommand,
286
+ worktrees: worktreesCommand,
271
287
  disconnect: async ({ args, host, config }) => {
272
288
  if (args.length !== 1) throw new Error("Usage: tsp-gateway disconnect");
273
289
  const outcome = await disconnect(host, config);
@@ -287,9 +303,9 @@ var VERBS = {
287
303
  );
288
304
  },
289
305
  remove: async ({ argument, config, paths }) => {
290
- if (!argument || !validSlug(argument.toLowerCase()))
291
- throw new Error("Usage: tsp-gateway remove <owner/name>");
292
- delete config.repositories[argument.toLowerCase()];
306
+ const repository = argument ? parseRepositoryRemote(argument) : null;
307
+ if (!repository) throw new Error("Usage: tsp-gateway remove <host/owner/name>");
308
+ delete config.repositories[repositoryKey(repository)];
293
309
  await saveConfig(paths.config, config);
294
310
  console.log("Repository removed. The running gateway picks up the change automatically.");
295
311
  },
@@ -326,7 +342,7 @@ async function main(args) {
326
342
  const verb = verbNamed(command);
327
343
  if (!verb) {
328
344
  console.log(
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"
345
+ "Usage: tsp-gateway connect [folder] | disconnect | pair | add <folder> | remove <slug> | configure-launch <json> | configure-reporting <activity|off> | status [--json] | worktrees | start | install | uninstall | unpair"
330
346
  );
331
347
  return;
332
348
  }