Skip to content

Commit a009a31

Browse files
committed
feat: indexer config recovery, question tool focus fix, comprehensive CPU optimization, MCP OAuth client profile workaround, Session Mind fixes, and memory leak prevention
Session Mind improvements: - Publish Session.Event.Finished in prompt.ts for short session capture - Add 60s timeout + 2 retries with exponential backoff for memory extraction LLM - Add async indexing functions for immediate memory searchability - Add exponential backoff retry queue for transient indexing failures - Enable Session Mind features by default (saveMemories, enrich_compaction) - Increase context limits (max_tokens: 2000, max_memories: 5, max_sessions: 5) - Enhanced degraded mode logging (info level) - Updated OpenAPI schema defaults and regenerated SDK types Memory leak prevention (from upstream PRs anomalyco#14650, anomalyco#13186, anomalyco#12259, anomalyco#9149): - ACP session TTL (1h) and LRU eviction (max 50 sessions) with 5min cleanup - Signal handlers (SIGTERM/SIGINT/SIGHUP) for graceful shutdown in serve/worker/CLI - LSP client limit (max 20) with oldest-client eviction - Plugin dispose hook for cleanup on Instance.disposeAll() - O(1) string building: textParts[] in copilot message conversion - O(1) string building: argumentChunks[] in copilot tool call streaming - O(1) buffer management: bufferChunks[] in PTY with 2MB limit - 50ms throttled flush in session processor to batch streaming deltas - LRU cache utility for reusable memory-bounded caching Tests added (44 new tests, 2435 total pass): - ACP session manager tests (TTL expiry, LRU eviction, basic ops) - LSP client limit eviction test - Plugin dispose hook tests - PTY buffer chunk tests - Session processor flush throttling tests - LRU cache utility tests
1 parent b985ea3 commit a009a31

File tree

318 files changed

+184825
-32162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+184825
-32162
lines changed

.githooks/install-opencode.sh

Lines changed: 4602 additions & 0 deletions
Large diffs are not rendered by default.

.githooks/post-checkout

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
# .githooks/post-checkout
3+
# Git hook for opencode contributors to provide sync reminders
4+
#
5+
# This hook provides helpful reminders when:
6+
# 1. Switching to dev branch
7+
# 2. Switching from dev to feature branch
8+
# 3. Creating new branches
9+
10+
# Color codes for output
11+
RED='\033[0;31m'
12+
YELLOW='\033[1;33m'
13+
GREEN='\033[0;32m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m' # No Color
16+
17+
# Configuration
18+
UPSTREAM_REMOTE="upstream"
19+
MAIN_BRANCH="dev"
20+
21+
# Arguments passed by git
22+
# $1: ref of previous HEAD
23+
# $2: ref of new HEAD
24+
# $3: flag indicating branch checkout (1) or file checkout (0)
25+
PREV_HEAD=$1
26+
NEW_HEAD=$2
27+
BRANCH_CHECKOUT=$3
28+
29+
# Only run for branch checkouts, not file checkouts
30+
if [ "$BRANCH_CHECKOUT" != "1" ]; then
31+
exit 0
32+
fi
33+
34+
# Get branch names
35+
NEW_BRANCH=$(git branch --show-current)
36+
PREV_BRANCH=$(git reflog -1 | grep -oP 'moving from \K[^ ]+' || echo "")
37+
38+
# Skip if we couldn't determine branches
39+
if [ -z "$NEW_BRANCH" ]; then
40+
exit 0
41+
fi
42+
43+
echo -e "${BLUE}[post-checkout] Switched to branch: $NEW_BRANCH${NC}"
44+
45+
# Check if upstream remote exists
46+
HAS_UPSTREAM=false
47+
if git remote | grep -q "^${UPSTREAM_REMOTE}$"; then
48+
HAS_UPSTREAM=true
49+
fi
50+
51+
# Case 1: Switched TO dev branch
52+
if [ "$NEW_BRANCH" = "$MAIN_BRANCH" ]; then
53+
echo ""
54+
if [ "$HAS_UPSTREAM" = true ]; then
55+
# Check if dev is behind upstream
56+
git fetch "$UPSTREAM_REMOTE" --quiet 2>/dev/null || true
57+
LOCAL_MAIN=$(git rev-parse "$MAIN_BRANCH" 2>/dev/null || echo "")
58+
UPSTREAM_MAIN=$(git rev-parse "${UPSTREAM_REMOTE}/${MAIN_BRANCH}" 2>/dev/null || echo "")
59+
60+
if [ -n "$LOCAL_MAIN" ] && [ -n "$UPSTREAM_MAIN" ]; then
61+
if [ "$LOCAL_MAIN" != "$UPSTREAM_MAIN" ]; then
62+
if git merge-base --is-ancestor "$LOCAL_MAIN" "$UPSTREAM_MAIN"; then
63+
echo -e "${YELLOW}💡 Your local '$MAIN_BRANCH' is behind upstream${NC}"
64+
echo -e "${YELLOW} Sync with: git pull $UPSTREAM_REMOTE $MAIN_BRANCH${NC}"
65+
elif ! git merge-base --is-ancestor "$UPSTREAM_MAIN" "$LOCAL_MAIN"; then
66+
echo -e "${RED}⚠️ Your local '$MAIN_BRANCH' has diverged from upstream${NC}"
67+
echo -e "${YELLOW} Reset with: git reset --hard $UPSTREAM_REMOTE/$MAIN_BRANCH${NC}"
68+
else
69+
echo -e "${GREEN}✓ Your local '$MAIN_BRANCH' is synced with upstream${NC}"
70+
fi
71+
else
72+
echo -e "${GREEN}✓ Your local '$MAIN_BRANCH' is synced with upstream${NC}"
73+
fi
74+
fi
75+
else
76+
echo -e "${YELLOW}💡 Tip: Add upstream remote for easier syncing:${NC}"
77+
echo -e " git remote add $UPSTREAM_REMOTE git@github.com:anomalyco/opencode.git"
78+
fi
79+
echo ""
80+
fi
81+
82+
# Case 2: Switched FROM dev to feature branch
83+
if [ "$PREV_BRANCH" = "$MAIN_BRANCH" ] && [ "$NEW_BRANCH" != "$MAIN_BRANCH" ]; then
84+
echo ""
85+
if [ "$HAS_UPSTREAM" = true ]; then
86+
# Check if current branch is based on latest dev
87+
MERGE_BASE=$(git merge-base "$NEW_BRANCH" "$MAIN_BRANCH" 2>/dev/null || echo "")
88+
MAIN_HEAD=$(git rev-parse "$MAIN_BRANCH" 2>/dev/null || echo "")
89+
90+
if [ -n "$MERGE_BASE" ] && [ -n "$MAIN_HEAD" ] && [ "$MERGE_BASE" != "$MAIN_HEAD" ]; then
91+
echo -e "${YELLOW}💡 This branch may need rebasing on latest '$MAIN_BRANCH'${NC}"
92+
echo -e " Rebase with: git rebase $MAIN_BRANCH"
93+
fi
94+
fi
95+
96+
# Remind about single-commit workflow
97+
COMMIT_COUNT=$(git rev-list --count "${MAIN_BRANCH}..${NEW_BRANCH}" 2>/dev/null || echo "0")
98+
if [ "$COMMIT_COUNT" -gt 1 ]; then
99+
echo -e "${YELLOW}💡 This branch has $COMMIT_COUNT commits${NC}"
100+
echo -e "${YELLOW} Remember to maintain single-commit workflow before pushing${NC}"
101+
echo -e " Squash with: git reset --soft $MAIN_BRANCH && git commit"
102+
fi
103+
echo ""
104+
fi
105+
106+
# Case 3: Creating a new branch (both refs are the same)
107+
if [ "$PREV_HEAD" = "$NEW_HEAD" ] && [ "$PREV_BRANCH" != "$NEW_BRANCH" ]; then
108+
echo ""
109+
echo -e "${GREEN}✓ New branch created: $NEW_BRANCH${NC}"
110+
echo -e "${BLUE}💡 Remember the single-commit workflow:${NC}"
111+
echo -e " 1. Make your changes"
112+
echo -e " 2. Commit once: git commit -m 'feat: description'"
113+
echo -e " 3. Update with: git commit --amend (not new commits)"
114+
echo -e " 4. Push with: git push --force-with-lease"
115+
echo ""
116+
fi
117+
118+
# General reminder for feature branches (not dev)
119+
if [ "$NEW_BRANCH" != "$MAIN_BRANCH" ]; then
120+
# Check if hooks are configured
121+
CURRENT_HOOKS_PATH=$(git config core.hooksPath || echo "")
122+
if [ "$CURRENT_HOOKS_PATH" != ".githooks" ]; then
123+
echo -e "${YELLOW}💡 Tip: Enable git hooks with:${NC}"
124+
echo -e " git config core.hooksPath .githooks"
125+
echo ""
126+
fi
127+
fi
128+
129+
exit 0

.githooks/pre-commit

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# .githooks/pre-commit
3+
# Git hook for opencode contributors to enforce clean commit practices
4+
#
5+
# This hook ensures:
6+
# 1. No direct commits to dev
7+
# 2. Provides guidance on amend workflow
8+
9+
set -e
10+
11+
# Color codes for output
12+
RED='\033[0;31m'
13+
YELLOW='\033[1;33m'
14+
GREEN='\033[0;32m'
15+
BLUE='\033[0;34m'
16+
NC='\033[0m' # No Color
17+
18+
# Configuration
19+
MAIN_BRANCH="dev"
20+
21+
# Get current branch
22+
CURRENT_BRANCH=$(git branch --show-current)
23+
24+
# 1. Block commits to dev
25+
if [ "$CURRENT_BRANCH" = "$MAIN_BRANCH" ]; then
26+
echo -e "${RED}❌ ERROR: Direct commits to '$MAIN_BRANCH' are not allowed!${NC}"
27+
echo ""
28+
echo -e "${YELLOW}The dev branch should only be updated by syncing with upstream.${NC}"
29+
echo -e "${YELLOW}To work on changes:${NC}"
30+
echo -e " 1. Create a feature branch: git checkout -b feat/your-feature"
31+
echo -e " 2. Make your changes"
32+
echo -e " 3. Commit: git commit -m 'feat: your feature description'"
33+
echo -e " 4. Push: git push -u origin feat/your-feature"
34+
exit 1
35+
fi
36+
37+
# 2. Check if this is an amend
38+
if [ -f ".git/COMMIT_EDITMSG" ]; then
39+
# Get the count of commits ahead of dev
40+
COMMIT_COUNT=$(git rev-list --count "${MAIN_BRANCH}..${CURRENT_BRANCH}" 2>/dev/null || echo "0")
41+
42+
# If we have exactly 1 commit and user is making another commit (not amending),
43+
# suggest using amend instead
44+
if [ "$COMMIT_COUNT" -eq 1 ] && [ -z "$GIT_REFLOG_ACTION" ]; then
45+
# Check if this is likely a new commit (not an amend)
46+
# by seeing if the commit message is being edited
47+
if ! git diff --cached --quiet; then
48+
echo -e "${BLUE}[pre-commit] Info: You have 1 commit on this branch${NC}"
49+
echo -e "${YELLOW}💡 Tip: Consider using 'git commit --amend' to update your existing commit${NC}"
50+
echo -e "${YELLOW} This maintains the single-commit-per-branch workflow.${NC}"
51+
echo ""
52+
echo -e "${YELLOW}To amend:${NC}"
53+
echo -e " git add <your-files>"
54+
echo -e " git commit --amend"
55+
echo ""
56+
echo -e "${YELLOW}Proceeding with new commit...${NC}"
57+
# This is just a helpful tip, not blocking
58+
fi
59+
fi
60+
fi
61+
62+
echo -e "${GREEN}✓ Pre-commit checks passed${NC}"
63+
exit 0

0 commit comments

Comments
 (0)