pluginapi

package
v0.5.0-rc.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pluginapi implements the paired capability surface Workstream B exposes to both JavaScript and Go plugins: resolving/reading files against the project root and node_modules, and writing static assets into the project root. Every function anchors paths to the project root and rejects traversal. The JavaScript capability host functions (internal/plugin) and the public Go SDK (pluginsdk) both delegate here so the security guards live in one place.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadFile

func ReadFile(root, spec string) (string, error)

ReadFile resolves spec (see Resolve) and returns its contents as a string.

func Resolve

func Resolve(root, spec string) (string, error)

Resolve turns a plugin file specifier into an absolute path.

  • Absolute paths are cleaned and must live under root.
  • Explicit relative paths ("./", "../") resolve against root and must stay inside it.

- Bare specifiers resolve through node_modules (walking up from root) - including subpaths like "pkg/styles/x.css" and "@scope/pkg/src/y" - and

otherwise fall back to a root-relative file.

The resolved path must exist. Traversal outside root is rejected.

func SafeJoin

func SafeJoin(root, rel string) (string, error)

SafeJoin joins rel onto root and verifies the result is inside root both lexically and after resolving symlinks. The final path component may not exist yet (writes), so symlinks are resolved on the deepest existing ancestor - this catches a symlinked directory inside the project that points outside it before a file is written through it. It returns the absolute path to use for the operation.

func WithinRoot

func WithinRoot(root, p string) bool

WithinRoot reports whether path p is the project root itself or lives inside it. Both paths are cleaned first; the result is case-sensitive, matching the underlying filesystem semantics.

func WithinRootEval

func WithinRootEval(root, p string) bool

WithinRootEval is WithinRoot but also resolves symlinks on both root and p so a symlinked root (e.g. /tmp -> /private/tmp on macOS) does not cause a false negative. Non-existent paths are compared lexically.

func WriteFileToRoot

func WriteFileToRoot(root, rel string, content []byte) error

WriteFileToRoot writes content to rel, interpreted relative to the project root (e.g. "public/logo.svg"), creating parent directories as needed. A path that escapes root is rejected.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL