The Open Framework for Building Agents
fix(eve): complete piped `eve info --json` output and key nested subagent schemas by path (#4071)
Andrew Barba4902e93a3b3a
diff --git a/.changeset/cli-flush-output-before-exit.md b/.changeset/cli-flush-output-before-exit.mdnew file mode 100644index 000000000..16423d8aa--- /dev/null+++ b/.changeset/cli-flush-output-before-exit.md@@ -0,0 +1,5 @@+---+"eve": patch+---++The `eve` CLI now finishes writing stdout and stderr before it exits. A parent process that reads large output through a pipe, such as `eve info --json` for an agent with many tool schemas, now receives the complete output instead of output cut off partway through.diff --git a/.changeset/info-tool-input-schemas.md b/.changeset/info-tool-input-schemas.mdindex ae7e3ed06..7c9efb81a 100644--- a/.changeset/info-tool-input-schemas.md+++ b/.changeset/info-tool-input-schemas.md@@ -2,4 +2,4 @@"eve": patch----`eve info --json` now includes `toolInputSchemas`: each static tool's input schema, for the root agent and each declared subagent, in the form eve sends to the model. `eve/tools` also exports `serializeModelInputSchema(schema)`, which returns that JSON Schema for any tool input schema, so checks no longer need to read `.eve/` build output.+`eve info --json` now includes `toolInputSchemas`: each static tool's input schema, for the root agent and each declared subagent, in the form eve sends to the model. Subagent entries are keyed by their path from the root agent, such as `forecaster/reviewer`, so nested subagents that share a name each get their own entry. `eve/tools` also exports `serializeModelInputSchema(schema)`, which returns that JSON Schema for any tool input schema, so checks no longer need to read `.eve/` build output.diff --git a/docs/reference/cli.md b/docs/reference/cli.mdindex bdaf60617..11114138b 100644--- a/docs/reference/cli.md+++ b/docs/reference/cli.md@@ -170,7 +170,7 @@ Run this first when something behaves unexpectedly. It confirms a file was disco| `messaging` | object | Session route patterns: `{ create, messages, stream }` || `artifacts` | object or `null` | Paths to the compiled manifest, discovery manifest, diagnostics, module map, and metadata |-`toolInputSchemas.root` maps each root agent tool name to its JSON Schema, including tools from mounted extensions under their namespaced names. `toolInputSchemas.subagents` maps each declared subagent name to the same kind of map for that subagent's tools. Each schema is the form eve sends to the model: schemas from a validation library such as Zod have `additionalProperties: false` on objects that allow no other keys, plain JSON Schema is kept as written, and tools whose calls run as `serve` tasks, including agent tools, include the optional `taskId` input eve adds.+`toolInputSchemas.root` maps each root agent tool name to its JSON Schema, including tools from mounted extensions under their namespaced names. `toolInputSchemas.subagents` has one entry for each declared subagent, including nested subagents, and each value is the same kind of map for that subagent's own tools. Each key is the subagent's path of names from the root agent: `forecaster` for a subagent the root agent declares, and `forecaster/reviewer` for a `reviewer` subagent that `forecaster` declares. Subagents that share a name under different parents get separate entries. Each schema is the form eve sends to the model: schemas from a validation library such as Zod have `additionalProperties: false` on objects that allow no other keys, plain JSON Schema is kept as written, and tools whose calls run as `serve` tasks, including agent tools, include the optional `taskId` input eve adds.```json{@@ -184,7 +184,17 @@ Run this first when something behaves unexpectedly. It confirms a file was disco"additionalProperties": false}},- "subagents": {}+ "subagents": {+ "forecaster": {},+ "forecaster/reviewer": {+ "check_source": {+ "type": "object",+ "properties": { "url": { "type": "string" } },+ "required": ["url"],+ "additionalProperties": false+ }+ }+ }}}```diff --git a/packages/eve/bin/eve.js b/packages/eve/bin/eve.jsindex d8546a2fd..5d96c0563 100755--- a/packages/eve/bin/eve.js+++ b/packages/eve/bin/eve.js@@ -321,6 +321,17 @@ export async function runEveCli(argv = process.argv.slice(2), overrides = {}, deawait cliModule.runCli(argv);}+/**+ * Resolves once every write already queued on the stream has been handed to the OS.+ */+async function flushWritable(stream) {+ if (stream.destroyed || stream.writableEnded) {+ return;+ }++ await new Promise((resolveFlush) => stream.write("", () => resolveFlush()));+}+async function isDirectExecution() {if (!process.argv[1]) {return false;@@ -354,6 +365,10 @@ if (await isDirectExecution()) {}process.exitCode = 1;} finally {+ // Pipes and sockets can accept writes asynchronously, and `process.exit`+ // drops anything still queued, truncating large output such as+ // `eve info --json` read by a parent Node process.+ await Promise.all([flushWritable(process.stdout), flushWritable(process.stderr)]);// The CLI bootstraps build/dev toolchains that can leave native service// handles alive after the command has completed. Once the top-level// command resolves, terminate the bin process explicitly so commands likediff --git a/packages/eve/src/cli/commands/info.test.ts b/packages/eve/src/cli/commands/info.test.tsindex 3885398d3..db3c0fb24 100644--- a/packages/eve/src/cli/commands/info.test.ts+++ b/packages/eve/src/cli/commands/info.test.ts@@ -3,6 +3,7 @@ import { z } from "zod";import { COMPILE_METADATA_KIND, COMPILE_METADATA_VERSION } from "#compiler/artifacts.js";import type { CompileAgentResult } from "#compiler/compile-agent.js";+import type { CompiledToolDefinition } from "#compiler/manifest.js";import { compileFromMemory } from "#internal/testing/compile-from-memory.js";import { defineInstructions } from "#public/definitions/instructions.js";import { defineSchedule } from "#public/definitions/schedule.js";@@ -115,21 +116,38 @@ describe("buildApplicationInfoJson", () => {});});- test("keys each subagent's tool input schemas by subagent name", async () => {+ test("keys subagent tool input schemas by path so same-named nested subagents stay distinct", async () => {const compiledState = await makeCompiledState();- const lookupOrder = compiledState.manifest.tools.find((tool) => tool.name === "lookup_order")!;- const researcher = { agent: { tools: [lookupOrder] }, name: "researcher" };+ const toolNamed = (name: string) =>+ compiledState.manifest.tools.find((tool) => tool.name === name)!;+ const subagent = (name: string, parentNodeId: string, tools: CompiledToolDefinition[]) => ({+ agent: { tools },+ name,+ nodeId: parentNodeId === "__root__" ? name : `${parentNodeId}::${name}`,+ parentNodeId,+ });const json = buildApplicationInfoJson({application: getApplicationInfo(APP_ROOT),compiledState: {...compiledState,- manifest: { ...compiledState.manifest, subagents: [researcher as never] },+ manifest: {+ ...compiledState.manifest,+ subagents: [+ subagent("billing", "__root__", []),+ subagent("red_team", "billing", [toolNamed("lookup_order")]),+ subagent("support", "__root__", []),+ subagent("red_team", "support", [toolNamed("create_ticket")]),+ ] as never,+ },},messaging: MESSAGING,});expect(json.toolInputSchemas.subagents).toEqual({- researcher: { lookup_order: lookupOrder.modelInputSchema },+ billing: {},+ "billing/red_team": { lookup_order: toolNamed("lookup_order").modelInputSchema },+ support: {},+ "support/red_team": { create_ticket: toolNamed("create_ticket").modelInputSchema },});expect(json.channels).toContainEqual(expect.objectContaining({ method: "GET", urlPath: "/eve/v1/health" }),diff --git a/packages/eve/src/cli/commands/info.ts b/packages/eve/src/cli/commands/info.tsindex d6be3138c..281d217fd 100644--- a/packages/eve/src/cli/commands/info.ts+++ b/packages/eve/src/cli/commands/info.ts@@ -1,5 +1,9 @@import { type ApplicationInspection, inspectApplication } from "#services/inspect-application.js";-import type { CompiledInstructionsDefinition, CompiledToolDefinition } from "#compiler/manifest.js";+import type {+ CompiledInstructionsDefinition,+ CompiledSubagentNode,+ CompiledToolDefinition,+} from "#compiler/manifest.js";import type { JsonObject } from "#shared/json.js";import { type CliRow, createCliTheme, renderCliSection } from "#cli/ui/output.js";@@ -28,7 +32,10 @@ export interface ApplicationInfoJson {toolInputSchemas: {/** The root agent's tools, including tools from mounted extensions. */root: Record<string, JsonObject>;- /** Each declared subagent's own tools, keyed by subagent name. */+ /**+ * Each declared subagent's own tools, keyed by the subagent's path of names+ * from the root agent, such as `researcher` or `researcher/reviewer`.+ */subagents: Record<string, Record<string, JsonObject>>;};subagents: string[];@@ -77,12 +84,7 @@ export function buildApplicationInfoJson(inspection: ApplicationInspection): Apptools: (compiledState?.manifest.tools ?? []).map((tool) => tool.name),toolInputSchemas: {root: modelInputSchemas(compiledState?.manifest.tools ?? []),- subagents: Object.fromEntries(- (compiledState?.manifest.subagents ?? []).map((subagent) => [- subagent.name,- modelInputSchemas(subagent.agent.tools),- ]),- ),+ subagents: subagentModelInputSchemas(compiledState?.manifest.subagents ?? []),},subagents: (compiledState?.manifest.subagents ?? []).map((subagent) => subagent.name),schedules: (compiledState?.manifest.schedules ?? []).map((schedule) => schedule.name),@@ -118,6 +120,20 @@ function modelInputSchemas(tools: readonly CompiledToolDefinition[]): Record<str);}+/** Subagent names are unique only among siblings, so each entry is keyed by its path from the root. */+function subagentModelInputSchemas(+ subagents: readonly CompiledSubagentNode[],+): Record<string, Record<string, JsonObject>> {+ const subagentsByNodeId = new Map(subagents.map((subagent) => [subagent.nodeId, subagent]));+ const pathOf = (subagent: CompiledSubagentNode): string => {+ const parent = subagentsByNodeId.get(subagent.parentNodeId);+ return parent === undefined ? subagent.name : `${pathOf(parent)}/${subagent.name}`;+ };+ return Object.fromEntries(+ subagents.map((subagent) => [pathOf(subagent), modelInputSchemas(subagent.agent.tools)]),+ );+}+function pluralize(count: number, noun: string): string {return `${count} ${noun}${count === 1 ? "" : "s"}`;}diff --git a/packages/eve/test/scenarios/cli.scenario.test.ts b/packages/eve/test/scenarios/cli.scenario.test.tsindex d455f8f95..4aca3e74e 100644--- a/packages/eve/test/scenarios/cli.scenario.test.ts+++ b/packages/eve/test/scenarios/cli.scenario.test.ts@@ -1,7 +1,8 @@-import { spawn, type ChildProcess } from "node:child_process";+import { execFile, spawn, type ChildProcess } from "node:child_process";import { access, mkdir, realpath, writeFile } from "node:fs/promises";import { join } from "node:path";import { fileURLToPath } from "node:url";+import { promisify } from "node:util";import { afterEach, describe, expect, it, vi } from "vitest";@@ -301,6 +302,45 @@ describe("runCli", () => {expect(output).toContain("0 errors, 0 warnings");});+ it("writes all of a large `eve info --json` document before the bin exits", async () => {+ const appRoot = await createMinimalAppRoot("eve-cli-info-json-pipe-");+ // Far larger than a pipe or socket buffer, so most of it is still queued+ // when the command resolves.+ const descriptionLength = 1024 * 1024;+ await mkdir(join(appRoot, "agent", "tools"), { recursive: true });+ await writeFile(+ join(appRoot, "agent", "tools", "file_report.mjs"),+ [+ "export default {",+ ' description: "File a report.",',+ " inputSchema: {",+ ' type: "object",',+ ` properties: { body: { type: "string", description: "x".repeat(${descriptionLength}) } },`,+ " },",+ " execute: () => null,",+ "};",+ "",+ ].join("\n"),+ );++ const { stdout } = await promisify(execFile)(+ process.execPath,+ [EVE_BIN_PATH, "info", "--json"],+ {+ cwd: appRoot,+ // A telemetry flush yields to the event loop, which would drain stdout+ // and hide an early exit.+ env: { ...process.env, EVE_TELEMETRY_DISABLED: "1" },+ maxBuffer: 16 * 1024 * 1024,+ },+ );++ const info = JSON.parse(stdout);+ expect(info.toolInputSchemas.root.file_report.properties.body.description).toHaveLength(+ descriptionLength,+ );+ }, 60_000);+it("defaults to dev when no command is provided in an eve project", async () => {const appRoot = await createMinimalAppRoot("eve-cli-default-dev-");const previousCwd = process.cwd();