Building an Agreement from Your Code

An assistant that runs in your project, such as Claude Code, Codex, GitHub Copilot in VS Code or Gemini CLI, can build an agreement from your code, so the agreement fits your app as it is. This page is what the assistant follows before it writes anything: what it reads, the brief it shows you, and the questions it asks. Once you have answered, the authoring loop applies unchanged.

Start it in your own words, for example "Build the agreement our app sends when a lease is renewed, from our code and the PDFs in ./forms." In a client that shows MCP prompts, you can instead start the author_agreement_from_code prompt. In Claude Code, with the server added as signstack, that is /mcp__signstack__author_agreement_from_code. Run it on its own: the assistant asks which agreement to build, and you answer in your next message. Claude Code passes each word typed after the command as a separate argument, so a description typed there arrives cut up.

1. Read the code first

The assistant reads your code before it plans, looking for:

In your code What it decides
Your app's calls to SignStack: where it creates workflows (REST or a client library), with the blueprint key and version, the input keys and the object built for each, the mode (Run or Review) and the envelopes it sends The blueprint's key, a version the call finds, its input keys, and schemas that accept the objects as your code builds them. A call pinned to 1.0.0 works with a first publish
Resources it reads by key, such as a template it fetches Those keys must exist
What it reads back: webhook handlers, the events they handle, the fields they read and what they do next The envelope the handler waits on is one that completes. See the envelope events' data
The models behind each input: field names, types, formats (an amount already formatted as text, or a number), allowed values, and which values can be missing The schemas, and which fields can be filled from data
The parties: who signs at this point in the app, where their names and emails come from, and anyone who signs somewhere else The participants and their roles
Conditions: code that picks a document or a signer, such as an addendum only for some offers or a second signer only when there is one An includeIf on the document or the step
Test data: fixtures, seeds and factories The scenarios

Through the MCP server, it then uploads each PDF (create_upload_url) and saves it as an asset draft, and it reads every page of each PDF itself: the blanks, the checkboxes, the PDF's own form fields, and the signature, initials and date lines. Those uploads and asset drafts are the only things it writes before you answer. With the CLI, a PDF stays a local file (file: ./path) until you push, and nothing is written before you answer.

2. The brief

Before it writes any schema, template or blueprint, the assistant shows you a brief, with the file and line that shows each point:

  • The contract: each of your app's calls, and what it relies on.
  • Inputs: each blueprint input, the model it comes from, its formats, and which values can be missing.
  • Documents: each document, and when it is included.
  • Parties and order: who signs, in which order, and where each name and email comes from.
  • The field plan: for each PDF, what the assistant found on its pages (blanks, checkboxes, form fields, signature, initials and date lines), and what fills each one: an input, a party (a role), or no one.
  • Defaults: what it chose where the code was clear but you may decide otherwise.
  • Questions: see below.

What the code settles, the brief states and does not ask. A short example, for an app that renews leases:

Contract
- src/leases/renewal.ts:41  POST /workflows: blueprint lease_renewal, version 1.0.0,
  inputs tenant, unit, terms; mode Review.
- src/webhooks/signstack.ts:18  on envelope.completed for renewal_envelope, stores the signed PDF
  → the blueprint's envelope is renewal_envelope, and it completes.

Inputs
- tenant ← Tenant (src/models/tenant.ts:7); coTenantEmail is optional.
- terms ← RenewalTerms (src/models/terms.ts:12); rent is a number, in cents.

Documents
- renewal_agreement: always.
- pet_addendum: when terms.petsAllowed (src/leases/renewal.ts:55).

Parties and order
- tenant_1 from tenant.email; tenant_2 from tenant.coTenantEmail, only when present.
  Both at once.

Field plan: renewal_agreement.pdf (4 pages)
- 31 blanks, 6 checkboxes, 2 signature lines, 2 date lines.
- 24 filled from inputs; 4 each for tenant_1 and tenant_2.
- The landlord's signature and date: question 1.

Defaults
- Rent printed in dollars with $formatNumber.

Questions
1. The landlord's signature and date (page 4). The app sends only to tenants
   (renewal.ts:62) and emails the signed copy to the landlord (signstack.ts:30).
   a) The landlord signs in this envelope, after the tenants.
   b) Keep the fields under a landlord role that no step assigns: they print empty,
      and the landlord signs the copy they receive.
   c) No fields: the report lists the two lines.
   Recommended: b, because it matches what the app does today.

3. Questions, in one round

A question is:

  • who signs, in what order, and which documents are conditional. These are always asked, even when the code points one way: they are cheap to confirm and costly to redo;
  • any decision the code does not settle, or allows more than one way of making, such as two models that could feed one input, or a document the code mentions but never sends;
  • a party who appears on a document but whose signing the code does not show;
  • anything in your app that would have to change for the agreement to work.

Each question gives its options, the evidence for each, and the option the assistant recommends. All of them come in one round, before anything is built. An assistant with a question tool uses it; others list the questions in the chat. A new decision that comes up while it builds is asked when it comes up.

A party who signs somewhere else (on paper, in another app, in a later envelope) has three routes:

  • They sign in this envelope. They become a participant with a step.
  • Their fields exist, but no step assigns their role. Nothing refuses this. Each signer is given only the fields of their own role, so no one is asked to fill these, and they print empty. In Review mode, a reviewer can still fill them before sending.
  • Their lines get no fields. The final report lists each one.

4. Build

Once you have answered, the assistant follows the authoring loop. For an agreement built from code, it also:

  • Matches the contract exactly: the blueprint key and version, the input keys, and the envelopes your app sends and waits on.
  • Never changes your app. When something in the app would have to change, it tells you what, and asks.
  • Puts a field on every blank, checkbox, form field, signature, initials and date line, unless you named the fields you want. A field is filled from an input only where your data has the value; the rest are left for the party who completes them. check_render judges only the fields placed, so before it reports, the assistant goes page by page and checks that each blank, checkbox and form field has one.
  • Writes scenarios from your test data that cover every conditional document and step, so each one is checked and previewed at least once before publishing.

5. The report

The assistant finishes with:

  • The contract, met: each of your app's calls, and each thing it reads back, beside what in the agreement satisfies it (blueprint and version, input, envelope);
  • What is left unfilled: every field filled by no input and assigned to no one, and every blank, checkbox or line left without a field, each with the reason;
  • What changed since the brief, and why;
  • The checks: the scenarios and previews, and what is published and what is still a draft.

After publishing, with your agreement, it can start one test workflow in a test namespace with the inputs your app sends (in Review mode, if your app uses it) and read it back with get_workflow. Then the first real call is not the first test.

When your code changes later

When a model gains a field, or the app starts sending a new document, ask again. The assistant reads the code the same way and compares it with the published agreement (get_resource with its dependencies). It then proposes the changes as a new draft, with a brief of what moves.