Files
moltbot/src/plugins/source-display.ts
Peter Steinberger 538605ff44 [codex] Extract filesystem safety primitives (#77918)
* refactor: extract filesystem safety primitives

* refactor: use fs-safe for file access helpers

* refactor: reuse fs-safe for media reads

* refactor: use fs-safe for image reads

* refactor: reuse fs-safe in qqbot media opener

* refactor: reuse fs-safe for local media checks

* refactor: consume cleaner fs-safe api

* refactor: align fs-safe json option names

* fix: preserve fs-safe migration contracts

* refactor: use fs-safe primitive subpaths

* refactor: use grouped fs-safe subpaths

* refactor: align fs-safe api usage

* refactor: adapt private state store api

* chore: refresh proof gate

* refactor: follow fs-safe json api split

* refactor: follow reduced fs-safe surface

* build: default fs-safe python helper off

* fix: preserve fs-safe plugin sdk aliases

* refactor: consolidate fs-safe usage

* refactor: unify fs-safe store usage

* refactor: trim fs-safe temp workspace usage

* refactor: hide low-level fs-safe primitives

* build: use published fs-safe package

* fix: preserve outbound recovery durability after rebase

* chore: refresh pr checks
2026-05-06 02:15:17 +01:00

49 lines
1.5 KiB
TypeScript

import path from "node:path";
import { isPathInside } from "../infra/path-guards.js";
import { shortenHomeInString } from "../utils.js";
import type { PluginRecord } from "./registry.js";
import type { PluginSourceRoots } from "./roots.js";
export { resolvePluginSourceRoots } from "./roots.js";
export type { PluginSourceRoots } from "./roots.js";
function tryRelative(root: string, filePath: string): string | null {
if (!isPathInside(root, filePath)) {
return null;
}
const rel = path.relative(root, filePath);
if (!rel || rel === ".") {
return null;
}
// Normalize to forward slashes for display (path.relative uses backslashes on Windows)
return rel.replaceAll("\\", "/");
}
export function formatPluginSourceForTable(
plugin: Pick<PluginRecord, "source" | "origin">,
roots: PluginSourceRoots,
): { value: string; rootKey?: keyof PluginSourceRoots } {
const raw = plugin.source;
if (plugin.origin === "bundled" && roots.stock) {
const rel = tryRelative(roots.stock, raw);
if (rel) {
return { value: `stock:${rel}`, rootKey: "stock" };
}
}
if (plugin.origin === "workspace" && roots.workspace) {
const rel = tryRelative(roots.workspace, raw);
if (rel) {
return { value: `workspace:${rel}`, rootKey: "workspace" };
}
}
if (plugin.origin === "global" && roots.global) {
const rel = tryRelative(roots.global, raw);
if (rel) {
return { value: `global:${rel}`, rootKey: "global" };
}
}
// Keep this stable/pasteable; only ~-shorten.
return { value: shortenHomeInString(raw) };
}