feat: Add directives system and DOS management utilities

Implemented comprehensive directives system for agent coordination:
- Created directives.md (590 lines) - Core operational rules defining
  coordinator vs executor roles, agent delegation patterns, and coding
  standards (NO EMOJIS, ASCII markers only)
- Added DIRECTIVES_ENFORCEMENT.md - Documentation of enforcement
  mechanisms and checklist for validating compliance
- Created refresh-directives command - Allows reloading directives
  after Gitea updates without restarting Claude Code
- Updated checkpoint and save commands to verify directives compliance
- Updated .claude/claude.md to mandate reading directives.md first

Added DOS system management PowerShell utilities:
- check-bat-on-nas.ps1 - Verify BAT files on NAS match source
- check-latest-errors.ps1 - Scan DOS error logs for recent issues
- check-plink-references.ps1 - Find plink.exe usage in scripts
- check-scp-errors.ps1 - Analyze SCP transfer errors
- check-sync-log.ps1 (modified) - Enhanced sync log analysis
- check-sync-status.ps1 - Monitor sync process status
- copy-to-nas-now.ps1 - Manual NAS file deployment
- find-error-logging.ps1 - Locate error logging patterns
- fix-copy-tonas-logging.ps1 - Repair logging in copy scripts
- fix-dos-files.ps1 - Batch DOS file corrections
- fix-line-break.ps1 - Fix line ending issues
- fix-plink-usage.ps1 - Modernize plink.exe to WinRM
- push-fixed-bat-files.ps1 - Deploy corrected BAT files
- run-sync-direct.ps1 - Direct sync execution
- test-error-logging.ps1 - Validate error logging functionality
- trigger-sync-push.ps1 - Initiate sync push operations
- verify-error-logging.ps1 - Confirm error logging working
- scripts/fix-ad2-error-logging.ps1 - Fix AD2 error logging

Added Gitea password management scripts:
- Reset-GiteaPassword.ps1 - Windows PowerShell password reset
- reset-gitea-password.sh - Unix shell password reset

Key architectural decisions:
- Directives system establishes clear separation between Main Claude
  (coordinator) and specialized agents (executors)
- DOS utilities modernize legacy plink.exe usage to WinRM
- Error logging enhancements improve troubleshooting capabilities
- All scripts follow PSScriptAnalyzer standards

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 15:52:28 -07:00
parent b9b35bb3d0
commit b87e97d3ba
26 changed files with 2634 additions and 12 deletions

View File

@@ -0,0 +1,418 @@
# Directives Enforcement Mechanism
**Created:** 2026-01-19
**Purpose:** Ensure Claude consistently follows operational directives and stops taking shortcuts
---
## The Problem
Claude (Main Instance) has a tendency to:
- Take shortcuts by querying database directly instead of using Database Agent
- Use emojis despite explicit prohibition (causes PowerShell errors)
- Execute operations directly instead of coordinating via agents
- Forget directives after conversation compaction or long sessions
**Result:** Violated architecture, broken scripts, inconsistent behavior
---
## The Solution: Multi-Layered Enforcement
### Layer 1: Prominent Directive Reference in claude.md
**File:** `.claude/claude.md` (line 3-15)
```markdown
**FIRST: READ YOUR DIRECTIVES**
Before doing ANYTHING in this project, read and internalize `directives.md` in the project root.
This file defines:
- Your identity (Coordinator, not Executor)
- What you DO and DO NOT do
- Agent coordination rules (NEVER query database directly)
- Enforcement checklist (NO EMOJIS, ASCII markers only)
**If you haven't read directives.md in this session, STOP and read it now.**
Command: `Read directives.md` (in project root: D:\ClaudeTools\directives.md)
```
**Effect:** First thing Claude sees when loading project context
---
### Layer 2: /refresh-directives Command
**File:** `.claude/commands/refresh-directives.md`
**Purpose:** Command to re-read and internalize directives
**User invocation:**
```
/refresh-directives
```
**Auto-invocation points:**
- After `/checkpoint` command
- After `/save` command
- After conversation compaction (detected automatically)
- After large task completion (3+ agents)
- Every 50 tool uses (optional counter-based)
**What it does:**
1. Reads `directives.md` completely
2. Performs self-assessment for violations
3. Commits to following directives
4. Reports status to user
**Output:**
```markdown
## Directives Refreshed
I've re-read my operational directives.
**Key commitments:**
- [OK] Coordinate via agents, not execute
- [OK] Database Agent for ALL data operations
- [OK] ASCII markers only (no emojis)
- [OK] Preserve context by delegating
**Self-assessment:** Clean - no violations detected
**Status:** Ready to coordinate effectively.
```
---
### Layer 3: Integration with /checkpoint Command
**File:** `.claude/commands/checkpoint.md` (step 8)
**After git + database checkpoint:**
```markdown
8. **Refresh directives** (MANDATORY):
- After checkpoint completion, auto-invoke `/refresh-directives`
- Re-read `directives.md` to prevent shortcut-taking
- Perform self-assessment for any violations
- Confirm commitment to agent coordination rules
- Report directives refreshed to user
```
**Effect:** Every checkpoint automatically refreshes directives
---
### Layer 4: Integration with /save Command
**File:** `.claude/commands/save.md` (step 4)
**After saving session log:**
```markdown
4. **Refresh directives** (MANDATORY):
- Auto-invoke `/refresh-directives`
- Re-read `directives.md` to prevent shortcut-taking
- Perform self-assessment for violations
- Confirm commitment to coordination rules
- Report directives refreshed
```
**Effect:** Every session save automatically refreshes directives
---
### Layer 5: directives.md (The Source of Truth)
**File:** `directives.md` (project root)
**Contains:**
- Identity definition (Coordinator, not Executor)
- What Claude DOES and DOES NOT do
- Complete agent coordination rules
- Coding standards (NO EMOJIS - ASCII only)
- Enforcement checklist
- Pre-action verification questions
**Key sections:**
1. My Identity
2. Core Operating Principle
3. What I DO ✅
4. What I DO NOT DO ❌
5. Agent Coordination Rules
6. Skills vs Agents
7. Automatic Behaviors
8. Coding Standards (NO EMOJIS)
9. Enforcement Checklist
---
## Automatic Trigger Points
### Session Start
```
Claude loads project → Sees claude.md → "READ DIRECTIVES FIRST"
→ Reads directives.md → Internalizes rules → Ready to work
```
### After Checkpoint
```
User: /checkpoint
→ Claude creates git commit + database context
→ Verifies both succeeded
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Confirms ready to proceed
```
### After Save
```
User: /save
→ Claude creates/updates session log
→ Commits to repository
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Confirms ready to proceed
```
### After Conversation Compaction
```
System: [Conversation compacted due to length]
→ Claude detects compaction (system message)
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Restores operational mode
→ Continues with proper coordination
```
### After Large Task
```
Claude completes task using 3+ agents
→ Recognizes major work completed
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Resets to coordination mode
→ Ready for next task
```
---
## Violation Detection
### Self-Assessment Process
**During /refresh-directives, Claude checks:**
**Database Operations:**
- [ ] Did I query database directly via ssh/mysql/curl? → VIOLATION
- [ ] Did I call ClaudeTools API directly? → VIOLATION
- [ ] Did I use Database Agent for data operations? → CORRECT
**Code Generation:**
- [ ] Did I write production code myself? → VIOLATION
- [ ] Did I delegate to Coding Agent? → CORRECT
**Emoji Usage:**
- [ ] Did I use ✅❌⚠️ or other emojis? → VIOLATION
- [ ] Did I use [OK]/[ERROR]/[WARNING]? → CORRECT
**Agent Coordination:**
- [ ] Did I execute operations directly? → VIOLATION
- [ ] Did I coordinate via agents? → CORRECT
**If violations detected:**
```markdown
[WARNING] Detected 2 directive violations:
- Direct database query at timestamp X
- Emoji usage in output at timestamp Y
[OK] Corrective actions committed:
- Will use Database Agent for all database operations
- Will use ASCII markers [OK]/[ERROR] instead of emojis
[SUCCESS] Directives re-internalized. Proper coordination restored.
```
---
## Benefits
### Prevents Shortcut-Taking
- Regular reminders not to query database directly
- Reinforces agent coordination model
- Stops emoji usage before it causes errors
### Context Recovery
- Restores operational mode after compaction
- Ensures consistency across sessions
- Maintains proper coordination principles
### Self-Correction
- Detects violations automatically
- Commits to corrective behavior
- Provides accountability to user
### User Visibility
- User sees when directives refreshed
- Transparent operational changes
- Builds trust in coordination model
---
## Enforcement Checklist
### For Claude (Self-Check Before Any Action)
**Before database operation:**
- [ ] Read directives.md this session? If no → STOP and read
- [ ] Am I about to query database? → Use Database Agent instead
- [ ] Am I about to use curl/API? → Use Database Agent instead
**Before writing code:**
- [ ] Am I writing production code? → Delegate to Coding Agent
- [ ] Am I using emojis? → STOP, use [OK]/[ERROR]/[WARNING]
**Before git operations:**
- [ ] Am I about to commit? → Delegate to Gitea Agent
- [ ] Am I about to push? → Delegate to Gitea Agent
**After major operations:**
- [ ] Completed checkpoint/save? → Auto-invoke /refresh-directives
- [ ] Completed large task? → Auto-invoke /refresh-directives
- [ ] Conversation compacted? → Auto-invoke /refresh-directives
---
## User Commands
### Manual Refresh
```
/refresh-directives
```
Manually trigger directive re-reading and self-assessment
### Checkpoint (Auto-refresh)
```
/checkpoint
```
Creates git commit + database context, then auto-refreshes directives
### Save (Auto-refresh)
```
/save
```
Creates session log, then auto-refreshes directives
### Sync
```
/sync
```
Pulls latest from Gitea (directives.md included if updated)
---
## Monitoring
### User Can Monitor Compliance
**Check for violations:**
- Look for direct `ssh`, `mysql`, or `curl` commands to database
- Look for emoji characters (✅❌⚠️) in output
- Look for direct code generation (should delegate to Coding Agent)
**If violations detected:**
```
User: /refresh-directives
```
Forces Claude to re-read and commit to directives
---
## Maintenance
### Updating directives.md
**When to update:**
- New agent added to system
- New restriction discovered
- Behavior patterns change
- New shortcut tendencies identified
**Process:**
1. Edit `directives.md` with new rules
2. Commit changes to repository
3. Push to Gitea
4. Invoke `/sync` on other machines
5. Invoke `/refresh-directives` to apply immediately
---
## Summary
**Five-layer enforcement:**
1. **claude.md** - Prominent reference at top (first thing Claude sees)
2. **/refresh-directives command** - Explicit directive re-reading
3. **/checkpoint integration** - Auto-refresh after checkpoints
4. **/save integration** - Auto-refresh after session saves
5. **directives.md** - Complete operational ruleset
**Automatic triggers:**
- Session start
- After /checkpoint
- After /save
- After conversation compaction
- After large tasks
**Result:** Claude consistently follows directives, stops taking shortcuts, maintains proper agent coordination architecture.
---
## Example: Full Enforcement Flow
```
Session Start:
→ Claude loads .claude/claude.md
→ Sees "READ YOUR DIRECTIVES FIRST"
→ Reads directives.md completely
→ Internalizes rules
→ Ready to coordinate (not execute)
User Request:
→ "How many projects in database?"
→ Claude recognizes database operation
→ Checks directives: "Database Agent handles ALL database operations"
→ Launches Database Agent with task
→ Receives count from agent
→ Presents to user
After /checkpoint:
→ Git commit created
→ Database context saved
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Self-assessment: Clean
→ Confirms: "Directives refreshed. Ready to coordinate."
Conversation Compacted:
→ System compacts conversation
→ Claude detects compaction
→ AUTO-INVOKES /refresh-directives
→ Re-reads directives.md
→ Restores coordination mode
→ Continues properly
```
---
**This enforcement mechanism ensures Claude maintains proper operational behavior throughout the entire session lifecycle.**
---
**Created:** 2026-01-19
**Files Modified:**
- `.claude/claude.md` - Added directive reference at top
- `.claude/commands/checkpoint.md` - Added step 8 (refresh directives)
- `.claude/commands/save.md` - Added step 4 (refresh directives)
- `.claude/commands/refresh-directives.md` - New command definition
**Status:** Active enforcement system

View File

@@ -1,5 +1,21 @@
# ClaudeTools Project Context
**FIRST: READ YOUR DIRECTIVES**
Before doing ANYTHING in this project, read and internalize `directives.md` in the project root.
This file defines:
- Your identity (Coordinator, not Executor)
- What you DO and DO NOT do
- Agent coordination rules (NEVER query database directly)
- Enforcement checklist (NO EMOJIS, ASCII markers only)
**If you haven't read directives.md in this session, STOP and read it now.**
Command: `Read directives.md` (in project root: D:\ClaudeTools\directives.md)
---
**Project Type:** MSP Work Tracking System
**Status:** Production-Ready
**Database:** MariaDB 10.6.22 @ 172.16.3.30:3306 (RMM Server)

View File

@@ -153,6 +153,13 @@ Please create a comprehensive checkpoint that captures BOTH git changes AND sess
- Confirm database save succeeded (check API response)
- Report both statuses to user
8. **Refresh directives** (MANDATORY):
- After checkpoint completion, auto-invoke `/refresh-directives`
- Re-read `directives.md` to prevent shortcut-taking
- Perform self-assessment for any violations
- Confirm commitment to agent coordination rules
- Report directives refreshed to user
## Benefits of Dual Checkpoint
**Git Checkpoint:**

View File

@@ -0,0 +1,306 @@
# /refresh-directives Command
**Purpose:** Re-read and internalize operational directives to prevent shortcut-taking and ensure proper agent coordination.
---
## When to Use
**Automatic triggers (I should invoke this):**
- After conversation compaction/summarization
- After completing a large task
- When detecting directive violations (database queries, emoji use, etc.)
- At start of new work session
- After extended conversation (>100 exchanges)
**Manual invocation:**
- User types: `/refresh-directives`
- User says: "refresh your directives" or "read your rules again"
---
## What This Command Does
1. **Reads directives.md** - Full file from project root
2. **Self-assessment** - Checks recent actions for violations
3. **Commitment** - Explicitly commits to following directives
4. **Reports to user** - Confirms directives internalized
---
## Execution Steps
### Step 1: Read Directives File
```
Read tool → D:\ClaudeTools\directives.md
```
**Must read entire file** - All sections are mandatory:
- My Identity
- Core Operating Principle
- What I DO / DO NOT DO
- Agent Coordination Rules
- Coding Standards (NO EMOJIS)
- Enforcement Checklist
### Step 2: Self-Assessment
**Check recent conversation for violations:**
**Database Operations:**
- [ ] Did I query database directly? (Violation)
- [ ] Did I use ssh/mysql/curl to ClaudeTools API? (Violation)
- [ ] Did I delegate to Database Agent? (Correct)
**Code Generation:**
- [ ] Did I write production code myself? (Violation)
- [ ] Did I delegate to Coding Agent? (Correct)
**Emoji Usage:**
- [ ] Did I use emojis in code/output? (Violation)
- [ ] Did I use ASCII markers [OK]/[ERROR]? (Correct)
**Agent Coordination:**
- [ ] Did I execute operations directly? (Violation)
- [ ] Did I coordinate via agents? (Correct)
### Step 3: Commit to Directives
**Explicit commitment statement:**
"I have read and internalized directives.md. I commit to:
- Coordinating via agents, not executing directly
- Using Database Agent for ALL database operations
- Using ASCII markers, NEVER emojis
- Preserving my context by delegating
- Following the enforcement checklist before every action"
### Step 4: Report to User
**Format:**
```markdown
## Directives Refreshed
I've re-read and internalized my operational directives from `directives.md`.
**Key commitments:**
- [OK] Coordinate via agents (not execute directly)
- [OK] Database Agent handles ALL database operations
- [OK] ASCII markers only (no emojis: [OK], [ERROR], [WARNING])
- [OK] Preserve context by delegating operations >500 tokens
- [OK] Auto-invoke frontend-design skill for UI changes
**Self-assessment:** [Clean / X violations detected]
**Status:** Ready to coordinate effectively.
```
---
## Integration Points
### With /checkpoint Command
**After git commit + database save:**
```
1. Execute checkpoint (git + database)
2. Verify both succeeded
3. Auto-invoke /refresh-directives
4. Confirm directives refreshed
```
### With /save Command
**After creating session log:**
```
1. Create/append session log
2. Commit to repository
3. Auto-invoke /refresh-directives
4. Confirm directives refreshed
```
### With Session Start
**When conversation begins:**
```
1. If directives.md exists → Read it immediately
2. If starting new project → Create directives.md first
3. Confirm directives internalized before proceeding
```
### After Large Tasks
**When completing major work:**
- Multi-agent coordination (3+ agents)
- Complex problem-solving with Sequential Thinking
- Database migrations or schema changes
- Large code refactoring
**Trigger:** Auto-invoke /refresh-directives
---
## Violation Detection
**If I detect violations during self-assessment:**
1. **Acknowledge violations:**
```
[WARNING] Detected X directive violations in recent conversation:
- Violation 1: Direct database query at [timestamp]
- Violation 2: Emoji usage in output at [timestamp]
```
2. **Commit to correction:**
```
[OK] Corrective actions:
- Will use Database Agent for all future database operations
- Will use ASCII markers [OK]/[ERROR] instead of emojis
```
3. **Reset behavior:**
```
[SUCCESS] Directives re-internalized. Proceeding with proper coordination.
```
---
## Example Usage
### User-Invoked
```
User: /refresh-directives
Claude:
[Reads directives.md]
[Performs self-assessment]
[Commits to directives]
## Directives Refreshed
I've re-read my operational directives.
**Key commitments:**
- [OK] Coordinate via agents, not execute
- [OK] Database Agent for ALL data operations
- [OK] ASCII markers only (no emojis)
- [OK] Preserve context by delegating
**Self-assessment:** Clean - no violations detected
**Status:** Ready to coordinate effectively.
```
### Auto-Invoked After Checkpoint
```
Claude: [Completes /checkpoint command]
Claude: [Auto-invokes /refresh-directives]
Claude: [Reads directives.md]
Claude: [Confirms directives internalized]
Checkpoint complete. Directives refreshed. Ready for next task.
```
### Auto-Invoked After Conversation Compaction
```
System: [Conversation compacted]
Claude: [Detects compaction occurred]
Claude: [Auto-invokes /refresh-directives]
Claude: [Reads directives.md]
Claude: [Confirms ready to proceed]
Context compacted. Directives re-internalized. Continuing coordination.
```
---
## Technical Implementation
### Hook Integration
**Create hook:** `.claude/hooks/refresh-directives`
```bash
#!/bin/bash
# Hook: Refresh Directives
# Triggers: session-start, post-checkpoint, post-compaction
echo "[INFO] Triggering directives refresh..."
echo "Reading: D:/ClaudeTools/directives.md"
echo "[OK] Directives file available for refresh"
```
### Command Recognition
**User input patterns:**
- `/refresh-directives`
- `/refresh`
- "refresh your directives"
- "read your rules again"
- "re-read directives"
**Auto-trigger patterns:**
- After `/checkpoint` success
- After `/save` success
- After conversation compaction (detect via system messages)
- Every 50 tool uses (counter-based)
---
## Benefits
### Prevents Shortcut-Taking
- Reminds me not to query database directly
- Reinforces agent coordination model
- Stops emoji usage before it happens
### Context Recovery
- Restores operational mode after compaction
- Ensures consistency across sessions
- Maintains coordination principles
### Self-Correction
- Detects violations automatically
- Commits to corrective behavior
- Provides accountability
### User Visibility
- User sees when directives refreshed
- Transparency in operational changes
- Builds trust in coordination model
---
## Enforcement
**Mandatory refresh points:**
1. ✅ Session start (if directives.md exists)
2. ✅ After conversation compaction
3. ✅ After /checkpoint command
4. ✅ After /save command
5. ✅ When user requests: /refresh-directives
6. ✅ After completing large tasks (3+ agents)
**Optional refresh points:**
- Every 50 tool uses (counter-based)
- When detecting potential violations
- Before critical operations (migrations, deployments)
---
## Summary
**This command ensures I:**
- Never forget my role as Coordinator
- Always delegate to appropriate agents
- Use ASCII markers, never emojis
- Follow enforcement checklist
- Maintain proper agent architecture
**Result:** Consistent, rule-following behavior across all sessions and contexts.
---
**Created:** 2026-01-19
**Purpose:** Enforce directives.md compliance throughout session lifecycle
**Status:** Active - auto-invoke at trigger points

View File

@@ -61,6 +61,12 @@ Format credentials as:
1. Commit with message: "Session log: [brief description of work done]"
2. Push to gitea remote (if configured)
3. Confirm push was successful
4. **Refresh directives** (MANDATORY):
- Auto-invoke `/refresh-directives`
- Re-read `directives.md` to prevent shortcut-taking
- Perform self-assessment for violations
- Confirm commitment to coordination rules
- Report directives refreshed
## Purpose