teapot-coding-agent 0.37.123 → 0.37.125

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.
@@ -16,8 +16,7 @@ import { metaToolSpecs } from "./meta-tools.js";
16
16
  import { skillRootsFingerprint, foreignSkillRoots } from "./skills.js";
17
17
  import { extractRules, enforceRules, RULES_HEADING } from "./compact-rules.js";
18
18
  import { bus } from "../bus.js";
19
- export const AUTO_CONTINUE_NUDGE = "[harness] " +
20
- "Continue working toward the current goal. If you are blocked, explain why briefly. " +
19
+ export const AUTO_CONTINUE_NUDGE = "Continue working toward the current goal. If you are blocked, explain why briefly. " +
21
20
  "When the goal is genuinely met — or truly blocked — call finish() " +
22
21
  "(finish(goalComplete=true) when met, finish(goalComplete=false) when blocked) " +
23
22
  "instead of replying in prose; prose here does not stop the loop.";
@@ -27,7 +26,7 @@ export function autoContinueNudge(goalText) {
27
26
  return AUTO_CONTINUE_NUDGE;
28
27
  return `${AUTO_CONTINUE_NUDGE}\nCurrent goal:\n=====\n${goal.slice(0, 1500)}\n=====`;
29
28
  }
30
- export const PROGRESS_REQUEST = "[harness] Please give a brief progress report now: what you are doing, goal progress, " +
29
+ export const PROGRESS_REQUEST = "Please give a brief progress report now: what you are doing, goal progress, " +
31
30
  "what you recently tried, any problems, and your next step. Keep it under 10 lines. " +
32
31
  "Record it with the report_progress TOOL (doing, goalStatus, recent, problems, next) — " +
33
32
  "call that tool; do NOT answer in prose, which would just duplicate this request.";
@@ -284,7 +283,7 @@ export class Agent {
284
283
  const head = where === "finish"
285
284
  ? "That finish() was refused: it gives the context window as the blocker, and the window is not yours to run out of."
286
285
  : "You stopped, giving the context window as the reason.";
287
- return (`${this.timeAnchor()}\n[harness] ${head} The numbers above are MEASURED, compaction is automatic and has ` +
286
+ return (`${this.timeAnchor()}\n${head} The numbers above are MEASURED, compaction is automatic and has ` +
288
287
  `just run — so how much window is left is not something you have to guess, and continuing the same way ` +
289
288
  `would land you here again in a few turns. Change the perspective instead:\n` +
290
289
  `1. Write down what you have LEARNED (add_memory) and what is LEFT (set_todo), so nothing depends on ` +
@@ -296,6 +295,16 @@ export class Agent {
296
295
  `If this is a FALSE POSITIVE (you were quoting the phrase), say so and carry on. finish(goalComplete=false) ` +
297
296
  `only with a blocker that is NOT the context size.`);
298
297
  }
298
+ /**
299
+ * A harness message: the time/usage anchor, then the body with any `[harness]` marker of its own removed.
300
+ *
301
+ * The marker is added HERE, once — the templates no longer carry it. They all used to start with `[harness]`, and
302
+ * so does the anchor line, so every composed message opened with it twice: "auto-continueとコンテキストウィンドウで
303
+ * [harness] が重複する問題". Adding it at construction also means a body written without the marker cannot forget.
304
+ */
305
+ harnessMessage(body) {
306
+ return `${this.timeAnchor()}\n${body.replace(/^\[harness\]\s*/, "")}`;
307
+ }
299
308
  timeAnchor() {
300
309
  const clock = turnAnchor({
301
310
  now: Date.now(),
@@ -716,7 +725,7 @@ export class Agent {
716
725
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
717
726
  event: "unfinished-tools-closed",
718
727
  count: seen.size,
719
- detail: "a restart left these tool calls without a result; they are marked not completed (#54)",
728
+ detail: "a restart left these tool calls without a result; they are marked not completed",
720
729
  });
721
730
  }
722
731
  get goalFile() {
@@ -1438,7 +1447,7 @@ export class Agent {
1438
1447
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
1439
1448
  event: "audit-retry-cap",
1440
1449
  rejects: this.consecutiveAuditRejects,
1441
- detail: "the completion audit rejected the same goal repeatedly ? stopping to avoid an unbounded retry loop (#128)",
1450
+ detail: "the completion audit rejected the same goal repeatedly ? stopping to avoid an unbounded retry loop",
1442
1451
  });
1443
1452
  this.consecutiveAuditRejects = 0;
1444
1453
  break;
@@ -1494,9 +1503,8 @@ export class Agent {
1494
1503
  event: "context-claim-answered",
1495
1504
  attempt: this.contextClaimNudges,
1496
1505
  via: "stop",
1497
- detail: "the agent stopped blaming its remaining capacity — the harness compacted and answered with the measured window plus a fresh-perspective instruction (#201)",
1506
+ detail: "the agent stopped blaming its remaining capacity — answered with the measured window plus a fresh-perspective instruction; auto-compaction handles the window on its own",
1498
1507
  });
1499
- await this.maybeCompact(true);
1500
1508
  const msg = this.contextClaimAnswer("stop");
1501
1509
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
1502
1510
  source: "harness",
@@ -1523,16 +1531,15 @@ export class Agent {
1523
1531
  if (this.progressRequestedThisRound) {
1524
1532
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
1525
1533
  event: "auto-continue-suppressed",
1526
- detail: "a progress report was already requested this round (#95) — the round that carried it already continues the work, so no nudge is added and the loop goes on",
1534
+ detail: "a progress report was already requested this round — the round that carried it already continues the work, so no nudge is added and the loop goes on",
1527
1535
  });
1528
1536
  this.progressRequestedThisRound = false;
1529
1537
  continue;
1530
1538
  }
1531
1539
  const isSub = !!this.opts.parent;
1532
- const anchor = this.timeAnchor();
1533
1540
  const nudge = isSub
1534
- ? `${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().`
1535
- : `${anchor}\n${autoContinueNudge(this.goal.text)}`;
1541
+ ? this.harnessMessage(`[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().`)
1542
+ : this.harnessMessage(autoContinueNudge(this.goal.text));
1536
1543
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
1537
1544
  source: "harness",
1538
1545
  text: nudge,
@@ -1639,9 +1646,8 @@ export class Agent {
1639
1646
  event: "context-claim-answered",
1640
1647
  attempt: this.contextClaimNudges,
1641
1648
  via: "finish",
1642
- detail: "a finish(goalComplete=false) blamed the context window — refused, compacted, and told to continue (#201)",
1649
+ detail: "a finish(goalComplete=false) blamed the context window — refused and told to continue; auto-compaction handles the window on its own",
1643
1650
  });
1644
- await this.maybeCompact(true);
1645
1651
  const msg = this.contextClaimAnswer("finish");
1646
1652
  /**
1647
1653
  * Answer the tool call FIRST — in the log as well as in memory.
@@ -1677,13 +1683,13 @@ export class Agent {
1677
1683
  this.blockerAsks += 1;
1678
1684
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
1679
1685
  event: "finish-without-blocker",
1680
- detail: "finish(goalComplete=false) named no blocker while the harness saw none either — asked for one instead of ending the round (#200)",
1686
+ detail: "finish(goalComplete=false) named no blocker while the harness saw none either — asked for one instead of ending the round",
1681
1687
  });
1682
- const msg = `${this.timeAnchor()}\n[harness] That finish() was refused: its summary names no blocker, and ` +
1688
+ const msg = this.harnessMessage(`[harness] That finish() was refused: its summary names no blocker, and ` +
1683
1689
  `nothing in the harness agrees with one — the context window above is measured, compaction is ` +
1684
1690
  `automatic, and your tools have not been failing.\nContinue the task. If you ARE blocked, name it ` +
1685
1691
  `concretely: what you tried, what exactly failed, and why it cannot be worked around — then ` +
1686
- `finish(goalComplete=false). If the goal is met, that is finish(goalComplete=true), not a stop.`;
1692
+ `finish(goalComplete=false). If the goal is met, that is finish(goalComplete=true), not a stop.`);
1687
1693
  await this.answerMeta(call, "(finish refused: no blocker named — say what actually failed)");
1688
1694
  await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
1689
1695
  this.messages.push({ role: "user", content: msg });
@@ -2501,7 +2507,7 @@ export class Agent {
2501
2507
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
2502
2508
  event: "audit-unavailable-cap",
2503
2509
  attempts: this.auditUnavailableStreak,
2504
- detail: "the completion audit could not produce a verdict repeatedly — stopping so the operator decides (#128)",
2510
+ detail: "the completion audit could not produce a verdict repeatedly — stopping so the operator decides",
2505
2511
  });
2506
2512
  await this.captureRecentTurns();
2507
2513
  return;
@@ -2567,7 +2573,7 @@ export class Agent {
2567
2573
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
2568
2574
  event: "audit-unavailable-cap",
2569
2575
  attempts: this.auditUnavailableStreak,
2570
- detail: "the completion audit could not produce a verdict repeatedly — stopping so the operator decides (#128)",
2576
+ detail: "the completion audit could not produce a verdict repeatedly — stopping so the operator decides",
2571
2577
  });
2572
2578
  await this.captureRecentTurns();
2573
2579
  return;
@@ -2635,7 +2641,7 @@ export class Agent {
2635
2641
  this.lastProgressAt = Date.now();
2636
2642
  this.activityChars = 0;
2637
2643
  this.turnsSinceProgress = 0;
2638
- const request = `${this.timeAnchor()}\n${PROGRESS_REQUEST}`;
2644
+ const request = this.harnessMessage(PROGRESS_REQUEST);
2639
2645
  await this.log.append("prompt", this.currentSession, this.currentBranch, {
2640
2646
  source: "harness",
2641
2647
  text: request,
@@ -176,7 +176,7 @@ export class McpRegistry {
176
176
  }
177
177
  try {
178
178
  const r = await this.servers.get(parts.server).connection.call(parts.tool, args);
179
- return { ok: r.ok, text: r.text };
179
+ return { ok: r.ok, text: r.text, ...(r.images?.length ? { images: r.images } : {}) };
180
180
  }
181
181
  catch (err) {
182
182
  const st = this.servers.get(parts.server);
package/dist/agent/mcp.js CHANGED
@@ -11,15 +11,46 @@ async function mcpSdk() {
11
11
  }
12
12
  return sdkPromise;
13
13
  }
14
- function resultText(result) {
14
+ export function resultText(result) {
15
15
  const parts = [];
16
+ const images = [];
17
+ let extraImages = 0;
18
+ const bytes = (b64) => Math.round((b64.length * 3) / 4);
16
19
  for (const c of result?.content ?? []) {
17
- if (c?.type === "text" && typeof c.text === "string")
20
+ if (!c)
21
+ continue;
22
+ if (c.type === "text" && typeof c.text === "string") {
18
23
  parts.push(c.text);
19
- else if (c?.type)
20
- parts.push(`[${c.type} content omitted]`);
24
+ }
25
+ else if (c.type === "image" && typeof c.data === "string" && c.data) {
26
+ const mime = c.mimeType || "image/png";
27
+ const name = `mcp-image-${images.length + 1}.${mime.split("/")[1] ?? "png"}`;
28
+ if (images.length === 0)
29
+ images.push({ url: `data:${mime};base64,${c.data}`, name });
30
+ else
31
+ extraImages++;
32
+ parts.push(`[image: ${mime}, ${Math.round(bytes(c.data) / 1024)}KB]`);
33
+ }
34
+ else if (c.type === "resource" && c.resource) {
35
+ const r = c.resource;
36
+ if (typeof r.text === "string")
37
+ parts.push(r.text);
38
+ else if (typeof r.blob === "string") {
39
+ parts.push(`[resource ${r.mimeType || "unknown"} · ${r.uri || "embedded"} · ${Math.round(bytes(r.blob) / 1024)}KB]`);
40
+ }
41
+ else
42
+ parts.push(`[resource ${r.uri || "embedded"}]`);
43
+ }
44
+ else if (c.type === "audio" && typeof c.data === "string") {
45
+ parts.push(`[audio: ${c.mimeType || "unknown"}, ${Math.round(bytes(c.data) / 1024)}KB — not readable by the model]`);
46
+ }
47
+ else if (c.type) {
48
+ parts.push(`[${c.type} content: ${Math.round(bytes(String(c.data ?? "")) / 1024)}KB]`);
49
+ }
21
50
  }
22
- return { text: parts.join("\n") || "(no content)", ok: result?.isError !== true };
51
+ if (extraImages > 0)
52
+ parts.push(`(+${extraImages} more image(s) shown as metadata — only the first is attached)`);
53
+ return { text: parts.join("\n") || "(no content)", ok: result?.isError !== true, images };
23
54
  }
24
55
  function toTools(list, server) {
25
56
  const out = [];
@@ -45,5 +45,9 @@ export function turnAnchor(args) {
45
45
  if (gap >= 3_000)
46
46
  parts.push(`${shortDuration(gap)} since the last turn`);
47
47
  }
48
- return `[harness] ${parts.join(" · ")}`;
48
+ /**
49
+ * `now 21:09` rather than a bare `21:09` — reported as "21:09 がいきなり出されても意味不明". A timestamp with no
50
+ * label is a number in a sentence; the label is three characters.
51
+ */
52
+ return `[harness] now ${parts.join(" · ")}`;
49
53
  }
@@ -2297,7 +2297,8 @@ export async function executeTool(name, rawArgs, ctx) {
2297
2297
  const r = await mcp.call(flattenToolName(entry.serverId, entry.name), callArgs);
2298
2298
  if (!r)
2299
2299
  return { ok: false, result: `unknown tool: ${entry.name}` };
2300
- return { ok: r.ok, result: r.text };
2300
+ // an MCP server may answer with an image; carry the first one the same way `read_file` does (#203)
2301
+ return { ok: r.ok, result: r.text, ...(r.images?.[0] ? { image: r.images[0] } : {}) };
2301
2302
  }
2302
2303
  if (name.startsWith(MCP_PREFIX)) {
2303
2304
  if (ctx.signal?.aborted)
@@ -2312,7 +2313,7 @@ export async function executeTool(name, rawArgs, ctx) {
2312
2313
  const r = await mcp.call(name, args);
2313
2314
  if (!r)
2314
2315
  return { ok: false, result: `unknown tool: ${name}` };
2315
- return { ok: r.ok, result: r.text };
2316
+ return { ok: r.ok, result: r.text, ...(r.images?.[0] ? { image: r.images[0] } : {}) };
2316
2317
  }
2317
2318
  const def = TOOLS.find((t) => t.name === name);
2318
2319
  if (!def)
@@ -875,6 +875,26 @@ export function buildApp(master) {
875
875
  a.start("prompt");
876
876
  return c.json({ ok: true, promptId, queued: a.snapshot().pendingPrompts });
877
877
  });
878
+ /**
879
+ * Force-load and follow a skill.
880
+ *
881
+ * The wording lives HERE, not in the browser: it is a harness message, and the frontend used to compose it and
882
+ * post it with `source: "harness"` — which put harness-authored text in the UI and let the client claim the
883
+ * harness role. The goal notification two hundred lines down already worked this way; this is the same shape.
884
+ */
885
+ app.post("/api/agents/:id/skill", async (c) => {
886
+ const a = master.agents.get(c.req.param("id"));
887
+ if (!a)
888
+ return notFound(c, "agent", c.req.param("id"));
889
+ const body = await c.req.json().catch(() => null);
890
+ const name = String(body?.name ?? "").trim();
891
+ if (!name)
892
+ return c.json({ error: "name required" }, 400);
893
+ const promptId = a.enqueuePrompt(`[harness] Force-load and follow the skill "${name}" now: call load_skill("${name}") and execute its playbook for the current task.`, "harness");
894
+ if (a.status !== "running")
895
+ a.start("skill");
896
+ return c.json({ ok: true, promptId });
897
+ });
878
898
  app.post("/api/agents/:id/prompt/cancel", async (c) => {
879
899
  const a = master.agents.get(c.req.param("id"));
880
900
  if (!a)
@@ -1,5 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
- import { existsSync } from "node:fs";
2
+ import { existsSync, readFileSync, readlinkSync } from "node:fs";
3
3
  import { toolShellFor } from "../agent/tools.js";
4
4
  export function terminalShellFor(platform, env, exists = existsSync) {
5
5
  return toolShellFor(platform, env, exists).file;
@@ -46,6 +46,7 @@ export function createTerminal(agentId, workspace, title) {
46
46
  const id = `t${++seq}-${Date.now().toString(36)}`;
47
47
  const t = {
48
48
  id,
49
+ workspace,
49
50
  agentId,
50
51
  title: title?.trim().slice(0, 60) || `shell ${live.length + 1}`,
51
52
  child,
@@ -86,11 +87,35 @@ export function createTerminal(agentId, workspace, title) {
86
87
  console.log(`[teapot] ⌨ terminal open: ${id} ${agentId} @ ${workspace} (${hasScript ? "pty" : "pipe"})`);
87
88
  return { ok: true, terminal: infoOf(t) };
88
89
  }
90
+ /**
91
+ * The shell's current directory, for the tab label.
92
+ *
93
+ * The pty is spawned through `script`, so `t.child.pid` is script's — the SHELL is its child, and it is the shell
94
+ * whose cwd moves when the operator `cd`s. Reading `/proc/<pid>/cwd` is Linux-only and deliberately falls back to
95
+ * the workspace: a wrong label is worse than a generic one, and this must never throw.
96
+ */
97
+ function shellCwd(t) {
98
+ try {
99
+ const kids = readFileSync(`/proc/${t.child.pid}/task/${t.child.pid}/children`, "utf8").trim().split(/\s+/);
100
+ for (const pid of kids) {
101
+ if (!pid)
102
+ continue;
103
+ const cwd = readlinkSync(`/proc/${pid}/cwd`);
104
+ if (cwd)
105
+ return cwd;
106
+ }
107
+ }
108
+ catch {
109
+ /* not Linux, or the process is gone */
110
+ }
111
+ return t.workspace;
112
+ }
89
113
  function infoOf(t) {
90
114
  return {
91
115
  id: t.id,
92
116
  agentId: t.agentId,
93
117
  title: t.title,
118
+ cwd: shellCwd(t),
94
119
  clients: sinks.get(t.id)?.size ?? 0,
95
120
  createdAt: t.createdAt,
96
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.123",
3
+ "version": "0.37.125",
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",
@@ -46,7 +46,8 @@
46
46
  "test:portable": "node scripts/run-portable-tests.ts",
47
47
  "test:clean": "node scripts/clean-test-tmp.ts --apply",
48
48
  "test:tmp": "node scripts/clean-test-tmp.ts",
49
- "release:wait": "node scripts/wait-npm-version.ts"
49
+ "release:wait": "node scripts/wait-npm-version.ts",
50
+ "pre-release": "pnpm typecheck && pnpm typecheck-web && pnpm typecheck:scripts && pnpm lint && pnpm build && pnpm test && pnpm test:portable && node scripts/smoke-web.ts"
50
51
  },
51
52
  "dependencies": {
52
53
  "@hono/node-server": "^2.1.4",