mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-22 16:51:28 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agent work is issue-centered, and reviewers often need to inspect files, artifacts, and path references produced during that work. > - Before this branch, workspace-relative paths and artifact file references were not first-class inspectable objects in the board UI. > - Safe file viewing needs shared resource contracts, server-side workspace boundary checks, and UI that opens files without exposing arbitrary host paths. > - The workspace file viewer branch needed to stay as one active PR and be rebased onto current `paperclipai/paperclip:master` for review. > - This pull request adds the workspace file resource API, issue-page file viewer and browser, markdown file-reference links, and artifact file chips. > - The benefit is that board users can inspect relevant files from issue context while preserving workspace boundaries and auditability. ## Linked Issues or Issue Description No public GitHub issue exists for this branch. Internal Paperclip issues: `PAP-1953`, `PAP-10539`, `PAP-10733`. Problem / motivation: - Board users need to open workspace-relative files mentioned by agents or attached as work-product metadata without switching to a terminal. - The UI needs to support both direct file-path opening and workspace browsing/searching from an issue page. - The server must enforce company access, workspace boundaries, size limits, rate limits, and safe audit logging. Related PR: - Prior closed attempt: #4442 - Single active PR for this branch: #7681 ## What Changed - Added shared workspace file resource types, validators, and workspace-file `resourceRef` metadata validation for work products. - Added server routes/services for resolving, listing, and previewing workspace-relative files with access checks, scan caps, list-specific limits, and audit logging. - Added the issue file viewer provider, sheet, workspace browser, command-palette action, markdown workspace-file autolinks, and artifact file chips. - Updated issue workspace UI and stories/tests for file browsing and workspace file opening. - Rebased the branch onto current `paperclipai/paperclip:master` and updated the existing single PR branch. - Addressed current-head Greptile follow-ups by applying `offset` consistently across search/recent/changed file listings, restoring stopped-service port ownership checks before auto-port reuse, and stabilizing the workspace browser pagination test. ## Verification Current local verification after rebase to `public/master`: - `pnpm exec vitest run packages/shared/src/work-product.test.ts server/src/__tests__/file-resources.test.ts server/src/__tests__/instance-settings-routes.test.ts server/src/__tests__/instance-settings-service.test.ts server/src/__tests__/workspace-runtime.test.ts ui/src/components/FileViewerSheet.test.tsx ui/src/components/FileViewerSheet.copy.test.tsx ui/src/components/WorkspaceFileBrowser.test.tsx ui/src/components/WorkspaceFileMarkdownBody.test.tsx ui/src/context/FileViewerContext.test.ts ui/src/lib/remark-workspace-file-refs.test.ts ui/src/lib/workspace-file-parser.test.ts ui/src/components/IssueWorkspaceCard.test.tsx` - 13 files passed, 197 tests passed. - `pnpm -r --filter @paperclipai/shared --filter @paperclipai/server --filter @paperclipai/ui typecheck` - passed. - `pnpm exec vitest run ui/src/components/WorkspaceFileBrowser.test.tsx` - 1 file passed, 25 tests passed. - `pnpm exec vitest run server/src/__tests__/file-resources.test.ts server/src/__tests__/workspace-runtime.test.ts` - 2 files passed, 90 tests passed. - `pnpm -r --filter @paperclipai/server typecheck` - passed. - Confirmed branch is `0` behind and `46` ahead of current `public/master` after rebase and follow-up commits. - Confirmed the PR diff does not include `pnpm-lock.yaml`. - Confirmed the PR diff does not include `.github/workflows` changes. - Searched GitHub for duplicate or related workspace file viewer PRs/issues; #4442 is the prior closed attempt and this PR is the single active PR for the branch. - No screenshots were committed; the task explicitly asked not to add design screenshots or images unless they were part of the work. Current remote verification on head `a698a7bc10137baf7d25bd5722e1d6e0343387c1`: - Greptile Review - success, 64 files reviewed, 0 comments added, no unresolved Greptile review threads. - PR workflow `verify` - success. - Typecheck + Release Registry, General tests, workspace test shards, serialized server suites, Build, Canary Dry Run, e2e, Socket, and Snyk - success. - `security-review` - neutral, with output saying a draft advisory was filed for maintainer review and is not a merge block. - `commitperclip PR Review / review` - cancelled after the security gate detected flags and timed out while creating/reviewing the advisory. I reran it once and it cancelled the same way; no actionable code/test failure was exposed in the job logs. ## Risks - This is a broad UI/server feature PR, so review needs to pay attention to route authorization, workspace boundary handling, and markdown autolink false positives. - Workspace browsing intentionally caps list results and scan depth; very large workspaces may require users to refine search terms. - Remote workspace preview remains unavailable until remote file-access support is implemented. - The neutral commitperclip security-review advisory needs maintainer review, but the check output says it is not a merge block. > 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 in a Paperclip/Codex local tool-use environment, medium reasoning, with shell/GitHub CLI tool use for branch inspection, verification, rebase, PR update, Greptile review, and CI inspection. ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] 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 - [ ] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
290 lines
8.1 KiB
TypeScript
290 lines
8.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
findPageSearchShortcutTarget,
|
|
focusPageSearchShortcutTarget,
|
|
hasBlockingShortcutDialog,
|
|
isKeyboardShortcutTextInputTarget,
|
|
resolveIssueDetailGoKeyAction,
|
|
resolveInboxQuickArchiveKeyAction,
|
|
resolveInboxUndoArchiveKeyAction,
|
|
shouldBlurPageSearchOnEnter,
|
|
shouldBlurPageSearchOnEscape,
|
|
} from "./keyboardShortcuts";
|
|
|
|
describe("keyboardShortcuts helpers", () => {
|
|
it("detects editable shortcut targets", () => {
|
|
const wrapper = document.createElement("div");
|
|
wrapper.innerHTML = `
|
|
<div contenteditable="true"><span id="contenteditable-child">Editable</span></div>
|
|
<div role="textbox"><span id="textbox-child">Textbox</span></div>
|
|
<button id="button">Action</button>
|
|
`;
|
|
|
|
const editableChild = wrapper.querySelector("#contenteditable-child");
|
|
const textboxChild = wrapper.querySelector("#textbox-child");
|
|
const button = wrapper.querySelector("#button");
|
|
|
|
expect(isKeyboardShortcutTextInputTarget(editableChild)).toBe(true);
|
|
expect(isKeyboardShortcutTextInputTarget(textboxChild)).toBe(true);
|
|
expect(isKeyboardShortcutTextInputTarget(button)).toBe(false);
|
|
});
|
|
|
|
it("reports when a modal dialog is open", () => {
|
|
const root = document.createElement("div");
|
|
root.innerHTML = `<div role="dialog" aria-modal="true"></div>`;
|
|
|
|
expect(hasBlockingShortcutDialog(root)).toBe(true);
|
|
expect(hasBlockingShortcutDialog(document.createElement("div"))).toBe(false);
|
|
});
|
|
|
|
it("ignores non-dialog elements that happen to be aria-modal", () => {
|
|
const root = document.createElement("div");
|
|
root.innerHTML = `<section aria-modal="true"></section>`;
|
|
|
|
expect(hasBlockingShortcutDialog(root)).toBe(false);
|
|
});
|
|
|
|
it("finds the visible page search shortcut target", () => {
|
|
const root = document.createElement("div");
|
|
const hidden = document.createElement("input");
|
|
hidden.setAttribute("data-page-search-target", "true");
|
|
vi.spyOn(hidden, "getClientRects").mockReturnValue([] as unknown as DOMRectList);
|
|
|
|
const visible = document.createElement("input");
|
|
visible.setAttribute("data-page-search-target", "true");
|
|
vi.spyOn(visible, "getClientRects").mockReturnValue([{}] as unknown as DOMRectList);
|
|
|
|
root.append(hidden, visible);
|
|
document.body.appendChild(root);
|
|
|
|
expect(findPageSearchShortcutTarget(root)).toBe(visible);
|
|
|
|
root.remove();
|
|
});
|
|
|
|
it("focuses and selects the page search shortcut target", () => {
|
|
const root = document.createElement("div");
|
|
const input = document.createElement("input");
|
|
input.value = "existing query";
|
|
input.setAttribute("data-page-search-target", "true");
|
|
vi.spyOn(input, "getClientRects").mockReturnValue([{}] as unknown as DOMRectList);
|
|
root.appendChild(input);
|
|
document.body.appendChild(root);
|
|
|
|
expect(focusPageSearchShortcutTarget(root)).toBe(true);
|
|
expect(document.activeElement).toBe(input);
|
|
expect(input.selectionStart).toBe(0);
|
|
expect(input.selectionEnd).toBe(input.value.length);
|
|
|
|
root.remove();
|
|
});
|
|
|
|
it("blurs page search on a plain Enter press", () => {
|
|
expect(shouldBlurPageSearchOnEnter({
|
|
key: "Enter",
|
|
isComposing: false,
|
|
})).toBe(true);
|
|
});
|
|
|
|
it("keeps focus while composing with an IME", () => {
|
|
expect(shouldBlurPageSearchOnEnter({
|
|
key: "Enter",
|
|
isComposing: true,
|
|
})).toBe(false);
|
|
});
|
|
|
|
it("blurs page search on Escape when the field is already empty", () => {
|
|
expect(shouldBlurPageSearchOnEscape({
|
|
key: "Escape",
|
|
isComposing: false,
|
|
currentValue: "",
|
|
})).toBe(true);
|
|
});
|
|
|
|
it("keeps focus on the first Escape while the field still has text", () => {
|
|
expect(shouldBlurPageSearchOnEscape({
|
|
key: "Escape",
|
|
isComposing: false,
|
|
currentValue: "query",
|
|
})).toBe(false);
|
|
});
|
|
|
|
it("archives only the first clean y press", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveInboxQuickArchiveKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "y",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("archive");
|
|
});
|
|
|
|
it("ignores non-y keypresses", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveInboxQuickArchiveKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "n",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("ignore");
|
|
});
|
|
|
|
it("stays inert for modifier combos before a real keypress", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveInboxQuickArchiveKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "Meta",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("ignore");
|
|
|
|
expect(resolveInboxQuickArchiveKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "y",
|
|
metaKey: true,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("ignore");
|
|
});
|
|
|
|
it("ignores input typing instead of archiving", () => {
|
|
const input = document.createElement("input");
|
|
|
|
expect(resolveInboxQuickArchiveKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "y",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: input,
|
|
hasOpenDialog: false,
|
|
})).toBe("ignore");
|
|
});
|
|
|
|
it("undoes only a clean lowercase u press when an archive is available", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveInboxUndoArchiveKeyAction({
|
|
hasUndoableArchive: true,
|
|
defaultPrevented: false,
|
|
key: "u",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("undo_archive");
|
|
});
|
|
|
|
it("keeps uppercase U available for mark-unread handling", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveInboxUndoArchiveKeyAction({
|
|
hasUndoableArchive: true,
|
|
defaultPrevented: false,
|
|
key: "U",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("ignore");
|
|
});
|
|
|
|
it("arms go-to-inbox on a clean g press", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveIssueDetailGoKeyAction({
|
|
armed: false,
|
|
defaultPrevented: false,
|
|
key: "g",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("arm");
|
|
});
|
|
|
|
it("navigates to inbox on i after g", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveIssueDetailGoKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "i",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("navigate_inbox");
|
|
});
|
|
|
|
it("focuses the comment composer on c after g", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveIssueDetailGoKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "c",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("focus_comment");
|
|
});
|
|
|
|
it("opens the file viewer on f after g", () => {
|
|
const button = document.createElement("button");
|
|
|
|
expect(resolveIssueDetailGoKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "f",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: button,
|
|
hasOpenDialog: false,
|
|
})).toBe("open_file_viewer");
|
|
});
|
|
|
|
it("disarms go-to-inbox instead of firing from an editor", () => {
|
|
const input = document.createElement("textarea");
|
|
|
|
expect(resolveIssueDetailGoKeyAction({
|
|
armed: true,
|
|
defaultPrevented: false,
|
|
key: "i",
|
|
metaKey: false,
|
|
ctrlKey: false,
|
|
altKey: false,
|
|
target: input,
|
|
hasOpenDialog: false,
|
|
})).toBe("disarm");
|
|
});
|
|
});
|