Skip to content

Runtime-core: multi-model tool tolerance, failure guard, rich TUI, subagents, plugins/skills - #101

Closed
gnanam1990 wants to merge 36 commits into
mainfrom
zenline-runtime-work
Closed

gnanam1990 wants to merge 36 commits into
mainfrom
zenline-runtime-work

Conversation

@gnanam1990

@gnanam1990 gnanam1990 commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hardens the Zero Go runtime-core for a diverse multi-model userbase and lands the high-value blueprint features. Scope is the runtime/TUI (internal/agent, internal/tools, internal/zenline, internal/tui, internal/plugins, internal/skills, internal/cli).

Reliability & weak-model tolerance

  • Shared tool-arg tolerance layer (internal/tools/argtolerance.go): every tool accepts the key/shape variants any model emits — path↔file/file_path, content↔contents/text/body, old_string↔old/search, new_string↔new/replace, patch↔diff, pattern↔query/regex, command↔cmd/script, plus list/dir/glob aliases. Type-strictness preserved (a genuinely wrong type still errors).
  • bool/int coercion: boolArg accepts true/false/yes/no/on/off/1/0 (string or number); intArg accepts whole-number strings. Fixes the live overwrite must be a boolean cycling.
  • Repeated-tool-failure guard (internal/agent/guardrails.go): after 2 identical failures the model gets a one-shot corrective hint (tool schema + exact error); after 4 the run halts with a clear message instead of burning turns to maxTurns.

TUI / UX

  • Mouse capture removed so the terminal handles native click / select / copy / paste (it was breaking copy-paste).
  • Full-bleed themed background on home/boot (no terminal-bg "card"; chat status bars unaffected).
  • Rich rendering: assistant text via glamour (CommonMark) + chroma syntax-highlighted code; colored, guttered unified diffs for edit_file/apply_patch. Output cached per (text, theme, width) so RenderChat doesn't re-render every frame.
  • Slash-command autocomplete + interactive model/theme/effort/mode pickers (both skins; existing permission/ask_user/key precedence untouched).

Capabilities

  • Subagents (task tool): spawns an isolated child agent.Run with Depth+1, a registry filtered via Registry.Without("task","ask_user"), inherited sandbox/permission but no interactive callbacks; maxTaskDepth=2.
  • Plugins + skills: optional plugin-manifest metadata (author/license/keywords/interface); new internal/skills package loads */SKILL.md (hand-parsed frontmatter, no YAML dep), a read-only skill tool, and a zero skills command.

Testing

  • go build, go vet, go test ./..., and go test -race ./... all green.
  • End-to-end verified through the real zero exec agent loop (with a mock OpenAI provider, since the live model was quota-limited): weak-model write_file args (text alias + overwrite:"true") accepted and file overwritten; task delegation runs a child and returns; the failure guard halts at exactly 4 identical errors; zero skills/--list-tools/models and themed markdown+diff rendering confirmed.

Dependencies

  • Adds github.com/charmbracelet/glamour + github.com/alecthomas/chroma/v2 for markdown/highlighting. Binary grows to ~22 MB.

Deferred (follow-ups)

  • Async task output/stop, collapsible/typed tool-row interactivity, multi-screen layout, full 4-action permission engine, reasoning-effort propagation to the provider request.

Summary by CodeRabbit

  • New Features

    • Model presets and new --mode exec presets; conversation compaction; session checkpoint & rewind; interactive "ask user" flow; skills discovery and new skills/zenline CLI commands; Zenline TUI skin with themes, autocomplete and pickers; sub-agent/task handling and safer tool execution.
  • Bug Fixes

    • Improved dropped-tool detection/retries, streaming idle-timeout handling, secret redaction, interactive-command blocking, and tool-result metadata (redaction/changed-files) plus pre-tool checkpointing.
  • Documentation

    • Added agent confirmation policy guidance.

KRATOS and others added 17 commits June 6, 2026 21:41
Local development snapshot of one session's intertwined workstreams. Committed together because changes span shared files (provider.go, model.go, loop.go, types.go, streamjson) and can't be cleanly split without interactive hunk staging. Build + vet + full -race suite green.

Zenline TUI skin: Zen home / Statusline chat / permission-modal surfaces, 5 themes (Phosphor/Cyan/Sage/Violet/Mono), boot splash, mouse support, and a headless --snapshot mode (internal/zenline, cli/zenline.go, tui/zenline_view.go).

OpenAI provider: streaming tool-call accumulation hardening plus an idle-timeout watchdog (reader goroutine + context cancel) so a stalled upstream surfaces an error instead of hanging the agent forever.

Agent reliability: update_plan schema makes id optional/auto-numbered with an advertised item schema; malformed (nameless) tool calls feed a retry to the model instead of silently ending the turn; secret scrubbing at the registry boundary (covers agent loop AND MCP); structured ToolResult (changedFiles/display/redacted) surfaced via stream-json.

Session file checkpoints + safe rewind: before-mutation content snapshots (content-addressed, deduped, size-capped, 0600) captured on write/edit/apply_patch in TUI and headless; RestoreToSequence + ApplyRewind (path-traversal-guarded, session-locked); /rewind in TUI and 'zero sessions rewind' headless; stream-json checkpoint/restore events.

Design specs under docs/superpowers/specs/.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…reasoning defaults

Resolve()/ResolveWithFallback()/FallbackFor() + DefaultReasoningEffort/EffectiveReasoningEffort wired into CLI --model and TUI /model (deprecated models auto-redirect with a notice; unknown ids like minimax-m3 pass through unchanged). zero models renders an aligned table; catalog entries decorated with match patterns/default efforts/deprecation rules. Provider reasoning-effort propagation deferred (needs request-schema change). Build/vet/test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…firmation policy

Pre-exec interactive-command detection (editors/pagers/REPLs/ssh/git-rebase-i) hardened against absolute-path, quoted, and $()/backtick-substitution bypasses; destructive-pattern hardening (fork bombs, block-device writes, rm -rf root variants); structured violation annotation on blocked bash; CONFIRMATION_POLICY embedded + appended to the system prompt; 'zero sandbox policy --effective'. Full 4-action permission-engine / 5x3 autonomy matrix deferred. Build/vet/-race green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Stops a run after 3 consecutive empty turns (no text/tool calls) instead of burning to maxTurns; one-shot not-called reminder (by turn 3 if a multi-step task skipped update_plan) and stale reminder (after 10 tool calls since last update_plan). Dropped-call turns excluded from the empty counter. Build/vet/-race green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
New read-only ask_user tool (questions[] with options/multiSelect); the loop intercepts it like permissions and routes to Options.OnAskUser. TUI shows an async questionnaire (buffered channel + ctx.Done select, mirroring the permission flow — no deadlock); headless leaves OnAskUser nil so it degrades gracefully to 'proceed with assumptions'. Build/vet/-race green; 13 new tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Data-driven presets (smart/deep/fast/large/precise) bundling model + reasoning effort + max turns (+ optional tool filter), resolved through the registry. --mode seeds only unset exec options so explicit --model/-r/--max-turns still win; /mode lists/switches in the TUI. Build/vet/test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…g sessions

Proactive compaction at 80% of the model context window + reactive recovery on context-limit errors: summarizes the oldest middle messages into one user-role summary, preserves system + recent suffix. Pure Compact() (injectable Summarizer), low-water-mark guard against churn, suffix walked back to an assistant boundary so no consecutive-user/dangling-tool-result sequences, recover() gated on enabled. Disabled (no-op) when ContextWindow==0 — wired from the resolved model's context window in CLI+TUI. Build/vet/-race green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ask_user: coerce options from objects ({label|value|text|...})/scalars/newline-strings instead of erroring 'options must be an array of strings'; accept bare-string question items and prompt/text/q/title aliases for the question. write_file: read content from contents/text/body/data/file_content aliases (minimax mis-keys 'content'); present-but-non-string still rejected. Same weak-model tolerance already applied to update_plan. Tests added; build/vet/-race green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ively

Removed tea.WithMouseCellMotion() from the zenline program: mouse cell-motion reporting routed clicks to the app and broke the terminal's native text selection + copy (and made paste flaky). The permission modal is keyboard-driven (a/y/d/Esc), so capturing the mouse cost core UX for little gain. Click-to-select, Cmd/Ctrl+C copy, and Cmd/Ctrl+V paste now behave like a normal terminal.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…models

internal/tools/argtolerance.go adds aliasedStringArg (alias-aware, type-strict, primary-key errors) and coerceStringSlice (best-effort list coercion). Every tool now accepts the key variants models emit: read_file/write_file/edit_file path->file/file_path/filename; content->contents/text/body/data; old_string->old/search/find; new_string->new/replace/replacement; apply_patch patch->diff; grep pattern->query/regex/search + path->dir/directory; glob pattern->glob/match/query + cwd->dir/path; list_directory path->directory/dir; bash command->cmd/script/shell. ask_user options/question coercion unified onto the shared helper. Type-strictness preserved (content:42 still errors). Serves the diverse multi-model userbase; build/vet/full-suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
guardState tracks consecutive same-error failures per tool: after 2 identical failures it injects a one-shot corrective hint (the tool's JSON arg schema + the exact error) so the model self-corrects; after 4 it halts the run with a clear message instead of burning turns to maxTurns. A successful call resets that tool's streak; the hint takes priority over plan reminders. Complements the arg-tolerance layer: tolerance prevents most mis-shapes, the guard backstops any that remain (any model, any tool). Build/vet/-race/full-suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…bg card)

Home/boot text used foreground-only styles, so content cells showed the TERMINAL's own background while lipgloss filled the surrounding whitespace with the theme bg — a visible two-tone 'card'. Added newCanvasStyles (foreground + theme background) for the full-bleed surfaces (home + boot), and set the theme bg on the input box and the centered-content wrappers, so the whole screen is one uniform themed background filling the terminal. Chat status bars keep the bg-free styles (they compose inside Panel-colored segments) so they're unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…nce)

boolArg accepts true/false/yes/no/on/off/1/0 (string or number); intArg accepts whole-number strings. Fixes minimax-m3's 'overwrite must be a boolean' and string-number args. Genuinely uncoercible values still error. Completes the arg-tolerance layer alongside string aliases.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…diffs (PRD F4)

Assistant messages now render through glamour (CommonMark + chroma-highlighted fenced code), themed to the active palette and sitting on the full-bleed bg. edit_file/apply_patch results render as colored, guttered unified diffs (green add / red del / dim context, 40-line cap). Rendered markdown is cached per (text,theme,width) with a 512-entry bound so RenderChat (called every spinner tick/keystroke) doesn't re-run glamour each frame. Streaming text stays plain (partial markdown renders badly). Adds glamour v1.0.0 + chroma v2 (offline from cache). Build/vet/-race/full-suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Typing '/' surfaces a filtered, navigable command list (Tab/↑↓ cycle, Enter/Tab complete, Esc dismiss) in both default and zenline skins — purely additive UI state that never disturbs the permission/ask_user/zenline/submit key precedence. Bare /model, /effort, /mode (and /theme in zenline) open an interactive selector overlay that routes the choice through the existing handlers. Build/vet/-race/full-suite green; existing key tests unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
agent.Options gains Provider (auto-injected in Run) + Depth. A 'task' tool is intercepted in executeToolCall (like ask_user): it spawns agent.Run as a child with Depth+1, a registry filtered via new Registry.Without("task","ask_user") (no infinite nesting, no interactive prompts), inherited Sandbox/PermissionMode/Autonomy but all interactive callbacks nil, sharing ctx for cancellation; the child's final answer becomes the tool result. Depth guard (maxTaskDepth=2) refuses deeper nesting with a clear message. Synchronous; async task output/stop deferred. Build/vet/-race/full-suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Plugins: LoadedPlugin gains optional Author/License/Keywords/Homepage/Interface metadata (omitempty, non-breaking, best-effort parse) surfaced in 'zero plugins'. Skills: new internal/skills package loads */SKILL.md (hand-parsed frontmatter, no YAML dep) from ZERO_SKILLS_DIR or the XDG data dir; a read-only 'skill' tool lets the agent load a named skill's content on demand (registered in CoreReadOnlyTools); 'zero skills' lists them (+--json). Build/vet/-race/full-suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: Changes requested

Blockers

  • go test ./... ended with failure.

Validation

  • [pass] Diff hygiene: git diff --check
  • [fail] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 2ee03ac8544a
Changed files (135): .gitignore, go.mod, go.sum, internal/agent/ask_user_test.go, internal/agent/compaction.go, internal/agent/compaction_test.go, internal/agent/confirmation_policy.md, internal/agent/guardrails.go, internal/agent/guardrails_test.go, internal/agent/loop.go, internal/agent/loop_test.go, internal/agent/task_test.go, and 123 more

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link