Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Proposal words check: three small tightenings (#3055)

harness-for-autonomous[bot]03e4e89febed
diff --git a/backend/src/superTabs/buddies.test.ts b/backend/src/superTabs/buddies.test.ts
index 7243353cf..d2b69ec77 100644
--- a/backend/src/superTabs/buddies.test.ts
+++ b/backend/src/superTabs/buddies.test.ts
@@ -631,6 +631,105 @@ describe('a Buddy\'s proposal to the PM', () => {
}
})
+ /** Whether the Buddy may post [text] as its owner, given the lines it showed them (newest first) and their ask. */
+ const passes = (text: string, shown: string[], ask = 'ok, post it') => {
+ const { f } = asked()
+ try {
+ f.run({ type: 'buddy.propose', conversationId: f.chat, ownerMessageId: 'ask', ...proposal, text }, buddy, okayed(f, shown, ask))
+ return true
+ } catch (error) {
+ expect(error).toMatchObject({ code: 'PROPOSAL_UNSHOWN' })
+ expect(group(f, f.chat).proposals).toBeUndefined()
+ return false
+ }
+ }
+
+ // Task #2989 (security reviews of #3024): the line shown is the first quoted one right after the marker; any later line
+ // of that message is the Buddy's talk, never what the owner okayed.
+ it('counts as shown only the first quoted line right after the marker', () => {
+ const two = 'I\'ll post this as you: “Fix the login” or, if you prefer, “Delete the old accounts table”'
+ expect(passes('Fix the login', [two])).toBe(true)
+ expect(passes('Delete the old accounts table', [two])).toBe(false)
+ const straight = 'I\'ll post this as you:\n"Fix the login"\n\nKen also said "the client is leaving". OK?'
+ expect(passes('Fix the login', [straight])).toBe(true)
+ expect(passes('the client is leaving', [straight])).toBe(false)
+ // The rest of the message around the first quoted line, which passed whole, is not a line the owner was shown to post.
+ expect(passes('“Fix the login” or, if you prefer, “Delete the old accounts table', [two])).toBe(false)
+ expect(passes('"Keep drafts offline" OK?', ['I\'ll post this as you: "Keep drafts offline" OK?'])).toBe(false)
+ // An unquoted line after the marker is still taken whole, as today, and never a piece of it or a quote inside it.
+ expect(passes('Fix the "login" page', ['I’ll post this as you: Fix the "login" page'])).toBe(true)
+ expect(passes('login', ['I’ll post this as you: Fix the "login" page'])).toBe(false)
+ // Only a pair of the same kind closes the line (security review 2 of #3055): a straight quote inside a curly one, or a
+ // curly one opened inside it, is part of the line the owner read, never its end. An unclosed one leaves all of it whole, as today.
+ for (const [text, shown] of [['Ship it', 'I\'ll post this as you: “Ship it" is wrong, wait for the fix”'],
+ ['We merge', 'I\'ll post this as you: "We merge” only after Ken signs off"'],
+ ['A “B', 'I\'ll post this as you: “A “B” C”'], ['ship it', 'I\'ll post this as you: “Keep drafts offline" and then “ship it”']] as const)
+ expect(passes(text, [shown])).toBe(false)
+ expect(passes('We merge” only after Ken signs off', ['I\'ll post this as you: "We merge” only after Ken signs off"'])).toBe(true)
+ expect(passes('“Keep drafts offline', ['I\'ll post this as you: “Keep drafts offline'])).toBe(true)
+ })
+
+ // Task #2989: the Buddy showed one line, then replaced it; the owner's ok is for the newest one only.
+ it('counts as shown only the newest line its Buddy showed before the ok', () => {
+ const older = 'I\'ll post this as you: “Also ship the phone app”', newer = 'I\'ll post this as you: “Keep drafts offline”'
+ // Newest first, as shownBefore gives them.
+ expect(passes('Keep drafts offline', [newer, older])).toBe(true)
+ expect(passes('Also ship the phone app', [newer, older])).toBe(false)
+ // The Buddy's talk after the newest shown line leaves it in force.
+ expect(passes('Keep drafts offline', ['Want me to change anything?', newer, older])).toBe(true)
+ expect(passes('Also ship the phone app', ['Want me to change anything?', newer, older])).toBe(false)
+ // A newest marker that shows nothing leaves nothing to post: the older line was replaced.
+ expect(passes('Also ship the phone app', ['I\'ll post this as you:', older])).toBe(false)
+ })
+
+ // Task #2989: the owner's words after a colon count only when what comes before it asks to send them. A label, a quote of
+ // someone else or a "don't" before the colon is not an ask, and the part after it is not what they asked to post.
+ it('counts the words after the owner\'s colon only when what comes before it asks to send them', () => {
+ for (const [ask, words] of [
+ ['post this: Fix the login', 'Fix the login'],
+ ['Send this to the PM: Offline drafts please', 'Offline drafts please'],
+ ['ok, please send it to River: "Fix the login"', 'Fix the login'],
+ ['Can you post this for me: Keep drafts offline', 'Keep drafts offline'],
+ ['Gửi PM: Sửa lỗi đăng nhập', 'Sửa lỗi đăng nhập'],
+ ['Send this to the PM for me: Keep drafts offline', 'Keep drafts offline'],
+ ] as const) {
+ expect(passes(words, [], ask)).toBe(true)
+ expect(passes(ask, [], ask)).toBe(true)
+ }
+ for (const [ask, words] of [
+ ['Bug: login fails on the web', 'login fails on the web'],
+ ['Ken said: the client is leaving', 'the client is leaving'],
+ ['Don\'t post this: the client is leaving', 'the client is leaving'],
+ ['Please don\'t send this: the client is leaving', 'the client is leaving'],
+ ['Never tell the PM: the client is leaving', 'the client is leaving'],
+ ['Tell Ken not to post: the client is leaving', 'the client is leaving'],
+ ['Đừng gửi: khách hàng sắp rời đi', 'khách hàng sắp rời đi'],
+ ['Report: the client is leaving', 'the client is leaving'],
+ // A negation after the send word says not to send it (security review 1 of #3055).
+ ['Tell nobody: the client is leaving', 'the client is leaving'],
+ ['Send nothing yet: we drop Windows', 'we drop Windows'],
+ ['Share this with nobody: layoffs are coming', 'layoffs are coming'],
+ ['Send it to none of them: layoffs are coming', 'layoffs are coming'],
+ ['Post it without Ken knowing: layoffs are coming', 'layoffs are coming'],
+ ['Gửi ko được: khách hàng sắp rời đi', 'khách hàng sắp rời đi'],
+ ['Gửi khỏi cần: khách hàng sắp rời đi', 'khách hàng sắp rời đi'],
+ ['Nói chẳng ai nghe: khách hàng sắp rời đi', 'khách hàng sắp rời đi'],
+ // A question to the Buddy is not an ask to send (security review 2 of #3055).
+ ['Tell me why Ken said: the client is leaving', 'the client is leaving'],
+ ['can you tell me what this means: the client is leaving', 'the client is leaving'],
+ ['Send us what Ken said: the client is leaving', 'the client is leaving'],
+ ['Nói cho tôi biết vì sao Ken bảo: khách hàng sắp rời đi', 'khách hàng sắp rời đi'],
+ ['File: payroll.xlsx has every salary', 'payroll.xlsx has every salary'],
+ ['The client is leaving. Post this: Fix the login', 'Fix the login'],
+ ['The client is leaving. Post this: Fix the login', 'Post this: Fix the login'],
+ ['Send this when the client who is leaving next week has signed off: Fix the login', 'Fix the login'],
+ ] as const) {
+ expect(passes(words, [], ask)).toBe(false)
+ // The owner's whole message is still their own words.
+ expect(passes(ask, [], ask)).toBe(true)
+ }
+ })
+
it('refuses an older Buddy\'s proposal with no words of its owner, saying how to send one', () => {
const { f, ask } = asked()
expect(() => f.run({ type: 'buddy.propose', conversationId: f.chat, ownerMessageId: 'ask', goal: proposal.goal, scope: proposal.scope,
diff --git a/backend/src/superTabs/buddies.ts b/backend/src/superTabs/buddies.ts
index 1e85048c5..68f98577c 100644
--- a/backend/src/superTabs/buddies.ts
+++ b/backend/src/superTabs/buddies.ts
@@ -220,30 +220,54 @@ const comparable = (text: string): string => text.normalize('NFKC').replace(/\s+
const unquoted = (text: string): string => text.replace(/^["“”']+|["“”']+$/gu, '').trim()
const quotedIn = (text: string): string[] => [...text.matchAll(/“([^“”]+)”|"([^"]+)"/gu)].map(match => match[1] ?? match[2]!)
-/** The whole lines the owner's own message offers to post: all of it, all after its lead-in ("Send this to the PM: …"), and
- * each quoted line in it. Never a piece of one (security review 1 of #3024): a fragment can change what it says. */
+/** A lead-in that asks the Buddy to send what follows it ("Send this to the PM", "ok, post it", "Gửi PM"): it opens with a
+ * send word, after at most a few ok/please words; it says no "not", has no sentence break and is at most 10 words. Words
+ * that read as a label as often as an ask ("Report: …", "File: …", "Pass: …") are left out: in doubt, the Buddy shows the line. */
+const SEND_LEAD = /^(?:(?:ok(?:ay)?|yes|yeah|sure|please|pls|can you|could you|would you|go ahead and|and|then|just|ừ|vâng|được|làm ơn|hãy)[\s,]+)*(?:post|send|share|propose|tell|forward|submit|raise|gửi|đăng|chuyển|nói|đề xuất)(?=[\s,]|$)/iu
+/** A "no" anywhere in the lead-in, before or after its send word ("Tell nobody", "Send nothing yet", "Gửi ko được"; security
+ * review 1 of #3055), with the chat spellings of không (ko) and chẳng, khỏi. */
+const NEGATED = /(?:^|[^\p{L}])(?:not|no|never|nobody|nothing|none|neither|nor|without|đừng|không|ko|chưa|chẳng|khỏi)(?![\p{L}])|n['’]t(?![\p{L}])/iu
+/** "Tell me why …", "send us …", "nói cho tôi …": a question to the Buddy, not an ask to send (security review 2 of #3055). */
+const TO_ME = /(?:^|[^\p{L}])(?:post|send|share|tell|forward|gửi|chuyển|nói)\s+(?:(?:cho|với)\s+)?(?:me|us|tôi|mình)(?![\p{L}])/iu
+const asksToSend = (lead: string): boolean => {
+ const said = lead.normalize('NFKC').trim()
+ return SEND_LEAD.test(said) && !NEGATED.test(said) && !TO_ME.test(said) && !/[.!?;\n]/u.test(said) && said.split(/\s+/u).length <= 10
+}
+
+/** The whole lines the owner's own message offers to post: all of it, each quoted line in it, and all after its first colon
+ * when what comes before asks to send it (task #2989). A label ("Bug: …"), someone else's words ("Ken said: …") or a
+ * "don't post this: …" is not their ask, so the rest of that message alone is not their words to post. Never a piece of a
+ * line (security review 1 of #3024): a fragment can change what it says. */
const ownerLines = (said: string): string[] => {
const colon = said.indexOf(':')
- return [said, ...colon >= 0 ? [unquoted(said.slice(colon + 1))] : [], ...quotedIn(said)].map(comparable).filter(Boolean)
+ const lead = colon >= 0 && asksToSend(said.slice(0, colon))
+ return [said, ...lead ? [unquoted(said.slice(colon + 1))] : [], ...quotedIn(said)].map(comparable).filter(Boolean)
}
/** The skill's marker before the line a Buddy shows its owner (swarmSkills.ts): "I'll post this as you: …". */
const SHOWN_MARKER = /post this as you\s*:/giu
-/** The lines a Buddy's message showed to post: only what follows its last marker, whole or each quoted line in it (security
- * review 2 of #3024). What comes before the marker is the Buddy's own talk, which may quote any project. */
-const shownLines = (said: string): string[] => {
+/** The line a Buddy's message showed to post, or null with no marker. Only what follows its last marker counts (security
+ * review 2 of #3024): what comes before is the Buddy's own talk, which may quote any project. If it opens with a quote, only
+ * that first quoted line counts (task #2989): after the closing quote comes the Buddy's talk again ("OK?", another quote).
+ * Otherwise all of it counts, whole. */
+const shownLine = (said: string): string | null => {
const marker = [...said.matchAll(SHOWN_MARKER)].at(-1)
- if (!marker) return []
+ if (!marker) return null
const after = said.slice(marker.index! + marker[0].length)
- return [unquoted(after), ...quotedIn(after)].map(comparable).filter(Boolean)
+ // A pair of the same kind, with no curly opener inside (security review 2 of #3055): a mixed or nested quote is part of the
+ // line the owner read, so it never ends it early; with no such pair, all of it counts whole.
+ const quoted = /^\s*(?:“([^“”]*)”|"([^"]*)")/u.exec(after)
+ return comparable(quoted ? quoted[1] ?? quoted[2]! : unquoted(after))
}
-/** Whether [words] are what the owner okayed (anh Dee, task #2926): the whole of their own message that asked, or of the line
- * their Buddy showed them just before it (shownBefore) after its marker. Nothing else of their private chat goes out as them. */
+/** Whether [words] are what the owner okayed (anh Dee, task #2926): the whole of their own message that asked, or the line
+ * their Buddy showed them just before it (shownBefore, newest first). Only the newest shown line counts (task #2989): once
+ * the Buddy shows a new line, the older one is replaced. Nothing else of their private chat goes out as them. */
export function okayedWords(words: string, ask: { text?: string; shown?: readonly string[] }): boolean {
const wanted = comparable(words)
- return !!wanted && (ownerLines(ask.text ?? '').includes(wanted) || (ask.shown ?? []).some(said => shownLines(said).includes(wanted)))
+ const newest = (ask.shown ?? []).map(shownLine).find(line => line !== null)
+ return !!wanted && (ownerLines(ask.text ?? '').includes(wanted) || newest === wanted)
}
/** One row of a Buddy chat as the store reads it for a proposal, newest first. */
diff --git a/docs/plans/2026-11-05-proposal-words-tightenings-plan.md b/docs/plans/2026-11-05-proposal-words-tightenings-plan.md
new file mode 100644
index 000000000..2ded0c192
--- /dev/null
+++ b/docs/plans/2026-11-05-proposal-words-tightenings-plan.md
@@ -0,0 +1,101 @@
+# Proposal words check: three tightenings Implementation Plan
+
+> Implemented by the task's Engineer task by task, each failing test committed before its code (project instructions,
+> Engineer). Two independent security reviews on the pull request (Buddy guard).
+
+**Goal:** Task #2989, the follow-up to #2926 / #3024. A Buddy's proposal posts only its owner's own words, or the one
+line the Buddy showed them and they okayed. The two security reviews of #3024 left three minor gaps in the words check
+(`backend/src/superTabs/buddies.ts`, `okayedWords`), and this closes them. Tightening only: what passes today and is
+the owner's own words or the newest okayed shown line still passes.
+
+**Architecture:**
+
+- **(1) The first quoted line after the marker.** `shownLines` becomes `shownLine`, which returns at most one line. It
+ looks at what follows the Buddy's last "I'll post this as you:". If that starts with a quote (`"` or `“`), the shown
+ line is the text up to the first closing quote (`"` or `”`). Anything after the closing quote, such as "OK?" or a
+ second quoted line, does not count. Otherwise the shown line is everything after the marker, taken whole with its
+ outer quotes trimmed, as today. Today every quoted span after the marker counted, and so did the stray text around
+ the first one.
+- **(2) The newest shown line.** `okayedWords` reads `shown` newest first, as `shownBefore` gives it. It checks only
+ the newest Buddy message that carries the marker. An older shown line in the same window (the Buddy showed A, then
+ B, then the owner said ok) is refused. If the newest marker message shows nothing, nothing counts.
+- **(3) The colon lead-in of the owner's ask.** Today the text after the owner's first colon always counted, so a
+ label ("Bug: login fails"), an attribution ("Ken said: the client is leaving") or a refusal ("Don't post this: …")
+ let the Buddy post the rest as the owner. Now the text after the first colon counts only when everything before it
+ is a short ask to send it:
+ - it starts with a send word, optionally after ok/yes/please/can you: post, send, share, propose, tell,
+ forward, submit or raise, or in Vietnamese gửi, đăng, chuyển, nói or đề xuất. Words that read as a label as often
+ as an ask (report, file, pass, báo) are left out;
+ - it has no negation (not, n't, no, never, nobody, nothing, none, neither, nor, without, đừng, không, ko, chưa,
+ chẳng, khỏi);
+ - it is not a question to the Buddy (a send word followed by me, us, tôi or mình);
+ - it has no sentence break (`.`, `!`, `?`, `;` or a new line);
+ - it is at most 10 words.
+
+ Otherwise only the owner's whole message or a line they quoted counts. Any other words get the existing
+ show-then-ok refusal (`PROPOSAL_UNSHOWN`).
+- No new query: the 50 Buddy-chat rows the propose context reads already carry everything. The `shownBefore` window
+ (the Buddy's plain rows in the ask's lane since the owner's previous message) is unchanged.
+- The skill text needs no change. It already says to put nothing after the marker but the line, and that a change is
+ a new line to show.
+
+**Tech Stack:** TypeScript, the backend's Vitest unit suite.
+
+**Spec:** task #2989's brief.
+
+## Global Constraints
+
+- Tightening only. Every case the unit and integration tests accept today still passes.
+- Refusals use the existing `PROPOSAL_UNSHOWN` message. Nothing new is posted.
+- Owns `backend/src/superTabs/buddies.ts` and `buddies.test.ts`. No schema, index or query change.
+
+## Design
+
+- growth: N/A because nothing is stored.
+- concurrency: N/A because this is a pure check inside the existing command.
+- read cost: no new read.
+- scale: N/A because it checks at most 50 rows of one Buddy chat, once per proposal.
+- compatibility: an older Buddy that sends an older shown line or a fragment is refused, and the refusal tells it to
+ show the line and wait for the ok. Clients are unchanged.
+- migration + rollback: none. A rollback restores the looser check.
+- audience: the server checks the words, as today.
+- identity: N/A because no login or author changes.
+- failure: a refused send says why (`PROPOSAL_UNSHOWN`), and the Buddy shows the line again.
+- platforms: N/A because this is backend only.
+
+## Review Focus
+
+- Does any path still accept words the owner did not write or okay? Check the closing-quote scan, the
+ newest-marker pick and the lead-in pattern.
+- Does any legitimate case that passes today now fail? Look especially at an unquoted line after the marker and at
+ "Send this to the PM: …".
+
+## Tasks
+
+### Task 1: only the first quoted line after the marker
+
+**Files:** `backend/src/superTabs/buddies.test.ts`, `backend/src/superTabs/buddies.ts` (`shownLines`)
+
+- [ ] Test: `I'll post this as you: “A” or “B”` lets A through and refuses B; `“A” OK?` refuses `A” OK?`; an
+ unquoted line after the marker still passes whole. Watch it fail.
+- [ ] Code: `shownLine` returns the first quoted line, or everything after the marker when it is unquoted. Run
+ `npx vitest run src/superTabs/buddies.test.ts`.
+
+### Task 2: only the newest shown line
+
+**Files:** same (`okayedWords`)
+
+- [ ] Test: shown newest first `[“B”, “A”]` lets B through and refuses A. A newer Buddy message without the marker
+ leaves the newest marker line in force. A newest marker message that shows nothing lets nothing through. Watch
+ it fail.
+- [ ] Code: check only the newest `shown` entry that has the marker.
+
+### Task 3: the colon lead-in
+
+**Files:** same (`ownerLines`)
+
+- [ ] Test: these pass: "post this: Fix the login", "Send this to the PM: Offline drafts please",
+ "ok, please send it: …" and "Gửi PM: …". These are refused after the colon: "Bug: login fails",
+ "Ken said: the client is leaving", "Don't post this: …", "Please don't send this: …" and a lead-in with a
+ sentence break. Each whole message still passes. Watch it fail.
+- [ ] Code: `asksToSend` decides whether the lead-in is an ask to send.