feat(context): auto-load global and workspace AGENTS.md - #116
Open
A-m-o-r-F-a-t-i wants to merge 1 commit into
Open
A-m-o-r-F-a-t-i wants to merge 1 commit into
A-m-o-r-F-a-t-i wants to merge 1 commit into
Conversation
Make operator and project guidance available through MCP initialization and agentdock_context without requiring separate file reads, ACP, or Recall. Discover the explicit global instructions file or the default AGENTS.md, then load workspace guidance from the applicable root to the selected directory. Return ordered content with provenance, hashes, and explicit load/skip/error states. Read fresh files on each context request. Add an optional request-local workdir selector without changing command working directories or sharing workspace selection across clients. Keep empty-argument calls compatible and preserve the private Nexus context shape through the existing rules field. Bound discovery and content sizes, validate UTF-8, reject automatically discovered symlinks and non-regular files, and deduplicate physical files. Preserve explicit instructions-file behavior and provide an autoload opt-out through AGENTDOCK_AGENTS_AUTOLOAD. Cover discovery, refresh, scope boundaries, Windows path casing, file validation, concurrent workspace isolation, schema compatibility, and MCP initialization/live-context delivery with regression tests. Document the loading contract, configuration, and startup-snapshot limitations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add native loading of global and workspace
AGENTS.mdguidance to AgentDock's MCP context. Clients receive the applicable instructions directly instead of having to discover and read each file themselves. This does not require ACP, Codex, NexusDock, or Recall.Motivation
The existing explicit instructions-file setting provides a startup snapshot, while
agentdock_contextprimarily advertises capabilities and built-in rules. Project guidance therefore depends on clients remembering separate file reads, and switching projects can leave the wrong instructions in context.This change makes file discovery and loading a Core responsibility, exposes which files were actually loaded, and keeps workspace selection local to each request rather than introducing process-wide state shared by clients.
Behavior
AGENTDOCK_INSTRUCTIONS_FILEwhen explicitly configured; otherwise use${AGENTDOCK_HOME}/AGENTS.md. Then load applicable workspace files from the root through the selected directory. Stop at the nearest Git boundary (including worktree.gitfiles), the applicable configured default-directory boundary, or the selected directory when neither applies. Do not recursively scan unrelated projects.agentdock_contextcall rereads the files and returns current content, so additions, edits, and deletions do not require a Core restart or depend on modification-time caches.workdirtoagentdock_context. Empty arguments retain their existing meaning. An explicit selection does not change command defaults, persistent configuration, or another client's workspace.instruction_fileswith source path, scope, status, byte count, and SHA-256 for loaded content. Distinguish missing, empty, duplicate, skipped, and unreadable files instead of presenting incomplete guidance as successfully loaded.AGENTDOCK_AGENTS_AUTOLOAD=falseas an opt-out. Disabling discovery does not disable an explicitly configured instructions file or its existing startup validation.Safety and compatibility
Reads are limited to ordinary UTF-8 text files, 64 KiB per file, a 256 KiB combined content budget, and at most 64 directory levels. Support UTF-8 BOM and CRLF; reject malformed UTF-8, NUL bytes, and oversized files without returning partial instruction bodies. Automatically discovered leaf symlinks and non-regular files are rejected. Explicitly configured files retain their established symlink-resolution behavior. Use
os.Root, file-identity checks, physical-file deduplication, and Unix nonblocking/no-follow open flags to constrain reads.Guidance is labeled by source and scope. Workspace instructions refine project behavior; they are not described as overriding global safety requirements or the client's higher-priority instructions. The loader does not execute file contents or grant additional filesystem access. Because these files are delivered to connected clients, they should contain shareable instructions, not secrets.
The standalone tool gains only optional fields. Contract tests still compare every pre-existing field with the shared protocol. The private Nexus
context.localstructure remains unchanged and carries scoped text through its existingrulesfield; this PR does not claim that older Nexus fleet entrypoints accept the new localworkdirargument. No dependency versions are changed.Validation
The submission is prepared on upstream
mainatad51001515a2b1b82baa31281970e0b9f67f28e9.Passed on Windows/amd64 with Go 1.26.5 and bounded build concurrency: all 48 packages containing tests passed; static analysis, the executable build, formatting, and whitespace checks also passed.
Regression coverage includes ordered inheritance, repository/worktree boundaries, missing and deleted files, same-size/same-timestamp refreshes, explicit global overrides, opt-out behavior, hard-link deduplication, encoding and size limits, cancellation, Windows path casing, concurrent workspace isolation, schema compatibility, and MCP initialization plus live context delivery.
Additional development checks passed for the loader's race tests, Linux/amd64 and macOS/arm64 cross-compilation of the loader, and ten repeated runs of the new MCP integration tests. Broader application/MCP race checking was not completed on the development host because Windows/ThreadSanitizer memory allocation failed. Native Linux/macOS execution and complete platform installer checks are not claimed. A separate Unix installer-entry check under Git Bash reached a local
file://fixture-path failure (curlexit 37); unrelated installer code is unchanged.Operational notes
This is request-driven refresh, not a filesystem watcher or an unsolicited context push. Clients should fetch context before project operations and after changing projects or rules; previously delivered initialization text is still a startup snapshot. Cached tool definitions need to be refreshed after upgrading Core. The documentation and environment example describe these boundaries.
This PR contains only the feature implementation, regression tests, and its documentation/configuration example. It excludes developer-local
AGENTS.mdfiles, unrelated documents, logs, binaries, and runtime configuration. It does not deploy or restart a running AgentDock instance.