Skip to content

feat(chat): let an allowed agent send CMS drafts on its own (00445) - #1982

Merged
gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-go-live-agent-drafts
Nov 2, 2026
Merged

gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-go-live-agent-drafts

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AUTONOMOUS-GO-LIVE PR 5: an agent an Admin allowed can send a Library draft to the brand's CMS without a click, once its guards pass (§5, §6). Behind CHAT_AUTO_GO_LIVE. Nothing can turn it on yet: the per-agent permission is set by PR 7's box. Interactive Chat and MCP keep the click.

Stacked on #1979 (the quality gate), #1978 (the server's reads, with #1970's internal send and #1967's tables), #1968 (text and link checks) and #1977 (autoGoLiveEnabled). Migration 00445; schema.sql regenerated.

The precedence: step 4b (lib/chat/precedence.ts)

  • It is the one exception to hard rule 1. It is evaluated last for an EXECUTE, and only turns a click into run/go_live. It never lifts a denial or a card: read-only, the demo brand, an Admin's Never, the role and "publishing off for Managers" still decide first.

  • goLiveCandidate(tool, ctx), all of these:

    • the flag is on;
    • Chat, and an agent run;
    • the Admin's switch covers the row's group;
    • the agent is allowed for the run's version, with its skills' checksums as given (Library skills aren't built, so only {} matches today);
    • Full auto is open (Growth+, paid) and on for agents;
    • the run is in Full auto;
    • the row has goLive.
  • goLiveHold(ctx, facts): the guards in order, and the first that fails keeps the click with a held reason:

    1. injection, then an untrusted start;
    2. the page as Send to CMS makes it (placeholders, fields);
    3. text aimed at AI, hidden text, a 30-word copy, a foreign link;
    4. a live page;
    5. the quality gate;
    6. the daily limit, last, so a page that fails a check holds no slot.

    A missing fact gives unchecked, the closed side.

  • policyChoices, allowedTools and listingDenial are unchanged. WRITE taint is unchanged.

The registry

  • defineTool gets goLive(input) (kind, draft, target), which sets flags.goLiveOnOwn.
  • It is refused on a READ or a WRITE.
  • It is refused on a row whose input could name an outside target: every field must be an enum, a literal, a switch, or an id that refuses a URL, a mail address and a site (§6.3 B1).
  • Only push_cms_draft has it.

The facts (lib/chat/go-live-facts.ts, new)

  • Read for a candidate only, in the guards' order, stopping at the first that fails. The expensive gate runs only for a clean page.
  • The page comes from getContentDraftPackageFor, as Send to CMS makes it. That same page is what gets sent, so what was checked is what goes out.
  • Allowed links:
    • the run's sites;
    • the brand's domains;
    • the draft's Sources (cited pages, kept sources);
    • competitors as hosts.
  • Usage counts the last 24 hours once per (draft, target), as reserve_agent_go_live does. The page's own pair takes no new slot; nextAt is when the first slot frees.
  • Never throws: a read that fails leaves its fact out.

The send (lib/chat/go-live-send.ts, new; the engine; write.ts)

  • The engine reserves the slot (reserve_agent_go_live). A full limit, or a slot that can't be reserved, opens the click card with why.
  • runLoggedWrite allows an EXECUTE with auto/go_live only for an agent run with its run id, its slot and page, on a row with goLive. Anything else still throws.
  • It POSTs to feat(server): send a page to the CMS for an agent run without a browser session (00444) #1970's /api/internal/chat/go-live/send (CRON_SECRET), which checks everything again from the database. Answers are mapped as sendDraftToCms answers them.
  • askWithoutSession leaves go_live alone: this path exists for runs with no session.
  • A send that fails turns its step into the click card, saying why. It is never tried again by itself. The try on its own uses its own idempotency key ({step}:go_live), so the person's later click runs the person's own send anew instead of replaying the failure.
  • The server frees the slot on its outcomes. The web frees it only when nothing reached the API. If the API couldn't be reached, the slot stays counted (it may have gone).
  • keepReadSites also keeps a read's structured sites in agent runs, so a page may link to cited and competitor pages a read listed.

Words and Activity

  • The held reason goes into the click card's existing note line: "Held for your click: {reason}" (chatEngine.held.*, §7.3's words). It is shown the same way as the no-session note today. No new component.
  • Activity:
    • auto/go_live with the agent and its run;
    • the label "Went live on its own" instead of Full auto (spec §17 item 5);
    • logActivity refuses go_live outside an agent run's EXECUTE.
  • 00445: chat_activity_log.auto_via accepts go_live, and a check keeps it to an EXECUTE with an agent_run_id.
  • The web works before 00443/00445: the go-live reads run only while the flag is on, and fall back on 42P01, PGRST205, 42703 and PGRST204.

Not in this PR (later PRs of the spec): the Inbox notice (PR 8), publish and Take down (PRs 9, 10), webhook (PR 11), the agent's box (PR 7).

Related issue

None. AUTONOMOUS-GO-LIVE spec, PR 5.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Unit tests:

  • precedence.test.ts, step 4b's matrix:
    • only all-true lifts;
    • each failing condition (flag, MCP, a person's own chat, the switch, the version, Starter and the trial, agents' Full auto, the run's mode, a row without goLive) gives a plain click;
    • each guard gives its held reason, in order, with the earliest winning;
    • missing facts give unchecked;
    • a page already counted takes no new slot;
    • Manager with publishing off is execute_off, and read-only, demo, Never and an Analyst are denied before 4b;
    • Settings still offers only Never, and WRITE taint is unchanged.
  • precedence-context.test.ts:
    • the switch, agents' Full auto, and the run's agent with its permission are read;
    • another version or changed skills give no permission;
    • nothing extra is read with the flag off, the switch off, or in a person's own chat;
    • before 00443 there is no permission, and other failures throw.
  • go-live-facts.test.ts:
    • the order and the stops;
    • the sent page equals the checked page;
    • text, hidden text and copies;
    • the link list;
    • a live page by its address or a published send;
    • the 24-hour count as the RPC counts it;
    • a failed read leaves its fact out.
  • write.test.ts:
    • the send goes through the internal route, with no sendDraftToCms, logged auto/go_live with the agent;
    • a repeat sends nothing;
    • it throws without an agent run, a slot, or goLive, for a WRITE, and for Full auto;
    • refusals log nothing;
    • with no secret the slot is freed.
  • engine.test.ts, an agent run with no session:
    • reserve, send, Activity;
    • a held quality card, whose click runs the person's own send;
    • the limit with the time;
    • a failed send becomes the card, and the click runs anew;
    • injection holds;
    • facts are read for candidates only.
  • tools.test.ts: goLive only on an EXECUTE with no free-text target; only push_cms_draft has it.
  • activity-view.test.ts: the label and the CSV.

No reachable UI change: the held line and the Activity label show only once an Admin allows an agent (PR 7). So no Help article in this PR; PR 7 updates agents.md with the held card. Migration 00445 must be applied to the dev database before PR 7's manual test.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (4f9d788), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41365960030): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 16 commits November 1, 2026 23:56
…permission

AUTONOMOUS-GO-LIVE PR 1 (migration 00443), with nothing reading it yet:
chat_settings gains the workspace switch (auto_go_live_groups, who turned
it on, when, under which terms); chat_agent_go_live keeps an agent's
permission for the version it was given on, with its daily limit (1-20,
5 unless set); chat_agent_go_live_events keeps each step an agent takes
live on its own, read by brand access. reserve_agent_go_live and
finish_agent_go_live (service role) hold the daily limit under a lock per
agent, once per (draft, target); a failed step frees its slot. Types,
schema.sql, and the brand-access and demo coverage lists follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AUTONOMOUS-GO-LIVE PR 3 (owner's Q1 answer B): pure checks on the page as
it would go out, for a later PR's go-live step. go-live-checks.ts holds a
page with text aimed at AI (in its text or its structured data), hidden
text, 30 words in a row copied from an untrusted read of the run, or a
link to a site that isn't the brand's, a source the draft lists, or a page
a read listed (page-sites linksToSites, sitesOfPages). An agent run now
keeps its untrusted reads as 64-bit hashes of 12-word runs in its
progress, 32 KB at most; past that the check holds the page. A person's
own chat keeps none. Nothing calls the checks yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er session

AUTONOMOUS-GO-LIVE PR 4 (migration 00444). POST
/api/internal/chat/go-live/send (CRON_SECRET) is how the web's engine will
send an agent's page on its own: it checks everything again from the
database (Chat on, Full auto's plan, the Admins' switch, the run running
as the person, the agent's permission for the run's version, the person's
role and the Managers' publishing switch, brand access, not the demo
brand, and the step's own reservation), then sends as a person's Send to
CMS does, with the agent run kept on the delivery
(content_draft_deliveries.agent_run_id). The step is finished done, or
failed with why, which frees its slot; a refusal frees only this step's
own slot. Never retried. v1 takes CMS drafts only. Nothing calls it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… test's model steps out of a hook-named helper

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…function

AUTONOMOUS-GO-LIVE PR 2a. lib/content/quality-inputs.ts qualityState()
computes E-E-A-T, Trust and Readability and what the editor shows beside
them from the reads the editor holds, so PR 2b's server gate for an agent
going live on its own computes them exactly as the editor does. The
editor's two dozen memos become one call after its reads; nothing on
screen changes. quality-inputs.test.ts keeps the editor's code from before
the move and shows both give the same values for four page types in each
phase, for every read still pending, and with Quality off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ate, on the run's budget

AUTONOMOUS-GO-LIVE PR 2b-1 (the owner's 2026-11-02 decision). POST
/api/internal/chat/go-live/quality-reads (CRON_SECRET) reads the draft as
saved for the web's gate: its links, and with Quality's phase 2 its
claims, its page read and the kinds of the sites the gate's rules can't
place. A kept read costs nothing; a new one is the agent run's own step
(chat-budget agentRunReserve: feature agent, within the run's cap and the
month's budget), not the workspace's Quality budget. Each read answers on
its own (run_cap, ai_budget, off, failed), so the gate can hold the page
on the one it lacks. The three reads take an optional meter; the page
read's brand context moves to content-page-context.js for both callers.
Nothing calls the endpoint yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AUTONOMOUS-GO-LIVE PR 6. Settings › Chat gets "Agents that publish on
their own", under what Managers may take live: an Admin's switch, off by
default, locked below Growth and while Content Quality is off, read-only
for everyone else. Turning it on asks the Admin to accept the
responsibility text first (its version kept with who and when, 00443);
turning it off needs no dialog. Hidden unless staff turn on
CHAT_AUTO_GO_LIVE for the workspace (autoGoLiveEnabled). Where it shows,
the page's "EXECUTE needs a click" lines say an Admin may let an agent go
live on its own. Help: a new Settings › Chat article, and the "nothing is
published without your click" lines name the exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…trust with the draft's reads

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…efore an agent takes it live

AUTONOMOUS-GO-LIVE PR 2b-2. lib/content/go-live-gate.ts goLiveGate()
gathers, with no one's session, every read the Content Editor's scores
take (the draft, its authors, inputs, sources, rules, confirmations, own
images and catalog product; its links, claims, page read, sources' kinds,
brand facts and site trust from the server's go-live reads, made on the
agent run's budget when none is kept) and scores the page with the
editor's own qualityState. It holds the page for a click, with why: with
Content Quality off, placeholders or fields a CMS won't take, suggestions
waiting, a read that couldn't be made, a fact that differs from an
approved one or one stated with none approved, a score under 60 or an
average under 75. A score with nothing to judge is left out, as the
editor's average leaves it.

To read the page as the editor does on the server: the catalog match takes
a client (catalog-match.ts), the editor's StarterKit options and the HTML
block's node schema move to lib (the editor uses the same), and textRanges
and openSpotPlaces move to lib/content/doc-text.ts with pageDoc(), which
parses a page into the editor's document. Nothing calls the gate yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…check the plan themselves

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AUTONOMOUS-GO-LIVE PR 5. Step 4b of the precedence: for an agent run in
Full auto whose agent an Admin allowed for the run's version, on a
workspace whose Admins let agents take publishing live, on Growth and up
and behind CHAT_AUTO_GO_LIVE, the Send to CMS click is lifted once the
guards pass (injection and untrusted start, the page as Send to CMS makes
it, its text and links, a live page, the quality gate, the daily limit).
The engine reserves the agent's slot, sends the checked page through the
API's internal route as the run's person, and logs it as go_live (00445).
A guard that fails, a full limit or a failed send keeps the click card and
says why. Interactive Chat and MCP keep the click; nothing can turn it on
until the Settings switch and the agent's box ship.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 2, 2026
gkhngyk
gkhngyk previously approved these changes Nov 2, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# Conflicts:
#	server/src/lib/brand-access-policies.test.js
#	server/src/middleware/demo-brand.test.js
#	supabase/schema.sql
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/precedence.ts
#	web/src/lib/chat/registry/define-tool.ts
#	web/src/lib/chat/write.ts
#	web/src/lib/content/quality-inputs.test.ts
#	web/src/lib/content/quality-inputs.ts

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkhngyk
gkhngyk merged commit 74b78a4 into ansvisor:main Nov 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants