🤯 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
✨ feat(cli): add lh artifact unpublish (#22103)
Arvin Xu73f7f1bfee62
diff --git a/apps/cli/README.md b/apps/cli/README.mdindex 54c4815d900..927f82d4104 100644--- a/apps/cli/README.md+++ b/apps/cli/README.md@@ -19,6 +19,9 @@ lh artifact publish ./report.html --json# Create a separate Canvas and bind future publishes to itlh artifact publish ./report.html --new --json++# Take a published artifact offline (the deployment and its releases are kept)+lh artifact unpublish ./report.html --json```Bindings and pending operations live in the project's `.lobehub/artifacts.json`.diff --git a/apps/cli/src/commands/artifact.test.ts b/apps/cli/src/commands/artifact.test.tsindex 28b2b0662cd..d91475c375f 100644--- a/apps/cli/src/commands/artifact.test.ts+++ b/apps/cli/src/commands/artifact.test.ts@@ -13,6 +13,7 @@ const { mockTrpcClient } = vi.hoisted(() => ({deployments: {commitWorkspaceHtmlUpload: { mutate: vi.fn() },prepareWorkspaceHtmlUpload: { mutate: vi.fn() },+ unpublish: { mutate: vi.fn() },},},},@@ -257,4 +258,69 @@ describe('artifact publish', () => {expect(readManifest().artifacts['index.html']).toEqual({ deploymentId: 'dep-1' });});});++ describe('unpublishing', () => {+ const runUnpublish = async (...args: string[]) => {+ const program = new Command();+ program.exitOverride();+ registerArtifactCommand(program);+ await program.parseAsync(['node', 'lh', 'artifact', 'unpublish', ...args]);+ };++ const boundFile = () => path.join(workingDirectory, 'index.html');++ beforeEach(() => {+ fs.writeFileSync(boundFile(), '<title>Bound</title>');+ mockTrpcClient.market.deployments.unpublish.mutate+ .mockReset()+ .mockResolvedValue({ data: { id: 'dep-bound', status: 'unpublished', title: 'Bound' } });+ });++ it('takes the deployment bound to the file offline', async () => {+ writeManifest({ 'index.html': { deploymentId: 'dep-bound' } });++ await runUnpublish(boundFile());++ expect(mockTrpcClient.market.deployments.unpublish.mutate).toHaveBeenCalledWith({+ id: 'dep-bound',+ });+ // Kept on purpose: republishing the same file reactivates this deployment.+ expect(readManifest().artifacts['index.html']).toEqual({ deploymentId: 'dep-bound' });+ });++ it('--deployment targets an id without a file', async () => {+ await runUnpublish('--deployment', 'dep-oneoff');++ expect(mockTrpcClient.market.deployments.unpublish.mutate).toHaveBeenCalledWith({+ id: 'dep-oneoff',+ });+ });++ it('refuses to guess when neither a file nor --deployment is given', async () => {+ await runUnpublish();++ expect(exitSpy).toHaveBeenCalledWith(1);+ expect(mockTrpcClient.market.deployments.unpublish.mutate).not.toHaveBeenCalled();+ });++ it('refuses a file with no bound deployment', async () => {+ writeManifest({});++ await runUnpublish(boundFile());++ expect(exitSpy).toHaveBeenCalledWith(1);+ expect(mockTrpcClient.market.deployments.unpublish.mutate).not.toHaveBeenCalled();+ });++ it('reports a server failure instead of claiming success', async () => {+ writeManifest({ 'index.html': { deploymentId: 'dep-gone' } });+ mockTrpcClient.market.deployments.unpublish.mutate.mockRejectedValueOnce(+ new Error('Deployment not found'),+ );++ await runUnpublish(boundFile());++ expect(exitSpy).toHaveBeenCalledWith(1);+ });+ });});diff --git a/apps/cli/src/commands/artifact.ts b/apps/cli/src/commands/artifact.tsindex 95931e356fc..743007a2a79 100644--- a/apps/cli/src/commands/artifact.ts+++ b/apps/cli/src/commands/artifact.ts@@ -37,6 +37,7 @@ interface DeploymentRecord {slug?: string;status?: string;subdomainLabel?: string | null;+ title?: string | null;}/**@@ -52,6 +53,9 @@ interface MarketDeploymentClient {commitWorkspaceHtmlUpload: {mutate: (input: { uploadId: string }) => Promise<{ data: DeploymentRecord }>;};+ unpublish: {+ mutate: (input: { id: string }) => Promise<{ data: DeploymentRecord }>;+ };prepareWorkspaceHtmlUpload: {mutate: (input: {artifactIdentifier: string;@@ -349,4 +353,57 @@ export function registerArtifactCommand(program: Command) {console.log(` Deployment: ${pc.dim(result.data.id ?? '')}`);},);++ artifact+ .command('unpublish [file]')+ .description('Take a published artifact offline, keeping the deployment and its releases')+ .option('--deployment <id>', 'Unpublish this deployment instead of the one bound to the file')+ .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')+ .action(+ async (+ file: string | undefined,+ options: { deployment?: string; json?: string | boolean },+ ) => {+ let deploymentId = options.deployment;++ if (!deploymentId) {+ if (!file) {+ fail('Pass the published file, or --deployment <id>.');+ return;+ }++ const manifest = resolveManifest(path.resolve(file), process.cwd());+ deploymentId = readBinding(manifest).deploymentId;+ if (!deploymentId) {+ fail(+ `${file} is not bound to a deployment. Pass --deployment <id> to unpublish one.`,+ );+ return;+ }+ }++ const deployments = deploymentClient(await getTrpcClient()).market.deployments;+ let data: DeploymentRecord;+ try {+ ({ data } = await deployments.unpublish.mutate({ id: deploymentId }));+ } catch (error) {+ if (options.json !== undefined)+ outputJson({ error: formatError(error), success: false });+ fail(formatError(error));+ return;+ }++ if (options.json !== undefined) {+ outputJson(data, typeof options.json === 'string' ? options.json : undefined);+ return;+ }++ console.log(+ `${pc.green('✓')} Unpublished ${pc.bold(data.title ?? deploymentId)} (${deploymentId})`,+ );+ // The record survives so republishing the same file brings the same+ // address back, which is also why this is not a delete.+ if (file) console.log(` Republish: ${pc.dim(`lh artifact publish ${file}`)}`);+ },+ );}diff --git a/packages/builtin-skills/src/lobehub/references/artifact.ts b/packages/builtin-skills/src/lobehub/references/artifact.tsindex f423d7cb426..ca4974d6605 100644--- a/packages/builtin-skills/src/lobehub/references/artifact.ts+++ b/packages/builtin-skills/src/lobehub/references/artifact.ts@@ -4,6 +4,7 @@ const content = `# lh artifact - Publish local HTML and Canvas- \`lh artifact guide canvas\`: read the shared Canvas component and generation rules before authoring a Canvas.- \`lh artifact publish <file> [--type html|canvas] [--root <dir>] [--title <title>] [--slug <name>] [--new | --deployment <id>] [--json]\`: publish a public artifact.+- \`lh artifact unpublish [file] [--deployment <id>] [--json]\`: take a published artifact offline.Ordinary HTML is the default for unbound files and bundles local resources allowedby --root. Canvas requires --type canvas on its first publish and accepts a@@ -30,6 +31,12 @@ Canvas JSON failures include the saved canvasId, workId and version when known;an unsuccessful publish must never be reported as successful. Only a successfulpublish returns a publicUrl. A Canvas is also saved as a Work with version history;it does not require a topic or agent and uses the current authenticated scope.++Unpublish takes the site offline and keeps the deployment and its release history,+so publishing the same file again reactivates the same address. There is no hard+delete, and the binding stays in .lobehub/artifacts.json on purpose. With a file,+the bound deployment is used; --deployment names the id for this run. Unpublishing+is idempotent, so a retry after a lost response needs no recovery state.`;export const artifact = content;