picoclaw/pkg/providers
Zhaoyikaiii 1f7cbd9164
fix: cache system prompt with mtime-based auto-invalidation (#607)
Avoid rebuilding the entire system prompt on every BuildMessages() call
by caching the static portion (identity, bootstrap, skills summary,
memory) and only recomputing it when workspace source files change.

Key changes:

- ContextBuilder caches the static prompt behind an RWMutex with
  double-checked locking. Source file changes are detected via cheap
  os.Stat mtime checks so no explicit invalidation is needed.

- Track file existence at cache time (existedAtCache map) so that
  newly created or deleted bootstrap/memory files also trigger a
  rebuild — the old modifiedSince() silently returned false on
  os.IsNotExist.

- Walk the skills directory recursively with filepath.WalkDir to
  catch content-only edits at any nesting depth; directory mtime
  alone misses in-place file modifications on most filesystems.

- ToolRegistry.sortedToolNames() sorts tool names before iteration,
  ensuring deterministic tool definition order across calls — a
  prerequisite for LLM-side prefix/KV cache reuse.

- Merge all context (static + dynamic + summary) into a single
  system message for provider compatibility: the Anthropic adapter
  extracts messages[0] as the top-level system parameter, and Codex
  reads only the first system message as instructions.

- Fix a data race in BuildMessages() where cachedSystemPrompt was
  read without holding the lock in a debug log statement.

- Add tests: single system message invariant, mtime auto-invalidation,
  new-file creation detection, skill file content change, explicit
  InvalidateCache, cache stability, concurrent access (20 goroutines
  x 50 iterations, passes go test -race), and a benchmark.
2026-02-25 15:27:45 +08:00
..
anthropic fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
openai_compat fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
protocoltypes fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
antigravity_provider.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
antigravity_provider_test.go fix(antigravity): normalize tool calls to avoid empty function names 2026-02-17 20:05:35 +05:30
claude_cli_provider.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
claude_cli_provider_integration_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
claude_cli_provider_test.go Merge branch 'main' into fix-formatting 2026-02-20 20:02:53 +02:00
claude_provider.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
claude_provider_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
codex_cli_credentials.go feat(linter): Fix govet linter 2026-02-20 22:35:16 +02:00
codex_cli_credentials_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
codex_cli_provider.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
codex_cli_provider_integration_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
codex_cli_provider_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
codex_provider.go fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
codex_provider_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
cooldown.go style: fix gofmt formatting in cooldown files 2026-02-13 12:26:44 -03:00
cooldown_test.go style: fix gofmt formatting in cooldown files 2026-02-13 12:26:44 -03:00
error_classifier.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
error_classifier_test.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
factory.go Merge pull request #677 from yinwm/refactor/model-to-model-name 2026-02-24 19:05:40 +08:00
factory_provider.go feat: add native Mistral AI provider support 2026-02-22 11:40:21 +04:00
factory_provider_test.go chore: update Claude model references to claude-sonnet-4.6 2026-02-20 12:15:04 +08:00
factory_test.go chore: update Claude model references to claude-sonnet-4.6 2026-02-20 12:15:04 +08:00
fallback.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
fallback_test.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
github_copilot_provider.go fix: implement code review suggestions 2026-02-24 22:33:04 +08:00
http_provider.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
legacy_provider.go refactor(config): rename model field to model_name 2026-02-23 16:55:06 +08:00
model_ref.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
model_ref_test.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
tool_call_extract.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
toolcall_utils.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
types.go fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00