Skip to content

Commit 5577c4e

Browse files
committed
(human) more work on tui, chat starting to work again
1 parent df6c106 commit 5577c4e

File tree

22 files changed

+780
-255
lines changed

22 files changed

+780
-255
lines changed

.veg/tools.cue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ tools: [n=string]: {
1212

1313
TOOLS=tools: {
1414
cache_put: description: embed["tools/cache_put.md"]
15-
cache_write: description: embed["tools/cache_put.md"]
16-
cache_edit: description: embed["tools/cache_edit.md"]
17-
cache_remove: description: embed["tools/cache_del.md"]
15+
// cache_write: description: embed["tools/cache_put.md"]
16+
// cache_edit: description: embed["tools/cache_edit.md"]
17+
// cache_remove: description: embed["tools/cache_del.md"]
1818
cache_del: description: embed["tools/cache_del.md"]
1919

2020
fs_read: description: embed["tools/fs_read.md"]

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/hofstadter-io/hof
33
go 1.24.4
44

55
require (
6-
cuelang.org/go v0.15.3
6+
cuelang.org/go v0.15.4
77
dagger.io/dagger v0.19.10
88
github.com/AlecAivazis/survey/v2 v2.3.7
99
github.com/BurntSushi/toml v1.5.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ cuelabs.dev/go/oci/ociregistry v0.0.0-20250722084951-074d06050084 h1:4k1yAtPvZJZ
99
cuelabs.dev/go/oci/ociregistry v0.0.0-20250722084951-074d06050084/go.mod h1:4WWeZNxUO1vRoZWAHIG0KZOd6dA25ypyWuwD3ti0Tdc=
1010
cuelang.org/go v0.15.3 h1:JKR/lZVwuIGlLTGIaJ0jONz9+CK3UDx06sQ6DDxNkaE=
1111
cuelang.org/go v0.15.3/go.mod h1:NYw6n4akZcTjA7QQwJ1/gqWrrhsN4aZwhcAL0jv9rZE=
12+
cuelang.org/go v0.15.4 h1:lrkTDhqy8dveHgX1ZLQ6WmgbhD8+rXa0fD25hxEKYhw=
13+
cuelang.org/go v0.15.4/go.mod h1:NYw6n4akZcTjA7QQwJ1/gqWrrhsN4aZwhcAL0jv9rZE=
1214
cyphar.com/go-pathrs v0.2.1 h1:9nx1vOgwVvX1mNBWDu93+vaceedpbsDqo+XuBGL40b8=
1315
cyphar.com/go-pathrs v0.2.1/go.mod h1:y8f1EMG7r+hCuFf/rXsKqMJrJAUoADZGNh5/vZPKcGc=
1416
dagger.io/dagger v0.19.10 h1:farO4CggSoWCId92QeZWKpP5mY9YwsVhNYuUzpqsKqw=

lib/agent/agents/cue.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path"
88
"slices"
99
"sort"
10-
"strconv"
1110
"strings"
1211

1312
"cuelang.org/go/cue/cuecontext"
@@ -125,7 +124,7 @@ func BuildAgent(
125124
if modelName == "" || modelName == "default" {
126125
modelName = agt.Model
127126
}
128-
fmt.Println("BuildAgent", agentName, modelName)
127+
// fmt.Println("BuildAgent", agentName, modelName)
129128
mdl, ok := models[modelName]
130129
if !ok {
131130
return nil, fmt.Errorf("unknown model %q in agent %q", modelName, agt.Name)
@@ -198,13 +197,13 @@ func buildMcp(cfg *config.Config, agt config.Agent, models map[string]model.LLM)
198197
func buildTools(cfg *config.Config, agt config.Agent, models map[string]model.LLM, environMDs map[string]string) ([]tool.Tool, error) {
199198
var ts []tool.Tool
200199
for _, t := range agt.Tools {
201-
fmt.Printf("%s.tool: %q\n", agt.Name, t)
200+
// fmt.Printf("%s.tool: %q\n", agt.Name, t)
202201
var T tool.Tool
203202
var err error
204203

205204
// @<agent> handling
206205
agentAsTool, found := strings.CutPrefix(t, "@")
207-
fmt.Printf("%s.tool.agent: %q ? %v\n", agt.Name, agentAsTool, found)
206+
// fmt.Printf("%s.tool.agent: %q ? %v\n", agt.Name, agentAsTool, found)
208207
if found {
209208
A, aerr := BuildAgent(cfg, agentAsTool, "default", models, environMDs)
210209
if aerr != nil {
@@ -275,14 +274,14 @@ func buildTools(cfg *config.Config, agt config.Agent, models map[string]model.LL
275274
func addCallbacks(cfg *config.Config, agt config.Agent, environMDs map[string]string, c *llmagent.Config) {
276275
c.BeforeAgentCallbacks = []agent.BeforeAgentCallback{
277276
func(ctx agent.CallbackContext) (*genai.Content, error) {
278-
fmt.Printf("\nBAC.%s\n", ctx.AgentName())
277+
// fmt.Printf("\nBAC.%s\n", ctx.AgentName())
279278
return nil, nil
280279
},
281280
}
282281

283282
c.BeforeModelCallbacks = []llmagent.BeforeModelCallback{
284283
func(ctx agent.CallbackContext, req *model.LLMRequest) (*model.LLMResponse, error) {
285-
fmt.Printf("\nBMC.%s\n", ctx.AgentName())
284+
// fmt.Printf("\nBMC.%s\n", ctx.AgentName())
286285

287286
// This next section is all about making sure the state is in a good place
288287
// to match the data we are about to render instructions with
@@ -323,23 +322,23 @@ func addCallbacks(cfg *config.Config, agt config.Agent, environMDs map[string]st
323322

324323
// hmmm, little utils like this could get spread throughout the code
325324
// TODO, make a schema somewhere for the various config (cli, system, per-user, per-session, state)
326-
showStr, err := ctx.State().Get("showSystemPrompt")
327-
fmt.Println("showSystemPrompt.1?", showStr, err)
328-
if showStr != nil {
329-
show, err := strconv.ParseBool(showStr.(string))
330-
fmt.Println("showSystemPrompt.2?", show, err)
331-
if err == nil && show {
332-
fmt.Println(req.Config.SystemInstruction.Parts[0].Text)
333-
}
334-
}
325+
// showStr, err := ctx.State().Get("showSystemPrompt")
326+
// fmt.Println("showSystemPrompt.1?", showStr, err)
327+
// if showStr != nil {
328+
// show, err := strconv.ParseBool(showStr.(string))
329+
// fmt.Println("showSystemPrompt.2?", show, err)
330+
// if err == nil && show {
331+
// fmt.Println(req.Config.SystemInstruction.Parts[0].Text)
332+
// }
333+
// }
335334

336335
return nil, nil
337336
},
338337
}
339338

340339
c.BeforeToolCallbacks = []llmagent.BeforeToolCallback{
341340
func(ctx tool.Context, t tool.Tool, args map[string]any) (map[string]any, error) {
342-
fmt.Printf("\nBTC.%s.%s\n", ctx.AgentName(), t.Name())
341+
// fmt.Printf("\nBTC.%s.%s\n", ctx.AgentName(), t.Name())
343342
return nil, nil
344343
},
345344
}
@@ -350,21 +349,21 @@ func addCallbacks(cfg *config.Config, agt config.Agent, environMDs map[string]st
350349

351350
c.AfterToolCallbacks = []llmagent.AfterToolCallback{
352351
func(ctx tool.Context, t tool.Tool, args, result map[string]any, err error) (map[string]any, error) {
353-
fmt.Printf("\nATC.%s.%s %v\n", ctx.AgentName(), t.Name(), err)
352+
// fmt.Printf("\nATC.%s.%s %v\n", ctx.AgentName(), t.Name(), err)
354353
return result, err
355354
},
356355
}
357356

358357
c.AfterModelCallbacks = []llmagent.AfterModelCallback{
359358
func(ctx agent.CallbackContext, res *model.LLMResponse, err error) (*model.LLMResponse, error) {
360-
fmt.Printf("\nAMC.%s %v\n", ctx.AgentName(), err)
359+
// fmt.Printf("\nAMC.%s %v\n", ctx.AgentName(), err)
361360
return res, err
362361
},
363362
}
364363

365364
c.AfterAgentCallbacks = []agent.AfterAgentCallback{
366365
func(ctx agent.CallbackContext) (*genai.Content, error) {
367-
fmt.Printf("\nAAC.%s\n", ctx.AgentName())
366+
// fmt.Printf("\nAAC.%s\n", ctx.AgentName())
368367
return nil, nil
369368
},
370369
}

lib/agent/cmd/chat.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ func Chat(args []string, rflags flags.RootPflagpole, aflags flags.AgentPflagpole
2121
return fmt.Errorf("expected one match as an agent, matched %d of %d", len(matches), len(R.Agentics))
2222
}
2323

24-
m := tui.InitialModel(R, AR)
24+
m, err := tui.InitialModel(R, AR, "chat")
25+
if err != nil {
26+
return err
27+
}
28+
2529
p := tea.NewProgram(m, tea.WithAltScreen())
2630

2731
if _, err := p.Run(); err != nil {

lib/agent/cmd/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/hofstadter-io/hof/lib/agent/cmd/tui"
88
)
99

10-
const gap = "\n\n"
11-
1210
func Main(args []string, rflags flags.RootPflagpole, aflags flags.AgentPflagpole, cflags flags.Agent__ChatPflagpole) error {
1311
R, AR, _, err := commonStart(args, rflags, aflags)
1412
if err != nil {
@@ -24,7 +22,10 @@ func Main(args []string, rflags flags.RootPflagpole, aflags flags.AgentPflagpole
2422
// AR.Run()
2523
// }()
2624

27-
m := tui.InitialModel(R, AR)
25+
m, err := tui.InitialModel(R, AR, "list")
26+
if err != nil {
27+
return err
28+
}
2829
p := tea.NewProgram(m, tea.WithAltScreen())
2930

3031
if _, err := p.Run(); err != nil {

lib/agent/cmd/runtime.go

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"maps"
77
"net/url"
88
"os"
9-
"path/filepath"
109
"regexp"
1110
"slices"
1211
"sort"
12+
"strconv"
1313
"strings"
1414

1515
"cuelang.org/go/cue"
1616
"github.com/hofstadter-io/hof/cmd/hof/flags"
1717
"github.com/hofstadter-io/hof/lib/agent"
18-
"github.com/hofstadter-io/hof/lib/agent/config"
1918
aruntime "github.com/hofstadter-io/hof/lib/agent/runtime"
2019
"github.com/hofstadter-io/hof/lib/agent/runtime/handlers/ws"
2120
"github.com/hofstadter-io/hof/lib/cuetils"
2221
"github.com/hofstadter-io/hof/lib/env/incept"
2322
"github.com/hofstadter-io/hof/lib/runtime"
24-
"github.com/hofstadter-io/hof/lib/templates"
2523
)
2624

2725
type agentFilter func(*agent.Agentic) bool
@@ -58,6 +56,8 @@ func prepRuntime(args []string, rflags flags.RootPflagpole) (*runtime.Runtime, *
5856
return nil, nil, fmt.Errorf("failed to create agent runtime: %v", err)
5957
}
6058

59+
ar.BackfillAgentic()
60+
6161
ws.SetupHandlers(ar)
6262
return r, ar, nil
6363
}
@@ -213,42 +213,6 @@ func commonStart(
213213
return R, AR, matches, err
214214
}
215215

216-
// TODO, we still need to do this, through probably on a per-request basis, or at least with watch/config changes
217-
func prepareTemplates(cfg *config.Config) error {
218-
219-
cwd, _ := os.Getwd()
220-
// todo, also put this on the Session
221-
dir := filepath.Join(cwd, cfg.EmbedDir)
222-
glob := filepath.Join(dir, "**/*.*")
223-
cfg.Templates = templates.NewTemplateMap()
224-
// fmt.Printf("found %d templates in %q\n", len(config.Templates), dir)
225-
err := cfg.Templates.ImportFromFolder(glob, dir, templates.Delims{}, nil)
226-
if err != nil {
227-
return fmt.Errorf("while loading instruction templates (%s,%s): %w", cwd, cfg.EmbedDir, err)
228-
}
229-
// fmt.Printf("found %d templates in %s\n", len(config.Templates), dir)
230-
231-
for _, T1 := range cfg.Templates {
232-
for _, T2 := range cfg.Templates {
233-
if T1.Name == T2.Name {
234-
continue
235-
}
236-
t := T1.T.New(T2.Name)
237-
_, err := t.Parse(T2.Source)
238-
if err != nil {
239-
return fmt.Errorf("while cross registering templates (%s,%s): %w", T1.Name, T2.Name, err)
240-
}
241-
}
242-
243-
// fmt.Println(T1.Name)
244-
// for _, t := range T1.T.Templates() {
245-
// fmt.Printf(" - %s\n", t.Name())
246-
// }
247-
}
248-
249-
return nil
250-
}
251-
252216
func daggerInceptFlags(rflags flags.RootPflagpole, eflags flags.EnvPflagpole) (bool, error) {
253217
return daggerInceptOpts(&incept.InceptOptions{
254218
Verbose: rflags.Verbosity,
@@ -281,6 +245,8 @@ func extractMeta(a *agent.Agentic) (aname, akind, mname string) {
281245
if aname == "" {
282246
aname = mname
283247
}
248+
aname, _ = strconv.Unquote(aname)
249+
mname, _ = strconv.Unquote(mname)
284250
return aname, akind, mname
285251
}
286252

0 commit comments

Comments
 (0)