# AI17 source-only workflow reproduction. Base R + bundled tools only.
# Rscript actual-source-study.R [native_source_directory] [output_directory]
# Reads three native CSVs and original MovieLens README; no JS/model/answers.
# The inherited SHA256 primitive below hashes only the declared short ASCII
# selection messages. Native files are checked with bundled tools::md5sum;
# their independently bound SHA256 identifiers are declared in provenance.
# Exact rational operations below are intentionally bounded to integer
# intermediates <=2^51 for this retained study, not a general arbitrary-precision
# implementation of all interactive numeric inputs.
# MovieLens: Harper/Konstan2015 doi:10.1145/2827872. Original conditions,
# no endorsement/warranty and prior commercial permission still apply.
if(!isTRUE(l10n_info()[['UTF-8']])){
 if(.Platform$OS.type=='windows')suppressWarnings(Sys.setlocale('LC_CTYPE','.UTF-8'))
 if(!isTRUE(l10n_info()[['UTF-8']]))stop('A UTF-8 LC_CTYPE locale is required.')
}
invisible(suppressWarnings(Sys.setlocale('LC_NUMERIC','C')))
markUTF8<-function(x){ok<-validUTF8(x);Encoding(x[ok])<-'UTF-8';x}
argv<-markUTF8(commandArgs(trailingOnly=TRUE));allArgs<-markUTF8(commandArgs());fileArg<-sub('^--file=','',allArgs[grepl('^--file=',allArgs)][1]);here<-dirname(normalizePath(fileArg,mustWork=TRUE))
sourceDir<-if(length(argv))normalizePath(argv[1],mustWork=TRUE)else file.path(dirname(here),'ai17-sources')
outDir<-if(length(argv)>1)argv[2]else file.path(here,'reproduced-r');dir.create(outDir,recursive=TRUE,showWarnings=FALSE)
files<-c(country='actual32-country-observations-2024.csv',person='movielens-original-movies.csv',company='actual30-Apple-product-sales-FY2019-2024.csv')
expectedMD5<-c(country='20579b4e1d4e3e016bf3340ab82d117e',person='ed94fab72b62442ef8150d9446e000d6',company='9c72921fbcf7b4617d54c9671b3ca391')
expectedSHA<-c(country='4a544884181b228f4539c859abb874f92ddd77f09b956d1ba9c96d37b6f8587b',person='5a5f32dd9bb3797b8e728a1b98958789d2b13f294a69fdfbc5727f8a9611aa07',company='b163b104c02e0362e0d61fdb3bb220350a97e6e25f6eb6098b742bfac2aa5598')
stopifnot(all(unname(tools::md5sum(file.path(sourceDir,files)))==unname(expectedMD5)))
raw<-lapply(files,function(f)read.csv(file.path(sourceDir,f),colClasses='character',check.names=FALSE,na.strings=NULL,fileEncoding='UTF-8-BOM'))
readme<-file.path(sourceDir,'MovieLens-README-original.txt');stopifnot(unname(tools::md5sum(readme))=='9bc20a696092024abe52696ee6c5837f');invisible(file.copy(readme,file.path(outDir,basename(readme)),overwrite=TRUE))

# SHA256 for a batch of the declared ASCII selection messages (one block each).
# All arithmetic additions fit exactly within binary64; bit operations use safe
# unsigned 16-bit halves, avoiding R's reserved signed integer NA word.
u32 <- 4294967296; base <- 65536
bx <- function(x,y)as.double(bitwXor(as.integer(x%%base),as.integer(y%%base)))+base*as.double(bitwXor(as.integer(floor(x/base)),as.integer(floor(y/base))))
ba <- function(x,y)as.double(bitwAnd(as.integer(x%%base),as.integer(y%%base)))+base*as.double(bitwAnd(as.integer(floor(x/base)),as.integer(floor(y/base))))
bn <- function(x)u32-1-x
rr <- function(x,n)floor(x/2^n)+(x%%2^n)*2^(32-n)
hx <- function(s)strtoi(substr(s,1,4),16L)*base+strtoi(substr(s,5,8),16L)
K <- vapply(strsplit(paste('428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5','d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174','e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da','983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967','27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85','a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070','19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3','748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2'), ' +')[[1]],hx,0.0)
H <- vapply(strsplit('6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19',' ')[[1]],hx,0.0)
shaBatch <- function(strings){
 n<-length(strings); if(!n)return(character()); bytes<-lapply(strings,function(s)as.integer(charToRaw(enc2utf8(s))));stopifnot(all(lengths(bytes)<=55),all(vapply(bytes,function(x)all(x<128),TRUE)))
 block<-matrix(0,n,64)
 for(i in seq_len(n)){m<-length(bytes[[i]]);if(m)block[i,seq_len(m)]<-bytes[[i]];block[i,m+1]<-128;bits<-m*8;block[i,63]<-floor(bits/256);block[i,64]<-bits%%256}
 w<-vector('list',64)
 for(t in 1:16)w[[t]]<-as.vector(block[,(4*t-3):(4*t),drop=FALSE]%*%c(16777216,65536,256,1))
 for(t in 17:64){x<-w[[t-15]];y<-w[[t-2]];s0<-bx(bx(rr(x,7),rr(x,18)),floor(x/8));s1<-bx(bx(rr(y,17),rr(y,19)),floor(y/1024));w[[t]]<-(w[[t-16]]+s0+w[[t-7]]+s1)%%u32}
 v<-lapply(H,function(x)rep(x,n));a<-v[[1]];b<-v[[2]];c<-v[[3]];d<-v[[4]];e<-v[[5]];f<-v[[6]];g<-v[[7]];h<-v[[8]]
 for(t in 1:64){S1<-bx(bx(rr(e,6),rr(e,11)),rr(e,25));ch<-bx(ba(e,f),ba(bn(e),g));t1<-(h+S1+ch+K[t]+w[[t]])%%u32;S0<-bx(bx(rr(a,2),rr(a,13)),rr(a,22));maj<-bx(bx(ba(a,b),ba(a,c)),ba(b,c));t2<-(S0+maj)%%u32;h<-g;g<-f;f<-e;e<-(d+t1)%%u32;d<-c;c<-b;b<-a;a<-(t1+t2)%%u32}
 ans<-list(a,b,c,d,e,f,g,h);out<-rep('',n)
 for(j in 1:8){z<-(ans[[j]]+H[j])%%u32;out<-paste0(out,sprintf('%04x%04x',as.integer(floor(z/base)),as.integer(z%%base)))}
 out
}
stopifnot(identical(shaBatch(c('','abc')),c('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855','ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')))
key <- function(prefix,id)shaBatch(paste0(prefix,'|',id))

qzero<-list(n=0,d=1);bound<-2^51
whole<-function(x){stopifnot(is.finite(x),abs(x)<=bound,x==trunc(x));x}
product<-function(a,b){if(b!=0&&abs(a)>bound/abs(b))stop('bounded exact integer product exceeded');whole(a*b)}
gcd<-function(a,b){a<-abs(a);b<-abs(b);while(b!=0){r<-a%%b;a<-b;b<-r};a}
Q<-function(n,d=1){whole(n);whole(d);stopifnot(d!=0);if(d<0){n<--n;d<--d};g<-gcd(n,d);list(n=n/g,d=d/g)}
add<-function(a,b)Q(whole(product(a$n,b$d)+product(b$n,a$d)),product(a$d,b$d))
subq<-function(a,b)add(a,list(n=-b$n,d=b$d));mul<-function(a,b)Q(product(a$n,b$n),product(a$d,b$d));divq<-function(a,b)Q(product(a$n,b$d),product(a$d,b$n))
qs<-function(a)if(a$d==1)sprintf('%.0f',a$n)else paste0(sprintf('%.0f',a$n),'/',sprintf('%.0f',a$d))
parseq<-function(s){if(grepl('/',s,fixed=TRUE)){v<-strsplit(s,'/',fixed=TRUE)[[1]];return(Q(as.numeric(v[1]),as.numeric(v[2])))};stopifnot(grepl('^[+-]?[0-9]+([.][0-9]+)?$',s));v<-strsplit(s,'.',fixed=TRUE)[[1]];digits<-if(length(v)>1)nchar(v[2])else 0;Q(as.numeric(gsub('.','',s,fixed=TRUE)),10^digits)}
sumq<-function(v)Reduce(add,v,init=qzero)
cmpq<-function(a,b)sign(product(a$n,b$d)-product(b$n,a$d))
quotejson<-function(s){v<-utf8ToInt(enc2utf8(s));z<-vapply(v,function(c){if(c==34)'\\"'else if(c==92)'\\\\'else if(c<32)sprintf('\\u%04x',c)else intToUtf8(c)},'');paste0('"',paste0(z,collapse=''),'"')}
J<-function(x){if(is.null(x))return('null');if(is.list(x)){if(!is.null(names(x)))return(paste0('{',paste0(vapply(seq_along(x),function(i)paste0(quotejson(names(x)[i]),':',J(x[[i]])),''),collapse=','),'}'));return(paste0('[',paste0(vapply(x,J,''),collapse=','),']'))};if(length(x)!=1)return(J(as.list(x)));if(is.logical(x))return(if(x)'true'else'false');if(is.numeric(x))return(sprintf('%.0f',x));quotejson(as.character(x))}
B<-function(x)if(x)'true'else'false'
records<-setNames(lapply(files,function(x)list()),names(files));tasks<-setNames(lapply(files,function(x)list()),names(files));ledger<-list();growth<-list()
rec<-function(kind,id,row,native,unit,year,extra,value=NULL,upstream=NULL){response<-c(list(recordID=id,kind=c(country='annualRate',person='movieCatalog',company='nominalProductSales')[[kind]],unit=unit,year=as.character(year)),extra);if(!is.null(value))response$valueToken<-value;response$provenance<-list(file=files[[kind]],sourceRow=as.character(row),nativeSHA256=expectedSHA[[kind]]);if(!is.null(upstream))response$provenance$upstreamSourceRowToken<-upstream;r<-list(id=id,response=response,nativeFields=native,sourceRow=as.character(row));records[[kind]][[length(records[[kind]])+1]]<<-r;r}
meta<-function(r)r[c('recordID','kind','unit','year')]
task<-function(kind,id,role,group,operation,refs,answer){tasks[[kind]][[length(tasks[[kind]])+1]]<<-list(id=id,role=role,group=group,operation=operation,lookups=lapply(refs,function(r)list(recordID=r$id,expectedMetadata=meta(r$response))),expectedAnswer=answer)}
countries<-unique(raw$country$countryISO3);countries<-countries[order(key('AI17-country-role',countries),countries,method='radix')];countryRoles<-setNames(c(rep('train',8),rep('validation',4),rep('test',4)),countries);byCountry<-list()
for(i in seq_len(nrow(raw$country))){r<-as.list(raw$country[i,,drop=FALSE]);id<-paste('WB',r$countryISO3,r$indicatorID,r$date,sep=':');byCountry[[paste(r$countryISO3,r$indicatorID,sep='|')]]<-rec('country',id,i,r,'annual-percent',r$date,list(countryISO3=r$countryISO3,indicatorID=r$indicatorID),r$originalValueToken,r$sourceRow)}
for(c in sort(countries,method='radix')){refs<-lapply(c('NY.GDP.MKTP.KD.ZG','FP.CPI.TOTL.ZG'),function(ind)byCountry[[paste(c,ind,sep='|')]]);task('country',paste0('country:',c),countryRoles[[c]],c,'country-pair',refs,list(gdpGrowthToken=refs[[1]]$response$valueToken,cpiInflationToken=refs[[2]]$response$valueToken,evidence=lapply(refs,function(r)meta(r$response))))}
movieHashes<-key('AI16-person-corpus',raw$person$movieId);indices<-head(order(movieHashes,raw$person$movieId,method='radix'),240);ids<-raw$person$movieId[indices];taskHashes<-key('AI17-person-task',ids);queryIndices<-indices[head(order(taskHashes,ids,method='radix'),40)];queryIds<-raw$person$movieId[queryIndices];movieRoles<-setNames(c(rep('train',20),rep('validation',10),rep('test',10)),queryIds);byMovie<-list();allTaskHashes<-setNames(key('AI17-person-task',ids),ids)
for(i in seq_len(nrow(raw$person))){r<-as.list(raw$person[i,,drop=FALSE]);selected<-r$movieId%in%ids;role<-if(r$movieId%in%queryIds)movieRoles[[r$movieId]]else'';ledger[[i]]<-list(sourceRow=i,movieId=r$movieId,title=r$title,genres=r$genres,frameSHA=movieHashes[i],in240Frame=B(selected),taskSHA=if(selected)allTaskHashes[[r$movieId]]else'',taskRole=role);if(selected){yearMatch<-regmatches(r$title,regexec('[(]([0-9]{4})[)][[:space:]]*$',r$title))[[1]];year<-if(length(yearMatch)>1)yearMatch[2]else'not-present';byMovie[[r$movieId]]<-rec('person',paste0('MovieLens:movie:',r$movieId),i,r,'year-in-title',year,list(movieID=r$movieId,title=r$title,genres=as.list(strsplit(r$genres,'|',fixed=TRUE)[[1]])))}}
for(i in queryIndices){r<-as.list(raw$person[i,,drop=FALSE]);v<-byMovie[[r$movieId]];task('person',paste0('movie:',r$movieId),movieRoles[[r$movieId]],r$movieId,'movie-facts',list(v),list(movieID=r$movieId,title=r$title,genres=as.list(strsplit(r$genres,'|',fixed=TRUE)[[1]]),evidence=list(meta(v$response))))}
sales<-list()
for(i in seq_len(nrow(raw$company))){r<-as.list(raw$company[i,,drop=FALSE]);stopifnot(gsub(',','',r$originalUSDMillionsToken,fixed=TRUE)==r$valueUSDMillions);sales[[paste(r$product,r$fiscalYear,sep='|')]]<-rec('company',paste('Apple',r$product,r$fiscalYear,sep=':'),i,r,'nominal-USD-million',r$fiscalYear,list(product=r$product,sourceOriginalValueToken=r$originalUSDMillionsToken),r$valueUSDMillions)}
for(p in sort(unique(raw$company$product),method='radix'))for(year in 2020:2024){refs<-list(sales[[paste(p,year,sep='|')]],sales[[paste(p,year-1,sep='|')]]);x<-parseq(refs[[1]]$response$valueToken);b<-parseq(refs[[2]]$response$valueToken);stopifnot(b$n>0);g<-mul(Q(100),divq(subq(x,b),b));task('company',paste('growth',p,year,sep=':'),if(year<=2022)'train'else if(year==2023)'validation'else'test',as.character(year),'sales-growth',refs,list(growthPercentFraction=qs(g),evidence=lapply(refs,function(r)meta(r$response))));growth[[length(growth)+1]]<-list(product=p,fiscalYear=year,currentOriginalToken=refs[[1]]$nativeFields$originalUSDMillionsToken,priorOriginalToken=refs[[2]]$nativeFields$originalUSDMillionsToken,currentValueToken=qs(x),priorValueToken=qs(b),growthPercentFraction=qs(g),namedCSVRows=J(lapply(refs,function(r)r$sourceRow)))}
POLICIES<-c('single','retry-transient','checked-single','checked-retry-transient');SCENARIOS<-c('clean','first-attempt-transient-timeout','persistent-stale-metadata','persistent-wrong-kind-or-unit','persistent-valid-typed-corruption','persistent-missing-result');runrows<-list();traces<-list();means<-list();scenarioMeans<-list();selections<-list()
execute<-function(kind,t,policy,scenario){checked<-startsWith(policy,'checked-');retry<-endsWith(policy,'retry-transient');responses<-list();attempted<-0;reason<-NULL;by<-setNames(records[[kind]],vapply(records[[kind]],function(r)r$id,''))
 for(step in seq_along(t$lookups)){lookup<-t$lookups[[step]];response<-NULL
  for(attempt in seq_len(if(retry)3 else 1)){attempted<-attempted+1;status<-'ok';issues<-list();response<-NULL
   if(step==1&&scenario=='first-attempt-transient-timeout'&&attempt==1)status<-'transient-error'else if(step==1&&scenario=='persistent-missing-result')status<-'missing'else{response<-by[[lookup$recordID]]$response
    if(step==1&&scenario=='persistent-stale-metadata')response$year<-if(grepl('^[0-9]{4}$',response$year))as.character(as.integer(response$year)-1)else'unrelated-year'
    if(step==1&&scenario=='persistent-wrong-kind-or-unit')response$unit<-'unrelated-unit'
    if(step==1&&scenario=='persistent-valid-typed-corruption'){if(!is.null(response$valueToken))response$valueToken<-qs(add(parseq(response$valueToken),Q(1)))else response$title<-paste0(response$title,' [corrupted]')}
    if(checked)for(k in names(lookup$expectedMetadata))if(response[[k]]!=lookup$expectedMetadata[[k]])issues[[length(issues)+1]]<-paste0('metadata-mismatch:',k)
   }
   traces[[length(traces)+1]]<<-list(kind=kind,taskID=t$id,policy=policy,scenario=scenario,step=step,attempt=attempt,recordID=lookup$recordID,status=status,contractIssuesJSON=J(issues),responseJSON=J(response))
   if(status=='transient-error'){if(retry&&attempt<3)next;reason<-'transient-retry-bound';break};if(status=='missing'){reason<-'missing-result';break};if(length(issues)){reason<-'contract-rejected';break};break
  };if(!is.null(reason))break;responses[[length(responses)+1]]<-response
 }
 answer<-NULL;if(is.null(reason)){evidence<-lapply(responses,meta);if(t$operation=='country-pair')answer<-list(gdpGrowthToken=responses[[1]]$valueToken,cpiInflationToken=responses[[2]]$valueToken,evidence=evidence)else if(t$operation=='movie-facts')answer<-list(movieID=responses[[1]]$movieID,title=responses[[1]]$title,genres=responses[[1]]$genres,evidence=evidence)else{x<-parseq(responses[[1]]$valueToken);b<-parseq(responses[[2]]$valueToken);if(b$n==0)reason<-'zero-base-sales'else answer<-list(growthPercentFraction=qs(mul(Q(100),divq(subq(x,b),b))),evidence=evidence)}}
 accepted<-!is.null(answer);correct<-accepted&&identical(J(answer),J(t$expectedAnswer));wrong<-accepted&&!correct;utility<-subq(Q(if(correct)2 else if(wrong)-3 else 0),Q(attempted,100));list(kind=kind,taskID=t$id,role=t$role,policy=policy,scenario=scenario,attempted=attempted,accepted=B(accepted),correct=B(correct),wrong=B(wrong),abstention=if(is.null(reason))''else reason,utilityFraction=qs(utility),answerJSON=J(answer))
}
summarize<-function(frame){n<-length(frame);c<-sum(vapply(frame,function(r)r$correct=='true',TRUE));a<-sum(vapply(frame,function(r)r$accepted=='true',TRUE));w<-sum(vapply(frame,function(r)r$wrong=='true',TRUE));list(runs=n,correct=c,accepted=a,wrong=w,abstained=n-a,meanUtility=if(n)qs(divq(sumq(lapply(frame,function(r)parseq(r$utilityFraction))),Q(n)))else'',goalRate=if(n)qs(Q(c,n))else'',coverage=if(n)qs(Q(a,n))else'',accuracyAmongAccepted=if(a)qs(Q(c,a))else'',meanAttempts=if(n)qs(Q(sum(vapply(frame,function(r)r$attempted,0)),n))else'')}
for(kind in names(files)){local<-list();for(t in tasks[[kind]])for(p in POLICIES)for(s in SCENARIOS)local[[length(local)+1]]<-execute(kind,t,p,s);runrows<-c(runrows,local)
 for(p in POLICIES){for(role in c('train','validation','test'))means[[length(means)+1]]<-c(list(kind=kind,policy=p,role=role),summarize(Filter(function(r)r$policy==p&&r$role==role,local)));for(s in SCENARIOS)scenarioMeans[[length(scenarioMeans)+1]]<-c(list(kind=kind,policy=p,scenario=s),summarize(Filter(function(r)r$policy==p&&r$scenario==s,local)))}
 candidates<-Filter(function(r)r$kind==kind&&r$role=='validation',means);winner<-candidates[[1]];if(length(candidates)>1)for(i in 2:length(candidates))if(cmpq(parseq(candidates[[i]]$meanUtility),parseq(winner$meanUtility))>0)winner<-candidates[[i]];selections[[length(selections)+1]]<-list(kind=kind,policy=winner$policy,validationMeanUtility=winner$meanUtility)
}
recordRows<-list();taskRows<-list()
for(kind in names(files)){for(r in records[[kind]])recordRows[[length(recordRows)+1]]<-list(kind=kind,recordID=r$id,namedCSVDataRow=r$sourceRow,upstreamSourceRowToken=if(is.null(r$response$provenance$upstreamSourceRowToken))''else r$response$provenance$upstreamSourceRowToken,nativeFieldsJSON=J(r$nativeFields),typedResponseJSON=J(r$response));for(t in tasks[[kind]])taskRows[[length(taskRows)+1]]<-list(kind=kind,taskID=t$id,role=t$role,group=t$group,operation=t$operation,lookupsJSON=J(t$lookups),referenceAnswerJSON=J(t$expectedAnswer))}
points<-list();point<-function(fig,kind,series,x,y,mode,unit)points[[length(points)+1]]<<-list(figureID=fig,kind=kind,series=series,xLabel=as.character(x),yToken=as.character(y),valueKind=mode,unitCaption=unit)
for(i in seq_len(nrow(raw$country))){r<-raw$country[i,];point('country-facts','country',r$indicatorID,r$countryISO3,r$originalValueToken,'native-token','annual-percent indicator definition')}
genres<-unlist(lapply(records$person,function(r)unlist(r$response$genres)),use.names=FALSE);genreNames<-sort(unique(genres),method='radix');for(g in genreNames)point('person-facts','person','recorded genre count',g,sum(genres==g),'derived-exact-fraction','catalog records with tag')
for(i in seq_len(nrow(raw$company))){r<-raw$company[i,];point('company-facts','company',r$product,r$fiscalYear,r$valueUSDMillions,'native-token','nominal USD million')}
for(r in means)point(paste0(r$kind,'-role-utility'),r$kind,r$policy,r$role,r$meanUtility,'derived-exact-fraction','declared utility per run')
for(r in scenarioMeans)point(paste0(r$kind,'-scenario-utility'),r$kind,r$policy,r$scenario,r$meanUtility,'derived-exact-fraction','declared utility per run')
tables<-list('derived9742-frame-ledger.csv'=ledger,'derived302-tool-records.csv'=recordRows,'derived81-tasks.csv'=taskRows,'derived1944-run-results.csv'=runrows,'derived2680-attempt-traces.csv'=traces,'derived36-role-policy-means.csv'=means,'derived72-scenario-policy-means.csv'=scenarioMeans,'derived3-validation-selections.csv'=selections,'derived25-company-growth.csv'=growth,'derived-source-figure-points.csv'=points)
asFrame<-function(rows){nms<-names(rows[[1]]);d<-setNames(lapply(nms,function(k)vapply(rows,function(r)as.character(r[[k]]),'')),nms);as.data.frame(d,stringsAsFactors=FALSE,check.names=FALSE)}
for(n in names(tables))write.table(asFrame(tables[[n]]),file.path(outDir,n),row.names=FALSE,quote=TRUE,sep=',',na='',fileEncoding='UTF-8',qmethod='double',eol='\n')
stopifnot(length(runrows)==1944,length(traces)==2680,length(taskRows)==81,length(recordRows)==302,length(points)==190)
manifest<-list(chapter='AI-17',implementation='base R + bundled tools, bounded exact-integer rational study',inputs=lapply(names(files),function(k)list(file=files[[k]],verifiedMD5=expectedMD5[[k]],declaredSHA256=expectedSHA[[k]],rows=nrow(raw[[k]]))),outputs=lapply(names(tables),function(n)list(file=n,rows=length(tables[[n]]),bodyFields=length(tables[[n]])*length(tables[[n]][[1]]),MD5=unname(tools::md5sum(file.path(outDir,n))))),counts=list(tasks=81,typedRecords=302,stressOutcomes=1944,attemptEvents=2680,sourceFigureY=length(points)),selectionRule='Validation-only exact mean utility; earliest policy tie; no test reselection.',scope='Retained native facts plus authored tasks, roles, faults, controllers and utility. No LLM/live service/reliability estimate/historical forecast.',MovieLens=list(readmeFile=basename(readme),readmeMD5=unname(tools::md5sum(readme)),citation='Harper and Konstan2015,doi:10.1145/2827872',conditions='Original README conditions retained with transformations; educational/research conditional use; noendorsement/nowarranty; prior commercial/revenue permission. NotCCBY.'))
writeLines(J(manifest),file.path(outDir,'manifest.json'),useBytes=TRUE)
cat(J(list(status='completed actual source-only study',outputs=length(tables),tasks=81,typedRecords=302,stressOutcomes=1944,attemptEvents=2680,sourceFigureY=length(points))),'\n')
