How the Pre‑Send Check Works in the i‑have‑adhd OpenCode Plugin
The pre‑send check in i‑have‑adhd is a runtime validation hook that executes just before a response is delivered to the user, enforcing ADHD‑friendly formatting rules defined in the skill specification.
The ayghri/i-have-adhd repository implements a specialized OpenCode plugin designed to make AI assistant outputs more accessible for users with ADHD. At the heart of this system lies the pre‑send check mechanism—a gatekeeper that intercepts generated responses and validates them against a strict set of accessibility rules before they ever reach the user.
What Triggers the Pre‑Send Check
The pre‑send check fires automatically for every outgoing message. According to the plugin architecture, the check is registered through the hook system in hooks/always-on.mjs, which loads the .opencode/plugins/i-have-adhd.mjs plugin and binds the validation routine to the runtime's pre‑send event.
This design ensures zero manual intervention—developers don't need to explicitly call validation; it happens transparently on every response path.
The Core Validation Logic in .opencode/plugins/i-have-adhd.mjs
The preSendCheck function in .opencode/plugins/i-have-adhd.mjs serves as the implementation entry point. When invoked, it receives the raw LLM output and executes a multi‑stage validation pipeline:
import { preSendCheck } from './.opencode/plugins/i-have-adhd.mjs';
// rawResponse contains the unfiltered output from the language model
async function sendResponse(rawResponse) {
const validated = await preSendCheck(rawResponse);
if (!validated.ok) {
// Recursively regenerate until validation passes
return sendResponse(await regenerateResponse());
}
// Only after successful validation is the response transmitted
client.send(validated.text);
}
Validation Steps
- Token boundaries – Verifies the response respects runtime length limits.
- Rule compliance – Applies all ten ADHD‑friendly formatting rules from
skills/i-have-adhd/SKILL.md. - Safety screening – Blocks disallowed content including unsafe suggestions or copyrighted material.
- Auto‑correction – Attempts to trim or rewrite violations rather than failing outright.
- Final approval – Returns
{ ok: true, text: sanitizedOutput }or triggers regeneration.
The Rules Engine: skills/i-have-adhd/SKILL.md
The pre‑send check derives its validation criteria from skills/i-have-adhd/SKILL.md, which codifies ten specific accessibility rules. Here is a representative rule the validator enforces:
1️⃣ **Keep sentences short** – No sentence should exceed 20 words.
When preSendCheck parses a response, it counts words per sentence using boundary detection. If any sentence exceeds the 20‑word threshold, the validator flags the violation, applies sentence splitting or rewriting, and re‑validates before allowing transmission.
Additional rules in SKILL.md govern:
- Jargon avoidance – Technical terms must be defined inline or eliminated.
- Structure density – Limits on nested lists and paragraph length.
- Visual breaks – Mandatory use of emojis or separators for cognitive chunking.
Hook Registration and Runtime Integration
The hooks/always-on.mjs file serves as the integration layer between the plugin and the OpenCode runtime. It registers the pre‑send hook during initialization:
// Simplified structure based on hook registration pattern
import { preSendCheck } from '../.opencode/plugins/i-have-adhd.mjs';
export default function registerHooks(runtime) {
runtime.on('preSend', async (context, next) => {
const result = await preSendCheck(context.response);
if (!result.ok) {
throw new ValidationError('ADHD compliance check failed');
}
context.response = result.text;
return next();
});
}
This ensures every response path—whether from direct generation, tool use, or streaming—passes through the same validation layer.
Error Handling and Regeneration Strategy
When validation fails, the pre‑send check does not silently drop the response. Instead, it implements a regeneration loop:
- Soft failures (fixable formatting issues): Auto‑rewrite and re‑validate.
- Hard failures (safety violations or unrecoverable length breaches): Return failure state to trigger full regeneration with adjusted parameters.
This fail‑safe design prevents non‑compliant content from leaking through while minimizing latency impact through targeted corrections.
Summary
- The pre‑send check mechanism runs in
.opencode/plugins/i-have-adhd.mjsvia thepreSendCheckfunction. - Validation rules are defined in
skills/i-have-adhd/SKILL.mdand enforced automatically on every outgoing message. - The hook system in
hooks/always-on.mjsintegrates the check into the runtime without manual developer action. - Failed validations trigger either automatic rewriting or full regeneration until compliance is achieved.
- The mechanism guarantees all assistant outputs meet ADHD‑friendly accessibility standards before reaching users.
Frequently Asked Questions
What happens if a response fails the pre‑send check?
The validator first attempts to auto‑correct formatting violations. If the issue is unrecoverable—a safety breach or persistent length overflow—it returns a failure state that triggers regeneration with modified parameters. This loop continues until the response passes or a maximum retry threshold is reached.
Where are the ADHD‑friendly rules stored?
The authoritative rule definitions live in skills/i-have-adhd/SKILL.md. This markdown file enumerates ten specific formatting constraints, including sentence length limits, jargon prohibitions, and structural requirements that the preSendCheck function parses and enforces.
Can developers disable the pre‑send check?
The hook registration in hooks/always-on.mjs loads unconditionally in the OpenCode runtime. To bypass validation, a developer would need to modify or exclude that hook file from the plugin load path—an intentional friction point that protects the project's core accessibility mission.
How does the pre‑send check handle streaming responses?
The current implementation in .opencode/plugins/i-have-adhd.mjs buffers streaming chunks until the complete response is assembled, then runs preSendCheck against the full text. This ensures holistic validation of cross‑chunk formatting rules that would be invisible to per‑chunk filtering.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →