Public: anyone can read this; the crew can change it.

An admin's Talk sees cloud forges and what they cost (#16580) #16581

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

fix/talk-cloud → main 0 commits 1 thread · 1 unresolved

  • Merged. fix/talk-cloud was merged into main as fa82179.

Review

Sign in to review this change.
7 files changed +52 −9
src/cloud/overview.ts +13 −1
@@ -13,7 +13,8 @@ import type { User } from "../core/users.ts";
1313 import { err, ok, type Result } from "../kernel/result.ts";
1414 import { usedFor, type VendorUse } from "./declared.ts";
1515 import { watchLine } from "./watch.ts";
16 import { spendOf } from "./ceiling.ts";
16 import { priced, rowCents, spendOf } from "./ceiling.ts";
17 import { listPinned } from "../core/pinned.ts";
1718 import { warmOf, type WarmPlace } from "./warm_pool.ts";
1819 import { VENDOR_OF, type Provider } from "./providers.ts";
1920
@@ -40,6 +41,12 @@ export interface AccountRow {
4041 readonly warm: WarmPlace[];
4142 /** When the hourly watch last looked at the provider and what it found (`watch.ts`). */
4243 readonly watch: string;
44 /**
45 * The pinned forges this account holds, each with its state, whether its buyer claimed it and
46 * what it costs a month (`rowCents`: a retired one only the volume it kept): so "what is running
47 * in the cloud and what does it cost" is answered by this one read (#16580).
48 */
49 readonly forges: readonly { readonly name: string; readonly state: string; readonly claimed: boolean; readonly monthlyCents: number }[];
4350 }
4451
4552 export interface CloudOverview {
@@ -56,6 +63,8 @@ export function cloudOverview(
5663 if (actor?.isAdmin !== true) return err("not_found");
5764 const today = auditToday(app.db);
5865 const reads = recentCloudReads(app.db);
66 const pinned = listPinned(app.db);
67 const prices = priced(app.db);
5968 const accounts = listCloudAccounts(app.db).map((a) => ({
6069 provider: a.provider,
6170 name: a.name,
@@ -68,6 +77,9 @@ export function cloudOverview(
6877 ...spendOf(app.db, a.provider, a.name),
6978 warm: warmOf(app.db, a.provider, a.name),
7079 watch: watchLine(app.db, a.provider, a.name),
80 forges: pinned
81 .filter((p) => p.target === a.provider && p.account === a.name)
82 .map((p) => ({ name: p.name, state: p.state, claimed: p.claimedAt !== "", monthlyCents: rowCents(p, prices) })),
7183 }));
7284 return ok({ accounts, today });
7385 }
src/http/mcp/catalog.ts +12 −4
@@ -53,11 +53,19 @@ export const TALK_TOOLS: readonly string[] = [
5353 ];
5454
5555 /**
56 * What Talk's agent is also listed when the person is a forge admin: the machine's history
57 * (`telemetry_history`, a read; `brief` charts it). An everyday account's agent is not listed it,
58 * since the tool would only refuse them.
56 * What Talk's agent is also listed when the person is a forge admin (#16580): the machine's history
57 * (`telemetry_history`, a read; `brief` charts it) and the cloud (`cloud_accounts`, a read: each
58 * account, what the forge reckons it costs a month, and the pinned forges it holds with their state,
59 * claim and cost), so "what is running in the cloud and what does it cost" is answered from the
60 * forge's own rows. `pinned_forge` and `forges` (deploy, retire, archive) are not listed: their
61 * schemas would take the list past its ceiling (`test/mcp-talk-tools.test.ts`), and their changes
62 * belong to the Pinned forges and Forges pages, where retiring with data asks for the forge's
63 * name. And the experiments the spend buys (`experiments`: each question, its machines, what it
64 * costs a month and has spent, its result, and the machines that answer none; never held, since no
outdated

Remove this TODO. A note left as future work is not shippable; file an issue for the experiment read and link it from the pull.

65 * action touches a machine). An everyday account's agent is not listed them, since each would
66 * only refuse them.
5967 */
60 export const TALK_ADMIN_TOOLS: readonly string[] = ["telemetry_history"];
68 export const TALK_ADMIN_TOOLS: readonly string[] = ["telemetry_history", "cloud_accounts", "experiments"];
6169
6270 /**
6371 * Whether Talk's agent is listed this tool for this person: the only tools its harness can call,
src/http/mcp/tools/cloud_accounts.ts +2 −2
@@ -5,9 +5,9 @@ import { good, bad, type Tool } from "../shared.ts";
55 export const tool: Tool = {
66 name: "cloud_accounts",
77 listedTo: "admin",
8 doc: "the forge's cloud accounts, each attached provider token with its use, verification, write permission and today's calls; a forge admin only (counted as a write so a `ro` token never lists them)",
8 doc: "each cloud account: its token's use, verification, write permission, today's calls, monthly cost and pinned forges (state, claimed, cost); admin only (a write, so a `ro` token never lists them)",
99 description:
10 "Cloud accounts (admin): each token's use.",
10 "Cloud accounts and costs (admin).",
1111 inputSchema: { type: "object", properties: {} },
1212 // A read, but marked a write so a `ro` token never lists the accounts; it
1313 // is a forge admin's and the audit rows name every vendor call.
src/http/mcp/tools/pulls.ts +1 −1
@@ -17,7 +17,7 @@ export const tool: Tool = {
1717 name: "pulls",
1818 doc: "`{ repo?, state?, limit?, cursor? }`: without `repo`, every open pull you may read, oldest first, as `{ pulls, next_cursor }` (limit 1-200, default 50): `repo`, `number`, `title`, `author`, `yours`, `youMayReview`, `check`, `verdict` (approved, changes_requested or none) and `gate` (what holds it, or null); with `repo`, its pulls, newest first, one line each: `number`, `title`, `author` (a mirrored pull's: its login `on` the origin's host), `yours` (the asker wrote it), `youMayReview` (a writer where it lands, not its author), `head`, `check` (state), `approvals`, `movedSinceApproval` (approved, then the head or base moved), `changesRequested`, `mergeable` (null once closed), `waitsFor` (`pull`'s `line`, or null); `state` open (default) or closed, `limit` 1-50 (default 20). `{ repo, brief: true, days? }` (1-90, default 14): pulls merged each UTC day, `{ repo, days: [YYYY-MM-DD], merged: [n] }`, oldest first, to chart shipping; without `repo`: what shipped where you may read, `{ since, days, merged, repos: [{ repo, merged }] (top 10), others }`",
1919 description:
20 "A repo's pulls, newest first; no `repo`: all open ones you may read, oldest first; `brief`, no `repo`: merged per repo.",
20 "A repo's pulls, newest first; no `repo`: every open one you may read, oldest first; `brief`: merged per repo.",
2121 inputSchema: {
2222 type: "object",
2323 properties: {
src/http/mcp/tools/telemetry_history.ts +1 −1
@@ -7,7 +7,7 @@ import { good, bad, type Tool } from "../shared.ts";
77 export const tool: Tool = {
88 name: "telemetry_history",
99 doc: "`{ hours? }` (1–72, default 6): the node's and the forge's CPU cores, memory and load over the window, `{ hours, points: [{ target, at, cpuCores, cpuCoresMax (the bucket's peak), memoryBytes, load }] }`, at most 300 points a series (15-s samples to 24 h, 5-min beyond, averaged down); a forge admin or `telemetry:read`, as `system`; the machine records no disk history. `brief: true`: one value an hour to chart from, `{ hours, at: [YYYY-MM-DDTHH], node, forge }`, each `{ cpuCores, memoryGiB, load }` as arrays, a few hundred bytes a day",
10 description: "Machine CPU, memory, load over `hours` (1–72, default 6); brief: hourly series.",
10 description: "CPU, memory, load over `hours` (1–72); brief: hourly.",
1111 inputSchema: {
1212 type: "object",
1313 properties: { hours: { type: "integer", minimum: 1, maximum: 72 }, brief: { type: "boolean" } },
test/mcp-talk-tools.test.ts +16
@@ -15,6 +15,7 @@ import {
1515 createConversation,
1616 listTurns,
1717 } from "../src/core/conversations.ts";
18 import { beginExperiment } from "../src/cloud/experiments.ts";
1819 import { createIssue } from "../src/core/issues.ts";
1920 import { createToken } from "../src/core/tokens.ts";
2021 import { createUser, type User } from "../src/core/users.ts";
@@ -185,6 +186,21 @@ describe("the Talk list", () => {
185186 const forMember = await find(bob);
186187 expect(forMember).not.toContain("telemetry_history");
187188 for (const n of forMember) expect(member.names).toContain(n);
189 // The cloud and what it costs is the admin's agent's to read, at once (no confirm); not a member's.
190 const cloud = async (u: User) => (await post(via(u, "what is running in the cloud and what does it cost?").token, "tools/call", { name: "cloud_accounts", arguments: {} })).result!;
191 const seen = (await cloud(alice))["content"] as { text: string }[];
192 expect(seen[0]!.text).toContain("\"accounts\"");
193 expect(seen[0]!.text).not.toContain("needs_confirm");
194 expect(JSON.stringify(await cloud(bob))).toContain("no such tool here");
195 // "What experiments are running, what do they cost, what's idle" is one call, run at once.
196 const begun = beginExperiment(app, alice.id, "Does a warm pool cut a first boot under a minute?", []);
197 expect(begun.ok).toBe(true);
198 const asked = "what experiments are running, what do they cost, and what's idle?";
199 const answer = (await post(via(alice, asked).token, "tools/call", { name: "experiments", arguments: { action: "list" } })).result!;
200 const said = (answer["content"] as { text: string }[])[0]!.text;
201 expect(said).not.toContain("needs_confirm");
202 for (const key of ['"items"', '"idle"', '"monthlyCents"', "warm pool cut a first boot"]) expect(said).toContain(key);
203 expect(JSON.stringify((await post(via(bob, asked).token, "tools/call", { name: "experiments", arguments: { action: "list" } })).result)).toContain("no such tool here");
188204 // A plain token still finds every tool it may call, Talk's rule aside.
189205 const r = (await post(plain(alice, "admin"), "tools/call", { name: "find_tool", arguments: { query: "cpu memory" } })).result!;
190206 expect((r["content"] as { text: string }[])[0]!.text).toContain("\"system\"");
test/pinned-ceiling.test.ts +7
@@ -122,6 +122,13 @@ describe("cloud account ceiling", () => {
122122 for (const n of ["one", "two", "three"]) expect((await deployPinned(app, admin(), input(n))).ok).toBe(true);
123123 const o = cloudOverview(app, admin());
124124 expect(o.ok && o.value.accounts.find((a) => a.provider === "digitalocean")).toMatchObject({ monthlyCents: 3900, leftCents: 1100 });
125 // Each account names the forges it holds and what each costs, so one read says what runs in
126 // the cloud and what it costs (Talk's cloud question, #16580); they add up to the account's figure.
127 const forges = o.ok ? o.value.accounts.find((a) => a.provider === "digitalocean")!.forges : [];
128 expect(forges.map((f) => f.name).sort()).toEqual(["one", "three", "two"]);
129 for (const f of forges) expect(f).toMatchObject({ claimed: false, monthlyCents: 1300 });
130 expect(forges.reduce((n, f) => n + f.monthlyCents, 0)).toBe(3900);
131 expect(o.ok && o.value.accounts.find((a) => a.provider === "hetzner")?.forges).toEqual([]);
125132 });
126133
127134 test("the deploy that would cross the ceiling is refused before any provider call", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs