@loucompanion/forge-bridge 0.1.1-dev.03b8ba168599 → 0.1.1-dev.2ac58b6f94ce

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.
@@ -87,11 +87,20 @@ export class ForgeBridgeService {
87
87
  const normalized = this.normalizeDispatch(dispatch);
88
88
  const result = await this.sessions.runOnce(normalized, {
89
89
  emit: async (event) => {
90
- await this.invokeAck("DispatchEvent", {
91
- leaseId,
92
- fencingToken,
93
- event: redactSecrets(event, redactionSecrets)
94
- });
90
+ try {
91
+ await this.invokeAck("DispatchEvent", {
92
+ leaseId,
93
+ fencingToken,
94
+ event: redactSecrets(event, redactionSecrets)
95
+ });
96
+ }
97
+ catch (error) {
98
+ if (isDispatchNoLongerPending(error)) {
99
+ controller.abort(error instanceof Error ? error.message : "Dispatch is no longer pending.");
100
+ return;
101
+ }
102
+ throw error;
103
+ }
95
104
  }
96
105
  }, controller.signal);
97
106
  await this.sendResult(leaseId, fencingToken, redactSecrets(result, redactionSecrets));
@@ -123,6 +132,7 @@ export class ForgeBridgeService {
123
132
  const mapping = findRepoMapping(dispatch, this.config.repoMappings);
124
133
  const localPath = mapping?.localPath?.trim();
125
134
  const repoRoot = localPath ? path.dirname(path.resolve(localPath)) : this.config.defaultRepoRoot;
135
+ const qaLaunchTarget = normalizeQaAppLaunchTarget(mapping?.qaAppLaunchTarget) ?? dispatch.qaBrowser?.launchTarget ?? null;
126
136
  return {
127
137
  ...dispatch,
128
138
  repo: {
@@ -133,7 +143,13 @@ export class ForgeBridgeService {
133
143
  serverLocal: {
134
144
  repoRoot,
135
145
  cleanupWorktrees: this.config.cleanupWorktrees
136
- }
146
+ },
147
+ qaBrowser: dispatch.qaBrowser
148
+ ? {
149
+ ...dispatch.qaBrowser,
150
+ launchTarget: qaLaunchTarget
151
+ }
152
+ : dispatch.qaBrowser
137
153
  };
138
154
  }
139
155
  async sendResult(leaseId, fencingToken, result) {
@@ -142,7 +158,15 @@ export class ForgeBridgeService {
142
158
  fencingToken,
143
159
  result
144
160
  };
145
- await this.invokeAck("DispatchResult", payload);
161
+ try {
162
+ await this.invokeAck("DispatchResult", payload);
163
+ }
164
+ catch (error) {
165
+ if (isDispatchNoLongerPending(error)) {
166
+ return;
167
+ }
168
+ throw error;
169
+ }
146
170
  }
147
171
  startHeartbeat() {
148
172
  this.stopHeartbeat();
@@ -189,7 +213,7 @@ export class ForgeBridgeService {
189
213
  }
190
214
  const ack = await connection.invoke(methodName, payload);
191
215
  if (!ack.accepted) {
192
- throw new Error(ack.message ?? ack.code ?? `${methodName} callback was rejected.`);
216
+ throw new BridgeCallbackRejectedError(ack.code ?? null, ack.message ?? ack.code ?? `${methodName} callback was rejected.`);
193
217
  }
194
218
  return ack;
195
219
  }
@@ -207,6 +231,20 @@ export class ForgeBridgeService {
207
231
  }
208
232
  }
209
233
  }
234
+ class BridgeCallbackRejectedError extends Error {
235
+ code;
236
+ constructor(code, message) {
237
+ super(message);
238
+ this.code = code;
239
+ this.name = "BridgeCallbackRejectedError";
240
+ }
241
+ }
242
+ function isDispatchNoLongerPending(error) {
243
+ if (error instanceof BridgeCallbackRejectedError) {
244
+ return error.code === "bridge.dispatch_not_pending" || error.code === "bridge.stale_dispatch";
245
+ }
246
+ return error instanceof Error && error.message === "Dispatch is no longer pending.";
247
+ }
210
248
  export class SignalRBridgeConnectionFactory {
211
249
  create(config) {
212
250
  return new SignalRBridgeConnection(config);
@@ -323,6 +361,27 @@ function findRepoMapping(dispatch, mappings) {
323
361
  (!!mapping.remoteUrl?.trim() && equalsIgnoreCase(mapping.remoteUrl, dispatch.repo.remoteUrl)));
324
362
  });
325
363
  }
364
+ function normalizeQaAppLaunchTarget(target) {
365
+ if (!target) {
366
+ return null;
367
+ }
368
+ const routes = [...new Set((target.routes ?? []).map((route) => route.trim()).filter(Boolean))];
369
+ const normalized = {
370
+ url: cleanString(target.url),
371
+ command: cleanString(target.command),
372
+ working_directory: cleanString(target.working_directory),
373
+ ready_url: cleanString(target.ready_url),
374
+ routes,
375
+ notes: cleanString(target.notes)
376
+ };
377
+ return normalized.url || normalized.command || normalized.ready_url || routes.length > 0
378
+ ? normalized
379
+ : null;
380
+ }
381
+ function cleanString(value) {
382
+ const clean = value?.trim();
383
+ return clean ? clean : null;
384
+ }
326
385
  function equalsIgnoreCase(left, right) {
327
386
  return !!left?.trim() && !!right?.trim() && left.trim().toLowerCase() === right.trim().toLowerCase();
328
387
  }
@@ -27,6 +27,15 @@ export interface BridgeRepoMapping {
27
27
  readonly name?: string | null;
28
28
  readonly remoteUrl?: string | null;
29
29
  readonly localPath?: string | null;
30
+ readonly qaAppLaunchTarget?: QaAppLaunchTarget | null;
31
+ }
32
+ export interface QaAppLaunchTarget {
33
+ readonly url?: string | null;
34
+ readonly command?: string | null;
35
+ readonly working_directory?: string | null;
36
+ readonly ready_url?: string | null;
37
+ readonly routes?: readonly string[] | null;
38
+ readonly notes?: string | null;
30
39
  }
31
40
  export interface BridgeProviderStatus {
32
41
  readonly signedIn?: boolean | null;
@@ -14,6 +14,10 @@ export declare function parseArgs(argv: readonly string[]): {
14
14
  readonly command: "run-once";
15
15
  readonly dispatchPath: string;
16
16
  readonly resultPath: string;
17
+ } | {
18
+ readonly ok: true;
19
+ readonly command: "mcp";
20
+ readonly argv: readonly string[];
17
21
  } | {
18
22
  readonly ok: true;
19
23
  readonly command: "connect";
@@ -4,10 +4,12 @@ import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { createInterface } from "node:readline/promises";
6
6
  import { promisify } from "node:util";
7
+ import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
7
8
  import { redactSecrets, redactText } from "../shared/redaction/redaction.js";
8
9
  import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
9
10
  import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, writeLocalConfig } from "./local-config.js";
10
11
  import { BridgeSessionService } from "../session/session.service.js";
12
+ import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
11
13
  import { failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
12
14
  const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
13
15
  const execFileAsync = promisify(execFile);
@@ -102,6 +104,15 @@ export class ForgeBridgeCliService {
102
104
  if (args.command === "cleanup") {
103
105
  return await cleanupRepos(args.config, args.mode, args.force, io);
104
106
  }
107
+ if (args.command === "mcp") {
108
+ const parsed = parseCompletionMcpArgs(args.argv);
109
+ if (!parsed.ok) {
110
+ io.stderr.write(`${parsed.error}\n`);
111
+ return 2;
112
+ }
113
+ await runCompletionMcpServer(parsed.config);
114
+ return 0;
115
+ }
105
116
  let redactionSecrets = readEnvSecretValuesForRedaction();
106
117
  try {
107
118
  const dispatchJson = await fs.readFile(args.dispatchPath, "utf8");
@@ -214,6 +225,9 @@ export function parseArgs(argv) {
214
225
  if (argv[0] === "cleanup") {
215
226
  return parseCleanupArgs(argv);
216
227
  }
228
+ if (argv[0] === "mcp") {
229
+ return { ok: true, command: "mcp", argv };
230
+ }
217
231
  if (argv[0] !== "run-once") {
218
232
  return {
219
233
  ok: false,
@@ -508,7 +522,7 @@ function normalizeServerUrl(serverUrl) {
508
522
  return serverUrl.endsWith("/") ? serverUrl : `${serverUrl}/`;
509
523
  }
510
524
  function usage() {
511
- return "Usage: forge-bridge run-once --dispatch <dispatch-json-path> --result <result-json-path> | forge-bridge pair [code] [--server <url>] | forge-bridge connect --server <url> --runner-id <id> --device-token <token> | forge-bridge add-repo <label> <path> | forge-bridge remove-repo <label> | forge-bridge status [--check-updates] | forge-bridge cleanup [--stale|--merged|--all|--force]";
525
+ return "Usage: forge-bridge run-once --dispatch <dispatch-json-path> --result <result-json-path> | forge-bridge mcp --worktree <path> --work-item-id <id> --phase <phase> | forge-bridge pair [code] [--server <url>] | forge-bridge connect --server <url> --runner-id <id> --device-token <token> | forge-bridge add-repo <label> <path> | forge-bridge remove-repo <label> | forge-bridge status [--check-updates] | forge-bridge cleanup [--stale|--merged|--all|--force]";
512
526
  }
513
527
  async function writeJsonAtomic(outputPath, value) {
514
528
  await fs.mkdir(path.dirname(outputPath), { recursive: true });
@@ -620,6 +634,12 @@ function cliProbeCommandsFor(provider) {
620
634
  ];
621
635
  }
622
636
  async function execVersionCommand(probe, timeout = 2000) {
637
+ const directLaunch = process.platform === "win32"
638
+ ? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
639
+ : null;
640
+ if (directLaunch) {
641
+ return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout });
642
+ }
623
643
  try {
624
644
  return await execFileAsync(probe.command, probe.args, { timeout });
625
645
  }
@@ -159,7 +159,8 @@ function normalizeRepoMappings(values) {
159
159
  repoId: cleanString(mapping.repoId),
160
160
  name: cleanString(mapping.name) ?? label,
161
161
  remoteUrl: cleanString(mapping.remoteUrl),
162
- localPath: path.resolve(mapping.localPath)
162
+ localPath: path.resolve(mapping.localPath),
163
+ qaAppLaunchTarget: normalizeQaAppLaunchTarget(mapping.qaAppLaunchTarget)
163
164
  };
164
165
  })
165
166
  .sort((left, right) => left.label.localeCompare(right.label));
@@ -171,6 +172,22 @@ function normalizeLabel(value) {
171
172
  }
172
173
  return label;
173
174
  }
175
+ function normalizeQaAppLaunchTarget(value) {
176
+ if (!value)
177
+ return undefined;
178
+ const routes = cleanList(value.routes);
179
+ const normalized = {
180
+ url: cleanString(value.url),
181
+ command: cleanString(value.command),
182
+ working_directory: cleanString(value.working_directory),
183
+ ready_url: cleanString(value.ready_url),
184
+ routes,
185
+ notes: cleanString(value.notes)
186
+ };
187
+ return normalized.url || normalized.command || normalized.ready_url || routes?.length
188
+ ? normalized
189
+ : undefined;
190
+ }
174
191
  function cleanString(value) {
175
192
  const clean = value?.trim();
176
193
  return clean ? clean : undefined;
@@ -1,2 +1,4 @@
1
1
  export { BridgeSessionService } from "./session.service.js";
2
+ export { buildCompletionToolServerArgs, codexMcpConfigArgs, completionPhaseFromDispatch, expectedCompletionToolName, prepareCompletionToolRuntime, readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.js";
3
+ export type { CompletionArtifactReference, CompletionPhase, CompletionToolRuntime } from "./phase-completion.js";
2
4
  export type { SessionService } from "./session.base.js";
@@ -1 +1,2 @@
1
1
  export { BridgeSessionService } from "./session.service.js";
2
+ export { buildCompletionToolServerArgs, codexMcpConfigArgs, completionPhaseFromDispatch, expectedCompletionToolName, prepareCompletionToolRuntime, readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.js";
@@ -1,6 +1,8 @@
1
1
  export { parseRunOnceDispatchPacket, failureResult } from "./session.types.js";
2
+ export { buildCompletionToolServerArgs, codexMcpConfigArgs, completionPhaseFromDispatch, expectedCompletionToolName, prepareCompletionToolRuntime, readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.js";
3
+ export type { CompletionArtifactReference, CompletionPhase, CompletionToolRuntime } from "./phase-completion.js";
2
4
  export type { SessionEventSink, SessionService } from "./session.base.js";
3
- export type { ApiKeySecretGrant, DispatchCycleRun, DispatchExecution, DispatchLease, DispatchSession, DispatchRepo, DispatchServerLocalConfig, DispatchWorkItem, RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec, RunnerEventLine } from "./session.types.js";
5
+ export type { ApiKeySecretGrant, DispatchCycleRun, DispatchExecution, DispatchLease, DispatchPullRequestContext, DispatchSession, DispatchRepo, DispatchServerLocalConfig, DispatchWorkItem, RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec, RunnerEventLine } from "./session.types.js";
4
6
  export { DeterministicProviderCliService, ProcessBackedProviderCliService, RoutingProviderCliService, buildProviderCliCommand } from "./provider-cli/provider-cli.service.js";
5
7
  export type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
6
8
  export type { ProviderCliCommand, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "./provider-cli/provider-cli.service.js";
@@ -1,2 +1,3 @@
1
1
  export { parseRunOnceDispatchPacket, failureResult } from "./session.types.js";
2
+ export { buildCompletionToolServerArgs, codexMcpConfigArgs, completionPhaseFromDispatch, expectedCompletionToolName, prepareCompletionToolRuntime, readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.js";
2
3
  export { DeterministicProviderCliService, ProcessBackedProviderCliService, RoutingProviderCliService, buildProviderCliCommand } from "./provider-cli/provider-cli.service.js";
@@ -0,0 +1,101 @@
1
+ import type { RunOnceDispatchPacket, RunnerDispatchArtifact } from "./session.types.js";
2
+ import type { WorktreeHandle } from "../worktree/worktree.types.js";
3
+ export type CompletionPhase = "implementation" | "self_review" | "validation" | "qa";
4
+ export type QaCompletionGate = "qa_plan" | "qa_regression" | "qa_api" | "qa_manual_web" | "qa_bug_repro" | "qa_findings" | "qa_verdict";
5
+ export interface CompletionToolRuntime {
6
+ readonly serverName: string;
7
+ readonly command: string;
8
+ readonly args: readonly string[];
9
+ readonly env: Readonly<Record<string, string>>;
10
+ readonly cursorMcpConfigPath?: string | null;
11
+ cleanup(): Promise<void>;
12
+ }
13
+ export interface CompletionToolRuntimeOptions {
14
+ readonly dispatch: RunOnceDispatchPacket;
15
+ readonly worktree: WorktreeHandle;
16
+ readonly phase?: CompletionPhase;
17
+ }
18
+ export interface CompletionToolServerConfig {
19
+ readonly worktreePath: string;
20
+ readonly workItemId: string;
21
+ readonly ownerType?: string;
22
+ readonly ownerId?: string;
23
+ readonly phase: CompletionPhase;
24
+ readonly producedBy?: string;
25
+ readonly redactionSecrets?: readonly string[];
26
+ readonly developCycle?: boolean;
27
+ readonly qaCycle?: boolean;
28
+ }
29
+ export interface CompletionToolCallResult {
30
+ readonly content: readonly {
31
+ readonly type: "text";
32
+ readonly text: string;
33
+ }[];
34
+ readonly structuredContent: CompletionArtifactReference & {
35
+ readonly gate: {
36
+ readonly phase: CompletionPhase;
37
+ readonly qaGate?: QaCompletionGate;
38
+ readonly status: string;
39
+ readonly allowed: boolean;
40
+ readonly reason: string;
41
+ };
42
+ readonly nextPhase: CompletionPhase | "dev_test_ready" | "sign_off_ready";
43
+ readonly nextInstruction: string;
44
+ };
45
+ }
46
+ export interface CompletionArtifactReference {
47
+ readonly phase: CompletionPhase;
48
+ readonly workItemId: string;
49
+ readonly ownerType?: string;
50
+ readonly ownerId?: string;
51
+ readonly repoPath: string;
52
+ readonly path: string;
53
+ readonly reportPath: string;
54
+ readonly contentHash: string;
55
+ readonly status: string;
56
+ readonly producedBy: string;
57
+ }
58
+ export declare const qaCompletionGateOrder: readonly QaCompletionGate[];
59
+ export declare function completionPhaseFromDispatch(dispatch: RunOnceDispatchPacket): CompletionPhase;
60
+ export declare function normalizeCompletionPhase(value: string | null | undefined): CompletionPhase;
61
+ export declare function usesDevelopCycleCompletion(dispatch: RunOnceDispatchPacket): boolean;
62
+ export declare function usesQaCycleCompletion(dispatch: RunOnceDispatchPacket): boolean;
63
+ export declare function completionToolNamesForPhase(phase: CompletionPhase): readonly string[];
64
+ export declare function completionToolNamesForQaGate(gate: QaCompletionGate): readonly string[];
65
+ export declare function expectedCompletionToolName(phase: CompletionPhase): string;
66
+ export declare function expectedQaCompletionToolName(gate: QaCompletionGate): string;
67
+ export declare function artifactRootFor(worktreePath: string, workItemId: string): string;
68
+ export declare function completionArtifactJsonPath(worktreePath: string, workItemId: string, phase: CompletionPhase): string;
69
+ export declare function completionArtifactReportPath(worktreePath: string, workItemId: string, phase: CompletionPhase): string;
70
+ export declare function prepareCompletionToolRuntime(options: CompletionToolRuntimeOptions): Promise<CompletionToolRuntime>;
71
+ export declare function buildCompletionToolServerArgs(config: CompletionToolServerConfig): readonly string[];
72
+ export declare function codexMcpConfigArgs(runtime: CompletionToolRuntime): readonly string[];
73
+ export declare function cursorMcpServerConfig(runtime: CompletionToolRuntime): unknown;
74
+ export declare function completionPromptForPhase(phase: CompletionPhase): string;
75
+ export declare function completionPromptForDevelopCycle(phase: CompletionPhase): string;
76
+ export declare function completionPromptForQaCycle(currentGate?: QaCompletionGate): string;
77
+ export declare function completionToolNamesForServer(config: CompletionToolServerConfig): readonly string[];
78
+ export declare class CompletionToolServerSession {
79
+ private readonly config;
80
+ private currentPhase;
81
+ private currentQaGate;
82
+ private completed;
83
+ constructor(config: CompletionToolServerConfig);
84
+ get instructions(): string;
85
+ toolDefinitions(): readonly unknown[];
86
+ callTool(toolName: string, input: unknown): Promise<CompletionToolCallResult>;
87
+ private callQaGateTool;
88
+ private advanceAfterPass;
89
+ private advanceAfterQaGate;
90
+ }
91
+ export declare function writeCompletionArtifact(config: CompletionToolServerConfig, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
92
+ export declare function readCompletionArtifact(worktreePath: string, workItemId: string, phase: CompletionPhase): Promise<RunnerDispatchArtifact | null>;
93
+ export declare function runCompletionMcpServer(config: CompletionToolServerConfig): Promise<void>;
94
+ export declare function parseCompletionMcpArgs(argv: readonly string[]): {
95
+ readonly ok: true;
96
+ readonly config: CompletionToolServerConfig;
97
+ } | {
98
+ readonly ok: false;
99
+ readonly error: string;
100
+ };
101
+ export declare function completionRedactionEnv(secrets: readonly string[]): Readonly<Record<string, string>>;