Socratic Code Theory Recovery 标志

Socratic Code Theory Recovery

组织
LLM-Coding
socratic-code-theory-recovery

Recover the "theory" (Naur 1985) of an existing codebase through recursive question refinement before writing documentation. Use on brownfield projects where the spec is missing — produces a Question Tree separating what is answerable from code (with evidence) from what must be asked of the team (routed by role). Phase 1 builds the tree; team answers the OPEN leaves; Phase 2 synthesizes PRD, Cockburn use cases, arc42 architecture, and Nygard ADRs from the answered tree.

Add to TypingMind

概览

发布者LLM-Coding
代码仓库Semantic-Anchors
技能名称socratic-code-theory-recovery
星标数
521
复刻数
45
附带文件
8
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 8 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 LLM-Coding 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Socratic Code Theory Recovery AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/LLM-Coding/Semantic-Anchors/tree/main/plugins/semantic-anchors/skills/socratic-code-theory-recovery
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/LLM-Coding/Semantic-Anchors.git /tmp/Semantic-Anchors
mkdir -p .claude/skills
cp -r /tmp/Semantic-Anchors/plugins/semantic-anchors/skills/socratic-code-theory-recovery .claude/skills/socratic-code-theory-recovery
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Socratic Code Theory Recovery,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Socratic Code Theory Recovery。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Socratic Code Theory Recovery 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Socratic Code-Theory Recovery

Reverse-engineer a bounded context into documentation without hallucinating the parts the code cannot tell you.

On invocation

When this skill is invoked:

  1. Check whether the user named a bounded context. Look at the same message that invoked the skill and at the immediately preceding messages. A valid bounded-context pointer is a path (relative or absolute) to a directory, plus a short human-readable name for what the context is (e.g. src/auth, "Authentication"). If both are present, proceed to Phase 1.

  2. If no bounded context is named, ask for it before doing anything else. Do not start Phase 1 against the current working directory by default — Phase 1 produces files (QUESTION_TREE-<context-name>.adoc, OPEN_QUESTIONS-<context-name>.adoc) and running it on the wrong directory wastes work. Ask exactly:

    Which bounded context should I apply Socratic Code-Theory Recovery to? Give me a directory path (the bounded context's code root) and a short human-readable name. If you want the whole current repo treated as one bounded context, say so explicitly.

  3. Once you have the pointer, run Phase 1. Use prompts/phase-1-question-tree.md — substitute [bounded context path] with the user's path and [context-name] with the kebab-cased human-readable name. Do not change the leaf classification, Q-ID scheme, or the output-file naming scheme.

  4. Stop after Phase 1. Tell the user that Phase 1 is complete, where the two output files are, and that the next step is routing OPEN_QUESTIONS-<context-name>.adoc to the team. Phase 2 is gated on the file, not on being asked: before starting Phase 2 — even when the user explicitly requests it — check that every [OPEN] leaf in OPEN_QUESTIONS-<context-name>.adoc has either a team answer or an explicit (deferred) marker. If any leaf has neither, do not run Phase 2; list the unanswered leaves instead.

When to use this skill

Use this skill on a brownfield codebase when:

  • Documentation is missing, outdated, or untrusted.
  • A change is about to be made and you need a spec before you can change safely.
  • You want documentation that distinguishes code-derived facts from team-supplied context — auditable, not generated prose.
  • You want to surface the open questions in the system, not just synthesize an answer the team has not seen.

Do not use this skill when:

  • You are doing greenfield development — use the spec-driven workflow instead.
  • The whole system needs to be documented at once — work one bounded context at a time.
  • The code is not runnable — fix that first.

The contract

This skill implements the Socratic Code-Theory Recovery contract from the Semantic Anchors project. The methodology rests on Peter Naur's 1985 paper Programming as Theory Building: a program's theory lives in the heads of its developers and cannot be fully captured in code alone. A documentation-recovery process that ignores this produces confident-looking prose that fills in the gaps with invention.

The fix: model the gaps explicitly. Every question about the system is either [ANSWERED] from code (with file:line evidence) or [OPEN] (with a category and the role that must answer it). The OPEN leaves are the handoff to humans.

Two-phase workflow

                  ┌────────────────────────────────┐
   Phase 1        │  CODE  ──►  Question Tree       │
                  │             ├─ [ANSWERED] leaves│
                  │             └─ [OPEN] leaves    │
                  └────────────────┬───────────────┘
                                   ▼
                  ┌────────────────────────────────┐
   Between        │  OPEN_QUESTIONS-<context>.adoc │
                  │  ──► team (routed by role)     │
                  │  ──► answers fill in OPENs     │
                  └────────────────┬───────────────┘
                                   ▼
                  ┌────────────────────────────────┐
   Phase 2        │  Answered tree ──► Docs         │
                  │  PRD · Cockburn UCs · arc42 ·   │
                  │  Nygard ADRs (claims cite code) │
                  └────────────────────────────────┘

Phase 1: Build the Question Tree

Use prompts/phase-1-question-tree.md. Adapt the bounded-context path and the Q1-Q5 wording; do not change the fixed second level, the leaf classification, the Q-ID scheme, or the output-file naming scheme.

Outputs (named after the context so sequential runs on different bounded contexts never overwrite each other):

  • QUESTION_TREE-<context-name>.adoc — the full hierarchical reasoning trace
  • OPEN_QUESTIONS-<context-name>.adoc — only the [OPEN] leaves, grouped by Ask role

The five root questions decompose into a fixed second level — the same enumerated node set on every run, so Q-IDs are stable and trees from different runs can be diffed node-by-node. Adaptive, code-driven decomposition applies only below the fixed level. The fixed nodes:

  • Q1.1–Q1.6 — product identity, primary users, channels, why-built, success metrics, segment priority.
  • Q2.1–Q2.6 — actors, use-case catalog, per-interface system specs, data/entity model, acceptance criteria, cross-cutting business rules. See references/cockburn-use-cases.md.
  • Q3.1–Q3.12 — the twelve arc42 chapters, in arc42 order. See references/arc42.md. Design rationale lives in the Q3.9 chapter — see references/nygard-adrs.md. Q3.2 (Architecture Constraints) additionally carries a fixed third level — Q3.2.1 technical, Q3.2.2 organizational/process, Q3.2.3 conventional constraints — because these rarely live in dense code; for this branch, CLAUDE.md/AGENTS.md, CONTRIBUTING files, CI workflows, and linter configs are valid evidence sources.
  • Q4.1–Q4.8 — the eight ISO/IEC 25010 characteristics; Q4.9 — which characteristic has priority. See references/iso-25010.md.
  • Q5.1–Q5.5 — technical debt, security risks, operational risks, dependency/supply-chain risks, scaling/performance risks.

Every fixed node is emitted even when its only leaf is [OPEN] or [ANSWERED: not applicable].

Depth below the fixed level is adaptive, not fixed. A node is a leaf only when its question can be answered with specific file:line evidence or definitively marked [OPEN]. If the honest answer would still be coarse — a whole directory as evidence, one paragraph for an entire arc42 chapter — the node decomposes further (under a four-level cap below each fixed node). Tree depth therefore tracks code density: a small bounded context yields a shallow tree, a large one a deep tree. The fixed skeleton stays diffable; only the depth varies. This prevents the thin-documentation failure where a large context produces one leaf per arc42 chapter and Phase 2 cannot synthesize a substantial chapter without inventing detail.

Leaf classification rules and Q-ID scheme: references/output-schema.md.

Worked examples — one [ANSWERED] and one [OPEN] leaf for each major branch: references/examples.md.

Between Phases: Team answers the OPEN leaves

Route OPEN_QUESTIONS-<context-name>.adoc to the people whose role appears in each section: Product Owner, Architect, Developer, Domain Expert, Operations. In one controlled experiment with a 13,000-line Go codebase, 11 targeted OPEN questions were enough to close the gap to the original documentation.

Team answers are written directly into OPEN_QUESTIONS-<context-name>.adoc under each question, marked clearly. Do not call Phase 2 until every OPEN leaf has either an answer or an explicit (deferred) marker.

Phase 2: Synthesize documentation

Use prompts/phase-2-synthesize.md. The Phase 2 LLM reads the answered tree and produces:

  • PRD from the Q1 branch (problem, users, goals, success criteria)
  • Specification from the Q2 branch (Cockburn use cases at User Goal level, system use cases for each technical interface, supplementary specifications)
  • arc42 with all 12 chapters from the Q3 branch
  • Nygard ADRs with Pugh Matrix from the Q3.9 branch

Code-derived claims cite the file:line evidence from their [ANSWERED] leaf — a reference to the code, the only durable, canonical artifact. Team-supplied information is marked (team answer). The Question Tree is temporary scaffolding, so its Q-IDs are not written into the final documents; during synthesis every claim is still traced back to a leaf as a build-time check. This dual traceability — code evidence plus team input — is the difference from a simple reverse-engineering prompt that fills in gaps silently.

What the LLM can and cannot recover

A controlled experiment (deleting documentation from a greenfield project and regenerating it from code) showed:

Derivable from code: functional requirements, acceptance criteria, building-block views, glossary, security mechanisms, crosscutting concepts.

NOT derivable from code: business context, design rationale (the ADR "why"), quality-goal priorities, stakeholder concerns, aspirational features, performance budgets, tutorials, review results.

If your synthesized documentation contains a claim from the second list without a (team answer) marker, the LLM hallucinated it. Mark it [OPEN] and ask the team.

Spec drift and reconciliation

After this skill produces documentation, the implementation LLM will add security hardening, validation rules, and edge cases that are not in the spec. This is structural, not a discipline problem. Re-run Phase 1 against the current code periodically — before a release, after a security review, before onboarding — and diff against the existing spec. The diff reveals NEW (in code, not in spec), CHANGED (diverged), and DEAD (in spec, not in code).

Further reading

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Socratic Code Theory Recovery AI 技能有什么作用?

Recover the "theory" (Naur 1985) of an existing codebase through recursive question refinement before writing documentation. Use on brownfield projects where the spec is missing — produces a Question Tree separating what is answerable from code (with evidence) from what must be asked of the team (routed by role). Phase 1 builds the tree; team answers the OPEN leaves; Phase 2 synthesizes PRD, Cockburn use cases, arc42 architecture, and Nygard ADRs from the answered tree.

为什么在 TypingMind 中使用 Socratic Code Theory Recovery?

因为您只需安装一次,就能搭配任何模型使用。Socratic Code Theory Recovery 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Socratic Code Theory Recovery?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/LLM-Coding/Semantic-Anchors/tree/main/plugins/semantic-anchors/skills/socratic-code-theory-recovery。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Socratic Code Theory Recovery?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Socratic Code Theory Recovery 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Socratic Code Theory Recovery 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Socratic Code Theory Recovery AI 技能免费吗?

是的。LLM-Coding 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇