perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299 package-level regexp.MustCompile calls, in 148 files across agent, provider, gui, library, codexcat, sessions, usage, plugin and the rest, now go through lazyre.New too, so a launch that never reaches them (`magpie statusline`, run by Claude Code on every message) doesn't compile them. Fields, maps and params that held them are *lazyre.RE. Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build (t42) against this one (t43): - GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765 - `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M, peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30 changed packages ok; GOOS=linux go vet ok except ., internal/cli and internal/gui, which stop in wails v3's cgo files when cross-compiled (the same at main). New TestAllLazyPatternsCompile at the root compiles all 574 registered patterns (ok), so a bad pattern fails a test rather than a first use. Not run before push: the changed packages' own test suites; they run on mote after it.
This commit is contained in:
@@ -34,7 +34,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -42,6 +41,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -226,7 +226,7 @@ func jetBrainsIDESince(home, cfg string, year, minor int) bool {
|
||||
|
||||
// jetBrainsVersioned is an IDE's config folder name: the product, then its
|
||||
// year and release.
|
||||
var jetBrainsVersioned = regexp.MustCompile(`^[A-Za-z]+(\d{4})\.(\d+)$`)
|
||||
var jetBrainsVersioned = lazyre.New(`^[A-Za-z]+(\d{4})\.(\d+)$`)
|
||||
|
||||
// airAt is an Air agent on the acp.json at path: a, with its id, name,
|
||||
// icon and detection, gets the Magpie entry there and its OpenCode config
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/desktopdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -177,7 +177,7 @@ const claudeEffortEnv = "CLAUDE_CODE_EFFORT_LEVEL"
|
||||
// claudeNameRe finds the Claude model an id names, as Claude Code matches it
|
||||
// to its settings: claude-opus-5-5 in claude-opus-5-5[1m], in a dated id or
|
||||
// under a provider's prefix (anthropic/…).
|
||||
var claudeNameRe = regexp.MustCompile(`claude-(opus|sonnet|haiku|fable)-(\d+)(?:-(\d{1,2}))?(?:[^0-9]|$)`)
|
||||
var claudeNameRe = lazyre.New(`claude-(opus|sonnet|haiku|fable)-(\d+)(?:-(\d{1,2}))?(?:[^0-9]|$)`)
|
||||
|
||||
// claudeName is the Claude model a model id names, "" for another vendor's,
|
||||
// an alias (opus) or none. A version written with a dot (claude-opus-4.6)
|
||||
|
||||
@@ -40,7 +40,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -48,6 +47,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/desktopdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -893,7 +893,7 @@ func desktopSameJSON(a, b json.RawMessage) bool {
|
||||
// desktopLocaleName is a language Desktop takes for its "locale": the
|
||||
// names of its catalogs (lit in Desktop 2.7032's main process,
|
||||
// /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*\.json$/).
|
||||
var desktopLocaleName = regexp.MustCompile(`^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$`)
|
||||
var desktopLocaleName = lazyre.New(`^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$`)
|
||||
|
||||
// desktopLocaleFrom is the config.json, of every set's signed-in
|
||||
// userData, that names a language: the first set's (where Desktop runs)
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -32,6 +31,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/desktopdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -283,7 +283,7 @@ func (u *updater) shown() string {
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
var brewPath = regexp.MustCompile(`/(Cellar|Caskroom)/([^/]+)/`)
|
||||
var brewPath = lazyre.New(`/(Cellar|Caskroom)/([^/]+)/`)
|
||||
|
||||
// howInstalled says how the CLI at bin was installed, from where it is;
|
||||
// nil when that says nothing sure.
|
||||
@@ -523,7 +523,7 @@ func isDir(p string) bool { dir, ok := statKind(p); return ok && dir }
|
||||
|
||||
// ---- versions --------------------------------------------------------------
|
||||
|
||||
var versionRe = regexp.MustCompile(`(?:^|[^\w.])v?(\d+\.\d+(?:\.\d+)*(?:-[0-9A-Za-z][0-9A-Za-z.]*)?)`)
|
||||
var versionRe = lazyre.New(`(?:^|[^\w.])v?(\d+\.\d+(?:\.\d+)*(?:-[0-9A-Za-z][0-9A-Za-z.]*)?)`)
|
||||
|
||||
// parseVersion is the first version in what a CLI printed.
|
||||
func parseVersion(out string) string {
|
||||
@@ -1280,7 +1280,7 @@ func mendHint(u *updater, version string) string {
|
||||
return "run " + u.shown() + " again, or reinstall it the way you installed it"
|
||||
}
|
||||
|
||||
var ansiRe = regexp.MustCompile(`\x1b\[[0-9;?]*[ -/]*[@-~]`)
|
||||
var ansiRe = lazyre.New(`\x1b\[[0-9;?]*[ -/]*[@-~]`)
|
||||
|
||||
// lastLines is the last n lines of out with something on them, without
|
||||
// their colours.
|
||||
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ type shim struct {
|
||||
|
||||
// asdfExec is the line asdf's shims run: `exec asdf exec "claude" "$@"`
|
||||
// (asdf 0.16 on), `exec /home/u/.asdf/bin/asdf exec "claude" "$@"` before.
|
||||
var asdfExec = regexp.MustCompile(`(?m)^exec (\S*asdf) exec "`)
|
||||
var asdfExec = lazyre.New(`(?m)^exec (\S*asdf) exec "`)
|
||||
|
||||
// shimAt says whose shim bin is; nil when it is none, or the manager to ask
|
||||
// isn't here.
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -31,6 +30,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lastgood"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/sessions"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -2473,7 +2473,7 @@ var packedBudget int64 = 128 << 20
|
||||
// ccSwitchProvider matches the ids of the provider tables CC Switch writes
|
||||
// into Codex's config: "custom", and "cc-switch", "cc-switch-2"… from its
|
||||
// older versions. Its "cc-switch-official" is its own proxy to OpenAI.
|
||||
var ccSwitchProvider = regexp.MustCompile(`^(custom|cc-switch(-[0-9]+)?)$`)
|
||||
var ccSwitchProvider = lazyre.New(`^(custom|cc-switch(-[0-9]+)?)$`)
|
||||
|
||||
// codexBuiltinProvider is the providers Codex has built in, which a thread
|
||||
// can name with no table in config.toml (codex-rs model-provider-info:
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -39,6 +38,7 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -95,7 +95,7 @@ var codexReaders = func(at place) []CodexReader {
|
||||
return out
|
||||
}
|
||||
|
||||
var codexPackageVersionRe = regexp.MustCompile(`"version"\s*:\s*"([^"]+)"`)
|
||||
var codexPackageVersionRe = lazyre.New(`"version"\s*:\s*"([^"]+)"`)
|
||||
|
||||
// bundledCodexVersion is the version of the codex a Codex app bundle
|
||||
// ships (Contents/Resources/codex-cli/codex-package.json, "version":
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -35,6 +34,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
@@ -193,7 +193,7 @@ func cursorLocalProduct(res string) (cursorProduct, bool) {
|
||||
return p, strings.EqualFold(strings.TrimSpace(p.NameShort), cursorLocalName)
|
||||
}
|
||||
|
||||
var plistExeRe = regexp.MustCompile(`<key>CFBundleExecutable</key>\s*<string>([^<]+)</string>`)
|
||||
var plistExeRe = lazyre.New(`<key>CFBundleExecutable</key>\s*<string>([^<]+)</string>`)
|
||||
|
||||
// plistExecutable is CFBundleExecutable of an XML Info.plist, "" when it
|
||||
// can't be read.
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -226,8 +226,8 @@ func registeredExeDir(v string) string {
|
||||
}
|
||||
|
||||
var (
|
||||
plistIDRe = regexp.MustCompile(`<key>CFBundleIdentifier</key>\s*<string>([^<]+)</string>`)
|
||||
plistVersionRe = regexp.MustCompile(`<key>CFBundleShortVersionString</key>\s*<string>([^<]+)</string>`)
|
||||
plistIDRe = lazyre.New(`<key>CFBundleIdentifier</key>\s*<string>([^<]+)</string>`)
|
||||
plistVersionRe = lazyre.New(`<key>CFBundleShortVersionString</key>\s*<string>([^<]+)</string>`)
|
||||
)
|
||||
|
||||
// macBundle reports whether app's bundle is in one of appFolders, under one
|
||||
@@ -491,7 +491,7 @@ func (app desktopApp) linuxDir() string {
|
||||
return dir
|
||||
}
|
||||
|
||||
var linuxPackageVersionRe = regexp.MustCompile(`"version"\s*:\s*"([^"]+)"`)
|
||||
var linuxPackageVersionRe = lazyre.New(`"version"\s*:\s*"([^"]+)"`)
|
||||
|
||||
// linuxVersion is the version of the app's Linux package, from its
|
||||
// resources/linux-package-metadata.json ({"codexAppBrand":"chatgpt",
|
||||
|
||||
@@ -48,7 +48,6 @@ import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -60,6 +59,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -222,12 +222,12 @@ func droidBuiltin(ref string) string {
|
||||
// matches droidGPT, bar gpt-image and gpt-transcribe, which no chat
|
||||
// catalog lists.
|
||||
var (
|
||||
droidGPT = []*regexp.Regexp{
|
||||
regexp.MustCompile(`(?i)\bgpt[-_.]?\d`),
|
||||
regexp.MustCompile(`(?i)codex`),
|
||||
regexp.MustCompile(`(?i)\bo[1-9](?:[-_.]|$)`),
|
||||
droidGPT = []*lazyre.RE{
|
||||
lazyre.New(`(?i)\bgpt[-_.]?\d`),
|
||||
lazyre.New(`(?i)codex`),
|
||||
lazyre.New(`(?i)\bo[1-9](?:[-_.]|$)`),
|
||||
}
|
||||
droidClaude = regexp.MustCompile(`(?i)claude|haiku|sonnet|opus`)
|
||||
droidClaude = lazyre.New(`(?i)claude|haiku|sonnet|opus`)
|
||||
)
|
||||
|
||||
// droidWants is the provider droid asks for a custom model by its "model",
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -51,6 +50,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -629,7 +629,7 @@ type dshItem struct {
|
||||
lines []string
|
||||
}
|
||||
|
||||
var dshIDLine = regexp.MustCompile(`^(?:- | )id:\s*['"]?([^'"#\s]+)['"]?\s*(#.*)?$`)
|
||||
var dshIDLine = lazyre.New(`^(?:- | )id:\s*['"]?([^'"#\s]+)['"]?\s*(#.*)?$`)
|
||||
|
||||
// dshParse splits the patch list at path into what comes before its first
|
||||
// entry and the entries. A list written in flow style ([ {id: a} ], which
|
||||
@@ -984,7 +984,7 @@ func dshRouteLists(route *yaml.Node, id string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var dshModelLine = regexp.MustCompile(`^\s+model:\s*(.+?)\s*$`)
|
||||
var dshModelLine = lazyre.New(`^\s+model:\s*(.+?)\s*$`)
|
||||
|
||||
// dshLead is the profile whose start magpie shows: the one named lead
|
||||
// when there is one (the desktop app's when DeepSeek Harness Desktop is
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Goose (Block's goose, its CLI and desktop app alike) reaches magpie as a
|
||||
@@ -48,7 +48,7 @@ const gooseProviderID = magpieID
|
||||
// thinking_effort is one of its own request params, never sent — so a
|
||||
// level offered for it would change nothing; it is declared without
|
||||
// reasoning rather than shown a picker that does nothing.
|
||||
var gooseThinks = regexp.MustCompile(`(?i)(?:^|[-/])(?:o\d+(?:$|-)|gpt-(?:5|6)(?:$|[-.]))`)
|
||||
var gooseThinks = lazyre.New(`(?i)(?:^|[-/])(?:o\d+(?:$|-)|gpt-(?:5|6)(?:$|[-.]))`)
|
||||
|
||||
// gooseKeys are the secrets goose reads for the native providers whose
|
||||
// models magpie can list, and which goose takes from the environment before
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -43,6 +42,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -338,7 +338,7 @@ func hermesProfileFields(at place, dir string) []Field {
|
||||
|
||||
// hermesProfileID is the name a Hermes profile may have
|
||||
// (hermes_constants.PROFILE_ID_RE).
|
||||
var hermesProfileID = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,63}$`)
|
||||
var hermesProfileID = lazyre.New(`^[a-z0-9][a-z0-9_-]{0,63}$`)
|
||||
|
||||
// hermesProfiles is the config.yaml of each of Hermes's own profiles (its
|
||||
// bots), as Hermes lists them (hermes_cli/profiles.py): the root's own, and
|
||||
@@ -842,12 +842,12 @@ func hermesKept(at place, path, name string, e hermesProviderEntry) any {
|
||||
// hermesEnvRef is a reference in a value of Hermes's config.yaml, which
|
||||
// Hermes expands as it loads it: ${VAR}, or ${env:VAR}
|
||||
// (hermes_cli/config.py _ENV_REF_RE, _env_expand_match).
|
||||
var hermesEnvRef = regexp.MustCompile(`\$\{([^}]+)\}`)
|
||||
var hermesEnvRef = lazyre.New(`\$\{([^}]+)\}`)
|
||||
|
||||
// hermesSecretSource starts a reference to a secret source other than the
|
||||
// environment (${vault:...}, ${bitwarden:...}), which Hermes leaves as it
|
||||
// is in config.yaml (_is_non_env_secret_ref).
|
||||
var hermesSecretSource = regexp.MustCompile(`^[a-z][a-z0-9_-]*:`)
|
||||
var hermesSecretSource = lazyre.New(`^[a-z][a-z0-9_-]*:`)
|
||||
|
||||
// hermesRefVar is the variable the body of a reference reads, "" for
|
||||
// another source or an empty ${env:} (_env_ref_var_name).
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"bytes"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/access"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -72,13 +72,13 @@ func magpieFile(path string) bool {
|
||||
}
|
||||
|
||||
// originRE is an http(s) URL's scheme and host, as it is written in a file.
|
||||
var originRE = regexp.MustCompile(`https?://[A-Za-z0-9.\-_\[\]:%]+`)
|
||||
var originRE = lazyre.New(`https?://[A-Za-z0-9.\-_\[\]:%]+`)
|
||||
|
||||
// keyLineRE is a key and its value as a JSON, JSONC, YAML, TOML or .env
|
||||
// file writes it: "apiKey": "x", api_key = "x", apiKey: x, KEY=x; not one
|
||||
// whose value is an object or a list. The value is group 4 when quoted with
|
||||
// ", 5 with ', 6 bare.
|
||||
var keyLineRE = regexp.MustCompile(`(["']?)([A-Za-z0-9_\-]+)(["']?)[ \t]*[:=][ \t]*(?:"((?:[^"\\\n]|\\.)*)"|'([^'\n]*)'|([^\s"',{}\[\]#][^\n"',}\]#]*))`)
|
||||
var keyLineRE = lazyre.New(`(["']?)([A-Za-z0-9_\-]+)(["']?)[ \t]*[:=][ \t]*(?:"((?:[^"\\\n]|\\.)*)"|'([^'\n]*)'|([^\s"',{}\[\]#][^\n"',}\]#]*))`)
|
||||
|
||||
// keyName says a key of that name holds what an agent sends the gateway to
|
||||
// be let in: apiKey, api_key, MAGPIE_QWEN_API_KEY, experimental_bearer_token,
|
||||
@@ -208,7 +208,7 @@ func (k kept) away(path string, data []byte) []byte {
|
||||
}
|
||||
|
||||
// urlRE is an http(s) URL with its path, as it is written in a file.
|
||||
var urlRE = regexp.MustCompile(`https?://[^\s"'<>,{}\[\]\\]+`)
|
||||
var urlRE = lazyre.New(`https?://[^\s"'<>,{}\[\]\\]+`)
|
||||
|
||||
// awayPath is the path before magpie's own that the address away keeps in
|
||||
// was, the file before a sync wrote data with the gateway's address g: the
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -23,6 +22,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -89,12 +89,12 @@ func ompYAMLList(v string) bool { return strings.HasPrefix(v, "[") || strings.Ha
|
||||
|
||||
// ompProfileName is a profile name omp takes (pi-utils dirs.ts,
|
||||
// normalizeProfileName); it refuses any other.
|
||||
var ompProfileName = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
var ompProfileName = lazyre.New(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
|
||||
// ompReserved is a Windows device name omp refuses on every platform
|
||||
// (pi-utils dirs.ts, normalizeProfileName): CON, PRN, AUX, NUL, COM0–COM9,
|
||||
// LPT0–LPT9, and the same with a dot and anything after (con.work).
|
||||
var ompReserved = regexp.MustCompile(`(?i)^(?:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\..*)?$`)
|
||||
var ompReserved = lazyre.New(`(?i)^(?:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\..*)?$`)
|
||||
|
||||
// ompProfileOK says whether name is one omp takes as a profile (pi-utils
|
||||
// dirs.ts): "default" is none, a trailing dot is refused, and so is a
|
||||
|
||||
@@ -47,7 +47,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
@@ -55,6 +54,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// openBotFile is the file of OpenBot's custom endpoints in its userData.
|
||||
@@ -70,7 +70,7 @@ const openBotMaxModels = 64
|
||||
|
||||
// openBotModelID is a model id OpenBot lists as magpie/<id>
|
||||
// (isAgentModel, ipc-agent-identity.ts).
|
||||
var openBotModelID = regexp.MustCompile(`^[A-Za-z0-9._:/\[\],=-]+$`)
|
||||
var openBotModelID = lazyre.New(`^[A-Za-z0-9._:/\[\],=-]+$`)
|
||||
|
||||
// openBotProc is OpenBot's process: the .app's and the .exe's OpenBot, the
|
||||
// AppImage's openbot.
|
||||
|
||||
@@ -46,7 +46,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -56,6 +55,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/beat"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -105,7 +105,7 @@ const ombFleet = `{
|
||||
// ombModelID is the model id OpenMausBot takes for a Claude endpoint
|
||||
// (server/drivers/claude-model-extras.ts's CLAUDE_MODEL_ID); one other id
|
||||
// in the list makes it refuse the whole engine.
|
||||
var ombModelID = regexp.MustCompile(`(?i)^[a-z0-9][a-z0-9._:/-]*(?:\[1m\])?$`)
|
||||
var ombModelID = lazyre.New(`(?i)^[a-z0-9][a-z0-9._:/-]*(?:\[1m\])?$`)
|
||||
|
||||
// ombRouting is the environment that picks Claude Code's endpoint and
|
||||
// sign-in (config.ts's CLAUDE_ROUTING_ENV): magpie's on its engine, so none
|
||||
|
||||
@@ -10,13 +10,13 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
@@ -560,7 +560,7 @@ func splitLines(s string) []string {
|
||||
|
||||
// lineKey is what a line sets: TOML's and .env's key before =, JSON's and
|
||||
// YAML's before :, "" for a line that sets nothing.
|
||||
var keyRe = regexp.MustCompile(`^\s*(?:export\s+)?"?([A-Za-z0-9_.\-]+)"?\s*[:=]`)
|
||||
var keyRe = lazyre.New(`^\s*(?:export\s+)?"?([A-Za-z0-9_.\-]+)"?\s*[:=]`)
|
||||
|
||||
func lineKey(l string) string {
|
||||
if m := keyRe.FindStringSubmatch(l); m != nil {
|
||||
@@ -574,7 +574,7 @@ func lineKey(l string) string {
|
||||
|
||||
func indent(l string) string { return l[:len(l)-len(strings.TrimLeft(l, " \t"))] }
|
||||
|
||||
var secretKey = regexp.MustCompile(`(?i)(key|token|secret|password|auth)`)
|
||||
var secretKey = lazyre.New(`(?i)(key|token|secret|password|auth)`)
|
||||
|
||||
// mask hides the value of a line whose key reads as a secret's; magpie's
|
||||
// own token, which is no secret, stays.
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -21,12 +20,13 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
const reasonixKey = "MAGPIE_REASONIX_API_KEY"
|
||||
|
||||
var reasonixKeyLine = regexp.MustCompile(`(?m)^\s*(?:export\s+)?` + reasonixKey + `\s*=`)
|
||||
var reasonixKeyLine = lazyre.New(`(?m)^\s*(?:export\s+)?` + reasonixKey + `\s*=`)
|
||||
|
||||
// Every API request and catalog sync constructs its own Agent. The transaction
|
||||
// must cover the whole edit and rollback across those instances, including reads.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -206,7 +206,7 @@ func sameModel(opts []Option, ref, agent string) Option {
|
||||
return alike
|
||||
}
|
||||
|
||||
var dated = regexp.MustCompile(`-(\d{8}|\d{4}-\d{2}-\d{2})$`)
|
||||
var dated = lazyre.New(`-(\d{8}|\d{4}-\d{2}-\d{2})$`)
|
||||
|
||||
// modelKey is a model id as providers agree on it: its last part, lower
|
||||
// case, with dots and underscores as dashes and no date.
|
||||
|
||||
@@ -56,7 +56,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -65,6 +64,7 @@ import (
|
||||
|
||||
"github.com/MoeForge/moejs"
|
||||
"github.com/yetone/magpie/internal/jsmod"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
)
|
||||
|
||||
@@ -160,7 +160,7 @@ var (
|
||||
|
||||
var errTimeout = errors.New("took too long")
|
||||
|
||||
var idOK = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
var idOK = lazyre.New(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
|
||||
type set struct {
|
||||
stamp string
|
||||
|
||||
@@ -25,13 +25,13 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -214,15 +214,15 @@ func (q quiet) Write(p []byte) (int, error) {
|
||||
// keeps its first characters, for telling which it was, and masks the
|
||||
// rest.
|
||||
var secrets = []struct {
|
||||
re *regexp.Regexp
|
||||
re *lazyre.RE
|
||||
keep string
|
||||
}{
|
||||
{regexp.MustCompile(`(?i)\b((?:bearer|basic)\s+)[A-Za-z0-9._~+/=-]{8,}`), "${1}…"},
|
||||
{regexp.MustCompile(`(?i)([?&](?:key|api[_-]?key|apikey|access_token|refresh_token|id_token|token|auth|sig|signature|code)=)[^&\s"'<>]+`), "${1}…"},
|
||||
{regexp.MustCompile(`\b(sk-(?:ant-|proj-)?)[A-Za-z0-9_-]{12,}`), "${1}…"},
|
||||
{regexp.MustCompile(`\b(AIza)[0-9A-Za-z_-]{20,}`), "${1}…"},
|
||||
{regexp.MustCompile(`\b(gh[opsur]_)[A-Za-z0-9]{20,}`), "${1}…"},
|
||||
{regexp.MustCompile(`\b(eyJ)[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), "${1}…"},
|
||||
{lazyre.New(`(?i)\b((?:bearer|basic)\s+)[A-Za-z0-9._~+/=-]{8,}`), "${1}…"},
|
||||
{lazyre.New(`(?i)([?&](?:key|api[_-]?key|apikey|access_token|refresh_token|id_token|token|auth|sig|signature|code)=)[^&\s"'<>]+`), "${1}…"},
|
||||
{lazyre.New(`\b(sk-(?:ant-|proj-)?)[A-Za-z0-9_-]{12,}`), "${1}…"},
|
||||
{lazyre.New(`\b(AIza)[0-9A-Za-z_-]{20,}`), "${1}…"},
|
||||
{lazyre.New(`\b(gh[opsur]_)[A-Za-z0-9]{20,}`), "${1}…"},
|
||||
{lazyre.New(`\b(eyJ)[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), "${1}…"},
|
||||
}
|
||||
|
||||
// scrub is p with whatever looks like a key or token masked.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const label = "com.yetone.magpie"
|
||||
@@ -21,7 +22,7 @@ func record() string {
|
||||
// launchd loads no job that names neither its own label nor a program to
|
||||
// run: a record a write left short of either sits in LaunchAgents, is
|
||||
// refused, and magpie never opens at login however long the file is there.
|
||||
var ourLabel = regexp.MustCompile(`<key>Label</key>\s*<string>` + regexp.QuoteMeta(label) + `</string>`)
|
||||
var ourLabel = lazyre.New(`<key>Label</key>\s*<string>` + regexp.QuoteMeta(label) + `</string>`)
|
||||
|
||||
func enabled() bool {
|
||||
b, err := os.ReadFile(record())
|
||||
@@ -88,7 +89,7 @@ func plist(exe string) []byte {
|
||||
`, label, html.EscapeString(exe), Arg, associated(exe)))
|
||||
}
|
||||
|
||||
var bundleID = regexp.MustCompile(`<key>CFBundleIdentifier</key>\s*<string>([^<]+)</string>`)
|
||||
var bundleID = lazyre.New(`<key>CFBundleIdentifier</key>\s*<string>([^<]+)</string>`)
|
||||
|
||||
// associated is the AssociatedBundleIdentifiers entry for the app exe sits
|
||||
// in, read from that app's own Info.plist, so a build with another id
|
||||
@@ -112,7 +113,7 @@ func associated(exe string) string {
|
||||
|
||||
// with a path in the first string: an empty one names nothing to run, and
|
||||
// launchd refuses the job
|
||||
var program = regexp.MustCompile(`<key>ProgramArguments</key>\s*<array><string>([^<]+)</string>`)
|
||||
var program = lazyre.New(`<key>ProgramArguments</key>\s*<array><string>([^<]+)</string>`)
|
||||
|
||||
// refresh writes a launch agent an older magpie wrote over as this one
|
||||
// would, for the program it names: the path stays the one the user turned
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -220,7 +220,7 @@ func autoSignIns(c AutoConfig) (autoSealed, error) {
|
||||
// autoName is a backup's file name; anything else in the folder (the
|
||||
// temporary file one is written to, the user's own files) is never listed,
|
||||
// put back or removed.
|
||||
var autoName = regexp.MustCompile(`^magpie-(\d{8}-\d{6})(?:-\d+)?-(auto|restore)\.json$`)
|
||||
var autoName = lazyre.New(`^magpie-(\d{8}-\d{6})(?:-\d+)?-(auto|restore)\.json$`)
|
||||
|
||||
const autoTemp = ".magpie-backup-*.tmp"
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -24,6 +23,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Model is one entry the picker can offer.
|
||||
@@ -1610,7 +1610,7 @@ var relayPrefixes = []string{"claude-"}
|
||||
// a model another of them lists is (openai-, databricks-, doubao-, zai-):
|
||||
// the model after it is the same model, its window, levels and images
|
||||
// included.
|
||||
var channelPrefix = regexp.MustCompile(`^[a-z]{2,24}-`)
|
||||
var channelPrefix = lazyre.New(`^[a-z]{2,24}-`)
|
||||
|
||||
// renamed is the model a relay renamed to b, when models.dev lists none
|
||||
// by b (found), and the window the rename names, if any: a window mark
|
||||
@@ -1812,7 +1812,7 @@ func levelIndexOf(all map[string]mdProvider, at int, pid string) *levelIndex {
|
||||
// channel lists gemini-3.8-flash-high, claude-opus-5-5-high,
|
||||
// claude-opus-4-6-thinking and gpt-oss-120b-medium, and its xAI channel
|
||||
// grok-3-mini-fast. Its "(high)" form is found's.
|
||||
var variantSuffix = regexp.MustCompile(`(?i)-(minimal|low|medium|high|xhigh|max|thinking|fast)$`)
|
||||
var variantSuffix = lazyre.New(`(?i)-(minimal|low|medium|high|xhigh|max|thinking|fast)$`)
|
||||
|
||||
// Unsuffixed is id with a proxy's level or speed word taken off
|
||||
// (variantSuffix), and whether it had one. It is for borrowing levels a
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package catalog
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// A model's family is its id with the version numbers taken out, so that
|
||||
@@ -38,16 +39,16 @@ type Family struct {
|
||||
}
|
||||
|
||||
var (
|
||||
familySep = regexp.MustCompile(`[-_/:@\[\]\s]+`)
|
||||
familySep = lazyre.New(`[-_/:@\[\]\s]+`)
|
||||
// a number: 4, 4.5, 2.0
|
||||
familyNum = regexp.MustCompile(`^\d+(?:\.\d+)*$`)
|
||||
familyNum = lazyre.New(`^\d+(?:\.\d+)*$`)
|
||||
// a word that ends in its version: qwen3, qwen2.5, o4, k2, v1, llama3.1
|
||||
familyTail = regexp.MustCompile(`^([a-z][a-z.]*?[a-z])(\d+(?:\.\d+)*)$|^([a-z])(\d+(?:\.\d+)*)$`)
|
||||
familyTail = lazyre.New(`^([a-z][a-z.]*?[a-z])(\d+(?:\.\d+)*)$|^([a-z])(\d+(?:\.\d+)*)$`)
|
||||
// a word that starts with its version: 4o, 4.5v, 3n
|
||||
familyHead = regexp.MustCompile(`^(\d+(?:\.\d+)*)([a-z]+)$`)
|
||||
familyHead = lazyre.New(`^(\d+(?:\.\d+)*)([a-z]+)$`)
|
||||
// a size, kept in the name: 8b, 1.5b, 70b, 128e, 32k, 8x7b, a22b, e4b
|
||||
familySize = regexp.MustCompile(`^(?:[a-z]?\d+(?:\.\d+)?|\d+x\d+(?:\.\d+)?)[bmkte]$`)
|
||||
familyYear = regexp.MustCompile(`^(?:19|20)\d\d$`)
|
||||
familySize = lazyre.New(`^(?:[a-z]?\d+(?:\.\d+)?|\d+x\d+(?:\.\d+)?)[bmkte]$`)
|
||||
familyYear = lazyre.New(`^(?:19|20)\d\d$`)
|
||||
)
|
||||
|
||||
var familyPreview = map[string]bool{"preview": true, "exp": true, "experimental": true, "beta": true, "alpha": true}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package catalog
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// SameModel is a model's name as vendors agree on it: lowercase, without
|
||||
@@ -71,7 +72,7 @@ func snapshotDate(s string) bool {
|
||||
|
||||
// modelGaps are what SameModel spells as one "-": a run of spaces (a
|
||||
// no-break one too), "_" and "-".
|
||||
var modelGaps = regexp.MustCompile(`[\s\p{Zs}_-]+`)
|
||||
var modelGaps = lazyre.New(`[\s\p{Zs}_-]+`)
|
||||
|
||||
// singleDashes is whether modelGaps leaves k as it is: no gap in it but
|
||||
// single "-"s.
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/libc"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
@@ -50,7 +51,7 @@ func exeName(goos string) string {
|
||||
return "claude"
|
||||
}
|
||||
|
||||
var versionRe = regexp.MustCompile(`^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$`)
|
||||
var versionRe = lazyre.New(`^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$`)
|
||||
|
||||
// Downloaded is the Claude Code magpie downloaded and its version, or ""
|
||||
// when there is none: the newest of Root's versions that has the binary.
|
||||
|
||||
+27
-27
@@ -29,7 +29,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -39,6 +38,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/wslrun"
|
||||
)
|
||||
|
||||
@@ -357,7 +357,7 @@ func (s *shim) read() {
|
||||
}
|
||||
}
|
||||
|
||||
var ansi = regexp.MustCompile(`\x1b\[[0-9;?<>=]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[P^_][^\x1b]*\x1b\\|\x1b.`)
|
||||
var ansi = lazyre.New(`\x1b\[[0-9;?<>=]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[P^_][^\x1b]*\x1b\\|\x1b.`)
|
||||
|
||||
// plain is what Claude Code drew since the screen was last cleared
|
||||
// (clearScreen), its escapes taken out.
|
||||
@@ -457,17 +457,17 @@ func (s *shim) lastScreen() string {
|
||||
}
|
||||
|
||||
var (
|
||||
trustNo = regexp.MustCompile(`❯\s*No,\s*exit`)
|
||||
trustYes = regexp.MustCompile(`❯\s*Yes,\s*I trust`)
|
||||
trustNo = lazyre.New(`❯\s*No,\s*exit`)
|
||||
trustYes = lazyre.New(`❯\s*Yes,\s*I trust`)
|
||||
// the Bypass Permissions disclaimer's Yes (#5042): the disclaimer
|
||||
// pairs the same "No, exit" with it as the trust question does
|
||||
bypassYes = regexp.MustCompile(`❯\s*Yes,\s*I accept`)
|
||||
bypassYes = lazyre.New(`❯\s*Yes,\s*I accept`)
|
||||
// how long a Yes stays drawn before Enter is pressed on it
|
||||
trustSettle = 300 * time.Millisecond
|
||||
)
|
||||
|
||||
// lastAt is where re's last match in p starts, -1 with none.
|
||||
func lastAt(re *regexp.Regexp, p string) int {
|
||||
func lastAt(re *lazyre.RE, p string) int {
|
||||
m := re.FindAllStringIndex(p, -1)
|
||||
if len(m) == 0 {
|
||||
return -1
|
||||
@@ -500,7 +500,7 @@ var errUntrusted = errors.New(Untrusted + ", which only its user answers")
|
||||
// signIn is what Claude Code's interactive mode shows where it is not
|
||||
// signed in, as -p may be (CLAUDE_CODE_OAUTH_TOKEN, a container whose
|
||||
// ~/.claude.json has no onboarding done): nothing the helper may answer.
|
||||
var signIn = regexp.MustCompile(`Select login method|Log in with your Claude account|claude\.ai/oauth/authorize`)
|
||||
var signIn = lazyre.New(`Select login method|Log in with your Claude account|claude\.ai/oauth/authorize`)
|
||||
|
||||
// The screens Claude Code's interactive mode shows where its onboarding
|
||||
// isn't done (a config folder only -p was run in, or one signed in where
|
||||
@@ -514,8 +514,8 @@ var signIn = regexp.MustCompile(`Select login method|Log in with your Claude acc
|
||||
// words, any space between them one: Claude Code draws some by moving the
|
||||
// cursor.
|
||||
var (
|
||||
firstRun = regexp.MustCompile(`Security notes:.*Press Enter to continue`)
|
||||
terminalSetup = regexp.MustCompile(`terminal setup\?.*Esc to skip`)
|
||||
firstRun = lazyre.New(`Security notes:.*Press Enter to continue`)
|
||||
terminalSetup = lazyre.New(`terminal setup\?.*Esc to skip`)
|
||||
)
|
||||
|
||||
// onboardTries is how often one onboarding screen is answered before the
|
||||
@@ -921,7 +921,7 @@ func usageDrawn(screen string) bool {
|
||||
// limiting requests to the usage page (not your usage limit). Try again
|
||||
// in a moment.", "Error: Usage endpoint is rate limited until 12:11am."),
|
||||
// which were read as a panel with no window.
|
||||
var usageFailed = regexp.MustCompile(`Failed to load usage data|limiting requests to the usage page|Usage endpoint is rate limited`)
|
||||
var usageFailed = lazyre.New(`Failed to load usage data|limiting requests to the usage page|Usage endpoint is rate limited`)
|
||||
|
||||
// NoUsageWindow is what the helper tells for a /usage panel that loaded
|
||||
// with none of the account's windows drawn: each is left out until the
|
||||
@@ -929,7 +929,7 @@ var usageFailed = regexp.MustCompile(`Failed to load usage data|limiting request
|
||||
const NoUsageWindow = "No usage window has started"
|
||||
|
||||
// usageWindow is one of the account's windows as usageText tells it.
|
||||
var usageWindow = regexp.MustCompile(`(?m)^Current (?:session|week)\b`)
|
||||
var usageWindow = lazyre.New(`(?m)^Current (?:session|week)\b`)
|
||||
|
||||
// usageNoWindow says whether screen is /usage's panel loaded, its figures
|
||||
// told, with none of the account's windows among them: the Usage tab's
|
||||
@@ -951,11 +951,11 @@ func usageNoWindow(screen string) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
usageSession = regexp.MustCompile(`\bSession\b|\bTotal cost:`)
|
||||
usageCurrent = regexp.MustCompile(`\bCurrent (?:session|week)\b`)
|
||||
usageSession = lazyre.New(`\bSession\b|\bTotal cost:`)
|
||||
usageCurrent = lazyre.New(`\bCurrent (?:session|week)\b`)
|
||||
// the panel's "Error: …", however many rows it wraps to, up to the
|
||||
// keys it draws under it ("r to retry · Esc to cancel")
|
||||
usageError = regexp.MustCompile(`\bError: .*?(?: r to retry\b|$)`)
|
||||
usageError = lazyre.New(`\bError: .*?(?: r to retry\b|$)`)
|
||||
)
|
||||
|
||||
// usagePart is the words of /usage's panel in t (its fields joined) that
|
||||
@@ -972,7 +972,7 @@ func usagePart(t string) string {
|
||||
return strings.Join(strings.Fields(usageCost.ReplaceAllString(t[at[0]:], "")), " ")
|
||||
}
|
||||
|
||||
var usageCost = regexp.MustCompile(`\bTotal cost:.*?\bcache write\b`)
|
||||
var usageCost = lazyre.New(`\bTotal cost:.*?\bcache write\b`)
|
||||
|
||||
// usageWhy is why /usage's panel told no figures, as it says it: its
|
||||
// "Error: …" whole, else what it drew from its tabs on, not Claude Code's
|
||||
@@ -993,16 +993,16 @@ func usageWhy(screen string) string {
|
||||
// own replies ("Partial usage data", "Could not refresh usage data") are
|
||||
// today's, and are told.
|
||||
var (
|
||||
usageRefreshing = regexp.MustCompile(`\bRefreshing(?:…|\.\.\.)`)
|
||||
usageStale = regexp.MustCompile(`Showing last-known usage[^\n]*?\)|Showing last-known usage`)
|
||||
usageRefreshing = lazyre.New(`\bRefreshing(?:…|\.\.\.)`)
|
||||
usageStale = lazyre.New(`Showing last-known usage[^\n]*?\)|Showing last-known usage`)
|
||||
)
|
||||
|
||||
var (
|
||||
usageName = regexp.MustCompile(`^(session|week(?: \([^)]*\))?)`)
|
||||
usageUsed = regexp.MustCompile(`([0-9.]+)%\s+used`)
|
||||
usageReset = regexp.MustCompile(`Resets (.*?\))`)
|
||||
usagePanel = regexp.MustCompile(`\bSettings\b.*\bUsage\b`)
|
||||
usageLoading = regexp.MustCompile(`(?i)\bloading\b`)
|
||||
usageName = lazyre.New(`^(session|week(?: \([^)]*\))?)`)
|
||||
usageUsed = lazyre.New(`([0-9.]+)%\s+used`)
|
||||
usageReset = lazyre.New(`Resets (.*?\))`)
|
||||
usagePanel = lazyre.New(`\bSettings\b.*\bUsage\b`)
|
||||
usageLoading = lazyre.New(`(?i)\bloading\b`)
|
||||
)
|
||||
|
||||
// usageText is the plan's allowance as /usage's panel shows it, each
|
||||
@@ -1265,11 +1265,11 @@ func (s *shim) send(pieces []piece) error {
|
||||
return fmt.Errorf("Claude Code did not take the message: %s", s.lastScreen())
|
||||
}
|
||||
|
||||
var imageShown = regexp.MustCompile(`\[Image #(\d+)\]`)
|
||||
var imageShown = lazyre.New(`\[Image #(\d+)\]`)
|
||||
|
||||
// promptRule is a row of the rules Claude Code draws over and under its
|
||||
// prompt.
|
||||
var promptRule = regexp.MustCompile(`^\s*─{20,}\s*$`)
|
||||
var promptRule = lazyre.New(`^\s*─{20,}\s*$`)
|
||||
|
||||
// prompt is the prompt as the screen shows it, its words one space apart:
|
||||
// the rows between the screen's last two rules, "" with no such rows. A
|
||||
@@ -1304,7 +1304,7 @@ func (s *shim) prompt() string {
|
||||
// lastMark is the number of the mark re matches at the end of the prompt
|
||||
// as the screen shows it (prompt), 0 with none: the paste taken last, as
|
||||
// a paste goes where the prompt's words end.
|
||||
func lastMark(re *regexp.Regexp, prompt string) int {
|
||||
func lastMark(re *lazyre.RE, prompt string) int {
|
||||
m := re.FindAllStringSubmatchIndex(prompt, -1)
|
||||
if len(m) == 0 || m[len(m)-1][1] != len(prompt) {
|
||||
return 0
|
||||
@@ -1314,7 +1314,7 @@ func lastMark(re *regexp.Regexp, prompt string) int {
|
||||
}
|
||||
|
||||
// textLast is Claude Code's whole mark of a long paste.
|
||||
var textLast = regexp.MustCompile(`\[Pasted text #(\d+) \+\d+ lines\]`)
|
||||
var textLast = lazyre.New(`\[Pasted text #(\d+) \+\d+ lines\]`)
|
||||
|
||||
// path is where Claude Code reads a file of the helper's at path: one in
|
||||
// WSL under the distro's mount of the drive.
|
||||
@@ -1373,7 +1373,7 @@ func shownWait(n int) time.Duration {
|
||||
return pasteWait + time.Duration(n/(64<<10))*time.Second
|
||||
}
|
||||
|
||||
var textShown = regexp.MustCompile(`\[Pasted text #(\d+)`)
|
||||
var textShown = lazyre.New(`\[Pasted text #(\d+)`)
|
||||
|
||||
// shown waits for the prompt to show pasted text: its last words, or
|
||||
// Claude Code's "[Pasted text #<n>" for a long one, numbered past after,
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -43,7 +43,7 @@ var wslReadCommand = func(distro, sid string) *exec.Cmd {
|
||||
// how long the shell has to say it is ready
|
||||
var wslReadWait = 30 * time.Second
|
||||
|
||||
var sidRe = regexp.MustCompile(`^[0-9A-Za-z-]+$`)
|
||||
var sidRe = lazyre.New(`^[0-9A-Za-z-]+$`)
|
||||
|
||||
// wslRead is a transcript read inside the distro, copied to path.
|
||||
type wslRead struct {
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -26,6 +25,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/imagemcp"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const toolUsage = `usage:
|
||||
@@ -645,7 +645,7 @@ func (a toolAnswer) text() string {
|
||||
|
||||
// stillMaking is the id an answer says to wait on with generation_result;
|
||||
// a gateway older than PendingMeta says it in its text alone.
|
||||
var stillMakingText = regexp.MustCompile(gateway.GenerationResultTool + ` with id "([^"]+)"`)
|
||||
var stillMakingText = lazyre.New(gateway.GenerationResultTool + ` with id "([^"]+)"`)
|
||||
|
||||
func (a toolAnswer) pending() string {
|
||||
var id string
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -332,7 +332,7 @@ type model struct {
|
||||
// DeepSeek's own deepseek-flash, a found auto/deepseek-flash), named by
|
||||
// the model's own id after its provider's. A routing group is not one: it
|
||||
// may hand the turn to any model.
|
||||
var deepSeekModel = regexp.MustCompile(`(?i)^deepseek-(v[4-9]|v\d\d|flash|pro|chat|reasoner)`)
|
||||
var deepSeekModel = lazyre.New(`(?i)^deepseek-(v[4-9]|v\d\d|flash|pro|chat|reasoner)`)
|
||||
|
||||
func deepSeek(id string) bool {
|
||||
if strings.HasPrefix(id, "group/") {
|
||||
@@ -566,7 +566,7 @@ func Keep(cur, b []byte) []byte {
|
||||
|
||||
// datedSuffix is a snapshot's date after a model's id (-2026-09-14,
|
||||
// -20260914).
|
||||
var datedSuffix = regexp.MustCompile(`-(\d{4}-\d{2}-\d{2}|\d{8})$`)
|
||||
var datedSuffix = lazyre.New(`-(\d{4}-\d{2}-\d{2}|\d{8})$`)
|
||||
|
||||
// agentsEffort is the multi_agent_reasoning_effort of Codex's own entry for
|
||||
// the model a third-party one serves (s2a/gpt-6-astra, openai/gpt-6-astra on
|
||||
@@ -591,7 +591,7 @@ func agentsEffort(own map[string]map[string]any, m catalog.Model) string {
|
||||
}
|
||||
|
||||
// gptModel is an OpenAI model's id, as a relay may serve it: gpt-6-sol, o4.
|
||||
var gptModel = regexp.MustCompile(`^(gpt-|o\d)`)
|
||||
var gptModel = lazyre.New(`^(gpt-|o\d)`)
|
||||
|
||||
// ownTiers are the service tiers Codex's own entry gives the model a
|
||||
// provider the user added by its address serves (openai/gpt-6-sol on a
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/autostart"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -161,10 +162,10 @@ func Web() (addr, key string) {
|
||||
}
|
||||
|
||||
var (
|
||||
webArgRe = regexp.MustCompile(`(?:"|<string>)` + regexp.QuoteMeta(webFlag) + `([^"<\s]+)(?:"|</string>)`)
|
||||
webArgRe = lazyre.New(`(?:"|<string>)` + regexp.QuoteMeta(webFlag) + `([^"<\s]+)(?:"|</string>)`)
|
||||
// a unit's Environment="MAGPIE_WEB_KEY=…", a plist's
|
||||
// <key>MAGPIE_WEB_KEY</key><string>…</string>
|
||||
webKeyRe = regexp.MustCompile(webKeyVar + `(?:=|</key><string>)([A-Za-z0-9._~-]+)`)
|
||||
webKeyRe = lazyre.New(webKeyVar + `(?:=|</key><string>)([A-Za-z0-9._~-]+)`)
|
||||
)
|
||||
|
||||
// TLS is the certificate and key files the installed service serves
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/yetone/magpie/internal/backup"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// ServerFile is what the server held, or answered with, where the backup
|
||||
@@ -128,8 +128,8 @@ func described(c Config, data []byte, err error) error {
|
||||
return ¬Backup{f: whatIs(data), where: fileWhere(c), cmd: cmdOf(c), err: err}
|
||||
}
|
||||
|
||||
var titleRe = regexp.MustCompile(`(?is)<title[^>]*>(.*?)</title>`)
|
||||
var rootRe = regexp.MustCompile(`<([A-Za-z_][\w.:-]*)`)
|
||||
var titleRe = lazyre.New(`(?is)<title[^>]*>(.*?)</title>`)
|
||||
var rootRe = lazyre.New(`<([A-Za-z_][\w.:-]*)`)
|
||||
|
||||
// whatIs tells what a body that isn't a backup is, from its bytes alone.
|
||||
func whatIs(data []byte) ServerFile {
|
||||
|
||||
@@ -28,11 +28,11 @@ import (
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
xdraw "golang.org/x/image/draw"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -127,7 +127,7 @@ func plist(claudeApp string) string {
|
||||
`
|
||||
}
|
||||
|
||||
var plistKeyRe = regexp.MustCompile(`(?s)<key>([^<]*)</key>\s*<string>([^<]*)</string>`)
|
||||
var plistKeyRe = lazyre.New(`(?s)<key>([^<]*)</key>\s*<string>([^<]*)</string>`)
|
||||
|
||||
// plistString is key's string in the XML Info.plist at path, "" when it
|
||||
// has none or can't be read (Claude.app's is XML).
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// dotenv files (KEY=value per line) as Gemini CLI reads from ~/.gemini/.env.
|
||||
|
||||
var envLine = regexp.MustCompile(`^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$`)
|
||||
var envLine = lazyre.New(`^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$`)
|
||||
|
||||
// GetEnvFile reads one key from a dotenv file.
|
||||
func GetEnvFile(path, key string) (string, bool) {
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// TOML and top-level YAML entries are located by their parsers (toml.go and
|
||||
@@ -13,8 +15,8 @@ import (
|
||||
var (
|
||||
// tomlTable and tomlKV only read a TOML file its parser refuses; see
|
||||
// GetTOMLTop.
|
||||
tomlTable = regexp.MustCompile(`^\s*\[`)
|
||||
tomlKV = regexp.MustCompile(`^\s*([A-Za-z0-9_.-]+|"[^"]*")\s*=\s*(.*?)\s*$`)
|
||||
tomlTable = lazyre.New(`^\s*\[`)
|
||||
tomlKV = lazyre.New(`^\s*([A-Za-z0-9_.-]+|"[^"]*")\s*=\s*(.*?)\s*$`)
|
||||
)
|
||||
|
||||
// setLine replaces the line whose key matches, or inserts newLine after the
|
||||
|
||||
@@ -2,12 +2,13 @@ package edit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// GetYAMLTop reads a top-level scalar key from a YAML file. Quoted keys and
|
||||
@@ -88,7 +89,7 @@ func DelYAMLTop(path string, keys ...string) error {
|
||||
return writeYAMLTop(path, out)
|
||||
}
|
||||
|
||||
var yamlPlain = regexp.MustCompile(`^[A-Za-z0-9._/-]+$`)
|
||||
var yamlPlain = lazyre.New(`^[A-Za-z0-9._/-]+$`)
|
||||
|
||||
func yamlTopLiteral(value any) string {
|
||||
v := toString(value)
|
||||
|
||||
+2
-2
@@ -23,7 +23,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -42,6 +41,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/lastgood"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
"github.com/yetone/magpie/internal/mcpauth"
|
||||
"github.com/yetone/magpie/internal/middleware"
|
||||
@@ -1054,7 +1054,7 @@ func revalidated(next http.Handler) http.Handler {
|
||||
|
||||
// pageFile is a script or stylesheet of the page's own, named in it: one
|
||||
// of the page's, or of a built-in plugin's under plugins/<id>/.
|
||||
var pageFile = regexp.MustCompile(`(src|href)="([A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*\.(?:js|css))"`)
|
||||
var pageFile = lazyre.New(`(src|href)="([A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*\.(?:js|css))"`)
|
||||
|
||||
// versionedPage is the page with each of its own scripts and stylesheets
|
||||
// named with its content's hash; one not among the page's files (boot.js,
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -16,6 +15,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
"github.com/yetone/magpie/internal/middleware"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
@@ -51,7 +51,7 @@ type pluginOptionJSON struct {
|
||||
}
|
||||
|
||||
// pluginOptionKey is the key an option may have, as the host checks it.
|
||||
var pluginOptionKey = regexp.MustCompile(`^[a-z0-9_-]{1,40}$`)
|
||||
var pluginOptionKey = lazyre.New(`^[a-z0-9_-]{1,40}$`)
|
||||
|
||||
// pluginIcon is the vendor's icon: the one the plugin gives its provider,
|
||||
// else the one the plugin market gives the plugin or its provider, else
|
||||
|
||||
@@ -3,11 +3,11 @@ package gui
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -23,8 +23,8 @@ var onAlerts func()
|
||||
var notifyProblem func() string
|
||||
|
||||
var (
|
||||
hoursName = regexp.MustCompile(`^(\d+) hours?$`)
|
||||
daysName = regexp.MustCompile(`^(\d+) days?$`)
|
||||
hoursName = lazyre.New(`^(\d+) hours?$`)
|
||||
daysName = lazyre.New(`^(\d+) days?$`)
|
||||
)
|
||||
|
||||
// alertWindowZh is a window's name in Chinese, as the page's i18n.js has
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"runtime/metrics"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/sessions"
|
||||
@@ -1119,7 +1119,7 @@ func agentLine(a *agent.Agent, launch, goos string) string {
|
||||
}
|
||||
|
||||
// plainBin is a program name a distro's shell takes as it is.
|
||||
var plainBin = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._+-]*$`)
|
||||
var plainBin = lazyre.New(`^[A-Za-z0-9][A-Za-z0-9._+-]*$`)
|
||||
|
||||
// agentTerminal is openTerminal, a var so a test opens no terminal.
|
||||
var agentTerminal = openTerminal
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/fx"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
@@ -788,7 +788,7 @@ func trayIconFile(name string) (b []byte, mono bool) {
|
||||
return svgArcFlags(b), !strings.HasSuffix(name, "-color")
|
||||
}
|
||||
|
||||
var svgPathData = regexp.MustCompile(`\sd="([^"]*[aA][^"]*)"`)
|
||||
var svgPathData = lazyre.New(`\sd="([^"]*[aA][^"]*)"`)
|
||||
|
||||
// svgArcFlags spaces out the flags of a path's arcs ("a4.5 4.5 0 004.5 0",
|
||||
// the flags run into the number after them), which browsers read and the
|
||||
|
||||
@@ -2,9 +2,10 @@ package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// pageWords are the page's own translations (assets/i18n.js's I18N), by
|
||||
@@ -23,8 +24,8 @@ var pageWords = sync.OnceValue(func() map[string]map[string]string {
|
||||
})
|
||||
|
||||
var (
|
||||
pageLangHead = regexp.MustCompile(`^ "?([\w-]+)"?: \{`)
|
||||
pagePair = regexp.MustCompile(`"((?:[^"\\]|\\.)*)"\s*:\s*"((?:[^"\\]|\\.)*)"`)
|
||||
pageLangHead = lazyre.New(`^ "?([\w-]+)"?: \{`)
|
||||
pagePair = lazyre.New(`"((?:[^"\\]|\\.)*)"\s*:\s*"((?:[^"\\]|\\.)*)"`)
|
||||
)
|
||||
|
||||
// parsePageWords reads I18N's language blocks from i18n.js's source: each
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -719,7 +719,7 @@ func Target(dir, path, prompt, ext string, i, n int) (string, error) {
|
||||
return target(dir, path, prompt, ext, i, n)
|
||||
}
|
||||
|
||||
var unslug = regexp.MustCompile(`[^a-z0-9]+`)
|
||||
var unslug = lazyre.New(`[^a-z0-9]+`)
|
||||
|
||||
// target is where the i-th of n images goes: path as a file (numbered when
|
||||
// n > 1) or a folder, else generated-images/<words of the prompt>-<time>.
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -188,7 +188,7 @@ func biliAgents(agents []*agent.Agent) []*agent.Agent {
|
||||
|
||||
// biliStatusLine is a row of bili plugin list: the agent, then its
|
||||
// status, then the version and how it updates, apart by two spaces or more.
|
||||
var biliColumns = regexp.MustCompile(`\s{2,}`)
|
||||
var biliColumns = lazyre.New(`\s{2,}`)
|
||||
|
||||
// parseBiliList is each agent's status as bili plugin list prints it.
|
||||
func parseBiliList(out string) map[string]string {
|
||||
@@ -604,7 +604,7 @@ func keyPath(p []string) (string, bool) {
|
||||
|
||||
// biliURL is the ANTHROPIC_BASE_URL bili's Claude Code plugin writes: its
|
||||
// proxy, then the URL it forwards to.
|
||||
var biliURL = regexp.MustCompile(`^https?://(?:127\.0\.0\.1|localhost|\[::1\]):\d+/bili/(https?://.+)$`)
|
||||
var biliURL = lazyre.New(`^https?://(?:127\.0\.0\.1|localhost|\[::1\]):\d+/bili/(https?://.+)$`)
|
||||
|
||||
// biliMergeJSON is now with what the install changed (before → after) and
|
||||
// nothing changed since (cur still has it) put back as before, and what
|
||||
|
||||
@@ -17,16 +17,16 @@ package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/wslrun"
|
||||
)
|
||||
|
||||
// cmdVar is a variable in a command or an arg: ${NAME} or $NAME.
|
||||
var cmdVar = regexp.MustCompile(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)`)
|
||||
var cmdVar = lazyre.New(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)`)
|
||||
|
||||
// hasCmdVars says whether the command or any arg has a variable or a
|
||||
// leading ~.
|
||||
|
||||
@@ -24,13 +24,13 @@ import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const dshMCPPlugin = "@deepseek-ai/dsh-mcp-client"
|
||||
@@ -38,7 +38,7 @@ const dshMCPPlugin = "@deepseek-ai/dsh-mcp-client"
|
||||
const dshMark = "- insert: # magpie"
|
||||
|
||||
// dshServerName is what dsh-mcp-client takes as a serverName.
|
||||
var dshServerName = regexp.MustCompile(`^[A-Za-z0-9_-]{1,32}$`)
|
||||
var dshServerName = lazyre.New(`^[A-Za-z0-9_-]{1,32}$`)
|
||||
|
||||
// errDshName is what the page says of a server whose name dsh can't take.
|
||||
var errDshName = errors.New("DeepSeek Harness takes a server name of at most 32 letters, digits, - and _")
|
||||
@@ -298,7 +298,7 @@ func dshScalar(s string) string {
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
|
||||
var dshPlain = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]*$`)
|
||||
var dshPlain = lazyre.New(`^[A-Za-z_][A-Za-z0-9_-]*$`)
|
||||
|
||||
// dshKey is a key bare where YAML reads it so, quoted where not.
|
||||
func dshKey(k string) string {
|
||||
|
||||
@@ -14,15 +14,15 @@ import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
// envRef is a reference as the library writes one: ${NAME}.
|
||||
var envRef = regexp.MustCompile(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
var envRef = lazyre.New(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
|
||||
// refSyntax is how an agent spells a reference in a value.
|
||||
type refSyntax int
|
||||
@@ -347,12 +347,12 @@ func toAgent(syntax refSyntax, v string) string {
|
||||
}
|
||||
|
||||
var (
|
||||
openCodeRef = regexp.MustCompile(`\{env:([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
cursorRef = regexp.MustCompile(`\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
openCodeRef = lazyre.New(`\{env:([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
cursorRef = lazyre.New(`\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}`)
|
||||
)
|
||||
|
||||
// dshEnvRef is the expression dsh reads a variable whole with.
|
||||
var dshEnvRef = regexp.MustCompile(`^process\.env\.([A-Za-z_][A-Za-z0-9_]*)$`)
|
||||
var dshEnvRef = lazyre.New(`^process\.env\.([A-Za-z_][A-Za-z0-9_]*)$`)
|
||||
|
||||
// dshRef is a value with references as the !!js expression dsh evaluates
|
||||
// to it, or false for one with none. A variable whole is process.env.NAME,
|
||||
@@ -388,7 +388,7 @@ func dshRef(v string) (dshJS, bool) {
|
||||
|
||||
// dshPart is one operand of a longer value dshRef writes: a JSON string,
|
||||
// or a variable with "" in its place while unset.
|
||||
var dshPart = regexp.MustCompile(`^(?:"(?:[^"\\]|\\.)*"|\(process\.env\.([A-Za-z_][A-Za-z0-9_]*) \?\? ""\))`)
|
||||
var dshPart = lazyre.New(`^(?:"(?:[^"\\]|\\.)*"|\(process\.env\.([A-Za-z_][A-Za-z0-9_]*) \?\? ""\))`)
|
||||
|
||||
// dshUnref is the value an expression dshRef writes stands for, its
|
||||
// references as the library writes them; false for any other expression,
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"github.com/tidwall/jsonc"
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Hooks (#1790) are commands an agent runs at a point of its turn: when
|
||||
@@ -923,7 +923,7 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
}
|
||||
|
||||
// codexState is a [hooks.state."<key>"] header line in Codex's config.toml.
|
||||
var codexState = regexp.MustCompile(`^(\s*\[\s*hooks\s*\.\s*state\s*\.\s*)("(?:[^"\\]|\\.)*"|'[^']*')(\s*\].*)$`)
|
||||
var codexState = lazyre.New(`^(\s*\[\s*hooks\s*\.\s*state\s*\.\s*)("(?:[^"\\]|\\.)*"|'[^']*')(\s*\].*)$`)
|
||||
|
||||
// codexStateKey splits a hook's trust key: the file's path, the event's
|
||||
// label, the group's index and the handler's.
|
||||
|
||||
@@ -37,7 +37,6 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -45,6 +44,7 @@ import (
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// liveAgentMCP is the file K-brain keeps its MCP servers in, in its folder.
|
||||
@@ -61,7 +61,7 @@ var liveAgentBuiltins = []string{"skills-creator", "skills-installer"}
|
||||
// liveAgentSkillName is a name K-brain takes for a skill in its folder:
|
||||
// lowercase letters, digits and single hyphens inside, at most 64
|
||||
// (validManagedName); SaveSettings refuses a selection with another.
|
||||
var liveAgentSkillName = regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`)
|
||||
var liveAgentSkillName = lazyre.New(`^[a-z0-9]+(-[a-z0-9]+)*$`)
|
||||
|
||||
func liveAgentNameOK(name string) bool {
|
||||
return len(name) <= 64 && liveAgentSkillName.MatchString(name)
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -23,6 +22,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/iconproxy"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// The market is where the page finds MCP servers and skills to add in one
|
||||
@@ -476,7 +476,7 @@ type registryVar struct {
|
||||
IsSecret bool `json:"isSecret"`
|
||||
}
|
||||
|
||||
var placeholderRe = regexp.MustCompile(`\{[^{}]*\}`)
|
||||
var placeholderRe = lazyre.New(`\{[^{}]*\}`)
|
||||
|
||||
// listed is an active server the registry lists, as the market
|
||||
// offers it.
|
||||
@@ -975,7 +975,7 @@ var skillsShURL = "https://www.skills.sh"
|
||||
//go:embed market_skills.json
|
||||
var skillsSnapshot []byte
|
||||
|
||||
var repoRe = regexp.MustCompile(`^[\w.-]+/[\w.-]+$`)
|
||||
var repoRe = lazyre.New(`^[\w.-]+/[\w.-]+$`)
|
||||
|
||||
var popular = struct {
|
||||
sync.Mutex
|
||||
@@ -1369,7 +1369,7 @@ func (e *SearchError) Unwrap() error { return e.Err }
|
||||
// variable for tests.
|
||||
var retryPause = time.Second
|
||||
|
||||
var metaDescRe = regexp.MustCompile(`<meta\s+name="description"\s+content="([^"]*)"`)
|
||||
var metaDescRe = lazyre.New(`<meta\s+name="description"\s+content="([^"]*)"`)
|
||||
|
||||
// metaDescription is what a page's <meta name="description"> says.
|
||||
func metaDescription(page []byte) string {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// A search in the market can be an address: a server's repository
|
||||
@@ -20,9 +21,9 @@ var codeHosts = map[string]bool{
|
||||
}
|
||||
|
||||
var (
|
||||
schemeRe = regexp.MustCompile(`^[a-z][a-z0-9+.-]*://`)
|
||||
ownerRepoRe = regexp.MustCompile(`^@?[a-z0-9][a-z0-9_.-]*/[a-z0-9_.-]+$`)
|
||||
hostRe = regexp.MustCompile(`^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?$`)
|
||||
schemeRe = lazyre.New(`^[a-z][a-z0-9+.-]*://`)
|
||||
ownerRepoRe = lazyre.New(`^@?[a-z0-9][a-z0-9_.-]*/[a-z0-9_.-]+$`)
|
||||
hostRe = lazyre.New(`^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?$`)
|
||||
)
|
||||
|
||||
// normAddr is an address as it's compared: lower case, with no scheme, user,
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// A server the MCP Registry doesn't list can still be at the address
|
||||
@@ -27,7 +28,7 @@ type repoAt struct {
|
||||
Path string // the folder, "" for the top
|
||||
}
|
||||
|
||||
var ghRepoRe = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9_.-]+$`)
|
||||
var ghRepoRe = lazyre.New(`^[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9_.-]+$`)
|
||||
|
||||
// parseRepoAt reads a GitHub address as a repository's folder:
|
||||
// github.com/o/r, with #subdirectory=p (pip's and uv's way), /tree/ref/p,
|
||||
@@ -188,7 +189,7 @@ func pathPart(a repoAt) string {
|
||||
// pypiURL is PyPI's JSON API; a variable for tests.
|
||||
var pypiURL = "https://pypi.org/pypi"
|
||||
|
||||
var pypiNameRe = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
||||
var pypiNameRe = lazyre.New(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
||||
|
||||
// fromPyPI is the server a PyPI package of that name runs, uvx <name>,
|
||||
// with what its description (its README) says it reads from the
|
||||
@@ -230,10 +231,10 @@ func fromPyPI(name string) (MarketServer, bool) {
|
||||
}
|
||||
|
||||
var (
|
||||
envBlockRe = regexp.MustCompile(`"env"\s*:\s*\{`)
|
||||
envKeyRe = regexp.MustCompile(`^[A-Z][A-Z0-9_]*$`)
|
||||
secretRe = regexp.MustCompile(`KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH`)
|
||||
fenceRe = regexp.MustCompile("^\\s*(```|~~~)")
|
||||
envBlockRe = lazyre.New(`"env"\s*:\s*\{`)
|
||||
envKeyRe = lazyre.New(`^[A-Z][A-Z0-9_]*$`)
|
||||
secretRe = lazyre.New(`KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH`)
|
||||
fenceRe = lazyre.New("^\\s*(```|~~~)")
|
||||
)
|
||||
|
||||
// envInputs are the environment variables a README's configuration
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -28,6 +27,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/imagemcp"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Server is one MCP server: a command magpie's agents start, or a URL they
|
||||
@@ -354,7 +354,7 @@ func (f *mcpFile) supports(s *Server) error {
|
||||
|
||||
// windowsPath is a program named as Windows names one: C:/…, a path with a
|
||||
// backslash in it, or …/npx.cmd.
|
||||
var windowsPath = regexp.MustCompile(`^[A-Za-z]:[\\/]|\\|(?i)\.(?:exe|cmd|bat|ps1)$`)
|
||||
var windowsPath = lazyre.New(`^[A-Za-z]:[\\/]|\\|(?i)\.(?:exe|cmd|bat|ps1)$`)
|
||||
|
||||
// foreign says why an entry by the server's name that magpie can't read as
|
||||
// a server is one it mustn't write over, or nil: Zed's server from an
|
||||
|
||||
@@ -19,13 +19,13 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -39,7 +39,7 @@ type npxRun struct {
|
||||
// npmSpec is a package from the registry, with a version or tag or none:
|
||||
// npx's other specs (a path, a git or tarball URL, an alias) are left to
|
||||
// npx.
|
||||
var npmSpec = regexp.MustCompile(`^((?:@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*)(?:@([A-Za-z0-9._~^<>=*| -]+))?$`)
|
||||
var npmSpec = lazyre.New(`^((?:@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*)(?:@([A-Za-z0-9._~^<>=*| -]+))?$`)
|
||||
|
||||
// readNpx is s's npx line, ok false for anything else: a flag but -y
|
||||
// before the package (-p, --package, -c, a registry), or no -y, which
|
||||
@@ -74,7 +74,7 @@ func (r npxRun) pinned() bool {
|
||||
return ok && exactVersion.MatchString(v)
|
||||
}
|
||||
|
||||
var exactVersion = regexp.MustCompile(`^\d+\.\d+\.\d+([-+].*)?$`)
|
||||
var exactVersion = lazyre.New(`^\d+\.\d+\.\d+([-+].*)?$`)
|
||||
|
||||
// npxDir is where magpie installs a spec: a folder of its own each.
|
||||
func npxDir(spec string) string {
|
||||
|
||||
@@ -3,7 +3,6 @@ package library
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// A server's tools can be turned off one by one (nf1qaz2w on Discord): the
|
||||
@@ -216,7 +216,7 @@ func entryToolsEdit(f *mcpFile, old map[string]any, prev, want []string) (*tools
|
||||
// mcpToolName is a name as Claude Code and OpenCode spell it in a tool's
|
||||
// id: each character but a letter, a digit, _ and - is an _ (Claude Code
|
||||
// 2.1.296's normalizeNameForMCP; OpenCode's tool/mcp.ts namespace()).
|
||||
var mcpNameBad = regexp.MustCompile(`[^a-zA-Z0-9_-]`)
|
||||
var mcpNameBad = lazyre.New(`[^a-zA-Z0-9_-]`)
|
||||
|
||||
func mcpToolName(s string) string { return mcpNameBad.ReplaceAllString(s, "_") }
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -16,6 +15,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Pi 0.99 (2026-09-29) has MCP of its own, a built-in extension, builtin:mcp
|
||||
@@ -340,7 +340,7 @@ func piFiles(h, d string, p piPlugins, native bool) *mcpFile {
|
||||
}
|
||||
|
||||
// piKey is a server name that can be written as one step of a key path.
|
||||
var piKey = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
|
||||
var piKey = lazyre.New(`^[A-Za-z0-9_-]+$`)
|
||||
|
||||
// piMove moves what pi-mcp-adapter read from mcp.json into
|
||||
// mcp-adapter.json: the whole file when there is none yet, as the adapter's
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -20,6 +19,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -433,7 +433,7 @@ var rtkVersion = func() string {
|
||||
|
||||
// semver finds the version in what opencode --version prints: OpenCode 1
|
||||
// prints "1.18.32", OpenCode 2 "opencode v2.0.18".
|
||||
var semver = regexp.MustCompile(`(?:^|[^\w.])v?(\d+\.\d+\.\d+\S*)`)
|
||||
var semver = lazyre.New(`(?:^|[^\w.])v?(\d+\.\d+\.\d+\S*)`)
|
||||
|
||||
// openCodeVersion is the version the opencode on this machine says it is,
|
||||
// "" when there's none or it doesn't say; a test sets it. OpenCode 2's
|
||||
|
||||
@@ -14,13 +14,13 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
"github.com/yetone/magpie/internal/steady"
|
||||
@@ -1030,10 +1030,10 @@ func brewError(out string) string {
|
||||
}
|
||||
|
||||
var (
|
||||
ansiSeq = regexp.MustCompile(`\x1b\[[0-9;?]*[ -/]*[@-~]`)
|
||||
ansiSeq = lazyre.New(`\x1b\[[0-9;?]*[ -/]*[@-~]`)
|
||||
// a line that is only a spinner frame or a progress bar (winget's
|
||||
// ██████▒▒▒ 1.20 MB / 3.40 MB, Homebrew's ###, curl's %)
|
||||
progressLine = regexp.MustCompile(`^(?:[-\\|/]|[█▓▒░#=>.\s]*\d*(?:\.\d+)?\s*(?:[KMG]i?B\s*/\s*\d+(?:\.\d+)?\s*[KMG]i?B|%)?)$`)
|
||||
progressLine = lazyre.New(`^(?:[-\\|/]|[█▓▒░#=>.\s]*\d*(?:\.\d+)?\s*(?:[KMG]i?B\s*/\s*\d+(?:\.\d+)?\s*[KMG]i?B|%)?)$`)
|
||||
)
|
||||
|
||||
// installerSaid is the last lines an installer printed that say something:
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -308,7 +308,7 @@ func gitRepoOf(dir string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var originSection = regexp.MustCompile(`^\[\s*remote\s+"origin"\s*\]$`)
|
||||
var originSection = lazyre.New(`^\[\s*remote\s+"origin"\s*\]$`)
|
||||
|
||||
// originURL is the repository remote "origin" of a git config fetches.
|
||||
func originURL(cfg string) string {
|
||||
@@ -330,7 +330,7 @@ func originURL(cfg string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var scpRemote = regexp.MustCompile(`^(?:[\w.-]+@)?([\w.-]+\.[\w.-]+):(.+)$`)
|
||||
var scpRemote = lazyre.New(`^(?:[\w.-]+@)?([\w.-]+\.[\w.-]+):(.+)$`)
|
||||
|
||||
// remoteRepo reads a git remote's address as a repository: owner/repo on
|
||||
// GitHub, host/path elsewhere. A user or a token in it is never kept.
|
||||
|
||||
@@ -24,9 +24,10 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// followMovedSkills re-points each library skill linked into a version
|
||||
@@ -127,7 +128,7 @@ func linkedEnd(p string) string {
|
||||
}
|
||||
|
||||
// versionName is a folder named for a version: 0.6.0.12, v2.1, 1.4.2-beta.
|
||||
var versionName = regexp.MustCompile(`^[vV]?\d+(\.\d+)*([-+_][0-9A-Za-z.]+)?$`)
|
||||
var versionName = lazyre.New(`^[vV]?\d+(\.\d+)*([-+_][0-9A-Za-z.]+)?$`)
|
||||
|
||||
// currentNames are the links an app keeps beside its version folders to
|
||||
// the one in use.
|
||||
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -36,11 +36,11 @@ var gitTimeout = 3 * time.Minute
|
||||
var (
|
||||
// remoteHelper is git's <transport>::<address>, which hands the
|
||||
// address to a helper program (ext:: runs a command)
|
||||
remoteHelper = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9+.-]*::`)
|
||||
remoteHelper = lazyre.New(`^[A-Za-z][A-Za-z0-9+.-]*::`)
|
||||
// scpLike is git's user@host:path for SSH
|
||||
scpLike = regexp.MustCompile(`^(?:([\w.-]+)@)?([\w.-]+):(.+)$`)
|
||||
gitRef = regexp.MustCompile(`^[\w./+@-]+$`)
|
||||
hexRef = regexp.MustCompile(`^[0-9a-fA-F]{7,40}$`)
|
||||
scpLike = lazyre.New(`^(?:([\w.-]+)@)?([\w.-]+):(.+)$`)
|
||||
gitRef = lazyre.New(`^[\w./+@-]+$`)
|
||||
hexRef = lazyre.New(`^[0-9a-fA-F]{7,40}$`)
|
||||
)
|
||||
|
||||
// gitSchemes are the URL schemes a git source may have. file:// is a
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -195,7 +196,7 @@ func parseMeta(b []byte) meta {
|
||||
return m
|
||||
}
|
||||
|
||||
var unsafe = regexp.MustCompile(`[^A-Za-z0-9_-]+`)
|
||||
var unsafe = lazyre.New(`[^A-Za-z0-9_-]+`)
|
||||
|
||||
// nameFor is the name a skill in the folder named folder goes by: what its
|
||||
// SKILL.md says, made fit for a file name. A name in another script doesn't
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Subagents (#2283) are agents of their own the main agent hands a task
|
||||
@@ -74,7 +74,7 @@ type SubagentFile struct {
|
||||
// subagentNameRe is a name every agent takes: Cursor's and CodeBuddy's
|
||||
// are lowercase letters, digits and -, Qwen Code's 2 to 50 characters
|
||||
// that neither start nor end with - (validateName in its subagents).
|
||||
var subagentNameRe = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,48}[a-z0-9]$`)
|
||||
var subagentNameRe = lazyre.New(`^[a-z0-9][a-z0-9-]{0,48}[a-z0-9]$`)
|
||||
|
||||
// reservedSubagents are names Qwen Code keeps for itself.
|
||||
var reservedSubagents = []string{"self", "system", "user", "model", "tool", "config", "default", "main"}
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"log"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -37,6 +36,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/beat"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/routes"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
@@ -52,7 +52,7 @@ var (
|
||||
usageQueue = 1024
|
||||
)
|
||||
|
||||
var strategyName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
||||
var strategyName = lazyre.New(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
||||
|
||||
// strat is one strategy a module exports.
|
||||
type strat struct {
|
||||
@@ -195,7 +195,7 @@ func (m *mw) routing(n string) string {
|
||||
return short + "/" + n
|
||||
}
|
||||
|
||||
var badPrefix = regexp.MustCompile(`[^A-Za-z0-9._-]+`)
|
||||
var badPrefix = lazyre.New(`[^A-Za-z0-9._-]+`)
|
||||
|
||||
// seatJSON is a routes.Seat as a strategy is given it.
|
||||
type seatJSON struct {
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/redact"
|
||||
)
|
||||
@@ -373,14 +373,14 @@ func (h *helper) died() string {
|
||||
|
||||
// startup are the lines ggml writes as it starts, every time, on a GPU
|
||||
// and on the CPU alike: what the device is, the kernels it built.
|
||||
var startup = regexp.MustCompile(`^(ggml_metal_(device_init|library_init|init|free|library_compile_pipeline)|ggml_vulkan|load_backend|register_backend|register_device):`)
|
||||
var startup = lazyre.New(`^(ggml_metal_(device_init|library_init|init|free|library_compile_pipeline)|ggml_vulkan|load_backend|register_backend|register_device):`)
|
||||
|
||||
// trouble is a line that says something went wrong, startup's or not.
|
||||
var trouble = regexp.MustCompile(`(?i)error|fail|assert|abort|unable|cannot|can't|could not|out of memory|exception|lost`)
|
||||
var trouble = lazyre.New(`(?i)error|fail|assert|abort|unable|cannot|can't|could not|out of memory|exception|lost`)
|
||||
|
||||
// deviceLost is a GPU the driver reset under pf-serve, as ggml's Vulkan
|
||||
// says it (vk::DeviceLostError, VK_ERROR_DEVICE_LOST) and Metal's.
|
||||
var deviceLost = regexp.MustCompile(`(?i)DeviceLost|device[ _]lost`)
|
||||
var deviceLost = lazyre.New(`(?i)DeviceLost|device[ _]lost`)
|
||||
|
||||
// lastSaid is the last n lines of stderr that say more than ggml's
|
||||
// startup, joined.
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -24,6 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/libc"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
@@ -123,7 +123,7 @@ func bunExe() string {
|
||||
// missingLibRe finds what a musl Linux's loader says when a program needs
|
||||
// a library the system lacks: "Error loading shared library
|
||||
// libstdc++.so.6: No such file or directory (needed by …)".
|
||||
var missingLibRe = regexp.MustCompile(`Error loading shared library ([^:\s]+)`)
|
||||
var missingLibRe = lazyre.New(`Error loading shared library ([^:\s]+)`)
|
||||
|
||||
// missingLibs says which libraries a bun that started couldn't be linked
|
||||
// with lacks, from what it printed, "" when that isn't why it failed. Bun's
|
||||
|
||||
@@ -18,12 +18,12 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/steady"
|
||||
"github.com/yetone/magpie/internal/update"
|
||||
)
|
||||
@@ -130,7 +130,7 @@ func inUseLocked() string {
|
||||
// envBunVersion is what each $MAGPIE_BUN said it is, asked once.
|
||||
var envBunVersion = map[string]string{}
|
||||
|
||||
var bunVersionRe = regexp.MustCompile(`^\d+\.\d+\.\d+$`)
|
||||
var bunVersionRe = lazyre.New(`^\d+\.\d+\.\d+$`)
|
||||
|
||||
// bunReported is the version a bun says it is, "" when it won't say.
|
||||
func bunReported(exe string) string {
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
"github.com/yetone/magpie/internal/update"
|
||||
)
|
||||
@@ -81,7 +81,7 @@ var errDistUnread = errors.New("the community repo's dist branch can't be read")
|
||||
|
||||
// distFile is a file the index may name: one tarball under tgz/, nothing
|
||||
// that leaves the branch or plugins/dist.
|
||||
var distFile = regexp.MustCompile(`^tgz/[A-Za-z0-9._-]+\.tgz$`)
|
||||
var distFile = lazyre.New(`^tgz/[A-Za-z0-9._-]+\.tgz$`)
|
||||
|
||||
// distPkg is what the dist branch has of the package: nil with no error
|
||||
// when the branch was read and has none, or the package isn't one of its
|
||||
@@ -298,7 +298,7 @@ func distWanted(spec string) (name, version string, ok bool) {
|
||||
return name, version, true
|
||||
}
|
||||
|
||||
var exactVersion = regexp.MustCompile(`^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$`)
|
||||
var exactVersion = lazyre.New(`^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$`)
|
||||
|
||||
// installDist installs the package's version from the dist branch: its
|
||||
// tarball fetched, checked against the index's sha512, kept in
|
||||
@@ -397,7 +397,7 @@ func distNamed(b []byte, file string) bool {
|
||||
|
||||
// distLockedAt is a package bun.lock's packages has at a tarball in
|
||||
// plugins/dist, and that tarball: "<name>": ["<name>@./dist/<file>", …].
|
||||
var distLockedAt = regexp.MustCompile(`\["((?:@[^"/@]+/)?[^"/@]+)@(?:file:)?(?:\./)?dist/([A-Za-z0-9._-]+\.tgz)"`)
|
||||
var distLockedAt = lazyre.New(`\["((?:@[^"/@]+/)?[^"/@]+)@(?:file:)?(?:\./)?dist/([A-Za-z0-9._-]+\.tgz)"`)
|
||||
|
||||
// mendDist sends bun.lock back to package.json for the packages it has at a
|
||||
// dist tarball package.json doesn't name, when package.json has them at one
|
||||
|
||||
@@ -23,9 +23,11 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
var hexSHA = regexp.MustCompile(`^[0-9a-f]{7,40}$`)
|
||||
var hexSHA = lazyre.New(`^[0-9a-f]{7,40}$`)
|
||||
|
||||
// refFixed is whether a git spec names the exact commit to install
|
||||
// (#<commit>): nothing is resolved for one, so no cache is fetched for it
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -88,7 +88,7 @@ var ActionMenus = []string{"provider", "agent"}
|
||||
|
||||
// actionID is what an action's id is: short, of lower-case letters,
|
||||
// digits and dashes, so the page can switch on it
|
||||
var actionID = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,39}$`)
|
||||
var actionID = lazyre.New(`^[a-z0-9][a-z0-9-]{0,39}$`)
|
||||
|
||||
// maxActions is how many actions one plugin adds, at most.
|
||||
const maxActions = 8
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
toml "github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -189,7 +189,7 @@ type npmrc struct {
|
||||
}
|
||||
|
||||
// npmrcVar is a ${VAR} in an .npmrc's value, which npm expands.
|
||||
var npmrcVar = regexp.MustCompile(`\$\{[A-Za-z_][A-Za-z0-9_]*\}`)
|
||||
var npmrcVar = lazyre.New(`\$\{[A-Za-z_][A-Za-z0-9_]*\}`)
|
||||
|
||||
// npmrcOf reads the .npmrc at path; an empty one when it can't be read. A
|
||||
// ${VAR} is the environment's, as npm expands it.
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/steady"
|
||||
)
|
||||
@@ -52,7 +52,7 @@ func (p PluginSearch) VendorID() string {
|
||||
|
||||
// unsafeVendorChars are what a vendor id leaves out: the CLI lowercases it
|
||||
// and it is a word in a space-separated key id.
|
||||
var unsafeVendorChars = regexp.MustCompile(`[^a-z0-9-]+`)
|
||||
var unsafeVendorChars = lazyre.New(`[^a-z0-9-]+`)
|
||||
|
||||
// SearchPage is one page a plugin's search found.
|
||||
type SearchPage struct {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -37,6 +36,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lastgood"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -325,15 +325,15 @@ func IsPath(spec string) bool {
|
||||
return strings.HasPrefix(spec, "file://") || strings.HasPrefix(spec, ".") || strings.HasPrefix(spec, "/") || strings.HasPrefix(spec, `\`) || filepath.IsAbs(spec) || driveRooted.MatchString(spec)
|
||||
}
|
||||
|
||||
var driveRooted = regexp.MustCompile(`^[A-Za-z]:[\\/]`)
|
||||
var driveRooted = lazyre.New(`^[A-Za-z]:[\\/]`)
|
||||
|
||||
var pkgName = regexp.MustCompile(`^(@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$`)
|
||||
var pkgName = lazyre.New(`^(@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$`)
|
||||
|
||||
// gitSpec is a package bun fetches from a git repository, not npm:
|
||||
// github:owner/repo[#ref] (gitlab: and bitbucket: alike), a git+https://,
|
||||
// git+ssh://, git+file:// or git:// URL, a GitHub, GitLab or Bitbucket
|
||||
// page's URL, or owner/repo, GitHub's shorthand.
|
||||
var gitSpec = regexp.MustCompile(`^(?:(?:github|gitlab|bitbucket):|git\+[a-z]+://|git://)\S+$|^https?://(?:www\.)?(?:github\.com|gitlab\.com|bitbucket\.org)/\S+$|^[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9_.-]+(?:#\S+)?$`)
|
||||
var gitSpec = lazyre.New(`^(?:(?:github|gitlab|bitbucket):|git\+[a-z]+://|git://)\S+$|^https?://(?:www\.)?(?:github\.com|gitlab\.com|bitbucket\.org)/\S+$|^[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9_.-]+(?:#\S+)?$`)
|
||||
|
||||
// IsGit is whether spec names a git repository rather than an npm package
|
||||
// or a path. The package bun installs from it is named by its own
|
||||
@@ -839,7 +839,7 @@ func installAt(ctx context.Context, pkg, version string) error {
|
||||
}
|
||||
|
||||
// minAge is bun's word for a version its minimumReleaseAge holds back.
|
||||
var minAge = regexp.MustCompile(`minimum-release-age: (\d+) seconds`)
|
||||
var minAge = lazyre.New(`minimum-release-age: (\d+) seconds`)
|
||||
|
||||
// ageText is a number of seconds as a reader says it: 2 days, 12 hours.
|
||||
func ageText(secs string) string {
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// errAppMain is what a probe of an app's own program (a Mac bundle's, a
|
||||
@@ -56,7 +57,7 @@ func appMain(path string) bool {
|
||||
return strings.EqualFold(exe, filepath.Base(path))
|
||||
}
|
||||
|
||||
var bundleExeRe = regexp.MustCompile(`<key>CFBundleExecutable</key>\s*<string>([^<]+)</string>`)
|
||||
var bundleExeRe = lazyre.New(`<key>CFBundleExecutable</key>\s*<string>([^<]+)</string>`)
|
||||
|
||||
// bundleExecutable is the CFBundleExecutable an XML Info.plist names, ""
|
||||
// when it can't be read (a binary plist too) or names none.
|
||||
|
||||
@@ -3,8 +3,9 @@ package proc
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// End ends process pid as its own clean exit would look to its parent:
|
||||
@@ -29,7 +30,7 @@ func EnvOf(ctx context.Context, pid int, names ...string) (map[string]string, er
|
||||
}
|
||||
|
||||
// psEnvNameRe is where the next variable starts in `ps -E` output.
|
||||
var psEnvNameRe = regexp.MustCompile(` [A-Za-z_][A-Za-z0-9_]*=`)
|
||||
var psEnvNameRe = lazyre.New(` [A-Za-z_][A-Za-z0-9_]*=`)
|
||||
|
||||
// parsePSEnv reads names out of the line `ps -E -ww -o command=` prints:
|
||||
// the command line, then each variable as NAME=value, space-separated and
|
||||
|
||||
@@ -3,9 +3,10 @@ package proc
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// FindTool is the command-line tool name as a terminal would run it: on
|
||||
@@ -101,7 +102,7 @@ func toolIn(name, goos string, dirs []string) string {
|
||||
// npmShimLine is the line of npm's sh shim (cmd-shim) that runs a program
|
||||
// of its package's directly: exec "$basedir/node_modules/<pkg>/<bin>" "$@".
|
||||
// A shim of a node script names node first, and isn't matched.
|
||||
var npmShimLine = regexp.MustCompile(`(?m)^\s*exec "\$basedir/([^"$]+\.exe)"\s+"\$@"`)
|
||||
var npmShimLine = lazyre.New(`(?m)^\s*exec "\$basedir/([^"$]+\.exe)"\s+"\$@"`)
|
||||
|
||||
// npmShimExe is the Windows program the npm sh shim at path runs, where it
|
||||
// is: Claude Code's is node_modules\@anthropic-ai\claude-code\bin\claude.exe.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Group is what a profile holds for one agent, to be read before it is
|
||||
@@ -52,8 +52,8 @@ type Item struct {
|
||||
// model or provider id has). No agent field holds one today, but
|
||||
// profiles.json is a file anyone can edit.
|
||||
var (
|
||||
secretName = regexp.MustCompile(`(?i)(key|token|secret|passw|credential|cookie)`)
|
||||
secretValue = regexp.MustCompile(`^(sk-|sk_|ghp_|gho_|ghu_|github_pat_|xox[abpr]-|AIza|eyJ)|[A-Za-z0-9]{32,}`)
|
||||
secretName = lazyre.New(`(?i)(key|token|secret|passw|credential|cookie)`)
|
||||
secretValue = lazyre.New(`^(sk-|sk_|ghp_|gho_|ghu_|github_pat_|xox[abpr]-|AIza|eyJ)|[A-Za-z0-9]{32,}`)
|
||||
)
|
||||
|
||||
func secret(key, label, value string) bool {
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -37,6 +36,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/claudecode"
|
||||
"github.com/yetone/magpie/internal/filelock"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -618,7 +618,7 @@ func claudeKeychainAccount() string {
|
||||
return name
|
||||
}
|
||||
|
||||
var keychainAccountRe = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
|
||||
var keychainAccountRe = lazyre.New(`^[a-zA-Z0-9._-]+$`)
|
||||
|
||||
// keychainText undoes `security find-generic-password -w` printing a
|
||||
// password with a character it can't print — a newline — as hex.
|
||||
@@ -1702,7 +1702,7 @@ func copilotAPIs(endpoints []string) []string {
|
||||
}
|
||||
|
||||
// internal is a Copilot model id nobody picks by hand.
|
||||
var copilotInternal = regexp.MustCompile(`^(copilot-search|exec-agent|trajectory)|-(secondary|tertiary|4th|free-auto)$`)
|
||||
var copilotInternal = lazyre.New(`^(copilot-search|exec-agent|trajectory)|-(secondary|tertiary|4th|free-auto)$`)
|
||||
|
||||
// A model Copilot offers with terms of its own stays disabled until the
|
||||
// account accepts them, as VS Code does when one is first picked; magpie
|
||||
|
||||
@@ -20,12 +20,13 @@ import (
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// balanceSource is where one provider's balance is asked and how the
|
||||
@@ -1587,7 +1588,7 @@ func sub2APIKeyLimits(p Provider) bool {
|
||||
// {token} is the key too: it is what a vendor's own error names the value
|
||||
// in "Authorization: Bearer {token}" (lx_78654 on Discord, whose header
|
||||
// went with "{token}" in it as written, and the vendor refused it).
|
||||
var balanceKeyNames = regexp.MustCompile(`(?i)\$?\{\{?\s*(?:key|api[_-]?key|token)\s*\}?\}`)
|
||||
var balanceKeyNames = lazyre.New(`(?i)\$?\{\{?\s*(?:key|api[_-]?key|token)\s*\}?\}`)
|
||||
|
||||
// withBalanceKey is s with the key in place of its names, escaped for a
|
||||
// URL's query when inURL.
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lastgood"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -155,7 +155,7 @@ type currencyAmount struct {
|
||||
N float64
|
||||
}
|
||||
|
||||
var currencyPart = regexp.MustCompile(`^([^\d-]+?)(-?\d[\d,]*(?:\.\d+)?)$`)
|
||||
var currencyPart = lazyre.New(`^([^\d-]+?)(-?\d[\d,]*(?:\.\d+)?)$`)
|
||||
|
||||
// balanceCurrencies is a balance's amounts when it is told in several
|
||||
// currencies, each a sign and a number, apart by " · " as readDeepSeek
|
||||
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
// the zone /usage names its resets in: Windows has no zone database,
|
||||
// and without one a reset was read in the machine's own zone
|
||||
_ "time/tzdata"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// claudeCLIUsage runs Claude Code's /usage in configDir, or its own
|
||||
@@ -60,7 +62,7 @@ func readClaudeUsage(ctx context.Context, configDir string) ([]QuotaWindow, erro
|
||||
// "Current session: 13% used · resets Oct 1 at 3:30pm (Asia/Shanghai)",
|
||||
// "Current week (all models): 4% used · resets Oct 3 at 2pm (Asia/Shanghai)",
|
||||
// "Current week (Fable): 0% used"
|
||||
var claudeUsageLineRE = regexp.MustCompile(`^Current (session|week(?: \(([^)]+)\))?):\s*([0-9.]+)% used(?:\s*·\s*resets (.+))?$`)
|
||||
var claudeUsageLineRE = lazyre.New(`^Current (session|week(?: \(([^)]+)\))?):\s*([0-9.]+)% used(?:\s*·\s*resets (.+))?$`)
|
||||
|
||||
// A successful /usage run can tell only how the subscription is billed,
|
||||
// without an allowance. This says nothing about the account's limits.
|
||||
@@ -74,13 +76,13 @@ var errClaudeUsageUnavailable = errors.New("Claude Code's /usage is temporarily
|
||||
// account's last reading. Windows' pseudo console showed 2.1.316's panel
|
||||
// while it still loaded, and the card said the account had no allowance
|
||||
// (Seagull fries).
|
||||
var claudeUsageUnknown = regexp.MustCompile(`^(?:Claude Code: )?(?:` + regexp.QuoteMeta(errClaudeUsageUnavailable.Error()) + `|/usage couldn't load the plan's usage)`)
|
||||
var claudeUsageUnknown = lazyre.New(`^(?:Claude Code: )?(?:` + regexp.QuoteMeta(errClaudeUsageUnavailable.Error()) + `|/usage couldn't load the plan's usage)`)
|
||||
|
||||
var errClaudeCannotRun = errors.New("Claude Code can't be run from here")
|
||||
|
||||
// An account error stays visible even when it also mentions a timeout or
|
||||
// rate limit. It is not a temporary failure to read the usage endpoint.
|
||||
var claudeUsageDenied = regexp.MustCompile(`(?i)\b(401|403)\b|not (logged|signed) in|signed out|sign-in (has )?expired|unauthorized|forbidden|authentication (failed|required)|invalid (access )?token|(session|usage) limit|hit your limit`)
|
||||
var claudeUsageDenied = lazyre.New(`(?i)\b(401|403)\b|not (logged|signed) in|signed out|sign-in (has )?expired|unauthorized|forbidden|authentication (failed|required)|invalid (access )?token|(session|usage) limit|hit your limit`)
|
||||
|
||||
// claudeDenied says s tells an account error (claudeUsageDenied). Claude
|
||||
// Code's "(not your usage limit)", which it says of Anthropic turning the
|
||||
@@ -91,7 +93,7 @@ func claudeDenied(s string) bool {
|
||||
return claudeUsageDenied.MatchString(claudeNotYourLimit.ReplaceAllString(s, ""))
|
||||
}
|
||||
|
||||
var claudeNotYourLimit = regexp.MustCompile(`(?i)\(not your usage limit\)`)
|
||||
var claudeNotYourLimit = lazyre.New(`(?i)\(not your usage limit\)`)
|
||||
|
||||
// claudeUsageCounts is /usage's closing line of the account's local
|
||||
// activity ("Last 7d · 403 requests · 388 sessions"), with the " · "
|
||||
@@ -100,7 +102,7 @@ var claudeNotYourLimit = regexp.MustCompile(`(?i)\(not your usage limit\)`)
|
||||
// of the line is read: "Last 7d · 403 requests · 388 sessions · HTTP 403
|
||||
// Forbidden" is an account error. Any span and a count with thousands
|
||||
// separators ("1,403 requests") are counts too.
|
||||
var claudeUsageCounts = regexp.MustCompile(`(?: · )?Last [0-9]+[a-z]+ · [0-9][0-9,]* requests? · [0-9][0-9,]* sessions?`)
|
||||
var claudeUsageCounts = lazyre.New(`(?: · )?Last [0-9]+[a-z]+ · [0-9][0-9,]* requests? · [0-9][0-9,]* sessions?`)
|
||||
|
||||
// claudeOverages is /usage's line for an account past its plan's limits
|
||||
// and billed for what it uses ("You are currently using your overages to
|
||||
@@ -110,7 +112,7 @@ var claudeUsageCounts = regexp.MustCompile(`(?: · )?Last [0-9]+[a-z]+ · [0-9][
|
||||
// one, the reading had no windows and an error, and the switch, which
|
||||
// stays on an account it can't read, left Claude Code spending overages
|
||||
// with other accounts that had room (StringKe, #4532).
|
||||
var claudeOverages = regexp.MustCompile(`(?i)using your overages`)
|
||||
var claudeOverages = lazyre.New(`(?i)using your overages`)
|
||||
|
||||
// claudeOveragesWindow is the window an account on overages is read with,
|
||||
// beside ws: spent (usedPast, roomLeft), so the switch moves Claude Code
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// Claude Code takes a Claude model by its id's version written with dashes
|
||||
@@ -19,10 +20,10 @@ import (
|
||||
// as Mythos 5. Other vendors' ids are never respelled.
|
||||
|
||||
// claudeDotted is a Claude model's version written with a dot.
|
||||
var claudeDotted = regexp.MustCompile(`(?i)claude-(?:opus|sonnet|haiku|fable|mythos)-\d+(?:\.\d+)+`)
|
||||
var claudeDotted = lazyre.New(`(?i)claude-(?:opus|sonnet|haiku|fable|mythos)-\d+(?:\.\d+)+`)
|
||||
|
||||
// claudeDashedish is an id that could be a dotted one respelled.
|
||||
var claudeDashedish = regexp.MustCompile(`(?i)claude-(?:opus|sonnet|haiku|fable|mythos)-\d+-\d`)
|
||||
var claudeDashedish = lazyre.New(`(?i)claude-(?:opus|sonnet|haiku|fable|mythos)-\d+-\d`)
|
||||
|
||||
// ClaudeDashed is id with each dot of a Claude model's version a dash:
|
||||
// relay/claude-opus-4.6-us[1m] is relay/claude-opus-4-6-us[1m]. Any other
|
||||
|
||||
@@ -14,16 +14,17 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// expiredWords: a 401 that says the access token has expired and asks
|
||||
// for a refresh. Not refresh_token_expired ("_" is a word character, so
|
||||
// \b doesn't split it there), which says the sign-in itself is gone
|
||||
// (revokedWords).
|
||||
var expiredWords = regexp.MustCompile(`(?i)\btoken_expired\b|authentication token (is|has) expired|please try refreshing it`)
|
||||
var expiredWords = lazyre.New(`(?i)\btoken_expired\b|authentication token (is|has) expired|please try refreshing it`)
|
||||
|
||||
// SignInExpired says a reply is the vendor's word that the access token
|
||||
// it was sent with has expired, for a refresh to mend.
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
"unsafe"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// The ChatGPT backend checks every tool name a request carries, a call's
|
||||
@@ -24,7 +25,7 @@ import (
|
||||
// conversation that worked is sent byte for byte as before.
|
||||
|
||||
// codexNameOK is a name the ChatGPT backend takes.
|
||||
var codexNameOK = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
|
||||
var codexNameOK = lazyre.New(`^[a-zA-Z0-9_.-]+$`)
|
||||
|
||||
// CodexToolName is name as the ChatGPT backend takes it: as it is when
|
||||
// it is valid, else each character the backend refuses as "_", cut to
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/codexcat"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -119,7 +119,7 @@ func codexUserAgent(v string) string {
|
||||
return "codex_cli_rs/" + v + " (" + codexUA.os + "; " + arch + ") " + term
|
||||
}
|
||||
|
||||
var versionRE = regexp.MustCompile(`\d+(\.\d+)+`)
|
||||
var versionRE = lazyre.New(`\d+(\.\d+)+`)
|
||||
|
||||
// codexOS names the system as Codex CLI does: "Mac OS 26.6.0",
|
||||
// "Windows 10.0.26100", "Linux 6.8.0".
|
||||
|
||||
@@ -13,12 +13,13 @@ package provider
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// gheName is an enterprise's subdomain of ghe.com: one DNS label.
|
||||
var gheName = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`)
|
||||
var gheName = lazyre.New(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`)
|
||||
|
||||
// CopilotHost is where a Copilot account signs in, from what a user typed
|
||||
// ("acme.ghe.com", "https://acme.ghe.com/", "github.com"): "" for
|
||||
|
||||
@@ -11,9 +11,10 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// copilotRefusedFor is how long a refused model stays left out: a plan
|
||||
@@ -29,12 +30,12 @@ var (
|
||||
// not that it is asked on the wrong endpoint ("not accessible via the
|
||||
// /chat/completions endpoint", unsupported_api_for_model), which the
|
||||
// gateway takes to another of the model's endpoints.
|
||||
var copilotNotServed = regexp.MustCompile(`(?i)"model_not_supported"|requested model is not supported`)
|
||||
var copilotNotServed = lazyre.New(`(?i)"model_not_supported"|requested model is not supported`)
|
||||
|
||||
// copilotSessionGone is Copilot saying the request's Copilot-Session-Token
|
||||
// doesn't hold its model ("Requested model not available for session"),
|
||||
// which it says once the session is read (copilotAPIHeaders).
|
||||
var copilotSessionGone = regexp.MustCompile(`(?i)not available for session`)
|
||||
var copilotSessionGone = lazyre.New(`(?i)not available for session`)
|
||||
|
||||
// copilotRefused notes a refusal of model for the account, and says whether
|
||||
// the request is worth sending again: when Auto picked the model, as Auto
|
||||
|
||||
@@ -41,7 +41,6 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -50,6 +49,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/lastgood"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// DailyCredits is what one of an account's credits windows went to day
|
||||
@@ -144,7 +144,7 @@ func creditUnit(s string) string {
|
||||
// currency sign, thousands' commas, a compact K/M/B/万/亿, an exponent
|
||||
// (Qoder's 1.5e+06), and a unit word after; a note after a " · " (CodeArts'
|
||||
// "· 300 即将过期", JoyCode's "· 剩余 …") is cut before it is read.
|
||||
var creditsDisplay = regexp.MustCompile(`(?i)^\s*([$¥¥€])?\s*([\d.,]*\d(?:e[+-]?\d+)?)\s*([kmb]\b|万|亿)?\s*/\s*([$¥¥€])?\s*([\d.,]*\d(?:e[+-]?\d+)?)\s*([kmb]\b|万|亿)?\s*(.*?)\s*$`)
|
||||
var creditsDisplay = lazyre.New(`(?i)^\s*([$¥¥€])?\s*([\d.,]*\d(?:e[+-]?\d+)?)\s*([kmb]\b|万|亿)?\s*/\s*([$¥¥€])?\s*([\d.,]*\d(?:e[+-]?\d+)?)\s*([kmb]\b|万|亿)?\s*(.*?)\s*$`)
|
||||
|
||||
func creditsNumber(n, scale string) (float64, bool) {
|
||||
if strings.Count(n, ".") > 1 {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -145,15 +145,15 @@ func parseCursorAbout(out []byte) (user, plan string, said bool) {
|
||||
// whatever about said; a var so tests can fake it.
|
||||
var cursorSignedOut = func() bool { return readCursorToken() == "" }
|
||||
|
||||
var ansi = regexp.MustCompile(`\x1b\[[0-9;?]*[A-Za-z]`)
|
||||
var ansi = lazyre.New(`\x1b\[[0-9;?]*[A-Za-z]`)
|
||||
|
||||
// cursorDefaultContext is the context Cursor gives a model it doesn't name
|
||||
// as a 1M one.
|
||||
const cursorDefaultContext = 200_000
|
||||
|
||||
var (
|
||||
cursorMillion = regexp.MustCompile(`\b(\d+)M\b`)
|
||||
cursorVariant = regexp.MustCompile(`-(fast|none|low|medium|high|xhigh|extra-high|max|thinking)$`)
|
||||
cursorMillion = lazyre.New(`\b(\d+)M\b`)
|
||||
cursorVariant = lazyre.New(`-(fast|none|low|medium|high|xhigh|extra-high|max|thinking)$`)
|
||||
)
|
||||
|
||||
// cursorContext is how much of a conversation Cursor lets a model hold. Its
|
||||
@@ -197,7 +197,7 @@ func withCursorContexts(ms []catalog.Model) []catalog.Model {
|
||||
return out
|
||||
}
|
||||
|
||||
var cursorLoginURL = regexp.MustCompile(`https://\S+`)
|
||||
var cursorLoginURL = lazyre.New(`https://\S+`)
|
||||
|
||||
// cursorAuthFile is where cursor-agent keeps its sign-in off a Mac's keychain.
|
||||
func cursorAuthFile() string {
|
||||
|
||||
@@ -18,11 +18,11 @@ package provider
|
||||
// way to ask for it.
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// cursorEfforts are the effort words of Cursor's ids, the levels magpie
|
||||
@@ -181,7 +181,7 @@ func collapseCursorModels(raw []catalog.Model) []catalog.Model {
|
||||
|
||||
// cursorCapacity is the context Cursor puts in a model's name ("Claude
|
||||
// Opus 5.5 1M", "GPT-5.5 (1M)").
|
||||
var cursorCapacity = regexp.MustCompile(`\(\s*\d+M\s*\)|\b\d+M\b`)
|
||||
var cursorCapacity = lazyre.New(`\(\s*\d+M\s*\)|\b\d+M\b`)
|
||||
|
||||
// withoutCursorCapacity is Cursor's list, collapsed, with the context taken
|
||||
// out of each name: it is the model's Context, shown apart. A name that
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -33,6 +32,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -324,7 +324,7 @@ func devinDeclaredImages() map[string]*bool {
|
||||
return out
|
||||
}
|
||||
|
||||
var devinEffort = regexp.MustCompile(`-(none|min|minimal|low|medium|high|xhigh|max|fast|priority)$`)
|
||||
var devinEffort = lazyre.New(`-(none|min|minimal|low|medium|high|xhigh|max|fast|priority)$`)
|
||||
|
||||
// devinKnown is models.dev's window and reply cap for a model id, with the
|
||||
// effort suffix taken off: claude-opus-5-5-high-fast has claude-opus-5-5's.
|
||||
|
||||
@@ -17,17 +17,17 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
)
|
||||
|
||||
// factoryKeyPrefix is droid's Uh: what a Factory API key starts with.
|
||||
const factoryKeyPrefix = "fk-"
|
||||
|
||||
var factoryKeyRe = regexp.MustCompile(`\bfk-[A-Za-z0-9_\-]{8,}`)
|
||||
var factoryKeyRe = lazyre.New(`\bfk-[A-Za-z0-9_\-]{8,}`)
|
||||
|
||||
// factoryKeysIn finds the API keys in pasted text: one a line, in a .env
|
||||
// line (FACTORY_API_KEY=fk-…) or in JSON, each once.
|
||||
|
||||
@@ -12,11 +12,12 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// FaviconFor finds the site behind a provider's base URL and keeps its icon
|
||||
@@ -250,9 +251,9 @@ func letterIcon(name string) (string, error) {
|
||||
const iconUA = "magpie"
|
||||
|
||||
var (
|
||||
linkTag = regexp.MustCompile(`(?is)<link\b[^>]*>`)
|
||||
tagAttr = regexp.MustCompile(`(?is)\b(rel|href|sizes|type)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))`)
|
||||
headDone = regexp.MustCompile(`(?i)</head>|<body\b`)
|
||||
linkTag = lazyre.New(`(?is)<link\b[^>]*>`)
|
||||
tagAttr = lazyre.New(`(?is)\b(rel|href|sizes|type)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))`)
|
||||
headDone = lazyre.New(`(?i)</head>|<body\b`)
|
||||
)
|
||||
|
||||
// pageIcons are the pictures a site's home page names as its icon, the
|
||||
|
||||
@@ -23,13 +23,13 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -37,8 +37,8 @@ import (
|
||||
// "NVIDIA #595", "Mistral #0001", or "NVIDIA NIM 2" as freeName names a
|
||||
// second one alike.
|
||||
var (
|
||||
numberedHash = regexp.MustCompile(`^(.*\S)\s*#\s*\d+$`)
|
||||
numberedSpace = regexp.MustCompile(`^(.*\S) (\d+)$`)
|
||||
numberedHash = lazyre.New(`^(.*\S)\s*#\s*\d+$`)
|
||||
numberedSpace = lazyre.New(`^(.*\S) (\d+)$`)
|
||||
)
|
||||
|
||||
// copyBase is the name a numbered copy is a copy of, and whether name is
|
||||
|
||||
@@ -2,8 +2,9 @@ package provider
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
)
|
||||
|
||||
// A custom provider can be given a Gemini API (#1346): Google's own at
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
|
||||
// geminiMethod is a Gemini endpoint pasted whole, cut back to its base:
|
||||
// …/models/gemini-2.5-pro:streamGenerateContent?alt=sse, or …/models.
|
||||
var geminiMethod = regexp.MustCompile(`/models(?:/[^/?#]*)?(?:[?#].*)?$`)
|
||||
var geminiMethod = lazyre.New(`/models(?:/[^/?#]*)?(?:[?#].*)?$`)
|
||||
|
||||
// GeminiBase is the base a Gemini URL is kept as: trimmed, an endpoint or
|
||||
// the model list pasted whole cut back to the base, and a bare host given
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -37,6 +36,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
@@ -709,18 +709,18 @@ func runCLISignIn(s *signInFlow, what string, env []string, using bool, failed f
|
||||
// it couldn't reach, not a page to open: grok 1.0.46 behind a proxy it
|
||||
// can't get through prints "Error: error sending request for url
|
||||
// (https://auth.x.ai/oauth2/device/code): …" (𝕏 on Discord).
|
||||
var failedLine = regexp.MustCompile(`(?i)\berror\b`)
|
||||
var failedLine = lazyre.New(`(?i)\berror\b`)
|
||||
|
||||
// linkWait is how long a login command has to print its link.
|
||||
var linkWait = 30 * time.Second
|
||||
|
||||
// linkRest is a line that is nothing but more of a link: no spaces, only
|
||||
// what a URL holds.
|
||||
var linkRest = regexp.MustCompile(`^[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=%]+$`)
|
||||
var linkRest = lazyre.New(`^[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=%]+$`)
|
||||
|
||||
// queryRest is what may still follow a link that already has its challenge
|
||||
// and uuid: the rest of a value, or more params.
|
||||
var queryRest = regexp.MustCompile(`^[A-Za-z0-9\-_%&=]+$`)
|
||||
var queryRest = lazyre.New(`^[A-Za-z0-9\-_%&=]+$`)
|
||||
|
||||
// AgentUser is who an agent is signed in to itself, as its own files say,
|
||||
// for an agent whose vendor a plugin serves too; "" when not known.
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
@@ -40,7 +41,7 @@ import (
|
||||
// the bucket behind it. A var so tests can point it elsewhere.
|
||||
var grokCLIBases = []string{"https://x.ai/cli", "https://storage.googleapis.com/grok-build-public-artifacts/cli"}
|
||||
|
||||
var grokVersionRe = regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9._]+)?$`)
|
||||
var grokVersionRe = lazyre.New(`^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9._]+)?$`)
|
||||
|
||||
// grokMaxBinary bounds what is unpacked, as the installer bounds it.
|
||||
const grokMaxBinary = 512 << 20
|
||||
|
||||
@@ -25,13 +25,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -789,7 +789,7 @@ func SetAutoGroups(on bool) error {
|
||||
// vendor spells it: "auto-claude-opus-5-5" for claude-opus-5.5.
|
||||
func AutoGroupID(model string) string { return "auto-" + Slug(sameModel(model)) }
|
||||
|
||||
var groupDots = regexp.MustCompile(`\.{2,}`)
|
||||
var groupDots = lazyre.New(`\.{2,}`)
|
||||
|
||||
// GroupSlug derives a group's own id from a name as Slug does, the dots
|
||||
// kept: "GPT 6.1 Sol" → "gpt-6.1-sol", so an agent sending group/<id> sends
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user