@loucompanion/forge-bridge 0.1.1-dev.af36c7fa102b → 0.1.1-dev.e52b249f07a8
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.
- package/dist/bridge/bridge.service.js +29 -1
- package/dist/bridge/bridge.types.d.ts +9 -0
- package/dist/cli/cli.service.js +7 -0
- package/dist/cli/local-config.js +18 -1
- package/dist/session/phase-completion.d.ts +37 -1
- package/dist/session/phase-completion.js +1013 -83
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +5 -4
- package/dist/session/provider-cli/provider-cli.service.js +1075 -116
- package/dist/session/provider-cli/provider-cli.types.d.ts +1 -0
- package/dist/session/provider-cli/provider-usage.d.ts +25 -0
- package/dist/session/provider-cli/provider-usage.js +64 -0
- package/dist/session/qa-sidecar-validation.d.ts +3 -0
- package/dist/session/qa-sidecar-validation.js +44 -0
- package/dist/session/session.service.js +12 -14
- package/dist/session/session.types.d.ts +38 -0
- package/dist/session/session.types.js +96 -2
- package/dist/shared/cursor-agent/cursor-agent.launch.d.ts +9 -0
- package/dist/shared/cursor-agent/cursor-agent.launch.js +66 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +1 -4
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RunOnceDispatchPacket, RunnerDispatchEvent } from "../session.types.js";
|
|
2
|
+
export type UsageSource = "provider_reported" | "cli_reported" | "estimated" | "unknown";
|
|
3
|
+
/**
|
|
4
|
+
* Normalized, provider-agnostic token usage accumulated for a dispatch. Cost is never computed
|
|
5
|
+
* here; the API recomputes cost from these tokens x model rates (ADR-0006).
|
|
6
|
+
*/
|
|
7
|
+
export interface ProviderUsage {
|
|
8
|
+
readonly inputTokens: number;
|
|
9
|
+
readonly outputTokens: number;
|
|
10
|
+
readonly cacheReadTokens: number;
|
|
11
|
+
readonly cacheCreationTokens: number;
|
|
12
|
+
readonly reasoningOutputTokens: number;
|
|
13
|
+
readonly providerDurationMs: number | null;
|
|
14
|
+
readonly source: UsageSource;
|
|
15
|
+
}
|
|
16
|
+
export declare function emptyUsage(source?: UsageSource): ProviderUsage;
|
|
17
|
+
export declare function addUsage(base: ProviderUsage, next: Partial<ProviderUsage>): ProviderUsage;
|
|
18
|
+
export declare function totalTokens(usage: ProviderUsage): number;
|
|
19
|
+
export declare function hasUsage(usage: ProviderUsage | null): usage is ProviderUsage;
|
|
20
|
+
/**
|
|
21
|
+
* Builds the durable `provider_usage` event. Token numbers travel as a structured `data` JSON
|
|
22
|
+
* string (snake_case) that the API parses into a usage_event row.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildProviderUsageEvent(dispatch: RunOnceDispatchPacket, usage: ProviderUsage): RunnerDispatchEvent;
|
|
25
|
+
export declare function readUsageNumber(source: Record<string, unknown>, key: string): number;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export function emptyUsage(source = "unknown") {
|
|
2
|
+
return {
|
|
3
|
+
inputTokens: 0,
|
|
4
|
+
outputTokens: 0,
|
|
5
|
+
cacheReadTokens: 0,
|
|
6
|
+
cacheCreationTokens: 0,
|
|
7
|
+
reasoningOutputTokens: 0,
|
|
8
|
+
providerDurationMs: null,
|
|
9
|
+
source
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function addUsage(base, next) {
|
|
13
|
+
return {
|
|
14
|
+
inputTokens: base.inputTokens + nonNegative(next.inputTokens),
|
|
15
|
+
outputTokens: base.outputTokens + nonNegative(next.outputTokens),
|
|
16
|
+
cacheReadTokens: base.cacheReadTokens + nonNegative(next.cacheReadTokens),
|
|
17
|
+
cacheCreationTokens: base.cacheCreationTokens + nonNegative(next.cacheCreationTokens),
|
|
18
|
+
reasoningOutputTokens: base.reasoningOutputTokens + nonNegative(next.reasoningOutputTokens),
|
|
19
|
+
providerDurationMs: next.providerDurationMs ?? base.providerDurationMs,
|
|
20
|
+
source: next.source ?? base.source
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function totalTokens(usage) {
|
|
24
|
+
return usage.inputTokens + usage.outputTokens + usage.cacheReadTokens + usage.cacheCreationTokens;
|
|
25
|
+
}
|
|
26
|
+
export function hasUsage(usage) {
|
|
27
|
+
return usage !== null && totalTokens(usage) > 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Builds the durable `provider_usage` event. Token numbers travel as a structured `data` JSON
|
|
31
|
+
* string (snake_case) that the API parses into a usage_event row.
|
|
32
|
+
*/
|
|
33
|
+
export function buildProviderUsageEvent(dispatch, usage) {
|
|
34
|
+
const data = {
|
|
35
|
+
provider: dispatch.execution.provider,
|
|
36
|
+
model: dispatch.execution.model,
|
|
37
|
+
lane: dispatch.execution.lane,
|
|
38
|
+
phase: dispatch.cycleRun.phase,
|
|
39
|
+
attempt: dispatch.cycleRun.attempt,
|
|
40
|
+
input_tokens: usage.inputTokens,
|
|
41
|
+
output_tokens: usage.outputTokens,
|
|
42
|
+
cache_read_tokens: usage.cacheReadTokens,
|
|
43
|
+
cache_creation_tokens: usage.cacheCreationTokens,
|
|
44
|
+
reasoning_output_tokens: usage.reasoningOutputTokens,
|
|
45
|
+
metered: dispatch.execution.authKind === "api_key",
|
|
46
|
+
usage_source: usage.source,
|
|
47
|
+
provider_duration_ms: usage.providerDurationMs
|
|
48
|
+
};
|
|
49
|
+
const total = totalTokens(usage);
|
|
50
|
+
return {
|
|
51
|
+
role: "runner",
|
|
52
|
+
kind: "checkpoint",
|
|
53
|
+
content: `Provider usage: ${total} tokens (${usage.inputTokens} in / ${usage.outputTokens} out) for ${dispatch.execution.model}.`,
|
|
54
|
+
eventType: "provider_usage",
|
|
55
|
+
data: JSON.stringify(data)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function readUsageNumber(source, key) {
|
|
59
|
+
const value = source[key];
|
|
60
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
61
|
+
}
|
|
62
|
+
function nonNegative(value) {
|
|
63
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
64
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function isPathUnderRoot(root: string, target: string): boolean;
|
|
2
|
+
export declare function ensureNoSymbolicLinkPathSegments(root: string, targetDirectory: string, errorMessage: string): Promise<void>;
|
|
3
|
+
export declare function sha256File(filePath: string): Promise<string>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export function isPathUnderRoot(root, target) {
|
|
6
|
+
const relative = path.relative(path.resolve(root), path.resolve(target));
|
|
7
|
+
return Boolean(relative)
|
|
8
|
+
&& relative !== ".."
|
|
9
|
+
&& !relative.startsWith(`..${path.sep}`)
|
|
10
|
+
&& !path.isAbsolute(relative);
|
|
11
|
+
}
|
|
12
|
+
export async function ensureNoSymbolicLinkPathSegments(root, targetDirectory, errorMessage) {
|
|
13
|
+
const resolvedRoot = path.resolve(root);
|
|
14
|
+
const resolvedTargetDirectory = path.resolve(targetDirectory);
|
|
15
|
+
const relative = path.relative(resolvedRoot, resolvedTargetDirectory);
|
|
16
|
+
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
17
|
+
throw new Error(errorMessage);
|
|
18
|
+
}
|
|
19
|
+
let current = resolvedRoot;
|
|
20
|
+
const rootStat = await fs.lstat(current);
|
|
21
|
+
if (rootStat.isSymbolicLink()) {
|
|
22
|
+
throw new Error(errorMessage);
|
|
23
|
+
}
|
|
24
|
+
if (!relative) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const segment of relative.split(path.sep)) {
|
|
28
|
+
if (!segment) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
current = path.join(current, segment);
|
|
32
|
+
const stat = await fs.lstat(current);
|
|
33
|
+
if (stat.isSymbolicLink()) {
|
|
34
|
+
throw new Error(errorMessage);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function sha256File(filePath) {
|
|
39
|
+
const hash = crypto.createHash("sha256");
|
|
40
|
+
for await (const chunk of createReadStream(filePath)) {
|
|
41
|
+
hash.update(chunk);
|
|
42
|
+
}
|
|
43
|
+
return hash.digest("hex");
|
|
44
|
+
}
|
|
@@ -50,28 +50,26 @@ export class BridgeSessionService {
|
|
|
50
50
|
const role = dispatch.execution.role.toLowerCase();
|
|
51
51
|
const isQa = role === "qa" || lane === "qa";
|
|
52
52
|
const isConflictResolve = role === "conflict_resolve" || lane === "conflict_resolve";
|
|
53
|
+
const context = {
|
|
54
|
+
dispatch,
|
|
55
|
+
worktree,
|
|
56
|
+
emit,
|
|
57
|
+
signal
|
|
58
|
+
};
|
|
53
59
|
const run = isQa
|
|
54
|
-
? await this.providerCli.runQa(
|
|
60
|
+
? await this.providerCli.runQa(context)
|
|
55
61
|
: isConflictResolve
|
|
56
|
-
? await this.providerCli.runConflictResolve(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
emit,
|
|
60
|
-
signal
|
|
61
|
-
})
|
|
62
|
-
: await this.providerCli.runImplementation({
|
|
63
|
-
dispatch,
|
|
64
|
-
worktree,
|
|
65
|
-
emit,
|
|
66
|
-
signal
|
|
67
|
-
});
|
|
62
|
+
? await this.providerCli.runConflictResolve(context)
|
|
63
|
+
: await this.providerCli.runImplementation(context);
|
|
64
|
+
const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
|
|
68
65
|
return redactSecrets({
|
|
69
66
|
schemaVersion: 1,
|
|
70
67
|
exitCode: 0,
|
|
71
68
|
summary: run.summary,
|
|
72
69
|
events,
|
|
73
70
|
spec: run.spec ?? null,
|
|
74
|
-
artifact: run.artifact ?? null
|
|
71
|
+
artifact: run.artifact ?? null,
|
|
72
|
+
artifacts: phaseArtifacts
|
|
75
73
|
}, redactionSecrets);
|
|
76
74
|
}
|
|
77
75
|
finally {
|
|
@@ -11,6 +11,30 @@ export interface RunOnceDispatchPacket {
|
|
|
11
11
|
readonly apiKeySecretGrant?: ApiKeySecretGrant | null;
|
|
12
12
|
readonly artifacts: readonly DispatchResolvedArtifact[];
|
|
13
13
|
readonly warmPathOverrides?: readonly string[];
|
|
14
|
+
readonly qaBrowser?: DispatchQaBrowserContext | null;
|
|
15
|
+
readonly qaRework?: DispatchQaReworkContext | null;
|
|
16
|
+
}
|
|
17
|
+
export interface DispatchQaBrowserContext {
|
|
18
|
+
readonly required: boolean;
|
|
19
|
+
readonly launchTarget?: DispatchQaAppLaunchTarget | null;
|
|
20
|
+
readonly artifactsPath: string;
|
|
21
|
+
readonly missingTargetReason?: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface DispatchQaAppLaunchTarget {
|
|
24
|
+
readonly url?: string | null;
|
|
25
|
+
readonly command?: string | null;
|
|
26
|
+
readonly working_directory?: string | null;
|
|
27
|
+
readonly ready_url?: string | null;
|
|
28
|
+
readonly routes: readonly string[];
|
|
29
|
+
readonly notes?: string | null;
|
|
30
|
+
}
|
|
31
|
+
export interface DispatchQaReworkContext {
|
|
32
|
+
readonly attempt: number;
|
|
33
|
+
readonly maxAttempts: number;
|
|
34
|
+
readonly packetPath: string;
|
|
35
|
+
readonly packetJson: string;
|
|
36
|
+
readonly findingIds: readonly string[];
|
|
37
|
+
readonly findings: readonly Record<string, unknown>[];
|
|
14
38
|
}
|
|
15
39
|
export interface DispatchResolvedArtifact {
|
|
16
40
|
readonly kind: string;
|
|
@@ -18,6 +42,7 @@ export interface DispatchResolvedArtifact {
|
|
|
18
42
|
readonly scope: string;
|
|
19
43
|
readonly body: string;
|
|
20
44
|
readonly contentHash: string;
|
|
45
|
+
readonly version: number;
|
|
21
46
|
readonly lane?: string | null;
|
|
22
47
|
readonly event?: string | null;
|
|
23
48
|
}
|
|
@@ -40,6 +65,9 @@ export interface DispatchRepo {
|
|
|
40
65
|
}
|
|
41
66
|
export interface DispatchCycleRun {
|
|
42
67
|
readonly id: string;
|
|
68
|
+
readonly ownerType?: string | null;
|
|
69
|
+
readonly ownerId?: string | null;
|
|
70
|
+
readonly workItemId?: string | null;
|
|
43
71
|
readonly kind: string;
|
|
44
72
|
readonly phase: string;
|
|
45
73
|
readonly requestedBase: string;
|
|
@@ -55,6 +83,9 @@ export interface DispatchSession {
|
|
|
55
83
|
}
|
|
56
84
|
export interface DispatchLease {
|
|
57
85
|
readonly id: string;
|
|
86
|
+
readonly ownerType?: string | null;
|
|
87
|
+
readonly ownerId?: string | null;
|
|
88
|
+
readonly workItemId?: string | null;
|
|
58
89
|
readonly worktreeKey: string;
|
|
59
90
|
readonly lane: string;
|
|
60
91
|
readonly fencingToken: string;
|
|
@@ -70,6 +101,7 @@ export interface DispatchExecution {
|
|
|
70
101
|
readonly role: string;
|
|
71
102
|
readonly lane: string;
|
|
72
103
|
readonly requiresApiKeySecretGrant: boolean;
|
|
104
|
+
readonly runnerRepoLocalPath?: string | null;
|
|
73
105
|
}
|
|
74
106
|
export interface ApiKeySecretGrant {
|
|
75
107
|
readonly grantId: string;
|
|
@@ -86,6 +118,10 @@ export interface RunnerDispatchEvent {
|
|
|
86
118
|
readonly kind: string;
|
|
87
119
|
readonly content: string;
|
|
88
120
|
readonly eventType: string;
|
|
121
|
+
/** Provider/runner-reported event time (ISO-8601) when available, preserved for accurate durations. */
|
|
122
|
+
readonly occurredAt?: string | null;
|
|
123
|
+
/** Optional structured telemetry payload (JSON string), e.g. token usage for provider_usage events. */
|
|
124
|
+
readonly data?: string | null;
|
|
89
125
|
}
|
|
90
126
|
export interface RunnerDispatchSpec {
|
|
91
127
|
readonly repoPath: string;
|
|
@@ -101,6 +137,7 @@ export interface RunnerDispatchArtifact {
|
|
|
101
137
|
readonly report: string;
|
|
102
138
|
readonly producedBy: string;
|
|
103
139
|
readonly status: string;
|
|
140
|
+
readonly phase?: string | null;
|
|
104
141
|
}
|
|
105
142
|
export interface RunOnceResultPacket {
|
|
106
143
|
readonly schemaVersion: 1;
|
|
@@ -109,6 +146,7 @@ export interface RunOnceResultPacket {
|
|
|
109
146
|
readonly events: readonly RunnerDispatchEvent[];
|
|
110
147
|
readonly spec?: RunnerDispatchSpec | null;
|
|
111
148
|
readonly artifact?: RunnerDispatchArtifact | null;
|
|
149
|
+
readonly artifacts?: readonly RunnerDispatchArtifact[] | null;
|
|
112
150
|
}
|
|
113
151
|
export interface RunnerEventLine {
|
|
114
152
|
readonly type: "runner_event";
|
|
@@ -17,7 +17,9 @@ export function parseRunOnceDispatchPacket(value) {
|
|
|
17
17
|
serverLocal: parseServerLocal(packet.serverLocal),
|
|
18
18
|
apiKeySecretGrant: parseApiKeySecretGrant(packet.apiKeySecretGrant),
|
|
19
19
|
artifacts: parseArtifacts(packet.artifacts),
|
|
20
|
-
warmPathOverrides: parseWarmPathOverrides(packet.warmPathOverrides)
|
|
20
|
+
warmPathOverrides: parseWarmPathOverrides(packet.warmPathOverrides),
|
|
21
|
+
qaBrowser: parseQaBrowser(packet.qaBrowser),
|
|
22
|
+
qaRework: parseQaRework(packet.qaRework)
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
export function failureResult(summary, events = []) {
|
|
@@ -55,6 +57,9 @@ function parseCycleRun(value) {
|
|
|
55
57
|
const cycle = asObject(value, "cycleRun");
|
|
56
58
|
return {
|
|
57
59
|
id: requiredString(cycle, "id"),
|
|
60
|
+
ownerType: optionalString(cycle, "ownerType"),
|
|
61
|
+
ownerId: optionalString(cycle, "ownerId"),
|
|
62
|
+
workItemId: optionalString(cycle, "workItemId"),
|
|
58
63
|
kind: requiredString(cycle, "kind"),
|
|
59
64
|
phase: requiredString(cycle, "phase"),
|
|
60
65
|
requestedBase: optionalString(cycle, "requestedBase") ?? "develop",
|
|
@@ -76,6 +81,9 @@ function parseLease(value) {
|
|
|
76
81
|
const lease = asObject(value, "lease");
|
|
77
82
|
return {
|
|
78
83
|
id: requiredString(lease, "id"),
|
|
84
|
+
ownerType: optionalString(lease, "ownerType"),
|
|
85
|
+
ownerId: optionalString(lease, "ownerId"),
|
|
86
|
+
workItemId: optionalString(lease, "workItemId"),
|
|
79
87
|
worktreeKey: requiredString(lease, "worktreeKey"),
|
|
80
88
|
lane: requiredString(lease, "lane"),
|
|
81
89
|
fencingToken: requiredString(lease, "fencingToken"),
|
|
@@ -93,7 +101,8 @@ function parseExecution(value) {
|
|
|
93
101
|
repoId: requiredString(execution, "repoId"),
|
|
94
102
|
role: requiredString(execution, "role"),
|
|
95
103
|
lane: requiredString(execution, "lane"),
|
|
96
|
-
requiresApiKeySecretGrant: requiredBoolean(execution, "requiresApiKeySecretGrant")
|
|
104
|
+
requiresApiKeySecretGrant: requiredBoolean(execution, "requiresApiKeySecretGrant"),
|
|
105
|
+
runnerRepoLocalPath: optionalString(execution, "runnerRepoLocalPath")
|
|
97
106
|
};
|
|
98
107
|
}
|
|
99
108
|
function parseApiKeySecretGrant(value) {
|
|
@@ -138,6 +147,70 @@ function parseWarmPathOverride(entry, index) {
|
|
|
138
147
|
}
|
|
139
148
|
return segments.join("/");
|
|
140
149
|
}
|
|
150
|
+
function parseQaBrowser(value) {
|
|
151
|
+
if (value === undefined || value === null) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const qaBrowser = asObject(value, "qaBrowser");
|
|
155
|
+
return {
|
|
156
|
+
required: optionalBoolean(qaBrowser, "required") ?? false,
|
|
157
|
+
launchTarget: parseQaAppLaunchTarget(qaBrowser.launchTarget ?? qaBrowser.launch_target),
|
|
158
|
+
artifactsPath: optionalString(qaBrowser, "artifactsPath") ?? optionalString(qaBrowser, "artifacts_path") ?? "",
|
|
159
|
+
missingTargetReason: optionalString(qaBrowser, "missingTargetReason") ?? optionalString(qaBrowser, "missing_target_reason")
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function parseQaAppLaunchTarget(value) {
|
|
163
|
+
if (value === undefined || value === null) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const launchTarget = asObject(value, "qaBrowser.launchTarget");
|
|
167
|
+
const routes = launchTarget.routes;
|
|
168
|
+
if (routes !== undefined && routes !== null && !Array.isArray(routes)) {
|
|
169
|
+
throw new Error("qaBrowser.launchTarget.routes must be an array when provided.");
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
url: optionalString(launchTarget, "url"),
|
|
173
|
+
command: optionalString(launchTarget, "command"),
|
|
174
|
+
working_directory: optionalString(launchTarget, "working_directory"),
|
|
175
|
+
ready_url: optionalString(launchTarget, "ready_url"),
|
|
176
|
+
routes: Array.isArray(routes)
|
|
177
|
+
? routes.map((entry, index) => {
|
|
178
|
+
if (typeof entry !== "string") {
|
|
179
|
+
throw new Error(`qaBrowser.launchTarget.routes[${index}] must be a string.`);
|
|
180
|
+
}
|
|
181
|
+
return entry;
|
|
182
|
+
}).filter((entry) => entry.trim().length > 0)
|
|
183
|
+
: [],
|
|
184
|
+
notes: optionalString(launchTarget, "notes")
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function parseQaRework(value) {
|
|
188
|
+
if (value === undefined || value === null) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const qaRework = asObject(value, "qaRework");
|
|
192
|
+
const findingIdsValue = qaRework.findingIds;
|
|
193
|
+
if (!Array.isArray(findingIdsValue)) {
|
|
194
|
+
throw new Error("qaRework.findingIds must be an array.");
|
|
195
|
+
}
|
|
196
|
+
const findingsValue = qaRework.findings;
|
|
197
|
+
if (!Array.isArray(findingsValue)) {
|
|
198
|
+
throw new Error("qaRework.findings must be an array.");
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
attempt: requiredNumber(qaRework, "attempt"),
|
|
202
|
+
maxAttempts: requiredNumber(qaRework, "maxAttempts"),
|
|
203
|
+
packetPath: requiredString(qaRework, "packetPath"),
|
|
204
|
+
packetJson: requiredString(qaRework, "packetJson"),
|
|
205
|
+
findingIds: findingIdsValue.map((entry, index) => {
|
|
206
|
+
if (typeof entry !== "string" || entry.trim().length === 0) {
|
|
207
|
+
throw new Error(`qaRework.findingIds[${index}] must be a non-empty string.`);
|
|
208
|
+
}
|
|
209
|
+
return entry;
|
|
210
|
+
}),
|
|
211
|
+
findings: findingsValue.map((entry, index) => asObject(entry, `qaRework.findings[${index}]`))
|
|
212
|
+
};
|
|
213
|
+
}
|
|
141
214
|
function parseArtifacts(value) {
|
|
142
215
|
if (value === undefined || value === null) {
|
|
143
216
|
return [];
|
|
@@ -153,6 +226,7 @@ function parseArtifacts(value) {
|
|
|
153
226
|
scope: requiredString(artifact, "scope"),
|
|
154
227
|
body: optionalString(artifact, "body") ?? "",
|
|
155
228
|
contentHash: requiredString(artifact, "contentHash"),
|
|
229
|
+
version: optionalPositiveInteger(artifact, "version") ?? 1,
|
|
156
230
|
lane: optionalString(artifact, "lane"),
|
|
157
231
|
event: optionalString(artifact, "event")
|
|
158
232
|
};
|
|
@@ -188,6 +262,26 @@ function requiredBoolean(source, key) {
|
|
|
188
262
|
}
|
|
189
263
|
return value;
|
|
190
264
|
}
|
|
265
|
+
function optionalBoolean(source, key) {
|
|
266
|
+
const value = source[key];
|
|
267
|
+
if (value === undefined || value === null) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
if (typeof value !== "boolean") {
|
|
271
|
+
throw new Error(`${key} must be a boolean when provided.`);
|
|
272
|
+
}
|
|
273
|
+
return value;
|
|
274
|
+
}
|
|
275
|
+
function optionalPositiveInteger(source, key) {
|
|
276
|
+
const value = source[key];
|
|
277
|
+
if (value === undefined || value === null) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
281
|
+
throw new Error(`${key} must be a positive integer when provided.`);
|
|
282
|
+
}
|
|
283
|
+
return value;
|
|
284
|
+
}
|
|
191
285
|
function requiredNumber(source, key) {
|
|
192
286
|
const value = source[key];
|
|
193
287
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CursorAgentLaunch {
|
|
2
|
+
readonly command: string;
|
|
3
|
+
readonly args: readonly string[];
|
|
4
|
+
}
|
|
5
|
+
export declare function isCursorAgentCommand(command: string): boolean;
|
|
6
|
+
export declare function resolveCursorAgentDirectLaunch(command: string, args: readonly string[]): Promise<CursorAgentLaunch | null>;
|
|
7
|
+
export declare function findLatestCursorAgentVersionDir(versionsRoot: string): Promise<string | null>;
|
|
8
|
+
export declare function compareCursorAgentVersionDirNames(left: string, right: string): number;
|
|
9
|
+
export declare function parseCursorAgentVersionSortKey(name: string): number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const cursorAgentVersionDirPattern = /^\d{4}\.\d{1,2}\.\d{1,2}-.+/;
|
|
4
|
+
export function isCursorAgentCommand(command) {
|
|
5
|
+
const normalized = command.trim().toLowerCase();
|
|
6
|
+
return normalized === "cursor-agent" || normalized === "agent";
|
|
7
|
+
}
|
|
8
|
+
export async function resolveCursorAgentDirectLaunch(command, args) {
|
|
9
|
+
if (!isCursorAgentCommand(command)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
13
|
+
if (!localAppData) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const versionDir = await findLatestCursorAgentVersionDir(path.join(localAppData, "cursor-agent", "versions"));
|
|
17
|
+
if (!versionDir) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const nodePath = path.join(versionDir, "node.exe");
|
|
21
|
+
const indexPath = path.join(versionDir, "index.js");
|
|
22
|
+
if (!(await fileExists(nodePath)) || !(await fileExists(indexPath))) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
command: nodePath,
|
|
27
|
+
args: [indexPath, ...args]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export async function findLatestCursorAgentVersionDir(versionsRoot) {
|
|
31
|
+
let entries;
|
|
32
|
+
try {
|
|
33
|
+
entries = await fs.readdir(versionsRoot);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const latestName = entries
|
|
39
|
+
.filter((name) => cursorAgentVersionDirPattern.test(name))
|
|
40
|
+
.sort(compareCursorAgentVersionDirNames)
|
|
41
|
+
.at(-1);
|
|
42
|
+
return latestName ? path.join(versionsRoot, latestName) : null;
|
|
43
|
+
}
|
|
44
|
+
export function compareCursorAgentVersionDirNames(left, right) {
|
|
45
|
+
const leftKey = parseCursorAgentVersionSortKey(left);
|
|
46
|
+
const rightKey = parseCursorAgentVersionSortKey(right);
|
|
47
|
+
if (leftKey !== rightKey) {
|
|
48
|
+
return leftKey - rightKey;
|
|
49
|
+
}
|
|
50
|
+
return left.localeCompare(right);
|
|
51
|
+
}
|
|
52
|
+
export function parseCursorAgentVersionSortKey(name) {
|
|
53
|
+
const datePart = name.split("-")[0] ?? "";
|
|
54
|
+
const parts = datePart.split(".");
|
|
55
|
+
if (parts.length !== 3) {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
const year = parts[0] ?? "";
|
|
59
|
+
const month = (parts[1] ?? "").padStart(2, "0");
|
|
60
|
+
const day = (parts[2] ?? "").padStart(2, "0");
|
|
61
|
+
const numeric = Number(`${year}${month}${day}`);
|
|
62
|
+
return Number.isFinite(numeric) ? numeric : 0;
|
|
63
|
+
}
|
|
64
|
+
async function fileExists(inputPath) {
|
|
65
|
+
return fs.stat(inputPath).then((stat) => stat.isFile()).catch(() => false);
|
|
66
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1.1-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.1.1-dev.e52b249f07a8";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.1-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.1-dev.e52b249f07a8";
|
|
@@ -29,10 +29,7 @@ export function selectLaneCommand(artifacts, lane, phase) {
|
|
|
29
29
|
return artifacts.find((artifact) => normalizedArtifactKind(artifact.kind) === "command" && artifact.slug.trim().toLowerCase() === slug);
|
|
30
30
|
}
|
|
31
31
|
export function resolveCommandSlug(lane, phase) {
|
|
32
|
-
const normalizedPhase = phase.trim().toLowerCase();
|
|
33
|
-
if (normalizedPhase === "self_review") {
|
|
34
|
-
return "self-review-prompt";
|
|
35
|
-
}
|
|
32
|
+
const normalizedPhase = phase.trim().toLowerCase().replace(/-/g, "_");
|
|
36
33
|
if (normalizedPhase === "rework") {
|
|
37
34
|
return "rework-prompt";
|
|
38
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.1-dev.
|
|
3
|
+
"version": "0.1.1-dev.e52b249f07a8",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|