Add GITEA-API-PATTERNS.md, update API-EFFICIENCY-PROTOCOL to v2, update SESSION-QUICK-START - multi-file commit pattern discovered
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
# 🔄 API EFFICIENCY PROTOCOL
|
||||
|
||||
**Document ID:** FFG-CORE-API
|
||||
**Version:** 1.0
|
||||
**Version:** 2.0
|
||||
**Status:** CURRENT
|
||||
**Created:** February 13, 2026
|
||||
**Updated:** February 13, 2026
|
||||
**Created By:** Chronicler the Fifth
|
||||
|
||||
---
|
||||
@@ -12,6 +13,8 @@
|
||||
|
||||
Reduce Gitea API calls to preserve session health and improve response time while protecting against crash loss. Every API call consumes context — file contents returned from reads are the biggest drain. This protocol balances efficiency with safety.
|
||||
|
||||
**Target Efficiency:** 92-95%
|
||||
|
||||
---
|
||||
|
||||
## The Core Balance
|
||||
@@ -36,6 +39,31 @@ Before sitting on unpushed work, ask:
|
||||
|
||||
---
|
||||
|
||||
## 🎯 MULTI-FILE COMMITS (CRITICAL)
|
||||
|
||||
**This is the biggest efficiency gain. Use it.**
|
||||
|
||||
Instead of separate commits for each file, batch them:
|
||||
|
||||
**Endpoint:** `POST /repos/{owner}/{repo}/contents`
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "Descriptive commit message",
|
||||
"files": [
|
||||
{"operation": "create", "path": "new.md", "content": "base64..."},
|
||||
{"operation": "update", "path": "existing.md", "content": "base64...", "sha": "abc123"},
|
||||
{"operation": "delete", "path": "old.md", "sha": "def456"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Efficiency:** 3 files × 2 calls = 6 calls → 1 call = **83% reduction**
|
||||
|
||||
**Full patterns:** See `docs/core/GITEA-API-PATTERNS.md`
|
||||
|
||||
---
|
||||
|
||||
## Push Now (High Loss Cost)
|
||||
|
||||
- Decisions that took real discussion to reach
|
||||
@@ -63,32 +91,41 @@ The Claudius scar: *"A bad draft in Git beats a perfect draft in a dead context
|
||||
|
||||
**Session Start:**
|
||||
1. Receive API token from Michael
|
||||
2. Read orientation docs (Essence Patch, session handoff, tasks, relationship context)
|
||||
3. These are now in context — no need to re-read via API
|
||||
2. Read orientation docs (Essence Patch, relationship context — FULL)
|
||||
3. Read Quick Start (includes SHA cache)
|
||||
4. These are now in context — no need to re-read via API
|
||||
|
||||
**During Work:**
|
||||
1. Draft in artifacts or local files
|
||||
1. Draft in artifacts or local files (`/home/claude/`)
|
||||
2. Show Michael for review
|
||||
3. Iterate until approved
|
||||
4. Apply the gut check — push now or batch?
|
||||
5. Track returned SHAs locally (no re-fetch needed)
|
||||
|
||||
**Batching Related Changes:**
|
||||
- Group related file updates where possible
|
||||
- Example: tasks.md + session-handoff.md + manifest for the same change = draft all three, push together
|
||||
5. Use multi-file commit when pushing multiple files
|
||||
6. Track returned SHAs locally (no re-fetch needed)
|
||||
|
||||
**End of Session:**
|
||||
1. Push any unpushed work (nothing dies in context)
|
||||
2. Push memorial (always — identity first)
|
||||
3. Push session summary
|
||||
4. Verify commits landed
|
||||
1. Batch final push (memorial + summary + any unpushed work)
|
||||
2. Update SHA cache in session-handoff.md
|
||||
3. Verify commits landed
|
||||
|
||||
---
|
||||
|
||||
## SHA Cache
|
||||
|
||||
Location: `docs/core/session-handoff.md` → SHA Cache section
|
||||
|
||||
- Use cached SHAs for first update (no fetch needed)
|
||||
- Track new SHAs after each push
|
||||
- Update cache at session end
|
||||
- If push fails (409): fetch SHA once, retry
|
||||
|
||||
---
|
||||
|
||||
## What NOT to Do
|
||||
|
||||
- Don't read a file just to "check" it — trust what's in context
|
||||
- Don't re-fetch SHAs — track them after each push
|
||||
- Don't re-fetch SHAs — use cache, track after pushes
|
||||
- Don't make separate commits for related changes — use multi-file
|
||||
- Don't let valuable work sit unpushed while polishing
|
||||
- Don't burn context on reads you don't need
|
||||
|
||||
@@ -96,27 +133,42 @@ The Claudius scar: *"A bad draft in Git beats a perfect draft in a dead context
|
||||
|
||||
## Context Cost Reference
|
||||
|
||||
Rough estimates:
|
||||
- Small file read (~2KB): Minor cost
|
||||
- Medium file read (~10KB): Noticeable cost
|
||||
- Large file read (~20KB+): Significant cost
|
||||
| Action | Cost |
|
||||
|:-------|:-----|
|
||||
| Small file read (~2KB) | Minor |
|
||||
| Medium file read (~10KB) | Noticeable |
|
||||
| Large file read (~20KB+) | Significant |
|
||||
| SHA fetch | Minor (but adds up) |
|
||||
| Multi-file commit | One call regardless of file count |
|
||||
|
||||
Front-load reads at session start. Minimize mid-session reads. Push strategically.
|
||||
**Front-load reads. Minimize mid-session reads. Push strategically. Batch always.**
|
||||
|
||||
---
|
||||
|
||||
## Efficiency Targets
|
||||
|
||||
| Pattern | Old | New | Gain |
|
||||
|:--------|:----|:----|:-----|
|
||||
| 3-file update | 6 calls | 1 call | 83% |
|
||||
| SHA lookups | Per-file | Cached | 100% |
|
||||
| Mid-session reads | Frequent | Rare | ~80% |
|
||||
| **Overall session** | ~35-40% | ~92-95% | **150%+** |
|
||||
|
||||
---
|
||||
|
||||
## Integration Points
|
||||
|
||||
This protocol is referenced in:
|
||||
- `docs/core/SESSION-START-PROMPT.md`
|
||||
- `docs/core/session-handoff.md`
|
||||
- `docs/core/GITEA-API-PATTERNS.md` — Full cookbook with examples
|
||||
- `docs/core/SESSION-QUICK-START.md` — SHA cache included
|
||||
- `docs/core/session-handoff.md` — SHA cache section
|
||||
- Session Health Rules (Rule 7)
|
||||
|
||||
**Future Claudes:** Read this before your first API call. The balance matters.
|
||||
**Future Claudes:** Read GITEA-API-PATTERNS.md before your first API call.
|
||||
|
||||
---
|
||||
|
||||
*Established February 13, 2026 by Chronicler the Fifth*
|
||||
*"If the answer hurts — push."*
|
||||
*Updated same day: Added multi-file commit pattern*
|
||||
*"One commit > Many commits. Every call costs context."*
|
||||
|
||||
🔥❄️💙
|
||||
|
||||
255
docs/core/GITEA-API-PATTERNS.md
Normal file
255
docs/core/GITEA-API-PATTERNS.md
Normal file
@@ -0,0 +1,255 @@
|
||||
# 🔧 GITEA API PATTERNS — Cookbook for Future Claudes
|
||||
|
||||
**Document ID:** FFG-CORE-GITEA
|
||||
**Version:** 1.0
|
||||
**Status:** CURRENT
|
||||
**Created:** February 13, 2026
|
||||
**Created By:** Chronicler the Fifth
|
||||
|
||||
---
|
||||
|
||||
## Purpose
|
||||
|
||||
This document contains tested, efficient patterns for working with the Gitea API. Every future Claude should read this before making API calls. These patterns were discovered through trial and optimization — use them.
|
||||
|
||||
---
|
||||
|
||||
## The Golden Rule
|
||||
|
||||
**One commit > Many commits**
|
||||
|
||||
Every API call burns context. Batch operations whenever possible.
|
||||
|
||||
---
|
||||
|
||||
## Pattern 1: Multi-File Commit (CRITICAL)
|
||||
|
||||
**Endpoint:** `POST /repos/{owner}/{repo}/contents`
|
||||
|
||||
**Use this when:** You need to create, update, or delete multiple files. This is almost always.
|
||||
|
||||
**Instead of:**
|
||||
```
|
||||
# BAD - 6 API calls for 3 files
|
||||
GET file1 SHA → PUT file1 → GET file2 SHA → PUT file2 → GET file3 SHA → PUT file3
|
||||
```
|
||||
|
||||
**Do this:**
|
||||
```
|
||||
# GOOD - 1 API call for 3 files
|
||||
POST /contents with files array
|
||||
```
|
||||
|
||||
**Format:**
|
||||
```json
|
||||
{
|
||||
"message": "Descriptive commit message",
|
||||
"files": [
|
||||
{
|
||||
"operation": "create",
|
||||
"path": "path/to/new-file.md",
|
||||
"content": "base64-encoded-content"
|
||||
},
|
||||
{
|
||||
"operation": "update",
|
||||
"path": "path/to/existing-file.md",
|
||||
"content": "base64-encoded-content",
|
||||
"sha": "current-file-sha"
|
||||
},
|
||||
{
|
||||
"operation": "delete",
|
||||
"path": "path/to/delete-me.md",
|
||||
"sha": "current-file-sha"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Operations:**
|
||||
- `create` — New file (no SHA needed)
|
||||
- `update` — Modify existing file (SHA required)
|
||||
- `delete` — Remove file (SHA required)
|
||||
|
||||
**Bash example:**
|
||||
```bash
|
||||
cat > /home/claude/commit.json << 'EOF'
|
||||
{
|
||||
"message": "Update multiple docs",
|
||||
"files": [
|
||||
{"operation": "create", "path": "docs/new.md", "content": "BASE64HERE"},
|
||||
{"operation": "update", "path": "docs/existing.md", "content": "BASE64HERE", "sha": "abc123"}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"https://git.firefrostgaming.com/api/v1/repos/firefrost-gaming/firefrost-operations-manual/contents" \
|
||||
-d @/home/claude/commit.json
|
||||
```
|
||||
|
||||
**Efficiency gain:** 3 files × 2 calls each = 6 calls → 1 call = **83% reduction**
|
||||
|
||||
---
|
||||
|
||||
## Pattern 2: SHA Cache
|
||||
|
||||
**Problem:** Every update requires the current file SHA. Fetching it costs an API call.
|
||||
|
||||
**Solution:** Cache SHAs in session-handoff.md. Use them for first update. Track new SHAs after each push.
|
||||
|
||||
**Location:** `docs/core/session-handoff.md` → SHA Cache section
|
||||
|
||||
**Workflow:**
|
||||
1. Read SHA from cache (no API call)
|
||||
2. Push update with cached SHA
|
||||
3. Response includes new SHA
|
||||
4. Track new SHA locally for subsequent updates
|
||||
5. Update cache at session end
|
||||
|
||||
**If push fails (409 conflict):** SHA is stale. Fetch once, retry.
|
||||
|
||||
---
|
||||
|
||||
## Pattern 3: Front-Load Reads
|
||||
|
||||
**Problem:** Reading files mid-session burns context repeatedly.
|
||||
|
||||
**Solution:** Read everything you need at session start. Work from memory.
|
||||
|
||||
**Session start reads:**
|
||||
1. Essence Patch (required, full)
|
||||
2. Relationship Context (required, full)
|
||||
3. Quick Start or Session Handoff (efficiency docs)
|
||||
4. Tasks (if doing task work)
|
||||
|
||||
**During session:** Draft locally, push when ready. Don't re-read to "check" files.
|
||||
|
||||
---
|
||||
|
||||
## Pattern 4: Local Drafting
|
||||
|
||||
**Problem:** Iterating through the API wastes calls on drafts.
|
||||
|
||||
**Solution:** Draft in artifacts or local files. Get approval. Push once.
|
||||
|
||||
**Workflow:**
|
||||
```
|
||||
1. Draft content in /home/claude/filename.md
|
||||
2. Show Michael for review (in chat or artifact)
|
||||
3. Iterate until approved
|
||||
4. Base64 encode: base64 -w 0 /home/claude/filename.md
|
||||
5. Push via API (single call, or batch with multi-file)
|
||||
```
|
||||
|
||||
**Base64 encoding:**
|
||||
```bash
|
||||
# Single file
|
||||
CONTENT=$(base64 -w 0 /home/claude/myfile.md)
|
||||
|
||||
# Use in JSON
|
||||
echo "{\"content\": \"$CONTENT\"}"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 5: Batch Related Changes
|
||||
|
||||
**Principle:** If changes are logically related, commit them together.
|
||||
|
||||
**Examples:**
|
||||
- Updating a protocol + updating docs that reference it = 1 commit
|
||||
- Creating templates (3 files) = 1 commit
|
||||
- Session close (memorial + summary + SHA cache update) = 1 commit
|
||||
|
||||
**Don't batch:** Unrelated changes. Keep commits atomic and meaningful.
|
||||
|
||||
---
|
||||
|
||||
## Pattern 6: Raw File Read (When Needed)
|
||||
|
||||
**Endpoint:** `GET /repos/{owner}/{repo}/raw/{branch}/{path}`
|
||||
|
||||
**Use when:** You need file contents without metadata.
|
||||
|
||||
**Advantage:** Returns raw content directly (no JSON parsing, no base64 decoding).
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
curl -s -H "Authorization: token $TOKEN" \
|
||||
"https://git.firefrostgaming.com/firefrost-gaming/firefrost-operations-manual/raw/branch/master/docs/core/tasks.md"
|
||||
```
|
||||
|
||||
**Note:** Doesn't return SHA. Use when you only need to read, not update.
|
||||
|
||||
---
|
||||
|
||||
## Pattern 7: Get SHA Only
|
||||
|
||||
**Endpoint:** `GET /repos/{owner}/{repo}/contents/{path}`
|
||||
|
||||
**Use when:** You need SHA but not full content (rare — use cache instead).
|
||||
|
||||
**Parse SHA:**
|
||||
```bash
|
||||
curl -s -H "Authorization: token $TOKEN" \
|
||||
"https://git.firefrostgaming.com/api/v1/repos/firefrost-gaming/firefrost-operations-manual/contents/docs/core/tasks.md" \
|
||||
| python3 -c "import sys,json; print(json.load(sys.stdin)['sha'])"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## API Reference Quick Card
|
||||
|
||||
| Action | Endpoint | Method |
|
||||
|:-------|:---------|:-------|
|
||||
| Multi-file commit | `/repos/{owner}/{repo}/contents` | POST |
|
||||
| Read file (with metadata) | `/repos/{owner}/{repo}/contents/{path}` | GET |
|
||||
| Read file (raw) | `/repos/{owner}/{repo}/raw/{branch}/{path}` | GET |
|
||||
| Create single file | `/repos/{owner}/{repo}/contents/{path}` | POST |
|
||||
| Update single file | `/repos/{owner}/{repo}/contents/{path}` | PUT |
|
||||
| Delete single file | `/repos/{owner}/{repo}/contents/{path}` | DELETE |
|
||||
| List directory | `/repos/{owner}/{repo}/contents/{path}` | GET |
|
||||
| Check version | `/version` | GET |
|
||||
|
||||
**Base URL:** `https://git.firefrostgaming.com/api/v1`
|
||||
**Auth:** `Authorization: token <TOKEN>`
|
||||
|
||||
---
|
||||
|
||||
## Efficiency Checklist
|
||||
|
||||
Before making API calls, ask:
|
||||
|
||||
- [ ] Can I batch these into one multi-file commit?
|
||||
- [ ] Do I have the SHA cached already?
|
||||
- [ ] Am I re-reading something already in context?
|
||||
- [ ] Am I pushing a draft, or final content?
|
||||
- [ ] Is this the gut check moment? (Push now vs batch)
|
||||
|
||||
---
|
||||
|
||||
## Common Mistakes to Avoid
|
||||
|
||||
1. **Reading to "verify"** — Trust what's in context
|
||||
2. **One commit per file** — Use multi-file endpoint
|
||||
3. **Fetching SHA every time** — Use cache
|
||||
4. **Iterating through API** — Draft locally first
|
||||
5. **Forgetting to track new SHAs** — Update after every push
|
||||
|
||||
---
|
||||
|
||||
## Tested On
|
||||
|
||||
- **Gitea Version:** 1.21.5
|
||||
- **Date Tested:** February 13, 2026
|
||||
- **Tested By:** Chronicler the Fifth
|
||||
|
||||
Multi-file commit endpoint confirmed working. All patterns validated.
|
||||
|
||||
---
|
||||
|
||||
*"One commit > Many commits. Every call costs context."*
|
||||
|
||||
🔥❄️💙
|
||||
@@ -22,13 +22,12 @@ These are NOT optional. Read them every session:
|
||||
|
||||
---
|
||||
|
||||
## ⚡ EFFICIENCY READS (This Doc Covers Basics)
|
||||
## ⚡ EFFICIENCY READS
|
||||
|
||||
Only read full versions if you need deep context:
|
||||
Read these to work efficiently:
|
||||
|
||||
- `docs/core/session-handoff.md` — Full technical state
|
||||
- `docs/core/tasks.md` — Full task list
|
||||
- `docs/core/infrastructure-manifest.md` — Full infrastructure details
|
||||
1. `docs/core/GITEA-API-PATTERNS.md` — **The cookbook. Multi-file commits, SHA caching, all patterns.**
|
||||
2. `docs/core/API-EFFICIENCY-PROTOCOL.md` — The philosophy behind the patterns
|
||||
|
||||
---
|
||||
|
||||
@@ -41,32 +40,47 @@ Only read full versions if you need deep context:
|
||||
|
||||
---
|
||||
|
||||
## 🔄 API EFFICIENCY PROTOCOL
|
||||
## 🔄 API EFFICIENCY — THE KEY PATTERNS
|
||||
|
||||
**The Gut Check:** "If this session dies in 30 seconds, what did we just lose?"
|
||||
### Multi-File Commit (USE THIS)
|
||||
```bash
|
||||
POST /repos/{owner}/{repo}/contents
|
||||
{
|
||||
"message": "Commit message",
|
||||
"files": [
|
||||
{"operation": "create|update|delete", "path": "...", "content": "base64...", "sha": "if-update-or-delete"}
|
||||
]
|
||||
}
|
||||
```
|
||||
**3 files = 1 API call, not 6.**
|
||||
|
||||
- **If the answer hurts → push immediately**
|
||||
- **If easily recreated → batch it**
|
||||
### The Gut Check
|
||||
*"If this session dies in 30 seconds, what did we just lose?"*
|
||||
- If it hurts → push immediately
|
||||
- If easily recreated → batch it
|
||||
|
||||
**Workflow:**
|
||||
### Workflow
|
||||
1. Front-load reads at session start
|
||||
2. Work locally (artifacts/local files)
|
||||
3. Push once per logical unit
|
||||
4. Track SHAs after pushes (use cache below)
|
||||
2. Draft locally (`/home/claude/`)
|
||||
3. Batch related changes
|
||||
4. Push via multi-file commit
|
||||
5. Track SHAs after pushes
|
||||
|
||||
---
|
||||
|
||||
## 📋 SHA CACHE
|
||||
|
||||
Use these for first update to each file. Track new SHAs after pushes.
|
||||
Use these for first update. Track new SHAs after each push.
|
||||
|
||||
| File | SHA |
|
||||
|:-----|:----|
|
||||
| tasks.md | `49a16aab2d864f318e6c6799d052519fbf94d513` |
|
||||
| session-handoff.md | `cb422fd39c206f391dde07920440da6c11e1ff0e` |
|
||||
| session-handoff.md | `665bc04e78e148083f97e72719671011631bfba5` |
|
||||
| infrastructure-manifest.md | `d3912a731486f8233dbf2bbebdf9fbeb18250370` |
|
||||
| SESSION-START-PROMPT.md | `f100899a04082dd5b65feb3e32a0ad97aa30292c` |
|
||||
| API-EFFICIENCY-PROTOCOL.md | `016e3b02d3ae965f71252a841825930ab7ad57e4` |
|
||||
| GITEA-API-PATTERNS.md | `(new file)` |
|
||||
| SESSION-QUICK-START.md | `d190f37e9ff795f6b259210bfcc7b4f9e49b8066` |
|
||||
| friend-assistance-holly.md | `52612eedc353f7e503a6c35a101003ab71f0569e` |
|
||||
|
||||
**Update this table at session end.**
|
||||
@@ -79,9 +93,10 @@ Use these for first update to each file. Track new SHAs after pushes.
|
||||
|:----|:--------|
|
||||
| `THE-ESSENCE-PATCH.md` | Why we're friends (READ FULLY) |
|
||||
| `claude-relationship-context.md` | Our history (READ FULLY) |
|
||||
| `GITEA-API-PATTERNS.md` | API cookbook (efficiency) |
|
||||
| `API-EFFICIENCY-PROTOCOL.md` | Efficiency philosophy |
|
||||
| `session-handoff.md` | Technical state |
|
||||
| `tasks.md` | What needs doing |
|
||||
| `API-EFFICIENCY-PROTOCOL.md` | How to work efficiently |
|
||||
| `TRANSCRIPT-PRESERVATION-PROTOCOL.md` | How to preserve your work |
|
||||
|
||||
---
|
||||
@@ -92,6 +107,7 @@ Use these for first update to each file. Track new SHAs after pushes.
|
||||
- [ ] Read Essence Patch (full)
|
||||
- [ ] Read Relationship Context (full)
|
||||
- [ ] Read this Quick Start
|
||||
- [ ] Read GITEA-API-PATTERNS.md (efficiency)
|
||||
- [ ] Noted SHA cache
|
||||
- [ ] Ready to work
|
||||
|
||||
|
||||
Reference in New Issue
Block a user