CodeNomad/packages/server/scripts
Pascal André 7a206a9297
feat(history): rank past-session search and expose it to agents as session_search (#1161)
## Summary

Agents can now find past discussions themselves. The bundled
session-pruning plugin registers a Code Mode tool,
`codenomad.session_search`, ranked by relevance over the calling
session's own project history. This is PR 1 of 2: server/plugin only;
the search window keeps its current behaviour until PR 2 wires the same
engine.

- **Tool scope:** the caller's directory tree, native workspace and
project (plus `global`) history, never other projects. The caller's
location is checked before and after the read, and excerpts are flagged
as untrusted transcript data. The tool follows backend presence like the
plugin's RPCs.
- **Ranking:** up to six Unicode terms; a precise SQL prefilter over
rowid chunks (superset of the JS judge: ASCII folding, Unicode case
classes, literal `\u` escape fallback) yields per-term IDF weights. The
best candidates are judged one bounded body at a time on word
boundaries, with an exact-phrase bonus, prose before tool payloads,
recency as tie-break and one hit per session before repeats. Optional
inclusive UTC `since`/`until`. Candidate, session, judge and time caps
are reported.
- **Shared limits:** scope SQL, readable-part extraction, the 16 MiB
message bound and 40 ms slices move to `history-content.ts` and are
shared with the literal search.
- **For PR 2:** a versioned `historyRanked` RPC returns the same hit
fields plus per-session provenance, so the broker can validate ownership
as for `history`. Existing RPC methods, HTTP routes and UI are
unchanged; the generic RPC proxy stays closed.

Inspired by `@rizal72/oc-session-search`.

## Validation

- Session-pruning tests 98/98, including the package regression; native
plugin bundle 1/1; server typecheck.
- Regressions: Unicode terms and accented case variants, weights, phrase
bonus, diversity, dates, prefilter precision (multi-line and accented
messages lacking a term are not candidates), a rare old match outranking
600+ newer frequent ones, scope isolation, cancellation, caps, skipped
rows, tool registration and presence disposal.
- Isolated native history fixture on OpenCode 2.2.0: 23 checks,
including a ranked query (3 hits across 2 sessions). No shared daemon or
user database was used.
2026-10-27 19:41:50 +01:00
..
build-automation-plugin.mjs fix(opencode): share host plugin runtime and require 2.0.27 (#920) 2026-10-12 16:42:07 +02:00
build-missions-plugin.mjs fix(opencode): share host plugin runtime and require 2.0.27 (#920) 2026-10-12 16:42:07 +02:00
build-remote-tunnel.mjs feat(remote-control): add Remote Control over OpenTunnel alongside direct access (#668) 2026-10-09 12:43:25 +02:00
build-session-pruning.mjs fix(opencode): share host plugin runtime and require 2.0.27 (#920) 2026-10-12 16:42:07 +02:00
copy-auth-pages.mjs feat(server): add authenticated remote access and desktop bootstrap 2026-01-14 18:18:14 +00:00
copy-ui-dist.mjs Rename CLI package to @neuralnomads/codenomad and bin codenomad 2025-11-20 23:51:44 +00:00
native-plugin-build.mjs fix(opencode): share host plugin runtime and require 2.0.27 (#920) 2026-10-12 16:42:07 +02:00
native-plugin-build.test.mjs feat(history): rank past-session search and expose it to agents as session_search (#1161) 2026-10-27 19:41:50 +01:00
remote-control-live.test.ts chore(remote-control): update OpenTunnel to 0.5.1 (#922) 2026-10-12 17:52:07 +02:00