misec-1.1.0 is not a library.
misec
misec (mise context) 是一个本地上下文准备工具,用于将项目中的文件、片段和锚点整理成 Agent 可直接消费的上下文候选集合。
它不生成答案,只负责把材料摆好。
特点
• 面向 Agent 的 结构化输出(jsonl / json / md)
• 压缩并编排 find / grep / cat 类操作
• 支持显式 Anchor(锚点),精准圈定上下文
• 依赖分析与变更影响追踪
• 项目内缓存,可随时重建
平台支持
• ✅ Linux
• ✅ macOS
• ❌ Windows(不支持,WSL 不保证)
安装
cargo install misec
cargo install --git https://github.com/talkincode/mise
本地构建:
cargo build --release
命令速查
| 命令 |
用途 |
示例 |
scan |
扫描项目结构 |
misec scan --type file --max-depth 2 |
find |
按名称查找文件 |
misec find readme --scope docs |
extract |
提取文件片段 |
misec extract src/main.rs --lines 10:50 |
match |
文本搜索 (ripgrep) |
misec match "TODO|FIXME" src/ |
ast |
AST 结构搜索 |
misec ast "fn main" --scope src |
deps |
依赖分析 |
misec deps src/cli.rs --reverse |
impact |
变更影响分析 |
misec impact --staged |
anchor |
锚点管理 |
misec anchor list --tag chapter |
flow |
组合工作流 |
misec flow pack --anchors intro |
doctor |
检查依赖状态 |
misec doctor |
rebuild |
重建缓存 |
misec rebuild |
基本用法
扫描项目
misec scan misec scan --type file misec scan --type dir --max-depth 2 misec scan --scope src --hidden
查找文件
misec find cargo misec find readme --scope docs
文本匹配(ripgrep 后端)
misec match "TODO" src/ misec match "TODO|FIXME" misec match "unsafe" src tests
提取指定范围内容
misec extract README.md --lines 1:40 misec extract src/main.rs --lines 10:60 --max-bytes 20000
AST 结构搜索(ast-grep 后端)
misec ast "console.log(\$A)" src misec ast "unsafe { \$A }"
默认输出格式为 jsonl,适合 Agent 解析。
依赖分析(deps)
分析代码文件之间的依赖关系,支持 Rust、TypeScript/JavaScript、Python。
misec deps src/cli.rs misec deps src/cli.rs --reverse misec deps
输出格式
misec deps --deps-format jsonl misec deps --deps-format json misec deps --deps-format dot misec deps --deps-format mermaid misec deps --deps-format tree misec deps --deps-format table
生成依赖图可视化:
misec deps --deps-format dot | dot -Tpng -o deps.png
misec deps --deps-format mermaid >> README.md
变更影响分析(impact)
结合 git diff 与依赖图,分析代码变更的影响范围。
misec impact misec impact --staged misec impact --commit abc123 misec impact --diff main..feature misec impact --max-depth 5
输出格式
misec impact --impact-format jsonl misec impact --impact-format json misec impact --impact-format summary misec impact --impact-format table
Anchor(锚点)
在文本中定义显式语义范围:
这里是第一章的背景设定。
锚点查询
misec anchor list misec anchor list --tag chapter misec anchor get ch01.bg misec anchor get intro --with-neighbors 3 misec anchor lint
锚点标记(mark)
Agent 可以用 mark 命令在代码中插入锚点标记:
misec anchor mark README.md --start 10 --end 25 --id intro
misec anchor mark src/main.rs --start 1 --end 50 --id main.entry --tags entry,core
misec anchor mark doc.md --start 5 --end 10 --id sec1 --dry-run
misec anchor batch --json '[
{"path": "README.md", "start_line": 1, "end_line": 10, "id": "intro", "tags": ["doc"]},
{"path": "src/main.rs", "start_line": 5, "end_line": 20, "id": "main"}
]'
misec anchor batch --file marks.json --dry-run
misec anchor unmark README.md --id intro
Anchor 用于作者主动声明上下文边界,而不是自动推断。
Flow(工作流)
Flow 是对多个基础操作的固定组合,用于快速准备可用上下文。
writing - 写作上下文
misec flow writing --anchor ch01.bg misec flow writing --anchor intro --max-items 12
pack - 上下文打包
将锚点和文件打包成适合 AI 的上下文包:
misec flow pack --anchors cli.scan,core.model misec flow pack --anchors intro --files README.md misec flow pack --anchors api --max-tokens 8000 misec flow pack --anchors api --priority confidence misec flow pack --anchors api --stats
stats - 项目统计
misec flow stats misec flow stats --stats-format summary misec flow stats --stats-format json misec flow stats --stats-format table misec flow stats --scope docs --exts md,txt misec flow stats --top 20
统计内容包括:
- 字符数、词数、行数
- CJK 字符计数(中日韩)
- 估算 Token 数
- 锚点按标签分布
- 最大文件排名
outline - 文档大纲
基于锚点生成项目大纲:
misec flow outline misec flow outline --tag chapter misec flow outline --scope docs misec flow outline --outline-format tree misec flow outline --outline-format json misec flow outline --outline-format markdown
Flow 输出的是组织后的材料,不是结论。
输出格式
--format jsonl --format json --format md --format raw --pretty
所有格式来自同一内部结果模型,仅展示方式不同。
缓存
• 项目内缓存目录:.mise/
• 缓存可随时删除并重建
• 不跨项目共享任何状态
misec rebuild
第三方依赖
misec 会自动集成以下工具(如存在):
• ripgrep (rg):文本匹配 misec match
• ast-grep (sg):AST 结构匹配 misec ast
• watchexec(可选):文件变更触发 misec watch
检查依赖状态:
misec doctor
典型工作流组合
1. 探索陌生代码库
misec scan --type file --max-depth 3
misec match "fn main|async fn" src/
misec anchor list
misec deps src/main.rs --deps-format tree
2. 理解变更影响
misec impact --staged --impact-format summary
misec deps src/cli.rs --reverse
misec deps --deps-format dot | dot -Tpng -o impact.png
3. 为 AI 准备上下文
misec flow pack --anchors core.model,cli.commands --max-tokens 4000
misec flow stats --stats-format summary
misec flow outline --outline-format markdown
4. 长期维护标记
misec anchor mark src/core/model.rs --start 1 --end 100 --id core.model --tags core,data
misec anchor mark src/cli.rs --start 500 --end 600 --id cli.commands --tags cli,entry
misec anchor batch --json '[
{"path": "src/main.rs", "start_line": 1, "end_line": 30, "id": "main.entry", "tags": ["entry"]},
{"path": "src/lib.rs", "start_line": 1, "end_line": 50, "id": "lib.exports", "tags": ["api"]}
]'
misec anchor lint
5. 代码审查辅助
misec impact --diff main..feature --impact-format summary
misec impact --staged --impact-format json | jq '.affected_anchors'
misec flow pack --anchors affected.module --files CHANGELOG.md
设计边界(重要)
misec 不会:
• 生成答案或结论
• 保证上下文完整或正确
• 做语义理解或向量检索
• 替代 Agent 的判断
misec 提供的是 上下文候选集合,不是事实来源。
适用场景
• 写作项目(章节、设定、素材管理)
• 需要反复探索的代码仓库
• Agent 工作流中频繁调用文件检索的场景
• 接受噪音,但要求可回溯的上下文准备
一句话
misec 负责备料,不负责出菜。