pi-anchor 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -166
- package/README_zh.md +32 -172
- package/assets/hero-en.svg +33 -70
- package/assets/hero-zh.svg +33 -70
- package/bin/anchor.js +49 -95
- package/dist/chunk-LKY6WIKH.js +1100 -0
- package/dist/extension-B1-fzCox.d.cts +167 -0
- package/dist/extension-B1-fzCox.d.ts +167 -0
- package/dist/extension.cjs +428 -1240
- package/dist/extension.d.cts +2 -20
- package/dist/extension.d.ts +2 -20
- package/dist/extension.js +4 -518
- package/dist/index.cjs +370 -1070
- package/dist/index.d.cts +17 -223
- package/dist/index.d.ts +17 -223
- package/dist/index.js +21 -101
- package/package.json +2 -2
- package/src/extension.ts +142 -356
- package/src/index.ts +1 -6
- package/src/store.ts +308 -422
- package/src/tui.ts +112 -259
- package/src/types.ts +24 -65
- package/dist/chunk-G72UHPBN.js +0 -1441
- package/dist/store-BNKjzhS_.d.cts +0 -209
- package/dist/store-BNKjzhS_.d.ts +0 -209
- package/src/context_injector.ts +0 -166
- package/src/decay.ts +0 -125
- package/src/matcher.ts +0 -151
- package/src/observer.ts +0 -141
- package/src/protocol.ts +0 -95
- package/src/settlement.ts +0 -74
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# ⌖ Anchor
|
|
2
2
|
|
|
3
|
-
> **
|
|
3
|
+
> **A digital sticky note for Pi Coding Agent — with three clever touches.**
|
|
4
|
+
> Stick a quick note across sessions (`/pin`), get a 1-line comment whisper when the AI touches that file, and watch the note tear itself off when you `git commit`. Zero `TODO.md` clutter in your repo.
|
|
4
5
|
|
|
5
6
|
[](https://github.com/3ZEROS12/anchor/actions/workflows/ci.yml)
|
|
6
7
|
[](package.json)
|
|
7
8
|
[](tsconfig.json)
|
|
8
|
-
[](package.json)
|
|
10
|
-
[](#1-zero-repository-contamination--storage-topology)
|
|
9
|
+
[](tests/store.test.ts)
|
|
11
10
|
[](LICENSE)
|
|
12
11
|
|
|
13
12
|
**English** | [简体中文](./README_zh.md)
|
|
@@ -17,189 +16,57 @@ pi install npm:pi-anchor
|
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
<p align="center">
|
|
20
|
-
<img src="assets/hero-en.svg" alt="Anchor
|
|
19
|
+
<img src="assets/hero-en.svg" alt="Anchor Sticky Notes" width="820">
|
|
21
20
|
</p>
|
|
22
21
|
|
|
23
|
-
### How It Works in 3 Steps
|
|
24
|
-
|
|
25
|
-
1. **Pin in 1 second**: Tell the AI *"Remember to migrate auth tomorrow"* or type `/pin Migrate auth to HttpOnly cookies --due tomorrow`. Stored in `~/.anchor/state.json` (zero `TODO.md` files in your git repo).
|
|
26
|
-
2. **Wake up next session (0 idle tokens)**: Next time you open Pi, Anchor shows a 3-line summary above your editor and briefs the AI on Turn 1. From Turn 2 onwards, it consumes **0 tokens** — waking up only with a 1-line comment when the AI reads or edits matching files.
|
|
27
|
-
3. **Auto-complete on commit or test pass**: Commit related code (`git commit`), pass a `verifyCommand`, or run `/done 1` — Anchor archives the task automatically.
|
|
28
|
-
|
|
29
22
|
```text
|
|
30
|
-
⌖
|
|
31
|
-
|
|
32
|
-
[Today · Today's Focus]
|
|
33
|
-
01 [Today] Optimize token truncation & JIT safety Desktop Today Today 10:02
|
|
23
|
+
⌖ Notes (3):
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
02
|
|
37
|
-
03
|
|
38
|
-
04 [Upcoming] Polish CLI interactive dashboard & TUI Desktop In 2d Today 10:02
|
|
25
|
+
01 Switch session token to HttpOnly cookie app · auth.ts 25m ago
|
|
26
|
+
02 Double-check rate limit fallback on timeout app · gateway.ts 3h ago
|
|
27
|
+
03 Read external architecture notes first College/优化 · notes.md 8d ago · quiet
|
|
39
28
|
|
|
40
|
-
|
|
29
|
+
Run `anchor done <num>` to tear off, or `anchor undo` to put back.
|
|
41
30
|
```
|
|
42
31
|
|
|
43
32
|
---
|
|
44
33
|
|
|
45
|
-
## Why
|
|
46
|
-
|
|
47
|
-
When building software with terminal-based AI coding agents (Claude Code, Pi, Aider), developers encounter three recurring points of friction:
|
|
48
|
-
|
|
49
|
-
### 1. Terminal Exit = Instant Amnesia
|
|
50
|
-
Pressing `Ctrl+C` terminates the agent process, clearing working memory. Unfinished refactoring plans, temporary milestones, and cross-session agreements vanish instantly.
|
|
51
|
-
|
|
52
|
-
### 2. TODO.md Pollutes Git & Suffocates Token Windows
|
|
53
|
-
Writing tasks into `TODO.md` or `AGENTS.md` inside your repository creates unwanted git noise (`update todo`, `fix checklist`). Worse, **every single turn injects dozens of stagnant lines into the system prompt**, burning token budgets and diluting LLM attention on active code.
|
|
54
|
-
|
|
55
|
-
### 3. Checkbox Rot & Heavy Over-Engineering
|
|
56
|
-
Once code is written, developers rarely reopen markdown files to check boxes manually. Incomplete task lists rot inside the repository indefinitely. Existing alternatives introduce heavy trade-offs: `beads` forces a 200MB Dolt SQL database directly into your repository, while `engram` runs a persistent background Go daemon with SQLite and continuous vector retrieval.
|
|
57
|
-
|
|
58
|
-
**Anchor takes a lean, pragmatic approach**:
|
|
59
|
-
- **Zero Repo Contamination**: State is stored outside the workspace in `~/.anchor/state.json`, keeping your git tree 100% clean.
|
|
60
|
-
- **0 Idle Tokens**: Injects active commitments on Turn 1 cold-start; Turn 2+ working turns consume **0 tokens**. Stored tasks don't cost a dime while writing code.
|
|
61
|
-
- **Syntax-Safe JIT Wakeup**: When the agent touches relevant files, Anchor surfaces a single-line language-accurate comment (`//`, `#`, `<!-- -->`, `/* */`), while strictly skipping JSON, ENV, and lockfiles.
|
|
62
|
-
- **Auto-Settlement & Accidental Settle Guard**: Tasks automatically settle on git commits matching task descriptions or on session exit. In interactive dashboard mode, a two-stage dialog prevents accidental completion.
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## Core Architecture & State Machine
|
|
67
|
-
|
|
68
|
-
```text
|
|
69
|
-
┌──────────────────────────────────────────────────────────────────────────────┐
|
|
70
|
-
│ Anchor Lifecycle State Machine │
|
|
71
|
-
└──────────────────────────────────────┬───────────────────────────────────────┘
|
|
72
|
-
│ Pin task: anchor "Migrate auth to HTTP-only cookies"
|
|
73
|
-
▼
|
|
74
|
-
┌───────────────────────────────────────────────┐
|
|
75
|
-
│ [ACTIVE Tier] (Turn 1 Injected) │
|
|
76
|
-
│ - Status indicator: ⌖ 4 │
|
|
77
|
-
│ - Turn 2+ : Excluded from prompt (0 Tokens) │
|
|
78
|
-
└───────┬───────────────────────────────┬───────┘
|
|
79
|
-
│ │
|
|
80
|
-
Git Commit / │ │ Inactivity Decay
|
|
81
|
-
Code Touch ▼ ▼
|
|
82
|
-
┌──────────────────────────────┐ ┌────────────────────────────────┐
|
|
83
|
-
│ [Syntax-Safe JIT Wakeup] │ │ [SLEEPING Tier] (0 Tokens) │
|
|
84
|
-
│ Language-accurate comments │ │ Preserved safely in global │
|
|
85
|
-
│ JSON/ENV strictly skipped │ │ state; wakes upon code touch │
|
|
86
|
-
└──────────────┬───────────────┘ └────────────────┬───────────────┘
|
|
87
|
-
│ │
|
|
88
|
-
Exit Prompt / Commit Match │ Silent Sweep
|
|
89
|
-
▼ ▼
|
|
90
|
-
┌──────────────────────────────┐ ┌────────────────────────────────┐
|
|
91
|
-
│ [SETTLED / Archived] │ │ [GRAVEYARD / Evicted] │
|
|
92
|
-
│ Appended to archive.jsonl │ │ Swept to graveyard.jsonl │
|
|
93
|
-
│ Evicted from active context │ │ (Auto-pruned after decay) │
|
|
94
|
-
└──────────────────────────────┘ └────────────────────────────────┘
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
| Action / Scenario | What You Do | What Anchor Does | What the AI Gets | When to Use |
|
|
98
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
99
|
-
| **Pin Commitment** | Run `anchor "Refactor auth"` | Atomically writes to `~/.anchor/state.json` | Turn 1: Injected into prompt; Turn 2+: 0 tokens | Retaining multi-step plans across terminal restarts |
|
|
100
|
-
| **File Touch** | Edit or read code normally | Matches touched files against anchor paths | Injects syntax-safe 1-line comment (skips JSON/ENV) | Working on relevant project modules |
|
|
101
|
-
| **Git Commit** | `git commit -m "feat: ..."` | Matches commit message using `Intl.Segmenter` | Auto-settles and archives matching task | Finishing code milestones |
|
|
102
|
-
| **Session Exit** | Type `exit` / `quit` | Intersects git-modified files with active anchors | Single-keypress prompt: `[Enter Settle] / [Esc Keep]` | Wrapping up terminal session |
|
|
34
|
+
## Why a Sticky Note Instead of `TODO.md`?
|
|
103
35
|
|
|
104
|
-
|
|
36
|
+
When you're deep in a coding session at 11 PM and realize *"I still need to fix the token expiry in `src/auth.ts` tomorrow"*, you don't want a heavy task manager:
|
|
37
|
+
- Putting a `TODO.md` inside your repo pollutes `git status` and forces the AI to re-read stale checklists on every single turn.
|
|
38
|
+
- Closing the terminal wipes the agent's working memory clean.
|
|
105
39
|
|
|
106
|
-
|
|
40
|
+
**Anchor is just a physical sticky note stuck to the bezel of your terminal** — stored outside your repo in `~/.anchor/state.json` (<10 KB, zero external dependencies, 4 source files), with three small, thoughtful touches:
|
|
107
41
|
|
|
108
|
-
### 1.
|
|
109
|
-
|
|
42
|
+
### 1. Stick It & Forget It (Smart Path Spotting)
|
|
43
|
+
Write a note in plain language:
|
|
110
44
|
```text
|
|
111
|
-
|
|
112
|
-
├── state.json # Active and sleeping task state (< 10KB, atomic write)
|
|
113
|
-
├── state.lock # Cross-process sync atomic lock (Zero dependencies)
|
|
114
|
-
├── archive.jsonl # Append-only log of settled tasks
|
|
115
|
-
└── graveyard.jsonl # Append-only log of decayed and evicted items
|
|
45
|
+
/pin Switch session token to HttpOnly cookie in src/auth.ts
|
|
116
46
|
```
|
|
117
|
-
|
|
118
|
-
* **Dead PID Reclamation**: Automatically reclaims stale locks if the owning process terminated (`process.kill(pid, 0)` fails) or exceeded the 5000ms timeout.
|
|
119
|
-
* **Resilient Atomic Writes**: State writes use a temporary file followed by atomic `fs.renameSync` with spin-retries for Windows NTFS locks.
|
|
120
|
-
|
|
121
|
-
### 2. Accidental Settle Guard & Details Inspector (v0.2.1)
|
|
122
|
-
Pressing Enter in `/anchor` presents a two-stage action menu:
|
|
123
|
-
* `✓ Settle`: Completes and archives the task with an undo notice (`/anchor undo to revert`).
|
|
124
|
-
* `ℹ View details & associated files`: Inspects full description, target date, files, and physical verification command without completing the task.
|
|
125
|
-
* `↩ Cancel`: Returns safely without mutating state.
|
|
47
|
+
Anchor spots `src/auth.ts` (or any project path like `D:/College/...`) directly from your sentence — no forms or tags to fill out. Next time you open Pi in that project, a quiet card sits above your editor (`⌖ 1 note`) and disappears the moment you start typing.
|
|
126
48
|
|
|
127
|
-
###
|
|
128
|
-
|
|
49
|
+
### 2. A Gentle Whisper When Touching the File (0 Idle Tokens)
|
|
50
|
+
Anchor briefs the AI once on Turn 1 of a session, then drops to **0 tokens** from Turn 2 onwards.
|
|
51
|
+
When the AI reads or edits `src/auth.ts`, Anchor slips a single syntax-safe comment onto the end of that file read (`// ⌖ Note #1: Switch session token to HttpOnly cookie`), while strictly skipping `.json`, `.env`, and lockfiles.
|
|
129
52
|
|
|
130
|
-
|
|
131
|
-
* **Turn 1 (Cold Start)**: Injects active commitments for the current workspace alongside natural conversational guidelines.
|
|
132
|
-
* **Turn 2+ (Working Turns)**: Anchor strips task lists from subsequent turns. Stored tasks consume **0 tokens** while coding.
|
|
133
|
-
* **Syntax-Safe Guard (Strict Null)**: For **JSON, ENV, Lockfiles, and binary assets**, Anchor explicitly returns `null`, preventing corrupted parsers or invalid syntax.
|
|
53
|
+
*(Notes untouched for more than 7 days automatically enter `quiet` mode so they don't spend Turn-1 tokens in unrelated workspaces, while staying 100% visible in `/anchor` and waking up as soon as you open their project.)*
|
|
134
54
|
|
|
135
|
-
###
|
|
136
|
-
When
|
|
55
|
+
### 3. Auto-Tears Off on `git commit`
|
|
56
|
+
When you or the AI commits the fix (`git commit -m "feat: switch session token to HttpOnly cookie"`), Anchor matches the commit message against your sticky notes and tears the note off in real time (`⌖ Auto-torn off #1`).
|
|
57
|
+
Tore one off by mistake? Run `/anchor undo` to stick it right back.
|
|
137
58
|
|
|
138
59
|
---
|
|
139
60
|
|
|
140
|
-
## Commands
|
|
141
|
-
|
|
142
|
-
### Standalone CLI
|
|
143
|
-
```bash
|
|
144
|
-
anchor # List active tasks (Neovim-style dashboard)
|
|
145
|
-
anchor "Migrate auth to cookies" # Pin new commitment
|
|
146
|
-
anchor "Submit report" --due friday # Pin with explicit deadline
|
|
147
|
-
anchor done 1 # Complete row 1 (ordered index support)
|
|
148
|
-
anchor done anc-5 # Complete by explicit ID
|
|
149
|
-
anchor undo # Restore last archived task
|
|
150
|
-
```
|
|
61
|
+
## Commands
|
|
151
62
|
|
|
152
|
-
|
|
153
|
-
|
|
|
154
|
-
|
|
|
155
|
-
|
|
|
156
|
-
| `/
|
|
157
|
-
|
|
|
158
|
-
|
|
|
159
|
-
| Status bar `⌖ N` | Displays active task count in status row; 100% hidden when 0 tasks exist |
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## Technical Comparison
|
|
164
|
-
|
|
165
|
-
| Feature | `gastownhall/beads` | `Gentleman-Programming/engram` | `AGENTS.md` / `TODO.md` | **Anchor ⚓** |
|
|
166
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
167
|
-
| **Architecture** | Distributed SQL Graph | Vector/SQLite Memory | Static Markdown | **Decoupled Universal Protocol + Atomic State** |
|
|
168
|
-
| **Workspace Hygiene** | Pollutes repo with 200MB Dolt | System daemon | **Pollutes git commit history** | **100% Zero repo pollution (`~/.anchor/`)** |
|
|
169
|
-
| **Token Cost** | Medium/High per turn | High (full prompt injection) | Severe (stale text accumulates) | **0 Tokens idle (JIT file touch only)** |
|
|
170
|
-
| **Syntax Safety** | N/A | Raw text injection | Static unformatted | **Language-aware comments, strictly skips JSON** |
|
|
171
|
-
| **Closure Mechanism** | Manual CLI close | Passive storage | Manual file edit | **Git Commit auto-match + One-tap exit settlement** |
|
|
172
|
-
| **Concurrency Safety** | SQL Transaction locks | Daemon single-point | Git merge conflicts | **Zero-dep cross-process atomic file lock** |
|
|
173
|
-
| **Startup Overhead** | Heavy CLI init | Go daemon | None | **< 90ms pre-bundled production artifact** |
|
|
174
|
-
| **Dependencies** | External Dolt binary | External Go binary | None | **Zero native binary dependencies (Pure TS)** |
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
## Author's Note
|
|
179
|
-
|
|
180
|
-
The motivation behind Anchor came from a recurring headache during pair-programming with AI coding agents: watching `TODO.md` and `AGENTS.md` rot inside my git trees.
|
|
181
|
-
|
|
182
|
-
Every time a task remained unfinished across sessions, writing it to a project markdown file felt harmless at first. Over weeks of work, two frictions became unbearable:
|
|
183
|
-
1. In multi-turn sessions, the AI dragged dozens of stagnant task lines into the prompt on every single turn, burning hundreds of tokens while diluting the model's focus on the actual code being edited.
|
|
184
|
-
2. Merge conflicts on task checklists in Git commits polluted the repository's history with irrelevant bookkeeping noise.
|
|
185
|
-
|
|
186
|
-
When I looked at existing solutions, the trade-offs felt disproportionate. Stuffing a 200MB Dolt SQL relational database into the repository root (`beads`), or running a background Go daemon with SQLite and continuous vector retrieval (`engram`), inverted the relationship between tool and developer. A task tracker should not demand more system resources than the application being built.
|
|
187
|
-
|
|
188
|
-
Anchor takes the opposite approach: store state outside the project tree in a lean global ledger (`~/.anchor/state.json`), inject tasks only on Turn 1 of a cold start, keep Turn 2+ at exactly 0 tokens, and auto-settle upon git commits or session exit.
|
|
189
|
-
|
|
190
|
-
In v0.2.1, we added the two-stage settle menu to eliminate accidental completions and enhanced visual truncation to prevent dangling punctuation. I hope Anchor keeps your project trees clean and your focus where it belongs: on the code.
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## Verification & Quality Assurance
|
|
195
|
-
|
|
196
|
-
Engineered with strict TypeScript and 100% standard library test coverage using Node's native test runner:
|
|
197
|
-
|
|
198
|
-
```bash
|
|
199
|
-
npm run typecheck # Strict tsc --noEmit check (0 errors)
|
|
200
|
-
npm test # Native Node test runner (31/31 passing)
|
|
201
|
-
npm run build # Dual ESM/CJS compilation via tsup + declaration emit
|
|
202
|
-
```
|
|
63
|
+
| Where | Command | What It Does |
|
|
64
|
+
| :--- | :--- | :--- |
|
|
65
|
+
| **Inside Pi** | `/pin <note>` | Stick a new note (or just tell the AI *"Remember to..."*) |
|
|
66
|
+
| **Inside Pi** | `/anchor` | Open the interactive sticky note list (press Enter to tear off or read) |
|
|
67
|
+
| **Inside Pi** | `/done 1` | Tear off note `#01` directly |
|
|
68
|
+
| **Inside Pi** | `/anchor undo` | Put back the last torn-off note |
|
|
69
|
+
| **Terminal CLI** | `anchor` / `anchor "<note>"` / `anchor done 1` | Manage the exact same sticky notes outside Pi |
|
|
203
70
|
|
|
204
71
|
---
|
|
205
72
|
|
package/README_zh.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# ⌖ Anchor
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **贴在 Pi 终端边框上的电子便签 —— 带一点刚刚好的小巧思。**
|
|
4
|
+
> 随手贴一张跨会话备忘(`/pin`),AI 读改关联文件时顺手递上一行注释提醒,`git commit` 提交代码时自动撕掉便签。不在代码仓库里留任何 `TODO.md` 垃圾。
|
|
4
5
|
|
|
5
6
|
[](https://github.com/3ZEROS12/anchor/actions/workflows/ci.yml)
|
|
6
7
|
[](package.json)
|
|
7
8
|
[](tsconfig.json)
|
|
8
|
-
[](package.json)
|
|
10
|
-
[](#1-绝对零仓库污染与跨进程文件锁)
|
|
9
|
+
[](tests/store.test.ts)
|
|
11
10
|
[](LICENSE)
|
|
12
11
|
|
|
13
12
|
[English](./README.md) | **简体中文**
|
|
@@ -17,196 +16,57 @@ pi install npm:pi-anchor
|
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
<p align="center">
|
|
20
|
-
<img src="assets/hero-zh.svg" alt="Anchor
|
|
19
|
+
<img src="assets/hero-zh.svg" alt="Anchor 电子便签预览" width="820">
|
|
21
20
|
</p>
|
|
22
21
|
|
|
23
|
-
### 3 步看懂它怎么工作
|
|
24
|
-
|
|
25
|
-
1. **随手钉住待办**:直接对 AI 说 *“记一下明天把鉴权改成 HttpOnly Cookie”*,或敲 `/pin 重构鉴权模块 --due tomorrow`。保存在全局 `~/.anchor/state.json`,不在项目里留任何 `TODO.md` 垃圾文件。
|
|
26
|
-
2. **下次开终端自动唤醒(平时 0 Token)**:重新打开 Pi 时,编辑器上方展示 3 行今日聚焦清单,并在第 1 轮自动提醒 AI;从第 2 轮起 **0 Token 损耗**,只有当 AI 读/改关联代码文件时才附带 1 行注释精准提醒。
|
|
27
|
-
3. **提交代码自动销账**:`git commit` 提交关联代码、单测命令通过、或敲 `/done 1`,任务自动归档结案。
|
|
28
|
-
|
|
29
22
|
```text
|
|
30
|
-
⌖
|
|
31
|
-
|
|
32
|
-
[Today · 今日聚焦]
|
|
33
|
-
01 [Today] 今天完成anchor项目后端优化 Desktop Today Today 10:02
|
|
23
|
+
⌖ Notes (3):
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
02
|
|
37
|
-
03
|
|
38
|
-
04 [Upcoming] 完善CLI交互式仪表盘与TUI组件 Desktop In 2d Today 10:02
|
|
25
|
+
01 把登录 Token 改用 HttpOnly Cookie 存储 app · auth.ts 25m ago
|
|
26
|
+
02 检查网关超时后的降级重试边界 app · gateway.ts 3h ago
|
|
27
|
+
03 College 重构前置查阅外部架构参考库 College/优化 · notes.md 8d ago · quiet
|
|
39
28
|
|
|
40
|
-
|
|
29
|
+
Run `anchor done <num>` to tear off, or `anchor undo` to put back.
|
|
41
30
|
```
|
|
42
31
|
|
|
43
32
|
---
|
|
44
33
|
|
|
45
|
-
##
|
|
46
|
-
|
|
47
|
-
使用终端编程智能体(Claude Code、Pi、Aider 等)结对开发时,开发者普遍面临三个具体痛点:
|
|
48
|
-
|
|
49
|
-
### 1. 终端一关即失忆(Session Amnesia)
|
|
50
|
-
按下 `Ctrl+C` 退出终端,Agent 内存中的上下文被清空。未完成的代码重构计划、临时交代的排期与多步约定随之丢失。
|
|
51
|
-
|
|
52
|
-
### 2. TODO.md 污染 Git 且拖垮上下文
|
|
53
|
-
在工程根目录下维护 `TODO.md` 或 `AGENTS.md`:
|
|
54
|
-
- 会产生大量 `update todo`、`fix checklist` 之类的 Git 杂质提交;
|
|
55
|
-
- **每一轮对话都要把几十行陈旧清单塞入 System Prompt**,白白消耗大量 Token 预算,还会分散模型对当前核心代码的注意力。
|
|
34
|
+
## 为什么是一张电子便签,而不是 `TODO.md`?
|
|
56
35
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
深夜写代码准备关机时,你突然想到 *“明天得把 `src/auth.ts` 里的 Token 改成 Cookie”*。这时候你不需要一套沉重的项目管理系统:
|
|
37
|
+
- 往仓库里塞 `TODO.md` 会弄脏 `git status`,而且每一轮对话都在白白消耗上下文 Token;
|
|
38
|
+
- 直接关掉终端,AI 的内存记忆瞬间清空。
|
|
60
39
|
|
|
61
|
-
**Anchor
|
|
62
|
-
- **零仓库污染**:任务状态保存在全局主目录 `~/.anchor/state.json`,项目 Git 历史 100% 纯净;
|
|
63
|
-
- **0 闲置 Token 损耗**:第 1 轮冷启动注入任务,第 2 轮起保持 0 Token 稳态,绝不浪费推理预算;
|
|
64
|
-
- **语法安全 JIT 唤醒**:Agent 触碰相关代码文件时,以对应语言的单行安全注释精准唤醒,严格跳过 JSON、ENV 与锁文件;
|
|
65
|
-
- **自动核销与防误触抽屉**:代码提交命中任务描述或退出终端时自动核销;交互式面板提供防误触二级菜单。
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
## 工作机制:行为-结果矩阵
|
|
40
|
+
**Anchor 就是贴在终端显示器边框上的一张电子便签** —— 独立保存在全局 `~/.anchor/state.json`(全工程仅 4 个核心源码文件、0 外部依赖、20KB 体积),只做三件有小巧思的事:
|
|
70
41
|
|
|
42
|
+
### 1. 随手一贴,自动认路(无需填表打标签)
|
|
43
|
+
直接用大白话敲一句:
|
|
71
44
|
```text
|
|
72
|
-
|
|
73
|
-
│ Anchor 核心生命周期状态机 │
|
|
74
|
-
└──────────────────────────────────────┬───────────────────────────────────────┘
|
|
75
|
-
│ 记录任务: anchor "重构鉴权为 HttpOnly Cookie"
|
|
76
|
-
▼
|
|
77
|
-
┌───────────────────────────────────────────────┐
|
|
78
|
-
│ [活跃期 ACTIVE] (首轮注入提示) │
|
|
79
|
-
│ - 底部状态栏指示: ⌖ 4 │
|
|
80
|
-
│ - 第 2 轮起完全脱离提示词 (0 Token 稳态) │
|
|
81
|
-
└───────┬───────────────────────────────┬───────┘
|
|
82
|
-
│ │
|
|
83
|
-
Git 提交命中 / │ │ 闲置时间衰减
|
|
84
|
-
触碰关联代码文件 ▼ ▼
|
|
85
|
-
┌──────────────────────────────┐ ┌────────────────────────────────┐
|
|
86
|
-
│ [多语言语法安全 JIT 唤醒] │ │ [休眠期 SLEEPING] (0 Token) │
|
|
87
|
-
│ 触碰代码时注入语言对应注释 │ │ 全局安全封存,不打扰当前心流, │
|
|
88
|
-
│ JSON/ENV 等格式绝对跳过 │ │ 触碰关联文件时重新唤醒 │
|
|
89
|
-
└──────────────┬───────────────┘ └────────────────┬───────────────┘
|
|
90
|
-
│ │
|
|
91
|
-
退出自动提议 / Commit 命中 │ 静默定期清理
|
|
92
|
-
▼ ▼
|
|
93
|
-
┌──────────────────────────────┐ ┌────────────────────────────────┐
|
|
94
|
-
│ [已完成归档 SETTLED] │ │ [超期淘汰 GRAVEYARD] │
|
|
95
|
-
│ 追加写入 archive.jsonl 归档 │ │ 超期自动清理,防止陈旧堆积 │
|
|
96
|
-
│ 从当前活跃上下文中物理移除 │ │ │
|
|
97
|
-
└──────────────────────────────┘ └────────────────────────────────┘
|
|
45
|
+
/pin 把 src/auth.ts 的登录改用 HttpOnly Cookie
|
|
98
46
|
```
|
|
47
|
+
Anchor 会自动从这句话里认出文件名 `src/auth.ts`(或诸如 `D:/College/...` 的目录路径),自动绑定到对应工程。下次打开终端时,输入框上方安静浮现小便签(`⌖ 1 note`),你一开始打字它就自动收起,绝不挡视线。
|
|
99
48
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
| **代码触碰** | 正常阅读或修改代码 | 自动匹配关联文件后缀 | 注入对应语法的单行安全注释,绝不破坏代码 | Agent 触碰相关业务模块时 |
|
|
104
|
-
| **代码提交** | `git commit -m "feat: ..."` | 借助 `Intl.Segmenter` 分词匹配 | 自动核销任务并归档至 `archive.jsonl` | 完成开发里程碑,自动打勾 |
|
|
105
|
-
| **会话退出** | 输入 `exit` 或退出终端 | 扫描已改动文件与活跃任务的交集 | 弹出单键核销确认:`[Enter 归档] / [Esc 保留]` | 结束会话,零遗漏确认 |
|
|
49
|
+
### 2. 碰文件时顺手递纸条(平时 0 Token)
|
|
50
|
+
会话第 1 轮冷启动时向 AI 交代一眼当前便签,从第 2 轮起 **0 Token 损耗**。
|
|
51
|
+
只有当 AI 真正读取或修改 `src/auth.ts` 时,Anchor 才会在文件内容末尾顺手附上 1 行合法注释(`// ⌖ Note #1: 把 src/auth.ts 的登录改用 HttpOnly Cookie`),遇到 `.json`、`.env` 等文件则严格跳过。
|
|
106
52
|
|
|
107
|
-
|
|
53
|
+
*(超过 7 天没动过的旧便签会自动加上 `· quiet` 静默省流标记,不在无关工程首轮刷存在感,但在 `/anchor` 列表里永远都在,绝不莫名消失;一旦你进入对应工程目录就会自动唤醒。)*
|
|
108
54
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
所有状态统一保存在用户主目录 `~/.anchor/`,项目内绝不创建任何 `.anchor` 目录:
|
|
113
|
-
```text
|
|
114
|
-
~/.anchor/
|
|
115
|
-
├── state.json # 活跃与休眠任务状态表 (< 10KB,原子写入)
|
|
116
|
-
├── state.lock # 跨进程纯同步原子排他锁 (零依赖)
|
|
117
|
-
├── archive.jsonl # 已完成归档的历史账本 (追加写入)
|
|
118
|
-
└── graveyard.jsonl # 超期脱落墓地账本 (追加写入)
|
|
119
|
-
```
|
|
120
|
-
* **零依赖排他锁**:使用 Node 原生 `fs.openSync` 保证多终端并发读写安全;
|
|
121
|
-
* **死锁自动熔断回收**:若持有锁的进程已终止或超时(5000ms),系统自动安全回收重占;
|
|
122
|
-
* **原子写入与崩溃自愈**:写入临时文件后执行原子重命名,带 Windows NTFS 自旋重试。损坏文件自动备份为 `state.corrupt.${timestamp}.json` 并安全回退。
|
|
123
|
-
|
|
124
|
-
### 2. 防误触结算抽屉与详情查看器 (v0.2.1)
|
|
125
|
-
在 `/anchor` 仪表盘中选中任务后,弹出二级操作菜单:
|
|
126
|
-
* `✓ Settle (完成归档)`:核销并归档任务,提示可通过 `/anchor undo` 撤销恢复;
|
|
127
|
-
* `ℹ View details & associated files`:直接在终端查看完整任务描述、目标日期、关联文件列表与自动化物理验证命令;
|
|
128
|
-
* `↩ Cancel`:安全取消退出,避免直接敲击回车意外核销未完成事项。
|
|
129
|
-
|
|
130
|
-
### 3. 截断开括号守卫 (v0.2.1 · Invariant 11)
|
|
131
|
-
在仪表盘字符串视觉列宽截断算法中,自动清除省略号前紧邻的孤立未闭合开括号(`(`、`[`、`{`、`(`、`【`),消除标点破裂与视觉毛刺。
|
|
132
|
-
|
|
133
|
-
### 4. 0-Token 稳态经济与多语言语法安全 JIT
|
|
134
|
-
* **第 1 轮冷启动**:注入当前工作区的活跃任务承诺与简要行动指南;
|
|
135
|
-
* **第 2 轮起 0 损耗**:任务清单从 System Prompt 中彻底脱敏移除,普通写代码轮次消耗 **0 Token**;
|
|
136
|
-
* **语法安全严格跳过**:根据文件扩展名动态生成合法单行注释(`//`, `#`, `<!-- -->`, `/* */`)。对 **JSON、ENV、Lockfile 与二进制文件坚决返回 null 严格跳过**,杜绝破坏代码解析器。
|
|
137
|
-
|
|
138
|
-
### 5. 冷启动前置物理执行验证
|
|
139
|
-
任务声明 `verifyCommand` 时,系统在启动时自动执行该物理命令。验证通过的任务即刻就地核销,释放认知带宽。
|
|
55
|
+
### 3. 提交代码自动撕便签(支持一键反悔)
|
|
56
|
+
当你或 AI 执行 `git commit -m "feat: 登录改用 HttpOnly Cookie"` 时,Anchor 发现提交说明与便签吻合,当场自动帮你把这张便签撕掉归档(`⌖ Auto-torn off #1`)。
|
|
57
|
+
撕错了?敲一下 `/anchor undo` 就能原封不动贴回来。
|
|
140
58
|
|
|
141
59
|
---
|
|
142
60
|
|
|
143
61
|
## 常用命令
|
|
144
62
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
anchor
|
|
149
|
-
|
|
150
|
-
anchor
|
|
151
|
-
anchor done
|
|
152
|
-
anchor undo # 撤销上一次完成归档
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Pi 扩展内交互命令
|
|
156
|
-
| 命令 | 说明 |
|
|
157
|
-
| :--- | :--- |
|
|
158
|
-
| `/pin <任务描述> [--due tomorrow]` | 快速立项当前工程的跨会话任务(支持指定到期日) |
|
|
159
|
-
| `/anchor` | 在终端内弹出全景交互式任务仪表盘 |
|
|
160
|
-
| `/done <编号>` 或 `/anchor done <编号>` | 按列表行号(`1`)或 ID(`anc-1`)直接完成核销 |
|
|
161
|
-
| `/anchor undo` | 撤销上一次归档的任务 |
|
|
162
|
-
| 状态栏 `⌖ N` | 底部常驻微标签,有活跃任务时显示数量,无任务时 100% 静默隐形 |
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## 横向技术对比
|
|
167
|
-
|
|
168
|
-
| 核心维度 | `gastownhall/beads` | `Gentleman-Programming/engram` | `TODO.md` / `AGENTS.md` | **Anchor ⚓** |
|
|
169
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
170
|
-
| **架构拓扑** | 分布式 SQL 图谱 | 向量检索与 SQLite 常驻进程 | 静态 Markdown 文件 | **轻量解耦协议 + 单文件原子状态机** |
|
|
171
|
-
| **仓库整洁度** | 塞入 200MB Dolt 数据库 | 系统常驻守护进程 | 频繁制造 Git 提交杂质 | **100% 零仓库污染 (`~/.anchor/`)** |
|
|
172
|
-
| **每轮 Token 开销** | 中高频次全量注入 | 高 (全量提示词召回) | 严重 (陈旧清单持续膨胀) | **0 Token 稳态 (仅在触碰文件时 JIT 唤醒)** |
|
|
173
|
-
| **语法注入安全** | 无安全机制 | 原始文本直接拼接 | 静态未格式化文本 | **多语言语法安全注释,JSON/ENV 严格跳过** |
|
|
174
|
-
| **任务结算与核销** | 手动命令 `close` | 无自动结算机制 | 人工修改文本打勾 | **Git Commit 自动识别 + 退出前一键核销** |
|
|
175
|
-
| **并发读写安全** | SQL 事务排他锁 | 守护进程单点调度 | Git 合并冲突频繁 | **零外部依赖 Node 原生原子排他文件锁** |
|
|
176
|
-
| **启动性能损耗** | 较重 CLI 引导 | Go 进程通信延迟 | 无损耗 | **< 90ms 轻量打包生产产物** |
|
|
177
|
-
| **底层运行依赖** | 外部 Dolt 二进制 | 外部 Go 二进制 | 无依赖 | **零原生二进制外部依赖 (纯 TypeScript)** |
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## 作者手记 (Author's Note)
|
|
182
|
-
|
|
183
|
-
写 Anchor 的最初冲动,来自于我用终端 AI 编程智能体结对开发时经历的一场持续阵痛:看着项目根目录下的 `TODO.md` 与 `AGENTS.md` 在 Git 历史里发霉。
|
|
184
|
-
|
|
185
|
-
很多时候,写完一段代码已经是深夜,跨会话未完成的任务随手记在项目的 Markdown 里,看起来省事。然而几个月下来,两点物理摩擦让我极其痛苦:
|
|
186
|
-
1. 每一轮对话交互,AI 都要把陈旧的任务清单整段塞进系统提示词,白白烧掉几十上百行 Token,还会分散模型对当前正在修改的代码的注意力;
|
|
187
|
-
2. 团队多人协作或分支合并时,这类任务清单文件频发 Git 合并冲突,无端污染了核心代码的提交历史。
|
|
188
|
-
|
|
189
|
-
调研现存工具时,我发现社区给出的方案走向了沉重的极端:为了管理几个简单的任务,有的方案直接在代码仓库根目录塞入一个超过 200MB 的 Dolt SQL 关系型数据库(`beads`),有的方案在后台常驻一个用 Go 编写的 SQLite 守护进程并做持续向量检索(`engram`)。一个任务追踪工具消耗的系统资源与认知负担,甚至超过了开发者正在编写的业务代码本身。
|
|
190
|
-
|
|
191
|
-
这颠倒了工具与生产者的关系。
|
|
192
|
-
|
|
193
|
-
Anchor 选择了一条极度克制的工程路径:把状态移出代码仓库,托管在用户主目录下的单文件轻量状态表(`~/.anchor/state.json`);首轮对话注入冷启动上下文,第 2 轮起保持 0 Token 损耗;通过语言对应的语法安全注释在触碰代码时精准唤醒,并在代码提交或会话退出时自动核销。
|
|
194
|
-
|
|
195
|
-
在 v0.2.1 中,我们还为 `/anchor` 增加了防误触详情面板,按回车可以从容查看关联文件与执行命令,并在排版算法中消除了开括号截断毛刺。
|
|
196
|
-
|
|
197
|
-
希望 Anchor 能让你的代码仓库保持干净,把专注力还给代码本身。
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 质量验证与构建
|
|
202
|
-
|
|
203
|
-
基于严格 TypeScript 与 Node 原生测试运行器,保持 100% 标准库覆盖:
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
npm run typecheck # TypeScript 严格类型检查 (0 错误)
|
|
207
|
-
npm test # 全套自动化单元测试 (31/31 全绿通过)
|
|
208
|
-
npm run build # tsup 双格式打包 (ESM/CJS) 与 .d.ts 类型生成
|
|
209
|
-
```
|
|
63
|
+
| 场景 | 命令 | 作用 |
|
|
64
|
+
| :--- | :--- | :--- |
|
|
65
|
+
| **Pi 终端内** | `/pin <内容>` | 随手贴一张新便签(也可以直接对 AI 说 *“记一下明天…”*) |
|
|
66
|
+
| **Pi 终端内** | `/anchor` | 打开便签列表,回车即可撕掉(Done)或查看详情 |
|
|
67
|
+
| **Pi 终端内** | `/done 1` | 直接按编号撕掉第 1 张便签 |
|
|
68
|
+
| **Pi 终端内** | `/anchor undo` | 把刚撕掉的便签重新贴回来 |
|
|
69
|
+
| **系统命令行** | `anchor` / `anchor "<内容>"` / `anchor done 1` | 不开 Pi 也能随时在终端查看或贴便签 |
|
|
210
70
|
|
|
211
71
|
---
|
|
212
72
|
|