teapot-coding-agent 0.37.109 → 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;
@@ -304,6 +317,7 @@ export class Agent {
304
317
  onIdleUnpark: () => this.unparkFromTool(),
305
318
  hasPendingPrompts: () => this.pendingPrompts.length > 0,
306
319
  onBackgroundExit: (info) => void this.onBackgroundJobExit(info),
320
+ onBackgroundStart: () => this.emitSnapshotUpdate(),
307
321
  onFileRead: (p) => this.trackFileRead(p),
308
322
  };
309
323
  this.mainSession = path.basename(opts.sessionDir);
@@ -475,7 +489,17 @@ export class Agent {
475
489
  trackFileRead(p) {
476
490
  this.recentReads = [p, ...this.recentReads.filter((x) => x !== p)].slice(0, 5);
477
491
  }
492
+ /**
493
+ * Push a fresh snapshot to the UI.
494
+ *
495
+ * `agent-update` is the only carrier of `bgRunning`, and it previously came from session-title writes only.
496
+ * Cheap: the snapshot is what the browser replaces on the other end anyway.
497
+ */
498
+ emitSnapshotUpdate() {
499
+ bus.emit("update", { kind: "agent-update", agentId: this.opts.id });
500
+ }
478
501
  onBackgroundJobExit(info) {
502
+ this.emitSnapshotUpdate();
479
503
  const ok = info.code === 0;
480
504
  const one = info.cmd.replace(/\s+/g, " ").slice(0, 80);
481
505
  void this.log.append("system_note", this.currentSession, this.currentBranch, {
@@ -1403,9 +1427,10 @@ export class Agent {
1403
1427
  continue;
1404
1428
  }
1405
1429
  const isSub = !!this.opts.parent;
1430
+ const anchor = this.timeAnchor();
1406
1431
  const nudge = isSub
1407
- ? `[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().`
1408
- : 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)}`;
1409
1434
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
1410
1435
  source: "harness",
1411
1436
  text: nudge,
@@ -1446,6 +1471,7 @@ export class Agent {
1446
1471
  return;
1447
1472
  }
1448
1473
  }
1474
+ this.lastTurnEndedAt = Date.now();
1449
1475
  if (!this.stopRequested && !this.awaitingUser)
1450
1476
  this.setStatus("idle", "round complete");
1451
1477
  }
@@ -2424,7 +2450,7 @@ export class Agent {
2424
2450
  this.lastProgressAt = Date.now();
2425
2451
  this.activityChars = 0;
2426
2452
  this.turnsSinceProgress = 0;
2427
- const request = PROGRESS_REQUEST;
2453
+ const request = `${this.timeAnchor()}\n${PROGRESS_REQUEST}`;
2428
2454
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
2429
2455
  source: "harness",
2430
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
+ }
@@ -296,6 +296,14 @@ function startBackgroundShell(cmd, ctx) {
296
296
  child.on("exit", (code) => notify(code));
297
297
  child.on("close", (code) => notify(code));
298
298
  map.set(id, sh);
299
+ /**
300
+ * Tell the UI the count changed.
301
+ *
302
+ * The header badge reads `bgRunning` off the agent snapshot, and a snapshot only reaches the browser on an
303
+ * `agent-update` — which nothing emitted when a job started or finished, so the badge was right only after
304
+ * an unrelated update happened to arrive (#197 "クリックしないと値更新されなかった").
305
+ */
306
+ ctx.onBackgroundStart?.(id);
299
307
  return id;
300
308
  }
301
309
  export function isContextOverflow(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.109",
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",