@loucompanion/forge-bridge 0.1.4-dev.9e8a5b93cbcb → 0.1.4-dev.c2f22d1dd395

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 (45) hide show
  1. package/dist/bridge/bridge.service.d.ts +12 -1
  2. package/dist/bridge/bridge.service.js +51 -5
  3. package/dist/bridge/bridge.types.d.ts +6 -0
  4. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  5. package/dist/bridge/dispatch-result-outbox.js +31 -6
  6. package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
  7. package/dist/runtime/attempt-process-supervisor.js +50 -0
  8. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  9. package/dist/runtime/host-database-capability-boundary.js +1 -0
  10. package/dist/runtime/host-facts.d.ts +35 -0
  11. package/dist/runtime/host-facts.js +95 -0
  12. package/dist/runtime/host-load-sampler.d.ts +83 -0
  13. package/dist/runtime/host-load-sampler.js +164 -0
  14. package/dist/runtime/host-pressure-stall.d.ts +41 -0
  15. package/dist/runtime/host-pressure-stall.js +121 -0
  16. package/dist/runtime/host-runtime-contract.d.ts +1 -0
  17. package/dist/runtime/host-runtime-contract.js +2 -0
  18. package/dist/runtime/host-runtime-lease.js +55 -9
  19. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  20. package/dist/runtime/managed-command-teardown.js +607 -0
  21. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  22. package/dist/runtime/playwright-browser-cache.js +227 -0
  23. package/dist/runtime/playwright-host-runtime-adapter.d.ts +11 -0
  24. package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
  25. package/dist/session/managed-attempt-tools.d.ts +25 -0
  26. package/dist/session/managed-attempt-tools.js +212 -15
  27. package/dist/session/managed-build-coordinator.d.ts +1 -1
  28. package/dist/session/managed-build-coordinator.js +4 -1
  29. package/dist/session/phase-completion.artifacts.js +4 -0
  30. package/dist/session/phase-completion.runtime.js +22 -17
  31. package/dist/session/pre-publication-process.d.ts +20 -0
  32. package/dist/session/pre-publication-process.js +97 -0
  33. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  34. package/dist/session/pre-publication-skipped-tests.js +109 -0
  35. package/dist/session/pre-publication-validation.js +27 -57
  36. package/dist/session/provider-cli/provider-cli.artifacts.js +2 -9
  37. package/dist/session/provider-cli/provider-cli.process.d.ts +4 -1
  38. package/dist/session/provider-cli/provider-cli.process.js +88 -10
  39. package/dist/session/provider-cli/provider-cli.service.js +61 -10
  40. package/dist/session/publishable-worktree-changes.d.ts +45 -0
  41. package/dist/session/publishable-worktree-changes.js +177 -0
  42. package/dist/session/session.types.js +3 -0
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,177 @@
1
+ import fs from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { GitClient } from "../shared/git/git.js";
5
+ import { NodeProcessRunner } from "../shared/process/process.js";
6
+ /**
7
+ * Forge runtime output that is never published, whether or not the target repository
8
+ * tracks other `.forge/` content. Completion artifacts and evidence live here.
9
+ */
10
+ const runtimeOnlyPathPrefixes = [".local/", ".forge/work-items/", ".forge/stories/"];
11
+ const resetBatchSize = 200;
12
+ /**
13
+ * Decides whether a staged change is Forge runtime output rather than an author edit.
14
+ *
15
+ * `.local/`, `.forge/work-items/` and `.forge/stories/` are always runtime output. Any
16
+ * other `.forge/` path is runtime output only when HEAD does not track it (status `A`):
17
+ * that covers injected managed commands, hooks and skills. The injector never overwrites a
18
+ * tracked `.forge/` file and restores one that matches the managed body, so a tracked
19
+ * `.forge/` file that differs from HEAD is an author edit and must be published.
20
+ */
21
+ export function isNonPublishableWorktreeChange(relativePath, status) {
22
+ const normalized = relativePath.trim().replaceAll("\\", "/");
23
+ if (normalized === ".local" || runtimeOnlyPathPrefixes.some(prefix => normalized.startsWith(prefix))) {
24
+ return true;
25
+ }
26
+ if (normalized === ".forge" || normalized.startsWith(".forge/")) {
27
+ return status.trim().toUpperCase().startsWith("A");
28
+ }
29
+ return false;
30
+ }
31
+ /** Stages every publishable worktree change in the real index and returns both sets. */
32
+ export async function stagePublishableWorktreeChangeSet(git, worktreePath) {
33
+ await git.run(worktreePath, ["add", "-A"]);
34
+ const excluded = (await readStagedChanges(git, worktreePath))
35
+ .filter(change => isNonPublishableWorktreeChange(change.path, change.status))
36
+ .map(change => change.path);
37
+ for (let index = 0; index < excluded.length; index += resetBatchSize) {
38
+ const batch = excluded.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
39
+ await git.run(worktreePath, ["reset", "-q", "--", ...batch]);
40
+ }
41
+ const publishable = (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
42
+ .split(/\r?\n/)
43
+ .map(line => line.trim())
44
+ .filter(Boolean);
45
+ return { publishable, excluded: [...new Set(excluded)].sort() };
46
+ }
47
+ /**
48
+ * Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
49
+ * touching the worktree's index, using a throwaway copy of it. Returns null when
50
+ * `worktreePath` is not the root of a git worktree.
51
+ */
52
+ export async function readPublishableWorktreeChangeSet(worktreePath, processRunner = new NodeProcessRunner()) {
53
+ const resolvedWorktree = path.resolve(worktreePath);
54
+ const git = new GitClient(processRunner);
55
+ let topLevel;
56
+ try {
57
+ topLevel = (await git.run(resolvedWorktree, ["rev-parse", "--show-toplevel"])).trim();
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ if (!topLevel || !await samePath(topLevel, resolvedWorktree)) {
63
+ return null;
64
+ }
65
+ const realIndex = path.resolve(resolvedWorktree, (await git.run(resolvedWorktree, ["rev-parse", "--git-path", "index"])).trim());
66
+ const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "forge-publishable-index-"));
67
+ try {
68
+ const tempIndex = path.join(tempRoot, "index");
69
+ await fs.copyFile(realIndex, tempIndex).catch((error) => {
70
+ if (error.code !== "ENOENT")
71
+ throw error;
72
+ });
73
+ const tempIndexGit = new GitClient({
74
+ run: request => processRunner.run({
75
+ ...request,
76
+ env: { ...(request.env ?? process.env), GIT_INDEX_FILE: tempIndex },
77
+ }),
78
+ });
79
+ return await stagePublishableWorktreeChangeSet(tempIndexGit, resolvedWorktree);
80
+ }
81
+ finally {
82
+ await fs.rm(tempRoot, { recursive: true, force: true });
83
+ }
84
+ }
85
+ /** Compares claimed `changed_files` paths with the publishable diff. */
86
+ export function diffClaimedChangedFiles(claimedPaths, publishablePaths) {
87
+ const claimed = new Set(claimedPaths.map(normalizeChangedFilePath).filter(Boolean));
88
+ const actual = new Set(publishablePaths.map(normalizeChangedFilePath).filter(Boolean));
89
+ return {
90
+ missing: [...actual].filter(filePath => !claimed.has(filePath)).sort(),
91
+ unexpected: [...claimed].filter(filePath => !actual.has(filePath)).sort(),
92
+ };
93
+ }
94
+ export function normalizeChangedFilePath(value) {
95
+ return value.trim().replaceAll("\\", "/");
96
+ }
97
+ async function readStagedChanges(git, worktreePath) {
98
+ const fields = (await git.run(worktreePath, ["diff", "--cached", "--name-status", "--no-renames", "-z"]))
99
+ .split("\0");
100
+ const changes = [];
101
+ for (let index = 0; index + 1 < fields.length; index += 2) {
102
+ const status = fields[index].trim();
103
+ const filePath = fields[index + 1];
104
+ if (status && filePath)
105
+ changes.push({ status, path: filePath });
106
+ }
107
+ return changes;
108
+ }
109
+ async function samePath(left, right) {
110
+ const [realLeft, realRight] = await Promise.all([
111
+ fs.realpath(left).catch(() => path.resolve(left)),
112
+ fs.realpath(right).catch(() => path.resolve(right)),
113
+ ]);
114
+ return process.platform === "win32"
115
+ ? realLeft.toLowerCase() === realRight.toLowerCase()
116
+ : realLeft === realRight;
117
+ }
118
+ /**
119
+ * In-tool check for `forge.complete_comment_repair`: rejects a pass payload whose
120
+ * `changed_files` differs from what Forge would publish, so the agent can correct it
121
+ * in the same turn instead of failing at publication.
122
+ */
123
+ export async function assertClaimedChangedFilesMatchPublishableDiff(worktreePath, payload, toolName, processRunner) {
124
+ const changeSet = await readPublishableWorktreeChangeSet(worktreePath, processRunner);
125
+ if (!changeSet)
126
+ return;
127
+ const claimed = Array.isArray(payload.changed_files)
128
+ ? payload.changed_files.map(value => String(value?.path ?? ""))
129
+ : [];
130
+ const { missing, unexpected } = diffClaimedChangedFiles(claimed, changeSet.publishable);
131
+ if (missing.length === 0 && unexpected.length === 0)
132
+ return;
133
+ const details = [
134
+ missing.length > 0 ? `Publishable changes missing from changed_files: ${missing.join(", ")}.` : "",
135
+ unexpected.length > 0 ? `changed_files entries that Forge will not publish: ${unexpected.join(", ")}.` : "",
136
+ ].filter(Boolean).join(" ");
137
+ throw new Error(`changed_files must list exactly the files Forge will publish. ${details} `
138
+ + "Forge publishes every source change, including edits to tracked .forge/ files; it never publishes "
139
+ + ".local/, .forge/work-items/, .forge/stories/, or new untracked .forge/ files. "
140
+ + `Correct changed_files (or the worktree) and call ${toolName} again.`);
141
+ }
142
+ /**
143
+ * Returns the given paths whose worktree content differs from HEAD but is not in the
144
+ * publishable set: excluded runtime output, and untracked or git-ignored files that are
145
+ * never staged at all (for example an injected `.forge/` file in a repository that ignores
146
+ * `.forge/`). A review finding on such a path cannot be fixed by the published commit.
147
+ */
148
+ export async function findUnpublishedWorktreePaths(git, worktreePath, paths, publishablePaths) {
149
+ const candidates = [...new Set(paths.map(normalizeChangedFilePath).filter(Boolean))];
150
+ if (candidates.length === 0)
151
+ return [];
152
+ const publishable = new Set(publishablePaths.map(normalizeChangedFilePath));
153
+ const unpublished = new Set();
154
+ for (let index = 0; index < candidates.length; index += resetBatchSize) {
155
+ const batch = candidates.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
156
+ const output = await git.run(worktreePath, [
157
+ // `traditional` with `--untracked-files=all` lists each file inside an ignored directory.
158
+ "status", "--porcelain=v1", "-z", "--no-renames", "--ignored=traditional", "--untracked-files=all", "--", ...batch,
159
+ ]);
160
+ for (const entry of output.split("\0")) {
161
+ if (entry.length < 4)
162
+ continue;
163
+ const reported = normalizeChangedFilePath(entry.slice(3));
164
+ if (!reported)
165
+ continue;
166
+ // A collapsed directory entry ("dir/") covers every candidate beneath it.
167
+ const matches = reported.endsWith("/")
168
+ ? candidates.filter(candidate => candidate.startsWith(reported))
169
+ : [reported];
170
+ for (const filePath of matches) {
171
+ if (!publishable.has(filePath))
172
+ unpublished.add(filePath);
173
+ }
174
+ }
175
+ }
176
+ return [...unpublished].sort();
177
+ }
@@ -481,6 +481,9 @@ function unvalidatedFailureFactsForCode(code, source) {
481
481
  if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
482
482
  return facts(code, "domain", "validation", source, "non_retryable", "fix_input");
483
483
  }
484
+ if (code === "comment_repair_changed_files_mismatch") {
485
+ return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
486
+ }
484
487
  if (["generated_output_reset_failed", "generated_output_reset_unverified", "worktree_prepare_failed", "host_runtime_ledger_write_failed", "host_diagnostics_temporary_unavailable", "attempt_process_supervisor_start_failed", "attempt_process_supervisor_start_timeout"].includes(code)) {
485
488
  return facts(code, "transport", "prepare", source, "retryable", "retry_dispatch");
486
489
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const forgeBridgeVersion = "0.1.4-dev.9e8a5b93cbcb";
1
+ export declare const forgeBridgeVersion = "0.1.4-dev.c2f22d1dd395";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const forgeBridgeVersion = "0.1.4-dev.9e8a5b93cbcb";
1
+ export const forgeBridgeVersion = "0.1.4-dev.c2f22d1dd395";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loucompanion/forge-bridge",
3
- "version": "0.1.4-dev.9e8a5b93cbcb",
3
+ "version": "0.1.4-dev.c2f22d1dd395",
4
4
  "description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",