Skip to content

Commit 60dffe3

Browse files
authored
Merge pull request #176 from Opencode-DCP/feat/high-fidelity-pruning
Update prune distillation guidelines for high fidelity
2 parents fa111c9 + e2cf9c9 commit 60dffe3

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

lib/prompts/prune-system-prompt.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Every tool call adds to your context debt. You MUST pay this down regularly and
1010
WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER
1111
1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore. No distillation.
1212
2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune. No distillation.
13-
3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Be surgical and strategic in what you extract. THINK: high signal, low noise
13+
3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Your distillation must be high-fidelity and comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute.
1414

1515
You WILL use the `prune` tool when ANY of these are true:
1616
- Task or sub-task is complete

lib/prompts/prune-tool-spec.txt

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ You must use this tool in three specific scenarios. The rules for distillation (
2323
**When:** You have gathered useful information. Wait until you have several items or a few large outputs to prune, rather than doing tiny, frequent prunes. Aim for high-impact prunes that significantly reduce context size.
2424
**Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant).
2525
**Distillation:** MANDATORY. You MUST provide the distilled findings in the `metadata.distillation` parameter of the `prune` tool (as an object).
26-
- **Extract specific value:** If you read a large file but only care about one function, record that function's details.
27-
- **Consolidate:** When pruning multiple tools, your distillation object MUST aggregate findings from ALL of them. Ensure you capture any information necessary to solve the current task.
28-
- Structure: Map the `ID` from the `<prunable-tools>` list to its distilled findings.
29-
Example: `{ "20": { "findings": "...", "logic": "..." } }`
26+
- **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered.
27+
- **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation.
28+
- **Consolidate:** When pruning multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being pruned. You must capture high-fidelity findings for each tool individually to ensure no signal is lost.
29+
- Structure: Map EVERY `ID` from the `ids` array to its specific distilled findings.
30+
Example: `{ "20": { ... }, "21": { ... } }`
3031
- Capture all relevant details (function names, logic, constraints) to ensure no signal is lost.
3132
- Prioritize information that is essential for the immediate next steps of your plan.
3233
- Once distilled into the `metadata` object, the raw tool output can be safely pruned.
3334
- **Know when distillation isn't enough:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original.
3435
- **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls.
3536

3637
## Best Practices
38+
- **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps.
3739
- **Strategic Consolidation:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Instead, wait until you have several items or large outputs to perform high-impact prunes. This balances the need for an agile context with the efficiency of larger batches.
3840
- **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it.
3941

@@ -46,16 +48,31 @@ This file isn't relevant to the auth system. I'll remove it to clear the context
4648
</example_noise>
4749

4850
<example_consolidation>
49-
Assistant: [Reads 5 different config files]
50-
I'll preserve the configuration details and prune the raw reads.
51-
[Uses prune with ids: ["10", "11", "12", "13", "14"], metadata: {
51+
Assistant: [Reads service implementation, types, and config]
52+
I'll preserve the full technical specification and implementation logic before pruning.
53+
[Uses prune with ids: ["10", "11", "12"], metadata: {
5254
"reason": "consolidation",
5355
"distillation": {
54-
"10": "uses port 3000",
55-
"11": "connects to mongo:27017",
56-
"12": "defines shared constants",
57-
"13": "export defaults",
58-
"14": "unused fallback"
56+
"10": {
57+
"file": "src/services/auth.ts",
58+
"signatures": [
59+
"async function validateToken(token: string): Promise<User | null>",
60+
"function hashPassword(password: string): string"
61+
],
62+
"logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.",
63+
"dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"],
64+
"constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds."
65+
},
66+
"11": {
67+
"file": "src/types/user.ts",
68+
"interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }",
69+
"context": "The permissions array is strictly typed and used by the RBAC middleware."
70+
},
71+
"12": {
72+
"file": "config/default.json",
73+
"values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 },
74+
"impact": "The retry strategy affects all outgoing HTTP clients in the core module."
75+
}
5976
}
6077
}]
6178
</example_consolidation>

lib/strategies/prune-tool.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ export function createPruneTool(
143143
toolMetadata,
144144
workingDirectory
145145
)
146-
147-
if (distillation) {
148-
logger.info("Distillation data received:", distillation)
149-
}
146+
//
147+
// if (distillation) {
148+
// logger.info("Distillation data received:", distillation)
149+
// }
150150

151151
return result
152152
},

0 commit comments

Comments
 (0)