teapot-coding-agent 0.29.33 → 0.29.35

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.
package/dist/master.js CHANGED
@@ -295,8 +295,11 @@ function isRegularFileTarget(p) {
295
295
  return st.isFile() && !st.isSymbolicLink();
296
296
  }
297
297
  catch {
298
- // does not exist yet — the parent decides; a real config path will be created
299
- return true;
298
+ // Does not exist yet. The ATOMIC path needs a real directory to rename within, so
299
+ // only take it when the parent exists — otherwise a test that passes `/dev/null`
300
+ // (present on POSIX, absent on Windows) tried to create `/dev/.config.json.tmp…`
301
+ // and failed with a bare 400 that read like a schema rejection.
302
+ return existsSync(path.dirname(p));
300
303
  }
301
304
  }
302
305
  export function loadedRaw() {
@@ -367,7 +370,11 @@ function printAgentEvent(e) {
367
370
  else if (d.event === "model-changed")
368
371
  line = `${c("33", "🧦 model")} → ${d.model} (${d.provider})`;
369
372
  else if (d.event === "round-turn-cap")
370
- line = `${c("33", "⏸ round cap")} ${d.turns} turns — nudging report + wrap-up, next round continues`;
373
+ // The code deliberately does NOT nudge the model here (see the note at the
374
+ // emit site): telling it "the round ended, consider finish()" invited premature
375
+ // finishes. The old text claimed a nudge that does not happen, which sends
376
+ // anyone reading the log looking for behaviour that was removed on purpose.
377
+ line = `${c("33", "⏸ round cap")} ${d.turns} turns — round ended, auto-continue starts the next one`;
371
378
  break;
372
379
  }
373
380
  default:
@@ -472,6 +479,19 @@ export class Master {
472
479
  this.raw.providers = this.config.providers;
473
480
  this.raw.defaultProvider = this.config.defaultProvider;
474
481
  this.raw.tasks = this.config.tasks;
482
+ // #67: `raw` is what gets WRITTEN, and it is a hand-maintained mirror of `config`.
483
+ // `mcpServers` was added to the config and to the API but never to this list, so the
484
+ // servers existed in memory and in `GET /api/config` and were STILL lost on restart —
485
+ // a save→reopen appeared to work while the file never carried them.
486
+ //
487
+ // Every field that must survive a restart belongs here. Caught by asserting the FILE
488
+ // contents in test/mcp-config-roundtrip.test.ts, which was impossible while that test
489
+ // wrote to /dev/null.
490
+ this.raw.mcpServers = this.config.mcpServers;
491
+ if (this.config.shortContext !== undefined)
492
+ this.raw.shortContext = this.config.shortContext;
493
+ if (this.config.pluginsDir !== undefined)
494
+ this.raw.pluginsDir = this.config.pluginsDir;
475
495
  if (this.raw.progressIntervalMs === undefined && this.config.progressIntervalMs !== undefined)
476
496
  this.raw.progressIntervalMs = this.config.progressIntervalMs;
477
497
  if (this.raw.progressMinChars === undefined && this.config.progressMinChars !== undefined)
@@ -744,6 +764,10 @@ export class Master {
744
764
  // MCP connect below so a plugin's servers connect in the same pass as configured
745
765
  // ones, and before any agent starts so its skills are discoverable on turn one.
746
766
  if (this.config.mcpServers?.length || this.config.pluginsDir !== false) {
767
+ // OAuth grants live beside the data, not in config.json (a refresh token is a
768
+ // credential, and config.json is the file operators copy around). Must be pointed
769
+ // at the data dir BEFORE any server connects, or a stored grant is invisible.
770
+ mcp.init(this.config.dataDir);
747
771
  const allMcp = await this.loadPluginsAndMcp();
748
772
  if (allMcp.length) {
749
773
  mcp.apply(allMcp);
@@ -1526,6 +1550,13 @@ When this task is done (or truly blocked), call finish() with a summary for @${p
1526
1550
  // above. A chat's timeline is its own.
1527
1551
  }
1528
1552
  /** sessions root + helpers */
1553
+ /**
1554
+ * Where session directories live.
1555
+ *
1556
+ * Public: it is the layout contract every part of the harness depends on, and a test
1557
+ * that plants a directory (a foreign manifest, an impostor owner) needs the same path
1558
+ * the master resolves rather than a re-derivation that can drift from it.
1559
+ */
1529
1560
  sessionsRoot() {
1530
1561
  return path.join(this.config.dataDir, "sessions");
1531
1562
  }
@@ -55,7 +55,6 @@ import { bus } from "../bus.js";
55
55
  import { readEvents, readEventsTail, filterByBranch } from "../log/events.js";
56
56
  import { mcp } from "../agent/mcp-registry.js";
57
57
  import { connectMcp } from "../agent/mcp.js";
58
- import { oauth } from "../agent/mcp-oauth-manager.js";
59
58
  /** media categories the file tree can preview inline */
60
59
  const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "ico", "avif"]);
61
60
  const VIDEO_EXT = new Set(["mp4", "webm", "mov", "mkv", "avi", "m4v"]);
@@ -786,7 +785,13 @@ export function buildApp(master) {
786
785
  contextTokenBudget: master.config.contextTokenBudget,
787
786
  contextWindowTokens: master.config.contextWindowTokens,
788
787
  maxSpawnDepth: master.config.maxSpawnDepth,
788
+ shortContext: master.config.shortContext,
789
789
  tasks: master.config.tasks,
790
+ // #67: the SAVED MCP servers. Without this the settings dialog opened with an
791
+ // empty list, so adding a server, saving, and reopening showed nothing — the save
792
+ // had worked, but nothing ever read it back. Headers are returned as saved: they
793
+ // are ordinary config, and the dialog needs them to round-trip.
794
+ mcpServers: master.config.mcpServers ?? [],
790
795
  agents: master.config.agents.map((a) => ({ id: a.id, workspace: a.workspace, provider: a.provider, model: a.model })),
791
796
  version: master.getVersion(),
792
797
  });
@@ -885,78 +890,46 @@ export function buildApp(master) {
885
890
  * clickable link instead of hanging the request for minutes.
886
891
  */
887
892
  app.post("/api/mcp/oauth/start", async (c) => {
888
- const body = await c.req
889
- .json()
890
- .catch(() => null);
893
+ const body = await c.req.json().catch(() => null);
891
894
  if (!body?.name)
892
895
  return c.json({ error: "missing name" }, 400);
893
896
  const saved = (master.config.mcpServers ?? []).find((m) => m.name === body.name);
894
- const url = body.url ?? saved?.url;
895
- if (!url)
897
+ if (!saved?.url)
896
898
  return c.json({ error: "this server has no url — OAuth needs an http(s) endpoint" }, 400);
897
- // Kick the flow off; it settles when the redirect arrives. The promise is NOT
898
- // awaited here — awaiting it would hold this request open until the operator
899
- // finishes in the browser.
900
- const flow = oauth.authorize(body.name, url, {
901
- ...(body.scopes?.length ? { scopes: body.scopes } : {}),
902
- ...(body.clientId ? { clientId: body.clientId } : {}),
903
- ...(body.clientSecret ? { clientSecret: body.clientSecret } : {}),
904
- });
905
- flow.catch(() => {
906
- /* recorded in oauth.status(...).flow; nobody is listening here */
907
- });
908
- // Wait only long enough for the flow to produce its URL (discovery + registration
909
- // are network round-trips, but short ones).
910
- const deadline = Date.now() + 20_000;
911
- let url_;
912
- while (Date.now() < deadline) {
913
- const st = oauth.status(body.name);
914
- if (st.flow.phase === "authorizing") {
915
- url_ = st.flow.url;
916
- break;
917
- }
918
- if (st.flow.phase === "error")
919
- break;
920
- await new Promise((r) => setTimeout(r, 50));
899
+ try {
900
+ // `startOAuth` drives the SDK's own flow: discovery, dynamic registration, and the
901
+ // PKCE challenge all happen inside `connectMcp`, so this returns as soon as there
902
+ // is a URL to open. The exchange finishes when the browser hits the callback.
903
+ const { url } = await mcp.startOAuth(body.name, {
904
+ ...(body.scopes?.length ? { scopes: body.scopes } : {}),
905
+ });
906
+ const st = mcp.oauthStatus(body.name);
907
+ if (!url && st.authorized)
908
+ // a stored refresh token was still good — nothing for the operator to do
909
+ return c.json({ ok: true, alreadyAuthorized: true });
910
+ if (!url)
911
+ return c.json({ ok: false, error: st.lastError ?? "the authorization server produced no url" });
912
+ return c.json({ ok: true, url });
913
+ }
914
+ catch (err) {
915
+ return c.json({ ok: false, error: err.message });
921
916
  }
922
- const st = oauth.status(body.name);
923
- if (!url_)
924
- return c.json({
925
- ok: false,
926
- error: st.flow.phase === "error"
927
- ? st.flow.message
928
- : "the authorization server did not produce a URL in time",
929
- }, 200);
930
- return c.json({ ok: true, url: url_, redirectUri: "http://127.0.0.1/<port>/callback" });
931
917
  });
932
- app.get("/api/mcp/oauth/status", async (c) => {
918
+ app.get("/api/mcp/oauth/status", (c) => {
933
919
  const name = c.req.query("name");
934
920
  if (!name)
935
921
  return c.json({ error: "missing name" }, 400);
936
- const detect = c.req.query("detect") === "1";
937
- // `detect=1` probes the endpoint for a Bearer challenge. That is the ONLY way the
938
- // panel can learn "this needs a grant" before the operator has guessed it, and it
939
- // is opt-in because the probe is a real request to the server.
940
- if (detect && !oauth.status(name).required) {
941
- const saved = (master.config.mcpServers ?? []).find((m) => m.name === name);
942
- if (saved?.url) {
943
- try {
944
- await oauth.detect(name, saved.url, {
945
- ...(saved.headers ? { headers: saved.headers } : {}),
946
- });
947
- }
948
- catch {
949
- /* best-effort: the status is still returned */
950
- }
951
- }
952
- }
953
- return c.json(oauth.status(name));
922
+ // "needs OAuth" is now discovered by the SDK itself: an unauthorized connect leaves
923
+ // the server in `oauthRequired`, so there is no separate probe endpoint. The panel
924
+ // triggers that by calling `/api/mcp/connect` or by `test`.
925
+ const st = mcp.states().find((s) => s.config.name === name);
926
+ return c.json({ ...mcp.oauthStatus(name), required: Boolean(st?.oauthRequired) });
954
927
  });
955
928
  app.post("/api/mcp/oauth/disconnect", async (c) => {
956
929
  const body = await c.req.json().catch(() => null);
957
930
  if (!body?.name)
958
931
  return c.json({ error: "missing name" }, 400);
959
- await oauth.disconnect(body.name);
932
+ await mcp.disconnect(body.name);
960
933
  return c.json({ ok: true });
961
934
  });
962
935
  app.post("/api/mcp/test", async (c) => {
@@ -964,6 +937,9 @@ export function buildApp(master) {
964
937
  if (!body?.name)
965
938
  return c.json({ error: "a server needs a name" }, 400);
966
939
  try {
940
+ // no OAuth provider here on purpose: `test` answers "is this reachable and what
941
+ // does it expose", which an unauthorized server can still answer with a clear 401.
942
+ // Starting a browser flow from a test button would be a surprise.
967
943
  const conn = await connectMcp({ ...body, enabled: true });
968
944
  try {
969
945
  const tools = await conn.tools();
@@ -977,8 +953,12 @@ export function buildApp(master) {
977
953
  }
978
954
  }
979
955
  catch (err) {
980
- const e = err;
981
- return c.json({ ok: false, error: e.message, authRequired: Boolean(e.authRequired) }, 200);
956
+ const message = err.message;
957
+ // The SDK reports a missing grant as an HTTP error with a `status`. Reading that is
958
+ // reliable; matching the message is not (it is just "Error POSTing to endpoint").
959
+ const status = err.status;
960
+ const needsAuth = status === 401 || status === 403 || /unauthoriz|invalid_token|authorization required/i.test(message);
961
+ return c.json({ ok: false, error: message, needsOAuth: needsAuth }, 200);
982
962
  }
983
963
  });
984
964
  app.post("/api/mcp/connect", async (c) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.29.33",
3
+ "version": "0.29.35",
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",
@@ -35,17 +35,19 @@
35
35
  "build-web": "vite build",
36
36
  "typecheck": "tsc -p tsconfig.json --noEmit",
37
37
  "typecheck-web": "tsc -p tsconfig.frontend.json",
38
+ "typecheck:scripts": "tsc -p tsconfig.scripts.json",
38
39
  "lint": "oxlint src frontend test scripts",
39
40
  "start": "node dist/index.js",
40
41
  "dev": "node src/index.ts",
41
42
  "dev-web": "vite",
42
43
  "test": "node --test test/*.test.ts",
43
- "test:portable": "node scripts/run-portable-tests.mjs",
44
- "test:clean": "node scripts/clean-test-tmp.mjs --apply",
44
+ "test:portable": "node scripts/run-portable-tests.ts",
45
+ "test:clean": "node scripts/clean-test-tmp.ts --apply",
45
46
  "test:tmp": "node scripts/clean-test-tmp.mjs"
46
47
  },
47
48
  "dependencies": {
48
49
  "@hono/node-server": "^2.1.4",
50
+ "@modelcontextprotocol/client": "^2.3.1",
49
51
  "@mozilla/readability": "^0.6.0",
50
52
  "happy-dom": "^20.14.5",
51
53
  "hono": "^4.13.13",