minimal-forge-work-pack-sync 0.1.40 → 0.1.42

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 CHANGED
@@ -7607,7 +7607,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
7607
7607
  // packages/shared/src/contracts/settings.ts
7608
7608
  var DOCUMENT_READER_AGENT = "document-reader";
7609
7609
  var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
7610
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.40";
7610
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.42";
7611
7611
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
7612
7612
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
7613
7613
  var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
@@ -7918,7 +7918,7 @@ function skillUsageReporter(origin, credentialId, send) {
7918
7918
  schedule();
7919
7919
  }
7920
7920
  }
7921
- return (sessionID, callID, slug) => {
7921
+ return (sessionID, callID, slug, kind = "work_pack_invocation") => {
7922
7922
  if (!sessionID || !callID) return;
7923
7923
  const now = Date.now();
7924
7924
  for (const [key2, at2] of seen) if (now - at2 > 24 * 60 * 6e4) seen.delete(key2);
@@ -7930,9 +7930,9 @@ function skillUsageReporter(origin, credentialId, send) {
7930
7930
  }
7931
7931
  seen.set(key, now);
7932
7932
  const day = new Date(now).toISOString().slice(0, 10);
7933
- const existing = reporter.pending.find((event) => event.slug === slug && event.day === day && event.count < 100);
7933
+ const existing = reporter.pending.find((event) => event.kind === kind && event.slug === slug && event.day === day && event.count < 100);
7934
7934
  if (existing) existing.count++;
7935
- else reporter.pending.push({ kind: "work_pack_invocation", slug, day, count: 1 });
7935
+ else reporter.pending.push({ kind, slug, day, count: 1 });
7936
7936
  schedule();
7937
7937
  };
7938
7938
  }
@@ -8206,7 +8206,12 @@ var ReasoningLoopDetector = class {
8206
8206
  return this.rule;
8207
8207
  }
8208
8208
  push(text) {
8209
- if (this.rule || !text) return this.rule;
8209
+ for (let index = 0; index < text.length && !this.rule; index += CYCLE_CHECK_STRIDE) {
8210
+ this.pushSegment(text.slice(index, index + CYCLE_CHECK_STRIDE));
8211
+ }
8212
+ return this.rule;
8213
+ }
8214
+ pushSegment(text) {
8210
8215
  if (this.pushLines(text)) return this.rule = "reasoning-lines";
8211
8216
  this.tail = (this.tail + text).slice(-CYCLE_TAIL_CHARS);
8212
8217
  this.sinceCycleCheck += text.length;
@@ -8222,14 +8227,18 @@ var ReasoningLoopDetector = class {
8222
8227
  this.addLine(this.partial.slice(0, index).trim());
8223
8228
  this.partial = this.partial.slice(index + 1);
8224
8229
  }
8225
- if (this.partial.length > LINE_KEY_MAX_CHARS) this.partial = this.partial.slice(-LINE_KEY_MAX_CHARS);
8230
+ if (this.partial.length > LINE_KEY_MAX_CHARS) this.partial = this.partial.slice(-(LINE_KEY_MAX_CHARS + 1));
8226
8231
  if (this.repeatedLineChars < MIN_REPEATED_LINE_CHARS || this.totalLineChars === 0) return false;
8227
8232
  if (this.repeatedLineChars / this.totalLineChars < MIN_REPEATED_LINE_COVERAGE) return false;
8228
8233
  return this.lineInstances / this.lines.size >= MIN_REPEATED_LINE_CONCENTRATION;
8229
8234
  }
8230
8235
  addLine(line) {
8231
8236
  if (line.length < LINE_MIN_CHARS) return;
8232
- const key = line.slice(0, LINE_KEY_MAX_CHARS);
8237
+ if (line.length > LINE_KEY_MAX_CHARS) {
8238
+ this.totalLineChars += LINE_KEY_MAX_CHARS;
8239
+ return;
8240
+ }
8241
+ const key = line;
8233
8242
  const previous = this.lines.get(key) ?? 0;
8234
8243
  if (previous === 0 && this.lines.size >= MAX_DISTINCT_LINES) return;
8235
8244
  this.lines.set(key, previous + 1);
@@ -8240,11 +8249,11 @@ var ReasoningLoopDetector = class {
8240
8249
  }
8241
8250
  };
8242
8251
  var MAX_AUTOMATIC_RESUMES = 1;
8243
- function createReasoningLoopGuard(client, log = console.error) {
8252
+ function createReasoningLoopGuard(client, log = console.error, report = () => void 0) {
8244
8253
  const sessions = /* @__PURE__ */ new Map();
8245
8254
  const session = (id) => {
8246
8255
  let state = sessions.get(id);
8247
- if (!state) sessions.set(id, state = { parts: /* @__PURE__ */ new Map(), closedParts: /* @__PURE__ */ new Set(), interruptions: 0, interrupted: false, resumePending: false });
8256
+ if (!state) sessions.set(id, state = { parts: /* @__PURE__ */ new Map(), closedParts: /* @__PURE__ */ new Set(), interruptions: 0, interrupted: false, resumePending: false, awaitingOutcome: false });
8248
8257
  return state;
8249
8258
  };
8250
8259
  const closeParts = (state) => {
@@ -8257,12 +8266,20 @@ function createReasoningLoopGuard(client, log = console.error) {
8257
8266
  state.interruptions += 1;
8258
8267
  state.resumePending = state.interruptions <= MAX_AUTOMATIC_RESUMES;
8259
8268
  log(`[Forge reasoning guard] Repetitive reasoning interrupted (${rule}, interruption ${state.interruptions})`);
8260
- try {
8261
- await client.session.abort({ path: { id: sessionID } });
8262
- } catch (error45) {
8263
- state.resumePending = false;
8264
- log(`[Forge reasoning guard] Abort failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
8265
- }
8269
+ report(sessionID, rule);
8270
+ if (state.awaitingOutcome) {
8271
+ state.awaitingOutcome = false;
8272
+ report(sessionID, "second-loop");
8273
+ }
8274
+ state.abortRequest = client.session.abort({ path: { id: sessionID } }).then(
8275
+ () => void 0,
8276
+ (error45) => {
8277
+ state.resumePending = false;
8278
+ report(sessionID, "abort-failed");
8279
+ log(`[Forge reasoning guard] Abort failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
8280
+ }
8281
+ );
8282
+ await state.abortRequest;
8266
8283
  }
8267
8284
  async function resume(sessionID, state) {
8268
8285
  state.resumePending = false;
@@ -8275,7 +8292,9 @@ function createReasoningLoopGuard(client, log = console.error) {
8275
8292
  parts: [{ type: "text", text: REASONING_LOOP_RESUME_TEXT }]
8276
8293
  }
8277
8294
  });
8295
+ state.awaitingOutcome = true;
8278
8296
  } catch (error45) {
8297
+ report(sessionID, "resume-failed");
8279
8298
  log(`[Forge reasoning guard] Resume failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
8280
8299
  }
8281
8300
  }
@@ -8283,9 +8302,15 @@ function createReasoningLoopGuard(client, log = console.error) {
8283
8302
  const state = session(sessionID);
8284
8303
  if (state.interrupted || state.closedParts.has(partID)) return;
8285
8304
  let part = state.parts.get(partID);
8286
- if (!part) state.parts.set(partID, part = { detector: new ReasoningLoopDetector(), seen: 0 });
8287
- const fresh = absolute ? text.slice(part.seen) : text;
8288
- part.seen = absolute ? Math.max(part.seen, text.length) : part.seen + text.length;
8305
+ if (!part) state.parts.set(partID, part = { detector: new ReasoningLoopDetector(), pushed: 0, deltaSeen: 0 });
8306
+ let fresh;
8307
+ if (absolute) {
8308
+ fresh = text.slice(part.pushed);
8309
+ } else {
8310
+ part.deltaSeen += text.length;
8311
+ fresh = text.slice(Math.max(0, text.length - (part.deltaSeen - part.pushed)));
8312
+ }
8313
+ part.pushed += fresh.length;
8289
8314
  if (!fresh || part.detector.tripped) return;
8290
8315
  const rule = part.detector.push(fresh);
8291
8316
  if (rule) await interrupt(sessionID, state, rule);
@@ -8321,11 +8346,27 @@ function createReasoningLoopGuard(client, log = console.error) {
8321
8346
  if (typeof sessionID !== "string") return;
8322
8347
  const state = sessions.get(sessionID);
8323
8348
  if (!state) return;
8349
+ await state.abortRequest;
8350
+ state.abortRequest = void 0;
8324
8351
  closeParts(state);
8352
+ const settled = !state.interrupted;
8325
8353
  state.interrupted = false;
8354
+ if (settled && state.awaitingOutcome) {
8355
+ state.awaitingOutcome = false;
8356
+ report(sessionID, "recovered");
8357
+ }
8326
8358
  if (state.resumePending) await resume(sessionID, state);
8327
8359
  return;
8328
8360
  }
8361
+ if (event?.type === "session.error") {
8362
+ const sessionID = properties.sessionID;
8363
+ const state = typeof sessionID === "string" ? sessions.get(sessionID) : void 0;
8364
+ if (state?.awaitingOutcome && !state.interrupted) {
8365
+ state.awaitingOutcome = false;
8366
+ report(sessionID, "resume-failed");
8367
+ }
8368
+ return;
8369
+ }
8329
8370
  if (event?.type === "session.deleted") {
8330
8371
  const info = properties.info;
8331
8372
  if (typeof info?.id === "string") sessions.delete(info.id);
@@ -20821,8 +20862,8 @@ function resolveOpenCodeDir(home, platform, env, exists2, pathApi) {
20821
20862
 
20822
20863
  // packages/cli/src/report.ts
20823
20864
  import os2 from "node:os";
20824
- var AGENT_VERSION = "0.1.0";
20825
- async function reportFailure(credentials, kind, error45, runtime = UNKNOWN_RUNTIME) {
20865
+ var CLI_AGENT_VERSION = "0.1.0";
20866
+ async function reportFailure(credentials, kind, error45, runtime = UNKNOWN_RUNTIME, agentVersion = CLI_AGENT_VERSION) {
20826
20867
  try {
20827
20868
  const message = error45 instanceof Error ? error45.message : String(error45);
20828
20869
  await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/report`, {
@@ -20831,7 +20872,7 @@ async function reportFailure(credentials, kind, error45, runtime = UNKNOWN_RUNTI
20831
20872
  authorization: `Bearer ${credentials.forgeApiKey}`,
20832
20873
  "content-type": "application/json",
20833
20874
  "x-forge-hostname": os2.hostname(),
20834
- "x-forge-agent-version": AGENT_VERSION
20875
+ "x-forge-agent-version": agentVersion
20835
20876
  },
20836
20877
  body: JSON.stringify({
20837
20878
  kind,
@@ -20845,7 +20886,7 @@ async function reportFailure(credentials, kind, error45, runtime = UNKNOWN_RUNTI
20845
20886
  console.error("[Forge] Failed to report failure to Forge server:", error46 instanceof Error ? error46.message : String(error46));
20846
20887
  }
20847
20888
  }
20848
- async function reportWorkPackObservations(credentials, kind, workPacks, runtime = UNKNOWN_RUNTIME) {
20889
+ async function reportWorkPackObservations(credentials, kind, workPacks, runtime = UNKNOWN_RUNTIME, agentVersion = CLI_AGENT_VERSION) {
20849
20890
  try {
20850
20891
  await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/report`, {
20851
20892
  method: "POST",
@@ -20853,7 +20894,7 @@ async function reportWorkPackObservations(credentials, kind, workPacks, runtime
20853
20894
  authorization: `Bearer ${credentials.forgeApiKey}`,
20854
20895
  "content-type": "application/json",
20855
20896
  "x-forge-hostname": os2.hostname(),
20856
- "x-forge-agent-version": AGENT_VERSION
20897
+ "x-forge-agent-version": agentVersion
20857
20898
  },
20858
20899
  body: JSON.stringify({ kind, ok: true, workPacks, ...runtime ? { runtime } : {} }),
20859
20900
  signal: AbortSignal.timeout(3e3)
@@ -24871,14 +24912,14 @@ function buildSyncFailureMessage(operation, details) {
24871
24912
  if (details.body) parts.push(`resposta=${JSON.stringify(details.body)}`);
24872
24913
  return parts.join(" | ");
24873
24914
  }
24874
- async function fetchManifest(credentials) {
24915
+ async function fetchManifest(credentials, agentVersion = "0.1.0") {
24875
24916
  let response;
24876
24917
  try {
24877
24918
  response = await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/manifest`, {
24878
24919
  headers: {
24879
24920
  authorization: `Bearer ${credentials.forgeApiKey}`,
24880
24921
  "x-forge-hostname": os4.hostname(),
24881
- "x-forge-agent-version": "0.1.0"
24922
+ "x-forge-agent-version": agentVersion
24882
24923
  },
24883
24924
  signal: AbortSignal.timeout(15e3)
24884
24925
  });
@@ -26411,7 +26452,7 @@ async function syncLocalWorker(paths, credentials, manifest) {
26411
26452
  }
26412
26453
 
26413
26454
  // packages/cli/src/workPackSyncPlugin.ts
26414
- var PLUGIN_VERSION = "0.1.40";
26455
+ var PLUGIN_VERSION = "0.1.42";
26415
26456
  var FORGE_DECISION_TIMEOUT_MS = 11e4;
26416
26457
  var STATUS_FILENAME = "work-pack-startup-status.json";
26417
26458
  var activeSync = /* @__PURE__ */ new Map();
@@ -26431,8 +26472,25 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
26431
26472
  const legacyOwners = shared[ownershipSymbol] ??= /* @__PURE__ */ new Set();
26432
26473
  const legacyOwnerKey = JSON.stringify([forgeBaseUrl, legacyPath]);
26433
26474
  const client = reasoningLoopGuardClient(_input);
26475
+ const reportEvidence = async (sessionID, callID, slug, kind) => {
26476
+ const { forgeApiKey } = await readForgeCredentials(state.paths, forgeBaseUrl);
26477
+ const credentialId = createHash7("sha256").update(forgeApiKey).digest("hex");
26478
+ const report = skillUsageReporter(forgeBaseUrl, credentialId, (events) => fetch(`${forgeBaseUrl}/sync/evidence`, {
26479
+ method: "POST",
26480
+ redirect: "error",
26481
+ headers: { authorization: `Bearer ${forgeApiKey}`, "content-type": "application/json" },
26482
+ body: JSON.stringify({ events }),
26483
+ signal: AbortSignal.timeout(5e3)
26484
+ }));
26485
+ report(sessionID, callID, slug, kind);
26486
+ };
26487
+ const reportReasoningLoop = (sessionID, outcome) => {
26488
+ reportEvidence(sessionID, `reasoning-loop:${randomUUID4()}`, outcome, "reasoning_loop").catch(() => {
26489
+ console.error("[Forge evidence] Reasoning guard identity unavailable; event not queued");
26490
+ });
26491
+ };
26434
26492
  return {
26435
- ...client ? { event: createReasoningLoopGuard(client) } : {},
26493
+ ...client ? { event: createReasoningLoopGuard(client, console.error, reportReasoningLoop) } : {},
26436
26494
  "tool.execute.after": async (input) => {
26437
26495
  if (input.tool !== "skill" || legacyOwners.has(legacyOwnerKey)) return;
26438
26496
  const slug = typeof input.args?.name === "string" ? input.args.name.trim().toLowerCase() : "";
@@ -26443,16 +26501,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
26443
26501
  return;
26444
26502
  }
26445
26503
  try {
26446
- const { forgeApiKey } = await readForgeCredentials(state.paths, forgeBaseUrl);
26447
- const credentialId = createHash7("sha256").update(forgeApiKey).digest("hex");
26448
- const reportUsage = skillUsageReporter(forgeBaseUrl, credentialId, (events) => fetch(`${forgeBaseUrl}/sync/evidence`, {
26449
- method: "POST",
26450
- redirect: "error",
26451
- headers: { authorization: `Bearer ${forgeApiKey}`, "content-type": "application/json" },
26452
- body: JSON.stringify({ events }),
26453
- signal: AbortSignal.timeout(5e3)
26454
- }));
26455
- reportUsage(input.sessionID, input.callID, slug);
26504
+ await reportEvidence(input.sessionID, input.callID, slug, "work_pack_invocation");
26456
26505
  } catch {
26457
26506
  console.error("[Forge evidence] Invocation identity unavailable; event not queued");
26458
26507
  }
@@ -26819,11 +26868,11 @@ async function synchronizeAtStartup(forgeBaseUrl, input, localConfig) {
26819
26868
  try {
26820
26869
  await retireDebugCapture(paths);
26821
26870
  credentials = await readForgeCredentials(paths, forgeBaseUrl);
26822
- const manifest = await fetchManifest(credentials);
26871
+ const manifest = await fetchManifest(credentials, PLUGIN_VERSION);
26823
26872
  decisionBaseUrl = resolveDecisionBaseUrl(manifest.gatewayBaseUrl, forgeBaseUrl);
26824
26873
  forgeConfigVerified = true;
26825
26874
  const result = localConfig ? await syncLocalWorker(paths, credentials, manifest) : await applyWorkPackManifest(paths, credentials, manifest, {});
26826
- await reportWorkPackObservations(credentials, "sync", result.workPackObservations, runtime);
26875
+ await reportWorkPackObservations(credentials, "sync", result.workPackObservations, runtime, PLUGIN_VERSION);
26827
26876
  const failures = result.workPacks.outcomes.filter(
26828
26877
  (outcome) => outcome.status === "failed" || outcome.status === "recovery-uncertain"
26829
26878
  );
@@ -26851,7 +26900,7 @@ async function synchronizeAtStartup(forgeBaseUrl, input, localConfig) {
26851
26900
  attemptedAt: (/* @__PURE__ */ new Date()).toISOString(),
26852
26901
  message
26853
26902
  }).catch(() => void 0);
26854
- if (credentials) await reportFailure(credentials, "sync", new Error(message), runtime);
26903
+ if (credentials) await reportFailure(credentials, "sync", new Error(message), runtime, PLUGIN_VERSION);
26855
26904
  if (localConfig && !forgeConfigVerified && credentials) {
26856
26905
  decisionBaseUrl = await savedGatewayBaseUrl(paths, credentials, forgeBaseUrl) ?? decisionBaseUrl;
26857
26906
  }
package/dist/repair.js CHANGED
@@ -401,7 +401,7 @@ var DEVICE_ENROLLMENT_PROTOCOL_VERSION = 1;
401
401
  // packages/shared/src/contracts/settings.ts
402
402
  var DOCUMENT_READER_AGENT = "document-reader";
403
403
  var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
404
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.40";
404
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.42";
405
405
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
406
406
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
407
407
  var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
@@ -4187,14 +4187,14 @@ function buildSyncFailureMessage(operation, details) {
4187
4187
  if (details.body) parts.push(`resposta=${JSON.stringify(details.body)}`);
4188
4188
  return parts.join(" | ");
4189
4189
  }
4190
- async function fetchManifest(credentials) {
4190
+ async function fetchManifest(credentials, agentVersion = "0.1.0") {
4191
4191
  let response;
4192
4192
  try {
4193
4193
  response = await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/manifest`, {
4194
4194
  headers: {
4195
4195
  authorization: `Bearer ${credentials.forgeApiKey}`,
4196
4196
  "x-forge-hostname": os2.hostname(),
4197
- "x-forge-agent-version": "0.1.0"
4197
+ "x-forge-agent-version": agentVersion
4198
4198
  },
4199
4199
  signal: AbortSignal.timeout(15e3)
4200
4200
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {