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

Function agentGetAppState

src/tools/AgentTool/runAgent.ts:418–500  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

416 // For async agents, also set shouldAvoidPermissionPrompts since they can't show UI
417 const agentPermissionMode = agentDefinition.permissionMode
418 const agentGetAppState = () => {
419 const state = toolUseContext.getAppState()
420 let toolPermissionContext = state.toolPermissionContext
421
422 // Override permission mode if agent defines one (unless parent is bypassPermissions, acceptEdits, or auto)
423 if (
424 agentPermissionMode &&
425 state.toolPermissionContext.mode !== 'bypassPermissions' &&
426 state.toolPermissionContext.mode !== 'acceptEdits' &&
427 !(
428 feature('TRANSCRIPT_CLASSIFIER') &&
429 state.toolPermissionContext.mode === 'auto'
430 )
431 ) {
432 toolPermissionContext = {
433 ...toolPermissionContext,
434 mode: agentPermissionMode,
435 }
436 }
437
438 // Set flag to auto-deny prompts for agents that can't show UI
439 // Use explicit canShowPermissionPrompts if provided, otherwise:
440 // - bubble mode: always show prompts (bubbles to parent terminal)
441 // - default: !isAsync (sync agents show prompts, async agents don't)
442 const shouldAvoidPrompts =
443 canShowPermissionPrompts !== undefined
444 ? !canShowPermissionPrompts
445 : agentPermissionMode === 'bubble'
446 ? false
447 : isAsync
448 if (shouldAvoidPrompts) {
449 toolPermissionContext = {
450 ...toolPermissionContext,
451 shouldAvoidPermissionPrompts: true,
452 }
453 }
454
455 // For background agents that can show prompts, await automated checks
456 // (classifier, permission hooks) before showing the permission dialog.
457 // Since these are background agents, waiting is fine — the user should
458 // only be interrupted when automated checks can't resolve the permission.
459 // This applies to bubble mode (always) and explicit canShowPermissionPrompts.
460 if (isAsync && !shouldAvoidPrompts) {
461 toolPermissionContext = {
462 ...toolPermissionContext,
463 awaitAutomatedChecksBeforeDialog: true,
464 }
465 }
466
467 // Scope tool permissions: when allowedTools is provided, use them as session rules.
468 // IMPORTANT: Preserve cliArg rules (from SDK's --allowedTools) since those are
469 // explicit permissions from the SDK consumer that should apply to all agents.
470 // Only clear session-level rules from the parent to prevent unintended leakage.
471 if (allowedTools !== undefined) {
472 toolPermissionContext = {
473 ...toolPermissionContext,
474 alwaysAllowRules: {
475 // Preserve SDK-level permissions from --allowedTools

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected