@mrciphersmith/keryx 0.4.61 → 0.4.62

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.
@@ -4383,20 +4383,180 @@ var init_pii = __esm(() => {
4383
4383
  });
4384
4384
 
4385
4385
  // src/security/detect/secrets.ts
4386
+ function nextMatch(pattern, content, from) {
4387
+ pattern.lastIndex = from;
4388
+ return pattern.exec(content);
4389
+ }
4390
+ function isBase64Code(code) {
4391
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47 || code === 61;
4392
+ }
4393
+ function isDigitCode(code) {
4394
+ return code >= 48 && code <= 57;
4395
+ }
4396
+ function isHexCode(code) {
4397
+ return isDigitCode(code) || code >= 65 && code <= 70 || code >= 97 && code <= 102;
4398
+ }
4399
+ function isSeparatorCode(code) {
4400
+ return code === 58 || code === 45;
4401
+ }
4402
+ function isSpaceCode(code) {
4403
+ return code === 32 || code === 9 || code === 13 || code === 11 || code === 12;
4404
+ }
4405
+ function isDiffMarkerCode(code) {
4406
+ return code === 32 || code === 43 || code === 45;
4407
+ }
4408
+ function backslashesBefore(content, index, from) {
4409
+ let count = 0;
4410
+ for (let i = index - 1;i >= from && content.charCodeAt(i) === BACKSLASH; i--)
4411
+ count += 1;
4412
+ return count;
4413
+ }
4414
+ function bodyRunStart(content, end, from) {
4415
+ let run = end;
4416
+ while (run > from) {
4417
+ const last = run - 1;
4418
+ const code = content.charCodeAt(last);
4419
+ if (isHexCode(code) && last - 5 >= from && content.charCodeAt(last - 5) === BACKSLASH && content.charCodeAt(last - 4) === LETTER_U && isHexCode(content.charCodeAt(last - 3)) && isHexCode(content.charCodeAt(last - 2)) && isHexCode(content.charCodeAt(last - 1)) && backslashesBefore(content, last - 5, from) % 2 === 0) {
4420
+ run -= 6;
4421
+ continue;
4422
+ }
4423
+ if (code === BACKSLASH) {
4424
+ const count = backslashesBefore(content, run, from);
4425
+ if (count % 2 === 1)
4426
+ break;
4427
+ run -= count;
4428
+ continue;
4429
+ }
4430
+ if (backslashesBefore(content, last, from) % 2 === 1) {
4431
+ if (!BODY_ESCAPE_LETTERS.has(code))
4432
+ break;
4433
+ run -= 2;
4434
+ continue;
4435
+ }
4436
+ if (!isBase64Code(code))
4437
+ break;
4438
+ run -= 1;
4439
+ }
4440
+ return run;
4441
+ }
4442
+ function prefixShape(text) {
4443
+ let shape = "";
4444
+ let i = 0;
4445
+ while (i < text.length) {
4446
+ const code = text.charCodeAt(i);
4447
+ if (isDigitCode(code)) {
4448
+ let j = i;
4449
+ while (j < text.length && isDigitCode(text.charCodeAt(j)))
4450
+ j += 1;
4451
+ if (j < text.length && isSeparatorCode(text.charCodeAt(j))) {
4452
+ j += 1;
4453
+ for (;; ) {
4454
+ let k = j;
4455
+ while (k < text.length && isDigitCode(text.charCodeAt(k)))
4456
+ k += 1;
4457
+ if (k === j || k === text.length || !isSeparatorCode(text.charCodeAt(k)))
4458
+ break;
4459
+ j = k + 1;
4460
+ }
4461
+ shape += "\x00F";
4462
+ } else {
4463
+ shape += "\x00N";
4464
+ }
4465
+ i = j;
4466
+ } else if (isSpaceCode(code)) {
4467
+ let j = i;
4468
+ while (j < text.length && isSpaceCode(text.charCodeAt(j)))
4469
+ j += 1;
4470
+ if (j === text.length || !isDigitCode(text.charCodeAt(j)))
4471
+ shape += text.slice(i, j);
4472
+ i = j;
4473
+ } else if (isSeparatorCode(code) && (i + 1 === text.length || isDigitCode(text.charCodeAt(i + 1)))) {
4474
+ shape += "\x00S";
4475
+ i += 1;
4476
+ } else {
4477
+ shape += code === 0 ? "\x00\x00" : text.charAt(i);
4478
+ i += 1;
4479
+ }
4480
+ }
4481
+ return shape;
4482
+ }
4483
+ function keyLineOf(line, shape, blankShape) {
4484
+ const text = line.trimEnd();
4485
+ if (text.length === 0)
4486
+ return "blank";
4487
+ let bodyStart = text.length;
4488
+ while (bodyStart > 0 && isBase64Code(text.charCodeAt(bodyStart - 1)))
4489
+ bodyStart -= 1;
4490
+ if (bodyStart < text.length && PEM_BODY.test(text.slice(bodyStart)) && prefixShape(text.slice(0, bodyStart)) === shape)
4491
+ return "body";
4492
+ const header = PEM_HEADER_FIELD.exec(text);
4493
+ if (header !== null && prefixShape(text.slice(0, header.index)) === shape)
4494
+ return "header";
4495
+ return prefixShape(text) === blankShape ? "blank" : undefined;
4496
+ }
4497
+ function diffKeyLineOf(line) {
4498
+ if (line.length > 0 && isDiffMarkerCode(line.charCodeAt(0)))
4499
+ return keyLineOf(line.slice(1), "", "");
4500
+ return line.trimEnd().length === 0 ? "blank" : undefined;
4501
+ }
4502
+ function orphanBodyStart(content, endIndex, from) {
4503
+ const run = bodyRunStart(content, endIndex, from);
4504
+ let lineStart = run;
4505
+ while (lineStart > from && content.charCodeAt(lineStart - 1) !== NEWLINE)
4506
+ lineStart -= 1;
4507
+ const diffLine = endIndex === lineStart + 1 && isDiffMarkerCode(content.charCodeAt(lineStart));
4508
+ const prefix = content.slice(lineStart, run);
4509
+ const shape = prefixShape(prefix);
4510
+ const blankShape = prefixShape(prefix.trimEnd());
4511
+ let start = run;
4512
+ let headerSeen = false;
4513
+ let below = lineStart;
4514
+ while (below > from) {
4515
+ const lineEnd = below - 1;
4516
+ let lineBegin = lineEnd;
4517
+ while (lineBegin > from && content.charCodeAt(lineBegin - 1) !== NEWLINE)
4518
+ lineBegin -= 1;
4519
+ const line = content.slice(lineBegin, lineEnd);
4520
+ const kind = diffLine ? diffKeyLineOf(line) : keyLineOf(line, shape, blankShape);
4521
+ below = lineBegin;
4522
+ if (kind === "blank")
4523
+ continue;
4524
+ if (kind === "header") {
4525
+ headerSeen = true;
4526
+ } else if (kind !== "body" || headerSeen) {
4527
+ break;
4528
+ }
4529
+ start = lineBegin;
4530
+ }
4531
+ return start;
4532
+ }
4386
4533
  function scanPrivateKeyBlocks(content) {
4387
4534
  const spans = [];
4388
- PRIVATE_KEY_BEGIN.lastIndex = 0;
4389
- let begin;
4390
- while ((begin = PRIVATE_KEY_BEGIN.exec(content)) !== null) {
4391
- PRIVATE_KEY_END.lastIndex = begin.index + begin[0].length;
4392
- const end = PRIVATE_KEY_END.exec(content);
4535
+ let from = 0;
4536
+ let begin = nextMatch(PRIVATE_KEY_BEGIN, content, 0);
4537
+ let end = nextMatch(PRIVATE_KEY_END, content, 0);
4538
+ while (begin !== null || end !== null) {
4539
+ if (end !== null && (begin === null || end.index < begin.index)) {
4540
+ const stop = end.index + end[0].length;
4541
+ spans.push([orphanBodyStart(content, end.index, from), stop]);
4542
+ from = stop;
4543
+ end = nextMatch(PRIVATE_KEY_END, content, stop);
4544
+ continue;
4545
+ }
4546
+ if (begin === null)
4547
+ break;
4548
+ const headerEnd = begin.index + begin[0].length;
4549
+ if (end !== null && end.index < headerEnd)
4550
+ end = nextMatch(PRIVATE_KEY_END, content, headerEnd);
4393
4551
  if (end === null) {
4394
4552
  spans.push([begin.index, content.length]);
4395
4553
  break;
4396
4554
  }
4397
4555
  const stop = end.index + end[0].length;
4398
4556
  spans.push([begin.index, stop]);
4399
- PRIVATE_KEY_BEGIN.lastIndex = stop;
4557
+ from = stop;
4558
+ begin = nextMatch(PRIVATE_KEY_BEGIN, content, stop);
4559
+ end = nextMatch(PRIVATE_KEY_END, content, stop);
4400
4560
  }
4401
4561
  return spans;
4402
4562
  }
@@ -4450,10 +4610,13 @@ function valueGroupOf(rule, m) {
4450
4610
  }
4451
4611
  return;
4452
4612
  }
4453
- var PRIVATE_KEY_BEGIN, PRIVATE_KEY_END, ASSIGNED_VALUE, RULES2;
4613
+ var PRIVATE_KEY_BEGIN, PRIVATE_KEY_END, PEM_BODY, PEM_HEADER_FIELD, NEWLINE = 10, BACKSLASH = 92, LETTER_U = 117, BODY_ESCAPE_LETTERS, ASSIGNED_VALUE, RULES2;
4454
4614
  var init_secrets = __esm(() => {
4455
4615
  PRIVATE_KEY_BEGIN = /-----BEGIN (?:[A-Z0-9]{1,16} ){0,3}PRIVATE KEY(?: BLOCK)?-----/g;
4456
4616
  PRIVATE_KEY_END = /-----END (?:[A-Z0-9]{1,16} ){0,3}PRIVATE KEY(?: BLOCK)?-----/g;
4617
+ PEM_BODY = /^=?[A-Za-z0-9+/]+={0,2}$/;
4618
+ PEM_HEADER_FIELD = /(?:Proc-Type|DEK-Info|Content-Domain|Version|Comment|Hash|Charset|MessageID): /;
4619
+ BODY_ESCAPE_LETTERS = new Set([110, 114, 116, 98, 102, 47]);
4457
4620
  ASSIGNED_VALUE = String.raw`(?:"([^"\n]{6,})"|'([^'\n]{6,})'|["']?([^\s"'#]{6,}))`;
4458
4621
  RULES2 = [
4459
4622
  {
@@ -33095,6 +33258,7 @@ function readJsonl(file) {
33095
33258
  ...typeof o.trailStep === "number" && Number.isInteger(o.trailStep) && o.trailStep > 0 ? { trailStep: o.trailStep } : {},
33096
33259
  ...o.packed === true ? { packed: true } : {},
33097
33260
  ...o.slateFrame === true ? { slateFrame: true } : {},
33261
+ ...o.role === "user" && o.terminalContinuation === true ? { terminalContinuation: true } : {},
33098
33262
  ...typeof o.ts === "string" && o.ts.length > 0 ? { ts: o.ts } : {},
33099
33263
  ...reasoning !== undefined ? { reasoning } : {}
33100
33264
  });
@@ -33201,6 +33365,52 @@ function exportSessionMarkdown(cwd, sessionId, dataDir) {
33201
33365
  `);
33202
33366
  }
33203
33367
 
33368
+ // src/session/terminal-note.ts
33369
+ var RUN_ID_BODY = "[A-Za-z0-9_-]{1,64}";
33370
+ var TERMINAL_RUN_ID = new RegExp(`^${RUN_ID_BODY}$`);
33371
+ var HEAD_OPEN = "[terminal run ";
33372
+ var HEAD_RESULT = " result: ";
33373
+ var HEAD_CLOSE = "]";
33374
+ var OUTCOME_RUNNING = "still running";
33375
+ var OUTCOME_SIGNAL = "ended by a signal";
33376
+ var OUTCOME_EXIT = "exit ";
33377
+ function literal(text) {
33378
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
33379
+ }
33380
+ var HEAD_LINE_START = new RegExp(`^${literal(HEAD_OPEN)}(${RUN_ID_BODY})${literal(HEAD_RESULT)}(?:${literal(OUTCOME_EXIT)}(-?\\d+)|(${literal(OUTCOME_SIGNAL)})|(${literal(OUTCOME_RUNNING)}))${literal(HEAD_CLOSE)}`);
33381
+ function outcomeText(outcome) {
33382
+ if (outcome.state === "running")
33383
+ return OUTCOME_RUNNING;
33384
+ return outcome.exitCode === null ? OUTCOME_SIGNAL : `${OUTCOME_EXIT}${outcome.exitCode}`;
33385
+ }
33386
+ function terminalNoteHeadLine(runId, outcome) {
33387
+ return `${HEAD_OPEN}${runId}${HEAD_RESULT}${outcomeText(outcome)}${HEAD_CLOSE}`;
33388
+ }
33389
+ function readTerminalNoteHeadLine(text) {
33390
+ const match = HEAD_LINE_START.exec(text);
33391
+ const runId = match?.[1];
33392
+ if (match === null || runId === undefined)
33393
+ return;
33394
+ const length = match[0].length;
33395
+ if (match[4] !== undefined)
33396
+ return { head: { runId, outcome: { state: "running" } }, length };
33397
+ if (match[3] !== undefined)
33398
+ return { head: { runId, outcome: { state: "exited", exitCode: null } }, length };
33399
+ const exitCode = Number(match[2]);
33400
+ return Number.isSafeInteger(exitCode) ? { head: { runId, outcome: { state: "exited", exitCode } }, length } : undefined;
33401
+ }
33402
+ function parseTerminalNoteHeadLine(line) {
33403
+ const read = readTerminalNoteHeadLine(line);
33404
+ return read !== undefined && read.length === line.length ? read.head : undefined;
33405
+ }
33406
+ function storedTerminalNoteHead(message) {
33407
+ if (message === undefined || message.role !== "user" || message.injected !== true || message.provenance !== "harness")
33408
+ return;
33409
+ const newline = message.content.indexOf(`
33410
+ `);
33411
+ return parseTerminalNoteHeadLine(newline < 0 ? message.content : message.content.slice(0, newline));
33412
+ }
33413
+
33204
33414
  // src/session/compact.ts
33205
33415
  var MIN_PROMPT_CHARS = 500;
33206
33416
  var SUMMARY_HEADER = "[Compacted earlier context";
@@ -33209,6 +33419,9 @@ var FILES_READ_PREFIX = "Files read: ";
33209
33419
  var FILES_MODIFIED_PREFIX = "Files modified: ";
33210
33420
  var TOOLS_RUN_PREFIX = "Tools run: ";
33211
33421
  var MAX_LISTED_FILES = 40;
33422
+ var RUN_RESULTS_HEADER = "Run results removed from the active context (terminal-result notes):";
33423
+ var RUN_RESULT_ITEM = "- ";
33424
+ var MAX_LISTED_RUNS = 24;
33212
33425
  var LEGACY_INJECTED_PREFIXES = [
33213
33426
  "[system] A shell task finished",
33214
33427
  "[system] Messages from other keryx agents"
@@ -33223,6 +33436,39 @@ function isOperatorMessage(m) {
33223
33436
  }
33224
33437
  return !isLegacyInjectedContent(m.content);
33225
33438
  }
33439
+ function isRunResultNote(m) {
33440
+ return storedTerminalNoteHead(m) !== undefined;
33441
+ }
33442
+ function runResultDigest(head) {
33443
+ return terminalNoteHeadLine(head.runId, head.outcome);
33444
+ }
33445
+ function runResultDigests(messages) {
33446
+ const digests = [];
33447
+ for (const m of messages) {
33448
+ const head = storedTerminalNoteHead(m);
33449
+ if (head !== undefined)
33450
+ digests.push(runResultDigest(head));
33451
+ }
33452
+ return digests;
33453
+ }
33454
+ function carriedRunResult(line) {
33455
+ if (!line.startsWith(RUN_RESULT_ITEM))
33456
+ return;
33457
+ const read = readTerminalNoteHeadLine(line.slice(RUN_RESULT_ITEM.length));
33458
+ return read === undefined ? undefined : runResultDigest(read.head);
33459
+ }
33460
+ function runResultsHead(history, turnStart) {
33461
+ for (let i = history.length - 1;i > turnStart; i--) {
33462
+ const m = history[i];
33463
+ if (m?.role === "user" && m.terminalContinuation === true) {
33464
+ let start = i;
33465
+ while (start - 1 > turnStart && isRunResultNote(history[start - 1]))
33466
+ start -= 1;
33467
+ return { start, end: i };
33468
+ }
33469
+ }
33470
+ return;
33471
+ }
33226
33472
  function isLegacyInjectedContent(content) {
33227
33473
  return isAnchorsContent(content) || content.startsWith(SUMMARY_HEADER) || LEGACY_INJECTED_PREFIXES.some((p) => content.startsWith(p));
33228
33474
  }
@@ -33253,7 +33499,9 @@ function parsePreviousSummary(content) {
33253
33499
  const requests = [];
33254
33500
  const read = [];
33255
33501
  const modified = [];
33502
+ const runs = [];
33256
33503
  let inRequests = false;
33504
+ let inRuns = false;
33257
33505
  for (const line of content.split(`
33258
33506
  `)) {
33259
33507
  if (line === REQUESTS_HEADER) {
@@ -33266,13 +33514,23 @@ function parsePreviousSummary(content) {
33266
33514
  inRequests = false;
33267
33515
  }
33268
33516
  }
33517
+ if (line === RUN_RESULTS_HEADER) {
33518
+ inRuns = true;
33519
+ } else if (inRuns) {
33520
+ const run = carriedRunResult(line);
33521
+ if (run !== undefined) {
33522
+ runs.push(run);
33523
+ } else {
33524
+ inRuns = false;
33525
+ }
33526
+ }
33269
33527
  if (line.startsWith(FILES_READ_PREFIX)) {
33270
33528
  read.push(...splitList(line.slice(FILES_READ_PREFIX.length)));
33271
33529
  } else if (line.startsWith(FILES_MODIFIED_PREFIX)) {
33272
33530
  modified.push(...splitList(line.slice(FILES_MODIFIED_PREFIX.length)));
33273
33531
  }
33274
33532
  }
33275
- return { requests, read, modified };
33533
+ return { requests, read, modified, runs };
33276
33534
  }
33277
33535
  function splitList(text) {
33278
33536
  return text.split(", ").map((s) => s.trim()).filter((s) => s.length > 0);
@@ -33347,6 +33605,7 @@ function buildSummary(prefix, opts) {
33347
33605
  const previous = prefix.filter((m) => m.role === "user" && m.content.startsWith(SUMMARY_HEADER)).map((m) => parsePreviousSummary(m.content));
33348
33606
  const operatorRequests = prefix.filter(isOperatorMessage).map((m) => clip(m.content, maxPrompt));
33349
33607
  const requests = [...previous.flatMap((p) => p.requests), ...operatorRequests];
33608
+ const runs = [...previous.flatMap((p) => p.runs), ...runResultDigests(prefix)].slice(-MAX_LISTED_RUNS);
33350
33609
  const files = filesFromToolCalls(prefix);
33351
33610
  const filesRead = uniqueCapped([...previous.flatMap((p) => p.read), ...files.read]);
33352
33611
  const filesModified = uniqueCapped([...previous.flatMap((p) => p.modified), ...files.modified]);
@@ -33366,6 +33625,9 @@ function buildSummary(prefix, opts) {
33366
33625
  REQUESTS_HEADER,
33367
33626
  ...requests.length > 0 ? requests.map((p, i) => `${i + 1}. ${p}`) : ["(none)"]
33368
33627
  ];
33628
+ if (runs.length > 0) {
33629
+ lines.push("", RUN_RESULTS_HEADER, ...runs.map((run) => `${RUN_RESULT_ITEM}${run}`));
33630
+ }
33369
33631
  if (filesRead.length > 0) {
33370
33632
  lines.push("", `${FILES_READ_PREFIX}${filesRead.join(", ")}`);
33371
33633
  }
@@ -33408,6 +33670,24 @@ function toolCallCounts(messages) {
33408
33670
  return [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([name, n]) => `${name} \xD7${n}`);
33409
33671
  }
33410
33672
  var IN_TURN_TAIL_TOKENS = 20000;
33673
+ var IN_TURN_MIN_TAIL_TOKENS = 1000;
33674
+ var messageTokens = (m) => m === undefined ? 0 : estimateMessageTokens(m);
33675
+ function keptRunResultsHead(history, head, tailTokens) {
33676
+ let after = 0;
33677
+ for (let i = head.end + 1;i < history.length; i++)
33678
+ after += messageTokens(history[i]);
33679
+ const share = tailTokens - Math.min(after, Math.floor(tailTokens / 2));
33680
+ let tokens = messageTokens(history[head.end]);
33681
+ let keepFrom = head.end;
33682
+ while (keepFrom > head.start) {
33683
+ const t = messageTokens(history[keepFrom - 1]);
33684
+ if (tokens + t > share)
33685
+ break;
33686
+ tokens += t;
33687
+ keepFrom -= 1;
33688
+ }
33689
+ return { keepFrom, tokens };
33690
+ }
33411
33691
  function compactInTurn(history, opts = {}) {
33412
33692
  const noop = { context: [...history], removed: 0, summaryText: "", noop: true };
33413
33693
  const tailTokens = opts.tailTokens ?? IN_TURN_TAIL_TOKENS;
@@ -33422,11 +33702,19 @@ function compactInTurn(history, opts = {}) {
33422
33702
  if (turnStart < 0) {
33423
33703
  return noop;
33424
33704
  }
33705
+ const head = runResultsHead(history, turnStart);
33706
+ const keptHead = head === undefined ? undefined : { ...head, ...keptRunResultsHead(history, head, tailTokens) };
33707
+ const headTrimmed = keptHead !== undefined && keptHead.keepFrom > keptHead.start;
33425
33708
  let cut = history.length;
33426
- let tokens = 0;
33709
+ let tokens = keptHead?.tokens ?? 0;
33427
33710
  while (cut > turnStart + 1) {
33428
- const m = history[cut - 1];
33429
- const t = m === undefined ? 0 : estimateMessageTokens(m);
33711
+ if (keptHead !== undefined && cut - 1 >= keptHead.start && cut - 1 <= keptHead.end) {
33712
+ cut = keptHead.start;
33713
+ if (headTrimmed)
33714
+ break;
33715
+ continue;
33716
+ }
33717
+ const t = messageTokens(history[cut - 1]);
33430
33718
  if (tokens + t > tailTokens && cut < history.length) {
33431
33719
  break;
33432
33720
  }
@@ -33445,12 +33733,21 @@ function compactInTurn(history, opts = {}) {
33445
33733
  cut -= 1;
33446
33734
  }
33447
33735
  }
33448
- if (cut <= turnStart + 1) {
33736
+ if (cut <= turnStart + 1 && !headTrimmed) {
33449
33737
  return noop;
33450
33738
  }
33451
33739
  const turnMessage = history[turnStart];
33452
- const removed = [...history.slice(0, turnStart), ...history.slice(turnStart + 1, cut)];
33453
- const tail = history.slice(cut);
33740
+ const kept = (i) => {
33741
+ if (keptHead === undefined || i < keptHead.start || i > keptHead.end)
33742
+ return i >= cut;
33743
+ return i >= keptHead.keepFrom;
33744
+ };
33745
+ const removed = [];
33746
+ const tail = [];
33747
+ history.forEach((m, i) => {
33748
+ if (i !== turnStart)
33749
+ (kept(i) ? tail : removed).push(m);
33750
+ });
33454
33751
  const summary = buildSummary(removed, {
33455
33752
  maxPrompt: Math.max(MIN_PROMPT_CHARS, opts.maxPromptChars ?? MIN_PROMPT_CHARS),
33456
33753
  focus: opts.focus?.trim() ?? "",
@@ -33479,8 +33776,7 @@ function compactWithFallback(history, opts = {}) {
33479
33776
  }
33480
33777
  }
33481
33778
  const source = best?.context ?? history;
33482
- const inTurn = compactInTurn(source, {
33483
- ...tailTokens !== undefined ? { tailTokens } : {},
33779
+ const inTurn = inTurnCutThatFits(source, tailTokens ?? IN_TURN_TAIL_TOKENS, fits, {
33484
33780
  ...base.focus !== undefined ? { focus: base.focus } : {},
33485
33781
  ...base.maxPromptChars !== undefined ? { maxPromptChars: base.maxPromptChars } : {}
33486
33782
  });
@@ -33489,6 +33785,24 @@ function compactWithFallback(history, opts = {}) {
33489
33785
  }
33490
33786
  return { ...inTurn, removed: inTurn.removed + (best?.removed ?? 0) };
33491
33787
  }
33788
+ function inTurnCutThatFits(source, tailTokens, fits, opts) {
33789
+ const full = compactInTurn(source, { ...opts, tailTokens });
33790
+ if (fits === undefined || !fits([]) || !full.noop && fits(full.context)) {
33791
+ return full;
33792
+ }
33793
+ let smallest = full.noop ? undefined : full;
33794
+ for (let budget = Math.floor(tailTokens / 2);budget >= IN_TURN_MIN_TAIL_TOKENS; budget = Math.floor(budget / 2)) {
33795
+ const cut = compactInTurn(source, { ...opts, tailTokens: budget });
33796
+ if (cut.noop) {
33797
+ continue;
33798
+ }
33799
+ if (fits(cut.context)) {
33800
+ return cut;
33801
+ }
33802
+ smallest = cut;
33803
+ }
33804
+ return smallest ?? full;
33805
+ }
33492
33806
 
33493
33807
  // src/session/rewrite-gate.ts
33494
33808
  var PRUNE_PROTECT_MAX_TOKENS = 40000;
@@ -37956,6 +38270,8 @@ function sanitizeNudgeToolName(name) {
37956
38270
  function buildRepeatedFailureHint(name, nonce) {
37957
38271
  return wrapHarnessNudge(`tool "${sanitizeNudgeToolName(name)}" is failing repeatedly with the same error ` + `(see that tool's latest result above) \u2014 it is likely unavailable or misconfigured in ` + `this environment. Switch to a different tool or ask the user; do not retry the same call.`, nonce);
37958
38272
  }
38273
+ var CLIENT_RUNS_TERMINAL_RULE = "- In the Keryx desktop, a shell code block in your reply that holds exactly one command gets a Run button. " + "When the user runs it, the command's exit code and output come back to you as an untrusted terminal-result note " + "and your next turn starts by itself. So when you suggest a command for the user to run, put one command per block " + `and end your turn; do not ask the user to paste the output.
38274
+ `;
37959
38275
  function parseToolInput3(raw) {
37960
38276
  const text = raw.trim();
37961
38277
  if (text.length === 0) {
@@ -38544,6 +38860,9 @@ async function runAgentTurnCore(io, deps, history, userLine, options = {}, caugh
38544
38860
  } else if (options.origin === "agent-message") {
38545
38861
  history.push({ role: "user", content: scrub(userLine), provenance: "tool", ts: now() });
38546
38862
  io.onHistoryChange?.("user");
38863
+ } else if (options.origin === "terminal-results") {
38864
+ history.push({ role: "user", content: userLine, provenance: "harness", injected: true, terminalContinuation: true, ts: now() });
38865
+ io.onHistoryChange?.("user");
38547
38866
  } else {
38548
38867
  let effectivePrompt = userLine;
38549
38868
  if (deps.hooks !== undefined && userLine.trim().length > 0) {
@@ -38719,7 +39038,7 @@ ${AUTOMATIC_REVIEW_NOTE}`;
38719
39038
  hashByCallId.delete(id);
38720
39039
  }
38721
39040
  };
38722
- let untrustedContentSeen = options.origin === "agent-message" || options.untrustedPrompt === true || externalReportAtTurnStart;
39041
+ let untrustedContentSeen = options.origin === "agent-message" || options.origin === "terminal-results" || options.untrustedPrompt === true || externalReportAtTurnStart;
38723
39042
  if (deps.tools.some((tool) => tool.definition.name === "ask_user")) {
38724
39043
  rememberArbiterSession({ providerId: deps.providerId, modelId: deps.modelId });
38725
39044
  }
@@ -40495,7 +40814,15 @@ async function executeCallUnbounded(call, toolByName, requestApproval, permissio
40495
40814
  ...confirmationToken !== undefined && confirmationVia !== undefined ? { confirmationVia } : {},
40496
40815
  ...confirmationToken !== undefined && confirmationVia === "remote" && confirmationPressedBy !== undefined ? { confirmationPressedBy } : {},
40497
40816
  ...confirmationToken !== undefined && confirmationVia === "remote" && confirmationPressedAt !== undefined ? { confirmationPressedAt } : {},
40498
- ...untrustedContentSeen ? { untrustedContentSeen: true } : {}
40817
+ ...untrustedContentSeen ? { untrustedContentSeen: true } : {},
40818
+ ...call.name === "spawn_subagent" && requestApproval !== undefined ? { parentGate: {
40819
+ requestApproval,
40820
+ ...permissionMode === undefined ? {} : { permissionMode },
40821
+ ...readOnly === undefined ? {} : { readOnly },
40822
+ ...onAutoApproved === undefined ? {} : { onAutoApproved },
40823
+ ...beforeMutation === undefined ? {} : { beforeMutation },
40824
+ ...busLeases === undefined ? {} : { busLeases }
40825
+ } } : {}
40499
40826
  });
40500
40827
  if (review !== undefined && call.name === "shell_exec" && typeof input.command === "string") {
40501
40828
  review.observe(input.command, result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/keryx",
3
- "version": "0.4.61",
3
+ "version": "0.4.62",
4
4
  "description": "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
5
5
  "private": false,
6
6
  "publishConfig": {