v0.36.0 9897fd7

systemprompt_test.go RawHistoryFolder

1package agent
2
3import (
4	"strings"
5	"testing"
6	"time"
7)
8
9func TestBuildSystemPromptAlwaysIncludesFinalWritingGuidance(t *testing.T) {
10	for _, tt := range []struct {
11		name   string
12		custom string
13	}{
14		{name: "default"},
15		{name: "custom", custom: "custom identity"},
16	} {
17		t.Run(tt.name, func(t *testing.T) {
18			const conflictingAddendum = "Always use ceremonial language."
19			prompt := BuildSystemPrompt(SystemPromptOpts{
20				Custom: tt.custom,
21				Append: []string{conflictingAddendum},
22			})
23
24			if count := strings.Count(prompt, writingGuidance); count != 1 {
25				t.Fatalf("writing guidance count = %d, want 1:\n%s", count, prompt)
26			}
27			if strings.Index(prompt, writingGuidance) < strings.Index(prompt, conflictingAddendum) {
28				t.Fatalf("writing guidance must follow appended context:\n%s", prompt)
29			}
30			for _, want := range []string{
31				"medium, audience, and reader's immediate need",
32				"plain, precise language",
33				"Default to concise paragraphs",
34				"Use lists when items are genuinely parallel, sequential, or easier to compare",
35				"canned transitions",
36				"verified facts",
37				"descriptive links, and accessibility",
38				"Do not manufacture slang, errors, hesitation",
39				"Revise silently",
40			} {
41				if !strings.Contains(prompt, want) {
42					t.Errorf("writing guidance missing %q:\n%s", want, prompt)
43				}
44			}
45		})
46	}
47}
48
49func TestBuildSystemPromptAlwaysIncludesTaskAndSkillGuidance(t *testing.T) {
50	for _, custom := range []string{"", "Custom identity"} {
51		t.Run(custom, func(t *testing.T) {
52			prompt := BuildSystemPrompt(SystemPromptOpts{
53				Custom: custom,
54				Append: []string{"Workspace context", "Available skills"},
55			})
56			previous := strings.Index(prompt, "Available skills")
57			for _, guidance := range []string{taskExecutionGuidance, skillPriorityGuidance, writingGuidance} {
58				index := strings.Index(prompt, guidance)
59				if index <= previous {
60					t.Fatalf("shared guidance must follow appended context in task/skill/writing order")
61				}
62				previous = index
63			}
64			for _, want := range []string{
65				"Treat requests such as \"can you\" as instructions to do the requested work",
66				"do not stop at a plan or an offer to continue",
67				"Follow each progress statement with the action it describes",
68				"Final answers contain the result of the work or a concrete blocker",
69				"Respect requests for explanation, planning, or review without making unsolicited changes",
70				"Ask only when a necessary decision blocks safe, correct progress",
71				"Preserve tool permissions, required confirmations, and explicit approval requirements",
72				"Explicit user instructions take precedence over skill guidelines",
73				"Skills do not grant permissions or override system or developer constraints",
74				"identify its source and the relevant instruction",
75			} {
76				if count := strings.Count(prompt, want); count != 1 {
77					t.Errorf("guidance %q count = %d, want 1", want, count)
78				}
79			}
80		})
81	}
82}
83
84func TestBuildSystemPromptAddsCompactionHandoffToCustomPrompt(t *testing.T) {
85	prompt := BuildSystemPrompt(SystemPromptOpts{Custom: "custom identity"})
86	if !strings.Contains(prompt, "custom identity") {
87		t.Fatalf("custom prompt missing:\n%s", prompt)
88	}
89	if !strings.Contains(prompt, compactedSummaryHandoffInstruction) {
90		t.Fatalf("custom prompt missing compaction handoff:\n%s", prompt)
91	}
92	if count := strings.Count(prompt, compactedSummaryHandoffInstruction); count != 1 {
93		t.Fatalf("compaction handoff count = %d, want 1:\n%s", count, prompt)
94	}
95	for _, want := range []string{"most recent unresolved user request", "newer user request", "without waiting for the user to type \"continue\""} {
96		if !strings.Contains(prompt, want) {
97			t.Fatalf("compaction handoff missing %q:\n%s", want, prompt)
98		}
99	}
100}
101
102func TestBuildSystemPromptCustomOmitsBuiltInDocs(t *testing.T) {
103	got := BuildSystemPrompt(SystemPromptOpts{
104		CWD:        "/workspace",
105		Custom:     "Custom instructions",
106		Append:     []string{"Additional context"},
107		Now:        time.Date(2026, time.August, 6, 0, 0, 0, 0, time.UTC),
108		ZutDocsDir: "/zut/docs",
109	})
110
111	if strings.Contains(got, "Zut's own docs") || strings.Contains(got, "/zut/docs") {
112		t.Fatalf("custom prompt includes built-in docs guidance:\n%s", got)
113	}
114	for _, want := range []string{
115		"Custom instructions",
116		"Additional context",
117		"Current date: 2026-08-06",
118		"Current working directory: /workspace",
119	} {
120		if !strings.Contains(got, want) {
121			t.Errorf("custom prompt missing %q:\n%s", want, got)
122		}
123	}
124}
125
126func TestBuildSystemPromptDefaultIncludesBuiltInDocs(t *testing.T) {
127	got := BuildSystemPrompt(SystemPromptOpts{
128		CWD:        "/workspace",
129		Now:        time.Date(2026, time.August, 6, 0, 0, 0, 0, time.UTC),
130		ZutDocsDir: "/zut/docs",
131	})
132
133	if !strings.Contains(got, "Zut's own docs are installed under /zut/docs") {
134		t.Fatalf("default prompt missing built-in docs guidance:\n%s", got)
135	}
136}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close