@treestructuredplanning/gateway 0.1.3 → 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
@@ -50,6 +50,8 @@ so it also fixes a stopped, outdated or revoked gateway. If TSP cannot be reache
50
50
  changes; try again later. The login item runs the copy of the gateway that `connect` ran
51
51
  from. With `npx` that is npm's cache, so if you clear that cache, run `connect` again.
52
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
+
53
55
  ## Disconnect and uninstall
54
56
 
55
57
  ```sh
@@ -80,7 +82,7 @@ in its place.
80
82
  | `disconnect` | Remove the login item, then unpair. |
81
83
  | `pair` | Pair this computer with your TSP account (replaces any existing pairing). |
82
84
  | `add <folder>` | Register a repository folder. |
83
- | `remove <owner/name>` | Unregister a repository. |
85
+ | `remove <host/owner/name>` | Unregister a repository. |
84
86
  | `configure-launch '<json>'` | Set how sessions get your shell environment (see below). |
85
87
  | `configure-reporting <level>` | `activity` (default) or `off`: whether session activity is sent to TSP. |
86
88
  | `status [--json]` | Show pairing, connection and each folder's next steps; `--json` is for scripts. |
@@ -217,3 +219,44 @@ folder only after `disconnect`, once no gateway is running.
217
219
 
218
220
  See the [TSP documentation](https://treestructuredplanning.com/docs) or email
219
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-RM5C4AZN.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.3",
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:*",
@@ -112,8 +119,8 @@ async function runLocal(loginPath, paths, config, version) {
112
119
  let drivers;
113
120
  try {
114
121
  const journal = new Journal(join(paths.state, `${pairing.machine_id}-receipts.jsonl`));
115
- await journal.load();
116
- const repositories = async () => (await readConfig(paths.config)).repositories;
122
+ await journal.load(repositoryFolders(config));
123
+ const repositories = async () => repositoryFolders(await readConfig(paths.config));
117
124
  const environment = {
118
125
  ...process.env,
119
126
  PATH: loginPath ?? config.loginPath ?? process.env["PATH"]
@@ -129,6 +136,7 @@ async function runLocal(loginPath, paths, config, version) {
129
136
  await drivers.reap();
130
137
  const registry = drivers;
131
138
  const commands = new Commands(journal, registry, repositories, {
139
+ checkout: new CheckoutPreparer(executor, () => readConfig(paths.config)),
132
140
  activity: new ActivityReporter(async () => (await readConfig(paths.config)).reporting)
133
141
  });
134
142
  await runDaemon({
@@ -196,7 +204,7 @@ async function printStatus(paths, config, drivers, executor, json) {
196
204
  return;
197
205
  }
198
206
  const view = machineView(status);
199
- const setups = await folderSetups(drivers, config, null);
207
+ const setups = await folderSetups(drivers, config, null, executor);
200
208
  for (const line of statusLines(view, setups, harnessName(drivers))) console.log(line);
201
209
  }
202
210
  function machineView(status) {
@@ -256,10 +264,12 @@ async function configureReporting(args, config, path) {
256
264
  );
257
265
  }
258
266
  var VERBS = {
259
- connect: async ({ args, argument, config, host, paths, drivers, executor }) => {
260
- 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);
261
269
  const since = Date.now();
262
- 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);
263
273
  const reported = outcome.loginItem === "installed" ? await awaitDaemonConnection(join(paths.state, "status.json"), since) : null;
264
274
  const status = await readStatus(
265
275
  paths,
@@ -268,10 +278,12 @@ var VERBS = {
268
278
  executor,
269
279
  outcome.loginItem === "installed" && reported === null ? "Starting" : void 0
270
280
  );
271
- const setups = await folderSetups(drivers, config, outcome.repository);
281
+ const setups = await folderSetups(drivers, config, outcome.repository, executor);
272
282
  for (const line of connectLines(machineView(status), setups, harnessName(drivers)))
273
283
  console.log(line);
274
284
  },
285
+ config: worktreesCommand,
286
+ worktrees: worktreesCommand,
275
287
  disconnect: async ({ args, host, config }) => {
276
288
  if (args.length !== 1) throw new Error("Usage: tsp-gateway disconnect");
277
289
  const outcome = await disconnect(host, config);
@@ -291,9 +303,9 @@ var VERBS = {
291
303
  );
292
304
  },
293
305
  remove: async ({ argument, config, paths }) => {
294
- if (!argument || !validSlug(argument.toLowerCase()))
295
- throw new Error("Usage: tsp-gateway remove <owner/name>");
296
- 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)];
297
309
  await saveConfig(paths.config, config);
298
310
  console.log("Repository removed. The running gateway picks up the change automatically.");
299
311
  },
@@ -330,7 +342,7 @@ async function main(args) {
330
342
  const verb = verbNamed(command);
331
343
  if (!verb) {
332
344
  console.log(
333
- "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"
334
346
  );
335
347
  return;
336
348
  }