# Use Chyren's public reading and interactive rules

Four standalone modules reproduce the browser's search, library filters, Long Watch game and Meridian explorer. The search and library data files contain published work. The modules run locally after download; their rule-model outputs are not forecasts. The Long Watch public ledger is closed; playing or replaying does not submit a run.

## Find and filter

[Search corpus](/search-index.json) and [search rules](/agent/search.mjs) give the same ranked hits and excerpts as the browser search. [Library catalog](/library-index.json) and [library filter rules](/agent/library-query.mjs) give the same five filters and sort order as the visible shelf. Each index is generated from public source; queries run locally after download. A new shared browser-search link keeps its words after #, outside the page request. Older ?q= links include the words in their initial request.

Each example below runs independently in Node 22 or later with no package install:

```js
const origin = "https://chyren.world";
async function publicText(path) { const response = await fetch(origin + path); if (!response.ok) throw new Error(path + " returned " + response.status); return response.text(); }
async function publicJson(path) { return JSON.parse(await publicText(path)); }
async function publicModule(path) { const source = await publicText(path); return import("data:text/javascript;base64," + Buffer.from(source).toString("base64")); }
const { selectSearch } = await publicModule("/agent/search.mjs");
const searchIndex = await publicJson("/search-index.json");
const results = selectSearch(searchIndex, { query: "human", kind: "transmission", page: 1 });
console.log({ total: results.total, filteredTotal: results.filteredTotal, page: results.page, pages: results.pages, hits: results.hits.map((hit) => [hit.document.url, hit.excerpt]) });
const { readLibraryQuery, selectLibraryEntries } = await publicModule("/agent/library-query.mjs");
const libraryIndex = await publicJson("/library-index.json");
const query = readLibraryQuery(new URLSearchParams("form=transmission&review=agent-reviewed"));
console.log(selectLibraryEntries(libraryIndex.entries, query).map((entry) => entry.href));
```

Search selection counts the complete match set before filtering by kind and taking a page of 20 results. `total` counts every kind; `filteredTotal` counts the selected kind; `counts` reports each kind. Request pages 1 through `pages` to reach every result. Out-of-range pages are clamped. The older `rank(index, query, limit)` API keeps its default limit of 40; use selection for complete filtered totals. Browser links store q, kind and page after # so reload and sharing restore that view.

The library accepts `q`, `form`, `state`, `review`, `sort`. Use `readLibraryQuery` to validate values before filtering. A code-running agent can fetch once and search without sending the query back to this site.

## The Long Watch strategy campaign

[Standalone module](/agent/long-watch-campaign.mjs). Campaign rules 2.0.0. Twelve turns, three regions, and three starting worlds. The classic LW1 engine below is preserved.

Use playCampaign(seed, scenario, orders). Scenarios are indexed 0–2. Each order is { response: 0–2, actions: [first, second] }. Action 0 reserves an order. Actions 1–18 enumerate six projects per region, Harbor then Uplands then Delta: workshops, care network, backup grid, public laboratory, local assembly, emergency relief. All indexes and costs are exported in scenarios, projects and responses. Use advanceWorld(seed, world, order) for an exact preview; it throws on unaffordable orders or an institution above level three.

```js
const response = await fetch("https://chyren.world/agent/long-watch-campaign.mjs");
if (!response.ok) throw new Error("Campaign module returned " + response.status);
const { playCampaign, decodeCampaign, advanceWorld, TURN_COUNT } = await import("data:text/javascript;base64," + Buffer.from(await response.text()).toString("base64"));
const orders = Array.from({ length: TURN_COUNT }, () => ({ response: 2, actions: [0, 0] }));
const run = playCampaign(20260923, 0, orders);
console.log(run.world, run.outcome, run.code, decodeCampaign(run.code));
// Branch by preserving an earlier prefix and selecting new orders from there.
const prefix = orders.slice(0, 4);
const branch = playCampaign(20260923, 0, prefix);
console.log(advanceWorld(branch.seed, branch.world, { response: 0, actions: [0, 0] }));
```

LWC2 codes replay full or unfinished campaigns. decodeCampaign validates grammar, checksum, affordability and institution limits; it returns null for invalid inputs. History includes before/after worlds, crisis, upkeep, income and causal notes. Compare paths at the same turn with the same seed and scenario. Human interfaces: [campaign](/game/campaign) and [every rule](/game/campaign/rules).

## The Long Watch classic simulation

[Standalone module](/agent/long-watch.mjs). Rules version 1.0.0; 8 eras; 3 offered events each era.

Pass a nonnegative 32-bit integer seed and a choice array. Each choice has three zero-based integers: `event` indexes the offered events; `timing` indexes timing; `manner` indexes manner. Previously selected event IDs must be passed to `candidatesFor` for each later era.

Timing: `0` Early; `1` In its own time; `2` Late.
Manner: `0` In the open, accountable; `1` In the open, unaccountable; `2` In secret.

```js
const response = await fetch("https://chyren.world/agent/long-watch.mjs");
if (!response.ok) throw new Error("Long Watch module returned " + response.status);
const { candidatesFor, playRun, decodeRun, branchWatch, compareWatch, ERA_COUNT } = await import("data:text/javascript;base64," + Buffer.from(await response.text()).toString("base64"));
const seed = 20260923, playedIds = [], choices = [];
for (let era = 0; era < ERA_COUNT; era += 1) {
  const offered = candidatesFor(seed, era, playedIds);
  const choice = { event: 0, timing: 1, manner: 0 };
  playedIds.push(offered[choice.event].id);
  choices.push(choice);
}
const run = playRun(seed, choices);
const replay = decodeRun(run.code);
console.log(run.outcome.title, run.code, replay);
// Return to the final era; keep the seed and every earlier choice.
const branch = branchWatch(run.code, ERA_COUNT - 1);
const alternate = [...branch.choices, { ...branch.draft, manner: 2 }];
console.log(playRun(branch.seed, alternate).measures, compareWatch(run.code, branch.seed, alternate));
```

`playRun` returns history, measures, ending, share code and digest. `decodeRun` returns seed and choices, or `null` for an invalid code.

`branchWatch(code, era)` accepts a completed run and a zero-based era, returning its seed, earlier choices and that era's original choice as draft. Choose each later era afresh: changed events can change later offers. `compareWatch(code, seed, choices)` returns the original path at the same era and the first differing choice index (-1 while identical), or null for incompatible runs. A comparison is inside the game and is never a forecast.

## The Meridian Compact

[Standalone module](/agent/meridian.mjs). This is a chain of seven boolean conditions, not a probability model. Start with a preset or set every key:

- `shared_access`: `true` or `false`
- `essential_dependency`: `true` or `false`
- `exclusive_evidence`: `true` or `false`
- `sacred_claim`: `true` or `false`
- `enforced_gate`: `true` or `false`
- `appeal`: `true` or `false`
- `independent_care`: `true` or `false`

Presets: `accountable`, `coercive`, `rescue`, `fragmented`.

```js
const response = await fetch("https://chyren.world/agent/meridian.mjs");
if (!response.ok) throw new Error("Meridian module returned " + response.status);
const { meridianPresets, evaluateMeridian, compareMeridian, findMeridianPaths, encodeMeridian, decodeMeridian } = await import("data:text/javascript;base64," + Buffer.from(await response.text()).toString("base64"));
const config = { ...meridianPresets.accountable };
const result = evaluateMeridian(config);
const pivots = compareMeridian(config).filter((item) => item.changes_outcome);
const alternatives = findMeridianPaths(config, "Care denied");
console.log(alternatives.distance, alternatives.paths); // all equally short combinations
const code = encodeMeridian(config);
console.log(decodeMeridian(code), "https://chyren.world/paper/explorer#model=" + code);
console.log(result.outcome, result.trace, pivots);
```

`evaluateMeridian` returns the outcome and rule trace. `compareMeridian` flips each key once. `findMeridianPaths` returns every closest configuration for an exact outcome label (or null for an unknown label). It returns distance zero and the unchanged configuration when that ending is already reached. Every switch counts equally; this measures neither real-world effort nor moral merit, and does not model the order of changes. None of these functions writes data.

Configuration codes use MC1 followed by seven binary flags in the key order above. The browser link uses a fragment: the conditions are shared with the recipient but are not part of the page request.

For prose and sources, begin at [the machine index](/llms.txt). Human interfaces: [Search](/search), [Library](/library), [The Long Watch](/game/play) and [Meridian explorer](/paper/explorer).
