minimal-forge-work-pack-sync 0.1.27 → 0.1.30

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.
Files changed (2) hide show
  1. package/dist/index.js +62 -43
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -664,36 +664,38 @@ var require_Alias = __commonJS({
664
664
  if (node.anchor === this.source)
665
665
  found = node;
666
666
  }
667
+ if (found && ctx) {
668
+ const { anchors: anchors2, doc: doc2, maxAliasCount } = ctx;
669
+ let data = anchors2.get(found);
670
+ if (!data) {
671
+ toJS.toJS(found, null, ctx);
672
+ data = anchors2.get(found);
673
+ }
674
+ if (data?.res === void 0) {
675
+ const msg = "This should not happen: Alias anchor was not resolved?";
676
+ throw new ReferenceError(msg);
677
+ }
678
+ if (maxAliasCount >= 0) {
679
+ data.count += 1;
680
+ if (data.aliasCount === 0)
681
+ data.aliasCount = getAliasCount(doc2, found, anchors2);
682
+ if (data.count * data.aliasCount > maxAliasCount) {
683
+ const msg = "Excessive alias count indicates a resource exhaustion attack";
684
+ throw new ReferenceError(msg);
685
+ }
686
+ }
687
+ }
667
688
  return found;
668
689
  }
669
690
  toJSON(_arg, ctx) {
670
691
  if (!ctx)
671
692
  return { source: this.source };
672
- const { anchors: anchors2, doc, maxAliasCount } = ctx;
673
- const source = this.resolve(doc, ctx);
693
+ const source = this.resolve(ctx.doc, ctx);
674
694
  if (!source) {
675
695
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
676
696
  throw new ReferenceError(msg);
677
697
  }
678
- let data = anchors2.get(source);
679
- if (!data) {
680
- toJS.toJS(source, null, ctx);
681
- data = anchors2.get(source);
682
- }
683
- if (data?.res === void 0) {
684
- const msg = "This should not happen: Alias anchor was not resolved?";
685
- throw new ReferenceError(msg);
686
- }
687
- if (maxAliasCount >= 0) {
688
- data.count += 1;
689
- if (data.aliasCount === 0)
690
- data.aliasCount = getAliasCount(doc, source, anchors2);
691
- if (data.count * data.aliasCount > maxAliasCount) {
692
- const msg = "Excessive alias count indicates a resource exhaustion attack";
693
- throw new ReferenceError(msg);
694
- }
695
- }
696
- return data.res;
698
+ return ctx.anchors.get(source).res;
697
699
  }
698
700
  toString(ctx, _onComment, _onChompKeep) {
699
701
  const src = `*${this.source}`;
@@ -4695,37 +4697,38 @@ var require_resolve_flow_scalar = __commonJS({
4695
4697
  }
4696
4698
  if (badChar)
4697
4699
  onError(0, "BAD_SCALAR_START", `Plain value cannot start with ${badChar}`);
4698
- return foldLines(source);
4700
+ return unfoldLines(source);
4699
4701
  }
4700
4702
  function singleQuotedValue(source, onError) {
4701
4703
  if (source[source.length - 1] !== "'" || source.length === 1)
4702
4704
  onError(source.length, "MISSING_CHAR", "Missing closing 'quote");
4703
- return foldLines(source.slice(1, -1)).replace(/''/g, "'");
4705
+ return unfoldLines(source.slice(1, -1)).replace(/''/g, "'");
4704
4706
  }
4705
- function foldLines(source) {
4706
- let first, line;
4707
+ function unfoldLines(source) {
4708
+ const line = /(.*?)\r?\n/sy;
4709
+ let match = line.exec(source);
4710
+ if (!match)
4711
+ return source;
4712
+ let trimEnd, trimBoth;
4707
4713
  try {
4708
- first = new RegExp("(.*?)(?<![ ])[ ]*\r?\n", "sy");
4709
- line = new RegExp("[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?\n", "sy");
4714
+ trimEnd = new RegExp("(?<![ ])[ ]+$");
4715
+ trimBoth = new RegExp("^[ ]+|(?<![ ])[ ]+$", "g");
4710
4716
  } catch {
4711
- first = /(.*?)[ \t]*\r?\n/sy;
4712
- line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
4717
+ trimEnd = /[ \t]+$/;
4718
+ trimBoth = /^[ \t]+|[ \t]+$/g;
4713
4719
  }
4714
- let match = first.exec(source);
4715
- if (!match)
4716
- return source;
4717
- let res = match[1];
4720
+ let res = match[1].replace(trimEnd, "");
4718
4721
  let sep = " ";
4719
- let pos = first.lastIndex;
4720
- line.lastIndex = pos;
4722
+ let pos = line.lastIndex;
4721
4723
  while (match = line.exec(source)) {
4722
- if (match[1] === "") {
4724
+ const lm = match[1].replace(trimBoth, "");
4725
+ if (lm === "") {
4723
4726
  if (sep === "\n")
4724
4727
  res += sep;
4725
4728
  else
4726
4729
  sep = "\n";
4727
4730
  } else {
4728
- res += sep + match[1];
4731
+ res += sep + lm;
4729
4732
  sep = " ";
4730
4733
  }
4731
4734
  pos = line.lastIndex;
@@ -7548,7 +7551,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
7548
7551
  };
7549
7552
 
7550
7553
  // packages/shared/src/contracts/settings.ts
7551
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.27";
7554
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.30";
7552
7555
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
7553
7556
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
7554
7557
  var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
@@ -7922,7 +7925,7 @@ async function replaceFile(filename, contents) {
7922
7925
 
7923
7926
  // packages/cli/src/workPackSyncPlugin.ts
7924
7927
  var import_yaml = __toESM(require_dist(), 1);
7925
- import { mkdir as mkdir3, readdir as readdir4, readFile as readFile4, rename as rename4, writeFile as writeFile4 } from "node:fs/promises";
7928
+ import { mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir4, readFile as readFile4, rename as rename4, writeFile as writeFile4 } from "node:fs/promises";
7926
7929
  import path6 from "node:path";
7927
7930
 
7928
7931
  // node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
@@ -25165,7 +25168,7 @@ function isRecord(value) {
25165
25168
  }
25166
25169
 
25167
25170
  // packages/cli/src/workPackSyncPlugin.ts
25168
- var PLUGIN_VERSION = "0.1.27";
25171
+ var PLUGIN_VERSION = "0.1.30";
25169
25172
  var FORGE_DECISION_TIMEOUT_MS = 11e4;
25170
25173
  var STATUS_FILENAME = "work-pack-startup-status.json";
25171
25174
  var activeSync = /* @__PURE__ */ new Map();
@@ -25248,7 +25251,7 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
25248
25251
  })
25249
25252
  ]);
25250
25253
  return tool({
25251
- description: "Pede ao Jev uma ou mais decis\xF5es estruturadas sobre o mesmo estado. Usa este recurso para classifica\xE7\xE3o, escolha ou pontua\xE7\xE3o; n\xE3o para gerar texto livre.",
25254
+ description: "Pede ao Jev uma ou mais decis\xF5es estruturadas sobre o mesmo estado. Usa este recurso para classifica\xE7\xE3o, escolha ou pontua\xE7\xE3o; n\xE3o para gerar texto livre. Guarda a resposta integral num ficheiro local e devolve response_file; copiar esse ficheiro, sem transcrever o JSON.",
25252
25255
  args: {
25253
25256
  state: tool.schema.union([
25254
25257
  tool.schema.string(),
@@ -25258,6 +25261,8 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
25258
25261
  questions: tool.schema.record(tool.schema.string(), question).describe("Perguntas identificadas por uma chave est\xE1vel")
25259
25262
  },
25260
25263
  async execute(args, context) {
25264
+ const responseDir = await mkdtemp2(path6.join(context.directory, ".forge-decision-"));
25265
+ const responseFile = path6.join(responseDir, "response.json");
25261
25266
  const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
25262
25267
  const response = await fetch(`${decisionBaseUrl}/v1/decisions`, {
25263
25268
  method: "POST",
@@ -25269,9 +25274,23 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
25269
25274
  body: JSON.stringify({ state: args.state, questions: args.questions }),
25270
25275
  signal: AbortSignal.any([context.abort, AbortSignal.timeout(FORGE_DECISION_TIMEOUT_MS)])
25271
25276
  });
25272
- const body = await response.json().catch(() => void 0);
25277
+ const raw = await response.text();
25278
+ let body;
25279
+ try {
25280
+ body = JSON.parse(raw);
25281
+ } catch {
25282
+ }
25273
25283
  if (response.ok && body && typeof body === "object" && body.answers && typeof body.answers === "object") {
25274
- return JSON.stringify(body, null, 2);
25284
+ try {
25285
+ await writeFile4(responseFile, raw, { flag: "wx", mode: 384 });
25286
+ return JSON.stringify({ ...body, response_file: responseFile }, null, 2);
25287
+ } catch {
25288
+ return JSON.stringify({
25289
+ ...body,
25290
+ response_file: null,
25291
+ persistence_error: "A decis\xE3o foi conclu\xEDda, mas n\xE3o foi poss\xEDvel guardar o ficheiro. Recuperar esta resposta do hist\xF3rico da ferramenta; n\xE3o repetir a chamada ao Jev."
25292
+ }, null, 2);
25293
+ }
25275
25294
  }
25276
25295
  const nested = body?.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : void 0;
25277
25296
  const safeError = typeof nested === "string" && nested.length <= 300 ? nested.replace(/forge_[A-Za-z0-9_-]+/g, "<credencial oculta>") : `O Forge n\xE3o concluiu a decis\xE3o (HTTP ${response.status})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.27",
3
+ "version": "0.1.30",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {