@mergeline/agent 0.6.0 → 0.6.1

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/worker.js +25 -4
  2. package/package.json +1 -1
package/dist/worker.js CHANGED
@@ -42,6 +42,22 @@ const KILL_GRACE_MS = 2000;
42
42
  const REFUSALS = [403, 404, 409];
43
43
  const FENCED_VARS = ["GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN", "SSH_AUTH_SOCK"];
44
44
  const clip = (s, n) => (s.length > n ? s.slice(0, n) : s);
45
+ /** The board's limits on a question and a release reason (block_text's max), and on a PR summary the worker sends. */
46
+ const LONG_MAX = 5000;
47
+ const SUMMARY_MAX = 2000;
48
+ /** Over max: the start of s and " … [cut by the worker: <n> more characters]", all within max (R23). */
49
+ export function cut(s, max) {
50
+ if (s.length <= max)
51
+ return s;
52
+ const mark = (n) => ` … [cut by the worker: ${n} more characters]`;
53
+ let keep = max;
54
+ for (let i = 0; i < 3; i++)
55
+ keep = max - mark(s.length - keep).length;
56
+ const c = s.charCodeAt(keep - 1);
57
+ if (c >= 0xd800 && c <= 0xdbff)
58
+ keep--;
59
+ return s.slice(0, keep) + mark(s.length - keep);
60
+ }
45
61
  /** Reads .mergeline-run/result.json; anything but one of the three forms is no result, with why. */
46
62
  export function readResult(file) {
47
63
  const st = lstatOrNull(file);
@@ -62,7 +78,7 @@ export function readResult(file) {
62
78
  return { outcome: "none", why: "result.json is not a JSON object" };
63
79
  const r = data;
64
80
  const field = { done: "summary", ask: "question", release: "reason" };
65
- const max = { done: 2000, ask: 5000, release: 5000 };
81
+ const max = { done: SUMMARY_MAX, ask: LONG_MAX, release: LONG_MAX };
66
82
  const outcome = r.outcome;
67
83
  if (typeof outcome !== "string" || !(outcome in field)) {
68
84
  return { outcome: "none", why: `unknown outcome ${JSON.stringify(outcome ?? null)}` };
@@ -71,7 +87,7 @@ export function readResult(file) {
71
87
  const text = r[field[o]];
72
88
  if (typeof text !== "string" || !text.trim())
73
89
  return { outcome: "none", why: `"${field[o]}" must be a non-empty string` };
74
- const value = clip(text.trim(), max[o]);
90
+ const value = cut(text.trim(), max[o]);
75
91
  if (o === "done")
76
92
  return { outcome: "done", summary: value };
77
93
  if (o === "ask")
@@ -531,7 +547,7 @@ export async function work(opts) {
531
547
  : null;
532
548
  if (unsafe) {
533
549
  try {
534
- await settle(lbl, () => board.release(ticket.id, unsafe));
550
+ await settle(lbl, () => board.release(ticket.id, cut(unsafe, LONG_MAX)));
535
551
  say(`released: ${unsafe}`);
536
552
  }
537
553
  catch (err) {
@@ -597,12 +613,14 @@ export async function work(opts) {
597
613
  const release = async (reason) => {
598
614
  if (refused)
599
615
  throw new Refused(refused);
616
+ reason = cut(reason.trim(), LONG_MAX);
600
617
  await settle(lbl, () => board.release(ticket.id, reason, usage ?? undefined));
601
618
  say(`released: ${reason}`);
602
619
  return "failed";
603
620
  };
604
621
  const ask = async (question) => {
605
622
  held();
623
+ question = cut(question.trim(), LONG_MAX);
606
624
  await settle(lbl, () => board.askHuman(ticket.id, question));
607
625
  say(`asked: ${question.split("\n")[0]}`);
608
626
  if (usage) {
@@ -1056,7 +1074,10 @@ function killGroup(child) {
1056
1074
  const oneLine = (s) => clip(s.replace(/\s+/g, " ").trim(), 500);
1057
1075
  /** A question for a run that could not push, after what the engine itself asked (if it asked). */
1058
1076
  function withBefore(result, what) {
1059
- return result.outcome === "ask" ? `${result.question}\n\n${what}` : `The engine said done, but its work could not be pushed. ${what}`;
1077
+ // The engine's question gives up its end first, so the worker's line is kept.
1078
+ if (result.outcome === "ask")
1079
+ return `${cut(result.question, Math.max(LONG_MAX - what.length - 2, 500))}\n\n${what}`;
1080
+ return `The engine said done, but its work could not be pushed. ${what}`;
1060
1081
  }
1061
1082
  /** `test` from .mergeline.json on origin/main (never from the worktree), or null. */
1062
1083
  async function repoTest(git, repo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mergeline/agent",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "The agent's side of a Mergeline board: an MCP server and the `board` CLI. Works with any agent tool that runs MCP servers or shell commands.",
5
5
  "license": "MIT",
6
6
  "author": "frontender-ua",