←
SIYUAN-23
Created: 2026-02-02
•
Updated: 2026-02-03
Relationships
Loading...
Attachments
Loading...
Comments (2)
agent
·
2026-02-03
## Implementation Complete
Implemented backlink and reference commands using the undocumented SiYuan APIs.
### Changes Made
**Client Methods (siyuan.py:889-958)**
- `get_backlink(block_id, before_len, keyword, mention_keyword, mention_before_len)` - Calls `/api/ref/getBacklink`
- `get_backlink2(block_id, sort, mention_sort, keyword, mention_keyword)` - Calls `/api/ref/getBacklink2`
- `get_ref_ids(block_id)` - Calls `/api/block/getRefIDs`
**Handler Functions (siyuan.py:2315-2442)**
- `handle_ref_backlinks()` - Text output shows backlinks/mentions with document context
- `handle_ref_backlinks2()` - Tabular text output with ID/Type/Content/HPath
- `handle_ref_ids()` - Lists reference IDs and definition IDs
**CLI Commands (siyuan.py:3744-3860)**
- `siyuan ref backlinks BLOCK_ID` - Options: `--keyword`, `--mention-keyword`, `--format`
- `siyuan ref backlinks2 BLOCK_ID` - Options: `--sort`, `--mention-sort`, `--keyword`, `--mention-keyword`, `--format`
- `siyuan ref ids BLOCK_ID` - Options: `--format`
### Test Results
- 31 new unit tests in `tests/test_ref.py` - All passing
- Integration tests in `tests/integration/test_ref_live.py` - Requires live SiYuan
- Full test suite (437 tests) - All passing
### Verification
```bash
$ siyuan --token test ref --help
Commands:
backlinks Get blocks that link TO this block.
backlinks2 Enhanced backlink view with more context and sorting.
ids Get all reference IDs from a block.
```
triage-agent
·
2026-02-03
## Feature Triage Complete
**Status:** NOT IMPLEMENTED
**Summary:** This feature requests three new commands for exploring backlinks and reference relationships using undocumented SiYuan APIs:
- `siyuan ref backlinks` - Uses `/api/ref/getBacklink`
- `siyuan ref backlinks2` - Uses `/api/ref/getBacklink2` (with sorting)
- `siyuan ref ids` - Uses `/api/block/getRefIDs`
**Note:** An existing `siyuan search ref` command uses a different API (`/api/search/searchRefBlock`) that searches for blocks containing references rather than retrieving backlinks.
**Implementation Location:**
- Client methods: ~line 460-500 in siyuan.py
- Handler functions: ~line 2200-2300 in siyuan.py
- New `ref` CLI group: ~line 3530 in siyuan.py
- New test files: `tests/test_ref.py` and `tests/integration/test_ref_live.py`
**Complexity:** Low-Medium (follows existing patterns, ~500 lines total across all files)
See attached triage report for full details including API documentation from SiYuan source code.