@myagentroam/node 0.9.62 → 0.9.65
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.
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/capabilities.js +110 -2
- package/dist/claude-agent-sdk.js +330 -2
- package/dist/claude-channel.js +44 -2
- package/dist/codex-app-server.js +510 -2
- package/dist/config.js +106 -2
- package/dist/connector/node-connector-options.js +1 -2
- package/dist/connector/node-operation-router.js +22 -2
- package/dist/connector.js +1736 -2
- package/dist/control-outbound-scheduler.js +153 -2
- package/dist/database.js +639 -2
- package/dist/fake-runner.js +129 -2
- package/dist/git-askpass.js +12 -0
- package/dist/git-execution-helper.js +266 -0
- package/dist/health.js +3 -2
- package/dist/main.js +57 -2
- package/dist/mcp-installation-model.js +1 -2
- package/dist/migrations/v004.js +55 -3
- package/dist/migrations/v005.js +13 -3
- package/dist/migrations/v006.js +90 -3
- package/dist/migrations/v007.js +22 -3
- package/dist/migrations/v008.js +18 -3
- package/dist/migrations/v009.js +70 -4
- package/dist/migrations/v010.js +43 -3
- package/dist/migrations/v011.js +20 -3
- package/dist/migrations/v012.js +8 -0
- package/dist/native-jsonl-reader.js +186 -2
- package/dist/native-session-history.js +1143 -2
- package/dist/opencode-runtime.js +80 -2
- package/dist/opencode-server.js +259 -2
- package/dist/operational.js +122 -2
- package/dist/process-tree.js +18 -2
- package/dist/ripgrep-binary.js +31 -2
- package/dist/rotating-log.js +67 -2
- package/dist/runner/abstract-runner.js +260 -2
- package/dist/runner/claude/managed-run-controller.js +355 -2
- package/dist/runner/claude/tool-normalizer.js +120 -2
- package/dist/runner/claude-code-runner.js +303 -2
- package/dist/runner/codex/composer-image-markers.js +8 -2
- package/dist/runner/codex/conversation-parser.js +913 -2
- package/dist/runner/codex/managed-run-controller.js +494 -2
- package/dist/runner/codex/tool-normalizer.js +214 -2
- package/dist/runner/codex-runner.js +585 -2
- package/dist/runner/fake-test-runner.js +47 -2
- package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
- package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
- package/dist/runner/mar-agent/generated-images.js +41 -2
- package/dist/runner/mar-agent/history-projection.js +106 -2
- package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
- package/dist/runner/mar-agent/managed-run-controller.js +785 -2
- package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
- package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
- package/dist/runner/mar-agent-runner.js +458 -2
- package/dist/runner/opencode/conversation-parser.js +221 -2
- package/dist/runner/opencode/managed-run-controller.js +588 -2
- package/dist/runner/opencode/tool-normalizer.js +80 -2
- package/dist/runner/opencode-runner.js +426 -2
- package/dist/runner/runner-registry.js +87 -2
- package/dist/runner-command-engine.js +71 -2
- package/dist/runner-profiles.js +323 -2
- package/dist/runner-usage.js +190 -2
- package/dist/runtime-command-detector.js +73 -2
- package/dist/runtime-model.js +1 -2
- package/dist/runtime-state.js +1509 -2
- package/dist/service/attachment-domain-state.js +7 -2
- package/dist/service/bubblewrap-sandbox-executor.js +543 -2
- package/dist/service/continuous-run-coordinator.js +425 -2
- package/dist/service/conversation-history-service.js +552 -2
- package/dist/service/conversation-hosting-capability-service.js +61 -2
- package/dist/service/conversation-hosting-enablement-service.js +91 -2
- package/dist/service/conversation-hosting-maintenance-service.js +174 -2
- package/dist/service/conversation-segment-service.js +162 -2
- package/dist/service/conversation-template-node-service.js +992 -2
- package/dist/service/external-session-resume-service.js +152 -2
- package/dist/service/fake-managed-run-service.js +60 -2
- package/dist/service/git-execution-service.js +418 -0
- package/dist/service/git-operation-service.js +57 -0
- package/dist/service/hosted-conversation-node-service.js +1982 -2
- package/dist/service/hosted-conversation-store.js +1405 -2
- package/dist/service/managed-runner-session-service.js +35 -2
- package/dist/service/mar-agent-model-transport-test-service.js +88 -2
- package/dist/service/mcp-installation-verifier.js +87 -2
- package/dist/service/mcp-node-operation-service.js +90 -2
- package/dist/service/mission-mcp-server.js +124 -2
- package/dist/service/mission-mcp-stdio.js +40 -2
- package/dist/service/mission-runtime.js +142 -2
- package/dist/service/native-session-projection-service.js +274 -2
- package/dist/service/native-session-watch-service.js +683 -2
- package/dist/service/node-connection-lifecycle-service.js +88 -2
- package/dist/service/node-control-channel.js +85 -2
- package/dist/service/node-control-message-service.js +109 -2
- package/dist/service/node-request-service.js +62 -2
- package/dist/service/node-run-event-bridge.js +88 -2
- package/dist/service/node-terminal-channel.js +202 -2
- package/dist/service/node-upgrade-coordinator.js +137 -2
- package/dist/service/node-workspace-coordinator.js +97 -2
- package/dist/service/recent-run-projection-service.js +99 -2
- package/dist/service/run-attachment-service.js +321 -2
- package/dist/service/run-domain-state.js +4 -2
- package/dist/service/run-event-service.js +246 -2
- package/dist/service/run-ownership-policy.js +22 -2
- package/dist/service/run-workbench-service.js +120 -2
- package/dist/service/runner-channel-message-service.js +20 -2
- package/dist/service/runner-interaction-service.js +243 -2
- package/dist/service/runner-service.js +69 -2
- package/dist/service/runtime-credential-control-service.js +95 -2
- package/dist/service/session-catalog-service.js +404 -2
- package/dist/service/session-command-service.js +125 -2
- package/dist/service/session-context-service.js +128 -2
- package/dist/service/session-domain-state.js +9 -2
- package/dist/service/session-identity-service.js +86 -2
- package/dist/service/session-lifecycle-service.js +248 -2
- package/dist/service/session-message-service.js +270 -2
- package/dist/service/session-presentation-service.js +43 -2
- package/dist/service/session-query-service.js +82 -2
- package/dist/service/session-watch-slot-coordinator.js +21 -2
- package/dist/service/skill-directory-service.js +238 -2
- package/dist/service/skill-install-service.js +434 -2
- package/dist/service/skill-node-operation-service.js +206 -2
- package/dist/service/terminal-relay-state.js +3 -2
- package/dist/service/terminal-service.js +90 -2
- package/dist/service/web-search-error.js +40 -2
- package/dist/service/workbench-event-service.js +21 -2
- package/dist/service/workbench-manifest-service.js +69 -2
- package/dist/service/workspace-change-service.js +290 -2
- package/dist/service/workspace-content-search-service.js +457 -2
- package/dist/service/workspace-domain-state.js +41 -2
- package/dist/service/workspace-file-service.js +150 -2
- package/dist/service/workspace-git-exclude-service.js +119 -2
- package/dist/service/workspace-queue-workbench-service.js +176 -2
- package/dist/service/workspace-service.js +92 -2
- package/dist/service/workspace-session-service.js +154 -2
- package/dist/service/workspace-upload-service.js +262 -2
- package/dist/service/workspace-watch-controller.js +68 -2
- package/dist/service/workspace-watch-service.js +170 -2
- package/dist/service/workspace-watch-snapshot-service.js +218 -2
- package/dist/service/workspace-workbench-service.js +239 -2
- package/dist/service.js +91 -2
- package/dist/storage.js +32 -2
- package/dist/supervisor.js +136 -2
- package/dist/terminal.js +496 -2
- package/dist/util/git-credential-client.js +32 -0
- package/dist/util/node-operation-data.js +9 -2
- package/dist/util/node-operation-parsers.js +382 -2
- package/dist/util/personal-instructions.js +34 -2
- package/dist/util/runner-error.js +70 -2
- package/dist/util/runner-native-session-parsers.js +510 -2
- package/dist/util/safe-error.js +8 -2
- package/dist/util/secret-environment.js +25 -2
- package/dist/workspace.js +1793 -2
- package/package.json +11 -8
- package/vendor/ripgrep/darwin-arm64/rg +0 -0
- package/vendor/ripgrep/darwin-x64/rg +0 -0
- package/vendor/ripgrep/manifest.json +12 -0
- package/README.md +0 -42
- package/dist/event-buffer.js +0 -2
- package/dist/migrations/v001.js +0 -107
- package/dist/migrations/v002.js +0 -2
- package/dist/migrations/v003.js +0 -2
- package/dist/service/mcp-package-installer.js +0 -2
|
@@ -1,2 +1,1143 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x4c6cb8=_0x40d6;(function(_0x449d42,_0x5ef011){const _0x17114a=_0x40d6,_0x27b168=_0x449d42();while(!![]){try{const _0x259754=-parseInt(_0x17114a(0x1b1))/(0x2547+0x796*-0x4+-0x6ee)+-parseInt(_0x17114a(0x1b3))/(0x1663+0x3cc*-0x3+-0xafd)+parseInt(_0x17114a(0x15f))/(0x19*0x41+-0x17a5+-0x7*-0x279)*(-parseInt(_0x17114a(0x1cb))/(0x10eb+-0x29*-0xa7+-0x2ba6))+parseInt(_0x17114a(0x1ed))/(-0x175*0xe+0x10bd+0x3ae)+parseInt(_0x17114a(0x1d0))/(0x1*-0x2d7+0x1b40+-0x1863)+parseInt(_0x17114a(0x1b2))/(0x2639*0x1+0x3f9*0x3+0x1*-0x321d)+-parseInt(_0x17114a(0x175))/(0x2d1*0x1+0x1088+-0x1351)*(-parseInt(_0x17114a(0x1da))/(0x5*0x13d+-0x24b8+0x8*0x3d2));if(_0x259754===_0x5ef011)break;else _0x27b168['push'](_0x27b168['shift']());}catch(_0x5e5acc){_0x27b168['push'](_0x27b168['shift']());}}}(_0x3485,0xf8be7+-0x103ed9+0xecf9f));import{createHash}from'node:crypto';import{readFile,readdir,stat,unlink}from'node:fs/promises';import{homedir}from'node:os';import{basename,join,resolve}from'node:path';import{forEachJsonlRecord,listJsonlFiles,mapConcurrent,readJsonlBackwardWindow,readJsonlFileAnchor,readJsonlWindow}from'./native-jsonl-reader.js';import{nodeLog}from'./operational.js';import{stripClaudePlanTag}from'./runner-command-engine.js';import{stripMissionStartPrompt}from'./service/mission-runtime.js';import{parseCodexComposerImageMarkers}from'./runner/codex/composer-image-markers.js';const DISCOVERY_READ_BYTES=(-0x1ece+-0x20c7+0x3fb5)*(0x1*0x1c48+0x1bb8+-0x3400),TRANSCRIPT_HEADER_READ_BYTES=(0x163e+-0x1d*-0x107+0x89*-0x61)*(0x1af6+0x2*-0xfb5+0x4*0x21d),TRANSCRIPT_READ_MAX_BYTES=(0x1*-0x2102+-0xf76+0x3088)*(0xd8d*0x2+0x1d1f+0x1cd*-0x1d)*(-0xcac+0x5cd+0xadf),TRANSCRIPT_MIN_LINES=-0x2*0x6a3+-0x25c9*0x1+0x340f,TRANSCRIPT_MAX_LINES=0x17*-0x151+0x6*-0x270+0x3ce7,TRANSCRIPT_LINES_PER_TURN=-0x191*0x16+0x3*0x4ef+0x13c9,CONTEXT_USAGE_READ_BYTES=(-0x2*0xbd3+-0x1*-0x2174+0x17*-0x62)*(-0x283*0x4+0xa15*0x3+0xb*-0x179),CLAUDE_CONTEXT_USAGE_READ_BYTES=[CONTEXT_USAGE_READ_BYTES,(0x5*0x23+-0xefa+0x3*0x619)*(-0x100c+-0x1106+0x2512),(-0x137d*0x1+-0x6d1+-0x1*-0x1a52)*(-0x745*-0x1+0xb*0x179+-0x1378)*(0x3*0x106+-0x23ca+0x24b8)],TRANSCRIPT_INDEX_TTL_MS=(-0x17ec+0x24b8+0x192*-0x8)*(0x2*0x9e5e+-0x145b7*-0x1+-0x19813),DISCOVERY_SNAPSHOT_TTL_MS=-0x65a6+-0x4c1*0x14+0xff52,TRANSCRIPT_DETAIL_CACHE_TTL_MS=0x1b42e+-0x3c27+0x8da7*-0x1,TRANSCRIPT_DETAIL_CACHE_MAX_ENTRIES=-0x5*-0x508+-0x20d6+0x7be,transcriptIndex=new Map(),transcriptIndexTimers=new Map(),transcriptDetailCache=new Map(),transcriptDetailReads=new Map(),discoveryReads=new Map(),discoverySnapshots=new Map(),discoveryGenerations=new Map(),DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS=0x1*-0xf5e1+0x20810+0x1fb11,CLAUDE_CONTEXT_WINDOW_ENV=_0x4c6cb8(0x134);function _0x40d6(_0x1811ab,_0x396d0e){_0x1811ab=_0x1811ab-(0x1*0x244d+0x1439+-0x3777);const _0x36cb23=_0x3485();let _0x1c1ad1=_0x36cb23[_0x1811ab];if(_0x40d6['KsmEZp']===undefined){var _0x1ae9ae=function(_0x627500){const _0x17e72f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x275ded='',_0x4bea81='';for(let _0x353951=-0x18a*-0x19+-0x1737+-0xf43,_0xa87f14,_0x4678f0,_0x2bd5c3=-0xffe+0x355*-0xb+0x1*0x34a5;_0x4678f0=_0x627500['charAt'](_0x2bd5c3++);~_0x4678f0&&(_0xa87f14=_0x353951%(0x775*-0x2+-0x49+-0x13*-0xcd)?_0xa87f14*(-0x6c7*-0x4+0x18ff+0x4b*-0xb1)+_0x4678f0:_0x4678f0,_0x353951++%(0x16cf+0x1159+0x1*-0x2824))?_0x275ded+=String['fromCharCode'](0xe87*-0x2+0xf0b*-0x2+0x3c23&_0xa87f14>>(-(0xa3f+-0x8e5*-0x3+-0x24ec)*_0x353951&-0xedb+-0x2*0x6a3+-0x1c27*-0x1)):-0xacc+0x17*-0x151+0x3*0xdb1){_0x4678f0=_0x17e72f['indexOf'](_0x4678f0);}for(let _0x389015=0x3*-0xcbb+-0x2276+0x1*0x48a7,_0x4375a7=_0x275ded['length'];_0x389015<_0x4375a7;_0x389015++){_0x4bea81+='%'+('00'+_0x275ded['charCodeAt'](_0x389015)['toString'](0xdb*-0x7+-0x17a6+-0x1*-0x1db3))['slice'](-(0x41a+0x1*0xfc3+-0x13db));}return decodeURIComponent(_0x4bea81);};_0x40d6['DSOEHs']=_0x1ae9ae,_0x40d6['qUJcQn']={},_0x40d6['KsmEZp']=!![];}const _0x4dcb8b=_0x36cb23[0x2*0x202+-0x7*-0x443+0x1*-0x21d9];_0x40d6['eAmsZh']!==_0x4dcb8b&&(_0x40d6['qUJcQn']={},_0x40d6['eAmsZh']=_0x4dcb8b);const _0x10d572=_0x40d6['qUJcQn'][_0x1811ab];return _0x10d572===undefined?(_0x1c1ad1=_0x40d6['DSOEHs'](_0x1c1ad1),_0x40d6['qUJcQn'][_0x1811ab]=_0x1c1ad1):_0x1c1ad1=_0x10d572,_0x1c1ad1;}export async function discoverNativeSessions(_0xd88c16,_0x5634f5){const _0x140d4c=_0x4c6cb8,_0x58ab4c=canonical(_0x5634f5);return(await discoverAllNativeSessions(_0xd88c16))[_0x140d4c(0x1b6)](_0x4bf980=>canonical(_0x4bf980[_0x140d4c(0x14d)])===_0x58ab4c);}export async function discoverAllNativeSessions(_0x564adf){const _0x5b33a8=_0x4c6cb8,_0x5f15c3=discoveryKey(_0x564adf),_0x5e400a=discoverySnapshots[_0x5b33a8(0x1d4)](_0x5f15c3);if(_0x5e400a!==undefined&&_0x5e400a[_0x5b33a8(0x18f)]>Date[_0x5b33a8(0x1bb)]())return _0x5e400a[_0x5b33a8(0x1ac)]+=0xbf2+0x9f*-0x1a+0x435,_0x5e400a[_0x5b33a8(0x165)];const _0x3385d2=discoveryReads[_0x5b33a8(0x1d4)](_0x5f15c3);if(_0x3385d2!==undefined)return nodeLog(_0x5b33a8(0x172),{'runner':_0x564adf}),_0x3385d2;const _0x51a46f=discoveryGenerations[_0x5b33a8(0x1d4)](_0x5f15c3)??-0x1*-0x1877+0x1e0e*0x1+-0x11*0x335,_0x5baaef=performNativeSessionDiscovery(_0x564adf,_0x5e400a)[_0x5b33a8(0x17b)](_0x3403aa=>{const _0x2bfca1=_0x5b33a8;if((discoveryGenerations[_0x2bfca1(0x1d4)](_0x5f15c3)??-0x4e*-0x3d+0x366+-0x15fc)===_0x51a46f)discoverySnapshots[_0x2bfca1(0x117)](_0x5f15c3,_0x3403aa);return _0x3403aa[_0x2bfca1(0x165)];})[_0x5b33a8(0x173)](()=>{const _0x382733=_0x5b33a8;if(discoveryReads[_0x382733(0x1d4)](_0x5f15c3)===_0x5baaef)discoveryReads[_0x382733(0x14c)](_0x5f15c3);});return discoveryReads[_0x5b33a8(0x117)](_0x5f15c3,_0x5baaef),_0x5baaef;}async function performNativeSessionDiscovery(_0x36d8df,_0x3c6558){const _0x3db6c5=_0x4c6cb8,_0x2cd06c=performance[_0x3db6c5(0x1bb)](),_0x2e4a5c=new Map();nodeLog(_0x3db6c5(0x1a5),{'runner':_0x36d8df});const _0xae16d2=(await listJsonlFiles(transcriptRoot(_0x36d8df)))[_0x3db6c5(0x1b6)](_0x4ff371=>_0x36d8df!==_0x3db6c5(0x1c3)||!_0x4ff371[_0x3db6c5(0x168)](/[\\/]/u)[_0x3db6c5(0x126)](_0x3db6c5(0x14b)));nodeLog(_0x3db6c5(0x1ca),{'runner':_0x36d8df,'files':_0xae16d2[_0x3db6c5(0x1e1)],'durationMs':Math[_0x3db6c5(0x11f)](performance[_0x3db6c5(0x1bb)]()-_0x2cd06c)});let _0x4b02ff=0x16c6+0x6a4*-0x2+-0x97e,_0x13e28e=-0x49*-0x16+-0x623+-0x1*0x23,_0x63d81=0x1ae8+-0x2475*0x1+-0x98d*-0x1,_0x19744a=0x362*-0x5+0x2525+-0x143b,_0x5ea90d=-0x1*0x1229+-0x13dd+0x2606,_0x4a8d1c=0x16ad+-0x1*-0xb7b+0x1114*-0x2;const _0x441e60=await mapConcurrent(_0xae16d2,0x22*-0x6f+0x1*0x1bbf+-0xce1,async _0x4fecd9=>{const _0x48eff6=_0x3db6c5;let _0x399276;const _0x521591=performance[_0x48eff6(0x1bb)]();try{const _0x516ee4=await stat(_0x4fecd9);_0x399276=_0x516ee4[_0x48eff6(0x161)]+':'+_0x516ee4[_0x48eff6(0x19d)];}catch{return _0x19744a+=0xef*-0x22+0xb*0xa6+0x189d,undefined;}finally{_0x5ea90d+=performance[_0x48eff6(0x1bb)]()-_0x521591;}const _0x2a7f0d=_0x3c6558?.[_0x48eff6(0x121)][_0x48eff6(0x1d4)](_0x4fecd9);let _0x1bb6ee;if(_0x2a7f0d?.[_0x48eff6(0x188)]===_0x399276)_0x1bb6ee=_0x2a7f0d[_0x48eff6(0x19c)],_0x63d81+=-0x37*0x16+-0x14e8+0x1*0x19a3;else{const _0x542e65=performance[_0x48eff6(0x1bb)]();_0x1bb6ee=await readTranscript(_0x4fecd9,_0x36d8df,DISCOVERY_READ_BYTES),_0x4a8d1c+=performance[_0x48eff6(0x1bb)]()-_0x542e65,_0x13e28e+=-0xb5f+0x2654+-0x1af4;}_0x4b02ff+=-0x21f1*-0x1+0x2*-0xbb3+-0xa8a;if(_0x4b02ff%(0x1158+-0x2010+0x31*0x52)===0x1*0xb7b+-0x2*-0xddc+-0x2733)nodeLog(_0x48eff6(0x198),{'runner':_0x36d8df,'completed':_0x4b02ff,'files':_0xae16d2[_0x48eff6(0x1e1)],'parsedFiles':_0x13e28e,'reusedFiles':_0x63d81,'metadataFailures':_0x19744a,'metadataWorkMs':Math[_0x48eff6(0x11f)](_0x5ea90d),'parseWorkMs':Math[_0x48eff6(0x11f)](_0x4a8d1c),'durationMs':Math[_0x48eff6(0x11f)](performance[_0x48eff6(0x1bb)]()-_0x2cd06c)});return{'path':_0x4fecd9,'fingerprint':_0x399276,'parsed':_0x1bb6ee};}),_0x40f799=new Map();for(const _0x1b4d8f of _0x441e60){if(_0x1b4d8f===undefined)continue;_0x40f799[_0x3db6c5(0x117)](_0x1b4d8f[_0x3db6c5(0x138)],{'fingerprint':_0x1b4d8f[_0x3db6c5(0x188)],'parsed':_0x1b4d8f[_0x3db6c5(0x19c)]});const _0x39fd2c=_0x1b4d8f[_0x3db6c5(0x19c)];if(_0x39fd2c===undefined)continue;const _0x4fdb10=canonical(_0x39fd2c[_0x3db6c5(0x14d)]);setTranscriptIndex(indexKey(_0x36d8df,_0x4fdb10,_0x39fd2c[_0x3db6c5(0x1a0)]),_0x1b4d8f[_0x3db6c5(0x138)]),_0x2e4a5c[_0x3db6c5(0x117)](_0x4fdb10+'\x00'+_0x39fd2c[_0x3db6c5(0x1a0)],_0x39fd2c);}return nodeLog(_0x3db6c5(0x13a),{'runner':_0x36d8df,'files':_0xae16d2[_0x3db6c5(0x1e1)],'sessions':_0x2e4a5c[_0x3db6c5(0x161)],'parsedFiles':_0x13e28e,'reusedFiles':_0x63d81,'unparsedFiles':[..._0x40f799[_0x3db6c5(0x16e)]()][_0x3db6c5(0x1b6)](_0x387084=>_0x387084[_0x3db6c5(0x19c)]===undefined)[_0x3db6c5(0x1e1)],'metadataFailures':_0x19744a,'metadataWorkMs':Math[_0x3db6c5(0x11f)](_0x5ea90d),'parseWorkMs':Math[_0x3db6c5(0x11f)](_0x4a8d1c),'cacheMode':_0x3c6558===undefined?_0x3db6c5(0x10f):_0x3db6c5(0x142),'previousCacheHits':_0x3c6558?.[_0x3db6c5(0x1ac)]??0x1031+0x21c0+-0x31f1,'durationMs':Math[_0x3db6c5(0x11f)](performance[_0x3db6c5(0x1bb)]()-_0x2cd06c)}),{'expiresAt':Date[_0x3db6c5(0x1bb)]()+DISCOVERY_SNAPSHOT_TTL_MS,'files':_0x40f799,'sessions':[..._0x2e4a5c[_0x3db6c5(0x16e)]()],'cacheHits':0x0};}export async function readNativeSession(_0x42293b,_0x586af1,_0x5dc03d,_0x2b87be,_0x1904df=-0x11cf+-0x3bb+-0x84*-0x2a){const _0x4f598e=_0x4c6cb8,_0x49c95e=canonical(_0x586af1),_0x25e942=getTranscriptIndex(indexKey(_0x42293b,_0x49c95e,_0x5dc03d));if(_0x25e942===undefined)return undefined;const _0x595755=await readTranscriptDetail(_0x25e942,_0x42293b,_0x2b87be,_0x2b87be?.[_0x4f598e(0x11a)]??_0x1904df),_0x2221df=_0x595755?.[_0x4f598e(0x17f)];if(_0x2221df===undefined||_0x2221df[_0x4f598e(0x1a0)]!==_0x5dc03d||canonical(_0x2221df[_0x4f598e(0x14d)])!==_0x49c95e)return deleteTranscriptIndex(indexKey(_0x42293b,_0x49c95e,_0x5dc03d)),undefined;return _0x595755?.[_0x4f598e(0x147)]===![]?{..._0x2221df,'cursorReset':!![]}:_0x2221df;}async function readTranscriptDetail(_0x157740,_0x43b539,_0x582742,_0x353693){const _0x481f71=_0x4c6cb8;let _0x537888;try{const _0x414cc3=await stat(_0x157740);_0x537888=_0x414cc3[_0x481f71(0x161)]+':'+_0x414cc3[_0x481f71(0x19d)];}catch{return undefined;}const _0x2db33a=Number(_0x537888[_0x481f71(0x1f5)](0x106c*-0x1+-0x9f1*0x2+0x2*0x1227,_0x537888[_0x481f71(0x11c)](':'))),_0x601f78=_0x582742!==undefined&&_0x582742[_0x481f71(0x1d3)]<=_0x2db33a&&await readJsonlFileAnchor(_0x157740,_0x582742[_0x481f71(0x1e8)])===_0x582742[_0x481f71(0x1cf)]?_0x582742:undefined,_0x33279c=Math[_0x481f71(0x1c4)](TRANSCRIPT_MAX_LINES,Math[_0x481f71(0x15e)](TRANSCRIPT_MIN_LINES,Math[_0x481f71(0x15e)](-0x438*-0x3+0x1a1+-0xe48,_0x353693)*TRANSCRIPT_LINES_PER_TURN)),_0x537e95=(_0x601f78===undefined?_0x481f71(0x1ce):_0x601f78[_0x481f71(0x1cf)]+':'+_0x601f78[_0x481f71(0x1d3)]+':'+_0x601f78[_0x481f71(0x180)])+':'+_0x33279c,_0x1cfa59=_0x43b539+'\x00'+_0x157740+'\x00'+_0x537e95,_0x59880b=_0x601f78===undefined?_0x537888:_0x601f78[_0x481f71(0x1cf)]+':'+_0x601f78[_0x481f71(0x1d3)],_0x47ee93=transcriptDetailCache[_0x481f71(0x1d4)](_0x1cfa59);if(_0x47ee93?.[_0x481f71(0x188)]===_0x59880b&&_0x47ee93[_0x481f71(0x18f)]>Date[_0x481f71(0x1bb)]())return _0x47ee93[_0x481f71(0x18f)]=Date[_0x481f71(0x1bb)]()+TRANSCRIPT_DETAIL_CACHE_TTL_MS,transcriptDetailCache[_0x481f71(0x14c)](_0x1cfa59),transcriptDetailCache[_0x481f71(0x117)](_0x1cfa59,_0x47ee93),{'history':_0x47ee93[_0x481f71(0x19c)],'cursorAccepted':_0x582742===undefined||_0x601f78!==undefined};transcriptDetailCache[_0x481f71(0x14c)](_0x1cfa59);const _0x179d1b=transcriptDetailReads[_0x481f71(0x1d4)](_0x1cfa59);if(_0x179d1b?.[_0x481f71(0x188)]===_0x59880b)return nodeLog(_0x481f71(0x1ba),{'runner':_0x43b539}),{'history':await _0x179d1b[_0x481f71(0x19a)],'cursorAccepted':_0x582742===undefined||_0x601f78!==undefined};const _0x1b00f1=performance[_0x481f71(0x1bb)](),_0x49c4ab=readTranscript(_0x157740,_0x43b539,TRANSCRIPT_READ_MAX_BYTES,_0x601f78,_0x33279c)[_0x481f71(0x17b)](_0x192be6=>_0x192be6===undefined?undefined:{..._0x192be6,'windowReadLimit':_0x582742?.[_0x481f71(0x11a)]??_0x353693})[_0x481f71(0x17b)](_0x167be8=>{const _0x55e7c5=_0x481f71;transcriptDetailReads[_0x55e7c5(0x1d4)](_0x1cfa59)?.[_0x55e7c5(0x19a)]===_0x49c4ab&&(transcriptDetailCache[_0x55e7c5(0x117)](_0x1cfa59,{'fingerprint':_0x59880b,'parsed':_0x167be8,'expiresAt':Date[_0x55e7c5(0x1bb)]()+TRANSCRIPT_DETAIL_CACHE_TTL_MS}),pruneTranscriptDetailCache());const _0x12968f=Math[_0x55e7c5(0x11f)](performance[_0x55e7c5(0x1bb)]()-_0x1b00f1);if(_0x12968f>=-0x9*-0x23b+0x1*-0x1503+-0x62*-0x5)nodeLog(_0x55e7c5(0x186),{'runner':_0x43b539,'bytes':Number(_0x537888[_0x55e7c5(0x1f5)](0x101d+-0x2344+0x1*0x1327,_0x537888[_0x55e7c5(0x11c)](':'))),'durationMs':_0x12968f});return _0x167be8;})[_0x481f71(0x173)](()=>{const _0xc298c2=_0x481f71;if(transcriptDetailReads[_0xc298c2(0x1d4)](_0x1cfa59)?.[_0xc298c2(0x19a)]===_0x49c4ab)transcriptDetailReads[_0xc298c2(0x14c)](_0x1cfa59);});return transcriptDetailReads[_0x481f71(0x117)](_0x1cfa59,{'fingerprint':_0x59880b,'read':_0x49c4ab}),{'history':await _0x49c4ab,'cursorAccepted':_0x582742===undefined||_0x601f78!==undefined};}function pruneTranscriptDetailCache(){const _0x572224=_0x4c6cb8,_0x1e83e8=Date[_0x572224(0x1bb)]();for(const [_0x34b9bc,_0x39c417]of transcriptDetailCache)if(_0x39c417[_0x572224(0x18f)]<=_0x1e83e8)transcriptDetailCache[_0x572224(0x14c)](_0x34b9bc);while(transcriptDetailCache[_0x572224(0x161)]>TRANSCRIPT_DETAIL_CACHE_MAX_ENTRIES){const _0x30cf5d=transcriptDetailCache[_0x572224(0x1c0)]()[_0x572224(0x1f1)]()[_0x572224(0x1a2)];if(_0x30cf5d===undefined)return;transcriptDetailCache[_0x572224(0x14c)](_0x30cf5d);}}export async function readCodexNativeContextUsage(_0x4e7516,_0xffb658){const _0x3135ee=_0x4c6cb8,_0x2ea712=canonical(_0x4e7516);let _0x2331ad=getTranscriptIndex(indexKey(_0x3135ee(0x1ee),_0x2ea712,_0xffb658));_0x2331ad===undefined&&(await discoverNativeSessions(_0x3135ee(0x1ee),_0x4e7516),_0x2331ad=getTranscriptIndex(indexKey(_0x3135ee(0x1ee),_0x2ea712,_0xffb658)));if(_0x2331ad===undefined)return undefined;const _0x1333bb=await readJsonlWindow(_0x2331ad,{'tailBytes':CONTEXT_USAGE_READ_BYTES});if(_0x1333bb===undefined)return undefined;let _0x5dc49d;return forEachJsonlRecord(_0x1333bb[_0x3135ee(0x17d)],_0x1ce3d3=>{const _0x186763=codexContextUsage(_0x1ce3d3);if(_0x186763!==undefined)_0x5dc49d=_0x186763;}),_0x5dc49d;}export async function readClaudeNativeContextUsage(_0x318f4e,_0x43610c,_0x118aa5={}){const _0x1a8a1d=_0x4c6cb8,_0x185c21=canonical(_0x318f4e);let _0x5494e0=getTranscriptIndex(indexKey(_0x1a8a1d(0x1c3),_0x185c21,_0x43610c));_0x5494e0??=await locateClaudeTranscript(_0x185c21,_0x43610c);_0x5494e0===undefined&&(await discoverNativeSessions(_0x1a8a1d(0x1c3),_0x318f4e),_0x5494e0=getTranscriptIndex(indexKey(_0x1a8a1d(0x1c3),_0x185c21,_0x43610c)));if(_0x5494e0===undefined)return undefined;const _0x23a208=await readLatestClaudeContextUsage(_0x5494e0);if(_0x23a208===undefined)return undefined;return{..._0x23a208,'maxTokens':await claudeContextWindowTokens(_0x118aa5)};}async function readLatestClaudeContextUsage(_0x449416){const _0x538677=_0x4c6cb8;for(const _0x47f15b of CLAUDE_CONTEXT_USAGE_READ_BYTES){const _0x3a0fdd=await readJsonlWindow(_0x449416,{'tailBytes':_0x47f15b});if(_0x3a0fdd===undefined)return undefined;let _0x19372e;forEachJsonlRecord(_0x3a0fdd[_0x538677(0x17d)],_0x3be5f3=>{const _0x5bd9b7=claudeContextUsage(_0x3be5f3);if(_0x5bd9b7!==undefined)_0x19372e=_0x5bd9b7;});if(_0x19372e!==undefined)return _0x19372e;if(!_0x3a0fdd[_0x538677(0x15c)])return undefined;}return undefined;}async function locateClaudeTranscript(_0x136c98,_0x29aac4){const _0x1e33b1=_0x4c6cb8,_0x74d2b8=transcriptRoot(_0x1e33b1(0x1c3));let _0x362e3f;try{_0x362e3f=await readdir(_0x74d2b8,{'withFileTypes':!![]});}catch{return undefined;}const _0x50ac7d=_0x362e3f[_0x1e33b1(0x1b6)](_0x4934d5=>_0x4934d5[_0x1e33b1(0x12b)]())[_0x1e33b1(0x1b5)](_0x42c61e=>join(_0x74d2b8,_0x42c61e[_0x1e33b1(0x159)],_0x29aac4+_0x1e33b1(0x136))),_0x1e6e79=await mapConcurrent(_0x50ac7d,-0xa*-0x2b4+-0x2389+-0x2b*-0x33,async _0x5c0032=>({'path':_0x5c0032,'history':await readTranscript(_0x5c0032,_0x1e33b1(0x1c3),DISCOVERY_READ_BYTES)})),_0x5d3b04=_0x1e6e79[_0x1e33b1(0x145)](({history:_0x36ce24})=>_0x36ce24?.[_0x1e33b1(0x1a0)]===_0x29aac4&&canonical(_0x36ce24[_0x1e33b1(0x14d)])===_0x136c98);if(_0x5d3b04===undefined)return undefined;return setTranscriptIndex(indexKey(_0x1e33b1(0x1c3),_0x136c98,_0x29aac4),_0x5d3b04[_0x1e33b1(0x138)]),_0x5d3b04[_0x1e33b1(0x138)];}export async function claudeContextWindowTokens(_0x2854af={}){const _0x40c32e=_0x4c6cb8,_0x579beb=_0x2854af[_0x40c32e(0x1f4)]??process.env,_0x1c721d=positiveInteger(_0x579beb[CLAUDE_CONTEXT_WINDOW_ENV]);if(_0x1c721d!==undefined)return _0x1c721d;try{const _0x4fb700=JSON[_0x40c32e(0x1e5)](await readFile(_0x2854af[_0x40c32e(0x178)]??join(homedir(),_0x40c32e(0x1d9),_0x40c32e(0x11d)),_0x40c32e(0x1be)));if(isRecord(_0x4fb700)&&isRecord(_0x4fb700[_0x40c32e(0x12a)])){const _0x229c5f=positiveInteger(_0x4fb700[_0x40c32e(0x12a)][CLAUDE_CONTEXT_WINDOW_ENV]);if(_0x229c5f!==undefined)return _0x229c5f;}}catch{}return DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS;}export async function removeNativeSession(_0x2255cb,_0x1f6a4b,_0x1af23a){const _0x4200e8=_0x4c6cb8,_0x3a0708=canonical(_0x1f6a4b);let _0x3aa231=getTranscriptIndex(indexKey(_0x2255cb,_0x3a0708,_0x1af23a));_0x3aa231===undefined&&(await discoverNativeSessions(_0x2255cb,_0x1f6a4b),_0x3aa231=getTranscriptIndex(indexKey(_0x2255cb,_0x3a0708,_0x1af23a)));if(_0x3aa231===undefined)throw new Error(_0x4200e8(0x1c1));const _0x2985eb=await readTranscript(_0x3aa231,_0x2255cb,DISCOVERY_READ_BYTES);if(_0x2985eb===undefined||_0x2985eb[_0x4200e8(0x1a0)]!==_0x1af23a||canonical(_0x2985eb[_0x4200e8(0x14d)])!==_0x3a0708){deleteTranscriptIndex(indexKey(_0x2255cb,_0x3a0708,_0x1af23a));throw new Error(_0x4200e8(0x1c1));}try{await unlink(_0x3aa231);}catch(_0x467403){if(_0x467403[_0x4200e8(0x17c)]===_0x4200e8(0x110))throw new Error(_0x4200e8(0x1c1));throw _0x467403;}deleteTranscriptIndex(indexKey(_0x2255cb,_0x3a0708,_0x1af23a));const _0x2385c7=_0x2255cb+'\x00'+_0x3aa231+'\x00';for(const _0x4982f8 of transcriptDetailCache[_0x4200e8(0x1c0)]())if(_0x4982f8[_0x4200e8(0x160)](_0x2385c7))transcriptDetailCache[_0x4200e8(0x14c)](_0x4982f8);for(const _0x2c84b7 of transcriptDetailReads[_0x4200e8(0x1c0)]())if(_0x2c84b7[_0x4200e8(0x160)](_0x2385c7))transcriptDetailReads[_0x4200e8(0x14c)](_0x2c84b7);invalidateNativeDiscovery(_0x2255cb);}function transcriptRoot(_0x16515c){const _0x423a15=_0x4c6cb8;return _0x16515c===_0x423a15(0x1ee)?join(homedir(),_0x423a15(0x1d5),_0x423a15(0x165)):join(homedir(),_0x423a15(0x1d9),_0x423a15(0x13c));}function discoveryKey(_0x3feeb4){return _0x3feeb4+'\x00'+transcriptRoot(_0x3feeb4);}function invalidateNativeDiscovery(_0x556579){const _0x1180b5=_0x4c6cb8,_0x1a6f53=discoveryKey(_0x556579);discoveryGenerations[_0x1180b5(0x117)](_0x1a6f53,(discoveryGenerations[_0x1180b5(0x1d4)](_0x1a6f53)??0x1*-0x17f6+0x62f+0x11c7)+(-0x54*0x55+-0xa14+0x25f9*0x1)),discoverySnapshots[_0x1180b5(0x14c)](_0x1a6f53),discoveryReads[_0x1180b5(0x14c)](_0x1a6f53);}async function readTranscript(_0x23a2f2,_0x1f8c4a,_0x3db5af,_0x5ed442,_0x5ca1bb=Number[_0x4c6cb8(0x1f0)]){const _0x1e6060=_0x4c6cb8,_0x590a15=await readJsonlBackwardWindow(_0x23a2f2,{'headBytes':Math[_0x1e6060(0x1c4)](_0x3db5af,TRANSCRIPT_HEADER_READ_BYTES),'targetLines':_0x5ca1bb,'maxBytes':_0x3db5af,..._0x5ed442===undefined?{}:{'page':_0x5ed442}});if(_0x590a15===undefined)return undefined;const {content:_0xf40c7,truncated:_0x5eeeec}=_0x590a15;let _0x1d5791,_0x95c974,_0x7e5808=![];const _0x1496b1=[],_0x44067a=new Map(),_0x2ecd34=new Set(),_0x5cd379=new Set();forEachJsonlRecord(_0xf40c7,_0x4d4762=>{const _0x401ea9=_0x1e6060;if(derivedTranscriptRecord(_0x1f8c4a,_0x4d4762))_0x7e5808=!![];_0x1d5791??=workspacePath(_0x4d4762),_0x95c974??=sessionId(_0x4d4762);if(_0x1f8c4a===_0x401ea9(0x1c3)&&typeof _0x4d4762[_0x401ea9(0x1ef)]===_0x401ea9(0x127)&&isClaudeCompactCommand(_0x4d4762))_0x5cd379[_0x401ea9(0x158)](_0x4d4762[_0x401ea9(0x1ef)]);}),forEachJsonlRecord(_0x5eeeec?_0x590a15[_0x1e6060(0x1af)]:_0xf40c7,_0x33d8fd=>{const _0x50f44f=_0x1e6060,_0x5b5ed6=typeof _0x33d8fd[_0x50f44f(0x1ef)]===_0x50f44f(0x127)?_0x33d8fd[_0x50f44f(0x1ef)]:undefined,_0x5d1ae5=typeof _0x33d8fd[_0x50f44f(0x12e)]===_0x50f44f(0x127)?_0x33d8fd[_0x50f44f(0x12e)]:undefined;if(_0x33d8fd[_0x50f44f(0x1e0)]===!![]&&_0x5b5ed6!==undefined)_0x2ecd34[_0x50f44f(0x158)](_0x5b5ed6);if(_0x1f8c4a===_0x50f44f(0x1c3)&&_0x5d1ae5!==undefined&&_0x5cd379[_0x50f44f(0x1aa)](_0x5d1ae5)&&isClaudeCompactSuccess(_0x33d8fd)){_0x1496b1[_0x50f44f(0x124)]({'kind':_0x50f44f(0x15d),'phase':_0x50f44f(0x199),'summary':null,'createdAt':timestampOf(_0x33d8fd),'nativeId':_0x5d1ae5});return;}if(isHiddenTranscriptRecord(_0x33d8fd)||_0x5d1ae5!==undefined&&_0x2ecd34[_0x50f44f(0x1aa)](_0x5d1ae5))return;const _0x113d05=codexGeneratedImageEvent(_0x33d8fd);if(_0x113d05!==undefined)_0x1496b1[_0x50f44f(0x124)](_0x113d05);for(const _0x3208bb of transcriptItems(_0x1f8c4a,_0x33d8fd)){const _0x252427=_0x5b5ed6===undefined?_0x3208bb:{..._0x3208bb,'nativeId':_0x5b5ed6};if(_0x252427[_0x50f44f(0x18b)]===_0x50f44f(0x1c7)){const _0x7b3038=_0x44067a[_0x50f44f(0x1d4)](_0x252427[_0x50f44f(0x1d1)]);if(_0x7b3038!==undefined)_0x1496b1[_0x7b3038]=withToolResult(_0x1496b1[_0x7b3038],_0x252427);continue;}if(_0x252427[_0x50f44f(0x18b)]===_0x50f44f(0x197)){_0x44067a[_0x50f44f(0x117)](_0x252427[_0x50f44f(0x1d1)],_0x1496b1[_0x50f44f(0x1e1)]),_0x1496b1[_0x50f44f(0x124)](_0x252427);continue;}_0x1496b1[_0x50f44f(0x124)](_0x252427);}});if(_0x7e5808)return undefined;if(_0x1d5791===undefined)return undefined;const _0x26a3f1=_0x1496b1[_0x1e6060(0x145)](_0x42fa64=>_0x42fa64[_0x1e6060(0x18b)]===_0x1e6060(0x16a)&&_0x42fa64[_0x1e6060(0x1dd)]===_0x1e6060(0x14f))?.[_0x1e6060(0x1a4)],_0x8213b1=_0x26a3f1===undefined?undefined:stripClaudePlanTag(stripMissionStartPrompt(_0x26a3f1));return{'runner':_0x1f8c4a,'externalSessionId':_0x95c974??basename(_0x23a2f2,_0x1e6060(0x136)),'cwd':_0x1d5791,..._0x8213b1===undefined||_0x8213b1[_0x1e6060(0x1e1)]===-0x1522+0xf1b+-0x1*-0x607?{}:{'title':compact(_0x8213b1)},'digest':createHash(_0x1e6060(0x129))[_0x1e6060(0x1d2)](_0xf40c7)[_0x1e6060(0x1b4)](_0x1e6060(0x171)),'items':_0x1496b1,'lastActivityAt':Math[_0x1e6060(0x15e)](0x41*0x11+0x157e+-0x19cf,..._0x1496b1[_0x1e6060(0x1b5)](_0x49882c=>_0x49882c[_0x1e6060(0x156)]??0x5*0x7c3+0x234a+-0x1*0x4a19)),'truncated':_0x5eeeec,'windowStart':_0x590a15[_0x1e6060(0x170)],'windowEnd':_0x590a15[_0x1e6060(0x133)],'snapshotEnd':_0x590a15[_0x1e6060(0x1d3)],'fileAnchor':_0x590a15[_0x1e6060(0x1cf)],'anchorBytes':_0x590a15[_0x1e6060(0x1e8)]};}function derivedTranscriptRecord(_0xf540a1,_0x5d7237){const _0x10a6c1=_0x4c6cb8;if(_0xf540a1===_0x10a6c1(0x1c3))return _0x5d7237[_0x10a6c1(0x114)]===!![];if(_0xf540a1!==_0x10a6c1(0x1ee)||_0x5d7237[_0x10a6c1(0x11e)]!==_0x10a6c1(0x191))return![];const _0x222d79=isRecord(_0x5d7237[_0x10a6c1(0x183)])?_0x5d7237[_0x10a6c1(0x183)]:undefined;if(_0x222d79===undefined)return![];if(_0x222d79[_0x10a6c1(0x163)]===_0x10a6c1(0x1f6))return!![];const _0x1f9f0c=_0x222d79[_0x10a6c1(0x1c8)];return _0x1f9f0c===_0x10a6c1(0x1f6)||isRecord(_0x1f9f0c)&&(_0x1f9f0c[_0x10a6c1(0x18b)]===_0x10a6c1(0x1f6)||isRecord(_0x1f9f0c[_0x10a6c1(0x1f6)]));}function workspacePath(_0x4a9e03){const _0x2e4749=_0x4c6cb8;return firstString(_0x4a9e03,[_0x2e4749(0x14d),_0x2e4749(0x18e),_0x2e4749(0x162)])??nestedString(_0x4a9e03,[_0x2e4749(0x183),_0x2e4749(0x14d)])??nestedString(_0x4a9e03,[_0x2e4749(0x16a),_0x2e4749(0x14d)]);}function sessionId(_0x470e6a){const _0x57fc09=_0x4c6cb8;if(_0x470e6a[_0x57fc09(0x11e)]===_0x57fc09(0x191)){const _0xc22855=nestedString(_0x470e6a,[_0x57fc09(0x183),'id']);if(_0xc22855!==undefined)return _0xc22855;}return firstString(_0x470e6a,[_0x57fc09(0x115),_0x57fc09(0x137),_0x57fc09(0x19e),_0x57fc09(0x16c)])??nestedString(_0x470e6a,[_0x57fc09(0x183),'id'])??nestedString(_0x470e6a,[_0x57fc09(0x183),_0x57fc09(0x137)])??nestedString(_0x470e6a,[_0x57fc09(0x183),_0x57fc09(0x19e)]);}function codexContextUsage(_0x461ff8){const _0x1d8161=_0x4c6cb8;if(!isRecord(_0x461ff8)||_0x461ff8[_0x1d8161(0x11e)]!==_0x1d8161(0x194)||!isRecord(_0x461ff8[_0x1d8161(0x183)]))return undefined;const _0x35f2ac=_0x461ff8[_0x1d8161(0x183)];if(_0x35f2ac[_0x1d8161(0x11e)]!==_0x1d8161(0x1c6)||!isRecord(_0x35f2ac[_0x1d8161(0x192)]))return undefined;const _0x583f7d=_0x35f2ac[_0x1d8161(0x192)][_0x1d8161(0x113)],_0x1969d1=_0x35f2ac[_0x1d8161(0x192)][_0x1d8161(0x1b9)];if(!isRecord(_0x583f7d)||typeof _0x583f7d[_0x1d8161(0x149)]!==_0x1d8161(0x187)||typeof _0x1969d1!==_0x1d8161(0x187))return undefined;if(!Number[_0x1d8161(0x1ab)](_0x583f7d[_0x1d8161(0x149)])||!Number[_0x1d8161(0x1cd)](_0x583f7d[_0x1d8161(0x149)])||!Number[_0x1d8161(0x1ab)](_0x1969d1)||!Number[_0x1d8161(0x1cd)](_0x1969d1)||_0x1969d1<=0x4*-0x304+0x11b4+-0x5a4||_0x583f7d[_0x1d8161(0x149)]<0xb03*-0x1+-0x21d1+0x2cd4)return undefined;return{'usedTokens':_0x583f7d[_0x1d8161(0x149)],'maxTokens':_0x1969d1};}function claudeContextUsage(_0x128aaa){const _0x566dd5=_0x4c6cb8;if(_0x128aaa[_0x566dd5(0x11e)]!==_0x566dd5(0x17e)||!isRecord(_0x128aaa[_0x566dd5(0x16a)]))return undefined;const _0x3270f6=_0x128aaa[_0x566dd5(0x16a)][_0x566dd5(0x176)],_0x1a06e4=_0x128aaa[_0x566dd5(0x16a)][_0x566dd5(0x119)];if(typeof _0x3270f6!==_0x566dd5(0x127)||_0x3270f6[_0x566dd5(0x1e1)]===-0x15c5*-0x1+0x1433+-0x29f8||_0x3270f6===_0x566dd5(0x1d8)||!isRecord(_0x1a06e4))return undefined;const _0x2ab897=nonNegativeInteger(_0x1a06e4[_0x566dd5(0x149)]),_0x1bb21f=optionalNonNegativeInteger(_0x1a06e4[_0x566dd5(0x120)]),_0x21afc0=optionalNonNegativeInteger(_0x1a06e4[_0x566dd5(0x1ec)]);if(_0x2ab897===undefined||_0x1bb21f===undefined||_0x21afc0===undefined)return undefined;return{'model':_0x3270f6,'usedTokens':_0x2ab897+_0x1bb21f+_0x21afc0};}function optionalNonNegativeInteger(_0x25f55d){return _0x25f55d===undefined?0xf25+-0x16*-0x47+0x31*-0x6f:nonNegativeInteger(_0x25f55d);}function nonNegativeInteger(_0x50df70){const _0x30f24a=_0x4c6cb8;return typeof _0x50df70===_0x30f24a(0x187)&&Number[_0x30f24a(0x1d6)](_0x50df70)&&_0x50df70>=0x2662+-0x23a1*-0x1+-0x4a03?_0x50df70:undefined;}function positiveInteger(_0x4882b7){const _0x459e36=_0x4c6cb8;if(typeof _0x4882b7!==_0x459e36(0x127)||!/^\d+$/[_0x459e36(0x1e2)](_0x4882b7[_0x459e36(0x135)]()))return undefined;const _0x5e64e9=Number(_0x4882b7);return Number[_0x459e36(0x1d6)](_0x5e64e9)&&_0x5e64e9>0x78c+-0x1a05+0x1279?_0x5e64e9:undefined;}function transcriptItems(_0x5952ab,_0x43356c){const _0x53ac06=_0x4c6cb8,_0x2d3bfa=timestampOf(_0x43356c),_0x41dc49=[...toolResultsOf(_0x43356c,_0x2d3bfa),...codexToolResultsOf(_0x43356c,_0x2d3bfa)];if(_0x41dc49[_0x53ac06(0x1e1)]>0x12ab+-0x8*0x2c+-0x114b)return _0x41dc49;const _0x4bf079=[...toolUsesOf(_0x43356c,_0x2d3bfa),...codexToolUsesOf(_0x43356c,_0x2d3bfa),...codexReasoningSummariesOf(_0x43356c,_0x2d3bfa),...unsupportedCodexResponseItems(_0x43356c,_0x2d3bfa),...unsupportedTranscriptItems(_0x43356c,_0x2d3bfa)],_0xafa017=roleOf(_0x43356c);if(_0xafa017===undefined)return _0x4bf079;const _0x1aa5d0=messageText(textOf(_0x43356c)??'');if(_0x1aa5d0[_0x53ac06(0x1e1)]===0xab0+-0xd33*-0x1+-0x5*0x4c7)return _0x4bf079;if(_0xafa017===_0x53ac06(0x14f)&&isInjectedContextPrompt(_0x1aa5d0))return _0x4bf079;const _0x520245=_0xafa017===_0x53ac06(0x14f)&&_0x5952ab===_0x53ac06(0x1ee)?parseCodexComposerImageMarkers(_0x1aa5d0):{'text':_0x1aa5d0,'images':[]};return _0x4bf079[_0x53ac06(0x1eb)]({'kind':_0x53ac06(0x16a),'role':_0xafa017,'text':_0x520245[_0x53ac06(0x1a4)],..._0x520245[_0x53ac06(0x116)][_0x53ac06(0x1e1)]===-0x1*-0x3d4+0x16be+0x26*-0xb3?{}:{'imageAttachments':_0x520245[_0x53ac06(0x116)][_0x53ac06(0x1b5)](_0x2f5a39=>({'name':_0x53ac06(0x1f7)+_0x2f5a39[_0x53ac06(0x1b8)],'mime':imageMime(_0x2f5a39[_0x53ac06(0x1ae)]),'localPath':_0x2f5a39[_0x53ac06(0x1ae)]}))},'createdAt':_0x2d3bfa}),_0x4bf079;}function unsupportedCodexResponseItems(_0xaac99b,_0x12a152){const _0x378b02=_0x4c6cb8,_0x18bd8d=codexToolPayload(_0xaac99b),_0x763216=typeof _0x18bd8d?.[_0x378b02(0x11e)]===_0x378b02(0x127)?_0x18bd8d[_0x378b02(0x11e)]:undefined;if(_0x763216===undefined||typeof _0x18bd8d?.[_0x378b02(0x1dd)]===_0x378b02(0x127)||_0x763216===_0x378b02(0x16f)||_0x763216===_0x378b02(0x139)||_0x763216===_0x378b02(0x14e)||_0x763216===_0x378b02(0x11b)||_0x763216===_0x378b02(0x16b))return[];return[{'kind':_0x378b02(0x140),'sourceEventType':_0x378b02(0x181)+_0x763216,'label':_0x378b02(0x12d)+compact(_0x763216)[_0x378b02(0x1f5)](-0x1ab2+-0x3a*-0x99+-0x7f8,-0x4f3*-0x3+0x7eb+-0x64*0x39),'createdAt':_0x12a152}];}function codexReasoningSummariesOf(_0xc0b887,_0x5d3ad0){const _0x1b1164=_0x4c6cb8,_0x412c28=codexToolPayload(_0xc0b887);if(_0x412c28?.[_0x1b1164(0x11e)]!==_0x1b1164(0x16f))return[];const _0x50f1b7=Array[_0x1b1164(0x1db)](_0x412c28[_0x1b1164(0x193)])?_0x412c28[_0x1b1164(0x193)][_0x1b1164(0x141)]((_0x217a7d,_0x3b8285)=>{const _0x5466b2=_0x1b1164;if(typeof _0x217a7d!==_0x5466b2(0x127))return[];const _0x54ee46=compact(_0x217a7d)[_0x5466b2(0x1f5)](0x81*0x21+-0x2d*0x3+-0x6*0x2af,-0x28*0x6a+-0x2723+0x5ec3);return _0x54ee46[_0x5466b2(0x1e1)]===-0x1*-0x93a+-0x11c7+0x88d?[]:[{'index':_0x3b8285,'text':_0x54ee46}];}):[];return[{'kind':_0x1b1164(0x12c),'sections':_0x50f1b7,'createdAt':_0x5d3ad0}];}function unsupportedTranscriptItems(_0x33ceaf,_0x3742cb){const _0x574bfb=_0x4c6cb8;return contentBlocks(_0x33ceaf)[_0x574bfb(0x141)](_0x3fdf39=>{const _0x465b74=_0x574bfb,_0x48c899=typeof _0x3fdf39[_0x465b74(0x11e)]===_0x465b74(0x127)?_0x3fdf39[_0x465b74(0x11e)]:undefined;if(_0x48c899===undefined||_0x48c899===_0x465b74(0x1a4)||_0x48c899===_0x465b74(0x1bc)||_0x48c899===_0x465b74(0x15b)||_0x48c899===_0x465b74(0x122)||_0x48c899===_0x465b74(0x1e6)||_0x48c899===_0x465b74(0x1f9)||_0x48c899===_0x465b74(0x17a)||_0x48c899===_0x465b74(0x13f)||_0x48c899===_0x465b74(0x1e3)||_0x48c899===_0x465b74(0x1c7))return[];return[{'kind':_0x465b74(0x140),'sourceEventType':_0x465b74(0x185)+_0x48c899,'label':_0x465b74(0x1a3)+compact(_0x48c899)[_0x465b74(0x1f5)](-0x7*0x23b+-0x1*-0xa1+0x1c*0x89,-0x9*0x249+0x4*0x595+-0x143),'createdAt':_0x3742cb}];});}function toolUsesOf(_0x4af7f9,_0x15bdef){const _0x194be9=_0x4c6cb8;return contentBlocks(_0x4af7f9)[_0x194be9(0x141)](_0x74121f=>{const _0x41bb9f=_0x194be9;if(_0x74121f[_0x41bb9f(0x11e)]!==_0x41bb9f(0x1e3)||typeof _0x74121f['id']!==_0x41bb9f(0x127)||typeof _0x74121f[_0x41bb9f(0x159)]!==_0x41bb9f(0x127))return[];const _0x30025d=_0x74121f[_0x41bb9f(0x164)],_0xa764af=compactValue(_0x30025d,-0x1c69+0x504+0x3e75);return[{'kind':_0x41bb9f(0x197),'toolUseId':_0x74121f['id'],'toolName':compact(_0x74121f[_0x41bb9f(0x159)])[_0x41bb9f(0x1f5)](-0x1c5b+0x44*0x2d+0xd*0x143,0x13*-0x143+-0xc9c+0x2515),'input':_0x30025d,'inputSummary':_0xa764af[_0x41bb9f(0x1a4)]||null,'inputTruncated':_0xa764af[_0x41bb9f(0x15c)],'outputSummary':null,'outputTruncated':![],'failed':![],'createdAt':_0x15bdef}];});}function toolResultsOf(_0x21dc30,_0x5ec999){const _0x474ef5=_0x4c6cb8;return contentBlocks(_0x21dc30)[_0x474ef5(0x141)](_0x6e2da8=>{const _0x5d7eb9=_0x474ef5;if(_0x6e2da8[_0x5d7eb9(0x11e)]!==_0x5d7eb9(0x1c7)||typeof _0x6e2da8[_0x5d7eb9(0x18c)]!==_0x5d7eb9(0x127))return[];const _0x111bed=compactValue(_0x6e2da8[_0x5d7eb9(0x17d)],-0x286a+0x5b*0x47+-0x5*-0xad9);return[{'kind':_0x5d7eb9(0x1c7),'toolUseId':_0x6e2da8[_0x5d7eb9(0x18c)],'output':_0x111bed[_0x5d7eb9(0x1a4)],'failed':_0x6e2da8[_0x5d7eb9(0x1d7)]===!![],'truncated':_0x111bed[_0x5d7eb9(0x15c)],'createdAt':_0x5ec999}];});}function codexToolUsesOf(_0xdca994,_0x312989){const _0x3a14b7=_0x4c6cb8,_0x5dc5d3=codexToolPayload(_0xdca994);if(_0x5dc5d3?.[_0x3a14b7(0x11e)]!==_0x3a14b7(0x139)&&_0x5dc5d3?.[_0x3a14b7(0x11e)]!==_0x3a14b7(0x11b))return[];const _0x7689d9=firstString(_0x5dc5d3,[_0x3a14b7(0x1a7),'id']),_0xf80cc4=firstString(_0x5dc5d3,[_0x3a14b7(0x159),_0x3a14b7(0x155)]);if(_0x7689d9===undefined||_0xf80cc4===undefined)return[];const _0x2d33b4=_0x5dc5d3[_0x3a14b7(0x164)]??_0x5dc5d3[_0x3a14b7(0x130)],_0x23f8d9=compactValue(_0x2d33b4,-0xad1*-0x3+-0x3*0xdf3+0x3076);return[{'kind':_0x3a14b7(0x197),'toolUseId':_0x7689d9,'toolName':compact(_0xf80cc4)[_0x3a14b7(0x1f5)](-0x76*0x1+-0x12ae+0x1324,-0x337*0x4+0x165c+-0x80*0x12),'input':_0x2d33b4,'inputSummary':_0x23f8d9[_0x3a14b7(0x1a4)]||null,'inputTruncated':_0x23f8d9[_0x3a14b7(0x15c)],'outputSummary':null,'outputTruncated':![],'failed':![],'createdAt':_0x312989}];}function codexToolResultsOf(_0x52083c,_0x5d626a){const _0x4033ac=_0x4c6cb8,_0x1ec32c=codexToolPayload(_0x52083c);if(_0x1ec32c?.[_0x4033ac(0x11e)]!==_0x4033ac(0x14e)&&_0x1ec32c?.[_0x4033ac(0x11e)]!==_0x4033ac(0x16b))return[];const _0x16f587=firstString(_0x1ec32c,[_0x4033ac(0x1a7),'id']);if(_0x16f587===undefined)return[];const _0x5e11e2=compactValue(codexToolOutput(_0x1ec32c[_0x4033ac(0x1fb)]??_0x1ec32c[_0x4033ac(0x184)]),-0x48a6*0x1+-0x334a+-0x28c0*-0x4),_0x971976=codexImagePlaceholders(_0x1ec32c[_0x4033ac(0x1fb)]??_0x1ec32c[_0x4033ac(0x184)]);return[{'kind':_0x4033ac(0x1c7),'toolUseId':_0x16f587,'output':_0x5e11e2[_0x4033ac(0x1a4)],'failed':_0x1ec32c[_0x4033ac(0x1c2)]===_0x4033ac(0x1c9)||_0x1ec32c[_0x4033ac(0x1e9)]!==undefined,'truncated':_0x5e11e2[_0x4033ac(0x15c)],..._0x971976[_0x4033ac(0x1e1)]===-0x1*0x1e70+0x258d*0x1+-0x3*0x25f?{}:{'imageAttachments':_0x971976},'createdAt':_0x5d626a}];}function codexToolPayload(_0x402561){const _0x541390=_0x4c6cb8;return _0x402561[_0x541390(0x11e)]===_0x541390(0x128)&&isRecord(_0x402561[_0x541390(0x183)])?_0x402561[_0x541390(0x183)]:undefined;}function codexGeneratedImageEvent(_0x211f11){const _0x504da3=_0x4c6cb8;if(_0x211f11[_0x504da3(0x11e)]!==_0x504da3(0x194)||!isRecord(_0x211f11[_0x504da3(0x183)]))return undefined;const _0x6d69c0=_0x211f11[_0x504da3(0x183)];if(_0x6d69c0[_0x504da3(0x11e)]!==_0x504da3(0x154)||typeof _0x6d69c0[_0x504da3(0x1a7)]!==_0x504da3(0x127)||typeof _0x6d69c0[_0x504da3(0x125)]!==_0x504da3(0x127))return undefined;const _0x230cd5=_0x6d69c0[_0x504da3(0x125)];if(!_0x230cd5[_0x504da3(0x126)](_0x504da3(0x1dc))||!/\.(?:png|jpe?g|webp)$/i[_0x504da3(0x1e2)](_0x230cd5))return undefined;return{'kind':_0x504da3(0x197),'toolUseId':_0x6d69c0[_0x504da3(0x1a7)],'toolName':_0x504da3(0x1df),'input':null,'inputSummary':null,'inputTruncated':![],'outputSummary':_0x6d69c0[_0x504da3(0x1c2)]===_0x504da3(0x153)?_0x504da3(0x167):_0x504da3(0x131),'outputTruncated':![],'toolCategory':_0x504da3(0x15a),'imageAttachments':[{'name':basename(_0x230cd5),'mime':imageMime(_0x230cd5),'localPath':_0x230cd5}],'failed':_0x6d69c0[_0x504da3(0x1c2)]!==_0x504da3(0x153),'createdAt':timestampOf(_0x211f11)};}function codexToolOutput(_0x47e33b){const _0x509405=_0x4c6cb8;if(!Array[_0x509405(0x1db)](_0x47e33b))return _0x47e33b;const _0x41b941=_0x47e33b[_0x509405(0x141)](_0x5f2bc1=>{const _0x3b56ea=_0x509405;if(typeof _0x5f2bc1===_0x3b56ea(0x127))return[_0x5f2bc1];if(!isRecord(_0x5f2bc1))return[];const _0x45057e=firstString(_0x5f2bc1,[_0x3b56ea(0x1a4),_0x3b56ea(0x17d)]);return _0x45057e===undefined?[]:[codexVisibleToolText(_0x45057e)];});return _0x41b941[_0x509405(0x1e1)]>0x530+-0xcd6+-0x59*-0x16?_0x41b941[_0x509405(0x1e7)](''):_0x47e33b;}function codexVisibleToolText(_0x1b4115){const _0x165def=_0x4c6cb8,_0x133179=_0x165def(0x143);let _0x4b0e24=-0x25*-0x61+0x3d*-0x3+-0xd4e,_0x1e220d='';while(_0x4b0e24<_0x1b4115[_0x165def(0x1e1)]){const _0x5ac3a2=_0x1b4115[_0x165def(0x11c)](_0x133179,_0x4b0e24);if(_0x5ac3a2<-0x17f3+0xd60*-0x1+0x31*0xc3)return _0x1e220d+_0x1b4115[_0x165def(0x1f5)](_0x4b0e24);_0x1e220d+=_0x1b4115[_0x165def(0x1f5)](_0x4b0e24,_0x5ac3a2)+_0x165def(0x112);const _0x1edbfb=_0x1b4115[_0x165def(0x11c)]('\x22',_0x5ac3a2),_0x21969c=_0x1b4115[_0x165def(0x11c)]('\x27',_0x5ac3a2),_0x1894e3=_0x1edbfb<-0x25e7*-0x1+0x17*-0x163+0x1*-0x602?_0x21969c:_0x21969c<-0x1*0x19a9+-0x2336*-0x1+0x1*-0x98d?_0x1edbfb:Math[_0x165def(0x1c4)](_0x1edbfb,_0x21969c);if(_0x1894e3<0x8ff+0x470+-0x1*0xd6f)return _0x1e220d;_0x4b0e24=_0x1894e3;}return _0x1e220d;}function codexImagePlaceholders(_0x26ff05){const _0x3a8d02=[];let _0x3bf7e4=0x988+-0x4*-0x95e+-0x2f00;const _0x411d05=(_0x52b74e,_0x469972)=>{const _0x1657aa=_0x40d6;if(_0x3a8d02[_0x1657aa(0x1e1)]>=0x19c1+0x49*-0x56+0x2*-0x9b||_0x3bf7e4>=-0x2369+-0xeea+0x32d3||_0x469972>-0x1*0x2073+0xc03+0x1*0x1475||_0x52b74e==null)return;_0x3bf7e4+=-0x4*-0x2d7+-0x2681*0x1+0x1b26;if(typeof _0x52b74e===_0x1657aa(0x127)){const _0x937e80=[];collectGeneratedImagePaths(_0x52b74e,_0x937e80);for(const _0x142645 of _0x937e80){if(_0x3a8d02[_0x1657aa(0x1f8)](_0x5ebc2a=>_0x5ebc2a[_0x1657aa(0x1ae)]===_0x142645))continue;_0x3a8d02[_0x1657aa(0x124)]({'name':basename(_0x142645),'mime':imageMime(_0x142645),'localPath':_0x142645});}return;}if(Array[_0x1657aa(0x1db)](_0x52b74e)){for(const _0x5d4851 of _0x52b74e)_0x411d05(_0x5d4851,_0x469972+(-0xfc2*-0x1+0x1370+0x8f*-0x3f));return;}if(!isRecord(_0x52b74e))return;const _0x57995d=typeof _0x52b74e[_0x1657aa(0x11e)]===_0x1657aa(0x127)?_0x52b74e[_0x1657aa(0x11e)]:'';if(_0x57995d===_0x1657aa(0x1bc)&&typeof _0x52b74e[_0x1657aa(0x1a4)]===_0x1657aa(0x127)){const _0x25c849=/["']image_url["']\s*:\s*["']data:(image\/[^;,"']+)[;,]/[_0x1657aa(0x1c5)](_0x52b74e[_0x1657aa(0x1a4)])?.[0x22f7+0x54c+-0x1*0x2842];if(_0x25c849!==undefined)_0x3a8d02[_0x1657aa(0x124)]({'name':_0x1657aa(0x1f3)+(_0x3a8d02[_0x1657aa(0x1e1)]+(0x123b+0xead*-0x2+0x1*0xb20))+'.'+imageExtension(_0x25c849),'mime':_0x25c849});}const _0x5c766e=isRecord(_0x52b74e[_0x1657aa(0x132)])?firstString(_0x52b74e[_0x1657aa(0x132)],[_0x1657aa(0x1f2)]):typeof _0x52b74e[_0x1657aa(0x132)]===_0x1657aa(0x127)?_0x52b74e[_0x1657aa(0x132)]:undefined,_0x354e45=typeof _0x52b74e[_0x1657aa(0x144)]===_0x1657aa(0x127)?_0x52b74e[_0x1657aa(0x144)]:_0x5c766e;if((_0x57995d===_0x1657aa(0x122)||_0x57995d===_0x1657aa(0x1e6)||_0x57995d===_0x1657aa(0x13b))&&_0x354e45?.[_0x1657aa(0x160)](_0x1657aa(0x143))){const _0x46cca0=/^data:([^;,]+)[;,]/[_0x1657aa(0x1c5)](_0x354e45)?.[-0x40f*0x3+-0x16*-0x5f+0x404]??_0x1657aa(0x123);_0x3a8d02[_0x1657aa(0x124)]({'name':_0x1657aa(0x1f3)+(_0x3a8d02[_0x1657aa(0x1e1)]+(-0x1*0x589+0x15b5+0x1*-0x102b))+'.'+imageExtension(_0x46cca0),'mime':_0x46cca0});}for(const _0x286e8c of Object[_0x1657aa(0x16e)](_0x52b74e))_0x411d05(_0x286e8c,_0x469972+(-0x41b*0x1+0x4c1*-0x1+0x8dd));};return _0x411d05(_0x26ff05,0x1f*0x101+0x88d+-0x13d6*0x2),_0x3a8d02;}function collectGeneratedImagePaths(_0x5ee37e,_0x42ea25){const _0x4114d5=_0x4c6cb8,_0x3582b8=_0x4114d5(0x1dc);let _0x205d69=-0x219f+-0xb*-0x217+0x2*0x551;while(_0x42ea25[_0x4114d5(0x1e1)]<-0x12dc+0x1ccb+-0x9ea){const _0xcdf0f5=_0x5ee37e[_0x4114d5(0x11c)](_0x3582b8,_0x205d69);if(_0xcdf0f5<0xe6+0x1d0b+-0x5fd*0x5)return;let _0x2e0d80=_0xcdf0f5;while(_0x2e0d80>-0x1*0x2519+-0x11*0x1cd+0x43b6&&!/[\s"']/[_0x4114d5(0x1e2)](_0x5ee37e[_0x2e0d80-(0xed5+-0x187f+0x9ab)]))_0x2e0d80-=-0x115e+0x245f*-0x1+0x35be;let _0x306fb8=_0xcdf0f5+_0x3582b8[_0x4114d5(0x1e1)];while(_0x306fb8<_0x5ee37e[_0x4114d5(0x1e1)]&&!/[\s"']/[_0x4114d5(0x1e2)](_0x5ee37e[_0x306fb8]))_0x306fb8+=0x2*0xa78+0xcb4*-0x1+-0x83b;const _0x35d9b3=_0x5ee37e[_0x4114d5(0x1f5)](_0x2e0d80,_0x306fb8)[_0x4114d5(0x190)](/[),.;:]+$/,'');if(/\.(?:png|jpe?g|webp)$/i[_0x4114d5(0x1e2)](_0x35d9b3)&&!_0x42ea25[_0x4114d5(0x126)](_0x35d9b3))_0x42ea25[_0x4114d5(0x124)](_0x35d9b3);_0x205d69=_0x306fb8;}}function imageMime(_0x5b26cb){const _0x12b577=_0x4c6cb8,_0x1e33f2=_0x5b26cb[_0x12b577(0x1f5)](_0x5b26cb[_0x12b577(0x18a)]('.')+(0x1765+-0x4a*0x7a+0xbe0))[_0x12b577(0x182)]();if(_0x1e33f2===_0x12b577(0x150)||_0x1e33f2===_0x12b577(0x118))return _0x12b577(0x1bd);if(_0x1e33f2===_0x12b577(0x179))return _0x12b577(0x1ad);return _0x12b577(0x123);}function imageExtension(_0x46015b){const _0x5c524d=_0x4c6cb8;if(_0x46015b===_0x5c524d(0x1bd))return _0x5c524d(0x150);if(_0x46015b===_0x5c524d(0x1ad))return _0x5c524d(0x179);if(_0x46015b===_0x5c524d(0x195))return _0x5c524d(0x14a);return _0x5c524d(0x166);}function withToolResult(_0x10a3d7,_0x1e8aba){const _0x7a48d=_0x4c6cb8,_0x1ae0a1=codexViewedImagePath(_0x10a3d7),_0x293ea6=_0x1e8aba[_0x7a48d(0x151)]?.[_0x7a48d(0x1b5)](_0x457c69=>_0x457c69[_0x7a48d(0x1ae)]!==undefined||_0x1ae0a1===undefined?_0x457c69:{'name':basename(_0x1ae0a1),'mime':imageMime(_0x1ae0a1),'localPath':_0x1ae0a1});return{..._0x10a3d7,'outputSummary':_0x1e8aba[_0x7a48d(0x1fb)],'outputTruncated':_0x1e8aba[_0x7a48d(0x15c)],..._0x293ea6===undefined?{}:{'imageAttachments':_0x293ea6},'failed':_0x1e8aba[_0x7a48d(0x1c9)]};}function codexViewedImagePath(_0x13589e){const _0x2ed08a=_0x4c6cb8,_0x1f7c08=_0x13589e[_0x2ed08a(0x1de)][_0x2ed08a(0x182)]();if(_0x1f7c08===_0x2ed08a(0x146)||_0x1f7c08===_0x2ed08a(0x1cc))return isRecord(_0x13589e[_0x2ed08a(0x164)])&&typeof _0x13589e[_0x2ed08a(0x164)][_0x2ed08a(0x138)]===_0x2ed08a(0x127)?_0x13589e[_0x2ed08a(0x164)][_0x2ed08a(0x138)]:undefined;if(_0x1f7c08!==_0x2ed08a(0x1c5)||typeof _0x13589e[_0x2ed08a(0x164)]!==_0x2ed08a(0x127))return undefined;if(!/tools\.view_image\s*\(/[_0x2ed08a(0x1e2)](_0x13589e[_0x2ed08a(0x164)]))return undefined;const _0x4a7add=/["']path["']\s*:\s*("(?:\\.|[^"\\])*")/[_0x2ed08a(0x1c5)](_0x13589e[_0x2ed08a(0x164)])?.[0x12ef+0x1d0e+-0x2ffc];if(_0x4a7add===undefined)return undefined;try{const _0xa8bef5=JSON[_0x2ed08a(0x1e5)](_0x4a7add);return typeof _0xa8bef5===_0x2ed08a(0x127)?_0xa8bef5:undefined;}catch{return undefined;}}function isInjectedContextPrompt(_0xf10c3a){const _0x481417=_0x4c6cb8,_0x3cb56f=_0xf10c3a[_0x481417(0x190)](/\s+/g,'\x20')[_0x481417(0x135)]();if(_0x3cb56f[_0x481417(0x160)](_0x481417(0x19b)))return!![];if(/^<(?:environment_context|subagent_notification|turn_aborted)(?:\s|>)/u[_0x481417(0x1e2)](_0x3cb56f))return!![];return _0x3cb56f[_0x481417(0x160)](_0x481417(0x13e))&&(_0x3cb56f[_0x481417(0x126)](_0x481417(0x177))||_0x3cb56f[_0x481417(0x126)](_0x481417(0x16d)));}function isClaudeCompactCommand(_0x23af19){const _0x31006b=_0x4c6cb8;return textOf(_0x23af19)?.[_0x31006b(0x135)]()===_0x31006b(0x1a9);}function isClaudeCompactSuccess(_0x393109){const _0x5b66f2=_0x4c6cb8;return textOf(_0x393109)?.[_0x5b66f2(0x135)]()===_0x5b66f2(0x157);}function isHiddenTranscriptRecord(_0x3ffe1a){const _0x3c68d1=_0x4c6cb8;if(contentBlocks(_0x3ffe1a)[_0x3c68d1(0x1f8)](_0x5063a3=>_0x5063a3[_0x3c68d1(0x11e)]===_0x3c68d1(0x1c7)))return![];if(_0x3ffe1a[_0x3c68d1(0x1bf)]===!![]||_0x3ffe1a[_0x3c68d1(0x1e0)]===!![]||_0x3ffe1a[_0x3c68d1(0x1b7)]===!![]||_0x3ffe1a[_0x3c68d1(0x174)]===!![])return!![];const _0x3a2a06=textOf(_0x3ffe1a)?.[_0x3c68d1(0x135)]()??'';return _0x3a2a06[_0x3c68d1(0x160)](_0x3c68d1(0x1a1))||_0x3a2a06[_0x3c68d1(0x160)](_0x3c68d1(0x189))||_0x3a2a06[_0x3c68d1(0x160)](_0x3c68d1(0x12f));}function roleOf(_0x22aab6){const _0x270ebd=_0x4c6cb8,_0x3f5cbd=[firstString(_0x22aab6,[_0x270ebd(0x1dd)]),nestedString(_0x22aab6,[_0x270ebd(0x16a),_0x270ebd(0x1dd)]),nestedString(_0x22aab6,[_0x270ebd(0x183),_0x270ebd(0x1dd)]),firstString(_0x22aab6,[_0x270ebd(0x11e)]),nestedString(_0x22aab6,[_0x270ebd(0x183),_0x270ebd(0x11e)])];if(_0x3f5cbd[_0x270ebd(0x1f8)](_0x122836=>_0x122836===_0x270ebd(0x13d)||_0x122836===_0x270ebd(0x1a6)||_0x122836===_0x270ebd(0x164)))return _0x270ebd(0x14f);if(_0x3f5cbd[_0x270ebd(0x1f8)](_0x33fc01=>_0x33fc01===_0x270ebd(0x17e)||_0x33fc01===_0x270ebd(0x148)||_0x33fc01===_0x270ebd(0x1fb)))return _0x270ebd(0x196);return undefined;}function textOf(_0x37da10){const _0xa9be4=_0x4c6cb8;return firstString(_0x37da10,[_0xa9be4(0x17d),_0xa9be4(0x1a4)])??nestedText(_0x37da10[_0xa9be4(0x16a)])??nestedText(_0x37da10[_0xa9be4(0x183)]);}function nestedText(_0x19e3fd){const _0x4588ce=_0x4c6cb8;if(typeof _0x19e3fd===_0x4588ce(0x127))return _0x19e3fd;if(!isRecord(_0x19e3fd))return undefined;const _0xae0c4f=firstString(_0x19e3fd,[_0x4588ce(0x17d),_0x4588ce(0x1a4),_0x4588ce(0x16a)]);if(_0xae0c4f!==undefined)return _0xae0c4f;if(Array[_0x4588ce(0x1db)](_0x19e3fd[_0x4588ce(0x17d)])){const _0x3ad8ba=_0x19e3fd[_0x4588ce(0x17d)][_0x4588ce(0x141)](_0x8a66cc=>{const _0x4918ac=_0x4588ce;if(typeof _0x8a66cc===_0x4918ac(0x127))return[_0x8a66cc];if(!isRecord(_0x8a66cc))return[];return[firstString(_0x8a66cc,[_0x4918ac(0x1a4),_0x4918ac(0x17d)])][_0x4918ac(0x1b6)](_0x5cb454=>_0x5cb454!==undefined);});return _0x3ad8ba[_0x4588ce(0x1e7)]('\x0a');}return undefined;}function contentBlocks(_0x1ea0b2){const _0x32aa04=_0x4c6cb8,_0x35af05=[_0x1ea0b2[_0x32aa04(0x16a)],_0x1ea0b2[_0x32aa04(0x183)]];for(const _0x410d7d of _0x35af05)if(isRecord(_0x410d7d)&&Array[_0x32aa04(0x1db)](_0x410d7d[_0x32aa04(0x17d)]))return _0x410d7d[_0x32aa04(0x17d)][_0x32aa04(0x1b6)](isRecord);return[];}function _0x3485(){const _0x65a000=['Aw5WDxrFAw1Hz2u','AM9PBG','yw5JAg9YqNL0zxm','zxjYB3i','Axnoyu4','Dw5ZAgLMDa','y2fJAgvFCMvHzf9PBNb1Df90B2TLBNm','ntqXotaZnxfKB21UvG','y29KzxG','DxvPza','tufyx1nbrKvFsu5uruDfuG','BMv4Da','DxjS','Aw1Hz2uT','zw52AxjVBM1LBNq','C2XPy2u','C3vIywDLBNq','sw1Hz2uGiW','C29Tzq','DgHPBMTPBMC','DgLTzxn0yw1W','B3v0Chv0','y29Sza','ru5pru5u','D2LUmZi','w0LTywDLignVBNrLBNqGzMLSDgvYzwrD','BgfZDf90B2TLBL91C2fNzq','AxntAwrLy2HHAw4','C2vZC2LVBKLK','Aw1Hz2vZ','C2v0','ANbLzW','DxnHz2u','CMvHzeXPBwL0','zNvUy3rPB25Fy2fSBa','Aw5KzxHpzG','C2v0DgLUz3mUANnVBG','DhLWzq','CM91BMq','y2fJAgvFy3jLyxrPB25FAw5WDxrFDg9Rzw5Z','zMLSzxm','Aw1Hz2u','Aw1Hz2uVCg5N','ChvZAa','C2f2zwrFCgf0Aa','Aw5JBhvKzxm','C3rYAw5N','CMvZCg9UC2vFAxrLBq','C2HHmJu2','zw52','AxneAxjLy3rVCNK','CMvHC29UAw5Nx3n1Bw1HCNK','q29KzxGG','CgfYzw50vxvPza','pgnVBw1HBMqTBwvZC2fNzt4','yxjNDw1LBNrZ','sw1Hz2uGz2vUzxjHDgLVBIbMywLSzwq','Aw1Hz2vFDxjS','zw5K','tufsx0nmqvverv9dt05urvHux1DjtKrpv19ut0TftLm','DhjPBq','lMPZB25S','C2vZC2LVBL9Pza','Cgf0Aa','y3vZDg9Tx3rVB2XFy2fSBa','BMf0AxzLlNnLC3nPB24UzgLZy292zxj5lMnVBxbSzxrLza','B3v0Chv0x2LTywDL','ChjVAMvJDhm','DxnLCG','iYbbr0vovfmUBwqGAw5ZDhj1y3rPB25Z','zw5JCNLWDgvKx3rOAw5RAw5N','Dw5RBM93BG','zMXHDe1HCa','CMvMCMvZAa','zgf0ytPPBwfNzs8','zgf0yq','zMLUza','DMLLD19PBwfNzq','y3vYC29YqwnJzxb0zwq','ywDLBNq','Aw5WDxrFDg9Rzw5Z','z2LM','C3vIywDLBNrZ','zgvSzxrL','y3DK','y3vZDg9Tx3rVB2XFy2fSBf9VDxrWDxq','vvnfuG','ANbN','Aw1Hz2vbDhrHy2HTzw50CW','C3rYAw5NAwz5','y29TCgXLDgvK','Aw1Hz2vFz2vUzxjHDgLVBL9LBMq','Dg9VBa','y3jLyxrLzef0','pgXVy2fSlwnVBw1HBMqTC3rKB3v0pKnVBxbHy3rLzdWVBg9JywWTy29TBwfUzc1ZDgrVDxq+','ywrK','BMfTzq','su1br0vFr0vorvjbveLptG','B3v0Chv0x3rLEhq','Dhj1BMnHDgvK','y29UDgv4Df9JB21Wywn0Aw9U','Bwf4','mJq4nJG4nLboyLLjvG','C3rHCNrZv2L0Aa','C2L6zq','D29YA3nWywnLugf0Aa','DgHYzwfKx3nVDxjJzq','Aw5WDxq','C2vZC2LVBNm','Cg5N','sw1Hz2uGz2vUzxjHDgLVBIbJB21WBgv0zwq','C3bSAxq','y3jLyxrLzf9HDa','BwvZC2fNzq','zNvUy3rPB25Fy2fSBf9VDxrWDxq','y29UDMvYC2f0Aw9Uswq','pgvUDMLYB25Tzw50x2nVBNrLEhq+','DMfSDwvZ','CMvHC29UAw5N','C3rHCNq','Agv4','BMf0AxzLlNnLC3nPB24UzgLZy292zxj5lNnPBMDSzs1MBgLNAhqTAM9PBMvK','zMLUywXSEq','AxndB21Wywn0u3vTBwfYEq','mta4ndbvzuf6y1C','Bw9KzwW','peLou1rsvunusu9ouZ4','C2v0DgLUz3nqyxrO','D2vICa','CMvKywn0zwrFDgHPBMTPBMC','DgHLBG','y29Kzq','y29UDgvUDa','yxnZAxn0yw50','AgLZDg9YEq','BMv4DevUza','y29KzxG6','Dg9mB3DLCKnHC2u','Cgf5Bg9Hza','y29UDgvUDeL0zw1Z','DhjHBNnJCMLWDdO','BMf0AxzLlNnLC3nPB24UAgLZDg9YEs5KzxrHAwWTCgfYC2uUy29TCgXLDgvK','BNvTyMvY','zMLUz2vYChjPBNq','pgnVBw1HBMqTBMfTzt4','BgfZDeLUzgv4t2y','A2LUza','Dg9VBf91C2vFAwq','kfvUywjSzsb0BYbKAxnWBgf5kq','D29YA2LUz19KAxjLy3rVCNK','zxHWAxjLC0f0','CMvWBgfJzq','C2vZC2LVBL9TzxrH','Aw5MBW','C3vTBwfYEq','zxzLBNrFBxnN','Aw1Hz2uVz2LM','qvntsvnuqu5u','Dg9VBf9JywXS','BMf0AxzLlNnLC3nPB24UzgLZy292zxj5lNbYB2DYzxnZ','q09nueXfveve','CMvHza','pgnVzgv4x2LUDgvYBMfSx2nVBNrLEhq','CgfYC2vK','BxrPBwvnCW','DgHYzwfKx2LK','Dw5Yzwy','zxH0zxjUywXtzxnZAw9Uswq','pgXVy2fSlwnVBw1HBMqT','DMfSDwu','qwDLBNqG','Dgv4Da','BMf0AxzLlNnLC3nPB24UzgLZy292zxj5lNn0yxj0zwq','AhvTyw4','y2fSBf9Pza','CgXHDgzVCM0','pgnVBw1HBMqTBMfTzt4Vy29TCgfJDdWVy29TBwfUzc1Uyw1LpG','AgfZ','AxngAw5PDgu','y2fJAgviAxrZ','Aw1Hz2uVD2vICa','Bg9JywXqyxrO','CgfNzunVBNrLBNq','B2jQzwn0','ndGXmZaWEhbLufny','ndi3nZeZm3ngDxf2wa','mta2nZaYDLfsy2ji','zgLNzxn0','BwfW','zMLSDgvY','AxnwAxnPyMXLsw5uCMfUC2nYAxb0t25SEq','Aw5KzxG','Bw9KzwXFy29UDgv4Df93Aw5KB3C','BMf0AxzLlNnLC3nPB24UAgLZDg9YEs5ZAw5NBguTzMXPz2H0lwPVAw5Lza','BM93','Aw5WDxrFDgv4Da','Aw1Hz2uVANbLzW','DxrMoa','Aw50zxjYDxb0zwrcEvnODxrKB3DU','A2v5CW','tKfusvzfx1rsqu5tq1jjufrFvu5bvKfjtefcteu','C3rHDhvZ','y2XHDwrLlwnVzgu','BwLU','zxHLyW','Dg9Rzw5Fy291BNq','Dg9VBf9Yzxn1Bhq','C291CMnL','zMfPBgvK','BMf0AxzLlNnLC3nPB24UzgLZy292zxj5lMzPBgvZlwXPC3rLza','oevpzePzBW','Aw1Hz2v2Awv3','AxnjBNrLz2vY','Bgf0zxn0','zMLSzufUy2HVCG','nZu3nJiYnenAu3HOrG','Dg9VBfvZzuLK','DxbKyxrL','C25HChnOB3rfBMq','z2v0','lMnVzgv4','AxntywzLsw50zwDLCG','AxnFzxjYB3i','phn5BNrOzxrPyZ4','lMnSyxvKzq','mta2mNveyvH1vW','AxnbCNjHEq','lY5JB2rLEc9Nzw5LCMf0zwrFAw1Hz2vZlW','CM9Szq','Dg9VBe5HBwu','Aw1Hz2vNzw4','AxnnzxrH','BgvUz3rO','DgvZDa','Dg9VBf91C2u','Dg9mB2nHBgvmB3DLCKnHC2u','CgfYC2u'];_0x3485=function(){return _0x65a000;};return _0x3485();}function compactValue(_0x462c84,_0x4fd10d){const _0x4c0f91=_0x4c6cb8;if(_0x462c84===undefined||_0x462c84===null)return{'text':'','truncated':![]};let _0xcc2835;if(typeof _0x462c84===_0x4c0f91(0x127))_0xcc2835=_0x462c84;else try{_0xcc2835=JSON[_0x4c0f91(0x152)](_0x462c84);}catch{return{'text':_0x4c0f91(0x18d),'truncated':![]};}return{'text':_0xcc2835[_0x4c0f91(0x1e1)]<=_0x4fd10d?_0xcc2835:_0xcc2835[_0x4c0f91(0x1f5)](-0x128e+0x26a4+-0x1416,Math[_0x4c0f91(0x15e)](-0x1*0x157f+-0x37*-0x2c+-0xc0b*-0x1,_0x4fd10d-(-0x2dd*0x4+0x2360+-0x3*0x7f9)))+'…','truncated':_0xcc2835[_0x4c0f91(0x1e1)]>_0x4fd10d};}function timestampOf(_0x54a713){const _0xa434b5=_0x4c6cb8,_0x687ab8=_0x54a713[_0xa434b5(0x1fa)]??_0x54a713[_0xa434b5(0x169)]??_0x54a713[_0xa434b5(0x156)];if(typeof _0x687ab8===_0xa434b5(0x187)&&Number[_0xa434b5(0x1ab)](_0x687ab8))return _0x687ab8<-0x67767d*-0x542+-0x1dd655624+-0x3afb59*-0x8fa?_0x687ab8*(-0xc1*-0x28+0x1*-0x4ee+-0x1552):_0x687ab8;if(typeof _0x687ab8===_0xa434b5(0x127)){const _0x40df5e=Date[_0xa434b5(0x1e5)](_0x687ab8);return Number[_0xa434b5(0x1ea)](_0x40df5e)?null:_0x40df5e;}return null;}function firstString(_0x23480f,_0x578d76){const _0x4e61c6=_0x4c6cb8;for(const _0x3fc157 of _0x578d76)if(typeof _0x23480f[_0x3fc157]===_0x4e61c6(0x127)&&_0x23480f[_0x3fc157][_0x4e61c6(0x1e1)]>-0x21*-0xa4+-0x9e0+-0xb44)return _0x23480f[_0x3fc157];return undefined;}function nestedString(_0xdc4f75,_0x3b157b){const _0x4aa2ec=_0x4c6cb8;let _0x51d8a7=_0xdc4f75;for(const _0x37915d of _0x3b157b){if(!isRecord(_0x51d8a7))return undefined;_0x51d8a7=_0x51d8a7[_0x37915d];}return typeof _0x51d8a7===_0x4aa2ec(0x127)&&_0x51d8a7[_0x4aa2ec(0x1e1)]>0x1123*-0x1+0x2*-0xaaf+0x1*0x2681?_0x51d8a7:undefined;}function compact(_0x4912cd){const _0x314a50=_0x4c6cb8;return _0x4912cd[_0x314a50(0x190)](/\s+/g,'\x20')[_0x314a50(0x135)]()[_0x314a50(0x1f5)](0x3*-0xc7+0x1188+-0xf33,-0x57e6+0x6e4b+0x281b);}function messageText(_0x302085){const _0x4f7bd4=_0x4c6cb8;return _0x302085[_0x4f7bd4(0x135)]()[_0x4f7bd4(0x1f5)](-0x2cc+0x7a3+0x3*-0x19d,-0x1250+-0x20c*-0x1d+-0x1*-0x1574);}function canonical(_0x1c602a){const _0x5cfc8f=_0x4c6cb8;try{const _0x169075=resolve(_0x1c602a)[_0x5cfc8f(0x190)](/[\\/]+$/,'');return process[_0x5cfc8f(0x1a8)]===_0x5cfc8f(0x111)?_0x169075[_0x5cfc8f(0x1e4)]():_0x169075;}catch{return _0x1c602a;}}function indexKey(_0x47b1c4,_0x3d9c90,_0x25c690){return _0x47b1c4+'\x00'+_0x3d9c90+'\x00'+_0x25c690;}function setTranscriptIndex(_0x3f7f5d,_0x247488){const _0x271d18=_0x4c6cb8,_0x263e80=transcriptIndexTimers[_0x271d18(0x1d4)](_0x3f7f5d);if(_0x263e80!==undefined)clearTimeout(_0x263e80);transcriptIndex[_0x271d18(0x117)](_0x3f7f5d,_0x247488);const _0x34b10e=setTimeout(()=>deleteTranscriptIndex(_0x3f7f5d),TRANSCRIPT_INDEX_TTL_MS);_0x34b10e[_0x271d18(0x19f)](),transcriptIndexTimers[_0x271d18(0x117)](_0x3f7f5d,_0x34b10e);}function getTranscriptIndex(_0xf64cfb){const _0x203798=_0x4c6cb8;return transcriptIndex[_0x203798(0x1d4)](_0xf64cfb);}function deleteTranscriptIndex(_0x1eb77a){const _0xf1110e=_0x4c6cb8,_0x4862a2=transcriptIndexTimers[_0xf1110e(0x1d4)](_0x1eb77a);if(_0x4862a2!==undefined)clearTimeout(_0x4862a2);transcriptIndexTimers[_0xf1110e(0x14c)](_0x1eb77a),transcriptIndex[_0xf1110e(0x14c)](_0x1eb77a);}function isRecord(_0x1ccbc6){const _0xcafab9=_0x4c6cb8;return typeof _0x1ccbc6===_0xcafab9(0x1b0)&&_0x1ccbc6!==null&&!Array[_0xcafab9(0x1db)](_0x1ccbc6);}
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir, stat, unlink } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, join, resolve } from 'node:path';
|
|
5
|
+
import { forEachJsonlRecord, listJsonlFiles, mapConcurrent, readJsonlBackwardWindow, readJsonlFileAnchor, readJsonlWindow } from './native-jsonl-reader.js';
|
|
6
|
+
import { nodeLog } from './operational.js';
|
|
7
|
+
import { stripClaudePlanTag } from './runner-command-engine.js';
|
|
8
|
+
import { stripMissionStartPrompt } from './service/mission-runtime.js';
|
|
9
|
+
import { parseCodexComposerImageMarkers } from './runner/codex/composer-image-markers.js';
|
|
10
|
+
const DISCOVERY_READ_BYTES = 32 * 1024;
|
|
11
|
+
const TRANSCRIPT_HEADER_READ_BYTES = 32 * 1024;
|
|
12
|
+
const TRANSCRIPT_READ_MAX_BYTES = 16 * 1024 * 1024;
|
|
13
|
+
const TRANSCRIPT_MIN_LINES = 256;
|
|
14
|
+
const TRANSCRIPT_MAX_LINES = 4096;
|
|
15
|
+
const TRANSCRIPT_LINES_PER_TURN = 32;
|
|
16
|
+
const CONTEXT_USAGE_READ_BYTES = 256 * 1024;
|
|
17
|
+
const CLAUDE_CONTEXT_USAGE_READ_BYTES = [CONTEXT_USAGE_READ_BYTES, 1024 * 1024, 4 * 1024 * 1024];
|
|
18
|
+
const TRANSCRIPT_INDEX_TTL_MS = 60 * 60_000;
|
|
19
|
+
const DISCOVERY_SNAPSHOT_TTL_MS = 15_000;
|
|
20
|
+
const TRANSCRIPT_DETAIL_CACHE_TTL_MS = 60_000;
|
|
21
|
+
const TRANSCRIPT_DETAIL_CACHE_MAX_ENTRIES = 16;
|
|
22
|
+
const transcriptIndex = new Map();
|
|
23
|
+
const transcriptIndexTimers = new Map();
|
|
24
|
+
const transcriptDetailCache = new Map();
|
|
25
|
+
const transcriptDetailReads = new Map();
|
|
26
|
+
const discoveryReads = new Map();
|
|
27
|
+
const discoverySnapshots = new Map();
|
|
28
|
+
const discoveryGenerations = new Map();
|
|
29
|
+
const DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS = 200_000;
|
|
30
|
+
const CLAUDE_CONTEXT_WINDOW_ENV = 'MAR_CLAUDE_CONTEXT_WINDOW_TOKENS';
|
|
31
|
+
/**
|
|
32
|
+
* Read-only adapter for the supported vendor JSONL stores. It requires an
|
|
33
|
+
* explicit cwd on the record and returns normalized visible messages and tool
|
|
34
|
+
* cards; no raw vendor events or hidden reasoning are exposed to the Workbench.
|
|
35
|
+
*/
|
|
36
|
+
export async function discoverNativeSessions(runner, workspacePath) {
|
|
37
|
+
const wanted = canonical(workspacePath);
|
|
38
|
+
return (await discoverAllNativeSessions(runner)).filter((value) => canonical(value.cwd) === wanted);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reads every supported transcript header before applying a Workspace filter.
|
|
42
|
+
* A short Runner-level snapshot is shared across Workspaces and refreshes only
|
|
43
|
+
* files whose size or modification time changed. A fixed file-count cutoff
|
|
44
|
+
* would silently hide older sessions from a project with a large global history.
|
|
45
|
+
*/
|
|
46
|
+
export async function discoverAllNativeSessions(runner) {
|
|
47
|
+
const key = discoveryKey(runner);
|
|
48
|
+
const snapshot = discoverySnapshots.get(key);
|
|
49
|
+
if (snapshot !== undefined && snapshot.expiresAt > Date.now()) {
|
|
50
|
+
snapshot.cacheHits += 1;
|
|
51
|
+
return snapshot.sessions;
|
|
52
|
+
}
|
|
53
|
+
const current = discoveryReads.get(key);
|
|
54
|
+
if (current !== undefined) {
|
|
55
|
+
nodeLog('native.session.discovery.single-flight-joined', { runner });
|
|
56
|
+
return current;
|
|
57
|
+
}
|
|
58
|
+
const generation = discoveryGenerations.get(key) ?? 0;
|
|
59
|
+
const discovery = performNativeSessionDiscovery(runner, snapshot)
|
|
60
|
+
.then((next) => {
|
|
61
|
+
if ((discoveryGenerations.get(key) ?? 0) === generation)
|
|
62
|
+
discoverySnapshots.set(key, next);
|
|
63
|
+
return next.sessions;
|
|
64
|
+
})
|
|
65
|
+
.finally(() => {
|
|
66
|
+
if (discoveryReads.get(key) === discovery)
|
|
67
|
+
discoveryReads.delete(key);
|
|
68
|
+
});
|
|
69
|
+
discoveryReads.set(key, discovery);
|
|
70
|
+
return discovery;
|
|
71
|
+
}
|
|
72
|
+
async function performNativeSessionDiscovery(runner, previous) {
|
|
73
|
+
const startedAt = performance.now();
|
|
74
|
+
const found = new Map();
|
|
75
|
+
nodeLog('native.session.discovery.started', { runner });
|
|
76
|
+
const files = (await listJsonlFiles(transcriptRoot(runner))).filter((path) => runner !== 'claude-code' || !path.split(/[\\/]/u).includes('subagents'));
|
|
77
|
+
nodeLog('native.session.discovery.files-listed', {
|
|
78
|
+
runner,
|
|
79
|
+
files: files.length,
|
|
80
|
+
durationMs: Math.round(performance.now() - startedAt)
|
|
81
|
+
});
|
|
82
|
+
let completed = 0;
|
|
83
|
+
let parsedCount = 0;
|
|
84
|
+
let reusedCount = 0;
|
|
85
|
+
let metadataFailures = 0;
|
|
86
|
+
let metadataWorkMs = 0;
|
|
87
|
+
let parseWorkMs = 0;
|
|
88
|
+
const discoveredFiles = await mapConcurrent(files, 32, async (path) => {
|
|
89
|
+
let fingerprint;
|
|
90
|
+
const metadataStartedAt = performance.now();
|
|
91
|
+
try {
|
|
92
|
+
const metadata = await stat(path);
|
|
93
|
+
fingerprint = `${metadata.size}:${metadata.mtimeMs}`;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
metadataFailures += 1;
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
metadataWorkMs += performance.now() - metadataStartedAt;
|
|
101
|
+
}
|
|
102
|
+
const cached = previous?.files.get(path);
|
|
103
|
+
let parsed;
|
|
104
|
+
if (cached?.fingerprint === fingerprint) {
|
|
105
|
+
parsed = cached.parsed;
|
|
106
|
+
reusedCount += 1;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const parseStartedAt = performance.now();
|
|
110
|
+
parsed = await readTranscript(path, runner, DISCOVERY_READ_BYTES);
|
|
111
|
+
parseWorkMs += performance.now() - parseStartedAt;
|
|
112
|
+
parsedCount += 1;
|
|
113
|
+
}
|
|
114
|
+
completed += 1;
|
|
115
|
+
if (completed % 250 === 0)
|
|
116
|
+
nodeLog('native.session.discovery.progress', {
|
|
117
|
+
runner,
|
|
118
|
+
completed,
|
|
119
|
+
files: files.length,
|
|
120
|
+
parsedFiles: parsedCount,
|
|
121
|
+
reusedFiles: reusedCount,
|
|
122
|
+
metadataFailures,
|
|
123
|
+
metadataWorkMs: Math.round(metadataWorkMs),
|
|
124
|
+
parseWorkMs: Math.round(parseWorkMs),
|
|
125
|
+
durationMs: Math.round(performance.now() - startedAt)
|
|
126
|
+
});
|
|
127
|
+
return { path, fingerprint, parsed };
|
|
128
|
+
});
|
|
129
|
+
const snapshotFiles = new Map();
|
|
130
|
+
for (const file of discoveredFiles) {
|
|
131
|
+
if (file === undefined)
|
|
132
|
+
continue;
|
|
133
|
+
snapshotFiles.set(file.path, { fingerprint: file.fingerprint, parsed: file.parsed });
|
|
134
|
+
const parsed = file.parsed;
|
|
135
|
+
// Discovery only needs a session identity, cwd and an optional early
|
|
136
|
+
// title. Loading entire JSONL files here made opening a Workspace depend
|
|
137
|
+
// on the total history of every other project on the Node.
|
|
138
|
+
if (parsed === undefined)
|
|
139
|
+
continue;
|
|
140
|
+
const cwd = canonical(parsed.cwd);
|
|
141
|
+
setTranscriptIndex(indexKey(runner, cwd, parsed.externalSessionId), file.path);
|
|
142
|
+
found.set(`${cwd}\u0000${parsed.externalSessionId}`, parsed);
|
|
143
|
+
}
|
|
144
|
+
nodeLog('native.session.discovery.completed', {
|
|
145
|
+
runner,
|
|
146
|
+
files: files.length,
|
|
147
|
+
sessions: found.size,
|
|
148
|
+
parsedFiles: parsedCount,
|
|
149
|
+
reusedFiles: reusedCount,
|
|
150
|
+
unparsedFiles: [...snapshotFiles.values()].filter((file) => file.parsed === undefined).length,
|
|
151
|
+
metadataFailures,
|
|
152
|
+
metadataWorkMs: Math.round(metadataWorkMs),
|
|
153
|
+
parseWorkMs: Math.round(parseWorkMs),
|
|
154
|
+
cacheMode: previous === undefined ? 'cold' : 'refresh',
|
|
155
|
+
previousCacheHits: previous?.cacheHits ?? 0,
|
|
156
|
+
durationMs: Math.round(performance.now() - startedAt)
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
expiresAt: Date.now() + DISCOVERY_SNAPSHOT_TTL_MS,
|
|
160
|
+
files: snapshotFiles,
|
|
161
|
+
sessions: [...found.values()],
|
|
162
|
+
cacheHits: 0
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Reads one already-discovered external session again to follow appended JSONL records. */
|
|
166
|
+
export async function readNativeSession(runner, workspacePath, externalSessionId, page, limit = 30) {
|
|
167
|
+
const wanted = canonical(workspacePath);
|
|
168
|
+
const path = getTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
169
|
+
if (path === undefined)
|
|
170
|
+
return undefined;
|
|
171
|
+
const detail = await readTranscriptDetail(path, runner, page, page?.readLimit ?? limit);
|
|
172
|
+
const parsed = detail?.history;
|
|
173
|
+
if (parsed === undefined ||
|
|
174
|
+
parsed.externalSessionId !== externalSessionId ||
|
|
175
|
+
canonical(parsed.cwd) !== wanted) {
|
|
176
|
+
deleteTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
return detail?.cursorAccepted === false ? { ...parsed, cursorReset: true } : parsed;
|
|
180
|
+
}
|
|
181
|
+
async function readTranscriptDetail(path, runner, page, limit) {
|
|
182
|
+
let fingerprint;
|
|
183
|
+
try {
|
|
184
|
+
const metadata = await stat(path);
|
|
185
|
+
fingerprint = `${metadata.size}:${metadata.mtimeMs}`;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
const metadataSize = Number(fingerprint.slice(0, fingerprint.indexOf(':')));
|
|
191
|
+
const validPage = page !== undefined &&
|
|
192
|
+
page.snapshotEnd <= metadataSize &&
|
|
193
|
+
(await readJsonlFileAnchor(path, page.anchorBytes)) === page.fileAnchor
|
|
194
|
+
? page
|
|
195
|
+
: undefined;
|
|
196
|
+
const targetLines = Math.min(TRANSCRIPT_MAX_LINES, Math.max(TRANSCRIPT_MIN_LINES, Math.max(1, limit) * TRANSCRIPT_LINES_PER_TURN));
|
|
197
|
+
const pageKey = `${validPage === undefined
|
|
198
|
+
? 'latest'
|
|
199
|
+
: `${validPage.fileAnchor}:${validPage.snapshotEnd}:${validPage.nextEnd}`}:${targetLines}`;
|
|
200
|
+
const key = `${runner}\u0000${path}\u0000${pageKey}`;
|
|
201
|
+
const cacheFingerprint = validPage === undefined ? fingerprint : `${validPage.fileAnchor}:${validPage.snapshotEnd}`;
|
|
202
|
+
const cached = transcriptDetailCache.get(key);
|
|
203
|
+
if (cached?.fingerprint === cacheFingerprint && cached.expiresAt > Date.now()) {
|
|
204
|
+
cached.expiresAt = Date.now() + TRANSCRIPT_DETAIL_CACHE_TTL_MS;
|
|
205
|
+
transcriptDetailCache.delete(key);
|
|
206
|
+
transcriptDetailCache.set(key, cached);
|
|
207
|
+
return {
|
|
208
|
+
history: cached.parsed,
|
|
209
|
+
cursorAccepted: page === undefined || validPage !== undefined
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
transcriptDetailCache.delete(key);
|
|
213
|
+
const current = transcriptDetailReads.get(key);
|
|
214
|
+
if (current?.fingerprint === cacheFingerprint) {
|
|
215
|
+
nodeLog('native.session.history.single-flight-joined', { runner });
|
|
216
|
+
return {
|
|
217
|
+
history: await current.read,
|
|
218
|
+
cursorAccepted: page === undefined || validPage !== undefined
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const startedAt = performance.now();
|
|
222
|
+
const read = readTranscript(path, runner, TRANSCRIPT_READ_MAX_BYTES, validPage, targetLines)
|
|
223
|
+
.then((parsed) => parsed === undefined ? undefined : { ...parsed, windowReadLimit: page?.readLimit ?? limit })
|
|
224
|
+
.then((parsed) => {
|
|
225
|
+
if (transcriptDetailReads.get(key)?.read === read) {
|
|
226
|
+
transcriptDetailCache.set(key, {
|
|
227
|
+
fingerprint: cacheFingerprint,
|
|
228
|
+
parsed,
|
|
229
|
+
expiresAt: Date.now() + TRANSCRIPT_DETAIL_CACHE_TTL_MS
|
|
230
|
+
});
|
|
231
|
+
pruneTranscriptDetailCache();
|
|
232
|
+
}
|
|
233
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
234
|
+
if (durationMs >= 250)
|
|
235
|
+
nodeLog('native.session.history.detail-parse.completed', {
|
|
236
|
+
runner,
|
|
237
|
+
bytes: Number(fingerprint.slice(0, fingerprint.indexOf(':'))),
|
|
238
|
+
durationMs
|
|
239
|
+
});
|
|
240
|
+
return parsed;
|
|
241
|
+
})
|
|
242
|
+
.finally(() => {
|
|
243
|
+
if (transcriptDetailReads.get(key)?.read === read)
|
|
244
|
+
transcriptDetailReads.delete(key);
|
|
245
|
+
});
|
|
246
|
+
transcriptDetailReads.set(key, { fingerprint: cacheFingerprint, read });
|
|
247
|
+
return { history: await read, cursorAccepted: page === undefined || validPage !== undefined };
|
|
248
|
+
}
|
|
249
|
+
function pruneTranscriptDetailCache() {
|
|
250
|
+
const now = Date.now();
|
|
251
|
+
for (const [key, cached] of transcriptDetailCache)
|
|
252
|
+
if (cached.expiresAt <= now)
|
|
253
|
+
transcriptDetailCache.delete(key);
|
|
254
|
+
while (transcriptDetailCache.size > TRANSCRIPT_DETAIL_CACHE_MAX_ENTRIES) {
|
|
255
|
+
const oldest = transcriptDetailCache.keys().next().value;
|
|
256
|
+
if (oldest === undefined)
|
|
257
|
+
return;
|
|
258
|
+
transcriptDetailCache.delete(oldest);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Codex records the most recent prompt token count alongside the model context
|
|
263
|
+
* window in `event_msg/token_count`. Read only the tail of an already
|
|
264
|
+
* discovered transcript: the count is append-only and never needs a costly
|
|
265
|
+
* full-history scan.
|
|
266
|
+
*/
|
|
267
|
+
export async function readCodexNativeContextUsage(workspacePath, externalSessionId) {
|
|
268
|
+
const wanted = canonical(workspacePath);
|
|
269
|
+
let path = getTranscriptIndex(indexKey('codex', wanted, externalSessionId));
|
|
270
|
+
if (path === undefined) {
|
|
271
|
+
await discoverNativeSessions('codex', workspacePath);
|
|
272
|
+
path = getTranscriptIndex(indexKey('codex', wanted, externalSessionId));
|
|
273
|
+
}
|
|
274
|
+
if (path === undefined)
|
|
275
|
+
return undefined;
|
|
276
|
+
const window = await readJsonlWindow(path, { tailBytes: CONTEXT_USAGE_READ_BYTES });
|
|
277
|
+
if (window === undefined)
|
|
278
|
+
return undefined;
|
|
279
|
+
let usage;
|
|
280
|
+
forEachJsonlRecord(window.content, (record) => {
|
|
281
|
+
const next = codexContextUsage(record);
|
|
282
|
+
if (next !== undefined)
|
|
283
|
+
usage = next;
|
|
284
|
+
});
|
|
285
|
+
return usage;
|
|
286
|
+
}
|
|
287
|
+
/** Reads the latest actual Claude prompt occupancy without starting a CLI/SDK control stream. */
|
|
288
|
+
export async function readClaudeNativeContextUsage(workspacePath, externalSessionId, options = {}) {
|
|
289
|
+
const wanted = canonical(workspacePath);
|
|
290
|
+
let path = getTranscriptIndex(indexKey('claude-code', wanted, externalSessionId));
|
|
291
|
+
path ??= await locateClaudeTranscript(wanted, externalSessionId);
|
|
292
|
+
if (path === undefined) {
|
|
293
|
+
await discoverNativeSessions('claude-code', workspacePath);
|
|
294
|
+
path = getTranscriptIndex(indexKey('claude-code', wanted, externalSessionId));
|
|
295
|
+
}
|
|
296
|
+
if (path === undefined)
|
|
297
|
+
return undefined;
|
|
298
|
+
const latest = await readLatestClaudeContextUsage(path);
|
|
299
|
+
if (latest === undefined)
|
|
300
|
+
return undefined;
|
|
301
|
+
return {
|
|
302
|
+
...latest,
|
|
303
|
+
maxTokens: await claudeContextWindowTokens(options)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async function readLatestClaudeContextUsage(path) {
|
|
307
|
+
for (const tailBytes of CLAUDE_CONTEXT_USAGE_READ_BYTES) {
|
|
308
|
+
const window = await readJsonlWindow(path, { tailBytes });
|
|
309
|
+
if (window === undefined)
|
|
310
|
+
return undefined;
|
|
311
|
+
let latest;
|
|
312
|
+
forEachJsonlRecord(window.content, (record) => {
|
|
313
|
+
const usage = claudeContextUsage(record);
|
|
314
|
+
if (usage !== undefined)
|
|
315
|
+
latest = usage;
|
|
316
|
+
});
|
|
317
|
+
if (latest !== undefined)
|
|
318
|
+
return latest;
|
|
319
|
+
if (!window.truncated)
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
/** Claude main transcripts use the native session ID as their filename. */
|
|
325
|
+
async function locateClaudeTranscript(wantedCwd, externalSessionId) {
|
|
326
|
+
const root = transcriptRoot('claude-code');
|
|
327
|
+
let entries;
|
|
328
|
+
try {
|
|
329
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
const candidates = entries
|
|
335
|
+
.filter((entry) => entry.isDirectory())
|
|
336
|
+
.map((entry) => join(root, entry.name, `${externalSessionId}.jsonl`));
|
|
337
|
+
const parsed = await mapConcurrent(candidates, 16, async (path) => ({
|
|
338
|
+
path,
|
|
339
|
+
history: await readTranscript(path, 'claude-code', DISCOVERY_READ_BYTES)
|
|
340
|
+
}));
|
|
341
|
+
const match = parsed.find(({ history }) => history?.externalSessionId === externalSessionId && canonical(history.cwd) === wantedCwd);
|
|
342
|
+
if (match === undefined)
|
|
343
|
+
return undefined;
|
|
344
|
+
setTranscriptIndex(indexKey('claude-code', wantedCwd, externalSessionId), match.path);
|
|
345
|
+
return match.path;
|
|
346
|
+
}
|
|
347
|
+
export async function claudeContextWindowTokens(options = {}) {
|
|
348
|
+
const environment = options.environment ?? process.env;
|
|
349
|
+
const direct = positiveInteger(environment[CLAUDE_CONTEXT_WINDOW_ENV]);
|
|
350
|
+
if (direct !== undefined)
|
|
351
|
+
return direct;
|
|
352
|
+
try {
|
|
353
|
+
const settings = JSON.parse(await readFile(options.settingsPath ?? join(homedir(), '.claude', 'settings.json'), 'utf8'));
|
|
354
|
+
if (isRecord(settings) && isRecord(settings.env)) {
|
|
355
|
+
const configured = positiveInteger(settings.env[CLAUDE_CONTEXT_WINDOW_ENV]);
|
|
356
|
+
if (configured !== undefined)
|
|
357
|
+
return configured;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
// Missing or malformed optional Claude settings use the stable default.
|
|
362
|
+
}
|
|
363
|
+
return DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Permanently removes exactly one previously discovered transcript. The
|
|
367
|
+
* caller supplies no path: the in-process discovery index resolves it, then
|
|
368
|
+
* the record is re-read and its runner/cwd/native ID are checked again before
|
|
369
|
+
* unlinking. This keeps a destructive operation bounded to one known file.
|
|
370
|
+
*/
|
|
371
|
+
export async function removeNativeSession(runner, workspacePath, externalSessionId) {
|
|
372
|
+
const wanted = canonical(workspacePath);
|
|
373
|
+
let path = getTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
374
|
+
if (path === undefined) {
|
|
375
|
+
await discoverNativeSessions(runner, workspacePath);
|
|
376
|
+
path = getTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
377
|
+
}
|
|
378
|
+
if (path === undefined)
|
|
379
|
+
throw new Error('NATIVE_TRANSCRIPT_UNAVAILABLE');
|
|
380
|
+
const parsed = await readTranscript(path, runner, DISCOVERY_READ_BYTES);
|
|
381
|
+
if (parsed === undefined ||
|
|
382
|
+
parsed.externalSessionId !== externalSessionId ||
|
|
383
|
+
canonical(parsed.cwd) !== wanted) {
|
|
384
|
+
deleteTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
385
|
+
throw new Error('NATIVE_TRANSCRIPT_UNAVAILABLE');
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
await unlink(path);
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
if (error.code === 'ENOENT')
|
|
392
|
+
throw new Error('NATIVE_TRANSCRIPT_UNAVAILABLE');
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
deleteTranscriptIndex(indexKey(runner, wanted, externalSessionId));
|
|
396
|
+
const detailKeyPrefix = `${runner}\u0000${path}\u0000`;
|
|
397
|
+
for (const key of transcriptDetailCache.keys())
|
|
398
|
+
if (key.startsWith(detailKeyPrefix))
|
|
399
|
+
transcriptDetailCache.delete(key);
|
|
400
|
+
for (const key of transcriptDetailReads.keys())
|
|
401
|
+
if (key.startsWith(detailKeyPrefix))
|
|
402
|
+
transcriptDetailReads.delete(key);
|
|
403
|
+
invalidateNativeDiscovery(runner);
|
|
404
|
+
}
|
|
405
|
+
function transcriptRoot(runner) {
|
|
406
|
+
return runner === 'codex'
|
|
407
|
+
? join(homedir(), '.codex', 'sessions')
|
|
408
|
+
: join(homedir(), '.claude', 'projects');
|
|
409
|
+
}
|
|
410
|
+
function discoveryKey(runner) {
|
|
411
|
+
return `${runner}\u0000${transcriptRoot(runner)}`;
|
|
412
|
+
}
|
|
413
|
+
function invalidateNativeDiscovery(runner) {
|
|
414
|
+
const key = discoveryKey(runner);
|
|
415
|
+
discoveryGenerations.set(key, (discoveryGenerations.get(key) ?? 0) + 1);
|
|
416
|
+
discoverySnapshots.delete(key);
|
|
417
|
+
discoveryReads.delete(key);
|
|
418
|
+
}
|
|
419
|
+
async function readTranscript(path, runner, byteLimit, page, targetLines = Number.MAX_SAFE_INTEGER) {
|
|
420
|
+
const window = await readJsonlBackwardWindow(path, {
|
|
421
|
+
headBytes: Math.min(byteLimit, TRANSCRIPT_HEADER_READ_BYTES),
|
|
422
|
+
targetLines,
|
|
423
|
+
maxBytes: byteLimit,
|
|
424
|
+
...(page === undefined ? {} : { page })
|
|
425
|
+
});
|
|
426
|
+
if (window === undefined)
|
|
427
|
+
return undefined;
|
|
428
|
+
const { content, truncated } = window;
|
|
429
|
+
let cwd;
|
|
430
|
+
let id;
|
|
431
|
+
let derivedSession = false;
|
|
432
|
+
const items = [];
|
|
433
|
+
const toolIndexes = new Map();
|
|
434
|
+
const metaRecordIds = new Set();
|
|
435
|
+
const claudeCompactCommandIds = new Set();
|
|
436
|
+
forEachJsonlRecord(content, (value) => {
|
|
437
|
+
if (derivedTranscriptRecord(runner, value))
|
|
438
|
+
derivedSession = true;
|
|
439
|
+
cwd ??= workspacePath(value);
|
|
440
|
+
id ??= sessionId(value);
|
|
441
|
+
if (runner === 'claude-code' &&
|
|
442
|
+
typeof value['uuid'] === 'string' &&
|
|
443
|
+
isClaudeCompactCommand(value))
|
|
444
|
+
claudeCompactCommandIds.add(value['uuid']);
|
|
445
|
+
});
|
|
446
|
+
forEachJsonlRecord(truncated ? window.pageContent : content, (value) => {
|
|
447
|
+
const recordId = typeof value['uuid'] === 'string' ? value['uuid'] : undefined;
|
|
448
|
+
const parentId = typeof value['parentUuid'] === 'string' ? value['parentUuid'] : undefined;
|
|
449
|
+
if (value['isMeta'] === true && recordId !== undefined)
|
|
450
|
+
metaRecordIds.add(recordId);
|
|
451
|
+
if (runner === 'claude-code' &&
|
|
452
|
+
parentId !== undefined &&
|
|
453
|
+
claudeCompactCommandIds.has(parentId) &&
|
|
454
|
+
isClaudeCompactSuccess(value)) {
|
|
455
|
+
items.push({
|
|
456
|
+
kind: 'context_compaction',
|
|
457
|
+
phase: 'COMPLETED',
|
|
458
|
+
summary: null,
|
|
459
|
+
createdAt: timestampOf(value),
|
|
460
|
+
nativeId: parentId
|
|
461
|
+
});
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (isHiddenTranscriptRecord(value) ||
|
|
465
|
+
(parentId !== undefined && metaRecordIds.has(parentId))) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const generatedImage = codexGeneratedImageEvent(value);
|
|
469
|
+
if (generatedImage !== undefined)
|
|
470
|
+
items.push(generatedImage);
|
|
471
|
+
for (const parsedItem of transcriptItems(runner, value)) {
|
|
472
|
+
const item = recordId === undefined ? parsedItem : { ...parsedItem, nativeId: recordId };
|
|
473
|
+
if (item.kind === 'tool_result') {
|
|
474
|
+
const toolIndex = toolIndexes.get(item.toolUseId);
|
|
475
|
+
if (toolIndex !== undefined)
|
|
476
|
+
items[toolIndex] = withToolResult(items[toolIndex], item);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (item.kind === 'tool_call') {
|
|
480
|
+
toolIndexes.set(item.toolUseId, items.length);
|
|
481
|
+
items.push(item);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
items.push(item);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
if (derivedSession)
|
|
488
|
+
return undefined;
|
|
489
|
+
if (cwd === undefined)
|
|
490
|
+
return undefined;
|
|
491
|
+
const title = items.find((item) => item.kind === 'message' && item.role === 'USER')?.text;
|
|
492
|
+
// Tagged Plan Mode instruction labels do not form a session title.
|
|
493
|
+
const strippedTitle = title === undefined ? undefined : stripClaudePlanTag(stripMissionStartPrompt(title));
|
|
494
|
+
return {
|
|
495
|
+
runner,
|
|
496
|
+
externalSessionId: id ?? basename(path, '.jsonl'),
|
|
497
|
+
cwd,
|
|
498
|
+
...(strippedTitle === undefined || strippedTitle.length === 0
|
|
499
|
+
? {}
|
|
500
|
+
: { title: compact(strippedTitle) }),
|
|
501
|
+
digest: createHash('sha256').update(content).digest('hex'),
|
|
502
|
+
items,
|
|
503
|
+
lastActivityAt: Math.max(0, ...items.map((item) => item.createdAt ?? 0)),
|
|
504
|
+
truncated,
|
|
505
|
+
windowStart: window.start,
|
|
506
|
+
windowEnd: window.end,
|
|
507
|
+
snapshotEnd: window.snapshotEnd,
|
|
508
|
+
fileAnchor: window.fileAnchor,
|
|
509
|
+
anchorBytes: window.anchorBytes
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function derivedTranscriptRecord(runner, value) {
|
|
513
|
+
if (runner === 'claude-code')
|
|
514
|
+
return value['isSidechain'] === true;
|
|
515
|
+
if (runner !== 'codex' || value['type'] !== 'session_meta')
|
|
516
|
+
return false;
|
|
517
|
+
const payload = isRecord(value['payload']) ? value['payload'] : undefined;
|
|
518
|
+
if (payload === undefined)
|
|
519
|
+
return false;
|
|
520
|
+
if (payload['thread_source'] === 'subagent')
|
|
521
|
+
return true;
|
|
522
|
+
const source = payload['source'];
|
|
523
|
+
return (source === 'subagent' ||
|
|
524
|
+
(isRecord(source) && (source['kind'] === 'subagent' || isRecord(source['subagent']))));
|
|
525
|
+
}
|
|
526
|
+
function workspacePath(record) {
|
|
527
|
+
return (firstString(record, ['cwd', 'working_directory', 'workspacePath']) ??
|
|
528
|
+
nestedString(record, ['payload', 'cwd']) ??
|
|
529
|
+
nestedString(record, ['message', 'cwd']));
|
|
530
|
+
}
|
|
531
|
+
function sessionId(record) {
|
|
532
|
+
// A Codex sub-agent transcript records its own thread in `payload.id`, but
|
|
533
|
+
// retains the parent thread in `payload.session_id`. Treating the latter
|
|
534
|
+
// as this file's identity makes the child file overwrite the parent thread
|
|
535
|
+
// in the discovery index, which then shows unrelated messages for the
|
|
536
|
+
// parent Chat.
|
|
537
|
+
if (record['type'] === 'session_meta') {
|
|
538
|
+
const transcriptId = nestedString(record, ['payload', 'id']);
|
|
539
|
+
if (transcriptId !== undefined)
|
|
540
|
+
return transcriptId;
|
|
541
|
+
}
|
|
542
|
+
return (firstString(record, ['sessionId', 'session_id', 'thread_id', 'conversationId']) ??
|
|
543
|
+
nestedString(record, ['payload', 'id']) ??
|
|
544
|
+
nestedString(record, ['payload', 'session_id']) ??
|
|
545
|
+
nestedString(record, ['payload', 'thread_id']));
|
|
546
|
+
}
|
|
547
|
+
function codexContextUsage(value) {
|
|
548
|
+
if (!isRecord(value) || value.type !== 'event_msg' || !isRecord(value.payload))
|
|
549
|
+
return undefined;
|
|
550
|
+
const payload = value.payload;
|
|
551
|
+
if (payload.type !== 'token_count' || !isRecord(payload.info))
|
|
552
|
+
return undefined;
|
|
553
|
+
const promptUsage = payload.info.last_token_usage;
|
|
554
|
+
const maxTokens = payload.info.model_context_window;
|
|
555
|
+
if (!isRecord(promptUsage) ||
|
|
556
|
+
typeof promptUsage.input_tokens !== 'number' ||
|
|
557
|
+
typeof maxTokens !== 'number')
|
|
558
|
+
return undefined;
|
|
559
|
+
if (!Number.isFinite(promptUsage.input_tokens) ||
|
|
560
|
+
!Number.isInteger(promptUsage.input_tokens) ||
|
|
561
|
+
!Number.isFinite(maxTokens) ||
|
|
562
|
+
!Number.isInteger(maxTokens) ||
|
|
563
|
+
maxTokens <= 0 ||
|
|
564
|
+
promptUsage.input_tokens < 0)
|
|
565
|
+
return undefined;
|
|
566
|
+
return { usedTokens: promptUsage.input_tokens, maxTokens };
|
|
567
|
+
}
|
|
568
|
+
function claudeContextUsage(value) {
|
|
569
|
+
if (value.type !== 'assistant' || !isRecord(value.message))
|
|
570
|
+
return undefined;
|
|
571
|
+
const model = value.message.model;
|
|
572
|
+
const usage = value.message.usage;
|
|
573
|
+
if (typeof model !== 'string' ||
|
|
574
|
+
model.length === 0 ||
|
|
575
|
+
model === '<synthetic>' ||
|
|
576
|
+
!isRecord(usage))
|
|
577
|
+
return undefined;
|
|
578
|
+
const inputTokens = nonNegativeInteger(usage.input_tokens);
|
|
579
|
+
const cacheCreationTokens = optionalNonNegativeInteger(usage.cache_creation_input_tokens);
|
|
580
|
+
const cacheReadTokens = optionalNonNegativeInteger(usage.cache_read_input_tokens);
|
|
581
|
+
if (inputTokens === undefined ||
|
|
582
|
+
cacheCreationTokens === undefined ||
|
|
583
|
+
cacheReadTokens === undefined)
|
|
584
|
+
return undefined;
|
|
585
|
+
return { model, usedTokens: inputTokens + cacheCreationTokens + cacheReadTokens };
|
|
586
|
+
}
|
|
587
|
+
function optionalNonNegativeInteger(value) {
|
|
588
|
+
return value === undefined ? 0 : nonNegativeInteger(value);
|
|
589
|
+
}
|
|
590
|
+
function nonNegativeInteger(value) {
|
|
591
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
592
|
+
}
|
|
593
|
+
function positiveInteger(value) {
|
|
594
|
+
if (typeof value !== 'string' || !/^\d+$/.test(value.trim()))
|
|
595
|
+
return undefined;
|
|
596
|
+
const parsed = Number(value);
|
|
597
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
598
|
+
}
|
|
599
|
+
function transcriptItems(runner, record) {
|
|
600
|
+
const createdAt = timestampOf(record);
|
|
601
|
+
const results = [...toolResultsOf(record, createdAt), ...codexToolResultsOf(record, createdAt)];
|
|
602
|
+
if (results.length > 0)
|
|
603
|
+
return results;
|
|
604
|
+
const values = [
|
|
605
|
+
...toolUsesOf(record, createdAt),
|
|
606
|
+
...codexToolUsesOf(record, createdAt),
|
|
607
|
+
...codexReasoningSummariesOf(record, createdAt),
|
|
608
|
+
...unsupportedCodexResponseItems(record, createdAt),
|
|
609
|
+
...unsupportedTranscriptItems(record, createdAt)
|
|
610
|
+
];
|
|
611
|
+
const role = roleOf(record);
|
|
612
|
+
if (role === undefined)
|
|
613
|
+
return values;
|
|
614
|
+
const rawText = messageText(textOf(record) ?? '');
|
|
615
|
+
if (rawText.length === 0)
|
|
616
|
+
return values;
|
|
617
|
+
// Codex transcripts can contain the host's injected AGENTS.md and runtime
|
|
618
|
+
// context as a `user` item before the first actual prompt. It is neither a
|
|
619
|
+
// user-visible chat turn nor a meaningful session title.
|
|
620
|
+
if (role === 'USER' && isInjectedContextPrompt(rawText))
|
|
621
|
+
return values;
|
|
622
|
+
const message = role === 'USER' && runner === 'codex'
|
|
623
|
+
? parseCodexComposerImageMarkers(rawText)
|
|
624
|
+
: { text: rawText, images: [] };
|
|
625
|
+
values.unshift({
|
|
626
|
+
kind: 'message',
|
|
627
|
+
role,
|
|
628
|
+
text: message.text,
|
|
629
|
+
...(message.images.length === 0
|
|
630
|
+
? {}
|
|
631
|
+
: {
|
|
632
|
+
imageAttachments: message.images.map((image) => ({
|
|
633
|
+
name: `Image #${image.index}`,
|
|
634
|
+
mime: imageMime(image.localPath),
|
|
635
|
+
localPath: image.localPath
|
|
636
|
+
}))
|
|
637
|
+
}),
|
|
638
|
+
createdAt
|
|
639
|
+
});
|
|
640
|
+
return values;
|
|
641
|
+
}
|
|
642
|
+
function unsupportedCodexResponseItems(record, createdAt) {
|
|
643
|
+
const payload = codexToolPayload(record);
|
|
644
|
+
const type = typeof payload?.type === 'string' ? payload.type : undefined;
|
|
645
|
+
if (type === undefined ||
|
|
646
|
+
typeof payload?.role === 'string' ||
|
|
647
|
+
type === 'reasoning' ||
|
|
648
|
+
type === 'custom_tool_call' ||
|
|
649
|
+
type === 'custom_tool_call_output' ||
|
|
650
|
+
type === 'function_call' ||
|
|
651
|
+
type === 'function_call_output')
|
|
652
|
+
return [];
|
|
653
|
+
return [
|
|
654
|
+
{
|
|
655
|
+
kind: 'unknown',
|
|
656
|
+
sourceEventType: `codex:${type}`,
|
|
657
|
+
label: `Codex ${compact(type).slice(0, 128)}`,
|
|
658
|
+
createdAt
|
|
659
|
+
}
|
|
660
|
+
];
|
|
661
|
+
}
|
|
662
|
+
function codexReasoningSummariesOf(record, createdAt) {
|
|
663
|
+
const payload = codexToolPayload(record);
|
|
664
|
+
if (payload?.type !== 'reasoning')
|
|
665
|
+
return [];
|
|
666
|
+
const sections = Array.isArray(payload.summary)
|
|
667
|
+
? payload.summary.flatMap((value, index) => {
|
|
668
|
+
if (typeof value !== 'string')
|
|
669
|
+
return [];
|
|
670
|
+
const text = compact(value).slice(0, 10_000);
|
|
671
|
+
return text.length === 0 ? [] : [{ index, text }];
|
|
672
|
+
})
|
|
673
|
+
: [];
|
|
674
|
+
return [{ kind: 'reasoning_summary', sections, createdAt }];
|
|
675
|
+
}
|
|
676
|
+
function unsupportedTranscriptItems(record, createdAt) {
|
|
677
|
+
return contentBlocks(record).flatMap((block) => {
|
|
678
|
+
const type = typeof block.type === 'string' ? block.type : undefined;
|
|
679
|
+
if (type === undefined ||
|
|
680
|
+
type === 'text' ||
|
|
681
|
+
type === 'input_text' ||
|
|
682
|
+
type === 'output_text' ||
|
|
683
|
+
type === 'image' ||
|
|
684
|
+
type === 'input_image' ||
|
|
685
|
+
type === 'thinking' ||
|
|
686
|
+
type === 'redacted_thinking' ||
|
|
687
|
+
type === 'encrypted_thinking' ||
|
|
688
|
+
type === 'tool_use' ||
|
|
689
|
+
type === 'tool_result')
|
|
690
|
+
return [];
|
|
691
|
+
return [
|
|
692
|
+
{
|
|
693
|
+
kind: 'unknown',
|
|
694
|
+
sourceEventType: `transcript:${type}`,
|
|
695
|
+
label: `Agent ${compact(type).slice(0, 128)}`,
|
|
696
|
+
createdAt
|
|
697
|
+
}
|
|
698
|
+
];
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function toolUsesOf(record, createdAt) {
|
|
702
|
+
return contentBlocks(record).flatMap((block) => {
|
|
703
|
+
if (block['type'] !== 'tool_use' ||
|
|
704
|
+
typeof block['id'] !== 'string' ||
|
|
705
|
+
typeof block['name'] !== 'string')
|
|
706
|
+
return [];
|
|
707
|
+
const input = block['input'];
|
|
708
|
+
const summary = compactValue(input, 10_000);
|
|
709
|
+
return [
|
|
710
|
+
{
|
|
711
|
+
kind: 'tool_call',
|
|
712
|
+
toolUseId: block['id'],
|
|
713
|
+
toolName: compact(block['name']).slice(0, 128),
|
|
714
|
+
input,
|
|
715
|
+
inputSummary: summary.text || null,
|
|
716
|
+
inputTruncated: summary.truncated,
|
|
717
|
+
outputSummary: null,
|
|
718
|
+
outputTruncated: false,
|
|
719
|
+
failed: false,
|
|
720
|
+
createdAt
|
|
721
|
+
}
|
|
722
|
+
];
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
function toolResultsOf(record, createdAt) {
|
|
726
|
+
return contentBlocks(record).flatMap((block) => {
|
|
727
|
+
if (block['type'] !== 'tool_result' || typeof block['tool_use_id'] !== 'string')
|
|
728
|
+
return [];
|
|
729
|
+
const output = compactValue(block['content'], 10_000);
|
|
730
|
+
return [
|
|
731
|
+
{
|
|
732
|
+
kind: 'tool_result',
|
|
733
|
+
toolUseId: block['tool_use_id'],
|
|
734
|
+
output: output.text,
|
|
735
|
+
failed: block['is_error'] === true,
|
|
736
|
+
truncated: output.truncated,
|
|
737
|
+
createdAt
|
|
738
|
+
}
|
|
739
|
+
];
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Codex persists custom and standard function tools as paired `response_item`
|
|
744
|
+
* records. Their record IDs differ, while `call_id` is the stable identifier
|
|
745
|
+
* shared by invocation and result. Normalize on that key so JSONL fallback
|
|
746
|
+
* history has the same single-card shape as live events.
|
|
747
|
+
*/
|
|
748
|
+
function codexToolUsesOf(record, createdAt) {
|
|
749
|
+
const payload = codexToolPayload(record);
|
|
750
|
+
if (payload?.['type'] !== 'custom_tool_call' && payload?.['type'] !== 'function_call')
|
|
751
|
+
return [];
|
|
752
|
+
const toolUseId = firstString(payload, ['call_id', 'id']);
|
|
753
|
+
const toolName = firstString(payload, ['name', 'tool']);
|
|
754
|
+
if (toolUseId === undefined || toolName === undefined)
|
|
755
|
+
return [];
|
|
756
|
+
const input = payload['input'] ?? payload['arguments'];
|
|
757
|
+
const summary = compactValue(input, 10_000);
|
|
758
|
+
return [
|
|
759
|
+
{
|
|
760
|
+
kind: 'tool_call',
|
|
761
|
+
toolUseId,
|
|
762
|
+
toolName: compact(toolName).slice(0, 128),
|
|
763
|
+
input,
|
|
764
|
+
inputSummary: summary.text || null,
|
|
765
|
+
inputTruncated: summary.truncated,
|
|
766
|
+
outputSummary: null,
|
|
767
|
+
outputTruncated: false,
|
|
768
|
+
failed: false,
|
|
769
|
+
createdAt
|
|
770
|
+
}
|
|
771
|
+
];
|
|
772
|
+
}
|
|
773
|
+
function codexToolResultsOf(record, createdAt) {
|
|
774
|
+
const payload = codexToolPayload(record);
|
|
775
|
+
if (payload?.['type'] !== 'custom_tool_call_output' &&
|
|
776
|
+
payload?.['type'] !== 'function_call_output')
|
|
777
|
+
return [];
|
|
778
|
+
const toolUseId = firstString(payload, ['call_id', 'id']);
|
|
779
|
+
if (toolUseId === undefined)
|
|
780
|
+
return [];
|
|
781
|
+
const output = compactValue(codexToolOutput(payload['output'] ?? payload['contentItems']), 10_000);
|
|
782
|
+
const imageAttachments = codexImagePlaceholders(payload['output'] ?? payload['contentItems']);
|
|
783
|
+
return [
|
|
784
|
+
{
|
|
785
|
+
kind: 'tool_result',
|
|
786
|
+
toolUseId,
|
|
787
|
+
output: output.text,
|
|
788
|
+
failed: payload['status'] === 'failed' || payload['error'] !== undefined,
|
|
789
|
+
truncated: output.truncated,
|
|
790
|
+
...(imageAttachments.length === 0 ? {} : { imageAttachments }),
|
|
791
|
+
createdAt
|
|
792
|
+
}
|
|
793
|
+
];
|
|
794
|
+
}
|
|
795
|
+
function codexToolPayload(record) {
|
|
796
|
+
return record['type'] === 'response_item' && isRecord(record['payload'])
|
|
797
|
+
? record['payload']
|
|
798
|
+
: undefined;
|
|
799
|
+
}
|
|
800
|
+
function codexGeneratedImageEvent(record) {
|
|
801
|
+
if (record['type'] !== 'event_msg' || !isRecord(record['payload']))
|
|
802
|
+
return undefined;
|
|
803
|
+
const payload = record['payload'];
|
|
804
|
+
if (payload['type'] !== 'image_generation_end' ||
|
|
805
|
+
typeof payload['call_id'] !== 'string' ||
|
|
806
|
+
typeof payload['saved_path'] !== 'string')
|
|
807
|
+
return undefined;
|
|
808
|
+
const localPath = payload['saved_path'];
|
|
809
|
+
if (!localPath.includes('/.codex/generated_images/') || !/\.(?:png|jpe?g|webp)$/i.test(localPath))
|
|
810
|
+
return undefined;
|
|
811
|
+
return {
|
|
812
|
+
kind: 'tool_call',
|
|
813
|
+
toolUseId: payload['call_id'],
|
|
814
|
+
toolName: 'imagegen',
|
|
815
|
+
input: null,
|
|
816
|
+
inputSummary: null,
|
|
817
|
+
inputTruncated: false,
|
|
818
|
+
outputSummary: payload['status'] === 'completed' ? 'Image generation completed' : 'Image generation failed',
|
|
819
|
+
outputTruncated: false,
|
|
820
|
+
toolCategory: 'IMAGE_GENERATION',
|
|
821
|
+
imageAttachments: [{ name: basename(localPath), mime: imageMime(localPath), localPath }],
|
|
822
|
+
failed: payload['status'] !== 'completed',
|
|
823
|
+
createdAt: timestampOf(record)
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
/** Extract Codex output text blocks instead of rendering their JSON envelopes. */
|
|
827
|
+
function codexToolOutput(value) {
|
|
828
|
+
if (!Array.isArray(value))
|
|
829
|
+
return value;
|
|
830
|
+
const text = value.flatMap((block) => {
|
|
831
|
+
if (typeof block === 'string')
|
|
832
|
+
return [block];
|
|
833
|
+
if (!isRecord(block))
|
|
834
|
+
return [];
|
|
835
|
+
const direct = firstString(block, ['text', 'content']);
|
|
836
|
+
return direct === undefined ? [] : [codexVisibleToolText(direct)];
|
|
837
|
+
});
|
|
838
|
+
return text.length > 0 ? text.join('') : value;
|
|
839
|
+
}
|
|
840
|
+
function codexVisibleToolText(value) {
|
|
841
|
+
const marker = 'data:image/';
|
|
842
|
+
let cursor = 0;
|
|
843
|
+
let visible = '';
|
|
844
|
+
while (cursor < value.length) {
|
|
845
|
+
const start = value.indexOf(marker, cursor);
|
|
846
|
+
if (start < 0)
|
|
847
|
+
return visible + value.slice(cursor);
|
|
848
|
+
visible += `${value.slice(cursor, start)}[Image content filtered]`;
|
|
849
|
+
const doubleQuote = value.indexOf('"', start);
|
|
850
|
+
const singleQuote = value.indexOf("'", start);
|
|
851
|
+
const end = doubleQuote < 0
|
|
852
|
+
? singleQuote
|
|
853
|
+
: singleQuote < 0
|
|
854
|
+
? doubleQuote
|
|
855
|
+
: Math.min(doubleQuote, singleQuote);
|
|
856
|
+
if (end < 0)
|
|
857
|
+
return visible;
|
|
858
|
+
cursor = end;
|
|
859
|
+
}
|
|
860
|
+
return visible;
|
|
861
|
+
}
|
|
862
|
+
/** Extract only image placeholder metadata from native Codex output. */
|
|
863
|
+
function codexImagePlaceholders(value) {
|
|
864
|
+
const attachments = [];
|
|
865
|
+
let visited = 0;
|
|
866
|
+
const visit = (current, depth) => {
|
|
867
|
+
if (attachments.length >= 5 || visited >= 128 || depth > 5 || current == null)
|
|
868
|
+
return;
|
|
869
|
+
visited += 1;
|
|
870
|
+
if (typeof current === 'string') {
|
|
871
|
+
const paths = [];
|
|
872
|
+
collectGeneratedImagePaths(current, paths);
|
|
873
|
+
for (const localPath of paths) {
|
|
874
|
+
if (attachments.some((attachment) => attachment.localPath === localPath))
|
|
875
|
+
continue;
|
|
876
|
+
attachments.push({ name: basename(localPath), mime: imageMime(localPath), localPath });
|
|
877
|
+
}
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (Array.isArray(current)) {
|
|
881
|
+
for (const entry of current)
|
|
882
|
+
visit(entry, depth + 1);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (!isRecord(current))
|
|
886
|
+
return;
|
|
887
|
+
const type = typeof current['type'] === 'string' ? current['type'] : '';
|
|
888
|
+
if (type === 'input_text' && typeof current['text'] === 'string') {
|
|
889
|
+
const mime = /["']image_url["']\s*:\s*["']data:(image\/[^;,"']+)[;,]/.exec(current['text'])?.[1];
|
|
890
|
+
if (mime !== undefined)
|
|
891
|
+
attachments.push({ name: `image-${attachments.length + 1}.${imageExtension(mime)}`, mime });
|
|
892
|
+
}
|
|
893
|
+
const imageUrl = isRecord(current['image_url'])
|
|
894
|
+
? firstString(current['image_url'], ['url'])
|
|
895
|
+
: typeof current['image_url'] === 'string'
|
|
896
|
+
? current['image_url']
|
|
897
|
+
: undefined;
|
|
898
|
+
const data = typeof current['data'] === 'string' ? current['data'] : imageUrl;
|
|
899
|
+
if ((type === 'image' || type === 'input_image' || type === 'output_image') &&
|
|
900
|
+
data?.startsWith('data:image/')) {
|
|
901
|
+
const mime = /^data:([^;,]+)[;,]/.exec(data)?.[1] ?? 'image/png';
|
|
902
|
+
attachments.push({ name: `image-${attachments.length + 1}.${imageExtension(mime)}`, mime });
|
|
903
|
+
}
|
|
904
|
+
for (const child of Object.values(current))
|
|
905
|
+
visit(child, depth + 1);
|
|
906
|
+
};
|
|
907
|
+
visit(value, 0);
|
|
908
|
+
return attachments;
|
|
909
|
+
}
|
|
910
|
+
function collectGeneratedImagePaths(value, paths) {
|
|
911
|
+
const marker = '/.codex/generated_images/';
|
|
912
|
+
let cursor = 0;
|
|
913
|
+
while (paths.length < 5) {
|
|
914
|
+
const markerIndex = value.indexOf(marker, cursor);
|
|
915
|
+
if (markerIndex < 0)
|
|
916
|
+
return;
|
|
917
|
+
let start = markerIndex;
|
|
918
|
+
while (start > 0 && !/[\s"']/.test(value[start - 1]))
|
|
919
|
+
start -= 1;
|
|
920
|
+
let end = markerIndex + marker.length;
|
|
921
|
+
while (end < value.length && !/[\s"']/.test(value[end]))
|
|
922
|
+
end += 1;
|
|
923
|
+
const path = value.slice(start, end).replace(/[),.;:]+$/, '');
|
|
924
|
+
if (/\.(?:png|jpe?g|webp)$/i.test(path) && !paths.includes(path))
|
|
925
|
+
paths.push(path);
|
|
926
|
+
cursor = end;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function imageMime(path) {
|
|
930
|
+
const extension = path.slice(path.lastIndexOf('.') + 1).toLowerCase();
|
|
931
|
+
if (extension === 'jpg' || extension === 'jpeg')
|
|
932
|
+
return 'image/jpeg';
|
|
933
|
+
if (extension === 'webp')
|
|
934
|
+
return 'image/webp';
|
|
935
|
+
return 'image/png';
|
|
936
|
+
}
|
|
937
|
+
function imageExtension(mime) {
|
|
938
|
+
if (mime === 'image/jpeg')
|
|
939
|
+
return 'jpg';
|
|
940
|
+
if (mime === 'image/webp')
|
|
941
|
+
return 'webp';
|
|
942
|
+
if (mime === 'image/gif')
|
|
943
|
+
return 'gif';
|
|
944
|
+
return 'png';
|
|
945
|
+
}
|
|
946
|
+
function withToolResult(call, result) {
|
|
947
|
+
const viewedImagePath = codexViewedImagePath(call);
|
|
948
|
+
const imageAttachments = result.imageAttachments?.map((attachment) => attachment.localPath !== undefined || viewedImagePath === undefined
|
|
949
|
+
? attachment
|
|
950
|
+
: {
|
|
951
|
+
name: basename(viewedImagePath),
|
|
952
|
+
mime: imageMime(viewedImagePath),
|
|
953
|
+
localPath: viewedImagePath
|
|
954
|
+
});
|
|
955
|
+
return {
|
|
956
|
+
...call,
|
|
957
|
+
outputSummary: result.output,
|
|
958
|
+
outputTruncated: result.truncated,
|
|
959
|
+
...(imageAttachments === undefined ? {} : { imageAttachments }),
|
|
960
|
+
failed: result.failed
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
function codexViewedImagePath(call) {
|
|
964
|
+
const toolName = call.toolName.toLowerCase();
|
|
965
|
+
if (toolName === 'view_image' || toolName === 'imageview') {
|
|
966
|
+
return isRecord(call.input) && typeof call.input['path'] === 'string'
|
|
967
|
+
? call.input['path']
|
|
968
|
+
: undefined;
|
|
969
|
+
}
|
|
970
|
+
if (toolName !== 'exec' || typeof call.input !== 'string')
|
|
971
|
+
return undefined;
|
|
972
|
+
if (!/tools\.view_image\s*\(/.test(call.input))
|
|
973
|
+
return undefined;
|
|
974
|
+
const encodedPath = /["']path["']\s*:\s*("(?:\\.|[^"\\])*")/.exec(call.input)?.[1];
|
|
975
|
+
if (encodedPath === undefined)
|
|
976
|
+
return undefined;
|
|
977
|
+
try {
|
|
978
|
+
const path = JSON.parse(encodedPath);
|
|
979
|
+
return typeof path === 'string' ? path : undefined;
|
|
980
|
+
}
|
|
981
|
+
catch {
|
|
982
|
+
return undefined;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
function isInjectedContextPrompt(text) {
|
|
986
|
+
const normalized = text.replace(/\s+/g, ' ').trim();
|
|
987
|
+
if (normalized.startsWith('<codex_internal_context'))
|
|
988
|
+
return true;
|
|
989
|
+
if (/^<(?:environment_context|subagent_notification|turn_aborted)(?:\s|>)/u.test(normalized))
|
|
990
|
+
return true;
|
|
991
|
+
return (normalized.startsWith('# AGENTS.md instructions') &&
|
|
992
|
+
(normalized.includes('<INSTRUCTIONS>') || normalized.includes('<environment_context>')));
|
|
993
|
+
}
|
|
994
|
+
function isClaudeCompactCommand(record) {
|
|
995
|
+
return textOf(record)?.trim() === '<command-name>/compact</command-name>';
|
|
996
|
+
}
|
|
997
|
+
function isClaudeCompactSuccess(record) {
|
|
998
|
+
return textOf(record)?.trim() === '<local-command-stdout>Compacted</local-command-stdout>';
|
|
999
|
+
}
|
|
1000
|
+
function isHiddenTranscriptRecord(record) {
|
|
1001
|
+
if (contentBlocks(record).some((block) => block['type'] === 'tool_result'))
|
|
1002
|
+
return false;
|
|
1003
|
+
if (record['interruptedByShutdown'] === true ||
|
|
1004
|
+
record['isMeta'] === true ||
|
|
1005
|
+
record['isVisibleInTranscriptOnly'] === true ||
|
|
1006
|
+
record['isCompactSummary'] === true)
|
|
1007
|
+
return true;
|
|
1008
|
+
const text = textOf(record)?.trim() ?? '';
|
|
1009
|
+
return (text.startsWith('<local-command-') ||
|
|
1010
|
+
text.startsWith('<command-name>') ||
|
|
1011
|
+
text.startsWith('<command-message>'));
|
|
1012
|
+
}
|
|
1013
|
+
function roleOf(record) {
|
|
1014
|
+
const candidates = [
|
|
1015
|
+
firstString(record, ['role']),
|
|
1016
|
+
nestedString(record, ['message', 'role']),
|
|
1017
|
+
nestedString(record, ['payload', 'role']),
|
|
1018
|
+
firstString(record, ['type']),
|
|
1019
|
+
nestedString(record, ['payload', 'type'])
|
|
1020
|
+
];
|
|
1021
|
+
if (candidates.some((value) => value === 'user' || value === 'human' || value === 'input'))
|
|
1022
|
+
return 'USER';
|
|
1023
|
+
if (candidates.some((value) => value === 'assistant' || value === 'agent' || value === 'output'))
|
|
1024
|
+
return 'ASSISTANT';
|
|
1025
|
+
return undefined;
|
|
1026
|
+
}
|
|
1027
|
+
function textOf(record) {
|
|
1028
|
+
return (firstString(record, ['content', 'text']) ??
|
|
1029
|
+
nestedText(record['message']) ??
|
|
1030
|
+
nestedText(record['payload']));
|
|
1031
|
+
}
|
|
1032
|
+
function nestedText(value) {
|
|
1033
|
+
if (typeof value === 'string')
|
|
1034
|
+
return value;
|
|
1035
|
+
if (!isRecord(value))
|
|
1036
|
+
return undefined;
|
|
1037
|
+
const direct = firstString(value, ['content', 'text', 'message']);
|
|
1038
|
+
if (direct !== undefined)
|
|
1039
|
+
return direct;
|
|
1040
|
+
if (Array.isArray(value['content'])) {
|
|
1041
|
+
const parts = value['content'].flatMap((part) => {
|
|
1042
|
+
if (typeof part === 'string')
|
|
1043
|
+
return [part];
|
|
1044
|
+
if (!isRecord(part))
|
|
1045
|
+
return [];
|
|
1046
|
+
return [firstString(part, ['text', 'content'])].filter((text) => text !== undefined);
|
|
1047
|
+
});
|
|
1048
|
+
return parts.join('\n');
|
|
1049
|
+
}
|
|
1050
|
+
return undefined;
|
|
1051
|
+
}
|
|
1052
|
+
function contentBlocks(record) {
|
|
1053
|
+
const values = [record['message'], record['payload']];
|
|
1054
|
+
for (const value of values)
|
|
1055
|
+
if (isRecord(value) && Array.isArray(value['content']))
|
|
1056
|
+
return value['content'].filter(isRecord);
|
|
1057
|
+
return [];
|
|
1058
|
+
}
|
|
1059
|
+
function compactValue(value, limit) {
|
|
1060
|
+
if (value === undefined || value === null)
|
|
1061
|
+
return { text: '', truncated: false };
|
|
1062
|
+
let text;
|
|
1063
|
+
if (typeof value === 'string')
|
|
1064
|
+
text = value;
|
|
1065
|
+
else {
|
|
1066
|
+
try {
|
|
1067
|
+
text = JSON.stringify(value);
|
|
1068
|
+
}
|
|
1069
|
+
catch {
|
|
1070
|
+
return { text: '(Unable to display)', truncated: false };
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
return {
|
|
1074
|
+
text: text.length <= limit ? text : `${text.slice(0, Math.max(0, limit - 1))}…`,
|
|
1075
|
+
truncated: text.length > limit
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
function timestampOf(record) {
|
|
1079
|
+
const raw = record['timestamp'] ?? record['created_at'] ?? record['createdAt'];
|
|
1080
|
+
if (typeof raw === 'number' && Number.isFinite(raw))
|
|
1081
|
+
return raw < 10_000_000_000 ? raw * 1_000 : raw;
|
|
1082
|
+
if (typeof raw === 'string') {
|
|
1083
|
+
const value = Date.parse(raw);
|
|
1084
|
+
return Number.isNaN(value) ? null : value;
|
|
1085
|
+
}
|
|
1086
|
+
return null;
|
|
1087
|
+
}
|
|
1088
|
+
function firstString(value, keys) {
|
|
1089
|
+
for (const key of keys)
|
|
1090
|
+
if (typeof value[key] === 'string' && value[key].length > 0)
|
|
1091
|
+
return value[key];
|
|
1092
|
+
return undefined;
|
|
1093
|
+
}
|
|
1094
|
+
function nestedString(value, keys) {
|
|
1095
|
+
let current = value;
|
|
1096
|
+
for (const key of keys) {
|
|
1097
|
+
if (!isRecord(current))
|
|
1098
|
+
return undefined;
|
|
1099
|
+
current = current[key];
|
|
1100
|
+
}
|
|
1101
|
+
return typeof current === 'string' && current.length > 0 ? current : undefined;
|
|
1102
|
+
}
|
|
1103
|
+
function compact(value) {
|
|
1104
|
+
return value.replace(/\s+/g, ' ').trim().slice(0, 16_000);
|
|
1105
|
+
}
|
|
1106
|
+
/** Conversation content can be Markdown, so its internal whitespace must not be collapsed like a title. */
|
|
1107
|
+
function messageText(value) {
|
|
1108
|
+
return value.trim().slice(0, 16_000);
|
|
1109
|
+
}
|
|
1110
|
+
function canonical(value) {
|
|
1111
|
+
try {
|
|
1112
|
+
const normalized = resolve(value).replace(/[\\/]+$/, '');
|
|
1113
|
+
return process.platform === 'win32' ? normalized.toLocaleLowerCase() : normalized;
|
|
1114
|
+
}
|
|
1115
|
+
catch {
|
|
1116
|
+
return value;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function indexKey(runner, cwd, externalSessionId) {
|
|
1120
|
+
return `${runner}\u0000${cwd}\u0000${externalSessionId}`;
|
|
1121
|
+
}
|
|
1122
|
+
function setTranscriptIndex(key, path) {
|
|
1123
|
+
const previousTimer = transcriptIndexTimers.get(key);
|
|
1124
|
+
if (previousTimer !== undefined)
|
|
1125
|
+
clearTimeout(previousTimer);
|
|
1126
|
+
transcriptIndex.set(key, path);
|
|
1127
|
+
const timer = setTimeout(() => deleteTranscriptIndex(key), TRANSCRIPT_INDEX_TTL_MS);
|
|
1128
|
+
timer.unref();
|
|
1129
|
+
transcriptIndexTimers.set(key, timer);
|
|
1130
|
+
}
|
|
1131
|
+
function getTranscriptIndex(key) {
|
|
1132
|
+
return transcriptIndex.get(key);
|
|
1133
|
+
}
|
|
1134
|
+
function deleteTranscriptIndex(key) {
|
|
1135
|
+
const timer = transcriptIndexTimers.get(key);
|
|
1136
|
+
if (timer !== undefined)
|
|
1137
|
+
clearTimeout(timer);
|
|
1138
|
+
transcriptIndexTimers.delete(key);
|
|
1139
|
+
transcriptIndex.delete(key);
|
|
1140
|
+
}
|
|
1141
|
+
function isRecord(value) {
|
|
1142
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1143
|
+
}
|