.md file to compare - side-by-side diff against email-send-tick
email-send-tick
description: "Triggers on prompt mention of 'email-send-tick'."
What it does for you
Sends your approved email drafts on time and retries any that hiccup.
What it produces
A recent result, so you can see the kind of work it returns.
loading…
How to get it
These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.
For developers how this skill is built, graded, and how it runs
at a glance- the short version
what's inside - the parts that make up a skill 2/4 present
A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.
state/skills/email-send-tick/SKILL.md
present
state/lib/email-send-tick.ts
not present
state/bin/email-send-tick/
not present
state/skills/email-send-tick/AGENTS.md
present
how it's graded - what counts as a good run 6 criteria · 6 deterministic
Each row is one thing a good run has to get right. deterministic means a quick check decides, pass or fail. judge means the AI reads the result and rates it. Grading each piece on its own (instead of one overall score) shows exactly where a run fell short, so the fix is obvious.
how it runs - the shared frame every skill uses 5/5 present
Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.
state/log/evals.ndjson what it has learned - fixes written back in over time sample
When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.
- Loading feedback rows…
how the work flows- who makes it, who checks it
what this step does
SKILL.md- the skill, written out in plain English
Backed by: state/bin/email-send-tick.ts, state/lib/email.ts (read-side: queue + sendEmailDraft).
email-send-tick
The consumer half of snappy-os's scheduled-send pipeline. Producers append rows to state/log/email-send-queue.ndjson via scheduleSendDraft({...}). This skill (LaunchAgent-driven, every 60 s) reads the queue, finds rows where status == "scheduled" AND sendAt <= now, and sends them via sendEmailDraft(draftId, account). Atomic queue rewrite (temp + rename); idempotent on a per-tick basis.
Producers today: meeting-followup. Future: any skill that needs deferred client-comm send. The contract is the queue row shape, not the producing skill - adding new producers requires no change here.
Steps
1. Read the queue
const lines = readFileSync("state/log/email-send-queue.ndjson", "utf8").split("\n").filter(Boolean);
const rows = lines.map(l => JSON.parse(l));
const now = new Date();
const ready = rows.filter(r => r.status === "scheduled" && new Date(r.sendAt) <= now);
2. Honour the global kill switch
if (process.env.SNAPPY_EMAIL_AUTO_SEND_DISABLED === "1") {
// log a no-op tick + exit cleanly
score("email-send-tick", run_id, { score: 1.0, primary_issue: "kill-switch-active", sent: 0, ready: ready.length });
process.exit(0);
}
3. For each ready row - send, veto, or retry
for (const row of ready) {
try {
const sent = await sendEmailDraft(row.draftId, row.account || "work");
row.status = "sent";
row.sent_message_id = sent.id;
appendNdjson("state/log/email-sent.ndjson", { ts: now.toISOString(), ...row, sent_message_id: sent.id });
} catch (err) {
if (is404(err)) {
// Veto: Robert deleted the draft in Gmail before the window expired.
// Not an error — the user explicitly declined.
row.status = "vetoed";
row.error = "draft not found (Gmail 404 — likely deleted or already sent)";
} else if (isTransient(err) && (row.retry_count ?? 0) < 3) {
// Network blip / 5xx / rate-limit. Bump retry count, leave status="scheduled" — next tick retries.
row.retry_count = (row.retry_count ?? 0) + 1;
appendNdjson("state/log/email-send-errors.ndjson", { ts: now.toISOString(), draftId: row.draftId, error: errMsg(err), retry_count: row.retry_count });
} else {
// Permanent failure OR retry cap reached.
row.status = "failed";
row.error = errMsg(err);
}
}
}
4. Atomic queue rewrite
const tmp = `state/log/email-send-queue.ndjson.tmp.${process.pid}`;
writeFileSync(tmp, rows.map(r => JSON.stringify(r)).join("\n") + (rows.length ? "\n" : ""));
renameSync(tmp, "state/log/email-send-queue.ndjson");
Never leave a half-written queue - partial writes corrupt the next tick's read. If the rename fails, the original file is intact.
5. Score
const score = (sent_count > 0 || ready.length === 0) ? 1.0 : 0.0;
const primary_issue = failed_count > 0 ? `failed:${failed_count}` : transient_errors > 0 ? `transient:${transient_errors}` : null;
score("email-send-tick", run_id, { score, primary_issue, sent: sent_count, vetoed: vetoed_count, failed: failed_count, ready: ready.length, transient_errors, queue_size: rows.length });
Eval
Actor: the queue-read + send loop (run_id-bound process). Auditor: independent re-read of the queue file from disk after the rewrite, confirming each row that the actor claimed to send has status: "sent" and a sent_message_id. Auditor uses a different session id (<actor_session>-auditor-<pid>-<ts>).
| Outcome | Score | primary_issue |
|---|---|---|
ready === 0 (idle tick) | 1.0 | null |
sent > 0, no failures | 1.0 | null |
sent > 0, some transient (still in-queue) | 0.5 | transient:<n> |
failed > 0 | 0.0 | failed:<n> |
| Auditor disagrees with actor counts | 0.0 | actor-auditor-mismatch |
| Kill switch active | 1.0 | kill-switch-active |
Gotchas
- Atomic write or nothing. A non-atomic rewrite (write directly to
email-send-queue.ndjson) corrupts the queue if the process is killed mid-write. Always temp + rename. - Veto path is NOT an error. Gmail 404 on
drafts.sendmeans the user (or another process) deleted the draft. Markstatus: "vetoed", no retry, no friction. The veto window is the whole point of the design. - Retry cap = 3. Beyond that,
status: "failed"and stop. Don't loop forever - failed rows surface in the queue file for human review. - Don't send rows where
apply: trueis missing on the producer side. The queue contract assumes the producer already gated. This consumer is just executing scheduled work; it does not re-validate. - Per-account credentials. Default
account: "work"(service-account JWT forrobert@snappy.ai). Foraccount: "personal", the OAuth refresh token in.env.cacheresolves the token - same auth path ascreateEmailDraft. - The kill switch is belt-and-suspenders.
SNAPPY_EMAIL_AUTO_SEND_DISABLED=1halts sends but the LaunchAgent still ticks (so the audit trail keeps flowing - easier to verify the switch is honoured).
Install (LaunchAgent)
cp state/launchd/com.snappy.email-send-tick.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.snappy.email-send-tick.plist
launchctl list | grep email-send-tick # confirm loaded; second column is exit status of last run
To pause without uninstalling:
launchctl unload ~/Library/LaunchAgents/com.snappy.email-send-tick.plist
Or set the kill switch globally:
launchctl setenv SNAPPY_EMAIL_AUTO_SEND_DISABLED 1
To resume: unset (launchctl unsetenv SNAPPY_EMAIL_AUTO_SEND_DISABLED) or launchctl load.
Rubric
criteria:
- name: queue_atomic_rewrite
kind: deterministic
check: "After every tick, state/log/email-send-queue.ndjson is either the original file or the new file — never partially-written. Verified by file size monotonicity within a tick."
- name: ready_rows_processed
kind: deterministic
check: "Every row that satisfied (status=scheduled AND sendAt<=now) at tick start has status != scheduled at tick end."
- name: sent_rows_have_message_id
kind: deterministic
check: "Every row with status=sent has a non-empty sent_message_id field; every such id appears in state/log/email-sent.ndjson with matching draftId."
- name: vetoed_marked_not_failed
kind: deterministic
check: "Gmail 404 responses are recorded as status=vetoed, NOT status=failed. Verified by inspecting error strings on vetoed rows."
- name: kill_switch_honoured
kind: deterministic
check: "When SNAPPY_EMAIL_AUTO_SEND_DISABLED=1, no row's status changes from scheduled to sent in that tick."
- name: actor_auditor_distinct
kind: deterministic
check: "actor_session_id and auditor_session_id on the eval row are non-empty and differ — proves actor != auditor."AGENTS.md- what the AI loads when this skill comes up
email-send-tick - loader
Per-turn rules for the email-send-tick skill. The minute-cron consumer of state/log/email-send-queue.ndjson - sends drafts whose veto window expired, marks vetoed / failed / transient, retries transient errors up to 3x. Atomic queue rewrite (temp + rename); idempotent per tick. Backed by state/bin/email-send-tick.ts + state/lib/email.ts (read-side: queue + sendEmailDraft). Full reference: state/skills/email-send-tick/SKILL.md. Do not skip these.
Critical Rules
- HONOUR THE KILL SWITCH FIRST. Check
process.env.SNAPPY_EMAIL_AUTO_SEND_DISABLED === "1"at the top of every tick. If set, log a no-op eval row withprimary_issue: "kill-switch-active"and exit. No reads, no sends. - ATOMIC QUEUE REWRITE OR NOTHING. Always write to a temp path (
state/log/email-send-queue.ndjson.tmp.<pid>) thenrename. Direct writes corrupt the queue if the process is killed mid-write. - GMAIL 404 IS A VETO, NOT A FAILURE. When
sendEmailDraftthrows a 404, the user (or another process) deleted the draft before the window expired. That is the whole point of the design. Markstatus: "vetoed", no retry, no friction row. - RETRY CAP = 3. Transient errors (network, 5xx, rate-limit) bump
retry_countand leavestatus: "scheduled". Past 3 retries →status: "failed", stop. - DON'T VALIDATE PRODUCER GATING. This consumer assumes
apply: truewas already gated on the producer side (e.g.meeting-followuponly schedules oneval=1.0). The consumer is execution, not policy. - ACTOR ≠ AUDITOR. The actor session id is
email-send-tick-<run_id>; the auditor session id includes pid + ms timestamp. Both must appear on the eval row, distinct. - NEVER REORDER ROWS IN THE QUEUE. Mutate row fields in place; preserve insertion order so
tail -nalways shows the most recent activity at the end.
Commands
| ui dashboard | state/skills/email-send-tick/resources/ui.openui | |invoke (manual): npx tsx state/bin/email-send-tick.ts |sidecar: state/bin/email-send-tick.ts |launchd plist: state/launchd/com.snappy.email-send-tick.plist |install: cp state/launchd/com.snappy.email-send-tick.plist ~/Library/LaunchAgents/ && launchctl load ~/Library/LaunchAgents/com.snappy.email-send-tick.plist |kill switch (global): launchctl setenv SNAPPY_EMAIL_AUTO_SEND_DISABLED 1 - unset to resume |pause without uninstall: launchctl unload ~/Library/LaunchAgents/com.snappy.email-send-tick.plist |queue: state/log/email-send-queue.ndjson (in-flight rows, all statuses) |sent log: state/log/email-sent.ndjson (append-only, every successful send) |error log: state/log/email-send-errors.ndjson (append-only, every transient/failed) |eval log: state/log/evals.ndjson (skill: "email-send-tick")
Producers (who writes to the queue)
| Producer skill | When | Eval-gate threshold |
|---|---|---|
meeting-followup | After createEmailDraft() succeeds | eval = 1.0 (no partial sends) |
To add a new producer: import scheduleSendDraft({draftId, sendAt, recipient, subject, account, meta}) from state/lib/email.ts, gate on the producer's own eval, append. The queue contract is the row shape, not the producer name.
Score Table
| Outcome | Score | primary_issue |
|---|---|---|
ready === 0 (idle tick) | 1.0 | null |
sent > 0, no failures | 1.0 | null |
sent > 0, some transient (still in-queue) | 0.5 | transient:<n> |
failed > 0 | 0.0 | failed:<n> |
| Auditor disagrees with actor | 0.0 | actor-auditor-mismatch |
| Kill switch active | 1.0 | kill-switch-active |
Self-Test
An agent reading this should correctly:
- [ ] Honour
SNAPPY_EMAIL_AUTO_SEND_DISABLED=1before any queue read? - [ ] Distinguish Gmail-404 (veto) from other 4xx (failure) on send error?
- [ ] Atomic-rewrite the queue file (temp + rename), never direct-write?
- [ ] Cap retries at 3 then mark
status: "failed"? - [ ] Emit a distinct
actor_session_idandauditor_session_idon the eval row?
Self-report
If this loader fell short, append a line:
echo "[$(date -u +%FT%TZ)] email-send-tick: <what was missing or fixed> [FIXED|LOGGED] action_kind=<kind>" >> state/log/loader-feedback.log
<!-- kernel-ok: historical attribution for the PID-loader pattern. -->
Self-correcting loader (PID feedback)
This is the rule that makes loaders learn. Ported from snappy-kernel, where it demonstrably worked: the snappy-dom-cartographer skill mapped Skool admin UI once, every later ship-agent inherited the full map for free.
Before you finish, do two things:
1. Fix gaps (P - proportional). MANDATORY. If this loader didn't cover your case - if you had to read another file, run an undocumented command, work around a wrong selector, or discover a quirk - you MUST attempt an Edit to this AGENTS.md before you log.
- Default action: edit this file. Surgical. Add the missing line, table
row, or code example where it belongs. No restructuring.
- Only
LOGGEDis allowed when: the fix needs >10 lines, spans multiple
files, or requires a structural rewrite. In that case the state/regen/drain.sh queue picks it up asynchronously.
- "I didn't have time" / "it's minor" / "the next agent will figure it out"
are NOT valid reasons. Minor gaps compound - that's the whole point of this loop.
- Concrete example of a valid P-fix: discover
agent-browser screenshot
takes path positionally not as --output <path>. One line in a table. Edit it in. Do not just log it.
- The goal: the next agent never has to leave the loader.
2. Log the result.
echo "[$(date -u +%FT%TZ)] email-send-tick: <what was missing or fixed> [FIXED|LOGGED] action_kind=<kind>" >> state/log/loader-feedback.log
<slug>MUST be the literal folder name of this loader
(state/skills/<slug>/AGENTS.md). The class token between [ts] and : is the producer slug, the writeback class, AND the grade class - they must be equal so state/lib/controller-tune.ts can pair the brief.
FIXED= you patched this loader inline (P-fix).LOGGED= too large for inline; the PostToolUse enqueue + Stop-hook drain
will rewrite the loader from scratch on next session-end.
action_kindis the SECOND pairing predicate (added 2026-04-27, task #327).
Pick the value that describes what you actually did - same slug, different action_kind means the writeback satisfies a different brief layer:
shape-ok- only frontmatter-shape verification passed (rare from
a human; usually emitted by the lint, not a loader echo)
skill-ran- the skill ran end-to-end and an eval row landed
in state/log/evals.ndjson
loader-rewritten- you EDITED this AGENTS.md inline (the FIXED case),
OR the regen drain rewrote it
pattern-elevated- you promoted a recurring failure to a Critical Rule
(rule fix or new-skill scaffold) If you LOGGED (couldn't fix inline), omit action_kind - the inferrer will pick it up from your body keywords.
Do not skip this. Every agent run must leave the system better than it found it. The loader is the setpoint; you are the sensor; the gap is the error signal; closing the gap is the correction.
OpenUI Resource
- Skill-owned OpenUI Lang resource:
state/skills/email-send-tick/resources/ui.openui. Read it before rendering or editing this skill's generated component surface. - Treat this resource as a first-class artifact of the skill, not a generic chat response. Improve it when the skill's user-facing output needs to become richer.
- System resources compose OpenUI primitives and inherit SnappyChat tokens. Use
ui_contract: brandedin SKILL.md only for deliberate platform or client visuals.
api.ts- the code it can call
⚠ no api.ts - this skill has no typed action surface
scripts- helper scripts it can run
prose-only skill - 9 inline code blocks live in SKILL.md above (no state/bin/ sidecar yet).
how we check it- the checks, plus the last 10 runs
| timestamp | verb | score | primary_issue | artifact |
|---|---|---|---|---|
| 2026-05-03 15:29Z | - | 1.00 | - | - |
| 2026-05-03 13:29Z | - | 1.00 | - | - |
| 2026-05-03 11:29Z | - | 1.00 | - | - |
| 2026-05-03 09:29Z | - | 1.00 | - | - |
| 2026-05-03 07:29Z | - | 1.00 | - | - |
| 2026-05-03 05:29Z | - | 1.00 | - | - |
| 2026-05-03 03:28Z | - | 1.00 | - | - |
| 2026-05-03 01:28Z | - | 1.00 | - | - |
| 2026-05-02 23:28Z | - | 1.00 | - | - |
| 2026-05-02 21:28Z | - | 0.00 | - | - |