Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.1 #13

Merged
merged 57 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9e7fa54
:package: include git short sha in builds
yusufcanb Mar 8, 2024
c3e2429
:package: include git short sha in builds
yusufcanb Mar 8, 2024
8090d2c
:wrench: optimizations and refactoring for install package
yusufcanb Mar 8, 2024
2822494
:necktie: sonar scan workflow added
yusufcanb Mar 8, 2024
7f3e1b8
:necktie: sonar scan workflow added
yusufcanb Mar 8, 2024
3d93002
:package: workflow updates
yusufcanb Mar 9, 2024
4866f00
:test_tube: initial test files added
yusufcanb Mar 9, 2024
fec1973
:package: go mod update
yusufcanb Mar 9, 2024
1b89025
:package: go sum update
yusufcanb Mar 9, 2024
c3af686
:seedling: initial impl for upgrade functionality. implements app hoo…
yusufcanb Mar 10, 2024
4602caf
:package: remove test flow and add semver package
yusufcanb Mar 10, 2024
f6762da
:wrench: added a check when no command is found
yusufcanb Mar 10, 2024
2d4da2e
:wrench: release_manager and checkpoint impl to check latests release…
yusufcanb Mar 10, 2024
2c555b7
:bookmark: version bump
yusufcanb Mar 10, 2024
b794439
:package: include git short sha in builds
yusufcanb Mar 8, 2024
05b1975
:package: include git short sha in builds
yusufcanb Mar 8, 2024
c70f878
:wrench: optimizations and refactoring for install package
yusufcanb Mar 8, 2024
b57f6fc
:necktie: sonar scan workflow added
yusufcanb Mar 8, 2024
5e18e32
:necktie: sonar scan workflow added
yusufcanb Mar 8, 2024
c5b39eb
:package: workflow updates
yusufcanb Mar 9, 2024
c1a688f
:test_tube: initial test files added
yusufcanb Mar 9, 2024
f7c5a33
:package: go mod update
yusufcanb Mar 9, 2024
01ed0c3
:package: go sum update
yusufcanb Mar 9, 2024
07e9b00
:seedling: initial impl for upgrade functionality. implements app hoo…
yusufcanb Mar 10, 2024
150e03c
:package: remove test flow and add semver package
yusufcanb Mar 10, 2024
daa330a
:wrench: added a check when no command is found
yusufcanb Mar 10, 2024
401379b
:wrench: release_manager and checkpoint impl to check latests release…
yusufcanb Mar 10, 2024
fa22196
:bookmark: version bump
yusufcanb Mar 10, 2024
a73d3f4
Merge remote-tracking branch 'origin/release/1.1' into release/1.1
yusufcanb Mar 12, 2024
cbf5eba
:sparkles: configurable suggestion selection for different shell and …
yusufcanb Mar 12, 2024
3bbd03c
:sparkles: checkpoint version comparison added
yusufcanb Mar 12, 2024
140a4ec
:wrench: minor refactoring
yusufcanb Mar 12, 2024
0f0eb20
:wrench: allow config set shell <shell>
yusufcanb Mar 12, 2024
71228ee
:test_tube: initial commit for e2e tests
yusufcanb Mar 12, 2024
a6c9045
:test_tube: fix workflow
yusufcanb Mar 12, 2024
edb5671
:test_tube: fix workflow
yusufcanb Mar 12, 2024
2aaaccf
:test_tube: fix workflow
yusufcanb Mar 12, 2024
7c85514
:test_tube: e2e on every push
yusufcanb Mar 12, 2024
709e24a
:test_tube: e2e into build.yaml
yusufcanb Mar 12, 2024
59cfbc6
:test_tube: e2e into build.yaml
yusufcanb Mar 12, 2024
c9b4622
:test_tube: download artifact fix
yusufcanb Mar 12, 2024
7e70eaf
:test_tube: version match fix
yusufcanb Mar 12, 2024
954bcc3
:test_tube: version match fix
yusufcanb Mar 12, 2024
df7c9a3
:test_tube: version match fix
yusufcanb Mar 12, 2024
fa67aaf
:test_tube: version match fix
yusufcanb Mar 12, 2024
58c4599
:test_tube: version match fix
yusufcanb Mar 12, 2024
bfe5c09
:test_tube: version match fix
yusufcanb Mar 12, 2024
55957ed
:test_tube: version match fix
yusufcanb Mar 12, 2024
9a929ef
:test_tube: version match fix
yusufcanb Mar 12, 2024
c2c687b
:test_tube: version match fix
yusufcanb Mar 12, 2024
9b0a2bc
:test_tube: version match fix
yusufcanb Mar 12, 2024
ef78009
:test_tube: version match fix
yusufcanb Mar 12, 2024
e7d8857
Merge branch 'feature/e2e' into release/1.1
yusufcanb Mar 12, 2024
38560e0
:test_tube: fix test
yusufcanb Mar 12, 2024
6ecaaab
:test_tube: fix test
yusufcanb Mar 12, 2024
aa6465a
:test_tube: e2e tests restructured
yusufcanb Mar 13, 2024
a0ca50d
:bookmark: bump installation url version
yusufcanb Mar 13, 2024
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
46 changes: 41 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: build
name: ci

on: [push]
on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -27,5 +26,42 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: dist
path: |
dist
path: dist/
retention-days: 1
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist

- name: Install tlm
run: |
mv $(cat VERSION)/tlm_$(cat VERSION)_linux_amd64 /usr/local/bin/tlm
chmod +x /usr/local/bin/tlm
tlm help

- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: 3.11

- name: Install dependencies
run: pip install -r e2e/requirements.txt

- name: Run Tests wo/ Ollama
run: robot --outputdir dist --name tlm --exclude requires=ollama tlm.robot
working-directory: e2e/

- name: Archive e2e artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-report
path: e2e/dist/

needs:
- build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
# Go workspace file
go.work
.idea
dist
dist
.venv/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ It will recognize the which platform and architecture to download and will execu
Download and execute the installation script by using the following command;

```bash
curl -fsSL https://raw.githubusercontent.com/yusufcanb/tlm/main/install.sh | sudo bash -E
curl -fsSL https://raw.githubusercontent.com/yusufcanb/tlm/release/1.1/install.sh | sudo bash -E
```

#### Windows (Powershell 5.1 or higher)

Download and execute the installation script by using the following command;

```powershell
Invoke-RestMethod -Uri https://raw.githubusercontent.com/yusufcanb/tlm/main/install.ps1 | Invoke-Expression
Invoke-RestMethod -Uri https://raw.githubusercontent.com/yusufcanb/tlm/release/1.1/install.ps1 | Invoke-Expression
```

### Go Install
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0
1.1
36 changes: 19 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"github.com/yusufcanb/tlm/config"
"github.com/yusufcanb/tlm/explain"
"github.com/yusufcanb/tlm/install"
"github.com/yusufcanb/tlm/shell"
"github.com/yusufcanb/tlm/suggest"
"os"
"io/fs"
"runtime"

"github.com/urfave/cli/v2"
Expand All @@ -22,51 +21,54 @@ var explainModelfile string
var suggestModelfile string

type TlmApp struct {
App *cli.App
writer *fs.File

explainModelfile string
suggestModelfile string

App *cli.App
}

func New(version string) *TlmApp {
func New(version, buildSha string) *TlmApp {
con := config.New()
con.LoadOrCreateConfig()

o, _ := ollama.ClientFromEnvironment()
sug := suggest.New(o, suggestModelfile)
exp := explain.New(o, explainModelfile)
sug := suggest.New(o)
exp := explain.New(o)
ins := install.New(o, suggestModelfile, explainModelfile)

cliApp := &cli.App{
Name: "tlm",
Usage: "terminal copilot, powered by CodeLLaMa.",
UsageText: "tlm explain <command>\ntlm suggest <prompt>",
Version: version,
CommandNotFound: func(context *cli.Context, s string) {
fmt.Println(shell.Err() + " command not found.")
os.Exit(-1)
},
Name: "tlm",
Usage: "terminal copilot, powered by CodeLLaMa.",
UsageText: "tlm explain <command>\ntlm suggest <prompt>",
Version: version,
CommandNotFound: notFound,
Before: beforeRun(),
After: afterRun(ins, version),
Action: func(c *cli.Context) error {
return cli.ShowAppHelp(c)
},
Commands: []*cli.Command{
sug.Command(),
exp.Command(),
ins.Command(),
ins.DeployCommand(),
con.Command(),
{
Name: "version",
Aliases: []string{"v"},
Usage: "Prints tlm version.",
Action: func(c *cli.Context) error {
fmt.Printf("tlm %s (%s/%s)", version, runtime.GOOS, runtime.GOARCH)
fmt.Printf("tlm %s (%s) on %s/%s", version, buildSha, runtime.GOOS, runtime.GOARCH)
return nil
},
},
},
}

return &TlmApp{
app := &TlmApp{
App: cliApp,
}

return app
}
52 changes: 52 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package app_test

import (
"fmt"
"github.com/yusufcanb/tlm/app"
"io"
"os"
"testing"
)

func run(args []string) {
tlm := app.New("0.0", "test")

err := tlm.App.Run(args)
if err != nil {
os.Exit(1)
}
}

func Test_Version(t *testing.T) {

stdout := os.Stdout

args := os.Args[0:1]
args = append(args, " version")

capturedOutput := os.NewFile(0, "tlm.log")
os.Stdout = capturedOutput

run(args)

// Read all contents from the capturedOutput
contents, err := io.ReadAll(capturedOutput)
if err != nil {
fmt.Println("Error reading contents:", err)
t.Fail()
}

os.Stdout = stdout
_ = capturedOutput.Close()

// Print the captured output
t.Log("Captured Output:")
t.Log(string(contents))

}

func Test_Help(t *testing.T) {
args := os.Args[0:1]
args = append(args, "help")
run(args)
}
33 changes: 33 additions & 0 deletions app/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app

import (
"fmt"
"github.com/urfave/cli/v2"
"github.com/yusufcanb/tlm/install"
"github.com/yusufcanb/tlm/shell"
"os"
)

func notFound(_ *cli.Context, _ string) {
fmt.Println(shell.Err() + " command not found.")
os.Exit(-1)
}

func beforeRun() func(c *cli.Context) error {
return func(c *cli.Context) error {
return nil
}
}

func afterRun(ins *install.Install, version string) func(c *cli.Context) error {
return func(c *cli.Context) error {
switch c.Args().Get(0) {
case "suggest", "s", "explain", "e":
return nil

default:
return ins.ReleaseManager.CheckForUpdates(version)
}
}

}
3 changes: 2 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ New-Item -ItemType Directory -Path "dist"
# Build Function (Helper)
Function Build-Target($os, $version, $arch) {
$outputName = "${appName}_${version}_${os}_${arch}"
$sha1 = (git rev-parse --short HEAD).Trim()
if ($os -eq "windows") {
$outputName += ".exe"
}

Write-Output "Building for $os/$arch (version: $version) -> $outputName"
# Invokes the Go toolchain (assumes it's in the PATH)
go build -o "dist/$version/$outputName" "main.go"
go build -o "dist/$version/$outputName" -ldflags "-X main.sha1ver=$sha1" "main.go"
}

# Build for each target OS
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build() {
app_name=$2
version=$3
arch=$4
sha1=$(git rev-parse --short HEAD | tr -d '\n')

# Determine output filename with optional .exe extension
output_name="${app_name}_${version}_${os}_${arch}"
Expand All @@ -14,7 +15,7 @@ build() {
fi

echo "Building for $os/$arch (version: $version) -> $output_name"
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" main.go
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" -ldflags "-X main.sha1ver=$sha1" main.go
}

# Operating systems to target
Expand Down
13 changes: 8 additions & 5 deletions config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
"path"
)

var defaultLLMHost = "http://localhost:11434"
var (
defaultSuggestionPolicy = "stable"
defaultExplainPolicy = "creative"
defaultShell = "auto"
)

func isExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
Expand All @@ -30,11 +34,10 @@ func (c *Config) LoadOrCreateConfig() {

configPath := path.Join(homeDir, ".tlm.yaml")
if !isExists(configPath) {
viper.Set("shell", shell.GetShell())

viper.Set("shell", defaultShell)
viper.Set("llm.host", defaultLLMHost)
viper.Set("llm.suggestion", "balanced")
viper.Set("llm.explain", "balanced")
viper.Set("llm.suggestion", defaultSuggestionPolicy)
viper.Set("llm.explain", defaultExplainPolicy)

err := os.Setenv("OLLAMA_HOST", defaultLLMHost)
if err != nil {
Expand Down
39 changes: 28 additions & 11 deletions config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@ import (
"net/url"
)

var (
defaultLLMHost = "http://localhost:11434"
shellKey = "shell"
llmHostKey = "llm.host"
llmExplainKey = "llm.explain"
llmSuggestKey = "llm.suggest"
)

func (c *Config) Action(_ *cli.Context) error {
var err error

form := ConfigForm{
host: viper.GetString("llm.host"),
explain: viper.GetString("llm.explain"),
suggest: viper.GetString("llm.suggest"),
host: viper.GetString(llmHostKey),
shell: viper.GetString(shellKey),
explain: viper.GetString(llmExplainKey),
suggest: viper.GetString(llmSuggestKey),
}

err = form.Run()
if err != nil {
return err
}

viper.Set("shell", form.shell)
viper.Set("llm.host", form.host)
viper.Set("llm.explain", form.explain)
viper.Set("llm.suggest", form.suggest)
viper.Set(shellKey, form.shell)
viper.Set(llmHostKey, form.host)
viper.Set(llmExplainKey, form.explain)
viper.Set(llmSuggestKey, form.suggest)

err = viper.WriteConfig()
if err != nil {
Expand Down Expand Up @@ -78,19 +87,27 @@ func (c *Config) subCommandSet() *cli.Command {
key := c.Args().Get(0)

switch key {
case "llm.host":
case llmHostKey:
u, err := url.ParseRequestURI(c.Args().Get(1))
if err != nil {
return errors.New("Invalid url: " + c.Args().Get(1))
return errors.New("invalid url: " + c.Args().Get(1))
}
viper.Set(key, u.String())

case "llm.suggest", "llm.explain":
case llmSuggestKey, llmExplainKey:
mode := c.Args().Get(1)
if mode != "stable" && mode != "balanced" && mode != "creative" {
return errors.New("Invalid mode: " + mode)
return errors.New("invalid mode: " + mode)
}
viper.Set(key, mode)

case shellKey:
s := c.Args().Get(1)
if s != "bash" && s != "zsh" && s != "auto" && s != "powershell" {
return errors.New("invalid shell: " + c.Args().Get(1))
}
viper.Set(shellKey, s)

default:
fmt.Println(fmt.Sprintf("%s <%s> is not a tlm parameter", shell.Err(), key))
return nil
Expand Down
Loading
Loading