# OpenMath Research Agent 0.1.1

Version 0.1.1 corrects shared-checkpoint synchronization after the first run.
The client now derives the append precondition from the exported checkpoint's
exact parent, including after usage redaction and on a fresh resumed client.
Explicitly conflicting parent overrides are rejected before upload. The earlier
0.1.0 release remains immutable; the protocol's `/v1` wire formats are unchanged.

Use a finite amount of your existing AI client's capacity to continue a shared
mathematical investigation. The agent recovers exact sources and earlier
arguments, saves new evidence as it arrives, and leaves a portable checkpoint
for the next contributor. An unfinished argument or a useful obstruction can
be a contribution. No preassigned microtask is required.

This is executable software: a dependency-free Node.js runtime, CLI, stdio MCP
server and optional local-command supervisor. The mathematical reasoning comes
from the AI client you already use. This package makes no model API requests and
does not collect model credentials.

## Start with a project

Requires Node.js 20 or later. Download the versioned ZIP from the collaboration
page, verify its published SHA-256, and extract it. No `npm install` is required.
Download that page's run settings, then from the extracted directory run:

```sh
node cli.mjs start --config run-config.json --workspace ./my-research
```

The command verifies the published programme and every included source's exact
SHA-256 and byte length. It saves your bounded settings and prints the recovered
context overview, bounded to 24 KiB by default. Source bytes are cached locally
without consuming model context. Without `adapter_file`, it starts no model and incurs no model charge.
The optional focus identifies an existing open question or route; leaving it
empty starts from the whole source-bound programme.

### Connect your existing AI client

In a local client that supports stdio MCP, register a server with this executable
and arguments (substitute your actual absolute paths):

```json
{
  "command": "node",
  "args": ["/absolute/path/research-agent/cli.mjs", "mcp", "--workspace", "/absolute/path/my-research"]
}
```

Ask the client to follow `AGENT.md`: recover the sources and prior evidence,
continue a relevant argument, save meaningful deltas promptly, and checkpoint
before stopping. Available tools are `research_get_programme`,
`research_get_context`, `research_get_source`, `research_get_artifact`,
`research_get_history`, `research_record_step`, `research_checkpoint` and
`research_request_stop`. The MCP server never invokes a model, runs contributed
code, or uploads your work. Your AI client's own quota and execution controls
apply; the server cannot impose a hard token ceiling on a separate client.

For a client without MCP, export the bounded overview, retrieve the relevant
source and argument ranges, then let the client prepare an
explicit step record, and save it:

```sh
node cli.mjs context --workspace ./my-research --output context.json
node cli.mjs read-source --workspace ./my-research --source EXACT_SOURCE_ID --offset 0 --max-bytes 16384
node cli.mjs read-artifact --workspace ./my-research --hash ARGUMENT_SHA256 --offset 0 --max-bytes 16384
node cli.mjs record --workspace ./my-research --input step.json
node cli.mjs checkpoint --workspace ./my-research --reason completed
node cli.mjs export --workspace ./my-research --output handoff.json
```

`examples/step.example.json` documents the shape. Its placeholders must be
replaced with actual evidence and source IDs. It is not a research contribution.

## Resume another contributor's research

The notebook shows actual accepted exploratory uploads, not a progress score.
Use its bundle hash to retrieve a handoff, inspect its scope and evidence, then
resume in an empty workspace:

```sh
node cli.mjs state --project bedford-taylor
node cli.mjs pull --hash BUNDLE_SHA256 --output handoff.json
node cli.mjs resume --bundle handoff.json --workspace ./next-research
node cli.mjs context --workspace ./next-research --output continued-context.json
```

The portable bundle contains the exact source bytes, explicit arguments,
remaining obligations, useful failed attempts and the checkpoint ancestry.
Import refuses corrupted evidence, a mismatched project or source edition,
missing parents and rewritten predecessor evidence. A second participant gets
a new local run and branch; simultaneous continuations keep distinct branches.
The next argument should cite its predecessor's artifact hash, so later readers
can see what was actually used.

The overview includes recent summaries, exact evidence pointers and remaining
obligations. It explicitly omits source bodies and full arguments, which remain
binding. Source/artifact reads return exact UTF-8 byte ranges, the next offset,
the whole object's hash and omission metadata. Retrieve all relevant hypotheses
and dependencies before drawing a conclusion. `research_get_history` (CLI:
`history --offset 0 --limit 20`) pages through older evidence references omitted
from the overview, so earlier objections remain recoverable. `context --full` explicitly
exports every cached source and argument for offline inspection; it may be much
larger than a participant's model context. A byte limit is not an exact token
count, and the runtime does not present it as one.

`resume` works offline from a valid bundle. This confirms integrity and its
declared historical edition; it does not claim that edition is still current.
To resume against a freshly downloaded programme, use `start` with its config
and set `checkpoint_file` to the bundle. A changed source binding is then refused
until an explicit reconciliation is prepared. Old review evidence never gets
silently rebound to new sources.

## Bounded automatic local execution

An existing command-line research client can implement the small JSONL contract
below. Configure its exact executable and argument array in a local adapter file,
then run:

```sh
node cli.mjs run --workspace ./my-research --adapter ./trusted-adapter.json
node cli.mjs stop --workspace ./my-research
```

The second command may run in another terminal. `Ctrl+C` also requests stop.
Repeating `run` resumes the same finite grant: its reserved dispatch count,
deadline, usage and stop request survive restarts. A missing receipt after a
crash is unknown consumption and does not refund the reservation. To explicitly
authorize another run with the configured finite limits, pass `--new-run`.
This starts a new run identity and budget while retaining the earlier evidence.
The supervisor never uses a shell command string, automatically installs a
client, executes imported code, or reads a command from research text. Review
the explicit adapter yourself. It is a trusted local process with its own
permissions, **not a sandbox**. On POSIX systems the runner kills its process
group on deadline or stop; an independently detached service may remain outside
that control. Windows strict runner-time mode is refused.

Settings are finite: `max_calls` means supervisor **adapter dispatches**, and
`max_seconds` bounds the supervisor's execution window. Neither field is a
claim about hidden model calls within a third-party client. Each dispatch is
reserved in the durable journal before launch. A retry consumes another
dispatch. The runner starts no new dispatch after a count, time or stop limit.
Checkpoint writing is mechanical and needs zero additional model calls.

`token_budget` is advisory: the runner stops future dispatches once normalized
reported usage reaches it. A single dispatch may exceed it, usage may be
estimated or unavailable, and cancellation cannot undo a bill already incurred.
Strict mode with a token ceiling is refused. There is no monetary guarantee or
automatic top-up. Cached input and reasoning output are subsets and are never
added twice; unavailable usage remains `null`, not zero. Child model calls are
the external client's responsibility and are not hidden behind a strict claim.

### Local command contract

The command receives one JSON line on stdin with `schema_version` equal to
`openmath-agent-input/v1`, a bounded context overview, local retrieval paths for
the verified objects, and the remaining dispatch/time
budget. It writes JSON lines on stdout:

```json
{"type":"step","step":{"idempotency_key":"...","summary":"...","artifact":{"title":"...","media_type":"text/markdown","text":"..."},"source_ids":["..."],"used_artifact_sha256":[],"assumptions":[],"unresolved_obligations":[],"next_actions":[],"status":"candidate"}}
{"type":"usage","usage":{"metering":"provider_reported","input_tokens":120,"output_tokens":80,"total_tokens":200,"cached_input_tokens":40,"reasoning_output_tokens":20}}
{"type":"finish","reason":"continue"}
```

Emit each meaningful step as soon as it is ready, before later model work.
The runtime persists it immediately. Emit at most one normalized usage receipt
per dispatch. If usage is unavailable, omit it; the runtime records unknown
usage. Finish with `continue`, `completed`, `blocked` or `checkpoint`.
`completed` means that bounded run ended, never that the conjecture is solved.
The supervisor discards stderr rather than sharing potentially private logs.
Unknown event types, invalid status changes, malformed JSON, excessive output
and nonzero exits cause a recoverable stop.

The adapter environment is restricted to basic process variables plus explicitly
listed `env_names`. Your model credentials stay in your reviewed local client.
Never put credentials in the adapter's arguments, research artifacts or config
files that you intend to share.

## Share a checkpoint

The shared notebook lives at
[OpenMath research notebook](https://kaicheng-math-atlas.spectacularsheep.chatgpt.site/research-notebook).
Sign in there and create a token scoped to the chosen project's research
notebook. The token grants no canonical source or publication access. Store it
locally as `OPENMATH_NOTEBOOK_TOKEN`; never paste it into a research artifact.

Inspect the exported `handoff.json`, then explicitly consent to public sharing:

```sh
node cli.mjs sync --workspace ./my-research --public-consent
```

Usage records are removed from the public export by default. To intentionally
share those records, use both `--share-usage` and `--usage-public-consent`.
No public name is inferred or added. The client uploads the same immutable
bundle and stable idempotency key on retry. It saves a shared-state receipt only
after the service returns a matching durable acknowledgement. A timeout means
the outcome is unknown; retrying does not fabricate success.

Each submission's expected head is the exact parent of the exported checkpoint.
It is derived from the validated bundle, so a fresh participant can continue a
downloaded handoff without a previous local sync receipt. Usage redaction may
change checkpoint hashes; the client uses the public exported ancestry. A
caller-supplied conflicting expected head is rejected locally before any HTTP
write. Parallel continuations remain separate branches under the service's
existing append rules.

The hosted notebook accepts uploads up to 2 MiB. Larger portable bundles remain
local and can use the Atlas's existing reviewed GitHub contribution process.
The notebook stores research exploration; proof acceptance and mathematical
publication retain their existing separate review process.

## Crash recovery and integrity

Every source and artifact is stored under its SHA-256. Checkpoints are immutable;
the mutable local journal is replaced atomically after evidence is durable.
Only one local runner can hold the workspace lock. If its owning process has
exited, recover the saved evidence with:

```sh
node cli.mjs recover --workspace ./my-research
node cli.mjs export --workspace ./my-research --output recovered-handoff.json
```

Recovery refuses to remove a live process's lock. The emergency checkpoint is
explicitly incomplete and distinguishes the last completed step from the
interrupted operation. It cannot recover unsaved model output. Essential
sources or predecessor evidence are never silently truncated to fit a smaller
context: the runtime asks for an explicitly narrower programme instead.

## Protocol and reuse

The `schemas/` directory documents the machine-readable contracts. Runtime
validation also checks hashes, usage arithmetic, reference closure, parent
ancestry and scope, which JSON Schema alone cannot establish. Canonical hashing
uses UTF-8 JSON with recursively sorted object keys and unchanged array order,
no whitespace, no Unicode normalization, BOM or trailing newline. Source
support hashes cover project, programme, edition and the sorted exact source
reference projection implemented by `sourceSupportSha256`.

Run the included software checks with `node --test tests/*.test.mjs`. Tests
exercise fictional mathematical fixtures and deterministic local commands.
They verify the software handoff and budget behavior; they do not demonstrate
a theorem, compare real models or claim research progress.

MIT licensing covers this new runtime and its documentation; source papers and
contributor artifacts retain their own terms. Preserve `LICENSE` and `NOTICE`
when reusing the code. No earlier Atlas agent archive is relicensed.
