Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
80d8170
Zenline TUI + runtime-core reliability + session file checkpoints
Jun 6, 2026
30545b4
Slice 3: model registry depth — regex aliases, deprecation fallback, …
Jun 6, 2026
7634c08
Slice 4: sandbox depth — interactive/destructive command safety + con…
Jun 6, 2026
af74523
Slice 5: agent guardrails — no-output guard + plan-enforcement reminders
Jun 6, 2026
4c5fc2f
Slice 6: ask_user tool — agent asks clarifying questions mid-run
Jun 6, 2026
45be88a
Slice 7: agent modes — --mode flag + /mode command presets
Jun 6, 2026
fa7cdef
Slice 8: compaction execution — LLM-driven history compaction for lon…
Jun 6, 2026
1bdbb46
Harden ask_user + write_file arg parsing for weak models (minimax-m3)
Jun 6, 2026
76e6d74
Fix TUI: stop capturing the mouse so click/select/copy/paste work nat…
Jun 6, 2026
4eb8c0f
Add shared model-agnostic tool-arg tolerance layer (aliases) for all …
Jun 6, 2026
2f0c6d5
Add repeated-tool-failure guard so no model loops on a bad tool call
Jun 6, 2026
96f191e
Zenline home/boot: uniform full-bleed themed background (no terminal-…
Jun 6, 2026
a457ea3
Coerce bool/int tool args from string/number forms (weak-model tolera…
Jun 6, 2026
3302518
Zenline rendering tier: markdown + syntax-highlighted code + colored …
Jun 6, 2026
7a5bb7f
Batch 2: slash-command autocomplete + interactive pickers (TUI)
Jun 6, 2026
956f71d
Batch 3: subagents — task tool spawns isolated sub-agent runs (PRD F11)
Jun 6, 2026
29fe8e0
Batch 4: plugin manifest enrichment + skills system (PRD F9/F15)
Jun 6, 2026
634ec18
audit fixes: sandbox + sessions (H2,H3,H4,M5,M6,M7 + lows)
Jun 6, 2026
c2dacc8
audit fixes: mcp + providers + zeroruntime (H6,H9,M4 + lows)
Jun 6, 2026
7a3ccff
audit fixes: zenline render (M8,M9,M10)
Jun 6, 2026
ca39c85
audit fixes: tools (H1,M3 + lows)
Jun 6, 2026
1af7d22
audit fixes: agent loop (M1,M2 + lows)
Jun 6, 2026
a180c32
audit fixes: tui + cli (H5,H7,H8,M11 + lows)
Jun 6, 2026
4bc58e1
audit: document plugin/skills extension wiring as discovery-only (def…
Jun 6, 2026
18108b8
address PR #103 review (CodeRabbit): OnUsage, multi-cancel flush, uns…
Jun 7, 2026
0372f00
address PR #101 review (CodeRabbit): registry validation + test error…
Jun 7, 2026
7c2d184
Merge branch 'zenline-runtime-work' into audit-fixes
Jun 7, 2026
6dec2bf
Remove accidentally-committed shop.html test artifact + gitignore it
Jun 7, 2026
aa43970
Remove accidentally-committed audit doc from the repo (lives in issue…
Jun 7, 2026
0990971
Remove brainstorming process specs from the repo (keep local)
Jun 7, 2026
a9655a6
audit2: sandbox + sessions fixes (2 high, 2 med, 6 low)
Jun 7, 2026
d04c42e
audit2: providers + runtime + zenline fixes (3 med, 7 low)
Jun 7, 2026
4427152
audit2: tools fixes (4 high, 1 med)
Jun 7, 2026
ae5e408
audit2: agent-loop fixes (1 med, 1 low)
Jun 7, 2026
956724e
audit2: tui + mcp + skills fixes (2 med, 3 low)
Jun 7, 2026
2ee03ac
audit2: cli + modelregistry + dead-code cleanup (2 med, rest low)
Jun 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

/zero
/zero.exe

# local launcher with API key — never commit
start-zenline.sh

# user test artifact — never commit
shop.html
docs/audit-2026-06-07-deep-audit.md
docs/superpowers/
26 changes: 18 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
module github.com/Gitlawb/zero

go 1.24.2

toolchain go1.24.13
go 1.25

require (
github.com/charmbracelet/bubbles v1.0.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/charmbracelet/glamour v1.0.0
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834
github.com/charmbracelet/x/ansi v0.11.6
github.com/muesli/termenv v0.16.0
golang.org/x/sys v0.38.0
)

require (
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/colorprofile v0.4.1 // indirect
github.com/charmbracelet/x/ansi v0.11.6 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.9.0 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.3.8 // indirect
github.com/yuin/goldmark v1.7.13 // indirect
github.com/yuin/goldmark-emoji v1.0.6 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
)
45 changes: 41 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.20.0 h1:sfIHpxPyR07/Oylvmcai3X/exDlE8+FA820NTz+9sGw=
github.com/alecthomas/chroma/v2 v2.20.0/go.mod h1:e7tViK0xh/Nf4BYHl00ycY6rV7b8iXBksI9E359yNmA=
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc=
github.com/charmbracelet/bubbles v1.0.0/go.mod h1:9d/Zd5GdnauMI5ivUIVisuEm3ave1XwXtD1ckyV6r3E=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/glamour v1.0.0 h1:AWMLOVFHTsysl4WV8T8QgkQ0s/ZNZo7CiE4WKhk8l08=
github.com/charmbracelet/glamour v1.0.0/go.mod h1:DSdohgOBkMr2ZQNhw4LZxSGpx3SvpeujNoXrQyH2hxo=
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 h1:ZR7e0ro+SZZiIZD7msJyA+NjkCNNavuiPBLgerbOziE=
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834/go.mod h1:aKC/t2arECF6rNOnaKaVU6y4t4ZeHQzqfxedE/VkVhA=
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf h1:rLG0Yb6MQSDKdB52aGX55JT1oi0P0Kuaj7wi1bLUpnI=
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf/go.mod h1:B3UgsnsBZS/eX42BlaNiJkD1pPOUa+oF1IYC6Yd2CEU=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
Expand All @@ -22,31 +38,52 @@ github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfa
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
github.com/yuin/goldmark-emoji v1.0.6 h1:QWfF2FYaXwL74tfGOW5izeiZepUDroDJfWubQI9HTHs=
github.com/yuin/goldmark-emoji v1.0.6/go.mod h1:ukxJDKFpdFb5x0a5HqbdlcKtebh086iJpI31LTKmWuA=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
193 changes: 193 additions & 0 deletions internal/agent/ask_user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package agent

import (
"context"
"errors"
"strings"
"testing"

"github.com/Gitlawb/zero/internal/tools"
"github.com/Gitlawb/zero/internal/zeroruntime"
)

// providerCallingAskUserThenAnswer returns a mock provider whose first turn calls
// the ask_user tool and whose second turn returns a plain-text final answer.
func providerCallingAskUserThenAnswer(arguments string, answer string) *mockProvider {
return &mockProvider{
turns: [][]zeroruntime.StreamEvent{
{
{Type: zeroruntime.StreamEventToolCallStart, ToolCallID: "call-1", ToolName: "ask_user"},
{Type: zeroruntime.StreamEventToolCallDelta, ToolCallID: "call-1", ArgumentsFragment: arguments},
{Type: zeroruntime.StreamEventToolCallEnd, ToolCallID: "call-1"},
{Type: zeroruntime.StreamEventDone},
},
{
{Type: zeroruntime.StreamEventText, Content: answer},
{Type: zeroruntime.StreamEventDone},
},
},
}
}

func registryWithAskUser() *tools.Registry {
registry := tools.NewRegistry()
registry.Register(tools.NewAskUserTool())
return registry
}

func TestRunAskUserReturnsHandlerAnswers(t *testing.T) {
registry := registryWithAskUser()
args := `{"questions":[{"question":"Which framework?","options":["React","Vue"]},{"question":"TypeScript?"}]}`
provider := providerCallingAskUserThenAnswer(args, "thanks")

var requests []AskUserRequest
result, err := Run(context.Background(), "clarify", provider, Options{
Registry: registry,
OnAskUser: func(_ context.Context, request AskUserRequest) (AskUserResponse, error) {
requests = append(requests, request)
return AskUserResponse{Answers: []string{"React", "yes"}}, nil
},
})

if err != nil {
t.Fatal(err)
}
if result.FinalAnswer != "thanks" {
t.Fatalf("expected final answer from second turn, got %q", result.FinalAnswer)
}
if len(requests) != 1 {
t.Fatalf("expected one ask_user request, got %#v", requests)
}
request := requests[0]
if len(request.Questions) != 2 {
t.Fatalf("expected two parsed questions, got %#v", request.Questions)
}
if request.Questions[0].Question != "Which framework?" || len(request.Questions[0].Options) != 2 {
t.Fatalf("unexpected first question: %#v", request.Questions[0])
}
if request.Questions[1].Question != "TypeScript?" {
t.Fatalf("unexpected second question: %#v", request.Questions[1])
}

// The answers must be threaded back to the model as the tool result.
toolMessage := provider.requests[1].Messages[len(provider.requests[1].Messages)-1]
if toolMessage.Role != zeroruntime.MessageRoleTool || toolMessage.ToolCallID != "call-1" {
t.Fatalf("expected tool result message for call-1, got %#v", toolMessage)
}
for _, want := range []string{"Which framework?", "React", "TypeScript?", "yes"} {
if !strings.Contains(toolMessage.Content, want) {
t.Fatalf("expected tool result to contain %q, got %q", want, toolMessage.Content)
}
}
}

func TestRunAskUserWithoutHandlerDegradesGracefully(t *testing.T) {
registry := registryWithAskUser()
args := `{"questions":[{"question":"Which framework?"}]}`
provider := providerCallingAskUserThenAnswer(args, "proceeding with React")

// No OnAskUser handler: the loop must NOT hang, and must hand the model a
// result telling it to proceed with its best assumption.
result, err := Run(context.Background(), "clarify", provider, Options{
Registry: registry,
})

if err != nil {
t.Fatal(err)
}
if result.FinalAnswer != "proceeding with React" {
t.Fatalf("expected loop to continue to a final answer, got %q", result.FinalAnswer)
}
if len(provider.requests) != 2 {
t.Fatalf("expected the loop to continue (2 turns), got %d", len(provider.requests))
}
toolMessage := provider.requests[1].Messages[len(provider.requests[1].Messages)-1]
if toolMessage.ToolCallID != "call-1" {
t.Fatalf("expected tool result for call-1, got %#v", toolMessage)
}
if !strings.Contains(strings.ToLower(toolMessage.Content), "no interactive user") {
t.Fatalf("expected no-interactive-user message, got %q", toolMessage.Content)
}
if !strings.Contains(strings.ToLower(toolMessage.Content), "assumption") {
t.Fatalf("expected guidance to proceed with assumptions, got %q", toolMessage.Content)
}
}

func TestRunAskUserHandlerErrorDegradesGracefully(t *testing.T) {
registry := registryWithAskUser()
args := `{"questions":[{"question":"Which framework?"}]}`
provider := providerCallingAskUserThenAnswer(args, "done")

result, err := Run(context.Background(), "clarify", provider, Options{
Registry: registry,
OnAskUser: func(_ context.Context, _ AskUserRequest) (AskUserResponse, error) {
return AskUserResponse{}, errors.New("user cancelled")
},
})

if err != nil {
t.Fatal(err)
}
if result.FinalAnswer != "done" {
t.Fatalf("expected loop to continue after handler error, got %q", result.FinalAnswer)
}
toolMessage := provider.requests[1].Messages[len(provider.requests[1].Messages)-1]
if !strings.Contains(strings.ToLower(toolMessage.Content), "no interactive user") {
t.Fatalf("expected graceful degradation message after handler error, got %q", toolMessage.Content)
}
}

func TestRunAskUserRedactsSecretsInAnswers(t *testing.T) {
registry := registryWithAskUser()
secret := "sk-ant-api03-ABCDEFGHIJKLMNOP1234567890"
args := `{"questions":[{"question":"Paste your key"}]}`
provider := providerCallingAskUserThenAnswer(args, "done")

var captured ToolResult
_, err := Run(context.Background(), "clarify", provider, Options{
Registry: registry,
OnToolResult: func(r ToolResult) { captured = r },
OnAskUser: func(_ context.Context, _ AskUserRequest) (AskUserResponse, error) {
return AskUserResponse{Answers: []string{"my key is " + secret}}, nil
},
})
if err != nil {
t.Fatal(err)
}
if strings.Contains(captured.Output, secret) {
t.Fatalf("secret leaked into ask_user tool result: %q", captured.Output)
}
if !captured.Redacted {
t.Error("expected Redacted=true when a secret was scrubbed from an ask_user answer")
}
// The redacted answer must also not reach the model.
for _, m := range provider.requests[1].Messages {
if strings.Contains(m.Content, secret) {
t.Fatalf("secret leaked into model message: %q", m.Content)
}
}
}

func TestRunAskUserRejectsMissingQuestions(t *testing.T) {
registry := registryWithAskUser()
provider := providerCallingAskUserThenAnswer(`{"questions":[]}`, "done")

result, err := Run(context.Background(), "clarify", provider, Options{
Registry: registry,
OnAskUser: func(_ context.Context, _ AskUserRequest) (AskUserResponse, error) {
t.Fatal("handler should not be invoked when questions are missing")
return AskUserResponse{}, nil
},
})

if err != nil {
t.Fatal(err)
}
if result.FinalAnswer != "done" {
t.Fatalf("expected loop to continue, got %q", result.FinalAnswer)
}
toolMessage := provider.requests[1].Messages[len(provider.requests[1].Messages)-1]
if !strings.Contains(strings.ToLower(toolMessage.Content), "at least one question") {
t.Fatalf("expected invalid-arguments message, got %q", toolMessage.Content)
}
}
Loading
Loading