OpenSource-Hub

adhd

ライブラリ

UditAkhourii/adhd

コーディングエージェント向けの並列発散的思考によるツリー状思考スキル。

概要

ADHD は剪定機能を備えた思考ツリー(Tree of Thoughts)を実装し、分離された認知フレームワーク下で発散的推論を並列実行することで、早期収束を回避します。スコアリング、罠の剪定、生き残った候補の深化を通じて、AI エージェントの創造性と学際的な作業能力を強化します。

README プレビュー

\n  \n    \n  \n\n\n# ADHD — a skill for agents\n\n[](https://github.com/UditAkhourii/adhd/actions/workflows/ci.yml)\n[](https://www.npmjs.com/package/adhd-agent)\n[](./LICENSE)\n[](./documentation/install.md)\n[](https://adhdstack.github.io/)\n[](https://thenewstack.io/claude-code-adhd/)\n[](https://discord.gg/NbWwkwwGw)\n\n\n\n> ### 🎮 [**Join the ADHD Discord →**](https://discord.gg/NbWwkwwGw)\n> This is where the real-time thinking happens: frame design, eval problems, trap-hunting, and neurodivergence-inspired research on reasoning architectures. If you've got opinions on premature convergence, cognitive frames, or just want to argue about the next eval problem — **[come argue with us live](https://discord.gg/NbWwkwwGw).**\n\n> 👉 [**Join the ADHD community →**](https://tally.so/r/WO1Nzj) as a contributor, maintainer, early adopter, or just a member. One short form. We coordinate frame contributions, eval problems, integrations, and adopter onboarding there.\n\n> **An architectural fix for premature convergence in autoregressive reasoning.**\n\nLinear Chain-of-Thought anchors on whatever it says first. Tree-of-Thought widens the search but still walks a single shared context, so the anchoring persists across branches. **ADHD treats this as an architectural problem, not a prompting one** — it spawns N isolated reasoning processes under deliberately distorted cognitive frames, with zero shared context during divergence, then runs a separate critic pass to score, cluster, prune traps, and deepen the survivors.\n\nReach for it on **design decisions, fuzzy debugging, naming, API surface design, strategy, and any prompt of the shape *"give me a few ways to…"***.\n\n📄 **Preprint:** [ADHD: Parallel Divergent Ideation for Coding Agents](https://adhdstack.github.io/) · 👤 **Author:** Udit Akhouri — [@akhouriudit](https://x.com/akhouriudit) · [LinkedIn](https://www.linkedin.com/in/udit-akhouri-10160a168/)\n\n---\n\n## Side-by-side: baseline vs ADHD\n\nOne eval problem, s

FAQ (2)

トラブル対応
adhd --frames 1 を実行したときに、ワイルドカードフレームが約半分の確率で欠落してしまう問題を修正するにはどうすればよいですか?

これは n === 1 の場合に src/frames.ts 内の selectFrames() に存在するバグです。ランダムなフレームを1つ選択してワイルドカードを追加しますが、最後の .slice(0, n) により、最初のフレームがすでに wild タグ付きでない限り、そのワイルドカードが削除されてしまいます。

**暫定的な回避策:** --frames 2 以上を使用してください。ワイルドカードの保証は n >= 2 では正しく機能します:

adhd "your prompt" --frames 2

**恒久的な修正:** 残りのフレームを選択する前にワイルドカードを確保しておき、切り捨てられることがないようにします:

const wildPick = wild[Math.floor(Math.random() * wild.length)];
const rest = shuffle(pool.filter((f) => f.id !== wildPick.id))
  .slice(0, Math.max(0, n - 1));

return n <= 1 ? [wildPick] : [...rest, wildPick].slice(0, n);

selectFrames(1) のすべての結果に wild タグの付いたフレームがちょうど1つ含まれることをアサートするユニットテストを追加してください。

参照 Issue #37
トラブル対応
1つの失敗したLLM呼び出しがブランチのファンアウト全体をキャンセルし、完了した結果を破棄しないようにするにはどうすればよいですか?

発散ファンアウト(frames.map(...))と deepen パス(toDeepen.map(...))の両方で、Promise.all を Promise.allSettled に置き換えてください。そのうえで、fulfilled な結果を個別に処理し、最初の rejection で実行が中断されるのではなく、rejected なブランチを収集するようにします。

実装パターンの例:

const settled = await Promise.allSettled(
  frames.map((frame) => divergeBranch(frame))
);

const branches: Branch[] = [];
const failedFrames: { frameId: string; error: string }[] = [];

settled.forEach((result, i) => {
  if (result.status === "fulfilled") {
    branches.push(result.value);
  } else {
    const frameId = frames[i].id;
    const error = String(result.reason);
    failedFrames.push({ frameId, error });
    emitter.emit("frame:failed", { frameId, error });
  }
});

deepen パスにも同じ変更を適用してください。types.ts の RunResult に failedFrames を追加します:

type RunResult = {
  // existing fields
  failedFrames: { frameId: string; error: string }[];
};

これにより、CLI は ✗ <frame> failed: <reason> のような部分的な失敗を出力できるようになります。実行がハードフェイルするのは、すべてのブランチが失敗した場合のみとします:

if (branches.length === 0) {
  throw new Error("All LLM branches failed");
}

これは、レート制限、タイムアウト、復旧不可能な不正形式のレスポンスなど、ネットワーク/LLM 層でのスローに対応します。divergeBranch、scoreIdeas、clusterIdeas 内での JSON パース失敗は、空の結果を返すことで既にフェイルオープンになっています。再実行サポートについては、(frame_id, input_hash) をキーとするオプションのチェックポイントにより、完了したブランチをスキップし、失敗したブランチをバックオフ付きで再試行できます。

参照 Issue #44