# Runtime stack and substitution tokens (https://docs.neuralisapp.com/package-system/runtime-stack)

Packages and skills never guess where the platform lives. The runtime stack
snapshot, built once per process at bootstrap, is the one source of host
classification, container-versus-host paths, bind mounts and backing-service
URLs, read by the agent's `<runtime_stack>` block, the path resolvers and any
package that needs its environment.

## `RuntimeStackInfo` [#runtimestackinfo]

`discoverRuntimeStack()` (from `@neuralis/package-system/paths`) reads the
environment, OS signals, and a few cheap filesystem checks, and never throws.
The resulting shape is **closed** — every field is present, and a value that
is not meaningful for the environment is `null`, never `undefined`:

| Group | Fields |
| --- | --- |
| Host classification | `osKind`, `osRelease`, `osType`, `nodeVersion`, `isDocker`, `isWSL`, `wslDistro` |
| Container path roots | `neuralisHome`, `appRoot` (platform-internal zone), `projectsRoot`, `cwd` |
| Host path roots | `hostHome`, `hostAppRoot`, `hostProjectsRoot` — populated in Docker when the host home is configured; on native deploys they mirror the container roots |
| Mount table | `osMounts[]` — `{ key, containerPath, hostPath, readOnly }` per configured bind mount |
| Services | `qdrantUrl`, `ollamaUrl`, `embeddingModelId`, `brainInfraMode`, `maxAgentSteps`, `apiBaseUrl` — URLs and headline knobs only, never secrets |

Mounts come from the `NEURALIS_MOUNT_<KEY>` env triplets the platform's mount
tooling writes. `services.apiBaseUrl` is the loopback base URL of
`/api/packages/*`, which the `${NEURALIS_API}` token (below) resolves to.

## Path translation [#path-translation]

Two pure functions translate between the container view and the host view
using the snapshot:

- **`resolveHostPath(stack, containerPath)`** — container → host (app root,
  projects root, then every mount; segment-aware; unchanged on native deploys).
  Use it wherever a user expects a path to paste: sync logs, tool results,
  file trees.
- **`resolveContainerPath(stack, hostPath)`** — the reverse, so a host path a
  model pastes back is translated before spawn and policy mapping.

`realProjectRoot(stack, projectId)` returns both views
(`{ containerPath, hostPath }`) for a project's filesystem root, and refuses
unsafe or sentinel project ids.

### What the prompt block carries [#what-the-prompt-block-carries]

The `<runtime_stack>` block is rendered once per stream, in a fixed order: host
flags and path roots; the **source table** (each source the caller can address:
connector, effective read/write/exec policy, description); one **`data_areas`**
row per visible package with a manifest
[`dataLayout`](https://docs.neuralisapp.com/package-system/manifest.md#datalayout--where-the-package-keeps-its-files)
(never its `machineWritten` list); the mount table; the service URLs. It derives
from boot-time facts and manifests only, so it stays byte-stable for the whole
conversation and the prompt cache holds; volatile per-source state goes in the
trailing `<workspace_live>` reminder. The mount-table lines are display labels:
no tool resolves a mount label as a URI, so make a host path agent-callable by
attaching it as a source.

## The file coordinate quadruple [#the-file-coordinate-quadruple]

Every package file (skill, rule, instruction, agent, doc) carries up to four
coordinates that tie the contribution to the filesystem — the
`(uri, connector, osUri, containerDir)` quadruple on `PackageFile`:

| Field | Meaning | When filled |
| --- | --- | --- |
| `uri` | Address in the filesystem-tool layer (`packages://<dir>/...` — the directory name, not the registry id — `data://<src>/...`, `brain://...`) | Project packages and source-contributed files; undefined for builtins read from the image |
| `connector` | Connector kind serving the URI (`'folder'`, `'webtop'`, `'brain'`, …) | Always reflects the disk layout, even when `uri` is undefined |
| `osUri` | Absolute path in the connector's own environment — host-side for host-anchored kinds, container-internal for sandbox kinds — produced by the connector's `resolveOsUri`. Read it together with `connector` to know which. | When the connector can derive one; UI and vectors consume it |
| `containerDir` | Container-internal absolute path (for a skill: its bundle directory) | Always for builtin and project-package files; for source-fed files only when a local mount maps into the container |

A connector never fabricates a host path. One that cannot derive a real one
either **throws a structured `OsUriUnresolvableError`** — so URIs surfaced to
the UI and the vector store never contain stale fallbacks — or, when its store
is a sandbox whose internal absolute paths are themselves the true coordinate,
returns that internal path instead. Container-backed desktop sources take the
second route, which is why the host/container translators re-map only
host-anchored kinds. See
[Connectors](https://docs.neuralisapp.com/package-system/connectors.md) for the contract.

## Activation substitution tokens [#activation-substitution-tokens]

When a skill is activated through the `execute` tool, the host renders the
skill body — and resolves the skill's environment — with these tokens:

| Token | Resolves from | Typical use |
| --- | --- | --- |
| `${SKILL_DIR}` | The skill bundle's `containerDir` | `node "${SKILL_DIR}/scripts/run.mjs"`; also expands inside the shell `cwd` parameter |
| `${SKILL_URI}` | The skill's `uri` | `fs_read` access to bundle files when no container path exists |
| `${SKILL_CONNECTOR}` | The skill's `connector` kind | Branching a body on how the bundle is reachable |
| `${SKILL_NAME}` | The skill's id | Self-reference in logs and output |
| `${SESSION_ID}` | The active stream session | Correlating script output with the conversation |
| `${NEURALIS_API}` | `services.apiBaseUrl` | the local host base URL for scripts that call host routes (authenticated by the [session ticket](https://docs.neuralisapp.com/package-system/sessions.md)) |
| `${SKILL_CREDENTIALS_RESOLVED}` | The declared `credentials:` ids that resolved, comma-joined | Letting a body state which keys its scripts will find in the environment |
| `${SKILL_CREDENTIALS_MISSING}` | The declared ids that did **not** resolve | Telling the model to degrade instead of failing on a missing key |

A ninth form, `${MISSING:<id>}`, is per-credential rather than a fixed token: it
renders as `(missing: <id>)` or `(present: <id>)` for the id named inside it.
Values are never substituted — the tokens carry names and coordinates, and the
secrets themselves reach only the script's environment.

An unknown `${...}` placeholder is left intact, visible to the model. When the
skill's connector provides no container directory, `${SKILL_DIR}` resolves to an
explanatory sentinel and the platform shell cannot run its scripts; if the
skill's source can execute commands itself, the activation envelope prints the
directory URI to pass as the `execute` working directory. Activation flow:
[Skills](https://docs.neuralisapp.com/package-system/skills.md).

## How packages receive the snapshot [#how-packages-receive-the-snapshot]

The host threads the snapshot to every package through the bootstrap-complete
[lifecycle](https://docs.neuralisapp.com/package-system/lifecycle.md) context, beside the aggregated URI
policies. Nothing secret belongs in it: secrets go through the
[credential store](https://docs.neuralisapp.com/package-system/credentials.md).