Skip to content

Commit 21d1783

Browse files
committed
fix(acp): retain current schemas and decline empty-only forms
1 parent 4855d52 commit 21d1783

5 files changed

Lines changed: 2356 additions & 2695 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 1 addition & 333 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const emitBackgroundToolDuringAnswer =
3232
const emitMcpToolApprovalElicitation =
3333
process.env.T3_ACP_EMIT_MCP_TOOL_APPROVAL_ELICITATION === "1";
3434
const emitElicitation = process.env.T3_ACP_EMIT_ELICITATION === "1";
35-
// With T3_ACP_EMIT_ELICITATION, a JSON form schema replacing the default
36-
// boolean question, and a file the client's response is appended to as JSON.
3735
const elicitationSchema = process.env.T3_ACP_ELICITATION_SCHEMA;
3836
const decodeElicitationSchema = Schema.decodeUnknownSync(
3937
Schema.fromJsonString(AcpSchema.ElicitationSchema),
@@ -1537,338 +1535,8 @@ const program = Effect.gen(function* () {
15371535
? { _meta: { codex_approval_kind: "mcp_tool_call" } }
15381536
: {}),
15391537
});
1540-
if (elicitationResponseLogPath) {
1538+
if (elicitationResponseLogPath)
15411539
NodeFS.appendFileSync(elicitationResponseLogPath, `${encodeJson(response)}\n`, "utf8");
1542-
}
1543-
return yield* finishPrompt(requestedSessionId, "end_turn");
1544-
}
1545-
1546-
if (emitToolCalls) {
1547-
const toolCallId = "tool-call-1";
1548-
1549-
yield* agent.client.sessionUpdate({
1550-
sessionId: requestedSessionId,
1551-
update: {
1552-
sessionUpdate: "tool_call_update",
1553-
toolCallId,
1554-
title: "Terminal",
1555-
kind: "execute",
1556-
status: "pending",
1557-
rawInput: {
1558-
command: ["cat", "server/package.json"],
1559-
},
1560-
},
1561-
});
1562-
1563-
yield* agent.client.sessionUpdate({
1564-
sessionId: requestedSessionId,
1565-
update: {
1566-
sessionUpdate: "tool_call_update",
1567-
toolCallId,
1568-
status: "in_progress",
1569-
},
1570-
});
1571-
1572-
const permissionOptions: Array<AcpSchema.PermissionOption> = [
1573-
{ optionId: permissionOptionIds.allowOnce, name: "Allow once", kind: "allow_once" },
1574-
...(omitAllowAlways
1575-
? []
1576-
: [
1577-
{
1578-
optionId: permissionOptionIds.allowAlways,
1579-
name: "Allow always",
1580-
kind: "allow_always" as const,
1581-
},
1582-
]),
1583-
{ optionId: permissionOptionIds.rejectOnce, name: "Reject", kind: "reject_once" },
1584-
];
1585-
1586-
let cancelled = cancelledSessions.delete(requestedSessionId);
1587-
for (let index = 0; index < permissionRequestCount; index++) {
1588-
const command =
1589-
index > 0
1590-
? (process.env.T3_ACP_SECOND_PERMISSION_COMMAND ?? "cat server/package.json")
1591-
: "cat server/package.json";
1592-
const permission = yield* agent.client.requestPermission({
1593-
sessionId: requestedSessionId,
1594-
title: process.env.T3_ACP_PERMISSION_TITLE ?? `\`${command}\``,
1595-
subject: {
1596-
type: "tool_call",
1597-
toolCall: {
1598-
toolCallId: index === 0 ? toolCallId : `${toolCallId}-${index + 1}`,
1599-
title: process.env.T3_ACP_PERMISSION_TITLE ?? `\`${command}\``,
1600-
kind: "execute",
1601-
status: "pending",
1602-
rawInput: {
1603-
variant: "Bash",
1604-
command,
1605-
description: index === 0 ? "Read package metadata" : "Read it again",
1606-
},
1607-
content: [
1608-
{
1609-
type: "content",
1610-
content: {
1611-
type: "text",
1612-
text: `Not in allowlist: ${command}`,
1613-
},
1614-
},
1615-
],
1616-
},
1617-
},
1618-
options: permissionOptions,
1619-
});
1620-
cancelled =
1621-
cancelled ||
1622-
cancelledSessions.delete(requestedSessionId) ||
1623-
permission.outcome.outcome === "cancelled";
1624-
if (cancelled) {
1625-
break;
1626-
}
1627-
}
1628-
1629-
if (hangAfterPermission) {
1630-
return yield* Effect.never;
1631-
}
1632-
1633-
yield* agent.client.sessionUpdate({
1634-
sessionId: requestedSessionId,
1635-
update: {
1636-
sessionUpdate: "tool_call_update",
1637-
toolCallId,
1638-
title: "Terminal",
1639-
kind: "execute",
1640-
status: "completed",
1641-
rawOutput: {
1642-
exitCode: 0,
1643-
stdout: '{ "name": "t3" }',
1644-
stderr: "",
1645-
},
1646-
},
1647-
});
1648-
1649-
yield* agent.client.sessionUpdate({
1650-
sessionId: requestedSessionId,
1651-
update: {
1652-
sessionUpdate: "agent_message_chunk",
1653-
messageId: "mock-agent-message",
1654-
content: { type: "text", text: "hello from mock" },
1655-
},
1656-
});
1657-
1658-
return yield* finishPrompt(requestedSessionId, cancelled ? "cancelled" : "end_turn");
1659-
}
1660-
1661-
if (emitGenericToolPlaceholders) {
1662-
const toolCallId = "tool-call-generic-1";
1663-
1664-
yield* agent.client.sessionUpdate({
1665-
sessionId: requestedSessionId,
1666-
update: {
1667-
sessionUpdate: "tool_call_update",
1668-
toolCallId,
1669-
title: "Read File",
1670-
kind: "read",
1671-
status: "pending",
1672-
rawInput: {},
1673-
},
1674-
});
1675-
1676-
yield* agent.client.sessionUpdate({
1677-
sessionId: requestedSessionId,
1678-
update: {
1679-
sessionUpdate: "tool_call_update",
1680-
toolCallId,
1681-
status: "in_progress",
1682-
},
1683-
});
1684-
1685-
yield* agent.client.sessionUpdate({
1686-
sessionId: requestedSessionId,
1687-
update: {
1688-
sessionUpdate: "tool_call_update",
1689-
toolCallId,
1690-
status: "completed",
1691-
rawOutput: {
1692-
content: "package.json\n",
1693-
},
1694-
},
1695-
});
1696-
1697-
return yield* finishPrompt(requestedSessionId, "end_turn");
1698-
}
1699-
1700-
// In-turn monitor + TaskOutput hydrate, then a late post-finalize
1701-
// duplicate terminal TaskOutput for the same task. Exercises the
1702-
// already-handled short-circuit: must not pin hasPendingBackgroundWork.
1703-
if (emitInTurnTaskOutputThenLateDuplicate) {
1704-
const monitorToolCallId = "tool-call-monitor-1";
1705-
yield* agent.client.sessionUpdate({
1706-
sessionId: requestedSessionId,
1707-
update: {
1708-
sessionUpdate: "tool_call_update",
1709-
toolCallId: monitorToolCallId,
1710-
title: "Monitor: mock background task",
1711-
kind: "execute",
1712-
status: "pending",
1713-
rawInput: {},
1714-
},
1715-
});
1716-
yield* agent.client.sessionUpdate({
1717-
sessionId: requestedSessionId,
1718-
update: {
1719-
sessionUpdate: "tool_call_update",
1720-
toolCallId: monitorToolCallId,
1721-
status: "in_progress",
1722-
},
1723-
});
1724-
yield* agent.client.sessionUpdate({
1725-
sessionId: requestedSessionId,
1726-
update: {
1727-
sessionUpdate: "tool_call_update",
1728-
toolCallId: "tool-call-fetch-1",
1729-
title: "get_command_or_subagent_output",
1730-
kind: "other",
1731-
status: "pending",
1732-
rawInput: { task_id: "task-monitor-1" },
1733-
},
1734-
});
1735-
yield* agent.client.sessionUpdate({
1736-
sessionId: requestedSessionId,
1737-
update: {
1738-
sessionUpdate: "tool_call_update",
1739-
toolCallId: "tool-call-fetch-1",
1740-
status: "completed",
1741-
rawOutput: { output: "MONITOR_LISTING_TOKEN" },
1742-
},
1743-
});
1744-
yield* agent.client.sessionUpdate({
1745-
sessionId: requestedSessionId,
1746-
update: {
1747-
sessionUpdate: "agent_message_chunk",
1748-
messageId: "mock-agent-message",
1749-
content: { type: "text", text: "Monitor listing ready in-turn." },
1750-
},
1751-
});
1752-
// After deferred finalize (~2s) clears activeTurn, re-emit a terminal
1753-
// TaskOutput for the same task so bufferPostSettleWake sees
1754-
// alreadyHandledToolUpdate with a non-empty wake path.
1755-
yield* Effect.gen(function* () {
1756-
yield* Effect.sleep("2500 millis");
1757-
yield* Effect.sync(() => {
1758-
writeJsonRpcNotification("session/update", {
1759-
sessionId: requestedSessionId,
1760-
update: {
1761-
sessionUpdate: "tool_call_update",
1762-
toolCallId: "tool-call-fetch-1",
1763-
title: "get_command_or_subagent_output",
1764-
kind: "other",
1765-
status: "completed",
1766-
rawOutput: { output: "MONITOR_LISTING_TOKEN_LATE" },
1767-
},
1768-
});
1769-
});
1770-
}).pipe(Effect.forkDetach);
1771-
return yield* finishPrompt(requestedSessionId, "end_turn");
1772-
}
1773-
1774-
if (emitPostSettleMonitorFlow) {
1775-
const monitorToolCallId = "tool-call-monitor-1";
1776-
1777-
yield* agent.client.sessionUpdate({
1778-
sessionId: requestedSessionId,
1779-
update: {
1780-
sessionUpdate: "tool_call_update",
1781-
toolCallId: monitorToolCallId,
1782-
title: "Monitor: mock background task",
1783-
kind: "execute",
1784-
status: "pending",
1785-
rawInput: {},
1786-
},
1787-
});
1788-
1789-
yield* agent.client.sessionUpdate({
1790-
sessionId: requestedSessionId,
1791-
update: {
1792-
sessionUpdate: "tool_call_update",
1793-
toolCallId: monitorToolCallId,
1794-
status: "in_progress",
1795-
},
1796-
});
1797-
1798-
// After the prompt settles, replay the CLI-injected monitor-event
1799-
// turn: end notice, TaskOutput hydration, then (once the trigger
1800-
// file exists) the report chunk. Detached fiber on the real clock;
1801-
// it outlives the prompt handler.
1802-
yield* Effect.gen(function* () {
1803-
yield* Effect.sleep("150 millis");
1804-
yield* Effect.sync(() => {
1805-
writeJsonRpcNotification("session/update", {
1806-
sessionId: requestedSessionId,
1807-
update: {
1808-
sessionUpdate: "user_message_chunk",
1809-
messageId: "mock-user-message",
1810-
content: {
1811-
type: "text",
1812-
text: 'Monitor "task-monitor-1" ended: [monitor ended: exit 0]',
1813-
},
1814-
},
1815-
});
1816-
writeJsonRpcNotification("session/update", {
1817-
sessionId: requestedSessionId,
1818-
update: {
1819-
sessionUpdate: "tool_call_update",
1820-
toolCallId: "tool-call-fetch-1",
1821-
title: "get_command_or_subagent_output",
1822-
kind: "other",
1823-
status: "pending",
1824-
rawInput: { task_id: "task-monitor-1" },
1825-
},
1826-
});
1827-
writeJsonRpcNotification("session/update", {
1828-
sessionId: requestedSessionId,
1829-
update: {
1830-
sessionUpdate: "tool_call_update",
1831-
toolCallId: "tool-call-fetch-1",
1832-
status: "completed",
1833-
rawOutput: { output: "MONITOR_LISTING_TOKEN" },
1834-
},
1835-
});
1836-
});
1837-
if (injectedReportTriggerPath === undefined) return;
1838-
while (!(yield* Effect.sync(() => NodeFS.existsSync(injectedReportTriggerPath)))) {
1839-
yield* Effect.sleep("20 millis");
1840-
}
1841-
yield* Effect.sync(() => {
1842-
writeJsonRpcNotification("session/update", {
1843-
sessionId: requestedSessionId,
1844-
update: {
1845-
sessionUpdate: "agent_message_chunk",
1846-
messageId: "mock-agent-message",
1847-
content: { type: "text", text: "Monitor finished. MONITOR_REPORT_TOKEN" },
1848-
},
1849-
});
1850-
});
1851-
}).pipe(Effect.forkDetach);
1852-
1853-
return yield* finishPrompt(requestedSessionId, "end_turn");
1854-
}
1855-
1856-
if (emitAskQuestion) {
1857-
yield* agent.client.extRequest("cursor/ask_question", {
1858-
toolCallId: "ask-question-tool-call-1",
1859-
title: "Question",
1860-
questions: [
1861-
{
1862-
id: "scope",
1863-
prompt: "Which scope?",
1864-
options: [
1865-
{ id: "workspace", label: "Workspace" },
1866-
{ id: "session", label: "Session" },
1867-
],
1868-
},
1869-
],
1870-
});
1871-
18721540
return yield* finishPrompt(requestedSessionId, "end_turn");
18731541
}
18741542

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5705,12 +5705,13 @@ describe("AcpAdapterV2", () => {
57055705
}).pipe(Effect.provide(layerTest), Effect.scoped),
57065706
);
57075707

5708-
it.live("declines a form whose selection counts no answer can meet, without asking", () =>
5708+
it.live("declines a form whose selection counts the client cannot answer, without asking", () =>
57095709
Effect.gen(function* () {
57105710
const items = { type: "string", enum: ["a", "b"] };
57115711
for (const [name, bounds] of [
57125712
["min-above-max", { minItems: 2, maxItems: 1 }],
57135713
["min-above-options", { minItems: 3 }],
5714+
["empty-only", { maxItems: 0 }],
57145715
] as const) {
57155716
const { questions, response } = yield* runFormElicitation({
57165717
name,

0 commit comments

Comments
 (0)