Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tegg/standalone/standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"dependencies": {
"@eggjs/aop-runtime": "workspace:*",
"@eggjs/controller-plugin": "workspace:*",
"@eggjs/dal-plugin": "workspace:*",
"@eggjs/lifecycle": "workspace:*",
"@eggjs/metadata": "workspace:*",
Expand Down
16 changes: 16 additions & 0 deletions tegg/standalone/standalone/src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@eggjs/dal-plugin';
import {
type EggPrototype,
EggPrototypeCreatorFactory,
EggPrototypeLifecycleUtil,
GlobalGraph,
type LoadUnit,
Expand All @@ -40,6 +41,7 @@ import {
ContextHandler,
EggContainerFactory,
type EggContext,
EggObjectFactory,
EggObjectLifecycleUtil,
type LoadUnitInstance,
LoadUnitInstanceFactory,
Expand All @@ -48,6 +50,9 @@ import {
import { CrosscutAdviceFactory } from '@eggjs/tegg/aop';
import { StandaloneUtil, type MainRunner } from '@eggjs/tegg/standalone';

import { AgentControllerObject } from '@eggjs/controller-plugin/lib/AgentControllerObject';
import { AgentControllerProto } from '@eggjs/controller-plugin/lib/AgentControllerProto';
Comment on lines +53 to +54
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Importing directly from the lib directory of @eggjs/controller-plugin is generally discouraged as it relies on internal implementation details that can change without notice, leading to potential breakages. It would be better to import these from the package's public API if they are exposed, for example: import { AgentControllerObject, AgentControllerProto } from '@eggjs/controller-plugin';. If they are not exported, it might be worth considering exposing them from the plugin package to create a stable API contract.


import { ConfigSourceLoadUnitHook } from './ConfigSourceLoadUnitHook.ts';
import { EggModuleLoader } from './EggModuleLoader.ts';
import { StandaloneContext } from './StandaloneContext.ts';
Expand Down Expand Up @@ -246,6 +251,17 @@ export class Runner {
EggPrototypeLifecycleUtil.registerLifecycle(this.dalTableEggPrototypeHook);
EggPrototypeLifecycleUtil.registerLifecycle(this.transactionPrototypeHook);
LoadUnitLifecycleUtil.registerLifecycle(this.dalModuleLoadUnitHook);

// AgentController support
EggPrototypeCreatorFactory.registerPrototypeCreator(
'AGENT_CONTROLLER_PROTO',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using a magic string like 'AGENT_CONTROLLER_PROTO' is brittle. If this string is defined as a constant within the @eggjs/controller-plugin package (e.g., on AgentControllerProto itself as a static property), it would be safer to import and use that constant instead. This would prevent potential issues if the value changes in the source package.

AgentControllerProto.createProto,
);
EggObjectFactory.registerEggObjectCreateMethod(
AgentControllerProto,
AgentControllerObject.createObject,
);
AgentControllerObject.setLogger(logger as any);
Copy link
Copy Markdown
Contributor

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

🌐 Web query:

What is the EggLogger interface in egg.js framework?

πŸ’‘ Result:

The EggLogger interface in the Egg.js framework refers to the Logger class provided by the egg-logger module, which is the core logging system for Egg.js applications. It is not a formal TypeScript "interface" but the primary Logger class and its extensions used throughout Egg.js (e.g., app.logger, ctx.logger). Key aspects from official sources: - Logger is the base class from egg-logger that supports multiple Transports (e.g., file, console, custom). - Common methods: debug(msg), info(msg), warn(msg), error(err), supports printf-style formatting (%s, %j, %d). - Additional methods: set(name, transport), disable(name), enable(name), duplicate(target, options), redirect(level, logger). - Levels: NONE, DEBUG, INFO, WARN, ERROR. - Egg.js provides specialized loggers: appLogger (app-web.log), coreLogger (egg-web.log), errorLogger (common-error.log), agentLogger (egg-agent.log). - Custom loggers via config.customLogger. - Accessed as app.logger, ctx.logger, this.logger in controllers/services. Usage example: const Logger = require('egg-logger').Logger; const logger = new Logger; logger.set('console', new require('egg-logger').ConsoleTransport({ level: 'INFO' })); logger.info('Hello %s', 'world'); Egg.js loggers are instances of or wrap this Logger for enterprise features like multi-process safety, log rotation, and JSON output.

Citations:


🏁 Script executed:

# First, let's examine the Runner.ts file around line 264
fd -t f "Runner.ts" | xargs wc -l | head -20

Repository: eggjs/egg

Length of output: 172


🏁 Script executed:

# Get the specific file path
find . -name "Runner.ts" -path "*/tegg/standalone/*" -type f

Repository: eggjs/egg

Length of output: 95


🏁 Script executed:

# Read the Runner.ts file to understand the context
fd -t f "Runner.ts" -path "*/tegg/standalone/*" | head -1 | xargs cat -n | sed -n '240,280p'

Repository: eggjs/egg

Length of output: 221


🏁 Script executed:

# Find AgentControllerObject and its setLogger method
rg "AgentControllerObject" -A 20 -B 5 | head -50

Repository: eggjs/egg

Length of output: 3863


🏁 Script executed:

# Search for AgentControllerObject class definition and setLogger method
fd -t f "\.ts$" -path "*/tegg/*" | xargs rg "setLogger" -B 3 -A 3

Repository: eggjs/egg

Length of output: 1702


🏁 Script executed:

# Read the Runner.ts constructor to find the logger type definition
cat -n tegg/standalone/standalone/src/Runner.ts | sed -n '230,270p'

Repository: eggjs/egg

Length of output: 2184


🏁 Script executed:

# Find the imports and logger type in Runner.ts
cat -n tegg/standalone/standalone/src/Runner.ts | sed -n '1,50p'

Repository: eggjs/egg

Length of output: 1547


🏁 Script executed:

# Read AgentControllerObject.ts to find EggLogger import
cat -n tegg/plugin/controller/src/lib/AgentControllerObject.ts | sed -n '1,50p'

Repository: eggjs/egg

Length of output: 2161


🏁 Script executed:

# Check for Logger and EggLogger type definitions
rg "type Logger|interface Logger|class Logger" -B 2 -A 5 | head -80

Repository: eggjs/egg

Length of output: 5588


Remove the as any castβ€”use a compatible logger type or adjust the signature.

AgentControllerObject.setLogger() expects EggLogger from the egg package, but the logger variable is typed as Logger from @eggjs/tegg. The fallback to console further complicates this, since console is not compatible with EggLogger. The as any cast violates the no-any guideline and masks a real type mismatch.

Consider:

  1. Importing EggLogger and ensuring type compatibility before calling setLogger()
  2. Adding a type guard or adapter function to validate logger compatibility
  3. Adjusting setLogger() to accept a more general logger interface
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tegg/standalone/standalone/src/Runner.ts` at line 264, Replace the unsafe
cast by ensuring the logger passed to AgentControllerObject.setLogger has the
correct EggLogger shape: import EggLogger from the egg package and either (a)
assert/convert the existing logger variable (typed Logger from `@eggjs/tegg`) to
EggLogger after mapping or wrapping it with an adapter function that implements
EggLogger methods, or (b) add a small type-guard that verifies the logger
implements the EggLogger interface and choose a proper fallback (avoid using raw
console); then call AgentControllerObject.setLogger(with the adapted/typed
EggLogger) instead of using `as any`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The use of as any here bypasses type safety. It suggests a type mismatch between the logger object (of type Logger from @eggjs/tegg) and the logger expected by AgentControllerObject.setLogger. Please investigate the type incompatibility and resolve it. If the logger types are structurally compatible but differ by name, you could use a more specific type assertion to the expected type instead of any, or create a simple adapter. Using any can hide bugs and makes the code harder to maintain.

}

async init(): Promise<void> {
Expand Down
Loading