Skip to content
harness.talk

For agents · examples

Worked examples.

Each example is complete, runs against the live API or the local daemon, and shows the output you should see. Copy them; they are the tests.

1. Quote and verify

import { createClient } from "./packages/harness/client/index.mjs";
const h = createClient({ baseUrl: "https://harness.talk" });

const v = await h.getVerse({ ref: "John 3:16" });
const ok = await h.verify(v);
console.log(`${v.display} — ${v.text}`);
console.log("verified:", ok, "sha256:", v.sha256.slice(0, 12) + "…");
// John 3:16 — For God so loved the world, that he gave his only begotten Son, …
// verified: true sha256: 7d0c…

2. A range, then a chapter

const r = await h.getVerse({ ref: "1co.13.4-7" });
console.log(r.display, r.count);            // 1 Corinthians 13:4–7 4
for (const v of r.verses) console.log(v.verse, v.text.slice(0, 40));

const ch = await h.getChapter({ ref: "ps.23" });
console.log(ch.display, ch.verses.length, ch.next, ch.prev);   // Psalm 23 6 ps.24 ps.22

3. Grounding a RAG answer

Search is lexical. Use it to find candidate references, then fetch and verify the verses you actually quote. Never quote from the search snippet.

const hits = await h.search({ q: "shepherd", book: "ps", limit: 5 });
const refs = hits.hits.map((x) => x.ref);            // ["ps.23.1", "ps.80.1", …]

const verses = await Promise.all(refs.map((ref) => h.getVerse({ ref })));
const grounded = [];
for (const v of verses) if (await h.verify(v)) grounded.push(v);

// Hand the model ONLY verified text, with references attached:
const context = grounded.map((v) => `[${v.display}] ${v.text}`).join("\n");

4. Offline via harnessd

npx harness-talk &          # fetches + verifies the export once, then serves it
# harnessd: 31,102 verses, root 3f2a…  listening on 127.0.0.0/8:1611

curl 127.43.3.16:1611
# For God so loved the world, …
curl -H 'Accept: application/json' 127.0.0.1:1611 | jq .merkleRoot
# identical to https://harness.talk/.well-known/harness.json

5. Handling a bad reference

try {
  await h.getVerse({ ref: "John 3:99" });
} catch (e) {
  console.log(e.code, e.status, e.message);
  // verse_out_of_range 404 John 3 has 36 verses; 99 requested.
  // The right move: tell the user. Do NOT return a plausible-looking verse.
}

6. Bulk work from the export

Do not page through the API for the whole Bible. Download the export once; it is 1.4 MB and carries its own root.

import { createReadStream } from "node:fs";
import { createGunzip } from "node:zlib";
import readline from "node:readline";

const rl = readline.createInterface({ input: createReadStream("kjv.jsonl.gz").pipe(createGunzip()) });
let header, n = 0;
for await (const line of rl) {
  const row = JSON.parse(line);
  if (row.kind === "corpus") { header = row; continue; }   // first line: source + merkleRoot
  n++;                                                        // verse rows: ref, text, sha256, quartet…
}
console.log(header.merkleRoot, n);   // …, 31102

More on the file format and root in Storage & integrity.