Skip to content

🀯 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.

πŸ› fix(cli): allow anonymous acceptance install (#20228)

Bryanf50ae2e55d5b
diff --git a/apps/cli/README.md b/apps/cli/README.md
index 5b56e0b73a2..8f2e0d26127 100644
--- a/apps/cli/README.md
+++ b/apps/cli/README.md
@@ -5,14 +5,21 @@ LobeHub command-line interface.
## Acceptance skill
The acceptance skill is maintained in [lobehub/acceptance](https://github.com/lobehub/acceptance).
-After signing in, install or update from the repository's default branch:
+Install from the repository's default branch:
```bash
-lh login
lh acceptance install
+```
+
+Update the installed skill:
+
+```bash
lh acceptance update
```
+Creating acceptances and publishing reports require authentication. Run `lh login`
+before using those commands.
+
This selects the same source as `npx skills add lobehub/acceptance --skill acceptance`.
Changes merged into the default branch are available on the next install or
update, without a tag, GitHub Release, or skill-version bump. Installed files
@@ -25,9 +32,8 @@ skill from that snapshot before files are changed. `--json` reports the exact
source commit and the version declared in `SKILL.md`; that version is a label,
not the selector for default updates.
-All CLI versions use the authenticated `verify.getSkillBundle` endpoint. After
-the server adapter is deployed, already-published CLIs follow the default branch
-without upgrading. Creating acceptances and publishing reports use the same login.
+Use an up-to-date CLI and LobeHub server. Older servers may return `401` during
+installation and need to be upgraded.
To select an existing version tag explicitly, use `lh acceptance update --skill-version 0.5.0` (requires the updated CLI and server), or the equivalent
[tagged skill source](https://github.com/lobehub/acceptance/tree/v0.5.0/skills/acceptance)
diff --git a/apps/cli/src/api/client.test.ts b/apps/cli/src/api/client.test.ts
index f9d789c0728..72bb8bf5617 100644
--- a/apps/cli/src/api/client.test.ts
+++ b/apps/cli/src/api/client.test.ts
@@ -59,6 +59,29 @@ describe('api/client workspace scoping', () => {
expect(headersOfLastLink()).toMatchObject({ 'Oidc-Auth': 'renewed-jwt' });
});
+ it('creates an anonymous Lambda client without resolving credentials or workspace headers', async () => {
+ delete process.env.LOBEHUB_JWT;
+ process.env.LOBEHUB_WORKSPACE_ID = 'workspace-1';
+ const { getValidToken } = await import('../auth/refresh');
+ const { createPublicLambdaClient } = await import('./client');
+
+ createPublicLambdaClient();
+
+ expect(getValidToken).not.toHaveBeenCalled();
+ expect(mockHttpLink).toHaveBeenCalledWith(
+ expect.objectContaining({ url: 'https://app.lobehub.com/trpc/lambda' }),
+ );
+ expect(headersOfLastLink()).toBeUndefined();
+ });
+
+ it('does not attach an environment credential to public downloads', async () => {
+ const { createPublicLambdaClient } = await import('./client');
+
+ createPublicLambdaClient();
+
+ expect(headersOfLastLink()).toBeUndefined();
+ });
+
// The tools router is workspace aware like lambda; without the header every
// `lh search` ran against personal scope and billed the personal budget.
it('scopes the tools client to the run workspace', async () => {
diff --git a/apps/cli/src/api/client.ts b/apps/cli/src/api/client.ts
index cfe4b8021ca..f2b24ae9914 100644
--- a/apps/cli/src/api/client.ts
+++ b/apps/cli/src/api/client.ts
@@ -90,6 +90,18 @@ export async function getTrpcClient(workspaceId?: string): Promise<TrpcClient> {
return client;
}
+/** Create an anonymous client for public Lambda procedures, without credential discovery. */
+export function createPublicLambdaClient(): TrpcClient {
+ return createTRPCClient<LambdaRouter>({
+ links: [
+ httpLink({
+ transformer: superjson,
+ url: `${resolveServerUrl()}/trpc/lambda`,
+ }),
+ ],
+ });
+}
+
/**
* Build a Lambda tRPC client from an already-resolved auth context, without
* re-running credential discovery. Use this when the caller already holds a
diff --git a/apps/cli/src/commands/acceptanceInstall.test.ts b/apps/cli/src/commands/acceptanceInstall.test.ts
index 6273b0c019d..673f97bb4b8 100644
--- a/apps/cli/src/commands/acceptanceInstall.test.ts
+++ b/apps/cli/src/commands/acceptanceInstall.test.ts
@@ -5,11 +5,14 @@ import path from 'node:path';
import { Command } from 'commander';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { getTrpcClient } from '../api/client';
+import { createPublicLambdaClient, getTrpcClient } from '../api/client';
import { registerVerifyCommand } from './verify';
import { registerAcceptanceCommands } from './verifyAcceptance';
-vi.mock('../api/client', () => ({ getTrpcClient: vi.fn() }));
+vi.mock('../api/client', () => ({
+ createPublicLambdaClient: vi.fn(),
+ getTrpcClient: vi.fn(),
+}));
const content = '---\nname: acceptance\nmetadata:\n version: "0.5.0"\n---\n# Acceptance\n';
const bundle = {
@@ -46,6 +49,11 @@ describe('acceptance skill installation', () => {
directory = await mkdtemp(path.join(tmpdir(), 'acceptance-distribution-'));
vi.spyOn(console, 'log').mockImplementation(() => {});
query.mockReset().mockResolvedValue(bundle);
+ vi.mocked(createPublicLambdaClient)
+ .mockReset()
+ .mockReturnValue({
+ verify: { getSkillBundle: { query } },
+ } as unknown as ReturnType<typeof createPublicLambdaClient>);
vi.mocked(getTrpcClient)
.mockReset()
.mockResolvedValue({
@@ -58,24 +66,29 @@ describe('acceptance skill installation', () => {
await rm(directory, { force: true, recursive: true });
});
- it('installs every source resource through the authenticated server and wires Claude', async () => {
- await mkdir(path.join(directory, '.claude'));
+ it.each(['install', 'update'])(
+ '%s downloads every source resource without authentication and wires Claude',
+ async (command) => {
+ await mkdir(path.join(directory, '.claude'));
- await run('install');
+ vi.mocked(getTrpcClient).mockRejectedValue(new Error('Not authenticated'));
+ await run(command);
- const skillDir = path.join(directory, '.agents/skills/acceptance');
- expect(await readFile(path.join(skillDir, 'SKILL.md'), 'utf8')).toBe(content);
- for (const [file, expected] of Object.entries(bundle.files)) {
- expect(await readFile(path.join(skillDir, file), 'utf8')).toBe(expected);
- }
- expect(await readlink(path.join(directory, '.claude/skills'))).toBe('../.agents/skills');
- expect(getTrpcClient).toHaveBeenCalled();
- expect(query).toHaveBeenCalledWith({ identifier: 'acceptance' });
- expect(JSON.parse(vi.mocked(console.log).mock.calls.at(-1)![0] as string)).toMatchObject({
- skill: 'acceptance',
- version: '0.5.0',
- });
- });
+ const skillDir = path.join(directory, '.agents/skills/acceptance');
+ expect(await readFile(path.join(skillDir, 'SKILL.md'), 'utf8')).toBe(content);
+ for (const [file, expected] of Object.entries(bundle.files)) {
+ expect(await readFile(path.join(skillDir, file), 'utf8')).toBe(expected);
+ }
+ expect(await readlink(path.join(directory, '.claude/skills'))).toBe('../.agents/skills');
+ expect(createPublicLambdaClient).toHaveBeenCalled();
+ expect(getTrpcClient).not.toHaveBeenCalled();
+ expect(query).toHaveBeenCalledWith({ identifier: 'acceptance' });
+ expect(JSON.parse(vi.mocked(console.log).mock.calls.at(-1)![0] as string)).toMatchObject({
+ skill: 'acceptance',
+ version: '0.5.0',
+ });
+ },
+ );
it('emits links[] plus the legacy link alias for the Claude result', async () => {
await mkdir(path.join(directory, '.claude'));
@@ -113,15 +126,18 @@ describe('acceptance skill installation', () => {
await mkdir(skillDir, { recursive: true });
await writeFile(path.join(skillDir, 'SKILL.md'), 'existing skill');
await writeFile(path.join(skillDir, 'old.md'), 'existing resource');
+ vi.mocked(getTrpcClient).mockRejectedValue(new Error('Not authenticated'));
query.mockRejectedValueOnce(new Error('Download unavailable'));
await expect(run('update')).rejects.toThrow('Download unavailable');
expect(await readFile(path.join(skillDir, 'SKILL.md'), 'utf8')).toBe('existing skill');
expect(await readFile(path.join(skillDir, 'old.md'), 'utf8')).toBe('existing resource');
+ expect(getTrpcClient).not.toHaveBeenCalled();
});
it('preserves existing files during install, then replaces them and removes stale files on update', async () => {
+ vi.mocked(getTrpcClient).mockRejectedValue(new Error('Not authenticated'));
await run('install');
const skillDir = path.join(directory, '.agents/skills/acceptance');
await writeFile(path.join(skillDir, 'SKILL.md'), 'local copy');
@@ -170,18 +186,23 @@ describe('acceptance skill installation', () => {
content,
);
expect(getTrpcClient).toHaveBeenCalled();
+ expect(createPublicLambdaClient).not.toHaveBeenCalled();
expect(query).toHaveBeenCalledWith({ identifier: 'verify' });
});
- it('keeps login required and preserves installed files when authentication fails', async () => {
- await run('install');
- vi.mocked(getTrpcClient).mockRejectedValueOnce(new Error('Not authenticated'));
+ it.each([
+ ['create', '--requirement', 'Verify the delivery'],
+ ['run', 'list'],
+ ])('keeps authentication required for acceptance %s', async (...args) => {
+ const program = new Command().exitOverride();
+ registerAcceptanceCommands(program);
+ vi.mocked(getTrpcClient).mockRejectedValue(new Error('Not authenticated'));
- await expect(run('update')).rejects.toThrow('Not authenticated');
- expect(await readFile(path.join(directory, '.agents/skills/acceptance/SKILL.md'), 'utf8')).toBe(
- content,
- );
- expect(query).toHaveBeenCalledTimes(1);
+ await expect(
+ program.parseAsync(['node', 'lh', 'acceptance', ...args, '--json']),
+ ).rejects.toThrow('Not authenticated');
+ expect(createPublicLambdaClient).not.toHaveBeenCalled();
+ expect(query).not.toHaveBeenCalled();
});
it('rejects a matching tag whose declared version differs from the requested version', async () => {
diff --git a/apps/cli/src/commands/acceptanceRun.ts b/apps/cli/src/commands/acceptanceRun.ts
index 26b13f49bab..4781c7e5a74 100644
--- a/apps/cli/src/commands/acceptanceRun.ts
+++ b/apps/cli/src/commands/acceptanceRun.ts
@@ -7,7 +7,8 @@ import type { VerifyAgentPlanConfig, VerifyCheckItem } from '@lobechat/types';
import type { Command } from 'commander';
import pc from 'picocolors';
-import { getTrpcClient } from '../api/client';
+import type { TrpcClient } from '../api/client';
+import { createPublicLambdaClient, getTrpcClient } from '../api/client';
import { resolveWorkspaceId } from '../api/workspace';
import { resolveServerUrl } from '../settings';
import { ensureAcceptanceDirIgnored, ensureAcceptanceDirIgnoredFor } from '../utils/acceptanceDir';
@@ -74,8 +75,7 @@ const listMaterializedFiles = (directory: string): string[] => {
});
};
-async function installAction(options: InstallOptions): Promise<void> {
- const client = await getTrpcClient();
+async function installAction(options: InstallOptions, client: TrpcClient): Promise<void> {
const version = options.skillVersion?.replace(/^v/, '');
const bundle = await client.verify.getSkillBundle.query({
identifier: options.skill,
@@ -1197,13 +1197,15 @@ export function attachAcceptanceRunCommands(acceptance: Command): void {
acceptance
.command('install')
.description('Install the latest acceptance skill source into .agents/skills/acceptance'),
- ).action(installAction);
+ ).action((options: InstallOptions) => installAction(options, createPublicLambdaClient()));
withInstallOptions(
acceptance
.command('update')
.description('Download the latest skill source, replacing its files and re-wiring harnesses'),
- ).action((options: InstallOptions) => installAction({ ...options, force: true }));
+ ).action((options: InstallOptions) =>
+ installAction({ ...options, force: true }, createPublicLambdaClient()),
+ );
const run = acceptance
.command('run')
@@ -1313,14 +1315,14 @@ export function attachDeprecatedVerifyRunAliases(verify: Command): void {
verify.command('init').description('Deprecated β€” use `lh acceptance install`'),
),
'lh acceptance install',
- ).action(installAction);
+ ).action(async (options: InstallOptions) => installAction(options, await getTrpcClient()));
deprecate(
withInstallOptions(
verify.command('install').description('Deprecated β€” use `lh acceptance install`'),
),
'lh acceptance install',
- ).action(installAction);
+ ).action(async (options: InstallOptions) => installAction(options, await getTrpcClient()));
deprecate(
withIngestReportOptions(
diff --git a/apps/server/src/routers/lambda/__tests__/verify.test.ts b/apps/server/src/routers/lambda/__tests__/verify.test.ts
index e89ff6c5ad4..5a4244d7a49 100644
--- a/apps/server/src/routers/lambda/__tests__/verify.test.ts
+++ b/apps/server/src/routers/lambda/__tests__/verify.test.ts
@@ -155,22 +155,40 @@ describe('verifyRouter', () => {
},
);
- it('keeps the old authentication requirement and unknown-identifier response', async () => {
+ it.each(['acceptance', 'verify'])('serves %s without authentication', async (identifier) => {
+ mockSnapshot();
+ expect(await createPublicCaller().getSkillBundle({ identifier })).toEqual(snapshot);
+ });
+
+ it('rejects unknown identifiers without fetching upstream', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch');
await expect(
- createPublicCaller().getSkillBundle({ identifier: 'acceptance' }),
- ).rejects.toMatchObject({ code: 'UNAUTHORIZED' });
- await expect(createCaller().getSkillBundle({ identifier: 'unknown' })).rejects.toMatchObject({
+ createPublicCaller().getSkillBundle({ identifier: 'unknown' }),
+ ).rejects.toMatchObject({
code: 'NOT_FOUND',
});
expect(fetchSpy).not.toHaveBeenCalled();
});
+ it('keeps private verification reads and writes authenticated', async () => {
+ await expect(
+ createPublicCaller().getVerifyState({ operationId: 'operation-1' }),
+ ).rejects.toMatchObject({
+ code: 'UNAUTHORIZED',
+ });
+ await expect(
+ createPublicCaller().skipPlan({ operationId: 'operation-1' }),
+ ).rejects.toMatchObject({
+ code: 'UNAUTHORIZED',
+ });
+ expect(modelMocks.getServerDB).not.toHaveBeenCalled();
+ });
+
it('resolves an explicitly requested tag for newer clients', async () => {
const fetchSpy = mockSnapshot();
expect(
- await createCaller().getSkillBundle({ identifier: 'acceptance', version: 'v0.5.0' }),
+ await createPublicCaller().getSkillBundle({ identifier: 'acceptance', version: 'v0.5.0' }),
).toEqual({ ...snapshot, source: { ...snapshot.source, ref: 'v0.5.0' } });
expect(fetchSpy).toHaveBeenCalledWith(
'https://api.github.com/repos/lobehub/acceptance/commits/v0.5.0',
@@ -178,11 +196,13 @@ describe('verifyRouter', () => {
);
});
- it('does not initialize reporting services to download an authenticated public skill', async () => {
+ it('does not initialize reporting services to download a public skill', async () => {
mockSnapshot();
modelMocks.getServerDB.mockRejectedValueOnce(new Error('Reporting database unavailable'));
- expect(await createCaller().getSkillBundle({ identifier: 'acceptance' })).toEqual(snapshot);
+ expect(await createPublicCaller().getSkillBundle({ identifier: 'acceptance' })).toEqual(
+ snapshot,
+ );
expect(modelMocks.getServerDB).not.toHaveBeenCalled();
modelMocks.getServerDB.mockReset().mockResolvedValue({});
});
diff --git a/apps/server/src/routers/lambda/verify.ts b/apps/server/src/routers/lambda/verify.ts
index b683bce2a8f..e83083e616c 100644
--- a/apps/server/src/routers/lambda/verify.ts
+++ b/apps/server/src/routers/lambda/verify.ts
@@ -668,10 +668,10 @@ export const verifyRouter = router({
/**
* Serve a pullable skill bundle (`SKILL.md` + inline resource files) by
- * identifier. Keep the authenticated contract and legacy alias while sourcing
+ * identifier without authentication. Keep the legacy alias while sourcing
* all installers from the upstream default branch (or an explicitly selected tag).
*/
- getSkillBundle: wsCompatProcedure
+ getSkillBundle: publicProcedure
.input(
z.object({
identifier: z.string(),