Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/validate-daemon-tool-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@agentproto/runtime": minor
"@agentproto/cli": patch
---

`agentproto app validate` (and `catalog verify`) checks an app's `ui.tools` against the daemon's real tool surface instead of a hand-kept list of 21 names, which rejected valid apps such as session-chat. The list is `DAEMON_TOOL_NAMES`, exported as `@agentproto/runtime/daemon-tool-names`, generated from a gateway's `tools/list` with every optional surface wired (`pnpm --filter @agentproto/runtime gen:daemon-tool-names`) and kept exact by a runtime test.
17 changes: 7 additions & 10 deletions docs/cli/verbs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,13 @@ Exit `0` iff ALL of:
2. Every declared workflow loads via `@agentproto/workflow-loader` —
harness blocks, `promptFile` resolution, and `kind: gate` steps are
validated there.
3. Every `ui.tools` entry is a known daemon tool or any `app_*` tool. There
is no authoritative exported tool-name list in the daemon today, so the
CLI validates against a documented static list of the
orchestration/session surface (`agent_start`, `agent_prompt`,
`agent_output`, `agent_kill`, `agent_export`, `session_list`,
`session_monitor`, `session_events_poll`, `session_tree`,
`session_set_keepalive`, `message_parent`, `command_execute`,
`permissions_list`, `permissions_respond`, `task_create`, `task_list`,
`task_claim`, `task_update`, `daemon_health`) plus the whole `app_*`
family.
3. Every `ui.tools` entry is a tool the daemon registers or any `app_*`
tool. The daemon list is `DAEMON_TOOL_NAMES`
(`@agentproto/runtime/daemon-tool-names`), generated from a real
gateway's `tools/list` with every optional surface wired (workflows,
pairing/devices, llm-endpoint, ...) and kept exact by a runtime test, so
it follows the daemon of the same release. A tool added in a newer daemon
needs a CLI from that release.
4. When APP.md declares `data.dir`, `<dir>/<data.dir>/DATA.md` exists (the
data plane must ship its key dictionary — see `data/DATA.md`).
5. When APP.md declares `verify.command`, it is run — argv-split on
Expand Down
38 changes: 38 additions & 0 deletions packages/cli/src/__tests__/app-init-validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,44 @@ describe("agentproto app validate", () => {
).toBe(true)
})

it("accepts any tool the daemon registers in ui.tools (session-chat's surface)", async () => {
const appDir = await scaffoldTrame("daemon-tools")
const appMdPath = join(appDir, ".agentproto", "APP.md")
const appMd = await readFile(appMdPath, "utf8")
const tools = [
"adapter_list",
"catalog_models",
"auth_profile_list",
"agent_interrupt",
"session_queue_list",
"session_rename",
"conversation_read",
"message_send",
"session_capabilities",
"agent_set_model",
"session_compact",
"session_artifact_list",
"session_bg_task_tail",
"activities_list",
"cron_list",
"device_list",
"user_preset_list",
"mcp_app_ui_index",
]
await writeFile(
appMdPath,
appMd.replace(
" - app_state_list\n",
" - app_state_list\n" + tools.map((t) => ` - ${t}\n`).join(""),
),
"utf8",
)

const { stdout } = await captureJson(() => runAppValidate([appDir, "--json"]))
const report = parseReport(stdout)
expect(report.findings.filter((f) => f.scope === "ui.tools")).toEqual([])
})

it("fails — and propagates the exit code shape — when verify.command exits 1", async () => {
const appDir = await scaffoldTrame("failing-verify")
await writeFile(
Expand Down
48 changes: 11 additions & 37 deletions packages/cli/src/commands/app-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import matter from "gray-matter"
import { scaffoldApp } from "create-agentproto-app/scaffold"
import { loadAppHandle } from "@agentproto/app-kit"
import { loadWorkflowHandle } from "@agentproto/workflow-loader"
import { DAEMON_TOOL_NAMES } from "@agentproto/runtime/daemon-tool-names"

import { pathExists } from "./skill-install/shared.js"
import { expandHome } from "./skill-install/pack-resolve.js"
Expand All @@ -42,44 +43,16 @@ import { expandHome } from "./skill-install/pack-resolve.js"
const VERIFY_TIMEOUT_MS = 10 * 60 * 1000

/**
* The known daemon tool names a `ui.tools` allowlist may name besides the
* `app_*` family (which is accepted wholesale — app tools evolve together).
* This is a documented static list in the CLI: the daemon registers its
* full surface dynamically and exports no authoritative name list today.
* It covers the orchestration/session surface an app UI or app agent
* typically reaches (see `packages/runtime/src/orchestrator-gateway.ts`
* `DEFAULT_ORCHESTRATOR_TOOLS` and `DEFAULT_ALWAYS_ON_TOOLS` in
* `packages/runtime/src/index.ts`); genuinely app-scoped tools are all
* `app_*` and need no entry here.
* A `ui.tools` entry is valid when it is an `app_*` tool (accepted wholesale:
* app tools evolve together) or a tool the daemon registers. The daemon list
* is `DAEMON_TOOL_NAMES`, generated from a real gateway's `tools/list` and
* kept exact by a runtime test (`daemon-tool-names.test.ts`), so it follows
* the daemon instead of a hand-kept subset.
*/
const KNOWN_NON_APP_TOOLS: readonly string[] = [
"agent_start",
"agent_prompt",
"agent_output",
"agent_kill",
"agent_export",
"session_list",
"session_monitor",
"session_events_poll",
"session_tree",
"session_set_keepalive",
"message_parent",
"command_execute",
"permissions_list",
"permissions_respond",
"task_create",
"task_list",
"task_claim",
"task_update",
"daemon_health",
// Reached by app UIs through the served stage board (/agentproto/stageboard.js):
// Approve resolves a parked approval step via the escalation seam.
"workflow_escalation_resolve",
"workflow_status",
]
const DAEMON_TOOL_SET: ReadonlySet<string> = new Set(DAEMON_TOOL_NAMES)

function isKnownUiTool(name: string): boolean {
return name.startsWith("app_") || KNOWN_NON_APP_TOOLS.includes(name)
return name.startsWith("app_") || DAEMON_TOOL_SET.has(name)
}

const KNOWN_STEP_KINDS: readonly string[] = [
Expand Down Expand Up @@ -350,8 +323,9 @@ export async function collectAppFindings(appDir: string): Promise<{
scope: "ui.tools",
level: "error",
message:
`unknown tool '${tool}' — ui.tools entries must be app_* ` +
`tools or known daemon tools (${KNOWN_NON_APP_TOOLS.join(", ")}).`,
`unknown tool '${tool}': ui.tools entries must be app_* tools or ` +
`tools the agentproto daemon registers (${DAEMON_TOOL_NAMES.length} known ` +
`to this CLI version; a newer daemon tool needs a newer CLI).`,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
"import": "./dist/app-catalog.mjs",
"default": "./dist/app-catalog.mjs"
},
"./daemon-tool-names": {
"types": "./dist/daemon-tool-names.d.ts",
"import": "./dist/daemon-tool-names.mjs",
"default": "./dist/daemon-tool-names.mjs"
},
"./first-party-catalog-gen": {
"types": "./dist/first-party-catalog-gen.d.ts",
"import": "./dist/first-party-catalog-gen.mjs",
Expand Down Expand Up @@ -176,6 +181,7 @@
"clean": "rm -rf dist",
"check-types": "tsc --noEmit",
"test": "vitest run --passWithNoTests",
"gen:daemon-tool-names": "UPDATE_DAEMON_TOOL_NAMES=1 vitest run src/__tests__/daemon-tool-names.test.ts",
"test:watch": "vitest",
"gen:checkpoint-schema": "vite-node scripts/gen-checkpoint-schema.mjs",
"sim:inbound": "vite-node scripts/simulate-inbound.mjs",
Expand Down
158 changes: 158 additions & 0 deletions packages/runtime/src/__tests__/daemon-tool-names.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* `DAEMON_TOOL_NAMES` (daemon-tool-names.generated.ts) must be EXACTLY the
* tool surface a daemon registers: `agentproto app validate` checks an app's
* `ui.tools` against it, so a missing name rejects a valid app (every
* session-chat tool beyond the old hand-kept list did) and a stale one lets
* a typo through.
*
* Boots a real gateway (isolated HOME, nothing persisted) with every
* conditional surface wired: a pairing + host registry stub (pair_*,
* device_*) and the llm-endpoint tools, which the daemon only registers when
* `features.llmEndpoint` is on (registered here on a scratch server, so no
* sidecar starts). Then compares `tools/list` to the generated list.
*
* Regenerate after adding, renaming or removing a daemon tool:
* pnpm --filter @agentproto/runtime gen:daemon-tool-names
*/

import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
import { createServer } from "node:net"
import { tmpdir } from "node:os"
import { dirname, join } from "node:path"
import { fileURLToPath } from "node:url"
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { createMcpServer } from "@agentproto/mcp-server"
import { DAEMON_TOOL_NAMES } from "../daemon-tool-names.generated.js"

const GENERATED = join(dirname(fileURLToPath(import.meta.url)), "..", "daemon-tool-names.generated.ts")
const UPDATE = process.env.UPDATE_DAEMON_TOOL_NAMES === "1"

function freePort(): Promise<number> {
return new Promise((resolve, reject) => {
const srv = createServer()
srv.once("error", reject)
srv.listen(0, "127.0.0.1", () => {
const addr = srv.address()
const port = typeof addr === "object" && addr ? addr.port : 0
srv.close(() => resolve(port))
})
})
}

/** An object whose every method resolves to undefined. */
function noopStub(): never {
return new Proxy({}, { get: (_t, key) => (key === "then" ? undefined : async () => undefined) }) as never
}

const noopFn = (): never => (async () => undefined) as never
const listFn = (): never => (async () => []) as never

let home = ""

beforeAll(async () => {
home = await mkdtemp(join(tmpdir(), "daemon-tool-names-"))
vi.stubEnv("HOME", home)
vi.stubEnv("AGENTPROTO_HOME", join(home, ".agentproto"))
})

afterAll(async () => {
vi.unstubAllEnvs()
await rm(home, { recursive: true, force: true })
})

async function registeredToolNames(): Promise<string[]> {
// Imported after HOME is stubbed: some modules resolve ~/.agentproto at load.
const { createGateway } = await import("../index.js")
const { registerLlmEndpointTools } = await import("../llm-endpoint-tools.js")
const workspace = await mkdtemp(join(home, "ws-"))
const gateway = await createGateway({
workspace,
specs: [],
port: await freePort(),
boot: false,
persist: false,
persistPath: join(workspace, "sessions.json"),
// Every optional dependency `agentproto serve` wires, stubbed: several
// tool families only register when theirs is present (workflow_* needs
// an agent resolver, pair_*/device_* the pairing registry, ...). The
// tools close over these; listing them calls nothing beyond lifecycle
// hooks (shutdown on stop), so every method is a no-op.
pairingRegistry: noopStub(),
hostRegistry: noopStub(),
joinTokens: noopStub(),
resolveAgentAdapter: noopFn(),
installAgentAdapter: noopFn(),
listAgentAdapters: listFn(),
listBrowserAdapters: listFn(),
resolveBrowserAdapter: noopFn(),
listCatalogModels: listFn(),
listHarnessCapabilities: listFn(),
listWorktreeStatuses: listFn(),
provisionWorktree: noopFn(),
readBranchGcVerdict: noopFn(),
recordBranchGcVerdict: noopFn(),
resolveOpenPr: noopFn(),
resolvePrState: noopFn(),
runBranchGc: noopFn(),
runWorktreeAutoReclaim: noopFn(),
runWorktreeGc: noopFn(),
listSandboxProviders: listFn(),
resolveSandboxProvider: noopFn(),
})
const names = new Set<string>()
try {
const client = new Client({ name: "daemon-tool-names", version: "0" }, { capabilities: {} })
await client.connect(new StreamableHTTPClientTransport(new URL(`${gateway.url}/mcp`)))
for (const t of (await client.listTools()).tools) names.add(t.name)
await client.close()
} finally {
await gateway.stop()
}

const { server: scratch } = await createMcpServer({ specs: [], name: "llm-endpoint-scratch", version: "0" })
registerLlmEndpointTools(scratch, { registry: {} as never })
const [a, b] = InMemoryTransport.createLinkedPair()
await scratch.connect(b)
const c = new Client({ name: "scratch", version: "0" }, { capabilities: {} })
await c.connect(a)
for (const t of (await c.listTools()).tools) names.add(t.name)
await c.close()

return [...names].sort()
}

function render(names: readonly string[]): string {
return [
"// GENERATED by src/__tests__/daemon-tool-names.test.ts, do not edit.",
"// Regenerate: pnpm --filter @agentproto/runtime gen:daemon-tool-names",
"",
"/** Every MCP tool a daemon's gateway can register (conditional surfaces",
" * included: pairing/devices, llm-endpoint). Read by `agentproto app",
" * validate` to check an app's `ui.tools`. */",
"export const DAEMON_TOOL_NAMES: readonly string[] = [",
...names.map(n => ` ${JSON.stringify(n)},`),
"]",
"",
].join("\n")
}

describe("DAEMON_TOOL_NAMES", () => {
it("is exactly the daemon's registered tool surface", async () => {
const actual = await registeredToolNames()
expect(actual.length).toBeGreaterThan(100)
if (UPDATE) {
await writeFile(GENERATED, render(actual), "utf8")
return
}
const missing = actual.filter(n => !DAEMON_TOOL_NAMES.includes(n))
const stale = DAEMON_TOOL_NAMES.filter(n => !actual.includes(n))
expect(
{ missing, stale },
"daemon-tool-names.generated.ts is out of date: run pnpm --filter @agentproto/runtime gen:daemon-tool-names",
).toEqual({ missing: [], stale: [] })
expect(await readFile(GENERATED, "utf8")).toBe(render(actual))
}, 60_000)
})
Loading
Loading