Commit Graph
53 Commits
Author SHA1 Message Date
digua 6c07610778 fix(ai): align cross-chat relative time ranges 2026-08-24 00:25:35 +08:00
digua a6557608c6 fix(ai): harden shared interaction analysis
Keep shared-interaction evidence, pagination, and token truncation accurate while bounding anchor inputs, proximity scans, contact discovery, and reply aggregation. Resolve participants across all imported history and isolate damaged database candidates without changing the final analysis tree.
2026-08-23 16:19:57 +08:00
digua d79e4733dd feat(ai): inspect shared contact interactions 2026-08-23 16:19:57 +08:00
digua 10e0825578 fix(ai): harden contact session inspection
Use the all-history contact snapshot and validate raw session candidates inside the cancellable scan loop. Bound model-visible structural results to the configured token budget while preserving full tool details and continuation metadata.
2026-08-22 20:29:40 +08:00
digua f26c6f6eba feat(ai): inspect contact activity across sessions 2026-08-22 20:29:40 +08:00
digua fbcc0f299f fix(ai): budget cross-chat entity results
Keep full entity resolution details available to the application while bounding the model-visible payload with the runtime tokenizer. Preserve coverage and truncation metadata, prioritize usable scopes fairly, and cap ambiguity hints to avoid duplicate unbounded source lists.
2026-08-22 17:09:23 +08:00
digua dc3bd82c90 fix(ai): enforce cross-chat execution budgets
Count complete tool payloads with the runtime tokenizer so Chinese evidence respects the configured model context budget.\n\nResolve contact sources incrementally with cancellation checks and targeted member lookups to keep long cross-chat investigations responsive.
2026-08-22 17:09:23 +08:00
digua d1a6c711fe feat(ai): add isolated cross-chat agent 2026-08-22 17:09:23 +08:00
digua 2e624f6beb feat(ai): stream tool execution progress 2026-08-18 17:27:48 +08:00
digua cf1aee9e5b refactor(ai): upgrade pi runtime and define execution semantics 2026-08-18 17:27:48 +08:00
digua 883fa0896d docs(search): record FTS removal benchmarks 2026-08-03 17:28:19 +08:00
digua 256e93605a refactor(database): remove legacy session FTS 2026-08-03 17:28:19 +08:00
digua 4777ca9f63 fix(web-ai): harden Web WASM AI chat
Stabilize browser model setup, tool execution, retries, cancellation, and error reporting.
2026-07-27 00:09:33 +08:00
digua 7dcf5d9070 feat(web): add Web WASM AI chat 2026-07-27 00:09:33 +08:00
digua 5a5fae880a refactor: remove redundant re-export proxies 2026-07-16 20:09:18 +08:00
digua 16ee4d8348 refactor(ai): unify desktop tool adapters 2026-07-13 20:42:27 +08:00
digua 801e7fc66a fix(cli): harden agent query safeguards
Tighten agent-facing query validation, privacy guards, SQL result handling, config writes, and LIKE search semantics for the CLI query workflow.
2026-07-04 15:12:50 +08:00
digua fd97c55681 feat(query): extend shared chat query capabilities 2026-07-04 15:12:50 +08:00
digua 434334b203 feat(semantic-index): run local embeddings in lazy worker 2026-06-23 14:18:32 +08:00
diguaandClaude Sonnet 4.6 7df673f62f test: add openTestSqliteDatabase helper to fix native binding mismatch
Centralise the better-sqlite3 native-binding selection for tests in
tests/helpers/sqlite.mts so test files consistently use the CLI-side
binding (apps/cli/native/better_sqlite3.node) rather than the default
one, which may be compiled for a different Node.js ABI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 14:18:32 +08:00
diguaandClaude Sonnet 4.6 39393cf38d refactor: remove dead code and simplify over-engineered abstractions
- Delete NotificationBus interface (no implementations, no callers)
- Delete useAsyncData/useMultipleAsyncData composables (zero import sites)
- Inline CHART_CAPABILITY_SKILL_ID into tool-catalog.ts (was a single-constant file)
- Inline AsyncSqlExecutor into message-query-functions.ts (was a single-interface file)
- Rename tools TimeFilter → ToolTimeRange to eliminate name collision with shared-types
- Shrink useToast wrapper: two interfaces → one type, 40 lines → 17 lines
- Simplify deepMerge: remove recursion, config is at most 1 level deep

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 14:18:32 +08:00
digua abd05981c6 fix(ai): semantic index core reliability and evidence text
Prevent stale semantic index writes by checking write guard before
persisting chunks; make rebuild detection explicit on app restart via
reactivate() path; preserve full evidence snippet text without truncation;
add regression test for same-second chunk tie-breaking in mapMessageToChunk.
2026-06-21 16:18:39 +08:00
diguaandClaude Sonnet 4.6 69ac64791e fix(ai): fix evidence tool classification and semantic search time filter
retrieve-chat-evidence:
- repair semantic cleanup and keyword time filter; pass context timeFilter
  (seconds→ms) when no explicit date params are provided
- classifyGroup: skip Chinese keyword matching for non-Chinese locales and
  update the English LLM instruction to allow judgment on uncertain groups,
  so English-language chats are not permanently stuck at "cannot confirm"
- mergeCandidates: replace ID-range overlap check with timestamp overlap
  so keyword hits are not incorrectly dropped after incremental imports
  backfill older messages with non-monotonic IDs

semantic-search-current-chat:
- forward context.timeFilter (seconds→ms) to searchForTool so the tool
  respects session time range the same way other retrieval tools do

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 16:18:39 +08:00
digua 2ec99e5880 feat(ai): streamline agent tool results 2026-06-21 16:18:39 +08:00
digua 5d20429af7 fix(tools): support multi-keyword message search 2026-06-21 16:18:39 +08:00
diguaandCursor d58168a029 fix(ai): correct evidence snippet time unit and strip per-message times
Evidence messages carry millisecond timestamps but the preprocessing pipeline
renders times assuming seconds (multiplies by 1000), producing absurd years
(e.g. 56150) inside semantic snippets. Convert ms back to seconds before
rendering. Also strip the per-line time prefix from semantic snippets so the
evidence block shows a single group time instead of a time on every message,
and drop the redundant time span in the group header. Adds regression tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
diguaandCursor 402b78b683 feat(ai): render evidence content block with click-through tracing
Add a structured "evidence" content block produced by retrieve_chat_evidence:
extract the payload from tool results, persist it in AI chat history, and
render grouped, desensitized sources in EvidenceBlock.vue. Sources open the
chat record drawer at the matched message for traceability. Evidence payload
types move to @openchatlab/core so tools, node-runtime and the frontend share
one definition. Includes zh-CN/en-US/ja-JP/zh-TW i18n.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
diguaandCursor b248e48787 feat(ai): route evidence questions to retrieve_chat_evidence via planner
Add an "evidence" planner intent and tiered retrieval guidance so
fact/occurrence/count questions are routed to retrieve_chat_evidence
instead of a single low-level search path.

- planner: new evidence intent + prompt strategy suggesting only
  retrieve_chat_evidence for that step
- semantic-search guidance: three-tier tool selection (evidence > semantic > keyword)
- expose retrieve_chat_evidence as an always-on Agent tool (desktop special
  append; CLI via AGENT_TOOL_REGISTRY core), semantic tool stays dynamic
- export evidence tool + payload types from @openchatlab/tools
- TDD: planner evidence-intent test

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
diguaandCursor 27a5bbf9bf feat(ai): apply millisecond time-range filter to semantic retrieval
Thread an optional timeFilter through SemanticSearchToolOptions →
searchForTool → search → hybridSearch so evidence retrieval no longer
mixes time ranges between semantic and keyword paths.

- hybridSearch filters dense + FTS-mapped chunks by startTs/endTs overlap
  (millisecond, single-sided supported) and amplifies the candidate pool
  when filtering to avoid under-recall
- retrieve_chat_evidence now passes its parsed ms range to the semantic path
- TDD: hybrid-search overlap unit tests + service wiring test

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
diguaandCursor 6886eb3dc6 feat(ai): add retrieve_chat_evidence tool with evidence payload protocol
Introduce a high-level evidence retrieval tool for fact/occurrence/count
questions. It resolves auto mode, runs semantic + keyword paths, de-identifies
keyword snippets via an injected desensitizeMessages callback, applies a
tool-layer millisecond time-range fallback (keyword path can't rely on the CLI
provider's timeFilter), and merges/dedupes candidates into conservative groups.

- Add ChatEvidencePayload / group / source types and EvidenceTimeRangeMs to tools
- Register tool in AGENT_TOOL_REGISTRY only (Agent-only, excluded from MCP)
- Inject desensitizeMessages (preprocessMessages) in desktop + CLI adapters
- TDD: tool + registry unit tests

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
diguaandCursor b9599da1c8 feat(semantic-index): expose semantic search via routes, agent tool and pipeline
Add shared /_web/ai/semantic-index HTTP routes and wire the service into
CLI web and Electron internal API. Introduce the semantic_search_current_chat
agent tool (AGENT-only, not MCP) with desensitized output and a narrowed
service interface, forward the semantic-search context through the CLI and
Desktop tool adapters, and integrate on-demand semantic search into the
agent pipeline with guidance and a max-result-token evidence budget.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 16:18:39 +08:00
LeoandLeo 28fedbd815 fix(ai): recover from analysis tool timeouts (#229)
Co-authored-by: Leo <jxy0811@users.noreply.github.com>
2026-06-16 11:30:02 +08:00
digua 56693685fa fix(ai): stabilize chart rendering during streaming 2026-06-12 11:36:46 +08:00
diguaandClaude Sonnet 4.6 56ad4a9578 feat(ai): prefer high-level tools over raw SQL when rendering charts
Add optional `rows` parameter to render_chart so AI can pass pre-fetched
data arrays (e.g. from get_time_stats, member_stats) directly instead of
rewriting SQL from scratch. Update chart capability prompts and all locale
files to guide AI to check high-level tools first before falling back to SQL.
Remove debug console.debug log from agent-core thinkingLevel resolution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-10 00:15:25 +08:00
digua 9ad012680d feat(ai): integrate chart planning support 2026-06-10 00:15:25 +08:00
digua 6b29c07326 test(routes,tools): cover high-risk analysis paths 2026-06-08 10:14:42 +08:00
digua c2295e317f refactor: align ai chat and segment identifiers 2026-06-07 20:27:27 +08:00
CEQ151 15470444e5 feat(ai): improve chart runtime UX 2026-06-05 11:12:42 +08:00
CEQ151 782f67ba63 feat(ai): add slash-activated chart runtime with EChart init fix
- Add ChartSpec validation and chart data normalization (bar/line/pie/heatmap)
- Add render_chart analysis tool with SQL safety (readonly check, outer LIMIT wrapper, CTE write rejection)
- Add chart content block type and ChartBlockRenderer for inline chart rendering
- Add slash menu chart capability activation (single-use per message)
- Add chart payload transport through Electron and CLI Web tool adapters
- Add error block handling for render-only chart tool failures
- Add chart payload persistence through content_blocks JSON storage
- Fix EChart.vue init timing: defer initChart() to nextTick so container
  layout completes before ECharts reads width (was rendering 92px canvases)
- Add comprehensive test coverage: core, integration, agent flow, frontend, smoke
- Add i18n for render_chart and get_schema in 4 locales
- Add project handoff documentation
2026-06-05 11:12:42 +08:00
diguaandCursor 0ba9ae04a6 chore: migrate workspace packages to ESM
- Add "type": "module" to all workspace package.json files
- Replace __dirname with import.meta.url-based resolveCliPath() helper
- Convert stream-json/stream-chain CJS named imports to default + destructure
  for ESM compatibility
- Use createRequire() for @node-rs/jieba native module loading in ESM context

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 23:19:47 +08:00
digua 3a2d4e753a refactor(mcp): trim exposed tool registry 2026-05-21 22:38:10 +08:00
diguaandCursor 68652248fe feat(mcp): enrich toolset to 33 tools with token compression and dual format
- Expand MCP_TOOL_REGISTRY from 8 to 33 tools by including all
  AGENT_TOOL_REGISTRY tools (analytics, deep search, conversation, etc.)
- Add format=text|json parameter to all MCP tools (default: text for
  most, json for SQL tools) for token-efficient LLM consumption
- Create format.ts: message filtering, consecutive-sender merging,
  content truncation, and compact text output
- Inspired by community chatlab-mcp-server project

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-22 10:20:39 +08:00
digua 56a7939356 feat: implement all CoreDataProvider methods for Server Agent
Extract 10 query functions from Electron worker to @openchatlab/core:

- message-queries: getMessageContext, getSearchMessageContext,
  getConversationBetween, getMemberNameHistory, getMembersWithAliases,
  executeParameterizedSql
- session-queries: getChatOverview, searchSessions, getSessionMessages,
  getSessionSummaries
- filters: hasTable, hasColumn utilities

CoreDataProvider now delegates to core functions instead of throwing
NotImplementedError. All 27 Server Agent tools are functional.

Also inject segmentText (batchSegmentWithFrequency) into server
ToolExecutionContext so keyword_frequency tool works properly.
2026-05-15 22:23:27 +08:00
digua 74ea5563cb refactor: split tool registry into MCP and Agent, align agent tools with Electron
- Rename TOOL_REGISTRY to MCP_TOOL_REGISTRY (MCP Server only)
- Create AGENT_TOOL_REGISTRY with full Electron-aligned tool set (27 tools)
- MCP-only tools (list_sessions, get_session_info, search_keyword) excluded
  from agent registry
- Update ai.ts to use AGENT_TOOL_REGISTRY, mcp.ts to use MCP_TOOL_REGISTRY
- Add truncation strategies for newly registered agent tools

Note: Most newly registered agent tools require CoreDataProvider method
implementations (currently NotImplementedError). See follow-up task doc.
2026-05-15 22:03:40 +08:00
digua c789df5495 refactor: unify AI tool naming across Electron, CLI Web, and MCP
Remove chatlab_ prefix from all tool definitions in @openchatlab/tools,
aligning with Electron-style names (get_*, search_*, etc.). The chatlab_
prefix is now only added at the MCP registration layer via MCP_TOOL_PREFIX
constant, keeping MCP namespace isolation without polluting internal names.

This ensures the AI agent uses identical tool names in both Electron and
CLI Web environments, fixing skill system compatibility and tool catalog
consistency.
2026-05-15 21:39:30 +08:00
digua 9d55676892 refactor(tools): complete migration of all Electron tools to shared definitions
Move all 24 Electron-native tool definitions to @openchatlab/tools:
- 13 data query tools (chat-overview, search-messages, deep-search,
  get-recent-messages, get-message-context, search-sessions,
  get-session-messages, get-members, get-member-name-history,
  get-conversation-between, get-session-summaries,
  response-time-analysis, keyword-frequency)
- 11 SQL template tools (message_type_breakdown, etc.)

Electron definitions/ now contains only index.ts with adaptSharedTool()
calls. All tool logic lives in the shared package.

Key changes:
- Expand ToolDataProvider with 12 new methods for full data access
- Add ToolExecutionContext fields: searchContextBefore/After,
  maxMessagesLimit, segmentText callback, translateTemplate callback
- Create shared utils: format.ts (i18n), time-params.ts, schemas.ts
- Create SQL tool system: definitions, executor, types
- WorkerDataProvider implements all new methods via workerManager
- CoreDataProvider stubs new methods (Server doesn't use these yet)
- Delete 16 Electron tool files (-1280 lines, +482 lines)
2026-05-15 19:34:35 +08:00
digua f35676cb23 refactor(electron): replace member_stats and time_stats with shared tool definitions
Create shared-tool-adapter to convert @openchatlab/tools ToolDefinition → AgentTool.
Delete Electron-specific get-member-stats.ts and get-time-stats.ts,
replaced by shared definitions via adaptSharedTool().
Make ToolExecutionContext.db optional to support Electron (no DatabaseAdapter).
2026-05-15 19:11:59 +08:00
digua 619b59270b refactor(tools): migrate 6 tool handlers to use ToolDataProvider
Replace direct @openchatlab/core function calls with dataProvider abstraction:
- member-stats, time-stats, search, recent-messages, sql, schema
- Handlers are now async, using context.dataProvider for data access
- Server consumers inject CoreDataProvider alongside db for backward compat
2026-05-15 19:07:21 +08:00
digua b1df81b064 feat(tools): implement CoreDataProvider and WorkerDataProvider
Add ToolDataProvider implementations for both platforms:
- CoreDataProvider: wraps @openchatlab/core sync queries for Server/MCP
- WorkerDataProvider: wraps workerManager async IPC for Electron
2026-05-15 19:05:00 +08:00
digua 21a0ce36f4 refactor(tools): add ToolDataProvider interface and async handler support
Prepare @openchatlab/tools for unified tool layer:
- ToolDefinition.handler now supports async (ToolResult | Promise<ToolResult>)
- Add ToolDataProvider abstraction interface for platform-agnostic data access
- Add TimeFilter, ToolCategory, TruncationStrategy types
- Update Server consumers (tool-adapter, mcp) to await handler results
2026-05-15 19:02:49 +08:00