Commit Graph
8 Commits
Author SHA1 Message Date
yetone 4ef718651f library: InUse answers while a sync holds the library's lock
#2774: the macOS window stayed white at start. The window waits on
boot.js before it paints, and boot.js asks library.InUse through the
built-in plugins. InUse took the library's mu, which a sync holds for
its whole run: 13-16s on the reporter's Mac, with many agents and
skills. InUse only reads library.json, and save replaces that file whole
(edit.WriteAtomic), so InUse now reads it without mu. A read beside a
sync sees the file from before or after one of the sync's writes, never
half of one. A file that can't be read is still an error, never 0.

TestInUseAnswersWhileASyncHoldsTheLock holds mu and expects InUse to
return 3 within 5s. It also expects a half-written file to be an error.
With the lock put back by hand, it goes red:
  --- FAIL: TestInUseAnswersWhileASyncHoldsTheLock (14.32s)
      inuse_unlocked_test.go:36: InUse waited on the sync's lock

The sandbox cold start measured for this work has a short library sync,
so boot.js came at about the same time before and after (4527ms against
4822ms after listen at ~4s). The reporter's 13-16s sync wasn't
reproduced here.

What was run (worktree at 9fd80b212 plus this change and the commits
before it):
  gofmt -l internal/: nothing
  go vet ./internal/library: exit 0
  GOOS=linux go vet -tags nogui ./...: exit 0
  GOOS=windows go vet -tags nogui ./...: exit 0
  go test -timeout 45m -count=1 ./internal/library: ok 1220.249s
2026-10-20 20:23:56 +08:00
yetone 5ca897690f library: an instructions set linked to the file an agent reads is read without magpie's part, so it isn't written into itself until gigabytes (#2349, eachann1024)
instructions.md linked to ~/.claude/CLAUDE.md (or both linked to one
dotfile) made the set's text the whole file, magpie's part included.
wanted() read it as is, syncInstructions wrote it into that same file's
part, and split() only knows the first begin/end pair, so the part never
matched and each sync nested the whole file in it again: the file doubled
at every sync. linkable() refuses an agent's own file for a set kept in
the user's file, but the default set's instructions.md being a link went
around it.

- setText reads a set's text with every magpie part taken out; used where
  the set's text is read (wanted, the page, ImportInstructions, carry,
  setup snapshot/compare).
- own() takes out every part, and the end lines a part nested in itself
  leaves behind, so a file already grown comes back to the user's text.
- An agent whose instructions file is, links followed (realBelow), the
  file the set on is kept in gets no part; one written before is taken
  out, the file kept aside first. ImportInstructions refuses that agent.
- docs/subsystems/library.md: Instructions row.

Run (worktree on origin/main 03eb0633a, go1.26, sandbox HOME via the
package's sandbox()):
- go test -p 1 -tags nogui ./internal/library -count=1: ok (114s)
- gofmt -l internal/library: clean
- GOOS=windows and GOOS=linux go vet -tags nogui ./internal/library: clean
Broken by hand: with instructions.go, carry.go and setup.go put back to
origin/main, TestInstructionsSetLinkedToAgentsFile fails: CLAUDE.md
holds nested magpie parts after three syncs, codex gets them, the page's
shared text has them, and a 4-deep grown file stays grown.
Not run: the real app with a linked instructions.md; Windows (symlink
creation skips the test there without the privilege).

Full suite: SUITE_LINE
2026-10-15 23:08:01 +08:00
yetone 692a779d3d library: an instruction set can be kept in a file of your own, such as ~/.agents/AGENTS.md (新v学员 on Discord)
新v学员 keeps one user-level ~/.agents/AGENTS.md by hand and wants every
agent to follow it. Only Factory Droid, omp and Cline CLI read that file
natively; Codex, Claude Code, Gemini, OpenCode, Pi, Amp and the rest
don't. Rather than teach magpie a new agent target, a set of shared
instructions can now be kept in that file instead of a copy in the
library, and the library writes it into every agent that is on, as it
does any set.

What changed:
- InstrSet.File: a set kept in a file of the user's own. Its text is
  read from that file, Save writes to it (kept aside in the backups
  first, written atomically, never removed: emptied, it stays empty),
  and Remove lets go of the set without touching the file.
- The file is refused when it is relative, a folder, an agent's own
  instructions or override file (magpie writes into those), a file
  holding magpie's marked block, inside the library, or another set's.
  A file not there yet is made on the first save.
- The GUI checks the active linked file every 30s (KeepLinked) and
  writes a change made in an editor into the agents.
- Carried by davsync or a backup, a linked set goes as its text; where
  the file is stays this computer's. Put back, the set keeps its file
  and the file gets the carried text, never emptied for a text not
  carried. A profile restored with no text doesn't empty it either.
- GUI: New set has "Keep in a file…" (filled with ~/.agents/AGENTS.md);
  a linked set is tagged "Your file", says where it is kept, and warns
  when Droid or omp is on, as they read ~/.agents/AGENTS.md themselves
  and would get it twice. Strings in zh, zh-TW, ja and de.

Run:
- gofmt -l; go vet for darwin, linux/amd64 -tags nogui and
  windows/amd64 on ./internal/library ./internal/gui.
- go test ./internal/library ./internal/gui -count=1: ok.
- New TestLinkedSet, TestLinkRefused, TestLinkedSetCarried. Each was
  broken by hand and went red: putText writing a linked file like a
  library one, Collect not stripping File, Put not restoring it,
  SyncLinked not syncing, linkable not checking agents' own files.
- library-linked-set.test.cjs in chromium and webkit, at 1100 and 420,
  in en, zh, zh-TW, ja, de: 22 pass; red with the file left out of
  create. library-instr-sets and i18n-keys still pass.

Not done or tried:
- No CLI to link a set (`magpie library instructions set <file>` still
  copies once), and the headless `magpie serve` doesn't watch the file:
  after an edit there, `magpie library sync` writes it out.
- Not tried with real Droid or omp reading the same file.
2026-10-13 17:28:26 +08:00
yetone 3ccbe6bc15 plugins: a runtime for built-in plugins, and Plugins › Built-in to switch them (P0)
Lxxyx on X (https://x.com/Lxxyx_/status/2109506752656150974): magpie has
too much in it. This is P0 of making magpie's parts plugins, as DeepSeek
Harness does: a runtime, plugins.yml, and the first five built-in plugins
the user can switch off.

- internal/pluginrt: a registry (Register from init), a manifest (API
  caret range, Requires/Provides, Essential, InUse, Apply, Parts,
  Defaults) and Reconcile: the plugins no longer wanted, with whatever
  needs a service they provided, are disposed newest first; the wanted
  ones are applied once their services are there. A plugin that fails or
  panics is failed and the rest run. TestPluginsImportOnlyCore keeps the
  boundary: nothing outside plugins/ imports one, none imports another.
- plugins.yml (appdir.Config()): default → preset (essentials | all) →
  the user's rows → in use. A new install is written Essentials, a magpie
  that ran here before (settings.RanBefore) All, so existing users keep
  everything. Writes are locked, whole and keep a .bak; a file that
  doesn't parse is an error, never empty, and is never written over.
- plugins/groups, library, otel, sessions, warmups. In P0 a plugin off
  is the window's alone: its page, sections and rows (data-feature) leave
  the window; the gateway, TUI and CLI serve the same, nothing is
  deleted. One in use stays on.
- The window: Plugins › Built-in, the first tab, a switch per plugin;
  GET/POST /api/plugins/builtin; boot.js says which are off before the
  first paint. CLI: magpie plugin builtin [on|off <id>], plugin preset,
  plugin dump [--json].
- docs/subsystems/plugin-runtime.md, gui-shell.md.

Run: go test ./internal/pluginrt/ ./internal/settings/ ./internal/gui/;
gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows
go vet ./.... GUI: builtins.test.cjs in Chromium and WebKit, 5 languages,
1100/800/420; list-sort, mobile-web, routing-keys-fold, routing-sessions
pass. By hand under a sandbox HOME: a new install gets essentials, an
existing one all, a broken plugins.yml is refused and kept, dump works.
Full suite results after the rebase are in the push notes.
2026-10-13 16:19:13 +08:00
yetone bfaedf1830 gui, profile: the profile in use is ticked and named on the panel's Profiles button, not a count read as its name (superhtoooth on X)
superhtoooth (macOS): 保存方案设置了方案名字,但是应用方案没有用这个名字。
menu 里面变成了方案 1,方案 2。而且在应用里面没有显示当前使用的方案.

The bug: the tray panel's Profiles button showed the number of saved
profiles next to its label ("方案" + "2"), which reads as a profile
named 方案 2. Profiles were saved and applied under the typed name all
along; nothing anywhere said which profile was in use.

What changed:
- profile.InUse: a profile is in use while applying it would change
  nothing on this computer - every detected agent's saved field is as
  the profile has it (compared with the same renamed-ref spelling Apply
  writes), its model lists are held (provider.ModelListsHeld, a dry run
  of SetModelLists via the extracted putModelLists) and its library
  setup is as saved (library.Holds, the mirror of Restore). A profile
  that touches no agent here is not in use.
- Why not "last applied": that would stay ticked after the user changes
  a model by hand, a tick that lies. With this definition a profile
  saved from the current setup is in use at once, a hand change clears
  the tick, and applying puts it back. Two identical profiles are both
  ticked; the button names the first.
- GUI: /api/state carries inUse. The panel's button names the profile
  in use (a pop-up button showing what is picked), else counts them as
  before; its chip gets a check mark and aria-current, in panel and
  window; the chip's tooltip and its details say "In use" (string
  already in every language). CLI `magpie profiles` marks it, the TUI
  notes "in use". Docs (reference, start en/zh/ja) say so.

What was run:
- go test ./internal/profile (new TestProfileInUse: save, hand change,
  apply, hidden model list, library instructions, absent agents) and
  ./internal/gui (new TestStateProfileInUse through the HTTP handler),
  scratch HOME. Broken by hand: field compare, ModelListsHeld,
  library.Holds and state's InUse each turned a test red.
- go test -tags nogui ./... in a scratch HOME (the four slow packages
  rerun with -timeout 40m under load ~45).
- GUI: new profile-in-use.test.cjs (reporter's steps in the panel at
  360px, every language, plus the window) and panel-profiles,
  profile-confirm, profile-details, old-webkit, i18n-keys, gui-zh-tw,
  gui-ja, gui-de in chromium and webkit: all pass. Old app.js fails the
  new test.
- Real CLI in a sandbox HOME with a codex config: save/use/profiles
  show the mark, and it goes after a hand edit.
- gofmt; go vet darwin, linux (nogui), windows.
Not tried: the real tray app with real agents, and Windows/Linux at
runtime.
2026-10-12 19:14:54 +08:00
yetone b03967bb79 library: agents in a running WSL distro take skills, MCP servers and instructions (#331) — the Library knew only this machine's agent ids, so codex@wsl:Ubuntu and the like were never offered, and the id's colon was refused as an agent's name and can't be in a Windows file name. Claude Code, Codex, Pi and OmO in a distro now get them at their default places under the distro's $HOME through \\wsl.localhost, only while it runs (opening a stopped one's files starts it; its state is kept and asking for it says to start it). Skills go in as copies, made beside and renamed into place and made again when the library's changes, since a Linux agent can't follow a link to a Windows folder (project skills share the same copy code); an MCP server that runs a Windows program (C:\…, *.exe/.cmd/.bat/.ps1) is refused for them with a message; Pi there gets no MCP servers, where its version decides the file. The id's colon is a dot in file and folder names, and setup export/import turns it back. TestWSLTargets, TestWSLSkillsCopied, TestWSLServers and TestWSLInstructions (a fake distro) fail without the change. go vet (and GOOS=windows for agent, library), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. Not run against a real distro. 2026-09-30 22:17:23 +08:00
yetone 3597cbbcc3 library: instructions come in sets — Default and any others named, each its own text, one of them the one the agents read; a set is added, renamed, switched to and removed (after a confirm, never the one in use or Default) in Library → Instructions, and a setup snapshot keeps which was in use. Providers: each protocol keeps its own URL, so a saved chat URL no longer shows as the Anthropic one; a URL typed and not saved yet moves to the protocol picked after it, spelled as that one wants it (/v1 dropped for Anthropic, added for OpenAI). Settings: an open WebDAV, export or import form is no longer emptied when the window regains focus. Tested in the browser from a sandbox. Issues #104 #105 #106 2026-09-27 17:05:59 +08:00
yetone dd7d4875d7 profiles: a saved profile keeps the Library's setup too, and switching to it switches that as well (#29) — which agents get each MCP server and skill, and the instructions (the shared text, the agents it is written to, what each gets besides), so moving from one profile to another left the tools and the instructions as they were and only the models followed. A profile keeps them under "library" beside its agent.field keys; the servers and skills themselves stay in the library, a profile only names them. Applying one sets the models as before, then gives each server and skill to the agents it names and puts the instructions back, written into the agents as any Library change is, their files and the library's own instructions kept aside first; one removed from the library since is skipped and said so, one added since keeps its agents (the profile knows nothing of it, and switching it off would lose it for good). A profile saved before, or while the library was empty, carries none and leaves the library as it is. magpie profiles, the TUI and the panel's chips say what a profile gives out (+ library: 2 servers, 1 skill, instructions) 2026-09-25 14:23:56 +08:00