Skip to content

Commit b044d03

Browse files
author
bjohns
committed
feat: create .tinycode/ dirs on startup, add tc-doctor skill to container config
1 parent 2214e0a commit b044d03

2 files changed

Lines changed: 194 additions & 0 deletions

File tree

config/skills/tc-doctor/SKILL.md

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
name: tc-doctor
3+
description: Diagnose and fix tinycode environment issues — missing directories, agents, skills, config, connectivity, and container health
4+
---
5+
6+
# tc-doctor
7+
8+
Self-diagnostic skill that checks the tinycode environment is correctly configured and fixes problems it finds.
9+
10+
## When to use
11+
12+
- The user says "doctor", "tc-doctor", "health check", "fix my setup", "why isn't X working"
13+
- After a fresh deployment or container restart
14+
- When agents, skills, or tools aren't appearing
15+
- When tmux/swarm/terminal features aren't working
16+
- When the model connection is failing
17+
18+
## When NOT to use
19+
20+
- The user is asking about their own application code
21+
- The user wants to configure a new provider (use /mcp-setup or /customize-tinycode instead)
22+
23+
## Checks to run (in order)
24+
25+
### 1. Directory structure
26+
Verify these directories exist and are writable. Create any that are missing:
27+
28+
```bash
29+
# Project-level tinycode directory
30+
mkdir -p .tinycode 2>/dev/null && echo "✓ .tinycode/" || echo "✗ .tinycode/ — not writable"
31+
32+
# Required subdirectories
33+
for dir in .tinycode/plans .tinycode/state .tinycode/swarm; do
34+
mkdir -p "$dir" 2>/dev/null && echo "$dir" || echo "$dir — not writable"
35+
done
36+
37+
# Config directory (may be PVC-mounted)
38+
ls ~/.config/tinycode/ >/dev/null 2>&1 && echo "✓ ~/.config/tinycode/" || echo "✗ ~/.config/tinycode/ — missing"
39+
40+
# Data directory
41+
ls ~/.local/share/tinycode/ >/dev/null 2>&1 && echo "✓ ~/.local/share/tinycode/" || echo "✗ ~/.local/share/tinycode/ — missing"
42+
```
43+
44+
### 2. Agents
45+
Check that bundled agents are loaded:
46+
47+
```bash
48+
# Count agent files in config
49+
AGENT_COUNT=$(ls ~/.config/tinycode/agent/*.md 2>/dev/null | wc -l)
50+
echo "Agent files: $AGENT_COUNT"
51+
if [ "$AGENT_COUNT" -lt 20 ]; then
52+
echo "✗ Expected 20+ agent files. Check /opt/tinycode-defaults/agent/ and entrypoint.sh"
53+
# Attempt fix
54+
if [ -d /opt/tinycode-defaults/agent ]; then
55+
mkdir -p ~/.config/tinycode/agent
56+
cp -n /opt/tinycode-defaults/agent/*.md ~/.config/tinycode/agent/ 2>/dev/null
57+
echo " → Copied bundled agents. Restart tinycode to pick them up."
58+
fi
59+
else
60+
echo "✓ Agents loaded"
61+
fi
62+
```
63+
64+
### 3. Skills
65+
Check that bundled skills are loaded:
66+
67+
```bash
68+
SKILL_COUNT=$(find ~/.config/tinycode/skills -name "SKILL.md" 2>/dev/null | wc -l)
69+
echo "Skill files: $SKILL_COUNT"
70+
if [ "$SKILL_COUNT" -lt 5 ]; then
71+
echo "✗ Expected 5+ skill files. Check /opt/tinycode-defaults/skills/"
72+
if [ -d /opt/tinycode-defaults/skills ]; then
73+
for skill_dir in /opt/tinycode-defaults/skills/*/; do
74+
skill_name=$(basename "$skill_dir")
75+
mkdir -p ~/.config/tinycode/skills/$skill_name
76+
cp -n "$skill_dir"SKILL.md ~/.config/tinycode/skills/$skill_name/ 2>/dev/null
77+
done
78+
echo " → Copied bundled skills. Restart tinycode to pick them up."
79+
fi
80+
else
81+
echo "✓ Skills loaded"
82+
fi
83+
```
84+
85+
### 4. Tools availability
86+
Check that required system tools are present:
87+
88+
```bash
89+
for tool in tmux curl tar gzip git; do
90+
if command -v $tool >/dev/null 2>&1; then
91+
echo "$tool: $(command -v $tool)"
92+
else
93+
echo "$tool: NOT FOUND"
94+
fi
95+
done
96+
```
97+
98+
### 5. oc CLI (if cluster-admin mode)
99+
```bash
100+
if [ "${TINYCODE_CLUSTER_ADMIN}" = "true" ] || [ -f ~/.kube/config ]; then
101+
if command -v oc >/dev/null 2>&1; then
102+
echo "✓ oc: $(oc version --client 2>/dev/null | head -1)"
103+
oc whoami 2>/dev/null && echo "✓ Cluster auth valid" || echo "✗ Cluster auth failed — kubeconfig may be expired"
104+
else
105+
echo "✗ oc: NOT FOUND — cluster-admin mode requires oc CLI"
106+
fi
107+
fi
108+
```
109+
110+
### 6. Model connectivity
111+
Check if the configured model responds:
112+
113+
```bash
114+
# Check if any provider is connected
115+
curl -sf http://localhost:4096/provider 2>/dev/null | python3 -c "
116+
import sys, json
117+
try:
118+
providers = json.load(sys.stdin)
119+
connected = [p['id'] for p in providers if any(m.get('status') == 'active' for m in p.get('models', {}).values())]
120+
if connected:
121+
print(f'✓ Connected providers: {connected}')
122+
else:
123+
print('✗ No connected providers — check model configuration')
124+
except:
125+
print('✗ Could not query provider status')
126+
" 2>/dev/null || echo "✗ tinycode API not responding on localhost:4096"
127+
```
128+
129+
### 7. tmux / swarm readiness
130+
```bash
131+
if command -v tmux >/dev/null 2>&1; then
132+
echo "✓ tmux available: $(tmux -V)"
133+
# Test tmux can create a session
134+
if tmux new-session -d -s tc-doctor-test 2>/dev/null; then
135+
tmux kill-session -t tc-doctor-test 2>/dev/null
136+
echo "✓ tmux sessions work"
137+
else
138+
echo "✗ tmux cannot create sessions — check /tmp permissions and terminal settings"
139+
fi
140+
else
141+
echo "✗ tmux not installed — /swarm skill will not work"
142+
fi
143+
```
144+
145+
### 8. Disk space
146+
```bash
147+
df -h / /home/tinycode/.local/share/tinycode 2>/dev/null | tail -n +2 | while read fs size used avail pct mount; do
148+
pct_num=${pct%\%}
149+
if [ "$pct_num" -gt 90 ]; then
150+
echo "$mount: ${pct} used ($avail free) — LOW DISK SPACE"
151+
else
152+
echo "$mount: ${pct} used ($avail free)"
153+
fi
154+
done
155+
```
156+
157+
## Output format
158+
159+
```
160+
## tinycode Doctor Report
161+
162+
### Environment
163+
- Container: [yes/no]
164+
- Working directory: [path]
165+
- User: [uid]
166+
167+
### Checks
168+
[results from each check above]
169+
170+
### Issues Found
171+
- [list of ✗ items]
172+
173+
### Fixes Applied
174+
- [list of automatic fixes taken]
175+
176+
### Manual Actions Needed
177+
- [anything that couldn't be auto-fixed]
178+
```
179+
180+
## Important
181+
182+
- Run ALL checks, even if early ones fail
183+
- Apply fixes automatically where safe (directory creation, file copying)
184+
- Do NOT modify user config files (tinycode.json, tinycode.jsonc)
185+
- Do NOT restart tinycode — tell the user to restart if needed
186+
- Report everything found, even if all checks pass

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ cat > "$DEFAULTS_FILE" << 'EOF'
1919
}
2020
EOF
2121

22+
# ── Create required directories ───────────────────────────────────────────────
23+
# tinycode expects these directories to exist. The PVC provides ~/.config/tinycode/
24+
# but the project-level .tinycode/ must be created in the working directory.
25+
# /projects is where user workspaces live; /home/tinycode is the fallback.
26+
WORKDIR="${TINYCODE_WORKDIR:-/projects}"
27+
mkdir -p "$WORKDIR/.tinycode" 2>/dev/null || mkdir -p /home/tinycode/.tinycode 2>/dev/null || true
28+
mkdir -p /tmp/tinycode 2>/dev/null || true
29+
2230
# Copy bundled agents and skills into the PVC-mounted config directory.
2331
# The PVC shadows /home/tinycode/.config/tinycode so files COPY'd into the image
2432
# at build time are hidden. This copies from a staging path (/opt/tinycode-defaults/)

0 commit comments

Comments
 (0)