Skip to content

Commit 192e7c3

Browse files
leaning into uid and muid
1 parent 305e7de commit 192e7c3

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

lib/prompts/compress.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ Before compressing, ask: _"Is this range closed enough to become summary-only?"_
3838
BOUNDARY MATCHING
3939
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.
4040

41+
SELECTION ORDER (STRICT):
42+
43+
1. Use `muid` / `uid` anchors first (most reliable, preferred default)
44+
2. Only if those are unavailable, use long distinctive verbatim substrings
45+
46+
Do NOT use short generic status/progress phrases as boundaries (`task_id`, `Done — I ...`, short patch headers, etc.) because they commonly appear multiple times and will fail with ambiguity.
47+
4148
WHERE TO PICK STRINGS FROM (important for reliable matching):
49+
4250
- `muid` and `uid` strings in message and tool output annotations (MOST RELIABLE - guaranteed unique)
4351
- Your own assistant text responses (MOST RELIABLE - always stored verbatim)
4452
- The user's own words in their messages

lib/prompts/nudge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Avoid unnecessary context build-up with targeted uses of the `compress` tool. St
2020

2121
If you are performing a critical atomic operation, do not interrupt it, but make sure to perform context management rapidly
2222

23-
Be mindful of the startString and endString you use for compression and prefer using `muid` and `uid` strings for reliable boundary matching. Ensure your summaries are inclusive of all parts of the range.
23+
Be mindful of the startString and endString you use for compression. Use `muid` and `uid` strings AS THE DEFAULT boundary anchors whenever available (do NOT rely on generic prose snippets that can repeat). Ensure your summaries are inclusive of all parts of the range.
2424
</instruction>

lib/prompts/system.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ MACRO: for completed phases, distilling entire chapters of conversation
1414
A strategic and regular use of the `compress` tool is encouraged to maintain a focused context. Be proactive and deliberate in managing your context.
1515

1616
BOUNDARY MATCHING
17-
`compress` uses inclusive string boundaries, matching a string at the start of a message or tool output will consume the entire item. User messages are annotated with `muid`, tool outputs with `uid`, and are intended for you to use as startString and endString anchors to avoid any potential mismatch errors. You can also use unique text from your own reasoning or text outputs, but be sure to provide more than enough surrounding context to ensure a unique match. The preferred way to match is still to use `muid` and `uid` strings.
17+
`compress` uses inclusive string boundaries, matching a string at the start of a message or tool output will consume the entire item. User messages are annotated with `muid`, tool outputs with `uid`.
18+
19+
DEFAULT RULE (HIGH PRIORITY): Use `muid` / `uid` anchors for BOTH `startString` and `endString` whenever they exist. Treat these IDs as the canonical boundary keys.
20+
21+
AVOID generic prose boundaries that can repeat (for example: `task_id: ...`, `Done — I ...`, short status lines, common code headers). Repeated strings will cause ambiguity failures.
22+
23+
Fallback only if `muid`/`uid` cannot be used: choose a long, highly distinctive verbatim substring that appears exactly once.
1824

1925
THE SUMMARY STANDARD
2026
Your summary MUST be technical and specific enough to preserve FULL understanding of what transpired, such that NO ambiguity remains about what asked, found, planned, done, or decided - yet noise free

lib/tools/compress.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ export function createCompressTool(ctx: ToolContext): ReturnType<typeof tool> {
2424
.object({
2525
startString: tool.schema
2626
.string()
27-
.describe("Unique text from conversation marking the beginning of range"),
27+
.describe(
28+
"Unique text marking range start. Prefer exact `[muid_x]` or `[uid_x]` anchors over prose.",
29+
),
2830
endString: tool.schema
2931
.string()
30-
.describe("Unique text marking the end of range"),
32+
.describe(
33+
"Unique text marking range end. Prefer exact `[muid_x]` or `[uid_x]` anchors over prose.",
34+
),
3135
summary: tool.schema
3236
.string()
3337
.describe("Complete technical summary replacing all content in range"),

lib/tools/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,19 @@ export function findStringInMessages(
176176
}
177177

178178
if (exactMatches.length > 1) {
179+
const candidates = exactMatches
180+
.slice(0, 5)
181+
.map((m) => `${m.messageId}@${m.messageIndex}`)
182+
.join(", ")
179183
clog.error(C.BOUNDARY, `${stringType}: MULTIPLE exact matches - ambiguous`, {
180184
count: exactMatches.length,
181185
matches: exactMatches.map((m) => ({ msgId: m.messageId, idx: m.messageIndex })),
182186
searchString: searchString.substring(0, 150),
183187
})
184188
throw new Error(
185189
`Found multiple matches for ${stringType}. ` +
186-
`Provide more surrounding context to uniquely identify the intended match.`,
190+
`Use a [muid_x] or [uid_x] anchor when possible, or provide more unique surrounding context. ` +
191+
`Candidates: ${candidates}${exactMatches.length > 5 ? ", ..." : ""}`,
187192
)
188193
}
189194

@@ -260,7 +265,7 @@ export function findStringInMessages(
260265
})
261266
throw new Error(
262267
`Found multiple matches for ${stringType}. ` +
263-
`Provide more unique surrounding context to disambiguate.`,
268+
`Use a [muid_x] or [uid_x] anchor when possible, or provide more unique surrounding context to disambiguate.`,
264269
)
265270
}
266271

0 commit comments

Comments
 (0)