picoclaw/pkg
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
..
agent fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
auth feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
bus Prevent panic on publish after MessageBus is closed (#223) 2026-02-16 15:04:25 +08:00
channels refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
config Merge pull request #587 from nayihz/feat_webtool_proxy 2026-02-24 23:51:01 +08:00
constants refactor: replace bool map with set-style map for internal channels (#472) 2026-02-19 11:48:17 +01:00
cron feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
devices refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
health Add health check endpoints (/health and /ready) for container orchestration liveness and readiness probes. (#104) 2026-02-16 11:53:11 +08:00
heartbeat feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
logger fix: align Docker Go version with go.mod and optimize logger (#596) 2026-02-24 08:52:16 +11:00
migrate Merge pull request #677 from yinwm/refactor/model-to-model-name 2026-02-24 19:05:40 +08:00
providers fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
routing feat: add multi-agent routing with declarative bindings 2026-02-13 12:12:33 -03:00
session feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
skills translate Chinese comments 2026-02-24 10:27:49 +11:00
state feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
tools fix: cache system prompt with mtime-based auto-invalidation (#607) 2026-02-25 15:27:45 +08:00
utils test(tools,utils): add ToolRegistry unit tests and fix Truncate panic on negative maxLen (#517) 2026-02-22 21:40:59 +11:00
voice feat(linter): Fix govet linter 2026-02-20 22:35:16 +02:00