oficina / docs Public

Design contract preparation and native signing boundaries

Paul Campbell pushed by paul@keymail.dev 0dd62595ee93c612a12c7f4a8a44ff9e396f63b8 parent c660212
1 file changed, +305 −0
  • docs/superpowers/specs/2026-10-25-contract-workflow-design.md +305 −0

CI passed — run details

diff --git a/docs/superpowers/specs/2026-10-25-contract-workflow-design.md b/docs/superpowers/specs/2026-10-25-contract-workflow-design.md
new file mode 100644
index 0000000..7e4929a
--- /dev/null
+++ b/docs/superpowers/specs/2026-10-25-contract-workflow-design.md
@@ -0,0 +1,305 @@
+# Contracts: Docs templates, Fichas merge, native signing
+
+Status: **proposal, revision 1, 2026-10-25**. Author: GPT-6 / Codex.
+Not an implementation plan or an approved change to suite authority.
+Independent GPT-6 review accepted this as a scoped discovery/design
+proposal, with four clarifications incorporated below. This is not
+approval to implement issuance or native signing. No application code or
+deployed configuration is changed by this document.
+
+## 1. Outcome and authority
+
+Paul requested a contract authored in Docs, personalised from Fichas, and
+sent for signature. On 2026-10-25 Paul confirmed Fichas is live and asked
+to proceed; when asked about the signing implementation, he chose
+**native signing in Oficina**. The narrower implementation choices below
+are this session's proposals, not decisions attributed to Paul.
+
+The first usable milestone is one customer, one template, and a preview.
+The next is one agreement issued to one external signer and returned to
+the customer's card as completed. Batch issuance follows the working
+single-agreement lifecycle. Suite-wide API, CLI and MCP design remains a
+separate workstream; these operations must eventually be usable by those
+clients without recreating business logic in each transport.
+
+Canonical dependencies, read after fetching on 2026-10-25:
+
+| Source | Revision | Relevant boundary |
+|---|---|---|
+| Suite sharing doctrine | revision 8, `094de9c0733e908c944e958d852cc583f5b78ea5` | §4.1–4.3, §5, §7, §7.1, §11 gates 6b and 7 |
+| Docs | `c6602122601d2dcbfcc24ba9b625dda1852d22bc` on `origin/main` | existing editor, encrypted content, access checks, PDF export, Home bridge; Docs design §14 and §14a |
+| Fichas | `714409257562048ad97fb0fc0b4148acfcce9b4b` on `origin/design/rulings-2026-09-19` | card/field/entry implementation, record revisions, sealed values, standalone admission |
+| Suite producer proposal | `design/producer-protocol`, discussion [10](https://amadan.net/oficina/suite/discussions/10) | proposed producer integration; not an implemented service |
+| External sharing requirement | suite discussion [12](https://amadan.net/oficina/suite/discussions/12) | Paul’s document-scoped isolation requirement; architecture remains unresolved |
+
+Those doctrine sections are cited, not replaced by local paraphrases.
+No new sibling credential, private-item transfer, issuance permission or
+external-signing grant is authorised merely by this draft.
+
+## 2. Verified starting point
+
+The public Fichas `/api/version` returned `7144092`; the Docs endpoint
+returned `v0.1.0-40-gce29703`. These are endpoint observations, not an
+authenticated end-to-end test. Docs main is ahead of the observed release.
+Fichas main is still `fab37e4`, a design-only commit; the live code is on
+the branch above. Feature work must explicitly name its base and cannot
+silently treat that branch as main or merge unrelated work into main.
+
+Fichas has card types, configurable fields/layouts, customer records and
+entries. Its configuration still rejects `FICHAS_SHAPE=suite`. Its mounted
+routes do not implement S2/S3 or a contract handoff. Docs has PDF and
+Markdown export but no template fields, personalised preview, handoff
+receipt/commit, provenance enforcement, agreement store or signing flow.
+An app switcher or Home link is not evidence those integrations exist.
+
+## 3. Product flow
+
+1. In Docs, mark a document as a template and insert named fields. Bind
+ customer fields using stable Fichas field keys, showing their labels.
+ Contract-specific inputs such as a start date are separate from CRM
+ fields. Changing a field label must not break a binding.
+2. From a Fichas customer, choose **Prepare contract**, select a template,
+ and enter any contract-specific values. Selection exposes only templates
+ this person can use. Displaying their titles is itself an authorised read.
+3. Docs shows the resolved contract, customer and template revisions,
+ unresolved fields and explicit formatting errors. A separate preview
+ renders the actual PDF bytes. A preview cannot send invitations.
+4. Once issuance exists, the sender names the signer, reviews those same
+ bytes, and explicitly issues the agreement. A changed source requires a
+ new preview; issue must not silently re-merge against a newer source.
+5. The signer verifies control of their named address, reads the issued
+ document, accepts the displayed signing consent, and confirms signing.
+6. Fichas shows agreement status with a link to Docs. Completed document
+ and evidence are available to authorised participants from Docs.
+
+Prepare/preview is a useful release without issue/sign controls. The first
+release must not display a functioning-looking send button backed by a
+stub or ordinary public document link.
+
+## 4. Ownership and records
+
+**Proposal: Docs owns templates and agreements; Fichas owns customer
+records and references to agreements.** No new app is required for this
+first workflow. An agreement is not an editable Doc with a status flag.
+Its access paths, transitions and immutable payload are separate.
+
+Proposed records, not a migration prescription:
+
+- Template definition: document ID, schema version, field bindings and
+ signer-role anchors. Rendering pins the document content revision and
+ the binding revision together.
+- Preparation: owner/actor, customer reference and revision, template
+ reference and revision, selected values and manual inputs, locale,
+ renderer version, provenance, PDF bytes and digest, expiry. Seal content
+ and personal data under the receiving app's normal content protection.
+- Agreement: preparation reference, exact issued payload and digest,
+ issuer, named recipients/roles, issue timestamp and lifecycle state.
+- Agreement events: attributed transitions with server timestamps,
+ previous state/version, payload digest, and reasons where appropriate.
+- Signing evidence: agreement/payload identity, recipient identity,
+ verification method and time, consent text/version and affirmative
+ action. It must identify what was signed without storing bearer secrets.
+- Delivery outbox: invitation/completion jobs with stable deduplication
+ keys, retry state and delivery outcomes. Delivery is not signing.
+- Fichas reference: Docs instance and agreement ID. Any status projection
+ identifies its last observed revision/time and reports unavailable or
+ stale status honestly. It holds no duplicate PDF.
+
+Reference visibility and status retrieval require agreement access, not
+just access to the customer card. Recipients, agreement titles and state
+must not leak to another card reader. Recheck after team departure or
+participant revocation; an obsolete projection cannot preserve access.
+
+Preparation retention is proposed at 24 hours, to let a sender return the
+next day without making abandoned drafts a permanent copy. Reauthorise
+each access; expiry is not permission to serve a revoked source. Purge
+expired payloads on reads and in scheduled maintenance. Define the backup
+retirement bound before deploying this storage. Issued-record retention,
+withdrawal and deletion are separate decisions required before issuance;
+do not inherit temporary-preparation expiry for signed records.
+
+## 5. Template and rendering contract
+
+Use explicit inline field nodes in the document schema, not global string
+replacement on HTML or a PDF. Field IDs are stable; labels are editable.
+Fields cannot execute expressions, fetch URLs or recursively expand
+values that happen to contain field syntax. Rendering treats values as
+text. Rich-text content is not accepted as a customer field in this slice.
+
+Start with text, date and integer-minor-unit money inputs with an explicit
+currency. Preserve numeric zero; distinguish missing from an empty value.
+Required missing values, removed fields, incompatible types and unsupported
+formatting block successful preview. Optional fields have explicit empty
+behaviour. Date-only values never pass through a timezone conversion.
+Locale and currency are selected once and included in the preparation.
+No conditions, repeating tables or formulas in the first slice.
+
+Preview produces a new resolved representation and leaves the original
+template unchanged. The existing PDF exporter is the initial renderer,
+subject to tests for the supported document subset. Unsupported node
+types and missing glyph substitutions must be visible blocking errors for
+issuance; the existing export route's log-only warning is insufficient.
+
+Persist the PDF being reviewed. Issue freezes those bytes; completion
+preserves them and attaches evidence, rather than regenerating the original
+from a changed renderer/template. If a completion PDF adds a signature
+page, it is a separate derivative with both original and final digests.
+This draft does not claim a PDF certificate signature or any particular
+legal assurance level.
+
+## 6. Cross-app preparation prerequisites
+
+The live standalone instances do not yet satisfy the suite integration
+needed for this workflow. Reuse the Home identity/membership contracts and
+the suite's producer/handoff designs; do not derive trust from matching
+email strings, the shared DNS suffix, or an unrestricted service token.
+
+Before preview is enabled for real customer records, the implementation
+must demonstrate all of the following against the actual app middleware:
+
+- A named identity and membership recognised by both apps, with the
+ configured instances belonging to the same authorised team.
+- The Fichas source authorises the precise record/revision and selected
+ values for the relevant operation. An unavailable source cannot become
+ an empty but apparently successful merge.
+- Docs authorises template use and the resulting preparation. Customer
+ visibility and template visibility are independent checks.
+- A concrete transport for the selected data and provenance that satisfies
+ the cited suite sections, including receipt/commit and sign-in resume.
+ S2 alone is not a data-transfer grant, and the current S3 scope must not
+ be widened to private records for convenience.
+- Source revisions and content are read consistently. Receipt stores
+ bounded, expiring pending state; commit is bound to the same authenticated
+ browser/person and to the exact server-held payload.
+- Every preparation disclosure, including PDF/thumbnail/download and
+ resumed tabs, enforces the source rules. No anonymous preview links.
+
+Choosing the precise source transport is gated on the missing producer and
+identity integration; a naked cross-origin form carrying customer values
+is not a substitute. This proposal therefore does not invent routes or
+declare an implementation-ready wire protocol before those dependencies
+are resolved. A local renderer fixture is useful development work but
+does not pass the integrated-preview milestone.
+
+## 7. Native issuance: required suite decision
+
+The proposed new boundary is **explicit issuance of an independent
+agreement**, distinct from a source-dependent preparation. Once issued,
+editing or deleting a customer card must not mutate the bytes a recipient
+was asked to sign. A participant's access to the issued agreement must not
+require access to CRM notes or the source template.
+
+This needs a reviewed extension to the suite doctrine, specifically §7,
+and must satisfy the external-isolation requirement in suite discussion
+12. The proposal is:
+
+- Require an explicit, auditable authority to issue the template body,
+ selected customer values and every transitive source in their provenance.
+ Permission merely to read or internally use them is not permission to release them
+ independently. The first implementation may restrict issue to owners,
+ but must define what ownership means in both apps and verify it there.
+- Record the approved source revisions, fields, payload digest and named
+ recipients at the issuance boundary. A source change or loss of authority
+ before issuance invalidates preparation and demands a fresh review.
+- Issuance creates recipient-scoped access to this agreement only, hosted
+ by its owning Docs instance. It does not grant team membership, general
+ Docs access, or access to the original customer/template.
+- Subsequent source changes do not invalidate this separately authorised
+ record. Agreement withdrawal, participant access revocation and retention
+ are explicit lifecycle actions, not accidental consequences of editing
+ unrelated records.
+
+These are proposed product semantics, not an exception this app can apply
+unilaterally. **No send/sign implementation may ship before the suite
+extension and the external-isolation design are reviewed.** Merely adding
+a database permission flag does not fulfil discussion 12.
+
+The suite design must define the authoritative issuance point and the
+semantics of a concurrent source update/revocation. Revalidation in one
+app followed by a local transaction in another is not atomic cross-app
+authorisation. Define whether the source supplies a bounded, irrevocable
+release authorisation or a coordinated commit mechanism, including crash,
+timeout and retry behaviour, before prescribing an implementation.
+
+## 8. Signing lifecycle and reliability
+
+First-release proposal: one issuer, one named external signer, one fixed
+document. Email verification identifies control of an address; it is not
+represented as proof of corporate signing authority. Signing is a separate
+affirmative action after verification and document review. Opening an
+email link, a scanner fetch, or rendering a page never signs anything.
+
+Proposed agreement states: `issued`, `completed`, `declined`, `voided`,
+`expired`. Preparations have their own lifecycle. Invitation delivery
+status is independent, so a failed email cannot be mistaken for an
+unissued agreement or a completed one. A completed agreement cannot be
+rewritten or reopened; corrections require a new agreement with a link to
+the previous one. Countersigning and signing order are later slices.
+
+Issue commits an immutable payload, recipient set and delivery outbox job
+atomically. Its idempotency key is scoped to actor and operation and bound
+to the request digest; reuse with different input is a conflict. Network
+retries return the existing result. Delivery retries reuse the invitation
+job; no claim of exactly-once email transport.
+
+Sign/decline/void/expire use a conditional state/version transition. A
+concurrent terminal action has one winner; signature, evidence and state
+commit together. Confirmation binds the recipient and exact payload
+digest; it must fail after withdrawal or expiry. Tokens are expiring,
+purpose-bound and stored only as hashes. Invitation and verified session
+secrets are redacted from logs and referrers. Signing-session and document
+access rules require their own adversarial design review before code.
+
+## 9. Acceptance evidence and sequencing
+
+This is a dependency order for design, not an approved implementation plan.
+
+| Milestone | Evidence required |
+|---|---|
+| Template fields | field nodes survive editing/save/reload; rename preserves binding; missing/type errors are actionable; literal markup remains text; source template unchanged |
+| Integrated preview | real Fichas record through the agreed identity/producer/handoff path; real Docs template; actual PDF; sign-in resume; revoked access, wrong team, replay and expired pending state refused; no customer values in URLs/logs |
+| Issue | suite boundary approved; exact reviewed PDF and source revisions frozen; revalidation failures refuse; double-click/retry yields one agreement; outbox survives restart |
+| Sign | verified named recipient; affirmative consent bound to original digest; scanners do nothing; concurrent sign/void safe; recipient cannot enumerate or access unrelated content |
+| Completion | immutable original and evidence retrievable by intended participants; Fichas link/status correct; outages show stale/unavailable; storage/backup and deletion rules tested |
+
+Browser coverage must include JavaScript disabled for preparation forms,
+handoff confirmation and signing, keyboard navigation, and narrow-screen
+review. Native field-node editing/rendering compatibility must be resolved
+before enabling template editing in clients that cannot preserve the new
+schema. Never silently drop fields in an older client or an export.
+
+The review/signing design must also provide an accessible reading path
+for the exact issued content. Keyboard access to a PDF viewer alone is not
+sufficient: specify reading order and assistive-technology support, and
+how any alternative representation is bound to the reviewed PDF so it
+cannot present different contract terms.
+
+Useful independent implementation work after design review is the typed
+field/renderer layer. The integrated milestone still depends on real
+source authorisation and handoff; unit tests and simulated signing cannot
+be reported as the completed workflow.
+
+## 10. Next design outputs
+
+1. Resolve the suite boundary for independently issued agreements,
+ alongside discussion 12's required isolation mechanism and explicit
+ issued-record retention/access policy.
+2. Specify the authenticated Fichas-to-Docs preview transport against the
+ actual Home and producer implementations. State what source rungs the
+ first release supports; do not claim all cards/templates by default.
+3. Review a concrete document-field schema and rendering compatibility
+ design, then produce the implementation plan for the preview slice.
+4. Review the recipient identity, consent and evidence design before
+ shipping native signing. Keep the wider API/CLI/MCP work separate.
+
+## 11. Independent review record
+
+GPT-6 / Codex, separate `contract_design_review` agent, 2026-10-25:
+acceptable as a scoped discovery/design proposal, not approval to implement
+issuance or signing. No blocking factual error found in inspected fetched
+refs. Clarifications incorporated: issuance authority includes template and
+transitive sources; cross-app revocation race needs an authoritative commit
+boundary; card visibility does not grant agreement-status visibility; PDF
+review needs an accessible equivalent tied to the issued content. The
+reviewer did not repeat live endpoint or discussion-12 checks; those remain
+author-session observations.