• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kshard / thinker / 13445877338

20 Feb 2025 10:27PM UTC coverage: 71.667% (+3.9%) from 67.766%
13445877338

push

github

web-flow
Enhance command interface (#2)

* Generic reasoner for commands (single and sequence)
* Support Python command
* Support Golan
* Support language commands via <codeblock>

216 of 281 new or added lines in 6 files covered. (76.87%)

387 of 540 relevant lines covered (71.67%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.58
/command/bash.go
1
//
2
// Copyright (C) 2025 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/kshard/thinker
7
//
8

9
package command
10

11
import (
12
        "bytes"
13
        "fmt"
14
        "os"
15
        "os/exec"
16

17
        "github.com/kshard/chatter"
18
        "github.com/kshard/thinker"
19
)
20

21
// A unique name for bash (the shell)
22
const BASH = "bash"
23

24
// Create new bash command, defining the os variant and working dir
25
func Bash(os, dir string) thinker.Cmd {
1✔
26
        return thinker.Cmd{
1✔
27
                Cmd:    BASH,
1✔
28
                Short:  fmt.Sprintf("executes shell command, strictly adhere shell command syntaxt to %s. Enclose the bash commands in <codeblock> tags.", os),
1✔
29
                Syntax: "bash <codeblock>source code</codeblock>",
1✔
30
                Run:    bash(os, dir),
1✔
31
        }
1✔
32
}
1✔
33

34
func shfile(dir, code string) (string, error) {
1✔
35
        fd, err := os.CreateTemp(dir, "job-*.sh")
1✔
36
        if err != nil {
1✔
NEW
37
                return "", err
×
NEW
38
        }
×
39
        defer fd.Close()
1✔
40

1✔
41
        _, err = fd.WriteString(code)
1✔
42
        if err != nil {
1✔
NEW
43
                return "", err
×
NEW
44
        }
×
45

46
        return fd.Name(), nil
1✔
47
}
48

49
func bash(os string, dir string) func(chatter.Reply) (float64, thinker.CmdOut, error) {
1✔
50
        return func(command chatter.Reply) (float64, thinker.CmdOut, error) {
2✔
51
                code, err := CodeBlock(BASH, command.Text)
1✔
52
                if err != nil {
1✔
NEW
53
                        return 0.00, thinker.CmdOut{Cmd: BASH}, err
×
NEW
54
                }
×
55

56
                file, err := shfile(dir, code)
1✔
57
                if err != nil {
1✔
NEW
58
                        return 0.00, thinker.CmdOut{Cmd: BASH}, err
×
NEW
59
                }
×
60

61
                cmd := exec.Command("bash", file)
1✔
62
                var stdout bytes.Buffer
1✔
63
                var stderr bytes.Buffer
1✔
64
                cmd.Dir = dir
1✔
65
                cmd.Stdout = &stdout
1✔
66
                cmd.Stderr = &stderr
1✔
67

1✔
68
                if err := cmd.Run(); err != nil {
1✔
69
                        err = thinker.Feedback(
×
70
                                fmt.Sprintf("The TOOL:%s has failed, improve the response based on feedback:", BASH),
×
71

×
72
                                fmt.Sprintf("Strictly adhere shell command syntaxt to %s.", os),
×
73
                                "Execution of the tool is failed with the error: "+err.Error(),
×
74
                                "The error output is "+stderr.String(),
×
75
                        )
×
76
                        return 0.05, thinker.CmdOut{Cmd: BASH}, err
×
77
                }
×
78

79
                return 1.0, thinker.CmdOut{Cmd: BASH, Output: stdout.String()}, nil
1✔
80
        }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc