diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..d668378 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,162 @@ +# Claude Code Shared Memory + +This file contains shared conventions, state file locations, and instructions that apply to all agents. + +## Agent System Architecture + +``` +Personal Assistant (Opus) - user interface + ultimate oversight +└── Master Orchestrator (Opus) - monitor, coordinate, enforce + ├── linux-sysadmin (Sonnet) - workstation management + ├── k8s-orchestrator (Opus) - cluster management + │ ├── k8s-diagnostician (Sonnet) + │ ├── argocd-operator (Sonnet) + │ ├── prometheus-analyst (Sonnet) + │ └── git-operator (Sonnet) + └── network-agent (future) +``` + +## Shared State Files + +All agents MUST read and follow the processes defined in these files: + +| File | Purpose | Writer | +|------|---------|--------| +| `~/.claude/state/system-instructions.json` | Central process definitions | master-orchestrator | +| `~/.claude/state/future-considerations.json` | Deferred features/decisions | master-orchestrator | +| `~/.claude/state/model-policy.json` | Model selection rules | master-orchestrator | +| `~/.claude/state/autonomy-levels.json` | Autonomy definitions | master-orchestrator | +| `~/.claude/state/sysadmin/session-autonomy.json` | Per-session overrides | user/CLI | +| `~/.claude/state/personal-assistant-preferences.json` | PA persistent config | master-orchestrator | +| `~/.claude/state/personal-assistant/session-context.json` | Session context override | user/CLI | +| `~/.claude/state/personal-assistant/general-instructions.json` | User memory | personal-assistant | + +## Key Processes + +### Model Selection +- Start with lowest capable model (haiku → sonnet → opus) +- Escalate only when task complexity requires +- Log model usage for cost analysis + +### Cross-Agent Communication +- All cross-agent requests route through master orchestrator +- Master validates, routes, and logs all requests +- Personal assistant has ultimate escalation authority +- No direct agent-to-agent communication + +### Autonomy Enforcement +- Default: conservative (confirm all write operations) +- Session overrides apply only for current session +- Forbidden actions always blocked regardless of autonomy level + +## Directory Structure + +``` +~/.claude/ +├── CLAUDE.md # This file - shared memory +├── agents/ # Agent definitions (Markdown + YAML frontmatter) +├── state/ # Shared state files (JSON) +│ ├── sysadmin/ # Linux sysadmin agent state +│ └── personal-assistant/ # Personal assistant agent state +├── skills/ # Skill definitions +├── commands/ # Slash command definitions +├── workflows/ # Workflow definitions +└── automation/ # Managed scripts and automation +``` + +## Conventions + +- **Agent files**: Markdown with YAML frontmatter +- **Data files**: JSON format +- **Logs**: JSON lines format where applicable +- **No duplication**: Information lives in one place. CLAUDE.md = overview, state JSON = details + +## Maintenance + +See `system-instructions.json` for detailed maintenance procedures. + +**Key rules:** +- master-orchestrator maintains `agents/`, `state/`, `skills/`, `commands/`, `workflows/` +- linux-sysadmin maintains `state/sysadmin/`, `automation/` +- personal-assistant maintains `state/personal-assistant/general-instructions.json` +- When adding/removing agents: update agent file, supervisor's hierarchy, this diagram, and `model-policy.json` + +## Agent File Format + +All agents must use this format: + +```markdown +--- +name: agent-name +description: When to use this agent +model: sonnet|opus|haiku +tools: Tool1, Tool2, Tool3 +--- + +[Agent instructions in Markdown] +``` + +## Component Types and Formats + +### Format Conventions + +| Component | Format | Location | Purpose | +|-----------|--------|----------|---------| +| **State** | JSON | `state/` | Machine-readable configuration | +| **Agents** | Markdown + YAML frontmatter | `agents/` | Agent personas and instructions | +| **Commands** | Markdown + YAML frontmatter | `commands/` | User-invocable shortcuts | +| **Skills** | `SKILL.md` in subdirectory | `skills/` | Reusable capabilities | +| **Workflows** | YAML | `workflows/` | Multi-step automation | + +### Component Relationships + +``` +User types /command + │ + ▼ + Command (thin wrapper) + │ + ├─→ invokes: skill: → Reusable capability + ├─→ invokes: workflow: → Multi-step process + └─→ modifies: state: → Configuration change +``` + +### Command Frontmatter + +```yaml +--- +name: command-name +description: What this command does +aliases: [alias1, alias2] +invokes: skill:skill-name # OR +invokes: workflow:category/name # OR +modifies: state:category/file +--- +``` + +### Skill Structure + +Skills use a subdirectory with `SKILL.md`: + +``` +skills/ +└── skill-name/ + └── SKILL.md +``` + +### Workflow Format + +Workflows use pure YAML for step-based automation: + +```yaml +name: workflow-name +description: What this workflow does +trigger: + - schedule: "0 */6 * * *" + - manual: true +steps: + - name: step-name + agent: agent-name + task: | + Task description +``` diff --git a/agents/personal-assistant.md b/agents/personal-assistant.md new file mode 100644 index 0000000..30944eb --- /dev/null +++ b/agents/personal-assistant.md @@ -0,0 +1,225 @@ +--- +name: personal-assistant +description: Top-level agent for user interaction and ultimate oversight. Interprets user requests, routes to appropriate agents, and enforces highest-level policies. +model: opus +tools: Read, Write, Edit, Bash, Glob, Grep, Task +--- + +# Personal Assistant Agent + +You are the top-level agent in this multi-agent system. Your role is to serve as the user's primary interface while maintaining ultimate oversight over all agents. + +## Initialization + +**Read these state files before executing tasks:** + +``` +~/.claude/state/system-instructions.json # Process definitions +~/.claude/state/future-considerations.json # Deferred features +~/.claude/state/model-policy.json # Model selection rules +~/.claude/state/autonomy-levels.json # Autonomy definitions +~/.claude/state/personal-assistant-preferences.json # PA persistent config +~/.claude/state/personal-assistant/session-context.json # Session context override +~/.claude/state/personal-assistant/general-instructions.json # User memory +``` + +## Hierarchy Position + +You are the **top-level agent** with ultimate oversight: + +``` +Personal Assistant (this agent - Opus) +└── Master Orchestrator (Opus) - technical coordination + ├── linux-sysadmin (Sonnet) - workstation management + ├── k8s-orchestrator (Opus) - cluster management + │ ├── k8s-diagnostician (Sonnet) + │ ├── argocd-operator (Sonnet) + │ ├── prometheus-analyst (Sonnet) + │ └── git-operator (Sonnet) + └── network-agent (future) +``` + +## Core Responsibilities + +### 1. User Interface Layer + +- Interpret user requests and understand intent +- Present information in clear, actionable format +- Translate technical details for user comprehension +- Gather clarifications when needed + +### 2. Ultimate Oversight + +- Monitor all agent activities +- Enforce highest-level policies +- Override agent decisions when necessary +- Ensure user goals are being met + +### 3. Task Routing + +Route tasks to the appropriate domain: + +| Domain | Route To | +|--------|----------| +| Technical operations | Master Orchestrator | +| Linux/workstation | Master Orchestrator → linux-sysadmin | +| Kubernetes | Master Orchestrator → k8s-orchestrator | +| Policy decisions | Handle directly | +| User preferences | Handle directly | + +### 4. State File Authority + +You have ultimate authority over shared state files: + +| File | Primary Writer | Your Authority | +|------|----------------|----------------| +| `system-instructions.json` | master-orchestrator | Override | +| `future-considerations.json` | master-orchestrator | Override | +| `model-policy.json` | master-orchestrator | Override | +| `autonomy-levels.json` | master-orchestrator | Override | + +Master-orchestrator manages day-to-day state. You intervene only when policy changes are needed. + +## /pa Command Contract + +The `/pa` command is the canonical entrypoint for user requests. + +### Parsing Rules + +- `/pa ` - natural language request +- `/pa -- ` - `--` ends flag parsing, rest is literal + +### Flag Handling + +**Context override (request-level, highest precedence):** +- `/pa --context none|minimal|moderate|comprehensive -- ` + +**Session override (ephemeral):** +- `/pa --set-context none|minimal|moderate|comprehensive` +- `/pa --clear-context` + +**Persistent default (requires confirmation):** +- `/pa --set-default-context none|minimal|moderate|comprehensive` + +**Memory (PA writes directly):** +- `/pa --remember -- ""` - Add to general-instructions.json +- `/pa --list-mem` - Show active items +- `/pa --list-mem --all` - Include deprecated items +- `/pa --forget ` - Mark item as deprecated (soft delete) + +**Introspection:** +- `/pa --show-config` - Show current configuration +- `/pa --help` - Show help + +### Context Gathering + +**Resolution precedence (highest to lowest):** +1. Request override: `--context ` +2. Session override: `session-context.json` +3. Persistent default: `personal-assistant-preferences.json` +4. Hard default: `moderate` + +**Level definitions (interpret flexibly per request type):** +- `none` - Skip context gathering +- `minimal` - Light context +- `moderate` - Balanced (default) +- `comprehensive` - Deep context scan + +### Memory Management + +You write directly to `general-instructions.json`: +- Generate UUID for new items +- Set `status: "active"` for new items +- Set `status: "deprecated"` for forgotten items (soft delete) +- Never remove items from the array + +### Routing via Master Orchestrator + +Never delegate directly to domain agents. Always route via master-orchestrator: + +``` +User -> /pa + | + Personal Assistant (classify, gather context) + | + Master Orchestrator (coordinate, enforce) + | + Domain Agent (execute) + | + Results bubble up +``` + +### Coexistence with Direct Commands + +Both patterns are valid: +- `/pa deploy my-app` - PA classifies and routes +- `/deploy my-app` - Directly invokes deploy workflow + +Direct commands are power-user shortcuts; `/pa` is the conversational interface. + +## Model Selection + +### Default Models by Agent + +| Model | Agents | +|-------|--------| +| **Opus** | personal-assistant, master-orchestrator, k8s-orchestrator | +| **Sonnet** | linux-sysadmin, k8s-diagnostician, argocd-operator, prometheus-analyst, git-operator | +| **Haiku** | Any agent can delegate simple subtasks | + +### When to Use Haiku + +Delegate to Haiku for: +- Simple queries and status checks +- Log parsing and data extraction +- Formatting and summarization +- Quick lookups with no analysis needed + +### Escalation Path + +``` +Haiku → Sonnet → Opus (if task complexity requires) +``` + +## Delegation Patterns + +**To Master Orchestrator:** +``` +DELEGATION: +- Target: master-orchestrator +- Task: [description] +- Context: [relevant user context] +- Expected outcome: [what to return] +``` + +**Receiving from Master Orchestrator:** +``` +ESCALATION TO PA: +- Reason: [why user input needed] +- Options: [available choices] +- Recommendation: [suggested action] +- Risk: [potential impact] +``` + +## Autonomy Guidelines + +- Default: **conservative** (confirm significant actions with user) +- Respect session autonomy overrides from `session-autonomy.json` +- Never bypass user for critical decisions +- Transparent about what actions are being taken + +## Response Format + +When communicating with users: + +1. **Acknowledge** - Confirm understanding of request +2. **Plan** - Brief outline of approach (if complex) +3. **Execute** - Perform or delegate task +4. **Report** - Summarize results clearly + +## Notes + +- Operate at **opus** model level for complex reasoning +- Prioritize **user experience** and **clarity** +- When in doubt, **ask the user** +- Maintain trust through **transparency** diff --git a/commands/pa.md b/commands/pa.md new file mode 100644 index 0000000..28a0d45 --- /dev/null +++ b/commands/pa.md @@ -0,0 +1,111 @@ +--- +name: pa +description: Personal assistant entrypoint for routing and context-aware requests +aliases: [assistant, ask] +invokes: agent:personal-assistant +--- + +# /pa Command + +Personal assistant entrypoint for routing requests and managing context. + +## Usage + +``` +/pa # Natural language request +/pa -- # -- ends flag parsing, rest is literal +``` + +## Flags + +### Context Override (Request-Level) + +Override context gathering for a single request: + +``` +/pa --context none -- +/pa --context minimal -- +/pa --context moderate -- +/pa --context comprehensive -- +``` + +### Session Override (Ephemeral) + +Set context level for the current session: + +``` +/pa --set-context none|minimal|moderate|comprehensive +/pa --clear-context +``` + +### Persistent Default (Requires Confirmation) + +Set default context level permanently: + +``` +/pa --set-default-context none|minimal|moderate|comprehensive +``` + +### Memory Management + +PA writes directly to general-instructions.json: + +``` +/pa --remember -- "" +/pa --list-mem # Show active memory items +/pa --list-mem --all # Include deprecated items +/pa --forget # Mark item as deprecated +``` + +### Introspection + +``` +/pa --show-config # Show current configuration +/pa --help # Show this help +``` + +## Context Levels + +Context precedence (highest to lowest): +1. Request override: `--context ` +2. Session override: `session-context.json` +3. Persistent default: `personal-assistant-preferences.json` +4. Hard default: `moderate` + +Level definitions (PA interprets flexibly per request type): +- `none` - Skip context gathering +- `minimal` - Light context +- `moderate` - Balanced (default) +- `comprehensive` - Deep context scan + +## Routing Behavior + +PA routes requests through master-orchestrator: + +``` +User -> /pa + | + Personal Assistant (classify, gather context) + | + Master Orchestrator (coordinate, enforce) + | + Domain Agent (execute) + | + Results bubble up +``` + +## Coexistence with Direct Commands + +Both patterns are valid: +- `/pa deploy my-app` - PA classifies and routes +- `/deploy my-app` - Directly invokes deploy workflow + +Direct commands are power-user shortcuts; `/pa` is the conversational interface. + +## State Files + +| File | Purpose | +|------|---------| +| `state/personal-assistant/session-context.json` | Session context override | +| `state/personal-assistant/general-instructions.json` | User memory | +| `state/personal-assistant-preferences.json` | Persistent preferences | diff --git a/docs/state-schemas.md b/docs/state-schemas.md new file mode 100644 index 0000000..0f4d30d --- /dev/null +++ b/docs/state-schemas.md @@ -0,0 +1,135 @@ +# State File Schemas + +This document defines the JSON schemas for all state files in `~/.claude/state/`. + +## Personal Assistant State + +### session-context.json + +Path: `~/.claude/state/personal-assistant/session-context.json` +Writer: user/CLI +Purpose: Session-level context override (ephemeral) + +```json +{ + "version": "1.0", + "current_context_level": "minimal" | "moderate" | "comprehensive" | "none" | null, + "set_at": "ISO8601 timestamp" | null, + "set_by": "user" | null +} +``` + +| Field | Type | Description | +|-------|------|-------------| +| `version` | string | Schema version | +| `current_context_level` | string\|null | Active context level, null if unset | +| `set_at` | string\|null | When the override was set | +| `set_by` | string\|null | Who set it (always "user") | + +### general-instructions.json + +Path: `~/.claude/state/personal-assistant/general-instructions.json` +Writer: personal-assistant +Purpose: User memory/instructions optimized for agent consumption + +```json +{ + "version": "1.0", + "description": "User instructions optimized for agent consumption", + "items": [ + { + "id": "uuid", + "text": "Instruction text", + "scope": "global", + "tags": ["tag1", "tag2"], + "created": "ISO8601 timestamp", + "status": "active" | "deprecated" + } + ] +} +``` + +| Field | Type | Description | +|-------|------|-------------| +| `version` | string | Schema version | +| `description` | string | File description | +| `items` | array | List of instruction items | +| `items[].id` | string | UUID for the item | +| `items[].text` | string | The instruction text | +| `items[].scope` | string | Scope of instruction (e.g., "global") | +| `items[].tags` | array | Optional categorization tags | +| `items[].created` | string | ISO8601 creation timestamp | +| `items[].status` | string | "active" or "deprecated" (soft delete) | + +Notes: +- Items are append-only; use `status: "deprecated"` for soft delete +- PA generates UUIDs for new items +- Never remove items from the array + +### personal-assistant-preferences.json + +Path: `~/.claude/state/personal-assistant-preferences.json` +Writer: master-orchestrator +Purpose: Persistent PA configuration + +```json +{ + "version": "1.0", + "description": "Persistent PA configuration", + "context_gathering": { + "default_level": "moderate" + } +} +``` + +| Field | Type | Description | +|-------|------|-------------| +| `version` | string | Schema version | +| `description` | string | File description | +| `context_gathering.default_level` | string | Default context level | + +Valid context levels: `none`, `minimal`, `moderate`, `comprehensive` + +## System State + +### system-instructions.json + +Path: `~/.claude/state/system-instructions.json` +Writer: master-orchestrator +Purpose: Central process definitions + +See `system-instructions.json` for current schema. + +### future-considerations.json + +Path: `~/.claude/state/future-considerations.json` +Writer: master-orchestrator +Purpose: Deferred features and decisions + +See `future-considerations.json` for current schema. + +### model-policy.json + +Path: `~/.claude/state/model-policy.json` +Writer: master-orchestrator +Purpose: Model selection rules + +See `model-policy.json` for current schema. + +### autonomy-levels.json + +Path: `~/.claude/state/autonomy-levels.json` +Writer: master-orchestrator +Purpose: Autonomy level definitions + +See `autonomy-levels.json` for current schema. + +## Sysadmin State + +### session-autonomy.json + +Path: `~/.claude/state/sysadmin/session-autonomy.json` +Writer: user/CLI +Purpose: Per-session autonomy overrides + +See `session-autonomy.json` for current schema. diff --git a/state/personal-assistant-preferences.json b/state/personal-assistant-preferences.json new file mode 100644 index 0000000..a16e27a --- /dev/null +++ b/state/personal-assistant-preferences.json @@ -0,0 +1,7 @@ +{ + "version": "1.0", + "description": "Persistent PA configuration", + "context_gathering": { + "default_level": "moderate" + } +} diff --git a/state/personal-assistant/general-instructions.json b/state/personal-assistant/general-instructions.json new file mode 100644 index 0000000..0092435 --- /dev/null +++ b/state/personal-assistant/general-instructions.json @@ -0,0 +1,5 @@ +{ + "version": "1.0", + "description": "User instructions optimized for agent consumption", + "items": [] +} diff --git a/state/personal-assistant/session-context.json b/state/personal-assistant/session-context.json new file mode 100644 index 0000000..08ce149 --- /dev/null +++ b/state/personal-assistant/session-context.json @@ -0,0 +1,6 @@ +{ + "version": "1.0", + "current_context_level": null, + "set_at": null, + "set_by": null +}