@bridge_gpt/mcp-server 0.2.73 → 0.2.74

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 (90) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +12 -0
  3. package/build/agents.generated.js +3 -3
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +3 -0
  6. package/build/command-provisioning.js +4 -3
  7. package/build/commands.generated.js +5 -5
  8. package/build/conductor/bridge-api-client.js +26 -1
  9. package/build/conductor/command-drift.js +1 -1
  10. package/build/conductor/declared-extras.js +335 -0
  11. package/build/conductor/doctor.js +2 -0
  12. package/build/conductor/driver-pass-output.js +104 -0
  13. package/build/conductor/driver-pass.js +571 -0
  14. package/build/conductor/epic-branch-ci-inspection.js +61 -16
  15. package/build/conductor/epic-implementer-cli.js +33 -0
  16. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  17. package/build/conductor/epic-server-sfcc.js +58 -80
  18. package/build/conductor/epic-server.js +57 -4
  19. package/build/conductor/gate-discovery.js +46 -6
  20. package/build/conductor/gate-settings-review.js +51 -14
  21. package/build/credential-delivery.js +280 -0
  22. package/build/credential-launch-safety.js +142 -0
  23. package/build/credential-materialization.js +91 -16
  24. package/build/credential-references-node-deps.js +29 -0
  25. package/build/credential-references.js +1394 -0
  26. package/build/credential-references.test-fixtures.js +211 -0
  27. package/build/credential-scan-conventions.js +145 -0
  28. package/build/credential-scan.js +517 -0
  29. package/build/credential-store.js +50 -0
  30. package/build/credentials-cli.js +252 -3
  31. package/build/dependency-install-declarations.js +47 -1
  32. package/build/docs.generated.js +8 -1
  33. package/build/doctor.js +41 -0
  34. package/build/drive-epic.js +297 -37
  35. package/build/epic-branch-ci-summary.js +18 -1
  36. package/build/epic-capability-statement.js +71 -3
  37. package/build/epic-ci-workflow-drift.js +52 -13
  38. package/build/epic-ci-workflow-install.js +31 -6
  39. package/build/epic-ci-workflow-v3.js +273 -0
  40. package/build/epic-ci-workflow.js +128 -7
  41. package/build/epic-implementer-bin.js +161 -70
  42. package/build/epic-launch-context.js +102 -7
  43. package/build/epic-server-record.js +30 -15
  44. package/build/executor/credential-delivery-step.js +168 -0
  45. package/build/executor/deps.js +3 -1
  46. package/build/executor/env.js +39 -1
  47. package/build/executor/epic-server-context.js +23 -7
  48. package/build/executor/guarded-fast-forward-push.js +13 -8
  49. package/build/executor/job-runner.js +159 -17
  50. package/build/executor/permissions.js +85 -3
  51. package/build/executor/prompt-spec.js +37 -3
  52. package/build/executor-launch.js +4 -2
  53. package/build/git-exclude-lock.js +187 -0
  54. package/build/index.js +398 -269
  55. package/build/install-bridge-conductor-answers.js +84 -21
  56. package/build/install-bridge-conductor-apply.js +30 -1
  57. package/build/install-bridge-conductor-assessment.js +375 -48
  58. package/build/install-bridge-conductor-compact.js +27 -2
  59. package/build/install-bridge-conductor-contracts.js +10 -1
  60. package/build/install-bridge-conductor-gate.js +124 -11
  61. package/build/install-bridge-conductor-setup.js +46 -8
  62. package/build/install-bridge-conductor.js +625 -113
  63. package/build/install-bridge.js +88 -11
  64. package/build/install-doctor.js +38 -8
  65. package/build/install-sfcc-detection.js +120 -0
  66. package/build/install-sfcc-setup.js +185 -0
  67. package/build/mcp-grant-candidates.js +108 -96
  68. package/build/mcp-invoke.js +168 -4
  69. package/build/mcp-provisioning.js +21 -4
  70. package/build/mcp-server-invocation.js +13 -0
  71. package/build/merge-workflow-install.js +9 -1
  72. package/build/pipelines.generated.js +2 -1
  73. package/build/plane/status.js +8 -2
  74. package/build/printed-remedy-commands.js +5 -0
  75. package/build/project-root.js +40 -0
  76. package/build/readme.generated.js +1 -1
  77. package/build/repository-state-paths.js +5 -2
  78. package/build/repository-toolchains.js +6 -3
  79. package/build/setup-epic.js +116 -15
  80. package/build/sfcc/credentials.js +3 -2
  81. package/build/sfcc/hostname.js +98 -2
  82. package/build/sfcc/tool-wrapper.js +6 -95
  83. package/build/start-tickets.js +193 -29
  84. package/build/test-support/executor-source-files.js +200 -0
  85. package/build/testing-config-client.js +25 -2
  86. package/build/third-party-mcp-targets.js +35 -4
  87. package/build/version.generated.js +3 -3
  88. package/build/with-credentials.js +208 -0
  89. package/build/worktree-credential-delivery.js +340 -0
  90. package/package.json +1 -1
@@ -0,0 +1,187 @@
1
+ /**
2
+ * BAPI-1647: a bounded cross-process lock for Bridge's writes to a checkout's
3
+ * `info/exclude`.
4
+ *
5
+ * `ensureGitInfoExcluded()` (`git-ignore-utils.ts`) and the executor's
6
+ * `provisionWorktreeSettingsExclude()` (`executor/permissions.ts`) are both
7
+ * read-then-write. Linked worktrees of one repository share ONE common
8
+ * `info/exclude`, so two launches preparing two worktrees at the same moment
9
+ * could each read the file, each append their own line, and the second rename or
10
+ * write would drop the first line. Every Bridge writer therefore takes this lock
11
+ * around its whole read-modify-write and re-reads inside it.
12
+ *
13
+ * The lock is keyed on the CANONICAL exclude pathname (its directory resolved
14
+ * through `realpath`), never the worktree path: two worktrees resolve to the
15
+ * same key exactly when they share an exclude file. The lock file sits beside
16
+ * the exclude file (`exclude.bridge-lock`), created with `open(..., "wx")`, and
17
+ * only its owner removes it. A lock older than {@link STALE_LOCK_MS} is treated
18
+ * as abandoned (a crashed writer) and removed once; the critical section is a
19
+ * few milliseconds, so a live owner never gets near that age.
20
+ *
21
+ * Failure outcomes are fixed text: no path, no errno, no exception message.
22
+ */
23
+ import { mkdir as fsMkdir, open as fsOpen, realpath as fsRealpath, stat as fsStat, unlink as fsUnlink } from "fs/promises";
24
+ import path from "path";
25
+ import { ensureGitInfoExcluded } from "./git-ignore-utils.js";
26
+ /** How long a contended writer waits before giving up. */
27
+ export const EXCLUDE_LOCK_TIMEOUT_MS = 10_000;
28
+ /** Poll interval while waiting. */
29
+ export const EXCLUDE_LOCK_POLL_MS = 25;
30
+ /** A lock file older than this is an abandoned lock from a crashed writer. */
31
+ export const STALE_LOCK_MS = 60_000;
32
+ /** Lock file name beside the exclude file. */
33
+ export const EXCLUDE_LOCK_FILE_NAME = "exclude.bridge-lock";
34
+ export function defaultExcludeLockDeps() {
35
+ return {
36
+ open: (p, flags, mode) => fsOpen(p, flags, mode),
37
+ unlink: (p) => fsUnlink(p),
38
+ mkdir: (p, o) => fsMkdir(p, o),
39
+ realpath: (p) => fsRealpath(p),
40
+ mtimeMs: async (p) => (await fsStat(p)).mtimeMs,
41
+ now: () => Date.now(),
42
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
43
+ };
44
+ }
45
+ function errnoCode(err) {
46
+ return err && typeof err === "object" ? err.code : undefined;
47
+ }
48
+ /**
49
+ * The lock key: the exclude file's directory resolved through `realpath`, joined
50
+ * with the file name. The directory is created first so it can be resolved.
51
+ */
52
+ export async function canonicalExcludePath(excludePath, deps) {
53
+ const dir = path.dirname(excludePath);
54
+ await deps.mkdir(dir, { recursive: true });
55
+ const realDir = await deps.realpath(dir);
56
+ return path.join(realDir, path.basename(excludePath));
57
+ }
58
+ /** Acquire the lock for one resolved exclude path. */
59
+ export async function acquireExcludeLock(excludePath, deps = defaultExcludeLockDeps()) {
60
+ let lockPath;
61
+ try {
62
+ const canonical = await canonicalExcludePath(excludePath, deps);
63
+ lockPath = path.join(path.dirname(canonical), EXCLUDE_LOCK_FILE_NAME);
64
+ }
65
+ catch {
66
+ return { ok: false, reason: "lock_unavailable" };
67
+ }
68
+ let released = false;
69
+ const release = async () => {
70
+ if (released)
71
+ return;
72
+ released = true;
73
+ try {
74
+ await deps.unlink(lockPath);
75
+ }
76
+ catch {
77
+ /* a lock that is already gone never fails the caller */
78
+ }
79
+ };
80
+ const deadline = deps.now() + (deps.timeoutMs ?? EXCLUDE_LOCK_TIMEOUT_MS);
81
+ let staleChecked = false;
82
+ for (;;) {
83
+ try {
84
+ const handle = await deps.open(lockPath, "wx", 0o600);
85
+ await handle.close();
86
+ return { ok: true, release };
87
+ }
88
+ catch (err) {
89
+ if (errnoCode(err) !== "EEXIST")
90
+ return { ok: false, reason: "lock_unavailable" };
91
+ }
92
+ if (!staleChecked) {
93
+ staleChecked = true;
94
+ try {
95
+ const age = deps.now() - (await deps.mtimeMs(lockPath));
96
+ if (age > STALE_LOCK_MS) {
97
+ await deps.unlink(lockPath);
98
+ continue;
99
+ }
100
+ }
101
+ catch {
102
+ /* vanished or unreadable: retry normally */
103
+ }
104
+ }
105
+ if (deps.now() >= deadline)
106
+ return { ok: false, reason: "lock_timeout" };
107
+ await deps.sleep(EXCLUDE_LOCK_POLL_MS);
108
+ }
109
+ }
110
+ /** Run `fn` while holding the lock for `excludePath`. */
111
+ export async function withExcludeLock(excludePath, fn, deps = defaultExcludeLockDeps()) {
112
+ const lock = await acquireExcludeLock(excludePath, deps);
113
+ if (!lock.ok)
114
+ return lock;
115
+ try {
116
+ return { ok: true, value: await fn() };
117
+ }
118
+ finally {
119
+ await lock.release();
120
+ }
121
+ }
122
+ /**
123
+ * Resolve the exclude path the same way `ensureGitInfoExcluded()` does: through
124
+ * `git rev-parse --git-path info/exclude` when `runCommand` and `platform` are
125
+ * supplied (linked worktrees resolve to the common directory), else the legacy
126
+ * `<root>/.git/info/exclude` join. `git-ignore-utils.ts` keeps its resolver
127
+ * private, so this mirrors it rather than editing that file.
128
+ */
129
+ export async function resolveExcludePathForLock(worktreeRoot, deps) {
130
+ if (deps.runCommand && deps.platform) {
131
+ const api = deps.platform === "win32" ? path.win32 : path.posix;
132
+ const result = await deps.runCommand("git", ["rev-parse", "--git-path", "info/exclude"], { cwd: worktreeRoot });
133
+ if (result.exitCode !== 0 || result.stdout.trim().length === 0) {
134
+ throw new Error("Failed to resolve the worktree info/exclude path.");
135
+ }
136
+ const raw = result.stdout.trim();
137
+ return api.isAbsolute(raw) ? api.normalize(raw) : api.resolve(worktreeRoot, raw);
138
+ }
139
+ return path.join(worktreeRoot, ".git", "info", "exclude");
140
+ }
141
+ /**
142
+ * `ensureGitInfoExcluded()` inside the exclude lock, re-reading the file inside
143
+ * the critical section (the wrapped call reads first). Never throws.
144
+ */
145
+ export async function ensureGitInfoExcludedLocked(worktreeRoot, relativePath, deps, lockDeps = defaultExcludeLockDeps()) {
146
+ let excludePath;
147
+ try {
148
+ excludePath = await resolveExcludePathForLock(worktreeRoot, deps);
149
+ }
150
+ catch {
151
+ return { ok: false, reason: "exclude_failed" };
152
+ }
153
+ try {
154
+ const locked = await withExcludeLock(excludePath, () => ensureGitInfoExcluded(worktreeRoot, relativePath, deps), lockDeps);
155
+ return locked.ok ? { ok: true } : locked;
156
+ }
157
+ catch {
158
+ return { ok: false, reason: "exclude_failed" };
159
+ }
160
+ }
161
+ /**
162
+ * For the pre-existing writers whose contract predates the lock: hold the lock
163
+ * when it can be had, and otherwise fall back to the unlocked write they always
164
+ * did, so a lock problem never changes their established outcome. Errors from
165
+ * the write itself propagate exactly as before.
166
+ */
167
+ export async function ensureGitInfoExcludedSerialized(worktreeRoot, relativePath, deps, lockDeps = defaultExcludeLockDeps()) {
168
+ let excludePath;
169
+ try {
170
+ excludePath = await resolveExcludePathForLock(worktreeRoot, deps);
171
+ }
172
+ catch {
173
+ excludePath = undefined;
174
+ }
175
+ if (excludePath === undefined) {
176
+ await ensureGitInfoExcluded(worktreeRoot, relativePath, deps);
177
+ return;
178
+ }
179
+ const lock = await acquireExcludeLock(excludePath, lockDeps);
180
+ try {
181
+ await ensureGitInfoExcluded(worktreeRoot, relativePath, deps);
182
+ }
183
+ finally {
184
+ if (lock.ok)
185
+ await lock.release();
186
+ }
187
+ }