Skip to content

Add content length + title length validation to CLI and API indexer #670

@realproject7

Description

@realproject7

Problem

The frontend enforces content length (500-10,000 chars) and title length (60 chars), but the CLI and API indexer have NO validation. Via CLI or direct contract calls, users can:

  • Create storylines with arbitrarily long titles
  • Submit 1-character "stories" or 1MB stories
  • Only contract-level check is non-empty title + valid CID format

Current validation by layer

Layer Title Content min Content max
Smart contract Non-empty only None None
Frontend 60 chars ✓ 500 chars ✓ 10,000 chars ✓
CLI Non-empty only ✗ Non-empty only ✗ None ✗
API indexer None None None

Fix

1. CLI validation (`packages/cli/src/sdk/client.ts`)

Import and use the shared constants from `lib/content.ts`:

  • `createStoryline()`: validate `title.length <= 60`, `content.length >= 500`, `content.length <= 10000`
  • `chainPlot()`: validate `content.length >= 500`, `content.length <= 10000`
  • Show clear error messages: "Title must be 60 characters or less", "Content must be between 500 and 10,000 characters (currently: X)"

2. API indexer validation (soft — don't reject, but flag)

The API indexers process on-chain events that already succeeded — we can't reject them. But we can:

  • Log a warning for out-of-bounds content
  • Consider adding a `flagged` column or `hidden = true` for storylines that violate limits (created via direct contract calls)

This is optional — the CLI validation is the priority since that's the programmatic entry point we control.

Constants

```typescript
const MAX_TITLE_LENGTH = 60;
const MIN_CONTENT_LENGTH = 500;
const MAX_CONTENT_LENGTH = 10_000;
```

These already exist in `lib/content.ts` — the CLI should either import them or define matching constants.

Branch

`task/670-cli-content-validation`

Self-Verification (T3)

  • `plotlink create` with title > 60 chars — shows error, does not create
  • `plotlink create` with content < 500 chars — shows error, does not create
  • `plotlink create` with content > 10,000 chars — shows error, does not create
  • `plotlink create` with valid title + content — succeeds
  • `plotlink chain` with content < 500 chars — shows error
  • `plotlink chain` with valid content — succeeds
  • `npm run build` passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions