MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / addLink

Function addLink

src/config/links.ts:112–127  ·  view source on GitHub ↗
(cwd: string, input: string)

Source from the content-addressed store, hash-verified

110
111/** Resolve, validate and persist a new link. Idempotent on the resolved path. */
112export function addLink(cwd: string, input: string): LinkResult {
113 const resolved = resolveLinkTarget(input)
114 if (!resolved) return { ok: false, message: "Enter a folder path." }
115 if (path.resolve(cwd) === resolved) return { ok: false, message: "Can't link a repo to itself." }
116 if (!isDir(resolved)) return { ok: false, message: `Not a directory: ${resolved}` }
117
118 const links = loadLinks(cwd)
119 if (links.some((l) => l.path === resolved)) return { ok: false, message: "Already linked." }
120 if (links.length >= MAX_LINKED_REPOS) {
121 return { ok: false, message: `At most ${MAX_LINKED_REPOS} linked repos.` }
122 }
123
124 links.push({ input: input.trim(), path: resolved })
125 saveLinks(cwd, links)
126 return { ok: true, message: `Linked ${resolved}` }
127}
128
129/** Remove a link by its resolved path. */
130export function removeLink(cwd: string, targetPath: string): void {

Callers 1

AppFunction · 0.85

Calls 4

resolveLinkTargetFunction · 0.85
isDirFunction · 0.85
loadLinksFunction · 0.85
saveLinksFunction · 0.85

Tested by

no test coverage detected