Claude Code plugin 構成と HTML spec management 統合の徹底調査

v0.1.0-draft · 調査日 2026-05-23 · session 5592bf08 · 調査範囲: 公式仕様 (plugin.json / SKILL.md / hooks / agents / scripts / 組合せ pattern) / Git-based hook framework / Linter + SSG plugin architecture / ADR + spec OSS / JSON-LD lint mechanism

§1. 調査背景

§1.1. folio の Phase X3 着手要件

folio は AI agent (Claude Code) と人間が共同で「仕様書 (architecture spec)」 を HTML 形式で書き続ける meta framework (P-2)。 Phase X1-X2 で rules.html / folio-self-spec.html / relations.html / constitution.html の 4 file が確定 (commit 75232b9)、 Phase X3 で「architecture/ という構造を作成し維持する」 試作 plugin の実装に着手する。 plugin の 6 機能候補:

  1. architecture/ 構造の強制 (rule 違反 path で reject)
  2. spec 追加時の README index 自動更新
  3. JSON-LD lint (Edit 完了時 schema check)
  4. broken link detection
  5. 双方向 link auto-materialize (forward 宣言時 reverse 自動追加)
  6. caller marker enforcement (REQ-CM-001〜003)

これらを Claude Code plugin の skills / hooks / scripts / slash commands でどう組み合わせるか、 業界事例 (pre-commit / husky / ESLint / log4brains / Beads / twill) を踏まえて設計判断する必要がある。

§1.2. 5 サブ質問

  1. Claude Code Plugin 公式仕様 (plugin.json manifest / SKILL.md format / hooks 全種 / agents / scripts / 組み合わせ pattern)
  2. Git-based hook framework 業界事例 (pre-commit / husky / lefthook / lint-staged / pre-commit.ci) と PreToolUse / PostToolUse の使い分け
  3. Linter plugin architecture と SSG/catalog hook system (ESLint / Stylelint / Prettier / Sphinx / MkDocs / Antora / Docusaurus / Backstage)
  4. ADR / spec management OSS の具体実装 (log4brains / Beads / MADR / adr-tools / Specmatic / Spectral / ArchUnit / twill plugin)
  5. JSON-LD validation の実装 + Claude Code PostToolUse hook で「Edit 後即時 lint」 する mechanism

追加で Q3 use case matrix (8 use case × skill/hook/script/CLI) / Q6 folio Phase X3 minimal viable plugin 設計推奨 / Q7 ADR 起票候補 を全 worker findings の統合で導出。

§2. Claude Code Plugin 公式仕様 reference

§2.1. plugin.json manifest (23 field、 大半は optional)

配置先: <plugin-root>/.claude-plugin/plugin.json。 manifest は optional (省略時は directory name から自動導出 + default 位置からコンポーネントを auto-discover)。

plugin.json 主要 field カテゴリ
カテゴリfield 群規則
identityname / displayName / version / description / author / homepage / repository / license / keywordsname は kebab-case (skill namespace に使用)、 version は semver (省略時は git SHA)
component (加算)skillsdefault skills/ に追加
component (置換)commands / agents / outputStyles / experimental.themes / experimental.monitorsmanifest 指定時は default ディレクトリをスキャンしない
component (独自 merge)hooks / mcpServers / lspServers設定 file への merge ルール
runtimeuserConfig / settings / dependencies / channels / $schemauserConfig は enable 時に prompt、 ${user_config.KEY} で hook command / MCP/LSP config / monitor / skill content (非 sensitive) に展開

全 path は ./ 相対指定 MUST。 環境変数: ${CLAUDE_PLUGIN_ROOT} (絶対パス) / ${CLAUDE_PLUGIN_DATA} (永続データ) / ${CLAUDE_PROJECT_DIR} (project root)。

§2.2. plugin directory layout

my-plugin/
├── .claude-plugin/
│   └── plugin.json
├── skills/<name>/SKILL.md        ← Progressive Disclosure 3-tier (推奨)
├── commands/<name>.md             ← legacy flat .md (Skills と同一 frontmatter)
├── agents/<name>.md               ← subagent 定義 (plugin agent は hooks/mcpServers/permissionMode 非対応)
├── hooks/hooks.json               ← 自動 detection (plugin.json 明示不要)
├── scripts/                       ← 慣習 (必須でない)、 ${CLAUDE_PLUGIN_ROOT}/scripts/ で参照
├── bin/                           ← Bash の PATH に追加
├── monitors/monitors.json         ← experimental、 stdout 各行が notification
├── output-styles/, themes/
└── .mcp.json, .lsp.json

§2.3. Hooks — 29 イベント (公式 verified)

folio に関連する主要 hook event (29 種から抜粋)
eventtriggermatcherblocking (exit 2)主用途
SessionStartsession 開始/再開source enum不可context injection (Beads pattern)
UserPromptSubmituser prompt 送信時なしprompt 検査・拡張
PreToolUseツール呼出前tool name (regex)caller marker check / file protection
PermissionRequest権限ダイアログtool nameauto allow/deny
PostToolUseツール成功後tool name不可 (stderr → Claude)lint feedback / auto-fix
PostToolUseFailureツール失敗後tool name不可エラーログ収集
PostToolBatch並列バッチ完了後なしagentic loop 停止
Stop / SubagentStop応答終了なしend-of-session 検証
InstructionsLoadedCLAUDE.md ロード時5 source enum不可spec 自動 inject
FileChanged監視 file 変更時literal name (regex 不可)不可外部編集追従
PreCompact / PostCompactcontext compactionなし可 / 不可状態保存・復元

Hook 5 type: command (shell コマンド、 args で exec form 可) / http (JSON POST) / mcp_tool (MCP tool 呼出) / prompt (Claude model 推論、 yes/no) / agent (subagent spawn、 experimental)。

stdin JSON (PreToolUse 例):

{
  "session_id": "...", "transcript_path": "...", "cwd": "...",
  "hook_event_name": "PreToolUse",
  "permission_mode": "default|plan|acceptEdits|...",
  "tool_name": "Write", "tool_input": {...}, "tool_use_id": "...",
  "effort": {"level": "..."}
}

stdout JSON output (PreToolUse の deny 例):

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "caller marker not set"
  }
}

§2.4. SKILL.md + Progressive Disclosure (3-tier)

frontmatter 全フィールド optional、 description のみ強推奨:

---
name: skill-name
description: "What it does... Use when..."
when_to_use: "Additional context..."        # description に連結、 合計 1536 文字上限
allowed-tools: "Read Grep Bash(git *)"
model: sonnet
effort: medium
context: fork                                # subagent で実行
agent: Explore
hooks: {...}                                 # skill ライフサイクル hook
paths: "src/**/*.ts"                         # glob で自動起動限定
---
Progressive Disclosure 3-tier (Anthropic Agent Skills、 relations.html §4.2 と整合)
Level内容ロードタイミングtokens
Level 1 (Metadata)name + description常時 (session 開始時)~100 / skill
Level 2 (Instructions)SKILL.md bodytrigger 時のみ5,000 tokens 以下
Level 3 (Resources)reference.md / scripts/明示参照時のみunbounded

Dynamic context injection (skill 本文): !`<command>` 構文で skill ロード前にコマンド実行・出力で置換。

§2.5. Slash Commands と Agents

公式 docs では skills と commands は統合/slash-commands 独立ページは存在しない (skills page に redirect)。

方式path呼び出し
Skills (推奨)<plugin>/skills/<name>/SKILL.md/plugin-name:name
Commands (legacy)<plugin>/commands/<name>.md/plugin-name:name

Agents (subagent) 配置: <plugin>/agents/<name>.md。 v2.1.63 で Task tool → Agent tool 改名 (Task は alias 継続)。 plugin agent では security 上 hooks / mcpServers / permissionMode無視される。 built-in: Explore (Haiku、 read-only) / Plan / general-purpose

§2.6. 組み合わせ pattern

公式 docs verified の 8 pattern
pattern実現方法公式記載
(a) hook → scripthooks.jsontype: "command"${CLAUDE_PLUGIN_ROOT}/scripts/...あり
(b) skill → scriptSKILL.md 本文で !`bash ...` または allowed-tools 経由あり
(c) skill → subagent (fork)frontmatter context: fork, agent: Exploreあり
(d) slash command → skillcommands/ も skill system で動作あり
(e) hook → agenttype: "agent" (experimental)experimental
(f) skill が hook を持つfrontmatter hooks: でライフサイクル hookあり
(g) hook が skill を直接 trigger公式 docs に記載なし
(h) subagent が skills プリロードagent frontmatter skills:あり

§3. Git-based hook framework 業界事例

§3.1. 6 tool 比較

tool言語config実行モデル性能monorepo用途
pre-commit (yelp)Python.pre-commit-config.yaml + 外部 .pre-commit-hooks.yaml順次 (default)中 (isolated env 構築)限定多言語 / 外部 hook repo
huskyNode.js.husky/ shell scripts順次中 (Node 起動)手動 + lint-stagedJS/TS 標準 (週 5M DL)
lefthookGo (single binary)lefthook.yml並列対応 (Go binary)root: で限定高性能 monorepo
simple-git-hooksNode.jspackage.json順次低 (zero deps)非対応小規模 minimal
lint-stagedNode.js.lintstagedrc / package.jsonglob ごと並列 (staged のみ)glob で自然対応husky/lefthook 併用
pre-commit.ciSaaS.pre-commit-config.yamlci: sectionPR 自動 (共有 cache)repo 単位CI 強制 + autofix PR

§3.2. PreToolUse / PostToolUse vs git hook の対比

4 軸対比 (researcher-2 統合)
PreToolUsePostToolUsegit pre-commitCI
発火AI ツール実行直前AI ツール成功直後git commitPR/merge 時
介入 (block) (exit 2 / JSON deny)不可 (stderr → Claude)可 (exit 非0) (status check)
bypass 可Claude 外編集は素通り同左--no-verify で完全バイパス不可
cross-file1 file (Agent 経由で複数可)同左staged 全体一括repo 全体
自動修正PostToolUse で auto-fixedit + stage 可hook 内 modify (複雑)autofix PR

§3.3. 3 層防御 (defense in depth) 原則

Layer 1: PreToolUse / PostToolUse hook  ← AI 編集時のリアルタイムチェック
Layer 2: git pre-commit hook           ← commit 時 (human + AI 両方)
Layer 3: CI (GitHub Actions)           ← merge gate (bypass 不可)

Xygeni / AdamJ の指摘: --no-verify の使用を完全に抑制することはできないため、 git hook でチェックしているのと同じ内容を CI/CD パイプラインでも実施することがベストプラクティス。

folio use case 別の推奨レイヤー
use case推奨理由
caller marker checkPreToolUse + pre-commit hookAI 編集 block + 人手保護
JSON-LD lintPostToolUse (即時 feedback) + pre-commit (--no-verify 保険)AI へのリアルタイム feedback + final gate
broken link detectionCI全 file scan で hook には遅い、 PR merge gate が適切
双方向 link materializePostToolUse auto-fixatomic write + git add の連携 (idempotent 必須)

§4. Linter + SSG plugin architecture

§4.1. 共通 4 design pattern

8 ツール (ESLint / Stylelint / Prettier / Sphinx / MkDocs / Antora / Docusaurus / Backstage) の帰納
pattern説明採用例
(a) Extension Point declarative 宣言「宣言 manifest → runtime 登録」全ツール (ESLint plugin.rules / Sphinx setup(app) / MkDocs entry_points / Antora register() / Docusaurus factory)
(b) Rule + Autofix + Meta 三位一体検出ロジック + 修正 + メタ情報を 1 unitESLint {meta, create(context)} / Stylelint createPlugin(name, fn)
(c) Lifecycle Event 順序保証named event の pipeline 構造Antora 14 step / Sphinx 8+ event / MkDocs Global→Page 2 層 / Docusaurus loadContent→contentLoaded→postBuild / Backstage 3 stage
(d) Context Objectplugin が runtime context 受領ESLint context / Sphinx app / MkDocs config/files/page / Docusaurus LoadContext + actions

§4.2. ESLint Rule Unit (folio HTML lint に直接適用可能)

module.exports = {
  meta: {
    type: "problem",
    fixable: "code",
    hasSuggestions: true,
    schema: [{ type: "object", properties: {...} }],  // JSON Schema Draft-04
    docs: { url: "..." }
  },
  create(context) {
    return {
      "Identifier": (node) => {
        context.report({
          node,
          messageId: "...",
          fix(fixer) {
            return fixer.replaceText(node, newText);
          }
        });
      }
    };
  }
};

Autofix 安全性原則:

§4.3. MkDocs Event System (folio README 自動更新パターンに最適合)

class MyPlugin(BasePlugin):
    @event_priority(-50)
    def on_files(self, files, config):
        files.append(File.generated(config, "virtual.md", content="..."))
        return files

    def on_page_markdown(self, markdown, page, **kwargs):
        return modified_markdown  # None → 元のまま

Event 分類:

§4.4. Antora Generator Events (14 step、 SSoT enforcement に応用)

順序保証あり: contextStartedplaybookBuiltbeforeProcesscontentAggregated (ファイル追加可能) → uiLoadedcontentClassified (分類済み catalog 使用可能) → documentsConvertednavigationBuiltpagesComposedredirectsProducedsiteMappedbeforePublishsitePublishedcontextStopped / contextClosed

§4.5. Backstage Catalog Auto-Discovery

EntityProvider (エッジ)
  → getProviderName() で一意 bucket
  → connect(connection)
  → connection.applyMutation({type: 'full'|'delta', entities: [...]})
     'full': bucket 全体置換
     'delta': {added, removed}

→ EntityProcessor (中継、 推奨は Provider に移行)
  → preProcessEntity / postProcessEntity
  → 新 entity / relation / error を emit

→ Stitching (最終 catalog API 出力)

Provider 削除 → 即時 purge。 Processor はオーファン化のみ。 Provider は webhook / schedule / event 駆動 (柔軟)、 Processor は固定 loop。

§5. ADR / spec management OSS の具体実装事例

§5.1. log4brains — 双方向 link auto-materialize (TypeScript verified)

GitHub source 直接 fetch (packages/core/src/adr/domain/Adr.ts):

class Adr extends AggregateRoot<Props> {
  // ADR-A が ADR-B に supersede される時
  supersedeBy(superseder: Adr): void {
    const relation = new AdrRelation(this, "superseded by", superseder);
    this.body.setHeaderMetadata("Status", relation.toMarkdown());
    superseder.markAsSuperseder(this);  // ← ADR-B 側に逆参照を自動追加
  }

  private markAsSuperseder(superseded: Adr): void {
    const relation = new AdrRelation(this, "Supersedes", superseded);
    this.body.addLinkNoDuplicate(relation.toMarkdown());  // 重複防止
  }
}

双方向 materialize の仕組み:

  1. adr-A.supersedeBy(adr-B) を呼ぶ
  2. adr-A の Status header が "superseded by: [adr-B-slug]" に書き換え
  3. 同時に adr-B.markAsSuperseder(adr-A) 自動呼び出し
  4. adr-B の Links section に "Supersedes: [adr-A-slug]" 追加 (重複防止付き)

ADR link resolver の設計決定 (log4brains ADR 20201027): markdown parsing はドメイン層責務 (infra 層ではない)。 slug と filename を分離 → rename に強い。

§5.2. Beads — 動的 context injection (Claude Code 統合 verified)

steveyegge/beads は SQLite + Dolt のデュアルストレージで Issue dependency graph を管理し、 AI agent (Claude Code 等) に動的 context を inject する。

bd setup claude    # ~/.claude/settings.json に自動登録
{
  "hooks": {
    "SessionStart": [{"command": "bd prime"}],
    "PreCompact": [{"command": "bd prime --stealth"}]
  }
}

コンテキスト効率化: IssueMinimal model で ~80-95% トークン削減、 ~10-50k → ~2-5k。 9 ツール対応 (Aider / Claude Code / Cursor / Factory.ai / Gemini CLI / Mux / Junie / OpenCode / Codex CLI)。

§5.3. adr-tools (npryce) — bash 双方向

# adr new -s OLD_ID で supersede
_adr_add_link "$old_adr" "Superceded by" "$new_adr"
_adr_add_link "$new_adr" "Supercedes" "$old_adr"

# custom: TARGET:LINK:REVERSE-LINK
adr new -l "0004:Amended by:Amends"

_adr_add_link ヘルパで grep/sed/awk による markdown 操作。 MADR (Markdown ADR) 自体には自動 cross-ref 更新機能はなく、 テンプレートのみ提供 (adr-tools / log4brains 等ツール層でカバー)。

§5.4. Spectral — declarative rule (folio の lint rule 設計に応用)

extends: ["spectral:oas"]
rules:
  my-rule:
    description: "パス名は kebab-case"
    severity: warn  # error / warn / info / hint / off
    given: "$.paths[*]~"  # JSONPath
    then:
      function: pattern
      functionOptions:
        match: "^[a-z/-]+$"

severity 5 段階: error / warn / info / hint / off。 autofix は公式未対応 (validation のみ)。 Specmatic は specmatic backward-compatibility-check で非互換変更を exit 1 でブロック (folio の breaking change gate に応用可能)。

§5.5. twill plugin (folio predecessor) hook architecture

verified: ローカル file 直接読取 (/home/shuu5/projects/local-projects/twill/main/plugins/twl/hooks/hooks.json 他)。

twill hooks.json の要点抜粋:

{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Edit|Write|NotebookEdit",
        "hooks": [{"type": "command", "command": "pre-tool-use-worktree-boundary.sh"}] },
      { "matcher": "Bash",
        "hooks": [{"type": "command", "command": "pre-tool-use-host-safety.sh"}] },
      { "matcher": "Edit|Write",
        "hooks": [{"type": "command", "if": "Edit(deps.yaml)|Write(deps.yaml)",
                   "command": "pre-tool-use-deps-yaml-guard.sh"}] },
      { "matcher": "Edit|Write|NotebookEdit",
        "hooks": [{"type": "command", "command": "pre-tool-use-spec-write-boundary.sh"}] },
      { "matcher": "Skill",
        "hooks": [{"type": "command", "if": "Skill(phaser-*)",
                   "command": "pre-tool-use-phase-gate.sh"}] }
    ],
    "PostToolUse":        [{ "matcher": "Edit|Write|NotebookEdit", ... }],
    "PostToolUseFailure": [{ "matcher": "Bash", ... }],
    "PreCompact":         [...],
    "PostCompact":        [...]
  }
}

spec-write-boundary.sh の caller marker pattern:

caller="${TWL_TOOL_CONTEXT:-}"
case "$caller" in
  "")           exit 0 ;;           # user manual → allow
  tool-architect) ... allow + warn ;;
  *)  jq -nc '{hookSpecificOutput:{permissionDecision:"deny",...}}'; exit 0 ;;
esac

R-N 規律体系 (R-1〜R-44) — folio が継承すべき pattern:

Rule内容
R-1新 file 追加時は README.html index table に entry 追加 MUST
R-2新 file 追加時は architecture-graph.html に node + edge 追加 MUST
R-3orphan 禁止 (inbound link ≥ 1)
R-4削除/rename 時は inbound link 全更新 MUST
R-7spec 編集前に TWL_TOOL_CONTEXT=tool-architect 設定 MUST
R-8PR merge gate: broken link 0 + orphan 0 (CI)
R-14declarative form (時系列マーカー / 過去 narration 禁止)

twill 多層防御 L1-L5: L1 Skill (SKILL.md + rules) / L2 bats (unit test) / L3 PreToolUse hook + MCP tool / L4 Vale / textlint (optional) / L5 CI (spec-link-check.yml + spec-content-check.yml)。

§5.6. 5 共通設計原則 (抽出)

pattern説明採用例
(1) Domain entity + lifecycle event + side-effect handlermutation method → 自動副作用呼出log4brains supersedeBy() → markAsSuperseder()
(2) Hook gate + caller context injectionenv var で caller 識別 + 機械的許可/拒否twill TWL_TOOL_CONTEXT / Beads bd prime
(3) 静的ルール定義 + 機械検証YAML/Java/MD 宣言 → validator → CI gateArchUnit / Spectral / twill R-N
(4) 動的 context injectionSessionStart hook → real-time data 注入Beads bd prime
(5) SSoT + cross-reference enforcement複数 SSoT 相互参照 + 追加削除時の副作用規律twill R-1〜R-8

§6. JSON-LD validation + lint mechanism

§6.1. JSON-LD validation tool 比較

tool言語役割folio 適合性
ajv + ajv-cliNode.jsJSON Schema validator@context/@type/@id 構造 + required check に最適、 最速
jsonschema + check-jsonschemaPythonJSON Schema validatoriter_errors() で全エラー取得、 Python ecosystem 統合
pyldPythonJSON-LD processorFrozenDocumentLoader でオフライン、 on_property_dropped で unmapped property 検出
jsonld.jsNode.jsJSON-LD processor{safe: true} で lossy transform 検出、 カスタム documentLoader
pySHACLPythonSHACL validatorRDF graph constraint (minCount/datatype/pattern)、 学習コスト高
schemaorg-jsdNode.jsSchema.org + ajvSchema.org 型のみ、 folio カスタム型未対応
jsonld-schema (mulesoft)TypeScripthybrid2024/01 archived、 採用不可

folio 推奨 2 層構成:

  1. ajv (or jsonschema): JSON Schema check (@context存在・値、 @type enum、 @id URI format)
  2. pyld (FrozenDocumentLoader): expansion check (unmapped property をエラー化、 context resolution offline)

§6.2. folio 用 JSON Schema 例

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["@context", "@type", "@id"],
  "properties": {
    "@context": { "type": ["string", "object", "array"] },
    "@type":    { "type": "string" },
    "@id":      { "type": "string", "format": "uri" },
    "dc:title": { "type": "string" },
    "folio:version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+" },
    "folio:depends-on": { "type": "array", "items": {...} }
  },
  "additionalProperties": true
}

§6.3. PostToolUse hook lint flow

#!/usr/bin/env bash
set -euo pipefail

INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')

[[ -z "$FILE_PATH" || "$FILE_PATH" != *.html ]] && exit 0
[[ ! -f "$FILE_PATH" ]] && exit 0

VALIDATION_OUTPUT=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/validate_jsonld.py" "$FILE_PATH" 2>&1)
VALIDATION_EXIT=$?

if [[ $VALIDATION_EXIT -ne 0 ]]; then
    echo "JSON-LD validation failed: $FILE_PATH" >&2
    echo "$VALIDATION_OUTPUT" >&2
    exit 2  # ← Claude が stderr を読んで修正に取り組む
fi
exit 0

§6.4. failure 挙動 3 pattern

pattern動作用途
Pattern A: warn onlyexit 0 + stderrdev 中・規約移行期
Pattern B: block + feedbackexit 2 + stderr確定規約、 Claude に修正促す
Pattern C: auto-fixidempotent edit + os.replace() で atomic安全な機械修正 (双方向 link 等)

auto-fix の安全性: idempotent + Biome の lint --write バグから学び、 まずは warn → 手動修正が安全。

§6.5. false positive 抑制 4 戦略

  1. inline suppression comment: <!-- folio-lint-disable jsonld-required:dcterms:contributor --> (HTML comment、 lint script で parse)
  2. severity tuning: .folio-lint.json で rule 別に error/warn/off
  3. allowlist: .folio-lint-allow.json で file glob + rule 組み合わせ
  4. temporal downgrade: 規約変更時は一時 warn に降格、 移行後 error 復帰

実績例: ESLint // eslint-disable-next-line + reportUnusedDisableDirectives / Ruff # noqa: E501 / golangci-lint //nolint:errcheck

§6.6. security 考慮

§6.7. pre-commit vs PostToolUse 使い分け

[Claude Edit/Write]
    ↓ PostToolUse hook ← AI 即時 feedback (修正コスト最低)
[Claude が修正完了と判断]
    ↓ git commit
    ↓ pre-commit hook ← human + AI 両対応、 final gate (`--no-verify` 回避リスクあり)
[push]
    ↓ CI lint ← 唯一 bypass 不可

推奨: 3 つ全て併用

§7. folio Phase X3 minimal viable plugin 設計推奨

§7.1. P-11 binding 隔離原則

HOW の隔離先 (folio-self-spec.html §9 と整合)
隔離対象binding location
環境変数 default 値.claude-plugin/plugin.json userConfigcaller_marker_env: "FOLIO_ARCHITECT_CONTEXT"
hook script 実装.claude-plugin/scripts/validate_jsonld.py、 pre-edit-boundary.sh
CI script 実装.claude-plugin/scripts/link-integrity.py (lychee wrapper)
Claude Code 固有命名CLAUDE.md (P-2 Markdown 例外)Skill / Hook 命名規約

§7.2. use case × 機能 matrix (Q3 統合)

8 use case の best fit を全 researcher の findings から導出 (実装 Step 番号は §7.4 を参照):

use caseskillhookscriptCLI (bin/)best fitStep
architecture/ 構造強制folio-architectPreToolUsepath-validator.shhook + script2
README 自動更新 (新 spec で index 追記)PostToolUsereadme-updater.pyfolio inventoryhook + script4
JSON-LD lint (Edit 完了時)PostToolUsevalidate_jsonld.pyfolio validatehook + script3
broken link 検出lychee runnerCI (GitHub Actions)7
双方向 link auto-materializePostToolUsebidir-materialize.pyfolio fixhook + script (Pattern C)8
caller marker checkfolio-architect (set 担当)PreToolUsecheck-caller-marker.shskill (set) + hook (verify)2
context injection (Tier 1 inventory 自動読込)folio-architectSessionStartinject-inventory.shfolio primehook + script5
inventory.json 自動 regeneratePostToolUse + FileChangedregen-inventory.pyfolio inventoryhook + CLI5

§7.3. minimal viable plugin scope (Phase X3 着手分)

folio-self-spec.html §7.2 が定義する完成形は 8 skill + 8 agent + 7-phase PR cycle だが、 試作駆動哲学に従い Phase X3 着手は 1 skill から:

Phase X3 minimal — 1 skill + 4 hook + 6 script + 1 CLI
categorycomponent役割
skills/ (1)folio-architect/SKILL.mdspec edit の唯一 author、 caller marker 設定の起点
hooks/hooks.json (4 hook)SessionStartinventory inject (Beads pattern §5.2)
PreToolUse: caller markerenv var 未 set or 異値で deny (twill pattern §5.5)
PreToolUse: path boundaryspec dir 外への作成を block
PostToolUse: JSON-LD lint + README updateschema check + index 自動更新
scripts/ (6)inject-inventory.shSessionStart / PreCompact で inventory.json を context inject
check-caller-marker.shPreToolUse、 rules.html §10.1 REQ-CM
check-path-boundary.shPreToolUse、 spec dir 外の spec 作成を block
lint-jsonld.sh + validate_jsonld.pyPostToolUse、 ajv/pyld 2 層検証
update-readme-index.sh + update_readme_index.py新 spec 追加時 README index 自動更新
link-integrity.pyCI script (lychee wrapper)、 broken link 0
bin/ (1)folio CLIinit / validate / inventory / prime / fix サブコマンド

§7.4. implementation 順序 (依存関係)

Step 1 (基盤): plugin.json + bin/folio (init + validate サブコマンド)
   ↓
Step 2 (boundary 強制): scripts/check-caller-marker.sh + check-path-boundary.sh
                       + PreToolUse hook 登録
   ↓
Step 3 (lint): scripts/lint-jsonld.sh + validate_jsonld.py + PostToolUse hook
   ↓
Step 4 (auto-update): scripts/update-readme-index.sh + PostToolUse hook
   ↓
Step 5 (context injection): scripts/inject-inventory.sh + SessionStart / PreCompact hook
                            + bin/folio prime
   ↓
Step 6 (skill): skills/folio-architect/SKILL.md (caller marker set の起点)
   ↓
Step 7 (CI integration): scripts/link-integrity.py + .github/workflows/spec-check.yml
   ↓
Step 8 (双方向 link materialize): scripts/bidir-materialize.py + PostToolUse hook (auto-fix mode)

各 step は独立して動作可能。 Phase X3 minimal は Step 1-3 のみで「動くもの」 を成立させ、 Step 4-8 は段階的に追加 (試作駆動哲学に合致)。

§7.5. 設計 4 原則

  1. declarative manifest (§4.1(a)): hooks.json で全 lifecycle を宣言、 script は実装 detail
  2. rule + fix + meta 三位一体 (§4.1(b)): 各 lint rule に severity + fix mode + 適用条件を .folio-lint.json で集約
  3. idempotent autofix (§4.2 + §6.4 Pattern C): atomic write、 dry-run mode、 suggestion/fix 分離
  4. 3 層防御 (§3.3 + §6.7): PostToolUse (即時) → pre-commit (--no-verify 保険) → CI (final gate)

§8. ADR 起票候補 (Q7 統合)

ADR ID 候補title内容関連 finding優先度
ADR-0003 plugin architecture: skill + hook + script + CLI 役割分担 folio plugin の最小構成 = 1 skill (folio-architect) + 4 hook + 6 script + 1 CLI (folio)。 P-11 binding 隔離原則を構造化。 §7.2 + §7.3 MUST (Phase X3 着手前)
ADR-0004 JSON-LD lint mechanism: ajv + pyld 2 層構成 JSON Schema validator (高速 structural) + JSON-LD processor (semantic / unmapped property)。 PostToolUse hook で起動、 exit 2 + stderr で Claude feedback。 §6.1 + §6.3 MUST
ADR-0005 双方向 link auto-materialize の実装場所と pattern log4brains の supersedeBy() → markAsSuperseder() domain entity + lifecycle side-effect handler pattern を採用、 PostToolUse hook で auto-fix mode (idempotent + atomic) §5.1 + §6.4 Pattern C SHOULD
ADR-0006 caller marker hook 実装 PreToolUse hook + env var で spec edit を folio-architect skill 専任化、 twill spec-write-boundary pattern 継承 §5.5 + §2.6 (a) MUST
ADR-0007 context injection mechanism (Beads-inspired) SessionStart + PreCompact hook で inventory.json (Tier 1) を agent に inject、 動的 issue 状態は folio prime CLI 経由 §5.2 + §7.3 MUST
ADR-0008 3 層防御原則 (PostToolUse / pre-commit / CI) layer 別役割: PostToolUse=AI 即時 feedback, pre-commit=--no-verify 保険, CI=final gate (bypass 不可) §3.3 + §6.7 MUST
ADR-0009 linter false positive 抑制 4 戦略 inline suppression comment / severity tuning / allowlist / temporal downgrade を併用。 ESLint + Ruff + golangci-lint の実績 pattern 継承 §6.5 SHOULD
ADR-0010 autofix 安全性原則 idempotent + atomic + suggestion/fix 分離 + meta.fixable 強制 + --fix-dry-run。 ESLint pattern を採用、 Biome 反面教師 §4.2 + §6.4 SHOULD
ADR-0011 inventory.json auto-generation timing spec file Edit/Write 後 (PostToolUse hook) + FileChanged hook (外部編集) で regen、 手動再生成は folio inventory CLI。 stale 状態は CI で detect §4.3 + §4.4 + §7.3 SHOULD
ADR-0012 hook 配置と plugin agent 制限の対処 plugin agents は hooks/mcpServers/permissionMode 非対応 (security)。 これらが必要な場合は .claude/agents/ にコピー、 または skill frontmatter hooks: で対応 §2.5 SHOULD

起票手順: 各 ADR について (1) user に提示 → (2) user 承認取得 → (3) scratch/decisions/ADR-NNNN-<slug>.html に Accepted status で起票 → (4) 関連 spec section に cross-ref を追加。 CLAUDE.md の制約により自動起票は禁止。

§9. Open Questions / Future Work

§9.1. WARNING (実装段階で要確認)

  1. twill hooks.json の完全構成: §5.5 の抜粋は folio が継承すべき要点 pattern に絞っており、 twill の完全な hook 構成 (host-safety / deps-yaml-guard / phase-gate / failure-learn / PostCompact) は省略している。 folio 設計時に実 file (~/projects/local-projects/twill/main/plugins/twl/hooks/hooks.json) を直接参照のこと。
  2. log4brains TypeScript 行番号: §5.1 の関数名 (supersedeBy / markAsSuperseder / addLinkNoDuplicate) は verified だが、 行番号は本調査範囲外。 将来 log4brains バージョンアップで実装位置が変わっても追跡可能なように、 直接 URL (Adr.ts) を保持する。
  3. ADR 起票の user 承認制約: §8 の ADR-0003〜ADR-0012 は推奨候補。 folio CLAUDE.md により scratch/decisions/ 配下への新規起票は user 承認必須。 自動生成 + commit は禁止。 各 ADR を起票する前に user に提示し承認を取得する手続きを徹底する。
  4. architecture/ 未存在状態と check-path-boundary.sh の対象パス: folio CLAUDE.md では architecture/ dir は Phase X3 完了後に user 主導で作成予定であり、 現時点では存在しない。 §7.2 / §7.3 の path boundary 機能は実装時に対象パスを scratch/specs/ (現状) から architecture/spec/ (Phase X3 完了後) に切替可能な userConfig 駆動の設計とすること。 例: ${FOLIO_SPEC_PATH:-scratch/specs}

§9.2. 追加検討事項

  1. 完成形 8 skill vs Phase X3 minimal 1 skill の関係: folio-self-spec.html §7.2 は完成形として 8 skill (folio-init / folio-architect / folio-spec-edit / folio-validate / review-* × 4) を定義。 本レポート §7.3 の minimal viable plugin は「1 skill (folio-architect) から着手」 を推奨。 試作駆動哲学に合致した段階的成長 (1 → 8) を意図しており、 完成形 8 skill は Phase X3 完遂後 (Phase X4+) の目標と位置付ける。
  2. PreToolUse deny bug (#37210) の動作確認: §2.3 の注記で「exit 2 + stderr が確実な fallback」 と述べているが、 twill spec-write-boundary.sh は実際には exit 0 + JSON output のみ (exit 2 未使用)。 folio 実装時は Phase X3 Step 2 (boundary 強制) で empirically verify する。
  3. Beads DeepWiki sources の二次性: §5.2 の Beads 記述は GitHub README (一次) + DeepWiki (AI 生成 wiki、 二次) を参照。 DeepWiki は信頼度高いが AI 生成のため、 重要設計判断は実 source code を一次資料として優先する。

§9.3. 本調査の範囲外 (将来の調査候補)

§10. References

全 76 sources (公式 docs 35 + GitHub リポジトリ 14 + 技術 blog / 比較記事 23 + ローカル twill 4)。 確認日 2026-05-23。

§10.1. 公式 docs (一次資料、 35 件)

Claude Code (7 件)

  1. Create plugins - Claude Code Docs
  2. Plugins reference - Claude Code Docs
  3. Extend Claude with skills - Claude Code Docs
  4. Hooks - Claude Code Docs
  5. Create custom subagents - Claude Code Docs
  6. Agent Skills overview - platform.claude.com
  7. Claude Code Security

Git hook frameworks (6 件)

  1. pre-commit official documentation
  2. Husky official documentation
  3. Lefthook GitHub README
  4. lint-staged GitHub README
  5. simple-git-hooks GitHub README
  6. pre-commit.ci official site

Linter / SSG (15 件)

  1. ESLint Plugins Documentation
  2. ESLint Custom Rules
  3. ESLint Architecture
  4. ESLint Shareable Configs
  5. Stylelint Writing Plugins
  6. Prettier Plugins
  7. Sphinx Extension API
  8. Sphinx Application API
  9. Sphinx Event Callbacks API
  10. MkDocs Plugin Dev Guide
  11. Antora Extensions Overview
  12. Antora Generator Events Reference
  13. Docusaurus Plugin Lifecycle APIs
  14. Backstage External Integrations
  15. Backstage Life of an Entity
  16. ESLint Custom Rule Tutorial

ADR / spec OSS (2 件)

  1. Specmatic Backward Compatibility Rules
  2. ArchUnit User Guide

JSON-LD / validation (5 件)

  1. Ajv JSON schema validator
  2. jsonschema Python
  3. W3C SHACL Spec
  4. ESLint Configure Rules
  5. golangci-lint False Positives

§10.2. GitHub リポジトリ (一次ソース、 14 件)

  1. thomvaill/log4brains
  2. log4brains Adr.ts (TypeScript verified)
  3. steveyegge/beads
  4. adr/madr
  5. npryce/adr-tools
  6. stoplightio/spectral
  7. TNG/ArchUnit
  8. digitalbazaar/pyld
  9. digitalbazaar/jsonld.js README
  10. ajv-validator/ajv-cli
  11. RDFLib/pySHACL
  12. mulesoft-labs/json-ld-schema (archived 2024/01)
  13. chharvey/schemaorg-jsd
  14. PreToolUse permissionDecision deny ignored - Issue #37210

§10.3. 技術 blog / 比較記事 (二次資料、 23 件)

  1. Git Hooks with Claude Code (dev.to)
  2. Git Hook Frameworks Comparison 2026 (Andy Madge)
  3. Claude Code Hooks production CI/CD patterns (Pixelmojo)
  4. husky vs lefthook vs lint-staged 2026 (PkgPulse)
  5. Lefthook advanced config (Evil Martians)
  6. Why Pre-Commit Hooks Fail at Stopping Secrets (Xygeni)
  7. log4brains ADR link resolver
  8. log4brains Use Next.js for SSG
  9. Beads AI Tool Integrations (DeepWiki)
  10. Beads Agent Workflow Guidelines (DeepWiki)
  11. Beads MCP Server (DeepWiki)
  12. Beads Claude Plugin (DeepWiki)
  13. Beads memory for coding agent (Ian Bull)
  14. ArchUnit Baeldung intro
  15. Claude Code Hooks Tutorial (Blake Crosley)
  16. Claude Code Hook Control Flow (Steve Kinney)
  17. Pre-commit vs CI (Sebastian Witowski)
  18. Python os.replace() atomic file updates
  19. Scraping JSON-LD with BeautifulSoup
  20. Core Architecture lint-staged (DeepWiki)
  21. Claude Code Hooks reference (eesel.ai)
  22. PyLD - PyPI
  23. log4brains official site (additional ADRs)

§10.4. ローカルファイル (twill plugin、 folio predecessor verified、 4 件)

  1. ~/projects/local-projects/twill/main/plugins/twl/hooks/hooks.json — twill hooks.json (verified)
  2. ~/projects/local-projects/twill/main/architecture/spec/gate-hook.html — twill gate-hook spec
  3. ~/projects/local-projects/twill/main/plugins/twl/skills/tool-architect/refs/spec-management-rules.md — twill R-N 規律
  4. ~/projects/local-projects/twill/main/architecture/decisions/ADR-0013-spec-clean-architecture.md — twill ADR-0013

§11. 調査メタデータ

調査日
2026-05-23
session_id
5592bf08
parallel researcher
5 (researcher-1〜5)
収集 sources
76 (公式 35 + GitHub 14 + 技術 blog 23 + ローカル twill 4)
critique 判定
PASS (WARNING 4 件は §9 Open Questions に反映済)
snapshot dir
/tmp/research-search-5592bf08/
前回調査との関係
本レポートは spec-graph-management-research.html (session c3c53fbb、 2026-05-22) の plugin architecture 実装局面における後続調査。 前回は spec 関係性管理 + AI agent indexing を扱い、 本回は plugin harness 設計 (hook + script + skill + CLI) を扱う。
folio 整合性
constitution P-11 (HOW 禁止)、 P-12 (Layer 0 一体配布)、 試作駆動哲学 (2026-05-22 user 確定) と整合。 ADR 起票候補は user 承認必須 (CLAUDE.md 制約)。