files.ts 700 B

12345678910111213141516171819
  1. import { relative } from 'path'
  2. import type { ToolUseContext } from '../../Tool.js'
  3. import type { LocalCommandResult } from '../../types/command.js'
  4. import { getCwd } from '../../utils/cwd.js'
  5. import { cacheKeys } from '../../utils/fileStateCache.js'
  6. export async function call(
  7. _args: string,
  8. context: ToolUseContext,
  9. ): Promise<LocalCommandResult> {
  10. const files = context.readFileState ? cacheKeys(context.readFileState) : []
  11. if (files.length === 0) {
  12. return { type: 'text' as const, value: '上下文中没有文件' }
  13. }
  14. const fileList = files.map(file => relative(getCwd(), file)).join('\n')
  15. return { type: 'text' as const, value: `上下文中的文件:\n${fileList}` }
  16. }