Skip to content

A skill to stop your coding agent from burying the answer. ADHD-friendly output.

Merge main into feat/pi-native-extension

Ayoub G.adc89d79e081
diff --cc INSTALL.md
index bf50a11,c2fd3d9..31a4710
--- a/INSTALL.md
+++ b/INSTALL.md
@@@ -290,81 -398,41 +410,34 @@@ Or update every unpinned Pi package wit
### Uninstall
```bash
-npx skills remove i-have-adhd
+pi remove https://github.com/ayghri/i-have-adhd
```
-Or delete `~/.pi/agent/skills/i-have-adhd`.
-
### Always-on (optional)
-Add to your project `AGENTS.md`:
+Create a flag in Pi's agent configuration directory:
-```markdown
-## Output style
+```bash
+touch ~/.pi/agent/.i-have-adhd-always
+```
-The reader has ADHD. Shape every response so it can be acted on:
+The extension checks the flag at every new, resumed, forked, or reloaded session. A saved choice for the current session wins over this default, so `stop adhd mode` keeps that session disabled.
-1. Lead with the answer or next action: command, path, or snippet first.
-2. Number multi-step work; one bounded action per step.
-3. End with one next action doable in under two minutes.
-4. Finish the current issue before raising a new one.
-5. Restate progress each turn ("step 3 of 5 done").
-6. Give time estimates in concrete units, never "a bit".
-7. After a change, show what now works.
-8. Errors: state location, cause, and fix. No drama.
-9. Cap lists at 5 items.
-10. No preamble, no recaps, no closers.
+Back to on-demand:
-Exceptions: explain fully when asked to explain. Confirm before destructive actions. After three failed fixes, stop and name the doubtful assumption. If the request is ambiguous, ask one short question.
+```bash
+rm ~/.pi/agent/.i-have-adhd-always
```
+If `PI_CODING_AGENT_DIR` is set, put `.i-have-adhd-always` in that directory instead. Run `/reload` or start a new session after changing the flag.
+
</details>
- <details>
- <summary><strong>Gemini CLI</strong></summary>
-
- Gemini CLI has no plugin marketplace, so there are two native routes: a **custom command** (opt-in, off until you invoke it) or an **extension** (always-on once installed). The command route matches this skill's default posture; pick it unless you want the rules on every session.
-
- ### Install (command, opt-in)
-
- ```bash
- mkdir -p ~/.gemini/commands
- curl -fsSL https://raw.githubusercontent.com/ayghri/i-have-adhd/main/skills/i-have-adhd/agents/gemini.toml \
- -o ~/.gemini/commands/i-have-adhd.toml
- ```
-
- Start a new session, type `/i-have-adhd`. It stays on for that session.
-
- ### Install (extension, always-on)
-
- ```bash
- gemini extensions install https://github.com/ayghri/i-have-adhd
- ```
-
- The extension loads `GEMINI.md`, which imports the full skill, so the rules apply from message one. `git` must be installed.
-
- ### Verify
-
- ```bash
- gemini extensions list # extension route
- ls ~/.gemini/commands # command route: i-have-adhd.toml present
- ```
-
- Or type `/` in a session and confirm `i-have-adhd` is listed.
-
- ### Update
-
- ```bash
- gemini extensions update i-have-adhd # extension route
- # command route: re-run the curl above
- ```
-
- ### Uninstall
-
- ```bash
- gemini extensions uninstall i-have-adhd # extension route
- rm ~/.gemini/commands/i-have-adhd.toml # command route
- ```
-
- </details>
<details>
- <summary><strong>GitHub Copilot (VS Code and Copilot CLI)</strong></summary>
+ <summary><strong>Zed</strong></summary>
- Copilot reads Agent Skills natively: the same `SKILL.md`, no conversion. It scans `.github/skills/`, `.claude/skills/`, and `.agents/skills/` in the project, and `~/.copilot/skills/`, `~/.claude/skills/`, and `~/.agents/skills/` globally.
+ Zed's Agent reads Agent Skills natively: the same `SKILL.md`, no conversion. (Zed's older "Rules" were replaced by Skills plus `AGENTS.md` instructions.)
### Install
diff --cc extensions/i-have-adhd.ts
index b0b58e3,0000000..8e43fba
mode 100644,000000..100644
--- a/extensions/i-have-adhd.ts
+++ b/extensions/i-have-adhd.ts
@@@ -1,221 -1,0 +1,226 @@@
+import { existsSync, readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import {
+ getAgentDir,
+ type ExtensionAPI,
+ type ExtensionContext,
+} from "@earendil-works/pi-coding-agent";
+
+const EXTENSION_DIR = dirname(fileURLToPath(import.meta.url));
+const SKILL_PATH = join(
+ EXTENSION_DIR,
+ "..",
+ "skills",
+ "i-have-adhd",
+ "SKILL.md",
+);
+const STATE_ENTRY_TYPE = "i-have-adhd-state";
+const RULES_MESSAGE_TYPE = "i-have-adhd-rules";
+const DISABLED_MESSAGE_TYPE = "i-have-adhd-disabled";
+const STATUS_KEY = "i-have-adhd";
+const DISABLE_CONFIRMATION = "ADHD mode disabled.";
+const STOP_PHRASES = new Set(["stop adhd mode", "normal mode"]);
+const RULES_HEADER =
+ 'ADHD MODE ACTIVE. The ruleset below applies to every response until turned off. "stop adhd mode" or "normal mode" turns it off for this session.';
+const DISABLED_NOTICE =
+ "ADHD MODE OFF. Ignore the i-have-adhd ruleset injected earlier in this conversation and return to your default response style.";
+
+type AdhdModeState = {
+ enabled: boolean;
+};
+
+function stripFrontmatter(content: string): string {
- return content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim();
++ return content
++ .replace(
++ /^---[^\S\r\n]*\r?\n[\s\S]*?\r?\n---[^\S\r\n]*(?:\r?\n|$)/,
++ "",
++ )
++ .trim();
+}
+
+function loadRules(): string {
+ let content: string;
+
+ try {
+ content = readFileSync(SKILL_PATH, "utf8");
+ } catch (error) {
+ const reason = error instanceof Error ? error.message : String(error);
+ throw new Error(
+ `Unable to load i-have-adhd rules from ${SKILL_PATH}: ${reason}`,
+ );
+ }
+
+ const rules = stripFrontmatter(content);
+ if (!rules) {
+ throw new Error(`The i-have-adhd rules file is empty: ${SKILL_PATH}`);
+ }
+
+ return rules;
+}
+
+function getSavedState(ctx: ExtensionContext): boolean | undefined {
+ let savedState: boolean | undefined;
+
+ for (const entry of ctx.sessionManager.getBranch()) {
+ if (entry.type !== "custom" || entry.customType !== STATE_ENTRY_TYPE) {
+ continue;
+ }
+
+ const data = entry.data as Partial<AdhdModeState> | undefined;
+ if (typeof data?.enabled === "boolean") {
+ savedState = data.enabled;
+ }
+ }
+
+ return savedState;
+}
+
+/**
+ * Whether the rules are still live in the context the model actually receives.
+ *
+ * Only the newest marker counts: a later "disabled" notice cancels an earlier
+ * ruleset, and compaction drops summarized entries so the ruleset has to be
+ * injected again.
+ */
+function rulesAreInContext(ctx: ExtensionContext): boolean {
+ let active = false;
+
+ for (const entry of ctx.sessionManager.buildContextEntries()) {
+ if (entry.type !== "custom_message") continue;
+
+ if (entry.customType === RULES_MESSAGE_TYPE) {
+ active = true;
+ } else if (entry.customType === DISABLED_MESSAGE_TYPE) {
+ active = false;
+ }
+ }
+
+ return active;
+}
+
+export default function iHaveAdhdExtension(pi: ExtensionAPI) {
+ const rules = loadRules();
+ const alwaysOnFlag = join(getAgentDir(), ".i-have-adhd-always");
+ let enabled = false;
+
+ const updateStatus = (ctx: ExtensionContext): void => {
+ if (!enabled) {
+ ctx.ui.setStatus(STATUS_KEY, undefined);
+ return;
+ }
+
+ const dot = ctx.ui.theme.fg("success", "●");
+ const label = ctx.ui.theme.fg("accent", "ADHD ON");
+ ctx.ui.setStatus(STATUS_KEY, `${dot} ${label}`);
+ };
+
+ /**
+ * Keep the conversation in sync with the current mode, the way the Claude Code
+ * SessionStart hook does: inject the ruleset once, never per request.
+ */
+ const syncContext = (ctx: ExtensionContext): void => {
+ const injected = rulesAreInContext(ctx);
+
+ if (enabled && !injected) {
+ pi.sendMessage(
+ {
+ customType: RULES_MESSAGE_TYPE,
+ content: `${RULES_HEADER}\n\n${rules}`,
+ display: false,
+ },
+ { triggerTurn: false },
+ );
+ return;
+ }
+
+ if (!enabled && injected) {
+ pi.sendMessage(
+ {
+ customType: DISABLED_MESSAGE_TYPE,
+ content: DISABLED_NOTICE,
+ display: false,
+ },
+ { triggerTurn: false },
+ );
+ }
+ };
+
+ const restoreState = (ctx: ExtensionContext): void => {
+ const savedState = getSavedState(ctx);
+ const enabledByDefault =
+ pi.getFlag("adhd") === true || existsSync(alwaysOnFlag);
+
+ enabled = savedState ?? enabledByDefault;
+ updateStatus(ctx);
+ syncContext(ctx);
+ };
+
+ const setEnabled = (nextEnabled: boolean, ctx: ExtensionContext): void => {
+ enabled = nextEnabled;
+ pi.appendEntry(STATE_ENTRY_TYPE, { enabled } satisfies AdhdModeState);
+ updateStatus(ctx);
+ syncContext(ctx);
+ ctx.ui.notify(`ADHD mode ${enabled ? "enabled" : "disabled"}`, "info");
+ };
+
+ pi.registerFlag("adhd", {
+ description: "Start with ADHD-friendly output enabled",
+ type: "boolean",
+ default: false,
+ });
+
+ pi.registerCommand("i-have-adhd", {
+ description: "Toggle ADHD-friendly output for this session",
+ handler: async (args, ctx) => {
+ const argument = args.trim().toLowerCase();
+
+ if (argument === "") {
+ setEnabled(!enabled, ctx);
+ return;
+ }
+
+ if (argument === "on") {
+ setEnabled(true, ctx);
+ return;
+ }
+
+ if (argument === "off" || argument === "stop") {
+ setEnabled(false, ctx);
+ return;
+ }
+
+ ctx.ui.notify("Usage: /i-have-adhd [on|off]", "warning");
+ },
+ });
+
+ pi.on("input", async (event, ctx) => {
+ const input = event.text.trim().toLowerCase();
+
+ // Keep the built-in skill command working as an alias without letting Pi
+ // expand a second copy of the same rules into the conversation.
+ if (input === "/skill:i-have-adhd") {
+ setEnabled(true, ctx);
+ return { action: "handled" };
+ }
+
+ if (enabled && STOP_PHRASES.has(input)) {
+ setEnabled(false, ctx);
+
+ if (ctx.hasUI) {
+ return { action: "handled" };
+ }
+
+ return {
+ action: "transform",
+ text: `Reply with exactly: ${DISABLE_CONFIRMATION}`,
+ };
+ }
+
+ return { action: "continue" };
+ });
+
+ pi.on("session_start", async (_event, ctx) => restoreState(ctx));
+ pi.on("session_tree", async (_event, ctx) => restoreState(ctx));
+ pi.on("session_compact", async (_event, ctx) => syncContext(ctx));
+}