UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

107 lines • 3.93 kB
import { theme } from "./theme/theme.js"; const GROUP_ORDER = ["project", "user", "path", "system"]; export function isSystemResource(sourceInfo) { return sourceInfo?.scope === "system"; } export function isPackageSourceInfo(sourceInfo) { const source = sourceInfo?.source ?? ""; return source.startsWith("npm:") || source.startsWith("git:"); } export function getResourceScopeGroup(sourceInfo) { const source = sourceInfo?.source ?? "local"; const scope = sourceInfo?.scope ?? "project"; if (scope === "system") return "system"; if (source === "cli") return "path"; switch (scope) { case "temporary": return "path"; case "user": return "user"; case "project": return "project"; default: return assertNever(scope); } } export function buildResourceScopeGroups(items) { const groups = new Map(GROUP_ORDER.map((scope) => [scope, { scope, paths: [], packages: new Map() }])); for (const item of items) { const group = groups.get(getResourceScopeGroup(item.sourceInfo)); if (group === undefined) continue; if (isPackageSourceInfo(item.sourceInfo)) { const source = item.sourceInfo?.source ?? "local"; const list = group.packages.get(source) ?? []; list.push(item); group.packages.set(source, list); } else { group.paths.push(item); } } return GROUP_ORDER.map((scope) => groups.get(scope)).filter((group) => group !== undefined && (group.paths.length > 0 || group.packages.size > 0)); } export function formatResourceScopeGroups(groups, options) { const lines = []; for (const group of groups) { lines.push(` ${theme.fg("accent", group.scope)}`); const sortedPaths = [...group.paths].sort((a, b) => a.path.localeCompare(b.path)); for (const item of sortedPaths) { lines.push(theme.fg("dim", ` ${options.formatPath(item)}`)); } const sortedPackages = Array.from(group.packages.entries()).sort(([a], [b]) => a.localeCompare(b)); for (const [source, items] of sortedPackages) { lines.push(` ${theme.fg("mdLink", source)}`); const sortedPackagePaths = [...items].sort((a, b) => a.path.localeCompare(b.path)); for (const item of sortedPackagePaths) { lines.push(theme.fg("dim", ` ${options.formatPackagePath(item, source)}`)); } } } return lines.join("\n"); } export function getScopeAutocompleteTag(scope) { switch (scope) { case "user": return "u"; case "project": return "p"; case "temporary": return "t"; case "system": return "s"; default: return assertNever(scope); } } export function getDisplaySourceInfo(sourceInfo) { const source = sourceInfo?.source ?? "local"; const scope = sourceInfo?.scope ?? "project"; if (scope === "system") { return { label: "system", color: "muted" }; } if (source === "local") { if (scope === "user") { return { label: "user", color: "muted" }; } if (scope === "project") { return { label: "project", color: "muted" }; } return { label: "path", scopeLabel: "temp", color: "muted" }; } if (source === "cli") { return { label: "path", scopeLabel: scope === "temporary" ? "temp" : undefined, color: "muted", }; } const scopeLabel = scope === "user" ? "user" : scope === "project" ? "project" : "temp"; return { label: source, scopeLabel, color: "accent" }; } function assertNever(value) { throw new Error(`Unexpected resource scope: ${String(value)}`); } //# sourceMappingURL=loaded-resource-scopes.js.map