(autoMemDir: string)
| 373 | * Build the "Searching past context" section if the feature gate is enabled. |
| 374 | */ |
| 375 | export function buildSearchingPastContextSection(autoMemDir: string): string[] { |
| 376 | if (!getFeatureValue_CACHED_MAY_BE_STALE('tengu_coral_fern', false)) { |
| 377 | return [] |
| 378 | } |
| 379 | const projectDir = getProjectDir(getOriginalCwd()) |
| 380 | // Ant-native builds alias grep to embedded ugrep and remove the dedicated |
| 381 | // Grep tool, so give the model a real shell invocation there. |
| 382 | // In REPL mode, both Grep and Bash are hidden from direct use — the model |
| 383 | // calls them from inside REPL scripts, so the grep shell form is what it |
| 384 | // will write in the script anyway. |
| 385 | const embedded = hasEmbeddedSearchTools() || isReplModeEnabled() |
| 386 | const memSearch = embedded |
| 387 | ? `grep -rn "<search term>" ${autoMemDir} --include="*.md"` |
| 388 | : `${GREP_TOOL_NAME} with pattern="<search term>" path="${autoMemDir}" glob="*.md"` |
| 389 | const transcriptSearch = embedded |
| 390 | ? `grep -rn "<search term>" ${projectDir}/ --include="*.jsonl"` |
| 391 | : `${GREP_TOOL_NAME} with pattern="<search term>" path="${projectDir}/" glob="*.jsonl"` |
| 392 | return [ |
| 393 | '## Searching past context', |
| 394 | '', |
| 395 | 'When looking for past context:', |
| 396 | '1. Search topic files in your memory directory:', |
| 397 | '```', |
| 398 | memSearch, |
| 399 | '```', |
| 400 | '2. Session transcript logs (last resort — large files, slow):', |
| 401 | '```', |
| 402 | transcriptSearch, |
| 403 | '```', |
| 404 | 'Use narrow search terms (error messages, file paths, function names) rather than broad keywords.', |
| 405 | '', |
| 406 | ] |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Load the unified memory prompt for inclusion in the system prompt. |
no test coverage detected