MCPcopy Index your code
hub / github.com/callstack/agent-device / runReplayScriptFile

Function runReplayScriptFile

src/daemon/handlers/session-replay-runtime.ts:33–204  ·  view source on GitHub ↗
(params: {
  req: DaemonRequest;
  sessionName: string;
  logPath: string;
  sessionStore: SessionStore;
  tracePath?: string;
  invoke: DaemonInvokeFn;
})

Source from the content-addressed store, hash-verified

31
32// fallow-ignore-next-line complexity
33export async function runReplayScriptFile(params: {
34 req: DaemonRequest;
35 sessionName: string;
36 logPath: string;
37 sessionStore: SessionStore;
38 tracePath?: string;
39 invoke: DaemonInvokeFn;
40}): Promise<DaemonResponse> {
41 const { req, sessionName, logPath, sessionStore, tracePath, invoke } = params;
42 const filePath = req.positionals?.[0];
43 if (!filePath) {
44 return errorResponse('INVALID_ARGS', 'replay requires a path');
45 }
46
47 let resolved = '';
48 const artifactPaths = new Set<string>();
49 try {
50 resolved = SessionStore.expandHome(filePath, req.meta?.cwd);
51 const script = fs.readFileSync(resolved, 'utf8');
52 const firstNonWhitespace = script.trimStart()[0];
53 if (firstNonWhitespace === '{' || firstNonWhitespace === '[') {
54 return errorResponse(
55 'INVALID_ARGS',
56 'replay accepts .ad script files. JSON replay payloads are no longer supported.',
57 );
58 }
59
60 const parsed = parseReplayInput(script, req.flags, { sourcePath: resolved });
61 const metadata = parsed.metadata;
62 const replayReq =
63 metadata.platform || metadata.target
64 ? { ...req, flags: buildReplayMetadataFlags(req.flags, metadata) }
65 : req;
66 const actions = parsed.actions;
67 const actionLines = parsed.actionLines;
68 if (req.flags?.replayUpdate === true && parsed.updateUnsupportedMessage) {
69 return errorResponse('INVALID_ARGS', parsed.updateUnsupportedMessage);
70 }
71 if (req.flags?.replayUpdate === true && metadata.env && Object.keys(metadata.env).length > 0) {
72 return errorResponse(
73 'INVALID_ARGS',
74 'replay -u does not yet preserve env directives. Temporarily remove the env lines, run replay -u, then restore them.',
75 );
76 }
77 if (req.flags?.replayUpdate === true && actionsContainInterpolation(actions)) {
78 return errorResponse(
79 'INVALID_ARGS',
80 'replay -u does not yet preserve ${VAR} substitutions. Resolve or inline the variables before running with -u.',
81 );
82 }
83 const scope = buildReplayVarScope({
84 builtins: buildReplayBuiltinVars({
85 req: replayReq,
86 sessionName,
87 metadata,
88 resolvedPath: resolved,
89 }),
90 fileEnv: metadata.env,

Callers 3

runReplayFixtureFunction · 0.90

Calls 15

errorResponseFunction · 0.90
parseReplayInputFunction · 0.90
buildReplayVarScopeFunction · 0.90
collectReplayShellEnvFunction · 0.90
readReplayShellEnvSourceFunction · 0.90
parseReplayCliEnvEntriesFunction · 0.90
readReplayCliEnvEntriesFunction · 0.90
invokeReplayActionFunction · 0.90
healReplayActionFunction · 0.90
writeReplayScriptFunction · 0.90
asAppErrorFunction · 0.90

Tested by 1

runReplayFixtureFunction · 0.72