MCPcopy Create free account
hub / github.com/Noumena-Network/code / getAttachments

Function getAttachments

src/utils/attachments.ts:745–1005  ·  view source on GitHub ↗
(
  input: string | null,
  toolUseContext: ToolUseContext,
  ideSelection: IDESelection | null,
  queuedCommands: QueuedCommand[],
  messages?: Message[],
  querySource?: QuerySource,
  options?: { skipSkillDiscovery?: boolean },
)

Source from the content-addressed store, hash-verified

743 * TODO: Generate attachments when we create messages
744 */
745export async function getAttachments(
746 input: string | null,
747 toolUseContext: ToolUseContext,
748 ideSelection: IDESelection | null,
749 queuedCommands: QueuedCommand[],
750 messages?: Message[],
751 querySource?: QuerySource,
752 options?: { skipSkillDiscovery?: boolean },
753): Promise<Attachment[]> {
754 if (
755 isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS) ||
756 isEnvTruthy(process.env.CLAUDE_CODE_SIMPLE)
757 ) {
758 // query.ts:removeFromQueue dequeues these unconditionally after
759 // getAttachmentMessages runs — returning [] here silently drops them.
760 // Coworker runs with --bare and depends on task-notification for
761 // mid-tool-call notifications from Local*Task/Remote*Task.
762 return getQueuedCommandAttachments(queuedCommands)
763 }
764
765 // This will slow down submissions
766 // TODO: Compute attachments as the user types, not here (though we use this
767 // function for slash command prompts too)
768 const abortController = createAbortController()
769 const timeoutId = setTimeout(ac => ac.abort(), 1000, abortController)
770 const context = { ...toolUseContext, abortController }
771
772 const isMainThread = !toolUseContext.agentId
773
774 // Attachments which are added in response to on user input
775 const userInputAttachments = input
776 ? [
777 maybe('at_mentioned_files', () =>
778 processAtMentionedFiles(input, context),
779 ),
780 maybe('mcp_resources', () =>
781 processMcpResourceAttachments(input, context),
782 ),
783 maybe('agent_mentions', () =>
784 Promise.resolve(
785 processAgentMentions(
786 input,
787 toolUseContext.options.agentDefinitions.activeAgents,
788 ),
789 ),
790 ),
791 // Skill discovery on turn 0 (user input as signal). Inter-turn
792 // discovery runs via startSkillDiscoveryPrefetch in query.ts,
793 // gated on write-pivot detection — see skillSearch/prefetch.ts.
794 // feature() here lets DCE drop the 'skill_discovery' string (and the
795 // function it calls) from external builds.
796 //
797 // skipSkillDiscovery gates out the SKILL.md-expansion path
798 // (getMessagesForPromptSlashCommand). When a skill is invoked, its
799 // SKILL.md content is passed as `input` here to extract @-mentions —
800 // but that content is NOT user intent and must not trigger discovery.
801 // Without this gate, a 110KB SKILL.md fires ~3.3s of chunked AKI
802 // queries on every skill invocation (session 13a9afae).

Callers 1

getAttachmentMessagesFunction · 0.85

Calls 15

isEnvTruthyFunction · 0.90
createAbortControllerFunction · 0.85
maybeFunction · 0.85
processAtMentionedFilesFunction · 0.85
processAgentMentionsFunction · 0.85
getDateChangeAttachmentsFunction · 0.85

Tested by

no test coverage detected