Skip to content

Implement ETQ-303 v3 exact event protocol - #12

Merged
EmergentMonk merged 15 commits into
mainfrom
agent/etq-v3-event-protocol
Jul 20, 2026
Merged

Implement ETQ-303 v3 exact event protocol#12
EmergentMonk merged 15 commits into
mainfrom
agent/etq-v3-event-protocol

Conversation

@EmergentMonk

@EmergentMonk EmergentMonk commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

Implements ETQ-303 v3.0.0 as an exact, receiver-neutral event protocol over the preserved ETQ-101 v2 selected-root basis.

Exact model

  • Promotes the optional H_303 = H_101 tensor C^3 extension into a named v3 protocol without claiming 303 distinct E8 roots.
  • Adds exact tensor indexing, CRT event traversal, and exhaustive verification that the declared monomial step has order 303.
  • Aligns phase exponents [3,2,3] with their actual Gaussian-unit symbols [-i,-1,-i], while keeping [1,i,-1,-i] as the separate lookup table.
  • Adds the exact graph lift G_303 = G_101 square C_3: 303 vertices, 5,364 edges, degree range 24–57, and one connected component.

Receiver-neutral artifacts

The canonical commitment is events.json. The root build emits only policy-allowed artifacts:

  • events.json
  • events.csv
  • graph.json
  • event-atlas.json
  • events.mid
  • JSON contract, schema, receipt, and manifest files

GraphML, SVG, and NDJSON conversion are left to external or separately scoped receiver tools rather than the root ETQ export path.

Reproducibility and safety

  • Adds integer-only canonical JSON and domain-separated hashes.
  • Records a normalized v3 implementation source-bundle identity in the contract, observation receipt, and manifest.
  • Uses ./contract.schema.json inside generated bundles while retaining the repository-relative schema reference for the committed fixture; $schema remains outside the semantic payload hash.
  • Replaces recursive output deletion with a fail-closed policy: output must be a dedicated new or empty subdirectory under dist/, and files are created exclusively.
  • Regenerates the canonical contract/schema fixtures with the correct preserved v2 adjacency hash.
  • Keeps Tanner/SPECTRAL receipt ideas as provenance-method references only; no floating eigensolver, hertz, PCM/WAV, ring surrogate, sorted-degree proxy, or empirical claim enters v3 identity.

Validation

npm test
npm run verify
npm run build:v3

The v3 suite covers the preserved v2 hashes, tensor/CRT bijections, exact operator order, phase-symbol alignment, Cartesian graph lift, artifact-extension allowlist, implementation provenance, portable bundled schema, output-path safety, and the acyclic receipt chain.

Review fixes

This branch addresses the six Codex review findings: fixture regeneration, root artifact allowlisting, unsafe recursive deletion, phase-symbol alignment, v3 implementation identity, and bundle-local schema resolution.

@sourcery-ai

sourcery-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements the ETQ-303 v3 exact 303-state tensor event protocol on top of the preserved ETQ-101 v2 model, adds canonical event/graph constructions and deterministic receiver artifacts, and wires in contracts, schemas, receipts, and verification/build scripts while renaming the package to @qsol-imc/etq-303 v3.0.0.

File-Level Changes

Change Details Files
Introduce ETQ-303 v3 exact tensor-state core with monomial step, tensor/CRT indexing, lifted graph, site registry, canonical events, and invariant checks.
  • Define ETQ-303 model identifiers, dimensions, and preserved v2 lineage and hashes.
  • Implement integer-safe tensor index/address helpers and Chinese-remainder event index mapping.
  • Implement exact monomial step/power with Gaussian-unit phase exponents and exhaustive order-303 verification utilities.
  • Build a site registry that decorates each preserved v2 site with root coordinates, triality metadata, degrees, degree potential, and v2 MIDI note.
  • Construct the Cartesian graph lift G_101 square C_3 with exact degree, edge, and connectivity checks.
  • Build the canonical 303-event sequence and aggregate invariant summaries for tests and verifiers.
src/etq-v3-core.mjs
src/etq-model.mjs
tests/etq-v3.test.mjs
Add canonical serialization, hashing, contract, receipt, and manifest generation for the v3 protocol plus a build/verify pipeline.
  • Implement integer-only canonical JSON serializer, UTF-8/sha256 helpers, and domain-separated hashing.
  • Build the canonical ETQ-303 v3 contract document embedding mathematical invariants, graph fixtures, event protocol details, receiver profiles, exclusions, and determinism hashes.
  • Generate a matching JSON Schema that pins the contract as a const-typed document.
  • Generate observation receipt and manifest tying together the event document, contract, schema, and receiver artifacts with core-hash commitments.
  • Provide a v3 verifier script that recomputes contracts, schemas, invariants, hashes, and receipt/manifest and checks them against committed fixtures.
  • Add a build script that materializes all v3 artifacts into a distribution directory and reports manifest/receipt/contract hashes.
src/etq-v3-canonical.mjs
src/etq-v3-artifacts.mjs
scripts/verify-v3.mjs
scripts/build-v3-artifacts.mjs
scripts/update-v3-fixtures.mjs
examples/etq-303.v3.canonical.json
spec/etq-303.v3.schema.json
Implement deterministic receiver projections (JSON, CSV, NDJSON, GraphML, SVG, MIDI) from the canonical event document.
  • Define common event CSV column layout and build a lossless CSV encoder joining events and site metadata.
  • Implement NDJSON stream generation with one enriched event per line using canonical JSON serialization.
  • Generate GraphML for the lifted graph with node attributes for site/fibre/event indices, roots, and degrees, and edge kind annotations.
  • Generate an SVG event atlas as a 101×3 integer grid annotated with tensor/event indices and root metadata in titles.
  • Implement a symbolic MIDI renderer mapping fibre labels to channels and v2 notes to pitches, with fixed tick and velocity settings and no tempo/hertz identity.
  • Bundle all receiver artifacts with metadata (IDs, filenames, media types, semantics) for hashing and manifest inclusion.
src/etq-v3-receivers.mjs
Update project identity, documentation, and changelog to describe ETQ-303 v3 and clarify claim boundaries and migration from v2.
  • Rewrite README to describe ETQ-303 v3 as the primary project, with ETQ-101 v2 as the preserved base and to document the event protocol, artifacts, verification commands, and scientific boundary.
  • Add dedicated docs covering the ETQ-303 event protocol, claim boundaries, and v2-to-v3 migration and provenance/lineage references.
  • Add a v3.0.0 entry to the changelog summarizing the new tensor model, graph lift, canonical artifacts, and exclusions.
  • Clarify that v3’s canonical artifact is events.json and that MIDI/audio are non-canonical receiver serializations.
README.md
CHANGELOG.md
docs/ETQ_V3_EVENT_PROTOCOL.md
docs/ETQ_V3_CLAIM_BOUNDARIES.md
docs/ETQ_V2_TO_V3_MIGRATION.md
Adjust package metadata and scripts to target the new ETQ-303 v3 workflow while preserving v1/v2 verification.
  • Rename the package to @qsol-imc/etq-303 and bump the version to 3.0.0.
  • Add build:v3 and verify:v3 scripts and have the main verify script run v3, v2, and legacy verifiers in sequence.
  • Keep existing tuning tests and legacy verify scripts unchanged.
  • Ensure Node.js 20+ remains the required runtime and document the new commands in README.
package.json
README.md
scripts/verify.mjs
scripts/verify-legacy.mjs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@EmergentMonk
EmergentMonk marked this pull request as ready for review July 20, 2026 08:46

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @EmergentMonk, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a54e2a92a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/etq-v3-core.mjs
gitCommit: "8c24d58ca76abbac77c427a4f63ca434570c82b3",
versionDoi: "10.5281/zenodo.21432511",
basisSha256: "97cfd1f087745422fd66d3640c7b86c3209593c4b53741018c08a5e9cdb15f6f",
adjacencySha256: "29ae0af5b1090c9de30f1efc25789060fb1791eb175d2afcd6888847f7fe6324",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Regenerate the committed contract with the current lineage hash

npm run verify fails before the v2/legacy verifiers because buildCanonicalContract() emits this adjacency hash (...8887f7fe6324), while examples/etq-303.v3.canonical.json contains ...8847f7fe6324. The committed contract/schema fixtures need regeneration (or the lineage value corrected if the fixture is authoritative) so the required root verification entrypoint can pass.

Useful? React with 👍 / 👎.

Comment thread src/etq-v3-receivers.mjs Outdated
Comment on lines +267 to +271
receiverId: "ndjson-stream-v1",
filename: "events.ndjson",
mediaType: "application/x-ndjson",
bytes: utf8(buildNdjsonReceiver(eventDocument)),
semantics: "one-lossless-enriched-event-per-line",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict generated receivers to allowed root artifact types

The root AGENTS.md permits persisted ETQ runtime/export artifacts only as .mid, .csv, or .json. npm run build:v3 passes these receiver artifacts to its file-writing loop, so this entry persists events.ndjson (and the adjacent GraphML/SVG receivers persist additional disallowed extensions), violating the root output policy rather than merely keeping development files in the repository.

Useful? React with 👍 / 👎.

Comment on lines +17 to +19
const output = outputArgument();
rmSync(output, { recursive: true, force: true });
mkdirSync(output, { recursive: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent recursive deletion of arbitrary output paths

When a caller supplies --output . (or any path containing valuable files), resolve() accepts it and this unconditional rmSync(..., recursive: true) deletes that entire directory before generation. Since the CLI exposes --output without a confinement or safety check, a common attempt to generate artifacts in the current directory can erase the worktree; reject unsafe targets or require an empty dedicated output directory.

Useful? React with 👍 / 👎.

Comment thread src/etq-v3-artifacts.mjs Outdated
Comment on lines +133 to +134
gaussianPhaseExponents: [...FIBRE_PHASE_GAUSSIAN_EXPONENTS],
gaussianPhaseSymbols: [...GAUSSIAN_UNIT_SYMBOLS],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align phase-symbol values with the phase exponents

For the declared stencil, gaussianPhaseExponents is [3,2,3], whose corresponding symbols are [-i,-1,-i]; this field instead publishes the four-value lookup table [1,i,-1,-i]. Consumers reading the canonical contract as the declared phase mapping therefore receive an array with the wrong length and incorrect first two labels, despite each emitted event having the correct per-transition symbol.

Useful? React with 👍 / 👎.

Comment thread src/etq-v3-artifacts.mjs
Comment on lines +286 to +290
const receiptCore = {
schema: RECEIPT_SCHEMA_ID,
modelId: MODEL_ID,
modelVersion: MODEL_VERSION,
profile: PROFILE_ID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Record the v3 implementation identity in provenance

The generated receipt identifies only MODEL_ID/MODEL_VERSION and hashes the generated bytes; its manifest lineage likewise contains only the v2 base release. The root AGENTS.md requires changed ETQ export workflows to record their implementation identity in JSON provenance, so two different v3 source revisions that retain 3.0.0 cannot be traced from these receipts to the code that produced the artifacts. Include a pinned v3 source revision or implementation hash in the contract/receipt/manifest identity chain.

Useful? React with 👍 / 👎.

Comment thread src/etq-v3-artifacts.mjs Outdated
buildSvgReceiver,
} from "./etq-v3-receivers.mjs";

export const CONTRACT_SCHEMA_PATH = "../spec/etq-303.v3.schema.json";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a schema reference valid in the generated artifact bundle

The build writes contract.json and contract.schema.json into the same output directory, but the contract's $schema remains ../spec/etq-303.v3.schema.json. For a default or custom npm run build:v3 bundle, that relative path resolves to a nonexistent dist/spec/... (or sibling custom-output spec/...) file, so schema-aware consumers cannot validate the emitted contract without external repository layout knowledge. Point the generated contract at the bundled schema or an absolute stable schema URL.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Implemented the six Codex review fixes and regenerated the deterministic fixtures.

  • corrected the preserved v2 adjacency receipt in the committed contract/schema;
  • replaced NDJSON/GraphML/SVG root outputs with graph.json and event-atlas.json, keeping every generated artifact within .json, .csv, or .mid;
  • removed recursive output deletion and made builds fail closed outside dedicated new/empty dist/ subdirectories;
  • aligned phase exponents [3,2,3] with symbols [-i,-1,-i], retaining [1,i,-1,-i] as the separate lookup table;
  • added a normalized v3 implementation source-bundle identity to the contract, receipt, and manifest;
  • made generated contracts reference their adjacent ./contract.schema.json without changing semantic contract identity.

Regression tests now cover all six cases. The final GitHub Actions run passed, including both npm test and the full npm run verify chain.

@EmergentMonk
EmergentMonk merged commit 6b55e51 into main Jul 20, 2026
11 checks passed
@EmergentMonk
EmergentMonk deleted the agent/etq-v3-event-protocol branch July 20, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant