minimal-forge-work-pack-sync 0.1.19 → 0.1.21
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/index.js +137 -80
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7367,77 +7367,6 @@ var require_dist = __commonJS({
|
|
|
7367
7367
|
}
|
|
7368
7368
|
});
|
|
7369
7369
|
|
|
7370
|
-
// packages/cli/src/workPackSyncPlugin.ts
|
|
7371
|
-
import { createHash as createHash5 } from "node:crypto";
|
|
7372
|
-
import { pathToFileURL } from "node:url";
|
|
7373
|
-
|
|
7374
|
-
// packages/cli/src/skillUsageReporter.ts
|
|
7375
|
-
function skillUsageReporter(origin, credentialId, send) {
|
|
7376
|
-
const symbol2 = /* @__PURE__ */ Symbol.for("minimal-forge.skill-usage.v1");
|
|
7377
|
-
const shared = globalThis;
|
|
7378
|
-
const origins = shared[symbol2] ??= /* @__PURE__ */ new Map();
|
|
7379
|
-
let owner = origins.get(origin);
|
|
7380
|
-
if (!owner) {
|
|
7381
|
-
owner = { seen: /* @__PURE__ */ new Map(), reporters: /* @__PURE__ */ new Map() };
|
|
7382
|
-
origins.set(origin, owner);
|
|
7383
|
-
}
|
|
7384
|
-
const seen = owner.seen;
|
|
7385
|
-
let state = owner.reporters.get(credentialId);
|
|
7386
|
-
if (!state) {
|
|
7387
|
-
state = { pending: [], sending: false, nextSend: 0 };
|
|
7388
|
-
owner.reporters.set(credentialId, state);
|
|
7389
|
-
}
|
|
7390
|
-
const reporter = state;
|
|
7391
|
-
function schedule() {
|
|
7392
|
-
if (reporter.timer || reporter.sending || !reporter.pending.length) return;
|
|
7393
|
-
reporter.timer = setTimeout(() => {
|
|
7394
|
-
reporter.timer = void 0;
|
|
7395
|
-
void flush();
|
|
7396
|
-
}, Math.max(1e3, reporter.nextSend - Date.now()));
|
|
7397
|
-
reporter.timer.unref?.();
|
|
7398
|
-
}
|
|
7399
|
-
async function flush() {
|
|
7400
|
-
if (reporter.sending || !reporter.pending.length) return;
|
|
7401
|
-
reporter.sending = true;
|
|
7402
|
-
reporter.nextSend = Date.now() + 12e4;
|
|
7403
|
-
const batch = reporter.pending.splice(0, 100);
|
|
7404
|
-
try {
|
|
7405
|
-
const response = await send(batch);
|
|
7406
|
-
if (response.status === 429) {
|
|
7407
|
-
reporter.pending.unshift(...batch);
|
|
7408
|
-
if (reporter.pending.length > 1e3) {
|
|
7409
|
-
reporter.pending.length = 1e3;
|
|
7410
|
-
console.error("[Forge evidence] Local usage buffer full after rate rejection");
|
|
7411
|
-
}
|
|
7412
|
-
const retry = Number(response.headers.get("retry-after"));
|
|
7413
|
-
reporter.nextSend = Date.now() + Math.max(12e4, Number.isFinite(retry) ? retry * 1e3 : 0);
|
|
7414
|
-
} else if (!response.ok) console.error(`[Forge evidence] Upload rejected (HTTP ${response.status})`);
|
|
7415
|
-
} catch {
|
|
7416
|
-
console.error("[Forge evidence] Upload unconfirmed; batch not retried");
|
|
7417
|
-
} finally {
|
|
7418
|
-
reporter.sending = false;
|
|
7419
|
-
schedule();
|
|
7420
|
-
}
|
|
7421
|
-
}
|
|
7422
|
-
return (sessionID, callID, slug) => {
|
|
7423
|
-
if (!sessionID || !callID) return;
|
|
7424
|
-
const now = Date.now();
|
|
7425
|
-
for (const [key2, at2] of seen) if (now - at2 > 24 * 60 * 6e4) seen.delete(key2);
|
|
7426
|
-
const key = JSON.stringify([sessionID, callID]);
|
|
7427
|
-
if (seen.has(key)) return;
|
|
7428
|
-
if (seen.size >= 2e4 || reporter.pending.length >= 1e3) {
|
|
7429
|
-
console.error("[Forge evidence] Local usage buffer full");
|
|
7430
|
-
return;
|
|
7431
|
-
}
|
|
7432
|
-
seen.set(key, now);
|
|
7433
|
-
const day = new Date(now).toISOString().slice(0, 10);
|
|
7434
|
-
const existing = reporter.pending.find((event) => event.slug === slug && event.day === day && event.count < 100);
|
|
7435
|
-
if (existing) existing.count++;
|
|
7436
|
-
else reporter.pending.push({ kind: "work_pack_invocation", slug, day, count: 1 });
|
|
7437
|
-
schedule();
|
|
7438
|
-
};
|
|
7439
|
-
}
|
|
7440
|
-
|
|
7441
7370
|
// packages/shared/src/contracts/models.ts
|
|
7442
7371
|
var BUILT_IN_OPENROUTER_MODELS = [
|
|
7443
7372
|
{
|
|
@@ -7594,6 +7523,11 @@ function openRouterReasoningVariants(efforts) {
|
|
|
7594
7523
|
return Object.fromEntries(efforts.map((effort) => [effort, { reasoning: { effort } }]));
|
|
7595
7524
|
}
|
|
7596
7525
|
|
|
7526
|
+
// packages/shared/src/runtimeObservation.ts
|
|
7527
|
+
function runtimeVersion(value) {
|
|
7528
|
+
return typeof value === "string" && /^[0-9][A-Za-z0-9.+_-]{0,63}$/.test(value) ? value : void 0;
|
|
7529
|
+
}
|
|
7530
|
+
|
|
7597
7531
|
// packages/shared/src/contracts/debugTrace.ts
|
|
7598
7532
|
var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
7599
7533
|
eventEnvelopeBytes: 256 * 1024,
|
|
@@ -7614,7 +7548,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
|
7614
7548
|
};
|
|
7615
7549
|
|
|
7616
7550
|
// packages/shared/src/contracts/settings.ts
|
|
7617
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7551
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.21";
|
|
7618
7552
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7619
7553
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7620
7554
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -7690,6 +7624,127 @@ function integrityKind(summary) {
|
|
|
7690
7624
|
return "match";
|
|
7691
7625
|
}
|
|
7692
7626
|
|
|
7627
|
+
// packages/cli/src/runtimeObservation.ts
|
|
7628
|
+
var UNKNOWN_RUNTIME = {
|
|
7629
|
+
opencode: { status: "unknown" },
|
|
7630
|
+
openwork: { status: "unknown" }
|
|
7631
|
+
};
|
|
7632
|
+
async function observeRuntime(input) {
|
|
7633
|
+
const engine = input?.serverUrl;
|
|
7634
|
+
const engineHeaders = {};
|
|
7635
|
+
if (process.env.OPENCODE_SERVER_PASSWORD) {
|
|
7636
|
+
engineHeaders.authorization = `Basic ${Buffer.from(`${process.env.OPENCODE_SERVER_USERNAME || "opencode"}:${process.env.OPENCODE_SERVER_PASSWORD}`).toString("base64")}`;
|
|
7637
|
+
}
|
|
7638
|
+
let server;
|
|
7639
|
+
const token = process.env.OPENWORK_SERVER_TOKEN;
|
|
7640
|
+
if (process.env.OPENWORK_SERVER_URL && token) {
|
|
7641
|
+
try {
|
|
7642
|
+
server = new URL(process.env.OPENWORK_SERVER_URL);
|
|
7643
|
+
} catch {
|
|
7644
|
+
}
|
|
7645
|
+
}
|
|
7646
|
+
const [opencode, openwork] = await Promise.all([
|
|
7647
|
+
probeHealth(engine, "/global/health", engineHeaders, "healthy", "engine-health"),
|
|
7648
|
+
probeHealth(server, "/health", token ? { authorization: `Bearer ${token}` } : {}, "ok", "server-health")
|
|
7649
|
+
]);
|
|
7650
|
+
return { opencode, openwork };
|
|
7651
|
+
}
|
|
7652
|
+
async function probeHealth(url2, route, headers, healthyField, source) {
|
|
7653
|
+
if (!(url2 instanceof URL) || !["http:", "https:"].includes(url2.protocol) || !["localhost", "127.0.0.1", "[::1]"].includes(url2.hostname) || url2.username || url2.password || url2.search || url2.hash) return { status: "unknown" };
|
|
7654
|
+
let timer;
|
|
7655
|
+
const controller = new AbortController();
|
|
7656
|
+
try {
|
|
7657
|
+
const probe = async () => {
|
|
7658
|
+
const response = await fetch(new URL(route, url2), { headers, signal: controller.signal, redirect: "error" });
|
|
7659
|
+
if (!response.ok) return { status: "unknown" };
|
|
7660
|
+
const body = await response.json();
|
|
7661
|
+
const version2 = runtimeVersion(body?.version);
|
|
7662
|
+
return body?.[healthyField] === true && version2 ? { status: "known", version: version2, source } : { status: "unknown" };
|
|
7663
|
+
};
|
|
7664
|
+
return await Promise.race([probe(), new Promise((resolve) => {
|
|
7665
|
+
timer = setTimeout(() => {
|
|
7666
|
+
controller.abort();
|
|
7667
|
+
resolve({ status: "unknown" });
|
|
7668
|
+
}, 500);
|
|
7669
|
+
})]);
|
|
7670
|
+
} catch {
|
|
7671
|
+
return { status: "unknown" };
|
|
7672
|
+
} finally {
|
|
7673
|
+
if (timer) clearTimeout(timer);
|
|
7674
|
+
}
|
|
7675
|
+
}
|
|
7676
|
+
|
|
7677
|
+
// packages/cli/src/workPackSyncPlugin.ts
|
|
7678
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
7679
|
+
import { pathToFileURL } from "node:url";
|
|
7680
|
+
|
|
7681
|
+
// packages/cli/src/skillUsageReporter.ts
|
|
7682
|
+
function skillUsageReporter(origin, credentialId, send) {
|
|
7683
|
+
const symbol2 = /* @__PURE__ */ Symbol.for("minimal-forge.skill-usage.v1");
|
|
7684
|
+
const shared = globalThis;
|
|
7685
|
+
const origins = shared[symbol2] ??= /* @__PURE__ */ new Map();
|
|
7686
|
+
let owner = origins.get(origin);
|
|
7687
|
+
if (!owner) {
|
|
7688
|
+
owner = { seen: /* @__PURE__ */ new Map(), reporters: /* @__PURE__ */ new Map() };
|
|
7689
|
+
origins.set(origin, owner);
|
|
7690
|
+
}
|
|
7691
|
+
const seen = owner.seen;
|
|
7692
|
+
let state = owner.reporters.get(credentialId);
|
|
7693
|
+
if (!state) {
|
|
7694
|
+
state = { pending: [], sending: false, nextSend: 0 };
|
|
7695
|
+
owner.reporters.set(credentialId, state);
|
|
7696
|
+
}
|
|
7697
|
+
const reporter = state;
|
|
7698
|
+
function schedule() {
|
|
7699
|
+
if (reporter.timer || reporter.sending || !reporter.pending.length) return;
|
|
7700
|
+
reporter.timer = setTimeout(() => {
|
|
7701
|
+
reporter.timer = void 0;
|
|
7702
|
+
void flush();
|
|
7703
|
+
}, Math.max(1e3, reporter.nextSend - Date.now()));
|
|
7704
|
+
reporter.timer.unref?.();
|
|
7705
|
+
}
|
|
7706
|
+
async function flush() {
|
|
7707
|
+
if (reporter.sending || !reporter.pending.length) return;
|
|
7708
|
+
reporter.sending = true;
|
|
7709
|
+
reporter.nextSend = Date.now() + 12e4;
|
|
7710
|
+
const batch = reporter.pending.splice(0, 100);
|
|
7711
|
+
try {
|
|
7712
|
+
const response = await send(batch);
|
|
7713
|
+
if (response.status === 429) {
|
|
7714
|
+
reporter.pending.unshift(...batch);
|
|
7715
|
+
if (reporter.pending.length > 1e3) {
|
|
7716
|
+
reporter.pending.length = 1e3;
|
|
7717
|
+
console.error("[Forge evidence] Local usage buffer full after rate rejection");
|
|
7718
|
+
}
|
|
7719
|
+
const retry = Number(response.headers.get("retry-after"));
|
|
7720
|
+
reporter.nextSend = Date.now() + Math.max(12e4, Number.isFinite(retry) ? retry * 1e3 : 0);
|
|
7721
|
+
} else if (!response.ok) console.error(`[Forge evidence] Upload rejected (HTTP ${response.status})`);
|
|
7722
|
+
} catch {
|
|
7723
|
+
console.error("[Forge evidence] Upload unconfirmed; batch not retried");
|
|
7724
|
+
} finally {
|
|
7725
|
+
reporter.sending = false;
|
|
7726
|
+
schedule();
|
|
7727
|
+
}
|
|
7728
|
+
}
|
|
7729
|
+
return (sessionID, callID, slug) => {
|
|
7730
|
+
if (!sessionID || !callID) return;
|
|
7731
|
+
const now = Date.now();
|
|
7732
|
+
for (const [key2, at2] of seen) if (now - at2 > 24 * 60 * 6e4) seen.delete(key2);
|
|
7733
|
+
const key = JSON.stringify([sessionID, callID]);
|
|
7734
|
+
if (seen.has(key)) return;
|
|
7735
|
+
if (seen.size >= 2e4 || reporter.pending.length >= 1e3) {
|
|
7736
|
+
console.error("[Forge evidence] Local usage buffer full");
|
|
7737
|
+
return;
|
|
7738
|
+
}
|
|
7739
|
+
seen.set(key, now);
|
|
7740
|
+
const day = new Date(now).toISOString().slice(0, 10);
|
|
7741
|
+
const existing = reporter.pending.find((event) => event.slug === slug && event.day === day && event.count < 100);
|
|
7742
|
+
if (existing) existing.count++;
|
|
7743
|
+
else reporter.pending.push({ kind: "work_pack_invocation", slug, day, count: 1 });
|
|
7744
|
+
schedule();
|
|
7745
|
+
};
|
|
7746
|
+
}
|
|
7747
|
+
|
|
7693
7748
|
// packages/cli/src/pluginWriter.ts
|
|
7694
7749
|
var FORGE_PLUGIN_HEADER = "// Managed by Forge sync. Do not edit.";
|
|
7695
7750
|
var FORGE_EVIDENCE_PLUGIN_FILENAME = "forge-evidence.js";
|
|
@@ -20330,7 +20385,7 @@ function resolveOpenCodeDir(home, platform, env, exists, pathApi) {
|
|
|
20330
20385
|
// packages/cli/src/report.ts
|
|
20331
20386
|
import os2 from "node:os";
|
|
20332
20387
|
var AGENT_VERSION = "0.1.0";
|
|
20333
|
-
async function reportFailure(credentials, kind, error45) {
|
|
20388
|
+
async function reportFailure(credentials, kind, error45, runtime = UNKNOWN_RUNTIME) {
|
|
20334
20389
|
try {
|
|
20335
20390
|
const message = error45 instanceof Error ? error45.message : String(error45);
|
|
20336
20391
|
await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/report`, {
|
|
@@ -20344,6 +20399,7 @@ async function reportFailure(credentials, kind, error45) {
|
|
|
20344
20399
|
body: JSON.stringify({
|
|
20345
20400
|
kind,
|
|
20346
20401
|
ok: false,
|
|
20402
|
+
...runtime ? { runtime } : {},
|
|
20347
20403
|
message
|
|
20348
20404
|
}),
|
|
20349
20405
|
signal: AbortSignal.timeout(3e3)
|
|
@@ -20352,7 +20408,7 @@ async function reportFailure(credentials, kind, error45) {
|
|
|
20352
20408
|
console.error("[Forge] Failed to report failure to Forge server:", error46 instanceof Error ? error46.message : String(error46));
|
|
20353
20409
|
}
|
|
20354
20410
|
}
|
|
20355
|
-
async function reportWorkPackObservations(credentials, kind, workPacks) {
|
|
20411
|
+
async function reportWorkPackObservations(credentials, kind, workPacks, runtime = UNKNOWN_RUNTIME) {
|
|
20356
20412
|
try {
|
|
20357
20413
|
await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/report`, {
|
|
20358
20414
|
method: "POST",
|
|
@@ -20362,7 +20418,7 @@ async function reportWorkPackObservations(credentials, kind, workPacks) {
|
|
|
20362
20418
|
"x-forge-hostname": os2.hostname(),
|
|
20363
20419
|
"x-forge-agent-version": AGENT_VERSION
|
|
20364
20420
|
},
|
|
20365
|
-
body: JSON.stringify({ kind, ok: true, workPacks }),
|
|
20421
|
+
body: JSON.stringify({ kind, ok: true, workPacks, ...runtime ? { runtime } : {} }),
|
|
20366
20422
|
signal: AbortSignal.timeout(3e3)
|
|
20367
20423
|
});
|
|
20368
20424
|
} catch (error45) {
|
|
@@ -25099,14 +25155,14 @@ function isRecord(value) {
|
|
|
25099
25155
|
}
|
|
25100
25156
|
|
|
25101
25157
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
25102
|
-
var PLUGIN_VERSION = "0.1.
|
|
25158
|
+
var PLUGIN_VERSION = "0.1.21";
|
|
25103
25159
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
25104
25160
|
var activeSync = /* @__PURE__ */ new Map();
|
|
25105
25161
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
25106
25162
|
const forgeBaseUrl = parseForgeBaseUrl(options);
|
|
25107
25163
|
let sync = activeSync.get(forgeBaseUrl);
|
|
25108
25164
|
if (!sync) {
|
|
25109
|
-
sync = synchronizeAtStartup(forgeBaseUrl);
|
|
25165
|
+
sync = synchronizeAtStartup(forgeBaseUrl, _input);
|
|
25110
25166
|
activeSync.set(forgeBaseUrl, sync);
|
|
25111
25167
|
}
|
|
25112
25168
|
const state = await sync;
|
|
@@ -25188,18 +25244,19 @@ function createForgeFeedbackTool(forgeBaseUrl, paths) {
|
|
|
25188
25244
|
}
|
|
25189
25245
|
});
|
|
25190
25246
|
}
|
|
25191
|
-
async function synchronizeAtStartup(forgeBaseUrl) {
|
|
25247
|
+
async function synchronizeAtStartup(forgeBaseUrl, input) {
|
|
25192
25248
|
const paths = resolveStartupPaths();
|
|
25193
25249
|
const before = await managedProjectionNames(paths);
|
|
25194
25250
|
let credentials;
|
|
25195
25251
|
let forgeConfigVerified = false;
|
|
25252
|
+
const runtime = await observeRuntime(input);
|
|
25196
25253
|
try {
|
|
25197
25254
|
await retireDebugCapture(paths);
|
|
25198
25255
|
credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
25199
25256
|
const manifest = await fetchManifest(credentials);
|
|
25200
25257
|
forgeConfigVerified = true;
|
|
25201
25258
|
const result = await applyWorkPackManifest(paths, credentials, manifest, {});
|
|
25202
|
-
await reportWorkPackObservations(credentials, "sync", result.workPackObservations);
|
|
25259
|
+
await reportWorkPackObservations(credentials, "sync", result.workPackObservations, runtime);
|
|
25203
25260
|
const failures = result.workPacks.outcomes.filter(
|
|
25204
25261
|
(outcome) => outcome.status === "failed" || outcome.status === "recovery-uncertain"
|
|
25205
25262
|
);
|
|
@@ -25227,7 +25284,7 @@ async function synchronizeAtStartup(forgeBaseUrl) {
|
|
|
25227
25284
|
attemptedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25228
25285
|
message
|
|
25229
25286
|
}).catch(() => void 0);
|
|
25230
|
-
if (credentials) await reportFailure(credentials, "sync", new Error(message));
|
|
25287
|
+
if (credentials) await reportFailure(credentials, "sync", new Error(message), runtime);
|
|
25231
25288
|
const after = await managedProjectionNames(paths).catch(() => before);
|
|
25232
25289
|
return { paths, before, after, forgeConfigVerified };
|
|
25233
25290
|
}
|