Skip to content

docs: make declarative-first an explicit design principle - #158

Merged
jimhoyd merged 2 commits into
mainfrom
docs/declarative-first-agent-guidance
Sep 19, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
docs/declarative-first-agent-guidance

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem and change

Agent guidance said to prefer YAML/native handlers, but did not consistently establish the highest-level declarative approach as a design principle or direct agents to check extensions before generating custom code.

Record the declarative-first principle in Project Direction and contributor instructions. Apply it in llms.txt, the AI-authoring guide, both authoring skills and generated project AGENTS.md. Regenerate llms-full.txt, the packaged Claude skill and the bundled starter. Review also corrected generated guidance that suggested an unsupported auth field; agents are now directed to supported authentication extensions, and MCP registration is described conditionally. Custom functions/middleware remain available for requirements the framework cannot express; agents must explain the gap rather than invent fields or bypass capabilities.

Companion PRs: https://github.com/jimhoyd-com/urlcode-docs/pull/17 (public principle/authoring guidance) and jimhoyd-com/urlcode-template#6 (aligned standalone starter).

Verification

  • Both edited skills pass the skill validator.
  • Generated documentation/plugin checks and git diff --check pass.
  • npm run test:package passed, including packed installation and starter/cookbook checks.
  • npm run verify passed: lint, typecheck, generated-resource checks, build, and 501 tests passed (2 skipped, 0 failed). The first restricted attempt could not bind loopback HTTP test servers; the rerun with local networking passed.
  • Public-docs verification and standalone template validation/tests/audit passed in companion workspaces.

Compatibility and security

Only authoring guidance and generated guide text change. No runtime API, YAML, dependency, permissions or deployment changes. Baseline benchmark experiments must retain the pre-guidance snapshot as specified in the spike.

  • Changes match the documented portable contract; docs/examples are updated where needed.
  • Relevant tests and package checks pass, or limitations are explained above.
  • No credentials, customer data or private project material are included.
  • Runtime/starter changes remain aligned where applicable.

@jimhoyd
jimhoyd merged commit e75875a into main Sep 19, 2026
10 checks passed
@jimhoyd
jimhoyd deleted the docs/declarative-first-agent-guidance branch September 19, 2026 14:53

@jimhoyd jimhoyd left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recording the declarative-first principle once and propagating it to every copy in the same change is the right shape — that is the discipline the trust-model change had to be chased across repos by hand for.

One correction before merge, though: the auth guidance inverts the principle this PR is adding.

Route-level auth is implemented

src/agents-guide.ts and starters/default/AGENTS.md both replace

Authentication is host processing: declare auth on the route, never build login forms, sessions or password checks in functions.

with

Prefer supported authentication extensions and their documented configuration; never invent an auth field or duplicate functionality they provide.

But route-level auth is not an invented field — it shipped:

  • schemas/urlcode.schema.json, routes.<path>.auth: "Short form for a route protected by the declared auth extension. true or an object expands to policies.extensions.auth with the same keys minus required; required: false emits no policy. Refused without an extensions.auth declaration or alongside policies.extensions.auth."
  • src/config.ts: the expansion into the canonical policies.extensions.auth requirement, and the assertion that refuses a route declaring both forms.
  • src/types.ts: the routeAuth type and its documentation comment.
  • test/recipes.test.ts: asserts both auth: true and auth: {role: admin}.
  • ROADMAP.md lists "short forms, route-level auth" among what 0.4.0-alpha.1 carries.

So the new text steers agents away from the short form and toward writing policies.extensions.auth by hand — the lower-level mechanism, which is the opposite of "use the highest-level declarative features whenever possible."

The accurate rule is the conditional one the schema already enforces:

Protect a route with auth: true, or auth: { role: … }, when the project declares an auth extension; it expands to the policies.extensions.auth requirement. Without that extension declared the field is refused at validation — report the gap rather than building login forms, sessions or password checks in a function.

The same applies to the cache short form defined beside it in the schema (Short form for policies.cache … Refused alongside policies.cache; use one form), which the guidance does not mention at all.

Two smaller things

docs/PROJECT-DIRECTION.md now argues with itself. The new principle section lands in the same file whose "why" section showcases

/admin:
  auth: { required: true, roles: [admin] }

as the example of what a route should read like. After this PR that file both demonstrates the field and warns against inventing it. Worth reconciling in this PR since it edits that file anyway — note that the showcase example's roles: (plural) does not match the schema's shape either, so it needs a pass regardless.

Where this came from. docs/NEXT-STEPS.md still lists Phase 4.1 (short-form function routes) and Phase 4.2 (route-level auth) as future work, which is almost certainly what this guidance was written against. That staleness is being fixed separately; flagging it so the two changes do not disagree.

Companion PR

jimhoyd-com/urlcode-template#6 adds a generated AGENTS.md that states "Functions and middleware are sandboxed" and lists link among the handlers. Both are correct for that repo's pinned 0.4.0-alpha.1 — link was removed from core in f7dbe54, after alpha.1 — but it does mean a public starter gains pre-alpha.2, pre-extraction language at merge. Core's own generator (src/agents-guide.ts) already emits the trusted-by-default text. Worth holding that companion until the template repins, or landing it with the pin stated inline.


Generated by Claude Code

jimhoyd added a commit that referenced this pull request Sep 19, 2026
…check guidance against the schema (#160)

* docs: align the documented trust model, plan status and version facts

The 0.4.0-alpha.2 trust-model change (function/middleware trusted and
unsandboxed by default, sandbox: true as the per-route opt-in) had not been
carried through the documentation, docs/NEXT-STEPS.md described shipped work as
future, and no page stated which core version downstream packages support.

Trust model:
- Correct every live claim that functions/middleware are untrusted, sandboxed
  or isolated by default across docs/, README.md and llms.txt, scoping
  QuickJS/WASM statements to routes that declare sandbox: true.
- Annotate rather than rewrite historical text: the ROADMAP 0.1.0-alpha.2
  security-correction entry, the next-phase plan's preserved-architecture
  sentence and the dated usability review keep what they said and carry a note
  that 0.4.0-alpha.2 superseded it.
- Record in docs/SPIKE-DEFAULT-TRUST-MODEL.md that the decision is implemented
  in 0.4.0-alpha.2, evidenced by sandbox/sandboxReason in the schema, and that
  0.4.0-alpha.2 is not yet published.
- Add scripts/check-trust-model-prose.ts, wired into npm run check, which fails
  on a stale claim. It scans 138 files sentence by sentence, allows explicitly
  marked historical text, and does not fire on correctly scoped sentences.

Plan and version facts:
- Mark the 17 docs/NEXT-STEPS.md items that have shipped, citing files and
  symbols rather than line numbers, and record that Phases 1, 3 and 4 largely
  landed before Phase 0 produced a model-backed benchmark run.
- Record dated npm dist-tag facts in docs/RELEASE-READINESS.md, including that
  auth's latest tag resolves an older build than admin's peer floor requires.
- Add docs/VERSION-ALIGNMENT.md: the supported core floor, how each downstream
  form declares it, the rule against publishing an unsatisfiable peer, and the
  publish-core then raise-floors then regenerate ordering.
- Add docs/OPEN-DECISIONS.md: nine decisions documentation cannot make, each
  with what is true today, the options and the cost of leaving it open.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RGEwCLf6egztgdcFPbLGaE

* Teach the auth and cache short forms, and check guidance against the schema

#158 recorded declarative-first as a design principle and, in the same change,
told agents to "never invent an `auth` field". Route-level `auth` is
implemented: schemas/urlcode.schema.json defines it, normalizeRouteAuth in
src/config.ts expands it to policies.extensions.auth, src/types.ts types it and
test/recipes.test.ts asserts both `auth: true` and `auth: {role: admin}`. The
guidance therefore steered agents away from a supported short form and toward
the long policy form it expands to, which is the opposite of the principle it
was introducing. The sibling `cache` short form was not mentioned at all.

- src/agents-guide.ts, and starters/default/AGENTS.md regenerated from it: teach
  both short forms, conditioned on an `auth` extension being declared, within
  the guide's 80-line bound.
- skills/urlcode/SKILL.md: name the short forms as the highest-level form, which
  is what choosing the highest-level supported abstraction means here.
- docs/PROJECT-DIRECTION.md: the showcase example used `roles: [admin]`; the
  schema's routeAuth defines singular `role`, so the flagship example of what a
  route should read like would not have validated.
- llms.txt: state that this revision is 0.4.0-alpha.2 and what its default is,
  rather than calling 0.4.0-alpha.1 current; llms-full.txt regenerated.

Add scripts/check-guidance-claims.ts, wired into npm run check, so this cannot
recur. It derives its rules from the schema rather than a hand-maintained list:
a schema-defined field may not be described as invented or unsupported; a line
enumerating route handlers may name only handlers the schema still defines; a
field the reader is told to declare must resolve. Verified against both real
regressions -- reintroducing the "never invent an `auth` field" sentence fails
it, and returning the removed `link` handler to the inventory line fails it --
and clean on the current tree. A documented marker exempts text that is
deliberately about another version.

docs/OPEN-DECISIONS.md records the check as delivered and leaves open whether it
should also be a required status check rather than only a member of npm run
check.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RGEwCLf6egztgdcFPbLGaE

---------

Co-authored-by: Claude <[email protected]>
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.

1 participant