Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Resolve stale approval decisions quietly and contain denied commands in history (#1742)

Joshua France8e531eec7fde
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index d9d9276f3..7c7a54810 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -1834,7 +1834,9 @@ export function createChatSurface(
data-index=${index}
data-entry-seqs=${messageEntrySeqs(message).join(" ")}
>
- <div class="system-note">${label}: <code>${decision.command}</code></div>
+ <div class="system-note approval-decision">
+ ${label}<code class="approval-cmd approval-cmd-full">${decision.command}</code>
+ </div>
</article>`;
}
if (role === "system-note") {
diff --git a/plugins/web-ui/src/core-bridge.ts b/plugins/web-ui/src/core-bridge.ts
index c8e47341b..64c813c44 100644
--- a/plugins/web-ui/src/core-bridge.ts
+++ b/plugins/web-ui/src/core-bridge.ts
@@ -981,7 +981,7 @@ export function makeRunResumeStreamFn(
return fn as unknown as StreamFn;
}
-export async function resolveApproval(decision: ApprovalDecision): Promise<string> {
+export async function resolveApproval(decision: ApprovalDecision): Promise<string | null> {
if (decision.requestId.startsWith("keychain:")) {
const id = decision.requestId.slice("keychain:".length);
let choice = "deny";
@@ -995,7 +995,11 @@ export async function resolveApproval(decision: ApprovalDecision): Promise<strin
const submit = await api<{ runId?: string }>(`/api/approvals/${encodeURIComponent(decision.requestId)}`, {
method: "POST",
body: JSON.stringify({ approved: decision.approved, ...(decision.scope ? { scope: decision.scope } : {}) }),
+ }).catch((err: unknown) => {
+ if (err instanceof ApiError && err.status === 404) return null;
+ throw err;
});
+ if (!submit) return null;
if (!submit.runId) throw new Error("Could not continue after the approval.");
return submit.runId;
}
diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.css
index 2446e612f..69facc90f 100644
--- a/plugins/web-ui/src/shell.css
+++ b/plugins/web-ui/src/shell.css
@@ -1812,6 +1812,14 @@ a.chat-row-open {
text-align: center;
padding: 2px 10px;
}
+.approval-decision {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ width: 100%;
+ min-width: 0;
+ text-align: left;
+}
.system-note-text {
font-style: italic;
}
diff --git a/plugins/web-ui/test/approval-refusal-feedback.test.ts b/plugins/web-ui/test/approval-refusal-feedback.test.ts
index f4a3e1661..669b0797f 100644
--- a/plugins/web-ui/test/approval-refusal-feedback.test.ts
+++ b/plugins/web-ui/test/approval-refusal-feedback.test.ts
@@ -2,7 +2,7 @@ import { test, afterEach } from "node:test";
import assert from "node:assert/strict";
import type { Api, Model } from "@earendil-works/pi-ai";
import type { Agent } from "@earendil-works/pi-agent-core";
-import { runApprovalTurn } from "../src/core-bridge.ts";
+import { resolveApproval, runApprovalTurn } from "../src/core-bridge.ts";
const MODEL = { id: "m", api: "anthropic", provider: "anthropic" } as unknown as Model<Api>;
@@ -106,6 +106,11 @@ test("a missing or expired approval record surfaces a visible expiry message", a
);
});
+test("deciding an approval that was already decided resolves quietly with nothing to follow", async () => {
+ stubResolveResponse({ error: "not_found" }, 404);
+ assert.equal(await resolveApproval({ requestId: "a-1", approved: false }), null);
+});
+
test("a synchronous core refusal surfaces its reason, not a bare HTTP status", async () => {
stubResolveResponse(
{