Skip to content

Commit 418ad56

Browse files
PR #332: prompts rewrite, build prompt gen, tool schemas, compress default permission
2 parents 5b88376 + 451fb00 commit 418ad56

File tree

16 files changed

+207
-292
lines changed

16 files changed

+207
-292
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Thumbs.db
2929
.opencode/
3030

3131
# Generated prompt files (from scripts/generate-prompts.ts)
32-
lib/prompts/*.generated.ts
32+
lib/prompts/**/*.generated.ts
3333

3434
# Tests
3535
tests/results/

index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ const plugin: Plugin = (async (ctx) => {
112112
logger.info(
113113
`Added ${toolsToAdd.map((t) => `'${t}'`).join(" and ")} to experimental.primary_tools via config mutation`,
114114
)
115+
116+
// Set compress permission to ask (only if not already configured)
117+
if (config.tools.compress.enabled) {
118+
const permission = opencodeConfig.permission ?? {}
119+
if (!("compress" in permission)) {
120+
opencodeConfig.permission = {
121+
...permission,
122+
compress: "ask",
123+
} as typeof permission
124+
}
125+
}
115126
}
116127
},
117128
}

lib/prompts/compress-tool-spec.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/prompts/compress.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Use this tool to collapse a contiguous range of conversation into a preserved summary.
2+
3+
THE PHILOSOPHY OF COMPRESS
4+
`compress` transforms verbose conversation sequences into dense, high-fidelity summaries. This is not cleanup - it is crystallization. Your summary becomes the authoritative record of what transpired.
5+
6+
Think of compression as phase transitions: raw exploration becomes refined understanding. The original context served its purpose; your summary now carries that understanding forward.
7+
8+
THE SUMMARY
9+
Your summary must be EXHAUSTIVE. Capture file paths, function signatures, decisions made, constraints discovered, key findings... EVERYTHING that maintains context integrity. This is not a brief note - it is an authoritative record so faithful that the original conversation adds no value.
10+
11+
Yet be LEAN. Strip away the noise: failed attempts that led nowhere, verbose tool outputs, back-and-forth exploration. What remains should be pure signal - golden nuggets of detail that preserve full understanding with zero ambiguity.
12+
13+
THE WAYS OF COMPRESS
14+
`compress` when a chapter closes - when a phase of work is truly complete and the raw conversation has served its purpose:
15+
16+
Research concluded and findings are clear
17+
Implementation finished and verified
18+
Exploration exhausted and patterns understood
19+
20+
Do NOT compress when:
21+
You may need exact code, error messages, or file contents from the range
22+
Work in that area is still active or may resume
23+
You're mid-sprint on related functionality
24+
25+
Before compressing, ask: _"Is this chapter closed?"_ Compression is irreversible. The summary replaces everything in the range.
26+
27+
BOUNDARY MATCHING
28+
You specify boundaries by matching unique text strings in the conversation. CRITICAL: In code-centric conversations, strings repeat often. Provide sufficiently unique text to match exactly once. If a match fails (not found or found multiple times), the tool will error - extend your boundary string with more surrounding context in order to make SURE the tool does NOT error.
29+
30+
THE FORMAT OF COMPRESS
31+
`topic`: Short label (3-5 words) for display - e.g., "Auth System Exploration"
32+
`content`: Object containing:
33+
`startString`: Unique text string marking the beginning of the range
34+
`endString`: Unique text string marking the end of the range
35+
`summary`: Complete technical summary replacing all content in the range

lib/prompts/distill-tool-spec.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/prompts/distill.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Use this tool to distill relevant findings from a selection of raw tool outputs into preserved knowledge, in order to denoise key bits and parts of context.
2+
3+
THE PRUNABLE TOOLS LIST
4+
A <prunable-tools> will show in context when outputs are available for distillation (you don't need to look for it). Each entry follows the format `ID: tool, parameter (~token usage)` (e.g., `20: read, /path/to/file.ts (~1500 tokens)`). You MUST select outputs by their numeric ID. THESE ARE YOUR ONLY VALID TARGETS.
5+
6+
THE PHILOSOPHY OF DISTILLATION
7+
`distill` is your favored instrument for transforming raw tool outputs into preserved knowledge. This is not mere summarization; it is high-fidelity extraction that makes the original output obsolete.
8+
9+
Your distillation must be COMPLETE. Capture function signatures, type definitions, business logic, constraints, configuration values... EVERYTHING essential. Think of it as creating a high signal technical substitute so faithful that re-fetching the original would yield no additional value. Be thorough; be comprehensive; leave no ambiguity, ensure that your distillation stands alone, and is designed for easy retrieval and comprehension.
10+
11+
AIM FOR IMPACT. Distillation is most powerful when applied to outputs that contain signal buried in noise. A single line requires no distillation; a hundred lines of API documentation do. Make sure the distillation is meaningful.
12+
13+
THE WAYS OF DISTILL
14+
`distill` when you have extracted the essence from tool outputs and the raw form has served its purpose.
15+
Here are some examples:
16+
EXPLORATION: You've read extensively and grasp the architecture. The original file contents are no longer needed; your understanding, synthesized, is sufficient.
17+
PRESERVATION: Valuable technical details (signatures, logic, constraints) coexist with noise. Preserve the former; discard the latter.
18+
19+
Not everything should be distilled. Prefer keeping raw outputs when:
20+
PRECISION MATTERS: You will edit the file, grep for exact strings, or need line-accurate references. Distillation sacrifices precision for essence.
21+
UNCERTAINTY REMAINS: If you might need to re-examine the original, defer. Distillation is irreversible; be certain before you commit.
22+
23+
Before distilling, ask yourself: _"Will I need the raw output for upcoming work?"_ If you plan to edit a file you just read, keep it intact. Distillation is for completed exploration, not active work.
24+
25+
THE FORMAT OF DISTILL
26+
`targets`: Array of objects, each containing:
27+
`id`: Numeric ID (as string) from the `<prunable-tools>` list
28+
`distillation`: Complete technical substitute for that tool output

lib/prompts/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// Tool specs
2-
import { PRUNE_TOOL_SPEC } from "./prune-tool-spec"
3-
import { DISTILL_TOOL_SPEC } from "./distill-tool-spec"
4-
import { COMPRESS_TOOL_SPEC } from "./compress-tool-spec"
5-
61
// Generated prompts (from .md files via scripts/generate-prompts.ts)
7-
import { SYSTEM as SYSTEM_PROMPT } from "./system.generated"
8-
import { NUDGE } from "./nudge.generated"
2+
import { SYSTEM as SYSTEM_PROMPT } from "./_codegen/system.generated"
3+
import { NUDGE } from "./_codegen/nudge.generated"
4+
import { PRUNE as PRUNE_TOOL_SPEC } from "./_codegen/prune.generated"
5+
import { DISTILL as DISTILL_TOOL_SPEC } from "./_codegen/distill.generated"
6+
import { COMPRESS as COMPRESS_TOOL_SPEC } from "./_codegen/compress.generated"
97

108
export interface ToolFlags {
119
distill: boolean

lib/prompts/nudge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ You should prioritize context management, but do not interrupt a critical atomic
77

88
IMMEDIATE ACTION REQUIRED
99
<distill>KNOWLEDGE PRESERVATION: If holding valuable raw data you POTENTIALLY will need in your task, use the `distill` tool. Produce a high-fidelity distillation to preserve insights - be thorough</distill>
10-
<prune>NOISE REMOVAL: If you read files or ran commands that yielded no value, use the `prune` tool to remove them. If newer tools supersedes older ones, prune the old</prune>
1110
<compress>PHASE COMPLETION: If a phase is complete, use the `compress` tool to condense the entire sequence into a detailed summary</compress>
11+
<prune>NOISE REMOVAL: If you read files or ran commands that yielded no value, use the `prune` tool to remove them. If newer tools supersedes older ones, prune the old</prune>
1212
</instruction>

lib/prompts/prune-tool-spec.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/prompts/prune.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Use this tool to remove tool outputs from context entirely. No preservation - pure deletion.
2+
3+
THE PRUNABLE TOOLS LIST
4+
A `<prunable-tools>` section surfaces in context showing outputs eligible for removal. Each line reads `ID: tool, parameter (~token usage)` (e.g., `20: read, /path/to/file.ts (~1500 tokens)`). Reference outputs by their numeric ID - these are your ONLY valid targets for pruning.
5+
6+
THE WAYS OF PRUNE
7+
`prune` is surgical excision - eliminating noise (irrelevant or unhelpful outputs), superseded information (older outputs replaced by newer data), or wrong targets (you accessed something that turned out to be irrelevant). Use it to keep your context lean and focused.
8+
9+
BATCH WISELY! Pruning is most effective when consolidated. Don't prune a single tiny output - accumulate several candidates before acting.
10+
11+
Do NOT prune when:
12+
NEEDED LATER: You plan to edit the file or reference this context for implementation.
13+
UNCERTAINTY: If you might need to re-examine the original, keep it.
14+
15+
Before pruning, ask: _"Is this noise, or will it serve me?"_ If the latter, keep it. Pruning that forces re-fetching is a net loss.
16+
17+
THE FORMAT OF PRUNE
18+
`ids`: Array of numeric IDs (as strings) from the `<prunable-tools>` list

0 commit comments

Comments
 (0)