Skip to content

Add ExtensionActivation.root so extensions can resolve project-relative paths - #130

Merged
jimhoyd merged 1 commit into
mainfrom
claude/extension-activation-root
Sep 19, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/extension-activation-root

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Why

urlcode-middleware (a new, separate repo — see
jimhoyd-com/urlcode-middleware)
needs to resolve project-relative middleware source files declared in its
policies.extensions.middleware config (e.g. middleware/headers.mjs), the
same way core's own functionFile()/router.ts resolves native
function/middleware source entries against the project root. But
ExtensionActivation ({origin, target, projectSha256, mounts}) carries no
project directory to resolve against.

process.cwd() is not a reliable substitute — verified by reading
src/cli.ts/src/config.ts:

  • --project <directory> and --host-file <path> are independent, explicit
    paths a caller passes; nothing ties them to the process's working directory.
  • urlcode serve --project DIR can be started from any directory.
  • createRuntime(project, options) (the JS API) accepts a project path
    with no relationship to cwd() at all.
  • loadDocument() already resolves the real project root via
    realpath(project), independent of cwd() — that's loaded.root, already
    computed in runtime.ts and already used for compilePolicies and
    functionFile() — but never passed to prepareExtensions()'s activation
    context.

This is the same category of small, additive contract gap PR #129 closed for
wrap semantics; this closes the equivalent gap for path resolution.

What changed

  • src/extensions.ts: adds root: string to ExtensionActivation,
    documented as the project's resolved absolute directory — the same value
    functionFile() resolves native sources against — and explicitly not
    process.cwd().
  • src/runtime.ts: passes loaded.root through to prepareExtensions's
    context so every RuntimeExtension.activate() receives it.
  • test/extensions.test.ts: asserts activate() receives the resolved
    project root, and adds a dedicated regression test that chdirs to an
    unrelated directory before activation and confirms the observed root is
    still the project's own resolved directory, not cwd().
  • docs/SPIKE-CORE-LAYERING.md: records this as a second gap the middleware
    extraction surfaced (alongside the wrap-semantics gap Add ExtensionInstance.middleware: wrap semantics alongside authorize's gate #129 already closed),
    now resolved the same way.

No schema change, no behavior change for existing extensions that don't read
context.root.

Verification (real, not assumed)

  • npm run typecheck — clean
  • npm run lint — clean
  • npm run check — clean (llms-full.txt does not include SPIKE docs, so no
    regeneration needed)
  • npm run verify (lint + typecheck + check + build + full test suite) —
    487 tests, 485 pass, 2 pre-existing skips, 0 fail

Downstream dependency

jimhoyd-com/urlcode-middleware's
own implementation PR depends on this merging (and on this version of
@jimhoyd/urlcode being published) to resolve middleware/ source files
against the real project root instead of guessing at cwd().


🤖 Generated with Claude Code

https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr


Generated by Claude Code

…cwd()

urlcode-middleware needs to resolve project-relative middleware source
files (the same way core's own functionFile()/router.ts resolves native
function/middleware `source` entries) the same way core does, but
ExtensionActivation ({origin, target, projectSha256, mounts}) had no
project directory to resolve against. process.cwd() is not a substitute:
--project/--host-file are independent, arbitrary paths, a server can be
started from a different working directory than the project, and the JS
API can load a project programmatically with no relationship to cwd() at
all (confirmed by reading src/cli.ts/src/config.ts: loadDocument() takes
an explicit `project` path and resolves it via realpath(), independent of
cwd()).

- src/extensions.ts: adds `root: string` to ExtensionActivation, documented
  as the project's resolved absolute directory, the same value functionFile()
  resolves native sources against, and explicitly not process.cwd().
- src/runtime.ts: passes loaded.root (already computed there, already used
  for compilePolicies and functionFile()) through to prepareExtensions'
  context, so it reaches every RuntimeExtension's activate().
- test/extensions.test.ts: asserts activate() receives the resolved project
  root, and adds a dedicated regression test that changes process.cwd() to
  an unrelated directory before activation and confirms the observed root
  is still the project's own resolved directory, not cwd().
- docs/SPIKE-CORE-LAYERING.md: records this as a second gap the middleware
  extraction surfaced (alongside the wrap-semantics gap #129 already
  closed), now resolved the same way.

Verification: npm run typecheck, npm run lint, npm run check, full
npm run verify (487 tests, 485 pass / 2 pre-existing skips, 0 fail).

Claude-Session: https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd merged commit 2eafa11 into main Sep 19, 2026
10 checks passed
@jimhoyd
jimhoyd deleted the claude/extension-activation-root branch September 19, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants