@loucompanion/forge-bridge 0.2.1-dev.573a8a5fa582 → 0.2.1-dev.7171bf414613

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.
Files changed (121) hide show
  1. package/README.md +38 -2
  2. package/dist/bridge/bridge-state-io.d.ts +6 -2
  3. package/dist/bridge/bridge-state-io.js +22 -4
  4. package/dist/bridge/bridge.service.d.ts +10 -0
  5. package/dist/bridge/bridge.service.js +62 -92
  6. package/dist/bridge/bridge.types.d.ts +6 -0
  7. package/dist/bridge/default-session-service.d.ts +13 -0
  8. package/dist/bridge/default-session-service.js +22 -0
  9. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  10. package/dist/bridge/dispatch-offer-policy.js +58 -0
  11. package/dist/cleanup/cleanup-wip.js +3 -3
  12. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  13. package/dist/cleanup/forge-owned-paths.js +9 -0
  14. package/dist/cli/cli.help.js +1 -1
  15. package/dist/cli/cli.service.js +3 -3
  16. package/dist/cli/local-config.d.ts +2 -0
  17. package/dist/cli/local-config.js +3 -0
  18. package/dist/runtime/host-load-capacity.d.ts +198 -0
  19. package/dist/runtime/host-load-capacity.js +353 -0
  20. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  21. package/dist/runtime/host-load-child-environment.js +35 -1
  22. package/dist/runtime/host-load-governor-config.d.ts +23 -2
  23. package/dist/runtime/host-load-governor-config.js +20 -2
  24. package/dist/runtime/host-load-governor.d.ts +81 -1
  25. package/dist/runtime/host-load-governor.js +184 -15
  26. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  27. package/dist/runtime/host-load-live-test-slots.js +193 -0
  28. package/dist/runtime/host-load-sampler.d.ts +17 -0
  29. package/dist/runtime/host-load-sampler.js +24 -0
  30. package/dist/runtime/host-load-step-run.d.ts +37 -3
  31. package/dist/runtime/host-load-step-run.js +63 -7
  32. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  33. package/dist/runtime/host-load-test-slot.js +19 -7
  34. package/dist/sandbox/runtime.d.ts +1 -2
  35. package/dist/sandbox/runtime.js +7 -13
  36. package/dist/sandbox/sandbox-input.d.ts +22 -0
  37. package/dist/sandbox/sandbox-input.js +49 -0
  38. package/dist/sandbox/workspace.service.js +15 -2
  39. package/dist/session/managed-attempt-tools.js +6 -29
  40. package/dist/session/managed-build-receipt.d.ts +3 -1
  41. package/dist/session/managed-build-receipt.js +5 -2
  42. package/dist/session/managed-command-environment.d.ts +8 -0
  43. package/dist/session/managed-command-environment.js +28 -0
  44. package/dist/session/managed-command-host-load.d.ts +10 -5
  45. package/dist/session/managed-command-host-load.js +18 -14
  46. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  47. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  48. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  49. package/dist/session/phase-completion.artifacts.js +63 -165
  50. package/dist/session/phase-completion.d.ts +25 -2
  51. package/dist/session/phase-completion.helpers.js +5 -53
  52. package/dist/session/phase-completion.js +15 -32
  53. package/dist/session/phase-completion.mcp-args.js +69 -2
  54. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  55. package/dist/session/phase-completion.phase-aliases.js +43 -0
  56. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  57. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  58. package/dist/session/phase-completion.pr-review-threads.d.ts +34 -0
  59. package/dist/session/phase-completion.pr-review-threads.js +90 -0
  60. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  61. package/dist/session/phase-completion.pr-review-validation.js +215 -0
  62. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  63. package/dist/session/phase-completion.pr-review.js +294 -0
  64. package/dist/session/phase-completion.prompts.d.ts +1 -1
  65. package/dist/session/phase-completion.prompts.js +14 -0
  66. package/dist/session/phase-completion.runtime.js +9 -3
  67. package/dist/session/phase-completion.schemas.js +12 -2
  68. package/dist/session/phase-completion.validation.d.ts +1 -0
  69. package/dist/session/phase-completion.validation.js +9 -1
  70. package/dist/session/pr-review-diff-base.d.ts +18 -0
  71. package/dist/session/pr-review-diff-base.js +45 -0
  72. package/dist/session/pr-review-placement.d.ts +50 -0
  73. package/dist/session/pr-review-placement.js +91 -0
  74. package/dist/session/pre-publication-change-set.d.ts +62 -0
  75. package/dist/session/pre-publication-change-set.js +166 -0
  76. package/dist/session/pre-publication-host-load.js +6 -5
  77. package/dist/session/pre-publication-process.js +3 -2
  78. package/dist/session/pre-publication-validation.d.ts +2 -1
  79. package/dist/session/pre-publication-validation.js +31 -36
  80. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  81. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  82. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  83. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  84. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  85. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  86. package/dist/session/provider-cli/pr-review-prompt.d.ts +11 -0
  87. package/dist/session/provider-cli/pr-review-prompt.js +132 -0
  88. package/dist/session/provider-cli/pre-publication-repair.js +7 -3
  89. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  90. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  91. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  92. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  93. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  94. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -13
  95. package/dist/session/provider-cli/provider-cli.prompts.js +123 -107
  96. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  97. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  98. package/dist/session/provider-cli/provider-cli.runtime.d.ts +7 -0
  99. package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
  100. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  101. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  102. package/dist/session/provider-cli/provider-cli.service.d.ts +11 -17
  103. package/dist/session/provider-cli/provider-cli.service.js +24 -139
  104. package/dist/session/sandbox-host-capacity-gate.js +28 -6
  105. package/dist/session/session.parse-helpers.d.ts +10 -0
  106. package/dist/session/session.parse-helpers.js +84 -0
  107. package/dist/session/session.runtime-refresh.d.ts +46 -0
  108. package/dist/session/session.runtime-refresh.js +116 -0
  109. package/dist/session/session.service.d.ts +2 -1
  110. package/dist/session/session.service.js +40 -95
  111. package/dist/session/session.types.d.ts +4 -0
  112. package/dist/session/session.types.js +7 -77
  113. package/dist/session/session.types.pr-review.d.ts +59 -0
  114. package/dist/session/session.types.pr-review.js +53 -0
  115. package/dist/version.d.ts +1 -1
  116. package/dist/version.js +1 -1
  117. package/dist/worktree/artifact-injector.js +24 -0
  118. package/dist/worktree/worktree.service.d.ts +22 -0
  119. package/dist/worktree/worktree.service.js +116 -12
  120. package/dist/worktree/worktree.types.d.ts +7 -0
  121. package/package.json +1 -1
@@ -36,10 +36,10 @@ export class GitWorktreeService {
36
36
  async prepare(request) {
37
37
  const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
38
38
  const baseBranch = normalizeBranchName(request.baseBranch, "develop");
39
+ const detachedHeadSha = normalizeDetachedHeadSha(request.detachedHeadSha);
39
40
  const shortId = request.workItem.id.replace(/-/g, "").slice(0, 12);
40
41
  const kind = safeSegment(request.workItem.kind, "work-item");
41
- const fallbackWorktreeKey = `${kind}/${shortId}`;
42
- const worktreeKey = request.worktreeKey?.trim() || fallbackWorktreeKey;
42
+ const worktreeKey = request.worktreeKey?.trim() || `${kind}/${shortId}`;
43
43
  const worktreeSegments = worktreeKeySegments(worktreeKey, kind, shortId);
44
44
  const branchName = normalizeBranchName(worktreeSegments.join("/"), "work-item/unknown");
45
45
  const creationCoordinationPath = this.repoCreationCoordinationPath(request.repo, allowedRoot);
@@ -48,7 +48,9 @@ export class GitWorktreeService {
48
48
  });
49
49
  const { worktreePath: resolvedWorktreePath, ...preparedState } = await this.coordinator.withLock(repoPath, async () => {
50
50
  await this.ensureGitIdentity(repoPath);
51
- const baseStartPoint = await this.resolveBaseStartPoint(repoPath, baseBranch, branchName);
51
+ const baseStartPoint = detachedHeadSha
52
+ ? await this.resolveReviewHead(repoPath, detachedHeadSha)
53
+ : await this.resolveBaseStartPoint(repoPath, baseBranch, branchName);
52
54
  const worktreeRoot = resolveManagedWorktreeRoot(allowedRoot, repoPath);
53
55
  const worktreePath = path.join(worktreeRoot, ...worktreeSegments);
54
56
  const resolvedWorktreeParent = await ensureDirectory(path.dirname(worktreePath));
@@ -63,8 +65,7 @@ export class GitWorktreeService {
63
65
  await this.git.run(repoPath, ["worktree", "prune", "--expire", "now"]);
64
66
  const registeredWorktreePath = await this.registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments);
65
67
  if (!registeredWorktreePath) {
66
- const originSync = await this.addWorktree(request, repoPath, branchName, worktreePath, baseStartPoint);
67
- return await this.withRestoredWip(request, repoPath, branchName, await resolveExistingDirectoryPath(worktreePath), originSync);
68
+ return await this.createWorktree(request, { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha });
68
69
  }
69
70
  // The selected checkout can change when a Bridge reconnects or a local
70
71
  // runner takes over. Its managed root therefore changes even though the
@@ -85,13 +86,17 @@ export class GitWorktreeService {
85
86
  allowedRoot,
86
87
  });
87
88
  }
88
- const currentBranch = await this.currentBranch(existingWorktreePath);
89
- if (currentBranch !== branchName) {
90
- throw new Error(`Existing worktree ${existingWorktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
91
- }
92
- const originSync = await this.refreshReusedWorktree(request, existingWorktreePath, branchName, baseStartPoint);
93
- return await this.withRestoredWip(request, repoPath, branchName, existingWorktreePath, originSync);
89
+ return await this.reuseWorktree(request, {
90
+ repoPath,
91
+ branchName,
92
+ worktreePath: existingWorktreePath,
93
+ baseStartPoint,
94
+ detachedHeadSha,
95
+ });
94
96
  });
97
+ if (detachedHeadSha) {
98
+ await this.assertDetachedAtHead(resolvedWorktreePath, detachedHeadSha);
99
+ }
95
100
  const { hydratedPriorPhaseArtifactCount, qaReworkPacketPath } = await materializeWorktreeInputs(resolvedWorktreePath, request, this.git);
96
101
  const dependencyWarm = await this.warmDependencies(request, repoPath, resolvedWorktreePath, allowedRoot);
97
102
  return {
@@ -107,8 +112,80 @@ export class GitWorktreeService {
107
112
  lane: request.lane,
108
113
  wipAttempt: request.wipAttempt ?? null,
109
114
  ...preparedState,
115
+ ...(detachedHeadSha ? { detachedHeadSha } : {}),
110
116
  };
111
117
  }
118
+ /**
119
+ * Creates the lease's worktree. A review's is detached at the review head: no lease branch is
120
+ * created and no WIP is restored. Any other is on the lease branch with the story's WIP restored.
121
+ */
122
+ async createWorktree(request, checkout) {
123
+ const { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha } = checkout;
124
+ if (detachedHeadSha) {
125
+ await this.git.run(repoPath, ["worktree", "add", "--detach", worktreePath, detachedHeadSha]);
126
+ return { worktreePath: await resolveExistingDirectoryPath(worktreePath) };
127
+ }
128
+ const originSync = await this.addWorktree(request, repoPath, branchName, worktreePath, baseStartPoint);
129
+ return await this.withRestoredWip(request, repoPath, branchName, await resolveExistingDirectoryPath(worktreePath), originSync);
130
+ }
131
+ /**
132
+ * Readies a surviving worktree. A review reads one exact commit, so whatever state a prior attempt
133
+ * left behind is discarded. Any other must still be on the lease branch; it is refreshed for this
134
+ * pass and given the story's WIP.
135
+ */
136
+ async reuseWorktree(request, checkout) {
137
+ const { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha } = checkout;
138
+ if (detachedHeadSha) {
139
+ await this.git.run(worktreePath, ["checkout", "--force", "--detach", detachedHeadSha]);
140
+ await this.git.run(worktreePath, ["reset", "--hard", detachedHeadSha]);
141
+ await this.git.run(worktreePath, ["clean", "-fd"]);
142
+ return { worktreePath };
143
+ }
144
+ const currentBranch = await this.currentBranch(worktreePath);
145
+ if (currentBranch !== branchName) {
146
+ throw new Error(`Existing worktree ${worktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
147
+ }
148
+ const originSync = await this.refreshReusedWorktree(request, worktreePath, branchName, baseStartPoint);
149
+ return await this.withRestoredWip(request, repoPath, branchName, worktreePath, originSync);
150
+ }
151
+ /**
152
+ * Finds the review head in the repository, fetching it when the local clone has not seen it
153
+ * yet, and returns the full commit id.
154
+ */
155
+ async resolveReviewHead(repoPath, headSha) {
156
+ const resolve = async () => {
157
+ const resolved = await this.git.run(repoPath, ["rev-parse", "--verify", "--quiet", `${headSha}^{commit}`])
158
+ .then((value) => value.trim())
159
+ .catch(() => "");
160
+ return /^[0-9a-f]{40,64}$/iu.test(resolved) ? resolved : null;
161
+ };
162
+ const local = await resolve();
163
+ if (local) {
164
+ return local;
165
+ }
166
+ const origin = await this.git.run(repoPath, ["remote", "get-url", "origin"]).catch(() => "");
167
+ if (origin.trim().length > 0) {
168
+ await this.git.run(repoPath, ["fetch", "--prune", "origin"]).catch(() => undefined);
169
+ const afterFetch = await resolve();
170
+ if (afterFetch) {
171
+ return afterFetch;
172
+ }
173
+ await this.git.run(repoPath, ["fetch", "origin", headSha]).catch(() => undefined);
174
+ const afterShaFetch = await resolve();
175
+ if (afterShaFetch) {
176
+ return afterShaFetch;
177
+ }
178
+ }
179
+ throw new Error(`Review head ${headSha} was not found in the repository or on origin.`);
180
+ }
181
+ async assertDetachedAtHead(worktreePath, headSha) {
182
+ const head = (await this.git.run(worktreePath, ["rev-parse", "HEAD"])).trim().toLowerCase();
183
+ const detached = await this.git.run(worktreePath, ["symbolic-ref", "--quiet", "HEAD"]).then(() => false).catch(() => true);
184
+ const expected = (await this.git.run(worktreePath, ["rev-parse", "--verify", `${headSha}^{commit}`])).trim().toLowerCase();
185
+ if (head !== expected || !detached) {
186
+ throw new Error(`Review worktree ${worktreePath} must be detached at ${headSha}, found ${detached ? "detached" : "a branch"} HEAD ${head}.`);
187
+ }
188
+ }
112
189
  async warmDependencies(request, repoPath, worktreePath, allowedRoot) {
113
190
  if (!requiresMutableEnvironmentPreparation(request))
114
191
  return undefined;
@@ -175,6 +252,10 @@ export class GitWorktreeService {
175
252
  });
176
253
  }
177
254
  async settleWip(handle, outcome) {
255
+ // A review worktree holds the reviewed head plus whatever the review session left in it. That is
256
+ // never saved or published: a WIP snapshot would push it to a ref anyone who can read the repo can list.
257
+ if (handle.detachedHeadSha)
258
+ return {};
178
259
  return await settleSessionWip(handle, outcome);
179
260
  }
180
261
  async registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments) {
@@ -201,7 +282,10 @@ export class GitWorktreeService {
201
282
  return;
202
283
  }
203
284
  await this.coordinator.withLock(handle.repoPath, async () => {
204
- if (await directoryExists(handle.worktreePath)) {
285
+ if (handle.detachedHeadSha) {
286
+ await this.removeReviewWorktree(handle);
287
+ }
288
+ else if (await directoryExists(handle.worktreePath)) {
205
289
  // Never delete work that could not be saved: this throws and keeps the worktree.
206
290
  await guardWorktreeRelease(handle);
207
291
  // On Windows, `git worktree remove` can delete the `.git` link and then
@@ -231,6 +315,16 @@ export class GitWorktreeService {
231
315
  await sweepBranchesAfterRelease(this.git, handle, this.leaseStateRoot, releaseSweepLimit);
232
316
  });
233
317
  }
318
+ /**
319
+ * Removes a review worktree without saving anything from it (see settleWip). A failed removal leaves
320
+ * the folder for the next prepare of that head, which resets and cleans it, or for stale cleanup.
321
+ */
322
+ async removeReviewWorktree(handle) {
323
+ if (!(await directoryExists(handle.worktreePath)))
324
+ return;
325
+ await this.git.run(handle.repoPath, ["worktree", "remove", "--force", handle.worktreePath]).catch(() => undefined);
326
+ await fs.rm(handle.worktreePath, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }).catch(() => undefined);
327
+ }
234
328
  async restoreOrphanedWorktree(input) {
235
329
  const orphanStat = await fs.lstat(input.worktreePath);
236
330
  if (orphanStat.isSymbolicLink() || !orphanStat.isDirectory()) {
@@ -561,6 +655,16 @@ async function overlayEntry(input) {
561
655
  backupPath: preservedBasePath,
562
656
  });
563
657
  }
658
+ function normalizeDetachedHeadSha(value) {
659
+ const trimmed = value?.trim().toLowerCase() ?? "";
660
+ if (trimmed.length === 0) {
661
+ return null;
662
+ }
663
+ if (!/^[0-9a-f]{40}$|^[0-9a-f]{64}$/u.test(trimmed)) {
664
+ throw new Error("Review head_sha must be a full 40 or 64 character commit id.");
665
+ }
666
+ return trimmed;
667
+ }
564
668
  export function normalizeBranchName(value, fallback) {
565
669
  const branch = (value?.trim() || fallback).trim();
566
670
  if (branch.length === 0 ||
@@ -24,6 +24,11 @@ export interface WorktreePrepareRequest {
24
24
  readonly warmPathOverrides?: readonly string[];
25
25
  readonly applicationRuntimeRequired?: boolean;
26
26
  readonly preserveExistingState?: boolean;
27
+ /**
28
+ * Review-only checkout: the worktree is detached at exactly this commit and verified with
29
+ * `git rev-parse HEAD`. The lease branch is never created or advanced.
30
+ */
31
+ readonly detachedHeadSha?: string | null;
27
32
  /** The session this worktree is prepared for; names its WIP snapshots and enables restoring one. */
28
33
  readonly sessionId?: string | null;
29
34
  /** Forge's issued attempt for this dispatch (sandbox.wipAttempt), stamped on its WIP refs: newest work wins. */
@@ -45,6 +50,8 @@ export interface WorktreeHandle {
45
50
  readonly dependencyWarm?: WarmDependenciesResult;
46
51
  readonly qaReworkPacketPath?: string;
47
52
  readonly hydratedPriorPhaseArtifactCount?: number;
53
+ /** Set when the worktree was checked out detached at a review head. */
54
+ readonly detachedHeadSha?: string;
48
55
  readonly sessionId?: string | null;
49
56
  readonly lane?: string;
50
57
  /** Forge's issued attempt for the dispatch the worktree was prepared for; null from older servers. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loucompanion/forge-bridge",
3
- "version": "0.2.1-dev.573a8a5fa582",
3
+ "version": "0.2.1-dev.7171bf414613",
4
4
  "description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",