Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(omp): resolve path shorthand the way omp does before a call

Kyle Elliott4b19f6db929e
diff --git a/cli/beacon-hooks/cmd/omp_paths_test.go b/cli/beacon-hooks/cmd/omp_paths_test.go
index dd5f4897..6820d28c 100644
--- a/cli/beacon-hooks/cmd/omp_paths_test.go
+++ b/cli/beacon-hooks/cmd/omp_paths_test.go
@@ -71,6 +71,17 @@ func TestOmpPathAsWrittenIsResolvedTheWayTheRuntimeWill(t *testing.T) {
{"report:2024", filepath.Join(cwd, "report:2024")},
// Not selector grammar: a range may not end in `+`.
{"a.go:12+", filepath.Join(cwd, "a.go:12+")},
+ // The runtime's shorthand, applied the way its expandPath and resolveToCwd apply it.
+ {"/", cwd},
+ {"//", cwd},
+ {"@/etc/hosts", "/etc/hosts"},
+ {"@~/notes.md", filepath.Join(home, "notes.md")},
+ {":/etc/hosts", "/etc/hosts"},
+ {":../shared/a.go:1-5", filepath.Join(filepath.Dir(cwd), "shared/a.go")},
+ {"~work/notes.md", filepath.Join(home, "work/notes.md")},
+ {"Screenshot 2026-10-05 at 3.35.12\u202fPM.png", filepath.Join(cwd, "Screenshot 2026-10-05 at 3.35.12 PM.png")},
+ // A leading `@` before anything else is part of the name.
+ {"@notes.md", filepath.Join(cwd, "@notes.md")},
} {
t.Run(tc.target, func(t *testing.T) {
for _, typ := range []string{"tool_call", "tool_approval_requested"} {
@@ -86,6 +97,53 @@ func TestOmpPathAsWrittenIsResolvedTheWayTheRuntimeWill(t *testing.T) {
}
}
+// A read the runtime reports as a URL or one of its own resources is not a file read, even when a
+// file in the runtime's storage backs it and the spelling looked like a path: the runtime routes
+// `local:/plan.md` as `local://plan.md`. And a URL behind an `@` mention marker is a URL, not a
+// file named `@skill:/…`; the runtime refuses to read it as a path at all.
+func TestOmpResourceReadIsNotAFileWhateverItsSpelling(t *testing.T) {
+ for _, payload := range []map[string]interface{}{
+ {"type": "tool_result", "toolName": "read", "input": map[string]interface{}{"path": "local:/plan.md"},
+ "details": map[string]interface{}{
+ "resolvedPath": "/home/u/.omp/agent/sessions/s/local/plan.md",
+ "meta": map[string]interface{}{"source": map[string]interface{}{"type": "internal", "value": "local://plan.md"}},
+ }},
+ {"type": "tool_call", "toolName": "read", "input": map[string]interface{}{"path": "@skill://self-verify-beacon-in-sandbox"}},
+ {"type": "tool_result", "toolName": "read", "input": map[string]interface{}{"path": "@skill://self-verify-beacon-in-sandbox"},
+ "isError": true},
+ } {
+ payload["toolCallId"], payload["cwd"] = "call-1", "/repo"
+ events := ompRuntime.endpointEvents(payload, "sess-1")
+ if len(events) != 1 {
+ t.Fatalf("%v produced %d events, want 1", payload, len(events))
+ }
+ if file, ok := events[0].fields["file"]; ok {
+ t.Fatalf("%s of %v grew a file block: %v", payload["type"], payload["input"], file)
+ }
+ }
+}
+
+func TestOmpDriveAliasPathFollowsTheHost(t *testing.T) {
+ for _, tc := range []struct {
+ path, goos string
+ wsl bool
+ want string
+ }{
+ {"/c/Users/me/a.go", "windows", false, `C:\Users\me\a.go`},
+ {"/mnt/d/src/a.go", "windows", false, `D:\src\a.go`},
+ {"/c", "windows", false, `C:\`},
+ {"/home/me/a.go", "windows", false, "/home/me/a.go"},
+ {`C:\Users\me\a.go`, "linux", true, "/mnt/c/Users/me/a.go"},
+ {"C:/Users/me/a.go", "linux", true, "/mnt/c/Users/me/a.go"},
+ {`C:\Users\me\a.go`, "linux", false, `C:\Users\me\a.go`},
+ {"/c/Users/me/a.go", "darwin", false, "/c/Users/me/a.go"},
+ } {
+ if got := ompDriveAliasPath(tc.path, tc.goos, tc.wsl); got != tc.want {
+ t.Errorf("ompDriveAliasPath(%q, %s, wsl=%v) = %q, want %q", tc.path, tc.goos, tc.wsl, got, tc.want)
+ }
+ }
+}
+
// Oh My Pi's default edit format can change several files in one call. Its result names no single
// path, so each changed file is recorded as its own file.modified, keeping the edit's operation.
func TestOmpMultiFileEditRecordsEachFile(t *testing.T) {
diff --git a/cli/beacon-hooks/cmd/pi_family.go b/cli/beacon-hooks/cmd/pi_family.go
index 84a6f89e..5e2c463c 100644
--- a/cli/beacon-hooks/cmd/pi_family.go
+++ b/cli/beacon-hooks/cmd/pi_family.go
@@ -4,8 +4,10 @@ import (
"encoding/json"
"net/url"
"os"
+ "path"
"path/filepath"
"regexp"
+ "runtime"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon-hooks/internal/diff"
@@ -430,34 +432,49 @@ func isURIScheme(s string) bool {
//
// On a runtime that resolves its tool paths, the runtime's own statement of the file is preferred,
// because it is the one path that is certainly right: it is absolute, and any selector or `~` in
-// what the model wrote has already been resolved. A tool_call or an approval, which happen before
-// the runtime has resolved anything, resolve the target the same way the runtime will.
+// what the model wrote has already been resolved. A result whose source the runtime reports as a
+// URL or one of its own resources is not a file, whatever file backs it. A tool_call or an
+// approval, which happen before the runtime has resolved anything, resolve the target the same way
+// the runtime will.
func (f piFamily) filePath(call piToolCall, input map[string]interface{}, target string) string {
+ if f.resolvesToolPaths {
+ target = ompStripPathMarker(target)
+ }
path := piFilePath(target)
if path == "" || !f.resolvesToolPaths {
return path
}
- if resolved := piResolvedPath(call.details); resolved != "" {
+ resolved, isFile := piResolvedPath(call.details)
+ if !isFile {
+ return ""
+ }
+ if resolved != "" {
return resolved
}
- return ompToolPath(path, resolveCwd(input, f.platform))
+ return ompToolPath(path, resolveCwd(input, f.platform), runtime.GOOS, ompIsWSL())
}
-// piResolvedPath returns the absolute path a tool result reports having read or written.
+// piResolvedPath returns the absolute path a tool result reports having read or written, and
+// whether the result describes a file at all.
//
-// Oh My Pi reports it in three places, one per tool: a read names its source in `meta.source`
-// when the source was a file, a write names the file in `resolvedPath`, and an edit of one file
-// names it in `path`. A read of anything else -- a URL, or a runtime resource backed by a file in
-// the runtime's own storage -- reports a different source type and is never taken for a file.
-func piResolvedPath(details map[string]interface{}) string {
- path := getFirstStr(details, "resolvedPath", "path")
- if source := firstMap(firstMap(details, "meta"), "source"); getFirstStr(source, "type") == "path" {
+// Oh My Pi reports the path in three places, one per tool: a read names its source in
+// `meta.source`, a write names the file in `resolvedPath`, and an edit of one file names it in
+// `path`. A read whose source is a URL or an `internal` resource is not a file read, even when a
+// file in the runtime's own storage backs it and `resolvedPath` names that file.
+func piResolvedPath(details map[string]interface{}) (string, bool) {
+ var path string
+ switch source := firstMap(firstMap(details, "meta"), "source"); getFirstStr(source, "type") {
+ case "path":
path = getFirstStr(source, "value")
+ case "":
+ path = getFirstStr(details, "resolvedPath", "path")
+ default:
+ return "", false
}
if !filepath.IsAbs(path) {
- return ""
+ return "", true
}
- return path
+ return path, true
}
// ompLineSelector is Oh My Pi's read selector grammar, FILE_LINE_RANGE_RE in its
@@ -468,6 +485,47 @@ var ompLineSelector = regexp.MustCompile(`(?i)^(?:` + ompLineRange + `(?:,` + om
const ompLineRange = `L?\d+(?:(?:\.\.|-)(?:L?\d+)?|\+L?\d+)?`
+// ompStrayColon matches the stray `:` some models put in front of a path (`:/abs`, `:../rel`,
+// `:C:\repo`), which Oh My Pi drops before resolving: no real path starts with `:`.
+var ompStrayColon = regexp.MustCompile(`^:(?:[/\\~]|\.\.?[/\\]|[A-Za-z]:)`)
+
+// ompWindowsAbsolute matches a Windows absolute path: a drive (`C:\`, `C:/`), a UNC share, or a
+// root-relative `\path`, the forms Node's path.win32.isAbsolute accepts.
+var ompWindowsAbsolute = regexp.MustCompile(`^(?:[A-Za-z]:[\\/]|[\\/]{2}|\\)`)
+
+// ompStripPathMarker drops the marker characters Oh My Pi strips from the front of a path before
+// it reads one, mirroring the first steps of its expandPath (tools/path-utils.ts).
+//
+// A stray `:` goes before a path shape. A leading `@` -- a mention marker -- goes only before `/`,
+// `~`, a Windows absolute path, or an internal URL, so a file literally named `@notes.md` keeps its
+// name. The runtime recognizes an internal URL by its own scheme registry; any `scheme://` other
+// than a file or web URL is taken for one here, because it is not a file either way. Stripping the
+// `@` before the URI check is what keeps `@skill://name` from being read as a file path.
+func ompStripPathMarker(target string) string {
+ if ompStrayColon.MatchString(target) {
+ target = target[1:]
+ }
+ rest, ok := strings.CutPrefix(target, "@")
+ if !ok {
+ return target
+ }
+ if strings.HasPrefix(rest, "/") || rest == "~" || strings.HasPrefix(rest, "~/") || ompWindowsAbsolute.MatchString(rest) {
+ return rest
+ }
+ if scheme, _, ok := strings.Cut(rest, "://"); ok && isURIScheme(scheme) {
+ switch strings.ToLower(scheme) {
+ case "file", "http", "https":
+ default:
+ return rest
+ }
+ }
+ return target
+}
+
+// ompUnicodeSpaces are the space characters Oh My Pi reads as a plain space in a path: no-break,
+// the U+2000 block, narrow no-break, medium mathematical and ideographic.
+var ompUnicodeSpaces = regexp.MustCompile("[\u00A0\u2000-\u200A\u202F\u205F\u3000]")
+
// ompToolPath turns a path as an Oh My Pi tool was given it into the file it names.
//
// Oh My Pi resolves a relative path against the session's working directory, expands `~`, and
@@ -477,19 +535,36 @@ const ompLineRange = `L?\d+(?:(?:\.\.|-)(?:L?\d+)?|\+L?\d+)?`
// credential-read rules match `(^|/)\.env($|\.)`, not `.env:1-20` -- and filed one file under as
// many names as it was read with. Cline resolves relative paths for the same reason.
//
+// The rest of the runtime's shorthand is applied the same way its expandPath and resolveToCwd
+// apply it (tools/path-utils.ts), so the path recorded before a call is the one its result will
+// report: Unicode spaces become plain spaces; `~name` is `<home>/name`, the runtime's reading
+// rather than a shell's; a Windows drive alias is translated for the host (ompDriveAliasPath); and
+// a path that is nothing but slashes means the working directory, because the runtime reads `/`
+// as "here" rather than the filesystem root.
+//
// The selector is peeled the way the runtime peels it: from the last colon, only when what follows
// is selector grammar, at most twice (a range and `raw` may be combined), and not at all when a
// file of that literal name exists, which is the runtime's own tiebreak.
-func ompToolPath(path, cwd string) string {
- if path == "~" || strings.HasPrefix(path, "~/") || strings.HasPrefix(path, "~"+string(filepath.Separator)) {
+//
+// What this cannot reproduce is anything the runtime decides by looking at the disk once the path
+// it resolved turns out not to exist -- a unique-suffix search under the working directory, an
+// edit rebound by its snapshot tag, or a macOS spelling variant of the name. Those reach only the
+// result, which reports the file the runtime actually used.
+func ompToolPath(target, cwd, goos string, wsl bool) string {
+ p := ompUnicodeSpaces.ReplaceAllString(target, " ")
+ if strings.HasPrefix(p, "~") {
if home, err := os.UserHomeDir(); err == nil {
- path = filepath.Join(home, path[1:])
+ p = filepath.Join(home, p[1:])
}
}
- if !filepath.IsAbs(path) && cwd != "" {
- path = filepath.Join(cwd, path)
+ p = ompDriveAliasPath(p, goos, wsl)
+ switch {
+ case strings.Trim(p, "/") == "" && cwd != "":
+ p = cwd
+ case !filepath.IsAbs(p) && cwd != "":
+ p = filepath.Join(cwd, p)
}
- stripped := path
+ stripped := p
for range 2 {
i := strings.LastIndexByte(stripped, ':')
if i <= 0 || !ompLineSelector.MatchString(stripped[i+1:]) {
@@ -497,15 +572,71 @@ func ompToolPath(path, cwd string) string {
}
stripped = stripped[:i]
}
- if stripped == path {
- return path
+ if stripped == p {
+ return p
}
- if _, err := os.Lstat(path); err == nil {
- return path
+ if _, err := os.Lstat(p); err == nil {
+ return p
}
return stripped
}
+// ompDriveAliasPath translates a Windows drive alias for the host the runtime runs on, mirroring
+// its normalizeWindowsDriveAliasPath: on Windows, an MSYS or WSL mount root (`/c/...`,
+// `/mnt/c/...`) is the drive itself (`C:\...`); under WSL, a pasted Windows path (`C:\...`,
+// `C:/...`) is that drive's mount (`/mnt/c/...`). Anywhere else the path is left alone.
+func ompDriveAliasPath(p, goos string, wsl bool) string {
+ switch {
+ case goos == "windows":
+ parts := strings.Split(p, "/")
+ if len(parts) < 2 || parts[0] != "" {
+ return p
+ }
+ var drive string
+ tail := parts[2:]
+ if isDriveLetter(parts[1]) {
+ drive = strings.ToUpper(parts[1])
+ } else if len(parts) >= 3 && strings.EqualFold(parts[1], "mnt") && isDriveLetter(parts[2]) {
+ drive = strings.ToUpper(parts[2])
+ tail = parts[3:]
+ }
+ if drive == "" {
+ return p
+ }
+ return drive + `:\` + strings.Join(nonEmpty(tail), `\`)
+ case wsl:
+ match := ompWindowsDrivePath.FindStringSubmatch(strings.ReplaceAll(strings.TrimSpace(p), "/", `\`))
+ if match == nil {
+ return p
+ }
+ segments := append([]string{"/mnt", strings.ToLower(match[1])}, nonEmpty(strings.Split(match[2], `\`))...)
+ return path.Join(segments...)
+ default:
+ return p
+ }
+}
+
+var ompWindowsDrivePath = regexp.MustCompile(`^([A-Za-z]):\\(.*)$`)
+
+func isDriveLetter(s string) bool {
+ return len(s) == 1 && (s[0] >= 'a' && s[0] <= 'z' || s[0] >= 'A' && s[0] <= 'Z')
+}
+
+func nonEmpty(parts []string) []string {
+ out := parts[:0:0]
+ for _, part := range parts {
+ if part != "" {
+ out = append(out, part)
+ }
+ }
+ return out
+}
+
+// ompIsWSL reports whether the hook runs under WSL, the way Oh My Pi's isWsl decides it.
+func ompIsWSL() bool {
+ return runtime.GOOS == "linux" && (os.Getenv("WSL_DISTRO_NAME") != "" || os.Getenv("WSL_INTEROP") != "")
+}
+
// ompMCPResourceScheme is the URI scheme through which Oh My Pi's read tool reads an MCP resource:
// `read mcp://<resource-uri>` asks whichever connected server lists that resource.
const ompMCPResourceScheme = "mcp://"
diff --git a/docs/runtimes/oh-my-pi.mdx b/docs/runtimes/oh-my-pi.mdx
index a7a62823..5925b811 100644
--- a/docs/runtimes/oh-my-pi.mdx
+++ b/docs/runtimes/oh-my-pi.mdx
@@ -112,7 +112,18 @@ Unlike Pi, a project-level install needs no trust prompt: Oh My Pi loads `.omp`
### File paths
-Oh My Pi's tools take a path the way the model wrote it: relative to the session's working directory or to `~`, often with a line selector such as `.env:1-20`, `main.go:5-16,960-973`, or `notes.md:raw`. Beacon records the file that path names, as an absolute path, so file rules and queries see `/repo/.env` rather than `.env:1-20`. Results use the path Oh My Pi reports having resolved. The `tool.invoked` before a call, and any approval for it, resolve the path the same way Oh My Pi will: against the working directory, with `~` expanded and the selector removed, unless a file of that literal name exists. `tool.path` keeps the path as written, selector included.
+Oh My Pi's tools take a path the way the model wrote it: relative to the session's working directory or to `~`, often with a line selector such as `.env:1-20`, `main.go:5-16,960-973`, or `notes.md:raw`. Beacon records the file that path names, as an absolute path, so file rules and queries see `/repo/.env` rather than `.env:1-20`. Results use the path Oh My Pi reports having resolved. `tool.path` keeps the path as written, selector included.
+
+The `tool.invoked` before a call, and any approval for it, resolve the path the same way Oh My Pi will:
+
+- against the session's working directory, even when the session has extra workspace directories (`--add-dir`), which Oh My Pi's tools only reach by absolute path;
+- with `~` expanded, including Oh My Pi's reading of `~name` as `<home>/name`;
+- with a stray leading `:` dropped, and a leading `@` dropped before `/`, `~`, a Windows absolute path, or a URL;
+- with Unicode spaces read as plain spaces, and a Windows drive alias translated for the host (`/c/...` on Windows, `C:\...` under WSL);
+- with a path of nothing but slashes read as the working directory;
+- with the selector removed, unless a file of that literal name exists.
+
+A result Oh My Pi reports as a URL or one of its own resources is never recorded as a file, even when a file backs it. The event before a call cannot follow what Oh My Pi decides by looking at the disk after the path it resolved turns out not to exist: a unique-suffix search under the working directory, an edit rebound by its snapshot tag, or a macOS spelling variant of a filename. Only the result records the file Oh My Pi used in those cases.
Oh My Pi's default edit format can change several files in one call. Such an edit is recorded as one `file.modified` per file, each with that file's diff and its own operation (`create`, `modify`, or `delete`).