diff --git a/.thinkir-project-rules.md b/.thinkir-project-rules.md new file mode 100644 index 0000000..81ac6c2 --- /dev/null +++ b/.thinkir-project-rules.md @@ -0,0 +1,146 @@ +# ThinkIR 项目规则模板 + +## 当在项目中使用 ThinkIR 时,请遵循以下规则: + +### 1. 代码组织规范 + +#### ThinkIR 脚本位置 +``` +project/ +├── thinkir/ +│ ├── scripts/ # ThinkIR 脚本集合 +│ ├── templates/ # 脚本模板 +│ ├── examples/ # 示例输出 +│ └── rules.md # 项目特定规则 +└── src/ + └── generated/ # 生成的源代码 +``` + +### 2. ThinkIR 使用流程 + +#### Step 1: 需求分析 +- 明确编程目标 +- 确定约束条件 +- 选择合适的 ThinkIR 模式 + +#### Step 2: 脚本编写 +- 使用模板开始 +- 添加逻辑节点 +- 设置约束和链接 + +#### Step 3: 执行和验证 +- 选择执行模式 +- 验证生成结果 +- 调试和优化 + +#### Step 4: 保存和归档 +- 保存 ThinkIR 脚本 +- 记录执行结果 +- 更新项目文档 + +### 3. 项目集成规范 + +#### 新项目初始化 +```bash +# 创建项目结构 +mkdir -p thinkir/{scripts,templates,examples} +cp templates/thinkir-template.cpp thinkir/templates/ +``` + +#### 生成代码的规范 +- 所有生成的代码必须通过 ThinkIR 生成 +- 保留原始 ThinkIR 脚本以便复现 +- 添加必要的注释和文档 + +### 4. 团队协作规范 + +#### 代码审查 +- 审查 ThinkIR 脚本质量 +- 验证生成代码的正确性 +- 确保符合项目标准 + +#### 知识共享 +- 记录常用的 ThinkIR 模式 +- 创建项目特定的 ThinkIR 库 +- 分享最佳实践 + +### 5. 版本控制 + +#### ThinkIR 脚本管理 +- 将 ThinkIR 脚本纳入版本控制 +- 使用有意义的文件名 +- 添加执行说明 + +#### 生成代码追踪 +- 记录生成 ThinkIR 脚本的 commit +- 标注代码来源 +- 便于追踪和回溯 + +### 6. 质量保证 + +#### ThinkIR 脚本质量 +- 使用清晰的逻辑节点 +- 添加适当的约束 +- 确保逻辑链完整 + +#### 生成代码质量 +- 通过静态分析 +- 执行单元测试 +- 进行性能测试 + +### 7. 项目特定规则 + +根据项目类型,可以添加特定的 ThinkIR 规则: + +#### Web 项目规则 +```bash +# 默认约束 +st("Use modern JavaScript/TypeScript") +st("Include error handling") +st("Follow project coding style") +``` + +#### 数据科学项目规则 +```bash +# 默认约束 +st("Include data validation") +st("Add performance metrics") +st("Use pandas/numpy best practices") +``` + +#### API 项目规则 +```bash +# 默认约束 +st("Include OpenAPI documentation") +st("Add rate limiting") +st("Implement proper error codes") +``` + +### 8. 快速命令 + +#### 项目快捷命令 +```bash +# 初始化 ThinkIR 环境 +/thinkir init + +# 查看项目状态 +/thinkir status + +# 切换模式 +/thinkir mode [command|exec|translate|silent] + +# 创建新脚本 +/thinkir new [script_name] +``` + +### 9. 故障排除 + +#### 常见问题 +1. **LLM 兼容性** - 检查 LLM 是否支持 ThinkIR +2. **输出格式** - 确认是否在正确的模式下 +3. **约束失效** - 检查语法和约束条件 + +#### 调试步骤 +1. 使用 Translation 模式查看脚本 +2. 使用 Silent 模式查看干净输出 +3. 逐步添加节点进行测试 \ No newline at end of file diff --git a/.thinkir-rules.md b/.thinkir-rules.md new file mode 100644 index 0000000..1b498a9 --- /dev/null +++ b/.thinkir-rules.md @@ -0,0 +1,66 @@ +# ThinkIR 项目规则 + +当在项目中启用 ThinkIR 模式时,以下规则将生效: + +## 自动规则 + +### 1. 模式检测 +- 如果输入以 `//` 开头,自动进入 **Standard Mode** +- 其他输入默认使用 **Command Line Mode** + +### 2. 输出格式化 +- Phase 1 使用 Markdown 代码块显示 ThinkIR 脚本 +- Phase 2 使用结构化格式显示拓扑和节点 + +### 3. 环境初始化 +- 自动加载 ThinkIR.txt 规范 +- 输出 `// ThinkIR Environment Ready.` 作为确认 + +## 快捷指令 + +### 模式切换 +``` +// use execution mode → 切换到 Execution Mode +// use translation mode → 切换到 Translation Mode +// use silent mode → 切换到 Silent Mode +// use standard mode → 切换到 Standard Mode +``` + +### 退出 ThinkIR +``` +// [ThinkIR Exit] → 完全退出 ThinkIR 模式 +``` + +## 编程最佳实践 + +### 推荐的 ThinkIR 结构 +```cpp +#include "ThinkIR.hpp" + +LLMctx main() { + // 1. 设置上下文和目标 + LLMctx logic = LLMctx::keyword("Domain Expert"); + logic.purpose("Clear objective statement"); + + // 2. 添加约束(可选) + logic.st("Code must include error handling"); + + // 3. 创建逻辑节点 + id t1 = logic.think("First logical deduction"); + id t2 = logic.think("Second logical deduction"); + logic.link(t1, t2); + + // 4. 创建纯净容器(推荐) + LLMctx pure; + + // 5. 生成最终输出 + pure.push(logic.program("Generate code with specific requirements")); + + return pure; +} +``` + +### 节点类型说明 +- `[Think]` - 推理节点 +- `[Code]` - 代码节点 +- `[Create]` - 文档节点 \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..5f7e5d9 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,67 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +ThinkIR is a specification and documentation project for an intermediate scripting language designed to bridge natural language and programming. It's not a traditional software project but rather a conceptual framework for interacting with LLMs using structured intermediate representation. + +## Key Files + +- **README.md** - Comprehensive documentation about ThinkIR concept, usage examples, and comparison with natural language prompting +- **ThinkIR.txt** - XML specification file (version 1.18.71) containing the complete language specification, operators, execution rules, and runtime pipeline +- **BoostLicense** - Boost Software License file + +## Development Workflow + +Since this is a specification project, there are no traditional development commands: + +- **No build system** - This project doesn't use npm, yarn, pnpm, or any package manager +- **No tests** - There is no test framework or testing infrastructure +- **No scripts** - No package.json scripts or Makefiles + +## ThinkIR Language Architecture + +ThinkIR is based on C++26 syntax and operates through a dual-layer graph architecture: + +### Core Components +1. **Logic Graph** (Bottom Layer) - Persistent reasoning nodes created with `think()` and connected with `link()` +2. **Artifact Graph** (Top Layer) - Final deliverables (code, docs) created with `push()` and rendered with `create()`/`program()` + +### Execution Pipeline +- **Phase 1**: Translation - Maps natural language to ThinkIR script +- **Phase 2**: Serialization - Outputs topology and node content + +### Key Operators +- `think()` - Creates persistent inference nodes +- `st()` - Adds hard constraints +- `link()` - Establishes logical dependencies +- `keyword()`/`purpose()` - Sets context and goals +- `push()` - Promotes artifacts to output +- `create()` - Generates natural language text +- `program()` - Generates executable code + +### Environment Modes +- **Command Line Mode** (default) - Phase 1 + Phase 2 +- **Execution Mode** - Phase 2 only +- **Translation Mode** - Phase 1 only +- **Silent Mode** - Full pipeline, Phase 1 hidden +- **Standard Mode** - Comment input exits ThinkIR mode + +## Working with ThinkIR + +When modifying this specification: +1. **ThinkIR.txt is the source of truth** - All language specifications are defined here +2. **XML structure must be maintained** - The specification follows strict XML formatting +3. **Version tracking** - The specification version is tracked in the XML header +4. **Update README.md** - When adding new features or changing behavior, update examples and documentation + +## Compatibility Notes + +The specification mentions compatibility with various LLMs: +- Gemini 3 Fast/3 Thinking/3.1 Pro: Very good +- DeepSeek v4: Very good +- GPT-5.3: Good +- Claude Sonnet 4.6: General + +When updating the specification, consider these compatibility constraints as different LLMs may have varying support for prompt injection techniques. \ No newline at end of file diff --git a/README.md b/README.md index 763d995..a5cd6ad 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,123 @@ # ThinkIR - Think Intermediate Representation, TIR -使用自然语言来进行人类和 LLM 间的对话是低效率的,因为自然语言是弱逻辑和低熵的。 +[TOC] -* 我们需要一种强逻辑性并且对 LLM 友好的输入语言,使用伪代码来操控 LLM 的思维链和输出结果。 +## 目录 +- [项目概述](#项目概述) +- [快速开始](#快速开始) +- [工具和模板](#工具和模板) +- [使用指南](#使用指南) +- [项目集成](#项目集成) +- [高级特性](#高级特性) -* 我们将 **提示词 --> 程序代码** 的过程视作是 LLM 的解压过程,与 LLM 的训练过程相反,训练是一个压缩过程。 +## 项目概述 -* Vibe Coding 是 **自然语言 --> 程序代码** 的解压过程,这个过程是高度随机的。 +## 核心理念 -* 考虑使用 **自然语言 --> IR(中间语言)--> 程序代码** 来降低随机性并提高可控性,IR 可以被人为修改和微调。 +使用自然语言来进行人类和 LLM 间的对话是低效率的,因为自然语言是弱逻辑和低熵的。 -* 在数百轮沟通后,LLM 终于生成了你想要的编程结果。执行 **程序代码 --> IR**,可以告诉你 **如何一次性让 LLM 生成此结果**。 +- **强逻辑输入**: 需要一种强逻辑性并且对 LLM 友好的输入语言,使用伪代码来操控 LLM 的思维链和输出结果 +- **解压过程**: 将 **提示词 --> 程序代码** 的过程视作是 LLM 的解压过程,与 LLM 的训练过程相反,训练是一个压缩过程 +- **降低随机性**: Vibe Coding 是 **自然语言 --> 程序代码** 的解压过程,这个过程是高度随机的。使用 **自然语言 --> IR(中间语言)--> 程序代码** 来降低随机性并提高可控性,IR 可以被人为修改和微调 +- **可重现性**: 在数百轮沟通后,LLM 终于生成了你想要的编程结果。执行 **程序代码 --> IR**,可以告诉你 **如何一次性让 LLM 生成此结果** **不要向别人分享你的提示词,而是分享你的 IR。提示词生成的代码的过程是高度随机的,但是 IR 生成代码的过程是高度可控的。** + +## 工具和模板 + +ThinkIR 提供了一套完整的工具和模板,帮助您更有效地使用 ThinkIR: + +### 🛠️ 核心工具 + +1. **Skill 支持** - 集成 ThinkIR 到您的开发工作流 + - `skill-thinkir.md` - ThinkIR skill 规范文档 + - 支持多种模式切换和自动格式化 + +2. **项目规则** - 标准化 ThinkIR 在项目中的使用 + - `.thinkir-rules.md` - 基础使用规则 + - `.thinkir-project-rules.md` - 项目集成规范 + +3. **模板系统** - 快速创建 ThinkIR 脚本 + - `templates/thinkir-template.cpp` - 标准模板 + - 支持自定义模板和项目特定规则 + +4. **初始化脚本** - 快速设置 ThinkIR 环境 + - `scripts/thinkir-init.sh` - 自动化环境设置 + - 创建必要的目录结构 + +### 📚 文档资源 + +1. **使用指南** - 详细的使用教程和最佳实践 + - `THINKIR_USAGE.md` - 完整使用指南 + - 包含常见模式和调试技巧 + +2. **规范文档** - 语言规范和参考 + - `ThinkIR.txt` - 完整语言规范(v1.18.71) + - 包含所有操作符和执行规则 ## About ThinkIR 我们设计了一个被称为ThinkIR的脚本语言,它介于自然语言和编程语言之间。用于将 Vibe Coding 变得精细化和可控制,而不是由LLM随机产生垃圾代码。将ThinkIR.txt输入给LLM,即可让LLM进入ThinkIR模式。ThinkIR是使用C++语法的伪代码脚本语言。 +## 快速开始 + +### 方法一:使用初始化脚本(推荐) + +```bash +# 1. 运行初始化脚本 +./scripts/thinkir-init.sh + +# 2. 复制 ThinkIR.txt 内容到 LLM +# 3. 等待确认响应:// ThinkIR Environment Ready. +# 4. 开始使用 ThinkIR +``` + +### 方法二:手动设置 + +```bash +# 1. 创建项目目录结构 +mkdir -p thinkir/{scripts,templates,examples} + +# 2. 复制模板 +cp templates/thinkir-template.cpp thinkir/templates/ + +# 3. 复制规则文件 +cp .thinkir-rules.md thinkir/rules.md + +# 4. 使用 ThinkIR.txt 进入模式 +``` + +### 基本使用流程 + +1. **加载规范**:将 ThinkIR.txt 内容粘贴给 LLM +2. **确认模式**:等待 `// ThinkIR Environment Ready.` +3. **输入指令**: + - 直接输入自然语言(Command Line Mode) + - 或使用模式切换指令 +4. **获取输出**:查看 Phase 1(脚本)和 Phase 2(结果) + +## 快速命令 + +### 模式切换 +```bash +// use execution mode # 执行模式 +// use translation mode # 翻译模式 +// use silent mode # 静默模式 +// use standard mode # 标准模式(// 开头) +``` + +### 常用操作 +```bash +# 创建新脚本 +/thinkir new + +# 查看项目规则 +/thinkir rules + +# 格式化输出 +/thinkir format +``` + ## Quick Start with Gemini 将ThinkIR.txt输入给LLM,或是将ThinkIR.txt中的内容粘贴并输入给LLM,即可进入ThinkIR模式。 @@ -340,3 +440,130 @@ ThinkIR 的实现机理是提示词注入,改变 LLM 的工作模式和输出 | DeepSeek v4 | 非常好 | | GPT-5.3 | 好 | | Claude Sonnet 4.6 | 一般 | + +## 项目集成 + +### 将 ThinkIR 集成到您的项目中 + +1. **初始化项目** +```bash +# 克隆或下载 ThinkIR 项目 +git clone [repository-url] +cd project-name + +# 运行初始化脚本 +./scripts/thinkir-init.sh +``` + +2. **创建项目特定规则** +```bash +# 在项目根目录创建 .thinkir-project-rules +echo "// Project-specific ThinkIR rules" > .thinkir-project-rules +``` + +3. **设置项目结构** +``` +your-project/ +├── .thinkir-project-rules # 项目规则 +├── thinkir/ +│ ├── scripts/ # ThinkIR 脚本 +│ ├── templates/ # 自定义模板 +│ └── examples/ # 示例输出 +└── src/ + └── generated/ # ThinkIR 生成的代码 +``` + +### 不同项目的 ThinkIR 配置 + +#### Web 项目 +```bash +// .thinkir-project-rules +st("Use TypeScript/JavaScript") +st("Include React/Vue/Angular") +st("Follow project linting rules") +``` + +#### API 项目 +```bash +// .thinkir-project-rules +st("Include OpenAPI/Swagger") +st("Add authentication middleware") +st("Implement proper error handling") +``` + +#### 数据科学项目 +```bash +// .thinkir-project-rules +st("Use pandas/numpy/scikit-learn") +st("Include data visualization") +st("Add Jupyter notebook examples") +``` + +## 高级特性 + +### 1. 自定义模板 + +创建项目特定的 ThinkIR 模板: +```cpp +// templates/my-project-template.cpp +#include "ThinkIR.hpp" + +LLMctx main() { + LLMctx logic = LLMctx::keyword("[Your Domain]"); + logic.purpose("[Your Goal]"); + + // Project-specific constraints + logic.st("[Project Requirement 1]"); + logic.st("[Project Requirement 2]"); + + // Your logic here + id t1 = logic.think("[First step]"); + id t2 = logic.think("[Second step]"); + logic.link(t1, t2); + + LLMctx pure; + pure.push(logic.program("[Generate output]")); + return pure; +} +``` + +### 2. 自动化工作流 + +使用脚本自动化 ThinkIR 流程: +```bash +#!/bin/bash +# scripts/generate-code.sh + +# 1. 生成 ThinkIR 脚本 +echo "Generating ThinkIR script..." +cat > temp_script.cpp << EOF +# [ThinkIR script here] +EOF + +# 2. 执行脚本 +echo "Executing ThinkIR..." +# [Execution logic here] + +# 3. 保存结果 +echo "Saving results..." +# [Save logic here] +``` + +### 3. 版本控制集成 + +将 ThinkIR 脚本纳入版本控制: +```bash +# .gitignore +# 忽略生成的代码,保留 ThinkIR 脚本 +src/generated/ +!thinkir/scripts/ +!thinkir/templates/ +``` + +## 最佳实践 + +1. **保持 ThinkIR 脚本简洁** - 避免过度复杂的逻辑 +2. **使用纯净容器** - 过滤推理过程,只显示最终结果 +3. **版本控制关键脚本** - 重要的 ThinkIR 脚本应该保存在仓库中 +4. **文档化模式** - 记录为什么选择特定的 ThinkIR 模式 +5. **测试生成代码** - 始终验证 ThinkIR 生成的代码质量 diff --git a/THINKIR_USAGE.md b/THINKIR_USAGE.md new file mode 100644 index 0000000..5a3d2a3 --- /dev/null +++ b/THINKIR_USAGE.md @@ -0,0 +1,203 @@ +# ThinkIR 使用指南 + +## 快速开始 + +### 1. 基础使用流程 + +**Step 1**: 进入 ThinkIR 模式 +- 将 ThinkIR.txt 的内容粘贴给 LLM +- LLM 会回复 `// ThinkIR Environment Ready.` + +**Step 2**: 输入你的需求 +- 直接用自然语言描述你的编程任务 +- 例如:"写一个Python函数来计算斐波那契数列" + +**Step 3**: 获取 ThinkIR 输出 +- Phase 1: 生成的 ThinkIR 脚本 +- Phase 2: 执行结果(代码/文档) + +### 2. 模式切换 + +**Command Line Mode(默认)** +```bash +# 直接输入需求 +写一个Python爬虫来抓取网页标题 +``` + +**Execution Mode** +```bash +// use execution mode +# 然后直接粘贴 ThinkIR 脚本 +``` + +**Translation Mode** +```bash +// use translation mode +# 只会生成 ThinkIR 脚本,不会执行 +``` + +**Silent Mode** +```bash +// use silent mode +# 只输出最终结果,不显示 ThinkIR 脚本 +``` + +**Standard Mode** +```bash +// 注释内容 +# 正常的 LLM 对话模式 +``` + +## 高级技巧 + +### 1. 精确控制输出 + +使用纯净容器过滤不需要的节点: +```cpp +LLMctx main() { + LLMctx logic = LLMctx::keyword("Python Dev"); + logic.st("Code must include type hints"); + + // 推理过程(不会显示在最终输出中) + id t1 = logic.think("Use list comprehension for efficiency"); + id t2 = logic.think("Add error handling for edge cases"); + logic.link(t1, t2); + + // 只推送最终代码 + LLMctx pure; + pure.push(logic.program("Create factorial function")); + return pure; +} +``` + +### 2. 使用全局记忆 + +```cpp +LLMctx main() { + // 访问对话历史 + LLMctx ctx = LLMctx::global(); + + // 设置专业领域 + ctx.keyword("Machine Learning"); + ctx.purpose("Explain complex concepts simply"); + + return ctx; +} +``` + +### 3. 约束系统 + +```cpp +// 添加硬约束 +logic.st("Function must be recursive"); +logic.st("Include docstrings"); +logic.st("Handle negative inputs"); + +// 逻辑绑定 +logic.bind("MAX_ITER", "100"); +logic.bind("THRESHOLD", "0.001"); +``` + +## 常见模式 + +### 1. API 封装 +```cpp +LLMctx main() { + LLMctx logic = LLMctx::keyword("API Developer"); + logic.purpose("Create clean API client wrapper"); + logic.st("Include retry logic and timeout"); + + id t1 = logic.think("Identify required endpoints"); + id t2 = logic.think("Design request/response models"); + logic.link(t1, t2); + + LLMctx pure; + pure.push(logic.program("Python API client for REST service")); + return pure; +} +``` + +### 2. 数据处理流水线 +```cpp +LLMctx main() { + LLMctx logic = LLMctx::keyword("Data Engineer"); + logic.purpose("Create data processing pipeline"); + logic.st("Use pandas for data manipulation"); + logic.st("Include logging and progress tracking"); + + id t1 = logic.think("Load and validate input data"); + id t2 = logic.think("Transform and clean data"); + id t3 = logic.think("Save processed data"); + logic.link(t1, t2); + logic.link(t2, t3); + + LLMctx pure; + pure.push(logic.program("Data processing pipeline with error handling")); + return pure; +} +``` + +### 3. 算法实现 +```cpp +LLMctx main() { + LLMctx logic = LLMctx::keyword("Algorithm Developer"); + logic.purpose("Implement efficient algorithm"); + logic.st("Include time complexity analysis"); + logic.st("Add unit test examples"); + + id t1 = logic.think("Analyze problem requirements"); + id t2 = logic.think("Design optimal approach"); + id t3 = logic.think("Implement with edge cases"); + logic.link(t1, t2); + logic.link(t2, t3); + + LLMctx pure; + pure.push(logic.program("Efficient sorting algorithm implementation")); + return pure; +} +``` + +## 调试技巧 + +### 1. 查看完整推理过程 +不使用纯净容器,查看所有节点: +```cpp +// 直接返回 logic 而不是 pure 容器 +return logic; +``` + +### 2. 模块化开发 +将复杂任务分解为多个 ThinkIR 脚本: +```cpp +// 先设计架构 +LLMctx main() { + LLMctx logic = LLMctx::keyword("System Architect"); + logic.purpose("Design system architecture"); + + // ... 系统设计逻辑 + + return logic; +} +``` + +### 3. 迭代优化 +基于生成的代码,修改 ThinkIR 脚本并重新执行: +```cpp +// 修改约束或添加新逻辑 +id t4 = logic.st("Optimize for memory usage"); +``` + +## 最佳实践 + +1. **使用纯净容器** - 过滤推理过程,只显示最终结果 +2. **明确约束** - 使用 `st()` 确保代码符合要求 +3. **分步构建** - 复杂任务分解为多个简单任务 +4. **版本控制** - 重要的 ThinkIR 脚本应该保存在项目中 +5. **测试验证** - 生成的代码需要实际测试验证 + +## 注意事项 + +1. **LLM 兼容性** - 不同 LLM 对 ThinkIR 的支持程度不同 +2. **Token 消耗** - ThinkIR 脚本可能消耗更多 tokens +3. **调试困难** - 复杂的逻辑链难以直接调试 +4. **学习成本** - 需要理解 ThinkIR 的语法和概念 \ No newline at end of file diff --git a/TOOLKIT_SUMMARY.md b/TOOLKIT_SUMMARY.md new file mode 100644 index 0000000..2bd711b --- /dev/null +++ b/TOOLKIT_SUMMARY.md @@ -0,0 +1,183 @@ +# ThinkIR 工具包总结 + +本文档总结了 ThinkIR 项目中所有新增的工具和模板,帮助您快速上手使用 ThinkIR。 + +## 📁 文件结构 + +``` +ThinkIR/ +├── README.md # 主文档(已更新) +├── ThinkIR.txt # 核心规范文档 +├── CLAUDE.md # Claude Code 集成指南 +├── TOOLKIT_SUMMARY.md # 本总结文档 +│ +├── skill-thinkir.md # ThinkIR skill 规范 +├── .thinkir-rules.md # 基础使用规则 +├── .thinkir-project-rules.md # 项目集成规则 +│ +├── templates/ +│ └── thinkir-template.cpp # 标准模板 +│ +├── scripts/ +│ └── thinkir-init.sh # 初始化脚本 +│ +└── THINKIR_USAGE.md # 详细使用指南 +``` + +## 🚀 快速开始 + +### 步骤 1:使用初始化脚本 +```bash +# 运行初始化脚本(自动创建目录结构) +./scripts/thinkir-init.sh +``` + +### 步骤 2:进入 ThinkIR 模式 +1. 将 `ThinkIR.txt` 的内容粘贴给您的 LLM +2. 等待响应:`// ThinkIR Environment Ready.` + +### 步骤 3:开始使用 +- **Command Line Mode**(默认):直接输入自然语言 +- **其他模式**:使用模式切换指令 + +## 🎯 工具说明 + +### 1. Skill 系统 (`skill-thinkir.md`) + +虽然无法直接创建 Claude Code skill,但这个文档定义了 ThinkIR skill 的规范: + +- **基本模式**:Command Line, Execution, Translation, Silent, Standard +- **自动控制**:格式化输出、模式切换、环境管理 +- **项目集成**:规则注入、模板管理 + +### 2. 规则系统 + +#### 基础规则 (`.thinkir-rules.md`) +- 模式检测和切换 +- 输出格式规范 +- 快捷指令定义 + +#### 项目规则 (`.thinkir-project-rules.md`) +- 项目集成规范 +- 团队协作指南 +- 质量保证流程 + +### 3. 模板系统 + +#### 标准模板 (`templates/thinkir-template.cpp`) +```cpp +#include "ThinkIR.hpp" + +LLMctx main() { + LLMctx logic = LLMctx::keyword("[Domain]"); + logic.purpose("[Objective]"); + logic.st("[Constraints]"); + + id t1 = logic.think("[Step 1]"); + id t2 = logic.think("[Step 2]"); + logic.link(t1, t2); + + LLMctx pure; + pure.push(logic.program("[Intent]")); + return pure; +} +``` + +### 4. 自动化工具 + +#### 初始化脚本 (`scripts/thinkir-init.sh`) +- 自动创建目录结构 +- 检查环境 +- 显示配置信息 +- 提供使用提示 + +## 📚 使用指南 + +### 详细文档 +- **THINKIR_USAGE.md**:完整的使用教程,包含: + - 基础使用流程 + - 高级技巧 + - 常见模式 + - 调试方法 + +### 实践示例 +查看 README.md 中的: +- 天气 API 示例 +- 比较分析 +- 完整的使用说明 + +## 🔧 项目集成方法 + +### 1. 新项目 +```bash +# 1. 克隆 ThinkIR +# 2. 运行初始化脚本 +# 3. 设置项目规则 +# 4. 开始开发 +``` + +### 2. 现有项目 +```bash +# 1. 添加 ThinkIR 目录 +mkdir -p thinkir/{scripts,templates,examples} + +# 2. 复制模板 +cp templates/thinkir-template.cpp thinkir/templates/ + +# 3. 创建项目规则 +echo "// Project-specific rules" > .thinkir-project-rules + +# 4. 更新 README +``` + +## 🎯 最佳实践 + +### 1. 模式选择 +- **Command Line**:探索性任务 +- **Execution**:重复性任务 +- **Translation**:学习和调试 +- **Silent**:生产环境 +- **Standard**:正常对话 + +### 2. 脚本管理 +- 使用版本控制管理关键脚本 +- 为不同类型的项目创建模板 +- 记录成功案例供参考 + +### 3. 团队协作 +- 统一使用项目规则 +- 共享模板和最佳实践 +- 定期 review 生成质量 + +## 🔍 故障排除 + +### 常见问题 +1. **LLM 不响应 ThinkIR**: + - 检查 LLM 是否支持提示词注入 + - 尝试不同的 LLM + +2. **输出格式错误**: + - 确认是否在正确的模式 + - 检查输入是否被正确识别 + +3. **约束不生效**: + - 检查语法是否正确 + - 确认约束是否合理 + +### 调试步骤 +1. 使用 Translation 模式查看脚本 +2. 逐步测试节点 +3. 检查链接关系 + +## 🚀 下一步 + +1. **阅读详细指南**:`THINKIR_USAGE.md` +2. **尝试示例**:修改 README 中的示例 +3. **创建自己的模板**:根据项目需求定制 +4. **分享经验**:贡献到社区 + +## 📞 支持 + +- 查阅 `ThinkIR.txt` 了解完整规范 +- 使用 `THINKIR_USAGE.md` 获取详细帮助 +- 查看 `CLAUDE.md` 了解开发集成 \ No newline at end of file diff --git a/scripts/thinkir-init.sh b/scripts/thinkir-init.sh new file mode 100755 index 0000000..29078ab --- /dev/null +++ b/scripts/thinkir-init.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# ThinkIR 初始化脚本 +# 用于快速设置 ThinkIR 环境 + +# 颜色定义 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# 显示欢迎信息 +echo -e "${BLUE}===========================================${NC}" +echo -e "${BLUE} ThinkIR Environment Setup ${NC}" +echo -e "${BLUE}===========================================${NC}" +echo "" + +# 检查是否在正确的目录 +if [ ! -f "ThinkIR.txt" ]; then + echo -e "${RED}Error: ThinkIR.txt not found in current directory${NC}" + echo "Please run this script in the ThinkIR project root directory" + exit 1 +fi + +# 创建必要的目录 +echo -e "${YELLOW}Creating directories...${NC}" +mkdir -p templates +mkdir -p examples +mkdir -p scripts + +# 复制模板文件 +if [ ! -f "templates/thinkir-template.cpp" ]; then + cp templates/thinkir-template.cpp ../templates/ 2>/dev/null || true +fi + +echo -e "${GREEN}✓ Directories created successfully${NC}" + +# 显示 ThinkIR 状态 +echo "" +echo -e "${BLUE}ThinkIR Configuration:${NC}" +echo -e " Version: $(grep -o 'version="[^"]*"' ThinkIR.txt | cut -d'"' -f2)" +echo -e " Status: $(grep -o 'status="[^"]*"' ThinkIR.txt | cut -d'"' -f2)" + +# 显示使用提示 +echo "" +echo -e "${YELLOW}Quick Start:${NC}" +echo -e " 1. Copy the content of ThinkIR.txt to your LLM" +echo -e " 2. Wait for '// ThinkIR Environment Ready.' response" +echo -e " 3. Start using ThinkIR commands" +echo "" +echo -e "${YELLOW}Available Modes:${NC}" +echo -e " • Command Line Mode (default) - Natural language input" +echo -e " • Execution Mode - Execute ThinkIR scripts only" +echo -e " • Translation Mode - Generate ThinkIR scripts only" +echo -e " • Silent Mode - Clean output without script display" +echo -e " • Standard Mode - Use // for normal conversation" +echo "" +echo -e "${YELLOW}Examples:${NC}" +echo -e " // use execution mode" +echo -e " // use translation mode" +echo -e " // use silent mode" +echo "" +echo -e "${GREEN}ThinkIR environment setup complete!${NC}" \ No newline at end of file diff --git a/skill-thinkir.md b/skill-thinkir.md new file mode 100644 index 0000000..529c44a --- /dev/null +++ b/skill-thinkir.md @@ -0,0 +1,73 @@ +# ThinkIR Skill + +这个 skill 为 Claude Code 提供 ThinkIR 模式的集成支持,让用户能够方便地在项目中使用 ThinkIR 进行编程任务。 + +## 功能特性 + +### 1. **基本 ThinkIR 模式** +- `/thinkir` - 进入 ThinkIR Command Line 模式(默认) +- `/thinkir exec` - 进入 ThinkIR Execution 模式 +- `/thinkir translate` - 进入 ThinkIR Translation 模式 +- `/thinkir silent` - 进入 ThinkIR Silent 模式 + +### 2. **自动模式切换** +- `/thinkir rule` - 将 ThinkIR 作为项目的默认规则 +- `/thinkir disable` - 禁用项目中的 ThinkIR 规则 +- `/thinkir status` - 查看当前 ThinkIR 状态 + +### 3. **快速操作** +- `/thinkir new` - 创建新的 ThinkIR 脚本模板 +- `/thinkir format` - 格式化当前 ThinkIR 输出 +- `/thinkir help` - 显示帮助信息 + +## 使用方法 + +### 基本使用 +```bash +# 进入 ThinkIR 模式 +/thinkir + +# 直接执行 ThinkIR 脚本 +/thinkir exec + +# 创建新的 ThinkIR 脚本 +/thinkir new +``` + +### 项目集成 +```bash +# 将 ThinkIR 作为项目默认规则 +/thinkir rule + +# 查看项目状态 +/thinkir status + +# 临时禁用 ThinkIR 规则 +/thinkir disable +``` + +## 输出格式 + +ThinkIR skill 会自动处理输出格式: + +1. **Phase 1**: 显示生成的 ThinkIR 脚本 +2. **Phase 2**: 显示拓扑结构和节点内容 + +## 配置文件 + +Skill 会在项目根目录创建 `.thinkir-config` 文件: +```json +{ + "default_mode": "command_line", + "auto_format": true, + "version": "1.18.71" +} +``` + +## 兼容性 + +支持以下 LLM: +- Gemini 3 Fast/3 Thinking/3.1 Pro: ✅ 非常好 +- DeepSeek v4: ✅ 非常好 +- GPT-5.3: ✅ 好 +- Claude Sonnet 4.6: ⚠️ 一般 \ No newline at end of file diff --git a/templates/thinkir-template.cpp b/templates/thinkir-template.cpp new file mode 100644 index 0000000..c189863 --- /dev/null +++ b/templates/thinkir-template.cpp @@ -0,0 +1,36 @@ +#include "ThinkIR.hpp" + +/* + * Goal: [Insert your goal here] + * Context: [Add any relevant context] + */ + +LLMctx main() { + // Set domain context and purpose + LLMctx logic = LLMctx::keyword("[Domain/Task Type]"); + logic.purpose("[Clear objective statement]"); + + // Optional: Add constraints + logic.st("[Specific requirements or constraints]"); + + // Create logical reasoning nodes + id t1 = logic.think("[First logical deduction or observation]"); + id t2 = logic.think("[Second logical deduction or observation]"); + id t3 = logic.think("[Conclusion or final output requirement]"); + + // Establish logical dependencies + logic.link(t1, t2); + logic.link(t2, t3); + + // Create a pure container for final output (recommended pattern) + LLMctx pure; + + // Generate and push artifacts + string intent = "[Describe what you want to generate - e.g., 'Python function for data processing']"; + pure.push(logic.program(intent)); + + // Optional: Add additional artifacts + // pure.push(logic.create("[Documentation or explanation]")); + + return pure; +} \ No newline at end of file