<commit_before>package main

import (
    "os"
    "fmt"
    "bufio"
    "strconv"
    "encoding/json"
)

type command struct {
    Path string `json:"path"`
    Args []string `json:"args"`
    Env map[string]string `json:"env"`
}

func usage() {
    fmt.Fprintf(os.Stderr, "Usage: dasc <req fd> <res fd>\n");
}

func getIntArg(i int) int {
    if i < len(os.Args) {
        a, err := strconv.Atoi(os.Args[i])
        if err == nil {
            return a
        }
    }
    usage()
    os.Exit(1)
    return -1
}

func main() {
    reqfd := uintptr(getIntArg(1))
    resfd := uintptr(getIntArg(2))
    req := os.NewFile(reqfd, "<request pipe>")
    res := bufio.NewReader(os.NewFile(resfd, "<response pipe>"))

    cmd := command{
        "/usr/bin/env",
        []string{"/usr/bin/env"},
        map[string]string{"some_key": "some_value"},
    }
    json, err := json.Marshal(cmd)
    if err != nil {
        panic("failed to marshal command")
    }
    req.Write(json)
    req.WriteString("\n")

    msg, err := res.ReadBytes('\n')
    if err == nil {
        fmt.Printf("response: %s", msg)
    }
}<commit_msg>dasc.go: very rough (but working!) REPL<commit_after>package main

import (
    "os"
    "fmt"
    "bufio"
    "strconv"
    "strings"
    "encoding/json"
)

type command struct {
    Path string `json:"path"`
    Args []string `json:"args"`
    Env map[string]string `json:"env"`
}

func usage() {
    fmt.Fprintf(os.Stderr, "Usage: dasc <req fd> <res fd>\n");
}

func getIntArg(i int) int {
    if i < len(os.Args) {
        a, err := strconv.Atoi(os.Args[i])
        if err == nil {
            return a
        }
    }
    usage()
    os.Exit(1)
    return -1
}

func prompt() {
    fmt.Print("> ")
}

func lackeol() {
    fmt.Println("\033[7m%\033[m")
}

func search(path string) string {
    if path[0] == '/' {
        return path
    }
    return "/bin/" + path
}

func readline(stdin *bufio.Reader) (line string, err error) {
    line, err = stdin.ReadString('\n')
    if err == nil {
        line = line[:len(line)-1]
    }
    return
}

func main() {
    reqfd := uintptr(getIntArg(1))
    resfd := uintptr(getIntArg(2))
    req := os.NewFile(reqfd, "<request pipe>")
    res := bufio.NewReader(os.NewFile(resfd, "<response pipe>"))

    stdin := bufio.NewReader(os.Stdin)

    for {
        prompt()
        line, err := readline(stdin)
        if err != nil {
            lackeol()
            break
        }
        words := strings.Split(line, " ")
        if len(words) == 0 {
            continue
        }
        words[0] = search(words[0])
        cmd := command{}
        cmd.Path = words[0]
        cmd.Args = words
        cmd.Env = map[string]string{}

        json, err := json.Marshal(cmd)
        if err != nil {
            panic("failed to marshal command")
        }
        req.Write(json)
        req.WriteString("\n")

        msg, err := res.ReadBytes('\n')
        if err == nil {
            fmt.Printf("response: %s", msg)
        }
    }
}
{'fraction_non_alphanumeric': 0.1667223521550284, 'fraction_numerical': 0.0070163715335783495, 'mean_word_length': 1.991008991008991, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '838097', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1061, 'n_words': 239}