Public: anyone can read this; the crew can change it.
An admin's Talk sees cloud forges and what they cost (#16580) #16581
Check · Review · Land · Live done — Landed and live in production.
fix/talk-cloud → main 0 commits 1 thread · 1 unresolved
7 files
changed +52
−9
src/cloud/overview.ts +13 −1
| @@ -13,7 +13,8 @@ import type { User } from "../core/users.ts"; | ||
| 13 | 13 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 14 | 14 | import { usedFor, type VendorUse } from "./declared.ts"; |
| 15 | 15 | 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"; | |
| 17 | 18 | import { warmOf, type WarmPlace } from "./warm_pool.ts"; |
| 18 | 19 | import { VENDOR_OF, type Provider } from "./providers.ts"; |
| 19 | 20 | |
| @@ -40,6 +41,12 @@ export interface AccountRow { | ||
| 40 | 41 | readonly warm: WarmPlace[]; |
| 41 | 42 | /** When the hourly watch last looked at the provider and what it found (`watch.ts`). */ |
| 42 | 43 | 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 }[]; | |
| 43 | 50 | } |
| 44 | 51 | |
| 45 | 52 | export interface CloudOverview { |
| @@ -56,6 +63,8 @@ export function cloudOverview( | ||
| 56 | 63 | if (actor?.isAdmin !== true) return err("not_found"); |
| 57 | 64 | const today = auditToday(app.db); |
| 58 | 65 | const reads = recentCloudReads(app.db); |
| 66 | const pinned = listPinned(app.db); | |
| 67 | const prices = priced(app.db); | |
| 59 | 68 | const accounts = listCloudAccounts(app.db).map((a) => ({ |
| 60 | 69 | provider: a.provider, |
| 61 | 70 | name: a.name, |
| @@ -68,6 +77,9 @@ export function cloudOverview( | ||
| 68 | 77 | ...spendOf(app.db, a.provider, a.name), |
| 69 | 78 | warm: warmOf(app.db, a.provider, a.name), |
| 70 | 79 | 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) })), | |
| 71 | 83 | })); |
| 72 | 84 | return ok({ accounts, today }); |
| 73 | 85 | } |
src/http/mcp/catalog.ts +12 −4
| @@ -53,11 +53,19 @@ export const TALK_TOOLS: readonly string[] = [ | ||
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | 55 | /** |
| 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 | |
| 65 | * action touches a machine). An everyday account's agent is not listed them, since each would | |
| 66 | * only refuse them. | |
| 59 | 67 | */ |
| 60 | export const TALK_ADMIN_TOOLS: readonly string[] = ["telemetry_history"]; | |
| 68 | export const TALK_ADMIN_TOOLS: readonly string[] = ["telemetry_history", "cloud_accounts", "experiments"]; | |
| 61 | 69 | |
| 62 | 70 | /** |
| 63 | 71 | * 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"; | ||
| 5 | 5 | export const tool: Tool = { |
| 6 | 6 | name: "cloud_accounts", |
| 7 | 7 | 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)", | |
| 9 | 9 | description: |
| 10 | "Cloud accounts (admin): each token's use.", | |
| 10 | "Cloud accounts and costs (admin).", | |
| 11 | 11 | inputSchema: { type: "object", properties: {} }, |
| 12 | 12 | // A read, but marked a write so a `ro` token never lists the accounts; it |
| 13 | 13 | // 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 = { | ||
| 17 | 17 | name: "pulls", |
| 18 | 18 | 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 }`", |
| 19 | 19 | 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.", | |
| 21 | 21 | inputSchema: { |
| 22 | 22 | type: "object", |
| 23 | 23 | properties: { |
src/http/mcp/tools/telemetry_history.ts +1 −1
| @@ -7,7 +7,7 @@ import { good, bad, type Tool } from "../shared.ts"; | ||
| 7 | 7 | export const tool: Tool = { |
| 8 | 8 | name: "telemetry_history", |
| 9 | 9 | 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.", | |
| 11 | 11 | inputSchema: { |
| 12 | 12 | type: "object", |
| 13 | 13 | properties: { hours: { type: "integer", minimum: 1, maximum: 72 }, brief: { type: "boolean" } }, |
test/mcp-talk-tools.test.ts +16
| @@ -15,6 +15,7 @@ import { | ||
| 15 | 15 | createConversation, |
| 16 | 16 | listTurns, |
| 17 | 17 | } from "../src/core/conversations.ts"; |
| 18 | import { beginExperiment } from "../src/cloud/experiments.ts"; | |
| 18 | 19 | import { createIssue } from "../src/core/issues.ts"; |
| 19 | 20 | import { createToken } from "../src/core/tokens.ts"; |
| 20 | 21 | import { createUser, type User } from "../src/core/users.ts"; |
| @@ -185,6 +186,21 @@ describe("the Talk list", () => { | ||
| 185 | 186 | const forMember = await find(bob); |
| 186 | 187 | expect(forMember).not.toContain("telemetry_history"); |
| 187 | 188 | 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"); | |
| 188 | 204 | // A plain token still finds every tool it may call, Talk's rule aside. |
| 189 | 205 | const r = (await post(plain(alice, "admin"), "tools/call", { name: "find_tool", arguments: { query: "cpu memory" } })).result!; |
| 190 | 206 | expect((r["content"] as { text: string }[])[0]!.text).toContain("\"system\""); |
test/pinned-ceiling.test.ts +7
| @@ -122,6 +122,13 @@ describe("cloud account ceiling", () => { | ||
| 122 | 122 | for (const n of ["one", "two", "three"]) expect((await deployPinned(app, admin(), input(n))).ok).toBe(true); |
| 123 | 123 | const o = cloudOverview(app, admin()); |
| 124 | 124 | 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([]); | |
| 125 | 132 | }); |
| 126 | 133 | |
| 127 | 134 | test("the deploy that would cross the ceiling is refused before any provider call", async () => { |
new above
offline
Remove this TODO. A note left as future work is not shippable; file an issue for the
experimentread and link it from the pull.