MCPcopy Create free account
hub / github.com/arctic-cli/interface / execute

Function execute

packages/arctic/src/cli/cmd/run.ts:120–267  ·  view source on GitHub ↗
(sdk: ArcticClient, sessionID: string)

Source from the content-addressed store, hash-verified

118 }
119
120 const execute = async (sdk: ArcticClient, sessionID: string) => {
121 const printEvent = (color: string, type: string, title: string) => {
122 UI.println(
123 color + `|`,
124 UI.Style.TEXT_NORMAL + UI.Style.TEXT_DIM + ` ${type.padEnd(7, " ")}`,
125 "",
126 UI.Style.TEXT_NORMAL + title,
127 )
128 }
129
130 const outputJsonEvent = (type: string, data: any) => {
131 if (args.format === "json") {
132 process.stdout.write(JSON.stringify({ type, timestamp: Date.now(), sessionID, ...data }) + EOL)
133 return true
134 }
135 return false
136 }
137
138 const events = await sdk.event.subscribe()
139 let errorMsg: string | undefined
140 let isWorking = false
141 let workingInterval: number | undefined
142
143 const updateWorkingIndicator = () => {
144 if (workingInterval) {
145 clearInterval(workingInterval as any)
146 }
147 if (!isWorking) {
148 process.stderr.write("\r" + " ".repeat(50))
149 return
150 }
151 const spinner = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
152 let i = 0
153 workingInterval = setInterval(() => {
154 process.stderr.write(`\r${UI.Style.TEXT_INFO}${spinner[i % 10]} Working...${UI.Style.TEXT_NORMAL}`)
155 i++
156 }, 100) as any
157 }
158
159 const eventProcessor = (async () => {
160 for await (const event of events.stream) {
161 if (event.type === "session.status") {
162 const status = event.properties.status
163 const newIsWorking = status.type === "busy" || status.type === "retry"
164 if (newIsWorking !== isWorking) {
165 isWorking = newIsWorking
166 updateWorkingIndicator()
167 }
168 }
169
170 if (event.type === "message.part.updated") {
171 const part = event.properties.part
172 if (part.sessionID !== sessionID) continue
173
174 if (part.type === "tool" && part.state.status === "completed") {
175 if (outputJsonEvent("tool_use", { part })) continue
176 const [tool, color] = TOOL[part.tool] ?? [part.tool, UI.Style.TEXT_INFO_BOLD]
177 const title =

Callers 1

run.tsFile · 0.70

Calls 8

updateWorkingIndicatorFunction · 0.85
outputJsonEventFunction · 0.85
printEventFunction · 0.85
selectFunction · 0.85
respondMethod · 0.80
subscribeMethod · 0.45
commandMethod · 0.45
promptMethod · 0.45

Tested by

no test coverage detected