chain-insights 0.85.2 → 0.93.0
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.
- package/README.md +2 -0
- package/bin/install.cjs +2 -1
- package/dist/{active-q3yViZhc.cjs → active-COPA14FA.cjs} +2 -16
- package/dist/{active-D2aabYRF.mjs → active-CyC4jFka.mjs} +2 -7
- package/dist/{active-D2aabYRF.mjs.map → active-CyC4jFka.mjs.map} +1 -1
- package/dist/address-card-C-NB03XP.cjs +218 -0
- package/dist/address-card-LYaT5yz0.mjs +190 -0
- package/dist/address-card-LYaT5yz0.mjs.map +1 -0
- package/dist/address-risk-B8xTh1iM.mjs +760 -0
- package/dist/address-risk-B8xTh1iM.mjs.map +1 -0
- package/dist/address-risk-WIKbjqy2.cjs +913 -0
- package/dist/{capabilities-Mxa4oQdd.cjs → capabilities-DkNreyv7.cjs} +1 -1
- package/dist/{capabilities-bZOr5Ads.mjs → capabilities-w5bNR7F9.mjs} +2 -2
- package/dist/{capabilities-bZOr5Ads.mjs.map → capabilities-w5bNR7F9.mjs.map} +1 -1
- package/dist/cli.cjs +138 -46
- package/dist/cli.mjs +138 -46
- package/dist/cli.mjs.map +1 -1
- package/dist/{deployer-screen-B5yrXZGo.mjs → deployer-screen-Bkw_sz94.mjs} +3 -3
- package/dist/{deployer-screen-B5yrXZGo.mjs.map → deployer-screen-Bkw_sz94.mjs.map} +1 -1
- package/dist/{deployer-screen-0SOQ_HFf.cjs → deployer-screen-CFLi7OeH.cjs} +2 -2
- package/dist/{dex-registry-BY67f4Ul.mjs → dex-registry-Bkri0--q.mjs} +10 -2
- package/dist/{dex-registry-BY67f4Ul.mjs.map → dex-registry-Bkri0--q.mjs.map} +1 -1
- package/dist/{dex-registry-BhGJUG9_.cjs → dex-registry-CyR3GyRr.cjs} +20 -0
- package/dist/{dex-tool-7BK_gD6H.mjs → dex-tool-D0K_Qx4N.mjs} +4 -4
- package/dist/dex-tool-D0K_Qx4N.mjs.map +1 -0
- package/dist/{dex-tool-Be9NAuD8.cjs → dex-tool-DQ5Eg0LO.cjs} +3 -3
- package/dist/{exchange-deposit-check-C5MseGlZ.cjs → exchange-deposit-check-BNzkwQeW.cjs} +18 -18
- package/dist/{exchange-deposit-check-CXHZCHWW.mjs → exchange-deposit-check-DIALj2sm.mjs} +19 -19
- package/dist/exchange-deposit-check-DIALj2sm.mjs.map +1 -0
- package/dist/{exchange-registry-CT0rRW__.cjs → exchange-registry-CEgkeQV1.cjs} +16 -93
- package/dist/{exchange-registry-CoLgHw6d.mjs → exchange-registry-Dr5UtcT5.mjs} +17 -94
- package/dist/exchange-registry-Dr5UtcT5.mjs.map +1 -0
- package/dist/{exchange-tool-Dc46SJ49.mjs → exchange-tool-B7E29YoQ.mjs} +4 -4
- package/dist/exchange-tool-B7E29YoQ.mjs.map +1 -0
- package/dist/{exchange-tool-B2SMeC5f.cjs → exchange-tool-CXaUBAd2.cjs} +3 -3
- package/dist/{graph-schema-CcrYPpSv.cjs → graph-schema-Bn3txQCj.cjs} +115 -12
- package/dist/{graph-schema-CRQuKya1.mjs → graph-schema-DvABR1yl.mjs} +97 -12
- package/dist/graph-schema-DvABR1yl.mjs.map +1 -0
- package/dist/{layer-routing-YDj-ynG9.cjs → layer-routing-j48SQ8Wk.cjs} +2 -2
- package/dist/{layer-routing-DCJVNN6O.mjs → layer-routing-r4IbIQSr.mjs} +3 -3
- package/dist/layer-routing-r4IbIQSr.mjs.map +1 -0
- package/dist/mcp-proxy.cjs +62 -15
- package/dist/mcp-proxy.d.cts.map +1 -1
- package/dist/mcp-proxy.d.mts.map +1 -1
- package/dist/mcp-proxy.mjs +62 -15
- package/dist/mcp-proxy.mjs.map +1 -1
- package/dist/public-file-BISyAesm.mjs +133 -0
- package/dist/public-file-BISyAesm.mjs.map +1 -0
- package/dist/public-file-DDp2CrUl.cjs +138 -0
- package/dist/{request-timeout-DxwNijQD.cjs → request-timeout-BXiIt9Jy.cjs} +0 -1
- package/dist/{request-timeout-K3ljP0pa.mjs → request-timeout-DetG2xO4.mjs} +2 -2
- package/dist/{request-timeout-K3ljP0pa.mjs.map → request-timeout-DetG2xO4.mjs.map} +1 -1
- package/dist/{token-lookup-Cf59VdGe.mjs → token-lookup-Ck0q7crJ.mjs} +2 -2
- package/dist/{token-lookup-Cf59VdGe.mjs.map → token-lookup-Ck0q7crJ.mjs.map} +1 -1
- package/dist/{token-lookup-DqjSRIxd.cjs → token-lookup-DLe4erP9.cjs} +1 -1
- package/dist/token-risk-BkwTaKxS.cjs +1004 -0
- package/dist/token-risk-XVaN_Yp3.mjs +971 -0
- package/dist/token-risk-XVaN_Yp3.mjs.map +1 -0
- package/dist/{tool-visibility-D8Up081E.cjs → tool-visibility-BCa-tmyZ.cjs} +11 -2
- package/dist/{tool-visibility-DuTds7V4.mjs → tool-visibility-BstrSl4s.mjs} +12 -3
- package/dist/tool-visibility-BstrSl4s.mjs.map +1 -0
- package/docs/contributing.md +10 -8
- package/docs/development.md +5 -5
- package/docs/evals.md +16 -1
- package/docs/graph-query-compatibility.md +15 -2
- package/docs/graph-tools.md +44 -6
- package/docs/mcp-proxy.md +206 -8
- package/docs/stability.md +4 -5
- package/docs/testing.md +77 -0
- package/package.json +1 -1
- package/registry/README.md +20 -5
- package/registry/address-card.json +772 -0
- package/skills/chain-insights-address-risk/SKILL.md +77 -0
- package/skills/chain-insights-address-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-aml-exchange/SKILL.md +9 -7
- package/skills/chain-insights-cypher/SKILL.md +80 -3
- package/skills/chain-insights-token-risk/SKILL.md +81 -0
- package/skills/chain-insights-token-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-virtuals/reference.md +1 -1
- package/dist/dex-tool-7BK_gD6H.mjs.map +0 -1
- package/dist/exchange-deposit-check-CXHZCHWW.mjs.map +0 -1
- package/dist/exchange-registry-CoLgHw6d.mjs.map +0 -1
- package/dist/exchange-tool-Dc46SJ49.mjs.map +0 -1
- package/dist/graph-schema-CRQuKya1.mjs.map +0 -1
- package/dist/layer-routing-DCJVNN6O.mjs.map +0 -1
- package/dist/public-tools-CBszU2oX.cjs +0 -1334
- package/dist/public-tools-DVhUjSDV.mjs +0 -1333
- package/dist/public-tools-DVhUjSDV.mjs.map +0 -1
- package/dist/tool-visibility-DuTds7V4.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -111,6 +111,8 @@ Never touches:
|
|
|
111
111
|
| `aml_deployer_screen` | Screen who is behind a token or a wallet: launcher, first funder, labels |
|
|
112
112
|
| `meta_exchange_lookup` | Turn a centralized exchange name (Binance, OKX) into its wallets proven on chain |
|
|
113
113
|
| `aml_exchange_deposit_check`| Check an address: an exchange deposit, of which exchange, swept into which wallet |
|
|
114
|
+
| `aml_address_risk` | Screen an address: who it is, its risk word with reasons, model score, risky partners |
|
|
115
|
+
| `aml_token_risk` | Screen a token or a pool: founder, factory, gas wallets and pools, each with its word |
|
|
114
116
|
| `meta_usage_status` | Check the caller's daily free-tier graph query allowance |
|
|
115
117
|
| `meta_subscription_status` | Check your wallet's subscription: days left, today's allowance, payments pending |
|
|
116
118
|
| `meta_rules` | Read the answer rules when the `chain-insights-cypher` skill is not loaded |
|
package/bin/install.cjs
CHANGED
|
@@ -52,8 +52,9 @@ const srcSkillsDir = path.join(__dirname, '..', 'skills')
|
|
|
52
52
|
const SKILL_VERSION_FILE = '.chain-insights-version'
|
|
53
53
|
// The core skill every install carries. Protocol skills sit beside it.
|
|
54
54
|
const CORE_SKILL_NAME = 'chain-insights-cypher'
|
|
55
|
+
// chain-insights-address-risk was retired in 0.44.0 and ships again from
|
|
56
|
+
// 0.90.0, on the aml_address_risk tool: it is no longer a retired name.
|
|
55
57
|
const RETIRED_SKILL_NAMES = Object.freeze([
|
|
56
|
-
'chain-insights-address-risk',
|
|
57
58
|
'chain-insights-bittensor-cypher',
|
|
58
59
|
'chain-insights-developer-experience',
|
|
59
60
|
'chain-insights-investigation',
|
|
@@ -6,10 +6,6 @@ node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
|
6
6
|
let node_os = require("node:os");
|
|
7
7
|
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
8
8
|
// src/workspace/active.ts
|
|
9
|
-
var active_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
10
|
-
activeDataDir: () => activeDataDir,
|
|
11
|
-
findActiveWorkspace: () => findActiveWorkspace
|
|
12
|
-
});
|
|
13
9
|
function workspaceFromRoot(rootCandidate) {
|
|
14
10
|
const root = node_path.default.resolve(rootCandidate);
|
|
15
11
|
const metadataDir = node_path.default.join(root, ".chain-insights");
|
|
@@ -45,15 +41,5 @@ function findActiveWorkspace(startDir = process.cwd()) {
|
|
|
45
41
|
function activeDataDir(fallbackDataDir) {
|
|
46
42
|
return findActiveWorkspace()?.root ?? fallbackDataDir ?? node_path.default.join(node_os.default.homedir(), ".chain-insights");
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
get: function() {
|
|
51
|
-
return active_exports;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "findActiveWorkspace", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function() {
|
|
57
|
-
return findActiveWorkspace;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
44
|
+
exports.activeDataDir = activeDataDir;
|
|
45
|
+
exports.findActiveWorkspace = findActiveWorkspace;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import fs from "node:fs";
|
|
4
3
|
import os from "node:os";
|
|
5
4
|
// src/workspace/active.ts
|
|
6
|
-
var active_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
-
activeDataDir: () => activeDataDir,
|
|
8
|
-
findActiveWorkspace: () => findActiveWorkspace
|
|
9
|
-
});
|
|
10
5
|
function workspaceFromRoot(rootCandidate) {
|
|
11
6
|
const root = path.resolve(rootCandidate);
|
|
12
7
|
const metadataDir = path.join(root, ".chain-insights");
|
|
@@ -42,6 +37,6 @@ function findActiveWorkspace(startDir = process.cwd()) {
|
|
|
42
37
|
function activeDataDir(fallbackDataDir) {
|
|
43
38
|
return findActiveWorkspace()?.root ?? fallbackDataDir ?? path.join(os.homedir(), ".chain-insights");
|
|
44
39
|
}
|
|
45
|
-
export {
|
|
40
|
+
export { activeDataDir, findActiveWorkspace };
|
|
46
41
|
|
|
47
|
-
//# sourceMappingURL=active-
|
|
42
|
+
//# sourceMappingURL=active-CyC4jFka.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-
|
|
1
|
+
{"version":3,"file":"active-CyC4jFka.mjs","names":[],"sources":["../src/workspace/active.ts"],"sourcesContent":["import fs from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\n\ninterface WorkspaceConfig {\n schema?: string\n workspace_root?: string\n artifacts_dir?: string\n domain_hints?: unknown\n}\n\nexport interface ActiveWorkspace {\n root: string\n metadataDir: string\n artifactsRoot: string\n domainHints: string[]\n}\n\nfunction workspaceFromRoot(rootCandidate: string): ActiveWorkspace | null {\n const root = path.resolve(rootCandidate)\n const metadataDir = path.join(root, '.chain-insights')\n const markerPath = path.join(metadataDir, 'workspace.json')\n if (!fs.existsSync(markerPath)) return null\n\n const parsed = JSON.parse(fs.readFileSync(markerPath, 'utf8')) as WorkspaceConfig\n if (parsed.schema !== 'chain-insights.workspace.v1') return null\n\n const workspaceRoot = path.resolve(parsed.workspace_root ?? root)\n const artifactsDir = parsed.artifacts_dir ?? 'artifacts'\n const domainHints = Array.isArray(parsed.domain_hints)\n ? parsed.domain_hints.filter(\n (value): value is string => typeof value === 'string' && value.trim().length > 0\n )\n : []\n return {\n root: workspaceRoot,\n metadataDir: path.join(workspaceRoot, '.chain-insights'),\n artifactsRoot: path.resolve(workspaceRoot, artifactsDir),\n domainHints,\n }\n}\n\nexport function findActiveWorkspace(startDir = process.cwd()): ActiveWorkspace | null {\n const envWorkspace = process.env['CHAIN_INSIGHTS_WORKSPACE']?.trim()\n if (envWorkspace) {\n const active = workspaceFromRoot(envWorkspace)\n if (active) return active\n }\n\n let current = path.resolve(startDir)\n while (true) {\n const active = workspaceFromRoot(current)\n if (active) return active\n\n const parent = path.dirname(current)\n if (parent === current) return null\n current = parent\n }\n}\n\nexport function activeMetadataDir(): string {\n return findActiveWorkspace()?.metadataDir ?? path.join(os.homedir(), '.chain-insights')\n}\n\nexport function activeArtifactsRoot(): string {\n return (\n findActiveWorkspace()?.artifactsRoot ?? path.join(os.homedir(), '.chain-insights', 'artifacts')\n )\n}\n\nexport function activeDataDir(fallbackDataDir?: string): string {\n return (\n findActiveWorkspace()?.root ?? fallbackDataDir ?? path.join(os.homedir(), '.chain-insights')\n )\n}\n"],"mappings":";;;;AAkBA,SAAS,kBAAkB,eAA+C;CACxE,MAAM,OAAO,KAAK,QAAQ,aAAa;CACvC,MAAM,cAAc,KAAK,KAAK,MAAM,iBAAiB;CACrD,MAAM,aAAa,KAAK,KAAK,aAAa,gBAAgB;CAC1D,IAAI,CAAC,GAAG,WAAW,UAAU,GAAG,OAAO;CAEvC,MAAM,SAAS,KAAK,MAAM,GAAG,aAAa,YAAY,MAAM,CAAC;CAC7D,IAAI,OAAO,WAAW,+BAA+B,OAAO;CAE5D,MAAM,gBAAgB,KAAK,QAAQ,OAAO,kBAAkB,IAAI;CAChE,MAAM,eAAe,OAAO,iBAAiB;CAC7C,MAAM,cAAc,MAAM,QAAQ,OAAO,YAAY,IACjD,OAAO,aAAa,QACjB,UAA2B,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS,CACjF,IACA,CAAC;CACL,OAAO;EACL,MAAM;EACN,aAAa,KAAK,KAAK,eAAe,iBAAiB;EACvD,eAAe,KAAK,QAAQ,eAAe,YAAY;EACvD;CACF;AACF;AAEA,SAAgB,oBAAoB,WAAW,QAAQ,IAAI,GAA2B;CACpF,MAAM,eAAe,QAAQ,IAAI,2BAA2B,EAAE,KAAK;CACnE,IAAI,cAAc;EAChB,MAAM,SAAS,kBAAkB,YAAY;EAC7C,IAAI,QAAQ,OAAO;CACrB;CAEA,IAAI,UAAU,KAAK,QAAQ,QAAQ;CACnC,OAAO,MAAM;EACX,MAAM,SAAS,kBAAkB,OAAO;EACxC,IAAI,QAAQ,OAAO;EAEnB,MAAM,SAAS,KAAK,QAAQ,OAAO;EACnC,IAAI,WAAW,SAAS,OAAO;EAC/B,UAAU;CACZ;AACF;AAYA,SAAgB,cAAc,iBAAkC;CAC9D,OACE,oBAAoB,CAAC,EAAE,QAAQ,mBAAmB,KAAK,KAAK,GAAG,QAAQ,GAAG,iBAAiB;AAE/F"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-BW-eSwOZ.cjs");
|
|
2
|
+
const require_cache_location = require("./cache-location-C09AE55j.cjs");
|
|
3
|
+
const require_public_file = require("./public-file-DDp2CrUl.cjs");
|
|
4
|
+
let node_url = require("node:url");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
7
|
+
let node_fs = require("node:fs");
|
|
8
|
+
// src/mcp/address-card.ts
|
|
9
|
+
/**
|
|
10
|
+
* The address card dictionary, as meta_schema serves it.
|
|
11
|
+
*
|
|
12
|
+
* Every :Address node of the graph carries one resolved card: what the address
|
|
13
|
+
* is (identity), which wallet it is (address_roles), what one week of counts
|
|
14
|
+
* shows (behaviour), what it did or what was done to it (evidence), the risky
|
|
15
|
+
* patterns that convict nobody (judgements), its risk, and who gave the
|
|
16
|
+
* answers (sources). registry/address-card.json names each card property with
|
|
17
|
+
* its question, its meaning and its closed values, each mark and each flag with
|
|
18
|
+
* the words that give it, each card word with its question, its level and its
|
|
19
|
+
* plain sentence (words), and the one rule an agent follows. The file is
|
|
20
|
+
* generated from the label vocabulary and never edited by hand.
|
|
21
|
+
*
|
|
22
|
+
* The proxy reads it through the shared public file loader
|
|
23
|
+
* (src/mcp/public-file.ts):
|
|
24
|
+
*
|
|
25
|
+
* cached ~/.chain-insights/cache/address-card.json, younger than one hour
|
|
26
|
+
* fetched https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json
|
|
27
|
+
* packaged registry/address-card.json of the installed package
|
|
28
|
+
*
|
|
29
|
+
* A malformed file is refused with one line naming the fault, and the packaged
|
|
30
|
+
* copy answers. A dictionary merged on main reaches every running proxy within
|
|
31
|
+
* the hour, with no release.
|
|
32
|
+
*/
|
|
33
|
+
var address_card_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ loadAddressCard: () => loadAddressCard });
|
|
34
|
+
const ADDRESS_CARD_URL_ENV = "CHAIN_INSIGHTS_ADDRESS_CARD_URL";
|
|
35
|
+
const ADDRESS_CARD_PUBLIC_URL = "https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json";
|
|
36
|
+
const ADDRESS_CARD_FILE = "registry/address-card.json";
|
|
37
|
+
/**
|
|
38
|
+
* The `rule` of registry/address-card.json, word for word. It is the one text
|
|
39
|
+
* of the card every host reads: the meta_schema description carries it.
|
|
40
|
+
* tests/graph-schema-address-card.test.ts holds it to the file.
|
|
41
|
+
*/
|
|
42
|
+
const ADDRESS_CARD_RULE = "Read the address card (identity, address_roles, behaviour, evidence, judgements, risk), not the labels list.";
|
|
43
|
+
/** The levels a card word may carry, lowest first. */
|
|
44
|
+
const ADDRESS_CARD_LEVELS = [
|
|
45
|
+
"none",
|
|
46
|
+
"low",
|
|
47
|
+
"medium",
|
|
48
|
+
"high",
|
|
49
|
+
"critical"
|
|
50
|
+
];
|
|
51
|
+
function isRecord(value) {
|
|
52
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
const isWord = (value) => typeof value === "string" && value.trim() !== "";
|
|
55
|
+
const isWordList = (value) => Array.isArray(value) && value.length > 0 && value.every(isWord);
|
|
56
|
+
function markFault(list, field) {
|
|
57
|
+
if (!Array.isArray(list)) return `${field} is not a list`;
|
|
58
|
+
const names = /* @__PURE__ */ new Set();
|
|
59
|
+
for (const [index, entry] of list.entries()) {
|
|
60
|
+
const at = `${field}[${index}]`;
|
|
61
|
+
if (!isRecord(entry)) return `${at} is not an object`;
|
|
62
|
+
if (!isWord(entry.name)) return `${at} has no name`;
|
|
63
|
+
if (names.has(entry.name)) return `${at} ${entry.name} is listed twice`;
|
|
64
|
+
names.add(entry.name);
|
|
65
|
+
if (!isWord(entry.question)) return `${at} (${entry.name}) has no question`;
|
|
66
|
+
if (!isWordList(entry.words)) return `${at} (${entry.name}) words is not a list of words`;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/** The fault of a card dictionary, or null when it is valid. */
|
|
71
|
+
function addressCardFault(value) {
|
|
72
|
+
if (!isRecord(value)) return "the file is not a JSON object";
|
|
73
|
+
if (!isWord(value.version)) return "version is missing";
|
|
74
|
+
if (!isWord(value.rule)) return "rule is missing";
|
|
75
|
+
if (!Array.isArray(value.properties) || value.properties.length === 0) return "properties is empty";
|
|
76
|
+
const names = /* @__PURE__ */ new Set();
|
|
77
|
+
for (const [index, property] of value.properties.entries()) {
|
|
78
|
+
const at = `properties[${index}]`;
|
|
79
|
+
if (!isRecord(property)) return `${at} is not an object`;
|
|
80
|
+
if (typeof property.name !== "string" || !/^[a-z][a-z0-9_]*$/.test(property.name)) return `${at} name is not a property name: ${String(property.name)}`;
|
|
81
|
+
if (names.has(property.name)) return `${at} ${property.name} is listed twice`;
|
|
82
|
+
names.add(property.name);
|
|
83
|
+
for (const field of [
|
|
84
|
+
"type",
|
|
85
|
+
"question",
|
|
86
|
+
"means"
|
|
87
|
+
]) if (!isWord(property[field])) return `${at} (${property.name}) has no ${field}`;
|
|
88
|
+
if (property.values !== void 0 && !isWordList(property.values)) return `${at} (${property.name}) values is not a list of words`;
|
|
89
|
+
if (property.value_form !== void 0 && !isWord(property.value_form)) return `${at} (${property.name}) value_form is empty`;
|
|
90
|
+
}
|
|
91
|
+
const marks = markFault(value.marks, "marks");
|
|
92
|
+
if (marks) return marks;
|
|
93
|
+
const flags = markFault(value.flags, "flags");
|
|
94
|
+
if (flags) return flags;
|
|
95
|
+
if (!isWordList(value.sources)) return "sources is not a list of words";
|
|
96
|
+
return wordsFault(value.words);
|
|
97
|
+
}
|
|
98
|
+
/** The fault of the words list, or null. A file with no words is refused, so the packaged copy answers. */
|
|
99
|
+
function wordsFault(list) {
|
|
100
|
+
if (!Array.isArray(list) || list.length === 0) return "words is not a list";
|
|
101
|
+
for (const [index, entry] of list.entries()) {
|
|
102
|
+
const at = `words[${index}]`;
|
|
103
|
+
if (!isRecord(entry)) return `${at} is not an object`;
|
|
104
|
+
if (!isWord(entry.word)) return `${at} has no word`;
|
|
105
|
+
if (!isWord(entry.question)) return `${at} (${entry.word}) has no question`;
|
|
106
|
+
if (!ADDRESS_CARD_LEVELS.includes(entry.level)) return `${at} (${entry.word}) level is not one of ${ADDRESS_CARD_LEVELS.join(", ")}`;
|
|
107
|
+
if (!isWord(entry.plain)) return `${at} (${entry.word}) has no plain sentence`;
|
|
108
|
+
if (entry.value !== void 0 && !isWord(entry.value)) return `${at} (${entry.word}) value is empty`;
|
|
109
|
+
if (entry.standing !== void 0 && !isWord(entry.standing)) return `${at} (${entry.word}) standing is empty`;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
/** The version as a number, so a newer packaged copy wins; 0 when it is not a number. */
|
|
114
|
+
function addressCardVersion(document) {
|
|
115
|
+
const version = Number(document.version);
|
|
116
|
+
return Number.isFinite(version) ? version : 0;
|
|
117
|
+
}
|
|
118
|
+
/** The URL of the served copy: the public file on main, or the override. */
|
|
119
|
+
function addressCardUrl(env = process.env) {
|
|
120
|
+
return env[ADDRESS_CARD_URL_ENV]?.trim() || ADDRESS_CARD_PUBLIC_URL;
|
|
121
|
+
}
|
|
122
|
+
function addressCardCachePath() {
|
|
123
|
+
return node_path.default.join(require_cache_location.chainInsightsHome(), "cache", "address-card.json");
|
|
124
|
+
}
|
|
125
|
+
/** registry/address-card.json of the installed package: next to dist/, or the repository root when run from source. */
|
|
126
|
+
function packagedAddressCardPath() {
|
|
127
|
+
const candidates = [(0, node_url.fileURLToPath)(new URL("../registry/address-card.json", require("url").pathToFileURL(__filename).href)), (0, node_url.fileURLToPath)(new URL("../../registry/address-card.json", require("url").pathToFileURL(__filename).href))];
|
|
128
|
+
return candidates.find((candidate) => (0, node_fs.existsSync)(candidate)) ?? candidates[0];
|
|
129
|
+
}
|
|
130
|
+
/** The packaged copy, or null when the package carries none. A packaged copy that fails the rules throws. */
|
|
131
|
+
function readPackagedAddressCard(file = packagedAddressCardPath()) {
|
|
132
|
+
let parsed;
|
|
133
|
+
try {
|
|
134
|
+
parsed = JSON.parse((0, node_fs.readFileSync)(file, "utf8"));
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const fault = addressCardFault(parsed);
|
|
139
|
+
if (fault) throw new Error(`the packaged ${ADDRESS_CARD_FILE} is malformed: ${fault}`);
|
|
140
|
+
return parsed;
|
|
141
|
+
}
|
|
142
|
+
const defaultLog = (line) => {
|
|
143
|
+
process.stderr.write(`[chain-insights] address-card: ${line}\n`);
|
|
144
|
+
};
|
|
145
|
+
/** The card dictionary: the fresh cache, else the public file, else the stale cache, else the packaged copy. Null when there is none. */
|
|
146
|
+
async function loadAddressCard(options = {}) {
|
|
147
|
+
return require_public_file.loadPublicFile({
|
|
148
|
+
url: addressCardUrl(options.env),
|
|
149
|
+
cachePath: addressCardCachePath(),
|
|
150
|
+
fault: addressCardFault,
|
|
151
|
+
packaged: readPackagedAddressCard(options.packagedFile),
|
|
152
|
+
version: addressCardVersion,
|
|
153
|
+
log: options.log ?? defaultLog
|
|
154
|
+
}, options);
|
|
155
|
+
}
|
|
156
|
+
function addressCardSection(loaded) {
|
|
157
|
+
const { document } = loaded;
|
|
158
|
+
return {
|
|
159
|
+
file: ADDRESS_CARD_FILE,
|
|
160
|
+
version: document.version,
|
|
161
|
+
source: loaded.source,
|
|
162
|
+
rule: document.rule,
|
|
163
|
+
properties: document.properties,
|
|
164
|
+
marks: document.marks,
|
|
165
|
+
flags: document.flags
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function propertyLine(property) {
|
|
169
|
+
const entries = property.value_form ? `, entries ${property.value_form}` : "";
|
|
170
|
+
const values = property.values?.length ? ` Values: ${property.values.join(", ")}.` : "";
|
|
171
|
+
return `- ${property.name} (${property.type}, question ${property.question}${entries}): ${property.means}${values}`;
|
|
172
|
+
}
|
|
173
|
+
function markLine(mark) {
|
|
174
|
+
return `- ${mark.name} (question ${mark.question}): ${mark.words.join(", ")}`;
|
|
175
|
+
}
|
|
176
|
+
/** The card as the model and the terminal read it. */
|
|
177
|
+
function formatAddressCardLines(card) {
|
|
178
|
+
return [
|
|
179
|
+
`Address card, on every :Address node (${card.file}, version ${card.version}, ${card.source})`,
|
|
180
|
+
`Rule: ${card.rule}`,
|
|
181
|
+
"Card properties:",
|
|
182
|
+
...card.properties.map(propertyLine),
|
|
183
|
+
"Marks, the node labels a card word gives:",
|
|
184
|
+
...card.marks.map(markLine),
|
|
185
|
+
"Flags, true when the card holds one of the words:",
|
|
186
|
+
...card.flags.map(markLine)
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
Object.defineProperty(exports, "ADDRESS_CARD_RULE", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function() {
|
|
192
|
+
return ADDRESS_CARD_RULE;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(exports, "addressCardSection", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: function() {
|
|
198
|
+
return addressCardSection;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, "address_card_exports", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function() {
|
|
204
|
+
return address_card_exports;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(exports, "formatAddressCardLines", {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
get: function() {
|
|
210
|
+
return formatAddressCardLines;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, "loadAddressCard", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function() {
|
|
216
|
+
return loadAddressCard;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
|
+
import { n as chainInsightsHome } from "./cache-location-DxTTqBwk.mjs";
|
|
3
|
+
import { t as loadPublicFile } from "./public-file-BISyAesm.mjs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
// src/mcp/address-card.ts
|
|
8
|
+
/**
|
|
9
|
+
* The address card dictionary, as meta_schema serves it.
|
|
10
|
+
*
|
|
11
|
+
* Every :Address node of the graph carries one resolved card: what the address
|
|
12
|
+
* is (identity), which wallet it is (address_roles), what one week of counts
|
|
13
|
+
* shows (behaviour), what it did or what was done to it (evidence), the risky
|
|
14
|
+
* patterns that convict nobody (judgements), its risk, and who gave the
|
|
15
|
+
* answers (sources). registry/address-card.json names each card property with
|
|
16
|
+
* its question, its meaning and its closed values, each mark and each flag with
|
|
17
|
+
* the words that give it, each card word with its question, its level and its
|
|
18
|
+
* plain sentence (words), and the one rule an agent follows. The file is
|
|
19
|
+
* generated from the label vocabulary and never edited by hand.
|
|
20
|
+
*
|
|
21
|
+
* The proxy reads it through the shared public file loader
|
|
22
|
+
* (src/mcp/public-file.ts):
|
|
23
|
+
*
|
|
24
|
+
* cached ~/.chain-insights/cache/address-card.json, younger than one hour
|
|
25
|
+
* fetched https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json
|
|
26
|
+
* packaged registry/address-card.json of the installed package
|
|
27
|
+
*
|
|
28
|
+
* A malformed file is refused with one line naming the fault, and the packaged
|
|
29
|
+
* copy answers. A dictionary merged on main reaches every running proxy within
|
|
30
|
+
* the hour, with no release.
|
|
31
|
+
*/
|
|
32
|
+
var address_card_exports = /* @__PURE__ */ __exportAll({ loadAddressCard: () => loadAddressCard });
|
|
33
|
+
const ADDRESS_CARD_URL_ENV = "CHAIN_INSIGHTS_ADDRESS_CARD_URL";
|
|
34
|
+
const ADDRESS_CARD_PUBLIC_URL = "https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json";
|
|
35
|
+
const ADDRESS_CARD_FILE = "registry/address-card.json";
|
|
36
|
+
/**
|
|
37
|
+
* The `rule` of registry/address-card.json, word for word. It is the one text
|
|
38
|
+
* of the card every host reads: the meta_schema description carries it.
|
|
39
|
+
* tests/graph-schema-address-card.test.ts holds it to the file.
|
|
40
|
+
*/
|
|
41
|
+
const ADDRESS_CARD_RULE = "Read the address card (identity, address_roles, behaviour, evidence, judgements, risk), not the labels list.";
|
|
42
|
+
/** The levels a card word may carry, lowest first. */
|
|
43
|
+
const ADDRESS_CARD_LEVELS = [
|
|
44
|
+
"none",
|
|
45
|
+
"low",
|
|
46
|
+
"medium",
|
|
47
|
+
"high",
|
|
48
|
+
"critical"
|
|
49
|
+
];
|
|
50
|
+
function isRecord(value) {
|
|
51
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
const isWord = (value) => typeof value === "string" && value.trim() !== "";
|
|
54
|
+
const isWordList = (value) => Array.isArray(value) && value.length > 0 && value.every(isWord);
|
|
55
|
+
function markFault(list, field) {
|
|
56
|
+
if (!Array.isArray(list)) return `${field} is not a list`;
|
|
57
|
+
const names = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const [index, entry] of list.entries()) {
|
|
59
|
+
const at = `${field}[${index}]`;
|
|
60
|
+
if (!isRecord(entry)) return `${at} is not an object`;
|
|
61
|
+
if (!isWord(entry.name)) return `${at} has no name`;
|
|
62
|
+
if (names.has(entry.name)) return `${at} ${entry.name} is listed twice`;
|
|
63
|
+
names.add(entry.name);
|
|
64
|
+
if (!isWord(entry.question)) return `${at} (${entry.name}) has no question`;
|
|
65
|
+
if (!isWordList(entry.words)) return `${at} (${entry.name}) words is not a list of words`;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/** The fault of a card dictionary, or null when it is valid. */
|
|
70
|
+
function addressCardFault(value) {
|
|
71
|
+
if (!isRecord(value)) return "the file is not a JSON object";
|
|
72
|
+
if (!isWord(value.version)) return "version is missing";
|
|
73
|
+
if (!isWord(value.rule)) return "rule is missing";
|
|
74
|
+
if (!Array.isArray(value.properties) || value.properties.length === 0) return "properties is empty";
|
|
75
|
+
const names = /* @__PURE__ */ new Set();
|
|
76
|
+
for (const [index, property] of value.properties.entries()) {
|
|
77
|
+
const at = `properties[${index}]`;
|
|
78
|
+
if (!isRecord(property)) return `${at} is not an object`;
|
|
79
|
+
if (typeof property.name !== "string" || !/^[a-z][a-z0-9_]*$/.test(property.name)) return `${at} name is not a property name: ${String(property.name)}`;
|
|
80
|
+
if (names.has(property.name)) return `${at} ${property.name} is listed twice`;
|
|
81
|
+
names.add(property.name);
|
|
82
|
+
for (const field of [
|
|
83
|
+
"type",
|
|
84
|
+
"question",
|
|
85
|
+
"means"
|
|
86
|
+
]) if (!isWord(property[field])) return `${at} (${property.name}) has no ${field}`;
|
|
87
|
+
if (property.values !== void 0 && !isWordList(property.values)) return `${at} (${property.name}) values is not a list of words`;
|
|
88
|
+
if (property.value_form !== void 0 && !isWord(property.value_form)) return `${at} (${property.name}) value_form is empty`;
|
|
89
|
+
}
|
|
90
|
+
const marks = markFault(value.marks, "marks");
|
|
91
|
+
if (marks) return marks;
|
|
92
|
+
const flags = markFault(value.flags, "flags");
|
|
93
|
+
if (flags) return flags;
|
|
94
|
+
if (!isWordList(value.sources)) return "sources is not a list of words";
|
|
95
|
+
return wordsFault(value.words);
|
|
96
|
+
}
|
|
97
|
+
/** The fault of the words list, or null. A file with no words is refused, so the packaged copy answers. */
|
|
98
|
+
function wordsFault(list) {
|
|
99
|
+
if (!Array.isArray(list) || list.length === 0) return "words is not a list";
|
|
100
|
+
for (const [index, entry] of list.entries()) {
|
|
101
|
+
const at = `words[${index}]`;
|
|
102
|
+
if (!isRecord(entry)) return `${at} is not an object`;
|
|
103
|
+
if (!isWord(entry.word)) return `${at} has no word`;
|
|
104
|
+
if (!isWord(entry.question)) return `${at} (${entry.word}) has no question`;
|
|
105
|
+
if (!ADDRESS_CARD_LEVELS.includes(entry.level)) return `${at} (${entry.word}) level is not one of ${ADDRESS_CARD_LEVELS.join(", ")}`;
|
|
106
|
+
if (!isWord(entry.plain)) return `${at} (${entry.word}) has no plain sentence`;
|
|
107
|
+
if (entry.value !== void 0 && !isWord(entry.value)) return `${at} (${entry.word}) value is empty`;
|
|
108
|
+
if (entry.standing !== void 0 && !isWord(entry.standing)) return `${at} (${entry.word}) standing is empty`;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/** The version as a number, so a newer packaged copy wins; 0 when it is not a number. */
|
|
113
|
+
function addressCardVersion(document) {
|
|
114
|
+
const version = Number(document.version);
|
|
115
|
+
return Number.isFinite(version) ? version : 0;
|
|
116
|
+
}
|
|
117
|
+
/** The URL of the served copy: the public file on main, or the override. */
|
|
118
|
+
function addressCardUrl(env = process.env) {
|
|
119
|
+
return env[ADDRESS_CARD_URL_ENV]?.trim() || ADDRESS_CARD_PUBLIC_URL;
|
|
120
|
+
}
|
|
121
|
+
function addressCardCachePath() {
|
|
122
|
+
return path.join(chainInsightsHome(), "cache", "address-card.json");
|
|
123
|
+
}
|
|
124
|
+
/** registry/address-card.json of the installed package: next to dist/, or the repository root when run from source. */
|
|
125
|
+
function packagedAddressCardPath() {
|
|
126
|
+
const candidates = [fileURLToPath(new URL("../registry/address-card.json", import.meta.url)), fileURLToPath(new URL("../../registry/address-card.json", import.meta.url))];
|
|
127
|
+
return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];
|
|
128
|
+
}
|
|
129
|
+
/** The packaged copy, or null when the package carries none. A packaged copy that fails the rules throws. */
|
|
130
|
+
function readPackagedAddressCard(file = packagedAddressCardPath()) {
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const fault = addressCardFault(parsed);
|
|
138
|
+
if (fault) throw new Error(`the packaged ${ADDRESS_CARD_FILE} is malformed: ${fault}`);
|
|
139
|
+
return parsed;
|
|
140
|
+
}
|
|
141
|
+
const defaultLog = (line) => {
|
|
142
|
+
process.stderr.write(`[chain-insights] address-card: ${line}\n`);
|
|
143
|
+
};
|
|
144
|
+
/** The card dictionary: the fresh cache, else the public file, else the stale cache, else the packaged copy. Null when there is none. */
|
|
145
|
+
async function loadAddressCard(options = {}) {
|
|
146
|
+
return loadPublicFile({
|
|
147
|
+
url: addressCardUrl(options.env),
|
|
148
|
+
cachePath: addressCardCachePath(),
|
|
149
|
+
fault: addressCardFault,
|
|
150
|
+
packaged: readPackagedAddressCard(options.packagedFile),
|
|
151
|
+
version: addressCardVersion,
|
|
152
|
+
log: options.log ?? defaultLog
|
|
153
|
+
}, options);
|
|
154
|
+
}
|
|
155
|
+
function addressCardSection(loaded) {
|
|
156
|
+
const { document } = loaded;
|
|
157
|
+
return {
|
|
158
|
+
file: ADDRESS_CARD_FILE,
|
|
159
|
+
version: document.version,
|
|
160
|
+
source: loaded.source,
|
|
161
|
+
rule: document.rule,
|
|
162
|
+
properties: document.properties,
|
|
163
|
+
marks: document.marks,
|
|
164
|
+
flags: document.flags
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function propertyLine(property) {
|
|
168
|
+
const entries = property.value_form ? `, entries ${property.value_form}` : "";
|
|
169
|
+
const values = property.values?.length ? ` Values: ${property.values.join(", ")}.` : "";
|
|
170
|
+
return `- ${property.name} (${property.type}, question ${property.question}${entries}): ${property.means}${values}`;
|
|
171
|
+
}
|
|
172
|
+
function markLine(mark) {
|
|
173
|
+
return `- ${mark.name} (question ${mark.question}): ${mark.words.join(", ")}`;
|
|
174
|
+
}
|
|
175
|
+
/** The card as the model and the terminal read it. */
|
|
176
|
+
function formatAddressCardLines(card) {
|
|
177
|
+
return [
|
|
178
|
+
`Address card, on every :Address node (${card.file}, version ${card.version}, ${card.source})`,
|
|
179
|
+
`Rule: ${card.rule}`,
|
|
180
|
+
"Card properties:",
|
|
181
|
+
...card.properties.map(propertyLine),
|
|
182
|
+
"Marks, the node labels a card word gives:",
|
|
183
|
+
...card.marks.map(markLine),
|
|
184
|
+
"Flags, true when the card holds one of the words:",
|
|
185
|
+
...card.flags.map(markLine)
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
export { loadAddressCard as a, formatAddressCardLines as i, addressCardSection as n, address_card_exports as r, ADDRESS_CARD_RULE as t };
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=address-card-LYaT5yz0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-card-LYaT5yz0.mjs","names":[],"sources":["../src/mcp/address-card.ts"],"sourcesContent":["/**\n * The address card dictionary, as meta_schema serves it.\n *\n * Every :Address node of the graph carries one resolved card: what the address\n * is (identity), which wallet it is (address_roles), what one week of counts\n * shows (behaviour), what it did or what was done to it (evidence), the risky\n * patterns that convict nobody (judgements), its risk, and who gave the\n * answers (sources). registry/address-card.json names each card property with\n * its question, its meaning and its closed values, each mark and each flag with\n * the words that give it, each card word with its question, its level and its\n * plain sentence (words), and the one rule an agent follows. The file is\n * generated from the label vocabulary and never edited by hand.\n *\n * The proxy reads it through the shared public file loader\n * (src/mcp/public-file.ts):\n *\n * cached ~/.chain-insights/cache/address-card.json, younger than one hour\n * fetched https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json\n * packaged registry/address-card.json of the installed package\n *\n * A malformed file is refused with one line naming the fault, and the packaged\n * copy answers. A dictionary merged on main reaches every running proxy within\n * the hour, with no release.\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { chainInsightsHome } from './cache-location.js'\nimport { loadPublicFile, type LoadedPublicFile, type PublicFileOptions } from './public-file.js'\n\nexport const ADDRESS_CARD_URL_ENV = 'CHAIN_INSIGHTS_ADDRESS_CARD_URL'\nexport const ADDRESS_CARD_PUBLIC_URL =\n 'https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/address-card.json'\nexport const ADDRESS_CARD_FILE = 'registry/address-card.json'\n\n/**\n * The `rule` of registry/address-card.json, word for word. It is the one text\n * of the card every host reads: the meta_schema description carries it.\n * tests/graph-schema-address-card.test.ts holds it to the file.\n */\nexport const ADDRESS_CARD_RULE =\n 'Read the address card (identity, address_roles, behaviour, evidence, judgements, risk), not the labels list.'\n\n/** One property of the card on an :Address node. */\nexport interface AddressCardProperty {\n name: string\n /** `string`, `integer` or `list<string>`. */\n type: string\n /** The question it answers: identity, role, behaviour, evidence, judgement, or card for the card's own fields. */\n question: string\n means: string\n /** The closed values, when the property has them. */\n values?: string[]\n /** How one entry is written when it carries a value: `word:VALUE`. */\n value_form?: string\n}\n\n/** A mark (a node label) or a flag (a true-or-false property) and the card words that give it. */\nexport interface AddressCardMark {\n name: string\n question: string\n words: string[]\n}\n\n/** The levels a card word may carry, lowest first. */\nexport const ADDRESS_CARD_LEVELS = ['none', 'low', 'medium', 'high', 'critical'] as const\nexport type AddressCardLevel = (typeof ADDRESS_CARD_LEVELS)[number]\n\n/**\n * One word of the card dictionary: the word, the question it answers, its\n * level, and the one fixed sentence that says what it means. An item with a\n * value is the meaning of `word:VALUE`; the item with none is every other\n * value of the word.\n */\nexport interface AddressCardWord {\n word: string\n question: string\n level: AddressCardLevel\n value?: string\n /** proven or reported, when the word says how it is known. */\n standing?: string\n plain: string\n}\n\nexport interface AddressCardDocument {\n generated_from?: string\n version: string\n rule: string\n properties: AddressCardProperty[]\n marks: AddressCardMark[]\n flags: AddressCardMark[]\n sources: string[]\n words: AddressCardWord[]\n}\n\nexport type LoadedAddressCard = LoadedPublicFile<AddressCardDocument>\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value)\n}\n\nconst isWord = (value: unknown): value is string =>\n typeof value === 'string' && value.trim() !== ''\n\nconst isWordList = (value: unknown): value is string[] =>\n Array.isArray(value) && value.length > 0 && value.every(isWord)\n\nfunction markFault(list: unknown, field: 'marks' | 'flags'): string | null {\n if (!Array.isArray(list)) return `${field} is not a list`\n const names = new Set<string>()\n for (const [index, entry] of list.entries()) {\n const at = `${field}[${index}]`\n if (!isRecord(entry)) return `${at} is not an object`\n if (!isWord(entry.name)) return `${at} has no name`\n if (names.has(entry.name)) return `${at} ${entry.name} is listed twice`\n names.add(entry.name)\n if (!isWord(entry.question)) return `${at} (${entry.name}) has no question`\n if (!isWordList(entry.words)) return `${at} (${entry.name}) words is not a list of words`\n }\n return null\n}\n\n/** The fault of a card dictionary, or null when it is valid. */\nexport function addressCardFault(value: unknown): string | null {\n if (!isRecord(value)) return 'the file is not a JSON object'\n if (!isWord(value.version)) return 'version is missing'\n if (!isWord(value.rule)) return 'rule is missing'\n if (!Array.isArray(value.properties) || value.properties.length === 0) {\n return 'properties is empty'\n }\n const names = new Set<string>()\n for (const [index, property] of value.properties.entries()) {\n const at = `properties[${index}]`\n if (!isRecord(property)) return `${at} is not an object`\n if (typeof property.name !== 'string' || !/^[a-z][a-z0-9_]*$/.test(property.name)) {\n return `${at} name is not a property name: ${String(property.name)}`\n }\n if (names.has(property.name)) return `${at} ${property.name} is listed twice`\n names.add(property.name)\n for (const field of ['type', 'question', 'means'] as const) {\n if (!isWord(property[field])) return `${at} (${property.name}) has no ${field}`\n }\n if (property.values !== undefined && !isWordList(property.values)) {\n return `${at} (${property.name}) values is not a list of words`\n }\n if (property.value_form !== undefined && !isWord(property.value_form)) {\n return `${at} (${property.name}) value_form is empty`\n }\n }\n const marks = markFault(value.marks, 'marks')\n if (marks) return marks\n const flags = markFault(value.flags, 'flags')\n if (flags) return flags\n if (!isWordList(value.sources)) return 'sources is not a list of words'\n return wordsFault(value.words)\n}\n\n/** The fault of the words list, or null. A file with no words is refused, so the packaged copy answers. */\nfunction wordsFault(list: unknown): string | null {\n if (!Array.isArray(list) || list.length === 0) return 'words is not a list'\n for (const [index, entry] of list.entries()) {\n const at = `words[${index}]`\n if (!isRecord(entry)) return `${at} is not an object`\n if (!isWord(entry.word)) return `${at} has no word`\n if (!isWord(entry.question)) return `${at} (${entry.word}) has no question`\n if (!(ADDRESS_CARD_LEVELS as readonly unknown[]).includes(entry.level)) {\n return `${at} (${entry.word}) level is not one of ${ADDRESS_CARD_LEVELS.join(', ')}`\n }\n if (!isWord(entry.plain)) return `${at} (${entry.word}) has no plain sentence`\n if (entry.value !== undefined && !isWord(entry.value)) return `${at} (${entry.word}) value is empty`\n if (entry.standing !== undefined && !isWord(entry.standing)) {\n return `${at} (${entry.word}) standing is empty`\n }\n }\n return null\n}\n\n/** The version as a number, so a newer packaged copy wins; 0 when it is not a number. */\nexport function addressCardVersion(document: AddressCardDocument): number {\n const version = Number(document.version)\n return Number.isFinite(version) ? version : 0\n}\n\n/** The URL of the served copy: the public file on main, or the override. */\nexport function addressCardUrl(env: NodeJS.ProcessEnv = process.env): string {\n return env[ADDRESS_CARD_URL_ENV]?.trim() || ADDRESS_CARD_PUBLIC_URL\n}\n\nexport function addressCardCachePath(): string {\n return path.join(chainInsightsHome(), 'cache', 'address-card.json')\n}\n\n/** registry/address-card.json of the installed package: next to dist/, or the repository root when run from source. */\nexport function packagedAddressCardPath(): string {\n const candidates = [\n fileURLToPath(new URL('../registry/address-card.json', import.meta.url)),\n fileURLToPath(new URL('../../registry/address-card.json', import.meta.url)),\n ]\n return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0]!\n}\n\n/** The packaged copy, or null when the package carries none. A packaged copy that fails the rules throws. */\nexport function readPackagedAddressCard(\n file: string = packagedAddressCardPath()\n): AddressCardDocument | null {\n let parsed: unknown\n try {\n parsed = JSON.parse(readFileSync(file, 'utf8'))\n } catch {\n return null\n }\n const fault = addressCardFault(parsed)\n if (fault) throw new Error(`the packaged ${ADDRESS_CARD_FILE} is malformed: ${fault}`)\n return parsed as AddressCardDocument\n}\n\nexport interface LoadAddressCardOptions extends PublicFileOptions {\n env?: NodeJS.ProcessEnv\n log?: (line: string) => void\n /** The packaged file, for a test. */\n packagedFile?: string\n}\n\nconst defaultLog = (line: string): void => {\n process.stderr.write(`[chain-insights] address-card: ${line}\\n`)\n}\n\n/** The card dictionary: the fresh cache, else the public file, else the stale cache, else the packaged copy. Null when there is none. */\nexport async function loadAddressCard(\n options: LoadAddressCardOptions = {}\n): Promise<LoadedAddressCard | null> {\n return loadPublicFile<AddressCardDocument>(\n {\n url: addressCardUrl(options.env),\n cachePath: addressCardCachePath(),\n fault: addressCardFault,\n packaged: readPackagedAddressCard(options.packagedFile),\n version: addressCardVersion,\n log: options.log ?? defaultLog,\n },\n options\n )\n}\n\n// ─── The answer of meta_schema ────────────────────────────────────────────────\n\n/** The card as meta_schema serves it: the file's rows, unchanged, and where they came from. */\nexport interface AddressCardSection {\n file: typeof ADDRESS_CARD_FILE\n version: string\n source: LoadedAddressCard['source']\n rule: string\n properties: AddressCardProperty[]\n marks: AddressCardMark[]\n flags: AddressCardMark[]\n}\n\nexport function addressCardSection(loaded: LoadedAddressCard): AddressCardSection {\n const { document } = loaded\n return {\n file: ADDRESS_CARD_FILE,\n version: document.version,\n source: loaded.source,\n rule: document.rule,\n properties: document.properties,\n marks: document.marks,\n flags: document.flags,\n }\n}\n\nfunction propertyLine(property: AddressCardProperty): string {\n const entries = property.value_form ? `, entries ${property.value_form}` : ''\n const values = property.values?.length ? ` Values: ${property.values.join(', ')}.` : ''\n return `- ${property.name} (${property.type}, question ${property.question}${entries}): ${property.means}${values}`\n}\n\nfunction markLine(mark: AddressCardMark): string {\n return `- ${mark.name} (question ${mark.question}): ${mark.words.join(', ')}`\n}\n\n/** The card as the model and the terminal read it. */\nexport function formatAddressCardLines(card: AddressCardSection): string[] {\n return [\n `Address card, on every :Address node (${card.file}, version ${card.version}, ${card.source})`,\n `Rule: ${card.rule}`,\n 'Card properties:',\n ...card.properties.map(propertyLine),\n 'Marks, the node labels a card word gives:',\n ...card.marks.map(markLine),\n 'Flags, true when the card holds one of the words:',\n ...card.flags.map(markLine),\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,uBAAuB;AACpC,MAAa,0BACX;AACF,MAAa,oBAAoB;;;;;;AAOjC,MAAa,oBACX;;AAwBF,MAAa,sBAAsB;CAAC;CAAQ;CAAO;CAAU;CAAQ;AAAU;AAgC/E,SAAS,SAAS,OAAkD;CAClE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE;AAEA,MAAM,UAAU,UACd,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM;AAEhD,MAAM,cAAc,UAClB,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,MAAM,MAAM,MAAM;AAEhE,SAAS,UAAU,MAAe,OAAyC;CACzE,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO,GAAG,MAAM;CAC1C,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,QAAQ,GAAG;EAC3C,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM;EAC7B,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO,GAAG,GAAG;EACnC,IAAI,CAAC,OAAO,MAAM,IAAI,GAAG,OAAO,GAAG,GAAG;EACtC,IAAI,MAAM,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,GAAG,GAAG,M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