teapot-coding-agent 0.37.196 → 0.37.197

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.
@@ -1047,14 +1047,32 @@ export class Agent {
1047
1047
  * Coalescing is the right shape because the requests are IDENTICAL — nothing is lost by answering "already running".
1048
1048
  */
1049
1049
  compactInFlight = null;
1050
+ /**
1051
+ * "A compaction has been ASKED for", as a flag — not a queued job.
1052
+ *
1053
+ * `/compact` used to enqueue an item on the same chain as the agent's turns, so its effect landed at an arbitrary later
1054
+ * point with nothing recording that a compaction was pending: a second `/compact` reported "did not run", the operator
1055
+ * could not tell a manual compaction from an automatic one in the log, and a request issued while a turn was still
1056
+ * streaming could be reported as fired when nothing had compacted. One boolean, consumed at the next turn boundary.
1057
+ */
1058
+ compactRequested = false;
1050
1059
  async compactNow() {
1051
- if (this.compactInFlight)
1052
- return { ran: false };
1060
+ if (this.compactInFlight || this.compactRequested)
1061
+ return { ran: false, queued: true };
1062
+ if (this.status === "running" || this.parkedByTool) {
1063
+ this.compactRequested = true;
1064
+ await this.log.append("prompt", this.currentSession, this.currentBranch, {
1065
+ source: "harness",
1066
+ text: "[compact] a compaction was requested; it runs at the next turn boundary",
1067
+ hidden: true,
1068
+ });
1069
+ return { ran: false, queued: true };
1070
+ }
1053
1071
  this.compactInFlight = this.enqueue(async () => {
1054
1072
  await this.ensureReady();
1055
1073
  const before = this.stats.compactions;
1056
1074
  await this.maybeCompact(true);
1057
- return { ran: this.stats.compactions > before };
1075
+ return { ran: this.stats.compactions > before, queued: false };
1058
1076
  });
1059
1077
  try {
1060
1078
  return await this.compactInFlight;
@@ -2421,7 +2439,13 @@ export class Agent {
2421
2439
  await this.refreshSkills();
2422
2440
  this.progressRequestedThisRound = false;
2423
2441
  await this.maybeRequestProgress();
2424
- await this.maybeCompact();
2442
+ if (this.compactRequested) {
2443
+ this.compactRequested = false;
2444
+ await this.maybeCompact(true);
2445
+ }
2446
+ else {
2447
+ await this.maybeCompact();
2448
+ }
2425
2449
  await this.log.append("state", this.currentSession, this.currentBranch, {
2426
2450
  from: this.status,
2427
2451
  to: this.status,
@@ -3316,8 +3340,28 @@ export class Agent {
3316
3340
  }
3317
3341
  if (!force && this.consecutiveCompactFailures >= MAX_AUTO_COMPACT_FAILURES)
3318
3342
  return;
3319
- if (force && this.messages.length <= this.compactedAtLen)
3343
+ /**
3344
+ * A compaction needs a couple of turns of new material before it can be worth running again.
3345
+ *
3346
+ * The token estimate is rebuilt from the log right after a compaction (`lastUsage` is dropped), and re-estimating a
3347
+ * freshly-compacted history can still land over the budget — so the next two turns each compacted again, reported as
3348
+ * "その数ターン後にcompactされて、更にその数ターン後にまたcompactされた". Growth, not the clock, is the gate.
3349
+ */
3350
+ if (!force && this.messages.length <= this.compactedAtLen + 2)
3351
+ return;
3352
+ if (force && this.messages.length <= this.compactedAtLen) {
3353
+ /**
3354
+ * A requested compaction with nothing new to compact says so.
3355
+ *
3356
+ * Silently returning is what made `/compact` look broken ("`/compact` して、何も変化がなくて"): the request WAS honoured,
3357
+ * the history was already compacted at this size.
3358
+ */
3359
+ await this.log.append("system_note", this.currentSession, this.currentBranch, {
3360
+ event: "compact-nothing-new",
3361
+ detail: "the history has not grown since the last compaction, so there is nothing to compact",
3362
+ });
3320
3363
  return;
3364
+ }
3321
3365
  this.lastUsage = undefined;
3322
3366
  const keepTokens = keepFraction !== undefined
3323
3367
  ? Math.max(1, Math.floor(this.opts.contextTokenBudget * keepFraction))
@@ -3521,6 +3565,8 @@ export class Agent {
3521
3565
  });
3522
3566
  }
3523
3567
  await this.log.append("compaction", this.currentSession, this.currentBranch, {
3568
+ // which asked for it — the log could not tell a manual compaction from an automatic one
3569
+ trigger: force ? "forced" : "auto",
3524
3570
  tokensBefore: before,
3525
3571
  tokensAfter: after,
3526
3572
  summarized: summarizedCount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.196",
3
+ "version": "0.37.197",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",