mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-15 14:19:13 +02:00
* feat(agent): add GitHub Copilot CLI backend Integrate Copilot CLI as a new agent backend using the stable `-p` JSONL mode (`--output-format json`), following the same spawn-CLI-scan-JSONL pattern established by claude.go. Backend (server/pkg/agent/copilot.go): - Spawn `copilot -p <prompt> --output-format json --allow-all-tools --no-ask-user` - Parse streaming JSONL events (system/assistant/user/result/log) - Extract session ID for resume support (`--resume <id>`) - Accumulate per-model token usage for billing - Filter blocked args to prevent protocol-critical flag overrides Daemon config: - Probe MULTICA_COPILOT_PATH / MULTICA_COPILOT_MODEL env vars - Copilot uses AGENTS.md (native discovery) and default skills path Frontend: - Add Copilot logo SVG and provider switch case Tests: 14 unit tests covering arg building, event parsing, usage accumulation, and edge cases. All Go + TS checks pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(daemon): add restart subcommand, make daemon uses it - `daemon start` keeps original behavior: errors if already running - `daemon restart` stops existing daemon then starts fresh - `make daemon` now runs `daemon restart --profile local` Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(copilot): address review nits 1-5 - Nit 1: Add MinVersions["copilot"] = "1.0.0" - Nit 2: Seed activeModel from session.start.data.selectedModel (falls back to opts.Model, then "copilot"). First-turn tokens now get correct model attribution. - Nit 3: Handle assistant.reasoning/reasoning_delta → MessageThinking, reasoningText in assistant.message → MessageThinking, session.warning → MessageLog{warn} - Nit 4: Extract handleCopilotEvent() method shared by production and tests — no more duplicated switch body that can drift - Nit 5: Deltas write to output buffer as defense-in-depth; if process dies before assistant.message, output is non-empty Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
// MinVersions defines the minimum required CLI version for each agent type.
|
|
// Versions below these will be rejected during daemon registration.
|
|
var MinVersions = map[string]string{
|
|
"claude": "2.0.0",
|
|
"codex": "0.100.0", // app-server --listen stdio:// added in 0.100.0
|
|
"copilot": "1.0.0", // --output-format json envelope stable from 1.0.x
|
|
}
|
|
|
|
// semver holds a parsed semantic version (major.minor.patch).
|
|
type semver struct {
|
|
Major, Minor, Patch int
|
|
}
|
|
|
|
// versionRe matches version strings like "2.1.100", "v2.0.0", or
|
|
// "2.1.100 (Claude Code)" — it extracts the first three numeric components.
|
|
var versionRe = regexp.MustCompile(`v?(\d+)\.(\d+)\.(\d+)`)
|
|
|
|
// parseSemver extracts a semver from a version string.
|
|
func parseSemver(raw string) (semver, error) {
|
|
m := versionRe.FindStringSubmatch(raw)
|
|
if m == nil {
|
|
return semver{}, fmt.Errorf("cannot parse version %q", raw)
|
|
}
|
|
major, _ := strconv.Atoi(m[1])
|
|
minor, _ := strconv.Atoi(m[2])
|
|
patch, _ := strconv.Atoi(m[3])
|
|
return semver{Major: major, Minor: minor, Patch: patch}, nil
|
|
}
|
|
|
|
// lessThan returns true if v < other.
|
|
func (v semver) lessThan(other semver) bool {
|
|
if v.Major != other.Major {
|
|
return v.Major < other.Major
|
|
}
|
|
if v.Minor != other.Minor {
|
|
return v.Minor < other.Minor
|
|
}
|
|
return v.Patch < other.Patch
|
|
}
|
|
|
|
// CheckMinVersion validates that detectedVersion meets the minimum for agentType.
|
|
// Returns nil if the version is acceptable or no minimum is defined.
|
|
func CheckMinVersion(agentType, detectedVersion string) error {
|
|
minRaw, ok := MinVersions[agentType]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
min, err := parseSemver(minRaw)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid minimum version %q for %s: %w", minRaw, agentType, err)
|
|
}
|
|
detected, err := parseSemver(detectedVersion)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot parse detected %s version %q: %w", agentType, detectedVersion, err)
|
|
}
|
|
if detected.lessThan(min) {
|
|
return fmt.Errorf("%s version %s is below minimum required %s — please upgrade", agentType, detectedVersion, minRaw)
|
|
}
|
|
return nil
|
|
}
|