From 758eb1c367530eb68aad63a76261ba19399d3ac5 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Mon, 23 Nov 2026 12:21:28 +0900 Subject: [PATCH 1/2] feat(supervision): unified supervision status surface across CLI/MCP/VSCode (#409) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every consumer now reads the same durable ae-a8n.supervision/v1 report and produces the identical snapshot — phase, observation health, pending requests, and the structured needs-human request (dialog, reason, options, required action, resume path). No client implements GUI probing, dialog pressing, or recovery policy. - devtools-cli: new read-only 'supervision' command resolves the session dir via --session-root / --workdir (/a8n-session) / --run-id (surviving run marker) and emits ae-devtools.cli.supervision/v1; optional --wait-ms/--wait-phases bounded wait (phase deadline still caps it). Never opens a session. - MCP: new ae_supervision tool (sessionRoot arg or the already-open session's root; never opens a session) and ae_session now carries the supervision snapshot additively when a session with an ae-a8n root is open. - VSCode: controller.supervision() + ae-devtools.supervision command registered in package.json; identical payload through callTool. - dev-loop/supervision.mjs: dir-addressed snapshot/wait helpers so surfaces that never opened a session read the same contract. - diagnostics: supervision snapshot already rides ae-devtools.diagnostics/v1 records/blocks additively (#408); sourcemap diagnostics remain a separate concern. Attached sessions get the identical read-only view — reading the report grants no ownership and no mutation. Fake/mock evidence only; real-host GUI path remains unverified. --- .../ae-devtools-cli/dev-loop/supervision.mjs | 40 +++++++ packages/ae-devtools-cli/devtools-cli/cli.mjs | 79 +++++++++++- .../devtools-cli/tests/run.mjs | 101 +++++++++++++++- .../mcp-server/tests/server.test.mjs | 112 +++++++++++++++++- packages/ae-devtools-cli/mcp-server/tools.mjs | 82 ++++++++++++- .../vscode-extension/controller.mjs | 12 ++ .../vscode-extension/extension.mjs | 1 + .../vscode-extension/package.json | 6 + .../tests/controller.test.mjs | 34 +++++- 9 files changed, 459 insertions(+), 8 deletions(-) diff --git a/packages/ae-devtools-cli/dev-loop/supervision.mjs b/packages/ae-devtools-cli/dev-loop/supervision.mjs index e5463a5..8f1e1d2 100644 --- a/packages/ae-devtools-cli/dev-loop/supervision.mjs +++ b/packages/ae-devtools-cli/dev-loop/supervision.mjs @@ -18,6 +18,7 @@ */ import { supervisionForSession, + supervisionReport, supervisionSnapshot, supervisionStatePath, waitForSupervisionPhase, @@ -49,6 +50,45 @@ export function supervisionSnapshotForSession(session, options = {}) { return report === null ? null : supervisionSnapshot(report); } +/** + * Read the supervision snapshot for an explicit ae-a8n session + * directory (Issue #409): the same durable contract the session-bound + * path uses, for surfaces that name the dir directly (CLI + * `--session-root`, MCP `ae_supervision.sessionRoot`). Read-only — + * never opens a session, never touches AE. + */ +export function supervisionSnapshotForDir(sessionDir, options = {}) { + if (typeof sessionDir !== "string" || sessionDir.length === 0) return null; + return supervisionSnapshot(supervisionReport(sessionDir, options)); +} + +/** + * Bounded wait on an explicit session dir (Issue #409): same contract + * as awaitSupervisionClassification but dir-addressed, for surfaces + * that never opened a session. + * @returns {Promise<{timedOut:boolean, deadlineExceeded:boolean, + * snapshot:object|null}>} + */ +export async function awaitSupervisionPhaseForDir(sessionDir, { + timeoutMs = 5_000, + intervalMs = 250, + phases = BLOCKING_SUPERVISION_PHASES, +} = {}) { + if (typeof sessionDir !== "string" || sessionDir.length === 0) { + return { timedOut: false, deadlineExceeded: false, snapshot: null }; + } + const outcome = await waitForSupervisionPhase(sessionDir, { + phases, + timeoutMs, + intervalMs, + }); + return { + timedOut: outcome.timedOut, + deadlineExceeded: outcome.deadlineExceeded, + snapshot: supervisionSnapshot(outcome.report), + }; +} + /** * Bounded wait for supervision to classify a blocking state after a * dispatch ended UNKNOWN (the modal-dialog case supervision exists diff --git a/packages/ae-devtools-cli/devtools-cli/cli.mjs b/packages/ae-devtools-cli/devtools-cli/cli.mjs index 3bc89f4..06e29b9 100644 --- a/packages/ae-devtools-cli/devtools-cli/cli.mjs +++ b/packages/ae-devtools-cli/devtools-cli/cli.mjs @@ -24,6 +24,9 @@ * node cli.mjs reap [--confirm] — recover a stale owned leftover * node cli.mjs diagnose * [--map-dir d] [--jsx p] [--jsx-map p] [--bundle-map p] + * node cli.mjs supervision [--session-root | --workdir | + * --run-id ] [--wait-ms ] [--wait-phases ] + * — read-only ae-a8n supervision status (Issue #409) * * Failure diagnostics (Issue #103): a failed/refused execute or verify * adds an additive `diagnostics` block to the evidence record — @@ -42,6 +45,15 @@ * before the evidence is recorded. monitor-lost/degraded/unavailable * health is reported verbatim, never as healthy. * + * Supervision status (Issue #409): `supervision` reads the SAME durable + * `ae-a8n.supervision/v1` report every other surface consumes — CLI, + * MCP `ae_supervision`, VSCode. It never opens a session, never + * dispatches, never probes the GUI: the session directory is named + * explicitly (--session-root), derived from a run workdir + * (--workdir → /a8n-session), or recovered from a surviving + * run marker (--run-id). Attached sessions get the identical read-only + * view — reading the report grants no ownership and no mutation. + * * Sessions: * fake — codec-faithful vm host (FAKE/MOCK evidence only) * a8n — owned AE session via a8n-transport (Issue #49); requires that @@ -92,6 +104,11 @@ import { beginRun, markSession, endRun, listRuns, reapRun, recordRequestEvent, n import { buildFailureDiagnostics, runDiagnose } from "./diagnostics.mjs"; import { failureOutcome, normalizedOutcome, isUnknownOutcome } from "../dev-loop/outcomes.mjs"; import { supervisionSnapshotForSession, awaitSupervisionClassification } from "../dev-loop/supervision.mjs"; +import { + supervisionReport, + supervisionSnapshot, + waitForSupervisionPhase, +} from "../a8n-transport/supervision.mjs"; import { aeDevtoolsSourceRef } from "./real-run-kit.mjs"; import { createConsentAudit } from "../trusted-execution/consent-audit.mjs"; @@ -322,6 +339,66 @@ async function main() { emit(payload); return code; } + case "supervision": { + // Read-only ae-a8n supervision status (Issue #409). Resolves the + // session dir WITHOUT opening a session: explicit --session-root + // wins, --workdir maps to the canonical /a8n-session + // layout, --run-id recovers the workdir from a surviving run + // marker. --wait-ms/--wait-phases give the monitor a BOUNDED + // window (also capped by the phase deadline) to reach a phase — + // there is no unbounded wait path. + let supDir = null; + let resolvedFrom = null; + if (typeof flags["session-root"] === "string" && flags["session-root"].length > 0) { + supDir = flags["session-root"]; + resolvedFrom = "session-root"; + } else if (typeof flags.workdir === "string" && flags.workdir.length > 0) { + supDir = join(flags.workdir, "a8n-session"); + resolvedFrom = "workdir"; + } else if (typeof flags["run-id"] === "string" && flags["run-id"].length > 0) { + const runs = await listRuns({ dir: RUNS_DIR }); + const marker = runs.find((r) => r.runId === flags["run-id"]) ?? null; + const workdir = marker?.session?.workdir; + if (typeof workdir === "string" && workdir.length > 0) { + supDir = join(workdir, "a8n-session"); + resolvedFrom = "run-marker"; + } + } + if (supDir === null) { + emit({ + schema: "ae-devtools.cli.error/v1", + code: "USAGE", + message: "supervision requires --session-root , --workdir , or --run-id ", + }); + return 2; + } + const waitMsRaw = flags["wait-ms"]; + const waitMs = waitMsRaw === undefined ? 0 : (waitMsRaw === "0" ? 0 : positiveMsFlag(waitMsRaw) ?? 0); + const phases = typeof flags["wait-phases"] === "string" && flags["wait-phases"].length > 0 + ? flags["wait-phases"].split(",").map((s) => s.trim()).filter((s) => s.length > 0) + : null; + let report; + let wait = null; + if (waitMs > 0 && phases !== null) { + const outcome = await waitForSupervisionPhase(supDir, { phases, timeoutMs: waitMs }); + report = outcome.report; + wait = { timeoutMs: waitMs, timedOut: outcome.timedOut, deadlineExceeded: outcome.deadlineExceeded }; + } else { + report = supervisionReport(supDir); + } + const snapshot = supervisionSnapshot(report); + emit({ + schema: "ae-devtools.cli.supervision/v1", + resolvedFrom, + sessionDir: supDir, + supervision: snapshot, + ...(wait !== null ? { wait } : {}), + evidenceLevel: "read-only durable state — no session opened, nothing dispatched", + }); + // Exit nonzero only when the report itself is unavailable — + // needs-human/blocked are observed states, not command failures. + return snapshot?.status === "observed" ? 0 : 1; + } case "discover": { emit({ schema: DEVLOOP_SCHEMA, evidenceLevel: "registry metadata — no dispatch", ...discover({ domain: flags.domain ?? null }) }); return 0; @@ -588,7 +665,7 @@ async function main() { return code; } default: - process.stderr.write("usage: cli.mjs ...\n"); + process.stderr.write("usage: cli.mjs ...\n"); return 2; } } diff --git a/packages/ae-devtools-cli/devtools-cli/tests/run.mjs b/packages/ae-devtools-cli/devtools-cli/tests/run.mjs index 4330c9b..7bfe30d 100644 --- a/packages/ae-devtools-cli/devtools-cli/tests/run.mjs +++ b/packages/ae-devtools-cli/devtools-cli/tests/run.mjs @@ -3,7 +3,7 @@ */ import assert from "node:assert/strict"; import { execFileSync, spawn } from "node:child_process"; -import { mkdtempSync, rmSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { mkdtempSync, mkdirSync, rmSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -991,4 +991,103 @@ t("diagnose refuses marker-lookup traversal ids", () => { assert.ok(r.body.notes.some((n) => n.includes("no such file or run marker")), JSON.stringify(r.body.notes)); }); +// ------------------------------------------------ supervision status (Issue #409) +// Fake level only: durable ae-a8n.supervision/v1 files in temp dirs. +// The CLI supervision command reads files — no session, no AE. + +function writeSupDoc(dir, overrides = {}) { + const doc = { + schemaVersion: "ae-a8n.supervision/v1", + sessionId: "s1", + phase: "running", + observationHealth: "ok", + blocking: null, + pendingRequests: [], + enteredAt: new Date().toISOString(), + deadline: null, + evidence: [], + monitor: { + ownerId: "m", pid: 1, pidStart: null, + acquiredAt: new Date().toISOString(), heartbeatAt: new Date().toISOString(), + }, + history: [], + updatedAt: new Date().toISOString(), + ...overrides, + }; + writeFileSync(join(dir, "supervision.json"), `${JSON.stringify(doc, null, 2)}\n`); +} + +t("supervision --session-root reports the durable report, needs-human verbatim", () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-cli-")); + writeSupDoc(dir, { + phase: "needs-human", + deadline: new Date(Date.now() + 60_000).toISOString(), + blocking: { + host: "none", detail: "sign-in required", + windows: [{ + title: "Sign In", role: "AXWindow", subrole: "AXDialog", blocking: true, + tier: "human-required", dialogClass: "sign-in", code: "X", + texts: [], buttons: ["Cancel", "Sign In"], + }], + }, + }); + const r = run(["supervision", "--session-root", dir]); + assert.equal(r.code, 0); + assert.equal(r.body.schema, "ae-devtools.cli.supervision/v1"); + assert.equal(r.body.resolvedFrom, "session-root"); + assert.equal(r.body.supervision.status, "observed"); + assert.equal(r.body.supervision.phase, "needs-human"); + assert.equal(r.body.supervision.needsHuman.reason, "sign-in required"); + assert.deepEqual(r.body.supervision.needsHuman.options.sort(), ["Cancel", "Sign In"]); + assert.match(r.body.supervision.needsHuman.resumePath, /supervision status/); + rmSync(dir, { recursive: true, force: true }); +}); + +t("supervision --workdir derives /a8n-session; absent state is unavailable", () => { + const workdir = mkdtempSync(join(tmpdir(), "ae-sup-wd-")); + const sessionDir = join(workdir, "a8n-session"); + mkdirSync(sessionDir, { recursive: true }); + const absent = run(["supervision", "--workdir", workdir]); + assert.equal(absent.code, 1); + assert.equal(absent.body.resolvedFrom, "workdir"); + assert.equal(absent.body.supervision.status, "unavailable"); + assert.equal(absent.body.supervision.source, "absent"); + writeSupDoc(sessionDir); + const observed = run(["supervision", "--workdir", workdir]); + assert.equal(observed.code, 0); + assert.equal(observed.body.supervision.phase, "running"); + rmSync(workdir, { recursive: true, force: true }); +}); + +t("supervision without a resolvable dir is a usage error", () => { + const r = run(["supervision"]); + assert.equal(r.code, 2); + assert.equal(r.body.code, "USAGE"); +}); + +t("supervision absent/corrupt state exits 1, never reports healthy", () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-none-")); + const absent = run(["supervision", "--session-root", dir]); + assert.equal(absent.code, 1); + assert.equal(absent.body.supervision.status, "unavailable"); + assert.equal(absent.body.supervision.source, "absent"); + writeFileSync(join(dir, "supervision.json"), "not json"); + const corrupt = run(["supervision", "--session-root", dir]); + assert.equal(corrupt.code, 1); + assert.equal(corrupt.body.supervision.source, "corrupt"); + rmSync(dir, { recursive: true, force: true }); +}); + +t("supervision --wait-ms is bounded: running phase times out honestly", () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-wait-")); + writeSupDoc(dir); + const started = Date.now(); + const r = run(["supervision", "--session-root", dir, "--wait-ms", "200", "--wait-phases", "blocked,needs-human"]); + assert.equal(r.code, 0); + assert.equal(r.body.wait.timedOut, true); + assert.equal(r.body.supervision.phase, "running"); + assert.ok(Date.now() - started < 10_000); + rmSync(dir, { recursive: true, force: true }); +}); + await finish("tests passed"); diff --git a/packages/ae-devtools-cli/mcp-server/tests/server.test.mjs b/packages/ae-devtools-cli/mcp-server/tests/server.test.mjs index 845c81b..6d636b9 100644 --- a/packages/ae-devtools-cli/mcp-server/tests/server.test.mjs +++ b/packages/ae-devtools-cli/mcp-server/tests/server.test.mjs @@ -18,7 +18,7 @@ import { createServer, SERVER_NAME } from "../server.mjs"; import { loadTrustedCodec, createJsxRunner } from "../../trusted-execution/runner.mjs"; import { openFakeSession } from "../../devtools-cli/fake-session.mjs"; import { reapRun } from "../../devtools-cli/session-guard.mjs"; -import { mkdtempSync, readdirSync, readFileSync, rmSync, existsSync } from "node:fs"; +import { mkdtempSync, readdirSync, readFileSync, rmSync, existsSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; const HERE = dirname(fileURLToPath(import.meta.url)); @@ -133,7 +133,7 @@ test("tools/list exposes the dev-loop tools including ae_session", async () => { const c = makeClient(); const res = await c.request("tools/list"); const names = res.result.tools.map((t) => t.name).sort(); - assert.deepEqual(names, ["ae_discover", "ae_execute", "ae_inspect", "ae_session", "ae_verify"]); + assert.deepEqual(names, ["ae_discover", "ae_execute", "ae_inspect", "ae_session", "ae_supervision", "ae_verify"]); for (const t of res.result.tools) { assert.equal(t.inputSchema.type, "object"); assert.ok(t.description.length > 0); @@ -252,6 +252,112 @@ test("ae_session reports failed state after a rejected session open", async () = await c.server.close(); }); +// ------------------------------------------------ supervision (Issue #409) +// Fake level only: durable ae-a8n.supervision/v1 files in temp dirs. +// No AE, no monitor, no GUI — the tool reads files, nothing else. + +function writeSupervisionDoc(dir, overrides = {}) { + const doc = { + schemaVersion: "ae-a8n.supervision/v1", + sessionId: "s1", + phase: "running", + observationHealth: "ok", + blocking: null, + pendingRequests: [], + enteredAt: new Date().toISOString(), + deadline: null, + evidence: [], + monitor: { + ownerId: "m", pid: 1, pidStart: null, + acquiredAt: new Date().toISOString(), heartbeatAt: new Date().toISOString(), + }, + history: [], + updatedAt: new Date().toISOString(), + ...overrides, + }; + writeFileSync(join(dir, "supervision.json"), `${JSON.stringify(doc, null, 2)}\n`); + return doc; +} + +test("ae_supervision reads an explicit sessionRoot — same snapshot shape as every surface", async () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-mcp-")); + writeSupervisionDoc(dir, { + phase: "needs-human", + deadline: new Date(Date.now() + 60_000).toISOString(), + blocking: { + host: "none", detail: "license dialog is up", + windows: [{ + title: "License", role: "AXWindow", subrole: "AXDialog", blocking: true, + tier: "human-required", dialogClass: "license", code: "X", + texts: [], buttons: ["OK"], + }], + }, + }); + const { factory, calls } = countingSessionFactory(); + const c = makeClient({ sessionFactory: factory }); + const { payload, isError } = toolPayload(await c.request("tools/call", { + name: "ae_supervision", arguments: { sessionRoot: dir }, + })); + assert.equal(isError, false); + assert.equal(calls.count, 0, "ae_supervision must never open a session"); + assert.equal(payload.resolvedFrom, "sessionRoot"); + assert.equal(payload.supervision.status, "observed"); + assert.equal(payload.supervision.phase, "needs-human"); + // Structured needs-human detail rides every surface verbatim. + assert.equal(payload.supervision.needsHuman.reason, "license dialog is up"); + assert.deepEqual(payload.supervision.needsHuman.options, ["OK"]); + assert.match(payload.supervision.needsHuman.resumePath, /supervision status/); + rmSync(dir, { recursive: true, force: true }); + await c.server.close(); +}); + +test("ae_supervision without session or sessionRoot reports honest unavailable", async () => { + const { factory, calls } = countingSessionFactory(); + const c = makeClient({ sessionFactory: factory }); + const { payload } = toolPayload(await c.request("tools/call", { + name: "ae_supervision", arguments: {}, + })); + assert.equal(payload.supervision.status, "unavailable"); + assert.match(payload.supervision.reason, /no sessionRoot/); + assert.equal(calls.count, 0); + await c.server.close(); +}); + +test("ae_supervision uses the open session's root; fake session has none", async () => { + const c = makeClient(); + await c.request("tools/call", { + name: "ae_execute", + arguments: { opId: "read.projectSummary", consent: "grant" }, + }); + const { payload } = toolPayload(await c.request("tools/call", { + name: "ae_supervision", arguments: {}, + })); + assert.equal(payload.resolvedFrom, "open-session"); + // fake sessions have no ae-a8n session root — honest unavailable, + // never a fabricated running state. + assert.equal(payload.supervision.status, "unavailable"); + await c.server.close(); +}); + +test("ae_session carries the supervision snapshot when a session with a root is open", async () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-sess-")); + writeSupervisionDoc(dir, { phase: "blocked", deadline: new Date(Date.now() + 60_000).toISOString() }); + const s = fakeA8nSession(); + s.sessionRoot = dir; + const c = makeClient({ sessionFactory: async () => s }); + await c.request("tools/call", { + name: "ae_execute", + arguments: { opId: "read.projectSummary", consent: "grant" }, + }); + const { payload } = toolPayload(await c.request("tools/call", { + name: "ae_session", arguments: {}, + })); + assert.equal(payload.supervision.phase, "blocked"); + assert.equal(payload.supervision.health, "ok"); + rmSync(dir, { recursive: true, force: true }); + await c.server.close(); +}); + test("ae_execute without consent is refused BEFORE any session opens (default deny)", async () => { const { factory, calls } = countingSessionFactory(); const c = makeClient({ sessionFactory: factory }); @@ -643,7 +749,7 @@ test("spawned server over real stdio: initialize → tools → execute → verif child.stdin.write(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\n"); const list = await request("tools/list"); - assert.equal(list.result.tools.length, 5); + assert.equal(list.result.tools.length, 6); const ex = await request("tools/call", { name: "ae_execute", diff --git a/packages/ae-devtools-cli/mcp-server/tools.mjs b/packages/ae-devtools-cli/mcp-server/tools.mjs index 666ef03..4861381 100644 --- a/packages/ae-devtools-cli/mcp-server/tools.mjs +++ b/packages/ae-devtools-cli/mcp-server/tools.mjs @@ -30,7 +30,12 @@ import { discover, inspect, execute, verify, sessionStatus, DEVLOOP_SCHEMA } from "../dev-loop/devloop.mjs"; import { failureOutcome, normalizedOutcome, isUnknownOutcome } from "../dev-loop/outcomes.mjs"; import { recordFromExecuteResult } from "../dev-loop/failure-record.mjs"; -import { supervisionSnapshotForSession } from "../dev-loop/supervision.mjs"; +import { + supervisionSnapshotForSession, + supervisionSnapshotForDir, + awaitSupervisionPhaseForDir, +} from "../dev-loop/supervision.mjs"; +import { sessionDirFor } from "../a8n-transport/supervision.mjs"; export const MCP_SCHEMA = "ae-devtools.mcp/v1"; @@ -98,6 +103,20 @@ export const TOOLS = [ "Report session/API metadata: configured session kind, whether a session is open/opening/failed/closed in this server process, and the evidence level of an open session. Metadata only — never opens a session and never dispatches.", inputSchema: { ...OBJECT, properties: {}, additionalProperties: false }, }, + { + name: "ae_supervision", + description: + "Read the ae-a8n GUI-supervision status for a session (ae-a8n.supervision/v1 durable report): phase, observation health, pending requests, and the structured needs-human request (blocking dialog, reason, options, required action, resume path) when a human must act. Read-only — never opens a session, never dispatches, never probes the GUI. Pass sessionRoot to read a specific ae-a8n session dir; otherwise the already-open session's supervision state is reported. monitor-lost/degraded/unavailable health is reported verbatim, never as healthy.", + inputSchema: { + ...OBJECT, + properties: { + sessionRoot: { ...STRING, description: "ae-a8n session directory holding supervision.json (optional; defaults to the open session's root)" }, + waitMs: { type: "number", description: "Optional bounded wait (ms) for the phase to reach waitPhases; also capped by the phase deadline. 0/absent = single read." }, + waitPhases: { type: "array", items: { ...STRING }, description: "Phases to wait for when waitMs is set (default: blocked/recovering/needs-human/quarantined)" }, + }, + additionalProperties: false, + }, + }, ]; const TOOL_NAMES = new Set(TOOLS.map((t) => t.name)); @@ -325,18 +344,77 @@ export async function callTool(name, args = {}, ctx = {}) { } case "ae_session": { const peek = typeof ctx.peekSession === "function" ? ctx.peekSession() : {}; + const openSession = peek.session ?? null; return toolResult({ schema: MCP_SCHEMA, evidenceLevel: "metadata only — this call never opens a session", ...sessionStatus({ - session: peek.session ?? null, + session: openSession, sessionKind: ctx.sessionKind ?? null, opening: peek.opening === true, failed: peek.failed === true, }), + // Additive supervision snapshot (Issue #409): when a session is + // already open its durable ae-a8n supervision state rides along — + // the same report ae_supervision returns. Absent when no session + // is open or the session has no ae-a8n root (fake). Read-only. + ...(openSession !== null + ? (() => { + const sup = supervisionSnapshotForSession(openSession); + return sup !== null ? { supervision: sup } : {}; + })() + : {}), api: { mcp: MCP_SCHEMA, devLoop: DEVLOOP_SCHEMA }, }); } + case "ae_supervision": { + // Read-only durable supervision status (Issue #409). Resolution: + // explicit args.sessionRoot wins; otherwise the ALREADY-OPEN + // session's root is used — this tool never opens a session, so a + // closed server reports an honest unavailable, not a fabricated + // state. Attached sessions get the identical read-only view. + const peek = typeof ctx.peekSession === "function" ? ctx.peekSession() : {}; + const openSession = peek.session ?? null; + const explicitRoot = typeof args.sessionRoot === "string" && args.sessionRoot.length > 0 + ? args.sessionRoot + : null; + const dir = explicitRoot ?? (openSession !== null ? sessionDirFor(openSession) : null); + const waitMs = Number.isFinite(Number(args.waitMs)) && Number(args.waitMs) > 0 + ? Number(args.waitMs) + : 0; + const phases = Array.isArray(args.waitPhases) + ? args.waitPhases.filter((p) => typeof p === "string" && p.length > 0) + : null; + let snapshot = null; + let wait = null; + if (dir !== null) { + if (waitMs > 0) { + const outcome = await awaitSupervisionPhaseForDir(dir, { + timeoutMs: waitMs, + phases: phases !== null && phases.length > 0 ? phases : undefined, + }); + snapshot = outcome.snapshot; + wait = { timeoutMs: waitMs, timedOut: outcome.timedOut, deadlineExceeded: outcome.deadlineExceeded }; + } else { + snapshot = supervisionSnapshotForDir(dir); + } + } + return toolResult({ + schema: MCP_SCHEMA, + evidenceLevel: "read-only durable state — no session opened, nothing dispatched", + resolvedFrom: explicitRoot !== null ? "sessionRoot" : openSession !== null ? "open-session" : null, + ...(openSession !== null ? { session: sessionBlock(openSession) } : {}), + supervision: snapshot ?? { + status: "unavailable", + source: null, + reason: explicitRoot === null && openSession === null + ? "no session is open in this server and no sessionRoot was given; pass sessionRoot to read a specific ae-a8n session dir" + : "the resolved session has no ae-a8n supervision state", + readAt: new Date().toISOString(), + }, + ...(wait !== null ? { wait } : {}), + }); + } default: return toolResult({ schema: MCP_SCHEMA, error: `unhandled tool '${name}'` }, true); } diff --git a/packages/ae-devtools-cli/vscode-extension/controller.mjs b/packages/ae-devtools-cli/vscode-extension/controller.mjs index 9c7f324..93ee7cd 100644 --- a/packages/ae-devtools-cli/vscode-extension/controller.mjs +++ b/packages/ae-devtools-cli/vscode-extension/controller.mjs @@ -199,6 +199,18 @@ export function createController(options = {}) { return tool("ae_session", {}); }, + /** + * ae-a8n GUI-supervision status (Issue #409): the same durable + * ae-a8n.supervision/v1 report the CLI `supervision` command and + * MCP `ae_supervision` return — phase, observation health, and the + * structured needs-human request. Read-only: never opens a session, + * never dispatches, never probes the GUI; attached sessions get the + * identical view with no ownership or mutation grant. + */ + supervision(args = {}) { + return tool("ae_supervision", args); + }, + /** Op schema/metadata — never executes, never opens a session. */ inspect(opId) { return tool("ae_inspect", { opId }); diff --git a/packages/ae-devtools-cli/vscode-extension/extension.mjs b/packages/ae-devtools-cli/vscode-extension/extension.mjs index 3986a73..62d6ae6 100644 --- a/packages/ae-devtools-cli/vscode-extension/extension.mjs +++ b/packages/ae-devtools-cli/vscode-extension/extension.mjs @@ -179,6 +179,7 @@ export async function activate(context) { reg("ae-devtools.discover", () => controller.discover()); reg("ae-devtools.sessionStatus", () => controller.sessionStatus()); + reg("ae-devtools.supervision", () => controller.supervision()); reg("ae-devtools.inspect", async () => { const opId = await promptOpId(); if (!opId) return { schema: "ae-devtools.vscode-extension/v1", status: "cancelled", detail: "no operation id entered" }; diff --git a/packages/ae-devtools-cli/vscode-extension/package.json b/packages/ae-devtools-cli/vscode-extension/package.json index 6636f7a..10f696b 100644 --- a/packages/ae-devtools-cli/vscode-extension/package.json +++ b/packages/ae-devtools-cli/vscode-extension/package.json @@ -18,6 +18,7 @@ "onCommand:ae-devtools.execute", "onCommand:ae-devtools.verify", "onCommand:ae-devtools.sessionStatus", + "onCommand:ae-devtools.supervision", "onCommand:ae-devtools.debug.setup", "onCommand:ae-devtools.debug.attach" ], @@ -48,6 +49,11 @@ "title": "AE DevTools: Session Status", "category": "AE DevTools" }, + { + "command": "ae-devtools.supervision", + "title": "AE DevTools: Supervision Status", + "category": "AE DevTools" + }, { "command": "ae-devtools.debug.setup", "title": "AE DevTools: Debug Setup (launch.json)", diff --git a/packages/ae-devtools-cli/vscode-extension/tests/controller.test.mjs b/packages/ae-devtools-cli/vscode-extension/tests/controller.test.mjs index 6225776..5330eac 100644 --- a/packages/ae-devtools-cli/vscode-extension/tests/controller.test.mjs +++ b/packages/ae-devtools-cli/vscode-extension/tests/controller.test.mjs @@ -8,7 +8,7 @@ */ import test from "node:test"; import assert from "node:assert/strict"; -import { mkdtempSync, readdirSync, readFileSync, rmSync, existsSync } from "node:fs"; +import { mkdtempSync, readdirSync, readFileSync, rmSync, existsSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -74,6 +74,38 @@ test("sessionStatus reports closed then open state without dispatching itself (C assert.equal(spy.calls.length, 1); }); +test("supervision reports the durable ae-a8n report read-only (Issue #409)", async () => { + const dir = mkdtempSync(join(tmpdir(), "ae-sup-vsc-")); + writeFileSync(join(dir, "supervision.json"), `${JSON.stringify({ + schemaVersion: "ae-a8n.supervision/v1", + sessionId: "s1", phase: "needs-human", observationHealth: "ok", + blocking: { host: "none", detail: "modal up", windows: [] }, + pendingRequests: [], + enteredAt: new Date().toISOString(), + deadline: new Date(Date.now() + 60_000).toISOString(), + evidence: [], + monitor: { ownerId: "m", pid: 1, pidStart: null, acquiredAt: new Date().toISOString(), heartbeatAt: new Date().toISOString() }, + history: [], updatedAt: new Date().toISOString(), + }, null, 2)}\n`); + const spy = factorySpy(); + const c = createController({ sessionFactory: spy.factory, ui: recordingUi() }); + const res = await c.supervision({ sessionRoot: dir }); + assert.equal(res.schema, EXTENSION_SCHEMA); + assert.equal(res.command, "ae_supervision"); + assert.equal(res.supervision.phase, "needs-human"); + assert.equal(res.supervision.needsHuman.reason, "modal up"); + assert.equal(spy.calls.length, 0, "supervision must never open a session"); + rmSync(dir, { recursive: true, force: true }); +}); + +test("supervision without session or sessionRoot is honest unavailable", async () => { + const spy = factorySpy(); + const c = createController({ sessionFactory: spy.factory, ui: recordingUi() }); + const res = await c.supervision(); + assert.equal(res.supervision.status, "unavailable"); + assert.equal(spy.calls.length, 0); +}); + test("inspect returns op metadata; unknown op is a typed result, never executes", async () => { const spy = factorySpy(); const c = createController({ sessionFactory: spy.factory, ui: recordingUi() }); From 1b6729355d88836ad9392e39e4d19f7dc8a171f8 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Mon, 23 Nov 2026 12:39:59 +0900 Subject: [PATCH 2/2] test(consumer): expect ae_supervision in packaged MCP tools/list Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- packages/ae-devtools-cli/scripts/consumer-smoke.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ae-devtools-cli/scripts/consumer-smoke.mjs b/packages/ae-devtools-cli/scripts/consumer-smoke.mjs index b1b2303..1171e5f 100644 --- a/packages/ae-devtools-cli/scripts/consumer-smoke.mjs +++ b/packages/ae-devtools-cli/scripts/consumer-smoke.mjs @@ -258,7 +258,7 @@ try { const list = await request("tools/list"); const names = (list.result?.tools ?? []).map((t) => t.name).sort(); - assertNode.deepEqual(names, ["ae_discover", "ae_execute", "ae_inspect", "ae_session", "ae_verify"], "tools/list mismatch"); + assertNode.deepEqual(names, ["ae_discover", "ae_execute", "ae_inspect", "ae_session", "ae_supervision", "ae_verify"], "tools/list mismatch"); // Consent default deny still holds through the packaged bin: an // ae_execute without consent must be refused before any session.