Skip to content

v1.82.0 ·

Running discovery again erased what we wrote

Running aidlc discover a second time damaged a knowledge graph people had already written up. It seeds the graph through the same path as aidlc knowledge import, and on a project with hand-written entries a re-run did three kinds of harm.

It overwrote. The merge keeps the incoming description whenever it is non-empty, so "Module at packages/cli/src/core/ (has index)" replaced a hand-written paragraph.

It duplicated. Discovery builds module ids from the folder path, and the writer matches by id only. A module written up as menu-module got a second entity, module-rasensio-aidlc-menu, with the same name.

It made noise. Every merge bumped lastVerified and added metadata: {}, and every relationship was rewritten, or written a second time as a new record file when the edge lived in the legacy relationships.yaml. An unchanged repo still produced a diff of about 100 files.

What changed

Discovery now replaces a description only when it is empty or still one of the short placeholders discovery wrote itself. It never changes an entry's name, source, author, confidence or tags. When it finds a module already written up under a different id, it adds its facts to that entry. When two entries could be the one it found, it writes nothing for that module and prints a warning naming both. Nothing whose facts did not change is rewritten, so running it twice on an unchanged project leaves an empty diff.

On this repository the first run after the fix added only the ten modules with no entry yet and modified no existing file. Before it, the same run replaced a seven-line description, created 14 duplicate modules and touched about 100 files.

Why this way

The simplest fix was to make every merge keep the old description, and it was wrong. The same merge serves a person adding a fact by hand, and when they write a new description they mean to replace the old one. So aidlc knowledge add and aidlc knowledge import keep their behaviour, and discovery got its own way in.

A placeholder is recognized by its shape, not by who wrote the entry. An entry discovery created and a person later rewrote still says discovery created it.

For duplicates, a folder is matched to an existing entry by the same name or the same source path, and nothing looser. One match, discovery writes into it. Two, it writes nothing and says which two, because quietly attaching facts to the wrong module is worse than leaving one visible gap. On this project that left one folder unmatched and one near-duplicate added under a name nobody had used. Both show in the output instead of hiding in the diff.

What it does not fix

It is a patch with one visible change. The summary line now reads N entities added, M updated, K unchanged where it said M merged, and discovery warnings go to stderr. Two ambiguous modules still need a person to decide.