nandi/oripublic Fork 0
55d4c9e2f7a9027b52846558166f42e50851523a
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

config.go · 79 lines · 2.4 KBGo Blame HistoryRaw
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday1// Package config parses the command-line configuration of the ori server.
2//
3// It is deliberately tiny: three flags, validated once at startup, then passed
4// around as an immutable value.
5package config
6
7import (
8 "flag"
9 "fmt"
10 "os"
11 "path/filepath"
12 "strings"
13)
14
15// DefaultAgentCommand is the ACP agent spawned when --agent-cmd is not given.
✨ Switch the ACP adapter to @agentclientprotocol/claude-agent-acp (template 0.0.2) 5d476ff k33g yesterday16// It is the Agent Client Protocol project's adapter for the Claude Agent SDK,
17// which bundles a current Claude Code CLI (the older Zed adapter ships a CLI
18// too old for current models).
19const DefaultAgentCommand = "npx -y @agentclientprotocol/claude-agent-acp"
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday20
21// Config holds the runtime configuration of the ori server.
22type Config struct {
23 // Addr is the TCP address the HTTP server listens on, e.g. ":8888".
24 Addr string
25 // Cwd is the absolute working directory handed to the agent session.
26 Cwd string
27 // AgentCommand is the command line used to spawn the ACP agent,
28 // split on whitespace (the first field is the executable).
29 AgentCommand []string
30}
31
32// FromArgs parses command-line arguments (without the program name) into a
33// Config. It returns an error for unknown flags, an empty agent command, or a
34// working directory that does not exist.
35//
36// Example:
37//
38// cfg, err := config.FromArgs([]string{"--addr", ":9000", "--cwd", "/tmp"})
39// if err != nil {
40// log.Fatal(err)
41// }
42// fmt.Println(cfg.Addr) // ":9000"
43func FromArgs(args []string) (Config, error) {
44 fs := flag.NewFlagSet("ori", flag.ContinueOnError)
45 addr := fs.String("addr", ":8888", "TCP address the HTTP server listens on")
46 cwd := fs.String("cwd", "", "working directory for the agent session (default: current directory)")
47 agentCmd := fs.String("agent-cmd", DefaultAgentCommand, "command spawning the ACP agent, split on whitespace")
48
49 if err := fs.Parse(args); err != nil {
50 return Config{}, err
51 }
52
53 command := strings.Fields(*agentCmd)
54 if len(command) == 0 {
55 return Config{}, fmt.Errorf("--agent-cmd must not be empty")
56 }
57
58 dir := *cwd
59 if dir == "" {
60 wd, err := os.Getwd()
61 if err != nil {
62 return Config{}, fmt.Errorf("resolve current directory: %w", err)
63 }
64 dir = wd
65 }
66 absDir, err := filepath.Abs(dir)
67 if err != nil {
68 return Config{}, fmt.Errorf("resolve --cwd: %w", err)
69 }
70 info, err := os.Stat(absDir)
71 if err != nil {
72 return Config{}, fmt.Errorf("--cwd: %w", err)
73 }
74 if !info.IsDir() {
75 return Config{}, fmt.Errorf("--cwd: %s is not a directory", absDir)
76 }
77
78 return Config{Addr: *addr, Cwd: absDir, AgentCommand: command}, nil
79}