feat(business): add schema-driven query templates
Expose a business schema catalog and explicit template runner for Kingdee sales-order facts. Update wiki-query guidance so the LLM routes operational questions through templates first and guarded SQL only when needed. Refresh user docs and ops aliases, and add coverage for schema metadata, template execution, and CLI JSON output. Validation: python3 -m unittest discover -v; python3 -m compileall obsidian_wiki tests scripts; git diff --check
This commit is contained in:
@@ -52,6 +52,30 @@ Also decide the **mode**:
|
||||
- **Index-only mode** — triggered by "quick answer", "just scan", "don't read the pages", "fast lookup". Stops at Step 3. Answers from frontmatter + `index.md` only.
|
||||
- **Normal mode** — the full tiered pipeline below.
|
||||
|
||||
### Step 1a: Business Facts Route (LLM-decided, before wiki retrieval)
|
||||
|
||||
If filtered mode is active, skip this step. The business fact database is operator-internal and should not be used for public/user-facing answers.
|
||||
|
||||
Before searching wiki pages, decide semantically whether the user is asking for exact operational sales-order facts instead of narrative knowledge. Treat it as a business facts query when the intent is about counts, sums, averages, rankings, trends, lists, or breakdowns of Kingdee sales orders, customers, products/materials, salespeople, organizations, departments, projects, warehouses, statuses, currencies, or delivery plans.
|
||||
|
||||
If it is a business facts query:
|
||||
|
||||
1. Load the machine-readable schema and template catalog:
|
||||
```bash
|
||||
obsidian-wiki business schema --json
|
||||
```
|
||||
2. Prefer a template whenever one fits. Convert the user's natural date range into either `--year/--month` or `--start-date` plus exclusive `--end-date`, then run:
|
||||
```bash
|
||||
obsidian-wiki business template <template_name> --vault "$OBSIDIAN_VAULT_PATH" <parameters> --json
|
||||
```
|
||||
Common parameters include `--customer`, `--product`, `--staff`, `--org`, `--department`, `--project`, `--warehouse`, `--billstatus`, `--orderstatus`, `--closestatus`, `--currency`, `--limit`, `--granularity day|month`, and `--staff-role-scope primary|all`. Salesperson questions default to `primary`; choose `all` only when the user asks to include secondary sales/follow-up roles.
|
||||
3. If no template fits, generate one guarded read-only SQL statement from the schema. Use only `SELECT` or `WITH ... SELECT`, only the documented business tables, never `raw_json` or `raw_snapshots`, and never write/DDL/PRAGMA. Then run:
|
||||
```bash
|
||||
obsidian-wiki business sql --vault "$OBSIDIAN_VAULT_PATH" "<SQL>" --json
|
||||
```
|
||||
4. If the template or guarded SQL returns an answer, answer from that JSON result as structured business facts. Do not cite wiki pages unless you also used wiki pages for business context. Mention stale sync warnings when `is_stale` is true.
|
||||
5. If the CLI/database is unavailable or the question is not a business facts query, continue with the normal wiki retrieval protocol below.
|
||||
|
||||
### Step 2: Index Pass (cheap)
|
||||
|
||||
Build a candidate set *without opening any page bodies*:
|
||||
|
||||
Reference in New Issue
Block a user