mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 02:30:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Operators store company and user secrets under human-readable names > - Slash-delimited names already express useful hierarchy, but the Secrets page previously rendered them as one flat list > - Large secret collections therefore became harder to scan, navigate, and create within consistently named groups > - A client-derived folder model preserves the existing server contract while making those names navigable > - This pull request adds folder browsing, URL-addressable paths, global search, and create-in-folder behavior without adding folder records > - The benefit is a more scalable secrets workflow with no migration or API compatibility risk ## Linked Issues or Issue Description Slash-delimited secret names such as `dev/github/oauth/clientid` currently appear as raw flat rows. This change treats name prefixes as client-side navigation folders on the main Secrets tab while leaving stored names, API contracts, validation, and the database unchanged. - Wireframes and interaction specification: https://pages.paperclip.ing/pap-14698-secrets-folders/ - Folder paths are derived only from secret names; there is no server-side folder entity or data-model change. ## What Changed - Added pure secret-path utilities for normalized segments, breadcrumbs, nested folder listings, counts, and leaf/path rendering. - Added a Folders/Flat view to the main Secrets tab with folder-first sorting, breadcrumbs, empty-folder states, filters, and global search results. - Added URL navigation through `?path=<normalized/path>` so deep links, reload, browser Back, and new-tab folder navigation work. - Persisted the preferred view in `localStorage` under `paperclip.secrets.viewMode`; an explicit `?path=` deep link takes precedence for that visit. - Added create-in-folder behavior with a removable prefix chip, staged New folder paths, inline segment validation, and full-name key derivation. - Kept My secrets flat while rendering slash-delimited names with muted paths and emphasized leaves. - Added unit/render coverage for path helpers, folder navigation, and create-in-folder behavior. ## Verification - `pnpm exec vitest run ui/src/pages/secrets/secret-path.test.ts ui/src/pages/Secrets.render.test.tsx` — 35 tests passed. - `pnpm -r typecheck` — passed. - `pnpm test:run` — server suite passed 2,707 tests and UI suite passed 3,022 tests; one unrelated CLI doctor test was environment-sensitive because this agent inherited AWS variables. - `env -u AWS_PROFILE -u AWS_ACCESS_KEY_ID -u AWS_SECRET_ACCESS_KEY -u AWS_SESSION_TOKEN -u AWS_REGION -u AWS_DEFAULT_REGION pnpm exec vitest run cli/src/__tests__/secrets.test.ts` — 8 tests passed. - `pnpm build` — passed. - `pnpm check:token-gates` — feature files are clean; the command reports five existing `#9627` color literals outside this diff. ## Risks - Low data risk: folders are derived client-side from existing names, with no schema, migration, API, or stored-name changes. - URL behavior changes only the main Secrets tab and uses the additive `?path=` contract. - View preference is browser-local and scoped to the `paperclip.secrets.viewMode` key. - Renaming or deleting the last secret under an open prefix intentionally leaves the user on an empty-folder state instead of redirecting. - “Move to folder…” bulk prefix rename remains deferred because it is a multi-secret mutation with separate conflict and partial-failure semantics. > 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 `gpt-5.5` via Codex CLI for PR preparation, verification, GitHub/Paperclip tool use, and codebase analysis; the managed harness does not expose the active context-window size. - Anthropic Claude Opus 4.8 (1M context) and Claude Fable 5 assisted earlier implementation/design commits, as recorded in their commit trailers; both used repository and code-editing tools. ## 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) - [ ] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details — the assigned shared execution branch name is fixed for this work - [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 - [x] 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: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
113 lines
3.4 KiB
TypeScript
113 lines
3.4 KiB
TypeScript
export type SecretPathRow =
|
|
| { kind: "company"; secret: { name: string } }
|
|
| { kind: "user"; definition: { name: string } };
|
|
|
|
export interface SecretPathFolder {
|
|
name: string;
|
|
path: string;
|
|
secretCount: number;
|
|
folderCount: number;
|
|
}
|
|
|
|
export interface SecretPathBreadcrumb {
|
|
name: string;
|
|
path: string;
|
|
}
|
|
|
|
export interface SecretPathListing<Row extends SecretPathRow> {
|
|
folders: SecretPathFolder[];
|
|
secrets: Row[];
|
|
}
|
|
|
|
const NATURAL_NAME_SORT_OPTIONS: Intl.CollatorOptions = {
|
|
numeric: true,
|
|
sensitivity: "base",
|
|
};
|
|
|
|
export function getSecretPathRowName(row: SecretPathRow): string {
|
|
return row.kind === "company" ? row.secret.name : row.definition.name;
|
|
}
|
|
|
|
export function splitSecretPath(path: string): string[] {
|
|
return path.split("/").filter((segment) => segment.length > 0);
|
|
}
|
|
|
|
export function normalizeSecretPath(path: string): string {
|
|
return splitSecretPath(path).join("/");
|
|
}
|
|
|
|
function startsWithSegments(segments: readonly string[], prefix: readonly string[]): boolean {
|
|
return prefix.every((segment, index) => segments[index] === segment);
|
|
}
|
|
|
|
function compareNames(left: string, right: string): number {
|
|
return left.localeCompare(right, undefined, NATURAL_NAME_SORT_OPTIONS);
|
|
}
|
|
|
|
export function buildSecretPathListing<Row extends SecretPathRow>(
|
|
rows: readonly Row[],
|
|
path: string,
|
|
): SecretPathListing<Row> {
|
|
const pathSegments = splitSecretPath(path);
|
|
const entries = rows.map((row) => ({
|
|
row,
|
|
name: getSecretPathRowName(row),
|
|
segments: splitSecretPath(getSecretPathRowName(row)),
|
|
}));
|
|
const folderNames = new Set<string>();
|
|
const secrets: Row[] = [];
|
|
|
|
for (const entry of entries) {
|
|
if (!startsWithSegments(entry.segments, pathSegments)) continue;
|
|
const relativeDepth = entry.segments.length - pathSegments.length;
|
|
if (relativeDepth === 0 || relativeDepth === 1) secrets.push(entry.row);
|
|
if (relativeDepth >= 2) folderNames.add(entry.segments[pathSegments.length]);
|
|
}
|
|
|
|
const folders = [...folderNames].map((name): SecretPathFolder => {
|
|
const folderSegments = [...pathSegments, name];
|
|
const descendantFolderPaths = new Set<string>();
|
|
let secretCount = 0;
|
|
|
|
for (const entry of entries) {
|
|
if (!startsWithSegments(entry.segments, folderSegments)) continue;
|
|
const relativeDepth = entry.segments.length - folderSegments.length;
|
|
if (relativeDepth < 1) continue;
|
|
secretCount += 1;
|
|
for (let depth = 1; depth < relativeDepth; depth += 1) {
|
|
descendantFolderPaths.add(
|
|
entry.segments.slice(folderSegments.length, folderSegments.length + depth).join("/"),
|
|
);
|
|
}
|
|
}
|
|
|
|
return {
|
|
name,
|
|
path: folderSegments.join("/"),
|
|
secretCount,
|
|
folderCount: descendantFolderPaths.size,
|
|
};
|
|
});
|
|
|
|
folders.sort((left, right) => compareNames(left.name, right.name));
|
|
secrets.sort((left, right) =>
|
|
compareNames(getSecretPathRowName(left), getSecretPathRowName(right)),
|
|
);
|
|
|
|
return { folders, secrets };
|
|
}
|
|
|
|
export function buildSecretPathBreadcrumbs(path: string): SecretPathBreadcrumb[] {
|
|
const segments = splitSecretPath(path);
|
|
return segments.map((name, index) => ({
|
|
name,
|
|
path: segments.slice(0, index + 1).join("/"),
|
|
}));
|
|
}
|
|
|
|
export function validateSecretFolderSegment(value: string): string | null {
|
|
if (!value.trim()) return "Folder name is required.";
|
|
if (value.includes("/")) return "Folder name cannot contain slashes.";
|
|
return null;
|
|
}
|