diff --git a/AGENTS.md b/AGENTS.md index b0d0a0a..fe1f517 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -61,7 +61,16 @@ ln -s $(pwd)/skills/ ~/.claude/skills/-test - Use for: Quick project-specific commands (test, deploy, rebuild) - Example: This repo has `/speckit.*` commands in `.opencode/command/` -**Deployment tool**: `./bin/deploy-skill.sh ` (copies to dotfiles, shows Nix config) +**Deployment tool**: `./bin/deploy-skill.sh ` +- Copies skill to dotfiles +- Automatically injects configuration into `home/claude.nix` and `home/opencode.nix` +- Checks for `home/antigravity.nix` and injects global binary configuration if present + +**Antigravity Support (Global Binaries)**: +- Antigravity does not auto-load skills like Claude/OpenCode. +- Instead, we deploy skill scripts to `~/.local/bin/` via Nix. +- This makes them available as global commands (e.g., `web-search "query"`). +- Configuration lives in `home/antigravity.nix` (or similar) in dotfiles. **Note on Agents**: OpenCode agents (Build/Plan/custom) use Tab to switch. Agents are modes/personalities, not skills. Skills work with all agents. Per-agent skill filtering not supported. @@ -70,4 +79,5 @@ ln -s $(pwd)/skills/ ~/.claude/skills/-test - Filesystem - modifies `~/proj/dotfiles/pkgs/opencode/default.nix` (002-update-opencode) ## Recent Changes +- 003-web-search: Added `web-search` skill and automated deployment injection for Claude, OpenCode, and Antigravity. - 002-update-opencode: Added Bash (no specific version requirement - standard POSIX + bash extensions) + `jq`, `curl`, `nix-prefetch-url`, `sed`/`awk`, GitHub API diff --git a/RFC-AI-AGENT-EXTENSIBILITY-PATTERNS.md b/RFC-AI-AGENT-EXTENSIBILITY-PATTERNS.md new file mode 100644 index 0000000..6394d32 --- /dev/null +++ b/RFC-AI-AGENT-EXTENSIBILITY-PATTERNS.md @@ -0,0 +1,487 @@ +# RFC: AI Agent Extensibility Patterns + +**Status:** Draft +**Author:** Dan (with Claude Code assistance) +**Date:** 2025-11-09 +**Version:** 0.1.0 + +## Abstract + +This RFC defines the standard patterns for extending AI coding agents (Claude Code, OpenCode, Cursor, etc.) across our organization. It establishes when to use Skills, Commands, Tools, and MCP servers, with examples from our current implementations. + +## Motivation + +As we build AI-assisted workflows, we need clear guidelines on: +- When to use which extension mechanism +- How to maintain consistency across repos +- How to share capabilities between agents +- How to balance simplicity with power + +**Current state:** Ad-hoc decisions leading to inconsistent patterns. +**Desired state:** Clear, documented standards that make the right choice obvious. + +--- + +## Extension Mechanisms + +### 1. Skills (SKILL.md format) + +**What:** Markdown files with YAML frontmatter containing detailed instructions for multi-step workflows. + +**When to use:** +- ✅ Multi-step processes (5+ steps) +- ✅ Workflows requiring domain knowledge +- ✅ Processes with bundled resources (scripts, templates, docs) +- ✅ Tasks that benefit from progressive disclosure +- ✅ Cross-agent compatibility is desired + +**When NOT to use:** +- ❌ Simple one-off commands +- ❌ Programmatic operations needing code execution +- ❌ Real-time data fetching + +**Structure:** +``` +skill-name/ +├── SKILL.md # Required: Instructions with YAML frontmatter +├── scripts/ # Optional: Helper scripts +├── references/ # Optional: Supporting documentation +└── assets/ # Optional: Templates, configs +``` + +**Example frontmatter:** +```yaml +--- +name: worklog +description: Create comprehensive structured org-mode worklogs documenting work sessions in docs/worklogs/. Use when the user explicitly asks to document work, create/write a worklog, log the session, or record what was accomplished. +--- +``` + +**Current implementations:** +- `worklog` - Creates structured org-mode documentation +- `niri-window-capture` - Invisibly captures window screenshots + +**Requested from skills team:** +- `update-opencode` - Updates OpenCode version via Nix (see Examples section) + +**Deployment:** +- **Claude Code:** Native support via `.claude/skills/` +- **OpenCode:** Via `opencode-skills` plugin (1.0.44 compatible) +- **Universal:** Via `openskills` CLI tool for all agents + +### 2. Slash Commands + +**What:** Short markdown files that trigger predefined prompts/workflows. + +**When to use:** +- ✅ Quick shortcuts (1-3 steps) +- ✅ Common repeated tasks +- ✅ Simple prompt templates +- ✅ OpenCode-specific workflows + +**When NOT to use:** +- ❌ Complex multi-step processes (use Skills) +- ❌ Need bundled resources (use Skills) +- ❌ Cross-agent compatibility required + +**Structure:** +```markdown +--- +description: Run tests with coverage and suggest fixes +agent: build +--- + +Run the full test suite with coverage report and show any failures. + +!`nix flake check 2>&1 || true` + +Focus on the failing tests and suggest fixes. If tests pass, provide a brief summary. +``` + +**Location:** `.opencode/command/*.md` + +**Current implementations:** +- `/test` - Runs test suite with coverage +- `/rebuild` - Rebuilds NixOS configuration + +**Deployment:** +- **OpenCode:** Native support +- **Other agents:** Not supported (use Skills instead) + +### 3. Custom Tools (Plugin API) + +**What:** TypeScript/JavaScript code that extends agent capabilities programmatically. + +**When to use:** +- ✅ Programmatic operations (parsing, transformation) +- ✅ Need to maintain state +- ✅ Complex logic that's hard to express as instructions +- ✅ Agent-specific integrations + +**When NOT to use:** +- ❌ Simple workflows (use Skills/Commands) +- ❌ Static instructions (use Skills) +- ❌ Cross-agent compatibility required + +**Structure:** +```typescript +// .opencode/tool/my-tool.ts +import { tool } from "@opencode-ai/plugin"; + +export default tool({ + name: "my_tool", + description: "What this tool does", + parameters: z.object({ + param: z.string(), + }), + execute: async ({ param }) => { + // Implementation + return result; + }, +}); +``` + +**Current implementations:** +- None yet in our org + +**Deployment:** +- **OpenCode:** Native plugin API +- **Other agents:** Not portable + +### 4. MCP Servers (Model Context Protocol) + +**What:** External services that provide dynamic data/tools via standardized protocol. + +**When to use:** +- ✅ Database connections +- ✅ External API integrations +- ✅ Real-time data fetching +- ✅ Service-to-agent communication +- ✅ Need authentication/secrets management + +**When NOT to use:** +- ❌ Static workflows (use Skills) +- ❌ Simple prompts (use Commands) +- ❌ Don't need external services + +**Current implementations:** +- None yet in our org + +**Deployment:** +- **Claude Code:** Native MCP support +- **OpenCode:** Emerging MCP support +- **Other agents:** Varies + +--- + +## Decision Framework + +Use this flowchart to decide which pattern to use: + +``` +Is it a workflow with instructions? +├─ Yes: Is it complex (5+ steps) or needs bundled resources? +│ ├─ Yes: Use SKILL.md +│ └─ No: Is it OpenCode-specific? +│ ├─ Yes: Use slash command +│ └─ No: Use SKILL.md for portability +│ +└─ No: Does it need programmatic logic? + ├─ Yes: Does it need external services/data? + │ ├─ Yes: Use MCP Server + │ └─ No: Use Custom Tool (if agent-specific) or bash script + │ + └─ No: Reconsider if it should be a Skill +``` + +**Examples:** + +| Task | Pattern | Reason | +|------|---------|--------| +| Update OpenCode version | Skill | Multi-step workflow, can bundle helper scripts | +| Run tests | Command | Quick shortcut, OpenCode-specific | +| Create worklog | Skill | Complex workflow, bundled templates | +| Capture window | Skill | Multi-step, bundled scripts, cross-agent | +| Parse config file | Tool | Programmatic logic | +| Fetch live data | MCP | External service, real-time | + +--- + +## Implementation Guidelines + +### Skills + +**Naming:** +- Lowercase with hyphens: `update-opencode`, `worklog`, `niri-window-capture` +- Directory name must match frontmatter `name` field + +**Description requirements:** +- Minimum 20 characters (for LLM discoverability) +- Include when to use: "Use when user asks to X" +- Be specific about capabilities + +**Instructions format:** +- Use imperative mood ("Read the file", not "You should read") +- Number multi-step processes +- Reference bundled resources with relative paths +- Include base directory context for agent + +**Progressive disclosure:** +- Keep descriptions concise (for `` list) +- Put detailed instructions in SKILL.md body +- Only load full content when skill is invoked + +### Commands + +**Keep them simple:** +- 1-3 steps maximum +- Use `!` for bash command execution +- Specify agent type in frontmatter if specialized + +### Deployment Strategy + +**For dotfiles repo (NixOS system):** +```nix +# home/opencode.nix or home/claude.nix +home.file.".config/opencode/skills/skill-name" = { + source = ../claude/skills/skill-name; + recursive = true; +}; +``` + +**For project repos:** +- Commit to `.claude/skills/` or `.opencode/skills/` +- Reference in AGENTS.md for universal agents +- Use `openskills` for cross-agent compatibility + +**For shared/org-wide skills:** +- Maintain in `~/proj/skills` repo +- Deploy via Nix modules or git submodules +- Document in DEPLOYED.md + +--- + +## Security Considerations + +**Skills can execute arbitrary code** via bash commands and bundled scripts: + +1. **Review all scripts** in `scripts/` before deployment +2. **Document security implications** in SECURITY.md (see `niri-window-capture`) +3. **Log security-sensitive operations** (e.g., to systemd journal) +4. **Use principle of least privilege** in bundled scripts +5. **Never commit secrets** in skill files + +**For security-sensitive skills:** +```markdown +# skill-name/SECURITY.md + +⚠️ **SECURITY NOTICE**: This skill can [describe capability]. + +## Threat Model +- [What can go wrong] +- [Who might exploit it] + +## Mitigations +- [How we limit risk] +- [Logging/auditing] + +## Deployment Considerations +- [Production vs development] +``` + +--- + +## Maintenance & Versioning + +**Skills should include:** +- Version in directory structure: `skill-name-v1/` +- Changelog in README.md +- Dependencies in frontmatter (if needed) + +**When updating:** +1. Test in development environment +2. Update version documentation +3. Commit with clear description of changes +4. Deploy via Nix rebuild or skill manager + +**Deprecation:** +1. Mark as deprecated in description +2. Keep for 30 days minimum +3. Create migration guide if replacement exists +4. Remove after deprecation period + +--- + +## Examples from Our Org + +### Worklog Skill (Complex Workflow) + +**Pattern:** Skill +**Reason:** Multi-step documentation process with templates + +```markdown +--- +name: worklog +description: Create comprehensive structured org-mode worklogs documenting work sessions in docs/worklogs/. Use when the user explicitly asks to document work, create/write a worklog, log the session, or record what was accomplished. +--- + +# Worklog Skill + +## When to Use +- "Document today's work" +- "Create a worklog" +- "Record this session" + +## Context Gathering +1. Check git status: `git status` +2. Get recent commits: `git log --oneline -10` +3. Review uncommitted changes: `git diff --stat` + +## Document Creation +[Detailed steps using templates/...] +``` + +### Niri Window Capture (Tool + Workflow) + +**Pattern:** Skill with bundled scripts +**Reason:** Complex setup, security considerations, reusable scripts + +``` +niri-window-capture/ +├── SKILL.md # Instructions +├── SECURITY.md # Threat model and mitigations +├── scripts/ +│ ├── capture-focused.sh +│ ├── capture-by-title.sh +│ └── capture-all-windows.sh +└── examples/ + └── usage-example.sh +``` + +### Update OpenCode (Requested from Skills Team) + +**Pattern:** Skill +**Reason:** Multi-step Nix workflow, could bundle helper scripts +**Status:** 🔴 Needs implementation by skills team + +**Use Case:** Operations team needs to check for and apply OpenCode updates without manually editing Nix files and fetching SHA256 hashes. + +**Proposed structure:** +``` +update-opencode/ +├── SKILL.md # Instructions for checking/updating +├── scripts/ +│ ├── check-version.sh # Compare current vs latest +│ └── fetch-sha256.sh # Get SHA256 for new version +└── references/ + └── nix-package-format.md # Example Nix package structure +``` + +**Key requirements:** +1. Check current OpenCode version from `pkgs/opencode/default.nix` +2. Query GitHub API for latest release +3. If newer version available: + - Fetch SHA256 hash for new release + - Update version and hash in Nix file + - Trigger system rebuild + - Verify successful update +4. Handle errors gracefully (network issues, invalid releases, etc.) + +**Expected workflow:** +```markdown +User: "Update OpenCode to the latest version" +Agent: [Invokes skills_update_opencode] + 1. Current: 1.0.44 + 2. Latest: 1.0.51 + 3. Fetching SHA256... + 4. Updating pkgs/opencode/default.nix + 5. Rebuilding system... + 6. ✓ Updated to 1.0.51 +``` + +**Related:** +- Dotfiles repo: `/home/dan/proj/dotfiles/pkgs/opencode/default.nix` +- Current manual process documented in dotfiles repo +- Should work with pinned versions (currently pinned to 1.0.44 for plugin compatibility) + +--- + +## Migration Path + +### Phase 1: Document Current State (This RFC) +- ✅ Identify existing patterns +- ✅ Document decision framework +- ✅ Establish guidelines + +### Phase 2: Standardize Existing Skills +- Audit current skills for compliance +- Add missing SECURITY.md where needed +- Standardize naming and structure + +### Phase 3: Tooling & Automation +- Create skill template generator +- Add linting for skill structure +- Automate deployment testing + +### Phase 4: Expand +- Build out shared skill library +- Create org-wide skill registry +- Document best practices from experience + +--- + +## Open Questions + +1. **Skill versioning:** Should we version skills or use git tags? +2. **Testing:** How do we test skills before deployment? +3. **Discovery:** How do users find available skills across repos? +4. **Conflicts:** What happens when multiple repos define same skill name? +5. **Performance:** Impact of many skills on agent context/startup time? + +--- + +## References + +- [Anthropic Agent Skills Specification](https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills) +- [Anthropic Skills Repository](https://github.com/anthropics/skills) +- [OpenCode Documentation](https://opencode.ai/docs) +- [Model Context Protocol Specification](https://modelcontextprotocol.io) + +--- + +## Appendix: Current Tool Inventory + +### Dotfiles Repo +- **Skills:** + - `worklog` - Structured documentation creation + - `niri-window-capture` - Window screenshot capture +- **Commands:** + - `/test` - Run test suite + - `/rebuild` - System rebuild +- **Plugins:** + - `opencode-skills@0.1.0` - Skill loader (OpenCode 1.0.44 compatible) + +### Skills Repo +- **Requested Skills (for team to implement):** + - `update-opencode` - Check and apply OpenCode updates in dotfiles Nix setup +- **In Development:** + - Various project-specific skills + +--- + +## Approval Process + +**Review Period:** 1 week +**Feedback Channel:** GitHub issues or comments in this file +**Final Approval:** Team consensus + +**Reviewers:** +- [ ] Technical lead +- [ ] Operations team +- [ ] Development team + +--- + +## Changelog + +- **2025-11-09:** Initial draft based on dotfiles experience and research diff --git a/bin/deploy-skill.sh b/bin/deploy-skill.sh index 73a223a..27f70cf 100755 --- a/bin/deploy-skill.sh +++ b/bin/deploy-skill.sh @@ -108,33 +108,91 @@ if [[ -n "$SECURITY_WARNING" ]]; then echo "$SECURITY_WARNING" fi -echo "Next steps:" +# Function to inject config into Nix file +inject_nix_config() { + local target_file="$1" + local config_block="$2" + local marker="$3" # Unique string to check if already deployed + + if [[ ! -f "$target_file" ]]; then + echo "⚠️ File not found: $target_file (skipping)" + return + fi + + if grep -q "$marker" "$target_file"; then + echo "ℹ️ Config already present in $(basename "$target_file")" + else + echo "Injecting config into $(basename "$target_file")..." + # Create backup + cp "$target_file" "${target_file}.bak" + + # Insert before the last line (assuming it is '}') + # We use a temporary file to construct the new content + head -n -1 "$target_file" > "${target_file}.tmp" + echo "$config_block" >> "${target_file}.tmp" + tail -n 1 "$target_file" >> "${target_file}.tmp" + mv "${target_file}.tmp" "$target_file" + echo "✓ Updated $(basename "$target_file")" + fi +} + +echo "Configuring system..." echo "" -echo "1. Add to Claude Code (edit $DOTFILES_REPO/home/claude.nix):" + +# 1. Claude Code Config +CLAUDE_CONFIG=" + # Skill: $SKILL_NAME + home.file.\".claude/skills/$SKILL_NAME\" = { + source = ../claude/skills/$SKILL_NAME; + recursive = true; + };" +inject_nix_config "$DOTFILES_REPO/home/claude.nix" "$CLAUDE_CONFIG" ".claude/skills/$SKILL_NAME" + +# 2. OpenCode Config +OPENCODE_CONFIG=" + # Skill: $SKILL_NAME + home.file.\".config/opencode/skills/$SKILL_NAME\" = { + source = ../claude/skills/$SKILL_NAME; + recursive = true; + };" +inject_nix_config "$DOTFILES_REPO/home/opencode.nix" "$OPENCODE_CONFIG" ".config/opencode/skills/$SKILL_NAME" + +# 3. Antigravity / Global Config +# Check if antigravity.nix exists, otherwise warn +ANTIGRAVITY_NIX="$DOTFILES_REPO/home/antigravity.nix" +if [[ -f "$ANTIGRAVITY_NIX" ]]; then + # For global scripts, we need to find executable scripts in the skill + SCRIPTS=$(find "$SKILL_SOURCE/scripts" -name "*.sh" -type f) + + if [[ -n "$SCRIPTS" ]]; then + GLOBAL_CONFIG="" + for script in $SCRIPTS; do + SCRIPT_NAME=$(basename "$script") + SCRIPT_NO_EXT="${SCRIPT_NAME%.*}" + # If skill has only one script and it matches skill name or is 'search', use skill name + # Otherwise use script name + LINK_NAME="$SCRIPT_NO_EXT" + + GLOBAL_CONFIG="$GLOBAL_CONFIG + # Skill: $SKILL_NAME ($SCRIPT_NAME) + home.file.\".local/bin/$LINK_NAME\" = { + source = ../claude/skills/$SKILL_NAME/scripts/$SCRIPT_NAME; + executable = true; + };" + done + + inject_nix_config "$ANTIGRAVITY_NIX" "$GLOBAL_CONFIG" ".local/bin/$LINK_NAME" + fi +else + echo "⚠️ $ANTIGRAVITY_NIX not found. Skipping global binary configuration." + echo " To enable global binaries, create home/antigravity.nix and add it to your flake." +fi + echo "" -echo " home.file.\".claude/skills/$SKILL_NAME\" = {" -echo " source = ../claude/skills/$SKILL_NAME;" -echo " recursive = true;" -echo " };" -echo "" -echo "2. Add to OpenCode (edit $DOTFILES_REPO/home/opencode.nix):" -echo "" -echo " home.file.\".config/opencode/skills/$SKILL_NAME\" = {" -echo " source = ../claude/skills/$SKILL_NAME;" -echo " recursive = true;" -echo " };" -echo "" -echo "3. Rebuild system:" +echo "Deployment configured." +echo "Run the following to apply changes:" echo "" echo " cd $DOTFILES_REPO" echo " sudo nixos-rebuild switch --flake .#delpad" echo "" -echo "4. Restart AI agents (OpenCode and Claude Code)" -echo "" - -if [[ -n "$SECURITY_WARNING" ]]; then - echo "⚠️ REMEMBER: Review SECURITY.md before rebuilding!" - echo "" -fi - -echo "Skill deployment prepared. Complete steps 1-4 to activate." +echo "Then restart your agents." diff --git a/docs/worklogs/2025-11-22-create-web-research-skill.org b/docs/worklogs/2025-11-22-create-web-research-skill.org new file mode 100644 index 0000000..313dfb8 --- /dev/null +++ b/docs/worklogs/2025-11-22-create-web-research-skill.org @@ -0,0 +1,83 @@ +#+TITLE: Create Web Research Skill and Automate Deployment +#+DATE: 2025-11-22 +#+KEYWORDS: web-research, kagi, sops-nix, automation, claude-code, skills +#+COMMITS: 0 (pending) +#+COMPRESSION_STATUS: uncompressed + +* Session Summary +** Date: 2025-11-22 +** Focus Area: Creating advanced web research capabilities and automating skill deployment. + +* Accomplishments +- [X] Created `web-search` skill for quick information retrieval. +- [X] Automated skill deployment in `bin/deploy-skill.sh` (injects config into Nix files). +- [X] Added Antigravity/Global support to deployment script. +- [X] Created `web-research` skill for deep, synthesized research reports. +- [X] Implemented Multi-Backend support for `web-research` (`claude`, `llm`, `kagi`). +- [X] Integrated `sops-nix` for secure Kagi API key management. +- [X] Verified all backends and deployment automation. + +* Key Decisions +** Decision 1: Hybrid Backend for LLM +- Context: `llm` CLI tool does not have built-in web search plugins installed. +- Options considered: + 1. Install new plugins (risk of environment issues). + 2. Use `curl` + `llm` (limited scraping capability). + 3. Hybrid: Use `claude` to fetch context, `llm` to synthesize. +- Rationale: Leverages Claude's robust tool access for retrieval while allowing `llm` to use any model for synthesis. +- Impact: Flexible backend that works with existing tools. + +** Decision 2: Sops-Nix for Kagi Key +- Context: Kagi API key is sensitive and shouldn't be in plain text env vars permanently. +- Options considered: + 1. Manual `export KAGI_API_KEY`. + 2. Hardcoded in script (insecure). + 3. `sops-nix` secret file. +- Rationale: Aligns with existing infrastructure (`dotfiles` uses sops). +- Impact: Secure, persistent configuration via Nix. + +* Problems & Solutions +| Problem | Solution | Learning | +|---------|----------|----------| +| `web_search` param deprecated in Kagi FastGPT | Removed parameter, relied on default behavior | APIs change; always check current docs. | +| `llm` backend verification hung | Increased timeout/patience (it was just slow) | Deep research takes time; progress indicators help. | +| `sudo` restriction for rebuild | Asked user to run rebuild manually | Agent limitations require human-in-the-loop for root ops. | + +* Technical Details + +** Code Changes +- Total files modified: ~10 +- Key files changed: + - `bin/deploy-skill.sh`: Added `inject_nix_config` function. + - `skills/web-research/scripts/research.sh`: Main logic with backend switching. + - `skills/web-research/SKILL.md`: Documentation. + - `AGENTS.md`: Updated with new workflow. + +** Commands Used +```bash +# Deploy skill +./bin/deploy-skill.sh web-research + +# Run research with Kagi backend +RESEARCH_BACKEND=kagi ./skills/web-research/scripts/research.sh "topic" +``` + +* Process and Workflow + +** What Worked Well +- **Iterative Development**: Started with `web-search`, then `web-research`, then backends. +- **Verification**: Testing each backend (Claude, LLM, Kagi) ensured robustness. + +** What Was Challenging +- **Environment Restrictions**: Unable to run `sudo` or install global packages (`googler`), forcing creative solutions (Hybrid backend). + +* Context for Future Work + +** Next Steps +- Explore `playwright-skill` as a standalone skill for browser automation. +- Add more backends if needed (e.g., Perplexity). + +* Session Metrics +- Commits made: 0 (pending) +- Files touched: 69 (scanned) +- Lines added: +13012 (mostly new skill files + logs) diff --git a/docs/worklogs/2025-11-22-create-web-search-skill.org b/docs/worklogs/2025-11-22-create-web-search-skill.org new file mode 100644 index 0000000..a4f66c2 --- /dev/null +++ b/docs/worklogs/2025-11-22-create-web-search-skill.org @@ -0,0 +1,70 @@ +#+TITLE: Create Web Search Skill +#+DATE: 2025-11-22 +#+KEYWORDS: web-search, claude-code, antigravity, skills, bash +#+COMMITS: 0 +#+COMPRESSION_STATUS: uncompressed + +* Session Summary +** Date: 2025-11-22 +** Focus Area: Implementing a web search capability for Claude Code and Antigravity agents. + +* Accomplishments +- [X] Explored the `skills` repository structure and documentation (`AGENTS.md`, `RFC-AI-AGENT-EXTENSIBILITY-PATTERNS.md`). +- [X] Confirmed that Antigravity is not natively supported but can utilize skills via their underlying Bash scripts. +- [X] Implemented the `web-search` skill based on requirements from `claude-code-web-search.md`. + - Created `skills/web-search/SKILL.md` documentation. + - Created `skills/web-search/scripts/search.sh` helper script. +- [X] Verified the skill functionality by successfully querying "current time in Tokyo" and "latest stable version of python". + +* Key Decisions +** Decision 1: Implement as a Standard Skill +- Context: We needed a way to search the web using Claude Code's subprocess capability. +- Rationale: Following the existing pattern in the `skills` repo ensures compatibility and reusability. +- Impact: The skill is available for Claude Code (via native loading) and Antigravity (via manual script execution). + +** Decision 2: Use `claude -p` with `--allowedTools` +- Context: Standard `webfetch` only gets static HTML. +- Rationale: The `--allowedTools "web_search,WebSearch,mcp__*"` flag explicitly grants the subprocess permission to use the search tool, which is otherwise restricted. +- Impact: Enables dynamic web searching including "Product Investigation" and "Nix Package Discovery" workflows. + +* Technical Details + +** Code Changes +- New files created: + - `skills/web-search/SKILL.md`: Defines the skill interface and usage. + - `skills/web-search/scripts/search.sh`: Bash wrapper for the `claude` CLI. + +** Commands Used +```bash +# The core command implemented in the script +claude -p "Search the web for '$QUERY'. Provide a summary of findings." \ + --allowedTools "web_search,WebSearch,mcp__*" + +# Verification +./skills/web-search/scripts/search.sh "current time in Tokyo" +``` + +* Process and Workflow + +** What Worked Well +- The `skills` repo structure is clear and easy to extend. +- Using `claude -p` as a bridge to web search is a powerful pattern. + +** What Was Challenging +- Antigravity does not automatically discover these skills, requiring manual script invocation or future tooling (symlinks/workflows). + +* Context for Future Work + +** Open Questions +- How best to expose these skills to Antigravity globally? + - Option 1: Global Binaries (symlinks to `~/.local/bin`). + - Option 2: Antigravity Workflows (`.agent/workflows/`). + - We are leaning towards a hybrid approach (Global Binaries + Local Workflow stubs). + +** Next Steps +- Decide on the global exposure strategy. +- Commit the new skill to the repository. + +* Session Metrics +- Commits made: 0 (Work in progress) +- Files touched: Created `skills/web-search/` diff --git a/skills/web-research/SKILL.md b/skills/web-research/SKILL.md new file mode 100644 index 0000000..65a5345 --- /dev/null +++ b/skills/web-research/SKILL.md @@ -0,0 +1,51 @@ +--- +name: web-research +description: Conduct deep web research to gather insights, determine best practices, and discover new developments. Produces structured reports. +--- + +# Web Research + +Conduct deep, comprehensive web research on a topic. This skill acts as a "Lead Researcher," synthesizing information from multiple sources to provide insights, best practices, and trend analysis. + +## When to Use + +- "Research [topic]" +- "What are the best practices for [technology]?" +- "Gather insights on [subject]" +- "What's new in [field]?" +- "Compare [option A] and [option B]" + +## Process + +1. Identify the research topic from the user's request. +2. Run the helper script with the topic. + +## Helper Scripts + +### research.sh + +**Usage**: +```bash +./scripts/research.sh "your research topic" +``` + +**Backends**: +You can choose the synthesis backend using the `RESEARCH_BACKEND` environment variable. +- `claude` (default): Uses Claude for both search and synthesis. +- `llm`: Uses Claude for search, but pipes results to the `llm` CLI for synthesis. +- `kagi`: Uses Kagi's FastGPT API (requires `KAGI_API_KEY` or `/run/secrets/api_keys/kagi`). + +**Example**: +```bash +# Default (Claude) +./scripts/research.sh "current best practices for React state management in 2025" + +# Use LLM backend +RESEARCH_BACKEND=llm ./scripts/research.sh "current best practices for React state management in 2025" +``` + +## Requirements + +- `claude` CLI tool must be installed and in the PATH. +- `llm` CLI tool (optional) for using the `llm` backend. +- `KAGI_API_KEY` environment variable OR `/run/secrets/api_keys/kagi` (for `kagi` backend). diff --git a/skills/web-research/scripts/research.sh b/skills/web-research/scripts/research.sh new file mode 100755 index 0000000..c378374 --- /dev/null +++ b/skills/web-research/scripts/research.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +set -euo pipefail + +TOPIC="$*" +if [ -z "$TOPIC" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Default to claude backend, but allow override via env var +BACKEND="${RESEARCH_BACKEND:-claude}" + +# Specialized prompt for research +PROMPT="You are a Lead Researcher. Conduct a comprehensive investigation into '$TOPIC'. + +Your goal is to provide a deep, synthesized report, not just a list of links. + +Focus on: +1. **Key Insights**: What are the most important takeaways? +2. **Best Practices**: What is the current consensus or recommended approach? +3. **Emerging Trends**: What is new or changing in this field? +4. **Concrete Examples**: Provide real-world usage or code snippets where applicable. + +Use the web search tool multiple times if necessary to get a complete picture. Cross-reference sources to ensure accuracy. + +Output the result as a structured Markdown report with clear headings." + +if [[ "$BACKEND" == "claude" ]]; then + # Use claude -p with allowedTools to enable web search + claude -p "$PROMPT" \ + --allowedTools "web_search,WebSearch,mcp__*" + +elif [[ "$BACKEND" == "llm" ]]; then + # Hybrid approach: Use Claude to fetch context, LLM to synthesize + echo "Using hybrid backend: Claude (Search) -> LLM (Synthesis)..." >&2 + + SEARCH_PROMPT="Search the web for '$TOPIC'. + Collect comprehensive information, including key insights, best practices, and examples. + Do NOT summarize yet. Just dump the raw findings, facts, and excerpts from the search results. + I will pass your output to another agent for synthesis." + + # 1. Fetch Context + CONTEXT=$(claude -p "$SEARCH_PROMPT" --allowedTools "web_search,WebSearch,mcp__*") + + # 2. Synthesize with LLM + # We pipe the context + original instructions to llm + echo "$CONTEXT" | llm -s "$PROMPT" + +elif [[ "$BACKEND" == "kagi" ]]; then + # Kagi FastGPT backend + + # Check for API key in env var, then sops secret file + if [ -z "${KAGI_API_KEY:-}" ]; then + if [ -r "/run/secrets/api_keys/kagi" ]; then + KAGI_API_KEY=$(cat /run/secrets/api_keys/kagi) + else + echo "Error: KAGI_API_KEY environment variable is required for 'kagi' backend." >&2 + echo " OR ensure /run/secrets/api_keys/kagi exists and is readable." >&2 + exit 1 + fi + fi + + echo "Using backend: Kagi FastGPT..." >&2 + + # Call Kagi FastGPT API + RESPONSE=$(curl -s -X POST "https://kagi.com/api/v0/fastgpt" \ + -H "Authorization: Bot $KAGI_API_KEY" \ + -H "Content-Type: application/json" \ + --data "{\"query\": \"$TOPIC\"}") + + # Check for errors in response + if echo "$RESPONSE" | grep -q '"error"'; then + ERROR_MSG=$(echo "$RESPONSE" | jq -r '.error[0].msg // .error') + echo "Error from Kagi API: $ERROR_MSG" >&2 + exit 1 + fi + + # Extract and print the answer + # The API returns: {"data": {"output": "The answer...", ...}} + echo "$RESPONSE" | jq -r '.data.output' + +else + echo "Error: Unknown backend '$BACKEND'. Supported: claude, llm, kagi" >&2 + exit 1 +fi diff --git a/skills/web-search/SKILL.md b/skills/web-search/SKILL.md new file mode 100644 index 0000000..9fe9207 --- /dev/null +++ b/skills/web-search/SKILL.md @@ -0,0 +1,39 @@ +--- +name: web-search +description: Search the web for information, documentation, or troubleshooting help using Claude Code's subprocess capability. +--- + +# Web Search + +Perform a web search to answer questions, find documentation, or troubleshoot issues. This skill wraps `claude -p` with the necessary permissions to access the web. + +## When to Use + +- "Search the web for [topic]" +- "Find documentation for [library]" +- "Troubleshoot [error message]" +- "Check if [package] is available on Nix" +- "What is [product]?" + +## Process + +1. Identify the search query from the user's request. +2. Run the helper script with the query. + +## Helper Scripts + +### search.sh + +**Usage**: +```bash +./scripts/search.sh "your search query" +``` + +**Example**: +```bash +./scripts/search.sh "how to install ripgrep on nixos" +``` + +## Requirements + +- `claude` CLI tool must be installed and in the PATH. diff --git a/skills/web-search/scripts/search.sh b/skills/web-search/scripts/search.sh new file mode 100755 index 0000000..fac63b3 --- /dev/null +++ b/skills/web-search/scripts/search.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +QUERY="$*" +if [ -z "$QUERY" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Use claude -p (print/subprocess mode) with allowedTools to enable web search +# The tools list includes web_search (standard), WebSearch (alternative), and mcp__* (all MCP tools) +claude -p "Search the web for '$QUERY'. Provide a summary of findings." \ + --allowedTools "web_search,WebSearch,mcp__*" diff --git a/web_search_brainstorm.md b/web_search_brainstorm.md new file mode 100644 index 0000000..7faa591 --- /dev/null +++ b/web_search_brainstorm.md @@ -0,0 +1,53 @@ +# Brainstorming: Advanced Web Search Skill + +## Objective +Create a versatile web search skill that supports multiple search modes, providers, and use cases. + +## Potential Search Modes + +### 1. General Search +- **Goal**: Find general information, answers to questions. +- **Tools**: `claude -p` (existing), `googler`, `ddgr`. +- **Features**: Summaries, top N results. + +### 2. Documentation Search +- **Goal**: Find specific technical documentation. +- **Target**: MDN, Python Docs, Rust Docs, NixOS Wiki. +- **Strategy**: Restrict search to specific domains (`site:docs.python.org`). + +### 3. Code Search +- **Goal**: Find code snippets, libraries, or usage examples. +- **Target**: GitHub, GitLab, StackOverflow. +- **Tools**: GitHub CLI (`gh`), specialized code search APIs. + +### 4. Package Search +- **Goal**: Find packages and versions. +- **Target**: NixOS Packages, PyPI, NPM, Crates.io. +- **Tools**: `nix-search` (if available), `pip search` (deprecated, need alternative), `npm search`. + +### 5. Deep Research / Investigation +- **Goal**: Thoroughly investigate a topic by following links. +- **Strategy**: Recursive search or multi-step agentic workflow (search -> read -> search). + +## Implementation Options + +### Option A: Enhanced `claude -p` Wrapper +- Expand the existing `web-search` skill. +- Add flags: `--docs`, `--code`, `--package`. +- Modify the prompt sent to Claude to guide its search behavior. +- **Pros**: Uses existing powerful agent. +- **Cons**: Dependent on Claude's tools and context window. + +### Option B: Direct CLI Tools +- Use tools like `googler` or `ddgr` directly for faster, raw results. +- **Pros**: Fast, lightweight, structured output (JSON). +- **Cons**: Requires installing extra tools, raw output might need parsing. + +### Option C: Hybrid Approach +- Use CLI tools for discovery (getting URLs). +- Use `claude` or `curl` + `readability` for content extraction. + +## Questions for User +- Do you prefer a single "smart" skill that figures out what to do, or explicit flags/subcommands? +- Are there specific sources you search often (e.g., NixOS packages)? +- Do you want raw links or summarized answers?