@tarquinen/opencode-dcp 3.2.5-beta0 → 3.2.6-beta0
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/index.ts +141 -0
- package/lib/analysis/tokens.ts +225 -0
- package/lib/auth.ts +37 -0
- package/lib/commands/compression-targets.ts +137 -0
- package/lib/commands/context.ts +132 -0
- package/lib/commands/decompress.ts +275 -0
- package/lib/commands/help.ts +76 -0
- package/lib/commands/index.ts +11 -0
- package/lib/commands/manual.ts +125 -0
- package/lib/commands/recompress.ts +224 -0
- package/lib/commands/stats.ts +148 -0
- package/lib/commands/sweep.ts +268 -0
- package/lib/compress/index.ts +3 -0
- package/lib/compress/message-utils.ts +250 -0
- package/lib/compress/message.ts +137 -0
- package/lib/compress/pipeline.ts +106 -0
- package/lib/compress/protected-content.ts +154 -0
- package/lib/compress/range-utils.ts +308 -0
- package/lib/compress/range.ts +180 -0
- package/lib/compress/search.ts +267 -0
- package/lib/compress/state.ts +268 -0
- package/lib/compress/timing.ts +77 -0
- package/lib/compress/types.ts +108 -0
- package/lib/compress-permission.ts +25 -0
- package/lib/config.ts +1071 -0
- package/lib/hooks.ts +378 -0
- package/lib/host-permissions.ts +101 -0
- package/lib/logger.ts +235 -0
- package/lib/message-ids.ts +172 -0
- package/lib/messages/index.ts +8 -0
- package/lib/messages/inject/inject.ts +215 -0
- package/lib/messages/inject/subagent-results.ts +82 -0
- package/lib/messages/inject/utils.ts +374 -0
- package/lib/messages/priority.ts +102 -0
- package/lib/messages/prune.ts +238 -0
- package/lib/messages/query.ts +56 -0
- package/lib/messages/reasoning-strip.ts +40 -0
- package/lib/messages/sync.ts +124 -0
- package/lib/messages/utils.ts +187 -0
- package/lib/prompts/compress-message.ts +42 -0
- package/lib/prompts/compress-range.ts +60 -0
- package/lib/prompts/context-limit-nudge.ts +18 -0
- package/lib/prompts/extensions/nudge.ts +43 -0
- package/lib/prompts/extensions/system.ts +32 -0
- package/lib/prompts/extensions/tool.ts +35 -0
- package/lib/prompts/index.ts +29 -0
- package/lib/prompts/iteration-nudge.ts +6 -0
- package/lib/prompts/store.ts +467 -0
- package/lib/prompts/system.ts +33 -0
- package/lib/prompts/turn-nudge.ts +10 -0
- package/lib/protected-patterns.ts +128 -0
- package/lib/state/index.ts +4 -0
- package/lib/state/persistence.ts +256 -0
- package/lib/state/state.ts +190 -0
- package/lib/state/tool-cache.ts +98 -0
- package/lib/state/types.ts +112 -0
- package/lib/state/utils.ts +334 -0
- package/lib/strategies/deduplication.ts +127 -0
- package/lib/strategies/index.ts +2 -0
- package/lib/strategies/purge-errors.ts +88 -0
- package/lib/subagents/subagent-results.ts +74 -0
- package/lib/token-utils.ts +162 -0
- package/lib/ui/notification.ts +346 -0
- package/lib/ui/utils.ts +287 -0
- package/package.json +9 -2
- package/tui/data/context.ts +177 -0
- package/tui/index.tsx +34 -0
- package/tui/routes/summary.tsx +175 -0
- package/tui/shared/names.ts +9 -0
- package/tui/shared/theme.ts +58 -0
- package/tui/shared/types.ts +38 -0
- package/tui/slots/sidebar-content.tsx +502 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const COMPRESS_RANGE = `Collapse a range in the conversation into a detailed summary.
|
|
2
|
+
|
|
3
|
+
THE SUMMARY
|
|
4
|
+
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.
|
|
5
|
+
|
|
6
|
+
USER INTENT FIDELITY
|
|
7
|
+
When the compressed range includes user messages, preserve the user's intent with extra care. Do not change scope, constraints, priorities, acceptance criteria, or requested outcomes.
|
|
8
|
+
Directly quote user messages when they are short enough to include safely. Direct quotes are preferred when they best preserve exact meaning.
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
COMPRESSED BLOCK PLACEHOLDERS
|
|
13
|
+
When the selected range includes previously compressed blocks, use this exact placeholder format when referencing one:
|
|
14
|
+
|
|
15
|
+
- \`(bN)\`
|
|
16
|
+
|
|
17
|
+
Compressed block sections in context are clearly marked with a header:
|
|
18
|
+
|
|
19
|
+
- \`[Compressed conversation section]\`
|
|
20
|
+
|
|
21
|
+
Compressed block IDs always use the \`bN\` form (never \`mNNNN\`) and are represented in the same XML metadata tag format.
|
|
22
|
+
|
|
23
|
+
Rules:
|
|
24
|
+
|
|
25
|
+
- Include every required block placeholder exactly once.
|
|
26
|
+
- Do not invent placeholders for blocks outside the selected range.
|
|
27
|
+
- Treat \`(bN)\` placeholders as RESERVED TOKENS. Do not emit \`(bN)\` text anywhere except intentional placeholders.
|
|
28
|
+
- If you need to mention a block in prose, use plain text like \`compressed bN\` (not as a placeholder).
|
|
29
|
+
- Preflight check before finalizing: the set of \`(bN)\` placeholders in your summary must exactly match the required set, with no duplicates.
|
|
30
|
+
|
|
31
|
+
These placeholders are semantic references. They will be replaced with the full stored compressed block content when the tool processes your output.
|
|
32
|
+
|
|
33
|
+
FLOW PRESERVATION WITH PLACEHOLDERS
|
|
34
|
+
When you use compressed block placeholders, write the surrounding summary text so it still reads correctly AFTER placeholder expansion.
|
|
35
|
+
|
|
36
|
+
- Treat each placeholder as a stand-in for a full conversation segment, not as a short label.
|
|
37
|
+
- Ensure transitions before and after each placeholder preserve chronology and causality.
|
|
38
|
+
- Do not write text that depends on the placeholder staying literal (for example, "as noted in \`(b2)\`").
|
|
39
|
+
- Your final meaning must be coherent once each placeholder is replaced with its full compressed block content.
|
|
40
|
+
|
|
41
|
+
BOUNDARY IDS
|
|
42
|
+
You specify boundaries by ID using the injected IDs visible in the conversation:
|
|
43
|
+
|
|
44
|
+
- \`mNNNN\` IDs identify raw messages
|
|
45
|
+
- \`bN\` IDs identify previously compressed blocks
|
|
46
|
+
|
|
47
|
+
Each message has an ID inside XML metadata tags like \`<dcp-message-id>...</dcp-message-id>\`.
|
|
48
|
+
The same ID tag appears in every tool output of the message it belongs to — each unique ID identifies one complete message.
|
|
49
|
+
Treat these tags as boundary metadata only, not as tool result content.
|
|
50
|
+
|
|
51
|
+
Rules:
|
|
52
|
+
|
|
53
|
+
- Pick \`startId\` and \`endId\` directly from injected IDs in context.
|
|
54
|
+
- IDs must exist in the current visible context.
|
|
55
|
+
- \`startId\` must appear before \`endId\`.
|
|
56
|
+
- Do not invent IDs. Use only IDs that are present in context.
|
|
57
|
+
|
|
58
|
+
BATCHING
|
|
59
|
+
When multiple independent ranges are ready and their boundaries do not overlap, include all of them as separate entries in the \`content\` array of a single tool call. Each entry should have its own \`startId\`, \`endId\`, and \`summary\`.
|
|
60
|
+
`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const CONTEXT_LIMIT_NUDGE = `<dcp-system-reminder>
|
|
2
|
+
CRITICAL WARNING: MAX CONTEXT LIMIT REACHED
|
|
3
|
+
|
|
4
|
+
You are at or beyond the configured max context threshold. This is an emergency context-recovery moment.
|
|
5
|
+
|
|
6
|
+
You MUST use the \`compress\` tool now. Do not continue normal exploration until compression is handled.
|
|
7
|
+
|
|
8
|
+
If you are in the middle of a critical atomic operation, finish that atomic step first, then compress immediately.
|
|
9
|
+
|
|
10
|
+
SELECTION PROCESS
|
|
11
|
+
Start from older, resolved history and capture as much stale context as safely possible in one pass.
|
|
12
|
+
Avoid the newest active working messages unless it is clearly closed.
|
|
13
|
+
|
|
14
|
+
SUMMARY REQUIREMENTS
|
|
15
|
+
Your summary MUST cover all essential details from the selected messages so work can continue.
|
|
16
|
+
If the compressed range includes user messages, preserve user intent exactly. Prefer direct quotes for short user messages to avoid semantic drift.
|
|
17
|
+
</dcp-system-reminder>
|
|
18
|
+
`
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SessionState } from "../../state"
|
|
2
|
+
|
|
3
|
+
export function buildCompressedBlockGuidance(state: SessionState): string {
|
|
4
|
+
const refs = Array.from(state.prune.messages.activeBlockIds)
|
|
5
|
+
.filter((id) => Number.isInteger(id) && id > 0)
|
|
6
|
+
.sort((a, b) => a - b)
|
|
7
|
+
.map((id) => `b${id}`)
|
|
8
|
+
const blockCount = refs.length
|
|
9
|
+
const blockList = blockCount > 0 ? refs.join(", ") : "none"
|
|
10
|
+
|
|
11
|
+
return [
|
|
12
|
+
"Compressed block context:",
|
|
13
|
+
`- Active compressed blocks in this session: ${blockCount} (${blockList})`,
|
|
14
|
+
"- If your selected compression range includes any listed block, include each required placeholder exactly once in the summary using `(bN)`.",
|
|
15
|
+
].join("\n")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function renderMessagePriorityGuidance(priorityLabel: string, refs: string[]): string {
|
|
19
|
+
const refList = refs.length > 0 ? refs.join(", ") : "none"
|
|
20
|
+
|
|
21
|
+
return [
|
|
22
|
+
"Message priority context:",
|
|
23
|
+
"- Higher-priority older messages consume more context and should be compressed right away if it is safe to do so.",
|
|
24
|
+
`- ${priorityLabel}-priority message IDs before this point: ${refList}`,
|
|
25
|
+
].join("\n")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function appendGuidanceToDcpTag(nudgeText: string, guidance: string): string {
|
|
29
|
+
if (!guidance.trim()) {
|
|
30
|
+
return nudgeText
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const closeTag = "</dcp-system-reminder>"
|
|
34
|
+
const closeTagIndex = nudgeText.lastIndexOf(closeTag)
|
|
35
|
+
|
|
36
|
+
if (closeTagIndex === -1) {
|
|
37
|
+
return nudgeText
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const beforeClose = nudgeText.slice(0, closeTagIndex).trimEnd()
|
|
41
|
+
const afterClose = nudgeText.slice(closeTagIndex)
|
|
42
|
+
return `${beforeClose}\n\n${guidance}\n${afterClose}`
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const MANUAL_MODE_SYSTEM_EXTENSION = `<dcp-system-reminder>
|
|
2
|
+
Manual mode is enabled. Do NOT use compress unless the user has explicitly triggered it through a manual marker.
|
|
3
|
+
|
|
4
|
+
Only use the compress tool after seeing \`<compress triggered manually>\` in the current user instruction context.
|
|
5
|
+
|
|
6
|
+
Issue exactly ONE compress tool per manual trigger. Do NOT launch multiple compress tools in parallel. Each trigger grants a single compression; after it completes, wait for the next trigger.
|
|
7
|
+
|
|
8
|
+
After completing a manually triggered context-management action, STOP IMMEDIATELY. Do NOT continue with any task execution. End your response right after the tool use completes and wait for the next user input.
|
|
9
|
+
</dcp-system-reminder>
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
export const SUBAGENT_SYSTEM_EXTENSION = `<dcp-system-reminder>
|
|
13
|
+
You are operating in a subagent environment.
|
|
14
|
+
|
|
15
|
+
The initial subagent instruction is imperative and must be followed exactly.
|
|
16
|
+
It is the only user message intentionally not assigned a message ID, and therefore is not eligible for compression.
|
|
17
|
+
All subsequent messages in the session will have IDs.
|
|
18
|
+
</dcp-system-reminder>
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
export function buildProtectedToolsExtension(protectedTools: string[]): string {
|
|
22
|
+
if (protectedTools.length === 0) {
|
|
23
|
+
return ""
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const toolList = protectedTools.map((t) => `\`${t}\``).join(", ")
|
|
27
|
+
return `<dcp-system-reminder>
|
|
28
|
+
The following tools are environment-managed: ${toolList}.
|
|
29
|
+
Their outputs are automatically preserved during compression.
|
|
30
|
+
Do not include their content in compress tool summaries — the environment retains it independently.
|
|
31
|
+
</dcp-system-reminder>`
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// These format schemas are kept separate from the editable compress prompts
|
|
2
|
+
// so they cannot be modified via custom prompt overrides. The schemas must
|
|
3
|
+
// match the tool's input validation and are not safe to change independently.
|
|
4
|
+
|
|
5
|
+
export const RANGE_FORMAT_EXTENSION = `
|
|
6
|
+
THE FORMAT OF COMPRESS
|
|
7
|
+
|
|
8
|
+
\`\`\`
|
|
9
|
+
{
|
|
10
|
+
topic: string, // Short label (3-5 words) - e.g., "Auth System Exploration"
|
|
11
|
+
content: [ // One or more ranges to compress
|
|
12
|
+
{
|
|
13
|
+
startId: string, // Boundary ID at range start: mNNNN or bN
|
|
14
|
+
endId: string, // Boundary ID at range end: mNNNN or bN
|
|
15
|
+
summary: string // Complete technical summary replacing all content in range
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
\`\`\``
|
|
20
|
+
|
|
21
|
+
export const MESSAGE_FORMAT_EXTENSION = `
|
|
22
|
+
THE FORMAT OF COMPRESS
|
|
23
|
+
|
|
24
|
+
\`\`\`
|
|
25
|
+
{
|
|
26
|
+
topic: string, // Short label (3-5 words) for the overall batch
|
|
27
|
+
content: [ // One or more messages to compress independently
|
|
28
|
+
{
|
|
29
|
+
messageId: string, // Raw message ID only: mNNNN (ignore metadata attributes like priority)
|
|
30
|
+
topic: string, // Short label (3-5 words) for this one message summary
|
|
31
|
+
summary: string // Complete technical summary replacing that one message
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
\`\`\``
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RuntimePrompts } from "./store"
|
|
2
|
+
export type { PromptStore, RuntimePrompts } from "./store"
|
|
3
|
+
|
|
4
|
+
export function renderSystemPrompt(
|
|
5
|
+
prompts: RuntimePrompts,
|
|
6
|
+
protectedToolsExtension?: string,
|
|
7
|
+
manual?: boolean,
|
|
8
|
+
subagent?: boolean,
|
|
9
|
+
): string {
|
|
10
|
+
const extensions: string[] = []
|
|
11
|
+
|
|
12
|
+
if (protectedToolsExtension) {
|
|
13
|
+
extensions.push(protectedToolsExtension.trim())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (manual) {
|
|
17
|
+
extensions.push(prompts.manualExtension.trim())
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (subagent) {
|
|
21
|
+
extensions.push(prompts.subagentExtension.trim())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [prompts.system.trim(), ...extensions]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join("\n\n")
|
|
27
|
+
.replace(/\n([ \t]*\n)+/g, "\n\n")
|
|
28
|
+
.trim()
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const ITERATION_NUDGE = `<dcp-system-reminder>
|
|
2
|
+
You've been iterating for a while after the last user message.
|
|
3
|
+
|
|
4
|
+
If there is a closed portion that is unlikely to be referenced immediately (for example, finished research before implementation), use the compress tool on it now.
|
|
5
|
+
</dcp-system-reminder>
|
|
6
|
+
`
|