MCPcopy Index your code
hub / github.com/anomalyco/opencode / reduceSessionData

Function reduceSessionData

packages/opencode/src/cli/cmd/run/session-data.ts:773–1113  ·  view source on GitHub ↗
(input: SessionDataInput)

Source from the content-addressed store, hash-verified

771// question.* → manage the question queue, drive footer view
772// session.error → emit error scrollback entry
773export function reduceSessionData(input: SessionDataInput): SessionDataOutput {
774 const commits: SessionCommit[] = []
775 const data = input.data
776 const event = input.event
777
778 if (event.type === "session.next.shell.started") {
779 if (event.properties.sessionID !== input.sessionID) {
780 return out(data, commits)
781 }
782
783 const shell = claimShell(data, event.properties.callID, "shell", event.properties.command)
784 if (shell.source !== "shell") {
785 return out(data, commits)
786 }
787
788 const partID = shellPartID(event.properties.callID)
789 if (data.ids.has(partID) || data.tools.has(partID)) {
790 return out(data, commits, patch({ status: "running shell" }))
791 }
792
793 data.tools.add(partID)
794 commits.push(startShell(event.properties.callID, shell.command ?? event.properties.command))
795 return out(data, commits, patch({ status: "running shell" }))
796 }
797
798 if (event.type === "session.next.shell.ended") {
799 if (event.properties.sessionID !== input.sessionID) {
800 return out(data, commits)
801 }
802
803 const shell = claimShell(data, event.properties.callID, "shell")
804 if (shell.source !== "shell") {
805 return out(data, commits)
806 }
807
808 const partID = shellPartID(event.properties.callID)
809 const seen = data.tools.has(partID)
810 const command = shell.command ?? ""
811 data.tools.delete(partID)
812 if (data.ids.has(partID)) {
813 return out(data, commits)
814 }
815
816 if (!seen && command) {
817 commits.push(startShell(event.properties.callID, command))
818 }
819
820 data.ids.add(partID)
821 commits.push(doneShell(event.properties.callID, command, event.properties.output))
822 return out(data, commits)
823 }
824
825 if (event.type === "message.updated") {
826 if (event.properties.sessionID !== input.sessionID) {
827 return out(data, commits)
828 }
829
830 const info = event.properties.info

Callers 6

reduceFunction · 0.90
feedFunction · 0.90
applyChildEventFunction · 0.90
bootstrapChildEventFunction · 0.90
createLayerFunction · 0.90
applyFunction · 0.90

Calls 15

toolViewFunction · 0.90
claimShellFunction · 0.85
shellPartIDFunction · 0.85
doneShellFunction · 0.85
formatUsageFunction · 0.85
isAbortFunction · 0.85
msgErrFunction · 0.85
flushPartFunction · 0.85
syncPermissionFunction · 0.85
syncQuestionFunction · 0.85
bashCommandFunction · 0.85
toolStatusFunction · 0.85

Tested by 1

reduceFunction · 0.72