Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions .thinkir-project-rules.md
Original file line number Diff line number Diff line change
@@ -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. 逐步添加节点进行测试
66 changes: 66 additions & 0 deletions .thinkir-rules.md
Original file line number Diff line number Diff line change
@@ -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]` - 文档节点
67 changes: 67 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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.
Loading