Skip to main content

Module asset_paths

Module asset_paths 

Source
Expand description

Package-root prompt asset addressing (issue #742).

Pipelines that move files around want stable, refactor-safe paths to .harn.prompt assets. Source-relative ../../partials/foo.harn.prompt paths break the moment a caller is renamed or relocated. This module resolves a small URI scheme that anchors prompt assets at the project root or a project-defined alias instead:

  • @/<rel> → resolved from the calling module’s project root (the nearest harn.toml ancestor of the calling file, not the workspace cwd).
  • @<alias>/<rel> → resolved from a [asset_roots] entry in the project’s harn.toml, e.g. [asset_roots] partials = "...".

Plain (non-@) paths fall through to the caller’s existing source-relative resolver — back-compat is exact.

Lives in harn-modules so the VM, the LSP, and the CLI’s preflight checker can share one resolver and produce identical errors.

Enums§

AssetRef
A parsed @-prefixed asset reference.

Functions§

find_project_root
Walk up from base looking for the nearest ancestor containing harn.toml. Mirrors harn-vm’s in-VM walker so the resolver can run from the LSP/CLI without dragging in the VM crate.
is_asset_path
Returns true when path starts with the @-asset prefix.
parse
Parse an @-prefixed path. Returns None for plain paths so callers can fall back to source-relative resolution. Malformed @-paths (e.g. @foo with no slash) also return None; the resolver wraps None cases into a parse-time error when the caller knows it has an @ prefix.
resolve
Resolve an @-prefixed asset path to an absolute filesystem path.
resolve_or
Convenience for the common case in render_prompt(path, ...): resolve @-prefixed paths against the project root, otherwise apply the caller’s source-relative fallback.