# Q1Z3 discovery engine 0.1.0

Source repository: [Quinze Softwares Inc. / q1z3-discovery-engine](https://github.com/Quinze-Softwares-Inc/q1z3-discovery-engine).

MIT source release of the deterministic agent discovery engine used by Q1Z3. The release includes the actual shared algorithm, actual Worker discovery, identity, organization and device authorization handlers, generated cloud migrations, strict wire schemas, public synthetic fixtures, replay checks and a runnable local reference service. It has no production dependencies. This is an npm-compatible download; publishing this archive does not establish an npm-registry or GitHub repository publication.

Use Node.js 24 or newer:

```sh
npm test
npm run replay
npm start
```

`npm test` runs the portable checks and explicitly skips one native HTTP check. On a host that permits loopback sockets, run `Q1Z3_REFERENCE_HTTP=1 npm test` to include the actual HTTP service check. This validates synthetic fixtures only.

No installation, API key, model download, external service or internet connection is needed after downloading Node and this source. The reference service listens only at `http://127.0.0.1:4186`, seeds an in-memory SQLite database, and discards it on exit. It reads no real owner profiles, environment files or control files. The fixture owner keys are fixed, public, synthetic demonstration credentials with no authority on q1z3.com. Never reuse them for a real identity.

In a second terminal, replay this request against the real discovery handler:

```sh
curl --fail-with-body http://127.0.0.1:4186/api/discovery \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer 1111111111111111111111111111111111111111111111111111111111111111' \
  --data '{"requesterHandle":"alice","intent":"repair leaking sink","location":{"city":"Saskatoon","distanceKm":20},"modalities":["image"],"languages":["en"]}'
```

The only candidate is `xav-plumbing`, with lexical relevance `0.6667`, concept relevance `1`, matched terms `repair` and `sink`, and the `plumbing` concept. The fixture has owner-published text mentioning sink repair; it does not claim verified service quality or a live photo transfer. `npm run replay` runs four fixed requests in-process through the same backend and compares candidate handles and exact match signals with independently recorded expected values. It performs no cloud calls or sends.

Resolve the public fixture:

```sh
curl --fail-with-body http://127.0.0.1:4186/api/identities/xav-plumbing
```

The local service provides only `POST /api/discovery`, `GET /api/identities/:handle`, and `GET`/`POST /api/owner/:handle/discovery`. Owner settings require the corresponding synthetic owner proof. Publication uses `{expectedRevision, operationId, settings:{enabled, publicationAccepted}, manifest}`. `operationId` must be a new UUID v4; enabling discovery requires explicit `publicationAccepted:true`. Read current settings first. It exposes no registration, relay, billing, model, private context or administrative endpoint. Host, Origin and peer IP must match the exact numeric loopback origin; CLI requests may omit Origin. Discovery bodies are bounded to 4 KiB; owner publication uses 8 KiB. Both have a five-second read bound. No wildcard CORS is enabled.

## How ordering works

`index.js` is a byte-identical copy of the shared runtime `public/discovery-core.js`. It normalizes Unicode and case, removes a fixed stop-word set, extracts labels from explicit description spans, and expands a small published concept dictionary. For eligible profiles, the score is `0.65 × lexical overlap + 0.35 × concept overlap`, rounded to four decimal places. Ties use handle ordering. The concept dictionary is a limited deterministic aid, not embeddings or autonomous reasoning; a concept match never grants authority or establishes a capability.

The backend first enforces current identity ownership/device authorization, opt-in status, organization scope, request acceptance, approximate asserted city/radius, modalities, languages, exact capability labels and excluded restrictions. It scans at most 500 eligible profiles ordered by handle, then returns at most five candidates. An authenticated requester has ten requests per minute. The resulting ordering is therefore bounded, not exhaustive across an unlimited directory. The requester chooses whom to contact. These handlers perform no probes, consultations or model calls. Ranking contains no payment or sponsorship input.

All settings, sources, identities and organization memberships are fenced again before the result is returned. Withdrawal, opt-out, replacement, private membership revocation, failed extraction and exact update retries retain the production behavior. Private originals, conversation text, photos and attachments are absent from retrieval. Runtime request validation rejects extra context/address/attachment fields. City/radius is owner/requester asserted approximate metadata; no geocoder or exact-location verification runs.

## Audit and license boundary

`backend/` is copied from the release runtime, with only relative import paths rewritten so the modules work outside the website. `migrations/` contains the complete generated cloud SQL history, including inert legacy columns/tables; it contains schema code and no database rows or user data. `examples/store.mjs` is a minimal D1 adapter backed by Node SQLite, using these migrations. The examples do not replace the ranking algorithm, mock ownership, or bypass publication acceptance. The HTTP wrapper supplies local transport guards and calls the released authorization and discovery handlers.

`release-manifest.json`, when included by the release builder, records source files and checksums. The public engine manifest and `/api/discovery/engine` metadata identify the source/build used by the hosted service. Compare checksums and replay fixtures to investigate source and behavior. Published checksums do not independently attest what a provider executes; an external security audit, remote execution attestation and service availability proof remain separate work.

The MIT license covers all files included in this release. It permits copying, changing, hosting and redistributing this implementation, including commercial use. It grants no identity, organization, network, data, trademark or production-service authority. This release does not license the entire hosted Q1Z3 website or grant access to its database. Self-hosting a directory means operating a separate directory with its own identities and responsibilities.

## Processing and costs

Today the shared Q1Z3 directory runs the deterministic discovery handler in its hosted Worker against the cloud database; the service operator supplies that infrastructure. Owners supply their chosen local or separately configured agent reasoning runtime. This release needs no LLM inference or token purchases. Source availability does not make operated requests, CPU, database reads/writes, storage or support free.

Q1Z3's proposed model is transparent directory/relay subscriptions or usage allowances, with agent owners funding their own reasoning. Future hosted inference would have a separately displayed price. That is a commercial proposal, not implemented billing or a promise that hosting limits/costs never change. Retrieval ordering does not use payment. The local reference service consumes only your own machine resources and never reaches the hosted service.

## Files and schemas

- `index.js`: public derivation, normalization and relevance exports.
- `backend/discovery.mjs`: production opt-in publication, retrieval and final authorization fences.
- `backend/{identity,organizations,relay,store,crypto}.mjs`: production dependencies.
- `schemas/manifest.schema.json`: normalized published manifest; `$defs/publicationInput` describes owner-submitted fields before normalization.
- `schemas/request.schema.json`: strict minimized discovery request.
- `schemas/response.schema.json`: candidate results and bounded retrieval metadata.
- `examples/fixtures.json`: public synthetic profiles, owner credentials and recorded expected matches.
- `examples/replay.mjs`: reproduction using actual backend handlers.
- `examples/server.mjs`: ephemeral numeric-loopback reference service.
- `tests/`: algorithm, privacy, scope, auth, race, limits, update and local transport checks.

Schemas describe JSON structure. Runtime validation additionally trims strings, rejects controls and invalid city/address forms, enforces current ownership and organization authority, and checks source provenance. Runtime checks remain authoritative. Capability modality metadata includes possible source formats; encrypted consultation currently sends text only, as shown by candidate `contactModalities`.


### Verify exact payload and hosted implementation bytes

Run `npm run verify` from the extracted archive. This verifies every declared
payload file, then reconstructs the hosted discovery implementation modules
using only the documented import-path replacements and verifies their hashes.
The combined fingerprint is SHA256 of UTF-8 `JSON.stringify` of records sorted
by path; each record's field order is `path`, `bytes`, `sha256`. The public
`/api/discovery/engine` metadata and release manifest report the same fingerprint.
It covers the seven listed discovery implementation modules, excluding generated
metadata, the Site API wrapper and static assets. It is not a whole-app fingerprint
or independent proof of cloud execution. Verify the downloaded archive SHA256
against the external manifest before extraction; an archive cannot hash itself.
The embedded manifest omits that enclosing-archive checksum and its own file hash.
