How sheily899/feishu-sales-dealtrace works
Purpose and Entry Points
DealTrace is a Python prototype for tracking customer issues across Feishu sales-group conversations. It normalizes messages, uses an LLM to propose structured changes, validates those changes against source evidence and prior state, then renders a local workbench. Primary runtime entry points are src/dealtrace/__main__.py and src/dealtrace/cli.py; the browser-only offline demo is published from docs/index.html.
Conversation Ingestion Boundary
Feishu integration receives group-message events, enforces configured group/role boundaries, and converts events into internal message representations. Local fixtures support offline/demo input. The external-system boundary is isolated in src/dealtrace/feishu.py, while core entities are defined in src/dealtrace/models.py; recorder/transcript import formats are handled under src/dealtrace/adapters/.
Analysis Pipeline and LLM Boundary
The processing pipeline takes normalized message batches plus the prior customer snapshot, invokes prompt-guided LLM analysis, and converts returned content into state operations. LLM output is advisory, not canonical: model access and request behavior belong in src/dealtrace/llm.py, orchestration in src/dealtrace/pipeline.py, and prompt contracts in prompts/system.md, prompts/outcome_inference.md, and prompts/rubric_scoring.md. Live analysis uses a DeepSeek API key; offline demo mode uses precomputed data and avoids model calls.
Canonical Customer-State Engine
State is the central integrity boundary. It parses proposed issue changes, links updates to historical issue_ids, retains unresolved issues, and rejects unsupported transitions while preserving the previous state. This logic is concentrated in src/dealtrace/customer_state.py, with evidence/ownership attribution support in src/dealtrace/attribution.py. The intended flow is: new normalized messages → proposed issue operations → historical linking and evidence validation → accepted snapshot/change set or recorded rejection.
Persistence and Workbench Delivery
Accepted analysis, message history, state versions, and rejection reasons are persisted in a single-machine SQLite store; the live default is data/workbench.sqlite3 (runtime-created). src/dealtrace/workbench_store.py owns storage concerns, and src/dealtrace/workbench.py exposes the local UI/workflow for chat inspection, triggering analysis, viewing issues, and navigating evidence. There is no stated authentication, multi-tenancy, or production-grade authorization boundary.
Configuration-Driven Sales Semantics
Schemas constrain interchange formats for transcripts, extracted reports, scorecards, CRM mappings, and inbox data. Key contracts are schemas/transcript.schema.json, schemas/coaching_report.schema.json, and schemas/rubric_report.schema.json. Domain behavior is parameterized through scorecards, sales frameworks, rubrics, CRM stage mappings, and outcome/call-type definitions: scorecards/, frameworks/, rubrics/, and config/crm/. CRM mapping/writing is a separate integration layer in src/dealtrace/crm/mapping.py and src/dealtrace/crm/writers.py.
Agent and Automation Distribution Layer
Alongside the executable DealTrace package, the repository distributes reusable sales/RevOps agent specifications across business domains. Each agent typically has a human-readable specification, structured descriptor, and implementation targets for Claude, LangGraph, n8n, Zapier, and Activepieces—for example agents/revenue-operations/deal-stage-clarity.md, agents/revenue-operations/deal-stage-clarity.json, and agents/revenue-operations/deal-stage-clarity.builds/langgraph.py. Claude-native commands and agent definitions under .claude/commands/ and .claude/agents/ are another invocation surface; they are distribution/orchestration assets rather than the core Feishu workbench runtime.
Main entry points: pipeline.py Analysis pipeline · customer_state.py Customer-state engine · workbench.py Local workbench · workbench_store.py SQLite workbench store
Components 19
DealTrace runtime
- CLI entry points · Starts live and local workflows.
src/dealtrace/cli.py - Feishu boundary · Filters group events and normalizes them.
src/dealtrace/feishu.py - Transcript adapters · Imports recorder and transcript formats.
- Core message models
src/dealtrace/models.py - Local workbench · Inspects chat, issues, and evidence; triggers analysis.
src/dealtrace/workbench.py - SQLite workbench store · Persists messages, snapshots, accepted changes, and rejections.
src/dealtrace/workbench_store.py - Offline browser demo · Uses precomputed data without model calls.
docs/index.html
Analysis and state
- Analysis pipeline · Turns normalized batches and prior snapshots into proposed operations.
src/dealtrace/pipeline.py - LLM client · DeepSeek request behavior; output is advisory.
src/dealtrace/llm.py - Prompt contracts
prompts/system.md - Customer-state engine · Links history, validates evidence, and preserves prior state on rejection.
src/dealtrace/customer_state.py - Evidence attribution · Supports evidence and ownership attribution.
src/dealtrace/attribution.py
Contracts and semantics
- Interchange schemas · Constrain transcript, coaching, and rubric reports.
schemas/transcript.schema.json - Sales semantics · Scorecards, frameworks, rubrics, and CRM stage mappings.
- CRM mapping · Maps canonical state to CRM fields.
src/dealtrace/crm/mapping.py - CRM writers · Writes mapped changes to CRM.
src/dealtrace/crm/writers.py
Automation distribution
- Sales agent specs · Reusable RevOps agent specifications and descriptors.
agents/revenue-operations/deal-stage-clarity.md - LangGraph build target
agents/revenue-operations/deal-stage-clarity.builds/langgraph.py - Claude commands and agents · Separate distribution and orchestration surface.
Connections 21
- CLI entry points → Feishu boundary: receives events
- CLI entry points → Local workbench: starts
- Feishu boundary → Core message models: normalizes
- Transcript adapters → Core message models: imports
- Core message models → Analysis pipeline: message batches
- Local workbench → Analysis pipeline: triggers analysis
- SQLite workbench store → Analysis pipeline: prior snapshot and history
- Analysis pipeline → LLM client: analysis request
- Prompt contracts → LLM client: guides
- LLM client → Analysis pipeline: advisory output
- Analysis pipeline → Customer-state engine: proposed operations
- Evidence attribution → Customer-state engine: evidence support
- Customer-state engine → SQLite workbench store: accepted snapshots or rejections
- SQLite workbench store → Local workbench: history and state
- Interchange schemas → Transcript adapters: validates formats
- Sales semantics → Analysis pipeline: scoring and outcomes
- Customer-state engine → CRM mapping: canonical changes
- CRM mapping → CRM writers: mapped updates
- Sales agent specs → LangGraph build target: implementation target
- Claude commands and agents → Sales agent specs: invokes distributed agents
- Offline browser demo → Local workbench: demo counterpart