slaude Docs

Field notes

2026-05-13 — fallback ctx, table emphasis, metrics, stop-guard

  • SLAUDE_FALLBACK_CONTEXT_WINDOW env override added for the TokenBudget fallback used when SDK result.modelUsage is empty. Default still 200000; set e.g. 1000000 for 1M-ctx models. TokenBudget constructor accepts { fallbackContextWindow }; manager wires env.tokenFallbackContextWindow().
  • Slack code-block table cells now strip markdown emphasis (**bold**, __bold__, *italic*, _italic_, ~~strike~~) before width calc + render. Reason: code blocks render verbatim — markers would show literal. Definition-list branch untouched (mrkdwn renders normally there).
  • Prometheus /metrics endpoint shipped on the existing health-server port. Hand-rendered text format in src/metrics.ts — no prom-client dep. Singleton metrics Registry plus pre-declared metric handles (m.sessionsLive, m.turnsTotal{result}, m.toolCallsTotal{tool}, m.tokensTotal{kind}, m.contextWindowPct, m.stopGuardBlockedTotal, m.stopGuardFailedTotal, m.errorsTotal{kind}, m.slackDropsTotal{reason}, m.userTurnsTotal{user_id,user_name}). Static labels (SLAUDE_METRICS_LABELS="agent=hermes,env=prod,team=ai") applied to every series at render time. Per-user counter is opt-in via SLAUDE_METRICS_PER_USER=1 because user-id cardinality blows up in public channels. metrics.ts imports config/env for dotenv side-effect so ~/.slaude/.env lands before label parsing at module init.
  • "No reply emitted" fallback retired in favor of true enforcement via SDK Stop hook. New setStopGuard(fn) on AgentManager mirrors setPermissionResolver / setMcpResolver. Adapter installs a guard that returns null when route.spoke === true and an instruction string ("call mcp__slaude_slack__reply now") when false. Manager's Stop hook returns {decision: "block", reason} to make the SDK feed the instruction back to the agent, which continues the turn. Single-shot per turn: #stopBlocked: Set<sessionId> cleared on user message + session teardown. If agent stops a second time without spoke, manager logs [stop-guard] … blocked once but agent still stopping to stderr and lets the stop through — no Slack notice (drift surfaces in logs, not chat). Auto-evolve safe because route.spoke carries over from the prior user-visible turn that satisfied the contract.