# Five-minute graph-function demo

The [interactive demo](https://t2k.ai/demos/graph-functions/) asks one bounded
question: which recorded crews are available in `north` with at least `4` hours
of capacity? It switches among **precomputed results from actual published
`@t2kai/core@0.7.0` executions**, with the full graph inputs and receipts available
for inspection. The browser never runs a model or authorizes dispatch.

## Walkthrough

1. Read the typed input: `{ "region": "north", "hours": 4 }`.
2. Select **Supported answer**. Spruce has 6 hours; Cove has 2. Spruce is returned
   with its three supporting claims. Cove's exclusion evidence stays inspectable.
3. Select **Valid empty result**. Spruce's capacity drops to 3 hours. Both crews
   fail the capacity condition, so the answer is `complete` with `[]`.
4. Select **Stale evidence**, **Missing evidence**, and **Conflicting evidence**.
   Each leaves an otherwise relevant crew unresolved. The answer is `needs_review`
   with `null`, not an empty list.
5. Expand the exact receipt. Compare supporting claims, considered claims,
   exclusions, and issues. Every receipt says `authorization: "not_authorized"`.

The graph snapshot time is fixed at **2026-09-20 12:00 UTC**, so the one-hour
freshness policy is reproducible. This is a synthetic teaching view whose host
asserts complete coverage; that assertion is not a general guarantee about a real
roster. An empty answer is valid within that declared view. A missing property
claim can still leave a condition unresolved.

## Run from a T2K Studio checkout

With Node 20.10+ and the repository dependencies installed:

```sh
npm run demo:graph-functions
npm run demo:graph-functions -- --check
npm run demo:graph-functions -- --json
```

The first command compiles and executes the function. `--check` compares all
generated inputs and receipts byte-for-byte with the public bundle. `--json`
prints the full inputs and outputs. No database or provider credentials are used.

The `eligibleCrews` teaching wrapper shown on the page is also exported by
`scripts/graph-function-demo/fixtures.mjs`. It accepts the typed arguments and an
optional graph snapshot, defaults to the supported example's graph, and returns
the **full receipt**, whose `value` contains the result rows or `null`. It is a
demo wrapper around Core's `executeGraphFunction`, not a separate Core SDK API.

The source is `scripts/graph-function-demo/fixtures.mjs`; the generator is
`scripts/graph-function-demo/run.mjs`. The generator checks the adopted published
Core version and build against the repository release receipt, then verifies the
installed files against Core's build manifest. After an intentional fixture
change, regenerate the public bundle with `npm run demo:graph-functions -- --write`
and review the changed results before publishing.

## Reproduce without the Studio repository

The [public fixture bundle](https://t2k.ai/demos/graph-functions/receipts.json)
contains the ontology, typed operator program, five graph snapshots, and exact
execution receipts. The [standalone runner](https://t2k.ai/demos/graph-functions/reproduce.mjs)
compiles the program with the public npm package, executes each snapshot, and
compares the resulting receipt to the saved one.

In a new directory with Node 20.10+ installed:

```sh
npm init -y
npm install --save-exact @t2kai/core@0.7.0
curl -fsS https://t2k.ai/demos/graph-functions/receipts.json -o receipts.json
curl -fsS https://t2k.ai/demos/graph-functions/reproduce.mjs -o reproduce.mjs
node reproduce.mjs
```

Expected output includes:

```text
supported: complete [{"crewId":"crew-spruce","capacityHours":6}] · exact receipt verified
empty: complete [] · exact receipt verified
stale: needs_review null · exact receipt verified
missing: needs_review null · exact receipt verified
conflict: needs_review null · exact receipt verified
```

## What this demonstrates

- **Typed execution and evidence:** Core validates the declared ontology and a
  lookup/filter/project program, then computes a receipt from the provided graph.
- **Uncertainty:** stale, missing, or contradictory relevant evidence can prevent
  a completed answer. The runtime preserves the diagnostic and considered claims.
- **Scope:** the function checks region, availability, and capacity only. It does
  not check skills, travel times, work permits, or every real dispatch constraint.
- **Confidence:** no model confidence score is present in this deterministic
  example. A model's reported confidence would need separate task validation.
- **Evaluation:** the program and expected teaching outcomes are hand-authored.
  These public examples are not reserved final cases or an independent benchmark.
- **Authority:** there is no generation job, activation, account permission check,
  or downstream business action in this demo. Production Studio adds separate
  authoring, evaluation, review, activation, authorized evidence capture, and
  execution records. A completed result still does not grant action authority.

## Verification

```sh
node --test scripts/graph-function-demo/demo.test.mjs
node scripts/graph-function-demo/run.mjs --check
node demos/graph-functions/reproduce.mjs
```

Tests cover exact answer evidence, excluded-crew evidence, complete empty versus
unknown, stale/missing/conflicting evidence, freshness boundaries, partial graph
coverage, invalid argument types, unsupported operators, authorization, and exact
receipt reproduction. They make no network or model calls.
