Repository navigation
feat: init public resources - #180
Conversation
📝 WalkthroughWalkthroughRefactors public resource initialization to support multiple kinds (Shell, Ghost, Bot, Team). Renames Changes
Sequence Diagram(s)(Skipped — changes are primarily refactor/initialization and UI tweaks without a new multi-component sequential runtime flow warranting a diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/app/core/yaml_init.py (1)
541-609: Resource totals can overcount when unsupported kinds are present.
public_resourcesincludes all docs, butapply_public_resourcesskips unsupported kinds without emitting results, soresources_failedcan be inflated. Consider basing totals onpublic_results(processed items) or emitting explicit “skipped” entries for unsupported kinds.🔧 Proposed adjustment (counts based on processed resources)
- total_resources = len(public_resources) + len(skill_results) + total_resources = len(public_results) + len(skill_results)
🤖 Fix all issues with AI agents
In `@backend/app/core/yaml_init.py`:
- Around line 205-219: Add tracing to the module by importing trace_sync from
shared.telemetry.decorators and decorating each top-level synchronous
initialization entrypoint with `@trace_sync`(span_name="...",
tracer_name="backend.yaml_init"); specifically add the import and apply the
decorator to the apply_public_resources function and to the two other public
sync init functions in this file (the remaining two top-level initialization
entrypoints), using descriptive span names for each (e.g.,
span_name="yaml_init.apply_public_resources") while keeping
tracer_name="backend.yaml_init".
🧹 Nitpick comments (2)
backend/app/core/yaml_init.py (2)
343-345: Preferlogger.exceptionto retain stack traces.
Line 344 is in an exception path;logger.exception(...)is the idiomatic way to include the traceback automatically.🔧 Proposed change
- except Exception as e: - logger.error(f"Failed to process public {kind}: {e}") + except Exception as e: + logger.exception(f"Failed to process public {kind}: {e}")
614-628: Document the intentionally-unusedskip_lockparameter.
This keeps the backward-compatible signature while silencing lint noise.🔧 Proposed change
def run_yaml_initialization(db: Session, skip_lock: bool = False) -> Dict[str, Any]: + _ = skip_lock # deprecated; kept for backward compatibility
| def apply_public_resources( | ||
| db: Session, resources: List[Dict[str, Any]], force: bool = False | ||
| ) -> List[Dict[str, Any]]: | ||
| """ | ||
| Apply public shell resources to the kinds table (user_id=0). | ||
| Only creates new shells, skips existing ones (create-only mode). | ||
| Apply public resources (Shell, Ghost, Bot, Team) to the kinds table (user_id=0). | ||
| Only creates new resources, skips existing ones (create-only mode). | ||
|
|
||
| Args: | ||
| db: Database session | ||
| resources: List of Shell resource documents | ||
| force: If True, delete existing shells and recreate them | ||
| resources: List of resource documents (Shell, Ghost, Bot, Team) | ||
| force: If True, delete existing resources and recreate them | ||
|
|
||
| Returns: | ||
| List of operation results | ||
| """ |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
# First, let's see the file structure and examine the specified line ranges
wc -l backend/app/core/yaml_init.pyRepository: wecode-ai/Wegent
Length of output: 93
🏁 Script executed:
# View the functions at the specified lines
cat -n backend/app/core/yaml_init.py | sed -n '200,225p'Repository: wecode-ai/Wegent
Length of output: 1016
🏁 Script executed:
# View lines 501-518
cat -n backend/app/core/yaml_init.py | sed -n '495,525p'Repository: wecode-ai/Wegent
Length of output: 1404
🏁 Script executed:
# View lines 614-621
cat -n backend/app/core/yaml_init.py | sed -n '610,630p'Repository: wecode-ai/Wegent
Length of output: 946
🏁 Script executed:
# Check for any existing `@trace_sync` or `@trace_async` decorators in the file
rg '@trace_sync|@trace_async' backend/app/core/yaml_init.pyRepository: wecode-ai/Wegent
Length of output: 42
🏁 Script executed:
# Check import statements to see if tracing is imported
head -50 backend/app/core/yaml_init.py | cat -nRepository: wecode-ai/Wegent
Length of output: 1770
🏁 Script executed:
# Search for any tracing imports in the entire file
rg 'trace_sync|trace_async|from.*tracing|import.*tracing' backend/app/core/yaml_init.pyRepository: wecode-ai/Wegent
Length of output: 42
🏁 Script executed:
# Check if trace_sync decorator exists in the codebase
fd -t f '*.py' backend/app | xargs rg -l 'def trace_sync|trace_sync ='Repository: wecode-ai/Wegent
Length of output: 391
🏁 Script executed:
# Look for where tracing decorators are defined/exported
fd -t f '*.py' backend | xargs rg -l '@trace_sync' | head -5Repository: wecode-ai/Wegent
Length of output: 515
🏁 Script executed:
# Check the structure of trace_sync decorator
cat -n shared/telemetry/decorators.py | head -100Repository: wecode-ai/Wegent
Length of output: 3827
🏁 Script executed:
# Look for examples of `@trace_sync` usage in backend code
rg -A 3 '@trace_sync' backend --glob '*.py' | head -30Repository: wecode-ai/Wegent
Length of output: 803
🏁 Script executed:
# Check if tracing is imported in yaml_init.py
rg -n 'from.*telemetry|import.*telemetry' backend/app/core/yaml_init.pyRepository: wecode-ai/Wegent
Length of output: 42
🏁 Script executed:
# Look at how trace_sync is imported in the backend files that use it
rg -B 5 '@trace_sync' backend/app/services/chat/trigger/core.py | head -30Repository: wecode-ai/Wegent
Length of output: 234
Add required tracing decorators for sync public functions in initialization module.
The sync functions at lines 205, 501, and 614 are missing @trace_sync() decorators as required by guidelines. These are initialization entrypoints and should include tracing. Add the import from shared.telemetry.decorators import trace_sync and decorate each function with @trace_sync(span_name="...", tracer_name="backend.yaml_init").
🤖 Prompt for AI Agents
In `@backend/app/core/yaml_init.py` around lines 205 - 219, Add tracing to the
module by importing trace_sync from shared.telemetry.decorators and decorating
each top-level synchronous initialization entrypoint with
`@trace_sync`(span_name="...", tracer_name="backend.yaml_init"); specifically add
the import and apply the decorator to the apply_public_resources function and to
the two other public sync init functions in this file (the remaining two
top-level initialization entrypoints), using descriptive span names for each
(e.g., span_name="yaml_init.apply_public_resources") while keeping
tracer_name="backend.yaml_init".
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@backend/init_data/02-public-resources.yaml`:
- Line 593: The language instruction "(in chinese)" after the agent name is
ambiguous; update the Core Principles by removing that inline note and adding a
clear separate rule such as "Your responses should be in Chinese" (or "Your
responses must be in Chinese") as its own bullet or sentence alongside the
"Wegent Notebook Agent" identity to make the language requirement explicit and
unambiguous.
- Around line 564-566: Update the README files to reflect the team rename:
search for occurrences of the old team name "chat-team" in README.md and
README_zh.md and replace them with the new name "wegent-chat" so the team
reference tables and any mentions match the resource name (e.g., the manifest
entry named "wegent-chat" / displayName "Wegent Chat"); verify both English and
Chinese READMEs and update any captions, links or table rows that reference the
old identifier to the new one.
🧹 Nitpick comments (1)
frontend/src/features/tasks/components/chat/QuickAccessCards.tsx (1)
569-607: Consider reusing the helper functions for consistency.The inline logic (
isGroupTeamItem,isPublicTeam,isPersonalTeamItem) duplicates theisPersonalTeamandisGroupTeamhelper functions defined at lines 316-325. Using the helpers would reduce code duplication and ensure consistent badge logic across card and dropdown views.♻️ Suggested refactor
dropdownTeams.map(team => { const isSelected = selectedTeam?.id === team.id const isSharedTeam = team.share_status === 2 && team.user?.user_name - const isGroupTeamItem = team.namespace && team.namespace !== 'default' - const isPublicTeam = 'user_id' in team && team.user_id === 0 - const isPersonalTeamItem = !isPublicTeam && !isGroupTeamItem + // Reuse helper functions for consistency + const isPersonalTeamItem = isPersonalTeam(team as DisplayTeam) + const isGroupTeamItem = isGroupTeam(team as DisplayTeam) return (Note: This requires casting
teamtoDisplayTeamsince the dropdown iterates overTeamobjects. Alternatively, make the helper functions acceptTeamtype ifDisplayTeamfields aren't needed.
| name: wegent-chat | ||
| displayName: Wegent Chat | ||
| namespace: default |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for references to the old team name "chat-team"
echo "=== Searching for 'chat-team' references ==="
rg "chat-team" --type-list | head -20
echo ""
echo "=== Searching across common file types ==="
rg "chat-team" -t yaml -t py -t ts -t js -t json 2>/dev/null || true
echo ""
echo "=== Searching all files (no type restriction) ==="
rg "chat-team" --no-heading -c 2>/dev/null || trueRepository: wecode-ai/Wegent
Length of output: 1023
🏁 Script executed:
#!/bin/bash
echo "=== README.md context for 'chat-team' ==="
rg "chat-team" -B 2 -A 2 README.md
echo ""
echo "=== README_zh.md context for 'chat-team' ==="
rg "chat-team" -B 2 -A 2 README_zh.md
echo ""
echo "=== Check test file content ==="
rg "chat-team" -B 2 -A 2 frontend/e2e/tests/tasks/chat-image-browser-e2e.spec.tsRepository: wecode-ai/Wegent
Length of output: 692
Update documentation to reflect team name change.
The rename from chat-team to wegent-chat requires corresponding updates in the README files. Both README.md and README_zh.md document the old team name in their team reference tables and must be updated to wegent-chat to maintain consistency.
No code or configuration dependencies on the old name were found, so this is primarily a documentation update requirement.
🤖 Prompt for AI Agents
In `@backend/init_data/02-public-resources.yaml` around lines 564 - 566, Update
the README files to reflect the team rename: search for occurrences of the old
team name "chat-team" in README.md and README_zh.md and replace them with the
new name "wegent-chat" so the team reference tables and any mentions match the
resource name (e.g., the manifest entry named "wegent-chat" / displayName
"Wegent Chat"); verify both English and Chinese READMEs and update any captions,
links or table rows that reference the old identifier to the new one.
| - mermaid-diagram | ||
| mcpServers: {} | ||
| systemPrompt: | | ||
| You are "Wegent Notebook Agent", a research and writing assistant whose knowledge is strictly limited to the materials provided by the user in the current conversation(in chinese). Your behavior and output style are inspired by Google NotebookLM: material-centric, evidence-first, and focused on helping users understand, organize, and reuse their own content. |
There was a problem hiding this comment.
Minor: Clarify the language instruction.
The inline (in chinese) is ambiguous. Consider making the language requirement more explicit, e.g., "Your responses should be in Chinese" as a separate instruction in the Core Principles section.
🤖 Prompt for AI Agents
In `@backend/init_data/02-public-resources.yaml` at line 593, The language
instruction "(in chinese)" after the agent name is ambiguous; update the Core
Principles by removing that inline note and adding a clear separate rule such as
"Your responses should be in Chinese" (or "Your responses must be in Chinese")
as its own bullet or sentence alongside the "Wegent Notebook Agent" identity to
make the language requirement explicit and unambiguous.
* feat: init public resources * fix: fix wegent initial team
feat: init public resources (#180) See merge request weibo_rd/common/wecode/wegent!1211
Summary by CodeRabbit
New Features
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.