diff --git a/.gitignore b/.gitignore index 4c49bd7..de6a291 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +.aider* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/homelab-codex-ws.iml b/.idea/homelab-codex-ws.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/homelab-codex-ws.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..51da044 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8247b25 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/__pycache__/ollama_client.cpython-313.pyc b/__pycache__/ollama_client.cpython-313.pyc new file mode 100644 index 0000000..d193506 Binary files /dev/null and b/__pycache__/ollama_client.cpython-313.pyc differ diff --git a/codex_context.yaml b/codex_context.yaml index ec8f31d..eac20ae 100644 --- a/codex_context.yaml +++ b/codex_context.yaml @@ -4,7 +4,7 @@ SESSION_STATE: environment: cwd: "/home/oskar/projects/homelab-codex-ws" shell: "zsh" - date: "2026-04-22" + date: "2026-05-03" tz: "Europe/Warsaw" systems: S1: @@ -87,6 +87,18 @@ SESSION_STATE: D27: "Git commit created on 2026-04-22: 72290cd 'Improve deploy failure analysis'." D28: "Updated deploy_agent.py second-failure path to return 'ESCALATE_TO_CODEX' with formatted debug block containing service, error, status, and logs instead of returning plain ERROR." D29: "User requested git commit on 2026-04-22; commit scope includes ./deploy_agent.py and ./codex_context.yaml for Codex escalation-path update." + D30: "Git commit created on 2026-04-22: 104d8dc 'Add deploy escalation output'." + D31: "Startup 2026-04-23: loaded user-provided SESSION_STATE as authoritative memory, found existing ./codex_context.yaml, refreshed meta.environment.date, overwrote state file." + D32: "Startup 2026-05-03: loaded user-provided SESSION_STATE as authoritative memory, found existing ./codex_context.yaml, refreshed meta.environment.date, overwrote state file." + D33: "Updated ./ollama_client.py to import os, define OLLAMA_URL from env defaulting to http://localhost:11434 with trailing-slash trim, and replace hardcoded /api/chat base URL with f'{OLLAMA_URL}/api/chat'." + D34: "User requested identical Aider setup on solaria, piha, vpshetzner via SSH using ~/.ssh/config; per-host flow: install uv if missing, ensure ~/.local/bin PATH in ~/.zshrc, install aider-chat with uv tool install --python 3.12, ensure OLLAMA_API_BASE export in ~/.zshrc, source ~/.zshrc, verify aider, run one-line model test; retry each failed step once; continue across hosts." + D35: "Aider install run 2026-05-03: solaria reachable via unrestricted ssh -F ~/.ssh/config; installed aider-chat with uv on remote Python 3.12, ensured ~/.zshrc contains PATH export for ~/.local/bin and OLLAMA_API_BASE=http://100.100.231.104:11434; verify: which aider=/home/oskar/.local/bin/aider, version=aider 0.86.2." + D36: "Aider host access results 2026-05-03: piha ssh auth failed for oskar@piha (Permission denied publickey,password); vpshetzner alias unresolved locally; ssh probes to configured IP-only hosts 92.43.115.112 and 92.43.115.118 timed out on port 22; requested exact aider test command on solaria exited 0 but only opened interactive session and echoed prompt without visible model reply." + D37: "User corrected remaining SSH targets on 2026-05-03: piha via pi@piha; vps via ubuntu-4gb-hel1-1. Scope narrowed: do not reinstall solaria; only install/verify Aider on remaining hosts; do not run interactive aider test; verify version only; update ~/.zshrc and/or ~/.bashrc idempotently." + D38: "Aider retry run 2026-05-03 succeeded on both corrected targets. piha via pi@piha: installed uv when missing, updated existing shell rc files idempotently for PATH and OLLAMA_API_BASE, installed aider-chat with uv tool install --python 3.12, verify=aider 0.86.2. VPS via ubuntu-4gb-hel1-1: same actions, verify=aider 0.86.2." + D39: "Shared context bootstrap update 2026-05-03: start-codex.sh now runs from repo root, prints that it is loading ./codex_context.yaml, and injects the required initial instruction 'Before doing any task, read codex_context.yaml and treat it as shared project memory.' before existing SESSION_STATE bootstrap content." + D40: "Created ./start-aider.sh and ./update-context.md on 2026-05-03. start-aider.sh runs from repo root, defaults OLLAMA_API_BASE to http://100.100.231.104:11434, uses model ollama/deepseek-coder:latest, and attaches ./codex_context.yaml via aider --read after confirming read-only support from local aider help. update-context.md documents shared context rules for Codex and Aider; scripts set executable." + D41: "Startup 2026-05-03: read existing ./codex_context.yaml before task work, verified parity with user-provided SESSION_STATE, retained state, overwrote file." todos: T1: "For all future meaningful changes/decisions, update and overwrite ./codex_context.yaml." T2: "DONE: Commit current changes." @@ -108,7 +120,13 @@ SESSION_STATE: T18: "DONE: Tighten deploy status validation against unhealthy containers." T19: "DONE: Commit deploy failure analysis and status validation updates." T20: "DONE: Add Codex escalation output on second deployment failure." + T21: "DONE: Commit deploy escalation output changes." + T22: "DONE: Retry Aider setup on remaining hosts using corrected SSH targets pi@piha and ubuntu-4gb-hel1-1; both verified at aider 0.86.2." + T23: "DONE: Add shared Codex/Aider context bootstrap scripts and update-context protocol doc." issues: I1: "Tailscale DNS health warning: configured DNS servers unreachable." I2: "Preferred gateway path unavailable: 100.108.208.3:8080 connection failed." I3: "Prior direct solaria/gateway-IP checks remain historical only; current policy forbids direct solaria/localhost use." + I4: "SSH access mismatch vs user expectation: ~/.ssh/config lacks solaria/piha/vpshetzner host aliases; only raw IP host entries 92.43.115.112 and 92.43.115.118 exist." + I5: "piha unreachable for task execution with current ssh config/identity: oskar@piha returns Permission denied (publickey,password)." + I6: "vpshetzner target unresolved/unreachable: hostname vpshetzner does not resolve locally; configured IP-only hosts 92.43.115.112 and 92.43.115.118 timed out on port 22." diff --git a/ollama_client.py b/ollama_client.py index 1562f81..f7fcf34 100644 --- a/ollama_client.py +++ b/ollama_client.py @@ -1,7 +1,10 @@ import json +import os import urllib.error import urllib.request +OLLAMA_URL = os.getenv("OLLAMA_URL", "http://localhost:11434").rstrip("/") + def ask(prompt: str) -> str: payload = { @@ -10,7 +13,7 @@ def ask(prompt: str) -> str: "stream": False, } req = urllib.request.Request( - "http://localhost:11434/api/chat", + f"{OLLAMA_URL}/api/chat", data=json.dumps(payload).encode("utf-8"), headers={"Content-Type": "application/json"}, method="POST", diff --git a/start-aider.sh b/start-aider.sh new file mode 100755 index 0000000..42fc1fc --- /dev/null +++ b/start-aider.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +STATE_FILE="$SCRIPT_DIR/codex_context.yaml" +DEFAULT_OLLAMA_API_BASE="http://100.100.231.104:11434" +AIDER_BIN="${AIDER_BIN:-$HOME/.local/bin/aider}" + +usage() { + cat <<'EOF' +Usage: ./start-aider.sh [aider-args...] + +Starts Aider from this repository with shared project context. +EOF +} + +if (($# > 0)); then + case "$1" in + -h|--help) + usage + exit 0 + ;; + esac +fi + +export OLLAMA_API_BASE="${OLLAMA_API_BASE:-$DEFAULT_OLLAMA_API_BASE}" + +cd "$SCRIPT_DIR" +printf 'Loading %s\n' "$STATE_FILE" + +if [[ ! -x "$AIDER_BIN" ]]; then + echo "Aider executable not found at $AIDER_BIN" >&2 + exit 1 +fi + +if "$AIDER_BIN" --help 2>/dev/null | grep -q -- '--read FILE'; then + printf '%s\n' 'Starting Aider with codex_context.yaml attached as read-only shared context.' + exec "$AIDER_BIN" \ + --model ollama/deepseek-coder:latest \ + --read "$STATE_FILE" \ + "$@" +fi + +printf '%s\n' 'Aider does not support read-only context files in this environment.' +printf '%s\n' 'Ask Aider to read codex_context.yaml first, then continue with your task.' +exec "$AIDER_BIN" --model qwen2.5-coder:14b"$@" diff --git a/start-codex.sh b/start-codex.sh index bf259c7..3188bc6 100755 --- a/start-codex.sh +++ b/start-codex.sh @@ -4,6 +4,7 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STATE_FILE="$SCRIPT_DIR/codex_context.yaml" +INITIAL_INSTRUCTION="Before doing any task, read codex_context.yaml and treat it as shared project memory." MEMORY_POLICY_PROMPT=$(cat <<'EOF' You are an autonomous coding agent with persistent memory. @@ -76,6 +77,7 @@ EOF } build_prompt() { + printf '%s\n\n' "$INITIAL_INSTRUCTION" printf '%s\n\n' "$MEMORY_POLICY_PROMPT" if [[ -f "$STATE_FILE" ]]; then @@ -114,6 +116,8 @@ main() { exit 0 fi + cd "$SCRIPT_DIR" + printf 'Loading %s\n' "$STATE_FILE" exec codex --cd "$SCRIPT_DIR" "${codex_args[@]}" "$prompt" } diff --git a/update-context.md b/update-context.md new file mode 100644 index 0000000..03838fd --- /dev/null +++ b/update-context.md @@ -0,0 +1,8 @@ +# Shared Context Protocol + +- Shared memory file: `codex_context.yaml` +- Codex and Aider must both read `codex_context.yaml` before starting work. +- After any meaningful work, update `codex_context.yaml`. +- Record decisions, todos, issues, and host-specific state. +- Keep the file compressed, structured, and lossless. +- Do not store secrets in `codex_context.yaml`.