adachsoft/agent-rule

Implementation of the adachsoft/agent-rule-contract library providing JSON-based rule management.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/adachsoft/agent-rule

v0.2.0 2026-02-07 07:37 UTC

This package is not auto-updated.

Last update: 2026-02-07 06:43:08 UTC


README

Implementation of the adachsoft/agent-rule-contract library. This package provides a JSON-based rule provider and a default registry implementation for managing agent rules in the AdachSoft AI ecosystem.

Features

  • JSON Rule Provider: Load rules from local JSON files.
  • Rule Registry: Aggregate global and project-specific rules.
  • Conflict Resolution: Default strategy to resolve rule conflicts based on priority.
  • Public API Builder (read-side): Simple entry point to construct the registry.
  • JSON Rule Writer: Write-side implementation of RuleWriterInterface for JSON files.
  • Public API Builder (write-side): Builder to create a JSON-based rule writer.

Requirements

  • PHP ^8.3
  • adachsoft/agent-rule-contract ^0.2.0

Installation

composer require adachsoft/agent-rule

Usage

Read-side registry

Use the JsonRuleRegistryBuilder to create a registry instance:

use AdachSoft\AgentRule\PublicApi\Builder\JsonRuleRegistryBuilder;

$builder = new JsonRuleRegistryBuilder();
$registry = $builder->fromPaths(
    '/path/to/global_rules.json',
    '/path/to/project_rules.json' // or directory
);

// Get global rules
$globalRules = $registry->getGlobalRules();

// Get effective rules for a project (resolves conflicts)
$projectRules = $registry->resolveEffectiveRules('my-project-id');

Write-side rule management

Use the JsonRuleWriterBuilder to create a writer instance implementing RuleWriterInterface:

use AdachSoft\AgentRule\PublicApi\Builder\JsonRuleWriterBuilder;
use AdachSoft\AgentRuleContract\Dto\RuleDto;
use AdachSoft\AgentRuleContract\Enum\RuleScopeEnum;
use AdachSoft\AgentRuleContract\Enum\RuleTargetEnum;
use AdachSoft\AgentRuleContract\Enum\RuleTypeEnum;

$builder = new JsonRuleWriterBuilder();
$writer = $builder->fromPaths(
    '/path/to/global_rules.json',
    '/path/to/project_rules.json'
);

$rule = new RuleDto(
    id: 'example-rule',
    type: RuleTypeEnum::REQUIREMENT,
    scope: RuleScopeEnum::GLOBAL,
    target: RuleTargetEnum::AGENT,
    content: 'Example content',
    priority: 10,
);

$writer->create($rule);