Commit Graph
2 Commits
Author SHA1 Message Date
yetone d6284bf8a0 library: a skill's installed dependencies are no change of the user's
ggbr on Discord (#help): easyeda/easyeda-api-skill says to run
`npm install` in its own folder. Once that ran, the Library tagged the
skill Changed here (本地已改动). The check for updates still ran on it
(it compares commits, not the folder), but Update all left it out as
changed, and its own Update asked to replace "your changes" and threw
node_modules away with the old version, so the user had to install again.

Cause: editState compared the hash of the whole library folder (only
.DS_Store left out) with Hash, the hash of the files as fetched. The
install's node_modules and its rewrite of package-lock.json made them
differ.

Now what installing dependencies or running the skill writes is not a
change (fromInstall): node_modules, .venv, venv, __pycache__,
.pytest_cache, .mypy_cache, .ruff_cache, *.pyc/*.pyo, and the lock files
package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock(b), uv.lock.
- New Skill.Own: the hash of the files as fetched without those, set on
  install, update and when skill_from binds a skill to its repo.
  onlyInstalled compares the folder with it first.
- An agent's copy (copy mode) counts as edited only when its ownHash
  differs from the library's.
- An update carries those entries from the version replaced into the new
  one wherever the new one has no entry of its own (carryInstalled). The
  new version's own lock file wins.
A file the user really edited (run.py, SKILL.md, package.json, ...) still
marks the skill changed and is never overwritten without asking. An edit
to a lock file alone is no longer protected; an update takes upstream's.

Skills already marked changed: they clear on their own on the next page
read when only installed folders and bytecode differ, or the lock file the
skill came with was left byte-for-byte (compared with Hash, leaving
installed folders aside). A skill fetched before this commit whose lock
file the install did rewrite has no Own, so it stays marked until its
next update (Update on its row asks once, keeps the old folder in the
backups, carries node_modules over and records Own). From then on, a
rewritten lock file isn't counted.

Run (mote, worktree at e863f520c plus this change):
- go test -timeout 45m -count=1 ./internal/library: ok (107s)
- go vet ./internal/library, GOOS=windows and GOOS=linux go vet: clean
- gofmt -l internal/library: clean
- Windows box (win-run): TestInstalledDependencies* and TestUpdateKeeps*
  pass (the first run found the test comparing a link target with "/";
  it now uses filepath.ToSlash)

Broken by hand, each red on mote:
- editState without onlyInstalled: TestInstalledDependenciesAreNoChange
  and TestInstalledDependenciesBeforeOwnWasKept red ("installing eda's
  dependencies made it changed here")
- apply without carryInstalled: node_modules, .venv, __pycache__ and the
  .bin link didn't go on with the update
- copy branch on sameTree alone: TestInstalledDependenciesInACopy red
- onlyInstalled ignoring Own: the lock-file rewrite after an update reads
  as changed

Not tried: a real `npm install` of easyeda-api-skill in the GUI. No GUI
assets changed. Not changed: takeEdits still takes node_modules
installed in an agent's copy into the library (as before), and folders
like build/ or dist/ still count, since a skill can ship them.
2026-10-30 10:29:59 +08:00
yetone 3a80ce7fa0 library: reading the Library page no longer reads every byte of the agents' skills each time; a folder unchanged since the last read isn't opened again (#541)
0day404 (#541, Windows): the Library page spins for minutes each time it
is opened. The page waits on GET /api/library, and library.Read, under
the library lock, compared every skill an agent has of its own with the
same name in each other agent byte by byte (foundSkills -> sameTree ->
sameFile) and hashed every library skill given as a copy (behind ->
libHash -> hashDir). Skills with node_modules or templates, given to
several agents, are hundreds of MB per read; on Windows each file opened
is scanned.

What sameTree and hashFiles found is now kept against a stamp of the
folders: each file's and link's path, type, size and mtime (stamper in
treememo.go). The walk that compares or hashes a folder stamps it as it
goes, before opening a file, so a folder seen for the first time is
walked once, as before; a later read walks it without opening a file, and
while the stamps match, the answer is reused. In foundSkills a skill held
by several agents is walked once per read, not once per pair.

What is never taken as unchanged:
- a folder that can't be walked, or a file in it that can't be read
  (compareTrees and sameFile now say whether they read everything): it is
  unknown, not the same, and compared again next time;
- a folder with a file written in the last 3s (a rewrite within a file
  system's time granularity can keep size and mtime);
- any change of a file's size or mtime, or a file added or removed.
A rewrite that keeps both size and mtime (cp -p of a same-size file) is
not seen, as with rsync's quick check. .git, .DS_Store and magpie's mark
aren't part of a stamp, as they aren't part of the compare. hashFiles'
hashes are byte-for-byte what they were (they are kept in library.json
and each copy's mark).

Measured on the Windows box (Windows 11 x64, test binary, 20 library
skills given as copies to 4 agents and 40 own skills in 3 agents, each
300 files of 8KB under node_modules), library.Read:
  before:  5.5-6.3s every read
  after:   5.0s the first read after start, then 2.0s
(Glance, the next commit, is 80ms.) The Mac was under load average ~118
from other work, so its timings weren't comparable.

Tests:
- TestPageReadDoesntReadUnchangedSkillsAgain: aged folders, the second
  read finds codex's copy the same with its files made unreadable; an
  edit afterwards is read again and found to differ.
- TestJustWrittenSkillIsReadAgain: a folder written a moment ago isn't
  taken from the memo.
- TestUnreadableSkillIsntRememberedAsDifferent (scripts/run.sh made
  unreadable; SKILL.md unreadable leaves the skill unlisted).
- TestEditedLibrarySkillIsHashedAgain: a library skill edited to the same
  size and aged an hour after a read: its copies are behind.
- TestHashUnchangedByTheMemo: hashFiles' value for files, a link,
  .DS_Store and .git; passes on the old code too.
Broken by hand, each goes red: stamp without mtime (PageRead,
EditedLibrarySkill), memo never hit (PageRead), unsure compares kept
(Unreadable), unsettled folders kept (JustWritten).

Run: go test -tags nogui ./internal/library ./internal/gui (macOS); the
library package's tests on the Windows box; gofmt; vet on darwin, linux
and windows.
2026-10-10 19:53:02 +08:00