humanish 0.113.0 → 0.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/CONTEXT.md +1 -0
  3. package/README.md +1 -1
  4. package/dist/actors/closing-report-limits.d.ts +11 -0
  5. package/dist/actors/closing-report-limits.js +13 -0
  6. package/dist/actors/closing-report.d.ts +68 -0
  7. package/dist/actors/closing-report.js +55 -0
  8. package/dist/actors/codex/restricted-participant-policy.d.ts +4 -47
  9. package/dist/actors/codex/restricted-participant-policy.js +12 -40
  10. package/dist/actors/computer-use/loop/debrief.d.ts +1 -10
  11. package/dist/actors/computer-use/loop/debrief.js +10 -46
  12. package/dist/actors/computer-use/loop/impressions.d.ts +2 -2
  13. package/dist/actors/computer-use/loop/impressions.js +6 -1
  14. package/dist/actors/computer-use/loop.d.ts +0 -1
  15. package/dist/actors/computer-use/loop.js +3 -3
  16. package/dist/actors/computer-use/openai-conversation.d.ts +1 -1
  17. package/dist/actors/computer-use/openai-conversation.js +12 -36
  18. package/dist/actors/computer-use/openai-provider.js +11 -5
  19. package/dist/actors/contract.d.ts +6 -22
  20. package/dist/actors/contract.js +0 -13
  21. package/dist/analysis/admission.d.ts +47 -0
  22. package/dist/analysis/admission.js +65 -0
  23. package/dist/analysis/automatic-completion.d.ts +0 -6
  24. package/dist/analysis/automatic-completion.js +3 -3
  25. package/dist/analysis/automatic-config.d.ts +10 -2
  26. package/dist/analysis/automatic-config.js +29 -14
  27. package/dist/analysis/automatic.js +7 -0
  28. package/dist/analysis/execute.d.ts +24 -5
  29. package/dist/analysis/execute.js +61 -27
  30. package/dist/analysis/finding-lead.d.ts +27 -0
  31. package/dist/analysis/finding-lead.js +23 -0
  32. package/dist/analysis/image-tokens.d.ts +2 -0
  33. package/dist/analysis/image-tokens.js +1 -1
  34. package/dist/analysis/job.d.ts +9 -1
  35. package/dist/analysis/job.js +11 -2
  36. package/dist/analysis/service.js +8 -3
  37. package/dist/cli/commands/analyze.js +7 -2
  38. package/dist/cli/commands/notes.d.ts +3 -0
  39. package/dist/cli/commands/notes.js +145 -0
  40. package/dist/cli/commands/observe.js +1 -1
  41. package/dist/cli/commands/study-run.js +2 -1
  42. package/dist/cli/findings.js +11 -30
  43. package/dist/cli/io.d.ts +1 -0
  44. package/dist/cli/io.js +8 -12
  45. package/dist/cli/program.js +2 -0
  46. package/dist/cli/telemetry.js +10 -22
  47. package/dist/cli/update-check.js +6 -18
  48. package/dist/cli/user-config.d.ts +11 -0
  49. package/dist/cli/user-config.js +25 -0
  50. package/dist/comms/email-catch.js +7 -31
  51. package/dist/evidence/encoded-text.d.ts +17 -3
  52. package/dist/evidence/encoded-text.js +121 -46
  53. package/dist/evidence/redaction.d.ts +11 -0
  54. package/dist/evidence/redaction.js +21 -10
  55. package/dist/evidence/secret-scrub.d.ts +14 -1
  56. package/dist/evidence/secret-scrub.js +125 -28
  57. package/dist/feedback/draft.d.ts +19 -0
  58. package/dist/feedback/draft.js +62 -15
  59. package/dist/feedback/export-bundle.js +3 -3
  60. package/dist/feedback/export.js +50 -20
  61. package/dist/feedback/feedback.js +29 -2
  62. package/dist/keys/key-resolution.js +12 -17
  63. package/dist/observer/artifact.d.ts +5 -0
  64. package/dist/observer/artifact.js +18 -2
  65. package/dist/observer/http.d.ts +7 -0
  66. package/dist/observer/http.js +19 -1
  67. package/dist/observer/notes-route.d.ts +20 -0
  68. package/dist/observer/notes-route.js +120 -0
  69. package/dist/observer/pinned-files.d.ts +8 -1
  70. package/dist/observer/pinned-files.js +17 -3
  71. package/dist/observer/render.js +39 -14
  72. package/dist/observer/run-routes.d.ts +8 -2
  73. package/dist/observer/run-routes.js +32 -6
  74. package/dist/observer/serve.d.ts +3 -0
  75. package/dist/observer/serve.js +29 -3
  76. package/dist/observer-app.html +7 -6
  77. package/dist/run/contained-output.d.ts +8 -0
  78. package/dist/run/contained-output.js +27 -0
  79. package/dist/run/evidence-files.d.ts +7 -0
  80. package/dist/run/evidence-files.js +24 -14
  81. package/dist/run/note-files.d.ts +54 -0
  82. package/dist/run/note-files.js +212 -0
  83. package/dist/run/note-shape.d.ts +35 -0
  84. package/dist/run/note-shape.js +20 -0
  85. package/dist/run/notes.d.ts +34 -0
  86. package/dist/run/notes.js +192 -0
  87. package/dist/run/participant-caption.d.ts +9 -0
  88. package/dist/run/participant-caption.js +19 -0
  89. package/dist/run/participant-records.d.ts +2 -0
  90. package/dist/run/participant-records.js +17 -2
  91. package/dist/run/transient-comms-secrets.d.ts +6 -5
  92. package/dist/run/transient-comms-secrets.js +19 -24
  93. package/dist/study/doctor.js +1 -1
  94. package/dist/study/preflight-result.js +2 -1
  95. package/dist/study/summary.d.ts +4 -5
  96. package/dist/study/summary.js +6 -4
  97. package/dist/study/warnings.js +2 -1
  98. package/dist/tui-app.js +1 -1
  99. package/docs/architecture/actor-contract.md +3 -3
  100. package/docs/architecture/restricted-codex-analysis.md +1 -1
  101. package/docs/architecture/state-driven-executor.md +1 -1
  102. package/docs/contracts/errors.md +2 -2
  103. package/docs/contracts/run-bundle.md +61 -0
  104. package/docs/contracts/schemas.md +17 -14
  105. package/docs/contracts/study-analysis.md +35 -9
  106. package/docs/principles/invariants-and-defaults.md +2 -2
  107. package/docs/product/automatic-analysis.md +22 -16
  108. package/package.json +8 -7
  109. package/skills/humanish/SKILL.md +6 -2
package/dist/tui-app.js CHANGED
@@ -283,7 +283,7 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
283
283
  `))}patchConsole(){this.options.debug||(this.restoreConsole=cv((i,u)=>{i==="stdout"&&this.writeToStdout(u),i==="stderr"&&(u.startsWith("The above error occurred")||this.writeToStderr(u))}))}registerInputControl(i,u){this.pauseInput=i,this.resumeInput=u}async suspendTerminal(i){if(this.beginSuspend(),i){try{await i()}finally{await this.endSuspend()}return}let u=o(async()=>{await this.endSuspend()},"resume");return{resume:u,[Symbol.asyncDispose]:u}}setAlternateScreen(i){this.alternateScreen=this.resolveAlternateScreenOption(i,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,kn.enterAlternativeScreen),this.writeBestEffort(this.options.stdout,Nc))}resolveInteractiveOption(i){return i??(!rh&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(i,u){return!!i&&u&&!!this.options.stdout.isTTY}shouldSync(){return FR(this.options.stdout,this.interactive)}writeBestEffort(i,u){try{i.write(u)}catch{}}async awaitExit(){try{await this.exitPromise}catch{}}hasPendingConcurrentWork(){let i=this.container;return(i.pendingLanes??0)!==0&&i.callbackNode!==void 0&&i.callbackNode!==null}async awaitNextRender(){if(!this.nextRenderCommit){let i,u=new Promise(c=>{i=c});this.nextRenderCommit={promise:u,resolve:i}}return this.nextRenderCommit.promise}renderInteractiveFrame(i,u,c){let d=c!=="",m=this.options.stdout.isTTY,B=m?Ic(this.options.stdout).rows:24,Q=m&&u>=B?i:i+`
284
284
  `;if(UU({isTty:m,viewportRows:B,previousOutputHeight:this.lastOutputHeight,nextOutputHeight:u,isUnmounting:this.isUnmounting})){let b=this.shouldSync();b&&this.options.stdout.write(bc),this.options.stdout.write(kn.clearTerminal+this.fullStaticOutput+Q),this.lastOutput=i,this.lastOutputToRender=Q,this.lastOutputHeight=u,this.log.sync(Q),b&&this.options.stdout.write(qr);return}if(d){let b=this.shouldSync();b&&this.options.stdout.write(bc),this.log.clear(),this.options.stdout.write(c),this.log(Q),b&&this.options.stdout.write(qr)}else(i!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(Q);this.lastOutput=i,this.lastOutputToRender=Q,this.lastOutputHeight=u}initKittyKeyboard(){if(!this.options.kittyKeyboard)return;let i=this.options.kittyKeyboard,u=i.mode??"auto";if(u==="disabled")return;let c=i.flags??["disambiguateEscapeCodes"];if(u==="enabled"){this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(c);return}!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(c)}confirmKittySupport(i){let{stdin:u,stdout:c}=this.options,d=[],m=o(()=>{this.cancelKittyDetection=void 0,clearTimeout(y),u.removeListener("data",B);let Q=wU(d);d=[],Q.length>0&&u.unshift(Uint8Array.from(Q))},"cleanup"),B=o(Q=>{let N=typeof Q=="string"?SU.encode(Q):Q;for(let b of N)d.push(b);_U(d)&&(m(),this.isUnmounted||this.enableKittyProtocol(i))},"onData");u.on("data",B);let y=setTimeout(m,200);this.cancelKittyDetection=m,c.write("\x1B[?u")}enableKittyProtocol(i){this.options.stdout.write(`\x1B[>${HQ(i)}u`),this.kittyProtocolEnabled=!0,this.kittyFlags=i}beginSuspend(){if(this.isSuspended)throw new Error("The terminal is already suspended. Resume the current suspension before suspending again.");if(this.isSuspended=!0,!(!this.interactive||this.isUnmounted||this.isUnmounting))try{let i=this.options.stdout,{canWriteToStdout:u}=EB(i);Eg(this.throttledOnRender,u),Eg(this.throttledLog,u),u&&(this.log.clear(),this.log.done(),this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen&&this.writeBestEffort(this.options.stdout,kn.exitAlternativeScreen)),this.pauseInput?.()}catch(i){this.isSuspended=!1;try{this.resumeInput?.()}catch{}throw i}}async endSuspend(){if(!this.isSuspended||(this.isSuspended=!1,this.resumeInput?.(),!this.interactive||this.isUnmounted||this.isUnmounting))return;let i=this.options.stdout,{canWriteToStdout:u}=EB(i);u&&(this.alternateScreen&&this.writeBestEffort(this.options.stdout,kn.enterAlternativeScreen),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${HQ(this.kittyFlags)}u`)),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.log.reset();try{this.calculateLayout(),this.onRender(),await this.waitUntilRenderFlush()}catch{}}};var HU=o((n,i)=>{let u={stdout:ep.stdout,stdin:ep.stdin,stderr:ep.stderr,debug:!1,exitOnCtrlC:!0,patchConsole:!0,maxFps:30,incrementalRendering:!1,concurrent:!1,alternateScreen:!1,...GU(i)},c=LU(u.stdout,()=>new tp(u));return c.render(n),{rerender:c.render,unmount(){c.unmount()},waitUntilExit:c.waitUntilExit,waitUntilRenderFlush:c.waitUntilRenderFlush,cleanup(){c.unmount()},clear:c.clear}},"render"),zQ=HU,GU=o((n={})=>n instanceof OU?{stdout:n,stdin:ep.stdin}:n,"getOptions"),LU=o((n,i)=>{let u=Xm.get(n);if(u===void 0){let c=i();return Xm.set(n,c),c}return ep.stderr.write(`Warning: render() was called again for the same stdout before the previous Ink instance was unmounted. Reusing stdout across multiple render() calls is unsupported. Call unmount() first.
285
285
  `),u},"getInstance");var zU=Ot(gh(),1);var pB=Ot(Le(),1);var T2=Ot(Le(),1);var YU=Ot(Le(),1);var JU=Ot(Le(),1);var np=Ot(Le(),1);var b2=new TextDecoder,KU=/^(?:\x1b)([a-zA-Z0-9])$/,FU=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,w2={OP:"f1",OQ:"f2",OR:"f3",OS:"f4","[P":"f1","[Q":"f2","[R":"f3","[S":"f4","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"},M2=[...Object.values(w2),"backspace"],kU=o(n=>["[a","[b","[c","[d","[e","[2$","[3$","[5$","[6$","[7$","[8$","[Z"].includes(n),"isShiftKey"),qU=o(n=>["Oa","Ob","Oc","Od","Oe","[2^","[3^","[5^","[6^","[7^","[8^"].includes(n),"isCtrlKey"),U2=/^\x1b\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,jU=/^\x1b\[(\d+);(\d+):(\d+)([A-Za-z~])$/,VU={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},XU={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},_2={27:"escape",9:"tab",127:"backspace",8:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"},O2=o(n=>n>=0&&n<=1114111&&!(n>=55296&&n<=57343),"isValidCodepoint"),YQ=o(n=>O2(n)?String.fromCodePoint(n):"?","safeFromCodePoint");function H2(n){return n===3?"release":n===2?"repeat":"press"}o(H2,"resolveEventType");function G2(n){return{ctrl:!!(n&Vo.ctrl),shift:!!(n&Vo.shift),meta:!!(n&(Vo.meta|Vo.alt)),super:!!(n&Vo.super),hyper:!!(n&Vo.hyper),capsLock:!!(n&Vo.capsLock),numLock:!!(n&Vo.numLock)}}o(G2,"parseKittyModifiers");var ZU=o(n=>{let i=U2.exec(n);if(!i)return null;let u=parseInt(i[1],10),c=i[2]?Math.max(0,parseInt(i[2],10)-1):0,d=i[3]?parseInt(i[3],10):1,m=i[4];if(!O2(u))return null;let B;m&&(B=m.split(":").map(N=>YQ(parseInt(N,10))).join(""));let y,Q;return u===32?(y="space",Q=!0):u===13?(y="return",Q=!0):_2[u]?(y=_2[u],Q=!1):u>=1&&u<=26?(y=String.fromCodePoint(u+96),Q=!1):(y=YQ(u).toLowerCase(),Q=!0),Q&&!B&&(B=YQ(u)),{name:y,...G2(c),eventType:H2(d),sequence:n,raw:n,isKittyProtocol:!0,isPrintable:Q,text:B}},"parseKittyKeypress"),WU=o(n=>{let i=jU.exec(n);if(!i)return null;let u=parseInt(i[1],10),c=Math.max(0,parseInt(i[2],10)-1),d=parseInt(i[3],10),m=i[4],B=m==="~"?XU[u]:VU[m];return B?{name:B,...G2(c),eventType:H2(d),sequence:n,raw:n,isKittyProtocol:!0,isPrintable:!1}:null},"parseKittySpecialKey"),PU=o((n="")=>{let i;n instanceof Uint8Array?n[0]>127&&n[1]===void 0?(n[0]-=128,n="\x1B"+b2.decode(n)):n=b2.decode(n):n!==void 0&&typeof n!="string"?n=String(n):n||(n="");let u=ZU(n);if(u)return u;let c=WU(n);if(c)return c;if(U2.test(n))return{name:"",ctrl:!1,meta:!1,shift:!1,sequence:n,raw:n,isKittyProtocol:!0,isPrintable:!1};let d={name:"",ctrl:!1,meta:!1,shift:!1,sequence:n,raw:n};if(d.sequence=d.sequence||n||d.name,n==="\r"||n==="\x1B\r")d.raw=void 0,d.name="return",d.meta=n.length===2;else if(n===`
286
- `)d.name="enter";else if(n===" ")d.name="tab";else if(n==="\b"||n==="\x1B\b")d.name="backspace",d.meta=n.charAt(0)==="\x1B";else if(n==="\x7F"||n==="\x1B\x7F")d.name="backspace",d.meta=n.charAt(0)==="\x1B";else if(n==="\x1B"||n==="\x1B\x1B")d.name="escape",d.meta=n.length===2;else if(n===" "||n==="\x1B ")d.name="space",d.meta=n.length===2;else if(n.length===1&&n<="")d.name=String.fromCharCode(n.charCodeAt(0)+97-1),d.ctrl=!0;else if(n.length===1&&n>="0"&&n<="9")d.name="number";else if(n.length===1&&n>="a"&&n<="z")d.name=n;else if(n.length===1&&n>="A"&&n<="Z")d.name=n.toLowerCase(),d.shift=!0;else if(i=KU.exec(n))d.name=i[1].toLowerCase(),d.meta=!0,d.shift=/^[A-Z]$/.test(i[1]);else if(i=FU.exec(n)){let m=[...n];m[0]==="\x1B"&&m[1]==="\x1B"&&(d.meta=!0);let B=[i[1],i[2],i[4],i[6]].filter(Boolean).join(""),y=(i[3]||i[5]||1)-1;d.ctrl=!!(y&4),d.meta=d.meta||!!(y&10),d.shift=!!(y&1),d.code=B,d.name=w2[B]??"",d.shift=kU(B)||d.shift,d.ctrl=qU(B)||d.ctrl}return d},"parseKeypress"),L2=PU;var z2=Ot(Le(),1);var JQ=o(()=>(0,z2.useContext)(rB),"useStdinContext");var $U=o((n,i={})=>{let{setRawMode:u,internal_exitOnCtrlC:c,internal_eventEmitter:d}=JQ();(0,np.useEffect)(()=>{if(i.isActive!==!1)return u(!0),()=>{u(!1)}},[i.isActive,u]);let m=(0,np.useEffectEvent)(B=>{let y=L2(B),Q={upArrow:y.name==="up",downArrow:y.name==="down",leftArrow:y.name==="left",rightArrow:y.name==="right",pageDown:y.name==="pagedown",pageUp:y.name==="pageup",home:y.name==="home",end:y.name==="end",return:y.name==="return",escape:y.name==="escape",ctrl:y.ctrl,shift:y.shift,tab:y.name==="tab",backspace:y.name==="backspace",delete:y.name==="delete",meta:y.meta,super:y.super??!1,hyper:y.hyper??!1,capsLock:y.capsLock??!1,numLock:y.numLock??!1,eventType:y.eventType},N;y.isKittyProtocol?y.isPrintable?N=y.text??y.name:y.ctrl&&y.name.length===1?N=y.name:N="":y.ctrl?N=y.name??"":N=y.sequence,!y.isKittyProtocol&&M2.includes(y.name)&&(N=""),N.startsWith("\x1B")&&(N=N.slice(1)),N.length===1&&/[A-Z]/.test(N)&&(Q.shift=!0),!(N==="c"&&Q.ctrl&&c)&&za.discreteUpdates(()=>{n(N,Q)})});(0,np.useEffect)(()=>{if(i.isActive!==!1)return d.on("input",m),()=>{d.removeListener("input",m)}},[i.isActive,d])},"useInput"),Ap=$U;var Y2=Ot(Le(),1);var J2=Ot(Le(),1);var tO=o(()=>(0,J2.useContext)(uB),"useApp"),KQ=tO;var K2=Ot(Le(),1);var eO=o(()=>(0,K2.useContext)(sB),"useStdout"),CB=eO;var nO=Ot(Le(),1);var FQ=Ot(Le(),1);var aO=Ot(Le(),1);var iO=Ot(Le(),1);var hB=Ot(Le(),1);var ap=Ot(Le(),1);var F2=Ot(Le(),1);var BB=Ot(Le(),1);var lO=/utf-?8/i;function _c(n=process.env){if(process.platform==="win32")return!0;let i=n.LC_ALL??n.LC_CTYPE??n.LANG;return i===void 0||i.trim().length===0?!1:lO.test(i)}o(_c,"terminalRendersUnicode");var oO=new Map([["\u2014","--"],["\u2013","-"],["\u2019","'"],["\u2018","'"],["\u201C",'"'],["\u201D",'"'],["\u2026","..."],["\xB7","-"],["\u276F",">"],["\u2039","<"],["\u25B8",">"],["\u2713","+"],["\u2691","!"],["\u23CE","Enter"],["\u2191","^"],["\u2193","v"],["\u2190","<-"],["\u2192","->"],["\xD7","x"],["\u2248","~"],["\u2717","x"]]);function k2(n,i=process.env){if(_c(i))return n;let u="";for(let c of n){if(c.codePointAt(0)<128){u+=c;continue}u+=oO.get(c)??"?"}return u}o(k2,"forTerminal");var Ze=Ot(Le(),1);var kt={accent:"#93a2ff",ok:"#7dc9a0",warn:"#d9a441",bad:"#e0796b"};var _l=Ot(Aa(),1);function X2({columns:n,connections:i}){let u=[["\u2191 \u2193 \xB7 k j","move the cursor"],["\u23CE \xB7 \u2192","open what the cursor is on, or run the action it names"],["esc \xB7 \u2190","back; it cancels an armed confirmation first"],["g \xB7 G","jump to the top, jump to the bottom"],...i?[["c","keys and accounts: provider key setup and the email connection"]]:[],["?","these shortcuts"],["q","quit; a run you started keeps going without this window"]];return(0,_l.jsxs)(ut,{flexDirection:"column",width:n,children:[(0,_l.jsx)(q,{color:kt.accent,bold:!0,children:"Keyboard shortcuts"}),(0,_l.jsx)(ut,{marginTop:1,flexDirection:"column",children:u.map(([c,d])=>(0,_l.jsxs)(ut,{children:[(0,_l.jsx)(ut,{width:16,children:(0,_l.jsx)(q,{bold:!0,children:c})}),(0,_l.jsx)(q,{dimColor:!0,children:d})]},c))}),(0,_l.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,_l.jsx)(q,{dimColor:!0,children:"Starting a run asks twice when it spends money: the first \u23CE arms and"}),(0,_l.jsx)(q,{dimColor:!0,children:"restates the cost, the second commits. A dry run never asks."})]})]})}o(X2,"HelpScreen");var Da=Ot(Le(),1);function sO(n){let i=new Map,u=[];for(let d of n){let m=d.study?.id;if(m===void 0){u.push(d);continue}let B=i.get(m);B===void 0?i.set(m,[d]):B.push(d)}let c=[...i.entries()].map(([d,m])=>{let B=m.filter(y=>y.liveness==="running");return{studyId:d,runs:m.length,live:B.length,...m[0]===void 0?{}:{latest:m[0]},liveRuns:B}});return c.sort((d,m)=>d.live!==m.live?m.live-d.live:QB(m.latest)-QB(d.latest)),{studies:c,unattributed:u}}o(sO,"groupRunsByStudy");function QB(n){if(n===void 0)return 0;for(let i of[n.completedAt,n.updatedAt,n.startedAt]){if(i===void 0)continue;let u=Date.parse(i);if(Number.isFinite(u))return u}return 0}o(QB,"recencyOf");function Z2(n,i){let c=(i===void 0?n:n.filter(y=>y.mode===i)).filter(y=>y.liveness==="finished"),d=c.map(y=>y.durationMs).filter(y=>typeof y=="number"&&Number.isFinite(y)&&y>=0).sort((y,Q)=>y-Q),m=c.map(y=>y.estimatedCostUsd).filter(y=>typeof y=="number"&&Number.isFinite(y)).sort((y,Q)=>y-Q),B=c.filter(y=>y.estimatedCostUsd===null||y.estimatedCostUsd===void 0).length;return{sample:c.length,...d.length===0?{}:{medianDurationMs:W2(d),durationRangeMs:{min:d[0],max:d[d.length-1]}},...m.length===0?{}:{medianCostUsd:W2(m)},costUnknown:B}}o(Z2,"expectationFor");function W2(n){let i=Math.floor(n.length/2);return n.length%2===1?n[i]:(n[i-1]+n[i])/2}o(W2,"median");function SB(n){if(n.sample===0)return"no runs yet";let i=[];if(n.durationRangeMs!==void 0){let{min:m,max:B}=n.durationRangeMs;i.push(m===B?wl(m):`${wl(m)}\u2013${wl(B)}`)}n.medianCostUsd!==void 0&&i.push(`~$${n.medianCostUsd.toFixed(2)} median`);let u=`${n.sample} run${n.sample===1?"":"s"}`,c=n.sample>0&&n.costUnknown===n.sample,d=n.costUnknown===0?"":c?", none priced":`, ${n.costUnknown} unpriced`;return i.length===0?c?`${u}, nothing recorded`:`${u}${d}, nothing timed`:`${i.join(" \xB7 ")} \xB7 ${u}${d}`}o(SB,"expectationLine");function vB(n){return n.runs===0?n.declared?"never run":"no runs":n.liveExpectation.sample>0?SB(n.liveExpectation):`${n.runs} ${n.runs===1?"run":"runs"}, none live`}o(vB,"studySummaryLine");function wl(n){let i=Math.max(0,Math.round(n/1e3));if(i<60)return`${i}s`;let u=Math.floor(i/60);if(u<60)return i%60===0?`${u}m`:`${u}m ${i%60}s`;let c=Math.floor(u/60);return u%60===0?`${c}h`:`${c}h ${u%60}m`}o(wl,"formatDuration");function mg(n,i){let u=Math.max(8,Math.floor(i.width)),c=Math.max(1,Math.floor(i.maxLines)),d=n.replace(/\*\*([^*]+)\*\*/g,"$1").replace(/\s*\n+\s*/g," ").replace(/\s{2,}/g," ").trim();if(d==="")return{lines:[],truncated:!1};let m=d.split(" "),B=[],y="",Q=0;for(;Q<m.length;Q+=1){let b=m[Q],O=y===""?b:`${y} ${b}`;if(O.length<=u){y=O;continue}if(y!==""&&B.push(y),y=b.length<=u?b:`${b.slice(0,u-1)}\u2026`,b.length>u&&(B.push(y),y=""),B.length===c)break}B.length<c&&y!==""&&(B.push(y),Q=m.length);let N=Q<m.length;if(N&&B.length>0){let b=B[B.length-1];B[B.length-1]=b.length+1<=u?`${b}\u2026`:`${b.slice(0,u-1)}\u2026`}return{lines:B,truncated:N}}o(mg,"normalizeThought");function Xr(n){let i=Math.max(0,Math.floor(n.total)),u=Math.max(1,Math.floor(n.viewport));if(i<=u)return{start:0,end:i};let c=Math.min(Math.max(0,Math.floor(n.selected)),i-1),d=Math.min(Math.max(0,Math.floor(n.margin??1)),Math.floor((u-1)/2)),m=Math.min(Math.max(0,c-d),i-u);return c>=m+u-d&&(m=Math.min(c-u+1+d,i-u)),m=Math.max(0,Math.min(m,i-u)),{start:m,end:m+u}}o(Xr,"listWindow");function P2(n){return(n.split("/").pop()??n).replace(/\.(ya?ml)$/i,"")}o(P2,"studyNameFromPath");function $2(n,i){let{studies:u,unattributed:c}=sO(i),d=new Map(u.map(O=>[O.studyId,O])),m=new Map;for(let O of i){let x=O.study?.id;if(x===void 0)continue;let L=m.get(x);L===void 0?m.set(x,[O]):L.push(O)}let B=new Map;for(let O of n)B.set(O.id,(B.get(O.id)??0)+1);let y=o((O,x,L)=>{let j=d.get(O),k=x?.path;return{key:k??`id:${O}`,studyId:O,name:k===void 0?O:P2(k),...x?.title===void 0?{}:{title:x.title},...k===void 0?{}:{path:k},...x?.origin===void 0?{}:{origin:x.origin},declared:L,label:x?.title??(k===void 0?O:P2(k)),...x?.description===void 0?{}:{description:x.description},sharesIdWith:Math.max(0,(B.get(O)??0)-1),runs:j?.runs??0,live:j?.live??0,...j?.latest===void 0?{}:{latest:j.latest},liveRuns:j?.liveRuns??[],expectation:Z2(m.get(O)??[]),liveExpectation:Z2(m.get(O)??[],"live")}},"build"),Q=new Set(n.map(O=>O.id)),N=[...n.map(O=>y(O.id,O,!0)),...u.filter(O=>!Q.has(O.studyId)).map(O=>y(O.studyId,void 0,!1))];cO(N);let b=o(O=>O.label,"label");return N.sort((O,x)=>{if(O.live!==x.live)return x.live-O.live;let L=o(k=>k.runs>0?0:k.declared?1:2,"rank");if(L(O)!==L(x))return L(O)-L(x);if(O.runs>0&&x.runs>0){let k=QB(x.latest)-QB(O.latest);if(k!==0)return k}let j=b(O).localeCompare(b(x));return j!==0?j:O.key.localeCompare(x.key)}),{rows:N,unattributed:c}}o($2,"studyRows");function cO(n){let i=o(d=>{let m=new Map;for(let B of d)m.set(B,(m.get(B)??0)+1);return m},"count"),u=i(n.map(d=>d.title??d.name)),c=i(n.map(d=>d.name));for(let d of n){let m=d.title??d.name;if((u.get(m)??0)===1){d.label=m;continue}d.label=(c.get(d.name)??0)===1?d.name:d.path??d.name}}o(cO,"assignLabels");function Xo(n,i){let u=Math.max(4,Math.floor(i));return n.length<=u?n:`${n.slice(0,u-1)}\u2026`}o(Xo,"fitLabelToWidth");function Mn(n){return n===void 0?{}:{color:n}}o(Mn,"color");import tN from"node:path";var dO=tN.join(".humanish","runs"),F9=tN.join(dO,"latest.json");var gO=5e3,r7=gO*3;var EO={running:"running",interrupted:"interrupted",passed:"passed",failed:"failed",blocked:"blocked",timed_out:"timed out",no_verdict:"no verdict",dry_run:"dry run",unknown:"unknown"},mO={running:"live",interrupted:"warn",passed:"pass",failed:"fail",blocked:"warn",timed_out:"warn",no_verdict:"warn",dry_run:"neutral",unknown:"neutral"};function Zr(n,i){return{state:n,label:EO[n],tone:mO[n],...i===void 0?{}:{reason:i}}}o(Zr,"shown");function Wr(n){if(n.liveness==="running")return Zr("running");if(n.liveness==="interrupted")return Zr("interrupted");let i=n.ok===!1&&n.failure!==void 0?`${n.failure.kind}: ${n.failure.message}`:void 0;return n.verdict==="blocked"?Zr("blocked",i):n.verdict==="timed_out"?Zr("timed_out",i):n.verdict==="fail"||n.ok===!1?Zr("failed",i):n.verdict==="pass"?Zr("passed"):n.verdict==="contract_proof_only"?Zr(n.mode==="dry-run"?"dry_run":"no_verdict"):Zr("unknown")}o(Wr,"runDisplay");var mo=Ot(Aa(),1),pO=96;function pg(n){return Math.max(20,Math.min(pO,n))}o(pg,"contentWidth");function eN({columns:n,context:i,breadcrumb:u,hints:c,children:d}){let m=pg(n);return(0,mo.jsxs)(ut,{flexDirection:"column",width:m,children:[(0,mo.jsxs)(ut,{width:m,children:[(0,mo.jsx)(q,{bold:!0,children:"human(ish)"}),(0,mo.jsx)(ut,{flexGrow:1}),i===void 0?null:(0,mo.jsx)(q,{dimColor:!0,wrap:"truncate-start",children:i})]}),u===void 0?null:(0,mo.jsx)(q,{dimColor:!0,wrap:"truncate-start",children:u}),(0,mo.jsx)(ut,{marginTop:1,flexDirection:"column",children:d}),(0,mo.jsx)(ut,{marginTop:1,children:(0,mo.jsx)(q,{dimColor:!0,children:c})})]})}o(eN,"Frame");var qQ=_c()?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["|","/","-","\\","|","/","-","\\","|","/"];function ip(n){return qQ[Math.abs(Math.floor(n))%qQ.length]??qQ[0]}o(ip,"spinnerFrame");function yi(n){return n?_c()?"\u276F":">":" "}o(yi,"gutter");function lp(n){let{state:i,tone:u}=Wr(n);if(i==="running")return ip(n.tick??0);let c=_c();return u==="pass"?c?"\u2713":"+":u==="fail"||u==="warn"?c?"\u2691":"!":c?"\xB7":"-"}o(lp,"verdictGlyph");var CO={live:kt.ok,fail:kt.bad,warn:kt.warn,pass:void 0,neutral:void 0},Cg=o(n=>Mn(CO[Wr(n).tone]),"glyphColor");var DB=Ot(Le(),1);function RB(){let{stdout:n}=CB(),i=o(()=>({columns:Math.max(20,n.columns||80),rows:Math.max(6,n.rows||24)}),"read"),[u,c]=(0,DB.useState)(i);return(0,DB.useEffect)(()=>{let d=o(()=>{c(B=>{let y=i();return y.columns===B.columns&&y.rows===B.rows?B:y})},"update");n.on("resize",d);let m=setTimeout(d,0);return()=>{n.off("resize",d),clearTimeout(m)}},[n]),u}o(RB,"useTerminalSize");var ht=Ot(Aa(),1),hO=400;function nN({capabilities:n,columns:i,notice:u,onBack:c,onKeyEntry:d}){let[m,B]=(0,Da.useState)(),[y,Q]=(0,Da.useState)(u),[N,b]=(0,Da.useState)(!1),[O,x]=(0,Da.useState)("home"),L=(0,Da.useRef)(!1),[j,k]=(0,Da.useState)(!0),[F,gt]=(0,Da.useState)(0),[lt,Pt]=(0,Da.useState)({kind:"home"}),[Dt,ue]=(0,Da.useState)(),[se,fe]=(0,Da.useState)([]),[Tt,Ct]=(0,Da.useState)([]),{rows:qt}=RB(),ie=(0,Da.useCallback)(async()=>{k(!0);try{let xt=await n.read();B(xt),ue(xt.authentication)}catch{B(void 0),Q("Could not read connection setup. Recheck to try again.")}finally{k(!1)}},[n]);(0,Da.useEffect)(()=>{ie()},[ie]);let Gt=m?.connections.some(xt=>xt.name==="agentmail"&&xt.apiKeyEnv==="AGENTMAIL_API_KEY"),Fe=m?.credential.source,ve=Fe==="process env"?"session environment":Fe?.includes("provider.env")?"project env file":"saved key",st=!!n.studies&&!!n.configure,Rt=Tt.filter(xt=>xt.status!=="closed"||xt.unresolvedCount>0),Wt=j?[]:[...m?.ok?[{id:"key",label:m.credential.stored?"Replace stored key":"Add API key"},...m.credential.present&&!Gt?[{id:"save",label:"Use this key for this project"}]:[],...m.credential.present&&Gt&&n.check?[{id:"check",label:"Test authentication (read-only)"}]:[],...m.credential.present&&Gt&&st?[{id:"studies",label:"Use real email in a study"}]:[]]:[],...n.recovery?[{id:"recovery",label:"Review inbox cleanup"}]:[],{id:"read",label:"Recheck local setup"}],Nt=lt.kind==="home"?Wt:lt.kind==="check"?[{id:"check",label:"Check again"},{id:"home",label:"Back to Connections"}]:lt.kind==="studies"?se.map((xt,_e)=>({id:`study-${_e}`,label:xt.title})):lt.kind==="preview"?[{id:"apply",label:"Save study copy"},{id:"studies",label:"Cancel"}]:lt.kind==="saved"?[{id:"home",label:"Back to Connections"}]:lt.kind==="recovery"?Rt.map((xt,_e)=>({id:`recovery-${_e}`,label:`${xt.runId} \xB7 ${xt.unresolvedCount} pending`})):[...lt.entry.activeOwner===!1&&lt.entry.unresolvedCount>0&&n.recover?[{id:"recover",label:"Release study inboxes"}]:[],{id:"recovery",label:"Back to cleanup"}],jt=Math.min(F,Math.max(0,Nt.length-1));function De(xt){Pt(xt),gt(0),Q(void 0)}o(De,"go");function dn(){lt.kind==="home"?c():De({kind:lt.kind==="preview"?"studies":lt.kind==="recover"?"recovery":"home"})}o(dn,"back");async function et(xt){if(!L.current){L.current=!0,x(lt.kind),b(!0);try{await xt()}catch{Q("The action could not complete. Recheck before retrying.")}finally{L.current=!1,b(!1)}}}o(et,"run"),Ap((xt,_e)=>{if(L.current||j)return;if(_e.escape||_e.leftArrow){dn();return}if(_e.upArrow||xt==="k"){gt(Lt=>Math.max(0,Lt-1));return}if(_e.downArrow||xt==="j"){gt(Lt=>Math.min(Math.max(0,Nt.length-1),Lt+1));return}if(!_e.return)return;let le=Nt[jt]?.id;if(le){if(le==="key"){d();return}if(le==="home"){De({kind:"home"});return}(le==="apply"&&lt.kind==="preview"||le==="recover"&&lt.kind==="recover")&&Date.now()-lt.openedAt<hO||et(async()=>{if(le==="read"||le==="save"){le==="save"&&Q((await n.save()).message),ue(void 0),await ie(),gt(0);return}if(le==="check"&&n.check){De({kind:"check"}),ue(void 0),ue(await n.check());return}if(le==="studies"&&n.studies){let Lt=await n.studies();fe(Lt),De({kind:"studies"});return}if(le.startsWith("study-")&&n.configure){let Lt=se[jt];if(!Lt)return;let It=await n.configure(Lt.path,!1);if(!It.ok||!It.path||!It.planToken){Q(It.message);return}De({kind:"preview",study:Lt,plan:It,openedAt:Date.now()});return}if(le==="apply"&&lt.kind==="preview"&&n.configure&&lt.plan.planToken){let Lt=await n.configure(lt.study.path,!0,lt.plan.planToken);if(!Lt.ok||!Lt.applied||!Lt.path){De({kind:"studies"}),Q(Lt.message);return}De({kind:"saved",path:Lt.path});return}if(le==="recovery"&&n.recovery){Ct(await n.recovery()),De({kind:"recovery"});return}if(le.startsWith("recovery-")){let Lt=Rt[jt];Lt&&De({kind:"recover",entry:Lt,openedAt:Date.now()});return}if(le==="recover"&&lt.kind==="recover"&&n.recover&&n.recovery&&lt.entry.activeOwner===!1){let Lt=await n.recover(lt.entry.runId,lt.entry.connectionName);Ct(await n.recovery()),De({kind:"recovery"}),Q(Lt.message)}})}});let Mt=Xr({total:Nt.length,selected:jt,viewport:lt.kind==="studies"||lt.kind==="recovery"?Math.max(2,qt-14):Nt.length}),te=(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[Mt.start>0?(0,ht.jsxs)(q,{dimColor:!0,children:["\u2191 ",Mt.start," more"]}):null,Nt.slice(Mt.start,Mt.end).map((xt,_e)=>{let le=Mt.start+_e;return(0,ht.jsxs)(q,{bold:le===jt,...Mn(le===jt?kt.accent:void 0),children:[yi(le===jt)," ",Xo(xt.label,i-3),N&&O===lt.kind&&le===jt?"\u2026":""]},xt.id)}),Mt.end<Nt.length?(0,ht.jsxs)(q,{dimColor:!0,children:["\u2193 ",Nt.length-Mt.end," more"]}):null]});return(0,ht.jsxs)(ut,{flexDirection:"column",width:i,children:[lt.kind==="home"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"AgentMail \xB7 hosted email"}),(0,ht.jsxs)(q,{children:["Connection:"," ",j?"checking\u2026":m?.ok?Gt?"agentmail \xB7 saved":"not saved for this project":"unavailable"]}),(0,ht.jsxs)(q,{children:["Key:"," ",m?m.credential.present?`present \xB7 ${ve}`:"missing":"checking\u2026"]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Provider authentication:"," ",Dt?.authenticated===!0?"passed":Dt?.authenticated===!1?"rejected":Dt?"unknown":"not checked"]}),m?.ok===!1?(0,ht.jsx)(q,{color:kt.bad,children:m.message}):null,m?.credential.explicitlyEmpty?(0,ht.jsx)(q,{color:kt.warn,children:"An empty AGENTMAIL_API_KEY overrides the stored key. Unset it and reopen the TUI."}):m?.credential.strict&&!m.credential.present?(0,ht.jsx)(q,{color:kt.warn,children:"Strict key mode ignores saved keys. Reopen without HUMANISH_STRICT_KEYS=1, or pass an env file."}):(Fe==="process env"||Fe?.includes("provider.env"))&&m?.credential.stored?(0,ht.jsx)(q,{dimColor:!0,children:"Env and project keys take precedence over your saved key."}):null,te,y?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{children:y})}):null,(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{dimColor:!0,children:"Get a key: https://console.agentmail.to"}),(0,ht.jsx)(q,{dimColor:!0,children:"Key entry is hidden. Saved keys apply to all your projects."}),st?(0,ht.jsx)(q,{dimColor:!0,children:"Fresh inbox per participant \xB7 hosted email"}):(0,ht.jsx)(q,{color:kt.warn,children:"Email receiving in studies is not available yet."}),(0,ht.jsx)(q,{dimColor:!0,children:"Local capture: per study \xB7 SMS: unavailable"})]})]}):lt.kind==="check"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Authentication check"}),N&&!Dt?(0,ht.jsx)(q,{children:"Contacting AgentMail\u2026"}):Dt?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsxs)(q,{children:["Credential: ",Dt.credentialPresent?"present":"missing"]}),(0,ht.jsxs)(q,{children:["Authentication:"," ",Dt.authenticated===!0?"passed":Dt.authenticated===!1?"rejected":"unknown"]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Inbox permissions: ",Dt.permissions]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Capacity: ",Dt.capacity," \xB7 delivery: untested"]}),(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{children:Dt.message})}),Dt.checkedAt?(0,ht.jsxs)(q,{dimColor:!0,children:["Checked: ",Dt.checkedAt]}):null]}):(0,ht.jsx)(q,{children:"Authentication is unknown."}),te]}):lt.kind==="studies"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Choose a study for real email"}),(0,ht.jsx)(q,{dimColor:!0,children:"Preview a local copy before saving."}),se.length?te:(0,ht.jsx)(q,{children:"No studies are available in this project."}),se[jt]?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{dimColor:!0,children:se[jt].path})}):null]}):lt.kind==="preview"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Save email-enabled study"}),(0,ht.jsxs)(q,{dimColor:!0,children:["From: ",lt.study.path]}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Save as:"}),(0,ht.jsx)(q,{children:lt.plan.path})]}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Fresh inbox for each participant."}),(0,ht.jsx)(q,{children:"Mail is hosted. Models may see content."}),(0,ht.jsx)(q,{children:"Recordings remain restricted for sharing."}),(0,ht.jsx)(q,{children:"Provider charges are separate."})]}),te]}):lt.kind==="saved"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.ok,children:"Email study saved"}),(0,ht.jsx)(q,{children:lt.path}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Select this study from Studies to start."}),(0,ht.jsx)(q,{dimColor:!0,children:"Or run this exact path:"}),(0,ht.jsxs)(q,{children:["humanish run ",lt.path]})]}),te]}):lt.kind==="recovery"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Inbox cleanup"}),(0,ht.jsx)(q,{dimColor:!0,children:"Study completion and inbox cleanup are separate."}),Rt.length?te:(0,ht.jsx)(q,{children:"No pending inbox cleanup."}),Rt[jt]?(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:Rt[jt].runId}),(0,ht.jsxs)(q,{dimColor:!0,children:["Connection: ",Rt[jt].connectionName]})]}):null]}):(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Review inbox cleanup"}),(0,ht.jsx)(q,{children:lt.entry.runId}),(0,ht.jsxs)(q,{children:["Connection: ",lt.entry.connectionName]}),(0,ht.jsxs)(q,{children:[lt.entry.unresolvedCount," pending \xB7 ",lt.entry.participantCount," participants"]}),(0,ht.jsx)(ut,{marginTop:1,flexDirection:"column",children:lt.entry.activeOwner===!0?(0,ht.jsx)(q,{color:kt.warn,children:"This run has an active owner. Cleanup is unavailable while it is running."}):lt.entry.activeOwner===null?(0,ht.jsx)(q,{color:kt.warn,children:"Ownership is unknown. Cleanup is unavailable until ownership can be verified."}):(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{children:"Release this study\u2019s owned inboxes."}),(0,ht.jsx)(q,{dimColor:!0,children:"An uncertain creation may be replayed, then released. Other inboxes are untouched."})]})}),te]}),lt.kind!=="home"&&y?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{color:kt.warn,children:y})}):null,lt.kind!=="home"&&N&&O===lt.kind?(0,ht.jsx)(q,{dimColor:!0,children:"Working\u2026"}):null]})}o(nN,"ConnectionsScreen");import hg from"node:path";var j7=[{relativeDir:hg.join("humanish","studies"),origin:"committed",family:"studies"},{relativeDir:hg.join(".humanish","studies"),origin:"ignored",family:"studies"},{relativeDir:hg.join(".humanish","local","studies"),origin:"ignored",family:"studies"},{relativeDir:hg.join("humanish","labs"),origin:"committed",family:"labs"},{relativeDir:hg.join(".humanish","labs"),origin:"ignored",family:"labs"},{relativeDir:hg.join(".humanish","local","labs"),origin:"ignored",family:"labs"}],BO=[".yaml",".yml"];function AN(n){let i=BO.find(u=>n.endsWith(u));return i===void 0?void 0:n.slice(0,-i.length)}o(AN,"studyFileStem");function jQ(n){switch(n.name){case"studies":return"studies";case"all-runs":return"all-runs";case"study":return`study:${n.studyKey}`;default:return`run:${n.runId}`}}o(jQ,"screenKey");function aN(){return{stack:[{name:"studies"}],selection:{},quit:!1}}o(aN,"initialNav");function op(n){return n.stack[n.stack.length-1]??{name:"studies"}}o(op,"currentScreen");function iN(n){return n.selection[jQ(op(n))]??0}o(iN,"selectedIndex");function lN(n,i){switch(i.type){case"enter":return{...n,stack:[...n.stack,i.screen]};case"back":return n.stack.length<=1?{...n,quit:!0}:{...n,stack:n.stack.slice(0,-1)};case"move":{if(i.total<=0)return n;let u=jQ(op(n)),c=n.selection[u]??0,d=Math.min(Math.max(0,c+i.delta),i.total-1);return d===c?n:{...n,selection:{...n.selection,[u]:d}}}case"select":{if(i.total<=0)return n;let u=jQ(op(n)),c=Math.min(Math.max(0,i.index),i.total-1);return{...n,selection:{...n.selection,[u]:c}}}default:return{...n,quit:!0}}}o(lN,"navigate");function up(n){let i=n.estimatedCostUsd;return typeof i=="number"&&Number.isFinite(i)&&i>=0?i:i===void 0&&n.mode==="dry-run"?0:null}o(up,"runEstimateUsd");function IO(n,i){let u=up({estimatedCostUsd:n}),c=up({estimatedCostUsd:i});return u===null&&c===null?null:QO((u??0)+(c??0))}o(IO,"sumEstimatedUsd");function yO(n,i){if(n==null)return{run:null,analysis:null,total:null};let u={usd:up({estimatedCostUsd:n.estimatedTotalUsd}),complete:n.fullyEstimated===void 0?null:n.fullyEstimated,ratesAsOf:n.ratesAsOf??null,placeholder:n.placeholder===!0},c=i==null?null:{...i,estimatedUsd:up({estimatedCostUsd:i.estimatedUsd}),complete:i.complete&&up({estimatedCostUsd:i.estimatedUsd})!==null},d=IO(u.usd,c?.estimatedUsd??null);if(d===null)return{run:u,analysis:c,total:null};let m=u.usd===null||u.complete===!1||c?.complete===!1;return{run:u,analysis:c,total:{usd:d,complete:m?!1:u.complete}}}o(yO,"runCost");function Bg(n){return yO({estimatedTotalUsd:n.estimatedCostUsd??null,...n.estimatedCostComplete===void 0?{}:{fullyEstimated:n.estimatedCostComplete}},n.analysisCost)}o(Bg,"indexedRunCost");function QO(n){return Math.round(n*1e6)/1e6}o(QO,"round6");function SO(n){return n===1?"analysis":`${n} analyses`}o(SO,"analysesNoun");function NB(n){if(n.run===null)return;let i=n.total===null?"cost not estimated":`~$${n.total.usd.toFixed(2)} est.${n.total.complete===!1?" plus unpriced usage":""}`;return n.analysis===null?i:`${i}, with ${SO(n.analysis.requests)}`}o(NB,"runCostLabel");var bn=Ot(Aa(),1);function rN({runs:n,details:i,labels:u,expected:c,selected:d,columns:m,viewport:B,tick:y,now:Q}){if(n.length===0)return(0,bn.jsxs)(ut,{flexDirection:"column",children:[(0,bn.jsx)(q,{children:"No one is working right now."}),(0,bn.jsx)(q,{dimColor:!0,children:"Start a run from any study and it appears here."})]});let N=Xr({total:n.length,selected:d,viewport:Math.max(2,B-6)}),b=n[Math.min(Math.max(0,d),n.length-1)],O=b===void 0?void 0:i.get(b.runId),x=O?.participants[0],L=x?.thought===void 0?void 0:mg(x.thought.text,{width:Math.max(16,m-2),maxLines:2});return(0,bn.jsxs)(ut,{flexDirection:"column",children:[n.slice(N.start,N.end).map((j,k)=>(0,bn.jsx)(vO,{run:j,who:oN(i.get(j.runId))??"starting\u2026",study:u.get(j.runId)??j.study?.id??"",expectedMs:c.get(j.study?.id??""),active:N.start+k===d,columns:m,tick:y,now:Q},j.runId)),L===void 0?null:(0,bn.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[L.lines.map((j,k)=>(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsx)(ut,{width:2,flexShrink:0,children:(0,bn.jsx)(q,{color:kt.accent,children:"\u258C"})}),(0,bn.jsxs)(q,{dimColor:!0,wrap:"truncate-end",children:[k===0?`"${j}`:j,k===L.lines.length-1?'"':""]})]},k)),(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsx)(ut,{width:2,flexShrink:0,children:(0,bn.jsx)(q,{children:" "})}),(0,bn.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:Xo([oN(O),u.get(b?.runId??"")].filter(Boolean).join(" \xB7 "),Math.max(10,m-2))})]})]}),(0,bn.jsx)(ut,{marginTop:1,children:(0,bn.jsx)(q,{dimColor:!0,children:DO(n,i)})}),(0,bn.jsx)(q,{dimColor:!0,children:"Run + analysis costs: humanish stats"})]})}o(rN,"AllRunsScreen");function oN(n){return n?.participants[0]?.label}o(oN,"personaOf");function vO({run:n,who:i,study:u,expectedMs:c,active:d,columns:m,tick:B,now:y}){let Q=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),N=Number.isFinite(Q)?uN(y-Q):"",b=c===void 0?N:`${N} / ~${uN(c)}`,O=Math.max(10,Math.floor((m-b.length-6)*.5)),x=Math.max(8,m-b.length-O-6);return(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsxs)(q,{...Mn(d?kt.accent:void 0),bold:d,children:[yi(d)," "]}),(0,bn.jsxs)(q,{color:kt.ok,children:[ip(B)," "]}),(0,bn.jsx)(ut,{width:O,children:(0,bn.jsx)(q,{...Mn(d?kt.accent:void 0),bold:d,wrap:"truncate-end",children:Xo(i,O)})}),(0,bn.jsx)(ut,{width:x,children:(0,bn.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:Xo(u,x)})}),(0,bn.jsx)(ut,{flexGrow:1}),(0,bn.jsx)(q,{dimColor:!0,children:b})]})}o(vO,"RunRow");function DO(n,i){let u=0,c=0,d=0;for(let Q of n){let N=Q.estimatedCostUsd===void 0?i.get(Q.runId)?.participants[0]?.estimatedCostUsd:Bg(Q).total?.usd;d+=Q.analysisCost?.requests??0,typeof N=="number"&&(u+=N,c+=1)}if(c===0)return"no spend recorded yet; a live run prices itself as it goes";let m=n.length-c,B=m===0?"":` \xB7 ${m} not priced yet`,y=d===0?"":` \xB7 with ${d===1?"1 analysis":`${d} analyses`}`;return`run spend ~$${u.toFixed(2)} across ${c} of ${n.length}${B}${y}`}o(DO,"spendLine");function uN(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60);return u<60?`${u}:${String(i%60).padStart(2,"0")}`:wl(n)}o(uN,"clockOf");var Ht=Ot(Aa(),1);function xB(n,i){return[...i?[{kind:"start",mode:"dry-run"},{kind:"start",mode:"live"}]:[],...n.map(c=>({kind:"run",run:c}))]}o(xB,"studyItems");function fN(n){let{row:i,summary:u,runs:c,selected:d,columns:m,viewport:B,now:y,tick:Q,canStart:N}=n,b=xB(c,N);return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[u?.description===void 0?null:(0,Ht.jsx)(q,{wrap:"truncate-end",children:OO(u.description)}),u?.subject===void 0?null:(0,Ht.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:[u.subject,u.participants,u.model,u.reasoningEffort===void 0?void 0:`${u.reasoningEffort} effort`].filter(Boolean).join(" \xB7 ")}),(0,Ht.jsxs)(ut,{width:m,children:[(0,Ht.jsxs)(q,{dimColor:!0,wrap:"truncate-end",children:[vB(i),UO(u)]}),(0,Ht.jsx)(ut,{flexGrow:1}),u?.planRefusal!==void 0?(0,Ht.jsx)(q,{...Mn(kt.warn),children:"refused \u2717"}):u?.keysReady===void 0?null:(0,Ht.jsx)(q,{...Mn(u.keysReady?kt.ok:kt.warn),children:u.keysReady?"keys \u2713":"keys \u2717"})]}),u?.analysis===void 0?null:(0,Ht.jsx)(q,{wrap:"wrap",children:u.analysis.provider==="codex"?`After live runs: Codex account analyst \xB7 ${u.analysis.model} \xB7 remote inference \xB7 account limits apply; dollar cost unknown`:`After live runs: analysis \xB7 ${u.analysis.model} \xB7 separate $${u.analysis.maxCostUsd} admission estimate limit \xB7 not a billing cap`}),u?.runtime?(0,Ht.jsx)(q,{color:u.runtime.ok?kt.ok:kt.warn,children:u.runtime.message}):null,u?.participantReadiness?(0,Ht.jsx)(q,{color:u.participantReadiness.ok?kt.ok:kt.warn,children:u.participantReadiness.message}):null,u?.communications?(0,Ht.jsx)(q,{color:kt.warn,children:u.communications}):null,u?.planRefusal===void 0?null:(0,Ht.jsx)(ut,{width:m,children:(0,Ht.jsxs)(q,{wrap:"wrap",...Mn(kt.warn),children:["A live run is refused: ",u.planRefusal]})}),u?.keysReady===!1?(0,Ht.jsxs)(ut,{flexDirection:"column",width:m,children:[(0,Ht.jsxs)(q,{...Mn(kt.warn),children:[u.missingKeys?.join(", ")," not found"]}),(0,Ht.jsxs)(q,{dimColor:!0,children:[" ","humanish keys set openai"," ","\xB7 stores them for every project"]}),(0,Ht.jsxs)(q,{dimColor:!0,children:[" ","humanish tui --env-file .env"," ","\xB7 or just this session"]})]}):null,n.launchNote===void 0?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{dimColor:!0,children:n.launchNote})}),n.launchError===void 0?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{color:kt.bad,children:n.launchError})}),N?(0,Ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Ht.jsx)(NO,{...n,active:RO(b,d)}),n.confirming==="live"?(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsxs)(q,{color:kt.warn,children:[" ","start a live run? ",SB(n.row.liveExpectation),u?.analysis?u.analysis.provider==="codex"?" + Codex account analysis (remote inference; account limits apply, dollar cost unknown)":` + analysis ($${u.analysis.maxCostUsd} admission estimate limit, separate from participant spend)`:""," ","\xB7 \u23CE confirm \xB7 esc cancel"]})}):null]}):null,i.declared?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{color:kt.warn,children:n.retired??"no manifest here: renamed, deleted, or run from elsewhere"})}),i.sharesIdWith>0?(0,Ht.jsxs)(q,{color:kt.warn,children:[i.sharesIdWith+1,' manifests declare "',i.studyId,'": these runs are shared between them']}):null,(0,Ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Ht.jsx)(q,{dimColor:!0,children:"Runs"}),n.liveDetail?.automaticAnalysis===void 0?null:(0,Ht.jsxs)(q,{children:["Latest analysis: ",n.liveDetail.automaticAnalysis.state," \xB7 open run for details"]}),c.length===0?(0,Ht.jsx)(q,{dimColor:!0,children:" none yet"}):(0,Ht.jsx)(bO,{runs:c,liveDetail:n.liveDetail,selected:d-xB([],N).length,columns:m,viewport:Math.max(2,B-6),now:y,tick:Q,expectedMs:i.liveExpectation.medianDurationMs})]})]})}o(fN,"StudyScreen");function RO(n,i){let u=n[i];return u?.kind==="start"?u.mode:void 0}o(RO,"activeStart");function NO(n){let i=xO(n.columns,n.row,n.summary);return(0,Ht.jsxs)(Ht.Fragment,{children:[(0,Ht.jsx)(sN,{...n,mode:"dry-run",active:n.active==="dry-run",stacked:i}),(0,Ht.jsx)(sN,{...n,mode:"live",active:n.active==="live",stacked:i})]})}o(NO,"StartRows");function sN({mode:n,active:i,stacked:u,columns:c,row:d,summary:m}){let{label:B,value:y,blocked:Q}=gN(n,d,m),N=n==="live"?kt.warn:kt.accent,b=(0,Ht.jsxs)(q,{...Mn(i?N:void 0),bold:i,dimColor:Q&&!i,children:[yi(i)," ",B]}),O=(0,Ht.jsx)(q,{dimColor:!Q,...Mn(Q?kt.warn:void 0),children:y});return u?(0,Ht.jsxs)(ut,{flexDirection:"column",width:c,children:[b,(0,Ht.jsx)(ut,{marginLeft:4,children:O})]}):(0,Ht.jsxs)(ut,{width:c,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:b}),(0,Ht.jsx)(ut,{flexGrow:1,minWidth:dN}),O]})}o(sN,"StartRow");var dN=2;function gN(n,i,u){if(n==="dry-run")return{label:"Start a dry run",value:"free \xB7 no keys, no spend",blocked:!1};let c=u?.planRefusal!==void 0||u?.keysReady===!1||u?.runtime?.ok===!1||u?.participantReadiness?.ok===!1,d=SB(i.liveExpectation);return{label:"Start a live run",value:c?`${d} \xB7 ${TO(u)}`:d,blocked:c}}o(gN,"startRowText");function xO(n,i,u){return["dry-run","live"].some(c=>{let{label:d,value:m}=gN(c,i,u);return 2+[...d].length+dN+[...m].length>n})}o(xO,"startRowsStack");function TO(n){return n?.planRefusal!==void 0?"refused":n?.keysReady===!1?"needs keys":n?.runtime?.ok===!1?"needs runtime setup":"needs Codex login"}o(TO,"blocker");function bO({runs:n,liveDetail:i,selected:u,columns:c,viewport:d,now:m,tick:B,expectedMs:y}){let Q=Xr({total:n.length,selected:u,viewport:d});return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[Q.start>0?(0,Ht.jsx)(q,{dimColor:!0,children:` \u2191 ${Q.start} more`}):null,n.slice(Q.start,Q.end).map((N,b)=>N.liveness==="running"?(0,Ht.jsx)(_O,{run:N,detail:i,active:Q.start+b===u,columns:c,now:m,tick:B,expectedMs:y},N.runId):(0,Ht.jsx)(MO,{run:N,active:Q.start+b===u,columns:c},N.runId)),Q.end<n.length?(0,Ht.jsx)(q,{dimColor:!0,children:` \u2193 ${n.length-Q.end} more`}):null]})}o(bO,"RunList");function _O({run:n,detail:i,active:u,columns:c,now:d,tick:m,expectedMs:B}){let y=i?.participants[0],Q=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),N=Number.isFinite(Q)?cN(d-Q):void 0,b=B===void 0?"":` of ~${cN(B)}`,O=y?.thought===void 0?void 0:mg(y.thought.text,{width:Math.max(16,c-6),maxLines:3});return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[(0,Ht.jsxs)(ut,{width:c,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Mn(u?kt.accent:void 0),bold:u,children:[yi(u)," "]})}),(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{color:kt.ok,children:[lp({liveness:"running",tick:m})," "]})}),(0,Ht.jsx)(q,{...Mn(u?kt.accent:void 0),bold:u,wrap:"truncate-end",children:y?.label??"starting\u2026"}),(0,Ht.jsx)(ut,{flexGrow:1}),(0,Ht.jsx)(q,{dimColor:!0,children:N===void 0?"":`${N}${b}`})]}),O===void 0?null:(0,Ht.jsx)(ut,{flexDirection:"column",marginLeft:4,children:O.lines.map((x,L)=>(0,Ht.jsxs)(q,{dimColor:L>0,children:[L===0?`"${x}`:x,L===O.lines.length-1?'"':""]},L))}),y===void 0?null:(0,Ht.jsx)(ut,{width:c,children:(0,Ht.jsxs)(q,{dimColor:!0,children:[" ",wO(y)]})})]})}o(_O,"LiveRun");function wO(n){let i=[];return n.actions!==void 0&&i.push(`${n.actions} actions`),n.thoughts!==void 0&&i.push(`${n.thoughts} thoughts`),n.turns!==void 0&&i.push(`${n.turns} turns`),i.length===0?"working\u2026":i.join(" \xB7 ")}o(wO,"activityLine");function MO({run:n,active:i,columns:u}){let c=HO(n.completedAt??n.startedAt),d=Wr(n),m=d.state==="passed"?"":` \xB7 ${d.label}`,B=n.participants===void 0?d.state==="unknown"?"no verdict":d.label:`${n.participants.reachedGoal}/${n.participants.total} reached the goal${m}`,y=n.estimatedCostUsd===void 0||n.estimatedCostUsd===null&&n.analysisCost===void 0?"":` \xB7 run ${NB(Bg(n))}`,Q=[c,B].filter(Boolean).join(" \xB7 ")+y;return(0,Ht.jsxs)(ut,{width:u,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Mn(i?kt.accent:void 0),bold:i,children:[yi(i)," "]})}),(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Cg(n),children:[lp(n)," "]})}),(0,Ht.jsx)(q,{...Mn(i?kt.accent:void 0),bold:i,wrap:"truncate-end",children:Q})]})}o(MO,"PastRun");function UO(n){let i=n?.caps.laneUsd,u=n?.caps.studyUsd;if(i===void 0&&u===void 0)return"";let c=[];return i!==void 0&&c.push(`$${i} per participant`),u!==void 0&&c.push(`$${u} study`),` \xB7 caps ${c.join(" / ")}`}o(UO,"capsLine");function OO(n){let i=n.replace(/\s+/g," ").trim(),u=i.indexOf(". ");return u===-1?i:i.slice(0,u+1)}o(OO,"firstSentence");function HO(n){if(n===void 0)return"";let i=Date.parse(n);if(!Number.isFinite(i))return"";let u=new Date(i),c=o(d=>String(d).padStart(2,"0"),"pad");return`${c(u.getUTCMonth()+1)}-${c(u.getUTCDate())} ${c(u.getUTCHours())}:${c(u.getUTCMinutes())}`}o(HO,"shortDate");function cN(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60);return u<60?`${u}:${String(i%60).padStart(2,"0")}`:wl(n)}o(cN,"clockOf");var Un=Ot(Aa(),1);function rp(n,i){return["queued","running"].includes(i?.automaticAnalysis?.state??"")?i?.observerPath===void 0?["cancel-analysis"]:["observer","cancel-analysis"]:n.liveness==="interrupted"?i?.observerPath===void 0?["reclaim"]:["reclaim","observer"]:n.liveness==="running"?i?.observerPath===void 0?["stop"]:["stop","observer"]:i?.observerPath===void 0?["again"]:["observer","again"]}o(rp,"runActions");function GO(n){switch(n){case"observer":return"Open in Observer";case"again":return"Run again";case"stop":return"Stop this run";case"cancel-analysis":return"Cancel analysis";default:return"Reclaim: stop sandboxes, keep evidence"}}o(GO,"actionLabel");function EN({run:n,detail:i,columns:u,selected:c,tick:d,now:m,actionNote:B}){let y=i?.participants[0],Q=rp(n,i),N=n.liveness==="interrupted";return(0,Un.jsxs)(ut,{flexDirection:"column",children:[(0,Un.jsx)(ut,{children:(0,Un.jsxs)(q,{...Cg(n),bold:!0,children:[lp({...n,tick:d})," ",LO(n,y)]})}),N?(0,Un.jsx)(YO,{run:n,participant:y,now:m,columns:u}):(0,Un.jsx)(zO,{run:n,participant:y,columns:u}),i?.automaticAnalysis===void 0?null:(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Un.jsxs)(q,{children:["Analysis: ",i.automaticAnalysis.state]}),i.automaticAnalysis.reason===null?null:(0,Un.jsx)(q,{dimColor:!0,wrap:"wrap",children:i.automaticAnalysis.reason})]}),Q.length===0?null:(0,Un.jsx)(ut,{marginTop:1,flexDirection:"column",children:Q.map((b,O)=>(0,Un.jsx)(ut,{children:(0,Un.jsxs)(q,{...Mn(O===c?kt.accent:void 0),bold:O===c,children:[yi(O===c)," ",Xo(GO(b),Math.max(10,u-3))]})},b))}),B===void 0?null:(0,Un.jsx)(ut,{marginTop:1,children:(0,Un.jsx)(q,{dimColor:!0,wrap:"wrap",children:B})})]})}o(EN,"RunScreen");function LO(n,i){if(n.liveness==="interrupted")return"interrupted: no outcome recorded";if(n.liveness==="running"){let B=i?.label;return B===void 0?"starting\u2026":`${B} is working`}let u=Wr(n),c=n.participants;if(c===void 0)return u.state==="unknown"?"finished, no verdict recorded":u.label;let d=c.reportedFriction===void 0||c.reportedFriction===0?"":` \xB7 ${c.reportedFriction} reported friction`,m=u.state==="passed"?"":` \xB7 ${u.label}`;return`${c.reachedGoal}/${c.total} reached the goal${d}${m}`}o(LO,"headline");function zO({run:n,participant:i,columns:u}){let c=i?.thought===void 0?void 0:mg(i.thought.text,{width:Math.max(16,u),maxLines:3}),{reason:d}=Wr(n),m=[n.durationMs===void 0?void 0:wl(n.durationMs),i?.turns===void 0?void 0:`${i.turns} turns`,i?.thoughts===void 0?void 0:`${i.thoughts} thoughts`].filter(Boolean).join(" \xB7 ");return(0,Un.jsxs)(ut,{flexDirection:"column",children:[c===void 0?null:(0,Un.jsx)(ut,{marginTop:1,flexDirection:"column",children:c.lines.map((B,y)=>(0,Un.jsxs)(q,{children:[y===0?`"${B}`:B,y===c.lines.length-1?'"':""]},y))}),(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[d===void 0?null:(0,Un.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:`why: ${d}`}),m===""?null:(0,Un.jsx)(q,{dimColor:!0,children:m}),(0,Un.jsx)(q,{dimColor:!0,children:mN(n,i)})]})]})}o(zO,"FinishedFacts");function YO({run:n,participant:i,now:u,columns:c}){let d=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),m=n.updatedAt===void 0?Number.NaN:u-Date.parse(n.updatedAt),B=[i?.thoughts===void 0?void 0:`${i.thoughts} thoughts`,i?.actions===void 0?void 0:`${i.actions} actions`].filter(Boolean).join(" \xB7 ");return(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",width:c,children:[(0,Un.jsxs)(q,{dimColor:!0,children:[Number.isFinite(d)?`started ${JO(d)}`:"start time not recorded",Number.isFinite(m)?` \xB7 quiet ${wl(m)}`:"",B===""?"":` \xB7 ${B} captured`]}),(0,Un.jsxs)(ut,{children:[(0,Un.jsx)(q,{dimColor:!0,children:n.estimatedCostUsd===void 0&&i?.estimatedCostUsd===void 0?"cost unknown: it ended before pricing itself":mN(n,i)}),(0,Un.jsx)(q,{color:kt.warn,children:" sandboxes may still be running"})]})]})}o(YO,"InterruptedFacts");function mN(n,i){if(n.estimatedCostUsd===void 0){let u=i?.estimatedCostUsd;return u===void 0?"cost not recorded":u===null?"cost declared absent":`~$${u.toFixed(2)} participant model estimate`}return n.estimatedCostUsd===null&&n.analysisCost===void 0?"cost declared absent":`run ${NB(Bg(n))}`}o(mN,"costLine");function JO(n){let i=new Date(n),u=o(c=>String(c).padStart(2,"0"),"pad");return`${u(i.getUTCHours())}:${u(i.getUTCMinutes())}`}o(JO,"clockTime");var CN=Ot(Le(),1);var he=Ot(Aa(),1);function pN({retired:n}){let i=n.filter(c=>c.code==="HUMANISH_STUDY_V2_UNSUPPORTED").length,u=n.length-i;return(0,he.jsxs)(ut,{flexDirection:"column",children:[i===0?null:(0,he.jsx)(q,{color:kt.warn,children:`${i} study ${i===1?"file uses":"files use"} humanish.lab.v2, which humanish no longer reads. Run humanish migrate to convert ${i===1?"it":"them"}.`}),u===0?null:(0,he.jsx)(q,{color:kt.warn,children:`${u} study ${u===1?"file is":"files are"} in a labs/ folder, which humanish no longer reads. Move ${u===1?"it":"them"} to the matching studies/ folder; humanish study list names each one.`})]})}o(pN,"RetiredNote");function hN({rows:n,selected:i,columns:u,viewport:c,unattributed:d,tick:m,liveParticipants:B,now:y,initialized:Q,peerSelected:N,liveTotal:b,initArmed:O,actionNote:x,retired:L=[]}){if(n.length===0)return Q?(0,he.jsxs)(ut,{flexDirection:"column",children:[L.length>0?(0,he.jsx)(pN,{retired:L}):(0,he.jsx)(q,{children:"No studies here yet."}),(0,he.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,he.jsx)(q,{dimColor:!0,children:"A study file says who to send, to what, and what counts as done."}),(0,he.jsx)(q,{dimColor:!0,children:"Write one in humanish/studies/, or run `humanish init` for starter studies."})]})]}):(0,he.jsxs)(ut,{flexDirection:"column",children:[(0,he.jsx)(q,{children:"This directory is not a humanish project."}),(0,he.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,he.jsx)(q,{dimColor:!0,children:"A project is a humanish/ directory of studies and personas,"}),(0,he.jsx)(q,{dimColor:!0,children:"kept beside the app they study."})]}),(0,he.jsxs)(ut,{marginTop:1,children:[(0,he.jsxs)(q,{...Mn(kt.accent),bold:!0,children:[yi(!0)," Set up humanish here"]}),(0,he.jsx)(ut,{flexGrow:1}),(0,he.jsx)(q,{dimColor:!0,children:O?"\u23CE again to confirm \xB7 esc cancel":"writes humanish/ and updates package.json"})]}),x===void 0?null:(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsx)(q,{dimColor:!0,children:x})})]});let j=Xr({total:n.length,selected:i,viewport:c});return(0,he.jsxs)(ut,{flexDirection:"column",children:[j.start>0?(0,he.jsx)(q,{dimColor:!0,children:` \u2191 ${j.start} more`}):null,n.slice(j.start,j.end).map((k,F)=>{let gt=j.start+F,lt=gt>0?n[gt-1]:void 0,Pt=k.runs===0&&lt!==void 0&&lt.runs>0;return(0,he.jsxs)(CN.default.Fragment,{children:[Pt?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsxs)(q,{dimColor:!0,children:[" ","not yet run"]})}):null,(0,he.jsx)(FO,{row:k,columns:u,active:gt===i,tick:m,liveParticipants:B,now:y})]},k.key)}),j.end<n.length?(0,he.jsx)(q,{dimColor:!0,children:` \u2193 ${n.length-j.end} more`}):null,(0,he.jsxs)(ut,{marginTop:1,children:[(0,he.jsx)(q,{...Mn(N?kt.accent:void 0),bold:N,dimColor:!N,children:`${yi(N)} All runs`}),b>0?(0,he.jsx)(q,{color:kt.ok,children:` ${b} working`}):null]}),d>0?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsxs)(q,{dimColor:!0,children:[d," ",d===1?"run":"runs"," with no study"]})}):null,L.length>0?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsx)(pN,{retired:L})}):null,(0,he.jsxs)(ut,{marginTop:1,width:u,children:[(0,he.jsx)(ut,{flexShrink:0,children:(0,he.jsx)(q,{...Mn(kt.accent),children:"\u25B8"})}),(0,he.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:` ${KO(n[i],N)}`})]})]})}o(hN,"StudiesScreen");function KO(n,i){if(i)return"every run in this project, newest first, across every study";if(n===void 0)return"";let u=n.description?.split(/(?<=[.!?])\s/)[0]?.trim();return u!==void 0&&u.length>0?u:"no description in the manifest"}o(KO,"describe");function FO({row:n,columns:i,active:u,tick:c,liveParticipants:d,now:m}){let B=n.liveRuns[0],y=B===void 0?vB(n):kO(n,B,d.get(B.runId),m),Q=Math.max(10,Math.floor(i/2)-2),N=y.length<=Q?y:qO(n),b=Math.max(8,i-N.length-6);return(0,he.jsxs)(ut,{width:i,children:[(0,he.jsxs)(q,{...Mn(u?kt.accent:void 0),bold:u,children:[yi(u)," "]}),(0,he.jsxs)(q,{...Cg({liveness:B===void 0?"finished":"running"}),children:[B===void 0?" ":ip(c)," "]}),(0,he.jsx)(q,{...Mn(u?kt.accent:void 0),bold:u,wrap:"truncate-end",children:Xo(n.label,b)}),(0,he.jsx)(ut,{flexGrow:1}),(0,he.jsx)(q,{...Mn(B===void 0?void 0:kt.ok),dimColor:B===void 0,children:N})]})}o(FO,"StudyRowView");function kO(n,i,u,c){let d=i.startedAt===void 0?Number.NaN:Date.parse(i.startedAt),m=Number.isFinite(d)?jO(c-d):void 0,B=u??"starting\u2026",y=n.live>1?` +${n.live-1}`:"";return m===void 0?`${B}${y}`:`${B} \xB7 ${m}${y}`}o(kO,"liveStatus");function qO(n){return n.live>0?`${n.live} running`:n.runs===0?n.declared?"never run":"no runs":`${n.runs} runs`}o(qO,"fallbackStatus");function jO(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60),c=i%60;return u<60?`${u}:${String(c).padStart(2,"0")}`:wl(n)}o(jO,"clockOf");var Xi=Ot(Aa(),1),VO=6,VQ=2e3,XO=5e3,ZO=100,XQ=400,WO=120;function QN({options:n,onReady:i,onKeyEntry:u,now:c,tick:d}){let{exit:m}=KQ(),B=RB(),[y,Q]=(0,Ze.useReducer)(lN,void 0,aN),[N,b]=(0,Ze.useState)(void 0),[O,x]=(0,Ze.useState)(void 0),[L,j]=(0,Ze.useState)(void 0),[k,F]=(0,Ze.useState)(void 0),[gt,lt]=(0,Ze.useState)(void 0),[Pt,Dt]=(0,Ze.useState)(void 0),[ue,se]=(0,Ze.useState)(void 0),[fe,Tt]=(0,Ze.useState)(void 0),[Ct,qt]=(0,Ze.useState)(void 0),[ie,Gt]=(0,Ze.useState)(!1),[Fe,ve]=(0,Ze.useState)(n.initialScreen==="connections"),[st,Rt]=(0,Ze.useState)(void 0),[Wt,Nt]=(0,Ze.useState)(0),jt=d??Wt,[De,dn]=(0,Ze.useState)(void 0),[et,Mt]=(0,Ze.useState)(new Map),xt=(0,Ze.useMemo)(()=>n.capabilities.readProjectState(n.cwd),[n]).initialized||(N?.retired.length??0)>0,_e=c??Date.now(),le=(0,Ze.useRef)(void 0),Lt=(0,Ze.useRef)({name:"studies"});(0,Ze.useEffect)(()=>{let _t=!1,oe=o(async()=>{try{let[Re,cn]=await Promise.all([n.capabilities.readRunIndex(n.cwd),n.capabilities.listStudies(n.cwd)]);if(_t)return;x(void 0),b(IN(Re,cn.studies,cn.retired))}catch(Re){if(_t)return;x(Re instanceof Error?Re.message:String(Re))}},"read");oe();let Pe=setInterval(()=>{oe()},VQ);return Pe.unref?.(),()=>{_t=!0,clearInterval(Pe)}},[n]),(0,Ze.useEffect)(()=>{(N!==void 0||O!==void 0)&&i?.()},[N,O,i]);let It=op(y),ne=iN(y),_n=yN(It,N,ue);(0,Ze.useEffect)(()=>{Lt.current=It;let _t=nH(It,N,ne);_t!==void 0&&(le.current=_t)},[It,N,ne]),(0,Ze.useEffect)(()=>{if(N===void 0)return;let _t=le.current;if(_t===void 0)return;let oe=AH(It,N,_t);oe>=0&&oe!==ne&&Q({type:"select",index:oe,total:yN(It,N,ue)})},[N,It]);let DA=(0,Ze.useCallback)(async(_t,oe)=>{if(oe==="live"&&L!=="live"){j("live"),Dt(Date.now());return}if(oe==="live"&&Pt!==void 0&&Date.now()-Pt<XQ)return;j(void 0),Dt(void 0),F(void 0),lt({studyKey:_t.key,text:`starting ${_t.name}\u2026`});let Pe=await n.capabilities.startRun({cwd:n.cwd,study:_t.name,..._t.path?{manifestPath:_t.path}:{},mode:oe});if(!Pe.ok){lt(void 0),F({studyKey:_t.key,text:Pe.error.message});return}let Re=Date.parse(Pe.run.launchedAt),cn=o(vn=>{if(vn.pid!==Pe.run.pid)return!1;let yt=vn.startedAt===void 0?Number.NaN:Date.parse(vn.startedAt);return!Number.isFinite(yt)||!Number.isFinite(Re)?!1:yt>=Re-1e3},"isOurs"),In=Date.now()+XO;for(;;){let vn=await n.capabilities.readRunIndex(n.cwd),yt=vn.runs.find(cn);if(yt!==void 0){let Vt=await n.capabilities.listStudies(n.cwd);b(IN(vn,Vt.studies,Vt.retired)),lt(void 0),Lt.current.name==="study"&&Lt.current.studyKey===_t.key&&Q({type:"enter",screen:{name:"run",studyId:_t.studyId,runId:yt.runId}});return}if(Date.now()>=In)break;await new Promise(Vt=>setTimeout(Vt,ZO))}let we=await n.capabilities.readLaunchLog(Pe.run.logPath);lt(void 0),F({studyKey:_t.key,text:we===""?`${_t.name} started (pid ${Pe.run.pid}) but has not reported in. Check ${Pe.run.logPath}.`:`${_t.name} did not report in. Its log ends:
286
+ `)d.name="enter";else if(n===" ")d.name="tab";else if(n==="\b"||n==="\x1B\b")d.name="backspace",d.meta=n.charAt(0)==="\x1B";else if(n==="\x7F"||n==="\x1B\x7F")d.name="backspace",d.meta=n.charAt(0)==="\x1B";else if(n==="\x1B"||n==="\x1B\x1B")d.name="escape",d.meta=n.length===2;else if(n===" "||n==="\x1B ")d.name="space",d.meta=n.length===2;else if(n.length===1&&n<="")d.name=String.fromCharCode(n.charCodeAt(0)+97-1),d.ctrl=!0;else if(n.length===1&&n>="0"&&n<="9")d.name="number";else if(n.length===1&&n>="a"&&n<="z")d.name=n;else if(n.length===1&&n>="A"&&n<="Z")d.name=n.toLowerCase(),d.shift=!0;else if(i=KU.exec(n))d.name=i[1].toLowerCase(),d.meta=!0,d.shift=/^[A-Z]$/.test(i[1]);else if(i=FU.exec(n)){let m=[...n];m[0]==="\x1B"&&m[1]==="\x1B"&&(d.meta=!0);let B=[i[1],i[2],i[4],i[6]].filter(Boolean).join(""),y=(i[3]||i[5]||1)-1;d.ctrl=!!(y&4),d.meta=d.meta||!!(y&10),d.shift=!!(y&1),d.code=B,d.name=w2[B]??"",d.shift=kU(B)||d.shift,d.ctrl=qU(B)||d.ctrl}return d},"parseKeypress"),L2=PU;var z2=Ot(Le(),1);var JQ=o(()=>(0,z2.useContext)(rB),"useStdinContext");var $U=o((n,i={})=>{let{setRawMode:u,internal_exitOnCtrlC:c,internal_eventEmitter:d}=JQ();(0,np.useEffect)(()=>{if(i.isActive!==!1)return u(!0),()=>{u(!1)}},[i.isActive,u]);let m=(0,np.useEffectEvent)(B=>{let y=L2(B),Q={upArrow:y.name==="up",downArrow:y.name==="down",leftArrow:y.name==="left",rightArrow:y.name==="right",pageDown:y.name==="pagedown",pageUp:y.name==="pageup",home:y.name==="home",end:y.name==="end",return:y.name==="return",escape:y.name==="escape",ctrl:y.ctrl,shift:y.shift,tab:y.name==="tab",backspace:y.name==="backspace",delete:y.name==="delete",meta:y.meta,super:y.super??!1,hyper:y.hyper??!1,capsLock:y.capsLock??!1,numLock:y.numLock??!1,eventType:y.eventType},N;y.isKittyProtocol?y.isPrintable?N=y.text??y.name:y.ctrl&&y.name.length===1?N=y.name:N="":y.ctrl?N=y.name??"":N=y.sequence,!y.isKittyProtocol&&M2.includes(y.name)&&(N=""),N.startsWith("\x1B")&&(N=N.slice(1)),N.length===1&&/[A-Z]/.test(N)&&(Q.shift=!0),!(N==="c"&&Q.ctrl&&c)&&za.discreteUpdates(()=>{n(N,Q)})});(0,np.useEffect)(()=>{if(i.isActive!==!1)return d.on("input",m),()=>{d.removeListener("input",m)}},[i.isActive,d])},"useInput"),Ap=$U;var Y2=Ot(Le(),1);var J2=Ot(Le(),1);var tO=o(()=>(0,J2.useContext)(uB),"useApp"),KQ=tO;var K2=Ot(Le(),1);var eO=o(()=>(0,K2.useContext)(sB),"useStdout"),CB=eO;var nO=Ot(Le(),1);var FQ=Ot(Le(),1);var aO=Ot(Le(),1);var iO=Ot(Le(),1);var hB=Ot(Le(),1);var ap=Ot(Le(),1);var F2=Ot(Le(),1);var BB=Ot(Le(),1);var lO=/utf-?8/i;function _c(n=process.env){if(process.platform==="win32")return!0;let i=n.LC_ALL??n.LC_CTYPE??n.LANG;return i===void 0||i.trim().length===0?!1:lO.test(i)}o(_c,"terminalRendersUnicode");var oO=new Map([["\u2014","--"],["\u2013","-"],["\u2019","'"],["\u2018","'"],["\u201C",'"'],["\u201D",'"'],["\u2026","..."],["\xB7","-"],["\u276F",">"],["\u2039","<"],["\u25B8",">"],["\u2713","+"],["\u2691","!"],["\u23CE","Enter"],["\u2191","^"],["\u2193","v"],["\u2190","<-"],["\u2192","->"],["\xD7","x"],["\u2248","~"],["\u2717","x"]]);function k2(n,i=process.env){if(_c(i))return n;let u="";for(let c of n){if(c.codePointAt(0)<128){u+=c;continue}u+=oO.get(c)??"?"}return u}o(k2,"forTerminal");var Ze=Ot(Le(),1);var kt={accent:"#93a2ff",ok:"#7dc9a0",warn:"#d9a441",bad:"#e0796b"};var _l=Ot(Aa(),1);function X2({columns:n,connections:i}){let u=[["\u2191 \u2193 \xB7 k j","move the cursor"],["\u23CE \xB7 \u2192","open what the cursor is on, or run the action it names"],["esc \xB7 \u2190","back; it cancels an armed confirmation first"],["g \xB7 G","jump to the top, jump to the bottom"],...i?[["c","keys and accounts: provider key setup and the email connection"]]:[],["?","these shortcuts"],["q","quit; a run you started keeps going without this window"]];return(0,_l.jsxs)(ut,{flexDirection:"column",width:n,children:[(0,_l.jsx)(q,{color:kt.accent,bold:!0,children:"Keyboard shortcuts"}),(0,_l.jsx)(ut,{marginTop:1,flexDirection:"column",children:u.map(([c,d])=>(0,_l.jsxs)(ut,{children:[(0,_l.jsx)(ut,{width:16,children:(0,_l.jsx)(q,{bold:!0,children:c})}),(0,_l.jsx)(q,{dimColor:!0,children:d})]},c))}),(0,_l.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,_l.jsx)(q,{dimColor:!0,children:"Starting a run asks twice when it spends money: the first \u23CE arms and"}),(0,_l.jsx)(q,{dimColor:!0,children:"restates the cost, the second commits. A dry run never asks."})]})]})}o(X2,"HelpScreen");var Da=Ot(Le(),1);function sO(n){let i=new Map,u=[];for(let d of n){let m=d.study?.id;if(m===void 0){u.push(d);continue}let B=i.get(m);B===void 0?i.set(m,[d]):B.push(d)}let c=[...i.entries()].map(([d,m])=>{let B=m.filter(y=>y.liveness==="running");return{studyId:d,runs:m.length,live:B.length,...m[0]===void 0?{}:{latest:m[0]},liveRuns:B}});return c.sort((d,m)=>d.live!==m.live?m.live-d.live:QB(m.latest)-QB(d.latest)),{studies:c,unattributed:u}}o(sO,"groupRunsByStudy");function QB(n){if(n===void 0)return 0;for(let i of[n.completedAt,n.updatedAt,n.startedAt]){if(i===void 0)continue;let u=Date.parse(i);if(Number.isFinite(u))return u}return 0}o(QB,"recencyOf");function Z2(n,i){let c=(i===void 0?n:n.filter(y=>y.mode===i)).filter(y=>y.liveness==="finished"),d=c.map(y=>y.durationMs).filter(y=>typeof y=="number"&&Number.isFinite(y)&&y>=0).sort((y,Q)=>y-Q),m=c.map(y=>y.estimatedCostUsd).filter(y=>typeof y=="number"&&Number.isFinite(y)).sort((y,Q)=>y-Q),B=c.filter(y=>y.estimatedCostUsd===null||y.estimatedCostUsd===void 0).length;return{sample:c.length,...d.length===0?{}:{medianDurationMs:W2(d),durationRangeMs:{min:d[0],max:d[d.length-1]}},...m.length===0?{}:{medianCostUsd:W2(m)},costUnknown:B}}o(Z2,"expectationFor");function W2(n){let i=Math.floor(n.length/2);return n.length%2===1?n[i]:(n[i-1]+n[i])/2}o(W2,"median");function SB(n){if(n.sample===0)return"no runs yet";let i=[];if(n.durationRangeMs!==void 0){let{min:m,max:B}=n.durationRangeMs;i.push(m===B?wl(m):`${wl(m)}\u2013${wl(B)}`)}n.medianCostUsd!==void 0&&i.push(`~$${n.medianCostUsd.toFixed(2)} median`);let u=`${n.sample} run${n.sample===1?"":"s"}`,c=n.sample>0&&n.costUnknown===n.sample,d=n.costUnknown===0?"":c?", none priced":`, ${n.costUnknown} unpriced`;return i.length===0?c?`${u}, nothing recorded`:`${u}${d}, nothing timed`:`${i.join(" \xB7 ")} \xB7 ${u}${d}`}o(SB,"expectationLine");function vB(n){return n.runs===0?n.declared?"never run":"no runs":n.liveExpectation.sample>0?SB(n.liveExpectation):`${n.runs} ${n.runs===1?"run":"runs"}, none live`}o(vB,"studySummaryLine");function wl(n){let i=Math.max(0,Math.round(n/1e3));if(i<60)return`${i}s`;let u=Math.floor(i/60);if(u<60)return i%60===0?`${u}m`:`${u}m ${i%60}s`;let c=Math.floor(u/60);return u%60===0?`${c}h`:`${c}h ${u%60}m`}o(wl,"formatDuration");function mg(n,i){let u=Math.max(8,Math.floor(i.width)),c=Math.max(1,Math.floor(i.maxLines)),d=n.replace(/\*\*([^*]+)\*\*/g,"$1").replace(/\s*\n+\s*/g," ").replace(/\s{2,}/g," ").trim();if(d==="")return{lines:[],truncated:!1};let m=d.split(" "),B=[],y="",Q=0;for(;Q<m.length;Q+=1){let b=m[Q],O=y===""?b:`${y} ${b}`;if(O.length<=u){y=O;continue}if(y!==""&&B.push(y),y=b.length<=u?b:`${b.slice(0,u-1)}\u2026`,b.length>u&&(B.push(y),y=""),B.length===c)break}B.length<c&&y!==""&&(B.push(y),Q=m.length);let N=Q<m.length;if(N&&B.length>0){let b=B[B.length-1];B[B.length-1]=b.length+1<=u?`${b}\u2026`:`${b.slice(0,u-1)}\u2026`}return{lines:B,truncated:N}}o(mg,"normalizeThought");function Xr(n){let i=Math.max(0,Math.floor(n.total)),u=Math.max(1,Math.floor(n.viewport));if(i<=u)return{start:0,end:i};let c=Math.min(Math.max(0,Math.floor(n.selected)),i-1),d=Math.min(Math.max(0,Math.floor(n.margin??1)),Math.floor((u-1)/2)),m=Math.min(Math.max(0,c-d),i-u);return c>=m+u-d&&(m=Math.min(c-u+1+d,i-u)),m=Math.max(0,Math.min(m,i-u)),{start:m,end:m+u}}o(Xr,"listWindow");function P2(n){return(n.split("/").pop()??n).replace(/\.(ya?ml)$/i,"")}o(P2,"studyNameFromPath");function $2(n,i){let{studies:u,unattributed:c}=sO(i),d=new Map(u.map(O=>[O.studyId,O])),m=new Map;for(let O of i){let x=O.study?.id;if(x===void 0)continue;let L=m.get(x);L===void 0?m.set(x,[O]):L.push(O)}let B=new Map;for(let O of n)B.set(O.id,(B.get(O.id)??0)+1);let y=o((O,x,L)=>{let j=d.get(O),k=x?.path;return{key:k??`id:${O}`,studyId:O,name:k===void 0?O:P2(k),...x?.title===void 0?{}:{title:x.title},...k===void 0?{}:{path:k},...x?.origin===void 0?{}:{origin:x.origin},declared:L,label:x?.title??(k===void 0?O:P2(k)),...x?.description===void 0?{}:{description:x.description},sharesIdWith:Math.max(0,(B.get(O)??0)-1),runs:j?.runs??0,live:j?.live??0,...j?.latest===void 0?{}:{latest:j.latest},liveRuns:j?.liveRuns??[],expectation:Z2(m.get(O)??[]),liveExpectation:Z2(m.get(O)??[],"live")}},"build"),Q=new Set(n.map(O=>O.id)),N=[...n.map(O=>y(O.id,O,!0)),...u.filter(O=>!Q.has(O.studyId)).map(O=>y(O.studyId,void 0,!1))];cO(N);let b=o(O=>O.label,"label");return N.sort((O,x)=>{if(O.live!==x.live)return x.live-O.live;let L=o(k=>k.runs>0?0:k.declared?1:2,"rank");if(L(O)!==L(x))return L(O)-L(x);if(O.runs>0&&x.runs>0){let k=QB(x.latest)-QB(O.latest);if(k!==0)return k}let j=b(O).localeCompare(b(x));return j!==0?j:O.key.localeCompare(x.key)}),{rows:N,unattributed:c}}o($2,"studyRows");function cO(n){let i=o(d=>{let m=new Map;for(let B of d)m.set(B,(m.get(B)??0)+1);return m},"count"),u=i(n.map(d=>d.title??d.name)),c=i(n.map(d=>d.name));for(let d of n){let m=d.title??d.name;if((u.get(m)??0)===1){d.label=m;continue}d.label=(c.get(d.name)??0)===1?d.name:d.path??d.name}}o(cO,"assignLabels");function Xo(n,i){let u=Math.max(4,Math.floor(i));return n.length<=u?n:`${n.slice(0,u-1)}\u2026`}o(Xo,"fitLabelToWidth");function Mn(n){return n===void 0?{}:{color:n}}o(Mn,"color");import tN from"node:path";var dO=tN.join(".humanish","runs"),F9=tN.join(dO,"latest.json");var gO=5e3,r7=gO*3;var EO={running:"running",interrupted:"interrupted",passed:"passed",failed:"failed",blocked:"blocked",timed_out:"timed out",no_verdict:"no verdict",dry_run:"dry run",unknown:"unknown"},mO={running:"live",interrupted:"warn",passed:"pass",failed:"fail",blocked:"warn",timed_out:"warn",no_verdict:"warn",dry_run:"neutral",unknown:"neutral"};function Zr(n,i){return{state:n,label:EO[n],tone:mO[n],...i===void 0?{}:{reason:i}}}o(Zr,"shown");function Wr(n){if(n.liveness==="running")return Zr("running");if(n.liveness==="interrupted")return Zr("interrupted");let i=n.ok===!1&&n.failure!==void 0?`${n.failure.kind}: ${n.failure.message}`:void 0;return n.verdict==="blocked"?Zr("blocked",i):n.verdict==="timed_out"?Zr("timed_out",i):n.verdict==="fail"||n.ok===!1?Zr("failed",i):n.verdict==="pass"?Zr("passed"):n.verdict==="contract_proof_only"?Zr(n.mode==="dry-run"?"dry_run":"no_verdict"):Zr("unknown")}o(Wr,"runDisplay");var mo=Ot(Aa(),1),pO=96;function pg(n){return Math.max(20,Math.min(pO,n))}o(pg,"contentWidth");function eN({columns:n,context:i,breadcrumb:u,hints:c,children:d}){let m=pg(n);return(0,mo.jsxs)(ut,{flexDirection:"column",width:m,children:[(0,mo.jsxs)(ut,{width:m,children:[(0,mo.jsx)(q,{bold:!0,children:"human(ish)"}),(0,mo.jsx)(ut,{flexGrow:1}),i===void 0?null:(0,mo.jsx)(q,{dimColor:!0,wrap:"truncate-start",children:i})]}),u===void 0?null:(0,mo.jsx)(q,{dimColor:!0,wrap:"truncate-start",children:u}),(0,mo.jsx)(ut,{marginTop:1,flexDirection:"column",children:d}),(0,mo.jsx)(ut,{marginTop:1,children:(0,mo.jsx)(q,{dimColor:!0,children:c})})]})}o(eN,"Frame");var qQ=_c()?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["|","/","-","\\","|","/","-","\\","|","/"];function ip(n){return qQ[Math.abs(Math.floor(n))%qQ.length]??qQ[0]}o(ip,"spinnerFrame");function yi(n){return n?_c()?"\u276F":">":" "}o(yi,"gutter");function lp(n){let{state:i,tone:u}=Wr(n);if(i==="running")return ip(n.tick??0);let c=_c();return u==="pass"?c?"\u2713":"+":u==="fail"||u==="warn"?c?"\u2691":"!":c?"\xB7":"-"}o(lp,"verdictGlyph");var CO={live:kt.ok,fail:kt.bad,warn:kt.warn,pass:void 0,neutral:void 0},Cg=o(n=>Mn(CO[Wr(n).tone]),"glyphColor");var DB=Ot(Le(),1);function RB(){let{stdout:n}=CB(),i=o(()=>({columns:Math.max(20,n.columns||80),rows:Math.max(6,n.rows||24)}),"read"),[u,c]=(0,DB.useState)(i);return(0,DB.useEffect)(()=>{let d=o(()=>{c(B=>{let y=i();return y.columns===B.columns&&y.rows===B.rows?B:y})},"update");n.on("resize",d);let m=setTimeout(d,0);return()=>{n.off("resize",d),clearTimeout(m)}},[n]),u}o(RB,"useTerminalSize");var ht=Ot(Aa(),1),hO=400;function nN({capabilities:n,columns:i,notice:u,onBack:c,onKeyEntry:d}){let[m,B]=(0,Da.useState)(),[y,Q]=(0,Da.useState)(u),[N,b]=(0,Da.useState)(!1),[O,x]=(0,Da.useState)("home"),L=(0,Da.useRef)(!1),[j,k]=(0,Da.useState)(!0),[F,gt]=(0,Da.useState)(0),[lt,Pt]=(0,Da.useState)({kind:"home"}),[Dt,ue]=(0,Da.useState)(),[se,fe]=(0,Da.useState)([]),[Tt,Ct]=(0,Da.useState)([]),{rows:qt}=RB(),ie=(0,Da.useCallback)(async()=>{k(!0);try{let xt=await n.read();B(xt),ue(xt.authentication)}catch{B(void 0),Q("Could not read connection setup. Recheck to try again.")}finally{k(!1)}},[n]);(0,Da.useEffect)(()=>{ie()},[ie]);let Gt=m?.connections.some(xt=>xt.name==="agentmail"&&xt.apiKeyEnv==="AGENTMAIL_API_KEY"),Fe=m?.credential.source,ve=Fe==="process env"?"session environment":Fe?.includes("provider.env")?"project env file":"saved key",st=!!n.studies&&!!n.configure,Rt=Tt.filter(xt=>xt.status!=="closed"||xt.unresolvedCount>0),Wt=j?[]:[...m?.ok?[{id:"key",label:m.credential.stored?"Replace stored key":"Add API key"},...m.credential.present&&!Gt?[{id:"save",label:"Use this key for this project"}]:[],...m.credential.present&&Gt&&n.check?[{id:"check",label:"Test authentication (read-only)"}]:[],...m.credential.present&&Gt&&st?[{id:"studies",label:"Use real email in a study"}]:[]]:[],...n.recovery?[{id:"recovery",label:"Review inbox cleanup"}]:[],{id:"read",label:"Recheck local setup"}],Nt=lt.kind==="home"?Wt:lt.kind==="check"?[{id:"check",label:"Check again"},{id:"home",label:"Back to Connections"}]:lt.kind==="studies"?se.map((xt,_e)=>({id:`study-${_e}`,label:xt.title})):lt.kind==="preview"?[{id:"apply",label:"Save study copy"},{id:"studies",label:"Cancel"}]:lt.kind==="saved"?[{id:"home",label:"Back to Connections"}]:lt.kind==="recovery"?Rt.map((xt,_e)=>({id:`recovery-${_e}`,label:`${xt.runId} \xB7 ${xt.unresolvedCount} pending`})):[...lt.entry.activeOwner===!1&&lt.entry.unresolvedCount>0&&n.recover?[{id:"recover",label:"Release study inboxes"}]:[],{id:"recovery",label:"Back to cleanup"}],jt=Math.min(F,Math.max(0,Nt.length-1));function De(xt){Pt(xt),gt(0),Q(void 0)}o(De,"go");function dn(){lt.kind==="home"?c():De({kind:lt.kind==="preview"?"studies":lt.kind==="recover"?"recovery":"home"})}o(dn,"back");async function et(xt){if(!L.current){L.current=!0,x(lt.kind),b(!0);try{await xt()}catch{Q("The action could not complete. Recheck before retrying.")}finally{L.current=!1,b(!1)}}}o(et,"run"),Ap((xt,_e)=>{if(L.current||j)return;if(_e.escape||_e.leftArrow){dn();return}if(_e.upArrow||xt==="k"){gt(Lt=>Math.max(0,Lt-1));return}if(_e.downArrow||xt==="j"){gt(Lt=>Math.min(Math.max(0,Nt.length-1),Lt+1));return}if(!_e.return)return;let le=Nt[jt]?.id;if(le){if(le==="key"){d();return}if(le==="home"){De({kind:"home"});return}(le==="apply"&&lt.kind==="preview"||le==="recover"&&lt.kind==="recover")&&Date.now()-lt.openedAt<hO||et(async()=>{if(le==="read"||le==="save"){le==="save"&&Q((await n.save()).message),ue(void 0),await ie(),gt(0);return}if(le==="check"&&n.check){De({kind:"check"}),ue(void 0),ue(await n.check());return}if(le==="studies"&&n.studies){let Lt=await n.studies();fe(Lt),De({kind:"studies"});return}if(le.startsWith("study-")&&n.configure){let Lt=se[jt];if(!Lt)return;let It=await n.configure(Lt.path,!1);if(!It.ok||!It.path||!It.planToken){Q(It.message);return}De({kind:"preview",study:Lt,plan:It,openedAt:Date.now()});return}if(le==="apply"&&lt.kind==="preview"&&n.configure&&lt.plan.planToken){let Lt=await n.configure(lt.study.path,!0,lt.plan.planToken);if(!Lt.ok||!Lt.applied||!Lt.path){De({kind:"studies"}),Q(Lt.message);return}De({kind:"saved",path:Lt.path});return}if(le==="recovery"&&n.recovery){Ct(await n.recovery()),De({kind:"recovery"});return}if(le.startsWith("recovery-")){let Lt=Rt[jt];Lt&&De({kind:"recover",entry:Lt,openedAt:Date.now()});return}if(le==="recover"&&lt.kind==="recover"&&n.recover&&n.recovery&&lt.entry.activeOwner===!1){let Lt=await n.recover(lt.entry.runId,lt.entry.connectionName);Ct(await n.recovery()),De({kind:"recovery"}),Q(Lt.message)}})}});let Mt=Xr({total:Nt.length,selected:jt,viewport:lt.kind==="studies"||lt.kind==="recovery"?Math.max(2,qt-14):Nt.length}),te=(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[Mt.start>0?(0,ht.jsxs)(q,{dimColor:!0,children:["\u2191 ",Mt.start," more"]}):null,Nt.slice(Mt.start,Mt.end).map((xt,_e)=>{let le=Mt.start+_e;return(0,ht.jsxs)(q,{bold:le===jt,...Mn(le===jt?kt.accent:void 0),children:[yi(le===jt)," ",Xo(xt.label,i-3),N&&O===lt.kind&&le===jt?"\u2026":""]},xt.id)}),Mt.end<Nt.length?(0,ht.jsxs)(q,{dimColor:!0,children:["\u2193 ",Nt.length-Mt.end," more"]}):null]});return(0,ht.jsxs)(ut,{flexDirection:"column",width:i,children:[lt.kind==="home"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"AgentMail \xB7 hosted email"}),(0,ht.jsxs)(q,{children:["Connection:"," ",j?"checking\u2026":m?.ok?Gt?"agentmail \xB7 saved":"not saved for this project":"unavailable"]}),(0,ht.jsxs)(q,{children:["Key:"," ",m?m.credential.present?`present \xB7 ${ve}`:"missing":"checking\u2026"]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Provider authentication:"," ",Dt?.authenticated===!0?"passed":Dt?.authenticated===!1?"rejected":Dt?"unknown":"not checked"]}),m?.ok===!1?(0,ht.jsx)(q,{color:kt.bad,children:m.message}):null,m?.credential.explicitlyEmpty?(0,ht.jsx)(q,{color:kt.warn,children:"An empty AGENTMAIL_API_KEY overrides the stored key. Unset it and reopen the TUI."}):m?.credential.strict&&!m.credential.present?(0,ht.jsx)(q,{color:kt.warn,children:"Strict key mode ignores saved keys. Reopen without HUMANISH_STRICT_KEYS=1, or pass an env file."}):(Fe==="process env"||Fe?.includes("provider.env"))&&m?.credential.stored?(0,ht.jsx)(q,{dimColor:!0,children:"Env and project keys take precedence over your saved key."}):null,te,y?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{children:y})}):null,(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{dimColor:!0,children:"Get a key: https://console.agentmail.to"}),(0,ht.jsx)(q,{dimColor:!0,children:"Key entry is hidden. Saved keys apply to all your projects."}),st?(0,ht.jsx)(q,{dimColor:!0,children:"Fresh inbox per participant \xB7 hosted email"}):(0,ht.jsx)(q,{color:kt.warn,children:"Email receiving in studies is not available yet."}),(0,ht.jsx)(q,{dimColor:!0,children:"Local capture: per study \xB7 SMS: unavailable"})]})]}):lt.kind==="check"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Authentication check"}),N&&!Dt?(0,ht.jsx)(q,{children:"Contacting AgentMail\u2026"}):Dt?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsxs)(q,{children:["Credential: ",Dt.credentialPresent?"present":"missing"]}),(0,ht.jsxs)(q,{children:["Authentication:"," ",Dt.authenticated===!0?"passed":Dt.authenticated===!1?"rejected":"unknown"]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Inbox permissions: ",Dt.permissions]}),(0,ht.jsxs)(q,{dimColor:!0,children:["Capacity: ",Dt.capacity," \xB7 delivery: untested"]}),(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{children:Dt.message})}),Dt.checkedAt?(0,ht.jsxs)(q,{dimColor:!0,children:["Checked: ",Dt.checkedAt]}):null]}):(0,ht.jsx)(q,{children:"Authentication is unknown."}),te]}):lt.kind==="studies"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Choose a study for real email"}),(0,ht.jsx)(q,{dimColor:!0,children:"Preview a local copy before saving."}),se.length?te:(0,ht.jsx)(q,{children:"No studies are available in this project."}),se[jt]?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{dimColor:!0,children:se[jt].path})}):null]}):lt.kind==="preview"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Save email-enabled study"}),(0,ht.jsxs)(q,{dimColor:!0,children:["From: ",lt.study.path]}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Save as:"}),(0,ht.jsx)(q,{children:lt.plan.path})]}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Fresh inbox for each participant."}),(0,ht.jsx)(q,{children:"Mail is hosted. Models may see content."}),(0,ht.jsx)(q,{children:"Recordings remain restricted for sharing."}),(0,ht.jsx)(q,{children:"Provider charges are separate."})]}),te]}):lt.kind==="saved"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.ok,children:"Email study saved"}),(0,ht.jsx)(q,{children:lt.path}),(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:"Select this study from Studies to start."}),(0,ht.jsx)(q,{dimColor:!0,children:"Or run this exact path:"}),(0,ht.jsxs)(q,{children:["humanish run ",lt.path]})]}),te]}):lt.kind==="recovery"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Inbox cleanup"}),(0,ht.jsx)(q,{dimColor:!0,children:"Study completion and inbox cleanup are separate."}),Rt.length?te:(0,ht.jsx)(q,{children:"No pending inbox cleanup."}),Rt[jt]?(0,ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,ht.jsx)(q,{children:Rt[jt].runId}),(0,ht.jsxs)(q,{dimColor:!0,children:["Connection: ",Rt[jt].connectionName]})]}):null]}):(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{bold:!0,color:kt.accent,children:"Review inbox cleanup"}),(0,ht.jsx)(q,{children:lt.entry.runId}),(0,ht.jsxs)(q,{children:["Connection: ",lt.entry.connectionName]}),(0,ht.jsxs)(q,{children:[lt.entry.unresolvedCount," pending \xB7 ",lt.entry.participantCount," participants"]}),(0,ht.jsx)(ut,{marginTop:1,flexDirection:"column",children:lt.entry.activeOwner===!0?(0,ht.jsx)(q,{color:kt.warn,children:"This run has an active owner. Cleanup is unavailable while it is running."}):lt.entry.activeOwner===null?(0,ht.jsx)(q,{color:kt.warn,children:"Ownership is unknown. Cleanup is unavailable until ownership can be verified."}):(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsx)(q,{children:"Release this study\u2019s owned inboxes."}),(0,ht.jsx)(q,{dimColor:!0,children:"An uncertain creation may be replayed, then released. Other inboxes are untouched."})]})}),te]}),lt.kind!=="home"&&y?(0,ht.jsx)(ut,{marginTop:1,children:(0,ht.jsx)(q,{color:kt.warn,children:y})}):null,lt.kind!=="home"&&N&&O===lt.kind?(0,ht.jsx)(q,{dimColor:!0,children:"Working\u2026"}):null]})}o(nN,"ConnectionsScreen");import hg from"node:path";var j7=[{relativeDir:hg.join("humanish","studies"),origin:"committed",family:"studies"},{relativeDir:hg.join(".humanish","studies"),origin:"ignored",family:"studies"},{relativeDir:hg.join(".humanish","local","studies"),origin:"ignored",family:"studies"},{relativeDir:hg.join("humanish","labs"),origin:"committed",family:"labs"},{relativeDir:hg.join(".humanish","labs"),origin:"ignored",family:"labs"},{relativeDir:hg.join(".humanish","local","labs"),origin:"ignored",family:"labs"}],BO=[".yaml",".yml"];function AN(n){let i=BO.find(u=>n.endsWith(u));return i===void 0?void 0:n.slice(0,-i.length)}o(AN,"studyFileStem");function jQ(n){switch(n.name){case"studies":return"studies";case"all-runs":return"all-runs";case"study":return`study:${n.studyKey}`;default:return`run:${n.runId}`}}o(jQ,"screenKey");function aN(){return{stack:[{name:"studies"}],selection:{},quit:!1}}o(aN,"initialNav");function op(n){return n.stack[n.stack.length-1]??{name:"studies"}}o(op,"currentScreen");function iN(n){return n.selection[jQ(op(n))]??0}o(iN,"selectedIndex");function lN(n,i){switch(i.type){case"enter":return{...n,stack:[...n.stack,i.screen]};case"back":return n.stack.length<=1?{...n,quit:!0}:{...n,stack:n.stack.slice(0,-1)};case"move":{if(i.total<=0)return n;let u=jQ(op(n)),c=n.selection[u]??0,d=Math.min(Math.max(0,c+i.delta),i.total-1);return d===c?n:{...n,selection:{...n.selection,[u]:d}}}case"select":{if(i.total<=0)return n;let u=jQ(op(n)),c=Math.min(Math.max(0,i.index),i.total-1);return{...n,selection:{...n.selection,[u]:c}}}default:return{...n,quit:!0}}}o(lN,"navigate");function up(n){let i=n.estimatedCostUsd;return typeof i=="number"&&Number.isFinite(i)&&i>=0?i:i===void 0&&n.mode==="dry-run"?0:null}o(up,"runEstimateUsd");function IO(n,i){let u=up({estimatedCostUsd:n}),c=up({estimatedCostUsd:i});return u===null&&c===null?null:QO((u??0)+(c??0))}o(IO,"sumEstimatedUsd");function yO(n,i){if(n==null)return{run:null,analysis:null,total:null};let u={usd:up({estimatedCostUsd:n.estimatedTotalUsd}),complete:n.fullyEstimated===void 0?null:n.fullyEstimated,ratesAsOf:n.ratesAsOf??null,placeholder:n.placeholder===!0},c=i==null?null:{...i,estimatedUsd:up({estimatedCostUsd:i.estimatedUsd}),complete:i.complete&&up({estimatedCostUsd:i.estimatedUsd})!==null},d=IO(u.usd,c?.estimatedUsd??null);if(d===null)return{run:u,analysis:c,total:null};let m=u.usd===null||u.complete===!1||c?.complete===!1;return{run:u,analysis:c,total:{usd:d,complete:m?!1:u.complete}}}o(yO,"runCost");function Bg(n){return yO({estimatedTotalUsd:n.estimatedCostUsd??null,...n.estimatedCostComplete===void 0?{}:{fullyEstimated:n.estimatedCostComplete}},n.analysisCost)}o(Bg,"indexedRunCost");function QO(n){return Math.round(n*1e6)/1e6}o(QO,"round6");function SO(n){return n===1?"analysis":`${n} analyses`}o(SO,"analysesNoun");function NB(n){if(n.run===null)return;let i=n.total===null?"cost not estimated":`~$${n.total.usd.toFixed(2)} est.${n.total.complete===!1?" plus unpriced usage":""}`;return n.analysis===null?i:`${i}, with ${SO(n.analysis.requests)}`}o(NB,"runCostLabel");var bn=Ot(Aa(),1);function rN({runs:n,details:i,labels:u,expected:c,selected:d,columns:m,viewport:B,tick:y,now:Q}){if(n.length===0)return(0,bn.jsxs)(ut,{flexDirection:"column",children:[(0,bn.jsx)(q,{children:"No one is working right now."}),(0,bn.jsx)(q,{dimColor:!0,children:"Start a run from any study and it appears here."})]});let N=Xr({total:n.length,selected:d,viewport:Math.max(2,B-6)}),b=n[Math.min(Math.max(0,d),n.length-1)],O=b===void 0?void 0:i.get(b.runId),x=O?.participants[0],L=x?.thought===void 0?void 0:mg(x.thought.text,{width:Math.max(16,m-2),maxLines:2});return(0,bn.jsxs)(ut,{flexDirection:"column",children:[n.slice(N.start,N.end).map((j,k)=>(0,bn.jsx)(vO,{run:j,who:oN(i.get(j.runId))??"starting\u2026",study:u.get(j.runId)??j.study?.id??"",expectedMs:c.get(j.study?.id??""),active:N.start+k===d,columns:m,tick:y,now:Q},j.runId)),L===void 0?null:(0,bn.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[L.lines.map((j,k)=>(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsx)(ut,{width:2,flexShrink:0,children:(0,bn.jsx)(q,{color:kt.accent,children:"\u258C"})}),(0,bn.jsxs)(q,{dimColor:!0,wrap:"truncate-end",children:[k===0?`"${j}`:j,k===L.lines.length-1?'"':""]})]},k)),(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsx)(ut,{width:2,flexShrink:0,children:(0,bn.jsx)(q,{children:" "})}),(0,bn.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:Xo([oN(O),u.get(b?.runId??"")].filter(Boolean).join(" \xB7 "),Math.max(10,m-2))})]})]}),(0,bn.jsx)(ut,{marginTop:1,children:(0,bn.jsx)(q,{dimColor:!0,children:DO(n,i)})}),(0,bn.jsx)(q,{dimColor:!0,children:"Run + analysis costs: humanish stats"})]})}o(rN,"AllRunsScreen");function oN(n){return n?.participants[0]?.label}o(oN,"personaOf");function vO({run:n,who:i,study:u,expectedMs:c,active:d,columns:m,tick:B,now:y}){let Q=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),N=Number.isFinite(Q)?uN(y-Q):"",b=c===void 0?N:`${N} / ~${uN(c)}`,O=Math.max(10,Math.floor((m-b.length-6)*.5)),x=Math.max(8,m-b.length-O-6);return(0,bn.jsxs)(ut,{width:m,children:[(0,bn.jsxs)(q,{...Mn(d?kt.accent:void 0),bold:d,children:[yi(d)," "]}),(0,bn.jsxs)(q,{color:kt.ok,children:[ip(B)," "]}),(0,bn.jsx)(ut,{width:O,children:(0,bn.jsx)(q,{...Mn(d?kt.accent:void 0),bold:d,wrap:"truncate-end",children:Xo(i,O)})}),(0,bn.jsx)(ut,{width:x,children:(0,bn.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:Xo(u,x)})}),(0,bn.jsx)(ut,{flexGrow:1}),(0,bn.jsx)(q,{dimColor:!0,children:b})]})}o(vO,"RunRow");function DO(n,i){let u=0,c=0,d=0;for(let Q of n){let N=Q.estimatedCostUsd===void 0?i.get(Q.runId)?.participants[0]?.estimatedCostUsd:Bg(Q).total?.usd;d+=Q.analysisCost?.requests??0,typeof N=="number"&&(u+=N,c+=1)}if(c===0)return"no spend recorded yet; a live run prices itself as it goes";let m=n.length-c,B=m===0?"":` \xB7 ${m} not priced yet`,y=d===0?"":` \xB7 with ${d===1?"1 analysis":`${d} analyses`}`;return`run spend ~$${u.toFixed(2)} across ${c} of ${n.length}${B}${y}`}o(DO,"spendLine");function uN(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60);return u<60?`${u}:${String(i%60).padStart(2,"0")}`:wl(n)}o(uN,"clockOf");var Ht=Ot(Aa(),1);function xB(n,i){return[...i?[{kind:"start",mode:"dry-run"},{kind:"start",mode:"live"}]:[],...n.map(c=>({kind:"run",run:c}))]}o(xB,"studyItems");function fN(n){let{row:i,summary:u,runs:c,selected:d,columns:m,viewport:B,now:y,tick:Q,canStart:N}=n,b=xB(c,N);return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[u?.description===void 0?null:(0,Ht.jsx)(q,{wrap:"truncate-end",children:OO(u.description)}),u?.subject===void 0?null:(0,Ht.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:[u.subject,u.participants,u.model,u.reasoningEffort===void 0?void 0:`${u.reasoningEffort} effort`].filter(Boolean).join(" \xB7 ")}),(0,Ht.jsxs)(ut,{width:m,children:[(0,Ht.jsxs)(q,{dimColor:!0,wrap:"truncate-end",children:[vB(i),UO(u)]}),(0,Ht.jsx)(ut,{flexGrow:1}),u?.planRefusal!==void 0?(0,Ht.jsx)(q,{...Mn(kt.warn),children:"refused \u2717"}):u?.keysReady===void 0?null:(0,Ht.jsx)(q,{...Mn(u.keysReady?kt.ok:kt.warn),children:u.keysReady?"keys \u2713":"keys \u2717"})]}),u?.analysis===void 0?null:(0,Ht.jsx)(q,{wrap:"wrap",children:u.analysis.line}),u?.runtime?(0,Ht.jsx)(q,{color:u.runtime.ok?kt.ok:kt.warn,children:u.runtime.message}):null,u?.participantReadiness?(0,Ht.jsx)(q,{color:u.participantReadiness.ok?kt.ok:kt.warn,children:u.participantReadiness.message}):null,u?.communications?(0,Ht.jsx)(q,{color:kt.warn,children:u.communications}):null,u?.planRefusal===void 0?null:(0,Ht.jsx)(ut,{width:m,children:(0,Ht.jsxs)(q,{wrap:"wrap",...Mn(kt.warn),children:["A live run is refused: ",u.planRefusal]})}),u?.keysReady===!1?(0,Ht.jsxs)(ut,{flexDirection:"column",width:m,children:[(0,Ht.jsxs)(q,{...Mn(kt.warn),children:[u.missingKeys?.join(", ")," not found"]}),(0,Ht.jsxs)(q,{dimColor:!0,children:[" ","humanish keys set openai"," ","\xB7 stores them for every project"]}),(0,Ht.jsxs)(q,{dimColor:!0,children:[" ","humanish tui --env-file .env"," ","\xB7 or just this session"]})]}):null,n.launchNote===void 0?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{dimColor:!0,children:n.launchNote})}),n.launchError===void 0?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{color:kt.bad,children:n.launchError})}),N?(0,Ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Ht.jsx)(NO,{...n,active:RO(b,d)}),n.confirming==="live"?(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsxs)(q,{color:kt.warn,children:[" ","start a live run? ",SB(n.row.liveExpectation),u?.analysis?u.analysis.provider==="codex"?" + Codex account analysis (remote inference; account limits apply, dollar cost unknown)":` + analysis ($${u.analysis.maxCostUsd} admission estimate limit, separate from participant spend)`:""," ","\xB7 \u23CE confirm \xB7 esc cancel"]})}):null]}):null,i.declared?null:(0,Ht.jsx)(ut,{marginTop:1,children:(0,Ht.jsx)(q,{color:kt.warn,children:n.retired??"no manifest here: renamed, deleted, or run from elsewhere"})}),i.sharesIdWith>0?(0,Ht.jsxs)(q,{color:kt.warn,children:[i.sharesIdWith+1,' manifests declare "',i.studyId,'": these runs are shared between them']}):null,(0,Ht.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Ht.jsx)(q,{dimColor:!0,children:"Runs"}),n.liveDetail?.automaticAnalysis===void 0?null:(0,Ht.jsxs)(q,{children:["Latest analysis: ",n.liveDetail.automaticAnalysis.state," \xB7 open run for details"]}),c.length===0?(0,Ht.jsx)(q,{dimColor:!0,children:" none yet"}):(0,Ht.jsx)(bO,{runs:c,liveDetail:n.liveDetail,selected:d-xB([],N).length,columns:m,viewport:Math.max(2,B-6),now:y,tick:Q,expectedMs:i.liveExpectation.medianDurationMs})]})]})}o(fN,"StudyScreen");function RO(n,i){let u=n[i];return u?.kind==="start"?u.mode:void 0}o(RO,"activeStart");function NO(n){let i=xO(n.columns,n.row,n.summary);return(0,Ht.jsxs)(Ht.Fragment,{children:[(0,Ht.jsx)(sN,{...n,mode:"dry-run",active:n.active==="dry-run",stacked:i}),(0,Ht.jsx)(sN,{...n,mode:"live",active:n.active==="live",stacked:i})]})}o(NO,"StartRows");function sN({mode:n,active:i,stacked:u,columns:c,row:d,summary:m}){let{label:B,value:y,blocked:Q}=gN(n,d,m),N=n==="live"?kt.warn:kt.accent,b=(0,Ht.jsxs)(q,{...Mn(i?N:void 0),bold:i,dimColor:Q&&!i,children:[yi(i)," ",B]}),O=(0,Ht.jsx)(q,{dimColor:!Q,...Mn(Q?kt.warn:void 0),children:y});return u?(0,Ht.jsxs)(ut,{flexDirection:"column",width:c,children:[b,(0,Ht.jsx)(ut,{marginLeft:4,children:O})]}):(0,Ht.jsxs)(ut,{width:c,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:b}),(0,Ht.jsx)(ut,{flexGrow:1,minWidth:dN}),O]})}o(sN,"StartRow");var dN=2;function gN(n,i,u){if(n==="dry-run")return{label:"Start a dry run",value:"free \xB7 no keys, no spend",blocked:!1};let c=u?.planRefusal!==void 0||u?.keysReady===!1||u?.runtime?.ok===!1||u?.participantReadiness?.ok===!1,d=SB(i.liveExpectation);return{label:"Start a live run",value:c?`${d} \xB7 ${TO(u)}`:d,blocked:c}}o(gN,"startRowText");function xO(n,i,u){return["dry-run","live"].some(c=>{let{label:d,value:m}=gN(c,i,u);return 2+[...d].length+dN+[...m].length>n})}o(xO,"startRowsStack");function TO(n){return n?.planRefusal!==void 0?"refused":n?.keysReady===!1?"needs keys":n?.runtime?.ok===!1?"needs runtime setup":"needs Codex login"}o(TO,"blocker");function bO({runs:n,liveDetail:i,selected:u,columns:c,viewport:d,now:m,tick:B,expectedMs:y}){let Q=Xr({total:n.length,selected:u,viewport:d});return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[Q.start>0?(0,Ht.jsx)(q,{dimColor:!0,children:` \u2191 ${Q.start} more`}):null,n.slice(Q.start,Q.end).map((N,b)=>N.liveness==="running"?(0,Ht.jsx)(_O,{run:N,detail:i,active:Q.start+b===u,columns:c,now:m,tick:B,expectedMs:y},N.runId):(0,Ht.jsx)(MO,{run:N,active:Q.start+b===u,columns:c},N.runId)),Q.end<n.length?(0,Ht.jsx)(q,{dimColor:!0,children:` \u2193 ${n.length-Q.end} more`}):null]})}o(bO,"RunList");function _O({run:n,detail:i,active:u,columns:c,now:d,tick:m,expectedMs:B}){let y=i?.participants[0],Q=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),N=Number.isFinite(Q)?cN(d-Q):void 0,b=B===void 0?"":` of ~${cN(B)}`,O=y?.thought===void 0?void 0:mg(y.thought.text,{width:Math.max(16,c-6),maxLines:3});return(0,Ht.jsxs)(ut,{flexDirection:"column",children:[(0,Ht.jsxs)(ut,{width:c,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Mn(u?kt.accent:void 0),bold:u,children:[yi(u)," "]})}),(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{color:kt.ok,children:[lp({liveness:"running",tick:m})," "]})}),(0,Ht.jsx)(q,{...Mn(u?kt.accent:void 0),bold:u,wrap:"truncate-end",children:y?.label??"starting\u2026"}),(0,Ht.jsx)(ut,{flexGrow:1}),(0,Ht.jsx)(q,{dimColor:!0,children:N===void 0?"":`${N}${b}`})]}),O===void 0?null:(0,Ht.jsx)(ut,{flexDirection:"column",marginLeft:4,children:O.lines.map((x,L)=>(0,Ht.jsxs)(q,{dimColor:L>0,children:[L===0?`"${x}`:x,L===O.lines.length-1?'"':""]},L))}),y===void 0?null:(0,Ht.jsx)(ut,{width:c,children:(0,Ht.jsxs)(q,{dimColor:!0,children:[" ",wO(y)]})})]})}o(_O,"LiveRun");function wO(n){let i=[];return n.actions!==void 0&&i.push(`${n.actions} actions`),n.thoughts!==void 0&&i.push(`${n.thoughts} thoughts`),n.turns!==void 0&&i.push(`${n.turns} turns`),i.length===0?"working\u2026":i.join(" \xB7 ")}o(wO,"activityLine");function MO({run:n,active:i,columns:u}){let c=HO(n.completedAt??n.startedAt),d=Wr(n),m=d.state==="passed"?"":` \xB7 ${d.label}`,B=n.participants===void 0?d.state==="unknown"?"no verdict":d.label:`${n.participants.reachedGoal}/${n.participants.total} reached the goal${m}`,y=n.estimatedCostUsd===void 0||n.estimatedCostUsd===null&&n.analysisCost===void 0?"":` \xB7 run ${NB(Bg(n))}`,Q=[c,B].filter(Boolean).join(" \xB7 ")+y;return(0,Ht.jsxs)(ut,{width:u,children:[(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Mn(i?kt.accent:void 0),bold:i,children:[yi(i)," "]})}),(0,Ht.jsx)(ut,{flexShrink:0,children:(0,Ht.jsxs)(q,{...Cg(n),children:[lp(n)," "]})}),(0,Ht.jsx)(q,{...Mn(i?kt.accent:void 0),bold:i,wrap:"truncate-end",children:Q})]})}o(MO,"PastRun");function UO(n){let i=n?.caps.laneUsd,u=n?.caps.studyUsd;if(i===void 0&&u===void 0)return"";let c=[];return i!==void 0&&c.push(`$${i} per participant`),u!==void 0&&c.push(`$${u} study`),` \xB7 caps ${c.join(" / ")}`}o(UO,"capsLine");function OO(n){let i=n.replace(/\s+/g," ").trim(),u=i.indexOf(". ");return u===-1?i:i.slice(0,u+1)}o(OO,"firstSentence");function HO(n){if(n===void 0)return"";let i=Date.parse(n);if(!Number.isFinite(i))return"";let u=new Date(i),c=o(d=>String(d).padStart(2,"0"),"pad");return`${c(u.getUTCMonth()+1)}-${c(u.getUTCDate())} ${c(u.getUTCHours())}:${c(u.getUTCMinutes())}`}o(HO,"shortDate");function cN(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60);return u<60?`${u}:${String(i%60).padStart(2,"0")}`:wl(n)}o(cN,"clockOf");var Un=Ot(Aa(),1);function rp(n,i){return["queued","running"].includes(i?.automaticAnalysis?.state??"")?i?.observerPath===void 0?["cancel-analysis"]:["observer","cancel-analysis"]:n.liveness==="interrupted"?i?.observerPath===void 0?["reclaim"]:["reclaim","observer"]:n.liveness==="running"?i?.observerPath===void 0?["stop"]:["stop","observer"]:i?.observerPath===void 0?["again"]:["observer","again"]}o(rp,"runActions");function GO(n){switch(n){case"observer":return"Open in Observer";case"again":return"Run again";case"stop":return"Stop this run";case"cancel-analysis":return"Cancel analysis";default:return"Reclaim: stop sandboxes, keep evidence"}}o(GO,"actionLabel");function EN({run:n,detail:i,columns:u,selected:c,tick:d,now:m,actionNote:B}){let y=i?.participants[0],Q=rp(n,i),N=n.liveness==="interrupted";return(0,Un.jsxs)(ut,{flexDirection:"column",children:[(0,Un.jsx)(ut,{children:(0,Un.jsxs)(q,{...Cg(n),bold:!0,children:[lp({...n,tick:d})," ",LO(n,y)]})}),N?(0,Un.jsx)(YO,{run:n,participant:y,now:m,columns:u}):(0,Un.jsx)(zO,{run:n,participant:y,columns:u}),i?.automaticAnalysis===void 0?null:(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,Un.jsxs)(q,{children:["Analysis: ",i.automaticAnalysis.state]}),i.automaticAnalysis.reason===null?null:(0,Un.jsx)(q,{dimColor:!0,wrap:"wrap",children:i.automaticAnalysis.reason})]}),Q.length===0?null:(0,Un.jsx)(ut,{marginTop:1,flexDirection:"column",children:Q.map((b,O)=>(0,Un.jsx)(ut,{children:(0,Un.jsxs)(q,{...Mn(O===c?kt.accent:void 0),bold:O===c,children:[yi(O===c)," ",Xo(GO(b),Math.max(10,u-3))]})},b))}),B===void 0?null:(0,Un.jsx)(ut,{marginTop:1,children:(0,Un.jsx)(q,{dimColor:!0,wrap:"wrap",children:B})})]})}o(EN,"RunScreen");function LO(n,i){if(n.liveness==="interrupted")return"interrupted: no outcome recorded";if(n.liveness==="running"){let B=i?.label;return B===void 0?"starting\u2026":`${B} is working`}let u=Wr(n),c=n.participants;if(c===void 0)return u.state==="unknown"?"finished, no verdict recorded":u.label;let d=c.reportedFriction===void 0||c.reportedFriction===0?"":` \xB7 ${c.reportedFriction} reported friction`,m=u.state==="passed"?"":` \xB7 ${u.label}`;return`${c.reachedGoal}/${c.total} reached the goal${d}${m}`}o(LO,"headline");function zO({run:n,participant:i,columns:u}){let c=i?.thought===void 0?void 0:mg(i.thought.text,{width:Math.max(16,u),maxLines:3}),{reason:d}=Wr(n),m=[n.durationMs===void 0?void 0:wl(n.durationMs),i?.turns===void 0?void 0:`${i.turns} turns`,i?.thoughts===void 0?void 0:`${i.thoughts} thoughts`].filter(Boolean).join(" \xB7 ");return(0,Un.jsxs)(ut,{flexDirection:"column",children:[c===void 0?null:(0,Un.jsx)(ut,{marginTop:1,flexDirection:"column",children:c.lines.map((B,y)=>(0,Un.jsxs)(q,{children:[y===0?`"${B}`:B,y===c.lines.length-1?'"':""]},y))}),(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[d===void 0?null:(0,Un.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:`why: ${d}`}),m===""?null:(0,Un.jsx)(q,{dimColor:!0,children:m}),(0,Un.jsx)(q,{dimColor:!0,children:mN(n,i)})]})]})}o(zO,"FinishedFacts");function YO({run:n,participant:i,now:u,columns:c}){let d=n.startedAt===void 0?Number.NaN:Date.parse(n.startedAt),m=n.updatedAt===void 0?Number.NaN:u-Date.parse(n.updatedAt),B=[i?.thoughts===void 0?void 0:`${i.thoughts} thoughts`,i?.actions===void 0?void 0:`${i.actions} actions`].filter(Boolean).join(" \xB7 ");return(0,Un.jsxs)(ut,{marginTop:1,flexDirection:"column",width:c,children:[(0,Un.jsxs)(q,{dimColor:!0,children:[Number.isFinite(d)?`started ${JO(d)}`:"start time not recorded",Number.isFinite(m)?` \xB7 quiet ${wl(m)}`:"",B===""?"":` \xB7 ${B} captured`]}),(0,Un.jsxs)(ut,{children:[(0,Un.jsx)(q,{dimColor:!0,children:n.estimatedCostUsd===void 0&&i?.estimatedCostUsd===void 0?"cost unknown: it ended before pricing itself":mN(n,i)}),(0,Un.jsx)(q,{color:kt.warn,children:" sandboxes may still be running"})]})]})}o(YO,"InterruptedFacts");function mN(n,i){if(n.estimatedCostUsd===void 0){let u=i?.estimatedCostUsd;return u===void 0?"cost not recorded":u===null?"cost declared absent":`~$${u.toFixed(2)} participant model estimate`}return n.estimatedCostUsd===null&&n.analysisCost===void 0?"cost declared absent":`run ${NB(Bg(n))}`}o(mN,"costLine");function JO(n){let i=new Date(n),u=o(c=>String(c).padStart(2,"0"),"pad");return`${u(i.getUTCHours())}:${u(i.getUTCMinutes())}`}o(JO,"clockTime");var CN=Ot(Le(),1);var he=Ot(Aa(),1);function pN({retired:n}){let i=n.filter(c=>c.code==="HUMANISH_STUDY_V2_UNSUPPORTED").length,u=n.length-i;return(0,he.jsxs)(ut,{flexDirection:"column",children:[i===0?null:(0,he.jsx)(q,{color:kt.warn,children:`${i} study ${i===1?"file uses":"files use"} humanish.lab.v2, which humanish no longer reads. Run humanish migrate to convert ${i===1?"it":"them"}.`}),u===0?null:(0,he.jsx)(q,{color:kt.warn,children:`${u} study ${u===1?"file is":"files are"} in a labs/ folder, which humanish no longer reads. Move ${u===1?"it":"them"} to the matching studies/ folder; humanish study list names each one.`})]})}o(pN,"RetiredNote");function hN({rows:n,selected:i,columns:u,viewport:c,unattributed:d,tick:m,liveParticipants:B,now:y,initialized:Q,peerSelected:N,liveTotal:b,initArmed:O,actionNote:x,retired:L=[]}){if(n.length===0)return Q?(0,he.jsxs)(ut,{flexDirection:"column",children:[L.length>0?(0,he.jsx)(pN,{retired:L}):(0,he.jsx)(q,{children:"No studies here yet."}),(0,he.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,he.jsx)(q,{dimColor:!0,children:"A study file says who to send, to what, and what counts as done."}),(0,he.jsx)(q,{dimColor:!0,children:"Write one in humanish/studies/, or run `humanish init` for starter studies."})]})]}):(0,he.jsxs)(ut,{flexDirection:"column",children:[(0,he.jsx)(q,{children:"This directory is not a humanish project."}),(0,he.jsxs)(ut,{marginTop:1,flexDirection:"column",children:[(0,he.jsx)(q,{dimColor:!0,children:"A project is a humanish/ directory of studies and personas,"}),(0,he.jsx)(q,{dimColor:!0,children:"kept beside the app they study."})]}),(0,he.jsxs)(ut,{marginTop:1,children:[(0,he.jsxs)(q,{...Mn(kt.accent),bold:!0,children:[yi(!0)," Set up humanish here"]}),(0,he.jsx)(ut,{flexGrow:1}),(0,he.jsx)(q,{dimColor:!0,children:O?"\u23CE again to confirm \xB7 esc cancel":"writes humanish/ and updates package.json"})]}),x===void 0?null:(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsx)(q,{dimColor:!0,children:x})})]});let j=Xr({total:n.length,selected:i,viewport:c});return(0,he.jsxs)(ut,{flexDirection:"column",children:[j.start>0?(0,he.jsx)(q,{dimColor:!0,children:` \u2191 ${j.start} more`}):null,n.slice(j.start,j.end).map((k,F)=>{let gt=j.start+F,lt=gt>0?n[gt-1]:void 0,Pt=k.runs===0&&lt!==void 0&&lt.runs>0;return(0,he.jsxs)(CN.default.Fragment,{children:[Pt?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsxs)(q,{dimColor:!0,children:[" ","not yet run"]})}):null,(0,he.jsx)(FO,{row:k,columns:u,active:gt===i,tick:m,liveParticipants:B,now:y})]},k.key)}),j.end<n.length?(0,he.jsx)(q,{dimColor:!0,children:` \u2193 ${n.length-j.end} more`}):null,(0,he.jsxs)(ut,{marginTop:1,children:[(0,he.jsx)(q,{...Mn(N?kt.accent:void 0),bold:N,dimColor:!N,children:`${yi(N)} All runs`}),b>0?(0,he.jsx)(q,{color:kt.ok,children:` ${b} working`}):null]}),d>0?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsxs)(q,{dimColor:!0,children:[d," ",d===1?"run":"runs"," with no study"]})}):null,L.length>0?(0,he.jsx)(ut,{marginTop:1,children:(0,he.jsx)(pN,{retired:L})}):null,(0,he.jsxs)(ut,{marginTop:1,width:u,children:[(0,he.jsx)(ut,{flexShrink:0,children:(0,he.jsx)(q,{...Mn(kt.accent),children:"\u25B8"})}),(0,he.jsx)(q,{dimColor:!0,wrap:"truncate-end",children:` ${KO(n[i],N)}`})]})]})}o(hN,"StudiesScreen");function KO(n,i){if(i)return"every run in this project, newest first, across every study";if(n===void 0)return"";let u=n.description?.split(/(?<=[.!?])\s/)[0]?.trim();return u!==void 0&&u.length>0?u:"no description in the manifest"}o(KO,"describe");function FO({row:n,columns:i,active:u,tick:c,liveParticipants:d,now:m}){let B=n.liveRuns[0],y=B===void 0?vB(n):kO(n,B,d.get(B.runId),m),Q=Math.max(10,Math.floor(i/2)-2),N=y.length<=Q?y:qO(n),b=Math.max(8,i-N.length-6);return(0,he.jsxs)(ut,{width:i,children:[(0,he.jsxs)(q,{...Mn(u?kt.accent:void 0),bold:u,children:[yi(u)," "]}),(0,he.jsxs)(q,{...Cg({liveness:B===void 0?"finished":"running"}),children:[B===void 0?" ":ip(c)," "]}),(0,he.jsx)(q,{...Mn(u?kt.accent:void 0),bold:u,wrap:"truncate-end",children:Xo(n.label,b)}),(0,he.jsx)(ut,{flexGrow:1}),(0,he.jsx)(q,{...Mn(B===void 0?void 0:kt.ok),dimColor:B===void 0,children:N})]})}o(FO,"StudyRowView");function kO(n,i,u,c){let d=i.startedAt===void 0?Number.NaN:Date.parse(i.startedAt),m=Number.isFinite(d)?jO(c-d):void 0,B=u??"starting\u2026",y=n.live>1?` +${n.live-1}`:"";return m===void 0?`${B}${y}`:`${B} \xB7 ${m}${y}`}o(kO,"liveStatus");function qO(n){return n.live>0?`${n.live} running`:n.runs===0?n.declared?"never run":"no runs":`${n.runs} runs`}o(qO,"fallbackStatus");function jO(n){if(!Number.isFinite(n)||n<0)return"0:00";let i=Math.floor(n/1e3),u=Math.floor(i/60),c=i%60;return u<60?`${u}:${String(c).padStart(2,"0")}`:wl(n)}o(jO,"clockOf");var Xi=Ot(Aa(),1),VO=6,VQ=2e3,XO=5e3,ZO=100,XQ=400,WO=120;function QN({options:n,onReady:i,onKeyEntry:u,now:c,tick:d}){let{exit:m}=KQ(),B=RB(),[y,Q]=(0,Ze.useReducer)(lN,void 0,aN),[N,b]=(0,Ze.useState)(void 0),[O,x]=(0,Ze.useState)(void 0),[L,j]=(0,Ze.useState)(void 0),[k,F]=(0,Ze.useState)(void 0),[gt,lt]=(0,Ze.useState)(void 0),[Pt,Dt]=(0,Ze.useState)(void 0),[ue,se]=(0,Ze.useState)(void 0),[fe,Tt]=(0,Ze.useState)(void 0),[Ct,qt]=(0,Ze.useState)(void 0),[ie,Gt]=(0,Ze.useState)(!1),[Fe,ve]=(0,Ze.useState)(n.initialScreen==="connections"),[st,Rt]=(0,Ze.useState)(void 0),[Wt,Nt]=(0,Ze.useState)(0),jt=d??Wt,[De,dn]=(0,Ze.useState)(void 0),[et,Mt]=(0,Ze.useState)(new Map),xt=(0,Ze.useMemo)(()=>n.capabilities.readProjectState(n.cwd),[n]).initialized||(N?.retired.length??0)>0,_e=c??Date.now(),le=(0,Ze.useRef)(void 0),Lt=(0,Ze.useRef)({name:"studies"});(0,Ze.useEffect)(()=>{let _t=!1,oe=o(async()=>{try{let[Re,cn]=await Promise.all([n.capabilities.readRunIndex(n.cwd),n.capabilities.listStudies(n.cwd)]);if(_t)return;x(void 0),b(IN(Re,cn.studies,cn.retired))}catch(Re){if(_t)return;x(Re instanceof Error?Re.message:String(Re))}},"read");oe();let Pe=setInterval(()=>{oe()},VQ);return Pe.unref?.(),()=>{_t=!0,clearInterval(Pe)}},[n]),(0,Ze.useEffect)(()=>{(N!==void 0||O!==void 0)&&i?.()},[N,O,i]);let It=op(y),ne=iN(y),_n=yN(It,N,ue);(0,Ze.useEffect)(()=>{Lt.current=It;let _t=nH(It,N,ne);_t!==void 0&&(le.current=_t)},[It,N,ne]),(0,Ze.useEffect)(()=>{if(N===void 0)return;let _t=le.current;if(_t===void 0)return;let oe=AH(It,N,_t);oe>=0&&oe!==ne&&Q({type:"select",index:oe,total:yN(It,N,ue)})},[N,It]);let DA=(0,Ze.useCallback)(async(_t,oe)=>{if(oe==="live"&&L!=="live"){j("live"),Dt(Date.now());return}if(oe==="live"&&Pt!==void 0&&Date.now()-Pt<XQ)return;j(void 0),Dt(void 0),F(void 0),lt({studyKey:_t.key,text:`starting ${_t.name}\u2026`});let Pe=await n.capabilities.startRun({cwd:n.cwd,study:_t.name,..._t.path?{manifestPath:_t.path}:{},mode:oe});if(!Pe.ok){lt(void 0),F({studyKey:_t.key,text:Pe.error.message});return}let Re=Date.parse(Pe.run.launchedAt),cn=o(vn=>{if(vn.pid!==Pe.run.pid)return!1;let yt=vn.startedAt===void 0?Number.NaN:Date.parse(vn.startedAt);return!Number.isFinite(yt)||!Number.isFinite(Re)?!1:yt>=Re-1e3},"isOurs"),In=Date.now()+XO;for(;;){let vn=await n.capabilities.readRunIndex(n.cwd),yt=vn.runs.find(cn);if(yt!==void 0){let Vt=await n.capabilities.listStudies(n.cwd);b(IN(vn,Vt.studies,Vt.retired)),lt(void 0),Lt.current.name==="study"&&Lt.current.studyKey===_t.key&&Q({type:"enter",screen:{name:"run",studyId:_t.studyId,runId:yt.runId}});return}if(Date.now()>=In)break;await new Promise(Vt=>setTimeout(Vt,ZO))}let we=await n.capabilities.readLaunchLog(Pe.run.logPath);lt(void 0),F({studyKey:_t.key,text:we===""?`${_t.name} started (pid ${Pe.run.pid}) but has not reported in. Check ${Pe.run.logPath}.`:`${_t.name} did not report in. Its log ends:
287
287
  ${we.split(`
288
288
  `).slice(-3).join(`
289
289
  `)}`})},[L,Pt,n]),kA=(0,Ze.useCallback)(async(_t,oe)=>{if(oe==="stop"||oe==="cancel-analysis"){if(Ct===void 0){qt(Date.now()),Tt(oe==="cancel-analysis"?"cancel analysis? \u23CE again to confirm \xB7 esc keep analyzing":"stop this run? \u23CE again to confirm \xB7 esc cancel");return}if(Date.now()-Ct<XQ)return;qt(void 0),Tt(oe==="cancel-analysis"?"cancelling analysis\u2026":"stopping\u2026");let we=await n.capabilities.stopRun(n.cwd,_t.runId,oe==="cancel-analysis"?"analysis":"run");Tt(we.message);return}if(oe==="observer"){let we=ue?.observerPath;if(we===void 0){Tt("this run has no Observer artifact on disk");return}Tt("opening\u2026");let vn=await n.capabilities.openObserver(n.cwd,we);Tt(vn.message);return}if(oe==="reclaim"){Tt("reclaiming: stopping sandboxes, keeping evidence\u2026");let we=await n.capabilities.reclaimRun(n.cwd,_t.runId),vn=we.outcomes.length;Tt(we.error===void 0?`reclaim ${we.state}: ${vn} sandbox${vn===1?"":"es"} found by receipt or E2B tag`:`could not reclaim: ${we.error.message}`);return}let Pe=_t.study?.id,Re=Pe===void 0?[]:N?.rows.filter(we=>we.studyId===Pe&&we.declared)??[];if(Re.length>1){Tt("multiple manifests share this study id; choose the exact one from the list to run again");return}let cn=Re[0];if(cn===void 0||!cn.declared){let we=N===void 0?void 0:SN(N,Pe);Tt(we===void 0?"cannot run this again: its study has no manifest here any more":`cannot run this again: ${we.message}`);return}Tt(`starting ${cn.name}\u2026`);let In=await n.capabilities.startRun({cwd:n.cwd,study:cn.name,...cn.path?{manifestPath:cn.path}:{},mode:_t.mode==="live"?"live":"dry-run"});Tt(In.ok?`started ${cn.name} (pid ${In.run.pid})`:In.error.message)},[ue,n,N,Ct]);Ap((0,Ze.useCallback)((_t,oe)=>{if(Fe){_t==="q"&&m();return}if(ie){Gt(!1),_t==="q"&&m();return}if(_t==="?"){Gt(!0);return}if(_t==="q"){m();return}if(_t==="c"&&n.capabilities.comms){j(void 0),Dt(void 0),qt(void 0),Rt(void 0),ve(!0);return}if(_t==="g"||_t==="G"){L!==void 0&&(j(void 0),Dt(void 0)),Q({type:"move",delta:_t==="g"?-_n:_n,total:_n});return}if(oe.upArrow||_t==="k"||oe.downArrow||_t==="j"){L!==void 0&&(j(void 0),Dt(void 0)),Q({type:"move",delta:oe.upArrow||_t==="k"?-1:1,total:_n});return}if(oe.escape||oe.leftArrow){if(L!==void 0){j(void 0),Dt(void 0);return}if(Ct!==void 0){qt(void 0),Tt(void 0);return}if(st!==void 0){Rt(void 0);return}Q({type:"back"});return}if(oe.return||oe.rightArrow){if(It.name==="studies"&&!xt){if(st===void 0){Rt(Date.now());return}if(Date.now()-st<XQ)return;Rt(void 0),(async()=>{let Re=await n.capabilities.initProject(n.cwd);Tt(Re.message)})();return}if(It.name==="run"&&N!==void 0){let Re=N.runsById.get(It.runId);if(Re!==void 0){let cn=rp(Re,ue)[ne];if(cn!==void 0){kA(Re,cn);return}}}if(It.name==="study"&&N!==void 0){let{row:Re,items:cn}=Ig(N,It.studyKey),In=cn[ne];if(Re!==void 0&&In?.kind==="start"){DA(Re,In.mode);return}}let Pe=aH(It,N,ne);Pe!==void 0&&Q({type:"enter",screen:Pe})}},[m,_n,It,N,ne,L,DA,ue,kA,Ct,ie,Fe,st,xt,n])),(0,Ze.useEffect)(()=>{y.quit&&m()},[y.quit,m]);let Ie=It.name==="run"?It.runId:void 0;(0,Ze.useEffect)(()=>{if(Tt(void 0),qt(void 0),Ie===void 0){se(void 0);return}let _t=!1;se(void 0);let oe=o(async()=>{try{let Re=await n.capabilities.readRunDetail(n.cwd,Ie);_t||se(Re)}catch{_t||se(null)}},"read");oe();let Pe=setInterval(()=>{oe()},VQ);return Pe.unref?.(),()=>{_t=!0,clearInterval(Pe)}},[Ie,n]),(0,Ze.useEffect)(()=>{if(d!==void 0)return;let _t=setInterval(()=>Nt(oe=>oe+1),WO);return _t.unref?.(),()=>clearInterval(_t)},[d]);let Nn=It.name==="study"?N?.rows.find(_t=>_t.key===It.studyKey):void 0,An=Nn===void 0?void 0:N?.runsByStudy.get(Nn.studyId)?.[0]?.runId,mn=[...new Set([...(N?.rows??[]).flatMap(_t=>_t.liveRuns.map(oe=>oe.runId)),...An===void 0?[]:[An]])].join(",");(0,Ze.useEffect)(()=>{if(mn===""){Mt(new Map);return}let _t=!1,oe=!1,Pe=o(async()=>{if(oe)return;oe=!0;let cn=mn.split(","),In=await Promise.all(cn.map(async we=>{let vn=await n.capabilities.readRunDetail(n.cwd,we).catch(()=>null);return vn===null?null:[we,vn]}));_t||Mt(new Map(In.filter(we=>we!==null))),oe=!1},"read");Pe();let Re=setInterval(()=>{Pe()},VQ);return Re.unref?.(),()=>{_t=!0,clearInterval(Re)}},[mn,n]);let We=It.name==="study"?It.studyKey:void 0,Wn=We===void 0?void 0:N?.rows.find(_t=>_t.key===We),jn=Wn?.path??Wn?.name;(0,Ze.useEffect)(()=>{if(jn===void 0){dn(void 0);return}let _t=!1;return dn(void 0),(async()=>{let oe=await n.capabilities.readStudySummary(n.cwd,jn,{checkKeys:!0}).catch(()=>null);_t||dn(oe)})(),()=>{_t=!0}},[jn,n]);let Jt=Math.max(1,B.rows-VO),gn=(0,Ze.useMemo)(()=>Fe&&n.capabilities.comms?(0,Xi.jsx)(nN,{capabilities:n.capabilities.comms,columns:pg(B.columns),notice:n.connectionNotice,onBack:()=>ve(!1),onKeyEntry:()=>{u?.(),m()}}):ie?(0,Xi.jsx)(X2,{columns:pg(B.columns),connections:!!n.capabilities.comms}):O!==void 0?(0,Xi.jsxs)(q,{color:kt.bad,children:["could not read this project: ",O]}):N===void 0?(0,Xi.jsx)(q,{dimColor:!0,children:"reading project\u2026"}):iH({screen:It,data:N,selected:ne,columns:pg(B.columns),viewport:Jt,now:_e,confirming:L,launchError:k,launchNote:gt,detail:ue,summary:De,liveDetails:et,tick:jt,initialized:xt,actionNote:fe,initArmed:st!==void 0}),[ie,Fe,n,u,m,O,N,It,ne,B.columns,Jt,_e,L,k,gt,ue,De,et,jt,xt,fe]);return(0,Xi.jsx)(eN,{columns:B.columns,context:PO(It,N,n),breadcrumb:Fe?"\u2039 connections":$O(It,N),hints:Fe?"\u2191\u2193 move \u23CE select esc back q quit":ie?"any key returns q quit":tH(It,N,ne,L,pg(B.columns),xt)+(n.capabilities.comms?" c keys and accounts":""),children:gn})}o(QN,"App");function PO(n,i,u){let c=u.cwd.split("/").filter(Boolean).pop();if(n.name==="run"&&i!==void 0){let m=i.runsById.get(n.runId),B=n.runId.split("-").pop()??n.runId;return[m?.study?.id,B].filter(Boolean).join(" \xB7 ")}if(i===void 0)return c;let d=wc(i).length;return d===0?c:`${c} \xB7 ${d} participant${d===1?"":"s"} working`}o(PO,"contextLine");function $O(n,i){if(n.name==="studies")return;if(n.name==="all-runs")return"\u2039 studies / all runs";if(n.name==="study")return`\u2039 studies / ${i?.rows.find(d=>d.key===n.studyKey)?.name??n.studyKey}`;let u=n.studyId;return u===void 0?"\u2039 studies / run":`\u2039 studies / ${u} / run`}o($O,"breadcrumbOf");function tH(n,i,u,c,d,m){let B=BN(n,i,u,c,"\u2191\u2193 move",m);return[...B].length<=d?B:BN(n,i,u,c,"\u2191\u2193",m)}o(tH,"keyHints");function BN(n,i,u,c,d,m){switch(n.name){case"studies":return(i?.rows.length??0)>0?`${d} \u23CE open ? shortcuts q quit`:m===!1?"\u23CE set up humanish here ? shortcuts q quit":"? shortcuts q quit";case"study":{if(c!==void 0)return"\u23CE confirm esc cancel";let y=(i===void 0?void 0:Ig(i,n.studyKey).items[u])?.kind==="start"?"\u23CE start":"\u23CE open";return`${d} ${y} esc back ? shortcuts q quit`}case"all-runs":return`${d} \u23CE open esc back ? shortcuts q quit`;default:{let B=i===void 0?void 0:i.runsById.get(n.name==="run"?n.runId:"");return B!==void 0&&rp(B,void 0).length>0?`${d} \u23CE select esc back ? shortcuts q quit`:"esc back ? shortcuts q quit"}}}o(BN,"legendFor");function SN(n,i){if(i===void 0)return;let u=o(d=>d.replace(/\\/g,"/"),"slashed"),c=new Set((n.runsByStudy.get(i)??[]).flatMap(d=>d.study?.path===void 0?[]:[u(d.study.path)]));return c.size>0?n.retired.find(d=>c.has(u(d.path))):n.retired.find(d=>AN(u(d.path).split("/").pop()??"")===i)}o(SN,"retiredFileOf");function IN(n,i,u){let{rows:c,unattributed:d}=$2(i.map(y=>({id:y.id,...y.title===void 0?{}:{title:y.title},...y.description===void 0?{}:{description:y.description},path:y.path,origin:y.origin})),n.runs),m=new Map,B=new Map;for(let y of n.runs){B.set(y.runId,y);let Q=y.study?.id;if(Q===void 0)continue;let N=m.get(Q);N===void 0?m.set(Q,[y]):N.push(y)}return{rows:c,unattributed:d,runsByStudy:m,runsById:B,unreadable:n.unreadable,retired:u}}o(IN,"project");function wc(n){let i=new Set,u=[];for(let c of n.rows.flatMap(d=>d.liveRuns))i.has(c.runId)||(i.add(c.runId),u.push(c));return u}o(wc,"liveRunsOf");function eH(n,i){return i===void 0?"":n.rows.find(u=>u.studyId===i)?.label??i}o(eH,"labelForStudy");function Ig(n,i){let u=n.rows.find(c=>c.key===i);return u===void 0?{items:[]}:{row:u,items:xB(n.runsByStudy.get(u.studyId)??[],u.declared)}}o(Ig,"itemsForStudy");function yN(n,i,u){if(i===void 0)return 0;switch(n.name){case"studies":return i.rows.length+1;case"all-runs":return wc(i).length;case"study":return Ig(i,n.studyKey).items.length;case"run":{let c=i.runsById.get(n.runId);return c===void 0?0:rp(c,u).length}default:return 0}}o(yN,"countRows");function nH(n,i,u){if(i!==void 0){if(n.name==="studies")return i.rows[u]?.key??"peer:all-runs";if(n.name==="all-runs")return wc(i)[u]?.runId;if(n.name==="study"){let c=Ig(i,n.studyKey).items[u];return c===void 0?void 0:c.kind==="start"?`start:${c.mode}`:`run:${c.run.runId}`}}}o(nH,"identityOf");function AH(n,i,u){return n.name==="studies"?u==="peer:all-runs"?i.rows.length:i.rows.findIndex(c=>c.key===u):n.name==="all-runs"?wc(i).findIndex(c=>c.runId===u):n.name==="study"?Ig(i,n.studyKey).items.findIndex(c=>c.kind==="start"?u===`start:${c.mode}`:`run:${c.run.runId}`===u):-1}o(AH,"indexOfIdentity");function aH(n,i,u){if(i!==void 0){if(n.name==="studies"){let c=i.rows[u];return c===void 0?u===i.rows.length?{name:"all-runs"}:void 0:{name:"study",studyKey:c.key}}if(n.name==="all-runs"){let c=wc(i)[u];return c===void 0?void 0:{name:"run",...c.study?.id===void 0?{}:{studyId:c.study.id},runId:c.runId}}if(n.name==="study"){let{row:c,items:d}=Ig(i,n.studyKey),m=d[u];return c===void 0||m===void 0||m.kind!=="run"?void 0:{name:"run",studyId:c.studyId,runId:m.run.runId}}}}o(aH,"openSelected");function iH(n){let{screen:i,data:u,selected:c,columns:d,viewport:m,now:B,confirming:y,launchError:Q,launchNote:N,detail:b}=n,{summary:O,liveDetails:x,tick:L,initialized:j,actionNote:k}=n;if(i.name==="studies")return(0,Xi.jsx)(hN,{rows:u.rows,selected:c,columns:d,viewport:m,unattributed:u.unattributed.length,tick:L,initialized:j,retired:u.retired,peerSelected:c===u.rows.length,liveTotal:wc(u).length,...n.initArmed===!0?{initArmed:!0}:{},...n.actionNote===void 0?{}:{actionNote:n.actionNote},liveParticipants:new Map([...x.entries()].map(([gt,lt])=>{let Pt=lt.participants[0]?.label;return Pt===void 0?null:[gt,Pt]}).filter(gt=>gt!==null)),now:B});if(i.name==="study"){let gt=u.rows.find(Pt=>Pt.key===i.studyKey);if(gt===void 0)return(0,Xi.jsx)(q,{color:kt.warn,children:"that study is no longer in this project"});let lt=gt.declared?void 0:SN(u,gt.studyId)?.message;return(0,Xi.jsx)(fN,{row:gt,summary:O,runs:u.runsByStudy.get(gt.studyId)??[],liveDetail:x.get(gt.liveRuns[0]?.runId??u.runsByStudy.get(gt.studyId)?.[0]?.runId??""),selected:c,columns:d,viewport:m,now:B,tick:L,canStart:gt.declared,...lt===void 0?{}:{retired:lt},confirming:y,launchError:Q?.studyKey===gt.key?Q.text:void 0,launchNote:N?.studyKey===gt.key?N.text:void 0})}if(i.name==="all-runs"){let gt=wc(u);return(0,Xi.jsx)(rN,{runs:gt,details:x,labels:new Map(gt.map(lt=>[lt.runId,eH(u,lt.study?.id)])),expected:new Map(u.rows.map(lt=>lt.liveExpectation.medianDurationMs===void 0?null:[lt.studyId,lt.liveExpectation.medianDurationMs]).filter(lt=>lt!==null)),selected:c,columns:d,viewport:m,tick:L,now:B})}let F=u.runsById.get(i.runId);return F===void 0?(0,Xi.jsx)(q,{color:kt.warn,children:"that run is no longer on disk"}):(0,Xi.jsx)(EN,{run:F,detail:b,columns:d,viewport:m,selected:c,tick:L,now:B,actionNote:k})}o(iH,"renderScreen");var vN=Ot(Aa(),1);function lH(n){if(_c())return n;let i=Object.create(n);return i.write=((u,...c)=>n.write(typeof u=="string"?k2(u):u,...c)),i}o(lH,"encodeFor");var nJ=o(async n=>{let i=0,u=o(()=>{},"ready"),c=new Promise(B=>{u=B}),d=lH(n.stdout),m=zQ((0,vN.jsx)(QN,{options:n,onReady:u,onKeyEntry:()=>{i={action:"agentmail-key"}}}),{stdin:n.stdin,stdout:d,patchConsole:!1,exitOnCtrlC:!0,interactive:!0});n.exitAfterFirstFrame===!0&&(await c,await new Promise(B=>setImmediate(B)),m.unmount());try{return await m.waitUntilExit(),m.clear(),m.cleanup(),i}catch(B){return m.unmount(),n.stdout.write(`humanish tui exited: ${B instanceof Error?B.message:String(B)}
@@ -57,7 +57,7 @@ API surface.
57
57
  1. **Transport-agnostic contract; Codex stays the reference implementation.** The
58
58
  contract describes lifecycle and evidence, not transport. An adapter may be a
59
59
  subprocess protocol (Codex stdio JSON-RPC, `pi --mode rpc`, `claude -p
60
- --output-format stream-json`) or an in-process SDK (`pi-agent-core`, Claude
60
+ --output-format stream-json`) or an in-process SDK (`pi-agent-core`, Claude
61
61
  Agent SDK, Stagehand). The existing Codex app-server integration is the
62
62
  reference adapter. `pi-agent-core` was planned as the first in-process-SDK
63
63
  adapter to prove both shapes early; it shipped only as a trace mapper with no
@@ -325,7 +325,7 @@ the computer-use loop distinguishes two ways to hit the cap:
325
325
 
326
326
  - **`budget_reached`**: the deadline was reached after at least one material (non-idle)
327
327
  action, or a spend, adapter or token limit ended the session. This maps to `ActorStatus:
328
- "incomplete"`: the participant did not reach the goal, and the harness did not fail.
328
+ "incomplete"`: the participant did not reach the goal, and the harness did not fail.
329
329
  `participantOutcomeOk` is false, the verdict is `fail`, and the CLI exits `2`. The trace
330
330
  `reason` and optional `stopCause` say which limit ended the session.
331
331
  - **`timed_out`**: the deadline was reached with zero material actions (a hung provider, an
@@ -422,7 +422,7 @@ returns the full `resolvedPersona` from `parseResolvedPersona`.
422
422
  Plan:
423
423
 
424
424
  1. **Parse the whole persona** into a `ResolvedPersona`: `{ id, name, summary, goals[],
425
- traits: { patience, skill, accessibilityNeeds? }, constraints[], sourceDigest }` (map
425
+ traits: { patience, skill, accessibilityNeeds? }, constraints[], sourceDigest }` (map
426
426
  `technical_confidence` to `skill`). The shipped shape in `src/study/persona.ts` has no
427
427
  `goals`, adds `background`, and makes every trait optional.
428
428
  2. **Compile traits into actor-neutral directives**, not prose, via a pure
@@ -176,7 +176,7 @@ the following, on Linux x64:
176
176
  runs this check; see "The qualifier" below.
177
177
  3. One hosted participant study with the candidate first on `PATH` (for example
178
178
  `PATH=<evidence>/npm-<version>/node_modules/.bin:$PATH pnpm humanish run <study>
179
- --dotenv <file with E2B_API_KEY only>`) reached its goal in the final capture, with a
179
+ --dotenv <file with E2B_API_KEY only>`) reached its goal in the final capture, with a
180
180
  verified request receipt, `humanish verify --run <id>` passing and the automatic Codex
181
181
  analysis recording the release. Keep `OPENAI_API_KEY` out of that environment so the
182
182
  participant stays on ChatGPT-account billing.
@@ -86,7 +86,7 @@ action**, not a fatal error:
86
86
  uniformly. When the caught error `isCommandExitError`
87
87
  (`src/substrates/command-failure.ts`; it matches the SDK class name or any object carrying
88
88
  a numeric `exitCode`), the loop records a `notice` item (`status: "error"`, title `action
89
- skipped: desktop command failed`, text = the public-safe action label + exit code + a
89
+ skipped: desktop command failed`, text = the public-safe action label + exit code + a
90
90
  redacted `stderrTail`), does **not** count the action as a material action, and
91
91
  **continues**. The next `observe()` hands the model a fresh screenshot/state to adapt to.
92
92
  - An executor error declared as `action_rejected` with disposition `not_dispatched` also
@@ -46,8 +46,8 @@ Counts are the distinct quoted codes in `src/` on 2026-10-03.
46
46
  The lowercase families are values recorded inside artifacts and receipts, and an artifact keeps
47
47
  the code it was written with. Automatic analysis reads two of them back:
48
48
  `analysis_admission_estimate_exceeded` becomes the reason `AUTOMATIC_ANALYSIS_ADMISSION_EXCEEDED`,
49
- and `analysis_budget_exceeded` on a default analysis prints the hint to rerun with
50
- `humanish analyze --max-cost`. Validation also accepts a partial artifact whose error is
49
+ and `analysis_budget_exceeded` records the expected cost, the worst case and the cap on the job,
50
+ and prints them with the command that reruns it, `humanish analyze --run <id> --max-cost <n>`. Validation also accepts a partial artifact whose error is
51
51
  `analysis_admission_estimate_exceeded`.
52
52
 
53
53
  Share-safety reasons in `humanish verify` (`VERIFY_FAILED`, `RAW_SCREENSHOTS` and the rest) are
@@ -576,6 +576,67 @@ updatedAt: "<ISO timestamp>"
576
576
 
577
577
  The latest pointer may move. Run bundle directories should not.
578
578
 
579
+ ## Reviewer notes
580
+
581
+ Each note a person adds while reviewing a run is its own file in the run directory,
582
+ `notes/<id>.json`, written by `humanish notes --add` and by an Observer served on loopback.
583
+ `notes/` is absent until the first note.
584
+
585
+ ```json
586
+ {
587
+ "schema": "humanish.run-note.v1",
588
+ "runId": "example-2026-06-02t10-00-00-000z-proof",
589
+ "id": "note-20260602t103000000z-000000000001",
590
+ "atMs": 151000,
591
+ "participant": "stream-001",
592
+ "nearest": { "participant": "stream-001", "itemId": "turn-07-call-01" },
593
+ "text": "They looked for the save button here.",
594
+ "author": "you",
595
+ "createdAt": "2026-06-02T10:30:00.000Z",
596
+ "editedAt": null
597
+ }
598
+ ```
599
+
600
+ - `id`: `note-`, the creation time as `yyyymmddthhmmssmmmz`, `-` and 12 hex digits of
601
+ random bits. The file is named `<id>.json`, so the files sort in the order they were
602
+ added.
603
+ - `runId`: the run directory's name. A file whose `runId` or `id` does not match its run or
604
+ its file name is not read.
605
+ - `atMs`: milliseconds from the run clock's start, the earliest timed capture or
606
+ desktop video of any participant. The Observer's study timeline shows that moment as
607
+ 00:00. A participant's captures count only when every one is stamped and the stamps
608
+ never go back.
609
+ - `participant`: the stream id the note belongs to, or `null` for the whole run.
610
+ `humanish notes --add --participant` and the Observer also take the participant's id from
611
+ the study (the stream's `laneId`) and record its stream id. A name that is one stream's id
612
+ and another stream's study id is refused.
613
+ - `nearest`: the latest stamped trace item, a capture or an event, at or before the
614
+ moment, among the note's participant or every participant; `null` when there is none.
615
+ - `text`: 1 to 2000 characters, after the run's known values, secret-shaped values and
616
+ local paths are replaced.
617
+ - `author`: `"you"` in this version.
618
+ - `createdAt`, `editedAt`: ISO-8601. Notes cannot be edited yet, so `editedAt` is `null`.
619
+
620
+ A note file is created once under its own name, only when no file has that name (`O_CREAT` with
621
+ `O_EXCL`), filled in one write and never rewritten; a taken name gets a new id. No temporary
622
+ file or second link is made, so the run directory passes the single-link check that `verify`,
623
+ serving and adding a note run while a note is added. A reader can find a note while it is being
624
+ written, as an empty or short file; it skips and names that file like any unreadable note, and
625
+ the next read finds the whole note. A writer stopped mid-write leaves such a file, which readers
626
+ keep skipping. Adding a note reads no other note, so notes added at the same time from any
627
+ process are all kept, and there is no lock. Readers list at most 1000 entries of `notes/` and
628
+ read at most 500 notes, each within 16 KiB and refused before reading past that; any other
629
+ entry, or a file that is not a note of the run, is skipped and named. The Observer servers serve
630
+ any file under `notes/` only within 16 KiB. A run takes no note past 500.
631
+ `verify` scans the note files with every other run file, so a secret-shaped value in a note
632
+ keeps the run from `share_ready`. A bundle export copies them; an HTML export carries the notes
633
+ read-only after checking the set it read.
634
+
635
+ Threat model: forged web requests are refused, whether from a page on another site or through a
636
+ name rebound to 127.0.0.1, by the token, Origin and Host checks on `POST /api/notes`. A local
637
+ process with write access to the run directory is out of scope: it already has the user's
638
+ privileges and can change any file in the run.
639
+
579
640
  ## Verify Result Share Safety
580
641
 
581
642
  `humanish.verify-result.v1` includes a machine-readable `shareSafety` block in
@@ -169,7 +169,7 @@ The rest of this section names keys by their v3 spelling:
169
169
  - `subject.state` (clone or local-tree subjects, computer-use route): the
170
170
  subject's state story. `state.seed[]` declares ordered, bounded
171
171
  seed/migration/fixture steps (`{ name, command, when: before-build |
172
- before-start | after-ready, timeoutMs }`) executed in-sandbox around the
172
+ before-start | after-ready, timeoutMs }`) executed in-sandbox around the
173
173
  serve sequence; `state.external[]` declares env var names (each must also
174
174
  appear in `subject.env`) pointing at state the study does not control,
175
175
  recorded as unpinned in provenance. Commands persist in evidence as
@@ -189,7 +189,7 @@ before-start | after-ready, timeoutMs }`) executed in-sandbox around the
189
189
  single participant (no E2B to fan out);
190
190
  - a `participants` list (computer-use E2B route): a differentiated fan-out,
191
191
  each entry `{ id?, actorType?, surface?, caseGroup?, persona?, device?,
192
- instruction?, target?, entry?, host?, reasoningEffort?, stopWhen?, dwell? }` becoming one independent E2B desktop (or, on the
192
+ instruction?, target?, entry?, host?, reasoningEffort?, stopWhen?, dwell? }` becoming one independent E2B desktop (or, on the
193
193
  shared-world routes, one participant against the shared plane). `actorType`,
194
194
  `surface`, and `caseGroup` are adapter-owned public-safe labels for grouping
195
195
  simulated users; they are not core enums, and `actorType` is deliberately
@@ -530,10 +530,10 @@ Core-owned fields:
530
530
  convention `study:<id>`, or `lab:<id>` from runs written before 0.108, and nothing else.
531
531
  - `subject` (optional, additive): structured subject provenance,
532
532
  `{ source: clone | app-url | local-tree, repo?, commit?, archiveSha256?,
533
- dirty?, envNames?, state }` where `state` is `{ provenance: seeded |
534
- unpinned | declared-not-run | undeclared | external-public, seed?: [{ name, when,
535
- commandDigest, ok?, exitCode?, timedOut?, durationMs? }], externalEnvNames?
536
- }`. Emitted by the computer-use and shared-world routes and the clone
533
+ dirty?, envNames?, state }` where `state` is `{ provenance: seeded |
534
+ unpinned | declared-not-run | undeclared | external-public, seed?: [{ name, when,
535
+ commandDigest, ok?, exitCode?, timedOut?, durationMs? }], externalEnvNames?
536
+ }`. Emitted by the computer-use and shared-world routes and the clone
537
537
  scripted-browser route; absent on pre-existing and other bundles. `repo`/`commit` are clone-route fields; `archiveSha256`
538
538
  (64-hex sha256, the local-tree provenance pin) and `dirty` (host git
539
539
  porcelain status at pack time) are local-tree-route fields, additive under
@@ -542,7 +542,7 @@ commandDigest, ok?, exitCode?, timedOut?, durationMs? }], externalEnvNames?
542
542
  sha256-16 of the exact seed command; command text and env values never
543
543
  appear. `humanish verify` fails closed when a live `local-tree` bundle carries
544
544
  no well-formed `archiveSha256`, in addition to the existing `subject state
545
- provenance` check.
545
+ provenance` check.
546
546
  - `desktopTemplate` (optional, additive): the custom E2B desktop template (image)
547
547
  the run's sandbox(es) launched on, from `execution.desktop.template`, so the
548
548
  evidence shows which image ran. Present only when a template was configured;
@@ -665,7 +665,7 @@ A shared-world bundle adds two additive, optional fields to `humanish.run-bundle
665
665
  0.106.0):
666
666
  - `sequence: [roleId, …]`: the role ids that actually took a turn, in declared order.
667
667
  - `skippedTail` (optional, live sequential only): `{ afterRoleId, roles,
668
- cause, maxTotalUsd?, estimatedTotalUsd? }`. Each ordered `roles` entry names
668
+ cause, maxTotalUsd?, estimatedTotalUsd? }`. Each ordered `roles` entry names
669
669
  `{ roleId, simId, streamId }` for an unstarted participant. Together with the
670
670
  executed prefix it must account for the full declared denominator. The
671
671
  predecessor must have a matching `harness_error`, explicit `session_error`,
@@ -700,7 +700,7 @@ cause, maxTotalUsd?, estimatedTotalUsd? }`. Each ordered `roles` entry names
700
700
  the internet-reachable getHost URL is synthetic seeded data (author-trust + a
701
701
  provenance gate, not a no-real-data guarantee).
702
702
  - `laneWindows: [{ roleId, simId, streamId, startedAt, endedAt, verdict, routeHostDigest,
703
- commit?, seedDigest }]`: one harness-clocked window per actor; overlapping windows
703
+ commit?, seedDigest }]`: one harness-clocked window per actor; overlapping windows
704
704
  prove ≥2 personas were active simultaneously. `routeHostDigest` == `plane.hostDigest`
705
705
  (every actor drove exactly the harness-minted host).
706
706
  - `stateSeries: [{ timestamp, digest }]`: cadence digests of the shared world under
@@ -1008,9 +1008,12 @@ Core-owned fields:
1008
1008
  `cacheWriteInput`. `summarizedTurns` counts the earlier exchanges the latest
1009
1009
  `explicit_context` request no longer carried whole: lines of the note, or
1010
1010
  only counted once the note reached its cap.
1011
- `requests[]` has one entry per participant request: its `mode` and, in
1011
+ `requests[]` has one entry per participant turn or impressions request: its `mode` and, in
1012
1012
  `explicit_context`, `carriedExchanges`, `carriedScreenshots` and
1013
- `estimatedInputTokens`. Billed input per request is in `tokenUsage.turns`. A
1013
+ `estimatedInputTokens`. The impressions-only request has `kind: impressions`;
1014
+ the optional `kind` field is absent on participant turns and in older bundles.
1015
+ Impressions carry the context the next turn would carry, with the same budget
1016
+ and summarization of older turns. Billed input per request is in `tokenUsage.turns`. A
1014
1017
  participant that ran in `explicit_context` gets a run warning. Absent on other
1015
1018
  providers and on earlier bundles
1016
1019
  - optional `affordanceUse` (`humanish.affordance-use.v1`): which kind of route this
@@ -1026,7 +1029,7 @@ Core-owned fields:
1026
1029
  (the Codex participant), or, when the participant ended the session itself
1027
1030
  without them, one impressions-only request (OpenAI computer-use, threaded or
1028
1031
  `explicit_context`). That request is recorded as `debrief` with `trigger:
1029
- participant_end` and never has a `report` or `messageId`; it leaves the
1032
+ participant_end` and never has a `report` or `messageId`; it leaves the
1030
1033
  participant's `reason`, outcome and friction as they were. An empty `items`
1031
1034
  list means the participant named none. `status: not_collected` carries a
1032
1035
  `reason`: the closing report or impressions request was skipped or failed
@@ -1371,7 +1374,7 @@ Three new `.v1` schema tags ship, all additive and optional so
1371
1374
  the E2B shell sandbox (its acquired-to-cleanup span and `e2b.getInfo` size) and
1372
1375
  one `model-tokens` line for the Codex participant, priced from the model the route passed
1373
1376
  to Codex (`gpt-5.6-sol` unless the study declares one) with `basis:
1374
- aggregated_turns_base_rate`, or `null` with `no_token_usage`. Older terminal bundles record
1377
+ aggregated_turns_base_rate`, or `null` with `no_token_usage`. Older terminal bundles record
1375
1378
  `no_rate_for_model` (model `codex`). The terminal trace records the same `estimatedCost`. The sandbox line is not part of the
1376
1379
  terminal cost ledger, whose lines are checked against `caps.maxUsd`.
1377
1380
 
@@ -1671,7 +1674,7 @@ record its own:
1671
1674
 
1672
1675
  - **Adapter score** (`humanish.adapter-score.v1`, `RunBundle.adapterScore`).
1673
1676
  A namespaced summary the adapter's `score` hook returns: `{ schema, namespace,
1674
- status, score, summary, data? }`. Core never reads `data`, where the adopter's
1677
+ status, score, summary, data? }`. Core never reads `data`, where the adopter's
1675
1678
  component rubric rides; `namespace` (an adopter slug) scopes the whole
1676
1679
  record so a future inert-field audit never misfires.
1677
1680
  - **Namespaced product-noun block** (`RunFeedbackCandidate.adapter`). The