Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: layered memory loading and /init command
  - Add src/memory.ts: 3-layer instruction file loading (global, ancestors, cwd), 6 filename candidates, dedup, capacity limits (8K/20K)
  - Add src/init.ts: /init command bootstraps .mini-code/, .gitignore, MINI.md with auto-detected stack
  - Refactor src/prompt.ts to delegate instruction loading to loadMemory()
  - Add tests: 19 memory tests + 12 init tests (all passing)
  - Update docs: ARCHITECTURE, README, ROADMAP (EN + ZH)
  • Loading branch information
GoDiao committed Apr 30, 2026
commit 4e074046af1b20f6f945be3a747171461e64c3c7
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
node_modules/
tmp/
dist/
~/
.DS_Store
*.log

# MiniCode local artifacts
.mini-code/settings.local.json
.mini-code/sessions/
6 changes: 4 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In other words, MiniCode is a smaller, more controllable terminal coding assista
- More complex permission modes
- Feature-flag system
- Telemetry / analytics
- Layered project memory and richer session search
- Layered project memory and richer session search (basic layered memory loading is now implemented)

## Current implementation

Expand All @@ -57,6 +57,8 @@ In other words, MiniCode is a smaller, more controllable terminal coding assista
- `src/mock-model.ts`: offline fallback adapter
- `src/permissions.ts`: path, command, and edit approval with allowlist / denylist
- `src/session.ts`: multi-session persistence with append-only JSONL, parentUuid tree structure, compact boundary, session forking, and expiry cleanup
- `src/memory.ts`: layered instruction file loading (`MINI.md` / `CLAUDE.md`), upward directory walk, content deduplication, and capacity-limited rendering
- `src/init.ts`: project bootstrapping — creates `.mini-code/`, adds MiniCode entries to `.gitignore`, and generates a `MINI.md` template with auto-detected stack (languages, frameworks, verification commands). Idempotent `/init` slash command.
- `src/file-review.ts`: diff review before writing files
- `src/tui/*`: transcript / chrome / input / screen / markdown terminal components

Expand Down Expand Up @@ -91,5 +93,5 @@ That makes it well suited to:
1. A more complete virtual-scrolling transcript
2. Richer input editing behavior
3. A finer-grained tool execution status panel
4. Session history and project memory (session persistence is now implemented; project memory is still planned)
4. Session history and project memory (session persistence and basic layered memory loading are now implemented)
5. Stronger UI componentization
6 changes: 4 additions & 2 deletions ARCHITECTURE_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MiniCode 优先保留这些能力:
- 复杂 permission 模式
- feature flag 体系
- telemetry / analytics
- 分层项目 memory 与更完整的会话搜索
- 分层项目 memory 与更完整的会话搜索(基础分层 memory 加载已实现)



Expand All @@ -59,6 +59,8 @@ MiniCode 优先保留这些能力:
- `src/mock-model.ts`: 离线回退适配器
- `src/permissions.ts`: 路径、命令、编辑审批与 allowlist / denylist
- `src/session.ts`: 多会话持久化,追加写入 JSONL,parentUuid 树结构,compact boundary,会话分叉,过期清理
- `src/memory.ts`: 分层指令文件加载(`MINI.md` / `CLAUDE.md`),向上目录递归,内容去重,容量限制渲染
- `src/init.ts`: 项目初始化 — 创建 `.mini-code/`,向 `.gitignore` 追加 MiniCode 条目,根据项目结构检测生成 `MINI.md` 模板(语言、框架、验证命令)。幂等 `/init` 命令。
- `src/file-review.ts`: 写文件前 diff review
- `src/tui/*`: transcript / chrome / input / screen / markdown 终端组件

Expand Down Expand Up @@ -93,5 +95,5 @@ MiniCode 的一个优势,是用更轻量的实现方式,提供了类 Claude
1. 更完整的虚拟滚动 transcript
2. 更完整的输入编辑行为
3. 更细的工具执行状态面板
4. 会话历史与项目记忆(会话持久化已实现;项目记忆仍待开发
4. 会话历史与项目记忆(会话持久化与基础分层 memory 加载已实现
5. 更强的 UI 组件化
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ CLI flags:

Sessions are scoped per working directory and stored in `~/.mini-code/projects/` using append-only JSONL. On exit, MiniCode prints the session ID so you can resume later. Sessions older than 30 days are automatically cleaned up.

### Layered memory

MiniCode loads instruction files at startup from a three-layer hierarchy:

1. **User global**: `~/.mini-code/MINI.md` (also reads `~/.mini-code/CLAUDE.md` for compatibility)
2. **Project root and ancestors**: walks upward from cwd, reading `MINI.md`, `MINI.local.md`, `.mini-code/MINI.md`, `CLAUDE.md`, `CLAUDE.local.md`, `.claude/CLAUDE.md` at each level
3. **Priority**: content closer to cwd takes precedence over broader layers

Files with identical content are deduplicated. Per-file limit is ~8k chars, total limit ~20k chars.

Example `MINI.md`:

```markdown
# Project Rules

- Use TypeScript strict mode.
- Run `npm run check` before committing.
- Keep changes minimal and focused.
```

## Long Sessions and Context Management

MiniCode now treats long-running conversations as a first-class workflow:
Expand Down
20 changes: 20 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ CLI 参数:

会话按工作目录隔离,存储在 `~/.mini-code/projects/`,采用追加写入的 JSONL 格式。退出时会打印 session ID,方便后续恢复。超过 30 天的会话会自动清理。

### 分层 memory

MiniCode 启动时从三层层级加载指令文件:

1. **用户全局**:`~/.mini-code/MINI.md`(同时兼容读取 `~/.mini-code/CLAUDE.md`)
2. **项目根及祖先目录**:从 cwd 向上递归,读取 `MINI.md`、`MINI.local.md`、`.mini-code/MINI.md`、`CLAUDE.md`、`CLAUDE.local.md`、`.claude/CLAUDE.md`
3. **优先级**:越靠近 cwd 的内容优先级越高

相同内容的文件会自动去重。单文件上限约 8k 字符,总量上限约 20k 字符。

`MINI.md` 示例:

```markdown
# 项目规则

- 使用 TypeScript strict 模式。
- 提交前运行 `npm run check`。
- 保持改动最小且聚焦。
```

## 长会话与上下文管理

MiniCode 现在把长会话作为一等工作流处理:
Expand Down
14 changes: 8 additions & 6 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ If you are interested in maintaining or extending the Python or Rust variants, o

### 5. Layered memory loading

MiniCode should support a lightweight memory hierarchy similar in spirit to Claude Code's layered project context.
**Status: mostly implemented.** MiniCode now loads instruction files from a three-layer hierarchy: user global (`~/.mini-code/MINI.md`), project root, and nested directories (walked upward from cwd). Supports `MINI.md`, `MINI.local.md`, `.mini-code/MINI.md`, plus compatibility scanning for `CLAUDE.md` and `.claude/CLAUDE.md`. Includes content deduplication and capacity limits.

This may include:
The `/init` command bootstraps a project: creates `.mini-code/`, adds MiniCode entries to `.gitignore`, and generates a `MINI.md` template with auto-detected stack (languages, frameworks, verification commands, repository shape). Idempotent — safe to re-run.

- global memory
- project memory
- nested/project-local memory
- simple include support where appropriate
Planned follow-ups:

- `@path` include resolution
- `.mini-code/rules/*.md` auto-discovery
- Auto memory read/write
- `/memory` command to inspect loaded files

### 6. Stronger provider abstraction

Expand Down
14 changes: 8 additions & 6 deletions ROADMAP_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ MiniCode 现在会把 provider usage 记录在 assistant response boundary 上

### 5. 分层 memory 加载

MiniCode 应该支持一种轻量的分层 memory 体系,方向上接近 Claude Code 的 layered project context
**状态:基本实现。** MiniCode 现在从三层层级加载指令文件:用户全局(`~/.mini-code/MINI.md`)、项目根、嵌套目录(从 cwd 向上递归)。支持 `MINI.md`、`MINI.local.md`、`.mini-code/MINI.md`,并兼容扫描 `CLAUDE.md` 和 `.claude/CLAUDE.md`。包含内容去重和容量限制

可以包括:
`/init` 命令可初始化项目:创建 `.mini-code/`、向 `.gitignore` 追加 MiniCode 条目、根据项目检测生成 `MINI.md` 模板(语言、框架、验证命令、目录结构)。幂等 — 可安全重复运行。

- 全局 memory
- 项目级 memory
- 嵌套目录 / 本地 memory
- 在合适范围内支持简单 include
后续计划:

- `@path` include 解析
- `.mini-code/rules/*.md` 自动发现
- Auto memory 读写
- `/memory` 命令查看已加载文件

### 6. 更完整的 provider abstraction

Expand Down
11 changes: 11 additions & 0 deletions src/cli-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
loadRuntimeConfig,
saveMiniCodeSettings,
} from './config.js'
import { initializeRepo, renderInitReport } from './init.js'
import type { ToolRegistry } from './tool.js'

export type SlashCommand = {
Expand Down Expand Up @@ -130,6 +131,11 @@ export const SLASH_COMMANDS: SlashCommand[] = [
usage: '/compact',
description: 'Compress conversation context to free up context window space.',
},
{
name: '/init',
usage: '/init',
description: 'Create .mini-code/, .gitignore entries, and MINI.md in the current project (idempotent).',
},
]

export function formatSlashCommands(): string {
Expand Down Expand Up @@ -217,6 +223,11 @@ export async function tryHandleLocalCommand(
].join('\n')
}

if (input === '/init') {
const report = await initializeRepo(process.cwd())
return renderInitReport(report)
}

if (input === '/model') {
const runtime = await loadRuntimeConfig()
return `current model: ${runtime.model}`
Expand Down
Loading