MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / run

Method run

src/runtime/agent.ts:670–887  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

668 ): Promise<HandleResult> {
669 const cs = await this.getOrCreateSession(adapter, channelId);
670 const run = async (): Promise<HandleResult> => {
671 cs.running = true;
672
673 let turnHadVisibleOutput = false;
674 let sawAgentStart = false;
675 let sawAgentEnd = false;
676 const runId = randomUUID();
677 let unsubscribe = () => undefined;
678 const waitForQueuedAgentEvents = async (): Promise<void> => {
679 const maybeQueue = (cs.session as { _agentEventQueue?: unknown })
680 ._agentEventQueue;
681 if (
682 !maybeQueue ||
683 typeof (maybeQueue as Promise<unknown>).then !== "function"
684 ) {
685 return;
686 }
687
688 try {
689 await maybeQueue;
690 } catch (error) {
691 log("[PackAgent] Waiting for queued agent events failed:", error);
692 }
693 };
694
695 try {
696 if (this.pendingAbortChannels.delete(channelId)) {
697 return { stopReason: "aborted" };
698 }
699
700 const forwardAgentEvent = (event: AgentEvent): void => {
701 if (event.type === "agent_start") {
702 sawAgentStart = true;
703 } else if (event.type === "agent_end") {
704 if (sawAgentEnd) {
705 return;
706 }
707 sawAgentEnd = true;
708 }
709
710 onEvent(event);
711 };
712
713 // Wire up file output callback for this run
714 cs.fileOutputCallbackRef.current = (event) => {
715 forwardAgentEvent(event);
716 };
717 cs.delegatedToolRunContextRef.current = {
718 runId,
719 channelId,
720 adapter,
721 };
722
723 // Subscribe to agent events and forward to adapter
724 unsubscribe = cs.session.subscribe((event: any) => {
725 switch (event.type) {
726 case "agent_start":
727 log("\n=== [AGENT SESSION START] ===");

Callers 3

_call_claudeFunction · 0.80
_kill_portFunction · 0.80
run_zipFunction · 0.80

Calls 6

logFunction · 0.85
writeFunction · 0.85
getAssistantDiagnosticsFunction · 0.85
isImageMimeFunction · 0.85
formatAttachmentsPromptFunction · 0.85

Tested by

no test coverage detected