@promptbook/cli 0.114.0-13 → 0.114.0-18
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/apps/agents-server/next.config.ts +6 -0
- package/apps/agents-server/src/app/admin/_components/AdminFilterFields.tsx +84 -0
- package/apps/agents-server/src/app/admin/_components/AdminMetricCard.tsx +36 -0
- package/apps/agents-server/src/app/admin/_components/AdminTaskManagerTabs.tsx +97 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerClient.tsx +103 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerEditDialog.tsx +232 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerFiltersCard.tsx +195 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerRow.tsx +189 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerSummaryMetrics.tsx +60 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerTableCard.tsx +147 -0
- package/apps/agents-server/src/app/admin/planned-messages/page.tsx +17 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageEditForm.ts +186 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageManagerDialogs.ts +46 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageManagerPresentation.tsx +188 -0
- package/apps/agents-server/src/app/admin/planned-messages/resolvePlannedMessageSortValue.ts +115 -0
- package/apps/agents-server/src/app/admin/planned-messages/usePlannedMessageManagerData.ts +116 -0
- package/apps/agents-server/src/app/admin/planned-messages/usePlannedMessageManagerState.ts +289 -0
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +7 -2
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerFiltersCard.tsx +7 -73
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerSummaryMetrics.tsx +5 -30
- package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +1 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/book/reference-diagnostics/route.ts +30 -7
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +1 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/test.http +3 -3
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorMissingReferences.tsx +106 -12
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +3 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorDiagnostics.ts +12 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorWrapper.tsx +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +46 -3
- package/apps/agents-server/src/app/api/admin/default-agents/reinstate/route.ts +5 -1
- package/apps/agents-server/src/app/api/admin/planned-messages/[timeoutId]/route.ts +80 -0
- package/apps/agents-server/src/app/api/admin/planned-messages/route.ts +19 -0
- package/apps/agents-server/src/app/api/internal/agent-goal-chat-planned-messages/route.ts +30 -2
- package/apps/agents-server/src/components/DefaultAgents/ReinstateBundledAgentsButton.tsx +7 -0
- package/apps/agents-server/src/components/DefaultAgents/coreAgentsAdminRoute.ts +6 -0
- package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +7 -0
- package/apps/agents-server/src/components/Homepage/DefaultAgentsStatusNotice.tsx +1 -7
- package/apps/agents-server/src/database/migrations/2026-08-1800-user-chat-timeout-schedule.sql +11 -0
- package/apps/agents-server/src/instrumentation-node.ts +18 -0
- package/apps/agents-server/src/languages/ServerTranslationKeys.ts +4 -0
- package/apps/agents-server/src/languages/translations/czech.yaml +4 -0
- package/apps/agents-server/src/languages/translations/english.yaml +4 -0
- package/apps/agents-server/src/tools/agentGoalChatTimeoutToolFunctions.ts +62 -15
- package/apps/agents-server/src/tools/agentGoalChatTimeoutTools.ts +63 -9
- package/apps/agents-server/src/utils/adminEntityLookups/loadAgentNamesByPermanentId.ts +45 -0
- package/apps/agents-server/src/utils/adminEntityLookups/loadUsernamesByUserId.ts +36 -0
- package/apps/agents-server/src/utils/adminEntityLookups.ts +2 -0
- package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatPlannedMessageActions.ts +299 -52
- package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +45 -17
- package/apps/agents-server/src/utils/agentGoalChat.ts +1 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectIdentity.ts +46 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeAutostartScheduler.ts +162 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDesiredState.ts +252 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDisplay.ts +6 -3
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDomains.ts +2 -44
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePaths.ts +25 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePm2.ts +4 -3
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeRegistry.ts +77 -24
- package/apps/agents-server/src/utils/agentProjects/agentProjectStateMutationQueue.ts +58 -0
- package/apps/agents-server/src/utils/agentProjects/listAllLocalAgentProjectIdentities.ts +48 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectRuntimeEnvironmentFlag.ts +23 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectRuntimeStatus.ts +73 -0
- package/apps/agents-server/src/utils/agentProjects/startDefaultAgentProjectRuntimes.ts +110 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/MissingCoreAgentRecovery.ts +19 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/bookScopedAgentReferences.ts +7 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/createAgentInheritanceDiagnostics.ts +457 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/createUnresolvedAgentReferenceDiagnostics.ts +27 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/resolveCoreAgentAwareMissingReferences.ts +156 -0
- package/apps/agents-server/src/utils/chatMessageChips/createAnsweredMessageChipToolCalls.ts +15 -3
- package/apps/agents-server/src/utils/chatMessageChips/createPlannedMessageChipToolCalls.ts +8 -3
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedExternalSourceChipToolCalls.ts +39 -0
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipResult.ts +45 -0
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipToolCalls.ts +58 -24
- package/apps/agents-server/src/utils/cronExpression/CronExpression.ts +63 -0
- package/apps/agents-server/src/utils/cronExpression/normalizeCronExpression.ts +34 -0
- package/apps/agents-server/src/utils/cronExpression/normalizeCronExpressionWhitespace.ts +11 -0
- package/apps/agents-server/src/utils/cronExpression/parseCronExpression.ts +41 -0
- package/apps/agents-server/src/utils/cronExpression/parseCronExpressionField.ts +140 -0
- package/apps/agents-server/src/utils/cronExpression/resolveNextCronRun.ts +100 -0
- package/apps/agents-server/src/utils/cronExpression/throwInvalidCronExpressionField.ts +20 -0
- package/apps/agents-server/src/utils/cronExpression.ts +10 -0
- package/apps/agents-server/src/utils/explicitFromCommitment.ts +130 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/loadAdminChatTaskFallbackData.ts +3 -77
- package/apps/agents-server/src/utils/localChatRunner/applyLocalAgentPlannedMessageCommands.ts +53 -4
- package/apps/agents-server/src/utils/localChatRunner/prepareLocalAgentPlannedMessagesSidecar.ts +15 -7
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +8 -0
- package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentBooks.ts +5 -11
- package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentRuntime.ts +2 -2
- package/apps/agents-server/src/utils/managementApi/managementApiSchemas.ts +2 -2
- package/apps/agents-server/src/utils/plannedMessageManager/cancelManagedPlannedMessage.ts +35 -0
- package/apps/agents-server/src/utils/plannedMessageManager/collectPlannedMessageAgentOptions.ts +56 -0
- package/apps/agents-server/src/utils/plannedMessageManager/createPlannedMessageManagerCounters.ts +104 -0
- package/apps/agents-server/src/utils/plannedMessageManager/filterPlannedMessages.ts +191 -0
- package/apps/agents-server/src/utils/plannedMessageManager/getPlannedMessageManagerResponse.ts +55 -0
- package/apps/agents-server/src/utils/plannedMessageManager/isPlannedMessageStillPlanned.ts +18 -0
- package/apps/agents-server/src/utils/plannedMessageManager/loadPlannedMessageManagerRecord.ts +32 -0
- package/apps/agents-server/src/utils/plannedMessageManager/mapPlannedMessageManagerRecord.ts +73 -0
- package/apps/agents-server/src/utils/plannedMessageManager/parsePlannedMessageManagerUpdateRequest.ts +76 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageEndReason.ts +59 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageLifecycle.ts +99 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageRecurrenceKind.ts +40 -0
- package/apps/agents-server/src/utils/plannedMessageManager/updateManagedPlannedMessage.ts +121 -0
- package/apps/agents-server/src/utils/plannedMessagesAdmin.ts +200 -0
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +114 -95
- package/apps/agents-server/src/utils/userChatClient.ts +4 -0
- package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +37 -1
- package/apps/agents-server/src/utils/userChatTimeout/agentScopedTimeoutBulkActions.ts +11 -17
- package/apps/agents-server/src/utils/userChatTimeout/createTimeoutWakeUpMessage.ts +37 -13
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/PlannedMessageSchedule.ts +52 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/hasPlannedMessageRecurrence.ts +13 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/isPlannedMessageScheduleFinished.ts +30 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/normalizePlannedMessageScheduleValues.ts +62 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/parsePlannedMessageSchedule.ts +202 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/resolvePlannedMessageDueAt.ts +121 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule.ts +12 -0
- package/apps/agents-server/src/utils/userChatTimeout/setAgentScopedUserChatTimeoutPausedState.ts +66 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/createUserChatTimeout.ts +76 -5
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAllUserChatTimeouts.ts +37 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/mapUserChatTimeoutRow.ts +9 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/repeatFiredUserChatTimeout.ts +19 -9
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/updateAgentScopedUserChatTimeout.ts +39 -6
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore.ts +1 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +110 -11
- package/apps/agents-server/src/utils/userChatTimeout.ts +16 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateCron.ts +23 -316
- package/apps/agents-server/tests/e2e/support/AgentManagementApi.ts +3 -3
- package/esm/index.es.js +951 -102
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/git/commitAgentProjectChanges.d.ts +15 -0
- package/esm/scripts/run-agent-messages/git/commitAnsweredMessageProjectChanges.d.ts +24 -0
- package/esm/scripts/run-agent-messages/git/ensureAgentProjectGitRepository.d.ts +20 -0
- package/esm/scripts/run-agent-messages/git/readAgentProjectCommitChange.d.ts +11 -0
- package/esm/scripts/run-agent-messages/git/runAgentProjectGitCommand.d.ts +29 -0
- package/esm/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +3 -3
- package/esm/scripts/run-agent-messages/messages/listAgentProjectDirectoryNames.d.ts +7 -0
- package/esm/scripts/run-agent-messages/messages/resolveAnsweredMessageTouches.d.ts +29 -0
- package/esm/scripts/run-codex-prompts/ping/pingCoderHarnessPeriodically.d.ts +22 -0
- package/esm/src/book-3.0/AgentMessageRunReport.d.ts +18 -0
- package/esm/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +38 -5
- package/esm/src/book-3.0/describeAgentPlannedMessageSchedule.d.ts +31 -0
- package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +1 -9
- package/esm/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.d.ts +28 -0
- package/esm/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.test.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/renderAgentProjectDiff.d.ts +13 -0
- package/esm/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.d.ts +16 -0
- package/esm/src/book-components/Chat/utils/agentProjectToolCall.d.ts +39 -0
- package/esm/src/book-components/Chat/utils/agentProjectToolCall.test.d.ts +1 -0
- package/esm/src/book-components/Chat/utils/externalSourceToolCall.d.ts +38 -0
- package/esm/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +6 -0
- package/esm/src/cli/cli-commands/coder/waitOptions.d.ts +12 -0
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +15 -0
- package/esm/src/utils/agent-message-runtime/AgentMessageProjectChange.d.ts +76 -0
- package/esm/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.d.ts +45 -0
- package/esm/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +3 -0
- package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.d.ts +18 -0
- package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.test.d.ts +1 -0
- package/esm/src/utils/random/$generateBookBoilerplate.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/book-2.0/agent-source/string_book.ts +1 -1
- package/src/book-2.0/book-language-documentation/czechBookLanguageManualDictionary.ts +6 -1
- package/src/book-2.0/book-language-documentation/englishBookLanguageManualDictionary.ts +6 -1
- package/src/book-3.0/AgentMessageRunReport.ts +59 -0
- package/src/book-3.0/AgentPlannedMessagesSidecar.ts +64 -9
- package/src/book-3.0/describeAgentPlannedMessageSchedule.ts +94 -0
- package/src/book-components/BookEditor/BookEditorMonaco.tsx +2 -0
- package/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.ts +3 -11
- package/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.ts +71 -0
- package/src/book-components/Chat/Chat/Chat.module.css +165 -18
- package/src/book-components/Chat/Chat/ChatMessageMap.tsx +0 -1
- package/src/book-components/Chat/Chat/renderAgentProjectDiff.tsx +85 -0
- package/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.tsx +206 -0
- package/src/book-components/Chat/Chat/renderToolCallDetails.tsx +8 -0
- package/src/book-components/Chat/MarkdownContent/MarkdownContent.tsx +2 -3
- package/src/book-components/Chat/utils/agentProjectToolCall.ts +82 -5
- package/src/book-components/Chat/utils/externalSourceToolCall.ts +65 -0
- package/src/book-components/Chat/utils/getToolCallChipletInfo.ts +36 -0
- package/src/book-components/Chat/utils/renderMarkdown.ts +3 -10
- package/src/book-components/Chat/utils/timeoutToolCallPresentation.ts +12 -1
- package/src/cli/cli-commands/coder/ping.ts +35 -9
- package/src/cli/cli-commands/coder/waitOptions.ts +33 -0
- package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +3 -1
- package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +3 -1
- package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +1 -4
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +47 -3
- package/src/commands/FORMAT/formatCommandParser.ts +4 -2
- package/src/commitments/FROM/FROM.ts +13 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +819 -751
- package/src/utils/agent-message-runtime/AgentMessageProjectChange.ts +183 -0
- package/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.ts +80 -0
- package/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.ts +3 -0
- package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +2 -4
- package/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.ts +341 -0
- package/src/utils/random/$generateBookBoilerplate.ts +1 -1
- package/src/version.ts +2 -2
- package/src/versions.txt +5 -0
- package/umd/index.umd.js +950 -101
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/git/commitAgentProjectChanges.d.ts +15 -0
- package/umd/scripts/run-agent-messages/git/commitAnsweredMessageProjectChanges.d.ts +24 -0
- package/umd/scripts/run-agent-messages/git/ensureAgentProjectGitRepository.d.ts +20 -0
- package/umd/scripts/run-agent-messages/git/readAgentProjectCommitChange.d.ts +11 -0
- package/umd/scripts/run-agent-messages/git/runAgentProjectGitCommand.d.ts +29 -0
- package/umd/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +3 -3
- package/umd/scripts/run-agent-messages/messages/listAgentProjectDirectoryNames.d.ts +7 -0
- package/umd/scripts/run-agent-messages/messages/resolveAnsweredMessageTouches.d.ts +29 -0
- package/umd/scripts/run-codex-prompts/ping/pingCoderHarnessPeriodically.d.ts +22 -0
- package/umd/src/book-3.0/AgentMessageRunReport.d.ts +18 -0
- package/umd/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +38 -5
- package/umd/src/book-3.0/describeAgentPlannedMessageSchedule.d.ts +31 -0
- package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +1 -9
- package/umd/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.d.ts +28 -0
- package/umd/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.test.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/renderAgentProjectDiff.d.ts +13 -0
- package/umd/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.d.ts +16 -0
- package/umd/src/book-components/Chat/utils/agentProjectToolCall.d.ts +39 -0
- package/umd/src/book-components/Chat/utils/agentProjectToolCall.test.d.ts +1 -0
- package/umd/src/book-components/Chat/utils/externalSourceToolCall.d.ts +38 -0
- package/umd/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +6 -0
- package/umd/src/cli/cli-commands/coder/waitOptions.d.ts +12 -0
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +15 -0
- package/umd/src/utils/agent-message-runtime/AgentMessageProjectChange.d.ts +76 -0
- package/umd/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.d.ts +45 -0
- package/umd/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +3 -0
- package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.d.ts +18 -0
- package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.test.d.ts +1 -0
- package/umd/src/utils/random/$generateBookBoilerplate.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerScopeTabs.tsx +0 -74
- package/esm/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +0 -15
- package/umd/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +0 -15
package/apps/agents-server/src/utils/agentReferenceResolver/createAgentInheritanceDiagnostics.ts
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES } from '../../../../../servers';
|
|
2
|
+
import type { AgentReferenceResolver } from '../../../../../src/book-2.0/agent-source/AgentReferenceResolver';
|
|
3
|
+
import { isVoidPseudoAgentReference } from '../../../../../src/book-2.0/agent-source/pseudoAgentReferences';
|
|
4
|
+
import type {
|
|
5
|
+
string_agent_permanent_id,
|
|
6
|
+
string_agent_url,
|
|
7
|
+
string_book,
|
|
8
|
+
} from '../../../../../src/_packages/types.index';
|
|
9
|
+
import type { AgentCollection } from '../../../../../src/collection/agent-collection/AgentCollection';
|
|
10
|
+
import { isValidAgentUrl } from '../../../../../src/utils/validators/url/isValidAgentUrl';
|
|
11
|
+
import { getEffectiveExplicitFromCommitment, type ExplicitFromCommitment } from '../explicitFromCommitment';
|
|
12
|
+
import {
|
|
13
|
+
createLocalAgentUrl,
|
|
14
|
+
normalizeLocalServerUrls,
|
|
15
|
+
resolveLocalAgentRouteReference,
|
|
16
|
+
} from '../localAgentRouteReferences';
|
|
17
|
+
import { createBookScopedAgentReferenceResolver, resolveBookScopedAgentContext } from './bookScopedAgentReferences';
|
|
18
|
+
import { createServerAgentReferenceResolver } from './createServerAgentReferenceResolver';
|
|
19
|
+
import type { AgentReferenceDiagnostic } from './createUnresolvedAgentReferenceDiagnostics';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of local inheritance links inspected while preparing Book editor diagnostics.
|
|
23
|
+
*
|
|
24
|
+
* A real local cycle is found much sooner, while this bound keeps an unexpectedly deep graph from delaying the editor.
|
|
25
|
+
*
|
|
26
|
+
* @private utility of Agents Server inheritance diagnostics
|
|
27
|
+
*/
|
|
28
|
+
const MAX_LOCAL_INHERITANCE_DIAGNOSTIC_DEPTH = 100;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Monaco marker source used for invalid root and circular inheritance warnings.
|
|
32
|
+
*
|
|
33
|
+
* @private utility of Agents Server inheritance diagnostics
|
|
34
|
+
*/
|
|
35
|
+
const AGENT_INHERITANCE_DIAGNOSTIC_SOURCE = 'agent-inheritance';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Dependencies needed to validate the effective local `FROM` chain of one in-editor book.
|
|
39
|
+
*
|
|
40
|
+
* @private utility of Agents Server inheritance diagnostics
|
|
41
|
+
*/
|
|
42
|
+
export type CreateAgentInheritanceDiagnosticsOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* Current unsaved source from the Book editor.
|
|
45
|
+
*/
|
|
46
|
+
readonly agentSource: string_book;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Stable permanent id of the agent being edited.
|
|
50
|
+
*/
|
|
51
|
+
readonly agentPermanentId: string_agent_permanent_id;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Collection used to load local ancestors and their Book sources.
|
|
55
|
+
*/
|
|
56
|
+
readonly collection: AgentCollection;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Current server origin used to build and recognize local agent URLs.
|
|
60
|
+
*/
|
|
61
|
+
readonly localServerUrl: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One local agent source participating in an inheritance-chain walk.
|
|
66
|
+
*
|
|
67
|
+
* @private utility of Agents Server inheritance diagnostics
|
|
68
|
+
*/
|
|
69
|
+
type LocalInheritanceNode = {
|
|
70
|
+
/**
|
|
71
|
+
* Editable source before `FROM` materialization.
|
|
72
|
+
*/
|
|
73
|
+
readonly agentSource: string_book;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Canonical local route used to identify the node in the chain.
|
|
77
|
+
*/
|
|
78
|
+
readonly canonicalAgentUrl: string_agent_url;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Friendly title displayed in a cycle warning.
|
|
82
|
+
*/
|
|
83
|
+
readonly title: string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Resolver scoped to embedded agents declared by this Book.
|
|
87
|
+
*/
|
|
88
|
+
readonly agentReferenceResolver: AgentReferenceResolver;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Last explicit parent declaration, when the Book has one.
|
|
92
|
+
*/
|
|
93
|
+
readonly effectiveFromCommitment: ExplicitFromCommitment | undefined;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether this source is the server's root Adam agent.
|
|
97
|
+
*/
|
|
98
|
+
readonly isAdamAgent: boolean;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates Book editor warnings for a circular local inheritance chain and for an Adam source that is not rooted in
|
|
103
|
+
* `Null`/`Void`.
|
|
104
|
+
*
|
|
105
|
+
* The runtime remains the authority that materializes local and federated sources. This intentionally lightweight
|
|
106
|
+
* graph walk only follows local `FROM` links, which is enough to point an author at the exact Book line before a
|
|
107
|
+
* cycle can make runtime resolution fail.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Current editable source and local-server dependencies.
|
|
110
|
+
* @returns Warning markers suitable for the Book editor.
|
|
111
|
+
*
|
|
112
|
+
* @private utility of Agents Server Book editor diagnostics
|
|
113
|
+
*/
|
|
114
|
+
export async function createAgentInheritanceDiagnostics(
|
|
115
|
+
options: CreateAgentInheritanceDiagnosticsOptions,
|
|
116
|
+
): Promise<Array<AgentReferenceDiagnostic>> {
|
|
117
|
+
const { agentSource, agentPermanentId, collection, localServerUrl } = options;
|
|
118
|
+
const normalizedLocalServerUrl = localServerUrl.replace(/\/+$/g, '');
|
|
119
|
+
const baseAgentReferenceResolver = await createServerAgentReferenceResolver({
|
|
120
|
+
agentCollection: collection,
|
|
121
|
+
localServerUrl: normalizedLocalServerUrl,
|
|
122
|
+
});
|
|
123
|
+
const adamCanonicalAgentUrl = await resolveAdamCanonicalAgentUrl(collection, normalizedLocalServerUrl);
|
|
124
|
+
const rootNode = createRootInheritanceNode({
|
|
125
|
+
agentSource,
|
|
126
|
+
agentPermanentId,
|
|
127
|
+
localServerUrl: normalizedLocalServerUrl,
|
|
128
|
+
adamCanonicalAgentUrl,
|
|
129
|
+
baseAgentReferenceResolver,
|
|
130
|
+
});
|
|
131
|
+
const adamDiagnostics = createAdamRootDiagnostics(rootNode);
|
|
132
|
+
const cycleDiagnostic = await createCycleDiagnostic({
|
|
133
|
+
rootNode,
|
|
134
|
+
collection,
|
|
135
|
+
localServerUrl: normalizedLocalServerUrl,
|
|
136
|
+
adamCanonicalAgentUrl,
|
|
137
|
+
baseAgentReferenceResolver,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return cycleDiagnostic ? [...adamDiagnostics, cycleDiagnostic] : adamDiagnostics;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Resolves Adam's canonical current route from its well-known name.
|
|
145
|
+
*
|
|
146
|
+
* @param collection - Collection containing local core agents.
|
|
147
|
+
* @param localServerUrl - Current server origin.
|
|
148
|
+
* @returns Canonical Adam route or `null` when the core agent is missing.
|
|
149
|
+
*
|
|
150
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
151
|
+
*/
|
|
152
|
+
async function resolveAdamCanonicalAgentUrl(
|
|
153
|
+
collection: Pick<AgentCollection, 'getAgentPermanentId'>,
|
|
154
|
+
localServerUrl: string,
|
|
155
|
+
): Promise<string_agent_url | null> {
|
|
156
|
+
try {
|
|
157
|
+
const adamPermanentId = await collection.getAgentPermanentId(CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES.ADAM);
|
|
158
|
+
return createLocalAgentUrl(localServerUrl, adamPermanentId);
|
|
159
|
+
} catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates the first graph node from the source currently being edited rather than its last saved database version.
|
|
166
|
+
*
|
|
167
|
+
* @param options - Current source and dependencies shared by the diagnostics pass.
|
|
168
|
+
* @returns Root node of the local inheritance walk.
|
|
169
|
+
*
|
|
170
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
171
|
+
*/
|
|
172
|
+
function createRootInheritanceNode(options: {
|
|
173
|
+
readonly agentSource: string_book;
|
|
174
|
+
readonly agentPermanentId: string_agent_permanent_id;
|
|
175
|
+
readonly localServerUrl: string;
|
|
176
|
+
readonly adamCanonicalAgentUrl: string_agent_url | null;
|
|
177
|
+
readonly baseAgentReferenceResolver: AgentReferenceResolver;
|
|
178
|
+
}): LocalInheritanceNode {
|
|
179
|
+
const { agentSource, agentPermanentId, localServerUrl, adamCanonicalAgentUrl, baseAgentReferenceResolver } =
|
|
180
|
+
options;
|
|
181
|
+
const canonicalAgentUrl = createLocalAgentUrl(localServerUrl, agentPermanentId);
|
|
182
|
+
const title = readAgentSourceTitle(agentSource, agentPermanentId);
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
agentSource,
|
|
186
|
+
canonicalAgentUrl,
|
|
187
|
+
title,
|
|
188
|
+
agentReferenceResolver: createBookScopedAgentReferenceResolver({
|
|
189
|
+
parentAgentSource: agentSource,
|
|
190
|
+
parentAgentIdentifier: agentPermanentId,
|
|
191
|
+
localServerUrl,
|
|
192
|
+
fallbackResolver: baseAgentReferenceResolver,
|
|
193
|
+
}),
|
|
194
|
+
effectiveFromCommitment: getEffectiveExplicitFromCommitment(agentSource),
|
|
195
|
+
isAdamAgent:
|
|
196
|
+
canonicalAgentUrl === adamCanonicalAgentUrl ||
|
|
197
|
+
title.trim().toLowerCase() === CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES.ADAM,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Creates the Adam-specific warning when the root agent does not explicitly inherit from `Null`/`Void`.
|
|
203
|
+
*
|
|
204
|
+
* @param node - Root node being edited.
|
|
205
|
+
* @returns One warning for invalid Adam ancestry, otherwise an empty list.
|
|
206
|
+
*
|
|
207
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
208
|
+
*/
|
|
209
|
+
function createAdamRootDiagnostics(node: LocalInheritanceNode): Array<AgentReferenceDiagnostic> {
|
|
210
|
+
if (node.isAdamAgent && !isExplicitNoParentCommitment(node.effectiveFromCommitment)) {
|
|
211
|
+
return [
|
|
212
|
+
createInheritanceMarker(
|
|
213
|
+
node.agentSource,
|
|
214
|
+
node.effectiveFromCommitment,
|
|
215
|
+
'The core `Adam` agent must explicitly use `FROM @Null` (or the equivalent `FROM @Void`) so it remains the root of the inheritance chain.',
|
|
216
|
+
),
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Checks whether an effective `FROM` commitment explicitly opts out of inheritance.
|
|
225
|
+
*
|
|
226
|
+
* @param fromCommitment - Effective parent declaration, if present.
|
|
227
|
+
* @returns True only for an explicit `Null`/`Void` parent.
|
|
228
|
+
*
|
|
229
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
230
|
+
*/
|
|
231
|
+
function isExplicitNoParentCommitment(fromCommitment: ExplicitFromCommitment | undefined): boolean {
|
|
232
|
+
return Boolean(fromCommitment && isVoidPseudoAgentReference(fromCommitment.content));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Walks the local parent chain and creates one warning when it reaches a previously visited agent.
|
|
237
|
+
*
|
|
238
|
+
* @param options - Root node and dependencies shared by the graph walk.
|
|
239
|
+
* @returns Cycle warning marker or `null` when the chain is safe or leaves the local server.
|
|
240
|
+
*
|
|
241
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
242
|
+
*/
|
|
243
|
+
async function createCycleDiagnostic(options: {
|
|
244
|
+
readonly rootNode: LocalInheritanceNode;
|
|
245
|
+
readonly collection: AgentCollection;
|
|
246
|
+
readonly localServerUrl: string;
|
|
247
|
+
readonly adamCanonicalAgentUrl: string_agent_url | null;
|
|
248
|
+
readonly baseAgentReferenceResolver: AgentReferenceResolver;
|
|
249
|
+
}): Promise<AgentReferenceDiagnostic | null> {
|
|
250
|
+
const { rootNode } = options;
|
|
251
|
+
const inheritancePath: Array<LocalInheritanceNode> = [rootNode];
|
|
252
|
+
let currentNode = rootNode;
|
|
253
|
+
|
|
254
|
+
for (let depth = 0; depth < MAX_LOCAL_INHERITANCE_DIAGNOSTIC_DEPTH; depth++) {
|
|
255
|
+
const parentNode = await resolveLocalParentNode(currentNode, options);
|
|
256
|
+
if (!parentNode) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const cycleStartIndex = inheritancePath.findIndex(
|
|
261
|
+
(pathNode) => pathNode.canonicalAgentUrl === parentNode.canonicalAgentUrl,
|
|
262
|
+
);
|
|
263
|
+
if (cycleStartIndex !== -1) {
|
|
264
|
+
const cycleTitles = [...inheritancePath.slice(cycleStartIndex), parentNode]
|
|
265
|
+
.map((cycleNode) => `\`${cycleNode.title}\``)
|
|
266
|
+
.join(' → ');
|
|
267
|
+
|
|
268
|
+
return createInheritanceMarker(
|
|
269
|
+
rootNode.agentSource,
|
|
270
|
+
rootNode.effectiveFromCommitment,
|
|
271
|
+
`Cyclic \`FROM\` inheritance detected: ${cycleTitles}. Change one of these parent references to break the cycle.`,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
inheritancePath.push(parentNode);
|
|
276
|
+
currentNode = parentNode;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Resolves one node's effective local parent, or returns `null` for explicit no-parent, missing, or remote parents.
|
|
284
|
+
*
|
|
285
|
+
* @param node - Node whose parent should be followed.
|
|
286
|
+
* @param options - Shared local resolution dependencies.
|
|
287
|
+
* @returns The next local node, or `null` when the diagnostic walk should stop.
|
|
288
|
+
*
|
|
289
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
290
|
+
*/
|
|
291
|
+
async function resolveLocalParentNode(
|
|
292
|
+
node: LocalInheritanceNode,
|
|
293
|
+
options: {
|
|
294
|
+
readonly collection: AgentCollection;
|
|
295
|
+
readonly localServerUrl: string;
|
|
296
|
+
readonly adamCanonicalAgentUrl: string_agent_url | null;
|
|
297
|
+
readonly baseAgentReferenceResolver: AgentReferenceResolver;
|
|
298
|
+
},
|
|
299
|
+
): Promise<LocalInheritanceNode | null> {
|
|
300
|
+
const { effectiveFromCommitment } = node;
|
|
301
|
+
|
|
302
|
+
if (!effectiveFromCommitment) {
|
|
303
|
+
if (node.isAdamAgent) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const adamAgentUrl = createLocalAgentUrl(
|
|
308
|
+
options.localServerUrl,
|
|
309
|
+
CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES.ADAM,
|
|
310
|
+
);
|
|
311
|
+
return loadLocalInheritanceNode(adamAgentUrl, options);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!effectiveFromCommitment.content || isVoidPseudoAgentReference(effectiveFromCommitment.content)) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let resolvedParentReference: string;
|
|
319
|
+
try {
|
|
320
|
+
resolvedParentReference = await node.agentReferenceResolver.resolveCommitmentContent(
|
|
321
|
+
'FROM',
|
|
322
|
+
effectiveFromCommitment.content,
|
|
323
|
+
);
|
|
324
|
+
} catch {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (!resolvedParentReference || isVoidPseudoAgentReference(resolvedParentReference)) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!isValidAgentUrl(resolvedParentReference)) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return loadLocalInheritanceNode(resolvedParentReference as string_agent_url, options);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Loads one local parent node through the same book-scoped context used by the regular runtime resolver.
|
|
341
|
+
*
|
|
342
|
+
* @param parentAgentUrl - Resolved parent URL to inspect.
|
|
343
|
+
* @param options - Shared local resolution dependencies.
|
|
344
|
+
* @returns Loaded local node, or `null` for a remote/unavailable parent.
|
|
345
|
+
*
|
|
346
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
347
|
+
*/
|
|
348
|
+
async function loadLocalInheritanceNode(
|
|
349
|
+
parentAgentUrl: string_agent_url,
|
|
350
|
+
options: {
|
|
351
|
+
readonly collection: AgentCollection;
|
|
352
|
+
readonly localServerUrl: string;
|
|
353
|
+
readonly adamCanonicalAgentUrl: string_agent_url | null;
|
|
354
|
+
readonly baseAgentReferenceResolver: AgentReferenceResolver;
|
|
355
|
+
},
|
|
356
|
+
): Promise<LocalInheritanceNode | null> {
|
|
357
|
+
const localRouteReference = resolveLocalAgentRouteReference(
|
|
358
|
+
parentAgentUrl,
|
|
359
|
+
normalizeLocalServerUrls([options.localServerUrl]),
|
|
360
|
+
[],
|
|
361
|
+
);
|
|
362
|
+
if (!localRouteReference) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
try {
|
|
367
|
+
const resolvedAgentContext = await resolveBookScopedAgentContext({
|
|
368
|
+
collection: options.collection,
|
|
369
|
+
agentIdentifier: localRouteReference.agentIdentifier,
|
|
370
|
+
localServerUrl: options.localServerUrl,
|
|
371
|
+
fallbackResolver: options.baseAgentReferenceResolver,
|
|
372
|
+
});
|
|
373
|
+
const title = readAgentSourceTitle(
|
|
374
|
+
resolvedAgentContext.unresolvedAgentSource,
|
|
375
|
+
resolvedAgentContext.resolvedAgentName,
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
return {
|
|
379
|
+
agentSource: resolvedAgentContext.unresolvedAgentSource,
|
|
380
|
+
canonicalAgentUrl: resolvedAgentContext.canonicalAgentUrl,
|
|
381
|
+
title,
|
|
382
|
+
agentReferenceResolver: resolvedAgentContext.scopedAgentReferenceResolver,
|
|
383
|
+
effectiveFromCommitment: getEffectiveExplicitFromCommitment(resolvedAgentContext.unresolvedAgentSource),
|
|
384
|
+
isAdamAgent:
|
|
385
|
+
resolvedAgentContext.canonicalAgentUrl === options.adamCanonicalAgentUrl ||
|
|
386
|
+
title.trim().toLowerCase() === CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES.ADAM,
|
|
387
|
+
};
|
|
388
|
+
} catch {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Reads a Book's visible title for friendly diagnostics, with a stable fallback for incomplete editor content.
|
|
395
|
+
*
|
|
396
|
+
* @param agentSource - Source to inspect.
|
|
397
|
+
* @param fallbackTitle - Stable fallback when the source has no title yet.
|
|
398
|
+
* @returns First non-empty source line or the fallback title.
|
|
399
|
+
*
|
|
400
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
401
|
+
*/
|
|
402
|
+
function readAgentSourceTitle(agentSource: string_book, fallbackTitle: string): string {
|
|
403
|
+
for (const line of agentSource.split(/\r?\n/)) {
|
|
404
|
+
const title = line.trim();
|
|
405
|
+
if (title) {
|
|
406
|
+
return title;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return fallbackTitle;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Creates a warning marker on the effective `FROM` keyword, or on the title when inheritance is implicit.
|
|
415
|
+
*
|
|
416
|
+
* @param agentSource - Source whose marker should be displayed.
|
|
417
|
+
* @param fromCommitment - Effective explicit `FROM`, if one exists.
|
|
418
|
+
* @param message - Human-readable warning shown by Monaco.
|
|
419
|
+
* @returns Monaco-compatible warning marker.
|
|
420
|
+
*
|
|
421
|
+
* @private utility of `createAgentInheritanceDiagnostics`
|
|
422
|
+
*/
|
|
423
|
+
function createInheritanceMarker(
|
|
424
|
+
agentSource: string_book,
|
|
425
|
+
fromCommitment: ExplicitFromCommitment | undefined,
|
|
426
|
+
message: string,
|
|
427
|
+
): AgentReferenceDiagnostic {
|
|
428
|
+
const sourceLines = agentSource.split(/\r?\n/);
|
|
429
|
+
|
|
430
|
+
if (fromCommitment) {
|
|
431
|
+
const sourceLine = sourceLines[fromCommitment.lineIndex] || '';
|
|
432
|
+
const keywordIndex = Math.max(0, sourceLine.indexOf('FROM'));
|
|
433
|
+
|
|
434
|
+
return {
|
|
435
|
+
startLineNumber: fromCommitment.lineIndex + 1,
|
|
436
|
+
startColumn: keywordIndex + 1,
|
|
437
|
+
endLineNumber: fromCommitment.lineIndex + 1,
|
|
438
|
+
endColumn: keywordIndex + 'FROM'.length + 1,
|
|
439
|
+
message,
|
|
440
|
+
source: AGENT_INHERITANCE_DIAGNOSTIC_SOURCE,
|
|
441
|
+
severity: 'warning',
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const titleLineIndex = sourceLines.findIndex((sourceLine) => sourceLine.trim().length > 0);
|
|
446
|
+
const sourceLine = sourceLines[titleLineIndex] || '';
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
startLineNumber: Math.max(0, titleLineIndex) + 1,
|
|
450
|
+
startColumn: 1,
|
|
451
|
+
endLineNumber: Math.max(0, titleLineIndex) + 1,
|
|
452
|
+
endColumn: Math.max(2, sourceLine.length + 1),
|
|
453
|
+
message,
|
|
454
|
+
source: AGENT_INHERITANCE_DIAGNOSTIC_SOURCE,
|
|
455
|
+
severity: 'warning',
|
|
456
|
+
};
|
|
457
|
+
}
|
|
@@ -5,6 +5,8 @@ import type { BookCommitment } from '../../../../../src/commitments/_base/BookCo
|
|
|
5
5
|
import type { ParsedCommitment } from '../../../../../src/commitments/_base/ParsedCommitment';
|
|
6
6
|
import { consumeAgentReferenceResolutionIssues } from './AgentReferenceResolutionIssue';
|
|
7
7
|
import { extractAgentReferenceTokens } from './extractAgentReferenceTokens';
|
|
8
|
+
import type { MissingCoreAgentRecovery } from './MissingCoreAgentRecovery';
|
|
9
|
+
import { getEffectiveExplicitFromCommitment } from '../explicitFromCommitment';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Monaco-compatible diagnostic payload for unresolved compact agent references.
|
|
@@ -39,6 +41,11 @@ export type AgentReferenceDiagnostic = {
|
|
|
39
41
|
* Optional source label shown by Monaco.
|
|
40
42
|
*/
|
|
41
43
|
readonly source?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Optional marker severity. Missing references use Monaco's default error severity.
|
|
47
|
+
*/
|
|
48
|
+
readonly severity?: 'error' | 'warning' | 'info' | 'hint';
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -48,6 +55,19 @@ export type MissingAgentReference = {
|
|
|
48
55
|
readonly reference: string;
|
|
49
56
|
readonly token: string;
|
|
50
57
|
readonly commitmentType: BookCommitment;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether the reference is implied by the Book language itself instead of being written in the book.
|
|
61
|
+
*
|
|
62
|
+
* A book without any `FROM` commitment implicitly inherits from `@Adam`, so a missing Adam has to be reported
|
|
63
|
+
* even though no token points at it.
|
|
64
|
+
*/
|
|
65
|
+
readonly isImplicit?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Reinstatement offered when the missing reference points to one of the bundled core agents.
|
|
69
|
+
*/
|
|
70
|
+
readonly coreAgentRecovery?: MissingCoreAgentRecovery;
|
|
51
71
|
};
|
|
52
72
|
|
|
53
73
|
/**
|
|
@@ -186,6 +206,7 @@ export async function createUnresolvedAgentReferenceDiagnostics(
|
|
|
186
206
|
function collectAgentReferenceTokenLocations(agentSource: string_book): Array<AgentReferenceTokenLocation> {
|
|
187
207
|
const parsed = parseAgentSourceWithCommitments(agentSource);
|
|
188
208
|
const sourceLines = agentSource.split(/\r?\n/);
|
|
209
|
+
const effectiveFromCommitment = getEffectiveExplicitFromCommitment(agentSource);
|
|
189
210
|
const tokenLocations: Array<AgentReferenceTokenLocation> = [];
|
|
190
211
|
|
|
191
212
|
for (let commitmentIndex = 0; commitmentIndex < parsed.commitments.length; commitmentIndex++) {
|
|
@@ -194,6 +215,12 @@ function collectAgentReferenceTokenLocations(agentSource: string_book): Array<Ag
|
|
|
194
215
|
continue;
|
|
195
216
|
}
|
|
196
217
|
|
|
218
|
+
// A parent is singular: only the final FROM participates in resolution, so diagnostics must not report an
|
|
219
|
+
// overridden reference as missing. The Book editor separately marks every duplicate FROM with an explanation.
|
|
220
|
+
if (commitment.type === 'FROM' && effectiveFromCommitment?.lineIndex !== commitment.lineNumber - 1) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
|
|
197
224
|
const startLineNumber = commitment.lineNumber;
|
|
198
225
|
const nextCommitmentStartLine = parsed.commitments[commitmentIndex + 1]?.lineNumber ?? sourceLines.length + 1;
|
|
199
226
|
const endLineNumber = resolveCommitmentEndLine(sourceLines, startLineNumber, nextCommitmentStartLine - 1);
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES } from '../../../../../servers';
|
|
2
|
+
import { normalizeAgentName } from '../../../../../src/book-2.0/agent-source/normalizeAgentName';
|
|
3
|
+
import type { string_book } from '../../../../../src/book-2.0/agent-source/string_book';
|
|
4
|
+
import { resolveDefaultAgentsStatus, type CoreAgentReport } from '../defaultAgents/resolveDefaultAgentsStatus';
|
|
5
|
+
import { isImplicitAdamInheritance } from '../explicitFromCommitment';
|
|
6
|
+
import type { MissingAgentReference } from './createUnresolvedAgentReferenceDiagnostics';
|
|
7
|
+
import type { MissingCoreAgentRecovery } from './MissingCoreAgentRecovery';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Dependencies needed to enrich unresolved references with bundled-core-agent recovery.
|
|
11
|
+
*
|
|
12
|
+
* @private utility of Agents Server agent-reference diagnostics
|
|
13
|
+
*/
|
|
14
|
+
export type ResolveCoreAgentAwareMissingReferencesOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Agent source currently edited in the Book editor.
|
|
17
|
+
*/
|
|
18
|
+
readonly agentSource: string_book;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Unresolved compact references already detected in `agentSource`.
|
|
22
|
+
*/
|
|
23
|
+
readonly missingAgentReferences: ReadonlyArray<MissingAgentReference>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether the current user is allowed to reinstate the missing core agents.
|
|
27
|
+
*/
|
|
28
|
+
readonly isReinstateAllowed: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extends unresolved compact references of one book with bundled-core-agent recovery.
|
|
33
|
+
*
|
|
34
|
+
* Two things are added here:
|
|
35
|
+
*
|
|
36
|
+
* 1. A reference naming a bundled core agent is marked as recoverable, because such an agent should be reinstated
|
|
37
|
+
* from its bundled book instead of being created empty from scratch.
|
|
38
|
+
* 2. A book without any explicit `FROM` implicitly inherits from `@Adam`, so a missing Adam is reported right away
|
|
39
|
+
* even though no token in the book points at it.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Current book, already-detected missing references, and the reinstate permission.
|
|
42
|
+
* @returns Missing references carrying core-agent recovery, with the implicit `@Adam` ancestor first when missing.
|
|
43
|
+
*
|
|
44
|
+
* @private utility of Agents Server agent-reference diagnostics
|
|
45
|
+
*/
|
|
46
|
+
export async function resolveCoreAgentAwareMissingReferences(
|
|
47
|
+
options: ResolveCoreAgentAwareMissingReferencesOptions,
|
|
48
|
+
): Promise<ReadonlyArray<MissingAgentReference>> {
|
|
49
|
+
const { agentSource, missingAgentReferences, isReinstateAllowed } = options;
|
|
50
|
+
const isAdamImplicitlyInherited = isImplicitAdamInheritance(agentSource);
|
|
51
|
+
|
|
52
|
+
if (!isAdamImplicitlyInherited && missingAgentReferences.length === 0) {
|
|
53
|
+
return missingAgentReferences;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const missingCoreAgents = await resolveMissingCoreAgents();
|
|
57
|
+
|
|
58
|
+
if (missingCoreAgents.length === 0) {
|
|
59
|
+
return missingAgentReferences;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const coreAgentRecovery: MissingCoreAgentRecovery = {
|
|
63
|
+
missingCoreAgentTitles: missingCoreAgents.map((missingCoreAgent) => missingCoreAgent.title),
|
|
64
|
+
isReinstateAllowed,
|
|
65
|
+
};
|
|
66
|
+
const recoverableMissingAgentReferences = missingAgentReferences.map((missingAgentReference) =>
|
|
67
|
+
findMissingCoreAgent(missingCoreAgents, missingAgentReference.reference)
|
|
68
|
+
? { ...missingAgentReference, coreAgentRecovery }
|
|
69
|
+
: missingAgentReference,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!isAdamImplicitlyInherited) {
|
|
73
|
+
return recoverableMissingAgentReferences;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const missingAdamAgent = findMissingCoreAgent(missingCoreAgents, CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES.ADAM);
|
|
77
|
+
|
|
78
|
+
if (!missingAdamAgent || hasMissingAgentReferenceFor(recoverableMissingAgentReferences, missingAdamAgent)) {
|
|
79
|
+
return recoverableMissingAgentReferences;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return [
|
|
83
|
+
createImplicitAdamMissingReference(missingAdamAgent, coreAgentRecovery),
|
|
84
|
+
...recoverableMissingAgentReferences,
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Resolves which bundled core agents are absent from the current server.
|
|
90
|
+
*
|
|
91
|
+
* Presence comes from the same status the Core Agents admin page renders, so the panel linking to that page can never
|
|
92
|
+
* disagree with it. Implicit inheritance always loads Adam from this very server, so a federated namesake elsewhere
|
|
93
|
+
* must not count as present.
|
|
94
|
+
*
|
|
95
|
+
* @returns Reports of the bundled core agents that are missing, in bundled order.
|
|
96
|
+
*/
|
|
97
|
+
async function resolveMissingCoreAgents(): Promise<ReadonlyArray<CoreAgentReport>> {
|
|
98
|
+
try {
|
|
99
|
+
const { coreAgents } = await resolveDefaultAgentsStatus();
|
|
100
|
+
return coreAgents.filter((coreAgent) => !coreAgent.isPresent);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn('[AgentReferenceResolver] Failed to resolve the bundled core agent status:', error);
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Finds the missing bundled core agent one reference points to.
|
|
109
|
+
*
|
|
110
|
+
* @param missingCoreAgents - Bundled core agents currently missing on this server.
|
|
111
|
+
* @param reference - Raw reference payload, for example `Adam` or `adam`.
|
|
112
|
+
* @returns Matching missing core agent, or `undefined` when the reference names something else.
|
|
113
|
+
*/
|
|
114
|
+
function findMissingCoreAgent(
|
|
115
|
+
missingCoreAgents: ReadonlyArray<CoreAgentReport>,
|
|
116
|
+
reference: string,
|
|
117
|
+
): CoreAgentReport | undefined {
|
|
118
|
+
const normalizedReference = normalizeAgentName(reference);
|
|
119
|
+
return missingCoreAgents.find((missingCoreAgent) => missingCoreAgent.agentName === normalizedReference);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Checks whether one missing core agent is already reported by an explicit reference written in the book.
|
|
124
|
+
*
|
|
125
|
+
* @param missingAgentReferences - Missing references detected in the book.
|
|
126
|
+
* @param missingCoreAgent - Missing core agent to look for.
|
|
127
|
+
* @returns True when the book already shows a card for that agent.
|
|
128
|
+
*/
|
|
129
|
+
function hasMissingAgentReferenceFor(
|
|
130
|
+
missingAgentReferences: ReadonlyArray<MissingAgentReference>,
|
|
131
|
+
missingCoreAgent: CoreAgentReport,
|
|
132
|
+
): boolean {
|
|
133
|
+
return missingAgentReferences.some(
|
|
134
|
+
(missingAgentReference) => normalizeAgentName(missingAgentReference.reference) === missingCoreAgent.agentName,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates the missing-reference entry standing for the implicit `FROM @Adam` ancestor.
|
|
140
|
+
*
|
|
141
|
+
* @param missingAdamAgent - Report of the missing Adam core agent.
|
|
142
|
+
* @param coreAgentRecovery - Reinstatement offered for the missing core agents.
|
|
143
|
+
* @returns Missing reference shown exactly like an explicitly referenced agent that was not found.
|
|
144
|
+
*/
|
|
145
|
+
function createImplicitAdamMissingReference(
|
|
146
|
+
missingAdamAgent: CoreAgentReport,
|
|
147
|
+
coreAgentRecovery: MissingCoreAgentRecovery,
|
|
148
|
+
): MissingAgentReference {
|
|
149
|
+
return {
|
|
150
|
+
reference: missingAdamAgent.title,
|
|
151
|
+
token: `{${missingAdamAgent.title}}`,
|
|
152
|
+
commitmentType: 'FROM',
|
|
153
|
+
isImplicit: true,
|
|
154
|
+
coreAgentRecovery,
|
|
155
|
+
};
|
|
156
|
+
}
|