Agent Skills & AGENTS.md (openhusky-skills)
openhusky-skills implements the open agentskills.io SKILL.md specification and hierarchical AGENTS.md instruction loading using standard JDK 21 APIs—with zero SnakeYAML and zero process execution (enforced by ArchUnit).
<dependency>
<groupId>dev.openhusky</groupId>
<artifactId>openhusky-skills</artifactId>
<version>0.3.0</version>
</dependency>implementation("dev.openhusky:openhusky-skills:0.3.0")3-Stage Progressive Disclosure & Prompt Cache Stability
Injecting dozens of full operational playbooks into the system prompt inflates token usage, dilutes attention, and invalidates provider prompt caches whenever any document changes. openhusky-skills uses 3-Stage Progressive Disclosure:
- Stage 1 — Compact Catalog (
SkillContextComposer): Injects only<available_skills>XML (<name>+<description>) into the stable system prompt prefix, preserving high prompt-cache hit rates across turns. - Stage 2 — On-Demand Playbook (
load_skill): When a task matches a skill's<description>, the model invokesload_skill(name)(readOnly = true,PARALLEL_SAFE), which returns the fullSKILL.mdbody and lists relative bundled resource paths under<skill_resources>. - Stage 3 — Lazy Resource Inspection (
read_skill_resource): If the model needs a specific reference table or template, it callsread_skill_resource(skill_name, path)(readOnly = true,PARALLEL_SAFE) to load UTF-8 files up tomaxResourceBytes(64 KiBdefault).
SKILL.md Frontmatter & Directory Layout
A skill directory contains a required SKILL.md plus optional relative resources (references/, scripts/, templates/):
skills/
└── refund-policy/
├── SKILL.md
└── references/
└── refund-matrix.mdFrontmatterParser validates SKILL.md frontmatter without SnakeYAML:
---
name: refund-policy
description: Standard operating procedure for evaluating B2B and retail refund requests, SLA credits, and escalation thresholds.
license: Apache-2.0
compatibility: Supports Support Desk v2+
allowed-tools:
- lookup_order
- issue_refund
metadata:
tenant: nimbus-cloud
owner: support-ops
---
# Refund Evaluation Procedure
1. Verify order status and invoice age.
2. Consult `references/refund-matrix.md` for tier-specific credit caps.
3. Request supervisor approval via `issue_refund` for refunds exceeding policy thresholds.Validation Constraints (FrontmatterParser)
name(required):1–64characters matching^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$(lowercase alphanumeric and single hyphens; consecutive--is rejected).description(required): Non-blank, max1024characters.compatibility(optional): Max500characters.allowed-tools(optional): YAML list or space-separated tool names surfaced inload_skillToolResult.details().
Skill Sources & SkillRegistry
SkillRegistry supports three SkillSource implementations with Last-Wins precedence across ordered sources, lock-free snapshot reads, and hot reload (registry.reload()):
| Source | Factory | Typical Use Case |
|---|---|---|
DirectorySkillSource | DirectorySkillSource.of(Path) | Local filesystem skill directories (.skills/, workspace skills). |
ClasspathSkillSource | ClasspathSkillSource.of(resourcePrefix) | Skills packaged inside application JARs (META-INF/skills). |
InMemorySkillSource | InMemorySkillSource.of(rawSkillMd, resources) | Dynamic per-tenant SaaS playbooks stored in a database or config service. |
SkillRegistry registry = SkillRegistry.builder()
.addClasspath("skills/defaults") // Base defaults
.addDirectory(workspaceDir.resolve(".skills")) // Workspace overrides (Last-Wins)
.addInMemory(InMemorySkillSource.of(tenantSopMd, Map.of("references/sla.md", slaMd)))
.strict(false) // Collect errors in loadErrors() instead of throwing
.maxResourceBytes(65_536) // Default 64 KiB cap per resource
.build();SkillToolkit, SkillContextComposer & Sandbox Mounting
Combine SkillContextComposer (systemPromptSupplier), SkillToolkit.tools(registry), and optionally AgentSandbox.mountBundles(...) when exposing skill scripts or files inside an execution sandbox:
// Optional: mount skill files read-only inside an execution sandbox
sandbox.mountBundles(".openhusky/skills", registry.exportAllFiles());
InstructionLoader instructions = InstructionLoader.builder()
.rootDir(repoRoot)
.workingDir(subProjectDir)
.build();
SkillContextComposer promptComposer = SkillContextComposer.builder()
.baseSystemPrompt("You are an enterprise engineering assistant.")
.instructionLoader(instructions)
.skillRegistry(registry)
.build();
List<AgentTool> skillTools = SkillToolkit.builder(registry)
.workspacePathResolver(meta -> ".openhusky/skills/" + meta.name())
.build();
AgentRuntime runtime = AgentRuntime.builder()
.provider(provider)
.model(model)
.systemPromptSupplier(promptComposer)
.tools(skillTools)
.permissionPolicy(PermissionPolicy.failClosed()
.allowReadOnlyTools() // Automatically permits load_skill & read_skill_resource
.build())
.build();Hierarchical AGENTS.md (InstructionLoader)
InstructionLoader walks outer-to-inner from rootDir down to workingDir (plus any explicit globalFiles), combining AGENTS.md files into <project_instructions> inside SkillContextComposer:
- Deduplication: Resolves
toRealPath()on every file so symlinks or overlappingrootDir/workingDirpaths are never loaded twice. - Byte Budgets: Enforces
DEFAULT_MAX_FILE_BYTES = 32 KiBper file andDEFAULT_MAX_TOTAL_BYTES = 64 KiBtotal across all files, truncating cleanly on UTF-8 character boundaries (utf8SafePrefixLength). - Custom Filenames: Override via
.filenames("AGENTS.md", "CLAUDE.md")when supporting multiple repository conventions.
Security Controls
- Path Traversal & Symlink Rejection:
SkillPaths.validateResourceMapKey(...)andDirectorySkillSourcereject..segments, absolute paths, null bytes, and symlinks pointing outside the skill root directory. - Binary File Rejection:
SkillRegistry.readResourceText(...)scans for null bytes and validates strict UTF-8 decoding (CodingErrorAction.REPORT), throwingSkillExceptionon binary payloads. - Zero Code Execution:
openhusky-skillsnever spawns subprocesses or evaluates templates; if a skill includes helper scripts, they are mounted intoopenhusky-sandboxand executed under sandbox andPermissionPolicycontrols.