agent: DeepSeek Harness Desktop is found on Linux (AUR, .deb, AppImage entry)
xianhongtao (magpie 0.1.3232, Arch Linux) has DeepSeek Harness Desktop
from the AUR (deepseek-harness-desktop 0.2.2rc.1-1) and no dsh CLI.
magpie knew the app on macOS and Windows only, so it said "DeepSeek
Harness CLI not found ~/.dsh/profiles/web/cordis.patch.yml".
HasApp for dsh now also finds the Linux app (linuxApp, desktopapp_xdg.go):
- a folder holding the Electron executable deepseek-harness with
resources/app.asar beside it: /usr/lib/deepseek-harness-desktop (the
AUR's) or /opt/DeepSeek Harness (electron-builder's .deb/.rpm);
- or the app's desktop entry in the XDG data dirs (XDG_DATA_HOME first,
then XDG_DATA_DIRS, the first file of a name wins, Hidden=true hides
it): Name=DeepSeek Harness, Type Application, MimeType holding
x-scheme-handler/dsh, and its Exec program there (on PATH, or an
absolute executable file: an AppImage anywhere). Scans of a folder are
kept by its mtime, trusted only when read over a second after it
changed and for a minute at most.
Linux only; macOS and Windows keep their own checks.
Siblings: everything reading HasApp for dsh follows: the profile a fresh
~/.dsh gets (profiles/desktop), the desktop lead and notices, cliHeld and
CLIMissing (so the GUI's and the CLI's "CLI not found" go away). The
"running" check for noticeDsh2 also knows deepseek-harness, the app's
Linux executable. With both profiles present (the reporter's case) Path
stays profiles/web as on macOS; the desktop lead picks the model shown.
Run (mote, through mote-run):
- go test -count=1 -race -run 'TestDshLinux|TestDshDesktop|TestCodexLinux|Lody' ./internal/agent/: ok
- go test -count=1 ./internal/agent/ ./internal/gui/ ./internal/cli/: ok
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; GOOS=linux/windows go build: ok
Run (wsl-run, magpie-desktop, Ubuntu 24.04): the TestDshLinux tests
-count=3: ok. The first WSL run caught a stale scan of a folder made
again within the same mtime tick; the 1s rule fixes it.
Broken by hand (mote), each red, then restored:
- installed() without onLinux: all three new tests red ("the AUR's app:
app false, CLI missing true", "the AUR's entry, its program on PATH,
not found", the profile = profiles/web, want profiles/desktop);
- no scheme check: "another app's entry taken for DeepSeek Harness's";
- no Hidden check: "an entry the user hid still counts".
Not tried: a real AUR, .deb or AppImage install of DeepSeek Harness
Desktop (the fixtures are the AUR PKGBUILD's entry and layout as the
reporter gave them, and AppImageLauncher's entry shape); the GUI suite
(no GUI file changed). The full suite runs after the push.
Reported-by: xianhongtao (Discord)
This commit is contained in:
@@ -170,7 +170,7 @@ something else shows up as drift.
|
||||
- VS Code's, Insiders' and VSCodium's User and extensions folders come from one build (`vscodeDirs` in [`vscode.go`](../../internal/agent/vscode.go)), so its chat models, profiles, Disconnect and Zoo Code (which keeps its settings in that User folder and is found by its extension there) all use the same place. A portable build keeps both in its data folder, `user-data/User` and `extensions`, and is told as VS Code's own `configurePortable` (`src/bootstrap-node.ts`) tells it: its `product.json` has no `target` (an installer's build has one), and its data folder exists, `data` beside the program on Windows and Linux (`<install>/data`, also for a build that updates into `<install>/<version>`), or on a Mac `product.json`'s `portable`, else `<applicationName>-portable-data`, beside the `.app` (`vscodePortableAt`). The build is the one the launcher on PATH is, through a Scoop shim and every symlink (`/usr/local/bin/code` into `/Applications/Code/Visual Studio Code.app`, #4151, faketrader; Scoop's `current` junction, #3260, #4009); a launcher whose `product.json` names another editor (a fork's `code`) is not the build's. A Mac with no launcher of the build's reads the app folders and Spotlight, and takes a portable bundle only when every bundle found is that one; beside an installed one, which the user runs is unknown and nothing moves. An installed build keeps the OS's folder (`~/Library/Application Support/Code/User`, `%APPDATA%\Code\User`, `$XDG_CONFIG_HOME/Code/User`) and `~/.vscode/extensions`. `VSCODE_PORTABLE` is not read: it is the editor's environment, not magpie's. A group an older magpie wrote in the OS's folder for a portable build stays there; connecting again writes the portable one. Disconnect's preview is refused for a file in a portable data folder: its process keeps the PATH, whose launcher would find the build's own files, not the copy (`TestVSCodeMacPortable*`, `TestVSCodePortableUserDir`, `TestVSCodePortableScoopShim`, `TestVSCodePortableProduct`).
|
||||
- An agent is detected by its config file, its folder, or its command on magpie's PATH (`Detected`). That PATH is the login shell's plus the folders users' tools go in (`proc.UserPath`: `~/.local/bin`, npm's prefixes, the Node nvm's default alias resolves to (the highest installed when it names none), bun, Homebrew, ...; on Windows the registry's PATH plus the Node fnm's default alias names, `%APPDATA%\fnm\aliases\default` or under `FNM_DIR`, which fnm puts on a terminal's PATH from the shell profile and never in the registry, #2685), so a CLI a terminal doesn't find can still be found and listed: an npm install under a Node the terminal no longer uses. `/api/agents/cli` then gives where it is (`path`) and `offPath` when the login shell's PATH (`proc.LoginPath`) lacks its folder, and the Agents row says "Not on your terminal's PATH", its tip naming the file (悠悠哥 on Discord: Codex 0.162.1 listed with no codex on PATH and no `~/.codex`). An unknown login PATH says nothing. A folder another tool writes too doesn't count (`dirShared`): Pi's for omp, `~/.copilot` for the Copilot CLI, which GitHub Copilot's JetBrains and VS Code plugins also write, and Qoder's and Qoder CN's, which Qoder's JetBrains plugin fills, and `~/.cursor` for Cursor CLI, which the Cursor editor makes on its own (`TestCursorFolderFromTheEditorIsNotTheCLI`, @G_Z_Y on X); only `cli-config.json` or `cursor-agent` finds Cursor CLI. A command another app ships under the agent's name doesn't count either: VS Code forks put a `code` launcher in their own bin folder (Cursor; Qoder IDE beside `qoder`), which their Windows installers put on PATH, so a `code`, `code-insiders` or `codium` counts as VS Code, Insiders or VSCodium only when the `product.json` beside it names that build (`applicationName`), or names none (`vscodeCodeBinary`; ggbr on Discord: Qoder IDE listed as VS Code too, `TestVSCodeDetected`, `TestVSCodeBuildLauncher`). A config file another tool writes first counts only when `pathOwn` says it is the agent's: Qoder's `settings.json` holding `enabledPlugins` alone is the plugin's (`qoderPluginOnly`; #1495, `TestCopilotFolderFromAnIDEPluginIsNotTheCLI`, `TestQoderSettingsFromAnIDEPluginIsNotTheCLI`). The Qoder app (the desktop app, which runs Qoder's CLI as its agent with the same folder) is found by the `.qoder-app-status.json` it writes there (`sign`, `qoderApp`; #2138, `TestQoderAppIsQoder`), as its `settings.json` can be its bundled plugin's `enabledPlugins` alone. Only the GUI and `daemon install` widen the PATH so; `magpie serve`, `web`, `tui` and the CLI keep the one they were started with, so an agent's CLI (`cliBin`, which its version and `omp`'s max effort are read from) is looked for in those folders (`proc.FindTool`) on every system when it isn't on the PATH, not only on Windows (whqtian on Discord: omp under `~/.bun/bin` on Ubuntu read as no version and offered xhigh in place of max; `TestOmpVersionOffPath`).
|
||||
- CLI lookup (`proc.Look`, `LookPath`, `FindTool`) caches answers and directory listings while PATH folders are unchanged. A directory modified in the last 100ms is read again rather than cached, so an installer writing in the same filesystem clock tick does not leave a permanent cached miss (#3141). Older and future-dated directories retain the cache; the normal two-second stamp window and explicit `proc.Forget` refresh remain. Filesystems whose timestamp resolution exceeds 100ms need a longer settling window.
|
||||
- Detection goes by an agent's folder, which an uninstall leaves behind, so an agent found by that alone is shown as gone (`CLIMissing`; #843, #2177, #2173): its CLI is on no PATH and in none of `proc.FindTool`'s folders nor where its own installer puts it (`~/.claude/local`, `~/.codex/packages/standalone`, `~/.opencode/bin`, Hermes' `hermes-agent` checkout), and nothing else that reads the folder is here (`cliHeld`): its desktop app (`HasApp`), an editor's extension (`~/.<editor>/extensions/<id>-*`: `anthropic.claude-code`, `openai.chatgpt`, `saoudrizwan.claude-dev`), Claude.app, OpenCode.app and Goose.app on a Mac, a JetBrains IDE's settings (its AI Assistant's agents and Cline's plugin) or Zed's `external_agents` (its Claude Code and Codex adapters). Where magpie can't tell (every shared folder, `cliShared`, on Windows, whose readers can be a Store app, a portable editor or a PATH only a shell profile sets, #1482, and there too one a desktop app of the agent's reads, `desktopApps`: DeepSeek Harness Desktop installs to any folder and puts its `dsh.cmd` in one the user picks, #2300, #2304; OpenCode and Goose off a Mac, Gemini, an agent detected its own way or by a command name other tools share, one with no install command but `cliOnly`'s Hermes), it is never gone. A gone row in the GUI shows "CLI not found" and none of its settings, nor Apply again; while connected it keeps its switch and Disconnect, and it folds under Not set up once not. Get started never offers it (`connectKind` is "no"). The TUI leaves it out and `magpie ls` says "CLI not found" (`TestCLIMissing*`, `agent-cli-missing.test.cjs`, `getting-started.test.cjs`).
|
||||
- Detection goes by an agent's folder, which an uninstall leaves behind, so an agent found by that alone is shown as gone (`CLIMissing`; #843, #2177, #2173): its CLI is on no PATH and in none of `proc.FindTool`'s folders nor where its own installer puts it (`~/.claude/local`, `~/.codex/packages/standalone`, `~/.opencode/bin`, Hermes' `hermes-agent` checkout), and nothing else that reads the folder is here (`cliHeld`): its desktop app (`HasApp`; on Linux DeepSeek Harness Desktop, which only others package, is found in the AUR's `/usr/lib/deepseek-harness-desktop` or a .deb's `/opt/DeepSeek Harness`, or by a desktop entry in the XDG data folders' `applications/` named DeepSeek Harness that handles `dsh://` and whose program is there, an AppImage's among them: `linuxApp` in [`desktopapp_xdg.go`](../../internal/agent/desktopapp_xdg.go), xianhongtao on Discord, `TestDshLinuxDesktopApp`, `TestDshLinuxDesktopEntry`), an editor's extension (`~/.<editor>/extensions/<id>-*`: `anthropic.claude-code`, `openai.chatgpt`, `saoudrizwan.claude-dev`), Claude.app, OpenCode.app and Goose.app on a Mac, a JetBrains IDE's settings (its AI Assistant's agents and Cline's plugin) or Zed's `external_agents` (its Claude Code and Codex adapters). Where magpie can't tell (every shared folder, `cliShared`, on Windows, whose readers can be a Store app, a portable editor or a PATH only a shell profile sets, #1482, and there too one a desktop app of the agent's reads, `desktopApps`: DeepSeek Harness Desktop installs to any folder and puts its `dsh.cmd` in one the user picks, #2300, #2304; OpenCode and Goose off a Mac, Gemini, an agent detected its own way or by a command name other tools share, one with no install command but `cliOnly`'s Hermes), it is never gone. A gone row in the GUI shows "CLI not found" and none of its settings, nor Apply again; while connected it keeps its switch and Disconnect, and it folds under Not set up once not. Get started never offers it (`connectKind` is "no"). The TUI leaves it out and `magpie ls` says "CLI not found" (`TestCLIMissing*`, `agent-cli-missing.test.cjs`, `getting-started.test.cjs`).
|
||||
- An agent's folder variable (`agentenv.Vars`: `PI_CODING_AGENT_DIR`, `CODEX_HOME`, `CLAUDE_CONFIG_DIR`, …) is read through `appdir.LookupEnv`, never `os.Getenv`. On Windows one that came from the registry is read there again, at most once a second, as a process started now would get it (the user's value over the machine's, `%…%` expanded), and set in magpie's environment so what magpie starts gets it too ([`follow.go`](../../internal/appdir/follow.go)): Windows never passes a changed User variable to a running process, and a magpie in the tray kept writing Pi's files into the AgentDir the user had moved and deleted (bm_rabbit on Discord). A value the launcher set itself, unlike the registry's, or one set inside magpie since, stands. `edit`'s writes make the folder such a variable names when the folder above it is there, as mkdir would, but never a missing tree above it (`appdir.Gone`): bm_rabbit's whole F:\piData was gone, and such a write fails with a `GoneError` naming the variable. An agent's default folder is made as before. Writes that call `os.MkdirAll` themselves (the library's skills and hooks, some agents' own files) don't ask yet (#4634).
|
||||
- Tests never touch the real machine. `TestMain` uses `testenv`, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears `agentenv.Vars` and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in `TestMain`. The one thing tests keep between runs is the pi tests' Bun install cache, `magpie-test-bun-cache-<uid>-<n>` in the temp folder (`pinnedPiCache` in `internal/plugin`), outside the test home on purpose so a run doesn't fetch the pinned pi's 118 packages again (#2865): it is used only when it is this user's alone, never as root, and is a new folder every two days, so the temp folder's cleaner never takes a file out of the one in use.
|
||||
- OmO and Prime Agent write a Gemini-capable model as `google-generative-ai` at the gateway's `/v1beta` (`piModelJSON` in [`agents.go`](../../internal/agent/agents.go)); each one's Google client takes the version path from `baseUrl` (senpi-ai's `apiVersion = ""`, Prime Agent's `pa-ai` `providers/google.rs`). omp does the same in `models.yml` (`ompProviderAt` in [`omp.go`](../../internal/agent/omp.go), #4277): its `google-generative-ai` posts to `baseUrl/models/<id>:streamGenerateContent?alt=sse` (pi-ai `providers/google.ts`, 16.0.0 to 18.14.0). Its Google client throws without a key, but under `auth: none` omp hands it its no-auth key `N/A`, which it sends as `x-goog-api-key` and loopback takes, so the provider stays keyless; a WSL omp under NAT sends its `apiKey` there. A Gemini 3 or later model thinks with `mode: google-level` (thinkingLevel MINIMAL to HIGH; xhigh and max go as HIGH), a Gemini 1.x or 2.x one with `budget`, which omp sends as `thinkingBudget: -1` (`ompGeminiMode`; `TestOmpGeminiModelsAskedOnGeminisAPI`). Checked with omp 18.14.0 against the gateway and a fake Gemini server. Pi and StepCode keep such a model on Chat, which the gateway translates (`piAsked`). StepCode registers no `google-generative-ai` stream, only `anthropic-messages`, `openai-completions` and `openai-responses` (Step-Code `packages/providers/src/compat.ts`), though its docs list it. Pi's own agent folder is read by apps that run Pi's SDK on it too: Raft's daemon (`@botiverse/raft-daemon`, pi-ai 0.83.0) opens `~/.pi/agent/models.json` and hands every request its own fetch, which pi-ai's Google adapter refuses before sending ("Custom fetch is not supported by the Google Generative AI adapter", in pi-ai 1.4.0 too; yunfei9958 on X, `TestPiFolderKeepsGeminiOnChatForRaft`). `magpieModels` in [`route.go`](../../internal/agent/route.go) includes Gemini and Code Assist capabilities when no native Chat, Responses or Messages API was selected; this includes a plugin model declaring `@ai-sdk/google`. Requests keep going through the gateway and the plugin's sign-in and fetch, with the gateway's usual translation where needed. A normal model sync updates existing entries. Routing groups retain their existing API choice, and Pencil remains on Chat. Pi resolves a level there to one of Gemini's four (minimal, low, medium, high) and throws on any other, so a level the model names otherwise is set to null in `thinkingLevelMap` (`TestPiGoogleThinkingLevelsAreGeminis`).
|
||||
|
||||
@@ -26,7 +26,7 @@ var notAnAgent = map[string]string{
|
||||
"USER": "the process' own",
|
||||
"XDG_CONFIG_HOME": "magpie's own folder's, which appdir decides",
|
||||
"XDG_DATA_HOME": "the same",
|
||||
"XDG_DATA_DIRS": "the system's own data folders, where a .deb puts Lody's desktop entry; a test that reaches agent.OpenLody sets it to its own",
|
||||
"XDG_DATA_DIRS": "the system's own data folders, where a .deb puts Lody's desktop entry; a test that reaches agent.OpenLody sets it to its own, and DeepSeek Harness Desktop's entries are read there through proc.SystemDirs",
|
||||
"XDG_CACHE_HOME": "Go's build cache's too, which a sandbox keeps shared; Air's ACP OpenCode under it is found by path in a test's own home (#2423)",
|
||||
"MAGPIE_ADDR": "magpie's own",
|
||||
"MAGPIE_DEBUG": "magpie's own debug flag",
|
||||
|
||||
@@ -33,7 +33,8 @@ import (
|
||||
// DisplayVersion): its installer lets the user pick another folder. more
|
||||
// are the app's other builds, each under a bundle id of its own (CodeBuddy's
|
||||
// China build beside its international one). linux is the folder the
|
||||
// vendor's own Linux packages install the app to.
|
||||
// vendor's own Linux packages install the app to; onLinux finds an app
|
||||
// others package for Linux (linuxApp).
|
||||
type desktopApp struct {
|
||||
id string
|
||||
names []string
|
||||
@@ -42,6 +43,7 @@ type desktopApp struct {
|
||||
publisher string
|
||||
guid string
|
||||
linux string
|
||||
onLinux *linuxApp
|
||||
more []desktopApp
|
||||
}
|
||||
|
||||
@@ -62,8 +64,18 @@ var desktopApps = map[string]desktopApp{
|
||||
// by default; the folder can be changed ("Choose an empty folder or the
|
||||
// registered DeepSeek Harness installation folder"), and the installer
|
||||
// registers it under HKCU\Software\1bf39983-… (#2279, read from
|
||||
// 0.2.0-rc.2's dsh-latest-windows-x64.exe installer script).
|
||||
"dsh": {id: "com.deepseek.dsh", names: []string{"DeepSeek Harness.app"}, win: filepath.Join("DeepSeek Harness", "DeepSeek Harness.exe"), guid: "1bf39983-50d0-5fe0-9ef4-cece76f67c5e"},
|
||||
// 0.2.0-rc.2's dsh-latest-windows-x64.exe installer script). DeepSeek
|
||||
// publishes no Linux build; its electron-builder config (0.2.2-rc.1)
|
||||
// has an AppImage target, productName DeepSeek Harness, executable
|
||||
// deepseek-harness and the dsh:// scheme. The AUR's
|
||||
// deepseek-harness-desktop builds it into
|
||||
// /usr/lib/deepseek-harness-desktop, with a deepseek-harness-desktop
|
||||
// script in /usr/bin and deepseek-ai-dsh-desktop.desktop (xianhongtao
|
||||
// on Discord: ~/.dsh shown as "CLI not found" and wired as the web
|
||||
// profile with that app in use); deepseek-harness-desktop-bin unpacks a
|
||||
// .deb of it into /opt/DeepSeek Harness, electron-builder's folder.
|
||||
"dsh": {id: "com.deepseek.dsh", names: []string{"DeepSeek Harness.app"}, win: filepath.Join("DeepSeek Harness", "DeepSeek Harness.exe"), guid: "1bf39983-50d0-5fe0-9ef4-cece76f67c5e",
|
||||
onLinux: &linuxApp{dirs: []string{"/usr/lib/deepseek-harness-desktop", "/opt/DeepSeek Harness"}, exe: "deepseek-harness", name: "DeepSeek Harness", scheme: "dsh"}},
|
||||
// DS Bot's desktop app (app/electron-builder.yml, 0.3.0: appId
|
||||
// io.github.fei2411.dsbot, productName DS Bot, DS Bot.app; DeepSeek
|
||||
// Bot, its name before) runs a DSH of its own on its data folder
|
||||
@@ -556,7 +568,8 @@ func storeAppVersion(packages []string, name, publisher string) string {
|
||||
// HasApp reports whether the agent's desktop app is installed here: its
|
||||
// bundle on macOS (AppVersion), its executable on Windows: under
|
||||
// %LOCALAPPDATA%\Programs, or in the folder its installer registered; on
|
||||
// Linux the folder its package installed (desktopApp.linux).
|
||||
// Linux the folder its package installed (desktopApp.linux), or one a
|
||||
// packager's install or an AppImage's desktop entry names (linuxApp).
|
||||
func (a *Agent) HasApp() bool {
|
||||
app, ok := desktopApps[a.ID]
|
||||
return ok && a.WSL == "" && slices.ContainsFunc(app.builds(), desktopApp.installed)
|
||||
@@ -564,7 +577,7 @@ func (a *Agent) HasApp() bool {
|
||||
|
||||
// installed reports whether app is installed on this machine (see HasApp).
|
||||
func (app desktopApp) installed() bool {
|
||||
if app.version() != "" || app.linuxDir() != "" {
|
||||
if app.version() != "" || app.linuxDir() != "" || app.onLinux.installed() {
|
||||
return true
|
||||
}
|
||||
if app.win == "" {
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
// linuxApp is how a desktop app whose vendor ships no Linux package is
|
||||
// found on Linux, where others package it (DeepSeek Harness Desktop:
|
||||
// the AUR, a .deb, an AppImage). It is installed when one of dirs, the
|
||||
// folders packagers install it to, holds exe and an Electron app's
|
||||
// resources/app.asar, or when a desktop entry in the XDG data folders'
|
||||
// applications/ is the app's (its Name is name and it handles links of
|
||||
// scheme, the app's own) and its program is there: what a package puts
|
||||
// in /usr/share/applications, and what AppImageLauncher, Gear Lever or
|
||||
// the user writes in ~/.local/share/applications for an AppImage
|
||||
// anywhere.
|
||||
type linuxApp struct {
|
||||
dirs []string
|
||||
exe string
|
||||
name string
|
||||
scheme string
|
||||
}
|
||||
|
||||
// linuxAppOS is the system linuxApp looks on; tests stand in Linux.
|
||||
var linuxAppOS = runtime.GOOS
|
||||
|
||||
// installed reports whether l is installed here (see linuxApp); false
|
||||
// for no linuxApp, and on macOS and Windows.
|
||||
func (l *linuxApp) installed() bool {
|
||||
if l == nil || linuxAppOS == "darwin" || linuxAppOS == "windows" {
|
||||
return false
|
||||
}
|
||||
// through proc.SystemDirs, so a test binary never reads the machine's
|
||||
for _, dir := range proc.SystemDirs(l.dirs...) {
|
||||
if isFile(filepath.Join(dir, l.exe)) && isFile(filepath.Join(dir, "resources", "app.asar")) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return slices.ContainsFunc(appEntryPrograms(l.name, l.scheme), programThere)
|
||||
}
|
||||
|
||||
// programThere reports whether a desktop entry's program is there: an
|
||||
// executable file at its path, or one on PATH by its name.
|
||||
func programThere(prog string) bool {
|
||||
if !filepath.IsAbs(prog) {
|
||||
_, err := proc.LookPath(prog)
|
||||
return err == nil
|
||||
}
|
||||
st, err := os.Stat(prog)
|
||||
return err == nil && !st.IsDir() && st.Mode()&0o111 != 0
|
||||
}
|
||||
|
||||
// appEntryDirs are the folders desktop entries are read from, the
|
||||
// user's first (xdgDataDirs' applications/). The system's go through
|
||||
// proc.SystemDirs: testenv sets the user's data folder to the test's own
|
||||
// but leaves $XDG_DATA_DIRS, which names the machine's.
|
||||
func appEntryDirs() []string {
|
||||
data := xdgDataDirs()
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
dirs := []string{filepath.Join(data[0], "applications")}
|
||||
for _, d := range proc.SystemDirs(data[1:]...) {
|
||||
dirs = append(dirs, filepath.Join(d, "applications"))
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
|
||||
// appEntryPrograms are the programs of the desktop entries named name
|
||||
// that handle scheme's links, as the Desktop Entry Specification finds
|
||||
// entries: the first folder with an entry of a file name has the one that
|
||||
// counts, and one that is Hidden hides it. Each folder is read again
|
||||
// when its time changed (an entry added, removed or renamed over), else
|
||||
// once a minute: this runs whenever dsh's row is read.
|
||||
func appEntryPrograms(name, scheme string) []string {
|
||||
var progs []string
|
||||
seen := map[string]bool{}
|
||||
for _, dir := range appEntryDirs() {
|
||||
for file, prog := range entriesIn(dir, name, scheme) {
|
||||
if seen[file] {
|
||||
continue
|
||||
}
|
||||
seen[file] = true
|
||||
if prog != "" {
|
||||
progs = append(progs, prog)
|
||||
}
|
||||
}
|
||||
}
|
||||
return progs
|
||||
}
|
||||
|
||||
// entryScan is what one applications/ folder held at its time, read at
|
||||
// read: each entry's file name, with the program of one that is the
|
||||
// app's ("" for another app's, or a hidden one).
|
||||
type entryScan struct {
|
||||
at, read time.Time
|
||||
entries map[string]string
|
||||
}
|
||||
|
||||
var entryScans = struct {
|
||||
sync.Mutex
|
||||
m map[string]entryScan
|
||||
}{m: map[string]entryScan{}}
|
||||
|
||||
// entriesIn is the desktop entries in dir (see entryScan); none when it
|
||||
// can't be read.
|
||||
func entriesIn(dir, name, scheme string) map[string]string {
|
||||
st, err := os.Stat(dir)
|
||||
if err != nil || !st.IsDir() {
|
||||
return nil
|
||||
}
|
||||
key := dir + "\x00" + name + "\x00" + scheme
|
||||
entryScans.Lock()
|
||||
scan, ok := entryScans.m[key]
|
||||
entryScans.Unlock()
|
||||
// an entry written over in place leaves the folder's time: read
|
||||
// again after a minute. A folder changed within a second of the read
|
||||
// is read again too: Linux stamps times by the kernel's tick, so a
|
||||
// change soon after the read can leave the time as it was.
|
||||
if ok && scan.at.Equal(st.ModTime()) && scan.read.Sub(scan.at) > time.Second && time.Since(scan.read) < time.Minute {
|
||||
return scan.entries
|
||||
}
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
entries := map[string]string{}
|
||||
for _, f := range files {
|
||||
if f.IsDir() || !strings.HasSuffix(f.Name(), ".desktop") {
|
||||
continue
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(dir, f.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
entries[f.Name()] = appEntryProgram(string(b), name, scheme)
|
||||
}
|
||||
entryScans.Lock()
|
||||
entryScans.m[key] = entryScan{at: st.ModTime(), read: time.Now(), entries: entries}
|
||||
entryScans.Unlock()
|
||||
return entries
|
||||
}
|
||||
|
||||
// appEntryProgram is the program a desktop entry runs when it is the
|
||||
// app's: its Name is name, it handles scheme's links and isn't Hidden;
|
||||
// "" otherwise. A program run through env (Exec=env VAR=x prog) is prog.
|
||||
func appEntryProgram(entry, name, scheme string) string {
|
||||
keys := map[string]string{}
|
||||
in := false
|
||||
for _, l := range strings.Split(entry, "\n") {
|
||||
l = strings.TrimSpace(l)
|
||||
if strings.HasPrefix(l, "[") {
|
||||
in = l == "[Desktop Entry]"
|
||||
continue
|
||||
}
|
||||
if k, v, ok := strings.Cut(l, "="); in && ok {
|
||||
if k = strings.TrimSpace(k); keys[k] == "" {
|
||||
keys[k] = strings.TrimSpace(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if keys["Name"] != name || keys["Hidden"] == "true" || keys["Type"] != "" && keys["Type"] != "Application" {
|
||||
return ""
|
||||
}
|
||||
if !slices.Contains(strings.Split(keys["MimeType"], ";"), "x-scheme-handler/"+scheme) {
|
||||
return ""
|
||||
}
|
||||
argv := desktopArgs(entry, "")
|
||||
if len(argv) > 0 && argv[0] == "env" {
|
||||
argv = argv[1:]
|
||||
for len(argv) > 0 && strings.Contains(argv[0], "=") {
|
||||
argv = argv[1:]
|
||||
}
|
||||
}
|
||||
if len(argv) == 0 {
|
||||
return ""
|
||||
}
|
||||
return argv[0]
|
||||
}
|
||||
@@ -141,7 +141,8 @@ func dshAt(at place) *Agent {
|
||||
// running or not: agent-default-model is read for new
|
||||
// ones only (#2359)
|
||||
notes = append(notes, noticeDsh1.String())
|
||||
} else if Running(`DeepSeek Harness\.app/`, `(^|/)dsh( |$)`) {
|
||||
} else if Running(`DeepSeek Harness\.app/`, `(^|/)dsh( |$)`, `(^|/)deepseek-harness( |$)`) {
|
||||
// deepseek-harness is the desktop app's executable on Linux
|
||||
notes = append(notes, noticeDsh2.String())
|
||||
}
|
||||
if dshSearchesHere(dir) && !gateway.CanSearch() {
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
// dshAURDesktopEntry is /usr/share/applications/deepseek-ai-dsh-desktop.desktop
|
||||
// as the AUR's deepseek-harness-desktop 0.2.2rc.1-1 PKGBUILD writes it.
|
||||
const dshAURDesktopEntry = `[Desktop Entry]
|
||||
Type=Application
|
||||
Name=DeepSeek Harness
|
||||
Comment=DeepSeek Harness desktop application
|
||||
Exec=deepseek-harness-desktop %U
|
||||
Icon=deepseek-harness
|
||||
Terminal=false
|
||||
StartupNotify=true
|
||||
StartupWMClass=deepseek-ai-dsh-desktop
|
||||
Categories=Development;
|
||||
Keywords=AI;agent;deepseek;harness;dsh;
|
||||
MimeType=x-scheme-handler/dsh;
|
||||
`
|
||||
|
||||
// dshAppImageEntry is the entry AppImageLauncher writes to
|
||||
// ~/.local/share/applications for an AppImage it integrates: the
|
||||
// AppImage's own (electron-builder's, with the app's protocol as its
|
||||
// MimeType), its Exec pointed at where the AppImage now is.
|
||||
const dshAppImageEntry = `[Desktop Entry]
|
||||
Name=DeepSeek Harness
|
||||
Exec="IMAGE" --no-sandbox %U
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Icon=appimagekit_0d1f-deepseek-harness
|
||||
StartupWMClass=DeepSeek Harness
|
||||
X-AppImage-Version=0.2.2-rc.1
|
||||
Comment=DeepSeek Harness
|
||||
MimeType=x-scheme-handler/dsh;
|
||||
Categories=Development;
|
||||
TryExec=IMAGE
|
||||
X-AppImage-Old-Icon=deepseek-harness
|
||||
X-AppImage-Identifier=0d1f
|
||||
`
|
||||
|
||||
// dshLinuxSandbox is a Linux machine with none of DeepSeek Harness's
|
||||
// installs, whatever runs the test: the system linuxApp looks on, the
|
||||
// one CLIMissing judges for, the user's data folder and the system's
|
||||
// (under the test's proc.SystemDirs), and a PATH with no dsh. It gives
|
||||
// the home.
|
||||
func dshLinuxSandbox(t *testing.T) string {
|
||||
t.Helper()
|
||||
judgeFor(t, "linux")
|
||||
wasOS, wasFolders, wasStore, wasReg := linuxAppOS, appFolders, windowsStorePackages, windowsRegisteredApp
|
||||
linuxAppOS = "linux"
|
||||
appFolders = func() []string { return nil }
|
||||
windowsStorePackages = func() []string { return nil }
|
||||
windowsRegisteredApp = func(string) (string, string) { return "", "" }
|
||||
t.Cleanup(func() {
|
||||
linuxAppOS, appFolders, windowsStorePackages, windowsRegisteredApp = wasOS, wasFolders, wasStore, wasReg
|
||||
})
|
||||
resetEntryScans := func() {
|
||||
entryScans.Lock()
|
||||
entryScans.m = map[string]entryScan{}
|
||||
entryScans.Unlock()
|
||||
}
|
||||
resetEntryScans()
|
||||
t.Cleanup(resetEntryScans)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("DSH_HOME", "")
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(home, ".local", "share"))
|
||||
t.Setenv("XDG_DATA_DIRS", "/usr/local/share:/usr/share")
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
for _, d := range proc.SystemDirs("/usr/lib/deepseek-harness-desktop", "/opt/DeepSeek Harness", "/usr/share/applications", "/usr/local/share/applications") {
|
||||
if _, err := os.Stat(d); err == nil {
|
||||
t.Fatalf("an empty sandbox has %s", d)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(d) })
|
||||
}
|
||||
return home
|
||||
}
|
||||
|
||||
// writeTestFile writes body to path, making its folder.
|
||||
func writeTestFile(t *testing.T, path, body string, mode os.FileMode) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(body), mode); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// xianhongtao on Discord (magpie 0.1.3232, Arch Linux): with DeepSeek
|
||||
// Harness Desktop from the AUR (deepseek-harness-desktop 0.2.2rc.1-1) and
|
||||
// no dsh CLI, magpie found ~/.dsh and said "DeepSeek Harness CLI not
|
||||
// found", and knew the app on macOS and Windows only. Its Linux installs
|
||||
// are found now: the AUR's folder, a .deb's under /opt, and any install
|
||||
// whose desktop entry is the app's, an AppImage's among them.
|
||||
func TestDshLinuxDesktopApp(t *testing.T) {
|
||||
home := dshLinuxSandbox(t)
|
||||
for _, p := range []string{"web", "desktop"} {
|
||||
writeTestFile(t, filepath.Join(home, ".dsh", "profiles", p, "cordis.patch.yml"), dshDesktopPatch, 0o644)
|
||||
}
|
||||
a := dsh(home)
|
||||
a.Bin = "magpie-test-gone-dsh"
|
||||
if a.HasApp() || !a.Detected() || !a.CLIMissing() {
|
||||
t.Fatalf("nothing installed: app %v, detected %v, CLI missing %v", a.HasApp(), a.Detected(), a.CLIMissing())
|
||||
}
|
||||
|
||||
// the AUR's build: /usr/lib/deepseek-harness-desktop, the reporter's
|
||||
aur := proc.SystemDirs("/usr/lib/deepseek-harness-desktop")[0]
|
||||
writeTestFile(t, filepath.Join(aur, "deepseek-harness"), "\x7fELF", 0o755)
|
||||
if a.HasApp() {
|
||||
t.Fatal("an executable with no Electron app beside it taken for the app")
|
||||
}
|
||||
writeTestFile(t, filepath.Join(aur, "resources", "app.asar"), "asar", 0o644)
|
||||
if !a.HasApp() || a.CLIMissing() {
|
||||
t.Fatalf("the AUR's app: app %v, CLI missing %v", a.HasApp(), a.CLIMissing())
|
||||
}
|
||||
// it isn't looked for on macOS or Windows
|
||||
linuxAppOS = "darwin"
|
||||
if a.HasApp() {
|
||||
t.Fatal("a Linux folder read on macOS")
|
||||
}
|
||||
linuxAppOS = "linux"
|
||||
os.RemoveAll(aur)
|
||||
|
||||
// a .deb's, in electron-builder's /opt/<productName>
|
||||
deb := proc.SystemDirs("/opt/DeepSeek Harness")[0]
|
||||
writeTestFile(t, filepath.Join(deb, "deepseek-harness"), "\x7fELF", 0o755)
|
||||
writeTestFile(t, filepath.Join(deb, "resources", "app.asar"), "asar", 0o644)
|
||||
if !a.HasApp() {
|
||||
t.Fatal("the .deb's app in /opt not found")
|
||||
}
|
||||
os.RemoveAll(deb)
|
||||
if a.HasApp() {
|
||||
t.Fatal("the app found with nothing installed")
|
||||
}
|
||||
|
||||
// dsh in a WSL distro is not this machine's app
|
||||
if (&Agent{ID: "dsh@wsl:Ubuntu", WSL: "Ubuntu", Bin: "dsh"}).HasApp() {
|
||||
t.Fatal("WSL twin")
|
||||
}
|
||||
}
|
||||
|
||||
// An install magpie knows no folder of is found by its desktop entry: the
|
||||
// AUR's in /usr/share/applications (its program a script on PATH), an
|
||||
// AppImage's in ~/.local/share/applications (its program the AppImage,
|
||||
// anywhere). Only the app's entry counts: named DeepSeek Harness and
|
||||
// handling dsh:// links, its program there, not hidden by the user's own.
|
||||
func TestDshLinuxDesktopEntry(t *testing.T) {
|
||||
home := dshLinuxSandbox(t)
|
||||
a := &Agent{ID: "dsh", Bin: "dsh"}
|
||||
sys := filepath.Join(proc.SystemDirs("/usr/share")[0], "applications")
|
||||
user := filepath.Join(home, ".local", "share", "applications")
|
||||
|
||||
// the AUR's entry, whose program is /usr/bin/deepseek-harness-desktop
|
||||
writeTestFile(t, filepath.Join(sys, "deepseek-ai-dsh-desktop.desktop"), dshAURDesktopEntry, 0o644)
|
||||
if a.HasApp() {
|
||||
t.Fatal("an entry whose program isn't on PATH")
|
||||
}
|
||||
bin := t.TempDir()
|
||||
writeTestFile(t, filepath.Join(bin, "deepseek-harness-desktop"), "#!/bin/sh\nexec /usr/lib/deepseek-harness-desktop/deepseek-harness \"$@\"\n", 0o755)
|
||||
t.Setenv("PATH", bin)
|
||||
if !a.HasApp() {
|
||||
t.Fatal("the AUR's entry, its program on PATH, not found")
|
||||
}
|
||||
// the user's own copy of it, hidden, hides it (the menu editors'
|
||||
// way to take an app out of the menu)
|
||||
writeTestFile(t, filepath.Join(user, "deepseek-ai-dsh-desktop.desktop"), dshAURDesktopEntry+"Hidden=true\n", 0o644)
|
||||
if a.HasApp() {
|
||||
t.Fatal("an entry the user hid still counts")
|
||||
}
|
||||
os.RemoveAll(user)
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
|
||||
// another app's entries: the same name with no dsh:// links, dsh://
|
||||
// under another name, the scheme only in another group
|
||||
for i, other := range []string{
|
||||
strings.Replace(dshAURDesktopEntry, "MimeType=x-scheme-handler/dsh;\n", "", 1),
|
||||
strings.Replace(dshAURDesktopEntry, "Name=DeepSeek Harness\n", "Name=DeepSeek Harness EAC\n", 1),
|
||||
strings.Replace(dshAURDesktopEntry, "MimeType=x-scheme-handler/dsh;\n", "[Desktop Action new]\nMimeType=x-scheme-handler/dsh;\n", 1),
|
||||
} {
|
||||
os.Remove(filepath.Join(sys, "deepseek-ai-dsh-desktop.desktop"))
|
||||
name := filepath.Join(sys, fmt.Sprintf("other-%d.desktop", i))
|
||||
writeTestFile(t, name, other, 0o644)
|
||||
t.Setenv("PATH", bin)
|
||||
if a.HasApp() {
|
||||
t.Fatalf("another app's entry taken for DeepSeek Harness's:\n%s", other)
|
||||
}
|
||||
os.Remove(name)
|
||||
}
|
||||
os.RemoveAll(sys)
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
|
||||
// an AppImage that AppImageLauncher integrated, in ~/Applications
|
||||
image := filepath.Join(home, "Applications", "deepseek-harness-0.2.2-rc.1-linux-x86_64_0d1f.AppImage")
|
||||
entry := filepath.Join(user, "appimagekit_0d1f-DeepSeek_Harness.desktop")
|
||||
writeTestFile(t, entry, strings.ReplaceAll(dshAppImageEntry, "IMAGE", image), 0o644)
|
||||
if a.HasApp() {
|
||||
t.Fatal("an entry whose AppImage isn't there")
|
||||
}
|
||||
writeTestFile(t, image, "\x7fELF", 0o755)
|
||||
if !a.HasApp() {
|
||||
t.Fatal("the AppImage's entry not found")
|
||||
}
|
||||
// the AppImage deleted, its entry left
|
||||
os.Remove(image)
|
||||
if a.HasApp() {
|
||||
t.Fatal("an AppImage deleted since still counts")
|
||||
}
|
||||
}
|
||||
|
||||
// With the app on Linux and no profile yet, magpie wires the app's
|
||||
// profile, profiles/desktop, as on macOS and Windows: the web profile is a
|
||||
// dsh CLI's, which this machine doesn't have.
|
||||
func TestDshLinuxDesktopAppProfile(t *testing.T) {
|
||||
home := dshLinuxSandbox(t)
|
||||
dir := filepath.Join(home, ".dsh")
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aur := proc.SystemDirs("/usr/lib/deepseek-harness-desktop")[0]
|
||||
writeTestFile(t, filepath.Join(aur, "deepseek-harness"), "\x7fELF", 0o755)
|
||||
writeTestFile(t, filepath.Join(aur, "resources", "app.asar"), "asar", 0o644)
|
||||
if got := dsh(home).Path; got != dshDesktopFile(dir) {
|
||||
t.Fatalf("the profile magpie wires = %s, want the desktop app's %s", got, dshDesktopFile(dir))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user