Files
configkit/docs/roadmap/absolute-imports.md

18 KiB

Absolute and parent-relative imports

Status: agreed target behavior; implementation pending. Baseline: 9037fdb74e1cd4f35ac78032f1bf70854b0e8754.

Purpose and agreed direction

Applications should be able to import shared configuration from locations such as /etc/shared/logging.yml, even when their discovered main file lives in another directory. The declaring file's canonical directory supplies the base for relative imports. Absolute host paths select their named targets directly.

For ordinary host-file loading, enabling imports is sufficient to enable these paths. Omission of an explicit containment root permits imports elsewhere on the host, subject to filesystem access and the existing import rules. Parent-relative paths such as ../shared/logging.yml follow the same access policy. Absolute and relative spellings of the same target should not acquire different permissions merely because of their spelling.

An explicitly supplied FilesystemContext.Root remains an intentional boundary. Applications can continue choosing containment when they need it. Supplied fs.FS values remain their own namespaces; an import from such a namespace does not silently switch to host filesystem access.

This feature changes filesystem selection and access. Existing composition, precedence, configuration destinations, schema/version handling and inspection semantics continue to apply.

Current baseline

The configuration contract currently accepts slash-separated relative selectors and rejects absolute paths. Host access uses a canonical root which defaults to the selected main file's directory. Relative targets and symlink targets must remain within that root. A caller can supply a wider root, but absolute selector syntax remains invalid.

Host byte, reader and mapping sources currently require explicit absolute BaseDir and Root directories for filesystem imports. A Filesystem.File source uses its selected namespace, with . as its default root. Synthetic sources with native context provide namespace-relative base and root directories. Diagnostic labels do not establish filesystem locations.

Internally, the resolved context carries a root and base, and live host access opens an os.Root for that root. Selection, link resolution and resource-context construction rely on those facts. In particular, contextsForResolvedSources rejects source directories outside the selected root. Updating only selector validation would therefore leave external imports unusable.

The same context machinery supports main-relative inputs, captured main sources, selected overlays, passive resource contexts and configured secrets bootstrap. Their uses of a root need explicit consideration when import access changes.

Target behavior

Host selectors and resolution

The following is valid when imports are enabled:

config:
  imports:
    - path: /etc/shared/logging.yml
    - path: ../shared/application.yml
    - dir: /etc/shared/fragments
      pattern: "*.yml"
    - glob: "/etc/shared/services/*.yml"

Apply the same absolute/relative resolution policy to path, dir and glob, including each element of a path or directory list. Existing selector-specific options, wildcard grammar, filtering, ordering and requiredness remain in place. An absolute glob establishes its absolute starting location; it does not scan the declaring file's directory first. Handle path roots separately from pattern segments so normalization preserves wildcard and escape semantics.

Absolute globs also work within an explicit containment root. With Root: /etc/myapp, /etc/myapp/fragments/*.yml starts wildcard discovery in /etc/myapp/fragments; resolving its literal prefix must not fail merely because / and /etc are ancestors of the allowed root. Establish the literal starting directory before wildcard discovery, then apply the existing containment and traversal rules. The same rule applies within a supplied filesystem namespace.

Preserve traversal order when parent segments follow wildcards. For example, services/*/../shared/*.yml must expand the wildcard directory segment before processing its following .., using the existing link-handling rules. Cleaning the complete pattern as though * were a literal directory name would change which directories are visited and could suppress relevant access errors.

Relative imports in an acquired file resolve from that file's own canonical directory, including when it lies outside the main file's directory. YAML destination and placement continue to describe configuration-tree placement; they do not affect physical path resolution.

Resolve host paths using the supported host platform's path rules while preserving existing slash-based selector and glob conventions. Absolute volume roots must not be accidentally interpreted as relative components where the platform supports them. This feature does not expand the project's platform support commitments. It adds no URL fetching, shell expansion, environment substitution or implicit directory search.

Supplied filesystem namespaces

A leading / in a YAML import selector starts at the selected fs.FS namespace's root. For example, /shared/common.yml selects that namespace's shared/common.yml; a relative selector starts at the declaring file's directory. Apply this interpretation consistently to path, dir and glob. An explicit Root continues to bound canonical targets within the namespace.

Translate selector paths to valid namespace-relative paths for Go filesystem operations. The existing fs.ValidPath conventions for Filesystem.File and FilesystemContext Go arguments remain unchanged. YAML selector syntax expresses one conceptual absolute/relative rule across host and supplied filesystems while respecting the selected namespace.

The namespace-root interpretation of a leading / applies to YAML selectors. Symlink target strings returned by a supplied filesystem retain their existing interpretation and validation, including existing fs.ReadLinkFS capability handling. Do not apply YAML selector rewriting to those target strings; a host absolute target returned by a filesystem wrapper must not be reinterpreted as an absolute YAML path within that namespace.

Keep relative-path base selection independent of optional import containment. For host files, an omitted Root means unrestricted host import scope; a supplied root retains existing validation and containment semantics.

Host byte, reader and mapping sources retain their existing requirement for an explicit absolute BaseDir, including when all selectors are absolute. Their host context may omit Root. This preserves a predictable relative base without inferring filesystem locations from display labels or the working directory. The redundant base for an absolute-only synthetic document is an accepted tradeoff for keeping the existing context model straightforward.

An explicit absolute existing BaseDir without Root is also a usable host context for NoSource(), optional discovery exhaustion, and main-relative fallbacks where a host context is applicable. It supplies the relative lookup base and default resource root, with no import containment boundary. Existing root-only absent-main contexts continue to use that root as their base and explicit boundary. Omitting both does not infer the working directory. These rules do not change context selection or the rule that a selected host file determines its own base and rejects an explicit BaseDir.

Apply explicit containment to canonical targets, including symlink targets and every transitive import. Without an explicit boundary, a host symlink target outside the main file's directory is eligible under the normal import rules. Existing discovered-link follow behavior remains independent of whether the resolved target is inside the former default root.

Use ordinary filesystem facilities and existing stable-input assumptions. No additional sandbox, isolation, adversarial mutation guarantee, allowlist, confirmation step or numeric limit is part of this feature.

Identity, loading and reporting

Retain canonical access identity separately from selector spelling. Absolute, parent-relative and symlink spellings of the same file must participate in the existing cycle/repeated-source detection within its established scopes. Cross-directory imports remain in the same host namespace for those checks. Preserve established canonical-path identity, including the existing treatment of hard links, rather than adding inode identity or new deduplication rules.

Maintain deterministic selection and dependency-ready composition ordering under the existing import scheduling model. Source records, import sites, source-local coordinates, version evidence and configuration destinations continue to identify actual acquisitions. Absolute paths must not create a second composition or precedence model.

External imports must work through ordinary and layered loading, mapping and sequence-item placement, discovered mains and main-relative underlay contexts. Prepared main sources must retain whether containment was expressly selected; materializing a default context during preparation must not turn an omitted import boundary into an explicit one on a subsequent load.

With no later context, a prepared main retains its captured policy. A later compatible host context may explicitly select containment at the captured resource root: preparing without Root and then loading with Root equal to the main directory remains valid and applies that explicit boundary. Omitting Root in a later context does not remove a boundary explicitly selected during preparation. Continue rejecting incompatible root changes under the existing prepared-source contract. Context compatibility must account for the selected containment policy as well as resolved paths.

Keep passive SourceContext reporting usable for externally imported files, including through resolution and available failed-load inspection. Its filesystem and slash-relative BaseDir must address the contributing source's directory. For host sources inside the previous default root, preserve their existing resource contexts and FS/BaseDir coordinates. A newly eligible external source without an explicit containment root receives a passive context rooted at that source's canonical directory, with BaseDir equal to .. With an explicit root, continue using it for the passive context as today.

For a synthetic or absent host source with BaseDir and no explicit Root, use that BaseDir as its default passive resource root, with resource BaseDir equal to .. Imports inside that resource root share it; external imports receive the source-directory-rooted context described above. A main-relative input preserves its inherited resource context, including its resource root and base coordinates, instead of manufacturing a new resource root from its relative lookup base.

This gives an external file the default resource scope it would have when loaded directly, while retaining established consumers' contexts. A caller needing resource access beyond that directory can select a broader explicit context. Broader import access does not automatically make the host filesystem root the passive resource root. Loading must not fail simply because a source directory lies outside the former implicit import root. These choices do not establish a general filesystem sandbox guarantee.

Release library-owned acquisition handles before returning, as today. No additional close obligation or background activity is introduced.

Selected-overlay lookup conventions and main-relative context selection retain their existing meanings. Imports within inputs that support them use the policy above once their context has been selected. A broader import scope must not accidentally change overlay search locations.

Configured secrets bootstrap retains its separately documented relative-path and containment rules in ADR 0023 and the configuration contract. Changing imports does not implicitly enable absolute secrets directories, widen their default root, or make Load modify the environment. Separate the internal facts where a shared root currently conflates these responsibilities.

Additive compatibility and release intent

Implement this as an additive feature suitable for a minor release under the release policy: pre-existing valid configurations must continue to work. Strictly identical behavior is not required by that policy. Existing public Go signatures and fields need no removal or incompatible change to support the selected design.

Preserve established relative imports, explicit-root validation and containment, composition and precedence, source identity/reporting, and existing passive resource contexts. Synthetic host sources supplying both BaseDir and Root continue to work. Making Root optional and accepting additional YAML selector spellings expands the supported input set.

Relaxing implicit main-directory import containment is a deliberate revision of the documented default. The release note must explain that broader default and show how callers can retain containment by explicitly setting FilesystemContext.Root. Do not describe the release as preserving all former rejection behavior. Previously invalid absolute or outside-default-root imports can become valid; explicit boundaries continue to apply.

Keep secrets bootstrap and overlay lookup behavior intact. Compatibility coverage should exercise representative previously valid configurations and their source/resource contexts alongside the newly accepted forms. The intent adds no release gate or requirement for downstream consumers to rewrite working configuration to adopt the release.

Changes needed from the baseline

  • Declarations and selection: revise selector validation, absolute-root recognition, parent-relative normalization, directory selection and glob starting locations. Preserve existing import defaults and error distinctions; newly valid paths must still honor missing/required and inaccessible-target behavior. Filesystem-dependent interpretation belongs with the selected namespace rather than assuming every selector is a host path.
  • Access and contexts: distinguish an authored containment boundary from a relative base and from any root used for passive resource access. Revise host/native context resolution, rooted access and link handling accordingly. Unrestricted host access may require different internal access setup from explicitly rooted access; opening the main directory alone cannot implement it. Preserve caller-owned filesystem and reader ownership.
  • Pipeline integration: carry those distinctions through discovery, main-relative bindings, ordinary/grouped acquisition, prepared mains and source-context construction. Reuse existing acquisition accounting and graph admission. Avoid a separate absolute-import pipeline, repeated source reads, or a retained root handle per imported file.
  • Contracts and decisions: update docs/config.md, public filesystem-context comments, relevant consumer examples and docs/internal/imports.md when the implementation lands. Record the revised default and context distinctions in a new ADR, including the extension of inherited containment described by ADR 0022. Preserve accepted ADR decision text and the configured-bootstrap contract. Update architecture policy only where its statements are affected. Document the additive compatibility intent and default-containment change in the minor release note.
  • Behavioral verification: replace tests of the former implicit restriction with coverage of the new default and retained explicit-root choice. Cover all selectors, transitive relative bases, parent-relative paths, explicit-root failures, symlink aliases, repeated sources and cycles. Include representative discovery/preparation, mounted input, provenance/resource-context and failed inspection interactions. Verify namespace-root YAML selectors separately from unchanged Go filesystem argument conventions. Include compatibility cases for existing valid relative imports, explicit roots, synthetic contexts and passive resource coordinates. Include a glob with parent traversal after a wildcard, absolute globs whose literal prefixes lead into an explicit host or namespace root, and synthetic and absent-main host contexts with an omitted root. Exercise BaseDir-only main-relative fallbacks and retained root-only absent-main behavior. Cover prepared-source loads that inherit the captured boundary, explicitly narrow an unbounded capture at its resource root, or supply an incompatible root; an omitted later root must preserve captured containment. Include inherited main-relative resource contexts and the distinction between native YAML selectors and native symlink targets. Reuse existing semantic, budget and cleanup coverage rather than adding a Cartesian test matrix or performance thresholds.

The implementation plan owns sequencing and concrete verification commands. This roadmap proposes no new release gates, dependencies or public performance guarantees. Completion means eligible absolute and parent-relative imports work end to end, with intentional caller-selected boundaries and consistent source evidence, without unrelated changes to configuration composition or startup.