ummaya 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/bin/ummaya +10 -1
- package/bun.lock +180 -244
- package/npm-shrinkwrap.json +760 -1760
- package/package.json +39 -22
- package/prompts/manifest.yaml +1 -1
- package/prompts/system_v1.md +1 -0
- package/pyproject.toml +27 -2
- package/specs/2803-document-production-hardening/contracts/document-tools.schema.json +1043 -0
- package/src/ummaya/_canonical/__init__.py +2 -0
- package/src/ummaya/_canonical/baselines.yaml +113 -0
- package/src/ummaya/engine/engine.py +29 -132
- package/src/ummaya/evidence/__init__.py +21 -2
- package/src/ummaya/evidence/dataset_contract.py +193 -0
- package/src/ummaya/evidence/document_authoring_cases.py +33 -0
- package/src/ummaya/evidence/document_harness.py +313 -0
- package/src/ummaya/evidence/document_viewer_ux.py +391 -0
- package/src/ummaya/evidence/gates.py +70 -0
- package/src/ummaya/evidence/json_types.py +20 -0
- package/src/ummaya/evidence/models.py +88 -1
- package/src/ummaya/evidence/output_payload.py +89 -0
- package/src/ummaya/evidence/payload_documents.py +233 -0
- package/src/ummaya/evidence/route_contracts.py +224 -0
- package/src/ummaya/evidence/route_helpers.py +150 -0
- package/src/ummaya/evidence/runner.py +81 -212
- package/src/ummaya/evidence/source_provenance.py +246 -0
- package/src/ummaya/evidence/source_provenance_redaction.py +176 -0
- package/src/ummaya/evidence/tool_layer.py +39 -0
- package/src/ummaya/evidence/tool_layer_models.py +151 -0
- package/src/ummaya/ipc/adapter_manifest_emitter.py +26 -10
- package/src/ummaya/ipc/document_intent_normalization.py +185 -0
- package/src/ummaya/ipc/frame_schema.py +5 -5
- package/src/ummaya/ipc/route_diagnostics.py +73 -0
- package/src/ummaya/ipc/stdio.py +1109 -477
- package/src/ummaya/llm/client.py +102 -3
- package/src/ummaya/llm/config.py +8 -3
- package/src/ummaya/primitives/__init__.py +6 -2
- package/src/ummaya/primitives/delegation.py +1 -1
- package/src/ummaya/primitives/document.py +28 -0
- package/src/ummaya/settings.py +0 -3
- package/src/ummaya/tools/discovery_bridge.py +17 -1
- package/src/ummaya/tools/documents/__init__.py +297 -0
- package/src/ummaya/tools/documents/adapter_registry.py +487 -0
- package/src/ummaya/tools/documents/archive_container_probe.py +167 -0
- package/src/ummaya/tools/documents/artifact_store.py +454 -0
- package/src/ummaya/tools/documents/authoring.py +283 -0
- package/src/ummaya/tools/documents/baselines.py +132 -0
- package/src/ummaya/tools/documents/capability.py +331 -0
- package/src/ummaya/tools/documents/contracts.py +112 -0
- package/src/ummaya/tools/documents/conversion.py +521 -0
- package/src/ummaya/tools/documents/diff.py +275 -0
- package/src/ummaya/tools/documents/engines.py +163 -0
- package/src/ummaya/tools/documents/evaluation.py +291 -0
- package/src/ummaya/tools/documents/explicit_values.py +108 -0
- package/src/ummaya/tools/documents/fixtures.py +174 -0
- package/src/ummaya/tools/documents/format_completion_audit.py +471 -0
- package/src/ummaya/tools/documents/formats/__init__.py +2 -0
- package/src/ummaya/tools/documents/formats/archive.py +528 -0
- package/src/ummaya/tools/documents/formats/base.py +41 -0
- package/src/ummaya/tools/documents/formats/code_file.py +211 -0
- package/src/ummaya/tools/documents/formats/data_file.py +272 -0
- package/src/ummaya/tools/documents/formats/hwp.py +284 -0
- package/src/ummaya/tools/documents/formats/hwpx.py +1837 -0
- package/src/ummaya/tools/documents/formats/odf.py +435 -0
- package/src/ummaya/tools/documents/formats/ooxml.py +1030 -0
- package/src/ummaya/tools/documents/formats/passive.py +766 -0
- package/src/ummaya/tools/documents/formats/pdf.py +702 -0
- package/src/ummaya/tools/documents/formats/text_web.py +268 -0
- package/src/ummaya/tools/documents/hwp_conversion_probe.py +178 -0
- package/src/ummaya/tools/documents/hwp_direct_candidate.py +141 -0
- package/src/ummaya/tools/documents/inspection.py +289 -0
- package/src/ummaya/tools/documents/intake.py +1079 -0
- package/src/ummaya/tools/documents/legacy_office_promotion_probe.py +366 -0
- package/src/ummaya/tools/documents/models.py +1598 -0
- package/src/ummaya/tools/documents/odf_promotion_probe.py +167 -0
- package/src/ummaya/tools/documents/orchestrator.py +96 -0
- package/src/ummaya/tools/documents/passive_capability_probe.py +251 -0
- package/src/ummaya/tools/documents/patch.py +170 -0
- package/src/ummaya/tools/documents/pdfa_conformance.py +284 -0
- package/src/ummaya/tools/documents/pdfa_promotion_probe.py +198 -0
- package/src/ummaya/tools/documents/permissions.py +110 -0
- package/src/ummaya/tools/documents/planner.py +616 -0
- package/src/ummaya/tools/documents/registry.py +2733 -0
- package/src/ummaya/tools/documents/render.py +978 -0
- package/src/ummaya/tools/documents/render_comparison.py +113 -0
- package/src/ummaya/tools/documents/render_comparison_models.py +74 -0
- package/src/ummaya/tools/documents/render_comparison_regions.py +73 -0
- package/src/ummaya/tools/documents/render_comparison_style.py +161 -0
- package/src/ummaya/tools/documents/reread.py +157 -0
- package/src/ummaya/tools/documents/runtime_authoring.py +244 -0
- package/src/ummaya/tools/documents/runtime_authoring_bundle.py +76 -0
- package/src/ummaya/tools/documents/scorecard.py +184 -0
- package/src/ummaya/tools/documents/socratic_planner.py +193 -0
- package/src/ummaya/tools/documents/style.py +48 -0
- package/src/ummaya/tools/documents/tool_defs.py +523 -0
- package/src/ummaya/tools/documents/validate.py +347 -0
- package/src/ummaya/tools/executor.py +29 -0
- package/src/ummaya/tools/live_proxy.py +0 -3
- package/src/ummaya/tools/models.py +5 -1
- package/src/ummaya/tools/register_all.py +8 -0
- package/src/ummaya/tools/registry.py +10 -1
- package/src/ummaya/tools/routing/__init__.py +59 -0
- package/src/ummaya/tools/routing/builder.py +105 -0
- package/src/ummaya/tools/routing/cards.py +29 -0
- package/src/ummaya/tools/routing/decision_service.py +534 -0
- package/src/ummaya/tools/routing/decision_types.py +74 -0
- package/src/ummaya/tools/routing/feasibility.py +122 -0
- package/src/ummaya/tools/routing/intent.py +17 -0
- package/src/ummaya/tools/routing/intent_extractor.py +207 -0
- package/src/ummaya/tools/routing/intent_patterns.py +160 -0
- package/src/ummaya/tools/routing/intent_public_data.py +150 -0
- package/src/ummaya/tools/routing/intent_types.py +48 -0
- package/src/ummaya/tools/routing/lint.py +78 -0
- package/src/ummaya/tools/routing/metadata.py +174 -0
- package/src/ummaya/tools/routing/projection.py +340 -0
- package/src/ummaya/tools/routing/retrieval_policy.py +629 -0
- package/src/ummaya/tools/routing/schema.py +81 -0
- package/src/ummaya/tools/routing/types.py +96 -0
- package/src/ummaya/tools/routing_index.py +2 -2
- package/src/ummaya/tools/search.py +34 -746
- package/tests/fixtures/documents/public_forms/baselines.yaml +113 -0
- package/tui/bun.lock +126 -305
- package/tui/package.json +35 -22
- package/tui/src/.cc-byte-identical-whitelist.yaml +266 -0
- package/tui/src/QueryEngine.ts +12 -8
- package/tui/src/bridge/inboundAttachments.ts +3 -3
- package/tui/src/cli/handlers/auth.ts +3 -12
- package/tui/src/cli/handlers/mcp.tsx +0 -1
- package/tui/src/cli/print.ts +8 -9
- package/tui/src/commands/insights.ts +1 -1
- package/tui/src/commands/install-github-app/types.ts +8 -30
- package/tui/src/commands/plugin/types.ts +6 -28
- package/tui/src/commands/plugin/unifiedTypes.ts +4 -26
- package/tui/src/commands/rename/generateSessionName.ts +1 -1
- package/tui/src/components/Feedback.tsx +1 -1
- package/tui/src/components/LogoV2/EmergencyTip.tsx +11 -2
- package/tui/src/components/LogoV2/WelcomeV2.tsx +1 -3
- package/tui/src/components/ScrollKeybindingHandler.tsx +6 -6
- package/tui/src/components/Spinner/types.ts +6 -28
- package/tui/src/components/agents/generateAgent.ts +1 -1
- package/tui/src/components/agents/new-agent-creation/types.ts +4 -26
- package/tui/src/components/config/EnvSecretIsolatedEditor.tsx +1 -1
- package/tui/src/components/mcp/types.ts +16 -38
- package/tui/src/components/messages/AssistantToolUseMessage.tsx +3 -2
- package/tui/src/components/messages/UserCrossSessionMessage.ts +16 -4
- package/tui/src/components/messages/UserForkBoilerplateMessage.ts +16 -4
- package/tui/src/components/messages/UserGitHubWebhookMessage.ts +16 -4
- package/tui/src/components/messages/UserToolResultMessage/utils.tsx +3 -2
- package/tui/src/components/permissions/MonitorPermissionRequest/MonitorPermissionRequest.ts +9 -4
- package/tui/src/components/permissions/ReviewArtifactPermissionRequest/ReviewArtifactPermissionRequest.ts +9 -4
- package/tui/src/components/primitive/DocumentSocraticReviewBlock.tsx +129 -0
- package/tui/src/components/primitive/DocumentToolResultCard.tsx +224 -0
- package/tui/src/components/primitive/documentSocraticReview.ts +215 -0
- package/tui/src/components/primitive/index.tsx +43 -1
- package/tui/src/components/primitive/types.ts +137 -0
- package/tui/src/components/ui/option.ts +4 -26
- package/tui/src/constants/common.ts +0 -2
- package/tui/src/constants/prompts.ts +4 -3
- package/tui/src/constants/querySource.ts +4 -26
- package/tui/src/entrypoints/sdk/controlTypes.ts +26 -48
- package/tui/src/entrypoints/sdk/coreTypes.generated.ts +3 -25
- package/tui/src/entrypoints/sdk/runtimeTypes.ts +38 -60
- package/tui/src/entrypoints/sdk/sdkUtilityTypes.ts +4 -26
- package/tui/src/entrypoints/sdk/settingsTypes.generated.ts +3 -25
- package/tui/src/entrypoints/sdk/toolTypes.ts +3 -25
- package/tui/src/hooks/toolPermission/handlers/interactiveHandler.ts +10 -0
- package/tui/src/hooks/useApiKeyVerification.ts +1 -1
- package/tui/src/hooks/useVirtualScroll.ts +1 -1
- package/tui/src/ink/ink.tsx +33 -14
- package/tui/src/ink/reconciler.ts +2 -3
- package/tui/src/ink/render-to-screen.ts +30 -10
- package/tui/src/ipc/bridge.ts +62 -15
- package/tui/src/ipc/bridgeSingleton.ts +5 -1
- package/tui/src/ipc/codec.ts +3 -3
- package/tui/src/ipc/frames.generated.ts +12 -12
- package/tui/src/ipc/llmClient.ts +151 -27
- package/tui/src/ipc/schema/frame.schema.json +1 -1
- package/tui/src/keybindings/defaultBindings.ts +4 -0
- package/tui/src/main.tsx +32 -15
- package/tui/src/native-ts/file-index/index.ts +33 -3
- package/tui/src/observability/surface.ts +2 -2
- package/tui/src/probes/toolRegistryProbe.tsx +3 -1
- package/tui/src/projectOnboardingState.ts +7 -6
- package/tui/src/query/chatMessageTypes.ts +18 -0
- package/tui/src/query/chatMessagesBuilder.ts +1 -1
- package/tui/src/query/deps.ts +1 -1
- package/tui/src/query/messageGuards.ts +106 -0
- package/tui/src/query/publicDataTerminalRepair.ts +384 -0
- package/tui/src/query/run.ts +1075 -0
- package/tui/src/query/supportBoundary.ts +168 -0
- package/tui/src/query/toolResultErrors.ts +103 -0
- package/tui/src/query/toolRunner.ts +687 -0
- package/tui/src/query/unavailableToolRepair.ts +118 -0
- package/tui/src/query.ts +9 -2186
- package/tui/src/screens/REPL.tsx +40 -29
- package/tui/src/services/api/adapterManifest.ts +4 -0
- package/tui/src/services/api/backendChat/events.ts +117 -0
- package/tui/src/services/api/backendChat/finalMessage.ts +40 -0
- package/tui/src/services/api/backendChat/frame.ts +9 -0
- package/tui/src/services/api/backendChat/streaming.ts +430 -0
- package/tui/src/services/api/backendChat/types.ts +62 -0
- package/tui/src/services/api/backendChat.ts +1 -0
- package/tui/src/services/api/client.ts +65 -2
- package/tui/src/services/api/errorUtils.ts +5 -5
- package/tui/src/services/api/errors.ts +1 -1
- package/tui/src/services/api/logging.ts +1 -1
- package/tui/src/services/api/ummaya/evidence.ts +194 -0
- package/tui/src/services/api/ummaya/messages.ts +255 -0
- package/tui/src/services/api/ummaya/nonStreaming.ts +66 -0
- package/tui/src/services/api/ummaya/provider.ts +200 -0
- package/tui/src/services/api/ummaya/reasoning.ts +24 -0
- package/tui/src/services/api/ummaya/request.ts +200 -0
- package/tui/src/services/api/ummaya/selectionContext.ts +240 -0
- package/tui/src/services/api/ummaya/streaming.ts +365 -0
- package/tui/src/services/api/ummaya/streamingPayload.ts +129 -0
- package/tui/src/services/api/ummaya/streamingReader.ts +40 -0
- package/tui/src/services/api/ummaya/toolSelection.ts +217 -0
- package/tui/src/services/api/ummaya/types.ts +110 -0
- package/tui/src/services/api/ummaya/usage.ts +30 -0
- package/tui/src/services/api/ummaya.ts +26 -418
- package/tui/src/services/api/withRetry.ts +1 -1
- package/tui/src/services/awaySummary.ts +2 -2
- package/tui/src/services/claudeAiLimits.ts +1 -1
- package/tui/src/services/compact/autoCompact.ts +1 -1
- package/tui/src/services/compact/compact.ts +1 -1
- package/tui/src/services/lsp/types.ts +8 -30
- package/tui/src/services/tips/types.ts +6 -28
- package/tui/src/services/tokenEstimation.ts +1 -1
- package/tui/src/services/toolRegistry/bootGuard.ts +5 -5
- package/tui/src/services/toolUseSummary/toolUseSummaryGenerator.ts +1 -1
- package/tui/src/services/tools/toolExecution.ts +94 -1
- package/tui/src/store/pendingPermissionSlot.ts +1 -1
- package/tui/src/store/session-store.ts +10 -36
- package/tui/src/stubs/any-stub.ts +15 -10
- package/tui/src/stubs/color-diff-napi.ts +37 -23
- package/tui/src/stubs/globals.d.ts +3 -3
- package/tui/src/stubs/macro-preload.ts +23 -12
- package/tui/src/tools/AdapterTool/AdapterTool.ts +1207 -714
- package/tui/src/tools/AdapterTool/routeDiagnostics.ts +75 -0
- package/tui/src/tools/AgentTool/AgentTool.tsx +84 -1371
- package/tui/src/tools/AgentTool/agentToolHandoff.ts +114 -0
- package/tui/src/tools/AgentTool/agentToolPartialResult.ts +16 -0
- package/tui/src/tools/AgentTool/agentToolProgress.ts +32 -0
- package/tui/src/tools/AgentTool/agentToolResolver.ts +161 -0
- package/tui/src/tools/AgentTool/agentToolResult.ts +163 -0
- package/tui/src/tools/AgentTool/agentToolUtils.ts +14 -686
- package/tui/src/tools/AgentTool/asyncAgentLifecycle.ts +208 -0
- package/tui/src/tools/AgentTool/asyncLifecycle.ts +153 -0
- package/tui/src/tools/AgentTool/backgroundedCompletion.ts +126 -0
- package/tui/src/tools/AgentTool/backgroundedLifecycle.ts +174 -0
- package/tui/src/tools/AgentTool/foregroundBackground.ts +83 -0
- package/tui/src/tools/AgentTool/foregroundDrain.tsx +133 -0
- package/tui/src/tools/AgentTool/foregroundFinalize.ts +98 -0
- package/tui/src/tools/AgentTool/foregroundLifecycle.tsx +237 -0
- package/tui/src/tools/AgentTool/foregroundProgress.tsx +169 -0
- package/tui/src/tools/AgentTool/foregroundTask.ts +89 -0
- package/tui/src/tools/AgentTool/forkSubagent.ts +1 -12
- package/tui/src/tools/AgentTool/forkSubagentGate.ts +34 -0
- package/tui/src/tools/AgentTool/launchRouting.ts +203 -0
- package/tui/src/tools/AgentTool/lifecycle.ts +244 -0
- package/tui/src/tools/AgentTool/mcpRouting.ts +73 -0
- package/tui/src/tools/AgentTool/orchestrationSupport.ts +70 -0
- package/tui/src/tools/AgentTool/permissions.ts +39 -0
- package/tui/src/tools/AgentTool/promptSetup.ts +181 -0
- package/tui/src/tools/AgentTool/remoteRouting.ts +62 -0
- package/tui/src/tools/AgentTool/resultMapping.ts +116 -0
- package/tui/src/tools/AgentTool/resumeAgent.ts +39 -107
- package/tui/src/tools/AgentTool/resumeAgentHelpers.ts +140 -0
- package/tui/src/tools/AgentTool/runAgent.ts +1 -1
- package/tui/src/tools/AgentTool/runtimeConfig.ts +57 -0
- package/tui/src/tools/AgentTool/schemas.ts +196 -0
- package/tui/src/tools/AgentTool/sourceVerificationPropagation.ts +263 -0
- package/tui/src/tools/AgentTool/worktreeLifecycle.ts +105 -0
- package/tui/src/tools/AskUserQuestionTool/AskUserQuestionTool.tsx +174 -202
- package/tui/src/tools/BashTool/BashTool.tsx +71 -1072
- package/tui/src/tools/BashTool/bashCommandHelpers.ts +12 -12
- package/tui/src/tools/BashTool/bashPermissions/astPreflight.ts +173 -0
- package/tui/src/tools/BashTool/bashPermissions/classifierChecks.ts +199 -0
- package/tui/src/tools/BashTool/bashPermissions/compoundGuards.ts +53 -0
- package/tui/src/tools/BashTool/bashPermissions/constants.ts +99 -0
- package/tui/src/tools/BashTool/bashPermissions/index.ts +38 -0
- package/tui/src/tools/BashTool/bashPermissions/legacyMisparsing.ts +62 -0
- package/tui/src/tools/BashTool/bashPermissions/main.ts +135 -0
- package/tui/src/tools/BashTool/bashPermissions/normalizedCommands.ts +33 -0
- package/tui/src/tools/BashTool/bashPermissions/operatorFlow.ts +98 -0
- package/tui/src/tools/BashTool/bashPermissions/permissionChecks.ts +200 -0
- package/tui/src/tools/BashTool/bashPermissions/prefixSuggestions.ts +88 -0
- package/tui/src/tools/BashTool/bashPermissions/promptClassifierRules.ts +125 -0
- package/tui/src/tools/BashTool/bashPermissions/ruleDelegates.ts +19 -0
- package/tui/src/tools/BashTool/bashPermissions/ruleMatching.ts +145 -0
- package/tui/src/tools/BashTool/bashPermissions/sandboxAutoAllow.ts +75 -0
- package/tui/src/tools/BashTool/bashPermissions/subcommandFlow.ts +205 -0
- package/tui/src/tools/BashTool/bashPermissions/subcommandGuards.ts +73 -0
- package/tui/src/tools/BashTool/bashPermissions/subcommandResultHelpers.ts +116 -0
- package/tui/src/tools/BashTool/bashPermissions/types.ts +26 -0
- package/tui/src/tools/BashTool/bashPermissions/wrapperStripping.ts +139 -0
- package/tui/src/tools/BashTool/bashPermissions.ts +26 -2621
- package/tui/src/tools/BashTool/call.ts +202 -0
- package/tui/src/tools/BashTool/callLoader.ts +35 -0
- package/tui/src/tools/BashTool/commandClassification.ts +151 -0
- package/tui/src/tools/BashTool/commandClassificationLoader.ts +40 -0
- package/tui/src/tools/BashTool/cwdReset.ts +33 -0
- package/tui/src/tools/BashTool/lineTruncation.ts +11 -0
- package/tui/src/tools/BashTool/modeValidation.ts +13 -1
- package/tui/src/tools/BashTool/outputPersistence.ts +42 -0
- package/tui/src/tools/BashTool/permissionClassification.ts +66 -0
- package/tui/src/tools/BashTool/permissionLoader.ts +44 -0
- package/tui/src/tools/BashTool/resultLoader.ts +29 -0
- package/tui/src/tools/BashTool/resultMapping.ts +83 -0
- package/tui/src/tools/BashTool/sandboxPolicy.ts +79 -0
- package/tui/src/tools/BashTool/schemas.ts +65 -0
- package/tui/src/tools/BashTool/sedEditExecution.ts +59 -0
- package/tui/src/tools/BashTool/shellExecution.tsx +245 -0
- package/tui/src/tools/BashTool/shellOutputUtils.ts +85 -0
- package/tui/src/tools/BashTool/shellPermissionGauntlet.ts +97 -0
- package/tui/src/tools/BashTool/uiLoader.ts +37 -0
- package/tui/src/tools/BriefTool/upload.ts +1 -1
- package/tui/src/tools/CalculatorTool/parser.ts +2 -2
- package/tui/src/tools/DocumentPrimitive/DocumentPrimitive.ts +262 -0
- package/tui/src/tools/DocumentPrimitive/dispatchNormalization.ts +270 -0
- package/tui/src/tools/DocumentPrimitive/documentDestinationPath.ts +18 -0
- package/tui/src/tools/DocumentPrimitive/documentMutationGuard.ts +22 -0
- package/tui/src/tools/DocumentPrimitive/documentPatchNormalization.ts +248 -0
- package/tui/src/tools/DocumentPrimitive/documentSourceVerification.ts +245 -0
- package/tui/src/tools/DocumentPrimitive/documentSourceVerificationFields.ts +103 -0
- package/tui/src/tools/DocumentPrimitive/modelVisibleOutput.ts +40 -0
- package/tui/src/tools/DocumentPrimitive/prompt.ts +35 -0
- package/tui/src/tools/FileEditTool/FileEditTool.ts +9 -507
- package/tui/src/tools/FileEditTool/call.ts +228 -0
- package/tui/src/tools/FileEditTool/validateInput.ts +196 -0
- package/tui/src/tools/FileReadTool/imageProcessor.ts +13 -0
- package/tui/src/tools/FileWriteTool/FileWriteTool.ts +7 -300
- package/tui/src/tools/FileWriteTool/call.ts +223 -0
- package/tui/src/tools/FileWriteTool/validateInput.ts +80 -0
- package/tui/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.ts +19 -3
- package/tui/src/tools/LookupPrimitive/LookupPrimitive.ts +25 -32
- package/tui/src/tools/LookupPrimitive/prompt.ts +0 -2
- package/tui/src/tools/MCPTool/trustPolicy.ts +118 -0
- package/tui/src/tools/McpAuthTool/McpAuthTool.ts +21 -3
- package/tui/src/tools/NotebookEditTool/NotebookEditTool.ts +7 -326
- package/tui/src/tools/NotebookEditTool/call.ts +254 -0
- package/tui/src/tools/NotebookEditTool/notebookModel.ts +51 -0
- package/tui/src/tools/NotebookEditTool/validateInput.ts +142 -0
- package/tui/src/tools/PowerShellTool/PowerShellTool.tsx +46 -937
- package/tui/src/tools/PowerShellTool/acceptEditsCommandValidation.ts +162 -0
- package/tui/src/tools/PowerShellTool/call.ts +179 -0
- package/tui/src/tools/PowerShellTool/callLoader.ts +37 -0
- package/tui/src/tools/PowerShellTool/commandClassification.ts +86 -0
- package/tui/src/tools/PowerShellTool/modeValidation.ts +25 -332
- package/tui/src/tools/PowerShellTool/outputPersistence.ts +42 -0
- package/tui/src/tools/PowerShellTool/permissionClassification.ts +28 -0
- package/tui/src/tools/PowerShellTool/resultLoader.ts +31 -0
- package/tui/src/tools/PowerShellTool/resultMapping.ts +75 -0
- package/tui/src/tools/PowerShellTool/schemas.ts +40 -0
- package/tui/src/tools/PowerShellTool/shellExecution.tsx +258 -0
- package/tui/src/tools/PowerShellTool/symlinkModeValidation.ts +44 -0
- package/tui/src/tools/PowerShellTool/uiLoader.ts +37 -0
- package/tui/src/tools/PowerShellTool/validation.ts +39 -0
- package/tui/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.ts +19 -3
- package/tui/src/tools/ResolveLocationPrimitive/ResolveLocationPrimitive.ts +1 -11
- package/tui/src/tools/ResolveLocationPrimitive/prompt.ts +2 -6
- package/tui/src/tools/SkillTool/SkillTool.ts +2 -2
- package/tui/src/tools/SubmitPrimitive/SubmitPrimitive.ts +27 -10
- package/tui/src/tools/TaskCreateTool/TaskCreateTool.ts +16 -2
- package/tui/src/tools/TaskGetTool/TaskGetTool.ts +23 -3
- package/tui/src/tools/TaskListTool/TaskListTool.ts +22 -4
- package/tui/src/tools/TaskOutputTool/TaskOutputTool.tsx +46 -547
- package/tui/src/tools/TaskOutputTool/lookup.ts +216 -0
- package/tui/src/tools/TaskOutputTool/render.tsx +257 -0
- package/tui/src/tools/TaskOutputTool/schemas.ts +55 -0
- package/tui/src/tools/TaskOutputTool/serialization.ts +36 -0
- package/tui/src/tools/TaskStopTool/TaskStopTool.ts +10 -0
- package/tui/src/tools/TaskUpdateTool/TaskUpdateTool.ts +14 -364
- package/tui/src/tools/TaskUpdateTool/completion.ts +62 -0
- package/tui/src/tools/TaskUpdateTool/schemas.ts +62 -0
- package/tui/src/tools/TaskUpdateTool/serialization.ts +46 -0
- package/tui/src/tools/TaskUpdateTool/statusUpdate.ts +247 -0
- package/tui/src/tools/TodoWriteTool/TodoWriteTool.ts +21 -2
- package/tui/src/tools/ToolSearchTool/ToolSearchTool.ts +21 -302
- package/tui/src/tools/ToolSearchTool/ccSupportTools.ts +223 -0
- package/tui/src/tools/ToolSearchTool/descriptionCache.ts +50 -0
- package/tui/src/tools/ToolSearchTool/keywordSearch.ts +216 -0
- package/tui/src/tools/ToolSearchTool/prompt.ts +10 -4
- package/tui/src/tools/ToolSearchTool/resultMapping.ts +30 -0
- package/tui/src/tools/ToolSearchTool/schemas.ts +30 -0
- package/tui/src/tools/ToolSearchTool/searchPool.ts +47 -0
- package/tui/src/tools/ToolSearchTool/supportIntentHints.ts +140 -0
- package/tui/src/tools/TranslateTool/TranslateTool.ts +1 -1
- package/tui/src/tools/VerifyPrimitive/VerifyPrimitive.ts +2 -1
- package/tui/src/tools/WebFetchTool/WebFetchTool.ts +43 -138
- package/tui/src/tools/WebFetchTool/call.ts +227 -0
- package/tui/src/tools/WebFetchTool/resolvedAddressSafety.ts +78 -0
- package/tui/src/tools/WebFetchTool/sourceVerification.ts +204 -0
- package/tui/src/tools/WebFetchTool/types.ts +23 -0
- package/tui/src/tools/WebFetchTool/urlSafety.ts +181 -0
- package/tui/src/tools/WebFetchTool/utils.ts +1 -1
- package/tui/src/tools/WebSearchTool/UI.tsx +0 -1
- package/tui/src/tools/WebSearchTool/WebSearchTool.ts +9 -313
- package/tui/src/tools/WebSearchTool/call.ts +33 -0
- package/tui/src/tools/WebSearchTool/responseMapping.ts +190 -0
- package/tui/src/tools/WebSearchTool/resultBlock.ts +47 -0
- package/tui/src/tools/WebSearchTool/schemas.ts +47 -0
- package/tui/src/tools/WebSearchTool/toolSchema.ts +12 -0
- package/tui/src/tools/WorkspaceToolAdapter/WorkspaceToolAdapter.ts +79 -0
- package/tui/src/tools/WorkspaceToolAdapter/allowedRootPolicy.ts +85 -0
- package/tui/src/tools/WorkspaceToolAdapter/documentFormatGuards.ts +73 -0
- package/tui/src/tools/WorkspaceToolAdapter/inputNormalization.ts +105 -0
- package/tui/src/tools/WorkspaceToolAdapter/mcpExposurePolicy.ts +64 -0
- package/tui/src/tools/WorkspaceToolAdapter/toolDefFactory.ts +215 -0
- package/tui/src/tools/WorkspaceToolAdapter/toolNames.ts +6 -0
- package/tui/src/tools/WorkspaceToolAdapter/workspacePolicy.ts +15 -0
- package/tui/src/tools/_shared/dispatchPrimitive.ts +6 -6
- package/tui/src/tools/_shared/documentChangeToPatch.ts +125 -0
- package/tui/src/tools/_shared/documentDispatchArguments.ts +87 -0
- package/tui/src/tools/_shared/documentPrimitiveTimeout.ts +13 -0
- package/tui/src/tools/_shared/documentToolResultRender.ts +98 -0
- package/tui/src/tools/_shared/pendingCallRegistry.ts +1 -6
- package/tui/src/tools/_shared/rootPrimitiveInput.ts +1 -0
- package/tui/src/tools/_shared/toolChoiceRepair/documentCompletionPatterns.ts +58 -0
- package/tui/src/tools/_shared/toolChoiceRepair/documentCompletionPrompt.ts +271 -0
- package/tui/src/tools/_shared/toolChoiceRepair/documentRepair.ts +452 -0
- package/tui/src/tools/_shared/toolChoiceRepair/messageAccess.ts +80 -0
- package/tui/src/tools/_shared/toolChoiceRepair/publicDataRepair.ts +92 -0
- package/tui/src/tools/_shared/toolChoiceRepair/supportRepair.ts +135 -0
- package/tui/src/tools/_shared/toolChoiceRepair.ts +55 -860
- package/tui/src/tools/shared/mockDisclaimer.ts +1 -1
- package/tui/src/tools.ts +39 -190
- package/tui/src/types/fileSuggestion.ts +4 -26
- package/tui/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +186 -148
- package/tui/src/types/generated/events_mono/common/v1/auth.ts +25 -11
- package/tui/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +47 -30
- package/tui/src/types/generated/google/protobuf/timestamp.ts +21 -7
- package/tui/src/types/message.ts +80 -102
- package/tui/src/types/messageQueueTypes.ts +6 -28
- package/tui/src/types/notebook.ts +16 -38
- package/tui/src/types/statusLine.ts +4 -26
- package/tui/src/types/tools.ts +24 -46
- package/tui/src/types/utils.ts +6 -28
- package/tui/src/upstreamproxy/relay.ts +7 -3
- package/tui/src/upstreamproxy/upstreamproxy.ts +1 -1
- package/tui/src/utils/assistantMessageFactories.ts +9 -3
- package/tui/src/utils/auth.ts +129 -139
- package/tui/src/utils/bash/ast.ts +23 -23
- package/tui/src/utils/bash/bashParser.ts +5 -5
- package/tui/src/utils/billing.ts +1 -1
- package/tui/src/utils/claudeDesktop.ts +4 -4
- package/tui/src/utils/collapseReadSearch.ts +3 -3
- package/tui/src/utils/cronTasks.ts +1 -1
- package/tui/src/utils/execFileNoThrow.ts +1 -1
- package/tui/src/utils/filePersistence/types.ts +16 -38
- package/tui/src/utils/forkedAgent.ts +1 -1
- package/tui/src/utils/gracefulShutdown.ts +4 -4
- package/tui/src/utils/heapDumpService.ts +12 -8
- package/tui/src/utils/hooks/apiQueryHookHelper.ts +1 -1
- package/tui/src/utils/hooks/execPromptHook.ts +1 -1
- package/tui/src/utils/hooks/skillImprovement.ts +1 -1
- package/tui/src/utils/mcp/dateTimeParser.ts +1 -1
- package/tui/src/utils/messages.ts +18 -0
- package/tui/src/utils/migrateSessions.ts +3 -3
- package/tui/src/utils/model/model.ts +6 -6
- package/tui/src/utils/permissions/yoloClassifier.ts +1 -1
- package/tui/src/utils/plugins/headlessPluginInstall.ts +1 -1
- package/tui/src/utils/plugins/mcpPluginIntegration.ts +1 -1
- package/tui/src/utils/plugins/mcpbHandler.ts +1 -1
- package/tui/src/utils/plugins/pluginLoader.ts +8 -8
- package/tui/src/utils/protectedNamespace.ts +5 -3
- package/tui/src/utils/rawJsonToolCall.ts +242 -0
- package/tui/src/utils/ripgrep.ts +16 -7
- package/tui/src/utils/sessionTitle.ts +1 -1
- package/tui/src/utils/settings/permissionValidation.ts +14 -2
- package/tui/src/utils/shell/prefix.ts +1 -1
- package/tui/src/utils/sideQuery.ts +1 -1
- package/tui/src/utils/systemThemeWatcher.ts +13 -3
- package/tui/src/utils/teleport.tsx +1 -1
- package/uv.lock +426 -45
- package/tui/src/services/api/claude.ts +0 -3540
- package/tui/src/tools/_shared/directPublicDataGuard.ts +0 -362
- package/tui/src/tools/_shared/kmaAnalysisGuard.ts +0 -197
- package/tui/src/tools/_shared/kmaAviationGuard.ts +0 -70
- package/tui/src/tools/_shared/nmcAedGuard.ts +0 -234
- package/tui/src/tools/_shared/protectedCheckGuard.ts +0 -207
- package/tui/src/tools/_shared/textToolCallGuard.ts +0 -91
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { feature } from 'bun:bundle'
|
|
2
|
+
import { z } from 'zod/v4'
|
|
3
|
+
import type { AgentToolProgress, ShellProgress } from '../../types/tools.js'
|
|
4
|
+
import type { PermissionMode } from '../../types/permissions.js'
|
|
5
|
+
import { lazySchema } from '../../utils/lazySchema.js'
|
|
6
|
+
import { permissionModeSchema } from '../../utils/permissions/PermissionMode.js'
|
|
7
|
+
import { isForkSubagentEnabled } from './forkSubagentGate.js'
|
|
8
|
+
import type { AgentSupportMetadata } from './orchestrationSupport.js'
|
|
9
|
+
import { agentToolResultSchema, type AgentToolResult } from './agentToolResult.js'
|
|
10
|
+
import { isAntBuild, isBackgroundTasksDisabled } from './runtimeConfig.js'
|
|
11
|
+
|
|
12
|
+
const baseInputSchema = lazySchema(() =>
|
|
13
|
+
z.object({
|
|
14
|
+
description: z.string().describe('A short (3-5 word) description of the task'),
|
|
15
|
+
prompt: z.string().describe('The task for the agent to perform'),
|
|
16
|
+
subagent_type: z
|
|
17
|
+
.string()
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('The type of specialized agent to use for this task'),
|
|
20
|
+
model: z
|
|
21
|
+
.enum(['sonnet', 'opus', 'haiku'])
|
|
22
|
+
.optional()
|
|
23
|
+
.describe(
|
|
24
|
+
"Optional model override for this agent. Takes precedence over the agent definition's model frontmatter. If omitted, uses the agent definition's model, or inherits from the parent.",
|
|
25
|
+
),
|
|
26
|
+
run_in_background: z
|
|
27
|
+
.boolean()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe(
|
|
30
|
+
'Set to true to run this agent in the background. You will be notified when it completes.',
|
|
31
|
+
),
|
|
32
|
+
}),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const fullInputSchema = lazySchema(() => {
|
|
36
|
+
const multiAgentInputSchema = z.object({
|
|
37
|
+
name: z
|
|
38
|
+
.string()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe(
|
|
41
|
+
'Name for the spawned agent. Makes it addressable via SendMessage({to: name}) while running.',
|
|
42
|
+
),
|
|
43
|
+
team_name: z
|
|
44
|
+
.string()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Team name for spawning. Uses current team context if omitted.'),
|
|
47
|
+
mode: permissionModeSchema()
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Permission mode for spawned teammate (e.g., "plan" to require plan approval).'),
|
|
50
|
+
})
|
|
51
|
+
return baseInputSchema()
|
|
52
|
+
.merge(multiAgentInputSchema)
|
|
53
|
+
.extend({
|
|
54
|
+
isolation: (isAntBuild()
|
|
55
|
+
? z.enum(['worktree', 'remote'])
|
|
56
|
+
: z.enum(['worktree'])
|
|
57
|
+
)
|
|
58
|
+
.optional()
|
|
59
|
+
.describe(
|
|
60
|
+
isAntBuild()
|
|
61
|
+
? 'Isolation mode. "worktree" creates a temporary git worktree so the agent works on an isolated copy of the repo. "remote" launches the agent in a remote CCR environment (always runs in background).'
|
|
62
|
+
: 'Isolation mode. "worktree" creates a temporary git worktree so the agent works on an isolated copy of the repo.',
|
|
63
|
+
),
|
|
64
|
+
cwd: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe(
|
|
68
|
+
'Absolute path to run the agent in. Overrides the working directory for all filesystem and shell operations within this agent. Mutually exclusive with isolation: "worktree".',
|
|
69
|
+
),
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export const inputSchema = () => {
|
|
74
|
+
const schema = feature('KAIROS')
|
|
75
|
+
? fullInputSchema()
|
|
76
|
+
: fullInputSchema().omit({ cwd: true })
|
|
77
|
+
|
|
78
|
+
// Keep the final feature-gated view uncached. Fork availability depends on
|
|
79
|
+
// session state, and memoizing this wrapper lets the first schema access
|
|
80
|
+
// leak field visibility into later accesses in the same process.
|
|
81
|
+
return isBackgroundTasksDisabled || isForkSubagentEnabled()
|
|
82
|
+
? schema.omit({ run_in_background: true })
|
|
83
|
+
: schema
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type InputSchema = ReturnType<typeof inputSchema>
|
|
87
|
+
|
|
88
|
+
export type AgentToolInput = z.infer<ReturnType<typeof baseInputSchema>> & {
|
|
89
|
+
readonly name?: string
|
|
90
|
+
readonly team_name?: string
|
|
91
|
+
readonly mode?: PermissionMode
|
|
92
|
+
readonly isolation?: 'worktree' | 'remote'
|
|
93
|
+
readonly cwd?: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const outputSchema = lazySchema(() => {
|
|
97
|
+
const syncOutputSchema = agentToolResultSchema().extend({
|
|
98
|
+
status: z.literal('completed'),
|
|
99
|
+
prompt: z.string(),
|
|
100
|
+
evidenceJoinKey: z.string(),
|
|
101
|
+
parentToolUseId: z.string(),
|
|
102
|
+
resumeToken: z.string(),
|
|
103
|
+
permissionFlow: z.literal('coordinator_parent_round_trip'),
|
|
104
|
+
})
|
|
105
|
+
const asyncOutputSchema = z.object({
|
|
106
|
+
status: z.literal('async_launched'),
|
|
107
|
+
agentId: z.string().describe('The ID of the async agent'),
|
|
108
|
+
description: z.string().describe('The description of the task'),
|
|
109
|
+
prompt: z.string().describe('The prompt for the agent'),
|
|
110
|
+
outputFile: z.string().describe('Path to the output file for checking agent progress'),
|
|
111
|
+
canReadOutputFile: z
|
|
112
|
+
.boolean()
|
|
113
|
+
.optional()
|
|
114
|
+
.describe('Whether the calling agent has Read/Bash tools to check progress'),
|
|
115
|
+
evidenceJoinKey: z.string(),
|
|
116
|
+
parentToolUseId: z.string(),
|
|
117
|
+
resumeToken: z.string(),
|
|
118
|
+
permissionFlow: z.literal('coordinator_parent_round_trip'),
|
|
119
|
+
})
|
|
120
|
+
return z.union([syncOutputSchema, asyncOutputSchema])
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
export type OutputSchema = ReturnType<typeof outputSchema>
|
|
124
|
+
export type Progress = AgentToolProgress | ShellProgress
|
|
125
|
+
|
|
126
|
+
export type AgentToolProgressCallback = (event: {
|
|
127
|
+
readonly toolUseID: string
|
|
128
|
+
readonly data: Progress
|
|
129
|
+
}) => void
|
|
130
|
+
|
|
131
|
+
export type WorktreeResult = {
|
|
132
|
+
readonly worktreePath?: string
|
|
133
|
+
readonly worktreeBranch?: string
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type CompletedAgentOutput = AgentToolResult &
|
|
137
|
+
AgentSupportMetadata &
|
|
138
|
+
WorktreeResult & {
|
|
139
|
+
readonly status: 'completed'
|
|
140
|
+
readonly prompt: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type AsyncLaunchedOutput = AgentSupportMetadata & {
|
|
144
|
+
readonly isAsync?: true
|
|
145
|
+
readonly status: 'async_launched'
|
|
146
|
+
readonly agentId: string
|
|
147
|
+
readonly description: string
|
|
148
|
+
readonly prompt: string
|
|
149
|
+
readonly outputFile: string
|
|
150
|
+
readonly canReadOutputFile?: boolean
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type TeammateSpawnedOutput = AgentSupportMetadata & {
|
|
154
|
+
readonly status: 'teammate_spawned'
|
|
155
|
+
readonly prompt: string
|
|
156
|
+
readonly teammate_id: string
|
|
157
|
+
readonly agent_id: string
|
|
158
|
+
readonly agent_type?: string
|
|
159
|
+
readonly model?: string
|
|
160
|
+
readonly name: string
|
|
161
|
+
readonly color?: string
|
|
162
|
+
readonly tmux_session_name: string
|
|
163
|
+
readonly tmux_window_name: string
|
|
164
|
+
readonly tmux_pane_id: string
|
|
165
|
+
readonly team_name?: string
|
|
166
|
+
readonly is_splitpane?: boolean
|
|
167
|
+
readonly plan_mode_required?: boolean
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type RemoteLaunchedOutput = {
|
|
171
|
+
readonly status: 'remote_launched'
|
|
172
|
+
readonly taskId: string
|
|
173
|
+
readonly sessionUrl: string
|
|
174
|
+
readonly description: string
|
|
175
|
+
readonly prompt: string
|
|
176
|
+
readonly outputFile: string
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type AgentToolOutput =
|
|
180
|
+
| CompletedAgentOutput
|
|
181
|
+
| AsyncLaunchedOutput
|
|
182
|
+
| TeammateSpawnedOutput
|
|
183
|
+
| RemoteLaunchedOutput
|
|
184
|
+
|
|
185
|
+
export type AgentToolCallResult = {
|
|
186
|
+
readonly data: AgentToolOutput
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type AgentLifecycleMetadata = {
|
|
190
|
+
readonly prompt: string
|
|
191
|
+
readonly resolvedAgentModel: string
|
|
192
|
+
readonly isBuiltInAgent: boolean
|
|
193
|
+
readonly startTime: number
|
|
194
|
+
readonly agentType: string
|
|
195
|
+
readonly isAsync: boolean
|
|
196
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type { Message as MessageType } from '../../types/message.js'
|
|
2
|
+
import {
|
|
3
|
+
buildSourceVerification,
|
|
4
|
+
sourceVerificationSchema,
|
|
5
|
+
type SourceVerification,
|
|
6
|
+
type SourceVerificationEvidence,
|
|
7
|
+
} from '../WebFetchTool/sourceVerification.js'
|
|
8
|
+
import { WEB_FETCH_TOOL_NAME } from '../WebFetchTool/prompt.js'
|
|
9
|
+
import { WEB_SEARCH_TOOL_NAME } from '../WebSearchTool/prompt.js'
|
|
10
|
+
|
|
11
|
+
const MAX_PROPAGATED_SOURCE_EVIDENCE = 20
|
|
12
|
+
|
|
13
|
+
type TrustedSourceToolName =
|
|
14
|
+
| typeof WEB_FETCH_TOOL_NAME
|
|
15
|
+
| typeof WEB_SEARCH_TOOL_NAME
|
|
16
|
+
|
|
17
|
+
type TrustedToolResultText = {
|
|
18
|
+
readonly text: string
|
|
19
|
+
readonly toolName: TrustedSourceToolName
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type SourceEvidenceDraft = {
|
|
23
|
+
toolId?: string
|
|
24
|
+
sourceUrl?: string | null
|
|
25
|
+
title?: string | null
|
|
26
|
+
observedAt?: string
|
|
27
|
+
citationHandle?: string
|
|
28
|
+
blockedOrUsed?: SourceVerificationEvidence['blockedOrUsed']
|
|
29
|
+
trust?: SourceVerificationEvidence['trust']
|
|
30
|
+
promptInjection?: SourceVerificationEvidence['promptInjection']
|
|
31
|
+
redacted?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseNullableField(value: string): string | null {
|
|
35
|
+
return value === 'none' ? null : value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseBlockedOrUsed(
|
|
39
|
+
value: string,
|
|
40
|
+
): SourceVerificationEvidence['blockedOrUsed'] | undefined {
|
|
41
|
+
switch (value) {
|
|
42
|
+
case 'blocked':
|
|
43
|
+
case 'needs_input':
|
|
44
|
+
return value
|
|
45
|
+
default:
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parsePromptInjection(
|
|
51
|
+
value: string,
|
|
52
|
+
): SourceVerificationEvidence['promptInjection'] | undefined {
|
|
53
|
+
switch (value) {
|
|
54
|
+
case 'detected':
|
|
55
|
+
case 'not_detected':
|
|
56
|
+
return value
|
|
57
|
+
default:
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseRedacted(value: string): boolean | undefined {
|
|
63
|
+
switch (value) {
|
|
64
|
+
case 'true':
|
|
65
|
+
return true
|
|
66
|
+
case 'false':
|
|
67
|
+
return false
|
|
68
|
+
default:
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function appendSourceEvidenceDraft(
|
|
74
|
+
draft: SourceEvidenceDraft,
|
|
75
|
+
evidence: SourceVerificationEvidence[],
|
|
76
|
+
expectedToolId: TrustedSourceToolName,
|
|
77
|
+
): void {
|
|
78
|
+
if (
|
|
79
|
+
draft.toolId === undefined ||
|
|
80
|
+
draft.toolId !== expectedToolId ||
|
|
81
|
+
draft.sourceUrl === undefined ||
|
|
82
|
+
draft.title === undefined ||
|
|
83
|
+
draft.observedAt === undefined ||
|
|
84
|
+
draft.citationHandle === undefined ||
|
|
85
|
+
draft.blockedOrUsed === undefined ||
|
|
86
|
+
draft.trust === undefined ||
|
|
87
|
+
draft.promptInjection === undefined ||
|
|
88
|
+
draft.redacted === undefined
|
|
89
|
+
) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
evidence.push({
|
|
93
|
+
toolId: draft.toolId,
|
|
94
|
+
sourceUrl: draft.sourceUrl,
|
|
95
|
+
title: draft.title,
|
|
96
|
+
observedAt: draft.observedAt,
|
|
97
|
+
citationHandle: draft.citationHandle,
|
|
98
|
+
blockedOrUsed: draft.blockedOrUsed,
|
|
99
|
+
trust: draft.trust,
|
|
100
|
+
promptInjection: draft.promptInjection,
|
|
101
|
+
redacted: draft.redacted,
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseSourceVerificationSegment(
|
|
106
|
+
segment: string,
|
|
107
|
+
evidence: SourceVerificationEvidence[],
|
|
108
|
+
expectedToolId: TrustedSourceToolName,
|
|
109
|
+
): void {
|
|
110
|
+
let draft: SourceEvidenceDraft = {}
|
|
111
|
+
for (const line of segment.split('\n')) {
|
|
112
|
+
const separatorIndex = line.indexOf(':')
|
|
113
|
+
if (separatorIndex < 0) continue
|
|
114
|
+
const key = line.slice(0, separatorIndex).trim()
|
|
115
|
+
const value = line.slice(separatorIndex + 1).trim()
|
|
116
|
+
if (key === 'tool_id') {
|
|
117
|
+
appendSourceEvidenceDraft(draft, evidence, expectedToolId)
|
|
118
|
+
if (evidence.length >= MAX_PROPAGATED_SOURCE_EVIDENCE) return
|
|
119
|
+
draft = { toolId: value }
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
switch (key) {
|
|
123
|
+
case 'source_url':
|
|
124
|
+
draft.sourceUrl = parseNullableField(value)
|
|
125
|
+
break
|
|
126
|
+
case 'title':
|
|
127
|
+
draft.title = parseNullableField(value)
|
|
128
|
+
break
|
|
129
|
+
case 'timestamp':
|
|
130
|
+
draft.observedAt = value
|
|
131
|
+
break
|
|
132
|
+
case 'citation_handle':
|
|
133
|
+
draft.citationHandle = value
|
|
134
|
+
break
|
|
135
|
+
case 'blocked_or_used':
|
|
136
|
+
draft.blockedOrUsed = parseBlockedOrUsed(value)
|
|
137
|
+
break
|
|
138
|
+
case 'trust':
|
|
139
|
+
draft.trust = value === 'untrusted_source' ? value : undefined
|
|
140
|
+
break
|
|
141
|
+
case 'prompt_injection':
|
|
142
|
+
draft.promptInjection = parsePromptInjection(value)
|
|
143
|
+
break
|
|
144
|
+
case 'redacted':
|
|
145
|
+
draft.redacted = parseRedacted(value)
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
break
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
appendSourceEvidenceDraft(draft, evidence, expectedToolId)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function collectSourceVerificationSegments(text: string): string[] {
|
|
155
|
+
const segments: string[] = []
|
|
156
|
+
const openTag = '<source_verification>'
|
|
157
|
+
const closeTag = '</source_verification>'
|
|
158
|
+
let searchStart = 0
|
|
159
|
+
while (searchStart < text.length) {
|
|
160
|
+
const openIndex = text.indexOf(openTag, searchStart)
|
|
161
|
+
if (openIndex < 0) return segments
|
|
162
|
+
const contentStart = openIndex + openTag.length
|
|
163
|
+
const closeIndex = text.indexOf(closeTag, contentStart)
|
|
164
|
+
if (closeIndex < 0) return segments
|
|
165
|
+
segments.push(text.slice(contentStart, closeIndex))
|
|
166
|
+
searchStart = closeIndex + closeTag.length
|
|
167
|
+
}
|
|
168
|
+
return segments
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function trustedSourceToolName(value: string | undefined): TrustedSourceToolName | undefined {
|
|
172
|
+
switch (value) {
|
|
173
|
+
case WEB_FETCH_TOOL_NAME:
|
|
174
|
+
return WEB_FETCH_TOOL_NAME
|
|
175
|
+
case WEB_SEARCH_TOOL_NAME:
|
|
176
|
+
return WEB_SEARCH_TOOL_NAME
|
|
177
|
+
default:
|
|
178
|
+
return undefined
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function collectToolUseNameById(
|
|
183
|
+
agentMessages: readonly MessageType[],
|
|
184
|
+
): ReadonlyMap<string, string> {
|
|
185
|
+
const toolUseNameById = new Map<string, string>()
|
|
186
|
+
for (const message of agentMessages) {
|
|
187
|
+
if (message.type !== 'assistant') continue
|
|
188
|
+
const { content } = message.message
|
|
189
|
+
if (!Array.isArray(content)) continue
|
|
190
|
+
for (const block of content) {
|
|
191
|
+
if (
|
|
192
|
+
block.type === 'tool_use' &&
|
|
193
|
+
typeof block.id === 'string' &&
|
|
194
|
+
typeof block.name === 'string'
|
|
195
|
+
) {
|
|
196
|
+
toolUseNameById.set(block.id, block.name)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return toolUseNameById
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function collectToolResultText(
|
|
204
|
+
message: MessageType,
|
|
205
|
+
toolUseNameById: ReadonlyMap<string, string>,
|
|
206
|
+
): TrustedToolResultText[] {
|
|
207
|
+
if (message.type !== 'user') return []
|
|
208
|
+
const { content } = message.message
|
|
209
|
+
if (!Array.isArray(content)) return []
|
|
210
|
+
const texts: TrustedToolResultText[] = []
|
|
211
|
+
for (const block of content) {
|
|
212
|
+
if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string') {
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
const toolName = trustedSourceToolName(toolUseNameById.get(block.tool_use_id))
|
|
216
|
+
if (toolName === undefined) continue
|
|
217
|
+
if (typeof block.content === 'string') {
|
|
218
|
+
texts.push({ text: block.content, toolName })
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
if (!Array.isArray(block.content)) continue
|
|
222
|
+
for (const contentBlock of block.content) {
|
|
223
|
+
if (
|
|
224
|
+
typeof contentBlock === 'object' &&
|
|
225
|
+
contentBlock !== null &&
|
|
226
|
+
'text' in contentBlock &&
|
|
227
|
+
typeof contentBlock.text === 'string'
|
|
228
|
+
) {
|
|
229
|
+
texts.push({ text: contentBlock.text, toolName })
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return texts
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function validatedSourceVerification(
|
|
237
|
+
evidence: readonly SourceVerificationEvidence[],
|
|
238
|
+
): SourceVerification | undefined {
|
|
239
|
+
const verification = buildSourceVerification(evidence)
|
|
240
|
+
return sourceVerificationSchema.safeParse(verification).success
|
|
241
|
+
? verification
|
|
242
|
+
: undefined
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function extractSourceVerificationFromMessages(
|
|
246
|
+
agentMessages: readonly MessageType[],
|
|
247
|
+
): SourceVerification | undefined {
|
|
248
|
+
const evidence: SourceVerificationEvidence[] = []
|
|
249
|
+
const toolUseNameById = collectToolUseNameById(agentMessages)
|
|
250
|
+
for (const message of agentMessages) {
|
|
251
|
+
for (const { text, toolName } of collectToolResultText(message, toolUseNameById)) {
|
|
252
|
+
for (const segment of collectSourceVerificationSegments(text)) {
|
|
253
|
+
parseSourceVerificationSegment(segment, evidence, toolName)
|
|
254
|
+
if (evidence.length >= MAX_PROPAGATED_SOURCE_EVIDENCE) {
|
|
255
|
+
return validatedSourceVerification(
|
|
256
|
+
evidence.slice(0, MAX_PROPAGATED_SOURCE_EVIDENCE),
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return evidence.length > 0 ? validatedSourceVerification(evidence) : undefined
|
|
263
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { AgentId } from '../../types/ids.js'
|
|
2
|
+
import { asAgentId } from '../../types/ids.js'
|
|
3
|
+
import { getCwd } from '../../utils/cwd.js'
|
|
4
|
+
import { logForDebugging } from '../../utils/debug.js'
|
|
5
|
+
import { writeAgentMetadata } from '../../utils/sessionStorage.js'
|
|
6
|
+
import {
|
|
7
|
+
createAgentWorktree,
|
|
8
|
+
hasWorktreeChanges,
|
|
9
|
+
removeAgentWorktree,
|
|
10
|
+
} from '../../utils/worktree.js'
|
|
11
|
+
import { buildWorktreeNotice } from './forkSubagent.js'
|
|
12
|
+
import { createUserMessage } from '../../utils/messages.js'
|
|
13
|
+
import type { Message as MessageType } from 'src/types/message.js'
|
|
14
|
+
import type { AgentDefinition } from './loadAgentsDir.js'
|
|
15
|
+
import type { WorktreeResult } from './schemas.js'
|
|
16
|
+
|
|
17
|
+
export type AgentWorktreeInfo = {
|
|
18
|
+
readonly worktreePath: string
|
|
19
|
+
readonly worktreeBranch?: string
|
|
20
|
+
readonly headCommit?: string
|
|
21
|
+
readonly gitRoot?: string
|
|
22
|
+
readonly hookBased?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Mutable cleanup guard; cleanup must become idempotent after the first call. */
|
|
26
|
+
export type MutableWorktreeState = {
|
|
27
|
+
current: AgentWorktreeInfo | null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function createWorktreeState({
|
|
31
|
+
isolation,
|
|
32
|
+
earlyAgentId,
|
|
33
|
+
}: {
|
|
34
|
+
readonly isolation?: 'worktree' | 'remote'
|
|
35
|
+
readonly earlyAgentId: string
|
|
36
|
+
}): Promise<MutableWorktreeState> {
|
|
37
|
+
if (isolation !== 'worktree') return { current: null }
|
|
38
|
+
return {
|
|
39
|
+
current: await createAgentWorktree(`agent-${earlyAgentId.slice(0, 8)}`),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function appendForkWorktreeNotice({
|
|
44
|
+
isForkPath,
|
|
45
|
+
worktreePath,
|
|
46
|
+
promptMessages,
|
|
47
|
+
}: {
|
|
48
|
+
readonly isForkPath: boolean
|
|
49
|
+
readonly worktreePath?: string
|
|
50
|
+
readonly promptMessages: MessageType[]
|
|
51
|
+
}): void {
|
|
52
|
+
if (!isForkPath || !worktreePath) return
|
|
53
|
+
promptMessages.push(
|
|
54
|
+
createUserMessage({ content: buildWorktreeNotice(getCwd(), worktreePath) }),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function buildWorktreeCleanup({
|
|
59
|
+
state,
|
|
60
|
+
earlyAgentId,
|
|
61
|
+
selectedAgent,
|
|
62
|
+
description,
|
|
63
|
+
}: {
|
|
64
|
+
readonly state: MutableWorktreeState
|
|
65
|
+
readonly earlyAgentId: string
|
|
66
|
+
readonly selectedAgent: AgentDefinition
|
|
67
|
+
readonly description: string
|
|
68
|
+
}): () => Promise<WorktreeResult> {
|
|
69
|
+
return async () => {
|
|
70
|
+
const worktreeInfo = state.current
|
|
71
|
+
if (!worktreeInfo) return {}
|
|
72
|
+
state.current = null
|
|
73
|
+
const { worktreePath, worktreeBranch, headCommit, gitRoot, hookBased } =
|
|
74
|
+
worktreeInfo
|
|
75
|
+
if (hookBased) {
|
|
76
|
+
logForDebugging(`Hook-based agent worktree kept at: ${worktreePath}`)
|
|
77
|
+
return { worktreePath }
|
|
78
|
+
}
|
|
79
|
+
if (headCommit) {
|
|
80
|
+
const changed = await hasWorktreeChanges(worktreePath, headCommit)
|
|
81
|
+
if (!changed) {
|
|
82
|
+
await removeAgentWorktree(worktreePath, worktreeBranch, gitRoot)
|
|
83
|
+
clearWorktreeMetadata(asAgentId(earlyAgentId), selectedAgent, description)
|
|
84
|
+
return {}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
logForDebugging(`Agent worktree has changes, keeping: ${worktreePath}`)
|
|
88
|
+
return { worktreePath, worktreeBranch }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function clearWorktreeMetadata(
|
|
93
|
+
agentId: AgentId,
|
|
94
|
+
selectedAgent: AgentDefinition,
|
|
95
|
+
description: string,
|
|
96
|
+
): void {
|
|
97
|
+
void writeAgentMetadata(agentId, {
|
|
98
|
+
agentType: selectedAgent.agentType,
|
|
99
|
+
description,
|
|
100
|
+
}).then(
|
|
101
|
+
() => undefined,
|
|
102
|
+
error =>
|
|
103
|
+
logForDebugging(`Failed to clear worktree metadata: ${String(error)}`),
|
|
104
|
+
)
|
|
105
|
+
}
|