Phase 1 of plans/autonomous-survival-bot-prd.md. The bot must always be able to answer "what am I doing and why am I not doing more?" without parsing the log stream. New modules: - runtime/state.js: pure FSM classifier emitting emergency / working / recovering / planning / social / idle from snapshot + reflex context. - runtime/no-progress.js: sliding-window detector that watches position and inventory; when both are unchanged for 60 s+, emits one stable reason code from REASONS (waiting_for_day, night_hostile_nearby, no_food_source, inventory_full, no_reachable_target, planner_empty, awaiting_action_cooldown). - runtime/viewer.js: optional prismarine-viewer launcher behind VIEWER_PORT. Lazy import so the dep is not required by default. Wiring: - runtime/bot.js: tick() now computes runtimeState + noProgressReason every tick and stamps them on the snapshot along with activeSkill, currentMilestone (read from plan.md, cached 30 s), lastResult, failuresByCode and lastEscalation. - runtime/bot.js: dispatchAction records lastResult and lastFailureAt for the recovering-state classifier. - runtime/planner.js: exports isPlannerBusy(), readNextMilestone() and planExists() so the runtime can show planning state + current milestone without spawning extra Pi calls. - runtime/config.js: adds VIEWER_PORT support. TUI: - tui/tui.tsx: StatusBar gains a state badge, current-skill row, milestone row, no-progress reason warning, last-result line with ok/fail color, failures-by-class summary and last-escalation age. Co-authored-by: Yuriy Mayatnikov <mayatnikov@me.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
63 lines
2.2 KiB
JavaScript
63 lines
2.2 KiB
JavaScript
import { config as loadDotenv } from "dotenv";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
export const REPO_ROOT = path.resolve(__dirname, "..");
|
|
|
|
loadDotenv({ path: path.join(REPO_ROOT, ".env") });
|
|
|
|
function req(name) {
|
|
const v = process.env[name]?.trim();
|
|
if (!v) throw new Error(`Missing required env var: ${name}`);
|
|
return v;
|
|
}
|
|
|
|
function opt(name, fallback = "") {
|
|
return process.env[name]?.trim() || fallback;
|
|
}
|
|
|
|
const host = req("MC_HOST");
|
|
const port = Number.parseInt(opt("MC_PORT", "25565"), 10);
|
|
const username = req("MC_USERNAME");
|
|
|
|
// MC_VERSION: "auto" (or empty) lets mineflayer auto-detect from the server
|
|
// handshake — the right default per the survival-bot PRD (no hard-coded modern
|
|
// version unless the server requires pinning). Mineflayer accepts `false` to
|
|
// auto-detect, so we translate "auto" into false at the boundary; the original
|
|
// string is preserved for logging.
|
|
const rawVersion = opt("MC_VERSION", "auto");
|
|
const mineflayerVersion = rawVersion.toLowerCase() === "auto" ? false : rawVersion;
|
|
|
|
export const config = Object.freeze({
|
|
host,
|
|
port,
|
|
username,
|
|
version: rawVersion,
|
|
mineflayerVersion,
|
|
authMode: opt("MC_AUTH_MODE", "offline"),
|
|
authmePassword: opt("MC_AUTHME_PASSWORD", ""),
|
|
operators: opt("OPERATOR_USERNAMES", "")
|
|
.split(",")
|
|
.map((s) => s.trim().toLowerCase())
|
|
.filter(Boolean),
|
|
tickIntervalMs: Math.max(1, Number.parseInt(opt("TICK_INTERVAL_SECONDS", "3"), 10)) * 1000,
|
|
chatRateLimitPerMin: Number.parseInt(opt("CHAT_RATE_LIMIT_PER_MIN", "15"), 10),
|
|
// Optional prismarine-viewer port for local visual debugging. 0/empty = off.
|
|
viewerPort: (() => {
|
|
const v = Number.parseInt(opt("VIEWER_PORT", "0"), 10);
|
|
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
})(),
|
|
});
|
|
|
|
export const serverKey = `${host}_${port}`;
|
|
export const stateDir = path.join(REPO_ROOT, "state", serverKey);
|
|
export const socketPath = path.join(stateDir, "bot.sock");
|
|
|
|
// Redacted env view for logs — never include the AuthMe password.
|
|
export function redactedConfig() {
|
|
const { authmePassword, ...rest } = config;
|
|
return { ...rest, authmePassword: authmePassword ? "***" : "(unset)" };
|
|
}
|