chain-insights 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/bin/cli.js +10 -0
  4. package/bin/install.cjs +252 -0
  5. package/bin/mcp-proxy.cjs +10 -0
  6. package/dist/active-BSrxLKwn.mjs +50 -0
  7. package/dist/active-BSrxLKwn.mjs.map +1 -0
  8. package/dist/active-Dv7Tu-O4.cjs +68 -0
  9. package/dist/app-BjjuQM0B.mjs +155 -0
  10. package/dist/app-BjjuQM0B.mjs.map +1 -0
  11. package/dist/app-Dq1TdB6p.cjs +161 -0
  12. package/dist/artifact-server-DoxJ7fCx.cjs +47 -0
  13. package/dist/artifact-server-Dxz5YbuQ.mjs +48 -0
  14. package/dist/artifact-server-Dxz5YbuQ.mjs.map +1 -0
  15. package/dist/assets/bg-pattern.png +0 -0
  16. package/dist/assets/logo.png +0 -0
  17. package/dist/call-args-DQA2QcRA.cjs +27 -0
  18. package/dist/call-args-Lk_wOJxd.mjs +29 -0
  19. package/dist/call-args-Lk_wOJxd.mjs.map +1 -0
  20. package/dist/capabilities-CB97WMA5.cjs +83 -0
  21. package/dist/capabilities-DliMBim-.mjs +84 -0
  22. package/dist/capabilities-DliMBim-.mjs.map +1 -0
  23. package/dist/cases-By7INiOa.mjs +6 -0
  24. package/dist/cases-CDcNU91B.cjs +9 -0
  25. package/dist/chunk-CZWwpsFl.cjs +43 -0
  26. package/dist/cli.cjs +752 -0
  27. package/dist/cli.d.cts +1 -0
  28. package/dist/cli.d.mts +1 -0
  29. package/dist/cli.mjs +753 -0
  30. package/dist/cli.mjs.map +1 -0
  31. package/dist/client-D4Bq0rp9.mjs +111 -0
  32. package/dist/client-D4Bq0rp9.mjs.map +1 -0
  33. package/dist/client-D4fZgIaO.cjs +132 -0
  34. package/dist/config-Bmdl5hdk.cjs +67 -0
  35. package/dist/config-BwrBYmiC.mjs +44 -0
  36. package/dist/config-BwrBYmiC.mjs.map +1 -0
  37. package/dist/data-extractor-BNGj7ECT.cjs +347 -0
  38. package/dist/data-extractor-DFzsa5CS.mjs +336 -0
  39. package/dist/data-extractor-DFzsa5CS.mjs.map +1 -0
  40. package/dist/dossier-BsroDgD3.mjs +76 -0
  41. package/dist/dossier-BsroDgD3.mjs.map +1 -0
  42. package/dist/dossier-DtxREpPm.cjs +76 -0
  43. package/dist/evidence-BGcdKxuV.cjs +200 -0
  44. package/dist/evidence-BhvFW-y_.mjs +195 -0
  45. package/dist/evidence-BhvFW-y_.mjs.map +1 -0
  46. package/dist/format-Ce1RObVl.mjs +22 -0
  47. package/dist/format-Ce1RObVl.mjs.map +1 -0
  48. package/dist/format-DOrPvXEr.cjs +20 -0
  49. package/dist/frontmatter-D8wWCeOa.mjs +26 -0
  50. package/dist/frontmatter-D8wWCeOa.mjs.map +1 -0
  51. package/dist/frontmatter-DgAuai7E.cjs +35 -0
  52. package/dist/graph-normalizer-Cv9yK9Pg.mjs +130 -0
  53. package/dist/graph-normalizer-Cv9yK9Pg.mjs.map +1 -0
  54. package/dist/graph-normalizer-DeIj6Ses.cjs +133 -0
  55. package/dist/graph-reports-C4TBjCkM.mjs +63 -0
  56. package/dist/graph-reports-C4TBjCkM.mjs.map +1 -0
  57. package/dist/graph-reports-DU05YCei.cjs +64 -0
  58. package/dist/html-generator-CAv81IWH.cjs +85 -0
  59. package/dist/html-generator-V6Bp0uRb.mjs +68 -0
  60. package/dist/html-generator-V6Bp0uRb.mjs.map +1 -0
  61. package/dist/index.cjs +31 -0
  62. package/dist/index.d.cts +187 -0
  63. package/dist/index.d.cts.map +1 -0
  64. package/dist/index.d.mts +187 -0
  65. package/dist/index.d.mts.map +1 -0
  66. package/dist/index.mjs +9 -0
  67. package/dist/init-BjuFt54X.cjs +232 -0
  68. package/dist/init-CaOsHTIo.mjs +232 -0
  69. package/dist/init-CaOsHTIo.mjs.map +1 -0
  70. package/dist/mcp-proxy.cjs +1257 -0
  71. package/dist/mcp-proxy.d.cts +12 -0
  72. package/dist/mcp-proxy.d.cts.map +1 -0
  73. package/dist/mcp-proxy.d.mts +12 -0
  74. package/dist/mcp-proxy.d.mts.map +1 -0
  75. package/dist/mcp-proxy.mjs +1255 -0
  76. package/dist/mcp-proxy.mjs.map +1 -0
  77. package/dist/output-root-CFYms3ad.cjs +43 -0
  78. package/dist/output-root-CmWM7aV2.mjs +33 -0
  79. package/dist/output-root-CmWM7aV2.mjs.map +1 -0
  80. package/dist/parser-BUIWW1OH.cjs +182 -0
  81. package/dist/parser-DO0_SssG.mjs +182 -0
  82. package/dist/parser-DO0_SssG.mjs.map +1 -0
  83. package/dist/public-tools-D4UI-Zb0.mjs +2554 -0
  84. package/dist/public-tools-D4UI-Zb0.mjs.map +1 -0
  85. package/dist/public-tools-XSpkz2ky.cjs +2556 -0
  86. package/dist/resolver-C2ZS7oC8.mjs +201 -0
  87. package/dist/resolver-C2ZS7oC8.mjs.map +1 -0
  88. package/dist/resolver-zYbu4wDV.cjs +203 -0
  89. package/dist/rolldown-runtime-wcPFST8Q.mjs +13 -0
  90. package/dist/runner-1Eq55OYb.cjs +148 -0
  91. package/dist/runner-BhUHbiHG.mjs +149 -0
  92. package/dist/runner-BhUHbiHG.mjs.map +1 -0
  93. package/dist/schema-4XpzDFQM.cjs +55 -0
  94. package/dist/schema-8d0rVIdZ.mjs +37 -0
  95. package/dist/schema-8d0rVIdZ.mjs.map +1 -0
  96. package/dist/schema-cache-9CksD7tX.mjs +34 -0
  97. package/dist/schema-cache-9CksD7tX.mjs.map +1 -0
  98. package/dist/schema-cache-CgWRCN2N.cjs +36 -0
  99. package/dist/selector-CkFcTXzz.cjs +10 -0
  100. package/dist/selector-xjm6NTHI.mjs +12 -0
  101. package/dist/selector-xjm6NTHI.mjs.map +1 -0
  102. package/dist/server-BkM5xrXb.mjs +45 -0
  103. package/dist/server-BkM5xrXb.mjs.map +1 -0
  104. package/dist/server-DXowbpfi.cjs +54 -0
  105. package/dist/session-BpNylyuJ.cjs +115 -0
  106. package/dist/session-CcTgYxsj.mjs +115 -0
  107. package/dist/session-CcTgYxsj.mjs.map +1 -0
  108. package/dist/setup-DOpKPrlx.cjs +81 -0
  109. package/dist/setup-DyrWHuwQ.mjs +80 -0
  110. package/dist/setup-DyrWHuwQ.mjs.map +1 -0
  111. package/dist/store-BiUhQOIf.cjs +230 -0
  112. package/dist/store-BoWE-Gtl.mjs +225 -0
  113. package/dist/store-BoWE-Gtl.mjs.map +1 -0
  114. package/dist/templates/graph.html +1406 -0
  115. package/dist/tool-visibility-3Z_KvO9Q.mjs +28 -0
  116. package/dist/tool-visibility-3Z_KvO9Q.mjs.map +1 -0
  117. package/dist/tool-visibility-CwgY205r.cjs +36 -0
  118. package/dist/tools-Cp2jAAAb.mjs +100 -0
  119. package/dist/tools-Cp2jAAAb.mjs.map +1 -0
  120. package/dist/tools-f_vJUZAF.cjs +139 -0
  121. package/dist/topup-server-BZuQifvh.cjs +940 -0
  122. package/dist/topup-server-DUjyFftI.mjs +919 -0
  123. package/dist/topup-server-DUjyFftI.mjs.map +1 -0
  124. package/dist/version-1gP19Lhi.mjs +8 -0
  125. package/dist/version-1gP19Lhi.mjs.map +1 -0
  126. package/dist/version-BNGtdpmH.cjs +18 -0
  127. package/dist/viz-BlCJe6Tk.mjs +35 -0
  128. package/dist/viz-BlCJe6Tk.mjs.map +1 -0
  129. package/dist/viz-ClezVXrJ.cjs +44 -0
  130. package/dist/wallet-BMelXBYP.mjs +104 -0
  131. package/dist/wallet-BMelXBYP.mjs.map +1 -0
  132. package/dist/wallet-RnvvSpV2.cjs +146 -0
  133. package/docs/architecture.md +145 -0
  134. package/docs/contributing.md +68 -0
  135. package/docs/debugging.md +68 -0
  136. package/docs/development.md +44 -0
  137. package/docs/graph-tools.md +251 -0
  138. package/docs/images/graph-mcp-iframe.png +0 -0
  139. package/docs/images/graph-visualization.png +0 -0
  140. package/docs/images/topup-page.png +0 -0
  141. package/docs/investigation-workspaces.md +151 -0
  142. package/docs/mcp-proxy.md +180 -0
  143. package/package.json +59 -0
  144. package/skills/chain-insights-developer-experience/SKILL.md +101 -0
  145. package/skills/chain-insights-investigation/SKILL.md +285 -0
  146. package/skills/chain-insights-investigation/agents/openai.yaml +4 -0
  147. package/skills/chain-insights-investigation/scripts/run-target-uat.sh +197 -0
  148. package/skills/chain-insights-trace-funds/SKILL.md +249 -0
  149. package/skills/ci-case/SKILL.md +43 -0
  150. package/skills/ci-status/SKILL.md +45 -0
  151. package/skills/test-chain-insights-graphrag-mcp/SKILL.md +75 -0
  152. package/skills/test-chain-insights-graphrag-mcp/agents/openai.yaml +4 -0
  153. package/skills/test-chain-insights-graphrag-mcp/scripts/run-uat.sh +414 -0
@@ -0,0 +1,145 @@
1
+ # Architecture
2
+
3
+ Chain Insights is a local investigation framework around a remote graph
4
+ execution endpoint. It keeps sensitive workspace outputs as normal local files
5
+ and leaves graph computation to the configured GraphRAG MCP backend.
6
+
7
+ ## Product Layers
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ Agent[Agent or CLI user] --> Proxy[Chain Insights MCP proxy]
12
+ Agent --> CLI[Chain Insights CLI]
13
+ CLI --> Config[Local config]
14
+ CLI --> Wallet[Encrypted wallet]
15
+ CLI --> Workspace[Investigation workspace]
16
+ Proxy --> GraphMCP[GraphRAG MCP]
17
+ CLI --> GraphMCP
18
+ GraphMCP --> Memgraph[(Memgraph)]
19
+ GraphMCP --> StarRocks[(StarRocks)]
20
+ Wallet --> Base[Base RPC]
21
+ Workspace --> Browser[Local browser reports]
22
+ ```
23
+
24
+ The CLI is the operator entry point. The MCP proxy exposes the same local
25
+ framework to AI agents. The GraphRAG MCP endpoint executes graph-language reads
26
+ against live topology, archive topology, and facts.
27
+
28
+ ## Module Responsibilities
29
+
30
+ | Module area | Responsibility |
31
+ | --- | --- |
32
+ | CLI | Command routing and user-facing workflows |
33
+ | Config | Local config schema and owner-only storage |
34
+ | Wallet | Encrypted EVM wallet and Base USDC balance checks |
35
+ | MCP client/proxy | x402, debug-token, test-key auth, schema cache, stdio proxy |
36
+ | Cases | Case state, evidence, dossiers, sessions |
37
+ | Playbooks | Legacy playbook runner and migration boundary |
38
+ | Visualization | Graph data model and self-contained HTML generation |
39
+ | Server | Local report and visualization server |
40
+ | Workspace init | Investigation workspace scaffold and runtime schema notes |
41
+
42
+ ## Data Flow
43
+
44
+ 1. The user or agent works inside an initialized investigation workspace.
45
+ 2. Chain Insights reads local config for endpoint and auth mode.
46
+ 3. Graph queries go to the configured GraphRAG MCP endpoint.
47
+ 4. The graph backend executes against `live_topology`, `archive_topology`, or
48
+ `facts`.
49
+ 5. Chain Insights stores compact evidence, graph JSON, HTML reports, CSVs, and
50
+ summaries in the active workspace.
51
+ 6. Case evidence references report files instead of embedding large payloads.
52
+
53
+ ## Config
54
+
55
+ Configuration is stored in `~/.chain-insights/config.json` with owner-only
56
+ permissions.
57
+
58
+ Primary GraphRAG MCP config:
59
+
60
+ ```bash
61
+ chain-insights config get graphMcpEndpoint
62
+ chain-insights config set graphMcpEndpoint https://staging-mcp.chain-insights.ai/mcp
63
+ ```
64
+
65
+ Supported config keys:
66
+
67
+ | Key | Purpose |
68
+ | --- | --- |
69
+ | `graphMcpEndpoint` | GraphRAG MCP endpoint used by CLI and proxy |
70
+ | `graphMcpAuthToken` | GraphRAG MCP bearer credential for test access keys or local debug UAT |
71
+ | `mcpEndpoint` | Legacy endpoint fallback |
72
+ | `mcpAuthToken` | Legacy debug token fallback |
73
+ | `walletAddress` | Optional wallet metadata |
74
+ | `serverPort` | Local visualization and graph report server port |
75
+ | `dataDir` | Local Chain Insights data directory |
76
+ | `version` | Config schema version |
77
+
78
+ Wallet private keys are intercepted before config write and stored encrypted in
79
+ `~/.chain-insights/wallet.json`.
80
+
81
+ ## Local Data
82
+
83
+ Default local data directory:
84
+
85
+ ```text
86
+ ~/.chain-insights/
87
+ config.json
88
+ wallet.json
89
+ mcp-schema-*.json
90
+ chain-insights.duckdb
91
+ ```
92
+
93
+ Investigation outputs belong in initialized workspaces, not in the global data
94
+ directory.
95
+
96
+ Workspace outputs include:
97
+
98
+ ```text
99
+ cases/
100
+ imports/
101
+ reports/
102
+ reports/graphs/
103
+ reports/tables/
104
+ templates/
105
+ .chain-insights/schema/
106
+ .chain-insights/runtime/
107
+ .chain-insights/runtime-skill/
108
+ ```
109
+
110
+ ## Security Model
111
+
112
+ - `wallet.json`, `config.json`, and schema cache files use owner-only
113
+ permissions.
114
+ - Wallet private keys are encrypted with AES-256-GCM.
115
+ - Debug bearer tokens are redacted in CLI output.
116
+ - Test access keys are payment bypass credentials.
117
+ - Production x402 should use a hot wallet with limited funds.
118
+ - Graph report JSON is stored in the active workspace and served from
119
+ `127.0.0.1`.
120
+ - Chain Insights does not custody user funds.
121
+ - CI runs typecheck, tests, build, npm package packing, vulnerability audit,
122
+ registry signature verification, secret-pattern scanning, CodeQL, OpenSSF
123
+ Scorecard, and Dependabot updates.
124
+
125
+ ## Test Access Keys
126
+
127
+ Invited testers can use server-side test keys without x402 payment:
128
+
129
+ ```bash
130
+ chain-insights access-key set ci_test_REDACTED --endpoint https://staging-mcp.chain-insights.ai/mcp
131
+ chain-insights access-key status
132
+ chain-insights mcp call graph_query network=bittensor query='USE live_topology MATCH (n) RETURN n LIMIT 1'
133
+ ```
134
+
135
+ Operators configure the server with `MCP_TEST_ACCESS_KEY_HASHES`, a
136
+ comma-separated list of `key_id:sha256(full_key)` entries:
137
+
138
+ ```bash
139
+ export TEST_KEY="ci_test_$(openssl rand -hex 24)"
140
+ printf '%s' "$TEST_KEY" | sha256sum
141
+ export MCP_TEST_ACCESS_KEY_HASHES="partner-a:<sha256-from-command>"
142
+ ```
143
+
144
+ Share the raw `ci_test_...` key once. Store only its SHA-256 hash in deployment
145
+ config. Revoke by removing the entry and redeploying GraphRAG MCP.
@@ -0,0 +1,68 @@
1
+ # Contributing To Chain Insights
2
+
3
+ Chain Insights is an AML investigation framework layered on top of GraphRAG
4
+ MCP. Contributions should keep the product easy to try while preserving precise
5
+ tool contracts for agents and analysts.
6
+
7
+ ## Local Setup
8
+
9
+ ```bash
10
+ npm install
11
+ npm run build
12
+ node bin/cli.js --help
13
+ ```
14
+
15
+ ## Adding AML Tools
16
+
17
+ Current AML tools live in the Chain Insights layer:
18
+
19
+ - `address_risk`
20
+ - `track_funds`
21
+ - `scam_topology`
22
+
23
+ When adding a tool, document:
24
+
25
+ - User problem.
26
+ - Required and optional inputs.
27
+ - GraphRAG MCP primitive calls.
28
+ - Use of `live_topology`, `archive_topology`, and `facts`.
29
+ - Result contract.
30
+ - Case evidence behavior.
31
+ - Graph report behavior.
32
+ - Tests and dogfood path.
33
+
34
+ ## Documentation Updates
35
+
36
+ - README stays product-first.
37
+ - Detailed graph contracts belong in `docs/graph-tools.md`.
38
+ - Workspace behavior belongs in `docs/investigation-workspaces.md`.
39
+ - MCP proxy/client setup belongs in `docs/mcp-proxy.md`.
40
+ - Debug and UAT details belong in `docs/debugging.md`.
41
+ - Agent-facing contributor guidance belongs in shipped skills under `skills/`.
42
+
43
+ ## Tests
44
+
45
+ Run focused tests while developing:
46
+
47
+ ```bash
48
+ npm test -- tests/skills-contract.test.ts
49
+ npm test -- tests/cli.test.ts
50
+ ```
51
+
52
+ Run the full local gate before a PR:
53
+
54
+ ```bash
55
+ npm run typecheck
56
+ npm test
57
+ npm run build
58
+ npm run release:check
59
+ git diff --check
60
+ ```
61
+
62
+ ## Release Discipline
63
+
64
+ Every PR to `main` must:
65
+
66
+ - Bump `package.json` and `package-lock.json`.
67
+ - Add a matching `CHANGELOG.md` entry.
68
+ - Pass the GitHub verification checks.
@@ -0,0 +1,68 @@
1
+ # Debugging Chain Insights
2
+
3
+ This document covers local GraphRAG MCP debugging, auth bypasses, Inspector
4
+ checks, and UAT. Product quick starts belong in README; debugging details live
5
+ here.
6
+
7
+ ## Local GraphRAG MCP Debug
8
+
9
+ Start GraphRAG MCP with debug bypass from the RBMK ML repo:
10
+
11
+ ```bash
12
+ cd /home/aphex5/work/rbmk/repos/ml
13
+ test -f .env || cp .env.example .env
14
+ set -a
15
+ . ./.env
16
+ set +a
17
+ docker compose -f compose/shared.yml build graphrag-mcp-go
18
+ MCP_DEBUG_BYPASS_ENABLED=true \
19
+ MCP_DEBUG_BYPASS_TOKEN=chain-insights-dev-debug \
20
+ docker compose -f compose/shared.yml up -d graphrag-mcp-go
21
+ ```
22
+
23
+ Point Chain Insights at the local endpoint:
24
+
25
+ ```bash
26
+ cd /home/aphex5/work/chain-insights
27
+ node bin/cli.js debug on --token chain-insights-dev-debug --endpoint http://localhost:8012/mcp
28
+ node bin/cli.js mcp tools --refresh
29
+ ```
30
+
31
+ ## Inspector
32
+
33
+ Inspect the GraphRAG MCP endpoint directly:
34
+
35
+ ```bash
36
+ npx @modelcontextprotocol/inspector \
37
+ --cli http://localhost:8012/mcp \
38
+ --transport http \
39
+ --method tools/list \
40
+ --header "X-MCP-Debug-Token: chain-insights-dev-debug"
41
+ ```
42
+
43
+ Inspect the Chain Insights proxy:
44
+
45
+ ```bash
46
+ npx @modelcontextprotocol/inspector \
47
+ --cli chain-insights-mcp-proxy \
48
+ --method tools/list
49
+ ```
50
+
51
+ ## Smoke Checks
52
+
53
+ ```bash
54
+ node bin/cli.js mcp call graph_query_batch \
55
+ network=bittensor \
56
+ 'queries=[{"id":"count","query":"USE live_topology MATCH (n) RETURN count(n) AS count LIMIT 1"}]'
57
+ node bin/cli.js wallet address
58
+ node bin/cli.js wallet balance
59
+ ```
60
+
61
+ ## UAT Script
62
+
63
+ ```bash
64
+ skills/test-chain-insights-graphrag-mcp/scripts/run-uat.sh
65
+ ```
66
+
67
+ The UAT script uses a temporary initialized workspace, calls the real GraphRAG
68
+ MCP endpoint, verifies proxy tools, and checks graph report serving.
@@ -0,0 +1,44 @@
1
+ # Development
2
+
3
+ This document is for engineers changing Chain Insights.
4
+
5
+ ## Install And Build
6
+
7
+ ```bash
8
+ npm install
9
+ npm run build
10
+ node bin/cli.js --help
11
+ ```
12
+
13
+ ## Tests
14
+
15
+ Run the full local gate:
16
+
17
+ ```bash
18
+ npm run typecheck
19
+ npm test
20
+ npm run build
21
+ npm run release:check
22
+ git diff --check
23
+ ```
24
+
25
+ Focused docs and workspace tests:
26
+
27
+ ```bash
28
+ npm test -- tests/skills-contract.test.ts tests/cli.test.ts
29
+ ```
30
+
31
+ ## Global Install From Checkout
32
+
33
+ ```bash
34
+ npm run build
35
+ npm install -g .
36
+ cia --version
37
+ ```
38
+
39
+ ## More Developer Docs
40
+
41
+ - Contributor workflow: `docs/contributing.md`
42
+ - Debugging and UAT: `docs/debugging.md`
43
+ - Graph tool contracts: `docs/graph-tools.md`
44
+ - Investigation workspace layout: `docs/investigation-workspaces.md`
@@ -0,0 +1,251 @@
1
+ # Chain Insights Graph Tools
2
+
3
+ This document covers the graph-facing tools and the result contracts that
4
+ agents should rely on during investigations.
5
+
6
+ ## Graph MCP Surface
7
+
8
+ The GraphRAG MCP public graph surface is intentionally small:
9
+
10
+ | Tool | Purpose |
11
+ | --- | --- |
12
+ | `graph_query` | Run one read-only GQL/Cypher query through the universal graph endpoint |
13
+ | `graph_query_batch` | Run related read-only graph-language queries as one MCP call |
14
+
15
+ Chain Insights AML tools such as `address_risk`, `track_funds`, and
16
+ `scam_topology` are recipes built over `graph_query_batch`. They are not
17
+ assumed to exist on the GraphRAG MCP endpoint.
18
+
19
+ ## Query Rules
20
+
21
+ - `network` is required. Do not guess it in agent workflows.
22
+ - GQL/Cypher must be read-only.
23
+ - Use `USE live_topology` for Memgraph RAM topology.
24
+ - Use `USE archive_topology` for StarRocks historical topology.
25
+ - Use `USE facts` for StarRocks facts.
26
+ - Use `graph_query_batch` for related reads that should share one paid call.
27
+ - `per_query_timeout_seconds` is optional and capped at `600`.
28
+ - Returned rows live in `structuredContent.facts`.
29
+
30
+ Example single query:
31
+
32
+ ```bash
33
+ chain-insights mcp call graph_query \
34
+ network=bittensor \
35
+ "query=USE live_topology MATCH (n) WHERE n.address IS NOT NULL RETURN n.labels AS labels, n.address AS address LIMIT 10"
36
+ ```
37
+
38
+ Example batch query:
39
+
40
+ ```bash
41
+ chain-insights mcp call graph_query_batch \
42
+ network=bittensor \
43
+ 'queries=[{"id":"count","query":"USE live_topology MATCH (n) RETURN count(n) AS count LIMIT 1"},{"id":"archive_flows","query":"USE archive_topology MATCH (src:Address)-[f:FLOWS_TO]->(dst:Address) RETURN f.period_granularity AS granularity, src.address AS source, dst.address AS target LIMIT 3"}]'
44
+ ```
45
+
46
+ Batch result facts include:
47
+
48
+ ```json
49
+ {
50
+ "batch": {
51
+ "count": 2,
52
+ "completed": 2,
53
+ "failed": 0,
54
+ "per_query_timeout_seconds": 600,
55
+ "total_query_elapsed_ms": 1345,
56
+ "billable_seconds": 2,
57
+ "estimated_usdc": "0.02"
58
+ }
59
+ }
60
+ ```
61
+
62
+ ## Address Risk
63
+
64
+ `address_risk` screens one address for AML risk, behavior patterns,
65
+ neighborhood context, and exchange exposure. Use it as the first tool for a
66
+ single-address investigation.
67
+
68
+ Required input:
69
+
70
+ - `network`
71
+ - `address`
72
+
73
+ Optional input:
74
+
75
+ - `compare_address`
76
+ - `include_attachments`
77
+
78
+ The tool can emit graph report metadata when attachments are requested. Store
79
+ large graph payloads under workspace reports and save compact evidence pointers
80
+ to cases.
81
+
82
+ ## Track Funds
83
+
84
+ `track_funds` traces funds from trusted victim/source addresses through
85
+ intermediaries to exchange deposit candidates.
86
+
87
+ Required input:
88
+
89
+ - `network`
90
+ - `trusted_addresses`
91
+
92
+ Optional input:
93
+
94
+ - `untrusted_addresses`
95
+ - `max_hops`
96
+ - `min_amount_sum`
97
+ - `per_address_limit`
98
+ - `case_id`
99
+ - `include_attachments`
100
+
101
+ Victim/source addresses are case roles, not risky labels. The tool returns
102
+ investigator-ready flow summaries and, when a case is provided, stores compact
103
+ evidence pointers in the active workspace.
104
+
105
+ CLI example:
106
+
107
+ ```bash
108
+ cia mcp track-funds \
109
+ --network bittensor \
110
+ --trusted-addresses 5... \
111
+ --case 1
112
+ ```
113
+
114
+ ## Scam Topology
115
+
116
+ `scam_topology` expands the topology around a known victim incident so the
117
+ result can produce reviewable scam-label inputs for ML and analyst workflows.
118
+
119
+ Contract summary: victim-only traversal is outward from victim/source funds;
120
+ the primary graph is a node-relative novelty wave with non-expanding
121
+ convergence edges; exchange terminal safety; `scam_labels` are ML-ready flags;
122
+ label candidates are reviewable, not automatic writes.
123
+
124
+ Required input:
125
+
126
+ - `network`
127
+ - `victim_address`
128
+ - `incident_timestamp_ms`
129
+ - `max_hops`
130
+
131
+ Optional input:
132
+
133
+ - `activity_policy`
134
+ - `case_id`
135
+ - `include_attachments`
136
+
137
+ CLI examples:
138
+
139
+ ```bash
140
+ cia mcp scam-topology \
141
+ --network bittensor \
142
+ --victim-address 5... \
143
+ --incident-timestamp-ms 1715532228001 \
144
+ --max-hops 16
145
+ ```
146
+
147
+ ```bash
148
+ cia mcp scam-topology \
149
+ --network bittensor \
150
+ --victim-address 5... \
151
+ --incident-timestamp-ms 1715532228001 \
152
+ --max-hops 16 \
153
+ --activity-policy global_incident_only \
154
+ --case 1
155
+ ```
156
+
157
+ ### Traversal Semantics
158
+
159
+ `scam_topology` starts from one victim/source address and
160
+ `incident_timestamp_ms`, then runs directed `FLOWS_TO` traversal outward from
161
+ that victim incident.
162
+
163
+ The default traversal is `node_relative_only`. Each new node expands only once.
164
+ Repeated targets are retained as non-expanding `convergence_edge` context.
165
+ Downstream edges must have `first_seen_timestamp` or `last_seen_timestamp`
166
+ greater than or equal to the current node's wave-arrival timestamp.
167
+
168
+ The alternate policy is `global_incident_only`. In that mode every wave is
169
+ filtered against the original `incident_timestamp_ms`.
170
+
171
+ Exchange terminal safety is the only hard-coded terminal class. Other labels
172
+ are generic context hints. Victim/source addresses, exchange endpoints, and
173
+ generic labeled context nodes are not automatic scam labels.
174
+
175
+ ### Result Contract
176
+
177
+ `scam_topology` returns `chain-insights.result.v1` JSON with this stable
178
+ top-level shape:
179
+
180
+ ```json
181
+ {
182
+ "schema": "chain-insights.result.v1",
183
+ "tool": "scam_topology",
184
+ "facts": {
185
+ "network": "bittensor",
186
+ "victim_address": "5...",
187
+ "incident_timestamp_ms": 1715532228001,
188
+ "topology_graphs": ["live_topology"],
189
+ "primary_activity_policy": "node_relative",
190
+ "activity_policy_mode": "node_relative_only",
191
+ "topology_edges": [],
192
+ "intermediaries": [],
193
+ "terminal_points": [],
194
+ "exchange_deposits": [],
195
+ "investigation_hints": [],
196
+ "scam_labels": [],
197
+ "label_candidates": [],
198
+ "case_roles": [],
199
+ "safety_decisions": [],
200
+ "runs": [
201
+ {
202
+ "graph_scope": "incident",
203
+ "topology_graph": "live_topology",
204
+ "activity_policy": "node_relative",
205
+ "primary": true
206
+ }
207
+ ]
208
+ }
209
+ }
210
+ ```
211
+
212
+ The tool returns ML-ready `scam_labels` plus `label_candidates` for analyst
213
+ review before any write to warehouse address labels.
214
+
215
+ ## Graph Reports
216
+
217
+ Graph reports use `chain-insights.graph.v1` JSON. Visual edges use the
218
+ canonical `source` / `target` convention.
219
+
220
+ For `scam_topology`:
221
+
222
+ - Primary victim-flow edges are emitted in `flows`.
223
+ - Exchange deposit candidates are emitted in `deposits`.
224
+ - Deposit-cluster enrichment is emitted in `reverse_leads`.
225
+ - Deposit-cluster enrichment is not emitted as primary victim-flow topology.
226
+
227
+ For `track_funds`, the same graph report shape is used so renderers and import
228
+ helpers can share one parser.
229
+
230
+ When `case_id` or CLI `--case` is provided, `track_funds` and
231
+ `scam_topology` store `chain-insights.evidence_pointer.v1` evidence entries.
232
+ The pointer references workspace-local compact evidence JSON, graph JSON, graph
233
+ HTML, CSV or table files, and Markdown reports.
234
+
235
+ Evidence Markdown should be a provenance record with key facts and pointers.
236
+ Large JSON belongs under workspace report directories, not inline in evidence.
237
+
238
+ ## Runtime Schema Capture
239
+
240
+ Fresh workspaces include a runtime schema skill and schema capture directory.
241
+ Before the first case query against a network, capture the live graph schema and
242
+ use the observed labels, relationship types, and property names in subsequent
243
+ queries.
244
+
245
+ Useful schema probes:
246
+
247
+ ```bash
248
+ cia mcp call graph_query_batch \
249
+ network=bittensor \
250
+ 'queries=[{"id":"live_address_sample","query":"USE live_topology MATCH (n:Address) RETURN n.address AS address, n.labels AS labels LIMIT 5"},{"id":"archive_flow_sample","query":"USE archive_topology MATCH (src:Address)-[f:FLOWS_TO]->(dst:Address) RETURN src.address AS source, dst.address AS target, f.period_granularity AS granularity LIMIT 5"},{"id":"facts_sample","query":"USE facts MATCH (a:Address)-[:HAS_FEATURE]->(f:AddressFeature) RETURN a.address AS address, f.sent_count AS sent_count LIMIT 5"}]'
251
+ ```
Binary file
Binary file