mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-17 21:34:48 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Chat replies, comments and documents render Markdown through
`MarkdownBody`. Task links in that Markdown become company-aware links
> - `parseIssueReferenceFromHref` turned every task link into an
unprefixed `/issues/<id>` path. The router then added the viewer's
active company prefix
> - In chat-eval cohort 4 (`access.other-company`), a reply in company
COM linked `/BIR/issues/BIR-1`. The chat rendered it as
`/COM/issues/BIR-1`, which points into the wrong company
> - This pull request keeps the company that a task link names: an
explicit `/BIR/issues/...` prefix, or an identifier whose prefix belongs
to a known company
> - The benefit is that a link to another company's task opens that
company's task, not a same-numbered task or an error in the current
company
## Linked Issues or Issue Description
**What happened?**
A chat reply in company COM contained `[BIR-1](/BIR/issues/BIR-1)`. The
rendered link pointed to `/COM/issues/BIR-1`.
**Expected behavior**
A task link that names a company keeps that company: `/BIR/issues/BIR-1`
stays `/BIR/issues/BIR-1`. A bare `BIR-1` or `/issues/BIR-1` goes to BIR
when BIR is a company that the viewer knows.
**Steps to reproduce**
1. Have two companies, COM and BIR.
2. In a COM chat or comment, render the Markdown
`[BIR-1](/BIR/issues/BIR-1)`.
3. Inspect the link. Its `href` is `/COM/issues/BIR-1`.
**Paperclip version or commit**
master at f1aef0cb58.
## What Changed
- `ui/src/lib/issue-reference.ts`: a new `issueHref` builds the internal
link. It keeps the company prefix of an explicit `/PREFIX/issues/...`
path. When the path has no prefix, it uses the identifier's prefix if
that prefix is in the known company prefixes. Otherwise the link stays
`/issues/<id>` and resolves in the active company, as before.
- `ui/src/components/MarkdownBody.tsx`: passes the known company
prefixes to the explicit-link path too (the auto-link path already had
them).
- Tests: a red/green unit test with the recorded shape in
`issue-reference.test.ts`, and a rendered test in
`MarkdownBody.test.tsx` (COM and BIR known; explicit, bare and
unprefixed BIR links all render `/BIR/issues/BIR-1`). Existing
expectations that asserted the stripped `/issues/<id>` form now assert
the company-prefixed form.
## Verification
- `cd ui && npx vitest run src/components/MarkdownBody.test.tsx
src/lib/issue-reference.test.ts src/lib/company-routes.test.ts`: 105
tests pass.
- Red/green: with `issue-reference.ts` and `MarkdownBody.tsx` from
`origin/master`, the new tests fail (`/issues/BIR-1` instead of
`/BIR/issues/BIR-1`). With the change, they pass.
- `pnpm check:token-gates` is clean. `tsc -p ui/tsconfig.json` reports
only existing errors in
`ui/storybook/support/feature-map/FeatureOverview.tsx`, which this
change does not touch.
- A paid chat-eval run with this change is linked in a comment below.
## Risks
- Same-company links now carry the explicit prefix (`/COM/issues/COM-1`
instead of `/issues/COM-1` resolved to the same place). The route is the
same.
- An explicit link with a bare identifier as its target (`[x](JIRA-2)`)
is now gated by known company prefixes like auto-linked text. Such a
link to a non-Paperclip key stays an ordinary link.
- Low risk otherwise: no API, data or saved state changes.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code
execution in Claude Code.
## 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 searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
175 lines
7.5 KiB
TypeScript
175 lines
7.5 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import type { ReactNode } from "react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { ThemeProvider } from "../context/ThemeContext";
|
|
import { MarkdownBody, type MarkdownExternalReferenceMap } from "./MarkdownBody";
|
|
import { CoordinatorPresentation } from "./coordinator/CoordinatorPresentation";
|
|
import { CoordinatorChatReferences } from "./coordinator/CoordinatorChatReferences";
|
|
|
|
vi.mock("@/lib/router", () => ({
|
|
Link: ({
|
|
children,
|
|
to,
|
|
...props
|
|
}: { children: ReactNode; to: string } & React.ComponentProps<"a">) => (
|
|
<a href={to} {...props}>{children}</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("../api/issues", () => ({
|
|
issuesApi: { get: vi.fn() },
|
|
}));
|
|
|
|
function render(children: string, externalReferences?: MarkdownExternalReferenceMap, coordinator = false) {
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
return renderToStaticMarkup(
|
|
<QueryClientProvider client={queryClient}>
|
|
<ThemeProvider>
|
|
<CoordinatorPresentation.Provider value={coordinator}>
|
|
<CoordinatorChatReferences.Provider value={new Map(coordinator ? [["tes-2", { label: "Chat with CTD", href: "/chats/ctd" }]] : [])}>
|
|
<MarkdownBody externalReferences={externalReferences}>{children}</MarkdownBody>
|
|
</CoordinatorChatReferences.Provider>
|
|
</CoordinatorPresentation.Provider>
|
|
</ThemeProvider>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
describe("MarkdownBody external object decoration", () => {
|
|
it("labels a standing conversation by its agent and keeps its conversation anchor", () => {
|
|
const html = render("Source: [TES-2](/TES/issues/TES-2#interaction-answer)", undefined, true);
|
|
expect(html).toContain('href="/chats/ctd#interaction-answer"');
|
|
expect(html).toContain('data-mention-kind="chat"');
|
|
expect(html).toContain("Chat with CTD");
|
|
expect(html).not.toContain("Issue TES-2");
|
|
expect(html).not.toContain('data-mention-kind="issue"');
|
|
expect(render("Source: TES-2")).toContain('data-mention-kind="issue"');
|
|
});
|
|
|
|
it("uses a compact document card for sidebar links, preserving the exact revision", () => {
|
|
const markdown = "[View saved recommendations](/TES/issues/TES-6#document-skill-recommendations&revision=reviewed-rev)";
|
|
const html = render(markdown, undefined, true);
|
|
expect(html).toContain('data-sidebar-document-link="true"');
|
|
expect(html).toContain('href="/TES/issues/TES-6#document-skill-recommendations&revision=reviewed-rev"');
|
|
expect(html).toContain("View saved recommendations");
|
|
expect(html).not.toContain('data-mention-kind="issue"');
|
|
expect(render(markdown)).not.toContain("data-sidebar-document-link");
|
|
expect(render("[External document](https://example.com/issues/TES-6#document-plan)", undefined, true)).not.toContain("data-sidebar-document-link");
|
|
});
|
|
const successReference: MarkdownExternalReferenceMap = {
|
|
"https://github.com/acme/web/pull/241": {
|
|
providerKey: "github",
|
|
objectType: "pull_request",
|
|
displayKey: "Github Pull Request",
|
|
iconKey: "github",
|
|
statusCategory: "succeeded",
|
|
statusIconKey: "git-merge",
|
|
liveness: "fresh",
|
|
statusLabel: "Merged",
|
|
displayTitle: "Add external refs",
|
|
},
|
|
};
|
|
|
|
it("decorates a known URL with the external status icon and metadata attributes", () => {
|
|
const html = render("Take a look: https://github.com/acme/web/pull/241", successReference);
|
|
expect(html).toContain('data-link-state="merged"');
|
|
expect(html).toContain("lucide-git-merge");
|
|
expect(html).toContain('data-external-link="resolved"');
|
|
expect(html).toContain('data-external-status="succeeded"');
|
|
expect(html).toContain('data-external-liveness="fresh"');
|
|
expect(html).toContain('aria-label="Github Pull Request Merged: Add external refs"');
|
|
expect(html).toContain("github.com/acme/web/pull/241");
|
|
});
|
|
|
|
it("matches a URL even when the user pasted it with different host case or trailing punctuation", () => {
|
|
const html = render("see HTTPS://Github.com/acme/web/pull/241#frag.", successReference);
|
|
expect(html).toContain('data-external-status="succeeded"');
|
|
});
|
|
|
|
it("renders an unresolved URL as a plain external link with no status affordance", () => {
|
|
const html = render("https://random.example.com/path");
|
|
expect(html).not.toContain("paperclip-markdown-external-ref");
|
|
expect(html).toContain('href="https://random.example.com/path"');
|
|
});
|
|
|
|
it("never decorates a URL that lives inside a fenced or inline code block", () => {
|
|
const html = render(
|
|
"```\nhttps://github.com/acme/web/pull/241\n```\n\nInline: `https://github.com/acme/web/pull/241`",
|
|
successReference,
|
|
);
|
|
// The fenced/inline literal should still be present as text but the
|
|
// decorated anchor should not appear since no `<a>` is created in code.
|
|
expect(html).not.toContain('class="paperclip-markdown-external-ref"');
|
|
});
|
|
|
|
it("shows liveness suffix in the aria-label when the object is stale or auth_required", () => {
|
|
const html = render("Auth-blocked: https://app.hubspot.com/leads/99", {
|
|
"https://app.hubspot.com/leads/99": {
|
|
providerKey: "hubspot",
|
|
objectType: "lead",
|
|
statusCategory: "auth_required",
|
|
liveness: "auth_required",
|
|
statusLabel: "Reconnect",
|
|
displayTitle: "Acme deal",
|
|
},
|
|
});
|
|
expect(html).toContain('aria-label="HubSpot Reconnect (Requires auth): Acme deal"');
|
|
});
|
|
|
|
it("labels detected-but-unresolved GitHub objects as not yet refreshed, not not yet resolved", () => {
|
|
const html = render("See https://github.com/acme/web/pull/241", {
|
|
"https://github.com/acme/web/pull/241": {
|
|
providerKey: "github",
|
|
objectType: "pull_request",
|
|
displayKey: "Github Pull Request",
|
|
iconKey: "github",
|
|
statusCategory: "unknown",
|
|
liveness: "unknown",
|
|
statusLabel: null,
|
|
displayTitle: "acme/web#241",
|
|
},
|
|
});
|
|
expect(html).toContain("data-external-link=\"resolved\"");
|
|
expect(html).toContain('aria-label="Github Pull Request Not yet refreshed: acme/web#241"');
|
|
expect(html).not.toContain("Not yet resolved");
|
|
});
|
|
|
|
it("does not repeat the liveness label when the status label equals it", () => {
|
|
const html = render("Auth-blocked: https://github.com/acme/web/pull/241", {
|
|
"https://github.com/acme/web/pull/241": {
|
|
providerKey: "github",
|
|
objectType: "pull_request",
|
|
displayKey: "Github Pull Request",
|
|
iconKey: "github",
|
|
statusCategory: "unknown",
|
|
liveness: "auth_required",
|
|
statusLabel: null,
|
|
displayTitle: "acme/web#241",
|
|
},
|
|
});
|
|
expect(html).toContain('aria-label="Github Pull Request Requires auth: acme/web#241"');
|
|
expect(html).not.toContain("Requires auth (Requires auth)");
|
|
expect(html).not.toContain("(Requires auth)");
|
|
});
|
|
|
|
it("does not repeat the liveness label when the status label equals it for unreachable", () => {
|
|
const html = render("Down: https://github.com/acme/web/pull/241", {
|
|
"https://github.com/acme/web/pull/241": {
|
|
providerKey: "github",
|
|
objectType: "pull_request",
|
|
displayKey: "Github Pull Request",
|
|
iconKey: "github",
|
|
statusCategory: "unknown",
|
|
liveness: "unreachable",
|
|
statusLabel: null,
|
|
displayTitle: "acme/web#241",
|
|
},
|
|
});
|
|
expect(html).toContain('aria-label="Github Pull Request Unreachable: acme/web#241"');
|
|
expect(html).not.toContain("(Unreachable)");
|
|
});
|
|
});
|