1- import fs from 'node:fs' ;
21import { AppError } from '@agent-device/kernel/errors' ;
32import type { SessionAction } from '@agent-device/contracts/session' ;
43import {
@@ -12,7 +11,7 @@ import { resolveReplayEntryIndex, type PendingRecordAndHeal } from './resume.ts'
1211
1312/**
1413 * #1478 P5 stage C2b: the read-only `.ad` inspection façade. Moved out of
15- * `session-replay-runtime.ts`'s old `parseReplayScript` (the fs read + the
14+ * `session-replay-runtime.ts`'s old `parseReplayScript` (the
1615 * legacy-JSON-payload rejection it guarded) plus the `parseReplayInput`
1716 * composition (`src/compat/replay-input.ts`) it fed into — this is the same
1817 * `parseReplayScriptDetailed` + `readReplayScriptMetadata` pair
@@ -50,12 +49,14 @@ export type AdReplayManifest = Readonly<{
5049export type AdReplayDigestFlags = Readonly < { platform ?: string ; target ?: string } > ;
5150
5251/**
53- * Reads `sourcePath` once and returns its parsed actions/line table, header
54- * metadata, plan digest, and resume-index resolver. Throws
52+ * Parses one `.ad` script's TEXT and returns its actions/line table, header
53+ * metadata, plan digest, and resume-index resolver. Takes the script itself,
54+ * never a path: #1802 made the CALLER read every script file a replay run
55+ * needs, so nothing below this façade opens a file. Throws
5556 * `AppError('INVALID_ARGS', …)` for the one source format `.ad` replay no
5657 * longer accepts — a legacy JSON replay payload — matching the daemon's
5758 * prior explicit rejection exactly. Callers do not need to check for this
58- * case separately: `runReplayScriptFile `'s top-level catch (`asAppError`)
59+ * case separately: `runReplayScriptSource `'s top-level catch (`asAppError`)
5960 * maps a thrown `AppError` straight to the same `errorResponse` the old
6061 * explicit branch built, so this is not a behavior change, only where the
6162 * check lives.
@@ -67,10 +68,9 @@ export type AdReplayDigestFlags = Readonly<{ platform?: string; target?: string
6768 * `open` wins; absent that, the `context platform=`/`target=` header line.
6869 */
6970export function inspectAdReplay (
70- sourcePath : string ,
71+ script : string ,
7172 digestFlags ?: AdReplayDigestFlags ,
7273) : AdReplayManifest {
73- const script = fs . readFileSync ( sourcePath , 'utf8' ) ;
7474 const firstNonWhitespace = script . trimStart ( ) [ 0 ] ;
7575 if ( firstNonWhitespace === '{' || firstNonWhitespace === '[' ) {
7676 throw new AppError (
0 commit comments