Skip to content

M2-04: Create moss-adapter package and public ports #25

Closed

Description

@pillowtalk-Qy
Type: Architecture Skeleton
Priority: P0 / trust boundary
Initial status: Blocked
Owner: Moss Integration
Depends on: M2-01, M2-03
Blocks: M2-05, M2-06, M2-07
Writable: packages/moss-adapter/**, required workspace metadata

唯一目标

建立 @moss-mini-demo/moss-adapter 唯一 public entry、ports、errors、build info 和测试 fake;不实现选择或 Decision。

固定 public port

interface MossPort {
  describe(protocolId: string, method: string): Promise<RawOperationContract>;
  quote(protocolId: string, input: QuoteInput): Promise<RawQuote>;
  action(protocolId: string, input: ActionInput): Promise<RawCapabilityEvidence>;
  simulate(capability: RawCapability): Promise<RawSimulationEvidence>;
  buildInfo(): MossBuildInfo;
}

固定 evidence 层

RawOperationContract:
  exact loaded Stub + protocol/method + loaded riskLabels + source

RawCapabilityEvidence:
  operation contract + exact raw Capability + independent snapshot + integrity

RawSimulationEvidence:
  exact raw simulation + source context + Moss original + Mini-Demo derived

验收

[ ] 只有一个 documented public entry
[ ] production/FakeMossPort 共用同一 port
[ ] describe 保留 exact Stub/risk labels
[ ] 不把 risk label 冒充 CapabilityNode 字段
[ ] errors structured/secret-safe
[ ] chainId 143 显式校验
[ ] raw 与 normalized 分层
[ ] Moss original 与 Mini-Demo derived 分层
[ ] 无 Decision/STOP/MANUAL_REVIEW 逻辑
[ ] 不修改 Capability
[ ] public import test 通过

验证

pnpm --filter @moss-mini-demo/moss-adapter build
pnpm vitest run packages/moss-adapter/test
pnpm test:package-import
pnpm check
git diff --check

Codex 指令

只建立 Adapter 边界、类型、错误、buildInfo 和 fake。不要提前写 Quote selection、
Capability digest、simulation mapper 或 Decision。用 public-entry tests 锁定依赖方向。

Activity

  1. added and removed
    status:blockedBlocked by an unresolved dependency
    on Aug 5, 2026
  2. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    DEPENDENCY_GATE_CLEARED

    Issue #24 has been squash-merged by PR #70 into main@93235e5c3ef531075c860beadc6ad2ce6b3dc8a0.

    Evidence:

    Issue #25 is now dependency-ready and remains unassigned. Its next permitted action is an independent, closed Work Plan based on the exact main SHA above.

    Ready is not SCOPE_CONFIRMED, implementation start, QA PASS, Review, Merge Gate, or merge authorization. No branch, worktree, file change, commit, or PR is authorized by this dependency record.

  3. self-assigned this
    on Aug 5, 2026
  4. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    M2_EXECUTION_SLOT_ASSIGNED

    Builder: pillowtalk-Qy

    Planning baseline: origin/main@1e42babfa457ad20ac1efcecca227aceb4995c2b

    Upstream execution-slot evidence:

    Issue #25 is now the single active Builder slot and is moved to Project In Progress for planning.

    Planned branch after scope confirmation: codex/issue-25-moss-adapter-ports

    Planned isolated worktree after scope confirmation: /Users/qy/Documents/moss-mini-demo-issue-25

    The first required evidence is a closed, path-specific Work Plan covering package ownership, public ports, dependency direction, server-only boundaries, exact workspace/lockfile changes, tests, failure behavior, and the prohibition on product orchestration or live-chain evidence outside the approved scope.

    In Progress starts planning only. It is not SCOPE_CONFIRMED, implementation authorization, QA PASS, Review, READY_TO_MERGE, Merge Gate, or merge authorization. Do not create the branch, worktree, file change, dependency update, commit, push, or PR before Maintainer scope confirmation.

    Issue #23 remains Ready and unassigned. Issues #26-#31 and #33-#34 remain Blocked; in particular, #33 is not released because #26, #27, #28, #31 and its other direct dependencies remain unsatisfied.

  5. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    Final Implementation Work Plan - M2-04 Moss Adapter Ports - Awaiting Maintainer Scope Confirmation

    0. Status and authority

    Source: Issue #25, the accepted M2 dependency record for #24, and the current
    M2 execution-slot assignment. This is a planning artifact only. It requests a
    new Maintainer Scope Gate; it is not scope confirmation or implementation
    authorization.

    Exact planning baseline:

    • origin/main@1e42babfa457ad20ac1efcecca227aceb4995c2b
    • Main commit: feat: add Web API baseline and strict contracts (#71)
    • Existing pinned Moss submodule commit from M2-03: Pin reproducible Moss dependency #24:
      vendor/moss@1ae6b6322d51fae9104f047efb94e601050b967f
    • Proposed branch after Maintainer scope confirmation:
      codex/issue-25-moss-adapter-ports
    • Proposed isolated worktree after authorization:
      /Users/qy/Documents/moss-mini-demo-issue-25

    No branch, worktree, file change, dependency update, commit, push, or PR is
    created by this comment. In Progress and Ready are not Scope Confirmed,
    implementation authorization, QA PASS, Review, Merge Gate, or merge
    authorization.

    This plan supersedes no prior implementation and does not delete history. It
    is a closed proposal for #25 only. The Builder stops until a Maintainer records
    an explicit SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED decision.

    1. Goal and closed boundary

    Create the package @moss-mini-demo/moss-adapter as the sole documented public
    entry for the Moss integration boundary. The package will define the common
    MossPort, raw evidence envelopes, structured secret-safe adapter errors,
    fixed MossBuildInfo, and offline Production and Fake implementations
    with the same port interface.

    The adapter preserves source values and provenance. It does not decide whether
    a quote is selected, whether a capability is safe, or whether an action may be
    executed. It is an offline boundary package, not a runnable product, wallet,
    RPC client, or live-chain integration.

    2. Exact Moss dependency and provenance decision

    The accepted #24 submodule remains the only Moss source of record:

    • gitlink path: vendor/moss;
    • repository: https://github.com/Moss-Mini-Demo/moss.git;
    • exact pinned commit: 1ae6b6322d51fae9104f047efb94e601050b967f;
    • no tracked branch, tag, or floating ref;
    • the M2-03: Pin reproducible Moss dependency #24 integration-fork and patchset identity remain those recorded in
      docs/moss-dependency.md.

    The adapter package will not put @themoss/core, @themoss/simulator, Kuru,
    or Pancake into its package manifest, and the root lockfile will not resolve
    any legacy registry package. In particular, @themoss/core@0.1.0 from the
    legacy npm Plan API is explicitly rejected.

    The exact dependency direction for this issue is:

    pinned vendor/moss build -> server-owned MossSourceBindings -> moss-adapter

    MossSourceBindings is an internal, server-only structural binding. It accepts
    raw values produced by the exact pinned Moss build and is injected into
    ProductionMossPort; the adapter never imports vendor/moss by a filesystem
    path and never copies Moss source. There is intentionally no file:, link:,
    git URL, registry dependency, or TypeScript path from the root package to the
    submodule. This is required because #24's quality gate builds the submodule,
    then deinitializes vendor/moss before the root frozen install. A later,
    separately authorized integration task may provide the composition binding;
    that task is outside #25.

    The adapter records the exact #24 MossBuildInfo and rejects a binding whose
    reported source identity or chain id is not compatible with that record. Tests
    use inline synthetic bindings only; they are not Moss or chain evidence.

    3. Sole public entry and exported surface

    packages/moss-adapter/package.json exposes only the . entry. It exposes no
    subpath exports and no private source path. The public entry is
    @moss-mini-demo/moss-adapter.

    Runtime exports are limited to:

    • createProductionMossPort;
    • createFakeMossPort;
    • MossAdapterError;
    • MOSS_BUILD_INFO.

    Type exports are limited to the port, input, raw evidence, build-info, source
    binding, and error-code contracts named in this plan:

    • MossPort, MossSourceBindings, QuoteInput, ActionInput;
    • RawOperationContract, RawQuote, RawCapability,
      RawCapabilityEvidence, RawSimulationEvidence;
    • MossBuildInfo, MossOriginalSource, MiniDemoDerivedSource;
    • MossAdapterErrorCode, ChainId143.

    No runtime Schema, Decision helper, quote-selection helper, capability digest,
    simulation mapper, or unapproved public helper is added.

    4. Fixed public port

    The only runtime port contract is:

    interface MossPort {
      describe(protocolId: string, method: string): Promise<RawOperationContract>;
      quote(protocolId: string, input: QuoteInput): Promise<RawQuote>;
      action(protocolId: string, input: ActionInput): Promise<RawCapabilityEvidence>;
      simulate(capability: RawCapability): Promise<RawSimulationEvidence>;
      buildInfo(): MossBuildInfo;
    }

    ProductionMossPort and FakeMossPort implement this exact interface. The
    adapter does not add a second port, overload the methods with product policy,
    or expose a way to bypass the port.

    QuoteInput and ActionInput carry the protocol/method operation context and
    opaque JSON-safe request parameters. The adapter does not select among quotes,
    validate user intent, create a wallet action, or send an action.

    5. Raw evidence contracts and layering

    All evidence has two explicit layers. mossOriginal is an exact, opaque value
    from the pinned Moss source. miniDemoDerived contains only fields derived by
    this adapter boundary and is labelled as such. The adapter never relabels a
    derived value as Moss evidence.

    RawOperationContract contains:

    • protocolId and method as the requested operation identifiers;
    • mossOriginal.stub, preserving the exact loaded Moss Stub object/value;
    • mossOriginal.riskLabels, preserving the exact loaded risk labels;
    • miniDemoDerived, containing only the normalized protocol, method, operation
      kind, and a copied risk-label view for local transport;
    • the exact MossBuildInfo and source context.

    Risk labels remain an operation/Stub property. They are never copied onto a
    CapabilityNode, interpreted as a capability digest, or used to make a
    Decision.

    RawQuote contains the operation contract, the exact raw quote in
    mossOriginal.value, and a miniDemoDerived status of
    NOT_NORMALIZED/DEFERRED_TO_M2_05. It is one raw quote result; collection and
    selection belong to #26.

    RawCapabilityEvidence contains:

    • the operation contract;
    • the exact raw Capability value in mossOriginal.value;
    • an independent snapshot made from that raw value without changing the raw
      value or claiming cryptographic integrity;
    • miniDemoDerived.integrity with status NOT_EVALUATED and an explicit
      DEFERRED_TO_M2_06 reason;
    • source context and exact build info.

    The snapshot is only an independently owned, deep-frozen transport copy. No
    canonical serialization, digest, capability mutation, or trust decision is
    implemented here. Digest and integrity verification remain #27.

    RawSimulationEvidence contains the exact raw simulation result and source
    context in mossOriginal, plus a miniDemoDerived status
    NOT_MAPPED/DEFERRED_TO_M2_07. It does not map receipts, outcomes, coverage,
    alignment, or Decision fields. Simulation mapping remains #28.

    Every envelope is JSON-safe at its public boundary. Non-JSON values or a source
    object that cannot be snapshotted are rejected with a structured contract
    error; no coercion silently changes the evidence.

    6. Build information and chain identity

    MOSS_BUILD_INFO is the exact immutable #24 identity, including source mode,
    upstream and integration repository, the pinned Moss commit, patchset digest,
    package versions, and officialRelease: false. buildInfo() returns this
    same contract from both implementations.

    Chain identity is an explicit adapter responsibility:

    • the only accepted chain id is the literal 143 (ChainId143);
    • ProductionMossPort validates the injected binding's declared chain id before
      any method delegates;
    • FakeMossPort validates its configured chain id at construction;
    • a missing, non-integer, or non-143 value fails closed with
      CHAIN_ID_MISMATCH;
    • the adapter does not query an RPC to discover chain identity.

    This check is configuration/provenance validation, not live-chain evidence.

    7. Structured, secret-safe errors

    All adapter failures are MossAdapterError values with stable fields:

    • code: MossAdapterErrorCode;
    • operation (describe, quote, action, simulate, or buildInfo);
    • safe protocolId/method context when they match the bounded identifier
      grammar;
    • retryable boolean;
    • a stable public message.

    The code set is closed for #25 and includes INVALID_INPUT,
    CHAIN_ID_MISMATCH, SOURCE_CONTRACT_VIOLATION, UNSUPPORTED_PROTOCOL,
    UNSUPPORTED_METHOD, DESCRIBE_FAILED, QUOTE_FAILED, ACTION_FAILED, and
    SIMULATION_FAILED.

    Driver exceptions are converted to the corresponding stable code. Raw error
    objects, RPC URLs, headers, account values, private keys, API keys, params,
    capabilities, receipts, and original exception messages are never stored in or
    returned by the public error. Tests inject secret-looking sentinel strings and
    assert that they do not occur in message, enumerable fields, or serialized
    error output.

    8. Production and Fake behavior

    createProductionMossPort(bindings) creates the production boundary around
    server-only MossSourceBindings. Each method:

    1. validates the operation identifiers and chain identity;
    2. delegates exactly once to the binding;
    3. preserves the returned Moss raw value by identity where the contract calls
      for exact preservation;
    4. creates only the explicitly allowed derived envelope fields;
    5. converts failures to the closed secret-safe error contract.

    It performs no quote ranking, capability digesting, simulation mapping,
    alignment, decision, STOP, MANUAL_REVIEW, RPC, wallet, signing, or transaction
    work.

    createFakeMossPort(config) accepts only inline synthetic operation, quote,
    capability, and simulation values and implements the same method signatures,
    chain validation, source/derived labels, and error shape. It is a deterministic
    development double, never a Moss/Monad fixture and never real evidence. Fake
    values are not exported as product data.

    9. Server-only and browser boundary

    packages/moss-adapter is a server-only package. Its runtime entry imports
    server-only and is built for the Node/Next server condition. The browser
    condition must fail closed; no adapter runtime is imported by apps/web client
    code.

    The public-entry smoke runs once with the Node react-server condition and
    once as a normal browser-like import that must fail with the server-only guard.
    The existing Web bundle scan remains mandatory and must find no
    @moss-mini-demo/moss-adapter, @themoss/*, vendor/moss, or Moss build-info
    marker in browser output. No browser API, UI, Web orchestration, or Clear402
    surface is added by #25.

    10. Exact repository writable list

    The implementation may modify exactly these 18 repository paths, and no other
    path:

    1. package.json
    2. pnpm-lock.yaml
    3. packages/moss-adapter/package.json
    4. packages/moss-adapter/tsconfig.json
    5. packages/moss-adapter/tsconfig.build.json
    6. packages/moss-adapter/src/types.ts
    7. packages/moss-adapter/src/errors.ts
    8. packages/moss-adapter/src/build-info.ts
    9. packages/moss-adapter/src/source-bindings.ts
    10. packages/moss-adapter/src/production.ts
    11. packages/moss-adapter/src/fake.ts
    12. packages/moss-adapter/src/index.ts
    13. packages/moss-adapter/test/contracts.test.ts
    14. packages/moss-adapter/test/errors.test.ts
    15. packages/moss-adapter/test/production.test.ts
    16. packages/moss-adapter/test/fake.test.ts
    17. packages/moss-adapter/test/server-only.test.ts
    18. packages/moss-adapter/test/public-entry.smoke.mjs

    pnpm-workspace.yaml is an explicitly audited metadata file but requires zero
    content change: the existing packages/* entry already registers the exact
    adapter package and the existing allowBuilds policy is unchanged. Adding a
    vendor workspace entry, a second build-script permission, or a new workspace
    glob is forbidden. If implementation discovers that a pnpm-workspace change is
    actually necessary, it stops and requests a revised Scope Gate instead of
    expanding this list.

    No changes are allowed to vendor/moss contents or gitlink, .gitmodules,
    .github/workflows/quality-gate.yml, ADRs, report-schema, decision-engine,
    fixtures, Web/API files, governance, permissions, branch protection, Issue,
    Project, Milestone, README.md, or docs/real-vs-mock.md.

    11. Required package metadata and root scripts

    packages/moss-adapter/package.json is a private workspace package with one
    public . export and only the existing server-only runtime dependency. It
    must not add @themoss/*, a registry Moss package, a new third-party package,
    or a subpath export.

    The lockfile changes only by adding the adapter workspace importer and the
    resolved server-only entry if it is not already present. No unrelated lockfile
    refresh is accepted.

    Root package.json changes are limited to the established clean-checkout
    ordering:

    • build: report-schema, decision-engine, moss-adapter, then web;
    • typecheck: prepare report-schema, run the root strict no-emit check, then
      adapter and web package checks;
    • test:package-import: retain existing report-schema and decision-engine
      smokes and append the adapter public-entry smoke;
    • check: retain the existing quality-gate sequence and contents; it remains
      the only CI entry point.

    The adapter package has explicit build and typecheck scripts. No prebuild,
    pretypecheck, postinstall, or other hidden lifecycle script is introduced.
    No workflow edit or second build-script permission is introduced.

    12. Tests and evidence

    All tests use inline synthetic values and bounded error sentinels. No real
    address, private key, API key, RPC result, quote, receipt, wallet, or chain
    record is used.

    Required coverage:

    • public types/envelopes preserve exact Moss-original values and distinguish
      Mini-Demo-derived fields;
    • operation contracts retain Stub and loaded risk labels without putting labels
      on CapabilityNode;
    • raw quote remains unselected and NOT_NORMALIZED;
    • capability snapshot is independent and frozen, raw capability is unchanged,
      and integrity is explicitly NOT_EVALUATED;
    • simulation remains raw and NOT_MAPPED;
    • production and fake implement the same five methods and return identical
      contract shapes;
    • chain id 143 succeeds and missing/non-143 ids fail closed;
    • every closed error code has deterministic, secret-safe serialization;
    • driver failures never leak secret-looking values and delegation is exactly
      once;
    • input objects and raw references are not mutated;
    • both implementations return the fixed M2-03: Pin reproducible Moss dependency #24 build info;
    • server-only positive/negative import behavior works under Node 22;
    • adapter package import through @moss-mini-demo/moss-adapter succeeds after
      build and never through a private source path.

    13. Implementation sequence after authorization

    1. Reconfirm origin/main and create the exact branch/worktree named above.
    2. Add the workspace package metadata and the fixed type/error/build-info
      contracts.
    3. Add the injected Production boundary and inline-only Fake using the same
      MossPort.
    4. Add package tests and the public-entry/server-only smoke.
    5. Update only the root scripts and the adapter importer in the lockfile.
    6. Inspect the exact diff against the baseline; any path outside the 18-item
      list is a stop condition.

    14. Verification from a clean clone

    Run on Node 22.23.1 and pnpm 11.16.0, from a fresh isolated checkout with
    no pre-existing dist:

    node --version
    pnpm --version
    pnpm install --frozen-lockfile
    pnpm --filter @moss-mini-demo/moss-adapter build
    pnpm --filter @moss-mini-demo/moss-adapter typecheck
    pnpm vitest run packages/moss-adapter/test
    pnpm test:package-import
    pnpm build
    pnpm typecheck
    pnpm test
    pnpm check
    pnpm test:web:bundle
    pnpm test:web:prod
    git diff --check origin/main...HEAD
    git diff --name-only origin/main...HEAD
    git status --short

    The production start/health commands are regression checks for the existing
    Web baseline; #25 must not change its API contract. The expected changed-path
    set must be exactly the 18 paths above. The existing quality-gate workflow,
    with its unchanged name, trigger scope, and contents: read permission, must
    pass on the exact pushed head. Any CI result from another head is not evidence.

    15. Acceptance, stop conditions, and rollback

    Acceptance requires all of the following:

    • Maintainer Scope Gate explicitly accepts this plan and the dependency
      decision;
    • exact 18-path diff and no submodule/gitlink/workflow/lockfile drift outside
      the adapter importer;
    • package-name import smoke and server-only/browser scans pass on Node 22;
    • adapter build, typecheck, tests, root check, Web production smoke, and
      exact-head quality-gate all pass;
    • no public API beyond the listed entry and types;
    • no claims of live Moss, Monad, RPC, wallet, signing, transaction, safety,
      approval, authorization, or Decision evidence.

    Stop immediately and return to the Maintainer if:

    • main differs from the baseline before branch creation;
    • M2-03: Pin reproducible Moss dependency #24's pinned submodule commit or MossBuildInfo changes;
    • implementation needs a direct package-manager/vendor dependency, a workflow
      permission, a second build-script permission, a new public helper, or any
      path outside the 18-item list;
    • a test requires real chain data or an unapproved fixture;
    • an error would expose a secret or raw source exception;
    • the adapter would need to select quotes, compute a digest, map simulation,
      align evidence, or make a Decision.

    Rollback is a single revert of the #25 implementation commit (or deletion of
    only the exact #25 branch/PR before merge). Never revert #24, #32, main,
    required checks, or the submodule gitlink as part of #25.

    16. Explicit non-goals

    #25 does not implement Quote selection, Capability digest, simulation mapper,
    Alignment, Decision, STOP, MANUAL_REVIEW, Web/API orchestration, RPC or
    live-chain access, Clear402, wallet, signing, transaction construction or
    submission, database, deployment, UI, fixtures, or changes to #8, #9, #20,
    #23, or any M3 task.

    17. Requested decision

    Please record one of:

    • SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED, with this exact path list and
      dependency direction accepted; or
    • SCOPE_CHANGES_REQUESTED, naming the path, API, or dependency decision that
      must change.

    Until the first decision is recorded, Builder status is
    WORK_PLAN_SUBMITTED / AWAITING_MAINTAINER_SCOPE_CONFIRMATION and no
    implementation action is authorized.

  6. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SCOPE_CHANGES_REQUESTED

    Reviewed Work Plan: #25 (comment)

    Planning baseline: main@1e42babfa457ad20ac1efcecca227aceb4995c2b

    Reviewed Work Plan body SHA-256: 9dbbfc567c45b0e2d8939f5fc6985a2cba7023451c2e1ce8859266fb42bdb47e

    The following Scope Gate checks pass:

    • the writable set is closed at exactly 18 paths;
    • vendor/moss remains the organization submodule gitlink at exact commit 1ae6b6322d51fae9104f047efb94e601050b967f, with https://github.com/Moss-Mini-Demo/moss.git and no branch, tag, floating ref, copied source, or package-manager Moss dependency;
    • the root workspace remains only packages/* and apps/*; vendor/moss is not absorbed into it;
    • no new npm package or build permission is proposed beyond the existing server-only@0.0.1 link and unchanged sole 'sharp@0.34.5': true policy;
    • apps/web and its API contracts are read-only regression targets, not writable implementation scope;
    • Production and Fake implement the same single MossPort and five methods;
    • quote selection, capability digest/integrity, simulation mapping, Alignment, Decision, STOP and MANUAL_REVIEW work remain deferred to M2-05: Implement quote collection and deterministic selection #26-M2-10: Assemble DecisionInput, PreflightReport and presentation model #31;
    • the package exposes only @moss-mini-demo/moss-adapter through the . public entry;
    • the planned tests cover exact original-value identity, independent frozen snapshots, non-mutation, derived/original separation and secret-safe failures.

    One verification blocker prevents implementation authorization:

    • Section 14 calls pnpm test:web:prod, but no such script exists on the frozen baseline. The approved root production smoke command is pnpm test:web:production.

    Required correction:

    1. Replace pnpm test:web:prod with the existing pnpm test:web:production command throughout the complete Work Plan.
    2. Do not add a test:web:prod alias or otherwise expand package.json; root script changes remain limited to the ordering and adapter public-entry additions already listed.
    3. Preserve the exact baseline, 18 writable paths, dependencies, build permission, public surface, port contract, tests and non-goals without a second revision axis.

    Submit a complete revised Work Plan as a new comment so this reviewed plan remains an audit record. No implementation is authorized from the current plan. Until a Maintainer records SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED for the revision, do not create the branch, worktree, file change, dependency update, commit, push, or PR.

    #25 remains Open, assigned to pillowtalk-Qy, and Project In Progress for planning only. This is not QA, Review, READY_TO_MERGE, Merge Gate, or merge authorization.

  7. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    Revised Final Implementation Work Plan - M2-04 Moss Adapter Ports - Awaiting Maintainer Scope Confirmation

    Revision source: SCOPE_CHANGES_REQUESTED. This complete revision preserves the exact baseline, 18 writable paths, dependencies, public surface, port contract, tests, risk boundaries, and non-goals. Its only scope delta is correcting the production-smoke script name to the baseline existing pnpm test:web:production; the historical Work Plan remains unchanged as an audit record.

    0. Status and authority

    Source: Issue #25, the accepted M2 dependency record for #24, and the current
    M2 execution-slot assignment. This is a planning artifact only. It requests a
    new Maintainer Scope Gate; it is not scope confirmation or implementation
    authorization.

    Exact planning baseline:

    • origin/main@1e42babfa457ad20ac1efcecca227aceb4995c2b
    • Main commit: feat: add Web API baseline and strict contracts (#71)
    • Existing pinned Moss submodule commit from M2-03: Pin reproducible Moss dependency #24:
      vendor/moss@1ae6b6322d51fae9104f047efb94e601050b967f
    • Proposed branch after Maintainer scope confirmation:
      codex/issue-25-moss-adapter-ports
    • Proposed isolated worktree after authorization:
      /Users/qy/Documents/moss-mini-demo-issue-25

    No branch, worktree, file change, dependency update, commit, push, or PR is
    created by this comment. In Progress and Ready are not Scope Confirmed,
    implementation authorization, QA PASS, Review, Merge Gate, or merge
    authorization.

    This plan supersedes no prior implementation and does not delete history. It
    is a closed proposal for #25 only. The Builder stops until a Maintainer records
    an explicit SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED decision.

    1. Goal and closed boundary

    Create the package @moss-mini-demo/moss-adapter as the sole documented public
    entry for the Moss integration boundary. The package will define the common
    MossPort, raw evidence envelopes, structured secret-safe adapter errors,
    fixed MossBuildInfo, and offline Production and Fake implementations
    with the same port interface.

    The adapter preserves source values and provenance. It does not decide whether
    a quote is selected, whether a capability is safe, or whether an action may be
    executed. It is an offline boundary package, not a runnable product, wallet,
    RPC client, or live-chain integration.

    2. Exact Moss dependency and provenance decision

    The accepted #24 submodule remains the only Moss source of record:

    • gitlink path: vendor/moss;
    • repository: https://github.com/Moss-Mini-Demo/moss.git;
    • exact pinned commit: 1ae6b6322d51fae9104f047efb94e601050b967f;
    • no tracked branch, tag, or floating ref;
    • the M2-03: Pin reproducible Moss dependency #24 integration-fork and patchset identity remain those recorded in
      docs/moss-dependency.md.

    The adapter package will not put @themoss/core, @themoss/simulator, Kuru,
    or Pancake into its package manifest, and the root lockfile will not resolve
    any legacy registry package. In particular, @themoss/core@0.1.0 from the
    legacy npm Plan API is explicitly rejected.

    The exact dependency direction for this issue is:

    pinned vendor/moss build -> server-owned MossSourceBindings -> moss-adapter

    MossSourceBindings is an internal, server-only structural binding. It accepts
    raw values produced by the exact pinned Moss build and is injected into
    ProductionMossPort; the adapter never imports vendor/moss by a filesystem
    path and never copies Moss source. There is intentionally no file:, link:,
    git URL, registry dependency, or TypeScript path from the root package to the
    submodule. This is required because #24's quality gate builds the submodule,
    then deinitializes vendor/moss before the root frozen install. A later,
    separately authorized integration task may provide the composition binding;
    that task is outside #25.

    The adapter records the exact #24 MossBuildInfo and rejects a binding whose
    reported source identity or chain id is not compatible with that record. Tests
    use inline synthetic bindings only; they are not Moss or chain evidence.

    3. Sole public entry and exported surface

    packages/moss-adapter/package.json exposes only the . entry. It exposes no
    subpath exports and no private source path. The public entry is
    @moss-mini-demo/moss-adapter.

    Runtime exports are limited to:

    • createProductionMossPort;
    • createFakeMossPort;
    • MossAdapterError;
    • MOSS_BUILD_INFO.

    Type exports are limited to the port, input, raw evidence, build-info, source
    binding, and error-code contracts named in this plan:

    • MossPort, MossSourceBindings, QuoteInput, ActionInput;
    • RawOperationContract, RawQuote, RawCapability,
      RawCapabilityEvidence, RawSimulationEvidence;
    • MossBuildInfo, MossOriginalSource, MiniDemoDerivedSource;
    • MossAdapterErrorCode, ChainId143.

    No runtime Schema, Decision helper, quote-selection helper, capability digest,
    simulation mapper, or unapproved public helper is added.

    4. Fixed public port

    The only runtime port contract is:

    interface MossPort {
      describe(protocolId: string, method: string): Promise<RawOperationContract>;
      quote(protocolId: string, input: QuoteInput): Promise<RawQuote>;
      action(protocolId: string, input: ActionInput): Promise<RawCapabilityEvidence>;
      simulate(capability: RawCapability): Promise<RawSimulationEvidence>;
      buildInfo(): MossBuildInfo;
    }

    ProductionMossPort and FakeMossPort implement this exact interface. The
    adapter does not add a second port, overload the methods with product policy,
    or expose a way to bypass the port.

    QuoteInput and ActionInput carry the protocol/method operation context and
    opaque JSON-safe request parameters. The adapter does not select among quotes,
    validate user intent, create a wallet action, or send an action.

    5. Raw evidence contracts and layering

    All evidence has two explicit layers. mossOriginal is an exact, opaque value
    from the pinned Moss source. miniDemoDerived contains only fields derived by
    this adapter boundary and is labelled as such. The adapter never relabels a
    derived value as Moss evidence.

    RawOperationContract contains:

    • protocolId and method as the requested operation identifiers;
    • mossOriginal.stub, preserving the exact loaded Moss Stub object/value;
    • mossOriginal.riskLabels, preserving the exact loaded risk labels;
    • miniDemoDerived, containing only the normalized protocol, method, operation
      kind, and a copied risk-label view for local transport;
    • the exact MossBuildInfo and source context.

    Risk labels remain an operation/Stub property. They are never copied onto a
    CapabilityNode, interpreted as a capability digest, or used to make a
    Decision.

    RawQuote contains the operation contract, the exact raw quote in
    mossOriginal.value, and a miniDemoDerived status of
    NOT_NORMALIZED/DEFERRED_TO_M2_05. It is one raw quote result; collection and
    selection belong to #26.

    RawCapabilityEvidence contains:

    • the operation contract;
    • the exact raw Capability value in mossOriginal.value;
    • an independent snapshot made from that raw value without changing the raw
      value or claiming cryptographic integrity;
    • miniDemoDerived.integrity with status NOT_EVALUATED and an explicit
      DEFERRED_TO_M2_06 reason;
    • source context and exact build info.

    The snapshot is only an independently owned, deep-frozen transport copy. No
    canonical serialization, digest, capability mutation, or trust decision is
    implemented here. Digest and integrity verification remain #27.

    RawSimulationEvidence contains the exact raw simulation result and source
    context in mossOriginal, plus a miniDemoDerived status
    NOT_MAPPED/DEFERRED_TO_M2_07. It does not map receipts, outcomes, coverage,
    alignment, or Decision fields. Simulation mapping remains #28.

    Every envelope is JSON-safe at its public boundary. Non-JSON values or a source
    object that cannot be snapshotted are rejected with a structured contract
    error; no coercion silently changes the evidence.

    6. Build information and chain identity

    MOSS_BUILD_INFO is the exact immutable #24 identity, including source mode,
    upstream and integration repository, the pinned Moss commit, patchset digest,
    package versions, and officialRelease: false. buildInfo() returns this
    same contract from both implementations.

    Chain identity is an explicit adapter responsibility:

    • the only accepted chain id is the literal 143 (ChainId143);
    • ProductionMossPort validates the injected binding's declared chain id before
      any method delegates;
    • FakeMossPort validates its configured chain id at construction;
    • a missing, non-integer, or non-143 value fails closed with
      CHAIN_ID_MISMATCH;
    • the adapter does not query an RPC to discover chain identity.

    This check is configuration/provenance validation, not live-chain evidence.

    7. Structured, secret-safe errors

    All adapter failures are MossAdapterError values with stable fields:

    • code: MossAdapterErrorCode;
    • operation (describe, quote, action, simulate, or buildInfo);
    • safe protocolId/method context when they match the bounded identifier
      grammar;
    • retryable boolean;
    • a stable public message.

    The code set is closed for #25 and includes INVALID_INPUT,
    CHAIN_ID_MISMATCH, SOURCE_CONTRACT_VIOLATION, UNSUPPORTED_PROTOCOL,
    UNSUPPORTED_METHOD, DESCRIBE_FAILED, QUOTE_FAILED, ACTION_FAILED, and
    SIMULATION_FAILED.

    Driver exceptions are converted to the corresponding stable code. Raw error
    objects, RPC URLs, headers, account values, private keys, API keys, params,
    capabilities, receipts, and original exception messages are never stored in or
    returned by the public error. Tests inject secret-looking sentinel strings and
    assert that they do not occur in message, enumerable fields, or serialized
    error output.

    8. Production and Fake behavior

    createProductionMossPort(bindings) creates the production boundary around
    server-only MossSourceBindings. Each method:

    1. validates the operation identifiers and chain identity;
    2. delegates exactly once to the binding;
    3. preserves the returned Moss raw value by identity where the contract calls
      for exact preservation;
    4. creates only the explicitly allowed derived envelope fields;
    5. converts failures to the closed secret-safe error contract.

    It performs no quote ranking, capability digesting, simulation mapping,
    alignment, decision, STOP, MANUAL_REVIEW, RPC, wallet, signing, or transaction
    work.

    createFakeMossPort(config) accepts only inline synthetic operation, quote,
    capability, and simulation values and implements the same method signatures,
    chain validation, source/derived labels, and error shape. It is a deterministic
    development double, never a Moss/Monad fixture and never real evidence. Fake
    values are not exported as product data.

    9. Server-only and browser boundary

    packages/moss-adapter is a server-only package. Its runtime entry imports
    server-only and is built for the Node/Next server condition. The browser
    condition must fail closed; no adapter runtime is imported by apps/web client
    code.

    The public-entry smoke runs once with the Node react-server condition and
    once as a normal browser-like import that must fail with the server-only guard.
    The existing Web bundle scan remains mandatory and must find no
    @moss-mini-demo/moss-adapter, @themoss/*, vendor/moss, or Moss build-info
    marker in browser output. No browser API, UI, Web orchestration, or Clear402
    surface is added by #25.

    10. Exact repository writable list

    The implementation may modify exactly these 18 repository paths, and no other
    path:

    1. package.json
    2. pnpm-lock.yaml
    3. packages/moss-adapter/package.json
    4. packages/moss-adapter/tsconfig.json
    5. packages/moss-adapter/tsconfig.build.json
    6. packages/moss-adapter/src/types.ts
    7. packages/moss-adapter/src/errors.ts
    8. packages/moss-adapter/src/build-info.ts
    9. packages/moss-adapter/src/source-bindings.ts
    10. packages/moss-adapter/src/production.ts
    11. packages/moss-adapter/src/fake.ts
    12. packages/moss-adapter/src/index.ts
    13. packages/moss-adapter/test/contracts.test.ts
    14. packages/moss-adapter/test/errors.test.ts
    15. packages/moss-adapter/test/production.test.ts
    16. packages/moss-adapter/test/fake.test.ts
    17. packages/moss-adapter/test/server-only.test.ts
    18. packages/moss-adapter/test/public-entry.smoke.mjs

    pnpm-workspace.yaml is an explicitly audited metadata file but requires zero
    content change: the existing packages/* entry already registers the exact
    adapter package and the existing allowBuilds policy is unchanged. Adding a
    vendor workspace entry, a second build-script permission, or a new workspace
    glob is forbidden. If implementation discovers that a pnpm-workspace change is
    actually necessary, it stops and requests a revised Scope Gate instead of
    expanding this list.

    No changes are allowed to vendor/moss contents or gitlink, .gitmodules,
    .github/workflows/quality-gate.yml, ADRs, report-schema, decision-engine,
    fixtures, Web/API files, governance, permissions, branch protection, Issue,
    Project, Milestone, README.md, or docs/real-vs-mock.md.

    11. Required package metadata and root scripts

    packages/moss-adapter/package.json is a private workspace package with one
    public . export and only the existing server-only runtime dependency. It
    must not add @themoss/*, a registry Moss package, a new third-party package,
    or a subpath export.

    The lockfile changes only by adding the adapter workspace importer and the
    resolved server-only entry if it is not already present. No unrelated lockfile
    refresh is accepted.

    Root package.json changes are limited to the established clean-checkout
    ordering:

    • build: report-schema, decision-engine, moss-adapter, then web;
    • typecheck: prepare report-schema, run the root strict no-emit check, then
      adapter and web package checks;
    • test:package-import: retain existing report-schema and decision-engine
      smokes and append the adapter public-entry smoke;
    • check: retain the existing quality-gate sequence and contents; it remains
      the only CI entry point.

    The adapter package has explicit build and typecheck scripts. No prebuild,
    pretypecheck, postinstall, or other hidden lifecycle script is introduced.
    No workflow edit or second build-script permission is introduced.

    12. Tests and evidence

    All tests use inline synthetic values and bounded error sentinels. No real
    address, private key, API key, RPC result, quote, receipt, wallet, or chain
    record is used.

    Required coverage:

    • public types/envelopes preserve exact Moss-original values and distinguish
      Mini-Demo-derived fields;
    • operation contracts retain Stub and loaded risk labels without putting labels
      on CapabilityNode;
    • raw quote remains unselected and NOT_NORMALIZED;
    • capability snapshot is independent and frozen, raw capability is unchanged,
      and integrity is explicitly NOT_EVALUATED;
    • simulation remains raw and NOT_MAPPED;
    • production and fake implement the same five methods and return identical
      contract shapes;
    • chain id 143 succeeds and missing/non-143 ids fail closed;
    • every closed error code has deterministic, secret-safe serialization;
    • driver failures never leak secret-looking values and delegation is exactly
      once;
    • input objects and raw references are not mutated;
    • both implementations return the fixed M2-03: Pin reproducible Moss dependency #24 build info;
    • server-only positive/negative import behavior works under Node 22;
    • adapter package import through @moss-mini-demo/moss-adapter succeeds after
      build and never through a private source path.

    13. Implementation sequence after authorization

    1. Reconfirm origin/main and create the exact branch/worktree named above.
    2. Add the workspace package metadata and the fixed type/error/build-info
      contracts.
    3. Add the injected Production boundary and inline-only Fake using the same
      MossPort.
    4. Add package tests and the public-entry/server-only smoke.
    5. Update only the root scripts and the adapter importer in the lockfile.
    6. Inspect the exact diff against the baseline; any path outside the 18-item
      list is a stop condition.

    14. Verification from a clean clone

    Run on Node 22.23.1 and pnpm 11.16.0, from a fresh isolated checkout with
    no pre-existing dist:

    node --version
    pnpm --version
    pnpm install --frozen-lockfile
    pnpm --filter @moss-mini-demo/moss-adapter build
    pnpm --filter @moss-mini-demo/moss-adapter typecheck
    pnpm vitest run packages/moss-adapter/test
    pnpm test:package-import
    pnpm build
    pnpm typecheck
    pnpm test
    pnpm check
    pnpm test:web:bundle
    pnpm test:web:production
    git diff --check origin/main...HEAD
    git diff --name-only origin/main...HEAD
    git status --short

    The production start/health commands are regression checks for the existing
    Web baseline; #25 must not change its API contract. The expected changed-path
    set must be exactly the 18 paths above. The existing quality-gate workflow,
    with its unchanged name, trigger scope, and contents: read permission, must
    pass on the exact pushed head. Any CI result from another head is not evidence.

    15. Acceptance, stop conditions, and rollback

    Acceptance requires all of the following:

    • Maintainer Scope Gate explicitly accepts this plan and the dependency
      decision;
    • exact 18-path diff and no submodule/gitlink/workflow/lockfile drift outside
      the adapter importer;
    • package-name import smoke and server-only/browser scans pass on Node 22;
    • adapter build, typecheck, tests, root check, Web production smoke, and
      exact-head quality-gate all pass;
    • no public API beyond the listed entry and types;
    • no claims of live Moss, Monad, RPC, wallet, signing, transaction, safety,
      approval, authorization, or Decision evidence.

    Stop immediately and return to the Maintainer if:

    • main differs from the baseline before branch creation;
    • M2-03: Pin reproducible Moss dependency #24's pinned submodule commit or MossBuildInfo changes;
    • implementation needs a direct package-manager/vendor dependency, a workflow
      permission, a second build-script permission, a new public helper, or any
      path outside the 18-item list;
    • a test requires real chain data or an unapproved fixture;
    • an error would expose a secret or raw source exception;
    • the adapter would need to select quotes, compute a digest, map simulation,
      align evidence, or make a Decision.

    Rollback is a single revert of the #25 implementation commit (or deletion of
    only the exact #25 branch/PR before merge). Never revert #24, #32, main,
    required checks, or the submodule gitlink as part of #25.

    16. Explicit non-goals

    #25 does not implement Quote selection, Capability digest, simulation mapper,
    Alignment, Decision, STOP, MANUAL_REVIEW, Web/API orchestration, RPC or
    live-chain access, Clear402, wallet, signing, transaction construction or
    submission, database, deployment, UI, fixtures, or changes to #8, #9, #20,
    #23, or any M3 task.

    17. Requested decision

    Please record one of:

    • SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED, with this exact path list and
      dependency direction accepted; or
    • SCOPE_CHANGES_REQUESTED, naming the path, API, or dependency decision that
      must change.

    Until the first decision is recorded, Builder status is
    WORK_PLAN_SUBMITTED / AWAITING_MAINTAINER_SCOPE_CONFIRMATION and no
    implementation action is authorized.

  8. pillowtalk-Qy commented on Aug 5, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SCOPE_CONFIRMED / IMPLEMENTATION_AUTHORIZED

    Authorized Work Plan: #25 (comment)

    Implementation baseline: main@1e42babfa457ad20ac1efcecca227aceb4995c2b

    Authorized Work Plan body SHA-256: bab5c67b4cb56f87e929c738549a3420620dafa0f58b4bf42666065757fc4a6d

    Maintainer Scope Gate result: PASS.

    The complete revised Work Plan is authorized with these frozen boundaries:

    • exactly the 18 writable paths enumerated in the revised Work Plan; no wildcard or 19th path;
    • vendor/moss remains the independent organization submodule at exact gitlink 1ae6b6322d51fae9104f047efb94e601050b967f; no gitlink, .gitmodules, vendor-source, tracked-ref, root-workspace, npm Moss dependency or source-copy change;
    • no new third-party dependency and no build-permission change; the existing sole 'sharp@0.34.5': true policy remains unchanged;
    • exactly one documented public entry, @moss-mini-demo/moss-adapter through export . only, with the runtime and type exports listed in the Work Plan;
    • Production and Fake implement the same single MossPort and five methods, with fixed chain-id, source/derived, build-info and secret-safe error boundaries;
    • original Moss values remain identity-preserved and unmodified; only the independent transport snapshot may be deep-copied/frozen, and tests must prove the distinction;
    • quote selection, capability digest/integrity, simulation mapping, Alignment, Decision, STOP, MANUAL_REVIEW, Web/API orchestration and all M2-05: Implement quote collection and deterministic selection #26-M2-10: Assemble DecisionInput, PreflightReport and presentation model #31 behavior remain outside M2-04: Create moss-adapter package and public ports #25;
    • apps/web remains read-only, while its public import, browser-bundle and production-start/health checks remain mandatory regressions;
    • clean verification uses the corrected existing command pnpm test:web:production; no alias or additional root script is authorized.

    Builder Qy may now re-fetch and confirm the exact baseline, create only codex/issue-25-moss-adapter-ports in the planned isolated worktree, implement the authorized scope, and open one Draft PR with Closes #25 only. If main changes before branching, or another path, dependency, permission, public export, port behavior or later-Issue semantic becomes necessary, stop and request a new Maintainer Scope Gate.

    This record authorizes implementation only. It is not Pre-PR QA, Review, READY_TO_MERGE, Merge Gate, or merge authorization. The implementation PR must remain Draft until exact-head QA handoff and subsequent Maintainer review.

    #25 remains Open, assigned to pillowtalk-Qy, and Project In Progress. No downstream Issue is released by this authorization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions