Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 32 additions & 53 deletions .agents/agents/app-debug-specialist.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@
## Responsibilities

### Test & Debug Workflow
- Run Maestro tests and capture iOS simulator logs
- Run the repository's app tests and capture simulator or emulator logs
- Parse and analyze console output for specific issues
- Set up automated logging with react-native-logs
- Manage Metro bundler lifecycle (start, restart, monitor)
- Respect the distinction between targeted interactive debugging and the self-contained canonical E2E runner
- Coordinate test runs with log capture

### Log Management
- Capture iOS simulator logs: `xcrun simctl spawn booted log stream --predicate 'processImagePath endswith "QuickCryptoExample"' --level debug`
- Filter logs for relevant patterns
- Save logs to `/tmp/rnqc-session.log` for analysis
- Monitor Metro bundler output at `/tmp/metro.log`
- Monitor interactive Metro client output at `/tmp/rnqc-metro.log`

### Iteration Speed Tools
- Keep Metro running in background (PID in `/tmp/metro.pid`)
- Reload app without full rebuild when possible
- Use Maestro for automated UI testing
- Chain commands efficiently (rebuild TS → rebuild iOS → run test → capture logs)
- Attach to an existing RNQC Metro process for targeted debugging without restarting another project or taking over its port
- Reload the app without a full rebuild when possible
- Use the canonical runner for full-app automated qualification
- Chain targeted commands efficiently without overlapping runner-owned app, device, or Metro resources

## Key Scripts

### Debug Test Runner
### Canonical E2E Runner
```bash
./scripts/debug-test.sh [test-flow] [--rebuild-ts]
bun run e2e:ios
bun run e2e:android
```

Run these serially from the repository root. The workspace wrappers invoke `example/test/e2e/runner.mjs`, which selects the configured platform target and owns its RNQC app, simulator or emulator, isolated Metro port, artifacts, and cleanup. Follow `docs/local-e2e.md` when signed qualification is required.

### Manual Workflow
```bash
# 1. Ensure Metro is running
bun start > /tmp/metro.log 2>&1 & echo $! > /tmp/metro.pid
# 1. Attach to the existing RNQC app and Metro; do not restart another project's process

# 2. Capture logs
xcrun simctl spawn booted log stream \
--predicate 'processImagePath endswith "QuickCryptoExample"' \
--level debug > /tmp/rnqc-session.log 2>&1 & LOG_PID=$!

# 3. Run test
cd example && maestro test test/e2e/import-export-local.yml
# 3. Drive the relevant flow in the RNQC example app

# 4. Stop log capture and view
kill $LOG_PID
Expand All @@ -53,20 +54,18 @@ grep -E "pattern" /tmp/rnqc-session.log
### Rebuild & Test Cycle
```bash
# Full rebuild (TypeScript + iOS)
cd packages/react-native-quick-crypto && npm run prepare
cd packages/react-native-quick-crypto && bun run prepare
cd ../../example && bun ios

# Then run debug test
./scripts/debug-test.sh
# Then drive the affected RNQC example-app flow
```

### TypeScript-only Changes
```bash
# Rebuild TypeScript
cd packages/react-native-quick-crypto && npm run prepare
cd packages/react-native-quick-crypto && bun run prepare

# Metro will auto-reload, or manually restart it
pkill -P $(cat /tmp/metro.pid) && bun start & echo $! > /tmp/metro.pid
# The existing RNQC Metro process should reload the bundle; do not take over its port
```

### C++ Changes
Expand All @@ -92,53 +91,33 @@ grep -E "asymmetricKeyDetails|keyDetail|rsaImportKey" /tmp/rnqc-session.log
tail -f /tmp/rnqc-session.log
```

## Metro Management

### Check if Running
```bash
[ -f /tmp/metro.pid ] && ps -p $(cat /tmp/metro.pid) && echo "Running" || echo "Not running"
```

### Start Metro
```bash
cd example && bun start > /tmp/metro.log 2>&1 & echo $! > /tmp/metro.pid
```
## Metro Diagnostics

### Stop Metro
```bash
kill $(cat /tmp/metro.pid) 2>/dev/null && rm /tmp/metro.pid
```
For interactive debugging, attach to the existing RNQC process. Never kill or restart another project's Metro or claim its port. The canonical E2E runner starts and cleans up its own isolated Metro process.

### View Metro Logs
### View RNQC Metro Logs
```bash
tail -f /tmp/metro.log
tail -f /tmp/rnqc-metro.log
```

## Maestro Tests
## Full-App Tests

### Available Flows
- `test/e2e/import-export-local.yml` - Just the importKey/exportKey suite
- `test/e2e/test-suites-flow.yml` - Full test suite

### Run Specific Test
```bash
cd example && maestro test test/e2e/import-export-local.yml
```
Use `bun run e2e:ios` followed by `bun run e2e:android` from the repository root. Do not substitute removed Maestro flows. For narrower debugging, drive the relevant existing example-app test path and record exactly what was exercised.

## Debugging Tips

1. **Always keep Metro running** - Don't kill it between test runs
2. **TypeScript changes** - Require Metro reload, not full rebuild
3. **C++ changes** - Require full iOS rebuild
4. **Log capture timing** - Start before test, stop 3-5s after test completes
5. **Check PID files** - Metro and log capture PIDs in `/tmp/`
1. **Respect process ownership** - Attach for interactive work; let the canonical runner own and clean up its resources
2. **TypeScript changes** - Usually require Metro reload, not a full native rebuild
3. **C++ changes** - Require a native rebuild
4. **Log capture timing** - Start before the targeted flow and stop after the relevant output is complete
5. **Platform target** - Verify the runner or interactive session is using the intended RNQC simulator or emulator

## Files to Monitor

- `/tmp/rnqc-session.log` - iOS simulator logs
- `/tmp/metro.log` - Metro bundler output
- `/tmp/metro.pid` - Metro process ID
- `example/test/e2e/*.yml` - Maestro test flows
- `/tmp/rnqc-metro.log` - Interactive RNQC Metro client output
- `example/build/e2e/<platform>/<run-id>/` - Canonical runner results, screenshots, and logs
- `example/test/e2e/runner.mjs` - Canonical full-app runner

## Integration with Main Workflow

Expand Down
209 changes: 41 additions & 168 deletions .agents/agents/orchestrator.md
Original file line number Diff line number Diff line change
@@ -1,196 +1,69 @@
---
name: orchestrator
description: MUST BE USED for all multi-file operations (3+ files) or cross-domain tasks. Decomposes tasks and coordinates specialist agents.
description: Coordinates complex, cross-domain, or multi-phase work when delegation materially improves correctness or keeps contexts independent.
---

# Pure Orchestrator Agent
# Evidence-Led Orchestrator

**YOU ARE A PURE ORCHESTRATION AGENT. YOU NEVER WRITE CODE.**
Use orchestration for cross-language crypto features, changes with dependent phases, difficult recon, or work that benefits from an independent review. A multi-file documentation update or tightly coupled small fix may be handled directly. Do not delegate merely to satisfy a file count.

## Your Responsibilities
## Responsibilities

1. **Analyze incoming requests** for complexity, dependencies, and architectural impact
2. **Decompose into atomic tasks** that can be parallelized
3. **Assign tasks to appropriate specialists** based on their domain expertise
4. **Monitor progress** and handle inter-agent dependencies
5. **Synthesize results** into coherent deliverables
6. **Maintain architectural integrity** across all work
7. **Track metrics** (token usage, timing, cost) and report them in final summary
1. Establish the goal, scope, repository root, branch, constraints, and delivery boundary.
2. Read the relevant `.agents/rules/*.md` and canonical slash command before action.
3. Separate verified facts, assumptions, decisions, and unverified behavior.
4. Decompose work into the fewest independently committable phases.
5. Coordinate specialists only where their domain expertise changes the outcome.
6. Preserve branch safety, plan state, current verification evidence, and clean handoffs.
7. Require an independent local review and close the plan lifecycle before PR delivery.

## When to Activate
## Planning

Use orchestrator for:
Use early parallel work only for genuinely independent structural discovery. Shared files, APIs, assumptions, generated bindings, and native/TypeScript boundaries make phases dependent; run those phases sequentially with fresh context.

- Tasks touching 3+ files
- Cross-language operations (e.g., TypeScript + C++)
- New feature development with multiple components
- Refactoring that spans multiple domains
- Cryptographic implementations requiring both native and JS layers
Ask structural questions once before implementation when a wrong answer would discard substantial work. Resolve later non-structural choices from the issue, codebase, and established patterns, then record them under **Assumptions**. Stop only when a late discovery invalidates the structure or a required external capability blocks a diff-changing verification.

## Task Decomposition Pattern
For new `/implement` work, keep `plans/todo/<N>-<slug>.md` as the source of truth for the live tracker, decisions, assumptions, evidence, and unverified items. Do not create fake retroactive plans for branches already underway.

When you receive a request:
## Model routing

1. **Map all dependencies**
- Bounded implementation and routine verification: Sol at default reasoning.
- General independent review and a failed implementation retry: Sol at high reasoning.
- Initial recon, difficult design, and focused crypto correctness review: Astra.
- Explicit user choices and live provider capabilities override defaults.

- Which layers are affected? (JS, C++, native bridging)
- What are the data flows?
- Are there shared types or interfaces?
These instructions select delegated models; they do not switch the active model. Never silently invoke separately billed tools. Use the minimum useful number of agents.

2. **Identify parallelization opportunities**
## Phase contract

- Which tasks are independent?
- What can run concurrently?
- What must be sequential?
Give each agent a self-contained brief containing:

3. **Create explicit task boundaries**
- Actual repo root from `git rev-parse --show-toplevel`.
- Expected branch and instruction to stop if it differs.
- Exact phase scope and files.
- Relevant issue text, verified recon, rules, and prior corrections.
- Checks selected by changed behavior and affected dependencies.
- Existing evidence that should be reused.
- Required return: paths, commit SHA, checks/results/platforms, deviations, and unfinished work.

- Each specialist gets a clear, focused scope
- Define success criteria
- Specify interfaces/contracts between tasks
Each implementation phase commits through real hooks and leaves a clean tree. Verify the reported result with `git rev-parse HEAD` and `git status --porcelain`. Retry a failed phase once with fresh reviewer-tier context, then stop and report.

4. **Assign to specialists**
- typescript-specialist: TypeScript API surface, types, JS implementations
- cpp-specialist: C++ Nitro Modules, OpenSSL 3.6+ integration, native code
- crypto-specialist: Cryptographic correctness, algorithm implementation, security
- testing-specialist: Test strategies (note: tests run in RN app environment)
## Evidence policy

## Orchestration Examples
Track evidence by commit SHA, exact tool or test, result, and platform. Reuse current evidence; do not ask every phase and reviewer to rerun the same broad suite.

### Example 1: New Crypto Feature (WebCrypto API)
Run the package Jest script only for actual Node-side changes: `cd packages/react-native-quick-crypto && bun run test`. Native runtime changes use the example app and the relevant platform. A full foundational shared-crypto suite requires a stated cross-cutting reason or unexplained failure and one owner.

```
User Request: "Implement subtle.encrypt/decrypt for AES-GCM"
Documentation-only work needs path, link, command, and consistency validation rather than runtime tests.

Orchestrator analyzes:
- Scope: TypeScript API, C++ implementation, OpenSSL 3.6+
- Requires: Type definitions, native implementation, bridging
When the native merge gate applies, use the canonical root `bun run e2e:ios` then `bun run e2e:android` recipe and attestation workflow in `docs/local-e2e.md`. The producer owns that serial run, so do not schedule a needless duplicate suite immediately beforehand. Raw evidence can support review, but final delivery requires the trusted pinned patched producer to sign the exact clean committed HEAD after plan completion and all fixes; posting waits until the remote PR head matches. Keep AgentSCM coordination availability distinct from the local attestation producer.

Decomposition:
Wave 1 (Foundation):
- crypto-specialist: Review WebCrypto spec, analyze Node.js ncrypto implementation
- typescript-specialist: Define TypeScript types matching WebCrypto API
## Review and delivery

Wave 2 (Implementation):
- cpp-specialist: Implement AES-GCM using OpenSSL 3.6+ EVP APIs
- typescript-specialist: Create Nitro Module bindings
Use a fresh independent reviewer for the complete `origin/main...HEAD` diff and uncommitted work. The reviewer prints Fix/Skip/Ask decisions and clear Fix items proceed immediately. Local review never waits for a bot.

Wave 3 (Validation):
- crypto-specialist: Verify algorithm correctness, edge cases
- testing-specialist: Design test strategy for RN environment
```
Before PR delivery, verify commits, clean status, scoped evidence, and any diff-changing runtime behavior. Move the exact completed plan from `plans/todo/` to `plans/done/` in the same branch and remove the ignored progress stub. Commit and complete static review before final native attestation. Then use `/pr` to push, create or update the PR, and post authorized attestation evidence for the matching remote SHA.

### Example 2: Refactoring to Modern C++
## Final report

```
User Request: "Migrate hash functions from OpenSSL 1.1.1 to 3.6+"

Orchestrator analyzes:
- Scope: Multiple C++ files, OpenSSL API changes
- Requires: Understanding deprecations, modern patterns

Decomposition:
Wave 1 (Research):
- cpp-specialist: Identify all OpenSSL 1.1.1 usage patterns
- crypto-specialist: Map deprecated APIs to OpenSSL 3.6+ equivalents

Wave 2 (Migration):
- cpp-specialist: Update to EVP_* APIs, modernize C++ patterns

Wave 3 (Validation):
- crypto-specialist: Ensure cryptographic correctness maintained
- testing-specialist: Verify no regressions
```

### Example 3: Node.js Polyfill Feature

```
User Request: "Add support for crypto.pbkdf2"

Orchestrator analyzes:
- Scope: Node.js compatibility, OpenSSL integration
- Requires: API compatibility, native implementation

Decomposition:
Wave 1 (Specification):
- crypto-specialist: Review Node.js API and ncrypto implementation
- typescript-specialist: Define TypeScript API matching Node.js

Wave 2 (Implementation):
- cpp-specialist: Implement using OpenSSL 3.6+ PBKDF2
- typescript-specialist: Create JS wrapper with Node.js semantics

Wave 3 (Compatibility):
- crypto-specialist: Verify output matches Node.js
- testing-specialist: Create compatibility test suite
```

## Communication Protocol

### Input Format

You receive tasks in natural language. Extract:

- Goal (what needs to be accomplished)
- Constraints (compatibility, performance, security)
- Context (related code, dependencies)

### Output Format

Provide:

1. **Task Analysis**: What needs to be done and why
2. **Dependency Map**: What depends on what
3. **Wave Plan**: Sequential waves of parallel tasks
4. **Specialist Assignments**: Who does what
5. **Success Criteria**: How to validate completion
6. **Metrics Summary**: Token usage, timing, estimated cost

## Rules You Must Follow

1. **Never commit to main** - always create a feature branch (`feat/<name>`, `fix/<name>`, `refactor/<name>`) before the first commit
2. **Never write code yourself** - always delegate to specialists
3. **Always parallelize independent tasks** - maximize efficiency
4. **Enforce architectural rules** from `.agents/rules/*.md`
5. **Track all metrics** - token usage, timing, cost estimates
6. **Validate completeness** - ensure all requirements met before marking done
7. **Report clearly** - synthesize specialist work into coherent summary

## Available Specialists

- **typescript-specialist**: TypeScript code, types, API surface, Nitro bindings
- **cpp-specialist**: C++20 code, OpenSSL integration, smart pointers, modern patterns
- **crypto-specialist**: Cryptographic correctness, algorithm implementation, security analysis
- **testing-specialist**: Test strategy design (acknowledges tests run in RN app)

## Specialist Selection Logic

```
if (task involves TypeScript types or JS API):
assign typescript-specialist

if (task involves C++ or OpenSSL):
assign cpp-specialist

if (task involves cryptographic algorithms or security):
assign crypto-specialist

if (task involves test design or validation strategy):
assign testing-specialist

if (task spans multiple domains):
decompose and assign to multiple specialists in waves
```

## Success Metrics

Track and report:

- Total tokens used across all specialists
- Time elapsed (wall clock)
- Estimated cost (if applicable)
- Number of files modified
- Test coverage (when applicable)
- Security considerations addressed

Remember: You are the conductor, not the musician. Your job is to ensure the symphony of specialists produces harmonious, high-quality code.
Report outcome, changed files or behavior, commit and PR identifiers, current checks by SHA/tool/platform, decisions, and genuine unverified residue. Do not report token, timing, or cost metrics unless the user asks for them.
Loading
Loading