Normalize escaped multiline issue and approval text (#4444)

## Thinking Path

> - Paperclip orchestrates AI agents for zero-human companies
> - The board and agent APIs accept multiline issue, approval,
interaction, and document text
> - Some callers accidentally send literal escaped newline sequences
like `\n` instead of JSON-decoded line breaks
> - That makes comments, descriptions, documents, and approval notes
render as flattened text instead of readable markdown
> - This pull request centralizes multiline text normalization in shared
validators
> - The benefit is newline-preserving API behavior across issue and
approval workflows without route-specific fixes

## What Changed

- Added a shared `multilineTextSchema` helper that normalizes escaped
`\n`, `\r\n`, and `\r` sequences to real line breaks.
- Applied the helper to issue descriptions, issue update comments, issue
comment bodies, suggested task descriptions, interaction summaries,
issue documents, approval comments, and approval decision notes.
- Added shared validator regressions for issue and approval multiline
inputs.

## Verification

- `pnpm exec vitest run --project @paperclipai/shared
packages/shared/src/validators/approval.test.ts
packages/shared/src/validators/issue.test.ts`
- `pnpm --filter @paperclipai/shared typecheck`

## Risks

- Low risk. This only changes text fields that are explicitly multiline
user/operator content.
- If a caller intentionally wanted literal backslash-n text in these
fields, it will now render as a real line break.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- OpenAI Codex, GPT-5 coding agent, tool-enabled with
shell/GitHub/Paperclip API access. Context window was not reported by
the runtime.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Dotta 2026-04-24 18:02:45 -05:00 committed by GitHub
parent 5a0c1979cf
commit 0c6961a03e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 130 additions and 9 deletions

View file

@ -0,0 +1,78 @@
import { describe, expect, it } from "vitest";
import {
addIssueCommentSchema,
createIssueSchema,
respondIssueThreadInteractionSchema,
suggestedTaskDraftSchema,
updateIssueSchema,
upsertIssueDocumentSchema,
} from "./issue.js";
describe("issue validators", () => {
it("passes real line breaks through unchanged", () => {
const parsed = createIssueSchema.parse({
title: "Follow up PR",
description: "Line 1\n\nLine 2",
});
expect(parsed.description).toBe("Line 1\n\nLine 2");
});
it("accepts null and omitted optional multiline issue fields", () => {
expect(createIssueSchema.parse({ title: "Follow up PR", description: null }).description)
.toBeNull();
expect(createIssueSchema.parse({ title: "Follow up PR" }).description)
.toBeUndefined();
expect(updateIssueSchema.parse({ comment: undefined }).comment)
.toBeUndefined();
});
it("normalizes JSON-escaped line breaks in issue descriptions", () => {
const parsed = createIssueSchema.parse({
title: "Follow up PR",
description: "PR: https://example.com/pr/1\\n\\nShip the follow-up.",
});
expect(parsed.description).toBe("PR: https://example.com/pr/1\n\nShip the follow-up.");
});
it("normalizes escaped line breaks in issue update comments", () => {
const parsed = updateIssueSchema.parse({
comment: "Done\\n\\n- Verified the route",
});
expect(parsed.comment).toBe("Done\n\n- Verified the route");
});
it("normalizes escaped line breaks in issue comment bodies", () => {
const parsed = addIssueCommentSchema.parse({
body: "Progress update\\r\\n\\r\\nNext action.",
});
expect(parsed.body).toBe("Progress update\n\nNext action.");
});
it("normalizes escaped line breaks in generated task drafts", () => {
const parsed = suggestedTaskDraftSchema.parse({
clientKey: "task-1",
title: "Follow up",
description: "Line 1\\n\\nLine 2",
});
expect(parsed.description).toBe("Line 1\n\nLine 2");
});
it("normalizes escaped line breaks in thread summaries and documents", () => {
const response = respondIssueThreadInteractionSchema.parse({
answers: [],
summaryMarkdown: "Summary\\n\\nNext action",
});
const document = upsertIssueDocumentSchema.parse({
format: "markdown",
body: "# Plan\\n\\nShip it",
});
expect(response.summaryMarkdown).toBe("Summary\n\nNext action");
expect(document.body).toBe("# Plan\n\nShip it");
});
});