<?php
require 'examples/boot.php';
use Cognesy\Agents\Builder\AgentBuilder;
use Cognesy\Agents\Capability\Core\UseGuards;
use Cognesy\Agents\Capability\Skills\SkillLibrary;
use Cognesy\Agents\Capability\Skills\SkillPreprocessor;
use Cognesy\Agents\Capability\Skills\UseSkills;
// -- Step 1: Discover skills from the example skills directory -----------
$library = SkillLibrary::inDirectory(__DIR__ . '/skills');
echo "=== All skills ===\n";
echo $library->renderSkillList() . "\n\n";
echo "=== Model-invocable only (excludes disable-model-invocation: true) ===\n";
echo $library->renderSkillList(modelInvocable: true) . "\n\n";
echo "=== User-invocable only ===\n";
echo $library->renderSkillList(userInvocable: true) . "\n\n";
// -- Step 2: Load a skill with argument substitution --------------------
$skill = $library->getSkill('fix-issue');
echo "=== fix-issue skill rendered with arguments ===\n";
echo $skill->render('42') . "\n\n";
$skill = $library->getSkill('code-review');
echo "=== code-review skill rendered with arguments ===\n";
echo $skill->render('src/Auth/LoginController.php') . "\n\n";
// -- Step 3: Shell preprocessing (command substitution) ----------------
$preprocessor = new SkillPreprocessor(timeoutSeconds: 5);
$skill = $library->getSkill('project-context');
echo "=== project-context skill (raw body, before preprocessing) ===\n";
echo $skill->body . "\n\n";
echo "=== project-context skill (after preprocessing + argument substitution) ===\n";
// Preprocessing is automatic when LoadSkillTool has a preprocessor,
// but we can also call it directly for demonstration:
$processedBody = $preprocessor->process($skill->body);
echo $processedBody . "\n\n";
// -- Step 4: Wire skills into an agent ----------------------------------
$agent = AgentBuilder::base()
->withCapability(new UseGuards(maxSteps: 3))
->withCapability(new UseSkills($library, $preprocessor))
->build();
echo "=== Agent built with skills capability ===\n";
echo "Tools registered: " . implode(', ', $agent->tools()->names()) . "\n";
echo "Done.\n";
?>