Repository navigation
feat(chat): let Chat send findings to Action Center, attach files to tasks and set Ready for review, with Undo (W2-10) - #1897
Merged
gkhngyk merged 9 commits intoOct 31, 2026
Conversation
…uplicates checked first (W2-10) CHAT-09 §E and CHAT-20 §12 (V1 Final rules), behind the web's Chat tools. - POST /api/action-center/chat-actions/check: the brand's active actions that already cover a finding's prompts, pages or competitors (their kept list, 00244, and the prompts and pages their payload names), closest first: all of it, or some. - POST /api/action-center/chat-actions: the finding as an action, kind chat_finding with payload.source chat, the chat, the run and execution.mode (assisted or automated). An action that covers it answers 409 duplicate with that action and whether Create anyway may go (only when the entities differ); the same idempotency key returns what it made. - Frozen at creation: every entity, the targets, the baseline (the basket's metrics over the 14 days before, each named prompt per named platform) and the approved tasks, checked against AC-004 (a page or place per task, Done when, no analyze/identify/validate/measure, no "for N prompts"). tasks_generated_at is set, so the task writer never rewrites them. - Manual: Chat's own dedup key takes no definition slot, and the generator leaves chat_finding out of the day's five. The engine scores it on creation (priority.js sentByHand) and validate.js measures it on its prompts and pages, as other person-sent kinds. - Admins and Managers of the brand only; both routes on the demo-brand list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tasks and set Ready for review, with Undo (W2-10)
CHAT-09 §D–E, CHAT-20 §9 rows 43–46, §10a–b, §12. Behind CHAT_AGENTIC.
Tools (lib/chat/registry/action-center-tools.ts, Admins and Managers,
policy Ask (auto allowed in Full auto)):
- create_action (Send to Action Center): its card lists the tasks; a
duplicate check runs before the card (a row's new `precheck`), so an
active action that covers it is said with no card, for Add to AC-{n};
Create anyway only where the entities differ. Undo 24 h while no task
started: the action is cancelled, in its History.
- attach_to_action (Add to AC-{n}): the finding as evidence in History;
the action's targets never change. Undo 24 h.
- attach_file_to_task (Attach only): chat_file_task_links, file attached,
History line. Undo 7 d. The model now gets the file id a change filed.
- set_task_ready_for_review: Chat's status in chat_task_state and a
History line; the task's own status doesn't change. Undo 7 d.
No tool completes, dismisses or edits a task or an action.
Chat: Send to Action Center under the latest answer (Admins, Managers, own
chat); approval cards list a change's items; a new action.sent event shows
"Sent to Action Center · AC-n" / "Added to AC-n" with Open in Actions
(/dashboard/action-center/actions/[id] redirects to its drawer), kept after
a reload; the place (chat, run, approval key, execution.mode) reaches the
write rows.
Action Center: "Attached from Chat" in a task's details (name, who, when,
Open) with a count on the task row; History lines for created from Chat,
attachments, findings, Ready for review and their Undo; kind chat_finding
with its title, finding, goal and a Source: Chat block.
Help: chat, action-tasks and action-center-actions updated.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as any person's send (W2-10) The owner's decision of 2026-10-31: a Chat-created action counts toward the brand's daily five new actions like Improve's, Content's or Mentions' sends. Those are never refused or queued for it: they are made, and the nightly generator opens fewer of its own, the rest waiting in its queue. So: - generate.js counts chat_finding again (the exclusion is taken back), with a test that Chat's sends today leave the generator less room. - POST /api/action-center/chat-actions still always makes the action, and says the day's count (dailyLimit: used, limit, reached) after it. - createChatAction passes on daily_limit_reached and the one sentence Chat says then (chatEngine.actionCard.dailyLimit); create_action's description tells the model to say it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rver (W2-10)
Review follow-ups for Send to Action Center's route (CHAT-09 §E, CHAT-20 §12).
- S1: an action whose tasks can't be written is deleted again, so no action
is left without the tasks the person approved; the same approval tried
again makes it whole.
- S2: the duplicate check reads the competitors a payload names
(competitorIds, competitorId) beside the kept list.
- K3: the chat, the run and how it was approved are read again on the
server (verifiedPlace): the caller's own chat, a run of it, and its step
by the approval key, whose mark says automated. A caller's word alone is
never recorded; executionMode is null when it can't be read.
- K4: an approval whose action was cancelled or deleted since answers 409
conflict instead of "made".
- K5: the routes' 400s carry code invalid.
- K9: a bare word ("pricing", "blog/aeo") is a path on the brand's site,
never a host.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and the Action Center drawer (W2-10)
- B1: Send to Action Center sends the answer's run (fromRunId). The server
reads that run's taint, as for a next move; a run that isn't this chat's,
or an unreadable one, counts as tainted. A change written from an answer
that read outside text shows its card even in Full auto (§16a rule 3).
- S3: create_anyway shows its card in every mode, Full auto included
(alwaysCardWhen, read as overBatch by the precedence): that choice is the
person's (CHAT-09 18a).
- S4: the card shows what is frozen once made: each task with its new text
(shortened, Show all), the finding (why), the goal and the targets
(prompts, pages, competitors, platforms). cardDetails replaces cardItems;
ApprovalCard takes children; copy in chatRun.proposal.
- S5: Undo of a sent action only dismisses it (no deleted_at), so it stays
in Dismissed, with "Cancelled from Chat by {user} · undo" in History; any
event but created since (assigned, edited, a task added, a finding or a
file attached) answers changed.
- S6: conflict is a said refusal: a closed action's or task's words reach
the model.
- K1: a file's title on the card is read within the brand's workspace.
- K3: the server action reads the chat, run and step itself (the step the
engine marks when it ran without a card) and records nothing a caller
only said; Ready for review refuses a task of another brand than its
chat's.
- K5: 403 not_in_workspace / no_brand_access and 409 conflict are said as
such.
- K6: the paperclip says "{n} files attached from Chat" to screen readers.
- K7: unique keys; Open the chat only for a reader who may open it.
- K8: actions/[id] opens the drawer on the action's brand with no filter.
- K10: a finding's note and sources show in History; a withdrawn one says
which finding.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
8 of 13 tasks
# Conflicts: # help/chat/chat.md # web/messages/en.json # web/src/lib/chat/engine.test.ts # web/src/lib/chat/engine.ts # web/src/lib/chat/precedence-context.ts # web/src/lib/chat/registry/define-tool.ts # web/src/lib/chat/registry/tools.test.ts # web/src/lib/chat/registry/tools.ts # web/src/lib/chat/run-state.test.tsx # web/src/lib/chat/run-state.ts # web/src/lib/chat/thread.ts # web/src/lib/chat/undo.ts # web/src/lib/chat/write.test.ts
…eady for review (W2-10) The member reads of actions and action_tasks see the whole workspace, so a person given Selected brands could reach another brand's action. Each of the three server actions now asks can_access_brand first and answers not_found.
…ogged brand's (W2-10) The inverse runs with the service role; it now reads the task with its action's brand and finds nothing when that isn't the brand the change was logged on.
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 31, 2026
Resolves ansvisor#1897's and ansvisor#1900's chat files against main's W2-04..W2-25 work; For you now's Complete tasks chip now types /tasks so the run keeps its task strip, as the PR's Complete with Chat message did.
gkhngyk
previously approved these changes
Oct 31, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Approving, with 2 fixes on top: commits 8ebd130 and a4c4f06. It fast-forwards from this PR's head, with origin/main merged in at e976992.
Merge with main: 13 files conflicted against W2-04/07/19/25. Each one was resolved by keeping both sides:
readEarlierRunskeepsfromTaintedRun, through afromTaintedflag that also setstainted.overBatchCard(tool, input, before)keepsalwaysCardWhen.- Cards carry both
cardNotesandcardDetailsOf. ChatToolContexthas bothchatandpageSites.SAID_FAILUREShas bothnot_connectedand this PR's codes.- The run state, thread, registry, Undo rules, en.json, help and test lists are unions of both sides.
Fixes
8ebd1302b(brand access inlib/actions/chat-action-center.ts):attachToAction,attachFileToTaskandsetTaskReadyForReviewread actions and tasks with the member's own client. Each one now callscan_access_brandfirst and answersnot_foundwhen it fails. Send to Action Center already had this check, because the server route runsassertBrandAccess. Test:brand access (Selected brands)inchat-action-center.test.ts. It fails without the fix.a4c4f0638(Undo scope inundo-action-center.ts): theattach_file_to_taskinverse read the task with the service role and no brand filter. It now reads the task's action brand and answersgonewhen that isn't the logged brand. Test: "takes nothing off a task that isn't the logged brand's". It fails without the fix.
Checked and fine
- Roles: all four rows are WRITE with
minRole: manager. The server actions re-checkisManagerand the route re-checksassertRole(MANAGER_ROLES). - Client input: the chat, run and execution mode are read again on the server (
placeOf/verifiedPlace). A browserfromRunIdfrom another chat counts as tainted. - Card rules: Create anyway always shows a card, and a tainted run shows a card even in Full auto.
- Idempotency: one key per approval step, and a retry after Undo gets a 409.
- Undo: create is cancelled only while untouched, within 24h; withdrawals and detaches are new History events.
- Guards: the demo guard covers both new routes, and
assertWritableis on every write. - Embeds: each one names a single FK, checked against the prod schema.
- Files: the member's read of the file is brand-scoped by RLS.
- Bundle: client components import only types.
Follow-ups (not blocking)
- Chat's
readBrandAccessstill returns'all'. Brand scope in Chat's precedence and card targets (for example the file title on an attach card) waits on that global change. attachToActionhas no idempotency key, so a retried approval could add the finding twice. Keying the event on the approval step would close this.- Two concurrent sends with the same key: the second returns
duplicateof the first instead of the same action. This is harmless.
Tests
- Web vitest:
src/lib/chat,src/components/chat, action-center (lib, components, pages),src/lib/actions,subscription-guard-coverage,demo-gate-routes,src/lib/guards(plan-row) andsrc/lib/helpall pass. The exception is two engine "who may do what" cases that time out at 5s under full-suite load. They pass alone, at 10s and 3s. - Web
tsc --noEmitis clean, and eslint and prettier are clean on touched files. - Server: the suite passes except 8 timing-only cases (page-content, content-agent, content-people, audit, traffic-events). Prettier and eslint are clean on the touched server files.
gkhngyk
approved these changes
Oct 31, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 31, 2026
Resolves help/chat/chat.md keywords, thread.ts imports and thread.test.ts against the squashed ansvisor#1897/ansvisor#1900 on main.
Merged
8 of 13 tasks
8 of 13 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Nov 1, 2026
…click repeats (#1935) Follow-ups from the approval notes on #1897, #1902 and #1898. - Add to AC-{n} (attachToAction, W2-10): the evidence_attached event carries its approval's key (`chat:{step}`, as Send to Action Center's payload does), and a retried approval finds that event and returns it instead of adding the finding again. Two calls at the very same moment are already kept apart by the engine's idempotency claim; a database-level guarantee would need a unique index (a migration), not added here. - Card clicks (W2-12): Attach to task & mark done and its Undo write the task's status only when it really changes (`.neq('status', …)` through writeTaskStatus's new onlyIfChanged), so two clicks at once leave one History event. The drawer's own writes are unchanged. - Attach only from a card now records the card's chat and run on its file_attached event, as a mark done's event does. attachFileToTask takes the card's place and reads it on the server (the person's own chat and a run of it) before recording it; no execution mode, as it is the person's own click. - Daily suggestions (W2-26): recordUse skips a removed suggestion (no use, no feed stamp), and the page's last Site Audit matches the action's pages by pageKey (no scheme, www or trailing slash), by the audit's url or final_url, among the brand's latest 500 audits (as the server's recheck reads them). - The test fake reads JSON-path filters (`data->>key`) as PostgREST does. Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
8 of 13 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Chat W2-10 adds four things, each with Undo:
Specs: CHAT-09 §D–E, CHAT-20 §9 rows 43–46, §10a–b and §12. Built on main. Everything stays behind
CHAT_AGENTIC/CHAT_AGENTIC_ORGS. No migration.Server (
server/src/routes/action-center.js,lib/action-center/from-chat.js)POST /api/action-center/chat-actions/checklists the brand's active actions that already cover a finding's prompts, pages or competitors, closest first. It compares the action's kept list (00244), the prompts and pages its payload names, and the competitor ids it names.POST /api/action-center/chat-actionssaves the finding as an action of kindchat_finding, withpayload.source: 'chat', the chat, the run andexecution.mode(assisted or automated).duplicatewith that action. Create anyway is offered only when the entities differ.tasks_generated_atis set, so the task writer never rewrites them.dailyLimit), and Chat says one sentence when the day is full.conflict;pricingis a path on the brand's site, never a host.Chat (
web/src/lib/chat/registry/action-center-tools.ts)The tools are for Admins and Managers, with policy Ask (auto allowed in Full auto). No tool completes, dismisses or edits a task or an action.
create_action(Send to Action Center)changed.attach_to_action(Add to AC-{n})attach_file_to_task(Attach only)chat_file_task_links, attaches the file and adds a History line.set_task_ready_for_reviewchat_task_stateand adds a History line. The task's own status doesn't change.fromRunId). The server reads that run's taint.action.sentevent shows "Sent to Action Center · AC-n" or "Added to AC-n", with Open in Actions. It is kept after a reload./dashboard/action-center/actions/[id]opens the drawer on the action's brand with no filter.Action Center
chat_findinggets its title, finding, goal and a Source: Chat block. The decision of 2026-10-31 approved the drawer list, "Source: Chat" and the paperclip count.Help:
help/chat/chat.md,help/action-center/action-tasks.mdandhelp/action-center/action-center-actions.md(approved: false).Related issue
None. Chat Wave 2 (W2-10).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
CHAT_AGENTIC=truein web and server. Sign in as an Admin.from-chat.test.js,action-center-chat.test.js,generatetests;action-center-tools,chat-action-center,undo-action-center,engine.test,action-drawer,proposal-details, theactionsandactions/[id]pages.Screens checked in the browser at 1024px, light and dark, and approved by the user. Screenshots are available on request.
Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)On this branch:
format:checkandtypecheckpass, and lint has 0 errors. 760 files / 7,693 tests: 7,692 pass. The one failure ischat-menu.test.tsx"Done · 08:02", a date-dependent case that fails on main today too and is fixed by fix(chat): give a chat row the menu's clock, so a run's time matches its day #1876.yarn buildpasses.format:checkand lint are clean, and 335 files / 4,618 tests pass (3 skipped).For production (@gkhngyk): deploy the server first, then the web. The web tools call the new
/api/action-center/chat-actionsroutes.Follow-ups, not in this PR:
🤖 Generated with Claude Code