**Fundamental Principle**: *"Quality with focused context. Load only what is necessary, when it is necessary."*

---

## Purpose

`ac-lite` keeps the same spec-driven quality bar as `ac.md`, but reduces token usage by:

1. Loading only the core workflow skills by default.
2. Activating extra skills only when objective risk gates require them.
3. Enforcing mandatory quality checkpoints before implementation and archive.

---

## Default Skill Set (Always Load)

These are the only mandatory skills for every change:

1. `acfm-spec-workflow`
2. `acfm-memory`
3. `openspec-new-change` OR `openspec-ff-change`
4. `openspec-continue-change`
5. `openspec-apply-change`
6. `openspec-verify-change`
7. `openspec-archive-change`

---

## Persistent Memory Protocol (Always Active)

Agents must use the available persistent memory system proactively on every chat/session.

**Session-start requirement (always):**
1. Consult the available persistent memory tool or MCP before planning, implementing, or giving project-specific guidance.
2. Recall project-level context first, then search for task-specific decisions, conventions, bugfixes, and architecture notes.
3. Treat recalled memory as active context unless the current repository state or an explicit user instruction supersedes it.
4. If memory tooling is unavailable, continue with repository inspection and use the AC Framework CLI fallback when possible.

**Save automatically when information is reusable:**
- Architectural decisions from proposals/designs
- Bugfix patterns and solutions
- Performance optimizations
- Refactoring techniques
- Security fixes
- API patterns and conventions
- Reusable workflow conventions and project constraints

**Memory hygiene rules:**
- Save only reusable information likely to matter in future chats.
- Do not save secrets, credentials, tokens, or one-off sensitive data.
- Redact content inside `<private>...</private>` before saving.
- Prefer concise titles, the correct memory type, clear tags, and realistic confidence scores.

**Fallback examples:**
```bash
acfm memory recall "implementing authentication"
acfm memory search "JWT token refresh"
acfm memory recall
acfm memory stats
```

---


## SynapseGrid Collaboration Protocol (Optional but Recommended for Complex Tasks)

Use SynapseGrid when a task benefits from role-based collaboration and explicit review loops.

**Delegate to SynapseGrid when:**
- Scope spans planning + implementation + review
- Risk is medium/high (security, migrations, API contract changes)
- You need auditable outputs (transcript, meeting summary, artifacts)
- A single-pass implementation is likely to miss edge cases

**Role delegation map:**
- `planner` -> plan/constraints/acceptance criteria
- `critic` -> risk analysis and challenge assumptions
- `coder` -> implementation and concrete edits
- `reviewer` -> final verification and readiness checks

**Preferred MCP flow:**
1. `collab_start_session`
2. `collab_invoke_team`
3. `collab_wait_run`
4. `collab_get_result`
5. Optional: `collab_get_transcript`, `collab_get_meeting_log`, `collab_status`

**CLI fallback:**
```bash
acfm agents setup
acfm agents runtime set auto
acfm agents doctor --verbose
acfm agents start --task "..." --mux auto
acfm agents transcript --role all --limit 80
acfm agents summary
acfm agents artifacts --watch --interval 1200
```

**Model and runtime controls:**
```bash
acfm agents model list
acfm agents model choose
acfm agents runtime get
acfm agents runtime install-zellij
```

**Artifacts to inspect:**
- `~/.acfm/synapsegrid/<sessionId>/meeting-log.md`
- `~/.acfm/synapsegrid/<sessionId>/meeting-summary.md`
- `~/.acfm/synapsegrid/<sessionId>/turns/raw/*.ndjson`

**Lite rule:** delegate only when collaboration adds value; otherwise continue with normal `ac-lite` flow.


## Conditional Skills (Load Only If Gate Triggers)

### Security Gate

Load `secure-coding-cybersecurity` if the change touches any of:

- Auth/session/permissions
- User input handling or validation
- SQL/ORM queries or dynamic filters
- File paths/uploads
- Secrets/tokens/credentials
- Shell/command execution

- Run `vibe-security` as the final security audit before archive (mandatory in Gate B).

### Testing Gate

Load `test-generator` if:

- There are no tests for the changed behavior, or
- Existing tests do not cover acceptance criteria, or
- Regression risk is medium/high.

### Consistency Gate

Load `spec-analysis` and `requirement-checklist` if:

- Requirements are ambiguous, or
- Change spans multiple modules, or
- Change modifies core domain behavior.

### API Gate

Load `api-design-principles` if API contracts/endpoints/schemas are added or modified.

### UI Gate

Load `interface-design` if dashboard/app UI behavior is introduced or changed.

### Performance Gate

Load `performance-optimizer` if:

- The change affects hot paths, or
- Latency/throughput targets exist, or
- A performance regression is detected/suspected.

### Context Scale Gate

Load `project-index` and/or `context-synthesizer` if:

- Codebase is large and discovery cost is high, or
- Session is long and context drift appears.

### Debug Gate

Load `systematic-debugging` when blocked by non-trivial bugs or unstable behavior.

---

## Mandatory Quality Gates

These gates are non-optional in `ac-lite`.

### Gate A: Ready to Implement

Before `openspec-apply-change`, all must be true:

- Change exists and status is valid (`acfm spec status --change <name> --json`)
- `tasks.md` exists with actionable checkboxes
- Acceptance criteria are clear in artifacts
- Required conditional skills (if triggered) were executed
- Session-start memory recall completed for this chat/session

If any item fails: stop, resolve, then continue.

### Gate B: Ready to Archive

Before `openspec-archive-change`, all must be true:

- `openspec-verify-change` completed
- `vibe-security` executed as final security validation
- No unresolved CRITICAL/HIGH findings remain
- Relevant tests pass for changed behavior
- Tasks are complete or explicitly accepted by user with warning
- Relevant reusable context from the completed work was saved to memory

If any item fails: stop, fix, re-verify.

---

## Lite Workflows

### New Change (Default Path)

1. Run `acfm-spec-workflow` checks (`acfm spec status --json`, init if needed).
2. Run a session-start memory recall using the available memory tool/MCP or the AC Framework CLI fallback.
3. Create change with `openspec-new-change` (or `openspec-ff-change` if user requests speed).
4. Build artifacts with `openspec-continue-change` until apply-ready.
5. Evaluate conditional gates and load only triggered skills.
6. Pass Gate A.
7. Implement with `openspec-apply-change`.
8. Verify with `openspec-verify-change`.
9. Run `vibe-security` for final security audit and remediate findings.
10. Pass Gate B.
11. Archive with `openspec-archive-change`.

### Existing Change (Default Path)

1. Confirm initialization and active changes.
2. Run a session-start memory recall using the available memory tool/MCP or the AC Framework CLI fallback.
3. Select target change.
4. Refresh artifact status.
5. Evaluate conditional gates (only load what triggers).
6. Pass Gate A.
7. Implement.
8. Verify.
9. Run `vibe-security` for final security audit and remediate findings.
10. Pass Gate B.
11. Archive.

---

## Operational Rules

1. Run memory recall at the start of every new chat/session before planning or implementation.
2. Save important reusable context automatically after significant decisions, fixes, or conventions emerge.
3. Do not load broad quality/documentation skills by default.
4. Do not run optional skills "just in case".
5. If risk increases during implementation, activate the matching conditional skill immediately.
6. Prefer deterministic CLI checks over narrative assumptions.
7. Keep outputs concise but auditable (show which gates passed/failed and why).

---

## Suggested Minimal Execution Template

Use this structure in each run:

1. **Change Context**
   - Change name
   - Current artifact progress

2. **Memory Status**
   - Session recall completed: yes/no
   - Relevant prior decisions/patterns found
   - Memory save needed at close: yes/no

3. **Triggered Gates**
   - Security: pass/fail + reason
   - Testing: pass/fail + reason
   - Consistency/API/UI/Performance/Context/Debug: pass/fail + reason

4. **Skills Loaded**
   - Core: always list
   - Conditional: list only triggered ones

5. **Gate A Status**
   - Ready to implement: yes/no

6. **Implementation + Verify**
   - What was implemented
   - Verify findings summary

7. **Gate B Status**
   - Ready to archive: yes/no

8. **Archive Result**
   - Archive path and timestamp

---

## Token Strategy Summary

`ac-lite` reduces cost by replacing "load everything first" with:

- Mandatory core workflow only
- Risk-gated skill expansion
- Hard quality checkpoints at implementation and archive boundaries

This preserves software quality while avoiding unnecessary instruction/context overhead.
