@loucompanion/forge-bridge 0.1.1-dev.32d4dd5874ee → 0.1.1-dev.4f31cdd58cac
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/session/phase-completion.d.ts +32 -0
- package/dist/session/phase-completion.js +360 -79
- package/dist/session/provider-cli/provider-cli.service.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.service.js +351 -54
- package/dist/session/provider-cli/provider-usage.d.ts +25 -0
- package/dist/session/provider-cli/provider-usage.js +64 -0
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +11 -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,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
|
+
}
|
|
@@ -18,6 +18,7 @@ export interface DispatchResolvedArtifact {
|
|
|
18
18
|
readonly scope: string;
|
|
19
19
|
readonly body: string;
|
|
20
20
|
readonly contentHash: string;
|
|
21
|
+
readonly version: number;
|
|
21
22
|
readonly lane?: string | null;
|
|
22
23
|
readonly event?: string | null;
|
|
23
24
|
}
|
|
@@ -86,6 +87,10 @@ export interface RunnerDispatchEvent {
|
|
|
86
87
|
readonly kind: string;
|
|
87
88
|
readonly content: string;
|
|
88
89
|
readonly eventType: string;
|
|
90
|
+
/** Provider/runner-reported event time (ISO-8601) when available, preserved for accurate durations. */
|
|
91
|
+
readonly occurredAt?: string | null;
|
|
92
|
+
/** Optional structured telemetry payload (JSON string), e.g. token usage for provider_usage events. */
|
|
93
|
+
readonly data?: string | null;
|
|
89
94
|
}
|
|
90
95
|
export interface RunnerDispatchSpec {
|
|
91
96
|
readonly repoPath: string;
|
|
@@ -153,6 +153,7 @@ function parseArtifacts(value) {
|
|
|
153
153
|
scope: requiredString(artifact, "scope"),
|
|
154
154
|
body: optionalString(artifact, "body") ?? "",
|
|
155
155
|
contentHash: requiredString(artifact, "contentHash"),
|
|
156
|
+
version: optionalPositiveInteger(artifact, "version") ?? 1,
|
|
156
157
|
lane: optionalString(artifact, "lane"),
|
|
157
158
|
event: optionalString(artifact, "event")
|
|
158
159
|
};
|
|
@@ -188,6 +189,16 @@ function requiredBoolean(source, key) {
|
|
|
188
189
|
}
|
|
189
190
|
return value;
|
|
190
191
|
}
|
|
192
|
+
function optionalPositiveInteger(source, key) {
|
|
193
|
+
const value = source[key];
|
|
194
|
+
if (value === undefined || value === null) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
198
|
+
throw new Error(`${key} must be a positive integer when provided.`);
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
191
202
|
function requiredNumber(source, key) {
|
|
192
203
|
const value = source[key];
|
|
193
204
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
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.4f31cdd58cac";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.1-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.1-dev.4f31cdd58cac";
|
|
@@ -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.4f31cdd58cac",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|