Repository navigation
fix: send Not yet to the coordinator as the person's answer #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheGreatAxios
merged 4 commits into
main
from
cl-12078-treat-not-yet-as-a-decline-with-the-persons-reason-not-a
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4edfd75
fix: send Not yet to the coordinator as the person's answer
TheGreatAxios aeb4629
fix: decline open asks with the person's words on every path
TheGreatAxios 617bc29
docs(hub): warn that the decline note's wording is read back
TheGreatAxios 1c04dac
fix: mail a decline's words when the ask cannot take them
TheGreatAxios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Interchange answers a declined call with "denied by approver: " and the decline's message. The | ||
| // hub writes that message for the coordinator's asks, so it reads the person's answer rather than | ||
| // a failed call. Stored declines keep this wording, and the conversation finds the person's words | ||
| // by it, so rewording it shows earlier declines' whole note as the person's message. | ||
| const DECLINE_LEAD = "The person has chosen to decline this tool call."; | ||
| const FEEDBACK_LEAD = DECLINE_LEAD + "\n\nTheir feedback is: "; | ||
| const NO_FEEDBACK = | ||
| DECLINE_LEAD + | ||
| " They left no feedback. Ask them what they would like to do next."; | ||
|
|
||
| /** The message a coordinator ask's decline carries, around the person's words when they gave some. */ | ||
| export function declineNote(words: string | undefined): string { | ||
| const said = words?.trim(); | ||
| return said === undefined || said === "" ? NO_FEEDBACK : FEEDBACK_LEAD + said; | ||
| } | ||
|
|
||
| /** The person's own words in a decline's message: none for a bare decline, all of a message the hub did not write. */ | ||
| export function declinedWords(message: string | undefined): string | undefined { | ||
| if (message === undefined || message === NO_FEEDBACK) return undefined; | ||
| return message.startsWith(FEEDBACK_LEAD) | ||
| ? message.slice(FEEDBACK_LEAD.length) | ||
| : message; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { Hono } from "hono"; | ||
| import { declineNote } from "../config/decline.ts"; | ||
| import { createDeclineNote } from "./decline-note.ts"; | ||
|
|
||
| // What Interchange's reject route would receive. | ||
| async function rejected(approvalId: string, body: unknown) { | ||
| const app = new Hono(); | ||
| app.use( | ||
| "/api/tenants/:tenantId/approvals/:approvalId/reject", | ||
| createDeclineNote({ | ||
| coordinatorAsk: async (tenantId, id) => | ||
| tenantId === "tenant_1" && id === "appr_brief", | ||
| }), | ||
| ); | ||
| app.post("/api/tenants/:tenantId/approvals/:approvalId/reject", async (c) => | ||
| c.json(await c.req.json()), | ||
| ); | ||
| const response = await app.request( | ||
| `/api/tenants/tenant_1/approvals/${approvalId}/reject`, | ||
| { | ||
| method: "POST", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify(body), | ||
| }, | ||
| ); | ||
| return response.json(); | ||
| } | ||
|
|
||
| test("a coordinator ask's decline carries the person's words in the hub's note", async () => { | ||
| expect( | ||
| await rejected("appr_brief", { scope: "once", message: "Make it shorter" }), | ||
| ).toEqual({ scope: "once", message: declineNote("Make it shorter") }); | ||
| }); | ||
|
|
||
| test("a coordinator ask's decline without words asks the coordinator to find out what next", async () => { | ||
| expect(await rejected("appr_brief", {})).toEqual({ | ||
| message: declineNote(undefined), | ||
| }); | ||
| }); | ||
|
|
||
| test("a decline of another run's ask passes through unchanged", async () => { | ||
| expect(await rejected("appr_packages", { message: "Not that one" })).toEqual({ | ||
| message: "Not that one", | ||
| }); | ||
| }); | ||
|
|
||
| test("a decline whose message Interchange would refuse passes through unchanged", async () => { | ||
| expect(await rejected("appr_brief", { message: 42 })).toEqual({ | ||
| message: 42, | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { and, eq } from "drizzle-orm"; | ||
| import type { MiddlewareHandler } from "hono"; | ||
| import type { DB } from "@intx/db"; | ||
| import { approval } from "@intx/db/schema"; | ||
| import { getLogger } from "@intx/log"; | ||
| import { declineNote } from "../config/decline.ts"; | ||
| import { projectCoordinator } from "../db/schema.ts"; | ||
| import { requestErrorMetadata } from "../request-error.ts"; | ||
| import { readJson } from "../lib/json.ts"; | ||
| import { isRecord } from "../mail/conversation-turns.ts"; | ||
|
|
||
| const log = getLogger(["corbits-builder", "hub", "decline-note"]); | ||
|
|
||
| /** Whether an approval is one of a project coordinator's own asks. */ | ||
| export function coordinatorAskReader(db: DB["db"]) { | ||
| return async (tenantId: string, approvalId: string): Promise<boolean> => { | ||
| const [asked] = await db | ||
| .select({ runId: approval.runId }) | ||
| .from(approval) | ||
| .innerJoin( | ||
| projectCoordinator, | ||
| eq(projectCoordinator.runId, approval.runId), | ||
| ) | ||
| .where(and(eq(approval.id, approvalId), eq(approval.tenantId, tenantId))) | ||
| .limit(1); | ||
| return asked !== undefined; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * A decline of one of a coordinator's asks carries the hub's note around the person's words, so | ||
| * the coordinator reads it as their answer. Other declines, such as the coder's package asks, and | ||
| * a body Interchange's own validation should refuse, pass through unchanged. | ||
| */ | ||
| export function createDeclineNote(deps: { | ||
| coordinatorAsk: (tenantId: string, approvalId: string) => Promise<boolean>; | ||
| }): MiddlewareHandler { | ||
| return async (c, next) => { | ||
| const tenantId = c.req.param("tenantId"); | ||
| const approvalId = c.req.param("approvalId"); | ||
| if (c.req.method !== "POST" || !tenantId || !approvalId) return next(); | ||
| // A note that cannot be written must not cost the person their decision. | ||
| let body: Record<string, unknown>; | ||
| let words: string | undefined; | ||
| try { | ||
| const read = await readJson(c.req.raw.clone()); | ||
| if (!isRecord(read)) return next(); | ||
| const message = read["message"]; | ||
| if (message !== undefined && typeof message !== "string") return next(); | ||
| if (!(await deps.coordinatorAsk(tenantId, approvalId))) return next(); | ||
| body = read; | ||
| words = message; | ||
| } catch (error) { | ||
| log.error("Decline note unavailable", { | ||
| approvalId, | ||
| ...requestErrorMetadata(error), | ||
| }); | ||
| return next(); | ||
| } | ||
| const headers = new Headers(c.req.raw.headers); | ||
| headers.delete("content-length"); | ||
| c.req.raw = new Request(c.req.raw, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ ...body, message: declineNote(words) }), | ||
| }); | ||
| return next(); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.