-
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
base: main
Are you sure you want to change the base?
Refactor/code wiki kb #2328
Changes from 3 commits
1c5d371
51fbe67
7931f70
783c460
edf8b67
8c5b046
9367b99
cbba7dc
651b108
e24bf18
5c949c4
ec7fd12
f15e712
cd51e34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| WikiGenerationDetail, | ||
| WikiGenerationInDB, | ||
| WikiGenerationListResponse, | ||
| WikiPageRead, | ||
| WikiProjectDetail, | ||
| WikiProjectInDB, | ||
| WikiProjectListResponse, | ||
|
|
@@ -217,6 +218,35 @@ def save_wiki_generation_contents( | |
| return None | ||
|
|
||
|
|
||
| @internal_router.get("/generations/{generation_id}/pages", response_model=WikiPageRead) | ||
| def read_wiki_generation_page( | ||
| generation_id: int, | ||
| path: str = Query(..., min_length=1, description="Stable page path to read"), | ||
| _: None = Depends(_verify_internal_token), | ||
| wiki_db: Session = Depends(get_wiki_db), | ||
| ): | ||
| """Read one page of the version the agent is writing into (internal use). | ||
|
|
||
| An incremental version begins as a complete copy of the published wiki, so the | ||
| agent's own generation is also the current wiki — which makes "read your own | ||
| version" both the capability it needs and the narrowest scope that provides it. | ||
| Without this the instruction to revise a page cannot be followed: the agent knows | ||
| the page's path and cannot see a word of what it says. | ||
|
|
||
| Answers 404 when the path holds no page. That is a useful answer rather than a | ||
| failure — in an incremental run it means the page is new. | ||
| """ | ||
| page = wiki_service.get_generation_page( | ||
| wiki_db=wiki_db, generation_id=generation_id, path=path | ||
| ) | ||
| if page is None: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail=f"Generation {generation_id} has no page at '{path}'", | ||
| ) | ||
| return page | ||
|
Comment on lines
+266
to
+293
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift The "own generation only" scope is documented but not enforced.
🧰 Tools🪛 Ruff (0.16.0)[warning] 226-226: Do not perform function call (B008) 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| @router.get( | ||
| "/generations/{generation_id}/contents", response_model=list[WikiContentInDB] | ||
| ) | ||
|
|
||
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