@fangorn-network/sdk 2026.11.4-dev → 2026.11.4

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 CHANGED
@@ -52,7 +52,8 @@ for await (const change of fangorn.subscribe({
52
52
  npm i -g @fangorn-network/sdk
53
53
  fangorn init # wallet key, storage → ~/.fangorn/config.json
54
54
  fangorn repo init rusty-anchor # create on chain, track in ./.fangorn
55
- fangorn commit records.json # local commit (IPFS only)
55
+ fangorn add . # stage files: csv/json rows → records, text files → one record each
56
+ fangorn commit # local commit (IPFS only)
56
57
  fangorn push # move the on-chain head
57
58
  fangorn subscribe --owner 0x... rusty-anchor # stream diffs as JSON lines
58
59
  ```
package/lib/cli/cli.js CHANGED
@@ -3,6 +3,7 @@ import getNetwork, { nonBlank } from "../config.js";
3
3
  import { agentCardUrl, parseAgentId } from "../erc8004.js";
4
4
  import { Fangorn } from "../fangorn.js";
5
5
  import { sealRecords } from "./sell.js";
6
+ import { fileToRecords, walk } from "./stage.js";
6
7
  import { handleCancel } from "./index.js";
7
8
  import { createPublicClient, formatEther, http, isAddress, parseUnits } from "viem";
8
9
  import { privateKeyToAccount } from "viem/accounts";
@@ -143,6 +144,20 @@ var LocalRepo = class LocalRepo {
143
144
  this.state.head = cid;
144
145
  this.save();
145
146
  }
147
+ root() {
148
+ return this.dir;
149
+ }
150
+ /** The staging area: what the next `fangorn commit` (no file) will commit. */
151
+ staged() {
152
+ const p = join(this.dir, ".fangorn", "index.json");
153
+ return existsSync(p) ? JSON.parse(readFileSync(p, "utf-8")) : {
154
+ records: [],
155
+ deletes: []
156
+ };
157
+ }
158
+ setStaged(s) {
159
+ writeFileSync(join(this.dir, ".fangorn", "index.json"), JSON.stringify(s, null, 2), "utf-8");
160
+ }
146
161
  };
147
162
  const program = new Command();
148
163
  program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
@@ -266,14 +281,53 @@ program.command("repo").description("Repository operations").command("init").des
266
281
  process.exit(1);
267
282
  }
268
283
  });
269
- program.command("commit").description("Put/delete a namespace's records in a new local commit (does not push)").argument("<file>", "JSON file: {\"records\":[{\"id\",\"type\",\"payload\"}],\"deletes\":[\"id\"]}").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").option("--paid <fields>", "Comma-separated payload fields to sell: sealed (field-v1) and priced with signed terms").option("--price <usdc>", "Price of each paid record, in USDC (e.g. 0.01)").option("--share <percent>", "Share of each sale paid to the referrer (Fangorn's treasury, via its relay)", "5").option("--deadline-days <days>", "Days the signed terms stay buyable", "365").option("--key-server <url>", "Key server a new deposit is sealed to (an existing deposit keeps its own)", "https://keys-test.fangorn.network").action(async (file, options) => {
284
+ program.command("add").description("Stage files as records: csv/jsonl/json arrays → a record per row, other text → one record per file").argument("<paths...>", "Files or directories (dot entries skipped)").option("--type <type>", "Record type (default: file name, or \"file\" for text)").option("--id-column <col>", "Column/field holding the record id", "id").action((paths, options) => {
270
285
  try {
271
- if (!existsSync(file)) throw new Error(`file not found: ${file}`);
272
- const data = JSON.parse(readFileSync(file, "utf-8"));
286
+ const repo = LocalRepo.open();
287
+ const staged = repo.staged();
288
+ let n = 0;
289
+ for (const p of paths) for (const rel of walk(repo.root(), join(process.cwd(), p))) {
290
+ const got = fileToRecords(repo.root(), rel, options);
291
+ if (!got) {
292
+ console.warn(`skipped (binary): ${rel}`);
293
+ continue;
294
+ }
295
+ const ids = new Set(got.records.map((r) => r.id));
296
+ staged.records = staged.records.filter((r) => !r.id || !ids.has(r.id)).concat(got.records);
297
+ staged.deletes = staged.deletes.filter((d) => !ids.has(d)).concat(got.deletes);
298
+ n += got.records.length + got.deletes.length;
299
+ console.log(`added ${rel} (${got.records.length.toString()} record(s))`);
300
+ }
301
+ repo.setStaged(staged);
302
+ console.log(`${n.toString()} change(s) staged. Run \`fangorn commit\`.`);
303
+ process.exit(0);
304
+ } catch (err) {
305
+ console.error("Failed:", err.message);
306
+ process.exit(1);
307
+ }
308
+ });
309
+ program.command("rm").description("Stage record deletes (and drop them from the staging area)").argument("<ids...>", "Record ids").action((ids) => {
310
+ try {
311
+ const repo = LocalRepo.open();
312
+ const staged = repo.staged();
313
+ staged.records = staged.records.filter((r) => !r.id || !ids.includes(r.id));
314
+ staged.deletes = [...new Set([...staged.deletes, ...ids])];
315
+ repo.setStaged(staged);
316
+ console.log(`${ids.length.toString()} delete(s) staged.`);
317
+ process.exit(0);
318
+ } catch (err) {
319
+ console.error("Failed:", err.message);
320
+ process.exit(1);
321
+ }
322
+ });
323
+ program.command("commit").description("Put/delete a namespace's records in a new local commit (does not push)").argument("[file]", "JSON file: {\"records\":[{\"id\",\"type\",\"payload\"}],\"deletes\":[\"id\"]} (default: the staging area, see `fangorn add`)").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").option("--paid <fields>", "Comma-separated payload fields to sell: sealed (field-v1) and priced with signed terms").option("--price <usdc>", "Price of each paid record, in USDC (e.g. 0.01)").option("--share <percent>", "Share of each sale paid to the referrer (Fangorn takes none by default)", "0").option("--deadline-days <days>", "Days the signed terms stay buyable", "365").option("--key-server <url>", "Key server a new deposit is sealed to (an existing deposit keeps its own)", "https://keys-test.fangorn.network").action(async (file, options) => {
324
+ try {
325
+ const repo = LocalRepo.open();
326
+ if (file && !existsSync(file)) throw new Error(`file not found: ${file}`);
327
+ const data = file ? JSON.parse(readFileSync(file, "utf-8")) : repo.staged();
273
328
  let records = data.records ?? [];
274
329
  const deletes = data.deletes ?? [];
275
- if (!Array.isArray(records) || !Array.isArray(deletes) || records.length + deletes.length === 0) throw new Error(`${file} must contain a non-empty "records" or "deletes" array`);
276
- const repo = LocalRepo.open();
330
+ if (!Array.isArray(records) || !Array.isArray(deletes) || records.length + deletes.length === 0) throw new Error(file ? `${file} must contain a non-empty "records" or "deletes" array` : "nothing staged — run `fangorn add <paths>` first");
277
331
  const fangorn = getFangorn();
278
332
  const parent = repo.head() ?? void 0;
279
333
  if (options.paid) {
@@ -301,6 +355,10 @@ program.command("commit").description("Put/delete a namespace's records in a new
301
355
  });
302
356
  s.stop();
303
357
  repo.setHead(result.commitCid);
358
+ if (!file) repo.setStaged({
359
+ records: [],
360
+ deletes: []
361
+ });
304
362
  console.log(`Commit: ${result.commitCid}`);
305
363
  console.log(`Parent: ${result.parent ?? "(root)"}`);
306
364
  console.log(`Tree: ${result.root}`);
@@ -342,6 +400,8 @@ program.command("status").description("Compare the local tip with the on-chain t
342
400
  console.log(`Local HEAD: ${localHead ?? "(none)"}`);
343
401
  console.log(`On-chain tip: ${onChainTip ?? "(none)"}`);
344
402
  console.log(`Status: ${state}`);
403
+ const staged = repo.staged();
404
+ console.log(`Staged: ${staged.records.length.toString()} put(s) / ${staged.deletes.length.toString()} delete(s)`);
345
405
  process.exit(0);
346
406
  } catch (err) {
347
407
  console.error("Failed:", err.message);
@@ -0,0 +1,19 @@
1
+ import { RecordInput } from "../engine/index.js";
2
+
3
+ //#region src/cli/stage.d.ts
4
+ interface Staged {
5
+ records: RecordInput[];
6
+ deletes: string[];
7
+ }
8
+ interface StageOpts {
9
+ type?: string;
10
+ idColumn?: string;
11
+ }
12
+ /** RFC 4180 CSV → one object per row, keyed by the header. */
13
+ declare function parseCsv(text: string): Record<string, string>[];
14
+ /** Files under `path` (file or dir) as root-relative posix paths; dot entries skipped. */
15
+ declare function walk(root: string, path: string): string[];
16
+ /** One file → records. null for binary files (no text to stage). */
17
+ declare function fileToRecords(root: string, rel: string, opts: StageOpts): Staged | null;
18
+ //#endregion
19
+ export { StageOpts, Staged, fileToRecords, parseCsv, walk };
@@ -0,0 +1,94 @@
1
+ import { readFileSync, readdirSync, statSync } from "fs";
2
+ import { basename, extname, join, relative, sep } from "path";
3
+
4
+ //#region src/cli/stage.ts
5
+ /** RFC 4180 CSV → one object per row, keyed by the header. */
6
+ function parseCsv(text) {
7
+ const rows = [];
8
+ let row = [];
9
+ let field = "";
10
+ let quoted = false;
11
+ for (let i = 0; i < text.length; i++) {
12
+ const c = text[i];
13
+ if (quoted) if (c === "\"" && text[i + 1] === "\"") field += text[++i];
14
+ else if (c === "\"") quoted = false;
15
+ else field += c;
16
+ else if (c === "\"") quoted = true;
17
+ else if (c === ",") {
18
+ row.push(field);
19
+ field = "";
20
+ } else if (c === "\n" || c === "\r") {
21
+ if (c === "\r" && text[i + 1] === "\n") i++;
22
+ row.push(field);
23
+ rows.push(row);
24
+ row = [];
25
+ field = "";
26
+ } else field += c;
27
+ }
28
+ if (field || row.length) rows.push([...row, field]);
29
+ const [header = [], ...body] = rows;
30
+ return body.map((r) => Object.fromEntries(header.map((h, i) => [h, r[i] ?? ""])));
31
+ }
32
+ const safeId = (s) => s.replace(/[^\x21-\x7e]/g, "_");
33
+ /** Files under `path` (file or dir) as root-relative posix paths; dot entries skipped. */
34
+ function walk(root, path) {
35
+ const rel = (p) => relative(root, p).split(sep).join("/");
36
+ if (!statSync(path).isDirectory()) return [rel(path)];
37
+ return readdirSync(path, {
38
+ recursive: true,
39
+ withFileTypes: true
40
+ }).filter((e) => e.isFile()).map((e) => rel(join(e.parentPath, e.name))).filter((p) => !p.split("/").some((s) => s.startsWith(".")));
41
+ }
42
+ /** One file → records. null for binary files (no text to stage). */
43
+ function fileToRecords(root, rel, opts) {
44
+ const bytes = readFileSync(join(root, rel));
45
+ if (bytes.subarray(0, 8192).includes(0)) return null;
46
+ const text = bytes.toString("utf-8");
47
+ const ext = extname(rel).toLowerCase();
48
+ const type = opts.type ?? basename(rel, extname(rel));
49
+ const idCol = opts.idColumn ?? "id";
50
+ const many = (rows) => ({
51
+ records: rows.map((payload, i) => {
52
+ const id = payload[idCol];
53
+ return {
54
+ id: safeId((typeof id === "string" || typeof id === "number") && id !== "" ? String(id) : `${rel}#${(i + 1).toString()}`),
55
+ type,
56
+ payload
57
+ };
58
+ }),
59
+ deletes: []
60
+ });
61
+ if (ext === ".csv") return many(parseCsv(text));
62
+ if (ext === ".jsonl" || ext === ".ndjson") return many(text.split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l)));
63
+ if (ext === ".json") {
64
+ const data = JSON.parse(text);
65
+ if (Array.isArray(data)) return many(data);
66
+ const obj = data;
67
+ if (Array.isArray(obj.records) || Array.isArray(obj.deletes)) return {
68
+ records: obj.records ?? [],
69
+ deletes: obj.deletes ?? []
70
+ };
71
+ return {
72
+ records: [{
73
+ id: safeId(rel),
74
+ type,
75
+ payload: data
76
+ }],
77
+ deletes: []
78
+ };
79
+ }
80
+ return {
81
+ records: [{
82
+ id: safeId(rel),
83
+ type: opts.type ?? "file",
84
+ payload: {
85
+ path: rel,
86
+ text
87
+ }
88
+ }],
89
+ deletes: []
90
+ };
91
+ }
92
+
93
+ //#endregion
94
+ export { fileToRecords, parseCsv, walk };
@@ -7308,6 +7308,7 @@ declare function chainNetwork(): Promise<{
7308
7308
  }, undefined, chainOverride, calls>) => Promise<{
7309
7309
  id: string;
7310
7310
  chainId: number;
7311
+ version: string;
7311
7312
  atomic: boolean;
7312
7313
  capabilities?: {
7313
7314
  [key: string]: any;
@@ -7315,7 +7316,6 @@ declare function chainNetwork(): Promise<{
7315
7316
  [x: string]: any;
7316
7317
  } | undefined;
7317
7318
  receipts?: viem119.WalletCallReceipt<bigint, "success" | "reverted">[] | undefined;
7318
- version: string;
7319
7319
  statusCode: number;
7320
7320
  status: "pending" | "success" | "failure" | undefined;
7321
7321
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.11.04-dev",
3
+ "version": "2026.11.04",
4
4
  "description": "decentralized, verifiable and platformless content management framework",
5
5
  "repository": {
6
6
  "type": "git",