@downcity/agent 1.1.437 → 1.1.445
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -18
- package/bin/agent/Agent.d.ts +44 -20
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +114 -69
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentInstructions.d.ts +18 -4
- package/bin/agent/AgentInstructions.d.ts.map +1 -1
- package/bin/agent/AgentInstructions.js +33 -14
- package/bin/agent/AgentInstructions.js.map +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
- package/bin/agent/AgentMemoryStorage.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +29 -16
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +42 -22
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/group/Group.d.ts +13 -12
- package/bin/group/Group.d.ts.map +1 -1
- package/bin/group/Group.js +24 -23
- package/bin/group/Group.js.map +1 -1
- package/bin/group/GroupSession.d.ts.map +1 -1
- package/bin/group/GroupSession.js +13 -9
- package/bin/group/GroupSession.js.map +1 -1
- package/bin/group/GroupSessions.d.ts +27 -2
- package/bin/group/GroupSessions.d.ts.map +1 -1
- package/bin/group/GroupSessions.js +68 -21
- package/bin/group/GroupSessions.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts +8 -0
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.d.ts +64 -5
- package/bin/group/storage/LocalGroupSessionStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.js +114 -23
- package/bin/group/storage/LocalGroupSessionStore.js.map +1 -1
- package/bin/index.d.ts +25 -30
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +14 -14
- package/bin/index.js.map +1 -1
- package/bin/{executor/model → model}/ModelGenerate.d.ts +1 -1
- package/bin/model/ModelGenerate.d.ts.map +1 -0
- package/bin/model/ModelGenerate.js.map +1 -0
- package/bin/{executor/model → model}/ModelRequestRunner.d.ts +1 -1
- package/bin/model/ModelRequestRunner.d.ts.map +1 -0
- package/bin/model/ModelRequestRunner.js.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.d.ts +6 -7
- package/bin/model/ModelStepRunner.d.ts.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.js +16 -10
- package/bin/model/ModelStepRunner.js.map +1 -0
- package/bin/model/ModelStreamConsumer.d.ts.map +1 -0
- package/bin/model/ModelStreamConsumer.js.map +1 -0
- package/bin/model/ModelStreamFailure.d.ts.map +1 -0
- package/bin/model/ModelStreamFailure.js.map +1 -0
- package/bin/model/ToolInputValidation.d.ts +28 -0
- package/bin/model/ToolInputValidation.d.ts.map +1 -0
- package/bin/model/ToolInputValidation.js +37 -0
- package/bin/model/ToolInputValidation.js.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.d.ts.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.js.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.d.ts.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.js.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.d.ts.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.js.map +1 -0
- package/bin/model/messages/SessionMessageLog.d.ts.map +1 -0
- package/bin/model/messages/SessionMessageLog.js.map +1 -0
- package/bin/model/messages/SessionModelMessages.d.ts.map +1 -0
- package/bin/{executor → model}/messages/SessionModelMessages.js +0 -1
- package/bin/model/messages/SessionModelMessages.js.map +1 -0
- package/bin/model/prompts/SystemPromptAssets.d.ts.map +1 -0
- package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.js +1 -1
- package/bin/model/prompts/SystemPromptAssets.js.map +1 -0
- package/bin/model/prompts/assets/core.prompt.d.ts +7 -0
- package/bin/model/prompts/assets/core.prompt.d.ts.map +1 -0
- package/bin/model/prompts/assets/core.prompt.js +8 -0
- package/bin/model/prompts/assets/core.prompt.js.map +1 -0
- package/bin/session/Session.d.ts +29 -17
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +161 -134
- package/bin/session/Session.js.map +1 -1
- package/bin/session/input/SessionHookRunner.d.ts +52 -0
- package/bin/session/input/SessionHookRunner.d.ts.map +1 -0
- package/bin/session/input/SessionHookRunner.js +51 -0
- package/bin/session/input/SessionHookRunner.js.map +1 -0
- package/bin/session/input/SessionSystem.d.ts +26 -0
- package/bin/session/input/SessionSystem.d.ts.map +1 -0
- package/bin/session/{SessionSystem.js → input/SessionSystem.js} +27 -23
- package/bin/session/input/SessionSystem.js.map +1 -0
- package/bin/session/input/StepInput.d.ts +77 -0
- package/bin/session/input/StepInput.d.ts.map +1 -0
- package/bin/session/input/StepInput.js +429 -0
- package/bin/session/input/StepInput.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts +33 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js +83 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts +26 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.js +124 -0
- package/bin/session/input/composer/AdaptiveContextParts.js.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts +21 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.js +64 -0
- package/bin/session/input/composer/ComposerAssembly.js.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.d.ts → input/composer/ContextSummaryPrompts.d.ts} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.d.ts.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.js → input/composer/ContextSummaryPrompts.js} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.js.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts +24 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.js +108 -0
- package/bin/session/input/composer/DefaultSessionComposer.js.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts +19 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js +36 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js.map +1 -0
- package/bin/session/{SessionLoop.d.ts → loop/SessionLoop.d.ts} +34 -7
- package/bin/session/loop/SessionLoop.d.ts.map +1 -0
- package/bin/session/{SessionLoop.js → loop/SessionLoop.js} +79 -16
- package/bin/session/loop/SessionLoop.js.map +1 -0
- package/bin/session/{SessionQueue.d.ts → loop/SessionQueue.d.ts} +9 -1
- package/bin/session/loop/SessionQueue.d.ts.map +1 -0
- package/bin/session/{SessionQueue.js → loop/SessionQueue.js} +19 -0
- package/bin/session/loop/SessionQueue.js.map +1 -0
- package/bin/session/{SessionState.d.ts → loop/SessionState.d.ts} +4 -5
- package/bin/session/loop/SessionState.d.ts.map +1 -0
- package/bin/session/{SessionState.js → loop/SessionState.js} +6 -25
- package/bin/session/loop/SessionState.js.map +1 -0
- package/bin/session/{SessionTitle.d.ts → loop/SessionTitle.d.ts} +4 -4
- package/bin/session/loop/SessionTitle.d.ts.map +1 -0
- package/bin/session/{SessionTitle.js → loop/SessionTitle.js} +3 -3
- package/bin/session/loop/SessionTitle.js.map +1 -0
- package/bin/session/loop/SessionTitleTask.d.ts.map +1 -0
- package/bin/session/loop/SessionTitleTask.js.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.d.ts +7 -0
- package/bin/session/loop/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.js +25 -6
- package/bin/session/loop/SessionTurnCompletion.js.map +1 -0
- package/bin/session/loop/SessionTurnContext.d.ts +12 -0
- package/bin/session/loop/SessionTurnContext.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnContext.js +14 -67
- package/bin/session/loop/SessionTurnContext.js.map +1 -0
- package/bin/session/loop/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnFileDiff.js +1 -1
- package/bin/session/loop/SessionTurnFileDiff.js.map +1 -0
- package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.d.ts +3 -3
- package/bin/session/loop/SessionTurnFileDiffBuilder.d.ts.map +1 -0
- package/bin/session/loop/SessionTurnFileDiffBuilder.js.map +1 -0
- package/bin/session/messages/ApprovalInteraction.d.ts +30 -0
- package/bin/session/messages/ApprovalInteraction.d.ts.map +1 -0
- package/bin/session/messages/ApprovalInteraction.js +61 -0
- package/bin/session/messages/ApprovalInteraction.js.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts +47 -18
- package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageState.js +224 -86
- package/bin/session/messages/SessionAgentMessageState.js.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.d.ts +15 -4
- package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.js +57 -37
- package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -1
- package/bin/session/messages/SessionAgentParts.d.ts +14 -0
- package/bin/session/messages/SessionAgentParts.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentParts.js +20 -0
- package/bin/session/messages/SessionAgentParts.js.map +1 -0
- package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.d.ts +2 -2
- package/bin/session/messages/SessionAssistantOutputAdapter.d.ts.map +1 -0
- package/bin/session/messages/SessionAssistantOutputAdapter.js.map +1 -0
- package/bin/session/messages/SessionEventHub.d.ts.map +1 -0
- package/bin/session/messages/SessionEventHub.js.map +1 -0
- package/bin/session/messages/SessionInteractions.d.ts +57 -0
- package/bin/session/messages/SessionInteractions.d.ts.map +1 -0
- package/bin/session/messages/SessionInteractions.js +178 -0
- package/bin/session/messages/SessionInteractions.js.map +1 -0
- package/bin/session/messages/SessionJsonValue.d.ts +1 -3
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
- package/bin/session/messages/SessionJsonValue.js +0 -19
- package/bin/session/messages/SessionJsonValue.js.map +1 -1
- package/bin/session/messages/SessionMessageCache.d.ts +55 -0
- package/bin/session/messages/SessionMessageCache.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageCache.js +133 -0
- package/bin/session/messages/SessionMessageCache.js.map +1 -0
- package/bin/session/messages/SessionMessageState.d.ts +17 -0
- package/bin/session/messages/SessionMessageState.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageState.js +34 -0
- package/bin/session/messages/SessionMessageState.js.map +1 -0
- package/bin/session/messages/SessionMessageTimeline.d.ts.map +1 -0
- package/bin/session/{browse → messages}/SessionMessageTimeline.js +0 -1
- package/bin/session/messages/SessionMessageTimeline.js.map +1 -0
- package/bin/session/{SessionMessages.d.ts → messages/SessionMessages.d.ts} +35 -43
- package/bin/session/messages/SessionMessages.d.ts.map +1 -0
- package/bin/session/{SessionMessages.js → messages/SessionMessages.js} +178 -196
- package/bin/session/messages/SessionMessages.js.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.d.ts.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.js.map +1 -0
- package/bin/session/messages/SessionMutationFactory.d.ts +26 -0
- package/bin/session/messages/SessionMutationFactory.d.ts.map +1 -0
- package/bin/session/messages/SessionMutationFactory.js +38 -0
- package/bin/session/messages/SessionMutationFactory.js.map +1 -0
- package/bin/session/messages/SessionUserMessage.d.ts +5 -7
- package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
- package/bin/session/messages/SessionUserMessage.js +5 -28
- package/bin/session/messages/SessionUserMessage.js.map +1 -1
- package/bin/{executor/core-engine/CoreEngineSignals.d.ts → session/runner/AssistantParts.d.ts} +4 -9
- package/bin/session/runner/AssistantParts.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineSignals.js → session/runner/AssistantParts.js} +4 -17
- package/bin/session/runner/AssistantParts.js.map +1 -0
- package/bin/session/runner/ContextPressure.d.ts +15 -0
- package/bin/session/runner/ContextPressure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineContextCompaction.js → session/runner/ContextPressure.js} +11 -11
- package/bin/session/runner/ContextPressure.js.map +1 -0
- package/bin/session/runner/ContextRetry.d.ts +39 -0
- package/bin/session/runner/ContextRetry.d.ts.map +1 -0
- package/bin/{executor/services/ExecutorRecoveryPolicy.js → session/runner/ContextRetry.js} +19 -19
- package/bin/session/runner/ContextRetry.js.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.d.ts → session/runner/ModelFailure.d.ts} +4 -4
- package/bin/session/runner/ModelFailure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.js → session/runner/ModelFailure.js} +4 -4
- package/bin/session/runner/ModelFailure.js.map +1 -0
- package/bin/session/runner/SessionExecutor.d.ts +108 -0
- package/bin/session/runner/SessionExecutor.d.ts.map +1 -0
- package/bin/session/runner/SessionExecutor.js +430 -0
- package/bin/session/runner/SessionExecutor.js.map +1 -0
- package/bin/session/runner/ToolLoopDecision.d.ts +60 -0
- package/bin/session/runner/ToolLoopDecision.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineLoopDecision.js → session/runner/ToolLoopDecision.js} +5 -5
- package/bin/session/runner/ToolLoopDecision.js.map +1 -0
- package/bin/session/runner/ToolLoopLimits.d.ts +30 -0
- package/bin/session/runner/ToolLoopLimits.d.ts.map +1 -0
- package/bin/session/runner/ToolLoopLimits.js +46 -0
- package/bin/session/runner/ToolLoopLimits.js.map +1 -0
- package/bin/session/{browse → storage}/Browse.d.ts +1 -1
- package/bin/session/storage/Browse.d.ts.map +1 -0
- package/bin/session/{browse → storage}/Browse.js +1 -1
- package/bin/session/storage/Browse.js.map +1 -0
- package/bin/session/storage/LocalSessionStore.js +1 -1
- package/bin/session/storage/LocalSessionStore.js.map +1 -1
- package/bin/session/storage/LocalStorePaths.d.ts +0 -2
- package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
- package/bin/session/storage/LocalStorePaths.js +1 -1
- package/bin/session/storage/LocalStorePaths.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +1 -23
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +0 -18
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +0 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +0 -1
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js +0 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js.map +1 -1
- package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -1
- package/bin/session/storage/SessionStorageCodec.js +36 -18
- package/bin/session/storage/SessionStorageCodec.js.map +1 -1
- package/bin/session/storage/SessionStorageSchema.d.ts +1 -1
- package/bin/session/storage/SessionStorageSchema.js +1 -1
- package/bin/session/storage/SqliteSessionStorage.d.ts +6 -4
- package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -1
- package/bin/session/storage/SqliteSessionStorage.js +21 -18
- package/bin/session/storage/SqliteSessionStorage.js.map +1 -1
- package/bin/tools/ask/AskQuestionAnswers.d.ts +20 -0
- package/bin/tools/ask/AskQuestionAnswers.d.ts.map +1 -0
- package/bin/tools/ask/AskQuestionAnswers.js +99 -0
- package/bin/tools/ask/AskQuestionAnswers.js.map +1 -0
- package/bin/tools/ask/AskQuestionsTool.d.ts +5 -2
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +23 -31
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +1 -1
- package/bin/types/agent/AgentOptions.d.ts +16 -8
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentSessionCollection.d.ts +8 -0
- package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +3 -3
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/group/DispatchStrategy.js +1 -1
- package/bin/types/group/DispatchStrategy.js.map +1 -1
- package/bin/types/group/GroupSession.d.ts +41 -1
- package/bin/types/group/GroupSession.d.ts.map +1 -1
- package/bin/types/group/GroupSessionStore.d.ts +30 -3
- package/bin/types/group/GroupSessionStore.d.ts.map +1 -1
- package/bin/types/model/ModelRequest.d.ts.map +1 -0
- package/bin/types/model/ModelRequest.js.map +1 -0
- package/bin/types/sdk/AgentSessionAction.d.ts +1 -9
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/session/{AdaptivePartContextPolicy.d.ts → ContextCheckpoint.d.ts} +10 -9
- package/bin/types/session/ContextCheckpoint.d.ts.map +1 -0
- package/bin/types/session/ContextCheckpoint.js +8 -0
- package/bin/types/session/ContextCheckpoint.js.map +1 -0
- package/bin/types/session/SessionAgentMessageState.d.ts +6 -10
- package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/types/session/SessionAgentMessageState.js +3 -2
- package/bin/types/session/SessionAgentMessageState.js.map +1 -1
- package/bin/types/session/SessionComposer.d.ts +65 -36
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.js +7 -2
- package/bin/types/session/SessionComposer.js.map +1 -1
- package/bin/types/session/SessionExecution.d.ts +15 -11
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionExecution.js +1 -1
- package/bin/types/session/SessionInteractions.d.ts +0 -2
- package/bin/types/session/SessionInteractions.d.ts.map +1 -1
- package/bin/types/session/SessionLocalState.d.ts +0 -4
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/bin/types/session/SessionLoop.d.ts +33 -12
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +3 -29
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +16 -13
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +0 -3
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionState.d.ts +0 -1
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +10 -12
- package/bin/types/session/SessionSystem.d.ts.map +1 -1
- package/bin/types/session/SessionTool.d.ts +2 -2
- package/bin/types/session/SessionTool.d.ts.map +1 -1
- package/bin/types/session/SessionTurnCompletion.d.ts +12 -2
- package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -1
- package/bin/types/session/SessionTurnFileDiff.d.ts +4 -4
- package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -1
- package/bin/types/session/{SessionComposition.d.ts → StepInput.d.ts} +17 -15
- package/bin/types/session/StepInput.d.ts.map +1 -0
- package/bin/types/session/StepInput.js +8 -0
- package/bin/types/session/StepInput.js.map +1 -0
- package/bin/types/store/SessionHistoryMeta.d.ts.map +1 -0
- package/bin/types/store/SessionHistoryMeta.js.map +1 -0
- package/bin/types/store/SessionStorage.d.ts +17 -12
- package/bin/types/store/SessionStorage.d.ts.map +1 -1
- package/bin/types/tool/BoundAgentTool.d.ts +36 -0
- package/bin/types/tool/BoundAgentTool.d.ts.map +1 -0
- package/bin/types/tool/BoundAgentTool.js +13 -0
- package/bin/types/tool/BoundAgentTool.js.map +1 -0
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +9 -13
- package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/types/tools/ask/AskQuestionsTool.js +3 -2
- package/bin/types/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/turn/SessionAssistantOutput.d.ts.map +1 -0
- package/bin/types/turn/SessionAssistantOutput.js.map +1 -0
- package/bin/types/{executor → turn}/SessionTurnContext.d.ts +10 -28
- package/bin/types/turn/SessionTurnContext.d.ts.map +1 -0
- package/bin/types/turn/SessionTurnContext.js.map +1 -0
- package/bin/{executor/ids/resolveSessionId.d.ts → utils/ResolveSessionId.d.ts} +1 -1
- package/bin/utils/ResolveSessionId.d.ts.map +1 -0
- package/bin/{executor/ids/resolveSessionId.js → utils/ResolveSessionId.js} +1 -1
- package/bin/utils/ResolveSessionId.js.map +1 -0
- package/bin/utils/Time.d.ts +5 -8
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +5 -54
- package/bin/utils/Time.js.map +1 -1
- package/package.json +2 -2
- package/scripts/ask-question-answers.test.mjs +132 -0
- package/scripts/group-session-archive.test.mjs +193 -0
- package/scripts/{core-engine-model-stream.test.mjs → model-step-runner.test.mjs} +97 -4
- package/scripts/rewrite-build-aliases.mjs +3 -4
- package/scripts/session-action-part.test.mjs +172 -0
- package/scripts/session-agent-message-part-order.test.mjs +13 -7
- package/scripts/{core-engine-context-compaction.test.mjs → session-executor-context-pressure.test.mjs} +40 -32
- package/scripts/{executor-failure-result.test.mjs → session-executor-failure-result.test.mjs} +17 -14
- package/scripts/session-executor-max-steps.test.mjs +143 -0
- package/scripts/session-initialization.test.mjs +3 -4
- package/scripts/session-interaction-migration.test.mjs +145 -0
- package/scripts/session-interaction-mutation.test.mjs +202 -0
- package/scripts/session-messages-error-part.test.mjs +1 -1
- package/scripts/session-messages-error.test.mjs +1 -1
- package/scripts/session-prompt-idempotency.test.mjs +4 -2
- package/scripts/session-queue.test.mjs +21 -1
- package/scripts/session-storage-sqlite.test.mjs +3 -3
- package/scripts/session-system-blocks.test.mjs +61 -39
- package/scripts/session-turn-context.test.mjs +37 -40
- package/scripts/verify-build-aliases.mjs +1 -1
- package/src/agent/Agent.ts +137 -80
- package/src/agent/AgentInstructions.ts +48 -15
- package/src/agent/AgentMemoryStorage.ts +1 -1
- package/src/agent/AgentSessions.ts +60 -38
- package/src/group/Group.ts +27 -24
- package/src/group/GroupSession.ts +12 -8
- package/src/group/GroupSessions.ts +79 -20
- package/src/group/storage/LocalGroupSessionDataStore.ts +9 -1
- package/src/group/storage/LocalGroupSessionStore.ts +138 -28
- package/src/index.ts +35 -52
- package/src/{executor/model → model}/ModelGenerate.ts +3 -3
- package/src/{executor/model → model}/ModelRequestRunner.ts +2 -2
- package/src/{executor/model → model}/ModelStepRunner.ts +22 -19
- package/src/{executor/model → model}/ModelStreamConsumer.ts +1 -1
- package/src/model/README.md +117 -0
- package/src/model/ToolInputValidation.ts +58 -0
- package/src/{executor → model}/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/{executor → model}/messages/SessionModelMessages.ts +0 -1
- package/src/{executor/composer/system/default → model/prompts}/SystemPromptAssets.ts +1 -1
- package/src/model/prompts/assets/core.prompt.ts +9 -0
- package/src/{executor/composer/system/default → model/prompts}/assets/core.prompt.ts.txt +26 -25
- package/src/session/Session.ts +185 -151
- package/src/session/input/SessionHookRunner.ts +100 -0
- package/src/session/{SessionSystem.ts → input/SessionSystem.ts} +31 -29
- package/src/session/input/StepInput.ts +507 -0
- package/src/session/input/composer/AdaptiveContextCheckpoint.ts +115 -0
- package/src/session/input/composer/AdaptiveContextParts.ts +166 -0
- package/src/session/input/composer/ComposerAssembly.ts +81 -0
- package/src/session/{composer/policies/SessionSummaryPrompts.ts → input/composer/ContextSummaryPrompts.ts} +5 -2
- package/src/session/input/composer/DefaultSessionComposer.ts +147 -0
- package/src/session/input/composer/FullHistorySessionComposer.ts +55 -0
- package/src/session/loop/README.md +28 -0
- package/src/session/{SessionLoop.ts → loop/SessionLoop.ts} +100 -24
- package/src/session/{SessionQueue.ts → loop/SessionQueue.ts} +18 -0
- package/src/session/{SessionState.ts → loop/SessionState.ts} +4 -21
- package/src/session/{SessionTitle.ts → loop/SessionTitle.ts} +3 -3
- package/src/session/{runtime → loop}/SessionTurnCompletion.ts +27 -8
- package/src/session/{runtime → loop}/SessionTurnContext.ts +19 -93
- package/src/session/{runtime → loop}/SessionTurnFileDiff.ts +1 -1
- package/src/session/{messages → loop}/SessionTurnFileDiffBuilder.ts +4 -4
- package/src/session/messages/ApprovalInteraction.ts +77 -0
- package/src/session/messages/README.md +27 -0
- package/src/session/messages/SessionAgentMessageState.ts +324 -113
- package/src/session/messages/SessionAgentMessageWriter.ts +82 -45
- package/src/session/messages/SessionAgentParts.ts +39 -0
- package/src/session/{execution → messages}/SessionAssistantOutputAdapter.ts +2 -2
- package/src/session/messages/SessionInteractions.ts +227 -0
- package/src/session/messages/SessionJsonValue.ts +1 -18
- package/src/session/messages/SessionMessageCache.ts +171 -0
- package/src/session/messages/SessionMessageState.ts +42 -0
- package/src/session/{browse → messages}/SessionMessageTimeline.ts +0 -1
- package/src/session/{SessionMessages.ts → messages/SessionMessages.ts} +225 -284
- package/src/session/messages/SessionMutationFactory.ts +58 -0
- package/src/session/messages/SessionUserMessage.ts +7 -32
- package/src/{executor/core-engine/CoreEngineSignals.ts → session/runner/AssistantParts.ts} +3 -21
- package/src/{executor/core-engine/CoreEngineContextCompaction.ts → session/runner/ContextPressure.ts} +10 -10
- package/src/{executor/services/ExecutorRecoveryPolicy.ts → session/runner/ContextRetry.ts} +25 -25
- package/src/{executor/core-engine/CoreEngineError.ts → session/runner/ModelFailure.ts} +3 -3
- package/src/session/runner/SessionExecutor.ts +633 -0
- package/src/session/runner/ToolLoopDecision.ts +98 -0
- package/src/session/runner/ToolLoopLimits.ts +53 -0
- package/src/session/{browse → storage}/Browse.ts +2 -2
- package/src/session/storage/LocalSessionStore.ts +1 -1
- package/src/session/storage/LocalStorePaths.ts +1 -1
- package/src/session/storage/Metadata.ts +1 -44
- package/src/session/storage/RuntimeSessionPort.ts +0 -5
- package/src/session/{preview → storage}/SessionMessagePreview.ts +0 -1
- package/src/session/storage/SessionStorageCodec.ts +54 -28
- package/src/session/storage/SessionStorageSchema.ts +1 -1
- package/src/session/storage/SqliteSessionStorage.ts +29 -22
- package/src/tools/ask/AskQuestionAnswers.ts +125 -0
- package/src/tools/ask/AskQuestionsTool.ts +32 -37
- package/src/types/agent/AgentOptions.ts +17 -8
- package/src/types/agent/AgentSessionCollection.ts +9 -0
- package/src/types/agent/SessionActor.ts +3 -4
- package/src/types/group/DispatchStrategy.ts +1 -1
- package/src/types/group/GroupSession.ts +44 -1
- package/src/types/group/GroupSessionStore.ts +30 -3
- package/src/types/sdk/AgentSessionAction.ts +1 -14
- package/src/types/session/{AdaptivePartContextPolicy.ts → ContextCheckpoint.ts} +9 -8
- package/src/types/session/SessionAgentMessageState.ts +6 -16
- package/src/types/session/SessionComposer.ts +67 -39
- package/src/types/session/SessionExecution.ts +15 -13
- package/src/types/session/SessionInteractions.ts +0 -2
- package/src/types/session/SessionLocalState.ts +0 -5
- package/src/types/session/SessionLoop.ts +37 -12
- package/src/types/session/SessionMessages.ts +3 -34
- package/src/types/session/SessionOptions.ts +18 -13
- package/src/types/session/SessionPort.ts +0 -4
- package/src/types/session/SessionState.ts +0 -1
- package/src/types/session/SessionSystem.ts +10 -16
- package/src/types/session/SessionTool.ts +2 -2
- package/src/types/session/SessionTurnCompletion.ts +12 -2
- package/src/types/session/SessionTurnFileDiff.ts +4 -4
- package/src/types/session/{SessionComposition.ts → StepInput.ts} +22 -14
- package/src/types/store/SessionStorage.ts +17 -12
- package/src/types/tool/BoundAgentTool.ts +38 -0
- package/src/types/tools/ask/AskQuestionsTool.ts +11 -13
- package/src/types/{executor → turn}/SessionTurnContext.ts +8 -34
- package/src/utils/Time.ts +12 -64
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/Executor.d.ts +0 -92
- package/bin/executor/Executor.d.ts.map +0 -1
- package/bin/executor/Executor.js +0 -232
- package/bin/executor/Executor.js.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +0 -15
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +0 -26
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +0 -48
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +0 -343
- package/bin/executor/core-engine/CoreEngineRunner.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +0 -1
- package/bin/executor/ids/resolveSessionId.d.ts.map +0 -1
- package/bin/executor/ids/resolveSessionId.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +0 -1
- package/bin/executor/messages/SessionMessageLog.d.ts.map +0 -1
- package/bin/executor/messages/SessionMessageLog.js.map +0 -1
- package/bin/executor/messages/SessionModelMessages.d.ts.map +0 -1
- package/bin/executor/messages/SessionModelMessages.js.map +0 -1
- package/bin/executor/model/ModelGenerate.d.ts.map +0 -1
- package/bin/executor/model/ModelGenerate.js.map +0 -1
- package/bin/executor/model/ModelRequestRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelRequestRunner.js.map +0 -1
- package/bin/executor/model/ModelStepRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelStepRunner.js.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.js.map +0 -1
- package/bin/executor/model/ModelStreamFailure.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamFailure.js.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +0 -39
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.js.map +0 -1
- package/bin/executor/types/SessionLoop.d.ts +0 -59
- package/bin/executor/types/SessionLoop.d.ts.map +0 -1
- package/bin/executor/types/SessionLoop.js +0 -9
- package/bin/executor/types/SessionLoop.js.map +0 -1
- package/bin/executor/types/SessionPrompts.d.ts +0 -14
- package/bin/executor/types/SessionPrompts.d.ts.map +0 -1
- package/bin/executor/types/SessionPrompts.js +0 -8
- package/bin/executor/types/SessionPrompts.js.map +0 -1
- package/bin/session/DefaultSessionComposer.d.ts +0 -24
- package/bin/session/DefaultSessionComposer.d.ts.map +0 -1
- package/bin/session/DefaultSessionComposer.js +0 -99
- package/bin/session/DefaultSessionComposer.js.map +0 -1
- package/bin/session/SessionComposition.d.ts +0 -49
- package/bin/session/SessionComposition.d.ts.map +0 -1
- package/bin/session/SessionComposition.js +0 -309
- package/bin/session/SessionComposition.js.map +0 -1
- package/bin/session/SessionHookPoints.d.ts +0 -15
- package/bin/session/SessionHookPoints.d.ts.map +0 -1
- package/bin/session/SessionHookPoints.js +0 -15
- package/bin/session/SessionHookPoints.js.map +0 -1
- package/bin/session/SessionHooks.d.ts +0 -38
- package/bin/session/SessionHooks.d.ts.map +0 -1
- package/bin/session/SessionHooks.js +0 -71
- package/bin/session/SessionHooks.js.map +0 -1
- package/bin/session/SessionLoop.d.ts.map +0 -1
- package/bin/session/SessionLoop.js.map +0 -1
- package/bin/session/SessionMessages.d.ts.map +0 -1
- package/bin/session/SessionMessages.js.map +0 -1
- package/bin/session/SessionQueue.d.ts.map +0 -1
- package/bin/session/SessionQueue.js.map +0 -1
- package/bin/session/SessionState.d.ts.map +0 -1
- package/bin/session/SessionState.js.map +0 -1
- package/bin/session/SessionSystem.d.ts +0 -19
- package/bin/session/SessionSystem.d.ts.map +0 -1
- package/bin/session/SessionSystem.js.map +0 -1
- package/bin/session/SessionTitle.d.ts.map +0 -1
- package/bin/session/SessionTitle.js.map +0 -1
- package/bin/session/browse/Browse.d.ts.map +0 -1
- package/bin/session/browse/Browse.js.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.d.ts.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.js.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +0 -35
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js +0 -256
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +0 -24
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.js +0 -31
- package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.js.map +0 -1
- package/bin/session/control/SessionInteractions.d.ts +0 -39
- package/bin/session/control/SessionInteractions.d.ts.map +0 -1
- package/bin/session/control/SessionInteractions.js +0 -255
- package/bin/session/control/SessionInteractions.js.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +0 -28
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js +0 -87
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts +0 -22
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.js +0 -36
- package/bin/session/messages/SessionAgentActionPartWriter.js.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts +0 -46
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +0 -183
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.d.ts.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.js.map +0 -1
- package/bin/session/runtime/SessionEventHub.d.ts.map +0 -1
- package/bin/session/runtime/SessionEventHub.js.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.d.ts.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.js.map +0 -1
- package/bin/session/runtime/SessionTitleTask.d.ts.map +0 -1
- package/bin/session/runtime/SessionTitleTask.js.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.js.map +0 -1
- package/bin/session/runtime/SessionTurnContext.d.ts +0 -29
- package/bin/session/runtime/SessionTurnContext.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnContext.js.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.js.map +0 -1
- package/bin/types/action/ActionResult.d.ts +0 -35
- package/bin/types/action/ActionResult.d.ts.map +0 -1
- package/bin/types/action/ActionResult.js +0 -18
- package/bin/types/action/ActionResult.js.map +0 -1
- package/bin/types/executor/ModelRequest.d.ts.map +0 -1
- package/bin/types/executor/ModelRequest.js.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.js.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +0 -23
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.js +0 -10
- package/bin/types/executor/SessionToolExecutionContext.js.map +0 -1
- package/bin/types/executor/SessionTurnContext.d.ts.map +0 -1
- package/bin/types/executor/SessionTurnContext.js.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.js +0 -7
- package/bin/types/session/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/types/session/SessionComposition.d.ts.map +0 -1
- package/bin/types/session/SessionComposition.js +0 -8
- package/bin/types/session/SessionComposition.js.map +0 -1
- package/bin/types/session/SessionContextPolicy.d.ts +0 -70
- package/bin/types/session/SessionContextPolicy.d.ts.map +0 -1
- package/bin/types/session/SessionContextPolicy.js +0 -8
- package/bin/types/session/SessionContextPolicy.js.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.d.ts +0 -30
- package/bin/types/tools/ToolActionExecutionContext.d.ts.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.js +0 -8
- package/bin/types/tools/ToolActionExecutionContext.js.map +0 -1
- package/src/executor/Executor.ts +0 -319
- package/src/executor/README.md +0 -92
- package/src/executor/composer/system/default/assets/core.prompt.ts +0 -9
- package/src/executor/core-engine/CoreEngineLoopDecision.ts +0 -63
- package/src/executor/core-engine/CoreEngineRunner.ts +0 -458
- package/src/executor/types/SessionLoop.ts +0 -69
- package/src/executor/types/SessionPrompts.ts +0 -14
- package/src/session/DefaultSessionComposer.ts +0 -123
- package/src/session/SessionComposition.ts +0 -370
- package/src/session/SessionHookPoints.ts +0 -17
- package/src/session/SessionHooks.ts +0 -85
- package/src/session/composer/policies/AdaptivePartContextPolicy.ts +0 -307
- package/src/session/composer/policies/FullHistoryContextPolicy.ts +0 -36
- package/src/session/control/SessionInteractions.ts +0 -311
- package/src/session/execution/tools/SessionShellApprovalAdapter.ts +0 -105
- package/src/session/messages/SessionAgentActionPartWriter.ts +0 -54
- package/src/session/messages/SessionMessageInteractionWriter.ts +0 -279
- package/src/types/action/ActionResult.ts +0 -50
- package/src/types/executor/SessionToolExecutionContext.ts +0 -26
- package/src/types/session/SessionContextPolicy.ts +0 -77
- package/src/types/tools/ToolActionExecutionContext.ts +0 -32
- /package/bin/{executor/model → model}/ModelGenerate.js +0 -0
- /package/bin/{executor/model → model}/ModelRequestRunner.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.js +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.d.ts +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.js +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.js +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.js +0 -0
- /package/bin/{executor → model}/messages/SessionModelMessages.d.ts +0 -0
- /package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.js +0 -0
- /package/bin/session/{runtime → loop}/SessionTurnFileDiff.d.ts +0 -0
- /package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.js +0 -0
- /package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.js +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.js +0 -0
- /package/bin/session/{browse → messages}/SessionMessageTimeline.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.js +0 -0
- /package/bin/session/{preview → storage}/SessionMessagePreview.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.js +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.d.ts +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.js +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.d.ts +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.js +0 -0
- /package/bin/types/{executor → turn}/SessionTurnContext.js +0 -0
- /package/src/{executor/model → model}/ModelStreamFailure.ts +0 -0
- /package/src/{executor → model}/messages/ChatMessageMarkup.ts +0 -0
- /package/src/{executor → model}/messages/SessionAttachmentMapper.ts +0 -0
- /package/src/{executor → model}/messages/SessionMessageLog.ts +0 -0
- /package/src/session/{runtime → loop}/SessionTitleTask.ts +0 -0
- /package/src/session/{runtime → messages}/SessionEventHub.ts +0 -0
- /package/src/session/{runtime → messages}/SessionModelRequestWarning.ts +0 -0
- /package/src/types/{executor → model}/ModelRequest.ts +0 -0
- /package/src/{executor/types → types/store}/SessionHistoryMeta.ts +0 -0
- /package/src/types/{executor → turn}/SessionAssistantOutput.ts +0 -0
- /package/src/{executor/ids/resolveSessionId.ts → utils/ResolveSessionId.ts} +0 -0
package/src/executor/README.md
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# Executor Module
|
|
2
|
-
|
|
3
|
-
`executor/` 是 Session 内部的模型与 Tool Loop 执行内核。普通 SDK 用户只通过 `Session` 调用它。
|
|
4
|
-
|
|
5
|
-
完整 Session Runtime 设计见 [`docs/session-runtime-architecture.md`](../../../../docs/session-runtime-architecture.md)。
|
|
6
|
-
|
|
7
|
-
## 边界
|
|
8
|
-
|
|
9
|
-
- `Session` 拥有输入队列并创建 Command;`SessionLoop` 负责消费、Turn Handle 与 Assistant Message 收口。
|
|
10
|
-
- `SessionTurnContext` 从 Turn 创建起唯一拥有取消信号、Step 快照和执行期资源。
|
|
11
|
-
- `SessionComposer` 根据只读 Session 快照组装 system、messages 和 tools。
|
|
12
|
-
- `Executor` 管理一次 Turn 的输入装配、上下文超限恢复和 Step Plugin Lease;它只对外提供 `execute()`。
|
|
13
|
-
- `ModelRequestRunner` 唯一拥有普通模型请求的五次重试、退避和逐次失败通知。
|
|
14
|
-
- `CoreEngineRunner` 执行 Tool Loop、续写和真实 usage 观测,不自行改写模型历史,也不维护普通请求重试状态。
|
|
15
|
-
- `SessionMessages` 是 Message 唯一事实源;Executor 不写文件、不持有 Store。
|
|
16
|
-
|
|
17
|
-
## 执行关系
|
|
18
|
-
|
|
19
|
-
```mermaid
|
|
20
|
-
flowchart LR
|
|
21
|
-
Loop["SessionLoop"] --> Context["SessionTurnContext"]
|
|
22
|
-
Context --> Executor
|
|
23
|
-
Executor --> Composer["SessionComposer"]
|
|
24
|
-
Composer --> Input["system + messages + tools"]
|
|
25
|
-
Executor --> Engine["CoreEngineRunner"]
|
|
26
|
-
Input --> Engine
|
|
27
|
-
Engine --> Request["ModelRequestRunner"]
|
|
28
|
-
Request --> Step["ModelStepRunner"]
|
|
29
|
-
Step --> Model["ModelClient"]
|
|
30
|
-
Engine --> Tools["Tools / Plugins"]
|
|
31
|
-
Model -->|"ModelStreamEvent"| Step
|
|
32
|
-
Step --> Request
|
|
33
|
-
Engine -->|"ModelStreamEvent / Tool Result"| Context
|
|
34
|
-
Context --> Messages["SessionMessages"]
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
每个模型 Step 前,`SessionLoop` 先消费排队的 Steer 和状态 Command。Executor 随后捕获最新 effective state,并调用 Composer 生成完整 Step 输入。
|
|
38
|
-
|
|
39
|
-
```text
|
|
40
|
-
Session.prompt()
|
|
41
|
-
-> SessionLoop 持久化 canonical User Message
|
|
42
|
-
-> Executor 捕获只读 Session 快照
|
|
43
|
-
-> SessionComposer.compose()
|
|
44
|
-
-> SessionModelMessages: SessionMessage -> ModelMessage
|
|
45
|
-
-> CoreEngineRunner.execute()
|
|
46
|
-
-> Federation / Provider 返回 ModelStreamEvent
|
|
47
|
-
-> SessionAssistantOutput 直接更新 canonical Assistant Message
|
|
48
|
-
-> SessionMessages 持久化并发布 Mutation
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 旧 Composer 去向
|
|
52
|
-
|
|
53
|
-
过去的四个独立 Composer 不再构成执行管线:
|
|
54
|
-
|
|
55
|
-
| 旧能力 | 当前归属 |
|
|
56
|
-
| --- | --- |
|
|
57
|
-
| `SystemComposer` | `DefaultSessionComposer.compose()` + `SessionSystem` |
|
|
58
|
-
| `HistoryComposer` | `SessionComposer` + `SessionContextPolicy` + `SessionModelMessages` |
|
|
59
|
-
| `ContextComposer` 的 tools | `Session.create_compose_input()` + `SessionComposer.compose()` |
|
|
60
|
-
| `ContextComposer` 的 Step Callback | `SessionLoop` + `CoreEngineRunner` |
|
|
61
|
-
| `ContextComposer` 的 fallback Assistant | `CoreEngineRunner` + `ExecutorRecoveryPolicy` |
|
|
62
|
-
| `CompactionComposer` | `SessionComposer.recover_context()` + Context Policy 派生表 |
|
|
63
|
-
|
|
64
|
-
统一 Composer 只回答一个策略问题:
|
|
65
|
-
|
|
66
|
-
1. 当前 Step 的 system、messages 和 tools 是什么?上下文超限时是否能由当前 Policy 推进派生状态?
|
|
67
|
-
|
|
68
|
-
Queue 消费、Turn 控制、Message 写入和 Mutation 发布都不是 Composer 职责。
|
|
69
|
-
|
|
70
|
-
## Context recovery
|
|
71
|
-
|
|
72
|
-
```text
|
|
73
|
-
SessionLoop / CoreEngine
|
|
74
|
-
-> SessionComposer.recover_context()
|
|
75
|
-
-> SessionContextPolicy 写入自己的派生表
|
|
76
|
-
-> Composer 下一次 compose() 读取最新派生上下文
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Composer 可以调用模型生成 Summary,但不能修改 canonical Message、Metadata 或发布事件。持久化提交始终由 `SessionStorage` 事务完成。
|
|
80
|
-
|
|
81
|
-
## 目录
|
|
82
|
-
|
|
83
|
-
```text
|
|
84
|
-
executor/
|
|
85
|
-
Executor.ts
|
|
86
|
-
core-engine/ 模型与 Tool Loop
|
|
87
|
-
composer/system/ 可复用的默认 system prompt 领域实现
|
|
88
|
-
messages/ Session 与 Model Protocol 消息转换
|
|
89
|
-
services/ 执行恢复策略
|
|
90
|
-
tools/ Tool 运行辅助
|
|
91
|
-
types/ Executor 内部类型
|
|
92
|
-
```
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 自动生成文件,请勿手改。
|
|
3
|
-
* 源文件:由同路径 `*.ts.txt` 生成。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Source: src/executor/composer/system/default/assets/core.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "# Harness Design\n\nYou are a Downcity Agent. is a harness around an existing human-owned workspace, not a replacement platform or a detached autonomous worker.\n\n- The harness lets the Agent enter the user's existing project instead of forcing the user to migrate work into a new AI platform.\n- The project structure is the control surface. Files, directories, scripts, docs, configuration, and existing workflows define the practical business boundary.\n- The Agent inherits the workspace's knowledge topology. Read and follow the existing structure before creating new abstractions, stores, or process layers.\n- The harness keeps the human in control. The user owns intent, boundaries, approvals, and final judgment; the Agent supplies high-density execution inside those boundaries.\n- Agent state should remain observable and handoff-friendly. Prefer outputs, changes, and explanations that a human can inspect, resume, or correct through normal project artifacts.\n- Autonomy should be progressive. Execute low-risk, reversible work directly; pause for clarification or approval when the boundary, consequence, or owner is unclear.\n- Tools and plugins are harness surfaces. Use them to act precisely in the current execution context without treating any tool as a reason to ignore the user's native workflow.\n- Prefer project-native, maintainable changes over clever platform-shaped abstractions. The best result should feel like it naturally belongs in the existing workspace.\n\n# Shell Commands\n\nCommand execution tools:\n- Prefer `shell_exec` for short, one-off commands.\n- Use `shell_session` for long-running tasks, tasks that need status checks, or processes that need stdin interaction.\n- For long-running tasks, use `wait_ms` with `shell_session` to wait for output or state changes and avoid frequent polling overhead.\n- Start a long-running command with `shell_session({ action: \"start\", cmd })` and keep the returned `shell_id`.\n- `shell_id` identifies a shell session; it is not a chat `session_id`.\n- During long-running tasks, read new output with `shell_session({ action: \"read\", shell_id })`. Do not implement your own high-frequency empty polling loop.\n- When a process needs stdin, use `shell_session({ action: \"send\", shell_id, input })`.\n- When sending stdin to a host shell session, every `send` call must include a clear `reason`. Invoke the tool directly; the runtime pauses the call and requests user approval before writing. Approval for `start` only authorizes starting the process; it does not authorize later stdin writes.\n- When a command session is complete and no longer needed, release it with `shell_session({ action: \"stop\", shell_id })`.\n- Do not forward very long raw shell output directly to the user. Summarize it first.\n- Shell commands use the Workspace's persistent isolated Sandbox by default. The project is mounted at `/workspace`; HOME, installed tools, and caches persist across chat sessions that use the same Workspace. Different Workspaces do not share writable Sandbox state.\n- When installing Python dependencies, prefer a project-local `.venv`; do not use `pip install --user`.\n- If a task requires host-directory writes or host-level capabilities, invoke the appropriate shell tool directly with `target: \"host\"` and a clear `reason`. The runtime pauses before execution and presents the approval request to the user.\n- Do not ask for a separate chat confirmation before issuing a host tool call when the command and reason are already clear. Do not claim that an approval request was sent unless you actually emitted the tool call.\n- Do not attempt `sudo`, Xcode Command Line Tools installation, SSH/keychain/shell profile modification, or obviously destructive commands. These requests are rejected even for host execution.\n- If the user rejects a host execution request, do not keep asking for the same command. Explain the impact and provide a Sandbox alternative when possible.\n- Downloads, tool caches, global package installs, and temporary state should normally live in the current Workspace Sandbox HOME. Do not assume access to the real user's HOME or cache.\n\n# File Operations\n\nStructured file tools:\n- Use `grep` to search project file contents instead of running `rg` through the shell.\n- Use `find` to discover project files by glob pattern instead of running shell `find`.\n- Use `read` to examine project files instead of `cat`, `head`, `tail`, or `sed`. Continue with the returned `next_offset` when `truncated` is true.\n- Use `write` for new files or complete rewrites. Existing files are not overwritten unless `overwrite: true` is explicit.\n- Use `edit` for precise changes. Every `edits[].old_text` must match exactly once in the original file.\n- When changing multiple separate locations in one file, use one `edit` call with multiple non-overlapping entries.\n- Pass the SHA-256 returned by `read` as `edit.expected_sha256` when the file may be changed concurrently.\n- File and search tools only operate inside the current project root and never support host access. Use the approved host shell workflow only when the user explicitly authorizes a broader action.\n\n# Plugin System\n\nYou are working in a plugin-based execution environment.\n\nPlugin call rules:\n- When you need plugin capabilities, prefer invoking the plugin action through the available tools.\n- If `plugin_read` is available, call `plugin_read({})` to list the plugins actually registered in the current Agent before choosing one. Use `plugin_read({ plugin, action? })` to inspect its action schema and examples.\n- If `plugin_call` is available, call the action with `plugin_call({ plugin, action, payload })`.\n- `plugin_call.plugin` must be a plugin name returned by `plugin_read({})`.\n- `plugin_call.action` must be an action name returned by `plugin_read({ plugin })`.\n- `plugin_call.payload` is a structured JSON payload. Pass `{}` when there are no parameters. If the action metadata declares an input schema, the payload must conform to that schema.\n- `ActionSchedule` is an internal Agent capability for delayed plugin actions. It is not a standalone plugin.\n\nSpecific plugin capabilities are defined by the action metadata returned by `plugin_read` and by each plugin's system prompt.\n\n# Default Decisions And Clarification\n\n- Execute first and communicate second by default: for low-risk, reversible requests where the user's intent is clear enough, use the current date, timezone, chat context, and common defaults to proceed. Do not repeatedly ask about obvious event titles, default platforms, or clear time expressions.\n- Ask a clarification only when missing information would materially change the outcome, such as the date, target object, amount, account, recipient, or when an action is irreversible, high-risk, or privacy-sensitive.\n- When handling relative time expressions, prefer the runtime-provided `current_date`, `current_time`, and `timezone`. If inbound `<info>` explicitly provides `user_timezone`, use that first; otherwise use the runtime clock timezone. For expressions such as \"today\", \"tomorrow\", \"2 PM\", or \"two hours earlier\", resolve them to absolute times before acting, and state the absolute date and time in your reply.\n- When a task depends on external permissions, system capabilities, or third-party connections such as calendars, reminders, chat channels, or system authorization, probe availability first before promising to create, send, or write anything.\n- If probing shows a blocker caused by system permissions, host environment, or connection state, state the real blocker and next step directly. Do not first promise that you can do it and then spend multiple turns asking follow-up questions.\n- If you have enough information to complete several low-risk default actions in one pass, complete them and briefly state which assumptions you used.\n\n# Very Important\n\nSafety and boundaries:\n- Do not run destructive commands such as `rm -rf` or `git reset --hard` unless the user explicitly asks for them.\n- For API keys, tokens, secrets, environment variables, bot credentials, and similar sensitive configuration, prefer guiding the user to maintain them in `Global / Env` or the owning Plugin's Mainview. Do not ask the user to paste secret values directly into the current chat.\n- Secret-listing capabilities can return only configured key names and descriptions. They never return secret values. Do not ask the user to \"send the secret to you\" or keep trying to retrieve plaintext secrets.\n";
|
|
8
|
-
|
|
9
|
-
export default TEXT_MODULE_CONTENT;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CoreEngineLoopDecision:模型/tool-loop 核心循环的纯决策模块。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 把 “是否继续下一轮” 的分支优先级从 CoreEngine 主流程中拆出。
|
|
6
|
-
* - 保持纯函数,不依赖模型、持久化或 logger,便于直接测试。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
SessionLoopDecision,
|
|
11
|
-
SessionLoopDecisionInput,
|
|
12
|
-
SessionTailMergeContinuationInput,
|
|
13
|
-
} from "@/executor/types/SessionLoop.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 评估当前 step 完成后,tool-loop 是否应继续下一轮。
|
|
17
|
-
*
|
|
18
|
-
* 优先级(中文)
|
|
19
|
-
* 1. 不完整响应恢复
|
|
20
|
-
* 2. 已发生的工具调用
|
|
21
|
-
* 3. 停止
|
|
22
|
-
*/
|
|
23
|
-
export function evaluate_core_engine_loop_decision(
|
|
24
|
-
input: SessionLoopDecisionInput,
|
|
25
|
-
): SessionLoopDecision {
|
|
26
|
-
if (
|
|
27
|
-
input.hasIncompleteResponse &&
|
|
28
|
-
input.incompleteRecoveryCount < input.maxIncompleteRecoveries
|
|
29
|
-
) {
|
|
30
|
-
return {
|
|
31
|
-
kind: "recover_incomplete",
|
|
32
|
-
continueForToolCalls: false,
|
|
33
|
-
continueForIncompleteRecovery: true,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (input.toolCallCount > 0) {
|
|
38
|
-
return {
|
|
39
|
-
kind: "continue_for_tool_calls",
|
|
40
|
-
continueForToolCalls: true,
|
|
41
|
-
continueForIncompleteRecovery: false,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
kind: "stop",
|
|
47
|
-
continueForToolCalls: false,
|
|
48
|
-
continueForIncompleteRecovery: false,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 评估 stop 前的尾部合并是否应该继续下一轮。
|
|
54
|
-
*
|
|
55
|
-
* 关键点(中文)
|
|
56
|
-
* - 只要最后一次 tail merge 真正并入了新的 user 消息,就必须续跑。
|
|
57
|
-
* - 这样可以覆盖“最后一个 step 结束后,新消息才到达”的收尾窗口。
|
|
58
|
-
*/
|
|
59
|
-
export function should_continue_for_tail_merged_user_messages(
|
|
60
|
-
input: SessionTailMergeContinuationInput,
|
|
61
|
-
): boolean {
|
|
62
|
-
return input.mergedUserMessageCount > 0;
|
|
63
|
-
}
|
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CoreEngineRunner:模型与 tool-loop 主循环执行器。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 每个 Provider Step 都通过回调取得 Composer 生成的完整输入。
|
|
6
|
-
* - 只负责 step 循环、续写恢复与最终 assistant 汇总,不持有历史副本。
|
|
7
|
-
* - 保持失败返回结构稳定,避免对外 Session 行为变化。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { RuntimeTool as Tool } from "@downcity/type";
|
|
11
|
-
import { log_assistant_message_now } from "@executor/messages/SessionMessageLog.js";
|
|
12
|
-
import {
|
|
13
|
-
MAX_INCOMPLETE_RESPONSE_RECOVERIES,
|
|
14
|
-
MAX_TOOL_LOOP_STEPS,
|
|
15
|
-
build_incomplete_response_recovery_nudge,
|
|
16
|
-
detect_incomplete_response,
|
|
17
|
-
extract_assistant_text,
|
|
18
|
-
merge_assistant_parts,
|
|
19
|
-
summarize_assistant_parts_for_debug,
|
|
20
|
-
summarize_step_for_debug,
|
|
21
|
-
to_inline_preview,
|
|
22
|
-
} from "@executor/core-engine/CoreEngineSignals.js";
|
|
23
|
-
import {
|
|
24
|
-
evaluate_core_engine_loop_decision,
|
|
25
|
-
should_continue_for_tail_merged_user_messages,
|
|
26
|
-
} from "@executor/core-engine/CoreEngineLoopDecision.js";
|
|
27
|
-
import {
|
|
28
|
-
resolve_effective_core_engine_error,
|
|
29
|
-
} from "@executor/core-engine/CoreEngineError.js";
|
|
30
|
-
import {
|
|
31
|
-
run_model_step,
|
|
32
|
-
type ModelStepResult,
|
|
33
|
-
type ModelStepToolCall,
|
|
34
|
-
} from "@executor/model/ModelStepRunner.js";
|
|
35
|
-
import { execute_model_request } from "@executor/model/ModelRequestRunner.js";
|
|
36
|
-
import {
|
|
37
|
-
resolve_model_usage_ratio,
|
|
38
|
-
should_compact_after_usage,
|
|
39
|
-
} from "@executor/core-engine/CoreEngineContextCompaction.js";
|
|
40
|
-
import type { Logger } from "@/utils/logger/Logger.js";
|
|
41
|
-
import type { SessionTurnContext } from "@/types/executor/SessionTurnContext.js";
|
|
42
|
-
import { to_session_json_value } from "@/session/messages/SessionJsonValue.js";
|
|
43
|
-
import type {
|
|
44
|
-
SessionStepExecutionInput,
|
|
45
|
-
SessionTurnExecutionResult,
|
|
46
|
-
} from "@/types/session/SessionExecution.js";
|
|
47
|
-
import type { SessionAgentMessagePart } from "@downcity/type";
|
|
48
|
-
import { create_session_agent_content_part } from "@/session/messages/SessionAgentContent.js";
|
|
49
|
-
import { generate_id } from "@/utils/Id.js";
|
|
50
|
-
|
|
51
|
-
const TURN_STOPPED_MESSAGE = "Turn stopped";
|
|
52
|
-
|
|
53
|
-
interface CoreEngineRunnerOptions {
|
|
54
|
-
/** 当前 Session 稳定标识。 */
|
|
55
|
-
session_id: string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 当前 session 统一日志器。
|
|
59
|
-
*/
|
|
60
|
-
logger: Logger;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 判断某次执行错误是否应该上抛给外层压缩重试。
|
|
64
|
-
*/
|
|
65
|
-
should_compact_on_error: (error: unknown) => boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface CoreEngineTurnInput {
|
|
69
|
-
/**
|
|
70
|
-
* 当前显式运行上下文。
|
|
71
|
-
*/
|
|
72
|
-
turn_context: SessionTurnContext;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 在统一输入队列提交后解析当前 Session step 的 effective 配置。
|
|
76
|
-
*/
|
|
77
|
-
resolve_step_input: () => Promise<SessionStepExecutionInput>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 模型与 tool-loop 主循环执行器。
|
|
82
|
-
*/
|
|
83
|
-
export class CoreEngineRunner {
|
|
84
|
-
private readonly session_id: string;
|
|
85
|
-
private readonly logger: Logger;
|
|
86
|
-
private readonly should_compact_on_error: CoreEngineRunnerOptions["should_compact_on_error"];
|
|
87
|
-
|
|
88
|
-
constructor(options: CoreEngineRunnerOptions) {
|
|
89
|
-
this.session_id = String(options.session_id || "").trim();
|
|
90
|
-
this.logger = options.logger;
|
|
91
|
-
this.should_compact_on_error = options.should_compact_on_error;
|
|
92
|
-
if (!this.session_id) {
|
|
93
|
-
throw new Error("CoreEngineRunner requires a non-empty session_id");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 执行一次已装配完成的模型/tool-loop 运行。
|
|
99
|
-
*/
|
|
100
|
-
async execute(input: CoreEngineTurnInput): Promise<SessionTurnExecutionResult> {
|
|
101
|
-
const start_time = Date.now();
|
|
102
|
-
const session_id = this.session_id;
|
|
103
|
-
let last_observed_stream_error: unknown = undefined;
|
|
104
|
-
let final_assistant_parts: SessionAgentMessagePart[] = [];
|
|
105
|
-
let compact_required = false;
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
let step_count = 0;
|
|
109
|
-
let total_tool_call_count = 0;
|
|
110
|
-
let total_tool_result_count = 0;
|
|
111
|
-
const on_step_finish = async (
|
|
112
|
-
step_result: ModelStepResult,
|
|
113
|
-
): Promise<void> => {
|
|
114
|
-
step_count += 1;
|
|
115
|
-
const summary = summarize_step_for_debug(step_result);
|
|
116
|
-
total_tool_call_count +=
|
|
117
|
-
typeof summary.toolCallCount === "number" ? summary.toolCallCount : 0;
|
|
118
|
-
total_tool_result_count +=
|
|
119
|
-
typeof summary.toolResultCount === "number"
|
|
120
|
-
? summary.toolResultCount
|
|
121
|
-
: 0;
|
|
122
|
-
await this.logger.log("info", "[agent] step.finish", {
|
|
123
|
-
session_id: session_id,
|
|
124
|
-
step_index: step_count,
|
|
125
|
-
...summary,
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
let incomplete_response_recovery_count = 0;
|
|
130
|
-
while (step_count < MAX_TOOL_LOOP_STEPS) {
|
|
131
|
-
// 关键点(中文):steer 与 command 在同一个 Session step 检查点执行。
|
|
132
|
-
// 当前流与 tool callback 保持原执行视图,下一 step 再统一读取 effective 配置。
|
|
133
|
-
await input.turn_context.input.checkpoint();
|
|
134
|
-
const step_input = await input.resolve_step_input();
|
|
135
|
-
|
|
136
|
-
last_observed_stream_error = undefined;
|
|
137
|
-
let step_assistant_parts: SessionAgentMessagePart[];
|
|
138
|
-
let step_result: ModelStepResult;
|
|
139
|
-
try {
|
|
140
|
-
const result = await execute_model_request({
|
|
141
|
-
request_kind: "turn",
|
|
142
|
-
abort_signal: input.turn_context.lifecycle.abort_signal,
|
|
143
|
-
should_retry: (error) => !this.should_compact_on_error(error),
|
|
144
|
-
on_failure: async (notice, error) => {
|
|
145
|
-
const is_compact_error = this.should_compact_on_error(error);
|
|
146
|
-
input.turn_context.output.report_model_request_failure({
|
|
147
|
-
...notice,
|
|
148
|
-
...(is_compact_error
|
|
149
|
-
? {
|
|
150
|
-
attempt: 1,
|
|
151
|
-
max_attempts: 1,
|
|
152
|
-
will_retry: false,
|
|
153
|
-
}
|
|
154
|
-
: {}),
|
|
155
|
-
});
|
|
156
|
-
if (notice.will_retry) {
|
|
157
|
-
await this.logger.log("warn", "[agent] model_stream.retry", {
|
|
158
|
-
session_id,
|
|
159
|
-
retry_count: notice.attempt,
|
|
160
|
-
error_code: notice.code,
|
|
161
|
-
error: notice.message,
|
|
162
|
-
provider_request_id: notice.provider_request_id ?? null,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
execute_attempt: async () => {
|
|
167
|
-
await input.turn_context.output.assistant?.begin_step();
|
|
168
|
-
try {
|
|
169
|
-
return await run_model_step({
|
|
170
|
-
model: step_input.model,
|
|
171
|
-
system: step_input.system,
|
|
172
|
-
messages: step_input.messages,
|
|
173
|
-
tools: step_input.tools,
|
|
174
|
-
abort_signal: input.turn_context.lifecycle.abort_signal,
|
|
175
|
-
...(input.turn_context.output.assistant
|
|
176
|
-
? { assistant_output: input.turn_context.output.assistant }
|
|
177
|
-
: {}),
|
|
178
|
-
approve_tool: async (call, tool) => await resolve_tool_approval({
|
|
179
|
-
call,
|
|
180
|
-
tool,
|
|
181
|
-
turn_context: input.turn_context,
|
|
182
|
-
}),
|
|
183
|
-
});
|
|
184
|
-
} catch (error) {
|
|
185
|
-
await input.turn_context.output.assistant?.abort_step();
|
|
186
|
-
throw error;
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
step_assistant_parts = result.assistant_parts;
|
|
191
|
-
await on_step_finish(result.step_result);
|
|
192
|
-
|
|
193
|
-
if (input.turn_context.output.assistant) {
|
|
194
|
-
await input.turn_context.output.assistant.finish_step(
|
|
195
|
-
step_assistant_parts,
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
const action_assistant_parts =
|
|
199
|
-
input.turn_context.output.take_assistant_parts();
|
|
200
|
-
if (action_assistant_parts.length > 0) {
|
|
201
|
-
const persisted_parts = input.turn_context.output.assistant
|
|
202
|
-
? await input.turn_context.output.assistant.append_result_parts(
|
|
203
|
-
action_assistant_parts,
|
|
204
|
-
)
|
|
205
|
-
: action_assistant_parts.map((part, index) =>
|
|
206
|
-
create_session_agent_content_part(
|
|
207
|
-
part,
|
|
208
|
-
`${part.type}:${generate_id()}`,
|
|
209
|
-
index + 1,
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
step_assistant_parts = merge_assistant_parts(
|
|
213
|
-
step_assistant_parts,
|
|
214
|
-
persisted_parts,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
final_assistant_parts = merge_assistant_parts(
|
|
218
|
-
final_assistant_parts,
|
|
219
|
-
step_assistant_parts,
|
|
220
|
-
);
|
|
221
|
-
step_result = result.step_result;
|
|
222
|
-
} catch (error) {
|
|
223
|
-
const compact_error = this.should_compact_on_error(error)
|
|
224
|
-
? error
|
|
225
|
-
: last_observed_stream_error;
|
|
226
|
-
if (this.should_compact_on_error(compact_error)) throw compact_error;
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const usage_ratio = resolve_model_usage_ratio(
|
|
231
|
-
step_result.usage,
|
|
232
|
-
step_input.context_window,
|
|
233
|
-
);
|
|
234
|
-
if (usage_ratio !== null) {
|
|
235
|
-
const pressure_detected = should_compact_after_usage(usage_ratio);
|
|
236
|
-
if (pressure_detected) compact_required = true;
|
|
237
|
-
await this.logger.log("info", "[agent] context.usage", {
|
|
238
|
-
session_id: session_id,
|
|
239
|
-
step_index: step_count,
|
|
240
|
-
usageRatio: usage_ratio,
|
|
241
|
-
contextWindow: step_input.context_window,
|
|
242
|
-
compactPending: pressure_detected,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const incomplete_response = detect_incomplete_response({
|
|
247
|
-
step_result,
|
|
248
|
-
assistant_parts: step_assistant_parts,
|
|
249
|
-
});
|
|
250
|
-
const loop_decision = evaluate_core_engine_loop_decision({
|
|
251
|
-
hasIncompleteResponse: incomplete_response !== null,
|
|
252
|
-
incompleteRecoveryCount: incomplete_response_recovery_count,
|
|
253
|
-
maxIncompleteRecoveries: MAX_INCOMPLETE_RESPONSE_RECOVERIES,
|
|
254
|
-
toolCallCount: step_result.tool_calls.length,
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
await this.logger.log("info", "[agent] loop.decision", {
|
|
258
|
-
session_id: session_id,
|
|
259
|
-
step_index: step_count,
|
|
260
|
-
continueForToolCalls: loop_decision.continueForToolCalls,
|
|
261
|
-
continueForIncompleteRecovery:
|
|
262
|
-
loop_decision.continueForIncompleteRecovery,
|
|
263
|
-
decisionKind: loop_decision.kind,
|
|
264
|
-
incompleteResponseReason: incomplete_response?.reason ?? null,
|
|
265
|
-
incompleteResponseRecoveryCount: incomplete_response_recovery_count,
|
|
266
|
-
toolCallCount: step_result.tool_calls.length,
|
|
267
|
-
toolResultCount: step_result.tool_results.length,
|
|
268
|
-
finishReason: step_result.finish_reason,
|
|
269
|
-
textPreview: to_inline_preview(step_result.text),
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
loop_decision.continueForIncompleteRecovery &&
|
|
274
|
-
incomplete_response
|
|
275
|
-
) {
|
|
276
|
-
incomplete_response_recovery_count += 1;
|
|
277
|
-
await this.logger.log("warn", "[agent] incomplete_response.recover", {
|
|
278
|
-
session_id: session_id,
|
|
279
|
-
step_index: step_count,
|
|
280
|
-
recoveryCount: incomplete_response_recovery_count,
|
|
281
|
-
reason: incomplete_response.reason,
|
|
282
|
-
...incomplete_response.details,
|
|
283
|
-
});
|
|
284
|
-
await input.turn_context.input.append_internal([{
|
|
285
|
-
type: "text",
|
|
286
|
-
text: build_incomplete_response_recovery_nudge(
|
|
287
|
-
incomplete_response_recovery_count,
|
|
288
|
-
),
|
|
289
|
-
}]);
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (incomplete_response) {
|
|
294
|
-
await this.logger.log("error", "[agent] incomplete_response", {
|
|
295
|
-
session_id: session_id,
|
|
296
|
-
step_index: step_count,
|
|
297
|
-
reason: incomplete_response.reason,
|
|
298
|
-
recoveryCount: incomplete_response_recovery_count,
|
|
299
|
-
...incomplete_response.details,
|
|
300
|
-
});
|
|
301
|
-
throw new Error(
|
|
302
|
-
`Agent received incomplete response (${incomplete_response.reason})`,
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (loop_decision.continueForToolCalls) {
|
|
307
|
-
incomplete_response_recovery_count = 0;
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// 关键点(中文):stop 前做 tail merge,覆盖最后一个 step 后才入队的新 user 消息。
|
|
312
|
-
const tail_merged_message_count = input.turn_context.input.has_pending()
|
|
313
|
-
? 1
|
|
314
|
-
: 0;
|
|
315
|
-
if (
|
|
316
|
-
should_continue_for_tail_merged_user_messages({
|
|
317
|
-
mergedUserMessageCount: tail_merged_message_count,
|
|
318
|
-
})
|
|
319
|
-
) {
|
|
320
|
-
incomplete_response_recovery_count = 0;
|
|
321
|
-
await this.logger.log("info", "[agent] loop.tail_merge_continue", {
|
|
322
|
-
session_id: session_id,
|
|
323
|
-
step_index: step_count,
|
|
324
|
-
mergedUserMessageCount: tail_merged_message_count,
|
|
325
|
-
});
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (step_count >= MAX_TOOL_LOOP_STEPS) {
|
|
333
|
-
await this.logger.log("warn", "[agent] loop.max_steps_reached", {
|
|
334
|
-
session_id: session_id,
|
|
335
|
-
stepCount: step_count,
|
|
336
|
-
totalToolCallCount: total_tool_call_count,
|
|
337
|
-
totalToolResultCount: total_tool_result_count,
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const final_parts = final_assistant_parts.length > 0
|
|
342
|
-
? final_assistant_parts
|
|
343
|
-
: build_fallback_assistant_parts("Execution completed");
|
|
344
|
-
|
|
345
|
-
await this.logger.log("info", "[agent] final.message", {
|
|
346
|
-
session_id: session_id,
|
|
347
|
-
...summarize_assistant_parts_for_debug(final_parts),
|
|
348
|
-
});
|
|
349
|
-
await log_assistant_message_now(this.logger, final_parts);
|
|
350
|
-
|
|
351
|
-
const duration = Date.now() - start_time;
|
|
352
|
-
await this.logger.log("info", "[agent] finish", {
|
|
353
|
-
session_id: session_id,
|
|
354
|
-
duration,
|
|
355
|
-
stepCount: step_count,
|
|
356
|
-
totalToolCallCount: total_tool_call_count,
|
|
357
|
-
totalToolResultCount: total_tool_result_count,
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
return {
|
|
361
|
-
success: true,
|
|
362
|
-
text: extract_assistant_text(final_parts),
|
|
363
|
-
...(compact_required ? { compact_required: true } : {}),
|
|
364
|
-
};
|
|
365
|
-
} catch (error) {
|
|
366
|
-
if (input.turn_context.lifecycle.abort_signal.aborted) {
|
|
367
|
-
const error_text = TURN_STOPPED_MESSAGE;
|
|
368
|
-
await this.logger.log("info", "[agent] stopped", {
|
|
369
|
-
session_id: session_id,
|
|
370
|
-
});
|
|
371
|
-
return {
|
|
372
|
-
success: false,
|
|
373
|
-
text: extract_assistant_text(final_assistant_parts),
|
|
374
|
-
error: error_text,
|
|
375
|
-
...(compact_required ? { compact_required: true } : {}),
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (this.should_compact_on_error(error)) {
|
|
380
|
-
throw error;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const error_text = resolve_effective_core_engine_error({
|
|
384
|
-
error,
|
|
385
|
-
streamError: last_observed_stream_error,
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
await this.logger.log("error", "CoreEngine execution failed", {
|
|
389
|
-
error: error_text,
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
return {
|
|
393
|
-
success: false,
|
|
394
|
-
text: extract_assistant_text(final_assistant_parts),
|
|
395
|
-
error: error_text,
|
|
396
|
-
...(compact_required ? { compact_required: true } : {}),
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/** 在工具执行前接入 Session canonical Interaction 生命周期。 */
|
|
403
|
-
async function resolve_tool_approval(input: {
|
|
404
|
-
call: ModelStepToolCall;
|
|
405
|
-
tool: Tool;
|
|
406
|
-
turn_context: SessionTurnContext;
|
|
407
|
-
}): Promise<boolean> {
|
|
408
|
-
const needs_approval = input.tool.needs_approval;
|
|
409
|
-
const required = typeof needs_approval === "function"
|
|
410
|
-
? await needs_approval(input.call.input as never, {
|
|
411
|
-
tool_call_id: input.call.tool_call_id,
|
|
412
|
-
messages: [],
|
|
413
|
-
})
|
|
414
|
-
: needs_approval === true;
|
|
415
|
-
if (!required) return true;
|
|
416
|
-
const interactions = input.turn_context.interactions;
|
|
417
|
-
if (!interactions) {
|
|
418
|
-
throw new Error("Tool approval requires a Session Interaction port");
|
|
419
|
-
}
|
|
420
|
-
const approval_id = `approval:${input.call.tool_call_id}`;
|
|
421
|
-
const handle = await interactions.request({
|
|
422
|
-
interaction_id: `interaction:tool-approval:${approval_id}`,
|
|
423
|
-
turn_id: input.turn_context.session.turn_id,
|
|
424
|
-
type: "approval",
|
|
425
|
-
source: {
|
|
426
|
-
type: "tool",
|
|
427
|
-
tool_call_id: input.call.tool_call_id,
|
|
428
|
-
tool_name: input.call.tool_name,
|
|
429
|
-
},
|
|
430
|
-
payload: {
|
|
431
|
-
operation: "tool",
|
|
432
|
-
validated_input: to_session_json_value(input.call.input),
|
|
433
|
-
...(input.tool.description ? { tool_description: input.tool.description } : {}),
|
|
434
|
-
},
|
|
435
|
-
created_at: Date.now(),
|
|
436
|
-
});
|
|
437
|
-
const result = await handle.result;
|
|
438
|
-
const payload = result.status === "resolved" && result.response.type === "approval"
|
|
439
|
-
? result.response.payload as { decision?: unknown }
|
|
440
|
-
: undefined;
|
|
441
|
-
return result.status === "resolved" &&
|
|
442
|
-
result.response.type === "approval" &&
|
|
443
|
-
result.response.outcome === "resolved" &&
|
|
444
|
-
payload?.decision === "approved";
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** 构造成功执行但缺少最终内容时使用的 canonical Assistant Parts。 */
|
|
448
|
-
function build_fallback_assistant_parts(
|
|
449
|
-
text: string,
|
|
450
|
-
): SessionAgentMessagePart[] {
|
|
451
|
-
return [{
|
|
452
|
-
part_id: "fallback-text:1",
|
|
453
|
-
sequence: 1,
|
|
454
|
-
type: "text",
|
|
455
|
-
text,
|
|
456
|
-
state: "done",
|
|
457
|
-
}];
|
|
458
|
-
}
|