| 1 | # Contracts: Docs templates, Fichas merge, native signing |
| 2 | |
| 3 | Status: **proposal, revision 1, 2026-10-25**. Author: GPT-6 / Codex. |
| 4 | Not an implementation plan or an approved change to suite authority. |
| 5 | Independent GPT-6 review accepted this as a scoped discovery/design |
| 6 | proposal, with four clarifications incorporated below. This is not |
| 7 | approval to implement issuance or native signing. No application code or |
| 8 | deployed configuration is changed by this document. |
| 9 | |
| 10 | ## 1. Outcome and authority |
| 11 | |
| 12 | Paul requested a contract authored in Docs, personalised from Fichas, and |
| 13 | sent for signature. On 2026-10-25 Paul confirmed Fichas is live and asked |
| 14 | to proceed; when asked about the signing implementation, he chose |
| 15 | **native signing in Oficina**. The narrower implementation choices below |
| 16 | are this session's proposals, not decisions attributed to Paul. |
| 17 | |
| 18 | The first usable milestone is one customer, one template, and a preview. |
| 19 | The next is one agreement issued to one external signer and returned to |
| 20 | the customer's card as completed. Batch issuance follows the working |
| 21 | single-agreement lifecycle. Suite-wide API, CLI and MCP design remains a |
| 22 | separate workstream; these operations must eventually be usable by those |
| 23 | clients without recreating business logic in each transport. |
| 24 | |
| 25 | Canonical dependencies, read after fetching on 2026-10-25: |
| 26 | |
| 27 | | Source | Revision | Relevant boundary | |
| 28 | |---|---|---| |
| 29 | | Suite sharing doctrine | revision 8, `094de9c0733e908c944e958d852cc583f5b78ea5` | §4.1–4.3, §5, §7, §7.1, §11 gates 6b and 7 | |
| 30 | | Docs | `c6602122601d2dcbfcc24ba9b625dda1852d22bc` on `origin/main` | existing editor, encrypted content, access checks, PDF export, Home bridge; Docs design §14 and §14a | |
| 31 | | Fichas | `714409257562048ad97fb0fc0b4148acfcce9b4b` on `origin/design/rulings-2026-09-19` | card/field/entry implementation, record revisions, sealed values, standalone admission | |
| 32 | | Suite producer proposal | `design/producer-protocol`, discussion [10](https://amadan.net/oficina/suite/discussions/10) | proposed producer integration; not an implemented service | |
| 33 | | External sharing requirement | suite discussion [12](https://amadan.net/oficina/suite/discussions/12) | Paul’s document-scoped isolation requirement; architecture remains unresolved | |
| 34 | |
| 35 | Those doctrine sections are cited, not replaced by local paraphrases. |
| 36 | No new sibling credential, private-item transfer, issuance permission or |
| 37 | external-signing grant is authorised merely by this draft. |
| 38 | |
| 39 | ## 2. Verified starting point |
| 40 | |
| 41 | The public Fichas `/api/version` returned `7144092`; the Docs endpoint |
| 42 | returned `v0.1.0-40-gce29703`. These are endpoint observations, not an |
| 43 | authenticated end-to-end test. Docs main is ahead of the observed release. |
| 44 | Fichas main is still `fab37e4`, a design-only commit; the live code is on |
| 45 | the branch above. Feature work must explicitly name its base and cannot |
| 46 | silently treat that branch as main or merge unrelated work into main. |
| 47 | |
| 48 | Fichas has card types, configurable fields/layouts, customer records and |
| 49 | entries. Its configuration still rejects `FICHAS_SHAPE=suite`. Its mounted |
| 50 | routes do not implement S2/S3 or a contract handoff. Docs has PDF and |
| 51 | Markdown export but no template fields, personalised preview, handoff |
| 52 | receipt/commit, provenance enforcement, agreement store or signing flow. |
| 53 | An app switcher or Home link is not evidence those integrations exist. |
| 54 | |
| 55 | ## 3. Product flow |
| 56 | |
| 57 | 1. In Docs, mark a document as a template and insert named fields. Bind |
| 58 | customer fields using stable Fichas field keys, showing their labels. |
| 59 | Contract-specific inputs such as a start date are separate from CRM |
| 60 | fields. Changing a field label must not break a binding. |
| 61 | 2. From a Fichas customer, choose **Prepare contract**, select a template, |
| 62 | and enter any contract-specific values. Selection exposes only templates |
| 63 | this person can use. Displaying their titles is itself an authorised read. |
| 64 | 3. Docs shows the resolved contract, customer and template revisions, |
| 65 | unresolved fields and explicit formatting errors. A separate preview |
| 66 | renders the actual PDF bytes. A preview cannot send invitations. |
| 67 | 4. Once issuance exists, the sender names the signer, reviews those same |
| 68 | bytes, and explicitly issues the agreement. A changed source requires a |
| 69 | new preview; issue must not silently re-merge against a newer source. |
| 70 | 5. The signer verifies control of their named address, reads the issued |
| 71 | document, accepts the displayed signing consent, and confirms signing. |
| 72 | 6. Fichas shows agreement status with a link to Docs. Completed document |
| 73 | and evidence are available to authorised participants from Docs. |
| 74 | |
| 75 | Prepare/preview is a useful release without issue/sign controls. The first |
| 76 | release must not display a functioning-looking send button backed by a |
| 77 | stub or ordinary public document link. |
| 78 | |
| 79 | ## 4. Ownership and records |
| 80 | |
| 81 | **Proposal: Docs owns templates and agreements; Fichas owns customer |
| 82 | records and references to agreements.** No new app is required for this |
| 83 | first workflow. An agreement is not an editable Doc with a status flag. |
| 84 | Its access paths, transitions and immutable payload are separate. |
| 85 | |
| 86 | Proposed records, not a migration prescription: |
| 87 | |
| 88 | - Template definition: document ID, schema version, field bindings and |
| 89 | signer-role anchors. Rendering pins the document content revision and |
| 90 | the binding revision together. |
| 91 | - Preparation: owner/actor, customer reference and revision, template |
| 92 | reference and revision, selected values and manual inputs, locale, |
| 93 | renderer version, provenance, PDF bytes and digest, expiry. Seal content |
| 94 | and personal data under the receiving app's normal content protection. |
| 95 | - Agreement: preparation reference, exact issued payload and digest, |
| 96 | issuer, named recipients/roles, issue timestamp and lifecycle state. |
| 97 | - Agreement events: attributed transitions with server timestamps, |
| 98 | previous state/version, payload digest, and reasons where appropriate. |
| 99 | - Signing evidence: agreement/payload identity, recipient identity, |
| 100 | verification method and time, consent text/version and affirmative |
| 101 | action. It must identify what was signed without storing bearer secrets. |
| 102 | - Delivery outbox: invitation/completion jobs with stable deduplication |
| 103 | keys, retry state and delivery outcomes. Delivery is not signing. |
| 104 | - Fichas reference: Docs instance and agreement ID. Any status projection |
| 105 | identifies its last observed revision/time and reports unavailable or |
| 106 | stale status honestly. It holds no duplicate PDF. |
| 107 | |
| 108 | Reference visibility and status retrieval require agreement access, not |
| 109 | just access to the customer card. Recipients, agreement titles and state |
| 110 | must not leak to another card reader. Recheck after team departure or |
| 111 | participant revocation; an obsolete projection cannot preserve access. |
| 112 | |
| 113 | Preparation retention is proposed at 24 hours, to let a sender return the |
| 114 | next day without making abandoned drafts a permanent copy. Reauthorise |
| 115 | each access; expiry is not permission to serve a revoked source. Purge |
| 116 | expired payloads on reads and in scheduled maintenance. Define the backup |
| 117 | retirement bound before deploying this storage. Issued-record retention, |
| 118 | withdrawal and deletion are separate decisions required before issuance; |
| 119 | do not inherit temporary-preparation expiry for signed records. |
| 120 | |
| 121 | ## 5. Template and rendering contract |
| 122 | |
| 123 | Use explicit inline field nodes in the document schema, not global string |
| 124 | replacement on HTML or a PDF. Field IDs are stable; labels are editable. |
| 125 | Fields cannot execute expressions, fetch URLs or recursively expand |
| 126 | values that happen to contain field syntax. Rendering treats values as |
| 127 | text. Rich-text content is not accepted as a customer field in this slice. |
| 128 | |
| 129 | Start with text, date and integer-minor-unit money inputs with an explicit |
| 130 | currency. Preserve numeric zero; distinguish missing from an empty value. |
| 131 | Required missing values, removed fields, incompatible types and unsupported |
| 132 | formatting block successful preview. Optional fields have explicit empty |
| 133 | behaviour. Date-only values never pass through a timezone conversion. |
| 134 | Locale and currency are selected once and included in the preparation. |
| 135 | No conditions, repeating tables or formulas in the first slice. |
| 136 | |
| 137 | Preview produces a new resolved representation and leaves the original |
| 138 | template unchanged. The existing PDF exporter is the initial renderer, |
| 139 | subject to tests for the supported document subset. Unsupported node |
| 140 | types and missing glyph substitutions must be visible blocking errors for |
| 141 | issuance; the existing export route's log-only warning is insufficient. |
| 142 | |
| 143 | Persist the PDF being reviewed. Issue freezes those bytes; completion |
| 144 | preserves them and attaches evidence, rather than regenerating the original |
| 145 | from a changed renderer/template. If a completion PDF adds a signature |
| 146 | page, it is a separate derivative with both original and final digests. |
| 147 | This draft does not claim a PDF certificate signature or any particular |
| 148 | legal assurance level. |
| 149 | |
| 150 | ## 6. Cross-app preparation prerequisites |
| 151 | |
| 152 | The live standalone instances do not yet satisfy the suite integration |
| 153 | needed for this workflow. Reuse the Home identity/membership contracts and |
| 154 | the suite's producer/handoff designs; do not derive trust from matching |
| 155 | email strings, the shared DNS suffix, or an unrestricted service token. |
| 156 | |
| 157 | Before preview is enabled for real customer records, the implementation |
| 158 | must demonstrate all of the following against the actual app middleware: |
| 159 | |
| 160 | - A named identity and membership recognised by both apps, with the |
| 161 | configured instances belonging to the same authorised team. |
| 162 | - The Fichas source authorises the precise record/revision and selected |
| 163 | values for the relevant operation. An unavailable source cannot become |
| 164 | an empty but apparently successful merge. |
| 165 | - Docs authorises template use and the resulting preparation. Customer |
| 166 | visibility and template visibility are independent checks. |
| 167 | - A concrete transport for the selected data and provenance that satisfies |
| 168 | the cited suite sections, including receipt/commit and sign-in resume. |
| 169 | S2 alone is not a data-transfer grant, and the current S3 scope must not |
| 170 | be widened to private records for convenience. |
| 171 | - Source revisions and content are read consistently. Receipt stores |
| 172 | bounded, expiring pending state; commit is bound to the same authenticated |
| 173 | browser/person and to the exact server-held payload. |
| 174 | - Every preparation disclosure, including PDF/thumbnail/download and |
| 175 | resumed tabs, enforces the source rules. No anonymous preview links. |
| 176 | |
| 177 | Choosing the precise source transport is gated on the missing producer and |
| 178 | identity integration; a naked cross-origin form carrying customer values |
| 179 | is not a substitute. This proposal therefore does not invent routes or |
| 180 | declare an implementation-ready wire protocol before those dependencies |
| 181 | are resolved. A local renderer fixture is useful development work but |
| 182 | does not pass the integrated-preview milestone. |
| 183 | |
| 184 | ## 7. Native issuance: required suite decision |
| 185 | |
| 186 | The proposed new boundary is **explicit issuance of an independent |
| 187 | agreement**, distinct from a source-dependent preparation. Once issued, |
| 188 | editing or deleting a customer card must not mutate the bytes a recipient |
| 189 | was asked to sign. A participant's access to the issued agreement must not |
| 190 | require access to CRM notes or the source template. |
| 191 | |
| 192 | This needs a reviewed extension to the suite doctrine, specifically §7, |
| 193 | and must satisfy the external-isolation requirement in suite discussion |
| 194 | 12. The proposal is: |
| 195 | |
| 196 | - Require an explicit, auditable authority to issue the template body, |
| 197 | selected customer values and every transitive source in their provenance. |
| 198 | Permission merely to read or internally use them is not permission to release them |
| 199 | independently. The first implementation may restrict issue to owners, |
| 200 | but must define what ownership means in both apps and verify it there. |
| 201 | - Record the approved source revisions, fields, payload digest and named |
| 202 | recipients at the issuance boundary. A source change or loss of authority |
| 203 | before issuance invalidates preparation and demands a fresh review. |
| 204 | - Issuance creates recipient-scoped access to this agreement only, hosted |
| 205 | by its owning Docs instance. It does not grant team membership, general |
| 206 | Docs access, or access to the original customer/template. |
| 207 | - Subsequent source changes do not invalidate this separately authorised |
| 208 | record. Agreement withdrawal, participant access revocation and retention |
| 209 | are explicit lifecycle actions, not accidental consequences of editing |
| 210 | unrelated records. |
| 211 | |
| 212 | These are proposed product semantics, not an exception this app can apply |
| 213 | unilaterally. **No send/sign implementation may ship before the suite |
| 214 | extension and the external-isolation design are reviewed.** Merely adding |
| 215 | a database permission flag does not fulfil discussion 12. |
| 216 | |
| 217 | The suite design must define the authoritative issuance point and the |
| 218 | semantics of a concurrent source update/revocation. Revalidation in one |
| 219 | app followed by a local transaction in another is not atomic cross-app |
| 220 | authorisation. Define whether the source supplies a bounded, irrevocable |
| 221 | release authorisation or a coordinated commit mechanism, including crash, |
| 222 | timeout and retry behaviour, before prescribing an implementation. |
| 223 | |
| 224 | ## 8. Signing lifecycle and reliability |
| 225 | |
| 226 | First-release proposal: one issuer, one named external signer, one fixed |
| 227 | document. Email verification identifies control of an address; it is not |
| 228 | represented as proof of corporate signing authority. Signing is a separate |
| 229 | affirmative action after verification and document review. Opening an |
| 230 | email link, a scanner fetch, or rendering a page never signs anything. |
| 231 | |
| 232 | Proposed agreement states: `issued`, `completed`, `declined`, `voided`, |
| 233 | `expired`. Preparations have their own lifecycle. Invitation delivery |
| 234 | status is independent, so a failed email cannot be mistaken for an |
| 235 | unissued agreement or a completed one. A completed agreement cannot be |
| 236 | rewritten or reopened; corrections require a new agreement with a link to |
| 237 | the previous one. Countersigning and signing order are later slices. |
| 238 | |
| 239 | Issue commits an immutable payload, recipient set and delivery outbox job |
| 240 | atomically. Its idempotency key is scoped to actor and operation and bound |
| 241 | to the request digest; reuse with different input is a conflict. Network |
| 242 | retries return the existing result. Delivery retries reuse the invitation |
| 243 | job; no claim of exactly-once email transport. |
| 244 | |
| 245 | Sign/decline/void/expire use a conditional state/version transition. A |
| 246 | concurrent terminal action has one winner; signature, evidence and state |
| 247 | commit together. Confirmation binds the recipient and exact payload |
| 248 | digest; it must fail after withdrawal or expiry. Tokens are expiring, |
| 249 | purpose-bound and stored only as hashes. Invitation and verified session |
| 250 | secrets are redacted from logs and referrers. Signing-session and document |
| 251 | access rules require their own adversarial design review before code. |
| 252 | |
| 253 | ## 9. Acceptance evidence and sequencing |
| 254 | |
| 255 | This is a dependency order for design, not an approved implementation plan. |
| 256 | |
| 257 | | Milestone | Evidence required | |
| 258 | |---|---| |
| 259 | | Template fields | field nodes survive editing/save/reload; rename preserves binding; missing/type errors are actionable; literal markup remains text; source template unchanged | |
| 260 | | 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 | |
| 261 | | Issue | suite boundary approved; exact reviewed PDF and source revisions frozen; revalidation failures refuse; double-click/retry yields one agreement; outbox survives restart | |
| 262 | | Sign | verified named recipient; affirmative consent bound to original digest; scanners do nothing; concurrent sign/void safe; recipient cannot enumerate or access unrelated content | |
| 263 | | Completion | immutable original and evidence retrievable by intended participants; Fichas link/status correct; outages show stale/unavailable; storage/backup and deletion rules tested | |
| 264 | |
| 265 | Browser coverage must include JavaScript disabled for preparation forms, |
| 266 | handoff confirmation and signing, keyboard navigation, and narrow-screen |
| 267 | review. Native field-node editing/rendering compatibility must be resolved |
| 268 | before enabling template editing in clients that cannot preserve the new |
| 269 | schema. Never silently drop fields in an older client or an export. |
| 270 | |
| 271 | The review/signing design must also provide an accessible reading path |
| 272 | for the exact issued content. Keyboard access to a PDF viewer alone is not |
| 273 | sufficient: specify reading order and assistive-technology support, and |
| 274 | how any alternative representation is bound to the reviewed PDF so it |
| 275 | cannot present different contract terms. |
| 276 | |
| 277 | Useful independent implementation work after design review is the typed |
| 278 | field/renderer layer. The integrated milestone still depends on real |
| 279 | source authorisation and handoff; unit tests and simulated signing cannot |
| 280 | be reported as the completed workflow. |
| 281 | |
| 282 | ## 10. Next design outputs |
| 283 | |
| 284 | 1. Resolve the suite boundary for independently issued agreements, |
| 285 | alongside discussion 12's required isolation mechanism and explicit |
| 286 | issued-record retention/access policy. |
| 287 | 2. Specify the authenticated Fichas-to-Docs preview transport against the |
| 288 | actual Home and producer implementations. State what source rungs the |
| 289 | first release supports; do not claim all cards/templates by default. |
| 290 | 3. Review a concrete document-field schema and rendering compatibility |
| 291 | design, then produce the implementation plan for the preview slice. |
| 292 | 4. Review the recipient identity, consent and evidence design before |
| 293 | shipping native signing. Keep the wider API/CLI/MCP work separate. |
| 294 | |
| 295 | ## 11. Independent review record |
| 296 | |
| 297 | GPT-6 / Codex, separate `contract_design_review` agent, 2026-10-25: |
| 298 | acceptable as a scoped discovery/design proposal, not approval to implement |
| 299 | issuance or signing. No blocking factual error found in inspected fetched |
| 300 | refs. Clarifications incorporated: issuance authority includes template and |
| 301 | transitive sources; cross-app revocation race needs an authoritative commit |
| 302 | boundary; card visibility does not grant agreement-status visibility; PDF |
| 303 | review needs an accessible equivalent tied to the issued content. The |
| 304 | reviewer did not repeat live endpoint or discussion-12 checks; those remain |
| 305 | author-session observations. |
| 306 | |
| 307 | ## 12. Implementation progress, 2026-10-26 |
| 308 | |
| 309 | Paul asked to proceed. The first implemented unit is the bounded internal |
| 310 | template renderer specified in `2026-10-26-contract-rendering-design.md`: |
| 311 | structural fields, typed values, exact integer money, strict validation, |
| 312 | PDF fidelity checks, byte/digest output and resource limits. Its independent |
| 313 | GPT-6 code review approved that scope subject to repository gates. |
| 314 | |
| 315 | This is not a user-facing template editor or the integrated Fichas preview. |
| 316 | The live editor schema remains unchanged to avoid dropping fields in older |
| 317 | native clients. Source authorisation, handoff, preparation persistence, |
| 318 | authoring UI and native signing are still required. The first renderer uses |
| 319 | explicit ISO formatting; locale-specific formatting is not yet supported. |
| 320 | |