Skip to content

Latest commit

 

History

History
143 lines (98 loc) · 7.42 KB

AGENTS.md

File metadata and controls

143 lines (98 loc) · 7.42 KB

AGENTS.md

This document supplements instructions in CONTRIBUTING.md rather than replacing them.

Quick Start

composer test # PHPStan + deptrac + tests + PHPCS (run before commits)
composer unit -- --filter X # Run specific tests
composer phpstan -- --error-format=raw --no-progress # run phpstan
composer phpstan -- --error-format=raw --no-progress path/to/analyze # run phpstan on a specific path
composer phpcs -- -q --report=emacs # run code style checks (PSR-12)

Development Workflow

  • Before a pull request leaves draft, a fresh agent runs the pr-review skill on it.

Design

The project is a language server for PHP. Every design rule below exists to stop one problem: multiple routes to one fact. Routes drift, and the drift shows up as a feature that works in hover but not in completion, or a member kind that inherits while another does not.

The codebase is undergoing structural transition to eliminate this issue.

ADR documents are being added in docs/adrs to capture the intended architecture and context behind it. If a session leads to a design decision, that decision should be captured in a new ADR. ADRs should be considered read-only once landed to main, with the exception of changing the status (e.g. superseding or abandoning).

Services and data types

A data type is a readonly structure over one or more values. It carries no logic beyond formatting and simple checks.

Application-wide data types live in src/Domain/. A data type that only one service uses lives next to that service, and should not be referenced outside of that service.

A service produces or exposes facts: which symbols a file declares, which file defines a symbol, what type an expression has. The interface describes what a caller can ask. It never says where the answer comes from, and it never takes a parser node or a reflection object where another implementation would take something else.

Code decides by what a symbol can do, such as whether it can be instantiated, not by checking which kind of symbol it is.

Factories

A factory must justify its existence. Most do not. Construction logic that several methods share is a private method on the service. Construction logic that several implementations of one family share is a trait in that family.

Handlers

An LSP handler extracts parameters, calls a resolver interface, and formats the result. A handler never parses a document, walks a tree, resolves a type, or looks up a member. If a handler is about to do one of those, the logic belongs in a resolver implementation.

Type graph

Every question about the type graph goes to the member resolver, member lookup and subclass checks alike. Its implementation walks used traits, then the parent chain, then interfaces. No other class walks the graph, so no member kind can see a different hierarchy than another. MemberResolverTypeGraphTest checks the reported members against PHP's runtime reflection.

Client capabilities

The raw initialize parameters are read once, in src/Capability/. Every decision that shapes output by client support reads SessionCapabilities. A capability the client does not declare takes its default value. A workaround for one editor's behavior lives in one place, outside feature logic.

Positions

Positions use one encoding inside the server and are converted only where messages enter and leave it.

Robustness

Bad input, from the client or from the project's files, never ends the process. Every request is answered correctly without background work, and background work never delays a request.

Code that does not parse

Code being edited usually does not parse, and every feature must keep working on it. At any position, every feature sees the same structure, and it is the structure the code will have once completed. Whether a feature must handle some shape of broken code is answered from the parser's guarantees (ParsedDocument, Located), never from how recovery happens to work.

Source text

Every read of a document's text goes through DocumentSourceInterface. Its composite answers from the editor's buffer while the document is open and from disk otherwise. While a document is open the server must not read it from disk ([LSP] textDocument/didOpen).

Caching

A service may hold an index it derives from its whole source and rebuilds on invalidation. A service never remembers the answer to a query. What a document declares is remembered by one PSR-16 decorator on DeclarationSourceInterface, applied in wiring. Its key is the document's path and text together, so an entry describes one state of one file and is never invalidated. The cache's size limit evicts.

Invalidation

The server never decides on its own that an answer is stale. The editor is the only source of change events. Two events invalidate: workspace/didChangeWatchedFiles for a path, and closing a document that was open. Both flow through InvalidatableInterface::invalidate, which fans out to every invalidatable in the wiring. An open buffer is not an invalidation; it wins by composite order while it is open. Built-in symbols should describe the PHP version the project targets; today they come from the PHP running the server, so they are never invalidated.

Handling Design or Specification Tensions

This codebase is in flux, and the current state may not reflect the intended design. Issues may have been written prior to the intended structure, and may be in tension with the goal. If you encounter this scenario, stop and ask the human.

Staying on track

Before each new change in a session, check it against the original request:

  • Proposed on its own, would this change be outside the scope of the original request?
  • Has a review or test found a new case of the same kind of problem in code you have already fixed?
  • Does this change satisfy the wording of a tool's rule or a test while doing what that rule or test exists to prevent?

If any answer is yes, stop and report what is happening instead of continuing. A review finding in code the pull request did not introduce becomes a new issue, linked from the pull request, not a change to it. When a tool such as PHPStan or deptrac blocks a change, the intent of its rule matters, not its wording: ask before working around it.

Development Workflow

  • GitHub issues are the source of truth for feature specs. Confirm a feature is not already built, and resolve every open question before writing code.
  • A good issue states which service owns each fact and how the work separates concerns. Adding a feature extends the existing route for its fact, or adds the first one; it never adds a second.
  • A fact read from syntax gets its first route in the one walker that reads the syntax tree, never in a feature.
  • Debug through the test suite. Do not write ad hoc PHP scripts.
  • When creating a new issue, add the ai-authored label.
  • Work that changes what the server says about code follows the fix-a-fact skill: its design is reviewed adversarially against PHP's behavior and the one-route rule before any code is written.
  • Fix at the root. When routes to a fact disagree because a lower-level fact is wrong, fix that fact first, in its own pull request, instead of patching the symptom where it shows.
  • A pull request description is for a reader with no context: the problem with a short example, the cause, then the change. State PHP's behavior plainly rather than citing php-src.

LSP Protocol

The server communicates over stdio. docs/vim-ale.md has Vim setup notes.