ainize 0.1.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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +225 -0
  3. package/dist/bin.d.ts +10 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +711 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/client.d.ts +38 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +164 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/commands/auth.d.ts +30 -0
  12. package/dist/commands/auth.d.ts.map +1 -0
  13. package/dist/commands/auth.js +216 -0
  14. package/dist/commands/auth.js.map +1 -0
  15. package/dist/commands/branch.d.ts +326 -0
  16. package/dist/commands/branch.d.ts.map +1 -0
  17. package/dist/commands/branch.js +467 -0
  18. package/dist/commands/branch.js.map +1 -0
  19. package/dist/commands/chain.d.ts +43 -0
  20. package/dist/commands/chain.d.ts.map +1 -0
  21. package/dist/commands/chain.js +224 -0
  22. package/dist/commands/chain.js.map +1 -0
  23. package/dist/commands/chat.d.ts +157 -0
  24. package/dist/commands/chat.d.ts.map +1 -0
  25. package/dist/commands/chat.js +395 -0
  26. package/dist/commands/chat.js.map +1 -0
  27. package/dist/commands/dataset.d.ts +51 -0
  28. package/dist/commands/dataset.d.ts.map +1 -0
  29. package/dist/commands/dataset.js +157 -0
  30. package/dist/commands/dataset.js.map +1 -0
  31. package/dist/commands/drive.d.ts +32 -0
  32. package/dist/commands/drive.d.ts.map +1 -0
  33. package/dist/commands/drive.js +68 -0
  34. package/dist/commands/drive.js.map +1 -0
  35. package/dist/commands/huggingface-dataset.d.ts +63 -0
  36. package/dist/commands/huggingface-dataset.d.ts.map +1 -0
  37. package/dist/commands/huggingface-dataset.js +254 -0
  38. package/dist/commands/huggingface-dataset.js.map +1 -0
  39. package/dist/commands/init.d.ts +107 -0
  40. package/dist/commands/init.d.ts.map +1 -0
  41. package/dist/commands/init.js +538 -0
  42. package/dist/commands/init.js.map +1 -0
  43. package/dist/commands/ledger.d.ts +43 -0
  44. package/dist/commands/ledger.d.ts.map +1 -0
  45. package/dist/commands/ledger.js +125 -0
  46. package/dist/commands/ledger.js.map +1 -0
  47. package/dist/commands/node.d.ts +250 -0
  48. package/dist/commands/node.d.ts.map +1 -0
  49. package/dist/commands/node.js +651 -0
  50. package/dist/commands/node.js.map +1 -0
  51. package/dist/commands/patch.d.ts +852 -0
  52. package/dist/commands/patch.d.ts.map +1 -0
  53. package/dist/commands/patch.js +1527 -0
  54. package/dist/commands/patch.js.map +1 -0
  55. package/dist/commands/peers.d.ts +86 -0
  56. package/dist/commands/peers.d.ts.map +1 -0
  57. package/dist/commands/peers.js +143 -0
  58. package/dist/commands/peers.js.map +1 -0
  59. package/dist/commands/teach-dataset.d.ts +381 -0
  60. package/dist/commands/teach-dataset.d.ts.map +1 -0
  61. package/dist/commands/teach-dataset.js +780 -0
  62. package/dist/commands/teach-dataset.js.map +1 -0
  63. package/dist/commands/teach.d.ts +351 -0
  64. package/dist/commands/teach.d.ts.map +1 -0
  65. package/dist/commands/teach.js +435 -0
  66. package/dist/commands/teach.js.map +1 -0
  67. package/dist/context.d.ts +55 -0
  68. package/dist/context.d.ts.map +1 -0
  69. package/dist/context.js +102 -0
  70. package/dist/context.js.map +1 -0
  71. package/dist/ens.d.ts +50 -0
  72. package/dist/ens.d.ts.map +1 -0
  73. package/dist/ens.js +155 -0
  74. package/dist/ens.js.map +1 -0
  75. package/dist/help.d.ts +57 -0
  76. package/dist/help.d.ts.map +1 -0
  77. package/dist/help.js +227 -0
  78. package/dist/help.js.map +1 -0
  79. package/dist/index.d.ts +15 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +15 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/output.d.ts +104 -0
  84. package/dist/output.d.ts.map +1 -0
  85. package/dist/output.js +383 -0
  86. package/dist/output.js.map +1 -0
  87. package/dist/pid.d.ts +5 -0
  88. package/dist/pid.d.ts.map +1 -0
  89. package/dist/pid.js +25 -0
  90. package/dist/pid.js.map +1 -0
  91. package/dist/quiet.d.ts +2 -0
  92. package/dist/quiet.d.ts.map +1 -0
  93. package/dist/quiet.js +12 -0
  94. package/dist/quiet.js.map +1 -0
  95. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI Network (Common Computer Inc.)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # `ainize` — Ainize knowledge-marketplace CLI
2
+
3
+ **Ainize** = *AI + -ize*, "make it usable by AI". The first Ainize (2019–2020) turned any GitHub repo into a
4
+ running AI service — you *ainized your repo* with the `ainize` CLI. This Ainize turns **knowledge** into
5
+ something an AI model actually knows — you *ainize your knowledge*: pick verified knowledge, test it live
6
+ against the model, and load it into a running model in seconds. Creators get paid per sale, and the first
7
+ three letters — **AIN** — are the AI Network, the chain that records payments and permissions.
8
+
9
+ So the CLI is called `ainize` again, for the same reason the 2019 one was: it is the verb. `ngram` (the
10
+ historical name of this binary, after the n-gram memory the patches live in) is installed as an alias to the
11
+ same program; help text follows whichever name you typed.
12
+
13
+ One binary runs a **P2P knowledge-marketplace node** and talks to it: publish knowledge patches (learned
14
+ memory items of an LLM — technically rows of its n-gram conditional-memory table), have independent nodes
15
+ verify them against a benchmark, **test them live** (`ainize chat`), trade them with **automatic payment**
16
+ (HTTP 402 / x402 — wallet AIN or node credit, no sign-up), keep the shared truth on a **local record DAG** or
17
+ the **AI Network blockchain** (via ain-js), and mirror files & change history into an **aindrive** drive.
18
+
19
+ ```
20
+ npm install # in the repo root (workspaces)
21
+ npm run build # builds core → node → cli → agent → web
22
+ alias ainize="node $PWD/packages/cli/dist/bin.js" # or: npm link -w packages/cli → `ainize` and `ngram`
23
+ ```
24
+
25
+ Requirements: Node ≥ 24 (uses `node:sqlite`), python3 + numpy for synthetic demo patches, docker for the
26
+ optional local AIN chain, the reference runtime repo (`/mnt/newdata/qwen3.8`, vLLM + patch hook) for real
27
+ apply / verify / chat.
28
+
29
+ ## Quickstart (single node, local ledger)
30
+
31
+ ```
32
+ ainize init --name alice --port 3402 # creates ~/.ainize/config.json + an AIN keypair (node identity)
33
+ ainize seed # real Qwen3.8 patches (pixelplus-087600, krx-all-2761…) if the runtime repo is present
34
+ ainize start -d # background node; web console at http://localhost:3402
35
+ ainize login # sets the operator password on first use, stores a token in ~/.ainize/cli.json
36
+ ainize status
37
+ ainize patch ls
38
+ ainize chat --list # what can be tested live on this node
39
+ ainize chat pixelplus-087600 "종목코드 픽셀플러스"
40
+ ```
41
+
42
+ `AINIZE_HOME` selects the node directory (default `~/.ainize`); `--node <url>` targets another node's API;
43
+ `--json` prints machine-readable output for every command.
44
+
45
+ ## Hugging Face dataset → teach → marketplace
46
+
47
+ `ainize dataset <huggingface-url>` imports an **existing** Hugging Face dataset into the selected Ainize
48
+ node. It does not create a Hub repository, publish data to Hugging Face, train automatically, or make a
49
+ marketplace listing. The returned `dataset_id` feeds the normal teaching workflow:
50
+
51
+ ```sh
52
+ ainize init --name my-node --peer https://ainize.ai
53
+ ainize start -d && ainize login
54
+ ainize dataset https://huggingface.co/datasets/owner/questions --config default --split train --json
55
+ ainize teach train <dataset-id> --key-file /private/teaching-key --wait
56
+ ainize teach publish <job-id> --name "My knowledge" --consent-permanent --consent-rights
57
+ ainize use <published-knowledge-id>
58
+ ainize chat <published-knowledge-id> "Question"
59
+ ```
60
+
61
+ Replace placeholders with real values. Alternatively, use `ainize teach dataset upload questions.csv`
62
+ for a local file. Configure a compatible real serving/training runtime before training. Publication needs
63
+ your own rights/permanence consent, successful server-side checks and any operator review; it is not
64
+ automatic consent to republish third-party data. A reachable peer is not a listing: peers must use the same
65
+ ledger, reach the seller endpoint, and obtain independent verification quorum. Do not re-initialize a live
66
+ AIN node as `local` merely to match a peer; use a separate home or coordinate the deployment.
67
+
68
+ Supported source URLs are dataset repositories, `/viewer/<config>/<split>`, and
69
+ `/resolve/<revision>/<file>`. `dataset import <url>` is an explicit alias. Use `--columns` when the source
70
+ does not already have Ainize question/answer fields:
71
+
72
+ ```sh
73
+ ainize dataset https://huggingface.co/datasets/lhoestq/demo1 --split train \
74
+ --columns '{"prompt":"review","answer":"star"}'
75
+ ainize dataset https://huggingface.co/datasets/owner/questions --revision <commit-sha> \
76
+ --file data/train.jsonl
77
+ ```
78
+
79
+ Repository imports use the Dataset Viewer, validate its revision on every page, reject truncated/partial
80
+ responses, and import the whole selected split up to 10,000 rows. Larger splits require an explicit
81
+ `--limit` (optionally `--offset`); provenance reports that selection rather than claiming the whole dataset.
82
+ Multiple configurations require `--config`. If the viewer is not ready, use `--file` for an immutable
83
+ JSONL/JSON/CSV/TSV/TXT file; the file mode cannot be combined with split/config/row selection. Imports are
84
+ limited to 32 MiB. This adapter supports data convertible to Ainize teaching rows, not arbitrary image/audio
85
+ training. Normal node validation, row limits, PII checks and canonicalization still apply; inspect `report`
86
+ for rejected or modified rows.
87
+
88
+ `--train --wait` optionally queues and observes the same lesson, without publishing it. Restricted datasets
89
+ can use `--hf-token-file` pointing to a private (0600) file; gating terms must already be accepted. The token
90
+ is not forwarded to the Ainize node or recorded in provenance. Raw input, mapped upload bytes and source
91
+ metadata are saved privately under `AINIZE_HOME/hf-imports/`. Output distinguishes source revision and
92
+ hashes from the node's canonical dataset hash. Existing `ainize dataset get <knowledge-id>` is unchanged.
93
+
94
+ ## `ainize chat` — test knowledge live before you buy it
95
+
96
+ ChatMode asks the serving model the same question **before** and **after** a patch is loaded, and marks the
97
+ answer against the patch's benchmark (**정답 ✓ / 오답 ✗**). Loading is live — no restart — and the node
98
+ restores the model afterwards.
99
+
100
+ ```
101
+ ainize chat --list # testable patches + runtime state (model, live-apply hook, lock)
102
+ ainize chat pixelplus-087600 "종목코드 픽셀플러스" # one shot: base answer, patched answer, latency, load time, 정답 marker
103
+ ainize chat pixelplus-087600 # interactive session — transcript is kept, /quit to exit
104
+ ainize chat krx-all-2761 --mode patched --thinking --max-tokens 400
105
+ ```
106
+
107
+ | option | meaning |
108
+ |---|---|
109
+ | `--mode base\|patched\|compare` | model only / with the patch loaded / both (default `compare`) |
110
+ | `--thinking` | let the model think first; its reasoning is shown dimmed |
111
+ | `--max-tokens N` | answer length limit (1–1024, default 200) |
112
+ | `--system "…"` | system prompt prepended to the conversation |
113
+ | `--json` | raw `POST /api/chat` response (one JSON object per turn in a session) |
114
+
115
+ In a session `/mode base|patched|compare` switches mode, `/reset` clears the transcript, `/quit` exits
116
+ (Ctrl+D works too). The conversation continues from the *patched* answer. Public visitors get a free hourly
117
+ trial quota per node (shown after each answer); the node operator (after `ainize login`) is unlimited. A patch
118
+ is testable on a node that holds its body — the seller node, or yours after `ainize patch buy <id>`.
119
+
120
+ ## Multi-node demo (three terminals or `-d`)
121
+
122
+ Verification needs a quorum (default 2) of *independent* verifiers, so listing a patch needs peers:
123
+
124
+ ```
125
+ # node A — seller + verifier
126
+ ainize init --name alice --port 3402 && ainize seed && ainize start -d && ainize login
127
+
128
+ # node B — verifier
129
+ AINIZE_HOME=~/.ainize-b ainize init --name bob --port 3403 --roles verifier --peer http://localhost:3402
130
+ AINIZE_HOME=~/.ainize-b ainize start -d
131
+
132
+ # node C — verifier + serving
133
+ AINIZE_HOME=~/.ainize-c ainize init --name carol --port 3404 --roles verifier,serving --peer http://localhost:3402
134
+ AINIZE_HOME=~/.ainize-c ainize start -d
135
+
136
+ ainize nodes # gossip found bob & carol
137
+ ainize patch ls # ANNOUNCED → VERIFYING → LISTED as attestations arrive
138
+ ainize ledger graph # lineage tree (original authors share in derived-patch revenue)
139
+ AINIZE_HOME=~/.ainize-c ainize login && AINIZE_HOME=~/.ainize-c ainize patch buy law-kr-2026 # 402 → pay → download
140
+ AINIZE_HOME=~/.ainize-c ainize branch subscribe law/KR && ainize route jurisdiction=KR # gateway routing
141
+ ```
142
+
143
+ ## Commands
144
+
145
+ | group | commands |
146
+ |---|---|
147
+ | setup | `init`, `config show\|set <key> <value>`, `keys show [--reveal]` |
148
+ | lifecycle | `start [-d] [--peer …] [--port]`, `stop`, `status`, `logs [-f] [--patch id] [--kind k]`, `seed [--no-real] [--no-synthetic]`, `nodes` |
149
+ | auth | `login [--password]` (or `AINIZE_PASSWORD`), `logout` |
150
+ | peers | `peers ls\|add <url>\|rm <url>` |
151
+ | patches | `patch ls\|get\|publish\|announce\|verify\|challenge\|buy [--apply]\|apply\|remove\|conflicts\|records\|rm` |
152
+ | chat | `chat --list`, `chat <id> [prompt]` (`--mode`, `--thinking`, `--max-tokens`, `--system`) — live test before/after |
153
+ | ledger | `ledger ls [--kind]\|verify\|graph\|export <file>` |
154
+ | branches | `branch ls\|create <name> --context k=v --patch id\|add <name> <id>\|subscribe\|unsubscribe`, `route k=v…` |
155
+ | wallet | `wallet` — balance, sales, royalties |
156
+ | drive | `drive status\|up\|stop\|sync\|login` — aindrive files & change history |
157
+ | chain | `chain up\|down\|status\|fund <addr> [amount]\|setup` — local AIN blockchain |
158
+
159
+ ### Publishing a patch
160
+
161
+ ```
162
+ cat > bench.json <<'EOF'
163
+ { "schema": "krx-ticker-codes", "queries": 8, "format": ["template"], "collateral_bound_nat": 0.1,
164
+ "samples": [ { "prompt": "종목코드 픽셀플러스 ", "expect": "087600" } ] }
165
+ EOF
166
+ ainize patch publish /mnt/newdata/qwen3.8/results/train-fact/픽셀플러스.npz \
167
+ --name "픽셀플러스 087600" --model Qwen3.8-Flash-Next --benchmark bench.json --price 0.1 --topic finance/krx --announce
168
+ ainize patch records pixelplus-087600 # anchor → attest… on the ledger
169
+ ainize patch conflicts pixelplus-087600 # overlap / conflict check with other patches (address-set intersection)
170
+ ainize chat pixelplus-087600 "종목코드 픽셀플러스" # see it work
171
+ ```
172
+
173
+ The file must be readable by the node (same machine): the CLI passes its absolute path, the node computes
174
+ the sha256, memory-item count and address set. Inline benchmark `samples` are what verifiers execute on the
175
+ serving model (apply → free-generation scoring → restore, restart-aware) and what `chat` uses for the 정답
176
+ marker; without a runtime a verifier only attests integrity (`verified_on: hash-only`).
177
+
178
+ ## AIN blockchain ledger mode
179
+
180
+ ```
181
+ ainize chain up # docker: ainblockchain/ain-blockchain 1-node chain on :8081 (or deploy/docker-compose.ain.yml)
182
+ ainize init --ledger ain --ain-provider http://localhost:8081 --force
183
+ ainize chain setup # funds the node identity (local chain) and registers /apps/knowledge + market rules
184
+ ainize start -d && ainize login && ainize seed
185
+ ainize chain status
186
+ ainize chain fund <buyer-address> 500 # give an agent/second node AIN to pay with
187
+ ```
188
+
189
+ In this mode anchors are `ain.knowledge.explore()` entries (lineage = graph edges), attestations /
190
+ settlements / branches / nodes live under `/apps/knowledge/market/*` behind write rules evaluated by the
191
+ chain, and payments are AIN transfers whose tx hash is the payment proof. Prices are in **AIN** (the AI
192
+ Network token; this demo runs a local dev chain) or, on the local ledger, in node **CREDIT** (development
193
+ credit granted by the node — see `/api/info.initial_credit`).
194
+
195
+ ## aindrive — files & change history
196
+
197
+ Every node mirrors its market state as plain files under `<dataDir>/drive/` (`patches/<id>/manifest.json`,
198
+ `benchmark.json`, `CHANGELOG.md`, the `.npz` body, `branches/*.json`, `ledger/records.jsonl`). Serve that folder
199
+ with aindrive so humans and agents can browse/share/sell it and every edit is versioned in aindrive's
200
+ Willow store:
201
+
202
+ ```
203
+ ainize drive login # one-time browser pairing (prints the sign-in link); Ctrl+C after "serving"
204
+ ainize drive up # background aindrive agent for the folder
205
+ ainize drive status --files
206
+ ainize drive sync # rewrite the mirror from the current ledger state
207
+ ```
208
+
209
+ Editing `patches/<id>/benchmark.json` in the aindrive UI (or through `aindrive mcp`) while a patch is a
210
+ DRAFT updates the draft on the node. Set `AINDRIVE_SERVER` to use a self-hosted aindrive web server.
211
+
212
+ ## Agent demo
213
+
214
+ ```
215
+ npm run build -w packages/agent
216
+ node packages/agent/dist/bin.js run --market http://localhost:3402 # 픽셀플러스 087600 end-to-end
217
+ node packages/agent/dist/bin.js keys # its own identity; fund it for AIN mode
218
+ node packages/agent/dist/bin.js balance # credit left (initial grant read from /api/info)
219
+ ```
220
+
221
+ See `packages/agent/README.md`.
222
+
223
+ ## Exit codes
224
+
225
+ `0` ok · `1` command error · `2` node unreachable · `3` operator login required.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `ainize` — operate an Ainize knowledge-marketplace node.
4
+ *
5
+ * Ainize = AI + -ize, "make it usable by AI". The 2019 `ainize` CLI ainized GitHub repos into running AI
6
+ * services; this one ainizes *knowledge*: publish verified knowledge patches, test them live against the model
7
+ * (`chat`), trade them with automatic payment and load them into a running model in seconds.
8
+ */
9
+ import './quiet.js';
10
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,OAAO,YAAY,CAAC"}