pi-planning-with-files 1.0.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/reference.md ADDED
@@ -0,0 +1,218 @@
1
+ # Reference: Manus Context Engineering Principles
2
+
3
+ This skill is based on context engineering principles from Manus, the AI agent company acquired by Meta for $2 billion in December 2025.
4
+
5
+ ## The 6 Manus Principles
6
+
7
+ ### Principle 1: Design Around KV-Cache
8
+
9
+ > "KV-cache hit rate is THE single most important metric for production AI agents."
10
+
11
+ **Statistics:**
12
+ - ~100:1 input-to-output token ratio
13
+ - Cached tokens: $0.30/MTok vs Uncached: $3/MTok
14
+ - 10x cost difference!
15
+
16
+ **Implementation:**
17
+ - Keep prompt prefixes STABLE (single-token change invalidates cache)
18
+ - NO timestamps in system prompts
19
+ - Make context APPEND-ONLY with deterministic serialization
20
+
21
+ ### Principle 2: Mask, Don't Remove
22
+
23
+ Don't dynamically remove tools (breaks KV-cache). Use logit masking instead.
24
+
25
+ **Best Practice:** Use consistent action prefixes (e.g., `browser_`, `shell_`, `file_`) for easier masking.
26
+
27
+ ### Principle 3: Filesystem as External Memory
28
+
29
+ > "Markdown is my 'working memory' on disk."
30
+
31
+ **The Formula:**
32
+ ```
33
+ Context Window = RAM (volatile, limited)
34
+ Filesystem = Disk (persistent, unlimited)
35
+ ```
36
+
37
+ **Compression Must Be Restorable:**
38
+ - Keep URLs even if web content is dropped
39
+ - Keep file paths when dropping document contents
40
+ - Never lose the pointer to full data
41
+
42
+ ### Principle 4: Manipulate Attention Through Recitation
43
+
44
+ > "Creates and updates todo.md throughout tasks to push global plan into model's recent attention span."
45
+
46
+ **Problem:** After ~50 tool calls, models forget original goals ("lost in the middle" effect).
47
+
48
+ **Solution:** Re-read `task_plan.md` before each decision. Goals appear in the attention window.
49
+
50
+ ```
51
+ Start of context: [Original goal - far away, forgotten]
52
+ ...many tool calls...
53
+ End of context: [Recently read task_plan.md - gets ATTENTION!]
54
+ ```
55
+
56
+ ### Principle 5: Keep the Wrong Stuff In
57
+
58
+ > "Leave the wrong turns in the context."
59
+
60
+ **Why:**
61
+ - Failed actions with stack traces let model implicitly update beliefs
62
+ - Reduces mistake repetition
63
+ - Error recovery is "one of the clearest signals of TRUE agentic behavior"
64
+
65
+ ### Principle 6: Don't Get Few-Shotted
66
+
67
+ > "Uniformity breeds fragility."
68
+
69
+ **Problem:** Repetitive action-observation pairs cause drift and hallucination.
70
+
71
+ **Solution:** Introduce controlled variation:
72
+ - Vary phrasings slightly
73
+ - Don't copy-paste patterns blindly
74
+ - Recalibrate on repetitive tasks
75
+
76
+ ---
77
+
78
+ ## The 3 Context Engineering Strategies
79
+
80
+ Based on Lance Martin's analysis of Manus architecture.
81
+
82
+ ### Strategy 1: Context Reduction
83
+
84
+ **Compaction:**
85
+ ```
86
+ Tool calls have TWO representations:
87
+ ├── FULL: Raw tool content (stored in filesystem)
88
+ └── COMPACT: Reference/file path only
89
+
90
+ RULES:
91
+ - Apply compaction to STALE (older) tool results
92
+ - Keep RECENT results FULL (to guide next decision)
93
+ ```
94
+
95
+ **Summarization:**
96
+ - Applied when compaction reaches diminishing returns
97
+ - Generated using full tool results
98
+ - Creates standardized summary objects
99
+
100
+ ### Strategy 2: Context Isolation (Multi-Agent)
101
+
102
+ **Architecture:**
103
+ ```
104
+ ┌─────────────────────────────────┐
105
+ │ PLANNER AGENT │
106
+ │ └─ Assigns tasks to sub-agents │
107
+ ├─────────────────────────────────┤
108
+ │ KNOWLEDGE MANAGER │
109
+ │ └─ Reviews conversations │
110
+ │ └─ Determines filesystem store │
111
+ ├─────────────────────────────────┤
112
+ │ EXECUTOR SUB-AGENTS │
113
+ │ └─ Perform assigned tasks │
114
+ │ └─ Have own context windows │
115
+ └─────────────────────────────────┘
116
+ ```
117
+
118
+ **Key Insight:** Manus originally used `todo.md` for task planning but found ~33% of actions were spent updating it. Shifted to dedicated planner agent calling executor sub-agents.
119
+
120
+ ### Strategy 3: Context Offloading
121
+
122
+ **Tool Design:**
123
+ - Use <20 atomic functions total
124
+ - Store full results in filesystem, not context
125
+ - Use `glob` and `grep` for searching
126
+ - Progressive disclosure: load information only as needed
127
+
128
+ ---
129
+
130
+ ## The Agent Loop
131
+
132
+ Manus operates in a continuous 7-step loop:
133
+
134
+ ```
135
+ ┌─────────────────────────────────────────┐
136
+ │ 1. ANALYZE CONTEXT │
137
+ │ - Understand user intent │
138
+ │ - Assess current state │
139
+ │ - Review recent observations │
140
+ ├─────────────────────────────────────────┤
141
+ │ 2. THINK │
142
+ │ - Should I update the plan? │
143
+ │ - What's the next logical action? │
144
+ │ - Are there blockers? │
145
+ ├─────────────────────────────────────────┤
146
+ │ 3. SELECT TOOL │
147
+ │ - Choose ONE tool │
148
+ │ - Ensure parameters available │
149
+ ├─────────────────────────────────────────┤
150
+ │ 4. EXECUTE ACTION │
151
+ │ - Tool runs in sandbox │
152
+ ├─────────────────────────────────────────┤
153
+ │ 5. RECEIVE OBSERVATION │
154
+ │ - Result appended to context │
155
+ ├─────────────────────────────────────────┤
156
+ │ 6. ITERATE │
157
+ │ - Return to step 1 │
158
+ │ - Continue until complete │
159
+ ├─────────────────────────────────────────┤
160
+ │ 7. DELIVER OUTCOME │
161
+ │ - Send results to user │
162
+ │ - Attach all relevant files │
163
+ └─────────────────────────────────────────┘
164
+ ```
165
+
166
+ ---
167
+
168
+ ## File Types Manus Creates
169
+
170
+ | File | Purpose | When Created | When Updated |
171
+ |------|---------|--------------|--------------|
172
+ | `task_plan.md` | Phase tracking, progress | Task start | After completing phases |
173
+ | `findings.md` | Discoveries, decisions | After ANY discovery | After viewing images/PDFs |
174
+ | `progress.md` | Session log, what's done | At breakpoints | Throughout session |
175
+ | Code files | Implementation | Before execution | After errors |
176
+
177
+ ---
178
+
179
+ ## Critical Constraints
180
+
181
+ - **Single-Action Execution:** ONE tool call per turn. No parallel execution.
182
+ - **Plan is Required:** Agent must ALWAYS know: goal, current phase, remaining phases
183
+ - **Files are Memory:** Context = volatile. Filesystem = persistent.
184
+ - **Never Repeat Failures:** If action failed, next action MUST be different
185
+ - **Communication is a Tool:** Message types: `info` (progress), `ask` (blocking), `result` (terminal)
186
+
187
+ ---
188
+
189
+ ## Manus Statistics
190
+
191
+ | Metric | Value |
192
+ |--------|-------|
193
+ | Average tool calls per task | ~50 |
194
+ | Input-to-output token ratio | 100:1 |
195
+ | Acquisition price | $2 billion |
196
+ | Time to $100M revenue | 8 months |
197
+ | Framework refactors since launch | 5 times |
198
+
199
+ ---
200
+
201
+ ## Key Quotes
202
+
203
+ > "Context window = RAM (volatile, limited). Filesystem = Disk (persistent, unlimited). Anything important gets written to disk."
204
+
205
+ > "if action_failed: next_action != same_action. Track what you tried. Mutate the approach."
206
+
207
+ > "Error recovery is one of the clearest signals of TRUE agentic behavior."
208
+
209
+ > "KV-cache hit rate is the single most important metric for a production-stage AI agent."
210
+
211
+ > "Leave the wrong turns in the context."
212
+
213
+ ---
214
+
215
+ ## Source
216
+
217
+ Based on Manus's official context engineering documentation:
218
+ https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
@@ -0,0 +1,42 @@
1
+ # Check if all phases in task_plan.md are complete
2
+ # Exit 0 if complete, exit 1 if incomplete
3
+ # Used by Stop hook to verify task completion
4
+
5
+ param(
6
+ [string]$PlanFile = "task_plan.md"
7
+ )
8
+
9
+ if (-not (Test-Path $PlanFile)) {
10
+ Write-Host "ERROR: $PlanFile not found"
11
+ Write-Host "Cannot verify completion without a task plan."
12
+ exit 1
13
+ }
14
+
15
+ Write-Host "=== Task Completion Check ==="
16
+ Write-Host ""
17
+
18
+ # Read file content
19
+ $content = Get-Content $PlanFile -Raw
20
+
21
+ # Count phases by status
22
+ $TOTAL = ([regex]::Matches($content, "### Phase")).Count
23
+ $COMPLETE = ([regex]::Matches($content, "\*\*Status:\*\* complete")).Count
24
+ $IN_PROGRESS = ([regex]::Matches($content, "\*\*Status:\*\* in_progress")).Count
25
+ $PENDING = ([regex]::Matches($content, "\*\*Status:\*\* pending")).Count
26
+
27
+ Write-Host "Total phases: $TOTAL"
28
+ Write-Host "Complete: $COMPLETE"
29
+ Write-Host "In progress: $IN_PROGRESS"
30
+ Write-Host "Pending: $PENDING"
31
+ Write-Host ""
32
+
33
+ # Check completion
34
+ if ($COMPLETE -eq $TOTAL -and $TOTAL -gt 0) {
35
+ Write-Host "ALL PHASES COMPLETE"
36
+ exit 0
37
+ } else {
38
+ Write-Host "TASK NOT COMPLETE"
39
+ Write-Host ""
40
+ Write-Host "Do not stop until all phases are complete."
41
+ exit 1
42
+ }
@@ -0,0 +1,44 @@
1
+ #!/bin/bash
2
+ # Check if all phases in task_plan.md are complete
3
+ # Exit 0 if complete, exit 1 if incomplete
4
+ # Used by Stop hook to verify task completion
5
+
6
+ PLAN_FILE="${1:-task_plan.md}"
7
+
8
+ if [ ! -f "$PLAN_FILE" ]; then
9
+ echo "ERROR: $PLAN_FILE not found"
10
+ echo "Cannot verify completion without a task plan."
11
+ exit 1
12
+ fi
13
+
14
+ echo "=== Task Completion Check ==="
15
+ echo ""
16
+
17
+ # Count phases by status (using -F for fixed string matching)
18
+ TOTAL=$(grep -c "### Phase" "$PLAN_FILE" || true)
19
+ COMPLETE=$(grep -cF "**Status:** complete" "$PLAN_FILE" || true)
20
+ IN_PROGRESS=$(grep -cF "**Status:** in_progress" "$PLAN_FILE" || true)
21
+ PENDING=$(grep -cF "**Status:** pending" "$PLAN_FILE" || true)
22
+
23
+ # Default to 0 if empty
24
+ : "${TOTAL:=0}"
25
+ : "${COMPLETE:=0}"
26
+ : "${IN_PROGRESS:=0}"
27
+ : "${PENDING:=0}"
28
+
29
+ echo "Total phases: $TOTAL"
30
+ echo "Complete: $COMPLETE"
31
+ echo "In progress: $IN_PROGRESS"
32
+ echo "Pending: $PENDING"
33
+ echo ""
34
+
35
+ # Check completion
36
+ if [ "$COMPLETE" -eq "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then
37
+ echo "ALL PHASES COMPLETE"
38
+ exit 0
39
+ else
40
+ echo "TASK NOT COMPLETE"
41
+ echo ""
42
+ echo "Do not stop until all phases are complete."
43
+ exit 1
44
+ fi
@@ -0,0 +1,120 @@
1
+ # Initialize planning files for a new session
2
+ # Usage: .\init-session.ps1 [project-name]
3
+
4
+ param(
5
+ [string]$ProjectName = "project"
6
+ )
7
+
8
+ $DATE = Get-Date -Format "yyyy-MM-dd"
9
+
10
+ Write-Host "Initializing planning files for: $ProjectName"
11
+
12
+ # Create task_plan.md if it doesn't exist
13
+ if (-not (Test-Path "task_plan.md")) {
14
+ @"
15
+ # Task Plan: [Brief Description]
16
+
17
+ ## Goal
18
+ [One sentence describing the end state]
19
+
20
+ ## Current Phase
21
+ Phase 1
22
+
23
+ ## Phases
24
+
25
+ ### Phase 1: Requirements & Discovery
26
+ - [ ] Understand user intent
27
+ - [ ] Identify constraints
28
+ - [ ] Document in findings.md
29
+ - **Status:** in_progress
30
+
31
+ ### Phase 2: Planning & Structure
32
+ - [ ] Define approach
33
+ - [ ] Create project structure
34
+ - **Status:** pending
35
+
36
+ ### Phase 3: Implementation
37
+ - [ ] Execute the plan
38
+ - [ ] Write to files before executing
39
+ - **Status:** pending
40
+
41
+ ### Phase 4: Testing & Verification
42
+ - [ ] Verify requirements met
43
+ - [ ] Document test results
44
+ - **Status:** pending
45
+
46
+ ### Phase 5: Delivery
47
+ - [ ] Review outputs
48
+ - [ ] Deliver to user
49
+ - **Status:** pending
50
+
51
+ ## Decisions Made
52
+ | Decision | Rationale |
53
+ |----------|-----------|
54
+
55
+ ## Errors Encountered
56
+ | Error | Resolution |
57
+ |-------|------------|
58
+ "@ | Out-File -FilePath "task_plan.md" -Encoding UTF8
59
+ Write-Host "Created task_plan.md"
60
+ } else {
61
+ Write-Host "task_plan.md already exists, skipping"
62
+ }
63
+
64
+ # Create findings.md if it doesn't exist
65
+ if (-not (Test-Path "findings.md")) {
66
+ @"
67
+ # Findings & Decisions
68
+
69
+ ## Requirements
70
+ -
71
+
72
+ ## Research Findings
73
+ -
74
+
75
+ ## Technical Decisions
76
+ | Decision | Rationale |
77
+ |----------|-----------|
78
+
79
+ ## Issues Encountered
80
+ | Issue | Resolution |
81
+ |-------|------------|
82
+
83
+ ## Resources
84
+ -
85
+ "@ | Out-File -FilePath "findings.md" -Encoding UTF8
86
+ Write-Host "Created findings.md"
87
+ } else {
88
+ Write-Host "findings.md already exists, skipping"
89
+ }
90
+
91
+ # Create progress.md if it doesn't exist
92
+ if (-not (Test-Path "progress.md")) {
93
+ @"
94
+ # Progress Log
95
+
96
+ ## Session: $DATE
97
+
98
+ ### Current Status
99
+ - **Phase:** 1 - Requirements & Discovery
100
+ - **Started:** $DATE
101
+
102
+ ### Actions Taken
103
+ -
104
+
105
+ ### Test Results
106
+ | Test | Expected | Actual | Status |
107
+ |------|----------|--------|--------|
108
+
109
+ ### Errors
110
+ | Error | Resolution |
111
+ |-------|------------|
112
+ "@ | Out-File -FilePath "progress.md" -Encoding UTF8
113
+ Write-Host "Created progress.md"
114
+ } else {
115
+ Write-Host "progress.md already exists, skipping"
116
+ }
117
+
118
+ Write-Host ""
119
+ Write-Host "Planning files initialized!"
120
+ Write-Host "Files: task_plan.md, findings.md, progress.md"
@@ -0,0 +1,120 @@
1
+ #!/bin/bash
2
+ # Initialize planning files for a new session
3
+ # Usage: ./init-session.sh [project-name]
4
+
5
+ set -e
6
+
7
+ PROJECT_NAME="${1:-project}"
8
+ DATE=$(date +%Y-%m-%d)
9
+
10
+ echo "Initializing planning files for: $PROJECT_NAME"
11
+
12
+ # Create task_plan.md if it doesn't exist
13
+ if [ ! -f "task_plan.md" ]; then
14
+ cat > task_plan.md << 'EOF'
15
+ # Task Plan: [Brief Description]
16
+
17
+ ## Goal
18
+ [One sentence describing the end state]
19
+
20
+ ## Current Phase
21
+ Phase 1
22
+
23
+ ## Phases
24
+
25
+ ### Phase 1: Requirements & Discovery
26
+ - [ ] Understand user intent
27
+ - [ ] Identify constraints
28
+ - [ ] Document in findings.md
29
+ - **Status:** in_progress
30
+
31
+ ### Phase 2: Planning & Structure
32
+ - [ ] Define approach
33
+ - [ ] Create project structure
34
+ - **Status:** pending
35
+
36
+ ### Phase 3: Implementation
37
+ - [ ] Execute the plan
38
+ - [ ] Write to files before executing
39
+ - **Status:** pending
40
+
41
+ ### Phase 4: Testing & Verification
42
+ - [ ] Verify requirements met
43
+ - [ ] Document test results
44
+ - **Status:** pending
45
+
46
+ ### Phase 5: Delivery
47
+ - [ ] Review outputs
48
+ - [ ] Deliver to user
49
+ - **Status:** pending
50
+
51
+ ## Decisions Made
52
+ | Decision | Rationale |
53
+ |----------|-----------|
54
+
55
+ ## Errors Encountered
56
+ | Error | Resolution |
57
+ |-------|------------|
58
+ EOF
59
+ echo "Created task_plan.md"
60
+ else
61
+ echo "task_plan.md already exists, skipping"
62
+ fi
63
+
64
+ # Create findings.md if it doesn't exist
65
+ if [ ! -f "findings.md" ]; then
66
+ cat > findings.md << 'EOF'
67
+ # Findings & Decisions
68
+
69
+ ## Requirements
70
+ -
71
+
72
+ ## Research Findings
73
+ -
74
+
75
+ ## Technical Decisions
76
+ | Decision | Rationale |
77
+ |----------|-----------|
78
+
79
+ ## Issues Encountered
80
+ | Issue | Resolution |
81
+ |-------|------------|
82
+
83
+ ## Resources
84
+ -
85
+ EOF
86
+ echo "Created findings.md"
87
+ else
88
+ echo "findings.md already exists, skipping"
89
+ fi
90
+
91
+ # Create progress.md if it doesn't exist
92
+ if [ ! -f "progress.md" ]; then
93
+ cat > progress.md << EOF
94
+ # Progress Log
95
+
96
+ ## Session: $DATE
97
+
98
+ ### Current Status
99
+ - **Phase:** 1 - Requirements & Discovery
100
+ - **Started:** $DATE
101
+
102
+ ### Actions Taken
103
+ -
104
+
105
+ ### Test Results
106
+ | Test | Expected | Actual | Status |
107
+ |------|----------|--------|--------|
108
+
109
+ ### Errors
110
+ | Error | Resolution |
111
+ |-------|------------|
112
+ EOF
113
+ echo "Created progress.md"
114
+ else
115
+ echo "progress.md already exists, skipping"
116
+ fi
117
+
118
+ echo ""
119
+ echo "Planning files initialized!"
120
+ echo "Files: task_plan.md, findings.md, progress.md"