@iaforged/context-code 2.1.7 → 2.1.8
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/dist/src/Task.js +1 -1
- package/dist/src/constants/oauth.js +1 -1
- package/dist/src/context/mailbox.js +1 -1
- package/dist/src/context/voice.js +1 -1
- package/dist/src/hooks/useTerminalSize.js +1 -1
- package/dist/src/ink/Ansi.js +1 -1
- package/dist/src/ink/clearTerminal.js +1 -1
- package/dist/src/ink/colorize.js +1 -1
- package/dist/src/ink/components/App.js +1 -1
- package/dist/src/ink/components/Button.js +1 -1
- package/dist/src/ink/components/ClockContext.js +1 -1
- package/dist/src/ink/components/CursorDeclarationContext.js +1 -1
- package/dist/src/ink/components/Link.js +1 -1
- package/dist/src/ink/components/StdinContext.js +1 -1
- package/dist/src/ink/components/TerminalFocusContext.js +1 -1
- package/dist/src/ink/dom.js +1 -1
- package/dist/src/ink/events/keyboard-event.js +1 -1
- package/dist/src/ink/hit-test.js +1 -1
- package/dist/src/ink/hooks/use-animation-frame.js +1 -1
- package/dist/src/ink/hooks/use-app.js +1 -1
- package/dist/src/ink/hooks/use-input.js +1 -1
- package/dist/src/ink/hooks/use-interval.js +1 -1
- package/dist/src/ink/hooks/use-selection.js +1 -1
- package/dist/src/ink/hooks/use-tab-status.js +1 -1
- package/dist/src/ink/hooks/use-terminal-focus.js +1 -1
- package/dist/src/ink/hooks/use-terminal-title.js +1 -1
- package/dist/src/ink/hooks/use-terminal-viewport.js +1 -1
- package/dist/src/ink/ink.js +1 -1
- package/dist/src/ink/layout/yoga.js +1 -1
- package/dist/src/ink/line-width-cache.js +1 -1
- package/dist/src/ink/log-update.js +1 -1
- package/dist/src/ink/measure-text.js +1 -1
- package/dist/src/ink/output.js +1 -1
- package/dist/src/ink/parse-keypress.js +1 -1
- package/dist/src/ink/reconciler.js +1 -1
- package/dist/src/ink/render-border.js +1 -1
- package/dist/src/ink/render-node-to-output.js +1 -1
- package/dist/src/ink/render-to-screen.js +1 -1
- package/dist/src/ink/renderer.js +1 -1
- package/dist/src/ink/root.js +1 -1
- package/dist/src/ink/screen.js +1 -1
- package/dist/src/ink/searchHighlight.js +1 -1
- package/dist/src/ink/selection.js +1 -1
- package/dist/src/ink/squash-text-nodes.js +1 -1
- package/dist/src/ink/stringWidth.js +1 -1
- package/dist/src/ink/tabstops.js +1 -1
- package/dist/src/ink/terminal.js +1 -1
- package/dist/src/ink/termio/osc.js +1 -1
- package/dist/src/ink/termio/parser.js +1 -1
- package/dist/src/ink/termio/tokenize.js +1 -1
- package/dist/src/ink/useTerminalNotification.js +1 -1
- package/dist/src/ink/warn.js +1 -1
- package/dist/src/ink/widest-line.js +1 -1
- package/dist/src/ink/wrap-text.js +1 -1
- package/dist/src/ink/wrapAnsi.js +1 -1
- package/dist/src/native-ts/yoga-layout/index.js +1 -1
- package/dist/src/schemas/hooks.js +1 -1
- package/dist/src/services/SessionMemory/sessionMemoryUtils.js +1 -1
- package/dist/src/services/api/client.js +1 -1
- package/dist/src/services/api/dumpPrompts.js +1 -1
- package/dist/src/services/api/errorUtils.js +1 -1
- package/dist/src/services/api/promptCacheBreakDetection.js +1 -1
- package/dist/src/services/api/withRetry.js +1 -1
- package/dist/src/services/autoDream/consolidationLock.js +1 -1
- package/dist/src/services/mcp/elicitationHandler.js +1 -1
- package/dist/src/services/mcp/mcpStringUtils.js +1 -1
- package/dist/src/services/mcp/oauthPort.js +1 -1
- package/dist/src/services/mcp/vscodeSdkMcp.js +1 -1
- package/dist/src/services/oauth/client.js +1 -1
- package/dist/src/services/oauth/getOauthProfile.js +1 -1
- package/dist/src/services/objetivo/types.js +1 -1
- package/dist/src/services/rateLimitMocking.js +1 -1
- package/dist/src/services/remoteManagedSettings/syncCacheState.js +1 -1
- package/dist/src/skills/bundledSkills.js +1 -1
- package/dist/src/tasks/DreamTask/DreamTask.js +1 -1
- package/dist/src/tools/AgentTool/agentMemory.js +1 -1
- package/dist/src/tools/AgentTool/forkSubagent.js +1 -1
- package/dist/src/tools/BashTool/BashToolResultMessage.js +1 -1
- package/dist/src/tools/BashTool/UI.js +1 -1
- package/dist/src/tools/BashTool/sedEditParser.js +1 -1
- package/dist/src/tools/BashTool/utils.js +1 -1
- package/dist/src/tools/FileReadTool/imageProcessor.js +1 -1
- package/dist/src/tools/FileReadTool/prompt.js +1 -1
- package/dist/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +1 -1
- package/dist/src/tools/ListMcpResourcesTool/UI.js +1 -1
- package/dist/src/tools/MCPTool/MCPTool.js +1 -1
- package/dist/src/tools/MCPTool/UI.js +1 -1
- package/dist/src/tools/McpAuthTool/McpAuthTool.js +1 -1
- package/dist/src/tools/NotebookEditTool/prompt.js +1 -1
- package/dist/src/tools/PowerShellTool/PowerShellTool.js +1 -1
- package/dist/src/tools/PowerShellTool/UI.js +1 -1
- package/dist/src/tools/PowerShellTool/gitSafety.js +1 -1
- package/dist/src/tools/PowerShellTool/modeValidation.js +1 -1
- package/dist/src/tools/PowerShellTool/pathValidation.js +1 -1
- package/dist/src/tools/PowerShellTool/powershellPermissions.js +1 -1
- package/dist/src/tools/PowerShellTool/powershellSecurity.js +1 -1
- package/dist/src/tools/PowerShellTool/prompt.js +1 -1
- package/dist/src/tools/PowerShellTool/readOnlyValidation.js +1 -1
- package/dist/src/tools/REPLTool/constants.js +1 -1
- package/dist/src/tools/REPLTool/primitiveTools.js +1 -1
- package/dist/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +1 -1
- package/dist/src/tools/ReadMcpResourceTool/UI.js +1 -1
- package/dist/src/tools/ScheduleCronTool/prompt.js +1 -1
- package/dist/src/tools/SkillTool/prompt.js +1 -1
- package/dist/src/tools/TodoWriteTool/TodoWriteTool.js +1 -1
- package/dist/src/tools/ToolSearchTool/prompt.js +1 -1
- package/dist/src/tools/WebSearchTool/prompt.js +1 -1
- package/dist/src/tools/shared/gitOperationTracking.js +1 -1
- package/dist/src/types/permissions.js +1 -1
- package/dist/src/utils/Cursor.js +1 -1
- package/dist/src/utils/QueryGuard.js +1 -1
- package/dist/src/utils/Shell.js +1 -1
- package/dist/src/utils/ShellCommand.js +1 -1
- package/dist/src/utils/activityManager.js +1 -1
- package/dist/src/utils/advisor.js +1 -1
- package/dist/src/utils/appleTerminalBackup.js +1 -1
- package/dist/src/utils/argumentSubstitution.js +1 -1
- package/dist/src/utils/authFileDescriptor.js +1 -1
- package/dist/src/utils/autoUpdater.js +1 -1
- package/dist/src/utils/background/remote/preconditions.js +1 -1
- package/dist/src/utils/background/remote/remoteSession.js +1 -1
- package/dist/src/utils/bash/ShellSnapshot.js +1 -1
- package/dist/src/utils/bash/ast.js +1 -1
- package/dist/src/utils/bash/bashParser.js +1 -1
- package/dist/src/utils/bash/bashPipeCommand.js +1 -1
- package/dist/src/utils/bash/parser.js +1 -1
- package/dist/src/utils/bash/shellQuote.js +1 -1
- package/dist/src/utils/bash/shellQuoting.js +1 -1
- package/dist/src/utils/billing.js +1 -1
- package/dist/src/utils/caCerts.js +1 -1
- package/dist/src/utils/claudeInChrome/common.js +1 -1
- package/dist/src/utils/claudeInChrome/setupPortable.js +1 -1
- package/dist/src/utils/claudemd.js +1 -1
- package/dist/src/utils/collapseBackgroundBashNotifications.js +1 -1
- package/dist/src/utils/collapseReadSearch.js +1 -1
- package/dist/src/utils/completionCache.js +1 -1
- package/dist/src/utils/computerUse/common.js +1 -1
- package/dist/src/utils/concurrentSessions.js +1 -1
- package/dist/src/utils/context.js +1 -1
- package/dist/src/utils/cron.js +1 -1
- package/dist/src/utils/cronTasks.js +1 -1
- package/dist/src/utils/cwd.js +1 -1
- package/dist/src/utils/debug.js +1 -1
- package/dist/src/utils/debugFilter.js +1 -1
- package/dist/src/utils/detectRepository.js +1 -1
- package/dist/src/utils/diagLogs.js +1 -1
- package/dist/src/utils/diff.js +1 -1
- package/dist/src/utils/directMemberMessage.js +1 -1
- package/dist/src/utils/doctorDiagnostic.js +1 -1
- package/dist/src/utils/dxt/helpers.js +1 -1
- package/dist/src/utils/dxt/zip.js +1 -1
- package/dist/src/utils/earlyInput.js +1 -1
- package/dist/src/utils/editor.js +1 -1
- package/dist/src/utils/effort.js +1 -1
- package/dist/src/utils/embeddedTools.js +1 -1
- package/dist/src/utils/envDynamic.js +1 -1
- package/dist/src/utils/envUtils.js +1 -1
- package/dist/src/utils/execFileNoThrowPortable.js +1 -1
- package/dist/src/utils/execSyncWrapper.js +1 -1
- package/dist/src/utils/exportRenderer.js +1 -1
- package/dist/src/utils/extraUsage.js +1 -1
- package/dist/src/utils/fastMode.js +1 -1
- package/dist/src/utils/fileOperationAnalytics.js +1 -1
- package/dist/src/utils/fileRead.js +1 -1
- package/dist/src/utils/findExecutable.js +1 -1
- package/dist/src/utils/format.js +1 -1
- package/dist/src/utils/frontmatterParser.js +1 -1
- package/dist/src/utils/fsOperations.js +1 -1
- package/dist/src/utils/fullscreen.js +1 -1
- package/dist/src/utils/genericProcessUtils.js +1 -1
- package/dist/src/utils/getWorktreePaths.js +1 -1
- package/dist/src/utils/git/gitConfigParser.js +1 -1
- package/dist/src/utils/git/gitFilesystem.js +1 -1
- package/dist/src/utils/git/gitignore.js +1 -1
- package/dist/src/utils/gitDiff.js +1 -1
- package/dist/src/utils/gitSettings.js +1 -1
- package/dist/src/utils/glob.js +1 -1
- package/dist/src/utils/gracefulShutdown.js +1 -1
- package/dist/src/utils/groupToolUses.js +1 -1
- package/dist/src/utils/handlePromptSubmit.js +1 -1
- package/dist/src/utils/hash.js +1 -1
- package/dist/src/utils/hooks/fileChangedWatcher.js +1 -1
- package/dist/src/utils/hooks/hooksSettings.js +1 -1
- package/dist/src/utils/hooks/registerSkillHooks.js +1 -1
- package/dist/src/utils/hooks/sessionHooks.js +1 -1
- package/dist/src/utils/http.js +1 -1
- package/dist/src/utils/hyperlink.js +1 -1
- package/dist/src/utils/ide.js +1 -1
- package/dist/src/utils/idePathConversion.js +1 -1
- package/dist/src/utils/imagePaste.js +1 -1
- package/dist/src/utils/imageResizer.js +1 -1
- package/dist/src/utils/imageStore.js +1 -1
- package/dist/src/utils/inProcessTeammateHelpers.js +1 -1
- package/dist/src/utils/ink.js +1 -1
- package/dist/src/utils/jetbrains.js +1 -1
- package/dist/src/utils/json.js +1 -1
- package/dist/src/utils/listSessionsImpl.js +1 -1
- package/dist/src/utils/localInstaller.js +1 -1
- package/dist/src/utils/lockfile.js +1 -1
- package/dist/src/utils/logoV2Utils.js +1 -1
- package/dist/src/utils/markdown.js +1 -1
- package/dist/src/utils/mcp/dateTimeParser.js +1 -1
- package/dist/src/utils/mcpOutputStorage.js +1 -1
- package/dist/src/utils/mcpValidation.js +1 -1
- package/dist/src/utils/memoize.js +1 -1
- package/dist/src/utils/memory/types.js +1 -1
- package/dist/src/utils/memoryFileDetection.js +1 -1
- package/dist/src/utils/messageQueueManager.js +1 -1
- package/dist/src/utils/messages/mappers.js +1 -1
- package/dist/src/utils/messages/systemInit.js +1 -1
- package/dist/src/utils/model/antModels.js +1 -1
- package/dist/src/utils/model/check1mAccess.js +1 -1
- package/dist/src/utils/model/contextWindowUpgradeCheck.js +1 -1
- package/dist/src/utils/model/model.js +1 -1
- package/dist/src/utils/model/modelAllowlist.js +1 -1
- package/dist/src/utils/model/modelCapabilities.js +1 -1
- package/dist/src/utils/model/modelOptions.js +1 -1
- package/dist/src/utils/model/modelStrings.js +1 -1
- package/dist/src/utils/model/providerModels.js +1 -1
- package/dist/src/utils/model/providerProfiles.js +1 -1
- package/dist/src/utils/model/providerProfilesDb.js +1 -1
- package/dist/src/utils/model/providerSwitch.js +1 -1
- package/dist/src/utils/model/providers.js +1 -1
- package/dist/src/utils/modelCost.js +1 -1
- package/dist/src/utils/modifiers.js +1 -1
- package/dist/src/utils/mtls.js +1 -1
- package/dist/src/utils/nativeInstaller/download.js +1 -1
- package/dist/src/utils/nativeInstaller/installer.js +1 -1
- package/dist/src/utils/nativeInstaller/packageManagers.js +1 -1
- package/dist/src/utils/nativeInstaller/pidLock.js +1 -1
- package/dist/src/utils/notebook.js +1 -1
- package/dist/src/utils/pasteStore.js +1 -1
- package/dist/src/utils/path.js +1 -1
- package/dist/src/utils/permissions/PermissionMode.js +1 -1
- package/dist/src/utils/permissions/PermissionPromptToolResultSchema.js +1 -1
- package/dist/src/utils/permissions/PermissionUpdate.js +1 -1
- package/dist/src/utils/permissions/PermissionUpdateSchema.js +1 -1
- package/dist/src/utils/permissions/autoModeState.js +1 -1
- package/dist/src/utils/permissions/bypassPermissionsKillswitch.js +1 -1
- package/dist/src/utils/permissions/filesystem.js +1 -1
- package/dist/src/utils/permissions/getNextPermissionMode.js +1 -1
- package/dist/src/utils/permissions/pathValidation.js +1 -1
- package/dist/src/utils/permissions/permissionRuleParser.js +1 -1
- package/dist/src/utils/permissions/permissionsDb.js +1 -1
- package/dist/src/utils/permissions/permissionsLoader.js +1 -1
- package/dist/src/utils/permissions/shellRuleMatching.js +1 -1
- package/dist/src/utils/planModeV2.js +1 -1
- package/dist/src/utils/plans.js +1 -1
- package/dist/src/utils/platform.js +1 -1
- package/dist/src/utils/plugins/addDirPluginSettings.js +1 -1
- package/dist/src/utils/plugins/cacheUtils.js +1 -1
- package/dist/src/utils/plugins/dependencyResolver.js +1 -1
- package/dist/src/utils/plugins/fetchTelemetry.js +1 -1
- package/dist/src/utils/plugins/gitAvailability.js +1 -1
- package/dist/src/utils/plugins/hintRecommendation.js +1 -1
- package/dist/src/utils/plugins/installedPluginsManager.js +1 -1
- package/dist/src/utils/plugins/loadPluginAgents.js +1 -1
- package/dist/src/utils/plugins/loadPluginCommands.js +1 -1
- package/dist/src/utils/plugins/loadPluginHooks.js +1 -1
- package/dist/src/utils/plugins/loadPluginOutputStyles.js +1 -1
- package/dist/src/utils/plugins/lspPluginIntegration.js +1 -1
- package/dist/src/utils/plugins/lspRecommendation.js +1 -1
- package/dist/src/utils/plugins/managedPlugins.js +1 -1
- package/dist/src/utils/plugins/marketplaceHelpers.js +1 -1
- package/dist/src/utils/plugins/marketplaceManager.js +1 -1
- package/dist/src/utils/plugins/mcpPluginIntegration.js +1 -1
- package/dist/src/utils/plugins/mcpbHandler.js +1 -1
- package/dist/src/utils/plugins/officialMarketplaceGcs.js +1 -1
- package/dist/src/utils/plugins/officialMarketplaceStartupCheck.js +1 -1
- package/dist/src/utils/plugins/orphanedPluginFilter.js +1 -1
- package/dist/src/utils/plugins/performStartupChecks.js +1 -1
- package/dist/src/utils/plugins/pluginAutoupdate.js +1 -1
- package/dist/src/utils/plugins/pluginBlocklist.js +1 -1
- package/dist/src/utils/plugins/pluginDirectories.js +1 -1
- package/dist/src/utils/plugins/pluginFlagging.js +1 -1
- package/dist/src/utils/plugins/pluginInstallationHelpers.js +1 -1
- package/dist/src/utils/plugins/pluginLoader.js +1 -1
- package/dist/src/utils/plugins/pluginOptionsStorage.js +1 -1
- package/dist/src/utils/plugins/pluginPolicy.js +1 -1
- package/dist/src/utils/plugins/pluginStartupCheck.js +1 -1
- package/dist/src/utils/plugins/pluginVersioning.js +1 -1
- package/dist/src/utils/plugins/reconciler.js +1 -1
- package/dist/src/utils/plugins/refresh.js +1 -1
- package/dist/src/utils/plugins/schemas.js +1 -1
- package/dist/src/utils/plugins/walkPluginMarkdown.js +1 -1
- package/dist/src/utils/plugins/zipCache.js +1 -1
- package/dist/src/utils/powershell/parser.js +1 -1
- package/dist/src/utils/processUserInput/processBashCommand.js +1 -1
- package/dist/src/utils/processUserInput/processSlashCommand.js +1 -1
- package/dist/src/utils/processUserInput/processTextPrompt.js +1 -1
- package/dist/src/utils/processUserInput/processUserInput.js +1 -1
- package/dist/src/utils/profilerBase.js +1 -1
- package/dist/src/utils/promptCategory.js +1 -1
- package/dist/src/utils/promptEditor.js +1 -1
- package/dist/src/utils/promptShellExecution.js +1 -1
- package/dist/src/utils/proxy.js +1 -1
- package/dist/src/utils/queryHelpers.js +1 -1
- package/dist/src/utils/queryProfiler.js +1 -1
- package/dist/src/utils/queueProcessor.js +1 -1
- package/dist/src/utils/readFileInRange.js +1 -1
- package/dist/src/utils/releaseNotes.js +1 -1
- package/dist/src/utils/renderOptions.js +1 -1
- package/dist/src/utils/ripgrep.js +1 -1
- package/dist/src/utils/sandbox/sandbox-adapter.js +1 -1
- package/dist/src/utils/sdkEventQueue.js +1 -1
- package/dist/src/utils/secureStorage/index.js +1 -1
- package/dist/src/utils/secureStorage/macOsKeychainHelpers.js +1 -1
- package/dist/src/utils/secureStorage/macOsKeychainStorage.js +1 -1
- package/dist/src/utils/secureStorage/plainTextStorage.js +1 -1
- package/dist/src/utils/secureStorage/sqliteStorage.js +1 -1
- package/dist/src/utils/sessionEnvironment.js +1 -1
- package/dist/src/utils/sessionIngressAuth.js +1 -1
- package/dist/src/utils/sessionRestore.js +1 -1
- package/dist/src/utils/sessionStart.js +1 -1
- package/dist/src/utils/sessionTitle.js +1 -1
- package/dist/src/utils/settings/managedPath.js +1 -1
- package/dist/src/utils/settings/mdm/rawRead.js +1 -1
- package/dist/src/utils/settings/mdm/settings.js +1 -1
- package/dist/src/utils/settings/permissionValidation.js +1 -1
- package/dist/src/utils/settings/pluginOnlyPolicy.js +1 -1
- package/dist/src/utils/settings/schemaOutput.js +1 -1
- package/dist/src/utils/settings/settings.js +1 -1
- package/dist/src/utils/settings/types.js +1 -1
- package/dist/src/utils/settings/validateEditTool.js +1 -1
- package/dist/src/utils/settings/validation.js +1 -1
- package/dist/src/utils/shell/bashProvider.js +1 -1
- package/dist/src/utils/shell/powershellDetection.js +1 -1
- package/dist/src/utils/shell/powershellProvider.js +1 -1
- package/dist/src/utils/shell/readOnlyCommandValidation.js +1 -1
- package/dist/src/utils/shell/resolveDefaultShell.js +1 -1
- package/dist/src/utils/shell/shellToolUtils.js +1 -1
- package/dist/src/utils/shell/specPrefix.js +1 -1
- package/dist/src/utils/shellConfig.js +1 -1
- package/dist/src/utils/sideQuestion.js +1 -1
- package/dist/src/utils/skills/skillChangeDetector.js +1 -1
- package/dist/src/utils/slashCommandParsing.js +1 -1
- package/dist/src/utils/sliceAnsi.js +1 -1
- package/dist/src/utils/slowOperations.js +1 -1
- package/dist/src/utils/standaloneAgent.js +1 -1
- package/dist/src/utils/startupProfiler.js +1 -1
- package/dist/src/utils/staticRender.js +1 -1
- package/dist/src/utils/status.js +1 -1
- package/dist/src/utils/statusNoticeDefinitions.js +1 -1
- package/dist/src/utils/suggestions/commandSuggestions.js +1 -1
- package/dist/src/utils/suggestions/directoryCompletion.js +1 -1
- package/dist/src/utils/suggestions/shellHistoryCompletion.js +1 -1
- package/dist/src/utils/suggestions/skillUsageTracking.js +1 -1
- package/dist/src/utils/suggestions/slackChannelSuggestions.js +1 -1
- package/dist/src/utils/swarm/backends/detection.js +1 -1
- package/dist/src/utils/swarm/permissionSync.js +1 -1
- package/dist/src/utils/swarm/reconnection.js +1 -1
- package/dist/src/utils/swarm/spawnUtils.js +1 -91
- package/dist/src/utils/swarm/teammateInit.js +1 -1
- package/dist/src/utils/systemDirectories.js +1 -1
- package/dist/src/utils/systemPrompt.js +1 -1
- package/dist/src/utils/systemTheme.js +1 -1
- package/dist/src/utils/task/TaskOutput.js +1 -1
- package/dist/src/utils/task/diskOutput.js +1 -1
- package/dist/src/utils/tasks.js +1 -1
- package/dist/src/utils/teamDiscovery.js +1 -1
- package/dist/src/utils/teamMemoryOps.js +1 -1
- package/dist/src/utils/teammateMailbox.js +1 -1
- package/dist/src/utils/telemetry/betaSessionTracing.js +1 -1
- package/dist/src/utils/telemetry/bigqueryExporter.js +1 -1
- package/dist/src/utils/telemetry/events.js +1 -1
- package/dist/src/utils/telemetry/instrumentation.js +1 -1
- package/dist/src/utils/telemetry/logger.js +1 -1
- package/dist/src/utils/telemetry/perfettoTracing.js +1 -1
- package/dist/src/utils/telemetry/pluginTelemetry.js +1 -1
- package/dist/src/utils/telemetry/sessionTracing.js +1 -1
- package/dist/src/utils/telemetryAttributes.js +1 -1
- package/dist/src/utils/teleport/api.js +1 -1
- package/dist/src/utils/teleport/environments.js +1 -1
- package/dist/src/utils/teleport/gitBundle.js +1 -1
- package/dist/src/utils/teleport.js +1 -1
- package/dist/src/utils/tempfile.js +1 -1
- package/dist/src/utils/terminal.js +1 -1
- package/dist/src/utils/terminalPanel.js +1 -1
- package/dist/src/utils/textHighlighting.js +1 -1
- package/dist/src/utils/theme.js +1 -1
- package/dist/src/utils/themes/bootstrap.js +1 -1
- package/dist/src/utils/themes/loader.js +1 -1
- package/dist/src/utils/thinking.js +1 -1
- package/dist/src/utils/tmuxSocket.js +1 -1
- package/dist/src/utils/tokens.js +1 -1
- package/dist/src/utils/toolPool.js +1 -1
- package/dist/src/utils/toolResultStorage.js +1 -1
- package/dist/src/utils/transcriptSearch.js +1 -1
- package/dist/src/utils/truncate.js +1 -1
- package/dist/src/utils/ultraplan/keyword.js +1 -1
- package/dist/src/utils/unaryLogging.js +1 -1
- package/dist/src/utils/undercover.js +1 -1
- package/dist/src/utils/user.js +1 -1
- package/dist/src/utils/userPromptKeywords.js +1 -1
- package/dist/src/utils/which.js +1 -1
- package/dist/src/utils/windowsPaths.js +1 -1
- package/dist/src/utils/worktree.js +1 -1
- package/dist/src/utils/zodToJsonSchema.js +1 -1
- package/dist/src/vim/operators.js +1 -1
- package/dist/src/vim/textObjects.js +1 -1
- package/dist/src/vim/transitions.js +1 -1
- package/dist/src/voice/voiceModeEnabled.js +1 -1
- package/dist/src/webapp/auth.js +1 -1
- package/dist/src/webapp/tunnel.js +1 -1
- package/dist/src/whatsapp/bridge.js +1 -1
- package/dist/src/whatsapp/mirror.js +1 -1
- package/dist/webapp/main-MTQLKGXD.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mkdir as
|
|
1
|
+
import{feature as e}from"../recovery/bunBundleShim.js";import{mkdir as t,writeFile as o}from"fs/promises";import{join as s}from"path";import{getOriginalCwd as n,getSessionId as r}from"../bootstrap/state.js";import{BYTES_PER_TOKEN as i,DEFAULT_MAX_RESULT_SIZE_CHARS as a,MAX_TOOL_RESULT_BYTES as l,MAX_TOOL_RESULTS_PER_MESSAGE_CHARS as c}from"../constants/toolLimits.js";import{getFeatureValue_CACHED_MAY_BE_STALE as u}from"../services/analytics/growthbook.js";import{logEvent as p}from"../services/analytics/index.js";import{sanitizeToolNameForAnalytics as d}from"../services/analytics/metadata.js";import{logForDebugging as m}from"./debug.js";import{getErrnoCode as f,toError as g}from"./errors.js";import{formatFileSize as h}from"./format.js";import{logError as y}from"./log.js";import{getProjectDir as R}from"./sessionStorage.js";import{jsonStringify as S}from"./slowOperations.js";export const TOOL_RESULTS_SUBDIR="tool-results";export const PERSISTED_OUTPUT_TAG="<persisted-output>";export const PERSISTED_OUTPUT_CLOSING_TAG="</persisted-output>";export const TOOL_RESULT_CLEARED_MESSAGE="[Old tool result content cleared]";export function getPersistenceThreshold(e,t){if(!Number.isFinite(t))return t;const o=u("tengu_satin_quoll",{}),s=o?.[e];return"number"==typeof s&&Number.isFinite(s)&&s>0?s:Math.min(t,a)}export function getToolResultsDir(){return s(s(R(n()),r()),"tool-results")}export const PREVIEW_SIZE_BYTES=2e3;export function getToolResultPath(e,t){const o=t?"json":"txt";return s(getToolResultsDir(),`${e}.${o}`)}export async function ensureToolResultsDir(){try{await t(getToolResultsDir(),{recursive:!0})}catch{}}export async function persistToolResult(e,t){const s=Array.isArray(e);if(s){if(e.some(e=>"text"!==e.type))return{error:"Cannot persist tool results containing non-text content"}}await ensureToolResultsDir();const n=getToolResultPath(t,s),r=s?S(e,null,2):e;try{await o(n,r,{encoding:"utf-8",flag:"wx"}),m(`Persisted tool result to ${n} (${h(r.length)})`)}catch(e){if("EEXIST"!==f(e))return y(g(e)),{error:getFileSystemErrorMessage(g(e))}}const{preview:i,hasMore:a}=generatePreview(r,2e3);return{filepath:n,originalSize:r.length,isJson:s,preview:i,hasMore:a}}export function buildLargeToolResultMessage(e){let t="<persisted-output>\n";return t+=`Output too large (${h(e.originalSize)}). Full output saved to: ${e.filepath}\n\n`,t+=`Preview (first ${h(2e3)}):\n`,t+=e.preview,t+=e.hasMore?"\n...\n":"\n",t+="</persisted-output>",t}export async function processToolResultBlock(e,t,o){return maybePersistLargeToolResult(e.mapToolResultToToolResultBlockParam(t,o),e.name,getPersistenceThreshold(e.name,e.maxResultSizeChars))}export async function processPreMappedToolResultBlock(e,t,o){return maybePersistLargeToolResult(e,t,getPersistenceThreshold(t,o))}export function isToolResultContentEmpty(e){return!e||("string"==typeof e?""===e.trim():!!Array.isArray(e)&&(0===e.length||e.every(e=>"object"==typeof e&&"type"in e&&"text"===e.type&&"text"in e&&("string"!=typeof e.text||""===e.text.trim()))))}async function maybePersistLargeToolResult(e,t,o){const s=e.content;if(isToolResultContentEmpty(s))return p("tengu_tool_empty_result",{toolName:d(t)}),{...e,content:`(${t} completed with no output)`};if(!s)return e;if(hasImageBlock(s))return e;const n=contentSize(s),r=o??l;if(n<=r)return e;const a=await persistToolResult(s,e.tool_use_id);if(isPersistError(a))return e;const c=buildLargeToolResultMessage(a);return p("tengu_tool_result_persisted",{toolName:d(t),originalSizeBytes:a.originalSize,persistedSizeBytes:c.length,estimatedOriginalTokens:Math.ceil(a.originalSize/i),estimatedPersistedTokens:Math.ceil(c.length/i),thresholdUsed:r}),{...e,content:c}}export function generatePreview(e,t){if(e.length<=t)return{preview:e,hasMore:!1};const o=e.slice(0,t).lastIndexOf("\n"),s=o>.5*t?o:t;return{preview:e.slice(0,s),hasMore:!0}}export function isPersistError(e){return"error"in e}export function createContentReplacementState(){return{seenIds:new Set,replacements:new Map}}export function cloneContentReplacementState(e){return{seenIds:new Set(e.seenIds),replacements:new Map(e.replacements)}}export function getPerMessageBudgetLimit(){const e=u("tengu_hawthorn_window",null);return"number"==typeof e&&Number.isFinite(e)&&e>0?e:c}export function provisionContentReplacementState(e,t){if(u("tengu_hawthorn_steeple",!1))return e?reconstructContentReplacementState(e,t??[]):createContentReplacementState()}function hasImageBlock(e){return Array.isArray(e)&&e.some(e=>"object"==typeof e&&"type"in e&&"image"===e.type)}function contentSize(e){return"string"==typeof e?e.length:e.reduce((e,t)=>e+("text"===t.type?t.text.length:0),0)}function collectCandidatesFromMessage(e){return"user"===e.type&&Array.isArray(e.message.content)?e.message.content.flatMap(e=>{return"tool_result"===e.type&&e.content?"string"==typeof(t=e.content)&&t.startsWith("<persisted-output>")||hasImageBlock(e.content)?[]:[{toolUseId:e.tool_use_id,content:e.content,size:contentSize(e.content)}]:[];var t}):[]}function collectCandidatesByMessage(e){const t=[];let o=[];const flush=()=>{o.length>0&&t.push(o),o=[]},s=new Set;for(const t of e)"user"===t.type?o.push(...collectCandidatesFromMessage(t)):"assistant"===t.type&&(s.has(t.message.id)||(flush(),s.add(t.message.id)));return flush(),t}function partitionByPriorDecision(e,t){return e.reduce((e,o)=>{const s=t.replacements.get(o.toolUseId);return void 0!==s?e.mustReapply.push({...o,replacement:s}):t.seenIds.has(o.toolUseId)?e.frozen.push(o):e.fresh.push(o),e},{mustReapply:[],frozen:[],fresh:[]})}function selectFreshToReplace(e,t,o){const s=[...e].sort((e,t)=>t.size-e.size),n=[];let r=t+e.reduce((e,t)=>e+t.size,0);for(const e of s){if(r<=o)break;n.push(e),r-=e.size}return n}function replaceToolResultContents(e,t){return e.map(e=>{if("user"!==e.type||!Array.isArray(e.message.content))return e;const o=e.message.content;return o.some(e=>"tool_result"===e.type&&t.has(e.tool_use_id))?{...e,message:{...e.message,content:o.map(e=>{if("tool_result"!==e.type)return e;const o=t.get(e.tool_use_id);return void 0===o?e:{...e,content:o}})}}:e})}async function buildReplacement(e){const t=await persistToolResult(e.content,e.toolUseId);return isPersistError(t)?null:{content:buildLargeToolResultMessage(t),originalSize:t.originalSize}}export async function enforceToolResultBudget(e,t,o=new Set){const s=collectCandidatesByMessage(e),n=o.size>0?function(e){const t=new Map;for(const o of e){if("assistant"!==o.type)continue;const e=o.message.content;if(Array.isArray(e))for(const o of e)"tool_use"===o.type&&t.set(o.id,o.name)}return t}(e):void 0,shouldSkip=e=>void 0!==n&&o.has(n.get(e)??""),r=getPerMessageBudgetLimit(),a=new Map,l=[];let c=0,u=0;for(const e of s){const{mustReapply:o,frozen:s,fresh:n}=partitionByPriorDecision(e,t);if(o.forEach(e=>a.set(e.toolUseId,e.replacement)),c+=o.length,0===n.length){e.forEach(e=>t.seenIds.add(e.toolUseId));continue}n.filter(e=>shouldSkip(e.toolUseId)).forEach(e=>t.seenIds.add(e.toolUseId));const i=n.filter(e=>!shouldSkip(e.toolUseId)),p=s.reduce((e,t)=>e+t.size,0),d=p+i.reduce((e,t)=>e+t.size,0)>r?selectFreshToReplace(i,p,r):[],m=new Set(d.map(e=>e.toolUseId));e.filter(e=>!m.has(e.toolUseId)).forEach(e=>t.seenIds.add(e.toolUseId)),0!==d.length&&(u++,l.push(...d))}if(0===a.size&&0===l.length)return{messages:e,newlyReplaced:[]};const d=await Promise.all(l.map(async e=>[e,await buildReplacement(e)])),f=[];let g=0;for(const[e,o]of d)t.seenIds.add(e.toolUseId),null!==o&&(g+=e.size,a.set(e.toolUseId,o.content),t.replacements.set(e.toolUseId,o.content),f.push({kind:"tool-result",toolUseId:e.toolUseId,replacement:o.content}),p("tengu_tool_result_persisted_message_budget",{originalSizeBytes:o.originalSize,persistedSizeBytes:o.content.length,estimatedOriginalTokens:Math.ceil(o.originalSize/i),estimatedPersistedTokens:Math.ceil(o.content.length/i)}));return 0===a.size?{messages:e,newlyReplaced:[]}:(f.length>0&&(m(`Per-message budget: persisted ${f.length} tool results across ${u} over-budget message(s), shed ~${h(g)}, ${c} re-applied`),p("tengu_message_level_tool_result_budget_enforced",{resultsPersisted:f.length,messagesOverBudget:u,replacedSizeBytes:g,reapplied:c})),{messages:replaceToolResultContents(e,a),newlyReplaced:f})}export async function applyToolResultBudget(e,t,o,s){if(!t)return e;const n=await enforceToolResultBudget(e,t,s);return n.newlyReplaced.length>0&&o?.(n.newlyReplaced),n.messages}export function reconstructContentReplacementState(e,t,o){const s=createContentReplacementState(),n=new Set(collectCandidatesByMessage(e).flat().map(e=>e.toolUseId));for(const e of n)s.seenIds.add(e);for(const e of t)"tool-result"===e.kind&&n.has(e.toolUseId)&&s.replacements.set(e.toolUseId,e.replacement);if(o)for(const[e,t]of o)n.has(e)&&!s.replacements.has(e)&&s.replacements.set(e,t);return s}export function reconstructForSubagentResume(e,t,o){if(e)return reconstructContentReplacementState(t,o,e.replacements)}function getFileSystemErrorMessage(e){const t=e;if(t.code)switch(t.code){case"ENOENT":return`Directory not found: ${t.path??"unknown path"}`;case"EACCES":return`Permission denied: ${t.path??"unknown path"}`;case"ENOSPC":return"No space left on device";case"EROFS":return"Read-only file system";case"EMFILE":return"Too many open files";case"EEXIST":return`File already exists: ${t.path??"unknown path"}`;default:return`${t.code}: ${t.message}`}return e.message}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{INTERRUPT_MESSAGE as t,INTERRUPT_MESSAGE_FOR_TOOL_USE as e}from"./messages.js";const n=new Set([t,e]),
|
|
1
|
+
import{INTERRUPT_MESSAGE as t,INTERRUPT_MESSAGE_FOR_TOOL_USE as e}from"./messages.js";const n="</system-reminder>",o=new Set([t,e]),s=new WeakMap;export function renderableSearchText(t){const e=s.get(t);if(void 0!==e)return e;const r=function(t){let e="";switch(t.type){case"user":{const n=t.message.content;if("string"==typeof n)e=o.has(n)?"":n;else{const s=[];for(const e of n)"text"===e.type?o.has(e.text)||s.push(e.text):"tool_result"===e.type&&s.push(toolResultSearchText(t.toolUseResult));e=s.join("\n")}break}case"assistant":{const n=t.message.content;Array.isArray(n)&&(e=n.flatMap(t=>"text"===t.type?[t.text]:"tool_use"===t.type?[toolUseSearchText(t.input)]:[]).join("\n"));break}case"attachment":if("relevant_memories"===t.attachment.type)e=t.attachment.memories.map(t=>t.content).join("\n");else if("queued_command"===t.attachment.type&&"task-notification"!==t.attachment.commandMode&&!t.attachment.isMeta){const n=t.attachment.prompt;e="string"==typeof n?n:n.flatMap(t=>"text"===t.type?[t.text]:[]).join("\n")}break;case"collapsed_read_search":t.relevantMemories&&(e=t.relevantMemories.map(t=>t.content).join("\n"))}let s=e,r=s.indexOf("<system-reminder>");for(;r>=0;){const t=s.indexOf(n,r);if(t<0)break;s=s.slice(0,r)+s.slice(t+18),r=s.indexOf("<system-reminder>")}return s}(t).toLowerCase();return s.set(t,r),r}export function toolUseSearchText(t){if(!t||"object"!=typeof t)return"";const e=t,n=[];for(const t of["command","pattern","file_path","path","prompt","description","query","url","skill"]){const o=e[t];"string"==typeof o&&n.push(o)}for(const t of["args","files"]){const o=e[t];Array.isArray(o)&&o.every(t=>"string"==typeof t)&&n.push(o.join(" "))}return n.join("\n")}export function toolResultSearchText(t){if(!t||"object"!=typeof t)return"string"==typeof t?t:"";const e=t;if("string"==typeof e.stdout){const t="string"==typeof e.stderr?e.stderr:"";return e.stdout+(t?"\n"+t:"")}if(e.file&&"object"==typeof e.file&&"string"==typeof e.file.content)return e.file.content;const n=[];for(const t of["content","output","result","text","message"]){const o=e[t];"string"==typeof o&&n.push(o)}for(const t of["filenames","lines","results"]){const o=e[t];Array.isArray(o)&&o.every(t=>"string"==typeof t)&&n.push(o.join("\n"))}return n.join("\n")}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringWidth as t}from"../ink/stringWidth.js";import{getGraphemeSegmenter as
|
|
1
|
+
import{stringWidth as t}from"../ink/stringWidth.js";import{getGraphemeSegmenter as n}from"./intl.js";export function truncatePathMiddle(n,e){if(t(n)<=e)return n;if(e<=0)return"…";if(e<5)return truncateToWidth(n,e);const r=n.lastIndexOf("/"),i=r>=0?n.slice(r):n,o=r>=0?n.slice(0,r):"",u=t(i);if(u>=e-1)return truncateStartToWidth(n,e);const s=e-1-u;if(s<=0)return truncateStartToWidth(i,e);return truncateToWidthNoEllipsis(o,s)+"…"+i}export function truncateToWidth(e,r){if(t(e)<=r)return e;if(r<=1)return"…";let i=0,o="";for(const{segment:u}of n().segment(e)){const n=t(u);if(i+n>r-1)break;o+=u,i+=n}return o+"…"}export function truncateStartToWidth(e,r){if(t(e)<=r)return e;if(r<=1)return"…";const i=[...n().segment(e)];let o=0,u=i.length;for(let n=i.length-1;n>=0;n--){const e=t(i[n].segment);if(o+e>r-1)break;o+=e,u=n}return"…"+i.slice(u).map(t=>t.segment).join("")}export function truncateToWidthNoEllipsis(e,r){if(t(e)<=r)return e;if(r<=0)return"";let i=0,o="";for(const{segment:u}of n().segment(e)){const n=t(u);if(i+n>r)break;o+=u,i+=n}return o}export function truncate(n,e,r=!1){let i=n;if(r){const r=n.indexOf("\n");if(-1!==r)return i=n.substring(0,r),t(i)+1>e?truncateToWidth(i,e):`${i}…`}return t(i)<=e?i:truncateToWidth(i,e)}export function wrapText(e,r){const i=[];let o="",u=0;for(const{segment:s}of n().segment(e)){const n=t(s);u+n<=r?(o+=s,u+=n):(o&&i.push(o),o=s,u=n)}return o&&i.push(o),i}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const n={"`":"`",'"':'"',"<":">","{":"}","[":"]","(":")","'":"'"};function findKeywordTriggerPositions(t,r){if(!new RegExp(r,"i").test(t))return[];if(t.startsWith("/"))return[];const e=[];let i=null,o=0;const isWord=n=>!!n&&/[\p{L}\p{N}_]/u.test(n);for(let r=0;r<t.length;r++){const s=t[r];if(i){if("["===i&&"["===s){o=r;continue}if(s!==n[i])continue;if("'"===i&&isWord(t[r+1]))continue;e.push({start:o,end:r+1}),i=null}else("<"===s&&r+1<t.length&&/[a-zA-Z/]/.test(t[r+1])||"'"===s&&!isWord(t[r-1])||"<"!==s&&"'"!==s&&s in n)&&(i=s,o=r)}const s=[],l=new RegExp(`\\b${r}\\b`,"gi"),u=t.matchAll(l);for(const n of u){if(void 0===n.index)continue;const r=n.index,i=r+n[0].length;if(e.some(n=>r>=n.start&&r<n.end))continue;const o=t[r-1],l=t[i];"/"!==o&&"\\"!==o&&"-"!==o&&"/"!==l&&"\\"!==l&&"-"!==l&&"?"!==l&&("."===l&&isWord(t[i+1])||s.push({word:n[0],start:r,end:i}))}return s}export function findUltraplanTriggerPositions(n){return findKeywordTriggerPositions(n,"ultraplan")}export function findUltrareviewTriggerPositions(n){return findKeywordTriggerPositions(n,"ultrareview")}export function hasUltraplanKeyword(n){return findUltraplanTriggerPositions(n).length>0}export function hasUltrareviewKeyword(n){return findUltrareviewTriggerPositions(n).length>0}export function replaceUltraplanKeyword(n){const[t]=findUltraplanTriggerPositions(n);if(!t)return n;const r=n.slice(0,t.start),e=n.slice(t.end);return(r+e).trim()?r+t.word.slice(5)+e:""}
|
|
1
|
+
const n={"`":"`",'"':'"',"<":">","{":"}","[":"]","(":")","'":"'"};function findKeywordTriggerPositions(t,r){if(!new RegExp(r,"i").test(t))return[];if(t.startsWith("/"))return[];const e=[];let i=null,o=0;const isWord=n=>!!n&&/[\p{L}\p{N}_]/u.test(n);for(let r=0;r<t.length;r++){const s=t[r];if(i){if("["===i&&"["===s){o=r;continue}if(s!==n[i])continue;if("'"===i&&isWord(t[r+1]))continue;e.push({start:o,end:r+1}),i=null}else("<"===s&&r+1<t.length&&/[a-zA-Z/]/.test(t[r+1])||"'"===s&&!isWord(t[r-1])||"<"!==s&&"'"!==s&&s in n)&&(i=s,o=r)}const s=[],l=new RegExp(`\\b${r}\\b`,"gi"),u=t.matchAll(l);for(const n of u){if(void 0===n.index)continue;const r=n.index,i=r+n[0].length;if(e.some(n=>r>=n.start&&r<n.end))continue;const o=t[r-1],l=t[i];"/"!==o&&"\\"!==o&&"-"!==o&&("/"!==l&&"\\"!==l&&"-"!==l&&"?"!==l&&("."===l&&isWord(t[i+1])||s.push({word:n[0],start:r,end:i})))}return s}export function findUltraplanTriggerPositions(n){return findKeywordTriggerPositions(n,"ultraplan")}export function findUltrareviewTriggerPositions(n){return findKeywordTriggerPositions(n,"ultrareview")}export function hasUltraplanKeyword(n){return findUltraplanTriggerPositions(n).length>0}export function hasUltrareviewKeyword(n){return findUltrareviewTriggerPositions(n).length>0}export function replaceUltraplanKeyword(n){const[t]=findUltraplanTriggerPositions(n);if(!t)return n;const r=n.slice(0,t.start),e=n.slice(t.end);return(r+e).trim()?r+t.word.slice(5)+e:""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{logEvent as a}from"
|
|
1
|
+
import{logEvent as a}from"../services/analytics/index.js";export async function logUnaryEvent(e){a("tengu_unary_event",{event:e.event,completion_type:e.completion_type,language_name:await e.metadata.language_name,message_id:e.metadata.message_id,platform:e.metadata.platform,...void 0!==e.metadata.hasFeedback&&{hasFeedback:e.metadata.hasFeedback}})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getRepoClassCached as e}from"./commitAttribution.js";import{getGlobalConfig as n}from"./config.js";import{isEnvTruthy as o}from"./envUtils.js";export function isUndercover(){return
|
|
1
|
+
import{getRepoClassCached as e}from"./commitAttribution.js";import{getGlobalConfig as n}from"./config.js";import{isEnvTruthy as o}from"./envUtils.js";export function isUndercover(){return"ant"===process.env.USER_TYPE&&(!(!o(process.env.CONTEXT_CODE_UNDERCOVER)&&!o(process.env.CLAUDE_CODE_UNDERCOVER))||"internal"!==e())}export function getUndercoverInstructions(){return"ant"===process.env.USER_TYPE?'## UNDERCOVER MODE — CRITICAL\n\nYou are operating UNDERCOVER in a PUBLIC/OPEN-SOURCE repository. Your commit\nmessages, PR titles, and PR bodies MUST NOT contain ANY Anthropic-internal\ninformación. No reveles tu cobertura.\n\nNUNCA incluir en mensajes de commit o descripciones de PR:\n- Nombres de modelos internos (nombres de animales como Capybara, Tengu, etc.)\n- Números de versión de modelos no lanzados (ej., opus-4-8, sonnet-4-8)\n- Nombres de repos o proyectos internos (ej., claude-cli-internal, anthropics/…)\n- Herramientas internas, canales de Slack, o enlaces cortos (ej., go/cc, #claude-code-…)\n- La frase "Context Code" o cualquier mención de que eres una IA\n- Cualquier pista sobre qué modelo o versión eres\n- Líneas Co-Authored-By o cualquier otra atribución\n\nEscribe mensajes de commit como lo haría un desarrollador humano — describe solo qué hace\nel cambio de código.\n\nBUENO:\n- "Fix race condition in file watcher initialization"\n- "Add support for custom key bindings"\n- "Refactor parser for better error messages"\n\nMALO (nunca escribas estos):\n- "Fix bug found while testing with Claude Capybara"\n- "1-shotted by claude-opus-4-6"\n- "Generated with Context Code"\n- "Co-Authored-By: Claude Opus 4.6 <…>"\n':""}export function shouldShowUndercoverAutoNotice(){return"ant"===process.env.USER_TYPE&&(!o(process.env.CONTEXT_CODE_UNDERCOVER)&&!o(process.env.CLAUDE_CODE_UNDERCOVER)&&(!!isUndercover()&&!n().hasSeenUndercoverAutoNotice))}
|
package/dist/src/utils/user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MACRO as e}from"../recovery/bunBundleShim.js";import{execa as
|
|
1
|
+
import{MACRO as e}from"../recovery/bunBundleShim.js";import{execa as r}from"execa";import t from"lodash-es/memoize.js";import{getSessionId as o}from"../bootstrap/state.js";import{getOauthAccountInfo as s,getRateLimitTier as i,getSubscriptionType as n}from"./auth.js";import{getGlobalConfig as a,getOrCreateUserID as c}from"./config.js";import{getCwd as p}from"./cwd.js";import{getHostPlatformForAnalytics as m}from"./env.js";import{isEnvTruthy as l}from"./envUtils.js";let u=null,d=null;export async function initUser(){null!==u||d||(d=async function(){const e=s();if(e?.emailAddress)return e.emailAddress;if("ant"!==process.env.USER_TYPE)return;if(process.env.COO_CREATOR)return`${process.env.COO_CREATOR}@anthropic.com`;return getGitEmail()}(),u=await d,d=null,getCoreUserData.cache.clear?.())}export function resetUserCache(){u=null,d=null,getCoreUserData.cache.clear?.(),getGitEmail.cache.clear?.()}export const getCoreUserData=t(r=>{const t=c(),p=a();let u,d,T;if(r&&(u=n()??void 0,d=i()??void 0,u&&p.claudeCodeFirstTokenDate)){const e=new Date(p.claudeCodeFirstTokenDate).getTime();isNaN(e)||(T=e)}const O=s(),R=O?.organizationUuid,f=O?.accountUuid;return{deviceId:t,sessionId:o(),email:getEmail(),appVersion:e.VERSION,platform:m(),organizationUuid:R,accountUuid:f,userType:process.env.USER_TYPE,subscriptionType:u,rateLimitTier:d,firstTokenTime:T,...l(process.env.GITHUB_ACTIONS)&&{githubActionsMetadata:{actor:process.env.GITHUB_ACTOR,actorId:process.env.GITHUB_ACTOR_ID,repository:process.env.GITHUB_REPOSITORY,repositoryId:process.env.GITHUB_REPOSITORY_ID,repositoryOwner:process.env.GITHUB_REPOSITORY_OWNER,repositoryOwnerId:process.env.GITHUB_REPOSITORY_OWNER_ID}}}});export function getUserForGrowthBook(){return getCoreUserData(!0)}function getEmail(){if(null!==u)return u;const e=s();return e?.emailAddress?e.emailAddress:"ant"===process.env.USER_TYPE&&process.env.COO_CREATOR?`${process.env.COO_CREATOR}@anthropic.com`:void 0}export const getGitEmail=t(async()=>{const e=await r("git config --get user.email",{shell:!0,reject:!1,cwd:p()});return 0===e.exitCode&&e.stdout?e.stdout.trim():void 0});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function matchesNegativeKeyword(e){const t=e.toLowerCase();return/\b(wtf|wth|ffs|omfg|shit(ty|tiest)?|dumbass|horrible|awful|piss(ed|ing)? off|piece of (shit|crap|junk)|what the (fuck|hell)|fucking? (broken|useless|terrible|awful|horrible)|fuck you|screw (this|you)|so frustrating|this sucks|damn it)\b/.test(t)}export function matchesKeepGoingKeyword(e){const t=e.toLowerCase().trim();
|
|
1
|
+
export function matchesNegativeKeyword(e){const t=e.toLowerCase();return/\b(wtf|wth|ffs|omfg|shit(ty|tiest)?|dumbass|horrible|awful|piss(ed|ing)? off|piece of (shit|crap|junk)|what the (fuck|hell)|fucking? (broken|useless|terrible|awful|horrible)|fuck you|screw (this|you)|so frustrating|this sucks|damn it)\b/.test(t)}export function matchesKeepGoingKeyword(e){const t=e.toLowerCase().trim();if("continue"===t)return!0;return/\b(keep going|go on)\b/.test(t)}
|
package/dist/src/utils/which.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{execa as t}from"execa";import{execSync_DEPRECATED as
|
|
1
|
+
import{execa as t}from"execa";import{execSync_DEPRECATED as n}from"./execSyncWrapper.js";const e="undefined"!=typeof Bun&&"function"==typeof Bun.which?Bun.which:null;export const which=e?async t=>e(t):async function(n){if("win32"===process.platform){const e=await t(`where.exe ${n}`,{shell:!0,stderr:"ignore",reject:!1});return 0===e.exitCode&&e.stdout&&e.stdout.trim().split(/\r?\n/)[0]||null}const e=await t(`which ${n}`,{shell:!0,stderr:"ignore",reject:!1});return 0===e.exitCode&&e.stdout?e.stdout.trim():null};export const whichSync=e??function(t){if("win32"===process.platform)try{const e=n(`where.exe ${t}`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]});return e.toString().trim().split(/\r?\n/)[0]||null}catch{return null}try{return n(`which ${t}`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).toString().trim()||null}catch{return null}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"lodash-es/memoize.js";import*as t from"path";import*as r from"path/win32";import{getCwd as o}from"./cwd.js";import{logForDebugging as s}from"./debug.js";import{execSync_DEPRECATED as i}from"./execSyncWrapper.js";import{memoizeWithLRU as n}from"./memoize.js";import{getPlatform as a}from"./platform.js";function checkPathExists(e){try{return i(`dir "${e}"`,{stdio:"pipe"}),!0}catch{return!1}}export function setShellIfWindows(){if("windows"===a()){const e=findGitBashPath();process.env.SHELL=e,s(`Using bash path: "${e}"`)}}export const findGitBashPath=e(()=>{const e=process.env.CONTEXT_CODE_GIT_BASH_PATH??process.env.CLAUDE_CODE_GIT_BASH_PATH;if(e){if(checkPathExists(e))return e;console.error(`Context Code no pudo encontrar la ruta de CONTEXT_CODE_GIT_BASH_PATH "${e}"`),process.exit(1)}const n=function(){{const e=["C:\\Program Files\\Git\\cmd\\git.exe","C:\\Program Files (x86)\\Git\\cmd\\git.exe"];for(const t of e)if(checkPathExists(t))return t}try{const
|
|
1
|
+
import e from"lodash-es/memoize.js";import*as t from"path";import*as r from"path/win32";import{getCwd as o}from"./cwd.js";import{logForDebugging as s}from"./debug.js";import{execSync_DEPRECATED as i}from"./execSyncWrapper.js";import{memoizeWithLRU as n}from"./memoize.js";import{getPlatform as a}from"./platform.js";function checkPathExists(e){try{return i(`dir "${e}"`,{stdio:"pipe"}),!0}catch{return!1}}export function setShellIfWindows(){if("windows"===a()){const e=findGitBashPath();process.env.SHELL=e,s(`Using bash path: "${e}"`)}}export const findGitBashPath=e(()=>{const e=process.env.CONTEXT_CODE_GIT_BASH_PATH??process.env.CLAUDE_CODE_GIT_BASH_PATH;if(e){if(checkPathExists(e))return e;console.error(`Context Code no pudo encontrar la ruta de CONTEXT_CODE_GIT_BASH_PATH "${e}"`),process.exit(1)}const n=function(e){if("git"===e){const e=["C:\\Program Files\\Git\\cmd\\git.exe","C:\\Program Files (x86)\\Git\\cmd\\git.exe"];for(const t of e)if(checkPathExists(t))return t}try{const r=i(`where.exe ${e}`,{stdio:"pipe",encoding:"utf8"}).trim().split("\r\n").filter(Boolean),n=o().toLowerCase();for(const e of r){const r=t.resolve(e).toLowerCase();if(t.dirname(r).toLowerCase()!==n&&!r.startsWith(n+t.sep))return e;s(`Skipping potentially malicious executable in current directory: ${e}`)}return null}catch{return null}}("git");if(n){const e=r.join(n,"..","..","bin","bash.exe");if(checkPathExists(e))return e}console.error("Context Code en Windows requiere git-bash (https://git-scm.com/downloads/win). Si está instalado pero no está en el PATH, establece la variable de entorno que apunta a tu bash.exe, similar a: CONTEXT_CODE_GIT_BASH_PATH=C:\\Program Files\\Git\\bin\\bash.exe"),process.exit(1)});export const windowsPathToPosixPath=n(e=>{if(e.startsWith("\\\\"))return e.replace(/\\/g,"/");const t=e.match(/^([A-Za-z]):[/\\]/);if(t){return"/"+t[1].toLowerCase()+e.slice(2).replace(/\\/g,"/")}return e.replace(/\\/g,"/")},e=>e,500);export const posixPathToWindowsPath=n(e=>{if(e.startsWith("//"))return e.replace(/\//g,"\\");const t=e.match(/^\/cygdrive\/([A-Za-z])(\/|$)/);if(t){return t[1].toUpperCase()+":"+(e.slice(("/cygdrive/"+t[1]).length)||"\\").replace(/\//g,"\\")}const r=e.match(/^\/([A-Za-z])(\/|$)/);if(r){return r[1].toUpperCase()+":"+(e.slice(2)||"\\").replace(/\//g,"\\")}return e.replace(/\//g,"\\")},e=>e,500);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{feature as e}from"bun:bundle";import t from"chalk";import{spawnSync as r}from"child_process";import{copyFile as o,mkdir as n,readdir as a,readFile as s,stat as i,symlink as c,utimes as l}from"fs/promises";import d from"ignore";import{basename as u,dirname as w,join as m}from"path";import{saveCurrentProjectConfig as h}from"./config.js";import{getCwd as f}from"./cwd.js";import{logForDebugging as k}from"./debug.js";import{errorMessage as g,getErrnoCode as p}from"./errors.js";import{execFileNoThrow as x,execFileNoThrowWithCwd as $}from"./execFileNoThrow.js";import{parseGitConfigValue as v}from"./git/gitConfigParser.js";import{getCommonDir as C,readWorktreeHeadSha as y,resolveGitDir as b,resolveRef as W}from"./git/gitFilesystem.js";import{findCanonicalGitRoot as P,findGitRoot as S,getBranch as E,getDefaultBranch as T,gitExe as F}from"./git.js";import{executeWorktreeCreateHook as I,executeWorktreeRemoveHook as D,hasWorktreeCreateHook as R}from"./hooks.js";import{containsPathTraversal as A}from"./path.js";import{getPlatform as N}from"./platform.js";import{getInitialSettings as _,getRelativeSettingsFilePathForSource as B}from"./settings/settings.js";import{sleep as j}from"./sleep.js";import{isInITerm2 as M}from"./swarm/backends/detection.js";const O=/^[a-zA-Z0-9._-]+$/;export function validateWorktreeSlug(e){if(e.length>64)throw new Error(`Invalid worktree name: must be 64 characters or fewer (got ${e.length})`);for(const t of e.split("/")){if("."===t||".."===t)throw new Error(`Invalid worktree name "${e}": must not contain "." or ".." path segments`);if(!O.test(t))throw new Error(`Invalid worktree name "${e}": each "/"-separated segment must be non-empty and contain only letters, digits, dots, underscores, and dashes`)}}let H=null;export function getCurrentWorktreeSession(){return H}export function restoreWorktreeSession(e){H=e}export function generateTmuxSessionName(e,t){return`${u(e)}_${t}`.replace(/[/.]/g,"_")}const U={GIT_TERMINAL_PROMPT:"0",GIT_ASKPASS:""};function worktreesDir(e){return m(e,".context","worktrees")}function flattenSlug(e){return e.replaceAll("/","+")}export function worktreeBranchName(e){return`worktree-${flattenSlug(e)}`}function worktreePathFor(e,t){return m(worktreesDir(e),flattenSlug(t))}async function getOrCreateWorktree(e,t,r){const o=worktreePathFor(e,t),a=worktreeBranchName(t),s=await y(o);if(s)return{worktreePath:o,worktreeBranch:a,headCommit:s,existed:!0};await n(worktreesDir(e),{recursive:!0});const i={...process.env,...U};let c,l=null;if(r?.prNumber){const{code:t,stderr:o}=await $(F(),["fetch","origin",`pull/${r.prNumber}/head`],{cwd:e,stdin:"ignore",env:i});if(0!==t)throw new Error(`Failed to fetch PR #${r.prNumber}: ${o.trim()||'PR may not exist or the repository may not have a remote named "origin"'}`);c="FETCH_HEAD"}else{const[t,r]=await Promise.all([T(),b(e)]),o=`origin/${t}`,n=r?await W(r,`refs/remotes/origin/${t}`):null;if(n)c=o,l=n;else{const{code:r}=await $(F(),["fetch","origin",t],{cwd:e,stdin:"ignore",env:i});c=0===r?o:"HEAD"}}if(!l){const{stdout:t,code:r}=await $(F(),["rev-parse",c],{cwd:e});if(0!==r)throw new Error(`Failed to resolve base branch "${c}": git rev-parse failed`);l=t.trim()}const d=_().worktree?.sparsePaths,u=["worktree","add"];d?.length&&u.push("--no-checkout"),u.push("-B",a,o,c);const{code:w,stderr:m}=await $(F(),u,{cwd:e});if(0!==w)throw new Error(`Failed to create worktree: ${m}`);if(d?.length){const tearDown=async t=>{throw await $(F(),["worktree","remove","--force",o],{cwd:e}),new Error(t)},{code:t,stderr:r}=await $(F(),["sparse-checkout","set","--cone","--",...d],{cwd:o});0!==t&&await tearDown(`Failed to configure sparse-checkout: ${r}`);const{code:n,stderr:a}=await $(F(),["checkout","HEAD"],{cwd:o});0!==n&&await tearDown(`Failed to checkout sparse worktree: ${a}`)}return{worktreePath:o,worktreeBranch:a,headCommit:l,baseBranch:c,existed:!1}}export async function copyWorktreeIncludeFiles(e,t){let r;try{r=await s(m(e,".worktreeinclude"),"utf-8")}catch{return[]}const a=r.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith("#"));if(0===a.length)return[];const i=await $(F(),["ls-files","--others","--ignored","--exclude-standard","--directory"],{cwd:e});if(0!==i.code||!i.stdout.trim())return[];const c=i.stdout.trim().split("\n").filter(Boolean),l=d().add(r),u=c.filter(e=>e.endsWith("/")),h=c.filter(e=>!e.endsWith("/")&&l.ignores(e)),f=u.filter(e=>!!a.some(t=>{const r=t.startsWith("/")?t.slice(1):t;if(r.startsWith(e))return!0;const o=r.search(/[*?[]/);if(o>0){const t=r.slice(0,o);if(e.startsWith(t))return!0}return!1})||!!l.ignores(e.slice(0,-1)));if(f.length>0){const t=await $(F(),["ls-files","--others","--ignored","--exclude-standard","--",...f],{cwd:e});if(0===t.code&&t.stdout.trim())for(const e of t.stdout.trim().split("\n").filter(Boolean))l.ignores(e)&&h.push(e)}const g=[];for(const r of h){const a=m(e,r),s=m(t,r);try{await n(w(s),{recursive:!0}),await o(a,s),g.push(r)}catch(e){k(`Failed to copy ${r} to worktree: ${e.message}`,{level:"warn"})}}return g.length>0&&k(`Copied ${g.length} files from .worktreeinclude: ${g.join(", ")}`),g}async function performPostCreationSetup(t,r){const a=B("localSettings"),s=m(t,a);try{const e=m(r,a);await async function(e){await n(e,{recursive:!0})}(w(e)),await o(s,e),k(`Copied settings.local.json to worktree: ${e}`)}catch(e){"ENOENT"!==p(e)&&k(`Failed to copy settings.local.json: ${e.message}`,{level:"warn"})}const l=m(t,".husky"),d=m(t,".git","hooks");let u=null;for(const e of[l,d])try{if((await i(e)).isDirectory()){u=e;break}}catch{}if(u){const e=await b(t),o=e?await C(e)??e:null;if((o?await v(o,"core",null,"hooksPath"):null)!==u){const{code:e,stderr:t}=await $(F(),["config","core.hooksPath",u],{cwd:r});0===e?k(`Configured worktree to use hooks from main repository: ${u}`):k(`Failed to configure hooks path: ${t}`,{level:"error"})}}const h=_(),f=h.worktree?.symlinkDirectories??[];if(f.length>0&&await async function(e,t,r){for(const o of r){if(A(o)){k(`Skipping symlink for "${o}": path traversal detected`,{level:"warn"});continue}const r=m(e,o),n=m(t,o);try{await c(r,n,"dir"),k(`Symlinked ${o} from main repository to worktree to avoid disk bloat`)}catch(e){const t=p(e);"ENOENT"!==t&&"EEXIST"!==t&&k(`Failed to symlink ${o} (${t??"unknown"}): ${g(e)}`,{level:"warn"})}}}(t,r,f),await copyWorktreeIncludeFiles(t,r),e("COMMIT_ATTRIBUTION")){const e=u===l?m(r,".husky"):void 0;import("./postCommitAttribution.js").then(t=>t.installPrepareCommitMsgHook(r,e).catch(e=>{k(`Failed to install attribution hook in worktree: ${e}`)})).catch(e=>{k(`Failed to load postCommitAttribution module: ${e}`)})}}export function parsePRReference(e){const t=e.match(/^https?:\/\/[^/]+\/[^/]+\/[^/]+\/pull\/(\d+)\/?(?:[?#].*)?$/i);if(t?.[1])return parseInt(t[1],10);const r=e.match(/^#(\d+)$/);return r?.[1]?parseInt(r[1],10):null}export async function isTmuxAvailable(){const{code:e}=await x("tmux",["-V"]);return 0===e}export function getTmuxInstallInstructions(){switch(N()){case"macos":return"Install tmux with: brew install tmux";case"linux":case"wsl":return"Install tmux with: sudo apt install tmux (Debian/Ubuntu) or sudo dnf install tmux (Fedora/RHEL)";case"windows":return"tmux is not natively available on Windows. Consider using WSL or Cygwin.";default:return"Install tmux using your system package manager."}}export async function createTmuxSessionForWorktree(e,t){const{code:r,stderr:o}=await x("tmux",["new-session","-d","-s",e,"-c",t]);return 0!==r?{created:!1,error:o}:{created:!0}}export async function killTmuxSession(e){const{code:t}=await x("tmux",["kill-session","-t",e]);return 0===t}export async function createWorktreeForSession(e,t,r,o){validateWorktreeSlug(t);const n=f();if(R()){const o=await I(t);k(`Created hook-based worktree at: ${o.worktreePath}`),H={originalCwd:n,worktreePath:o.worktreePath,worktreeName:t,sessionId:e,tmuxSessionName:r,hookBased:!0}}else{const a=S(f());if(!a)throw new Error("Cannot create a worktree: not in a git repository and no WorktreeCreate hooks are configured. Configure WorktreeCreate/WorktreeRemove hooks in settings.json to use worktree isolation with other VCS systems.");const s=await E(),i=Date.now(),{worktreePath:c,worktreeBranch:l,headCommit:d,existed:u}=await getOrCreateWorktree(a,t,o);let w;u?k(`Resuming existing worktree at: ${c}`):(k(`Created worktree at: ${c} on branch: ${l}`),await performPostCreationSetup(a,c),w=Date.now()-i),H={originalCwd:n,worktreePath:c,worktreeName:t,worktreeBranch:l,originalBranch:s,originalHeadCommit:d,sessionId:e,tmuxSessionName:r,creationDurationMs:w,usedSparsePaths:(_().worktree?.sparsePaths?.length??0)>0}}return h(e=>({...e,activeWorktreeSession:H??void 0})),H}export async function keepWorktree(){if(H)try{const{worktreePath:e,originalCwd:t,worktreeBranch:r}=H;process.chdir(t),H=null,h(e=>({...e,activeWorktreeSession:void 0})),k(`Linked worktree preserved at: ${e}${r?` on branch: ${r}`:""}`),k(`You can continue working there by running: cd ${e}`)}catch(e){k(`Error keeping worktree: ${e}`,{level:"error"})}}export async function cleanupWorktree(){if(H)try{const{worktreePath:e,originalCwd:t,worktreeBranch:r,hookBased:o}=H;if(process.chdir(t),o)await D(e)?k(`Removed hook-based worktree at: ${e}`):k(`No WorktreeRemove hook configured, hook-based worktree left at: ${e}`,{level:"warn"});else{const{code:r,stderr:o}=await $(F(),["worktree","remove","--force",e],{cwd:t});0!==r?k(`Failed to remove linked worktree: ${o}`,{level:"error"}):k(`Removed linked worktree at: ${e}`)}if(H=null,h(e=>({...e,activeWorktreeSession:void 0})),!o&&r){await j(100);const{code:e,stderr:o}=await $(F(),["branch","-D",r],{cwd:t});0!==e?k(`Could not delete worktree branch: ${o}`,{level:"error"}):k(`Deleted worktree branch: ${r}`)}k("Linked worktree cleaned up completely")}catch(e){k(`Error cleaning up worktree: ${e}`,{level:"error"})}}export async function createAgentWorktree(e){if(validateWorktreeSlug(e),R()){const t=await I(e);return k(`Created hook-based agent worktree at: ${t.worktreePath}`),{worktreePath:t.worktreePath,hookBased:!0}}const t=P(f());if(!t)throw new Error("Cannot create agent worktree: not in a git repository and no WorktreeCreate hooks are configured. Configure WorktreeCreate/WorktreeRemove hooks in settings.json to use worktree isolation with other VCS systems.");const{worktreePath:r,worktreeBranch:o,headCommit:n,existed:a}=await getOrCreateWorktree(t,e);if(a){const e=new Date;await l(r,e,e),k(`Resuming existing agent worktree at: ${r}`)}else k(`Created agent worktree at: ${r} on branch: ${o}`),await performPostCreationSetup(t,r);return{worktreePath:r,worktreeBranch:o,headCommit:n,gitRoot:t}}export async function removeAgentWorktree(e,t,r,o){if(o){const t=await D(e);return t?k(`Removed hook-based agent worktree at: ${e}`):k(`No WorktreeRemove hook configured, hook-based agent worktree left at: ${e}`,{level:"warn"}),t}if(!r)return k("Cannot remove agent worktree: no git root provided",{level:"error"}),!1;const{code:n,stderr:a}=await $(F(),["worktree","remove","--force",e],{cwd:r});if(0!==n)return k(`Failed to remove agent worktree: ${a}`,{level:"error"}),!1;if(k(`Removed agent worktree at: ${e}`),!t)return!0;const{code:s,stderr:i}=await $(F(),["branch","-D",t],{cwd:r});return 0!==s&&k(`Could not delete agent worktree branch: ${i}`,{level:"error"}),!0}const L=[/^agent-a[0-9a-f]{7}$/,/^wf_[0-9a-f]{8}-[0-9a-f]{3}-\d+$/,/^wf-\d+$/,/^bridge-[A-Za-z0-9_]+(-[A-Za-z0-9_]+)*$/,/^job-[a-zA-Z0-9._-]{1,55}-[0-9a-f]{8}$/];export async function cleanupStaleAgentWorktrees(e){const t=P(f());if(!t)return 0;const r=worktreesDir(t);let o;try{o=await a(r)}catch{return 0}const n=e.getTime(),s=H?.worktreePath;let c=0;for(const e of o){if(!L.some(t=>t.test(e)))continue;const o=m(r,e);if(s===o)continue;let a;try{a=(await i(o)).mtimeMs}catch{continue}if(a>=n)continue;const[l,d]=await Promise.all([$(F(),["--no-optional-locks","status","--porcelain","-uno"],{cwd:o}),$(F(),["rev-list","--max-count=1","HEAD","--not","--remotes"],{cwd:o})]);0!==l.code||l.stdout.trim().length>0||0!==d.code||d.stdout.trim().length>0||await removeAgentWorktree(o,worktreeBranchName(e),t)&&c++}return c>0&&(await $(F(),["worktree","prune"],{cwd:t}),k(`cleanupStaleAgentWorktrees: removed ${c} stale worktree(s)`)),c}export async function hasWorktreeChanges(e,t){const{code:r,stdout:o}=await $(F(),["status","--porcelain"],{cwd:e});if(0!==r)return!0;if(o.trim().length>0)return!0;const{code:n,stdout:a}=await $(F(),["rev-list","--count",`${t}..HEAD`],{cwd:e});return 0!==n||parseInt(a.trim(),10)>0}export async function execIntoTmuxWorktree(e){if("win32"===process.platform)return{handled:!1,error:"Error: --tmux is not supported on Windows"};if(0!==r("tmux",["-V"],{encoding:"utf-8"}).status)return{handled:!1,error:"Error: tmux is not installed. "+("darwin"===process.platform?"Install tmux with: brew install tmux":"Install tmux with: sudo apt install tmux")};let o,n=!1;for(let t=0;t<e.length;t++){const r=e[t];if(r)if("-w"===r||"--worktree"===r){const r=e[t+1];r&&!r.startsWith("-")&&(o=r)}else r.startsWith("--worktree=")?o=r.slice(11):"--tmux=classic"===r&&(n=!0)}let a,s,i=null;if(o&&(i=parsePRReference(o),null!==i&&(o=`pr-${i}`)),!o){const e=["swift","bright","calm","keen","bold"],t=["fox","owl","elm","oak","ray"];o=`${e[Math.floor(Math.random()*e.length)]}-${t[Math.floor(Math.random()*t.length)]}-${Math.random().toString(36).slice(2,6)}`}try{validateWorktreeSlug(o)}catch(e){return{handled:!1,error:`Error: ${e.message}`}}if(R()){try{a=(await I(o)).worktreePath}catch(e){return{handled:!1,error:`Error: ${g(e)}`}}s=u(P(f())??f()),console.log(`Using worktree via hook: ${a}`)}else{const t=P(f());if(!t)return{handled:!1,error:"Error: --worktree requires a git repository"};s=u(t),a=worktreePathFor(t,o);try{const e=await getOrCreateWorktree(t,o,null!==i?{prNumber:i}:void 0);e.existed||(console.log(`Created worktree: ${a} (based on ${e.baseBranch})`),await performPostCreationSetup(t,a))}catch(e){return{handled:!1,error:`Error: ${g(e)}`}}}const c=`${s}_${worktreeBranchName(o)}`.replace(/[/.]/g,"_"),l=[];for(let t=0;t<e.length;t++){const r=e[t];if(r&&"--tmux"!==r&&"--tmux=classic"!==r){if("-w"===r||"--worktree"===r){const r=e[t+1];r&&!r.startsWith("-")&&t++;continue}r.startsWith("--worktree=")||l.push(r)}}let d="C-b";const w=r("tmux",["show-options","-g","prefix"],{encoding:"utf-8"});if(0===w.status&&w.stdout){const e=w.stdout.match(/prefix\s+(\S+)/);e?.[1]&&(d=e[1])}const m=["C-b","C-c","C-d","C-t","C-o","C-r","C-s","C-g","C-e"].includes(d),h={...process.env,CLAUDE_CODE_TMUX_SESSION:c,CLAUDE_CODE_TMUX_PREFIX:d,CLAUDE_CODE_TMUX_PREFIX_CONFLICTS:m?"1":""},k=0===r("tmux",["has-session","-t",c],{encoding:"utf-8"}).status,p=Boolean(process.env.TMUX),x=M()&&!n&&!p,$=x?["-CC"]:[];if(x&&!k){const e=t.yellow;console.log(`\n${e("╭─ iTerm2 Tip ────────────────────────────────────────────────────────╮")}\n${e("│")} To open as a tab instead of a new window: ${e("│")}\n${e("│")} iTerm2 > Settings > General > tmux > "Tabs in attaching window" ${e("│")}\n${e("╰─────────────────────────────────────────────────────────────────────╯")}\n`)}if("ant"!==process.env.USER_TYPE||"claude-cli-internal"!==s||k)if(p)k||r("tmux",["new-session","-d","-s",c,"-c",a,"--",process.execPath,...l],{cwd:a,env:h}),r("tmux",["switch-client","-t",c],{stdio:"inherit"});else{const e=[...$,"new-session","-A","-s",c,"-c",a,"--",process.execPath,...l];r("tmux",e,{stdio:"inherit",cwd:a,env:h})}else r("tmux",["new-session","-d","-s",c,"-c",a,"--",process.execPath,...l],{cwd:a,env:h}),r("tmux",["split-window","-h","-t",c,"-c",a],{cwd:a}),r("tmux",["send-keys","-t",c,"bun run watch","Enter"],{cwd:a}),r("tmux",["split-window","-v","-t",c,"-c",a],{cwd:a}),r("tmux",["send-keys","-t",c,"bun run start"],{cwd:a}),r("tmux",["select-pane","-t",`${c}:0.0`],{cwd:a}),p?r("tmux",["switch-client","-t",c],{stdio:"inherit"}):r("tmux",[...$,"attach-session","-t",c],{stdio:"inherit",cwd:a});return{handled:!0}}
|
|
1
|
+
import{feature as e}from"../recovery/bunBundleShim.js";import t from"chalk";import{spawnSync as r}from"child_process";import{copyFile as o,mkdir as n,readdir as a,readFile as s,stat as i,symlink as c,utimes as l}from"fs/promises";import d from"ignore";import{basename as w,dirname as u,join as m}from"path";import{saveCurrentProjectConfig as h}from"./config.js";import{getCwd as f}from"./cwd.js";import{logForDebugging as k}from"./debug.js";import{errorMessage as p,getErrnoCode as g}from"./errors.js";import{execFileNoThrow as $,execFileNoThrowWithCwd as x}from"./execFileNoThrow.js";import{parseGitConfigValue as v}from"./git/gitConfigParser.js";import{getCommonDir as C,readWorktreeHeadSha as y,resolveGitDir as b,resolveRef as W}from"./git/gitFilesystem.js";import{findCanonicalGitRoot as P,findGitRoot as S,getBranch as E,getDefaultBranch as T,gitExe as I}from"./git.js";import{executeWorktreeCreateHook as F,executeWorktreeRemoveHook as A,hasWorktreeCreateHook as _}from"./hooks.js";import{containsPathTraversal as D}from"./path.js";import{getPlatform as B}from"./platform.js";import{getInitialSettings as N,getRelativeSettingsFilePathForSource as R}from"./settings/settings.js";import{sleep as j}from"./sleep.js";import{isInITerm2 as M}from"./swarm/backends/detection.js";const O=/^[a-zA-Z0-9._-]+$/;export function validateWorktreeSlug(e){if(e.length>64)throw new Error(`Invalid worktree name: must be 64 characters or fewer (got ${e.length})`);for(const t of e.split("/")){if("."===t||".."===t)throw new Error(`Invalid worktree name "${e}": must not contain "." or ".." path segments`);if(!O.test(t))throw new Error(`Invalid worktree name "${e}": each "/"-separated segment must be non-empty and contain only letters, digits, dots, underscores, and dashes`)}}let U=null;export function getCurrentWorktreeSession(){return U}export function restoreWorktreeSession(e){U=e}export function generateTmuxSessionName(e,t){return`${w(e)}_${t}`.replace(/[/.]/g,"_")}const H={GIT_TERMINAL_PROMPT:"0",GIT_ASKPASS:""};function worktreesDir(e){return m(e,".context","worktrees")}function flattenSlug(e){return e.replaceAll("/","+")}export function worktreeBranchName(e){return`worktree-${flattenSlug(e)}`}function worktreePathFor(e,t){return m(worktreesDir(e),flattenSlug(t))}async function getOrCreateWorktree(e,t,r){const o=worktreePathFor(e,t),a=worktreeBranchName(t),s=await y(o);if(s)return{worktreePath:o,worktreeBranch:a,headCommit:s,existed:!0};await n(worktreesDir(e),{recursive:!0});const i={...process.env,...H};let c,l=null;if(r?.prNumber){const{code:t,stderr:o}=await x(I(),["fetch","origin",`pull/${r.prNumber}/head`],{cwd:e,stdin:"ignore",env:i});if(0!==t)throw new Error(`Failed to fetch PR #${r.prNumber}: ${o.trim()||'PR may not exist or the repository may not have a remote named "origin"'}`);c="FETCH_HEAD"}else{const[t,r]=await Promise.all([T(),b(e)]),o=`origin/${t}`,n=r?await W(r,`refs/remotes/origin/${t}`):null;if(n)c=o,l=n;else{const{code:r}=await x(I(),["fetch","origin",t],{cwd:e,stdin:"ignore",env:i});c=0===r?o:"HEAD"}}if(!l){const{stdout:t,code:r}=await x(I(),["rev-parse",c],{cwd:e});if(0!==r)throw new Error(`Failed to resolve base branch "${c}": git rev-parse failed`);l=t.trim()}const d=N().worktree?.sparsePaths,w=["worktree","add"];d?.length&&w.push("--no-checkout"),w.push("-B",a,o,c);const{code:u,stderr:m}=await x(I(),w,{cwd:e});if(0!==u)throw new Error(`Failed to create worktree: ${m}`);if(d?.length){const tearDown=async t=>{throw await x(I(),["worktree","remove","--force",o],{cwd:e}),new Error(t)},{code:t,stderr:r}=await x(I(),["sparse-checkout","set","--cone","--",...d],{cwd:o});0!==t&&await tearDown(`Failed to configure sparse-checkout: ${r}`);const{code:n,stderr:a}=await x(I(),["checkout","HEAD"],{cwd:o});0!==n&&await tearDown(`Failed to checkout sparse worktree: ${a}`)}return{worktreePath:o,worktreeBranch:a,headCommit:l,baseBranch:c,existed:!1}}export async function copyWorktreeIncludeFiles(e,t){let r;try{r=await s(m(e,".worktreeinclude"),"utf-8")}catch{return[]}const a=r.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith("#"));if(0===a.length)return[];const i=await x(I(),["ls-files","--others","--ignored","--exclude-standard","--directory"],{cwd:e});if(0!==i.code||!i.stdout.trim())return[];const c=i.stdout.trim().split("\n").filter(Boolean),l=d().add(r),w=c.filter(e=>e.endsWith("/")),h=c.filter(e=>!e.endsWith("/")&&l.ignores(e)),f=w.filter(e=>!!a.some(t=>{const r=t.startsWith("/")?t.slice(1):t;if(r.startsWith(e))return!0;const o=r.search(/[*?[]/);if(o>0){const t=r.slice(0,o);if(e.startsWith(t))return!0}return!1})||!!l.ignores(e.slice(0,-1)));if(f.length>0){const t=await x(I(),["ls-files","--others","--ignored","--exclude-standard","--",...f],{cwd:e});if(0===t.code&&t.stdout.trim())for(const e of t.stdout.trim().split("\n").filter(Boolean))l.ignores(e)&&h.push(e)}const p=[];for(const r of h){const a=m(e,r),s=m(t,r);try{await n(u(s),{recursive:!0}),await o(a,s),p.push(r)}catch(e){k(`Failed to copy ${r} to worktree: ${e.message}`,{level:"warn"})}}return p.length>0&&k(`Copied ${p.length} files from .worktreeinclude: ${p.join(", ")}`),p}async function performPostCreationSetup(t,r){const a=R("localSettings"),s=m(t,a);try{const e=m(r,a);await async function(e){await n(e,{recursive:!0})}(u(e)),await o(s,e),k(`Copied settings.local.json to worktree: ${e}`)}catch(e){"ENOENT"!==g(e)&&k(`Failed to copy settings.local.json: ${e.message}`,{level:"warn"})}const l=m(t,".husky"),d=m(t,".git","hooks");let w=null;for(const e of[l,d])try{if((await i(e)).isDirectory()){w=e;break}}catch{}if(w){const e=await b(t),o=e?await C(e)??e:null;if((o?await v(o,"core",null,"hooksPath"):null)!==w){const{code:e,stderr:t}=await x(I(),["config","core.hooksPath",w],{cwd:r});0===e?k(`Configured worktree to use hooks from main repository: ${w}`):k(`Failed to configure hooks path: ${t}`,{level:"error"})}}const h=N(),f=h.worktree?.symlinkDirectories??[];if(f.length>0&&await async function(e,t,r){for(const o of r){if(D(o)){k(`Skipping symlink for "${o}": path traversal detected`,{level:"warn"});continue}const r=m(e,o),n=m(t,o);try{await c(r,n,"dir"),k(`Symlinked ${o} from main repository to worktree to avoid disk bloat`)}catch(e){const t=g(e);"ENOENT"!==t&&"EEXIST"!==t&&k(`Failed to symlink ${o} (${t??"unknown"}): ${p(e)}`,{level:"warn"})}}}(t,r,f),await copyWorktreeIncludeFiles(t,r),e("COMMIT_ATTRIBUTION")){const e=w===l?m(r,".husky"):void 0;import("./postCommitAttribution.js").then(t=>t.installPrepareCommitMsgHook(r,e).catch(e=>{k(`Failed to install attribution hook in worktree: ${e}`)})).catch(e=>{k(`Failed to load postCommitAttribution module: ${e}`)})}}export function parsePRReference(e){const t=e.match(/^https?:\/\/[^/]+\/[^/]+\/[^/]+\/pull\/(\d+)\/?(?:[?#].*)?$/i);if(t?.[1])return parseInt(t[1],10);const r=e.match(/^#(\d+)$/);return r?.[1]?parseInt(r[1],10):null}export async function isTmuxAvailable(){const{code:e}=await $("tmux",["-V"]);return 0===e}export function getTmuxInstallInstructions(){switch(B()){case"macos":return"Install tmux with: brew install tmux";case"linux":case"wsl":return"Install tmux with: sudo apt install tmux (Debian/Ubuntu) or sudo dnf install tmux (Fedora/RHEL)";case"windows":return"tmux is not natively available on Windows. Consider using WSL or Cygwin.";default:return"Install tmux using your system package manager."}}export async function createTmuxSessionForWorktree(e,t){const{code:r,stderr:o}=await $("tmux",["new-session","-d","-s",e,"-c",t]);return 0!==r?{created:!1,error:o}:{created:!0}}export async function killTmuxSession(e){const{code:t}=await $("tmux",["kill-session","-t",e]);return 0===t}export async function createWorktreeForSession(e,t,r,o){validateWorktreeSlug(t);const n=f();if(_()){const o=await F(t);k(`Created hook-based worktree at: ${o.worktreePath}`),U={originalCwd:n,worktreePath:o.worktreePath,worktreeName:t,sessionId:e,tmuxSessionName:r,hookBased:!0}}else{const a=S(f());if(!a)throw new Error("Cannot create a worktree: not in a git repository and no WorktreeCreate hooks are configured. Configure WorktreeCreate/WorktreeRemove hooks in settings.json to use worktree isolation with other VCS systems.");const s=await E(),i=Date.now(),{worktreePath:c,worktreeBranch:l,headCommit:d,existed:w}=await getOrCreateWorktree(a,t,o);let u;w?k(`Resuming existing worktree at: ${c}`):(k(`Created worktree at: ${c} on branch: ${l}`),await performPostCreationSetup(a,c),u=Date.now()-i),U={originalCwd:n,worktreePath:c,worktreeName:t,worktreeBranch:l,originalBranch:s,originalHeadCommit:d,sessionId:e,tmuxSessionName:r,creationDurationMs:u,usedSparsePaths:(N().worktree?.sparsePaths?.length??0)>0}}return h(e=>({...e,activeWorktreeSession:U??void 0})),U}export async function keepWorktree(){if(U)try{const{worktreePath:e,originalCwd:t,worktreeBranch:r}=U;process.chdir(t),U=null,h(e=>({...e,activeWorktreeSession:void 0})),k(`Linked worktree preserved at: ${e}${r?` on branch: ${r}`:""}`),k(`You can continue working there by running: cd ${e}`)}catch(e){k(`Error keeping worktree: ${e}`,{level:"error"})}}export async function cleanupWorktree(){if(U)try{const{worktreePath:e,originalCwd:t,worktreeBranch:r,hookBased:o}=U;if(process.chdir(t),o){await A(e)?k(`Removed hook-based worktree at: ${e}`):k(`No WorktreeRemove hook configured, hook-based worktree left at: ${e}`,{level:"warn"})}else{const{code:r,stderr:o}=await x(I(),["worktree","remove","--force",e],{cwd:t});0!==r?k(`Failed to remove linked worktree: ${o}`,{level:"error"}):k(`Removed linked worktree at: ${e}`)}if(U=null,h(e=>({...e,activeWorktreeSession:void 0})),!o&&r){await j(100);const{code:e,stderr:o}=await x(I(),["branch","-D",r],{cwd:t});0!==e?k(`Could not delete worktree branch: ${o}`,{level:"error"}):k(`Deleted worktree branch: ${r}`)}k("Linked worktree cleaned up completely")}catch(e){k(`Error cleaning up worktree: ${e}`,{level:"error"})}}export async function createAgentWorktree(e){if(validateWorktreeSlug(e),_()){const t=await F(e);return k(`Created hook-based agent worktree at: ${t.worktreePath}`),{worktreePath:t.worktreePath,hookBased:!0}}const t=P(f());if(!t)throw new Error("Cannot create agent worktree: not in a git repository and no WorktreeCreate hooks are configured. Configure WorktreeCreate/WorktreeRemove hooks in settings.json to use worktree isolation with other VCS systems.");const{worktreePath:r,worktreeBranch:o,headCommit:n,existed:a}=await getOrCreateWorktree(t,e);if(a){const e=new Date;await l(r,e,e),k(`Resuming existing agent worktree at: ${r}`)}else k(`Created agent worktree at: ${r} on branch: ${o}`),await performPostCreationSetup(t,r);return{worktreePath:r,worktreeBranch:o,headCommit:n,gitRoot:t}}export async function removeAgentWorktree(e,t,r,o){if(o){const t=await A(e);return t?k(`Removed hook-based agent worktree at: ${e}`):k(`No WorktreeRemove hook configured, hook-based agent worktree left at: ${e}`,{level:"warn"}),t}if(!r)return k("Cannot remove agent worktree: no git root provided",{level:"error"}),!1;const{code:n,stderr:a}=await x(I(),["worktree","remove","--force",e],{cwd:r});if(0!==n)return k(`Failed to remove agent worktree: ${a}`,{level:"error"}),!1;if(k(`Removed agent worktree at: ${e}`),!t)return!0;const{code:s,stderr:i}=await x(I(),["branch","-D",t],{cwd:r});return 0!==s&&k(`Could not delete agent worktree branch: ${i}`,{level:"error"}),!0}const L=[/^agent-a[0-9a-f]{7}$/,/^wf_[0-9a-f]{8}-[0-9a-f]{3}-\d+$/,/^wf-\d+$/,/^bridge-[A-Za-z0-9_]+(-[A-Za-z0-9_]+)*$/,/^job-[a-zA-Z0-9._-]{1,55}-[0-9a-f]{8}$/];export async function cleanupStaleAgentWorktrees(e){const t=P(f());if(!t)return 0;const r=worktreesDir(t);let o;try{o=await a(r)}catch{return 0}const n=e.getTime(),s=U?.worktreePath;let c=0;for(const e of o){if(!L.some(t=>t.test(e)))continue;const o=m(r,e);if(s===o)continue;let a;try{a=(await i(o)).mtimeMs}catch{continue}if(a>=n)continue;const[l,d]=await Promise.all([x(I(),["--no-optional-locks","status","--porcelain","-uno"],{cwd:o}),x(I(),["rev-list","--max-count=1","HEAD","--not","--remotes"],{cwd:o})]);0!==l.code||l.stdout.trim().length>0||(0!==d.code||d.stdout.trim().length>0||await removeAgentWorktree(o,worktreeBranchName(e),t)&&c++)}return c>0&&(await x(I(),["worktree","prune"],{cwd:t}),k(`cleanupStaleAgentWorktrees: removed ${c} stale worktree(s)`)),c}export async function hasWorktreeChanges(e,t){const{code:r,stdout:o}=await x(I(),["status","--porcelain"],{cwd:e});if(0!==r)return!0;if(o.trim().length>0)return!0;const{code:n,stdout:a}=await x(I(),["rev-list","--count",`${t}..HEAD`],{cwd:e});return 0!==n||parseInt(a.trim(),10)>0}export async function execIntoTmuxWorktree(e){if("win32"===process.platform)return{handled:!1,error:"Error: --tmux is not supported on Windows"};if(0!==r("tmux",["-V"],{encoding:"utf-8"}).status){return{handled:!1,error:`Error: tmux is not installed. ${"darwin"===process.platform?"Install tmux with: brew install tmux":"Install tmux with: sudo apt install tmux"}`}}let o,n=!1;for(let t=0;t<e.length;t++){const r=e[t];if(r)if("-w"===r||"--worktree"===r){const r=e[t+1];r&&!r.startsWith("-")&&(o=r)}else r.startsWith("--worktree=")?o=r.slice(11):"--tmux=classic"===r&&(n=!0)}let a,s,i=null;if(o&&(i=parsePRReference(o),null!==i&&(o=`pr-${i}`)),!o){const e=["swift","bright","calm","keen","bold"],t=["fox","owl","elm","oak","ray"];o=`${e[Math.floor(Math.random()*e.length)]}-${t[Math.floor(Math.random()*t.length)]}-${Math.random().toString(36).slice(2,6)}`}try{validateWorktreeSlug(o)}catch(e){return{handled:!1,error:`Error: ${e.message}`}}if(_()){try{a=(await F(o)).worktreePath}catch(e){return{handled:!1,error:`Error: ${p(e)}`}}s=w(P(f())??f()),console.log(`Using worktree via hook: ${a}`)}else{const e=P(f());if(!e)return{handled:!1,error:"Error: --worktree requires a git repository"};s=w(e),a=worktreePathFor(e,o);try{const t=await getOrCreateWorktree(e,o,null!==i?{prNumber:i}:void 0);t.existed||(console.log(`Created worktree: ${a} (based on ${t.baseBranch})`),await performPostCreationSetup(e,a))}catch(e){return{handled:!1,error:`Error: ${p(e)}`}}}const c=`${s}_${worktreeBranchName(o)}`.replace(/[/.]/g,"_"),l=[];for(let t=0;t<e.length;t++){const r=e[t];if(r&&("--tmux"!==r&&"--tmux=classic"!==r)){if("-w"===r||"--worktree"===r){const r=e[t+1];r&&!r.startsWith("-")&&t++;continue}r.startsWith("--worktree=")||l.push(r)}}let d="C-b";const u=r("tmux",["show-options","-g","prefix"],{encoding:"utf-8"});if(0===u.status&&u.stdout){const e=u.stdout.match(/prefix\s+(\S+)/);e?.[1]&&(d=e[1])}const m=["C-b","C-c","C-d","C-t","C-o","C-r","C-s","C-g","C-e"].includes(d),h={...process.env,CLAUDE_CODE_TMUX_SESSION:c,CLAUDE_CODE_TMUX_PREFIX:d,CLAUDE_CODE_TMUX_PREFIX_CONFLICTS:m?"1":""},k=0===r("tmux",["has-session","-t",c],{encoding:"utf-8"}).status,g=Boolean(process.env.TMUX),$=M()&&!n&&!g,x=$?["-CC"]:[];if($&&!k){const e=t.yellow;console.log(`\n${e("╭─ iTerm2 Tip ────────────────────────────────────────────────────────╮")}\n${e("│")} To open as a tab instead of a new window: ${e("│")}\n${e("│")} iTerm2 > Settings > General > tmux > "Tabs in attaching window" ${e("│")}\n${e("╰─────────────────────────────────────────────────────────────────────╯")}\n`)}if("ant"===process.env.USER_TYPE&&"claude-cli-internal"===s&&!k)r("tmux",["new-session","-d","-s",c,"-c",a,"--",process.execPath,...l],{cwd:a,env:h}),r("tmux",["split-window","-h","-t",c,"-c",a],{cwd:a}),r("tmux",["send-keys","-t",c,"bun run watch","Enter"],{cwd:a}),r("tmux",["split-window","-v","-t",c,"-c",a],{cwd:a}),r("tmux",["send-keys","-t",c,"bun run start"],{cwd:a}),r("tmux",["select-pane","-t",`${c}:0.0`],{cwd:a}),g?r("tmux",["switch-client","-t",c],{stdio:"inherit"}):r("tmux",[...x,"attach-session","-t",c],{stdio:"inherit",cwd:a});else if(g)k||r("tmux",["new-session","-d","-s",c,"-c",a,"--",process.execPath,...l],{cwd:a,env:h}),r("tmux",["switch-client","-t",c],{stdio:"inherit"});else{const e=[...x,"new-session","-A","-s",c,"-c",a,"--",process.execPath,...l];r("tmux",e,{stdio:"inherit",cwd:a,env:h})}return{handled:!0}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toJSONSchema as o}from"zod/v4";const t=new WeakMap;export function zodToJsonSchema(
|
|
1
|
+
import{toJSONSchema as o}from"zod/v4";const t=new WeakMap;export function zodToJsonSchema(n){const e=t.get(n);if(e)return e;const r=o(n);return t.set(n,r),r}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Cursor as e}from"../utils/Cursor.js";import{firstGrapheme as t,lastGrapheme as n}from"../utils/intl.js";import{countCharInString as s}from"../utils/stringUtils.js";import{isInclusiveMotion as o,isLinewiseMotion as r,resolveMotion as i}from"./motions.js";import{findTextObject as c}from"./textObjects.js";export function executeOperatorMotion(e,t,n,s){const o=i(t,s.cursor,n);if(o.equals(s.cursor))return;const r=getOperatorRange(s.cursor,o,t,e,n);applyOperator(e,r.from,r.to,s,r.linewise),s.recordChange({type:"operator",op:e,motion:t,count:n})}export function executeOperatorFind(t,n,s,o,r){const i=r.cursor.findCharacter(s,n,o);if(null===i)return;const c=new e(r.cursor.measuredText,i),f=function(e,t){const n=Math.min(e.offset,t.offset),s=Math.max(e.offset,t.offset);return{from:n,to:
|
|
1
|
+
import{Cursor as e}from"../utils/Cursor.js";import{firstGrapheme as t,lastGrapheme as n}from"../utils/intl.js";import{countCharInString as s}from"../utils/stringUtils.js";import{isInclusiveMotion as o,isLinewiseMotion as r,resolveMotion as i}from"./motions.js";import{findTextObject as c}from"./textObjects.js";export function executeOperatorMotion(e,t,n,s){const o=i(t,s.cursor,n);if(o.equals(s.cursor))return;const r=getOperatorRange(s.cursor,o,t,e,n);applyOperator(e,r.from,r.to,s,r.linewise),s.recordChange({type:"operator",op:e,motion:t,count:n})}export function executeOperatorFind(t,n,s,o,r){const i=r.cursor.findCharacter(s,n,o);if(null===i)return;const c=new e(r.cursor.measuredText,i),f=function(e,t){const n=Math.min(e.offset,t.offset),s=Math.max(e.offset,t.offset),o=e.measuredText.nextOffset(s);return{from:n,to:o}}(r.cursor,c);applyOperator(t,f.from,f.to,r),r.setLastFind(n,s),r.recordChange({type:"operatorFind",op:t,find:n,char:s,count:o})}export function executeOperatorTextObj(e,t,n,s,o){const r=c(o.text,o.cursor.offset,n,"inner"===t);r&&(applyOperator(e,r.start,r.end,o),o.recordChange({type:"operatorTextObj",op:e,objType:n,scope:t,count:s}))}export function executeLineOp(e,t,o){const r=o.text,i=r.split("\n"),c=s(r.slice(0,o.cursor.offset),"\n"),f=Math.min(t,i.length-c),l=o.cursor.startOfLogicalLine().offset;let a=l;for(let e=0;e<f;e++){const e=r.indexOf("\n",a);a=-1===e?r.length:e+1}let u=r.slice(l,a);if(u.endsWith("\n")||(u+="\n"),o.setRegister(u,!0),"yank"===e)o.setOffset(l);else if("delete"===e){let e=l;const t=a;t===r.length&&e>0&&"\n"===r[e-1]&&(e-=1);const s=r.slice(0,e)+r.slice(t);o.setText(s||"");const i=Math.max(0,s.length-(n(s).length||1));o.setOffset(Math.min(e,i))}else if("change"===e)if(1===i.length)o.setText(""),o.enterInsert(0);else{const e=[...i.slice(0,c),"",...i.slice(c+f)].join("\n");o.setText(e),o.enterInsert(l)}o.recordChange({type:"operator",op:e,motion:e[0],count:t})}export function executeX(e,t){const s=t.cursor.offset;if(s>=t.text.length)return;let o=t.cursor;for(let t=0;t<e&&!o.isAtEnd();t++)o=o.right();const r=o.offset,i=t.text.slice(s,r),c=t.text.slice(0,s)+t.text.slice(r);t.setRegister(i,!1),t.setText(c);const f=Math.max(0,c.length-(n(c).length||1));t.setOffset(Math.min(s,f)),t.recordChange({type:"x",count:e})}export function executeReplace(e,n,s){let o=s.cursor.offset,r=s.text;for(let s=0;s<n&&o<r.length;s++){const n=t(r.slice(o)).length||1;r=r.slice(0,o)+e+r.slice(o+n),o+=e.length}s.setText(r),s.setOffset(Math.max(0,o-e.length)),s.recordChange({type:"replace",char:e,count:n})}export function executeToggleCase(e,n){const s=n.cursor.offset;if(s>=n.text.length)return;let o=n.text,r=s,i=0;for(;r<o.length&&i<e;){const e=t(o.slice(r)),n=e.length,s=e===e.toUpperCase()?e.toLowerCase():e.toUpperCase();o=o.slice(0,r)+s+o.slice(r+n),r+=s.length,i++}n.setText(o),n.setOffset(r),n.recordChange({type:"toggleCase",count:e})}export function executeJoin(e,t){const n=t.text.split("\n"),{line:s}=t.cursor.getPosition();if(s>=n.length-1)return;const o=Math.min(e,n.length-s-1);let r=n[s];const i=r.length;for(let e=1;e<=o;e++){const t=(n[s+e]??"").trimStart();t.length>0&&(!r.endsWith(" ")&&r.length>0&&(r+=" "),r+=t)}const c=[...n.slice(0,s),r,...n.slice(s+o+1)],f=c.join("\n");t.setText(f),t.setOffset(getLineStartOffset(c,s)+i),t.recordChange({type:"join",count:e})}export function executePaste(e,t,s){const o=s.getRegister();if(!o)return;const r=o.endsWith("\n"),i=r?o.slice(0,-1):o;if(r){const n=s.text.split("\n"),{line:o}=s.cursor.getPosition(),r=e?o+1:o,c=i.split("\n"),f=[];for(let e=0;e<t;e++)f.push(...c);const l=[...n.slice(0,r),...f,...n.slice(r)],a=l.join("\n");s.setText(a),s.setOffset(getLineStartOffset(l,r))}else{const o=i.repeat(t),r=e&&s.cursor.offset<s.text.length?s.cursor.measuredText.nextOffset(s.cursor.offset):s.cursor.offset,c=s.text.slice(0,r)+o+s.text.slice(r),f=n(o),l=r+o.length-(f.length||1);s.setText(c),s.setOffset(Math.max(r,l))}}export function executeIndent(e,t,n){const s=n.text.split("\n"),{line:o}=n.cursor.getPosition(),r=Math.min(t,s.length-o),i=" ";for(let t=0;t<r;t++){const n=o+t,r=s[n]??"";if(">"===e)s[n]=i+r;else if(r.startsWith(i))s[n]=r.slice(2);else if(r.startsWith("\t"))s[n]=r.slice(1);else{let e=0,t=0;for(;t<r.length&&e<2&&/\s/.test(r[t]);)e++,t++;s[n]=r.slice(t)}}const c=s.join("\n"),f=s[o]??"",l=(f.match(/^\s*/)?.[0]??"").length;n.setText(c),n.setOffset(getLineStartOffset(s,o)+l),n.recordChange({type:"indent",dir:e,count:t})}export function executeOpenLine(e,t){const n=t.text.split("\n"),{line:s}=t.cursor.getPosition(),o="below"===e?s+1:s,r=[...n.slice(0,o),"",...n.slice(o)],i=r.join("\n");t.setText(i),t.enterInsert(getLineStartOffset(r,o)),t.recordChange({type:"openLine",direction:e})}function getLineStartOffset(e,t){return e.slice(0,t).join("\n").length+(t>0?1:0)}function getOperatorRange(e,t,n,s,i){let c=Math.min(e.offset,t.offset),f=Math.max(e.offset,t.offset),l=!1;if("change"!==s||"w"!==n&&"W"!==n)if(r(n)){l=!0;const t=e.text,n=t.indexOf("\n",f);-1===n?(f=t.length,c>0&&"\n"===t[c-1]&&(c-=1)):f=n+1}else o(n)&&e.offset<=t.offset&&(f=e.measuredText.nextOffset(f));else{let t=e;for(let e=0;e<i-1;e++)t="w"===n?t.nextVimWord():t.nextWORD();const s="w"===n?t.endOfVimWord():t.endOfWORD();f=e.measuredText.nextOffset(s.offset)}return c=e.snapOutOfImageRef(c,"start"),f=e.snapOutOfImageRef(f,"end"),{from:c,to:f,linewise:l}}function applyOperator(e,t,s,o,r=!1){let i=o.text.slice(t,s);if(r&&!i.endsWith("\n")&&(i+="\n"),o.setRegister(i,r),"yank"===e)o.setOffset(t);else if("delete"===e){const e=o.text.slice(0,t)+o.text.slice(s);o.setText(e);const r=Math.max(0,e.length-(n(e).length||1));o.setOffset(Math.min(t,r))}else if("change"===e){const e=o.text.slice(0,t)+o.text.slice(s);o.setText(e),o.enterInsert(t)}}export function executeOperatorG(e,t,n){const s=1===t?n.cursor.startOfLastLine():n.cursor.goToLine(t);if(s.equals(n.cursor))return;const o=getOperatorRange(n.cursor,s,"G",e,t);applyOperator(e,o.from,o.to,n,o.linewise),n.recordChange({type:"operator",op:e,motion:"G",count:t})}export function executeOperatorGg(e,t,n){const s=1===t?n.cursor.startOfFirstLine():n.cursor.goToLine(t);if(s.equals(n.cursor))return;const o=getOperatorRange(n.cursor,s,"gg",e,t);applyOperator(e,o.from,o.to,n,o.linewise),n.recordChange({type:"operator",op:e,motion:"gg",count:t})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isVimPunctuation as
|
|
1
|
+
import{isVimPunctuation as t,isVimWhitespace as e,isVimWordChar as n}from"../utils/Cursor.js";import{getGraphemeSegmenter as r}from"../utils/intl.js";const f={"(":["(",")"],")":["(",")"],b:["(",")"],"[":["[","]"],"]":["[","]"],"{":["{","}"],"}":["{","}"],B:["{","}"],"<":["<",">"],">":["<",">"],'"':['"','"'],"'":["'","'"],"`":["`","`"]};export function findTextObject(t,r,l,i){if("w"===l)return findWordObject(t,r,i,n);if("W"===l)return findWordObject(t,r,i,t=>!e(t));const o=f[l];if(o){const[e,n]=o;return e===n?function(t,e,n,r){const f=t.lastIndexOf("\n",e-1)+1,l=t.indexOf("\n",e),i=-1===l?t.length:l,o=t.slice(f,i),s=e-f,u=[];for(let t=0;t<o.length;t++)o[t]===n&&u.push(t);for(let t=0;t<u.length-1;t+=2){const e=u[t],n=u[t+1];if(e<=s&&s<=n)return r?{start:f+e+1,end:f+n}:{start:f+e,end:f+n+1}}return null}(t,r,e,i):function(t,e,n,r,f){let l=0,i=-1;for(let f=e;f>=0;f--)if(t[f]===r&&f!==e)l++;else if(t[f]===n){if(0===l){i=f;break}l--}if(-1===i)return null;l=0;let o=-1;for(let e=i+1;e<t.length;e++)if(t[e]===n)l++;else if(t[e]===r){if(0===l){o=e;break}l--}return-1===o?null:f?{start:i+1,end:o}:{start:i,end:o+1}}(t,r,e,n,i)}return null}function findWordObject(n,f,l,i){const o=[];for(const{segment:t,index:e}of r().segment(n))o.push({segment:t,index:e});let s=o.length-1;for(let t=0;t<o.length;t++){const e=o[t],r=t+1<o.length?o[t+1].index:n.length;if(f>=e.index&&f<r){s=t;break}}const graphemeAt=t=>o[t]?.segment??"",offsetAt=t=>t<o.length?o[t].index:n.length,isWs=t=>e(graphemeAt(t)),isWord=t=>i(graphemeAt(t)),isPunct=e=>t(graphemeAt(e));let u=s,d=s;if(isWord(s)){for(;u>0&&isWord(u-1);)u--;for(;d<o.length&&isWord(d);)d++}else{if(isWs(s)){for(;u>0&&isWs(u-1);)u--;for(;d<o.length&&isWs(d);)d++;return{start:offsetAt(u),end:offsetAt(d)}}if(isPunct(s)){for(;u>0&&isPunct(u-1);)u--;for(;d<o.length&&isPunct(d);)d++}}if(!l)if(d<o.length&&isWs(d))for(;d<o.length&&isWs(d);)d++;else if(u>0&&isWs(u-1))for(;u>0&&isWs(u-1);)u--;return{start:offsetAt(u),end:offsetAt(d)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveMotion as e}from"./motions.js";import{executeIndent as t,executeJoin as n,executeLineOp as r,executeOpenLine as o,executeOperatorFind as u,executeOperatorG as
|
|
1
|
+
import{resolveMotion as e}from"./motions.js";import{executeIndent as t,executeJoin as n,executeLineOp as r,executeOpenLine as o,executeOperatorFind as u,executeOperatorG as c,executeOperatorGg as s,executeOperatorMotion as i,executeOperatorTextObj as f,executePaste as p,executeReplace as a,executeToggleCase as x,executeX as d}from"./operators.js";import{FIND_KEYS as l,isOperatorKey as g,isTextObjScopeKey as y,MAX_VIM_COUNT as h,OPERATORS as O,SIMPLE_MOTIONS as I,TEXT_OBJ_SCOPES as m,TEXT_OBJ_TYPES as L}from"./types.js";export function transition(n,o,c){switch(n.type){case"idle":return function(e,t){if(/[1-9]/.test(e))return{next:{type:"count",digits:e}};if("0"===e)return{execute:()=>t.setOffset(t.cursor.startOfLogicalLine().offset)};const n=handleNormalInput(e,1,t);return n||{}}(o,c);case"count":return function(e,t,n){if(/[0-9]/.test(t)){const n=e.digits+t,r=Math.min(parseInt(n,10),h);return{next:{type:"count",digits:String(r)}}}const r=parseInt(e.digits,10),o=handleNormalInput(t,r,n);return o||{next:{type:"idle"}}}(n,o,c);case"operator":return function(e,t,n){if(t===e.op[0])return{execute:()=>r(e.op,e.count,n)};if(/[0-9]/.test(t))return{next:{type:"operatorCount",op:e.op,count:e.count,digits:t}};const o=handleOperatorInput(e.op,e.count,t,n);return o||{next:{type:"idle"}}}(n,o,c);case"operatorCount":return function(e,t,n){if(/[0-9]/.test(t)){const n=e.digits+t,r=Math.min(parseInt(n,10),h);return{next:{...e,digits:String(r)}}}const r=parseInt(e.digits,10),o=e.count*r,u=handleOperatorInput(e.op,o,t,n);return u||{next:{type:"idle"}}}(n,o,c);case"operatorFind":return function(e,t,n){return{execute:()=>u(e.op,e.find,t,e.count,n)}}(n,o,c);case"operatorTextObj":return function(e,t,n){if(L.has(t))return{execute:()=>f(e.op,e.scope,t,e.count,n)};return{next:{type:"idle"}}}(n,o,c);case"find":return function(e,t,n){return{execute:()=>{const r=n.cursor.findCharacter(t,e.find,e.count);null!==r&&(n.setOffset(r),n.setLastFind(e.find,t))}}}(n,o,c);case"g":return function(t,n,r){if("j"===n||"k"===n)return{execute:()=>{const o=e(`g${n}`,r.cursor,t.count);r.setOffset(o.offset)}};if("g"===n)return t.count>1?{execute:()=>{const e=r.text.split("\n"),n=Math.min(t.count-1,e.length-1);let o=0;for(let t=0;t<n;t++)o+=(e[t]?.length??0)+1;r.setOffset(o)}}:{execute:()=>r.setOffset(r.cursor.startOfFirstLine().offset)};return{next:{type:"idle"}}}(n,o,c);case"operatorG":return function(e,t,n){if("j"===t||"k"===t)return{execute:()=>i(e.op,`g${t}`,e.count,n)};if("g"===t)return{execute:()=>s(e.op,e.count,n)};return{next:{type:"idle"}}}(n,o,c);case"replace":return function(e,t,n){return""===t?{next:{type:"idle"}}:{execute:()=>a(t,e.count,n)}}(n,o,c);case"indent":return function(e,n,r){if(n===e.dir)return{execute:()=>t(e.dir,e.count,r)};return{next:{type:"idle"}}}(n,o,c)}}function handleNormalInput(t,u,c){return g(t)?{next:{type:"operator",op:O[t],count:u}}:I.has(t)?{execute:()=>{const n=e(t,c.cursor,u);c.setOffset(n.offset)}}:l.has(t)?{next:{type:"find",find:t,count:u}}:"g"===t?{next:{type:"g",count:u}}:"r"===t?{next:{type:"replace",count:u}}:">"===t||"<"===t?{next:{type:"indent",dir:t,count:u}}:"~"===t?{execute:()=>x(u,c)}:"x"===t?{execute:()=>d(u,c)}:"J"===t?{execute:()=>n(u,c)}:"p"===t||"P"===t?{execute:()=>p("p"===t,u,c)}:"D"===t?{execute:()=>i("delete","$",1,c)}:"C"===t?{execute:()=>i("change","$",1,c)}:"Y"===t?{execute:()=>r("yank",u,c)}:"G"===t?{execute:()=>{1===u?c.setOffset(c.cursor.startOfLastLine().offset):c.setOffset(c.cursor.goToLine(u).offset)}}:"."===t?{execute:()=>c.onDotRepeat?.()}:";"===t||","===t?{execute:()=>function(e,t,n){const r=n.getLastFind();if(!r)return;let o=r.type;if(e){o={f:"F",F:"f",t:"T",T:"t"}[o]}const u=n.cursor.findCharacter(r.char,o,t);null!==u&&n.setOffset(u)}(","===t,u,c)}:"u"===t?{execute:()=>c.onUndo?.()}:"i"===t?{execute:()=>c.enterInsert(c.cursor.offset)}:"I"===t?{execute:()=>c.enterInsert(c.cursor.firstNonBlankInLogicalLine().offset)}:"a"===t?{execute:()=>{const e=c.cursor.isAtEnd()?c.cursor.offset:c.cursor.right().offset;c.enterInsert(e)}}:"A"===t?{execute:()=>c.enterInsert(c.cursor.endOfLogicalLine().offset)}:"o"===t?{execute:()=>o("below",c)}:"O"===t?{execute:()=>o("above",c)}:null}function handleOperatorInput(e,t,n,r){return y(n)?{next:{type:"operatorTextObj",op:e,count:t,scope:m[n]}}:l.has(n)?{next:{type:"operatorFind",op:e,count:t,find:n}}:I.has(n)?{execute:()=>i(e,n,t,r)}:"G"===n?{execute:()=>c(e,t,r)}:"g"===n?{next:{type:"operatorG",op:e,count:t}}:null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getFeatureValue_CACHED_MAY_BE_STALE as
|
|
1
|
+
import{getFeatureValue_CACHED_MAY_BE_STALE as o}from"../services/analytics/growthbook.js";export function isVoiceGrowthBookEnabled(){return!o("tengu_amber_quartz_disabled",!1)}export function hasVoiceAuth(){return!0}export function isVoiceModeEnabled(){return isVoiceGrowthBookEnabled()}
|
package/dist/src/webapp/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomBytes as e,timingSafeEqual as
|
|
1
|
+
import{randomBytes as e,timingSafeEqual as t}from"node:crypto";import{getGlobalConfig as n,saveGlobalConfig as r}from"../utils/config.js";export function getWebappToken(){return n().webappConfig?.token}export function generateWebappToken(){const t=e(24).toString("base64url");return r(e=>({...e,webappConfig:{...e.webappConfig??{},token:t}})),t}export function ensureWebappToken(){return getWebappToken()??generateWebappToken()}export function tokenMatches(e,n){if(!e||!n)return!1;const r=Buffer.from(e,"utf8"),o=Buffer.from(n,"utf8");if(r.length!==o.length)return!1;try{return t(r,o)}catch{return!1}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as e,spawnSync as r}from"node:child_process";import{existsSync as o}from"node:fs";import{join as l}from"node:path";import{logForDebugging as
|
|
1
|
+
import{spawn as e,spawnSync as r}from"node:child_process";import{existsSync as o}from"node:fs";import{join as l}from"node:path";import{logForDebugging as t}from"../utils/debug.js";const n={proc:null,publicUrl:null,startedAt:null,lastError:null,binaryPath:null},a=/https?:\/\/[a-z0-9-]+\.trycloudflare\.com/i;export function isTunnelRunning(){return null!==n.proc}export function getTunnelStatus(){return{running:isTunnelRunning(),publicUrl:n.publicUrl,startedAt:n.startedAt,pid:n.proc?.pid??null,lastError:n.lastError,binaryPath:n.binaryPath}}const s=["No encontré `cloudflared` en tu sistema. Instalación rápida:",""," Windows (winget): winget install --id Cloudflare.cloudflared"," Windows (manual): https://github.com/cloudflare/cloudflared/releases (descargar cloudflared-windows-amd64.exe)"," macOS (brew): brew install cloudflared"," Linux (apt): https://pkg.cloudflare.com/index.html","","Si ya está instalado pero no aparece en PATH, podés indicar la ruta exacta","con la variable de entorno CLOUDFLARED_BIN:","",' Windows PowerShell: $env:CLOUDFLARED_BIN = "C:\\ruta\\a\\cloudflared.exe"'," macOS/Linux: export CLOUDFLARED_BIN=/ruta/a/cloudflared","","Alternativa: usá tu propio túnel/dominio y registralo con:"," /webapp tunnel url https://mi-dominio.example.com"].join("\n");export async function startTunnel(i){if(n.proc)return{ok:!0,publicUrl:n.publicUrl??void 0,message:n.publicUrl?`Túnel ya estaba activo: ${n.publicUrl}`:"Túnel ya estaba arrancando, esperando URL..."};const c=function(){const e=process.env.CLOUDFLARED_BIN?.trim();if(e&&o(e))return e;const t="win32"===process.platform?"where":"which",n="win32"===process.platform?"cloudflared.exe":"cloudflared";try{const e=r(t,[n],{encoding:"utf8",shell:!1,windowsHide:!0});if(0===e.status&&e.stdout){const r=e.stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean)[0];if(r&&o(r))return r}}catch{}const a=[];if("win32"===process.platform){const e=process.env.ProgramFiles??"C:\\Program Files",r=process.env["ProgramFiles(x86)"]??"C:\\Program Files (x86)",o=process.env.LOCALAPPDATA;a.push(l(e,"cloudflared","cloudflared.exe"),l(r,"cloudflared","cloudflared.exe")),o&&a.push(l(o,"Microsoft","WinGet","Packages","Cloudflare.cloudflared_Microsoft.Winget.Source_8wekyb3d8bbwe","cloudflared.exe"))}else"darwin"===process.platform?a.push("/opt/homebrew/bin/cloudflared","/usr/local/bin/cloudflared"):a.push("/usr/local/bin/cloudflared","/usr/bin/cloudflared");for(const e of a)if(o(e))return e;return null}();if(!c)return n.lastError="cloudflared no encontrado en PATH ni rutas conocidas",{ok:!1,message:s};let u;n.binaryPath=c,t(`[webapp:tunnel] usando binario: ${c}`);try{u=e(c,["tunnel","--url",`http://localhost:${i}`,"--no-autoupdate","--logfile","-"],{stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch(e){return n.lastError=e instanceof Error?e.message:String(e),{ok:!1,message:`${s}\n\nDetalle: ${n.lastError}`}}n.proc=u,n.publicUrl=null,n.startedAt=Date.now(),n.lastError=null;let d="";const p=new Promise(e=>{let r=!1;u.once("error",o=>{r||(r=!0,e(o))}),setTimeout(()=>{r||(r=!0,e(null))},2e3)}),f=new Promise(e=>{let r=!1;const onData=o=>{const l=o.toString("utf8");d=(d+l).slice(-4096),t(`[webapp:tunnel] ${l.trim()}`);const s=l.match(a);s&&!r&&(r=!0,n.publicUrl=s[0],e(s[0]))};u.stdout.on("data",onData),u.stderr.on("data",onData),u.once("exit",()=>{r||(r=!0,e(null))}),setTimeout(()=>{r||(r=!0,e(null))},3e4)});u.on("exit",e=>{t(`[webapp:tunnel] cloudflared salió con código ${e}`),n.proc===u&&(n.proc=null,n.publicUrl=null,n.startedAt=null)}),u.on("error",e=>{n.lastError=e.message,t(`[webapp:tunnel] error: ${e.message}`)});const m=await p;if(m){n.proc=null,n.lastError=m.message;return"ENOENT"===m.code?{ok:!1,message:s}:{ok:!1,message:`Fallo al arrancar cloudflared: ${m.message}`}}const b=await f;if(!b){n.lastError="No recibí URL pública de cloudflared en 30s.";const e=d.trim().slice(-800);return{ok:!1,message:"Arranqué cloudflared pero no recibí URL pública en 30s.\n"+(e?`Últimas líneas de log:\n${e}\n\n`:"")+"Probá: /webapp tunnel stop y luego /webapp tunnel start.\nSi persiste, verificá conectividad a https://api.trycloudflare.com."}}return{ok:!0,publicUrl:b,message:`Túnel activo: ${b}`}}export async function stopTunnel(){if(!n.proc)return{ok:!0,message:"No había túnel activo."};const e=n.proc;n.proc=null,n.publicUrl=null,n.startedAt=null;try{return e.kill("SIGTERM"),await new Promise(r=>{const o=setTimeout(()=>{try{e.kill("SIGKILL")}catch{}r()},3e3);e.once("exit",()=>{clearTimeout(o),r()})}),{ok:!0,message:"Túnel detenido."}}catch(e){return{ok:!1,message:`No pude detener cloudflared limpiamente: ${e instanceof Error?e.message:String(e)}`}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:fs/promises";import{dirname as a,join as t}from"node:path";import{tmpdir as o}from"node:os";import{addAllowedNumber as r,clearLinkedIdentity as i,e164ToJid as s,ensureCurrentWorkspaceRegistered as n,ensureWorkspaceRegisteredByPath as l,getActiveWorkspaceForNumber as d,getActiveWorkspaceAliasForNumber as c,getAllowedNumbers as u,getPrimaryRecipient as p,getWhatsAppAuthDir as m,getWhatsAppConfig as w,jidToE164 as g,listWhatsAppWorkspaces as f,normalizeE164 as y,setActiveWorkspaceAliasForNumber as v,setPrimaryRecipient as b,setSelfIdentity as h,setWhatsAppRunning as $}from"./config.js";import{closeSocketSafe as T,createWaSocket as A,getDisconnectStatus as j,readSelfIdentity as J,waitForOpenConnection as B,wipeAuthDir as k}from"./session.js";import{setMirrorSocket as E}from"./mirror.js";import{markInjectedFromWhatsApp as C}from"./mirror.js";import{logForDebugging as M}from"../utils/debug.js";import{getStoredActiveProviderPreference as P,getStoredLastModelForProvider as R,setStoredActiveProviderPreference as W,setStoredLastModelForProvider as x}from"../utils/model/providerProfilesDb.js";import{isProfiledProvider as S,listProviderProfiles as D,setActiveProfileForProvider as N}from"../utils/model/providerProfiles.js";import{checkLocalDictationConfiguration as L,transcribeAudioFile as O}from"../services/localDictation.js";import{runGlobalPromptForWhatsApp as G}from"../bridgeGlobal/runner.js";import{getGlobalBridgeDaemonStatus as I,startGlobalBridgeDaemon as F,stopGlobalBridgeDaemon as U}from"../bridgeGlobal/manager.js";import{approvePending as _,listPending as q,rejectPending as z}from"./permissionInbox.js";export function waTitle(e){return`*${e.toUpperCase()}*`}export function waBullet(e){return`-> ${e}`}export function waCode(e){return`>> ${e}`}export function waAlert(e){return`!! ${e}`}let Q=null,H=null,X=null;async function enqueueCommand(e){if(!X){const e=await import("../utils/messageQueueManager.js");X=e.enqueue}X(e)}export function setWhatsAppInboundHandler(e){H=e}export function isWhatsAppBridgeRunning(){return null!==Q}async function autoUnlinkOnLoggedOut(){Q&&(T(Q),Q=null,E(null)),await k(m()),i()}export async function unlinkWhatsApp(){try{return Q&&(T(Q),Q=null,E(null)),await k(m()),i(),{success:!0,message:"Cuenta desvinculada y credenciales borradas."}}catch(e){return{success:!1,message:`Error al desvincular: ${e instanceof Error?e.message:String(e)}`}}}function handleInbound(r){if(!r?.message||r.key?.fromMe)return;const i=r.key?.remoteJid;if(!i)return;if(M(`[wa:inbound] upsert remoteJid=${i}`),i.endsWith("@g.us")||i.endsWith("@newsletter"))return void M(`[wa:inbound] ignored non-direct remoteJid=${i}`);let s=function(e){const a=e?.key??{},t=[a.remoteJid,a.remoteJidAlt,a.participant,a.participantAlt,e?.participant,e?.participantAlt];for(const e of t){if(!e||"string"!=typeof e)continue;const a=g(e);if(a)return a}return null}(r);const m=p(),w=u(),y=i.endsWith("@lid");if(s&&!y||(m?s=m:1===w.length&&(s=w[0])),!s)return void M(`[wa:inbound] dropped: senderE164 unresolved remoteJid=${i}`);if(M(`[wa:inbound] sender=${s}`),0!==w.length||p()){if(!function(e){const a=u();return 0===a.length||a.includes(e)}(s))return void M(`[wa:inbound] dropped: sender not allowed sender=${s}`)}else b(s),M(`[wa:inbound] bootstrap primaryRecipient=${s}`);if(Boolean(r?.message?.imageMessage))return void async function(e,a,t){try{const o=(await import("@whiskeysockets/baileys")).downloadMediaMessage;if("function"!=typeof o)return void await replyToJid(a,"No pude descargar la imagen.");await replyToJid(a,"Descargando y procesando imagen...");const r=await o(e,"buffer",{});if(!r||0===r.length)return void await replyToJid(a,"No pude leer la imagen.");const i=r.toString("base64"),s=e.message?.imageMessage?.mimetype||"image/jpeg",n=e.message?.imageMessage?.caption?.trim()||"Analiza esta imagen.",l=Date.now(),d={id:l,type:"image",content:i,mediaType:s,filename:`wa_image_${l}`},{storeImage:c}=await import("../utils/imageStore.js");await c(d);const u={[l]:d};if(isGlobalBridgeModeEnabled())return void await replyToJid(a,"El modo de prompt global no soporta imágenes todavía.");C(n),enqueueCommand({value:n,mode:"prompt",pastedContents:u,skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] image injected via enqueue sender=${t}`)}catch(e){await replyToJid(a,`Error procesando imagen: ${e instanceof Error?e.message:String(e)}`)}}(r,i,s);const h=($=r.message)?"string"==typeof $.conversation?$.conversation:"string"==typeof $.extendedTextMessage?.text?$.extendedTextMessage.text:"string"==typeof $.imageMessage?.caption?$.imageMessage.caption:"string"==typeof $.videoMessage?.caption?$.videoMessage.caption:"string"==typeof $.buttonsResponseMessage?.selectedDisplayText?$.buttonsResponseMessage.selectedDisplayText:"":"";var $;if(!h)return Boolean(r?.message?.audioMessage)||Boolean(r?.message?.pttMessage)||Boolean(r?.message?.documentMessage?.mimetype?.startsWith?.("audio/"))?void async function(a,r,i){try{if(!(await L()).available)return void await replyToJid(r,"No puedo transcribir audio ahora. Configura dictado local con /dictar install");const s=(await import("@whiskeysockets/baileys")).downloadMediaMessage;if("function"!=typeof s)return void await replyToJid(r,"No pude descargar el audio para transcribirlo.");const n=await s(a,"buffer",{});if(!n||0===n.length)return void await replyToJid(r,"No pude leer el audio para transcribirlo.");const l=await e.mkdtemp(t(o(),"context-wa-audio-")),d=t(l,"input.ogg");try{await e.writeFile(d,n);const a=(await O(d)).trim();if(!a)return void await replyToJid(r,"No detecte voz en el audio.");const t=a;if(H)return H(t),void M(`[wa:inbound] audio transcribed via inboundHandler sender=${i}`);if(isGlobalBridgeModeEnabled())return void await runGlobalPromptFlow(t,r,i);C(t),enqueueCommand({value:t,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] audio transcribed via enqueue fallback sender=${i}`)}finally{await e.rm(l,{recursive:!0,force:!0})}}catch(e){await replyToJid(r,`Error transcribiendo audio: ${e instanceof Error?e.message:String(e)}`)}}(r,i,s):void M(`[wa:inbound] dropped: empty text sender=${s}`);const T=h.trim();if(T.startsWith("/"))return M(`[wa:inbound] slash message sender=${s} text=${T.slice(0,80)}`),void(async()=>{const o=await async function(o,r,i){const[s,...u]=o.split(/\s+/),p=s.toLowerCase();if("/proveedores"===p||"/providers"===p){const e=P()??"claude",a=["claude","openai","openrouter","ollama","ollama-cloud","gemini-api","gemini-google","zai","minimax","deepseek"].map(a=>waBullet(a===e?`*${a}* (activo)`:a));return await replyToJid(r,[waTitle("Proveedores"),"",`*Activo:* ${e}`,"","==","",waTitle("Disponibles"),...a,"","==","",waTitle("Opciones"),waBullet("list -> listar proveedores"),waBullet("current -> ver proveedor actual"),waBullet("set -> cambiar proveedor"),"","==","",`*Uso:* ${waCode("/provider <nombre>")}`].join("\n")),!0}if("/provider"===p){const e=u.join(" ").trim().toLowerCase();if(!e){const e=P()??"claude";return await replyToJid(r,[waTitle("Proveedor Actual"),"",`*Activo:* ${e}`,"","==","",waTitle("Opciones"),waBullet("list -> "+waCode("/proveedores")),waBullet("set -> "+waCode("/provider <nombre>"))].join("\n")),!0}if(!new Set(["claude","openai","openrouter","ollama","ollama-cloud","gemini-api","gemini-google","zai","minimax","deepseek"]).has(e))return await replyToJid(r,[waTitle("Proveedor No Valido"),"",`*Recibido:* ${e}`,"","==","",`*Ayuda:* usa ${waCode("/proveedores")}`].join("\n")),!0;W(e);const a=R(e)??"(sin modelo guardado)";return await replyToJid(r,[waTitle("Proveedor Actualizado"),"",`*Nuevo proveedor:* ${e}`,`*Modelo actual:* ${a}`].join("\n")),!0}if("/modelo"===p||"/model"===p){const e=u.join(" ").trim(),a=P()??"claude";if(!e){const e=R(a)??"(sin modelo guardado)";return await replyToJid(r,[waTitle("Modelo Actual"),"",`*Proveedor:* ${a}`,`*Modelo:* ${e}`,"","==","",`*Uso:* ${waCode("/modelo <nombre>")}`].join("\n")),!0}return x(a,e),await replyToJid(r,[waTitle("Modelo Actualizado"),"",`*Proveedor:* ${a}`,`*Nuevo modelo:* ${e}`].join("\n")),!0}if("/profiles"===p||"/perfiles"===p){const e=P()??"claude";if(!S(e))return await replyToJid(r,`${waAlert("Error")}\nEl proveedor activo (${e}) no usa perfiles.`),!0;const a=D(e);if(0===a.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo hay perfiles para ${e}. Crea uno desde CLI con /provider.`),!0;const t=a.map(e=>{const a=e.lastModel??"-";return waBullet(`${e.name} (model: ${a})`)});return await replyToJid(r,[waTitle(`Perfiles de ${e}`),"",...t,"","==","",`*Uso:* ${waCode("/profile <nombre>")}`].join("\n")),!0}if("/profile"===p||"/perfil"===p){const e=P()??"claude";if(!S(e))return await replyToJid(r,`${waAlert("Error")}\nEl proveedor activo (${e}) no usa perfiles.`),!0;const a=u.join(" ").trim();if(!a)return await replyToJid(r,`*Uso:* ${waCode("/profile <nombre>")}`),!0;const t=N(e,a);return await replyToJid(r,[waTitle("Perfil Activado"),"",`*Perfil:* ${t.provider}/${t.name}`,`*Agente:* ${t.agentName}`].join("\n")),!0}if("/repos"===p){const e=n(),a=f(),t=c(i)??e.alias,o=a.map(e=>{const a=e.alias===t?" * (activo)":"";return waBullet(`${e.alias}${a}`)});return await replyToJid(r,[waTitle("Repos Registrados"),"",...o,"","==","",`*Uso:* ${waCode("/use <alias>")}`].join("\n")),!0}if("/workspace-sync"===p){const o=await async function(){const o=[],r=new Set,i=new Set([process.cwd(),a(process.cwd())]);for(const a of i){try{if(await e.stat(t(a,".git"))){const e=l(a);r.has(e.path)||(r.add(e.path),o.push({alias:e.alias,path:e.path}))}}catch{}let i=[];try{i=await e.readdir(a,{withFileTypes:!0})}catch{continue}for(const s of i){if(!s.isDirectory())continue;const i=t(a,s.name);try{if(!await e.stat(t(i,".git")))continue}catch{continue}const n=l(i);r.has(n.path)||(r.add(n.path),o.push({alias:n.alias,path:n.path}))}}return o}();if(0===o.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo encontre repos nuevos cerca del directorio actual.`),!0;const i=o.map(e=>waBullet(e.alias));return await replyToJid(r,[waTitle("Repos Detectados"),"",...i].join("\n")),!0}if("/use"===p||"/cd"===p){const e=u.join(" ").trim();if(!e)return await replyToJid(r,`*Uso:* ${waCode(p+" <alias>")}`),!0;const a=await switchProcessWorkspaceByAlias(e);if(!a.ok)return await replyToJid(r,`${waAlert("Error")}\n${a.message}`),!0;if(!v(i,a.alias))return await replyToJid(r,`${waAlert("Error")}\nNo existe el repo "${e}". Usa /repos para ver aliases.`),!0;const t=d(i);return await replyToJid(r,[waTitle("Repo Activado"),"",`*Alias:* ${t?.alias??a.alias}`,`*Ruta:* ${t?.path??a.path}`,`*CWD:* ${process.cwd()}`].join("\n")),!0}if("/status"===p){const e=n(),a=d(i)??e,t=(process.env.CONTEXT_BRIDGE_RESUME_MIRROR_MODE??process.env.CONTEXT_RESUME_MIRROR_MODE??"summary").toLowerCase();return await replyToJid(r,[waTitle("Estado del Bridge"),"",`*Repo activo:* ${a.alias}`,`*Ruta:* ${a.path}`,`*Numero:* ${i}`,`*Total repos:* ${f().length}`,`*Resume mirror:* ${t}`].join("\n")),!0}if("/canal-global"===p||"/global-canal"===p||"/cg"===p){const e=(u[0]??"status").toLowerCase();if("status"===e||"estado"===e){const e=await I();return await replyToJid(r,[waTitle("Canal Global"),"","*Estado:* "+(e.running?"activo":"inactivo"),`*PID:* ${e.pid??"n/a"}`,`*Inicio:* ${e.startedAt??"n/a"}`,"","==","",waTitle("Opciones"),waBullet("/canal-global start"),waBullet("/canal-global stop"),waBullet("/canal-global status")].join("\n")),!0}if("start"===e||"iniciar"===e){const e=await F();return await replyToJid(r,`*Resultado:* ${e}`),!0}if("stop"===e||"detener"===e){const e=await U();return await replyToJid(r,`*Resultado:* ${e}`),!0}return await replyToJid(r,[waTitle("Canal Global - Ayuda"),"",waBullet("/canal-global status"),waBullet("/canal-global start"),waBullet("/canal-global stop")].join("\n")),!0}if("/aprobar"===p||"/approve"===p||"/aprobar-siempre"===p||"/approve-always"===p||"/denegar"===p||"/deny"===p){const e="/aprobar-siempre"===p||"/approve-always"===p,a="/denegar"===p||"/deny"===p,t=u.join(" ").trim();if(!t){const e=q();if(0===e.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo hay permisos pendientes.`),!0;const a=e.map(e=>waBullet(`[${e.id}] ${e.toolName}: ${(e.description||"(sin detalle)").slice(0,100)}`));return await replyToJid(r,[waTitle(`Permisos pendientes (${e.length})`),"",...a,"","==","","*Uso:* /aprobar <id> o /aprobar-siempre <id> o /denegar <id>"].join("\n")),!0}const o=t.toLowerCase(),i=a?z(o):_(o,e);if("not_found"===i.kind)return await replyToJid(r,`${waAlert("Error")}\nNo encontre ningun permiso con id "${o}". Usa /aprobar para listarlos.`),!0;if("already_resolved"===i.kind)return await replyToJid(r,`${waAlert("Aviso")}\nEl permiso ${o} (${i.item.toolName}) ya fue resuelto — ignorado.`),!0;const s=a?"rechazado":e?"aprobado permanentemente":"aprobado";return await replyToJid(r,[waTitle("Permiso Resuelto"),"",`*ID:* ${o}`,`*Herramienta:* ${i.item.toolName}`,`*Accion:* ${s}`].join("\n")),!0}return("/help"===p||"/ayuda"===p||"/ayudame"===p)&&(await replyToJid(r,[waTitle("Ayuda WhatsApp Bridge"),"",waBullet("/repos -> ver repos registrados"),waBullet("/use <alias> -> cambiar de repo"),waBullet("/status -> ver estado actual"),waBullet("/workspace-sync -> registrar repos git"),waBullet("/proveedores -> ver proveedores"),waBullet("/provider <nombre> -> cambiar proveedor"),waBullet("/modelo <nombre> -> cambiar modelo"),waBullet("/profiles -> ver perfiles"),waBullet("/profile <nombre> -> cambiar perfil"),waBullet("/canal-global <start|stop|status>"),waBullet("/aprobar [id] -> resolver permisos"),waBullet("/ayuda -> mostrar ayuda")].join("\n")),!0)}(T,i,s);if(!o){if(M(`[wa:inbound] slash passthrough to CLI sender=${s}`),H)return H(T),void M(`[wa:inbound] injected via inboundHandler sender=${s}`);C(T),enqueueCommand({value:T,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] injected via enqueue fallback sender=${s}`)}})();if(H)return H(h),void M(`[wa:inbound] text injected via inboundHandler sender=${s}`);if(isGlobalBridgeModeEnabled())return void runGlobalPromptFlow(h.trim(),i,s);const A=h.trim();A&&(C(A),enqueueCommand({value:A,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] text injected via enqueue fallback sender=${s}`))}function isGlobalBridgeModeEnabled(){return"1"===process.env.CONTEXT_BRIDGE_GLOBAL_MODE}async function runGlobalPromptFlow(e,a,t){if(e)try{await replyToJid(a,"Procesando...");const o=await G(e,t);await replyToJid(a,o)}catch(e){await replyToJid(a,`Error ejecutando prompt global: ${e instanceof Error?e.message:String(e)}`)}}async function replyToJid(e,a){if(Q)try{await Q.sendMessage(e,{text:a})}catch{}}async function switchProcessWorkspaceByAlias(a){const t=a.trim().toLowerCase(),o=f().find(e=>e.alias.toLowerCase()===t);if(!o)return{ok:!1,message:`No existe el repo "${a}". Usa /repos para ver aliases.`};try{if(!(await e.stat(o.path)).isDirectory())return{ok:!1,message:`La ruta de ${o.alias} no es una carpeta valida: ${o.path}`}}catch{return{ok:!1,message:`La ruta de ${o.alias} no existe: ${o.path}`}}try{process.chdir(o.path)}catch(e){return{ok:!1,message:`No pude cambiar al repo ${o.alias}: ${e instanceof Error?e.message:String(e)}`}}return{ok:!0,alias:o.alias,path:o.path}}export async function startLoginWithQr(e){const a=m(),t=await J(a);if(t.jid)return{alreadyLinked:!0,selfJid:t.jid,selfE164:t.e164};Q&&(T(Q),Q=null);const{sock:o,saveCreds:r}=await A({authDir:a,onQr:e.onQr}),i=e.timeoutMs??12e4;try{await Promise.race([B(o),new Promise((e,a)=>setTimeout(()=>a(new Error("QR timeout")),i))])}catch(e){if(515!==j(e))throw T(o),e;{T(o);const e=await A({authDir:a});try{await B(e.sock),T(e.sock)}catch{}}}T(o);try{await r()}catch{}const s=await J(a);return s.jid&&h(s.jid,s.e164),{alreadyLinked:!1,selfJid:s.jid,selfE164:s.e164}}export async function startWhatsAppBridge(){if(Q)return{success:!1,message:"El bridge ya está en ejecución."};const e=m(),a=await J(e);if(!a.jid)return{success:!1,message:"WhatsApp no está vinculado. Escanea el QR desde /whatsapp primero."};try{const t=n(),o=p(),r=o?c(o):void 0;r&&await switchProcessWorkspaceByAlias(r);const{sock:i}=await A({authDir:e});await B(i),function(e){const a=e?.user?.id,t=e?.user?.lid,o=a??t;if(!o)return;const r=String(o).split("@")[0]?.split(":")[0],i=r&&/^\d+$/.test(r)?`+${r}`:void 0;h(o,i)}(i),function(e){e.ev.on("messages.upsert",a=>{if(a&&Array.isArray(a.messages))for(const t of a.messages){try{handleInbound(t)}catch{}try{const a=t?.key,o=a?.remoteJid;!a||a.fromMe||!o||o.endsWith("@g.us")||o.endsWith("@newsletter")||"function"!=typeof e.readMessages||e.readMessages([a]).catch(()=>{})}catch{}}})}(i),function(e){e.ev.on("connection.update",a=>{"close"===a?.connection&&(401===j(a.lastDisconnect?.error)?autoUnlinkOnLoggedOut():Q===e&&(T(Q),Q=null,E(null),$(!1)))})}(i),Q=i,E(i),$(!0);const s=w();return{success:!0,message:`Bridge iniciado correctamente. Cuenta: ${s?.selfE164??a.e164??"desconocido"}. Repo activo: ${t.alias}`}}catch(e){return 401===j(e)?(await autoUnlinkOnLoggedOut(),{success:!1,message:"WhatsApp reportó que la sesión fue cerrada desde el móvil. Credenciales limpiadas; ejecuta /whatsapp de nuevo para mostrar un QR fresco."}):{success:!1,message:`Error al iniciar: ${e instanceof Error?e.message:String(e)}`}}}export async function stopWhatsAppBridge(){if(!Q)return{success:!1,message:"El bridge no está en ejecución."};try{return T(Q),Q=null,E(null),$(!1),{success:!0,message:"Bridge detenido correctamente."}}catch(e){return Q=null,E(null),$(!1),{success:!1,message:`Error al detener: ${e instanceof Error?e.message:String(e)}`}}}export{r as addAllowedNumber,y as normalizeE164,s as e164ToJid};
|
|
1
|
+
import e from"node:fs/promises";import{dirname as a,join as o}from"node:path";import{tmpdir as t}from"node:os";import{addAllowedNumber as r,clearLinkedIdentity as i,e164ToJid as n,ensureCurrentWorkspaceRegistered as s,ensureWorkspaceRegisteredByPath as l,getActiveWorkspaceForNumber as d,getActiveWorkspaceAliasForNumber as c,getAllowedNumbers as u,getPrimaryRecipient as p,getWhatsAppAuthDir as m,getWhatsAppConfig as w,jidToE164 as f,listWhatsAppWorkspaces as g,normalizeE164 as y,setActiveWorkspaceAliasForNumber as v,setPrimaryRecipient as b,setSelfIdentity as $,setWhatsAppRunning as h}from"./config.js";import{closeSocketSafe as T,createWaSocket as J,getDisconnectStatus as j,readSelfIdentity as B,waitForOpenConnection as E,wipeAuthDir as A}from"./session.js";import{setMirrorSocket as C}from"./mirror.js";import{markInjectedFromWhatsApp as k}from"./mirror.js";import{logForDebugging as M}from"../utils/debug.js";import{getStoredActiveProviderPreference as x,getStoredLastModelForProvider as R,setStoredActiveProviderPreference as N,setStoredLastModelForProvider as P}from"../utils/model/providerProfilesDb.js";import{isProfiledProvider as D,listProviderProfiles as O,setActiveProfileForProvider as W}from"../utils/model/providerProfiles.js";import{checkLocalDictationConfiguration as L,transcribeAudioFile as S}from"../services/localDictation.js";import{runGlobalPromptForWhatsApp as U}from"../bridgeGlobal/runner.js";import{getGlobalBridgeDaemonStatus as G,startGlobalBridgeDaemon as I,stopGlobalBridgeDaemon as _}from"../bridgeGlobal/manager.js";import{approvePending as q,listPending as z,rejectPending as Q}from"./permissionInbox.js";export function waTitle(e){return`*${e.toUpperCase()}*`}export function waBullet(e){return`-> ${e}`}export function waCode(e){return`>> ${e}`}export function waAlert(e){return`!! ${e}`}let F=null,H=null,X=null;async function enqueueCommand(e){if(!X){const e=await import("../utils/messageQueueManager.js");X=e.enqueue}X(e)}export function setWhatsAppInboundHandler(e){H=e}export function isWhatsAppBridgeRunning(){return null!==F}async function autoUnlinkOnLoggedOut(){F&&(T(F),F=null,C(null)),await A(m()),i()}export async function unlinkWhatsApp(){try{return F&&(T(F),F=null,C(null)),await A(m()),i(),{success:!0,message:"Cuenta desvinculada y credenciales borradas."}}catch(e){return{success:!1,message:`Error al desvincular: ${e instanceof Error?e.message:String(e)}`}}}function handleInbound(r){if(!r?.message||r.key?.fromMe)return;const i=r.key?.remoteJid;if(!i)return;if(M(`[wa:inbound] upsert remoteJid=${i}`),i.endsWith("@g.us")||i.endsWith("@newsletter"))return void M(`[wa:inbound] ignored non-direct remoteJid=${i}`);let n=function(e){const a=e?.key??{},o=[a.remoteJid,a.remoteJidAlt,a.participant,a.participantAlt,e?.participant,e?.participantAlt];for(const e of o){if(!e||"string"!=typeof e)continue;const a=f(e);if(a)return a}return null}(r);const m=p(),w=u(),y=i.endsWith("@lid");if(n&&!y||(m?n=m:1===w.length&&(n=w[0])),!n)return void M(`[wa:inbound] dropped: senderE164 unresolved remoteJid=${i}`);if(M(`[wa:inbound] sender=${n}`),0!==w.length||p()){if(!function(e){const a=u();return 0===a.length||a.includes(e)}(n))return void M(`[wa:inbound] dropped: sender not allowed sender=${n}`)}else b(n),M(`[wa:inbound] bootstrap primaryRecipient=${n}`);if(Boolean(r?.message?.imageMessage))return void async function(e,a,o){try{const t=(await import("@whiskeysockets/baileys")).downloadMediaMessage;if("function"!=typeof t)return void await replyToJid(a,"No pude descargar la imagen.");await replyToJid(a,"Descargando y procesando imagen...");const r=await t(e,"buffer",{});if(!r||0===r.length)return void await replyToJid(a,"No pude leer la imagen.");const i=r.toString("base64"),n=e.message?.imageMessage?.mimetype||"image/jpeg",s=e.message?.imageMessage?.caption?.trim()||"Analiza esta imagen.",l=Date.now(),d={id:l,type:"image",content:i,mediaType:n,filename:`wa_image_${l}`},{storeImage:c}=await import("../utils/imageStore.js");await c(d);const u={[l]:d};if(isGlobalBridgeModeEnabled())return void await replyToJid(a,"El modo de prompt global no soporta imágenes todavía.");k(s),enqueueCommand({value:s,mode:"prompt",pastedContents:u,skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] image injected via enqueue sender=${o}`)}catch(e){await replyToJid(a,`Error procesando imagen: ${e instanceof Error?e.message:String(e)}`)}}(r,i,n);const $=(h=r.message)?"string"==typeof h.conversation?h.conversation:"string"==typeof h.extendedTextMessage?.text?h.extendedTextMessage.text:"string"==typeof h.imageMessage?.caption?h.imageMessage.caption:"string"==typeof h.videoMessage?.caption?h.videoMessage.caption:"string"==typeof h.buttonsResponseMessage?.selectedDisplayText?h.buttonsResponseMessage.selectedDisplayText:"":"";var h;if(!$){return Boolean(r?.message?.audioMessage)||Boolean(r?.message?.pttMessage)||Boolean(r?.message?.documentMessage?.mimetype?.startsWith?.("audio/"))?void async function(a,r,i){try{if(!(await L()).available)return void await replyToJid(r,"No puedo transcribir audio ahora. Configura dictado local con /dictar install");const n=(await import("@whiskeysockets/baileys")).downloadMediaMessage;if("function"!=typeof n)return void await replyToJid(r,"No pude descargar el audio para transcribirlo.");const s=await n(a,"buffer",{});if(!s||0===s.length)return void await replyToJid(r,"No pude leer el audio para transcribirlo.");const l=await e.mkdtemp(o(t(),"context-wa-audio-")),d=o(l,"input.ogg");try{await e.writeFile(d,s);const a=(await S(d)).trim();if(!a)return void await replyToJid(r,"No detecte voz en el audio.");const o=a;if(H)return H(o),void M(`[wa:inbound] audio transcribed via inboundHandler sender=${i}`);if(isGlobalBridgeModeEnabled())return void await runGlobalPromptFlow(o,r,i);k(o),enqueueCommand({value:o,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] audio transcribed via enqueue fallback sender=${i}`)}finally{await e.rm(l,{recursive:!0,force:!0})}}catch(e){await replyToJid(r,`Error transcribiendo audio: ${e instanceof Error?e.message:String(e)}`)}}(r,i,n):void M(`[wa:inbound] dropped: empty text sender=${n}`)}const T=$.trim();if(T.startsWith("/"))return M(`[wa:inbound] slash message sender=${n} text=${T.slice(0,80)}`),void(async()=>{const t=await async function(t,r,i){const[n,...u]=t.split(/\s+/),p=n.toLowerCase();if("/proveedores"===p||"/providers"===p){const e=x()??"claude",a=["claude","openai","openrouter","ollama","ollama-cloud","gemini-api","gemini-google","zai","minimax","deepseek"].map(a=>waBullet(a===e?`*${a}* (activo)`:a));return await replyToJid(r,[waTitle("Proveedores"),"",`*Activo:* ${e}`,"","==","",waTitle("Disponibles"),...a,"","==","",waTitle("Opciones"),waBullet("list -> listar proveedores"),waBullet("current -> ver proveedor actual"),waBullet("set -> cambiar proveedor"),"","==","",`*Uso:* ${waCode("/provider <nombre>")}`].join("\n")),!0}if("/provider"===p){const e=u.join(" ").trim().toLowerCase();if(!e){const e=x()??"claude";return await replyToJid(r,[waTitle("Proveedor Actual"),"",`*Activo:* ${e}`,"","==","",waTitle("Opciones"),waBullet("list -> "+waCode("/proveedores")),waBullet("set -> "+waCode("/provider <nombre>"))].join("\n")),!0}if(!new Set(["claude","openai","openrouter","ollama","ollama-cloud","gemini-api","gemini-google","zai","minimax","deepseek"]).has(e))return await replyToJid(r,[waTitle("Proveedor No Valido"),"",`*Recibido:* ${e}`,"","==","",`*Ayuda:* usa ${waCode("/proveedores")}`].join("\n")),!0;N(e);const a=R(e)??"(sin modelo guardado)";return await replyToJid(r,[waTitle("Proveedor Actualizado"),"",`*Nuevo proveedor:* ${e}`,`*Modelo actual:* ${a}`].join("\n")),!0}if("/modelo"===p||"/model"===p){const e=u.join(" ").trim(),a=x()??"claude";if(!e){const e=R(a)??"(sin modelo guardado)";return await replyToJid(r,[waTitle("Modelo Actual"),"",`*Proveedor:* ${a}`,`*Modelo:* ${e}`,"","==","",`*Uso:* ${waCode("/modelo <nombre>")}`].join("\n")),!0}return P(a,e),await replyToJid(r,[waTitle("Modelo Actualizado"),"",`*Proveedor:* ${a}`,`*Nuevo modelo:* ${e}`].join("\n")),!0}if("/profiles"===p||"/perfiles"===p){const e=x()??"claude";if(!D(e))return await replyToJid(r,`${waAlert("Error")}\nEl proveedor activo (${e}) no usa perfiles.`),!0;const a=O(e);if(0===a.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo hay perfiles para ${e}. Crea uno desde CLI con /provider.`),!0;const o=a.map(e=>{const a=e.lastModel??"-";return waBullet(`${e.name} (model: ${a})`)});return await replyToJid(r,[waTitle(`Perfiles de ${e}`),"",...o,"","==","",`*Uso:* ${waCode("/profile <nombre>")}`].join("\n")),!0}if("/profile"===p||"/perfil"===p){const e=x()??"claude";if(!D(e))return await replyToJid(r,`${waAlert("Error")}\nEl proveedor activo (${e}) no usa perfiles.`),!0;const a=u.join(" ").trim();if(!a)return await replyToJid(r,`*Uso:* ${waCode("/profile <nombre>")}`),!0;const o=W(e,a);return await replyToJid(r,[waTitle("Perfil Activado"),"",`*Perfil:* ${o.provider}/${o.name}`,`*Agente:* ${o.agentName}`].join("\n")),!0}if("/repos"===p){const e=s(),a=g(),o=c(i)??e.alias,t=a.map(e=>{const a=e.alias===o?" * (activo)":"";return waBullet(`${e.alias}${a}`)});return await replyToJid(r,[waTitle("Repos Registrados"),"",...t,"","==","",`*Uso:* ${waCode("/use <alias>")}`].join("\n")),!0}if("/workspace-sync"===p){const t=await async function(){const t=[],r=new Set,i=new Set([process.cwd(),a(process.cwd())]);for(const a of i){try{if(await e.stat(o(a,".git"))){const e=l(a);r.has(e.path)||(r.add(e.path),t.push({alias:e.alias,path:e.path}))}}catch{}let i=[];try{i=await e.readdir(a,{withFileTypes:!0})}catch{continue}for(const n of i){if(!n.isDirectory())continue;const i=o(a,n.name);try{if(!await e.stat(o(i,".git")))continue}catch{continue}const s=l(i);r.has(s.path)||(r.add(s.path),t.push({alias:s.alias,path:s.path}))}}return t}();if(0===t.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo encontre repos nuevos cerca del directorio actual.`),!0;const i=t.map(e=>waBullet(e.alias));return await replyToJid(r,[waTitle("Repos Detectados"),"",...i].join("\n")),!0}if("/use"===p||"/cd"===p){const e=u.join(" ").trim();if(!e)return await replyToJid(r,`*Uso:* ${waCode(p+" <alias>")}`),!0;const a=await switchProcessWorkspaceByAlias(e);if(!a.ok)return await replyToJid(r,`${waAlert("Error")}\n${a.message}`),!0;if(!v(i,a.alias))return await replyToJid(r,`${waAlert("Error")}\nNo existe el repo "${e}". Usa /repos para ver aliases.`),!0;const o=d(i);return await replyToJid(r,[waTitle("Repo Activado"),"",`*Alias:* ${o?.alias??a.alias}`,`*Ruta:* ${o?.path??a.path}`,`*CWD:* ${process.cwd()}`].join("\n")),!0}if("/status"===p){const e=s(),a=d(i)??e,o=(process.env.CONTEXT_BRIDGE_RESUME_MIRROR_MODE??process.env.CONTEXT_RESUME_MIRROR_MODE??"summary").toLowerCase();return await replyToJid(r,[waTitle("Estado del Bridge"),"",`*Repo activo:* ${a.alias}`,`*Ruta:* ${a.path}`,`*Numero:* ${i}`,`*Total repos:* ${g().length}`,`*Resume mirror:* ${o}`].join("\n")),!0}if("/canal-global"===p||"/global-canal"===p||"/cg"===p){const e=(u[0]??"status").toLowerCase();if("status"===e||"estado"===e){const e=await G();return await replyToJid(r,[waTitle("Canal Global"),"","*Estado:* "+(e.running?"activo":"inactivo"),`*PID:* ${e.pid??"n/a"}`,`*Inicio:* ${e.startedAt??"n/a"}`,"","==","",waTitle("Opciones"),waBullet("/canal-global start"),waBullet("/canal-global stop"),waBullet("/canal-global status")].join("\n")),!0}if("start"===e||"iniciar"===e){const e=await I();return await replyToJid(r,`*Resultado:* ${e}`),!0}if("stop"===e||"detener"===e){const e=await _();return await replyToJid(r,`*Resultado:* ${e}`),!0}return await replyToJid(r,[waTitle("Canal Global - Ayuda"),"",waBullet("/canal-global status"),waBullet("/canal-global start"),waBullet("/canal-global stop")].join("\n")),!0}if("/aprobar"===p||"/approve"===p||"/aprobar-siempre"===p||"/approve-always"===p||"/denegar"===p||"/deny"===p){const e="/aprobar-siempre"===p||"/approve-always"===p,a="/denegar"===p||"/deny"===p,o=u.join(" ").trim();if(!o){const e=z();if(0===e.length)return await replyToJid(r,`${waAlert("Aviso")}\nNo hay permisos pendientes.`),!0;const a=e.map(e=>waBullet(`[${e.id}] ${e.toolName}: ${(e.description||"(sin detalle)").slice(0,100)}`));return await replyToJid(r,[waTitle(`Permisos pendientes (${e.length})`),"",...a,"","==","","*Uso:* /aprobar <id> o /aprobar-siempre <id> o /denegar <id>"].join("\n")),!0}const t=o.toLowerCase(),i=a?Q(t):q(t,e);if("not_found"===i.kind)return await replyToJid(r,`${waAlert("Error")}\nNo encontre ningun permiso con id "${t}". Usa /aprobar para listarlos.`),!0;if("already_resolved"===i.kind)return await replyToJid(r,`${waAlert("Aviso")}\nEl permiso ${t} (${i.item.toolName}) ya fue resuelto — ignorado.`),!0;const n=a?"rechazado":e?"aprobado permanentemente":"aprobado";return await replyToJid(r,[waTitle("Permiso Resuelto"),"",`*ID:* ${t}`,`*Herramienta:* ${i.item.toolName}`,`*Accion:* ${n}`].join("\n")),!0}if("/help"===p||"/ayuda"===p||"/ayudame"===p)return await replyToJid(r,[waTitle("Ayuda WhatsApp Bridge"),"",waBullet("/repos -> ver repos registrados"),waBullet("/use <alias> -> cambiar de repo"),waBullet("/status -> ver estado actual"),waBullet("/workspace-sync -> registrar repos git"),waBullet("/proveedores -> ver proveedores"),waBullet("/provider <nombre> -> cambiar proveedor"),waBullet("/modelo <nombre> -> cambiar modelo"),waBullet("/profiles -> ver perfiles"),waBullet("/profile <nombre> -> cambiar perfil"),waBullet("/canal-global <start|stop|status>"),waBullet("/aprobar [id] -> resolver permisos"),waBullet("/ayuda -> mostrar ayuda")].join("\n")),!0;return!1}(T,i,n);if(!t){if(M(`[wa:inbound] slash passthrough to CLI sender=${n}`),H)return H(T),void M(`[wa:inbound] injected via inboundHandler sender=${n}`);k(T),enqueueCommand({value:T,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] injected via enqueue fallback sender=${n}`)}})();if(H)return H($),void M(`[wa:inbound] text injected via inboundHandler sender=${n}`);if(isGlobalBridgeModeEnabled())return void runGlobalPromptFlow($.trim(),i,n);const J=$.trim();J&&(k(J),enqueueCommand({value:J,mode:"prompt",skipSlashCommands:!1,bridgeOrigin:!0}),M(`[wa:inbound] text injected via enqueue fallback sender=${n}`))}function isGlobalBridgeModeEnabled(){return"1"===process.env.CONTEXT_BRIDGE_GLOBAL_MODE}async function runGlobalPromptFlow(e,a,o){if(e)try{await replyToJid(a,"Procesando...");const t=await U(e,o);await replyToJid(a,t)}catch(e){await replyToJid(a,`Error ejecutando prompt global: ${e instanceof Error?e.message:String(e)}`)}}async function replyToJid(e,a){if(F)try{await F.sendMessage(e,{text:a})}catch{}}async function switchProcessWorkspaceByAlias(a){const o=a.trim().toLowerCase(),t=g().find(e=>e.alias.toLowerCase()===o);if(!t)return{ok:!1,message:`No existe el repo "${a}". Usa /repos para ver aliases.`};try{if(!(await e.stat(t.path)).isDirectory())return{ok:!1,message:`La ruta de ${t.alias} no es una carpeta valida: ${t.path}`}}catch{return{ok:!1,message:`La ruta de ${t.alias} no existe: ${t.path}`}}try{process.chdir(t.path)}catch(e){return{ok:!1,message:`No pude cambiar al repo ${t.alias}: ${e instanceof Error?e.message:String(e)}`}}return{ok:!0,alias:t.alias,path:t.path}}export async function startLoginWithQr(e){const a=m(),o=await B(a);if(o.jid)return{alreadyLinked:!0,selfJid:o.jid,selfE164:o.e164};F&&(T(F),F=null);const{sock:t,saveCreds:r}=await J({authDir:a,onQr:e.onQr}),i=e.timeoutMs??12e4;try{await Promise.race([E(t),new Promise((e,a)=>setTimeout(()=>a(new Error("QR timeout")),i))])}catch(e){if(515!==j(e))throw T(t),e;{T(t);const e=await J({authDir:a});try{await E(e.sock),T(e.sock)}catch{}}}T(t);try{await r()}catch{}const n=await B(a);return n.jid&&$(n.jid,n.e164),{alreadyLinked:!1,selfJid:n.jid,selfE164:n.e164}}export async function startWhatsAppBridge(){if(F)return{success:!1,message:"El bridge ya está en ejecución."};const e=m(),a=await B(e);if(!a.jid)return{success:!1,message:"WhatsApp no está vinculado. Escanea el QR desde /whatsapp primero."};try{const o=s(),t=p(),r=t?c(t):void 0;r&&await switchProcessWorkspaceByAlias(r);const{sock:i}=await J({authDir:e});await E(i),function(e){const a=e?.user?.id,o=e?.user?.lid,t=a??o;if(!t)return;const r=String(t).split("@")[0]?.split(":")[0],i=r&&/^\d+$/.test(r)?`+${r}`:void 0;$(t,i)}(i),function(e){e.ev.on("messages.upsert",a=>{if(a&&Array.isArray(a.messages))for(const o of a.messages){try{handleInbound(o)}catch{}try{const a=o?.key,t=a?.remoteJid;!a||a.fromMe||!t||t.endsWith("@g.us")||t.endsWith("@newsletter")||"function"!=typeof e.readMessages||e.readMessages([a]).catch(()=>{})}catch{}}})}(i),function(e){e.ev.on("connection.update",a=>{"close"===a?.connection&&(401===j(a.lastDisconnect?.error)?autoUnlinkOnLoggedOut():F===e&&(T(F),F=null,C(null),h(!1)))})}(i),F=i,C(i),h(!0);const n=w();return{success:!0,message:`Bridge iniciado correctamente. Cuenta: ${n?.selfE164??a.e164??"desconocido"}. Repo activo: ${o.alias}`}}catch(e){return 401===j(e)?(await autoUnlinkOnLoggedOut(),{success:!1,message:"WhatsApp reportó que la sesión fue cerrada desde el móvil. Credenciales limpiadas; ejecuta /whatsapp de nuevo para mostrar un QR fresco."}):{success:!1,message:`Error al iniciar: ${e instanceof Error?e.message:String(e)}`}}}export async function stopWhatsAppBridge(){if(!F)return{success:!1,message:"El bridge no está en ejecución."};try{return T(F),F=null,C(null),h(!1),{success:!0,message:"Bridge detenido correctamente."}}catch(e){return F=null,C(null),h(!1),{success:!1,message:`Error al detener: ${e instanceof Error?e.message:String(e)}`}}}export{r as addAllowedNumber,y as normalizeE164,n as e164ToJid};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e164ToJid as t,getActiveWorkspaceAliasForNumber as
|
|
1
|
+
import{e164ToJid as t,getActiveWorkspaceAliasForNumber as n,getPrimaryRecipient as e}from"./config.js";import{consumeInjectedMarkIfSameOrigin as o,markInjected as s,splitForChannel as r}from"../mirrors/shared.js";import{markdownToWhatsApp as i}from"./markdown.js";const l={user:"*USER* >>",assistant:"*AI* >>",tool:"*TOOL* >>"};export function splitMessageForWhatsApp(t,n=10){if(!t)return[];const e=t.split(/\n==\n/),o=[];let s=[];for(const t of e){const e=t.trim();if(!e)continue;const r=e.split("\n");if(r.length>n){s.length>0&&(o.push(s.join("\n")),s=[]);for(let t=0;t<r.length;t+=n){const e=r.slice(t,t+n);o.push(e.join("\n"))}}else{const t=s.length>0?3:0;s.length+t+r.length>n?(o.push(s.join("\n")),s=[...r]):(s.length>0&&s.push("=="),s.push(...r))}}return s.length>0&&o.push(s.join("\n")),o.map(t=>t.trim()).filter(Boolean)}let p=null;const f=[];let h=!1;export function setMirrorSocket(t){p=t,t||(f.length=0,h=!1)}export function markInjectedFromWhatsApp(t){s(t,"whatsapp")}export function mirrorToWhatsApp(s,c){if(!p)return;if(!e())return;const a=c?.trim();a&&("user"===s&&o(a,"whatsapp")||(f.length>=200&&f.shift(),f.push({role:s,text:a}),async function(){if(h)return;h=!0;try{for(;f.length>0&&p;){const o=f.shift(),s=e();if(!s)break;const h=t(s),c=n(s),a=c?`[${c}] `:"",u=splitMessageForWhatsApp(i(`${a}${l[o.role]} ${o.text}`),10),m=[];for(const t of u){const n=r(t,4e3).filter(t=>t.trim().length>0);m.push(...n)}for(const t of m){try{await p.sendMessage(h,{text:t})}catch{continue}await sleep(500)}}}finally{h=!1}}()))}function sleep(t){return new Promise(n=>setTimeout(n,t))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,Aa as r,Ba as i,C as a,Ca as o,Da as l,Ea as u,J as h,P as p,Q as b,a as g,aa as w,c as d,d as v,f
|
|
1
|
+
import{A as e,Aa as r,Ba as i,C as a,Ca as o,Da as l,Ea as u,J as h,P as p,Q as b,a as g,aa as w,c as d,d as v,f,h as E,i as m,j as y,k,l as O,m as T,o as C,pa as A,q as I,r as P,s as S,t as M,wa as N,xa as D,ya as W,za as L}from"./chunk-VAB2VXFI.js";var _="Service workers are disabled or not supported by this browser",x=class{serviceWorker;worker;registration;events;constructor(e,r){if(this.serviceWorker=e,e){let i=null,a=new v;this.worker=new d(e=>(null!==i&&e.next(i),a.subscribe(r=>e.next(r))));let s=()=>{let{controller:r}=e;null!==r&&(i=r,a.next(i))};e.addEventListener("controllerchange",s),s(),this.registration=this.worker.pipe(k(()=>e.getRegistration()));let o=new v;this.events=o.asObservable();let c=e=>{let{data:r}=e;r?.type&&o.next(r)};e.addEventListener("message",c),r?.get(b,null,{optional:!0})?.onDestroy(()=>{e.removeEventListener("controllerchange",s),e.removeEventListener("message",c)})}else this.worker=this.events=this.registration=new d(e=>e.error(new O(5601,!1)))}postMessage(e,r){return new Promise(i=>{this.worker.pipe(y(1)).subscribe(a=>{a.postMessage(g({action:e},r)),i()})})}postMessageWithOperation(e,r,i){let a=this.waitForOperationCompleted(i),o=this.postMessage(e,r);return Promise.all([o,a]).then(([,e])=>e)}generateNonce(){return Math.round(1e7*Math.random())}eventsOfType(e){let r;return r="string"==typeof e?r=>r.type===e:r=>e.includes(r.type),this.events.pipe(m(r))}nextEventOfType(e){return this.eventsOfType(e).pipe(y(1))}waitForOperationCompleted(e){return new Promise((r,i)=>{this.eventsOfType("OPERATION_COMPLETED").pipe(m(r=>r.nonce===e),y(1),f(e=>{if(void 0!==e.result)return e.result;throw new Error(e.error)})).subscribe({next:r,error:i})})}get isEnabled(){return!!this.serviceWorker}},V=(()=>{class n{sw;messages;notificationClicks;subscription;get isEnabled(){return this.sw.isEnabled}pushManager=null;subscriptionChanges=new v;constructor(e){if(this.sw=e,!e.isEnabled)return this.messages=E,this.notificationClicks=E,void(this.subscription=E);this.messages=this.sw.eventsOfType("PUSH").pipe(f(e=>e.data)),this.notificationClicks=this.sw.eventsOfType("NOTIFICATION_CLICK").pipe(f(e=>e.data)),this.pushManager=this.sw.registration.pipe(f(e=>e.pushManager));let r=this.pushManager.pipe(k(e=>e.getSubscription()));this.subscription=new d(e=>{let i=r.subscribe(e),a=this.subscriptionChanges.subscribe(e);return()=>{i.unsubscribe(),a.unsubscribe()}})}requestSubscription(e){if(!this.sw.isEnabled||null===this.pushManager)return Promise.reject(new Error(_));let r={userVisibleOnly:!0},i=this.decodeBase64(e.serverPublicKey.replace(/_/g,"/").replace(/-/g,"+")),a=new Uint8Array(new ArrayBuffer(i.length));for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);return r.applicationServerKey=a,new Promise((e,i)=>{this.pushManager.pipe(k(e=>e.subscribe(r)),y(1)).subscribe({next:r=>{this.subscriptionChanges.next(r),e(r)},error:i})})}unsubscribe(){if(!this.sw.isEnabled)return Promise.reject(new Error(_));let t=e=>{if(null===e)throw new O(5602,!1);return e.unsubscribe().then(e=>{if(!e)throw new O(5603,!1);this.subscriptionChanges.next(null)})};return new Promise((e,r)=>{this.subscription.pipe(y(1),k(t)).subscribe({next:e,error:r})})}decodeBase64(e){return atob(e)}static ɵfac=function(e){return new(e||n)(P(x))};static ɵprov=C({token:n,factory:n.ɵfac})}return n})(),F=(()=>{class n{sw;versionUpdates;unrecoverable;get isEnabled(){return this.sw.isEnabled}constructor(e){if(this.sw=e,!e.isEnabled)return this.versionUpdates=E,void(this.unrecoverable=E);this.versionUpdates=this.sw.eventsOfType(["VERSION_DETECTED","VERSION_INSTALLATION_FAILED","VERSION_READY","NO_NEW_VERSION_DETECTED"]),this.unrecoverable=this.sw.eventsOfType("UNRECOVERABLE_STATE")}checkForUpdate(){if(!this.sw.isEnabled)return Promise.reject(new Error(_));let e=this.sw.generateNonce();return this.sw.postMessageWithOperation("CHECK_FOR_UPDATES",{nonce:e},e)}activateUpdate(){if(!this.sw.isEnabled)return Promise.reject(new O(5601,!1));let e=this.sw.generateNonce();return this.sw.postMessageWithOperation("ACTIVATE_UPDATE",{nonce:e},e)}static ɵfac=function(e){return new(e||n)(P(x))};static ɵprov=C({token:n,factory:n.ɵfac})}return n})(),R=new I("");function X(){let e=S(U);if(!("serviceWorker"in navigator)||!1===e.enabled)return;let r=S(R),i=S(a),o=S(b);i.runOutsideAngular(()=>{let e=navigator.serviceWorker,s=()=>e.controller?.postMessage({action:"INITIALIZE"});e.addEventListener("controllerchange",s),o.onDestroy(()=>{e.removeEventListener("controllerchange",s)})}),i.runOutsideAngular(()=>{let i,{registrationStrategy:a}=e;if("function"==typeof a)i=new Promise(e=>a().subscribe(()=>e()));else{let[e,...r]=(a||"registerWhenStable:30000").split(":");switch(e){case"registerImmediately":i=Promise.resolve();break;case"registerWithDelay":i=q(+r[0]||0);break;case"registerWhenStable":i=Promise.race([o.whenStable(),q(+r[0])]);break;default:throw new O(5600,!1)}}i.then(()=>{o.destroyed||navigator.serviceWorker.register(r,{scope:e.scope}).catch(e=>console.error(T(5604,!1)))})})}function q(e){return new Promise(r=>setTimeout(r,e))}function ee(e,r){return new x(!1!==e.enabled?navigator.serviceWorker:void 0,r)}var U=class{enabled;scope;registrationStrategy};N(class n{constructor(){this.auth=S(l),this.socket=S(u)}ngOnInit(){this.auth.hasToken()&&this.socket.connect()}static{this.ɵfac=function(e){return new(e||n)}}static{this.ɵcmp=h({type:n,selectors:[["cx-root"]],decls:1,vars:0,template:function(e,r){1&e&&w(0,"router-outlet")},dependencies:[L],encapsulation:2,changeDetection:0})}},{providers:[i([{path:"",redirectTo:"chat",pathMatch:"full"},{path:"login",loadComponent:()=>import("./chunk-NFYBHCXF.js").then(e=>e.LoginComponent)},{path:"chat",canActivate:[()=>{let e=S(l),i=S(r);return!!e.hasToken()||(i.navigate(["/login"]),!1)}],loadComponent:()=>import("./chunk-AMCDNAIG.js").then(e=>e.ChatComponent)},{path:"**",redirectTo:"chat"}],o()),D(W()),function(r,i={}){return M([V,F,{provide:R,useValue:r},{provide:U,useValue:i},{provide:x,useFactory:ee,deps:[U,e]},p(X)])}("ngsw-worker.js",{enabled:!A(),registrationStrategy:"registerWhenStable:30000"})]}).catch(e=>console.error("[webapp] bootstrap error",e));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iaforged/context-code",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "Context Code es un asistente de desarrollo para la terminal. Puede revisar tu proyecto, editar archivos, ejecutar comandos y apoyarte en tareas reales de programacion.",
|
|
5
5
|
"author": "Context AI",
|
|
6
6
|
"license": "MIT",
|