Repository navigation
feat(chat): turn "every Monday at 9" into an editable schedule card (W3-02) - #2014
Merged
Merged
Conversation
…3-DB, 00457–00459) Chat's Wave 3 tables in one PR (one DB PR per wave), behind CHAT_AGENTIC: nothing reads or writes them while the flag is off. Tables, types, tests and the demo's coverage only; the code that uses them comes in W3-01, W3-06 and W3-11. Every new table has row level security on; members only ever read, anon gets nothing, and every write is the server's. - 00457: chat_schedules (CHAT-12): once, recurring or a follow-up check; run at / ready by, due and next run, the RRULE and time zone; title, prompt or skill, the brand fixed at creation, the creator it acts as and its own chat; delivery to chat and/or email, recipients only people of the workspace (a trigger checks), change-only with the last fingerprint; mode, model, effort; on/off with the reason, failures in a row, the one retry; a follow-up check's target, metric and who set it (card or full_auto, the latter only for follow-up checks). A job whose brand or creator is deleted turns off (missing_source, owner_role) instead of running on without them. chat_schedule_runs: slot and attempt (unique, so a slot never runs twice), Run now, the Chat run and answer, status, parts done, fingerprint, usage as a share, email outcome. chat_conversations.schedule_id with origin 'schedule' (one live chat per job; it stays the creator's), prompt_improve_usage.schedule_id, and reserve_chat_ai_usage taking p_schedule_id (default null, old calls still match): the row is named by the chat's job, a job that isn't the chat's is refused. Creator and Admins read a job, within their brands. - 00458: chat_skills (CHAT-13): name unique in the workspace in the format's rules, body up to 50 KB, licenses MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC (an import needs one), source user or import with the pinned commit and checksum, scan and removed parts, review status (only an approved skill can be on), private or workspace. Private or unapproved: creator and Admins; approved workspace skills: every member. chat_settings.disabled_skills for library skills. - 00459: chat_memory_items (CHAT-14): Me, brand and workspace lines, 1–300 characters, at most 4,000 a scope (a trigger under a lock per scope, deleted lines left out), one profile line a person, deleted_at for Undo; brand lines go with the brand, Me lines with the account and when the person leaves the workspace (trigger on profiles). Me: only its person; brand lines: brand access; workspace lines: every member. chat_settings.memory_enabled and chat_user_prefs.memory_enabled, both on. web/src/types/supabase.ts carries the new tables and columns; schema.test.ts checks the Wave 3 policies, limits, vocabularies, triggers and the hold's signature from the SQL; brand-access-policies.test.js lists the new tables; the demo coverage skips chat_schedules and chat_memory_items. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-09) Each / menu shortcut (CHAT-08) now has a hidden playbook in skills/ (metadata.hidden: "true"): its allowed reads, default scope, output, question rules and next moves, checked by the same format, scan and CI as the library skills. The menu gains /start, /optimize, /opportunities and /audit; "Create a report on" moves to /new-report, as /report is the Weekly report skill's. The composer sends shortcutId with the message while its trigger words stay (rewritten, it drops), and keeps it on Retry. Home chips whose job is a shortcut's send its id; chips for the focus areas' skills ask with the skill's /name. The server takes the id only for a message that is still that shortcut's, writes chat_messages.shortcut_id, loads the playbook first as one of the run's three skill bodies, offers only the reads in its data plan, and tells the model in one line what the plan leaves out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt (W2-03)
Before work in several like parts (drafts, pages, tasks), the model calls
the engine's plan_parts with how many; the server counts how many the AI
limit left covers (fitChatUnits and POST /api/internal/chat/budget/fit,
each part one write step's worst case, an agent run's own cap included):
a count, never dollars.
All covered, the work goes on. None, the run pauses at the AI limit as
before. Some, a question card asks "Your remaining AI limit covers about
{k} of the {n} ...": Do the first {k} now (Recommended), Get more AI
credits (pauses at the limit) or Cancel (stops). With no one there (an
agent's or a scheduled run), the first {k} are done and filed and the run
stops at the AI limit as it ends. A skill's run is checked as it starts,
before anything is read. Nothing is checked on the workspace's own key.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…duled jobs Move the RRULE subset (DAILY/WEEKLY/MONTHLY on a zone's clock) from agent-schedule.ts to schedule/rule.ts, which agent-schedule.ts re-exports, and add nextJobRun for a chat_schedules row. Extract openHeadlessRun (headless-run.ts) from openAgentRun: the chat, the message, the answer, the Chat run and its state, written in the same order; agent runs use it unchanged. No behaviour change: the agent tests pass as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat's scheduled jobs (CHAT-12) now run by themselves, behind CHAT_AGENTIC. The server's minute cron calls the new /api/internal/chat/schedules/tick (CHAT_INTERNAL_SECRET) right after the agents' tick; it settles open runs, resumes jobs the AI limit paused and runs the due ones (schedule/worker.ts): - A due job is claimed by moving next_run_at (or retry_at) from what was read, so two workers run a slot once; chat_schedule_runs' unique slot and attempt is the backstop. A recurring slot over an hour late is skipped (no catch-up); a busy workspace waits for the next minute. - Each run re-checks its creator: Admin or Manager and the brand still theirs (else owner_role), brand there (missing_source), skill on (skill_off), AI limit (paused_cap, the job pauses at cap). A read-only workspace skips the slot; with Chat off nothing is touched. - The run opens in the job's own chat as its creator (openHeadlessRun), Queued then claimRunSlot, always Auto · Normal, with no session, so every change waits as a card. - A failed run retries once 10 minutes on; 3 failures in a row turn the job off. After the reset a cap-paused job goes on at its next slot. Engine (thin hooks): a job's own run is metered as feature 'schedule' with its scheduleId (budget.ts meteredAs; the server passes p_schedule_id), and a question in it takes the Recommended option and lists it at the top of the answer (schedule/unattended.ts). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…worker Co-Authored-By: Claude Opus 5.5 <[email protected]>
…W3-02)
- schedule/when.ts reads a date phrase on the person's clock: 09:00 for a
day with no time, working days only when said, ready by vs run at, the
RRULE subset for repeats (at most once a day), and ambiguous phrases
("next Friday", "the 31st") returned with their likely dates for a
question card. CHAT-12's acceptance examples are its tests.
- create_schedule registry row (Scheduling area, row 78): WRITE, Ask, a
card in every mode, Admins and Managers; its precheck refuses what
won't read, a skill that's off and a full plan (Trial 1 · Starter 5 ·
Growth 25 · Enterprise 100 active jobs; follow-up checks don't count).
It runs through a session server action and logs with a 30-day Undo
that deletes the job.
- A reusable editable approval card: ChatConfirm.form, FormCard and the
row hooks form/stepKind/doneStep. The Approve sends the edited values;
the server applies them and checks them against the row's schema
before the change runs. W3-08 and W3-12a reuse it.
- The schedule step shows "Scheduled: {title}" with when and where.
- The card's usage line comes from a new internal estimate route (the
workspace's average Chat run over 30 days, as a share; never dollars).
- Help article help/chat/scheduling.md (approved: false).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-card # Conflicts: # server/src/routes/internal-chat-budget.js # server/src/routes/internal-chat-budget.test.js
Merged
8 of 13 tasks
This was referenced Nov 2, 2026
gkhngyk
requested changes
Nov 2, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
One fix needed; two smaller notes.
Finished one-time jobs keep counting toward the plan's limit. countActiveSchedules (schedule/store.ts:58-67) counts enabled = true. After a one-time job runs, the worker only sets next_run_at to null (worker.ts:363), and the job stays enabled. On a Trial (limit 1), "tomorrow at 3pm" runs once, and every later create_schedule is refused as quota_exceeded until the person deletes the finished job. #2018's "{n} of {limit} jobs on" and the menu badge count it too.
Fix: count only live jobs (next_run_at or retry_at not null), or turn a one-time job off once its run settles, with its own paused_reason.
Smaller:
- The count and the insert are separate steps (
store.ts:174-178, insert at :219), so two Creates at the same moment can go one over the limit. createChatSchedule(lib/actions/chat-schedules.ts:46-54) is a server action that doesn't run the tool's zod schema. Called directly, it skips the card and an Admin's "Never" policy, and bad input throws (title.trim()on a non-string, adelivervalue the DB rejects). Parse with the tool's schema inside the action.
…heck hits
The fit check (fitChatUnits) took the smaller of what is left of the
month's AI limit and what an agent run's own cap leaves, but only returned
the count. The engine then paused every new cap path (a skill's run that
can't start, a job none of whose parts fit, Get more AI credits, and the
parts done with no one there) at the month's limit. For a triggered run
stopped by its own cap, the agent driver read capHit 'month' and paused
the whole agent until the month resets instead of ending the run as
"Stopped at its limit".
The server now returns which limit binds ('run' when the run's cap leaves
no more than the month, as reserveChatStep's run_cap), the route passes it
on, and the web client reads it (the month's when absent). The engine
pauses with that limit, keeping it on the parts card and on limitStop, as
modelStep already does for run_cap refusals.
…e input A one-time job that has run stays enabled with no next run, so it kept counting toward the plan's job limit: on a trial every later schedule was refused until the finished job was deleted. The limit now counts live jobs only, enabled with a next run or a retry still to come. The count and the insert were separate steps, so two creates at once could go one over the limit. After the insert the new job must be among the first `limit` live jobs, oldest first; otherwise it is deleted and the create is refused as quota_exceeded. Both racers see the same order, so exactly one of them keeps the last place. No schema change. createChatSchedule is a server action and can be called with anything. It now parses the job with the create_schedule tool's schema (moved to schedule/input.ts so the action and the tool share it) and the run's place with a small schema, refusing bad input as invalid before any check or write. The test fake's or() gains `column.not.op.value` terms.
# Conflicts: # server/src/routes/internal-chat-budget.test.js
8 of 13 tasks
# Conflicts: # help/chat/chat.md # server/src/lib/chat-budget.test.js # server/src/routes/internal-chat-budget.js # server/src/routes/internal-chat-budget.test.js # web/messages/en.json # web/src/lib/chat/engine.test.ts # web/src/lib/chat/engine.ts
# Conflicts: # server/src/lib/brand-access-policies.test.js # server/src/lib/chat-budget.js # supabase/schema.sql # web/src/lib/chat/agent-driver.ts # web/src/lib/chat/schema.test.ts # web/src/types/supabase.ts
# Conflicts: # server/src/lib/chat-budget.js # server/src/lib/chat-budget.test.js # server/src/routes/internal-chat-budget.js # web/src/lib/chat/engine.test.ts # web/src/lib/chat/engine.ts
gkhngyk
previously approved these changes
Nov 2, 2026
8 of 13 tasks
# Conflicts: # help/chat/chat.md # server/src/routes/internal-chat-budget.js # server/src/routes/internal-chat-budget.test.js # web/messages/en.json # web/src/lib/chat/engine.test.ts # web/src/lib/chat/engine.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/schedule/worker.test.ts # web/src/lib/chat/schedule/worker.ts # web/src/lib/chat/undo.ts
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
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
"Every Monday at 9:00, send me the weekly report" now ends in an editable confirm card, and the job is made only when the person clicks Create schedule (CHAT-12 items 1–9), behind
CHAT_AGENTIC. Stacked on #2003 (W3-01, with W2-09 and W2-03; W3-01 is on #1990): merge those first; conflicts already resolved. No migration, no new env var. Plan: Chat waves plan, W3-02.Reading the date (
lib/chat/schedule/when.ts, pure)schedule/rule.ts(daily, weekdays, weekly on days, monthly on 1–28 or the last day), at most once a day.ambiguouswith its likely dates as phrases that read back. A past time, one more than a year away, or more than once a day is refused with its reason.2026-10-19T06:00Z; 3 working days → Wed 21 Oct; every Monday at 9:00 in New York across the DST change).The
create_scheduleregistry row (CHAT-20 §9 row 78, new Scheduling area)always_card; an Admin may set Never, never Always), Admins and Managers, no MCP tool.maxActiveSchedules; follow-up checks don't count).lib/actions/chat-schedules.ts:assertWritable, demo brand refused) and writes the job with the service role after the same checks: brand fixed, created by the person,modeauto, always Auto · Normal,created_viacard,set_by_run_id.schedulestep: Scheduled: {title} with "{when} · {deliver to}" (ready-by: "Due … · Starts now · …").A reusable editable card (W3-08 and W3-12a use it next)
ChatConfirm.form(events.ts): fields (text, textarea, choice, toggle), its button and notes. Row hooks indefine-tool.ts:form.fields/form.apply,stepKind,doneStep.components/agentic/form-card.tsx(FormCard): the approval card's look, live help as the person types (run/form-assist.ts: the When line with the next run, change-only only on a repeat), button off while a field is missing or doesn't read, read-only gate.prepareResumeapplies them and checks them against the row's input schema (lib/chat/card-form.ts) — a refusal keeps the card (400 with the card's own words). The digest stays bound to what the card was sent with.engine.tsgets only thin hooks.The usage line comes from a new internal route,
GET /api/internal/chat/budget/run-estimate(server,CRON_SECRET): the workspace's Chat and scheduled runs over the last 30 days, each run's spend averaged, over the plan's included budget, as a share. Never dollars; own-key workspaces see "Runs on your workspace's own AI key".Help: new
help/chat/scheduling.md(approved: false).Related issue
None. Chat waves plan, Wave 3 (W3-02).
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
With
CHAT_AGENTICon, as an Admin or Manager in a chat:chat_scheduleswith your edits. The Activity log has it with Undo (deletes the job).Screenshots (1024 px, light and dark) are in the PR comment.
Checklist
yarn lintpasses (changed files: 0 errors)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)Run locally: web — format:check, eslint on the changed files, typecheck, and 59 test files / 1,266 tests (Chat registry, engine, undo, write, events, precedence, access, components/chat, components/agentic, schedule, card-form, help, subscription-guard coverage, agent driver/triggers, schema). Server —
chat-budgetandinternal-chat-budgettests (57). Full CI runs on the fork.Screens: shown to the owner in a local preview (1024px, light and dark, with preview data) and approved on 2026-11-02.
CI passed on this branch (be70be1), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41440869426): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code