Skip to content

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

xml
<dependency>
    <groupId>dev.openhusky</groupId>
    <artifactId>openhusky-skills</artifactId>
    <version>0.3.0</version>
</dependency>
kotlin
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:

  1. 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.
  2. Stage 2 — On-Demand Playbook (load_skill): When a task matches a skill's <description>, the model invokes load_skill(name) (readOnly = true, PARALLEL_SAFE), which returns the full SKILL.md body and lists relative bundled resource paths under <skill_resources>.
  3. Stage 3 — Lazy Resource Inspection (read_skill_resource): If the model needs a specific reference table or template, it calls read_skill_resource(skill_name, path) (readOnly = true, PARALLEL_SAFE) to load UTF-8 files up to maxResourceBytes (64 KiB default).

SKILL.md Frontmatter & Directory Layout ​

A skill directory contains a required SKILL.md plus optional relative resources (references/, scripts/, templates/):

text
skills/
└── refund-policy/
    ├── SKILL.md
    └── references/
        └── refund-matrix.md

FrontmatterParser validates SKILL.md frontmatter without SnakeYAML:

markdown
---
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–64 characters matching ^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$ (lowercase alphanumeric and single hyphens; consecutive -- is rejected).
  • description (required): Non-blank, max 1024 characters.
  • compatibility (optional): Max 500 characters.
  • allowed-tools (optional): YAML list or space-separated tool names surfaced in load_skill ToolResult.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()):

SourceFactoryTypical Use Case
DirectorySkillSourceDirectorySkillSource.of(Path)Local filesystem skill directories (.skills/, workspace skills).
ClasspathSkillSourceClasspathSkillSource.of(resourcePrefix)Skills packaged inside application JARs (META-INF/skills).
InMemorySkillSourceInMemorySkillSource.of(rawSkillMd, resources)Dynamic per-tenant SaaS playbooks stored in a database or config service.
java
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:

java
// 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 overlapping rootDir/workingDir paths are never loaded twice.
  • Byte Budgets: Enforces DEFAULT_MAX_FILE_BYTES = 32 KiB per file and DEFAULT_MAX_TOTAL_BYTES = 64 KiB total 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(...) and DirectorySkillSource reject .. 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), throwing SkillException on binary payloads.
  • Zero Code Execution: openhusky-skills never spawns subprocesses or evaluates templates; if a skill includes helper scripts, they are mounted into openhusky-sandbox and executed under sandbox and PermissionPolicy controls.

Released under the MIT License. Built with Java 21 Virtual Threads.