snapshot-shell-path.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /** Exact recorded shell-command path translation; execution and reported outcomes remain real. */
  2. import type { Context } from '@deepseek-ai/cordis'
  3. import type {} from '@deepseek-ai/dsh-shell'
  4. export const name = 'snapshot-shell-path'
  5. export const inject = ['shell']
  6. /** One recorded command and its isolated live filesystem target. */
  7. export interface Config {
  8. command: string
  9. recordedPath: string
  10. livePath: string
  11. }
  12. /**
  13. * Translate one exact fixture command after tool logging and approval.
  14. * @param ctx - profile context with its real shell executor.
  15. * @param config - recorded command/path and allocated live target.
  16. */
  17. export function apply(ctx: Context, config: Config): void {
  18. const shell = ctx.shell
  19. // oxlint-disable-next-line typescript/unbound-method -- preserve method identity for restoration; calls bind the receiver.
  20. const run = shell.run
  21. ctx.effect(() => {
  22. shell.run = spec => run.call(shell, spec.command === config.command
  23. ? { ...spec, command: spec.command.replaceAll(config.recordedPath, "'" + config.livePath.replaceAll("'", "'\"'\"'") + "'") }
  24. : spec)
  25. return () => { shell.run = run }
  26. })
  27. }