Commit Graph

32 Commits

Author SHA1 Message Date
914190e119 feat: add LLM token counting meta plugin and token filters
Add tiktoken-based token counting via new 'tokens' feature flag.

New components:
- Shared tokenizer module wrapping tiktoken CoreBPE (cl100k_base, o200k_base)
- TokensMetaPlugin: streaming token counter, tokenizes each chunk independently
- head_tokens(N): stream first N tokens, split at exact boundary when mid-chunk
- skip_tokens(N): skip first N tokens, stream the rest
- tail_tokens(N): bounded ring buffer (~16KB), outputs last N tokens at finalize

All filters are fully streaming — no full-stream buffering.
Meta plugin accuracy: exact for normal text, ±1-2 tokens if long whitespace
sequence spans a chunk boundary.

Also: add 'client' and 'tokens' to default features, add curl to Dockerfile builder stage.
2026-03-13 16:48:31 -03:00
e672ec751e feat: add JWT auth, configurable username, switch password auth to Basic
Add server-side JWT authentication with permission-based access control
(read/write/delete claims). Password authentication now uses HTTP Basic
auth only (replacing Bearer). Add configurable username for both server
and client (--server-username/--client-username, defaults to "keep").

JWT secret supports file-based loading via --server-jwt-secret-file for
Docker secrets. OPTIONS preflight requests bypass auth. HEAD mapped to
read permission.

Co-Authored-By: opencode <noreply@opencode.ai>
2026-03-13 13:56:35 -03:00
b166477202 fix: harden security, eliminate panics, remove dead code, add Dockerfile
Security:
- Use constant-time password comparison (subtle crate) to prevent timing attacks
- Replace permissive CORS with configurable origin-restricted CORS
- Add TLS warning when password auth is used without HTTPS

Bug fixes:
- Convert MetaPlugin panics to anyhow::Result (get_meta_plugin, outputs_mut, options_mut)
- Replace item.id.unwrap() with proper error handling across 15 call sites
- Fix panic on unknown column type in list mode
- Fix conflicting PIPESIZE constant (was 8192 vs 65536, now unified to 8192)
- Add 256MB filter chain buffer limit to prevent OOM
- Gracefully skip unregistered plugins instead of panicking

Dead code removal:
- Delete unused filter parser files (filter_parser.rs, filter.pest, parser/ module)
- ~260 lines of dead PEG parser code removed

Code consolidation:
- Add is_content_binary_from_metadata() helper (was duplicated in 4 places)
- Simplify save_item_raw() to delegate to save_item_raw_streaming() (~90 lines removed)

Incomplete features:
- Populate filter_plugins in status output from global registry
- Add FallbackMagicFileMetaPlugin (was referenced but never implemented)
- Document init_plugins() as intentional no-op

Infrastructure:
- Add Dockerfile (static musl binary on scratch, 4.8MB)
- Add .dockerignore
- Add cors_origin to ServerConfig and config.rs
2026-03-13 07:57:36 -03:00
bee980605f feat: add HTTPS/TLS server support via rustls
Add optional TLS support for the server using axum-server with the
tls-rustls feature. When --server-cert and --server-key are provided
(and tls feature is enabled), the server binds with TLS instead of
plain HTTP.

Changes:
- Add axum-server dependency with optional tls-rustls feature
- New 'tls' feature flag (independent of 'server')
- --server-cert/--server-key CLI args gated behind tls feature
- ServerConfig extended with cert_file/key_file fields
- Conditional TLS/HTTP binding in server mod.rs
- Fix PathBuf::to_str().unwrap() panic risk -> to_string_lossy()
- Update README.md and DESIGN.md with TLS documentation
2026-03-12 22:18:42 -03:00
c5529bedbf feat: add client mode with streaming support
Add client mode enabling the keep CLI to connect to a remote keep
server over HTTP. Local plugins (compression, meta, filters) run on
the client; the server stores/retrieves binary blobs.

Architecture:
- Client save uses 3-thread streaming pipeline: reader thread (stdin
  → tee/stdout → hash → compress), OS pipe, streamer thread (pipe →
  chunked HTTP POST). Memory usage is O(PIPESIZE) regardless of data
  size.
- Server accepts compress=false, meta=false, decompress=false query
  params for granular control of server-side processing.
- Streaming body handling on server via async channel → sync reader
  bridge (ChannelReader).

Key additions:
- src/client.rs: KeepClient with post_stream() for chunked upload
- src/modes/client/: save, get, list, info, delete, diff, status
- --client-url / KEEP_CLIENT_URL configuration
- --client-password / KEEP_CLIENT_PASSWORD for auth
- os_pipe dependency for zero-copy pipe streaming

Co-Authored-By: andrew/openrouter/hunter-alpha <noreply@opencode.ai>
2026-03-12 18:01:36 -03:00
8a8a6e1c4b fix: correct critical bugs and improve pipe streaming performance
Critical bug fixes:
- save_item now returns real Item from database, not a hardcoded fake
- AsyncDataService::save() reuses self.sync_service instead of creating redundant instance
- GenerateStatus trait signature mismatch fixed (CLI/API decoupling)

Performance improvements (pipe path untouched):
- CompressionEngine::open() returns Box<dyn Read + Send> enabling true streaming
- mode_get eliminates triple full-file read (was sampling then re-reading entire file)
- FilteringReader adds fast-path bypass when no filters, pre-allocates temp buffer
- text.rs meta plugin processes &[u8] slice directly, eliminates data.to_vec() clone

API correctness:
- Tag parse errors now return 400 instead of being silently discarded
- compute_diff uses similar crate (LCS-based) instead of naive positional comparison

Cleanup:
- Modernize string formatting (format!({x})) across codebase
- Remove redundant DB query in get mode
- Derive Debug/ToSchema on public types
- Delete placeholder test files with no real assertions
- Extract parse_comma_tags utility function
2026-03-11 20:45:05 -03:00
Andrew Phillips
a8871a9575 docs: update build and formatting instructions in AGENT.md 2025-09-15 17:25:58 -03:00
Andrew Phillips
eaf47d7fed feat: Add TableStyle::Nothing to allow disabling table borders 2025-09-08 19:16:35 -03:00
Andrew Phillips
196fdbbda8 feat: add ringbuf and crossbeam-utils dependencies 2025-08-29 13:35:55 -03:00
Andrew Phillips
52dc8cea32 feat: update dependencies and remove binary and command meta plugins 2025-08-28 13:11:19 -03:00
Andrew Phillips
96cb67259d build: remove to_snake_case_string and to_snake_case_trait dependencies 2025-08-27 18:35:18 -03:00
Andrew Phillips
091634433b feat: add to_snake_case_string and to_snake_case_trait dependencies 2025-08-27 12:15:48 -03:00
Andrew Phillips
5d518711d5 feat: add md5 support and remove deprecated meta plugin 2025-08-27 10:37:07 -03:00
Andrew Phillips
f23cc6e94f feat: add termsize and tokio-util dependencies and remove system.rs 2025-08-26 20:16:08 -03:00
Andrew Phillips
321e00171e feat: move core services to services directory 2025-08-25 18:22:17 -03:00
Andrew Phillips
05b2c1b9bd feat: update metadata field names to use mime_type and mime_encoding 2025-08-18 09:44:27 -03:00
Andrew Phillips
014dd380cd feat: add new dependencies to Cargo.lock 2025-08-16 12:30:37 -03:00
Andrew Phillips
28b7199424 chore: remove deprecated tests.rs file 2025-08-16 11:57:10 -03:00
Andrew Phillips
24d7c4742c chore: update dependencies and remove unused test modules 2025-08-14 12:23:46 -03:00
Andrew Phillips
5150e2f478 chore: update dependencies and remove unused server modules 2025-08-12 14:38:59 -03:00
Andrew Phillips
47349802d8 chore: update dependencies and remove unused basic meta plugin 2025-07-29 14:17:06 -03:00
Andrew Phillips
2a38f9c357 chore: update dependencies 2025-05-12 19:00:41 -03:00
Andrew Phillips
d9072d22d5 refactor: improve test structure and reliability 2025-05-12 13:07:33 -03:00
Andrew Phillips
7725e41883 Finished implementing --diff 2025-05-06 14:53:22 -03:00
Andrew Phillips
6e4199867c Updated deps 2024-02-28 19:21:14 +00:00
Andrew Phillips
359129f5f8 Update versions 2023-09-20 19:05:46 +00:00
Andrew Phillips
26e22d113e Rename keep-rust to keep 2023-09-18 14:29:07 +00:00
Andrew Phillips
2119f7e226 Update deps 2023-09-06 13:40:05 +00:00
Andrew Phillips
d9d47e97a9 Add flate2 2023-09-01 21:01:22 +00:00
Andrew Phillips
53382246ac Remove unused deps 2023-09-01 15:36:21 +00:00
Andrew Phillips
49a77f9090 Most of basic functionality implemented 2023-08-31 19:38:59 +00:00
Andrew Phillips
b9bf5a831e Initial commit 2023-07-25 17:33:50 -03:00