-
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
14
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 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1c5d371
feat(knowledge): a code wiki is a knowledge base written by an agent
kissghosts 51fbe67
refactor(knowledge): act on review of the code wiki internals
kissghosts 7931f70
refactor(knowledge): collect the code wiki into a package
kissghosts 783c460
feat(knowledge): give a code wiki page a name, a place and an order
kissghosts edf8b67
feat(knowledge): a code wiki belongs to its repository, not to whoeve…
kissghosts 8c5b046
fix(knowledge): work through the review rounds, including one I had s…
kissghosts 9367b99
feat(knowledge): a reader for code wikis, and a list that is one request
kissghosts cbba7dc
docs(knowledge): document the code wiki fields on a knowledge base
kissghosts 651b108
fix(backend): decrypt stored git tokens in every repository provider
kissghosts e24bf18
refactor(knowledge): own code wikis by their creator
kissghosts 5c949c4
feat(knowledge): let a public repository have a wiki
kissghosts ec7fd12
feat(knowledge): create a code wiki from the ordinary knowledge base …
kissghosts f15e712
fix(knowledge): name a code wiki's existing wikis, and let a new one …
kissghosts cd51e34
refactor(knowledge): stop describing the repository twice when creati…
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
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: b9c0d1e2f3a4 | ||
|
|
||
| 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] = "b9c0d1e2f3a4" | ||
| 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") |
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