Prepare LinaAI project memory

This commit is contained in:
2026-05-24 07:54:37 +00:00
parent 2d3e0454cd
commit 90c15fdf84
7 changed files with 430 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cd "$ROOT"
CACHE_DIR="${LINAAI_KNOWLEDGE_DIR:-Saved/LinaAIKnowledge}"
OUT="${CACHE_DIR}/context.md"
mkdir -p "$CACHE_DIR"
: > "$OUT"
printf '# LinaAI Bootstrap Context\n\n' >> "$OUT"
printf 'Generated: %s\n\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$OUT"
printf 'This is a compact, local-only context pack built from tracked project docs. It intentionally excludes raw secrets.\n\n' >> "$OUT"
include_doc() {
local doc="$1"
local lines="${2:-120}"
if [[ -f "$doc" ]]; then
printf '\n---\n\n## %s\n\n' "$doc" >> "$OUT"
sed -n "1,${lines}p" "$doc" >> "$OUT"
printf '\n' >> "$OUT"
else
printf '\n---\n\n## Missing: %s\n\n' "$doc" >> "$OUT"
fi
}
include_doc "Docs/AI/LinaAIOperatingManual.md" 220
include_doc "Docs/AI/LocalAgentGuardrails.md" 180
include_doc "Docs/AI/LinaAISecretsPolicy.md" 180
include_doc "Docs/AI/LinaAIKnowledgeMap.md" 220
include_doc "Docs/Ops/HANDOFF.md" 220
include_doc "AGRARIAN_DEVELOPMENT_ROADMAP.md" 260
include_doc "Docs/CoreDesignDocument.md" 160
include_doc "Docs/TechnicalDesignDocument.md" 160
include_doc "Docs/SixMonthMvpDefinition.md" 160
include_doc "Docs/Investor/InvestorDemoAcceptanceGate.md" 160
printf 'LinaAI bootstrap context written: %s\n' "$OUT"
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cd "$ROOT"
CACHE_DIR="${LINAAI_KNOWLEDGE_DIR:-Saved/LinaAIKnowledge}"
RAW_DIR="${CACHE_DIR}/vendor/raw"
INTERNAL_DIR="${CACHE_DIR}/internal"
INDEX="${CACHE_DIR}/INDEX.md"
mkdir -p "$RAW_DIR" "$INTERNAL_DIR"
write_line() {
printf '%s\n' "$1" >> "$INDEX"
}
: > "$INDEX"
write_line "# LinaAI Knowledge Cache"
write_line ""
write_line "Generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
write_line ""
write_line "This directory is ignored by Git. It is a local retrieval/cache area for LinaAI."
write_line "Do not place raw credentials here."
write_line ""
write_line "## Tracked Project Memory"
write_line ""
project_docs=(
"Docs/AI/LinaAIOperatingManual.md"
"Docs/AI/LocalAgentGuardrails.md"
"Docs/AI/LinaAISecretsPolicy.md"
"Docs/AI/LinaAIKnowledgeMap.md"
"Docs/Ops/HANDOFF.md"
"AGRARIAN_DEVELOPMENT_ROADMAP.md"
"Docs/CoreDesignDocument.md"
"Docs/TechnicalDesignDocument.md"
"Docs/SixMonthMvpDefinition.md"
"Docs/MvpSurvivalReadinessCriteria.md"
"Docs/Investor/InvestorDemoAcceptanceGate.md"
"Docs/Art/AgrarianAssetPipeline.md"
"Docs/Terrain/GroundZeroTile.md"
"Docs/World/BiomeAndNaturalResourceGenerationPlan.md"
"Docs/EconomyAndAgrDesignDocument.md"
"Docs/MultiplayerNetworkingDesign.md"
"Docs/PersistenceDesignDocument.md"
)
for doc in "${project_docs[@]}"; do
if [[ -f "$doc" ]]; then
safe_name="$(printf '%s' "$doc" | tr '/ ' '__')"
{
printf '# %s\n\n' "$doc"
grep -E '^(#|##|###) ' "$doc" 2>/dev/null || true
} > "${INTERNAL_DIR}/${safe_name}.headings.md"
write_line "- ${doc} -> ${INTERNAL_DIR}/${safe_name}.headings.md"
else
write_line "- missing: ${doc}"
fi
done
write_line ""
write_line "## Official Vendor Docs"
write_line ""
fetch_doc() {
local name="$1"
local url="$2"
local out="${RAW_DIR}/${name}.html"
if curl -L --fail --retry 2 --connect-timeout 10 --max-time 45 -o "$out" "$url"; then
write_line "- ${name}: ${url} -> ${out}"
else
write_line "- ${name}: ${url} -> fetch failed"
rm -f "$out"
fi
}
fetch_doc "unraid" "https://docs.unraid.net/"
fetch_doc "unreal-engine-5-7" "https://dev.epicgames.com/documentation/en-us/unreal-engine"
fetch_doc "laravel-12" "https://laravel.com/docs/12.x"
fetch_doc "mysql-8-4" "https://dev.mysql.com/doc/refman/8.4/en/"
fetch_doc "gitea" "https://docs.gitea.com/"
fetch_doc "ollama" "https://docs.ollama.com/"
fetch_doc "open-webui" "https://docs.openwebui.com/"
fetch_doc "aider" "https://aider.chat/docs/"
write_line ""
write_line "## Usage"
write_line ""
write_line "- Use this index as evidence that project/vendor docs were refreshed."
write_line "- Use tracked docs as the source of truth for project policy."
write_line "- Treat fetched vendor docs as reference material; verify details before risky edits."
printf 'LinaAI knowledge cache refreshed: %s\n' "$INDEX"
+28 -4
View File
@@ -87,13 +87,27 @@ repo_evidence="$(
test -d Scripts && echo "Scripts/"
test -d Docs && echo "Docs/"
echo "script_samples:"
find Scripts -maxdepth 1 -type f -printf "%f\n" 2>/dev/null | sort | head -40
find Scripts -maxdepth 1 -type f -printf "%f\n" 2>/dev/null | sort | head -25
echo "doc_samples:"
find Docs -maxdepth 2 -type f -printf "%p\n" 2>/dev/null | sort | head -40
find Docs -maxdepth 2 -type f -printf "%p\n" 2>/dev/null | sort | head -25
echo "linaai_required_docs:"
for doc in \
Docs/AI/LinaAIOperatingManual.md \
Docs/AI/LocalAgentGuardrails.md \
Docs/AI/LinaAISecretsPolicy.md \
Docs/AI/LinaAIKnowledgeMap.md \
Docs/Ops/HANDOFF.md \
AGRARIAN_DEVELOPMENT_ROADMAP.md
do
test -f "$doc" && echo "$doc"
done
echo "linaai_cache:"
test -f Saved/LinaAIKnowledge/INDEX.md && echo "Saved/LinaAIKnowledge/INDEX.md"
test -f Saved/LinaAIKnowledge/context.md && echo "Saved/LinaAIKnowledge/context.md"
} | sed 's/"/'\''/g'
)"
system_prompt='You are LinaAI, a supervised local coding assistant for Agrarian. You must not pretend certainty. Classify task risk and confidence before any edits. Confidence must be based on concrete evidence. If you lack evidence, confidence must be below 0.65. High-risk areas include Unreal core architecture, save/load, multiplayer, networking/replication, AGR wallet/payments, marketplace/economy transfer logic, auth, security, migrations, deployment secrets, and broad refactors. Return JSON only.'
system_prompt='You are LinaAI, a supervised local coding assistant for Agrarian. Follow Docs/AI/LinaAIOperatingManual.md, Docs/AI/LocalAgentGuardrails.md, Docs/AI/LinaAISecretsPolicy.md, and Docs/AI/LinaAIKnowledgeMap.md when present. You must not pretend certainty. Classify task risk and confidence before any edits. Confidence must be based on concrete evidence. If you lack evidence, confidence must be below 0.65. Do not include raw secrets in prompts, docs, logs, or commits. High-risk areas include Unreal core architecture, save/load, multiplayer, networking/replication, AGR wallet/payments, marketplace/economy transfer logic, auth, security, migrations, deployment secrets, and broad refactors. Return JSON only.'
user_prompt=$(cat <<EOF
Task:
@@ -123,13 +137,18 @@ print(json.dumps({
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
],
"options": {
"num_ctx": 4096,
"num_predict": 220,
"temperature": 0.1
},
"stream": False,
}))
PY
)"
echo "LinaAI preflight with ${MODEL}..."
response="$(curl -fsS "${OLLAMA_URL}/api/chat" -H "Content-Type: application/json" -d "$payload")"
response="$(curl -fsS --max-time "${LINAAI_PREFLIGHT_TIMEOUT:-120}" "${OLLAMA_URL}/api/chat" -H "Content-Type: application/json" -d "$payload")"
content="$(printf '%s' "$response" | python3 -c 'import json,sys; print(json.load(sys.stdin)["message"]["content"])')"
python3 - "$content" "$PREFLIGHT_JSON" <<'PY'
@@ -238,6 +257,11 @@ if [[ "$should_escalate" -eq 1 ]]; then
exec Scripts/ai_codex_escalate.sh "$STATUS_JSON"
fi
if [[ -x Scripts/linaai_bootstrap_context.sh && ! -f Saved/LinaAIKnowledge/context.md ]]; then
echo "Building LinaAI bootstrap context..."
Scripts/linaai_bootstrap_context.sh >/dev/null || true
fi
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "Dry run: would run Aider locally."
exit 0