feat(operations): add shared Operation layer for agent capabilities (#494)

Introduce @shumai/operations (pure definitions: Zod schemas, metadata,
CLI hints) and @shumai/core/src/operations (implementOperation and the
runOperation pipeline: validate, authorize, prepare, execute, validate
output, audit).

Migrate list_assets, create_folder, rename_asset, move_assets and
delete_asset to Operations, and add list_projects. The agent now builds
these tools from the registry, and the folder create/rename, file
rename and reparent routes call the same Operations.

Audit logs gain a nullable via column recording the surface. A lint
rule keeps the Prisma client out of Operation implementations.
This commit is contained in:
Yiling-J
2026-10-27 08:09:09 +08:00
committed by GitHub
parent 47ee794ae4
commit 76057ccd21
65 changed files with 2372 additions and 1149 deletions
@@ -0,0 +1,25 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema } from '../schemas'
export const createFolder = defineOperation({
name: 'create_folder',
title: 'Create Folder',
description: 'Create a new folder in a specified parent folder.',
input: z.object({
parent: z
.string()
.min(1)
.describe('The parent folder ID under which to create the new folder.'),
name: z.string().min(1).describe('The name of the new folder to create.'),
}),
output: assetSummarySchema,
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false },
cli: {
command: ['mkdir'],
positional: ['name'],
flags: { parent: ['-p', '--parent'] },
format: (output) => `Created folder with ID: ${output.id}`,
},
})
@@ -0,0 +1,24 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const deleteAsset = defineOperation({
name: 'delete_asset',
title: 'Delete Asset',
description:
'Delete a single asset (file or folder) by its ID. Can only delete one asset at a time. ' +
'Deleted assets are moved to the project trash.',
input: z.object({
assetId: z.string().min(1).describe('The ID of the single asset (file or folder) to delete.'),
}),
output: z.object({
deletedAssetId: z.string(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: true },
cli: {
command: ['delete'],
aliases: ['rm'],
positional: ['assetId'],
format: (output) => `Deleted asset ${output.deletedAssetId}`,
},
})
@@ -0,0 +1,40 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema, MAX_PAGE_SIZE, pageInfoSchema } from '../schemas'
export const listAssets = defineOperation({
name: 'list_assets',
title: 'List Assets',
description:
'List the assets (files and folders) inside a parent folder. Results are paginated: when ' +
'pageInfo.hasNextPage is true, call again with after set to pageInfo.endCursor.',
input: z.object({
parent: z.string().min(1).describe('The parent folder ID to list assets from.'),
type: z
.enum(['file', 'folder', 'all'])
.optional()
.describe("Filter assets by type: 'file', 'folder', or 'all'. Default is 'all'."),
first: z
.number()
.int()
.min(1)
.max(MAX_PAGE_SIZE)
.optional()
.describe(`Maximum number of assets to return. Default is 20, maximum ${MAX_PAGE_SIZE}.`),
after: z
.string()
.optional()
.describe('Cursor from a previous response (pageInfo.endCursor) to fetch the next page.'),
}),
output: z.object({
data: z.array(assetSummarySchema),
pageInfo: pageInfoSchema,
total: z.number(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['ls'],
flags: { parent: ['-p', '--parent'] },
},
})
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const moveAssets = defineOperation({
name: 'move_assets',
title: 'Move Assets',
description:
'Move one or more assets (files or folders) to a specified parent folder. Note: All assets ' +
'to be moved must belong to the same current parent folder.',
input: z.object({
assetIds: z
.array(z.string().min(1))
.min(1)
.describe(
'The IDs of the assets to move. All assets must belong to the same parent folder. At least one asset ID is required.',
),
newParentId: z
.string()
.min(1)
.describe('The destination parent folder ID to move the assets into.'),
}),
output: z.object({
movedAssetIds: z.array(z.string()),
newParentId: z.string(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['move'],
aliases: ['mv'],
positional: ['assetIds'],
flags: { newParentId: ['-p', '--parent'] },
format: (output) =>
`Moved ${output.movedAssetIds.length} asset(s) to parent ${output.newParentId}`,
},
})
@@ -0,0 +1,21 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema } from '../schemas'
export const renameAsset = defineOperation({
name: 'rename_asset',
title: 'Rename Asset',
description: 'Rename an existing asset (file or folder).',
input: z.object({
assetId: z.string().min(1).describe('The ID of the asset (file or folder) to rename.'),
name: z.string().min(1).describe('The new name for the asset.'),
}),
output: assetSummarySchema,
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['rename'],
positional: ['assetId', 'name'],
format: (output) => `Renamed asset ${output.id} to "${output.name}"`,
},
})