@loucompanion/forge-bridge 0.1.4-dev.e1b4f55fb18d → 0.1.4-dev.e83e5bc6ecce

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.
@@ -5,6 +5,7 @@ import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
5
5
  import { GitClient } from "../shared/git/git.js";
6
6
  import { isSubPath, resolveExistingDirectoryPath, resolvePathIdentity } from "../shared/path/path.js";
7
7
  import { defaultWorktreeCoordinatorStateRoot, resolveManagedWorktreeRootForRepo, } from "../worktree/worktree-paths.js";
8
+ import { isForgeOwnedWorktreePath, isForgeWorktreeContainer, isRuntimeReadinessName } from "./forge-owned-paths.js";
8
9
  import { liveLeaseBranches, readHostRuntimeLeases } from "./host-runtime-ledger.js";
9
10
  import { sweepManagedBranches } from "./managed-branch-sweep.js";
10
11
  const staleRuntimeReadinessAgeMs = 30 * 60 * 1000;
@@ -64,7 +65,7 @@ export class ManagedWorktreeCleanupService {
64
65
  .filter(lease => lease.state !== "released")
65
66
  .map(lease => resolveRuntimeLeasePath(lease.worktreePath)));
66
67
  const metadataRoot = await this.worktreeMetadataRoot(repoPath);
67
- const staleReadinessPaths = await this.staleRuntimeReadinessPaths(listedWorktrees, activeRuntimePaths);
68
+ const staleReadinessPaths = await this.staleRuntimeReadinessPaths(safeRoot, listedWorktrees, activeRuntimePaths);
68
69
  const activeWorktrees = activePaths(listedWorktrees)
69
70
  .filter(activePath => !staleReadinessPaths.some(stalePath => samePath(stalePath, activePath)));
70
71
  if (request.mode === "all") {
@@ -114,7 +115,7 @@ export class ManagedWorktreeCleanupService {
114
115
  const currentRuntimePaths = await Promise.all(currentLeases
115
116
  .filter(lease => lease.state !== "released")
116
117
  .map(lease => resolveRuntimeLeasePath(lease.worktreePath)));
117
- const currentStaleReadinessPaths = await this.staleRuntimeReadinessPaths(currentWorktrees, currentRuntimePaths);
118
+ const currentStaleReadinessPaths = await this.staleRuntimeReadinessPaths(safeRoot, currentWorktrees, currentRuntimePaths);
118
119
  const currentlyProtected = [
119
120
  ...activePaths(currentWorktrees)
120
121
  .filter(activePath => !currentStaleReadinessPaths.some(stalePath => samePath(stalePath, activePath))),
@@ -179,10 +180,10 @@ export class ManagedWorktreeCleanupService {
179
180
  const output = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
180
181
  return parseWorktreeListing(repoPath, output);
181
182
  }
182
- async staleRuntimeReadinessPaths(worktrees, runtimePaths) {
183
+ async staleRuntimeReadinessPaths(worktreeRoot, worktrees, runtimePaths) {
183
184
  const stale = [];
184
185
  for (const worktree of worktrees) {
185
- if (worktree.prunable || !isRuntimeReadinessWorktree(worktree))
186
+ if (worktree.prunable || !isRuntimeReadinessWorktree(worktreeRoot, worktree))
186
187
  continue;
187
188
  if (worktreePathState(worktree.worktreePath, runtimePaths) !== "none")
188
189
  continue;
@@ -247,12 +248,13 @@ export class ManagedWorktreeCleanupService {
247
248
  containsManagedDirectory = await visit(realEntry) || containsManagedDirectory;
248
249
  continue;
249
250
  }
250
- if (await forgeManagedCandidateIdentity(metadataRoot, realEntry)) {
251
+ const relativePath = path.relative(worktreeRoot, realEntry);
252
+ if (isForgeOwnedWorktreePath(relativePath) && await forgeManagedCandidateIdentity(metadataRoot, realEntry)) {
251
253
  candidates.push(realEntry);
252
254
  containsManagedDirectory = true;
253
255
  continue;
254
256
  }
255
- if (await visit(realEntry)) {
257
+ if (isForgeWorktreeContainer(relativePath) && await visit(realEntry)) {
256
258
  containsManagedDirectory = true;
257
259
  continue;
258
260
  }
@@ -426,9 +428,13 @@ function parseWorktreeListing(repoPath, output) {
426
428
  worktrees.push(current);
427
429
  return worktrees;
428
430
  }
429
- function isRuntimeReadinessWorktree(worktree) {
430
- return worktree.branchName?.startsWith("refs/heads/runtime-readiness-") === true
431
- || path.basename(worktree.worktreePath).startsWith("runtime-readiness-");
431
+ // A registered worktree counts as a readiness probe only when Forge made it: its folder sits
432
+ // directly in the managed root under the probe's exact name, and it has the probe's exact branch.
433
+ function isRuntimeReadinessWorktree(worktreeRoot, worktree) {
434
+ const folderName = path.basename(worktree.worktreePath);
435
+ return samePath(path.dirname(worktree.worktreePath), worktreeRoot)
436
+ && isRuntimeReadinessName(folderName)
437
+ && worktree.branchName === `refs/heads/${folderName}`;
432
438
  }
433
439
  function activePaths(worktrees) {
434
440
  return worktrees.filter(entry => !entry.prunable).map(entry => entry.worktreePath);
@@ -0,0 +1,9 @@
1
+ import path from "node:path";
2
+ type PathSeparator = typeof path.posix.sep | typeof path.win32.sep;
3
+ /** True when `relativePath` (relative to the managed root) is a worktree path Forge creates. */
4
+ export declare function isForgeOwnedWorktreePath(relativePath: string, separator?: PathSeparator): boolean;
5
+ /** True when `relativePath` is one of the folders Forge groups its worktrees in. */
6
+ export declare function isForgeWorktreeContainer(relativePath: string, separator?: PathSeparator): boolean;
7
+ /** True for a readiness probe's exact folder or branch name: runtime-readiness-<UUID>. */
8
+ export declare function isRuntimeReadinessName(name: string): boolean;
9
+ export {};
@@ -0,0 +1,53 @@
1
+ // Cleanup may delete a worktree folder only when Forge itself created it for one of its own
2
+ // attempts. Forge places every such worktree at an exact path under the repository's managed root
3
+ // (`<repo parent>/.forge-worktrees/<repo name>`), built from the lease's worktree key:
4
+ // <kind>/<12 hex> a work item (story, task, bug, feature, work_order) or
5
+ // its Architect phase (architect)
6
+ // decompose/<feature|work_order>/<12 hex> a decompose session
7
+ // runtime-readiness-<UUID> a runtime readiness probe (session.service.ts)
8
+ // draft-<32 hex> a drafting session (DraftingService on the server)
9
+ // A release that couldn't finish deleting can leave `<one of those>.forge-release-<UUID>` beside it.
10
+ // Anything else under the root, such as a folder a person or another tool made there, is never
11
+ // removed, even if it is a Git worktree of the same repository.
12
+ import path from "node:path";
13
+ const hex12 = "[0-9a-f]{12}";
14
+ const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
15
+ const releaseSuffix = `(?:\\.forge-release-${uuid})?`;
16
+ const forgeOwnedWorktreePathPattern = new RegExp("^(?:"
17
+ + `(?:story|task|bug|feature|work_order|architect)/${hex12}`
18
+ + `|decompose/(?:feature|work_order)/${hex12}`
19
+ + `|runtime-readiness-${uuid}`
20
+ + "|draft-[0-9a-f]{32}"
21
+ + `)${releaseSuffix}$`);
22
+ const runtimeReadinessNamePattern = new RegExp(`^runtime-readiness-${uuid}$`);
23
+ // Folders that only group Forge's worktrees; cleanup may look inside them but never removes them.
24
+ const forgeWorktreeContainers = new Set([
25
+ "story",
26
+ "task",
27
+ "bug",
28
+ "feature",
29
+ "work_order",
30
+ "architect",
31
+ "decompose",
32
+ "decompose/feature",
33
+ "decompose/work_order",
34
+ ]);
35
+ // Split only on the separators the filesystem itself uses. On POSIX a backslash is an ordinary
36
+ // filename character, so a folder a person named `story\0123456789ab` must not read as Forge's
37
+ // `story/0123456789ab`. Windows accepts both `\` and `/`.
38
+ function normalizeRelativePath(relativePath, separator) {
39
+ const separators = separator === path.win32.sep ? /[\\/]+/u : /\/+/u;
40
+ return relativePath.split(separators).filter(segment => segment.length > 0).join("/");
41
+ }
42
+ /** True when `relativePath` (relative to the managed root) is a worktree path Forge creates. */
43
+ export function isForgeOwnedWorktreePath(relativePath, separator = path.sep) {
44
+ return forgeOwnedWorktreePathPattern.test(normalizeRelativePath(relativePath, separator));
45
+ }
46
+ /** True when `relativePath` is one of the folders Forge groups its worktrees in. */
47
+ export function isForgeWorktreeContainer(relativePath, separator = path.sep) {
48
+ return forgeWorktreeContainers.has(normalizeRelativePath(relativePath, separator));
49
+ }
50
+ /** True for a readiness probe's exact folder or branch name: runtime-readiness-<UUID>. */
51
+ export function isRuntimeReadinessName(name) {
52
+ return runtimeReadinessNamePattern.test(name);
53
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const forgeBridgeVersion = "0.1.4-dev.e1b4f55fb18d";
1
+ export declare const forgeBridgeVersion = "0.1.4-dev.e83e5bc6ecce";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const forgeBridgeVersion = "0.1.4-dev.e1b4f55fb18d";
1
+ export const forgeBridgeVersion = "0.1.4-dev.e83e5bc6ecce";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loucompanion/forge-bridge",
3
- "version": "0.1.4-dev.e1b4f55fb18d",
3
+ "version": "0.1.4-dev.e83e5bc6ecce",
4
4
  "description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",