pi-context 1.0.3 → 1.0.4

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 CHANGED
@@ -4,7 +4,8 @@ A Git-like context management tool that allows AI agents to proactively manage t
4
4
 
5
5
  Inspired by kimi-cli d-mail, implementing lossless time travel on the Pi session tree.
6
6
 
7
- Blog: [中文](https://blog.xlab.app/p/6a966aeb/) [EN](https://blog.xlab.app/p/51d26495/)
7
+ For the design philosophy, see the [blog post](https://blog.xlab.app/p/51d26495/)
8
+ ([中文版本](https://blog.xlab.app/p/6a966aeb/)).
8
9
 
9
10
  ## Installation
10
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-context",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "agent-driven context management tools",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,15 +39,15 @@ Follow this cycle for every major task:
39
39
 
40
40
  1. **CHECK:** Verify state.
41
41
  `context_log`
42
- 2. **START:** Tag the beginning.
43
- `context_tag({ name: "task-start" })`
42
+ 2. **START:** Tag the beginning with a semantic name.
43
+ `context_tag({ name: "<task-slug>-start" })` // e.g., `auth-login-start`
44
44
  3. **WORK:** Execute steps.
45
- 4. **MILESTONE:** Tag intermediate stable states (e.g., "Plan done", "Part 1 done").
46
- `context_tag({ name: "task-plan-done" })`
45
+ 4. **MILESTONE:** Tag intermediate stable states.
46
+ `context_tag({ name: "<task-slug>-plan" })` // e.g., `auth-login-plan`
47
47
  5. **SQUASH (Autonomous):** If history becomes noisy or low-density, **Squash with Backup**.
48
- * *Action:* `context_checkout({ target: "task-start", message: "Summarized debugging steps...", backupTag: "pre-squash-backup" })`
49
- * *Action (Optional):* `context_tag({ name: "clean-state" })`
50
- * *Safety:* If you need the details later, you can checkout `pre-squash-backup`.
48
+ * *Action:* `context_checkout({ target: "<task-slug>-start", message: "...", backupTag: "<task-slug>-raw-history" })`
49
+ * *Action (Optional):* `context_tag({ name: "<task-slug>-done" })`
50
+ * *Safety:* If you need the details later, checkout the backup tag.
51
51
 
52
52
  ## Tool Reference
53
53
 
@@ -60,11 +60,32 @@ Follow this cycle for every major task:
60
60
  ## Critical Rules
61
61
 
62
62
  ### Tag Wisely (Build The Skeleton)
63
- Tags are the "Table of Contents". Use them to mark **Start** and **Backups**.
64
- * **Start:** `task-start`
65
- * **Backup:** `task-raw-history` (Created automatically by `backupTag`)
66
- * **Milestone:** `phase-1-done`
67
63
 
64
+ Tags are the "Table of Contents". Name them so you can understand the history at a glance.
65
+
66
+ **Naming Formula:** `<task-slug>-<phase>`
67
+
68
+ * **task-slug**: Short, kebab-case identifier for the task (e.g., `auth-login`, `db-migration`)
69
+ * **phase**: The stage of work (`start`, `plan`, `impl`, `done`, `fail`, `backup`)
70
+
71
+ | Bad (Generic) | Good (Semantic) | Why |
72
+ | :--- | :--- | :--- |
73
+ | `task-start` | `auth-oauth-start` | Describes WHAT task |
74
+ | `pre-research` | `error-log-analysis-start` | Future-you knows the topic |
75
+ | `phase-1-done` | `db-schema-plan-done` | Know which phase of which task |
76
+ | `debug-retry` | `null-pointer-fix-retry` | What bug? |
77
+
78
+ **Tag Categories:**
79
+
80
+ | Category | Pattern | Examples |
81
+ | :--- | :--- | :--- |
82
+ | **Start** | `<task>-start` | `auth-jwt-start`, `docker-setup-start` |
83
+ | **Plan** | `<task>-plan` | `api-v2-plan`, `migration-plan` |
84
+ | **Milestone** | `<task>-<milestone>` | `auth-jwt-impl-done`, `tests-passed` |
85
+ | **Backup** | `<task>-raw-history` | `auth-jwt-raw-history` |
86
+ | **Failure** | `<task>-fail-<reason>` | `auth-jwt-fail-timeout` |
87
+
88
+ **How to generate:** Ask yourself "What is the task?" → Extract 1-3 keywords (e.g., "fix login timeout" → `login-timeout-fix-start`)
68
89
 
69
90
  ### Squash Noise, Keep Signal, Focus on Goal (Context Hygiene)
70
91
  Think of your conversation as a "Feature Branch" full of messy thoughts.
@@ -94,7 +115,7 @@ If you fail 3 times:
94
115
 
95
116
  | Situation | Action | Reason |
96
117
  | :--- | :--- | :--- |
97
- | **Starting Task** | `context_tag({ name: "task-X-start" })` | Create a rollback point. |
118
+ | **Starting Task** | `context_tag({ name: "<task-slug>-start" })` | Create a rollback point. |
98
119
  | **Research / Logs** | `context_checkout` (Squash) | **Process is Noise.** Read 2000 lines -> Keep result. |
99
120
  | **Messy Debugging** | **Squash w/ Backup** | **Cleanup.** The error logs are noise once fixed. |
100
121
  | **Task Done (Candidate)**| **Squash w/ Backup** | **Assume Success.** Summary is usually enough. Backup exists if not. |
@@ -117,17 +138,16 @@ If you cannot answer these, run `context_log`:
117
138
  The `message` is your lifeline to your past self.
118
139
  A good message preserves critical context that would otherwise be lost.
119
140
 
120
- Structure: `[Status] + [Reason] + [Carryover Data] + [Important Changes]`
141
+ Structure: `[Key Finding/Status] + [Reason] + [Important Changes]`
121
142
 
122
- * **Status**: What did you just finish or stop doing?
123
- * **Reason**: Why are you branching/moving? (e.g., "Too much noise", "Task complete", "Failed attempt")
124
- * **Carryover**: What specific details (e.g., IDs, file paths, user constraints) must be remembered?
143
+ * **Key Finding/Status**: What did you discover or complete? Include specific numbers, errors, or outcomes.
144
+ * **Reason**: Why are you branching/moving? (e.g., "Task complete", "Approach failed", "Need raw logs")
125
145
  * **Important Changes**: What files or logic have been modified? (This checkout only resets *conversation history*, NOT disk files, so you must remember what changed.)
126
146
 
127
147
  Examples:
128
148
 
129
- * *Good (Resetting after failure)*: "Abandoning the recursive approach (infinite loop). Switching back to iterative. **Important Changes**: Modified `utils/recursion.ts`. **Carryover**: The test case `test_retry_logic` is the one failing."
130
- * *Good (Cleaning up)*: "Completed authentication module. All tests passed. **Important Changes**: Created `auth/` directory and updated `routes.ts`. **Carryover**: The user ID is stored in `localStorage` under `auth_token`. Moving to Dashboard UI."
149
+ * *Good (Resetting after failure)*: "Recursive parser hit stack overflow at depth 8000. Switching to iterative. **Reason**: Stack limit reached. **Important Changes**: Modified `utils/recursion.ts`."
150
+ * *Good (Cleaning up)*: "Auth module complete: JWT + OAuth2 + RBAC. 23 tests passing. **Reason**: Task done, cleaning context. **Important Changes**: Created `auth/`, modified `routes.ts` and `middleware.ts`."
131
151
  * *Bad*: "Switching context." (Too vague - you will forget why)
132
152
  * *Bad*: "Done." (What is done? What did we learn?)
133
153
 
@@ -141,6 +161,7 @@ Examples:
141
161
  | **Panic** (Apologize repeatedly for errors) | **Revert** (`context_checkout`) to before the error. |
142
162
  | **Blind Checkout** (Guessing IDs) | **Look** (`context_log`) first to get valid IDs. |
143
163
  | **Vague Summaries** ("Done", "Fixed") | **Detailed Summaries** ("Found bug in line 40. Fixed with patch X.") |
164
+ | **Generic Tag Names** (`task-start`, `phase-1`) | **Semantic Names** (`auth-jwt-start`, `db-schema-plan`) |
144
165
 
145
166
  ## Recipes (Copy-Paste)
146
167
 
@@ -148,19 +169,21 @@ Examples:
148
169
  **Goal:** Pure information gathering (Reading files, Searching web).
149
170
  **Why:** The *process* of searching is irrelevant. Only the *result* matters.
150
171
 
172
+ **Example Task:** Analyzing error logs to find root cause of timeout
173
+
151
174
  ```javascript
152
- // 1. Tag BEFORE starting the noisy work
153
- context_tag({ name: "pre-research" });
175
+ // 1. Tag BEFORE starting the noisy work (use descriptive name)
176
+ context_tag({ name: "timeout-analysis-start" });
154
177
 
155
- // ... (Read 5 files, search 3 sites, find 1 key fact) ...
178
+ // ... (Read 5 log files, search 3 docs, find DB connection pool exhaustion) ...
156
179
 
157
180
  // 2. Squash IMMEDIATELY. Do not wait for user.
158
181
  context_checkout({
159
- target: "pre-research",
160
- message: "Researched logs. Found root cause: DB timeout. Irrelevant logs discarded.",
161
- backupTag: "raw-research-logs" // Safety backup
182
+ target: "timeout-analysis-start",
183
+ message: "Found DB connection pool exhaustion as root cause (pool size: 10, peak load: 1000 req/s). Recommended fix: increase to 50. **Reason**: Context cleanup after research. **Important Changes**: None (read-only).",
184
+ backupTag: "timeout-analysis-raw-history" // Safety backup
162
185
  });
163
- context_tag({ name: "research-done" });
186
+ context_tag({ name: "timeout-analysis-done" });
164
187
  ```
165
188
 
166
189
  ### 2. The "Candidate" (Wait for Confirmation)
@@ -168,52 +191,60 @@ context_tag({ name: "research-done" });
168
191
  **Why:** The history is noisy. The result is clean.
169
192
  **Safety:** We create a backup tag automatically.
170
193
 
194
+ **Example Task:** Implementing OAuth login flow
195
+
171
196
  ```javascript
172
197
  // Squash to Summary (Optimistic Cleanup)
173
198
  context_checkout({
174
- target: "feature-a-start", // Squash range: Start -> Now
175
- message: "Feature A implemented. 5 files changed. Tests passed. Revert to 'feature-a-raw-history' for full logs.",
176
- backupTag: "feature-a-raw-history"
199
+ target: "oauth-impl-start", // Squash range: Start -> Now
200
+ message: "OAuth2 flow implemented with PKCE, Google + GitHub providers. All 12 tests passing. **Reason**: Task complete, cleaning up. **Important Changes**: Created `auth/oauth.ts`, modified `routes.ts`, `config.ts`. Backup at 'oauth-impl-raw-history'.",
201
+ backupTag: "oauth-impl-raw-history"
177
202
  });
178
- context_tag({ name: "feature-a-candidate" });
203
+ context_tag({ name: "oauth-impl-candidate" });
179
204
  ```
180
205
 
181
206
  ### 3. The "Undo" (Revert Squash)
182
207
  **Goal:** User asks about a detail you squashed away.
183
208
  **Action:** Jump back to the backup tag.
184
209
 
210
+ **Example Task:** Reviewing OAuth implementation details
211
+
185
212
  ```javascript
186
213
  // Jump back to the raw history
187
214
  context_checkout({
188
- target: "feature-a-raw-history",
189
- message: "Reverting to raw history to check specific error logs."
215
+ target: "oauth-impl-raw-history",
216
+ message: "Reviewing token refresh logic - user reports 401 after 15 min idle. Suspect refresh token not firing. **Reason**: Need raw logs to trace the bug. **Important Changes**: None."
190
217
  });
191
- context_tag({ name: "restored-history" });
218
+ context_tag({ name: "oauth-review-start" });
192
219
  ```
193
220
 
194
221
  ### 4. Branching (Alternative Approach)
195
222
  **Scenario:** Method A failed (and was squashed). You want to try Method B from the clean state.
196
223
  **Action:** Checkout the start point.
197
224
 
225
+ **Example Task:** Fixing memory leak - trying different approaches
226
+
198
227
  ```javascript
199
- // Jump back to start
228
+ // Method A (weak references) failed, trying Method B (object pooling)
200
229
  context_checkout({
201
- target: "task-start",
202
- message: "Method A failed (see summary in 'method-a-fail'). Starting Method B from clean state."
230
+ target: "memory-leak-fix-start",
231
+ message: "WeakRef approach failed: objects GC'd within 30s (expected: 5min). Cache hit rate dropped from 95% to 12%. **Reason**: Switching to object pooling approach. **Important Changes**: `CacheManager.ts` modified (will revert)."
203
232
  });
204
- context_tag({ name: "method-b-start" });
233
+ context_tag({ name: "memory-leak-pool-approach-start" });
205
234
  ```
206
235
 
207
236
  ### 5. The "Undo" (Failed Attempt)
208
237
  You tried to fix a bug but broke everything.
209
238
  **Goal:** Clean up a failed path.
210
239
 
240
+ **Example Task:** Fixing race condition in async handler
241
+
211
242
  ```javascript
212
- // Jump back to safety.
243
+ // Attempted mutex-based fix, but introduced deadlock
213
244
  context_checkout({
214
- target: "pre-debug-tag",
215
- message: "Attempted fix using Method A failed. Error: 'Timeout'.",
216
- backupTag: "failed-attempt-1" // Save the failure just in case
245
+ target: "race-condition-fix-start",
246
+ message: "Mutex caused deadlock: Thread A holds mutex, awaits callback; callback needs mutex held by B; B waits for A. Circular wait detected. **Reason**: Trying lock-free CAS approach next. **Important Changes**: `AsyncQueue.ts` lines 70-90 modified (backup saved).",
247
+ backupTag: "race-condition-mutex-fail" // Save the failure for reference
217
248
  });
218
- context_tag({ name: "debug-retry" });
249
+ context_tag({ name: "race-condition-lockfree-start" });
219
250
  ```