Skip to content

feat(securities): express vesting & cliff in months instead of years - #562

Open
maxgubitosi wants to merge 1 commit into
captableinc:mainfrom
maxgubitosi:feat/vesting-cliff-in-months
Open

maxgubitosi wants to merge 1 commit into
captableinc:mainfrom
maxgubitosi:feat/vesting-cliff-in-months

Conversation

@maxgubitosi

@maxgubitosi maxgubitosi commented Jun 19, 2026 •

Copy link
Copy Markdown

Summary

Vesting and cliff durations for shares and stock options were previously entered and stored in years. This PR switches the unit to months (e.g. a 4-year grant with a 1-year cliff is now 48 months / 12 months), which is the granularity most grants actually use.

Changes

  • Schema — rename Share.{vestingYears,cliffYears} and Option.{vestingYears,cliffYears} to {vestingMonths,cliffMonths}.
  • Migration (20260619131445_vesting_cliff_in_months) — renames the columns and converts existing values from years to months (* 12), so existing rows keep the same real-world duration.
  • App — updates the Zod mutation schemas, the public OpenAPI schema, the add/get procedures for shares & options, and the share/option creation forms (the numeric input suffix now reads "month(s)").

Notes

  • There is no vesting math in the codebase today, so this is purely a unit / label / storage change.
  • ⚠️ API change: the public cliffYears / vestingYears fields are renamed to cliffMonths / vestingMonths (src/server/api/schema/shares.ts).

Testing

  • prisma generate regenerates cleanly with the renamed fields.
  • pnpm build (Next.js production build) passes with no type errors.

Summary by CodeRabbit

  • Updates
    • Vesting duration periods are now specified in months instead of years
    • Cliff duration periods are now specified in months instead of years
    • All existing vesting and cliff data has been automatically converted from years to months for consistency
    • Form inputs and interface displays updated to reflect month-based durations across shares and options

Vesting and cliff durations for shares and stock options were entered and
stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff
grant is now 48 months / 12 months).

- Rename the Share/Option `vestingYears`/`cliffYears` fields to
  `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the
  columns and converts existing values from years to months (x12).
- Update the Zod mutation schemas, the public OpenAPI schema, the add/get
  procedures for shares and options, and the share/option creation forms
  (the numeric input suffix now reads "month(s)").
- No vesting math exists in the app, so this is purely a unit/label/storage
  change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Thank you for following the naming conventions for pull request titles! 🙏

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Vesting and cliff duration fields are renamed from year-based (cliffYears, vestingYears) to month-based (cliffMonths, vestingMonths) across the entire stack. A database migration performs the column renames and multiplies existing stored values by 12. Corresponding changes are applied to Prisma schema, API/tRPC schemas, tRPC procedures, and UI form components.

Changes

Vesting/Cliff Duration: Years → Months

Layer / File(s) Summary
Database schema and migration
prisma/schema.prisma, prisma/migrations/.../migration.sql
Share and Option models rename cliffYears/vestingYears to cliffMonths/vestingMonths; the migration SQL renames the columns and multiplies existing values by 12.
API and tRPC input schemas
src/server/api/schema/shares.ts, src/trpc/routers/securities-router/schema.ts
ShareSchema, ZodAddOptionMutationSchema, and ZodAddShareMutationSchema replace the year-based fields with cliffMonths/vestingMonths, updating OpenAPI metadata and inferred TypeScript types.
tRPC read/write procedures
src/trpc/routers/securities-router/procedures/add-share.ts, add-option.ts, get-shares.ts, get-options.ts
Create payloads map the new month fields to the database; select clauses in the get procedures return the renamed fields. A debug console.log is also removed from add-share.
UI form components
src/components/securities/shares/steps/general-details.tsx, src/components/securities/options/steps/vesting-details.tsx
Zod form schemas and FormField bindings switch to cliffMonths/vestingMonths; NumericFormat unit suffixes change from "year(s)" to "month(s)".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, hooray — no more years in the way!
We measure in months now, twelve times the old day.
The cliff and the vesting, renamed with a squeak,
From schema to UI, the whole stack's unique.
A console.log vanished — cleaner, they say!
This rabbit approves of the month-based array. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting vesting and cliff duration units from years to months across the securities module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql (1)

10-20: ⚡ Quick win

Verify the rename and conversion run atomically.

If the migration runner does not wrap this file in one transaction, a failure after the renames but before both UPDATEs can leave month-named columns containing year-based values. Please verify the runner behavior or add an explicit transaction around these statements.

Atomic migration shape
+BEGIN;
+
 -- AlterTable
 ALTER TABLE "Share" RENAME COLUMN "vestingYears" TO "vestingMonths";
 ALTER TABLE "Share" RENAME COLUMN "cliffYears" TO "cliffMonths";
@@
 -- Convert existing durations from years to months
 UPDATE "Share" SET "vestingMonths" = "vestingMonths" * 12, "cliffMonths" = "cliffMonths" * 12;
 UPDATE "Option" SET "vestingMonths" = "vestingMonths" * 12, "cliffMonths" = "cliffMonths" * 12;
+
+COMMIT;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql`
around lines 10 - 20, The migration contains column renames followed by value
conversions that could leave the database in an inconsistent state if execution
fails between the ALTER TABLE and UPDATE statements. Wrap all the ALTER TABLE
statements (for both "Share" and "Option" tables renaming "vestingYears" to
"vestingMonths" and "cliffYears" to "cliffMonths") and the subsequent UPDATE
statements (that multiply the values by 12 for both tables) within an explicit
BEGIN TRANSACTION and COMMIT block to ensure all operations execute atomically,
so that either all changes succeed or all roll back together.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@prisma/schema.prisma`:
- Around line 693-694: The comment for cliffMonths incorrectly conflates "no
cliff" with "immediate vesting". Update the cliffMonths comment to clarify that
a value of 0 means "no cliff" (not immediate vesting), while keeping the
vestingMonths comment unchanged since it correctly states that 0 means immediate
vesting. Apply the same comment fix to the duplicate cliffMonths and
vestingMonths fields that appear later in the schema around lines 745-746.

In `@src/server/api/schema/shares.ts`:
- Around line 60-66: Update the schema validation for the month fields in
ShareSchema to enforce both integer and non-negative constraints. For both
cliffMonths and vestingMonths fields, change z.number() to
z.number().int().min(0) to match the Prisma model's Int type definition and
align with the internal tRPC/UI validation that already enforces these
constraints. This ensures the public API schema is consistent with the storage
layer and prevents invalid negative or fractional month values from being
accepted.

---

Nitpick comments:
In `@prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql`:
- Around line 10-20: The migration contains column renames followed by value
conversions that could leave the database in an inconsistent state if execution
fails between the ALTER TABLE and UPDATE statements. Wrap all the ALTER TABLE
statements (for both "Share" and "Option" tables renaming "vestingYears" to
"vestingMonths" and "cliffYears" to "cliffMonths") and the subsequent UPDATE
statements (that multiply the values by 12 for both tables) within an explicit
BEGIN TRANSACTION and COMMIT block to ensure all operations execute atomically,
so that either all changes succeed or all roll back together.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a1debd1-503d-44a4-81b2-a12279e33dc5

📥 Commits

Reviewing files that changed from the base of the PR and between b63006f and 3ac5b77.

📒 Files selected for processing (10)
  • prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql
  • prisma/schema.prisma
  • src/components/securities/options/steps/vesting-details.tsx
  • src/components/securities/shares/steps/general-details.tsx
  • src/server/api/schema/shares.ts
  • src/trpc/routers/securities-router/procedures/add-option.ts
  • src/trpc/routers/securities-router/procedures/add-share.ts
  • src/trpc/routers/securities-router/procedures/get-options.ts
  • src/trpc/routers/securities-router/procedures/get-shares.ts
  • src/trpc/routers/securities-router/schema.ts

Comment thread prisma/schema.prisma
Comment on lines +693 to +694
cliffMonths Int @default(0) // vesting cliff in months; 0 means immediate vesting
vestingMonths Int @default(0) // total vesting period in months; 0 means immediate vesting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify the zero-cliff semantics.

cliffMonths = 0 means “no cliff”, not necessarily immediate vesting when vestingMonths is still positive. Keep “immediate vesting” on vestingMonths = 0 only.

Proposed wording fix
-  cliffMonths   Int `@default`(0) // vesting cliff in months; 0 means immediate vesting
+  cliffMonths   Int `@default`(0) // vesting cliff in months; 0 means no cliff
   vestingMonths Int `@default`(0) // total vesting period in months; 0 means immediate vesting
-  cliffMonths   Int              `@default`(0) // vesting cliff in months; 0 means immediate vesting
+  cliffMonths   Int              `@default`(0) // vesting cliff in months; 0 means no cliff
   vestingMonths Int              `@default`(0) // total vesting period in months; 0 means immediate vesting

Also applies to: 745-746

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@prisma/schema.prisma` around lines 693 - 694, The comment for cliffMonths
incorrectly conflates "no cliff" with "immediate vesting". Update the
cliffMonths comment to clarify that a value of 0 means "no cliff" (not immediate
vesting), while keeping the vestingMonths comment unchanged since it correctly
states that 0 means immediate vesting. Apply the same comment fix to the
duplicate cliffMonths and vestingMonths fields that appear later in the schema
around lines 745-746.

Comment on lines +60 to +66
cliffMonths: z.number().openapi({
description: "Vesting cliff in months",
example: 12,
}),
vestingYears: z.number().openapi({
description: "Vesting Years",
example: 4,
vestingMonths: z.number().openapi({
description: "Total vesting period in months",
example: 48,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add integer and non-negative constraints to month fields in public API schema.

The ShareSchema uses z.number() for cliffMonths and vestingMonths, which accepts negative and fractional values. However, the Prisma model defines both as Int type, and internal tRPC/UI validation already enforces .min(0). Update the public API schema to match the storage and internal validation layer.

Proposed validation fix
-    cliffMonths: z.number().openapi({
+    cliffMonths: z.number().int().min(0).openapi({
       description: "Vesting cliff in months",
       example: 12,
     }),
-    vestingMonths: z.number().openapi({
+    vestingMonths: z.number().int().min(0).openapi({
       description: "Total vesting period in months",
       example: 48,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/api/schema/shares.ts` around lines 60 - 66, Update the schema
validation for the month fields in ShareSchema to enforce both integer and
non-negative constraints. For both cliffMonths and vestingMonths fields, change
z.number() to z.number().int().min(0) to match the Prisma model's Int type
definition and align with the internal tRPC/UI validation that already enforces
these constraints. This ensures the public API schema is consistent with the
storage layer and prevents invalid negative or fractional month values from
being accepted.

GabrielGoncalvesICE added a commit to smarthow/captable that referenced this pull request Dec 1, 2026
…einc#562) (#2)

* feat(securities): express vesting & cliff in months instead of years

Vesting and cliff durations for shares and stock options were entered and
stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff
grant is now 48 months / 12 months).

- Rename the Share/Option `vestingYears`/`cliffYears` fields to
  `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the
  columns and converts existing values from years to months (x12).
- Update the Zod mutation schemas, the public OpenAPI schema, the add/get
  procedures for shares and options, and the share/option creation forms
  (the numeric input suffix now reads "month(s)").
- No vesting math exists in the app, so this is purely a unit/label/storage
  change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(securities): validate vesting/cliff months as non-negative integers

Address upstream review feedback on captableinc#562:
- Public API ShareSchema, tRPC and form schemas now require whole,
  non-negative months, matching the Int columns.
- Clarify that cliffMonths = 0 means no cliff (not immediate vesting).
- Add unit tests for the months validation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: resolve tsconfig path aliases in vitest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(securities): format vesting months schema tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style(prisma): align Option fields after vesting rename

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Máximo Gubitosi <mgubitosi@udesa.edu.ar>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local>
GabrielGoncalvesICE added a commit to smarthow/captable that referenced this pull request Dec 1, 2026
…k deleting stakeholders with securities (upstream captableinc#561) (#11)

* feat(securities): express vesting & cliff in months instead of years

Vesting and cliff durations for shares and stock options were entered and
stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff
grant is now 48 months / 12 months).

- Rename the Share/Option `vestingYears`/`cliffYears` fields to
  `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the
  columns and converts existing values from years to months (x12).
- Update the Zod mutation schemas, the public OpenAPI schema, the add/get
  procedures for shares and options, and the share/option creation forms
  (the numeric input suffix now reads "month(s)").
- No vesting math exists in the app, so this is purely a unit/label/storage
  change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(securities): validate vesting/cliff months as non-negative integers

Address upstream review feedback on captableinc#562:
- Public API ShareSchema, tRPC and form schemas now require whole,
  non-negative months, matching the Int columns.
- Clarify that cliffMonths = 0 means no cliff (not immediate vesting).
- Add unit tests for the months validation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: wire Overview dashboard to real cap-table data

Replace hardcoded demo numbers on the company Overview with values
computed server-side from the same tables the dedicated pages list:
share issuances, option grants (excluding cancelled/expired), equity
plan pools, SAFEs and convertible notes.

- src/server/overview.ts: getOverviewData() computes amount raised,
  fully-diluted shares, stakeholder count, ownership by stakeholder
  and by share class, and the per-class summary on a fully-diluted
  basis (issued + granted options + unallocated pool)
- donut-card/summary-table now take data as props
- show EmptyOverview when no equity is issued, reserved or raised
- empty.tsx: fix 'undefined' rendering in welcome title

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat: implement Cap table and Reports pages

Both pages were 'Work in progress' stubs. They are now driven by a
shared cap-table engine so they can never disagree with the Overview.

- src/server/captable.ts: getCapTable() computes a per-stakeholder x
  per-share-class fully-diluted matrix (shares, options, equity plan
  pool, itemized SAFEs/notes, totals) with the same semantics the
  Overview already shipped with
- src/server/overview.ts: getOverviewData() now derives from
  getCapTable; output verified byte-identical against baselines
- Cap table page: summary cards, ownership matrix with per-class
  columns and totals, equity-plan pool row, convertibles card,
  empty state; gated behind stakeholder:read like sibling pages
- Reports page: four downloadable reports (cap table summary PDF,
  cap table matrix CSV, securities ledger CSV, stakeholders CSV)
  generated on demand by /api/reports/[type] with session + RBAC
  checks; PDF uses the existing @react-pdf/renderer pattern, CSVs
  use papaparse; no new dependencies

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(securities): enable updating shares and removing investors

On the cap table, shares could not be edited and investors (stakeholders)
could not be removed:
- The "Update Share" row action was a dead label with no handler, and there
  was no updateShares procedure (addShares is create-only).
- The investor table had no delete action and there was no deleteStakeholder
  procedure.

Changes:
- Add securities.updateShares procedure + ZodUpdateShareMutationSchema.
- Make the share wizard reusable for editing: AddShareFormProvider accepts
  defaultValues, each step prefills from them, and the final step branches to
  updateShares (and no longer forces a new document upload) in edit mode. The
  share row action now opens this pre-filled wizard.
- Add stakeholder.deleteStakeholder procedure + a Delete action in the
  investor table. The procedure refuses to remove an investor who still holds
  securities (shares/options/SAFEs/notes/investments) since relationMode=
  "prisma" provides no DB cascade, and it cleans up data-room / update
  recipient links.
- get-shares now selects stakeholderId/shareClassId (needed to prefill edit).
- Fix the share-delete toast that incorrectly said "stakeholder".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(securities): use month-based vesting fields in share editing

Adapt the share update procedure and edit form (from captableinc#561)
to the cliffMonths/vestingMonths rename (captableinc#562).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: resolve tsconfig path aliases in vitest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: address upstream review feedback on cap table, reports and stakeholders

Fixes for CodeRabbit findings on captableinc#561:
- Stakeholder deletion: require the `stakeholder:delete` permission, resolve
  the stakeholder within the caller's company before touching any rows
  (prevents cross-tenant deletes of data room / update recipients), and
  BLOCK deletion with an explicit message listing what is still held when
  the stakeholder has any share, option, SAFE, convertible note or
  investment. Runs in a serializable transaction so a concurrent issuance
  cannot race the check (cascades are emulated by Prisma Client).
- Share update: verify the stakeholder and share class belong to the same
  company; audit with the membership company id.
- Reports: escape spreadsheet formula prefixes in every CSV header/cell.
- Overview: gate behind `stakeholder:read` like the cap table page.
- Stakeholder table: move hooks into a StakeholderActionsCell component,
  refresh only on success, disable Delete while pending.
- Share stepper: keep the modal open until the mutation succeeds.
- Cap table PDF: correct matrix column count; use a built-in font instead
  of fetching one over the network.
- Use `Button asChild` for link CTAs; constrain report card type; reject
  empty ids in update/delete payloads.
- Add unit tests for CSV sanitisation and the stakeholder deletion guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(securities): format vesting months schema tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: resolve biome and type errors in stakeholder table and tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style(prisma): align Option fields after vesting rename

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style: apply biome formatting to cap table, reports and stakeholder changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Máximo Gubitosi <mgubitosi@udesa.edu.ar>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local>
GabrielGoncalvesICE pushed a commit to smarthow/captable that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GabrielGoncalvesICE pushed a commit to smarthow/captable that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GabrielGoncalvesICE added a commit to smarthow/captable that referenced this pull request Dec 2, 2026
* test(e2e): add Playwright harness with fictional scenario seed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): store rates and group ownership as fractions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(e2e): add @playwright/test and resolve seed import for ESM

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): assert overview stats and run seed unit tests in vitest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(e2e): express seeded vesting in months after captableinc#562

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): seed scenarios through the cap table contract

Write Decimal money with currency, CompanySettings, the group link,
a closed FundingRound and POSTED ledger ISSUANCE rows for every seeded
security, so engine projections match the registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(e2e): refuse to seed non-disposable databases

The seed creates admin users with a public password, and NODE_ENV alone
does not protect shared databases (Prisma loads .env; pnpm e2e and tsx
leave NODE_ENV unset). Seeding now requires a local host, a database
named for e2e/test, or an explicit E2E_ALLOW_SEED=1 (set in the CI e2e
job); NODE_ENV=production always refuses.

Also: scope the README reset command to an explicit E2E DATABASE_URL,
give the CI build 6 GB of heap, and assert the parent's 10,000,000
authorized shares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant