-
Notifications
You must be signed in to change notification settings - Fork 125
Refactor/code wiki kb #2328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kissghosts
wants to merge
11
commits into
wecode-ai:main
Choose a base branch
from
kissghosts:refactor/code-wiki-kb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor/code wiki kb #2328
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
093f1b7
fix: read the git token everywhere it is consumed
kissghosts 30d51a9
fix(executor-manager): make local startup work on macOS
kissghosts 4ff5abc
feat(knowledge): a code wiki is a knowledge base written by an agent
kissghosts 3ee1305
feat(knowledge): make a run's outcome visible, and gate creation for …
kissghosts 32c59e8
fix(knowledge): make publishing honest about what it did, and advisory
kissghosts abe334c
refactor: retire the legacy wiki reader (PR5b)
kissghosts 0876380
fix(knowledge): finish the reader -- narrow screens, rollback, diagrams
kissghosts 4ec3ba6
refactor(knowledge): split the code wiki endpoints and repository acc…
kissghosts 0b9c2f2
refactor(knowledge): retire the legacy wiki, leaving one set of run c…
kissghosts 2c60297
refactor(knowledge): close the boundaries the round-two review found
kissghosts cb69daa
fix(db): chain the code wiki migrations onto the rebased head
kissghosts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
backend/alembic/versions/20260731_bd9c871a93d2_add_knowledge_content_origin_and_wiki_.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """add knowledge content origin and wiki generation kb link | ||
|
|
||
| Revision ID: bd9c871a93d2 | ||
| Revises: e5f6a7b8c9d0 | ||
|
|
||
| Adds the two things a code wiki needs to coexist with ordinary knowledge content: | ||
|
|
||
| - ``origin`` on documents and folders, marking whether a row is agent-generated or | ||
| user-owned. It defaults to ``user`` so that every existing row, and every row this | ||
| service does not create itself, is excluded from the generated-content projection. | ||
| Getting this backwards would let a regeneration delete content nobody can restore. | ||
| - ``kind_id`` on wiki generations, binding a version line to a knowledge base. The | ||
| versions previously hung off ``wiki_projects``, whose ``source_url`` is globally | ||
| unique; leaving them there would share one version line between knowledge bases | ||
| tracking the same repository. ``0`` marks rows that predate code wikis. | ||
|
|
||
| All three columns are NOT NULL with a server default, as required for existing rows to | ||
| backfill without a nullable intermediate state. | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
| from typing import Union | ||
|
|
||
| import sqlalchemy as sa | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "bd9c871a93d2" | ||
| down_revision: Union[str, Sequence[str], None] = "e5f6a7b8c9d0" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| op.add_column( | ||
| "knowledge_documents", | ||
| sa.Column( | ||
| "origin", | ||
| sa.String(length=20), | ||
| nullable=False, | ||
| server_default="user", | ||
| comment="Content ownership: 'generated' (agent-owned) or 'user'", | ||
| ), | ||
| ) | ||
| op.add_column( | ||
| "knowledge_folders", | ||
| sa.Column( | ||
| "origin", | ||
| sa.String(length=20), | ||
| nullable=False, | ||
| server_default="user", | ||
| comment="Content ownership: 'generated' (agent-owned) or 'user'", | ||
| ), | ||
| ) | ||
| op.add_column( | ||
| "wiki_generations", | ||
| sa.Column( | ||
| "kind_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| server_default="0", | ||
| comment="Knowledge base this version line belongs to; 0 = legacy row", | ||
| ), | ||
| ) | ||
| op.create_index( | ||
| "ix_wiki_generations_kind_id", "wiki_generations", ["kind_id"], unique=False | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| op.drop_index("ix_wiki_generations_kind_id", table_name="wiki_generations") | ||
| op.drop_column("wiki_generations", "kind_id") | ||
| op.drop_column("knowledge_folders", "origin") | ||
| op.drop_column("knowledge_documents", "origin") | ||
48 changes: 48 additions & 0 deletions
48
backend/alembic/versions/20260804_2b5791acc5fa_link_wiki_projects_to_their_code_wiki.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """link wiki projects to their code wiki | ||
|
|
||
| Revision ID: 2b5791acc5fa | ||
| Revises: bd9c871a93d2 | ||
|
|
||
| ``wiki_projects.source_url`` is already UNIQUE, which makes this table the only place | ||
| that can enforce "one repository, one code wiki" against two people creating at the | ||
| same moment. Recording the knowledge base here, rather than checking a JSON field on | ||
| the knowledge base itself, turns a check-then-insert into a database constraint. | ||
|
|
||
| ``0`` marks a project row with no code wiki, which is every row that exists today. | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
| from typing import Union | ||
|
|
||
| import sqlalchemy as sa | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "2b5791acc5fa" | ||
| down_revision: Union[str, Sequence[str], None] = "bd9c871a93d2" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| op.add_column( | ||
| "wiki_projects", | ||
| sa.Column( | ||
| "kind_id", | ||
| sa.Integer(), | ||
| nullable=False, | ||
| server_default="0", | ||
| comment="Code wiki knowledge base built from this repository; 0 = none", | ||
| ), | ||
| ) | ||
| op.create_index( | ||
| "ix_wiki_projects_kind_id", "wiki_projects", ["kind_id"], unique=False | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| op.drop_index("ix_wiki_projects_kind_id", table_name="wiki_projects") | ||
| op.drop_column("wiki_projects", "kind_id") |
54 changes: 54 additions & 0 deletions
54
backend/alembic/versions/20260804_c3d4e5f6a7b8_allow_several_wikis_per_repository.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """allow several wikis per repository | ||
|
|
||
| Revision ID: c3d4e5f6a7b8 | ||
| Revises: 2b5791acc5fa | ||
|
|
||
| A code wiki belongs to whoever created it, so a wiki built by one person is invisible | ||
| to everyone else under the ordinary knowledge-base ACL. "One repository, one wiki" | ||
| therefore stopped being a saving and became a way to take a wiki away from the second | ||
| person to ask for one. | ||
|
|
||
| ``wiki_projects`` accordingly holds one row per ``(repository, wiki)`` rather than one | ||
| per repository. The UNIQUE moves from ``source_url`` alone to the pair, which is still | ||
| a database constraint rather than a check-then-insert: it settles two requests racing | ||
| for the same pair, and it lets ``COUNT(*) WHERE source_url = ?`` answer "how many | ||
| wikis already exist for this repository" without reading a JSON field. | ||
|
|
||
| Legacy wiki rows carry ``kind_id = 0`` and stay at most one per repository, which the | ||
| same constraint gives for free. | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
| from typing import Union | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "c3d4e5f6a7b8" | ||
| down_revision: Union[str, Sequence[str], None] = "2b5791acc5fa" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
| # MySQL names the constraint after the column it was declared on. | ||
| OLD_UNIQUE = "source_url" | ||
| NEW_UNIQUE = "uq_wiki_projects_source_url_kind_id" | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| # Created before the old one is dropped: between the two statements the table is | ||
| # covered by both rather than by neither, so a concurrent insert cannot slip a | ||
| # duplicate pair in through the gap. | ||
| op.create_unique_constraint(NEW_UNIQUE, "wiki_projects", ["source_url", "kind_id"]) | ||
| op.drop_constraint(OLD_UNIQUE, "wiki_projects", type_="unique") | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema. | ||
|
|
||
| Fails if any repository has more than one wiki, which is correct: silently | ||
| discarding one of them would destroy a generated knowledge base. Delete the | ||
| surplus wikis first if this has to be reversed. | ||
| """ | ||
| op.create_unique_constraint(OLD_UNIQUE, "wiki_projects", ["source_url"]) | ||
| op.drop_constraint(NEW_UNIQUE, "wiki_projects", type_="unique") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: wecode-ai/Wegent
Length of output: 2396
🏁 Script executed:
Repository: wecode-ai/Wegent
Length of output: 5842
Resolve the Alembic graph before applying this migration.
bd9c871a93d2correctly points tob9c0d1e2f3a4, but the migration tree still has multiple heads (bd9c871a93d2,c8d2e3f4a5b6,e6f7a8b9c012,e6f7a8b9c013, anda2b3c4d5e6f7). Merge or relink the branches soupgrade headapplies one linear sequence and the schema is not split across heads.🤖 Prompt for AI Agents
Source: Coding guidelines