minimal-forge-work-pack-sync 0.1.41 → 0.1.43

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.41";
7610
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.43";
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";
@@ -7697,7 +7697,7 @@ function managedPermission(value) {
7697
7697
  forge_decide_run: "allow",
7698
7698
  forge_generate_codebook: "allow",
7699
7699
  forge_image: "allow",
7700
- forge_feedback: "deny"
7700
+ forge_feedback: "ask"
7701
7701
  };
7702
7702
  }
7703
7703
  function withoutLegacyForgeProviders(provider) {
@@ -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);
@@ -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.41";
26455
+ var PLUGIN_VERSION = "0.1.43";
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
  }
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.41";
404
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.43";
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";
@@ -491,7 +491,7 @@ function managedPermission(value) {
491
491
  forge_decide_run: "allow",
492
492
  forge_generate_codebook: "allow",
493
493
  forge_image: "allow",
494
- forge_feedback: "deny"
494
+ forge_feedback: "ask"
495
495
  };
496
496
  }
497
497
  function withoutLegacyForgeProviders(provider) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {