teapot-coding-agent 0.37.110 → 0.37.111

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.
@@ -7,6 +7,7 @@ import { auditPrompt, parseAuditVerdict } from "./goal-audit.js";
7
7
  import { createCatalog } from "./tool-catalog.js";
8
8
  import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShells, hasRunningBgShellsFor, killBgShells, runningBgShellCount } from "./tools.js";
9
9
  import { effortChoosable } from "./llm.js";
10
+ import { turnAnchor } from "./timing.js";
10
11
  import { mcp } from "./mcp-registry.js";
11
12
  import { flattenToolName } from "./mcp-registry.js";
12
13
  import { metaToolSpecs } from "./meta-tools.js";
@@ -237,6 +238,18 @@ export class Agent {
237
238
  pendingSubReport = "";
238
239
  compactPhase = "";
239
240
  awaitingUser = false;
241
+ /** when the previous round finished, for the time anchor in harness messages (#194) */
242
+ lastTurnEndedAt = null;
243
+ /**
244
+ * "21:04 · 1h12m into this session · 3m since the last turn".
245
+ *
246
+ * Attached to harness-generated prompts only: the system prompt is the provider's prefix-cache anchor, so a
247
+ * clock in there would invalidate the cache on every request. Reported as "AIが時間把握するのが極めて下手"
248
+ * — a five minute exploit and a device reboot read exactly like an instant in the transcript.
249
+ */
250
+ timeAnchor() {
251
+ return turnAnchor({ now: Date.now(), startedAt: this.stats.startedAt, lastTurnAt: this.lastTurnEndedAt });
252
+ }
240
253
  activityChars = 0;
241
254
  turnsSinceProgress = 0;
242
255
  consecutiveToolErrors = 0;
@@ -1414,9 +1427,10 @@ export class Agent {
1414
1427
  continue;
1415
1428
  }
1416
1429
  const isSub = !!this.opts.parent;
1430
+ const anchor = this.timeAnchor();
1417
1431
  const nudge = isSub
1418
- ? `[harness] Auto-nudge. Re-anchor on YOUR task — and only that:\n\n${this.goal.text.slice(0, 1500)}\n\nThe inherited conversation is reference only; other agents own any older tasks in it. If your task is complete, call finish() now instead of continuing. If blocked, explain why briefly and finish().`
1419
- : autoContinueNudge(this.goal.text);
1432
+ ? `${anchor}\n[harness] Auto-nudge. Re-anchor on YOUR task — and only that:\n\n${this.goal.text.slice(0, 1500)}\n\nThe inherited conversation is reference only; other agents own any older tasks in it. If your task is complete, call finish() now instead of continuing. If blocked, explain why briefly and finish().`
1433
+ : `${anchor}\n${autoContinueNudge(this.goal.text)}`;
1420
1434
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
1421
1435
  source: "harness",
1422
1436
  text: nudge,
@@ -1457,6 +1471,7 @@ export class Agent {
1457
1471
  return;
1458
1472
  }
1459
1473
  }
1474
+ this.lastTurnEndedAt = Date.now();
1460
1475
  if (!this.stopRequested && !this.awaitingUser)
1461
1476
  this.setStatus("idle", "round complete");
1462
1477
  }
@@ -2435,7 +2450,7 @@ export class Agent {
2435
2450
  this.lastProgressAt = Date.now();
2436
2451
  this.activityChars = 0;
2437
2452
  this.turnsSinceProgress = 0;
2438
- const request = PROGRESS_REQUEST;
2453
+ const request = `${this.timeAnchor()}\n${PROGRESS_REQUEST}`;
2439
2454
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
2440
2455
  source: "harness",
2441
2456
  text: request,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A time anchor for harness-generated messages.
3
+ *
4
+ * Reported as "AIが時間把握するのが極めて下手": a five minute exploit, a device reboot, a progress report — and the
5
+ * model narrating it as if no time had passed. Tool results carry `[took 12.3s]` for the call just made, but
6
+ * nothing tells it what time it is NOW or how long it has been going, so a long wait and an instant are
7
+ * indistinguishable in the transcript.
8
+ *
9
+ * Only harness-injected messages get this. It cannot go in the system prompt: that text is the provider's
10
+ * prefix-cache anchor, and a timestamp there would invalidate the cache on every single request.
11
+ */
12
+ /** "0s" / "45s" / "12m" / "1h12m" / "2d3h" — one unit of resolution, never more than two parts */
13
+ export function shortDuration(ms) {
14
+ const secs = Math.max(0, Math.round(ms / 1000));
15
+ if (secs < 60)
16
+ return `${secs}s`;
17
+ const mins = Math.round(secs / 60);
18
+ if (mins < 60)
19
+ return `${mins}m`;
20
+ const hours = Math.floor(mins / 60);
21
+ const remMins = mins % 60;
22
+ if (hours < 24)
23
+ return remMins ? `${hours}h${remMins}m` : `${hours}h`;
24
+ const days = Math.floor(hours / 24);
25
+ const remHours = hours % 24;
26
+ return remHours ? `${days}d${remHours}h` : `${days}d`;
27
+ }
28
+ /**
29
+ * `[harness] 21:04 · 1h12m into this session · last turn ended 3m ago`
30
+ *
31
+ * `startedAt` is the ISO timestamp of the session's first turn; anything unparseable simply drops that part
32
+ * rather than injecting "NaN" into a prompt.
33
+ */
34
+ export function turnAnchor(args) {
35
+ const clock = new Date(args.now);
36
+ const hh = String(clock.getHours()).padStart(2, "0");
37
+ const mm = String(clock.getMinutes()).padStart(2, "0");
38
+ const parts = [`${hh}:${mm}`];
39
+ const start = args.startedAt ? Date.parse(args.startedAt) : Number.NaN;
40
+ if (Number.isFinite(start) && args.now >= start)
41
+ parts.push(`${shortDuration(args.now - start)} into this session`);
42
+ if (args.lastTurnAt && args.now >= args.lastTurnAt) {
43
+ const gap = args.now - args.lastTurnAt;
44
+ // below a few seconds the gap is noise, not information
45
+ if (gap >= 3_000)
46
+ parts.push(`${shortDuration(gap)} since the last turn`);
47
+ }
48
+ return `[harness] ${parts.join(" · ")}`;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.110",
3
+ "version": "0.37.111",
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",