Skip to content

feat: agentproto self-construction (create_driver, self_inspect, loadAgent, updateManifestSet) - #23

Merged
agentiknet merged 19 commits into
mainfrom
feat/agentproto-self-construction
Jun 20, 2026
Merged

agentiknet merged 19 commits into
mainfrom
feat/agentproto-self-construction

Conversation

@agentiknet

Copy link
Copy Markdown
Contributor

Summary

Enables an agentproto runtime to construct and introspect itself at runtime via MCP tools.

  • create_driver — new MCP verb that registers a DRIVER.md manifest; driver doctype (@agentproto/driver) exposed via DoctypeSpec and threaded into agentproto-serve
  • self_inspect — new MCP tool: reads the running server's own AGENT.md, resolves the full extends chain via loadAgent, returns handle + body so the LLM can inspect its own identity at runtime
  • loadAgent — resolves AGENT.md from disk, validates the extends-chain (AIP-42: max depth 5, cycle detection) before returning; replaces manual parseAgentManifest + agentFromManifest calls
  • validateExtendsChain — standalone validator, re-exported from @agentproto/agent
  • updateManifestSet — atomic multi-file manifest writes (all-or-nothing, no partial writes on error)
  • e2e test — starts a real in-process MCP server, calls create_driver then self_inspect over JSON-RPC transport

Also included

Release pipeline setup (changesets, CI, auto-changeset agent) from chore/release-pipeline.

Test plan

  • CI Build + test passes
  • CI Generate changeset runs and commits a .changeset/*.md to the branch
  • CI Changeset present? passes after the auto-commit

🤖 Generated with Claude Code

agentiknet and others added 19 commits June 20, 2026 03:40
- Add .github/workflows/release.yml (changesets/action two-state flow)
- Update ci.yml: frozen-lockfile, pnpm cache, changeset-check job on PRs
- Add .changeset/config.json + README with full process doc
- Expand scripts/publish-packages.sh to all 50+ packages in dep order
- Fix dead code in corpus/synthesize.ts (trim + startsWith bug)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`pnpm changeset status --since=origin/main` exits with code 254 on some
CLI versions. Replaced with a plain `git diff --diff-filter=A` check —
no pnpm/node install needed, no fragile exit codes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- scripts/auto-changeset.mjs — calls claude-haiku-4-5 with the git diff,
  determines affected packages + bump type, writes .changeset/<slug>.md
- .github/workflows/auto-changeset.yml — triggers on PR open/sync,
  skips if changeset already present, commits result back to branch
- pnpm changeset:auto — same script usable locally

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add DoctypeSpec for DRIVER.md (spec.ts) + re-export from @agentproto/driver index
- Thread driverSpec into agentproto-serve so MCP server registers create_driver
- Add @agentproto/driver dep + external in cli/tsup.config.ts
- Add @agentproto/manifest dep to @agentproto/driver (needed by spec)
- Bundled adapter catalog (catalog.ts) + listAdaptersWithCatalog in resolve.ts
  (carried alongside: serve.ts imports both for adapter discovery)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add validateExtendsChain (AIP-42: max depth 5, cycle detection)
- Add loadAgent — resolves AGENT.md from disk, validates the chain before
  returning {handle, body}; callers no longer need parseAgentManifest + agentFromManifest
- Re-export loadAgent + validateExtendsChain from @agentproto/agent index
- defineAgent: widen extendsChain field type to full AgentManifest[] for runtime use

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- New self_inspect MCP tool: reads the running server's own AGENT.md,
  resolves the extends-chain via @agentproto/agent loadAgent, and returns
  handle + body so an LLM can inspect the current agent's identity at runtime
- Wire self-inspect-tool into the server index
- Add @agentproto/agent + @agentproto/routine deps to mcp-server package.json
- Export self-inspect entry in tsup.config.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- updateManifestSet: accepts an array of {path, patch} pairs and applies
  them atomically (all-or-nothing, no partial writes on error)
- Extend verbs.test.ts coverage for multi-file scenarios

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
End-to-end test that starts a real in-process MCP server, calls create_driver
to register a driver manifest, then calls self_inspect to verify the agent
reads its own identity — exercises the full create_driver → self_inspect path
over the MCP JSON-RPC transport.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
serve.ts destructured model from startSession opts but the type in
http-server.ts didn't declare it → TS2339 build failure.

fix(corpus-cli): clean dist/specs before bundle-specs copy

cpSync without prior rmSync left stale AIP dirs (e.g. aip-49/HARNESS
from before HARNESS was moved to aip-52) in the published package.

docs(aip-52): add ADAPTER.md for Harness spec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Merge auto-changeset.yml into ci.yml with needs: [build-and-test]
  so Claude is never called for a broken build
- Delete auto-changeset.yml (job now lives in ci.yml)
- e2e test: replace `as Array<...>` cast with typed TextContent import
  from @modelcontextprotocol/sdk

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…overage

Previous auto-generated changeset only caught @agentproto/corpus. Branch
actually changed 8 packages: agent (minor), driver (minor), manifest (minor),
mcp-server (minor), cli (patch), corpus (patch), corpus-cli (patch), runtime (patch).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@agentiknet

Copy link
Copy Markdown
Contributor Author

PR #23 — Agentic Code Review

Summary

This PR delivers a dense batch of well-structured features across four packages: AIP-42 extends-chain validation with a new loadAgent async entry point (@agentproto/agent), an atomic multi-file write primitive updateManifestSet (@agentproto/manifest), the self_inspect MCP tool for agent introspection (@agentproto/mcp-server), and a complete CI overhaul including the new agentic PR-reviewer pipeline (.github/workflows/). Two packages (@agentproto/driver, @agentproto/cli) received smaller correctness fixes.


Changeset

Written to .changeset/amber-moles-review.md

Package Bump Reason
@agentproto/agent minor New exports loadAgent, validateExtendsChain, EXTENDS_MAX_DEPTH, ExtendsRef, ExtendsChainLoader — all backward-compatible additions
@agentproto/manifest minor New exports updateManifestSet and ManifestOp — new public surface
@agentproto/mcp-server minor New exports registerSelfInspectTool, selfInspect, summarizeToolRef, summarizeRoutineRef, SelfInspectResult, RefSummary + new self_inspect MCP tool verb
@agentproto/runtime patch AgentAdapterResolver.startSession now accepts optional model? — backward-compatible param addition; internal plumbing only
@agentproto/driver patch Existing create_driver verb through driverSpec is now surfaced/tested via MCP — no public API change
@agentproto/cli patch AgentCliCommand defined locally to break a circular dep — no public API change

CI / workflow / script changes (.github/workflows/, scripts/) carry no package bump per policy.


Findings

Correctness

  • validateExtendsChain depth check is correct. depth increments before the > EXTENDS_MAX_DEPTH guard, so a 5-hop chain (depth reaches 5 on the last parent) passes cleanly. The boundary tests at exactly EXTENDS_MAX_DEPTH and EXTENDS_MAX_DEPTH + 1 confirm this definitively.
  • loadAgent workspace inference — dirname(dirname(dirname(resolvePath(path)))) correctly walks three directory levels up from <workspace>/.agents/<id>/AGENT.md to <workspace>. The integration tests exercise this exact path layout.
  • updateManifestSet atomicity model — each op runs in dryRun mode first (render-and-validate without I/O), then all writes land after all ops succeed. This is a sound "validate then commit" pattern. True POSIX atomicity (rename) isn't attempted, and the docstring is clear about it. The rollback tests confirm partial-failure behavior is correct.
  • selfInspect error handling — sets .code = "agent_not_found" on the thrown Error and the MCP tool returns isError: true rather than propagating a JSON-RPC protocol error. Graceful degradation is correct.
  • auto-changeset vs pr-review race window — both jobs run after build-and-test and push to the branch. The auto-changeset job guards with if: steps.check.outputs.present == 'false', so if pr-review wins and commits first, auto-changeset is a no-op on a re-run. On the first run they're parallel; write_changeset in review-pr.mjs removes stale auto-generated changesets before writing, so the worst case is a harmless reorder. Acceptable for v1.

Type Safety

  • summarizeToolRef / summarizeRoutineRef cast raw to { ref?, file?, inline? } — safe because all three shapes are tested explicitly and the fallthrough returns a stringified JSON representation rather than throwing.
  • The callTool E2E helper narrows result.content via Array.isArray before indexing — correctly avoids the noUncheckedIndexedAccess trap that tripped up earlier commits.
  • AgentCliCommand being defined locally in packages/cli/src/registry/resolve.ts rather than imported from driver-agent-cli (which doesn't yet export it) is the correct short-term fix. A // TODO: import from @agentproto/driver-agent-cli once exported comment would be a welcome breadcrumb.

Tests

  • validate-extends-chain.test.ts — 9 cases: no-parent, max-depth boundary, over-depth, direct cycle, indirect cycle, inline-stop, unresolvable-ref, and error-message prefix. Comprehensive.
  • load-agent.test.ts — 5 integration cases using real tmpdir I/O: no-extends, single-level, exact-max-depth, over-depth, cycle. All use try/finally for cleanup. ✅
  • e2e-driver-selfinspect.test.ts — Full JSON-RPC round-trip via InMemoryTransport for create_driver, load_driver, list_driver, and self_inspect (success + agent_not_found). Excellent E2E coverage.
  • verbs.test.ts (updateManifestSet) — covers all-success, mixed-ops, rollback-on-first-failure, and rollback-on-middle-failure.

AIP Alignment

  • EXTENDS_MAX_DEPTH = 5 matches AIP-42 §extends depth constraint.
  • Cycle detection uses a Set<string> of visited IDs — correct implementation of the spec's "same id must not appear twice" rule.
  • self_inspect resolves <workspace>/.agents/<agentId>/AGENT.md — consistent with the AIP-42 workspace layout convention used throughout the codebase.
  • create_driver E2E validates the agentproto/driver/v1 schema literal on disk — confirms AIP-30 alignment.

Nits

  • Stale comment in ci.yml — the pr-review job's comment block still contains a paragraph from the original auto-changeset description ("On PRs: auto-generate a changeset via Claude if one is missing…"). The description no longer matches what the job does. Low-priority cleanup.
  • Race window — Consider making auto-changeset depend on pr-review (or vice-versa) to serialize branch pushes and eliminate the parallel-push race entirely.
  • selfInspect doesn't call loadAgent — it calls agentVerbs.load directly, bypassing validateExtendsChain. This is fine for introspection today, but if self_inspect is expected to enforce full AIP-42 validation at runtime, it should route through loadAgent. Worth a note for future hardening.

Verdict

LGTM ✅ — All new features are correct, well-tested with real I/O and full E2E JSON-RPC coverage, properly exported, and cleanly aligned to AIP-42/30 specs. The CI overhaul (frozen lockfile, action v5 bumps, pnpm cache, agentic reviewer pipeline, release workflow) is a significant improvement. Minor nits do not block merge.

@agentiknet
agentiknet merged commit 13b4a09 into main Jun 20, 2026
3 checks passed
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