Skip to content

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
uvwt:mainfrom
A-m-o-r-F-a-t-i:feat/agents-md-context
Open

A-m-o-r-F-a-t-i wants to merge 1 commit into
uvwt:mainfrom
A-m-o-r-F-a-t-i:feat/agents-md-context

Conversation

@A-m-o-r-F-a-t-i

Copy link
Copy Markdown

Summary

Add native loading of global and workspace AGENTS.md guidance 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_context primarily 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

  • Ordered discovery: load AGENTDOCK_INSTRUCTIONS_FILE when 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 .git files), the applicable configured default-directory boundary, or the selected directory when neither applies. Do not recursively scan unrelated projects.
  • Startup and refresh: include a labeled, scoped snapshot in MCP initialization. Every agentdock_context call rereads the files and returns current content, so additions, edits, and deletions do not require a Core restart or depend on modification-time caches.
  • Request-local selection: add optional workdir to agentdock_context. Empty arguments retain their existing meaning. An explicit selection does not change command defaults, persistent configuration, or another client's workspace.
  • Observable results: return instruction_files with 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.
  • Configuration: enable automatic discovery by default and provide AGENTDOCK_AGENTS_AUTOLOAD=false as 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.local structure remains unchanged and carries scoped text through its existing rules field; this PR does not claim that older Nexus fleet entrypoints accept the new local workdir argument. No dependency versions are changed.

Validation

The submission is prepared on upstream main at ad51001515a2b1b82baa31281970e0b9f67f28e9.

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.

go test -p 1 ./... -count=1
go vet -p 1 ./...
go build -p 1 -o <local-output>/agentdock.exe ./cmd/agentdock
gofmt -l <changed-go-files>
git diff --check

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 (curl exit 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.md files, unrelated documents, logs, binaries, and runtime configuration. It does not deploy or restart a running AgentDock instance.

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.
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