Debian Codegraph @

doc/clnkr.3.md

raw
1 % clnkr(3) Library Functions Manual
2
3 # NAME
4
5 clnkr - Go package for embedding the clnkr agent loop
6
7 # SYNOPSIS
8
9 ```go
10 import "github.com/clnkr-ai/clnkr"
11
12 agent := clnkr.NewAgent(model, executor, cwd)
13 err := agent.Run(ctx, "inspect the repository")
14 ```
15
16 # DESCRIPTION
17
18 Package **clnkr** exposes the agent loop used by **clnkr**(1). It is the
19 public Go import surface for callers that want to embed clnkr in another
20 frontend, test harness, or orchestration process.
21
22 The package is a loop kernel, not a full provider SDK. Provider adapters live
23 under **internal/** and are not importable. External callers provide a
24 **Model** implementation that returns clnkr turns, and an **Executor**
25 implementation that runs commands and returns structured command results.
26
27 Use **Agent.Run** for unattended execution. Use **Agent.RunWithPolicy** when a
28 frontend needs approval or clarification hooks while preserving the run loop's
29 protocol retry, step-limit, command execution, and final-summary behavior. Use
30 **Agent.Step** with **Agent.ExecuteTurn** or **Agent.RejectTurn** for custom
31 turn loops.
32
33 # API
34
35 **NewAgent**(*model*, *executor*, *cwd*)
36 : Constructs an **Agent** with **DefaultMaxSteps**.
37
38 **Model**
39 : Interface for model adapters. **Query** receives transcript messages and
40 returns a **Response**.
41
42 **Executor**
43 : Interface for command runners. **Execute** receives a command and working
44 directory and returns a **CommandResult**.
45
46 **ShellExecutor**
47 : Built-in Unix bash executor.
48
49 **Agent.Run**
50 : Runs the full-send policy loop until **done**, clarification, error, or step
51 limit. A **clarify** turn returns **ErrClarificationNeeded**.
52
53 **Agent.RunWithPolicy**
54 : Runs the same loop as **Agent.Run** with caller-supplied **RunPolicy** hooks.
55
56 **RunPolicy**
57 : Interface for **DecideAct** and **Clarify** hooks.
58
59 **ActProposal**, **ActDecision**, **ActDecisionApprove**, **ActDecisionReject**
60 : Approval proposal and decision types used by **RunWithPolicy**.
61
62 **FullSendPolicy**
63 : Policy implementation used by **Agent.Run**.
64
65 **Agent.Step**
66 : Queries the model once and parses one turn. It does not execute commands.
67
68 **Agent.ExecuteTurn**
69 : Runs an accepted **ActTurn** and appends command result blocks to the
70 transcript.
71
72 **Agent.ExecuteTurnWithSkipped**
73 : Runs an accepted **ActTurn** and records skipped bash tool calls.
74
75 **Agent.AppendUserMessage**
76 : Appends caller-authored input to the transcript.
77
78 **Agent.RejectTurn**
79 : Records that an approval-mode **ActTurn** was not executed.
80
81 **Agent.RequestStepLimitSummary**
82 : Asks the model for a final **done** turn after the caller exhausts its step
83 budget.
84
85 **Agent.Messages**
86 : Returns a cloned transcript.
87
88 **Agent.Compact**
89 : Rewrites older transcript history through a caller-supplied **Compactor**.
90
91 **ParseTurn**
92 : Validates canonical clnkr turn JSON.
93
94 **CanonicalTurnJSON**
95 : Marshals a validated turn into canonical transcript JSON.
96
97 **ActProtocol**, **ParseActProtocol**
98 : Select and validate the model act protocol.
99
100 **BashToolCall**, **BashToolResult**, **ProviderReplayItem**
101 : Provider-neutral transcript fields for native bash tool call replay.
102
103 **LoadPromptWithOptions**
104 : Builds the system prompt with optional **AGENTS.md** layers.
105
106 Run **go doc github.com/clnkr-ai/clnkr** for the complete exported API.
107
108 # EXAMPLE
109
110 ```go
111 package main
112
113 import (
114 "context"
115 "errors"
116 "log"
117
118 "github.com/clnkr-ai/clnkr"
119 )
120
121 type model struct{}
122
123 func (model) Query(context.Context, []clnkr.Message) (clnkr.Response, error) {
124 return clnkr.Response{
125 Turn: clnkr.DoneTurn{Summary: "no model wired"},
126 }, nil
127 }
128
129 func main() {
130 agent := clnkr.NewAgent(model{}, &clnkr.ShellExecutor{}, ".")
131 if err := agent.Run(context.Background(), "check status"); err != nil {
132 if errors.Is(err, clnkr.ErrClarificationNeeded) {
133 log.Print("model asked for clarification")
134 return
135 }
136 log.Fatal(err)
137 }
138 }
139 ```
140
141 # NOTES
142
143 The root package is the public library surface. Packages below **internal/**
144 are not importable by external callers.
145
146 The built-in **ShellExecutor** assumes Unix process semantics and bash.
147 Windows is unsupported.
148
149 # COPYRIGHT
150
151 Copyright 2026 Brian Cosgrove. Licensed under the Apache License, Version
152 2.0.
153
154 # SEE ALSO
155
156 **clnkr**(1), **clnkr**(7), **go**(1)