Skip to content
agents-toolsPublic

About

Swift libraries behind agents and skill: sources, locks, skills, instructions and watch.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

core logo

core

Swift libraries behind agents and skill: sources, locks, skills, instructions and watch.

CI Swift 6.3+ Platforms: macOS 15+ and Linux License: MIT

Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License

Overview

Declare sources and recipients, resolve exact content into a lock, and apply skill and instruction changes through recoverable transactions. Independent watch subscriptions compare upstream changes without changing installations.

Both agents and skill consume this package. Consumers own command parsing, terminal output and executable distribution.

  • AgentsManifest: reads and edits agents.yaml, validates complete symbolic declaration intent and prepares byte-preserving changes. It supplies read-only loadDeclaration() and loadManifest() access and declaration writes for the domain modules.
  • AgentsCore: source parsing and identity, Git requirements, declaration and resolved-state models, atomic state storage, bare mirrors and immutable source materializations, watch subscriptions, hashing, path safety, process execution and agent locations.
  • AgentsSkills: SKILL.md discovery and frontmatter, well-known artifacts, installation, updates, removal, listing, initialization and diagnostics. It depends on AgentsCore, AgentsManifest and Yams.
  • AgentsInstructions: instruction discovery, lifecycle operations, audits, managed Markdown blocks, Claude forwarding and named ChatGPT prompts. It uses AgentsCore for sources, state and transactions, AgentsManifest for the declaration, and swift-markdown for CommonMark structure. Pure text APIs remain available separately.
  • AgentsUpdates: previews and applies the declared configuration in one recoverable transaction. It also exposes source import, component inspection and explicit MCP connection tests to CLI and GUI consumers.

Quick look

In a fresh project with a valid review skill at skills/review/SKILL.md, link the live source for Codex and list the installed skills:

import AgentsCore
import AgentsSkills
import AgentsUpdates

let environment = RuntimeEnvironment()
_ = try SkillOperations.add(AddOptions(
  source: "./skills", agents: [.codex], skillNames: ["review"],
  mode: .edit, environment: environment
))
let installed = try SkillOperations.listInstalled(
  agents: [.codex], environment: environment
)
print(installed.map(\.name).joined(separator: ", ")) // review

Install

Add the package and the products your target uses to Package.swift:

dependencies: [
  .package(url: "https://github.com/agents-tools/core.git", branch: "master")
],
targets: [
  .executableTarget(
    name: "YourCLI",
    dependencies: [
      .product(name: "AgentsManifest", package: "core"),
      .product(name: "AgentsCore", package: "core"),
      .product(name: "AgentsSkills", package: "core"),
      .product(name: "AgentsInstructions", package: "core"),
      .product(name: "AgentsUpdates", package: "core"),
    ]
  )
]

No tagged release is available yet. Use branch: "master" until tagged releases are published, then replace the branch dependency with a tagged release requirement. Pin a reviewed revision when reproducibility is required. Use .package(path: "../core") for local integration.

Usage

State and lifecycle

Project state lives in .agent/agents.yaml, .agent/agents.resolved and .agent/agents.watch. User state uses the same filenames under ~/.agents/. The respective cache/ directory holds scope-owned mirrors and exact materializations needed for restoration. A project commits its agents.yaml declaration and agents.resolved lock; keep agents.watch, cache/, .agents.lock and transaction.json out of version control.

The declaration records source aliases, requirements, skill selections and recipients in the manifest language. Tool writes edit only the changed source ranges and keep comments. The version 2 ledger records the full linked graph, independent pins, resources, ownership and versioned deployments. link points to scope-owned materializations, copy writes a directory, and edit links a live local source with no requirement or pin. Local Git installs in link and copy use committed content.

AgentsCore defines the complete typed declaration and the skill and instruction lock models. loadDeclaration() preserves all component families, conditions and symbolic groups; deployment support is checked by the owning operation. Skill operations use the shared composition layer and preserve recorded other-domain semantics and watch state. Import AgentsUpdates for domain lifecycle methods.

Mutating state operations recover interrupted transactions before proceeding and report CoreError.transactionRecovered when the command should be retried. The durable scope journal covers installations, declaration, lock, watch state and cache pruning. Corrupt watch state stops scope mutations before any replacement. Read-only access, including loadResolved(), loadWatch() and, with import AgentsManifest, loadDeclaration() and loadManifest(), never recovers and reports a pending transaction with CoreError.recoveryPending. A scope with a lock or watch state but no agents.yaml reports CoreError.missingDeclaration.

Acquisition cache

AcquisitionCache(environment:) manages disposable acquisitions across projects. RuntimeEnvironment resolves its location from an explicit cache root, AGENTS_CACHE_DIR, or the provided home's platform cache directory. Call inspect() for per-store bytes and hazards, preview(.clean) or preview(.prune(days:)) to review removals, and apply(_:) for the results of that preview. Prune defaults to 30 days. A removal result reports completed, skipped and failed entries and the bytes actually reclaimed.

Git groups are keyed by the exact anonymous HTTPS transport and commit. Credentialed Git stays in scope-owned storage. Registry GETs honor origin policy and HTTP freshness and validators. Only verified public bytes from a completed deployment can enter the deployed-byte store. Scope-owned lock closure and installed links survive shared-cache cleanup. Call UpdateOperations.restore(environment:offline:) with offline: true to prohibit remote Git reacquisition during restore.

Package source access

Trusted hosts can configure repository credentials, direct egress and enterprise archive routes in RuntimeEnvironment.sourceAccess. Source inspection is status-only by default. Archive pins retain verified private recovery bytes independently of disposable acquisitions. See package source access.

Skills

SkillOperations supplies the consumer workflows:

  • add(_:) resolves a source and saves its selection and installations. An unselected source with several skills returns the available skills for a CLI choice. listOnly and fullDepth support source inspection.
  • updateInstalled(...) previews declared changes. With apply: true, its beforeApply callback receives differences before targets and state change. Unnamed updates reconcile all-member selections; named updates affect only the requested members.
  • installResolvedReport(...) restores the lock's pins, agents and modes. Missing pins and digest mismatches fail the operation.
  • remove(...) changes intent and installations together. Removing an all member records an exclusion; unused materializations are pruned.
  • listManaged(...), listInstalled(...), doctor(...) and initializeSkill(named:directory:) provide inventory, diagnostics and authoring.

Pass RuntimeEnvironment to select the project, home directory and environment. Default recipients for additions are Codex and Claude Code. Supported agents also include Cursor, Gemini CLI, OpenCode and Antigravity. Listing and removal without an agent filter cover every recipient. Update previews include physical removals, entry types and symbolic link destinations. Installed inventory validates skill metadata and excludes missing entries; managed inventory retains those records for diagnosis.

Watch

WatchOperations subscribes to sources independently of installations. Create it with SkillOperations.watchOperations() to use the package's skill discovery and well-known artifact formats. add declares and subscribes a source, status reports commits and new/changed/removed skills and instruction units, and diff provides typed before/after file contents. seen acknowledges the current head or a specified Git revision; remove drops only the subscription and baseline. Git subscriptions follow the declared branch or default branch, even when installations use a version requirement. Well-known subscriptions compare artifact digests and retain seen content for later diffs. Status and diff leave declaration, lock, watch state and installed content unchanged.

Combined updates

UpdateOperations.preview(...) returns the selected configuration under existing shared locks with temporary source acquisition. For application, withPreparedUpdate(...) prepares both kinds and holds the writer lock while the consumer renders update.report and calls update.apply(). Apply commits both kinds, changed state and pruning together. The handle is valid only on its preparing thread inside that synchronous closure and accepts one attempt. Do not re-enter scope operations there.

Skill reports include resolved versions, executable flags, missing-lock status and per-agent managed membership, independent of physical presence. Combined hasChanges also includes state-only updates. UpdateApplyError distinguishes confirmed unchanged, committed and recovery-required outcomes. See combined updates for cancellation, recovery and callback contracts.

Instructions

An instructions file is one Markdown file in a source's instructions/ or .agents/instructions/ container, subdirectories included, named by its path there without .md. It starts with front matter holding a required description and optional paths globs, then a body that begins with one heading. A project's own files live in .agent/instructions/ and are selected by bare name. InstructionOperations generates whole target files from them:

  • add(_:) selects files and writes every target together; source . selects the project's own files. Writing over a file that agents did not generate needs replace.
  • list(source:...) and listOwn(...) inspect available files; listManaged(...) returns locked sections, prompts and physical targets.
  • updateInstalled(...) previews resolutions, target differences and changed ChatGPT prompts. With apply: true, a throwing beforeApply callback can show differences or cancel before files and state change.
  • installResolvedReport(...) restores the locked renderings. remove(...) deletes a target that no longer receives sections while it still equals its locked rendering.
  • renderChatGPT(prompt:...) renders locked sections plus a custom append file. Prompts are declared in an instructions component’s chatgpt mapping.
  • doctor(...) checks missing, drifted and unowned locked targets, changed own files, links, scope duplication, Claude forwarding, Codex overrides and the project size budget, newer matching source revisions and uncommitted sources. Its projectRoots overload audits explicit projects without writing.
  • export(projectRoots:...) reads the user lock and the given projects' locks into a mapping of targets to sections, without writing.
  • initializeInstructions(named:environment:) creates a valid file skeleton in the project's .agent/instructions/.

A combined Markdown target is a notice line followed by the sections in declared order. A section with paths gets a line naming its patterns and, in project scope, is written to the AGENTS.md of the directory the patterns share. Codex, Claude Code, Cursor and OpenCode share project AGENTS.md. Gemini CLI uses GEMINI.md. Claude project files receive only a managed import when forwarding is needed. User locations honor CODEX_HOME, CLAUDE_CONFIG_DIR and XDG_CONFIG_HOME; Codex and Claude use separate files. Codex diagnostics accept effective discovery settings from the consumer, including trusted project configuration overrides.

Claude forwarding recognizes standalone, unquoted and unformatted imports of that project's AGENTS.md outside code and HTML, including managed import blocks. Inline mentions do not suppress the caller's managed import block; a duplicate import is acceptable to ensure the instructions load.

Antigravity installs one native rule per selected instruction section in .agents/rules/ for a project or ~/.gemini/config/rules/ for a user. Project sections with paths become scoped glob rules. The manifest reference lists Antigravity's skill, MCP and hook targets.

See instruction lifecycle for API contracts, target paths, read-only inspection and deletion rules.

Requirements

  • Swift 6.3 or newer, using Swift 6 language mode.
  • macOS 15 or newer, as declared in Package.swift, or Linux with glibc 2.34 or newer, /proc mounted and a filesystem supporting file flock, atomic directory exchange, POSIX ACLs and extended attributes.
  • Linux builds require SQLite 3 headers and library (libsqlite3-dev on Ubuntu).
  • Relocating a project with compressed Codex rollouts requires zstd.
  • Git and tar; ZIP artifacts also require unzip (including zipinfo).
  • Directory permissions, inherited/default ACLs and other filesystem policy must allow the owner to read/write created files and read/write/search created directories. Core does not repair access policy; denied operations stop with the affected path and a permission diagnostic. Correct the environment before retrying.

Documentation

Contributing

Read the organization contributing guide and the maintenance change flow before submitting changes. Run the development checks for the candidate you submit.

Development

The generation commands in .github/swift-package.json run on the last compiler entry's runner, using python3 and the toolchain's swift format. They regenerate into temporary directories and compare committed bytes. swift test checks YAML admission, complete domain round trips, source maps, lossless edits and the existing lifecycle contracts.

Run the package's build, test, generation and formatting checks:

swift build
env -u CODEX_HOME -u CLAUDE_CONFIG_DIR -u XDG_CONFIG_HOME \
  -u XDG_STATE_HOME -u XDG_CACHE_HOME swift test
swift build -c release
python3 Scripts/generate-manifest-schema.py --check
swift format lint --strict --configuration .swift-format \
  --recursive Package.swift Sources Tests

By default, publication tests kill each operation at representative points, and kill recovery at durable steps from each seeded interruption. When changing the transaction protocol, also kill at every recorded point:

env -u CODEX_HOME -u CLAUDE_CONFIG_DIR -u XDG_CONFIG_HOME \
  -u XDG_STATE_HOME -u XDG_CACHE_HOME AGENTS_PUBLICATION_MATRIX=full \
  swift test --filter PublicationTests

The required checks are policy / policy and validate / result, provided by full-SHA-pinned reusable workflows from agents-tools/github-workflows. Source policy validates PR titles, new commit messages and added lines. Package validation configuration selects Xcode 26.6 on macos-26 and a digest-pinned official Swift Linux container. macOS and Linux validation run the Debug and Release test suites with the default publication matrix; the full publication matrix is not part of CI. macOS also runs a release build and strict formatting with .swift-format over Package.swift, Sources and Tests. The test suites include subprocess recovery tests. The configuration owns the Linux compiler version and image digest. The suites run serially so other test cases cannot starve subprocess deadlines. Linux uses the checkout owner to exercise kernel permission checks, with Python 3 for the loopback HTTP fixture and Perl through Git.

Render and check the committed social preview locally with the github-readme-design toolchain against agents-tools/.github's DESIGN, fonts and catalog, using this repository's framework logo. Follow the local renderer commands and repository inputs, then commit the resulting assets.

All workflows run on branch pushes and PRs; only source policy reruns on PR title edits. They also support manual dispatch; source policy validates the selected ref's head commit. See the shared workflow reference for configuration and callers.

License

core is available under the MIT License.

About

Swift libraries behind agents and skill: sources, locks, skills, instructions and watch.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages