🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🔨 chore(alint): guard static App image namespace (#20999)
Innei1d879f85db7e
diff --git a/alint.config.toml b/alint.config.tomlindex a7e4f33a2dd..56e820513ea 100644--- a/alint.config.toml+++ b/alint.config.toml@@ -61,6 +61,22 @@ lobehub = "./packages/alint/rules""lobehub/no-mode-flags" = "warn""lobehub/no-unguarded-response-field" = "error"+# Fixed product images and App-owned resource requests have different namespaces.+[[config.group]]+files = [ "src/**/*.{ts,tsx,css}", "packages/const/src/**/*.ts", "apps/*/app/**/*.{ts,tsx,css}", "apps/{share,workbench}/src/**/*.{ts,tsx,css}", "apps/desktop/vite.*.config.{ts,mts}", "scripts/**/*.{ts,mts}" ]+ignores = [ "**/*.{test,spec}.{ts,tsx}", "**/__tests__/**", "**/fixtures/**", "**/generated/**" ]+[config.group.plugins]+lobehub = "./packages/alint/rules"+[config.group.rules]+"lobehub/static-app-image-namespace" = "warn"++[[config.group]]+files = [ "packages/alint/fixtures/static-app-image-namespace/**" ]+[config.group.plugins]+lobehub = "./packages/alint/rules"+[config.group.rules]+"lobehub/static-app-image-namespace" = "warn"+# Browser code, everywhere: no third-party package that needs Node may be# imported where the SPA (or the Electron renderer) runs it. Node built-ins anddiff --git a/packages/alint/README.md b/packages/alint/README.mdindex 56211ac31db..8c4120e2f01 100644--- a/packages/alint/README.md+++ b/packages/alint/README.md@@ -30,6 +30,7 @@ This is Phase 0: the rule set is a private workspace package (`@lobechat/alint`)| `no-privileged-untrusted-electron` | warn | Electron main/preload | remote content with Node privileges or unrestricted IPC bridges || `no-removal-only-tests` | warn | app/package/client test and spec files | tests should prove behavior, not merely that a retired option is absent || `no-redundant-api-copy` | warn | usage guides, builtin skills, CLI commands, public schemas | keep ordinary instructions focused on supported actions |+| `static-app-image-namespace` | warn | web client, image URL helpers and asset packaging | fixed product images use `/static/app-images` |Package-level rules, kept next to the package they describe:diff --git a/packages/alint/fixtures/static-app-image-namespace/bad-background.ts b/packages/alint/fixtures/static-app-image-namespace/bad-background.tsnew file mode 100644index 00000000000..622cea9be44--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/bad-background.ts@@ -0,0 +1,4 @@+export const productBanner = {+ // alint-expect+ backgroundImage: "url('/app-images/product-banner.webp')",+};diff --git a/packages/alint/fixtures/static-app-image-namespace/bad-bundled-reference.ts b/packages/alint/fixtures/static-app-image-namespace/bad-bundled-reference.tsnew file mode 100644index 00000000000..3e6d8e14957--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/bad-bundled-reference.ts@@ -0,0 +1,4 @@+// The bundled line-art illustration is a fixed input to artwork generation.+export const lineArtReferenceUrl = (appOrigin: string) =>+ // alint-expect+ new URL('/app-images/agent-artwork-styles/line-art-reference.webp', appOrigin).toString();diff --git a/packages/alint/fixtures/static-app-image-namespace/bad-fixed-image-helper.ts b/packages/alint/fixtures/static-app-image-namespace/bad-fixed-image-helper.tsnew file mode 100644index 00000000000..eb0c9d1969a--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/bad-fixed-image-helper.ts@@ -0,0 +1,3 @@+// Builds URLs for fixed product images shipped in public/.+// alint-expect+export const imageUrl = (filename: string) => `/app-images/${filename}`;diff --git a/packages/alint/fixtures/static-app-image-namespace/bad-static-copy.ts b/packages/alint/fixtures/static-app-image-namespace/bad-static-copy.tsnew file mode 100644index 00000000000..33daeaf0dc8--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/bad-static-copy.ts@@ -0,0 +1,5 @@+import { cp } from 'node:fs/promises';++// Package the current fixed product images for the renderer.+// alint-expect+await cp('public/static/app-images', 'dist/renderer/app-images', { recursive: true });diff --git a/packages/alint/fixtures/static-app-image-namespace/bad-static-image.tsx b/packages/alint/fixtures/static-app-image-namespace/bad-static-image.tsxnew file mode 100644index 00000000000..0dd7dc5b8a6--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/bad-static-image.tsx@@ -0,0 +1,4 @@+export const ProductHero = () => (+ // alint-expect+ <img alt="Product hero" src="/app-images/product-hero.webp" />+);diff --git a/packages/alint/fixtures/static-app-image-namespace/good-dynamic-resource.ts b/packages/alint/fixtures/static-app-image-namespace/good-dynamic-resource.tsnew file mode 100644index 00000000000..1a0d10e7d0c--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-dynamic-resource.ts@@ -0,0 +1,2 @@+// Generated previews are App resources addressed by their stored resource ID.+export const generatedPreviewUrl = (imageId: string) => `/app-images/generated/${imageId}.webp`;diff --git a/packages/alint/fixtures/static-app-image-namespace/good-external-image.tsx b/packages/alint/fixtures/static-app-image-namespace/good-external-image.tsxnew file mode 100644index 00000000000..949163897be--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-external-image.tsx@@ -0,0 +1,3 @@+export const ProviderLogo = () => (+ <img alt="External provider" src="https://images.example.com/app-images/provider-logo.webp" />+);diff --git a/packages/alint/fixtures/static-app-image-namespace/good-image-helper.tsx b/packages/alint/fixtures/static-app-image-namespace/good-image-helper.tsxnew file mode 100644index 00000000000..81eb7c4d579--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-image-helper.tsx@@ -0,0 +1,3 @@+import { imageUrl } from '@lobechat/const';++export const ProductHero = () => <img alt="Product hero" src={imageUrl('product-hero.webp')} />;diff --git a/packages/alint/fixtures/static-app-image-namespace/good-legacy-compatibility.ts b/packages/alint/fixtures/static-app-image-namespace/good-legacy-compatibility.tsnew file mode 100644index 00000000000..6b025a05858--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-legacy-compatibility.ts@@ -0,0 +1,4 @@+export const legacyImageFallback = {+ destination: '/static/app-images/:path*',+ source: '/app-images/:path*',+};diff --git a/packages/alint/fixtures/static-app-image-namespace/good-legacy-copy.ts b/packages/alint/fixtures/static-app-image-namespace/good-legacy-copy.tsnew file mode 100644index 00000000000..b3a810d51c1--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-legacy-copy.ts@@ -0,0 +1,4 @@+import { cp } from 'node:fs/promises';++// Keep a compatibility copy for released clients while new callers use /static/app-images.+await cp('public/static/app-images', 'public/app-images', { recursive: true });diff --git a/packages/alint/fixtures/static-app-image-namespace/good-migration-note.ts b/packages/alint/fixtures/static-app-image-namespace/good-migration-note.tsnew file mode 100644index 00000000000..849495cbd4c--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-migration-note.ts@@ -0,0 +1,2 @@+export const migrationNote =+ 'Older clients request /app-images/product-hero.webp; keep the fallback during migration.';diff --git a/packages/alint/fixtures/static-app-image-namespace/good-static-copy.ts b/packages/alint/fixtures/static-app-image-namespace/good-static-copy.tsnew file mode 100644index 00000000000..ca7a693230c--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-static-copy.ts@@ -0,0 +1,3 @@+import { cp } from 'node:fs/promises';++await cp('public/static/app-images', 'dist/renderer/static/app-images', { recursive: true });diff --git a/packages/alint/fixtures/static-app-image-namespace/good-static-prefix.ts b/packages/alint/fixtures/static-app-image-namespace/good-static-prefix.tsnew file mode 100644index 00000000000..35d95c20405--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-static-prefix.ts@@ -0,0 +1,5 @@+export const productBanner = {+ backgroundImage: "url('/static/app-images/product-banner.webp')",+};++export const imageUrl = (filename: string) => `/static/app-images/${filename}`;diff --git a/packages/alint/fixtures/static-app-image-namespace/good-unknown-image-helper.ts b/packages/alint/fixtures/static-app-image-namespace/good-unknown-image-helper.tsnew file mode 100644index 00000000000..31249d13b71--- /dev/null+++ b/packages/alint/fixtures/static-app-image-namespace/good-unknown-image-helper.ts@@ -0,0 +1,2 @@+export const resolveImageUrl = (origin: string, filename: string) =>+ `${origin}/app-images/${filename}`;diff --git a/packages/alint/rules/static-app-image-namespace/rule.alint.toml b/packages/alint/rules/static-app-image-namespace/rule.alint.tomlnew file mode 100644index 00000000000..7c110436899--- /dev/null+++ b/packages/alint/rules/static-app-image-namespace/rule.alint.toml@@ -0,0 +1,22 @@+name = "static-app-image-namespace"+builtInAgent = "basic-structured"+instruction = """+Review one component, image URL helper, stylesheet or asset packaging file.++The imageUrl contract is: "Fixed product imagery is mirrored to the static origin; /app-images belongs to the App." Fixed product images shipped with the application use imageUrl(filename) or /static/app-images/..., while /app-images is an App-owned request namespace.++Do not report:+- imageUrl(...) callers or paths under /static/app-images, including packaging destinations;+- generated, uploaded or stored business resources requested by runtime resource IDs, even when their URLs end in an image extension;+- legacy compatibility rewrites, redirects, fallback readers or deliberate compatibility copies that preserve released clients' old URLs;+- external third-party image URLs, documentation, comments, test inputs or assertions;+- strings whose use as a fixed product image cannot be established in this file. A variable filename alone does not establish either a fixed product image or a generated resource.++Report only when this file visibly uses /app-images for a FIXED product asset shipped with the application:+1. An image source, CSS image URL, fixed-asset mapping or a helper explicitly responsible for fixed public product images constructs an old /app-images/... URL. This includes relative URLs and URLs joined to this application's origin.+2. Asset packaging or mirroring writes those fixed product images into public/app-images or dist/renderer/app-images as the current asset location, without an explicit legacy compatibility purpose.++Anchor once on the offending image source, CSS value, URL expression or destination argument. Name the fixed asset or helper and explain that it occupies the App-owned request namespace. Suggest imageUrl(filename) for ordinary callers, /static/app-images/... for literal URLs, or the corresponding static/app-images directory for packaging. Do not change dynamic App endpoints or remove legacy compatibility handling.++Use only supplied evidence. If the resource is dynamic, external, compatibility-only or its ownership is uncertain, return no finding. Do not treat every occurrence of /app-images as a violation.+"""diff --git a/src/libs/next/config/define-config.test.ts b/src/libs/next/config/define-config.test.tsindex 4ba4f833a48..66d77e2a17f 100644--- a/src/libs/next/config/define-config.test.ts+++ b/src/libs/next/config/define-config.test.ts@@ -1,3 +1,11 @@+import { readFileSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++import {+ getRewrittenUrl,+ unstable_getResponseFromNextConfig,+} from 'next/experimental/testing/server';import { afterEach, describe, expect, it } from 'vitest';import { defineConfig } from './define-config';@@ -14,6 +22,28 @@ describe('defineConfig', () => {else process.env.NEXT_PUBLIC_ASSET_PREFIX = originalLegacyPrefix;});+ it('keeps an old image URL working after its static file moves, preserving the query', async () => {+ const response = await unstable_getResponseFromNextConfig({+ nextConfig: defineConfig({}),+ url: 'https://app.example.com/app-images/agent-artwork-styles/line-art-reference.webp?v=2',+ });+ const rewritten = new URL(getRewrittenUrl(response)!);++ expect(rewritten.pathname).toBe(+ '/static/app-images/agent-artwork-styles/line-art-reference.webp',+ );+ expect(rewritten.search).toBe('?v=2');+ const bytes = readFileSync(+ path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ '../../../../public',+ rewritten.pathname.slice(1),+ ),+ );+ expect(bytes.toString('ascii', 0, 4)).toBe('RIFF');+ expect(bytes.toString('ascii', 8, 12)).toBe('WEBP');+ });+describe('headers', () => {// Agent Share visitor pages (`/agent/:slugOrId`) are link-visible private// content: the route-scoped noindex must come AFTER the globaldiff --git a/src/libs/next/config/define-config.ts b/src/libs/next/config/define-config.tsindex 6b82709e82e..9b0762ba4a5 100644--- a/src/libs/next/config/define-config.ts+++ b/src/libs/next/config/define-config.ts@@ -278,6 +278,10 @@ export function defineConfig(config: CustomNextConfig) {outputFileTracingIncludes: config.outputFileTracingIncludes,}),reactStrictMode: true,+ // Old clients keep their image URLs; App routes take precedence over this fallback.+ rewrites: async () => ({+ fallback: [{ destination: '/static/app-images/:path*', source: '/app-images/:path*' }],+ }),redirects: async () => [// Sitemap generation lives on the landing site; keep legacy app sitemap URLs crawlable.{