Skip to content

Conversation

@killagu
Copy link
Contributor

@killagu killagu commented Jan 12, 2026

Document how tegg runs without Egg.js using the standalone package, including initialization flow, context management via AsyncLocalStorage, inner objects mechanism, and usage examples.

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Summary by CodeRabbit

  • Documentation
    • Added comprehensive documentation for the standalone runtime mode, enabling tegg to operate independently without the Egg.js framework. Coverage includes module structure, lifecycle management, initialization procedures, context management, dependency resolution, and practical usage examples. Documentation also provides guidance on plugin development and configuration patterns.

✏️ Tip: You can customize this high-level summary in your review settings.

Document how tegg runs without Egg.js using the standalone package,
including initialization flow, context management via AsyncLocalStorage,
inner objects mechanism, and usage examples.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

📝 Walkthrough

Walkthrough

Adds comprehensive documentation for tegg's standalone runtime mode, covering module initialization, lifecycle management, context handling via AsyncLocalStorage, inner object integration, and practical usage examples with configuration patterns for standalone and plugin-based operation.

Changes

Cohort / File(s) Summary
Documentation
CLAUDE.md
+238 lines: Standalone runtime documentation including module layout, lifecycle initialization, context management, inner objects, usage examples (basic, dependencies, manual control, preLoad), mode differences, StandaloneContextHandler, and plugin integration guidance

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • fengmk2

Poem

🐰 A tegg hops free, no egg in sight,
Standalone and bright, documented right!
Context flows with async grace,
Inner objects find their place.
From init to load, the path shines clear—
Rabbit's guide, now happy cheer! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: add standalone mode documentation to CLAUDE.md' accurately summarizes the main change—adding comprehensive documentation about tegg's standalone mode to the CLAUDE.md file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @killagu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's documentation by adding a detailed guide for the @eggjs/tegg-standalone package. It clarifies how the tegg framework can be used in environments outside of a full Egg.js application, such as CLI tools or background services. The new content explains the core concepts, setup, and usage patterns for this standalone capability, ensuring developers can effectively leverage tegg's dependency injection and module loading features in a broader range of Node.js applications.

Highlights

  • Standalone Mode Documentation: Added comprehensive documentation for the @eggjs/tegg-standalone package, explaining how tegg can run independently of the Egg.js framework.
  • Key Differences Explained: Detailed the architectural differences between Egg.js mode and standalone mode, covering context storage, context objects, inner objects, HTTP handling, and configuration loading.
  • Initialization Flow: Provided a step-by-step breakdown of the Runner initialization, execution, and destruction lifecycle in standalone mode.
  • Context Management: Explained how AsyncLocalStorage is utilized by StandaloneContextHandler to manage context objects, simulating Egg.js's request context in a standalone environment.
  • Inner Objects Handling: Documented the mechanism for providing and injecting 'inner objects' (such as logger and config) using innerObjectHandlers, replacing the app and ctx objects from Egg.js.
  • Usage Examples: Included practical examples for basic usage, usage with dependencies and custom objects, advanced manual Runner control, and utilizing preLoad for faster startup.
  • Standalone-Compatible Plugins: Provided guidelines for creating plugins that are compatible with standalone mode, emphasizing the use of eggModule in package.json and avoiding direct Egg.js API dependencies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds comprehensive documentation for the standalone mode of tegg. The new documentation in CLAUDE.md covers the architecture, initialization flow, context management, and usage of the @eggjs/tegg-standalone package. The content is well-structured and detailed. I've provided a couple of minor suggestions to improve the clarity and consistency of the code examples and text.

myService: MyService;

async main(): Promise<string> {
return await this.myService.doSomething();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In an async function, you can directly return a promise without await-ing it. The function will automatically adopt the state of the returned promise. Removing the redundant await makes the code slightly more concise and is a good practice to demonstrate in documentation.

Suggested change
return await this.myService.doSomething();
return this.myService.doSomething();

Comment on lines +974 to +976
- Use `@Inject()` for dependencies
- Use lifecycle hooks (`init()`, `destroy()`) instead of Egg.js lifecycle
- Provide factories that accept configuration via injection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and improved readability, it's good practice to end each item in a list with a period, especially when they function as complete sentences or imperative clauses.

Suggested change
- Use `@Inject()` for dependencies
- Use lifecycle hooks (`init()`, `destroy()`) instead of Egg.js lifecycle
- Provide factories that accept configuration via injection
- Use `@Inject()` for dependencies.
- Use lifecycle hooks (`init()`, `destroy()`) instead of Egg.js lifecycle.
- Provide factories that accept configuration via injection.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @CLAUDE.md:
- Line 882: Update the incorrect imports that use the hyphenated package name
'@eggjs/tegg-standalone' to the correct subpath '@eggjs/tegg/standalone' in all
standalone-mode examples; specifically replace occurrences that import symbols
like "main" (and any other imports) from '@eggjs/tegg-standalone' so they import
from '@eggjs/tegg/standalone' instead.
🧹 Nitpick comments (2)
CLAUDE.md (2)

744-754: Add language specifier to code block.

The code block showing the directory structure should have a language specifier for proper syntax highlighting and consistency with other code blocks in the document.

📝 Proposed fix
-```
+```text
 ├── src/
 │   ├── Runner.ts                   # Main orchestrator: loads modules, manages lifecycle

772-802: Add language specifier to initialization flow code block.

The initialization flow pseudo-code block should have a language specifier for consistency.

📝 Proposed fix
-```
+```text
 1. new Runner(cwd, options)
    ├── Read module references from cwd
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa6e26 and cc56cef.

📒 Files selected for processing (1)
  • CLAUDE.md
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Use 'eggjs/tegg/helper' for internal APIs like ModuleConfigUtil, LoaderFactory, and EggObjectLifeCycleContext in advanced usage scenarios
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to core/tegg/index.ts : Re-export core decorator, runtime, and type functionality from the main 'eggjs/tegg' package index.ts
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Create new tegg framework features in the order: core/types → core/*-decorator → core/*-runtime → core/tegg → plugin/*
📚 Learning: 2026-01-10T12:35:11.407Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to core/tegg/index.ts : Re-export core decorator, runtime, and type functionality from the main 'eggjs/tegg' package index.ts

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.408Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Use 'eggjs/tegg/helper' for internal APIs like ModuleConfigUtil, LoaderFactory, and EggObjectLifeCycleContext in advanced usage scenarios

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.408Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Create subpath exports in 'eggjs/tegg' for optional features (aop, orm, dal, schedule, transaction, ajv, helper, standalone)

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.407Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to plugin/**/*.test.{ts,js} : Use 'egg-mock' with 'app.mockModuleContextScope()' for testing plugin modules in isolation

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.408Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Always import decorators, enums, and public APIs from 'eggjs/tegg' in application code

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.407Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to plugin/**/*.{ts,tsx} : Framework internal code in plugin packages should import types from 'eggjs/tegg-types' and decorators from 'eggjs/core-decorator'

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.408Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Plugin packages must include 'eggPlugin' and 'eggModule' configuration in package.json

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.408Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.408Z
Learning: Create new tegg framework features in the order: core/types → core/*-decorator → core/*-runtime → core/tegg → plugin/*

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.407Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to plugin/*/app.ts : Register prototype lifecycle hooks in plugin 'app.ts' using 'app.eggPrototypeLifecycleUtil.registerLifecycle()'

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-10T12:35:11.407Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.407Z
Learning: Applies to core/**/*.{ts,tsx} : Framework internal code in core packages should import types from 'eggjs/tegg-types' and decorators from 'eggjs/core-decorator'

Applied to files:

  • CLAUDE.md
🪛 LanguageTool
CLAUDE.md

[grammar] ~742-~742: Ensure spelling is correct
Context: ...orks without Egg.js. This enables using tegg's dependency injection in CLI tools, back...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.18.1)
CLAUDE.md

744-744: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


772-772: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-macos (16)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Runner-macos (18)
🔇 Additional comments (3)
CLAUDE.md (3)

804-853: Well-documented context management and inner objects mechanism.

The explanation of AsyncLocalStorage-based context management and inner objects pattern is clear, technically accurate, and provides practical examples that will help developers understand how standalone mode differs from Egg.js mode.


891-891: Verify import path consistency.

Line 891 imports from '@eggjs/tegg-standalone', but this should likely be '@eggjs/tegg/standalone' based on the subpath pattern used elsewhere in the documentation (line 121) and other examples in this section.


954-976: Clear guidance for standalone-compatible plugins.

The documentation provides clear, actionable guidance for creating plugins that work in both Egg.js and standalone modes. The distinction between eggPlugin and eggModule is well-explained, and the best practices align well with the framework's dependency injection philosophy.

}

// Run it
import { main } from '@eggjs/tegg-standalone';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the main tegg package.json for exports configuration
find . -path "*/core/tegg/package.json" -o -path "*/tegg/package.json" | head -5 | xargs cat 2>/dev/null | grep -A 30 '"exports"' | head -40

Repository: eggjs/tegg

Length of output: 36


🏁 Script executed:

#!/bin/bash
# Also check if there's a standalone package directory
find . -type d -name "standalone" | grep -v node_modules

Repository: eggjs/tegg

Length of output: 90


🏁 Script executed:

#!/bin/bash
# Check CLAUDE.md content around lines 882 and other import examples
sed -n '875,895p' CLAUDE.md
echo "---"
sed -n '855,870p' CLAUDE.md
echo "---"
sed -n '920,950p' CLAUDE.md

Repository: eggjs/tegg

Length of output: 1643


🏁 Script executed:

#!/bin/bash
# Search for package.json files and check their exports
find . -name "package.json" -type f | grep -E "(core/tegg|root)" | head -10 | xargs cat | grep -B5 -A50 '"exports"' | head -100

Repository: eggjs/tegg

Length of output: 36


🏁 Script executed:

#!/bin/bash
# Try looking at the root package.json specifically
cat package.json | grep -A 50 '"exports"'

Repository: eggjs/tegg

Length of output: 36


🏁 Script executed:

#!/bin/bash
# Check if there's a package.json in the standalone directory
if [ -f "./standalone/package.json" ]; then
  cat ./standalone/package.json | head -20
fi

Repository: eggjs/tegg

Length of output: 36


🏁 Script executed:

#!/bin/bash
# List root directory and common package locations
ls -la | head -20

Repository: eggjs/tegg

Length of output: 1231


🏁 Script executed:

#!/bin/bash
# Find all package.json files
find . -name "package.json" -type f 2>/dev/null | head -20

Repository: eggjs/tegg

Length of output: 1239


🏁 Script executed:

#!/bin/bash
# Check the standalone package.json if it exists
cat ./standalone/package.json 2>/dev/null || echo "File not found"

Repository: eggjs/tegg

Length of output: 68


🏁 Script executed:

#!/bin/bash
# Search for actual imports in the codebase to see which pattern is used
rg '@eggjs/tegg-standalone|@eggjs/tegg/standalone' --type ts --type tsx -c | head -20

Repository: eggjs/tegg

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Find where standalone is located
find core plugin -type d -name "*standalone*" 2>/dev/null

Repository: eggjs/tegg

Length of output: 79


🏁 Script executed:

#!/bin/bash
# Check if standalone is a core package
ls -la core/ | grep standalone

Repository: eggjs/tegg

Length of output: 123


🏁 Script executed:

#!/bin/bash
# Look at CLAUDE.md line 121 area to see the subpaths list
sed -n '115,135p' CLAUDE.md

Repository: eggjs/tegg

Length of output: 606


🏁 Script executed:

#!/bin/bash
# Search for actual imports of both patterns in .ts files
rg '@eggjs/tegg-standalone|@eggjs/tegg/standalone' --type ts -A 2 | head -50

Repository: eggjs/tegg

Length of output: 3676


🏁 Script executed:

#!/bin/bash
# Find all instances of both import patterns in CLAUDE.md
echo "=== Imports with SLASH (correct) ==="
rg '@eggjs/tegg/standalone' CLAUDE.md -n
echo ""
echo "=== Imports with HYPHEN (incorrect) ==="
rg '@eggjs/tegg-standalone' CLAUDE.md -n

Repository: eggjs/tegg

Length of output: 496


🏁 Script executed:

#!/bin/bash
# Show the context around the examples to understand the scope
sed -n '850,860p' CLAUDE.md
echo "---"
sed -n '878,895p' CLAUDE.md
echo "---"
sed -n '918,932p' CLAUDE.md
echo "---"
sed -n '940,955p' CLAUDE.md

Repository: eggjs/tegg

Length of output: 1540


Fix import paths in standalone mode examples.

Lines 882, 891, 923, and 945 incorrectly import from '@eggjs/tegg-standalone' (with hyphen). The correct subpath format is '@eggjs/tegg/standalone' (with slash), which aligns with the documented subpaths list and the correct example at line 861. Update all four examples to use the slash format.

🤖 Prompt for AI Agents
In @CLAUDE.md at line 882, Update the incorrect imports that use the hyphenated
package name '@eggjs/tegg-standalone' to the correct subpath
'@eggjs/tegg/standalone' in all standalone-mode examples; specifically replace
occurrences that import symbols like "main" (and any other imports) from
'@eggjs/tegg-standalone' so they import from '@eggjs/tegg/standalone' instead.

@killagu killagu merged commit 5fc4023 into master Jan 15, 2026
11 checks passed
@killagu killagu deleted the doc/agents_standalone branch January 15, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants